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:
//by kcz 1552920354@qq.com
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
using namespace std;

template <typename T> void chmin(T&x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long s64;
typedef unsigned long long u64;
typedef unsigned int u32;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back
#define gc (c=getchar())
int read()
{
	char c;
	while(gc<'-');
	if(c=='-')
	{
		int x=gc-'0';
		while(gc>='0')x=x*10+c-'0';
		return -x;
	}
	int x=c-'0';
	while(gc>='0')x=x*10+c-'0';
	return x;
}
#undef gc

s64 mi(s64 x,int y,int D)
{
	s64 ans=1;
	while(y)
	{
		if(y&1)ans=ans*x%D;
		x=x*x%D;y>>=1;
	}
	return ans;
}
s64 niv(s64 x,int D)
{
	return mi(x,D-2,D);
}
const int N=250000+5;
typedef pair<s64,s64> hash_t;
const int D1=998244353,D2=1e9+7;
const hash_t w=hash_t(N+5,N+7);
hash_t operator +(const hash_t &a,const hash_t &b)
{
	return hash_t((a.first+b.first)%D1,(a.second+b.second)%D2);
}
hash_t operator -(const hash_t &a,const hash_t &b)
{
	return hash_t((a.first+D1-b.first)%D1,(a.second+D2-b.second)%D2);
}
hash_t operator /(const hash_t &a,const hash_t &b)
{
	return hash_t(a.first*niv(b.first,D1)%D1,a.second*niv(b.second,D2)%D2);
}
hash_t operator *(const hash_t &a,const hash_t &b)
{
	return hash_t(a.first*b.first%D1,a.second*b.second%D2);
}

int n;
char s[N];
hash_t k[N],b[N];

int main()
{
	//freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
	cin>>n;
	scanf("%s",s+1);
	k[n+1]=hash_t(1,1);b[n+1]=hash_t(0,0);
	per(i,n,1)
	if(s[i]=='+')
	{
		k[i]=k[i+1];
		b[i]=b[i+1]+hash_t(1,1);
	}
	else
	if(s[i]=='-')
	{
		k[i]=k[i+1];
		b[i]=b[i+1]-hash_t(1,1);
	}
	else
	if(s[i]=='>')
	{
		k[i]=k[i+1]*w;
		b[i]=b[i+1]*w;
	}
	else
	{
		k[i]=k[i+1]/w;
		b[i]=b[i+1]/w;
	}

	map<hash_t,int>mp;
	s64 ans=0;
	per(i,n,1)
	{
		++mp[b[i+1]/k[i+1]];
		ans+=mp[(b[i]-b[1])/k[i]];
	}
	cout<<ans;
}