from math import gcd

n = int(input())
a = []
for i in range(n):
    row = input()
    a.append(bin(int(row,16))[2:].zfill(n))
print(*a, sep='\n')
vis = [[False]*n for i in range(n)]
ans = n
for i in range(n):
    br = False
    for j in range(n):
        if vis[i][j]:
            continue
        currx = 1
        d = a[i][j]
        expand = True
        while expand and currx+i < n and currx+j < n:
            for ki in range(i, i+currx):
                if a[ki][j+currx] != d:
                    expand = False
                    break
            if expand:
                for kj in range(j, j+currx):
                    if a[i+currx][kj] != d:
                        expand = False
                        break
            if expand:
                for ki in range(i, i+currx):
                    vis[ki][j+currx] = True
                for kj in range(j, j+currx):
                    vis[i+currx][kj] = True
                currx += 1
        print(currx)
        kj = j + currx
        ans = gcd(ans, currx)
        if ans == 1:
            br = True
            break
        j += currx
        # print(*vis, sep='\n')
    if br:
        break

print(ans)
