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:
# Grand Contest 040 - Q1
import sys
import numpy as np

def calc_func(n):
    num_list = np.arange(n)
    ret = 0
    for i in range(len(num_list)):
        ret += num_list[i]
    return ret

S = list(input())

char_list = []
number_list = []
counter = 1
for i in range(len(S)):
    # 配列の最後だったら
    if i == len(S)-1:
        number_list.append(counter)
        char_list.append(S[i])
        break
    if S[i] == S[i+1]:
        counter += 1
    elif S[i] != S[i+1]:
        number_list.append(counter)
        char_list.append(S[i])
        counter = 1
# print('文字数え：',number_list)
# print('文字リスト：', char_list)

answer = 0
if char_list[0] == '<':
    answer = 0
if char_list[0] == '>':
    answer += number_list[1]

for i in range(1,len(number_list)-1):
    if char_list[i] == '<':
        answer += calc_func(number_list[i])
        # print(calc_func(number_list[i]))
    elif char_list[i] == '>' and number_list[i-1] < number_list[i]:
        answer += number_list[i] + calc_func(number_list[i])
        # print(calc_func(number_list[i]))
    elif char_list[i] == '>' and number_list[i-1] > number_list[i]:
        answer += number_list[i-1] + calc_func(number_list[i])
        # print(number_list[i-1] + calc_func2(number_list[i]))

if char_list[len(number_list)-1] == '<' and number_list[len(number_list)-1] == 1:
    answer += 1


print(answer)

Submission status: Runtime Error

Solution code:
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:
S = input()
s_len = len(S)

s_kigo_map = [] # [[0,1],[1,2]] 0 = < , 1 = >
init_s = S[0]
right_count = 0
left_count = 0
max_len = 0
if S[0] == '<':
    s_num = 0
else:
    s_num = 1
s_count = 1
for i in range(1,s_len):
    if S[0] == '<':
        right_count += 1
    else:
        left_count += 1
    if init_s == S[i]:
        s_count += 1
    else:
        if max_len < s_count:
            max_len = s_count
        s_kigo_map.append([s_num,s_count])
        if S[i] == '<':
            s_num = 0
        else:
            s_num = 1
        init_s = S[i]
        s_count = 1
s_kigo_map.append([s_num,s_count])

next_num = 0
sum_num = 0

