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: Time Limit Exceeded

Solution code:
s = input()
n = len(s) + 1
# max of...
#    * num of sequential '<' on the left side
#    * num of sequential '>' on the right side
def calc_left_num(st):
    num = 0
    length = len(st)
    for index in range(length - 1, -1, -1):
        if st[index] != '<':
            break
        num += 1
    return num
def calc_right_num(st):
    num = 0
    for c in st:
        if c != '>':
            break
        num += 1
    return num
li = list()
for i in range(n):
    left_num = calc_left_num(s[:i])
    right_num = calc_right_num(s[i:])
    if i == 0:
        li.append(right_num)
    elif i == n - 1:
        li.append(left_num)
    else:
        li.append(max([left_num, right_num]))
print(sum(li))

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s) + 1
# max of...
#    * num of sequential '<' on the left side
#    * num of sequential '>' on the right side
li = list()
for i in range(n):
    left_str_rev = s[:i][::-1]
    left_num = left_str_rev.find('>')
    left_num = left_num if left_num >= 0 else len(left_str_rev)
    right_str = s[i:]
    right_num = right_str.find('<')
    right_num = right_num if right_num >= 0 else len(right_str)
    if i == 0:
        li.append(right_num)
    elif i == n - 1:
        li.append(left_num)
    else:
        li.append(max([left_num, right_num]))
print(sum(li))

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
for i in range(len(s) + 1):
    tmp, tmpb = 0, 0
    for j in range(i, len(s)):
        if s[j] == '<':
            break
        tmpb += 1
    
    for j in range(i - 1, -1, -1):
        if s[j] == '>':
            break
        tmp += 1
    ans += max(tmp, tmpb)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
for i in range(len(s) + 1):
    tmp, tmpb = 0, 0
    for j in range(len(s)):
        if i > j:
            if s[j] == '<':
                tmp += 1
            else:
                tmp = 0
        else:
            if s[j] == '>':
                tmpb += 1
            else:
                break
    ans += max(tmp, tmpb)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
a=[0]*(len(s)+1)
for i in range(len(a)):
  j=i
  r=0
  l=0
  while j < len(s) and s[j] == '>':
    r+=1
    j+=1
  j=i
  while 0 < j and s[j-1] == '<':
    l+=1
    j-=1   
  a[i]=max(l,r)
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
S = input()

a = [0] * (len(S) + 1)
S = "*" + S + "*"
for i in range(len(a)):
    left_str = S[:i+1]
    right_str = S[i+1:]

    left_cnt = len(left_str) - len(left_str.rstrip("<"))
    right_cnt = len(right_str) - len(right_str.lstrip(">"))

    a[i] = max(left_cnt, right_cnt)

print(sum(a))

Submission status: Time Limit Exceeded

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

for i in range(0,N) :
  l_cnt=0
  r_cnt=0
  for j in range(i-1,-1,-1):
    #print(j)
    if S[j]=="<":
      l_cnt +=1
    else:
      break
  for k in range(i,N-1):
    #print("k=",k,S[k])
    if S[k]==">":
      r_cnt +=1
    else:
      break
  #print(l_cnt,r_cnt)
  sum += max(l_cnt,r_cnt)
  
print(sum)

Submission status: Time Limit Exceeded

Solution code:
# Problem A - ><

# input
S = input()

# initialization
part_str = []
tmp = S
last_i = 0
for i in range(len(S)-1):
    if S[i]=='>' and S[i+1]=='<':
        part_str.append(S[last_i:i+1])
        last_i = i + 1
        tmp = S[last_i:]
if len(tmp)>=1:
    part_str.append(tmp)

ans = 0

