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):
def main():
    from collections import Counter
    n, *a = map(int, open(0).read().split())
    b = Counter(a)
    *c, = map(lambda x: tuple(x), b.items())
    c.sort(key=lambda x: x[0], reverse=True)

    ans = 1
    count = 0
    for (k, v) in c:
        if v >= 4 and ans == 1:
            ans = k ** 2
            count += 2
            break
        if v >= 2:
            ans *= k
            count += 1
        if count == 2:
            break
    if count < 2:
        print(0)
    else:
        print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

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

cnt = Counter(A)
rect = []

for i,j in zip(cnt.keys(),cnt.values()):
    if j >= 2:
        rect.append([i,j])

rect.sort(reverse=True)

ans = 0
flag = False
finished = False
for i,j in rect:
    if flag:
        ans *= i
        finished = True
        break
    elif j < 4:
        ans = i
        flag = True
    else:
        ans = i**2
        finished = True
        break

print(0 if not finished else ans)

Solution (Python):
from collections import Counter
input()
angles = sorted(((key, value) for key, value in Counter(map(int, input().split())).items() if value > 1), key=lambda t: t[0])
try:
    square = angles[-1][0] ** 2 if angles[-1][1] > 3 else angles[-1][0] * angles[-2][0]
except:
    square = 0
print(square)

Solution (Python):
N = int(input())
List = list(map(int,input().split()))
List_t = []
List_q = []
List.sort()
for x in range(N-1):
  if List[x]==List[x+1]:
    List_t.append(List[x])
for x in range(N-3):
  if List[x]==List[x+1]==List[x+2]==List[x+3]:
    List_q.append(List[x])

if len(List_q) == 0:
  if len(List_t)<=1:
    print(0)
  else:
    M = sorted(set(List_t))[-1]
    m = sorted(set(List_t))[-2]
    print(M*m)
else:
  M_q = sorted(set(List_q))[-1]
  M_t = sorted(set(List_t))[-1]
  m = sorted(set(List_t))[-2]
  print(max([M_q**2,M_t*m]))

Solution (Python):
import sys
from collections import Counter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=sorted(lmp(),reverse=True)
i=0
l=[]
while i<n-1:
    if a[i]==a[i+1]:
        l.append(a[i])
        i+=1
    i+=1
if len(l)>=2:
    print(l[0]*l[1])
else:
    print(0)

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

Solution (Python):
import collections

n=int(input())
a=list(map(int,input().split()))
num=collections.Counter(a)
cnt=num.most_common()
if cnt[0][1]<=1:
    print(0)
    exit()
else:
    if cnt[1][1]<=1:
        print(0)
        exit()
    numlis=[]
    for i in cnt:
        if i[1]>=2:
            numlis.append(i)
        else:
            break
    numlis=[list(a) for a in numlis]
    numlis.sort(reverse=True)
    if numlis[0][1]>=4:
        print(numlis[0][0]**2)
    else:
        print(numlis[0][0]*numlis[1][0])

Solution (Python):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
x1=0
x2=0
count=Counter(a)
for i in count:
  if count[i]>=4:
    if x1<=i:
      x2=i
      x1=i
  if count[i]>=2:
    if x1<=i:
      x2=x1
      x1=i
    elif x2 <= i < x1:
      x2=i
print(x1*x2)

Solution (Python):
n = int(input())
A = sorted(list(map(int, input().split())), reverse = True)
l = 0
ln = []
for a in A:
    if l == a:
        ln.append(a)
        l = 0
    else:
        l = a
    if len(ln) == 2:
        break
if len(ln) == 2:
    print(ln[0]*ln[1])
else:
    print(0)

Solution (Python):


N = int(input())


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

