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<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#include<map>
#define LL long long
#define LD long double
using namespace std;
const int NN=250000 +117;
const int MM= +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("99f.in","r",stdin);
	//freopen(".out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
map<pair<LL,LL>,int> a;
char s[NN]={};
LL mod[2]={998244353,2281701377};
LL ksm(LL a,LL b,LL mod){
	LL ret=1;
	while(b){
		if(b&1){
			ret*=a;
			ret%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return ret;
}
inline void mop(LL &x,LL y,LL mod){
	x=(x+y>=mod?x+y-mod:x+y);
}
int main(){
	//open();
	n=read();
	scanf("%s",s);
	LL res[2]={0,0};
	LL rev[2];
	rev[0]=ksm(mod[0],mod[1]-2,mod[1]);
	rev[1]=ksm(mod[1],mod[0]-2,mod[0]);
	LL p[2]={1,1};
	for(int i=0;i<n;++i){
		if(s[i]=='+'){
			for(int i=0;i<2;++i){
				mop(res[i],p[i],mod[i]);
			}
		}
		else if(s[i]=='-'){
			for(int i=0;i<2;++i){
				
				mop(res[i],mod[i]-p[i],mod[i]);
			}
		}
		else if(s[i]=='<'){
			for(int i=0;i<2;++i){
				p[i]*=rev[i^1];
				p[i]%=mod[i];
			}
		}
		else if(s[i]=='>'){
			for(int i=0;i<2;++i){
				p[i]*=mod[i^1];
				p[i]%=mod[i];
			}
		}
	}
	p[0]=1;
	p[1]=1;
	LL tp[2]={0,0};
	LL ans=0;
	for(int i=0;i<n;++i){
		a[make_pair((tp[0]+p[0]*res[0])%mod[0],(tp[1]+p[1]*res[1])%mod[1])]++;;
		if(s[i]=='+'){
			for(int i=0;i<2;++i){
				mop(tp[i],p[i],mod[i]);
			}
		}
		else if(s[i]=='-'){
			for(int i=0;i<2;++i){
				mop(tp[i],mod[i]-p[i],mod[i]);
			}
		}
		else if(s[i]=='<'){
			for(int i=0;i<2;++i){
				p[i]*=rev[i^1];
				p[i]%=mod[i];
			}
		}
		else if(s[i]=='>'){
			for(int i=0;i<2;++i){
				p[i]*=mod[i^1];
				p[i]%=mod[i];
			}
		}
		ans+=a[make_pair(tp[0],tp[1])];
	}
	printf("%lld\n",ans);
	close();
	return 0;
}