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



Sample input:
6
3 1 2 4 2 1


Sample output:
2

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int, input().split()))
a = reversed(list(set(A)))
B = []
for k in range(len(a)):
    i = a[k]
    if A.count(i) >= 4:
        if len(B) == 0:
            print(i**2)
            exit()
        else:
            B.append(i)
            if len(B) >= 2:
                print(B[0]*B[1])
                exit()

    if A.count(i) >= 2:
        B.append(i)
        if len(B) >= 2:
            print(B[0]*B[1])
            exit()
if len(B) <= 1:
    print(0)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int, input().split()))
a = sorted(list(set(A)),reverse = True)
B = []
for i in a:
    if A.count(B[0]) >= 4:
        print(i**2)
        exit()
    if A.count(i) >= 2:
        B.append(i)
        if len(B) >= 2:
            print(B[0]*B[1])
            exit()
if len(B) <= 1:
    print(0)

Submission status: Runtime Error

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

AS = list(set(A))
D = {}
for i in A:
    if i in D.keys():
        D[i] += 1
    else:
        D[i] = 1

accum = []
AS.sort(reverse=True)
for i in AS:
    if D[i] >= 2:
       accum.append(i)


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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
a_set = set(a)
sides = []

for i in a_set:
    if a.count(i) > 1:
        sides.append(i)

if len(sides) <= 1:
    print(0)

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

Submission status: Runtime Error

Solution code:
from collections import Counter

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

c=Counter(a)
l=c.most_common()
rectangle=[]
square=[]
x=len(l)
for i in range(x):
    if l[i][1]>=2:
        rectangle.append(l[i][0])
    if l[i][1]>=4:
        square.append(l[i][0])
rectangle.sort()
square.sort()
ans1=rectangle[-1]*rectangle[-2]
ans2=square[-1]**2
if ans1<ans2:
    print(ans2)
else:
    print(ans1)

Submission status: Runtime Error

Solution code:
input()
a = list(map(int, input().split()))
a.sort(reverse=True)
i, c = 0, 0
m = list()
while i < n-1:
    if a[i] == a[i+1]:
        m.append(a[i])
        i += 1
        c += 1
    i += 1
    if c == 2:
        break
if c == 2:
    print(m[0]*m[1])
else:
    print(0)

Submission status: Runtime Error

Solution code:
a = []
tmp = 0
input()
a = list(map(int, input().split()))
a.sort(reverse=True)
for i in range(len(a)):
    if a[i] == a[i+3] and tmp == 0:
        print(a[i]**2)
        exit()
    elif a[i] == a[i+1]:
        if tmp == 0:
            W = a[i]
            tmp = 1
            del a[i+1]
        else:
            H = a[i]
            break
print(W*H)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
a = a[::-1]
i = 0
c = 0
m = list()
while i < n:
    if a[i]==a[i+1]:
        m.append(a[i])
        i += 1
        c += 1
    i += 1
    if c == 2:
        break
print(m[0]*m[1])

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
a = a[::-1]
i = 0
c = 0
m = list()
while i < n:
    if a[i]==a[i+1]:
        m.append(i)
        i += 1
        c += 1
    i += 1
    if c == 2:
        break
print(m[0]*m[1])

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
res = [0]*(n+1)
ans = [0,0]
for i in a:
    res[i] += 1
for i in range(len(res)):
    if res[i]>1:
        ans.append(i)
ans = sorted(ans,reverse=True)
print(ans[0]*ans[1])

Submission status: Runtime Error

Solution code:
def solve():
    N = int(input())
    a = [int(x) for x in input().split()]

    import collections
    count = collections.Counter(a)

    valid = {k:v for k, v in count.items() if v >= 2}

    # print(valid)

    m = sorted(valid.keys(), reverse=True)
    a, b = m[0], m[1]

    return a*b


def main():
    print(solve())


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
X = list(set(A))

