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 = list(map(int,input().split()))
A.sort()
side = [0,0]
tmp = 0
for i in A:
    if i == tmp:
        side.append(i)
        tmp = 0
    else:
        tmp = i
print(side[-1]*side[-2])

Solution (Python):
from collections import Counter

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

E = [0, 0]
for k, v in Counter(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).most_common()
C.sort()
C.reverse()

e = []
for i, j in C:
    if j >= 2:
        e.append(i)
        if j >= 4:
            e.append(i)
    if len(e) >= 2:
        break
if len(e) >= 2:
    print(e[0] * e[1])
else:
    print(0)

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

w = 0
h = 0
for k in sorted(d.keys()):
    if d[k] >= 2:
        h = w
        w = k
    if d[k] >= 4:
        h = w

print(h*w)

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

d = {}
for a in A:
    if not(a in d.keys()):
        d[a] = 0
    d[a] += 1

e = [x for x in d.items() if x[1] >= 2]
if len(e) <= 1:
    print(0)
    exit()
e = sorted(e,key=lambda x:x[0],reverse=True)
if e[0][1] >= 4:
    print(e[0][0]**2)
else:
    print(e[0][0]*e[1][0])

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

C=list(B.items())
C.sort(reverse=True)


H=0
W=0
for i in range(len(C)):
    if H==0:
        if C[i][1]>=4:
            print(C[i][0]**2)
            exit()
        elif C[i][1]>=2:
            H=C[i][0]
    else:
        if C[i][1]>=2:
            print(H*C[i][0])
            exit()
print(0)

Solution (Python):
n = int(input())
li = [ int(it) for it in input().split()]
li.sort()

import collections
col = collections.Counter(li)
li2 = []
pai = []

mxk1=0
mxv1=0
mxk2=0
mxv2=0
for k,v in col.items():
  if (v>1):
    if (k>mxk1):
      mxk2=mxk1
      mxv2=mxv1
      mxk1=k
      mxv1=v
    elif (k>mxk2):
      mxk2=k
      mxv2=v

if (mxv1>3):
	print (mxk1*mxk1)
elif (mxv1>1 and mxv2>1):
  	print(mxk1*mxk2)
else:
	print(0)

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

A.sort()
now = 0
B = []
for i in range(N-1, -1, -1):
    if now == A[i]:
        B.append(A[i])
        now = A[i] + 1
    elif now != A[i]:
        now = A[i]
    if len(B) == 2:
        break

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

Solution (Python):
from collections import Counter
from functools import reduce
import bisect
import fractions
import math
import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]  
def LF(): return [float(x) for x in sys.stdin.readline().split()]  
def LS(): return sys.stdin.readline().split()  
def MI(): return map(int, sys.stdin.readline().split())  
def II(): return int(sys.stdin.readline())  
def IS(): return input()  
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):  
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):  
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


n, a = II(), LI()
counter = sorted(C(a).items(), key=lambda x: x[0], reverse=True)
for i in range(n):
    if 4 <= counter[i][1]:
        print(counter[i][0] ** 2)
        exit()
    elif 2 <= counter[i][1]:
        for j in range(i+1, n):
            if 2 <= counter[j][1]:
                print(counter[i][0] * counter[j][0])
                exit()
print(0)

Solution (Python):
n=int(input())
d=dict()
for i in map(int,input().split()):
  if i not in d:
    d[i]=1
  else:
    d[i]+=1
