#include <bits/stdc++.h>
using namespace std;

const int N = 280005;
const int mod1 = 1e9 + 123;
const int mod2 = 1e9 + 7;

int pw1[N + N], pw2[N + N];
int e[N];
int h1[N], h2[N];
int n;
string s;

int inverse(int a, int m) {
	int b = m - 2;
	int ret = 1;
	while(b) {
		if (b & 1) ret = 1LL * ret * a % m; a = 1LL * a * a % m;
		b >>= 1;
	}
	return ret;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> s;
	s = ' ' + s;

	pw1[0] = pw2[0] = 1;
	for (int i = 1; i < N + N; ++i) {
		pw1[i] = 1LL * pw1[i - 1] * N % mod1;
		pw2[i] = 1LL * pw2[i - 1] * N % mod2;
	}

	e[0] = N;
	for (int i = 1; i <= n; ++i) {
		h1[i] = h1[i - 1];
		h2[i] = h2[i - 1];
		e[i] = e[i - 1];
		if (s[i] == '<' || s[i] == '>') {
			e[i] += (s[i] == '>' ? +1 : -1);
		}
		else {
			h1[i] = (h1[i] + (s[i] == '+' ? +1 : -1) * pw1[e[i]]) % mod1;
			if (h1[i] < 0) h1[i] += mod1;
			h2[i] = (h2[i] + (s[i] == '+' ? +1 : -1) * pw2[e[i]]) % mod2;
			if (h2[i] < 0) h2[i] += mod2;
		}
	}

	long long res = 0;
	int t1 = 1LL * h1[n] * inverse(pw1[N], mod1) % mod1;
	int t2 = 1LL * h2[n] * inverse(pw2[N], mod2) % mod2;
	map < pair<int, int>, int > mp;
	mp[{1LL * t1 * pw1[N] % mod1, 1LL * t2 * pw2[N] % mod2}]++;

	for (int i = 1; i <= n; ++i) {
		res += mp[{h1[i], h2[i]}];
		int k1 = (1LL * t1 * pw1[e[i]] + h1[i]) % mod1;
		int k2 = (1LL * t2 * pw2[e[i]] + h2[i]) % mod2;
		mp[{k1, k2}]++;
	}

	cout << res << endl;
}