#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;


#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }



long long modinv(long long a, long long mod) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a/b;
        a -= t*b; swap(a, b);
        u -= t*v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    if (n < 0) {
        a = modinv(a, mod);
        n = -n;
        return modpow(a, n, mod);
    }
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const vector<long long> MOD = {1000000009, 1000000007};
const vector<long long> BASE = {17, 1009};

long long solve(int N, const string &S) {
    vector<vector<long long>> hash(2, vector<long long>(N+1, 0));
    vector<vector<long long>> pval(2, vector<long long>(N+1, 0));
    map<pair<long long, long long>, vector<int>> pos;

    for (int i = 0; i < N; ++i) {
        for (int it = 0; it < 2; ++it) {
            if (S[i] == '>') {
                hash[it][i+1] = hash[it][i];
                pval[it][i+1] = pval[it][i] + 1;
            }
            else if (S[i] == '<') {
                hash[it][i+1] = hash[it][i];
                pval[it][i+1] = pval[it][i] - 1;
            }
            else if (S[i] == '+') {
                pval[it][i+1] = pval[it][i];
                long long add = modpow(BASE[it], pval[it][i], MOD[it]);
                hash[it][i+1] = (hash[it][i] + add) % MOD[it];
            }
            else if (S[i] == '-') {
                pval[it][i+1] = pval[it][i];
                long long add = modpow(BASE[it], pval[it][i], MOD[it]);
                hash[it][i+1] = (hash[it][i] - add + MOD[it]) % MOD[it];
            }
        }
        pos[{hash[0][i+1], hash[1][i+1]}].push_back(i+1);

        //cout << i+1 << ": " << hash[i+1] << ", " << pval[i+1] << endl;
    }

    long long res = 0;
    for (int i = 0; i <= N; ++i) {
        vector<long long> risou_add(2), risou(2);
        for (int it = 0; it < 2; ++it) {
            risou_add[it] = hash[it][N] * modpow(BASE[it], pval[it][i], MOD[it]) % MOD[it];
            risou[it] = (hash[it][i] + risou_add[it]) % MOD[it];
        }
        /*
        COUT("-----------------");
        COUT(i); COUT(pval[i]); COUT(pos[risou]);
        cout << cur << " + " << risou_add << " -> " << risou << endl;
        */
        
        auto &v = pos[{risou[0], risou[1]}];
        int it = upper_bound(v.begin(), v.end(), i) - v.begin();
        res += (int)v.size() - it;
    }
    return res;
}

int main() {
    int N; string S;
    while (cin >> N >> S) cout << solve(N, S) << endl;
}


Measured memory_bytes: 55136