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 <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

const int mod1 = 1000000007;
const int mod2 = 1000000009; 
const int arg1 = 1519153;
const int arg2 = 1057643;
const int Maxn = 250005;

int iarg1, iarg2;
int n;
char S[Maxn];
ii A[Maxn], B[Maxn];
map <ii, int> M;
ll res;

int toPower(int a, int p, int mod)
{
	int res = 1;
	while (p) {
		if (p & 1) res = ll(res) * a % mod;
		p >>= 1; a = ll(a) * a % mod;
	}
	return res;
}

int Inv(int a, int mod) { return toPower(a, mod - 2, mod); }

int main()
{
	iarg1 = Inv(arg1, mod1);
	iarg2 = Inv(arg2, mod2);
	scanf("%d", &n);
	scanf("%s", S + 1);
	A[0] = ii(1, 1); B[0] = ii(0, 0);
	for (int i = 1; i <= n; i++) {
		if (S[i] == '+') { A[i] = ii(1, 1); B[i] = ii(1, 1); }
		else if (S[i] == '-') { A[i] = ii(1, 1); B[i] = ii(mod1 - 1, mod2 - 1); }
		else if (S[i] == '>') { A[i] = ii(arg1, arg2); B[i] = ii(0, 0); }
		else if (S[i] == '<') { A[i] = ii(iarg1, iarg2); B[i] = ii(0, 0); }
		B[i].first = (ll(B[i - 1].first) * A[i].first + ll(B[i].first)) % mod1;
		B[i].second = (ll(B[i - 1].second) * A[i].second + ll(B[i].second)) % mod2;
		A[i].first = ll(A[i - 1].first) * A[i].first % mod1;
		A[i].second = ll(A[i - 1].second) * A[i].second % mod2;
	}
	ii X;
	X.first = ll(B[n].first) * Inv(A[n].first, mod1) % mod1;
	X.second = ll(B[n].second) * Inv(A[n].second, mod2) % mod2;
	M[X]++;
	for (int i = 1; i <= n; i++) {
		ii ainv = ii(Inv(A[i].first, mod1), Inv(A[i].second, mod2));
		ii need;
		need.first = ll(B[i].first) * ainv.first % mod1;
		need.second = ll(B[i].second) * ainv.second % mod2;
		auto it = M.find(need);
		if (it != M.end()) res += it->second;
		M[ii(ll(X.first + B[i].first) * ainv.first % mod1, ll(X.second + B[i].second) * ainv.second % mod2)]++;
	}
	cout << res << endl;
	return 0;
}