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<bits/stdc++.h>
using namespace std;
typedef long long D;
const int maxn=500005,mod1=1000000007,mod2=1000000009;
int qpow(int x,int y,int mod){
	int ans=1;
	while(y){
		if(y&1)ans=D(ans)*x%mod;
		x=D(x)*x%mod;
		y>>=1;
	}
	return ans;
}
int n;
char s[maxn];
struct H{
	int a,b;
	H():a(0),b(0){}
	H(int _a,int _b):a(_a),b(_b){}
	H operator+(const H &x)const{return H((a+x.a)%mod1,(b+x.b)%mod2);}
	H operator-(const H &x)const{return H((a-x.a+mod1)%mod1,(b-x.b+mod2)%mod2);}
	H operator*(const H &x)const{return H((D)a*x.a%mod1,(D)b*x.b%mod2);}
	bool operator<(const H &x)const{return a!=x.a?a<x.a:b<x.b;}
}b,inv,f[maxn],g[maxn];
map<H,int> mp;
int main(){
	b=H(23,29),inv=H(qpow(23,mod1-2,mod1),qpow(29,mod2-2,mod2));
	scanf("%d%s",&n,s+1);
	g[0]=H(1,1);
	for(int i=1;i<=n;i++){
		f[i]=f[i-1],g[i]=g[i-1];
		if(s[i]=='+')f[i]=f[i]+g[i];
		if(s[i]=='-')f[i]=f[i]-g[i];
		if(s[i]=='<')g[i]=g[i]*inv;
		if(s[i]=='>')g[i]=g[i]*b;
		mp[f[i]]++;
	}
	D ans=0;
	for(int i=1;i<=n;i++){
		ans+=mp[f[i-1]+g[i-1]*f[n]];
		mp[f[i]]--;
	}
	printf("%lld\n",ans);
	return 0;
}