https://www.acmicpc.net/problem/2630
import sys
n=int(sys.stdin.readline())
paper=[]
for _ in range(n):
paper.append(list(map(int, sys.stdin.readline().split())))
cnt, total=0,0
def find(size, x, y):
if isSame(size, x, y):
return
ns=size//2
find(ns, x, y)
find(ns, x, y+ns)
find(ns, x+ns, y)
find(ns, x+ns, y+ns)
def isSame(size, x, y):
global cnt, total
k=paper[x][y]
for i in range(x, x+size):
for j in range(y, y+size):
if paper[i][j] != k:
return False
if k==1:
cnt+=1
else:
total+=1
return True
find(n, 0, 0)
print(total)
print(cnt)
import sys
n=int(sys.stdin.readline())
paper=[]
for _ in range(n):
paper.append(list(map(int, sys.stdin.readline().split())))
w,b=0,0
def find2(size, x, y):
global w,b
k=paper[x][y]
for i in range(x, x+size):
for j in range(y, y+size):
if k!=paper[i][j]:
ns=size//2
find2(ns, x, y)
find2(ns, x, y+ns)
find2(ns, x+ns, y)
find2(ns, x+ns, y+ns)
return
if k==1:
b+=1
else:
w+=1
find2(n,0,0)
print(w)
print(b)