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: Accepted

Solution code:
import collections

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

cnt = collections.Counter(A)
k2 = []
k4 = []
for k in cnt:
    if cnt[k] >= 2:
        k2.append(k)
    if cnt[k] >= 4:
        k4.append(k)
ans = 0
k2.sort()
k4.sort()
if len(k4) >= 1:
    ans = max(ans, k4[-1] * k4[-1])
if len(k2) >= 2:
    ans = max(ans, k2[-1] * k2[-2])
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

input()
ans = []
for k, v in Counter([int(i) for i in input().split()]).items():
  if v >= 2:
    if v >= 4:
      ans.extend([k, k])
    else:
      ans.append(k)
ans.sort()
print(0 if len(ans) < 2 else ans[-1]*ans[-2])

Submission status: Accepted

Solution code:
#coding utf-8
import collections
_=input()
bars=[i for i in map(int,input().split())]
data=sorted(collections.Counter(bars).items(),key= lambda x: -x[0] )
stock=0
ret=0
for bar ,count in data:
    if count>=4:
        if stock:
            ret=stock*bar
            break
        else:
            ret=bar*bar
            break
    elif count>=2:
        if stock:
            ret=stock*bar
            break
        else:
            stock=bar
print(ret)

Submission status: Accepted

Solution code:
#ARc081C
import sys

n=int(raw_input())
l=map(int,raw_input().split())
l1=sorted(l,reverse=True)
l2=[]
for i in xrange(n-1):
 if l1[i]==l1[i+1]:
  l2.append(l1[i])
if l2==[]:
 print 0
 sys.exit()
ls=sorted(list(set(l2)),reverse=True)
if l1.count(ls[0])>3:
 res=ls[0]**2
else:
 res=ls[0]*ls[1]
print res

Submission status: Accepted

Solution code:
#C_Make_A_Rectangle

def MakeRectangle(N, A):
    A = sorted(A, reverse=True)
    length_list = list()
    length_buff = 0
    for length in A:
        if len(length_list) == 2:
            break
        if length_buff == length and length != 0:
            length_list.append(length)
            length_buff = 0
        else:
            length_buff = length
    if len(length_list) < 2:
        return 0
    else:
        return length_list[0] * length_list[1]


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    S = MakeRectangle(N, A)
    print(S)

Submission status: Accepted

Solution code:
#C_Make_A_Rectangle
import numpy as np

def MakeRectangle(N, A):
    A = np.array(A)
    length_list = list()
    length_buff = 0
    for length in np.sort(A)[::-1]:
        if len(length_list) == 2:
            break
        if length_buff == length and length != 0:
            length_list.append(length)
            length_buff = 0
        else:
            length_buff = length
    if len(length_list) < 2:
        return 0
    else:
        return length_list[0] * length_list[1]


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    S = MakeRectangle(N, A)
    print(S)

Submission status: Accepted

Solution code:
from collections import Counter

input()
t = Counter([int(i) for i in input().split()])
ans = []
for k, v in t.items():
  if v >= 2:
    if v >= 4:
      ans.extend([k, k])
    else:
      ans.append(k)
ans.sort()
if len(ans) < 2:
  print(0)
else:
  print(ans[-1]*ans[-2])

Submission status: Accepted

Solution code:
from collections import defaultdict

input()
t = defaultdict(lambda: 0)
for e in [int(i) for i in input().split()]:
  t[e] += 1
ans = []
for k, v in t.items():
  if v >= 2:
    if v >= 4:
      ans.extend([k, k])
    else:
      ans.append(k)
ans.sort()
if len(ans) < 2:
  print(0)
else:
  print(ans[-1]*ans[-2])

Submission status: Accepted

Solution code:
x = input()
a = []
a = map(int, raw_input().split())
b = []
d = {}
for i in range(len(a)):
    if a[i] in d:
        d[a[i]]+=1
    else:
        d[a[i]] = 1
g = []
for key in d:
    if d[key]>=2:
        b.append(key)
    if d[key]>=4:
        g.append(key)
b.sort()
g.sort()
if len(b)<2 and len(g) == 0:
    print 0
