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()))
ans1=0
ans2=0
A.sort(reverse=True)
flag = False
for i in range(n-1):
  if flag == True:
    flag = False
    continue
  if i < n-1 and A[i+1] == A[i]:
    flag = True
    if A[i] >= ans1:
      ans2 = ans1
      ans1 = A[i]
    elif A[i] > ans2:
      ans2 =A[i]
print(ans1*ans2)

Solution (Python):
N = int(input())
data = list(map(int, input().split()))
data.sort()
ans = []
N -= 1
while N > 0:
    if data[N] == data[N - 1]:
        ans.append(data[N])
        N -= 1
    N -= 1
    if len(ans) >= 2:
        break

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
d = {0:4}
for a in A:
    d[a] = d.get(a, 0)+1
longest = 0
for i in d:
    if d[i]>=2:
        longest = max(longest, i)
d[longest]-=2

longest_2nd = 0
for i in d:
    if d[i]>=2:
        longest_2nd = max(longest_2nd, i)
print(longest*longest_2nd)

Solution (Python):
from collections import defaultdict
Lineger_Dict = defaultdict(int)
N = int(input())
N_List = list(map(int,input().split()))
for i in N_List:
    Lineger_Dict[i] += 1

    
Rec = sorted([k for k,v in Lineger_Dict.items() if v >= 2] + [k for k,v in Lineger_Dict.items() if v >= 4])
if len(Rec) < 2:
    print(0)
else:
    print(Rec[-1]*Rec[-2])

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

d={}

for n in range(N):
    if d.get(A[n])==None:
        d[A[n]]=1
    else:
        d[A[n]]+=1

d=sorted(d.items(),reverse=True)

cnt=0
ans=0
for i in range(len(d)):
    if cnt==0:
        if d[i][1]>=4:
            ans=d[i][0]**2
            break
        elif d[i][1]>=2:
            temp=d[i][0]
            cnt+=1
    else:
        if d[i][1]>=2:
            ans=temp*d[i][0]
            break
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
import collections
b = collections.Counter(a).most_common()
li4 = []
li2 = []
ansli = []
for k in b:
    if k[1]>=4:
        li4 +=[k[0]]
        ansli += [k[0]**2]
    if k[1]>=2:
        li2 +=[k[0]]

if len(li2)>=2:
    li22 = sorted(li2)
    ansli += [li22[-1]*li22[-2]]
if ansli:
    print(max(ansli))
else:
    print(0)

Solution (Python):

"""
Created on Wed Sep 23 20:22:31 2020

@author: liang
"""

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

A.sort(reverse=True)

ans = list()
i = 0
while i < N-1:
    if A[i] == A[i+1]:
       
        ans.append(A[i])
        i += 1
    if len(ans) == 2:
        break
    i += 1

import numpy as np

if len(ans) < 2:
    print(0)
else:
    print(np.prod(ans))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ans = []
flg = 0

A.sort(reverse=True)

for i in range(N-1):
  if A[i] == A[i+1] and flg == 0:
    ans.append(A[i])
    flg = 1
  else:
    flg = 0

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

Solution (Python):
from collections import defaultdict

d = defaultdict(int)

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

ans = []
for i in a:
  d[i] += 1
  if d[i] == 2:
    d[i] = 0
    ans.append(i)
ans.sort(reverse=True)
if len(ans) >= 2:
  print(ans[0]*ans[1])
else:
  print(0)

Solution (Python):
from collections import deque
n = int(input())
a = list(map(int, input().split()))
num_map = dict()
for i in range(n):
    if a[i] not in num_map:
        num_map[a[i]] = 1
    else:
        num_map[a[i]] += 1

keys = sorted(list(num_map.keys()), reverse=True)

q = deque()
for i in keys:
    if num_map[i] >= 2:
        q.append([i, num_map[i]])
res = 1
counter = 0
while len(q) != 0:
    key, value = q.popleft()
    res *= key
    if value - 2 >= 2:
        q.appendleft([key, value - 2])
    counter += 1
    if counter == 2:
        print(res)
        break
else:
    print(0)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
num_map = dict()
for i in range(n):
    if a[i] not in num_map:
        num_map[a[i]] = 1
    else:
        num_map[a[i]] += 1

