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<algorithm>
#include<cstdio>
#include<map>
#define mxn 1000010
using namespace std;
const int hs[]={13,29,53,71,103,1999,13577,50177,341569,992863},iv[]={11,87,57,2792,10759,284652,16312892,8982012,583800912,300380820},md[]={71,97,151,6007,23087,616489,19260817,19491001,998244353,1000000007};
long long ans;
int n,sl,fh;
char s[mxn];
struct hsh
{
	int s[10],X[10];
}a[mxn];
struct vl
{
	int s[10];
	bool operator <(const vl &x)const
	{
		for(int i=0;i<10;++i)
			if(s[i]!=x.s[i])
				return s[i]<x.s[i];
		return 0;
	}
}N,nw,tmp;
map<vl,int> mp;
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
void upd(int &x,int y,int mod) {x+=y; if(x>=mod) x-=mod;}
void add(hsh &x) {for(int i=0;i<10;++i) upd(x.s[i],x.X[i],md[i]);}
void plu(hsh &x) {for(int i=0;i<10;++i) upd(x.s[i],md[i]-x.X[i],md[i]);}
void mul(hsh &x) {for(int i=0;i<10;++i) x.X[i]=1ll*hs[i]*x.X[i]%md[i];}
void del(hsh &x) {for(int i=0;i<10;++i) x.X[i]=1ll*iv[i]*x.X[i]%md[i];}
int main()
{
	n=rd();scanf("%s",s+1);
	for(int i=0;i<10;++i) a[0].X[i]=1;
	for(int i=1;i<=n;++i)
	{
		a[i]=a[i-1];
		if(s[i]=='+') add(a[i]);
		else if(s[i]=='-') plu(a[i]);
		else if(s[i]=='>') mul(a[i]);
		else del(a[i]);
	}
	for(int j=0;j<10;++j) N.s[j]=a[n].s[j];
	for(int i=n;i;--i)
	{
		for(int j=0;j<10;++j)
		{
			nw.s[j]=a[i].s[j];
			tmp.s[j]=(a[i-1].s[j]+1ll*N.s[j]*a[i-1].X[j])%md[j];
		}
		mp[nw]++;ans+=mp[tmp];
	}
	printf("%lld\n",ans);
	return 0;
}