Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/stack-eng-uzun-togri-qavslar

Longest valid parentheses

Medium 1000 ms 128 MB 47%
Share

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$.

A row of brackets: the longest segment that is a correct bracket sequence is highlighted

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

Sign in to submit a solution

Signing up is free and takes a minute.