else:
    if len(b)<2:
        b.append(0)
        b.append(0)
    if len(g)==0:
        g.append(0)
    print max(b[len(b)-1]*b[len(b)-2], g[len(g)-1]*g[len(g)-1])

Submission status: Accepted

Solution code:
n = input()
bars = map(int,raw_input().split(' '))
bars.sort()
h1_cand=0
h2_cand=0
h1=0
h2=0
for i in range(n):
  m = n-1-i
  if h1 > 0:
    if h2_cand == bars[m]:
      h2 = h2_cand
      break
    else:
      h2_cand = bars[m]
  else:
	if h1_cand == bars[m]:
    	  h1 = h1_cand
    	  h1_cand = 0
  	else:
    	  h1_cand = bars[m]
 
print h1*h2

Submission status: Accepted

Solution code:
n = int(input())
s = set()
q = [0,0]
import heapq as hq
for a in map(int, input().split()):
  if a > q[0]:
    try:
      s.remove(a)
      hq.heapreplace(q, a)
    except:
      s.add(a)

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

Submission status: Accepted

Solution code:
#! /usr/bin/env python3

def main():
    N = int(input())
    L = sorted(map(int, input().split()))
    a = b = 0
    c = len(L) - 1
    while c > -1:
        t = L[c]
        c -= 1
        if a == t:
            break
        else:
            a = t
    while c > -1:
        t = L[c]
        c -= 1
        if b == t:
            break
        else:
            b = t
    print(a*b)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#! /usr/bin/env python3

def main():
    N = int(input())
    L = sorted(map(int, input().split()))[::-1]
    a = b = c = 0
    while c < len(L):
        t = L[c]
        c += 1
        if a == t:
            break
        else:
            a = t
    while c < len(L):
        t = L[c]
        c += 1
        if b == t:
            break
        else:
            b = t
    print(a*b)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
input()

a = map(int, raw_input().split())
a.sort(reverse = True)

edge = []
p = 1
while p < len(a):
      if a[p] == a[p-1]:
              edge.append(a[p])
              p += 2
      else:
              p += 1

