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: Runtime Error

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

S = input()
ret = 0

# 山を下る
i = 0
while S[i] == ">":
    i += 1
    ret += i

# 山を登って降りる
n_up = 0
n_down = 0
while i < len(S):
    n_up = 0
    n_down = 0
    while i < len(S) and S[i] == "<":
        n_up += 1
        i += 1
        if i >= len(S):
            break
    while i < len(S) and S[i] == ">":
        n_down += 1
        i += 1
        if i >= len(S):
            break
    if n_up < n_down:
        n_up, n_down = n_down, n_up

    ret += ((n_up+1) * n_up) // 2
    ret += (n_down * (n_down-1)) // 2
    
print(ret)

Submission status: Runtime Error

Solution code:
s=int(input())

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

for i in range(sl-1):
  if s[i]=="<":
    l[i+1]=l[i]+1
    
for i in range(sl-2,-1,-1):
  if s[i]==">":
    l[i]=max(l[i+1], l[i])
    
print(sum(l))

Submission status: Runtime Error

Solution code:
S=input()
number=0
answer=0
if S[0]=='<' and S[1]=='>':
    pass
elif S[0]=='>' and S[1]=='<':
    answer+=1
else:
    number+=1
    answer+=number
for n in range(1,len(S)-1):
    if S[n]=='<' and S[n+1]=='<':
        number+=1
        answer+=number
    elif S[n]=='>' and S[n+1]=='>':
        number+=1
        answer+=number
    elif S[n]=='<' and S[n+1]=='>':
        number+=1
        answer+=number
        number=0
    else:
        number += 1
        answer += number
        number = 0
if len(S)>=3:
    if S[-1]==S[-2]:
        number+=1
        answer+=number
    elif S[-1]=='<':
        answer+=1
print(answer)

Submission status: Runtime Error

Solution code:
S = input()
A = [0]*(len(S)+1)
for i in range(len(S)+1):
    L = S[:i]
    R = S[i:]
    print('L=', L)
    print('R=', R)
    l = 0
    r = 0
    if L != '':
        T = len(L)
        for k in range(T):
            if L[T-k-1] != '<':
                l = k
                break
        else:
            l = T
    if R != '':
        U = len(R)
        for j in range(U):
            if R[j] != '>':
                r = j
                break
        else:
            r = len(R)
    A[i] = max(l, r)
# print(A)
print(sum(A))

Submission status: Runtime Error

Solution code:
S = list(map(str,input()))
# s = "><<<<><<"
# S = list(map(str,s))
num = [-1]*(len(S)+1)
index0 = list()
than = 0# 0 == >, 1 == <
#----------------------------------------
for i in range(len(S)):
    if(S[i] == '<'):
        if(than == 0):
            num[i] = 0
            index0.append(i)
        than = 1
    else:
        than = 0
if(S[-1] == '>'):
    num[-1] = 0
    index0.append(len(S)+1)
#--------------------------------------
if(index0[0] == 0):
    i = 1
    while(True):
        num[i] = num[i-1]+1
        if(S[i] == '>'):
            break
        i+=1
    index0.pop(0)
if(len(index0)>0):
    if(index0[-1] == len(S)+1):
        i = len(S)-1
        while(True):
            num[i] = num[i+1]+1
            i-=1
            if(i <= 0):break
            if(S[i] == '<'):break
        index0.pop(-1)
while(len(index0)>0):
        for i in reversed(range(0,index0[0])):
            if(S[i] == '<'):
                break
            num[i] = max(num[i],num[i+1]+1)
        for i in range(index0[0]+1,len(S)+1):
            num[i] = max(num[i],num[i-1]+1)
            if(i >= len(S)):break
            if(S[i]== '>'):break
        index0.pop(0)

ans = 0
for i in range(len(num)):
    ans += num[i]
print(ans)

Submission status: Runtime Error

Solution code:
S = list(map(str,input()))
# s = "><<<<><<"
# S = list(map(str,s))
num = [-1]*(len(S)+1)
index0 = list()
than = 0# 0 == >, 1 == <
#----------------------------------------
for i in range(len(S)):
    if(S[i] == '<'):
        if(than == 0):
            num[i] = 0
            index0.append(i)
        than = 1
    else:
        than = 0
