#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PLL;

const PLL M=mp(2147483647, 1088888881);   ///Should be large primes
const LL base=1135019;              ///Should be a prime larger than highest value
const int N = 1e6+7;            ///Highest length of string

ostream& operator<<(ostream& os, PLL hash) {
    return os<<"("<<hash.ff<<", "<<hash.ss<<")";
}

PLL operator+ (PLL a, LL x)     {return mp(a.ff + x, a.ss + x);}
PLL operator- (PLL a, LL x)     {return mp(a.ff - x, a.ss - x);}
PLL operator* (PLL a, LL x)     {return mp(a.ff * x, a.ss * x);}
PLL operator+ (PLL a, PLL x)    {return mp(a.ff + x.ff, a.ss + x.ss);}
PLL operator- (PLL a, PLL x)    {return mp(a.ff - x.ff, a.ss - x.ss);}
PLL operator* (PLL a, PLL x)    {return mp(a.ff * x.ff, a.ss * x.ss);}
PLL operator% (PLL a, PLL m)    {return mp(a.ff % m.ff, a.ss % m.ss);}

PLL power (PLL a, LL p) {
    if (p==0)   return mp(1,1);
    PLL ans = power(a, p/2);
    ans = (ans * ans)%M;
    if (p%2)    ans = (ans*a)%M;
    return ans;
}

///Magic!!!!!!!
PLL inverse(PLL a)  {
    return power(a, (M.ff-1)*(M.ss-1)-1);
}

PLL pb[N];      ///powers of base mod M
PLL invb;

///Call pre before everything
void hashPre() {
    pb[0] = mp(1,1);
    for (int i=1; i<N; i++)
        pb[i] = (pb[i-1] * base)%M;
    invb = inverse(pb[1]);
}

///Calculates Hash of a string
PLL Hash (string s) {
    PLL ans = mp(0,0);
    for (int i=0; i<s.size(); i++)
        ans=(ans*base + s[i])%M;
    return ans;
}

///replaces the i-th (0-indexed) character from right from a to b;
PLL replace(PLL cur, int i, char a, char b) {
    cur = (cur + pb[i] * (b-a))%M;
    return (cur + M)%M;
}

///Erases c from the back of the string
PLL pop_back(PLL hash, char c) {
    return (((hash-c)*invb)%M+M)%M;
}

///Erases c from front of the string with size len
PLL pop_front(PLL hash, int len, char c) {
    return ((hash - pb[len-1]*c)%M+M)%M;
}

///concatenates two strings where length of the right is k
PLL concat(PLL left, PLL right, int k) {
    return (left*pb[k] + right)%M;
}

///Calculates hash of string with size len repeated cnt times
///This is O(log n). For O(1), pre-calculate inverses
PLL repeat(PLL hash, int len, LL cnt) {
    PLL mul = (pb[len*cnt] - 1) * inverse(pb[len]-1);
    mul = (mul%M+M)%M;
    PLL ans = (hash*mul)%M;

    if (pb[len].ff == 1)    ans.ff = hash.ff*cnt;
    if (pb[len].ss == 1)    ans.ss = hash.ss*cnt;
    return ans;
}

///Calculates hashes of all prefixes of s including empty prefix
vector<PLL> hashList(string s) {
    int n = s.size();
    vector<PLL> ans(n+1);
    ans[0] = mp(0,0);

    for (int i=1; i<=n; i++)
        ans[i] = (ans[i-1] * base + s[i-1])%M;
    return ans;
}

///Calculates hash of substring s[l..r] (1 indexed)
PLL substringHash(const vector<PLL> &hashlist, int l, int r) {
    int len = (r-l+1);
    return ((hashlist[r] - hashlist[l-1]*pb[len])%M+M)%M;
}

const int MAXN = 5e5+7;
PLL dan[MAXN];

struct lfunc {
    PLL m, c;
    lfunc(PLL m, PLL c): m(m), c(c) { }
};

lfunc compose(const lfunc &f, const lfunc &g) {
    return lfunc((f.m*g.m)%M, (f.c*g.m+g.c)%M);
}

int main() {
    hashPre();

    int n; string s;
    cin >> n >> s;

    map< PLL , int >mp;

    PLL total(0, 0);
    PLL mal(1, 1);
    for (int i = 0, p = 0; i < n; i++) {
        if (s[i]=='>') {
            p++;
            mal = (mal*base)%M;
        } else if (s[i]=='<') {
            p--;
            mal = (mal*invb)%M;
        } else if (s[i]=='+') {
            total = (total+mal)%M;
        } else {
            assert(s[i]=='-');
            total = (total+M-mal)%M;
        }
        dan[i] = total;
        mp[total]++;
    }

    PLL one(1, 1);
    PLL zero(0, 0);
    PLL _one = (zero+M-one)%M;

    LL ans = 0;
    lfunc b4(one, zero);
    for (int i = 0; i < n; i++) {
        PLL tmp = (total+M-b4.c)%M;
        tmp = (tmp*inverse(b4.m))%M;
        ans += mp[tmp];
        mp[dan[i]]--;

        if (s[i]=='>') {
            b4 = compose(b4, lfunc(invb, zero));
        } else if (s[i]=='<') {
            b4 = compose(b4, lfunc(PLL(base, base), zero));
        } else if (s[i]=='+') {
            b4 = compose(b4, lfunc(one, _one));
        } else {
            assert(s[i]=='-');
            b4 = compose(b4, lfunc(one, one));
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 54288