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:
S = input()
N = len(S)+1
A = [0] * N
B = [0] * (N+1)

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

print(sum(A)+sum(B))

Submission status: Runtime Error

Solution code:
S = list(map(str, input()))
N = len(S)+1
List = [0]*N
rightcount = 0
leftcount = 0

if S[0] == "<":
    leftcount+=1
else:
    rightcount+=1

for i in range(1, N-1):
    if S[i] == "<":
        leftcount+=1
        if S[i-1] == ">":
            for j in range(rightcount):
                List[i-j] = j
            if List[i-rightcount]<List[i-rightcount+1]:
                List[i-rightcount] = List[i-rightcount+1] + 1
            rightcount = 0


    if S[i] == ">":
        rightcount+=1
        if S[i-1] =="<":
            for j in range(leftcount+1):
                List[i-j] = leftcount - j
            leftcount = 0

if S[N-2] == "<":
    List[N-1] = 1
else:
    for j in range(rightcount):
        List[N-j] = j
    if List[N-rightcount]<List[N-rightcount+1]:
        List[N-rightcount] = List[N-rightcount+1] + 1

print(sum(List))

Submission status: Runtime Error

Solution code:
s=input()
SUM=0
p=0;q=0
b=0

j=0
while s[j]==">":
    j+=1
SUM+=(1+j)*j//2
h=s[j]
for i in range(j,len(s)):
    if s[i]==h and b==0:
        p+=1
    if s[i]!=h:
        q+=1
        b=1
    if (s[i]==h and b==1) or (i==len(s)-1):
        w1=max(p,q)
        w2=min(p,q)
        SUM+=(1+w1)*w1//2+w2*(w2-1)//2
        if (s[i]==h and b==1) and (i==len(s)-1):
            SUM+=1
        b=0
        p=1;q=0
        
print(SUM)

Submission status: Runtime Error

Solution code:
s = input()

def rle(s):
	tmp, count, ans = s[0], 1, ""
	for i in range(1,len(s)):
		if tmp == s[i]:
			count += 1
		else:
			ans += tmp + str(count)
			tmp = s[i]
			count = 1
	ans += tmp + str(count)
	return ans

r = rle(s)

