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()
l = [0] * (len(s)+1)

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

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

print(sum(l))

Submission status: Accepted

Solution code:
s = input()

left, right = [0],[0]
tmp=0
for itr,eq in enumerate(s):
    if eq == "<":
        tmp+=1
    else:
        tmp = 0
    left.append(tmp)
tmp = 0
for itr in range(len(s)):
    if s[len(s)-itr -1] == ">":
        tmp+=1
    else:
        tmp =0
    right.append(tmp)
right.reverse()

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

print(ans)

Submission status: Accepted

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

# sample1: <>> 3
# sample2: <>>><<><<<<<>>>< 28

s=input()
n=len(s)

a=[0]
tmp=0
for i in range(n):
    if s[i]=='<':
        tmp+=1
    else:
        tmp=0
    a.append(tmp)

arev=[0]
for i in range(n):
    if s[n-i-1]=='>':
        tmp+=1
    else:
        tmp=0
    arev.append(tmp)
arev.reverse()

ans=0
for i in range(n+1):
    ans+=max(a[i], arev[i])

print(ans)

Submission status: Accepted

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

for i in range(N-2,-1,-1):
    if S[i] == ">":
        ary[i] = max(ary[i], ary[i+1] + 1)

print(sum(ary))

Submission status: Accepted

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

 
for i in range(len(S)):
    if S[len(S)-i-1] == ">":
        ans[len(S)-i-1] = max(ans[len(S)-i-1], ans[len(S)-i]+1)
 
print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc040/tasks/agc040_a
s = input()
A = [0] * (len(s) + 1)
B = [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]:
    if s[i] == '>':
        B[i] = B[i + 1] + 1

ans = 0
for i in range(len(s) + 1):
    ans += max(A[i], B[i])
print(ans)

Submission status: Accepted

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

for i in range(len(S)):
    if S[i] == ">":
        a[i+1] = a[i] - 1
    elif S[i] == "<":
        a[i+1] = a[i] + 1
    if i > 0:
        if S[i-1] == "<" and S[i] == ">":
            yama = i
        if S[i-1] == ">" and S[i] == "<":
            tani = i
            val = a[tani]
        if a[tani] < 0:
#            print(a)
            for j in range(yama, tani+2):
                a[j] = a[j] - val
#            print(a)
        elif a[tani] > 0:
            for j in range(yama+1, tani+2):
                a[j] = a[j] - val
last = len(a) -1
val = a[last]
if a[last] < 0:
#    print(a)
    for j in range(yama, last+1):
        a[j] = a[j] - val
#    print(a)

#print(a)
print(sum(a))

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
l=[0] #自分より左にある＜の数
r=[0] #自分より右にある＞の数
l_num=0
r_num=0
for i in range(n):
    if s[i]=="<":
        l_num+=1
    else:
        l_num=0
    if s[-(i+1)]==">":
        r_num+=1
    else:
        r_num=0
    l.append(l_num)
    r.append(r_num)
ans=0
for i in range(n+1):
    ans+=max(l[i],r[-(i+1)])
print(ans)

Submission status: Accepted

Solution code:
s_l = list(input())
n = len(s_l)+1
num_l = [0] * n

for i in range(n-1):
    if s_l[i] == '<':
        num_l[i+1] = num_l[i] + 1

for j in range(n-1):
    if s_l[n-2-j] == '>':
        num_l[n-2-j] = max(num_l[n-2-j], num_l[n-2-j+1]+1)

total = 0
for k in num_l:
    total += k

print(total)

Submission status: Accepted

Solution code:
s=list(input())
n=len(s)
#print(s)
num=[]
def search(now,kigo): #自分より右に何回同じ記号が続くか
    global s,n
    count=0
    while s[now]==kigo:
        now+=1
        count+=1
        if now==n:
            break
    return count
where=0
left=0
if s[0]=="<":
    a=search(0,"<")
    nn=0
    for i in range(a):
        num.append(nn)
        if i==a-1:
            break
        nn+=1
    left=nn
else:
    a=search(0,">")
    nn=a
    for i in range(a):
        num.append(nn)
        nn-=1
    left=1
