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:
n = list(input())
counter = 1
directions = []
list = []
def add_up(x):
    added = (1/2) * x * (x + 1)
    return added

for i in range(len(n)-1):
    if n[i] == n[i+1]:
        counter += 1
    else:
        directions.append(counter)
        counter = 1
if n[-1] == n[-2]:
    directions[-1] += 1
else:
    directions.append(1)
if n[0] == "<":
    for i in range(0,len(directions)-1,2):
        if directions[i] > directions[i+1]:
            directions[i+1] -= 1
        elif directions[i] < directions[i+1]:
            directions[i] -= 1
else:
    for i in range(1,len(directions)-1,2):
        if directions[i] > directions[i+1]:
            directions[i+1] -= 1
        elif directions[i] < directions[i+1]:
            directions[i] -= 1
for direction in directions:
    list.append(add_up(direction))
print(round(sum(list)))

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10**5+10)

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

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

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

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

while next_num != -1:
	solve(next_num)

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

Submission status: Runtime Error

Solution code:
S = str(input())
S += "<"
l = 0
r = 0
ans = 0
tmp = ">"
for i in range(len(s)):
    if tmp == ">" and S[i] == "<":
        ans += max(l, r) * (max(l, r) + 1) / 2 + min(l, r) - 1
        l = 1
        r = 0
        tmp = S[i]
    else:
        if S[i] == ">":
            r += 1
        else:
            l += 1
        tmp = S[i]
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
b = []
sho = 0
dai = 0
for i in range(len(s)):
	if(i == 0 and s[i+1] == ">"):continue
	if s[i] == "<":
		dai = 0
		sho += 1
		b.append(sho)
	else:
		sho = 0
		if(s[i-1] == "<" and i != 1):continue
		dai += 1
		b.append(dai)
#print(b)
print (sum(b))

Submission status: Runtime Error

Solution code:
s = input()
b = s[0]
cou = 0
if len(s)==2:
    if s[0]=='>' and s[1] =='<':
        print(2)
        exit()

lis = []
for i in s:
    if b ==i:
        if i=='<':
            cou-=1
        else:
            cou+=1
    else:
        lis.append(cou)
        b = i
        if b=='<':
            cou =-1
        else:
            cou = 1
lis.append(cou)
l = len(lis)
sum = 0

for i in range(0,l,2):
    if i+1 == l and (i+1)%2==1:
        a = abs(lis[i])
        sum += a*(a+1)//2
        break
    a = abs(lis[i])
    b = abs(lis[i+1])

    if a < b:
		sum += b*(b+1)//2
		sum += (a-1)*a//2
    else:
        sum += a*(a+1)//2
        sum += (b-1)*b//2        
print(sum)

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(1, len(S), 2):
    if slst[i] == []:
        break
    tmp = ((slst[i][1]) * ((slst[i][1] - 1))) // 2
    ans += tmp
    if slst[i][1] >= slst[i - 1][1]:
        ans += tmp + 1
    else:
        ans += ((slst[i - 1][1] + 1) * ((slst[i - 1][1]))) // 2

print(ans)

Submission status: Runtime Error

Solution code:
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 = input()
result = 0
for sp in S.split("><"):
    num_l = sp.count("<")
    num_g = sp.count(">")
    M = max(num_l, num_g)
    m = min(num_l, num_g)
    if sp[0] == ">":
        if M > 0:
            d = (M + 2) * (M + 1) / 2
            result += d
        if m > 0:
            d = m * (m + 1) / 2
            result += d
    else:
        d = (M + 0) * (M + 1) / 2
        result += d
print(int(result))

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
lst=[]
cnt=1

if n==2:
  print(1)
  
for i in range(n-2):
  if s[i]==s[i+1]:
    cnt+=1
  else:
    lst.append(cnt)
    cnt-=(cnt-1)
    
totl=0
l=len(lst)
if s[0]=='<':
  for j in range(l):
    if j%2==0:
      totl+=(lst[j]*(lst[j]-1))//2
      totl+=max(lst[j],lst[min(j+1,l-1)])
    else:
      totl+=(lst[j]*(lst[j]-1))//2
  print(totl)
else:
  totl+=lst[0]
  for j in range(len(lst)):
    if j%2==1:
      totl+=(lst[j]*(lst[j]-1))//2
      totl+=max(lst[j],lst[min(j+1,l-1)])
    else:
      totl+=(lst[j]*(lst[j]-1))//2
  print(totl)

