def solve(h, w): A = [[1] * w for _ in range(h)] if h == 1 or w == 1: A = [[0] * w for _ in range(h)] cnt = 0 elif not h & 1 and not w & 1: cnt = h * w elif not h & 1: for i in range(h): A[i][0] = 0 cnt = h * (w - 1) elif not w & 1: for j in range(w): A[0][j] = 0 cnt = (h - 1) * w elif h >= w: for i in range(h): A[i][min(i, w - 1)] = 0 cnt = h * (w - 1) else: for i in range(w): A[min(i, h - 1)][i] = 0 cnt = (h - 1) * w return cnt, A h, w = map(int, input().split()) cnt, A = solve(h, w) print(cnt) for row in A: print(*row)