where=a #次調べる場所
while where<=n-1:
    if s[where]=="<":
        a=search(where,"<")
        nn=0
        for i in range(a):
            num.append(nn)
            if i==a-1:
                break
            nn+=1
        left=nn
    else:
        a=search(where,">")
        if left<a:
            nn=a
        else:
            nn=left+1
        num.append(nn)
        nnn=a-1
        for i in range(a-1):
            num.append(nnn)
            nnn-=1
        left=1
    where+=a
    #print(a)
if s[-1]=="<":
    num.append(left+1)
else:
    num.append(left-1)
#print(num)
print(sum(num))

Submission status: Accepted

Solution code:
s = list(input())

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

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

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

print(sum(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
31min 41sec
"""
"""
<がn個連続するとき、0からnまでの自然数を並べればよい。
>がn個連続するとき、nから0までの自然数を並べればよい。
これらのときの和は、n*(n+1)//2。
><と並んだときは、間に0が挟まれるので考えなくいていい。
<>と並んだときは、連続する数が小さいほうから1個取り除くことにする。
"""
def main():
    S = input()
    N = len(S)
    compressed_list = []
    now_direction = S[0]
    now_counter = 0
    for i in range(N):
        if S[i] == now_direction:
            now_counter += 1
        else:
            compressed_list.append([now_direction, now_counter])
            now_direction = S[i]
            now_counter = 1
    compressed_list.append([now_direction, now_counter])
    answer = 0
    for i in range(len(compressed_list)):
        n = compressed_list[i][1]
        if compressed_list[i][0] == "<":
            if i <= len(compressed_list)-2 and \
                compressed_list[i][1] <= compressed_list[i+1][1]:
                n -= 1
        else:
            if i >= 1 and \
                compressed_list[i-1][1] > compressed_list[i][1]:
                n -= 1
        answer += n*(n+1)//2
    print(answer)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    n=len(s)
    A=[0]*(n+1)
    for i in range(n):
        if s[i]=="<":
            A[i+1]=A[i]+1
    for i in range(n):
        if s[n-i-1]==">":
            A[n-i-1]=max(A[n-i-1],A[n-i]+1)
    print(sum(A))

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

ans = [0] * (len(S)+1)

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

for i in range(len(S)):
    if S[len(S)-i-1] == ">":
        ans[len(S)-i-1] = max(ans[len(S)-i-1], ans[len(S)-i]+1)
# print(ans)

print(sum(ans))

Submission status: Accepted

Solution code:
S = input()
nums = [0] * (len(S)+1)
pos = 0
count = 0
pre_count = 0
now = '>'
for (i, s) in enumerate(S):
  if s != now:
    if s == '<':
      nums[pos] = max(pre_count, count)
      while pos != i:
        pos += 1
        count -= 1
        nums[pos] = count
    else:
      pos = i
      pre_count = count+1
      count = 1
    now = s
  else:
    count += 1
    if s == '<':
      nums[i] = count
if now == '<':
  nums[i+1] = count+1

if s == '>':
  nums[pos] = max(pre_count, count)
  while pos != i+1:
    pos += 1
    count -= 1
    nums[pos] = count

print(sum(nums))

Submission status: Accepted

Solution code:
si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
lmii = lambda: list(map(int, input().split()))
smii = lambda: sorted(map(int, input().split()))

# ----------

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

print(sum(a))

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''

    S = input()
    N = len(S)

    a_list = [ 0 for _ in range(N+1)]


    for i in range(N):
        if S[i] == '<':
            a_list[i+1] = a_list[i] + 1
    # print(a_list)
    for i in range(N):
        if S[-1*(i+1)] == '>':
            a_list[-1*(i+2)] = max(a_list[-1*(i+1)] + 1, a_list[-1*(i+2)])

    # print(a_list)
    
    print(sum(a_list))


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = read().rstrip().decode()
cnt = [[0, 0] for i in range(len(s) + 1)]
ans = 0
for i in range(len(s)):
    if s[i] == '<':
        cnt[i + 1][0] += 1
    else:
        cnt[i][1] += 1
for i in range(1, len(s) + 1):
    if cnt[i - 1][1] == 0:
        cnt[i][0] += cnt[i - 1][0]
    if cnt[len(s) - i + 1][0] == 0:
        cnt[len(s) - i][1] += cnt[len(s) - i + 1][1]
for i in range(len(s) + 1):
    ans += max(cnt[i])
print(ans)

Submission status: Accepted

Solution code:
INT_MAX=10**18+7
x=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
###############################################################################
s=input()
prev=0
sum=0
i=0
while(i<len(s)):
    if s[i]=="<":
        count1=0
        while(i<len(s) and s[i]=="<" ):
            count1+=1
            i+=1
        sum=sum+(count1*(2*prev+1+count1))//2
        prev=prev+count1
    else:
        count=0
        while(i<len(s) and s[i]==">"):
            count+=1
            i+=1
        if count>prev:
            sum-=prev
            prev=count
            sum+=((count)*(count+1))//2
            prev=0
        else:
            sum+=(count*(count-1))//2
            prev=0
print(sum)

Submission status: Accepted

Solution code:
S = input()

left_counter = 0
right_counter = 0
before = 0
answer = 0

for i,s in enumerate(S):
    if s == "<":
        left_counter += 1
        if i == len(S)-1:
            answer += ((1+left_counter)*left_counter)/2
            break
    else:
        right_counter += 1
        if i == len(S)-1:
            answer += ((1+max(left_counter, right_counter))*max(left_counter, right_counter))/2
            answer += (min(left_counter, right_counter)*(min(left_counter, right_counter)-1))/2
            break
        elif S[i+1] == "<":
            answer += ((1+max(left_counter, right_counter))*max(left_counter, right_counter))/2
            answer += (min(left_counter, right_counter)*(min(left_counter, right_counter)-1))/2
            left_counter = 0
            right_counter = 0
print(int(answer))

Submission status: Accepted

Solution code:
s = input()
n = len(s) + 1
ans = 0
l = 0
r = 0
if s[0] == ">":
    p = 0
elif s[0] == "<":
    p = 1
for i in range(n-1):
    if p == 0:
        if s[i] == ">":
            l += 1
        elif s[i] == "<":
            p = 1
            ans += l*(l+1)//2
            if l < r:
                ans -= l
            elif l >= r:
                ans -= r 
            l = 0
            r = 1
    elif p == 1:
        if s[i] == "<":
            r += 1
        elif s[i] == ">":
            l += 1
            p = 0
            ans += r*(r+1)//2
if p == 0:
    ans += l*(l+1)//2
    if l < r:
        ans -= l
    elif l >= r:
        ans -= r
elif p == 1:
    ans += r*(r+1)//2
    
print(ans)

Submission status: Accepted

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

for i in range(len(S)):
  if S[i]=='<':
    res[i+1]=res[i]+1
for i in range(len(S)-1,-1,-1):
  if S[i]=='>':
    res[i]=max(res[i],res[i+1]+1)

print(sum(res))

Submission status: Accepted

Solution code:
S = input()

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

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

print(sum(A))

Submission status: Accepted

Solution code:
s =input()
n = len(s)
a = [0]*(n+1)
res = 0
hidari = [0] *(n+1)
for i in range(1,n+1):
    if s[i-1] == '<':
        res +=1
    else:res = 0
    hidari[i] = res
hidari[-1] = res
res = 0
migi = [0] *(n+1)
for i in range(n-1,-1,-1):
    if s[i] == '>':
        res+=1
    else:res = 0
    migi[i] = res
migi[0] = res
ans = 0
for i in range(n+1):
    ans += max(migi[i],hidari[i])
print(ans)

Submission status: Accepted

Solution code:
s=input()
a=[0]*(len(s)+1)
r=0
l=0
for i in range(len(a)):
  j=i
  if r==0:
    while j < len(s) and s[j] == '>':
      r+=1
      j+=1
  else:
    r-=1
  if i !=0 and s[i-1] == '<':
    l+=1
  else:
    l=0
  a[i]=max(l,r)
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 j in range(len(s)-1,-1,-1):
    if s[j] == '>':
        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)
for i in range(n):
    if(S[i]=='<'):
        A[i+1]=A[i]+1
for i in reversed(range(n)):
    if(S[i]=='>'):
        A[i]=max(A[i],A[i+1]+1)
print(sum(A))

Submission status: Accepted

Solution code:
s=input()
flag=2
cnt=0
p=[]

for i in range(len(s)):
  if s[i]==">":
    if flag==0 or flag==2:
      cnt+=1
    elif flag==1:
      p.append(cnt)
      cnt=1
    flag=0
  
  elif s[i]=="<":
    if flag==1 or flag==2:
      cnt+=1
    elif flag==0:
      p.append(cnt)
      cnt=1
    flag=1
p.append(len(s)-sum(p))
n=len(p)
ans=0

if n%2==0 and s[0]=="<":
  for i in range(0,n,2):
    x=max(p[i],p[i+1])
    y=min(p[i],p[i+1])
    ans+=(x*(x+1)//2)+(y*(y-1)//2)

if n%2==0 and s[0]==">":
  ans+=p[0]*(p[0]+1)//2+p[n-1]*(p[n-1]+1)//2
  for i in range(1,n-1,2):
    x=max(p[i],p[i+1])
    y=min(p[i],p[i+1])
    ans+=(x*(x+1)//2)+(y*(y-1)//2) 

if n%2==1 and s[0]=="<":
  ans+=p[n-1]*(p[n-1]+1)//2
  for i in range(0,n-1,2):
    x=max(p[i],p[i+1])
    y=min(p[i],p[i+1])
    ans+=(x*(x+1)//2)+(y*(y-1)//2)
    
if n%2==1 and s[0]==">":
  ans+=p[0]*(p[0]+1)//2
  for i in range(1,n,2):
    x=max(p[i],p[i+1])
    y=min(p[i],p[i+1])
    ans+=(x*(x+1)//2)+(y*(y-1)//2)

print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

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

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

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

print(sum(a))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    s = list(input())
    ans = [0] * (len(s) + 1)
    for i in range(len(s)):
        if s[i] == "<":
            ans[i + 1] += ans[i] + 1
    for i in range(len(s) - 1, -1, -1):
        if s[i] == ">":
            ans[i] = max(ans[i], ans[i + 1] + 1)
    print(sum(ans))

Submission status: Accepted

Solution code:
s = input()
li = list(s)
#new_li = [False for _ in range((len(li)+1))]
#print(new_li) [False, False, False, False]
tmp = [] #<,>
last_str = ''
memo = []
for i,l in enumerate(li):
    if i == 0:
        tmp.append(l)
        last_str = l
        continue
    if l != last_str:
        memo.append(tmp)
        tmp = [l]
        last_str = l
    else:
        tmp.append(l)
if len(tmp)>0:
    memo.append(tmp)
#print(memo) [['<'], ['>', '>']]
all_count = 0
muki = memo[0][0]
last_len = 0
for mi,m in enumerate(memo):
    all_count += (1+len(m))*len(m)//2
    #print(m,all_count,muki,last_len)
    if muki == '<' and m[0] == '>':
        #print(min(last_len,len(m)))
        all_count -= (min(last_len,len(m)))
    muki = m[0]
    last_len = len(m)
print(all_count)

Submission status: Accepted

Solution code:
S = input().replace('><','> <').split()
ans = 0
for s in S:
    up = s.count('<')
    down = len(s)-up
    if up < down:
        up -= 1
        ans += up*(up+1)//2 + down*(down+1)//2
    else:
        down -= 1
        ans += up*(up+1)//2 + down*(down+1)//2        
print(ans)

Submission status: Accepted

Solution code:
S = list(input())

s = 0
cl = 0
cc = S[0]
ccc = 0

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

for i in range(len(S)):
    if S[i] == cc:
        ccc += 1
    else:
        if cc == '<':
            s += kaidan(ccc) + cl * ccc
            cl = ccc
        else:
            s += kaidan(ccc) - min(cl, ccc)
            cl = 0
        cc = S[i]
        ccc = 1

if cc == '<':
    s += kaidan(ccc) + cl * ccc
else:
    s += kaidan(ccc) - cl

print(int(s))

Submission status: Accepted

Solution code:
S = input()
ans = 0
a = []
up = True
count = 0
for i in S:
    if up:
        if i == '>':
            a.append(count)
            count = 1
            up = False
        else:
            count += 1
    else:
        if i == '<':
            a.append(count)
            count = 1
            up = True
        else:
            count += 1
a.append(count)
if len(a)%2 == 1:
    a.append(0)
for i in range(0,len(a),2):
    u,d = max(a[i],a[i+1]), min(a[i],a[i+1])-1
    ans += u*(u+1)//2 + d*(d+1)//2
print(ans)

Submission status: Accepted

Solution code:
S = input()
gt = [0]
for i in range(len(S)):
    if S[i] == '<':
        gt.append(gt[i] + 1)
    else:
        gt.append(0)

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

# print(gt)
# print(lt)
print(sum([max(g, l) for g, l in zip(gt, lt)]))

Submission status: Accepted

Solution code:
def solve():
    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))
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
S = input()

left_count = [0] * (len(S) + 1)
right_count = [0] * (len(S) + 1)

S = "*" + S + "*"
cur_left_count = 0
cur_right_count = 0
for i in range(len(left_count)):
    if S[i] == "<":
        cur_left_count += 1
    else:
        cur_left_count = 0

    if S[-i-1] == ">":
        cur_right_count += 1
    else:
        cur_right_count = 0
    
    left_count[i] = cur_left_count
    right_count[-i-1] = cur_right_count

a =  [max(l, r) for l, r in zip(left_count, right_count)]

print(sum(a))

Submission status: Accepted

Solution code:
S = input()

left_count = [0] * (len(S) + 1)
right_count = [0] * (len(S) + 1)

S = "*" + S + "*"
cur_left_count = 0
cur_right_count = 0
for i in range(len(left_count)):
    if S[i] == "<":
        cur_left_count += 1
    else:
        cur_left_count = 0

    if S[-i-1] == ">":
        cur_right_count += 1
    else:
        cur_right_count = 0
    
    left_count[i] = cur_left_count
    right_count[-i-1] = cur_right_count

a =  [max(l, r) for l, r in zip(left_count, right_count)]

print(sum(a))

Submission status: Accepted

Solution code:
S = str(input())
S += '/'
l = [0]*len(S)

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

print(sum(l))

Submission status: Accepted

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

# 「<」 がここから左に何個連続しているか
small_left=[1 if S[0]=="<" else 0]
# 「>」 がここから右に何個連続しているか
large_right=[1 if S[-1]==">" else 0]

for i in range(1,len(S)):
  if S[i]=="<":
    small_left.append(small_left[-1]+1) 
  else:
    small_left.append(0) 
    
for i in range(len(S)-2,-1,-1):
  if S[i]==">":
    large_right.append(large_right[-1]+1) 
  else:
    large_right.append(0) 
large_right = large_right[::-1]
#print(large_right,small_left)

cnt += large_right[0]
for i in range(1,N-1):
  cnt += max(large_right[i], small_left[i-1])
cnt += small_left[-1]

print(cnt)

Submission status: Accepted

Solution code:
# Problem A - ><

# input
S = input()

# initialization
N = len(S) + 1
num_list = [0]*N
ans = 0

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

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

# output
ans = sum(num_list)
print(ans)

Submission status: Accepted

Solution code:
S = input()

i = 0
h = 0
c = 0

while i < len(S):
  hx = 0
  while i < len(S) and S[i] == '<':
    i += 1
    hx += 1
  c += hx * (hx + 1) // 2
  h = hx
  #
  hx = 0
  while i < len(S) and S[i] == '>':
    i += 1
    hx += 1
  c += hx * (hx + 1) // 2
  c -= h if hx > h else hx
  h = hx

print(c)

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

print(sum(A))

Submission status: Accepted

Solution code:
s = input()
L = [0]*(len(s)+1)
R = [0]*(len(s)+1)

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

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

print(sum(max(x, y) for x, y in zip(L, R)))

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

s = readline().rstrip().decode('utf-8')
n = len(s)
count = 0
lst1 = [0]*(n+1)
lst2 = [0]*(n+1)

for i in range(n):
	if s[i] == "<":
		lst1[i+1] = lst1[i]+1
for i in range(n-1,-1,-1):
	if s[i] == ">":
		lst2[i] = lst2[i+1]+1

ans = 0
for i in range(n+1):
	ans += max(lst1[i],lst2[i])

print(ans)

Submission status: Accepted

Solution code:
s = 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
    if s[~i] == ">":
        r[~(i+1)] = r[~i] + 1
ans = 0
for j in range(n+1):
    ans += max(l[j],r[j])
print(ans)

Submission status: Accepted

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

A = [0] * (N + 1)
now = 0
for i, s in enumerate(S, start=1):
    if s == '<':
        now += 1
    else:
        now = 0
    A[i] = now

B = [0] * (N + 1)
now = 0
for i, s in enumerate(S[::-1], start=1):
    if s == '>':
        now += 1
    else:
        now = 0
    B[i] = now
B = B[::-1]

ans = [10**18] * (N + 1)
for i in range(N + 1):
    ans[i] = max(A[i], B[i])
print(sum(ans))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()


def resolve():
    S = list(input())
    ls = len(S)

    rr = [0] * (ls + 1)
    ll = [0] * (ls + 1)

    for i in range(ls):
        if S[i] == '<':
            ll[i+1]=ll[i]+1
    for i in reversed(range(ls)):
        if S[i] == '>':
            rr[i]=rr[i+1]+1


    ans = 0
    for i in range(ls + 1):
        ans += max(ll[i], rr[i])
    print(ans)


resolve()

Submission status: Accepted

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

left = [0]*(n+1)
right = [0]*(n+1)

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

answer = 0
for l, r in zip(left, right):
    answer += max(l, r)

print(answer)

Submission status: Accepted

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

l = [0] * n
r = [0] * n

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

for i, c in enumerate(s[::-1]):
    i = n - 2 - i
    if c == '<':
        r[i] = 0
    else:
        r[i] = r[i + 1] + 1

seq = [x if x > y else y for x, y in zip(l, r)]

ans = sum(seq)
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] = a[i] + 1
#print(a)

for j in range(len(S) - 1, -1, -1):
    if S[j] == '>':
        a[j] = max(a[j], a[j + 1] +1)
#print(a)
print(sum(a))

Submission status: Accepted

Solution code:
s = str(input())
n = len(s)
cnt = 0
l = []
for i in range(n):
    l.append(cnt)
    if s[i] == '<':
        cnt += 1
    else:
        cnt = 0
else:
    l.append(cnt)
#print(l)

r = []
cnt = 0
for i in reversed(range(n)):
    r.append(cnt)
    if s[i] == '>':
        cnt += 1
    else:
        cnt = 0
else:
    r.append(cnt)
r.reverse()
#print(r)

A = [0]*len(l)
for i in range(len(A)):
    A[i] = max(l[i], r[i])
print(sum(A))

Submission status: Accepted

Solution code:
s = input()
ans = [0]*(len(s)+1)

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

Submission status: Accepted

Solution code:
S = input()

over_count_in_my_left = [0] * (len(S)+1)
over_count_in_my_right = [0] * (len(S)+1)

over = 0
for idx, s in enumerate(S):
    over_count_in_my_left[idx] = over
    if s == '<':
        over += 1
    else:
        over = 0
over_count_in_my_left[-1] = over

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

ans = 0
for a, b in zip(over_count_in_my_left, over_count_in_my_right):
    ans += max(a, b)

print(ans)

Submission status: Accepted

Solution code:
from itertools import groupby
s=input()
n=len(s)
s=list(s)
gr=groupby(s)
a=[]
for k,g in gr:
    a.append(len(list(g)))

ans=0
nn=len(a)
if s[0]=='<':
    for i in range(nn):
        if i%2==0:
            if i==nn-1:
                if nn%2==1:
                    ans+=a[i]*(a[i]+1)//2
                else:
                    t_max=max(a[i],a[i+1])
                    t_min=min(a[i],a[i+1])
                    t_min-=1
                    ans+=t_max*(t_max+1)//2
                    ans+=t_min*(t_min+1)//2
            else:
                t_max=max(a[i],a[i+1])
                t_min=min(a[i],a[i+1])
                t_min-=1
                ans+=t_max*(t_max+1)//2
                ans+=t_min*(t_min+1)//2                
else:
    for i in range(nn):
        if i==0:
            t_max=a[i]
            ans+=t_max*(t_max+1)//2
            continue
        if i%2==1:
            if i==nn-1:
                if nn%2==0:
                    ans+=a[i]*(a[i]+1)//2
                else:
                    t_max=max(a[i],a[i+1])
                    t_min=min(a[i],a[i+1])
                    t_min-=1
                    ans+=t_max*(t_max+1)//2
                    ans+=t_min*(t_min+1)//2
            else:
                t_max=max(a[i],a[i+1])
                t_min=min(a[i],a[i+1])
                t_min-=1
                ans+=t_max*(t_max+1)//2
                ans+=t_min*(t_min+1)//2 

print(ans)

Submission status: Accepted

Solution code:
S = input()
ls = []
rs = []
if S[0] == '>':
    ls.append(0)
pre = None
seq = 0
for c in S:
    if c == pre:
        seq += 1
    else:
        if pre:
            if pre=='<':
                ls.append(seq)
            else:
                rs.append(seq)
        seq = 1
        pre = c
if pre=='<':
    ls.append(seq)
else:
    rs.append(seq)
if len(ls) > len(rs):
    rs.append(0)

ans = 0
for l,r in zip(ls,rs):
    if l<r: l,r = r,l
    ans += l*(l+1)//2 + r*(r-1)//2
print(ans)

Submission status: Accepted

Solution code:
from itertools import*
s=input()


x=[len(list(v)) for k,v in groupby(s)]

n=len(x)

ans=0
if s[0]==">":
    ans+=(x[0]+1)*x[0]//2
    n-=1
    del x[0]
if s[-1]=="<":
    ans+=(x[-1]+1)*x[-1]//2
    n-=1
for i in range(0,n,2):
    ma=max(x[i],x[i+1])
    mi=min(x[i],x[i+1])
    ans+=ma*(ma+1)//2
    ans+=(mi-1)*mi//2
print(ans)

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    S = input().strip("\n")
    N = len(S)
    A = [0] * (N + 1)
    Start = []
    if S[0] == "<": Start.append(0)
    for i in range(N - 1):
        if S[i] == ">" and S[i+1] == "<": Start.append(i + 1)
    if S[N-1] == ">": Start.append(N)
    for s in Start:
        if s < N:
            for r in range(s, N):
                if S[r] == ">": break
                else: A[r + 1] = max(A[r + 1], A[r] + 1)
    for s in Start:
        if s > 0:
            for r in reversed(range(1, s + 1)):
                if S[r - 1] == "<": break
                else: A[r - 1] = max(A[r - 1], A[r] + 1)
    #print(A)
    print(sum(A))
    #print(Start)

    
    
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def main():
    S = input()
    from itertools import groupby
    ans = 0
    g = [(k, len(list(v))) for k, v in groupby(S)]
    p = 0
    m = 0
    if g[0][0] == '>':
        ans += g[0][1]*(g[0][1]+1)//2
        p += 1
    if g[-1][0] == '<':
        ans += g[-1][1]*(g[-1][1]+1)//2
        m += 1
    for i in range(p, len(g)-m, 2):
        if g[i][1] > g[i+1][1]:
            m = g[i+1][1]
            n = g[i][1]
        else:
            n = g[i+1][1]
            m = g[i][1]
        ans += (m-1)*m//2
        ans += n*(n+1)//2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input()

L = [0]*(len(S)+1)
R = [0]*(len(S)+1)
l = 0
for k in range(len(S)):
    if S[-k-1] == ">":
        l += 1
    else:
        l = 0
    L[-k-2] = l

r = 0
for k in range(len(S)):
    if S[k] == "<":
        r += 1
    else:
        r = 0
    R[k+1] = r

ans = 0
for k in range(len(S)+1):
    ans += max(L[k],R[k])
print(ans)

Submission status: Accepted

Solution code:
S=input()
L,R=[0],[0]
for s in S:
    if s == '<': L.append(L[-1]+1)
    else: L.append(0)
for s in S[::-1]:
    if s == '>': R.append(R[-1]+1)
    else: R.append(0)
ans = 0
for i in range(len(S)+1):
    ans += max(L[i], R[-1-i])
print(ans)

Submission status: Accepted

Solution code:
s = input()
a = [0 for _ in range(len(s)+1)]

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

Submission status: Accepted

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

a_left = [0] * N
a_tmp = 0
for i in range(N - 1):
    if S[i] == '<':
        a_tmp += 1
    else:
        a_tmp = 0
    #
    a_left[i + 1] = a_tmp

a_right = [0] * N
a_tmp = 0
for i in range(N - 1):
    if S[-1 - i] == '>':
        a_tmp += 1
    else:
        a_tmp = 0
    #
    a_right[-2 - i] = a_tmp
        
a_ans = [max(li, ri) for li, ri in zip(a_left, a_right)]

print(sum(a_ans))