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 signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N;
string S;
ll mo=1000000007;
vector<ll> C,R;
const int PAT=5;
vector<ll> A[PAT];
vector<ll> B[PAT];

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S;
	srand(time(NULL));
	FOR(i,PAT) {
		C.push_back(rand()%10000000+10000000);
		R.push_back(modpow(C.back()));
		A[i].push_back(1);
		B[i].push_back(0);
	}
	reverse(ALL(S));
	FORR(c,S) {
		FOR(i,PAT) {
			if(c=='+') {
				A[i].push_back(A[i].back());
				B[i].push_back((B[i].back()+1)%mo);
			}
			if(c=='-') {
				A[i].push_back(A[i].back());
				B[i].push_back((B[i].back()+mo-1)%mo);
			}
			if(c=='>') {
				A[i].push_back(A[i].back()*C[i]%mo);
				B[i].push_back(B[i].back()*R[i]%mo);
			}
			if(c=='<') {
				A[i].push_back(A[i].back()*R[i]%mo);
				B[i].push_back(B[i].back()*C[i]%mo);
			}
		}
	}
	ll ret=0;
	map<vector<ll>,int> memo;
	memo[vector<ll>(PAT,0)]++;
	FOR(j,N) {
		vector<ll> BA(PAT),BAS(PAT);
		FOR(i,PAT) {
			BA[i]=B[i][j+1]*A[i][j+1]%mo;
			BAS[i]=(B[i][j+1]+mo-B[i].back())*A[i][j+1]%mo;
		}
		ret+=memo[BAS];
		memo[BA]++;
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}