if(S[-1] == '>'):
    num[-1] = 0
    index0.append(len(S)+1)
#--------------------------------------
if(index0[0] == 0):
    i = 1
    while(True):
        num[i] = max(num[i],num[i-1]+1)
        if(i >= len(S)):break
        if(S[i] == '>'):break
        i+=1
    index0.pop(0)
# if(len(index0) > 0):
if(index0[-1] == len(S)+1):
    i = len(S)-1
    while(True):
        num[i] = max(num[i],num[i+1]+1)
        i-=1
        if(i <= 0):break
        if(S[i] == '<'):break
    index0.pop(-1)
while(len(index0)>0):
        for i in reversed(range(0,index0[0])):
            if(i <= 0):break
            if(S[i] == '<'):break
            num[i] = max(num[i],num[i+1]+1)
        for i in range(index0[0]+1,len(S)+1):
            num[i] = max(num[i],num[i-1]+1)
            if(i >= len(S)):break
            if(S[i]== '>'):break
        index0.pop(0)

ans = 0
for i in range(len(num)):
    ans += num[i]
print(ans)

Submission status: Runtime Error

Solution code:
S = list(map(str,input()))
# s = "><<<<><<"
# S = list(map(str,s))
num = [-1]*(len(S)+1)
index0 = list()
than = 0# 0 == >, 1 == <
#----------------------------------------
for i in range(len(S)):
    if(S[i] == '<'):
        if(than == 0):
            num[i] = 0
            index0.append(i)
        than = 1
    else:
        than = 0
if(S[-1] == '>'):
    num[-1] = 0
    index0.append(len(S)+1)
#--------------------------------------
if(index0[0] == 0):
    i = 1
    while(True):
        num[i] = num[i-1]+1
        if(S[i] == '>'):
            break
        i+=1
    index0.pop(0)
if(index0[-1] == len(S)+1):
    i = len(S)-1
    while(True):
        num[i] = num[i+1]+1
        i-=1
        if(i <= 0):break
        if(S[i] == '<'):break
    index0.pop(-1)
while(len(index0)>0):
        for i in reversed(range(0,index0[0])):
            if(S[i] == '<'):
                break
            num[i] = max(num[i],num[i+1]+1)
        for i in range(index0[0]+1,len(S)+1):
            num[i] = max(num[i],num[i-1]+1)
            if(i >= len(S)):break
            if(S[i]== '>'):break
        index0.pop(0)

ans = 0
for i in range(len(num)):
    ans += num[i]
print(ans)

Submission status: Runtime Error

Solution code:
S = list(map(str,input()))
# s = "><<<<><<"
# S = list(map(str,s))
num = [-1]*(len(S)+1)
index0 = list()
than = 0# 0 == >, 1 == <
#----------------------------------------
for i in range(len(S)):
    if(S[i] == '<'):
        if(than == 0):
            num[i] = 0
            index0.append(i)
        than = 1
    else:
        than = 0
if(S[-1] == '>'):
    num[-1] = 0
    index0.append(len(S)+1)
#--------------------------------------
if(index0[0] == 0):
    i = 1
    while(True):
        num[i] = num[i-1]+1
        if(S[i] == '>'):
            break
        i+=1
    index0.pop(0)
if(index0[-1] == len(S)+1):
    i = len(S)-1
    while(True):
        num[i] = num[i+1]+1
        i-=1
        if(S[i] == '<'):
            break
    index0.pop(-1)
while(len(index0)>0):
        for i in reversed(range(0,index0[0])):
            if(S[i] == '<'):
                break
            num[i] = max(num[i],num[i+1]+1)
        for i in range(index0[0]+1,len(S)+1):
            num[i] = max(num[i],num[i-1]+1)
            if(i >= len(S)):break
            if(S[i]== '>'):break
        index0.pop(0)

ans = 0
for i in range(len(num)):
    ans += num[i]
print(ans)

Submission status: Runtime Error

