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:
S = input()
st_list =  []

for i in range(len(S)+1):
    if i==0:
        if S[i] == '<':
            st_list.append(i)
    elif i == (len(S)):
        if S[i-1] == '>':
            st_list.append(i)
    else:
        if (S[i-1] == '>') & (S[i] == '<'):
            st_list.append(i)
ans = [0] * (len(S)+1)
for i in st_list:
    j = i +1
    if j > (len(S)):
        pass
    else:
        while S[j-1] == '<':
            ans[j] = ans[j-1]+1
            j += 1
            if j > (len(S)):
                break

for i in st_list:
    j = i -1

    if j < 0:
        pass
    else:
        while S[j] == '>':
            ans[j] = max(ans[j+1]+1,ans[j])
            j -= 1
            if j < 0:
                break

print(sum(ans))

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]=max(ans[i+1],ans[i]+1)

for i in reversed(range(n)):
    if s[i]=='>':
        ans[i]=max(ans[i],ans[i+1]+1)
print(sum(ans))
#rangeの挙動に注意しよう

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]=max(ans[i+1],ans[i]+1)

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

Submission status: Accepted

Solution code:
a = [0]
n = 0

def main():
    global n
    for s in input():
        if s == "<":
            nproc()
            a.append(a[-1]+1)
        else:
            n += 1
    nproc()
    print(sum(a))

def nproc():
    global n, a
    if n > 0 and n > a[-1]:
        a[-1] = n
    for i in list(range(n))[::-1]:
        a.append(i)
    n = 0

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
n = len(s)
t = [0]*(n+1)
tmp=0
for i in range(n):
  tmp+=1
  if s[i]=="<":
    t[i]=tmp-1
    t[i+1]=tmp
  else:
    tmp=0
    
tmp=0
for j in range(n)[::-1]:
  tmp+=1
  if s[j]==">":
    t[j+1]=max(tmp-1,t[j+1])
    t[j]=max(tmp,t[j])
  else:
    tmp=0
#print(t)
print(sum(t))

Submission status: Accepted

Solution code:
def run_length(data, init=''):
    length = []
    tmp = init
    cnt = 0
    for c in data:
        if tmp != c:
            length.append(cnt)
            cnt = 0
        tmp = c
        cnt += 1
    length.append(cnt)
    return length


def resolve():
    s = input()
    if s[0] != '<':
        s = '<' + s
    if s[-1] != '>':
        s = s + '>'

    array = run_length(s)
    ans = 0
    for i in range(1, len(array), 2):
        a,b = array[i], array[i+1]
        mn = min(a,b) - 1
        mx = max(a,b)
        ans += (mn+1) * (mn) // 2 + mx * (mx+1) // 2
    #     print(a,b, (mn+1) * (mn) // 2 + mx * (mx+1) // 2)
    # print(array)
    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
s=input()

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

prev=0
for i in range(len(s)):
    if s[i]=='<':
        a[i+1]=a[i]+1

for j in range(len(s)-1,-1,-1):
    if s[j]=='>':
        if a[j]>a[j+1]+1:
            continue
        else:
            a[j]=a[j+1]+1

print(sum(a))

Submission status: Accepted

Solution code:
import sys
import math
import itertools as it
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    s = S()
    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 = open(0).read()

a = [0]
streak = 0
# mx = 0
for c in s:
    if c == '<':
        streak += 1
#         mx = max(mx, streak)
    else:
        streak = 0
    a.append(streak)
#     a.append(mx)

b = [0]
streak = 0
# mx = 0
for c in s[::-1]:
    if c == '>':
        streak += 1
#         mx = max(mx, streak)
    else:
        streak = 0
#     b.append(mx)
    b.append(streak)
b = b[::-1]

print(sum([max(x, y)for x, y in zip(a, b)]))

Submission status: Accepted

Solution code:
s = input()

