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=sorted(a,reverse=True)
l=len(a)
skip=False
ans=1
flag=0
for i in range(l) :
    if skip :
        skip=False
        continue
    if i == l-1 :
        print(0)
        break
    if a[i] == a[i+1] :
        ans *= a[i]
        flag += 1
        skip=True
        if flag == 2 :
            print(ans)
            break

Solution (Python):
raw_input()
ls = map(int, raw_input().split(" "))
ls.sort()
ls.reverse()
i = 0
answer = []
while i < len(ls) - 1:
  if ls[i] == ls[i+1]:
    answer.append(ls[i])
    if len(answer) >= 2:
      break
    i += 1
  i += 1

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

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

bars.sort(reverse=True)

flag = 0
l = 0
l1 = 0
l2 = 0

for x in bars:
    if flag==0:
        l = x
        flag = 1
    elif flag==1 and x==l and l1==0:
        l1 = x
        l = 0
        flag = 0
    elif flag==1 and x==l and l1!=0:
        l2 = x
        break
    else:
        l = x
        flag = 1

print(l1 * l2)

Solution (Python):


n = input()

a = map(int, raw_input().split())
a = list(reversed(sorted(a)))

i = 1
b = []
cnt = 0

while True:
    if cnt > 1:
        break
    elif i >= len(a):
        print 0
        exit()
    if a[i] == a[i-1]:
        
        b.append(a[i])
        cnt += 1
        i += 1
    i += 1
if cnt > 1:    
    print b[0] * b[1]

Solution (Python):

import sys
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
a = Counter(A)
width = -1
height = -1
candinate = []
for tmp in reversed(sorted(list(set(A)))):
    b = a[tmp]
    if b >= 4:
        if width == -1:
            width = tmp
        if height == -1:
            height = tmp
    elif b >= 2:
        if width == -1:
            width = tmp
            b = 0
        if height == -1 and b != 0:
            height = tmp
    else:
        pass
    if width != -1 and height != -1:
        print(width*height)
        sys.exit()
print(0)

Solution (Python):

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

pairs = []
for k, v in c.items():
    if v >= 4:
        pairs.extend([k]*2)
    elif v >= 2:
        pairs.append(k)

if len(pairs) >= 2:
    a, b = sorted(pairs, reverse=True)[:2]
    print(a*b)
else:
    print(0)

Solution (Python):
import numpy as np


def getInput():
    separator = ' '
    ret_array = []
    while True:
        try:
            row = input().split(sep=separator)
            ret_array.append(row)
        except EOFError:
            break
    return ret_array


g = getInput()
N = g[0][0]
A = np.array(g[1], dtype=np.int32)
A = np.sort(A, kind='mergesort')
A = A[::-1]

idx = 0
ph = np.empty((2,), dtype=np.int32)
try:
    for c in range(0, 2):
        while True:
            if A[idx] == A[idx + 1]:
                ph[c] = A[idx]
                idx += 2
                break
            else:
                idx += 1
except IndexError:
    print(0)
    exit()

print(np.prod(ph))

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

res = []
tmp = -1
for a in A:
    if a == tmp:
        res.append(a)
        tmp = -1
    else:
        tmp = a
    if len(res) >= 2:
        break

res = sorted(res, reverse=True)

result = 1
for i in range(2):
    result *= res[i]

print(result)

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

res = [0, 0]
tmp = -1
for a in A:
    if a == tmp:
        res.append(a)
        tmp = -1
    else:
        tmp = a
    if len(res) >= 4:
        break

res = sorted(res, reverse=True)

result = 1
for i in range(2):
    result *= res[i]

print(result)

Solution (Python):
input()
a=sorted(list(map(int,input().split())))
e={}
r=[]
for i in a:
  if not e.get(i):
    e[i]=1
  else:
    e[i]=0
    r.append(i)
print(0 if len(r) < 2 else r[-1] * r[-2])

Solution (Python):
import collections

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

cnt = collections.Counter(A)
k2 = []
k4 = []
for k in cnt:
    if cnt[k] >= 2:
        k2.append(k)
    if cnt[k] >= 4:
        k4.append(k)
ans = 0
k2.sort()
k4.sort()
if len(k4) >= 1:
    ans = max(ans, k4[-1] * k4[-1])