Submission status: Runtime Error

Solution code:
s = input()
n = len(s) + 1

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

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

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

while next_num != -1:
	solve(next_num)

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

Submission status: Runtime Error

Solution code:
S = input()
n = len(S)
S = S + " "
ans = 0
l = 0
r = 0
for i in range(n - 1):
    if S[i] == '>' and S[i + 1] == ('<'):
        temp = i
        break
if S[0] == '<':
    temp = -1
ans += (temp + 1) * (temp + 2) // 2
i = max(temp, 0)

while(i < n):
    while (i < n and S[i] == '<'):
        l += 1
        i += 1
    while (i < n and S[i] == '>'):
        r += 1
        i += 1
    l, r = min(l, r), max(l, r)
    ans += l * (l - 1) // 2 + r * (r + 1) // 2
    l = 0
    r = 0

l, r = min(l, r), max(l, r)
ans += l * (l - 1) // 2 + r * (r + 1) // 2
print(ans)

Submission status: Runtime Error

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

vA = [0,] * N
vZ = []
p = ">"
for i,s in enumerate(S):
    if p+s == "><":
        vZ.append(i)
    p = s
if S[-1] == ">":
    vZ.append(N-1)

# print(vZ)##
####
for z in vZ:
    if z == N-1:
        break
    t = z
    while t<N-1 and S[t] == "<":
        vA[t+1] = vA[t] + 1
        t += 1

# print(vA)##

for z in vZ:
    if z == 0:
        continue
    t = z
    while S[t-1] == ">":
        vA[t-1] = max(vA[t] + 1, vA[t-1])
        t -= 1

# print(vA)###
print(sum(vA))

Submission status: Runtime Error

Solution code:
#文字列Sの長さを取得
N = len(S)

#空のリストを用意
a = [0]

#<と>の順番に応じて初期の山の形を決定
for i in range(N):
    if S[i] == '<':
        a.append(a[i]+1)
    else:
        a.append(a[i]-1)

#aの最小値
min(a)

#山をずらす値
shift_value = 0 - min(a)

#aの全要素にシフト値を加える
newa = [n+shift_value for n in a]

#aの全要素の和
sum(newa)

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)+1
ans=[-1 for i in range(n)]
st=False
for i in range(1,n):
    if s[i-1]=="<":
        if st:
            st=False
            ans[i-1]=0
    else:
        st=True
if s[0]=="<":
    ans[0]=0
else:
    d=0
    for i in range(1,n):
        if s[i]==">":
            d+=1
        else:
            break
    ans[0]=d
#print(ans)
co=0
for i in range(n-1,0,-1):
    if s[i-1]==">":
        ans[i]=co
        co+=1
    else:
        if co>0:
            ans[i]=co
        co=0
#print(ans)
for i in range(1,n):
    if s[i-1]=="<" and ans[i]==-1:
        ans[i]=ans[i-1]+1
    elif s[i-1]=="<" and ans[i]!=-1:
        ans[i]=max(ans[i],ans[i-1]+1)
print(sum(ans))

Submission status: Runtime Error

Solution code:
#0<3>2>1>0<1<2>0<1<2<3<4<5>2>1>0<1
import math
s = input()
bigger=0
smaller=0
count = 0
for i in range(len(s)-1):
    if (s[i]==">" and s[i+1]=="<"):
        count += (max(bigger,smaller))*((max(bigger,smaller))+1)/2
        count += (min(bigger,smaller)-1)*((min(bigger,smaller)-1)+1)/2 if (min(bigger,smaller)-1)!=0 else 0
        bigger = 0
        smaller = 0
    elif (s[i]=="<" and s[i+1]=="<"):
        bigger += 1
    elif (s[i]=="<" and s[i+1]==">"):
        bigger += 1
        smaller += 1
    elif (s[i]==">" and s[i+1]==">"):
        smaller += 1
count += (max(bigger,smaller))*((max(bigger,smaller))+1)/2
count += math.factorial(min(bigger,smaller)-1) if smaller!=0 else True

print(int(count))

Submission status: Runtime Error

Solution code:
S = input()
n = len(S)
ans = 0
l = 0
r = 0
for i in range(n - 1):
    if S[i] == '>' and S[i + 1] == ('<'):
        temp = i
        break
if S[0] == '<':
    temp = -1
