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):
def main():
    s = input().rstrip("\n")
    import re
    parts = re.findall("((>*)(<*))", s)
    total = 0
    whole, left, right = parts[0]
    left_len = len(left)
    left_sum = (left_len * (left_len + 1)) // 2
    right_len = len(right)
    right_sum = (right_len * (right_len - 1)) // 2
    total = left_sum + right_sum
    for whole, left, right in parts[1:-1]:
        left_len = len(left)
        left_sum = (left_len * (left_len - 1)) // 2
        total += left_sum + max(left_len, right_len)
        right_len = len(right)
        right_sum = (right_len * (right_len - 1)) // 2
        total += right_sum
    total += right_len

    print(total)
if __name__ == "__main__":
    main()

Solution (Python):



def main():
    s = input()
    al, ar = ([0] * (len(s) + 1), [0] * (len(s) + 1))
    for i in range(0, len(s)):
        al[i + 1] = al[i] + 1 if s[i] == '<' else 0

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

    sum_a = sum([max(aln, arn) for aln, arn in zip(al, ar)])
    print(sum_a)


if __name__ == '__main__':
    main()

Solution (Python):
S = input()
n = len(S)
ans = [0]*(n+1)
for i in range(n):
    if S[i]=='<':

        ans[i+1]=ans[i]+1
    

for i in range(n-1,-1,-1):
    if S[i]==">":
        if ans[i]>ans[i+1]:
            continue
        else:
            ans[i]=ans[i+1]+1
    
res = 0
for i in range(n+1):
    res+=ans[i]

print(res)

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

Solution (Python):
s=input()
l=len(s)
arr1=[0]
cnt=0
for i in range(l):
  if s[i]=='<':
    cnt+=1
  else:
    cnt=0
  arr1.append(cnt)
arr2=[0]
cnt=0
for i in range(l-1,-1,-1):
  if s[i]=='>':
    cnt+=1
  else:
    cnt=0
  arr2.append(cnt)
arr2=arr2[::-1]
ans=0
for i in range(l+1):
  ans+=max(arr1[i],arr2[i])
print(ans)

Solution (Python):
s=input()
arr=[0]*(len(s)+1)
x=0
while x<len(s):
	i=x
	j=x+1
	if s[i]=='<':
		if arr[i] >= arr[j]:
			arr[j] = arr[i]+1
	else:
		if arr[i] <= arr[j]:
			arr[i] = arr[j]+1
	x+=1

x=len(s)-1
while x>=0:
	i=x
	j=x+1
	if s[i]=='<':
		if arr[i] >= arr[j]:
			arr[j]=arr[i]+1
	else:
		if arr[i] <= arr[j]:
			arr[i]=arr[j]+1
	x-=1

print(sum(arr))

Solution (Python):
S = list(input())
N = len(S)+1
L = [0]*N
R = [0]*N
for i in range(N-1):
    if S[i] == "<":
        L[i+1] = L[i]+1
for i in range(N-2,-1,-1):
    if S[i] == ">":
        R[i] = R[i+1]+1
ans = 0
for i in range(N):
    ans += max(L[i],R[i])
print(ans)

Solution (Python):
def main():
    S = input()
    N = len(S)
    i = 0
    ans = 0
    while i < N:
        inc = 0
        dec = 0
        while i < N and S[i] == "<":
            inc += 1
            i += 1
        while i < N and S[i] == ">":
            dec += 1
            i += 1
        ans += (inc - 1) * inc // 2
        ans += (dec - 1) * dec // 2
        ans += max(inc, dec)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
a=input()
n=len(a)
p=0
q=0
r=0
i=0
while i<n:
  while a[i]=="<":
    i+=1
    p+=1
    if i==n:
      print(r+p*(p+1)//2)
      exit(0)
  while a[i]==">":
    i+=1
    q+=1
    if i==n:
      break
  r+=p*(p+1)//2+q*(q+1)//2-min(p,q)
  p=0
  q=0
print(r)

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

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    s = input().strip()
    N = len(s)
    left = [0] * N
    right = [0] * N
    
    if s[0] == "<":
        left[0] = 1
    for i in range(1, N):
        if s[i] == "<":
            left[i] = left[i-1] + 1
    
    if s[-1] == ">":
        right[-1] = 1
    for i in range(N-2, -1, -1):
        if s[i] == ">":
            right[i] = right[i+1] + 1
    
    ans = right[0] + left[-1]
    for i in range(N-1):
        ans += max(left[i], right[i+1])
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
S = input()
result = 0
i = 0
while i < len(S):
    count_L = 0
    while i < len(S) and S[i] == '<':
        count_L += 1
        i += 1
    count_R = 0
    while i < len(S) and S[i] == '>':
        count_R += 1
        i += 1
    result += count_L * (count_L - 1) // 2 + count_R * (count_R - 1) // 2 + max(count_L, count_R)
print(result)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)

