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=input()
a = list(map(int, input().split()))
a.sort()
h, w =0, 0
while True:
    try:
        if a[-1] == a[-2]:
            h = a[-1]
            a.pop()
            a.pop()
            break
        else:
            a.pop()
    except:
        break

while True:
    try:
        if a[-1] == a[-2]:
            w = a[-1]
            a.pop()
            a.pop()
            break
        else:
            a.pop()
    except:
        break
print(h*w)

Solution (Python):
n = int(input())
sticks = list(map(int, input().split()))
sticks.append(0)
sticks.sort()
sticks.reverse()
ans = []

def find(sticks):

  for i in range(n):
    if sticks[i] == sticks[i+1] == sticks[i+2] and not sticks[i+3] == sticks[i]:
      continue
    elif sticks[i] == sticks[i+1]:
      ans.append(sticks[i])
  
  if len(ans) <= 2:
    ans.append(0)
    ans.append(0)
  return ans[0] * ans[1]
print(find(sticks))

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

target1 = False
target2 = False

i = 0

while i < N-1:
    if numList[i] == numList[i+1]:
        if target1 == False:
            num1 = numList[i]
            target1 = True
            i += 1
        elif target1 == True:
            num2 = numList[i]
            target2 = True
    if target1 == True and target2 == True:
        break
    i += 1

if target2 == False:
    print("0")
else:
    print(num1 * num2)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
edge = set()
h = 0
w = 0

for i in range(N):
    if A[i] in edge:
        if A[i] > h:
            h,w = A[i],h
        elif A[i] > w:
            w = A[i]
        edge.remove(A[i])
    else:
        edge.add(A[i])

print(h*w)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
l = []

for i in range(0, N - 1):
    if len(l) == 2:
        break
    if A[i] == A[i + 1] and not A[i] == 0:
        l.append(A[i])
        A[i + 1] = 0
        
if len(l) == 2:
    print(l[0] * l[1])
else:
    print('0')

Solution (Python):
input()
d = {}
for a in input().strip().split():
    x = int(a)
    if x in d:
        d[x] += 1
    else:
        d[x] = 1

w = 0
for k in sorted(d.keys(), reverse=True):
    if d[k] >= 2:
        if not w:
            if d[k] >= 4:
                print(k * k)
                raise SystemExit
            else:
                w = k
        else:
            print(k * w)
            raise SystemExit
print(0)

Solution (Python):
from collections import Counter
n = int(input())
num_l = sorted(map(int, input().split()),reverse=True)
s = sorted(set(num_l), reverse=True)
d = Counter(num_l) 
res = []
it = 0
lim=len(s)

for i in range(n):
    if d[s[it]] >= 2:
        d[s[it]]-=2
        res.append(s[it])
    else:
        it+=1
        
    if len(res) == 2:
        print(res[0] * res[1])
        break
    if lim==it:
        print(0)

Solution (Python):
from collections import Counter

n = int(input().rstrip())
counter = Counter(map(int, input().rstrip().split(' ')))

x = y = 0
for k, v in counter.items():
    if v >= 2 and k > y:
        if k >= x:
            if v >= 4:
                x = y = k
            else:
                x, y = k, x
        else:
            y = k

print(x * y)

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    N = int(input())
    A_list = list(map(int, input().split()))
    c = Counter(A_list)

    x = []
    for length, n in sorted(c.items(), key=lambda x: x[0], reverse=True):
        if n >= 4:
            x += [length] * 4
        elif n >= 2:
            x += [length] * 2
    x += [0] * 4
    print(x[0] * x[2])

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
 
N = int(input())
A = list(map(int, input().split()))
h = w = 0
 
for i, cnt in Counter(A).items():
    if cnt >= 2 and i > w:
        if i > h:
            if cnt >= 4:
                h = i
                w = i
            else:
                w = h
                h = i
        else:
            w = i
            
print(w * h)

Solution (Python):
n = int(input())
list1 = list(map(int,input().split()))
list2 = set()
list1.sort()
list1.reverse()
a,b = 0,0
for i in list1:
	if i in list2:
		if i > a:
			a = i
			list2.remove(i)
		else:
			b = i
			break
	else:
		list2.add(i)
print('{0}'.format(a*b))

Solution (Python):
n = int(input())
lst1 = list(map(int, input().split()))
lst1.sort()
lst2 = set()
a, b = 0, 0

