Problem:


Score : 300 points

Problem Statement

We have N sticks with negligible thickness.
The length of the i-th stick is A_i.

Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides.
Find the maximum possible area of the rectangle.

Constraints

4 \leq N \leq 10^5

1 \leq A_i \leq 10^9

A_i is an integer.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible area of the rectangle.
If no rectangle can be formed, print 0.

Sample Input 1

6
3 1 2 4 2 1

Sample Output 1

2

1 \times 2 rectangle can be formed.

Sample Input 2

4
1 2 3 4

Sample Output 2

0

No rectangle can be formed.

Sample Input 3

10
3 3 3 3 4 4 4 5 5 5

Sample Output 3

20



Sample input:
6
3 1 2 4 2 1


Sample output:
2

Submission status: Runtime Error

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

Submission status: Runtime Error

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

x, y = 0, 0

i = 0
while i < n - 1:
    if a[i] == a[i + 1]:
        x = a[i]
        i += 2
        break
    i += 1
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()

x, y = 0, 0

i = 0
while i < n - 1:
    if a[i] == a[i + 1]:
        x = a[i]
        i += 2
        break
    i += 1

while i < n - 1:
    if a[i] == a[i + 1]:
        y = a[i]
        i += 2
        break
    i += 1
print(x * y)
while i < n - 1:
    if a[i] == a[i + 1]:
        y = a[i]
        i += 2
        break
    i += 1
print(x * y)

Submission status: Runtime Error

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

input = open(sys.argv[1], "r").readline

def main():
    N = int(input())
    A = list(map(int,input().split()))
    d = collections.defaultdict(int)
    for a in A:
        d[a] += 1
    for k,v in list(d.items()):
        if v < 2:
            d.pop(k)
    d = sorted(d.items(), key=lambda x: x[0], reverse=True)
    if len(d) >= 1 and d[0][1] >= 4:
        print(d[0][0]**2)
    elif len(d) >= 2:
        print(d[0][0]*d[1][0])
    else:
        print(0)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

dic = {}
for i in A:
	if i in dic:
		dic[i] += 1
	else:
		dic[i] = 1
two = []
four = []
for j, k in dic.items():
	if k>=4:
		four.append(j)
	elif k>=2:
		two.append(j)
two.sort(reverse=True)
four.sort(reverse=True)
if len(four) == 0:
	if len(two) <= 1:
		print(0)
	else:
		print(two[0]*two[1])	
else:
	print(max(two[0]*two[1], four[0]**2))

Submission status: Runtime Error

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


a = sorted(a, reverse=True)
count = 0
edge = []
i = 0
for i in range(n-1):
    if a[i] == a[i+1]:
        count = count + 1
        edge.append(a[i])
        i = i + 1
        if count == 2:
            break

s = edge[0]*edge[1] if count == 2 else 0
print(s)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))
rect_long = 0
rect_small = 0
while A != []:
    long_max = max(A)
    if A.count(long_max) >= 2:
        rect_long += long_max
        A.remove(long_max)
        A.remove(long_max)
        break
	A.remove(long_max)

while A != []:
    small_max = max(A)
    if A.count(small_max) >= 2:
        rect_small += small_max
        break
    A.remove(small_max)

print(rect_long * rect_small)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split(' ')))
rect_long = 0
rect_small = 0
while rect_long == 0:
    a_max = max(A)
    if A.count(a_max) >= 2:
        rect_long += a_max
    elif A.count(a_max) >= 4:
        rect_small += a_max
    A.remove(a_max)

while rect_small == 0:
    b_max = max(A)
    if A.count(b_max) >= 2:
        rect_small += b_max
    A.remove(b_max)

print(rect_long * rect_small)

Submission status: Runtime Error

Solution code:
input = sys.stdin.readline

N = int(input())

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

l = collections.Counter(A)

l24 =list([int(l1[0]) for l1 in l.items() if l1[1]>=2])

l24.sort(reverse=True)

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
table = {}
for i in range(n):
  if a[i] not in table:
    table[a[i]] = 1
  else:
    table[a[i]] = table[a[i]] + 1