s = str(input())
c = s[0]
ran = [1]
for i in range(1, len(s)):
    if c == s[i]:
        ran[-1] += 1
    else:
        ran.append(1)
        c = s[i]

result = ran[0]
if s[0] == '<':
    result = ((ran[0]-1)*ran[0])//2
    h = True
else:
    result = ((1+ran[0])*ran[0])//2
    h = False
if len(ran) == 1:
    result = ((1+ran[0])*ran[0])//2

for i in range(1, len(ran)):
    if h:
        if ran[i-1] < ran[i]:
            result += ((1+ran[i])*ran[i])//2
        else:
            result += ((ran[i]-1)*ran[i])//2 + ran[i-1]
        h = False
    else:
        result += ((ran[i]-1)*ran[i])//2
        h = True
        if i == len(ran)-1:
            result += ran[i]
print(int(result))

Solution (Python):
import sys
sys.setrecursionlimit(5000000)

s = input()
if len(s) == 1:
    print("1")
    exit()
cont_list = []
ini_di = s[0]
count = 1
for i in range(1, len(s)):
    if s[i] == s[i-1]:
        count += 1
        if i == len(s) - 1:
            cont_list.append(count)
    else:
        cont_list.append(count)
        count = 1
        if i == len(s) - 1:
            cont_list.append(count)


def counting(i):
    a = max(cont_list[i], cont_list[i + 1])
    b = min(cont_list[i], cont_list[i + 1])
    return (1 + a) * a / 2 + b * (b - 1) / 2


if ini_di == "<":
    count2 = 0
    if len(cont_list) % 2 == 0:
        for i in range(0, len(cont_list), 2):
            count2 += int(counting(i))
    else:
        for i in range(0, len(cont_list)-1, 2):
            count2 += int(counting(i))
        las = cont_list[len(cont_list)-1]
        count2 += int((1+las)*las/2)
    print(count2)
else:
    count2 = 0
    if len(cont_list) % 2 == 1:
        ini = cont_list[0]
        count2 += int((1+ini)*ini/2)
        for i in range(1, len(cont_list), 2):
            count2 += int(counting(i))
    else:
        ini = cont_list[0]
        count2 += int((1 + ini) * ini / 2)
        las = cont_list[len(cont_list) - 1]
        count2 += int((1 + las) * las / 2)
        for i in range(1, len(cont_list)-1, 2):
            count2 += int(counting(i))
    print(count2)

Solution (Python):
S=input()
data=[-1 for i in range(len(S)+1)]
if S[0]=="<":data[0]=0
if S[-1]==">":data[-1]=0


for i in range(len(S)-1):
    if S[i]+S[i+1]=="><":
        data[i+1]=0
for i in range(len(S)):
    if data[i]>=0 and S[i]=="<":
        data[i+1]=data[i]+1
for i in range(len(S)-1,-1,-1):
    if data[i+1]>=0 and S[i]==">":
        if S[i-1]+S[i]=="<>" and i>=1:
            data[i]=max(data[i],data[i+1]+1)
        else:
            data[i]=data[i+1]+1
print(sum(data))

Solution (Python):
S=input()
n=len(S)

def f(a):
  return a*(a+1)//2

ans=0
i=0
if S[i]=='>':
  while i<n and S[i]=='>':
    i+=1
    
  ans+=f(i)
  
while i<n:
  j=i+1
  while j<n and S[j]=='<':
    j+=1
    
  if j==n:
    ans+=f(j-i)
    i=j+1
  else:
    k=j+1
    while k<n and S[k]=='>':
      k+=1
      
    if j-i>k-j:
      ans+=f(j-i)+f(k-j-1)
    else:
      ans+=f(j-i-1)+f(k-j)
      
    i=k
    
print(ans)

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

