For this Question: Given a string S consisting of opening and closing parenthesis '(' and ')'. Find length of the longest valid parenthesis substring.Each test case have one line string S of character '(' and ')' of length  N.

Constraints:
1 <= N <= 10^5Print the length of the longest valid parenthesis substring.Input
((()

Output
2

Input
)()())

Output
4, I have written this Solution Code: def longestValidParentheses( S):
    stack, ans = [-1], 0
    for i in range(len(S)):
        if S[i] == '(': stack.append(i)
        elif len(stack) == 1: stack[0] = i
        else:
            stack.pop()
            ans = max(ans, i - stack[-1])
    return ans
n=input()
print(longestValidParentheses(n)), In this Programming Language: Python, Now tell me if this Code is compilable or not?