table = sorted(table.items(), key=lambda x: x[1], reverse=True)
x = 0
y = 0
for i in table:
  if table[i] >= 4:
    if x == 0:
      x = i
      y = i
    else:
      y = i
    break
  elif table[i] >= 2:
    if x == 0:
      x = i
    else:
      y = i
      break
print(x*y)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
table = [0] * (10**9 + 1)
for i in range(n):
  table[a[i]] += 1
x = 0
y = 0
for i in range(10**9, 0, -1):
  if table[i] >= 4:
    if x == 0:
      x = i
      y = i
    else:
      y = i
    break
  elif table[i] >= 2:
    if x == 0:
      x = i
    else:
      y = i
      break
print(x*y)

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
a=[int(i) for i in input().split()]
dic =Counter(a)

li=[]
li2=[]
for i,j in dic.items():
    if j>=2:
        li.append(i)
    if j>=4:
        li2.append(i)
li.sort()
li2.sort()

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

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
A = list(map(int,input().split())), reverse = True
B = collections.Couter(A)
C = []
for a,c in B.items():
    C += [a] * c//2
C.sort()

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

Submission status: Runtime Error

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

a.sort(reverse= True)

cnt = 0
top = []

for i in range(n):
    if len(top) == 2:
        break    
    for j in range(4):
        if a[i] == a[i+1+j]:
            if len(top) == 2:
                break
            if j == 1:
                top.append(a[i])
            elif j == 3:
                top.append(a[i])

if len(top) != 2:
    print(0)
    exit()

print(int(top[0]*top[1]))

Submission status: Runtime Error

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

