Problem:
 Score : 300 points    Problem Statement We have N sticks with negligible thickness.
The length of the i -th stick is A_i .  Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides.
Find the maximum possible area of the rectangle.      Constraints  4 \leq N \leq 10^5  1 \leq A_i \leq 10^9  A_i is an integer.         Input Input is given from Standard Input in the following format:  N  A_1  A_2 ... A_N       Output Print the maximum possible area of the rectangle.
If no rectangle can be formed, print 0 .        Sample Input 1 6
3 1 2 4 2 1      Sample Output 1 2  1 \times 2 rectangle can be formed.       Sample Input 2 4
1 2 3 4      Sample Output 2 0  No rectangle can be formed.       Sample Input 3 10
3 3 3 3 4 4 4 5 5 5      Sample Output 3 20

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

over4 = []
over2 = []

for k, v in c.items():
    if v >= 4:
        over4.append(k)
    elif v >= 2:
        over2.append(k)

over4.sort(reverse=True)
over2.sort(reverse=True)

x, y, z = 0, 0, 0
if len(over4) > 0:
    x = over4[0] ** 2
if len(over2) >= 2:
    y = over2[0] * over2[1]
if len(over4) > 0 and len(over2) > 0:
    z = over4[0] * over2[0]

print(max(x, y, z))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
ac=Counter(a)
v=sorted(ac.items(),reverse=1)
ans=[]
ans1=[]

for i in range(len(ac)):
  if v[i][1]>=2:
    ans.append(v[i][0])
  if v[i][1]>=4:
    ans1.append(v[i][0])
if len(ans)>=2:
  if len(ans1)>=1:
      print(max(ans[0]*ans[1],ans1[0]**2))
  else:
      print(ans[0]*ans[1])
else:
  if len(ans1)>=1:
      print(max(0,ans1[0]**2))
  else:
      print(0)

Solution (Python):
import collections
n = int(input())
aa = list(map(int, input().split()))
ca = collections.Counter(aa)
la = sorted([a for a in ca.items()], key = lambda x:x[0], reverse=True)

list1 = []
list2 = []

for a in la:
  if a[1] > 1:
    list1.append(a)
  if a[1] >3:
    list2.append(a)
    
if len(list1) > 1:    
    xr = list1[0][0] * list1[1][0]
else:
  xr = 0
    
if len(list2) > 0:
  xs = list2[0][0] * list2[0][0]
else:
  xs = 0
  
ans = max(xr, xs)

print(ans)

Solution (Python):
import collections
n = int(input())
aa = list(map(int, input().split()))
ca = collections.Counter(aa)
la = sorted([a for a in ca.items()], key = lambda x:x[0], reverse=True)

list1 = []
list2 = []

for a in la:
  if a[1] > 1:
    list1.append(a)
  if a[1] >3:
    list2.append(a)
    
if len(list1) > 1:    
    xr = list1[0][0] * list1[1][0]
else:
  xr = 0
    
if len(list2) > 0:
  xs = list2[0][0] * list2[0][0]
else:
  xs = 0
  
ans = max(xr, xs)

print(ans)

Solution (Python):
import collections
n = int(input())
alist = list(map(int,input().split()))
adic = collections.Counter(alist)
A = [0,0]
for i in adic:
  if adic[i] > 1:
    A.append(i)
  if adic[i] > 3:
    A.append(i)
sortedA = sorted(A)
print(sortedA[-1]*sortedA[-2])

Solution (Python):
N = int(input())
List = list(map(int,input().split()))
List = sorted(List)[::-1]
L = 0
S = 0
temp = 0
for i in range(N-1):
  if List[i] == List[i+1]:
    L = List[i]
    temp =i+1
    break
for i in range(temp+1,N-1):
  if List[i] == List[i+1]:
    S = List[i]
    break
print(L*S)

Solution (Python):
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
c = Counter(A)

over4 = []
over2 = []

for k, v in c.items():
    if v >= 4:
        over4.append(k)
    elif v >= 2:
        over2.append(k)

over4.sort(reverse=True)
over2.sort(reverse=True)

s1, s2, s3 = 0, 0, 0
if len(over4) > 0:
    s1 = over4[0]**2
if len(over2) >= 2:
    s2 = over2[0]*over2[1]
