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:
zeroone = list(input())

cnt = [0]
for i in range(len(zeroone)-1):
    if zeroone[i+1] != zeroone[i]:
        cnt.append(i+1)
cnt.append(len(zeroone))

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

if zeroone[0] == "<":
    for j in range(0, cnt[1]):
            ans[j+1] = ans[j] + 1

for i in range(len(zeroone)-1):
    if zeroone[i+1] == "<" and zeroone[i] == ">":
        ans[i+1] = 0
        for j in range(i+1, cnt[cnt.index(i+1) + 1]):
            ans[j+1] = ans[j] + 1

        for k in range(cnt[cnt.index(i+1) - 1], i+1)[::-1]:
            ans[k] = max(ans[k+1] + 1, ans[k])

if zeroone[-1] == ">":
    for k in range(cnt[-2], cnt[-1])[::-1]:
            ans[k] = max(ans[k+1] + 1, ans[k])

print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
zeroone = []
for i in range(len(S)):
    if S[i] == "<":
        zeroone.append(1)
    else:
        zeroone.append(-1)

cnt = [0]
for i in range(len(zeroone)-1):
    if zeroone[i+1] != zeroone[i]:
        cnt.append(i+1)
cnt.append(len(zeroone))

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

if zeroone[0] == 1:
    for j in range(0, cnt[1]):
            ans[j+1] = ans[j] + 1

for i in range(len(zeroone)-1):
    if zeroone[i+1] - zeroone[i] > 0:
        ans[i+1] = 0
        for j in range(i+1, cnt[cnt.index(i+1) + 1]):
            ans[j+1] = ans[j] + 1
        
        for k in range(cnt[cnt.index(i+1) - 1], i+1)[::-1]:
            ans[k] = max(ans[k+1] + 1, ans[k])

if zeroone[-1] == -1:
    for k in range(cnt[-2], cnt[-1])[::-1]:
            ans[k] = max(ans[k+1] + 1, ans[k])

print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
S = input()
str_list = list(S)
count = 0
d = list()
dict = {}
dict[0] = 0
for c, i in enumerate(str_list,1):
    if i == '<':
        count += 1
        dict[c] = count
        if str_list[c-2] == '>':
            d.append(dict[c-1])
    else:
        count -= 1
        dict[c] = count

if len(d) != 0:
    for i in range(len(dict)):
        dict[i] -= max(d)

while(min(dict.values())<0):
    min_v = abs(min(dict.values()))
    min_k = min(dict, key=dict.get)
    for i in range(min_k,len(dict)):
        dict[i] += min_v
        if min_k == len(dict)-1:
            break
        elif dict[i] - min_v > dict[i+1]:
            break
        elif dict[i+1] > dict[i] and dict[i+1] > dict[i] - min_v:
            break
        elif dict[i+1] < dict[i] and dict[i+1] < dict[i]-min_v:
            break

    for i in range(min_k,-1,-1):
        if i != min_k:
            dict[i] += min_v
        if i == 0:
            break
        elif dict[i] - min_v > dict[i-1]:
            break
        elif dict[i-1] > dict[i] and dict[i-1] > dict[i] - min_v:
            break
        elif dict[i-1] < dict[i] and dict[i-1] < dict[i]-min_v:
            break
print(sum(dict.values()))

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np

S = list(input())
N = len(S)+1
if N%2==0:
    D = np.zeros(N)
else:
    D = np.zeros(N-1)
   
nc = 1
cur = S[0]
curi = 0
for i in range(1,N-1):
    if S[i]==cur:
        nc += 1
    else:
        D[curi] = nc
        cur = S[i]
        curi += 1
        nc = 1
D[curi] = nc
D=D.reshape([-1,2])
Asum = 0
for d in D:
    if d.all == 0:
        break
    else:
        a1 = max(np.absolute(d))
        a2 = min(np.absolute(d))
        Asum += int((a1+1)*a1/2 + a2*(a2-1)/2)

print(Asum)

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np

S = list(input())
N = len(S)+1
if N%2==0:
    D = np.zeros(N)
else:
    D = np.zeros(N-1)
   