if len(k2) >= 2:
    ans = max(ans, k2[-1] * k2[-2])
print(ans)

Solution (Python):
from collections import Counter

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

Solution (Python):

import collections
_=input()
bars=[i for i in map(int,input().split())]
data=sorted(collections.Counter(bars).items(),key= lambda x: -x[0] )
stock=0
ret=0
for bar ,count in data:
    if count>=4:
        if stock:
            ret=stock*bar
            break
        else:
            ret=bar*bar
            break
    elif count>=2:
        if stock:
            ret=stock*bar
            break
        else:
            stock=bar
print(ret)

Solution (Python):

import sys

n=int(raw_input())
l=map(int,raw_input().split())
l1=sorted(l,reverse=True)
l2=[]
for i in xrange(n-1):
 if l1[i]==l1[i+1]:
  l2.append(l1[i])
if l2==[]:
 print 0
 sys.exit()
ls=sorted(list(set(l2)),reverse=True)
if l1.count(ls[0])>3:
 res=ls[0]**2
else:
 res=ls[0]*ls[1]
print res

Solution (Python):


def MakeRectangle(N, A):
    A = sorted(A, reverse=True)
    length_list = list()
    length_buff = 0
    for length in A:
        if len(length_list) == 2:
            break
        if length_buff == length and length != 0:
            length_list.append(length)
            length_buff = 0
        else:
            length_buff = length
    if len(length_list) < 2:
        return 0
    else:
        return length_list[0] * length_list[1]


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    S = MakeRectangle(N, A)
    print(S)

Solution (Python):

import numpy as np

def MakeRectangle(N, A):
    A = np.array(A)
    length_list = list()
    length_buff = 0
    for length in np.sort(A)[::-1]:
        if len(length_list) == 2:
            break
        if length_buff == length and length != 0:
            length_list.append(length)
            length_buff = 0
        else:
            length_buff = length
    if len(length_list) < 2:
        return 0
    else:
        return length_list[0] * length_list[1]


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    S = MakeRectangle(N, A)
    print(S)

Solution (Python):
from collections import Counter

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

Solution (Python):
from collections import defaultdict

input()
t = defaultdict(lambda: 0)
for e in [int(i) for i in input().split()]:
  t[e] += 1
ans = []
for k, v in t.items():
  if v >= 2:
    if v >= 4:
      ans.extend([k, k])
    else:
      ans.append(k)
ans.sort()
if len(ans) < 2:
  print(0)
else:
  print(ans[-1]*ans[-2])

Solution (Python):
x = input()
a = []
a = map(int, raw_input().split())
b = []
d = {}
for i in range(len(a)):
    if a[i] in d:
        d[a[i]]+=1
    else:
        d[a[i]] = 1
g = []
for key in d:
    if d[key]>=2:
        b.append(key)
    if d[key]>=4:
        g.append(key)
b.sort()
g.sort()
if len(b)<2 and len(g) == 0:
    print 0
else:
    if len(b)<2:
        b.append(0)
        b.append(0)
    if len(g)==0:
        g.append(0)
    print max(b[len(b)-1]*b[len(b)-2], g[len(g)-1]*g[len(g)-1])

Solution (Python):
n = input()
bars = map(int,raw_input().split(' '))
bars.sort()
h1_cand=0
h2_cand=0
h1=0
h2=0
for i in range(n):
  m = n-1-i
  if h1 > 0:
    if h2_cand == bars[m]:
      h2 = h2_cand
      break
    else:
      h2_cand = bars[m]
  else:
	if h1_cand == bars[m]:
    	  h1 = h1_cand
    	  h1_cand = 0
  	else:
    	  h1_cand = bars[m]
 
print h1*h2

Solution (Python):
n = int(input())
s = set()
q = [0,0]
import heapq as hq
for a in map(int, input().split()):
  if a > q[0]:
    try:
      s.remove(a)
      hq.heapreplace(q, a)
    except:
      s.add(a)

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

Solution (Python):


def main():
    N = int(input())
    L = sorted(map(int, input().split()))
    a = b = 0
    c = len(L) - 1
    while c > -1:
        t = L[c]
        c -= 1
        if a == t:
            break
        else:
            a = t
    while c > -1:
        t = L[c]
        c -= 1
        if b == t:
            break
        else:
            b = t
    print(a*b)
    
