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 = [int(i) for i in input().split()]
a.sort(reverse=True)
b = list(set(a))
b.sort(reverse=True)
l = len(b)
c = [0 for _ in range(l)]
prei = b[0]
j = 0
for i in a:
    if i != prei:
        j += 1
    c[j] += 1
    prei = i
x = []
for i in range(l):
    if c[i] >= 2:
        x.append(b[i])
    if c[i] >= 4:
        x.append(b[i])
if len(x) >= 2:
    ans = x[0] * x[1]
    print(ans)
else:
    print(0)

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

a.sort()

tmp_val = 0
pair_val = 0
for i in range(n-1, -1, -1):
  if tmp_val == a[i]:
    if pair_val != 0:
      print(pair_val * a[i])
      exit()
    else:
      pair_val = a[i]
      tmp_val = 0
  else:
    tmp_val = a[i]

print(0)

Solution (Python):
from collections import Counter
n = int(input())
ctr = Counter(list(map(int, input().split())))
side = []
for k in sorted(ctr.keys(), reverse=True):
    if ctr[k] >= 4:
        side.append(k)
        side.append(k)
    elif ctr[k] >= 2:
        side.append(k)
print(side[0] * side[1] if len(side) >= 2 else 0)

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
A.sort()
cnt={}
K=list(set(A))
K.sort()
for k in K:
  cnt[k]=0
for a in A:
  cnt[a]+=1
E=[]
for k in K:
  if cnt[k]>=2:
    if cnt[k]>4:
      E.append(k)
    E.append(k)
E.sort()

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

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
A.sort()
cnt={}
K=list(set(A))
K.sort()
for k in K:
  cnt[k]=0
for a in A:
  cnt[a]+=1
E=[]
for k in K:
  if cnt[k]>=2:
    if cnt[k]>=4:
      E.append(k)
    E.append(k)
E.sort()

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

Solution (Python):
from collections import Counter

N=int(input())
L=list(map(int,input().split()))
Z=[]
M=Counter(L)
for i,j in M.items():
	if j>=2:
		Z.append(i)
	if j>=4:
		Z.append(i)
V=sorted(Z)
if len(V)<2:
	print(0)
else:
	print(V[-1]*V[-2])

Solution (Python):
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)

Solution (Python):

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

list.sort(a, reverse = True)


i = 0
tmp = []
while True:
    if a[i] == a[i + 1]:
        tmp.append(a[i])
        if i != n - 1:
            i += 2
        if i == n - 1:
            break
    else:
        i += 1
    if i == n - 2:
        break
if a[n-2] == a[n-1]:
    tmp.append(a[n-2])

list.sort(tmp, reverse = True)


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

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
b = list(set(a))
b.sort(reverse=True)
l = len(b)
c = [0 for _ in range(l)]
prei = b[0]
j = 0
for i in a:
    if i != prei:
        j += 1
    c[j] += 1
    prei = i
x = []
for i in range(l):
    if c[i] >= 2:
        x.append(b[i])
if len(x) >= 2:
    ans = x[0] * x[1]
    for i in range(len(x)):
        if c[i] >= 4:
            ans  = max(ans, x[i] ** 2)
    print(ans)
else:
    print(0)

Solution (Python):
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, groupby
from math import floor, ceil, sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
from itertools import product
import sys
stdin = sys.stdin
mod = 10**9 + 7


def ns(): return stdin.readline().rstrip()


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


n = ni()
a = na()

a.sort(reverse=True)
l = list()
for key, gr in groupby(a):
    if len(l) == 2:
        break
    num = len(list(gr))
    if num >= 2:
        l.append(key)
    if num >= 4:
        l.append(key)
print(l[0] * l[1] if len(l) >= 2 else 0)

Solution (Python):
import sys