# count
for p in part_str:
    left_count = 0
    right_count = 0
    for c in p:
        if c=='<':
            left_count += 1
        elif c=='>':
            right_count += 1
    tmp_max = max(left_count, right_count)
    if left_count-1>0:
        left_count -= 1
        left_count = (left_count * (1 + left_count)) / 2
    else:
        left_count = 0

    if right_count-1>0:
        right_count -= 1
        right_count = (right_count * (1 + right_count)) / 2
    else:
        right_count = 0
    ans += tmp_max + left_count + right_count

# output
print("%d"%(ans))

Submission status: Time Limit Exceeded

Solution code:
# import bisect
# from collections import Counter, deque # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


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

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

    for i in range(ls):
        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: Time Limit Exceeded

Solution code:
from itertools import groupby
s=list(input())
ans=[0]
for k,v in groupby(s):
  d=len(list(v))
  x= -1 if k==">" else 1 
  ad=list(range(d+1))[::x]
  ans=ans[:-1]+[max(ans[-1],ad[0])]+ad[1:]
print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
L = list(input())
N = [-1 for i in range(len(L)+1)]

def sounyu(L,N):    
    for i in range(len(N)-1):
        if L[i] == '<':
            N[i] = max(N[i],0)
            while(L[i] == '<'):
                N[i+1] = max(N[i+1],N[i]+1)
                i += 1
                if i == len(L):
                    break
def sounyu_aft(L,N):    
    for i in range(len(N)-1):
        if L[i] == '>':
            N[i] = max(N[i],0)
            while(L[i] == '>'):
                N[i+1] = max(N[i+1],N[i]+1)
                i += 1
                if i == len(L):
                    break

sounyu(L,N)
L.reverse()
N.reverse()
sounyu_aft(L,N)

print(sum(N))

Submission status: Time Limit Exceeded

Solution code:
L = list(input())
N = [-1 for i in range(len(L)+1)]

def sounyu(L,N):    
    for i in range(len(N)-1):
        if L[i] == '<':
            N[i] = max(N[i],0)
            while(L[i] == '<'):
                N[i+1] = max(N[i+1],N[i]+1)
                i += 1
                if i == len(L):
                    break

sounyu(L,N)
L.reverse()
for l in range(len(L)):
    if L[l] == '>':
        L[l] = '<'
    else:
        L[l] = '>'
N.reverse()
sounyu(L,N)

print(sum(N))

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
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):
    ans += max(check_left(i, S), check_right(i, S))
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re
from collections import Counter
s = input()
res = re.findall(r"<+>+", s) + re.findall(r"^>+", s) + re.findall(r"<+$", s)

def calc(string):
    ct = Counter(string)
    cnt_d = ct[">"]
    cnt_s = ct["<"]
    if cnt_s > cnt_d:
        return (cnt_s * (cnt_s + 1) + (cnt_d - 1) * cnt_d) // 2
    elif cnt_s == cnt_d:
        return cnt_s * cnt_s
    else:
        return ((cnt_d + 1) * cnt_d + (cnt_s - 1) * cnt_s) // 2
score = 0
for r in res:
    score += calc(r)
print(score)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
for i in range(len(s)+1):
    left = s[0:i]
    right = s[i:]
    l = 0
    r = 0
    for i in range(len(left)-1,-1,-1):
        if left[i] != "<":
            break
        else:
            l += 1
    for i in range(len(right)):
        if right[i] != ">":
            break
        else:
            r += 1
    ans += max(l,r)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
for i in range(len(s)+1):
    left = s[0:i]
    right = s[i:]
    l = 0
    r = 0
    for i in range(len(left)-1,-1,-1):
        if left[i] != "<":
            break
        else:
            l += 1
    for i in range(len(right)):
        if right[i] != ">":
            break
        else:
            r += 1
    ans += max(l,r)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
j = []
k = []
for i in range(len(s)+1):
    left = s[0:i]
    right = s[i:]
    l = 0
    r = 0
    for i in range(len(left)-1,-1,-1):
        if left[i] != "<":
            break
        else:
            l += 1
    for i in range(len(right)):
        if right[i] != ">":
            break
        else:
            r += 1
    j.append(max(l,r))
