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)
ans=[]
i=0
while i<n-1:
    if a[i]==a[i+1]:
        ans.append(a[i])
        i+=1
    i+=1
if len(ans) >= 2:
    print(ans[0]*ans[1])    
else:
    print(0)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.sort()
A.reverse()
flagBIG = 0
BIG = 0
SMALL = 0
i=1
while i<N:
    if A[i] == A[i-1] and flagBIG == 1:
        SMALL = A[i]
        break
    if A[i] == A[i-1] and flagBIG == 0:
        BIG = A[i]
        flagBIG = 1
        i = i+1
    i=i+1
if BIG!= 0 and SMALL!=0:
    print(BIG*SMALL)
else:
    print(0)

Solution (Python):
import collections
N=int(input())
A=[int(x) for x in input().split()]
C=collections.Counter(A)
C=sorted(list(C.items()),reverse=True)
li=[]
for i,j in C:
  if j>=4:
    li.append(i)
    break
  if j>=2:
    li.append(i)
  if len(li)==2:
    break
if len(li)==0:
  print(0)
if len(li)==1:
  print(li[0]**2)
if len(li)==2:
  print(li[0]*li[1])

Solution (Python):
n=int(input())
D={}
a_list=list(map(int,input().split()))
for i in a_list:
    if not i in D:
        D[i]=1
    else:
        D[i]+=1
l1=0
l2=0
for i in D:
    if D[i]>=2:
        if D[i]<4:
            if i>l1:
                temp=l1
                l1=i
                l2=max(temp,l2)
            else:
                l2=max(i,l2)
        else:
            if i>l1:
                temp=l1
                l1=i
                l2=max(temp,l2)
            else:
                l2=max(i,l2)
            if i>l1:
                temp=l1
                l1=i
                l2=max(temp,l2)
            else:
                l2=max(i,l2)
print(l1*l2)

Solution (Python):



from collections import Counter

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

a = Counter(a)
a = list(a.items())

b = []

for i,j in a:
    if j >= 2:
        b.append(i)
        if j >= 4:
            b.append(i)
b.sort()
if len(b) < 2:
    print(0)
else:
    x = b[-1]
    y = b[-2]
    print(x*y)

Solution (Python):



from collections import Counter

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

a = Counter(a)
a = list(a.items())

b = []

for i,j in a:
    if j >= 2:
        b.append(i)
        if j >= 4:
            b.append(i)
b.sort()
if len(b) < 2:
    print(0)
else:
    x = b[-1]
    y = b[-2]
    print(x*y)

Solution (Python):
from collections import*
n,*a=map(int,open(0).read().split())
d=defaultdict(int)
l=[]
for i in a:
    if d[i]%2:l.append(i)
    d[i]+=1
if len(l)>1:
    *_,a,b=sorted(l)
    print(a*b)
else:
    print(0)

Solution (Python):
from collections import*
n,*a=map(int,open(0).read().split())
d=defaultdict(int)
l=[]
for i in a:
    if d[i]%2:l.append(i)
    d[i]+=1
if len(l)>1:
    *_,a,b=sorted(l)
    print(a*b)
else:
    print(0)

Solution (Python):
n = int(input())
a = sorted(list(map(int,input().split())))
x,y,i=0,0,0
while i<n:
  if a[i-1]==a[i]:
    x,y=y,a[i]
    i+=1
  i+=1
print(x*y)

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

hen = [0, 0]
i, j = 0, 0
while i<n:
    if a[i]==a[i-1]:
        hen[j] = a[i]
        j = (j+1)%2
        i += 1
    i += 1
print(hen[0]*hen[1])

Solution (Python):

def C():
    n = int(input())
    a = sorted(list(map(int,input().split())),reverse=True)
    i=0
    longer = 0
    shorter = 0
    while i < len(a)-1:
        if a[i] == a[i+1]:
            if longer == 0:
                longer = a[i]
                i+=1
            elif shorter == 0:
                shorter = a[i]
                i+=1
        i+=1
    print(longer*shorter)
