{"problem":{"name":"(ox)","description":{"content":"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.","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"agc054_d"},"statements":[{"statement_type":"Markdown","content":"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.\n\n*   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**.\n\nDefinition of a balanced parenthesis stringA balanced parenthesis string is a string that is one of the following:\n\n*   an empty string;\n*   a string that is a concatenation of $s$, $t$ in this order, where $s$ and $t$ are some non-empty balanced parenthesis strings;\n*   a string that is a concatenation of `(`, $s$, `)` in this order, where $s$ is some balanced parenthesis string.\n\nUnder the Constraints of this problem, it is always possible to achieve the objective.\n\n## Constraints\n\n*   $S$ is a string consisting of `(`, `)`, `o`, and `x`.\n*   $S$ contains the same non-zero number of `(`s and `)`s.\n*   $|S| \\leq 8000$\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$S$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"agc054_d","tags":[],"sample_group":[[")x(","3\n\nWe should do as follows: `)x(` → `x)(` → `x()` → `(x)`. Here, we have $S'=$`()()`, which is a balanced parenthesis string."],["()ox","2"],["()oxo(xxx))))oox((oooxxoxo)oxo)ooo(xxx(oox(x)(x()x","68"]],"created_at":"2026-03-03 11:01:14"}}