Trees

No attempts yetTime limit1sMemory limit128 MB

Problem

Trees appear very often in computer science. Unlike trees in nature, computer-science trees grow upside down: the root is at the top and the leaves are at the bottom.

A tree is made of nodes. One node is the root. Every node ww other than the root has exactly one father vv; if vv is the father of ww, then ww is a son of vv. A node with no sons is a leaf. The sons of a node ww, their sons, their sons' sons, and so on are the descendants of ww. Every node except the root is a descendant of the root.

Each node has a level number. The root has level 00, and a son's level is one greater than its father's.

A tree is a complete binary tree exactly when every node has either two sons or no sons at all. In a binary tree the two sons are called left and right.

The picture below shows a complete binary tree. Its nodes are numbered in preorder: the root gets number 11, a father comes before its sons, and the left son together with all of its descendants gets smaller numbers than the right son together with all of its descendants.

A complete binary tree with such a numbering can be written down in several ways. Three of them follow.

Genealogical representation.\ A sequence of numbers. The first element is 00, and for j>1j > 1 the jj-th element is the number of the father of node jj.

Bracket representation.\ Each node maps to a string of brackets. A leaf maps to (). Any other node ww maps to (lr), where l and r are the strings of the left and right sons of ww. The string of the root is the bracket representation of the whole tree.

Level representation.\ The sequence of the level numbers of the leaves, listed in the node-numbering order described above.

The tree in the picture can be described as follows.

Genealogical representation0 1 2 2 4 4 1 7 7
Bracket representation((()(()()))(()()))
Level representation2 3 3 2 2

Read a sequence of numbers and decide whether it is the level representation of some complete binary tree. If it is not, print the single word NIE ("no"). If it is, output the two other representations of that tree: the genealogical one and the bracket one.

Input

The first line contains a positive integer mm (m2500m \le 2500), the number of elements in the sequence. The second line contains those mm elements separated by single spaces.

The input is always given in a correct format, so your program does not need to check it.

Output

Print one of the following:

  • the single word NIE, or
  • two lines: the first line holds the genealogical representation with its elements separated by single spaces, and the second line holds the bracket representation as a string of ( and ) characters with no spaces.