for i in lst1:
    if i>b:
        if i in lst2:
            lst2.remove(i)
            if i>a:
                b = a
                a = i
            else:
                b = i
        else:
            lst2.add(i)
print(a*b)

Solution (Python):
from collections import Counter
 
 
def solve(nums):
    counts = sorted([pair for pair in Counter(nums).items() if pair[1] >= 2], reverse=True)
 
    if len(counts) == 0:
        return 0
    elif len(counts) == 1:
        (val, cnt) = counts[0]
        return 0 if cnt < 4 else val * val
    else:
        (val1, cnt1) = counts[0]
        (val2, cnt2) = counts[1]
        return val1 * val2 if cnt1 < 4 else val1 * val1
 
 
if __name__ == '__main__':
    n = input()
    a = [int(i) for i in input().split()]
    print(solve(a))

Solution (Python):
input()
param_list = sorted([int(v) for v in input().split(" ")], reverse=True)
result = 0
duplicate_param = 0
count = 1
 
for v in param_list:
  if v == duplicate_param:
    if count == 1:
      result = v
      duplicate_param = 0
    else:
      result *= v
      print(result)
      break
    count += 1
  else:
    duplicate_param = v
 
if result == 0:
  print("0")

Solution (Python):
from collections import Counter


def solve(nums):
    counts = [pair for pair in Counter(nums).items() if pair[1] >= 2]
    counts.sort()
    counts.reverse()

    if len(counts) == 0:
        return 0
    elif len(counts) == 1:
        (val, cnt) = counts[0]
        return 0 if cnt < 4 else val * val
    else:
        (val1, cnt1) = counts[0]
        (val2, cnt2) = counts[1]
        return val1 * val2 if cnt1 < 4 else val1 * val1


if __name__ == '__main__':
    n = input()
    a = [int(i) for i in input().split()]
    print(solve(a))

Solution (Python):

"""
"""

from collections import Counter
from operator import itemgetter

def main():
    n = int(input())
    rods = [int(x) for x in input().split(' ')]

    candidates = []
    for r in Counter(rods).most_common():
        if r[1] >= 4:
            candidates.append(r[0])
            candidates.append(r[0])
        elif r[1] >= 2:
            candidates.append(r[0])
        else:
            break

    if len(candidates) >= 2:
        candidates.sort(reverse=True)
        print(candidates[0] * candidates[1])
    else:
        print('0')


if __name__ == '__main__':
    main()

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

A.sort()

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

A[N - 1] = 0

A.sort()
A.reverse()
print(A[0] * A[1])

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

A.sort()
A.reverse()

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

A.sort()
A.reverse()
print(A[0] * A[1])

Solution (Python):
import collections
dump = input()
inp = list(map(int,input().split()))
A = collections.Counter(inp)
t_A = [el[0] for el in A.items() if el[1] > 1]
t_A.extend([el[0] for el in A.items() if el[1] > 3])
t_A = sorted(t_A)
if len(t_A) >= 2:
  print(t_A[-2]*t_A[-1])
else:
  print(0)

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

i = 0

edge = []

while i < len(A)-1:
    if A[i] == A[i+1]:
        edge.append(A[i])
        i += 2
    else:
        i += 1
        
if len(edge) < 2:
    print(0)
else:
    print(edge[0] * edge[1])

Solution (Python):
def solve(): 
    n = int(input())
    sides = list(map(int, input().split(" ")))
    check_dual = {}
    possible_sides = []

    for i in sides:
        if i in check_dual:
            check_dual[i] += 1
        else:
            check_dual[i] = 1

    for k, v in check_dual.items():
        if v >=4:
            possible_sides.append(k)
            possible_sides.append(k)
        elif v == 2 or v == 3:
            possible_sides.append(k)

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


solve()

Solution (Python):
def solve(): 
    n = int(input())
    sides = list(map(int, input().split(" ")))
    check_dual = {}
    possible_sides = []

    for i in sides:
        if i in check_dual:
            check_dual[i] += 1
        else:
            check_dual[i] = 1

    tmp_square = 0
    for k, v in check_dual.items():
        if v >= 4 and k > tmp_square:
            tmp_square = k
            possible_sides.append(k)
        elif v == 2 or v == 3:
            possible_sides.append(k)
        else:
            pass

    possible_sides.sort(reverse=True)
    if tmp_square == 0 and len(possible_sides) < 2:
        print(0)
    elif tmp_square != 0 and len(possible_sides) == 0:
        print(tmp_square ** 2)
    elif tmp_square != 0 and len(possible_sides) == 1:
        print(max(tmp_square ** 2, tmp_square * possible_sides[0]))
    else:
        print(max(tmp_square ** 2, possible_sides[0] * possible_sides[1]))

