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 rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repk(i,k, n) for (int i = k; i < (int)(n); ++i)
#define MAX 500010

using namespace std;

int N, ans, cnt;
bool flg;
int a[10000];
string s;


void func(int start) {
	a[start] = 0;
	a[start + 1] = max(a[start + 1],1);
	a[start - 1] = max(a[start - 1], 1);

	// 右側
	int i = 0;
	while (1) { //s[start]==mi
		if (s[start + i] == s[start + i + 1]) {
			a[start + i + 2] = max(a[start + i + 2], i + 2);
			i++;
		}
		else break;
	}

	// 左側
	i = 0;
	while (1) { //s[start-1]==ma
		if (i > start - 2) break;
		if (s[start - i - 1] == s[start - i - 2]) {
			a[start - i - 2] = max(a[start - i - 2] , i + 2);
			i++;
		}
		else break;
	}
}


int main() {
	char mi = '<';
	char ma = '>';
	cin >> s;
	N = s.length();

	
	if (s[0] == mi) {
		a[0] = 0;
		a[1] = max(a[1],1);
		int i = 0;
		while (1) { // s[0]==mi
			if (s[i] == s[i + 1]) {
				a[i + 2] = max(a[i + 2], i + 2);
				i++;
			}
			else break;
		}
	}

	if (s[N - 1] == ma) {
		a[N] = 0;
		a[N - 1] = max(a[N - 1], 1);
		int i = 0;
		while (1) { //s[N-1]==ma
			if (i > N - 2) break;
			if (s[N - i - 1] == s[N - i - 2]) {
				a[N - i - 2] = max(a[N - i - 2], i + 2);
				i++;
			}
			else break;
		}
	}
	rep(i, N) {
		if (s[i] == ma && s[i + 1] == mi) { // ><の場合
			func(i + 1);
		}
	}

	rep(i, N + 1) {
		ans += a[i];
	}
	
	cout << ans << endl;

	return 0;
}