//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int, int> pii;

const int X = 250000 + 5;
const int N = 1e6 + 5;
const ull B = 545;
ull invB;

/***************************************************************************/

ull power(ull a, ull n) {
	if(n == 0) return 1;
	ull p = power(a, n>>1);
	p = p * p;
	if(n & 1) p = p * a;
	return p;
}

string S;
ull powB[N];

inline ull& pow(int n) {
	if(n < 0) n += N;
	return powB[n];
}

map<ull, int> M;

int main() {

	boost;
	invB = power(B, (ull(1)<<63)-1);
	assert(B * invB == 1);

	pow(0) = 1;
	for(int i=1; i<X; i++) {
		pow(i) = pow(i-1) * B;
		pow(-i) = pow(-i+1) * invB;
	}

	int n; cin>>n;
	cin>>S;

	ull phas = 0, chas = 0;

	int p = 0;
	for(auto it : S) {
		if(it == '+') phas += pow(p);
		else if(it == '-') phas -= pow(p);
		else if(it == '>') p++;
		else p--;
	}

	ll ans = 0;
	M[phas]++;
	p = 0;

	for(auto it : S) {
		if(it == '+') chas += pow(p);
		else if(it == '-') chas -= pow(p);
		else if(it == '>') p++;
		else p--;

		ans += M[chas];
		M[chas + pow(p) * phas]++;
	}

	cout<<ans<<"\n";

	return 0;
}