if len(over4) > 0 and len(over2) > 0:
    s3 = over4[0]*over2[0]

print(max(s1, s2, s3))

Solution (Python):



a=int(input())





f = list(map(int,input().split()))


f.sort()
ma =[]
count=1
for i in range(len(f)-1):
    if f[i]==f[i+1] and f[i]!=0:
        count+=1
    elif f[i]!=f[i+1] and count>=2 :
        ma.append(f[i])
        count=1
    elif  f[i]!=f[i+1] and count==1 :
        count=1
    else:
        count=1

if count>=4:
    ma.append(f[-1])
    ma.append(f[-1])
elif count>=2:
    ma.append(f[-1])


if ma==[]:
    print(0)
else:
    print(ma[-1]*ma[-2])

Solution (Python):
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n = k()
a = l()

a.sort(reverse=True)
b = -1

for i in a:
    if i==b:
        if ans != 0:
            ans *= i
            break
        else:
            ans = i
            b = -1
            continue
    b = i
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
A = A[::-1]


cnt = 1
length = []
for i in range(1, N):
    if A[i] == A[i-1]:
        cnt += 1
        if cnt >= 2:
            length.append(A[i])
            cnt = 0
            if len(length) >= 2:
                break
    elif cnt == 0:
        cnt = 1
else:
    length = [0, 0]
print(length[0] * length[1])

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
ans=0
b=-1
for i in a:
  if i==b:
    if ans!=0:
      ans*=i
      break
    else:
      ans=i
      b=-1
      continue
  b=i
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
A = list(map(int,input().split()))

cnt = Counter(A)

parts = []
for k in sorted(cnt.keys(),reverse=True):
    if cnt[k] >= 4:
        parts += [k,k]
    elif cnt[k] >= 2:
        parts.append(k)

if len(parts) >= 2:
    print(parts[0]*parts[1])
else:
    print(0)

Solution (Python):
import collections
n = int(input())
a = sorted(list(map(int, input().split())))

cnt = collections.Counter(a)
l1 = 0
l2 = 0

for i in cnt.keys():
    if cnt[i] >= 4:
        l1 = i
        l2 = i
    elif cnt[i] >= 2:
        l1, l2 = i, l1
print(l1 * l2)

Solution (Python):
import collections
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

one = 0
theo = 0
skip = False
for i in range(N-1):
    if skip:
        skip = False
        continue
    if A[i] == A[i+1]:
        if one == 0:
            one = A[i+1]
            skip = True
        else:
            theo = A[i+1]
            break
print(one*theo)

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
A=Counter(a)
s=set(a)
S=sorted(list(s))
S.reverse()
h=0
w=0
for i in S:
  res=A[i]
  if res>=4:
    if h==0:
      h=i
    if w==0:
      w=i
  elif 2<=res<4:
    if w==0:
      w=i
    elif w!=0 and h==0:
      h=i
print(h*w)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')

from collections import deque, defaultdict





def solve():
    N = II()
    A = LI()
    dct = defaultdict(int)
    for a in A:
        dct[a] += 1
    
    
    left = 2
    pre = 0
    for n, c in sorted(dct.items(), key=lambda x: x[0], reverse=True):
        
        if c >= 4:
            if left == 2:
                print(n ** 2)
                return
            elif left == 1:
                print(pre * n)
                return
        elif c >= 2:
            if left == 2:
                pre = n
                left -= 1
                continue
            elif left == 1:
                print(pre * n)
                return
    print(0)


