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()
ans = 0

big = [0]*(len(S)+1)
for i in range(len(S)):
  if S[i] == "<":
    big[i+1] = big[i] +1
  else:
    big[i+1] = 0
  
small = [0]*(len(S)+1)
for i in range(len(S)-1, -1, -1):
  if S[i] == ">":
    small[i] = small[i+1] + 1
  else:
    small[i] = 0
    
for b, s in zip(big, small):
  ans += max(b, s)

print(ans)

Submission status: Accepted

Solution code:
import re
s = input()
ss = re.findall(r">+|<+",s,re.S)
count = 0
num = 0
if re.findall(">",ss[0],re.S):
    count += sum(range(len(ss[0])+1))
    del ss[0]
if ss and re.findall("<",ss[-1],re.S):
    count += sum(range(len(ss[-1])+1))
    del ss[-1]
for i in range(len(ss)-1):
    if num == 0:
        num = max(len(ss[i]),len(ss[i+1]))
        count += sum(range(max(len(ss[i]),len(ss[i+1]))+1))
        count += sum(range(min(len(ss[i]),len(ss[i+1]))))
    else:
        num = 0
print(count)

Submission status: Accepted

Solution code:
*s, = input()

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

greater = [0]*(len(s)+1)
for i in range(len(s)-1, -1, -1):
    if  s[i] == ">":
        greater[i] = greater[i+1] + 1

ans = 0
for _l, _g in zip(less, greater):
    ans += max(_l, _g)

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
S = stdin.readline().rstrip()
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 = []
for ll, rr in zip(l, r):
    ans.append(max(ll, rr))
print(sum(ans))

Submission status: Accepted

Solution code:
from itertools import groupby
S = input()
if S[0] == ">":
    S = "<"+S
if S[-1] == "<":
    S += ">"

ans = 0
pair = [(s, len(list(l))) for s, l in groupby(S)]
for p, q in zip(pair[:-1:2], pair[1::2]):
    a, b = min(p[1], q[1]), max(p[1], q[1])
    ans += (a-1)*a//2
    ans += (b+1)*b//2

print(ans)

Submission status: Accepted

Solution code:
s = input()
for_l = [0] * (len(s) + 1)
for_r = [0] * (len(s) + 1)
l = [0] * (len(s) + 1)
for i in range(1, len(for_l)):
    if s[i - 1] == "<":
        for_l[i] = for_l[i - 1] + 1
for i in range(1, len(for_l)):
    if s[-i] == ">":
        for_r[-i-1] = for_r[-i] + 1
for i in range(len(for_l)):
    l[i] = max(for_l[i], for_r[i])
print(sum(l))

Submission status: Accepted

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

la = 0
ra = 0
ans = 0

for i in range(N-1):
    if S[i] == "<":
        la += 1
    else:
        ra += 1

    if S[i] == ">" and S[i+1] == "<":
        m = min(la,ra) - 1
        M = max(la,ra)
        ans += M*(M+1)//2 + m*(m+1)//2
        la = 0 
        ra = 0

if S[-1] == "<":
        la += 1
else:
    ra += 1

m = min(la,ra) - 1
M = max(la,ra)
ans += M*(M+1)//2 + m*(m+1)//2

print(ans)

Submission status: Accepted

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

a=[0]*(n+1)
for i in range(n):
    if s[i]=="<":
        a[i+1]=max(1+a[i],a[i+1])

s.reverse()
a.reverse()
for i in range(n):
    if s[i]==">":
        a[i+1]=max(1+a[i],a[i+1])
s.reverse()
a.reverse()
print(sum(a))

Submission status: Accepted

Solution code:
#%%
# 理屈は分かったが書き方がわからなかった...
# 答え: https://www.programming-pack.com/entry/2019/11/04/235625


s = list(input())

# 不等式の向きを記録する
memo = ''

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

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

# 答え
ans = 0

# 文字列Sの連続したふとうしきの向きを数える
for i in s:
    # はじめはmemoが空白なので、memoに不等式の向きを記録
    if memo == '':
        memo = i

    # 不等式の向きが同じ場合は数を1カウントしてループに戻る
    if memo == i:
        cnt += 1

    # 不等式の向きが異なる場合
    else:
        # ansに和を加算する
        ans += cnt * (cnt + 1) // 2

        # 不等式の向きの変化が処理が必要な場合
        if memo == '>':
            if before_cnt < cnt:
                ans -= before_cnt
            else:
                ans -= cnt

        before_cnt = cnt
        cnt = 1
        memo = i
