#include <cstdio>
#include <map>

typedef long long LL;
const int Mod[3] = {999988679, 999988609, 999988589};
const int B[3] = {370728, 370732, 370729};
const int iB[3] = {396903752, 462741403, 834141573};
const int MN = 250005;

inline void Add(int &x, int y, int i) { x -= (x += y) >= Mod[i] ? Mod[i] : 0; }

typedef std::tuple<int, int, int> i3;

int N;
char S[MN];
int A[3][MN], D[3][MN];
std::map<i3, int> Buk;
LL Ans;

int main() {
	scanf("%d%s", &N, S + 1);
	for (int j = 0; j < 3; ++j) A[j][0] = 0, D[j][0] = 1;
	for (int i = 1, V[3] = {1, 1, 1}; i <= N; ++i) {
		for (int j = 0; j < 3; ++j) {
			A[j][i] = A[j][i - 1];
			if (S[i] == '+') Add(A[j][i], V[j], j);
			if (S[i] == '-') Add(A[j][i], Mod[j] - V[j], j);
			if (S[i] == '>') V[j] = (LL)V[j] * B[j] % Mod[j];
			if (S[i] == '<') V[j] = (LL)V[j] * iB[j] % Mod[j];
			D[j][i] = V[j];
		}
	}
	for (int i = N; i >= 0; --i) {
		Ans += Buk[std::make_tuple(
			(A[0][i] + (LL)A[0][N] * D[0][i]) % Mod[0],
			(A[1][i] + (LL)A[1][N] * D[1][i]) % Mod[1],
			(A[2][i] + (LL)A[2][N] * D[2][i]) % Mod[2]
		)];
		++Buk[std::make_tuple(A[0][i], A[1][i], A[2][i])];
	}
	printf("%lld\n", Ans);
	return 0;
}