Yehia gave Omar a square 2D array of size $$$N$$$ x $$$N$$$. He wants Omar to count the number of nodes in a Quad Tree built from this array.
Definition – Quad Tree
A Quad Tree is a tree built recursively as follows: (see Notes for visualization)
Your task is to determine the total number of nodes (both internal and leaf nodes) in the Quad Tree.
The first line contains an integer $$$N$$$ ($$$1 \le N \le 512$$$, $$$N$$$ is guaranteed to be a power of $$$2$$$).
The next $$$N$$$ lines each contain $$$N$$$ integers $$$A[i][j]$$$ ($$$A[i][j]$$$ is either $$$0$$$ or $$$1$$$) — the elements of the 2D array.
Print a single integer: the total number of nodes in the Quad Tree.
40 1 1 11 1 1 00 0 0 10 0 0 1
17
20 00 0
1
80 0 0 0 1 0 0 11 0 0 1 0 0 1 00 1 1 0 0 0 1 11 0 1 1 1 1 0 10 0 0 1 0 0 0 01 1 1 1 1 0 0 00 0 1 1 0 0 1 11 1 0 1 0 0 1 0
77
The tree formed for test case 1 is as follows
The second testcase will form only one node (root node) because it all has the same value.
| Name |
|---|


