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 <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
#include <unordered_map>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
typedef __int128 bi;
const bi MOD=1000000000000000003LL;
bi qp(bi a,bi b)
{
	bi x=1; a%=MOD;
	while(b)
	{
		if(b&1) x=x*a%MOD;
		a=a*a%MOD; b>>=1;
	}
	return x;
}
const bi g=233333,rg=qp(g,MOD-2);
pair<bi,bi> operator +
(pair<bi,bi> a,pair<bi,bi> b)
{return mp((a.fi+a.se*b.fi)%MOD,a.se*b.se%MOD);}
#define SZ 666666
int n; char str[SZ];
pair<bi,bi> sg[SZ],tg(0,1),qz[SZ];
ll ans=0;
int main()
{
	scanf("%d%s",&n,str+1);
	for(int i=1;i<=n;++i)
	{
		if(str[i]=='+') sg[i]=mp(1,1);
		else if(str[i]=='-') sg[i]=mp(MOD-1,1);
		else if(str[i]=='>') sg[i]=mp(0,g);
		else sg[i]=mp(0,rg); tg=tg+sg[i];
	}
	qz[0]=mp(0,1);
	for(int i=1;i<=n;++i) qz[i]=qz[i-1]+sg[i];
	map<ll,int> ms;
	for(int i=n;i>=0;--i)
	{ 
		//A.fi+tg.fi*A.se=C.fi
		ans+=ms[(qz[i].fi+tg.fi*qz[i].se)%MOD];
		++ms[qz[i].fi];
	}
	cout<<ans<<"\n";
}