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:
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    A=list(map(int,input().split()))
    d=defaultdict(int)
    t=[]
    f=[]
    for x in A:
        d[x]+=1
        if d[x]==2:
            t.append(x)
        elif d[x]==4:
            f.append(x)
    t.sort()
    f.sort()
    if not f:
        if len(t)<2:
            print(0)
        else:
            print(t[-1]*t[-2])
    else:
        t.extend([0,0])
        t.sort()
        if f[-1]>=t[-1]:
            print(f**2)
        if t[-1]>f[-1]>=t[-2]:
            print(t[-1]*f[-1])
        else:
            print(t[-1]*t[-2])

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    A=list(map(int,input().split()))
    d=defaultdict(int)
    t=[]
    f=[]
    for x in A:
        d[x]+=1
        if d[x]==2:
            t.append(x)
        elif d[x]==4:
            f.append(x)
    t.sort()
    f.sort()
    if not f:
        if len(t)<2:
            print(0)
        else:
            print(t[-1]*t[-2])
    else:
        t.append(0)
        t.sort()
        if f[-1]>=t[-1]:
            print(f**2)
        if t[-1]>f[-1]>=t[-2]:
            print(t[-1]*f[-1])
        else:
            print(t[-1]*t[-2])

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
count = Counter(A)
sides = [k for k, v in count.items() if v >= 2]
sides.sort(reverse = True)
print(sides[0] * sides[1])

Submission status: Runtime Error

Solution code:
from collections import Counter
n, *A = map(int, open(0).read().split())
B = sorted([(k, v) for k, v in Counter(A).items() if v >= 2], reverse=1)
if len(B) == 0:
  print(0)
elif len(B) == 1:
  if B[0][1] >= 4:
  	print(B[0][0] ** 2)
  else:
    print(0)
else:
  if B[0][1] >= 4:
  	print(B[0][0] ** 2)
  else:
  	print(B[0]*B[1])

Submission status: Runtime Error

Solution code:
_=input()
A=list(map(int,input().split()))
B=list(set(A))
ans=-1
B=sorted(B)[::-1]
for i in B:
  if A.count(i) >=4:
    print(i**2)
  else:
    A.count(i) >= 2:
      if ans==-1:
        ans=i
      else:
        print(ans*i)
        exit()
print(0)

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
A=Counter(A)
S=[]
for i,j in A.items():
  if j>=2:
    S.append(i)
S=list(set(S))
S.sort()
if len(S)>=2:
  ans=S[-1]*S[-2]
else:
  print(0)
  exit()

Q=[]
for i,j in A.items():
  if j>=4:
    Q.append(i)
print(max(ans, (max(Q))**2))

Submission status: Runtime Error

Solution code:
import sys
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()
ans = []
for i in range(0,n-1):
    if(a[i]==a[i+1]):
        ans.append(a[i])
if (ans[0]==ans[1] and ans[1]!=ans[2]):
    print(ans[0]*ans[2])
    sys.exit()
if len(ans) <2:
    print(0)
    sys.exit()
print(ans[0]*ans[1])

Submission status: Runtime Error

Solution code:
a.sort(reverse=True)
ans = []
for i in range(n-1):
    if a[i] == a[i+1]:
        ans.append(a[i])
ans1 = set(ans)
ans2 = sorted(ans1, reverse=True)
if len(ans1) == 1 and a.count(ans[0]) >= 4:
    print(ans[0]**2)
elif len(ans1) >= 2:
    print(ans2[0]*ans2[1])
else:
    print(0)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
cnt=1
li=[]
for i in range(n-1):
    if a[i+1]==a[i]:
        cnt+=1
    else:
        cnt=1
    if cnt==2:
        li.append(a[i+1])
    if cnt==4:
        x=a[i+1]

if len(li)>=2:
    print(max(li[0]*li[1],x**2))
else:
    print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
dict = {}
b = []
c = []
for i in a:
	if i in dict:
		dict[i] += 1
	else:
		dict[i] = 1
	if dict[i] == 2:
		b.append(i)
	if dict[i] == 4:
		c.append(i)
b.sort(reverse=True)
c.sort(reverse=True)
if len(b) < 2:
	print (0)
else:
	print (max(b[0] * b[1],c[0]**2))

Submission status: Runtime Error

Solution code:
# Author: cr4zjh0bp
# Created: Tue Mar 24 00:01:43 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import Counter

