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(reverse = True)
b = True
wh = 0
for i in range(n - 1):
  if b == False:
    b = True
    continue
  if a[i] == a[i + 1]:
    b = False
    if wh == 0:
      wh = a[i]
    else:
      print(wh * a[i])
      exit()
print(0)

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

a_cnt = {}
for ai in A:
    if ai in a_cnt:
        a_cnt[ai] += 1
    else:
        a_cnt[ai] = 1
from operator import itemgetter
a_cnt = sorted(a_cnt.items(), key=itemgetter(0), reverse=True)
tate = 0
yoko = 0
for i in range(len(a_cnt)):
    if a_cnt[i][1] >= 2:
        tate = a_cnt[i][0]
        
        a_cnt[i] = (a_cnt[i][0], a_cnt[i][1] - 2)
        break
for i in range(len(a_cnt)):
    if a_cnt[i][1] >= 2:
        yoko = a_cnt[i][0]
        
        a_cnt[i] = (a_cnt[i][0], a_cnt[i][1] - 2)
        break


print(tate * yoko)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
cnt=1
li=[]
x=[0]
for i in range(n-1):
    if a[i+1]==a[i]:
        cnt+=1
    else:
        cnt=1
    if cnt==2:
        li.append(a[i+1])
    if cnt==4:
        x.append(a[i+1])

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

Solution (Python):
import collections

n, *a = map(int, open(0).read().split())
c = collections.Counter(a)
length_l = list(c.keys())
length_l.sort(reverse = True)
side1 = 0
ans = 0
for l in length_l:
    cnt = c[l]
    if cnt >= 4:
        if side1 != 0:
            ans = side1*l
            break
        else:
            ans = l**2
            break
    elif cnt >= 2:
        if side1 != 0:
            ans = side1*l
            break
        else:
            side1 = l
print(ans)

Solution (Python):


from collections import Counter


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

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


if __name__ == "__main__":
    main()

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

import collections
lst=collections.Counter(A).most_common()
lst_larger=[el for el in lst if el[1]>=2]


if len(lst_larger) >= 2:
    lst_larger=sorted(lst_larger, key=lambda x:x[0], reverse=True)
    if lst_larger[0][1]>=4:
        print(lst_larger[0][0]**2)
    else:
        print(lst_larger[0][0]*lst_larger[1][0])
else:
    print(0)

Solution (Python):
from collections import defaultdict
n=int(input())
a=list(map(int,input().split()))
cnt=defaultdict(int)
for i in range(n):
  cnt[a[i]]+=1
tmp=[]
for key in cnt.keys():
  if cnt[key]>=2:
    tmp.append(key)
    if cnt[key]>=4:
      tmp.append(key)
tmp=sorted(tmp,reverse=True)
if len(tmp)<=1:
  print(0)
else:
  print(tmp[0]*tmp[1])

Solution (Python):
def main2():
    r = int(input())

    stick = [int(v) for v in input().split()]
    stick = sorted(stick, reverse=True)

    line = []
    tmp = -1
    for i in range(0, len(stick), 1):
        if tmp == stick[i]:
            line.append(stick[i])
            tmp = -1
        else:
            tmp = stick[i]
        if len(line) == 2:
            print(line[0] * line[1])
            exit()
    print(0)

main2()

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

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

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

import collections

C = collections.Counter(A)

D = sorted(list(set(A)))[::-1]

t = 0
s = 0
for i in D:
    if C[i] >= 4 and t == 0:
        print(i ** 2)
        s = 1
        break
    elif C[i] >= 2 and t == 0:
        t = i
    elif C[i] >= 2 and t != 0:
        print(i * t)
        s = 1
        break

if s == 0:
    print(0)

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

Solution (Python):
from collections import Counter

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

num_counter = Counter(a_list)
num_keys = sorted(num_counter.keys(), reverse=True)

big = 0
small = 0

for i in num_keys:
  x = num_counter[i]
  if x >= 4:
    if big == 0:
      big = small = i
    elif big != 0 and small == 0:
      small = i
  elif x == 3 or x == 2:
    if big == 0:
      big = i
    elif big != 0 and small == 0:
      small = i
  if big != 0 and small != 0:
    break
print(big * small)

Solution (Python):
import collections
n=int(input())
a=map(int,input().split())
b=list(collections.Counter(a).items())
lst=[]
Lst=[]
for i in range(len(b)):
  if b[i][1]>1:
    lst.append(int(b[i][0]))  
    if b[i][1]>3:
      Lst.append(int(b[i][0]))