d = {}
for x in X:
  num = A.count(x)
  d[x] = num
result = []
for k, v in d.items():
  if(v >= 4):
    result.append(k)
    result.append(k)
  elif(v >= 2):
    result.append(k)
result.sort()
print(result[-1] * result[-2])

Submission status: Runtime Error

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

two = [0]*N
four = [0]*N 
for x in list(set(A)):
  num = A.count(x)
  if(num >= 4):
    four[x] = x
  elif(num != 1):
    two[x] = x
two.sort()
four.sort()
print(max(four[-1]**2, two[-1]*two[-2]))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
a = a[::-1]
s = set(a)
s = list(s)
t = set()
for i in range(len(s)):
    if a.count(s[i]) >= 4 and len(t) == 0:
        print(s[i]**2)
        exit()
    elif a.count(s[i]) >= 2:
        t.get(s[i])
        if len(t) >= 2:
            print(t[0]*t[1])
            exit()

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
a = a[::-1]
s = set(a)
s = list(s)
t = set()
for i in range(len(s)):
    if a.count(s[i]) >= 4 and len(t) == 0:
        print(s[i]**2)
        exit()
    elif a.count(s[i]) >= 2:
        t.get(s[i])
        if len(t) >= 2:
            print(s[0]*s[1])
            exit()

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
x1, x2, x3 = 0, 0, 0
for k, v in c.items():
    if v >= 4:
        if k > maxval1:
            x1 = k
    if v >= 2:
        if k > maxval1:
            x1, x2 = k, x1
        elif k > maxval2:
            x2 = k
        else:
            pass
print(max(x1*x1, x2*x3))

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int,input().split()))
A = Counter(A).most_common()
ans = 0

for i,j in sorted(A,reverse=True):
  if j >=4 and ans ==0:
    ans = i*i
    break
  elif j >= 2 and ans == 0:
    ans = i
  elif j >= 2:
    ans *= i
    break
print(ans)
print(sorted(A,reverse=True))

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(i) for i in input().split()]

A.sort(reverse=True)

x=0
y=0
for i in range(N):
      if A[0]==A[1]:
          x=A[0]
          A.remove(x)
          A.remove(x)
          break
      else:
          A.remove(A[0])
if len(A)!=0:
    for i in range(len(A)):
        if A[0]==A[1]:
            y=A[0]
            break
        else:
            A.remove(A[0])

print(x*y)

Submission status: Runtime Error

Solution code:
import dicimal 

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

A.sort(reverse=True)

x=0
y=0
for i in range(N):
      if A[0]==A[1]:
          x=A[0]
          A.remove(x)
          A.remove(x)
          break
      else:
          A.remove(A[0])

for i in range(len(A)):
    if A[0]==A[1]:
        y=A[0]
        break
    else:
        A.remove(A[0])

print(dicimal(x*y))

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(i) for i in input().split()]

A.sort(reverse=True)

x=0
y=0
for i in range(N):
      if A[0]==A[1]:
          x=A[0]
          A.remove(x)
          A.remove(x)
          break
      else:
          A.remove(A[0])

for i in range(len(A)):
    if A[0]==A[1]:
        y=A[0]
        break
    else:
        A.remove(A[0])

print(x*y)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(i) for i in input().split()]

A.sort(reverse=True)

x=0
y=0
for i in range(len(A)):
      x=A[0]
      if A[0]==A[1]:
          A.remove(x)
          A.remove(x)
          if A[0]==A[1]:
                y=A[0]
                break
          else:
                A.remove(x)
      else:
          A.remove(x)
print(x*y)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(i) for i in input().split()]

A.sort(reverse=True)

x=0
y=0
for i in range(len(A)):
      x=A[0]
      if A[0]==A[1]:
          A.remove(x)
          A.remove(x)
          if A[0]==A[1]:
                y=A[0]
                break
      else:
          A.remove(x)
