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):
S=list(input())

N=len(S)
L=[0]*(N+1)
R=[0]*(N+1)

for i in range(N):
  if S[i]=="<":
    L[i+1]=L[i]+1
  else:
    L[i+1]=0


S=S[::-1]
for i in range(N):
  if S[i]==">":
    R[i+1]=R[i]+1
  else:
    R[i+1]=0
R=R[::-1]


answer=0
for i in range(N+1):
  answer+=max(L[i],R[i])
print(answer)

Solution (Python):

s = input()
if s[0] ==">":
    s = "<"+s
if s[-1]=="<":
    s = s +">"

l=len(s)
upp = 0
dwn = 0
ans = 0
U = []
D = []
for i in range(l):
    if s[i] == "<":
        if dwn:
            D.append(dwn)
            ans += dwn*(dwn+1)//2
            dwn = 0
        upp+=1
    else:
        if upp:
            U.append(upp)
            ans += upp*(upp+1)//2
            upp=0
        dwn += 1
ans += dwn*(dwn+1)//2



D.append(dwn)

for i in range(len(D)):
    ans -= min(U[i],D[i])




print(ans)

Solution (Python):
s = input()
a = [0]
for i in s:
    if i == "<":
        a.append(a[-1] + 1)
    else:
        a.append(0)
b = [0]
for i in reversed(s):
    if i == ">":
        b.append(b[-1] + 1)
    else:
        b.append(0)
b.reverse()

c = [max(i, j) for i, j in zip(a, b)]
print(sum(c))

Solution (Python):
from itertools import groupby
import math
import numpy as np

S = list(input())
if S[0]=='>':
    S = ['<']+S
if S[-1]=='<':
    S = S+['>']

D = np.array([len(list(g)) for k, g in groupby(S) ])

D=D.reshape([-1,2])
Asum = 0
for d in D:
    a1 = max(d)
    a2 = min(d)
    Asum += int((a1+1)*a1/2 + a2*(a2-1)/2)

print(Asum)

Solution (Python):
import math
import numpy as np






S = list(input())
if S[0]=='>':
    S = ['<']+S
if S[-1]=='<':
    S = S+['>']

N=len(S)
D=np.zeros(N)
nc = 1
cur = S[0]
curi = 0
for i in range(1,N):
    if S[i]==cur:
        nc += 1
    else:
        D[curi] = nc
        cur = S[i]
        curi += 1
        nc = 1
D[curi] = nc
D = D[D>0]
D=D.reshape([-1,2])
Asum = 0
for d in D:
    a1 = max(d)
    a2 = min(d)
    Asum += int((a1+1)*a1/2 + a2*(a2-1)/2)

print(Asum)

Solution (Python):
s = input()
n = len(s) + 1
l = [None]*n
s = '>' + s + '<'
for i in range(n):
  if s[i] == '>' and s[i+1] == '<':
    l[i] = 0
  elif s[i] == '<':
      l[i] = l[i-1] + 1
for i in range(n-1,-1,-1):
  if s[i+1] == '>':
    if l[i] is None or l[i] < l[i+1]+1:
      l[i] = l[i+1] + 1

print(sum(l))

Solution (Python):
s = input()
key = s[0]
value = 1
key_list = []
for i in range(len(s)-1):
    if s[i+1] == s[i]:
        value += 1
    else:
        key_list.append(value)
        value = 1
key_list.append(value)