if __name__ == '__main__':
    solve()

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right 
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class countdict(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1        

N,A = ilint()
S = countdict()
L = list()
for a in A:
    S.add(a)
    if S[a]>=2:
        L.append(a)
        S[a] -= 2
L.sort(reverse=True)
print(0 if len(L)<2 else L[0]*L[1])

Solution (Python):
from collections import Counter

n = int(input())
A = list(map(int, input().split()))

B = set(A)
C = sorted(list(B))
A = Counter(A)


ans = 0
keep = 0

for i in C:
    kazu = A[i]
    if kazu >= 4:
        ans = i**2
        keep = i
    elif kazu >= 2:
        ans = keep * i
        keep = i
print(ans)

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
b=a.sort(reverse=True)
for i in range(n-1):
    if a[i]==a[i+1]:
        for j in range(i+2,n-1):
            if a[j]==a[j+1]:
                print(a[i]*a[j])
                exit()
else:
    print(0)

Solution (Python):

import collections 
N = int(input())
A = map(int,input().split())

cnt = collections.Counter(A)

cnt_2 = [i for i , j in cnt.items() if j>=2]

cnt_4 = [i for i, j in cnt.items() if j>=4]

cnt_2 = sorted(cnt_2,reverse = True)
cnt_4 = sorted(cnt_4,reverse = True)

ans1 = 0
ans2 = 0 
if len(cnt_2) >=2:
    ans1 = cnt_2[0]*cnt_2[1]
if len(cnt_4) >=1:
    ans2 = cnt_4[0]**2
    
print(max(ans1,ans2))

Solution (Python):
n = int(input())
A = list(map(int, input().split()))

d = dict()

for a in A:
    d[a] = d.get(a, 0) + 1

x = [(l, n) for l, n in sorted(d.items(), reverse=True, key=lambda x:x[0]) if n >= 2]
y = [(l, n) for l, n in sorted(d.items(), reverse=True, key=lambda x:x[0]) if n >= 4]

if x == [] and y == []:
    print(0)
else:
    ans = 0
    if len(x) >= 2:
        ans = max(ans, x[0][0] * x[1][0])
    if len(y) >= 1:
        ans = max(ans, y[0][0]**2)
    print(ans)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
count_a = Counter(a)
new_a = [i for i in count_a.keys() if count_a[i] >= 2]

if len(new_a) < 2:
    print(0)
    exit()
new_a = sorted(new_a, reverse=True)
if count_a[new_a[0]] >= 4:
    ans = new_a[0] ** 2
else:
    ans = new_a[0] * new_a[1]
print(ans)

Solution (Python):
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)

d = {}
l = []
for a in A:
  if a in d:
    d[a] += 1
    if d[a] % 2 == 0:
      l.append(a)
  else:
    d[a] = 1
  
  if len(l) == 2:
    print(l[0] * l[1])
    quit()

print(0)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
d = dict()

for ai in a:
    if ai not in d.keys():
        d[ai] = 1
    else:
        d[ai] += 1

l2 = []
l4 = []
for k, v in d.items():
    if v >= 2:
        l2.append(k)
    if v >= 4:
        l4.append(k)

l2.sort()
l4.sort()
if len(l2) > 1:
    if len(l4) > 0:
        ans = max(l2[-1]*l2[-2], l4[-1]**2)
    else:
        ans = l2[-1]*l2[-2]
elif len(l2) == 1:
    if len(l4) > 0:
        ans = l4[-1]**2
    else:
        ans = 0
else:
    ans = 0
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
A = Counter([int(i) for i in input().split()])

A = sorted(A.items(), key=lambda x: -x[0])

x = []
while len(x) < 2:
    for a, cnt in A:
        while cnt > 1 and len(x) < 2:
            x.append(a)
            cnt -= 2
    else:
        break

if len(x) < 2:
    print(0)
else:
    print(x[0] * x[1])

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

b1 = [i[0] for i in c.items() if i[1] >= 4]
b2 = [i[0] for i in c.items() if i[1] >= 2]
b = b1 + b2 + [0,0]

b.sort()
print(b[-1]*b[-2])

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
A_Counter = Counter(A)
A_Counter = sorted(A_Counter.items(), key=lambda x:x[0],reverse=True)



anslis = []
count = 0 
for single in A_Counter:

    key = int(single[0])
    value = int(single[1])
    
    if value >= 4:
        if count == 0:
            anslis.append(int(key))
            break
        else:
            anslis.append(int(key))
            count += 1
    
    if 2 <= value <= 3:
        anslis.append(int(key))
        count += 1
    
    if count == 2:
        break

if len(anslis) == 0:
    print(0)
elif len(anslis) == 1:
    print(anslis[0]**2)
else:
    print(anslis[0]*anslis[1])

Solution (Python):
from collections import *
N = int(input())
A = Counter(list(map(int, input().split())))

x = [0,0]
for key, value in A.items():
    if A[key] > 1:
        x.append(key)
    if A[key] > 3:
        x.append(key)
x = sorted(x)

print(x[-1]*x[-2])

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
li=[]
A.sort()
s=True

