Problem p03957 (python)

Fixed submission:
def read_input():
    return input()

def checker(inp_str):
    flag = 0
    for i in list(inp_str):
        if flag == 0:
            if i == "C":
                flag = 1
        if flag == 1:
            if i == "F":
                flag = 2

    if flag == 2:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    checker(read_input())

Buggy submission (verdict: Runtime Error):
def read_input():
    l_1 = input()
    day = int(l_1.split(" ")[0])

    num_cake = [int(i) for i in input().split(" ")]

    return day, num_cake

def get_max_index(target_list):
    return [i for i, j in enumerate(target_list) if j == max(target_list)]


def get_second_max_index(target_list):
    return [i for i, j in enumerate(target_list) if j == list(sorted(set(target_list), reverse=True))[1]]


def mog(day, num_cake):
    """

    >>> mog(7, [3,2,2])
    0
    >>> mog(6, [1,4,1])
    1
    >>> mog(100, [100])
    99
    """
    printed = False
    previous_index = -1

    for i in range(0, day):
        # print("num_cake: ", num_cake)
        # print("previous_index: ",previous_index)
        ate_flag = False
        mog_maybe_index = get_max_index(num_cake)
        # print("mog_maybe_index: {0}".format(mog_maybe_index))
        for n in mog_maybe_index:
            if n == previous_index:
                continue
            else:
                num_cake[n] = num_cake[n] - 1
                ate_flag = True
                previous_index = n
                break
        if ate_flag is False:
            try:
                mog_ext = get_second_max_index(num_cake)
                # print("mog_ext", mog_ext)
                if num_cake[mog_ext[0]] == 0:
                    printed = True
                    print(max(num_cake))
                    break
            except IndexError:
                print(max(num_cake))
                printed = True
                break
            num_cake[mog_ext[0]] = num_cake[mog_ext[0]] - 1
            previous_index = mog_ext[0]

    if printed is False:
        print(0)



if __name__ == "__main__":
    #import doctest
    #doctest.testmod()

    day, num_cake = read_input()
    mog(day, num_cake)

Buggy submission (verdict: Runtime Error):
def read_input():
    l_1 = input()
    day = int(l_1.split(" ")[0])

    num_cake = [int(i) for i in input().split(" ")]

    return day, num_cake

def get_max_index(target_list):
    return [i for i, j in enumerate(target_list) if j == max(target_list)]


def get_second_max_index(target_list):
    return [i for i, j in enumerate(target_list) if j == list(sorted(set(target_list), reverse=True))[1]]


def mog(day, num_cake):
    """

    >>> mog(7, [3,2,2])
    0
    >>> mog(6, [1,4,1])
    1
    >>> mog(100, [100])
    99
    """
    printed = False
    previous_index = -1

    for i in range(0, day):
        # print(num_cake)
        # print(previous_index)
        ate_flag = False
        mog_maybe_index = get_max_index(num_cake)
        # print("mog_maybe_index: {0}".format(mog_maybe_index))
        for n in mog_maybe_index:
            if n == previous_index:
                continue
            else:
                num_cake[n] = num_cake[n] - 1
                ate_flag = True
                previous_index = n
                break
        if ate_flag is False:
            try:
                mog_ext = get_second_max_index(num_cake)
                # print("mog_ext", mog_ext)
            except IndexError:
                print(max(num_cake))
                printed = True
                break
            num_cake[mog_ext[0]] = num_cake[mog_ext[0]] - 1
            previous_index = mog_ext[0]

    if printed is False:
        print(0)



if __name__ == "__main__":
    import doctest
    doctest.testmod()

    mog(read_input())