def main():
    cnt = Counter(A).items()
    koho_2 = []
    koho_4 = []
    for k, v in cnt:
        if v >= 4:
            koho_4.append(k)
        if v >= 2:
            koho_2.append(k)
    ans = [0]
    koho_2 = sorted(koho_2)[::-1]
    koho_4 = sorted(koho_4)[::-1]
    if len(koho_2) >= 2:
        ans.append(koho_2[0] * koho_2[1])
    if len(koho_4) >= 1:
        ans.append(koho_4[0] ** 2)
    print(max(ans))

if __name__ == "__main__":
    main()

Solution (Python):
def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	t = dict()
	for i in a:
		if t.get(i):
			t[i] += 1
		else:
			t[i] = 1
	a, b = 0, 0
	for k in t:
		if t[k] >= 4:
				a = max(a, k)
				b = max(b, k)
		elif t[k] >= 2:
			if k > a:
				b = a
				a = k
	print(a*b)
resolve()

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

n = int(input())
a = list(map(int,input().split()))
c = collections.Counter(a)
li2 = [0,0]
li4 = [0]
for key,value in c.items():
    if value>=4:
        li4.append(key)
    elif value>=2:
        li2.append(key)
li2.sort()
li4.sort()
ans1 = li2[-1]*li2[-2]
ans2 = li4[-1]**2
ans3 = li4[-1]*li2[-1]
ans = max(ans1,ans2)
ans = max(ans,ans3)
print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A = sorted(A, reverse = True)
t = 0
y = 0
cnt = 0
for i in range(len(A)-1):
    if A[i] == A[i+1]:
        t = A[i]
        break
    cnt += 1
for j in range(len(A)-1):
    if A[j] == A[j+1] and j >= cnt+2:
        y = A[j]
        break
print(t*y)

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

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

adic=defaultdict(int)
for a in alist:
  adic[a]+=1
alist2=list(adic.items())
alist2.sort(reverse=True)


x1,x2=0,0
for a2 in alist2:
  if a2[1]>=4:
    x1=max(x1,a2[0])
    x2=max(x2,a2[0])
  elif a2[1]>=2:
    if x1==0:
      x1=a2[0]
    else:
      x2=a2[0]

  if x1*x2>0:
    print(x1*x2)
    break
else:
  print(0)

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

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

alist = sorted(adic.items(),reverse = True)
before = 0
after = 0

for i in range(len(alist)):
    if before == 0:
        if alist[i][1] >= 4:
            before = alist[i][0]
            after = alist[i][0]
            break
        elif alist[i][1] >= 2:
            before = alist[i][0]
    else:
        if alist[i][1] >= 2:
            after = alist[i][0]
            break
print(before * after)

Solution (Python):
import collections
n = int(input())
p = list((map(int,input().split())))
x = collections.Counter(p)
y = [i[0] for i in x.items() if i[1]>=2]
z = [i[0] for i in x.items() if i[1]>=4]
y.sort(reverse=True)
y.append(0)
y.append(0)
z.sort(reverse=True)
z.append(0)
ans = y[0]*y[1]
ans1 = z[0]*z[0]
if ans1 > ans:
    ans =ans1
print(ans)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a = list(map(int, readline().split()))

    a.sort(reverse=True)

    e1 = 0
    e2 = 0
    prev = 0
    
    for cur in a:
        if prev == cur:
            if e1 == 0:
                e1 = cur
            else:
                e2 = cur
                print(e1*e2)
                sys.exit()
            cur = 0
        prev = cur

    print(0)

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

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

c = Counter(A)
pair = []

for x, cnt in c.items():
    pair += [x] * (cnt//2)


pair.sort()

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

Solution (Python):
from collections import defaultdict
def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    edge = defaultdict(int)

    for i in range(N):
        edge[A[i]] += 1

    edge = [ [k, v] for k, v in edge.items() if v >= 2 ]
    edge.sort(key = lambda x : x[0])

    if len(edge) >= 2 :
        if edge[-1][1] >= 4:
            print(max(edge[-1][0]**2, edge[-1][0]*edge[-2][0]))
        else:
            print(edge[-1][0]*edge[-2][0])
        
    elif len(edge) == 1:
        if edge[-1][1] >= 4:
            print(edge[-1][0]**2)
        else:
            print(0)
    else:
        print(0)

if __name__ == "__main__":
    main()

Solution (Python):
n =int(input())
a = list(map(int,input().split()))
a.sort()
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())),reverse=True)
x,y=0,0
def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
b=groupby(a)
l=len(b)
for i in range(l):
    if x==0:
        if b[i][1]>=4:
            x,y=b[i][0],b[i][0]
        elif b[i][1]>=2:
            x=b[i][0]
    elif y==0:
        if b[i][1]>=2:
            y=b[i][0]
    else:
        break