if (len(r) // 2) % 2 == 1:
	r += '>0'

res = 0
for i in range(len(r) // 4):
	a, b = int(r[4*i+1]), int(r[4*i+3])
	ma, mi = max(a, b), min(a, b)
	res += (ma * (ma + 1)) // 2 + (mi * (mi - 1)) // 2
print(res)

Submission status: Runtime Error

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

import numpy as np


def main():
    S = readline().rstrip()
    if S[0] == '>':
        S = '<' + S
    if S[-1] == '<':
        S = S + '>'
    ids = [0]
    ans = np.array([0] * (len(S) + 1))
    for i in range(len(S)-1):
        s = S[i:i+2]
        if s == '<>' or s == '><':
            ids.append(i+1)

    ids += [len(S)]

    for i in range(1, len(ids)-1, 2):
        current = ids[i]
        l = ids[i-1]
        r = ids[i+1]
        left = current - l
        right = r - current
        n = max(left, right)
        ans[current] = n
        if left >= right:
            ans[l:current] = np.arange(0, n)
            ans[current+1:r+1] = np.arange(right-1, -1, -1)
        else:
            ans[left:current] = np.arange(0, left)
            ans[current+1:r+1] = np.arange(n-1, -1, -1)    

    print(sum(ans)) 


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
s=input()
rl=[]
ll=[]
c=0
for i in range(len(s)-1):
  c+=1
  if s[i]!=s[i+1]:
    if s[i]=='<':
      rl.append(c)
    else:
      ll.append(c)
    c=0
if s[len(s)-1]=='<':
  rl.append(c+1)
else:
  ll.append(c+1)

rn=len(rl)
ln=len(ll)
ans=0
if s[0]=='<':
  for i in range(ln):
    M=max(rl[i], ll[i])
    m=min(rl[i], ll[i])
    ans+=M*(M+1)//2+m*(m-1)//2
  if rn>ln:
    ans+=rl[-1]*(rl[-1]+1)//2
else:
  ans+=ll[0]*(ll[0]+1)//2
  for i in range(rn-1):
    M=max(rl[i], ll[i+1])
    m=min(rl[i], ll[i+1])
    ans+=M*(M+1)//2+m*(m-1)//2
  if rn==ln:
    ans+=rl[-1]*(rl[-1]+1)//2
  else:
    M=max(rl[-1], ll[-1])
    m=min(rl[-1], ll[-1])
    ans+=M*(M+1)//2+m*(m-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
s=input()
rl=[]
ll=[]
c=0
for i in range(len(s)-1):
  c+=1
  if s[i]!=s[i+1]:
    if s[i]=='<':
      rl.append(c)
    else:
      ll.append(c)
    c=0
if s[len(s)-1]=='<':
  rl.append(c+1)
else:
  ll.append(c+1)

rn=len(rl)
ln=len(ll)
ans=0
if s[0]=='<':
  for i in range(ln):
    M=max(rl[i], ll[i])
    m=min(rl[i], ll[i])
    ans+=M*(M+1)//2+m*(m-1)//2
  if rn>ln:
    ans+=rl[-1]*(rl[-1]+1)//2
else:
  ans+=ll[0]*(ll[0]+1)//2
  for i in range(rn):
    M=max(rl[i], ll[i+1])
    m=min(rl[i], ll[i+1])
    ans+=M*(M+1)//2+m*(m-1)//2
  if rn==ln:
    ans+=rl[-1]*(rl[-1]+1)//2
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
zero = []
turn = []

def sum_n(n):
    return (n ** 2 + n) // 2

for i, s in enumerate(S):
    if i == 0:
        if s == '<':
            zero.append(i)
        else:
            turn.append(-1)
    else:
        if s_ == '>' and s == '<':
            zero.append(i)
        elif s_ == '<' and s == '>':
            turn.append(i)
    if i == len(S) - 1:
        if s == '>':
            zero.append(i + 1)
        else:
            turn.append(i + 1)
            zero.append(i + 2)
    s_ = s

#print(len(zero), zero)
#print(len(turn), turn)

ans = 0

for i in range(len(turn)):
    ans += sum_n(zero[i+1] - turn[i] - 1)
    ans += sum_n(turn[i] - zero[i] - 1)
    ans += max(zero[i+1] - turn[i], turn[i] - zero[i])
print(ans)

Submission status: Runtime Error

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

mn = 0
ans = 0
for s in S:
  if s == '<':
    a += 1
  elif s == '>':
    a -= 1
    mn = min(mn,a)    
  
  ans += a
  
ans -= mn * N
print(ans)

Submission status: Runtime Error

Solution code:
S = list(input())

mn = 0
ans = 0
for s in S:
  if s == '<':
    a += 1
  elif s == '>':
    a -= 1
    mn = min(mn,a)    
  
  ans += a
  
ans -= mn * (len(S) + 1)
print(ans)

Submission status: Runtime Error

Solution code:
S = list(input())

mn = 0
ans = 0
for s in S:
  if s == '<':
    a += 1
  elif s == '>':
    a -= 1
    mn = min(mn,a)    
  
  ans += a
  
plus = -mn
ans += plus * (len(S) + 1)
print(ans)

Submission status: Runtime Error

Solution code:
s =input()
n = len(s)
a = [0]*(n+1)
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: Runtime Error

Solution code:
S=input()
li=[]
cnt=1
now=S[0]
for i in range(1,len(S)):
    if(S[i]==now):
        cnt+=1
        if(i==len(S)-1):
            li.append([now,cnt])
    else:
        li.append([now,cnt])
        now=S[i]
        cnt=1
        if(i==len(S)-1):
            li.append([now,cnt])
res=0
if(li[0][0]=='>'):
    res+=li[0][1]
if(li[-1][0]=='<'):
    res+=li[-1][1]
for i in range(len(li)-1):
    if(li[i][0]=='<' and li[i+1][0]=='>'):
        max_=max(li[i][1],li[i+1][1])
        min_=min(li[i][1],li[i+1][1])
        res+=((max_+1)*max_)//2
        res+=((min_)*(min_-1))//2
print(res)

Submission status: Runtime Error

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

Solution code:
n =input().split("")
a=n.count("<")
b =n.count(">")
c = a+b

print((c-1)*c/2)

Submission status: Runtime Error

Solution code:
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):
        j = 0
        r = 0
        while True:
            if i + j < ls:
                if S[i + j] == '>':
                    r += 1
                    j += 1
                else:
                    rr[i] = r
                    break
            else:
                rr[i] = r
                break

    for i in range(1,ls+1):
        j = 0
        l = 0
        while True:
            if i - j-1 >= 0:
                if S[i - j-1] == '<':
                    l += 1
                    j += 1
                else:
                    ll[i] = l
                    break

            else:
                ll[i] = l
                break

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


resolve()

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
i,cntl,cntg=0,0,0
res,fl,fg=0,0,0
while(i<n):
  if s[i]=='<':
    while(s[i]!='>'):
      fl=1
      cntl+=1
      i+=1
  else:
    while(s[i]!='<'):
      fg=1
      cntg+=1
      i+=1
  if fl==1 and fg==1:
    res+=max(cntl,cntg)
    cntl-=1
    cntg-=1
    res+=cntl*(cntl+1)//2
    res+=cntg*(cntg+1)//2
    fl,fg,cntl,cntg=0,0,0,0
if fl:
  res+=cntl*(cntl+1)//2
if fg:
  res+=cntg*(cntg+1)//2
print(res)

Submission status: Runtime Error

Solution code:

s=input()
n=len(s)
ans=[0]*(n+1)
m=0
for i in range(1,n+1):
	if s[i]=='<':
		ans[i]=ans[i-1]+1
	else:
		ans[i]=ans[i-1]-1
	m=min(m,ans[i])
print(sum(ans)-m*n)

Submission status: Runtime Error

Solution code:
S = input()

s = S.replace('<>', '<,>').replace('><', '>,<').split(',')
lst1 = [ss.count('<') - ss.count('>') for ss in s]

ans = [0]

for i in lst:
    if i > 0:
        ans += list(range(1,i+1))
    else:
        ans[-1] = max(ans[-1], -i)
        ans += list(range(-i-1,-1, -1))

print(sum(ans))

Submission status: Runtime Error

Solution code:
S = input()

lst = [1]
for i in range(1, len(S)):
    if S[i] == S[i - 1]:
        if S[i]=='<':lst[-1] += 1
        else: lst[-1] -= 1
    else:
        if S[i]=='>':lst.append(-1)
        else: lst.append(1)

ans = []
con = 0

for i in range(len(lst)):
    if lst[i] > 0:
        for j in range(0, lst[i] + 1):
            ans.append(j)
        con = lst[i]
    else:
        ans[-1] = max(con, -lst[i])
        for j in range(0, -lst[i]):
            ans.append(-lst[i]-j-1)
        cont = 0
print(sum(ans))

Submission status: Runtime Error

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

flag=1
while flag==1:
  flag=0
  for i in range(n-1):
      if s[i]=='<' and l[i]>l[i+1]:
        flag=1
        l[i+1]+=1
      else s[i]=='>' and l[i]<l[i+1]:
        flag=1
        l[i]+=1
        
ans=0
for i in range(n):
  ans+=l[i]
  
print(ans)

Submission status: Runtime Error

Solution code:
S = input()

N = len(S) + 1
t = [0] * N
for i in range(N - 1):
    if S[i] == '<':
        t[i + 1] = t[i] + 1
for i in range(N - 1, -1, -1):
    if S[i] == '>':
        t[i + 1] = max(t[i], t[i + 1] + 1)
print(sum(t))

Submission status: Runtime Error

Solution code:
S = input()

N = len(S) + 1
t = [0] * N
for i in range(N - 1):
    if S[i] == '<':
        t[i + 1] = t[i] * 1
for i in range(N - 1, -1, -1):
    if S[i] == '>':
        t[i] = max(t[i], t[i + 1] + 1)
print(sum(t))

Submission status: Runtime Error

Solution code:
S = map(str, input().split())

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 - 1, -1, -1):
    if S[i] == '>':
        t[i] = max(t[i], t[i + 1] + 1)
