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()
d = []
lt = 0
gt = 0
for i in range(len(S)):
    if i == 0:
        continue
    if S[i - 1]  == S[i] and S[i] == "<":
        lt += 1
    if S[i - 1] == S[i] and S[i] == ">":
        gt += 1
    if S[i - 1] != S[i] and S[i-1] == "<":
        d.append("<" * (lt + 1))
        lt = 0
    if S[i - 1] != S[i] and S[i - 1] == ">":
        d.append(">" * (gt + 1))
        gt = 0
    if i == len(S) - 1 and S[i] == "<":
        d.append("<" * (lt + 1))
    if i == len(S) - 1 and S[i] == ">":
        d.append(">" * (gt + 1))
    
print(d)
ans=0

if d[0][0] == "<":
    i = 0
    while i < len(d) - 1:
        if i != len(d) - 1:
            if len(d[i]) >= len(d[i + 1]):
                for i in range(1, len(d[i])+1):
                    ans += i
                for i in range(1, len(d)):
                    ans += i
                i += 2
            elif len(d[i]) < len(d[i + 1]):
                for i in range(1, len(d[i])+1):
                    ans += i
                for i in range(1, len(d)):
                    ans += i
                i+= 2
        elif i  == len(d) - 1:
            for i in range(1, len(d[i])+1):
                ans += i
                i += 1

if d[0][0] ==">":
    ans += (len(d[i]) + 1) * len(d[i]) / 2
    i = 1
    while i < len(d) - 1:
        if i != len(d) - 1:
            if len(d[i]) >= len(d[i + 1]):
                ans += (len(d[i]) + 1) * len(d[i]) / 2 + (len(d[i+1])) * len(d[i + 1]) / 2
                i += 2
            elif len(d[i]) < len(d[i + 1]):
                ans += (len(d[i])) * len(d[i]) / 2 + (len(d[i+1])+1) * len(d[i + 1]) / 2
                i += 2
        elif i  == len(d) - 1:
            ans +=  (len(d[i]) + 1) * len(d[i]) / 2

print(ans)
    

                

        
# min_d = 0
# for i in d:
#     min_d = min(min_d, d[i])

# d = list(map(lambda x: x + abs(min_d), d))

# if S[0] == "<":
#     d[0] = 0

# ans = 0
# for i in range(len(S)):
#     ans += d[i]
# print(d)
# print(ans)

Submission status: Runtime Error

Solution code:
s= str(input())
n = len(s) + 1
a = []
for j in range(n):
    a.append(0)
 
for i in range(n-2):
    if s[i] == ">" and s[i+1] == "<":
        a[i+1] = 0
        j = i
        
        while s[i] == ">":
            a[i] = max(a[i], a[i+1] +1)
            i -= 1
        while s[j+1] == "<":
            a[j+2] = max(a[j+1]+1, a[j+2])
            j += 1



print(sum(a))

Submission status: Runtime Error

Solution code:
s = input()

a = []
index = 0
diff = 0
for i in range(len(s) - 1):
    if s[i] == "<":
        a.appned(a[-1] + 1)
        index += 1

    else:
        if s[i + 1] == "<":
            diff = index - i

            if a[-1] <= diff:
                a[-1] = diff

            a = a + [diff - 1 - i for i in range(diff)]
            index += count
            count = 0
        else:
            count += 1

if count != 0:
    diff = index - len(s) + 1
    if a[-1] <= diff:
        a[-1] = diff

    a = a + [diff - 1 - i for i in range(diff)]

print(sum(a))

Submission status: Runtime Error

Solution code:
s = input()


# ゼロ点を探す

now = s[0]
zero = []
kyoku = []

for i in range(len(s)):
  if now == '>' and s[i] == '<':
    zero.append(i)

  if now == '<' and s[i] == '>':
    kyoku.append(i)
  
  now = s[i]
    


if len(zero) == 0:
  zero.append(0)
  zero.append(len(s)- 1)

