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<cstdio>
#include<algorithm>
#include<map>
using namespace std;
const int N=250005;
const int base=20020415;
int n;char str[N];long long ans;
map<pair<int,int>,int>Map;
struct hash{
	int mod,pw[N],ipw[N],pos[N],val[N];
	int fastpow(int x,int y){
		int res=1;
		while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}
		return res;
	}
	int cal(int x){
		return x>0?pw[x]:ipw[-x];
	}
	void init(){
		pw[0]=ipw[0]=1;pw[1]=base;ipw[1]=fastpow(base,mod-2);
		for(int i=2;i<=n;++i){
			pw[i]=1ll*pw[i-1]*pw[1]%mod;
			ipw[i]=1ll*ipw[i-1]*ipw[1]%mod;
		}
		for(int i=1;i<=n;++i){
			if(str[i]=='+'){
				pos[i]=pos[i-1];
				val[i]=(val[i-1]+cal(pos[i]))%mod;
			}
			if(str[i]=='-'){
				pos[i]=pos[i-1];
				val[i]=(val[i-1]+mod-cal(pos[i]))%mod;
			}
			if(str[i]=='>'){
				pos[i]=pos[i-1]+1;
				val[i]=val[i-1];
			}
			if(str[i]=='<'){
				pos[i]=pos[i-1]-1;
				val[i]=val[i-1];
			}
		}
	}
	int get(int i){
		return (1ll*val[n]*cal(pos[i-1])+val[i-1])%mod;
	}
}S1,S2;
int main(){
	scanf("%d%s",&n,str+1);
	S1.mod=998244353;S1.init();
	S2.mod=998244853;S2.init();
	for(int i=1;i<=n;++i)++Map[{S1.val[i],S2.val[i]}];
	for(int i=1;i<=n;++i){
		int x=S1.get(i),y=S2.get(i);
		ans+=Map[{x,y}];--Map[{S1.val[i],S2.val[i]}];
	}
	printf("%lld\n",ans);
	return 0;
}