C()

Solution (Python):

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

for i in range(N-1):
    if A[i] == A[i+1]:
        A[i+1] = 0
    elif A[i] != A[i+1]:
        A[i] = 0
A.sort(reverse = True)
print(A[0] * A[1])

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
for i in range(n-1):
    if a[i]==a[i+1]:
        a[i+1]=0
    elif a[i]!=a[i+1]:
        a[i]=0
a=sorted(a,reverse=True)
print(a[0]*a[1])

Solution (Python):
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

ac = list(sorted([(a, c) for a, c in Counter(A).items() if c >= 2]))
if len(ac) >= 2:
    if ac[-1][1] >= 4:
        print(ac[-1][0] ** 2)
    else:
        print(ac[-1][0] * ac[-2][0])
else:
    print(0)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
d = {}
for c in a:d[c]=d.get(c,0)+1
l = []
sq = []
for k in d.keys():
    if d[k]>=4:sq.append(k)
    if d[k]>=2:l.append(k)

area = 0
if len(sq)>=1:
    area = max(sq) * max(sq)

if len(l)>=2:
    l1 = sorted(l,reverse = True)
    area = max(area,l1[0]*l1[1])
    print(area)
else:print(0)

Solution (Python):

N = int(input())

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

dic = {}
lis = []


for i in A:

    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
        lis.append(i)

lis.sort()
lis.reverse()

L = 0
S = 0

for i in lis:

    if L != 0 and S != 0:
        break

    if dic[i] >= 4:

        L = max(L,i)
        S = max(S,i)

    elif dic[i] >= 2 and L == 0:

        L = i

    elif dic[i] >= 2 and S == 0:

        S = i

print (L*S)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
d={}
l=[]
ll=[]
for i in range(len(a)):
    d[a[i]]=d.get(a[i],0)+1
for i in d.keys():
    if d[i]>=2:
        l.append(i)
    if d[i]>=4:
        ll.append(i)

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

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

dict={}

for i in range(n):
    if not a[i] in dict:
        dict[a[i]]=0
    dict[a[i]]+=1


a=sorted(dict.items(), key=lambda x:x[0])
one=0
two=0
for i in range(len(a)):
    if a[i][1]>3:
            one=a[i][0]
            two=one

    elif a[i][1]>1:
        two=one
        one=a[i][0]
    
print(one*two)

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

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

A.sort()
A = A[::-1]
ans = 0
counter = 0
buff = []
flag = False
for i in range(0, N-1):
    if flag:
        flag = False
        continue
    if A[i] == A[i+1]:
        buff.append(A[i])
        flag = True
        counter += 1
        if counter >= 2:
            print(buff[0]*buff[1])
            exit()

print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
D,L={},[0,0]
for a in A:
    if a not in D:D[a]=1
    else:
        L.append(a)
        del D[a]
L.sort(reverse=True)
print(L[0]*L[1])

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

from collections import defaultdict
d = defaultdict(int)

for i in input().split():
    d[int(i)] += 1

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

longest=0
for length, n in d_sorted:
    if n>=2 and longest!=0:
        print(longest*length)
        exit()
    elif n>=4 and longest==0:
        print(length**2)
        exit()
    elif n>=2 and longest==0:
        longest=length
print(0)

Solution (Python):

from collections import Counter


def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    cnt = sorted(
        {k: v for k, v in Counter(lst).items() if v >= 2}.items(), reverse=True
    )
    if cnt == []:
        print(0)
    elif cnt[0][1] >= 4:
        print(cnt[0][0] ** 2)
    else:
        print(cnt[0][0] * cnt[1][0])


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    i = 0
    d = [0, 0]
    while N - 1 > i:
        if A[i] == A[i + 1]:
            d.append(A[i])
            i += 1
        i += 1
    print(d[-1] * d[-2])


main()