if len(kyoku) == 0:
  kyoku.append(0)
  kyoku.append(len(s)- 1)

ans = 0

if len(zero) < len(kyoku):
  for i in range(0,len(zero),2):
    a = zero[i] -kyoku[i]
    b = kyoku[i+1] - zero[i]

    ans += a*(a+1) // 2 + b*(b-1) //2
else:
    for i in range(0,len(kyoku),2):
      a =  kyoku[i] - zero[i]
      b =  zero[i+1] - kyoku[i]

    ans += a*(a+1) // 2 + b*(b-1) //2

print(ans)

Submission status: Runtime Error

Solution code:
import re
s = input()
total = 0
sy = [m.span() for m in re.finditer(r'>+', s)]
if s.startswith('<'):
    a = sy[0]
    if a[0] == 1:
        w = a[1] - a[0]
        total += w + sum(range(1, w))
    else:
        w = a[1] - a[0]
        if w >= a[0]:
            total += sum(range(a[0])) + w + sum(range(1, w))
        else:
            total += sum(range(a[0] + 1)) + sum(range(1, w))
else:
    total += sum(range(sy[0][1] - sy[0][0]))
for i, a in enumerate(sy):
    if i == 0:
        continue
    if a[0] - sy[i-1][1] == 1:
        w = a[1] - a[0]
        total += w + sum(range(1, w))
    else:
        w = a[1] - a[0]
        if w >= a[0]-sy[i-1][1]:
            total += sum(range(a[0] - sy[i - 1][1])) + w + sum(range(1, w))
        else:
            total += sum(range(a[0]-sy[i-1][1]+1)) + sum(range(1, w))
if s.endswith('<'):
    total += sum(range(len(s)-sy[-1][1]+1))
print(total)

Submission status: Runtime Error

Solution code:
import re
S = input()

po=[]
ne=[]
li = [m.span()[0] for m in re.finditer('><', S)]
result = []

n = 0
for i in S:
    if i == "<":
        n += 1
    else:
        po.append(n)
        break
for i in li:
    s = "<"
    n = 0
    while s == S[i+1]:
        n += 1
        i += 1
        if i+1 >= len(S):
            break
    po.append(n)
for i in li:
    s = ">"
    n = 0
    while s == S[i]:
        n += 1
        i -= 1
    ne.append(n)
n = 0
for i in S[::-1]:
    if i == ">":
        n += 1
    else:
        ne.append(n)
        break
if len(po) == 0:
    result.append((1/2)*ne[i]*(ne[i]+1))
if len(ne) == 0:
    result.append((1/2)*po[i]*(po[i]+1))
for i,l in enumerate(po):
    if l < ne[i]:
        if l > 0:
            result.append((1/2)*(l-1)*l)
        if ne[i] > 0:
            result.append((1/2)*ne[i]*(ne[i]+1))
    else:
        if l > 0:
            result.append((1/2)*l*(l+1))
        if ne[i] > 0:
            result.append((1/2)*ne[i]*(ne[i]-1))
print(int(sum(result)))

Submission status: Runtime Error

Solution code:
# とりあえずランレングスhttps://www.kabegiwablog.com/entry/2018/04/09/100000
# 引数を配列に格納
# num = "><>>><<><<<<<>>><"
num = input()

# 変数初期化
count = 1
result = ''

# 配列全体のループ
for i in range(len(num)):
    try:
        if num[i] == num[i+1]:
           count = count + 1
        else:
            result = result + str(count) + str(num[i])
            count = 1
    except:
        # 最後の文字セットがOutOfRangeになるので結果に出力
        result = result + str(count) + str(num[i])
        
def sum_numbers(n):
    if n ==0:
        return 0
    return n + sum_numbers(n-1)

ans = 0
num_list = []
char_list = []

for idx, char in enumerate(result):
    if idx % 2 == 1:
        char_list.append(char)
    else:
        num_list.append(int(char))
if len(num_list) == 1:
    ans = sum_numbers(num_list[0])
