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 <iostream>
#include <vector>
#include <map>
#include <cstdio>

using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int) n; i ++)
 
const long long MOD = 1e9 + 7;
const long long MOD2 = 1e9 + 9;
const long long B = 23456789;

long long Pow(long long a, long long x, long long m) {
        long long res = 1;
        while (x > 0) {
                if (x & 1) res = res * a % m;
                a = a * a % m;
                x >>= 1;
        }
        return res;
}

long long Inv(long long a, long long m) { return Pow(a, m - 2, m); }
 
int main() {
	int n;
        scanf("%d", &n);
	string s;
        cin >> s;
	int x = 250000;
        int x2 = 250000;
        long long h = 0;
        long long h2 = 0;
	vector<int> xs(n + 1);
	vector<int> xs2(n + 1);
        xs[0] = x;
        xs2[0] = x2;
	vector<long long> hs(n + 1);
	vector<long long> hs2(n + 1);
        hs[0] = h;
        hs2[0] = h2;
	rep(i, n) {
		char c = s[i];
		if (c == '+') h = (h + Pow(B, x, MOD)) % MOD;
		if (c == '-') h = (h - Pow(B, x, MOD) + MOD) % MOD;
		if (c == '>') x ++;
		if (c == '<') x --;
		xs[i + 1] = x;
                hs[i + 1] = h;
		if (c == '+') h2 = (h2 + Pow(B, x2, MOD2)) % MOD2;
		if (c == '-') h2 = (h2 - Pow(B, x2, MOD2) + MOD2) % MOD2;
		if (c == '>') x2 ++;
		if (c == '<') x2 --;
		xs2[i + 1] = x2;
                hs2[i + 1] = h2;
	}
	map<pair<long long, long long>, int> cnt;
	long long ans = 0;
	for (int i = n; i >= 0; i --) {
		int dx = xs[i] - xs[0];
		long long coef = (dx >= 0 ? Pow(B, dx, MOD) : Inv(Pow(B, -dx, MOD), MOD));
		long long hoge = (hs[i] + hs[n] * coef) % MOD;
		int dx2 = xs2[i] - xs2[0];
		long long coef2 = (dx2 >= 0 ? Pow(B, dx2, MOD2) : Inv(Pow(B, -dx2, MOD2), MOD2));
		long long hoge2 = (hs2[i] + hs2[n] * coef2) % MOD2;
		ans += cnt[make_pair(hoge, hoge2)];
		cnt[make_pair(hs[i], hs2[i])] ++;
	}
        printf("%lld\n", ans);
}
