Problem: In Takahashi's mind, there is always an integer sequence of length 2 \times 10^9 + 1: A = (A_{-10^9}, A_{-10^9 + 1}, ..., A_{10^9 - 1}, A_{10^9}) and an integer P.

Initially, all the elements in the sequence A in Takahashi's mind are 0, and the value of the integer P is 0.

When Takahashi eats symbols `+`, `-`, `>` and `<`, the sequence A and the integer P will change as follows:

* When he eats `+`, the value of A_P increases by 1;
* When he eats `-`, the value of A_P decreases by 1;
* When he eats `>`, the value of P increases by 1;
* When he eats `<`, the value of P decreases by 1.



Takahashi has a string S of length N. Each character in S is one of the symbols `+`, `-`, `>` and `<`. He chose a pair of integers (i, j) such that 1 \leq i \leq j \leq N and ate the symbols that are the i-th, (i+1)-th, ..., j-th characters in S, in this order. We heard that, after he finished eating, the sequence A became the same as if he had eaten all the symbols in S from first to last. How many such possible pairs (i, j) are there?

Constraints

* 1 \leq N \leq 250000
* |S| = N
* Each character in S is `+`, `-`, `>` or `<`.

Input

Input is given from Standard Input in the following format:


N
S


Output

Print the answer.

Examples

Input

5
+>+<-


Output

3


Input

5
+>+-<


Output

5


Input

48
-+><<><><><>>>+-<<>->>><<><<-+<>><+<<>+><-+->><<


Output

475

Solution (in CPP):

Solution:
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <bitset>
#include <assert.h>
#include <complex.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define FILL(A,val) memset(A,val,sizeof(A))

#define ALL(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair

typedef long long Int;
typedef unsigned long long UInt;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double Pi = acos(-1.0);
const int INF = 1000000000;
const Int INF2 = Int(INF) * 5000;
const Int INF3 = Int(INF) * INF;
const int MAX = 510007;
const int MAXE = 2007000;
const int MAXV = 5000;
const int BASE = 1000000000;
const int ST = 1000000007;

const int MOD = 1000000007;

int p = 1000003;

Int H[MAX];
int delta[MAX];


Int pw[MAX];

int main()
{
    //freopen("in.txt", "r", stdin);
    
    pw[0] = 1;
    FOR(i,1,MAX)
    {
        pw[i] = pw[i - 1] * p;
    }
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    H[0] = 0;
    delta[0] = n + 1;
    
    FOR(i,0,n)
    {
        H[i + 1] = H[i];
        delta[i + 1] += delta[i];
        
        if (s[i] == '<')
        {
            delta[i + 1] --;
        }
        if (s[i] == '>')
        {
            delta[i + 1] ++;
        }
        
        if (s[i] == '+')
        {
            H[i + 1] += pw[delta[i + 1]];
        }
        
        if (s[i] == '-')
        {
            H[i + 1] -= pw[delta[i + 1]];
        }
        
    }
    
    Int res = 0;
    
    map<Int, int> M;
    
    
    
    
    RFOR(i,n,0)
    {
        M[H[i + 1] * pw[n]] ++;
        Int h = H[n] * pw[delta[i] - delta[0] + n] + H[i] * pw[n];
        
        res += M[h];
    }
    
    cout << res << endl;
    
    
}