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>
#define va first.first
#define vb first.second
#define vc second.first
#define vd second.second
using namespace std;

using ll = unsigned long long;
const size_t mod = 1e9 + 7;
const size_t b[2] = {23, 29};

size_t Pow(size_t x, int n){
    if(n < 0) n = mod - 1 + n;
    size_t ret = 1, pv = x;
    for(;n;n>>=1){
        if(n & 1) ret = 1LL * ret * pv % mod;
        pv = 1LL * pv * pv % mod;
    }
    return ret;
}

int P[250005];
ll V[250005][2];
string S, T;
int n;
unordered_map<ll,int> m;

ll H(size_t b1, size_t b2){
    return ll(b1) << 32ll | b2;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin >> n;
    cin >> S;
    T = "*";
    T += S;
    for(int i = 1; i <= n; i++){
        switch(T[i]){
        case '+':
            P[i] = P[i-1];
            for(int k = 0; k < 2; k++) V[i][k] = (V[i-1][k] + Pow(b[k], P[i])) % mod;
            break;
        case '-':
            P[i] = P[i-1];
            for(int k = 0; k < 2; k++) V[i][k] = (V[i-1][k] + mod - Pow(b[k], P[i])) % mod;
            break;
        case '>':
            P[i] = P[i-1] + 1;
            for(int k = 0; k < 2; k++) V[i][k] = V[i-1][k];
            break;
        case '<':
            P[i] = P[i-1] - 1;
            for(int k = 0; k < 2; k++) V[i][k] = V[i-1][k];
            break;
        }
    }
    ll ans = 0;
    m[H(V[n][0],V[n][1])]++;
    for(int i = 1; i <= n; i++){
        ans += m[H(V[i][0],V[i][1])];
        size_t v0 = (Pow(b[0],P[i]) * V[n][0] + V[i][0])%mod;
        size_t v1 = (Pow(b[1],P[i]) * V[n][1] + V[i][1])%mod;
        ll key = H(v0,v1);
        //cout << "i : " << v0 << " " << v1 << '\n';
        m[H(v0,v1)]++;
    }
    cout << ans << '\n';
}