edge.append(0)
edge.append(0)
print edge[0] * edge[1]

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    A.sort(reverse=True)

    v = []
    while len(A) > 1:
        if len(v) == 2:
            break

        if A[0] == A[1]:
            v.append(A[0])
            A.pop(0)
            A.pop(0)
        else:
            A.pop(0)

    if len(v) == 1 or len(v) == 0:
        print(0)
    else:
        print(v[0] * v[1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [ 0, 0 ]
i = 0
while i + 1 < n:
    if a[i] == a[i + 1]:
        b += [ a[i] ]
        i += 2
    else:
        i += 1
print(b[-2] * b[-1])

Submission status: Accepted

Solution code:

n = int(input().strip())

li = list(map(int,input().strip().split()))

d = {}
res = []
for i in li:
    d[i] = d.get(i,0)+1
    if(d[i] == 2 or d[i]==4):
        res.append(i)

if(len(res)<2):print(0)
else:
    res = sorted(res,reverse=True)
    print(res[0]*res[1])

Submission status: Accepted

Solution code:
def spaceinput():
    return list(map(int,input().split(" ")))


N=int(input())
a=spaceinput()


sa=sorted(a,reverse=True)
x=[]
i=0
while True:
    if i>=len(sa)-1:
        break
    ssa=sa[i]
    if sa[i]==sa[i+1]:
        x.append(ssa)
        i+=2
        if len(x)==2:
            break
        continue

    else:
        i+=1


x.extend([0,0])

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

Submission status: Accepted

Solution code:
import math
n = int(input())
ar = list(map(int,input().split()))
ar.sort()
ar.reverse()
ans = []
i=0
while True:
    if len(ar)-1 <= i or len(ans) >=2:
        break
    if ar[i] == ar[i+1]:
        ans.append(ar[i])
        i+=1
    i+=1
if(len(ans)<2):
    print(0)
else:
    print(ans[0]*ans[1])

Submission status: Accepted

Solution code:
from collections import Counter

n = input()
ac = Counter(map(int, input().split()))

w, h = 0, 0
for i in sorted(ac.keys(), reverse=True):
    if ac[i] == 1:
        continue
    if w:
        h = i
        break
    if ac[i] >= 4:
        w = h = i
        break
    w = i

print(w * h)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
s = 1
count = 0
after = False

for i in range(len(a)-1):
	if after:
		after = False
		pass
	else:
		if count == 2:
			break
		else:
			if a[i] == a[i+1]:
				s = s * a[i]
				count += 1
				after = True

if count == 2:
	print(s)
else:
	print(0)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
a=[int(i) for i in input().split()]
s=Counter(a)
b=[]
for key, val in s.items():
 if 4>val>=2:
   b.append(key)
 elif val>=4:
   b.append(key)
   b.append(key)
if len(b)>1:
  b.sort()
  print(b[-1]*b[-2])
else:
  print(0)

Submission status: Accepted

Solution code:
from collections import Counter
_ = input()
c = {k: x for k, x in Counter(map(int, input().split())).items() if x>=2}
d = sorted(list(c.keys()), reverse=True)
if len(c) < 1:
    print(0)
elif c[d[0]] >= 4:
    print(d[0] ** 2)
elif len(c) < 2:
    print(0)
else:
    print(d[0] * d[1])

Submission status: Accepted

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

a = sorted(a)
i = len(a) - 1
b = []

while (i - 1 >= 0):
	if (a[i] == a[i - 1]):
		b.append(a[i - 1])
		i -= 2

	else:
		i -= 1

	if(len(b) == 2):
		break


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

else:
	print(0)

Submission status: Accepted

Solution code:
import collections

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

s = collections.Counter(A)
res = 1
count = 0

for i in sorted(list(set(A)))[::-1]:
    if 4 <= s[i] and count != 1:
        res *= i
        res *= i
        count += 2
    elif 2 <= s[i]:
        res *= i 
        count += 1

    if count == 2:
        break

if count == 2:
    print(res)
else:
    print(0)

Submission status: Accepted

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

ai.sort()

i1 = -1
i2 = -1
b = 0
for i in range(n - 1, b - 1, -1):
    if ai[i - b] == ai[i - 1 - b]:
        b += 1
        if i1 == -1:
            i1 = ai[i - b]
        else:
            i2 = ai[i - b]
            print(i1 * i2)
            break

if i2 == -1:
    print(0)

Submission status: Accepted

Solution code:

import sys
from collections import deque
import copy
import numpy as np

from math import *
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = list(read_func().strip().split())
    length_set = set([])
    appeared_count = {}
    for i in range(N):
        A = int(input_raw[i])
        if A not in appeared_count:
            appeared_count[A] = 1
        else:
            appeared_count[A] += 1
            length_set.add(A)



    if len(length_set) == 0:
        print 0
    else:
        length_list = list(length_set)
        length_list.sort(reverse = True)
        max_length = length_list[0]
        next_maxt_length = length_list[1]

        if appeared_count[max_length] >= 4:
            print max_length * max_length
        else:
            print max_length * next_maxt_length

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=1)
a=0
b=0
j=N-1
for i in range(N-1):
  if A[i]==A[i+1]:
    a=A[i]
    j=i
    break
for i in range(j+2,N-1):
  if A[i]==A[i+1]:
    b=A[i]
    break

print(a*b)

Submission status: Accepted

Solution code:
n = int(input())
xs = [int(i) for i in input().split()]
dict = {}
for i in range(n):
    if xs[i] in dict:
        dict[xs[i]] += 1
    else:
        dict[xs[i]] = 1
edges = []
for k in dict.keys():
    while dict[k] >= 2:
        edges.append(k)
        dict[k] /= 2
edges.sort()
edges.reverse()
if len(edges) >= 2:
    print(edges[0] * edges[1])
else:
    print(0)

Submission status: Accepted

Solution code:
from copy import deepcopy as dcopy


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

    A.sort(reverse=True)

    p = 0
    q = 0
    pre = A[0]
    for a in range(1, len(A)):
        bpre = dcopy(pre)
        pre = A[a]
        if A[a] == bpre:
            if p == 0:
                p = A[a]
                pre = 0
            else:
                q = A[a]
                break

    print(p*q)

        
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))
def plis(a): return " ".join(list(map(str, a)))

N = ri()
A = rli()
A.sort(reverse=True)