Solution code:
S=list(str(input()))
ans=0
sofar=0
j=1
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        ans+=j
        j+=1
    elif S[i]=='<' and S[i+1]=='>':
        ans+=j
        nax=j
        j=1    
    else:
        ans+=j
        if nax!=0:
            ans-=j
        j=1
        nax=0
    if j>nax:
        ans-=nax
        nax=0
ans+=j
print(ans)

Submission status: Runtime Error

Solution code:
s=input()

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

total=0
cnt=0
while s[0]=='>':
  cnt+=1
  s=s[1:]
total+=sigma(cnt)
  
flag=True
while flag:
  l=[]
  if '>' in s:
    for i in range(s.find('>')):
      l.append(s[i])
    s=s[s.find('>'):]
  else:
    l.extend(['<']*len(s))
    s=''
    flag=False
  if '<' in s:
    for i in range(s.find('<')):
      l.append(s[i])
    s=s[s.find('<'):]
  else:
    l.extend(['>']*len(s))
    s=''
    flag=False
  if l.count('<')<=l.count('>'):
    total+=sigma(l.count('>'))+sigma(l.count('<')-1)
  else:
    total+=sigma(l.count('<'))+sigma(l.count('>')-1)

print(total)

Submission status: Runtime Error

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

a = [-1] * n

if s[0] == '<':
    a[0] = 0
if s[-1] == '>':
    a[-1] = 0

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

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

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

print(sum(a))

Submission status: Runtime Error

Solution code:
s = input()
l, count = [], 0
for i in s:
    if i=='>': count+=1
    else:
        if count: l.append(count)
        count = 0
if count: l.append(count); count = 0
j = 0
ans = []
if s[0]=='<':
    ans.append(0)
    for i in range(len(s)):
    if s[i]=='<': ans.append(ans[-1]+1)
    else:
        if l[j]==0: j+=1
        if ans[-1]>=l[j]:
            l[j]-=1
            ans.append(l[j])
                
        else:
            ans[-1]=l[j]
            l[j]-=1
            ans.append(l[j])
    print(sum(ans))

else:
    ans.append(l[j])
    l[j]-=1
    for i in range(len(s)):
    if s[i]=='<': ans.append(ans[-1]+1)
    else:
        if l[j]==0: j+=1
        if j<len(l):
            
            if ans[-1]>=l[j]:
                ans.append(l[j])
                l[j]-=1
                
                    
            else:
                ans[-1]=l[j]
                ans.append(l[j])
                l[j]-=1
                
        else: ans.append(0)
    print(sum(ans))

Submission status: Runtime Error

Solution code:
'''
    TC_1 : 0<2>1>0 : sum : 3
    TC_2 : 0<2>1>0>1<2<3>0<1<2<3<4<5>2>1>0<1 : sum : 28
'''
s = input()
l, count = [], 0
for i in s:
    if i=='>': count+=1
    else:
        if count: l.append(count)
        count = 0
if count: l.append(count); count = 0
j = 0
ans = []
if s[0]=='<': ans.append(0)
else:
    ans.append(l[j])
    l[j]-=1
for i in range(len(s)):
    if s[i]=='<': ans.append(ans[-1]+1)
    else:
        if l[j]==0: j+=1
        if ans[-1]>=l[j]:
            l[j]-=1
            ans.append(l[j])
                
        else:
            ans[-1]=l[j]
            l[j]-=1
            ans.append(l[j])
print(sum(ans))

Submission status: Runtime Error

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

for i in range(num):
    if s[i] is '<':
        a[i+1] = max(a[i+1], a[i]+1)

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

Submission status: Runtime Error

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


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

Submission status: Runtime Error

Solution code:
s = input()
li = []

s0 = s[0]
c = 0
# print(len(s)-1)
for i in range(len(s)+1):
    # print(i)
    if i == len(s):
        li.append(c)
        break
    if s[i] == s0:
        if s[i] == "<":
            c += 1
        else:
            c -= 1
    elif s[i] != s0:
        li.append(c)
        c = 0
        s0 = s[i]
        if s[i] == "<":
            c += 1
        else:
            c -= 1
