#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
const Int MAX = 514514;
const Int MOD1 = 1e9+7;
const Int MOD2 = 1e9+9;
const Int MOD3 = 1e8+7;
const Int BASE = 1777771;

Int po1[MAX],po2[MAX],po3[MAX];
Int op1[MAX],op2[MAX],op3[MAX];

Int mod_pow(Int x,Int n,Int mod){
  Int res=1;
  while(n){
    if(n&1) (res*=x)%=mod;
    (x*=x)%=mod;
    n>>=1;
  }
  return res;
}

Int mod_inverse2(Int a,Int mod){
  return mod_pow(a,mod-2,mod);
}

Int inv1,inv2,inv3;

using T = tuple<Int, Int, Int>;
struct HS{
  T v;
  HS():v(0,0,0){}
  HS(T v):v(v){}
  void inc(Int x){
    get<0>(v)+=po1[x];
    get<0>(v)%=MOD1;
    get<1>(v)+=po2[x];
    get<1>(v)%=MOD2;
    get<2>(v)+=po3[x];
    get<2>(v)%=MOD3;
  }
  void dec(Int x){
    get<0>(v)+=MOD1-po1[x];
    get<0>(v)%=MOD1;
    get<1>(v)+=MOD2-po2[x];
    get<1>(v)%=MOD2;
    get<2>(v)+=MOD3-po3[x];
    get<2>(v)%=MOD3;
  }
  void shl(Int k=1){
    get<0>(v)*=op1[k];
    get<0>(v)%=MOD1;
    get<1>(v)*=op2[k];
    get<1>(v)%=MOD2;
    get<2>(v)*=op3[k];
    get<2>(v)%=MOD3;
  }
  void shr(Int k=1){
    get<0>(v)*=po1[k];
    get<0>(v)%=MOD1;
    get<1>(v)*=po2[k];
    get<1>(v)%=MOD2;
    get<2>(v)*=po3[k];
    get<2>(v)%=MOD3;
  }

  HS mv(Int k){
    HS a(v);
    if(k<0) a.shl(-k);
    else a.shr(k);
    return a;
  }

  HS operator+(const HS a) const{
    T x(v);
    get<0>(x)+=get<0>(a.v);
    get<0>(x)%=MOD1;
    get<1>(x)+=get<1>(a.v);
    get<1>(x)%=MOD2;
    get<2>(x)+=get<2>(a.v);
    get<2>(x)%=MOD3;

    return HS(x);
  }
  
  HS operator-(const HS a) const{
    T x(v);
    get<0>(x)+=MOD1-get<0>(a.v);
    get<0>(x)%=MOD1;
    get<1>(x)+=MOD2-get<1>(a.v);
    get<1>(x)%=MOD2;
    get<2>(x)+=MOD3-get<2>(a.v);
    get<2>(x)%=MOD3;

    return HS(x);
  }
  
  void print(){
    cout<<endl;
    Int a,b,c;
    tie(a,b,c)=v;
    cout<<a<<" "<<b<<" "<<c<<endl;
    cout<<endl;
  }
  
};

signed main(){
  Int n;
  string s;
  cin>>n>>s;

  po1[0]=po2[0]=po3[0]=1;
  op1[0]=op2[0]=op3[0]=1;
  inv1=mod_inverse2(BASE,MOD1);
  inv2=mod_inverse2(BASE,MOD2);
  inv3=mod_inverse2(BASE,MOD3);
  for(Int i=1;i<MAX;i++){
    po1[i]=po1[i-1]*BASE%MOD1;
    po2[i]=po2[i-1]*BASE%MOD2;
    po3[i]=po3[i-1]*BASE%MOD3;  
    op1[i]=op1[i-1]*inv1%MOD1;
    op2[i]=op2[i-1]*inv2%MOD2;
    op3[i]=op3[i-1]*inv3%MOD3;    
  }
  
  Int p=MAX/2,q=p;
  vector<Int> ps(n+1);
  HS bs;
  for(Int i=n;i>0;i--){
    ps[i]=p;
    if(s[i-1]=='+') bs.inc(q);
    if(s[i-1]=='-') bs.dec(q);
    if(s[i-1]=='>') bs.shr(),p--;
    if(s[i-1]=='<') bs.shl(),p++;    
  }
  ps[0]=p;
  
  HS hs;
  map<T, Int> vm;
  for(Int i=n;i>0;i--){
    vm[(hs-bs).mv(ps[i]).v]++;
    //(hs-bs).mv(ps[i]).print();
    if(s[i-1]=='+') hs.inc(q);
    if(s[i-1]=='-') hs.dec(q);
    if(s[i-1]=='>') hs.shr();
    if(s[i-1]=='<') hs.shl();    
  }
  vm[(hs-bs).mv(ps[0]).v]++;
  
  Int ans=0;
  HS dp;
  for(Int i=n;i>0;i--){
    vm[(dp-bs).mv(ps[i]).v]--;
    ans+=vm[dp.mv(ps[i]).v];
    //cout<<i<<":"<<vm[dp.mv(ps[i]).v]<<endl;
    //dp.mv(ps[i]).print();
    if(s[i-1]=='+') dp.inc(q);
    if(s[i-1]=='-') dp.dec(q);
    if(s[i-1]=='>') dp.shr();
    if(s[i-1]=='<') dp.shl();
  }
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 65668