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 lim 300000
using namespace std;
const int mod[3] = {1000000007, 998244353, 1004535809};
int n;
char s[300005];
long long A[3], base[3][600005], lsp, p, suf[3][300005], pre[3];
map<long long, int> cnt[3];
int fsp(long long bs, int p, int mod) {
    int rt = 1;
    while (p) {
        if (p & 1) rt = bs * rt % mod;
        bs = bs * bs % mod, p >>= 1;
    }
    return rt;
}

long long bs(int id, int p) { return base[id][p + lim]; }

int main() {
    for (int t = 0; t < 3; ++t) {
        for (int i = base[t][lim] = 1; i <= lim; ++i)
            base[t][lim + i] = base[t][lim + i - 1] * 250007 % mod[t];
        for (int i = 1, ny = fsp(250007, mod[t] - 2, mod[t]); i <= lim; ++i)
            base[t][lim - i] = base[t][lim - i + 1] * ny % mod[t];
    }
    scanf("%d%s", &n, s + 1), p = 0;
    for (int i = 1; i <= n; ++i) {
        if (s[i] == '>') ++p;
        if (s[i] == '<') --p;
        for (int t = 0; t < 3; ++t) {
            if (s[i] == '+') (A[t] += bs(t, p)) %= mod[t];
            if (s[i] == '-') (A[t] += mod[t] - bs(t, p)) % mod[t];
        }
    }

    for (int t = 0; t < 3; ++t) ++cnt[t][suf[t][n + 1] = 0];
    for (int i = n; i > 1; --i) {
        for (int t = 0; t < 3; ++t) suf[t][i] = suf[t][i + 1];
        if (s[i] == '>') --p;
        if (s[i] == '<') ++p;
        for (int t = 0; t < 3; ++t) {
            if (s[i] == '+') (suf[t][i] += bs(t, p)) %= mod[t];
            if (s[i] == '-') (suf[t][i] += mod[t] - bs(t, p)) %= mod[t];
            ++cnt[t][suf[t][i]];
        }
    }

    long long res = min(min(cnt[0][0], cnt[1][0]), cnt[2][0]);
    p = 0;
    for (int i = 1; i <= n; ++i) {
        if (s[i] == '>') ++p;
        if (s[i] == '<') --p;
        int tmp = 1000000;
        for (int t = 0; t < 3; ++t) {
            int m = mod[t];
            if (s[i] == '+') (pre[t] += bs(t, p)) %= m;
            if (s[i] == '-') (pre[t] += mod[t] - bs(t, p)) % m;
            --cnt[t][suf[t][i + 1]];
            tmp = min(
                tmp,
                cnt[t][((A[t] - pre[t] - A[t] * bs(t, p) % m) % m + m) % m]);
        }
        res += tmp;
    }
    printf("%lld\n", res);
    return 0;
}