Problem p02971 (python)

Fixed submission:
N = int(input())
Arr = [int(input()) for i in range(N)]

left_max=0
right_max=max(Arr)

for i in range(N):
    n = Arr[i]
    if left_max>=right_max:
        print(left_max)
    else:
        if n==right_max:
            if i ==N-1:
                right_max=left_max
                
            else:
                right_max = max(Arr[i+1:])

        print(right_max)

    if i == N-1:
        break
    left_max=max(n,left_max)

Buggy submission (verdict: Runtime Error):
N = int(input())
Arr = [int(input()) for i in range(N)]


def funct(i, left_max, right_max):
    n = Arr[i]
    if left_max>=right_max:
        print(left_max)
    else:
        if n==right_max:
            if i ==N-1:
                right_max=0
            else:
                right_max = max(Arr[i+1:])
    
        print(right_max)
    
    if i == N-1:
        return
    
    left_max=max(n,left_max)
    return funct(i + 1, left_max, right_max)


funct(0, 0, max(Arr[1:]))

Buggy submission (verdict: Runtime Error):
N = int(input())
Arr = [int(input()) for i in range(N)]


def funct(i, left_max, right_max):
    n = Arr[i]

    if n==right_max:
        if i ==N-1:
            right_max=0
        else:
            right_max = max(Arr[i+1:])

    print(max(left_max, right_max))

    if i == N-1:
        return

    if n >left_max:
        left_max=n
    return funct(i + 1, left_max, right_max)


funct(0, 0, max(Arr[1:]))

Buggy submission (verdict: Runtime Error):
N = int(input())
Arr = [int(input()) for i in range(N)]


def funct(i, left_max, right_max):
    n = Arr[i]

    if n==right_max:
        if i ==N-1:
            right_max=0
        else:
            right_max = max(Arr[i+1:])

    print(max(left_max, right_max))

    if i == N-1:
        return

    if n >left_max:
        if i==0:
            left_max=n
        elif i ==1:
            left_max=max(Arr[:1])
        else:
            left_max=n

    return funct(i + 1, left_max, right_max)


funct(0, 0, max(Arr[1:]))

Buggy submission (verdict: Runtime Error):
N = int(input())
Arr = [int(input()) for i in range(N)]


def funct(i, left_max, right_max):
    n = Arr[i]

    if n==right_max:
        if i ==N-1:
            right_max=0
        else:
            right_max = max(Arr[i+1:])

    print(max(left_max, right_max))

    if i == N-1:
        return

    if n >=left_max:
        if i==0:
            left_max=0
        elif i ==1:
            left_max=Arr[0]
        else:
            left_max=n



    return funct(i + 1, left_max, right_max)


funct(0, 0, max(Arr[1:]))

Buggy submission (verdict: Runtime Error):
N = int(input())
Arr = [int(input()) for i in range(N)]


def funct(i, left_max, right_max):
    n = Arr[i]
    if n >=left_max:
        if i==0:
            left_max=0
        elif i ==1:
            left_max=Arr[0]
        else:
            left_max=max(Arr[:i-1])
    if n>=right_max:
        if i ==N-1:
            right_max=0
        else:
            right_max = max(Arr[i+1:])

    print(max(left_max, right_max))

    if i == N-1:
        return

    return funct(i + 1, left_max, right_max)


funct(0, 0, max(Arr[1:]))

Buggy submission (verdict: Runtime Error):
N = int(input())
Arr = [int(input()) for i in range(N)]


def funct(i, left_max, right_max):
    n = Arr[i]
    if n >=left_max:
        if i==0:
            left_max=0
        else:
            left_max=max(Arr[:i])
    if n>=right_max:
        if i < N-1:
            right_max = max(Arr[i+1:])
        else:
            right_max=left_max
    print(max(left_max, right_max))

    if i == N-1:
        return

    return funct(i + 1, left_max, right_max)


funct(0, 0, max(Arr[1:]))