edges=[]
for k,v in c.items():
    if v>=2:
        for i in range(v//2):
            edges.append(k)
edges.sort(reverse=True)
print(edges[0]*edges[1])

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
a=0
B=[]
C=[]
count=1
for i in range(len(A)):
    if A[i]==a:
        count+=1
    else:
        if count>=2:
            B.append(A[i-1])
        if count>=4:
            C.append(A[i-1])
        a=A[i]
        count=1
if count>=2:
    B.append(A[N-1])
if len(B)<2 and len(C)<1:
    print(0)
else:
    print(max(B[len(B)-1]*B[len(B)-2],C[len(C)]*C[len(C)]))

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <map>

using namespace std;

void AssignWherePossible(int &a, int &b, int value)
{
    if (a == 0) {
        a = value;
    } else if (b == 0) {
        b = value;
    }
}

int main()
{
    int n;
    cin >> n;

    map<int, int> count;
    for (auto i = 0; i < n; i += 1) {
        int length;
        cin >> length;
        count[length] += 1;
    }

    auto side1 = 0;
    auto side2 = 0;

    for (auto it = count.rbegin(); it != count.rend(); it++) {
        if (it->second > 1) {
            AssignWherePossible(side1, side2, it->first);
        }
        if (it->second > 3) {
            AssignWherePossible(side1, side2, it->first);
        }
        if (side2 != 0) {
            break;
        }
    }

    cout << 1LL * side1 * side2 << "\n";
    return 0;
}

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
A = list(map(str,input().split(' ')))
C = collections.Counter(A)
L = sorted(C.items(),key=lambda x:x[0],reverse=True)
ans = []
count = 0
for X in L:
  if count == 2:
    break
  if X[1] >= 2:
    ans.append(X)
    count += 1
  if X[1] >= 4:
    print(max(int(X[0]**2),int(ans[0][0]) * int(X[0])))
    exit()
if count < 2:
  print(0)
  exit()
print(int(ans[0][0]) * int(ans[1][0]))

Submission status: Runtime Error

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

d = defaultdict(int)
for ai in a:
    d[ai] += 1

cand = [k for k, v in d.items() if v >= 2]
cand.sort()

ans = 0
if len(cand) >= 1 and d[cand[-1]] >= 4:
    and = cand[-1] ** 2
if len(cand) >= 2:
    ans = cand[-1] * cand[-2]

print(ans)

Submission status: Runtime Error

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

height = 0
width = 0

for i in range(N-1):
    if A.count(A[i]) >= 2:
        height = A[i]
        continue

for i in range(N):
    if A[i] != height:
        if A.count(A[i]) >= 2:
            width = A[i]
            break

print(height*width)

Submission status: Runtime Error

Solution code:
N = int(input())
sticks = list(map(int, input().split()))
s_dict = {}
for stick in sticks:
  if stick in s_dict:
    s_dict[stick] += 1
  else:
    s_dict[stick] = 1
sorted_dict = sorted(s_dict.items(), key=lambda:-x[0])
side1 = 0
side2 = 0
for elem in sorted_dict:
  if elem[1] >= 4:
    side1 = side2 = elem[0]
  elif elem[1] == 2 or elem[1] == 3:
    if side1 == 0:
      side1 = elem[0]
    else:
      side2 = elem[0]
  if side1 != 0 and side2 != 0:
    print(side1*side2)
    exit()
print(0)

Submission status: Runtime Error

Solution code:
import collections 
N = int(input())
A = [int(i) for i in input().split()]
A = collections.Counter(A)
A = sorted(A.items(), key=lambda x:x[0],reverse = True)
e = []

for k,v in A:
  if v >= 4:
    e.append([k]*2)
  elif v >= 2:
    e.append(k)
  if len(e) >= 2:
    break
if len(e) < 2:
  ans = 0
else:
  ans = e[0]*e[1]
print(ans)

Submission status: Runtime Error

Solution code:
import collections
N=int(input())
A=[int(x) for x in input().split()]
C=collections.Counter(A)
li=[]
for i,j in C:
  if j>=4:
    li.append(i)
    break
  if j>=2:
    li.append(i)
  if len(li)==2:
    break
if len(li)==0:
  print(0)
if len(li)==1:
  print(li[0]**2)
if len(li)==2:
  print(li[0]*li[1])

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
AA=sorted(set(A),reverse=True)
li=[]
for aa in AA:
  if A.count(aa)>=4:
    print(a**2)
    break
  if A.count(aa)>=2:
    li.append(aa)
  if len(li)==2:
    break
if len(li)==0:
  print(0)
if len(li)==2:
  print(li[0]*li[1])

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  ll max1,max2;
  map<ll,int> mp;
  max1 = max2 = 0;
  rep(i,N){
    ll x;cin >> x;
    if(mp.count(x) && mp[x]&1){
      if(x>max1){
        max2 = max1;
        max1 = x;
      }else if(x>max2) max2 = x;
    }else mp[x] = 0;
    ++mp[x];
  }
  cout << max1*max2 << endl;
  return 0;
}

Submission status: Runtime Error

Solution code:
# ABC071-C
import collections
N = int(input())
A_list = sorted(list(map(int, input().split())), reverse = True)
A_set = set(A_list)
A_set = sorted(A_set, reverse=True)
ans_list = [0]   
ans_rectangle_list = []   # 長方形を作る辺を入れる
rec_counter = 0   # 大きい辺を入れる回数，二回入れば良い
for i in range(len(A_set)):   # 大きい順に取っていき，リストで個数を確認する
    if rec_counter == 2:
        break
    count = A_list.count(A_set[i])    # リストの個数を確認
    if count  == 2 or count == 3:   # 対辺を作れる時
        ans_rectangle_list.append(A_set[i])
        rec_counter += 1
    elif count >= 4:   # 4辺全てを作れる
        ans_list.append(A_set[i] ** 2)

if rec_counter == 2:
    rec_ans = ans_rectangle_list[0] * ans_rectangle_list[1]
if len(ans_list) == 0 and len(ans_rectangle_list) <= 1:
    print(0)
else:
    if max(ans_list) > rec_ans:
        print(max(ans_list))
    elif max(ans_list) <= rec_ans:
        print(rec_ans)

Submission status: Runtime Error

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

list=[0]*(10**9+1)

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

one=0
two=0

for i in range(10**9+1):
    if one==0 and list[i]>1:
        one=i
    elif list[i]>1:
        two=one
        one=i

print(one*two)

Submission status: Runtime Error

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

list=[0]*(10**5+1)

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

one=0
two=0

