#include <cstdio>
#include <map>
using namespace std;
typedef long long LL;
const int N=250010;
const LL MOD=1000000000000000031ll,B=1000000000000000003ll,REVB=821428571428571454ll;
int n;
char str[N];
LL f[N],p[N];
LL mul(LL x,LL y){
	return (LL)((__int128)x*y%MOD);
}
void readData(){
	scanf("%d",&n);
	scanf("%s",str+1);
}
map<LL,int> mp;
void solve(){
	f[0]=0;
	p[0]=1;
	for(int i=1;i<=n;i++){
		f[i]=f[i-1];
		p[i]=p[i-1];
		if(str[i]=='>')
			p[i]=mul(p[i],B);
		else if(str[i]=='<')
			p[i]=mul(p[i],REVB);
		else if(str[i]=='+')
			(f[i]+=p[i])%=MOD;
		else
			(f[i]-=p[i])%=MOD;
		if(f[i]<0)
			f[i]+=MOD;
	}
	LL ans=0;
	for(int i=n;i>=1;i--){
		mp[f[i]]++;
		ans+=mp[(mul(f[n],p[i-1])+f[i-1])%MOD];
	}
	printf("%lld\n",ans);
}
int main(){
	readData();
	solve();
	return 0;
}
