Magic triangles

We define a magic triangle of size nn as a triangle with nn rows, the first one with nn elements, the second one with n1n - 1 elements, …, and the last one with one element, such that:

Write a program that, given an nn, prints all the magic triangles of size nn, or indicates that there is none.

Input

Input consists of a natural number n>0n > 0.

Output

Print all the magic triangles of size nn. Note that the numbers are always written with two digits (if needed, adding a zero to the left), and that they are separated with two spaces. Print an empty line after each triangle.

Ignore the triangles that are symmetrical of any other lexicographically smaller. If there is no possible triangle for the given nn, indicate it following the format of the example.

Observation

It can be proved that there is no solution for n6n \ge 6, but do not use this fact in your program.

Information about the checker

You can print the solutions to this exercise in any order.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T10:14:30.902Z

© Jutge.org, 2006–2026.
https://jutge.org