def solve():
    N = int(input())
    A = [int(a) for a in input().split()]
    lengthD = dict()
    for a in A:
        if a in lengthD: lengthD[a] += 1
        else: lengthD[a] = 1
    moreThanTwo = []
    count = 0
    for key in lengthD:
        if lengthD[key] > 1: 
            moreThanTwo.append(key)
            count += 1
    
    if count == 0: print(0)
    else:
        ans = 0
        moreThanTwo.sort()
        if lengthD[moreThanTwo[-1]] > 3: ans = moreThanTwo[-1] ** 2
        if count < 2: print(ans)
        else:
            ans = max(ans, moreThanTwo[-1] * moreThanTwo[-2])
            print(ans)

    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]

from collections import Counter

Acnt = Counter(A)

ans = [-1] * 2
for key,cnt in Acnt.items():
    if cnt >= 4:
        if key > ans[0]:
            ans[0] = key
        if key > ans[1]:
            ans[1] = key
    elif cnt >= 2:
        if key > ans[0]:
            ans[0] = key
    
    ans.sort()

if -1 in ans:
    print(0)
else:
    print(ans[0] * ans[1])

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
ans = []
for k in sorted(cnt.keys(), reverse=True):
    if len(ans) == 2:
        break
    if cnt[k] >= 4:
        ans.append(k)
        ans.append(k)
    elif cnt[k] >= 2:
        ans.append(k)
if len(ans) < 2:
    print(0)
else:
    print(ans[0] * ans[1])

Solution (Python):
N, = map(int, input().split())
X = map(int, input().split())
from collections import defaultdict
d = defaultdict(int)
ccs = []
ccs2 = []
for x in X:
    d[x] += 1
    if d[x] == 2:
        ccs.append(x)
ccs.sort()
if len(ccs) > 1:
    r =ccs[-1]*ccs[-2]
    if d[ccs[-1]] >= 4:
        print(ccs[-1]**2)
    else:
        print(r)
else:
    print(0)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a.sort()
num=a[0]
fin=0
res=[]
i=1
while i<n:
    
    if a[i-1]==a[i]:
        res.append(a[i])
        i+=2
    else:
        i+=1

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

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

cnt=Counter(a)

cand=[]
for k,v in cnt.items():
    if 2<=v<4:
        cand.append([k,2])
    elif 4<=v:
        cand.append([k,2])
        cand.append([k,2])
cand=sorted(cand,reverse=True)
print(cand[0][0]*cand[1][0] if len(cand)>=2 else 0)

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


L = []
for k, v in d.items():
    if v >= 2:
        L.append([k, v])
L.sort(reverse=True)
if len(L) == 0:
    print(0)
elif len(L) == 1:
    if L[0][1] < 4:
        print(0)
    else:
        print((L[0][0])**2)
else:
    if L[0][1] >= 4:
        print((L[0][0])**2)
    else:
        print(L[0][0]*L[1][0])

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    if (c.most_common()[0][1] < 2 or c.most_common()[1][1] < 2) \
            and c.most_common()[0][1] < 4:
        return print(0)
    d = [i[0] for i in c.items() if i[1] >= 2]
    if d:
        d.sort()
    e = [i[0] for i in c.items() if i[1] >= 4]
    if e:
        e.sort()
    if d and e:
        print(max(d[-1] * d[-2], e[-1]*e[-1]))
    elif d:
        print(d[-1] * d[-2])
    else:
        print(e[-1]*e[-1])


if __name__ == '__main__':
    main()

Solution (Python):
n, *a = map(int, open(0).read().split())
a.sort()

b = []
prev = cnt = 0
for i in range(n):
        if prev==a[i]: cnt+=1
        else:
                if cnt>1: b.append([prev, cnt])
                cnt = 1
        prev = a[i]
if cnt>1: b.append([prev, cnt])

h, w = 0, 0
for i, cnt in b:
        if cnt>3: h, w = i, i
        else: h, w = max(h, w), i
print(h*w)

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

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

e = -1
for k,v in sorted(ctr.items(), reverse=True):
    if v < 2: continue
    if e > 0:
        print(e*k)
        exit()
    elif v >= 4:
        print(k*k)
        exit()
    else:
        e = k
