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
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;



ll pw(ll a, ll b, ll MOD) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
const ll M1 = ll(1e9) + 7;
const ll M2 = ll(1e9) + 9;

struct hsh {

	ll a, b;
	hsh() {a = b = 0;}
	hsh(ll x) {
		a = x % M1;
		b = x % M2;
	}
	hsh(ll A, ll B) {
		a = A % M1;
		b = B % M2;
	}
	hsh operator+(hsh x) {
		return hsh(a + x.a, b + x.b);
	}
	hsh operator-(hsh x) {
		return hsh(a - x.a + M1, b - x.b + M2);
	}
	hsh operator*(hsh x) {
		return hsh(a * x.a % M1, b * x.b % M2);
	}
	ll get() {
		return a * M2 + b;
	}
};

hsh P = 1000003;
hsh BP = hsh(pw(P.a, M1 - 2, M1), pw(P.b, M2 - 2, M2));

int n;
string s;

const int MX = 3000000;

int pos[MX];

hsh hs[MX];

hsh hst[MX];

map<ll, int> mm;

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n;
	cin >> s;
	pos[0] = 0;
	hst[0] = 1;
	int cur = 0;
	for (int i = 0; i < n; ++i) {
		hst[i + 1] = hst[i];
		if (s[i] == '<')
			--cur, hst[i + 1] = hst[i + 1] * BP;
		if (s[i] == '>')
			++cur, hst[i + 1] = hst[i + 1] * P;
		pos[i + 1] = cur;
	}
	hs[n] = 0;
	for (int i = n - 1; i >= 0; --i) {
		if (s[i] == '+') {
			hs[i] = hs[i + 1] + hst[i];
		}
		else if (s[i] == '-') {
			hs[i] = hs[i + 1] - hst[i];
		}
		else {
			hs[i] = hs[i + 1];
		}
	}
	++mm[hs[n].get()];
	ll ans = 0;
	for (int i = n - 1; i >= 0; --i) {
		hsh rq = hs[i] - hs[0] * hst[i];
		ans += mm[rq.get()];
		++mm[hs[i].get()];
	}
	cout << ans << "\n";
	return 0;
}


