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 (Python):

import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div

S = list(rs())
ans = 0
tmp = 0
cnt = 0
f = 1
for i in range(len(S)):
    if S[i] == '<':
        if f:
            cnt += 1
        else:
            ans += cnt * (cnt - 1) // 2
            ans += max(tmp, cnt)
            cnt = 1
            f = 1
    else:
        if f:
            ans += cnt * (cnt - 1) // 2
            tmp = cnt
            cnt = 1
            f = 0
        else:
            cnt += 1
ans += cnt * (cnt - 1) // 2
if f:
    ans += cnt
else:
    ans += max(tmp, cnt)
print(ans)

Solution (Python):
s = input()
cut = [0]
for i in range(len(s)-1):
    if(s[i:i+2] == '><'):
        cut.append(i+1)
cut.append(len(s)+1)

ans = 0
for i in range(len(cut)-1):
    ss = s[cut[i]:cut[i+1]]
    left = ss.count('<')
    right = ss.count('>')
    ans += left*(left+1)//2 + right*(right+1)//2 - min(left,right)

print(ans)

Solution (Python):
S = input()
ans = 0
tmpl = 0
tmpr = 0
for i in range(len(S) - 1):
  if S[i] == '<':
    tmpl += 1
  else:
    tmpr += 1
    if S[i + 1] == '<':
      x = max(tmpl, tmpr)
      y = min(tmpl, tmpr)
      ans += (1 + x) * x // 2 + y * (y - 1) // 2
      tmpl = 0
      tmpr = 0

if S[-1] == '<':
  tmpl += 1
else:
  tmpr += 1
x = max(tmpl, tmpr)
y = min(tmpl, tmpr)
ans += (1 + x) * x // 2 + y * (y - 1) // 2
print(ans)

Solution (Python):
S = input()
l = len(S)
A = [0 for i in range(l+1)]
for i in range(l):
    if S[i] == '<':
        A[i+1] = max(A[i+1],A[i]+1)
for i in range(l-1,-1,-1):
    if S[i] == '>':
        A[i] = max(A[i+1]+1,A[i])
print(sum(A))

Solution (Python):
S = input()
INC = '<'
DEC = '>'
icnt = 0
dcnt = 0
mode = DEC
ans = 0
for c in S:
  if mode == DEC:
    if c == DEC:
      dcnt += 1
    elif c == INC:
      if icnt <= dcnt:
        ans += (dcnt + 1) * dcnt // 2
      else:
        ans += icnt + dcnt * (dcnt - 1) // 2
      icnt = 1
      mode = INC
  elif mode == INC:
    if c == INC:
      icnt += 1
    elif c == DEC:
      ans += icnt * (icnt - 1) // 2
      dcnt = 1
      mode = DEC
if mode == INC:
  ans += (icnt + 1) * icnt // 2
elif mode == DEC:
  if icnt <= dcnt:
    ans += (dcnt + 1) * dcnt // 2
  else:
    ans += icnt + dcnt * (dcnt - 1) // 2
print(ans)

Solution (Python):
s=input()
l=len(s)
a=[0 for i in range(l+1)]
for i in range(l):
    if s[i]=='<':
        a[i+1]=max(a[i+1],a[i]+1)
        
for i in range(l-1,-1,-1):
    if s[i]=='>':
        a[i]=max(a[i+1]+1,a[i])
        
print(sum(a))

Solution (Python):
s = input()
A = [0] * (len(s) + 1)
for i, c in enumerate(s):
	if c == '<':
		A[i+1] = A[i] + 1
for i, c in enumerate(s[::-1]):
	if c == '>':
		x = len(s) - i
		A[x-1] = max(A[x-1], A[x] + 1)
print(sum(A))

Solution (Python):
S = input()
l = len(S)
A = [0 for i in range(l+1)]
for i in range(l):
    if S[i] == '<':
        A[i+1] = max(A[i+1],A[i]+1)
for i in range(l-1,-1,-1):
    if S[i] == '>':
        A[i] = max(A[i+1]+1,A[i])
print(sum(A))

Solution (Python):
s = input().strip()