print(0)

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

N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
l = []
ans = 0

for k in cnt.keys():
    if cnt[k]>=4:
        ans = max(ans, k*k)
    
    if cnt[k]>=2:
        l.append(k)

l.sort(reverse=True)

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

print(ans)

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

A.sort(reverse=True)
a = 0
b = 0
i = 1
while i < N:
    if A[i] == A[i-1] and a == 0:
        a = A[i]
        i += 2
    elif A[i] == A[i-1] and b == 0:
        b = A[i]
        i += 2
    else:
        i += 1

print(a*b)

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

Solution (Python):
from collections import Counter

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

c = Counter(A)
hen = [key for key, val in c.items() if val > 1]

l = max(hen) if hen else 0
if l != 0:
    if c[l] > 3:
        s = l
    else:
        hen.remove(l)
        s = max(hen) if hen else 0
else:
    s = 0

print(l * s)

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

Solution (Python):
import collections

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


c = collections.Counter(A)

z = []
for k, v in c.items():
    if v >= 4:
        z.append(k)
    if v >= 2:
        z.append(k)

if len(z) < 2:
    print(0)
    exit()

x = max(z)
del z[z.index(x)]
y = max(z)

print(x*y)

Solution (Python):
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))
    pair = [0, 0]
    dic = defaultdict(int)

    for a in A:
        if dic[a]:
            pair.append(a)
            dic[a] = 0
        else:
            dic[a] = 1

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


if __name__ == '__main__':
    main()

Solution (Python):
def examC():
    N = I()
    A = LI()
    d = defaultdict(int)
    for a in A:
        d[a] += 1
    a = [0,0]
    for key,i in d.items():
        if i>=4:
            if a[1]<key:
                a = [key,key]
            elif a[0]<key:
                a = [key,a[1]]
        elif i>=2:
            if a[1]<key:
                a = [a[1],key]
            elif a[0]<key:
                a = [key,a[1]]
    ans = a[0]*a[1]
    print(ans)
    return

def examD():

    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

"""

"""

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 heapq
import sys

N = int(input())
A = [-x for x in map(int, input().split())]
heapq.heapify(A)

while len(A) > 3:
    l1 = -heapq.heappop(A)
    l2 = -heapq.heappop(A)
    if l1 == l2:
        while len(A) > 1:
            s1 = -heapq.heappop(A)
            s2 = -heapq.heappop(A)
            
            if s1 == s2:
                print(l1 * s1)
                sys.exit()
            else:
                heapq.heappush(A, -s2)
                

    else:
        if A:
            heapq.heappush(A, -l2)
print(0)

Solution (Python):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
X = Counter()
for i in range(0, N):
    X[A[i]] += 1
width = 0
height = 0
for x, y in sorted(X.most_common(), reverse=True):
    if y >= 2:
        if y >= 4:
            width = max(width, x)
            height = max(height, x)
            break
        if width != 0:
            height = x
            break
        else:
            width = x
print(height*width)

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

lengths = []
for i in range(len(A) - 1):
    try:
        if A[i] == A[i+3] and len(lengths) == 0:
            lengths.append(A[i])
            lengths.append(A[i])
            break
    except:
        pass

    if (A[i] not in lengths) and (A[i] == A[i+1]):
        lengths.append(A[i])

    if len(lengths) == 2:
        break

try:
    ans = lengths[0] * lengths[1]
except:
    ans = 0

print(ans)

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

c = collections.Counter(a).most_common()
c.sort()
c.reverse()
first=0
second=0

for tmp in c:
        if tmp[1] >=4 and first==0 and second==0:
                first=tmp[0]
                second=tmp[0]
                break
        if tmp[1] >=2:
                if first==0:
                        first=tmp[0]
                else:
                        second=tmp[0]
                        break
print(first*second)

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

edge = []

for i in range(1,N):
  if A[i] == A[i - 1] and A[i] not in edge:
    edge.append(A[i])
  elif A[i] == A[i - 3]:
    edge.append(A[i])
  
  if len(edge) == 2:
    break
    
