n = int(input())
a = []
for i in range(n):
a.append(list(map(int, input())))
ans = []
for i in range(n):
for j in range(n):
if a[i][j] == 1:
q = [[i, j]]
a[i][j] = 0
cnt = 1
idx = 0
while idx < len(q):
x = q[idx][0]
y = q[idx][1]
idx += 1
if x > 0 and a[x-1][y] == 1:
a[x-1][y] = 0
q.append([x-1, y])
cnt += 1
if x < n-1 and a[x+1][y] == 1:
a[x+1][y] = 0
q.append([x+1, y])
cnt += 1
if y > 0 and a[x][y-1] == 1:
a[x][y-1] = 0
q.append([x, y-1])
cnt += 1
if y < n-1 and a[x][y+1] == 1:
a[x][y+1] = 0
q.append([x, y+1])
cnt += 1
ans.append(cnt)
for i in range(len(ans)):
for j in range(i + 1, len(ans)):
if ans[i] > ans[j]:
ans[i], ans[j] = ans[j], ans[i]
print(len(ans))
for x in ans:
print(x)
To embed this project on your website, copy the following code and paste it into your website's HTML: