Problem:
Score : 300 points

Problem Statement

Given is a string S of length N-1.
Each character in S is < or >.

A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be good when the following condition is satisfied for all i (1 \leq i \leq N-1):

If S_i= <: a_i<a_{i+1}

If S_i= >: a_i>a_{i+1}

Find the minimum possible sum of the elements of a good sequence of N non-negative integers.

Constraints

2 \leq N \leq 5 \times 10^5

S is a string of length N-1 consisting of < and >.

Input

Input is given from Standard Input in the following format:

S

Output

Find the minimum possible sum of the elements of a good sequence of N non-negative integers.

Sample Input 1

<>>

Sample Output 1

3

a=(0,2,1,0) is a good sequence whose sum is 3.
There is no good sequence whose sum is less than 3.

Sample Input 2

<>>><<><<<<<>>><

Sample Output 2

28

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include<bits/stdc++.h>
#define nmax 10004
#define oo 1000000007
#define reset(x, y) memset(x, y, sizeof (x))
#define s second
#define f first
#define PB(x) push_back(x)
#define Task ""
#define For(i, x, y) for(int i = x; i <= y; i++)
#define Fod(i, x, y) for(int i = x; i >= y; i--)
#define FOR(i, x) for(int i : x)

using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vti;
typedef vector<vti> vtv;
typedef vector<ll> vli;

string s;
int n;
vti e[nmax];
int deg[nmax];

void Enter()
{
    cin >> s;
    n = s.length();
    s = ' ' + s;
    reset(deg, 0);
    For(i, 1, n)
        if(s[i] == '<') {
            e[i].PB(i + 1);
            deg[i + 1]++;
        }
        else {
            e[i + 1].PB(i);
            deg[i]++;
        }
}

void Solve()
{
    queue<int> q;
    For(i, 1, n + 1)
        if(!deg[i])
            q.push(i);
    int dem = 0;
    ll res = 0;
    while(!q.empty()) {
        int cnt = q.size();
        For(i, 1, cnt) {
            int u = q.front();
            q.pop();
            for(int v : e[u]) {
                deg[v]--;
                if(!deg[v])
                    q.push(v);
            }
        }
        res += (1ll * cnt * dem);
        dem++;
        cnt = 0;
    }
    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    //freopen(Task".inp", "r", stdin);
    //freopen(Task".out", "w", stdout);
    Enter();
    Solve();
}