Problem p02873 (python)

Fixed submission:
s = input()                                                                                                                                                                                                                                                                                      
buf = 0                                                                                                                                                                                                                                                                                          
str_len = len(s)                                                                                                                                                                                                                                                                                 
total = 0                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                 
while buf < str_len:                                                                                                                                                                                                                                                                             
    l_count = 0                                                                                                                                                                                                                                                                                  
    r_count = 0                                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                 
    while buf < str_len and s[buf] == "<":                                                                                                                                                                                                                                                       
        l_count += 1                                                                                                                                                                                                                                                                             
        buf += 1                                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                 
    while buf < str_len and s[buf] == ">":                                                                                                                                                                                                                                                       
        r_count += 1                                                                                                                                                                                                                                                                             
        buf += 1                                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                 
    n = max(l_count, r_count)                                                                                                                                                                                                                                                                    
    total += n * ( n + 1 ) // 2                                                                                                                                                                                                                                                                  
    m = min(l_count, r_count) - 1                                                                                                                                                                                                                                                                
    total += m * ( m + 1 ) // 2                                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                 
print(total)

Buggy submission (verdict: Runtime Error):
s = input()

l = [for i in range(len(s) + 1)]

for x in range(len(s)-1):
    for y in range(len(s)-1-x):
        if '<' == s[y] and l[y] > l[y+1]:
            l[y], l[y+1] = l[y+1], l[y]

        elif '<' == s[y] and l[y] < l[y+1]:
            l[y], l[y+1] = l[y], l[y+1]

        elif '>' == s[y] and l[y] > l[y+1]:
            l[y], l[y+1] = l[y], l[y+1]

        elif '>' == s[y] and l[y] < l[y+1]:
            l[y], l[y+1] = l[y+1], l[y]

print(sum(l))

Buggy submission (verdict: Runtime Error):
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)