for i in range(N-1):
    if A[i]==A[i+1] and s==True:
        li.append(A[i])
        s=False
    else:
        s=True
li.sort(reverse=True)

if len(li)>=2:
    print(li[0]*li[1])
else:
    print(0)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
c=1
x=y=0
for i in range(n-1):
    if A[i]==A[i+1]:
        c+=1
        if c==2:
            if x!=0:
                y=A[i]
                break
            else:
                x=A[i]
        if c==4:
            x=y=A[i]
            break
    else:
        c=1
print(x*y)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
for i in range(N-1):
    if A[i] == A[i+1]:
        for j in range(i+2, N-1):
            if A[j] == A[j+1]:
                print(A[i]*A[j])
                exit()
else:
    print(0)

Solution (Python):
from collections import Counter
n = int(input())
c = Counter(map(int, input().split()))

L = R = 0
for k, v in c.items():
    if 4 <= v:
        L = max(L, k)
        R = max(R, k)
    elif 2 <= v:
        if R < L:
            L, R = R, L
        L = max(L, k)

print(L*R)

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    n = I()
    a = LI()
    a.sort()
    gr = itertools.groupby(a)
    lst = []
    for key, group in gr:
        lenth = len(list(group))
        if lenth >= 4:
            lst.append(key)
        if lenth >= 2:
            lst.append(key)

    ans = 0
    if len(lst) >= 2:
        ans = lst[-1] * lst[-2]
    print(ans)
main()

Solution (Python):
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
four=0
two=[]
numbers=Counter(A)
for key,value in numbers.items():
    if value>=4:
        four=max(four,key**2)
    if value>=2:
        two.append(key)
sorted_two=sorted(two)
if four==0 and len(sorted_two)<=1:
    print(0)
else:
    print(max(four,sorted_two[-1]*sorted_two[-2]))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))

A.sort(reverse = True)
a=0
b=0
cnt = 1
for i in range(1,len(A)):
    if A[i]==A[i-1]:
        cnt+=1
    else:
        cnt=1
        
    if cnt==2:
        if a==0:
            a=A[i]
        elif b==0:
            b=A[i]
        cnt=0
        
        if a*b!=0:
            break

print(a*b)

Solution (Python):
N=int(input())
*A,=map(int,input().split())
d={}
for a in A:
    d[a] = d.get(a, 0)+1
s=sorted([(k,v) for k,v in d.items() if 2<=v], reverse=True)

if len(s)<2:
    print(0)
else:
    if 4<=s[0][1]:
        print(s[0][0]**2)
    else:
        print(s[0][0]*s[1][0])

Solution (Python):
import sys
import math
from collections import Counter


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())


n = inint()
A = inintl()

A = Counter(A)
b = []

m = 0

for a in A:
    if A[a] >= 4:
        if a > m:
            m = a
    if A[a] >= 2:
        b.append(a)

b = sorted(b)[::-1]


if len(b) < 2:
    if m != 0:
        print(m*m)
    else:
        print(0)
elif m*m > b[0]*b[1]:
    print(m*m)
else:
    print(b[0]*b[1])

Solution (Python):
from collections import Counter
n = int(input())

a = list(map(int, input().split()))
c = Counter(a)
f = [0,0]
for k in c.keys():
    if c[k] >= 2:
        f.append(k)
    if c[k] >= 4:
        f.append(k)

f.sort()

[a, b] = f[-2:]

print(a*b)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

a = [0] * 2
i = j = 0
while i < N - 1:
    if A[i] == A[i + 1]:
        a[j] = A[i]
        i += 1
        j += 1
    if j == 2:
        break
    i += 1
print(a[0] * a[1])

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
counter_a = Counter(a)
ok_list = []
for key,value in counter_a.items():
    if value >= 4:
        ok_list.append(key)
        ok_list.append(key)
    elif value >= 2:
        ok_list.append(key)
    else:
        continue
ok_list.sort(reverse=True)
if len(ok_list) >= 2:
    ans = ok_list[0] * ok_list[1]
else:
    ans = 0
print(ans)

Solution (Python):
import collections
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
c = collections.OrderedDict(sorted(c.items(), key=lambda x:x[0],reverse=True))
high=0
low=0
for i,j in zip(c.keys(),c.values()):
    if(j>=4):
        if(high==0):
            high=i
        if(low==0):
            low =i
        break
    elif(j>=2):
        if(high==0):
            high=i
        else:
            low=i
            break