keys = sorted(list(num_map.keys()), reverse=True)

two_over = []
counter = 0
res = 1
for i in keys:
    if num_map[i] >= 4:
        res *= i ** (2 - counter)
        counter += 2
    elif num_map[i] >= 2:
        counter += 1
        res *= i
    if counter >= 2:
        print(res)
        break
else:
    print(0)

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

if n == len(num)+1 or n == len(num):
    print(0)
    exit()

ans = []

for i in num:
    if num[i] >= 2:
        ans.append(i)
    if num[i] >= 4:
        ans.append(i)     
n = max(ans)
ans.pop(ans.index(max(ans)))
m = max(ans)
print(n*m)

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

def main():
    n = i_input()
    a = i_list()

    a.sort()

    l = []
    start = a[0]
    cnt = 1
    for i in a:
        if i == start:
            cnt += 1
        else:
            start = i
            cnt = 1
        if cnt == 2:
            l.append(i)
            cnt = 0
    if cnt == 2:
        l.append(i)
    if len(l) < 2:
        print(0)
    else:
        print(l[-1]*l[-2])



if __name__=="__main__":
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
from collections import Counter
a = Counter(a)
lis = []
 
for i,j in a.items():
    lis += [i]*(j//2)
 

 
lis.sort(reverse=True)
if len(lis) <= 1:
    ans = 0
else:
    ans = lis[0]*lis[1]
 
print(ans)

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

C = Counter(A)

rec = []
squ = []

for a in A:
    if 2 <= C[a]:
        rec.append(a)
    if 4 <= C[a]:
        squ.append(a)
rec = list(set(rec))
squ = list(set(squ))



s = 0
if len(squ) != 0:
    s = max(squ)**2

if len(rec) < 2:
    print(s)
else:
    rec.sort(reverse=True)
    print(max(s, rec[0]*rec[1]))

Solution (Python):
with open(0) as f:
    N, *A = map(int, f.read().split())

pair = []
unpair = set()
for a in A:
    if a in unpair:
        unpair.remove(a)
        pair.append(a)
    else:
        unpair.add(a)
pair.sort()
print(pair.pop()*pair.pop() if len(pair) > 1 else 0)

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

i=N-1
ans=1
count=0
while i>=1:
    if A[i-1]==A[i]:
        ans*=A[i]
        i-=2
        count+=1
    else:
        i-=1
    if count==2:
        print(ans)
        break
else:
    print(0)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
  d[a] = d.get(a, 0) + 1
d2 = sorted(d.items(), reverse = True)
s = 0
t = 0
f = 0
for p in d2:
  if s == 0:
    if p[1] >= 4:
      print(p[0] * p[0])
      f = 1
      break
    elif p[1] >= 2:
      s = p[0]
  else:
    if p[1] >= 2:
      print(s * p[0])
      f = 1
      break
if f == 0:
  print(0)

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

dic = {}
for a in A:
  if a in dic:
    dic[a] += 1
  else:
    dic[a] = 1
    
dic = sorted(dic.items(), reverse=True)

ans = 1
check = 0
bool1 = False
for (i,j) in dic:
  cnt = j // 2
  for _ in range(cnt):
    ans *= i
    check += 1
    if check == 2:
      bool1 = True
      break
  if bool1:
    break

print(ans if ans != 1 else 0)

Solution (Python):
def main():
    n = int(input())
    a_lst = list(map(int, input().split()))
    lst = [0, 0]

    a_lst.sort()
    a_lst.reverse()

    length = a_lst[0]
    count = 0
    for i in range(n):
        if a_lst[i] == length:
            count += 1

            if count == 2:
                lst.append(a_lst[i])
                count = 0

            if len(lst) == 4:
                break

        else:
            count = 1
            length = a_lst[i]

    area = lst[-1] * lst[-2]
    print(area)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a=sorted(list(map(int,input().split())))
c=1
x=[]
for i in range(n-1):
    if a[i]!=a[i+1]:
        if c>=2:
            x.append(a[i])
        if c>=4:
            x.append(a[i])
        c=1
    else:
        c+=1
if c>=2:
    x.append(a[n-1])
if c>=4:
    x.append(a[n-1])
if len(x)<=1:
    print(0)
else:
    print(x[-1]*x[-2])

Solution (Python):
N = int(input())
A = list(map(int,input().rstrip().split(" ")))
A.sort()
lis = []

for i in range(len(A) - 1):
    if A[i] == A[i + 1]:
        lis.append(A[i])
        A[i + 1] = 0
if len(lis) < 2:
    print(0)
else:
    print(lis[-1] * lis[-2])

Solution (Python):
import heapq
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
l = []
for i in set(a):
    if c[i] >= 2:
        for j in range(c[i]//2):
            l.append(i)
if len(l) >= 2:
    print(heapq.nlargest(2, l)[0]*heapq.nlargest(2, l)[1])
else:
    print(0)

Solution (Python):



import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6
3 1 2 4 2 1"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4
1 2 3 4"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10
3 3 3 3 4 4 4 5 5 5"""
        output = """20"""
        self.assertIO(input, output)


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

    A.sort(reverse=True)
    l1 = l2 = 0
    for i in range(1, N):
        if l1 == 0:
            if A[i] == A[i-1]:
                l1 = A[i-1]
        else:
            if i < N-1 and A[i+1] == A[i]:
                l2 = A[i]
                break

    print(l1*l2)


if __name__ == "__main__":
    
    resolve()

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial

from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=reverse)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictsort(dict,reverse=False):
    return sorted( dict.items(), reverse=reverse )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

ddict = defaultdict(lambda: 0)





n = I()
a = RI()

for i in range(n):
    ddict[ a[i] ] += 1

d = mydictsort(ddict,reverse=True)


h = 0
w = 0
for i in range(len(ddict)):
    if d[i][1]>=4:
        if h==0:
            h = d[i][0]
            print(h*h)
            exit()
    if d[i][1]>=2:
        if h==0:
            h = d[i][0]
        elif w==0:
            w = d[i][0]

if h!=0 and w!=0:
    print(w*h)
else:
    print(0)

Solution (Python):









import os
import sys


from collections import Counter


def main():
    _ = int(input())
    a = list(map(int, input().split()))
    a_cnt = [[key, val] for key, val in Counter(a).items() if val >= 2]
    if len(a_cnt) == 0:
        print(0)
        return
    a_cnt.sort(key=lambda x: x[0], reverse=True)
    if a_cnt[0][1] >= 4:
        print(a_cnt[0][0]**2)
    elif len(a_cnt) == 1:
        print(0)
    else:
        print(a_cnt[0][0]*a_cnt[1][0])


if __name__ == "__main__":
    main()

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

for i,j in a.items():
    lis += [i]*(j//2)



lis.sort(reverse=True)
if len(lis) <= 1:
    ans = 0
else:
    ans = lis[0]*lis[1]

print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
import collections
a = collections.Counter(A)
b = []
for i, j in a.items():
    if j >= 2:
        b.append([i,j])
b.sort(reverse=True)
if len(b) >= 1 and b[0][1] >= 4:
    print(b[0][0] ** 2)
elif len(b) >= 2:
    print(b[0][0] * b[1][0])
else:
    print(0)

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


a.sort()

count=0


def get_num(a):
    count=1
    taishou = a.pop()
    while a!=[]:
        second=a.pop()
        if taishou==second:
            count+=1
        else:
            a.append(second)
            break
    if count==1:
        return taishou,0
    elif count==2 or count==3:
        return taishou,1
    else:
        return taishou,2

one=0
two=0


while a!=[] and (one==0 or two==0):
    hen,length=get_num(a)
    if length==1:
        if one==0:
            one=hen
        else:
            two=hen
    elif length==2:
        if one==0:
            one=hen
            two=hen
        else:
            two=hen

print(one*two)

Solution (Python):
def main():
    _ = int(input())
    a = [int(an) for an in input().split()]
    a.sort(reverse=True)
    line = -1
    lines = []
    for an in a:
        if line == an:
            lines.append(an)
            if len(lines) == 2:
                break
            line = -1
        else:
            line = an
    print(lines[0] * lines[1] if len(lines) == 2 else 0)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    _ = int(input())
    a = [int(an) for an in input().split()]
    a.sort(reverse=True)
    line = -1
    lines = []
    for an in a:
        if line == an:
            lines.append(an)
            if len(lines) == 2:
                break
            line = -1
        else:
            line = an
    print(lines[0] * lines[1] if len(lines) == 2 else 0)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

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

dic = Counter(a)

l = []
for i, j in dic.items():
    if j >= 4:
        l.append(i)
        l.append(i)
    elif j >= 2:
        l.append(i)

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

Solution (Python):
import collections
N = int(input())
lsA = list(map(int,input().split()))
counterA = collections.Counter(lsA)
lsline = []
for i in counterA.keys():
    if counterA[i] >= 2:
        lsline.append(i)
lsline.sort(reverse=True)
if bool(lsline):
    if counterA[lsline[0]] >= 4:
        ans = lsline[0]*lsline[0]
    elif len(lsline) < 2:
        ans = 0
    else:
        ans = lsline[0]*lsline[1]
else:
    ans = 0
print(ans)

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

for i in range(n):
  dic[a[i]] += 1
ans = 0
ls = list(dic.keys())
ls.sort()
ans_ls = []

for i in range(len(ls)-1,-1,-1):
  if dic[ls[i]] >= 2:
    ans_ls.append(ls[i])
  if dic[ls[i]] >= 4:
    ans_ls.append(ls[i])
if len(ans_ls) < 2:
  print(0)
else:
  print(ans_ls[0] * ans_ls[1])

Solution (Python):
from collections import Counter

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

A_ = sorted([[k, v] for k, v in cnt_A.items() if v >= 2], reverse=True)

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

Solution (Python):
from collections import *
n=int(input())
l=list(map(int,input().split()))
d=defaultdict(int)
for i in l:
    d[i]+=1
x=[]
for i in d:
    if(d[i]>=4):
        x.append(i)
        x.append(i)
    elif(d[i]>=2):
        x.append(i)
x.sort(reverse=True)
if(len(x)<2):
    print(0)
else:
    print(x[0]*x[1])

Solution (Python):
import collections

def main():
    N = input()
    A = map(int, input().split())
    c = collections.Counter(A)
    edge1 = None
    for edge, freq in sorted(c.items(), key=lambda x: -x[0]):
        if edge1 is None and freq >= 4:
            print(edge ** 2)
            exit()
        elif edge1 is None and freq >= 2:
            edge1 = edge
        elif edge1 is not None and freq >= 2:
            print(edge1 * edge)
            exit()
    print(0)


if __name__ == '__main__':
    main()

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

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

pair = []
unpair = set()
for a in A:
    if a in unpair:
        pair.append(a)
        unpair.remove(a)
    else:
        unpair.add(a)

pair.sort()
pair.reverse()
if len(pair) <= 1:
    ans = 0
else:
    ans = pair[0] * pair[1]
print(ans)

Solution (Python):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
counter = dict(Counter(A))
four = []
tow = []
for key in counter.keys():
    if counter[key] >= 4:
        four.append(key)
        tow.append(key)
    elif counter[key]>=2:
        tow.append(key)

if len(four) == 0 and len(tow) <= 1:
    print(0)
else:
    ans = 0
    four.sort(reverse=True)
    tow.sort(reverse=True)
    if len(four) >= 1:
        ans = max(ans, four[0]**2)
    if len(tow) >= 2:
        ans = max(ans, tow[1] * tow[0])
    print(ans)

Solution (Python):
from collections import Counter


def solve():
    c = Counter(arr)
    four_edges = [k for k, v in c.items() if v >= 4]
    two_edges = [k for k, v in c.items() if 1 < v < 4]
    four_edges.append(0)
    two_edges.append(0)
    four_edges.sort(reverse=True)
    two_edges.sort(reverse=True)

    area_f = four_edges[0] * four_edges[0]
    if len(two_edges) >= 2:
        area_t = two_edges[0] * two_edges[1]
    else:
        area_t = 0
    area_t_t = two_edges[0] * four_edges[0]
    max_area = max(area_f, max(area_t, area_t_t))
    return max_area


N = int(input())
arr = list(map(int, input().split()))
res = solve()
print(res)

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

d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
d = sorted(d.items(), key=lambda x:x[0], reverse=True)

m = len(d)
ans = 0
flg = True
for i in range(m):
    k, v = d[i][0], d[i][1]
    if ans == 0:
        if v >= 4:
            ans = k**2
            flg = True
            break
        elif v >= 2:
            ans = k
    elif v >= 2:
        ans *= k
        flg = True
        break
print(ans) if flg else print(0)

Solution (Python):
from collections import Counter
N=int(input())
A=list(map(int, input().split()))
C=Counter(A)
L=[]
R=[]
for i in C:
  l=C.get(i)
  if l>=2:
    L.append(i)
    if l>=4:
      R.append(i)
L.sort()
R.sort()

ans=0

if len(L)>=2:
  ans=max(L[-1]*L[-2], ans)
if len(R)>=1:
  ans=max(R[-1]**2, ans)
print(ans)

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

count = {}
rect = {}
for i in range(N):
    if A[i] in rect:
        rect[A[i]] += 1
    elif A[i] in count:
        rect[A[i]] = 2
    else:
        count[A[i]] = 1

if len(rect) < 1:
    ans = 0
else:
    x = max(rect)
    if rect[x] >= 4:
        ans = x * x 
    else:
        del rect[x]
        if len(rect) < 1:
            ans = 0
        else:
            y = max(rect)
            ans = x * y
print(ans)

Solution (Python):
input();a=list(map(int,input().split()));d={}
for i in a:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1
d={i:j for i,j in d.items() if j>1}
if len(d)<2:
  print(0)
else:
  d=sorted(d.items(),key=lambda x:(-x[0],-x[1]))
  print(d[0][0]*d[1][0] if d[0][1]<4 else d[0][0]*d[0][0])

Solution (Python):
from collections import Counter
 
input()
d = Counter(map(int, input().split()))
d = dict(sorted(d.items(), reverse=True))
ans = []
for i, j in d.items():
    if j >= 4:
        ans.append(i)
    if j >= 2:
        ans.append(i)
if len(ans) >= 2:
    print(ans[0] * ans[1])
else:
    print(0)

Solution (Python):
from heapq import heapify,heappush,heappop
a = []
heapify(a)

dic = {}

N = int(input())
A = list(map(int,input().split()))
for i in range(N):
    if not(A[i] in dic):
        dic[A[i]]=1
    elif dic[A[i]]==1:
        dic[A[i]]=0
        heappush(a,-A[i])
    elif dic[A[i]]==0:
        dic[A[i]]=1

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

w = heappop(a)
h = heappop(a)

print(w*h)

Solution (Python):
from collections import defaultdict,deque
import math
def main():
    n = int(input())
    A=[int(i) for i in input().split()]
    dd = defaultdict(int)
    for i in A:
        dd[i]+=1
    lis = []
    for v in dd.keys():
        if(dd[v]>=4):
            lis.append(v)
            lis.append(v)
        elif(dd[v]>=2):
            lis.append(v)

    lis.sort(reverse = True)
    if(len(lis)<2):
        print(0)
    else:
        print(lis[0]*lis[1])



if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
ca = Counter(A)
ca = sorted(ca.items(), key=lambda x:-x[0])
cnt = 0
m = []
for k, v in ca:
  if 3 >= v >= 2:
    cnt += 1
    m += [k]
  elif v >= 4:
    cnt += 2
    m += [k, k]
  if cnt >= 2:
    break

if len(m) <= 1:
  print(0)
  exit()
print(m[0]*m[1])

Solution (Python):
import collections
N=int(input())
L=list(map(int,input().split()))
c = collections.Counter(L)
A=list(c.keys())
B=list(c.values())
R=list()
for i in range(len(A)):
  if B[i]>=2:
    R.append([A[i],B[i]])
R=sorted(R,reverse=True)
if len(R)==0:
  print(0)
  exit()
if R[0][1]>=4:
  print(R[0][0]**2)
elif len(R)<2:
  print(0)
else:
  print(R[0][0]*R[1][0])

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

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

dic = {}
for ai in al:
    dic[ai] = dic.get(ai, 0)+1

edges = sorted(dic.items(), reverse=True)
ans = 0
partial = False
temp = 0
for tup in edges:
    e, num = tup
    if num == 1:
        continue
    elif num == 2 or num == 3:
        if partial:
            ans = temp*e
            break
        else:
            partial = True
            temp = e
    else:
        if partial:
            ans = temp*e
            break
        else:
            ans = e**2
            break
print(ans)

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

A.sort(reverse=True)
l1 = 0
c1 = 0
l2 = 0
c2 = 0

L1 = 0
L2 = 0

for i in range(len(A)):
  if L1 and L2:
    break
  elif L1:
    if l2 == A[i]:
      c2 += 1
    elif l2 != A[i]:
      l2 = A[i]
      c2 = 1
    if c2 == 2:
      L2 = l2
  else:
    if l1 == A[i]:
      c1 += 1
    elif l1 != A[i]:
      l1 = A[i]
      c1 = 1
    if c1 == 2:
      L1 = l1

print(L1 * L2)

Solution (Python):
def main():
    n = int(input())
    inlis = list(map(int, input().split()))
    indic = dict()

    for i in range(n):
        a = inlis[i]
        if a in indic:
            indic[a] += 1
        else:
            indic[a] = 1
    indic2 = sorted(indic.items(), key = lambda x:x[0], reverse=True)
    ans1 = 0

    for j in range(n):
        kazu = indic2[j][1]
        nagasa = indic2[j][0]
        if kazu >= 4 and ans1 == 0:
            print(nagasa ** 2)
            exit()
        elif kazu >= 2 and ans1 == 0:
            ans1 = nagasa
        elif kazu >= 2 and ans1 > 0:
            print(ans1 * nagasa)
            exit()
    print(0)
        



if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter

input()
ans = [0, 0]
for i, j in Counter(map(int, input().split())).items():
    if j >= 4:
        ans.append(i)
    if j >= 2:
        ans.append(i)
ans.sort()
print(ans[-1] * ans[-2])

Solution (Python):
from collections import Counter

input()
ans = []
for i, j in Counter(map(int, input().split())).items():
    if j >= 4:
        ans.append(i)
    if j >= 2:
        ans.append(i)
if len(ans) >= 2:
    ans.sort()
    print(ans[-1] * ans[-2])
else:
    print(0)

Solution (Python):
from collections import Counter

input()
d = Counter(map(int, input().split()))
d = dict(sorted(d.items(), reverse=True))
ans = []
for i, j in d.items():
    if j >= 4:
        ans.append(i)
    if j >= 2:
        ans.append(i)
if len(ans) >= 2:
    print(ans[0] * ans[1])
else:
    print(0)

Solution (Python):
from collections import Counter

input()
d = Counter(map(int, input().split()))
d = dict(sorted(d.items(), reverse=True))
ans = []
for i, j in d.items():
    if j >= 4:
        ans.append(i)
    if j >= 2:
        ans.append(i)
    if len(ans) >= 2:
        print(ans[0] * ans[1])
        break
else:
    print(0)

Solution (Python):
from collections import Counter

input()
d = Counter(map(int, input().split()))
d = dict(sorted(d.items(), reverse=True))
ans = []
for i, j in d.items():
    if len(ans) < 2 and j >= 4:
        ans.append(i)
        d[i] -= 2
    if len(ans) < 2 and j >= 2:
        ans.append(i)
        d[i] -= 2
    if len(ans) == 2:
        print(ans[0] * ans[1])
        break
else:
    print(0)

Solution (Python):
input()
d = {}
for i in map(int, input().split()):
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
d = dict(sorted(d.items(), reverse=True))
ans = []
for i, j in d.items():
    if len(ans) < 2 and j >= 4:
        ans.append(i)
        d[i] -= 2
    if len(ans) < 2 and j >= 2:
        ans.append(i)
        d[i] -= 2
    if len(ans) == 2:
        print(ans[0] * ans[1])
        break
else:
    print(0)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
dic = {}
for i in range(n):
    dic.setdefault(a[i],0)
    dic[a[i]] += 1
ans = []
for item in dic.items():
    if item[1]>=2:
        ans.append(item[0])
if len(ans)<=1:
    print(0)
else:
    ans.sort()
    if dic[ans[-1]]>=4:
        print(ans[-1]**2)
    else:
        print(ans[-1]*ans[-2])

Solution (Python):
n = int(input())
a = sorted(list(map(int, input().split())),reverse=True)
d = {}
for i in a:
  try:d[i] += 1
  except:d[i] = 1

ans = 0
t = 0
for i in d:
  if(d[i] >= 4 and ans == 0):print(i*i);exit()
  if(d[i] >= 2 and ans == 2):print(t*i);exit()
  if(d[i] >= 2 and ans == 0):t=i;ans=2
print(0)

Solution (Python):
N=int(input())
A=sorted(list(map(int,input().split())))
l=[]
s=set()
for i in range(N):
    if A[N-i-1] in s:
        l.append(A[N-i-1])
        s.discard(A[N-i-1])
    else:
        s.add(A[N-i-1])
l.sort()
print(0 if len(l)<2 else l[-1]*l[-2])

Solution (Python):
n = int(input())
a1 = list(map(int, input().split()))
from collections import Counter
a = Counter(a1).most_common()
l = []
for i in range(len(a)):
    if 2 <= a[i][1]:
        for h in range(a[i][1]//2):
            l.append(a[i][0])
l.sort()
if 2 <= len(l):
    print(l[-1]*l[-2])
else:
    print(0)

Solution (Python):
from collections import Counter

n = int(input())
a = Counter(map(int, input().split()))
xy = []
a = sorted(a.items(), key=lambda x: x[0], reverse=True)
for i in a:
    if len(xy) == 2:
        break
    if i[1] >= 4:
        xy.append(i[0])
        xy.append(i[0])
        break
    if i[1] >= 2:
        xy.append(i[0])

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

Solution (Python):
n = int(input())
a = sorted(list(map(int, input().split())))
i = n - 1
p = 0
q = 0
while i > 0:
  if a[i] == a[i-1]:
    if p == 0:
      p = a[i]
      i -= 1
    else:
      q = a[i]
      break
  i -= 1
print(p*q)

Solution (Python):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
bou2 = []
bou4 = []
for k, v in c.items():
    if v > 1:
        bou2.append(k)
    if v > 3:
        bou4.append(k)

bou2.sort(reverse=True)
bou4.sort(reverse=True)
ans = 0
if len(bou2) >= 2:
    ans = bou2[0]*bou2[1]
if len(bou4) != 0:
    ans = max(ans, bou4[0]*bou4[0])
print(ans)

Solution (Python):
from collections import Counter

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

c = Counter(A)
mc=[]
for k in c.keys():
  if c[k]>=2:mc.append(k)
    
if len(mc)==0:
  print(0)
  exit()

elif len(mc)==1:
  if c[mc[0]]<4:
    print(0)
    exit()
  else:
    print(mc[0]**2)
    exit()
  
mc = sorted(mc,reverse=True)
if c[mc[0]] < 4:print(mc[0]*mc[1])
else:print(mc[0]**2)

Solution (Python):
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
D = defaultdict(int)
A.sort(reverse=True)

for i in A:
  D[i] += 1

L = []

for i, x in D.items():
  if x >= 4:
    L.append(i)
    L.append(i)
    break
  elif x >= 2:
    L.append(i)

if len(L) <= 1:
  print(0)
else:
  print(L[0]*L[1])

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
i = 0
c = 0
x = 0
y = 0 
while i < len(a) - 1:
	if a[i] == a[i+1] and c == 0:
		x = a[i]
		i += 2
		c += 1
		continue
	if a[i] == a[i+1] and c == 1:
		y = a[i]
		break
	i += 1
if x != 0 and y != 0:
	print(x*y)
else:
	print(0)

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


import collections
d=collections.Counter(L)
M=0
m=[0,0]
for v in d:
	if d[v]>=4:
		M=max(M,v)
	elif d[v]>=2:
		m.append(v)
m.sort(reverse=True)

print(max(M**2,m[0]*m[1],M*m[0]))