Making Colored Paper

Time limit1sMemory limit128 MB

Problem

You are given an N×N square paper made of equal-sized square cells. Each cell is colored either white or blue. The paper is cut by a fixed rule, and you must count how many white and blue square pieces remain at the end.

If the current square region is entirely one color, it becomes one piece of that color. Otherwise, cut it through the middle horizontally and vertically to divide it into four equal square regions. Apply the same rule to each of the four regions.

Repeat this process until every remaining region is a single color, or until it is a single cell and cannot be divided further. Given N and the colors of all cells, compute the final number of white pieces and blue pieces.

Input

The first line contains the side length N of the whole paper. N is one of 2, 4, 8, 16, 32, 64, and 128.

The next N lines describe the colors of the cells from top to bottom. A white cell is given as 0 and a blue cell is given as 1. Numbers on the same line are separated by one space.

Output

Print the number of final white pieces on the first line.

Print the number of final blue pieces on the second line.