st = -1
l1 = 0
l2 = 0
for i in A:
    if i == st:
        if(l1 != 0):
            l2 = i
            break
        else:
            l1 = i
        st = -1
    else:
        st = i
print(l1*l2)

Submission status: Accepted

Solution code:
# encoding:utf-8
def main():
	n = int(input())
	bars = list(map(int, input().split()))

	bars.sort(reverse = True)

	d = {}
	used = []

	for bar in bars:
		if bar in d:
			d[bar] += 1
			if d[bar] == 2:
				used.append(bar)
				d[bar] = 0
		else:
			d[bar] = 1

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

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
#! /usr/bin/env python3

N = int(input())
L = sorted(map(int, input().split()))[::-1]
a = 0
b = 0
while L:
    t = L.pop(0)
    if a == t:
        break
    else:
        a = t
while L:
    t = L.pop(0)
    if b == t:
        break
    else:
        b = t
    
print(a*b)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
C = Counter(A)
t = 2
E = sorted(C.keys())
E.reverse()
ans = 1
for e in E:
    if(C[e] >= 4):
        t -= 1
        ans *= e
    if(t > 0 and C[e] >= 2):
        ans *= e
        t -= 1
    if(t <= 0):
        print(ans)
        break
else:
    print(0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import re
import math
import collections
import itertools
import functools

DEBUG = True
DEBUG = False

def dbg(*args):
    if DEBUG:
        print("DBG: ", file=sys.stderr, end="")
        print(*args, file=sys.stderr)



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

    d = collections.defaultdict(int)
    for a in map(int, input().split()):
        d[a] += 1

    #l = sorted(d.items(), key=lambda item: item[1], reverse=True)
    cands = filter(lambda item: item[1] >= 2, d.items())
    l = sorted(cands, key=lambda item: item[0], reverse=True)
    #print(l)

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

if __name__ == "__main__": main()

Submission status: Accepted

Solution code:
# coding: utf-8
from collections import defaultdict


def II(): return int(input())
def ILI(): return list(map(int, input().split()))


def read():
    N = II()
    A = ILI()
    return N, A


def solve(N, A):
    count = defaultdict(int)
    for a in A:
        count[a] += 1
    l_len = [(key, value) for key, value in count.items() if value >= 2]
    l_len.sort(key= lambda x: -x[0])
    if len(l_len) <= 1:
        ans = 0
    else:
        if l_len[0][1] >= 4:
            ans = l_len[0][0] ** 2
        else:
            ans = l_len[0][0] * l_len[1][0]
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(raw_input())
N=map(int,raw_input().split())
d={}
for i in N:
    d[i]=0
for i in N:
    d[i]+=1
res=res2=res3=0
for i in N:
    if d[i]>=2:
        res=max(res,i)
for i in N:
    if d[i]>=2 and i!=res:
        res2=max(res2,i)
for i in N:
    if d[i]>=4:
        res3=max(res3,i)
print max(res*res2,res3*res3)

Submission status: Accepted

Solution code:
n=int(input())
freq={}
for x in list(map(int,input().split())):
    if x not in freq:
        freq[x] = 1
    else:
        freq[x] += 1

s = []
ans = [0]
for i, v in sorted(list(freq.items()),reverse=True):
    if v >= 4:
        ans.append(i * i)
    if v >= 2:
        s.append(i)
        if len(s) == 2:
            ans.append(s[0] * s[1])

print(max(ans))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(num) for num in input().split()]

a.sort()
first = 0
second = 0
i = 0
while i + 1 < n:
    #print(i)
    if (a[i] == a[i + 1]):
        second = first
        first = a[i]
        i += 1
    i += 1
        

print(first * second)

Submission status: Accepted

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

cnt = {}
for ai in a:
    if ai in cnt:
        cnt[ai] += 1
    else:
        cnt[ai] = 1

ls = []
for k, v in cnt.items():
    if 4 <= v:
        ls.append(k)
    if 2 <= v:
        ls.append(k)
if len(ls) <= 1:
    print(0)
else:
    ls = list(reversed(sorted(ls)))
    print(ls[0] * ls[1])