else:
    ans += cnt * (cnt + 1) // 2
    if before_cnt < cnt:
        if memo == '>':
            ans -= before_cnt
    else:
        if memo == '>':
            ans -= cnt
    before_cnt = cnt
    cnt = 0

print(ans)

Submission status: Accepted

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

s = input()[:-1]

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

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

for i in range(len(a)):
    a[i] = max(l[i], r[i])

print(sum(a))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

s = input()[:-1]

cnts = []

tmp = 1
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        tmp += 1
    else:
        if s[i] == '>':
            tmp *= -1
        cnts.append(tmp)
        tmp = 1

if s[-1] == '>':
    tmp *= -1
cnts.append(tmp)

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

for i in range(len(cnts)):
    if i != 0 and cnts[i-1] > 0 and cnts[i] < 0 and a[idx-1] >=  abs(cnts[i]):
        a[idx] = a[idx-1] + 1

    for j in range(abs(cnts[i])):
        if a[idx] != 0:
            idx += 1
            continue
        if cnts[i] > 0:
            a[idx] = j
        else:
            a[idx] = abs(cnts[i]) - j
        idx += 1
if s[-1] == '<':
    a[-1] = a[-2] + 1

# print(*cnts)
# print(*a)
print(sum(a))
# for i in range(len(s)):
#     print(a[i],s[i],end='')
# print(a[-1])

Submission status: Accepted

Solution code:
s=str(input())
sl=len(s)+1
l,r=[0]*sl,[0]*sl
ss=[0]*sl
lcnt,rcnt=0,0
for i in range(sl):
  if i==0:
    l[0]=0
    r[sl-1]=0
  else:
    if s[i-1]=="<":
      lcnt+=1
    else:
      lcnt=0
    if s[sl-i-1]==">":
      rcnt+=1
    else:
      rcnt=0
    l[i]=lcnt
    r[sl-i-1]=rcnt
for i in range(sl):
  ss[i]=max(l[i],r[i])
print(sum(ss))

Submission status: Accepted

Solution code:
def left(arr, idx):
    if L[idx] != None:
        return L[idx]

    if arr[idx] == '<':
        if idx == 0:
            ret = 1
        else:
            ret = left(arr, idx-1) + 1
    else:
        ret = 0

    L[idx] = ret
    return ret
        
def right(arr, idx):
    if R[idx] != None:
        return R[idx]

    if arr[idx] == '>':    
        if idx == len(arr)-1:
            ret =  1
        else:
            ret = right(arr, idx+1) + 1
    else:
        ret = 0
    R[idx] = ret
    return ret