print(high*low)

Solution (Python):
import sys
from collections import Counter

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A = nl()
    C = Counter(A)
    can = []
    seq = []
    for c in set(A):
        if C[c] >= 2:
            can.append(c)
            if C[c] >= 4:
                seq.append(c)

    if can:
        can = sorted(can)
        if seq:
            seq = sorted(seq)
            print(max(can[-1] * can[-2], seq[-1] ** 2))
        else:
            print(can[-1] * can[-2])
    else:
        print(0)


if __name__ == '__main__':
    main()

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

tmp = a[0]
ans = []
cnt = 0
for i in range(1,len(a)):
    if tmp == a[i]:
        cnt += 1
        if cnt == 1 or cnt == 3:
            ans.append(tmp)
    else:
        tmp = a[i]
        cnt = 0


if len(ans) < 2:
    print(0)
else:
    print(ans[0]*ans[1])

Solution (Python):
import collections
import sys
N=int(input())
ans=0
ANS=[]
A = list(map(int, input().split()))
new_A = sorted(A, reverse=True)
j=0

for i in range(len(A)-1):
    if new_A[j]==new_A[j+1]:
        ANS.append(new_A[j])
        
        j+=1
    if len(ANS)==2:
        print(ANS[0]*ANS[1])
        sys.exit()
    j+=1
print("0")

Solution (Python):
import collections

def main():
    N = int(input())
    A = list(map(int, input().split()))
    rankA = list(set(A))
    rankA.sort(reverse=True)
    Acounter = collections.Counter(A)
    res = 4
    ans = []
    for a in rankA:
        count = Acounter[a]
        if count >= 2:
            ans.append(a)
            res = res - 2
            count = count - 2
            if len(ans) == 2:
                break
            if count >= 2:
                ans.append(a)
                break

    if len(ans) < 2:
        print(0)
        return

    a1 = ans.pop()
    a2 = ans.pop()
    ans = a1*a2
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
l=[]
s=0
i=1
while i<N:
  if A[i]==A[i-1]:
    l.append(A[i])
    i+=1
  if len(l)==2:
    s=l[0]*l[1]
    break
  i+=1
print(s)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
A = sorted(A, reverse=True)
tate=0
yoko=0

for i in range(N-1):
    if A[i]==A[i+1]:
        tate=A[i]
        A.remove(A[i+1])
        A.remove(A[i])
        break

for i in range(len(A)-1):
    if A[i]==A[i+1]:
        yoko=A[i]
        break

print(tate*yoko)

Solution (Python):
import sys
from operator import itemgetter
import collections
import math


def r(n, a):
    a.sort(reverse=True)
    side = [0, 0]
    s = 0
    i = 0
    for i in range(s, n - 1):
        if a[i] == a[i + 1]:
            side[0] = a[i]
            break
    s = i + 2
    for i in range(s, n - 1):
    	if a[i] == a[i + 1]:
            side[1] = a[i]
            break
    return side[0] * side[1]


def main():
    input = sys.stdin.readline
    n = int(input())
    a = list(map(int, input().split()))
    print(r(n, a))


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
d = {}

max1 = 0
max2 = 0

for i in range(n):
    if a[i] in d:
        if d[a[i]] == 1 or d[a[i]] == 3:
            if a[i] > max2:
                if a[i] > max1:
                    max2 = max1
                    max1 = a[i]
                else:
                    max2 = a[i]
        d[a[i]] += 1
    else:
        d[a[i]] = 1

print(max1*max2)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))

A.sort(reverse = True)

l = []
tmp = 0
for i in range(n-1):
    if A[i] == A[i+1]:
        l.append(A[i])
        tmp = i+1
        break

for i in range(tmp+1, n-1):
    if A[i] == A[i+1]:
        l.append(A[i])
        break

print(l[0] * l[1] if len(l) == 2 else 0)

Solution (Python):
from collections import Counter
N=int(input())
A=Counter(list(map(int,input().split())))
x=[0,0]
for a in A:
    if A[a]>1:x.append(a)
    if A[a]>3:x.append(a)