Submission status: Accepted

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

    cnt = {}
    for a in A:
        if a not in cnt:
            cnt[a] = 0
        cnt[a] += 1

    B = []
    for a, x in cnt.items():
        if x >= 2:
            B.append(a)

    B = sorted(B, reverse=True)
    if len(B) > 0 and cnt[B[0]] >= 4:
        print(B[0] ** 2)
    elif len(B) > 1:
        print(B[0] * B[1])
    else:
        print('0')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
sticks = dict()
for a in map(int, input().split()):
    sticks[a] = sticks.get(a, 0) + 1
sticks = sorted([(k, v) for k, v in sticks.items() if v >= 2], reverse=True)
if len(sticks) == 0 or (len(sticks) == 1 and sticks[0][1] < 4):
    print(0)
elif sticks[0][1] >= 4:
    print(sticks[0][0] ** 2)
else:
    print(sticks[0][0] * sticks[1][0])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from math import *
import random

def readln():
    return list(map(int,(input().split(" "))))

N = int(input())
A = sorted(readln())
x,y = 0,0
for i in range(1,N):
    if(A[i] == A[i-1]):
        y = x
        x = A[i]
        A[i] = 0
print(x*y)

Submission status: Accepted

Solution code:
from collections import Counter

N = input()
A = map(int, raw_input().split())
C = Counter(A)

m1 = -1
m2 = -1

for k in C.keys():
    if C[k] >= 4 and m1 < k:
        m1, m2 = k, k
    elif C[k] >= 2 and m1 < k:
        m1, m2 = k, m1
    elif C[k] >= 2 and m2 < k:
        m2 = k

if m1 < 0 or m2 < 0:
    print 0
else:
    print m1 * m2

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
C = Counter(map(int,input().split()))
quad = [i for i in C if C[i] >= 4]
if quad: maxa = max(quad)**2
else: maxa = 0

twice = [i for i in C if C[i] >= 2]
twice.sort()
if len(twice) >= 2: maxa = max(maxa, twice[-1]*twice[-2])
print(maxa)

Submission status: Accepted

Solution code:
n = input()
A = map(int, raw_input().split())

count = {}
for a in A:
    count[a] = count.get(a, 0) + 1
can = []
for a in count:
    can.extend([a]*(count[a]/2))
can.sort()
if len(can) < 2:
    print 0
else:
    print can[-1]*can[-2]

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n = I()
    a = LI()
    d = collections.defaultdict(int)
    for c in a:
        d[c] += 1
    r = []
    for k,v in sorted(d.items(),reverse=True):
        if v >= 4:
            r.append(k)
            r.append(k)
            break
        elif v >= 2:
            r.append(k)
            if len(r) > 1:
                break
    if len(r) > 1:
        return r[0] * r[1]

    return 0

print(main())

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int mod = 998244353;

int main() {
	int n;
	cin >> n;
	map<int, int> mp;
	rep(i, n) {
		int a;
		cin >> a;
		mp[a]++;
	}
	ll w = 0, h = 0;
	for (auto a : mp) {
		if (a.second >= 2) {
			if (w < a.first) h = w, w = a.first;
			else if (h < a.first) h = a.first;
		}
	}
	cout << w * h << endl;
	return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())
aa = list(map(int, input().split()))
bb = set()
cc = set()

for a in aa:
  if aa.count(a) > 1:
    bb.add(a)
  if aa.count(a) >3:
    cc.add(a)
    
m1 = max(bb)
bb.remove(m1)
m2 = max(bb)

if len(cc) > 0:
  y = max(cc)
else:
  y = 0

if len(bb) >= 2:
  ans = max(m1*m2, y*y)
else:
  ans = max(0, y*y)
print(ans)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
alist = list(map(int,input().split()))
adic = collections.Counter(alist)
A = [0,0]
for i in adic:
  if adic[i] > 1:
    A.append(i)
  if adic[i] > 3:
    A.append(i)
sortedA = sorted(A)
print(sorted[-1]*sorted[-2])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
alist = list(map(int,input().split()))
adic = collections.Counter(alist)
for k,v in adic.items():
  if v == 1:
    del(adic[k])
sort_adic = sorted(adic.items(), reverse = True, key = lambda x:x[1])
li = list(sort_adic.items())
print(li[0][0]*li[1][0])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
alist = list(map(int,input().split()))
adic = collections.Counter(alist)
for k,v in adic.items():
  if v == 1:
    del(adic[k])
