#include<stdio.h>
#include<map>
using namespace std;
typedef long long ll;
const ll mod=1000000000000000031ll,b=1000000000000000003ll,rb=821428571428571454ll;
ll mul(ll a,ll b){return(__int128)a*b%mod;}
ll ad(ll a,ll b){return(a+b)%mod;}
char s[250010];
ll p[250010],st[250010];
map<ll,int>m;
int main(){
	int n,i;
	ll ans;
	scanf("%d%s",&n,s+1);
	p[0]=1;
	for(i=1;i<=n;i++){
		p[i]=p[i-1];
		st[i]=st[i-1];
		switch(s[i]){
			case'+':st[i]=ad(st[i],p[i]);break;
			case'-':st[i]=ad(st[i],mod-p[i]);break;
			case'>':p[i]=mul(p[i],b);break;
			case'<':p[i]=mul(p[i],rb);break;
		}
	}
	ans=0;
	for(i=n;i>0;i--){
		m[st[i]]++;
		ans+=m[ad(mul(st[n],p[i-1]),st[i-1])];
	}
	printf("%lld",ans);
}