print(x*y)

Submission status: Runtime Error

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
br = sorted(set(ar))
cr = []
for b in br:
    if ar.count(b) >= 2:
        cr.append(b)
if len(cr) == 0:
    print(0)
else:
	if ar.count(max(cr)) >= 4:
    	print(max(cr) ** 2)
	else:
    	dr = sorted(cr,reverse=True)
    	print(dr[0] * dr[1])

Submission status: Runtime Error

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
br = sorted(set(ar))
cr = []
for b in br:
    if ar.count(b) >= 2:
        cr.append(b)
if ar.count(max(cr)) >= 4:
    print(max(cr) ** 2)
else:
    dr = sorted(cr,reverse=True)
    print(dr[0] * dr[1])

Submission status: Runtime Error

Solution code:
for b in br:
    if ar.count(b) >= 4:
        cr.append(b)
        dr.append(b)
    elif ar.count(b) >= 2:
        dr.append(b)
if len(cr) >= 1:
    mc = max(cr) ** 2
else:
    mc = 0
if len(dr) >= 2:
    er = sorted(dr,reverse=True)
    md = er[0] * er[1]
else:
    md = 0
print(max(mc,md))

Submission status: Runtime Error

Solution code:
# encoding: utf-8
N = int(input())
A = list(map(int, input().split()))

A.sort()

view = 10 * 9 + 7
lengths = [0] * 2
idx = 0
for Ai in reversed(A):
    if Ai < view:
        view = Ai
        cnt = 0
    cnt += 1
    if cnt >= 2:
        lengths[idx] = view
        cnt = 0
        idx += 1
    if idx > 1: break

# print("#", lengths)
print(lengths[0] * lengths[1] if idx > 1 else 0)

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
for i in range(n-1):
    if a[i]=a[i+1]:
        a[i+1]==0
    else:
        a[i]=0
a.sort(reverse=True)
print(a[0]*a[1])

Submission status: Runtime Error

Solution code:

def 解():
    iN = int(input())
    aA = [int(_) for _ in input().split()]
    aA = reversed(sorted(aA))
    d = {}
    for a in aA:
        if a in d:
            if d[a] == 3:
                print(a*a)
                exit()
            elif iC and iC != a:
                print(iC * a)
                exit()
            else:
                iC = a
                d[a] += 1
        else:
            d[a] = 1
    print(0)
解()

Submission status: Runtime Error

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
a = [0,0]
count = 0
for i in range(N):
    count += 1
    if i == N-1:
        if count >= 2:
            a.append(L[i])
            a.pop(0)
            res = a[0]*a[1] 
        count = 0
    elif L[i] != L[i+1]:
        if count >= 2:
            a.append(L[i])
            a.pop(0)
            res = a[0]*a[1]
        count = 0
            
print(res)

Submission status: Runtime Error

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

cnt = [0]*(int(1e9)+1)
for ai in a:
    cnt[ai] += 1

ans = 0
condi = 0
for ai in a[::-1]:
    if cnt[ai] >= 4:
        ans = max(ans, ai*ai)
        break
    else:
        if condi==0:
            condi = ai
        else:
            ans = condi * ai
            break
            
print(ans)

Submission status: Runtime Error

Solution code:
import math
import collections
N = int(input())
A = [int(input()) for x in range(N)]
c = collections.Counter(A)
#print(c)
aaa = []
for i in (reversed(sorted(A))):
    #print(i)
    #print(">>",c[i])
    #print()
    if c[i] > 1:
        c[i]-=2
        aaa.append(i)
    if len(aaa) == 2:
        break
if len(aaa) < 2:
    print(0)
else:
    print(aaa[0]*aaa[1])

Submission status: Runtime Error

Solution code:
import math
import collections
N = int(input())
A = [int(input()) for x in range(N)]
c = collections.Counter(A)
#print(c)
aaa = []
for i in (reversed(sorted(A))):
    #print(i)
    #print(">>",c[i])
    #print()
    if c[i] > 1:
        c[i]-=2
        aaa.append(i)
    if len(aaa) == 2:
        break
