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>

#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pii pair<int, int>
#define mp make_pair
#define f first
#define ll long long
#define s second
#define vec vector<int>

using namespace std;

const int N = (int) 2e6 + 10;
const int K = (int) 1e7 + 10;
const int mod1 = (int) 1e9 + 7;
const int mod2 = (int) 1e9 + 9;
const int T = (int) 200017;

int n;
string st;
pii p[N];

void add(pii &x, pii y) {
	(x.f += y.f) %= mod1;
	if (x.f < 0) 
		x.f += mod1;
	(x.s += y.s) %= mod2;
	if (x.s < 0)
		x.s += mod2;
}

pii mult(pii x, pii y) {
	return mp(x.f * 1ll * y.f % mod1, x.s * 1ll * y.s % mod2);
}

pii hsh[N];
int pos[N];

pair<pii, int> get(int l, int r) {
	return mp(hsh[r + 1], pos[r + 1]);
}

int bp(int x, int mod) {
	int pw = mod - 2;
	int ans = 1;
	while (pw) {
		if (pw & 1) 
			ans = (ans * 1ll * x) % mod;
		x = (x * 1ll * x) % mod;
		pw /= 2;
	}
	return ans;
}

pii inv(pii x) {
	return mp(bp(x.f, mod1), bp(x.s, mod2));
}

// get(l,r)=(get(0,r)-get(0,l-1))<<pos(0, l-1)

pii shift(pii x, int val) { // to the right
	if (val > 0) {
		x = mult(x, p[val]);
	} else {
		x = mult(x, inv(p[-val]));
	}
	return x;
}

pii sum(pii x, pii y) {
	add(x, y);
	return x;
}

int main() {
	#ifdef sony
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	cin >> n >> st;
	//HASH(A) = {FOR I = [0...big_N] SUM OF A[I]*T^I % MODULO} WHERE T = PRIME > 2.5 * 10^5
	p[0] = mp(1, 1);
	for (int i = 1; i < N; i++) {
		p[i] = mult(p[i - 1], mp(T, T));
	}
	pos[0] = 2 * n;
	hsh[0] = mp(0, 0);
	vector<int> a(4 * n, 0);
	for (int i = 0; i < n; i++) {
		pos[i + 1] = pos[i];
		hsh[i + 1] = hsh[i];
		if (st[i] == '+') {
			add(hsh[i + 1], p[pos[i + 1]]);
		} else if (st[i] == '-') {
			add(hsh[i + 1], mp(-p[pos[i + 1]].f, -p[pos[i + 1]].s));
		} else if (st[i] == '>') {
			pos[i + 1]++;
		} else {
			pos[i + 1]--;
		}
	}
	pii x = get(0, n - 1).f;
	ll ans = 0;
	map<pii, int> cnt;
	for (int i = 0; i < n; i++) {
		pii y = sum(shift(x, get(0, i - 1).s - 2 * n), shift(get(0, i - 1).f, 0));
		cnt[y]++;
		pii z = shift(get(0, i).f, 0);
		ans += cnt[z];
	}
	cout << ans;
	return 0;
}