Permutations

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

Let \[n]\[n] denote the set 1,2,,n\\{1, 2, \ldots, n\\}. A permutation of order nn is a one-to-one mapping from the set \[n]\[n] to the set \[n]\[n]. For example, let π ⁣:\[7]\[7]\pi \colon \[7] \to \[7] be a concrete permutation of order 77. We usually represent it with a table like this:

π=(1234567 3741652).\pi = \begin{pmatrix} 1 & 2 & 3 & 4 & 5 & 6 & 7 \\\ 3 & 7 & 4 & 1 & 6 & 5 & 2\end{pmatrix}.

This means that π(1)=3\pi(1) = 3, π(2)=7\pi(2) = 7, π(3)=4\pi(3) = 4 etc. Since the top row is always 1 2 3n1\ 2\ 3 \ldots n, we usually omit it and write down the permutation in the one-line notation:

π=3 7 4 1 6 5 2.\pi = 3\ 7\ 4\ 1\ 6\ 5\ 2.

The cycle notation is also very popular. We start with element 11 and determine its image π(1)=3\pi(1) = 3. Next, we take the element 33 and determine its image π(3)=4\pi(3) = 4. If we keep doing this, we sooner or later arrive back at the element 11. Indeed, π(4)=1\pi(4) = 1. The permutation π\pi contains the cycle (1 3 4)(1\ 3\ 4). Then we take the smallest number that has not yet appeared in any cycle - in our case it is 22 - and repeat the process. Eventually, we obtain to the following:

π=(1 3 4) (2 7) (5 6).\pi = (1\ 3\ 4)\ (2\ 7)\ (5\ 6).

A permutation of order nn can also be represented by an inversion table b_1 b_2 b_3b_nb\_1\ b\_2\ b\_3 \ldots b\_n (0b_ini0 \leq b\_i \leq n-i), where b_ib\_i is the number of those elements that are greater than ii and appear to the left of ii in the one-line notation. In our concrete example, the inversion table is:

3 5 0 1 2 1 03\ 5\ 0\ 1\ 2\ 1\ 0.

It is known that every permutation can be written in a unique way by an inversion table and that every inversion table b_1 b_2 b_3b_nb\_1\ b\_2\ b\_3 \ldots b\_n in which 0b_ini0 \leq b\_i \leq n-i holds for all i\[n]i \in \[n], represents a valid permutation.

Write a program that will convert a inversion table to its corresponding cycle notation.

입력

The input data consists of two lines. The first line contains an integer nn, i.e. the order of a permutation. The second line contains nn space-separated integers describing a valid inversion table.

출력

Output one line that contains the cycle notation of the permutation given by the given inversion table. Each cycle should be in parentheses. Cycles should be separated by one space. The numbers within the cycle should also be separated by one space. The smallest element should always be in the first place in the cycle. Cycles should be ordered according to the element in the first place. (See examples.)

제한

  • 1n1051 \leq n \leq 10^5