for i in range(10**5+1):
    if one==0 and list[i]>1:
        one=i
    elif list[i]>1:
        two=one
        one=i

print(one*two)

Submission status: Runtime Error

Solution code:
N=int(input())

from collections import defaultdict
d = defaultdict(int)

for i in input().split():
    d[int(i)] += 1

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

longest=0
for length, n in d_sorted:
    if n>=2 and longest!=0:
        print(longest*length)
        exit()
    elif n>=4 and logest==0:
        print(length**2)
        exit()
    elif n>=2 and longest==0:
        longest=length
print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
tables = [0] * (1100000)
a = list(map(int, input().split()))
lines = []
for i in a:
    tables[i] = tables[i] + 1
    if(tables[i] >= 2):
        lines.append(i)

lines = list(set(lines))
lines = sorted(lines, reverse=True)
if(len(lines) >= 2):
    print(lines[0] * lines[1])
else:
    print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
tables = [0] * (110000)
a = list(map(int, input().split()))
lines = []
for i in a:
    tables[i] = tables[i] + 1
    if(tables[i] >= 2):
        lines.append(i)

lines = list(set(lines))
lines = sorted(lines, reverse=True)
if(len(lines) >= 2):
    print(lines[0] * lines[1])
else:
    print(0)

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    A = sorted(list(map(int, input().split())), reverse=True)
    i = 0
    d = []
    while N - 1 > i:
        if len(d) == 2:
            break
        if A[i] == A[i + 1]:
            d.append(A[i])
            i += 1
        i += 1
    print(d[0] * d[1])


main()

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
deta = [0] * (10 ** 6)
for i in a:
    deta[i] += 1
h = 0
w = 0
hind = True
for now in range(len(deta)):
    if deta[now] > 3:
        h = w = now
    elif deta[now] > 1:
        if hind:
            h = now
            hind = False
        else:
            w = now
            hind = True
print(h * w)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
deta = [0] * (10 ** 5)
for i in a:
    deta[i] += 1
h = 0
w = 0
hind = True
for now in range(len(deta)):
    if deta[now] > 3:
        h = w = now
    elif deta[now] > 1:
        if hind:
            h = now
            hind = False
        else:
            w = now
            hind = True
print(h * w)

Submission status: Runtime Error

Solution code:

from collections import Counter

def main():
    num = int(input())
    data = Counter(list(map(int, input().split())))
    score_sorted = sorted(data.items(), key=lambda x: -x[0])

    ans = []
    for ele, kosuu in score_sorted:
        if kosuu >= 2:
            if len(ans) == 0 and kosuu >= 4:
                ans = [ele, ele]
                break
            else:
                ans.append(ele)
                if len(ans) == 2:
                    break
    print(ans[0] * ans[1])



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())

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

length = sorted(length)
length.append(0)

temp = length[0]
c = 1

unique_n = []
square = []

for i in range(n):
    if temp == length[i+1]:
        c += 1
    
    else:
        if c >= 2 :
            unique_n.append(length[i-1])
        
        if c >= 4:
            square.append(length[i-1])
            
        
        c = 1
        temp = length[i+1]

if len(unique_n) <= 1:
    print(0)

else:
    print(max(unique_n[-1]*unique_n[-2],(square[-1])**2))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

ac = Counter(a)

cur_a = 0
cur_c = 0
res = 0
for a,c in ac.items():
	if c < 2:
		break
	if c >= 4:
		res = max(res,a*a)
	if cur_c == c
		res = max(res,cur_a*a)
		cur_a = max(cur_a,a)
	else:
		cur_a = a
		cur_c = c

print(res)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
sorted_a = sorted([i[0]for i in Counter(a).most_common() if i[1] >= 2], reverse=True)
print(sorted_c_a[0] * sorted_c_a[1] if len(sorted_c_a) >= 2 else 0)

Submission status: Runtime Error

Solution code:
N = int(input())
lst_A = list(map(int, input().split()))
lst_rod_num = [0] * (N + 1)
a, b = 0, 0
lst_ans = []


for a in lst_A:
    lst_rod_num[a] += 1


