cho.sh
Notes
Loading...

Fractal Plane

Time limit

2s

Memory limit

128 MB

Problem

A fractal plane expands by the following rules. At time 0, the plane consists of one white square. Whenever time increases by 1, each square in the current plane is divided into N x N equal squares. If the original square was white, the centered K x K area among those new squares is colored black. Areas that are already black remain black. N and K are either both odd or both even.

When N=3 and K=1, the plane at time 1 is a 3 x 3 square. The center square is black and all other squares are white. At time 2, the plane is 9 x 9; 17 cells are black and the rest are white.

Given s, N, K, R1, R2, C1, and C2, print the part of the plane at time s from row R1, column C1 through row R2, column C2.

Input

The first line contains seven integers: s, N, K, R1, R2, C1, and C2.

Output

Print the answer. The first output line must show row R1, and the output must contain R2 - R1 + 1 lines in total. For each row, print the cells from column C1 through column C2 in order. Print 0 for a white cell and 1 for a black cell, with no spaces between digits.

Constraints

  • 0 <= s <= 10
  • 3 <= N <= 8
  • 1 <= K <= N - 2
  • (N - K) mod 2 = 0
  • 0 <= R1, R2, C1, C2 <= N^s - 1
  • R1 <= R2 <= R1 + 49
  • C1 <= C2 <= C1 + 49