if len(lst)<2 and len(Lst)==0:
  print(0)
else:
  if len(lst)==1:
    Lst.sort(reverse=True)
    print(Lst[0]**2)
  else:
    if len(Lst)>0:
      lst.sort(reverse=True)
      Lst.sort(reverse=True)
      print(max(lst[0]*lst[1],Lst[0]**2))     
    else:
      lst.sort(reverse=True)
      print(lst[0]*lst[1])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
dict = {}
b = [0,0]
c = [0,0]
for i in a:
	if i in dict:
		dict[i] += 1
	else:
		dict[i] = 1
	if dict[i] == 2:
		b.append(i)
	if dict[i] == 4:
		c.append(i)
b.sort(reverse=True)
c.sort(reverse=True)
print (max(b[0] * b[1],c[0]**2))

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

    double_cnt = 0
    ans = 1
    for elem in cnter_list:
        if elem[1] >= 4:
            if double_cnt == 0:
                ans = elem[0] * elem[0]
                break

        if elem[1] >= 2:
            double_cnt += 1
            ans *= elem[0]
        if double_cnt >= 2:
            break
    else:
        print(0)
        return
    
    print(ans)

if __name__ == '__main__':
    solve()

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

import collections
ans = 0
c = collections.Counter(A)
lis = []
for k,v in c.items():
  if v>=2:
    lis.append(k)
  if v>=4:
    lis.append(k)
if len(lis)>=2:
  lis.sort()
  ans = lis[-1]*lis[-2]
print(ans)

Solution (Python):


import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import Counter

n = ni()
a = na()
c = Counter(a)
m = list(c.items())
m.sort(reverse=True)
xy = [0] * 2
i = 0
flag = False
for k, v in m:
    if v >= 4:
        if i != 0:
            print(xy[0] * k)
        else:
            print(k * k)
        flag = True
        break
    elif v >= 2:
        xy[i] = k
        i += 1
        if i == 2:
            print(xy[0] * xy[1])
            flag = True
            break
if not flag:
    print(0)

Solution (Python):

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

c = Counter(a).most_common()
edges = []
for l, cnt in c:
    if cnt < 2:
        break
    else:
        edges.append(l)
        if cnt > 3:
            edges.append(l)
edges.sort(reverse= True)
if len(edges) < 2:
    print(0)
else:
    print(edges[0] * edges[1])

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

dict1 = {}
for i in a:
    if i in dict1:
        dict1[i] += 1
    else:
        dict1[i] = 1

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

ans = []

for a,b in dict1_sorted:
    if b >= 4:
        if len(ans) == 0:
            ans = [a] * 2
            break
        else:
            ans.append(a)
            break
    elif b >= 2:
        ans.append(a)
        if len(ans) == 2:
            break

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

Solution (Python):
input()
from collections import *
c=Counter(map(int,input().split()))
f=lambda x:sorted(-k for k,v in c.items() if v>x)
a=0;r=f(1);s=f(3)
if len(r)>1: a=r[0]*r[1]
if s: a=max(a,s[0]**2)
print(a)

