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:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
data=Counter(a)
two_i=[]
four_i=[]
for i,j in data.items():
    if 4<=j:
        four_i.append(i)
    elif 2<=j:
        two_i.append(i)
two_i.sort()
four_i.sort()
two_i.reverse()
four_i.reverse()
if len(four_i)==0:
    four_i.append(0)
if len(two_i)<=1:
    two_i.append(0)
    two_i.append(0)
four_area=four_i[0]*four_i[0]
two_area=two_i[0]*two_i[1]
mix_area=two_i[0]*four_i[0]
print(max(four_area,two_area,mix_area))

Submission status: Accepted

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

A.sort(reverse = True)
U = []
for i in range(N-1):
  if A[i] == A[i+1]:
    U.append(A[i])
    A[i] = -1
    A[i+1] = -1
  if len(U) >= 2:
    break
if len(U) >= 2:
	print(U[0] * U[1])
else:
  print(0)

Submission status: Accepted

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

for i in range(n):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1

a, b = 0, 0

for k,v in sorted(dic.items(), key=lambda x : -x[0]):
    if a==0:
        if 4 <= v:
            a, b = k, k
            break
        elif 2 <= v:
            a = k
    elif 2 <= v:
        b = k
        break

if not a==0 or not b==0:
    print(a*b)
else:
    print(0)

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    A = list(map(int, input().split(" ")))
    A = sorted(A, reverse=True)
    width, height = 0, 0
    cnt = 0
    last_val = -1
    for i, A_i in enumerate(A):
        if last_val == A_i:
            if width == 0:
                width = max(A_i, width)
                last_val = 0
            elif height == 0:
                height = max(A_i, height)
        else:
            cnt = 0
            last_val = A_i
        if width * height > 0:
            print(width * height)
            return
        
    print(0)
    return


solve()

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
cnt = Counter()
for x in map(int, input().split()):
    cnt[x] += 1

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

def find_pair():
    while xs:
        x = xs.pop()
        if x[1] >= 2:
            xs.append((x[0], x[1] - 2))
            return x[0]
        else:
            continue
    return 0

a = find_pair()
b = find_pair()
print(a*b)

Submission status: Accepted

Solution code:
N = int(input())
P = list(map(int,input().split()))
P.sort(reverse=True)
a = 0
b = 0
for i in range(N-1):
    if P[i] > 0:
        if a == 0:
            if P[i] == P[i+1]:
                a = P[i]
                P[i] = -i
                P[i+1] = -i -1
        elif b == 0:
            if P[i] == P[i+1]:
                b = P[i]
                P[i] = -i
                P[i+1] = -i -1
        else:
            break
    else:
        continue
ans = a * b
print(ans)

Submission status: Accepted

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

d = {}
for e in A:
    if e not in d:
        d[e] = 1
    else:
        d[e] = d[e] + 1

edges = []
for k, v in d.items():
    if v >= 4:
        edges.append(k)
        edges.append(k)
    elif v >= 2:
        edges.append(k)

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

Submission status: Accepted

Solution code:

input()
xs = map(int, input().split())

d = dict()
for x in xs:
    if x in d.keys():
        d[x] += 1
    else:
        d[x] = 1

res = 0
for x, c1 in d.items():
    if c1 >= 4:
        if res < x * x: res = x * x

v = sorted(list(map(lambda s: s[0], (filter(lambda x: x[1] >= 2, d.items())))), reverse=True)

if len(v) >= 2:
    if res < v[0] * v[1]: res = v[0] * v[1]

"""
    for y, c2 in d.items():
        if x != y and c1 >= 2 and c2 >= 2:
            if res < x * y: res = x * y
"""


print(res)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split(" ")))
over2 = []
num = {}

for length in A:
	if length in num:
		num.pop(length)
		over2.append(length)
	else:
		num[length] = 1


over2.sort()

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

Submission status: Accepted

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

li.sort(reverse=True)

vert = {}
even = []
ans = 0

for i in li:
	if i in vert:
		vert.pop(i)
		even.append(i)
		if len(even) == 2:
			ans = even[0] * even[1]
			break
	else:
		vert[i] = 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
