def solve(H,W): A=[[0]*W for _ in range(H)] if H==1 or W==1: pass elif H%2==0: if W%2==0: for i in range(H): a=A[i] for j in range(W): a[j]=1 else: for i in range(H): a=A[i] for j in range(W-1): a[j]=1 else: if W%2==0: for i in range(H-1): a=A[i] for j in range(W): a[j]=1 else: for i in range(H-1): a=A[i] for j in range(W-1): a[j]=1 A[-2][-2]=0 A[-2][-1]=A[-1][-2]=A[-1][-1]=1 X=0 for a in A: X+=sum(a) return X,A H,W=map(int,input().split()) X,A=solve(H,W) print(X) for a in A: print(*a)