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;
#define mp make_pair
#define fi first
#define se second
int n;
string s;
long long ans=0,prd[2][250007],cur1=1,cur2=1,cnt[250007];
map < pair<long long,long long> ,long long> val;
const long long mod1=1e9+7,mod2=1e9+9;
const long long base=500007;
const long long inv1=433573933, inv2=446715750;
long long pw(long long a,long long b,long long mod){
	if(b==0) return 1LL;
	if(b==1) return a;
	long long ret=pw(a,b/2,mod);
	if(b%2==0) return ret*ret%mod;
	return ret*ret%mod*a%mod;
}
int main(){
	ios_base::sync_with_stdio(0);
	//cout<<pw(base,mod1-2,mod1)<<endl;
	//cout<<pw(base,mod2-2,mod2)<<endl;
	cin>>n;
	cin>>s;
	for(int i=1;i<=n;i++){
		cnt[i]=cnt[i-1];
		prd[0][i]=prd[0][i-1];
		prd[1][i]=prd[1][i-1];
		if(s[i-1]=='>'){
			cur1=(cur1*base)%mod1;
			cur2=(cur2*base)%mod2;
			cnt[i]++;
		}
		else if(s[i-1]=='<'){
			cur1=(cur1*inv1)%mod1;
			cur2=(cur2*inv2)%mod2;
			cnt[i]--;
		}
		else if(s[i-1]=='+'){
			prd[0][i]=(prd[0][i]+cur1)%mod1;
			prd[1][i]=(prd[1][i]+cur2)%mod2;
		}
		else{
			prd[0][i]=(prd[0][i]-cur1+mod1)%mod1;
			prd[1][i]=(prd[1][i]-cur2+mod2)%mod2;
		}
	}
	for(int i=n;i>=1;i--){
		val[mp(prd[0][i],prd[1][i])]++;
		long long dif=cnt[0]-cnt[i-1];
		long long val1=0,val2=0;
		//cout<<dif<<" ";
		if(dif>=0){
			val1=(prd[0][i-1]+prd[0][n]*pw(inv1,dif,mod1)%mod1)%mod1;
			val2=(prd[1][i-1]+prd[1][n]*pw(inv2,dif,mod2)%mod2)%mod2;
		}
		else{
			val1=(prd[0][i-1]+prd[0][n]*pw(base,-dif,mod1)%mod1)%mod1;
			val2=(prd[1][i-1]+prd[1][n]*pw(base,-dif,mod2)%mod2)%mod2;
		}
		ans+=val[mp(val1,val2)];
		//cout<<ans<<endl;
	}
	cout<<ans;
}
