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 <cstdio>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#define int long long
using namespace std;
const int N = 3e5 + 5;
const int mod[2] = {999988679, 999988609}, b[2] = {370728, 370732}, ib[2] = {396903752, 462741403};
int read() {
	int x = 0, f = 1; char ch;
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48));
	return x * f;
}
template <class T> T Max(T a, T b) { return a > b ? a : b; }
template <class T> T Min(T a, T b) { return a < b ? a : b; }
char s[N];
int n, ans, a[2][N], d[2][N];
unordered_map <int, int> t;
signed main() {
	n = read(); scanf("%s", s + 1);
	for(int j = 0; j <= 1; ++ j) a[j][0] = 0, d[j][0] = 1;
	for(int i = 1, v[2] = {1, 1}; i <= n; ++ i) {
		for(int j = 0; j <= 1; ++ j) {
			a[j][i] = a[j][i - 1];
			if(s[i] == '+') a[j][i] = (a[j][i] + v[j]) % mod[j];
			if(s[i] == '-') a[j][i] = (a[j][i] + mod[j] - v[j]) % mod[j];
			if(s[i] == '>') v[j] = v[j] * b[j] % mod[j];
			if(s[i] == '<') v[j] = v[j] * ib[j] % mod[j];
			d[j][i] = v[j];
		}
	}
	for(int i = n; i >= 0; -- i) {
		ans += t[(a[0][i] + a[0][n] * d[0][i]) % mod[0] + (a[1][i] + a[1][n] * d[1][i]) % mod[1] * mod[0]];
		++ t[a[0][i] + a[1][i] * mod[0]];
	}
	printf("%lld\n", ans);
	return 0;
}