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: Wrong Answer)

#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}


int main(){
    string s;cin >> s;
    int n = s.size() + 1;
    ll INF = INT_MAX;
    vector<ll> a(n, -INF);
    vector<ll> btm;
    rep(i,n-2){
        if(i == 0 && s[i] == '<')btm.push_back(i);
        if(s[i] == '>' && s[i+1] == '<')btm.push_back(i+1);
        if(i == n-3 && s[i+1] == '>')btm.push_back(i+2);
    }
    for(auto i : btm)a[i] = 0;
    // 左に更新
    for(auto i : btm){
        ll temp = 1;
        while(i - temp >= 0 && s[i-temp] == '>'){
            a[i-temp] = temp;
            temp++;
        }
    }
    // 右に更新
    for(auto i : btm){
        ll temp = 1;
        while(i + temp <= n-1 && s[i+temp-1] == '<'){
            a[i+temp] = max(a[i+temp],temp);
            temp++;
        }
    }
    // print(btm);
    // print(a);
    ll res = 0;
    rep(i,n){
        if(a[i] == -INF)res += a[i-1]+1;
        res += a[i];
    }
    cout << res << endl;
}