class Solution(object):
    def generateParenthesis(self, n):
        """
        :type n: int
        :rtype: List[str]
        """
        def backtrack(n,score,cur,ans):
            if len(cur)>n*2 or score<0:
                return
            if len(cur)==n*2 and score==0:
                ans.append(cur)
                return
            backtrack(n,score+1,cur+"(",ans)
            backtrack(n,score-1,cur+")",ans)
        ans=[]
        backtrack(n,0,"",ans)
        return ans

s=Solution()
n=3
print(s.generateParenthesis(n))