#C14148. Longest Valid Parentheses

    ID: 43765 Type: Default 1000ms 256MiB

Longest Valid Parentheses

Longest Valid Parentheses

Given a string s consisting solely of the characters '(' and ')', determine the length of the longest well-formed (valid) parentheses substring.

A substring is considered valid if it satisfies the property that every opening parenthesis \( ( \) has a corresponding closing parenthesis \( ) \), and the parentheses are correctly nested. More formally, a valid parentheses substring will satisfy the condition that for every prefix of the substring, the number of \( ( \) is at least as many as the number of \( ) \), and the total count of \( ( \) equals the count of \( ) \).

Your task is to compute the maximum length of a valid parentheses substring contained in the input string.

inputFormat

The input consists of a single line containing a string s composed only of the characters '(' and ')'.

Input is read from standard input (stdin).

outputFormat

Output a single integer representing the length of the longest valid parentheses substring found in s. Write the output to standard output (stdout).

## sample
(()
2