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

Submission status: Accepted

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

        ans[i+1]=ans[i]+1
    # print(ans)
# print(ans)
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
    # print(ans)
res = 0
for i in range(n+1):
    res+=ans[i]
# print(ans)
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

#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

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
        #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:
#AGC040
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

#print(L)

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

#print(L)

print(sum(L))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
arr = [0]
for i in range(len(s)):
  if s[i] == '<':
    arr.append(arr[i]+1)
  else:
    arr.append(0)
#print(len(arr))
for i in reversed(range(len(s))):
  if s[i] == '>':
    arr[i] = max(arr[i],arr[i+1]+1)
print(sum(arr))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

#  < > < だと n=2
#  一旦0を全部に入れる
a = [0]*(n+2)

#  左から右に　< だと　a[i+1]はa[i]+1
for i in range(n):
    if s[i] == '<':
        a[i+1] = a[i]+1

#  右から左に > だた a[i]はa[i+1]+1
for i in range(n-1, -1, -1):
    if s[i] == '>':
        a[i] = max(a[i], a[i+1]+1)

print(sum(a))

Submission status: Accepted

Solution code:
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(v)
  print(sum(v))
  
if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    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): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    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]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)):
    #print("count", count, "Scount", S[count], "farstflag", farstflag, "countflag", countflag, "cfalg2", countflag2, "count3", count3, "count4", count4, "ans", anscount)
    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]:
            #print(count2)
            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("count", count, "farstflag", farstflag, "countflag", countflag, "cfalg2", countflag2, "count3", count3, "count4", count4, "ans", anscount)

print(anscount)

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

#a = [-1]*n
localmin = set()
localmax = set()

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

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

for i in range(n-2):
    if s[i]==">" and s[i+1]=="<":
        #a[i+1] = 0
        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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


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

    # See:
    # https://www.youtube.com/watch?v=qIzuNgDV6O8
    # KeyInsight:
    # 不等号を一つずつ扱い，全探索で処理
    # <: a[i + 1] = max(a[i + 1], a[i] + 1)
    # >: a[i - 1] = max(a[i - 1], a[i] + 1)

    # 考察できた部分
    # 0で初期化
    # 愚直にサンプルからシミュレーション

    # 考察できなかった部分
    # 各項の値をどうプログラムで求めるか

    # ギャップ
    # 符号をまとめて処理しようとした
    # 途中で，符号の組み合わせによって，カウントを調整必要があることに気がついたが，法則性が分からず
    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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

#A
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

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#%%
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]
    #print(i, ans)

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

print(ans)

#%%

Submission status: Accepted

Solution code:
s = input()#n-1

n = len(s)+1
a1 =[0]*n#n
a2 =[0]*n#n
a =[0]*n#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))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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))