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 sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
a = nl()
c = collections.Counter(a)

key = list(c.keys())
key.sort(reverse=True)
count = 0
for i in range(len(key)):
    if c[key[i]] >= 4 and count != 1:
        print(key[i] ** 2)
        exit()
    if c[key[i]] >= 2:
        if count == 0:
            a = key[i]
            count += 1
        elif count == 1:
            b = key[i]
            count += 1
    if count >= 2:
        print(a * b)
        exit()
print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict

N = int(input())
As = sorted(map(int, input().split()), reverse=True)

prev = None
pair = []
for A in As:
    if prev == A:
        prev = None
        pair.append(A)
        if len(pair) == 2:
            break
    else:
        prev = A

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

Submission status: Accepted

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 ans_part==-1:
		if counter[x] >= 4:
			ans = x**2
			break
		elif 2<=counter[x]<=3:
			ans_part=x
	else:
		if counter[x] >= 2:
			ans=ans_part*x
			break
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
dic = {} #key(長方形の辺の要素数max:10**5/2 = 5*10**4) -> sortするとTLE
max1,max2 = 0,0
count = 0

for i in range(N):
  if(A[i] in dic):
    dic[A[i]] += 1
    if(dic[A[i]]%2 == 0):
      count += 1
      if(max1 < A[i]):
        max2 = max1
        max1 = A[i]
      if(A[i] < max1):
        max2 = max(max2,A[i])
  else:
    dic[A[i]] = 1

ans = 0
if(count >= 2):
  if(dic[max1] >= 4):
    ans = max1*max1
  else:
    ans = max1*max2
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import sys
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:
    if l2[i][1]>=4:
      print(l2[i][0]**2)
      sys.exit()
    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: Accepted

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

d = {}
for a in A:
  d[a] = d.get(a,0) + 1
B = [0,0]
for k in d:
  if d[k] >= 4:
    B.append(k)
    B.append(k)
  elif d[k] >=2:
    B.append(k)
B.sort()
print(B[-1]*B[-2])

Submission status: Accepted

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 - 1:
            return 0
        if A[num] == A[num + 1]:
            return chouhoukei(count + 2, ans * A[num], num + 2)
        else:
            return chouhoukei(count, ans, num + 1)


print(chouhoukei(0, 1, 0))

Submission status: Accepted

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 = 0
    else:t = x[i]
if len(k)>=2:
    print(k[0]*k[1])
else:print(0)

Submission status: Accepted

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 n > 3 and remained > 0:
    s *= l
    remained -= 1
    

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

Submission status: Accepted

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:
                del h[i]
                if(i>m1):
                        m2=m1
                        m1=i
                else:
                        m2=max(m2,i)
print(m1*m2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

C = Counter(A)
l = []
for i, v in C.items():
    if v >= 2:
        l.append(i)
    if v >= 4:
        l.append(i)

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

Submission status: Accepted

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

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

    A.sort(reverse = True)
    e = []
    i = 0
    while i < N - 1:
        if A[i] == A[i + 1]:
            e.append(A[i])
            if len(e) == 2:
                print(e[0] * e[1])
                return
            i += 2
        else:
            i += 1


    print(0)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
As = map(int, input().split())
c = Counter(As)

ans = []
for k in reversed(sorted(c.keys())):
    v = c[k]
    while v >= 2:
        ans.append(k)
        v -= 2
        if len(ans) == 2:
            print(ans[0] * ans[1])
            sys.exit(0)
print(0)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))
sorted_A = sorted(A)
before = -1
pair = []
for a in sorted_A[::-1]:
    if a != before:
        before = a
    elif a == before:
        pair.append(a)
        if len(pair) == 2:
            break
        before = -1
ans = 0
if len(pair) == 2:
    ans = pair[0]*pair[1]
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)

rec = [0,0]

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

for key in A:
	d[key] += 1
	if d[key] == 2:
		if key > rec[0]:
			rec[0] = key
			rec = sorted(rec)
		d[key] = 0

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

Submission status: Accepted

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)
    if k >= 4:
        doubled.append(j)
doubled = (sorted(doubled))
if len(doubled) < 2:
    print(0)
else:
    print(doubled[-1]*doubled[-2])

Submission status: Accepted

Solution code:
lfl={}
l1=0
l2=0
n=int(input().strip())
a=list(map(int, input().split()))