else:
	if char_list[0] == "<":
	    if len(char_list) % 2 == 1:
	        for i in range(0, len(num_list)-1, 2):
	#             print(num_list[i], num_list[i+1])
	            if num_list[i] < num_list[i+1]:
	                temp_sum = sum_numbers(num_list[i]-1) + sum_numbers(num_list[i+1])
	#             print("上", temp_sum)
	                ans += temp_sum
	            else:
	                temp_sum = sum_numbers(num_list[i]) + sum_numbers(num_list[i+1]-1)
	#             print("下", temp_sum)
	                ans += temp_sum
	#             print(ans)
	        ans += sum_numbers(num_list[-1])
	    else:
	        for i in range(0, len(num_list), 2):
	#             print(num_list[i], num_list[i+1])
	            if num_list[i] < num_list[i+1]:
	                temp_sum = sum_numbers(num_list[i]-1) + sum_numbers(num_list[i+1])
	#             print("上", temp_sum)
	                ans += temp_sum
	            else:
	                temp_sum = sum_numbers(num_list[i]) + sum_numbers(num_list[i+1]-1)
	#             print("下", temp_sum)
	                ans += temp_sum
	#             print(ans)

	if char_list[0] == ">":
	#     print("test",len(char_list)-1 % 2)
	    if (len(char_list)-1) % 2 == 1:
	        for i in range(1, len(num_list)-1, 2):
	#             print(num_list[i], num_list[i+1])
	            if num_list[i] < num_list[i+1]:
	                temp_sum = sum_numbers(num_list[i]-1) + sum_numbers(num_list[i+1])
	                ans += temp_sum
	            else:
	                temp_sum = sum_numbers(num_list[i]) + sum_numbers(num_list[i+1]-1)
	                ans += temp_sum
	        ans += sum_numbers(num_list[-1])
	    else:
	        for i in range(1, len(num_list), 2):
	#             print(num_list[i], num_list[i+1])
	            if num_list[i] < num_list[i+1]:
	                temp_sum = sum_numbers(num_list[i]-1) + sum_numbers(num_list[i+1])
	                ans += temp_sum
	            else:
	                temp_sum = sum_numbers(num_list[i]) + sum_numbers(num_list[i+1]-1)
	                ans += temp_sum
	    ans += sum_numbers(num_list[0])

print(ans)

Submission status: Runtime Error

Solution code:
import re
S = input()

po=[]
ne=[]
li = [m.span()[0] for m in re.finditer('><', S)]
result = []

n = 0
for i in S:
    if i == "<":
        n += 1
    else:
        po.append(n)
        break
for i in li:
    s = "<"
    n = 0
    while s == S[i+1]:
        n += 1
        i += 1
        if i+1 >= len(S):
            break
    po.append(n)
for i in li:
    s = ">"
    n = 0
    while s == S[i]:
        n += 1
        i -= 1
    ne.append(n)
n = 0
for i in S[::-1]:
    if i == ">":
        n += 1
    else:
        ne.append(n)
        break
for i,l in enumerate(po):
    if l < ne[i]:
        if l > 0:
            result.append((1/2)*(l-1)*l)
        if ne[i] > 0:
            result.append((1/2)*ne[i]*(ne[i]+1))
    else:
        if l > 0:
            result.append((1/2)*l*(l+1))
        if ne[i] > 0:
            result.append((1/2)*ne[i]*(ne[i]-1))
print(int(sum(result)))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2147483647) 
S=str(input())
s=list(S)
x1=0
x2=1
y=0
len=min(len(s)-1,1000)
for i in range(len):
  if s[i+1]==s[i]:
    x2=x2+1
  else:
    if i==0:
      x2=0
    if s[i]=='>':
      if x2<x1:
        x2=x2-1
      else:
          x1=x1-1
    y+=x1*(x1+1)/2
    x1=x2
    x2=1
if s[i+1]=='>':
      if x2<x1:
        x2=x2-1
      else:
          x1=x1-1