x.sort()
print(x[-1]*x[-2])

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    cnt = collections.Counter(A)
    edge = [k for k, v in cnt.items() if v >= 2]
    edge.sort(reverse=True)


    if len(edge) >= 1 and cnt[edge[0]] >= 4:
        ans = edge[0] ** 2
    elif len(edge) >= 2:
        ans = edge[0] * edge[1]
    else:
        ans = 0

    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    cnt = collections.Counter(A)
    edge = [(k, v) for k, v in cnt.items() if v >= 2]
    edge.sort(reverse=True)

    if len(edge) >= 1 and edge[0][1] >= 4:
        ans = edge[0][0] ** 2
    elif len(edge) >= 2:
        ans = edge[0][0] * edge[1][0]
    else:
        ans = 0

    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
from collections import Counter
def solve():
  N = int(input())
  A = list(map(int, input().split()))
  c = Counter(A)
  B = [k for k,v in c.items() if v>=2]
  C = [k for k,v in c.items() if v>=4]
  B.extend(C)
  B.sort(reverse=True)
  if len(B)<2:
    return 0
  ans = B[0]*B[1]
  return ans
print(solve())

Solution (Python):
from collections import Counter

N = int(input())
a = list(map(int,input().split()))

d = Counter(a)
l = []
flag = False
for k,v in list(sorted(d.items()))[::-1]:
  if v >= 4:
    l.append(k)
    l.append(k)
  elif v >= 2:
    l.append(k)
  if len(l) >= 2:
    flag = True
    break

ans = 0
if flag:
  ans = l[0]*l[1]


print(ans)

Solution (Python):
from collections import Counter

N = int(input())
a = list(map(int,input().split()))

d = Counter(a)
l = []
flag = False
for k,v in list(sorted(d.items()))[::-1]:
  if v >= 4:
    l.append(k)
    l.append(k)
  elif v >= 2:
    l.append(k)
  if len(l) >= 2:
    flag = True
    break

ans = 0
if flag:
  ans = l[0]*l[1]


print(ans)

Solution (Python):
import collections
n = int(input())
a = list(map(int,input().split()))
c = sorted(collections.Counter(a).items(),reverse = True)

num2 = []
num4 = []
ans = [0]

for k in c:
  if k[1]>=4:
    num4.append(k[0])
  if k[1]>=2:
    num2.append(k[0])

if len(num2)>=2:
  ans.append(num2[0]*num2[1])
if len(num4)>=1:
  ans.append(num4[0]**2)

print(max(ans))

Solution (Python):
import collections
n = int(input())
a = list(map(int,input().split()))

c = sorted(collections.Counter(a).items(),reverse = True)

tmp = 0
ans=[]

for k in c:
  if k[1]>=4:
    tmp = max(tmp,k[0]*k[0])
  if k[1]>=2:
    ans.append(k[0])
  else:
    continue

if len(ans)>=2:
  print(max(ans[0]*ans[1],tmp))
else:
  print(tmp)

Solution (Python):
import collections
N = int(input())
A = list(map(int,input().split()))
B = collections.Counter(A)
C = [0,0]
for i in set(A):
    if B[i] >= 4:
        C.append(i)
    if B[i] >= 2:
        C.append(i)
C.sort(reverse=True)
print(C[0]*C[1])

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
i = 1
j = 0
ans = 1
while i < n and j < 2:
    if a[i-1] == a[i]:
        ans *= a[i]
        j += 1
        i += 2
    else:
        i += 1
if j == 2:
    print(ans)
else:
    print(0)

Solution (Python):
import sys
input = sys.stdin.readline
from collections import Counter


def read():
    N = int(input().strip())
    A = map(int, input().strip().split())
    return N, A


def solve(N, A):
    C = Counter(A)
    first = 0
    second = 0
    for k in C.keys():
        if k > first and C[k] >= 2:
            first = k
    C[first] -= 2
    for k in C.keys():
        if k > second and C[k] >= 2:
            second = k
    return first * second


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Solution (Python):
import heapq
N = int(input())
A = list(map(int, input().split()))+[0]*4
A = list(map(lambda x: x*(-1), A))
heapq.heapify(A)
a, b = -10**18, -10**18
while True:
  x = heapq.heappop(A)
  if a == x:
    break
  else:
    a = x
while True:
  x = heapq.heappop(A)
  if b == x:
    break
  else:
    b = x
print(a*b)