Solution (Python):
def main():
    N = int(input())
    A = sorted(list(map(int, input().split())), reverse=True)
    i = 0
    d = []
    while N - 1 > i:
        if len(d) == 2:
            break
        if A[i] == A[i + 1]:
            d.append(A[i])
            i += 1
        i += 1
    if (len(d) == 2):
        print(d[0] * d[1])
    else:
        print(0)


main()

Solution (Python):
n=int(input())
al=list(map(int,input().split()))
al.sort(reverse=True)
cnt=0
h=0
w=0
t=set()
for a in al:
    if a in t:
        if h==0:
            h=a
        else:
            w=a
            break
        t.remove(a)
    else:
        t.add(a)
print(h*w)

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

from collections import defaultdict
d = defaultdict(int)
for i in range(n):
    d[a[i]]+=1

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

ans = []
for i in range(n):
    if d[i][1]>=4 and len(ans)==0:
        ans.append(d[i][0])
        ans.append(d[i][0])
    if len(ans)==2:
        break

    if d[i][1]>=2:
        ans.append(d[i][0])
        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()))
A.sort(reverse=True)
x=0
y=0
tmp=0
for a in A:
    if tmp==a:
        if not(x):
            x=a
            tmp=0
        else:
            y=a
            tmp=0
    else:
        tmp=a
    if x and y:
        break
print(x*y)

Solution (Python):
from collections import Counter

def main():
    num = int(input())
    data = Counter(list(map(int, input().split())))
    score_sorted = sorted(data.items(), key=lambda x: -x[0])

    ans = []
    for ele, kosuu in score_sorted:
        if kosuu >= 2:
            if len(ans) == 0 and kosuu >= 4:
                ans = [ele, ele]
                break
            else:
                ans.append(ele)
                if len(ans) == 2:
                    break
    if len(ans) == 2:
        print(ans[0] * ans[1])
    else:
        print(0)



if __name__ == '__main__':
    main()

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

A.sort(reverse = True)

A += [0]
count = 1
lst = []
for i in range(1, N+1):
    if A[i] == A[i-1]:
        count += 1
    else:
        lst += [[A[i-1], count]]
        count = 1

ans = 1
flag = 0
for i in range(len(lst)):
    if lst[i][1] >= 2:
        ans *= lst[i][0]
        flag += 1
        if flag == 2:
            print (ans)
            sys.exit()
        if lst[i][1] >= 4:
            ans *= lst[i][0]
            print (ans)
            sys.exit()

print (0)