print(sum(t))

Submission status: Runtime Error

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

Solution code:
def calcsum(n):
    return n * (n + 1) // 2

s = str(input())
n = len(s) + 1
arrk = []
arrg = []
tmp = s[0]
cnt = 1
for i in range(1, n-1):
    if s[i] == tmp:
        cnt += 1
    elif s[i] != tmp:
        if tmp == '<':
            arrk.append(cnt)
        else:
            arrg.append(cnt)
        cnt = 1
        tmp = s[i]
if tmp == '<':
    arrk.append(cnt)
else:
    arrg.append(cnt)
#print(arrk, arrg)
ans = 0
for i in range(len(arrk)):
    #print(calcsum(arrk[i]-1))
    ans += calcsum(arrk[i]-1)
for i in range(len(arrg)):
    #print(calcsum(arrg[i]-1))
    ans += calcsum(arrg[i]-1)
#print('ans',ans)
if s[0] == '<':
    for i in range(len(arrg)):
        #print('a', max(arrg[i], arrk[i]))
        ans += max(arrg[i], arrk[i])
    if len(arrg) > len(arrk):
        ans += arrg[len(arrg)-1]
    elif len(arrk) > len(arrg):
        ans += arrk[len(arrk)-1]
elif s[0] == '>':
    ans += arrg[0]
    for i in range(len(arrk)-1):
        #print('a', max(arrg[i+1], arrk[i]))
        ans += max(arrg[i+1], arrk[i])
    if len(arrg) > len(arrk):
        ans += arrg[len(arrg)-1]
    elif len(arrk) > len(arrg):
        ans += arrk[len(arrk)-1]
    else:
        if s[n-2] == '<':
        ans += arrk[len(arrk)-1]
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
S=list(input())

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