if __name__ == '__main__':
    main()

Solution (Python):


def main():
    N = int(input())
    L = sorted(map(int, input().split()))[::-1]
    a = b = c = 0
    while c < len(L):
        t = L[c]
        c += 1
        if a == t:
            break
        else:
            a = t
    while c < len(L):
        t = L[c]
        c += 1
        if b == t:
            break
        else:
            b = t
    print(a*b)
    
if __name__ == '__main__':
    main()

Solution (Python):
input()

a = map(int, raw_input().split())
a.sort(reverse = True)

edge = []
p = 1
while p < len(a):
      if a[p] == a[p-1]:
              edge.append(a[p])
              p += 2
      else:
              p += 1

edge.append(0)
edge.append(0)
print edge[0] * edge[1]

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

    A.sort(reverse=True)

    v = []
    while len(A) > 1:
        if len(v) == 2:
            break

        if A[0] == A[1]:
            v.append(A[0])
            A.pop(0)
            A.pop(0)
        else:
            A.pop(0)

    if len(v) == 1 or len(v) == 0:
        print(0)
    else:
        print(v[0] * v[1])

Solution (Python):

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

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):
def spaceinput():
    return list(map(int,input().split(" ")))


N=int(input())
a=spaceinput()


sa=sorted(a,reverse=True)
x=[]
i=0
while True:
    if i>=len(sa)-1:
        break
    ssa=sa[i]
    if sa[i]==sa[i+1]:
        x.append(ssa)
        i+=2
        if len(x)==2:
            break
        continue

    else:
        i+=1


x.extend([0,0])

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

Solution (Python):
import math
n = int(input())
ar = list(map(int,input().split()))
ar.sort()
ar.reverse()
ans = []
i=0
while True:
    if len(ar)-1 <= i or len(ans) >=2:
        break
    if ar[i] == ar[i+1]:
        ans.append(ar[i])
        i+=1
    i+=1
if(len(ans)<2):
    print(0)
else:
    print(ans[0]*ans[1])

Solution (Python):
from collections import Counter

n = input()
ac = Counter(map(int, input().split()))

w, h = 0, 0
for i in sorted(ac.keys(), reverse=True):
    if ac[i] == 1:
        continue
    if w:
        h = i
        break
    if ac[i] >= 4:
        w = h = i
        break
    w = i

print(w * h)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
s = 1
count = 0
after = False

for i in range(len(a)-1):
	if after:
		after = False
		pass
	else:
		if count == 2:
			break
		else:
			if a[i] == a[i+1]:
				s = s * a[i]
				count += 1
				after = True

if count == 2:
	print(s)
else:
	print(0)

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

Solution (Python):
from collections import Counter
_ = input()
c = {k: x for k, x in Counter(map(int, input().split())).items() if x>=2}
d = sorted(list(c.keys()), reverse=True)
if len(c) < 1:
    print(0)
elif c[d[0]] >= 4:
    print(d[0] ** 2)
elif len(c) < 2:
    print(0)
else:
    print(d[0] * d[1])

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

a = sorted(a)
i = len(a) - 1
b = []

while (i - 1 >= 0):
	if (a[i] == a[i - 1]):
		b.append(a[i - 1])
		i -= 2

	else:
		i -= 1

	if(len(b) == 2):
		break


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

else:
	print(0)

Solution (Python):
import collections

N = int(input())
A = list(map(int,input().split()))
A = sorted(A)[::-1]

s = collections.Counter(A)
res = 1
count = 0

for i in sorted(list(set(A)))[::-1]:
    if 4 <= s[i] and count != 1:
        res *= i
        res *= i
        count += 2
    elif 2 <= s[i]:
        res *= i 
        count += 1

    if count == 2:
        break

if count == 2:
    print(res)
else:
    print(0)

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

ai.sort()

i1 = -1
i2 = -1
b = 0
for i in range(n - 1, b - 1, -1):
    if ai[i - b] == ai[i - 1 - b]:
        b += 1
        if i1 == -1:
            i1 = ai[i - b]
        else:
            i2 = ai[i - b]
            print(i1 * i2)
            break

if i2 == -1:
    print(0)

Solution (Python):