buf = s[0]
count = 0
popa  = []
suma = 0
for i in s:
  if i=="<":
    count+=1
    suma += count
  elif i==">" and buf=="<":
    popa.append(count)
    suma -= count
    count = 0
  buf = i
buf = s[-1]
count = 0
dupa  = []
for i in s[::-1]:
  if i==">":
    count+=1
    suma += count
  elif i=="<" and buf==">":
    dupa.append(count)
    suma -= count
    count = 0
  buf = i

for i,j in zip(dupa[::-1],popa):
  suma+=max(i,j)
print(suma)

Solution (Python):
s = input()
l = len(s)
n = [0] * (l+1)

for i in range(l):
    if s[i] == '<':
        n[i+1] = n[i] + 1

for i in reversed(range(l)):
    if s[i] == '>':
        n[i] = max(n[i+1] + 1, n[i])

print(sum(n))

Solution (Python):
s = input()
ans = [0]*(len(s)+1)
for i, c in enumerate(s):
    if c=='<':
        ans[i+1] = max(ans[i+1], ans[i]+1)
for i, c in enumerate(s[::-1]):
    if c=='>':
        ans[-2-i] = max(ans[-2-i], ans[-1-i]+1)
print(sum(ans))

Solution (Python):
def rle(t):
    tmp2, count_, ans_ = t[0], 1, []
    for i_ in range(1, len(t)):
        if tmp2 == t[i_]:
            count_ += 1
        else:
            ans_.append([tmp2, count_])
            tmp2 = t[i_]
            count_ = 1
    ans_.append([tmp2, count_])
    return ans_


S = list(input())

l = rle(S)
ans = [0] * (len(S) + 1)
count = 0
for i in range(len(l)):
    if l[i][0] == '<':
        for j in range(l[i][1] + 1):
            ans[count + j] = max(ans[count + j], j)
    elif l[i][0] == '>':
        for k in range(l[i][1] + 1):
            ans[count + k] = max(ans[count + k], l[i][1] - k)
    count += l[i][1]
print(sum(ans))

Solution (Python):
s=raw_input()
n=len(s)
a=[0]*(n+1)
for i in range(n):
	if s[i]=='<':
		a[i+1]=a[i]+1
for i in range(n-1,-1,-1):
	if s[i]=='>':
		a[i]=max(a[i+1]+1,a[i])
print sum(a)

Solution (Python):


S = input()
part = S.replace('><','> <').split(' ')

ans=0
for p in part:
    left  = p.count('<')
    right = p.count('>')
    ans += sum(range(1, max(left, right) + 1))
    ans += sum(range(1, min(left, right)))

print(ans)

Solution (Python):
S = input()
L = [0]
for s in S:
    L += [s]
    L += [0]
for i in range(len(L)):
    if L[i] == '<':
        L[i+1] = L[i-1]+1
for i in range(len(L)-1,-1,-1):
    if L[i] == '>':
        L[i-1] = max(L[i-1],L[i+1]+1)
ans = 0
for i in range(len(L)):
    if L[i] not in ['<','>']:
        ans += L[i]
print(ans)

Solution (Python):
s = input()
partition = s.replace('><','>|<').split('|')
ans=0

for sub in partition:
    left = sub.count('<')
    right = sub.count('>')
    ans += sum(range(1, max(left, right) + 1))
    ans += sum(range(1, min(left, right)))

print(ans)

Solution (Python):
S = list(input())
L = len(S)
count = 0
count_minus = [0] * L
for i in range(L):
    if S[i] == ">":
        count = 0
    else:
        count += 1
    count_minus[i] = count

count = 0
count_plus = [0] * L
for i in reversed(range(L)):
    if S[i] == "<":
        count = 0
    else:
        count += 1
    count_plus[i] = count

result_list = [0] * (L-1)
for i in range(len(result_list)):
    result_list[i] = max(count_minus[i], count_plus[i+1])

result = sum(result_list) + count_minus[L-1] + count_plus[0] 
print(result)

