~/algor $ cat problems/stack-eng-uzun-togri-qavslar
Longest valid parentheses
Medium
1000 ms
128 MB
47%
A string of the characters ( and ) is given. Find the length of its longest segment of consecutive characters that is a correct bracket sequence (every opened bracket is closed later, and every closing bracket always has a matching opened one). If there is no such segment, print $0$.
Input
One line with the string.
Output
One integer — the largest length.
Note
the length of the string is from $1$ to $2 \cdot 10^{5}$
the string consists only of ( and )
Examples
Input #1
)()())(
Output #1
4
Input #2
(((
Output #2
0