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
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=500005;
namespace{
	const int mod[2]={19260817,998244353};
	int p[N][2],rp[N][2];
	int power(int x,int t){
		return x>=0?p[x][t]:rp[-x][t];
	}
	int power(int x,int p,int mod){
		int res=1;
		for(;p;p>>=1,x=(ll)x*x%mod)
			if(p&1)res=(ll)res*x%mod;
		return res;
	}
	void init(int n){
		int A=2333,B=power(A,mod[0]-2,mod[0]);
		int C=19260817,D=power(C,mod[1]-2,mod[1]);
		p[0][0]=p[0][1]=rp[0][0]=rp[0][1]=1;
		rep(i,1,n){
			p[i][0]=(ll)p[i-1][0]*A%mod[0];
			rp[i][0]=(ll)rp[i-1][0]*B%mod[0];
			p[i][1]=(ll)p[i-1][1]*C%mod[1];
			rp[i][1]=(ll)rp[i-1][1]*D%mod[1];
		}
	}
}

int v[N][2],d[N],n;
map<pii,int> cnt;
char s[N];
ll ans;

int main(){
	read(n),init(n);
	scanf("%s",s+1);
	rep(i,1,n){
		v[i][0]=v[i-1][0];
		v[i][1]=v[i-1][1];
		d[i]=d[i-1];
		if(s[i]=='<')d[i]--;
		else if(s[i]=='>')d[i]++;
		else if(s[i]=='+')
			REP(t,2)v[i][t]=(v[i][t]+power(d[i],t))%mod[t];
		else
			REP(t,2)v[i][t]=(v[i][t]+mod[t]-power(d[i],t))%mod[t];
	}
	per(i,n-1,0){
		cnt[mp(v[i+1][0],v[i+1][1])]++;
		int A=(v[i][0]+(ll)power(d[i],0)*v[n][0])%mod[0];
		int B=(v[i][1]+(ll)power(d[i],1)*v[n][1])%mod[1];
		ans+=cnt[mp(A,B)];
	}
	cout<<ans<<endl;
	return 0;
}