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



Sample input:
<>>


Sample output:
3

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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):
########################### added
    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]

###########################

    #count '<'
    def count_S(i, N):
#        ret=S.find('>')
        if i >= len(next_S):
            return N
        ret = next_S[i] - i
        if ret < 0:
            ret = N
        return ret
    
    #count '>'
    def count_L(i, N):
#        ret=S.find('<')
        if i >= len(next_L):
            return N
        ret = next_L[i] - i
        if ret < 0:
            ret = N
        return ret


#    #count '<'
#    def count_S(S, N):
#        ret=S.find('>')
#        #print("<",S,N,ret)
#        if ret==-1:
#            ret=N
#        return ret
#    
#    #count '>'
#    def count_L(S, N):
#        ret=S.find('<')
#        if ret==-1:
#            ret=N
#        #print(">",S,N,ret)
#        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(S[i:],len(S[i:]))
#        cnt_l=count_L(S[i+cnt_s:],len(S[i+cnt_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
        #answer+=(cnt_l+1)*cnt_l//2
        #print("cnt_s,cnt_l",cnt_s, cnt_l,answer)
        i+=cnt_s+cnt_l

    print(answer)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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(k)
print(sum(k))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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
#print(L)

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]
#print(R)

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

Submission status: Accepted

Solution code:
# >0<
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足すのが自然
D.append(dwn)
###
for i in range(len(D)):
    ans -= min(U[i],D[i])

#不自然なans-1から戻ったが
#前のとは<<終端に>足した場合は同値
#>>>>終末では
print(ans)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
import math
import numpy as np

# N,K = map(int,input().split())
# A = np.sort(list(map(int,input().split())))
# F = np.sort(list(map(int,input().split())))[::-1]
#         if np.sum(AF[AF>0]) > K: 

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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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 # valley has 0, so add sum(range(valley-apex-1))
        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   # valley has 0, so calculate sum(range(valley-apex))
        else:
            ans += (valley-apex-1)*(valley-apex)//2 + apex_wave  # calculate sum(range(valley-apex-1)) + origin apex value
        wave = 0

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

print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#ライブラリインポート
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()

Submission status: Accepted

Solution code:
S=input();N=len(S)+1 # Sの添字: 0 ~ N-2
r=[-1 for i in range(N)];r[0]=0 # rの添字: 0 ~ N-1 , 初期値r[0]を代入
l=[-1 for i in range(N)];l[N-1]=0 # lの添字: 0 ~ N-1, 初期値l[N-1]を代入
for i in range(N-1): # この計算はN-1回行う。添字iは 0 ~ N-2
    if S[i]=='<':
        r[i+1]=r[i]+1
    else:
        r[i+1]=0
for i in range(N-2,-1,-1): # この計算はN-1回行う。添字iは N-2 ~ 0
    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)

Submission status: Accepted

Solution code:
s = list(input())

#不等号の向きを記録する
memo = ""

#不等号の連続した個数を記録する
cnt = 0

#1つ前に数えた不等号の連続した個数を記録する
before_cnt = 0

#出力する答え
ans = 0

#文字列Sの連続した不等号の向きを数える
for x in s:
    #初めはmemoが空白なので,memoに不等号の向きを記録
    if memo == "":
        memo = x
    
    #不等号の向きが同じ場合は、数を1カウントしてループに戻る
    if memo == x:
        cnt += 1
        
    #不等号の向きが異なる場合
    else:
        #ansに和を加算する
        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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
S = input()

ans = 0  # a1, a2, ... , ai の総和
a = 0   # a[i+1]
d = 0   # <> からの距離
p = '_'  # S[i-1]

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]
    # print(i, S[i], a, d, ans)

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


print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
s = list(input())
del s[-1] #/r消し
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)
            # print(ans)
            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)
            # print(ans)
            cnt -= 1

# print(ans)
print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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]
#print(SS)
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])
            #print(i,A[i],j)
        
        for j_ in range(j):
            A[i+j_+1] = j-1-j_
        num += j
print(sum(A))

Submission status: Accepted

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

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

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

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

# print (left)
# print (right)

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

print (ans)

Submission status: Accepted

Solution code:
# import sys
# input = sys.stdin.readline

def main():
    # input
    s = input()


    # calc
    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
    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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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()
#print(nsl)
#print(nsr)
r = 0
for i in range(len(S)+1):
  r += max(nsl[i], nsr[i])
print(r)