Josip is a strange painter. He wants to paint a picture consisting of
This would be no problem if Josip's painting process wasn't strange. He uses the following recursive process:
- If the picture is a single pixel, he colours it the way he intended.
- Otherwise, split the square into four smaller squares and then:
- Select one of the four squares and colour it white.
- Select one of the three remaining squares and colour it black.
- Consider the two remaining squares as new paintings and use the same three-step process on them.
Soon he noticed that it was not possible to convert all his visions to paintings with this process. Your task is to write a program that will paint a picture that differs as little as possible from the desired picture. The difference between two pictures is the number of pairs of pixels in corresponding positions that differ in colour.
Input Specification
The first line contains an integer
Each of the following
Output Specification
On the first line, output the smallest possible difference that can be achieved.
On the next
Note: The second part of the output may not be unique. Any correct output will be accepted.
Scoring
In test cases worth
Sample Input 1
4
0001
0001
0011
1110
Sample Output 1
1
0001
0001
0011
1111
Sample Input 2
4
1111
1111
1111
1111
Sample Output 2
6
0011
0011
0111
1101
Sample Input 3
8
01010001
10100011
01010111
10101111
01010111
10100011
01010001
10100000
Sample Output 3
16
00000001
00000011
00000111
00001111
11110111
11110011
11110001
11110000
Comments