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<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<cmath>
#define MN 250005
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll M1=233;
const ll mod=4179340454199820289ll;
void add(ll &x,ll y){(x+=y)>=mod?x-=mod:0;}
void dec(ll &x,ll y){(x-=y)<0?x+=mod:0;}/*
ull mul(ull x, ull y)
{
	x = (x % mod + mod) % mod;
	y = (y % mod + mod) % mod;
	return (x * y - (ll)((long double)x / mod * y) * mod + mod) % mod;
}*/
ll mul(ll x,ll y){
	ll tmp=0;
	while(y){
		if(y&1)add(tmp,x);
		add(x,x);y>>=1;
	}return tmp;
}
ll qpow(ll x,ll y){
	ll tmp=1;
	while(y){
		if(y&1)tmp=mul(tmp,x);
		x=mul(x,x);y>>=1;
	}return tmp;
}
int n,pos[MN];char s[MN];
map<ll,int> mp;
ll lh[MN],rh[MN],fac[MN<<1],ans;
int main(){
	scanf("%d%s",&n,s+1);/*fac[0]=1;
	for(int i=1;i<=2*n;i++)fac[i]=mul(fac[i-1],M1);
	for(int i=1;i<=n;i++){
		pos[i]=pos[i-1],lh[i]=lh[i-1];
		if(s[i]=='<')pos[i]++;
		else if(s[i]=='>')pos[i]--;
		else if(s[i]=='+')add(lh[i],fac[n+pos[i]]);
		else if(s[i]=='-')dec(lh[i],fac[n+pos[i]]);
		mp[lh[i]]++;
	}ans+=mp[lh[n]];ull tmp=lh[n];
	for(int i=1;i<=n;i++){
		if(s[i]=='<')tmp=mul(tmp,M1);
		else if(s[i]=='>')tmp=mul(tmp,inv);
		else if(s[i]=='+')add(tmp,fac[n+pos[i]]);
		else dec(tmp,fac[n+pos[i]]);
		ans+=mp[tmp];mp[lh[i]]--;
	}*/ll X=1,Y=0,x=M1,y=qpow(x,mod-2);
	for(int i=1;i<=n;++i)
	{
		lh[i]=lh[i-1];
		if(s[i]=='+')add(lh[i],X);
		if(s[i]=='-')dec(lh[i],X);
		if(s[i]=='<')X=mul(X,x);
		if(s[i]=='>')X=mul(X,y);
		++mp[lh[i]];
	}X=1;
	for(int i=1;i<=n;++i)
	{
		ll tmp=mul(lh[n],X);add(tmp,Y);
		ans+=mp[tmp];
		if(s[i]=='+')add(Y,X);
		if(s[i]=='-')dec(Y,X);
		if(s[i]=='<')X=mul(X,x);
		if(s[i]=='>')X=mul(X,y);
		--mp[lh[i]];
	}
	printf("%lld\n",ans);
}