Buggy python submission (verdict: Time Limit Exceeded):
# ARC081c
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    from collections import Counter

    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)

    mg = 0
    for i in a:
        if a.count(i) > 3 and mg != i:
            if mg == 0:
                print(i**2)
                exit(0)
            print(mg*i)
            exit(0)
        if a.count(i) > 1 and mg != i:
            if mg == 0:
                mg = i
                continue
            print(mg*i)
            exit(0)
    print(0)


if __name__ == '__main__':
    main()


Fixed submission:
# ARC081c
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    from collections import Counter
    import heapq

    n = int(input())

    def fun(i):
        return -int(i)

    a = list(map(fun, input().split()))
    heapq.heapify(a)

    b = []
    heapq.heapify(b)
    ln = 0
    cou = 0
    mn = 0
    while(len(a) > 0):
        i = -heapq.heappop(a)
        # print(i)
        if ln != i:
            ln = i
            cou = 0
        cou += 1
        if cou > 1:
            heapq.heappush(b, -i)
            cou = 0
    try:
        print(heapq.heappop(b)*heapq.heappop(b))
    except:
        print(0)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# ARC081c
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    from collections import Counter

    n = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse=True)

    mg = 0
    for i in a:
        if a.count(i) > 3 and mg != i:
            if mg == 0:
                print(i**2)
                exit(0)
            print(mg*i)
            exit(0)
        if a.count(i) > 1 and mg != i:
            if mg == 0:
                mg = i
                continue
            print(mg*i)
            exit(0)
    print(0)


if __name__ == '__main__':
    main()


Fixed submission:
# ARC081c
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    from collections import Counter
    import heapq

    n = int(input())

    def fun(i):
        return -int(i)

    a = list(map(fun, input().split()))
    heapq.heapify(a)

    b = []
    heapq.heapify(b)
    ln = 0
    cou = 0
    mn = 0
    while(len(a) > 0):
        i = -heapq.heappop(a)
        # print(i)
        if ln != i:
            ln = i
            cou = 0
        cou += 1
        if cou > 1:
            heapq.heappush(b, -i)
            cou = 0
    try:
        print(heapq.heappop(b)*heapq.heappop(b))
    except:
        print(0)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# ARC081c
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    from collections import Counter

    n = int(input())
    a = sorted(list(map(int, input().split())), reverse=True)

    mg = 0
    for i in a:
        if a.count(i) > 3 and mg != i:
            if mg == 0:
                print(i**2)
                exit(0)
            print(mg*i)
            exit(0)
        if a.count(i) > 1 and mg != i:
            if mg == 0:
                mg = i
                continue
            print(mg*i)
            exit(0)
    print(0)


if __name__ == '__main__':
    main()


Fixed submission:
# ARC081c
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    from collections import Counter
    import heapq

    n = int(input())

    def fun(i):
        return -int(i)

    a = list(map(fun, input().split()))
    heapq.heapify(a)

    b = []
    heapq.heapify(b)
    ln = 0
    cou = 0
    mn = 0
    while(len(a) > 0):
        i = -heapq.heappop(a)
        # print(i)
        if ln != i:
            ln = i
            cou = 0
        cou += 1
        if cou > 1:
            heapq.heappush(b, -i)
            cou = 0
    try:
        print(heapq.heappop(b)*heapq.heappop(b))
    except:
        print(0)


if __name__ == '__main__':
    main()