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:
def inc(a, b, inc_a, a_max, b_max, n, n_max):
    cnt = 0
    n += 1

    if inc_a:
        a += 1
    else:
        b += 1

    if a == a_max and b == b_max and n == n_max:
        return 1

    if a > b or a > a_max or b > b_max or n > n_max:
        return 0

    cnt += inc(a, b, True, a_max, b_max, n, n_max)
    cnt += inc(a, b, False, a_max, b_max, n, n_max)
    cnt += same(a, b, a_max, b_max, n, n_max)
    return cnt


def same(a, b, a_max, b_max, n, n_max):
    if b - a == 1:
        return 0

    cnt = 0
    n += 1

    a = b

    if a == a_max and b == b_max and n == n_max:
        return 1

    if a > b or a > a_max or b > b_max or n > n_max:
        return 0

    cnt += inc(a, b, True, a_max, b_max, n, n_max)
    cnt += inc(a, b, False, a_max, b_max, n, n_max)
    cnt += same(a, b, a_max, b_max, n, n_max)
    return cnt


if __name__ == '__main__':
    n_max, a_max, b_max = list(map(int, input().split()))
    n = 0
    a = 0
    b = 0
    cnt = 0

    cnt += inc(a, b, False, a_max, b_max, n, n_max)
    cnt += same(a, b, a_max, b_max, n, n_max)
    print(cnt)

Submission status: Runtime Error

Solution code:
s=input()

list=[0 for _ in range(len(s) + 1)]

def inc(n):
    if n < 0 or len(s) < n + 1:
        return

    if '<' == s[n]:
        if list[n] >= list[n + 1]:
            list[n + 1] += list[n] - list[n + 1] + 1
            inc(n + 1)

    elif '>' == s[n]:
        if list[n] <= list[n + 1]:
            list[n] += list[n + 1] - list[n] + 1
            inc(n - 1)

for i in range(len(s)):
    inc(i)

print(sum(list))

Submission status: Runtime Error

Solution code:
S = list(input()) + ["A"]

now = S[0]
renzoku = []
counter = 1
for c in S[1:]:
    if c == now:
        counter += 1
        now = c
    else:
        renzoku.append(counter)
        counter = 1
        now = c

ans = 0
for kigou in renzoku:
    ans += sum(range(1, kigou + 1))

if S[0] == "<":
    for right in range(1, len(renzoku), 2):
        kill = min(renzoku[right], renzoku[right - 1])
        ans -= kill
    print(ans)

else:
    for left in range(len(renzoku) - 1, 2):
        kill = min(renzoku[left], renzoku[left + 1])
        ans -= kill
    print(ans)

Submission status: Runtime Error

Solution code:
import itertools
f = lambda n:n*(n+1)//2

def sol():
  res = 0
  while q:
    x0 = q.popleft()
    x1 = q.popleft()
    res += f(max(x0, x1)) + f(min(x0, x1)-1)
    return res

s = input()

q = collections.deque()
for k, g in itertools.groupby(s):
  q.append(len(list(g)))
if len(q) % 2:
  q.append(1)

print(sol())

Submission status: Runtime Error

Solution code:
import itertools
f = lambda n:n*(n+1)//2

def sol():
    res = 0
    while q:
        x0 = q.popleft()
        x1 = q.popleft()
        res += f(max(x0, x1)) + f(min(x0, x1) -1)
    return res

s = input().rstrip("\n")

q = collections.deque()
for k, g in itertools.groupby(s):
    q.append(len(list(g)))
if len(q) % 2:
    q.append(1)

print(sol())

Submission status: Runtime Error

Solution code:
import itertools
f = lambda n:sum(i for i in range(n+1))

def sol():
    res = 0
    while q:
        x0 = q.popleft()
        x1 = q.popleft()
        res += f(max(x0, x1)) + f(min(x0, x1) -1)
    return res

s = input().rstrip("\n")

q = collections.deque()
for k, g in itertools.groupby(s):
    q.append(len(list(g)))
if len(q) % 2:
    q.append(1)

print(sol())

Submission status: Runtime Error

Solution code:
import itertools
f = lambda n:sum(i for i in range(n+1))

def sol():
    res = 0
    while q:
        x0 = q.popleft()
        x1 = q.popleft()
        res += f(max(x0, x1)) + f(min(x0, x1) -1)
    return res

s = input()