if len(aaa) < 2:
    print(0)
else:
    print(aaa[0]*aaa[1])3

Submission status: Runtime Error

Solution code:
import math
import collections
N = int(input())
A = [int(input()) for x in range(N)]
c = collections.Counter(A)
#print(c)
aaa = []
for i in (reversed(sorted(A))):
    #print(i)
    #print(">>",c[i])
    #print()
    if c[i] > 1:
        c[i]-=2
        aaa.append(i)
    if len(aaa) == 2:
        break
print(aaa[0]*aaa[1])

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
Acount = {}
q = []
 
for a in A:
  if a not in Acount:
    Acount[a] = 0
  else:
    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])
N = int(input())

Submission status: Runtime Error

Solution code:
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:
    for _ in range(d.get(i)):
        s.append(int(i))
    s.sort()
    
print(s[-1]*s[-2])

Submission status: Runtime Error

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
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))


# Binary converter
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


# Width First Search (+ Distance)
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


# Depth First Search (+Distance)
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(max(2, D[d] // 2))
            E.append(d)
            
    if len(E) >= 2:
        E.sort(reverse=True)
        print(E[0] * E[1])
    else:
        print(0)
 
 
main()

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
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 = 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)

Submission status: Runtime Error

Solution code:
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 A_dict.keys():
    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)

Submission status: Runtime Error

Solution code:
#ABC071C
N=int(input())
A=list(map(int,input().split()))
max_A=max(A)
lines=[0]*(max_A+1)
long_line=0
ans=0
for i in range(N):
    lines[A[i]]+=1
if max(lines)<2:
    print(int(ans))
else:
    for i in range(max_A):
        j=max_A-i
        if lines[j]>=4:
            if long_line>0:
                ans=j*long_line
                break
            else:
                ans=j*j
                break
        elif lines[j]>=2:
            if long_line>0:
                ans=j*long_line
                break
            else:
                long_line=j
    print(int(ans))

Submission status: Runtime Error

Solution code:
#ABC071C
N=int(input())
A=list(map(int,input().split()))
max_A=max(A)
lines=[0]*(max_A+1)
long_line=0
ans=0
for i in range(N):
    lines[A[i]]+=1
if max(lines)<2:
    print(int(ans))
else:
    for i in range(max_A):
        j=max_A-i
        if lines[j]>=4:
            if long_line>0:
                ans=j*long_line
                break
            else:
                ans=j*j
                break
        elif lines[j]>=2:
            if long_line>0:
                ans=j*long_line
                break
            else:
                long_line=j
print(int(ans))

Submission status: Runtime Error

Solution code:
#ABC071C
N=int(input())
A=list(map(int,input().split()))
max_A=max(A)
lines=[0]*(max_A+1)
long_line=0
for i in range(N):
    lines[A[i]]+=1
if max(lines)<2:
    print(0)
    exit()
for i in range(max_A-1):
    j=max_A-i
    if lines[j]>=4:
        if long_line>0:
            print(long_line*j)
            exit()
        else:
            print(j*j)
            exit()
    elif lines[j]>=2:
        if long_line>0:
            print(long_line*j)
            exit()
        else:
            long_line=j
print(0)

Submission status: Runtime Error

Solution code:
#ABC071C
N=int(input())
A=list(map(int,input().split()))
max_A=max(A)
lines=[0]*(max_A+1)
long_line=0
for i in range(N):
    lines[A[i]]+=1
# if max(lines)<2:
#     print(0)
#     exit()
for i in range(max_A):
    j=max_A-i
    if lines[j]>=4:
        if long_line>0:
            print(long_line*j)
            exit()
        else:
            print(j*j)
            exit()
    elif lines[j]>=2:
        if long_line>0:
            print(long_line*j)
            exit()
        else:
            long_line=j
