Problem p02873 (python)

Fixed submission:
def left(arr, idx):
    if L[idx] != None:
        return L[idx]

    if arr[idx] == '<':
        if idx == 0:
            ret = 1
        else:
            ret = left(arr, idx-1) + 1
    else:
        ret = 0

    L[idx] = ret
    return ret
        
def right(arr, idx):
    if R[idx] != None:
        return R[idx]

    if arr[idx] == '>':    
        if idx == len(arr)-1:
            ret =  1
        else:
            ret = right(arr, idx+1) + 1
    else:
        ret = 0
    R[idx] = ret
    return ret

def main():
    S = list(input())
    N = len(S)
    A = [0 for _ in range(N+1)]
    
    global L; L = [None for _ in range(N)]
    global R; R = [None for _ in range(N)]

    for i in range(N):
        j = N - i - 1
        L[i] = left(S, i)
        R[j] = right(S, j)
    
    L = [0] + L
    R = R + [0]

    for i in range(len(A)):
        A[i] = max(L[i], R[i])
            
    print(sum(A))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def left(arr, idx):
    if L[idx] != None:
        return L[idx]
    if idx == -1:
        ret =  0
    else:
        if arr[idx] == '<':
            ret = left(arr, idx-1) + 1
        else:
            ret = 0
    L[idx] = ret
    return ret
        
def right(arr, idx):
    if R[idx] != None:
        return R[idx]
    if idx == len(arr):
        ret =  0 
    else:
        if arr[idx] == '>':
            ret = right(arr, idx+1) + 1
        else:
            ret = 0
    R[idx] = ret
    return ret

def main():
    S = list(input())
    N = len(S)
    A = [0 for _ in range(N+1)]
    
    global L; L = [None for _ in range(N+1)]
    global R; R = [None for _ in range(N+1)]

    for i in range(len(A)):
        A[i] = max(left(S, i-1), right(S, i))
            
    print(sum(A))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def left(arr, idx):
    if L[idx] != None:
        return L[idx]
    if idx == -1:
        ret =  0
    else:
        if arr[idx] == '<':
            ret = left(arr, idx-1) + 1
        else:
            ret = 0
    L[idx] = ret
    return ret
        
def right(arr, idx):
    if R[idx] != None:
        return R[idx]
    if idx == len(arr):
        ret =  0 
    else:
        if arr[idx] == '>':
            ret = right(arr, idx+1) + 1
        else:
            ret = 0
    R[idx] = ret
    return ret

def main():
    S = list(input())
    N = len(S)
    A = [0 for _ in range(N+1)]
    
    global L; L = [None for _ in range(N+1)]
    global R; R = [None for _ in range(N+1)]

    for i in range(len(A)):
        A[i] = max(left(S, i-1), right(S, i))
            
    print(sum(A))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def left(arr, idx):
    if L[idx] != None:
        return L[idx]
    if idx == -1:
        ret =  0
    else:
        if arr[idx] == '<':
            ret = left(arr, idx-1) + 1
        else:
            ret = 0
    L[idx] = ret
    return ret
        
def right(arr, idx):
    if R[idx] != None:
        return R[idx]
    if idx == len(arr):
        ret =  0 
    else:
        if arr[idx] == '>':
            ret = right(arr, idx+1) + 1
        else:
            ret = 0
    R[idx] = ret
    return ret

def main():
    S = list(input())
    N = len(S)
    A = [0 for _ in range(N+1)]
    
    global L; L = [None for _ in range(N+1)]
    global R; R = [None for _ in range(N+1)]

    for i in range(len(A)):
        A[i] = max(left(S, i-1), right(S, i))
            
    print(sum(A))
    print(L)
    print(R)
    print(A)

if __name__ == "__main__":
    main()