Parentheses
Time limit4sMemory limit1024 MB
Given a permutation p of n cards, assign each card an opening or closing bracket so both the original and shuffled orders are correct bracket sequences.
- Level
Hard8 of 10
- Topics
- Graph, Greedy, Implementation
- Solved
- No attempts yet
Statement
Bajtazar is developing a new card trick. He has a deck of cards numbered from 1 to . On each card he wants to draw either an opening or a closing bracket, so that laying the cards out in order forms a correct bracket sequence.
Bajtazar is very good at shuffling, and every shuffle gives the same result: after shuffling, the card in position is card . The trick requires that after shuffling, the cards still form a correct bracket sequence.
For example, with and the permutation , the brackets can be drawn so that before shuffling the cards form (()()), and after shuffling they form ()(()).

Input
The first line contains an even integer (), the number of cards. The second line contains the permutation of the numbers from 1 to .
Output
Print the word NIE if the brackets cannot be drawn so that the cards meet the requirements. Otherwise, print a word of characters, each ( or ), giving the bracket to draw on each card in order. If more than one correct answer exists, print any of them.