// ===== 2018/06/30 01:18:04 =====

// ../../../lib/template/includes.hpp

#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <vector>

// ../../../lib/template/const_value.hpp

namespace sub {
template <typename T>
constexpr typename std::enable_if<std::is_integral<T>::value, T>::type
inf_sub() {
  return std::numeric_limits<T>::max() / 2 - 1000;
}

template <typename T>
constexpr typename std::enable_if<std::is_floating_point<T>::value, T>::type
inf_sub() {
  return std::min(std::numeric_limits<T>::max() / 2 - 1000, T(1e50));
}
}  // namespace sub

template <typename T> constexpr T inf() {
  static_assert(std::is_arithmetic<T>::value, "T must be arithmetic value");
  return sub::inf_sub<T>();
}

template <typename T> constexpr T zero() {
  static_assert(std::is_arithmetic<T>::value, "T must be arithmetic value");
  return T(0);
}

const long double pi = acos(-1.0);

// ../../../lib/template/initialize.cpp

struct yes_no : std::numpunct<char> {
  string_type do_truename() const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

struct Initialize {
  Initialize() {
    std::locale loc(std::locale(), new yes_no);
    std::cout << std::boolalpha << std::setprecision(11) << std::fixed;
    std::cout.imbue(loc);
  }
};

const Initialize initialize;

// ../../../lib/template/macros.hpp

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

// ../../../lib/template/misc.hpp

template <typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }

template <typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }

// ../../../lib/template/range.hpp

class range {
  class index_type {
    int x;

  public:
    index_type(int x_) : x(x_) {}
    int operator*() const { return x; }
    bool operator!=(index_type &r) { return x < r.x; }
    void operator++() { ++x; }
  };
  index_type i, n;

public:
  range(int n_) : i(0), n(n_) {}
  range(int i_, int n_) : i(i_), n(n_) {}
  index_type &begin() { return i; }
  index_type &end() { return n; }
};

// ../../../lib/template/typedef.hpp

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

// ../../../lib/template/template.cpp

using namespace std;

// F.cpp

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

static const ll moda = 1000000000000037LL;
static const ll modb = 1000000000000091LL;
static const ll pa = 17LL;
static const ll pb = 19LL;

ll powa_raw[520000];
ll powb_raw[520000];

ll inv(ll a, ll p) {
  return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}

void solve(ll N, string S) {
  const __int128 inv_pa = inv(pa, moda);
  const __int128 inv_pb = inv(pb, modb);
  ll *A = powa_raw + 260000;
  ll *B = powb_raw + 260000;
  A[0] = 1; B[0] = 1;
  REP(i,255000) {
    A[i+1] = (A[i] * pa) % moda;
    A[-(i+1)] = (A[-i] * inv_pa) % moda;
    B[i+1] = (B[i] * pb) % modb;
    B[-(i+1)] = (B[-i] * inv_pb) % modb;
  }
  map<pair<ll,ll>,int> cnt;
  cnt[make_pair(0LL, 0LL)] = 1;
  ll suma = 0, sumb = 0, P = 0;
  REP(i,N) {
    if (S[i] == '+') { suma += A[P]; sumb += B[P]; }
    if (S[i] == '-') { suma -= A[P]; sumb -= B[P]; }
    suma = (suma + moda) % moda;
    sumb = (sumb + modb) % modb;
    if (S[i] == '>') ++P;
    if (S[i] == '<') --P;
    cnt[make_pair(suma, sumb)] += 1;
  }
  const ll ta = suma, tb = sumb;
  ll res = 0;
  suma = 0, sumb = 0, P = 0;
  REP(i,N) {
    cnt[make_pair(suma, sumb)] -= 1;
    ll tta = (__int128(ta) * A[P] + suma) % moda;
    ll ttb = (__int128(tb) * B[P] + sumb) % modb;
    res += cnt[make_pair(tta, ttb)];
    if (S[i] == '+') { suma += A[P]; sumb += B[P]; }
    if (S[i] == '-') { suma -= A[P]; sumb -= B[P]; }
    suma = (suma + moda) % moda;
    sumb = (sumb + modb) % modb;
    if (S[i] == '>') ++P;
    if (S[i] == '<') --P;
  }
  cout << res << endl;
}

int main() {
	string S;
	ll N;
	scanf("%lld", &N);
	cin >> S;
	solve(N, S);
	return 0;
}
// ===== 2018/06/30 01:18:04 =====



Measured memory_bytes: 40064