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):
N=int(input())
*A,=map(int, input().split())
from collections import Counter
C=Counter(A)
ca=-1
E=sorted(C.items(), key=lambda x:x[0], reverse=True)
for k,v in E:
    if ca >= 0:
        if v >= 2:
            print(ca*k)
            exit()
    else:
        if v >= 4:
            print(k*k)
            exit()
        elif v >= 2:
            ca = k
print(0)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
A.sort()
A.reverse()
h=int(0)
w=int(0)
i=int(1)
while i<n:
    if A[i]==A[i-1] and h==0:
        h=A[i]
        i+=1
    elif A[i]==A[i-1] and w==0:
        w=A[i]
        i+=1
    i+=1
print(h*w)

Solution (Python):
import sys
from heapq import heapify, heappop, heappush

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    Anum = dict()
    for a in A:
        if a in Anum: Anum[a] += 1
        else: Anum[a] = 1
    q = [0, 0]
    for key in Anum:
        if Anum[key] >= 2: q.append(-key)  
        if Anum[key] >= 4: q.append(-key)
    heapify(q)
    x = heappop(q)
    y = heappop(q)
    print(x * y)


    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n = INT()
a = LIST()
b = Counter(a)
c = sorted(list(set(a)), reverse=True)
ans = []
for i in c:
    if b[i] >= 2:
        ans.append(i)
    if b[i] >= 4:
        ans.append(i)
    if len(ans) >= 2:
        break
debug(ans)
if len(ans) >= 2:
    print(ans[0] * ans[1])
else:
    print(0)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
from collections import Counter
ctr = Counter(A)
x = None
for k,v in reversed(sorted(ctr.items())):
    if v >= 4:
        if x:
            print(x*k)
        else:
            print(k**2)
        exit()
    if v >= 2:
        if x:
            print(x*k)
            exit()
        x = k
print(0)

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