ans=[0,0]
for i in d.keys():
  for _ in range(d[i]//2):
    ans.append(i)
ans.sort(reverse=1)
print(ans[0]*ans[1])

Solution (Python):
import collections
import copy
def main():
    ct=collections.Counter
    N=int(input())
    A=[int(i) for i in input().split()]
    B=ct(A)
    anum=sorted(B,reverse=True)
    tate=0
    yoko=0
    for _ in range(2):
        for k,a in enumerate(anum):
            if B[a]>=2 and tate==0:
                tate=a
                break
            elif B[a]>=2 and tate:
                if a==tate and B[a]<4:continue;
                else:
                    yoko=a
                    break
    print(tate*yoko)
    
if __name__=="__main__":
    main()

Solution (Python):
import collections
import sys

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
two = [k for k, v in c.items() if v > 1]
four = [k for k, v in c.items() if v > 3]
if len(two) < 2 and not four:
    print(0)
    sys.exit(0)

St = 0
Sf = 0
if two:
    two.sort(reverse=True)
    St = 1
    for i in range(2):
        St *= two[i]
if four:
    Sf = max(four) ** 2
print(St if St > Sf else Sf)

Solution (Python):
import sys
from collections import Counter
from sys import stdin
N = int(stdin.readline().rstrip())
A = Counter([int(_) for _ in stdin.readline().rstrip().split()]).most_common()
B = [t for t in A if t[1] >= 2]
B.sort(reverse=True)
if len(B) < 2:
    print(0)
    sys.exit()
if B[0][1] >= 4:
    print(B[0][0]**2)
else:
    print(B[0][0]*B[1][0])

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=Counter(a)
an=[]
for b,count in c.items():
    for _ in range(count//2):
        an.append(b)
an.sort(reverse=True)
if len(an)<2:
    print(0)
else:
    print(an[0]*an[1])

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
c = Counter(A)
op = []
for a, cnt in c.items():
    for _ in range(cnt // 2):
        op.append(a)
op.sort(reverse=True)
if len(op) < 2:
    print(0)
else:
    print(op[0]*op[1])

Solution (Python):
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
a = nl()
c = collections.Counter(a)

key = list(c.keys())
key.sort(reverse=True)
count = 0
for i in range(len(key)):
    if c[key[i]] >= 4 and count != 1:
        print(key[i] ** 2)
        exit()
    if c[key[i]] >= 2:
        if count == 0:
            a = key[i]
            count += 1
        elif count == 1:
            b = key[i]
            count += 1
    if count >= 2:
        print(a * b)
        exit()
print(0)

Solution (Python):
from collections import defaultdict

N = int(input())
As = sorted(map(int, input().split()), reverse=True)

prev = None
pair = []
for A in As:
    if prev == A:
        prev = None
        pair.append(A)
        if len(pair) == 2:
            break
    else:
        prev = A

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

Solution (Python):
import collections
N=int(input())
A=list(map(int,input().split(' ')))
counter=collections.Counter(A)
ans=0
ans_part=-1
for x in sorted(list(counter.keys()))[::-1]:
	if ans_part==-1:
		if counter[x] >= 4:
			ans = x**2
			break
		elif 2<=counter[x]<=3:
			ans_part=x
	else:
		if counter[x] >= 2:
			ans=ans_part*x
			break
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
dic = {} 
max1,max2 = 0,0
count = 0

for i in range(N):
  if(A[i] in dic):
    dic[A[i]] += 1
    if(dic[A[i]]%2 == 0):
      count += 1
      if(max1 < A[i]):
        max2 = max1
        max1 = A[i]
      if(A[i] < max1):
        max2 = max(max2,A[i])
  else:
    dic[A[i]] = 1

ans = 0
if(count >= 2):
  if(dic[max1] >= 4):
    ans = max1*max1
  else:
    ans = max1*max2
print(ans)

Solution (Python):
from collections import Counter
import sys
h=w=index=0
n=int(input())
a=list(map(int,input().split()))
l=Counter(a)
l2=sorted(l.items(),reverse=True)
for i in range(len(l2)):
  if l2[i][1]>=2:
    if l2[i][1]>=4:
      print(l2[i][0]**2)
      sys.exit()
    w=l2[i][0]
    index=i
    break
for i in range(index+1,len(l2)):
  if l2[i][1]>=2:
    h=l2[i][0]
    break
print(h*w)

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

d = {}
for a in A:
  d[a] = d.get(a,0) + 1
B = [0,0]
for k in d:
  if d[k] >= 4:
    B.append(k)
    B.append(k)
  elif d[k] >=2:
    B.append(k)
B.sort()
print(B[-1]*B[-2])

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)


def chouhoukei(count, ans, num):
    if count == 4:
        return ans
    else:
        if num >= N - 1:
            return 0
        if A[num] == A[num + 1]:
            return chouhoukei(count + 2, ans * A[num], num + 2)
        else:
            return chouhoukei(count, ans, num + 1)


print(chouhoukei(0, 1, 0))

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

x.sort()
x = x[::-1]
k = []
t = x[0]
for i in range(1,a):
    if t == x[i]:
        k.append(x[i])
        t = 0
    else:t = x[i]
if len(k)>=2:
    print(k[0]*k[1])
else:print(0)

Solution (Python):
N = input()
d = {}
for a in map(int, raw_input().split()):
  d[a] = d.get(a, 0) + 1
sorted_len_num = sorted(d.items(), key=lambda x:x[0])
REQUIRED_NUM = 2
remained = REQUIRED_NUM
s = 1
for l, n in reversed(sorted_len_num):
  if remained == 0:
    break
  if n < 2:
    continue
  s *= l
  remained -= 1
  if n > 3 and remained > 0:
    s *= l
    remained -= 1
    

if remained == 0:
  print s
else:
  print 0

Solution (Python):
N=int(input())
l=map(int,input().split())
h=dict()
m1=0
m2=0
for i in l:
        if(i not in h):
                h.update({i:1})
        else:
                del h[i]
                if(i>m1):
                        m2=m1
                        m1=i
                else:
                        m2=max(m2,i)
print(m1*m2)

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

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):
from collections import Counter

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

C = Counter(A)
l = []
for i, v in C.items():
    if v >= 2:
        l.append(i)
    if v >= 4:
        l.append(i)

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

Solution (Python):


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

    A.sort(reverse = True)
    e = []
    i = 0
    while i < N - 1:
        if A[i] == A[i + 1]:
            e.append(A[i])
            if len(e) == 2:
                print(e[0] * e[1])
                return
            i += 2
        else:
            i += 1


    print(0)


if __name__ == '__main__':
    main()

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
As = map(int, input().split())
c = Counter(As)

ans = []
for k in reversed(sorted(c.keys())):
    v = c[k]
    while v >= 2:
        ans.append(k)
        v -= 2
        if len(ans) == 2:
            print(ans[0] * ans[1])
            sys.exit(0)
print(0)

Solution (Python):
N = int(input())
A = list(map(int, input().split(' ')))
sorted_A = sorted(A)
before = -1
pair = []
for a in sorted_A[::-1]:
    if a != before:
        before = a
    elif a == before:
        pair.append(a)
        if len(pair) == 2:
            break
        before = -1
ans = 0
if len(pair) == 2:
    ans = pair[0]*pair[1]
print(ans)

Solution (Python):
from collections import defaultdict
d = defaultdict(int)

rec = [0,0]

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

for key in A:
	d[key] += 1
	if d[key] == 2:
		if key > rec[0]:
			rec[0] = key
			rec = sorted(rec)
		d[key] = 0

print(rec[0] * rec[1])

Solution (Python):
from collections import defaultdict
edge = defaultdict(lambda: 0)
def inpl(): return [int(i) for i in input().split()]
N = int(input())
A = inpl()
for i in A:
    edge[i] += 1
doubled = []
for j,k in edge.items():
    if k >= 2:
        doubled.append(j)
    if k >= 4:
        doubled.append(j)
doubled = (sorted(doubled))
if len(doubled) < 2:
    print(0)
else:
    print(doubled[-1]*doubled[-2])

Solution (Python):
lfl={}
l1=0
l2=0
n=int(input().strip())
a=list(map(int, input().split()))

for i in range(n):
    if a[i] in lfl:
        lfl[a[i]]+=1
    else:
        lfl[a[i]]=1
    if lfl[a[i]]>=2:
        if l1<a[i]:
            l2=l1
            l1=a[i]
            lfl[a[i]]-=2
        elif l2<a[i]:
            l2=a[i]
            lfl[a[i]]-=2
print(l1*l2)

Solution (Python):
import collections
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
c_l = c.most_common()
l = []
for e in c_l:
    if e[1] >= 4:
        l.append(e[0])
        l.append(e[0])
    elif e[1] >= 2:
        l.append(e[0])
l.sort()
if len(l) >= 2:
    print(l[-1]*l[-2])
else:
    print(0)

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
P = list(set(L))
if len(P) == len(L) :
    ans = 0
else :
    D = {}
    ans = 1
    for i in range(N) :
        if L[i] not in D :
            D[L[i]] = 1
        else :
            D[L[i]] += 1
    D = sorted(D.items(),key=lambda x: x[0], reverse=True)
    flag = 0
    for i in range(len(D)) :
        if D[i][1] >= 4 and flag < 1 :
            ans *= D[i][0]**2
            flag += 2
        elif D[i][1] >= 2 and flag < 2 :
            ans *= D[i][0]
            flag += 1
print(ans)

Solution (Python):
import sys

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

import collections

c = collections.Counter(A)

S = sorted(c.items(), reverse=True)

max1 = 0
max2 = 0
for s in S:
    if max1 == 0:
        if s[1] >= 4:
            max1 = s[0]
            max2 = s[0]
            break
        elif s[1] >= 2:
            max1 = s[0]
    else:
        if s[1] >= 2:
            max2 = s[0]
            break

print(max1 * max2)

Solution (Python):
import collections

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

count = collections.Counter(A).most_common()

candidate = [(i,j) for i,j in count if j >= 2]

if len(candidate) == 0:
    print(0)
    exit()

candidate = sorted(candidate)

if candidate[-1][1] >= 4:
    print(candidate[-1][0] ** 2)
else:
    print(candidate[-1][0] * candidate[-2][0])

Solution (Python):
import collections
c=collections.Counter()
n=input()
for a in map(int, raw_input().split()):
	c[a]+=1
l=[a for a, num in c.items() if num>=2]+[a for a, num in c.items() if num>=4]
if len(l)<2:
	print 0
else:
	m=max(l)
	l.remove(m)
	print m*max(l)

Solution (Python):
import collections
c=collections.Counter()
n=input()
for a in map(int, raw_input().split()):
	c[a]+=1
l=[a for a, num in c.items() if num>=2]+[a for a, num in c.items() if num>=4]
if len(l)<2:
	print 0
else:
	m=max(l)
	l.remove(m)
	print m*max(l)

Solution (Python):

from collections import Counter
def inpl(): return list(map(int, input().split()))

N = int(input())
C= Counter(inpl())

F = sorted([k for k, v in C.items() if v >= 4] + [0])
T = sorted([k for k, v in C.items() if v >= 2] + [0, 0])

print(max(F[-1]*F[-1], T[-1]*T[-2]))

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
A=sorted(A,reverse=True)
l=0
r=0
t=10**9+7
for i in range(N):
    s=A[i]
    if s==t:
        if l==0:
            l=s
            t=10**9+7
        elif r==0:
            r=s
            t=10**9+7
        continue
    t=A[i]
print(l*r)

Solution (Python):
import collections

n = int(input())
a = list(map(int, input().split()))
ac = collections.Counter(a)
quad = [i for i in ac if ac[i] >= 4]
if quad:
    ans = max(quad) ** 2
else:
    ans = 0
twice = sorted([i for i in ac if ac[i] >= 2])
if len(twice) >= 2:
    ans = max(ans, twice[-1] * twice[-2])
print(ans)

Solution (Python):
n = int(input())
list_a = list(map(int, input().split()))
dict_a = {}
for i in range(n):
    try:
        dict_a[list_a[i]] += 1
    except KeyError:
        dict_a[list_a[i]] = 1
key_list = []
for key,value in dict_a.items():
    if 2 <= value <= 3:
        key_list.append(key)
    elif 4 <= value:
        key_list.append(key)
        key_list.append(key)
key_list.sort()
try:
    print(key_list[-1] * key_list[-2])
except IndexError:
    print(0)

Solution (Python):
ai = lambda: list(map(int, input().split()))

n = int(input())
a = ai()
from collections import Counter
c = Counter(a)
a = [i for i in c if c[i]>1]
a.sort()
if len(a)>0 and c[a[-1]]>=4:
    print(a[-1]**2)
elif len(a)<2:
    print(0)
else:
    print(a[-1]*a[-2])

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

Solution (Python):
from collections import Counter
n = int(input())
a = Counter(map(int, input().split()))
ans = 0
b = [k for k, v in sorted(a.items()) if v >= 2]
for k, v in sorted(a.items(), reverse=True):
    if v >= 4:
        ans = max(ans, k * k)
if len(b) >= 2:
    ans = max(ans, b[-1] * b[-2])
print(ans)

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

A = sorted(list(map(int, input().split())))[::-1]

k = 0
i = 0
while i < N - 1:
    if A[i] == A[i + 1]:
        if k == 0:
            k = A[i]
            i += 1
        else:
            print(k * A[i])
            exit()
    i += 1

print(0)

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
from heapq import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N = read()
cnt = Counter()

for a in reads():
  cnt[a] += 1

edges = sorted([e for e in cnt.keys() if cnt[e] >= 2], reverse=True)

if len(edges) == 0:
  print(0)
else:
  e = edges[0]
  if cnt[e] >= 4:
    print(e*e)
  elif len(edges) <= 1:
    print(0)
  else:
    f = edges[1]
    print(e*f)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
f,s,i = 0,0,0
while i+1<n:
    if a[i]==a[i+1]:
        s = f
        f = a[i]
        i += 1
    i += 1
print(f*s)

Solution (Python):

n = int(input())
d = {}

for x in input().split():
    a = int(x)
    if a not in d:
        d[a] = 0
    d[a] += 1

ret1 = 0
ret2 = 0
kk = list(d.keys())
kk.sort(reverse=True)
for k in kk:
    if d[k]>=4 and ret1==0:
        ret1 = k**2
        if ret2==0:
            break
    if d[k]>=2:
        if ret2==0:
            ret2 = k
        elif ret2>0:
            ret2 *= k
            break
print(max(ret1,ret2))

Solution (Python):

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

a.sort()
ass = []
ans  =[]
d = 0

for i in range(n-1):
    if a[i] == a[i+1]:
        ass.append(a[i])
        d += 1
        if d == 3:
            ans.append(a[i])
    else:
        d = 0
ass = list(set(ass))
ass.sort()

if ans != []:
    if max(ans)==max(ass):
        print(max(ans)*max(ans))
    else:
        print(ass[len(ass)-1]*ass[len(ass)-2])
else:
    if len(ass) == 0 or len(ass) == 1:
        print(0)
    else:
        print(ass[len(ass)-1]*ass[len(ass)-2])

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

arr = map(int,raw_input().split())

arr.sort()

i = n-1

lines = []

while i > 0 and len(lines) < 2:
	if arr[i] == arr[i-1]:
		lines.append(arr[i])
		i -= 2
		next

	else :
		i -= 1

if len(lines) == 2:
	print lines[0] * lines[1]

else :
	print 0

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

a.sort(reverse=True)

i = 0
k = [0, 0]
while i < len(a) - 1:
    if a[i] == a[i + 1]:
        i += 1
        k.append(a[i])
    if len(k) > 3:
        break
    i += 1

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
from collections import defaultdict
d = defaultdict(int)
ans, t = 0, 0
for i in range(n):
  d[a[i]] += 1
  if d[a[i]]==2:
    d[a[i]] = 0
    ans = max(ans, t*a[i])
    t = a[i]
print(ans)

Solution (Python):
'''input
4
1 2 3 4
'''
from collections import Counter
n = input()
arr = map(int,raw_input().split())
c = Counter(arr)
li = []
for i in c:
	if c[i] >= 2:
		li.append(i)
li.sort()
if len(li) == 0:
	print "0"
elif len(li) == 1:
	print li[-1]**2
else:
	if c[li[-1]] >= 4:
		print li[-1]**2
	else:
		print li[-1]*li[-2]

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

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

b = {}

for i in a:
    if i in b:
        b[i] += 1
    else:
        b[i] = 1
c = []
for i in b:
    if b[i] >= 4:
        c.append(i)
        c.append(i)
    elif b[i] >= 2:
        c.append(i)
c.sort()
c.reverse()
c.append(0)
c.append(0)
print(c[0]*c[1])

Solution (Python):



from collections import Counter

n = int(input())
a = list(map(int, input().split()))
b = sorted(list(set(a)), reverse=True)
c = Counter(a)
d = []
for x in b:
    if c[x] >= 4:
        print(d[0] * x if len(d) else x * x)
        exit(0)
    elif c[x] >= 2:
        d.append(x)
        if len(d) == 2:
            print(d[0] * d[1])
            exit(0)
print(0)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
cand = [0]
p = 0
for i in range(n-1,-1, -2):
    if a[i] == a[i-1]:
        if p:
            cand.append(p*a[i])
            break
        else:
            p = a[i]

p = 0
for i in range(n-2,-1, -2):
    if a[i] == a[i-1]:
        if p:
            cand.append(p*a[i])
            break
        else:
            p = a[i]

print(max(cand))

Solution (Python):

from collections import Counter
from operator import itemgetter

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

c = Counter(a)

d = sorted(list(c.items()), key=itemgetter(0), reverse=True)

a = 0
b = 0
for i in d:
	if i[1] >= 4 and a == 0:
		a = i[0]
		b = i[0]
		break
	elif i[1] >= 2 and a == 0:
		a = i[0]
		continue
	elif i[1] >= 2 and a != 0:
		b = i[0]
		break

print(a * b)

Solution (Python):
from collections import Counter
input();a=sorted(Counter(map(int,input().split())).most_common())[::-1];c=b=0
for i in range(len(set(a))):
    if b and c:break
    if a[i][1]>3 and a[i][0]*c<a[i][0]**2:b=c=a[i][0]
    elif a[i][1]>1:b,c=c,a[i][0]
print(c*b)

Solution (Python):
from collections import Counter

N = int(input())

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

ans = []

for k,v in sorted(A.items(),key=lambda x:x[0],reverse=True):
    if v>=4:
        ans.append(k)
        ans.append(k)
    elif v>=2:
        ans.append(k)
    if len(ans)>=2:
        break
        
print(ans[0]*ans[1] if len(ans)>=2 else 0)

Solution (Python):


import sys, math, copy




HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(input())
    ai = list(map(int, input().split()))
    cnt = {}
    for a in ai:
        if a in cnt:
            cnt[a] += 1
        else:
            cnt[a] = 1

    ais = sorted(list(set(ai)), reverse=True)
    longer = 0
    shorter = 0
    for a in ais:
        if cnt[a] >= 2:
            longer = a
            cnt[a] -= 2
            break
    for a in ais:
        if cnt[a] >= 2:
            shorter = a
            cnt[a] -= 2
            break
    print(longer * shorter)

main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
import collections
data=collections.Counter(a)
ans_2=[]
ans_4=[]
for i,j in data.items():
    if 4<=j:
        ans_4.append(i)
    if 2<=j<=3:
        ans_2.append(i)
ans_2.sort()
ans_2.reverse()
ans_4.sort()
ans_4.reverse()
max_4=max_2=mix_24=0
if len(ans_4)!=0:
    max_4=ans_4[0]*ans_4[0]
if 2<=len(ans_2):
    max_2=ans_2[0]*ans_2[1]
if len(ans_4)!=0 and len(ans_2)!=0:
    mix_24=ans_2[0]*ans_4[0]
print(max(max_2,max_4,mix_24))

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

for i in A:
    if A[i]>=2:
        a.append(i)
    if A[i]>=4:
        a.append(i)
a.sort()
print(a[-1]*a[-2])

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

cnt = {}
for a in A:
	if a in cnt:
		cnt[a] += 1
	else:
		cnt[a] = 1

cnt = sorted(cnt.items(), key=lambda x: x[0], reverse=True)

cand2 = []
cand4 = []
for key,value in cnt:
	if value >= 4:
		cand4.append(key)
	if value >= 2:
		cand2.append(key)
cand4.append(0)
cand2.append(0)
cand2.append(0)

print(max(cand4[0] * cand4[0], cand2[0] * cand2[1]))

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

cnt = 1
sidea = 0
sideb = 0
a = 0
for i in range(1,len(A)):
	if A[i-1] == A[i]:
		a = A[i]
		cnt += 1
	else:
		if cnt >= 4:
			if sidea == 0:
				sidea = a
				sideb = a
				break
			elif sideb == 0:
				sideb = a
				break
		elif cnt >= 2:
			if sidea == 0:
				sidea = a
			elif sideb == 0:
				sideb = a
				break
		cnt = 1
		a = 0

print(sidea*sideb)

Solution (Python):

from collections import Counter
import math
N = int(input())

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

cnter = Counter(As)
V = dict()
select = 0

for k, v in cnter.most_common():
    if v>=2:
        V[k] = math.floor(v/2)

tmp = 0
h = 0

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

for k, v in sorted(V.items(), key=lambda x:-x[0]):
    if v >= 2 and tmp == 0:
        print(int(k*k))
        exit()
    else:
        if(tmp==1):
            print(int(h*k))
            exit()
        tmp += 1
        h = k

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
a = a[::-1]
tobasu = 0
one = 0
two = 0
for i in range(len(a) - 1):
    if tobasu == 1:
        tobasu = 0
        continue
    if a[i] == a[i + 1] and one == 0:
        tobasu = 1
        one = a[i]
    elif a[i] == a[i + 1] and one != 0 and two == 0:
        two = a[i]
        break
print(one * two)

Solution (Python):


N = int(input())
data = input()
A = data.split(" ")
dict = {}
for i in A:
    if i in dict:
        dict[i] += 1
    else:
        dict[i] = 1

a = 0
b = 0
for i in sorted(dict.items(),key = lambda x:int(x[0])):
    if i[1] >= 4:
        if int(i[0]) >= min(a,b):
            if a >= b:
                b = int(i[0])

            else:
                a = int(i[0])
    if i[1] >= 2:
        if int(i[0]) >= min(a,b):
            if a >= b:
                b = int(i[0])

            else:
                a = int(i[0])

print(a*b)

Solution (Python):
n = int(input())
s = input()

a = [int(i) for i in s.split(" ")]
a.sort()
a.reverse()
pairs = []
buf = None
sq = 0
for c in a:
    if buf == c:
        pairs.append(c)
        buf = None
        if len(pairs)==2:
            sq = pairs[0] * pairs[1]
            break
    else:
        buf = c
print(sq)

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

Solution (Python):
from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))