Solution (Python):
s = input()
s_len = len(s)
li = [0]*(s_len+1)
for i in range(0,s_len):
    if s[i] == "<":
        if li[i] >= li[i+1]:
            li[i+1] = li[i] + 1
for i in range(s_len-1,-1,-1):
    if s[i] == ">":
        if li[i] <= li[i+1]:
            li[i] = li[i+1]+1
print(sum(li))

Solution (Python):
A=list(input())
right_cnt=[0]
left_cnt=[0]
cnt=0
for i in range(len(A)):
   if A[i] == "<":
      right_cnt.append(right_cnt[-1]+1)
   else:
      right_cnt.append(0)
   if A[-i-1] == ">":
      left_cnt.append(left_cnt[-1]+1)
   else:
      left_cnt.append(0)
left_cnt=left_cnt[::-1]
for i in range(len(A)+1):
   cnt+=max(left_cnt[i],right_cnt[i])
print(cnt)

Solution (Python):
S = list(input())
n = len(S)+1
a = [0 for _ in range(n)]

for i in range(n-1):
    if S[i] == "<":
        a[i+1] = max(a[i+1], a[i] + 1)



S = S[::-1]
a = a[::-1]
for i in range(n-1):
    if S[i] == "<":
        S[i] = ">"
    else:
        S[i] = "<"



for i in range(n-1):
    if S[i] == "<":
        if a[i] >= a[i+1]:
            a[i+1] = max(a[i+1], a[i] + 1)

print(sum(a))

Solution (Python):

S = input()
N = len(S)+1
l = [0]
r = [0]

for i in range(N-1):
    if S[i] == '<':
        l.append(l[-1]+1)
    else:
        l.append(0)
    if S[-1-i] == '>':
        r.append(r[-1]+1)
    else:
        r.append(0)

r = r[::-1]
ans = [max(l[i], r[i]) for i in range(N)]
print(sum(ans))

Solution (Python):
s=list(input())
n=len(s)+1
lc=[0]
rc=[0]
for i in range(n-1):
    if s[i]=='<':
        lc.append(lc[-1]+1)
    else:
        lc.append(0)
    if s[-1-i]=='>':
        rc.append(rc[-1]+1)
    else:
        rc.append(0)
rc=rc[::-1]
ans=[max(lc[i], rc[i]) for i in range(n)]
print(sum(ans))

Solution (Python):
s=input()
ans=0
if s[0]==">":
    s="<"+s
if s[-1]=="<":
    s=s+">"
s=list(s)
ls=len(s)

st=ct=gl=0
ans=0
for i in range(ls-1):
    if s[i]=="<" and s[i+1]==">":
        ct=i
    elif s[i]==">" and s[i+1]=="<":
        gl=i
    if i==ls-2:
        gl=ls-1
    if gl!=0:
        pre=((ct-st)+1)*(ct-st)/2
        pos=((gl-ct-1)+1)*(gl-ct-1)/2
        intra=max(ct-st+1, gl-ct)
        ans+=pre+pos+intra
        
        st=gl+1
        ct=gl=0

print(int(ans))

Solution (Python):


s = input()
n = len(s)+1
a = [0 for _  in range(n)]

for i in range(n-1):
    if s[i] == '<':
        a[i+1] = max(a[i+1], a[i]+1)

for i in reversed(range(1, n)):
    if s[i-1] == '>':
        a[i-1] = max(a[i-1], a[i]+1)

ans = sum(a)


print(ans)

Solution (Python):
import re
a=0
for m in re.findall('(<*)(>*)',input()):u,v=map(len,m);a-=(u*~u+v*~v)//2+min(u,v)
print(a)

Solution (Python):
import re
a=0
for m in re.findall('(<*)(>*)',input()):u,v=map(len,m);a+=(u*u-u+v*v-v)//2+max(u,v)
print(a)