for i in range(n):
    if a[i] in lfl:
        lfl[a[i]]+=1
    else:
        lfl[a[i]]=1
    if lfl[a[i]]>=2:
        if l1<a[i]:
            l2=l1
            l1=a[i]
            lfl[a[i]]-=2
        elif l2<a[i]:
            l2=a[i]
            lfl[a[i]]-=2
print(l1*l2)

Submission status: Accepted

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] >= 4:
        l.append(e[0])
        l.append(e[0])
    elif e[1] >= 2:
        l.append(e[0])
l.sort()
if len(l) >= 2:
    print(l[-1]*l[-2])
else:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int,input().split()))
P = list(set(L))
if len(P) == len(L) :
    ans = 0
else :
    D = {}
    ans = 1
    for i in range(N) :
        if L[i] not in D :
            D[L[i]] = 1
        else :
            D[L[i]] += 1
    D = sorted(D.items(),key=lambda x: x[0], reverse=True)
    flag = 0
    for i in range(len(D)) :
        if D[i][1] >= 4 and flag < 1 :
            ans *= D[i][0]**2
            flag += 2
        elif D[i][1] >= 2 and flag < 2 :
            ans *= D[i][0]
            flag += 1
print(ans)

Submission status: Accepted

Solution code:
import sys

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

import collections

c = collections.Counter(A)

S = sorted(c.items(), reverse=True)

max1 = 0
max2 = 0
for s in S:
    if max1 == 0:
        if s[1] >= 4:
            max1 = s[0]
            max2 = s[0]
            break
        elif s[1] >= 2:
            max1 = s[0]
    else:
        if s[1] >= 2:
            max2 = s[0]
            break

print(max1 * max2)

Submission status: Accepted

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()

candidate = sorted(candidate)

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

Submission status: Accepted

Solution code:
import collections
c=collections.Counter()
n=input()
for a in map(int, raw_input().split()):
	c[a]+=1
l=[a for a, num in c.items() if num>=2]+[a for a, num in c.items() if num>=4]
if len(l)<2:
	print 0
else:
	m=max(l)
	l.remove(m)
	print m*max(l)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
def inpl(): return list(map(int, input().split()))

N = int(input())
C= Counter(inpl())

F = sorted([k for k, v in C.items() if v >= 4] + [0])
T = sorted([k for k, v in C.items() if v >= 2] + [0, 0])

print(max(F[-1]*F[-1], T[-1]*T[-2]))

Submission status: Accepted

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
A=sorted(A,reverse=True)
l=0
r=0
t=10**9+7
for i in range(N):
    s=A[i]
    if s==t:
        if l==0:
            l=s
            t=10**9+7
        elif r==0:
            r=s
            t=10**9+7
        continue
    t=A[i]
print(l*r)

Submission status: Accepted

Solution code:
import collections

n = int(input())
a = list(map(int, input().split()))
ac = collections.Counter(a)
quad = [i for i in ac if ac[i] >= 4]
if quad:
    ans = max(quad) ** 2
else:
    ans = 0
twice = sorted([i for i in ac if ac[i] >= 2])
if len(twice) >= 2:
    ans = max(ans, twice[-1] * twice[-2])
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
list_a = list(map(int, input().split()))
dict_a = {}
for i in range(n):
    try:
        dict_a[list_a[i]] += 1
    except KeyError:
        dict_a[list_a[i]] = 1
key_list = []
for key,value in dict_a.items():
    if 2 <= value <= 3:
        key_list.append(key)
    elif 4 <= value:
        key_list.append(key)
        key_list.append(key)
key_list.sort()
try:
    print(key_list[-1] * key_list[-2])
except IndexError:
    print(0)

Submission status: Accepted

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

n = int(input())
a = ai()
from collections import Counter
c = Counter(a)
a = [i for i in c if c[i]>1]
a.sort()
if len(a)>0 and c[a[-1]]>=4:
    print(a[-1]**2)
elif len(a)<2:
    print(0)