ans += (temp+1) * (temp + 2) // 2
i = max(temp, 0)
while(i < n):
    while (i < n and S[i] == '<'):
        l += 1
        i += 1
    while (i < n and S[i] == '>'):
        r += 1
        i += 1
    l, r = min(l, r), max(l, r)
    ans += l * (l - 1) // 2 + r * (r + 1) // 2
    l = 0
    r = 0

print(ans)

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
lst=[]
cnt=1

if n==2:
  print(1)
  
for i in range(n-2):
  if s[i]=s[i+1]:
    cnt+=1
  else:
    lst.append(cnt)
    cnt-=(cnt-1)
totl=0
if s[0]=='<':
  for j in range(len(lst)):
    if j%2==0:
      totl+=(lst[j]*(lst[j]-1))//2
      totl+=max(lst[j],lst[min(j+1,len(lst)-1)])
    else:
      totl+=(lst[j]*(lst[j]-1))//2
  print(totl)
else:
  totl+=lst[0]
  for j in range(len(lst)):
    if j%2==1:
      totl+=(lst[j]*(lst[j]-1))//2
      totl+=max(lst[j],lst[min(j+1,len(lst)-1)])
    else:
      totl+=(lst[j]*(lst[j]-1))//2
  print(totl)

Submission status: Runtime Error

Solution code:
s = input()
b = []
sho = 0
dai = 0
for i in range(len(s)):
	if(i == 0 and s[i+1] == ">"):continue
	if s[i] == "<":
		dai = 0
		sho += 1
		b.append(sho)
	else:
		oldsho = sho
		sho = 0
		if(oldsho >= 2):
			dai = -1
		elif(s[i-1] == "<"):
			dai = 0
		dai += 1
		b.append(dai)
print (sum(b))

Submission status: Runtime Error

Solution code:
s_ = input()
s = [one for one in s_]

cnt = 0
tmp_cnt = 0
save_num = 0
tmp_l = []
for i,one in enumerate(s):
    if i == one:
        tmp == one
        tmp_cnt = 1
    else:
        if one == tmp:
            tmp_cnt += 1
        else:
            tmp_l.append(tmp_cnt)
            tmp_cnt = 1
            tmp = one
tmp_l.append(cnt)

cnt = 0
for one in tmp_l:
    cnt += 1/2*one*(one-1)