n = ni()
a = na()
c = Counter(a)
m = list(c.items())
m.sort(reverse=True)
xy = [0] * 2
i = 0
flag = False
for k, v in m:
    if v >= 4:
        if i != 0:
            print(xy[0] * k)
        else:
            print(k * K)
        flag = True
        break
    elif v >= 2:
        xy[i] = k
        i += 1
        if i == 2:
            print(xy[0] * xy[1])
            flag = True
            break
if not flag:
    print(0)

Submission status: Runtime Error

Solution code:
input()
from collections import *
c=Counter(map(int,input().split()))
a=sorted(-k for k,v in c.items() if v>3)
if a: s=a[0]**2
l=sorted(-k for k,v in c.items() if v>1)
print(0 if len(l)<2 else max(s,l[0]*l[1]))

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
c=Counter(c).most_common()
s=[0,0]
for v in c:
  if v[1]>=2:
    s.append(int(v[0]))
s.sort()
print(s[-1]*s[-2])

Submission status: Runtime Error

Solution code:
from collections import Counter

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

c = Counter(a)  # リストの要素をカウント
cnt = [k for k, v in c.imtes() if v >= 2]

if len(cnt) < 2:
    print(0)
else:
    cnt = sorted(cnt, reverse=True)
    if c[cnt[0]] >= 4:
        print(cnt[0] * cnt[0])
    else:
        print(cnt[0] * cnt[1])

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
b = []
i = 0
while i+1<N:
    if len(b)==2:
        break
    if a[i] == a[i+1]:
        b += [a[i]]
        i += 2
    else:
        i += 1
print(b[0]*b[1])

Submission status: Runtime Error

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

n = int(input())
a = list(map(int, input().split()))
cnt = 0
check = 0
ans = 1

a.sort(reverse=True)
for i in range(n - 1):
    if a[cnt] == a[cnt + 1]:
        cnt += 2
        check += 1
        ans *= a[cnt]
        if check == 2:
            print(ans)
            exit()
    else:
        cnt += 1

    if cnt == n - 1:
        break
print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())),reverse = True)
use = []
flag = -1
for i in range(n):
  if flag == a[i]:
    use.append(a[i])
    flag = -1
  else:
    flag = a[i]
if len(use)<2:
  print(0)
else:
  use.sort(reverese =True)
  print(use[0]*use*[2])

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
c = defaultdict(int)
for x in a:
  c[x] += 1

top, sec = 0,0
for k,v in c:
  if n < 2:
    continue
  if k > top:
    sec = top
    top = k
  elif k > sec:
    sec = k

print(top * sec)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
c = defaultdict(int)
for x in a:
  c[x] += 1

top, sec = 0,0
for k,v in c:
  if n < 2:
    continue
  if k > top:
    sec = top
    top = k
  elif k > sec:
    sec = k

print(top * sec)

Submission status: Runtime Error

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

from collections import Counter

A.sort(reverse=True)
d = Counter(A)
d = d.most_common()
d.sort(reverse=True)
x = []

for i in range(len(d)):
    if d[i][1] >= 4:
        x.append(d[i][0])
        x.append(d[i][0])
    elif d[i][1] >= 2:
        x.append(d[i][0])
        
print(x[0]*x[1])

Submission status: Runtime Error

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

c=Counter(a)
m=c.most_common()
tmp=[]
for i in range(len(m)):
    if(m[i][1]>=2):
        tmp.append(m[i])
d=sorted(tmp,key=lambda tmp:tmp[1])

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

Submission status: Runtime Error

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

tmp=a[0]
for i in range(n-1):
    l= 0
    if tmp == a[i+1]:
        idx = i+1
        l = tmp #lを確定させる
        break
    else:
        idx=i
        tmp=a[i+1]
        

tmp2=a[idx+1]
for j in range(idx+1,n-1):
    s=0
    if tmp2==a[j+1]:
        s = tmp2
        break
    else:
        tmp2=a[j+1]
        
print(l*s)

Submission status: Runtime Error

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

b = list(set(a))
b.sort(reverse=True)

for i in range(len(b)):
    if a.count(b[i])==4:
        print(b[i]**2)
        exit()
    elif a.count(b[i])==3 or a.count(b[i])==2:
        while True:
            j=i+1
            if j<n and a.count(b[j])>=2:
                print(b[i]*b[j])
                break
                exit()
            else:
                j+=1
print(0)

Submission status: Runtime Error

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

b = list(set(a))
b.sort(reverse=True)