y+=x1*(x1+1)/2
y+=x2*(x2+1)/2
print(int(y))

Submission status: Runtime Error

Solution code:
import numpy as np

S = list(map(str,input().split()))
S2 = S[0]
S = [c for c in S[0]]

change_num = S2.count('><') + S2.count('<>')
count = 0
now_array = 0
array = [[], []]
a=0
tmp_count = 0
before_count = 0

if S[0] == '<':
    if change_num%2 == 0:
        for i in range(len(S)):
            if i==0:
                tmp = S[i]
                count = 1
            else:
                if S[i] != tmp or i == len(S)-1:
                    if S[i] == tmp and  i == len(S)-1:
                        count += 1
                    array[now_array].append(count)
                    if now_array == 0:
                        now_array = 1
                    else:
                        now_array = 0
                        if count<before_count:
                            tmp_count += int((count-1)*(count)/2)
                    before_count = count
                    count = 1
                    if S[i] != tmp and i == len(S)-1:
                        array[now_array].append(count)
                    tmp = S[i]
                else:
                    count += 1

        large = array[0]
        small = array[1]
        last_large = large[-1]
        del(large[-1])
        large = np.array(large)
        small = np.array(small)
        cmp = np.maximum(large, small)
        cmp = [int(x*(x+1)/2) for x in cmp]

        ans = np.sum(cmp)+int(last_large*(last_large+1)/2)+tmp_count
    else:
        for i in range(len(S)):
            if i==0:
                tmp = S[i]
                count = 1
            else:
                if S[i] != tmp or i == len(S)-1:
                    if S[i] == tmp and  i == len(S)-1:
                        count += 1
                    array[now_array].append(count)

                    if now_array == 0:
                        now_array = 1
                    else:
                        now_array = 0
                        if count<before_count:
                            tmp_count += int((count-1)*(count)/2)
                    before_count = count
                    count = 1
                    if S[i] != tmp and i == len(S)-1:
                        array[now_array].append(count)
                    tmp = S[i]
                else:
                    count += 1
        large = array[0]
        small = array[1]
        large = np.array(large)
        small = np.array(small)
        cmp = np.maximum(large, small)
        cmp = [int(x*(x+1)/2) for x in cmp]
        ans = np.sum(cmp)+tmp_count

        #############
else:
    if change_num%2 == 0:
        for i in range(len(S)):
            if i==0:
                tmp = S[i]
                count = 1
            else:
                if S[i] != tmp or i == len(S)-1:
                    if S[i] == tmp and  i == len(S)-1:
                        count += 1
                    array[now_array].append(count)
                    if now_array == 0:
                        now_array = 1
                    else:
                        now_array = 0
                        if count<before_count:
                            tmp_count += int((count-1)*(count)/2)
                    before_count = count
                    count = 1
                    if S[i] != tmp and i == len(S)-1:
                        array[now_array].append(count)
                    tmp = S[i]
                else:
                    count += 1

        large = array[0]
        small = array[1]
        first_small = small[0]
        del(small[0])
        large = np.array(large)
        small = np.array(small)
        cmp = np.maximum(large, small)
        cmp = [int(x*(x+1)/2) for x in cmp]
        ans = np.sum(cmp)+int(first_small*(first_small+1)/2)+tmp_count
        
    else:
        for i in range(len(S)):
            if i==0:
                tmp = S[i]
                count = 1
            else:
                if S[i] != tmp or i == len(S)-1:
                    if S[i] == tmp and  i == len(S)-1:
                        count += 1
                    array[now_array].append(count)
                    if now_array == 0:
                        now_array = 1
                    else:
                        now_array = 0
                        if count<before_count:
                            tmp_count += int((count-1)*(count)/2)
                    before_count = count
                    count = 1
                    if S[i] != tmp and i == len(S)-1:
                        array[now_array].append(count)
                    tmp = S[i]
                else:
                    count += 1

        large = array[0]
        small = array[1]
        large = np.array(large)
        small = np.array(small)
        cmp = np.maximum(large, small)
        cmp = [int(x*(x+1)/2) for x in cmp]
        ans = np.sum(cmp)+tmp_count
