import copy p=int(input()) n,m=map(int,input().split()) a=[list(map(int,input().split())) for i in range(n)] a_copy=copy.deepcopy(a) rank=0 for i in range(m): if rank==n: break if a_copy[rank][i]==0: not_pivot=True for j in range(rank+1,n): if a_copy[j][i]!=0: not_pivot=False for k in range(i,m): a_copy[rank][k],a_copy[j][k]=a_copy[j][k],a_copy[rank][k] break if not_pivot: continue for j in reversed(range(i,m)): a_copy[rank][j]*=pow(a_copy[rank][i],p-2,p) a_copy[rank][j]%=p for j in range(0,n): if j==rank: continue for k in reversed(range(i,m)): a_copy[j][k]-=a_copy[rank][k]*a_copy[j][i] a_copy[j][k]%=p rank+=1 if n*m<=n*rank+rank*m: print(1) print(n,m) for i in range(n): print(*a[i]) else: c=[[0 for j in range(rank)] for i in range(n)] pivot=0 for i in range(m): if pivot==n: break if a_copy[pivot][i]==0: continue for j in range(n): c[j][pivot]=a[j][i] pivot+=1 f=[[0 for j in range(m)] for i in range(rank)] for i in range(rank): for j in range(m): f[i][j]=a_copy[i][j] print(2) print(n,rank) for i in range(n): print(*c[i]) print(rank,m) for i in range(rank): print(*f[i])