else:
    print(a[-1]*a[-2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
a = Counter(map(int, input().split()))
ans = 0
b = [k for k, v in sorted(a.items()) if v >= 2]
for k, v in sorted(a.items(), reverse=True):
    if v >= 4:
        ans = max(ans, k * k)
if len(b) >= 2:
    ans = max(ans, b[-1] * b[-2])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

k = 0
i = 0
while i < N - 1:
    if A[i] == A[i + 1]:
        if k == 0:
            k = A[i]
            i += 1
        else:
            print(k * A[i])
            exit()
    i += 1

print(0)

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
from heapq import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N = read()
cnt = Counter()

for a in reads():
  cnt[a] += 1

edges = sorted([e for e in cnt.keys() if cnt[e] >= 2], reverse=True)

if len(edges) == 0:
  print(0)
else:
  e = edges[0]
  if cnt[e] >= 4:
    print(e*e)
  elif len(edges) <= 1:
    print(0)
  else:
    f = edges[1]
    print(e*f)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
f,s,i = 0,0,0
while i+1<n:
    if a[i]==a[i+1]:
        s = f
        f = a[i]
        i += 1
    i += 1
print(f*s)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
d = {}

for x in input().split():
    a = int(x)
    if a not in d:
        d[a] = 0
    d[a] += 1

ret1 = 0
ret2 = 0
kk = list(d.keys())
kk.sort(reverse=True)
for k in kk:
    if d[k]>=4 and ret1==0:
        ret1 = k**2
        if ret2==0:
            break
    if d[k]>=2:
        if ret2==0:
            ret2 = k
        elif ret2>0:
            ret2 *= k
            break
print(max(ret1,ret2))

Submission status: Accepted

Solution code:
# cook your dish here
n  =  int(input())
a= list(map(int,input().split()))

a.sort()
ass = []
ans  =[]
d = 0

for i in range(n-1):
    if a[i] == a[i+1]:
        ass.append(a[i])
        d += 1
        if d == 3:
            ans.append(a[i])
    else:
        d = 0
ass = list(set(ass))
ass.sort()

if ans != []:
    if max(ans)==max(ass):
        print(max(ans)*max(ans))
    else:
        print(ass[len(ass)-1]*ass[len(ass)-2])
else:
    if len(ass) == 0 or len(ass) == 1:
        print(0)
    else:
        print(ass[len(ass)-1]*ass[len(ass)-2])

Submission status: Accepted

Solution code:
n = int(input())

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

arr.sort()

i = n-1

lines = []

while i > 0 and len(lines) < 2:
	if arr[i] == arr[i-1]:
		lines.append(arr[i])
		i -= 2
		next

	else :
		i -= 1

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

else :
	print 0

Submission status: Accepted

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

a.sort(reverse=True)

i = 0
k = [0, 0]
while i < len(a) - 1:
    if a[i] == a[i + 1]:
        i += 1
        k.append(a[i])
    if len(k) > 3:
        break
    i += 1

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
from collections import defaultdict
d = defaultdict(int)
ans, t = 0, 0
for i in range(n):
  d[a[i]] += 1
  if d[a[i]]==2:
    d[a[i]] = 0
    ans = max(ans, t*a[i])
    t = a[i]
print(ans)

Submission status: Accepted

Solution code:
'''input
4
1 2 3 4
'''
from collections import Counter
n = input()
arr = map(int,raw_input().split())
c = Counter(arr)
li = []
for i in c:
	if c[i] >= 2:
		li.append(i)
li.sort()
if len(li) == 0:
	print "0"
elif len(li) == 1:
	print li[-1]**2
else:
	if c[li[-1]] >= 4:
		print li[-1]**2
	else:
		print li[-1]*li[-2]

Submission status: Accepted

Solution code:
n = int(input())

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

b = {}

for i in a:
    if i in b:
        b[i] += 1
    else:
        b[i] = 1
c = []
for i in b:
    if b[i] >= 4:
        c.append(i)
        c.append(i)
    elif b[i] >= 2:
        c.append(i)
c.sort()
c.reverse()
c.append(0)
c.append(0)
print(c[0]*c[1])

Submission status: Accepted

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

from collections import Counter

n = int(input())
a = list(map(int, input().split()))
b = sorted(list(set(a)), reverse=True)
c = Counter(a)
d = []
for x in b:
    if c[x] >= 4:
        print(d[0] * x if len(d) else x * x)
        exit(0)
    elif c[x] >= 2:
        d.append(x)
        if len(d) == 2:
            print(d[0] * d[1])
            exit(0)
print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
cand = [0]
p = 0
for i in range(n-1,-1, -2):
    if a[i] == a[i-1]:
        if p:
            cand.append(p*a[i])
            break
        else:
            p = a[i]

p = 0
for i in range(n-2,-1, -2):
    if a[i] == a[i-1]:
        if p:
            cand.append(p*a[i])
            break
        else:
            p = a[i]

print(max(cand))

Submission status: Accepted

Solution code:
#なぜ通らない？
from collections import Counter
from operator import itemgetter

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

c = Counter(a)

d = sorted(list(c.items()), key=itemgetter(0), reverse=True)

a = 0
b = 0
for i in d:
	if i[1] >= 4 and a == 0:
		a = i[0]
		b = i[0]
		break
	elif i[1] >= 2 and a == 0:
		a = i[0]
		continue
	elif i[1] >= 2 and a != 0:
		b = i[0]
		break

print(a * b)

Submission status: Accepted

Solution code:
from collections import Counter
input();a=sorted(Counter(map(int,input().split())).most_common())[::-1];c=b=0
for i in range(len(set(a))):
    if b and c:break
    if a[i][1]>3 and a[i][0]*c<a[i][0]**2:b=c=a[i][0]
    elif a[i][1]>1:b,c=c,a[i][0]
print(c*b)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())

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

ans = []

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

Submission status: Accepted

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

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(input())
    ai = list(map(int, input().split()))
    cnt = {}
    for a in ai:
        if a in cnt:
            cnt[a] += 1
        else:
            cnt[a] = 1

    ais = sorted(list(set(ai)), reverse=True)
    longer = 0
    shorter = 0
    for a in ais:
        if cnt[a] >= 2:
            longer = a
            cnt[a] -= 2
            break
    for a in ais:
        if cnt[a] >= 2:
            shorter = a
            cnt[a] -= 2
            break
    print(longer * shorter)

main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
import collections
data=collections.Counter(a)
ans_2=[]
ans_4=[]
for i,j in data.items():
    if 4<=j:
        ans_4.append(i)
    if 2<=j<=3:
        ans_2.append(i)
ans_2.sort()
ans_2.reverse()
ans_4.sort()
ans_4.reverse()
max_4=max_2=mix_24=0
if len(ans_4)!=0:
    max_4=ans_4[0]*ans_4[0]
if 2<=len(ans_2):
    max_2=ans_2[0]*ans_2[1]
if len(ans_4)!=0 and len(ans_2)!=0:
    mix_24=ans_2[0]*ans_4[0]
print(max(max_2,max_4,mix_24))

Submission status: Accepted

Solution code:
from collections import Counter
N=int(input())
A=Counter(list(map(int,input().split())))
a=[0,0]

for i in A:
    if A[i]>=2:
        a.append(i)
    if A[i]>=4:
        a.append(i)
a.sort()
print(a[-1]*a[-2])

Submission status: Accepted

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

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

cnt = sorted(cnt.items(), key=lambda x: x[0], reverse=True)

cand2 = []
cand4 = []
for key,value in cnt:
	if value >= 4:
		cand4.append(key)
	if value >= 2:
		cand2.append(key)
cand4.append(0)
cand2.append(0)
cand2.append(0)

print(max(cand4[0] * cand4[0], cand2[0] * cand2[1]))

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())), reverse=True)
A.append(0)