print(x*y)

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 collections
def slove(n, a):

    count = collections.Counter()
    a_list = [int(i) for i in a.split()]
    for i in a_list:
        count[i] += 1

    tmp = sorted([item for item in count.items() if item[1] >= 2])

    if len(tmp) == 0:
        return 0
    else:
        x = tmp.pop()
        if x[1] >= 4:
            return x[0] ** 2
        else:
            y = tmp.pop()[0]
            return x[0] * y

if __name__ == "__main__":
    n = int(input())
    a_list = input()
    print(slove(n, a_list))

Solution (Python):
from collections import Counter
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ac = Counter(a)
    acl = [i for i in ac if ac[i] >= 2]
    acl.sort(reverse=True)

    if len(acl) == 0:
        print(0)
    elif ac[acl[0]] >= 4:
        print(int(acl[0] * acl[0]))
    elif len(acl) <= 1:
        print(0)
    else:
        print(int(acl[0]*acl[1]))

if __name__ == '__main__':
    main()

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

c = Counter(a_ls)
edges_ls = [0] * 2
for value, count in c.items():
    if count >= 2:
        edges_ls.append(value)
    if count >= 4:
        edges_ls.append(value)
edges_ls.sort()
ans = edges_ls[-1] * edges_ls[-2]
print(ans)

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

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)
side = []
check = 4
A = sorted(set(A), reverse=True)
for i in A:
    if cnt[i] != 1:
        side.append(i)
        check -= cnt[i]
    if check <= 0:
        break
try:
    print(side[0]*side[1])
except IndexError:
    try:
        print(side[0]**2)
    except IndexError:
        print(0)

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

a.sort(reverse=True)

i=0
icnt=0
ai=0
while icnt<=1 and i<=n-2:
    icnt=1
    while i<=n-2 and a[i]==a[i+1]:
        ai=a[i]
        i+=1
        icnt+=1 
    i+=1

if icnt>=4:
    print(ai*ai)
elif icnt>=2:
    icnt=0
    while icnt<=1 and i<=n-2:
        icnt=1
        while i<=n-2 and a[i]==a[i+1] :
            ai2=a[i]
            i+=1
            icnt+=1
        i+=1
    if icnt>=2:
        print(ai*ai2)
    else:
        print(0)
else:
    print(0)

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



a.sort(reverse=True)


i=0
icnt=0
ai=0
while icnt<=1 and i<=n-2:
    icnt=1

    while i<=n-2 and a[i]==a[i+1]:
        ai=a[i]
        i+=1
        icnt+=1 

    i+=1


if icnt>=4:
    print(ai*ai)
elif icnt>=2:
    icnt=0

    while icnt<=1 and i<=n-2:
        icnt=1

        while i<=n-2 and a[i]==a[i+1] :
            ai2=a[i]
            i+=1
            icnt+=1

        i+=1
    if icnt>=2:
        print(ai*ai2)
    else:
        print(0)
else:
    print(0)

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)
key = []
p = -1
for i in range(1, n):
  if p == i:
    continue
  if a[i] == a[i-1]:
    key.append(a[i])
    if len(key) == 2:
      break
    p = i+1
if len(key) < 2:
  print(0)
else:
  print(key[0]*key[1])