print(0)

Submission status: Runtime Error

Solution code:
#ABC071C
N=int(input())
A=list(map(int,input().split()))
max_A=max(A)
lines=[0]*(max_A+1)
long_line=0
for i in range(N):
    lines[A[i]]+=1
if max(lines)<2:
    print(0)
    exit()
for i in range(max_A+1):
    j=max_A-i
    if lines[j]>=4:
        if long_line>0:
            print(long_line*j)
            exit()
        else:
            print(j*j)
            exit()
    elif lines[j]>=2:
        if long_line>0:
            print(long_line*j)
            exit()
        else:
            long_line=j
print(0)

Submission status: Runtime Error

Solution code:
#ABC071C
N=int(input())
A=list(map(int,input().split()))
max_A=max(A)
lines=[0]*(max_A+1)
long_line=0
for i in range(N):
    lines[A[i]]+=1
if max(lines)<2:
    print(0)
    exit()
for i in range(max_A):
    j=max_A-i
    if lines[j]>=4:
        if long_line>0:
            print(long_line*j)
            exit()
        else:
            print(j*j)
            exit()
    elif lines[j]>=2:
        if long_line>0:
            print(long_line*j)
            exit()
        else:
            long_line=j
print(0)

Submission status: Runtime Error

Solution code:
#ABC071C
N=int(input())
A=list(map(int,input().split()))
max_A=max(A)
lines=[0]*(max_A+1)
long_line=0
sqare_area=0
rectangl_area=0
for i in range(N):
    lines[A[i]]+=1
if max(lines)<2:
    print(0)
    exit()
for i in range(max_A):
    j=max_A-i
    if lines[j]>=4:
        if sqare_area==0:
            sqare_area=j*j
            if long_line==0:
                print(sqare_area)
                exit()
    elif lines[j]>=2:
        if long_line>0:
            rectangle_area=long_line*j
            if rectangle_area>sqare_area:
                print(rectangle_area)
                exit()
            else:
                print(sqare_area)
                exit()
        else:
            long_line=j

Submission status: Runtime Error

Solution code:
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 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])

Submission status: Runtime Error

Solution code:
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 bar_length_count.items() if v >= 2}, 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])

Submission status: Runtime Error

Solution code:
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 bar_length_count.items() if v >= 2], 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])

Submission status: Runtime Error

Solution code:
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
  else:
    pre = a
print(a * b)

Submission status: Runtime Error

Solution code:
a  =  int(input())

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

b.sorted()

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)

Submission status: Runtime Error

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

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

print(x*y)

Submission status: Runtime Error

Solution code:
N = int(input())
int_list = list(map(int, input().split()))

count_dct = {}
for input_num in int_list:
    if input_num in count_dct.keys():
        count_dct[input_num] += 1
    else:
        count_dct[input_num] = 1
        
count_sort_list = []
max_num = 0
for i, j in count_dct.items():
    if j >= 2:
        count_sort_list.append(i)
        if j >= 4 and j > max_num:
            max_num = j
    else:
        pass
      
a = sorted(count_sort_list)[-1]*sorted(count_sort_list)[-2]
b = max_num**2

if len(count_sort_list)<2:
    print(0)
elif a > b:
    print(a)
else:
    print(b)

Submission status: Runtime Error

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

d = dict()
for a_i in a:
	if a_i not in d:
		d[a_i] = 0
	d[a_i] += 1