# else:
#     li.append(c)
# print(li)

# """
ans = 0

if li[0] < 0:
    a = abs(li[0])
    ans += a*(a+1)/2
    li = li[1:]

if li[-1] > 0 and len(li) != 0:
    a = abs(li[0])
    ans += a*(a+1)/2
    li = li[:-1]

# print(li)

if len(li) != 0:
    for i in range(int(len(li)/2)):
        a = abs(li[2*i])
        b = abs(li[2*i+1])
        if a == b:
            ans += a*(a+1)/2 + a*(a-1)/2
        elif a > b:
            ans += a*(a+1)/2
            ans += b*(b-1)/2
        elif a < b:
            ans += a*(a-1)/2
            ans += b*(b+1)/2

print(int(ans))

Submission status: Runtime Error

Solution code:
s = input()
li = []

s0 = s[0]
c = 0
# print(len(s)-1)
for i in range(len(s)+1):
    # print(i)
    if i == len(s):
        li.append(c)
        break
    if s[i] == s0:
        if s[i] == "<":
            c += 1
        else:
            c -= 1
    elif s[i] != s0:
        li.append(c)
        c = 0
        s0 = s[i]
        if s[i] == "<":
            c += 1
        else:
            c -= 1
# else:
#     li.append(c)
# print(li)

# """
ans = 0

if li[0] < 0:
    a = abs(li[0])
    ans += a*(a+1)/2
    li = li[1:]

if li[-1] > 0:
    a = abs(li[0])
    ans += a*(a+1)/2
    li = li[:-1]

# print(li)

if len(li) != 0:
    for i in range(int(len(li)/2)):
        a = abs(li[2*i])
        b = abs(li[2*i+1])
        if a == b:
            ans += a*(a+1)/2 + a*(a-1)/2
        elif a > b:
            ans += a*(a+1)/2
            ans += b*(b-1)/2
        elif a < b:
            ans += a*(a-1)/2
            ans += b*(b+1)/2

print(int(ans))

Submission status: Runtime Error

Solution code:
s = input()
li = []

s0 = s[0]
c = 0
# print(len(s)-1)
for i in range(len(s)+1):
    # print(i)
    if i == len(s):
        li.append(c)
        break
    if s[i] == s0:
        if s[i] == "<":
            c += 1
        else:
            c -= 1
    elif s[i] != s0:
        li.append(c)
        c = 0
        s0 = s[i]
        if s[i] == "<":
            c += 1
        else:
            c -= 1
# else:
#     li.append(c)
# print(li)

# """
ans = 0

if li[0] < 0:
    a = abs(li[0])
    ans += a*(a+1)/2
    li = li[1:]

if li[-1] > 0:
    a = abs(li[0])
    ans += a*(a+1)/2
    li = li[:-1]

# print(li)

if len(li) != 0:
    for i in range(int(len(li)/2)):
        a = abs(li[2*i])
        b = abs(li[2*i+1])
        if a == b:
            ans += 2*a*(a+1)/2
        elif a > b:
            ans += a*(a+1)/2
            ans += b*(b-1)/2
        elif a < b:
            ans += a*(a-1)/2
            ans += b*(b+1)/2

print(int(ans))

Submission status: Runtime Error

Solution code:
s = input()
li = []

s0 = s[0]
c = 0
# print(len(s)-1)
for i in range(len(s)):
    # print(i)
    if s[i] == s0:
        if s[i] == "<":
            c += 1
        else:
            c -= 1
    elif s[i] != s0:
        li.append(c)
        c = 0
        s0 = s[i]
        if s[i] == "<":
            c += 1
        else:
            c -= 1
        if i == len(s)-1:
            li.append(c)
# else:
#     li.append(c)
# print(li)

# """
ans = 0

if li[0] < 0:
    a = abs(li[0])
    ans += a*(a+1)/2
    li = li[1:]

if li[-1] > 0:
    a = abs(li[0])
    ans += a*(a+1)/2
    li = li[:-1]

# print(li)