Solution (Python):
from collections import Counter
N = int(input())
A = [int(x) for x in input().split()]
pair = []
c = Counter(A)
for x,cnt in c.items():
  pair += [x]*(cnt//2)

pair.sort()

answer = 0
if len(pair)>= 2:
  answer = pair[-1] * pair[-2]

print(answer)

Solution (Python):

import sys


def solve(N: int, A: "List[int]"):
    A.sort(reverse=True)
    i = 0
    tmp = []
    while i < N- 1:
        if A[i] == A[i + 1]:
            tmp.append(A[i])
            i += 1
        i += 1
    if len(tmp) > 1:
        ret = tmp[0] * tmp[1]
    else:
        ret = 0
    print(ret)
    return


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



from collections import defaultdict

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

d = defaultdict(int)
for a in A:
    d[a] += 1

count = 0
sorted_keys = sorted(d.keys(), key=lambda x: -x)
has_choiced = False
h = 0
v = 0
for key in sorted_keys:
    if has_choiced == False and d[key] >= 4:
        h = key
        v = key
        break
    elif has_choiced == True and d[key] >= 4:
        v = key
        break
    elif has_choiced == True and d[key] >= 2:
        v = key
        break
    elif has_choiced == False and d[key] >= 2:
        h = key
        has_choiced = True
        
print(h * v)

Solution (Python):
n=int(input())
dic=dict()
l=list(map(int,input().split()))
for i in l:
	if i not in dic.keys():
		dic[i]=1
	else:
		dic[i]+=1
p=[k for k,v in dic.items() if v>=2]
f=0
s=0
for i in p:
	if i>f:
		f,s=i,f
	elif i>s:
		s=i
print(0 if f==0 else f**2 if dic[f]>=4 else f*s)

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

dic = {}
xy = []
for a in A:
    if a in dic:
        dic[a] += 1
        if dic[a] == 2:
            xy.append(a)
            dic[a] = 0
    else:
        dic[a] = 1
xy.sort(reverse = True)
if len(xy) < 2:
    print(0)
else:
    print(xy[0]*xy[1])

Solution (Python):
N = int(input())
tmp = input().split(" ")

als = []


for t in tmp:
    als.append(int(t))

als.sort(reverse = True)

rec_w = 0
prev = 0
for a in als:
    if rec_w:
        
        if a == prev:
            print(a*rec_w)
            exit()
        else:
            prev = a
    else:
        if a == prev:
            rec_w = a
            prev = 0
        else:
            prev = a

print(0)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

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

def main():
  n=I()
  l=LI()

  l.sort()

  a=[]
  b=[]
  for x in l:
    if len(a)>0:
      if x==a[-1]:
        a.pop()
        b.append(x)
      else:
        a.pop()
        a.append(x)
    else:
      a.append(x)

  b.sort()

  if len(b)<2:
    return 0

  return b[-1]*b[-2]

print(main())

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse = True)
edge = [0, 0]
index = 0
tmp = 0
for i in range(0, N):
	if 2 <= index: break
	if tmp == A[i]:
		edge[index] = A[i]
		tmp = 0
		index += 1
	else:
		tmp = A[i]
print(edge[0]*edge[1])

Solution (Python):
n = int(input())
ans = 0
num_list = sorted([ int(v) for v in input().split() ],reverse = True)

a, b = -1, -1
d = 0

for i in range(n-1):
	if num_list[i] != num_list[i+1]:
		d = 0
	else:
		if a != -1 and d == 0:
			b = num_list[i]
			ans = a*b
			break
		else:
			d += 1
			a = num_list[i]
			if d == 3:
				ans = a**2
				break

print(ans)

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

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

length = sorted(length)
length.append(0)

temp = length[0]
c = 1

unique_n = []
square = []

for i in range(n):
    if temp == length[i+1]:
        c += 1
    
    else:
        if c >= 2 :
            unique_n.append(length[i-1])
        
        if c >= 4:
            square.append(length[i-1])
            
        
        c = 1
        temp = length[i+1]

if len(unique_n) <= 1:
    print(0)

else:
    if len(square) >= 1:
        print(max(unique_n[-1]*unique_n[-2],(square[-1])**2))
    
    else:
        print(unique_n[-1]*unique_n[-2])

Solution (Python):
from collections import Counter

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

ac = Counter(a)

cur_a = 0
res = 0

for a,c in ac.items():
	
	if c < 2:
		continue
	else:
		res = max(res,cur_a*a)
		cur_a = max(cur_a,a)
		if c >= 4:
			res = max(res,a*a)
	
print(res)

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())
n = readi()
t = readl()
s = defaultdict(int)
for i in t:
    s[i] += 1

t1 = 0
t2 = 0
for i in sorted(s.items(),reverse=True,key=lambda x:x[0]):
    if t1 == 0:
        if i[1] >= 4:
            t1 = i[0]
            t2 = i[0]
            break
        elif i[1] >= 2:
            t1 = i[0]
    elif t2 == 0:
        if i[1] >= 2:
            t2 = i[0]
            break
print(t1 * t2)

Solution (Python):
from collections import *

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

filtered_a = sorted([i for i in Counter(a).most_common() if i[1] >= 2], reverse=True)

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

Solution (Python):
import collections
N=int(input())
A=list(map(int,input().split()))
B=collections.Counter(A).most_common()
B.sort(key= lambda x : -x[0])
L=[]
for i in B:
    if i[1]>=4:
        L.append(i[0])
        L.append(i[0])
    elif i[1]>=2:
        L.append(i[0])
    if len(L)==2:
        break