cnt = 0
ans = 0
tmp = 0
check = 0
for x in s:
    cnt += 1
    if x == '<':
        if check != cnt - 1:
            ans -= tmp * (cnt - check - 1)
            tmp = 0
        tmp += 1
        ans += tmp
        check = cnt
    else:
        tmp -= 1
        ans += tmp
        if tmp < 0:
            ans += (cnt -  check + 1)
            tmp += 1

print(ans)

Submission status: Accepted

Solution code:
S=input()
right=[0]*(len(S)+1)
for i in range(len(S)):
    if S[i]=="<":
        right[i+1]=right[i]+1
left=[0]*(len(S)+1)

for j in range(len(S)-1,-1,-1):
    if S[j]==">":
        left[j]=left[j+1]+1
        
total=0
for k in range(len(S)+1):
    total+=max(right[k],left[k])
print(total)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)
s=input()
#print(s)
l=[-1 for _ in range(len(s)+1)]
def aa(ix,v): #ixはlベース
# print(ix,v,l)
  if (ix>= len(s) and v==1) or (ix==0 and v==0-1):
    return
  if v==1 and s[ix]=="<" and l[ix+1]<=l[ix]:
    l[ix+1]=l[ix]+1
    aa(ix+1,1)
  elif v==-1 and s[ix-1]==">" and l[ix-1]<=l[ix]:
    l[ix-1]=l[ix]+1
    aa(ix-1,-1)
  return

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

print(sum(l))

Submission status: Accepted

Solution code:
S=input()
right=[0]*(len(S)+1)
for i in range(len(S)):
    if S[i]=="<":
        right[i+1]=right[i]+1
left=[0]*(len(S)+1)
for i in range(len(S)-1,-1,-1):
    if S[i]==">":
        left[i]=left[i+1]+1
total=0
for i in range(len(S)+1):
    total+=max(right[i],left[i])
print(total)

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:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=input()
lns=len(s)
lst=[0]*(lns+1)

start=[]
if s[0]=="<":
    start.append(0)
for i in range(lns-1):
    if s[i]==">" and s[i+1]=="<":
        start.append(i+1)
if s[lns-1]==">":
    start.append(lns)

for i in start:
    d=deque([[i,0],[i,1]])
    while d:
        now,lr=d.popleft()
        # print(now)
        if now-1>=0 and lr==0 and s[now-1]==">":
            lst[now-1]=max(lst[now-1],lst[now]+1)
            d.append([now-1,0])
        if now+1<=lns and lr==1 and s[now]=="<":
            lst[now+1]=max(lst[now+1],lst[now]+1)
            d.append([now+1,1])
    # print(lst)
# print(start)
# print(lst)
print(sum(lst))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

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

s = input()
l = []
t = [0,0]
b = s[0]
if b=="<":
	a = 0
else:
	a = 1

i=0
while 1:
	if i>len(s)-1:
		l.append(t)
		break
	else:
		if b==s[i]:
			t[a]+=1
			i+=1
		elif s[i]==">":
			a=1
			b = ">"
		else:
			b = "<"
			a=0
			l.append(t)
			t = [0,0]

#print(l)

ans = 0

for i in l:
	ans += TS(i[0]-1)
	ans += TS(i[1]-1)
	ans += max(i)

print(ans)

Submission status: Accepted

Solution code:
s=list(input())
k=0
bef="x"
n=[]
ans=0
def kai(n):
  if n==0:
    return 0
  ret=0
  for i in range(1,n+1):
    ret+=i
  return ret

for i in s:
  if bef!=i:
    if bef=="x":
      st=i
      bef=i
      k+=1
      continue
    bef=i
    n.append(k)
    k=0
  k+=1
n.append(k)
n.reverse()
if st==">":
  ans+=kai(n.pop())
while len(n)!=0:
  if len(n)==1:
    ans+=kai(n.pop())
  else:
    f=n.pop()
    s=n.pop()
    if f>s:
      ans+=kai(f)+kai(s-1)
    else:
      ans+=kai(f-1)+kai(s)
    #print("{} {}".format(f,s))

print(ans)

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)

print(sum(A))

Submission status: Accepted