nc = 1
cur = S[0]
curi = 0
for i in range(1,N-1):
    if S[i]==cur:
        nc += 1
    else:
        D[curi] = nc
        cur = S[i]
        curi += 1
        nc = 1
D[curi] = nc
D=D.reshape([-1,2])
Asum = 0
for d in D:
    if d.all == 0:
        break
    else:
        a1 = max(np.absolute(d))
        a2 = min(np.absolute(d))
        Asum += int(np.sum(np.arange(0,a1+1)) + np.sum(np.arange(0,a2)))

print(Asum)

Submission status: Time Limit Exceeded

Solution code:

import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions
from operator import itemgetter

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


S = input()

N = len(S) + 1

min_list = deque()
max_list = []
num = [-1]*N
if S[0] == "<":
	min_list.append(1)
	num[0] = 0
if S[-1] == ">":
	min_list.append(N - 2)
	num[N - 1] = 0
for i in range(1, N - 1):
	if S[i - 1] == ">" and S[i] == "<":
		min_list.append(i - 1)
		min_list.append(i + 1)
		num[i] = 0
	if S[i - 1] == "<" and S[i] == ">":
		max_list.append(i)

max_set = set(max_list)

while len(min_list) > 0:
	x = min_list.popleft()
	if x == 0:
		num[x] = num[x + 1] + 1
	elif x == N - 1:
		num[x] = num[x - 1] + 1
	elif not x in max_list:
		num[x] = max(num[x - 1], num[x + 1]) + 1
		if num[x - 1] == -1:
			min_list.append(x - 1)
		if num[x + 1] == -1:
			min_list.append(x + 1)

for x in max_list:
	num[x] = max(num[x - 1], num[x + 1]) + 1

print(sum(num))

Submission status: Time Limit Exceeded

Solution code:
s = input()

n = len(s) + 1
ans = 0
# for i in range(n - 1):
i = 0
while i < n - 1:
    uCount = 0 # '<'
    dCount = 0 # '>'
    while s[i] == '<' and i < n - 1:
        uCount += 1
        if i == n - 2:
            break
        i += 1
    while s[i] == '>' and i < n - 1:
        dCount += 1
        if i == n - 2:
            i += 1
            break
        i += 1
    if uCount > dCount:
        ans += sum(range(0, uCount + 1))
        ans += sum(range(0, dCount))
    elif uCount <= dCount:
        ans += sum(range(0, dCount + 1))
        ans += sum(range(0, uCount))
    # if i == n - 2 and s[i] == '<':
    #     ans += 1
    #     i += 1
    # elif i == n - 2 and s[i] == '>':
    #     i += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys

#count '<'
def count_S(S, N):
    ret=S.find('>')
    #print("<",S,N,ret)
    if ret==-1:
        ret=N
    return ret

#count '>'
def count_L(S, N):
    ret=S.find('<')
    if ret==-1:
        ret=N
    #print(">",S,N,ret)
    return ret

def count_L_slow(S, N):
    ret=0
    for i in range(N):
        if S[i:i+1]=='>':
            ret+=1
        else:
            break
    return ret

def solve(S: str):
    answer=0

    cnt_l=count_L(S,len(S))
    answer+=int((cnt_l+1)*cnt_l/2)
    i=cnt_l
    while i<len(S):
        cnt_s=count_S(S[i:],len(S[i:]))
        cnt_l=count_L(S[i+cnt_s:],len(S[i+cnt_s:]))
        answer+=int((cnt_s+1)*cnt_s/2)
        answer+=int((cnt_l+1)*cnt_l/2)
        if cnt_l>cnt_s:
           answer-=cnt_s
        else:
           answer-=cnt_l
        #answer+=(cnt_l+1)*cnt_l//2
        #print("cnt_s,cnt_l",cnt_s, cnt_l,answer)
        i+=cnt_s+cnt_l

    print(answer)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
r = len(s)
o = [0 for i in range(r+1)]