for i in range(len(b)):
    if a.count(b[i])==4:
        print(b[i]**2)
    elif a.count(b[i])==3 or a.count(b[i])==2:
        while True:
            j=i+1
            if j<n and a.count(b[j])>=2:
                print(b[i]*b[j])
                break
                exit()
            else:
                j+=1
print(0)

Submission status: Runtime Error

Solution code:
def makerectangle(n , a):

    listmax = []
    a.sort(reverse=True)
    for i in range(n):
        if a[i] == a[i + 1] and listmax.count(a[i]) == 0:
            if a[i] == a[i + 3] and len(listmax) == 0:
                return a[i] * a[i]
            else:
                listmax.append(a[i])
        if len(listmax) > 1:
            return listmax[0] * listmax[1]
    return 0


def main():
    n = int(input())
    a = list(map(int,input().split()))
    print(makerectangle(n , a))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def makerectangle(n , a):

    listmax = []
    a.sort(reverse=True)
    for i in range(n):
        if a.count(a[i]) > 1 and listmax.count(a[i]) == 0:
            if a.count(a[i]) > 3 len(listmax) == 0:
                return a[i] * 2
            else:
                listmax.append(a[i])
        if len(listmax) > 1:
            return listmax[0] * listmax[1]
    return 0



def main():
    n = int(input())
    a = list(map(int,input().split()))
    print(makerectangle(n , a))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter
from operator import itemgetter

N = int(input())
A = Counter(map(int,input().split()))
A1 = list(A.items())
A1 = sorted(A1,key=itemgetter(1),reverse = True)
A1 = sorted(A1,key=itemgetter(0),reverse = True)
#print(A1)

#正方形の場合
B =[]
for i in range(len(A1)):
    if A1[i][1] > 3:
        B.append(A1[i][0])
        if len(B) == 1:
            break
C =[]
for i in range(len(A1)):
    if A1[i][1] > 1:
        C.append(A1[i][0])
        if len(C) == 2:
            break

if len(C) == 0:
    print(0)
else:
    print(max(B[0]*2,C[0]*C[1]))

Submission status: Runtime Error

Solution code:
from collections import Counter
from operator import itemgetter

N = int(input())
A = Counter(map(int,input().split()))
A1 = list(A.items())
A1 = sorted(A1,key=itemgetter(1),reverse = True)
A1 = sorted(A1,key=itemgetter(0),reverse = True)
#print(A1)

B =[]
for i in range(len(A1)):
    if A1[i][1] > 1:
        B.append(A1[i][0])
        if len(B) == 2:
            break
print(B[1]*B[2] if len(B) !=0 else 0)

Submission status: Runtime Error

Solution code:
from collections import Counter

def solve(n, A):
    c = Counter(A)
    cands = sorted(filter(lambda kv: kv[1] >= 2, c.items()),  key=lambda kv: -kv[0])
    ret = 0
    if cands[0][1] >= 4:
        ret = cands[0][0] * cands[0][0]
    elif len(cands) >= 2:
        ret = cands[0][0] * cands[1][0]
    return ret

_n = int(input())
_A = map(int, input().split())
print(solve(_n, _A))

Submission status: Runtime Error

Solution code:
line1 = 0
line2 = 0

n = int(input())

lines = list(map(int,input().split()))
lines.sort()

mx1,mx2 = 0,0
temp = 0
streak = 0
for l in lines:
  if l != temp:
    temp = l
    streak = 0
  elif l == temp and streak = 0:
    streak += 1
  elif l == temp and streak == 1 and l > mx1:
    mx2 = mx1
    mx1 = l
    streak = 0
  elif l == temp and streak == 1 and l > mx2:
    mx2 = l
    streak = 0
print(mx1 * mx2)

Submission status: Runtime Error

Solution code:
4
1 2 3 4

Submission status: Runtime Error

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

from collections import Counter
a=Counter(a).most_common()

li=[]
li4=[]

for x,y in a:
  if  y>=4:
    li4.append(x)
  elif y>=2:
    li.append(x)

li.sort()
li4.sort()

if len(li4)<1 and len(li)<2:
  print(0)
  exit()

x=0
if li4:
  x=(li4[-1])**2

y=li[-1]*li[-2]

print(max(x,y))

Submission status: Runtime Error

Solution code:
iimport collections
N=int(input())
L=list(map(int,input().split()))
ANS=[0,0]
c = collections.Counter(L).most_common()
    