solve()

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

def max_pair(Asc):
    m1 = 0
    while Asc:
        m2 = Asc.pop()
        if m1 == m2:
            return m1
        m1 = m2

    return 0

A.sort()
print(max_pair(A) * max_pair(A))

Solution (Python):
import sys
N = raw_input()
items = raw_input().split()
res = dict()
for i in items[:int(N)]:
    i = int(i)
    if res.get(i) is None:
        res[i] = 1
    else:
        res[i] = res[i] + 1
long2 = [0,0]
for i, num in res.iteritems():
    if num < 2:
        continue
    if i > long2[0]:
        if num >= 4:
            long2 = [i, i]
        else:
            long2 = [i, long2[0]]
    elif i > long2[1]:
        long2[1] = i
print long2[0] * long2[1]

Solution (Python):
from collections import Counter
n = int(raw_input())
a = sorted(map(int, raw_input().split()))
D = Counter(a)
v = []
for num, cnt in D.items():
    for i in range(cnt/2):
        v.append(num)
v = sorted(v)[::-1]
print 0 if len(v) < 2 else v[0]*v[1]

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

a.sort(reverse=True)

num = None
hen = []
en = 0

for i in a:
    if en == 2:break
    if num == i:
        hen.append(num)
        num = None
        en += 1
    else:
        num = i
        
if en == 2:
    print(hen[0]*hen[1])
else:
    print(0)

Solution (Python):
from collections import Counter

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

pairs = sorted([k for k, v in Counter(A).items() if v >= 2] + [k for k,v in Counter(A).items() if v >= 4], reverse = True)

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

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
i=n-1
s1=0
s2=0
while i>0:
    if a[i]==a[i-1] and s1==0:
        s1=a[i]
        i-=2
        continue
    if a[i]==a[i-1]:
        s2=a[i]
        i-=1
        break
    i-=1

print(s1*s2)

Solution (Python):
N = int(input())
sticks = list(map(int, input().split()))
stocks = set([])
doubles = []
for s in sticks:
    if s not in stocks:
        stocks.add(s)
    else :
        doubles.append(s)
        stocks.remove(s)
if len(doubles) < 2:
    print("0")
else:
    l = max(doubles)
    doubles.remove(max(doubles))
    m = max(doubles)
    print(l*m)

Solution (Python):
from collections import Counter

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

for i, cnt in Counter(A).items():
    if cnt >= 2 and i > w:
        if i > h:
            if cnt >= 4:
                h = i
                w = i
            else:
                w = h
                h = i
        else:
            w = i
            
print(w * h)

Solution (Python):
from collections import Counter

n = int(input())
c = Counter(map(int, input().split()))
h = w = 0
for k, v in c.items():
    if v >= 2 and k > w:
        if k > h:
            if v >= 4:
                h = k
                w = k
            else:
                w = h
                h = k
        else:
            w = k
print(h * w)

Solution (Python):
from collections import Counter

N = int(input())
sticks = list(map(int , input().split()))
ans = []

sticks_counter = Counter(sticks).most_common()
sticks_counter.sort(reverse = True)

for s in sticks_counter:
    if s[1] >=2:
        ans.append(s[0])
        if len(ans) == 2:
            print(ans[0]*ans[1])
            break
    
    if s[1] >= 4:
        print(s[0]**2)
        break

else:
    print(0)

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




b = sorted(a, reverse=True)


flag = False

i = 0

tate = 0
yoko = 0

while i < n - 1:
    
    if b[i] == b[i+1]:
        
        if flag:
            yoko = b[i]
            
            break
        else:
            tate = b[i]
            flag = True
            i += 1
            
    i += 1

print(tate*yoko)

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

ans=[]
tmp=0
count=0
for el in a:
    if len(ans)==2: break
    if el != tmp: tmp=el; count=0
    else:
        if not count%2: ans.append(el);
        count+=1

try: ans=ans[0]*ans[1]
except: ans=0
print(ans)

