#C13382. Minimum Parentheses Correction
Minimum Parentheses Correction
Minimum Parentheses Correction
You are given a string s
consisting solely of the characters (')
. The goal is to determine the minimum number of insertions and deletions required to make the parentheses string valid. A valid parentheses string is defined as:
- An empty string is valid.
- If
A
is valid, then(A)
is valid. - If
A
andB
are valid, then the concatenationAB
is valid.
Mathematically, if we denote balance(s)
as the net difference between the number of opening and closing parentheses while scanning the string, the minimum number of operations required can be expressed as:
Your task is to compute this number.
inputFormat
The input is read from standard input (stdin). It consists of a single line containing the string s
(which only contains characters '(' and ')').
outputFormat
Output a single integer representing the minimum number of insertions and deletions needed to make the string valid. The output should be written to standard output (stdout).
## sample
0