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()))
Acount = {}
q = []
 
for a in A:
  if a not in Acount:
    Acount[a] = 0
  
  Acount[a] += 1
    
for key, val in Acount.items():
  if val >= 2:
    q.append(key)
    
  if val >= 4:
    q.append(key)
 
q.sort(reverse=True)
 
if len(q) < 2:
  print(0)
else:
  print(q[0]*q[1])

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

a = input().split()

d = {}
for i in a:
    d[i] = d.get(i,0)+1
    
for i in d:
    d[i] = d[i]//2

s = []
for i in d:
    s += [int(i)]*int(d.get(i))
if(len(s)>=2):
    s.sort()
    print(s[-1]*s[-2])
else:
    print(0)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
B = [0,0]
i = 0
A.sort()
while(i < len(A) - 1):
  if A[i] == A[i + 1]:
    B.append(A[i])
    i += 1
  i += 1
print(B[len(B) - 1] * B[len(B) - 2])

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v



def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk



def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False



dp = None


def main():
    N = int(input())
    A = sorted(li_input(), reverse=1)
 
    D = collections.defaultdict(lambda: 0)
    E = []

    for a in A:
        D[a] += 1
 
    for d in D.keys():
        for i in range(min(2, D[d] // 2)):
            E.append(d)
            
    if len(E) >= 2:
        E.sort(reverse=True)
        print(E[0] * E[1])
    else:
        print(0)
 
 
main()

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v



def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk



def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False



dp = None








 


 





 

 


def main():
    N = int(input())
    A = sorted(li_input(), reverse=1)
 
    D = collections.defaultdict(lambda: 0)
    X = []

    for a in A:
        D[a] += 1
 
    for d in D.keys():
        if D[d] >= 4:
            X.append(d)
            X.append(d)
            continue
 
        if D[d] >= 2:
            X.append(d)
            continue
        
 
    if len(X) >= 2:
        X.sort(reverse=True)
        print(X[0] * X[1])
    else:
        print(0)
 
 
main()

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v



def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk



def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False



dp = None


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

    D = collections.defaultdict(lambda: 0)
    X = [0, 0]
 
    for a in A:
        D[a] += 1
 
    for k, v in D.items():
        if 2 <= v:
            X.append(k)
        if 4 <= v:
            X.append(k)
 
    X.sort(reverse=True)
 
    print(X[0] * X[1])
 
 
main()

Solution (Python):
N = int(input())
A = {}
a = [int(i) for i in input().split()]
for i in range(N):
    if a[i] in A:
        A[a[i]] += 1
    else:
        A[a[i]] = 1

ans = []
A = list(sorted(list(A.items()), reverse=True))
for i in range(N):
    if A[i][1] >= 2:
        ans.append(A[i][0])
    if A[i][1] >= 4:
        ans.append(A[i][0])

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

Solution (Python):
N=int(input())
dic={}

for x in map(int,input().split()):
    if dic.get(x,0)==0:
        dic[x]=1
    else:
        dic[x]+=1
arr=[]
for k in dic.keys():
    if dic[k] >=4:
        arr.append(k)
        arr.append(k)
    elif dic[k] >=2:
        arr.append(k)

arr=sorted(arr)
if len(arr) < 2:
    ans=0
else:
    ans=arr[-1]*arr[-2]
print(ans)

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

index=0
beforeC =""
count=0
a=0
b=0
while index < n:
    if listA[index] == beforeC:
        count+=1
        if count == 2:
            if a ==0:
                a = listA[index]
            elif b ==0:
                b = listA[index]
                break
            count=0
            beforeC = ""
    else:
        beforeC = listA[index]
        count = 1
    index+=1

print(a*b)

Solution (Python):
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n = ni()
a = list(li())

cnt = Counter(a)

lst = []
for k,v in cnt.items():
    lst.append((k,v))

lst.sort(reverse=True)

first = 0
second = 0

for k,v in lst:
    if v >= 4 and first == 0:
        first = k
        second = k
        break
    
    elif v >= 4:
        second = k
        break
        
    elif v >= 2 and first != 0:
        second = k
        break
    
    elif v >= 2:
        first = k
        
print(first*second)

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

ctr = Counter(A)
lng = short = 0
for k,v in sorted(ctr.items(), reverse=True):
    if v == 1: continue
    if lng == 0 and v >= 4:
        print(k*k)
        exit()
    if lng == 0:
        lng = k
    else:
        short = k
        break
print(lng * short)

Solution (Python):

"""
Created on Sun Sep 30 10:49:33 2018
ABC071C
@author: maezawa
"""
import collections
n = int(input())
a = list(map(int,input().split()))
acount = collections.Counter(a)
auniq = list(acount.keys())
auniq.sort(reverse=True)
edge1 = 0
ans = 0
for edge in auniq:
    if acount[edge] >= 4:
        if edge1 == 0:
            ans = edge*edge
            break
        else:
            ans = edge1*edge
            break
    if acount[edge] >= 2:
        if edge1 == 0:
            edge1 = edge
        else:
            ans = edge1*edge
            break
print(ans)

Solution (Python):
import collections
n = int(input())
a = collections.Counter(list(map(int, input().split())))
candidates = []
for k,v in a.items():
    if v < 2:
        continue
    candidates.append(k)
    if v >= 4:
        candidates.append(k)
candidates = sorted(candidates)
if len(candidates) < 2:
    ans = 0
else:
    ans = candidates[-1] * candidates[-2]
print(ans)

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

anss = []
t = -1
for i in range(n):
    if t == a[i]:
        anss.append(t)
        t = -1
        if len(anss) >= 2:
            break
    else:
        t = a[i]

if len(anss) >= 2:
    ans = 1
    for x in anss:
        ans *= x
else:
    ans = 0
print(ans)

Solution (Python):
import collections

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

dic = collections.Counter(A)

tmp1,tmp2 = 0,0
for a in A[::-1]:
    if dic[a] >= 2 and tmp1 == 0:
        tmp1 = a
        dic[a] -= 2

    if dic[a] >=2:
        tmp2 = a
        break
ans = tmp1*tmp2

print(ans)

Solution (Python):
import collections
N = int(input())
A = collections.Counter(list(map(int, input().split())))
seihou = []
tyouhou = []
ans = 0


for i in A.keys():
    if A[i] >= 2:
        tyouhou.append(i)
    if A[i] >= 4:
        seihou.append(i)

if len(seihou) >= 1:
    ans = max(seihou)**2

if len(tyouhou) >= 2:
    c = max(tyouhou)
    tyouhou.remove(c)
    ans = max(ans, c*max(tyouhou))
print(ans)

Solution (Python):
import collections
N = int(input())
A = collections.Counter(list(map(int, input().split())))
seihou = []
tyouhou = []
ans = 0

for i in A.keys():
    if A[i] >= 2:
        tyouhou.append(i)
    if A[i] >= 4:
        seihou.append(i)

if len(seihou) >= 1:
    ans = max(seihou)**2

if len(tyouhou) >= 2:
    c = max(tyouhou)
    tyouhou.remove(c)
    ans = max(ans, c*max(tyouhou))
print(ans)

Solution (Python):
il = lambda: list(map(int, input().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

n = int(input())
a = il()
dic = dict()
for i in a:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
l = []
for i, j in sorted(dic.items())[::-1]:
    if j >= 4:
        l.append(i)
        l.append(i)
    elif j >= 2:
        l.append(i)
    if len(l) == 2:
        break
print(l[0] * l[1] if l else 0)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
A = A[::-1]
a = []
i = 0
while True:
    if i >= len(A) - 1:
        break
    if len(a) > 2:
        break
    if A[i] == A[i + 1]:
        a.append(A[i])
        del A[i]
        del A[i]
        i -= 1
    i += 1
if len(a) < 2:
    print(0)
else:
    print(a[0] * a[1])

Solution (Python):
from collections import defaultdict
N = int(input())
A = sorted([int(i) for i in input().split()], reverse=True)
A_dict = defaultdict(lambda:0)
for a in A:
    A_dict[a] += 1
key1 = 0
key2 = 0
for key in sorted(A_dict.keys(), reverse=True):
    if key2 > 0:
        break

    if A_dict[key] > 3:
        if key1 == 0:
            key1 = key
        if key2 == 0:
            key2 = key
    elif A_dict[key] > 1:
        if key1 > 0:
            key2 = key
        else:
            key1 = key
print(key1*key2)

Solution (Python):

N=int(input())
A=list(map(int,input().split()))
A_sorted=sorted(A,reverse=True)
long_line=0
lines=1
for i in range(N-1):
    if A_sorted[i]==A_sorted[i+1]:
        lines+=1
    if A_sorted[i]!=A_sorted[i+1] or i==N-2:
        if lines>=4:
            if long_line>0:
                print(long_line*A_sorted[i])
                exit()
            else:
                print(pow(A_sorted[i], 2))
                exit()
        elif lines>=2:
            if long_line>0:
                print(long_line * A_sorted[i])
                exit()
            else:
                long_line=A_sorted[i]
        lines=1
print(0)

Solution (Python):
from collections import Counter
N = int(input())
A_list = list(map(int, input().split()))
counter = Counter(A_list)
counter = sorted(counter.items(), key=lambda x: -x[0])

long_side = 0
short_side = 0
choice = 0

for k, v in counter:
    if v >= 4 and choice == 0:
        long_side = k
        short_side = k
        choice = 4

    elif v >= 2:
        if choice == 2:
            short_side = k
            choice = 4
        else:
            long_side = k
            choice = 2

    if choice == 4:
        print(long_side*short_side)
        exit()
print(0)

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

bar_length_count = dict()
for a in A:
    bar_length_count[a] = bar_length_count.get(a, 0) + 1

for val in bar_length_count.values():
    pass

count_at_least_2 = 0
for val in bar_length_count.values():
    if val >= 2:
        if val >= 4:
            count_at_least_2 += 2
        else:
            count_at_least_2 += 1

if count_at_least_2 < 2:
    import sys
    print(0)
    sys.exit(0)

else:
    bar_length_count = sorted({k:v for k, v in bar_length_count.items() if v >= 2}.items(), key=lambda x: x[0], reverse=True)
    if bar_length_count[0][1] >= 4:
        print(bar_length_count[0][0]**2)
    else:
        print(bar_length_count[0][0]*bar_length_count[1][0])

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


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

    s1 = list(sorted([k for k, v in C.items() if v >= 2], reverse=True))
    s2 = list(sorted([k for k, v in C.items() if v >= 4], reverse=True))

    ans = 0
    if len(s1) >= 2:
        ans = max(ans, s1[0] * s1[1])
    if len(s2) >= 1:
        ans = max(ans, s2[0] ** 2)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse=True)
pre = 0
e1, e2 = 0, 0
for a in A:
  if pre == a:
    if e1 == 0:
      e1 = a
    elif e2 == 0:
      e2 = a
    pre = 0
  else:
    pre = a
print(e1 * e2)

Solution (Python):
N = int(input())
A = sorted([int(Ai) for Ai in input().split()], reverse=True)
x, y = 0, 0
current = A[0]
for Ai in A[1:]:
    if current is None or current != Ai:
        current = Ai
    else:
        if x == 0:
            x = current
            current = None
        else:
            y = current
            break
print(x * y)

Solution (Python):
from collections import Counter

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

ans = []
for k, v in sorted(Counter(A).items(), reverse=True):
    if v >= 4:
        ans.append(k)
        ans.append(k)
    elif v >= 2:
        ans.append(k)
    if len(ans) >= 2:
        break
if len(ans) >= 2:
    print(ans[0] * ans[1])
else:
    print(0)

Solution (Python):
from collections import Counter

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

count = sorted(Counter(A).items())
more_than_2 = [0, 0]

for item in count:
    if item[1] >= 2:
        more_than_2.append(item[0])
    if item[1] >= 4:
        more_than_2.append(item[0])

print(more_than_2[-1] * more_than_2[-2])

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

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

sticks = {}
for i in range(n):
    if not a[i] in sticks.keys():
        sticks[a[i]] = 1
    else:
        sticks[a[i]] += 1

edge1, edge2 = 0, 0
lengths = sorted(sticks.keys())[::-1]
for l in lengths:
    if sticks[l] >= 4:
        if edge1 == 0:
            edge1, edge2 = l, l
            break
        else:
            edge2 = l
            break
    elif sticks[l] >= 2:
        if edge1 == 0:
            edge1 = l
        else:
            edge2 = l
            break

print(edge1*edge2)

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

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

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

A.sort(reverse=True)

cnt = 0
x = [0] * 2

i = 0

while i < N-1:
  
  if A[i] == A[i+1]:
    x[cnt] = A[i]
    i += 2
    cnt += 1
  else:
    i += 1
  
  if cnt >= 2:
    break
  
print(x[0]*x[1])

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

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

A.sort(reverse=True)

cnt = 0
x = [0] * 2

i = 0

while i < N-1:
  
  if A[i] == A[i+1]:
    x[cnt] = A[i]
    i += 2
    cnt += 1
  else:
    i += 1
  
  if cnt >= 2:
    break
  
print(x[0]*x[1])

Solution (Python):
def c_make_a_rectangle(N, A):
    from collections import Counter
    stick = Counter(A)  
    rectangle = []
    for length, num in sorted(stick.items(), reverse=True):  
        rectangle.extend([length] * (num // 2))  
    ans = 0 if len(rectangle) <= 1 else rectangle[0] * rectangle[1]
    return ans

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

Solution (Python):
from collections import Counter

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

cnt_all = Counter(a)
cnt2 = [k for k, v in cnt_all.items() if v >= 2]
cnt4 = [k for k, v in cnt_all.items() if v >= 4]
cnt2.sort(reverse=True)
cnt4.sort(reverse=True)

if len(cnt2) < 2:
    print(0)
elif len(cnt4) == 0:
    print(cnt2[0] * cnt2[1])
else:
    if cnt4[0] == cnt2[0]:
        print(cnt4[0] * cnt4[0])
    else:
        print(cnt2[0] * cnt2[1])

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(10000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]




dp = None


def main():
    N = int(input())
    A = li_input()
    D = collections.defaultdict(lambda: 0)
    C = [0, 0]

    for a in A:
        D[a] += 1

    for k, v in D.items():
        if 2 <= v:
            C.append(k)
        if 4 <= v:
            C.append(k)

    C.sort(reverse=True)

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


main()

Solution (Python):
from collections import Counter
N=int(input())
C=Counter(map(int,input().split()))
R=[]
for k in sorted(C)[::-1]:
    if C[k]>=4:
        if R:
            R+=[k]
        else:
            R=[k,k]
        break
    elif C[k]>=2:
        R+=[k]
        if len(R)==2:
            break
if len(R)==2:
    print(R[0]*R[1])
else:
    print(0)

Solution (Python):
from collections import defaultdict
N = int( input())
A = list( map( int, input().split()))
D = defaultdict(lambda: 0)
ansL = 0
ansS = 0
for a in A:
    D[a] += 1
    if D[a] == 2:
        if a >= ansL:
            ansL, ansS = a, ansL
        else:
            ansS = max( ansS, a)
    if D[a] == 4:
        if a >= ansL:
            ansL, ansS = a, a
        else:
            ansS = max( ansS, a)
print(ansL*ansS)

Solution (Python):
from itertools import groupby

n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
g = groupby(a)
s = [0,0]

for k,v in g:
    l = len(list(v))
    while l>1:
        s.append(k)
        l -= 2

s = sorted(s)
print(s[-1] * s[-2])

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

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

b.sort()

c = 1
d = 0
dd = 0

p = b[0]

for i in range(1,a):
	if p == b[i]:
		c += 1
	elif p != b[i]:
		p = b[i]
		c = 1
	if c == 2:
		d = dd
		dd = p
	elif c == 4:
		d = p
		dd = p

print(d*dd)

Solution (Python):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

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

N = int(input())
aa = inpl()
aa.sort(reverse = True)
bef = 0
ss = []

for a in aa:
	if bef == a:
		ss.append(a)
		if len(ss) == 2:
			print(ss[0]*ss[1])
			sys.exit()
		bef = 0
	else:
		bef = a

print(0)

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

x=0
y=0
a.sort()
i=n-1
while (i>0):
  if a[i-1]==a[i]:
    x=y
    y=a[i]
    if x>0:
      break
    i-=2
  else:
    i-=1

print(x*y)

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

x=0
y=0
a.sort()
i=len(a)-1
while (i>0):
  if a[i-1]==a[i]:
    x=y
    y=a[i]
    i-=2
  else:
    i-=1
  if x>0:
    break

print(x*y)

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

A.sort(reverse=True)

x = 0
y = 0
v = 0
for a in A:
    
    if v == 0 or v != a:
        v = a
        continue
    if x == 0:
        x = v
        v = 0
        
        continue
    else:
        y = v
        
        break
print(x*y)

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

x=0
y=0
a.sort()
i=1
while (i<len(a)):
  if a[i-1]==a[i]:
    x=y
    y=a[i]
    i+=2
  else:
    i+=1

print(x*y)

Solution (Python):
from collections import Counter
N = int(input())
A = [int(Ai) for Ai in input().split()]
c = Counter(A).most_common()
c.sort(key=lambda x: x[0], reverse=True)
e1 = None
result = None
for k, v in c:
    if e1 is None and v >= 4:
        result = k**2
        break
    elif v >= 2:
        if e1 is None:
            e1 = k
        else:
            result = e1 * k
            break
if result is not None:
    print(result)
else:
    print(0)

Solution (Python):
from collections import Counter

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

c = Counter(A)
ans = []
for k, v in sorted(c.items(), reverse=True):
    if v > 3 and len(ans) == 0:
        ans.append(k)
        ans.append(k)
    elif v > 1:
        ans.append(k)
    if len(ans) == 2:
        break

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

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

w = 0
while len(a) > 1:
    if a[-1] == a[-2]:
        w = a[-1]
        a.pop()
        a.pop()
        break
    else:
        a.pop()
h = 0
while len(a) > 1:
    if a[-1] == a[-2]:
        h = a[-1]
        a.pop()
        a.pop()
        break
    else:
        a.pop()

print(w*h)
exit(0)

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

a_sorted = sorted(a, reverse=True)
x = 0
y = 0

while True:
    if len(a_sorted) <= 1:
        break
    max = a_sorted[0]
    if x != 0 and y != 0:
        break
    if a_sorted[1] == max:
        if x == 0:
            x = max
        else:
            y = max
        a_sorted.remove(max)
        a_sorted.remove(max)
    else:
        a_sorted.remove(max)
print(x * y)

Solution (Python):
from collections import Counter
N = int(input())
a = Counter(map(int, input().split()))
h, w = 0, 0
for k, v in sorted(a.items(), key=lambda x: -x[0]):
    if v >= 4 and not h and not w:
        h, w = k, k
        break
    elif v >= 2:
        if not h:
            h = k
        elif not w:
            w = k
            break

print(h * w)

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

a.sort()
maxs = []
for i in range(2):
	max_1 = a.pop()
	while True:
		max_2 = a.pop()
		if max_1 == max_2:
			maxs.append(max_1)	
			break
		max_1 = max_2
		if len(a) == 0:
			print(0)
			exit()
print(maxs[0]*maxs[1])

Solution (Python):

from collections import Counter

def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    a_element = list(set(a_list))
    a_element.sort(reverse=True)

    counter = Counter(a_list)

    ans = []
    xy = []
    for i in a_element:
        if counter[i] >= 4:
            ans.append(i * i)
        if counter[i] >= 2:
            xy.append(i)
        if len(xy) == 2:
            ans.append(xy[0] * xy[1])
            break
    if len(ans) == 0:
        print(0)
    else:
        print(max(ans))



if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n=int(input())
l=map(int,input().split())
o=sorted(filter(lambda x:x[1]>=2,Counter(l).items()))

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

Solution (Python):
from collections import Counter

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

cntr = Counter(A)


key_list = list(cntr.keys())

key_list.sort(reverse=True)

ans_cand = []
ans = 0
for key in key_list:
    if cntr[key] >= 4:
        ans_cand.append(key)
    if cntr[key] >= 2:
        ans_cand.append(key)
        
if len(ans_cand) < 2:
    ans = 0
else:
    ans = ans_cand[0] * ans_cand[1]
    
print(ans)

Solution (Python):
def inpl():
    return input().split()

n = int(input())
a = list(map(int, inpl()))
a = sorted(a, reverse=True)

ans = 1
cnt = 0
bf = a[0]
i = 1
while (i < n) and (cnt < 2):
    a_i = a[i]
    if bf == a_i:
        ans *= a_i
        bf = -1
        cnt += 1
    else:
        bf = a_i
    i += 1
print(ans if cnt == 2 else 0)