print(L[0]*L[1] if len(L)>=2 else 0)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
from collections import defaultdict
d=defaultdict(int)
for i in a:
    d[i]+=1
a=sorted(list(d.items()),key=lambda x:x[0])
p=0
ans=0

while a:
    c=a.pop()
    if c[1]<2:
        continue
    if c[1]>=4:
        ans=max(c[0]**2,ans)
        p=max(p,c[0])
    if c[1]>=2:
        if p==0:
            p=max(c[0],p)
        else:
            ans=max(p*c[0],ans)
            
print(ans)

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

def main():
    e = {}
    for n in A:
        if not n in e.keys():
            e[n] = 0
        e[n] += 1

    fe = {k:v for k, v in e.items() if v >= 2}
    se = sorted(fe.items(), key=lambda o: o[0], reverse=True)
    if len(se) == 0:
        ans = 0
    elif se[0][1] >= 4:
        ans = se[0][0] ** 2
    elif len(se) == 1:
        ans = 0
    else:
        ans = se[0][0] * se[1][0]
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):

import sys

from bisect import bisect_left, bisect_right


def count(seq, element):
    "Return number of occurrences of item"
    i = bisect_left(seq, element)
    j = bisect_right(seq, element)
    return seq[i:j].count(element)


def solve(N: int, A: "List[int]"):
    flag = 0
    ans = 1
    seta = sorted(list(set(A)))
    sa = sorted(A)
    for a in reversed(seta):
        if count(sa, a) >= 4:
            if flag == 1:
                ans *= a
                print(ans)
                return
            ans = a * a
            print(ans)
            return
        elif count(sa, a) >= 2:
            flag += 1
            ans *= a
            if flag == 2:
                print(ans)
                return
    print(0)
    return



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):
from collections import Counter
N, *a = map(int, open(0).read().split())

