One-Line Notation
Time limit1sMemory limit512 MB
Find the lexicographically smallest shortest sequence of distinct labels a1..aN where every pair of labels appears adjacent somewhere, an Eulerian circuit of the complete graph.
- Level
Medium7 of 10
- Topics
- Graph, Greedy, Implementation, Combinatorics
- Solved
- No attempts yet
Problem
The statement that given numbers are all different can be written as a single expression that uses the symbol != several times. For example, A, B, C are all different exactly when (A != B) && (B != C) && (C != A) holds, and the one-line form of that,
A != B != C != A
is called a one-line notation for A, B, C.
Writing the condition that five numbers A, B, C, D, E are all different as
A != B != C != D != E
is not a valid one-line notation. Five numbers are all different only when each of the 10 pairs is said to be different, so at least 10 copies of != are needed. In general, a one-line notation for numbers needs at least copies of !=, where is the number of ways to choose 2 objects out of distinct ones.
More precisely, a one-line notation for a1, a2, ..., aN is a sequence , , ..., of those names, written on one line with != between every two neighbours. For every pair of distinct names , there must be a position with and , or with and . The length of the notation is the number of != symbols, that is .
You are given an odd number . Print the shortest one-line notation for a1, a2, ..., aN, and among the shortest ones the lexicographically smallest. Write a single space in place of each !=. For the answer is a1 a2 a3 a1. The notation a3 a1 a2 a3 has the same length, but it comes later in lexicographic order, so it is not the answer.
Hint: , the least number of != symbols, equals the number of edges of the complete graph on vertices.
Input
The first line contains an odd number with .
Output
Print on the first line the lexicographically smallest one among the shortest one-line notations. Write the names as a1, a2, and separate them with one space. Lexicographic order compares the sequences of subscripts from the front, and subscripts compare as numbers, so a2 comes before a10.