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 INF 1061109567
#define int long long
#define pb push_back
#define in(s) freopen(s,"r",stdin);
#define out(s) freopen(s,"w",stdout);
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
const int N = 5e5 + 10;
const int mod1 = 1e9 + 7, mod2 = 1e9 + 9, base = 121448;
typedef pair<int, int> ii;
int n, h[N][2], pw[N][2];
string s;
map<ii, int> mp;
void add(int &x, int y, int mod) {
	x += y;
	if (x >= mod) x -= mod;
}
void rem(int &x, int y, int mod) {
	x -= y;
	if (x < 0) x += mod;
}
int fpow(int a, int p, int mod) {
	if (!p) return 1;
	int ans = fpow(a, p >> 1, mod);
	ans = ans * ans % mod;
	if (p & 1) ans = ans * a % mod;
	return ans;
}
int inv(int x, int mod) {
	return fpow(x, mod - 2, mod);
}
signed main() {
	#ifdef aome
	in("aome.inp");	
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> s;
	//Hash 'em. Then for a range L -> R, if the pointer at L is P, it's (h[r] - h[l - 1]) / b ^ p
	pw[0][0] = pw[0][1] = 1;
	fw (i, 1, N) {
		pw[i][0] = pw[i - 1][0] * base % mod1;
		pw[i][1] = pw[i - 1][1] * base % mod2;
	}
	int cur = 25e4 + 5;
	fw (i, 0, n) {
		h[i][0] = i ? h[i - 1][0] : 0;
		h[i][1] = i ? h[i - 1][1] : 0;
		if (s[i] == '>') cur++;
		else if (s[i] == '<') cur--;
		else if (s[i] == '+') add(h[i][0], pw[cur][0], mod1), add(h[i][1], pw[cur][1], mod2);
		else rem(h[i][0], pw[cur][0], mod1), rem(h[i][1], pw[cur][1], mod2);
		//cout << "h["<<i<<"][0] = " << h[i][0] << ", 1 = " << h[i][1] << " cur = " << cur << "\n";
		mp[ii(h[i][0], h[i][1])]++;
	}
	cur = 0;
	int ans = 0;
	ans += mp[ii(h[n - 1][0], h[n - 1][1])]; //0 -> any good points
	fw (i, 0, n) {
		if (s[i] == '>') cur++;
		else if (s[i] == '<') cur--;
		mp[ii(h[i][0], h[i][1])]--;
		int pw0, pw1;
		if (cur >= 0) pw0 = pw[cur][0], pw1 = pw[cur][1];
		else pw0 = inv(pw[-cur][0], mod1), pw1 = inv(pw[-cur][1], mod2);
		//cout << (h[n - 1][0] * pw0 + h[i][0]) % mod1 << " " << (h[n - 1][1] * pw1 + h[i][1]) % mod2 << "\n";
		ans += mp[ii((h[n - 1][0] * pw0 + h[i][0]) % mod1, (h[n - 1][1] * pw1 + h[i][1]) % mod2)];
	}
	cout << ans;
	return 0;
}