#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

template<int mod>
struct mint{
  int x;
  mint() : x(0) {}
  mint(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  mint &operator+=(const mint &p) { if((x += p.x) >= mod) x -= mod; return *this; }
  mint &operator-=(const mint &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; }
  mint &operator*=(const mint &p) { x = (int) (1LL * x * p.x % mod); return *this; }
  mint &operator/=(const mint &p) { *this *= p.inverse(); return *this; }
  mint &operator^=(ll n) {
    int y = x; x = 1;
    while(n > 0) {
      if(n & 1) x = 1LL * x * y % mod; y = 1LL * y * y % mod; n /= 2; }
    return *this; }
  mint operator-() const { return mint(-x); }
  mint operator+(const mint &p) const { return mint(*this) += p; }
  mint operator-(const mint &p) const { return mint(*this) -= p; }
  mint operator*(const mint &p) const { return mint(*this) *= p; }
  mint operator/(const mint &p) const { return mint(*this) /= p; }
  mint operator^(const ll n) const { return mint(*this) ^= n; }
  bool operator==(const mint &p) const { return x == p.x; }
  bool operator!=(const mint &p) const { return x != p.x; }
  mint inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
    return mint(u); }
  friend ostream &operator<<(ostream &os, const mint<mod> &p) { return os << p.x; }
  friend istream &operator>>(istream &is, mint< mod > &a) { 
	  ll t; is >> t; a = mint<mod>(t); return (is); }
};

struct rhash { //don't forget to base_init()!!!!!
	mint<1000000007> v1;
	mint<1000000009> v2;
	rhash() : v1(0), v2(0) {}
	rhash(ll a) : v1(a), v2(a) {}
	rhash(ll a, ll b) : v1(a), v2(b) {}
	rhash &operator+=(const rhash &hs) { v1 += hs.v1; v2 += hs.v2; return *this; }
	rhash &operator-=(const rhash &hs) { v1 -= hs.v1; v2 -= hs.v2; return *this; }
	rhash &operator*=(const rhash &hs) { v1 *= hs.v1; v2 *= hs.v2; return *this; }
	rhash &operator/=(const rhash &hs) { v1 /= hs.v1; v2 /= hs.v2; return *this; }
	rhash &operator^=(ll n) { v1 ^= n; v2 ^= n; return *this; }
	rhash operator-() const { rhash hs; hs.v1 = -v1; hs.v2 = -v2; return hs; }
	rhash operator+(const rhash& hs) const { return rhash(*this) += hs; }
	rhash operator-(const rhash& hs) const { return rhash(*this) -= hs; }
	rhash operator*(const rhash& hs) const { return rhash(*this) *= hs; }
	rhash operator/(const rhash& hs) const { return rhash(*this) /= hs; }
	rhash operator^(ll n) const { return rhash(*this) ^= n; }
	bool operator<(const rhash &hs) const { return pi(v1.x, v2.x) < pi(hs.v1.x, hs.v2.x); }
	bool operator==(const rhash& hs) { return v1 == hs.v1 && v2 == hs.v2; }
	bool operator!=(const rhash& hs) { return v1 != hs.v1 || v2 != hs.v2; }
	friend ostream &operator<<(ostream &os, const rhash &hs) { return os << pi(hs.v1.x, hs.v2.x); }
};


ll mod_pow(ll a, ll n) {
	if(n == 0) return 1;
	ll res = mod_pow(a, n / 2);
	if(n % 2 == 0) return res * res % mod;
	else return a * res % mod * res % mod;
}

ll invf(ll a) {
	return mod_pow(a, mod - 2);
}

int N;
string S;

rhash A[MAX_N];
int B[MAX_N];

void solve() {
	cin >> N;
	cin >> S;
	rhash base;
	int v1 = uniform_int_distribution<int>(0, 1000000007 - 1)(rng);
	int v2 = uniform_int_distribution<int>(0, 1000000009 - 1)(rng);
	base = rhash(v1, v2);
	rhash one = 1;
	rhash inv = one / base;

	int at = 0;
	rhash tmp = 1;
	rhash res = 0;
	rep(i, 0, N) {
		if(S[i] == '<') {
			tmp *= inv;
			at--;
		}
		else if(S[i] == '>') {
			tmp *= base;
			at++;
		}
		else if(S[i] == '+') res += tmp;
		else res -= tmp;
		A[i + 1] = res;
		B[i + 1] = at;
		// debug(res, at, tmp);
	}
	map<rhash, int> D;
	D[A[N]]++;

	ll ans = 0;
	rer(i, N, 0) {
		int at = B[i];
		rhash coef = 1;
		if(at < 0) coef = inv ^ (-at);
		else coef = base ^ at;
		rhash target = (coef * A[N] + A[i]);
		if(D.count(target)) ans += D[target];
		D[A[i]]++;
		// debug(target, A[N]);
	}
	cout << ans << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 21012