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: Time Limit Exceeded)

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printarray(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long

using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 5e5 + 5;

vector<int> adj[MAXN];
int deg[MAXN];
bool visited[MAXN];
int depth[MAXN] = {0};

void dfs(int s){
	visited[s] = true;
	for(int u: adj[s]){
		if(!visited[u]){
			dfs(u);
			depth[s] = max(depth[s], depth[u]+1);
		}
	}
	return;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int n = s.length() + 1;
    for(int i = 1;i<n;i++){
    	if(s[i-1] == '<'){
    		adj[i+1].pb(i);
    		deg[i]++;
    	} else {
    		adj[i].pb(i+1);
    		deg[i+1]++;
    	}
    }    
    for(int i = 1;i<=n;i++){
    	if(deg[i] == 0){
    		memset(visited, 0, sizeof(visited));
    		dfs(i);
    	}
    }
    int sum = 0;
    for(int i = 1;i<=n;i++){
    	sum += depth[i];
    }
    cout<<sum<<endl;

    return 0;
}