import sys
from collections import deque
import copy
import numpy as np

from math import *
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = list(read_func().strip().split())
    length_set = set([])
    appeared_count = {}
    for i in range(N):
        A = int(input_raw[i])
        if A not in appeared_count:
            appeared_count[A] = 1
        else:
            appeared_count[A] += 1
            length_set.add(A)



    if len(length_set) == 0:
        print 0
    else:
        length_list = list(length_set)
        length_list.sort(reverse = True)
        max_length = length_list[0]
        next_maxt_length = length_list[1]

        if appeared_count[max_length] >= 4:
            print max_length * max_length
        else:
            print max_length * next_maxt_length

if __name__ == '__main__':
    main()

Solution (Python):
import sys
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=1)
a=0
b=0
j=N-1
for i in range(N-1):
  if A[i]==A[i+1]:
    a=A[i]
    j=i
    break
for i in range(j+2,N-1):
  if A[i]==A[i+1]:
    b=A[i]
    break

print(a*b)

Solution (Python):
n = int(input())
xs = [int(i) for i in input().split()]
dict = {}
for i in range(n):
    if xs[i] in dict:
        dict[xs[i]] += 1
    else:
        dict[xs[i]] = 1
edges = []
for k in dict.keys():
    while dict[k] >= 2:
        edges.append(k)
        dict[k] /= 2
edges.sort()
edges.reverse()
if len(edges) >= 2:
    print(edges[0] * edges[1])
else:
    print(0)

Solution (Python):
from copy import deepcopy as dcopy


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

    A.sort(reverse=True)

    p = 0
    q = 0
    pre = A[0]
    for a in range(1, len(A)):
        bpre = dcopy(pre)
        pre = A[a]
        if A[a] == bpre:
            if p == 0:
                p = A[a]
                pre = 0
            else:
                q = A[a]
                break

    print(p*q)

        
if __name__ == "__main__":
    main()

Solution (Python):
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))
def plis(a): return " ".join(list(map(str, a)))

N = ri()
A = rli()
A.sort(reverse=True)

st = -1
l1 = 0
l2 = 0
for i in A:
    if i == st:
        if(l1 != 0):
            l2 = i
            break
        else:
            l1 = i
        st = -1
    else:
        st = i
print(l1*l2)

Solution (Python):

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

	bars.sort(reverse = True)

	d = {}
	used = []

	for bar in bars:
		if bar in d:
			d[bar] += 1
			if d[bar] == 2:
				used.append(bar)
				d[bar] = 0
		else:
			d[bar] = 1

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

if __name__ == '__main__':
	main()

Solution (Python):


N = int(input())
L = sorted(map(int, input().split()))[::-1]
a = 0
b = 0
while L:
    t = L.pop(0)
    if a == t:
        break
    else:
        a = t
while L:
    t = L.pop(0)
    if b == t:
        break
    else:
        b = t
    
print(a*b)

Solution (Python):
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
C = Counter(A)
t = 2
E = sorted(C.keys())
E.reverse()
ans = 1
for e in E:
    if(C[e] >= 4):
        t -= 1
        ans *= e
    if(t > 0 and C[e] >= 2):
        ans *= e
        t -= 1
    if(t <= 0):
        print(ans)
        break
else:
    print(0)

Solution (Python):



import sys
import re
import math
import collections
import itertools
import functools

DEBUG = True
DEBUG = False

def dbg(*args):
    if DEBUG:
        print("DBG: ", file=sys.stderr, end="")
        print(*args, file=sys.stderr)



def main():
    N = int(input())

    d = collections.defaultdict(int)
    for a in map(int, input().split()):
        d[a] += 1

    
    cands = filter(lambda item: item[1] >= 2, d.items())
    l = sorted(cands, key=lambda item: item[0], reverse=True)
    

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

if __name__ == "__main__": main()

Solution (Python):

from collections import defaultdict


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


def read():
    N = II()
    A = ILI()
    return N, A


def solve(N, A):
    count = defaultdict(int)
    for a in A:
        count[a] += 1
    l_len = [(key, value) for key, value in count.items() if value >= 2]
    l_len.sort(key= lambda x: -x[0])
    if len(l_len) <= 1:
        ans = 0
    else:
        if l_len[0][1] >= 4:
            ans = l_len[0][0] ** 2
        else:
            ans = l_len[0][0] * l_len[1][0]
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Solution (Python):
n=int(raw_input())
N=map(int,raw_input().split())
d={}
for i in N:
    d[i]=0
