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>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define il inline
#define rg register
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define rep(i,st,ed) for(rg int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(rg int i=(ed);i>=(st);--i)
#define rep0(i,n) for(rg int i=0;i<(n);++i)
#define per0(i,n) for(rg int i=(n)-1;i>=0;--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &x,const T &y){return x<y?x:y;}
template<typename T> il T qmax(const T &x,const T &y){return x>y?x:y;}
template<typename T> il void getmin(T &x,const T &y){if(y<x) x=y;}
template<typename T> il void getmax(T &x,const T &y){if(y>x) x=y;}
il void fileio(const string &s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e18+7;
const ull base=(ull)1e8+7,inv=5840524504965430455ull;
const int N=500005;

char s[N];
ull pw[N],pwi[N];
map<ull,int> tot;
int a[N],pos[N];
ull val[N];
int n;

int main(){
	assert(base*inv==1);
	pw[0]=pwi[0]=1;
	rep(i,1,N-1){
		pw[i]=pw[i-1]*base;
		pwi[i]=pwi[i-1]*inv;
		assert(pw[i]*pwi[i]==1);
	}
//	fileio("test");
	scanf("%d%s",&n,s+1);
	int st=250001,cur=st;
	rep(i,1,n){
		if(s[i]=='<') --cur;
		else if(s[i]=='>') ++cur;
		else if(s[i]=='+') ++a[cur];
		else if(s[i]=='-') --a[cur];
		else assert(false);
		pos[i]=cur;
	}
	ull des=0;
	rep0(i,N) des+=a[i]*pw[i];
	++tot[0];
	per(i,n,1){
		val[i]=val[i+1];
		if(s[i]=='-') val[i]-=pw[pos[i]];
		else if(s[i]=='+') val[i]+=pw[pos[i]];
		++tot[val[i]];
	}
	--tot[val[1]];
	ll ans=tot[0];
//	cerr<<0<<" "<<tot[0]<<endl;
	ull sta=des;
	rep(i,1,n){
		--tot[val[i+1]];
		if(s[i]=='-') sta+=pw[pos[i]];
		else if(s[i]=='+') sta-=pw[pos[i]];
	//	cerr<<sta<<endl;
		ans+=tot[sta-des*(pos[i]>=st?pw[pos[i]-st]:pwi[st-pos[i]])];
	//	cerr<<i<<" "<<tot[sta-des*(pos[i]>=st?pw[pos[i]-st]:pwi[st-pos[i]])]<<endl;
	}
	printf("%lld\n",ans);
	return 0;
}