#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
typedef unsigned long long ull;
const int maxn=250000+10;
unordered_map<ull,int> mp;
char s[maxn];
ull Pw[maxn<<1],sum[maxn];
int p[maxn];
int main(){
	int n=read();
	Pw[0]=1;
	REP(i,1,maxn*2-10) Pw[i]=Pw[i-1]*101;
	scanf("%s",s+1);
	p[0]=n+5;
	REP(i,1,n){
		sum[i]=sum[i-1],p[i]=p[i-1];
		if(s[i]=='>') ++p[i];
		if(s[i]=='<') --p[i];
		if(s[i]=='+') sum[i]+=Pw[p[i]];
		if(s[i]=='-') sum[i]-=Pw[p[i]];
	}
	ll ans=0;
	REP(i,0,n){
		ull val=sum[n]*Pw[p[i]]+sum[i]*Pw[n+5];
		ans+=mp[sum[i]*Pw[n+5]];
		mp[val]++;
	}
	printf("%lld\n",ans);
	return 0;
}