print(ans)

Submission status: Runtime Error

Solution code:
print(s)
n=len(s)#長さ

c=0#非負整数列
N=0
j=0
k=0
for i in range(1,n):
  if (s[i-1]=="<" and s[i]==">"):
    #print(i)
    j=i
    N+=math.factorial(i-k)
    #print("<>",i-k)
  if (s[i-1]==">" and s[i]=="<"):
    k=i
    N+=math.factorial(i-j)
    #print("><",i-j)
print(N)

Submission status: Runtime Error

Solution code:
# とりあえずランレングスhttps://www.kabegiwablog.com/entry/2018/04/09/100000
# 引数を配列に格納
# num = "><>>><<><<<<<>>><"
num = input()

# 変数初期化
count = 1
result = ''

# 配列全体のループ
for i in range(len(num)):
    try:
        if num[i] == num[i+1]:
           count = count + 1
        else:
            result = result + str(count) + str(num[i])
            count = 1
    except:
        # 最後の文字セットがOutOfRangeになるので結果に出力
        result = result + str(count) + str(num[i])
        
def sum_numbers(n):
    if n ==0:
        return 0
    return n + sum_numbers(n-1)

ans = 0
num_list = []
char_list = []

for idx, char in enumerate(result):
    if idx % 2 == 1:
        char_list.append(char)
    else:
        num_list.append(int(char))
        
if char_list[0] == "<":
    if len(char_list) % 2 == 1:
        for i in range(0, len(num_list)-1, 2):
#             print(num_list[i], num_list[i+1])
            if num_list[i] < num_list[i+1]:
                temp_sum = sum_numbers(num_list[i]-1) + sum_numbers(num_list[i+1])
#             print("上", temp_sum)
                ans += temp_sum
            else:
                temp_sum = sum_numbers(num_list[i]) + sum_numbers(num_list[i+1]-1)
#             print("下", temp_sum)
                ans += temp_sum
#             print(ans)
        ans += sum_numbers(num_list[-1])
    else:
        for i in range(0, len(num_list), 2):
#             print(num_list[i], num_list[i+1])
            if num_list[i] < num_list[i+1]:
                temp_sum = sum_numbers(num_list[i]-1) + sum_numbers(num_list[i+1])
#             print("上", temp_sum)
                ans += temp_sum
            else:
                temp_sum = sum_numbers(num_list[i]) + sum_numbers(num_list[i+1]-1)
#             print("下", temp_sum)
                ans += temp_sum
#             print(ans)

if char_list[0] == ">":
#     print("test",len(char_list)-1 % 2)
    if (len(char_list)-1) % 2 == 1:
        for i in range(1, len(num_list)-1, 2):
#             print(num_list[i], num_list[i+1])
            if num_list[i] < num_list[i+1]:
                temp_sum = sum_numbers(num_list[i]-1) + sum_numbers(num_list[i+1])
                ans += temp_sum
            else:
                temp_sum = sum_numbers(num_list[i]) + sum_numbers(num_list[i+1]-1)
                ans += temp_sum
        ans += sum_numbers(num_list[-1])
    else:
        for i in range(1, len(num_list), 2):
#             print(num_list[i], num_list[i+1])
            if num_list[i] < num_list[i+1]:
                temp_sum = sum_numbers(num_list[i]-1) + sum_numbers(num_list[i+1])
                ans += temp_sum
            else:
                temp_sum = sum_numbers(num_list[i]) + sum_numbers(num_list[i+1]-1)
                ans += temp_sum
    ans += sum_numbers(num_list[0])

print(ans)

Submission status: Runtime Error

Solution code:
a = int(input())

Submission status: Runtime Error

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
l=sorted(l)
a=[]
b=[]
c=[]

for i in range(n):
    a.append(l[i][0])
    b.append(l[i][1])

