Fractal
A square of size 1×1 is painted either black or white. This square is divided into N^2 smaller squares of equal size using horizontal and vertical lines. Each of these smaller squares is painted black or white following a specified pattern. This process is then repeated for each smaller square: each one is further divided into even smaller squares, which are painted according to a pattern based on the color of the square being divided. Black squares are repainted using one pattern, while white squares use another. This division and repainting process is performed K times.
Write a program to calculate the total area covered by black squares.
Input
The first line contains two integers: N, the number of divisions, and K, the number of division operations (1 ≤ N ≤ 10, 0 ≤ K ≤ 10^9). The second line indicates the color of the initial square: 0 for black and 1 for white. The next N lines, each containing N numbers, describe the pattern for repainting black squares after division. Following this, another block of N lines describes the pattern for repainting white squares.
Output
Output a single number representing the total area of black squares, with a precision of at least 10^{-7}.
Note: In the example provided, the sequence of divisions and repaintings results in:
In the final image, the black portion consists of 11 small squares, each with a side length of 0.25.