cnt = 1
sidea = 0
sideb = 0
a = 0
for i in range(1,len(A)):
	if A[i-1] == A[i]:
		a = A[i]
		cnt += 1
	else:
		if cnt >= 4:
			if sidea == 0:
				sidea = a
				sideb = a
				break
			elif sideb == 0:
				sideb = a
				break
		elif cnt >= 2:
			if sidea == 0:
				sidea = a
			elif sideb == 0:
				sideb = a
				break
		cnt = 1
		a = 0

print(sidea*sideb)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
import math
N = int(input())

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

cnter = Counter(As)
V = dict()
select = 0

for k, v in cnter.most_common():
    if v>=2:
        V[k] = math.floor(v/2)
#print(V)
tmp = 0
h = 0

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

for k, v in sorted(V.items(), key=lambda x:-x[0]):
    if v >= 2 and tmp == 0:
        print(int(k*k))
        exit()
    else:
        if(tmp==1):
            print(int(h*k))
            exit()
        tmp += 1
        h = k

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
a = a[::-1]
tobasu = 0
one = 0
two = 0
for i in range(len(a) - 1):
    if tobasu == 1:
        tobasu = 0
        continue
    if a[i] == a[i + 1] and one == 0:
        tobasu = 1
        one = a[i]
    elif a[i] == a[i + 1] and one != 0 and two == 0:
        two = a[i]
        break
