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 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <stdio.h>
#define NDEBUG
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

// for DEBUG {{{
#ifdef NDEBUG
#define DEBUG_PRINT(fmt, ...) ((void)0)
#else
#define DEBUG_PRINT(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
#endif
#define ASSERT_RANGE(min,x,max) assert(((x)>=(min)) && ((x)<=(max)))
// }}}

int sort_int(int *a, int N) {// {{{
	int i;
	for (i = 0; i < N-1; i++) {
		int j;
		for (j = i + 1; j < N; j++) {
			if (a[i] > a[j]) {
				int tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
	return 0;
}// }}}
void merge_int(int *a, int *b, int lower, int sep, int upper) {// {{{
	int i_lower = lower;
	int i_upper = sep;
	int i_b = 0;
	while ((i_lower < sep) && (i_upper < upper)) {
		if (a[i_lower] < a[i_upper]) {
			b[i_b++] = a[i_lower++];
		} else {
			b[i_b++] = a[i_upper++];
		}
	}
	if (i_lower >= sep) {
		while (i_upper < upper) {
			b[i_b++] = a[i_upper++];
		}
	} else {
		while (i_lower < sep) {
			b[i_b++] = a[i_lower++];
		}
	}
	for (i_lower = 0; i_lower < i_b; i_lower++) {
		a[i_lower+lower] = b[i_lower];
	}
}// }}}
void merge_sort_int(int *a, int *b, int lower, int upper) {// {{{
	int sep;
	if ((lower == upper) || (lower + 1 == upper)) {
		return;
	}
	sep = (lower + upper) / 2;
	merge_sort_int(a,b,lower,sep);
	merge_sort_int(a,b,sep,upper);
	merge_int(a,b,lower,sep,upper);
}// }}}

#define S_MAX 30000
int main(int argc, char **argv) {
	long long t1, t2;
	long long a1, a2;
	long long b1, b2;
	fscanf(stdin,"%lld%lld",&t1,&t2) > 0;
	fscanf(stdin,"%lld%lld",&a1,&a2) > 0;
	fscanf(stdin,"%lld%lld",&b1,&b2) > 0;

	long long diff1 = (a1-b1)*t1;
	long long diff2 = (a2-b2)*t2;
	long long diff3 = diff1 + diff2;

	DEBUG_PRINT("%lld %lld %lld\n",diff1, diff2, diff3);
	if ((diff1 > 0) && (diff2 > 0)) {
		fprintf(stdout,"0\n");
		return 0;
	}
	if ((diff1 < 0) && (diff2 < 0)) {
		fprintf(stdout,"0\n");
		return 0;
	}
	if ((diff1 > 0) && (diff2 < 0)) {
		if (diff3 > 0) {
			fprintf(stdout,"0\n");
			return 0;
		}
		if (diff3 == 0) {
			fprintf(stdout,"infinity\n");
			return 0;
		}
		assert(diff3 < 0);
		long long  n = diff1 / llabs(diff3);
		if ((llabs(diff3) * n) == llabs(diff1)) {
			fprintf(stdout,"%lld\n",2*n);
		} else {
			fprintf(stdout,"%lld\n",1+2*n);
		}
		return 0;
	}
	if ((diff1 < 0) && (diff2 > 0)) {
		if (diff3 < 0) {
			fprintf(stdout,"0\n");
			return 0;
		}
		if (diff3 == 0) {
			fprintf(stdout,"infinity\n");
			return 0;
		}
		assert(diff3 > 0);
		long long n = llabs(diff1) / diff3;
		if ((llabs(diff3) * n) == llabs(diff1)) {
			fprintf(stdout,"%lld\n",2*n);
		} else {
			fprintf(stdout,"%lld\n",1+2*n);
		}
		//
		return 0;
	}
	return 0;
}