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;
const int mod=1e9+7;
int qpow(int x,int k)
{
    int r=1;
    while(k)
    {
        if(k&1)r=1ll*r*x%mod;
        k>>=1;x=1ll*x*x%mod;
    }
    return r;
}
int add(int x,int y){return x+y<mod?x+y:x+y-mod;}
int n;
char s[300300];

int X[6]={233,1919,114514,817,1001,9527};
int inv[6];
struct Node {
    int v[6];
    bool operator < (const Node &o)const{
        for(int i=0;i<6;++i)
            if(v[i]!=o.v[i])return v[i]<o.v[i];
        return 0;
    }
    void clear(){memset(v,0,sizeof(v));}
    void f(char c)
    {
        if(c=='+') for(int i=0;i<6;++i)v[i]=add(v[i],1);
        else if(c=='-') for(int i=0;i<6;++i)v[i]=add(v[i],mod-1);
        else if(c=='>') for(int i=0;i<6;++i)v[i]=1ll*v[i]*X[i]%mod;
        else if(c=='<') for(int i=0;i<6;++i)v[i]=1ll*v[i]*inv[i]%mod;
    }
};
map<Node,int>mp;
struct PNN{
    Node k,b;
    void clear() { for(int i=0;i<6;++i)k.v[i]=1,b.v[i]=0; }
    void f(char c)
    {
        if(c=='+')for(int i=0;i<6;++i)b.v[i]=add(b.v[i],mod-k.v[i]);
        else if(c=='-')for(int i=0;i<6;++i)b.v[i]=add(b.v[i],k.v[i]);
        else if(c=='>')for(int i=0;i<6;++i)k.v[i]=1ll*k.v[i]*inv[i]%mod;
        else if(c=='<')for(int i=0;i<6;++i)k.v[i]=1ll*k.v[i]*X[i]%mod;
    }
    Node calc(Node x)
    {
        Node res;
        for(int i=0;i<6;++i)
            res.v[i]=add(1ll*k.v[i]*x.v[i]%mod,b.v[i])%mod;
        return res;
    }
};
int main()
{
    for(int i=0;i<6;++i)inv[i]=qpow(X[i],mod-2);
    scanf("%d",&n);
    scanf("%s",s+1);
    Node C;C.clear();
    for(int i=n;i;--i)C.f(s[i]);
    Node o;o.clear();
    mp[o]++;
    PNN cur;cur.clear();
    long long ans=0;
    for(int i=n;i;--i)
    {
        cur.f(s[i]);
        Node tt=cur.calc(C);
        ans+=mp[cur.calc(C)];
        mp[cur.calc(o)]++;
    }
    printf("%lld\n",ans);
    return 0;
}
