Problem: 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.

Submission attempts (in order):
#AGC-040
S = input()
A = [0] * (len(S) + 1)

def check_left(n, S):
    count = 0
    for i in reversed(range(0, n)):
        if S[i] == "<":
            count += 1
        else:
            break
    return count

def check_right(n, S):
    count = 0
    for i in range(n, len(S)):
        if S[i] == ">":
            count += 1
        else:
            break
    return count

for i in range(len(S)+1):
    if i > 0 and A[i-1] != 0:
        if S[i-1] == ">":
            if S[i+1] == "<":
                A[i] = 0
            else:
                A[i] = A[i-1] - 1
        else:
            A[i] = A[i-1] + 1
    else:
        A[i] = max(check_left(i, S), check_right(i, S))
    
print(sum(A))

#AGC-040
S = input()
A = [0] * (len(S) + 1)

def check_left(n, S):
    count = 0
    for i in reversed(range(0, n)):
        if S[i] == "<":
            count += 1
        else:
            break
    return count

def check_right(n, S):
    count = 0
    for i in range(n, len(S)):
        if S[i] == ">":
            count += 1
        else:
            break
    return count

A[0] = max(check_left(0, S), check_right(0, S))

for i in range(1, len(S)+1):
    if A[i-1] != 0:
        if S[i-1] == "<":
            A[i] = A[i-1] + 1
        else:
            if S[i] == "<":
                A[i] = 0
            else:
                A[i] = max(check_left(i, S), check_right(i, S))
    else:
        A[i] = max(check_left(i, S), check_right(i, S))

print(sum(A))

#AGC-040
S = input()
A = [0] * (len(S) + 1)

def check_left(n, S):
    count = 0
    for i in reversed(range(0, n)):
        if S[i] == "<":
            count += 1
        else:
            break
    return count

def check_right(n, S):
    count = 0
    for i in range(n, len(S)):
        if S[i] == ">":
            count += 1
        else:
            break
    return count

A[0] = max(check_left(i, S), check_right(i, S))

for i in range(1, len(S)+1):
    if A[i-1] != 0:
        if S[i-1] == "<":
            A[i] = A[i-1] + 1
        else: #elif S[i-1] == ">"
            if S[i] == "<":
                A[i] = 0
            else:
                A[i] = max(check_left(i, S), check_right(i, S))
    else:
        A[i] = max(check_left(i, S), check_right(i, S))

print(sum(A))

#AGC-040
S = input()
A = [0] * (len(S) + 1)

def check_left(n, S):
    count = 0
    for i in reversed(range(0, n)):
        if S[i] == "<":
            count += 1
        else:
            break
    return count

def check_right(n, S):
    count = 0
    for i in range(n, len(S)):
        if S[i] == ">":
            count += 1
        else:
            break
    return count

A[0] = max(check_left(i, S), check_right(i, S))

for i in range(1, len(S)+1):
    if A[i-1] != 0:
        if S[i-1] == "<":
            A[i] = A[i-1] + 1
        else:
            if S[i] == "<":
                A[i] = 0
            else:
                A[i] = max(check_left(i, S), check_right(i, S))
    else:
        A[i] = max(check_left(i, S), check_right(i, S))

print(sum(A))

S = input()
N = len(S) + 1
 
A = [0] * N
 
if S[0] == '<':
    A[0] = 0

if S[-1] == '>':
    A[-1] = 0

for i in range(1, N-1):
    if S[i-1] == '>' and S[i] == '<':
        A[i] = 0

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

for i in range(N-1)[::-1]:
    if S[i] == '>':
        A[i] = max(A[i], A[i+1] + 1)

print(sum(A))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted