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 Python (3.4.3) (judge verdict: Accepted)

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

S = input()
N = len(S)
A = [0]*(N+1)

i = 0
ind = 0
flag = 0
if S[0] == '>':
    while S[ind] == '>':
        ind += 1
        if ind >= N:
            flag = 1
            break
    num = ind
    for i in range(ind+1):
        A[i] = num
        num -= 1
i = ind

if flag:
    print(sum(A))
    exit()
if S.count('<') == N:
    print(N*(N+1)//2)
    exit()
if S == '><' or (len(S) == ind+1 and S[i-1:i+1] == '><'):
    print(2)
    exit()
while True:
    if S[i] == '<' and S[i+1] == '>':
        cnt = 0
        while True:
            cnt += 1
            if i+1+cnt > N-1 or S[i+1+cnt] == '<':
                break
        #print(i, cnt)
        if i+1-ind >= cnt+1:
            num = 1
            for j in range(ind+1, i+2):
                A[j] = num
                num += 1
            num = 0
            for j in reversed(range(i+2, i+cnt+2)):
                A[j] = num
                num += 1
        else:
            num = 1
            for j in range(ind+1, i+1):
                A[j] = num
                num += 1
            num = 0
            for j in reversed(range(i+1, i+cnt+2)):
                A[j] = num
                num += 1
        ind = i+cnt+1
        i += cnt
        #print(A)
    else:
        A[i+1] = A[i] + 1
    i += 1
    if i >= N-1:
        if i == N-1:
            A[i+1] = A[i] + 1
        break

#print(A)
print(sum(A))