#P5725. Print Squares and Triangle Matrix

    ID: 18953 Type: Default 1000ms 256MiB

Print Squares and Triangle Matrix

Given a single integer n (with n ≥ 2), first generate a square matrix where the element at the i-th row and j-th column (0-indexed) is defined as \(a_{ij} = i \times n + j + 1\). Print this matrix in four different orientations:

  • Original
  • Rotated 90° clockwise
  • Rotated 180°
  • Rotated 270° clockwise

After printing the four matrices (each printed as an n×n block immediately one after the other), output a blank line, and then print a right-angled triangular matrix consisting of n rows. The i-th row of the triangle should contain the numbers from 1 to i, separated by a single space.

inputFormat

A single integer n (n ≥ 2).

outputFormat

First, output four n×n matrices corresponding to the original square and its rotations as described. Each matrix is printed as n lines with each line containing n numbers separated by a single space. Immediately after the fourth matrix, print a blank line, and then output the right-angled triangular matrix with n rows. The i-th row of the triangle contains the numbers from 1 to i, separated by a single space.

sample

2
1 2

3 4 3 1 4 2 4 3 2 1 2 4 1 3

1 1 2

</p>