Solution code:
s=input()
a,b,c,d=0,0,0,0
for i in range(len(s)):
 if s[i]==">":
  c=0;b+=1
  if b<=d:a+=b-1
  else:a+=b
 else:b=0;c+=1;a+=c;d=c
print(a)

Submission status: Accepted

Solution code:
# 解説動画視聴

s = input()

a = [0]*(len(s)+1)
if len(s) == 1:
    print(1)
    exit()
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:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

S = s()
n = len(S)
num = 1
num2 = 1
ans = 0
Flag = 0

for i in range(n-1):
    if S[i] == S[i+1]:
        ans += num
        num += 1
    if S[i] == "<" and S[i+1] == ">":
        num2 = num
        num = 1
        Flag = 1
    if S[i] == ">" and S[i+1] == "<":
        ans += max(num,num2)
        num = 1
        Flag = 0

if Flag:
    ans += max(num,num2)
else:
    ans += num

print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

S = s()
N = len(S)
num = 1
num2 = 1
ans = 0
Flag = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        ans += num
        num += 1
    if S[i] == '>' and S[i+1] == '<':
        ans += max(num,num2)
        num = 1
        Flag = 0
    if S[i] == '<' and S[i+1] == '>':
        num2 = num
        num = 1
        Flag = 1
if Flag:
    ans += max(num2,num)
else:
    ans += num
print(ans)

Submission status: Accepted

Solution code:
s = input()

cnt = [1] if s[0] == "<" else [0, 1]

bc = s[0]

for i in range(1, len(s)):
    if s[i] == bc:
        cnt[-1] += 1
    else:
        cnt.append(1)
    bc = s[i]

if len(cnt) % 2 == 1:
    cnt.append(0)


ans = 0

