Problem: 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

Solution (in CPP):

Solution:
//jinhaonan
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
template<class T>inline void read(T &x){
	x=0;char c=getchar();bool f=0;
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';x=(x<<1)+(x<<3)+c-'0',c=getchar());
	x=f?-x:x;
}
template<class T>inline void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x>=10)write(x/10);
	putchar(x%10+48);
}
template<class T>inline bool chkmax(T &a,T const &b){
	return a<b?a=b,1:0;
}
template<class T>inline bool chkmin(T &a,T const &b){
	return a>b?a=b,1:0;
} 
long long base=9901;
long long mo=1000000000000000031ll;
 
long long Mul(long long a,long long b){
	return (__int128)a*b%mo;
}
long long Add(long long a,long long b){
	return (a+b)%mo;
}
long long Pow(__int128 a,long long b){
	__int128 res=1;
	for(;b;b>>=1,a=a*a%mo)
		if(b&1)
			res=res*a%mo;
	return res;
}
vector<pair<long long,long long>> v;
map<long long,int> mp;
int main(){
	static char s[250000+10];
	int n;
	scanf("%d%s",&n,s);
	long long inv=Pow(base,mo-2);
	long long pos=1,val=0;
	v.push_back(make_pair(val,pos));
	for(int i=0;i<n;++i){
		if(s[i]=='<'){
			pos=Mul(pos,inv);
		}else if(s[i]=='>'){
			pos=Mul(pos,base);
		}else if(s[i]=='+'){
			val=Add(val,pos);
		}else if(s[i]=='-'){
			val=Add(val,mo-pos);
		}
		v.push_back(make_pair(val,pos));
	}
	long long V=v.back().first;
	long long ans=0;
	for(int i=v.size()-1;i>=0;--i){
		auto it=mp.find(Add(v[i].first,Mul(V,v[i].second)));
		if(it!=mp.end()){
			ans+=it->second;
		}
		++mp[v[i].first];
	}
	write(ans),putchar('\n');
	return 0;
}