def main():
    n = int(input())
    a = sorted(readLine_int_list(),reverse=True)
    a.append(-1)
    pair = []
    ans = 0
    t = 1
    
    for i in range(n):
        
        if a[i] == a[i+1]:
            t += 1
        else:
            if t > 1:
                pair.append(a[i])
                if len(pair) == 2:
                    ans = pair[0] * pair[1]
                    break
            t = 1
        
        if t > 3:
            if pair:
                ans = max(a[i-1]*a[i], pair[0]*a[i])
            else:
                ans = a[i]**2
            break

        
        

    print(ans)


if __name__ == '__main__':
    main()

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

S = set([])
T = []
for a in A:
    if a in S:
        T.append(a)
        S.remove(a)
    else:
        S.add(a)
if len(T) <= 1:
    print("0")
    exit()
T.sort(reverse=True)
ans = T[0] * T[1]
print(ans)

Solution (Python):

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

a.sort()

k = 0;
i = len(a)-1
side = [0, 0]

while i >= 0:
	if a[i] == a[i-1]: 
		side[k] = a[i]
		k += 1
		i -= 1
	if k == 2:
		break
	i -= 1
print(side[0]*side[1])

Solution (Python):
n=int(input())
a=list(reversed(sorted(map(int,input().split()))))
i,m1,m2=1,0,0
while i<len(a):
	if a[i-1]==a[i]:
		if m1==0: 
			m1=a[i]
		elif m2==0:
			m2=a[i]
			break
		i+=1
	i+=1
