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 <iostream>
#include<bits/stdc++.h>
using namespace std;
 
#define MAX 250002

template<typename ty,typename ty2>
struct my_hash_map{
	#define hash_map_MX ((1<<20)-1)
	int head[hash_map_MX+2];
	int nex[hash_map_MX+2];
	ty key[hash_map_MX+2];
	ty2 assoc_val[hash_map_MX+2];
	int tot;
	my_hash_map(){
		tot=0;
		memset(head,-1,sizeof(head));
		memset(nex,-1,sizeof(nex));
	}
	inline ty2* find(ty val){
		int km=(val&hash_map_MX);
		if(head[km]==-1){
			head[km]=tot++;
			key[head[km]]=val;
			return &assoc_val[tot-1];
		}
		for(int i=head[km];;i=nex[i]){
			if(key[i]==val)return &assoc_val[i];
			if(nex[i]==-1){
				nex[i]=tot++;
				key[nex[i]]=val;
				return &assoc_val[tot-1];
			}
		}
		return NULL;
	}
};

my_hash_map<__int128,int> mp;

int n;
 
char buf[MAX];
 
__int128 mod1=1007ll;
__int128 mod2=1000000000000000031LL;
 
inline __int128 mul(__int128 a,__int128 b){
	return (a*b)%mod2;
}
inline __int128 add(__int128 a,__int128 b){
	auto f=a+b;
	if(f>=mod2)f%=mod2;
	return f;
}
inline __int128 sub(__int128 a,__int128 b){
	auto f=a-b;
	if(f<0)f+=mod2;
	f%=mod2;
	return f;
}
__int128 ppow(__int128 a,__int128 b){
	__int128 res=1;
	while(b){
		if(b&1LL)res*=a;
		if(res>=mod2)res%=mod2;
		a*=a;
		a%=mod2;
		b>>=1LL;
	}
	return res;
}
vector<pair<__int128,__int128> > v;
int main() {
	cin>>n;
	scanf("%s",buf);
	auto inv = ppow(mod1,mod2-2);
	__int128 cur=1;
	__int128 hs=0;
	int sz=strlen(buf);
	v.push_back(make_pair(0,1));
	for(int i=0;i<sz;i++){
		if(buf[i]=='<'){
			cur=mul(cur,inv);
		}
		if(buf[i]=='>'){
			cur=mul(cur,mod1);
		}
		if(buf[i]=='+'){
			hs=add(hs,cur);
		}
		if(buf[i]=='-'){
			hs=sub(hs,cur);
		}
		v.push_back(make_pair(hs,cur));
	}
	__int128 acieve=v.back().first;
	//(x-c)/second=acieve
	//x-c=acieve/second
	//x = c+ acieve/second
	long long int way=0;
	for(int i=v.size()-1;i>=0;i--){
		__int128 want=add(v[i].first,mul(acieve,v[i].second));
		way+=(*mp.find(want));
		(*mp.find(v[i].first))++;
		//cerr<<i<<" "<<way<<endl;
	}
	printf("%lld\n",way);
	return 0;
}
