h, w = io.read("*n", "*n") if h % 2 == 0 and w % 2 == 0 then print(h * w) for i = 1, h do print(string.rep("1 ", w - 1) .. "1") end elseif h % 2 == 0 then print(h * (w - 1)) for i = 1, h do print(string.rep("1 ", w - 1) .. "0") end elseif w % 2 == 0 then print(w * (h - 1)) for i = 1, h - 1 do print(string.rep("1 ", w - 1) .. "1") end print(string.rep("0 ", w - 1) .. "0") elseif h < w then print(h * w - w) local t = {} for i = 1, h - 1 do for j = 1, w do t[j] = i == j and 0 or 1 end print(table.concat(t, " ")) end for j = 1, w do t[j] = h <= j and 0 or 1 end print(table.concat(t, " ")) else print(h * w - h) local t = {} for i = 1, w do for j = 1, w do t[j] = i == j and 0 or 1 end print(table.concat(t, " ")) end for j = 1, w - 1 do t[j] = 1 end t[w] = 0 for i = w + 1, h do print(table.concat(t, " ")) end end