cswork / OAOpen practice workspace

SafetyKitOA #1

Image Transformations on Binary Matrix

EasyJudge-ready

Topics (AI-labelled)In-place ArraysSimulation

Given an n×n binary image matrix, first rotate it clockwise by the specified angle (90, 180, or 270 degrees), then perform a vertical flip if its flag is set, and finally perform a horizontal flip if its flag is set; return the final matrix. A vertical flip swaps the rows top to bottom, and a horizontal flip reverses each row left to right.

The catalog specifies the square matrix, the rotation angles, and the three-step execution order.

Input

The first line contains n rotation vertical_flip horizontal_flip. Each of the next n lines contains n integers, each 0/1. Bounds on this site: 1≤n≤500; rotation∈{90,180,270}; both flags are 0 or 1.

Output

Output n lines, each with n integers, representing the transformed matrix.

Example 1

Input:

2 90 1 1
1 0
0 0

Output:

0 0
1 0

Example 2

Input:

2 180 0 0
1 0
0 1

Output:

1 0
0 1

Example 3

Input:

2 270 1 0
1 1
0 0

Output:

1 0
1 0

Editorial

Loading solution…