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):
import numpy as np

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

    for i in range(0, len(s)):
        if s[i] == '<':
            n_list[i+1] = n_list[i]+1
        else: 
            j = i 
            k = 1                          
            for j in range(i, 0, -1):
                if s[j] == '<':
                    n_list[j+1] = n_list[j]+1
                    break
                n_list[j] = k                
                j-=1
                k+=1

        # print('i={} {}'.format(i, n_list))    
    if s[0] == '>':
        n_list[0] = n_list[1]+1
    # print(n_list)
    print(int(sum(n_list)))


if __name__ == "__main__":
    main()





import numpy as np

def main():
    s = input()
    
    n_list = np.zeros(len(s)+1)

    for i in range(0, len(s)):
        if s[i] == '<':
            n_list[i+1] = n_list[i]+1
        else: 
            j = i 
            k = 1                          
            for j in range(i, 0, -1):
                if s[j] == '<':
                    n_list[j+1] = max(n_list[j], n_list[j+2])+1
                    break
                n_list[j] = k                
                j-=1
                k+=1
        if s[0] == '>':
            n_list[0] = n_list[1]+1
        print('i={} {}'.format(i, n_list))    

    print(n_list)
    print(int(sum(n_list)))


if __name__ == "__main__":
    main()


import numpy as np

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

    for i in range(0, len(s)):
        if s[i] == '<':
            n_list[i+1] = n_list[i]+1
        else: 
            j = i 
            k = 1                          
            for j in range(i, 0, -1):
                if s[j] == '<':
                    n_list[j+1] = n_list[j]+1
                    break
                n_list[j] = k                
                j-=1
                k+=1

        # print('i={} {}'.format(i, n_list))    
    if s[0] == '>':
        n_list[0] = n_list[1]+1
    # print(n_list)
    print(int(sum(n_list)))


if __name__ == "__main__":
    main()

import numpy as np

def main():
    
    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: 
            j = i 
            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=', i, n_list)        
                
    print(int(sum(n_list)))


if __name__ == "__main__":
    main()


# import numpy as np


def main():
    s = input()
    
    
    n_list = [0] * (len(s)+1)
    

    for i in range(1, len(s)):
        if s[i-1] == '<':
            n_list[i] = n_list[i-1]+1
        else: 
            if s[i] == '>':
                continue
            
            k = 1                          
            for j in range(i, 1, -1):
                if s[j-1] == '<':
                    n_list[j] = max(n_list[j-1], n_list[j+1])+1
                    break
                n_list[j-1] = k
                k+=1
    
    if s[-1] == '<':
        n_list[-1] = n_list[-2]+1
    elif s[-1] == '>':
        
        k = 1                     
        for j in range(len(s), 1, -1):
            if s[j-1] == '<':
                n_list[j] = max(n_list[j-1], n_list[j+1])+1
                break
            n_list[j-1] = k
            k+=1
    if s[0] == '>':
        n_list[0] = n_list[1]+1
            
        # print('i={} {}'.format(i, n_list))    
 
    # print(n_list)
    print(int(sum(n_list)))


if __name__ == "__main__":
    # start = time.time()
    main()    
    # elapsed_time = time.time() - start
    # print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted