#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9+7;
const ll MOD2 = 765876961;

template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; scanf("%lld", &x); return x;}
ld fin(){double x; scanf("%lf", &x); return x;}
char yuyushiki[1000010]; string stin(){scanf( "%s", yuyushiki ); return yuyushiki;}

// head


struct Mod{
  unsigned n;
  Mod() : n(0){}
  Mod( ll x ){
    if( x < 0 ) n = x%MOD+MOD;
    else n = x%MOD;
  }
};
Mod operator + ( Mod a  , Mod b ){ return Mod( a.n + b.n ); }
Mod operator +=( Mod &a , Mod b ){ return a = a + b; }
Mod operator - ( Mod a ){ return Mod( MOD - a.n ); }
Mod operator - ( Mod a  , Mod b ){ return Mod( a.n + MOD - b.n ); }
Mod operator -=( Mod &a , Mod b ){ return a = a - b; }
Mod operator * ( Mod a  , Mod b ){ return Mod( (ll)a.n * b.n ); }
Mod operator *=( Mod &a , Mod b ){ return a = a * b; }
Mod modpow( Mod x , ll k ){
  Mod res = 1;
  while( k ){
    if( k & 1 ) res *= x;
    k /= 2;
    x *= x;
  }
  return res;
}
ll extgcd( ll a , ll b , ll &x , ll &y ){
  ll d = a;
  if( b != 0 ){
    d = extgcd( b , a % b , y , x );
    y -= a / b * x;
  } else {
    x = 1, y = 0;
  }
  return d;
}
Mod inv( Mod a ){ ll x, y; assert( extgcd( a.n , MOD , x , y ) == 1 ); return Mod( x ); }
Mod operator / ( Mod a  , Mod b ){ return Mod( (ll)a.n * inv(b).n ); }
Mod operator /=( Mod &a , Mod b ){ return a = a / b; }


struct Mod2{
  unsigned n;
  Mod2() : n(0){}
  Mod2( ll x ){
    if( x < 0 ) n = x%MOD2+MOD2;
    else n = x%MOD2;
  }
};
Mod2 operator + ( Mod2 a  , Mod2 b ){ return Mod2( a.n + b.n ); }
Mod2 operator +=( Mod2 &a , Mod2 b ){ return a = a + b; }
Mod2 operator - ( Mod2 a ){ return Mod2( MOD2 - a.n ); }
Mod2 operator - ( Mod2 a  , Mod2 b ){ return Mod2( a.n + MOD2 - b.n ); }
Mod2 operator -=( Mod2 &a , Mod2 b ){ return a = a - b; }
Mod2 operator * ( Mod2 a  , Mod2 b ){ return Mod2( (ll)a.n * b.n ); }
Mod2 operator *=( Mod2 &a , Mod2 b ){ return a = a * b; }
Mod2 modpow( Mod2 x , ll k ){
  Mod2 res = 1;
  while( k ){
    if( k & 1 ) res *= x;
    k /= 2;
    x *= x;
  }
  return res;
}
Mod2 inv( Mod2 a ){ ll x, y; assert( extgcd( a.n , MOD2 , x , y ) == 1 ); return Mod2( x ); }
Mod2 operator / ( Mod2 a  , Mod2 b ){ return Mod2( (ll)a.n * inv(b).n ); }
Mod2 operator /=( Mod2 &a , Mod2 b ){ return a = a / b; }


/*
const ll MUL[3] = { 72727 , 51419 , 79393  };
const ll RHMOD[3] = { 1000000007 , 765876961 , 727272727 };
*/

using pl = pair<ll, ll>;

const ll B = 72727;
const ll B2 = 79393;
const ll N = 500020;

int n;
string s;

Mod cur;
Mod2 cur2;
pl state[N];
ll ps[N];

Mod e[N];
Mod2 e2[N];

int main(){

  e[0] = 1;
  FOR(i, 1, N){
    e[i] = e[i-1] * B;
  }

  e2[0] = 1;
  FOR(i, 1, N){
    e2[i] = e2[i-1] * B2;
  }
  
  n = in();
  s = stin();

  ll start = 250010;
  ll p = start;

  REP(i, n){
    state[i] = pl(cur.n, cur2.n);
    ps[i] = p;
    if(s[i] == '+'){
      cur += e[p];
      cur2 += e2[p];
    } else if(s[i] == '-'){
      cur -= e[p];
      cur2 -= e2[p];
    } else if(s[i] == '>'){
      p++;
    } else if(s[i] == '<'){
      p--;
    }
  }
  state[n] = pl(cur.n, cur2.n);

  map<pl, ll> cnt;
  ll ans = 0;
  
  for(int i = n; i >= 1; i--){
    if(cnt.find(state[i]) == cnt.end()){
      cnt[state[i]] = 1;
    } else {
      cnt[state[i]] += 1;
    }
    ll j = i - 1;

    Mod mokuhyo = 0;
    Mod2 mokuhyo2 = 0;
    if(ps[j] >= start){
      mokuhyo = cur * e[ps[j]-start] + state[j].fi;
      mokuhyo2 = cur2 * e2[ps[j]-start] + state[j].se;
    } else {
      mokuhyo = cur / e[start-ps[j]] + state[j].fi;
      mokuhyo2 = cur2 / e2[start-ps[j]] + state[j].se;
    }
    ans += cnt[pl(mokuhyo.n, mokuhyo2.n)];
  }

  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 46080