Solution (Python):
N = int(input())
bar = [int(x) for x in input().split()]
ls = set()
a,b = 0,0
for x in bar:
    if x>b:
        if x in ls:
            ls.remove(x)
            if x>a:
                b = a
                a = x
            else:
                b = x
        else:
            ls.add(x)
print(a*b)

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

ans=[]
tmp=0
count=0
for el in a:
    if len(ans)==2: break
    if el != tmp: tmp=el; count=0
    else:
        if count%2==0: ans.append(el); tmp=el;
        count+=1

try: ans=ans[0]*ans[1]
except: ans=0
print(ans)

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

x = 0
y = 0
S = set()

for a in A:
    if a in S:
        if a < x:
            continue
        elif a > y:
            x = y
            y = a
        else:
            x = a
        S.remove(a)
    else:
        S.add(a)

print(x*y)

Solution (Python):
n = int(input())
a = list(map(int , input().split()))
ans = []
a.sort()
a.reverse()
f = 0
cnt = 1
when = 0
for i in a:
    if i == f:
        cnt += 1
        if cnt >= 2:
            ans.append(i)
            cnt = 0
            when += 1
    else:
        f = i
        cnt = 1
    if when == 2:
        break
if len(ans) != 0:
    print(ans[0] * ans[1])
else:
    print(0)

Solution (Python):
def main():
    _ = input()
    a_list = sorted([int(i) for i in input().split()], reverse=True)

    height, width = None, None
    i = 0
    while (i != len(a_list)):
        a = a_list[i]
        j = i+1
        cnt = 1
        for j in range(i+1, len(a_list)):
            if cnt == 4: break
            b = a_list[j]
            if a != b:
                break
            cnt += 1
        if 1 < cnt and cnt < 4 and height == None:
            height = a
        elif 1 < cnt and cnt < 4 and width == None:
            width = a
            print(height*width)
            break
        elif cnt == 4 and height == None:
            height = a
            print(height*height)
            break
        elif cnt == 4:
            width = a
            print(height*width)
            break
        i = j
    if not height:
        print(0)
    

if __name__ == "__main__":
    main()

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

h=[]
count=0
f=0
for i in a:
 if f==i:
  h.append(i)
  count+=1
  f=0
 else:
   f=i
   if count==2:
       break 
if count==2:
 print(h[0]*h[1])
else:
 print(0)

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

a.sort()
a.reverse()

hoge = []
count = 0
p = 0
for i in a:
    if p == i:
        hoge.append(i)
        count += 1
        p = 0
    else:
        p = i
    if count == 2:
        break
if count == 2:
    print(hoge[0] * hoge[1])
else:
    print(0)

Solution (Python):
N=input()
A=[int(x) for x in input().split()]
from collections import defaultdict
d=defaultdict(int)
for i in A:
    d[i]+=1
hen=[0,0]
for i in d.items():
    if i[1]>=2:
        hen.append(i[0])
    if i[1]>=4:
        hen.append(i[0])
hen=sorted(hen,reverse=True)
print(hen[0]*hen[1])

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


count=0
ans=[]
flag=0
for i in range(1,n):
    if a[i]==a[i-1] and flag==1:
        flag=0


    elif a[i]==a[i-1] and flag==0:
        count += 1
        ans.append(a[i])
        flag=1

    elif a[i] != a[i-1]:
        flag=0

    if count==2:
        print(ans[0]*ans[1])
        exit()


print(0)

Solution (Python):
from collections import Counter

n = int(raw_input())
l = map(int, raw_input().split())
c = Counter(l)
ls = sorted(c.keys(), reverse=True)
h = 0
w = 0
for k in ls:
    if c[k] >= 4 and h == 0 and w == 0:
        h = k
        w = k
        break
    elif c[k] >= 2:
        if h == 0:
            h = k
        else:
            w = k
            break
print h*k

Solution (Python):
n=int(input())
a=sorted(list(map(int,input().split())),
         reverse=True)
ans=[]
p=-1
cnt=0
flag =False
for index,i in enumerate(a):
    if p!=i:
        if cnt>=4:
            ans.append(p)
            ans.append(p)
        if cnt>=2:
            ans.append(p)
        p=i
        cnt=1
    else:
        cnt+=1
    if len(ans)>=2:
                print(ans[0]*ans[1])
                flag=True
                break
if not flag:
    if cnt>=4:
            ans.append(p)
            ans.append(p)     
    elif cnt>=2:
            ans.append(p)
    if len(ans)>=2:
        print(ans[0]*ans[1])
        flag=True
       