q = collections.deque()
for k, g in itertools.groupby(s):
    q.append(len(list(g)))
if len(q) % 2:
    q.append(1)

print(sol())

Submission status: Runtime Error

Solution code:
S = list(input()) + ["A"]

now = S[0]
renzoku = []
counter = 1
for c in S[1:]:
    if c == now:
        counter += 1
        now = c
    else:
        renzoku.append(counter)
        counter = 1
        now = c

ans = 0
for kigou in renzoku:
    ans += sum(range(1, kigou + 1))

if S[0] == "<":
    for right in range(1, len(renzoku), 2):
        kill = min(renzoku[right], renzoku[right - 1])
        ans -= kill
        print(ans)

else:
    for left in range(len(renzoku) - 1, 2):
        kill = min(renzoku[left], renzoku[left + 1])
        ans -= kill
        print(ans)

Submission status: Runtime Error

Solution code:
S = list(input()) + ["A"]

now = S[0]
renzoku = []
counter = 1
for c in S[1:]:
    print(now, c)
    if c == now:
        counter += 1
        now = c
    else:
        renzoku.append(counter)
        counter = 1
        now = c

ans = 0
for kigou in renzoku:
    ans += sum(range(1, kigou + 1))

if S[0] == "<":
    for right in range(1, len(renzoku), 2):
        kill = min(renzoku[right], renzoku[right - 1])
        print(kill)
        ans -= kill
        print(ans)

else:
    for left in range(len(renzoku) - 1, 2):
        kill = min(renzoku[left], renzoku[left + 1])
        ans -= kill
        print(ans)

Submission status: Runtime Error

Solution code:
S = list(input()) + ["A"]

now = S[0]
renzoku = []
counter = 1
for c in S[1:]:
    print(now, c)
    if c == now:
        counter += 1
        now = c
    else:
        renzoku.append(counter)
        counter = 1
        now = c

ans = 0
for kigou in renzoku:
    ans += sum(range(1, kigou + 1))

if S[0] == "<":
    for right in range(1, len(renzoku), 2):
        kill = min(renzoku[right], renzoku[right - 1])
        print(kill)
        ans -= kill
        print(ans)

else:
    for left in range(len(renzoku), 2):
        kill = min(renzoku[left], renzoku[left + 1])
        ans -= kill
        print(ans)

Submission status: Runtime Error

Solution code:
S = input()
n = len(S)
ans = [0]*(n+1)
for i in range(n):
    if S[i]=='<':
        ans[i]=ans[i-1]+1
for i in range(n-1,-1,-1):
    if S[i]==">":
        ans[i]=ans[i+1]+1
res = 0
for i in range(n+1):
    res+=ans[i]
return res

Submission status: Runtime Error