for k,v in c:
  if v <= 1:
    break
  if v >= 4:
    ANS.append(k)
    ANS.append(k)
  else:
    ANS.append(k)

Z=sorted(ANS)
print(Z[-1]*Z[-2])

Submission status: Runtime Error

Solution code:
n = int(input())
list1 = [int(x) for x in input().split()]
list2 = list(reversed(sorted(list1)))
m = list2[0]

ans = []
for i in range(1, len(list2)):
  if list2[i] == m:
    ans.append(m)
  if len(ans) == 2:
    break
  m = list2[i]

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

Submission status: Runtime Error

Solution code:
n = int(input())
list1 = [int(x) for x in input().split()]

set1 = set(list1)


listans = []

for i in set1:
  if list1.count(i) > 1 and list1.count(i) < 4:
    listans.append(i)
  elif list1.count(i) >3:
    listans.append(i)
    listans.append(i)




listasn = sorted(listans)
if len(listansn) < 2:
  print(0)
else:
  print(listansn[-1]*listansn[-2])

Submission status: Runtime Error

Solution code:
from collections import Counter
import sys
N = int(input())
A = [int(_) for _ in input().split()]

key_val_lis = []
for key, value in Counter(A).items():
    if value >= 2:
        key_val_lis.append((key, value))

ans_lis = sorted(key_val_lis, key=lambda x: -x[0])

if len(ans_lis) == 1 and ans_lis[0][1] < 4:
    print(0)
    sys.exit()

area_1 = ans_lis[0][0] * ans_lis[1][0]
area_2 = 0
if ans_lis[0][1] >= 4:
    area_2 = ans_lis[0][0] ** 2
print(max(area_1, area_2))

Submission status: Runtime Error

Solution code:
from collections import Counter
import sys
N = int(input())
A = [int(_) for _ in input().split()]

key_val_lis = []
for key, value in Counter(A).items():
    if value >= 2:
        key_val_lis.append((key, value))

ans_lis = sorted(key_val_lis, key=lambda x: -x[0])

if ans_lis[0] is None:
    print(0)
    sys.exit()

if ans_lis[1] is not None:
    area_1 = ans_lis[0][0] * ans_lis[1][0]
    area_2 = 0
    if ans_lis[0][1] >= 4:
        area_2 = ans_lis[0][0] ** 2
    print(max(area_1, area_2))
else:
    print(0)

Submission status: Runtime Error

Solution code:
from collections import Counter
import sys
N = int(input())
A = [int(_) for _ in input().split()]

key_val_lis = []
for key, value in Counter(A).items():
    if value >= 2:
        key_val_lis.append((key, value))

ans_lis = sorted(key_val_lis, key=lambda x: -x[0])

if len(ans_lis) == 1 and ans_lis[0][0] < 4:
    print(0)
    sys.exit()

area_1 = ans_lis[0][0] * ans_lis[1][0]
area_2 = ans_lis[0][0] ** 2
print(max(area_1, area_2))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
d={}
for i in range(n):
  if a[i] not in d:
    d[a[i]]=1
  else:
    d[a[i]]+=1
lis=sorted(d.items(),reverse=True)
for i in range(len(lis)):
  if lis[i][1]<2:
    lis.remove(lis[i])
lis.sort(reverse=True)
if len(lis)>=2:
  if lis[0][1]>=4:
    print(lis[0][0]**2)
  else:
    print(lis[0][0]*lis[1][0])
elif len(lis)==1:
  if lis[0][1]>=4:
    print(lis[0][0]**2)
  else:
    print(0)
else:
  print(0)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
k=0
i=0
cnt=0
lis=[]
while i<=n-2 or cnt<2:
  if a[i]==a[i+1] and a[i]!=k:
    lis.append(a[i])
    k=a[i]
    cnt+=1
  i+=1
if len(lis)>=2:
  print(lis[0]*lis[1])
else:
  print(0)

Submission status: Runtime Error

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

r = []
i = 0
while i < n:
    if a[i] == a[i + 1]:
        r.append(a[i])
        i += 2
    else:
        i += 1
    if len(r) == 2:
        break
if len(r) == 2:
    print(r[0] * r[1])
else:
    print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
candidate = []
for i in range(n):
    dd[str(a[i])] += 1
for k in dd.keys():
    if dd[k] >= 2:
        candidate.append(int(k))
candidate.sort(reverse=True)
if len(candidate) < 2:
    print(0)