Solution (Python):
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    d = {}
    for a in A:
        if not a in d:
            d[a] = 1
        else:
            d[a] += 1
    tup = sorted([(k, v) for k, v in d.items() if v > 1], key=lambda x: x[0])
    
    hd = []
    while len(tup) > 0:
        length, cnt = tup.pop()
        if cnt >= 4:
            hd.append(length)
        if cnt >= 2:
            hd.append(length)
        if len(hd) >= 2:
            print(hd[0]*hd[1])
            return
    print(0)




if '__main__' == __name__:
    resolve()

Solution (Python):
import collections
import sys
sys.setrecursionlimit(2000000)




n = int(input())
a = list(map(int, input().split()))
a_count = collections.Counter(a)
a_list = list(a_count.items())
a_sorted = sorted(a_list, key=lambda x: x[0], reverse=True)


ans = []
kouho = []
for i in range(len(a_sorted)):
    if a_sorted[i][1] >= 4:
        b = a_sorted[i][0]
        kouho.append(b)
        ans.append(b*b)
    if a_sorted[i][1] >= 2:
        kouho.append(a_sorted[i][0])


if len(ans) == 0 and len(kouho) < 2:
    print(0)
else:
    if len(ans) == 0:
        print(kouho[0]*kouho[1])
    else:
        print(max(max(ans), kouho[0]*kouho[1]))

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

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    c = Counter(A)
    A = [a for a in A if c[a] > 1]
    if len(A) < 4:
        print(0)
        exit()
    c = Counter(A)
    keys = c.keys()
    vals = c.values()
    z = zip(keys, vals)
    z = sorted(z, reverse=True)
    keys, vals = zip(*z)
    if vals[0] >= 4:
        a1, a2 = keys[0], keys[0]
    else:
        a1, a2 = keys[0], keys[1]
    print(a1 * a2)


if __name__ == '__main__':
    main()

Solution (Python):

import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    A=list(map(int,input().split()))
    d=defaultdict(int)
    t=[0]
    f=[0]
    for x in A:
        d[x]+=1
        if d[x]==2:
            t.append(x)
        elif d[x]==4:
            f.append(x)
    t.sort()
    f.sort()
    if len(t)>=2:
        print(max(f[-1]**2,t[-1]*t[-2]))
    else:
        print(0)

if __name__ == '__main__':
    main()

Solution (Python):
import collections

i = int(input())
li = list(map(int,input().split()))
c = collections.Counter(li)
li = list(set(li))
li.sort(reverse=True)
ans = 1
x = 0
i = 0

for i in li:
    if c[i] > 3 and x == 0:
        ans = i**2
        x += 2
    elif c[i] > 1:
        ans *= i
        x += 1
    if x == 2:
        break

if x == 2:
    print(ans)
else:
    print(0)

Solution (Python):
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
cnt = defaultdict(int)
data = []
for i in range(n):
    cnt[a[i]] += 1

if sum(v >= 2 for v in cnt.values()) < 2:
    print(0)
elif cnt[max(cnt.keys())] >= 4:
    print(max(cnt.keys()) ** 2)

else:
    for k, v in cnt.items():
        if v >= 2:
            data.append(k)
    data.sort(reverse = True)
    print(data[0] * data[1])

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
count = Counter(A)
keys = list(count.keys())
keys.sort(reverse = True)
a = 0
b = 0
for k in keys:
    if a == 0:
        if count[k] >= 4:
            a = b = k
            break
        elif count[k] >= 2:
            a = k
    else:
        if count[k] >= 2:
            b = k
            break
print(a * b)

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


d = {}


for i in range(N):
    if A[i] in d:
        d[A[i]] += 1
        continue
    d[A[i]] = 1

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

a = []

for key, data in d:
    if data>=4:
        a.append(key)
        a.append(key)
    elif data>=2:
        a.append(key)

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

Solution (Python):

import io
import math

data=int(input())

array=list(map(int, input().split()))
array.sort()
tmp=[]
i=data-1
while i>0:
  if array[i]==array[i-1]:
    tmp.append(array[i])
    i-=2
  else:
    i-=1