for i in range(r):
  
  r2 = r-i
  
  b = ""
  for j in range(r2):
    b = b + "<"
  while b in s:
    k = s.find(b)
    if r2 > o[k+r2]:
      o[k+r2]=r2
    s = list(s)
    s[k+r2-1]="x"
    s = "".join(s)
  
  b = ""
  for j in range(r2):
    b = b + ">"
  while b in s:
    k = s.find(b)
    if r-i > o[k]:
      o[k]=r2
    s = list(s)
    s[k]="x"
    s = "".join(s)

print(sum(o))

Submission status: Time Limit Exceeded

Solution code:
import sys

inp = sys.stdin.readline()[:-1]
N = len(inp) - 1

from_left = []
from_right = []
less_row = 0
more_row = 0
for i, c in enumerate(inp):
    if c == "<":
        less_row += 1
    else:
        if less_row:
            from_left.append((less_row, less_row * (less_row + 1) // 2))
        less_row = 0

    r_i = N - i
    if inp[r_i] == ">":
        more_row += 1
    else:
        if more_row:
            from_right.insert(0, (more_row, more_row * (more_row + 1) // 2))
        more_row = 0

if less_row:
    from_left.append((less_row, less_row * (less_row + 1) // 2))
if more_row:
    from_right.insert(0, (more_row, more_row * (more_row + 1) // 2))

ans = 0
if inp[-1] == "<":
    ans += from_left.pop()[1]
if inp[0] == ">":
    ans += from_right.pop(0)[1]


def big_boy(it):
    r_last, r_tri = from_right[it[0]]
    return it[1][1] + r_tri - min(it[1][0], r_last)


print(ans + sum(map(big_boy, enumerate(from_left))))

Submission status: Time Limit Exceeded

Solution code:
s = input()
o = [0 for i in range(len(s)+1)]
b = "";
k = 0;

for i in range(len(s)):
  
  b = ""
  for j in range(len(s)-i):
    b = b + "<"
  while b in s:
    k = s.find(b)
    if len(s)-i > o[k+len(s)-i]:
      o[k+len(s)-i]=len(s)-i
    s = list(s)
    s[k+len(s)-i-1]="x"
    s = "".join(s)
  
  b = ""
  for j in range(len(s)-i):
    b = b + ">"
  while b in s:
    k = s.find(b)
    if len(s)-i > o[k]:
      o[k]=len(s)-i
    s = list(s)
    s[k]="x"
    s = "".join(s)

print(sum(o))

Submission status: Time Limit Exceeded

Solution code:
s = input()

index = 0
thanS = s[0]
count = 1
a = []
for i in range(1, len(s)):
    if thanS == s[i]:
        count += 1

    else:
        a.append(s[index: index + count])
        thanS = s[i]
        index = index + count
        count = 1

a.append(s[index:])
b = [0]

for i in range(len(a)):
    diff = len(a[i])
    if a[i][0] == "<":
        add = [b[-1] + 1 + j for j in range(diff)]
    else:
        if b[-1] < diff:
            b[-1] = diff
        add = [diff - j for j in range(1, diff + 1)]
    b = b + add

print(sum(b))

Submission status: Time Limit Exceeded

Solution code:
s = input()
tmp = [0]
tmpsc = 1
for i in range(len(s)):
    if s[i] == '<':
        tmp.append(tmp[i] + 1)
        tmpsc = 0
    else:
        tmpsc += 1
        if tmp[i] - 1 < 0:
            tmp.append(0)
            for j in range(tmpsc):
                if tmp[i - j] == tmp[i - j + 1]:
                    tmp[i - j] += 1
                else:
                    break
        else:
            tmp.append(0)
print(sum(tmp))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys

#count '<'
def count_S(S, N):
    ret=S.find('>')
    #print("<",S,N,ret)
    if ret==-1:
        ret=N
    return ret

#count '>'
def count_L(S, N):
    ret=S.find('<')
    if ret==-1:
        ret=N
    #print(">",S,N,ret)
    return ret

def count_L_slow(S, N):
    ret=0
    for i in range(N):
        if S[i:i+1]=='>':
            ret+=1
        else:
            break
    return ret

def solve(S: str):
    answer=0
    
    i=0
    old_s=old_l=0
    while i<len(S):
        cnt_s=count_S(S[i:],len(S[i:]))
        cnt_l=count_L(S[i:],len(S[i:]))
        answer+=(cnt_s+1)*cnt_s//2
        if cnt_s==0:
            if cnt_l>old_s:
               answer-=old_s
            else:
               answer-=cnt_l
        answer+=(cnt_l+1)*cnt_l//2
        #print("cnt_s,cnt_l",cnt_s, cnt_l,answer)
        old_s=cnt_s
        old_l=cnt_l
        i+=cnt_s+cnt_l

    print(answer)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
tmp = [0]
tmpsc = 1
tmpsum = 0
for i in range(len(s)):
    #print(tmp)
    if s[i] == '<':
        tmp.append(tmp[i] + 1)
        tmpsc = 0
    else:
        tmpsc += 1
        if tmp[i] - 1 < 0:
            # print(tmp)
            tmp.append(0)
            for j in range(tmpsc):
                if tmp[i - j] == tmp[i - j + 1]:
                    tmp[i - j] += 1
                    # print(i-j)
        else:
            tmp.append(0)
            #tmpsc += 1
#print(tmp)
print(sum(tmp))

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

index = 0
thanS = s[0]
count = 1
a = []
for i in range(1, len(s)):
    if thanS == s[i]:
        count += 1

    else:
        a.extend([s[index: index + count]])
        thanS = s[i]
        index = index + count
        count = 1

a.extend([s[index:]])
b = [0]

for i in range(len(a)):
    diff = len(a[i])
    if a[i][0] == "<":
        add = [b[-1] + 1 + j for j in range(diff)]
    else:
        if b[-1] <= diff:
            b[-1] = diff
        add = [diff - j for j in range(1, diff + 1)]
    b = b + add

print(sum(b))

Submission status: Time Limit Exceeded

Solution code:
# import numpy as np

def main():
    s = input()
    # s = '<>>><<><<<<<>>><'
    n_list = [0] * (len(s)+1)
    # n_list = np.zeros(len(s)+1)

    for i in range(0, len(s)):
        if s[i] == '<':
            n_list[i+1] = n_list[i]+1
        else: # i = >
            j = i # jは左側の                           文字のインデックス
            k = 1                          
            for j in range(i, 0, -1):
                if s[j] == '<':
                    n_list[j+1] = max(n_list[j], n_list[j+2])+1
                    break
                n_list[j] = k                
                j-=1
                k+=1
        if s[0] == '>':
            n_list[0] = n_list[1]+1
        # print('i={} {}'.format(i, n_list))    

    # print(n_list)
    print(int(sum(n_list)))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import operator
def compare(a, relate, b):
    ops = {'>': operator.gt,
           '<': operator.lt}
    return ops[relate](a, b)

def dfs(a, S):
  is_cor = True
  for i, s in enumerate(S):
    #if i == len(S):
    #  break
    if s == "<" and (compare(a[i], s, a[i + 1]) is False):
        is_cor = False
        a[i + 1] += 1
        break
    elif s == ">" and (compare(a[i], s, a[i + 1]) is False):
        is_cor = False
        a[i] += 1
        break
  return is_cor
  
S = input()
a = []
for _ in range(len(S) + 1):
  a.append(0)
while (dfs(a, S) is False):
  continue
#print(a)
s = 0
for e in a:
  s += e
print(s)

Submission status: Time Limit Exceeded

Solution code:
import operator
def compare(a, relate, b):
    ops = {'>': operator.gt,
           '<': operator.lt}
    return ops[relate](a, b)

def dfs(a, S):
  is_cor = True
  for i, s in enumerate(S):
    #if i == len(S):
    #  break
    if s == "<" and (compare(a[i], s, a[i + 1]) is False):
        is_cor = False
        a[i + 1] += 1
        continue
    elif s == ">" and (compare(a[i], s, a[i + 1]) is False):
        is_cor = False
        a[i] += 1
        continue
  return is_cor
  
S = input()
a = []
for _ in range(len(S) + 1):
  a.append(0)
while (dfs(a, S) is False):
  continue
#print(a)
s = 0
for e in a:
  s += e
print(s)

Submission status: Time Limit Exceeded

Solution code:
s= str(input())
n = len(s) + 1
a = []
for j in range(n):
    a.append(0)
 
i = 0
count = 1
while i<n-1:
    if s[i] == "<" and a[i] >= a[i+1]:
        a[i+1] = a[i] + 1
        i += 1
    elif s[i] == ">" and a[i] <= a[i+1]:
        a[i] = a[i+1] + 1
        if i > 0:
            i -= 1
            count += 1
        else:
            i += count
            count = 1
    else:
        i +=1
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
import copy

s = list(input())
s2 = copy.deepcopy(s)

thanS = s[0]
count = 1
a = []
for i in range(1, len(s)):
    if thanS == s[i]:
        count += 1

    else:
        thanS = s[i]
        if count == 1:
            a.append(s2[0: 1])
            del s2[0: 1]
        else:
            a.append(s2[0: count])
            del s2[0:count]
        count = 1

a.append(s2)
del s2
b = [0]

for i in range(len(a)):
    c = a[i]

    if c[0] == "<":
        add = [b[-1] + 1 + j for j in range(len(c))]
        b = b + add
    else:
        diff = len(c)
        if b[-1] <= diff:
            b[-1] = diff
            b = b + [diff - j for j in range(1, diff + 1)]
        else:
            b = b + [diff - j for j in range(1, diff + 1)]

print(sum(b))

Submission status: Time Limit Exceeded

Solution code:
import operator
def compare(a, relate, b):
    ops = {'>': operator.gt,
           '<': operator.lt}
    return ops[relate](a, b)

def dfs(a, S):
  is_cor = True
  for i, s in enumerate(S):
    #if i == len(S):
    #  break
    if s == "<" and (compare(a[i], s, a[i + 1]) is False):
        is_cor = False
        a[i + 1] += 1
        continue
    elif s == ">" and (compare(a[i], s, a[i + 1]) is False):
        is_cor = False
        a[i] += 1
        continue
  return is_cor
  
S = input()
a = []
for _ in range(len(S) + 1):
  a.append(0)
while (dfs(a, S) is False):
  dfs(a, S)
#print(a)
s = 0
for e in a:
  s += e
print(s)

Submission status: Time Limit Exceeded

Solution code:
import operator
def compare(a, relate, b):
    ops = {'>': operator.gt,
           '<': operator.lt}
    return ops[relate](a, b)

def dfs(a, S):
  #print("debug")
  is_cor = True
  for i, s in enumerate(S):
    #if i == len(S):
    #  break
    if s == "<":
      while (compare(a[i], s, a[i + 1]) is False):
        is_cor = False
        a[i + 1] += 1
        break
    elif s == ">":
      while (compare(a[i], s, a[i + 1]) is False):
        is_cor = False
        a[i] += 1
        break
  return is_cor
  
S = input()
a = []
for _ in range(len(S) + 1):
  a.append(0)
while (dfs(a, S) is False):
  dfs(a, S)
#print(a)
s = 0
for e in a:
  s += e
print(s)

Submission status: Time Limit Exceeded

Solution code:
import operator
def compare(a, relate, b):
    ops = {'>': operator.gt,
           '<': operator.lt}
    return ops[relate](a, b)

def dfs(a, S):
  #print("debug")
  is_cor = True
  for i, s in enumerate(S):
    #if i == len(S):
    #  break
    if s == "<":
      while (compare(a[i], s, a[i + 1]) is False):
        is_cor = False
        a[i + 1] += 1
    elif s == ">":
      while (compare(a[i], s, a[i + 1]) is False):
        is_cor = False
        a[i] += 1
  return is_cor
  
S = input()
a = []
for _ in range(len(S) + 1):
  a.append(0)
while (dfs(a, S) is False):
  dfs(a, S)
#print(a)
s = 0
for e in a:
  s += e
print(s)

Submission status: Time Limit Exceeded

Solution code:
s= str(input())
n = len(s) + 1
a = []
for j in range(n):
    a.append(0)
 
i = 0
count = 1
while i<n-1:
    if s[i] == "<" and a[i] >= a[i+1]:
        a[i+1] = a[i] + 1
        i += 1
    elif s[i] == ">" and a[i] <= a[i+1]:
        a[i] = a[i+1] + 1
        if i > 0:
            i -= 1
        else:
            i += count
            count = 1
    else:
        i +=1
print(sum(a))

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)+1
array = [0]*(N)
k = 0
for i in range(N-1):
  if S[i] == "<":
    array[i+1] = array[i] + 1
    k = i+1
  else:
    for j in reversed(range(k,i+1)):
      if array[j]<=array[j+1]:
        array[j] += 1
#print(array)
print(sum(array))

Submission status: Time Limit Exceeded

Solution code:
S = input()
S_length = len(S)
k = 1
s_l=[]
while S!='':
  s_x=S[0]
  if len(S)>=2:
    if S[1]==s_x:
      k+=1
      S=S[1:]
    else:
      s_l.append(s_x*k)
      k=1
      S=S[1:]
  else:
    s_l.append(s_x*k)
    S=S[1:]



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

s_l_length = len(s_l)
answer=0
if s_l[0][0]=='<':
  if s_l_length%2==0:
    for i in range(0,s_l_length,2):
      s_1=s_l[i]
      s_2=s_l[i+1]
      s_1_l=len(s_1)
      s_2_l=len(s_2)
      if s_1_l<=s_2_l:
        answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
      else:
        answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
  else:
    for i in range(0,s_l_length,2):
      if i==s_l_length-1:
        answer+=n_sum(len(s_l[i]))
      else:
        s_1=s_l[i]
        s_2=s_l[i+1]
        s_1_l=len(s_1)
        s_2_l=len(s_2)
        if s_1_l<=s_2_l:
          answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
        else:
          answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
          
else:
  answer+=n_sum(len(s_l.pop(0)))
  s_l_length-=1
  if s_l_length%2==0:
    for i in range(0,s_l_length,2):
      s_1=s_l[i]
      s_2=s_l[i+1]
      s_1_l=len(s_1)
      s_2_l=len(s_2)
      if s_1_l<=s_2_l:
        answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
      else:
        answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
  else:
    for i in range(0,s_l_length,2):
      if i==s_l_length-1:
        answer+=n_sum(len(s_l[i]))
      else:
        s_1=s_l[i]
        s_2=s_l[i+1]
        s_1_l=len(s_1)
        s_2_l=len(s_2)
        if s_1_l<=s_2_l:
          answer+=n_sum(s_1_l-1)+n_sum(s_2_l)
        else:
          answer+=n_sum(s_1_l)+n_sum(s_2_l-1)
  
      
print(answer)

Submission status: Time Limit Exceeded

Solution code:
s=str(input())
n=len(s)
i=0
ans=0
c=0
d=0
while i < n:
	if s[i] == "<":
		c=c+1
		ans=ans+c
	else:
		j=1
		while (i >= j) and (s[i-j] == ">"):
			j=j+1
		if j > 1:
			if d >= j:
				ans=ans+j-1
			else:
				ans=ans+j
		elif i == 0:
			ans=1
		else:
			d=c
		c=0
	i=i+1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from operator import itemgetter
input = sys.stdin.readline

_s = input()


def chker(s):
    slist = []
    i = 1
    while len(s) >= i:
        if s[i - 1:i + 1] == '><':
            slist.append(s[:i])
            s = s[i:]
            i = 1
        else:
            i += 1

    slist.append(s)

    minisum = 0
    for item in slist:
        l, r = item.count('<'), item.count('>')
        l, r = (l, r) if l > r else (r, l)
        minisum += l * (l + 1) / 2 + r * (r - 1) / 2

    print(int(minisum))


chker(_s)

Submission status: Time Limit Exceeded

Solution code:
import sys
from operator import itemgetter
input = sys.stdin.readline

_s = input()


def chker(s):
    slist = []
    i = 1
    while len(s) >= i:
        if s[i - 1:i + 1] == '><':
            slist.append(s[:i])
            s = s[i:]
            i = 1
        else:
            i += 1

    slist.append(s)

    minisum = 0
    for item in slist:
        l, r = item.count('<'), item.count('>')
        l, r = (l, r) if l > r else (r, l)
        minisum += sum([num for num in range(l + 1)]) + sum([num for num in range(r)])

    print(minisum)


chker(_s)

Submission status: Time Limit Exceeded

Solution code:
import sys

iter_num = 5 * (10**5) + 10
sys.setrecursionlimit(iter_num)

s = input()
n = len(s) + 1

a = [0 for _ in range(n)]
next_num=0

def solve(num):
	global next_num
	if num == 0:
		if s[0] == '<':
			a[num] = 0
			next_num = 1
			return 0
		else:
			next_num = 1
			a[num] = solve(num+1) + 1
	if num == n-1:
		if s[n-2] == '>':
			next_num = -1
			a[num] = 0
			return 0
		else:
			a[num] = solve(num-1) + 1
			next_num = -1
			return a[num]

	if s[num-1] == '>' and s[num] == '<':
		next_num = num+1
		a[num] = 0
		return 0
	elif s[num-1] == '>' and s[num] == '>':
		next_num = num+1
		a[num] = solve(num+1) + 1
		return a[num]
	elif s[num-1] == '<' and s[num] == '>':
		next_num = num+1
		a[num] = max(solve(num-1),solve(num+1)) + 1
		return a[num]
	else:
		a[num] = solve(num-1) + 1
		next_num = num+1
		return a[num]

while next_num != -1:
	solve(next_num)

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

Submission status: Time Limit Exceeded

Solution code:
import sys

inp = sys.stdin.readline()[:-1]
N = len(inp) - 1

from_left = []
from_right = []
less_row = 0
more_row = 0
for i, c in enumerate(inp):
    if c == "<":
        less_row += 1
    else:
        if less_row:
            from_left.append((less_row, less_row * (less_row + 1) // 2))
        less_row = 0

    r_i = N - i
    if inp[r_i] == ">":
        more_row += 1
    else:
        if more_row:
            from_right.insert(0, (more_row, more_row * (more_row + 1) // 2))
        more_row = 0

if less_row:
    from_left.append((less_row, less_row * (less_row + 1) // 2))
if more_row:
    from_right.insert(0, (more_row, more_row * (more_row + 1) // 2))

ans = 0
if inp[-1] == "<":
    ans += from_left.pop()[1]
if inp[0] == ">":
    ans += from_right.pop(0)[1]

for i, (last, tri) in enumerate(from_left):
    r_last, r_tri = from_right[i]
    ans += tri + r_tri - min(last, r_last)

print(ans)

Submission status: Time Limit Exceeded

Solution code:

S = input()
N = len(S) + 1
settingIndex = 0
result = [ -1 for i in range(N) ]

def countContinueChar(index):
    startChar = S[index]
    count = 0
    for i in range(index, N-1):
        if S[i] != startChar:
            break
        count += 1
    return count

def getValueOfIndex(index, current, prev = ''):
    if S[index] == '<':
        if prev == '>':
            return 0
        else:
            return current + 1
    else:
        if prev == '<':
            v = countContinueChar(index)
            if v < current + 1:
                return current + 1
            else:
                return v
        else:
            return countContinueChar(index)

current = -1
prev = ''
sum = 0
for i in range(N):
    if i == N-1:
        if S[-1] == '<':
            result[i] = current + 1
            sum += current + 1
        else:
            result[i] = 0
        break
    if i > 0:
        prev = S[i - 1]
    current = getValueOfIndex(i, current, prev)
    result[i] = current
    sum += current

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import re

S = input()
units = re.findall(r"<+>+", S)
ans = 0
for u in units:
    lm = re.search(r"<>", u).start() + 1
    rm = len(u) - lm
    n_max = max((lm, rm))
    n_min = min((lm, rm)) - 1
    k = (n_max * (n_max + 1) + n_min * (n_min + 1)) // 2
    ans += k
    #print(re.search(r"<+", u).group(), re.search(r">+", u).group(), lm, rm, k)

fu = re.search(r"^>+", S)
if fu is not None:
    fu = len(fu.group())
    ans += fu * (fu + 1) // 2
lu = re.search(r"<+$", S)
if lu is not None:
    lu = len(lu.group())
    ans += lu * (lu + 1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import re

def main():
    S = input()
    N = len(S) + 1

    ans = 0
    s_list = re.split("><", S)
    nelem = len(s_list)
    for i in range(nelem):
        elem = s_list[i]
        ln = elem.count(">") + 1
        rn = elem.count("<") + 1
        if i == 0:
            rn -= 1
        if i == nelem - 1:
            ln -= 1
        nmax = np.max([ln, rn])
        nmin = np.min([ln, rn])
        ans += np.sum(np.arange(start=0, stop=nmax+1, step=1))
        ans += np.sum(np.arange(start=0, stop=nmin, step=1))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s) +1
li = [-1] * n

if s[0]=="<":
  li[0]=0
else:
  li[0]=n
if s[-1]==">":
  li[-1]=0
else:
  li[-1]=n
for i in range(1,n):
  if s[i-1:i+1]=="><":
    li[i]=0
for i in range(1,n):
  for j in range(1,n-1):
    if (li[j-1]==i-1 and s[j-1]=="<") or (li[j+1]==i-1 and s[j]==">"):
      li[j]=i
if s[0]==">":
  li[0]=li[1]+1
if s[-1]=="<":
  li[-1]=li[-2]+1
print(sum(li))

Submission status: Time Limit Exceeded

Solution code:

S = input()
N = len(S) + 1
settingIndex = 0
result = [ -1 for i in range(N) ]

def countContinueChar(slice):
    startChar = slice[0]
    count = 0
    for c in slice:
        if c != startChar:
            break
        count += 1
    return count

def getValueOfIndex(slice, current, prev = ''):
    if slice[0] == '<':
        if prev == '>':
            return 0
        else:
            return current + 1
    else:
        if prev == '<':
            v = countContinueChar(slice)
            if v < current + 1:
                return current + 1
            else:
                return v
        else:
            return countContinueChar(slice)

current = -1
prev = ''
sum = 0
for i in range(N):
    if i == N-1:
        if S[-1] == '<':
            result[i] = current + 1
            sum += current + 1
        else:
            result[i] = 0
        break
    if i > 0:
        prev = S[i - 1]
    current = getValueOfIndex(S[i:], current, prev)
    result[i] = current
    sum += current

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import re

S = input()
units = re.findall(r"<+>+", S)
ans = 0
for u in units:
    lm = len(re.search(r"<+", u).group())
    rm = len(re.search(r">+", u).group())
    n_max = max((lm, rm))
    n_min = min((lm, rm)) - 1
    k = (n_max * (n_max + 1) + n_min * (n_min + 1)) // 2
    ans += k
    #print(re.search(r"<+", u).group(), re.search(r">+", u).group(), k)

fu = re.search(r"^>+", S)
if fu is not None:
    fu = len(fu.group())
    ans += fu * (fu + 1) // 2
lu = re.search(r"<+$", S)
if lu is not None:
    lu = len(lu.group())
    ans += lu * (lu + 1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import re

def main():
    S = input()
    N = len(S) + 1

    ans = 0
    s_list = re.split("(><)", S)
    nelem = len(s_list)
    for i in range(nelem):
        elem = s_list[i]
        if elem == "><":
            pass
        else:
            ln = elem.count(">") + 1
            rn = elem.count("<") + 1
            if i == 0:
                rn -= 1
            if i == nelem - 1:
                ln -= 1
            nmax = np.max([ln, rn])
            nmin = np.min([ln, rn])
            #print("===")
            #print([rn, ln])
            #print(np.arange(start=0, stop=nmax+1, step=1))
            #print(np.arange(start=0, stop=nmin-1, step=1))
            ans += np.sum(np.arange(start=0, stop=nmax+1, step=1))
            ans += np.sum(np.arange(start=0, stop=nmin, step=1))
    #print(s_list)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s= str(input())
n = len(s) + 1
a = []
for j in range(n):
    a.append(0)

i = 0
while i<n-1:
    if s[i] == "<" and a[i] >= a[i+1]:
        a[i+1] = a[i] + 1
        i +=1
    elif s[i] == ">" and a[i] <= a[i+1]:
        a[i] = a[i+1] + 1
        if i > 0:
            i -= 1
        else:
            i += 1
    else:
        i +=1
print(sum(a))