Problem: 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

Solution (in CPP):

Solution:
#pragma GCC optimize("trapv")
#include<bits/stdc++.h>
#define int ll
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
const int maxn = 1<<20, mod = 119<<23|1;
const int B = 299977, C = 1139123;
int n, pw[maxn], pw2[maxn], ps = 0, ans = 0;
array<ll, 2> F[maxn];
string s;
map<array<ll, 2>, int> cnt;
void add(int &a, int b) {
	a = a+b>=mod?a+b-mod:a+b;
}
ll bp(ll a, ll p) {
	ll r = 1;
	while(p) {
		if(p&1) r = r*a%mod;
		a = a*a%mod, p>>=1;
	}
	return r;
} 
signed main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> s;
	pw[0] = pw2[0] = 1;
	for(int i = 1; i < maxn; i++) pw[i] = pw[i-1]*1ll*B%mod;
	for(int i = 1; i < maxn; i++) pw2[i] = pw2[i-1]*1ll*C%mod;
	cnt[{0, 0}]++;
	array<ll, 2> cur = {0, 0};
	for(int i = 0; i < n; i++) {
		if(s[i] == '>') ps++;
		if(s[i] == '<') ps--;
		if(s[i] == '+') {
			add(cur[0], pw[(maxn/2) + ps]);
			add(cur[1], pw2[(maxn/2) + ps]);
		}
		if(s[i] == '-') {
			add(cur[0], mod-pw[(maxn/2) + ps]);
			add(cur[1], mod-pw2[(maxn/2) + ps]);
		}
		F[i+1] = cur;
		cnt[cur]++;
	}
	F[0] = {0, 0};
	ps = 0;
	array<ll, 2> ccur = {0, 0};
	for(int ps = 0, i = 0; i <= n; i++) {
		cnt[F[i]]--;
		ll X = (bp(B, mod-1+ps)*1ll*cur[0] + ccur[0])%mod;
		ll Y = (bp(C, mod-1+ps)*1ll*cur[1] + ccur[1])%mod;
		ans += cnt[{X, Y}];
		if(i == n) continue;
		if(s[i] == '>') ps++;
		if(s[i] == '<') ps--;
		if(s[i] == '+') {
			add(ccur[0], pw[(maxn/2) + ps]);
			add(ccur[1], pw2[(maxn/2) + ps]);
		}
		if(s[i] == '-') {
			add(ccur[0], mod-pw[(maxn/2) + ps]);
			add(ccur[1], mod-pw2[(maxn/2) + ps]);
		}
	}
	cout << ans << '\n';
}