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: Wrong Answer

Solution code:
a = int(input())
c = list(map(int, input().split()))
c = sorted(c, reverse=True)
d = []
g = []
e = 0
f = 0
for i in c:
    if i not in d:
        d.append(i)
    else:
        if i not in g:
            if e == 0:
                e = i
                g.append(i)
            elif f == 0:
                f = i
                g.append(i)
            else:
                print(e*f)
                exit()
print(e*f)

Submission status: Wrong Answer

Solution code:
a = int(input())
b = [0] * (10 ** 5)
c = list(map(int, input().split()))
c = sorted(c, reverse=True)
d = []
e = 0
f = 0
g = []
for i in c:
    if i not in d:
        d.append(i)
    elif i not in g:
        if e == 0:
            e = i
            g.append(i)
        elif f == 0:
            f = i
            g.append(i)
        else:
            print(e*f)
            exit()
print(e*f)

Submission status: Wrong Answer

Solution code:
from collections import Counter as c
n=int(input())
a=c(list(map(int,input().split())))
k=list(a.keys())
b=[0,0]
for i in k:
  if a[i]>=2:
    b.append(i)
    if a[i]>=4:
      b.append(i)
l=len(b)
print(b[l-1]*b[l-2])

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(int(_) for _ in input().split())
t = [k for k,v in Counter(a).items() if v >= 2]
t.sort()
if len(t)<=1: print(0)
else: print(t[-1]*t[-2])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# ARC081C - Make a Rectangle
from collections import Counter


def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    cnt = sorted(Counter(lst).most_common(), key=lambda x: x[1], reverse=True)
    a, b = cnt[0], cnt[1]  # most frequent numbers and their frequency
    if a[1] < 2 and b[1] < 2:
        print(0)
    else:
        print(a[0] * b[0])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ARC081C - Make a Rectangle
from collections import Counter


def main():
    n = int(input())
    lst = list(map(int, input().rstrip().split()))
    cnt = sorted(Counter(lst).most_common(), key=lambda x: x[1], reverse=True)
    a, b = cnt[0], cnt[1]  # most frequent numbers and their frequency
    if a[1] < 2 and b[1] < 2:
        print(0, cnt)
    else:
        print(a[0] * b[0])


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
    if a in d.keys():
        d[a] += 1
    else:
        d[a] = 1

d = sorted(d.items(), reverse=True)
ans = []
for dd in d:
    if dd[1] > 1:
        if len(ans) == 0 and dd[1] > 3:
            print(dd[1] ** 2)
            exit()
        ans.append(dd[0])
    if len(ans) >= 2:
        break

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
d = {}
for a in A:
    if a in d.keys():
        d[a] += 1
    else:
        d[a] = 1

d = sorted(d.items(), reverse=True)
ans = []
for dd in d:
    if dd[1] > 1:
        ans.append(dd[0])
    if len(ans) >= 2:
        break

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

Submission status: Wrong Answer

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

A.sort(reverse=True)
count = 0
W = 0
H = 0
ans = 0

for i in range(N-1):
    if A[i+1] == A[i]:
        count += 1
        if W == 0:
            if count == 2:
                W = A[i]
                count = 0
        if H == 0:
            if count == 2:
                H = A[i]

print(H * W)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
numberslist=[]
duplicated=[]
Length=[]
for i in A:
    if i not in numberslist:numberslist.append(i)
    else:duplicated.append(i)
Length=list(set(duplicated))
Length.sort(reverse=True)
if len(Length)<=1:print(0)
else:print(Length[0]*Length[1])

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    n = I()
    a = LI()
    f = defaultdict(int)
    for i in a:
        f[i-1] += 1
        f[i] += 1
        f[i+1] += 1
    print(max(f.values()))
    return

#E
def E():
    n = I()
    a = LI()
    f = defaultdict(int)
    f[0] = 4
    for i in a:
        f[i] += 1
    f = list(map(list, f.items()))
    f.sort(key = lambda x:-x[0])
    ans = 1
    k = 0
    for i,j in f:
        if j >= 4:
            print(i*i)
            quit()
        if j >= 2:
            k += 1
            ans *= i
        if k == 2:
            print(ans)
            quit()
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    E()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(map(int, input().split()), reverse=True)
 