print(one * two)

Submission status: Accepted

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

N = int(input())
data = input()
A = data.split(" ")
dict = {}
for i in A:
    if i in dict:
        dict[i] += 1
    else:
        dict[i] = 1

a = 0
b = 0
for i in sorted(dict.items(),key = lambda x:int(x[0])):
    if i[1] >= 4:
        if int(i[0]) >= min(a,b):
            if a >= b:
                b = int(i[0])

            else:
                a = int(i[0])
    if i[1] >= 2:
        if int(i[0]) >= min(a,b):
            if a >= b:
                b = int(i[0])

            else:
                a = int(i[0])

print(a*b)

Submission status: Accepted

Solution code:
n = int(input())
s = input()

a = [int(i) for i in s.split(" ")]
a.sort()
a.reverse()
pairs = []
buf = None
sq = 0
for c in a:
    if buf == c:
        pairs.append(c)
        buf = None
        if len(pairs)==2:
            sq = pairs[0] * pairs[1]
            break
    else:
        buf = c
print(sq)

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:
from sys import stdin, stdout
def readLine_int_list():return list(map(int, stdin.readline().split()))


def main():
    n = int(input())
    a = sorted(readLine_int_list(),reverse=True)
    a.append(-1)
    pair = []
    ans = 0
    t = 1
    
    for i in range(n):
        
        if a[i] == a[i+1]:
            t += 1
        else:
            if t > 1:
                pair.append(a[i])
                if len(pair) == 2:
                    ans = pair[0] * pair[1]
                    break
            t = 1
        
        if t > 3:
            if pair:
                ans = max(a[i-1]*a[i], pair[0]*a[i])
            else:
                ans = a[i]**2
            break

        
        

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

S = set([])
T = []
for a in A:
    if a in S:
        T.append(a)
        S.remove(a)
    else:
        S.add(a)
if len(T) <= 1:
    print("0")
    exit()
T.sort(reverse=True)
ans = T[0] * T[1]
print(ans)

Submission status: Accepted

Solution code:

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

a.sort()

k = 0;
i = len(a)-1
side = [0, 0]

while i >= 0:
	if a[i] == a[i-1]: 
		side[k] = a[i]
		k += 1
		i -= 1
	if k == 2:
		break
	i -= 1
print(side[0]*side[1])

Submission status: Accepted

Solution code:
n=int(input())
a=list(reversed(sorted(map(int,input().split()))))
i,m1,m2=1,0,0
while i<len(a):
	if a[i-1]==a[i]:
		if m1==0: 
			m1=a[i]
		elif m2==0:
			m2=a[i]
			break
		i+=1
	i+=1
print(m1*m2)

Submission status: Accepted

Solution code:
#Make a Rectangle
N = int(input())
A = list(map(int, input().split()))

a = sorted(A, reverse=True)
b = []

i = 0
while i<N-1:
    if ( a[i]==a[i+1] ):
        b+=[a[i]]
        i+=2
    else:
        i+=1
    if (len(b)>1):
        break

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

Submission status: Accepted

Solution code:
n = int(raw_input())

occ = {}
for i in map(int, raw_input().split()):
    if not i in occ:
        occ[i] = 0

    occ[i] += 1

found = 0
rect = 1

for i in sorted(occ, reverse=True):
    if occ[i] >= 4 and found < 1:
        found += 2
        rect *= i*i
    elif occ[i] >= 2:
        found += 1
        rect *= i

    if found == 2:
        print rect
        break
    
if found < 2:
    print 0

Submission status: Accepted

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

Submission status: Accepted

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

counter = Counter(A)
res =[]

for word,cnt in counter.most_common():
    if 4 <= cnt:
        res.append(word)
        res.append(word)
    elif 2 <= cnt:
        res.append(word)

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

Submission status: Accepted