if len(li) != 0:
    for i in range(int(len(li)/2)):
        a = abs(li[2*i])
        b = abs(li[2*i+1])
        if a == b:
            ans += 2*a*(a+1)/2
        elif a > b:
            ans += a*(a+1)/2
            ans += b*(b-1)/2
        elif a < b:
            ans += a*(a-1)/2
            ans += b*(b+1)/2

print(int(ans))

Submission status: Runtime Error

Solution code:
s = input()
li = []

s0 = s[0]
c = 0
for i in range(len(s)):
    # print(i, c)
    if s[i] == s0:
        if s[i] == "<":
            c += 1
        else:
            c -= 1
    elif s[i] != s0:
        li.append(c)
        c = 0
        s0 = s[i]
        if s[i] == "<":
            c += 1
        else:
            c -= 1
else:
    li.append(c)
# print(li)

ans = 0

if li[0] < 0:
    a = abs(li[0])
    ans += a*(a+1)/2
    li = li[1:]

if li[-1] > 0:
    a = abs(li[0])
    ans += a*(a+1)/2
    li = li[:-1]

# print(li)

if len(li) != 0:
    for i in range(int(len(li)/2)):
        a = abs(li[2*i])
        b = abs(li[2*i+1])
        if a == b:
            ans += 2*a*(a+1)/2
        elif a > b:
            ans += a*(a+1)/2
            ans += b*(b-1)/2
        elif a < b:
            ans += a*(a-1)/2
            ans += b*(b+1)/2

print(int(ans))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = list(input())
l = [-1]
i = 0
large = False
small = False

while i < len(s):
    if s[i] == "<":
        l.append(l[i] + 1)
    if s[i] == ">":
        cnt = 1
        while s[i + cnt] == ">":
            if i + cnt == len(s) -1:
                cnt += 1
                break
            cnt += 1
        if l[i] < cnt:
            l.append(cnt)
        else:
            l.append(l[i] + 1)
        i += cnt
        cnt -= 1
        while cnt != -1:
            l.append(cnt)
            cnt -= 1
    i += 1
if s[len(s) -1] == "<":
    l.append(l[i] + 1)
del l[0]
ans = sum(l)
print(ans)

Submission status: Runtime Error

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

ans_list = list()
ans = 0

if S[0] == "<":
    decrease = False
    ans_list.append(0)
else:
    decrease = True
    
continue_cnt = 1

for i in range(1,N):
    if decrease == False:
        if S[i] == "<":
            continue_cnt += 1
        else:
            ans_list += [i for i in range(1,continue_cnt+1)]
            
            continue_cnt = 1
            decrease = True
    else:
        if S[i] == ">":
            continue_cnt += 1
        else:
            if ans_list[-1] >= continue_cnt:
                ans_list += [i for i in range(continue_cnt-1,-1,-1)]
            else:
                if len(ans_list)!=0:
                    ans_list.pop(-1)
                ans_list += [i for i in range(continue_cnt,-1,-1)]
                
            continue_cnt = 1
            decrease = False
            
if decrease == True:
    if ans_list[-1] >= continue_cnt:
        ans_list += [i for i in range(continue_cnt-1,-1,-1)]
    else:
        if len(ans_list)!=0:
            ans_list.pop(-1)
        ans_list += [i for i in range(continue_cnt,-1,-1)]
else:
    ans_list += [i for i in range(1,continue_cnt+1)]

#print(ans_list[0],end="")
#for i in range(N):
#    print(S[i],ans_list[i+1],end="")

#print("")
print(sum(ans_list))

Submission status: Runtime Error

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

ans_list = list()
ans = 0

if S[0] == "<":
    decrease = False
    ans_list.append(0)
else:
    decrease = True
    
continue_cnt = 1

for i in range(1,N):
    if decrease == False:
        if S[i] == "<":
            continue_cnt += 1
        else:
            ans_list += [i for i in range(1,continue_cnt+1)]
            
            continue_cnt = 1
            decrease = True
    else:
        if S[i] == ">":
            continue_cnt += 1
        else:
            if ans_list[-1] >= continue_cnt:
                ans_list += [i for i in range(continue_cnt-1,-1,-1)]
            else:
                ans_list.pop(-1)
                ans_list += [i for i in range(continue_cnt,-1,-1)]
                
            continue_cnt = 1
            decrease = False
            