sort_adic = sorted(adic.items(), reverse = True, key = lambda x:x[1])
li = list(sort_adic.items())
print(li[0][1]*li[1][1])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
alist = list(map(int,input().split()))
adic = collections.Counter(alist)
for k,v in adic.items():
  if v == 1:
    del(adic[k])
sort_adic = sorted(adic.items(), reverse = True, key = lamda x:x[1])
li = list(sort_adic.items())
print(li[0][1]*li[1][1])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
alist = list(int,input().split())
adic = collections.Counter(alist)
for k,v in adic.items():
  if v == 1:
    del(adic[k])
sort_adic = sorted(adic.items(), reverse = True, key = lamda x:x[1])
li = list(sort_adic.items())
print(li[0][1]*li[1][1])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
alist = list(int,input().split())
adic = collections.Counter(alist)
for k,v in adic.items():
  if v == 1:
    del(dic[k])
sort_adic = sorted(adic.items(), reverse = True, key = lamda x:x[1])
li = list(sort_adic.items())
print(li[0][1]*li[1][1])

Submission status: Runtime Error

Solution code:
from collections import Counter

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

over4 = []
over2 = []

for k, v in c.items():
    if v >= 4:
        over4.append(k)
    elif v >= 2:
        over2.append(k)

over4.sort(reverse=True)
over2.sort(reverse=True)

s1, s2, s3 = 0, 0, 0
if len(over4) > 0:
    s1 = over4[0]**2
if len(over2) >= 1:
    s2 = over2[0]*over2[1]
if len(over4) > 0 and len(over2) > 0:
    s3 = over4[0]*over2[0]

print(max(s1, s2, s3))

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
f=0
s=0
mx=max(a)
cnt=[0]*(mx+1)
for i in a:
  cnt[i]+=1
for (j,i) in zip(cnt,range(mx+1)):
  if j>=2:
    if j>=4:
      f=i
      s=i
    else:
      s=f
      f=i
print(f*s)

Submission status: Runtime Error

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

lst = [0] * max(a)

l1 = 0
l2 = 0

for i in range(n):
    lst[a[i] - 1] += 1
    temp = lst[a[i] - 1]
    if temp >= 4:
        l1 = a[i]
        l2 = a[i]
    elif l1 != a[i] and temp >= 2:
        l1, l2 = a[i], l1
print(l1 * l2)

Submission status: Runtime Error

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

lst = [0] * max(a)

l1 = 0
l2 = 0

for i in range(n):
    lst[a[i] - 1] += 1
    temp = lst[a[i] - 1]
    if temp >= 4:
        l1 = a[i]
        l2 = a[i]
    elif l1 != a[i] and temp >= 2:
        l1, l2 = a[i], l1
print(l1 * l2)

Submission status: Runtime Error

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

a_max = max(an)
z = [0 for i in range(a_max)]
l = sorted(an, reverse=True)
l2 = []
flag = 0
for i in range(len(l)):
    if z[l[i]-1]==1:
        l2.append(l[i])
        flag+=1
        z[l[i]-1]+=1
    else:
        z[l[i]-1]+=1
    if flag == 2:
        break