else:
    print(candidate[0] * candidate[1])

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
a = list(map(int,input().split()))
c = dict(collections.Counter(a))

d1 = []
d2 = []
for num,v in c.items():
  if v >= 2:
    d1.append(num)
  if v >= 4:
    d2.append(num)
    
d1.sort()
d2.sort()

if d2:
  ans = max(d2[-1]**2, d1[-1]*d1[-2])
  print(ans)
else:
  print(d1[-1]*d1[-2])

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
D = defaultdict(int)
for e in A:
    D[e] += 1


l1 = []
l2 = []
for key,value in D.items():
    if value > 1:
        l1.append(key)
    if value > 3:
        l2.append(key)
if len(l1) < 2:
    print(0)
    exit()
l1.sort()
l2.sort()
print(max(l1[-1]*l1[-2],l2[-1]*l2[-1]))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
D = defaultdict(int)
for e in A:
    D[e] += 1
possible_length = []
for key,value in D.items():
    if value > 1:
        possible_length.append(key)
if len(possible_length) < 2:
    print(0)
possible_length.sort()
print(possible_length[-1]*possible_length[-2])

Submission status: Runtime Error

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))[::-1]
l = []
for i in range(n-1):
    if a[i] == a[i+1] and a[i] not in l:
        l.append(a[i])
        
print(l[0]*l[1])

Submission status: Runtime Error

Solution code:
n=input()

l=[int(x) for x in input().split()]
temp=list(set(x for x in l if l.count(x)>1))
if temp==[]:
	print("0")
else:	
	y.sort()
	print(a[n]*a[n-1])

Submission status: Runtime Error

Solution code:
n=input()
l=[int(x) for x in input().split()]
temp=list(set(x for x in l if l.count(x)>1))
y=max(temp)
lar=sec=0
if l.count(y)>3:
	lar=sec=y
else:
	lar=y
	temp.remove(y)
	sec=max(temp)
print(lar*sec)

Submission status: Runtime Error

Solution code:
n=input()
l=[int(x) for x in input().split()]
temp=list(set(x for x in l if l.count(x)>1))
y=max(temp)
if l.count(y)>3:
	lar=sec=y
else:
	lar=y
	temp.remove(y)
	sec=max(temp)
print(lar*sec)

Submission status: Runtime Error

Solution code:
n=int(input())
ls=[]
temp=[]
temp= list((for x in input().split()))
temp=list(set([x for x in l if l.count(x)>1]))
for x in l:
	if (l.count(x)>3):
		ls.append(x)
temp+=list(set(ls))
if len(temp)<2:
	print(0)
else:
	temp=[int(x) for x in temp]
	x=max(temp)
	temp.remove(x)
	print(x*max(temp))

Submission status: Runtime Error

Solution code:
n=int(input())
ls=[]
temp=[]
temp= list((for x in input().split()))
temp=list(set([x for x in l if l.count(x)>1]))
for x in l:
	if (l.count(x)>3):
		ls.append(x)
temp+=list(set(ls))
if len(temp)<2:
	print(0)
else:
	x=max(temp)
	temp.remove(x)
	print(x*max(temp))

Submission status: Runtime Error

Solution code:
lst = []
N = int(input("Enter number of elements : "))
for i in range(0,N):
    lst.append(int(input()))
temp = [x for x in lst if lst.count(x)>1]
list_set = set(temp)
# convert the set to the list
dups = (list(list_set))
n=len(dups)
if (n<2):
   print('0\nNo rectangle can be formed')
else:
    a = dups[0]
    b = dups[1]
    for i in range(0, n):
      for j in range(i + 1, n):
        if (dups[i]*dups[j]>a*b):
             a = dups[i]
             b = dups[j]
    print(a*b)
    print(a,' times ',b,' rectangle can be formed')

Submission status: Runtime Error

Solution code:
lst = []
N = int(input("Enter number of elements : "))
for i in range(0,N):
    lst.append(int(input()))
temp = [x for x in lst if lst.count(x)>1]
list_set = set(temp)
dups = (list(list_set))
if (len(dups)<2):
   print('0')
   print('No rectangle can be formed')
else:
    a = dups[0]; b = dups[1]
    n=len(dups)    
    for i in range(0, n):
      for j in range(i + 1, n):
        if (dups[i]*dups[j]>a*b):
             a = dups[i]
             b = dups[j]
    print(a*b)
    print(a,' times ',b,' rectangle can be formed')