if len(tmp)>=2:
  print(tmp[0]*tmp[1])
else:
  print(0)

Solution (Python):
n = int(input())
a_list = list(map(int, input().split()))
counts = {}
for a in a_list:
	if a in counts:
		counts[a] += 1
	else:
		counts[a] = 1
counts = sorted(counts.items(), reverse=True, key=lambda x: x[0])
a = 0
b = 0
for key, value in counts:
	if value > 1:
		if a == 0:
			a = key
			if value > 3:
				b = key
				break
		else:
			b = key
			break
r = a*b
print(r)

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

for i in range(N):
    if i == 0:
        continue
    elif A[i-1] == A[i]:
        kouho.add(A[i])
        if A.count(A[i]) >= 4 or len(kouho) >= 2:
            break
else:
    ans = 0

kouho = list(kouho)

if len(kouho) >= 2:
    ans = kouho[0] * kouho[1]
elif len(kouho) == 1:
    ans = kouho[0] ** 2

print(ans)

Solution (Python):
import collections

n=int(input())
a=list(map(int,input().split()))
a=collections.Counter(a)
a=sorted(a.items(),reverse=True)


tm=0

for i in range(n):
    if a[i][1]>=4 and tm==0:
        print(a[i][0]*a[i][0])
        exit()
    elif a[i][1]>=2:
        if tm==0:
            tm=a[i][0]
        else:
            print(tm*a[i][0])
            exit()

print("0")

Solution (Python):

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

c = Counter(A)
sc = sorted(c.items(), key=lambda x: x[0], reverse=True)
sides = []
for side, nums in sc:
    if nums >= 4:
        sides.append(side)
        sides.append(side)
    elif nums >= 2:
        sides.append(side)
if 1 >= len(sides):
    print(0)
    exit()

s = sorted(sides, reverse=True)
ans = s[0]*s[1]
print(ans)

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

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
d = {}
for ai in a:
  if ai in d:
    d[ai] += 1
  else:
    d[ai] = 1
d = sorted(d.items(),reverse = True)
r = []
for k,v in d:
  if len(r) >= 2:
    break
  if v >= 4:
    r.append(k)
    r.append(k)
  elif v >= 2:
    r.append(k)
if len(r) < 2:
  print(0)
else:
  print(r[0]*r[1])

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
a.reverse()
count = 1
x = 0
y = 0
for i in range(1,n):
    if a[i] == a[i-1]:
        count+=1
    else:
        count = 1
    if count == 2 and x == 0:
        x = a[i]
        count = 0       
    elif count == 2 and y == 0:
        y = a[i]
print(x*y)

Solution (Python):
from collections import Counter
n, *A = map(int, open(0).read().split())
B = sorted([(k, v) for k, v in Counter(A).items() if v >= 2], reverse=1)
if len(B) == 0:
  print(0)
elif len(B) == 1:
  if B[0][1] >= 4:
  	print(B[0][0] ** 2)
  else:
    print(0)
else:
  if B[0][1] >= 4:
  	print(B[0][0] ** 2)
  else:
  	print(B[0][0]*B[1][0])

Solution (Python):
import collections 

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

d = collections.Counter(A)

x = sorted([i for i in d.items() if i[1]>1])
if len(x)==0 :
  print(0)
elif x[-1][1] >3 :
  print(x[-1][0]**2)
elif len(x) == 1 :
  print(0)
else:
  print(x[-1][0]*x[-2][0])

Solution (Python):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
l = sorted(filter(lambda x:x[1] > 1,c.items()),reverse=True)

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

Solution (Python):
import collections
N = int(input())
l = list(map(int,input().split()))
c = collections.Counter(l)
dic = sorted(c.items(), reverse=True)
r = []
for j in dic:
    k = j[0]
    v = j[1]
    if v >= 4:
    	r.append(k)
    	r.append(k)
    elif v >= 2:
    	r.append(k)
    if len(r) >= 2:
      print(r[0]*r[1])
      exit()
