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 = [int(i) for i in input().split()]	


a.sort(reverse=True)

s=0
t=0
x=0
y=0
for _ in range(N):
	i = a[_]
	if t==0:
		if(s==i):
			t = i
		else:
			s = i
	else:
		if(x==i):
			y = i
			break
		else:
			x = i


print(s * x)

Solution (Python):
import sys

N=input()

A=list(map(int,raw_input().split()))
A.sort()


hen=[]
tmp_hen=-1
for i in reversed(A):
	if len(hen)==2:
		break
	if tmp_hen==i:
		hen.append(i)
		tmp_hen=-1
	else:
		tmp_hen=i


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

Solution (Python):


import sys


n = int(input().strip())
ar = list(map(int, input().strip().split(' ')))
ar = sorted(ar,reverse=True)
k = []
se = set(k)
for i in range(len(ar)-1):
    if(ar[i] == ar[i+1]):
        if(ar.count(ar[i])>=4 and len(se) == 0):
            print(ar[i]*ar[i])
            exit(0)
        se.add(ar[i])
    if(len(se)>1):
        break

se = list(se)
if(len(se)<2):
    print("0")
else:
    print(se[0]*se[1])

Solution (Python):
n = int(input())
a_in = list(input().split())
a = list(map(int,a_in))
a.sort(reverse=True)
ans = 0
t = 0
c = 1

for i in range(n-1):
    if a[i] == a[i+1]:
        c = c + 1
        if t == 0:
            t = int(a[i])
        elif t != int(a[i]):
            ans = t * int(a[i])
            break
        elif c == 4:
            ans = t * t
            break
    else:
        c = 1

print(ans)

Solution (Python):
import numpy as np

n = input()
n = int(n)
a_list = input().split()
a_list = [int(a) for a in a_list]

a_dict = dict()
for a in a_list:
    if a in a_dict:
        a_dict[a] += 1
    else:
        a_dict[a] = 1


l = []
for k,v in a_dict.items():
    l.append([k,v])
ar = np.array(l)

menseki = 1
for i in range(2):
    ar = ar[ar[:,1]>=2]
    if len(ar) == 0:
        menseki = 0
        break
    else:
        saidai = ar[:,0].max()
        menseki *= saidai
        ar[ar[:,0]==saidai,1] -=2
print(menseki)

Solution (Python):
from collections import Counter


def main():
    N = int(input())
    counter = Counter(map(int, input().split()))

    a = 0
    b = 0

    def sort_func(t):
        return t[0]
    for length, n in sorted(counter.items(),
                            key=sort_func,
                            reverse=True):
        if n < 2:
            continue
        if a == 0:
            a = length
            if n >= 4:
                b = length
                break
        else:
            b = length
            break
    print(a * b)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
d = {}
a = 0
b = 0

for i in range(N):
    if A[i] not in d:
        d[A[i]] = 1
    else:
        d[A[i]] += 1
    if d[A[i]] == 2 or d[A[i]] == 4:
        if A[i] > a:
            b = a
            a = A[i]
        elif A[i] > b:
            b = A[i]

print(a * b)

Solution (Python):
N=int(raw_input())
A=[int(x) for x in raw_input().split()]
 
used=dict()
for a in A:
    if a in used:
        used[a] += 1
    else:
        used[a]=1

B=[]
for a in used:
    if used[a]>=4:
        B.append(a)
        B.append(a)
    elif used[a]>=2:
        B.append(a)

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

Solution (Python):


























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

e1 = A[0]
e2 = 0
hoge = False
skip = 0

for i in range(1,len(A)-1):
    
    if i == skip:
        
        continue
    else:
        if hoge == False:
            if A[i] == e1 :
                hoge = True
                e2 = A[i+1]
                skip = i+1
                
            else :
                e1 = A[i] 
        else:
            if A[i] == e2 :
                
                break
            else:
                e2 = A[i]
        if i == range(1,len(A)-1)[-1]:
            e2 = 0

print(e1*e2)

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

first_second_biggest_numpairs = []

flag = False
for i in range(N):
    if flag == True:
        flag = False
        continue
    if i + 1 < N:
        if A[i] == A[i + 1]:
            if len(first_second_biggest_numpairs) < 2:
                first_second_biggest_numpairs.append(A[i])
                flag = True
            else:
                break
            
if len(first_second_biggest_numpairs) == 2:
    print(str(first_second_biggest_numpairs[0] * first_second_biggest_numpairs[1]))
else:
    print("0")

Solution (Python):
tree_dict = dict()

input()
l = map(int, raw_input().split())

for x in l:
    if tree_dict.has_key(x):
        tree_dict[x] += 1
    else:
        tree_dict[x] = 1

long_line = 0
short_line = 0

