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;
#define MAXN 250000
#define ll long long
#define rint register int
inline int read(){int r;int s=0,c;for(;!isdigit(c=getchar());s=c);for(r=c^48;isdigit(c=getchar());(r*=10)+=c^48);return s^45?r:-r;}
#define BS 998244353
#define EV1 669690699
#define EV2 679604188
#define MOD1 1004535809
#define MOD2 1061109589
struct Hash
{
	int h1,h2; Hash(){} Hash(int _h1, int _h2){h1=_h1;h2=_h2;} inline Hash operator + (Hash b){return Hash((h1+b.h1)%MOD1,(h2+b.h2)%MOD2);} inline ll v(){return (ll)h1<<32|h2;}
	inline Hash operator - (Hash b){return Hash((h1+MOD1-b.h1)%MOD1,(h2+MOD2-b.h2)%MOD2);} inline Hash operator * (Hash b){return Hash(1ll*h1*b.h1%MOD1,1ll*h2*b.h2%MOD2);}
}P[MAXN+5], H[MAXN+5], B(BS,BS), E(EV1,EV2), I(1,1), _; char s[MAXN+5]; int n; unordered_map<ll,int> G; ll Ans;
int main()
{
	n = read(); scanf("%s",s+1); P[0] = I; for(rint i = 1; i <= n; i++) switch(P[i]=P[i-1],H[i]=H[i-1],s[i]){case'<':P[i]=P[i]*E;break;case'>':P[i]=P[i]*B;break;case'+':H[i]=H[i]+P[i];break;case'-':H[i]=H[i]-P[i];break;}
	for(rint i = n; i; ++G[H[i].v()], Ans += G[(H[n]*P[i-1]+H[i-1]).v()], i--); return !printf("%lld\n",Ans);
}