ans = 0
if key == ">":
    p = key_list[0]
    ans += p*(p+1)//2
    for i in range((len(key_list)-1)//2):
        p, q = key_list[2*i+1], key_list[2*i+2]
        p, q = max([p, q]), min([p, q])
        ans += (p*(p+1)+q*(q-1))//2
    if len(key_list)%2 == 0:
        p = key_list[-1]
        ans += p*(p+1)//2
else:
    for i in range((len(key_list))//2):
        p, q = key_list[2*i], key_list[2*i+1]
        p, q = max([p, q]), min([p, q])
        ans += (p*(p+1)+q*(q-1))//2
    if len(key_list)%2 == 1:
        p = key_list[-1]
        ans += p*(p+1)//2
print(ans)

Solution (Python):
from itertools import groupby

S = input()

l = [0]*(S[0]=="<") + [len(list(g)) for k, g in groupby(S)] + [0]*(S[-1]==">")

s = 0
m = [0]*(len(l)//2)
for i in range(0, len(l)//2):
    a, b = l[i*2], l[i*2+1]
    m[i] = b
    if i >= 1:
        m[i-1] = min(m[i-1], a)
    s += int((a+1)*(a/2) + (b+1)*(b/2))

print(s-sum(m[:-1]))

Solution (Python):
s= input()
n=len(s)+1
l = []
ts = s[0]
f = 1
for i in range(1,n-1):
    if s[i] ==ts:
        f += 1
    else:
        l.append([ts,f])
        f = 1
        ts = s[i]
l.append([ts,f])

for i in range(len(l)):
    if l[i][0]=="<":
        if i < len(l)-1:
            if l[i][1] >= l[i+1][1]:
                l[i+1][1] -= 1
            else:
                l[i][1] -= 1

res = [(l[i][1]+1)*l[i][1]//2 for i in range(len(l))]
print(sum(res))

Solution (Python):
S = input()
decom = []

temp = 0
for i in range(1,len(S)):
  if S[i] != S[i-1]:
    decom.append((S[i-1],temp + 1))
    temp = 0
  else:
    temp += 1
decom.append((S[-1],temp + 1))

ans = 0
for i in range(len(decom)):
  if decom[i][0] == "<":
    if i == len(decom) - 1:
      ans += decom[i][1]
    ans += (decom[i][1] * (decom[i][1] - 1)) // 2
  else:
    if i == 0 or decom[i][1] > decom[i-1][1]:
      ans += (decom[i][1] * (decom[i][1] + 1)) // 2
    else:
      ans += decom[i-1][1] + (decom[i][1] * (decom[i][1] - 1)) // 2
print(ans)

Solution (Python):
n = input()

def sum(k):
    return (k+1)*k//2

pre = ">"
up = 0
down = 0
ans = 0
for x in n:
    if pre==">" and x ==">":
        down += 1
    elif pre=="<" and x=="<":
        up += 1
    elif pre=="<" and x==">":
        down += 1
    elif pre==">" and x=="<":
        ans += sum(max(up,down)) + sum(min(up,down)-1)
        up = 1
        down = 0
    pre = x

if pre==">":
    ans += sum(max(up,down)) + sum(min(up,down)-1)
elif pre=="<":
    ans += sum(up)

print(ans)

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

n = len(S) + 1

a = [0] * n

for i, x in enumerate(S):
    if x == '<':
        a[i+1] = a[i] + 1
    else:
        a[i+1] = 0

for i, x in enumerate(reversed(S)):
    j = n - i - 1
    if x == '>':
        a[j - 1] = max(a[j] + 1, a[j-1])

print(sum(a))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1

def main():
    s = input()
    if s[0] == "<":
        a = 1
        cnt_greater = 0
    else:
        a = 0
        cnt_greater = 1
    ans = 1
    for c0, c1 in zip(s, s[1:]):
        if c0 == ">" and c1 == "<":
            if a > 0:
                ans -= a * cnt_greater
            else:
                ans -= a * (cnt_greater + 1)
            a = 1
            cnt_greater = 0
        else:
            if c1 == "<":
                a += 1
            else:
                a -= 1
                cnt_greater += 1
        ans += a
    if a > 0:
        ans -= a * cnt_greater
    else:
        ans -= a * (cnt_greater + 1)
    print(ans)

main()

Solution (Python):
s = input()
if s[-1] =='<':
  s = s+'>' 
if s[0] =='>':
  s = '<'+s 
n = len(s)+1

def rui(n):
  return n*(n+1)//2
  
tani = []
yama = []
tani.append(0)

for i in range(n-1):
  if s[i:i+2] =='><':
    tani.append(i+1)
  elif s[i:i+2] =='<>':
    yama.append(i+1)
    
tani.append(n-1)

count = 0
for i in range(len(yama)):
  d1 = yama[i] - tani[i]
  d2 = tani[i+1] - yama[i]
  count += rui(max(d1,d2)) + rui(min(d1,d2)-1)
  
print(count)

Solution (Python):
S = str(input())

ans = 0

left_count = 0
right_count = 0

for i in range(len(S)):
  if S[i] == "<":
    left_count += 1
  elif S[i] == ">":
    right_count += 1
  if i != len(S)-1:
    if S[i] == ">" and S[i+1] == "<":
      ans += (left_count * (left_count -1))//2 + (right_count * (right_count -1))//2 + max(left_count , right_count)
      left_count = 0
      right_count = 0
  else:
    ans += (left_count * (left_count -1))//2 + (right_count * (right_count -1))//2 + max(left_count,right_count)

print(ans)

Solution (Python):
s = input()

valley, apex, wave, ans = 0, 0, 0, 0
prev = None
END = 'e'
for i, c in enumerate(s + END):
    if (prev==None)&(c=='>') | (prev=='<')&(c==END) | (prev=='<')&(c=='>'):
        apex = i
        ans += (apex-valley-1)*(apex-valley)//2 
        if c == END:
            ans += wave
    if (prev==None)&(c=='<') | (prev=='>')&(c==END) | (prev=='>')&(c=='<'):
        valley = i
        apex_wave = wave + valley - apex
        if wave < 0:
            ans += (valley-apex)*(valley-apex+1)//2   
        else:
            ans += (valley-apex-1)*(valley-apex)//2 + apex_wave  
        wave = 0

    prev = c
    if c == '<':
        wave += 1
    elif c == '>':
        wave -= 1

print(ans)

Solution (Python):
s=input()
from itertools import*
g=[[k,len(list(v))] for k,v in groupby(s)]
ans=0
for i,j in g:
    ans+=j*(j+1)//2
for i in range(len(g)-1):
    if g[i][0]=="<":
        ans-=min(g[i][1],g[i+1][1])
print(ans)

Solution (Python):

from collections import defaultdict

INF = float("inf")

def getlist():
	return list(map(int, input().split()))


def main():
	S = list(input())
	N = len(S) + 1
	L = [INF] * N
	for i in range(N - 2):
		if S[i] == ">" and S[i + 1] == "<":
			L[i + 1] = 0
	if S[0] == "<":
		L[0] = 0
	if S[-1] == ">":
		L[-1] = 0

	for i in range(N - 1):
		if S[i] == "<" and L[i] != INF:
			L[i + 1] = L[i] + 1
	for i in range(N - 1):
		if S[-1 - i] == ">" and L[-1 - i] != INF:
			if L[-2 - i] == INF:
				L[-2 - i] = L[-1 - i] + 1
			else:
				L[-2 - i] = max(L[-1 - i] + 1, L[-2 - i])
	print(sum(L))

if __name__ == '__main__':
	main()

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

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

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


memo = ""


cnt = 0


before_cnt = 0


ans = 0


for x in s:
    
    if memo == "":
        memo = x
    
    
    if memo == x:
        cnt += 1
        
    
    else:
        
        ans += cnt * (cnt+1) // 2
        
        if memo == ">":
            if before_cnt < cnt:
                ans -= before_cnt
            else:
                ans -= cnt
        before_cnt = cnt
        cnt = 1
        memo = x
else:
    ans += cnt * (cnt+1) // 2
    if before_cnt < cnt:
        if memo == ">":
            ans -= before_cnt
    else:
        if memo == ">":
            ans -= cnt
    before_cnt = cnt
    cnt = 0
 
print(ans)

Solution (Python):

s = input()
n = len(s)

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

Solution (Python):
def binSearch(N, A, key):
    left = 0
    right = N - 1
    memo = [-1 for _ in range(N)]
    k = (left + right) // 2
    while True:
        if memo[k] == -1:
            memo[k] = 1 if key(A[k]) else 0
        if memo[k] == 1:
            right = k
        else:
            left = k
        _k = (left + right) // 2
        if _k == k:
            if memo[left] == -1:
                memo[left] = key(A[left])
            if memo[right] == -1:
                memo[right] = key(A[right])
            if memo[right] == 0 or memo[left] == 1:
                return -1
            else:
                return right
        else:
            k = _k


def trisum(n):
    return n * (n + 1) // 2


def calc(S):
    t = []
    b = 0
    i = S.find('><', b)
    result = 0
    while i != -1:
        if i - b == 0:
            result += 0
        elif i - b == 1:
            result += 1
        else:
            t += [S[b:i + 1]]
        b = i + 1
        i = S.find('><', b)
    t += [S[b:]]
    for u in t:
        nu = len(u)
        l = binSearch(nu, u, lambda c: c == '>')
        if l != -1:
            result += trisum(max(l, nu - l)) + trisum(min(l, nu - l) - 1)
        else:
            result += trisum(nu)
    return result


S = input()
print(calc(S))

Solution (Python):
s=input()
n=len(s)+1
ans=[0]
p=s[::-1]
cnt=0
for i in range(n-1):
	if s[-i-1]==">":
		cnt+=1
	else:
		cnt=0
	ans.append(cnt)
ansk=[]
for i in range(n):
	ansk.append(ans[-i-1])
import copy
kari=copy.copy(ansk)
cnt=0
for i in range(n-1):
	if kari[i]==kari[i+1]==0:
		cnt+=1
		ansk[i+1]=cnt
	else:
		if kari[i]==0:
			if ansk[i+1]<=ansk[i]:
				ansk[i+1]=ansk[i]+1
		cnt=0
print(sum(ansk))

Solution (Python):
S = input()

ans = 0  
a = 0   
d = 0   
p = '_'  

for i in range(len(S)):
    if p == '>' and S[i] == '<':
        if a > 0:
            ans -= a*d
        elif a < 0:
            ans += -a*(d+1)
        a = 1
    elif S[i] == '<':
        a += 1
    elif p == '<' and S[i] == '>':
        a -= 1
        d = 1
    elif S[i] == '>':
        a -= 1
        d += 1
    ans += a
    p = S[i]
    

if S[-1] == '>':
    if a > 0:
        ans -= a*d
    elif a < 0:
        ans += -a*(d+1)


print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
s = list(input())
del s[-1] 
dainalist = [0]*(len(s)+1)
syounalist = [0]*(len(s)+1)

for i in range(len(s)):
  if s[i] == "<":
    dainalist[i+1] = dainalist[i] + 1
for i in range(len(s)-1,-1,-1):
  if s[i] == ">":
    syounalist[i] = syounalist[i+1] + 1
ans = 0
for i in range(len(dainalist)):
  ans += max(dainalist[i],syounalist[i])
 
print(ans)

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

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

Solution (Python):
from sys import stdin

S = stdin.readline().rstrip()

ans = [-1] * (len(S) + 1)
for i in range(len(S)):
    if i == 0 and S[i] == '<':
        ans[i] = 0
    if i > 0 and S[i - 1] == '>' and S[i] == '<':
        ans[i] = 0
if S[-1] == '>':
    ans[len(S)] = 0

for i in range(len(S) + 1):
    if ans[i] == 0:
        cnt = 0
        while i + cnt <= len(S) - 1 and S[i + cnt] == '<' and ans[i + cnt + 1] != 0:
            ans[i + cnt + 1] = max(ans[i + cnt + 1], ans[i + cnt] + 1)
            
            cnt += 1
        cnt = 0
        while i + cnt >= 0 and S[i + cnt - 1] == '>' and ans[i + cnt - 1] != 0:
            ans[i + cnt - 1] = max(ans[i + cnt - 1], ans[i + cnt] + 1)
            
            cnt -= 1


print(sum(ans))

Solution (Python):
def main():
    S = list(input())
    N = len(S) + 1
    a = [-1] * N
    for i in range(N):
        if a[i] == -1:
            calc(i, S, a)

    print(sum(a))

def calc(i, S, a):
    if i == 0:
        if S[i] == '<':
            a[i] = 0
        else:
            j = 0
            while j < len(S) and S[j] == '>':
                j += 1
            for k in range(j):
                a[k] = j - k
    elif i == len(S):
        if S[i - 1] == '>':
            a[i] = 0
        else:
            a[i] = a[i - 1] + 1
    else:
        if S[i - 1] == '<' and S[i] == '<':
            a[i] = a[i - 1] + 1
        elif S[i - 1] == '<' and S[i] == '>':
            j = 0
            while (i + j) < len(S) and S[i + j] == '>':
                j += 1
            for l in range(j):
                a[i + l] = j - l
            a[i] = max(a[i - 1] + 1, j)
        elif S[i - 1] == '>' and S[i] == '<':
            a[i] = 0
        elif S[i - 1] == '>' and S[i] == '>':
            a[i] = a[i - 1] - 1

main()

Solution (Python):
S = input()
SS = []

S += 'a'
p = S[0]
c = 1
for i in range(1,len(S)):
  if S[i] != p:
    SS.append([p,c])
    c = 1
  else:
    c += 1
  p = S[i]

a = 0
ans = 0
for s,c in SS:
  if s == '<':
    ans += c*(c+1)//2
    a = c
  else:
    if a < c:
      ans += c-a
    ans += c*(c-1)//2
    a = 0
print(ans)

Solution (Python):
s=input()
s="<"+s+"<"
n=len(s)-1
ans=0
cur=0
temp=0
for i in range(1,n+1):
  if s[i-1]=="<" and s[i]=="<":
    ans+=cur
    cur+=1
  elif s[i-1]=="<" and s[i]==">":
    temp=cur
    cur=1
  elif s[i-1]==">" and s[i]==">":
    cur+=1
  else:
    ans+=cur*(cur+1)//2+max(0,temp-cur)
    cur=1
print(ans)

Solution (Python):
S = list(input())
if S == ['>'] or S == ['<']:
    print(1)
    exit()
l = []
if S[0] == '>':
    l.append(0)
    p = '>'
else:
    p = '<'
c = 1
for i in range(1, len(S)):
    if S[i] == p:
        c += 1
    else:
        l.append(c)
        c = 1
        p = S[i]
if c != 0:
    l.append(c)
if S[-1] == '<':
    l.append(0)
ans = 0


def calc(x):
    return (1 + x) * x // 2


for i in range(0, len(l), 2):
    ans += calc(l[i]) + calc(l[i + 1]) - min(l[i], l[i + 1])
print(ans)

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

for  i in range(n+1):
    ans += box[i]

print(ans)

Solution (Python):
S = input()
N = len(S)+1
A = [0 for i in range(N)]

num = 0
while(num<=N-2):
    i = num
    if(S[i]=="<"):
        A[i+1]=A[i]+1
        num += 1
    else:
        start = i
        j = 0
        while(i+j<len(S) and S[i+j]==">"):
            j += 1
        if(i==0):
            A[i] = j
        else:
            A[i] = max([A[i],j])
            
        
        for j_ in range(j):
            A[i+j_+1] = j-1-j_
        num += j
print(sum(A))

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

left = [0] * N
right = [0] * N


for i in range(N - 1):
    if S[i] == '<':
        left[i + 1] = left[i] + 1


for i in range(N - 2, -1, -1):
    if S[i] == '>':
        right[i] = right[i + 1] + 1




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

print (ans)

Solution (Python):



def main():
    
    s = input()


    
    temp = 1
    li = []
    if s[0]=='>':
        li.append(0)
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            temp += 1
        else:
            li.append(temp)
            temp = 1
    li.append(temp)
    if s[-1]=='<':
        li.append(0)

    
    ans = 0
    temp = 0
    while temp < len(li):
        large = max(li[temp], li[temp+1])
        short = min(li[temp], li[temp+1])
        ans += large*(large+1)//2 + short*(short-1)//2
        temp += 2
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):



def main():
    
    s = input()


    
    temp = 1
    li = []
    if s[0]=='>':
        li.append(0)
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            temp += 1
        else:
            li.append(temp)
            temp = 1
    li.append(temp)
    if s[-1]=='<':
        li.append(0)

    
    ans = 0
    temp = 0
    while temp < len(li):
        large = max(li[temp], li[temp+1])
        short = min(li[temp], li[temp+1])
        ans += large*(large+1)//2 + short*(short-1)//2
        temp += 2
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
S=input()
N = len(S)+1
from_left = [0]*N
from_right = [0]*N

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

for i,s in enumerate(S[::-1]):
    i = N-2-i
    if s == '<':
        from_right[i] = 0
    else:
        from_right[i] = from_right[i+1]+1

seq = [x if x>y else y for x,y in zip(from_left,from_right)]

answer = sum(seq)
print(answer)

Solution (Python):
import re
 
def main():
    S = input()
    N = len(S) + 1
 
    ans = 0
    s_list = re.split("><", S)
    nelem = len(s_list)
    for i in range(nelem):
        elem = s_list[i]
        ln = elem.count(">") + 1
        rn = elem.count("<") + 1
        if i == 0:
            rn -= 1
        if i == nelem - 1:
            ln -= 1
        nmax = max([ln, rn])
        nmin = min([ln, rn])
        ans += (0 + nmax) * (nmax + 1) / 2
        ans += (0 + nmin - 1) * (nmin) / 2
    print(int(ans))
 
if __name__ == '__main__':
    main()

Solution (Python):
import re
 
def main():
    S = input()
    N = len(S) + 1
 
    ans = 0
    s_list = re.split("><", S)
    nelem = len(s_list)
    for i in range(nelem):
        elem = s_list[i]
        ln = elem.count(">") + 1
        rn = elem.count("<") + 1
        if i == 0:
            rn -= 1
        if i == nelem - 1:
            ln -= 1
        nmax = max([ln, rn])
        nmin = min([ln, rn])
        ans += (0 + nmax) * (nmax + 1) / 2
        ans += (0 + nmin - 1) * (nmin) / 2
    print(int(ans))
 
if __name__ == '__main__':
    main()

Solution (Python):
s = input()
n = len(s)+1
st = 1
lst = []
for i in range(n-2):
  if s[i] == s[i+1]:
    st += 1
  else:
    lst.append([s[i],st])
    st = 1
lst.append([s[n-2],st])
m = len(lst)
ans = [0]*n
now = 0
for l in lst:
  if l[0] == '<':
    for i in range(l[1]+1):
      ans[now+i] = max(i,ans[now+i])
  else:
    for i in range(l[1]+1):
      ans[now+i] = max(l[1]-i,ans[now+i])
  now += l[1]
print(sum(ans))

Solution (Python):
s = input()
n = len(s)
if s[0] == '<':
    p = []
    cnt = 1
    for i in range(1,n):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            p.append(cnt)
            cnt = 1
    p.append(cnt)
    res = 0
    if len(p)%2 == 0:
        for i in range(len(p)):
            if i%2 == 0:
                a = p[i]
            else:
                b = p[i]
                if b > a:
                    a,b = b,a
                res += a*(a+1)//2 + b*(b-1)//2
    else:
        for i in range(len(p)-1):
            if i%2 == 0:
                a = p[i]
            else:
                b = p[i]
                if b > a:
                    a,b = b,a
                res += a*(a+1)//2 + b*(b-1)//2
        res += p[-1]*(p[-1]+1)//2
    print(res)
else:
    p = []
    cnt = 1
    for i in range(1,n):
        if s[i] == s[i-1]:
            cnt += 1
        else:
            p.append(cnt)
            cnt = 1
    p.append(cnt)
    q = p[0]
    del p[0]
    res = q*(q+1)//2
    if len(p) == 0:
        res *= 1
    elif len(p)%2 == 0:
        for i in range(len(p)):
            if i%2 == 0:
                a = p[i]
            else:
                b = p[i]
                if b > a:
                    a,b = b,a
                res += a*(a+1)//2 + b*(b-1)//2
    else:
        for i in range(len(p)-1):
            if i%2 == 0:
                a = p[i]
            else:
                b = p[i]
                if b > a:
                    a,b = b,a
                res += a*(a+1)//2 + b*(b-1)//2
        res += p[-1]*(p[-1]+1)//2
    print(res)

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

def main():
    S = input().strip()

    ma = 0
    prev = ""
    a = []
    a.append(0)
    total = 0
    for i, s in enumerate(S):
        if prev == ">" and s == "<":
            if a[i] > 0:
                total -= (ma - a[i]) * a[i]
            elif a[i] < 0:
                total -= (ma - a[i] + 1) * a[i]
            a.append(1)
            ma = 1
        elif s == "<":
            ma += 1
            a.append(a[i] + 1)
        elif s == ">":
            a.append(a[i] - 1)

        prev = s


    if S[-1] == ">":
        if a[-1] > 0:
            total -= (ma - a[-1]) * a[-1]
        elif a[-1] < 0:
            total -= (ma - a[-1] + 1) * a[-1]

    print(total + sum(a))

if __name__ == '__main__':
    main()

Solution (Python):
s = input()
len_s = len(s)
ans_array = [0 for x in range(len_s+1)]
for index in range(len_s):
    if s[index] == "<":
        ans_array[index + 1] = ans_array[index]+1
for index in reversed(range(len_s)):
    if s[index] == ">":
        ans_array[index] = max(ans_array[index+1]+1, ans_array[index])
print(sum(ans_array))

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

for i in range(N - 1):
    if S[i] == '>' and S[i+1] == '<':
        j = 0
        while i - j >= 0 and S[i-j] == '>' and a[i-j] < j + 1:
            a[i-j] = j + 1
            j += 1
        j = 0
        while i + 2 + j < N and S[i+1+j] == '<' and a[i+2+j] < j + 1:
            a[i+2+j] = j + 1
            j += 1
print(sum(a) - a[0] - a[-1])

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

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

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

ans = 0
for i in range(n):
    ans +=max(l[i],r[i])
print(ans)

Solution (Python):
from itertools import*;r=p=0
for k,g in groupby(input()):x=len(list(g));r=r+x*(x+1)//2-min(x,p)*(k=='>');p=x
print(r)

Solution (Python):
from itertools import*
r=p=0
for k,g in groupby(input()):
    x=len(list(g))
    r+=x*(x+1)//2
    r-=min(x,p)*(k=='>')
    p=x
print(r)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
def input():
    return sys.stdin.readline().rstrip()

def main():
    S=list(input())
    pre=0
    ans=0
    m=0
    p=0
    for a in S:
        if a =='<':
            p+=1
            if m != 0:
                ans-=min(pre,m)
                pre=m
                ans+=m*(m+1)//2
                m=0
        elif a=='>':
            m+=1
            if p!=0:
                pre=p
                ans+=p*(p+1)//2
                p=0
    if m != 0:
        ans-=min(pre,m)
        pre=m
        ans+=m*(m+1)//2
        m==0
    elif p!=0:
        pre=p
        ans+=p*(p+1)//2
        p==0
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
S = input()
n = 0
nsl = [0]
for c in S:
  if c == "<":
    n += 1
  else:
    n = 0
  nsl.append(n)
n = 0
nsr = [0]
for c in reversed(S):
  if c == ">":
    n += 1
  else:
    n = 0
  nsr.append(n)
nsr.reverse()


r = 0
for i in range(len(S)+1):
  r += max(nsl[i], nsr[i])
print(r)

Solution (Python):
s=input()
n=len(s)+1
dp=[-1]*n
count=0
for i in range(n-1):
    if s[i]=='>':
        count+=1
    else:
        break
dp[0]=count
buf=dp[0]
for i in range(n-2):
    if s[i]=='>' and s[i+1]=='<':
        dp[i+1]=0
        continue
    if s[i]=='<' and s[i+1]=='<':
        dp[i+1]=dp[i]+1
        continue
    if s[i]=='<' and s[i+1]=='>':
        count=0
        for j in range(i+1,n-1):
            if s[j]=='>':
                count+=1
            else:
                break
        dp[i+1]=max(dp[i]+1,count)
        buf=count
        continue
    if s[i]=='>' and s[i+1]=='>':
        dp[i+1]=buf-1
        buf-=1
        continue
if s[n-2]=='>':
    dp[n-1]=dp[n-2]-1
else:
    dp[n-1]=dp[n-2]+1
print(sum(dp))

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

def check_list(li):
    count_big = 0
    count_small = 0
    for i in li:
        if i == '>':
            count_small += 1
        elif i == '<':
            count_big += 1
    a = list(range(max(count_small, count_big)+1))
    b = list(range(min(count_small, count_big)))
    return sum(a) + sum(b)

point_list = []
count = 0
for i in range(len(n)-1):
    if n[i] == '>' and n[i+1] == '<':
        point_list.append(i)

if point_list == []:
    print(check_list(n))
    exit()

point_list.insert(0,0)
point_list.insert(len(n), len(n)-1)

for i in range(len(point_list)-1):
    if i == 0:
        a = n[:point_list[i+1]+1]
    else:
        a = n[point_list[i]+1:point_list[i+1]+1]
    b = check_list(a)
    count += b

print(count)

Solution (Python):
import sys
input = sys.stdin.readline
s=input().rstrip()
ls=len(s)
L=[0]*(ls+1)

pre,n='<',0
for i,c in enumerate(s):
    if c=='<':
        if pre == '<':
            n+=1
            L[i+1]=n
        else:
            n=1
            L[i+1]=1
            pre='<'
    else:
        pre='>'

pre,n='>',0
for i,c in enumerate(s[::-1]):
    if c=='>':
        if pre == '>':
            n+=1
            L[ls-1-i]=max(n,L[ls-1-i])
        else:
            n=1
            L[ls-1-i]=max(n,L[ls-1-i])
            pre='>'
    else:
        pre='<'
print(sum(L))

Solution (Python):
def perm_cul(N):
    return N * (N + 1) // 2
S = input()
N = len(S)
cnt_list = []
cnt = 1
ans = 0
if N == 1:
    print(1)
    exit()
for i in range(N-1):
    if S[i] == S[i+1]:
        cnt += 1
    elif S[i] != S[i+1]:
        cnt_list.append(cnt)
        cnt = 1
    if i == N-2:
        cnt_list.append(cnt)

if S[0] == '<' and S[N-1] == '<':
    for i in range(len(cnt_list) - 1):
        ans += perm_cul(cnt_list[i]-1)
        if i % 2 == 1:
            ans += max(cnt_list[i-1], cnt_list[i])
    ans += perm_cul(cnt_list[len(cnt_list) - 1])

elif S[0] == '<' and S[N-1] == '>':
    for i in range(len(cnt_list)):
        ans += perm_cul(cnt_list[i]-1)
        if i % 2 == 1:
            ans += max(cnt_list[i-1], cnt_list[i])

elif S[0] == '>' and S[N-1] == '>':
    ans += perm_cul(cnt_list[0])
    for i in range(1, len(cnt_list)):
        ans += perm_cul(cnt_list[i] - 1)
        if i % 2 == 0:
            ans += max(cnt_list[i-1], cnt_list[i])

else:
    ans += perm_cul(cnt_list[0])
    for i in range(1, len(cnt_list) - 1):
        ans += perm_cul(cnt_list[i]-1)
        if i % 2 == 0:
            ans += max(cnt_list[i-1], cnt_list[i])
    ans += perm_cul(cnt_list[len(cnt_list) - 1])

print(ans)

Solution (Python):
import itertools
import math

S= input()
sg = [[s, len(list(g))] for s ,g in itertools.groupby(S)]
a= [0]* (len(S)+1)
ans =0

if sg[0][0]=='>':
    ans += (sg[0][1] + 1 ) * sg[0][1] //2

if sg[-1][0]=='<':
    ans += (sg[-1][1] + 1 ) * sg[-1][1] //2

for i in range(len(sg)-1):
    if sg[i][0]=='<' and sg[i+1][0]=='>':
        maxsg =max(sg[i][1] , sg[i+1][1])
        ans += (maxsg + 1 ) * maxsg //2
        minsg = min(sg[i][1] , sg[i+1][1])-1
        ans += ( minsg + 1 ) * minsg //2

print(ans)

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

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

count = 0
for i, s in enumerate(S):
    if s == '>':
        count = 0
    else:
        count += 1
        A[i+1] = count

count = 0
for i in range(l-1, -1, -1):
    s = S[i]
    if s == '<':
        count = 0
    else:
        count += 1
        A[i] = max(A[i], count)

print(sum(A))

Solution (Python):
from itertools import groupby
ans = premax = 0
for k, g in groupby(input()):
    for c, _ in enumerate(g, 1):
      ans += c
    if k == '>':
        ans -= min(c, premax)
    premax = c
print(ans)

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

S = input().strip()
N = len(S) + 1
incre = [0] * N
decre = [0] * N
sum_a = 0

t = 0
for i, s in enumerate(S):
    if s == '<':
        t += 1
        incre[i + 1] = t
    else:
        t = 0

t = 0
for i, s in enumerate(S[::-1]):
    if s == '>':
        t += 1
        decre[-(i + 2)] = t
    else:
        t = 0

for i, (inc, dec) in enumerate(zip(incre, decre)):
    if inc < dec:
        incre[i] = dec

print(sum(incre))

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)):
    if S[i:i+2] == "><":
        a[i + 1] = 0

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

for i in reversed(range(len(S))):
    if S[i] == ">" and a[i + 1] >= 0:
        a[i] = max(a[i], a[i + 1] + 1)

print(sum(a))

Solution (Python):
S=input()

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

if S[0]=="<":
    x[0]=0

if S[-1]==">":
    x[-1]=0


for i in range(len(S)):
    if S[i]=="<":
        if x[i]>=0:
            x[i+1]=x[i]+1
        
    
for i in reversed(range(len(S))):
    if S[i]==">" and x[i+1]>=0:
        x[i]=max(x[i+1]+1,x[i])

        
print(sum(x))