for s in s_arr:
  left = s.count('<')
  right = len(s) - left
  if left < right:
    left -= 1
    ans += left * (left + 1) // 2 + right * (right + 1) // 2
  else:
    right -= 1
    ans += left * (left + 1) // 2 + right * (right + 1) // 2

print(ans)

Solution (Python):

import sys


def count_S(S, N):
    ret=S.find('>')
    
    if ret==-1:
        ret=N
    return ret


def count_L(S, N):
    ret=S.find('<')
    if ret==-1:
        ret=N
    
    return ret

def count_S_slow(S, ns, N):
    ret=0
    for i in range(ns,N):
        if S[i:i+1]=='<':
            ret+=1
        else:
            break
    return ret

def count_L_slow(S, ns, N):
    ret=0
    for i in range(ns,N):
        if S[i:i+1]=='>':
            ret+=1
        else:
            break
    return ret

def solve(S: str):
    answer=0
    
    numS=len(S)
    cnt_l=count_L(S,len(S))
    answer+=(cnt_l+1)*cnt_l//2
    i=cnt_l
    while i<len(S):
        cnt_s=count_S_slow(S,i,numS)
        cnt_l=count_L_slow(S,i+cnt_s,numS)
        answer+=(cnt_s+1)*cnt_s//2
        answer+=(cnt_l+1)*cnt_l//2
        if cnt_l>cnt_s:
           answer-=cnt_s
        else:
           answer-=cnt_l
        
        
        i+=cnt_s+cnt_l

    print(answer)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  
    solve(S)

if __name__ == '__main__':
    main()

Solution (Python):

import sys
s = sys.stdin.readline().rstrip()
n = len(s)
L = [0 for _ in range(n+1)]

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



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



print(sum(L))

Solution (Python):
s=input()
n=len(s)
a=[0]*(n+1)
b=a[:]
x=0
for i in range(n):
  if s[i]=="<":
    x+=1
  else:
    x=0
  a[i+1]=x
x=0
for i in range(n-1,-1,-1):
  if s[i]==">":
    x+=1
  else:
    x=0
  b[i]=x
print(sum([max(i,j) for (i,j) in zip(a,b)]))

Solution (Python):
S = list(">" + input() + "<")


N = len(S) - 1
inf = 1001001
table = [inf] * N

minnum = 0
l = 0
r = 1


for i in range(N):
    if S[i+1] == "<" and S[i] == ">":
        table[i] = 0
    elif S[i] == "<":
        table[i] = table[i-1] + 1

for i in range(N, 0, -1):
    if S[i-1] == ">" and S[i] == ">":
        if table[i-1] > table[i] + 1:
            table[i-1] = table[i] + 1
    elif S[i-1] == "<" and S[i] == ">":
        if table[i-1] < table[i] + 1:
            table[i-1] = table[i] + 1

print(sum(table))

Solution (Python):
s=input()
left=[0 for c in s+" "]
right=[0 for c in s+" "]


cnt=0
for i in range(len(s)):
    if s[i]=="<":
        cnt+=1
        left[i+1]=cnt
    else:
        cnt=0

cnt=0
for i in range(len(s)):
    if s[len(s)-i-1]==">":
        cnt+=1
        right[len(s)-i-1]=cnt
    else:
        cnt=0

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

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 range(N-2, -1, -1):
  if S[i] == '>':
    a[i] = max(a[i+1]+1,a[i])

print(sum(a))

Solution (Python):
s = input()
arr = [0]
for i in range(len(s)):
  if s[i] == '<':
    arr.append(arr[i]+1)
  else:
    arr.append(0)

for i in reversed(range(len(s))):
  if s[i] == '>':
    arr[i] = max(arr[i],arr[i+1]+1)
print(sum(arr))

Solution (Python):
s = input()
s += "e"
border = 0
count = 0
flag = ">"
answer = 0

for i in s:
    if i == flag:
        count += 1

    else:
        if flag == ">":
            answer += max(border, count) + (count * (count - 1)) // 2
            border = 0
        else:
            answer += (count * (count - 1)) // 2
            border = count
        flag = i
        count = 1
else:
    answer += border

print(answer)

Solution (Python):
S = input()
y = 0
sum_t = 0
up = False
pre = 0
for c in S:
	if c == '<':
		if up:
			y += 1
		else:
			y = 1
			up = True
		sum_t += y
	elif c == '>':
		if up:
			pre = y
			y = 1
			up = False
		else:
			y += 1
			sum_t += y
			if y <= pre:
				sum_t -=1
