#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>

using namespace std;

int n;
char dat[260003];

const uint64_t p1 = 1288490207;
const uint64_t p2 = 1395864377;
const uint64_t p3 = 1417339213;
const uint64_t p4 = 1471026299;

/* find a pair (c,d) s.t. ac + bd = gcd(a,b)
* Dependencies: none */
pair<long long, long long> extended_gcd(long long a, long long b) {
  if (b == 0) return make_pair(1, 0);
  pair<long long, long long> t = extended_gcd(b, a % b);
  return make_pair(t.second, t.first - t.second * (a / b));
}

/* Find x in [0,m) s.t. ax ≡ gcd(a, m) (mod m)
* Dependencies: extended_gcd(a, b) */
long long modinverse(long long a, long long m) {
  return (extended_gcd(a, m).first % m + m) % m;
}

struct LinearFunction {
  // Ax + B
  long long A, B;
  long long mod;
  long long x, xinv;

  LinearFunction(long long mod, long long x) : A(1), B(0), mod(mod), x(x) {
    xinv = modinverse(x, mod);
  }

  long long evaluate(long long seed) const {
    return (((A % mod) * (seed % mod) + B) % mod + mod) % mod;
  }

  long long evaluateInverse(long long seed) const {
    // Ay + B = seed
    // Ay = seed - B
    // y = (seed - B) * A^-1
    long long result = seed - B;
    result *= modinverse(A, mod);
    return (result % mod + mod) % mod;
  }

  void applyPlus() { B++; B %= mod; }
  void applyMinus() { B += mod - 1; B %= mod; }
  void applyLeft() { A = (A * xinv) % mod; B = (B * xinv) % mod; }
  void applyRight() { A = (A * x) % mod; B = (B * x) % mod; }
};

int main() {
  scanf("%d", &n);
  scanf("%s", dat);

  pair<long long, long long> abc;
  {
    LinearFunction ef1(p1, p2);
    LinearFunction ef2(p3, p4);
    for (int i = n - 1; i >= 0; i--) {
      if (dat[i] == '+') {
        ef1.applyPlus();
        ef2.applyPlus();
      }
      else if (dat[i] == '-') {
        ef1.applyMinus();
        ef2.applyMinus();
      }
      else if (dat[i] == '<') {
        ef1.applyLeft();
        ef2.applyLeft();
      }
      else if (dat[i] == '>') {
        ef1.applyRight();
        ef2.applyRight();
      }
    }
    abc = make_pair(ef1.evaluate(0), ef2.evaluate(0));
  }
  long long ans = 0;
  {
    map<pair<long long, long long>, int> suffix;
    LinearFunction ef1(p1, p2);
    LinearFunction ef2(p3, p4);
    ++suffix[make_pair(ef1.evaluateInverse(0), ef2.evaluateInverse(0))];
    for (int i = n - 1; i >= 0; i--) {
      if (dat[i] == '+') {
        ef1.applyPlus();
        ef2.applyPlus();
      }
      else if (dat[i] == '-') {
        ef1.applyMinus();
        ef2.applyMinus();
      }
      else if (dat[i] == '<') {
        ef1.applyLeft();
        ef2.applyLeft();
      }
      else if (dat[i] == '>') {
        ef1.applyRight();
        ef2.applyRight();
      }
      ans += suffix[make_pair(
        ef1.evaluateInverse(abc.first),
        ef2.evaluateInverse(abc.second)
      )];
      ++suffix[make_pair(ef1.evaluateInverse(0), ef2.evaluateInverse(0))];
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 31744