#include <bits/stdc++.h>
using ll = long long;
template <typename T>
constexpr std::pair<T, T> extgcd(const T a, const T b)
{
    if (b == 0) { return std::pair<T, T>{1, 0}; }
    const auto p = extgcd(b, a % b);
    return {p.second, p.first - p.second * (a / b)};
}
template <typename T>
constexpr T inverse(const T a, const T mod) { return (mod + extgcd(a, mod).first % mod) % mod; }
constexpr ll MOD1 = 1000000007LL, MOD2 = 1000000009LL;
constexpr int H = 5;  //関数値サンプルの個数
constexpr ll X[H] = {2371983LL, 1231LL, 123123LL, 4329075LL, 134121LL};
constexpr ll XINV1[H] = {inverse(X[0], MOD1), inverse(X[1], MOD1), inverse(X[2], MOD1), inverse(X[3], MOD1), inverse(X[4], MOD1)};
constexpr ll XINV2[H] = {inverse(X[0], MOD2), inverse(X[1], MOD2), inverse(X[2], MOD2), inverse(X[3], MOD2), inverse(X[4], MOD2)};
int main()
{
    int N;
    std::string S;
    std::cin >> N >> S;
    using P = std::pair<ll, ll>;
    std::vector<int> deg(N + 1, 0);
    std::vector<std::vector<P>> value(N + 1, std::vector<P>(H, {0LL, 0LL}));
    auto plus = [](const P& p1, const P& p2) { return P{(p1.first + p2.first) % MOD1, (p1.second + p2.second) % MOD2}; };
    auto minus = [](const P& p1, const P& p2) { return P{(p1.first + MOD1 - p2.first) % MOD1, (p1.second + MOD2 - p2.second) % MOD2}; };
    auto rshift = [](const P& p, const int j) { return P{p.first * X[j] % MOD1, p.second * X[j] % MOD2}; };
    auto lshift = [](const P& p, const int j) { return P{p.first * XINV1[j] % MOD1, p.second * XINV2[j] % MOD2}; };
    auto mul = [](const P& p1, const P& p2) { return P{p1.first * p2.first % MOD1, p1.second * p2.second % MOD2}; };
    for (int i = N - 1; i >= 0; i--) {
        if (S[i] == '-') {
            deg[i] = deg[i + 1];
            for (int j = 0; j < H; j++) { value[i][j] = minus(value[i + 1][j], {1, 1}); }
        } else if (S[i] == '+') {
            deg[i] = deg[i + 1];
            for (int j = 0; j < H; j++) { value[i][j] = plus(value[i + 1][j], {1, 1}); }
        } else if (S[i] == '>') {
            deg[i] = deg[i + 1] + 1;
            for (int j = 0; j < H; j++) { value[i][j] = rshift(value[i + 1][j], j); }
        } else {
            deg[i] = deg[i + 1] - 1;
            for (int j = 0; j < H; j++) { value[i][j] = lshift(value[i + 1][j], j); }
        }
    }
    constexpr int L = 250000;
    std::vector<std::vector<P>> power(L + 1, std::vector<P>(H, {1, 1}));
    std::vector<std::vector<P>> invpower(L + 1, std::vector<P>(H, {1, 1}));
    auto invp = [&](const int i, const int j) { return i >= 0 ? invpower[i][j] : power[-i][j]; };
    for (int i = 1; i <= L; i++) {
        for (int j = 0; j < H; j++) { power[i][j] = rshift(power[i - 1][j], j), invpower[i][j] = lshift(invpower[i - 1][j], j); }  //  invpower[i][j] = lshift(power[i - 1][j], j) じゃねんだよなぁまじで
    }
    std::vector<P> answer(H);
    for (int i = 0; i < H; i++) { answer[i] = value[0][i]; }
    std::vector<std::vector<P>> hash(N + 1, std::vector<P>(H));
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j < H; j++) { hash[i][j] = mul(minus(value[i][j], answer[j]), invp(deg[i], j)); }
    }
    using VP = std::vector<P>;
    std::map<VP, ll> mp;
    ll ans = 0;
    for (int i = 0; i <= N; i++) {
        std::vector<P> obj(H);
        for (int j = 0; j < H; j++) { obj[j] = plus(hash[i][j], mul(invp(deg[i], j), answer[j])); }
        if (mp.find(obj) != mp.end()) { ans += mp[obj]; }
        mp[hash[i]]++;
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 161668