#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=1000005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int upd(int x,int y) { return x+y>=mods?x+y-mods:x+y; }
int quick_pow(int x,int y)
{
	int ret=1;
	for (;y;y>>=1)
	{
		if (y&1) ret=1ll*ret*x%mods;
		x=1ll*x*x%mods;
	}
	return ret;
}

char st[MAXN];
int X[6]={37,667,233333,17,19,53},inv[6];
struct Node
{
	int a[6]; 
	Node() { for (int i=0;i<6;i++) a[i]=0; }
};
bool operator < (Node x,Node y) 
{
	for (int i=0;i<6;i++) { if (x.a[i]==y.a[i]) continue; return x.a[i]<y.a[i]; }
	return 0;
}
map<Node,int> Map;
Node operator + (Node x,int y) { for (int i=0;i<6;i++) x.a[i]=upd(x.a[i],y); return x; }
Node operator - (Node x,int y) { for (int i=0;i<6;i++) x.a[i]=upd(x.a[i],mods-y); return x; }
Node operator >> (Node x,int y) { while (y--) for (int i=0;i<6;i++) x.a[i]=1ll*x.a[i]*X[i]%mods; return x; }
Node operator << (Node x,int y) { while (y--) for (int i=0;i<6;i++) x.a[i]=1ll*x.a[i]*inv[i]%mods; return x; }

struct fnode
{
	Node k,b;
	fnode() { for (int i=0;i<6;i++) k.a[i]=1,b.a[i]=0; }
};
fnode operator + (fnode x,int y) { for (int i=0;i<6;i++) x.b.a[i]=upd(x.b.a[i],y*x.k.a[i]); return x; }
fnode operator - (fnode x,int y) { for (int i=0;i<6;i++) x.b.a[i]=upd(x.b.a[i],mods-y*x.k.a[i]); return x; }
fnode operator >> (fnode x,int y) { while (y--) for (int i=0;i<6;i++) x.k.a[i]=1ll*x.k.a[i]*X[i]%mods; return x; }
fnode operator << (fnode x,int y) { while (y--) for (int i=0;i<6;i++) x.k.a[i]=1ll*x.k.a[i]*inv[i]%mods; return x; }
Node operator * (Node x,fnode y) 
{
	Node ans;
	for (int i=0;i<6;i++) ans.a[i]=upd(ans.a[i],(1ll*y.k.a[i]*x.a[i]+y.b.a[i])%mods);
	return ans;
}
int main()
{
	for (int i=0;i<6;i++) inv[i]=quick_pow(X[i],mods-2);
	int n=read();
	scanf("%s",st+1);
	Node c,p;
	for (int i=n;i>=1;i--)
	{
		if (st[i]=='+') c=c+1;
		if (st[i]=='-') c=c-1;
		if (st[i]=='<') c=c<<1;
		if (st[i]=='>') c=c>>1;
//		for (int j=0;j<6;j++) cout<<c.a[j]<<" ";cout<<endl;
	}
//	cout<<endl;
	Map[p]++;
	fnode f;
	ll ans=0;
	for (int i=n;i>=1;i--)
	{
		if (st[i]=='+') f=f-1;
		if (st[i]=='-') f=f+1;
		if (st[i]=='<') f=f>>1;
		if (st[i]=='>') f=f<<1;
		ans+=Map[c*f],Map[p*f]++;
//		for (int j=0;j<6;j++) cout<<(p*f).a[j]<<" ";cout<<endl;
//		for (int j=0;j<6;j++) cout<<(c*f).a[j]<<" ";cout<<endl<<endl;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 42996