Submission status: Runtime Error

Solution code:
lst = []
N = int(input("Enter number of elements : "))
for i in range(0,N):
    lst.append(int(input()))
    temp = [x for x in lst if lst.count(x)>1]
list_set = set(temp)
    # convert the set to the list
dups = (list(list_set))
if (len(dups)<2):
   print('0')
   print('No rectangle can be formed')
else:
    a = dups[0]; b = dups[1]
    for i in range(0, N):

       for j in range(i + 1, N):
            if (dups[i] * dups[j] > a * b):
                a = dups[i]; b = dups[j]
    print(a*b)
    print(a,' times ',b,' rectangle can be formed')

Submission status: Runtime Error

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

arrr = [0]*(max(arr)+2)

for i in arr:
    arrr[i]+=1

s1=0
s2=0

#print(arrr)

for j in range(max(arr),0,-1):
    #print(j)
    if arrr[j]>=2:
        arrr[j]-=2
        s1=j
        break

for j in range(max(arr),0,-1):
    if arrr[j]>=2:
        arrr[j]-=2
        s2=j
        break

print(s1*s2)

Submission status: Runtime Error

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

arrr = [0]*(max(arr)+2)

for i in arr:
    arrr[i]+=1

s1=0
s2=0

for j in range(max(arrr),0,-1):
    if arrr[j]>=2:
        arrr[j]-=2
        s1=j

for j in range(max(arrr),0,-1):
    if arrr[j]>=2:
        arrr[j]-=2
        s2=j

if s1==0 or s2==0:
    print(0)
