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:
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
ans=0
c=Counter(A).most_common()
c.sort(reverse=True)
l=[0]*2
four=[0]*2
for t in c:
    if t[1]>=2:
        l.append(t[0])
        if t[1]>=4:
            four.append(t[0])

l.sort(reverse=True)
four.sort(reverse=True)
    
ans=max(l[0]*l[1],four[0]*four[0])
print(ans)

Submission status: Accepted

Solution code:
n,a=int(input()),sorted(list(map(int,input().split())))
i=n-1
ans=1;c=0
while i>0:
  if a[i-1]==a[i]:
    i-=1
    c+=1
    ans*=a[i]
    if c==2:print(ans);exit()
  i-=1
print(0)

Submission status: Accepted

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

from collections import Counter
counter = Counter(an)

sc = sorted([(a, c) for a, c in counter.most_common() if c >= 2], key=lambda ac: ac[0], reverse=True)
if len(sc) < 2:
    print(0)
elif sc[0][1] >= 4:
    print(sc[0][0] ** 2)
else:
    print(sc[0][0] * sc[1][0])

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for i in a:
  d[i] += 1
l = [0, 0]
for k, v in d.items():
  if v >= 4 and k >= max(l):
    l = [k, k]
  elif v >= 2 and k >= min(l):
    l = sorted(l)
    l[0] = k
print(l[0]*l[1])

Submission status: Accepted

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
from collections import Counter
lst=list(Counter(l).items())
lst.sort(reverse=True)
num=0
for i in range(n):
    if lst[i][1]>3:
        if num==0:
            ans=lst[i][0]**2
            num+=2
            break
        elif num==1:
            ans*=lst[i][0]
            num+=1
            break
    elif 1<lst[i][1]<=3:
        if num==0:
            ans=lst[i][0]
            num+=1
        elif num==1:
            ans*=lst[i][0]
            num+=1
            break
    else:
        continue
if num==2:
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
n=int(input())
l=input()
m=l.split(" ")
lst=[]
for i in m:
    lst.append(int(i))
lst.sort(reverse=True)
a=0
b=0
c=0
d=0
for x in lst:
    if d==x and c==0:
        a=x
        c+=1
        d=0
    elif d==x and c==1:
        b=x
        c+=1
        d=0
    else:
        d=x
    if c==2:
        break
print(a*b)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

ans = 1
cnt = 0
for length, num in counter:
    if cnt >= 2:
        break
    if num >= 4 and cnt == 0:
        print(length**2)
        exit()
    if num >= 2:
        ans *= length
        cnt += 1

if cnt == 2:
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
ans=1
mem=a[0]
flag=1
cnt=0
for i in range(1,n):
    if a[i]==mem and flag==1:
        ans*=mem
        flag=0
        cnt+=1
    else:
        mem=a[i]
        flag=1
    if cnt==2:
        print(ans)
        exit()
print(0)

Submission status: Accepted

Solution code:
from collections import Counter
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
B = Counter(A)
C = [x[0] for x in B.items() if x[1] > 1]
C += [x[0] for x in B.items() if x[1] > 3]
C.sort(reverse = True)
if len(C) > 1:
    print(C[0] * C[1])
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
d = {}
x = [0, 0]
k = 0
for ai in a:
    if ai in d:
        d[ai] += 1
    else:
        d[ai] = 1
    if d[ai] == 2 or d[ai] == 4:
        x[k] = ai
        k += 1
    if k == 2:
        break
print(x[0] * x[1])

Submission status: Accepted

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

a.sort(reverse=True)
for i in range(len(a)-1):
    if a[i] == a[i+1]:
        a1 = a[i]
        break
    elif i == len(a)-2:
        print(0)
        exit()
    else:
        continue
b = []
l=0
for i in range(len(a)):
    if a[i] == a1 and l<2:
        l += 1
    else:
        b.append(a[i])
b.sort(reverse=True)
for i in range(len(b)-1):
    if b[i] == b[i+1]:
        a2 = b[i]
        break
    elif i == len(b)-2:
        print(0)
        exit()
    else:
        continue