def main():
    S = list(input())
    N = len(S)
    A = [0 for _ in range(N+1)]
    
    global L; L = [None for _ in range(N)]
    global R; R = [None for _ in range(N)]

    for i in range(N):
        j = N - i - 1
        L[i] = left(S, i)
        R[j] = right(S, j)
    
    L = [0] + L
    R = R + [0]

    for i in range(len(A)):
        A[i] = max(L[i], R[i])
            
    print(sum(A))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S = list(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[-i - 1] == ">" and l[-i - 2] <= l[-i -1]:
    l[-i -2] = l[-i - 1] + 1
print(sum(l))

Submission status: Accepted

Solution code:
S = input()

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

blocks = []
if len(chasms) == 0:
    blocks.append(S)
else:
    blocks.append(S[:chasms[0]])
    for i in range(len(chasms) - 1):
        blocks.append(S[chasms[i]:chasms[i + 1]])
    blocks.append(S[chasms[-1]:])

answer = 0
for i in blocks:
    a = i.count("<")
    b = i.count(">")
    if a >= b:
        n = a
        m = b - 1
    else:
        n = b
        m = a - 1
    answer += n * (n + 1) // 2
    answer += m * (m + 1) // 2

print(answer)

Submission status: Accepted

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

N = len(S)
ls = [[],[0]]
for i in range(N-1):
    if S[i] == '<' and S[i+1] == '>':
        ls[0].append(i+1)
    if S[i] == '>' and S[i+1] == '<':
        ls[1].append(i+1)
ls[1].append(N)
M = len(ls[0])
ans = 0
for i in range(M):
    s,t = max(ls[0][i]-ls[1][i], ls[1][i+1]-ls[0][i]),min(ls[0][i]-ls[1][i], ls[1][i+1]-ls[0][i])
    ans += s*(s+1) //2 + (t-1)*(t) //2

print(ans)

Submission status: Accepted

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

i=1
while i<=N:
    if S[i-1]==">" and S[i]=="<":
        a[i]=0

        j=i
        while j>=1:
            if S[j-1]==">":
                if a[j-1]<=a[j]:
                    a[j-1]=a[j]+1
                j=j-1
            else:
                break

        k=i
        while k<=N:
            if S[k]=="<":
                if a[k+1]<=a[k]:
                    a[k+1]=a[k]+1
                k=k+1
            else:
                break
    i=i+1

a[0]=0
a[N+1]=0
print(sum(a))

Submission status: Accepted

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

for n in range(0, len(s), 1):
    if '<' == s[n] and list[n] >= list[n + 1]:
        list[n + 1] += list[n] - list[n + 1] + 1

for n in range(len(s) - 1, -1, -1):
    if '>' == s[n] and list[n] <= list[n + 1]:
        list[n] += list[n + 1] - list[n] + 1

print(sum(list))

Submission status: Accepted

Solution code:
s = input()
buf = 0
str_len = len(s)
total = 0

while buf < str_len:
    l_count = 0
    r_count = 0

    while buf < str_len and s[buf] == "<":
        l_count += 1
        buf += 1

    while buf < str_len and s[buf] == ">":
        r_count += 1
        buf += 1

    f = lambda x : x * ( x + 1 ) // 2
    n = max(l_count, r_count)
    total += f(n)
    m = min(l_count, r_count) - 1
    total += f(m)

print(total)

Submission status: Accepted

Solution code:
s = input()

res = 0
i = 0
while (i < len(s)):
    a, b = 0, 0
    while (i < len(s) and s[i] == '<'):
        i += 1
        a += 1
    while (i < len(s) and s[i] == '>'):
        i += 1
        b += 1
    c = min(a, b)
    d = max(a, b)
    res += (c * (c - 1)) // 2
    res += (d * (d + 1)) // 2

print(res)

Submission status: Accepted

Solution code:
S = input()
snum = len(S)
N = snum +1
Nar = [0 for i in range(N)]

for i in range(snum):
    if S[i] == '<':
        Nar[i+1] = Nar[i] + 1

for i in reversed(range(N-1)):
    if S[i] == '>':
        Nar[i] = max(Nar[i],Nar[i+1]+1)
sum = 0
for i in Nar:
    sum += i
print(sum)

Submission status: Accepted

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

i=1
while i<=N:
    if S[i-1]==">" and S[i]=="<":
        a[i]=0

        j=i
        while j>=1:
            if S[j-1]==">":
                if a[j-1]<=a[j]:
                    a[j-1]=a[j]+1
                j=j-1
            else:
                break
        k=i
        while k<=N:
            if S[k]=="<":
                if a[k+1]<=a[k]:
                    a[k+1]=a[k]+1
                k=k+1
            else:
                break
    i=i+1

a[0]=0
a[N+1]=0
print(sum(a))

Submission status: Accepted

Solution code:
S = input()

p = 0
l = []
for s in S:
    if s == '<':
        if p <= 0:
            p -= 1
        else:
            l.append(p)
            p = -1
    else:
        if p >= 0:
            p += 1
        else:
            l.append(p)
            p = 1
l.append(p)

n = len(l)
ans = 0

for ll in l:
    if ll < 0:
        ll *= -1
    for i in range(ll):
        ans += i


for i in range(n - 1):
    if l[i] < 0:
        ans += max(-l[i], l[i +1])

if l[0] > 0:
    ans += l[0]
if l[-1] < 0:
    ans -= l[-1]
# print(l)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# Atcoder necoak answer
# https://atcoder.jp/contests/agc040/tasks/agc040_a

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

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(a)
print(sum(a))

Submission status: Accepted

Solution code:
str = input()
cntl = []
cnt = 1
for i in range(len(str)-1):
    if str[i] == str[i+1]:
        cnt += 1
    else:
        cntl.append(cnt)
        cnt = 1
else:
    cntl.append(cnt)
s = 0
for i in range(len(cntl)):
    s += cntl[i]*(cntl[i]+1)//2
r = 0
if str[0] == "<":
    for i in range(len(cntl)//2):
        r += min(cntl[2*i],cntl[2*i+1])
if str[0] == ">":
    for i in range(1,(len(cntl)+1)//2):
        r += min(cntl[2*i-1],cntl[2*i])
print(s-r)

Submission status: Accepted

Solution code:
s = input()

total = 0
tmp_current = 0
tmp_high = float('inf')
count_from_high = 1
flag_current = False # '<':True, '>':False
for c in s:
    if c == '<':
        if not flag_current:
            count_from_high = 0
        total += tmp_current+1
        tmp_current += 1
        flag_current = True
    else:
        if flag_current:
            tmp_high = tmp_current
            flag_current = False
        else:
            if tmp_high > count_from_high:
                total += count_from_high
            else:
                total += count_from_high + 1
        tmp_current = 0
        count_from_high += 1
print(total)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


S = readline().rstrip().decode('utf-8')

N = len(S)+1

from_left = [0]*N
from_right = [0]*N

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

answer = sum(seq)
print(answer)

Submission status: Accepted

Solution code:
s=input()
#<<>>><>>

g=[0 for i in range(len(s)+1)]
l=[0 for i in range(len(s)+1)]

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

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

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

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)+1
a=[0]*n
b=[0]*n
for i in range(n-1):
    if s[i]=='<':
        a[i+1]=a[i]+1
    if s[-i-1]=='>':
        b[i+1]=b[i]+1

print(sum([max(i,j) for i,j in zip(a,b[::-1])]))

Submission status: Accepted

Solution code:

S  = raw_input()
SS = ">"+S+"<"
N = len(SS) - 1
A = [None for i in xrange(N)]

for i in xrange(N):
    if (SS[i] == ">" and SS[i+1] == "<"):
        A[i] = 0
        j = 0
        while (i-j-1)>=0 and SS[i-j] == ">":
            if A[i-j-1] == None:
                A[i-j-1] = j+1
            else:
                Max = max(A[i-j-1], j+1)
                A[i-j-1] = Max
            j += 1
        j = 0
        while (i+j+1)<N and SS[i+j+1] == "<":
            if A[i+j+1] == None:
                A[i+j+1] = j+1
            else:
                Max = max(A[i+j+1], j+1)
                A[i+j+1] = Max
            j += 1

print sum(A)

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    s = str(readline().rstrip().decode('utf-8'))
    s = s.replace("><", ">_<").split("_")
    cnt = 0
    for sv in s:
        r = l = 0
        for i in range(len(sv)):
            if sv[i] == ">":
                r += 1
            else:
                l += 1
        cnt += r * (0 + r-1) // 2 + l * (0 + l-1) // 2 + max(r, l)
    print(cnt)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from collections import deque

S = list(input())
sign = deque()
times = deque()

# 1からnumberまでの総和
def total(number):
    answer = (number*(number+1))//2
    return answer


# 記号が何回続くか求める O(N)
sign.append(S[0])
count = 1
for i in range(1,len(S)):
    if S[i] == S[i-1]:
        count += 1
    else:
        times.append(count)
        sign.append(S[i])
        count = 1
times.append(count)

sign = list(sign)
times = list(times)

answer = 0
for i in range(len(sign)):
    if i == 0 and sign[i] == ">":
        answer += total(times[i])
        continue
    if i == len(sign)-1 and sign[i] == "<":
        answer += total(times[i])
        continue
    if sign[i] == "<":
        answer += total(max(times[i],times[i+1]))
        answer += total(min(times[i],times[i+1])-1)

print(answer)

Submission status: Accepted

Solution code:
def solve(s):
    n = len(s)
    l = [0] * (n+1)
    r = [0] * (n+1)
    for i in range(n):
        l[i+1] = l[i]
        if s[i] == ">":
            l[i+1] = 0
        else:
            l[i+1] += int(s[i] == "<")
    for i in range(n-1, -1, -1):
        r[i] = r[i+1]
        if s[i] == "<":
            r[i] = 0
        else:
            r[i] += int(s[i] == ">")
    return sum([max(l[i], r[i]) for i in range(n+1)])

s = input()
print(solve(s))

Submission status: Accepted

Solution code:
S = input()
list = [100 for i in range(len(S))]
list.append(100)
cnt = 0
min = 0
if S[0] == "<":
	cnt = 1
	list[0] = 0
if S[-1] == ">":
	list[len(S)] = 0
for i in range(len(S)-1):
	if S[i] == ">" and S[i+1] == "<":
		list[i+1] = 0
		cnt = 1
for i in range(len(S)):
	if S[i] == "<":
		if list[i] == 0:
			cnt = 1
		list[i+1] = cnt
		cnt += 1
#print("lsit",list)

for i in range(len(S)-1):
	if S[len(S) - i - 1] == ">" and S[len(S) - i - 2] == "<":
		list[len(S) - i-1] = max(list[len(S) - i-1],list[len(S) - i]+1)
	elif S[len(S) - i - 1] == ">":
		list[len(S) - i-1] = list[len(S) - i]+1		
if S[0] == ">":
	list[0] = list[1] + 1
#print(list)
print(sum(list))

Submission status: Accepted

Solution code:
s=input()

list=[0 for _ in range(len(s) + 1)]

for n in range(0, len(s), 1):
    if '<' == s[n] and list[n] >= list[n + 1]:
        list[n + 1] += list[n] - list[n + 1] + 1

for n in range(len(s) - 1, -1, -1):
    if '>' == s[n] and list[n] <= list[n + 1]:
        list[n] += list[n + 1] - list[n] + 1

print(sum(list))

Submission status: Accepted

Solution code:
s = input()
buf = 0
str_len = len(s)
total = 0

while buf < str_len:
    l_count = 0
    r_count = 0

    while buf < str_len and s[buf] == "<":
        l_count += 1
        buf += 1

    while buf < str_len and s[buf] == ">":
        r_count += 1
        buf += 1

    f = lambda x : x * ( x + 1 ) // 2
    n = max(l_count, r_count)
    total += f(n)
    m = min(l_count, r_count) - 1
    total += f(m)

print(total)

Submission status: Accepted

Solution code:
s=input()

list=[0 for _ in range(len(s) + 1)]

def inc(n):
    if n < 0 or len(s) < n + 1:
        return
    if '<' == s[n]:
        if list[n] >= list[n + 1]:
            list[n + 1] += list[n] - list[n + 1] + 1
    elif '>' == s[n]:
        if list[n] <= list[n + 1]:
            list[n] += list[n + 1] - list[n] + 1

for i in range(0, len(s), 1):
    inc(i)

for i in range(len(s) - 1, -1, -1):
    inc(i)

print(sum(list))

Submission status: Accepted

Solution code:
def main():
  s = input().rstrip('\n')
  n = len(s)
  dp = [0] * (1 + n)
  for i,c in enumerate(s):
    if c == '<':
      dp[i+1] = dp[i] + 1
  for i in range(n-1, -1, -1):
    if s[i] == '>':
      dp[i] = max(dp[i], dp[i+1] + 1)
  return sum(dp)

print(main())

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:
s = input()
buf = 0
str_len = len(s)
total = 0

while buf < str_len:
    l_count = 0
    r_count = 0

    while buf < str_len and s[buf] == "<":
        l_count += 1
        buf += 1

    while buf < str_len and s[buf] == ">":
        r_count += 1
        buf += 1

    n = max(l_count, r_count)
    total += n * ( n + 1 ) // 2
    m = min(l_count, r_count) - 1
    total += m * ( m + 1 ) // 2

print(total)

Submission status: Accepted

Solution code:
s = input()                                                                                                                                                                                                                                                                                      
buf = 0                                                                                                                                                                                                                                                                                          
str_len = len(s)                                                                                                                                                                                                                                                                                 
total = 0                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                 
while buf < str_len:                                                                                                                                                                                                                                                                             
    l_count = 0                                                                                                                                                                                                                                                                                  
    r_count = 0                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                 
    while buf < str_len and s[buf] == "<":                                                                                                                                                                                                                                                       
        l_count += 1                                                                                                                                                                                                                                                                             
        buf += 1                                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                 
    while buf < str_len and s[buf] == ">":                                                                                                                                                                                                                                                       
        r_count += 1                                                                                                                                                                                                                                                                             
        buf += 1                                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                 
    n = max(l_count, r_count)                                                                                                                                                                                                                                                                    
    total += n * ( n + 1 ) // 2                                                                                                                                                                                                                                                                  
    m = min(l_count, r_count) - 1                                                                                                                                                                                                                                                                
    total += m * ( m + 1 ) // 2                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                 
print(total)

Submission status: Accepted

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

a=[0]
temp=0
f=0
mx_idx=0

for i in range(1,N):
    if S[i-1]=="<":
        if f>=0:
            a.append(a[i-1]+1)
            temp+=1
            f=1
        else:
            if temp>0:
                for j in range(mx_idx+1,i):
                    a[j]-=temp
            elif temp<0:
                for j in range(mx_idx,i):
                    a[j]-=temp
            a.append(1)
            temp=1
            f=1
    else:
        if f<=0:
            a.append(a[i-1]-1)
            temp-=1
            f=-1
        else: 
            a.append(a[i-1]-1)
            temp-=1
            mx_idx=i-1
            f=-1

if temp<0:
    for j in range(mx_idx, N):
        a[j] -= temp
print(sum(a))

Submission status: Accepted

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

# 文字列の入力
S = input()

list = []
list.append(0)

for i in range(len(S)) :
  if S[i] == "<" :
    list.append(list[i] + 1)
  else :
    list.append(0)

#print(list)
for j in reversed(range(len(list))) :
  if j != len(list)-1 :
    if S[j] == ">" :
      val = list[j+1] + 1
      if list[j] < val :
        list[j] = val

sum = 0      
for k in range(len(list)) :
  sum += list[k]

#print(list)
print (sum)

Submission status: Accepted

Solution code:
S = input()
ans = [0]*(len(S) + 1)
temp = 0
for i, s in enumerate(S):
    if s == '<':
        ans[i+1] = ans[i] + 1
for i, s in reversed(list(enumerate(S))):
    if s == '>' :
        ans[i] = max(ans[i+1] + 1, ans[i])
print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
l_1 = [0]
l_2 = [0]
for i in range(len(S)):
  if S[i] == '<':
    l_1.append(l_1[i] + 1)
  else:
    l_1.append(0)
for i in range(len(S)):
  if  S[len(S)-i-1] == '>':
    l_2.append(l_2[i] + 1)
  else:
    l_2.append(0)
l_2.reverse()
l_3 = []
for i in range(len(S)+1):
  l_3.append(max(l_1[i], l_2[i]))
print(sum(l_3))

Submission status: Accepted

Solution code:
import numpy as np


def foo(x, y):
    return y * (y + 1) // 2 + x * (x - 1) // 2

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

s = [S[0]]
n = [0]
for si in S:
    if si == s[-1]:
        n[-1] += 1
    else:
        s.append(si)
        n.append(1)

n1, n2 = np.sort(np.array(n).reshape((-1, 2)), axis=-1).T
print(np.sum(foo(n1, n2)))

Submission status: Accepted

Solution code:
import sys
data = sys.stdin.readline().replace('\n', '')

indexes = []
def csum(a):
    return (a + 1) * a / 2
prev = 0
for element in range(1, len(data)):
    if data[element - 1] == '>' and data[element] == '<':
        indexes.append((prev, element - 1))
        prev = element
indexes.append((prev, len(data) - 1))
ans = 0
for x, y in indexes:
    fnd = False
    len = y - x + 1
    for i in range(x, y):
        if data[i] == '<' and data[i + 1] == '>':
            a = i - x + 1
            b = y - i
            if a > b:
                ans += csum(a)
                ans += csum(b - 1)
            else:
                ans += csum(b)
                ans += csum(a - 1)

            fnd = True
            break
    if not fnd:
        ans += csum(len)
print ans

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:i+1] == "<":
        ans[i+1] = max(ans[i],ans[i]+1)
for i in range(len(s)):
    if s[len(s)-i-1:len(s)-i] == ">":
        ans[len(s)-i-1] = max(ans[len(s)-i-1],ans[len(s)-i]+1)
print(sum(ans))

Submission status: Accepted

Solution code:
def main():
    s = input().rstrip("\n")
    import re
    parts = re.findall("((>*)(<*))", s)
    total = 0
    whole, left, right = parts[0]
    left_len = len(left)
    left_sum = (left_len * (left_len + 1)) // 2
    right_len = len(right)
    right_sum = (right_len * (right_len - 1)) // 2
    total = left_sum + right_sum
    for whole, left, right in parts[1:-1]:
        left_len = len(left)
        left_sum = (left_len * (left_len - 1)) // 2
        total += left_sum + max(left_len, right_len)
        right_len = len(right)
        right_sum = (right_len * (right_len - 1)) // 2
        total += right_sum
    total += right_len

    print(total)
if __name__ == "__main__":
    main()