print(sum(j))

Submission status: Time Limit Exceeded

Solution code:
def left(arr, idx):
    count = 0
    while idx >= 0 and arr[idx] == '<':
        count += 1
        idx -= 1
    return count

def right(arr, idx):
    count = 0
    while idx < len(arr) and arr[idx] == '>':
        count += 1
        idx += 1
    return count

def main():
    S = list(input())
    N = len(S)
    A = [0 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: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""
import numpy as np

glsequence = input()

slopeSequence = np.zeros(1)
lastsymb = glsequence[0]
if lastsymb == '<':
    glsign = 1
else:
    glsign = -1
slopeSequence = np.array([0])
    
for glsymb in glsequence:
    if glsymb != lastsymb:
        glsign = glsign*-1
        slopeSequence = np.append(slopeSequence,[glsign])
        lastsymb = glsymb
    else:
        slopeSequence[-1] += glsign

numSequence = np.zeros([len(glsequence)+1])
firstSlope = slopeSequence[0]
currentIndex = 0
if firstSlope<0:
    numSequence[currentIndex:abs(firstSlope)+1] = np.arange(abs(firstSlope),-1,-1)
    currentIndex = abs(firstSlope)
    
for slopeIndex in range(len(slopeSequence)-1):
    currentSlope = slopeSequence[slopeIndex]
    nextSlope = slopeSequence[slopeIndex+1]
    if nextSlope<0:
        if currentSlope>abs(nextSlope):
            # make the current slope dominate where the two meet
            numSequence[currentIndex:(currentIndex+currentSlope+1)] = np.arange(currentSlope+1)
            numSequence[(currentIndex+currentSlope+1):(currentIndex+currentSlope+abs(nextSlope)+1)] = np.arange(abs(nextSlope)-1,-1,-1)
        else:
            # make the next slope dominate where the two meet
            numSequence[currentIndex:(currentIndex+currentSlope)] = np.arange(currentSlope)
            numSequence[(currentIndex+currentSlope):(currentIndex+currentSlope+abs(nextSlope)+1)] = np.arange(abs(nextSlope),-1,-1)
        currentIndex = currentIndex+currentSlope+abs(nextSlope)

lastSlope = slopeSequence[-1]
if lastSlope>0:
    numSequence[-lastSlope-1:]=np.arange(lastSlope+1)

print(int(np.sum(numSequence)))

Submission status: Time Limit Exceeded

Solution code:
s="o"+input()+"o"
#o<<>>><>>o
ans=0
for i in range(0,len(s)-1):
  g=0
  for j in range(i,-1,-1):
    if s[j]=="<":
      g+=1
    else:
      break
  l=0
  for j in range(i+1,len(s)):
    if s[j]==">":
      l+=1
    else:
      break
  ans+=max(g,l)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
cntu = 0
cntd = 0
ans = 0

while s != "":
  while s != "":
    if s[0] == "<":
      cntu += 1
      s = s[1:]
    else:
      break
  while s != "":
    if s[0] == ">":
      cntd += 1
      s = s[1:]
    else:
      break
  if cntu == 0:
    ans += cntd*(cntd+1)//2
  elif cntd == 0:
    ans += cntu*(cntu+1)//2
  else:
    ans += max(cntu, cntd)*(max(cntu, cntd)+1)//2 + min(cntu, cntd)*(min(cntu, cntd)-1)//2
  cntu = 0
  cntd = 0

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python


def main():
    s = input()
    al, ar = 0, 0
    a = []
    for i in range(len(s) + 1):
        if i < len(s) and s[i] == '>':
            if ar == 0:
                for si in s[i:]:
                    if si == '>':
                        ar = ar + 1
                    else:
                        break
            else:
                ar = ar - 1
        else:
            ar = 0

        if i > 0 and s[i - 1] == '<':
            al = al + 1
        else:
            al = 0

        a.append(max(al, ar))

    print(sum(a))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python


def main():
    s = input()
    a = []
    for i in range(len(s) + 1):
        lefts, rights = (s[:i], s[i:])
        a_cand = [0, 0]
        j = len(lefts) - 1
        while j >= 0 and lefts[j] == '<':
            a_cand[0] = a_cand[0] + 1
            j = j - 1
        j = 0
        while j < len(rights) and rights[j] == '>':
            a_cand[1] = a_cand[1] + 1
            j = j + 1

        a.append(max(a_cand))

    print(sum(a))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
ar = list(input())
total = 0
for i in range(len(ar)+1):
    rc = 0
    lc = 0
    r = ar[i:len(ar)]
    l = ar[0:i][::-1]
    for j in r:
        if j == ">":
            rc += 1
        else:
            break
    for k in l:
        if k == "<":
            lc += 1
        else:
            break
    total += max(rc,lc)
print(total)

Submission status: Time Limit Exceeded

Solution code:
#AGC040A
import sys
s = sys.stdin.readline().rstrip()
n = len(s)
L = [0 for i in range(n+1)]
f = False
while (f==False):
    f = True
    for i in range(n):
        if s[i] =='<' and not L[i+1] >L[i]:
            L[i+1] = L[i]+1
            f = False
        elif s[i] == '>' and not L[i] > L[i+1]:
            L[i] = L[i+1] +1
            f = False
#print(*L)
print(sum(L))

Submission status: Time Limit Exceeded

Solution code:
#AGC040A
import sys
s = sys.stdin.readline().rstrip()
n = len(s)
L = [0 for i in range(n+1)]
f = False
while (f==False):
    f = True
    for i in range(n):
        if s[i] =='<' and not L[i+1] >L[i]:
            L[i+1] = L[i]+1
            f = False
        elif s[i] == '>' and not L[i] > L[i+1]:
            L[i] = L[i+1] +1
            f = False
#print(*L)
print(sum(L))

Submission status: Time Limit Exceeded

Solution code:
def calculate(input):
  il = list(input)
  ilSize = len(il)
  o = [0] * (ilSize + 1)
  for (i, symbol) in enumerate(il):
    ci = i + 1
    if symbol == '<':
      o[ci] = o[ci - 1] + 1
      pass
    for pi in range(i, -1, -1):
      if il[pi] != '>' or o[pi] > o[pi + 1]:
        break
      o[pi] = o[pi + 1] + 1
  print(sum(o))


calculate(input())

Submission status: Time Limit Exceeded

Solution code:
import sys
 
def calculate(input):
  il = list(input)
  ilSize = len(il)
  o = [0] * (ilSize + 1)
  for (i, symbol) in enumerate(il):
    ci = i + 1
    if symbol == '<':
      o[ci] = o[ci - 1] + 1
      pass
    for pi in range(i, -1, -1):
      if il[pi] != '>' or o[pi] > o[pi + 1]:
        break
      o[pi] = o[pi + 1] + 1
  print(sum(o))
 
for input in sys.stdin:
  calculate(input)

Submission status: Time Limit Exceeded

Solution code:
import sys
 
def calculate(input = ''):
  inputList = list(input)
  inputListSize = len(inputList)
  output = [0] * (inputListSize + 1)
  for (index, symbol) in enumerate(inputList):
    currentIndex = index + 1
    if symbol == '>':
      for preIndex in range(index, -1, -1):
        if inputList[preIndex] == '>' and output[preIndex] <= output[preIndex + 1]:
          output[preIndex] = output[preIndex + 1] + 1
        else: break
    elif symbol == '<':
      output[currentIndex] = output[currentIndex - 1] + 1
  print(sum(output))
 
for input in sys.stdin:
  calculate(input)

Submission status: Time Limit Exceeded

Solution code:
import sys

def calculate(input = ''):
  inputList = list(input)
  inputListSize = len(inputList)
  output = [0] * (inputListSize + 1)
  for (index, symbol) in enumerate(inputList):
    currentIndex = index + 1
    if symbol == '>':
      for preIndex in range(index, -1, -1):
        if inputList[preIndex] == '>' and output[preIndex] <= output[preIndex + 1]:
          output[preIndex] = output[preIndex + 1] + 1
        else: break
    elif symbol == '<':
      output[currentIndex] = output[currentIndex - 1] + 1
  print(sum(output))

for input in sys.stdin:
  calculate(input)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Nov  6 23:21:26 2019

@author: matsui
"""
import numpy as np
S=input()

a=np.zeros(len(S)+1)

for i in range(len(a)):
    right=0
    for j in range(i,len(S)):
        if S[j] =='>':
            right+=1
        else:
            break
    left=0
    for j in range(i-1,-1,-1):
        if S[j] =='<':
            left+=1
        else:
            break

    a[i]=np.max([right,left])
'''
V=[]
M=[]
if S[0]=='<':
    V.append(0)
for i in range(1,len(S)):
    if S[i-1]=='>' and S[i]=='<':
        V.append(i)
    if S[i-1]=='<' and S[i]=='>':
        M.append(i)
if S[len(S)-1]=='>':
    V.append(len(a)-1)  
    

if M==[]:
    a[V[0]:-1]=np.arange(len(a)-1-V[0])
    #for i in range(V[0],len(a)-1):
    #    a[i+1]=a[i]+1
else:
    a[V[0]:M[0]]=np.arange(M[0]-V[0])
    #for i in range(V[0],M[0]):
    #    a[i+1]=a[i]+1

if V[0] != 0:
    a[0:V[0]]=np.arange(V[0],0,-1)
    #for i in range(V[0],0,-1):
    #    a[i-1]=a[i]+1
        
    
for j,v in enumerate(V[1:-1]):
    a[v:M[j+1]]=np.arange(M[j+1]-v)
    #for i in range(v,M[j+1]):
    #    a[i+1]=a[i]+1
         
    a[M[j]:v]=np.arange(v-M[j],0,-1)
    #for i in range(v,M[j],-1):
    #    a[i-1]=a[i]+1

if V[-1] != len(a)-1:
    a[V[-1]:]=np.arange(len(a)-V[-1])
    #for i in range(V[-1],len(a)-1):
    #    a[i+1]=a[i]+1
 
if M==[]:
    a[0:V[-1]]=np.arange(V[-1],0,-1)
    #for i in range(V[-1],0,-1):
    #    a[i-1]=a[i]+1
else:
    a[M[-1]:V[-1]]=np.arange(V[-1]-M[-1],0,-1)
    #for i in range(V[-1],M[-1],-1):
    #    a[i-1]=a[i]+1
     
     
for m in M:
    a[m]=np.max([a[m-1],a[m+1]])+1   
'''
#print(a)
print(int(a.sum()))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Nov  6 23:21:26 2019

@author: matsui
"""
import numpy as np
S=input()

a=np.zeros(len(S)+1)
V=[]
M=[]
if S[0]=='<':
    V.append(0)
for i in range(1,len(S)):
    if S[i-1]=='>' and S[i]=='<':
        V.append(i)
    if S[i-1]=='<' and S[i]=='>':
        M.append(i)
if S[len(S)-1]=='>':
    V.append(len(a)-1)  
    

if M==[]:
    a[V[0]:-1]=np.arange(len(a)-1-V[0])
    #for i in range(V[0],len(a)-1):
    #    a[i+1]=a[i]+1
else:
    a[V[0]:M[0]]=np.arange(M[0]-V[0])
    #for i in range(V[0],M[0]):
    #    a[i+1]=a[i]+1

if V[0] != 0:
    a[0:V[0]]=np.arange(V[0],0,-1)
    #for i in range(V[0],0,-1):
    #    a[i-1]=a[i]+1
        
    
for j,v in enumerate(V[1:-1]):
    a[v:M[j+1]]=np.arange(M[j+1]-v)
    #for i in range(v,M[j+1]):
    #    a[i+1]=a[i]+1
         
    a[M[j]:v]=np.arange(v-M[j],0,-1)
    #for i in range(v,M[j],-1):
    #    a[i-1]=a[i]+1

if V[-1] != len(a)-1:
    a[V[-1]:]=np.arange(len(a)-V[-1])
    #for i in range(V[-1],len(a)-1):
    #    a[i+1]=a[i]+1
 
if M==[]:
    a[0:V[-1]]=np.arange(V[-1],0,-1)
    #for i in range(V[-1],0,-1):
    #    a[i-1]=a[i]+1
else:
    a[M[-1]:V[-1]]=np.arange(V[-1]-M[-1],0,-1)
    #for i in range(V[-1],M[-1],-1):
    #    a[i-1]=a[i]+1
     
     
for m in M:
    a[m]=np.max([a[m-1],a[m+1]])+1   

#print(a)
print(int(a.sum()))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Nov  6 23:21:26 2019

@author: matsui
"""
import numpy as np
S=input()

a=[0]*(len(S)+1)
V=[]
M=[]
if S[0]=='<':
    V.append(0)
for i in range(1,len(S)):
    if S[i-1]=='>' and S[i]=='<':
        V.append(i)
    if S[i-1]=='<' and S[i]=='>':
        M.append(i)
if S[len(S)-1]=='>':
    V.append(len(a)-1)  
    

if M==[]:
    for i in range(V[0],len(a)-1):
        a[i+1]=a[i]+1
else:
    for i in range(V[0],M[0]):
        a[i+1]=a[i]+1

if V[0] != 0:
    for i in range(V[0],0,-1):
        a[i-1]=a[i]+1
        
    
for j,v in enumerate(V[1:-1]):
    for i in range(v,M[j+1]):
        a[i+1]=a[i]+1
         
    for i in range(v,M[j],-1):
        a[i-1]=a[i]+1

if V[-1] != len(a)-1:
    for i in range(V[-1],len(a)-1):
        a[i+1]=a[i]+1
 
if M==[]:
    for i in range(V[-1],0,-1):
        a[i-1]=a[i]+1
else:
    for i in range(V[-1],M[-1],-1):
        a[i-1]=a[i]+1
     
     
for m in M:
    a[m]=np.max([a[m-1],a[m+1]])+1   

#print(a)
print(np.sum(a))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Nov  6 23:21:26 2019

@author: matsui
"""
import numpy as np
S=input()

a=[0]*(len(S)+1)
V=[]
M=[]
if S[0]=='<':
    V.append(0)
for i in range(1,len(S)):
    if S[i-1]=='>' and S[i]=='<':
        V.append(i)
    if S[i-1]=='<' and S[i]=='>':
        M.append(i)
if S[len(S)-1]=='>':
    V.append(len(a)-1)  
    
   
for v in V:
    i=v+1
    while(1):
        if i==len(S): 
            a[i]=a[i-1]+1
            break
        if i>len(S): 
            break
        if S[i]=='<':
            a[i]=a[i-1]+1
            i+=1
        else:
            break
        
    i=v-1
    while(1):
        if i==0: 
            a[i]=a[i+1]+1
            break
        if i<0: 
            break
        if S[i-1]=='>':
            a[i]=a[i+1]+1
            i-=1
        else:
            break
for m in M:
    a[m]=np.max([a[m-1],a[m+1]])+1   

print(np.sum(a))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Nov  6 23:21:26 2019

@author: matsui
"""
import numpy as np
S=input()

a=[0]*(len(S)+1)
V=[]
if S[0]=='<':
    V.append(0)
for i in range(1,len(S)):
    if S[i-1]=='>' and S[i]=='<':
        V.append(i)
if S[len(S)-1]=='>':
    V.append(len(a)-1)  
    
M=[]
for i in range(1,len(S)):
    if S[i-1]=='<' and S[i]=='>':
        M.append(i)
    
for v in V:
    i=v+1
    while(1):
        if i==len(S): 
            a[i]=a[i-1]+1
            break
        if i>len(S): 
            break
        if S[i]=='<':
            a[i]=a[i-1]+1
            i+=1
        else:
            break
        
    i=v-1
    while(1):
        if i==0: 
            a[i]=a[i+1]+1
            break
        if i<0: 
            break
        if S[i-1]=='>':
            a[i]=a[i+1]+1
            i-=1
        else:
            break
for m in M:
    a[m]=np.max([a[m-1],a[m+1]])+1   

print(np.sum(a))

Submission status: Time Limit Exceeded

Solution code:
string=list(input())
N=len(string)
num=[0]*(N+1)
sum0=0
if string==[">"]:
     sum0=1
else:
     for i in range(N):
          if string[i]=="<":
               num[i+1]=num[i]+1
          else:
               if num[i]==0:
                    num[i+1]=0
                    for j in range(N):
                         num[i-j]+=1
                         if ((i-j-2)<0 or string[i-j-2]=="<"):
                              if num[i-j-1]<=num[i-j]:
                                   num[i-j-1]=num[i-j]+1
                              break
     sum0=0
     for i in range(N+1):
          sum0=sum0+num[i]
print(sum0)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s) + 1
lft = 0
rgt = 0
l = []
for i in range(n):
    for j in reversed(range(i)):
        if s[j] == '<':
            lft += 1
        else:
            break
    for j in range(i, n-1):
        if s[j] == '>':
            rgt += 1
        else:
            break
    l.append(max(lft, rgt))
    lft = 0
    rgt = 0
print(sum(l))

Submission status: Time Limit Exceeded

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

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

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

ans = 0
for i in range(len(al)):
    if al[i] >= ar[::-1][i]:
        ans += al[i]
    else:
        ans += ar[::-1][i]

print(ans)

Submission status: Time Limit Exceeded

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

isGood = False
while not isGood:
  survey = True
  for i in range(n-1):
    if s[i] == '<':
      if a[i] >= a[i+1]:
        a[i+1] = a[i+1]+1
        survey = False
    else:
      if a[i] <= a[i+1]:
        a[i] = a[i]+1
        survey = False
  isGood = survey

print(sum(a))

Submission status: Time Limit Exceeded

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

def uptop(a):
  index = len(a) -1
  while index >= 0 and a[index] == a[index-1]-1:
    a[index] += 1
    index -= 1
  a[index] += 1

if S[0] == '<':
  a = [0,1]
else:
  a = [1,0]

for i in range(1,N-1):
  # print(a)
  if S[i] == '>':
    if a[i] == 0:
      uptop(a)
    a.append(min(a[i] - 1,0))
  else:
    a.append(a[i] + 1)

print(sum(a))

Submission status: Time Limit Exceeded

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

def uptop(a):
  b = [a[i] for i in range(len(a))]
  index = len(a) -1
  while index >= 0 and a[index] == a[index-1]-1:
    b[index] += 1
    index -= 1
  b[index] += 1
  return b

if S[0] == '<':
  a = [0,1]
else:
  a = [1,0]

for i in range(1,N-1):
  # print(a)
  if S[i] == '>':
    if a[i] == 0:
      a = uptop(a)
    a.append(min(a[i] - 1,0))
  else:
    a.append(a[i] + 1)

print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
s= str(input())
n = len(s) + 1
a = []
for j in range(n):
    a.append(0)
 
for i in range(n):
    ma1 = 0
    ma2 = 0
    for k in range(i-1, -1, -1):
        if s[k] == "<" :
            ma1 += 1
        else:
            break
    for l in range(i, n-1):
         if s[l] == ">" :
            ma2 += 1
         else:
            break
    a[i] = max(ma1, ma2)
            

print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
def binSearch(N, A, key):
    left = 0
    right = N - 1
    memo = [-1 for _ in range(N)]
    k = (left + right) // 2
    while True:
        if memo[k] == -1:
            memo[k] = 1 if key(A[k]) else 0
        if memo[k] == 1:
            right = k
        else:
            left = k
        _k = (left + right) // 2
        if _k == k:
            if memo[left] == -1:
                memo[left] = key(A[left])
            if memo[right] == -1:
                memo[right] = key(A[right])
            if memo[right] == 0 or memo[left] == 1:
                return -1
            else:
                return right
        else:
            k = _k


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


def calc(S):
    t = []
    i = S.find('><')
    while i != -1:
        t += [S[:i + 1]]
        S = S[i + 1:]
        i = S.find('><')
    t += [S]
    result = 0
    for u in t:
        nu = len(u)
        l = binSearch(nu, u, lambda c: c == '>')
        if l != -1:
            result += trisum(max(l, nu - l)) + trisum(min(l, nu - l) - 1)
        else:
            result += trisum(nu)
    return result


S = input()
print(calc(S))

Submission status: Time Limit Exceeded

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


def calc(S):
    t = []
    i = S.find('><')
    while i != -1:
        t += [S[:i + 1]]
        S = S[i + 1:]
        i = S.find('><')
    t += [S]
    result = 0
    for u in t:
        nu = len(u)
        l = 0
        for j in range(nu):
            if u[j] == '>':
                break
            l += 1
        result += trisum(max(l, nu - l)) + trisum(min(l, nu - l) - 1)
    return result


S = input()
print(calc(S))

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    S = list(input())
    N = len(S) + 1
    a = []
    for i in range(N):
        a.append(calc(i, S))
    
    print(sum(a))

def calc(i, S):
    if i == 0:
        if S[i] == '<':
            return 0
        else:
            j = 0
            while j < len(S) and S[j] == '>':
                j += 1
            return j
    elif i == len(S):
        if S[i - 1] == '>':
            return 0
        else:
            j = 0
            while j < len(S) and S[i - 1 - j] == '<':
                j += 1
            return j
    else:
        j = 0
        while j < i and S[i - 1 - j] == '<':
            j += 1
        k = 0
        while (i + k) < len(S) and S[i + k] == '>':
            k += 1
        return max(j, k)

main()

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    S = list(input())
    a = []
    for i in range(0, len(S) + 1):
        a.append(calc(i, S))
    
    total = 0
    for i in range(0, len(a)):
        total += a[i]
    
    print(total)

def calc(i, S):
    if i == 0:
        if S[i] == '<':
            return 0
        else:
            j = 0
            while j < len(S) and S[j] == '>':
                j += 1
            return j
    elif i == len(S):
        if S[i - 1] == '>':
            return 0
        else:
            j = 0
            while j < len(S) and S[i - 1 - j] == '<':
                j += 1
            return j
    else:
        j = 0
        while j < i and S[i - 1 - j] == '<':
            j += 1
        k = 0
        while (i + k) < len(S) and S[i + k] == '>':
            k += 1
        return max(j, k)

main()

Submission status: Time Limit Exceeded

Solution code:
def solve():
    s = input()
    ans = 0
    
    for i in range(len(s)+1):
        left = 0
        right = 0
        for j in range(i-1, -1, -1):
            if s[j] == '<':
                left += 1
            else:
                break
        for j in range(i, len(s)):
            if s[j] == '>':
                right += 1
            else:
                break
        ans += max(left, right)
    
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

S = list(input())
l = len(S) + 1
A = np.zeros(l, dtype=np.int16)
B = np.zeros(l, dtype=np.int16)

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] == '>':
        B[i] = B[i+1] + 1
answer = (np.maximum(A, B)).sum()
print(answer)