ans=0
if nums[0]<0:
    are=nums.pop(0)
    ans+=are*(are+1)//2
if nums[-1]>0:
    are=nums.pop(-1)
    ans+=are*(are+1)//2

temp=list(map(lambda x:abs(x)-1,nums))
temp=list(map(lambda x:x*(x+1)//2,temp))

ans+=sum(temp)
#print(ans)
for i in range(len(nums)-1):
    if nums[i]>0:
        ans+=max(nums[i],-nums[i+1])
#print(nums)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s=input()
def val(a):
  if a==0:
    uuu=[s[i] for i in range(len(s)) if s[i]=='>' else break]
    return len(uuu)
  elif a==len(s):
    yyy=[s[len(s)-1-i] for i in range(len(s)) if s[len(s)-1-i]=='<' else break]
    return len(yyy)
  else:
    uuu=[s[a-1-i] for i in range(a) if s[a-1-i]=='<' else break]
    yyy=[s[a+i] for i in range(len(s)-a) if s[a+i]=='>' else break]
    return max(len(uuu),len(yyy))
ans=0
for i in range(len(s)+1):
  ans+=val(i)
print(ans)

Submission status: Runtime Error

Solution code:
L = input()
L = list(L.split('><'))
if len(L) == 1:
    a = [L[0].count('<'),L[0].count('>')]
    a_max = max(a)
    ans += a_max*(a_max+1)/2
else:
    ans = 0
    for i in range(len(L)):
        if i == 0:
            a = [L[i].count('<'),L[i].count('>')+1]
        elif i == len(L)-1:
            a = [L[i].count('<')+1,L[i].count('>')]
        else:
            a = [L[i].count('<')+1,L[i].count('>')+1]
        a_max = max(a)
        a_min = min(a)

        ans += a_max*(a_max+1)/2
        ans += a_min*(a_min-1)/2

print(int(ans))

Submission status: Runtime Error

Solution code:
L = input()
L = list(L.split('><'))
if len(L) == 1:
    a = [L[0].count('<'),L[0].count('>')]
    ans += a_max*(a_max+1)/2
else:
    ans = 0
    for i in range(len(L)):
        if i == 0:
            a = [L[i].count('<'),L[i].count('>')+1]
        elif i == len(L)-1:
            a = [L[i].count('<')+1,L[i].count('>')]
        else:
            a = [L[i].count('<')+1,L[i].count('>')+1]
        a_max = max(a)
        a_min = min(a)

        ans += a_max*(a_max+1)/2
        ans += a_min*(a_min-1)/2

print(int(ans))

Submission status: Runtime Error

Solution code:
#bfs

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

ans = 0
a = [None]*N

prev = ">"
q=[]

#確定0を埋める．
for i in range(N-1):
    if prev==">" and S[i] == "<":
        a[i]=0
        q.append(i)
    prev = S[i]

if S[-1]==">":
    a[-1]=0
    q.append(N-1)

while len(q)!=0:
    i = q.pop()
    if i+1 < N:
        if S[i]=="<":
            if a[i+1]==None:
                a[i+1]=a[i]+1
                q.append(i+1)
            else:
                a[i+1]=max(a[i]+1,a[i+1])
    if i-1>0:
        if S[i-1]==">":
            if a[i-1]==None:
                a[i-1]=a[i]+1
                q.append(i-1)
            else:
                a[i-1]=max(a[i]+1,a[i-1])

print(sum(a))

Submission status: Runtime Error

Solution code:
#AGC-040
S = input()
A = [0] * (len(S) + 1)

def check_left(n, S):
    count = 0
    for i in reversed(range(0, n)):
        if S[i] == "<":
            count += 1
        else:
            break
    return count

def check_right(n, S):
    count = 0
    for i in range(n, len(S)):
        if S[i] == ">":
            count += 1
        else:
            break
    return count

A[0] = max(check_left(0, S), check_right(0, S))

for i in range(1, len(S)+1):
    if A[i-1] != 0:
        if S[i-1] == "<":
            A[i] = A[i-1] + 1
        else:
            if S[i] == "<":
                A[i] = 0
            else:
                A[i] = max(check_left(i, S), check_right(i, S))
    else:
        A[i] = max(check_left(i, S), check_right(i, S))

print(sum(A))

Submission status: Runtime Error

Solution code:
#AGC-040
S = input()
A = [0] * (len(S) + 1)

def check_left(n, S):
    count = 0
    for i in reversed(range(0, n)):
        if S[i] == "<":
            count += 1
        else:
            break
    return count

def check_right(n, S):
    count = 0
    for i in range(n, len(S)):
        if S[i] == ">":
            count += 1
        else:
            break
    return count

A[0] = max(check_left(i, S), check_right(i, S))

for i in range(1, len(S)+1):
    if A[i-1] != 0:
        if S[i-1] == "<":
            A[i] = A[i-1] + 1
        else:
            if S[i] == "<":
                A[i] = 0
            else:
                A[i] = max(check_left(i, S), check_right(i, S))
    else:
        A[i] = max(check_left(i, S), check_right(i, S))

print(sum(A))

Submission status: Runtime Error

Solution code:
#AGC-040
S = input()
A = [0] * (len(S) + 1)

def check_left(n, S):
    count = 0
    for i in reversed(range(0, n)):
        if S[i] == "<":
            count += 1
        else:
            break
    return count

def check_right(n, S):
    count = 0
    for i in range(n, len(S)):
        if S[i] == ">":
            count += 1
        else:
            break
    return count

A[0] = max(check_left(i, S), check_right(i, S))

for i in range(1, len(S)+1):
    if A[i-1] != 0:
        if S[i-1] == "<":
            A[i] = A[i-1] + 1
        else: #elif S[i-1] == ">"
            if S[i] == "<":
                A[i] = 0
            else:
                A[i] = max(check_left(i, S), check_right(i, S))
    else:
        A[i] = max(check_left(i, S), check_right(i, S))

print(sum(A))

Submission status: Runtime Error

Solution code:
#AGC-040
S = input()
A = [0] * (len(S) + 1)

def check_left(n, S):
    count = 0
    for i in reversed(range(0, n)):
        if S[i] == "<":
            count += 1
        else:
            break
    return count

def check_right(n, S):
    count = 0
    for i in range(n, len(S)):
        if S[i] == ">":
            count += 1
        else:
            break
    return count

for i in range(len(S)+1):
    if i > 0 and A[i-1] != 0:
        if S[i-1] == ">":
            if S[i+1] == "<":
                A[i] = 0
            else:
                A[i] = A[i-1] - 1
        else:
            A[i] = A[i-1] + 1
    else:
        A[i] = max(check_left(i, S), check_right(i, S))
    
print(sum(A))

Submission status: Runtime Error

Solution code:
from itertools import groupby
import sys
S = list(input())
Sum = 0

def sumup(num):
    if num == 0:
        return 0
    else:
        return (num + sumup(num-1))
S_g = [[k,len(list(g))] for k, g in groupby(S)]
print(S_g, file=sys.stderr)
sum1 = 0
sum2 = 0
if S_g[0][0] == '>':
    i = 1
else:
    i = 0
if S_g[len(S_g)-1][0] == '<':
    n = len(S_g)-1
else:
    n = len(S_g)
start = i
end = n
while i < n:
    sum1 = sumup(S_g[i][1])
    sum2 = sumup(S_g[i+1][1])
    if sum1 >= sum2:
        sum2 = sumup(S_g[i+1][1]-1)
    else :
        sum1 = sumup(S_g[i][1]-1)   
    Sum = sum2 + sum1 + Sum
    i = i + 2

if start == 1:
    Sum = Sum + sumup(S_g[0][1])
if end == len(S_g)-1:
    Sum = Sum + sumup(S_g[len(S_g)-1][1])
print(Sum)

Submission status: Runtime Error

Solution code:
from itertools import groupby
import sys
S = list(input())
Sum = 0

def sumup(num):
    if num == 0:
        return 0
    else:
        return (num + sumup(num-1))
S_g = [[k,len(list(g))] for k, g in groupby(S)]
print(S_g, file=sys.stderr)
sum1 = 0
sum2 = 0
for i in range(1,len(S_g)):
    sum1 = sumup(S_g[i-1][1])
    sum2 = sumup(S_g[i][1])
    if sum1 >= sum2 and S_g[i][0] == '>':
        sum2 = sumup(S_g[i][1]-1)
        print(['if',Sum,sum2], file=sys.stderr)
    Sum = sum2 + Sum
    print([Sum,sum2], file=sys.stderr)
if S_g[0][0] == '>' or S_g[0][1] > S_g[1][1]:
    Sum = Sum + sumup(S_g[0][1])
else:
    Sum = Sum + sumup(S_g[0][1]-1)
print(Sum)

Submission status: Runtime Error

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

Solution code:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 5e5+10;

string S;

int solve() {
    if (S[0] == '>') S = '<' + S;
    if (S[S.size()-1] == '<') S = S + '>';
    S = S + ';';

    vector<string> strs;
    string s;
    REP (r, S.size()-1) {
        s += S[r];
        if (S[r] == '>' && S[r+1] != '>') {
            strs.push_back(s);
            s = "";
        }
    }

    ll ans = 0;
    FORE (s, strs) {
        cout << s << endl;
        ll left = 0, right = 0;
        while (s[left] == '<') left++;
        right = s.size() - left;
        ll res = left * (left+1) / 2 +  right * (right+1) / 2 - min(left, right);
        ans += res;
    }
    return ans;
}

int main() {
    cin >> S;
    cout << solve() << endl;
}

Submission status: Runtime Error

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[i] == '>':
    tmp *= -1
cnts.append(tmp)

idx = 0
a = [0] * (len(s)+1)
for i in range(len(cnts)):
    base = 0
    if i != 0 and cnts[i-1] > 0 and cnts[i] < 0 and a[idx-1] >= abs(cnts[i]):
        base = a[idx-1] - abs(cnts[i])
    for j in range(abs(cnts[i])):
        if cnts[i] > 0:
            a[idx] = j
        else:
            a[idx] = abs(cnts[i]) - j + base
        idx += 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: Runtime Error

Solution code:
def left(arr, idx):
    if L[idx] != None:
        return L[idx]
    if idx == -1:
        ret =  0
    else:
        if arr[idx] == '<':
            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 idx == len(arr):
        ret =  0 
    else:
        if arr[idx] == '>':
            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+1)]
    global R; R = [None for _ in range(N+1)]

    for i in range(len(A)):
        A[i] = max(left(S, i-1), right(S, i))
            
    print(sum(A))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def left(arr, idx):
    if L[idx] != None:
        return L[idx]
    if idx == -1:
        ret =  0
    else:
        if arr[idx] == '<':
            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 idx == len(arr):
        ret =  0 
    else:
        if arr[idx] == '>':
            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+1)]
    global R; R = [None for _ in range(N+1)]

    for i in range(len(A)):
        A[i] = max(left(S, i-1), right(S, i))
            
    print(sum(A))
    print(L)
    print(R)
    print(A)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