for i in range(1,n):
    x=min(b[:i])-max(a[:i])
    y=min(b[i:])-max(a[i:])

    if x>(-1) and y>(-1):
        c.append(x+y)

print(max(c)+2)

Submission status: Runtime Error

Solution code:
import numpy as np

S = list(map(str,input().split()))
S2 = S[0]
S = [c for c in S[0]]

change_num = S2.count('><') + S2.count('<>')
count = 0
now_array = 0
array = [[], []]
a=0
tmp_count = 0
before_count = 0

if S[0] == '<':
    if change_num%2 == 0:
        for i in range(len(S)):
            if i==0:
                tmp = S[i]
                count = 1
            else:
                if S[i] != tmp or i == len(S)-1:
                    array[now_array].append(count)
                    if now_array == 0:
                        now_array = 1
                    else:
                        now_array = 0
                        if count > 1 and count>before_count:
                            tmp_count += int((count-1)*(count)/2)
                    before_count = count
                    count = 1
                    if S[i] != tmp and i == len(S)-1:
                        array[now_array].append(count)
                    tmp = S[i]
                else:
                    count += 1

        large = array[0]
        small = array[1]
        last_large = large[-1]
        del(large[-1])
        large = np.array(large)
        small = np.array(small)
        cmp = np.maximum(large, small)
        cmp = [int(x*(x+1)/2) for x in cmp]

        ans = np.sum(cmp)+int(last_large*(last_large+1)/2)+tmp_count
    else:
        for i in range(len(S)):
            if i==0:
                tmp = S[i]
                count = 1
            else:
                if S[i] != tmp or i == len(S)-1:
                    array[now_array].append(count)
                    if now_array == 0:
                        now_array = 1
                    else:
                        now_array = 0
                        if count > 1 and count>before_count:
                            tmp_count += int((count-1)*(count)/2)
                    before_count = count
                    count = 1
                    if S[i] != tmp and i == len(S)-1:
                        array[now_array].append(count)
                    tmp = S[i]
                else:
                    count += 1
        large = array[0]
        small = array[1]
        large = np.array(large)
        small = np.array(small)
        cmp = np.maximum(large, small)
        cmp = [int(x*(x+1)/2) for x in cmp]
        ans = np.sum(cmp)+int(last_large*(last_large+1)/2)+tmp_count

        #############
else:
    if change_num%2 == 0:
        for i in range(len(S)):
            if i==0:
                tmp = S[i]
                count = 1
            else:
                if S[i] != tmp or i == len(S)-1:

                    array[now_array].append(count)
                    if now_array == 0:
                        now_array = 1
                    else:
                        now_array = 0
                        if count > 1 and count>before_count:
                            tmp_count += int((count-1)*(count)/2)
                    before_count = count
                    count = 1
                    if S[i] != tmp and i == len(S)-1:
                        array[now_array].append(count)
                    tmp = S[i]
                else:
                    count += 1

        large = array[0]
        small = array[1]
        first_small = small[0]
        del(small[0])
        large = np.array(large)
        small = np.array(small)
        cmp = np.maximum(large, small)
        cmp = [int(x*(x+1)/2) for x in cmp]
        ans = np.sum(cmp)+int(first_small*(first_small+1)/2)+tmp_count
        
    else:
        for i in range(len(S)):
            if i==0:
                tmp = S[i]
                count = 1
            else:
                if S[i] != tmp or i == len(S)-1:
                    array[now_array].append(count)
                    if now_array == 0:
                        now_array = 1
                    else:
                        now_array = 0
                        if count > 1 and count>before_count:
                            tmp_count += int((count-1)*(count)/2)
                    before_count = count
                    count = 1
                    if S[i] != tmp and i == len(S)-1:
                        array[now_array].append(count)
                    tmp = S[i]
                else:
                    count += 1

        large = array[0]
        small = array[1]
        large = np.array(large)
        small = np.array(small)
        cmp = np.maximum(large, small)
        cmp = [int(x*(x+1)/2) for x in cmp]
        ans = np.sum(cmp)+int(last_large*(last_large+1)/2)+tmp_count
