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<algorithm>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
const long long Mod=1000000000039;
const long long base=1000003;
int n;
char s[250010];
long long a[250010],b[250010];
long long mul(long long a,long long b)
{
	long long ans=0,t=a;
	while(b)
	{
		if(b&1)ans=(ans+t)%Mod;
		t=(t+t)%Mod;
		b>>=1;
	}
	return ans;
}
long long fpow(long long a,long long b)
{
	long long ans=1,t=a;
	while(b)
	{
		if(b&1)ans=mul(ans,t);
		t=mul(t,t);
		b>>=1;
	}
	return ans;
}
map<long long,int>mp;
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	long long x=0,y=0,invbase=fpow(base,Mod-2);
	for(int i=n;i>=1;i--)
	{
		if(s[i]=='-')
			x=(x-1+Mod)%Mod;
		else if(s[i]=='+')
			x=(x+1)%Mod;
		else if(s[i]=='<')
			x=mul(x,base)%Mod;
		else x=mul(x,invbase)%Mod;
	}
	long long c=x;
	x=1;y=0;
	for(int i=n;i>=1;i--)
	{
		if(s[i]=='+')
			y=(y-x+Mod)%Mod;
		else if(s[i]=='-')
			y=(y+x)%Mod;
		else if(s[i]=='>')
			x=mul(x,base)%Mod;
		else x=mul(x,invbase)%Mod;
		b[i]=y;
		a[i]=(mul(x,c)+y)%Mod;
	}
	long long ans=0;
	for(int i=n;i>=1;i--)
	{
		mp[b[i+1]]++;
		ans+=mp[a[i]];
	}
	printf("%lld\n",ans);
	return 0;
}