s = input()

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

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

        elif '<' == s[y] and l[y] < l[y+1]:
            l[y], l[y+1] = l[y], l[y+1]

        elif '>' == s[y] and l[y] > l[y+1]:
            l[y], l[y+1] = l[y], l[y+1]

        elif '>' == s[y] and l[y] < l[y+1]:
            l[y], l[y+1] = l[y+1], l[y]

print(sum(l))

Submission status: Runtime Error

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)//2+1):
        r += min(cntl[2*i-1],cntl[2*i])
print(s-r)

Submission status: Runtime Error

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

MAX_INT = 100000
s_txt = input()

MIN_V = 1000000

def func(my_suretu, my_s_txt, min_v):
    #print('func(', my_suretu, my_s_txt, min_v, ')')

    now_sum = sum(my_suretu)
    # print(now_sum)
    if (now_sum >= min_v):
        return min_v

    if (len(my_s_txt) == 0):
        if (now_sum < min_v):
            min_v = now_sum
        return min_v
    else:
        next_my_s_txt = my_s_txt[1:]

    for v in range(0, MAX_INT):
        new_min_v = min_v
        if (len(my_suretu)==0):
            new_min_v = func(my_suretu + [v], next_my_s_txt, min_v)
        elif (((my_s_txt[0] == '>') and (my_suretu[-1] > v)) or 
            ((my_s_txt[0] == '<') and (my_suretu[-1] < v))):
            #print(my_suretu[-1], my_s_txt[0], v)
            new_min_v = func(my_suretu + [v], next_my_s_txt, min_v)
        if (new_min_v < min_v):
            min_v = new_min_v
        elif ((new_min_v == min_v) and (new_min_v != MIN_V)):
            break

    return min_v
        
