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 <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#define llint long long
#define mod 1000000007

using namespace std;

llint n;
string s;
llint a[6][250005], b[6][250005];
map<vector<llint>, llint> mp;
const llint p[] = {2, 1145143, 998244353, 101, 640099, 2172113};
llint invp[6];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

int main(void)
{
	cin >> n >> s;
	reverse(s.begin(), s.end());
	s = "#" + s;
	
	for(int i = 0; i < 6; i++){
		invp[i] = modpow(p[i], mod-2);
		a[i][0] = 1, b[i][0] = 0;
	}
	for(int z = 0; z < 6; z++){
		for(int i = 1; i <= n; i++){
			a[z][i] = a[z][i-1], b[z][i] = b[z][i-1];
			if(s[i] == '+') b[z][i]++, b[z][i] %= mod;
			if(s[i] == '-') b[z][i] += mod-1, b[z][i] %= mod;
			if(s[i] == '<'){
				a[z][i] *= p[z], a[z][i] %= mod;
				b[z][i] *= p[z], b[z][i] %= mod;
			}
			if(s[i] == '>'){
				a[z][i] *= invp[z], a[z][i] %= mod;
				b[z][i] *= invp[z], b[z][i] %= mod;
			}
		}
	}
	
	llint ans = 0;
	for(int i = 0; i <= n; i++){
		vector<llint> vec;
		for(int j = 0; j < 6; j++){
			llint tmp = (b[j][i]-b[j][n]+mod) % mod;
			tmp *= modpow(a[j][i], mod-2), tmp %= mod;
			vec.push_back(tmp);
		}
		ans += mp[vec];
		vec.clear();
		for(int j = 0; j < 6; j++) vec.push_back(b[j][i] * modpow(a[j][i], mod-2) % mod);
		mp[vec]++;
	}
	cout << ans << endl;
	
	return 0;
}