AtCoder Grand Contest 054
D
(ox)
AtCoder
⌀ 3426
原题
← CE →
翻译中…

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 of o with () and every occurrence of x with )( 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, and x.
  • $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.

翻译中…

样例

Input #1
)x(
Output #1
3
We should do as follows: `)x(` → `x)(` → `x()` → `(x)`. Here, we have $S'=$`()()`, which is a balanced parenthesis string.
Input #2
()ox
Output #2
2
Input #3
()oxo(xxx))))oox((oooxxoxo)oxo)ooo(xxx(oox(x)(x()x
Output #3
68
题目信息
题号
agc054_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。