d = sum([[d_i[0] for i in range(d_i[1]//2)] for d_i in d.items()], [])

d.sort(reverse=True)
print(d[0] * d[1])

Submission status: Runtime Error

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

for a_i in set(a):
	a.remove(a_i)
max_2 = sorted(a, reverse=True)[:2]
print(max_2[0]*max_2[1])

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
max1=0;max2=0
for i in range(n-3):
  if a[i]==a[i+1]:
    max1=a[i]
    a[i+1]=0
    count=i+1
    break
for j in range(count,n-1):
  if a[j]==a[j+1]:
    max2=a[j]
    break
print(max1*max2)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
max1=0;max2=0
for i in range(n-1):
  if a[i]==a[i+1]:
    max1=a[i]
    a[i+1]=0
    count=i
    break
for j in range(count,n-1):
  if a[j]==a[j+1]:
    max2=a[j]
    break
print(max1*max2)

Submission status: Runtime Error

Solution code:
n = int(input())

arr = map(int,raw_input().split())

dic = {}

for i in range(n):
	if dic.has_key(arr[i]):
		dic[arr[i]] += 1
	else :
		dic[arr[i]] = 1

ans = [[k,v] for k, v in dic.items() if v > 1] 

ans = ans[-2:]


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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
Adict = []
for i in A:
    if i in Adict:
        Adict[i]=Adict[i]+1
    else:
        Adict.update({i:1})
B = [0, 0]
for i in Adict.keys():
    if Adict[i] >= 2:
        B.append(i)
    if Adict[i] >= 4:
        B.append(i)
B.sort()
print(B[-1]*B[-2])

Submission status: Runtime Error

Solution code:

N = int(input())
A = list(map(int, input().split()))
Adict = []
for i in A:
  if i in Adict:
    Adict[i]=Adict[i]+1
  else:
    Adict.update({i:1})
B = [0, 0]
for i in Adict.keys():
    if Adict[i] >= 2:
        B.append(i)
    if Adict[i] >= 4:
        B.append(i)
B.sort()
print(B[-1]*B[-2])

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
A = Counter(map(int, input().split()))
B = [0, 0]
for i in A.keys():
    if A[i] >= 2:
        B.append(v)
    if A[i] >= 4:
        B.append(v)
B.sort()
print(B[-1]*B[-2])

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))
rod = {}
for i in A:
    if i in rod:
        rod[i] += 1
    else:
        rod[i] = 1
if len([i for i in rod.values() if i >= 2]) < 2:
    print(0)
else:
    length4 = [k for k, v in rod.items() if v >= 4]
    length4.sort()
    length2 = [k for k, v in rod.items() if v >= 2]
    length2.sort()
    if length4[-1] == length2[-1]:
        print(length4[-1]**2)
    else:
        print(length2[-2] * length2[-1])

Submission status: Runtime Error

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

a_sort = list(reversed(list(sorted(a))))
amax = max(a_sort)

if a_sort.count(amax) >3:
    print(amax ** 2)
    
else:
    one = 0
    two = 0
    for i in a_sort:
        if a_sort.count(i) > 1 and one = 0 and two = 0:
            one = i
        elif a_sort.count(i) > 1 and one > 0 and two = 0:
            two = i
        else:
            break
    print(one*two)

Submission status: Runtime Error

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

a_sort = list(sorted(a))
ad = {}
for i in range(len(a_sort)):
    if ad in a_sort[i]:
        ad[a_sort[i]] = ad[a_sort[i]] + 1
    else:
        ad.update(a_sort[i]:1)
ad2 = ad
for key in ad.keys():
    if ad[key] < 2:
        del ad2[key]

amax = max(ad2.keys())
b = ad2
while amax in b:
    b.remove(amax)
bmax = max(b)

if ad2[amax] > 3:
    print(amax*amax)
else:
    print(amax*bmax)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
data=Counter(a)
two=[]
four=[]
for i,j in data.items():
    if 2<=j<=3:
        two.append(i)
    elif 4<=j:
        four.append(i)
if len(four)==0:
    four.append(0)
    four.append(0)
    four[1]=0
elif len(two)==0:
    two.append(0)
    two.append(0)
print(max(four[0]*four[0],four[0]*four[1],two[0]*two[1],two[0]*four[0]))