#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> bool chmin(T& a,const T& b) {
  if(a>b) {
    a=b;
    return true;
  }
  return false;
}
template<class T> bool chmax(T& a,const T& b) {
  if(a<b){
    a=b;
    return true;
  }
  return false;
}

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
template<lint mod>
struct Int_{
  unsigned x;
  int mpow(Int_ a,int k){
    Int_ res=1;
    while(k){
      if(k&1) res=res*a;
      a=a*a;
      k>>=1;
    }
    return res.x;
  }
  int inverse(Int_ a){
    return mpow(a,mod-2);
  }
  Int_(): x(0) { }
  Int_(long long sig) { int sigt = sig % mod; if(sigt < 0) sigt += mod; x = sigt; }
  int get() const { return (int)x; }
  
  Int_ &operator+=(Int_ that) { if((x += that.x) >= mod) x -= mod; return *this; }
  Int_ &operator-=(Int_ that) { if((x += mod - that.x) >= mod) x -= mod; return *this; }
  Int_ &operator*=(Int_ that) { x = (unsigned long long)x * that.x % mod; return *this; }
  Int_ &operator=(Int_ that) { x=that.x; return *this;}
  Int_ &operator/=(Int_ that) { x=(unsigned long long) x * inverse(that.x)%mod; return *this;}
  bool operator==(Int_ that) const { return x==that.x; }
  bool operator!=(Int_ that) const { return x!=that.x; }


  Int_ operator-() const { return Int_(0)-Int_(*this);}
  Int_ operator+(Int_ that) const { return Int_(*this) += that; }
  Int_ operator-(Int_ that) const { return Int_(*this) -= that; }
  Int_ operator*(Int_ that) const { return Int_(*this) *= that; }
  Int_ operator/(Int_ that) const { return Int_(*this) /= that; }

};

typedef Int_<1000000021> Int_h;

namespace std{
  template<lint mod>
  ostream &operator <<(ostream& out,const Int_<mod>& a){
    out<<a.get();
    return out;
  }
  template<lint mod>
  istream &operator >>(istream& in,Int_<mod>& a){
    in>>a.x;
    return in;
  }
};
struct Hash{
  static const int MAX_N=550005;
  static Int_h M1,M2;
  static Int_h rev1,rev2;

  static Int_h mul1[MAX_N],mul2[MAX_N],
         div1[MAX_N],div2[MAX_N];

  typedef pair<Int_h,Int_h>key;
  static Hash pows[MAX_N];

  key a;
  static void init(){
    M1=1000000007,M2=1000000009;
    rev1=Int_h(1)/M1;
    rev2=Int_h(1)/M2;

    Int_h* ar[4]={mul1,mul2,div1,div2};
    Int_h mult[4]={M1,M2,rev1,rev2};
    REP(j,4){
      ar[j][0]=1;
      REP(i,MAX_N-1){
        ar[j][i+1]=ar[j][i]*mult[j];
      }
    }
    REP(i,MAX_N) pows[i].a=mp(mul1[i],mul2[i]);
  }
  Hash(lint val=0){
    a=mp(val,val);
  }
  Hash &operator+=(const Hash& b) { 
    a.fr+=b.a.fr;
    a.sc+=b.a.sc;

    return *this;
  }
  Hash &operator-=(const Hash& b) {
    a.fr-=b.a.fr;
    a.sc-=b.a.sc;

    return *this;
  }
  Hash &operator <<=(int k){
    if(k<0) (*this)>>=(-k);
    else{
      a.fr*=mul1[k];
      a.sc*=mul2[k];
      return *this;
    }
  }
  Hash &operator >>=(int k){
    if(k<0) (*this)<<=(-k);
    else{
      a.fr*=div1[k];
      a.sc*=div2[k];
      return *this;
    }
  }
  Hash &operator =(Hash b){
    a=b.a;
    return *this;
  }
  Hash &operator =(lint val){
    a.fr=val;
    a.sc=val;
    return *this;
  }
  Hash operator -()const{
    return Hash(0)-=Hash(*this);
  }

  Hash operator +(const Hash& b) const{
    return Hash(*this)+=b;
  }
  Hash operator -(const Hash& b) const{
    return Hash(*this)-=b;
  }

  Hash operator <<(int k) const{
    return Hash(*this)<<=k;
  }
  Hash operator >>(int k) const{
    return Hash(*this)>>=k;
  }

  bool operator==(const Hash& b) const { return (a==b.a); }
  bool operator!=(const Hash& b) const { return (a!=b.a); }
  bool operator<(const Hash& b) const {
    return mp(a.fr.x,a.sc.x)<mp(b.a.fr.x,b.a.sc.x);
  }
};

const int Hash::MAX_N;
Int_h Hash::M1,Hash::M2;
Int_h Hash::rev1,Hash::rev2;
Int_h Hash::mul1[MAX_N],Hash::mul2[MAX_N],
         Hash::div1[MAX_N],Hash::div2[MAX_N];

Hash Hash::pows[MAX_N];
//Hash::init();
//don't forget initializing!

int n;
char s[250005];
int main(){
  Hash::init();
  cin>>n;
  scanf("%s",s);


  map<Hash,int> cnt;
  Hash cur=0;
  int pos=0;
  REP(i,n){
    ++cnt[cur];
    if(s[i]=='<') --pos;
    else if(s[i]=='>') ++pos;
    else if(s[i]=='+') cur+=Hash::pows[pos+n];
    else cur-=Hash::pows[pos+n];
  }
  cnt[cur]++;

  Hash target=cur;
  cur=0;
  pos=0;

  lint res=0;
  REP(i,n){
    --cnt[cur];
    Hash target2=(target<<pos)+cur;
    res+=cnt[target2];
    if(s[i]=='<') --pos;
    else if(s[i]=='>') ++pos;
    else if(s[i]=='+') cur+=Hash::pows[pos+n];
    else cur-=Hash::pows[pos+n];
  }

  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 44672