for k,v in tree_dict.iteritems():
    if v >= 4:
        (_,_,short_line,long_line) = sorted((k,k,short_line,long_line))
        next
    if v >= 2:
        (_,short_line,long_line) = sorted((k,short_line,long_line))


print(long_line * short_line)

Solution (Python):

n = int(input())
data = list(map(int,input().split()))
dic = {}
max1=0
max2=0
for x in data:
    if x not in dic:
        dic[x]=1
    else:
        dic[x]+=1
    if dic[x]>=2:
        if max1<x:
            max2=max1
            max1=x
            dic[x]=0
        elif max2<x:
            max2=x
            dic[x]=0
        else:
            pass
print(max1*max2)

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

counter = {}

for i in l:
    if i in counter:
        counter[i] = counter[i] + 1
    else:
        counter[i] = 1

a = None
b = None
for k in sorted(counter.keys(), reverse=True):
    if counter[k] >= 4 and a == None and b == None:
        a = k
        b = k
    elif counter[k] >= 2 and a == None:
        a = k
    elif counter[k] >= 2 and a != None:
        b = k
    if (a != None and b != None):
        break

if (a != None and b!= None):
    print(a * b)
else:
    print('0')

Solution (Python):
import collections
n = int(raw_input())
sides = map(int, raw_input().split())
obj, squares, rectangles = collections.Counter(sides), list(), list()
for i in obj:
    if obj[i] >= 4:
        squares.append(i)
        rectangles.append(i)
    elif obj[i] >= 2:
        rectangles.append(i)
if (not rectangles and not squares) or (not squares and len(rectangles) < 2):
    print('0')
elif not squares and len(rectangles) >= 2:
    rectangles.sort(reverse=True)
    print(rectangles[0] * rectangles[1])
elif not rectangles and squares:
    squares.sort(reverse=True)
    print(squares[0] ** 2)
else:
    rectangles.sort(reverse=True)
    squares.sort(reverse=True)
    print(rectangles[0] * rectangles[1] if rectangles[0] * rectangles[1] > squares[0] ** 2 else squares[0] ** 2)

Solution (Python):
import sys

sys.stdin.readline()
d = list(map(int, sys.stdin.readline().strip().split()))

x = dict()
for i in d:
    if i not in x:
        x[i] = 1
    else:
        x[i] += 1

y = {i:j for i, j in x.items() if j>=2}

z = sorted(y.keys())


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

Solution (Python):
n = int(raw_input())
d = map(int, raw_input().split())
dict = {}
for i in range(n):
    if dict.has_key(d[i]):
        dict[d[i]] += 1
    else:
        dict[d[i]] = 1
dict = sorted(dict.items())
ans = []
for i in range(len(dict)-1, -1, -1):
    if dict[i][1] > 3:
        if len(ans) == 0:
            ans = [dict[i][0], dict[i][0]]
            break
        else:
            ans.append(dict[i][0])
            break
    elif dict[i][1] > 1:
        if len(ans) > 0:
            ans.append(dict[i][0])
            break
        else:
            ans.append(dict[i][0])
if len(ans) > 1:
    print ans[0]*ans[1]
else:
    print 0

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

a,b = 0,0
A.sort(reverse=True)
for i in range(N-1):
    if A[i] == A[i+1]:
        a = A[i]
        A.remove(a)
        A.remove(a)
        break
for i in range(N-3):
    if A[i] == A[i+1]:
        b = A[i]
        break

print(a*b)

Solution (Python):
N = int(input())
freq = {}
arr = map(int,input().split())
for i in arr:
    try:
        freq[i] += 1
    except KeyError:
        freq[i] = 1

to_multiply = []      
for i in sorted(freq.keys(),reverse=True):
    if freq[i] >= 4:
        to_multiply.append(i)
        to_multiply.append(i)
    elif freq[i] >= 2:
        to_multiply.append(i)
if len(to_multiply) >= 2:
    print(to_multiply[0] * to_multiply[1])
else:
    print("0")

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())
a = map(int,input().split())
a = list(a)
a = sorted(a,reverse=True)

x = 0
tmp = 0
for i in range(len(a)):
    
    
    if tmp == a[0]:
        x = a[0]
        a.remove(a[0])
        break
    else:
        tmp = a[0]
        a.remove(a[0])

b = 0
tmp = 0
for i in range(len(a)):
    if tmp == a[0]:
        b = a[0]
        break
    else:
        tmp = a[0]
        a.remove(a[0])



print(x*b)

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

Solution (Python):
from collections import Counter
N = int(input())
A = map(int, input().split())
A=Counter(A)
t = []
for k, v in A.items():
    if v > 1:
        t.append(k)
        if v > 3:
            t.append(k)
A = sorted(t,reverse=True)
if len(A) < 2:
    print(0)
