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:
#include<bits/stdc++.h>
const int N=500005,M1=900000011,M2=800000011;
using namespace std;
int n,now,a[N],b1[N],b2[N],w1,w2,tp,a1,a2;
char S[N];
long long ans;
map<pair<int,int>,int>mp;
inline int pls(int x,int y,int M){
	return ((x+y)%M+M)%M;
}
inline void sol(bool fl){
	now=n,w1=w2=0;
	for(int i=1;i<=n;i++){
		//cerr<<i<<"===now:"<<now<<endl;
		if(fl)mp[{pls(1ll*b1[now]*a1%M1,1ll*w1*b1[n]%M1,M1),
		pls(1ll*b2[now]*a2%M2,1ll*w2*b2[n]%M2,M2)}]++;
		//cerr<<"ins "<<pls(1ll*b1[now]*a1%M1,1ll*w1*b1[n]%M1,M1)<<','<<
		//pls(1ll*b2[now]*a2%M2,1ll*w2*b2[n]%M2,M2)<<endl;
		if(S[i]>59)now+=S[i]-61;
		else{
			//cerr<<S[i]<<"?";
			tp=44-S[i];
			w1=pls(w1,tp*b1[now],M1);
			w2=pls(w2,tp*b2[now],M2);
		}
		if(fl)ans+=mp[{1ll*w1*b1[n]%M1,1ll*w2*b2[n]%M2}];
		//cerr<<"("<<w1<<','<<w2<<")\n";
	}
}
int main(){
	//freopen("dat.txt","r",stdin);
	//cerr<<(int)'+'<<' '<<(int)'-'<<' '<<(int)'>'<<' '<<(int)'<'<<endl;
	scanf("%d%s",&n,S+1);
	b1[1]=b2[1]=1;
	for(int i=1;i<=2*n;i++)
	//b1[i+1]=1ll*b1[i]*7%M1,b2[i+1]=1ll*b2[i]*11%M2;
	b1[i+1]=1ll*b1[i]*524287%M1,b2[i+1]=1ll*b2[i]*19260817%M2;
	sol(0),a1=w1,a2=w2,//cerr<<"INI:("<<a1<<','<<a2<<")\n",
	sol(1);
	printf("%lld",ans);
}