print(0)

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

S=[]
for i,j in A.items():
  if j>=2:
    S.append(i)
S=list(set(S))
S.sort()
if len(S)>=2:
  ans=S[-1]*S[-2]
else:
  print(0)
  exit()

Q=[]

for i,j in A.items():
  if j>=4:
    Q.append(i)
if Q==[]:
  print(ans)
  exit()
print(max(ans, (max(Q))**2))

Solution (Python):
import sys

n, *a = map(int, sys.stdin.read().split())

def main():
    a.sort()
    y = x = 0
    i = n - 1
    while i > 0:
        if a[i] == a[i-1]:
            if not y:
                y = a[i]
                i -= 1
            else:
                x = a[i]
                break
        i -= 1
    print(y * x)

if __name__ ==  '__main__':
    main()

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
A.sort()
ls = []
pre = A[0]
cnt = 1
for i in range(n):
    if A[i] == pre:
        cnt+=1
    else:
        ls.append((pre,cnt))
        cnt = 1
    pre = A[i]
ls.append((pre,cnt))
ans = 0
pre = 0
for num,cnt in ls:
    if cnt>=2:
        if cnt>=4:
            ans = num**2
        else:
            ans = num*pre
        pre = num
print(ans)

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

x = 0; y = 0
count = 0
i = 0
while i < n - 1:
    if A[i] == A[i + 1]:
        if count == 0:
            x = A[i]
        else:
            y = A[i]
        count += 1
        i += 2
    else:
        i += 1
    if count == 2:
        break

print(x * y)

