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:
a = int(input())
b = [0] * (10 ** 5)
c = list(map(int, input().split()))
for i in c:
    b[i-1] += 1
d = 0
e = 0
for i in range(len(b)-1, -1, -1):
    if b[i] >= 2:
        if d == 0:
            d = i+1
        elif e == 0:
            e = i+1
        else:
            print(d*e)
            exit()
print(d*e)

Submission status: Runtime Error

Solution code:
from collcections import Counter
n=int(input())
l=list(map(int,input().split()))
d=[]
L=Counter(l)
a=L.most_common()
for i in a:
  if a[i][1]>=4:
    d.append(a[i][1])
    d.append(a[i][1])
  elif a[i][1]>=2:
    d.append(a[i][1])
d.sort(reverse=True)
print(d[0]*d[1] if len(d)>=2 else 0)

Submission status: Runtime Error

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

C = [0] * 10 ** 9
count = 0
H = 0
W = 0

for i in range(N):
    C[A[i]] += 1

for i in range(N)[::-1]:
    if (C[i] >= 2) and (count == 0):
        H = i
        count += 1
    elif (C[i] >= 2) and (count == 1):
        W = i
        break

print(H * W)

Submission status: Runtime Error

Solution code:
N = int(input())
A = sorted(map(int, input().split()), reverse=True)
 
p = [(i, x) for i, x, y in zip(range(N-1), A[:-1], A[1:]) if x == y]
print(p[0][1] * (p[1][1] if p[0][0] + 1 < p[1][0] else p[2][1]))

Submission status: Runtime Error

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

p = [x for x, y in zip(A[:-1], A[1:]) if x == y]
print(p[0] * p[1])

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
l1={}
l2=[]
for i in l:
  if i in l1:
    if l1[i]%2==0:
      l1[i]+=1
    else:
      l2.append(i)
      l1[i]+=1
  else:
    l1[i]=1
l2=sorted(l2)
print(l2[-1]*l2[-2])

Submission status: Runtime Error

Solution code:
// Created by sz
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int n;
map<long long, int> cnt;


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n;
    long long x;
    for (int i = 1; i <= n; i++){
        cin>>x;
        cnt[x] ++;
    }
    
    vector<long long> sid;
    vector<long long> sid4;
    for (auto i = cnt.rbegin(); i != cnt.rend(); i++){
        if(i->second >=4)sid4.push_back(i->first);
        if(i->second >=2)sid.push_back(i->first);
    }
    
    long long mx = 0;
    
    if(sid4.size()>0)mx = max(mx, sid4[0]*sid4[0]);
    
    if(sid.size()>=2)mx = max(mx, sid[0]*sid[1]);
    
    if(sid4.size()>0 && sid.size()>0)mx = max(mx, sid4[0]*sid[0]);
    
    cout<<mx<<endl;
    
    
    return 0;
}

Submission status: Runtime Error

Solution code:
n=int(input())
d=dict()
for i in map(int,input().split()):
  if i not in d:
    d[i]=1
  else:
    d[i]+=1
ans=[]
for i in d.keys():
  for _ in range(d[i]//2):
    ans.append(i)
ans.sort(reverse=1)
print(ans[0]*ans[1])

Submission status: Runtime Error

Solution code:
import collections
import sys

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
two = [k for k, v in c.items() if v > 1]
four = [k for k, v in c.items() if v > 3]
if len(two) < 2 and not four:
    print(0)
    sys.exit(0)
two.sort(reverse=True)
four.sort(reverse=True)
tmp = 1
for i in range(2):
    tmp *= two[i]
max_four = max(four)
print(tmp if tmp > max_four else max_four)

Submission status: Runtime Error

Solution code:
from collections import Counter
from sys import stdin
N = int(stdin.readline().rstrip())
A = Counter([int(_) for _ in stdin.readline().rstrip().split()]).most_common()
B = [t for t in A if t[1] >= 2]
B.sort(reverse=True)
print(B[0][0]*B[1][0])

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
sa=list(set(a))
sa=sorted(sa,reverse=True)
anew=[]
for i in range(len(sa)):
    if a.count(sa[i])>=2:
        anew.append(sa[i])
        if len(anew)==2:
            break
print(anew[0]*anew[1])

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

dic = {}
for a in A:
  dic[a] = dic.get(a,0) + 1

2p = []
ans = 0

for k in dic:
  if dic[k] >= 4:
    ans = max(ans,dic[k]**2)
  elif dic[k] >= 2:
    2p.append(dic[k])
if len(2p)>=2:
  2p.sort(reverse=True)
  ans = max(ans,2p[0]*2p[1])
print(ans)

Submission status: Runtime Error

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

dic = {}
for a in A:
  dic[a] = dic.get(a,0) + 1

B=[]
for k in dic:
  if dic[k]>=2:
    B.append(k)

B.sort()
if B>=2:
  print(B[-1]*B[-2])
else:
  print(0)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**10)