cnt = int(cnt)
for i in range(int(len(tmp_l)//2)):
    cnt += max(tmp_l[2*i],tmp_l[2*i+1])
    
if len(tmp_l) % 2 != 0:
    if tmp == "<":
        cnt += tmp_l[-1]+1
    else:
        cnt += 2
print(cnt)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    a, b = map(int, input().split())

    if a < 10 and b < 10:
        print(a * b)
    else:
        print(-1)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
S = input()
n = len(S)
ans = 0
l = 0
r = 0
for i in range(n - 1):
    if S[i] == '>' and S[i + 1] == ('<'):
        temp = i
        break
if S[0] == '<':
    temp = 0
ans += temp * (temp + 1) // 2
i = temp

while(i < n):
    while (i < n and S[i] == '<'):
        l += 1
        i += 1
    while (i < n and S[i] == '>'):
        r += 1
        i += 1
    l, r = min(l, r), max(l, r)
    ans += l * (l - 1) // 2 + r * (r + 1) // 2
    l = 0
    r = 0

print(ans)

Submission status: Runtime Error

Solution code:
S = input()

N = len(S) + 1
L = []
counter = 0

for n in range(N-2):
    counter += 1
    if S[n]!=S[n+1]:
        L.append(counter)
        counter = 0
        if S[n]=='>' and L[-1]>=L[-2]:
            L[-2] -= 1
        elif S[n]=='>' and L[-1]<L[-2]:
            L[-1] -= 1
            
if S[-1]=='<':
    L.append(counter+1)
else:
    L.append(counter)
        
print(sum([l*(l+1)//2 for l in L]))

Submission status: Runtime Error

Solution code:
s=input()
lst=[]
cnt=1
for i in range(n-2):
  if s[i]=s[i+1]:
    cnt+=1
  else:
    lst.append(cnt)
    cnt-=(cnt-1)
totl=0
if s[0]=='<':
  for j in range(len(lst)):
    if j%2==0:
      totl+=(lst[j]*(lst[j]-1))//2
      totl+=max(lst[j],lst[min(j+1,len(lst)-1)])
    else:
      totl+=(lst[j]*(lst[j]-1))//2
  print(totl)
else:
  totl+=lst[0]
  for j in range(len(lst)):
    if j%2==1:
      totl+=(lst[j]*(lst[j]-1))//2
      totl+=max(lst[j],lst[min(j+1,len(lst)-1)])
    else:
      totl+=(lst[j]*(lst[j]-1))//2
  print(totl)

Submission status: Runtime Error

Solution code:
#
import sys
import math
import numpy as np
import itertools

# 文字列を一文字ずつのリストに代入 test は['t', 'e', 's', 't']
s = list(input())
t = [0]
now = 0
for i in range(len(s)):
    print(i,t)
    if s[i]=='<':
        now += 1
        t.append(now)
    elif now == 0:
        now = -1
        t.append(now)
        if now == -1:
            t[i+1] += 1
            now += 1
            for j in range(i,-1,-1):
                if t[j]==t[j+1]:
                    t[j] += 1
                else:
                    break
    else:
        now = 0
        t.append(now)

answer=0
for i in range(len(t)):
    answer += t[i]

print(answer)

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
list0 = list()
list2 = list()
ans = 0
for i in range(n-1):
    if s[i:i+2] == '><':
        list0.append(i+1)
    elif s[i:i+2] == '<>':
        list2.append(i+1)

if s[0] == '<':
    list0.insert(0, 0)
else:
    p1 = list0[0]
    ans += 1/2 * p1 * (p1 + 1)


if s[-1] == '>':
    list0.append(n)
else:
    p1 = n - list0[-1]
    ans += 1/2 * p1 * (p1 + 1)

for i in range(len(list2)):
    p1 = max(list2[i] - list0[i], list0[i+1] - list2[i])
    p2 = min(list2[i] - list0[i], list0[i+1] - list2[i])
    ans += 1/2 * p1 * (p1 + 1) + 1/2 * p2 * (p2 - 1)

print(int(ans))

Submission status: Runtime Error

Solution code:
S = input()

N = len(S) + 1
L = []
counter = 0

for n in range(N-2):
    counter += 1
    if S[n]!=S[n+1]:
        L.append(counter)
        counter = 0
        if S[n]=='>' and L[-1]>=L[-2]:
            L[-2] -= 1
        elif S[n]=='>' and L[-1]<L[-2]:
            L[-1] -= 1
            
if S[N-2]=='<':
    L.append(counter+1)
else:
    L.append(counter)
L.append(counter)
        
print(sum([l*(l+1)//2 for l in L]))

Submission status: Runtime Error

Solution code:
S = input()

num_list = [0]
num = 0
bool_> = False
for s_ in S:
  if s_ == "<":
    num +=1      
    if bool_> == True:
      num=1
  elif s_ == ">":
    num -=1
    bool_> = True
  num_list.append(num)
print(num_list)

Submission status: Runtime Error

Solution code:
s = input()
a = [-1 for i in range(len(s)+1)]
for i in range(len(s)-1):
    if s[i] == '>' and s[i+1] == "<":
        a[i+1] = 0
if s[0] == "<":
    a[0] = 0
if s[-1] == ">":
    a[-1] = 0
def plus(i):
    j = i - 1
    while s[j] == '>':
        a[j] = max(a[j+1] + 1, a[j])
        j -= 1
        if j < 0:
            break
    j = i
    while s[j] == '<':
        a[j+1] = max(a[j] + 1, a[j+1])
        j += 1
        if  j == len(a) - 1:
            break
for i in range(len(a)):
    if a[i] == 0:
        plus(i)
print(sum(a))

Submission status: Runtime Error

Solution code:
def s_in():
    return input()

S = s_in()

if len(S) == 1:
    print(1)
    exit()


lis = []
cnt = 1
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 1
    else:
        lis.append((S[i], cnt))
        cnt = 1
else:
    lis.append((S[len(S)-1], cnt))


res = 0
idx = 0


if lis[0][0] == ">":
    res += sum(range(lis[0][1]+1))
    idx += 1

while True:
    if idx+1 == len(lis):
        res += sum(range(lis[idx][1]+1))
        break

    x = lis[idx][1]
    y = lis[idx+1][1]

    res += sum(range(max(x,y)+1)) + sum(range(min(x,y)))

    idx += 2

    if idx == len(lis):
        break


print(res)

Submission status: Runtime Error

Solution code:
S = input()
sep = [0]
for i in range(len(S)-1):
    if S[i]=='<' and S[i+1]=='>': sep.append(i+1)
sep.append(i+2)

S += 'X'
ans = 0
center = 0
for i in range(len(sep)-1):
    s = S[sep[i]: sep[i+1]]
    l_max = s.count('>')
    ans += max(center, l_max)
    ans += l_max*(l_max-1)//2
    r_max = s.count('<')
    ans += r_max*(r_max-1)//2
    center = r_max

ans += center
print(ans)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    int n = s.length()+1;
    int *cnt = new int[n];
    int k = 0;
    int l = 0;
    while (k < n-1) {
        int i = k;
        while (i+1 < n-1 && s[i] == s[i+1])
            i++;
        cnt[l] = i-k+1;
        l++;
        k = i+1;
    }

    long long ans = 0;
    if (s[0] == '<') {
        int i = 0;
        while (i < l) {
            if (i+1 < l) {
                ans += cnt[i]*(cnt[i]+1)/2 + cnt[i+1]*(cnt[i+1]+1)/2 - min(cnt[i], cnt[i+1]);
            }
            else if (i < l) {
                ans += cnt[i]*(cnt[i]+1)/2;
            }
            i+= 2;
        }
        cout << ans << endl;
    }
    else {
        ans += cnt[0];
        int i = 1;
        while (i < l) {
            if (i+1 < l) {
                ans += cnt[i]*(cnt[i]+1)/2 + cnt[i+1]*(cnt[i+1]+1)/2 - min(cnt[i], cnt[i+1]);
            }
            else if (i < l) {
                ans += cnt[i]*(cnt[i]+1)/2;
            }
            i+= 2;
        }
        cout << ans << endl;
    }
    return 0;
}

Submission status: Runtime Error

Solution code:
def s_in():
    return input()

S = s_in()

if len(S) == 1:
    print(1)
    exit()


lis = []
cnt = 1
for i in range(len(S)-1):
    if S[i] == S[i+1]:
        cnt += 1
    else:
        lis.append((S[i], cnt))
        cnt = 1
else:
    lis.append((S[len(S)-1], cnt))


res = 0
idx = 0


if lis[0][0] == ">":
    res += sum(range(lis[0][1]+1))
    idx += 1

while True:
    if idx+1 == len(lis):
        res += sum(range(lis[idx][1]+1))
        break

    x = lis[idx][1]
    y = lis[idx+1][1]

    if x == y:
        res += sum(x+1)*2
    else:
        res += sum(range(max(x,y)+1)) + sum(range(min(x,y)))

    idx += 2

    if idx == len(lis):
        break


print(res)

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)+1
a = [-1]*N
l = []
for i in range(1,N-1):
    if S[i-1] == '>' and S[i] == '<':
        a[i] = 0
        l.append(i)

if S[0] == '<':
    a[0] = 0
    l.append(0)
if S[-1] == '>':
    a[N-1] = 0
    l.append(N-1)

for i in l:
    j = i-1
    while 0<=j<=N-2 and S[j]=='>' and S[j-1]=='>':
        a[j] = a[j+1]+1
        j -= 1
    j = i+1
    while 0<=j<=N-2 and S[j]=='<' and S[j+1]=='<':
        a[j] = a[j-1]+1
        j += 1

for i in range(1,N-1):
    if a[i] == -1:
        a[i] = max(a[i-1],a[i+1])+1


if S[0] == '>':
    a[0] = a[1]+1

if S[-1] == '<':
    a[N-1] = a[N-2]+1

print(sum(a))

Submission status: Runtime Error

Solution code:
input = raw_input
S = input()
n = len(S) # N-1
s = S


up_count = 0
down_count = 0

for i, c in enumerate(S):
    if c == "<":
        start_i = i
        break
    down_count += 1

nums = []
for num in reversed(range(down_count+1)):
    nums.append(num)

up = True
for c in S[start_i:]: 
    if c == "<":
        if not up: # down->up
            if up_count >= down_count:
                for num in range(1, up_count+1):
                    nums.append(num)
                for num in reversed(range(0, down_count)):
                    nums.append(num)
            else:
                for num in range(0, up_count):
                    nums.append(num)
                for num in reversed(range(1, down_count+1)):
                    nums.append(num)
                 
            down_count = 0
            up_count = 1
            up = True
        else:
            up_count += 1
    else:
        if up:
            up = False
            down_count = 1
        else:
            down_count += 1
        

if up:
    for num in range(up_count+1):
        nums.append(num)
else:
    if up_count >= down_count:
        for num in range(1, up_count+1):
            nums.append(num)
        for num in reversed(range(0, down_count)):
            nums.append(num)
    else:
        for num in range(0, up_count):
            nums.append(num)
        for num in reversed(range(1, down_count+1)):
            nums.append(num)

out = sum(nums)
print(out)

Submission status: Runtime Error

Solution code:
S=input()
S+="1"
A=[]
count1=0
count2=0
total=0
for i in range(60):
    total+=i
    A.append(total)

total=0
for i in range(len(S)):
    if S[i]=="<":
        count1+=1
    if S[i]==">":
        count2+=1
    if S[i]==">" and S[i+1]=="<":
        total+=A[max(count1,count2)]
        if min(count1, count2) != 0:
            total+=A[min(count1,count2)-1]
        #print(count1, count2,total)
        count1=0
        count2=0

total+=A[max(count1,count2)]
if min(count1,count2)!=0:
    total+=A[min(count1,count2)-1]
#print(A)
#print(count1,count2)


print(total)

Submission status: Runtime Error

Solution code:
S = input()
sep = [0]
for i in range(len(S)-1):
    if S[i]=='<' and S[i+1]=='>': sep.append(i+1)
sep.append(i+2)

ans = 0
center = 0
for i in range(len(sep)-1):
    s = S[sep[i]: sep[i+1]]
    l_max = s.count('>')
    ans += max(center, l_max)
    ans += l_max*(l_max-1)//2

    r_max = s.count('<')
    ans += r_max*(r_max-1)//2
    center = r_max

ans += center
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)+1
a = [-1]*N
l = []
for i in range(1,N-1):
    if S[i-1] == '>' and S[i] == '<':
        a[i] = 0
        l.append(i)

for i in l:
    j = i-1
    while 0<=j<=N-2 and S[j]=='>' and S[j-1]=='>':
        a[j] = a[j+1]+1
        j -= 1
    j = i+1
    while 0<=j<=N-2 and S[j]=='<' and S[j+1]=='<':
        a[j] = a[j-1]+1
        j += 1

if S[0] == '>':
    a[0] = a[1]+1
else:
    a[0] = 0
if S[-1] == '<':
    a[N-1] = a[N-2]+1
else:
    a[N-1] = 0

for i in range(N):
    if a[i] == -1:
        a[i] = max(a[i-1],a[i+1])+1

print(sum(a))

Submission status: Runtime Error

Solution code:
import matplotlib.pyplot as plt
import networkx as nx
import numpy as np

def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

def main():
    s = input().strip()
    # tmp = 0
    # mx = 0
    # for ch in s:
    #     if ch == ">"
    #         tmp -= 1
    #     else:
    #         tmp += 1
    #
    #     if abs(tmp) > mx:
    #         mx = abs(tmp)
    #
    fwd = [0]
    rev = [0]
    tmp = 0
    mn = 0
    for ch in s:
        # print(ch)
        if ch == "<":
            tmp += 1
        else:
            tmp = 0
        fwd.append(tmp)

    for ch in s[::-1]:
        # print(ch)
        if ch == ">":
            tmp += 1
        else:
            tmp = 0
        rev.append(tmp)
    rev.reverse()
    # print(fwd, rev)
    print(sum([max(i, j) for i, j in zip(fwd, rev)]))

    #     if mn > tmp:
    #         mn = tmp
    #     print(tmp)
    #
    # ans = 0
    # print(mn)
    # ttmp = max(0, -mn)
    # for ch in s:
    #     ans += ttmp
    #     if ch == ">":
    #         ttmp -= 1
    #     else:
    #         ttmp += 1
    #
    # print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

S=input().strip()

from collections import deque
Q=deque(S)

ANS=0

count=0
while len(Q)>0 and Q[0]==">":
    count+=1
    Q.popleft()

ANS+=count*(count+1)//2
count=0

while len(Q)>0 and Q[-1]=="<":
    count+=1
    Q.pop()

ANS+=count*(count+1)//2


count=1
LIST=[]

for i in range(1,len(Q)):
    if Q[i]==Q[i-1]:
        count+=1
    else:
        LIST.append(count)
        count=1

LIST.append(count)

for i in range(0,len(LIST),2):
    s,t=sorted((LIST[i],LIST[i+1]))

    ANS+=t*(t+1)//2+s*(s-1)//2

print(ANS)