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>
using namespace std;
typedef long long ll;
const int N=3e5+5,mod1=998244353,mod2=1000000007,mod3=2333;
int n,x=799633,invx1,invx2,invx3;
ll sum1=1,sum2=1,sum3=1;
ll s1[N],s2[N],s3[N];
char s[N];
ll inv(ll x,ll mod){return x==1?x:(mod-mod/x)*inv(mod%x,mod)%mod;}
struct node
{
    ll s1,s2,s3;
    node(ll s1=0,ll s2=0,ll s3=0):s1(s1),s2(s2),s3(s3){}
    void add()
    { s1=(s1+sum1)%mod1;s2=(s2+sum2)%mod2;s3=(s3+sum3)%mod3;}
    void sub()
    { s1=(s1+mod1-sum1)%mod1;s2=(s2+mod2-sum2)%mod2;s3=(s3+mod3-sum3)%mod3;}
    bool operator<(const node&o)const
    {
        if(s1==o.s1&&s2==o.s2) return s3<o.s3;
        if(s1==o.s1) return s2<o.s2;
        return s1<o.s1;
    }
};
void div()
{
    sum1=sum1*invx1%mod1;
    sum2=sum2*invx2%mod2;
    sum3=sum3*invx3%mod3;
}
void mul()
{
    sum1=sum1*x%mod1;
    sum2=sum2*x%mod2;
    sum3=sum3*x%mod3;
}
node f[N];
map<node,int>mp;
int main()
{
    invx1=inv(x%mod1,mod1);
    invx2=inv(x%mod2,mod2);
    invx3=inv(x%mod3,mod3);
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++)
    {
        f[i]=f[i-1];
        if(s[i]=='>') div();
        if(s[i]=='<') mul();
        if(s[i]=='+') f[i].add();
        if(s[i]=='-') f[i].sub();
        mp[f[i]]++;
    }
    sum1=sum2=sum3=1;
    node now;
    ll ans=mp[f[n]];
    for(int i=1;i<=n;i++)
    {
        mp[f[i]]--;
        if(s[i]=='>') div();
        if(s[i]=='<') mul();
        if(s[i]=='+') now.add();
        if(s[i]=='-') now.sub();
        node p=now;
        p.s1=(p.s1+f[n].s1*sum1)%mod1;
        p.s2=(p.s2+f[n].s2*sum2)%mod2;
        p.s3=(p.s3+f[n].s3*sum3)%mod3;
        ans+=mp[p];
    }
    printf("%lld\n",ans);
}