cnt = 0
for i in range(N, -1, -1):
    if cnt == 2:
        a = lst_ans[0]
        b = lst_ans[1]
        break
    if lst_rod_num[i] >= 2:
        lst_ans.append(i)
        cnt += 1
ans = a * b


print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
lst_A = list(map(int, input().split()))
lst_rod_num = [0] * (N + 1)
a, b = 0, 0
lst_ans = []


for a in lst_A:
    lst_rod_num[a] += 1


cnt = 0
for i in range(N - 1, -1, -1):
    if lst_rod_num[i] >= 2:
        lst_ans.append(i)
        cnt += 1
    if cnt == 2:
        a = lst_ans[0]
        b = lst_ans[1]
        break
ans = a * b


print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
lst_A = list(map(int, input().split()))
lst_rod_num = [0] * (N + 1)
a, b = 0, 0
lst_ans = []


for a in lst_A:
    lst_rod_num[a] += 1


cnt = 0
for i in range(N, -1, -1):
    if lst_rod_num[i] >= 2:
        lst_ans.append(i)
        cnt += 1
    if cnt == 2:
        a = lst_ans[0]
        b = lst_ans[1]
        break
ans = a * b


print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
import collections
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    a = list(int(_) for _ in input().split())
    d = collections.defaultdict(int)
    for i in range(N):
        d[a[i]]+=1

    e_1 = 0
    e_2 = 0
    for d_i in sorted(d.items(),key=lambda x:-x[0]):
        if d_i[1] >= 4:
            e_1 = d_1[0]
            e_2 = d_1[0]
        elif d_i[1] >= 2 and e_1 == 0:
            e_1 = d_i[0]
        elif d_i[1] >= 2 and e_2 == 0:
            e_2 = d_i[0]
            break
    print(e_1 * e_2)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
ct = list(Counter(A).items())
flg = 0
ct. sort(key=lambda x: x[0], reverse=True)
for i in ct:
    if i[1] >= 4 and flg == 0:
        ans = i[0]**2
        break
    if i[1] >= 2 and flg == 0:
        flg = 1
        ans = i[0]
    elif i[1] >= 2 and flg == 1:
        ans *= i[0]
        break
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
arr=list(map(int,input().split()))+[0]
arr=sorted(arr, reverse=True
ans1=0
ans2=0
count=1
for i in range(n):
  if arr[i]!=arr[i+1]:
    if count>=2:
      if ans1==0:
        ans1=arr[i]
      else:
        ans2=arr[i]
    count=1
  else:
    count+=1
print(ans1*ans2)

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=I()
A=LI()
B = []
counts = collections.Counter(A)
for count in counts.items():
    if count[1] >= 2:
        B.append(count)
B.sort(reverse=True)
if len(B) ==0:
    print(0)
elif len(B) == 1:
    if B[0][1] >= 4:
        print(B[0][0]**2)
    else:
        print(0)
else:
    if B[0][1] >= 4:
        print(B[0][0]**2)
    else:
        print(B[0]*B[1])

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=I()
A=LI()
B = []
counts = collections.Counter(A)
for count in counts.items():
    if count[1] >= 2:
        B.append(count)
B.sort(reverse=True)
if len(B) ==0:
    print(0)
elif len(B) == 1:
    if B[0][1] >= 4:
        print(B[0][0]**2)
else:
    if B[0][1] >= 4:
        print(B[0][0]**2)
    else:
        print(B[0]*B[1])

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=I()
A=LI()
B = []
counts = collections.Counter(A)
for count in counts.keys():
    if counts[count] >= 2:
        B.append(count)
B.sort(reversed=True)
if len(B) < 2:
    print(0)
else:
    print(B[0]*B[1])

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=I()
A=LI()
B = []
counts = collections.Counter(A)
for count in counts:
    if counts[count] >= 2:
        B.append(count)
B.sort(reversed=True)
if len(B) < 2:
    print(0)
else:
    print(B[0]*B[1])

Submission status: Runtime Error

Solution code:
# カウントしていっていけるやつで比較
# 2つ以上の最大のやつと2番目に大きいやつ vs 4つ以上の最大のやつ

n = int(input())
arr = [0 for _ in range(10**5)]
for i in list(map(int, input().split())):
    arr[i - 1] += 1

ans = 0
overtwo = []
overfour = []
for idx, a in enumerate(arr):
    if a >= 4:
        overfour.append(idx + 1)
    elif a >= 2:
        overtwo.append(idx + 1)

if overfour != [] or len(overtwo) > 1:
    if len(overfour) != 0 and len(overtwo) > 1:
        ans = max(overfour[-1] * 4, overtwo[-1] * overtwo[-2])
    elif len(overfour) != 0:
        ans = overfour[-1] * 4
    else:
        ans = overtwo[-1] * overtwo[-2]
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
from collections import Counter
import math
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
            break
        elif num==1:
            ans*=lst[i]
            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: Runtime Error

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
l.sort(reverse=True)
num=0
d=0
ans=1
A=False
while d<n:
  if l[d]==l[d+1]:
    ans*=l[d]
    num+=1
    i
    d=d+2
  if num==2:
    A=True
    break
if A:
  print(ans)
else:
  print(0)

Submission status: Runtime Error

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()
print(l[-2]*l[-1])

Submission status: Runtime Error

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) - 1]
		del A[len(A) - 2]
	else:
		del A[len(A) -1]

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

