Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    sidelist = dict()

    for aa in a:
        if a.count(aa) >= 2:
            if aa not in sidelist:
                sidelist[aa] = 1
            else:
                sidelist[aa] += 1

    side_a = 0
    side_b = 0

    for s in sidelist:
        if sidelist[s] >= 4 and s > side_a:
            side_a = s
            side_b = s
        elif sidelist[s] >= 2:
            if side_a == 0:
                side_a = s
            elif side_b == 0:
                side_b = s
            elif s > side_a:
                side_b = side_a
                side_a = s
            elif s > side_b:
                side_b = s

    print(side_a*side_b)


Fixed submission:
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    sidelist = dict()

    for aa in a:
        if aa not in sidelist:
            sidelist[aa] = 1
        else:
            sidelist[aa] += 1

    side_a = 0
    side_b = 0

    for s in sidelist:
        if sidelist[s] >= 4 and s > side_a:
            side_a = s
            side_b = s
        elif sidelist[s] >= 2:
            if s > side_a:
                side_b = side_a
                side_a = s
            elif s > side_b:
                side_b = s

    print(side_a*side_b)

Buggy python submission (verdict: Runtime Error):
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    sidelist = OrderedDict()

    for aa in a:
        if a.count(aa) >= 2:
            if aa not in sidelist:
                sidelist[aa] = 1
            else:
                sidelist[aa] += 1

    side_a = 0
    side_b = 0

    for s in sidelist:
        if sidelist[s] >= 4 and s > side_a:
            side_a = s
            side_b = s
        elif sidelist[s] >= 2:
            if side_a == 0:
                side_a = s
            elif side_b == 0:
                side_b = s
            elif s > side_a:
                side_b = side_a
                side_a = s
            elif s > side_b:
                side_b = s

    print(side_a*side_b)


Fixed submission:
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    sidelist = dict()

    for aa in a:
        if aa not in sidelist:
            sidelist[aa] = 1
        else:
            sidelist[aa] += 1

    side_a = 0
    side_b = 0

    for s in sidelist:
        if sidelist[s] >= 4 and s > side_a:
            side_a = s
            side_b = s
        elif sidelist[s] >= 2:
            if s > side_a:
                side_b = side_a
                side_a = s
            elif s > side_b:
                side_b = s

    print(side_a*side_b)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import OrderedDict
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    sidelist = OrderedDict()

    for aa in a:
        if a.count(aa) >= 2:
            if aa not in sidelist:
                sidelist[aa] = 1
            else:
                sidelist[aa] += 1

    side_sorted = sorted(sidelist, reverse=True)

    side_a = 0
    side_b = 0

    for s in side_sorted:
        if sidelist[s] >= 4:
            side_a = s
            side_b = s
            break
        elif sidelist[s] >= 2:
            if side_a == 0:
                side_a = s
            else:
                side_b = s
                break

    print(side_a*side_b)


Fixed submission:
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    sidelist = dict()

    for aa in a:
        if aa not in sidelist:
            sidelist[aa] = 1
        else:
            sidelist[aa] += 1

    side_a = 0
    side_b = 0

    for s in sidelist:
        if sidelist[s] >= 4 and s > side_a:
            side_a = s
            side_b = s
        elif sidelist[s] >= 2:
            if s > side_a:
                side_b = side_a
                side_a = s
            elif s > side_b:
                side_b = s

    print(side_a*side_b)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import OrderedDict
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    sidelist = OrderedDict()

    for aa in a:
        if a.count(aa) >= 2:
            if aa not in sidelist:
                sidelist[aa] = 1
            else:
                sidelist[aa] += 1

    side_sorted = sorted(sidelist, reverse=True)

    side_a = 0
    side_b = 0

    for s in side_sorted:
        if sidelist[s] >= 4:
            side_a = s
            side_b = s
            break
        elif sidelist[s] >= 2:
            if side_a == 0:
                side_a = s
            else:
                side_b = s
                break

    print(side_a*side_b)


Fixed submission:
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    sidelist = dict()

    for aa in a:
        if aa not in sidelist:
            sidelist[aa] = 1
        else:
            sidelist[aa] += 1

    side_a = 0
    side_b = 0

    for s in sidelist:
        if sidelist[s] >= 4 and s > side_a:
            side_a = s
            side_b = s
        elif sidelist[s] >= 2:
            if s > side_a:
                side_b = side_a
                side_a = s
            elif s > side_b:
                side_b = s

    print(side_a*side_b)