print(sum_t)

Solution (Python):
import itertools
S = input()
A = [len(list(v)) for _, v in itertools.groupby(S)]
ans = 0
if S[0] == '>':
    a, A = A[0], A[1:]
    ans += a * (a + 1) // 2
for a, b in zip(A[::2], A[1::2]):
    ans += a * (a + 1) // 2 + b * (b + 1) // 2 - min(a, b)
if S[-1] == '<':
    a = A[-1]
    ans += a * (a + 1) // 2
print(ans)

Solution (Python):
s = list(input())
n = len(s)



a = [0]*(n+2)


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], a[i+1]+1)

print(sum(a))

Solution (Python):
def do_left(s, v, idx):
  while idx > 0 and s[idx] == '>':
    v[idx - 1] = max(v[idx] + 1, v[idx - 1])
    idx -= 1

def do_right(s, v, idx):
  while idx < len(v) - 1 and s[idx + 1] == '<':
    v[idx + 1] = max(v[idx] + 1, v[idx + 1])
    idx += 1
    
def main():
  s = '>' + input().strip() + '<'
  v = [-1] * (len(s) - 1)
  
  for i, (b, a) in enumerate(zip(s[:-1], s[1:])):
    if b == '>' and a == '<':
      v[i] = 0
      do_left(s, v, i)
      do_right(s, v, i)

  
  print(sum(v))
  
if __name__ == '__main__':
  main()

Solution (Python):
S = input()
y = 0
sum_t = 0
up = False
pre = 0
for c in S:
	if c == '<':
		if up:
			y += 1
		else:
			y = 1
			up = True
		sum_t += y
	elif c == '>':
		if up:
			pre = y
			y = 1
			up = False
		else:
			y += 1
			sum_t += y
			if y <= pre:
				sum_t -=1
print(sum_t)

Solution (Python):
S = input()
y = 0
sum_t = 0
up = False
pre = y
for c in S:
	if c == '<':
		if up:
			y += 1
		else:
			y = 1
		sum_t += y
		up = True
	elif c == '>':
		if up:
			pre = y
			y = 1
		else:
			y += 1
			sum_t += y
			if y <= pre:
				sum_t -=1
		up = False
print(sum_t)

Solution (Python):
S = input()
y = 0
sum_t = 0
up = False
pre = y
for i in range(len(S)):
	if S[i] == '<':
		if up & (i!=(len(S))):
			y += 1
			sum_t += y
		else:
			y = 1
			sum_t += y
		up = True
	elif S[i] == '>':
		if up == False & (i!=(len(S))):
			y += 1
			sum_t += y
			if y <= pre:
				sum_t -=1
		else:
			pre = y
			y = 1
		up = False
print(sum_t)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

a = list(input())


k = [[0 for i in range(len(a)+1)] for j in range(3)]

for j in range(len(a)):
    if a[j] == "<":
        k[0][j+1] = 1
    elif a[j] == ">":
        k[1][j] = 1

for i in range(len(a)):
    if k[0][i+1] > 0 and k[0][i] > 0:
        k[0][i+1] += k[0][i]
for i in range(len(a)):
    if k[1][-(i+1)] > 0 and k[1][-(i+2)] > 0:
        k[1][-(i+2)] += k[1][-(i+1)] 
for i in range(len(a)+1):
    if k[1][i] >= k[0][i]:
        k[2][i] = k[1][i]
    else:
        k[2][i] = k[0][i]


print(sum(k[2]))

Solution (Python):
S = input()
a = [0] * (len(S) + 1)

for i in range(len(S)):
    if S[i] == '<':
        a[i + 1] = max(a[i + 1], a[i] + 1)
for i in reversed(range(len(S))):
    if S[i] == '>':
        a[i] = max(a[i], a[i + 1]+1)
ans = sum(a)

print(ans)

Solution (Python):
from itertools import*
a=b=0
for c,m in groupby(input()):m=len(list(m));a-=m*~m//2+min(m,b)*(c>'<');b=m
print(a)

Solution (Python):
from itertools import*
a=b=0
for c,m in groupby(input()):m=len(list(m));a+=m*-~m//2-min(m,b)*(c>'<');b=m
print(a)

Solution (Python):
from itertools import*
a=b=0
for c,m in groupby(input()):m=len(list(m));a+=m*-~m//2-min(m,b)*(c>'<');b=m
print(a)

