eolymp
bolt
Try our new interface for solving problems
Problems

Longest Valid Parentheses

Longest Valid Parentheses

Given a string containing just the characters '(' and ')'. Find the length of the longest valid (well-formed) parentheses substring.

Input

One string consisting of characters '(' and ')' of length no more than 106.

Output

Print the length of the longest well-formed parentheses substring.

Time limit 1 second
Memory limit 128 MiB
Input example #1
)()())
Output example #1
4