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
#ifdef xay5421
#define D(...) fprintf(stderr,__VA_ARGS__)
#else
#define D(...) ((void)0)
#define NDEBUG
#endif
#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)
using namespace std;
typedef long long LL;
const int N=250005,K=6,P=1e9+9,X[K]={137,197,101,103,107,109};
int n,key[K],iX[K],k[N][K],b[N][K];
LL ans;
map<vector<int>,int>mp;
int fpow(int k1,int k2){
	int k3=1;
	for(;k2;k2>>=1,k1=1LL*k1*k1%P)if(k2&1)k3=1LL*k3*k1%P;
	return k3;
}
void pt(const vector<int>&a){
	for(auto x:a)D("%d ",x);
	D("\n");
}
char s[N];
int main(){
#ifdef xay5421
	freopen("a.in","r",stdin);
#endif
	rep(i,0,K-1)iX[i]=fpow(X[i],P-2);
	scanf("%d%s",&n,s+1);
	per(i,n,1){
		rep(j,0,K-1){
			switch(s[i]){
				case'<':
					key[j]=1LL*key[j]*iX[j]%P;
					break;
				case'>':
					key[j]=1LL*key[j]*X[j]%P;
					break;
				case'+':
					key[j]=(key[j]+1)%P;
					break;
				case'-':
					key[j]=(key[j]+P-1)%P;
					break;
			}
		}
	}
	rep(j,0,K-1)k[n+1][j]=1;
	per(i,n,1){
		rep(j,0,K-1){
			k[i][j]=k[i+1][j];
			b[i][j]=b[i+1][j];
			switch(s[i]){
				case'<':
					k[i][j]=1LL*k[i][j]*X[j]%P;
					break;
				case'>':
					k[i][j]=1LL*k[i][j]*iX[j]%P;
					break;
				case'+':
					b[i][j]=(b[i][j]+P-k[i][j])%P;
					break;
				case'-':
					b[i][j]=(b[i][j]+k[i][j])%P;
					break;
			}
		}
	}
	auto get0=[&](int i){
		return vector<int>(b[i],b[i]+K);
	};
	auto get=[&](int i){
		vector<int>res(K);
		rep(j,0,K-1)res[j]=(1LL*k[i][j]*key[j]+b[i][j])%P;
		return res;
	};
	mp[get0(n+1)]=1;
	per(i,n,1){
		auto now=get(i);
		//pt(now);
		if(mp.count(now)){
			D("ans[%d]=%d\n",i,mp[now]);
			ans+=mp[now];
		}
		++mp[get0(i)];
	}
	printf("%lld\n",ans);
	return 0;
}