#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

template<unsigned P> struct ModInt {
  using M = ModInt;
  unsigned v;
  ModInt() : v(0) {}
  ModInt(auto x) : v(x >= 0 ? x % P : (P - -x % P) % P) {}
  constexpr ModInt(unsigned v, int) : v(v) {}
  static constexpr unsigned p() { return P; }
  M operator+() const { return *this; }
  M operator-() const { return {v ? P - v : 0, 0}; }
  explicit operator bool() const noexcept { return v; }
  bool operator!() const noexcept { return !(bool)*this; }
  M operator*(M r) const { return M(*this) *= r; }
  M operator/(M r) const { return M(*this) /= r; }
  M operator+(M r) const { return M(*this) += r; }
  M operator-(M r) const { return M(*this) -= r; }
  bool operator==(M r) const { return v == r.v; }
  bool operator!=(M r) const { return !(*this == r); }
  M& operator*=(M r) { v = (uint64_t)v * r.v % P; return *this; }
  M& operator/=(M r) { return *this *= r.inv(); }
  M& operator+=(M r) { if ((v += r.v) >= P) v -= P; return *this; }
  M& operator-=(M r) { if ((v += P - r.v) >= P) v -= P; return *this; }
  M inv() const {
    int a = v, b = P, x = 1, u = 0;
    while (b) {
      int q = a / b;
      swap(a -= q * b, b);
      swap(x -= q * u, u);
    }
    assert(a == 1);
    return x;
  }
  M pow(auto n) const {
    if (n < 0) return pow(-n).inv();
    M res = 1;
    for (M a = *this; n; a *= a, n >>= 1) if (n & 1) res *= a;
    return res;
  }
  friend M operator*(auto l, M r) { return M(l) *= r; }
  friend M operator/(auto l, M r) { return M(l) /= r; }
  friend M operator+(auto l, M r) { return M(l) += r; }
  friend M operator-(auto l, M r) { return M(l) -= r; }
  friend ostream& operator<<(ostream& os, M r) { return os << r.v; }
  friend istream& operator>>(istream& is, M& r) { lint x; is >> x; r = x; return is; }
  friend bool operator==(auto l, M r) { return M(l) == r; }
  friend bool operator!=(auto l, M r) { return !(l == r); }
};
using M0 = ModInt<(unsigned)2e9 + 11>;
using M1 = ModInt<(unsigned)2e9 + 33>;

template<class Z> Z rng(Z a, Z b) {
  static mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
  return uniform_int_distribution<Z>(a, b - 1)(mt);
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;
  M0 B0 = rng(1u, M0::p()), iB0 = B0.inv();
  M1 B1 = rng(1u, M1::p()), iB1 = B1.inv();
  V<M0> powB0{1};
  V<M1> powB1{1};
  for (int _ = 0; _ < 2 * n; ++_) {
    powB0.push_back(powB0.back() * B0);
    powB1.push_back(powB1.back() * B1);
  }

  map< pair<int, int>, int > mp;
  int p = n;
  V<M0> h0{0};
  V<M1> h1{0};
  for (int i = 0; i < n; ++i) {
    h0.push_back(h0.back());
    h1.push_back(h1.back());
    if (s[i] == '>') ++p;
    if (s[i] == '<') --p;
    if (s[i] == '+') {
      h0.back() += powB0[p];
      h1.back() += powB1[p];
    }
    if (s[i] == '-') {
      h0.back() -= powB0[p];
      h1.back() -= powB1[p];
    }
    ++mp[{h0.back().v, h1.back().v}];
  }

  lint res = 0;
  M0 a0 = 1, b0;
  M1 a1 = 1, b1;
  for (int i = 0; i < n; ++i) {
    M0 t0 = a0 * h0.back() + b0;
    M1 t1 = a1 * h1.back() + b1;
    res += mp[{t0.v, t1.v}];
    if (s[i] == '>') {
      a0 *= B0;
      a1 *= B1;
    }
    if (s[i] == '<') {
      a0 *= iB0;
      a1 *= iB1;
    }
    if (s[i] == '+') {
      b0 += a0 * powB0[n];
      b1 += a1 * powB1[n];
    }
    if (s[i] == '-') {
      b0 -= a0 * powB0[n];
      b1 -= a1 * powB1[n];
    }
    --mp[{h0[i + 1].v, h1[i + 1].v}];
  }
  cout << res << '\n';
}

Measured memory_bytes: 37632