#include <bits/stdc++.h>
using namespace std;
inline int power(int a, int b, int mod) {
    long long res = a, ans = 1;
    for(; b; b >>= 1, res = res * res % mod) if(b & 1) ans = ans * res % mod;
    return ans;
}
const int mod1 = 1e9 + 7, mod2 = 1e9 + 9;
const int base1 = 19260817, base2 = 65537, base1Inv = power(base1, mod1 - 2, mod1), base2Inv = power(base2, mod2 - 2, mod2);
int n;
template <class T, int L, int R>
class Array {
    private:
        T buf[R - L + 1];
    public:
        struct iterator {
            T *p;
            inline iterator& operator ++ () {
                return ++p;
            }
            inline iterator& operator ++ (int) {
                return p++;
            }
            inline iterator& operator -- () {
                return --p;
            }
            inline iterator& operator -- (int) {
                return p--;
            }
            inline T& operator * () {
                return *p;
            }
            inline iterator operator + (int x) {
                return p + x;
            }
            inline iterator& operator += (int x) {
                return p += x;
            }
            inline iterator operator - (int x) {
                return p - x;
            }
            inline iterator& operator -= (int x) {
                return p -= x;
            }
            inline iterator& operator = (iterator b) {
                return p = b.p;
            }
            inline bool operator == (iterator b) {
                return p == b.p;
            }
            inline bool operator != (iterator b) {
                return p != b.p;
            }
        };
        inline iterator begin() {
            return iterator {buf};
        }
        inline iterator end() {
            return iterator {buf + R - L + 1};
        }
        inline T& operator [] (int x) {
            return buf[x - L];
        }
        inline const T& operator [] (int x) const {
            return buf[x - L];
        }
};
Array <int, -250000, 250000> pw1, pw2;
pair <int, int> need, sum[250010];
int pos[250010];
char opt[250010];
map < pair <int, int>, int > cnt;
int main() {
    scanf("%d%s", &n, opt + 1);
    pos[0] = 0;
    pw1[0] = pw2[0] = 1;
    for(int i = 0; i < 250000; i++) 
        pw1[i + 1] = 1ll * base1 * pw1[i] % mod1,
        pw2[i + 1] = 1ll * base2 * pw2[i] % mod2,
        pw1[-i - 1] = 1ll * base1Inv * pw1[-i] % mod1,
        pw2[-i - 1] = 1ll * base2Inv * pw2[-i] % mod2;
    for(int i = 1; i <= n; i++) {
        switch (opt[i]) {
        case '<': {
            pos[i] = pos[i - 1] - 1;
            sum[i] = sum[i - 1];
            break;
        }
        case '>': {
            pos[i] = pos[i - 1] + 1;
            sum[i] = sum[i - 1];
            break;
        }
        case '+': {
            pos[i] = pos[i - 1];
            sum[i] = sum[i - 1];
            sum[i].first = (sum[i].first + pw1[pos[i]]) % mod1;
            sum[i].second = (sum[i].second + pw2[pos[i]]) % mod2;
            break;
        }
        case '-': {
            pos[i] = pos[i - 1];
            sum[i] = sum[i - 1];
            sum[i].first = (sum[i].first + mod1 - pw1[pos[i]]) % mod1;
            sum[i].second = (sum[i].second + mod2 - pw2[pos[i]]) % mod2;
            break;
        }
        default:
            assert(0);
        }
    }
    long long ans = 0;
    for(int i = n; i >= 0; i--) {
        pair <int, int> tmp;
        tmp = sum[n]; // sum[n] = (sum[r] - sum[l - 1]) >> pos[l - 1]
        tmp.first = 1ll * tmp.first * pw1[pos[i]] % mod1;
        tmp.second = 1ll * tmp.second * pw2[pos[i]] % mod2;
        tmp.first = (tmp.first + sum[i].first) % mod1;
        tmp.second = (tmp.second + sum[i].second) % mod2;
        // cerr << i << ' ' << tmp.first << ' ' << tmp.second << endl;
        if(cnt.count(tmp)) ans += cnt[tmp];
        tmp = sum[i];
        // cerr << i << ' ' << tmp.first << ' ' << tmp.second << endl;
        if(cnt.count(tmp)) cnt[tmp]++;
        else cnt[tmp] = 1;
    }
    return cout << ans << endl, 0;
}

Measured memory_bytes: 22912