Buggy python submission (verdict: Time Limit Exceeded):
import math

def main(): 

    n = int(input())
    a = [int(input()) for _ in range(n)]

    for i in range(n):
        t = list(a)
        t.pop(i)

        print(max(t))




if __name__ == "__main__":
    main() 

Fixed submission:

def main(): 

    n = int(input())
    a = [int(input()) for _ in range(n)]

    max_v = 0
    max_sv = 0

    for i in range(n):
        if a[i] > max_v:
            max_sv = max_v
            max_v = a[i]
        elif a[i] > max_sv:
            max_sv = a[i]

    for i in range(n):
        if a[i] != max_v:
            print(max_v)
        else:
            print(max_sv)




if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math

def main(): 

    n = int(input())
    a = [int(input()) for _ in range(n)]

    max_value = max(a)
    max_list = [i for i, x in enumerate(a) if x == max_value]
    
    a.pop(max_list[0])
    second_max = max(a)

    for i in range(n):
        if i not in max_list:
            print(max_value)
        else:
            print(second_max)




if __name__ == "__main__":
    main() 

Fixed submission:

def main(): 

    n = int(input())
    a = [int(input()) for _ in range(n)]

    max_v = 0
    max_sv = 0

    for i in range(n):
        if a[i] > max_v:
            max_sv = max_v
            max_v = a[i]
        elif a[i] > max_sv:
            max_sv = a[i]

    for i in range(n):
        if a[i] != max_v:
            print(max_v)
        else:
            print(max_sv)




if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math

def main(): 

    n = int(input())
    a = [int(input()) for _ in range(n)]

    max_value = max(a)

    for i in range(n):
        if a[i] != max_value:
            print(max_value)
        else:
            t = list(a)
            t.pop(i)

            print(max(t))




if __name__ == "__main__":
    main() 

Fixed submission:

def main(): 

    n = int(input())
    a = [int(input()) for _ in range(n)]

    max_v = 0
    max_sv = 0

    for i in range(n):
        if a[i] > max_v:
            max_sv = max_v
            max_v = a[i]
        elif a[i] > max_sv:
            max_sv = a[i]

    for i in range(n):
        if a[i] != max_v:
            print(max_v)
        else:
            print(max_sv)




if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math

def main(): 

    n = int(input())
    a = [int(input()) for _ in range(n)]

    for i in range(n):
        t = list(a)
        t.pop(i)

        print(max(t))




if __name__ == "__main__":
    main() 

Fixed submission:

def main(): 

    n = int(input())
    a = [int(input()) for _ in range(n)]

    max_v = 0
    max_sv = 0

    for i in range(n):
        if a[i] > max_v:
            max_sv = max_v
            max_v = a[i]
        elif a[i] > max_sv:
            max_sv = a[i]

    for i in range(n):
        if a[i] != max_v:
            print(max_v)
        else:
            print(max_sv)




if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import math

def main(): 

    n = int(input())
    a = [int(input()) for _ in range(n)]

    for i in range(n):
        t = list(a)
        t.pop(i)

        print(max(t))




if __name__ == "__main__":
    main() 

Fixed submission:

def main(): 

    n = int(input())
    a = [int(input()) for _ in range(n)]

    max_v = 0
    max_sv = 0

    for i in range(n):
        if a[i] > max_v:
            max_sv = max_v
            max_v = a[i]
        elif a[i] > max_sv:
            max_sv = a[i]

    for i in range(n):
        if a[i] != max_v:
            print(max_v)
        else:
            print(max_sv)




if __name__ == "__main__":
    main()