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
#include<cstdio>
#include<map>
using namespace std;

#define i64 long long int
#define u64 unsigned long long int
#define mod 10000019
#define inv 8343730571309479835LLU
int n, M;
u64 mu[555555],iv[555555],H;
char s[255555];
i64 res;

map<u64, int> Map;
void rec(int L, int R) {
	if (L == R) {
		i64 h = (s[L] == '+' ? mu[n] : s[L] == '-' ? 0 - mu[n] : 0);
		if (h == H)
			res++;
		return;
	}
	int M = (L + R) / 2;

	int cur = n;
	u64 h = 0;
	Map.clear();
	for (int i = M + 1; i <= R; i++) {
		if (s[i] == '+')
			h += mu[cur];
		else
			if (s[i] == '-')
				h -= mu[cur];
			else
			if (s[i] == '>')
					cur++;
				else
					cur--;
		Map[h] ++;
	}
	h = 0;
	cur = n;
	for (int i = M; i >= L; i--) {
		if (s[i] == '+')
			h += mu[n];
		else {
			if (s[i] == '-')
				h -= mu[n];
			else
				if (s[i] == '>') {
					cur++;
					h *= mod;
				}
				else {
					cur--;
					h *= inv;
				}
		}
		u64 h2 = H - h;
		if (cur > n)h2 *= iv[cur - n];else
			h2 *= mu[n - cur];
		if (Map.count(h2))
			res += Map[h2];
	}

	rec(L, M);
	rec(M + 1, R);
}

int main() {
	scanf("%d%s", &n,s);

	M = 2 * n + 1;
	mu[0] = iv[0] = 1;
	for (int i = 1; i < M; i++) {
		mu[i] = mu[i - 1] * mod;
		iv[i] = iv[i - 1] * inv;
	}
	
	int cur = n;

	u64 h = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == '+')
			h += mu[cur];
		else
			if (s[i] == '-')
				h -= mu[cur];
			else
				if (s[i] == '>')
					cur++;
				else
					cur--;
	}
	H = h;

	rec(0, n-1);

	printf("%lld\n", res);
	return 0;
}
