What's wrong??? Give me ANY test, please!
{$APPTYPE CONSOLE}
Var S : Array [0..1,1..300000] of Byte;
N,M,I,J,C : Longint;
Begin
Assign(Input,'1249.in'); Reset(Input);
Assign(Output,'1249.out'); Rewrite(Output);
{}
Read(N,M);
C := 1;
For J:=1 to N do S[1-C,J] := 0; { Обнуляем "предыдущую" строку }
For I:=1 to M do { Цикл по всем строкам }
Begin
For J:=1 to N do Read(S[C,J]); { Читаем новую строку }
For J:=1 to N-1 do { Ищем неприятности ;) }
If (((S[1-C,J]=0) and (S[1-C,J+1]=1) and (S[C,J]=1) and (S
[C,J+1]=1)) or
((S[1-C,J]=1) and (S[1-C,J+1]=0) and (S[C,J]=1) and (S
[C,J+1]=1)) or
((S[1-C,J]=1) and (S[1-C,J+1]=1) and (S[C,J]=0) and (S
[C,J+1]=1)) or
((S[1-C,J]=1) and (S[1-C,J+1]=1) and (S[C,J]=1) and (S
[C,J+1]=0))) then
Begin
Writeln('No');
Halt;
End;
C := 1 - C;
End;
Writeln('Yes');
End.