Solution (Python):
from collections import Counter

N=int(input())
A=[int(i) for i in input().split()]
A=Counter(A)
e1=0
e2=0
for key,value in A.items():
    if value<2:
        continue
    elif value>=4:
        e1=max(e1,key)
        e2=max(e2,key)
    else:
        if key>e1:
            e2=e1
            e1=key
        else:
            e2=max(e2,key)
print(e1*e2)

Solution (Python):
from collections import Counter
input()
A = Counter(list(map(int, input().split()))+[0]*4)
A = [(a[0], a[1]) for a in A.most_common()  if a[1]>1]
A.sort(key=lambda l: -l[0])
print(A[0][0]**2 if A[0][1]>3 else A[0][0]*A[1][0])

Solution (Python):
from sys import stdin
from collections import Counter
def main():
  readline = stdin.readline
  N = int(input())
  A = list((map(int, readline().split())))
  C = Counter(A)
  A = sorted(set(A))
  flag = False
  for a in A[::-1]:
    if flag:
      if C[a] >= 2:
        print(a*b)
        break
    elif C[a] >= 4:
      print(a*a)
      break
    elif C[a] >= 2:
      b = a
      flag = True
  else:
    print(0)
if __name__ == "__main__":
  main()

Solution (Python):

from collections import defaultdict

n, *a = map(int, open(0).read().split())
ans = [0, 0]
d = defaultdict(int)
for i in a:
    d[i] += 1
    if d[i] > 1 and i > ans[0]:
        ans = sorted(ans + [i])[-2:]
        d[i] -= 2
print(ans[0] * ans[1])

Solution (Python):
from collections import Counter
n=int(input())
a=Counter(list(map(int,input().split()))).most_common()
x=[0,0]

for i in range(len(a)):
  if x[1]<=a[i][0] and x[0]<=a[i][0] and a[i][1]>=4:
    x[0],x[1]=a[i][0],a[i][0]
  elif (x[1]<=a[i][0] or x[0]<=a[i][0]) and a[i][1]>=2:
    if x[0]<x[1]:
      x[0]=a[i][0]
    else:
      x[1]=a[i][0]
print(x[0]*x[1])

Solution (Python):
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
d = Counter(A)
key = d.keys()
ans = []
for k in key:
    if d[k] >= 2:
        ans.append(k)
        if d[k] >= 4:
            ans.append(k)
if len(ans) < 2:
    print(0)
else:
    ans.sort()
    print(ans[-1]*ans[-2])

Solution (Python):
from collections import Counter

N=int(input())
A=Counter(list(map(int,input().split())))

x=sorted([i for i in A.items() if i[1]>=2])

if len(x)<2:
    print(0)
elif x[-1][1]>=4:
    print(x[-1][0]**2)
else:
    print(x[-1][0]*x[-2][0])

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
V = sorted([(k, v) for k, v in C.most_common() if v >= 2])
a = 0
b = 0
for v in V[::-1]:
    if a == 0:
        if v[1] >= 4:
            a, b = v[0], v[0]
            break
        else:
            a = v[0]
    else:
        b = v[0]
        break
print(a * b)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))

D={}
for a in A:
    if a in D:
        D[a]+=1
    else:
        D[a]=1
        
S=[0,0]
for a in D:
    for _ in range(D[a]//2):
        S.append(a)
        
x=max(S)
del S[S.index(x)]
y=max(S)
print(x*y)

Solution (Python):
from collections import Counter

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

d = Counter(A)

tmp_2 = []
tmp_4 = []
for k, v in d.items():
    if v >= 4:
        tmp_4.append(k)
    if v >= 2:
        tmp_2.append(k)

ans = 0
tmp_2.sort()
tmp_4.sort()
if len(tmp_4):
    ans = tmp_4[-1]**2
if len(tmp_2) >= 2:
    ans = max(ans, tmp_2[-1]*tmp_2[-2])
print(ans)

Solution (Python):
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
A_dic = Counter(A)

set_A = sorted((set(A)), reverse=True)
tmp = 0
for a in set_A:
    if A_dic[a] >= 4:
        print(max(tmp*a, a*a))
        exit()
    if A_dic[a] >= 2:
        ans = tmp * a
        if ans != 0:
            print(ans)
            exit()
        tmp = a
print(0)