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<map>
using namespace std;
#define N 500200
#define mod1 1000000009
#define mod2 1000000007
#define ch1 131
#define ch2 233
map<long long,int> tp;
int pw1[N],pw2[N],n,su[N],vl[N],ha1[N],ha2[N],as1,as2;
long long as;
char s[N];
int pw(int a,int p,int mod){int as=1;while(p){if(p&1)as=1ll*as*a%mod;a=1ll*a*a%mod;p>>=1;}return as;}
int main()
{
	scanf("%d%s",&n,s+1);
	su[0]=n;
	pw1[0]=pw2[0]=1;
	for(int i=1;i<=n*2;i++)pw1[i]=1ll*pw1[i-1]*ch1%mod1,pw2[i]=1ll*pw2[i-1]*ch2%mod2;
	for(int i=1;i<=n;i++)
	{
		su[i]=su[i-1];
		if(s[i]=='<')su[i]--;
		if(s[i]=='>')su[i]++;
		if(s[i]=='+')as1=(as1+pw1[su[i]])%mod1,as2=(as2+pw2[su[i]])%mod2;
		if(s[i]=='-')as1=(as1-pw1[su[i]]+mod1)%mod1,as2=(as2-pw2[su[i]]+mod2)%mod2;
	}
	for(int i=n;i>=1;i--)ha1[i]=(ha1[i+1]+mod1+(s[i]=='+'?1ll:(s[i]=='-'?-1ll:0))*pw1[su[i]])%mod1,ha2[i]=(ha2[i+1]+mod2+(s[i]=='+'?1ll:(s[i]=='-'?-1ll:0))*pw2[su[i]])%mod2;
	tp[0]=1;
	for(int i=n;i>=1;i--)
	{
		int nas1,nas2;
		if(su[i-1]>=su[0])nas1=1ll*as1*pw1[su[i-1]-su[0]]%mod1,nas2=1ll*as2*pw2[su[i-1]-su[0]]%mod2;
		else nas1=1ll*as1*pw(pw(ch1,mod1-2,mod1),su[0]-su[i-1],mod1)%mod1,nas2=1ll*as2*pw(pw(ch2,mod2-2,mod2),su[0]-su[i-1],mod2)%mod2;
		nas1=(ha1[i]-nas1+mod1)%mod1,nas2=(ha2[i]-nas2+mod2)%mod2;
		as+=tp[nas1*10000000000ll+nas2];
		tp[ha1[i]*10000000000ll+ha2[i]]++;
	}
	printf("%lld\n",as);
}//