print(m1*m2)

Solution (Python):

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

a = sorted(A, reverse=True)
b = []

i = 0
while i<N-1:
    if ( a[i]==a[i+1] ):
        b+=[a[i]]
        i+=2
    else:
        i+=1
    if (len(b)>1):
        break

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

Solution (Python):
n = int(raw_input())

occ = {}
for i in map(int, raw_input().split()):
    if not i in occ:
        occ[i] = 0

    occ[i] += 1

found = 0
rect = 1

for i in sorted(occ, reverse=True):
    if occ[i] >= 4 and found < 1:
        found += 2
        rect *= i*i
    elif occ[i] >= 2:
        found += 1
        rect *= i

    if found == 2:
        print rect
        break
    
if found < 2:
    print 0

Solution (Python):
from collections import Counter
N = int(input())
data = {num:x for num, x in Counter(map(int,input().split())).items() if x >= 2}
data_num = sorted(list(data.keys()), reverse=True)
if len(data) < 1:
    print(0)
elif data[data_num[0]] >= 4:
    print(data_num[0]**2)
elif len(data) < 2:
    print(0)
else:
    print(data_num[0]*data_num[1])

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

counter = Counter(A)
res =[]

for word,cnt in counter.most_common():
    if 4 <= cnt:
        res.append(word)
        res.append(word)
    elif 2 <= cnt:
        res.append(word)

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

Solution (Python):
_ = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
l = [0,0]
c = 0
i = 0
while(i < len(a)-1):
    if(a[i] == a[i+1]):
        del l[0]
        l.append(a[i])
        i += 1
        c += 1
    if(c >= 2 or i == len(a)-2):
        i = len(a)-1
        print(l[0] * l[1])
    i += 1

Solution (Python):
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
l = [0,0]
c = 0
i = 0
while(i < len(a)-1):
    if(a[i] == a[i+1]):
        del l[0]
        l.append(a[i])
        i += 1
        c += 1
    if(c >= 2 or i == len(a)-2):
        i = len(a)-1
        print(l[0] * l[1])
    i += 1