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>
using namespace std;

const int N = 280005;
const int mod1 = 1e9 + 123;
const int mod2 = 1e9 + 7;

int pw1[N + N], pw2[N + N];
int e[N];
int h1[N], h2[N];
int n;
string s;

int inverse(int a, int m) {
	int b = m - 2;
	int ret = 1;
	while(b) {
		if (b & 1) ret = 1LL * ret * a % m; a = 1LL * a * a % m;
		b >>= 1;
	}
	return ret;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> s;
	s = ' ' + s;

	pw1[0] = pw2[0] = 1;
	for (int i = 1; i < N + N; ++i) {
		pw1[i] = 1LL * pw1[i - 1] * N % mod1;
		pw2[i] = 1LL * pw2[i - 1] * N % mod2;
	}

	e[0] = N;
	for (int i = 1; i <= n; ++i) {
		h1[i] = h1[i - 1];
		h2[i] = h2[i - 1];
		e[i] = e[i - 1];
		if (s[i] == '<' || s[i] == '>') {
			e[i] += (s[i] == '>' ? +1 : -1);
		}
		else {
			h1[i] = (h1[i] + (s[i] == '+' ? +1 : -1) * pw1[e[i]]) % mod1;
			if (h1[i] < 0) h1[i] += mod1;
			h2[i] = (h2[i] + (s[i] == '+' ? +1 : -1) * pw2[e[i]]) % mod2;
			if (h2[i] < 0) h2[i] += mod2;
		}
	}

	long long res = 0;
	int t1 = 1LL * h1[n] * inverse(pw1[N], mod1) % mod1;
	int t2 = 1LL * h2[n] * inverse(pw2[N], mod2) % mod2;
	map < pair<int, int>, int > mp;
	mp[{1LL * t1 * pw1[N] % mod1, 1LL * t2 * pw2[N] % mod2}]++;

	for (int i = 1; i <= n; ++i) {
		res += mp[{h1[i], h2[i]}];
		int k1 = (1LL * t1 * pw1[e[i]] + h1[i]) % mod1;
		int k2 = (1LL * t2 * pw2[e[i]] + h2[i]) % mod2;
		mp[{k1, k2}]++;
	}

	cout << res << endl;
}