Problem Statement
Given is a string $S$ consisting of (, ), o, and x. You can swap two adjacent characters in $S$ any number of times. Find the minimum number of swaps needed to satisfy the following condition.
- Let us make a string
$S'$consisting of(and)by replacing every occurrence ofowith()and every occurrence ofxwith)(in$S$. Then,$S'$is a balanced parenthesis string.
Definition of a balanced parenthesis string A balanced parenthesis string is a string that is one of the following: an empty string; a string that is a concatenation of $s$, $t$ in this order, where $s$ and $t$ are some non-empty balanced parenthesis strings; a string that is a concatenation of (, $s$, ) in this order, where $s$ is some balanced parenthesis string.
Under the Constraints of this problem, it is always possible to achieve the objective.
Constraints
$S$is a string consisting of(,),o, andx.$S$contains the same non-zero number of(s and)s.$|S| \leq 8000$
Input
Input is given from Standard Input in the following format:
S
Output
Print the answer.
样例
)x(
3
()ox
2
()oxo(xxx))))oox((oooxxoxo)oxo)ooo(xxx(oox(x)(x()x
68
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。