Buggy python submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
A_counter = Counter(A).most_common()
A_counter.sort(reverse = True)

ans = []

for i, cnt in A_counter.items():
    if cnt >= 2:
        ans.append(i)
        if len(ans) == 2:
            print(ans[0] * ans[1])
            break
    
    if cnt >= 4:
        print(i**2)
        break
    
else:
    print(0)

Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
h = w = 0

for i, cnt in Counter(A).items():
    if cnt >= 2 and i > w:
        if i > h:
            if cnt >= 4:
                h = i
                w = i
            else:
                w = h
                h = i
        else:
            w = i
            
print(w * h)

Buggy python submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
two = []
four = []

for i, cnt in Counter(A).items():
    if cnt >= 4:
        four.append(i)
    if 4 > cnt >= 2:
        two.append(i)
    if len(two) >= 2:
        break

if two:
    if four:
        print(max(two[0]*two[1], four[0]*four[0]))
    else:
        print(two[0]*two[1])
else:
    if four:
        print(four[0]* four[0])
    else:
        print(0)
    

Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
h = w = 0

for i, cnt in Counter(A).items():
    if cnt >= 2 and i > w:
        if i > h:
            if cnt >= 4:
                h = i
                w = i
            else:
                w = h
                h = i
        else:
            w = i
            
print(w * h)

Buggy python submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
two = []
four = []

for i, cnt in Counter(A).items():
    if cnt >= 4:
        four.append(i)
    if 4 > cnt >= 2:
        two.append(i)
    if len(two) >= 2:
        break

if two:
    if four:
        print(max(two[0]*two[1], four[0]*four[0]))
    else:
        print(two[0]*two[1])
else:
    print(0)

Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
h = w = 0

for i, cnt in Counter(A).items():
    if cnt >= 2 and i > w:
        if i > h:
            if cnt >= 4:
                h = i
                w = i
            else:
                w = h
                h = i
        else:
            w = i
            
print(w * h)

Buggy python submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
two = []
four = []

for i, cnt in Counter(A).items():
    if cnt >= 4:
        four.append(i)
    if cnt >= 2:
        two.append(i)
    if len(two) >= 2:
        break

print(max(two[0] * two[1], four[0] * four[0]))

Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
h = w = 0

for i, cnt in Counter(A).items():
    if cnt >= 2 and i > w:
        if i > h:
            if cnt >= 4:
                h = i
                w = i
            else:
                w = h
                h = i
        else:
            w = i
            
print(w * h)