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

Initially, all the elements in the sequence A in Takahashi's mind are 0, and the value of the integer P is 0.

When Takahashi eats symbols `+`, `-`, `>` and `<`, the sequence A and the integer P will change as follows:

* When he eats `+`, the value of A_P increases by 1;
* When he eats `-`, the value of A_P decreases by 1;
* When he eats `>`, the value of P increases by 1;
* When he eats `<`, the value of P decreases by 1.



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

Constraints

* 1 \leq N \leq 250000
* |S| = N
* Each character in S is `+`, `-`, `>` or `<`.

Input

Input is given from Standard Input in the following format:


N
S


Output

Print the answer.

Examples

Input

5
+>+<-


Output

3


Input

5
+>+-<


Output

5


Input

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


Output

475

Solution (in CPP):

Solution:
#include <iostream>
#include <string>
#include <map>
using namespace std;

unsigned long long N, power[500009], inv[500009], L[500009]; int bx[500009]; string S;
map<unsigned long long, int>M;

int main() {
	cin >> N >> S;
	power[0] = 1; for (int i = 1; i <= 500000; i++) power[i] = (power[i - 1] * 1000000007LL);
	inv[0] = 1; for (int i = 1; i <= 500000; i++) inv[i] = (inv[i - 1] * 13499267949257065399ULL);

	L[0] = 0; int cx = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '>') cx++;
		if (S[i] == '<') cx--;
		if (S[i] == '+') L[i + 1] += power[250000 + cx];
		if (S[i] == '-') L[i + 1] -= power[250000 + cx];
		L[i + 1] += L[i];
		bx[i + 1] = cx;
	}

	long long cnt = 0;
	for (int i = N - 1; i >= 0; i--) {
		M[L[i + 1]]++;
		unsigned long long I = L[N];
		if (bx[i] > 0) I *= power[bx[i]];
		else I *= inv[-bx[i]];

		unsigned long long J = I + L[i];
		cnt += M[J];
	}
	cout << cnt << endl;
	return 0;
}