print(a1*a2)

Submission status: Accepted

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

A.sort(reverse=True)

j=0
prev=A[0]

longer_edge=0

for i,a in enumerate(A+[0,0,0,0,-1]):
  if a==prev:
    pass
  else:
    if not longer_edge:
      if (i-j)>=4:
        print(prev**2)
        exit()
      elif (i-j)>=2:
        longer_edge=prev
    elif longer_edge:
      if (i-j)>=2:
        print(prev*longer_edge)
        exit()
    prev=a
    j=i

Submission status: Accepted

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

temp_set=set()

l = []

for a in A:
  if a in temp_set:
    l.append(a)
    temp_set.remove(a)
  else:
    temp_set.add(a)
    
l.sort()
if len(l)>=2:
  print(l[-2]*l[-1])
else:
  print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

def array_count(arr):
    arr_target = [[]]
    cnt = 1
    for i in range(1,len(arr)):
        if arr[i] == arr[i-1]:
            cnt += 1
        else:
            arr_target.append([arr[i-1],cnt])
            cnt = 1
    arr_target.append([arr[len(arr)-1],cnt])
    del arr_target[0]
    return arr_target


a.sort()
a = array_count(a)

b= []

for i in range(len(a)):
    if a[i][1] >= 2:
        b.append(a[i][0])
    if a[i][1] >= 4:
        b.append(a[i][0])

b.sort()
b.reverse()

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
alist = list(map(int,input().split()))
cc = Counter(alist)
blist = []
clist = []
for c in cc.items():
    if c[1] >= 2:
        blist.append(c[0])
    if c[1] >= 4:
        clist.append(c[0])
blist.sort()
clist.sort()
if len(blist) < 2:
    print(0)
elif len(clist) > 0:
    print(max(blist[-1]*blist[-2],clist[-1]* clist[-1]))
else:
    print(blist[-1]*blist[-2])

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
c = 0
d = 0
for i in range(N):
    if a[i] == d:
        if c == 0:
            c = a[i]
            d = 0
        else:
            print(c * a[i])
            exit()
    else:
        d = a[i]
print(0)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

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

    d = defaultdict(lambda: 0)
    B = []
    for a in A:
        d[a] += 1

        if d[a] % 2 == 0:
            B.append(a)


    B = sorted(B, key=lambda x: -x)
    if len(B) < 2:
        return 0
    else:
        return B[0] * B[1]


if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
judge = 0
side = []
while judge != 2 and len(A) > 1:
	MAX_A = A[len(A) -1]
	if MAX_A == A[len(A) - 2]:
		side.append(MAX_A)
		judge += 1
		del A[len(A) - 2]
		del A[len(A) - 1]
	else:
		del A[len(A) -1]

if judge == 2:
	print(side[0] * side[1])
else:
	print(0)

Submission status: Accepted

Solution code:
import collections
n = int(input())
a = [int(i) for i in input().split()]
l = collections.Counter(a)
l_ = [k for k, v in l.items() if v > 1]
if len(l_) > 1:
    l_.sort()
    if l[l_[-1]] > 3:
        print(l_[-1]**2)
    else:
        print(l_[-1]*l_[-2])
else:
    print(0)

Submission status: Accepted

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

from collections import Counter

# 2本以上ある棒のみ集計
C = Counter(A).most_common()
D = []
for (k,v) in C:
    if v>=2:
        D.append((k,v))

D.sort()

# 一番長い棒が4本あれば正方形(も長方形のうち)
if len(D)>=1 and D[-1][1]>=4:
    print(D[-1][0]**2)
elif len(D)>=2:
    print(D[-1][0]*D[-2][0])
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
d = defaultdict(int)
ls = []
for x in A:
    d[x] += 1
    if d[x] == 2:
        ls.append(x)
        if len(ls) == 2:
            break
    elif d[x] == 4:
        ls.append(x)
        break
if len(ls) == 2:
    print(ls[0]*ls[1])
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter
n=int(input())
data=[int(aa) for aa in input().split()]