Solution (Python):
input()
from collections import *
c=Counter(map(int,input().split()))
a=0
r=sorted(-k for k,v in c.items() if v>1)
if len(r)>1: a=r[0]*r[1]
s=sorted(-k for k,v in c.items() if v>3)
if s: a=max(a,s[0]**2)
print(a)

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=Counter(a).most_common()
s=[0,0]
for v in c:
  if v[1]>=2:
    for _ in range(v[1]//2):
      s.append(int(v[0]))
s.sort()
print(s[-1]*s[-2])

Solution (Python):
from collections import Counter

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

c = Counter(a)
s = [(k, v) for k, v in c.items() if v >= 2]

s1 = s2 = 0  
for k, v in s:
    if k > s1:
        if v >= 4:
            s1 = s2 = k
        else:
            s1, s2 = k, s1
    elif k > s2:
        s2 = k

print(s1 * s2)

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

from collections import Counter
c = Counter(l)
c = sorted(c.items(), reverse=1)

temp = 0
for i in range(len(c)):
    if c[i][1] >= 2:
        if temp != 0:
            print(temp * c[i][0])
            exit()
        else:
            temp = c[i][0]
    if c[i][1] >= 4:
            print(c[i][0] ** 2)
            exit()
else:
    print(0)

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

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

t.sort()

memo = []
check = 1
for i in range(n-1):
    if t[i] == t[i+1] and i == n-2:
        check += 1
        memo.extend([t[i]]*(check//2))
    elif t[i] == t[i+1]:
        check += 1
    elif t[i] != t[i+1] and check>1:
        memo.extend([t[i]]*(check//2))
        check = 1

memo.sort(reverse=True)

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

Solution (Python):
from collections import defaultdict


def solve():
    _ = int(input())
    A = list(map(int, input().split()))
    
    counter = defaultdict(int)
    for ai in A:
        counter[ai] += 1
    
    first, second = 0, 0
    for key, val in counter.items():
        if 4 <= val:
            if first < key:
                first, second = key, key
            elif second < key:
                second = key
        elif 2 <= val:
            if first < key:
                first, second = key, first
            elif second < key:
                second = key
    ans = first * second
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
seq = sorted((int(x) for x in input().split()), reverse=True)
val1 = None
val2 = None
cur_val = seq[0]
for val in seq[1:]:
    if val == cur_val:
        if val1 is None:
            val1 = val
            cur_val = None
        elif val2 is None:
            val2 = val
            break
    else:
        cur_val = val
if val1 is None or val2 is None:
    print(0)
else:
    print(val1 * val2)

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

A.sort(key=lambda x: -x)

l = []

a_old = -1
for a in A:
    if a_old == a:
        l.append(a)
        a_old = -1
    else:
        a_old = a

l.append(0)
l.append(0)

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

Solution (Python):

from collections import Counter
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, A: "List[int]"):
    def g():
        ctr = Counter(A)
        for key in sorted(ctr.keys(), reverse=True):
            for _ in range(ctr[key] // 2):
                yield key
    gg = g()
    try:
        print(next(gg) * next(gg))
    except StopIteration:
        print(0)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    solve(N, A)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input().strip())
a = list(map(int, input().split()))
reps = []

a.sort()
tmp = 0
for e in a:
    if e == tmp:
        reps.append(e)
        tmp = 0
    else:
        tmp = e
if len(reps) < 2:
    print(0)
else:
    print(reps[-1] * reps[-2])

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

import collections

L = collections.Counter(a_L)

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

flag = 0

ans = 0
for k,v in L:
    
    if v>=4:
        ans = max(ans,k**2)

    if v >= 2:
        if flag== 0:
            tmp = k
            flag += 1
        elif flag == 1:
            ans = max(tmp*k,ans)
            
            
            print(ans)
            exit()

print(0)

Solution (Python):
from collections import Counter

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

c = Counter(a)  
cnt = [k for k, v in c.items() if v >= 2]

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

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter


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

W = H = 0
L = sorted(list(Counter(A).items()),key=lambda x:(-x[0]))
for k,v in L:
    if W == 0:
        if v >= 4:
            W = H = k
            break
        elif v >= 2:
            W = k
    elif H == 0:
        if v >= 2:
            H = k
            break

print(H*W)

Solution (Python):
from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]

A = Counter(a)
a_sorted = sorted(A.keys(), reverse=True)

ans = 0
tmp = 0
for i in a_sorted:
    if A[i] >= 4 and tmp == 0:
        ans = i**2
        break
    elif A[i] >= 2 and tmp == 0:
        tmp = i
    elif A[i] >= 2 and tmp != 0:
        ans = tmp * i
        break
print(ans)

Solution (Python):
import collections

n=int(input())
arr=list(map(int,input().split()))
cnt=collections.Counter(arr)
keys=cnt.keys()
keys=sorted(keys,reverse=True)
a=0
b=0
for key in keys:
  if b!=0:
    break
  if a==0:
    if cnt[key]>=2:
      a=key
      if cnt[key]>=4:
        b=key
  else:
    if cnt[key]>=2:
      b=key
print(a*b)

Solution (Python):
n = int(input())
a = sorted(list(map(int, input().split())))
a.reverse()
ans = []
c = 1
for i in range(1, n):
    if len(ans) >= 2:
        break
    if a[i] == a[i - 1]:
        c += 1
        m = a[i]
    else:
        if c >= 2:
            ans.append([a[i - 1], c])
        c = 1
if len(ans) < 2 and c >= 2:
    ans.append([a[n - 1], c])

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

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
b = []
i = 0
while i+1<N:
    if len(b)==2:
        break
    if a[i] == a[i+1]:
        b += [a[i]]
        i += 2
    else:
        i += 1

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

Solution (Python):
from collections import Counter
N = int(input())
stics = [int(i) for i in input().split()]

c = Counter(stics)

cnt = [k for k, v in c.items() if v >= 2]

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

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

exist_dict = {}
first_max = 0
second_max = 0

for i in l:
    if i in exist_dict:
        if exist_dict[i]==1 and i > first_max:
            second_max = first_max
            first_max = i
        elif exist_dict[i]==3 and i==first_max:
            second_max = i
        elif exist_dict[i]==1 and i > second_max:
            second_max = i
    
        exist_dict[i] = exist_dict[i] + 1
    else:
        exist_dict[i] = 1
    
    
    
print(first_max*second_max)

Solution (Python):
from collections import Counter

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

l = Counter(lines)

l = {k:v for k,v in l.items() if v>=2}

if len(l.keys()) <= 1:
  print(0)
else:
  anss = list(l.keys())
  ma  = max(anss)
  ma2 = sorted(anss)[-2]
  print(ma * ma2 if l[ma] < 4 else ma ** 2)

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

from collections import Counter
Aco = Counter(A)

ing = []
ing2 = []
for a in Aco.keys() :
    if Aco[a] >= 2 :
        ing.append(a)
    if Aco[a] >= 4 :
        ing2.append(a)

ing.sort(reverse = True)
ing2.sort(reverse = True)
if ing2 :
    if ing2[0] == ing[0] :
        print(ing2[0]**2)
        exit()

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

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

n = int(input())
a = list(map(int, input().split()))
cnt = 0
check = 0
ans = 1

a.sort(reverse=True)
for i in range(n - 1):
    if a[cnt] == a[cnt + 1]:
        check += 1
        ans *= a[cnt]
        cnt += 2
        if check == 2:
            print(ans)
            exit()
    else:
        cnt += 1

    if cnt == n - 1:
        break
print(0)

Solution (Python):
N = input()
a = input().split()
import numpy as np 
a = np.array(a).astype(int)
a.sort()
pai = -1
v = []
i = 0
for ai in a[::-1]:
    if pai == ai:
      v.append(ai)
      pai = -1
      i = i + 1
      if i >= 2:
          break
      continue
    pai = ai
if len(v) >= 2:
    print(v[0]*v[1])
else:
    print(0)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
d=Counter(a)
f=True
tt=0
ans=0
for i ,j in sorted(d.items(),reverse=True):
    if j==1:
        continue
    elif j>=4 and f:
        print(i*i)
        exit()
    else:
        f=False
        ans=tt*i
        tt=i
        if ans>0:
            break
print(ans)

Solution (Python):
n = int(input())
a = sorted(list(map(int,input().split())),reverse = True)
use = []
flag = -1
for i in range(n):
  if flag == a[i]:
    use.append(a[i])
    flag = -1
  else:
    flag = a[i]
if len(use)<2:
  print(0)
else:
  use.sort(reverse =True)
  print(use[0]*use[1])

Solution (Python):
n = int(input())
d = {}
for ai in input().split():
  ai = int(ai)
  if ai not in d:
    d[ai] = 0
  d[ai] += 1

n2 = [k for k in d if d[k] > 1]
n4 = [k for k in d if d[k] > 3]

n2.sort(reverse = True)
n4.sort(reverse = True)

ans = 0

if n4:
  ans = n4[0] ** 2

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

print(ans)

Solution (Python):
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
c = defaultdict(int)
for x in a:
  c[x] += 1

sq = False
top, sec = 0,0
for k,v in c.items():
    if v < 2:
        continue
    if k > top:
        sq = v >= 4
        sec = top
        top = k
    elif k > sec:
        sec = k

if sq:
    print(top * top)
else:
    print(top * sec)

Solution (Python):
def main():
    import sys
    
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations, permutations
    
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    

    

    N = int(input())
    A = list(map(int, input().split()))
    a = sorted(A, reverse=1)
    res1 = 0
    res2 = []
    for i in range(N-3):
        if a[i]==a[i+1]==a[i+2]==a[i+3]:
            res1 = a[i]
            break
    for i in range(N-1):
        if a[i]==a[i+1] and not a[i] in res2:
            res2.append(a[i])
        if len(res2)==2:
            break
    if len(res2)<2:
        print(res1**2)
    else:
        print(max(res1**2, res2[0]*res2[1]))



if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations, permutations
    
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    

    

    N = int(input())
    A = list(map(int, input().split()))
    a = sorted(A, reverse=1)
    res1 = 0
    res2 = []
    for i in range(N-3):
        if a[i]==a[i+1]==a[i+2]==a[i+3]:
            res1 = a[i]
            break
    for i in range(N-1):
        if a[i]==a[i+1] and not a[i] in res2:
            res2.append(a[i])
        if len(res2)==2:
            break
    if len(res2)==0:
        print(0)
    elif len(res2)==1:
        print(res1**2)
    else:
        print(max(res1**2, res2[0]*res2[1]))



if __name__ == '__main__':
    main()

Solution (Python):
import collections
n = int(input())
A = list(map(int, input().split()))
B = collections.Counter(A)
s = 0; t = 0
B = sorted(B.items(), key=lambda x:x[0], reverse=True)
se = 0
for i in B:
    if i[1] > 3 and se == 0:
        se = i[0]**2
    if i[1] > 1 and s == 0:
        s = i[0]
    elif i[1] > 1 and t == 0:
        t = i[0]
print(max(s*t, se))

Solution (Python):
import collections

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

c=collections.Counter(a)

MAX1=0
MAX2=0

for i,m in c.items():
    if m>=2 and m<4:
        if i>MAX1 and i>MAX2:
            if MAX1>MAX2:
                MAX2=i
            else:
                MAX1=i
        elif MAX1>i and i>MAX2:
            MAX2=i
        elif MAX2>i and i>MAX1:
            MAX1=i
    elif m>=4:
        if i>MAX1 and i>MAX2:
            MAX1=i
            MAX2=i
        elif MAX1>i and i>MAX2:
            MAX2=i
        elif MAX2>i and i>MAX1:
            MAX1=i

print(MAX1*MAX2)

Solution (Python):
import collections

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

c=collections.Counter(a)

MAX1=0
MAX2=0

for i,m in c.items():
    if m>=2 and m<4:
        if i>MAX1 and i>MAX2:
            if MAX1>MAX2:
                MAX2=i
            else:
                MAX1=i
        elif MAX1>i and i>MAX2:
            MAX2=i
    elif m>=4:
        if i>MAX1 and i>MAX2:
            MAX1=i
            MAX2=i
        elif MAX1>i and i>MAX2:
            MAX2=i

print(MAX1*MAX2)

Solution (Python):
from collections import Counter

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

A_=Counter(A)
A_=A_.most_common()
A_.sort(reverse=True)


ans=[]
cnt=0
for a in A_:
    if a[1]==2 or a[1]==3:
        ans.append(a[0])
        cnt+=1
    elif a[1]>=4:
        ans.append(a[0])
        cnt+=1
        if cnt==1:
            ans.append(a[0])
            cnt+=1
    if cnt>=2:
        break
if len(ans)<2:
    print(0)
    exit()
print(ans[0]*ans[1])

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

from collections import Counter

A.sort(reverse=True)
d = Counter(A)
d = d.most_common()
d.sort(reverse=True)
x = []

for i in range(len(d)):
    if d[i][1] >= 4:
        x.append(d[i][0])
        x.append(d[i][0])
    elif d[i][1] >= 2:
        x.append(d[i][0])
        
if len(x) < 2:
    print(0)
else:   
    print(x[0]*x[1])

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ans = []
a.sort(reverse=True)
key = a[0]
i = 1
while True:
    if i > n-1:
        break
    if len(ans) == 2:
        break
    if a[i] == key:
        i += 1
        ans.append(key)
        if i > n-1:
            break
        key = a[i]
    else:
        key = a[i]
    i += 1


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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
d = {}
for x in a:
    d[x] = d.get(x, 0) + 1
l = []
ans = 0
for num, cnt in sorted(d.items(), key=lambda x: x[0], reverse=True):
    if cnt > 3:
        if len(l) == 0:
            ans = num ** 2
            print(ans)
            exit()
        else:
            l.append(num)
            ans = l[0] * l[1]
            print(ans)
            exit()
    elif cnt > 1:
        l.append(num)
        if len(l) == 2:
            ans = l[0] * l[1]
            print(ans)
            exit()
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
d = {}
for x in a:
    d[x] = d.get(x, 0) + 1
d = sorted(d.items(), key=lambda x: x[0], reverse=True)

l = []
ans = 0
for num, cnt in d:
    if cnt > 1:
        l.append(num)
        if len(l) == 2:
            ans = l[0] * l[1]
            print(ans)
            exit()
    if cnt > 3:
        ans = num ** 2
        print(ans)
        exit()

print(ans)

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

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

def main():
    mod=10**9+7
    N=I()
    A=LI()
    from collections import defaultdict
    dd = defaultdict(int)
    
    for i in range(N):
        dd[A[i]]+=1
        
    L=[0,0]
    for k,v in dd.items():
        if v>=2:
            L.append(k)
        if v>=4:
            L.append(k)
            
        
    L.sort()
    print(L[-1]*L[-2])

main()

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

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def solve():
    n = II()
    a = LI()
    d = defaultdict(int)
    for ai in a:
        d[ai] += 1
    lis = list(d.items())
    ans = []
    for i,j in lis:
        for _ in range(j // 2):
            ans.append(i)
    ans.sort(reverse=True)
    if len(ans) < 2:
        print(0)
    else:
        print(ans[0]*ans[1])

    return



if __name__ == '__main__':
    solve()

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

Solution (Python):
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)
h,w,i=0,0,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)

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

A.sort(reverse=True)
edges = 2
cnt = 1
ans = 1
for i in range(N-1):
    if A[i] == A[i+1]:
        cnt += 1
        continue
    if edges == 2 and cnt >= 4:
        edges -= 2
        ans *= A[i] * A[i]
    elif cnt >= 2:
        edges -= 1
        ans *= A[i]
    if edges == 0:
        break
    cnt = 1
if edges == 2 and cnt >= 4:
    edges -= 2
    ans *= A[i] * A[i]
elif edges == 1 and cnt >= 2:
    edges -= 1
    ans *= A[i]
if edges == 0:
    print(ans)
else:
    print(0)

Solution (Python):
from collections import Counter
import sys
n = int(input())
a = list(map(int, input().split()))
count_a = list(Counter(a).items())
count_a = sorted(count_a, reverse=True)
result = 1
c = 0
for x, y in count_a:
    if y>=2:
        result *= x
        c += 1
        if c == 1 and y>=4:
            result *= x
            c += 1
        if c == 2:
            print(result)
            sys.exit()
print(0)

Solution (Python):
from collections import Counter
import sys
n = int(input())
a = list(map(int, input().split()))
count_a = list(Counter(a).items())
count_a = sorted(count_a, reverse=True)
result = 1
c = 0
for x, y in count_a:
    if y>=2:
        result *= x
        c += 1
        if y>=4 and c == 1:
            result *= x
            c += 1
        if c == 2:
            print(result)
            sys.exit()
print(0)

Solution (Python):
from collections import Counter
import sys
n = int(input())
a = list(map(int, input().split()))
count_a = list(Counter(a).items())
count_a = sorted(count_a, reverse=True)
result = 1
c = 0
for x, y in count_a:
    if y>=2:
        result *= x
        c += 1
        if y>=4 and c == 1:
            result *= x
            c += 1
    if c == 2:
        print(result)
        sys.exit()
print(0)

Solution (Python):
import collections

n = int(input())
a = [int(_) for _ in input().split()]
aa = collections.Counter(a).most_common()
aa = sorted(aa, reverse=True)
length = []
cnt = 0
for i in aa:
    if i[1] >= 2:
        length.append(i)
        cnt += 1
        if cnt == 2:
            break
    else:
        pass

if cnt == 2 and length[0][1] >= 4:
    print(length[0][0] * length[0][0])
elif cnt == 2:
    print(length[0][0] * length[1][0])
elif cnt == 1 and length[0][1] >= 4:
    print(length[0][0] * length[0][0])
else:
    print(0)

Solution (Python):
def main():
    _ = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    li = [(k, v) for k, v in c.items() if v >= 2]
    li.sort(reverse=True)
    if li and li[0][1] >= 4:
        print(li[0][0] * li[0][0])
    elif len(li) <= 1:
        print(0)
    else:
        print(li[0][0] * li[1][0])


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=Counter(a)
m=c.most_common()
t=sorted(m,key=lambda m:m[0],reverse=True)
w=0
b=0
for i in range(len(t)):
    if(t[i][1]>=4):
        if(w==b==0):
            w=t[i][0]
            b=t[i][0]
        elif(w==0):
            w=t[i][0]
        elif(b==0):
            b=t[i][0]
    elif(t[i][1]>=2):
        if(w==0):
            w=t[i][0]
        elif(b==0):
            b=t[i][0]
print(w*b)