def prod(A, B, MOD): n = len(A) m = len(B[0]) res = [[0]*m for _ in range(n)] for i in range(n): for j in range(m): for k in range(len(B)): res[i][j] += A[i][k]*B[k][j] % MOD res[i][j] %= MOD return res P = int(input()) N, M = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(N)] if A == [[0]*M for _ in range(N)]: if min(N, M) == 1: print(1) print(N, M) for _ in range(N): print(*[0]*M) else: print(2) print(N, 1) for _ in range(N): print(0) print(1, M) print(*[0]*M) exit() B = [a[:] for a in A] rank = 0 for r in range(N): for p in range(M): flag = 0 for i in range(r, N): if B[i][p] != 0: flag = 1 break if flag: break else: break rank += 1 B[r], B[i] = B[i], B[r] inv = pow(B[r][p], P-2, P) for j in range(M): B[r][j] = B[r][j]*inv % P for i in range(N): if i == r: continue v = B[i][p] for j in range(M): B[i][j] -= v*B[r][j] % P B[i][j] %= P rank = min(rank, M) if rank*(N+M) >= N*M: print(1) print(N, M) for a in A: print(*a) exit() plist = [] p = 0 for i in range(N): while p < M: if B[i][p] == 1: break p += 1 else: break plist.append(p) p += 1 res0 = [[a[ind] for ind in plist] for a in A] res1 = B[:rank] print(2) print(N, rank) for res in res0: print(*res) print(rank, M) for res in res1: print(*res) # print(prod(res0,res1,P) == A)