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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

const int MAXN = 250005;
const ll MOD1 = 998244353;
const ll MOD2 = 1000000007;

int n;
int p[MAXN];

ll inv1,inv2,ans;

pair<ll,ll> h[MAXN];
pair<ll,ll> pw[MAXN];
pair<ll,ll> rpw[MAXN];

char s[MAXN];

map<pair<ll,ll>,int> cnt;

ll power(ll a,ll b,ll p)
{
	ll res = 1;
	while (b)
	{
		if (b & 1)
			(res *= a) %= p;
		(a *= a) %= p;
		b >>= 1;
	}
	return res;
}

pair<ll,ll> getv(int t)
{
	return t >= 0 ? pw[t] : rpw[-t];
}

pair<ll,ll> mul(pair<ll,ll> a,pair<ll,ll> b)
{
	return make_pair(a.first * b.first % MOD1,a.second * b.second % MOD2);
}

pair<ll,ll> add(pair<ll,ll> a,pair<ll,ll> b)
{
	return make_pair((a.first + b.first) % MOD1,(a.second + b.second) % MOD2);
}

pair<ll,ll> sub(pair<ll,ll> a,pair<ll,ll> b)
{
	return make_pair((a.first - b.first) % MOD1,(a.second - b.second) % MOD2);
}

int main()
{
	scanf("%d%s",&n,s + 1);
	inv1 = power(786433,MOD1 - 2,MOD1);
	inv2 = power(786433,MOD2 - 2,MOD2);
	pw[0] = make_pair(1,1);
	for (int i = 1;i <= n;i++)
		pw[i] = mul(pw[i - 1],make_pair(786433,786433));
	rpw[0] = make_pair(1,1);
	for (int i = 1;i <= n;i++)
		rpw[i] = mul(rpw[i - 1],make_pair(inv1,inv2));
	for (int i = 1;i <= n;i++)
	{
		if (s[i] == '+')
		{
			p[i] = p[i - 1];
			h[i] = add(h[i - 1],getv(p[i]));
		}
		if (s[i] == '-')
		{
			p[i] = p[i - 1];
			h[i] = sub(h[i - 1],getv(p[i]));
		}
		if (s[i] == '<')
		{
			h[i] = h[i - 1];
			p[i] = p[i - 1] - 1;
		}
		if (s[i] == '>')
		{
			h[i] = h[i - 1];
			p[i] = p[i - 1] + 1;
		}
	}
	for (int i = n;i >= 1;i--)
	{
		(h[i].first += MOD1) %= MOD1;
		(h[i].second += MOD2) %= MOD2;
	}
	for (int i = n;i >= 1;i--)
	{
		cnt[h[i]]++;
		ans += cnt[add(mul(h[n],getv(p[i - 1])),h[i - 1])];
	}
	printf("%lld\n",ans);
	return 0;
}