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 ll long long
using namespace std;
const int N = 5e5 + 10;
int mod1=998244353,base1=19260817,inv1;
int mod2=353448299,base2=20000003,inv2;
int s[N], pw1[N], pw2[N], rev1[N], rev2[N];

int q_pow(int x, int y, int mod) {
  int ans = 1;
  for(; y; y >>= 1) {
    if(y & 1) ans = 1ll * ans * x % mod;
    x = 1ll * x * x % mod;
  }
  return ans;
}

int h1[N], h2[N];
typedef pair<int, int> P;
map<P, int> mp;

int main() {
  int n;
  scanf("%d", &n);
  inv1 = q_pow(base1, mod1 - 2, mod1);
  inv2 = q_pow(base2, mod2 - 2, mod2);
  pw1[0] = pw2[0] = rev1[0] = rev2[0] = 1;
  for(int i = 1; i <= (n << 1); ++i) {
    pw1[i] = 1ll * pw1[i - 1] * base1 % mod1;
    pw2[i] = 1ll * pw2[i - 1] * base2 % mod2;
    rev1[i] = 1ll * rev1[i - 1] * inv1 % mod1;
    rev2[i] = 1ll * rev2[i - 1] * inv2 % mod2;
  }
  s[0] = n;
  for(int i = 1; i <= n; ++i) {
    char ch; cin >> ch;
    if(ch == '+') {
      s[i] = s[i - 1];
      h1[i] = (h1[i - 1] + pw1[s[i]]) % mod1;
      h2[i] = (h2[i - 1] + pw2[s[i]]) % mod2;
    } else if(ch == '-') {
      s[i] = s[i - 1];
      h1[i] = (h1[i - 1] - pw1[s[i]] + mod1) % mod1;
      h2[i] = (h2[i - 1] - pw2[s[i]] + mod2) % mod2;
    } else if(ch == '>') {
      s[i] = s[i - 1] + 1;
      h1[i] = h1[i - 1];
      h2[i] = h2[i - 1];
    } else {
      s[i] = s[i - 1] - 1;
      h1[i] = h1[i - 1];
      h2[i] = h2[i - 1];
    }
    mp[P(h1[i], h2[i])]++;
  }
  ll ans = 0;
  for(int i = 1; i <= n; ++i) {
    int pos = h1[n], tmp = h2[n];
    int sit = s[i - 1] - n;
    if(sit >= 0) pos = 1ll * pos * pw1[sit] % mod1, tmp = 1ll * tmp * pw2[sit] % mod2;
    else pos = 1ll * pos * rev1[-sit] % mod1, tmp = 1ll * tmp * rev2[-sit] % mod2;
    pos = (pos + h1[i - 1]) % mod1;
    tmp = (tmp + h2[i - 1]) % mod2;
    ans += mp[P(pos, tmp)];
    mp[P(h1[i], h2[i])]--;
  }
  printf("%lld\n", ans);
  return 0;
}