    #include <iostream>
    #include<bits/stdc++.h>
    using namespace std;
     
    #define MAX 250002
    int n;
     
    char buf[MAX];
     
    __int128 mod1=1000000000000000003ll;
    __int128 mod2=1000000000000000031LL;
     
    inline __int128 mul(__int128 a,__int128 b){
    	return (a*b)%mod2;
    }
    inline __int128 add(__int128 a,__int128 b){
    	auto f=a+b;
    	if(f>=mod2)f%=mod2;
    	return f;
    }
    inline __int128 sub(__int128 a,__int128 b){
    	auto f=a-b;
    	if(f<0)f+=mod2;
    	f%=mod2;
    	return f;
    }
    __int128 ppow(__int128 a,__int128 b){
    	__int128 res=1;
    	while(b){
    		if(b&1LL)res*=a;
    		if(res>=mod2)res%=mod2;
    		b>>=1LL;
    	}
    	return res;
    }
    unordered_map<long long int,int> cnt;
    vector<pair<__int128,__int128> > v;
    int main() {
    	cin>>n;
    	scanf("%s",buf);
    	auto inv=821428571428571454ll;
    	//printf("%lld\n",inv);
    	__int128 cur=1;
    	__int128 hs=0;
    	int sz=strlen(buf);
    	v.push_back(make_pair(0,1));
    	for(int i=0;i<sz;i++){
    		if(buf[i]=='<'){
    			cur=mul(cur,inv);
    		}
    		if(buf[i]=='>'){
    			cur=mul(cur,mod1);
    		}
    		if(buf[i]=='+'){
    			hs=add(hs,cur);
    		}
    		if(buf[i]=='-'){
    			hs=sub(hs,cur);
    		}
    		v.push_back(make_pair(hs,cur));
    	}
    	__int128 acieve=v.back().first;
    	//(x-c)/second=acieve
    	//x-c=acieve/second
    	//x = c+ acieve/second
    	long long int way=0;
    	for(int i=v.size()-1;i>=0;i--){
    		__int128 want=add(v[i].first,mul(acieve,v[i].second));
    		way+=cnt[want];
    		cnt[v[i].first]++;
    		//cerr<<i<<" "<<way<<endl;
    	}
    	printf("%lld\n",way);
    	return 0;
    }

### Prompt

Please formulate a Cpp solution to the following 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

### Response

```cpp
    #include <iostream>
    #include<bits/stdc++.h>
    using namespace std;
     
    #define MAX 250002
    int n;
     
    char buf[MAX];
     
    __int128 mod1=1000000000000000003ll;
    __int128 mod2=1000000000000000031LL;
     
    inline __int128 mul(__int128 a,__int128 b){
    	return (a*b)%mod2;
    }
    inline __int128 add(__int128 a,__int128 b){
    	auto f=a+b;
    	if(f>=mod2)f%=mod2;
    	return f;
    }
    inline __int128 sub(__int128 a,__int128 b){
    	auto f=a-b;
    	if(f<0)f+=mod2;
    	f%=mod2;
    	return f;
    }
    __int128 ppow(__int128 a,__int128 b){
    	__int128 res=1;
    	while(b){
    		if(b&1LL)res*=a;
    		if(res>=mod2)res%=mod2;
    		b>>=1LL;
    	}
    	return res;
    }
    unordered_map<long long int,int> cnt;
    vector<pair<__int128,__int128> > v;
    int main() {
    	cin>>n;
    	scanf("%s",buf);
    	auto inv=821428571428571454ll;
    	//printf("%lld\n",inv);
    	__int128 cur=1;
    	__int128 hs=0;
    	int sz=strlen(buf);
    	v.push_back(make_pair(0,1));
    	for(int i=0;i<sz;i++){
    		if(buf[i]=='<'){
    			cur=mul(cur,inv);
    		}
    		if(buf[i]=='>'){
    			cur=mul(cur,mod1);
    		}
    		if(buf[i]=='+'){
    			hs=add(hs,cur);
    		}
    		if(buf[i]=='-'){
    			hs=sub(hs,cur);
    		}
    		v.push_back(make_pair(hs,cur));
    	}
    	__int128 acieve=v.back().first;
    	//(x-c)/second=acieve
    	//x-c=acieve/second
    	//x = c+ acieve/second
    	long long int way=0;
    	for(int i=v.size()-1;i>=0;i--){
    		__int128 want=add(v[i].first,mul(acieve,v[i].second));
    		way+=cnt[want];
    		cnt[v[i].first]++;
    		//cerr<<i<<" "<<way<<endl;
    	}
    	printf("%lld\n",way);
    	return 0;
    }

```