if decrease == True:
    if ans_list[-1] >= continue_cnt:
        ans_list += [i for i in range(continue_cnt-1,-1,-1)]
    else:
        ans_list.pop(-1)
        ans_list += [i for i in range(continue_cnt,-1,-1)]
else:
    ans_list += [i for i in range(1,continue_cnt+1)]

#print(ans_list[0],end="")
#for i in range(N):
#    print(S[i],ans_list[i+1],end="")

#print("")
print(sum(ans_list))

Submission status: Runtime Error

Solution code:
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: Runtime Error

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
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: Runtime Error

Solution code:
S = input()

count0, count1 = 0, 0
val = []
for i in range(len(S)):
    if S[i] == '<':
        count0 += 1
        if count1 != 0:
            val.append(count1)
        if i == len(S)-1:
            val.append(count0)
        count1 = 0
    else:
        count1 += 1
        if count0 != 0:
            val.append(count0)
        if i == len(S)-1:
            val.append(count1)
        count0 = 0
#print(val)
ans = 0
if S[0] == '>' and val[0] == 1:
    ans += 1
for i in range(0, len(val)-1, 2):
    a = max(val[i], val[i+1])
    b = min(val[i], val[i+1])
    ans += a*(a+1)/2 + (b-1)*b/2
if len(val) % 2 == 1:
    if S[-1] == '>':
        a = max(val[-2], val[-1])
        ans += a*(a+1)/2
    else:
        b = min(val[-2], val[-1])
        ans += (b+1)*b/2    
print(int(ans))

Submission status: Runtime Error

Solution code:
S = input()

count0, count1 = 0, 0
val = []
for i in range(len(S)):
    if S[i] == '<':
        count0 += 1
        if count1 != 0:
            val.append(count1)
        if i == len(S)-1:
            val.append(count0)
        count1 = 0
    else:
        count1 += 1
        if count0 != 0:
            val.append(count0)
        if i == len(S)-1:
            val.append(count1)
        count0 = 0
#print(val)
ans = 0
for i in range(0, len(val)-1, 2):
    a = max(val[i], val[i+1])
    b = min(val[i], val[i+1])
    ans += a*(a+1)/2 + (b-1)*b/2
if len(val) % 2 == 1:
    if S[-1] == '>':
        a = max(val[-2], val[-1])
        ans += a*(a+1)/2
    else:
        b = min(val[-2], val[-1])
        ans += (b+1)*b/2    
print(int(ans))

Submission status: Runtime Error

Solution code:
S = input()

count0, count1 = 0, 0
val = []
for i in range(len(S)):
    if S[i] == '<':
        count0 += 1
        if count1 != 0:
            val.append(count1)
        if i == len(S)-1:
            val.append(count0)
        count1 = 0
    else:
        count1 += 1
        if count0 != 0:
            val.append(count0)
        if i == len(S)-1:
            val.append(count1)
        count0 = 0

ans = 0
for i in range(0, len(val)-1, 2):
    a = max(val[i], val[i+1])
    b = min(val[i], val[i+1])
    ans += a*(a+1)/2 + (b-1)*b/2
if len(val) % 2 == 1:
    a = max(val[-2], val[-1])
    #b = min(val[i], val[i+1])
    ans += a*(a+1)/2 #+ (b-1)*b/2    
print(int(ans))

Submission status: Runtime Error

Solution code:
S = input()

count0, count1 = 0, 0
val = []
for i in range(len(S)):
    if S[i] == '<':
        count0 += 1
        if count1 != 0:
            val.append(count1)
        if i == len(S)-1:
            val.append(count0)
        count1 = 0
    else:
        count1 += 1
        if count0 != 0:
            val.append(count0)
        if i == len(S)-1:
            val.append(count1)
        count0 = 0
print(val)
ans = 0
for i in range(0, len(val)-1, 2):
    a = max(val[i], val[i+1])
    b = min(val[i], val[i+1])
    ans += a*(a+1)/2 + (b-1)*b/2
