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 <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#define mod1 998244353
#define base1 19260817
#define mod2 998244853
#define base2 666623333
#define M 1000005
typedef long long ll;
int n,G[M];
std::pair <int,int> F[M];
std::map <std::pair <int,int>,int> Map;
ll ans;
int read(){
	char c=getchar();int ans=0;
	while (c<'0'||c>'9') c=getchar();
	while (c>='0'&&c<='9') ans=ans*10+c-'0',c=getchar();
	return ans;
}
int read_opt(){
	char c=getchar();
	while (c!='<'&&c!='>'&&c!='+'&&c!='-') c=getchar();
	return c=='<'?1:(c=='>'?2:(c=='+'?3:4));
}
void Write(ll x){
	if (x<10) putchar(x^48);
	else Write(x/10),putchar((x%10)^48);
	return;
}
int power(ll x,int y,int mod){
	ll ans=1;if (y<0) y+=mod-1;
	for (;y;y>>=1,x=x*x%mod)
		if (y&1) ans=ans*x%mod;
	return ans;
}
int add(int x,int y,int mod){return (x+=y)>=mod?x-mod:x;}
int sub(int x,int y,int mod){return (x-=y)<0?x+mod:x;}
int main(){
	n=read();
	for (register int i=1;i<=n;i++)
		switch (read_opt()){
			case 1:F[i]=F[i-1],G[i]=G[i-1]-1;break;
			case 2:F[i]=F[i-1],G[i]=G[i-1]+1;break;
			case 3:G[i]=G[i-1],F[i]=std::make_pair(add(F[i-1].first,power(base1,G[i],mod1),mod1),add(F[i-1].second,power(base2,G[i],mod2),mod2));break;
			case 4:G[i]=G[i-1],F[i]=std::make_pair(sub(F[i-1].first,power(base1,G[i],mod1),mod1),sub(F[i-1].second,power(base2,G[i],mod2),mod2));break;
		}
	for (register int i=n,X,Y;i>=0;++Map[F[i--]])
		X=((F[n].first+0ll)*power(base1,G[i],mod1)+F[i].first)%mod1,
		Y=((F[n].second+0ll)*power(base2,G[i],mod2)+F[i].second)%mod2,
		ans+=Map[std::make_pair(X,Y)];
	Write(ans);
	return 0;
}