Permutations
시간 제한2초메모리 제한1024 MB
차수 n의 반전표를 순열의 순환 표기법으로 변환하여, 각 순환을 가장 작은 원소부터 시작해 순서대로 출력한다.
문제
Let denote the set . A permutation of order is a one-to-one mapping from the set to the set . For example, let be a concrete permutation of order . We usually represent it with a table like this:
This means that , , etc. Since the top row is always , we usually omit it and write down the permutation in the one-line notation:
The cycle notation is also very popular. We start with element and determine its image . Next, we take the element and determine its image . If we keep doing this, we sooner or later arrive back at the element . Indeed, . The permutation contains the cycle . Then we take the smallest number that has not yet appeared in any cycle - in our case it is - and repeat the process. Eventually, we obtain to the following:
A permutation of order can also be represented by an inversion table (), where is the number of those elements that are greater than and appear to the left of in the one-line notation. In our concrete example, the inversion table is:
.
It is known that every permutation can be written in a unique way by an inversion table and that every inversion table in which holds for all , 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 , i.e. the order of a permutation. The second line contains 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.)