Ans = l2[0]*l2[1]
print(Ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
cnt=0
data=[0]*max(a)
while cnt<n-1:
  if a[cnt]==a[cnt+1]:
    data[a[cnt]-1]+=1
    cnt+=2
  else:
    cnt+=1
data.reverse()
h=0
w=0
for i in range(len(data)):
  if data[i]==0:
    continue
  elif data[i]==1:
    if h==0:
      h=len(data)-i
    elif h!=0 and w==0:
      w=len(data)-i
  elif data[i]>=2:
    if h==0:
      h=len(data)-i
    if w==0:
      w=len(data)-i
  if h!=0 and w!=0:
    break
print(h*w)

Submission status: Runtime Error

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

b1 = [i[0] for i in c.items() if i[1] >= 4]
b2 = [i[0] for i in c.items() if 4 >= i[1] >= 2]
b = b1 + b2 

b.sort()
print(b[-1]*b[-2])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
a = list(map(int,input().split()))
c = sorted(collections.Counter(a).items(),reverse = True)

num2=[]
num4=[]

for k in c:
  if k[1]>=4:
    num4.append(k[0])
  if k[1]>=2:
    num2.append(k[0])

if len(num2)>=2 or len(num4)>=1:
  print(max(num2[0]*num2[1],num4[0]**2))
else:
  print(0)

Submission status: Runtime Error

Solution code:
W, H, x, y = map(int, input().split())
v = x/W
h = y/H
if v and h == 0.5 :
    print(W*H/2, 1)
else:
    print(W*H/2, 0)

Submission status: Runtime Error

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

Side = [0] * (10**5+1)
for a in A: Side[a] += 1

Side_2 = [i for i, x in enumerate(Side) if (x >= 2) and (x < 4)]
Side_4 = [i for i, x in enumerate(Side) if x >= 4]

if (len(Side_2) < 2) and not Side_4:
  print(0)
  exit()

if not Side_2 and Side_4:
  print(Side_4[-1]*2)
  exit()

if (len(Side_2) >= 2) and not Side_4:
  print(Side_2[-1]*Side_2[-2])
  exit()
  
if (len(Side_2) == 1) and Side_4:
  max2 = Side_2[-1]
  max4 = Side_4[-1]
  if max4 >= max2:
    print(max4*2)
    exit()
  else:
    print(max4*max2)
    exit()
    
if (len(Side_2) >= 2) and Side_4:
  max2 = Side_2[-1]
  max2_2 = Side_2[-2]
  max4 = Side_4[-1]
  if max4 >= max2:
    print(max4*2)
    exit()
  elif (max4 < max2) and (max4 <= max2_2):
    print(max2 * max2_2)
    exit()
  elif (max4 < max2) and (max4 > max2_2):
    print(max2 * max4)
    exit()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[38]:


import collections


# In[43]:


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


# In[49]:


a_cnt = collections.Counter(A)
p = sorted([i for i in a_cnt.items() if i[1] >= 2], reverse=True)
if p[0][1]>=4:
    print(p[0][0]**2)
elif len(p) > 1:
    print(p[0][0]*p[1][0])
else:
    print(0)


# In[ ]:

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

d = defaultdict(int)
n = readInt()
for i in readChars():
	d[i]+=1

d = [i for i in sorted(d.items(), reverse=True) if i[1]>=2]

if len(d)==0:
	print(0)
	exit()
elif len(d)==1:
	if d[0][1]>=4:
		pass
	else:
		print(0)
		exit()
if d[0][1]>=4:
	print(int(d[0][0])**2)
else:
	print(int(d[0][0])*int(d[1][0]))
	raise Exception

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

d = defaultdict(int)
n = readInt()
for i in readChars():
	d[i]+=1

d = [i for i in sorted(d.items(), reverse=True) if i[1]>1]

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

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

Submission status: Runtime Error

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

c=[0]*(max(a)+10)

for i in range(n):
    c[a[i]]+=1

short_edge=0
long_edge=0
for i in range(len(c)):
    if c[i]>=4:
        long_edge=i
        short_edge=i
    elif c[i]>=2:
        short_edge=long_edge
        long_edge=i
    else:
        pass

print(long_edge*short_edge)

Submission status: Runtime Error

Solution code:
from collections import defaultdict

n = int(input())
A = map(int, input().split())
C = defaultdict(int)
for a in A:
    C[a] += 1
C = sorted(C.items(), key=lambda x: x[1])
rods = []
for k, v in C:
    if v >= 4:
        rods.append(k, k)
        break
    if v >= 2:
        rods.append(k)
    if len(rods) == 2:
        break
if len(rods) >= 2:
    ans = rods[0]*rods[1]
else:
    ans = 0
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
for i in a:
  if i not in b:
    b+=[i]
  else:
    c+=[i]
c=list(set(c))
print(c[-1]*c[-2])

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
for i in a:
  if i not in b:
    b+=[i]
  elif i in b:
    if i not in c:
      c+=[i]
c=list(set(c))
print(c[-1]*c[-2])

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))
b=reversed()
c=[]
for i in b:
  if a.count(i)>=2:
    c+=[i]
    if len(c)==2:
      break
if len(c)<=1:
  print(0)
else:
  print(c[0]*c[1])