dct=Counter(data)
dct=dct.items()

dct2=[item for item in dct if item[1] > 1]
dct2.sort(reverse=True)

dct4=[item for item in dct if item[1] > 3]
dct4.sort(reverse=True)

ans=0
if len(dct2) > 1:
  ans=dct2[0][0]*dct2[1][0]
if len(dct4) > 0: 
  ans=max(ans,dct4[0][0]*dct4[0][0])

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
from operator import itemgetter

input()
An = Counter(map(int, input().split()))


def main():
    l = [[k, v] for k, v in An.items() if 2 <= v]
    l.sort(key=itemgetter(0), reverse=True)

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

    return


main()

Submission status: Accepted

Solution code:
N=int(input())
from collections import defaultdict
d=defaultdict(int)
for a in map(int,input().split()):
    d[a]+=1
data=[]
for i in d.keys():
    data.append((i,d[i]))
data.sort(key=lambda x:x[0],reverse=True)
res=[]
for x,y in data:
    if len(res)>=2:break
    if y>=4:
        res.append(x)
        res.append(x)
    elif y>=2:
        res.append(x)
res.append(0)
res.append(0)
print(res[0]*res[1])

Submission status: Accepted

Solution code:

n=int(input())

A=list(map(int,input().split()))
        
A.sort(reverse=True)

X=[]

t=-1

for i in A:
    if t==i:
        t=-1
        X.append(i)
        if len(X)>1:
            break
    else:
        t=i
        
if len(X)>1:
    print(X[0]*X[1])
else:
    print(0)

Submission status: Accepted

Solution code:
import collections

n=int(input())

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

ans=1
cnt_1=0
cnt_2=0

for k,v in sorted(X.items(),key=lambda x:x[0],reverse=True):
    if v>=2:
        cnt_1+=1
        ans*=k
        if cnt_1==2:
            break
        if v>=4:
            ans*=k
            break
    else:
        cnt_2+=1
        if cnt_2==n or cnt_2==n-2 or cnt_2==n-3:
            ans=0
            break
print(ans)

Submission status: Accepted

Solution code:
def make_a_rectangle(N: int, A: list)->int:
    d = {}
    for a in A:
        d.setdefault(a, 0)
        d[a] += 1

    max1, max2 = 0, 0
    for v, p in sorted([(k, v) for k, v in d.items() if v > 1], key=lambda x: -x[0]):
        if max1 == 0:
            max1 = v
            if p >= 4:
                max2 = v
                break
        else:
            max2 = v
            break

    return max1 * max2


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = make_a_rectangle(N, A)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
M = 0
m = 0
last = A[0]
flag1 = True
count = 1
for i in range(1,N):
    if last == A[i]:
        count += 1
    else:
        if count >= 2 and flag1:
            M = last
            flag1 = False
            if count >= 4:
                m = last
                break
            count = 1
            last = A[i]
            continue
        if count >= 2 and not flag1:
            m = last
            break
        count = 1
        last = A[i]
if count >= 2 and not flag1:
    m = last
print(M*m)

Submission status: Accepted

Solution code:
import collections
n = int(input())
A = list(map(int, input().split()))
# 2本以上ある棒, 4本以上を選び出してsort, 大きいものから選ぶ
A = sorted(A)
c = collections.Counter(A)
c_2 = sorted(c.items(), key=lambda x:x[0], reverse=True)
count = 0
for i in range(n):
    if c_2[i][1] >=4 and count==0:
        ans = c_2[i][0] **2
        count+=2
        break
    elif c_2[i][1]>=2:
        if count==0:
            ans = c_2[i][0]
            count+=1
        elif count==1:
            ans *= c_2[i][0]
            count+=1
            break
if count!=2:
    print(0)
else:
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]
L = sorted(A)[::-1]
mul = []
flag = 0
tmp = 0

for i in range(1, N):
    if flag == 1 and i == tmp + 1:
        continue
    if L[i] == L[i-1] and flag == 0:
        mul.append(L[i])
        tmp = i
        flag += 1
    elif L[i] == L[i-1] and flag == 1:
        mul.append(L[i])
        flag += 1
        break

