cswork / OAOpen practice workspace

UberOA #46

Matrix Transformation

Estimated EasyJudge-ready

Topics (AI-labelled)SimulationIn-place Arrays

Apply the given transformations to a square matrix in order. This site defines the operation codes explicitly: 0 rotates 90 degrees clockwise, 1 reflects across the main diagonal, and 2 reflects across the anti-diagonal.

This site has made the standard input and output explicit.

Input

The first line contains n q, followed by n lines of n integers each, and a last line with q operation codes. On this site 1≤n≤500, 0≤q≤200000, and elements are in −10⁹..10⁹.

Output

Output the transformed matrix, n integers per line.

Example 1

Input:

3 3
1 2 3
4 5 6
7 8 9
0 1 2

Output:

3 6 9
2 5 8
1 4 7

Example 2

Input:

2 1
1 2
3 4
1

Output:

1 3
2 4

Example 3

Input:

1 0
9

Output:

9

Example notes

Example 1: after transforming in order, the rows are 3 6 9, 2 5 8, 1 4 7. Example 2: transposing across the main diagonal gives 1 3, 2 4. Example 3: with no operations, it is still 9.

Editorial

Loading solution…