#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
using P = pair<int,int>;
template<unsigned long long mod_>
struct ModInt{
	using uint = unsigned long long;
	using ll = __int128;
	using ull =__int128;

	constexpr static uint mod = mod_;

	uint v;
	ModInt():v(0){}
	ModInt(ll v):v(normS(v%mod+mod)){}
	explicit operator bool() const {return v!=0;}
	static uint normS(const uint &x){return (x<mod)?x:x-mod;}		// [0 , 2*mod-1] -> [0 , mod-1]
	static ModInt make(const uint &x){ModInt m; m.v=x; return m;}
	ModInt operator+(const ModInt& b) const { return make(normS(v+b.v));}
	ModInt operator-(const ModInt& b) const { return make(normS(v+mod-b.v));}
	ModInt operator-() const { return make(normS(mod-v)); }
	ModInt operator*(const ModInt& b) const { return make((ull)v*b.v%mod);}
	ModInt operator/(const ModInt& b) const { return *this*b.inv();}
	ModInt& operator+=(const ModInt& b){ return *this=*this+b;}
	ModInt& operator-=(const ModInt& b){ return *this=*this-b;}
	ModInt& operator*=(const ModInt& b){ return *this=*this*b;}
	ModInt& operator/=(const ModInt& b){ return *this=*this/b;}
	ll extgcd(ll a,ll b,ll &x,ll &y) const{
		ll u[]={a,1,0},v[]={b,0,1};
		while(*v){
			ll t=*u/ *v;
			rep(i,3) swap(u[i]-=t*v[i],v[i]);
		}
		if(u[0]<0) rep(i,3) u[i]=-u[i];
		x=u[1],y=u[2];
		return u[0];
	}
	ModInt inv() const{
		ll x,y;
		extgcd(v,mod,x,y);
		return make(normS(x+mod));
	}
	bool operator==(const ModInt& b) const { return v==b.v;}
	bool operator!=(const ModInt& b) const { return v!=b.v;}
//	friend istream& operator>>(istream &o,ModInt& x){
//		ll tmp;
//		o>>tmp;
//		x=ModInt(tmp);
//		return o;
//	}
//	friend ostream& operator<<(ostream &o,const ModInt& x){ return o<<x.v;}
};
using mint = ModInt<1000000000000000003ULL>;
const mint B = 998244353;
mint ex(int p){
	bool m = 0;
	if(p<0){
		p = -p;
		m = 1;
	}
	mint a = 1;
	mint x = B;
	while(p){
		if(p%2==1) a *= x;
		x *= x;
		p/=2;
	}
	if(m) a = (mint)1/a;
	return a;
}

using ll = long long;
int N;
string s;

int main(){
	cin>>N>>s;
	mint H = 0;
	{
		map<int,int> cnt;
		int x = 0;
		rep(i,N){
			if(s[i]=='+') cnt[x]++;
			if(s[i]=='-') cnt[x]--;
			if(s[i]=='<') x--;
			if(s[i]=='>') x++;
		}
		for(P p:cnt){
			int x = p.fs, v = p.sc;
			H += ex(x) * v;
		}
	}
	mint a = 1, b = 0;
	ll ans = 0;
	
	map<long long,int> mp;
	mp[0] = 1;
	for(int i=N-1;i>=0;i--){
		mint na,nb;
		if(s[i]=='+'){
			na = a, nb = b+1;
		}
		if(s[i]=='-'){
			na = a, nb = b-1;
		}
		if(s[i]=='<'){
			na = a/B, nb = b/B;
		}
		if(s[i]=='>'){
			na = a*B, nb = b*B;
		}
		a = na, b = nb;
		mint H_false = (H-b)/a;
		ans += mp[H_false.v];
		mp[(-b/a).v]++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 31748