print(mul[0]*mul[1] if flag == 2 else 0)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = Counter(list(map(int, input().split())))
A = sorted([(k, v) for k, v in A.items() if v >= 2], key=lambda x: x[0], reverse=True)
if len(A) == 0:
    print(0)
    exit()
if len(A) == 1:
    if A[0][1] >= 4:
        print(A[0][0] ** 2)
    else:
        print(0)
    exit()
if A[0][1] >= 4:
    print(A[0][0] ** 2)
else:
    print(A[0][0] * A[1][0])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/23
Solved on 2019/3/23
@author: shinjisu
"""


# ABC 071 C Make Rectangle
from collections import Counter

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)

def getIntLines(n): return [int(input()) for i in range(n)]


def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替


class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N = getInt()
    d.dmp((N), 'N')
    A = getIntList()
    d.dmp((A), 'A')
    dic = Counter(A)
    d.dmp((dic), 'dic')
    side = []
    for k in dic.keys():
        if dic[k] >= 4:
            side.append(k)
            side.append(k)
        elif dic[k] >= 2:
            side.append(k)
    side.sort()
    d.dmp((side), 'side')
    if len(side) >= 2:
        return side[-1]*side[-2]
    else:
        return 0


ans = prob()
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/23
Solved on 2019/3/
@author: shinjisu
"""


# ABC 0xx C xxx
#import math
#import numpy as np

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)

def getIntLines(n): return [int(input()) for i in range(n)]


def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替


class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N = getInt()
    d.dmp((N), 'N')
    A = getIntList()
    d.dmp((A), 'A')
    dic = {}
    for e in A:
        if e in dic:
            dic[e] += 1
        else:
            dic[e] = 1
    d.dmp((dic), 'dic')
    side = []
    for k in dic.keys():
        if dic[k] >= 4:
            side.append(k)
            side.append(k)
        elif dic[k] >= 2:
            side.append(k)
    side.sort()
    d.dmp((side), 'side')
    if len(side) >= 2:
        return side[-1]*side[-2]
    else:
        return 0


ans = prob()
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
A = [int(i) for i in input().split()]
A = Counter(A)
rec = []
squ = []
for i in A.items():
    if i[1] >= 2:
        rec.append(i[0])
    if i[1] >= 4:
        squ.append(i[0])
rec.sort(reverse=True)
squ.sort(reverse=True)
if len(rec) >= 2 and len(squ) >= 1: 
    print(max(rec[0]*rec[1],squ[0]**2))
elif len(rec) >= 2:
    print(rec[0]*rec[1])
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
c = Counter(A).most_common()
l = 0
s = 0
for e in c:
    if e[1] >= 4 and e[0] > l:
        l = e[0]
        s = e[0]
    elif e[1] >= 2 and e[0] > l:
        s = l
        l = e[0]
    elif e[1] >= 2 and e[0] > s:
        s = e[0]
print(l * s)

Submission status: Accepted

Solution code:
input()
array = sorted(list(map(int,input().split(" "))),reverse=True)
set_array = set(array)
set_array_array = sorted(list(set_array),reverse=True)
dic = {}
for a in set_array:
    dic[a] = 0
for a in array:
    dic[a] += 1
temp = []
for a in set_array_array:
    if dic[a] >= 2:
        temp.append(a)
        if dic[a] >= 4:
            temp.append(a)
if len(temp) >= 2:
    print(temp[0] * temp[1])
else:
    print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()], reverse=True)

x = []
for i in range(n-1):
    if a[i] == a[i+1]:
        a[i+1] = -1
        x.append(a[i])
        if len(x) == 2:
            break

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

Submission status: Accepted

Solution code:
from collections import Counter

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

nums = [0, 0]

for key, value in A.items():
    if value < 2:
        continue
    if nums[0] < key:
        nums[0] = key
        value -= 2

    if value >= 2 and nums[1] < key:
        nums[1] = key

    nums.sort()
