program solitario;
uses Math;
var N,M,i,j, soluzione, con_x, senza_x, nuovariga, nuovacolonna:longint;
griglia:array[-1..12,-1..12] of longint;
function posso(r, c: longint): boolean;
begin
(*tris orizzontale*)
if (c-2>0) and (griglia[r][c-2]=1) and (griglia[r][c-1]=1) then posso:=false
(*tris orizzontale*)
else if (r-2>0) and (griglia[r-2][c]=1) and (griglia[r-1][c]=1) then posso:=false
(* Tris diagonale in alto a sx*)
else if (r-2>0 ) and (c-2>0) and (griglia[r-2][c-2]=1) and (griglia[r-1][c-1]=1) then posso:=false
(* Tris diagonale in alto a dx*)
else if (r-2>0) and (c+2<M) and (griglia[r-2][c+2]=1) and (griglia[r-1][c+1]=1) then posso:=false
else posso := true;
end;
function gioca (riga, colonna:longint):longint;
begin
while (riga <=N) do
begin
(*Se posso, metto la X*)
if posso (riga,colonna)=true then
begin
griglia[riga][colonna]:=1;
con_x:=con_x+1;
end;
if colonna+1=M then riga:=riga+1;
colonna:= (colonna +1) mod M;
end;
(*Ritorno la soluzione migliore*)
soluzione:= con_x-1;
end;
begin
readln(N,M);
for i:=1 to N do
for j:=1 to M do griglia[i,j]:=0;
griglia[1,1]:=1;nuovariga:=1; con_x:=0;
gioca(1,1);
writeln(soluzione);
for i:=1 to N do begin
for j:=1 to M do write(griglia[i,j],' '); writeln; end;
end.
cHJvZ3JhbSBzb2xpdGFyaW87CnVzZXMgTWF0aDsKdmFyIE4sTSxpLGosIHNvbHV6aW9uZSwgY29uX3gsIHNlbnphX3gsIG51b3ZhcmlnYSwgbnVvdmFjb2xvbm5hOmxvbmdpbnQ7CiAgICBncmlnbGlhOmFycmF5Wy0xLi4xMiwtMS4uMTJdIG9mIGxvbmdpbnQ7CgpmdW5jdGlvbiBwb3NzbyhyLCBjOiBsb25naW50KTogYm9vbGVhbjsKYmVnaW4KICAgICAgKCp0cmlzIG9yaXp6b250YWxlKikKICAgaWYgKGMtMj4wKSBhbmQgKGdyaWdsaWFbcl1bYy0yXT0xKSBhbmQgKGdyaWdsaWFbcl1bYy0xXT0xKSB0aGVuIHBvc3NvOj1mYWxzZQogICAgICAoKnRyaXMgb3JpenpvbnRhbGUqKQogICAgICBlbHNlICBpZiAoci0yPjApIGFuZCAoZ3JpZ2xpYVtyLTJdW2NdPTEpIGFuZCAoZ3JpZ2xpYVtyLTFdW2NdPTEpIHRoZW4gcG9zc286PWZhbHNlCiAgICAoKiBUcmlzIGRpYWdvbmFsZSBpbiBhbHRvIGEgc3gqKQogICAgICBlbHNlIGlmIChyLTI+MCApIGFuZCAoYy0yPjApIGFuZCAoZ3JpZ2xpYVtyLTJdW2MtMl09MSkgYW5kIChncmlnbGlhW3ItMV1bYy0xXT0xKSB0aGVuIHBvc3NvOj1mYWxzZQogICAgKCogVHJpcyBkaWFnb25hbGUgaW4gYWx0byBhIGR4KikKICAgICAgZWxzZSBpZiAoci0yPjApIGFuZCAoYysyPE0pIGFuZCAoZ3JpZ2xpYVtyLTJdW2MrMl09MSkgYW5kIChncmlnbGlhW3ItMV1bYysxXT0xKSB0aGVuIHBvc3NvOj1mYWxzZQogICAgICAgICAgZWxzZSAgIHBvc3NvIDo9IHRydWU7CmVuZDsgICAgCmZ1bmN0aW9uIGdpb2NhIChyaWdhLCBjb2xvbm5hOmxvbmdpbnQpOmxvbmdpbnQ7CiAgYmVnaW4KICAgIHdoaWxlIChyaWdhIDw9TikgIGRvCiAgICAgICAgICAgICAgICAgYmVnaW4KICAgICAgICAgICAgICAgICAgICgqU2UgcG9zc28sIG1ldHRvIGxhIFgqKQogICAgICAgICAgICAgICAgICAgaWYgcG9zc28gKHJpZ2EsY29sb25uYSk9dHJ1ZSB0aGVuCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBiZWdpbiAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGdyaWdsaWFbcmlnYV1bY29sb25uYV06PTE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25feDo9Y29uX3grMTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVuZDsKICAgICAgICAgICAgICAgICAgICBpZiBjb2xvbm5hKzE9TSB0aGVuIHJpZ2E6PXJpZ2ErMTsKICAgICAgICAgICAgICAgICAgICBjb2xvbm5hOj0gKGNvbG9ubmEgKzEpIG1vZCBNOyAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIGVuZDsgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgKCpSaXRvcm5vIGxhIHNvbHV6aW9uZSBtaWdsaW9yZSopCiAgICAgICAgICAgICAgICAgICAgc29sdXppb25lOj0gY29uX3gtMTsKZW5kOwpiZWdpbgoJcmVhZGxuKE4sTSk7Cglmb3IgaTo9MSB0byBOIGRvCgkgICAgICAgICAgICBmb3Igajo9MSB0byBNIGRvIGdyaWdsaWFbaSxqXTo9MDsKCWdyaWdsaWFbMSwxXTo9MTtudW92YXJpZ2E6PTE7ICBjb25feDo9MDsgICAgICAgICAgCglnaW9jYSgxLDEpOwoJd3JpdGVsbihzb2x1emlvbmUpOwoJZm9yIGk6PTEgdG8gTiBkbyBiZWdpbgoJICAgICAgICAgICAgZm9yIGo6PTEgdG8gTSBkbyB3cml0ZShncmlnbGlhW2ksal0sJyAnKTsgd3JpdGVsbjsgZW5kOwplbmQuCgo=