if len(val) % 2 == 1:
    a = max(val[-2], val[-1])
    #b = min(val[i], val[i+1])
    ans += a*(a+1)/2 #+ (b-1)*b/2    
print(int(ans))

Submission status: Runtime Error

Solution code:
S = input()

count0, count1 = 0, 0
val = []
for i in range(len(S)):
    if S[i] == '<':
        count0 += 1
        if count1 != 0:
            val.append(count1)
        if i == len(S)-1:
            val.append(count0)
        count1 = 0
    else:
        count1 += 1
        if count0 != 0:
            val.append(count0)
        if i == len(S)-1:
            val.append(count1)
        count0 = 0

ans = 0
for i in range(0, len(val)-1, 2):
    a = max(val[i], val[i+1])
    b = min(val[i], val[i+1])
    ans += a*(a+1)/2 + (b-1)*b/2
if len(val) % 2 == 1:
    b = min(val[-2], val[-1])
    ans += (b+1)*b/2    
print(int(ans))

Submission status: Runtime Error

Solution code:
S = input()
m = 1
num = 1
for c in S:
  if c == '<':
    num += 1
  elif c == '>':
    num -= 1
  m = min(num, m)
if m <= 0:
  num += 1 - m
else:
  num = 1
ans += num
for c in S:
  if c == '<':
    num += 1
  elif c == '>':
    num -= 1
  ans += num
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
Ans = [None] * (n + 1)

top = set()
bottom = set()
if s[0] == ">":
    top.add(0)
else:
    bottom.add(0)

for i in range(len(s)-1):
    left = s[i]
    right = s[i+1]
    if left == "<" and right == ">":
        top.add(i+1)
    elif left == ">" and right == "<":
        bottom.add(i+1)

if s[n-1] == ">":
    bottom.add(n)
else:
    top.add(n)

for b in list(bottom):
    counter = 0
    for i in range(b, n+1):
        if i in top:
            break
        else:
            Ans[i] = counter
            counter += 1

    counter = 0
    for i in range(b-1, -1, -1):
        if i in top:
            break
        else:
            Ans[i] = counter + 1
            counter += 1
#print(Ans)

for t in list(top):
    if t == 0:
        Ans[0] = Ans[1] + 1
    if t == n:
        Ans[n] = Ans[n-1] + 1
    else:
        Ans[t] = max(Ans[t-1] + 1, Ans[t+1] + 1)

#print(top)
#print(bottom)
print(sum(Ans))

Submission status: Runtime Error

Solution code:
s = input() 
ans = 0
flag = False
s += "|"
if s[0] == ">": 
    cntl = 1
    flag = True
else:
    cntr = 1
for i in range(1,len(s)):
    if flag:
        if s[i] == ">":
            ans += cntl
            cntl += 1
        else:
            ans += cntl if cntl >= need else need
            flag = False
            cntr = 1
    else:
        if s[i] == "<":
            ans += cntr
            cntr += 1
        else:
            need = cntr
            flag = True
            cntl = 1
            if i == len(s)-1:
                ans += need
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
a = 0
ans = 0
b = 0
d = []
e = []
now = 0

for i in range(len(s)):
    if s[i] == '<':
        
        if a != 0:
            if a > now:
                ans = ans - d[-1] + a
                
            for j in range(a):
                ans = ans + j
                d.append(a - j)
                e.append(">")
            now = 0
            a = 0
        
        ans = ans + now + 1
        now = now + 1
        d.append(now)
        
    else:
        a = a + 1
        b = 0
    
if a != 0:
    if a > now:
        ans = ans - d[-1] + a
                
    for j in range(a):
        ans = ans + j
        d.append(a - j)
        e.append(">")
    
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
<_cnt = 0
>_cnt = 0
total = 0
for i in range(len(s)):
  if s[i] == '<' and >_cnt == 0:
    <_cnt += 1
  elif s[i] == '<' and >_cnt > 0:
    k = max(<_cnt, >_cnt)
    l = min(<_cnt, >_cnt)
    total += (((k+1)*k) + (l*(l-1)))//2
    <_cnt = 1
    >_cnt = 0
  elif s[i] == '>':
    >_cnt += 1