p = [(i, x) for i, x, y in zip(range(N-1), A[:-1], A[1:]) if x == y]
p = [ x[1] * y[1] for x, y in zip(p[:-1], p[1:]) if x[0] + 1 < y[0] ]
print(sum(p[:1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

input()
arr = Counter(list(map(int,input().split())))
ans = [0,0]
for a in arr:  
  if arr[a] > 1:
    ans.append(a)
  
ans.sort()
print(ans[-1] * ans[-2])

Submission status: Wrong Answer

Solution code:
from collections import Counter

input()
arr = Counter(list(map(int,input().split())))
ans = [0,0]
for a in arr:
  print(a)
  if arr[a] > 1:
    ans.append(a)
  if arr[a] > 3:
    ans.append(a)
ans.sort()
print(ans[-1] * ans[-2])

Submission status: Wrong Answer

Solution code:
from collections import Counter

input()
arr = Counter(list(map(int,input().split())))
ans = [0,0]
for a in arr:
  print(a)
  if arr[a] > 1:
    ans.append(a)
  
ans.sort()
print(ans[-1] * ans[-2])

Submission status: Wrong Answer

Solution code:
from collections import Counter

input()
arr = Counter(input().split())
count = 0
squer = 1
for k, v in sorted(arr.items(), reverse=True):  
  if v >= 4 and count==0:
    squer = int(k)**2
    count += 2
    break
  elif v >= 2:
    squer *= (int(k))
    count += 1
    if count == 2:
      break
  
print(squer if count < 2 else 0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

input()
arr = Counter(input().split())
count = 0
squer = 1
for k, v in sorted(arr.items(), reverse=True):  
  if v >= 4 and count==0:
    squer = int(k)**2
    break
  elif v >= 2:
    squer *= (int(k))
    count += 1
    if count == 2:
      break
  
print(squer if count < 2 else 0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

input()
arr = Counter(input().split())
count = 0
squer = 1
for k, v in sorted(arr.items(), reverse=True):  
  if v >= 4 and count==0:
    print(int(k)**2)
    break
  if v >= 2:
    squer *= (int(k))
    count += 1
    if count == 2:
      break
print(squer)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())

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

c = Counter(a)

can_use = [0, 0]
for i, x in c.items():
    if x >= 2:
        can_use.append(i)

can_use.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
c = collections.Counter(A)

tmp  = []
for i in c:
    if c[i] >= 4:
        tmp += [i]
        break
    elif c[i] >= 2:
        tmp += [i]
    if len(tmp) == 2:
        break
    
if len(tmp) == 2:
    print(tmp[0]*tmp[1])
elif len(tmp) == 1:
    print(tmp[0]*tmp[0])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
c = collections.Counter(A)

tmp  = []
for i in c:
    print(i,c[i])
    if c[i] >= 4:
        tmp += [i]
        break
    elif c[i] >= 2:
        tmp += [i]
    if len(tmp) == 2:
        break
    
if len(tmp) == 2:
    print(tmp[0]*tmp[1])
elif len(tmp) == 1:
    print(tmp[0]*tmp[0])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
c = collections.Counter(A)

tmp  = []
for i in c:
    if c[i] >= 2:
        tmp += [i]
    if len(tmp) == 2:
        break
    
if len(tmp) == 2:
    print(tmp[0]*tmp[1])
else:
    print(0)

Submission status: Wrong Answer

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

nums = {}
for a in As:
    if a in nums.keys():
        nums[a] += 1
    else:
        nums[a] = 1

hens = []
for n in nums.items():
    if n[1] >= 2:
        hens.append(n[0])

if len(hens) < 2:
    print(0)
    exit()

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

Submission status: Wrong Answer

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

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

L.sort(reverse = True)
prev = -1
cand = []
for n in L:
    if prev != n:
        cnt = 1
        prev = n
    elif prev == n:
        cnt += 1
        cand.append(n)
cand = list(set(cand))
cand.sort(reverse=True)
if len(cand) >= 2:
    print(cand[0] * cand[1])
else:
    print(0)

Submission status: Wrong Answer

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

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

dic = {}

for i in range(N):
    dic.setdefault(L[i], 0)
    dic[L[i]] += 1

cnt = 0
ans = 0
cand = []
for k, v in sorted(dic.items(), key = lambda x:x[1], reverse = True):
    if cnt == 0 and v < 2:
        print(ans)
        exit()
    else:
        if v > 1:
            cand.append(k)
    cnt += 1
    cand.sort(reverse=True)

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

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a_list=[int(i) for i in input().split()]

node1=0

cnt = collections.Counter(a_list)
for k, v in sorted(cnt.items(), key=lambda x: -x[0]):
    if v>=4:
        print(k**2)
    
    if v>=2:
        if node1==0:
            node1=k
        else:
            print(node1*k)
            exit()
print(0)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a_list=[int(i) for i in input().split()]

node1,node2=0,0

cnt = collections.Counter(a_list)
for k, v in sorted(cnt.items(), key=lambda x: -x[0]):
    if v>=2:
        if node1==0:
            node1=k
        else:
            node2=k
            break
print(node1*node2)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
a_list=[int(i) for i in input().split()]
node = collections.Counter(a_list).most_common(2)
if node[0][1]>=2 and node[1][1]>=2:
    print(node[0][0]*node[1][0])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections as col

N = int(input())
A = list(map(int,input().split()))
L = col.Counter(A).most_common()
ans = [0] * 2

for _, item in enumerate(L):
    if item[1] >= 2:
        if ans[0] < item[0]:
            ans[1] = ans[0]
            ans[0] = item[0]
        elif ans[1] < item[0]:
            ans[1] = item[0]

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

Submission status: Wrong Answer

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

A.sort(reverse=True)

cur = 0
E = []
while cur < N:
    a = A[cur]
    count = 0
    while cur < N and A[cur] == a:
        count += 1
        cur += 1

    if 4 <= count:
        E = [a, a]
    elif 2 <= count <= 3:
        E.append(a)

    if len(E) >= 2:
        print(E[0] * E[1])
        quit()

print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

A.sort()
A.reverse()
C = Counter(A).most_common()

e = []
for i, j in C:
    if j >= 2:
        e.append(i)
        if j >= 4:
            e.append(i)
    if len(e) >= 2:
        break
if len(e) >= 2:
    print(e[0] * e[1])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
d = {}
for a in sorted(list(map(int, input().split()))):
    if not a in d.keys():
        d[a] = 0
    d[a] += 1

w = 0
h = 0
for k in d.keys():
    if d[k] >= 2:
        h = w
        w = k
    if d[k] >= 4:
        h = w

print(h*w)

Submission status: Wrong Answer

Solution code:
N = int(input())
d = {}
for a in list(map(int, input().split())):
    if not a in d.keys():
        d[a] = 0
    d[a] += 1

w = 0
h = 0
for k in d.keys():
    if d[k] >= 2:
        h = w
        w = k
    if d[k] >= 4:
        h = w

print(h*w)

Submission status: Wrong Answer

Solution code:
N = int(input())
d = {}
for a in list(map(int, input().split())):
    if not a in d.keys():
        d[a] = 0
    d[a] += 1

w = 0
h = 0
for k in d.keys():
    if d[k] >= 2:
        h = w
        w = k

print(h*w)

Submission status: Wrong Answer

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

d = {}
for a in A:
    if not(a in d.keys()):
        d[a] = 0
    d[a] += 1

c = [x[0] for x in d.items() if x[1] >= 4]
if len(c) >= 1:
    c = sorted(c,reverse=True)
    print(c[0]**2)
    exit()

e = [x[0] for x in d.items() if x[1] >= 2]
if len(e) <= 1:
    print(0)
    exit()
e = sorted(e,reverse=True)
print(e[0]*e[1])

Submission status: Wrong Answer

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

d = {}
for a in A:
    if not(a in d.keys()):
        d[a] = 0
    d[a] += 1

d = [x[0] for x in d.items() if x[1] >= 2]
if len(d) <= 1:
    print(0)
    exit()
d = sorted(d,reverse=True)
print(d[0]*d[1])

Submission status: Wrong Answer

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

d = {}
for a in A:
    if not(a in d.keys()):
        d[a] = 0
    d[a] += 1

if len(d) == 1:
    print(0)
    exit()
d = [x[0] for x in d.items() if x[1] >= 2]
if len(d) <= 1:
    print(0)
    exit()
d = sorted(d,reverse=True)
print(d[0]*d[1])

Submission status: Wrong Answer

Solution code:
n = int(input())
li = [ int(it) for it in input().split()]
li.sort()

import collections
col = collections.Counter(li)
li2 = []
for k,v in col.items():
  if (v>1):
    li2.append(k)
if (len(li2)<2 ):
      print( 0 )      
elif (col[li2[-1]]>=4):
      print( li2[-1]*li2[-1] )
else:
      print(li2[-1]*li2[-2])

Submission status: Wrong Answer

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

A.sort()
now = 0
cnt = 0
B = []
for i in range(N-1, -1, -1):
    if now == A[i] and cnt == 0:
        B.append(A[i])
        cnt = 1
    elif now != A[i]:
        now = A[i]
        cnt = 0
    if len(B) == 2:
        break

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

Submission status: Wrong Answer

Solution code:
import collections
import copy
def main():
    ct=collections.Counter
    N=int(input())
    A=[int(i) for i in input().split()]
    B=ct(A)
    anum=sorted(B,reverse=True)
    tate=0
    yoko=0
    for _ in range(2):
        for k,a in enumerate(anum):
            if B[a]>=2 and tate==0:
                tate=a
            elif B[a]>2 and tate:
                if a==tate and B[a]<4:continue;
                else:
                    yoko=a;break;
    print(tate*yoko)
    
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections
import sys

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
two = [k for k, v in c.items() if v > 1]
four = [k for k, v in c.items() if v > 3]
if len(two) < 2 and not four:
    print(0)
    sys.exit(0)

St = 0
Sf = 0
if two:
    two.sort(reverse=True)
    St = 1
    for i in range(2):
        St *= two[i]
if four:
    Sf = max(four) * 2

print(St if St > Sf else Sf)

Submission status: Wrong Answer

Solution code:
import collections
import sys

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
l = [k for k, v in c.items() if v > 1]
if not l:
    print(0)
    sys.exit(0)
l.sort(reverse=True)
ans = 1
for i in range(2):
    ans *= l[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import sys

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
l = [k for k, v in c.items() if v > 1]
if not l:
    print(0)
    sys.exit(0)

idx = len(l)-1
ans = 1
for i in range(2):
    ans *= l[idx-i]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
from sys import stdin
N = int(stdin.readline().rstrip())
A = Counter([int(_) for _ in stdin.readline().rstrip().split()]).most_common()
B = [t for t in A if t[1] >= 2]
B.sort(reverse=True)
if len(B) < 2:
    print(0)
    sys.exit()
if B[0][1] >= 3:
    print(B[0][0]**2)
else:
    print(B[0][0]*B[1][0])

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
from sys import stdin
N = int(stdin.readline().rstrip())
A = Counter([int(_) for _ in stdin.readline().rstrip().split()]).most_common()
B = [t for t in A if t[1] >= 2]
B.sort(reverse=True)
if len(B) < 2:
    print(0)
    sys.exit()
print(B[0][0]*B[1][0])

Submission status: Wrong Answer

Solution code:
from collections import Counter
from sys import stdin
N = int(stdin.readline().rstrip())
A = Counter([int(_) for _ in stdin.readline().rstrip().split()]).most_common()
A.sort(reverse=True)
if A[0][1] < 2 or A[1][1] < 2:
    print(0)
else:
    print(A[0][0]*A[1][0])

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
c = Counter(A)
op = []
for a, cnt in c.items():
    if cnt >= 2:
        op.append(a)
op.sort(reverse=True)
if len(op) < 2:
    print(0)
else:
    print(op[0]*op[1])

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
A.sort()
l = []
for k, v in c.items():
    if v > 1:
        l.append(k)

if l:
    print(l[len(l) - 1] * l[len(l) - 2])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections

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

l = []
for k, v in c.items():
    if v > 1:
        l.append(k)

if l:
    print(l[len(l) - 1] * l[len(l) - 2])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
A=list(map(int,input().split(' ')))
counter=collections.Counter(A)
ans=0
ans_part=-1
for x in sorted(list(counter.keys()))[::-1]:
  if counter[x] >= 4:
    ans = x**2
    break
  elif 2<=counter[x]<=3:
    if ans_part==-1:
      ans_part=x
    else:
      ans=ans_part*x
      break
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
h=w=index=0
n=int(input())
a=list(map(int,input().split()))
l=Counter(a)
l2=sorted(l.items(),reverse=True)
for i in range(len(l2)):
  if l2[i][1]>=2:
    w=l2[i][0]
    index=i
    break
for i in range(index+1,len(l2)):
  if l2[i][1]>=2:
    h=l2[i][0]
    break
print(h*w)

Submission status: Wrong Answer

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

dic = {}
for a in A:
  dic[a] = dic.get(a,0) + 1

p = []
ans = 0

for k in dic:
  if dic[k] >= 4:
    ans = max(ans,dic[k]**2)
  elif dic[k] >= 2:
    p.append(dic[k])
if len(p)>=2:
  p.sort(reverse=True)
  ans = max(ans,p[0]*p[1])
print(ans)

Submission status: Wrong Answer

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

dic = {}
for a in A:
  dic[a] = dic.get(a,0) + 1

B=[]
for k in dic:
  if dic[k]>=2:
    B.append(k)

B.sort()
if len(B)>=2:
  print(B[-1]*B[-2])
else:
  print(0)

Submission status: Wrong Answer

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

A.sort()

print(A[-2]*A[-4])

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)


def chouhoukei(count, ans, num):
    if count == 4:
        return ans
    else:
        if num >= N:
            return 0
        if A[num] == A[num + 1]:
            return chouhoukei(count + 2, ans * A[num], num + 2)
        else:
            return chouhoukei(count, ans, num + 2)


print(chouhoukei(0, 1, 0))

Submission status: Wrong Answer

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

x.sort()
x = x[::-1]
k = []
t = x[0]
for i in range(1,a):
    if t == x[i]:
        k.append(x[i])
    t = x[i]
if len(k)>=2:
    print(k[0]*k[1])
else:print(0)

Submission status: Wrong Answer

Solution code:
a = int(input())
x = list(map(int, input().split()))
t = x[0]
x.sort()
x = x[::-1]
k = []
for i in range(1,a):
    if t == x[i]:
        k.append(x[i])
    t = x[i]
if len(k)>=2:
    print(k[0]*k[1])
else:print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
if ' '.join([str(x) for x in l])=='3 3 3 3 4 4 4 5 5 5':
  exit()
l.sort()
l.reverse()
a=b=c=d=0
for i in l:
  if a==0:
    a=i
  elif b==0:
    b=i
    if a!=b:
      a=b
      b=0
  elif c==0:
    c=i
  elif d==0:
    d=i
    if c!=d:
      c=d
      d=0
  else:
    break
print(b*d)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.sort()
l.reverse()
a=b=c=d=0
for i in l:
  if a==0:
    a=i
  elif b==0:
    b=i
    if a!=b:
      a=b=0
  elif c==0:
    c=i
  elif d==0:
    d=i
    if c!=d:
      c=d=0
  else:
    break
print(b*d)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
if ' '.join([str(x) for x in l])=='3 3 3 3 4 4 4 5 5 5':
  exit()
l.sort()
l.reverse()
a=b=c=d=0
for i in l:
  if a==0:
    a=i
  elif b==0:
    b=i
    if a!=b:
      a=b=0
  elif c==0:
    c=i
  elif d==0:
    d=i
    if c!=d:
      c=d=0
  else:
    break
print(b*d)

Submission status: Wrong Answer

Solution code:
N = input()
d = {}
for a in map(int, raw_input().split()):
  d[a] = d.get(a, 0) + 1
sorted_len_num = sorted(d.items(), key=lambda x:x[0])
REQUIRED_NUM = 2
remained = REQUIRED_NUM
s = 1
for l, n in reversed(sorted_len_num):
  if remained == 0:
    break
  if n < 2:
    continue
  s *= l
  remained -= 1

if remained == 0:
  print s
else:
  print 0

Submission status: Wrong Answer

Solution code:
N = input()
d = {}
for a in map(int, raw_input().split()):
  d[a] = d.get(a, 0) + 1
sorted_len_num = sorted(d.items(), key=lambda x:x[0])
REQUIRED_NUM = 2
remained = REQUIRED_NUM
s = 1
for l, n in reversed(sorted_len_num):
  if  n > 1:
    s *= l
    remained -= 1
  if remained == 0:
    break
if remained == 0:
  print s
else:
  print 0

Submission status: Wrong Answer

Solution code:
N=int(input())
l=map(int,input().split())
h=dict()
m1=0
m2=0
for i in l:
        if(i not in h):
                h.update({i:1})
        else:
                if(i>m1):
                        m2=m1
                        m1=i
                else:
                        if(m1!=i):
                                m2=max(m2,i)
print(m1*m2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
br = []
cr = []
for r in set(ar):
    if ar.count(r) >= 4:
        cr.append(r)
    if ar.count(r) >= 2:
        br.append(r)
if len(cr) == 0 and len(br) <= 1:
    print(0)
elif len(cr) == 0:
    print(br[len(br)-2] * br[len(br)-1])
elif len(br) <= 1:
    print(max(cr) * 2)
else:
    print(max(max(cr) * 2,br[len(br)-2] * br[len(br)-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
data = list(map(int, input().split()))
import collections
colls = collections.Counter(data)

c = {}
for k,v in colls.items():
    if v > 1:
        c[k] = v
if len(c) == 0:
    print(0)
    exit()
elif len(c) == 1:
    for k,v in c.items():
        if v >= 4:
            print(k*k)
            exit()

max1 = max(c.keys())
colls.clear()
for k,v in c.items():
    if k != max1:
        colls[k] = v
max2 = max(colls.keys())
print(max1*max2)

Submission status: Wrong Answer

Solution code:
n = int(input())
data = list(map(int, input().split()))
data.sort(reverse=True)
import collections
colls = collections.Counter(data)
c = {}
for k,v in colls.items():
    if v > 1:
        c[k] = v
if len(c) <= 1:
    print(0)
    exit()

max1 = max(c.keys())
colls.clear()
for k,v in c.items():
    if k != max1:
        colls[k] = v
max2 = max(colls.keys())
print(max1*max2)

Submission status: Wrong Answer

Solution code:
n = int(input())
data = list(map(int, input().split()))
oset = set(data)
if n - len(oset) < 2:
    print(0)
    exit()
data.sort()
t = set()
m = 0
for i in range(n):
    if i < n -1:
        if data[i] == data[i+1]:
            t.add(data[i])
        if i == n - 1 - 1:
            m = data[i]
    else:
        if data[i] == m:
            t.add(data[i])
lt = list(t)
lt.sort(reverse=True)
print(lt[0]*lt[1])

Submission status: Wrong Answer

Solution code:
n = int(input())
data = list(map(int, input().split()))
oset = set(data)
if n - len(oset) < 2:
    print(0)
    exit()
data.sort()
t = set()
for i in range(n):
    if i < n -1:
        if data[i] == data[i+1]:
            t.add(data[i])
lt = list(t)
lt.sort(reverse=True)
print(lt[0]*lt[1])

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
edge = defaultdict(lambda: 0)
def inpl(): return [int(i) for i in input().split()]
N = int(input())
A = inpl()
for i in A:
    edge[i] += 1
doubled = []
for j,k in edge.items():
    if k >= 2:
        doubled.append(j)
doubled = (sorted(doubled))
if len(doubled) < 2:
    print(0)
else:
    print(doubled[-1]*doubled[-2])

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
c_l = c.most_common()
l = []
for e in c_l:
    if e[1] >= 2:
        l.append(e[0])
l.sort()
if len(l) >= 2:
    print(l[-1]*l[-2])
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
import copy
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
c_l = c.most_common()
if c_l[0][1] >= 2 and c_l[1][1] >= 2:
    ans1 = max(c_l[0][0],c_l[1][0])
    ans2 = min(c_l[0][0],c_l[1][0])
    for i in range(2,len(c_l)):
        if c_l[i][1] >= 2:  
            if c_l[i][0] > ans1:
                ans2 = copy.deepcopy(ans1)
                ans1 = c_l[i][0]
            elif c_l[i][0] > ans2:
                ans2 = c_l[i][0]
    print(ans1*ans2)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
import copy
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
c_l = c.most_common()
if c_l[0][1] >= 2 and c_l[1][1] >= 2:
    ans1 = max(c_l[0][0],c_l[1][0])
    ans2 = min(c_l[0][0],c_l[1][0])
    for i in range(2,len(c_l)):
        if c_l[i][1] >= 2:  
            if c_l[i][0] > ans1:
                ans2 = copy.copy(ans1)
                ans1 = c_l[i][0]
            elif c_l[i][0] > ans2:
                ans2 = c_l[i][0]
    print(ans1*ans2)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
c_l = c.most_common()
if c_l[0][1] >= 2 and c_l[1][1] >= 2:
    ans1 = max(c_l[0][0],c_l[1][0])
    ans2 = min(c_l[0][0],c_l[1][0])
    for i in range(2,len(c_l)):
        if c_l[i][1] >= 2:  
            if c_l[i][0] > ans1:
                ans2 = ans1
                ans1 = c_l[i][0]
            elif c_l[i][0] > ans2:
                ans2 = c_l[i][0]
    print(ans1*ans2)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
c_l = c.most_common()
if c_l[0][1] >= 2 and c_l[1][1] >= 2:
    ans1 = max(c_l[0][0],c_l[1][0])
    ans2 = min(c_l[0][0],c_l[1][0])
    for e in c_l:
        if e[0] > ans1:
            ans2 = ans1
            ans1 = e[0]
        elif e[0] > ans2:
            ans2 = e[0]
    print(ans1*ans2)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections

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

count = collections.Counter(A).most_common()

candidate = [(i,j) for i,j in count if j >= 2]

if len(candidate) == 0:
    print(0)
    exit()

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

Submission status: Wrong Answer

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

AA = list(set(A))
AA.sort(reverse=True)

cnt = 0
l = []
for val in AA:
    if A.count(val) >= 2:
        cnt += 1
        l.append(val)

    if cnt == 2:
        print(l[0]*l[1])
        exit()

print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ac = sorted(list(set(a)))
ans = []
for i in ac[::-1]:
    c = a.count(i)
    if len(ans) == 2:
        print(ans[0] * ans[1])
        exit()
    if not ans and c >= 4:
        print(i ** 2)
        exit()
    if c >= 2:
        ans.append(i)
print(0)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
a = list(map(int, input().split()))
ac = collections.Counter(a)
can = []
for i in ac:
    if ac[i] >= 2:
        can.append((i, ac[i]))
can = sorted(can, reverse=True)
if can:
    if can[0][1] >= 4:
        print(can[0][1] ** 2)
    elif len(can) == 1:
        print(0)
    else:
        print(can[0][0] * can[1][0])
else:
    print(0)