Solution (Python):
from itertools import*
g=[(c>'<',len(list(m)))for c,m in groupby(input())]
n=len(g)
a=b=0
for i,(c,m)in enumerate(g):
  a+=m*~-m//2+max(m,b)*c+m*(c^1)*(i>n-2)
  b=m
print(a)

Solution (Python):
S = input()
baf = S[0]
anscount = 0
count = 0
count2 = 0
count3 = 0
count4 = 0
farstflag = 1
countflag = 0
countflag2 = 0
def plus(N):
    return N * (N - 1) // 2
while(count < len(S)):
    
    if farstflag == 1 and S[0] == "<":
        farstflag = 0
    if farstflag == 1 and S[0] == ">":
        farstflag = 0
        countflag = 1
    if countflag == 1:
        if baf != S[count]:
            
            anscount += plus(count2 + 1)
            countflag = 0
        count2 += 1
        if count == len(S) - 1:
            anscount += plus(count2 + 1)
    if farstflag == 0 and countflag == 0 and countflag2 == 0:
        if S[count] == "<":
            count3 += 1
        else:
            countflag2 = 1
            count4 += 1
            count+= 1
            continue
    if farstflag == 0 and countflag == 0 and countflag2 == 1:
        if S[count] == ">":
            count4 += 1
        else:
            anscount += plus(max(count3, count4) + 1)
            anscount += plus(min(count3, count4))
            countflag2 = 0
            count4 = 0
            count3 = 0
            count3 += 1

    baf = S[count]
    count += 1
anscount += plus(max(count3, count4) + 1)
anscount += plus(min(count3, count4))


print(anscount)

Solution (Python):
from bisect import bisect_left

s = input()
n = len(s)+1


localmin = set()
localmax = set()

if s[0]=="<":
    
    localmin.add(0)
else:
    localmax.add(0)
    

if s[n-2]==">":
    
    localmin.add(n-1)
else:
    localmax.add(n-1)

for i in range(n-2):
    if s[i]==">" and s[i+1]=="<":
        
        localmin.add(i+1)
    elif s[i]=="<" and s[i+1]==">":
        localmax.add(i+1)        

localmin.add(-1)
localmin.add(n)

ans = 0

localmin = list(localmin)
localmin.sort()
for i in localmax:
    j = bisect_left(localmin, i)
    left = i - localmin[j-1]
    right= localmin[j] - i
    long = max(left, right)
    short= min(left, right)
    
    ans += (long * (long + 1))//2
    ans += (short* (short- 1))//2    

print(ans)

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

Solution (Python):



def main():
    s = list(input())
    n = len(s) + 1
    ans = [0 for _ in range(n)]

    
    
    
    
    
    

    
    
    

    
    

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

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

    print(sum(ans))


if __name__ == '__main__':
    main()

Solution (Python):

import sys
input = lambda: sys.stdin.buffer.readline()[:-1].decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

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

Solution (Python):

import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

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

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

Solution (Python):
s = input()

index = 0
thanS = s[0]
count = 1
a = []
for i in range(1, len(s)):
    if thanS == s[i]:
        count += 1

    else:
        a.append(s[index: index + count])
        thanS = s[i]
        index = index + count
        count = 1

a.append(s[index:])
b = 0
add = 0

for i in range(len(a)):
    diff = len(a[i])
    if a[i][0] == "<":
        add += diff * (diff + 1) / 2
        b = diff
    else:
        if b < diff:
            add = add + diff * (diff + 1) / 2 - b
        else:
            add = add + (diff - 1) * diff / 2
        b = 0

print(int(add))

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 range(N-2, -1, -1):
  if S[i] == '>':
    a[i] = max(a[i+1]+1,a[i])

print(sum(a))

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    s = S()
    n = len(s)
    Llis = [0] * (n + 1)
    Rlis = [0] * (n + 1)
    for i in range(n):
        if s[i] == "<":
            Llis[i + 1] = 1
        else:
            Rlis[i] = 1
    for i in range(n):
        if Llis[i + 1] == 0:
            continue
        Llis[i + 1] += Llis[i]
    for i in range(n):
        if Rlis[-i - 2] == 0:
            continue
        Rlis[-i - 2] += Rlis[-i - 1]
    ans = 0
    for i in range(n + 1):
        ans += max(Rlis[i], Llis[i])
    print(ans)
    return