lis = list(map(int,input().split()))
lis.sort()
a = lis[0];fir=0;sec=0;torf=False
for i in range(N-1):
    if torf:
        torf = False
    elif a == lis[i+1]:
        if a > fir:
            sec = fir
            fir = a
            torf = True
        elif a > sec:
            sec = a
            torf = True
    a = lis[i+1]

print(fir*sec)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
import sys

n = int(input())
a = list(map(int,input().split()))
cnt = Counter(a)
cntsort = sorted(cnt.items())[::-1]
h = 0
flg2 = False
for k, v in cntsort:
    if(v>=4 and flg2==False):
        print(k*k)
        sys.exit()
    elif(v>=2 and flg2==False):
        flg2 = True
        h = k
    elif(v>=2 and flg2==True):
        print(h*k)
        sys.exit()
else:
    print(0)

Submission status: Accepted

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

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

A.sort()

rectangle_edges = []
prev_edge = A[N - 1]
for i in reversed(range(N - 1)):
    if A[i] == prev_edge:
        rectangle_edges.append(A[i])
        if len(rectangle_edges) == 2:
            break
        prev_edge = -1
    else:
        prev_edge = A[i]

if len(rectangle_edges) != 2:
    print(0)
else:
    print(int(rectangle_edges[0] * rectangle_edges[1]))

Submission status: Accepted

Solution code:
n=input()
a = list(map(int, input().split()))
a.sort()
h, w =0, 0
while True:
    try:
        if a[-1] == a[-2]:
            h = a[-1]
            a.pop()
            a.pop()
            break
        else:
            a.pop()
    except:
        break

while True:
    try:
        if a[-1] == a[-2]:
            w = a[-1]
            a.pop()
            a.pop()
            break
        else:
            a.pop()
    except:
        break
print(h*w)

Submission status: Accepted

Solution code:
n = int(input())
sticks = list(map(int, input().split()))
sticks.append(0)
sticks.sort()
sticks.reverse()
ans = []

def find(sticks):

  for i in range(n):
    if sticks[i] == sticks[i+1] == sticks[i+2] and not sticks[i+3] == sticks[i]:
      continue
    elif sticks[i] == sticks[i+1]:
      ans.append(sticks[i])
  
  if len(ans) <= 2:
    ans.append(0)
    ans.append(0)
  return ans[0] * ans[1]
print(find(sticks))

Submission status: Accepted

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

target1 = False
target2 = False

i = 0

while i < N-1:
    if numList[i] == numList[i+1]:
        if target1 == False:
            num1 = numList[i]
            target1 = True
            i += 1
        elif target1 == True:
            num2 = numList[i]
            target2 = True
    if target1 == True and target2 == True:
        break
    i += 1

if target2 == False:
    print("0")
else:
    print(num1 * num2)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
edge = set()
h = 0
w = 0

for i in range(N):
    if A[i] in edge:
        if A[i] > h:
            h,w = A[i],h
        elif A[i] > w:
            w = A[i]
        edge.remove(A[i])
    else:
        edge.add(A[i])

print(h*w)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
l = []

for i in range(0, N - 1):
    if len(l) == 2:
        break
    if A[i] == A[i + 1] and not A[i] == 0:
        l.append(A[i])
        A[i + 1] = 0
        
if len(l) == 2:
    print(l[0] * l[1])
else:
    print('0')

Submission status: Accepted

Solution code:
input()
d = {}
for a in input().strip().split():
    x = int(a)
    if x in d:
        d[x] += 1
    else:
        d[x] = 1

w = 0
for k in sorted(d.keys(), reverse=True):
    if d[k] >= 2:
        if not w:
            if d[k] >= 4:
                print(k * k)
                raise SystemExit
            else:
                w = k
        else:
            print(k * w)
            raise SystemExit
