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
//ΔARC099F
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 266666;
const int B = 19260817;
const int MO = 1e9+21;
const int M2 = 998244353;
int fpow(int x,int y,int mo){
	if(!y)
		return 1;
	LL z=fpow(x,y>>1,mo);
	z=z*z%mo;
	if(y&1)
		z=z*x%mo;
	return z;
}
int invB=fpow(B,MO-2,MO),invB2=fpow(B,M2-2,M2);
char ch[N];
int n,a[N],f[N],f2[N],g[N],g2[N];
map<LL,int> M;
int main()
{
	int i,x,x2,y,y2;
	LL ans=0;
	cin>>n;
	scanf("%s",ch+1);
	for(i=1;i<=n;i=i+1){
		if(ch[i]=='-')
			a[i]=0;
		if(ch[i]=='+')
			a[i]=1;
		if(ch[i]=='<')
			a[i]=2;
		if(ch[i]=='>')
			a[i]=3;
	}
	x=0;
	for(i=n;i;i=i-1){
		if(a[i]==0)
			x=(x-1+MO)%MO;
		if(a[i]==1)
			x=(x+1)%MO;
		if(a[i]==2)
			x=(LL)x*invB%MO;
		if(a[i]==3)
			x=(LL)x*B%MO;
		f[i]=x;
	}
	x=0;
	for(i=n;i;i=i-1){
		if(a[i]==0)
			x=(x-1+M2)%M2;
		if(a[i]==1)
			x=(x+1)%M2;
		if(a[i]==2)
			x=(LL)x*invB2%M2;
		if(a[i]==3)
			x=(LL)x*B%M2;
		f2[i]=x;
	}
	x=0,y=1;
	for(i=n;i;i=i-1){
		if(a[i]==0)
			x=(x+y)%MO;
		if(a[i]==1)
			x=(x-y+MO)%MO;
		if(a[i]==2)
			y=(LL)y*B%MO;
		if(a[i]==3)
			y=(LL)y*invB%MO;
		g[i]=x;
	}
	x=0,y2=1;
	for(i=n;i;i=i-1){
		if(a[i]==0)
			x=(x+y2)%M2;
		if(a[i]==1)
			x=(x-y2+M2)%M2;
		if(a[i]==2)
			y2=(LL)y2*B%M2;
		if(a[i]==3)
			y2=(LL)y2*invB2%M2;
		g2[i]=x;
	}
	for(i=0;i<=n;i=i+1)
		M[(LL)g[i]<<32|g2[i]]++;
	for(i=1;i<=n;i=i+1){
		M[(LL)g[i]<<32|g2[i]]--;
		x=(f[1]-f[i]+MO)%MO;
		x=(LL)x*y%MO;
		x2=(f2[1]-f2[i]+M2)%M2;
		x2=(LL)x2*y2%M2;
		ans+=M[(LL)x<<32|x2];
		if(a[i]==2)
			y=(LL)y*invB%MO;
		if(a[i]==3)
			y=(LL)y*B%MO;
		if(a[i]==3)
			y2=(LL)y2*B%M2;
		if(a[i]==2)
			y2=(LL)y2*invB2%M2;
	}
	cout<<ans;
	return 0;
}