if len(edge) <= 1:
  print(0)
else:
  print(edge[0] * edge[1])

Solution (Python):
from collections import Counter
N = int(input())
Ac = Counter(list(map(int, input().split())))
over2 = [ele for ele in Ac.items() if ele[1]>=2]
if len(over2) == 0:
  print(0)
elif len(over2) == 1:
  if over2[0][1] >= 4:
    print(over2[0][0]**2)
else:
  over2.sort(reverse=True)
  if over2[0][1] >= 4:
    print(over2[0][0]**2)
  else:
    print(over2[0][0]*over2[1][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 sys
import math
import os
import itertools
import string
import heapq
from _collections import defaultdict
from functools import lru_cache

class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def map_int():
        return [int(x) for x in Scanner.string().split()]
    def string_list(n):
        return [input() for i in range(n)]
    def int_list_list(n):
        return [Scanner.mapInt() for i in range(n)]
    def int_cols_list(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True

MOD = int(1e09) + 7

def main():
    N = Scanner.int()
    A = Scanner.map_int()
    A.sort(reverse = True)
    h,w = 0,0
    i = 0
    while i < N - 1:
        if A[i] == A[i + 1]:
            if h == 0:
                h = A[i]
                i +=1
            else:
                w = A[i]
                break
        i += 1
    print(h * w)
    return

if __name__ == "__main__":
    main()

Solution (Python):

from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left
from collections import Counter
INF = float('inf')


N=int(input())
An=sorted(list(map(int, input().split())))

C = Counter(An)

C = [(k ,v) for k, v in C.items() if v > 1]
if len(C) < 2:
    print(0)
else:
    C = sorted(C, key=lambda x:x[0])
    
    if C[-1][1] >= 4:
        print(C[-1][0] ** 2)
    else:
        print(C[-1][0]*C[-2][0])

Solution (Python):
import collections

N = int(input())
A = map(int, input().split())
A_count = dict(collections.Counter(A))
A_countsort = sorted(A_count, reverse=True)

hen_list = []
for key in A_countsort:
    if A_count[key] >= 4:
        hen_list.append(key)
        hen_list.append(key)
    elif A_count[key] >= 2:
        hen_list.append(key)

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

Solution (Python):
from collections import Counter
N, *A = map(int, open(0).read().split())
C = Counter(A)
C = [(k,v) for k,v in C.items() if v > 1]
if len(C) < 2:
  print(0)
else:
  C = sorted(C, key=lambda x:x[0])
  if C[-1][1] >= 4:
    print(C[-1][0]**2)
  else:
    print(C[-1][0]*C[-2][0])

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

Solution (Python):
n=int(input())
a=map(int,input().split())
a=sorted(a)
a=list(reversed(a))
h,w=0,0
tmp=0
f=0
for x in a:
    if tmp==x:
        if w!=0:
            h=x
            break
        else:
            w=x
            tmp=0
            continue
    tmp=x
print(w*h)

Solution (Python):

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

    n = int(input())

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

    b = []
    heapq.heapify(b)
    ln = 0
    cou = 0
    for i in a:
        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()

Solution (Python):

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)
        
        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()

Solution (Python):

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)
        
        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()

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
Ac = Counter(A)
flag = False
a = 0
b = 0
ac2 = sorted(Ac.items(),reverse=True)
for k,v in ac2:
    if v < 2:
        continue
    elif v >= 4:
        if flag:
            b = k
            break
        else:
            a = k
            b = k
            break
    else:
        if flag:
            b = k
            break
        else:
            a = k
            flag = True
print(a*b)

Solution (Python):
import collections

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

c = collections.Counter(ls)

ls_s = c.most_common()
ls_s.sort(reverse=True)

mul = []

for i in range(len(ls_s)):
    if ls_s[i][1] >= 4:
        if len(mul) == 0:
            print(ls_s[i][0] ** 2)
            break
        elif len(mul) == 1:
            print(ls_s[i][0] * mul[0])
            break
    elif ls_s[i][1] >= 2:
        mul.append(ls_s[i][0])
    
    if len(mul) >= 2:
        print(mul[0] * mul[1])
        break
    elif i == len(ls_s) - 1:
        print(0)

Solution (Python):
import sys
from collections import Counter
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(a_ls)
flg = False
new_ct = []
for i, j in sorted(ct.items(), key=lambda x:x[0], reverse=True):
    if j >= 4:
        flg = True
    if j > 1:
        new_ct.append((i, j))
if len(new_ct) == 0:
    print(0)
elif len(new_ct) == 1 and not flg:
    print(0)
else:
    if new_ct[0][1] >= 4:
        print(new_ct[0][0] ** 2)
    else:
        print(new_ct[0][0] * new_ct[1][0])

Solution (Python):
from collections import Counter
N=int(input())
A=Counter(sorted(list(map(int,input().split()))))
A=[[i,A[i]] for i in A if A[i]>=2]
A.sort(reverse=True)
try:
    if A[0][1]>=4:
        print(A[0][0]**2)
    else:
        print(A[0][0]*A[1][0])
except:
    print(0)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
aset = set()
a2set = set()
a3set = set()
a4set = set()
for i in a:
    if i in a3set:
        a4set.add(i)
    if i in a2set:
        a3set.add(i)
    if i in aset:
        a2set.add(i)
    aset.add(i)
if len(a2set) < 2 and len(a4set) == 0:
    ans = 0
else:
    x = max(a2set)
    if x in a4set:
        ans = x ** 2
    else:
        a2set.remove(x)
        y = max(a2set)
        ans = x * y
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Ans = []
d = 0
cnt = 0
while cnt < 2:
  c = (A[d:d+4]).count(A[d])
  for j in range(c//2):
    Ans.append(A[d])
  cnt += c//2
  d += c
  if d == N:
    Ans.append(0)
    Ans.append(0)
    cnt +=2
print(Ans[0]*Ans[1])

Solution (Python):
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
A = Counter(A).most_common()
A = sorted(A)[::-1]
cnt = 0
l = []
ans = [0]
for i, v in A:
  if v >= 4:
    ans.append(i*i)
  if 2<=v:
    cnt += 1
    l.append(i)
    if cnt == 2:
      ans.append(l[0]*l[1])
print(max(ans))

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

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

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

two = sorted(two)
four = sorted(four)
ans = []
if four != []:
    ans.append(four[-1]**2)
if len(two) >= 2:
    ans.append(two[-1]*two[-2])

if ans == []:
    print(0)
else:
    print(max(ans))

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

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

Solution (Python):

import collections
n=int(input())
lists=list(map(int,input().split()))
A=dict(collections.Counter(lists))
dictdict=[]


for j in A.keys():
    for _ in range(A[j]//2):
        dictdict.append(j)

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

Solution (Python):
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    a = collections.Counter(a)
    c = 0
    t = 0
    for k, v in sorted(a.items(), reverse=True):
        if v >= 4:
            print(k * k if c == 0 else t * k)
            exit()
        elif v >= 2:
            if c != 0:
                print(t * k)
                exit()
            else:
                t += k
                c += 1
    print(0)


if __name__ == '__main__':
    solve()

Solution (Python):
N = int(input())

A = [int(x) for x in input().split()]

d = {}
for i in range(N):
    if A[i] not in d:
        d[A[i]] = 0
    d[A[i]] += 1


ans = {0}
s1 = [k for k, v in d.items() if v >= 4]
if len(s1) > 0:
    s1.sort()
    ans.add(s1[-1] ** 2)

s2 = [k for k, v in d.items() if v >= 2]
if len(s2) >= 2:
    s2.sort()
    ans.add(s2[-1] * s2[-2])

print(max(ans))

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

import collections

c = collections.Counter(a)
cs = sorted(c.items(), key=lambda x:x[0],reverse=True)
a=[0,0]
f=0
sq=0
for i in cs:
    if sq == 0 and i[1] >= 4:
        sq=i[0]**2
    if i[1] >= 2:
        a[f]=i[0]
        f+=1
    if f >= 2:
        break
print(max(sq,a[0]*a[1]))

Solution (Python):
from collections import Counter

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

a = list(Counter(A).items())
b = []

for i in range(len(a)):
    if a[i][1] >= 4:
        b.append(a[i][0])
        b.append(a[i][0])
    elif a[i][1] >= 2:
        b.append(a[i][0])

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

Solution (Python):
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
ans=1
cnt=0
i=0
while i<n-1 and cnt<2:
    if a[i]==a[i+1]:
        ans*=a[i]
        i+=2
        cnt+=1
    else:
        i+=1
if cnt==2:
    print(ans)
else:
    print(0)

Solution (Python):
import collections
n=int(input())
a=list(map(int,input().split()))
a.sort()
a=a[::-1]
c=collections.Counter(a)
d=list(c.keys())
d.sort()
d=d[::-1]
z=0
ans=1
for i in d:
    if c[i]>=4:
        if z==0:
            print(i**2)
            break
        elif z==2:
            ans*=i
            print(ans)
            break
    elif 2<=c[i]<=3:
        if z==0:
            z+=2
            ans*=i
            continue
        elif z==2:
            ans*=i
            print(ans)
            break
else:
    print(0)

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

f = 0
x = 0
for i in range(len(a)-1):
    if a[i] == a[i+1] != x:
        f += 1
    if f == 1:
        x = a[i]
        f += 1
        if a.count(x) >= 4:
          f = 3
    if f >= 3:
        print(x*a[i])
        exit()
print(0)

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

A.sort(reverse = True)
one = 0
two = 0
idx = 1
while idx < N:
  if A[idx-1]==A[idx]:
    one = A[idx]
    break
  idx += 1
idx += 2
while idx < N:
  if A[idx-1]==A[idx]:
    two =A[idx]
    break
  idx += 1
print(one*two)

Solution (Python):
import heapq
N = int(input())
A = list(map(int, input().split()))
hq = []
for i in range(N):
    heapq.heappush(hq, -A[i])
X, x1, x2, Y, y1, y2= 0, 0, 0, 0, 0, 0
x1 = -heapq.heappop(hq)
while hq:
    x2 = -heapq.heappop(hq)
    if x1 == x2:
        X = x1
        break
    else:
        x1 = x2
if len(hq) != 0:
    y1 = -heapq.heappop(hq)
    while hq:
        y2 = -heapq.heappop(hq)
        if y1 == y2:
            Y = y1
            break
        else:
            y1 = y2
print(X*Y)

Solution (Python):
from collections import defaultdict

n = int(input())
A = list(map(int, input().split()))
d = defaultdict(int)
l = []
for key in A:
  d[key] += 1
  if d[key] == 2:
    l.append(key)
    d[key] = 0
if len(l) < 2:
  print(0)
else:
  l.sort(reverse=True)
  print(l[0]*l[1])

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

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

Dict={}
for i in A:
    if(Dict.get(i,None)==None):
        Dict[i]=1
    else:
        Dict[i]+=1

T=1
C=0
Dict = sorted(Dict.items(), key=lambda x:-x[0])
for i in Dict:
    if((i[1]>=2)&(C>=1)):
        T*=i[0]
        C+=1
        break
    if(i[1]>=4):
        T*=i[0]*i[0]
        C=2
        break
    if(i[1]>=2):
        T*=i[0]
        C+=1

if(C==2):
    print(T)
else:
    print("0")

Solution (Python):
import sys
import heapq
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N = int(input())
    s = set()
    q = [0, 0]
    for a in map(int, input().split()):
        if a > q[0]:
            try:
                s.remove(a)
                heapq.heapreplace(q, a)
            except:
                s.add(a)
    print(q[0]*q[1])


if __name__ == '__main__':
    main()