print(0)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
num_l = sorted(map(int, input().split()),reverse=True)
s = sorted(set(num_l), reverse=True)
d = Counter(num_l) # {i:num_l.count(i) for i in s}
res = []
it = 0
lim=len(s)
# c = max()
for i in range(n):
    if d[s[it]] >= 2:
        d[s[it]]-=2
        res.append(s[it])
    else:
        it+=1#pass
        
    if len(res) == 2:
        print(res[0] * res[1])
        break
    if lim==it:
        print(0)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input().rstrip())
counter = Counter(map(int, input().rstrip().split(' ')))

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

print(x * y)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    N = int(input())
    A_list = list(map(int, input().split()))
    c = Counter(A_list)

    x = []
    for length, n in sorted(c.items(), key=lambda x: x[0], reverse=True):
        if n >= 4:
            x += [length] * 4
        elif n >= 2:
            x += [length] * 2
    x += [0] * 4
    print(x[0] * x[2])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
 
N = int(input())
A = list(map(int, input().split()))
h = w = 0
 
for i, cnt in Counter(A).items():
    if cnt >= 2 and i > w:
        if i > h:
            if cnt >= 4:
                h = i
                w = i
            else:
                w = h
                h = i
        else:
            w = i
            
print(w * h)

Submission status: Accepted

Solution code:
n = int(input())
list1 = list(map(int,input().split()))
list2 = set()
list1.sort()
list1.reverse()
a,b = 0,0
for i in list1:
	if i in list2:
		if i > a:
			a = i
			list2.remove(i)
		else:
			b = i
			break
	else:
		list2.add(i)
print('{0}'.format(a*b))

Submission status: Accepted

Solution code:
n = int(input())
lst1 = list(map(int, input().split()))
lst1.sort()
lst2 = set()
a, b = 0, 0

for i in lst1:
    if i>b:
        if i in lst2:
            lst2.remove(i)
            if i>a:
                b = a
                a = i
            else:
                b = i
        else:
            lst2.add(i)
print(a*b)

Submission status: Accepted

Solution code:
from collections import Counter
 
 
def solve(nums):
    counts = sorted([pair for pair in Counter(nums).items() if pair[1] >= 2], reverse=True)
 
    if len(counts) == 0:
        return 0
    elif len(counts) == 1:
        (val, cnt) = counts[0]
        return 0 if cnt < 4 else val * val
    else:
        (val1, cnt1) = counts[0]
        (val2, cnt2) = counts[1]
        return val1 * val2 if cnt1 < 4 else val1 * val1
 
 
if __name__ == '__main__':
    n = input()
    a = [int(i) for i in input().split()]
    print(solve(a))

Submission status: Accepted

Solution code:
input()
param_list = sorted([int(v) for v in input().split(" ")], reverse=True)
result = 0
duplicate_param = 0
count = 1
 
for v in param_list:
  if v == duplicate_param:
    if count == 1:
      result = v
      duplicate_param = 0
    else:
      result *= v
      print(result)
      break
    count += 1
  else:
    duplicate_param = v
 
if result == 0:
  print("0")

Submission status: Accepted

Solution code:
from collections import Counter


def solve(nums):
    counts = [pair for pair in Counter(nums).items() if pair[1] >= 2]
    counts.sort()
    counts.reverse()

    if len(counts) == 0:
        return 0
    elif len(counts) == 1:
        (val, cnt) = counts[0]
        return 0 if cnt < 4 else val * val
    else:
        (val1, cnt1) = counts[0]
        (val2, cnt2) = counts[1]
        return val1 * val2 if cnt1 < 4 else val1 * val1


if __name__ == '__main__':
    n = input()
    a = [int(i) for i in input().split()]
    print(solve(a))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