Submission status: Runtime Error

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:

Submission status: Runtime Error

Solution code:
n=int(input())
data=[int(aa) for aa in input().split()]
d=[0 for aa in range(100010+1)]
for aa in data:
    d[aa]+=1
#print(d)
mylist=[0,0]
ans1=0
for aa in range(100010+1):
    if d[aa] >3 and ans1 < aa:
        ans1=aa
    if d[aa] >1 :
        if aa not in mylist:
            mylist.pop(0)
            mylist.append(aa)
#            print(mylist)

print(max(ans1*ans1,mylist[0]*mylist[1]))

Submission status: Runtime Error

Solution code:
n=int(input())
data=[int(aa) for aa in input().split()]
d=[0 for aa in range(100000+1)]
for aa in data:
    d[aa]+=1
#print(d)
mydata=0
mylist=[0,0]
for aa in range(100000+1):
    if d[aa] >3:
        mydata=aa
    if d[aa] >1 :
        if aa not in mylist:
            mylist.pop(0)
            mylist.append(aa)
#            print(mylist)
 
print(max(mydata*mydata,mylist[0]*mylist[1]))
n=int(input())
data=[int(aa) for aa in input().split()]
d=[0 for aa in range(100000+1)]
for aa in data:
    d[aa]+=1
#print(d)
mydata=0
mylist=[0,0]
for aa in range(100000+1):
    if d[aa] >3:
        mydata=aa
    if d[aa] >1 :
        if aa not in mylist:
            mylist.pop(0)
            mylist.append(aa)
#            print(mylist)

print(max(mydata*mydata,mylist[0]*mylist[1]))

Submission status: Runtime Error

Solution code:
n=int(input())
data=[int(aa) for aa in input().split()]
d=[0 for aa in range(100000+1)]
for aa in data:
    d[aa]+=1
#print(d)
mydata=0
mylist=[0,0]
for aa in range(100000+1):
    if d[aa] >3:
        mydata=aa
    if d[aa] >1 :
        if aa not in mylist:
            mylist.pop(0)
            mylist.append(aa)
#            print(mylist)

print(max(mydata*mydata,mylist[0]*mylist[1]))

Submission status: Runtime Error

Solution code:
n=int(input())

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

X=[]

t=None

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

Submission status: Runtime Error

Solution code:
n=int(input())

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


X=[]

t=None

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

Submission status: Runtime Error

Solution code:
n=int(input())

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

X=[]

t=None

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

Submission status: Runtime Error

Solution code:
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: Runtime Error

Solution code:
n = int(input())
l = [int(x) for x in input().split()]
x = max(i for i in set(l) if l.count(i)>1)
if l.count(x) > 3:
  print(x*x)
else:
  y = max(i for i in set(l)-{x} if l.count(i) > 1)
  print(y*x)