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 <stdio.h>
#include <map>
using namespace std;
char s[250002];
pair<int,int> pw[500001],prefix[250001];
int pos[250001];
const int MOD=1002068539;
int qpow(int a,int b)
{
    int ret=1;
    for (;b;a=(long long)a*a%MOD,b>>=1)
        if (b&1)
            ret=(long long)ret*a%MOD;
    return ret;
}
void madd(int &a,int b)
{
    a+=b;
    if (a>=MOD)
        a-=MOD;
}
void madd(pair<int,int> &a,pair<int,int> b)
{
    madd(a.first,b.first);
    madd(a.second,b.second);
}
void msubtract(int &a,int b)
{
    a-=b;
    if (a<0)
        a+=MOD;
}
void msubtract(pair<int,int> &a,pair<int,int> b)
{
    msubtract(a.first,b.first);
    msubtract(a.second,b.second);
}
void mmultiply(pair<int,int> &a,pair<int,int> b)
{
    a.first=(long long)a.first*b.first%MOD;
    a.second=(long long)a.second*b.second%MOD;
}
int main()
{
    int n;
    scanf("%d%s",&n,s+1);
    pw[0]=make_pair(1,1);
    for (int i=1;i<=500000;++i)
    {
        pw[i]=pw[i-1];
        mmultiply(pw[i],make_pair(35748299,19260817));
    }
    pos[0]=0;
    for (int i=1;i<=n;++i)
    {
        prefix[i]=prefix[i-1];
        pos[i]=pos[i-1];
        if (s[i]=='<')
            --pos[i];
        else if (s[i]=='>')
            ++pos[i];
        else if (s[i]=='+')
            madd(prefix[i],pw[pos[i]+250000]);
        else
            msubtract(prefix[i],pw[pos[i]+250000]);
    }
    long long ans=0;
    map<pair<int,int>,int> mp;
    for (int i=n;i>=1;--i)
    {
        pair<int,int> tmp=prefix[n];
        msubtract(tmp,prefix[i]);
        ++mp[tmp];
        tmp=prefix[n];
        if (pos[i-1]>0)
            mmultiply(tmp,make_pair(pw[pos[i-1]].first,pw[pos[i-1]].second));
        else if (pos[i-1]<0)
            mmultiply(tmp,make_pair(qpow(pw[-pos[i-1]].first,MOD-2),qpow(pw[-pos[i-1]].second,MOD-2)));
        pair<int,int> search=prefix[n];
        msubtract(search,tmp);
        msubtract(search,prefix[i-1]);
        ans+=mp[search];
    }
    printf("%lld\n",ans);
    return 0;
}