min_v = MIN_V
for v in range(0, MAX_INT):
    new_min_v = func([v], s_txt, min_v)
    if (new_min_v < min_v):
        min_v = new_min_v
    elif ((new_min_v == min_v) and (new_min_v != MIN_V)):
        break

print(min_v)

Submission status: Runtime Error

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

MAX_INT = 100000
s_txt = input()


def func(my_suretu, my_s_txt):
    #print('func(', my_suretu, my_s_txt, ')')

    if (len(my_s_txt) == 0):
        #print(my_suretu)
        print(sum(my_suretu))
        exit()
    else:
        next_my_s_txt = my_s_txt[1:]

    for v in range(0, MAX_INT):
        if (len(my_suretu)==0):
            func(my_suretu + [v], next_my_s_txt)
        elif (((my_s_txt[0] == '>') and (my_suretu[-1] > v)) or 
            ((my_s_txt[0] == '<') and (my_suretu[-1] < v))):
            #print(my_suretu[-1], my_s_txt[0], v)
            func(my_suretu + [v], next_my_s_txt)
        

for v in range(0, MAX_INT):
    func([v], s_txt)

Submission status: Runtime Error

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

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

Solution code:
a

Submission status: Runtime Error

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
print(S)
print(list)
for i in range(len(S)):
	if S[i] == ">" and S[i+1] == "<":
		list[i+1] = 0
		cnt = 1
	if S[i] == "<":
		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		
print(list)
print(sum(list))