Day 1 : Generate Parentheses

mediumRecursion
Given $n$ pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Parentheses should be sorted, i.e. consider two parentheses with the first position of difference having '(' and ')' then parenthesis with '(' should be printed first.

Input Format:

The first and only line of input contains an integer $n$

Output Format:

You need to input the number of combinations $C$ followed by $C$ lines each containing the parentheses.

Constraints:

($1 \le n \le 8$)

Examples:

Example 1:

Input:

1

Output:

1
()

Example 2:

Input:

2

Output:

2
(())
()()

Code

Loading Editor...