if not flag:
    print(0)

Solution (Python):
N = int(input())
A = sorted(list(map(int, input().split())))[::-1]
l1, l2 = 0, 0
flag = True
for i in range(N-1):
    if A[i] > A[i+1]:
        flag = True
        pass
    elif l1 == 0:
        l1 = A[i]
        flag = False
    elif l2 == 0 and flag:
        l2 = A[i]
        break
    else:
        flag = True

print(l1 * l2)

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

As = [int(a) for a in tmp.split()]

dic = {}
maxes = [0, 0]
for a in As:
    if a not in dic:
        dic[a] = 0
    dic[a] += 1
    if dic[a] % 2 == 0:
        if maxes[0] < a:
            maxes[0], maxes[1] = a, maxes[0]
        elif maxes[1] < a:
                maxes[1] = a

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

Solution (Python):
def C_Make_a_Rectangle(lst):
    N = lst[0]
    A = lst[1:]

    from collections import Counter, deque
    c = sorted(Counter(A).items(), reverse=True)  
    

    ans = deque([])
    for k, v in c:
        if v == 1:
            continue
        elif v == 2 or v == 3:
            ans.append(k)
            if len(ans) == 2:
                break
        else:
            ans.append(k)
            ans.append(k)
            break

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

n = int(input())
l = [int(i) for i in input().split()]
x = [n] + l
print(C_Make_a_Rectangle(x))

Solution (Python):
import sys
from collections import Counter




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


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


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    n = read_int()
    a = read_int_list()
    a.sort()
    c = Counter(a)
    l = set()
    for i in a:
        if c[i] >= 2:
            l.add(i)
    l = list(l)
    l.sort()

    res = 0
    if len(l) >= 1:
        m = l[-1]
        if c[m] >= 4:
            res = m * m
        else:
            if len(l) >= 2:
                p = l[-2]
                res = m * p
    print(res)


main()

Solution (Python):
def search(A):
  B = list(set(A))
  if len(A)-len(B) == 0: return 0 

  a1 = 0
  for n,(i, j) in enumerate(zip(A[0:-1], A[1:])):
    if i == j:
      a1 = i
      break
  del(A[:n+2])

  return a1

N = int(input())
A = map(int, input().split())
A = [a for a in A]
A.sort(reverse=True)
a1 = search(A)
a2 = search(A)
if a1 > 0 and a2 > 0: print(a1*a2)
else: print(0)

Solution (Python):
def main():
    N = int(input())
    a = [int(i) for i in input().split()]
    area = 0
    
    b = 0
    tmp = 0

    sort_a = sorted(a, reverse=True)
    for num in sort_a:
        if(num == tmp):
            if(b > 0):
                area = num * b
                break
            else:
                b = num
                tmp = 0
        else:
            tmp = num
    
    print(area)
    
if __name__=="__main__":
    main()

Solution (Python):
import numpy as np

def search(A):
  B = list(set(A))
  B.sort(reverse=True)
  if len(A)-len(B) == 0: return 0 

  a1 = 0
  An = np.array(A)
  for n,(i, j) in enumerate(zip(An[0:-1], An[1:])):
    if i == j:
      a1 = i
      break
  del(A[:n+2])

  return a1

N = int(input())
A = map(int, input().split())
A = [a for a in A]
A.sort(reverse=True)
a1 = search(A)
a2 = search(A)
if a1 > 0 and a2 > 0: print(a1*a2)
else: print(0)

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

A.sort(reverse=True)

ans = 0

b = 0
tmp = 0


for i in range(len(A)):
    if ans == 0:
        if A[i] == tmp:
            if b > 0:
                ans = A[i] * b
            else:
                b = A[i]
                tmp = 0

        else:
            tmp = A[i]


print(ans)

Solution (Python):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
c_dict = Counter(A)
B = []
C = []

for k, v in c_dict.items():
    if v >= 4:
        B.append(k)
    elif v >= 2:
        C.append(k)
B.sort(reverse=True)
C.sort(reverse=True)

if len(B) < 1 and len(C) < 2:
    print(0)
elif len(B) < 1 and len(C) >= 2:
    F = C[1] * C[0]
    print(F)
elif len(B) >= 1 and len(C) == 1:
    D = B[0] ** 2
    E = C[0] * B[0]
    print(max(D, E))