"""
#
from collections import Counter
from operator import itemgetter

def main():
    n = int(input())
    rods = [int(x) for x in input().split(' ')]

    candidates = []
    for r in Counter(rods).most_common():
        if r[1] >= 4:
            candidates.append(r[0])
            candidates.append(r[0])
        elif r[1] >= 2:
            candidates.append(r[0])
        else:
            break

    if len(candidates) >= 2:
        candidates.sort(reverse=True)
        print(candidates[0] * candidates[1])
    else:
        print('0')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

A.sort()

for i in range(N - 1):
    if A[i] == A[i + 1]:
        A[i + 1] = 0
    else:
        A[i] = 0

A[N - 1] = 0

A.sort()
A.reverse()
print(A[0] * A[1])

Submission status: Accepted

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

A.sort()
A.reverse()

for i in range(N - 1):
    if A[i] == A[i + 1]:
        A[i + 1] = 0
    else:
        A[i] = 0

A.sort()
A.reverse()
print(A[0] * A[1])

Submission status: Accepted

Solution code:
import collections
dump = input()
inp = list(map(int,input().split()))
A = collections.Counter(inp)
t_A = [el[0] for el in A.items() if el[1] > 1]
t_A.extend([el[0] for el in A.items() if el[1] > 3])
t_A = sorted(t_A)
if len(t_A) >= 2:
  print(t_A[-2]*t_A[-1])
else:
  print(0)

Submission status: Accepted

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

i = 0

edge = []

while i < len(A)-1:
    if A[i] == A[i+1]:
        edge.append(A[i])
        i += 2
    else:
        i += 1
        
if len(edge) < 2:
    print(0)
else:
    print(edge[0] * edge[1])

Submission status: Accepted

Solution code:
def solve(): # 071C - Make a Rectangle
    n = int(input())
    sides = list(map(int, input().split(" ")))
    check_dual = {}
    possible_sides = []

    for i in sides:
        if i in check_dual:
            check_dual[i] += 1
        else:
            check_dual[i] = 1

    for k, v in check_dual.items():
        if v >=4:
            possible_sides.append(k)
            possible_sides.append(k)
        elif v == 2 or v == 3:
            possible_sides.append(k)

    possible_sides.sort(reverse=True)
    if len(possible_sides) < 2:
        print(0)
    else:
        print(possible_sides[0] * possible_sides[1])


solve()

Submission status: Accepted

Solution code:
def solve(): # 071C - Make a Rectangle
    n = int(input())
    sides = list(map(int, input().split(" ")))
    check_dual = {}
    possible_sides = []

    for i in sides:
        if i in check_dual:
            check_dual[i] += 1
        else:
            check_dual[i] = 1

    tmp_square = 0
    for k, v in check_dual.items():
        if v >= 4 and k > tmp_square:
            tmp_square = k
            possible_sides.append(k)
        elif v == 2 or v == 3:
            possible_sides.append(k)
        else:
            pass

    possible_sides.sort(reverse=True)
    if tmp_square == 0 and len(possible_sides) < 2:
        print(0)
    elif tmp_square != 0 and len(possible_sides) == 0:
        print(tmp_square ** 2)
    elif tmp_square != 0 and len(possible_sides) == 1:
        print(max(tmp_square ** 2, tmp_square * possible_sides[0]))
    else:
        print(max(tmp_square ** 2, possible_sides[0] * possible_sides[1]))

solve()

Submission status: Accepted

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

def max_pair(Asc):
    m1 = 0
    while Asc:
        m2 = Asc.pop()
        if m1 == m2:
            return m1
        m1 = m2

    return 0

A.sort()
print(max_pair(A) * max_pair(A))

Submission status: Accepted

Solution code:
import sys
N = raw_input()
items = raw_input().split()
res = dict()
for i in items[:int(N)]:
    i = int(i)
    if res.get(i) is None:
        res[i] = 1
    else:
        res[i] = res[i] + 1
long2 = [0,0]
for i, num in res.iteritems():
    if num < 2:
        continue
    if i > long2[0]:
        if num >= 4:
            long2 = [i, i]
        else:
            long2 = [i, long2[0]]
    elif i > long2[1]:
        long2[1] = i
print long2[0] * long2[1]

Submission status: Accepted

Solution code:
from collections import Counter
n = int(raw_input())
a = sorted(map(int, raw_input().split()))
D = Counter(a)
v = []
for num, cnt in D.items():
    for i in range(cnt/2):
        v.append(num)
v = sorted(v)[::-1]
print 0 if len(v) < 2 else v[0]*v[1]

Submission status: Accepted

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

a.sort(reverse=True)

num = None
hen = []
en = 0

for i in a:
    if en == 2:break
    if num == i:
        hen.append(num)
        num = None
        en += 1
    else:
        num = i
        
if en == 2:
    print(hen[0]*hen[1])
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter

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

pairs = sorted([k for k, v in Counter(A).items() if v >= 2] + [k for k,v in Counter(A).items() if v >= 4], reverse = True)

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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
i=n-1
s1=0
s2=0
while i>0:
    if a[i]==a[i-1] and s1==0:
        s1=a[i]
        i-=2
        continue
    if a[i]==a[i-1]:
        s2=a[i]
        i-=1
        break
    i-=1

print(s1*s2)

Submission status: Accepted

Solution code:
N = int(input())
sticks = list(map(int, input().split()))
stocks = set([])
doubles = []
for s in sticks:
    if s not in stocks:
        stocks.add(s)
    else :
        doubles.append(s)
        stocks.remove(s)
if len(doubles) < 2:
    print("0")
else:
    l = max(doubles)
    doubles.remove(max(doubles))
    m = max(doubles)
    print(l*m)

Submission status: Accepted

Solution code:
from collections import Counter

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

for i, cnt in Counter(A).items():
    if cnt >= 2 and i > w:
        if i > h:
            if cnt >= 4:
                h = i
                w = i
            else:
                w = h
                h = i
        else:
            w = i
            
print(w * h)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
c = Counter(map(int, input().split()))
h = w = 0
for k, v in c.items():
    if v >= 2 and k > w:
        if k > h:
            if v >= 4:
                h = k
                w = k
            else:
                w = h
                h = k
        else:
            w = k
print(h * w)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
sticks = list(map(int , input().split()))
ans = []

sticks_counter = Counter(sticks).most_common()
sticks_counter.sort(reverse = True)

for s in sticks_counter:
    if s[1] >=2:
        ans.append(s[0])
        if len(ans) == 2:
            print(ans[0]*ans[1])
            break
    
    if s[1] >= 4:
        print(s[0]**2)
        break

else:
    print(0)

Submission status: Accepted

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

# print(n)
# print(a)

b = sorted(a, reverse=True)
# print(b)

flag = False

i = 0

tate = 0
yoko = 0
# for i in range(n-1):
while i < n - 1:
    # print(i)
    if b[i] == b[i+1]:
        # print('test1')
        if flag:
            yoko = b[i]
            # print('test2')
            break
        else:
            tate = b[i]
            flag = True
            i += 1
            # print('test3')
    i += 1

print(tate*yoko)

Submission status: Accepted

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

ans=[]
tmp=0
count=0
for el in a:
    if len(ans)==2: break
    if el != tmp: tmp=el; count=0
    else:
        if not count%2: ans.append(el);
        count+=1

try: ans=ans[0]*ans[1]
except: ans=0
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
bar = [int(x) for x in input().split()]
ls = set()
a,b = 0,0
for x in bar:
    if x>b:
        if x in ls:
            ls.remove(x)
            if x>a:
                b = a
                a = x
            else:
                b = x
        else:
            ls.add(x)
print(a*b)

Submission status: Accepted

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

ans=[]
tmp=0
count=0
for el in a:
    if len(ans)==2: break
    if el != tmp: tmp=el; count=0
    else:
        if count%2==0: ans.append(el); tmp=el;
        count+=1

try: ans=ans[0]*ans[1]
except: ans=0
print(ans)

Submission status: Accepted

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

x = 0
y = 0
S = set()

for a in A:
    if a in S:
        if a < x:
            continue
        elif a > y:
            x = y
            y = a
        else:
            x = a
        S.remove(a)
    else:
        S.add(a)

print(x*y)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int , input().split()))
ans = []
a.sort()
a.reverse()
f = 0
cnt = 1
when = 0
for i in a:
    if i == f:
        cnt += 1
        if cnt >= 2:
            ans.append(i)
            cnt = 0
            when += 1
    else:
        f = i
        cnt = 1
    if when == 2:
        break
if len(ans) != 0:
    print(ans[0] * ans[1])
else:
    print(0)

Submission status: Accepted

Solution code:
def main():
    _ = input()
    a_list = sorted([int(i) for i in input().split()], reverse=True)

    height, width = None, None
    i = 0
    while (i != len(a_list)):
        a = a_list[i]
        j = i+1
        cnt = 1
        for j in range(i+1, len(a_list)):
            if cnt == 4: break
            b = a_list[j]
            if a != b:
                break
            cnt += 1
        if 1 < cnt and cnt < 4 and height == None:
            height = a
        elif 1 < cnt and cnt < 4 and width == None:
            width = a
            print(height*width)
            break
        elif cnt == 4 and height == None:
            height = a
            print(height*height)
            break
        elif cnt == 4:
            width = a
            print(height*width)
            break
        i = j
    if not height:
        print(0)
    

if __name__ == "__main__":
    main()

Submission status: Accepted

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

h=[]
count=0
f=0
for i in a:
 if f==i:
  h.append(i)
  count+=1
  f=0
 else:
   f=i
   if count==2:
       break 
if count==2:
 print(h[0]*h[1])
else:
 print(0)

Submission status: Accepted

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

a.sort()
a.reverse()

hoge = []
count = 0
p = 0
for i in a:
    if p == i:
        hoge.append(i)
        count += 1
        p = 0
    else:
        p = i
    if count == 2:
        break
if count == 2:
    print(hoge[0] * hoge[1])
else:
    print(0)

Submission status: Accepted

Solution code:
N=input()
A=[int(x) for x in input().split()]
from collections import defaultdict
d=defaultdict(int)
for i in A:
    d[i]+=1
hen=[0,0]
for i in d.items():
    if i[1]>=2:
        hen.append(i[0])
    if i[1]>=4:
        hen.append(i[0])
hen=sorted(hen,reverse=True)
print(hen[0]*hen[1])

Submission status: Accepted

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


count=0
ans=[]
flag=0
for i in range(1,n):
    if a[i]==a[i-1] and flag==1:
        flag=0


    elif a[i]==a[i-1] and flag==0:
        count += 1
        ans.append(a[i])
        flag=1

    elif a[i] != a[i-1]:
        flag=0

    if count==2:
        print(ans[0]*ans[1])
        exit()


print(0)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(raw_input())
l = map(int, raw_input().split())
c = Counter(l)
ls = sorted(c.keys(), reverse=True)
h = 0
w = 0
for k in ls:
    if c[k] >= 4 and h == 0 and w == 0:
        h = k
        w = k
        break
    elif c[k] >= 2:
        if h == 0:
            h = k
        else:
            w = k
            break
print h*k

Submission status: Accepted

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())),
         reverse=True)
ans=[]
p=-1
cnt=0
flag =False
for index,i in enumerate(a):
    if p!=i:
        if cnt>=4:
            ans.append(p)
            ans.append(p)
        if cnt>=2:
            ans.append(p)
        p=i
        cnt=1
    else:
        cnt+=1
    if len(ans)>=2:
                print(ans[0]*ans[1])
                flag=True
                break
if not flag:
    if cnt>=4:
            ans.append(p)
            ans.append(p)     
    elif cnt>=2:
            ans.append(p)
    if len(ans)>=2:
        print(ans[0]*ans[1])
        flag=True
       
if not flag:
    print(0)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))[::-1]
l1, l2 = 0, 0
flag = True
for i in range(N-1):
    if A[i] > A[i+1]:
        flag = True
        pass
    elif l1 == 0:
        l1 = A[i]
        flag = False
    elif l2 == 0 and flag:
        l2 = A[i]
        break
    else:
        flag = True

print(l1 * l2)

Submission status: Accepted

Solution code:
n = int(input())
tmp = raw_input()

As = [int(a) for a in tmp.split()]

dic = {}
maxes = [0, 0]
for a in As:
    if a not in dic:
        dic[a] = 0
    dic[a] += 1
    if dic[a] % 2 == 0:
        if maxes[0] < a:
            maxes[0], maxes[1] = a, maxes[0]
        elif maxes[1] < a:
                maxes[1] = a

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

Submission status: Accepted

Solution code:
def C_Make_a_Rectangle(lst):
    N = lst[0]
    A = lst[1:]

    from collections import Counter, deque
    c = sorted(Counter(A).items(), reverse=True)  # リストの要素が何回現れたか
    # cの0番要素は値、1番要素は度数

    ans = deque([])
    for k, v in c:
        if v == 1:
            continue
        elif v == 2 or v == 3:
            ans.append(k)
            if len(ans) == 2:
                break
        else:
            ans.append(k)
            ans.append(k)
            break

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

n = int(input())
l = [int(i) for i in input().split()]
x = [n] + l
print(C_Make_a_Rectangle(x))

Submission status: Accepted

Solution code:
import sys
from collections import Counter

# sys.stdin = open('c1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    n = read_int()
    a = read_int_list()
    a.sort()
    c = Counter(a)
    l = set()
    for i in a:
        if c[i] >= 2:
            l.add(i)
    l = list(l)
    l.sort()

    res = 0
    if len(l) >= 1:
        m = l[-1]
        if c[m] >= 4:
            res = m * m
        else:
            if len(l) >= 2:
                p = l[-2]
                res = m * p
    print(res)


main()

Submission status: Accepted

Solution code:
def search(A):
  B = list(set(A))
  if len(A)-len(B) == 0: return 0 

  a1 = 0
  for n,(i, j) in enumerate(zip(A[0:-1], A[1:])):
    if i == j:
      a1 = i
      break
  del(A[:n+2])

  return a1

N = int(input())
A = map(int, input().split())
A = [a for a in A]
A.sort(reverse=True)
a1 = search(A)
a2 = search(A)
if a1 > 0 and a2 > 0: print(a1*a2)
else: print(0)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    a = [int(i) for i in input().split()]
    area = 0
    
    b = 0
    tmp = 0

    sort_a = sorted(a, reverse=True)
    for num in sort_a:
        if(num == tmp):
            if(b > 0):
                area = num * b
                break
            else:
                b = num
                tmp = 0
        else:
            tmp = num
    
    print(area)
    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np

def search(A):
  B = list(set(A))
  B.sort(reverse=True)
  if len(A)-len(B) == 0: return 0 

  a1 = 0
  An = np.array(A)
  for n,(i, j) in enumerate(zip(An[0:-1], An[1:])):
    if i == j:
      a1 = i
      break
  del(A[:n+2])

  return a1

N = int(input())
A = map(int, input().split())
A = [a for a in A]
A.sort(reverse=True)
a1 = search(A)
a2 = search(A)
if a1 > 0 and a2 > 0: print(a1*a2)
else: print(0)

Submission status: Accepted

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

A.sort(reverse=True)

ans = 0

b = 0
tmp = 0


for i in range(len(A)):
    if ans == 0:
        if A[i] == tmp:
            if b > 0:
                ans = A[i] * b
            else:
                b = A[i]
                tmp = 0

        else:
            tmp = A[i]


print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
c_dict = Counter(A)
B = []
C = []

for k, v in c_dict.items():
    if v >= 4:
        B.append(k)
    elif v >= 2:
        C.append(k)
B.sort(reverse=True)
C.sort(reverse=True)

if len(B) < 1 and len(C) < 2:
    print(0)
elif len(B) < 1 and len(C) >= 2:
    F = C[1] * C[0]
    print(F)
elif len(B) >= 1 and len(C) == 1:
    D = B[0] ** 2
    E = C[0] * B[0]
    print(max(D, E))
elif len(B) >= 1 and len(C) >= 2:
    D = B[0] ** 2
    E = C[0] * B[0]
    F = C[1] * C[0]
    print(max(D, E, F))

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:
num = int(input())
hen = sorted(list(map(int, input().split(" "))), reverse=True)
i = 0
a = []
while i < num-1:
    if hen[i] == hen[i+1]:
        a.append(hen[i])
        i += 2
    else:
        i += 1
if len(a) < 2:
    print(0)
else:
    print(a[0] * a[1])