i = 0
if s_kigo_map[i][0] == 0: # <の時
    if s_kigo_map[i][1] >= s_kigo_map[i+1][1]:
        sum_num += (0 +s_kigo_map[i][1] )*(s_kigo_map[i][1]+1)//2
        #next_num = next_num + s_kigo_map[i][0]
    else: # `差分を増やす必要がある`
        sum_num += ( (0 +s_kigo_map[i][1] )*(s_kigo_map[i][1]+1)//2 )+ ( s_kigo_map[i+1][1] - s_kigo_map[i][1])
        #next_num = next_num + s_kigo_map[i+1][0] 
else:  # >の時
    sum_num += (0 +s_kigo_map[i][1] )*(s_kigo_map[i][1]+1)//2
    #next_num = 0

for i in range(1,len(s_kigo_map)):
    if s_kigo_map[i][0] == 0: # <の時
        if i == len(s_kigo_map) -1:
            sum_num += (1 +s_kigo_map[i][1] )*s_kigo_map[i][1]//2
            break
        if s_kigo_map[i][1] >= s_kigo_map[i+1][1]:
            sum_num += (1 +s_kigo_map[i][1] )*s_kigo_map[i][1]//2
            #next_num = next_num + s_kigo_map[i][0]
        else: # `差分を増やす必要がある`
            sum_num += ( (1 +s_kigo_map[i][1])*s_kigo_map[i][1]//2 ) + ( s_kigo_map[i+1][1] - s_kigo_map[i][1])
            #next_num = next_num + s_kigo_map[i+1][0] 
    else:  # >の時
        sum_num += (s_kigo_map[i][1] - 1 )*(s_kigo_map[i][1])//2
        #next_num = 0



print(sum_num)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

def calc_func(n):
    num_list = np.arange(n+1)
    ret = 0
    for i in range(len(num_list)):
        ret += num_list[i]
    return ret

def calc_func2(n):
    num_list = np.arange(n)
    ret = 0
    for i in range(len(num_list)):
        ret += num_list[i]
    return ret

S = list(input())

char_list = []
number_list = []
counter = 1
for i in range(len(S)):
    # 配列の最後だったら
    if i == len(S)-1:
        number_list.append(counter)
        char_list.append(S[i])
        break
    if S[i] == S[i+1]:
        counter += 1
    elif S[i] != S[i+1]:
        number_list.append(counter)
        char_list.append(S[i])
        counter = 1
# print('文字数え：',number_list)
# print('文字リスト：', char_list)

answer = 0
if char_list[0] == '<':
    answer = 0
if char_list[0] == '>':
    answer += number_list[1]

for i in range(1,len(number_list)):
    if char_list[i] == '<':
        answer += calc_func(number_list[i])
        # print(calc_func(number_list[i]))
    elif char_list[i] == '>' and number_list[i-1] < number_list[i]:
        answer += calc_func(number_list[i])
        # print(calc_func(number_list[i]))
    elif char_list[i] == '>' and number_list[i-1] > number_list[i]:
        answer += calc_func2(number_list[i])
        # print(number_list[i-1] + calc_func2(number_list[i]))

print(answer)

Submission status: Runtime Error

Solution code:
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:
        if x2>x1:
          x1=x1-1
    y+=x1*(x1+1)/2
    x1=x2
    x2=1
if s[i+1]=='>':
      if x2<x1:
        x2=x2-1
      else:
        if x2>x1:
          x1=x1-1
y+=x1*(x1+1)/2
y+=x2*(x2+1)/2
print(int(y))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(5000000)

s = input()
cont_list = []
ini_di = s[0]
count = 1
for i in range(1, len(s)):
    if s[i] == s[i-1]:
        count += 1
        if i == len(s) - 1:
            cont_list.append(count)
    else:
        cont_list.append(count)
        count = 1
        if i == len(s) - 1:
            cont_list.append(count)


def counting(i):
    a = max(cont_list[i], cont_list[i + 1])
    b = min(cont_list[i], cont_list[i + 1])
    return (1 + a) * a / 2 + b * (b - 1) / 2


if ini_di == "<":
    count2 = 0
    if len(cont_list) % 2 == 0:
        for i in range(0, len(cont_list), 2):
            count2 += int(counting(i))
    else:
        for i in range(0, len(cont_list)-1, 2):
            count2 += int(counting(i))
        las = cont_list[len(cont_list)-1]
        count2 += int((1+las)*las/2)
    print(count2)
else:
    count2 = 0
    if len(cont_list) % 2 == 1:
        ini = cont_list[0]
        count2 += int((1+ini)*ini/2)
        for i in range(1, len(cont_list), 2):
            count2 += int(counting(i))
    else:
        ini = cont_list[0]
        count2 += int((1 + ini) * ini / 2)
        las = cont_list[len(cont_list) - 1]
        count2 += int((1 + las) * las / 2)
        for i in range(1, len(cont_list)-1, 2):
            count2 += int(counting(i))
    print(count2)

Submission status: Runtime Error

Solution code:
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:
        if x2>x1:
          x1=x1-1
    y+=x1*(x1+1)/2
    x1=x2
    x2=1
if s[i+1]=='>':
      if x2<x1:
        x2=x2-1
      else:
        if x2>x1:
          x1=x1-1
y+=x1*(x1+1)/2
y+=x2*(x2+1)/2
print(int(y))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(5000000000)

s = input()
cont_list = []
ini_di = s[0]
count = 1
for i in range(1, len(s)):
    if s[i] == s[i-1]:
        count += 1
        if i == len(s) - 1:
            cont_list.append(count)
    else:
        cont_list.append(count)
        count = 1
        if i == len(s) - 1:
            cont_list.append(count)


def counting(i):
    a = max(cont_list[i], cont_list[i + 1])
    b = min(cont_list[i], cont_list[i + 1])
    return (1 + a) * a / 2 + b * (b - 1) / 2


if ini_di == "<":
    count2 = 0
    if len(cont_list) % 2 == 0:
        for i in range(0, len(cont_list), 2):
            count2 += int(counting(i))
    else:
        for i in range(0, len(cont_list)-1, 2):
            count2 += int(counting(i))
        las = cont_list[len(cont_list)-1]
        count2 += int((1+las)*las/2)
    print(count2)
else:
    count2 = 0
    if len(cont_list) % 2 == 1:
        ini = cont_list[0]
        count2 += int((1+ini)*ini/2)
        for i in range(1, len(cont_list), 2):
            count2 += int(counting(i))
    else:
        ini = cont_list[0]
        count2 += int((1 + ini) * ini / 2)
        las = cont_list[len(cont_list) - 1]
        count2 += int((1 + las) * las / 2)
        for i in range(1, len(cont_list)-1, 2):
            count2 += int(counting(i))
    print(count2)

Submission status: Runtime Error

Solution code:
S=input()
L=len(S)+1
a=list[0 for n in range(L)]
c=0
plus=0

for i in S:
    c+=1
    if(a[c]==">"):
        plus+=1
    if(a[c]=="<"):
        a[c-1]=0
        for i in range(plus) :
            a[c-2-i]=plus-i
        plus=0
        a[c]=a[c-1]+1
Ans=sum(a)
print(Ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S=str(input())
s=list(S)
x1=0
x2=0
y=0
for i in range(len(s)-1):
  if s[i+1]==s[i]:
    print(x1,x2,y,"yes")
    x2=x2+1
  else:
    if s[i]=='>':
      print(i)
      if x2<x1:
        x2=x2-1
      else:
        if x2>x1:
          x1=x1-1
    y+=x1*(x1+1)/2
    print(x1,x2,y,"no")
    x1=x2
    x2=1
print(x1,x2,y)
if s[i+1]=='>':
      print(i)
      if x2<x1:
        x2=x2-1
      else:
        if x2>x1:
          x1=x1-1
y+=x1*(x1+1)/2
y+=x2*(x2+1)/2
print(x1,x2,y)
print(int(y))

Submission status: Runtime Error

Solution code:
s = list(input())
lst = []
tmpcnt = 0
ans = 0
for i, e in enumerate(s):
    if i != len(s) - 1:
        if s[i] == s[i+1]:
            tmpcnt += 1
        else:
            if i == 0:
                if s[i] == ">":
                    lst.append(1)
                if s[i] == "<":
                    lst.append(0)
            else:
                tmpcnt += 1
                if s[i] == ">":
                    if lst[len(lst)-1] == 0:
                        for j in reversed(range(tmpcnt)):
                            lst.append(j+1)
                    else:
                        for j in reversed(range(tmpcnt)):
                            lst.append(j)
                    tmpcnt = 0
                if s[i] == "<":
                    for j in range(tmpcnt+1):
                        lst.append(j)
                    tmpcnt = 0
    else:
        tmpcnt += 1
        if s[i] == ">":
            if lst[len(lst)-1] == 0:
                for j in reversed(range(tmpcnt)):
                    lst.append(j+1)
            else:
                for j in reversed(range(tmpcnt)):
                    lst.append(j)
            tmpcnt = 0
        if s[i] == "<":
            for j in range(tmpcnt+1):
                lst.append(j)
            tmpcnt = 0

for i in lst:
    ans += i
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)+1
array = [0]*(N)
for i in range(N-1):
  if S[i] == "<":
    array[i+1] = array[i] + 1
    k = i+1
#  elif array[i] > 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: Runtime Error

Solution code:
import sys
from io import StringIO
import unittest
import math


def resolve():
    s = input()
    tmpValue = 0

    upOrDownStartIndex = 0
    previousIsUp = False

    upDownList = []
    count = 1
    before = s[0]
    c = None
    for i in range(1, len(s)):
        c = s[i]

        if c != before:
            if c == '>':
                upDownList.append(count)
            elif c == '<':
                upDownList.append(-1 * count)
            else:
                raise Exception()
            count = 0

        count += 1
        before = c

    if c == '<':
        upDownList.append(count)
    elif c == '>':
        upDownList.append(-count)
    else:
        raise Exception()
    # print(upDownList)

    a = []
    beforeIsUp = False
    before = 0
    count = 0
    for i in range(len(upDownList)):
        upDown = upDownList[i]

        for i in range(abs(upDown)+1):
            count += i

        if beforeIsUp:
            if before > abs(upDown):
                count -= abs(upDown)
            else:
                count -= before

        if upDown > 0:
            beforeIsUp = True
            before = upDown
        else:
            beforeIsUp = False
        # print(count)

    print(count)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """<>>"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """<>>><<><<<<<>>><"""
        output = """28"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Runtime Error

Solution code:
s = list(input())
N = len(s)
a = [0] * (10+N)
if(s[0] == '<'): p = 0
else: p = 1
count = 0
count2 = 0
sum_ = 0
start = 0
end = 0
for i in range(N):
    if ((s[i] == '>')& (p == 0)):
        #print('a')
        count2 += 1
        p = 1
        max_ = i
    elif(p == 0):
        #print('b')
        count += 1
    elif(s[i] == '<'):
        #print('c')
        end = i
        if(count > count2):
            t = count
            a[max_] = t
            max_ -= 1
            t -= 1
            while(t >= 0):
                a[max_] = t
                max_ -= 1
                t -= 1
            k = 0
            a[end] = 0
            k += 1
            while(k < count2):
                a[end-k] = k
                k += 1
        else:
            t = count2
            a[max_] = t
            max_ += 1
            t -= 1
            while(t >= 0):
                a[max_] = t
                max_ += 1
                t -= 1
            k = 0
            a[start] = 0
            k += 1
            while(k < count):
                a[start+k] = k
                k += 1
        p = 0
        start = i
        count = 1
        count2 = 0
        max_ = 0
        #print(a)
    else:
        #print('d')
        count2 += 1
        
if(count > count2):
    if(max_==0):
        max_= N
    t = count
    a[max_] = t
    max_ -= 1
    t -= 1
    while(t >= 0):
        a[max_] = t
        max_ -= 1
        t -= 1
    k = 0
    a[end] = 0
    k += 1
    while(k < count2):
        a[end-k] = k
        k += 1
else:
    t = count2
    a[max_] = t
    max_ += 1
    t -= 1
    while(t >= 0):
        a[max_] = t
        max_ += 1
        t -= 1
    k = 0
    a[start] = 0
    k += 1
    while(k < count):
        a[start+k] = k
        k += 1
sum(a)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(4100000)

s = input()
cont_list = []
ini_di = s[0]
count = 1
for i in range(1, len(s)):
    if s[i] == s[i-1]:
        count += 1
        if i == len(s) - 1:
            cont_list.append(count)
    else:
        cont_list.append(count)
        count = 1
        if i == len(s) - 1:
            cont_list.append(count)


def counting(i):
    a = max(cont_list[i], cont_list[i + 1])
    b = min(cont_list[i], cont_list[i + 1])
    return (1 + a) * a / 2 + b * (b - 1) / 2


if ini_di == "<":
    count2 = 0
    if len(cont_list) % 2 == 0:
        for i in range(0, len(cont_list), 2):
            count2 += counting(i)
    else:
        for i in range(0, len(cont_list)-1, 2):
            count2 += counting(i)
        las = cont_list[len(cont_list)-1]
        count2 += (1+las)*las/2
    print(int(count2))
else:
    count2 = 0
    if len(cont_list) % 2 == 1:
        ini = cont_list[0]
        count2 += (1+ini)*ini/2
        for i in range(1, len(cont_list), 2):
            count2 += counting(i)
    else:
        ini = cont_list[0]
        count2 += (1 + ini) * ini / 2
        las = cont_list[len(cont_list) - 1]
        count2 += (1 + las) * las / 2
        for i in range(1, len(cont_list)-1, 2):
            count2 += counting(i)
    print(int(count2))

Submission status: Runtime Error

Solution code:
s = list(input())
N = len(s)
a = [0] * (1+N)
if(s[0] == '<'): p = 0
else: p = 1
count = 0
count2 = 0
sum_ = 0
start = 0
end = 0
for i in range(N):
    if ((s[i] == '>')& (p == 0)):
        #print('a')
        count2 += 1
        p = 1
        max_ = i
    elif(p == 0):
        #print('b')
        count += 1
    elif(s[i] == '<'):
        #print('c')
        end = i
        if(count > count2):
            t = count
            a[max_] = t
            max_ -= 1
            t -= 1
            while(t >= 0):
                a[max_] = t
                max_ -= 1
                t -= 1
            k = 0
            a[end] = 0
            k += 1
            while(k < count2):
                a[end-k] = k
                k += 1
        else:
            t = count2
            a[max_] = t
            max_ += 1
            t -= 1
            while(t >= 0):
                a[max_] = t
                max_ += 1
                t -= 1
            k = 0
            a[start] = 0
            k += 1
            while(k < count):
                a[start+k] = k
                k += 1
        p = 0
        start = i
        count = 1
        count2 = 0
        max_ = 0
        #print(a)
    else:
        #print('d')
        count2 += 1
        
if(count > count2):
    if(max_==0):
        max_= N
    t = count
    a[max_] = t
    max_ -= 1
    t -= 1
    while(t >= 0):
        a[max_] = t
        max_ -= 1
        t -= 1
    k = 0
    a[end] = 0
    k += 1
    while(k < count2):
        a[end-k] = k
        k += 1
else:
    t = count2
    a[max_] = t
    max_ += 1
    t -= 1
    while(t >= 0):
        a[max_] = t
        max_ += 1
        t -= 1
    k = 0
    a[start] = 0
    k += 1
    while(k < count):
        a[start+k] = k
        k += 1
print(sum(a))

Submission status: Runtime Error

Solution code:
str = input()
result = [0 for x in range(len)]

def plus(str,i,result):
  if i == 0 or i == (len(str) - 1):
    return
  if str[i+1] == "<":
    result[i+1] = result[i]+1
    plus(str,i+1,result)
  elif str[i-1] == ">":
    result[i-1] = result[i]+1
    plus(str,i+1,result)
  else:
    result[i] = max(str[i],str[i+1]+1)

for i in range(len(str)):
  if i == 0 and str[0] == "<":
    result[i] = 0
    plus(str,i,result)
  elif i == len(str)-1 and str[i] == ">":
    result[i] = 0
    plus(str,i,result)
  elif str[i] == ">" and str[i+1] == "<":
    result[i] = 0
    plus(str,i,result)

Submission status: Runtime Error

Solution code:
S=input()
N=len(S)
ren=[]
a=1
for i in range(N-1):
  if S[i]==S[i+1]:
    a+=1
  else:
    ren.append(a)
    a=1
  if i==N-2:
    ren.append(a)
      
M=len(ren)
ma=max(ren)
su=0
if S[0]=="<":
  if M%2==0:
    for k in range(M//2):
      if ren[2*k]<ren[2*k+1]:
        su=su+ren[2*k]*(ren[2*k]-1)//2+ren[2*k+1]*(ren[2*k+1]+1)//2
      else:
        su=su+ren[2*k]*(ren[2*k]+1)//2+ren[2*k+1]*(ren[2*k+1]-1)//2
  else:
    for k in range(M//2):
      if ren[2*k]<ren[2*k+1]:
        su=su+((ren[2*k]*(ren[2*k]-1))//2)+(ren[2*k+1]*(ren[2*k+1]+1)//2)
      else:
        su=su+ren[2*k]*(ren[2*k]+1)//2+ren[2*k+1]*(ren[2*k+1]-1)//2
    su+=ren[-1]*(ren[-1]+1)//2
if S[0]==">":
  su+=ren[0]*(ren[0]+1)//2  
  if (M-1)%2==0:
    for k in range((M-1)//2):
      if ren[1+2*k]<ren[1+2*k+1]:
        su=su+ren[1+2*k]*(ren[1+2*k]-1)//2+ren[1+2*k+1]*(ren[1+2*k+1]+1)//2
      else:
        su=su+ren[1+2*k]*(ren[1+2*k]+1)//2+ren[1+2*k+1]*(ren[1+2*k+1]-1)//2
  else:
    for k in range((M-1)//2):
      if ren[1+2*k]<ren[1+2*k+1]:
        su=su+ren[1+2*k]*(ren[1+2*k]-1)//2+ren[1+2*k+1]*(ren[1+2*k+1]+1)//2
      else:
        su=su+ren[1+2*k]*(ren[1+2*k]+1)//2+ren[1+2*k+1]*(ren[1+2*k+1]-1)//2
    su+=ren[-1]*(ren[-1]+1)//2
print(su)

Submission status: Runtime Error

Solution code:
S = input()
kei = 0
k = []
l = []
if S[0] == '<':
  k.append(0)
for i in range(len(S)-1):
  if S[i] == '>' and S[i+1] == '<':
    k.append(i+1)
  elif S[i] == '<' and S[i+1] == '>':
    l.append(i+1)
if S[len(S)] == '>':
  k.append(len(S)+1)
def summ(m):
  s = 0
  if m != 0:
    for j in range(1,m+1):
      s += j
  return s
for p in range(len(k)-1):
  if k[p+1] - l[p] > l[p] - k[p]:
    kei += summ(k[p+1] - l[p]) + summ(l[p]-k[p] - 1)
  else:
    kei += summ(k[p+1] - l[p] - 1) + summ(l[p]-k[p])
print(kei)

Submission status: Runtime Error

Solution code:
S = list(str(input()))

count = 0
count_bef = 0
count_list=[]
count_list2=[]
minus = []
for i in range(len(S)-1):
  if S[i] == S[i+1]:
    count += 1
  elif not S[i] ==S[i+1]:
    count_list.append(int((count+1)*(count+2)/2))
    count_list2.append(count+1)
    count = 0
count_list.append(int((count+1)*(count+2)/2))
count_list2.append(count+1)
if S[0] == "<":
  for i in range(len(count_list2)//2):
    minus.append(min(count_list2[2*i], count_list2[2*i+1]))
elif S[0] == ">":
  for i in range(len(count_list2)//2):
    minus.append(min(count_list2[2*i+1], count_list2[2*i+2]))
    
#print(count_list)
#print(count_list2)
#print(minus)
print(sum(count_list)-sum(minus))

Submission status: Runtime Error

Solution code:
S = input()
S_length = len(S)
k = 1
s_l=[]
for i in range(S_length-1):
  s_x=S[i]
  if S[i+1]==s_x:
    k+=1
  else:
    s_l.append(s_x*k)
    k=1

if s_l[-1][0]!=S[-1]:
  s_l.append(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: Runtime Error

Solution code:
S = str(input())
a = []
ans = 0

def sumn(x):
    y = x * (x+1)//2
    return y
    
cnt = 1

if len(S) == 1:
    ans = 1
    print(ans)
else:
    for i in range(len(S)-1):
        if S[i+1] == S[i]:
            cnt += 1
            if i+1 == len(S)-1:
                a.append(cnt)
        
        else:
            a.append(cnt)
            cnt = 1
            if i+1 == len(S)-1:
                a.append(cnt)
            
    if S[0] == '<':
        for i in range(len(a)):
            if i % 2 == 0:
                ans += sumn(a[i])
            else:
                if a[i] > a[i-1]:
                    ans += (sumn(a[i]) - a[i-1])
                else:
                    ans += sumn(a[i]-1)
    else:
        if i == 0:
            ans += sumn(a[i])
        elif i % 2 == 1:
            ans += sumn(a[i])
        else:
            if a[i] > a[i-1]:
                ans += (sumn(a[i]) - a[i-1])
            else:
                ans += sumn(a[i]-1)
    print(ans)

Submission status: Runtime Error

Solution code:
s=str(input())
n=len(s)
i=0
ans=0
c=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: Runtime Error

Solution code:
S = input().strip()
V = []
for i in range(len(S)-1):
    if S[i]==">" and S[i+1]=="<":
        V.append(i+1)
if S[-1]==">":
    V.append(len(S))
B = [0 for _ in range(len(S)+1)]
for i in range(len(S)):
    if S[i]==">":
        B[i+1] = B[i]-1
    else:
        B[i+1] = B[i]+1
for j in V:
    if B[j]<0:
        B[j] = 0
        cur = j-1
        while S[cur]==">":
            B[cur] = max(B[cur],B[cur+1]+1)
            cur -= 1
        cur = j
        while cur<len(S) and S[cur]=="<":
            B[cur+1]=B[cur]+1
            cur += 1
    elif B[j]>0:
        B[j] = 0
        cur = j-1
        while S[cur]==">":
            if cur-1>=0 and S[cur-1]==">":
                B[cur] = B[cur+1]+1
            cur -= 1
        cur = j
        while cur<len(S) and S[cur]=="<":
            B[cur+1] = B[cur]+1
            cur += 1
print(sum(B))

Submission status: Runtime Error

Solution code:
s = list(input())
N = len(s)
a = [0] * (1+N)
if(s[0] == '<'): p = 0
else: p = 1
count = 0
count2 = 0
sum_ = 0
start = 0
end = 0
for i in range(N):
    if ((s[i] == '>')& (p == 0)):
        #print('a')
        count2 += 1
        p = 1
        max_ = i
    elif(p == 0):
        #print('b')
        count += 1
    elif(s[i] == '<'):
        #print('c')
        end = i
        if(count > count2):
            t = count
            a[max_] = t
            max_ -= 1
            t -= 1
            while(t >= 0):
                a[max_] = t
                max_ -= 1
                t -= 1
            k = 0
            a[end] = 0
            k += 1
            while(k < count2):
                a[end-k] = k
                k += 1
        else:
            t = count2
            a[max_] = t
            max_ += 1
            t -= 1
            while(t >= 0):
                a[max_] = t
                max_ += 1
                t -= 1
            k = 0
            a[start] = 0
            k += 1
            while(k < count):
                a[start+k] = k
                k += 1
        p = 0
        start = i
        count = 1
        count2 = 0
        max_ = 0
        #print(a)
    else:
        #print('d')
        count2 += 1
        
if(count > count2):
    if(max_==0):
        max_= N
    t = count
    a[max_] = t
    max_ -= 1
    t -= 1
    while(t >= 0):
        a[max_] = t
        max_ -= 1
        t -= 1
    k = 0
    a[end] = 0
    k += 1
    while(k < count2):
        a[end-k] = k
        k += 1
else:
    t = count2
    a[max_] = t
    max_ += 1
    t -= 1
    while(t >= 0):
        a[max_] = t
        max_ += 1
        t -= 1
    k = 0
    a[start] = 0
    k += 1
    while(k < count):
        a[start+k] = k
        k += 1
sum(a)

Submission status: Runtime Error

Solution code:
s=list(input())
a=[0]*(len(s)+1)
if s[0]=='<':
    a[0]=0
    l=0
    while s[l]=='<':
        a[l+1]=a[l]+1
        l+=1
        if l>len(s)-1:
          break
if s[len(s)-1]=='>':
    a[len(s)]=0
    m=len(s)-1
    while s[m]=='>':
        a[m]=a[m+1]+1
        m-=1
for i in range(len(s)-1):
    if s[i]=='>' and s[i+1]=='<':
        a[i+1]=0
        k=i
        t=i+1
        while s[k]=='>':
            a[k]=a[k+1]+1
            k-=1
            if k<0 or k>len(s)-1:
                break
        while s[t]=='<':
            a[t+1]=a[t]+1
            t+=1
            if t<0 or t>len(s)-1:
                break
for i in range(len(s)-1):
    if s[i]=='<' and s[i+1]=='>':
        a[i+1]=max(a[i],a[i+2])+1
print(sum(a))

Submission status: Runtime Error

Solution code:
import numpy as np

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

    if s[0] == '<':
        n_list[0] = 0
    else:
        n_list[1] = 1

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


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
s=list(input())
a=[0]*(len(s)+1)
if s[0]=='<':
    a[0]=0
    l=0
    while s[l]=='<':
        a[l+1]=a[l]+1
        l+=1
if s[len(s)-1]=='>':
    a[len(s)]=0
    m=len(s)-1
    while s[m]=='>':
        a[m]=a[m+1]+1
        m-=1
for i in range(len(s)-1):
    if s[i]=='>' and s[i+1]=='<':
        a[i+1]=0
        k=i
        t=i+1
        while s[k]=='>':
            a[k]=a[k+1]+1
            k-=1
            if k<0 or k>len(s)-1 or s[k]=='<':
                break
        while s[t]=='<':
            a[t+1]=a[t]+1
            t+=1
            if t<0 or t>len(s)-1 or s[t]=='>':
                break
for i in range(len(s)-1):
    if s[i]=='<' and s[i+1]=='>':
        a[i+1]=max(a[i],a[i+2])+1
print(sum(a))

Submission status: Runtime Error

Solution code:
S = input()
slst = [[] for _ in range(len(S))]
tmp = '<'
cnt = 0
index = 0
for i in range(len(S)):
    if tmp == S[i]:
        cnt += 1
    else:
        slst[index].append(tmp)
        slst[index].append(cnt)
        index += 1
        tmp = S[i]
        cnt = 1

slst[index].append(tmp)
slst[index].append(cnt)

ans = 0
for i in range(0, len(S), 2):
    if slst[i] == []:
        break
    elif slst[i + 1] == []:
        ans += ((slst[i][1] + 1) * ((slst[i][1]))) // 2
        break
    tmp = ((slst[i + 1][1]) * ((slst[i + 1][1] - 1))) // 2
    ans += tmp
    if slst[i + 1][1] >= slst[i][1]:
        ans += slst[i + 1][1]
    else:
        ans += ((slst[i][1] + 1) * ((slst[i][1]))) // 2

print(ans)