elif len(B) >= 1 and len(C) >= 2:
    D = B[0] ** 2
    E = C[0] * B[0]
    F = C[1] * C[0]
    print(max(D, E, F))

Solution (Python):

n = int(input().strip())

li = list(map(int,input().strip().split()))

d = {}
res = []
for i in li:
    d[i] = d.get(i,0)+1
    if(d[i] == 2 or d[i]==4):
        res.append(i)

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

Solution (Python):
num = int(input())
hen = sorted(list(map(int, input().split(" "))), reverse=True)
i = 0
a = []
while i < num-1:
    if hen[i] == hen[i+1]:
        a.append(hen[i])
        i += 2
    else:
        i += 1
if len(a) < 2:
    print(0)
else:
    print(a[0] * a[1])

Solution (Python):
int(input())
l=[int(x) for x in input().split()]
arr={}
for i in l:
	if not arr.get(i):
		arr[i]=1
	else:
		arr[i]+=1
max1=0
max2=-1
sqr=0
for i in arr:
	if arr[i]>=2:
		if i > max1:
			max1=i
		if arr[i]>=4:
			sol=i**2
			if sqr < sol :
				sqr=sol
for i in arr:
	if arr[i]>=2:
		if i > max2 and i < max1:
			max2=i

rec=max1 * max2
if rec > sqr:
	print(rec)
else:
	print(sqr)

Solution (Python):

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

y=sorted(x)
width=[0,0]
height=[0,0]


for i in range(0,len(y)-1):
    if (y[len(y)-1-i]==y[len(y)-2-i] and width[0]==0):
        width[0]=y[len(y)-1-i]
        width[1]=len(y)-1-i
        continue
    if (width!=0 and y[len(y)-1-i]==y[len(y)-2-i]):
        if(len(y)-1-i==width[1]-1):
            continue
        height[0]=y[len(y)-1-i]
        break



print('{0}'.format(int(width[0])*int(height[0])))



quit()

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

A=sorted(A,reverse=True)
if(len(A)%2==1):
    A.append(0)
c=0
l=1
t=0
th=0
for i in range(0,len(A),2):
    if(c==2):
        break
    if(A[i]==A[i+1]):
        c+=1
        l*=A[i]
        th=True
    elif(t==A[i] and not(th)):
        c+=1
        l*=A[i]
        th=False
    else:
        th=False
    t=A[i+1]
if(c==2):
    print(l)
else:
    print(0)

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

for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i]= 1

keys = sorted(d)
l= sorted(keys,reverse=True)
cnt =0
lenght=[]
found = False
for i in l:
    if d[i]>=4 and cnt <2:
        lenght.append(i)
        lenght.append(i)
        cnt+=2
    elif d[i]>=2 and cnt<2:
        lenght.append(i)
        cnt+=1
    else:
        found = True
        

if cnt>=2:
    print(lenght[0]*lenght[1])
else:
    print(0)

Solution (Python):
import itertools

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

num = dict()

for a in A:
    if a not in num:
        num[a] = 0
    num[a] += 1

m1 = 0
m2 = 0

for a in sorted(num.keys(), reverse=True):
    if num[a] >= 2:
        m1 = a
        num[a] = num[a] - 2
        break
for a in sorted(num.keys(), reverse=True):
    if num[a] >= 2:
        m2 = a
        num[a] = num[a] - 2
        break
print(m1*m2)

Solution (Python):
n=int(input())
a=map(int, input().split())
a=sorted(a)[::-1]
k=-2
l=-2
for i in range(n-1):
    if (a[i]==a[i+1])&(i>k+1):
        if (k>=0):
            l=i
            break
        else:
            k=i
if l>=0:
    print(a[k]*a[l])
else:
    print(0)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
hen1 = 0
hen2 = 0
hen_list = {}
for i in a:
    if(not i in hen_list):
        hen_list[i] = 0
    hen_list[i] += 1
for k, v in sorted(hen_list.items(), key=lambda x: -x[0]):
    if(v >= 4 and hen1 == 0):
        hen1 = k
        hen2 = k
        break
    if(v >= 2 and hen1 == 0):
        hen1 = k
    elif(v >= 2 and hen2 == 0):
        hen2 = k
    if(hen2!=0):
        break

print(hen1*hen2)

Solution (Python):
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
b = []
for key,val in Counter(a).items():
    if val >= 2:
        b.append(key)
        if val >= 4:
            b.append(key)