else:
    print(s1*s2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
    n = int(input())
    vals = list(map(int, input().split()))
    d= {}
    s = [0, 0]
     
    for i in range(n):
        if(vals[i] in d.keys()):
            d[vals[i]] += 1
        else:
            d[vals[i]] = 1
     
     
    for i in d.keys():
        if(d[i] >= 4):
            s.append(i)
            s.append(i)
        elif(d[i] >= 2):
            s.append(i)
    s.sort()
     
    print(s[-1]*s[-2])

Submission status: Runtime Error

Solution code:
    k = int(input())
    vals = list(map(int, input().split()))
    d= {}
    a = [0, 0]
     
    for i in range(k):
        if(vals[i] in d.keys()):
            d[vals[i]] += 1
        else:
            d[vals[i]] = 1
     
     
    for i in d.keys():
        if(d[i] >= 4):
            a.append(i)
            a.append(i)
        elif(d[i] >= 2):
            a.append(i)
    a.sort()
     
    print(a[-1]*a[-2])

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = dict()
c = list()
for i in a:
    if i not in b:
        b[i] = 1
    else:
        b[i] = b[i]+1
for i in b:
    b[i] = int(b[i]/2)
for i in b:
    for j in range(0, b[i]):
        c.append(i)
c.sort()
print(c[len(c)-1]*c[len(c)-2])

Submission status: Runtime Error

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

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

    if 4 <= n and n <= 10**5:
        
        for i in a:
            if not (1 <= i and i <= 10**9 and type(i) == int:
                return

        j = [x for x in a if a.count(x) > 1]
        j.sort(reverse = True)

        if len(j) < 4:
            print(0)
            return

        print(j[0]*j[2])

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
array = list(map(int,input().split()))
array.sort(reverse=True)
array2 = []
tmp = array[0]
for i in range(1,N):
    if tmp == array[i]:
        array2.append(array[i])
    tmp = array[i]
if array2.count(max(array2)) >= 4:
    print(max(array2)**2)
    exit()
array3 = list(set(array2))
array3.sort(reverse=True)
if 2 <= len(array3):
    print(array3[0]*array3[1])
else:
    print(0)

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
b=collections.Counter(a)
c=list(b.items())
d=[]
e=[]
for i in range(len(c)):
  if c[i][1]>3:
    d.append(int(c[i][0]))
  elif c[i][1]>1:
    e.append(int(c[i][0]))
d.sort(reverse=True)
e.sort(reverse=True)
if len(d)<1 and len(e)<2:
  print(0)
else:
  print(max((d[0])**2,e[0]*e[1]))

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
a=list(map(int,input().split()))
b=collections.Counter(a)
c=list(b.items())
d=[]
e=[]
for i in range(len(c)):
  if c[i][1]>3:
    d.append(int(c[i][0]))
  elif c[i][1]>1:
    e.append(int(c[i][0]))
d.sort(reverse=True)
e.sort(reverse=True)
if len(d)<1 and len(e)<2:
  print(0)
else:
  print(max(d[0]**2,e[0]*e[1]))

Submission status: Runtime Error

Solution code:
N = int(input())
li = list(map(int,input().split()))
li.sort()
a = 0
b = 0
while len(li) >= 1:
  if li[-1] == li[-2] and a == 0:
    a = li[-1]
    del li[-1]
  elif li[-1] != li[-2] or  a != 0 and a == li[-1]:
    del li[-1]
  elif li[-1] == li[-2] and a != 0:
    b = li[-1]
    break
print(a * b)

Submission status: Runtime Error

Solution code:
N = int(input())
li = list(map(int,input().split()))
li.sort()
a = 0
b = 0
for i in range(N):
  if li[-1] == li[-2] and a == 0:
    a = li[-1]
    del li[-1]
  elif li[-1] != li[-2] or  a != 0 and a == li[-1]:
    del li[-1]
  elif li[-1] == li[-2] and a != 0:
    b = li[-1]
    break
print(a * b)

Submission status: Runtime Error

Solution code:
def resolve():
	n=int(input())
	a=list(map(int,input().split()))
	s=list(set(a))[::-1]
	l=[0]*3
	k=0
	for i in s:
		if a.count(i)>=4:
			l[k],l[k+1]=i,i
			k+=2
		elif a.count(i)>=2:
			l[k]=i
			k+=1
		if k>1:
			break
	print(l[0]*l[1])
resolve():

Submission status: Runtime Error

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
from collections import Counter 
c=Counter(l)
arr=[i for i in c if c[i]>=2]
arr.sort(reverse=1)
if len(arr)==1 and c[arr[0]]>=4:
    print(0)
else:
    print(arr[0]*arr[1])

Submission status: Runtime Error

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
from collections import Counter 
c=Counter(l)
arr=[i for i in c if c[i]>=2]
arr.sort(reverse=1)
if len(arr)==1:
    print(0)
else:
    print(arr[0]*arr[1])

Submission status: Runtime Error

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



if __name__ == "__main__":
    test()

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=list(Counter(a).values())
lst=[]
for i in range(len(b)):
  if b[i]>1:
    c=Counter(a).keys()
    lst.append(int(c[i]))
Lst=list(set(lst.sort(reverse=True)))
if len(Lst)<2:
  print(0)
else:
  print(Lst[0]*Lst[1])

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=list(Counter(a).values())
lst=[]
for i in range(len(b)):
  if b[i]>1:
    lst.append(int(Counter(a).keys()[i]))
Lst=set(lst)
lst.sort(reverse=True)
Lst_2=set(lst)
if len(Lst)<2:
  print(0)
else:
  print(Lst_2[0]*Lst_2[1])

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=list(Counter(a).values())
lst=[]
for i in range(len(b)):
  if b[i]>1:
    lst.append(int(Counter(a).keys()[i]))
lst.sort(reverse=True)
if len(lst)<2:
  print(0)
else:
  print(lst[0]*lst[1])

Submission status: Runtime Error

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
swi = 0
s = [0, 0]
i = 0
while i < len(a):
    if a[i] == a[i + 1]:
        s[swi] = a[i]
        i += 1
        swi += 1
        if swi == 2:
            break
    i += 1

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

Submission status: Runtime Error

Solution code:
b = -1
ans = [0,0]
count = 0
for i in range(n+1):
    count += 1
    if b != a[i]:
        if count >= 2:
            if ans[0]:
                ans[1] = b
                break
            else: ans[0] = b
        b = a[i]
        count = 0
print(ans[0]*ans[1])

Submission status: Runtime Error

Solution code:
n=int(input())
A=list(map(int,input().split()))
c=[0]*(n+1)
for i in A:
  c[i] += 1
cnt=0
ans=0
for j in reversed(range(n)):
  if c[j]>=2 and cnt==0:
    ans=j
    cnt+=1
  elif c[j]>= 2 and cnt==1:
    ans*=j
    break
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
A=list(map(int,input().split()))
C=[0]*(n+1)
for i in A:
  C[i] += 1
cnt=0
ans=0
for j in reversed(range(n)):
  if C[j]>=2 and cnt==0:
    ans=j
    cnt+=1
  elif C[j]>= 2 and cnt==1:
    ans*=j
    break
print(ans)