N = int(input())
A = list(map(int, input().split()))
A = sorted(A, reverse=True)


def chouhoukei(count, ans, num):
    if count == 4:
        return ans
    else:
        if num >= N:
            return 0
        if A[num] == A[num + 1]:
            return chouhoukei(count + 2, ans * A[num], num + 2)
        else:
            return chouhoukei(count, ans, num + 2)


print(chouhoukei(0, 1, 0))

Submission status: Runtime Error

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


def chouhoukei(count, ans, num):
    if count == 4:
        return ans
    else:
        if num >= N:
            return 0
        if A[num] == A[num + 1]:
            return chouhoukei(count + 2, ans * A[num], num + 2)
        else:
            return chouhoukei(count, ans, num + 2)


print(chouhoukei(0, 1, 0))

Submission status: Runtime Error

Solution code:
def inpl(): return [int(i) for i in input().split()]

H, W = inpl()
ans = max(H, W)
S = ''
for _ in range(H):
    S += input()
T = [[0]*(W-1)]
for i in range(H-1):
    t = []
    for j in range(W-1):
        r = S[i*W+j] + S[i*W+j+1] + S[(i+1)*W+j] + S[(i+1)*W+j+1]
        t.append(r.count('.')%2)
    ts = [0]*(W-1)
    for i, k in enumerate(t):
        if k:
            continue
        ts[i] = T[-1][i] + 1
    T.append(ts)
for iT in T[1:]:
    stack = []
    for i, l in enumerate(iT):
        while stack:
            w, h = stack[-1]
            if h > l:
                dw, dh = stack.pop()
                ans = max(ans, (dh+1)*(i-dw+1))
                continue
            break
        stack.append((i, l))
    while stack:
        dw, dh = stack.pop()
        ans = max(ans, (dh+1)*(i-dw+2))
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = input()
b = input()

ans = 3
i = 0
if a[0] != b[0]:
    i += 1
    ans += 3

while i < n-1:
    if a[i]==b[i]:
        if a[i+1]==b[i+1]:
            ans *= 2
        else:
            ans *= 2
            i += 1
    else:
        if a[i+1]==b[i+1]:
            ans *= 1
        else:
            ans *= 3
            i += 1
    i += 1
    ans %= 1000000007
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
u = list(set(a))
u = [i for i in u if a.count(i)>1]
print(u[-1]*u[-2])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def check(i,j):
    if i > 0:
        k = S[j][i-1] 
        if k in checked and not k in C:
            C.append(k)
    if j > 0:
        l = S[j-1][i]
        if l in checked and not l in C:
            C.append(l)