print(nums[0]*nums[1])

Submission status: Accepted

Solution code:
n = int(input())
l = sorted((int(x) for x in input().split()), reverse = True)
a = []
t = None
for x in l:
  if t == x:
    t = None
    a.append(x)
    if len(a) > 1:
      break
  else:
    t = x
print(a[0]*a[1] if len(a) > 1 else 0)

Submission status: Accepted

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

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

V = [0, 0]
for a in M:
  if M[a]>=4:
    V += [a, a]
  elif M[a]>=2:
    V += [a]
V.sort()
print V[-1]*V[-2]

Submission status: Accepted

Solution code:
from collections import Counter

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

a = Counter(A)

x, y = 0, 0
for k, v in a.items():
  if(v >= 2 and k > y):
    if(k >= x):
      if(v >= 4):
        y = k
      else:
        y = x
      x = k
    else:
      y = k
print(x*y)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    prev = 0
    sides = []
    for a in A:
        if a == prev:
            sides.append(a)
            prev = 0
        else:
            prev = a
        if len(sides) >= 2:
            break
    if len(sides) >= 2:
        print(sides[0] * sides[1])
    else:
        print(0)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
num = 1
now = a[0]
ans = [0,0]
for i in a[1:]:
  if i == now:
    num += 1
  else:
    if num >= 4:
      ans.append(now)
      ans.append(now)
    elif num >= 2:
      ans.append(now)
    now = i
    num = 1
if num >= 4:
  ans.append(now)
  ans.append(now)
elif num >= 2:
  ans.append(now)
print(ans[-1]*ans[-2])

Submission status: Accepted

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

for i in a:
    if i in s:
        cands.append(i)
        s.remove(i)
    else:
        s.add(i)

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

Submission status: Accepted

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

#A

#B

#C
n = I()
d = defaultdict(int)
a = LI()
for i in a:
    d[i] += 1
d = list(d.items())
d.sort(key = lambda x:-x[0])
l = 0
k = 0
for i,j in d:
    if j >= 2:
        if l == 0:
            l = i
        else:
            k = i
        if j >= 4:
            k = i
    if k != 0:break
print(l*k)
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

Solution code:
def tami(a):
  global cnt
  if a in cnt:
    if cnt[a]==3:
      four.append(a)
    elif cnt[a]==1:
      two.append(a)
    cnt[a] += 1
  else:
    cnt[a] = 1
  
  
N = int(input())
l = list(map(int,input().split()))

cnt = {}
two = []
four = []

for i in l:
  tami(i)

two.sort(reverse=True)
four.sort(reverse=True)

if len(two)<2:
  print(0)
elif len(four)<1:
  print(two[0]*two[1])
else:
  print(max(two[0]*two[1],four[0]**2))

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [int(s) for s in input().split()]
    print(solve(a))

def solve(a):
    cands = []
    s = set()
    for i in a:
        if i in s:
            cands.append(i)
            s.remove(i)
        else:
            s.add(i)
    
    x = sorted(cands, reverse=True)
    if len(x) < 2:
        return 0
    
    return x[0] * x[1]

main()

Submission status: Accepted

Solution code:
#ABC071C
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
before=0
c=0
x=-1
for a in A:
	if before==a:
		c+=1
		if c==2:
			if x==-1:
				x=a
			else:
				print(x*a)
				break
		if c==4:
			print(a**2)
			break
	else:
		before=a
		c=1
else:
	print(0)

Submission status: Accepted

Solution code:
import collections

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

# collections.Counter(a): (aの要素, 出現回数) と組になった Counter オブジェクトを返す
# most_common(): Counter オブジェクトをタプルにして返す
c = collections.Counter(A)
c = c.most_common()
c = sorted( c, reverse=True )  # 要素の大きい順に並び替える

ans = 0
for i,j in c:
    if j >= 4 and ans == 0:
        ans = i*i
        break
    elif j >= 2 and ans == 0:
        ans = i
    elif j >= 2:
        ans *= i
        break

print( ans )

Submission status: Accepted