for i in N:
    d[i]+=1
res=res2=res3=0
for i in N:
    if d[i]>=2:
        res=max(res,i)
for i in N:
    if d[i]>=2 and i!=res:
        res2=max(res2,i)
for i in N:
    if d[i]>=4:
        res3=max(res3,i)
print max(res*res2,res3*res3)

Solution (Python):
n=int(input())
freq={}
for x in list(map(int,input().split())):
    if x not in freq:
        freq[x] = 1
    else:
        freq[x] += 1

s = []
ans = [0]
for i, v in sorted(list(freq.items()),reverse=True):
    if v >= 4:
        ans.append(i * i)
    if v >= 2:
        s.append(i)
        if len(s) == 2:
            ans.append(s[0] * s[1])

print(max(ans))

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

a.sort()
first = 0
second = 0
i = 0
while i + 1 < n:
    
    if (a[i] == a[i + 1]):
        second = first
        first = a[i]
        i += 1
    i += 1
        

print(first * second)

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

cnt = {}
for ai in a:
    if ai in cnt:
        cnt[ai] += 1
    else:
        cnt[ai] = 1

ls = []
for k, v in cnt.items():
    if 4 <= v:
        ls.append(k)
    if 2 <= v:
        ls.append(k)
if len(ls) <= 1:
    print(0)
else:
    ls = list(reversed(sorted(ls)))
    print(ls[0] * ls[1])

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

    cnt = {}
    for a in A:
        if a not in cnt:
            cnt[a] = 0
        cnt[a] += 1

    B = []
    for a, x in cnt.items():
        if x >= 2:
            B.append(a)

    B = sorted(B, reverse=True)
    if len(B) > 0 and cnt[B[0]] >= 4:
        print(B[0] ** 2)
    elif len(B) > 1:
        print(B[0] * B[1])
    else:
        print('0')


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
sticks = dict()
for a in map(int, input().split()):
    sticks[a] = sticks.get(a, 0) + 1
sticks = sorted([(k, v) for k, v in sticks.items() if v >= 2], reverse=True)
if len(sticks) == 0 or (len(sticks) == 1 and sticks[0][1] < 4):
    print(0)
elif sticks[0][1] >= 4:
    print(sticks[0][0] ** 2)
else:
    print(sticks[0][0] * sticks[1][0])

Solution (Python):



from math import *
import random

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

N = int(input())
A = sorted(readln())
x,y = 0,0
for i in range(1,N):
    if(A[i] == A[i-1]):
        y = x
        x = A[i]
        A[i] = 0
print(x*y)

Solution (Python):
from collections import Counter

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

m1 = -1
m2 = -1

for k in C.keys():
    if C[k] >= 4 and m1 < k:
        m1, m2 = k, k
    elif C[k] >= 2 and m1 < k:
        m1, m2 = k, m1
    elif C[k] >= 2 and m2 < k:
        m2 = k

if m1 < 0 or m2 < 0:
    print 0
else:
    print m1 * m2

Solution (Python):
from collections import Counter
n = int(input())
C = Counter(map(int,input().split()))
quad = [i for i in C if C[i] >= 4]
if quad: maxa = max(quad)**2
else: maxa = 0

twice = [i for i in C if C[i] >= 2]
twice.sort()
if len(twice) >= 2: maxa = max(maxa, twice[-1]*twice[-2])
print(maxa)

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

count = {}
for a in A:
    count[a] = count.get(a, 0) + 1
can = []
for a in count:
    can.extend([a]*(count[a]/2))
can.sort()
if len(can) < 2:
    print 0
else:
    print can[-1]*can[-2]

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

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    a = LI()
    d = collections.defaultdict(int)
    for c in a:
        d[c] += 1
    r = []
    for k,v in sorted(d.items(),reverse=True):
        if v >= 4:
            r.append(k)
            r.append(k)
            break
        elif v >= 2:
            r.append(k)
            if len(r) > 1:
                break
    if len(r) > 1:
        return r[0] * r[1]

    return 0

print(main())