#ARC099D. [ARC099F] Eating Symbols Hard

[ARC099F] Eating Symbols Hard

Score : 12001200 points

Problem Statement

In Takahashi's mind, there is always an integer sequence of length 2×109+12 \times 10^9 + 1: $A = (A_{-10^9}, A_{-10^9 + 1}, ..., A_{10^9 - 1}, A_{10^9})$ and an integer PP.

Initially, all the elements in the sequence AA in Takahashi's mind are 00, and the value of the integer PP is 00.

When Takahashi eats symbols +, -, > and <, the sequence AA and the integer PP will change as follows:

  • When he eats +, the value of APA_P increases by 11;
  • When he eats -, the value of APA_P decreases by 11;
  • When he eats >, the value of PP increases by 11;
  • When he eats <, the value of PP decreases by 11.

Takahashi has a string SS of length NN. Each character in SS is one of the symbols +, -, > and <. He chose a pair of integers (i,j)(i, j) such that 1ijN1 \leq i \leq j \leq N and ate the symbols that are the ii-th, (i+1)(i+1)-th, ......, jj-th characters in SS, in this order. We heard that, after he finished eating, the sequence AA became the same as if he had eaten all the symbols in SS from first to last. How many such possible pairs (i,j)(i, j) are there?

Constraints

  • 1N2500001 \leq N \leq 250000
  • S=N|S| = N
  • Each character in SS is +, -, > or <.

Input

Input is given from Standard Input in the following format:

NN

SS

Output

Print the answer.

5
+>+<-
3

If Takahashi eats all the symbols in SS, A1=1A_1 = 1 and all other elements would be 00. The pairs (i,j)(i, j) that leads to the same sequence AA are as follows:

  • (1,5)(1, 5)
  • (2,3)(2, 3)
  • (2,4)(2, 4)
5
+>+-<
5

Note that the value of PP may be different from the value when Takahashi eats all the symbols in SS.

48
-+><<><><><>>>+-<<>->>><<><<-+<>><+<<>+><-+->><<
475