Solution code:
from collections import Counter

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

a=Counter(a).most_common()
a=sorted(a,reverse=True)

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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
A = Counter([int(i) for i in input().split()])
mt4 = []
mt2 = []
for k, v in A.items():
    if v >= 4:
        mt4.append(k)
        mt2.append(k)
    elif v >= 2:
        mt2.append(k)

ans = 0
if len(mt4) != 0:
    ans = max(mt4) ** 2
if len(mt2) >= 2:
    mt2.sort(reverse = True)
    ans = max(ans, mt2[0] * mt2[1])

print(ans)

Submission status: Accepted

Solution code:
#! /usr/bin/python 
# -*- coding: utf-8 -*- 
#===============================================================================
# Date created  : 2019-03-02T16:27:42+09:00
# Date modified : 2019-03-02T16:32:15+09:00
# Author        : awk
# Description   : unanswered
#===============================================================================

N = int(input())
L = list(map(int,input().split()))
def counter(array):
    from collections import Counter
    return list(Counter(array).most_common())
c=counter(L)
c = list(filter(lambda x:x[1]>1,c))
c = sorted(c,key=lambda x:x[0])[::-1]
if len(c) == 0:
    print(0)
    quit()
ans = 0
try:
    ans = c[0][0] * c[1][0]
except:
    pass
if c[0][1] >= 4:
    try:
        ans = c[0][0] ** 2
    except:
        pass
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

int_n = int(input())
ar_int_a = list(map(int, input().split()))

c = collections.defaultdict(int)
result = []

for a in ar_int_a:
    c[a] += 1

for k in sorted(c.keys(), key=lambda x: x, reverse=True):
    if len(result) == 0 and c[k] >= 4:
        print(k ** 2)
        exit(0)
    elif len(result) < 2 and c[k] >= 2:
        result.append(k)

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

Submission status: Accepted

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

Submission status: Accepted

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

count = {}
for i in set(a):
    count[i] = 0
for i in a:
    count[i] += 1
    
keys = [k for k,v in count.items() if v >= 2]
keys_2 = [k for k,v in count.items() if v >= 4]

ans_1 = -10 ** 18
ans_2 = -10 ** 18
ans_3 = -10 ** 18
if len(keys) >= 2:
    ans_1 = sorted(keys)[-1]* sorted(keys)[-2]
if len(keys_2) >= 1:
    ans_2 = sorted(keys_2)[-1]**2
else:
    ans_3 = 0
print(max(ans_1,ans_2,ans_3))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
    d[i] = d.get(i, 0) + 1
s = [i for i in d if d[i] >= 2] + [0, 0]
s.sort(reverse=True)
if d.get(s[0], 0) >= 4:
    print(s[0]**2)
else:
    print(s[0]*s[1])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
aset = set(a)
d = {i:0 for i in aset}
for i in range(n):
    d[a[i]] += 1

res = 0
for k, i in sorted(d.items(), reverse = True):
    if i >= 4 and res == 0:
        print(k*k)
        exit()
    elif i >= 2 and res == 0:
        res = k
    elif i >= 2:
        print(res * k)
        exit()
print(res)

Submission status: Accepted

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

flag = True
for i in range(n-1):
  if flag :
    if a[i]==a[i+1]:
      hen1 =a[i]
      a[i+1]=-1
      flag =False
  elif not flag:
    if a[i]==a[i+1]:
      hen2 = a[i]
      print(hen1*hen2)
      exit()
print(0)

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]


from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

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

c = dict(Counter(A))
c = sorted(c.items(), key=lambda x: x[0])

max_one = None
max_two = None
max_sub = None
for k, v in c[::-1]:
    if v >= 4:
        if max_sub is None:
            max_sub = k
    if v >= 2:
        if max_one is None:
            max_one = k
        else:
            max_two = k
            break

if max_two is None:
    print(0)
elif max_sub is not None:
    sub_S = max_sub**2
    S = max_one * max_two
    if sub_S > S:
        print(sub_S)
    else:
        print(S)
else:
    print(max_one*max_two)