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;
const int maxn = 3e5, mod = 1e9 + 9;
int sd[6], isd[6];
int n, res[6];
char s[maxn + 10];
map<ll, int> mp;
ll ans;

int fpow(int x, int y) {
	int ans = 1;
	while (y) {
		if (y & 1) ans = 1ll * ans * x % mod;
		y >>= 1; x = 1ll * x * x % mod;
	}
	return ans;
}

struct data {
	int k[6], b[6];

	ll getans() {
		ll x = 0, y = 0;
		for (int i = 0; i < 6; ++i) {
			int w = 1ll * (res[i] - b[i] + mod) * fpow(k[i], mod - 2) % mod;
			if (i < 3)
				(x += 1ll * w * (i + 1) % mod) %= mod;
			else
				(y += 1ll * w * (i + 1) % mod) %= mod;
		}
		return x | (y << 32ll);
	}

	ll hsh() {
		ll x = 0, y = 0;
		for (int i = 0; i < 6; ++i) {
			if (i < 3) 
				(x += 1ll * b[i] * (i + 1) % mod) %= mod;
			else 
				(y += 1ll * b[i] * (i + 1) % mod) %= mod;
		}
		return x | (y << 32ll);
	}

	void init() {
		for (int i = 0; i < 6; ++i) {
			k[i] = 1; b[i] = 0;
		}
	}

}s1[maxn + 10], s2[maxn + 10];

data operator + (const data &a, const data &b) {
	data ans;
	for (int i = 0; i < 6; ++i) {
		ans.k[i] = 1ll * a.k[i] * b.k[i] % mod;
		ans.b[i] = (b.b[i] + 1ll * a.b[i] * b.k[i]) % mod;
	}
	return ans;
}

data inv(const data &a) {
	data ans;
	for (int i = 0; i < 6; ++i) {
		ans.k[i] = fpow(a.k[i], mod - 2);
		ans.b[i] = (mod - 1ll * ans.k[i] * a.b[i] % mod) % mod;
	}
	return ans;
}

int main() {
	scanf("%d", &n);
	scanf("%s", s + 1);
	for (int i = 0; i < 6; ++i) {
		sd[i] = rand() % mod;
		isd[i] = fpow(sd[i], mod - 2);
	}
	s1[0].init(); s2[0].init();
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < 6; ++j)
			if (s[i] == '+') {
				s1[i].k[j] = 1;
				s1[i].b[j] = 1;
			} else if (s[i] == '-') {
				s1[i].k[j] = 1;
				s1[i].b[j] = mod - 1;
			} else if (s[i] == '>') {
				s1[i].k[j] = sd[j];
				s1[i].b[j] = 0;
			} else if (s[i] == '<') {
				s1[i].k[j] = isd[j];
				s1[i].b[j] = 0;
			}
		s2[i] = inv(s1[i]);
		s1[i] = s1[i] + s1[i - 1];
		s2[i] = s2[i - 1] + s2[i];
	}
	for (int i = 0; i < 6; ++i) res[i] = s1[n].b[i];
	for (int i = 1; i <= n; ++i) {
		++mp[s2[i - 1].getans()];
		ans += mp[s1[i].hsh()];
	}
	printf("%lld", ans);
}