Solution (Python):
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
D = Counter(A)
res = []
for k, v in D.items():
    if v >= 2:
        for _ in range(v // 2):
            res.append(k)

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

Solution (Python):










"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:
    return a
  return gcd_(a,a % b) 
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""

"""def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def lcm(a,b):
  g = gcd(a,b)
  return (a * b) // g"""

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7

def main():
  n = int(input())
  dic = {}
  for nya in map(int,input().split()):
    if nya in dic:
      dic[nya] += 1
    else:
      dic[nya] = 1
  
  LIST = []
  
  for k,v in dic.items():
    if v // 2 >= 1 and v > 1: 
      LIST.append([k,v])
  LIST = sorted(LIST,reverse = True)
  
  cnt = 0
  pr_ = 0
  for k,v in LIST:
    
    if v // 2 >= 2 and cnt == 0:
      print(k * k)
      exit()
    elif v // 2 == 1 and cnt == 0:
      cnt += 2
      pr_ = k
    elif v // 2 >= 1 and cnt == 2:
      print(pr_ * k)
      exit()
  print(0)
  
if __name__ == '__main__':
  main()

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
d = {}

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

flag1 = False
flag2 = False

for kk in sorted(d.keys(),reverse = True):
    if d[kk] >= 2 and flag1 == False:
        mx_v = kk
        flag1 = True
        d[kk] -= 2
    if flag1 == True and flag2 == False and d[kk] >= 2:
        mn_v = kk
        flag2 = True

if flag1 and flag2:
    print(mx_v * mn_v)
else:
    print(0)

Solution (Python):
from collections import Counter
n = int(input())
ns = list(map(int, input().split()))
dic = Counter(ns)
dic = {key:value for key, value in dic.items() if value>=2}
if len(dic) < 2:
    print(0)
else:
    sorted_dic = sorted(dic.items(), key=lambda x: x[0])
    if sorted_dic[-1][1] >= 4:
        print(sorted_dic[-1][0]**2)
    else:
        print(sorted_dic[-1][0] * sorted_dic[-2][0])

Solution (Python):
from collections import Counter
n = int(input())
list_A = list(map(int, input().split()))
list_C = Counter(list_A)
list_D = sorted(list_C.items(), key=lambda x:x[0],reverse=True)
q = []
for i in range(len(list_D)):
    if len(q) == 2:
        break
    l = list_D[i]
    if l[1] > 1:
        q.append(l[0])
        if len(q) == 1 and l[1] > 3:
            q.append(l[0])
if len(q) == 2:
    print(q[0]*q[1])
else:
    print(0)

Solution (Python):
from collections import Counter as C
n,*a=map(int,open(0).read().split())
b=[]
for i in C(a).items():
  if i[1]>3:
    b+=[i[0],i[0]]
  elif i[1]>1:
    b+=[i[0]]
b=sorted(b)
print(b[-1]*b[-2] if len(b)>1 else 0)

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a = list(reversed(sorted(a)))
x = 0
y = 0
for i in range(len(a)-1):
         if a[i] == a[i+1]:
                  x = a[i]
                  break
for j in range(i+2,len(a)-1):
         if a[j] == a[j+1]:
                  y = a[j]
                  break
print(x*y)

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

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

Solution (Python):
import collections 
n=input()
a=tuple(map(int,input().split()))
c=collections.Counter(a)
b=sorted(list(set(a)))[::-1]
ans,count=0,0
for i in b:
  if c[i]>3 and ans==0:
    print(i**2)
    exit()
  if c[i]>1:
    ans=ans*i if ans>0 else i
    count+=1
    if count==2:
      print(ans)
      exit()
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
work = []
temp = []
for k, v in sorted(counter.items(), key=lambda x:x[0], reverse=True):
    if v >= 4:
        temp.append(k)
    if v >= 2:
        work.append(k)
        if len(work)==2:
            break   
if len(work) < 2:
    if len(temp)==0:
        result = 0
    else:
        result = temp[0]**2
else:
    if len(temp)==0:
        result = work[0]*work[1]
    else:
        result = work[0]*work[1] if work[0]*work[1]>temp[0]**2 else temp[0]**2
print(result)

Solution (Python):
import sys
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
ans = []
for i in range(0,n-1):
    if(a[i]==a[i+1]):
        ans.append(a[i])
if len(ans) <2:
    print(0)
    sys.exit()
        
if (ans[0]==ans[1] and ans[1]!=ans[2]):
    print(ans[0]*ans[2])
    sys.exit()

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

Solution (Python):









N = int(input())
ARR = [int(s) for s in input().split(" ")]


def calculate(n, arr):

    dict = {}

    for ar in arr:
        if dict.get(ar) == None:
            dict.__setitem__(ar, 1)
        else:
            dict.__setitem__(ar, dict.get(ar) + 1)

    dict2 = {changedu: geshu for changedu, geshu in dict.items() if geshu >= 2}

    dict3 = sorted(dict2.items(), key=lambda x: -x[0])


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


calculate(N, ARR)

Solution (Python):
from collections import Counter


N = int(input())
A = map(int, input().split())
edge = Counter(A)

cand = [a for a in edge.keys() if edge[a] >= 2]
cand.sort(reverse=True)

e1 = e2 = 0
if len(cand) >= 1:
    if edge[cand[0]] >= 4:
        e1 = e2 = cand[0]
    elif len(cand) > 1:
        e1 = cand[0]
        e2 = cand[1]

print(e1 * e2)

Solution (Python):
n = int(input())
lst = list(map(int, input().split()))
lst.sort()
count = []

i = 0
while i<n-1:
    if lst[i]==lst[i+1]:
        count.append(lst[i])
        i+=2
    else:
        i+=1

count.sort(reverse=True)
count.append(0)
count.append(0)

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

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

a.sort(reverse=True)

i1=-1
lena1=0
for i in range(len(a)-1):
    if a[i]==a[i+1]:
        lena1=a[i+1]
        i1=i
        break
if i1==-1:        
    print(0)
elif i1+2<len(a)-1:        
    lena2=0
    for i in range(i1+2,len(a)-1):

        if a[i]==a[i+1] :
            lena2=a[i+1]
            break
    print(lena1*lena2)
else:
    print(0)