Skip to content
UPEEC

Generate Parentheses

Medium#recursion#backtracking· solved by 0 · time limit 2.0 s

Print all balanced strings of nn pairs of parentheses, in lexicographic order (( comes before )).

Input

A single integer nn.

Output

One string per line.

Constraints

1≤n≤81 \le n \le 8

Sample 1

Input

3

Output

((()))
(()())
(())()
()(())
()()()

Sample 2

Input

1

Output

()

Sign in or join free to run and submit your solution.