program solitario;
uses Math;
var N,M,i,j, a, con_x, senza_x, nuovariga, nuovacolonna, ricorda,ricordatot,totale:longint;
griglia:array[0..12,0..12] of longint;
function gioca(r, c: longint): boolean;
begin
(* Tris diagonale in alto a dx*)
if ((r-2>=0) and (c+2<=M) and (griglia[r-2][c+2]=1) and (griglia[r-1][c+1]=1)) then gioca:=false
else if ((r+2<=N) and (c+2<=M) and (griglia[r+2][c+2]=1) and (griglia[r+1][c+1]=1)) then gioca:=false
else if ((r+2<=N) and (c-2>=0) and (griglia[r+2][c-2]=1) and (griglia[r+1][c-1]=1)) then gioca:=false
(*tris orizzontale*)
else if (c-2>=0) and (griglia[r][c-2]=1) and (griglia[r][c-1]=1) then gioca:=false
(*tris verticale*)
else if (r-2>=0) and (griglia[r-2][c]=1) and (griglia[r-1][c]=1) then gioca:=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 gioca:=false
else gioca := true;
end;
function riempi (riga, colonna, tot:longint):longint;
begin
if riga>=N then riempi(0,colonna+1,tot);
if colonna>=M then exit;
ricorda:=griglia[riga,colonna];
con_x:=0;
if gioca (riga,colonna)=true then
begin
griglia[riga][colonna]:=1;
con_x:= Riempi(riga,colonna+1, tot+1);
(* Reset della griglia[riga][col]*)
if ricorda=0 then griglia[riga, colonna]:=0;
end;
(* Non metto la X*)
if ricorda=0 then senza_x:=Riempi(riga,colonna+1, tot);
(*Ritorno la soluzione migliore*)
riempi:=max(con_x,senza_x);
for i:=0 to N-1 do
for j:=0 to M-1 do
if griglia[i,j]=1 then totale:=totale+1;
writeln(totale);
for i:=0 to N-1 do begin
for j:=0 to M-1 do
write (griglia[i,j],' ');
writeln
end;
writeln;
end;
begin
readln(N,M);
if M<N then begin a:=N; N:=M; M:=a; end;
if N<=2 then writeln(N* (M-(M div 3)));
ricordatot:=0;
for i:=0 to N-1 do
for j:=0 to M-1 do griglia[i,j]:=0;
totale:=0;
riempi(0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PWZhbHNlCiAgICAoKiBUcmlzIGRpYWdvbmFsZSBpbiBhbHRvIGEgc3gqKQogICAgIGVsc2UgaWYgKHItMj49MCApIGFuZCAoYy0yPj0wKSBhbmQgKGdyaWdsaWFbci0yXVtjLTJdPTEpIGFuZCAoZ3JpZ2xpYVtyLTFdW2MtMV09MSkgdGhlbiBnaW9jYTo9ZmFsc2UKICAgICAgZWxzZSAgIGdpb2NhIDo9IHRydWU7CmVuZDsgICAgCmZ1bmN0aW9uIHJpZW1waSAocmlnYSwgY29sb25uYSwgIHRvdDpsb25naW50KTpsb25naW50OwogIGJlZ2luCiAgICBpZiByaWdhPj1OIHRoZW4gcmllbXBpKDAsY29sb25uYSsxLHRvdCk7CiAgICAgICAgICAgICAKICAgIGlmIGNvbG9ubmE+PU0gdGhlbiBleGl0OwogICAgICAgICAgICAgICAgIAogICAgcmljb3JkYTo9Z3JpZ2xpYVtyaWdhLGNvbG9ubmFdOwogCiAgICBjb25feDo9MDsKICAgIGlmIGdpb2NhIChyaWdhLGNvbG9ubmEpPXRydWUgdGhlbgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJlZ2luIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZ3JpZ2xpYVtyaWdhXVtjb2xvbm5hXTo9MTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb25feDo9IFJpZW1waShyaWdhLGNvbG9ubmErMSwgdG90KzEpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKCogUmVzZXQgZGVsbGEgZ3JpZ2xpYVtyaWdhXVtjb2xdKikKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiByaWNvcmRhPTAgdGhlbiBncmlnbGlhW3JpZ2EsIGNvbG9ubmFdOj0wOyAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZW5kOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKCogTm9uIG1ldHRvIGxhIFgqKQogICAgaWYgcmljb3JkYT0wIHRoZW4gIHNlbnphX3g6PVJpZW1waShyaWdhLGNvbG9ubmErMSwgdG90KTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICgqUml0b3JubyBsYSBzb2x1emlvbmUgbWlnbGlvcmUqKQogICByaWVtcGk6PW1heChjb25feCxzZW56YV94KTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZm9yIGk6PTAgdG8gTi0xIGRvIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3Igajo9MCB0byBNLTEgZG8gCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiBncmlnbGlhW2ksal09MSB0aGVuIHRvdGFsZTo9dG90YWxlKzE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgd3JpdGVsbih0b3RhbGUpOyAgCiAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZm9yIGk6PTAgdG8gTi0xIGRvIGJlZ2luIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmb3Igajo9MCB0byBNLTEgZG8gCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB3cml0ZSAoZ3JpZ2xpYVtpLGpdLCcgJyk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB3cml0ZWxuCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlbmQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB3cml0ZWxuOwoKICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAKICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAplbmQ7ICAgICAgICAgICAgICAgICAgIApiZWdpbgoJcmVhZGxuKE4sTSk7CgkgaWYgTTxOIHRoZW4gYmVnaW4gYTo9TjsgTjo9TTsgTTo9YTsgZW5kOwoJICBpZiBOPD0yIHRoZW4gd3JpdGVsbihOKiAoTS0oTSBkaXYgMykpKTsKCSAgcmljb3JkYXRvdDo9MDsKCWZvciBpOj0wIHRvIE4tMSBkbwoJICAgICAgICAgICAgZm9yIGo6PTAgdG8gTS0xIGRvIGdyaWdsaWFbaSxqXTo9MDsKCSAgICAgICAgICAgIHRvdGFsZTo9MDsKICByaWVtcGkoMCwwLDApOwplbmQuCg==