print(ans)

Submission status: Runtime Error

Solution code:
import math

S = list(input())

prev = S[0]
series = 1
l = []

for i in range(1, len(S)):
    if prev == S[i]:
        series += 1
    else:
        l.append((prev, series))
        series = 1


prev_max = l[0][1]-1
prev = math.factorial(l[0][1]-1)
res = prev

for s, n in range(len(l)):
    if s == '<':
        prev = math.factorial(n-1)
        prev_max = n-1
        res += prev
    else:
        if n-1 > prev_max:
            prev = math.factorial(n-2)
            res += prev
        else:
            res -= prev_max
            prev = math.factorial(n-1)
            res += prev

print(res)

Submission status: Runtime Error

Solution code:
# import numpy as np
# import time

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

    for i in range(1, len(s)+1):
        if s[i-1] == '<':
            n_list[i] = n_list[i-1]+1
        else: # i = >
            if s[i] == '>':
                continue
            j = i # jは左側の                           文字のインデックス
            k = 1                          
            for j in range(i, 1, -1):
                if s[j-1] == '<':
                    n_list[j] = max(n_list[j-1], n_list[j+1])+1
                    break
                n_list[j-1] = k
                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__":
    # start = time.time()
    main()    
    # elapsed_time = time.time() - start
    # print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2147483647) 
S=str(input())
s=list(S)
x1=0
x2=1
y=0
len=len(s)-1
for i in range(len):
  if s[i+1]==s[i]:
    x2=x2+1
  else:
    if i==0:
      x2=0
    if s[i]=='>':
      if x2<x1:
        x2=x2-1
      else:
          x1=x1-1
    y+=x1*(x1+1)/2
    x1=x2
    x2=1
if s[i+1]=='>':
      if x2<x1:
        x2=x2-1
      else:
          x1=x1-1
y+=x1*(x1+1)/2
y+=x2*(x2+1)/2
print(int(y))

Submission status: Runtime Error

Solution code:
# import numpy as np
# import time

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

    for i in range(1, len(s)+1):
        if s[i-1] == '<':
            n_list[i] = n_list[i-1]+1
        else: # i = >
            if s[i] == '>':
                continue
            j = i # jは左側の                           文字のインデックス
            k = 1                          
            for j in range(i, 1, -1):
                if s[j-1] == '<':
                    n_list[j] = max(n_list[j-1], n_list[j+1])+1
                    break
                n_list[j-1] = k
                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__":
    # start = time.time()
    main()    
    # elapsed_time = time.time() - start
    # print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")

Submission status: Runtime Error

Solution code:
ans = 0
kukan = []
max_l = 0
min_r = 10**9
n = int(input())
for i in range(n):
    l,r = map(int, input().split())
    l,r = l-1,r-1
    max_l = max(max_l, l)
    min_r = min(min_r, r)
    kukan.append((l,r))
kukan = list(set(kukan))
kukan.sort()

# maxとminが同じ時は？
# 最大区間を取ってくればいいだけ
min_r_l = None
l,r = kukan.pop()
max_l_r = r
for i in range(len(kukan)):
    if kukan[i][1] == min_r:
        min_r_l = kukan[i][0]
        kukan.pop(i)
        break

if min_r_l is None:
    ans = min_r-max_l+1 + max(r-l+1 for l, r in kukan)
    print(ans)
    exit()

# 累積和
# Lが小さい方からK個取ったときに、残りのRの最小値がほしい
cumsum_r = [float("inf")]
for i in reversed(range(len(kukan))):
    cumsum_r.append(min(cumsum_r[-1], kukan[i][1]))
cumsum_r = cumsum_r[::-1]

# 左 : min_r_l, min_r
# 右 : max_l, max_l_r