b.sort()

if len(b)>=2:
    x = b.pop()
    y = b.pop()
    ans = x*y
else:
    ans = 0

print(ans)

Solution (Python):
num=raw_input()
tmp=map(int, raw_input().split(" "))
tmp.sort()
tmp.reverse()
oldnum=0
arr=[]
flag=0
out=0
for i in range(len(tmp)-1):
    if tmp[i]==tmp[i+1] and flag==0:
            arr.append(tmp[i])
            flag=1
    else:
        flag=0
    if len(arr)==2:
        out=arr[0]*arr[1]
        break
    try:
        if tmp[i]==tmp[i+1] and tmp[i]==tmp[i+2] and tmp[i]==tmp[i+3]:
            out=tmp[i]**2
            break
    except:
        pass
print out

Solution (Python):
from collections import *
n=int(input())
c=Counter(map(int,input().split()))
x=y=0
for k,v in c.items():
    if v>=2 and k>y:
        if k>=x:
            if v>=4:
                x=y=k
            else:
                x,y=k,x
        else:
            y=k
print(x*y)

Solution (Python):
def c():
    from collections import deque
    n = int(input())
    A = [int(ai) for ai in input().split()]
    A = deque(sorted(A, reverse=True))
    xy = []
    for i in range(1, n):
        
        if A[0] == A[1]:
            tmp = A.popleft(); A.popleft()
            xy.append(tmp)
        else:
            A.popleft()

        if len(xy) == 2:
            print(xy[0] * xy[1])
            break
    if len(xy) < 2:
        print(0)

c()

Solution (Python):
import sys

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

mstack = []
stack = [0]
for a in A:
    if a == stack[-1]:
        mstack.append(a)
        stack.pop()
        if len(mstack) >= 2:
            print(mstack[-1] * mstack[-2])
            sys.exit()
    else:
        stack.append(a)
print(0)

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

xy = [0, 0]

i = 0
j = 0
while i < N - 1:
    if side_list[i] == side_list[i+1]:
        xy[j] = side_list[i]
        i += 1
        j += 1
        if j > 1:
            break
    i += 1

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

Solution (Python):

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

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

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

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
bn = 0
ans = 0
count = 0
i = 0

while(i<n):
    if bn==a[i]:
        if count == 0:
            ans = a[i]
            if i+1<n:
                bn = a[i+1]
            i += 1
            count +=1
        else:
            ans *= a[i]
            count +=1
            break
    else:
        bn = a[i]
    i +=1

if count>=2:
    print(ans)
else:
    print(0)

Solution (Python):
def main():
    N = int(input())
    A = tuple(map(int, input().split()))

    a = sorted(A, reverse=True)
    b = {}
    for i in range(N - 1):
        if a[i] == a[i+1]:
            if a[i] in b.keys():
                b[a[i]] += 1
            else:
                b[a[i]] = 2
    if len(b) < 2:
        ans = 0
    elif b[max(b)] >= 4:
        ans = max(b) ** 2
    else:
        c = sorted(b, reverse=True)
        ans = c[0] * c[1]

    print(ans)

main()

Solution (Python):


def count(list, target, num):
    l = len(list)
    c = 0
    for i in xrange(-num, l + 1):
        if list[-i] == target:
            c += 1
            if c == 4:
                return c
        else:
            return c
    return c


N = int(raw_input())
A = map(int, raw_input().split())

candidates = []
A.sort()
t = -1
for i in xrange(0, N + 1):
    n = count(A, A[t], t)
    for m in range(n / 2):
        candidates.append(A[t])
        if len(candidates) == 4:
            break
    t -= n
    if t < -N:
        break
if len(candidates) < 2:
    print 0
else:
    print candidates[0] * candidates[1]

Solution (Python):
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n  = read_line(int)

as_ = [int(col) for col in input().split()]

max_a = -1
max_aa = -1

count = {}

for a in as_:
    if a not in count:
        count[a] = 1
    else:
        count[a] += 1

        if a == max_a:
            pass
        elif a > max_a:
            max_aa = max_a
            max_a = a
        elif a > max_aa:
            max_aa = a
    

if max_a > 0 and count[max_a] >= 4:
    print(max_a * max_a)
    exit()

if max_a > 0 and max_aa > 0:
    print(max_a * max_aa)
    exit()

print(0)