13613 - Subarray Rotation   

Description

After finishing Gregory's task, you feel like a genius and have a strong desire to solve more challenging problems. The next thing you want to do is a bit similar to the previous task: given a 2-dimensional array A, with size n * n, you want to

  1. find the subarray of A, with size m * m, that has the largest "first element" (i.e., the uppermost and the leftmost element) than any other m * m subarray;
  2. rotate this subarray in a certain degree b counterclockwise.

The following shows some 3 * 3 subarray examples for a given 5 * 5 array. 

 

 

Since in this case, the 3 * 3 subarray at the lower right corner has the maximum first element, you should rotate it.


The subarray would be rotated counterclockwise and will only be rotated by a degree that is a multiple of 90:

Note:

  1. If there is more than one subarray with the maximum value, rotate the uppermost one.
  2. If there is still more than one subarray that satisfies the condition, rotate the leftmost one.

Input

The first line contains an integer n, which means the size of A is n * n.
Each of the following n lines contains n positive integers, representing A.
The last line contains two integers m and b, which means the subarray size and the angle you want to rotate, respectively.

It is guaranteed that all numbers in A are less than 103.

Constraints:
3 ≤ n ≤ 100
1 ≤ m ≤ n
0 ≤ b ≤ 104
b ≡ 0 (mod 90)

Output

Output contains n lines, each having n integers that represent the rotated array.

Sample Input  Download

Sample Output  Download

Tags

FlyHighHigh wrong answer



Discuss