k = max(<_cnt, >_cnt)
l = min(<_cnt, >_cnt)
total += (((k+1)*k) + (l*(l-1)))//2
print(total)

Submission status: Runtime Error

Solution code:
s = input()
<_cnt = 0
>_cnt = 0
total = 0
for i in range(len(s)):
  if s[i] == '<' and >_cnt == 0:
    <_cnt += 1
  elif s[i] == '<' and >_cnt > 0:
    k = max(<_cnt, >_cnt)
    l = min(<_cnt, >_cnt)
    total += (k+1)*k//2 + l*(l-1)//2
    <_cnt = 1
    >_cnt = 0
  elif s[i] == '>':
    >_cnt += 1
k = max(<_cnt, >_cnt)
l = min(<_cnt, >_cnt)
total += (k+1)*k//2 + l*(l-1)//2
print(total)

Submission status: Runtime Error

Solution code:
s = input()
<_cnt = 0
>_cnt = 0
for i in range(len(s)):
  if s[i] == '<' and >_cnt == 0:
    <_cnt += 1
  elif s[i] == '<' and >_cnt > 0:
    k = max(<_cnt, >_cnt)
    l = min(<_cnt, >_cnt)
    total += (k+1)*k//2 + l*(l-1)//2
    <_cnt = 1
    >_cnt = 0
  elif s[i] == '>':
    >_cnt += 1
k = max(<_cnt, >_cnt)
l = min(<_cnt, >_cnt)
total += (k+1)*k//2 + l*(l-1)//2
print(total)

Submission status: Runtime Error

Solution code:

import math

def main():
    s = str(input())
    first = s[0]
    cnt_l = []
    tmp_cnt = 1
    prev_s = first
    for curr_s in s[1:]:
        if prev_s != curr_s:
            cnt_l.append(tmp_cnt)
            tmp_cnt = 1
        else:
            tmp_cnt+=1
        prev_s = curr_s
    cnt_l.append(tmp_cnt)

    ans_l = []
    last_num = 0
    if first == '>':
        down_cnt = ans_l[0]
        for d in range(down_cnt):
            ans_l.append(down_cnt-1-d)
        ans_l = ans_l[1:]

    # if first == '<':
    # print(cnt_l)
    ans_l.append(0)
    last_num = 0
    for i in range(math.ceil(len(cnt_l)/2)):
        # print('i',i)
        up_cnt = cnt_l[i*2]
        if i*2+1 >= len(cnt_l):
            down_cnt = 0
        else:
            down_cnt = cnt_l[i*2+1]
        # print(up_cnt,down_cnt)
        # print()
        for u in range(up_cnt):
            if u != up_cnt-1:
                last_num+=1
                ans_l.append(last_num)
            else:
                last_num = max(last_num+1, down_cnt)
                ans_l.append(last_num)
        for d in range(down_cnt):
            if d==0:
                if last_num > down_cnt:
                    last_num = down_cnt-1
                else:
                    last_num-=1
                ans_l.append(last_num)
            else:
                last_num-=1
                ans_l.append(last_num)

    # print(ans_l)
    print(sum(ans_l))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
s = input()
if s[0] == '>':
  a = [0]
else:
  a = []
flg = 1
for i in range(1,len(s)):
  if s[i] != s[i-1]:
    a.append(flg)
    flg = 1
  else:
    flg += 1
if s[-1] != s[-2]:
  a.append(flg)
else:
  a.append(flg)
if s[-1] == '<':
  a.append(0)
ans = 0
for i in range(len(a)//2):
  if a[2*i] > a[2*i+1]:
    a[2*i+1] -= 1
    ans += a[2*i]*(a[2*i]+1)//2 + a[2*i+1]*(a[2*i+1]+1)//2
  else:
    a[2*i] -= 1
    ans += a[2*i]*(a[2*i]+1)//2 + a[2*i+1]*(a[2*i+1]+1)//2
print(ans)