#include<bits/stdc++.h>
using namespace std;
using ll = long long;

// #undef DEBUG
// #define DEBUG
/// {{{ DEBUG --- ///
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { if(&o == &cerr) { o << '{'; for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? ", " : ""); o << "}"; } else { for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? " " : ""); } return o; }
#ifdef DEBUG
#ifdef USE_COUT
#define dump(...) (cout<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n")
#else
#define dump(...) (cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n")
#endif
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream &o, tuple<T...> const &t){ o << "("; _ot<0>(o, t); o << ")"; return o; }
template<class T, class U> ostream & operator<<(ostream &o, pair<T, U> const &p) { o << "(" << p.first << ", " << p.second << ")"; return o; }
#else
#define dump(...) (0)
#endif
/// }}}--- ///

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll extgcd(ll a, ll b, ll &x, ll &y) { ll d; return b == 0 ? (x = 1, y = 0, a) : (d = extgcd(b, a % b, y, x), y -= a / b * x, d); }
ll modinv(ll a, ll mod = 1e9 + 7) { ll x = 0, y = 0; extgcd(a, mod, x, y); return (x + mod) % mod; }
ll modpow(ll a, ll b, ll mod = 1e9 + 7) { ll r = 1; a %= mod; while(b) { if(b & 1) r = r * a % mod; a = a * a % mod; b >>= 1; } return r; }

const int N = 250000 + 10;
const ll mod = 1e9 + 7;
// vector<ll> gen{114514, 1919, 810, -114514, -1919, -810};
vector<ll> gen{114514, 1919, 810};
vector<map<ll, int>> Aex(gen.size()), Bex = Aex;
int n;
string s;
int ms[N];
ll calc(int i, int c, ll x) {
  if(i == 0) {
    // A
    if(c <= 1) return 1;
    if(c == 2) return modinv(x, mod);
    return x;
  } else {
    if(c == 0) return 1;
    if(c == 1) return -1;
    return 0;
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> s;
  vector<vector<ll>> A(gen.size(), vector<ll>(n+2)), B = A;
  for(int i = 0; i < n; i++) {
    if(s[i] == '+') ms[i] = 0;
    else if(s[i] == '-') ms[i] = 1;
    else if(s[i] == '>') ms[i] = 2;
    else ms[i] = 3;
  }
  for(int k = 0; k < gen.size(); k++) {
    gen[k] = ((gen[k] % mod + mod) % mod);
    ll x = gen[k];
    A[k][1] = 1;
    B[k][1] = 0;
    for(int i = 0; i < n; i++) {
      A[k][i+2] = A[k][i+1] * calc(0, ms[i], x) % mod;
      B[k][i+2] = A[k][i+1] * calc(1, ms[i], x) % mod + B[k][i+1];
      B[k][i+2] = ((B[k][i+2] % mod + mod) % mod);
      Bex[k][B[k][i+2]]++;
    }
  }
  // dump(A[0]);
  // dump(B[0]);
  ll ans = 0;
  for(int i = 0; i < n; i++) {
    ll mi = 1e18;
    for(int k = 0; k < gen.size(); k++) {
      ll c = A[k][i+1] * B[k][n+1] % mod;
      c += B[k][i+1];
      c %= mod;
      ll cnt = Bex[k][c];
      // dump(i, c, cnt);
      // mi = min(mi, cnt);
      if(cnt != mi) mi = min(mi, cnt);
      else break;
    }
    for(int k = 0; k < gen.size(); k++) Bex[k][B[k][i+2]]--;
    // dump(i, mi);
    ans += mi;
  }
  cout << ans << endl;
}



Measured memory_bytes: 91376