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>
#define int long long
#define P(x) {if (debug) cout << x << endl;}
#define H(x) P(#x << ": " << (x))
#define FR(i,a,b) for (int i=(a); i<(b); i++)
#define F(i,n) FR(i,0,n)
#define DR(i,a,b) for (int i=(b); i-->(a);)
#define D(i,n) DR(i,0,n)
#define S(s) (int)(s).size()
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,v)
#define MA(a,v) a = max(a,v)
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
template<class T> ostream &operator<<(ostream &os, V<T> v) {
    F(i,S(v)) os<<(i?" ":"")<<v[i];
    return os;
}
const bool debug = 0;

const int A=92821, PHI=9223372036854775807, N=250005, OFF=N;

int fp(int a, int b) {
    if (b == 0) return 1;
    int rt = fp(a, b/2);
    if (b%2) return rt*rt*a;
    else return rt*rt;
}

V<int> _mem(2*OFF);

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int B = fp(A, PHI);
    H(B) H(A*B)
    int n; cin>>n;
    string s; cin>>s;
    int *p = &_mem[OFF];
    p[0] = 1;
    F(i,n) {
        p[i+1] = p[i]*A;
        p[-i-1] = p[-i]*B;
    }
    V<int> pos(n+1), val(n+1);
    pos[0] = val[0] = 0;
    F(i,n) {
        pos[i+1] = pos[i];
        val[i+1] = val[i];
        if (s[i] == '+') {
            val[i+1] += p[pos[i]];
        } else if (s[i] == '-') {
            val[i+1] -= p[pos[i]];
        } else if (s[i] == '>') {
            pos[i+1]++;
        } else {
            pos[i+1]--;
        }
    }
    map<int,int> occ;
    occ[val[n]]++;
    int tot = 0;
    D(i,n) {
        int goal = val[n] * p[pos[i]] + val[i];
        tot += occ[goal];
        occ[val[i]]++;
    }
    cout<<tot<<"\n";
}