#agc054d. [agc054_d](ox)
[agc054_d](ox)
Problem Statement
Given is a string consisting of (
, )
, o
, and x
. You can swap two adjacent characters in any number of times. Find the minimum number of swaps needed to satisfy the following condition.
- Let us make a string consisting of
(
and)
by replacing every occurrence ofo
with()
and every occurrence ofx
with)(
in . Then, 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 , in this order, where and are some non-empty balanced parenthesis strings;
- a string that is a concatenation of
(
, ,)
in this order, where is some balanced parenthesis string.
Under the Constraints of this problem, it is always possible to achieve the objective.
Constraints
- is a string consisting of
(
,)
,o
, andx
. - contains the same non-zero number of
(
s and)
s.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
)x(
Sample Output 1
3
We should do as follows: )x(
→ x)(
→ x()
→ (x)
. Here, we have ()()
, which is a balanced parenthesis string.
Sample Input 2
()ox
Sample Output 2
2
Sample Input 3
()oxo(xxx))))oox((oooxxoxo)oxo)ooo(xxx(oox(x)(x()x
Sample Output 3
68