Solution code:
n=int(input())
a=input()
p=0
q=0
r=0
i=0
while i<n-1:
  while a[i]=="<":
    i+=1
    p+=1
    if i==n-1:
      print(r+p*(p+1)//2)
      exit(0)
  while a[i]==">":
    i+=1
    q+=1
    if i==n-1:
      break
  r+=p*(p+1)//2+q*(q+1)//2-min(p,q)
  p=0
  q=0
print(r)

Submission status: Runtime Error

Solution code:
s = input()
a = [0] * (len(s) + 1)
cur = 0
for i in range(len(s)):
  a[i] = cur
  cur = 0 if s[i] == '>' else cur + 1 
a[-1] = cur
cur = 0
for i in range(len(s)).reversed():
  a[i + 1] = max(a[i + 1], cur)
  cur = 0 if s[i] == '<' else cur + 1
a[0] = max(a[0], cur)
print(sum(a))

Submission status: Runtime Error

Solution code:
S=input()
n=len(S)

def sums(a):
  return (a+1)*a//2

def f(s):
  n=len(s)
  i=0
  while i<n and s[i]=='<':
    i+=1
  if i==n:
    return sums(i)
  else:
    j=i+1
    while j<n and s[j]=='>':
      j+=1
    if i>(j-i):
      temp=sums(i)+sums(j-i-1)
    else:
      temp=sums(j-i)+sums(i-1)
      
    if j<n:
      temp+=f(s[j:])
      
    return temp

if S[0]=='<':
  ans=f(S)
else:
  i=0
  while i<n and S[i]=='>':
    i+=1
    
  if i==n:
    ans=sums(i)
  else:
    ans=sums(i)+f(S[i:])
    
print(ans)

Submission status: Runtime Error

Solution code:
def flood(s, v, idx, val):
  v[idx] = max(val, v[idx])
  
  if idx < len(v) - 1 and s[idx + 1] == '<':
    flood(s, v, idx + 1, val + 1)
  if idx > 0 and s[idx] == '>':
    flood(s, v, idx - 1, val + 1)

def main():
  s = '>' + input().strip() + '<'
  v = [-1] * (len(s) - 1)
  
  for i, (b, a) in enumerate(zip(s[:-1], s[1:])):
    if b == '>' and a == '<':
      flood(s, v, i, 0)

  #print(v)
  print(sum(v))
  
if __name__ == '__main__':
  main()

Submission status: Runtime Error

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

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

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

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

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

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


print(np.sum(a))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

s=int(input())
n=len(s)+1
ans=[0]*n
for i in range(n-1):
    if s[i]=='<':
        ans[i+1]=max(ans[i+1],ans[i]+1)
for i in range(n-2,-1,-1):
    if s[i]=='>':
        ans[i]=max(ans[i+1]-1,ans[i])
print(sum(ans))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

s=int(input())
n=len(s)+1
ans=[0]*n
for i in range(n-1):
    if s[i]=='<':
        ans[i+1]=max(ans[i+1],ans[i]+1)
for i in range(n-2,-1,-1):
    if s[i]=='>':
        ans[i]=max(ans[i+1]-1),ans[i]
print(sum(ans))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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


void solve(std::string S){

}

// 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)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)

n = int(input())
LR = [tuple(map(int, input().split())) for _ in range(n)]

def quicksort(x):
    if x==[]: return []

    smallerSorted = quicksort([a for a in x[1:] if a[0] < x[0][0] or (a[0] == x[0][0] and a[1] => x[0][1])])
    biggerSorted = quicksort([a for a in x[1:] if a[0] > x[0][0] or (a[0] == x[0][0] and a[1] < x[0][1])])

    return(smallerSorted+[x[0]]+biggerSorted)

LR = quicksort(LR)

ans = [0] * (n+1)
temp = 10 ** 9
i = 1
for L, R in LR:
    temp = min(temp, R)
    if L > temp:
        break   
    ans[i] = temp - L + 1
    i += 1

temp = 10 ** 9
i = n - 1
L = LR[-1][0]
for x, R in reversed(LR):
    temp = min(temp, R)
    if L > temp:
        break
    ans[i] += temp - L + 1
    i -= 1

res = max(ans)
for L, R in LR:
    res = max(res, R - L + 1)

print(res)

Submission status: Runtime Error

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

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

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

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

print(sum(a))

Submission status: Runtime Error

Solution code:
s = raw_input()
m = 0
cur = 0
ans = 0
for i in xrange(len(s)):
  if s[i] == '<':
    cur += 1
    ans += cur
  else:
    cur -= 1
    ans += cur
    if cur < min:
      min = cur
ans += (-1)*min*(len(s)+1)
print ans

Submission status: Runtime Error

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

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

def plus_right(str,i,result):
  if i == 0 or i == len(str):
    return
  if str[i] == "<":
    result[i+1] = result[i]+1
    plus_right(str,i+1,result)
  elif str[i] == ">":
    result[i] = max(result[i],result[i+1]+1)
    
for i in range(len(str)):
  if i == 0 and str[0] == "<":
    result[i] = 0
    plus_right(str,i,result)
 
  elif i == len(str)-1 and str[i] == ">":
    result[i] = 0
    plus_left(str,i,result)

  elif str[i-1] == ">" and str[i] == "<":
    result[i] = 0
    plus_left(str,i,result)
    plus_right(str,i,result)

s = 0    
for i in result:
  s += i
print(s)

Submission status: Runtime Error

Solution code:
s = input()
direction = []
cnt_array = []
cnt = 1
for i in range(1, len(s)):
    if s[i] != s[i - 1]:
        direction.append(s[i - 1])
        cnt_array.append(cnt)
        cnt = 1
    else:
        cnt += 1
else:
    direction.append(s[i])
    cnt_array.append(cnt)

ans = 0
now = 0
ans_array = [now]
for i in range(1, len(direction)):
    if direction[i - 1] == "<" and direction[i] == ">":
        ans_array.append(max(cnt_array[i - 1], cnt_array[i]))
        if cnt_array[i - 1] < cnt_array[i]:
            ans_array.append(cnt_array[i - 1] - 1)
        elif cnt_array[i] < cnt_array[i - 1]:
            ans_array.append(cnt_array[i] - 1)
else:
    if direction[-1] == "<":
        ans += 1
print(ans + sum([(x * (x + 1)) // 2 for x in ans_array]))

Submission status: Runtime Error

Solution code:
def perm_cul(N):
    return N * (N + 1) // 2
S = input()
N = len(S)
cnt_list = []
cnt = 1
ans = 0
if N == 1:
    print(1)
    exit()
for i in range(N-1):
    if S[i] == S[i+1]:
        cnt += 1
    elif S[i] != S[i+1]:
        cnt_list.append(cnt)
        cnt = 1
    if i == N-2:
        cnt_list.append(cnt)
##print(cnt_list)
if S[0] == '<' and S[N-1] == '<':
    for i in range(len(cnt_list) - 1):
        ans += perm_cul(cnt_list[i]-1)
        if i % 2 == 1:
            ans += max(cnt_list[i-1], cnt_list[i])
    ans += perm_cul(cnt_list[len(cnt_list) - 1])

elif S[0] == '<' and S[N-1] == '>':
    for i in range(len(cnt_list)):
        ans += perm_cul(cnt_list[i]-1)
        if i % 2 == 1:
            ans += max(cnt_list[i-1], cnt_list[i])

elif S[0] == '>' and S[N-1] == '>':
    ans += perm_cul(cnt_list[0])
    for i in range(1, len(cnt_list)):
        ans += perm_cul(cnt_list[i] - 1)
        if i % 2 == 0:
            ans += max(cnt_list[i], cnt_list[i+1])

else:
    ans += perm_cul(cnt_list[0])
    for i in range(1, len(cnt_list) - 1):
        ans += perm_cul(cnt_list[i]-1)
        if i % 2 == 0:
            ans += max(cnt_list[i-1], cnt_list[i])
    ans += perm_cul(cnt_list[len(cnt_list) - 1])

print(ans)

Submission status: Runtime Error

Solution code:
import sys
s = [s for s in sys.stdin.readline().rstrip()]

ans = 0
if s[0] == '>':
    count = 1
    i = 1
    while s[i] == '>':
        count += 1
        i += 1
    del s[:i]
    ans += (1 + count) * count // 2

if s[-1] == '<':
    count = 1
    i = -2
    while s[i] == '>':
        count += 1
        i -= 1
    del s[i+1:]
    ans += count
    (1 + count) * count // 2

s.append(None)

while s != [None]:
    l_c, r_c = 0, 0
    i = 0
    # if s[i] == '<':
    while s[i] == '<':
        l_c += 1
        i += 1
    del s[:i]

    j = 0
    # if s[j] == '>':
    while s[j] == '>':
        r_c += 1
        j += 1
    del s[:j]

    if l_c >= r_c:
        ans += (1 + l_c) * l_c // 2 + r_c * (r_c - 1) // 2
    else:
        ans += l_c * (l_c - 1) // 2 + (1 + r_c) * r_c // 2

print(ans)

Submission status: Runtime Error

Solution code:
from itertools import groupby

r = p = 0
for k, g in groupby(input()):
    r += sum(i for i, _ in enumerate(g, 1))
    if k == '>':
        r -= min(i, p)
    p = i
print(r)

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-1):
		if (i == 0 and s[i] == '<'):
				a[i] == 0
				while s[i] == "<" and i < n-1:
            a[i+1] = max(a[i]+1, a[i+1])
            i += 1
    elif s[i-1] == ">" and s[i] == "<":
        		a[i] = 0
       			j = i
        
        while s[i-1] == ">":
            a[i-1] = max(a[i-1], a[i] +1)
            i -= 1
        while s[j] == "<":
            a[j+1] = max(a[j]+1, a[j+1])
            j += 1
    else:
     		pass

print(sum(a))

Submission status: Runtime Error

Solution code:
def sum_triangle(x):
    if x > 0:
        return x + sum_triangle(x - 1)
    else:
        return 0
    

s = input().replace("><", "> <")
new_s = s.split(" ")

a = [0] * len(new_s)

for i in range(len(new_s)):
    if new_s[i].count("<") >= new_s[i].count(">"):
        a[i] = sum_triangle(new_s[i].count("<"))
        a[i] += sum_triangle(new_s[i].count(">") - 1)
    else:
        a[i] = sum_triangle(new_s[i].count(">"))
        a[i] += sum_triangle(new_s[i].count("<") - 1)

print(sum(a))

Submission status: Runtime Error

Solution code:
S = input()

length = len(S) + 1
ans = [0] * length
flag = False
for x in range(len(S)) :
  if flag :
    if S[x] == '>' :
      continue
    else :
      flag = False
  if S[x] == '<' :
    ans[x+1] = ans[x] + 1
  else :
    if S[x+1] == '>' :
      for y in range(x+1,len(S)) :
        if S[y] == '>' :
          for z in range(x,y+1) :
            ans[z] += 1
          if ans[x] > ans[x+1] + 1 :
            ans[x] -= 1
        else :
          break
      flag = True

print(sum(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
S = input()
N = len(S)
good = np.zeros(N+1)
for i in range(N):
    if S[i] == '<':
        good[i+1] = good[i] + 1
    else:
        if good[i] == 0:
            good += 1
        good[i+1] = 0
def checkNum(i):
    if S[i-1] == '<':
        left = good[i-1] < good[i] - 1
    else:
        left = True
    if S[i] == '>':
        right = good[i] - 1 > good[i+1]
    else:
        right = True
    return left & right
if S[0] == '<':
        good[0] = 0
if S[N-1] == '>':
        good[N+1] = 0
pregood = np.zeros(N+1)
while(np.allclose(good,pregood)):
    pregood = good

    if S[0] == '>':
        good[0] = good[1] + 1
    if S[N-1] == '<':
        good[N] = good[N-1] + 1
    for i in range(N-1):
        if checkNum(i+1) == 1:
            good[i+1] -= 1    
int(sum(good))

Submission status: Runtime Error

Solution code:
S = input()
def rle_encode(data):
    encoding = []
    prev_char = ''
    count = 1

    if not data: return ''

    for char in data:
        # If the prev and current characters
        # don't match...
        if char != prev_char:
            # ...then add the count and character
            # to our encoding
            if prev_char:
                encoding.append([int(count), prev_char])
            count = 1
            prev_char = char
        else:
            # Or increment our counter
            # if the characters do match
            count += 1
    else:
        # Finish off the encoding
        encoding.append([int(count), prev_char])
        return encoding

S_rle = list(rle_encode(S))
total = 0
if S_rle[0][1] == '>':
  head = S_rle[0]
  S_rle.pop(0)
  total += sum(range(head[0]+1))
else:
  head = []
if S_rle[-1][1] == '<':
  tail = S_rle[-1]
  S_rle.pop(-1)
  total += sum(range(tail[0]+1))
else:
  tail = []
body = S_rle[:]
for i in range(len(body)//2):
  num1, num2 = body[2*i][0], body[2*i+1][0]
  total += sum(range(max(num1, num2)+1)) + sum(range(min(num1, num2)))
print(total)

Submission status: Runtime Error

Solution code:
import re

if __name__ == "__main__":
    ans = 0
    max_count = 1
    S = input()
    if S[0] == "<":
        S = "0" + S
    while re.search("><", S) is not None:
        S_resarched = re.search("><", S).span()
        S = S[:S_resarched[0]] + "0" + S[S_resarched[1]:]
        print("S = " + S)
    while re.search(r"0+0", S) is not None:
        S_zero = re.search(r"0+0", S)
        S_zero_span = S_zero.span()
        S_zero_str = S[S_zero_span[0]:S_zero_span[1]]
        print("S_zero = " + S_zero_str)
        S_in_r = S.count("<") # この場合にSi= ai < a+1
        S_in_l = S.count(">") # この場合にSi= ai > a+1
        if S_in_l < S_in_r:
            S_in_l = S_in_r
        for i in range(S_in_l):
            ans += i
    print("ans = " + str(ans))

Submission status: Runtime Error

Solution code:
S = input()
def rle_encode(data):
    encoding = []
    prev_char = ''
    count = 1

    if not data: return ''

    for char in data:
        # If the prev and current characters
        # don't match...
        if char != prev_char:
            # ...then add the count and character
            # to our encoding
            if prev_char:
                encoding.append([int(count), prev_char])
            count = 1
            prev_char = char
        else:
            # Or increment our counter
            # if the characters do match
            count += 1
    else:
        # Finish off the encoding
        encoding.append([int(count), prev_char])
        return encoding

S_rle = list(rle_encode(S))
total = 0
if S_rle[0][1] == '>':
  head = S_rle[0]
  S_rle.pop(0)
  total += sum(range(head[0]))
else:
  head = []
if S_rle[-1][1] == '<':
  tail = S_rle[-1]
  S_rle.pop(-1)
  total += sum(range(tail[0]))
else:
  tail = []
body = S_rle[:]
for i in range(len(body)//2):
  num1, num2 = body[2*i][0], body[2*i+1][0]
  total += sum(range(max(num1, num2)+1)) + sum(range(min(num1, num2)))
print(total)

Submission status: Runtime Error

Solution code:
s=input()
l=len(s)
success = []
suc = 1
for i in range(l-1):
  if s[i]==s[i+1]:
    suc += 1
  else:
    success.append(suc)
    suc = 1
  if i==l-2: success.append(suc)
ans = 0
def sum(n):
  ans=0
  for i in range(n):
    ans += (i+1)
  return ans
if s[0]=="<":
  for i in range((len(success)+1)//2):
    ans += sum(success[2*i]-1)
    if len(success)-1 >= 2*i+1:
      ans += sum(success[2*i+1]-1)
      ans += max(success[2*i],success[2*i+1])
  if s[l-1]=="<":
    ans+=success[len(success)-1]
else:
  ans+=s[0]
  for i in range((len(success)+1)//2):
    ans += sum(success[2*i]-1)
    if len(success)-1 >= 2*i+1:
      ans += sum(success[2*i+1]-1)
      ans += max(success[2*i],success[2*i+1])
    if s[l-1]=="<":
    	ans+=success[len(success)-1]
print(ans)

Submission status: Runtime Error

Solution code:
import re

S = input()

a = [-1] * (len(S) + 1)

zero_pos = []
if S[0] == "<":
    zero_pos.append(0)
    a[0] = 0
if S[-1] == ">":
    zero_pos.append(len(S) + 1)
    a[-1] = 0
for i in range(len(S)):
    if S[i:i+2] == "><":
        zero_pos.append(i + 1)
        a[i + 1] = 0

for j in zero_pos:
    if j == len(S):
        a[j + 1] = 1
    elif j > len(S):
        continue
    elif j == len(S) - 1:
        a[-1] = 1
    elif j == 0:
        v = 0
        while S[j + 1] == "<":
            a[j + 1] = v + 1
            j += 1
            v += 1
    else:
        v = 0
        while S[j + 1] == "<":
            a[j + 1] = v + 1
            j += 1
            v += 1
        a[j + 1] = v + 1

for k in zero_pos:
    if k == 0:
        continue
    elif k == len(S) + 1:
        v = 0
        while S[k - 2] == ">":
            a[k - 2] = v + 1
            k -= 1
            v += 1
    else:
        v = 0
        while a[k - 1] == -1:
            a[k - 1] = v + 1
            k -= 1
            v += 1

sum = 0
for m in a:
    sum += int(m)
print(sum)

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= 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(a)
print(sum(a))

Submission status: Runtime Error

Solution code:
s=input()
l=len(s)
success = []
suc = 1
for i in range(l-1):
  if s[i]==s[i+1]:
    suc += 1
  else:
    success.append(suc)
    suc = 1
  if i==l-2: success.append(suc)
ans = 0
def sum(n):
  ans=0
  for i in range(n):
    ans += (i+1)
  return ans
if s[0]=="<":
  for i in range((len(success)+1)//2):
    ans += sum(success[2*i]-1)
    if len(success)-1 >= 2*i+1:
      ans += sum(success[2*i+1]-1)
      ans += max(success[2*i],success[2*i+1])
  if s[l-1]=="<":
    ans+=success[len(success)-1]
else:
  ans+=s[0]
  for i in range((len(success)+1)//2):
     ans += sum(success[2*i]-1)
    if len(success)-1 >= 2*i+1:
      ans += sum(success[2*i+1]-1)
      ans += max(success[2*i],success[2*i+1])
    if s[l-1]=="<":
    ans+=success[len(success)-1]
print(ans)

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

array = [[], []]
a=0
tmp_count = 0
before_count = 0

if S[0] == '<':
    now_array = 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]
  
        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:
    now_array = 1
    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]
        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)