#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int mod_pow(int a, ll b, int MOD)
{
    int res = 1;
    while(b){
        if(b & 1){
            res = (ll)res * a % MOD;
        }
        a = (ll)a * a % MOD;
        b >>= 1;
    }
    return res;
}

int add(int x,int y, int MOD)
{
    return (x + y)%MOD;
}

int sub(int x,int y, int MOD)
{
    return (x+MOD-y)%MOD;
}

int mul(int x,int y, int MOD)
{
    return (ll)x*y%MOD;
}

#define mul0 10009
#define mul1 10007
#define MOD0 1000000007
#define MOD1 1000000007


struct RollingHash {
	int n, sz, res0, res1; vector<int> hash0, hash1;
    RollingHash(int _n) : n(_n), sz(2*n+2), res0(0), res1(0){
        hash0.resize(sz+1,0), hash0[0] = 1;
        hash1.resize(sz+1,0), hash1[0] = 1;
		rep(i,sz) hash0[i+1]=((ll)hash0[i]*mul0)%MOD0;
        rep(i,sz) hash1[i+1]=((ll)hash1[i]*mul1)%MOD1;
    }
    P calc(int id, bool pl){
        if(pl) res0 = add(res0, hash0[id+n+1], MOD0), res1 = add(res1, hash1[id+n+1], MOD1);
        else res0 = sub(res0, hash0[id+n+1], MOD0), res1 = sub(res1, hash1[id+n+1], MOD1);
        return P(res0, res1);
    }
};

map<P, int> mp;
vector<P> vec;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;
    RollingHash rh(n);
    int p = 0;
    rep(i,n){
        if(s[i] == '+'){
            vec.pb(rh.calc(p, true));
        }else if(s[i] == '-'){
            vec.pb(rh.calc(p, false));
        }else if(s[i] == '>'){
            if(len(vec)){
                vec.pb(vec.back());
            }else{
                vec.pb(P(0,0));
            }
            p++;
        }else{
            if(len(vec)){
                vec.pb(vec.back());
            }else{
                vec.pb(P(0,0));
            }
            p--;
        }
        mp[vec.back()]++;
    }
    P val = vec.back();
    ll ans = 0;
    int A0 = 1, A1 = 1, B0 = 0, B1 = 0;
    int hoge0 = mod_pow(mul0, MOD0-2, MOD0), hoge1 = mod_pow(mul1, MOD1-2, MOD1);
    auto& hash0 = rh.hash0;
    auto& hash1 = rh.hash1;
    rep(i,n){
        ans += mp[P(mul(sub(val.fi, B0, MOD0), mod_pow(A0, MOD0-2, MOD0), MOD0), mul(sub(val.se, B1, MOD1), mod_pow(A1, MOD1-2, MOD1), MOD1))];
        mp[vec[i]]--;
        if(s[i] == '+'){
            B0 = sub(B0, hash0[n+1], MOD0), B1 = sub(B1, hash1[n+1], MOD1);
        }else if(s[i] == '-'){
            B0 = add(B0, hash0[n+1], MOD0), B1 = add(B1, hash1[n+1], MOD1);
        }else if(s[i] == '>'){
            A0 = mul(A0, hoge0, MOD0), B0 = mul(B0, hoge0, MOD0);
            A1 = mul(A1, hoge1, MOD1), B1 = mul(B1, hoge1, MOD1);
        }else{
            A0 = mul(A0, mul0, MOD0), B0 = mul(B0, mul0, MOD0);
            A1 = mul(A1, mul1, MOD1), B1 = mul(B1, mul1, MOD1);
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 37640