for i in range(0, len(cnt), 2):
    ma = max(cnt[i], cnt[i + 1])
    mi = min(cnt[i], cnt[i + 1])
    ans += max(0, ma * (ma + 1) // 2)
    ans += max(0, (mi - 1) * mi // 2)

print(ans)

Submission status: Accepted

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

l = [0] * N
r = [0] * N

tmp_l = 0
# <,>,>の場合、l=[0,1,0,0]となる
for i in range(N - 1):
    if S[i] == "<":

        tmp_l += 1
        l[i + 1] = tmp_l
    else:
        tmp_l = 0

tmp_r = 0
# Sを逆からチェック
#<,>,>の場合、l=[0,2,1,0]となる
for i in range(N - 2, -1, -1):
    if S[i] == ">":
        tmp_r += 1
        r[i] = tmp_r
    else:
        tmp_r = 0

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

print(ans)

Submission status: Accepted

Solution code:
s = str(input())
#s = "<>>><<><<<<<>>><"
ans = 0
def leftmore(ln):
    ret = [0]
    cur = 0
    for c in ln:
        if c == "<":
            cur += 1
        else:
            cur = 0
        
        ret.append(cur)
    return ret

def rightless(ln):
    revl = reversed(ln)
    ret = [0]
    cur = 0
    for c in revl:
        if c == ">":
            cur += 1
        else:
            cur = 0
        ret.append(cur)
    return list(reversed(ret))

lm = leftmore(s)
rl = rightless(s)
for i in range(len(s)+1):
    ans += max(lm[i],rl[i])
print(ans)

Submission status: Accepted

Solution code:
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10
    tmp = 0
    S = list(input())
    N = len(S)+1
    A = [0]*N
    num_conti = 0
    for i in range(N-1):
        if S[i] == '<':
            num_conti += 1
        else:
            num_conti = 0
        A[i+1] = num_conti
    num_conti = 0
    for i in range(N-2,-1,-1):
        if S[i] == '>':
            num_conti += 1
        else:
            num_conti = 0
        A[i] = max(A[i],num_conti)
    print(sum(A))
    dbg(A)





    
main()

Submission status: Accepted

Solution code:
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10
    tmp = 0
    S = input()
    min_num = 0
    tmp_sum = 0
    diffs = deque()
    prev = ''
    ans = down = up = 0
    for i,c in enumerate(S):
        # dbg(i,ans)
        if c == '<':
            #trough
            if prev == '>':
                ans += down*(down-1)//2
                ans += max(down,up)
                down = up = 0
            ans += up
            up += 1
        
        else:
            down += 1

        prev = c

    #trough
    if S[-1] == '>':
        ans += down*(down-1)//2
        ans += max(down,up)
    if S[-1] == '<':
        ans += up

    print(ans)



    
main()

Submission status: Accepted

Solution code:
S=list(input())

s=0
f=0
g=0
h=0
for i in range(len(S)):
    if S[i]==">":
        g=0
        f+=1
        if h>=f:
            s+=f-1
        else:
            s+=f
        
    else:
        f=0
        g+=1
        s+=g
        h=g

print(s)

Submission status: Accepted

Solution code:
S = input()

def count_ll(l):

    ret = [0]
    cur = 0

    for c in l:
        if c == "<":
            cur += 1
        else:
            cur = 0
        
        ret.append(cur)
    
    return ret

def count_rg(l):

    revl = reversed(l)
    ret = [0]
    cur = 0

    for c in revl:
        if c == ">":
            cur += 1
        else:
            cur = 0
        
        ret.append(cur)
    
    return list(reversed(ret))

l = count_ll(S)
r = count_rg(S)
# print("left: >", l)
# print("right: <", r)

N = len(S) + 1

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

print(ans)

Submission status: Accepted

Solution code:
s=input()
ans=0
c=1#連続数
temp=0
for i in range(len(s)):
    if i==0:
        ans+=1
    else:
        if s[i]==">" and s[i]==s[i-1]:
            c+=1
            if temp>=c:
                ans+=c-1
            else:
                ans+=c
        elif s[i]==">" and s[i]!=s[i-1]:
            temp=c
            c=1
        elif s[i]=="<" and s[i]==s[i-1]:
            c+=1
            ans+=c
        elif s[i]=="<" and s[i]!=s[i-1]:
            c=1
            tmp=0
            ans+=1
    #print(ans)
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    s = list(input()[:-1].decode())
    n = len(s) + 1
    arr = [0] * n
    for i in range(n - 1):
        if s[i] == '<':
            arr[i + 1] = arr[i] + 1
        else:
            arr[i + 1] = 0
    for i in reversed(range(n - 1)):
        if s[i] == '>':
            arr[i] = max(arr[i], arr[i + 1] + 1)

    print(sum(arr))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

Solution code:
S=input()
N=len(S)

count=[0]*(N+1)
i=0
while i<N:
    if S[i]=='<':
        count[i+1]=count[i]+1
    i+=1

S=S[::-1]
count=count[::-1]
i=0
while i<N:
    if S[i]=='>':
        count[i+1]=max(count[i+1],count[i]+1)
    i+=1

print(sum(count))

Submission status: Accepted

Solution code:
Slist=input()
Slist=Slist.replace("><",">,<").split(",")
ans=0
for S in Slist:
    a=S.count("<")
    b=S.count(">")
    n=max(a,b)
    m=len(S)-n
    ans=ans+n*(n+1)//2+(m-1)*m//2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

S = input()
N = len(S) + 1

l = [0]*N
r = [0]*N

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

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

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

S = input()
N = len(S) + 1

l = [0]*N
r = [0]*N

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

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

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

#print(l)
#print(r)
#print(t)

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    S = input()
    n = len(S)+1
    left=[0]*n
    right=[0]*n
    for i,s in enumerate(S):
        if s=='<':
            left[i+1]=left[i]+1
    for i,s in enumerate(S[::-1]):
        if s=='>':
            right[n-i-2]=right[n-i-1]+1
    ret =0
    for i in range(n):
        ret+= max(left[i],right[i])
    print(ret)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

S = input()
N = len(S)+1

ans = [-1]*(N)

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

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

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

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

#print(ans)

for i in range(N-2, -1, -1):
	if S[i] == ">" and ans[i+1] != -1 and ans[i+1]+1 > ans[i] and ans[i] != 0:
		ans[i] = ans[i+1] + 1

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

Submission status: Accepted

Solution code:
def main():
    S = input()
    A = [ 0 for i in range(len(S) + 1)]

    idx_list = list([0])
    part = list()

    for i in range(len(S) - 1):
        if S[i] == ">" and S[i+1] == "<":
            idx_list.append(i+1)

    idx_list.append(len(S))

    if len(idx_list) == 1:
        part.append(S)
    else:
        for i in range(len(idx_list) - 1):
            part.append(S[idx_list[i]:idx_list[i+1]])

    ans = 0
    for p in part:
        G, L = 0, 0

        for j in range(len(p)):
            if p[j] == "<":
                G += 1
            else:
                L += 1

        tmp = 0
        if G < L:
            tmp += L*(L+1)//2 + G*(G-1)//2
        elif G > L:
            tmp += G*(G+1)//2 + L*(L-1)//2
        else:
            tmp += G*(G+1)//2 + L*(L-1)//2

        ans += tmp
        
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = input()

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

res = 0
for a, b in zip(x, y):
    res += max(a, b)

print(res)

Submission status: Accepted

Solution code:
#from statistics import median
import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
#from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())

S = input()
ln = len(S)
ans = [0] * (ln+1)
# 前から
for i in range(ln):
    if S[i] == '<':
        ans[i+1] = max(ans[i+1],ans[i]+1)
#print(ans)
# 後ろから
for i in range(ln-1,-1,-1):
    if S[i] == '>':
        ans[i] = max(ans[i],ans[i+1]+1)
#print(ans)
print(sum(ans))

Submission status: Accepted

Solution code:
s=input()
n=len(s)
if s[0]=="<":
    nari=0
    scnt,dcnt=0,1
else:
    nari=1
    scnt,dcnt=1,0
ans=0
sfla,dfla=0,0
for i in range(n):
    if nari==0:
        if s[i]=="<":
            scnt+=1
        elif s[i]==">":
            ans+=scnt*(scnt-1)//2
            sfla=scnt
            nari=1
            scnt=1
            dlas=0

    elif nari==1:
        if s[i]==">":
            dcnt+=1
        elif s[i]=="<":
            ans+=dcnt*(dcnt-1)//2
            dfla=dcnt
            nari=0
            dcnt=1
            dlas=1
            ans+=(max(dfla,sfla))
    # print(ans)
if dcnt!=1:
    ans+=dcnt*(dcnt+1)//2
elif scnt!=1:
    ans+=scnt*(scnt+1)//2
else: ans+=1
print(ans)

Submission status: Accepted

Solution code:
s = str(input())
di = []
k = 1
p = 0
for i in range(1,len(s)):
    if s[i-1] != s[i]:
        di.append(k)
        k = 1
        continue
    k += 1
di.append(k)
t = 1
p = 0
for l in range(1,len(s)):
    if s[l-1] == "<" and s[l] == ">":
        p += min(di[t-1],di[t])
        t += 1
    if s[l-1] == ">" and s[l] == "<":
        t += 1
ls = [e for e in range(max(di)+1)]
import numpy 
new_ls = numpy.cumsum(numpy.array(ls))
q = 0
for j in di:
    q += new_ls[j]
print(q-p)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[86]:


# ans = [0]*(len(S)+1)
# for i in range(len(S)):
#     count_left = 0
#     count_right = 0
#     for j in range(i):
#         if S[i-j-1] == "<":
#             count_left += 1
#         else:
#             j -= 1
#             break
#     for k in range(i,len(S)):
#         if S[k] == ">":
#             count_right += 1
#         else:
#             k -= 1
#             break
#     ans[i] = max(count_left, count_right)
# #     print(count_left, count_right)
# #     print(S[i-j-1:i], S[i:k+1])
# # print(ans)
# print(sum(ans))


# In[87]:


from collections import deque
S = input()
left = deque([0])
right = deque([0])
cnt = 0
for s in S:
    if s == '<':
        cnt += 1
    else:
        cnt = 0
    left.append(cnt)
cnt = 0
for s in S[::-1]:
    if s == '>':
        cnt += 1
    else:
        cnt = 0
    right.appendleft(cnt)
ans = 0
for l, r in zip(left, right):
    ans += max(l, r)
print(ans)


# In[ ]:

Submission status: Accepted

Solution code:
s = input()
n = len(s)
ans = 0
l = 0
ll = [0] * (n + 1)
r = 0
rl = [0] * (n + 1)
for i in range(n):
    if s[i] == '<':
        l += 1
        ll[i+1] = l
    else:
        l = 0
    if s[n-1-i] == '>':
        r += 1
        rl[n-i-1] = r
    else:
        r = 0
for i in range(n + 1):
    ans += max(rl[i], ll[i])
print(ans)

Submission status: Accepted

Solution code:
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
a = [0]*n
for i in range(n):
    a[i] = max(left[i], right[i])
ans = sum(a)
print(ans)

Submission status: Accepted

Solution code:
def mi():
    return map(int, input().split())

def main():
    S = input()
    N = len(S)+1
    l = [0]*N
    r = [0]*N
    ans = 0

    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

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
s = input()
l = len(s)

a1 = [0]*(l+1)
a2 = [0]*(l+1)

for i in range(l):
	if s[i] == "<":
		a1[i+1] = a1[i] + 1
	else:
		a1[i+1] = 0

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

cnt = 0
for i in range(l+1):
	cnt += max(a1[i],a2[-i-1])

print(cnt)

Submission status: Accepted

Solution code:
from itertools import groupby
s=input()
if s[0]=='>':
  s='<'+s
g=groupby(s)
a=[]
for i,j in g:
  a.append(len(list(j)))
def sum(n):
  return n*(n+1)//2
x=0
if len(a)%2==1:
  a+=[1]
for i in range(0,len(a),2):
  x+=sum(min(a[i],a[i+1])-1)
  x+=sum(max(a[i],a[i+1]))
print(x)

Submission status: Accepted

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

S = ('<' if S[0] == '>' else '>') + S \
    + ('<' if S[-1] == '>' else '>') # 最初と最後にダミー追加、長さn+1
    
for i in range(n):
    if S[i : i + 2] == '><': # 極小値
        for j in range(i, 0, -1):   # 左に辿る
            if S[j] == '<': break
            a[j - 1] = max(a[j - 1], a[j] + 1)
        for j in range(i + 1, n):   # 右に辿る
            if S[j] == '>': break
            a[j] = max(a[j], a[j - 1] + 1)

print(sum(a))

Submission status: Accepted

Solution code:
s = input()
n = len(s)
a = [0]*(n+1)
yama = []
tani = []

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

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

ans = sum(a)
print(ans)

Submission status: Accepted

Solution code:
s = input()
n = len(s) + 1
s = '<' + s + '>'

unfixed = set()
a = [0 for i in range(n+2)]
a[0] = -1
a[-1] = -1

for i in range(n+2):
    if i == 0 or i == n + 1 or s[i-1:i+1] == '><':
        j = i-1
        while 1 <= j <= n:
            if s[j-1:j+1] == '>>':
                a[j] = a[j+1] + 1
                j -= 1
            else:
                unfixed.add(j)
                break
        j = i + 1
        while 1 <= j <= n:
            if s[j-1:j+1] == '<<':
                a[j] = a[j-1] + 1
                j += 1
            else:
                unfixed.add(j)
                break

for j in unfixed:
    a[j] = max(a[j-1], a[j+1]) + 1

print(sum(a[1:-1]))

Submission status: Accepted

Solution code:
s = input()
n = len(s) + 1
dp = [0] * n
for i, c in enumerate(s):
  if c == '<':
    dp[i+1] = dp[i] + 1

for i, c in enumerate(reversed(s)):
  if c == '>':
    dp[-i-2] = max(dp[-i-2], dp[-i-1] + 1)

print(sum(dp))