def B():
    return


def C():
    return


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    A()

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

Solution (Python):
S = input()

N = len(S)+1
a = [0] * N
for i in range(N-1):
    if S[i] == '<':
        a[i+1] = max(a[i+1], a[i]+1)
for i in range(N-2, -1, -1):
    if S[i] == '>':
        a[i] = max(a[i], a[i+1]+1)

print(sum(a))

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] = a[i] + 1
for i in reversed(range(1, n)):
    if s[i-1] == '>':
        a[i-1] = max(a[i-1], a[i]+1)
print(sum(a))

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

Solution (Python):

s = list(input())
ans = 0
l_count, r_count = 0, 0
l, r = 0, 0
last = ''


for i in range(len(s)):
    if last == '>' and s[i] == '<':
        if l >= r:
            ans += l + r - r_count
        else:
            ans += l + r - l_count
        l_count = 0
        r_count = 1
        l = 0
        r = 1
    else:
        if s[i] == '>':
            l_count += 1
            l += l_count
        else:
            r_count += 1
            r += r_count
    last = s[i]
    

if l >= r:
    ans += l + r - r_count
else:
    ans += l + r - l_count

print(ans)

Solution (Python):
s = input()

n = len(s)+1
a1 =[0]*n
a2 =[0]*n
a =[0]*n


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

for i in range(n):
	a[i] = max(a1[i],a2[i])

print(sum(a))

Solution (Python):
import sys
sys.setrecursionlimit(2147483647) 
S=str(input())
s=list(S)
x1=0
x2=1
y=0
len=len(s)-1
for i in range(len):
  if s[i+1]==s[i]:
    x2=x2+1
  else:
    if i==0:
      x2=0
    if s[i]=='>':
      if x2<x1:
        x2=x2-1
      else:
          x1=x1-1
    y+=x1*(x1+1)/2
    x1=x2
    x2=1
if s[len]=='>':
  if x2<x1:
    x2=x2-1
  else:
    x1=x1-1
y+=x1*(x1+1)/2
y+=x2*(x2+1)/2
print(int(y))

Solution (Python):
import numpy as np
S = list(input())
S_len = len(S)
num_lst = np.zeros(S_len + 1)
for i in range(S_len):
    if S[i] == "<":
        num_lst[i + 1] = max(num_lst[i] + 1, num_lst[i + 1])


for i in range(S_len - 1, -1 , -1):
    if S[i] == ">":
        num_lst[i] = max(num_lst[i], num_lst[i + 1] + 1)
print(int(np.sum(num_lst)))

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

Solution (Python):
from collections import Counter
from itertools import groupby

s = input()
rlc = [len(list(itr)) for _, itr in groupby(s)]
for i in range(s[0] == '>', len(rlc) - 1, 2):
    rlc[i + (rlc[i] > rlc[i + 1])] -= 1
