class Solution:
# @param {string} s
# @return {integer}
def longestValidParentheses(self, s):
if len(s)<2:
return 0
result = 0; stack = [(-1, ')')]
for i in xrange(len(s)):
if s[i] == ')' and stack[-1][1] == '(':
stack.pop()
result = max(result, i - stack[-1][0])
else:
stack.append((i, s[i]))
return result