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 <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll mod_pow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll N;
string S;
const ll K=6;
ll A[6][250010],B[6][250010];
vector<ll> C[250010];
map<vector<ll>,ll> cnt;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  vector<ll> xs{452,8112,5734,56343,8766754,64537};

  cin>>N>>S;
  ll res=0;
  rep(k,K)A[k][N]=1;
  rep(k,K)C[N].push_back(0);
  for(ll j=N-1;j>=0;j--){
    rep(i,K){
      if(S[j]=='+'){
        A[i][j]=A[i][j+1];
        B[i][j]=(B[i][j+1]+1)%mod;
      }else if(S[j]=='-'){
        A[i][j]=A[i][j+1];
        B[i][j]=(B[i][j+1]+mod-1)%mod;
      }else if(S[j]=='>'){
        A[i][j]=A[i][j+1]*mod_pow(xs[i],mod-2)%mod;
        B[i][j]=B[i][j+1]*mod_pow(xs[i],mod-2)%mod;
      }else if(S[j]=='<'){
        A[i][j]=A[i][j+1]*xs[i]%mod;
        B[i][j]=B[i][j+1]*xs[i]%mod;
      }
      C[j].push_back(B[i][j]*mod_pow(A[i][j],mod-2)%mod);
    }
  }

  for(ll i=N;i>=0;i--){
    vector<ll> nc;
    rep(k,K){
      nc.push_back(((B[k][i]-B[k][0]+mod)%mod)*mod_pow(A[k][i],mod-2)%mod);
    }

    res+=cnt[nc];
    cnt[C[i]]++;
  }

  cout<<res<<endl;

  return 0;
}