Solution code:
_ = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
l = [0,0]
c = 0
i = 0
while(i < len(a)-1):
    if(a[i] == a[i+1]):
        del l[0]
        l.append(a[i])
        i += 1
        c += 1
    if(c >= 2 or i == len(a)-2):
        i = len(a)-1
        print(l[0] * l[1])
    i += 1

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
l = [0,0]
c = 0
i = 0
while(i < len(a)-1):
    if(a[i] == a[i+1]):
        del l[0]
        l.append(a[i])
        i += 1
        c += 1
    if(c >= 2 or i == len(a)-2):
        i = len(a)-1
        print(l[0] * l[1])
    i += 1

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int, input().split()))
a=sorted(a,reverse=True)
l=len(a)
skip=False
ans=1
flag=0
for i in range(l) :
    if skip :
        skip=False
        continue
    if i == l-1 :
        print(0)
        break
    if a[i] == a[i+1] :
        ans *= a[i]
        flag += 1
        skip=True
        if flag == 2 :
            print(ans)
            break

Submission status: Accepted

Solution code:
raw_input()
ls = map(int, raw_input().split(" "))
ls.sort()
ls.reverse()
i = 0
answer = []
while i < len(ls) - 1:
  if ls[i] == ls[i+1]:
    answer.append(ls[i])
    if len(answer) >= 2:
      break
    i += 1
  i += 1

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

Submission status: Accepted

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

bars.sort(reverse=True)

flag = 0
l = 0
l1 = 0
l2 = 0

for x in bars:
    if flag==0:
        l = x
        flag = 1
    elif flag==1 and x==l and l1==0:
        l1 = x
        l = 0
        flag = 0
    elif flag==1 and x==l and l1!=0:
        l2 = x
        break
    else:
        l = x
        flag = 1

print(l1 * l2)

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
n = input()

a = map(int, raw_input().split())
a = list(reversed(sorted(a)))

i = 1
b = []
cnt = 0

while True:
    if cnt > 1:
        break
    elif i >= len(a):
        print 0
        exit()
    if a[i] == a[i-1]:
        # print(a[i])
        b.append(a[i])
        cnt += 1
        i += 1
    i += 1
if cnt > 1:    
    print b[0] * b[1]

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
import sys
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
a = Counter(A)
width = -1
height = -1
candinate = []
for tmp in reversed(sorted(list(set(A)))):
    b = a[tmp]
    if b >= 4:
        if width == -1:
            width = tmp
        if height == -1:
            height = tmp
    elif b >= 2:
        if width == -1:
            width = tmp
            b = 0
        if height == -1 and b != 0:
            height = tmp
    else:
        pass
    if width != -1 and height != -1:
        print(width*height)
        sys.exit()
print(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
N = int(input())
A = tuple(map(int, input().split()))
c = Counter(A)

pairs = []
for k, v in c.items():
    if v >= 4:
        pairs.extend([k]*2)
    elif v >= 2:
        pairs.append(k)

if len(pairs) >= 2:
    a, b = sorted(pairs, reverse=True)[:2]
    print(a*b)
else:
    print(0)

Submission status: Accepted

Solution code:
import numpy as np


def getInput():
    separator = ' '
    ret_array = []
    while True:
        try:
            row = input().split(sep=separator)
            ret_array.append(row)
        except EOFError:
            break
    return ret_array


g = getInput()
N = g[0][0]
A = np.array(g[1], dtype=np.int32)
A = np.sort(A, kind='mergesort')
A = A[::-1]

idx = 0
ph = np.empty((2,), dtype=np.int32)
try:
    for c in range(0, 2):
        while True:
            if A[idx] == A[idx + 1]:
                ph[c] = A[idx]
                idx += 2
                break
            else:
                idx += 1
except IndexError:
    print(0)
    exit()

print(np.prod(ph))

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())) + [0, 0, 0, 0], reverse=True)

res = []
tmp = -1
for a in A:
    if a == tmp:
        res.append(a)
        tmp = -1
    else:
        tmp = a
    if len(res) >= 2:
        break

res = sorted(res, reverse=True)

result = 1
for i in range(2):
    result *= res[i]

print(result)

Submission status: Accepted

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

res = [0, 0]
tmp = -1
for a in A:
    if a == tmp:
        res.append(a)
        tmp = -1
    else:
        tmp = a
    if len(res) >= 4:
        break

res = sorted(res, reverse=True)

result = 1
for i in range(2):
    result *= res[i]

print(result)

Submission status: Accepted

Solution code:
input()
a=sorted(list(map(int,input().split())))
e={}
r=[]
for i in a:
  if not e.get(i):
    e[i]=1
  else:
    e[i]=0
    r.append(i)
print(0 if len(r) < 2 else r[-1] * r[-2])