S = []
for a, c in A.items():
    S.extend([a] * (c // 2))

S.sort()
if len(S) < 2:
    print(0)
else:
    print(S[-1] * S[-2])

Solution (Python):
import collections
n = int(input())
A = collections.Counter([int(x) for x in input().split()])
lst1 = [-1]
lst2 = [-1]
for l, c in A.items():
  if c > 1:
    lst1.append(l)
  if c > 3:
    lst2.append(l*l)
lst1.sort()
if len(lst1)-1>1 or len(lst2)-1>0:
  if len(lst1)-1>1:
    print(max(max(lst2), lst1[-1]*lst1[-2]))
  else:
    print(max(lst2))
else:
  print(0)

Solution (Python):
n = input()
l = list(map(int, input().split()))
w, h, temp = 0, 0, 0
cnt = 1
for i in sorted(l, reverse=True):
    if temp == i:
        cnt += 1
        if w == 0:
            w = i
        elif w != i:
            print(w*i)
            exit()
        if cnt == 4:
            print(w*w)
            exit()    
    else:
        cnt = 1
    temp = i
print(0)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
l1 = [0,0]
from collections import Counter
c = Counter(l)
for i in c.items():
  if i[1]>=2 :
    l1.append(i[0])
  if i[1]>=4 :
    l1.append(i[0])
l1.sort()
print(l1[-1]*l1[-2])

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

c = collections.Counter(A)
cs = sorted(c.items(), key=lambda x:x[0], reverse=True)

area = []
for i in range(len(cs)):
    if(cs[i][1] > 1):
        if(cs[i][1]//2 == 1):
            area.append(cs[i][0])
            if(len(area) == 2):
                print(area[0]*area[1])
                break
        else:
            area.append(cs[i][0])
            if(len(area) > 1):
                print(max(cs[i][0]*cs[i][0], area[0]*area[1]))
                break
            else:
                print(cs[i][0]*cs[i][0])
                break
else:
    print(0)

Solution (Python):

from collections import Counter, deque







import sys

sys.setrecursionlimit(10 ** 5 + 10)




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

    AA = Counter(A).most_common()

    ls = []
    for i in range(len(AA)):
        if AA[i][1] >= 2:
            ls.append(AA[i])
        else:
            break

    ls=sorted(ls, key=lambda x: x[0])

    try:
        ans = ls[-1][0] * ls[-2][0]
        for i in reversed(range(len(ls))):
            if ls[i][1] >= 4:
                ans = max(ans, ls[i][0] ** 2)
        print(ans)
    except:
        print(0)


resolve()

Solution (Python):
import collections as c

n = int(input())
co = c.Counter(list(map(int, input().split())))
cm = sorted(co.items(), key=lambda x:x[0], reverse=True)
a = 0
b = 0
for v,m in cm:
  if m >= 4:
    if a == 0:
      a = b = v
    else:
      b = v
    break
  elif m >= 2 and a == 0:
    a = v
  elif m >= 2 and a != 0:
    b = v
    break
print(a*b)

Solution (Python):

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Aset = list(set(A))
Aset.sort(reverse=True)
a, b = 0, 0
L = []
cnt = 1
for i in range(1, N):
    if A[i] == A[i-1]:
        cnt += 1
    else:
        L.append(cnt)
        cnt = 1
if A[-1] == A[-2]:
    L.append(cnt)
idx = 0
for i in range(len(L)):
    if L[i] >= 4:
        a, b = Aset[i], Aset[i]
        break
    elif L[i] >= 2:
        a = Aset[i]
        idx = i + 1
        break
if b <= 0:
    for i in range(idx, len(L)):
        if L[i] >= 2:
            b = Aset[i]
            break
print(a * b)

Solution (Python):

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

A.sort()

L1=0
L2=0
used=[False for i in range(N)]
for i in range(1,N):
    if A[i]==A[i-1] and not used[i-1] and not used[i]:
        if L1<=A[i]:
            used[i-1]=True
            used[i]=True
            L2=L1
            L1=A[i]

print(L1*L2)

Solution (Python):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
h = {}
for x in a:
    if x not in h:
        h[x] = 0
    h[x] += 1
b = []
for x in h:
    if h[x]>=2:
        b.append(x)
b.sort()
if len(b)>=1 and h[b[-1]]>=4:
    print(b[-1]*b[-1])
elif len(b)<2:
    print(0)
else:
    print(b[-1]*b[-2])

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

table = collections.defaultdict(int)
hq = [0, 0]
for x in A:
    table[x] += 1
    if table[x] == 2:
        heapq.heappush(hq, -x)
        table[x] = 0
print(heapq.heappop(hq) * heapq.heappop(hq))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
dls = []
A.sort()
A.reverse()
now = 0
for i in range(N-1):
  if now >= N-1:
    break
  else:
    if A[now] == A[now+1]:
      dls.append(A[now])
      now += 2
    else:
      now += 1
if len(dls) >= 2:
  print(dls[0]*dls[1])
else:
  print(0)

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

from collections import Counter
c = Counter(A)

x = 0
y = 0
for k, v in sorted(c.items(), key=lambda x: -x[0]):
    if v >= 4 and x == 0 and y == 0:
        x = y = k
    elif v >= 2:
        if x == 0:
            x = k
        elif y == 0:
            y = k

print(x*y)

Solution (Python):
from collections import defaultdict
N = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
ans = 0
for i in a:
    d[i] += 1
ans1 = []
for v, c in d.items():
    if c >= 2:
        ans1.append(v)

ans1.sort(reverse=True)
if len(ans1) > 1:
    ans = ans1[0] * ans1[1]

ans2 = []
for v, c in d.items():
    if c >= 4:
        ans2.append(v)

ans2.sort(reverse=True)

if len(ans2) > 0:
    ans = max(ans, ans2[0] * ans2[0])

print(ans)

Solution (Python):
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
ans = [0]
l =[]
values, counts = zip(*cnt.most_common())
for v, c in zip(values, counts):
    if c > 3:
        ans.append(v**2)
        l.append(v)
    elif c > 1:
        l.append(v)
l.sort(reverse=True)
if len(l) > 1:
    ans.append(l[0] * l[1])
print(max(ans))

Solution (Python):
from collections import Counter
n = int(input())
l = list(map(int,input().split()))
a = Counter(l)
b = a.most_common()
c = []
for i,j in b:
    if j>=4:
        c.append(i)
        c.append(i)
    elif j>=2:c.append(i)
c.sort()
print(c[-1]*c[-2] if len(c)>=2 else 0)

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

L = []
for a, c in cnt.items():
    if c >= 2:
        L += [a] * (c // 2)
L.sort()

ans = 0 if len(L) < 2 else L[-1] * L[-2]
print(ans)

Solution (Python):

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

a.sort(reverse = True)
tmp = []
i = 0
while i < n - 1:
    if a[i] == a[i + 1]:
        tmp.append(a[i])
        i += 2
    else:
        i += 1
if len(tmp) >= 2:
    print(tmp[0] * tmp[1])
else:
    print(0)

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

A = list(sorted(A, reverse=True))
ans = 1
is_before = False
count = 0
for i in range(N-1):
    if not is_before:
        if A[i] == A[i+1]:
            ans = ans * A[i]
            is_before = True
            count = count + 1
    else:
        is_before = False

    if count>1:
        print ans
        exit()

print 0

Solution (Python):
from collections import Counter

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

e=[]
f=[]

for i in c:
  if c[i]>1:
    e.append(i)
  if c[i]>=4:
    f.append(i)

e.sort(reverse=True)
f.sort(reverse=True)
if len(f)>=1:
  if f[0]>=e[0]:
    print(f[0]**2)
  else:
    if len(e)>=2:
      print(e[0]*e[1])
    else:
      print(0)
else:
  if len(e)>=2:
    print(e[0]*e[1])
  else:
    print(0)

Solution (Python):
import collections
 
n = int(input())
lens = list(map(int,input().split()))
lens = collections.Counter(lens)
lens = sorted(lens.items(), key=lambda x:x[0], reverse = True)
cnt = 0
for j in lens:
  if j[1] >= 4 and cnt == 0:
    print(j[0]**2)
    break
  elif j[1] >= 2 and cnt == 0:
    cnt = j[0]
  elif j[1] >= 2 and cnt != 0:
    print(cnt * j[0])
    break
else:
    print(0)

Solution (Python):
import collections
 
n = int(input())
lens = list(map(int,input().split()))
lens = collections.Counter(lens)
lens = sorted(lens.items(), key=lambda x:x[0], reverse = True)
cnt = 0
for j in lens:
  if j[1] >= 4 and cnt == 0:
    print(j[0]**2)
    break
  elif j[1] >= 2 and cnt == 0:
    cnt = j[0]
  elif j[1] >= 2 and cnt != 0:
    print(cnt * j[0])
    break
else:
    print(0)

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

Solution (Python):
import sys
input = sys.stdin.readline
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):
N = int(input())
import collections
A = list(map(int,input().split()))
C = collections.Counter(A)
use = []
for i,val in C.items():
  if val >= 4:
    use.append(i)
  if val >= 2:
    use.append(i)

use = sorted(use,reverse= True)
if len(use)<2:
  print(0)
else:
  print(use[0]*use[1])

Solution (Python):
N = int(input())
import collections
A = list(map(int,input().split()))
C = collections.Counter(A)
use = [0,0]
for i,val in C.items():
  if val >= 4:
    use.append(i)
  if val >= 2:
    use.append(i)

use.sort(reverse=True)
 
print(use[0] * use[1])

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 collections
def main():

    n = int(input())
    a = list(map(int,input().split()))
    cnt = collections.Counter(a)
    set_a = set(a)
    a = []
    a = list(set_a)
    a.sort(reverse=True)
    select = 0
    ans = 1
    tmp = 0
    flg = 0
    for i, aa in enumerate(a):
        if cnt[aa] >= 4 and flg == 0:
            tmp = aa * aa
            flg = 1
        if cnt[aa] >= 2:
            select += 1
            ans *= aa
        if select == 2:
            ans = max(tmp,ans)
            print(ans)
            return
    print(0)



if __name__ == '__main__':
    main()

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

f,t=[],[]
for k in a:
    if a[k]>=4:
        f.append(k)
    if a[k]>=2:
        t.append(k)


ans1=0
for ff in f:
    ans1=max(ans1,ff**2)
ans2=0
t.sort(reverse=True)
if len(t)>=2:
    ans2=t[0]*t[1]
print(max(ans1,ans2))

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

ans = []
s = A[0]
n = 1
for i in range(1, N):
  if len(ans) == 2: break
  if A[i] == s:
    n += 1
    if n == 2 or n == 4:
      ans.append(s)
  else:
    s = A[i]
    n = 1
print(ans[0] * ans[1] if len(ans) != 0 else 0)

Solution (Python):
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
ac = sorted([(i, v) for i, v in Counter(A).items() if v >= 2], reverse=True)
s = []
for k, v in ac:
  for _ in range(v//2):
    s.append(k)
  if len(s) >= 2:
    break
if len(s) >= 2:
  print(s[0]*s[1])
else:
  print(0)

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

edge1 = 0
edge2 = 0
start = 0

prev = A[start]
for i in range(start + 1, N):
    if A[i] == prev:
        edge1 = prev
        start = i + 1
        break
    prev = A[i]

prev = A[start]
for i in range(start + 1, N):
    if A[i] == prev:
        edge2 = prev
        break
    prev = A[i]

print(str(edge1 * edge2))

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
scount=1
flg=0
ans=1
for i in range(1,N):
    if A[i]==A[i-1]:
        scount+=1
        if i==N-1 and scount>=2 and flg==1:
            flg=2
            ans*=A[i-1]
        if i==N-1 and scount>=4 and flg==0:
            flg=2
            ans=A[i-1]**2
    else:
        if scount>=4 and flg==0:
            flg=2
            ans=A[i-1]**2
            break
        elif scount>=2:
            if flg==0:
                flg=1
                ans*=A[i-1]
            elif flg==1:
                flg=2
                ans*=A[i-1]
                break
        scount=1

print(ans if flg==2 else 0)

Solution (Python):
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
A = sorted(A, reverse=True)
d = defaultdict(int)
for i in range(N):
  d[A[i]] += 1
d = sorted(d.items(), key=lambda x:x[1], reverse=True)
d = sorted(d, key=lambda x:x[0], reverse=True)
a = []
for key, val in d:
  if 2 <= val <= 3:
    a.append(key)
  elif val >= 4:
    a.append(key)
    a.append(key)
  if len(a) >= 2:
    print(a[0]*a[1])
    exit()
if len(a) < 2:
  print(0)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a = Counter(a).most_common()
b = []
for i,j in a:
    if j >=4:
        b.append(i)
        b.append(i)
    elif j >= 2:
        b.append(i)
b.sort()
if len(b)>=2:
    print(b[-1]*b[-2])
else:
    print(0)

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

A = sorted(A)[::-1]
a = []
ng = 9999999
for i in range(N-1):
    if i != ng:
        if A[i] == A[i+1]:
            a.append(A[i])
            ng = i+1
            if len(a) == 2:
                break

ans = 0
if len(a) == 2:
    ans = a[0] * a[1]
else:
    ans = 0

print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

c = Counter(A)
c = sorted(c.items(), key=lambda x:x[0], reverse=True)
d = []
for a in c:
    
    if a[1] >= 2:
        d.append(a)

d = sorted(d, key=lambda x:x[0], reverse=True)
squ = 0
for y in d:
    
    if y[1] >= 4:
        squ = (y[0] ** 2)
    
    break
ans = squ

if len(d) >= 2:
    
    

    ans = (max(d[0][0] * d[1][0], ans))


print(ans)

Solution (Python):
def solve():
    N = int(input())
    A = [int(a) for a in input().split()]
    A.sort()

    Adict = dict()
    for i, a in enumerate(A):
        if a in Adict: Adict[a] += 1
        else: Adict[a] = 1

    rect = 0
    ri = -1
    for i in reversed(range(N)):
        if Adict[A[i]] >= 4:
            rect = A[i] ** 2
            break
        if Adict[A[i]] >= 2:
            rect = A[i]
            ri = i
            break
    if ri > -1:
        for i in reversed(range(ri)):
            if Adict[A[i]] >= 2 and A[i] != rect:
                rect *= A[i]
                break
    print(rect)

if __name__ == "__main__":
    solve()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
bar = dict()
for i in range(n):
    if a[i] not in bar:
        bar[a[i]] = 0
    bar[a[i]] += 1
l_bar = list(bar.items())
l_bar.sort(reverse=True)
cnt = 0
hen1 = 0
hen2 = 0
for i in range(len(l_bar)):
    if l_bar[i][1] >= 4 and cnt == 0:
        print(l_bar[i][0]**2)
        exit()
    if l_bar[i][1] >= 2:
        if cnt == 0:
            cnt += 1
            hen1 = l_bar[i][0]
        elif cnt == 1:
            cnt += 1
            hen2 = l_bar[i][0]
    if cnt == 2:
        print(hen1*hen2)
        exit()
print(0)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
C = Counter(A)
T = []
F = []
for e in C:
    if C[e] >= 4:
        F.append(e)
    if C[e] >= 2:
        T.append(e)
ans = 0
for e in F:
    ans = max(ans,e**2)
T = sorted(T)
if len(T) >= 2:
    ans = max(ans,T[-1]*T[-2])
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
from collections import Counter
C = Counter(A)
e = []
for k,v in C.items():
    if v >= 2: e.append(k)
    if v >= 4: e.append(k)
e.sort(reverse=True)
if len(e) >= 2:
    print(e[0]*e[1])
else:
    print(0)

Solution (Python):

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


a = sorted(a, reverse = True)
for i in range(n - 1):
    if a[i] == a[i + 1]:
        ans1 = a[i]
        tmp1 = i + 1
        break
    if i == n - 2:
        ans1 = 0
if ans1 == 0:
    print(0)
    exit()
for i in range(tmp1+1, n-1):
    if a[i] == a[i + 1]:
        ans2 = a[i]
        break
    if i == n - 2:
        ans2 = 0
print(ans1 * ans2)

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    most = c.most_common()
    if most[0][1] >= 4:
        ans = []
        for k, v in most:
            if v >= 4:
                ans.append(k)
                ans.append(k)
            elif v >= 2:
                ans.append(k)
        ans.sort()
        print(ans[-1]*ans[-2])
    elif most[0][1] >= 2 and most[1][1] >= 2:
        ans = []
        for k, v in most:
            if v >= 2:
                ans.append(k)
        ans.sort()
        print(ans[-1]*ans[-2])
    else:
        print(0)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

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

cntA = Counter(A)
B = []
for a, c in cntA.items():
    if c // 2 == 0:
        continue
    for _ in range(c // 2):
        B.append(a)

B.sort(reverse=True)
ans = B[0] * B[1] if len(B) >= 2 else 0

print(ans)

Solution (Python):
n = int(input())
A =list(map(int, input().split()))
d = {}
for i in range(n):
    if A[i] not in d:
        d[A[i]] = 1
    else:
        d[A[i]] += 1
ans = 0
l = []
for k, v in d.items():
    if v >= 4:
        ans = max(ans, k**2)
        l.append(k)
    elif v >= 2:
        l.append(k)
    else:
        continue
if len(l) <= 1:
    print(ans)
else:
    l.sort(reverse=True)
    ans = max(ans, l[0]*l[1])
    print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
a.sort(reverse=True)
b = list(set(a))
b.sort(reverse=True)
c = [1 for _ in range(len(b))]
j = 0
for i in range(n - 1):
    if a[i] == a[i + 1]:
        c[j] += 1
    else:
        j += 1
ans = []
for i in range(len(b)):
    if c[i] >= 2:
        ans.append(b[i])
    if c[i] >= 4:
        ans.append(b[i])
if len(ans) >= 2:
    print(ans[0] * ans[1])
else:
    print(0)

Solution (Python):


N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))


count_A_dic={}
for size in A_list:
    count_A_dic.setdefault(size,0)
    count_A_dic[size] += 1

length = sorted(set(A_list),reverse=True)

side=[]
for l in length:
    if count_A_dic[l] >= 4 and len(side) == 0:
        side = [l,l]
        break

    elif count_A_dic[l] >= 2 and len(side) < 2:
        side.append(l)
    
    if len(side) == 2:
        break

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

Solution (Python):
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = sorted([(k,v) for k,v in C.items() if v>=2], key = lambda x:-x[0])[:2]

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

Solution (Python):
from collections import Counter

n = int(input())
a = list(map(int,input().split()))
a_count = sorted(Counter(a).items(),reverse=True)
f = False

for k,v in a_count:
    if (4 <= v) and (not f):
        print (k**2)
        exit ()
    elif 2 <= v:
        if f:
            print (x*k)
            exit ()
        else:
            x = k
            f = True
    else:
        pass

print (0)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
tate = 0
yoko = 0
now = 0

for i in a:
    if tate == 0:
        if now == i:
            tate = now
            now = 0
            continue
    else:
        if now == i:
            yoko = now
            break
    now = i

print(tate * yoko)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
import collections
c =collections.Counter(a)
ln = [i[0] for i in c.items() if i[1] >= 2]
ln.sort(reverse = True)
if len(ln) < 1:
    print(0)
elif c[ln[0]] >= 4:
    print(ln[0] ** 2)
elif len(ln) <= 1:
    print(0)
else:
    print(ln[0] * ln[1])

Solution (Python):
import collections
N=int(input())
A=list(map(int,input().split()))
l=[]
c=collections.Counter(A)
a=[]
values=list(c.values())
key=list(c.keys())
b=[]
for i in range(len(key)):
    l.append([key[i],values[i]])
l.sort(key=lambda x:x[1],reverse=True)
for i in range(len(l)):
    if l[i][1]>=2:
        num=l[i][0]
        b=[num]*((l[i][1])//2)
        a.extend(b)
if len(a)<2:
    print("0")
else:
    a.sort(reverse=True)
    print(a[0]*a[1])

Solution (Python):
from collections import Counter

n=int(input())
a=Counter(list(map(int,input().split())))
x=[0,0]
for i in a.keys():
    if a[i]>1:
        x.append(i)
    if a[i]>3:
        x.append(i)
x.sort()
print(x[-1]*x[-2])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
bars = [0,0]
for i in range(n-1):
  if a[i + 1] == a[i]:
    bars.pop(0)
    bars.append(a[i])
    a[i+1] = 0
print(bars[0]*bars[1])

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

Solution (Python):
def main():
  n = int(input())
  a = list(input_list())
  ac = collections.Counter(sorted(a))
  aa = []
  hw = []
  for v, count in ac.items():
    if count >= 2:
      aa.append(v)
    if count >= 4:
      hw.append(v)
      
  sa = sorted(aa, reverse=True)
  shw = sorted(hw, reverse=True)
  if len(shw) > 0:
    if len(sa) < 2:
      print(shw[0]*shw[0])
    else:
      print(max(shw[0]*shw[0], sa[0]*sa[1]))
    exit()
  
  if len(sa) < 2:
    print(0)
    exit()
  
  print(sa[0]*sa[1])
    
    
  
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c 

import math
import fractions
import collections
from functools import reduce
main()

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]

from collections import Counter

d=Counter(a)
d=d.most_common()
ans = [i for i,j in d if j>=2]
ans2 = [i for i,j in d if j>=4]

if len(ans) <2:
    a1=0
else:
    ans.sort()
    a1 = ans[-1]*ans[-2]
    
if len(ans2)<1:
    a2=0
else:
    ans2.sort()
    a2=ans2[-1]**2
print(max(a1,a2))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
a.append(0)
cnt=1
l1,l2=0,0
for i in range(n):
    if a[i]==a[i+1]:
        cnt+=1
    else:
        if cnt>=4:
            if l1==0:
                l1=a[i]
                l2=a[i]
                break
            else:
                l2=a[i]
                break
        elif cnt>=2:
            if l1==0:
                l1=a[i]
                cnt=1
            else:
                l2=a[i]
                break
print(l1*l2)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
l.sort()
a=[]
tmp=l.pop(-1)
while len(a)<2 and len(l)>0:
  if tmp==l[-1]:
    a.append(tmp)
    l.pop(-1)
    if len(l)==0:
      break
    tmp=l.pop(-1)
  else:
    tmp=l.pop(-1)
if len(a)<2:
  print(0)
else:
  print(a[-1]*a[-2])

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = {}
for a in A:
    if a not in B:
        B[a] = 0
    B[a] += 1


C = [(b, B[b]) for b in B]
C.sort(reverse=True, key=lambda x: x[0])


ans = []
for c in C:
    if len(ans) == 0 and c[1] >= 4:
        print(c[0]**2)
        exit()
    if c[1] >= 2:
        ans.append(c)
    if len(ans) >= 2:
        print(ans[0][0] * ans[1][0])
        exit()
print(0)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
c = Counter(A)
a, b = 0, 0
for key in sorted(c.keys(), reverse=True):
  if c[key] >= 4:
    a = max(a, key)
    b = max(b, key)
  elif c[key] >= 2:
    if a == 0:
      a = key
    elif a != 0 and b == 0:
      b = key
print(a*b)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A = sorted(A,reverse=True)
a, b, i = 0, 0, 0
while i < N-1:
  if A[i] == A[i+1]:
    if a == 0 and b == 0:
      a = max(a, A[i])
      i += 2
    elif a != 0 and b == 0:
      b = max(b, A[i])
      i += 2
    else:
      i += 1
  else:
    i += 1
print(a*b)

Solution (Python):
n = int(input())
dat = list(map(int, input().split()))
import collections
c = collections.Counter(dat)
data = []
for k in c:
    cnt = c[k]
    if cnt > 1:
        data.append((k, cnt//2))
data.sort(reverse=True)

if len(data) == 0:
    print(0)
else:
    a = data[0]
    x =a[0]
    if a[1] > 1:
        y = a[0]
        print(x*y)
    elif len(data) > 1:
        y = data[1][0]
        print(x*y)
    else:
        print(0)

Solution (Python):
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines






def main():
	n=int(input())
	A=list(map(int,input().split()))
	A.sort(reverse=True)
	ans=0
	cnt=0
	li=[]
	for i in range(n-1):
		if A[i+1]==A[i]:
			cnt+=1
			if cnt==3:
				ans=A[i]**2
				break
			if cnt==1:
				li.append(A[i])
				if len(li)==2:
					ans=li[0]*li[1]
					break
		else:
			cnt=0
	print(ans)
	
	

if __name__ == "__main__":
	main()

Solution (Python):
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines





from collections import defaultdict

def main():
	d=defaultdict(int)
	
	n=int(input())
	A=list(map(int,input().split()))
	for x in A:
		d[x]+=1
	
	li=[]
	li2=[]
	for k,v in d.items():
		if v>=2:
			li.append(k)
		if v>=4:
			li2.append(k)

	li.sort(reverse=True)
	li2.sort(reverse=True)
	
	if len(li)<=1 and len(li2)==0:
		print(0)
	elif len(li)>=2 and len(li2)>=1:
		print(max(li[0]*li[1],li2[0]**2))
	elif len(li)>=2:
		print(li[0] * li[1])
	else:
		print(li2[0]**2)
	

if __name__ == "__main__":
	main()