c = Counter(a).most_common()
c = sorted([[i, j // 2] for i, j in c], reverse=True)
ans = 1
cnt = 0
for i in range(len(c)):
    a, v = c[i]
    while v > 0:
        ans *= a
        cnt += 1
        v -= 1
        if cnt == 2:
            break
    if cnt == 2:
      break
            
print(ans if cnt == 2 else 0)

Solution (Python):
from collections import Counter

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

A_cnt = list(Counter(A).items())
A_cnt.sort(key=lambda x:x[0], reverse=True)

sides = []
for i in range(len(A_cnt)):
  if A_cnt[i][1] >= 4:
    sides.extend([A_cnt[i][0]]*2)
  elif A_cnt[i][1] >= 2:
    sides.append(A_cnt[i][0])
  if len(sides) >= 2:
    break

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

Solution (Python):
from collections import Counter
n = int(input())
a = Counter(list(map(int, input().split())))
edge = []
for key, value in a.items():
    if value > 1:
        edge.append(key)
    if value > 3:
        edge.append(key)
edge.sort()
print(edge[-1] * edge[-2] if len(edge) > 1 else 0)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
count = {}
for i in a:
    if i not in count:
        count[i] = 1
    else:
        count[i] += 1
first = 0
for i, c in sorted(count.items(), key = lambda x: x[0], reverse = True):
    if c >= 4 and not first:
        print(i * i)
        exit()
    elif c >= 2:
        if first:
            print(first * i)
            exit()
        else:
            first = i
print(0)

Solution (Python):
N = int(input())
lst_A = list(map(int, input().split()))
lst_A.sort(reverse=True)
cur_a = -1
lst_ans = []


for a in lst_A:
    
    if cur_a == a:
        lst_ans.append(a)
        cur_a = -1
        if len(lst_ans) == 2:
            break
    
    else:
        cur_a = a


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

Solution (Python):
N = int(input())
lst_A = list(map(int, input().split()))
lst_A.sort(reverse=True)
cur_a = -1
lst_ans = []


for a in lst_A:
    if cur_a == a:
        lst_ans.append(a)
        cur_a = -1
        if len(lst_ans) == 2:
            break
    else:
        cur_a = a


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

Solution (Python):
N = int(input())
lst_A = list(map(int, input().split()))
lst_A.sort(reverse=True)
cur_a = -1
lst_ans = []


for i, a in enumerate(lst_A):
    if cur_a == a:
        lst_ans.append(a)
        cur_a = -1
        if len(lst_ans) == 2:
            break
    else:
        cur_a = a


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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
prev = -1
ans = []
for i, a in enumerate(A):
    if prev == a:
        ans.append(a)
        prev = -1
        if len(ans) == 2:
            break
    else:
        prev = a
if len(ans) == 2:
    print(ans[0] * ans[1])
else:
    print(0)

Solution (Python):


import math
from collections import defaultdict


int(input())
Ln = [0, 0]
mydict = defaultdict(lambda:0)
for a in list(map(int, input().split())):
  mydict[a] += 1
  if mydict[a] == 2:
    Ln.append(a)
    mydict[a] = 0
Ln = sorted(Ln,reverse=True)
print(Ln[0]*Ln[1])

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

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

Solution (Python):

N = int(input())
A = list(map(int, input().split()))
A.sort()
tmp = [0,0]
for i in range(len(A)-1):
    if A[i] == A[i+1] and not A[i] in tmp:
        tmp.append(A[i])
ans = tmp[-1]*tmp[-2]
if A.count(tmp[-1]) >=4:
        ans = tmp[-1]*tmp[-1]
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
A_cnt = Counter(A)
ans_list = []
for key, val in A_cnt.items():
    if val >= 2:
        ans_list.append(key)
    if val >= 4:
        ans_list.append(key)
if len(ans_list)>=2:
    ans_list.sort()
    print(ans_list[-1]*ans_list[-2])
else:
    print(0)

Solution (Python):
import collections
N=int(input())
a=collections.Counter(map(int, input().split())).items()
b=sorted([n for n in a if n[1] > 3], reverse=True)
c=sorted([n for n in a if n[1] > 1], reverse=True)
print(max([b[0][0] ** 2 if len(b) > 0 else 0, c[0][0] * c[1][0] if len(c) > 1 else 0]))

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

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



kouho = 0
for a in sorted(asum)[::-1]:
	if 4 <= asum[a]:
		if kouho:
			print(kouho * a)
		else:
			print(a * a)
		break
	elif 2 <= asum[a]:
		if kouho:
			print(kouho * a)
			break
		else:
			kouho = a
else:
	print(0)

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

Solution (Python):
from collections import defaultdict

def read_input():
    n = int(input())
    alist = map(int, input().split())

    return n, alist


def submit():
    n, alist = read_input()

    sides = defaultdict(int)
    for a in alist:
        sides[a] += 1

    sides = list(sides.items())
    sides.sort(key=lambda x: x[0], reverse=True)

    sides_four = [s for s in sides if s[1] >= 4]
    square = 0
    if sides_four:
        square = sides_four[0][0] * sides_four[0][0]

    sides_two = [s for s in sides if s[1] >= 2]
    rectangle = 0
    if len(sides_two) >= 2:
        rectangle = sides_two[0][0] * sides_two[1][0]

    print(max(square, rectangle))


if __name__ == '__main__':
    submit()

Solution (Python):
from functools import reduce
import collections
import math

def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    N = int(input())
    a = list(int(_) for _ in input().split())
    d = collections.defaultdict(int)
    for i in range(N):
        d[a[i]]+=1

    e_1 = 0
    e_2 = 0
    for d_i in sorted(d.items(),key=lambda x:-x[0]):
        if d_i[1] >= 4 and e_1 == 0:
            e_1 = d_i[0]
            e_2 = d_i[0]
            break
        elif d_i[1] >= 2 and e_1 == 0:
            e_1 = d_i[0]
        elif d_i[1] >= 2 and e_2 == 0:
            e_2 = d_i[0]
            break
    print(e_1 * e_2)
    
if __name__ == '__main__':
    main()

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

E.sort(reverse=True)
pre = 0
nums = []
for e in E:
    if pre == e:
        nums.append(e)
        pre = 0
    else:
        pre = e
    if len(nums) == 2:
        print(nums[0]*nums[1])
        quit()
print(0)

Solution (Python):
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
c=list(Counter(A).most_common())
c.sort(key=lambda x:x[0],reverse=True)
w=0
h=0
for a,b in c:
    if(b>=4):
        if(w==0):
            w=a
            h=a
            break
        else:
            h=a
            break
    if(b>1):
        if(w==0):
            w=a
        else:
            h=a
            break
print(w*h)

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

n = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
l = c.most_common()
L = [ l[i] for i in range(len(l)) if l[i][1] >= 2 ]
b = sorted(L,reverse = True)
if len(b) == 0:
    ans = 0
elif len(b) == 1 and b[0][1] < 4:
    ans = 0
else:
    if b[0][1] >= 4:
        ans = b[0][0]**2
    else:
        ans = b[0][0]*b[1][0]
print(ans)

Solution (Python):

import sys
try:
    from math import gcd
except Exception:
    from fractions import gcd
from collections import Counter

def solve(N: int, A: "List[int]"):
    tmp = [(i,c) for i, c in Counter(A).items() if 2 <= c]
    tmp = sorted(tmp, reverse=True)
    if 2 <= len(tmp):
        return (tmp[0][0] ** 2) if 4 <= tmp[0][1] else (tmp[0][0] * tmp[1][0])
    else:
        return 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) ]  
    result = solve(N, A)
    print(result)

if __name__ == '__main__':
    main()

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

d = dict()

for a in A:
    if a in d.keys():
        d[a] += 1
    else:
        d[a] = 1

d2 = sorted(d.items(), reverse=1)

first = 0
for i,j in d2:
    if d[i] >= 2:
        if first == 0 and d[i] >= 4:
            print(i**2)
            exit()
        elif first != 0:
            print(first*i)
            exit()
        else:
            first = i
print(0)

Solution (Python):
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
ct = list(Counter(A).items())
flg = 0
ct. sort(key=lambda x: x[0], reverse=True)
for i in ct:
    if i[1] >= 4 and flg == 0:
        flg = 2
        ans = i[0]**2
        break
    if i[1] >= 2 and flg == 0:
        flg = 1
        ans = i[0]
    elif i[1] >= 2 and flg == 1:
        flg = 2
        ans *= i[0]
        break

if flg != 2:
    print(0)
else:
    print(ans)

Solution (Python):

import copy
import random
import bisect 
import math


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

A.sort()
len_dic = {}
for a in A:
    if a in len_dic.keys():
        len_dic[a] += 1

    else:
        len_dic[a] = 1

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

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

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

A.sort(reverse=True)

check = int(2e9)
bar = []
for i in A:
    if check == i:
        bar.append(i)
        check = int(2e9)
    else:
        check = i
    if len(bar) == 2:
        break

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

Solution (Python):
import itertools
import heapq
import functools
import operator

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

desc_lengths = list(
  itertools.chain(
    *(
      [length, length] if count >= 4 else [length] if count >= 2 else []
      for (length, count)
      in [
        (length, sum(1 for _ in iter))
        for (length, iter)
        in itertools.groupby(sorted(a))
      ]
    )
  )
)
print(functools.reduce(operator.mul, heapq.nlargest(2, desc_lengths)) if len(desc_lengths) >= 2 else 0)

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

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

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

a = 0
b = 0

for i in range(len(nums_list_sorted)):
  if nums_list_sorted[i][1] >= 2:
    if a == 0:
      a = nums_list_sorted[i][0]
      if nums_list_sorted[i][1] >= 4:
        b = a
        break
      
    else:
      b = nums_list_sorted[i][0]
      break

print(a*b)