#K95062. Right-Aligned Number Pyramid

    ID: 38780 Type: Default 1000ms 256MiB

Right-Aligned Number Pyramid

Right-Aligned Number Pyramid

You are given a series of integer heights. For each height, if it is a valid integer in the range \(2 \leq height \leq 15\), output a right-aligned pyramid whose \(i\)th row contains the number \(i\) repeated \(i\) times, with each row padded on the left with spaces so that the last row starts at the beginning of the line. If the height is not within the valid range, output INVALID.

The outputs for multiple heights are separated by a blank line.

For example, given the height 3, the pyramid is:

  1
 2 2
3 3 3

Note: The pyramid for a height \(h\) is constructed by creating \(h\) rows. The \(i\)th row starts with \(h-i\) spaces followed by the number i printed \(i\) times with a space separating each occurrence.

inputFormat

The first line of input contains an integer \(T\) representing the number of test cases. Each of the next \(T\) lines contains a single integer representing the height for which you need to generate the pyramid.

For example:

5
1
3
5
8
-1

outputFormat

For each test case, output the corresponding pyramid pattern if the height is valid (i.e. between 2 and 15, inclusive). Otherwise, output INVALID. If there are multiple test cases, separate the outputs by a blank line.

For the sample input above, the output should be:

INVALID

1 2 2 3 3 3

1

2 2 3 3 3 4 4 4 4 5 5 5 5 5

   1
  2 2
 3 3 3
4 4 4 4

5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8

INVALID

## sample</p>
5
1
3
5
8
-1
INVALID

1 2 2 3 3 3

1

2 2 3 3 3 4 4 4 4 5 5 5 5 5

   1
  2 2
 3 3 3
4 4 4 4

5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8

INVALID

</p>