else:
    print(A[0] * A[1])

Solution (Python):
N = int(input())
listA = input().split()
listA = [int(i) for i in listA]
listA.sort()
listA.reverse()
side1 = 0
side2 = 0


if N == 1 or N == 2 or N == 3:
    pass
else:
    while len(listA) != 1:
        if listA[0] == listA[1]:
            if side1 == 0:
                side1 = listA[0]
                listA.pop(0)
                listA.pop(0)
            else:
                side2 = listA[0]
                break
        else:
            listA.pop(0)
        

print(side1 * side2)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
A_dict = dict()
for i in A:
    if i in A_dict:
        A_dict[i] += 1
    else:
        A_dict[i] = 1
A_ordered = sorted([i for i in A_dict if A_dict[i] >=2], reverse = True)
candidate_ans = [0]
if len(A_ordered) >= 2:
    candidate_ans.append(A_ordered[0] * A_ordered[1])
for i in A_ordered:
    if A_dict[i] >= 4:
        candidate_ans.append(i ** 2)
        break
print(max(candidate_ans))

Solution (Python):


N=int(input())

mozir=input()
hyo=mozir.split(' ')
A=[int(mono) for mono in hyo]

ans=0
kireiA=sorted(A,reverse=True)
mae=0
tmphen=0
for bo in kireiA:
    if mae==bo:
        if tmphen == 0:
            tmphen=mae
            mae=0 
            continue
        else:
            ans=tmphen*mae
            break

    mae=bo

print(ans)

Solution (Python):
import collections as col


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

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

edges.sort(reverse=True)

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

Solution (Python):


_ = input()
a = list(map(int, input().split()))
counter = {}

for a_ in a:
    if a_ in counter.keys():
        counter[a_] += 1
    else:
        counter[a_] = 1

ans = 1
cnt = 0

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

for k, v in counter:
    while v >= 2:
        if cnt == 2:
            break

        ans *= k
        cnt += 1
        v -= 2

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

Solution (Python):
n=input()
lens=raw_input().split()
lens=[int(x) for x in lens]
lens.sort()
lens=lens[::-1]
i=0
needed=[]
while i<n-1:
    if lens[i] == lens[i+1]:
        needed.append(lens[i])
        i+=1
    i+=1
if len(needed)<2:print '0'
else: print needed[0]*needed[1]

Solution (Python):
n=int(raw_input())
a=map(int,raw_input().split())
b={}
for i in a :
    if i in b :
        b[i] += 1
    else :
        b[i] = 1
c = []
for i,j in b.items():
    if j>=2 :
        c.append(i)
    if j>=4 :
        c.append(i)
        
c=sorted(c)
if len(c) >= 2 :
    c = sorted(c)
    print c[-1]*c[-2]
else :
    print 0

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

l = 0
ans = []
for i in a:
    if l == i:
        ans.append(i)
        l = 0
    else:
        l = i
    if len(ans) == 2:
        print(ans[0] * ans[1])
        exit()
print(0)

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

prev = 0
es = []
for a in reversed(sorted(A)):
    if(prev == a):
        es.append(a)
        prev = 0
        if len(es) == 2:
            print(es[0] * es[1])
            break
    else:
        prev = a
else:
    print(0)

Solution (Python):
import sys
inp = lambda t: t(sys.stdin.readline().strip())
inpm = lambda t: map(t, sys.stdin.readline().split())
inpl = lambda t: list(map(t, sys.stdin.readline().split()))

n = inp(int)
l = inpl(int)

s = set()

a = 0
b = 0

for i in l:
	if i in s:
		if i > a and a < b:
			a = i
		elif i > b:
			b = i
		s.remove(i)
	else:
		s.add(i)

print(a * b)

Solution (Python):

from collections import defaultdict


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

    lens = defaultdict(int)

    for x in xs:
        lens[x] += 1

    max_a = 0
    max_b = 0

    sides = sorted(
        [(length, num) for length, num in lens.items() if num >= 2],
        reverse=True,
    )

    if len(sides) >= 1 and sides[0][1] >= 4:
        max_a = sides[0][0]
        max_b = max_a
    elif len(sides) >= 2:
        max_a = sides[0][0]
        max_b = sides[1][0]

    print(max_a * max_b)


if __name__ == "__main__":
    main()

Solution (Python):

N = int(input())
tmp = 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):
N = int(input())
A = list(map(int, input().split()))

A = sorted(A, reverse=True)


pairs = []

flag = True

for i in range(1, len(A)):
    if flag:
        if A[i] == A[i-1]:
            pairs.append(A[i])
            flag = False
    else:
        flag = True
        
if len(pairs) < 2:
    print(0)
else:
    print(pairs[0]*pairs[1])