print(sum(l * (l + 1) * c // 2 for l, c in Counter(rlc).items()))

Solution (Python):
import itertools

s = input()
rlc = [len(list(itr)) for _, itr in itertools.groupby(s)]
for i in range(s[0] == '>', len(rlc) - 1, 2):
    if rlc[i] < rlc[i + 1]:
        rlc[i] -= 1
    else:
        rlc[i + 1] -= 1

print(sum(l * (l + 1) // 2 for l in rlc))

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

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

a = [0] * (n + 1)

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

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

print(sum(a))

Solution (Python):

import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions
from operator import itemgetter

import sys
def input():
	return sys.stdin.readline().strip()


S = input()

N = len(S) + 1

min_list = deque()
max_list = []
num = [-1]*N
if S[0] == "<":
	min_list.append(1)
	num[0] = 0
if S[-1] == ">":
	min_list.append(N - 2)
	num[N - 1] = 0
for i in range(1, N - 1):
	if S[i - 1] == ">" and S[i] == "<":
		min_list.append(i - 1)
		min_list.append(i + 1)
		num[i] = 0
	if S[i - 1] == "<" and S[i] == ">":
		max_list.append(i)

while len(min_list) > 0:
	x = min_list.popleft()
	if x == 0:
		num[x] = num[x + 1] + 1
	elif x == N - 1:
		num[x] = num[x - 1] + 1
	elif not (S[x - 1] == "<" and S[x] == ">"):
		num[x] = max(num[x - 1], num[x + 1]) + 1
		if num[x - 1] == -1:
			min_list.append(x - 1)
		if num[x + 1] == -1:
			min_list.append(x + 1)

for x in max_list:
	num[x] = max(num[x - 1], num[x + 1]) + 1

print(sum(num))

Solution (Python):

import sys


def count_L_slow(S, N):
    ret=0
    for i in range(N):
        if S[i:i+1]=='>':
            ret+=1
        else:
            break
    return ret

def solve(S: str):

    next_S = [-1 for i in range(len(S) + 1)]
    next_L = [-1 for i in range(len(S) + 1)]

    next_S[len(S)] = -1

    for i in range(len(S) - 1, -1, -1):
        if S[i] == '>':
            next_S[i] = i
        else:
            next_S[i] = next_S[i + 1]

    next_L[len(S)] = -1

    for i in range(len(S) - 1, -1, -1):
        if S[i] == '<':
            next_L[i] = i
        else:
            next_L[i] = next_L[i + 1]



    
    def count_S(i, N):

        if i >= len(next_S):
            return N
        ret = next_S[i] - i
        if ret < 0:
            ret = N
        return ret
    
    
    def count_L(i, N):

        if i >= len(next_L):
            return N
        ret = next_L[i] - i
        if ret < 0:
            ret = N
        return ret


















    answer=0

    cnt_l=count_L(0,len(S))
    answer+=int((cnt_l+1)*cnt_l/2)
    i=cnt_l


    while i<len(S):



        cnt_s=count_S(i, len(S) - i)
        cnt_l=count_L(i+cnt_s, len(S) - (i+cnt_s))

        answer+=int((cnt_s+1)*cnt_s/2)
        answer+=int((cnt_l+1)*cnt_l/2)
        if cnt_l>cnt_s:
           answer-=cnt_s
        else:
           answer-=cnt_l
        
        
        i+=cnt_s+cnt_l

    print(answer)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  
    solve(S)

if __name__ == '__main__':
    main()

Solution (Python):
s = input()

k = [0] * (len(s) + 1)
for i in range(len(s)):
    if s[i] == '<':
        k[i + 1] = max(k[i + 1], k[i] + 1)

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


print(sum(k))

Solution (Python):
from itertools import groupby

s = input()
gr = groupby(s)

ans = 0
n_prev = 0
k_prev = '0'
for k, g in gr:
    n = len(list(g))
    n_sum = n * (n + 1) // 2 
    ans += n_sum
    if k_prev == '<' and n_prev < n:
        ans -= n_prev
    elif k_prev == '<' and n_prev >= n:
        ans -= n
    n_prev = n
    k_prev = k

print(ans)

Solution (Python):
s = input()
l1, l2 = [0],[0]
cnt = 0
for i, j in enumerate(s):
    cnt = cnt + 1 if j == '<' else 0
    l1.append(cnt)
cnt = 0
for i, j in enumerate(s[::-1]):
    cnt = cnt + 1 if j == '>' else 0
    l2.append(cnt)
res = 0
for i, j in zip(l1, l2[::-1]):
    res += max(i, j)
print(res)

Solution (Python):
def groupby2(ar):
    a2=[[ar[0],1]]
    for i in range(1,len(ar)):
        if a2[-1][0]==ar[i]:
            a2[-1][1]+=1
        else:
            a2.append([ar[i],1])
    return a2

inf=10000000
S=input()
l=len(S)
a=[inf]*(l+1)
if l==2:
    print(1)
else:
    b=groupby2(list(S))
    l2=len(b)
    if l2==1:
        print(b[0][1]*(b[0][1]+1)//2)
    else:
        c=(b[0][1]*(b[0][1]+1)//2)
        for i in range(l2-1):
            y=b[i]
            x=b[i+1]
            c+=(x[1]*(x[1]+1)//2)
            if x[0]==">":
                c-=min(x[1],y[1])
        print(c)

Solution (Python):
s = list(input())
n = len(s) + 1
al, ar = [0] * n, [0] * n

for i in range(len(s)):
    if s[i] == "<":
        al[i+1] = al[i] + 1

for i in range(len(s)):
    if s[-(i+1)] == ">":
        ar[i+1] = ar[i] + 1

ans = 0
ar = ar[::-1]

for i in range(len(al)):
    if al[i] >= ar[i]:
        ans += al[i]
    else:
        ans += ar[i]

print(ans)