for i in range(len(kukan)+1):
    # Lに取らない時
    if i == 0:
        left_l = min_r_l
        right_r = min(max_l_r,cumsum_r[i])
    # 1個以上取る時
    else:
        left_l = max(min_r_l, kukan[i-1][0])
        right_r = min(max_l_r,cumsum_r[i])
    tmp = max(0, min_r-left_l+1) + max(0, right_r-max_l+1)
    ans = max(ans, tmp)

print(ans)

Submission status: Runtime Error

Solution code:
s = input()
List=list(s)

if s[0]=='<':
    List.insert(0,'0')
if s[-1]=='>':
    List.insert(-1,'0')

for i in range(len(List)+1):
    if List[i]=='>' and List[i+1]=='<':
        List.insert(i+1,'0')

List2=((''.join(List)).split('0'))
#print(List2)

Ans=[]

for i in List2:
    Ans.append(max(i.count("<"), i.count(">")))
    Ans.append(max(min(i.count("<"), i.count(">"))-1,0))

#print(Ans)

Sum=[]

for n in Ans:
  Sum.append(n*-~n>>1)

print(sum(Sum))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**9) 
S=str(input())
s=list(S)
x1=0
x2=1
y=0
for i in range(len(s)-1):
  if s[i+1]==s[i]:
    x2=x2+1
  else:
    if i==0:
      x2=0
    if s[i]=='>':
      if x2<x1:
        x2=x2-1
      else:
          x1=x1-1
    y+=x1*(x1+1)/2
    x1=x2
    x2=1
if s[i+1]=='>':
      if x2<x1:
        x2=x2-1
      else:
          x1=x1-1
y+=x1*(x1+1)/2
y+=x2*(x2+1)/2
print(int(y))

Submission status: Runtime Error

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

_s = input()


def chker(s):
    l, r, minisum = 0, 0, 0
    if s[0] == '<':
        l += 1
    elif s[i] == '>':
        r += 1
    for i in range(1, len(s)):
        if s[i - 1] == '>' and s[i] == '<':
            l, r = (l, r) if l > r else (r, l)
            minisum += l * (l + 1) / 2 + r * (r - 1) / 2
            l, r = 1, 0
        else:
            if s[i] == '<':
                l += 1
            elif s[i] == '>':
                r += 1

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

Solution code:
def count_angle_brackets(S):
    num_ab = []
    count = 1
    before = None
    for i, s in enumerate(S, 1):
        if before is None:
            before = s
            continue
        else:
            if s == before:
                count += 1
                before = s
            else:
                num_ab.append([before, count])
                count = 1
                before = s
                
            if len(S) == i:
                num_ab.append([before, count])
    return num_ab

  
S = input()
counted = count_angle_brackets(S)
sum_val = 0
sum_val += sum(sum(range(i[1])) for i in counted)
if counted[-1][0] == '<':
  sum_val += counted[-1][1]
if counted[0][0] == '>':
  sum_val += counted[0][1]
  counted = counted[1:]
it = iter(i for _, i in counted)
try:
  for i in it:
    sum_val += max(i, next(it))
except:
  pass
print(sum_val)

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)
ans = 0
cnt = 0
tmp = 0
i = 0
while i < N - 1:
  cnt = 0
  tmp = 0
  if S[i] == "<":
    while S[i] == "<":
      if i == N - 1:
        ans += 1
        break
      cnt += 1
      if S[i+1] == ">":
        ans += cnt * (cnt + 1) // 2
        tmp = cnt
        cnt = 0
        i += 1
        while S[i] == ">":
          cnt += 1
          i += 1
          if i == N:
            i -= 1
            break
        ans += (cnt - 1) * (cnt) // 2
        if tmp >= cnt:
          pass
        else:
          ans += cnt - tmp
        cnt = 0
      else:
        i += 1
  else:
    while S[i] == ">":
      cnt += 1
      i += 1
    ans += cnt * (cnt + 1) // 2
print(ans)

Submission status: Runtime Error

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

for i in range(N - 1):
  if S[i] == '<':
    a[i + 1] = a[i] + 1
  else:
    a[i + 1] = a[i] - 1
    


print(sum(b))