A square sheet of paper is divided into an N × N grid.
Its cells are colored blue or white.
Cut the sheet into squares, each containing only one color.
Find how many pieces of colored paper can be produced.
The first line contains N, where 1 ≤ N ≤ 128.
The next N lines describe the colors of the paper.
Each line consists of N values, each either 0 or 1.
0 represents white, and 1 represents blue.
# 입력 처리N = int(input())colors = [list(map(int, input().split())) for _ in range(N)] # 정답 저장: answer[0] = 흰색 개수, answer[1] = 파란색 개수answer = [0, 0]def count_color(x, y, size): """ (x, y)를 시작으로 size x size 정사각형을 검사한다. 만약 모든 색이 같다면 색종이 개수 증가, 아니면 4등분하여 재귀 처리. """ color = colors[x][y] all_same = True # 해당 영역 전체가 같은 색인지 확인 for i in range(x, x + size): for j in range(y, y + size): if colors[i][j] != color: all_same = False break if not all_same: break if all_same: # 모두 같은 색이면 해당 색의 개수 증가 answer[color] += 1 else: # 4등분하여 재귀 호출 half = size // 2 count_color(x, y, half) # 왼쪽 위 count_color(x, y + half, half) # 오른쪽 위 count_color(x + half, y, half) # 왼쪽 아래 count_color(x + half, y + half, half) # 오른쪽 아래 # 시작 좌표 (0, 0), 전체 크기 Ncount_color(0, 0, N) # 출력print(answer[0]) # 하얀색 색종이 개수print(answer[1]) # 파란색 색종이 개수