atcoder#ARC099D. [ARC099F] Eating Symbols Hard
[ARC099F] Eating Symbols Hard
Score : points
Problem Statement
In Takahashi's mind, there is always an integer sequence of length : $A = (A_{-10^9}, A_{-10^9 + 1}, ..., A_{10^9 - 1}, A_{10^9})$ and an integer .
Initially, all the elements in the sequence in Takahashi's mind are , and the value of the integer is .
When Takahashi eats symbols +
, -
, >
and <
, the sequence and the integer will change as follows:
- When he eats
+
, the value of increases by ; - When he eats
-
, the value of decreases by ; - When he eats
>
, the value of increases by ; - When he eats
<
, the value of decreases by .
Takahashi has a string of length . Each character in is one of the symbols +
, -
, >
and <
.
He chose a pair of integers such that and ate the symbols that are the -th, -th, , -th characters in , in this order.
We heard that, after he finished eating, the sequence became the same as if he had eaten all the symbols in from first to last.
How many such possible pairs are there?
Constraints
- Each character in is
+
,-
,>
or<
.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
5
+>+<-
3
If Takahashi eats all the symbols in , and all other elements would be . The pairs that leads to the same sequence are as follows:
5
+>+-<
5
Note that the value of may be different from the value when Takahashi eats all the symbols in .
48
-+><<><><><>>>+-<<>->>><<><<-+<>><+<<>+><-+->><<
475