N = int(input())
S = [list(input()) for _ in range(2)]
ans = 1
checked = {}
for i in range(N):
    for j in range(2):
        p = S[j][i]
        if not p in checked:
            C = []
            check(i,j)
            if j < 1 and S[j+1][i] == p:
                check(i,j+1)
            checked[p] = C
            if len(C) > 1:
                if not C[0] in checked[C[-1]]:
                    ans = ((ans*3)//2)
            else:
                ans = (ans*(3-len(C)))
print(ans%(10**9+7))

Submission status: Runtime Error

Solution code:
n =int(input())
nums = input().split(" ")
nums =[int(i) for i in nums]
nums_sort = sorted(nums, reverse=True)
multi_list =[]
cheak =-1
for i in nums_sort:
    if cheak == i:
        multi_list.append(i)
        cheak =-1
        if(len(multi_list)>=2):
            break
        continue
    else:
        cheak=i
        continue
print(multi_list[0]*multi_list[1])

Submission status: Runtime Error

Solution code:
n =int(input())
nums = input().split(" ")
nums =[int(i) for i in nums]
nums_sort = sorted(nums, reverse=True)
for i in nums:
    count =nums.count(i)
    if(count > 1):
        for j in range(count-1):
            nums_sort.remove(i)
            nums.remove(i)
    else:
        nums_sort.remove(i)
print(nums_sort[0]*nums_sort[1])

Submission status: Runtime Error

Solution code:
n =int(input())
nums = input().split(" ")
nums =[int(i) for i in nums]
num3=[]
for i in nums:
    if(nums.count(i)>=2):
        num3.append(i)
#         nums.remove(i)
num2= sorted(num3, reverse=True)
print(num2[0]*num2[1])

Submission status: Runtime Error

Solution code:
n =int(input())
nums = input().split(" ")
nums =[int(i) for i in nums]
num3=[]
for i in nums:
    if(nums.count(i)>=2):
        num3.append(i)
        nums.remove(i)
num2= sorted(num3, reverse=True)
print(num2[0]*num2[1])

Submission status: Runtime Error

Solution code:
n = int(raw_input())

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

    occ[i] += 1

found = 0
rect = 1

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

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

Submission status: Runtime Error

Solution code:
n = int(raw_input())

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

    occ[i] += 1

found = 0
rect = 1

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

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

Submission status: Runtime Error

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

bar_list = {}
for i in a:
	if i in bar_list:
		bar_list[i] += 1
	else:
		bar_list[i] = 1

saved = -1
ans = 0
for k, v in sorted(bar_list.items(), key=lambda x:x[1]):
	if v > 1:
		if saved < 0:
			saved = k
		else:
			ans = saved * k
			break
print(ans)

Submission status: Runtime Error

Solution code:
def checkio(data):
    list = []
    for i in data:
        for x in range(data.index(i) + 1,len(data)):
            if i == data[x]:
                list.append(i)
                break
    return list
n = int(input())
list2 =  checkio(map(int,raw_input().split()))
list2.sort()
if len(list2) < 3 == True:
    print 0
else:
    print list2[len(list2)-1]*list2[len(list2)-3]

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
l = [0,0]
c = 0
for j in range(len(a)-1):
    if(count => 2):
        print(l[0] * l[1])
    if(a[j] == a[j+1]):
        del l[0]
        l.append(a[j])
        j += 1
        c += 1

Submission status: Runtime Error

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
l = [0,0]
c = 0
for j in range(len(a)-1):
    if(count => 2):
        print(l[0] * l[1])
    if(a[j] == a[j+1]):
        del l[0]
        l.append(a[j])
        j += 1
        count += 1

Submission status: Runtime Error

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
l = [0,0]
count = 0
for j in range(len(a)-1):
    if(count => 2):
        print(l[0] * l[1])
    if(a[j] == a[j+1]):
        del l[0]
        l.append(a[j])
        j += 1
        count += 1

Submission status: Runtime Error

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
l = [0,0]
count = 0
for j in range(len(a)-1):
    if(count => 2):
        print(l[0] * l[1])
        break
    if(a[j] == a[j+1]):
        del l[0]
        l.append(a[j])
        j += 1
        count += 1

Submission status: Runtime Error

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
l = [0,0]
count = 0
for j in range(len(a)-1):
    if(count => 2):
        print(l[0] * l[1])
        exit()
    if(a[j] == a[j+1]):
        del l[0]
        l.append(a[j])
        j += 1
        count += 1

Submission status: Runtime Error

Solution code:
N = int(input())
s1 = input()
s2 = input()
sum = 1
mul = 1
flag = 0
i = 0

while True:
    if i >= N:
        print(sum%1000000007)
        break

    elif s1[i]==s2[i] and flag==0:
        sum = 3
        i += 1
        flag = 1
    elif s1[i]!=s2[i] and flag==0:
        sum = 6
        i += 2
        flag = 2
    elif s1[i]==s2[i] and flag==1:
        mul = 2
        i += 1
        flag = 1
    elif s1[i]!=s2[i] and flag==1:
        mul = 2
        i += 2
        flag = 2
    elif s1[i]==s2[i] and flag==2:
        mul = 1
        i += 1
        flag = 1
    elif s1[i]!=s2[i] and flag==2:
        mul = 3
        i += 2
        flag = 2
    sum = sum*mul

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

res = sorted(res, reverse=True)

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

print(result)

Submission status: Runtime Error

Solution code:
#coding utf-8
_=input()
bars=[i for i in map(int,input().split())]
bars.sort(reverse=True)
stock=[]
ret=0
_old=-1
for bar in bars:
    if bar=_old:
        continue
    _old=bar
    count=bars.count(bar)
    if count>=4:
        if len(stock)!=0 and  bar not in stock:
            #print("ret bar bar")
            ret=bar*stock[0]
        else:
            #print("ret bar bar")
            ret=bar*bar
        break
    elif count>=2:
        if bar in stock:
            continue
        stock.append(bar)
        if len(stock)==2 :
            #print("ret stock stock")
            ret=stock[0]*stock[1]
            break
print(ret)

Submission status: Runtime Error

Solution code:
a = []
x = input()
str1 = raw_input()
str2 = raw_input()
count = 0
while True:
    if count>x-1:
        break
    if str1[count] == str2[count]:
        a.append("v")
        count+=1
    else:
        a.append("h")
        count+=2
total = 1
if a[0] == "h":
    total*=6
if a[0] == "v":
    total*=3
for i in range(1, len(a)):
    if a[i] == "v" and a[i-1] == "h":
        total *=1
        total = total%1000000007
    elif a[i] == "h" and a[i-1] == "v":
        total*=2
        total = total%1000000007
    elif a[i] == "v" and a[i-1] == "v":
        total*=2
        total = total%1000000007
    elif a[i] == "h" and a[i-1] == "h":
        total*=3
        total = total%1000000007
print total

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
input()

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

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

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

Submission status: Runtime Error

Solution code:
input()

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

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

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

Submission status: Runtime Error

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

    A.sort(reverse=True)

    v = []
    while len(A) != 0:
        if len(v) == 2:
            break

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = np.array([int(i) for i in input().split()])
A.sort()
A = A[::-1]

l = []
for i in range(1,N):
    cnt = 0
    flg = 0
    if A[i] == A[i-1] and flg == 0:
        l.append(A[i].astype(np.int64))
        flg = 1
    else:
        flg = 0
    
    if len(l) >= 2:
        break
print(l[0]*l[1])

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
S = [input() for _ in range(H)]

ans = max(H, W)

f = [1] * W
for i in range(1, H):
    f = [(f[j]+1) if (S[i-1][j:j+2] + S[i][j:j+2]).count('#') in [0,2,4] else 1 for j in range(W-1)] + [0]
    stk = []
    for j, v in enumerate(f):
        while len(stk) > 0 and f[stk[-1]] >= v:
            ans = max(ans, f[stk.pop()] * (j - (stk[-1] if len(stk) > 0 else -1)))
        stk.append(j)

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
A = A[::-1]

l = []
for i in range(1,N):
    cnt = 0
    flg = 0
    if A[i] == A[i-1] and flg == 0:
        l.append(A[i].astype(np.int64))
        flg = 1
    else:
        flg = 0
    
    if len(l) >= 2:
        break
print(l[0]*l[1])

Submission status: Runtime Error

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


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


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

    i+=1


x.extend([0,0])

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

Submission status: Runtime Error

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


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


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

    i+=1
    if i>=len(sa):
        break

x.extend([0,0])

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

Submission status: Runtime Error

Solution code:
from __future__ import print_function
from collections import deque
from bisect import bisect_left as bl
input = raw_input
range = xrange

def goto(fr, to):
    i = bl(occ[to], fr+1)
    if i == len(occ[to]): return n+1
    return occ[to][i]

s = [-1]+[ord(c)-97 for c in input()]
n = len(s)-1
occ = [[] for i in range(26)]
for i in range(1, n+1):
    occ[s[i]].append(i)
visit = [None]*(n+2)
visit[0] = (-1, -1) # letter, lastindex
Q = deque()
Q.append(0)

while len(Q):
    p = Q.popleft()
    if p == n+1: break
    for q in range(26):
        qi = goto(p, q)
        if visit[qi]: continue
        visit[qi] = (q, p)
        Q.append(qi)
stack = []
i = n+1
while visit[i][0] != -1:
    stack.append(visit[i][0])
    i = visit[i][1]

for i in reversed(stack):
    print(chr(97+i), end='')

Submission status: Runtime Error

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


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


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

    i+=1

x.extend([0,0])

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

Submission status: Runtime Error

Solution code:
N=int(input())
a=spaceinput()


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

x.extend([0,0])
print(x[0]*x[1])