Solution (Python):
import re
print(sum(sum(i * (i - 1) // 2 for i in p) + max(p) for p in (tuple(map(len, m)) for m in re.findall(r"(<*)(>*)", input()))))

Solution (Python):
s = input()
partition = s.replace('><','>|<').split('|')
ans=0
for sub in partition:
    left = sub.count('<')
    right = sub.count('>')
    ans += sum(range(1, max(left, right)+1))+sum(range(1, min(left, right)))
    
print(ans)

Solution (Python):
s = input()
inc = 0
dec = 0
increasing = True
ans = 0
for c in s:
    if increasing:
        if c == '<':
            inc += 1
        else:
            increasing = False
            dec += 1
    else:
        if  c == '>':
            dec += 1
        else:
            if inc > dec:
                inc, dec = dec, inc
            ans += inc * (inc - 1) // 2 + dec * (dec + 1) // 2
            increasing = True
            inc = 1
            dec = 0
else:
    if increasing:
        ans += inc * (inc + 1) // 2
    else:
        if inc > dec:
            inc, dec = dec, inc
        ans += inc * (inc - 1) // 2 + dec * (dec + 1) // 2
print(ans)

Solution (Python):
s = input()
n = len(s)
Ans = [0] * (n + 1)

top = set()
bottom = set()
if s[0] == ">":
    top.add(0)
else:
    bottom.add(0)

for i in range(len(s)-1):
    left = s[i]
    right = s[i+1]
    if left == "<" and right == ">":
        top.add(i+1)
    elif left == ">" and right == "<":
        bottom.add(i+1)

if s[n-1] == ">":
    bottom.add(n)
else:
    top.add(n)

for b in list(bottom):
    counter = 0
    for i in range(b, n+1):
        if i in top:
            break
        else:
            Ans[i] = counter
            counter += 1

    counter = 0
    for i in range(b-1, -1, -1):
        if i in top:
            break
        else:
            Ans[i] = counter + 1
            counter += 1


for t in list(top):
    if t == 0:
        Ans[0] = Ans[1] + 1
    if t == n:
        Ans[n] = Ans[n-1] + 1
    else:
        Ans[t] = max(Ans[t-1] + 1, Ans[t+1] + 1)



print(sum(Ans))

Solution (Python):
S=input()
N=len(S)+1
LEFT=[0]
RIGHT=[0]
left=0
right=0
for i in range(N-1):
  if S[i]==">":
    left=0
  else:
    left+=1
  LEFT+=[left]
for i in range(N-2,-1,-1):
  if S[i]=="<":
    right=0
  else:
    right+=1
  RIGHT+=[right]
ans=0  
for i in range(N):  
  ans+=max(LEFT[i],RIGHT[N-1-i])
print(ans)

Solution (Python):
import itertools
S=input()
N=len(S)+1
ans=0
KEY=[]
gr=itertools.groupby(list(S))
i=0
for key,group in gr:
  n=len(list(group))
  ans+=n*(n+1)//2
  KEY+=[n]
  if key==">" and i!=0:
    ans-=min(KEY[i-1],KEY[i])
  i+=1
print(ans)

Solution (Python):
s = input()
n = len(s)+1
A = [0]*n

for i in range(n-1):
    if s[i] == '<':
        A[i+1] = A[i] + 1

for i in reversed(range(n-1)):
    if s[i] == '>':
        A[i] = max(A[i], A[i+1] + 1)

print(sum(A))

Solution (Python):
from itertools import groupby

s = input()
A = [(key, sum(1 for _ in group)) for key, group in groupby(s)]
tmp = 0
ans = 0
for key, count in A:
    if key == '<':
        ans += count*(count+1)//2
        tmp = count
    else:
        if tmp < count:
            ans -= tmp
            ans += count
        ans += (count-1)*count//2
        tmp = 0
print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement, groupby
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return (int(x) for x in input().split())
def LI(): return list(Is())
def TI(): return tuple(Is())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(S())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18


s = S()
A = [(key, sum(1 for _ in group)) for key, group in groupby(s)]
tmp = 0
ans = 0
for key, count in A:
    if key == '<':
        ans += count*(count+1)//2
        tmp = count
    else:
        if tmp < count:
            ans -= tmp
            ans += count*(count+1)//2
        else:
            ans += (count-1)*count//2
        tmp = 0
print(ans)

Solution (Python):
s = input()
big = 0
small = 0
n = 0
big2 =0
for i in range(len(s)):
  if s[i]=='<':
    big += 1
    n += big
    small =0
    big2 = big
  else:
    small += 1
    n += small
    if small<=big2:
      n-=1
      big =0
print(n)

Solution (Python):
import re
s = input()
ans = [-1] * (len(s) + 1)
if s[0] == '<':
    ans[0] = 0
    diff = 1
    while (0 <= diff -1 < len(s)):
        if (s[diff - 1] == '>'):
            break
        ans[diff] = max(ans[diff], ans[diff - 1] + 1)
        diff += 1
        
if s[len(s) - 1] == '>':
    t = len(s)
    ans[t] = 0
    diff = -1
    while (0 <= t + diff < len(s)) & (s[t + diff] == '>'):
        ans[t + diff] = max(ans[t + diff], ans[t + diff + 1] + 1)
        diff -= 1

match = []
for i in range(len(s)):
    if s[i:i+2] == '><':
        match.append(i)

for i in match:
    ans[i + 1] = 0
    diff = 1
    while (0 <= i + 1 - diff < len(s)):
        if s[i - diff + 1] == '<':
            break
        ans[i + 1 - diff] = max(ans[i + 1 - diff], ans[i - diff + 2] + 1)
        diff += 1
    diff = 1
    while (0 <= i + diff < len(s)):
        if s[i + diff] == '>':
            break
        ans[i + 1 + diff] = max(ans[i + 1 + diff], ans[i + diff] + 1)
        diff += 1
print(sum(ans))

Solution (Python):
s = input()

a = 0
l = []

for i in s:
    if a == 0:
        if i == "<":
            a = 1
        else:
            a = -1
    elif ((a > 0) and i == "<"):
        a += 1
    elif ((a < 0) and i == ">"):
        a -= 1
    elif i == "<":
        l.append(a)
        a = 1
    else:
        l.append(a)
        a = -1
l.append(a)

m=[]

for j in l:
    if m:
        if j > 0:
            m.pop()
            for k in range(0, abs(j) + 1, 1):
                m.append(k)
        else:
            b = m.pop()
            if b > abs(j) - 1:
                m.append(b)
                for k in range(abs(j) -1, -1, -1):
                    m.append(k)
            else:
                for k in range(abs(j), -1, -1):
                    m.append(k)
    else:
        if j > 0:
            for k in range(0, abs(j) + 1, 1):
                m.append(k)
        else:
            for k in range(abs(j), -1, -1):
                m.append(k)
            
print(sum(m))

Solution (Python):
s = input() 
ans = 0
flag = False
s += "|"
if s[0] == ">": 
    cntl = 1
    flag = True
    need = 0
else:
    cntr = 1
for i in range(1,len(s)):
    if flag:
        if s[i] == ">":
            ans += cntl
            cntl += 1
        else:
            ans += cntl if cntl >= need else need
            flag = False
            cntr = 1
    else:
        if s[i] == "<":
            ans += cntr
            cntr += 1
        else:
            need = cntr
            flag = True
            cntl = 1
            if i == len(s)-1:
                ans += need
print(ans)

Solution (Python):
s = input()
now = s[0]
c = []
count = 1
for i in range(1,len(s)):
    if (now == s[i]):
        count += 1
    else:
        c.append(count)
        now = s[i]
        count = 1
c.append(count)


def ta(n):
    ans = 0
    for i in range(1,n+1):
        ans += i
    return ans

if (s[0] == "<"):
    a = []
    for i in range(len(c)//2):
        a.append(max(c[2*i],c[2*i+1]))
        a.append(min(c[2*i],c[2*i+1])-1)
    if (len(c)%2==1):
        a.append(c[-1])
    
    ans = 0
    for i in a:
        ans += ta(i)
    print(ans)
else:
    a = []
    a.append(c[0])
    for i in range((len(c)-1)//2):
        a.append(max(c[2*i+1],c[2*i+2]))
        a.append(min(c[2*i+1],c[2*i+2])-1)
    if (len(c)%2==0):
        a.append(c[-1])
    ans = 0
    for i in a:
        ans += ta(i)
    print(ans)

Solution (Python):
s = input()
n = len(s)
a1 = [0] * (n+1) 
a2 = [0] * (n+1) 
tmp1 = 0
tmp2 = 0
for i in range(n):
    if s[i] == "<": tmp1 += 1
    else: tmp1 = 0
    if s[n-i-1] == ">": tmp2 += 1
    else: tmp2 = 0
    a1[i+1] = tmp1
    a2[n-i-1] = tmp2
ans = 0
for i in range(n+1):
    ans += max(a1[i], a2[i])
print(ans)

Solution (Python):
s = input()

a1 = [0] * (len(s) + 1)
for i in range(len(s)):
    if s[i] == '<':
        a1[i + 1] = a1[i] + 1
a2 = [0] * (len(s) + 1)
for i in reversed(range(len(s))):
    if s[i] == '>':
        a2[i] = a2[i + 1] + 1

ans = 0
for i in range(len(a1)):
    ans += max(a1[i], a2[i])
print(ans)

Solution (Python):
s = input()
x = s.replace('<>', '<|>').split('|')


def func(t):
    c1 = t.count('>')
    c2 = len(t) - c1
    return list(reversed(range(1, c1 + 1))) + list(range(c2 + 1))


a = func(x[0])
for i in range(1, len(x)):
    ai = func(x[i])
    a[-1] = max(a[-1], ai[0])
    a.extend(ai[1:])


ans = sum(a)
print(ans)

Solution (Python):
def main():
    S = input()
    N = len(S)

    ret = [0] * (N + 1)

    for i, c in enumerate(S, start=1):
        if c == '<':
            ret[i] = max(
                ret[i],
                ret[i - 1] + 1
            )

    for i, c in enumerate(reversed(S), start=1):
        i = N - i
        if c == '>':
            ret[i] = max(
                ret[i],
                ret[i + 1] + 1
            )

    print(sum(ret))


if __name__ == '__main__':
    main()

Solution (Python):
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)]




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
        
        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
        
    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(sum(A))

Solution (Python):
s=input()
cnt=0
if s[0]=="<":
    cnt=1
else:
    cnt=-1
l=[]
for i in range(len(s)-1):
    if s[i]=="<":
        if s[i+1]=="<":
            cnt+=1
        else:
            l.append(cnt)
            cnt=-1
    else:
        if s[i+1]==">":
            cnt-=1
        else:
            l.append(cnt)
            cnt=1
l.append(cnt)
ans=0
for i in range(len(l)-1):
    if l[i]>0 and l[i+1]<0:
        a=abs(l[i])
        b=abs(l[i+1])
        ans+=max(a,b)
        ans+=(a-1)*a//2+(b-1)*b//2

if l[0]<0:
    ans+=(abs(l[0])+1)*abs(l[0])//2

if l[-1]>0:
    ans+=(l[-1]+1)*l[-1]//2
print(ans)

Solution (Python):
S = input()
n = len(S) + 1
A = []
mini = 0

for i in range(n-1):
  if i==0:
    if S[i]=="<":
      A.append([1,0])
    else:
      A.append([0,1])
  else:
    if S[i]=="<" and S[i-1]==">":
      A.append([1,0])
    elif S[i]=="<":
      A[-1][0] += 1
    else:
      A[-1][1] += 1

summ = 0
for x in A:
  ma = max(x)
  mi = min(x)
  summ += (ma+1)*ma//2
  summ += (mi-1)*mi//2
print(summ)

Solution (Python):
S = list(input())
N = len(S)


dammy1=[0]*(N+1)
A=0
for i in range(1,N+1):
    if S[i-1]=='<':
        A+=1
        dammy1[i]=A
    elif S[i-1]=='>':
        A=0
        dammy1[i]=A

dammy2=[0]*(N+1)
B=0
for i in range(1,N+1):
    if S[-i]=='>':
        B+=1
        dammy2[-(i+1)]=B
    elif S[-i]=='<':
        B=0
        dammy2[-(i+1)]=B




out=[0]*(N+1)
for i in range(N+1):
    out[i] = max(dammy1[i], dammy2[i])


print(sum(out))

Solution (Python):
s=input()
s_l=len(s)

left=[0 for i in range(s_l+1)]
right=[0 for i in range(s_l+1)]

for i in range(s_l):
  if s[i]=='<':
    left[i+1]=left[i]+1
for i in range(s_l-1,-1,-1):
  if s[i]=='>':
    right[i]=right[i+1]+1

ans=0
for i,j in zip(left,right):
  ans+=max(i,j)
print(ans)

Solution (Python):
S = input()

count = 1
S2 = []
for i in range(len(S)):
    if i < len(S)-1 and S[i] == S[i+1]:
        count += 1
    else:
        if S[i] == '<':
            S2.append(['<', count])
        else:
            S2.append(['>', count])
        count = 1
ans = 0
for i in range(len(S2)):
    if S2[i][0] == '<':
        if i < len(S2)-1:
            if S2[i][1] < S2[i+1][1]:
                ans += (S2[i][1] - 1) * (S2[i][1] - 0) // 2
            else:
                ans += S2[i][1] * (S2[i][1] + 1) // 2
        else:
            ans += S2[i][1] * (S2[i][1] + 1) // 2
    else:
        if i > 0:
            if S2[i-1][1] >= S2[i][1]:
                ans += (S2[i][1] - 1) * (S2[i][1] - 0) // 2
            else:
                ans += S2[i][1] * (S2[i][1] + 1) // 2
        else:
            ans += S2[i][1] * (S2[i][1] + 1) // 2
print(ans)

Solution (Python):
S=input()
num=0
ans=0
con=0
upcon=0
before="<"
for s in S:
  if s==before and s=="<":
    upcon+=1
    num+=1
    ans+=num
  if s==">":
    con+=1
    num-=1
    ans+=num
  if s=="<" and before==">":
    ans+=(-num)*(con+(con>upcon))
    con=0
    upcon=1
    num=1
    ans+=num
  before=s
if con!=0:
  ans+=(-num)*(con+(con>upcon))
print(ans)

Solution (Python):
s = input()
a = [-1] * (len(s) + 1)

if s[0] == "<":
    a[0] = 0
if s[-1] == ">":
    a[-1] = 0
    
for i in range(len(s) - 1):
    if s[i] == ">" and s[i + 1] == "<":
        a[i + 1] = 0 

for i in range(len(a)):
    if a[i] == 0:
        l = i - 1
        while 0 <= l - 1:
            if s[l] == ">" and s[l - 1] == ">":
                a[l] = a[l + 1] + 1
            else:
                break
            l -= 1
        r = i + 1
        while r + 1< len(a):
            if s[r - 1] == "<" and s[r] == "<":
                a[r] = a[r - 1] + 1
            else:
                break
            r += 1

for i in range(len(a)):
    if a[i] == -1:
        if i == 0:
            a[i] = a[i + 1] + 1
        elif i == len(a) - 1:
            a[i] = a[i - 1] + 1
        else:
            a[i] = max(a[i - 1], a[i + 1]) + 1
            
ans = sum(a)
print(ans)

Solution (Python):
s = input()
n = len(s)
left = [0 for _ in range(n+1)]
right = [0 for _ in range(n+1)]

tmp = 0
for i in range(n):
    if s[i] == '<':
        tmp += 1
    else:
        tmp = 0
    left[i+1] = tmp

tmp = 0
for i in range(n-1, -1, -1):
    if s[i] == '>':
        tmp += 1
    else:
        tmp = 0
    right[i] = tmp

ans = 0
for i in range(n+1):
    ans += max(right[i], left[i])

print(ans)

Solution (Python):
s=input()
n=len(s)
ans=0
currentstreak=0
numberbefore=0
legacy=0
for i in range(n):
  if s[i]=='<':
    numberbefore+=1
    ans+=numberbefore
    currentstreak=0
    legacy=numberbefore
  else:
    currentstreak+=1
    ans+=currentstreak
    if currentstreak<=legacy:
      ans-=1
    numberbefore=0
print(ans)

Solution (Python):

s = list(str(input()))

n = len(s)+1


from_left = [0 for _ in range(n)]
from_right = [0 for _ in range(n)]

for i, sym in enumerate(s, 1):
    if sym == ">":
        from_left[i] = 0
    else:
        from_left[i] = from_left[i-1]+1

for i, sym in enumerate(s[::-1]):
    i = n-2-i
    if sym == "<":
        from_right[i] = 0
    else:
        from_right[i] = from_right[i+1]+1

seq = [max(x, y) for x, y in zip(from_left, from_right)]

print(sum(seq))

Solution (Python):
s = input()
a = 0
ans = 0
b = 0
d = [0]
e = []
now = 0

for i in range(len(s)):
    if s[i] == '<':
        
        if a != 0:
            if a > now:
                ans = ans - d[-1] + a
                
            for j in range(a):
                ans = ans + j
                d.append(a - j)
                e.append(">")
            now = 0
            a = 0
        
        ans = ans + now + 1
        now = now + 1
        d.append(now)
        
    else:
        a = a + 1
        b = 0
    
if a != 0:
    if a > now:
        ans = ans - d[-1] + a
                
    for j in range(a):
        ans = ans + j
        d.append(a - j)
        e.append(">")
    
print(ans)

Solution (Python):
S = input()
a = [0 for i in range(len(S)+1)]
for i, x in enumerate(S):
    if x == '<':
        a[i+1] = max(a[i+1], a[i]+1)
for i in range(len(S)):
    if S[-i-1] == '>':
        a[-i-2] = max(a[-i-2], a[-i-1]+1)
print(sum(a))

Solution (Python):
s=input()

result=[0]*(len(s)+1)


for index,ss in enumerate(s):
    if ss=="<":
        result[index+1]=result[index]+1

for i in range(len(s)):
    index=len(s)-i-1
    if s[index]==">":
        result[index]=max(result[index],result[index+1]+1)
print(sum(result))

Solution (Python):
S = input()
a = [0 for i in range(len(S)+1)]
for i, x in enumerate(S):
    if x == '<':
        a[i+1] = max(a[i+1], a[i]+1)
for i in range(len(S)):
    if S[-i-1] == '>':
        a[-i-2] = max(a[-i-2], a[-i-1]+1)
print(sum(a))

Solution (Python):
s=input()

l=[0]
r=[0]
l_,r_=0,0
for i in range(len(s)):
    if s[i]=='<':
        l_+=1
    else:
        l_=0
    l.append(l_)
    if s[-1-i]=='>':
        r_+=1
    else:
        r_=0
    r.append(r_)
r.reverse()
ans=0
for i in range(len(s)+1):
    ans+=max(l[i],r[i])
print(ans)

Solution (Python):
s = input()
d = [[0]*2 for _ in range(len(s)+1)]
count_r = 0
count_l = 0
ans = 0
for i in range(len(s)):
    if s[i] == "<":
        d[i+1][0] = d[i][0]+1
    else:
        d[i+1][0] = 0
for i in range(len(s)-1, -1, -1):
    if s[i] == ">":
        d[i][1] = d[i+1][1]+1
    else:
        d[i][1] = 0
for i in range(len(s)+1):
    ans += max(d[i])
print(ans)

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007



def main():
	
	
	s = input()
	if s[0] == '>':
		s = '<' + s
		
	if s[-1] == '<':
		s = s + '>_'
	else:
		s = s + '_'
		
	dd = []
	pre = '<'
	count = [1,0]
	for c in s[1:]:
		if c == '<' and pre == '<':
			count[0] += 1
		elif c == '>' and pre == '>':
			count[1] += 1
		elif c == '>' and pre == '<':
			pre = '>'
			count[1] = 1
		elif c == '<' and pre == '>':
			pre = '<'
			dd.append(count)
			count=[1,0]
		else:
			dd.append(count)
	
	ret_sum = 0
	for l, r in dd:
		ret_sum += (r*(r+1)//2) + (l*(l+1)//2) - min(r,l)
	print(ret_sum)
		
		
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)