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>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
//const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll Pow(ll n,ll p,ll mod){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

ll Div(ll n,ll m,ll mod){
	return n*Pow(m,mod-2,mod)%mod;
}

const ll mod[2]={1000000007,1000000009},base[2]={1009,17};
ll inv[2];

pll f(vl a,vl b){
	pll p=make_pair(Div(b[0],a[0],mod[0]),Div(b[1],a[1],mod[1]));
	return p;
}

ll n,res=0;
string s;
vvl a,b;
map<pll,ll> mp;

int main(){
	inv[0]=Div(1,base[0],mod[0]);
	inv[1]=Div(1,base[1],mod[1]);
	cin>>n>>s;
	a=b=vvl(n+1,vl(2));
	a[n][0]=a[n][1]=1;
	for(int i=n-1;i>=0;i--) for(int j=0;j<2;j++){
		if(s[i]=='+') a[i][j]=a[i+1][j],b[i][j]=b[i+1][j]+1;
		if(s[i]=='-') a[i][j]=a[i+1][j],b[i][j]=(b[i+1][j]-1+mod[j])%mod[j];
		if(s[i]=='>') a[i][j]=a[i+1][j]*base[j]%mod[j],b[i][j]=b[i+1][j]*base[j]%mod[j];
		if(s[i]=='<') a[i][j]=a[i+1][j]*inv[j]%mod[j],b[i][j]=b[i+1][j]*inv[j]%mod[j];
	}
	mp[f(a[n],b[n])]++;
	for(int i=n-1;i>=0;i--){
		pll p;
		p.first =Div((b[i][0]-b[0][0]+mod[0])%mod[0],a[i][0],mod[0]);
		p.second=Div((b[i][1]-b[0][1]+mod[1])%mod[1],a[i][1],mod[1]);
		res+=mp[p];
		mp[f(a[i],b[i])]++;
	}
	cout<<res<<endl;
}