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 <bits/stdc++.h>
#define R return
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
using namespace std;
typedef long long L;
const int N=3e5+50;
const L P=1000000000000000031LL,X=1000000000000000003LL;
L add(L a,L b){ a+=b; R a>=P?a-P:a; }
L sub(L a,L b){ a-=b; R a<0?a+P:a; }
L mul(L a,L b){ L r=0LL;for(;b;b>>=1LL,a=add(a,a))if(b&1LL)r=add(r,a);return r;}
L pw(L a,L k){  L r=1LL;for(;k;k>>=1LL,a=mul(a,a))if(k&1LL)r=mul(r,a);return r;}
L I=pw(X,P-2); 

char s[N]; 
L ans,n,A[N],B[N],u;
L f(char c,L x){
	if(c=='+')R add(x,1); 
	if(c=='-')R sub(x,1); 
	if(c=='<')R mul(x,I);
	if(c=='>')R mul(x,X); 
	exit(-1);
}
void g(char c,L &a,L &b){
	if(c=='+')b=sub(b,a);
	if(c=='-')b=add(b,a);
	if(c=='<')a=mul(a,X);
	if(c=='>')a=mul(a,I); 
}
L F(L a,L b,L x){ R add(mul(a,x),b); }
map<L,L> M;
int main(){
	scanf("%lld%s",&n,s+1); 
	dec(i,n,1)u=f(s[i],u); 
	A[n+1]=1,B[n+1]=0; dec(i,n,1)g(s[i],A[i]=A[i+1],B[i]=B[i+1]); 
	++M[F(A[n+1],B[n+1],0)]; dec(i,n,1)ans+=M[F(A[i],B[i],u)],++M[F(A[i],B[i],0)];
	printf("%lld\n",ans);
	R 0;
}
