Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import copy
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    Ap = copy.copy(A)
    set(Ap)
    Ap.sort(reverse=True)
    Am = max(A)
    for i in range(N):
        if i != A.index(Am) or A.count(Am)>1:
            print(Am)
        else:
            print(Ap[1])
if __name__ == '__main__':
    main()

Fixed submission:
# -*- coding: utf-8 -*-
import copy
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    Am = max(A)
    if A.count(Am)>1:
        for j in range(N):
            print(Am)
        return
    Ap = copy.copy(A)
    set(Ap)
    Ap.sort(reverse=True)
    for i in range(N):
        if  A[i] != Am:
            print(Am)
        else:
            print(Ap[1])
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import copy
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    Am = max(A)
    for i in range(N):
        if i != A.index(Am) or A.count(Am)>1:
            print(Am)
            continue
        Ap = []
        Ap = copy.copy(A)
        del Ap[i]
        print(max(Ap))
if __name__ == '__main__':
    main()

Fixed submission:
# -*- coding: utf-8 -*-
import copy
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    Am = max(A)
    if A.count(Am)>1:
        for j in range(N):
            print(Am)
        return
    Ap = copy.copy(A)
    set(Ap)
    Ap.sort(reverse=True)
    for i in range(N):
        if  A[i] != Am:
            print(Am)
        else:
            print(Ap[1])
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import copy
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    for i in range(N):
        if i != A.index(max(A)):
            print(max(A))
            continue
        Ap = []
        Ap = copy.copy(A)
        del Ap[i]
        print(max(Ap))
if __name__ == '__main__':
    main()

Fixed submission:
# -*- coding: utf-8 -*-
import copy
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    Am = max(A)
    if A.count(Am)>1:
        for j in range(N):
            print(Am)
        return
    Ap = copy.copy(A)
    set(Ap)
    Ap.sort(reverse=True)
    for i in range(N):
        if  A[i] != Am:
            print(Am)
        else:
            print(Ap[1])
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import copy
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    for i in range(N):
        Ap = []
        Ap = copy.copy(A)
        del Ap[i]
        print(max(Ap))
if __name__ == '__main__':
    main()

Fixed submission:
# -*- coding: utf-8 -*-
import copy
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    Am = max(A)
    if A.count(Am)>1:
        for j in range(N):
            print(Am)
        return
    Ap = copy.copy(A)
    set(Ap)
    Ap.sort(reverse=True)
    for i in range(N):
        if  A[i] != Am:
            print(Am)
        else:
            print(Ap[1])
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import copy
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    for i in range(N):
        Ap = copy.copy(A)
        del Ap[i]
        print(max(Ap))
if __name__ == '__main__':
    main()

Fixed submission:
# -*- coding: utf-8 -*-
import copy
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    Am = max(A)
    if A.count(Am)>1:
        for j in range(N):
            print(Am)
        return
    Ap = copy.copy(A)
    set(Ap)
    Ap.sort(reverse=True)
    for i in range(N):
        if  A[i] != Am:
            print(Am)
        else:
            print(Ap[1])
if __name__ == '__main__':
    main()