input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
#!usr/bin/env python3
from collections import defaultdict
def main():
#Read stdin
fl = input().split(" ")
V = int(fl[0])
E = int(fl[1])
R = int(fl[2])
#Adjacency list
G = defaultdict(list)
for i in range(int(E)):
s, t, w = [int(x) for x in input().split(" ")]
... | from collections import defaultdict
from collections import deque
#import time
def main():
# Read stdin
#start = time.clock()
fl = input().split(" ")
V = int(fl[0])
E = int(fl[1])
R = int(fl[2])
# Adjacency list
G = defaultdict(list)
for i in range(int(E)):
s, ... | p02361 |
from collections import defaultdict
from collections import deque
#import time
def main():
# Read stdin
#start = time.clock()
fl = input().split(" ")
V = int(fl[0])
E = int(fl[1])
R = int(fl[2])
# Adjacency list
G = defaultdict(dict)
for i in range(E):
s, t, ... | #!usr/bin/env python3
'''
time score 7.88 for list
time score 03.17 for deque
time score 03.22 for defaultdict(dict)
'''
from collections import defaultdict
from collections import deque
#import time
def main():
# Read stdin
#start = time.clock()
fl = input().split(" ")
V = int(fl[... | p02361 |
#!usr/bin/env python3
'''
time score 7.88 for list
time score 03.17 for deque
time score 03.22 for defaultdict(dict)
'''
from collections import defaultdict
from collections import deque
#import time
def main():
# Read stdin
#start = time.clock()
fl = input().split(" ")
V = int(fl[... | from collections import defaultdict
from collections import deque
from sys import stdin
def sp(G,R,V):
d = {}
INF = float('inf')
for i in range(V):
d[i] = INF
d[R] = 0
q = deque([(R)])
while q:
u = q.popleft()
for v in G[u]:
if d[v[0]] > d[u] + ... | p02361 |
from collections import defaultdict
from collections import deque
from sys import stdin
def sp(G,R,V):
d = {}
INF = float('inf')
for i in range(V):
d[i] = INF
d[R] = 0
q = deque([(R)])
while q:
u = q.popleft()
for v in G[u]:
if d[v[0]] > d[u] ... | from collections import defaultdict
from collections import deque
from sys import stdin
def sp(G,R,V):
d = {}
INF = float('inf')
for i in range(V):
d[i] = INF
d[R] = 0
q = deque([(R)])
while q:
u = q.popleft()
for v in list(G[u].keys()):
if d[... | p02361 |
from collections import defaultdict
from collections import deque
from sys import stdin
def sp(G,R,V):
d = {}
INF = float('inf')
for i in range(V):
d[i] = INF
d[R] = 0
q = deque([(R)])
while q:
u = q.popleft()
for v in list(G[u].keys()):
if d[... | from collections import defaultdict
from collections import deque
from sys import stdin
def sp(G,R,V):
d = {}
INF = float('inf')
for i in range(V):
d[i] = INF
d[R] = 0
q = deque([(R)])
while q:
u = q.popleft()
for v in list(G[u].keys()):
if d[v]... | p02361 |
from collections import defaultdict
from heapq import heappush, heappop, heapify
from sys import stdin
def sp(G,R,V):
d = {}
q = [(0, R)]
heapify(q)
seen = set()
while q:
(cost, v) = heappop(q)
if v not in seen:
seen.add(v)
d[v] = cost
... | from collections import defaultdict
from heapq import heappush, heappop, heapify
from sys import stdin
def sp(G,R,V):
d = {}
q = [(0, R)]
heapify(q)
#seen = set()
while q:
(cost, v) = heappop(q)
if v not in d:
#seen.add(v)
d[v] = cost
... | p02361 |
from heapq import heappop as pop
from heapq import heappush as push
INF = 10 ** 18
class edge:
def __init__(self, to, cost):
self.to = to
self.cost = cost
V, E, r = list(map(int,input().split()))
G = [[] for i in range(V)]
#G[i]...頂点iからの辺、(行き先、コスト)
d = [0 for i in range(V)]
#d[i]...スタートからみた... | from heapq import heappush, heappop
INF = 10 ** 20
v_num, e_num, r = list(map(int, input().split()))
edges_lst = [[] for _ in range(v_num)]
dist_lst = [INF for _ in range(v_num)]
for _ in range(e_num):
s, t, dist = list(map(int, input().split()))
edges_lst[s].append((t, dist))
que = []
heappush(que... | p02361 |
import heapq
maxd = float('inf')
nv, ne, r = [int(n) for n in input().split(' ')]
vertices = {k: {} for k in range(nv)}
for i in range(ne):
s, t, w = [int(n) for n in input().split(' ')]
vertices[s][t] = w
q = []
heapq.heappush(q, (0, r))
dist = {v: maxd for v in vertices}
dist[r] = 0
while l... | import heapq
nv, ne, r = map(int, input().split(' '))
vertices = [[] for i in range(nv)]
for i in range(ne):
s, t, w = map(int, input().split(' '))
vertices[s].append((t, w))
q = []
heapq.heappush(q, (0, r))
dist = [float('inf')] * nv
dist[r] = 0
while len(q):
u = heapq.heappop(q)[1]
... | p02361 |
import heapq
class Edge:
def __init__(self, dst, weight):
self.dst, self.weight = dst, weight
def __lt__(self, e):
return self.weight > e.weight
class Graph:
def __init__(self, V):
self.V = V
self.E = [[] for _ in range(V)]
def add_edge(self, src, ds... | import heapq
class Edge:
def __init__(self, dst, weight):
self.dst, self.weight = dst, weight
def __lt__(self, e):
return self.weight > e.weight
class Graph:
def __init__(self, V):
self.V = V
self.E = [[] for _ in range(V)]
def add_edge(self, src, ds... | p02361 |
import sys
from collections import deque
# 初期化
n_V, n_E, r = list(map(int, input().split()))
E = [[] for _ in range(n_V)]
D = [sys.maxsize for _ in range(n_V)]
# 入力
for i in range(n_E):
v, e, d = list(map(int, input().split()))
E[v].append((e, d))
# 各頂点への最短距離を求める処理
D[r] = 0
queue = deque([r]... | import sys
from heapq import heappush
from heapq import heappop
# 入力
n_V, n_E, r = list(map(int, input().split()))
E = [[] for _ in range(n_V)]
for i in range(n_E):
v, e, c = list(map(int, input().split()))
E[v].append((e, c))
# 初期化
D = [sys.maxsize for _ in range(n_V)]
D[r] = 0
h = []
... | p02361 |
v,e,r = list(map(int,input().split()))
d = [float('INF')]*v
d[r] = 0
edges=[]
for i in range(e):
s,t,c = list(map(int,input().split()))
edges.append([s,t,c])
for i in range(v):
for s,v,c in edges:
if d[v] > d[s]+c:
d[v] = d[s]+c
for i in d:
if i == float('inf'):
print('INF')
... | v,e,r = list(map(int,input().split()))
d = [float('INF')]*v
d[r] = 0
edges=[]
for i in range(e):
s,t,c = list(map(int,input().split()))
edges.append([s,t,c])
for i in range(v):
count = 0
for s,v,c in edges:
if d[v] > d[s]+c:
count += 1
d[v] = d[s]+c
if count == 0:
break
... | p02361 |
from collections import defaultdict
import heapq
vertice,edge,source = list(map(int,input().split(" ")))
link = defaultdict(dict)
weight = defaultdict(dict)
answer = [-1] * vertice
for e in range(edge):
i,j,w = list(map(int,input().split(" ")))
link[i] = link.get(i,set()) | {j}
weight[i].update({... | import sys
from heapq import heappush, heappop
readline = sys.stdin.readline
from collections import defaultdict
vertices, edges, start = list(map(int, readline().split()))
connect = defaultdict(list)
cost = defaultdict(dict)
answer = ["INF" for n in range(vertices)]
for _ in range(edges):
s, t, w = list(m... | p02361 |
# Single Source Shortest Path
class node():
def __init__(self, v, cost):
self.v = v
self.cost = cost
infty = 999999999
dict_c = {}
[vertex, edge, r] = list(map(int, input("").split()))
root_c = [node(r, 0)]
final_c = [infty for i in range(vertex)]
final_c[r] = 0
for i in range(edge):
... | # Single Source Shortest Path
import heapq
[vertex, edge, r] = list(map(int, input("").split()))
infty = 999999999
final_c = [infty for i in range(vertex)]
dict_c = [[] for i in range(vertex)]
for i in range(edge):
[e1, e2, c] = list(map(int, input("").split()))
dict_c[e1].append((e2, c))
final_c... | p02361 |
v,e,s=list(map(int,input().split()))
edge=[]
inf =1000000100
for i in range(v):
edge.append([])
for i in range(e):
vs,vt,d=list(map(int,input().split()))
edge[vs].append((vt,d))
dis=[]
for i in range(v):
dis.append(inf)
dis[s]=0
for j in range(v):
for i in range(v):
... | v,e,s=list(map(int,input().split()))
edge=[]
inf =1000000100
for i in range(v):
edge.append([])
for i in range(e):
vs,vt,d=list(map(int,input().split()))
edge[vs].append((vt,d))
dis=[]
for i in range(v):
dis.append(inf)
dis[s]=0
for j in range(v):
update=False
for i in ... | p02361 |
v, e, r = list(map(int, input().split()))
edgeList = [[0, 0, 0] for i in range(e)]
for i in range(e):
a = list(map(int, input().split()))
edgeList[i] = [a[2], a[0], a[1]]
rootList = [-1 for i in range(v)]
parent = [0 for i in range(v)]
lenList = [float("inf") for i in range(v)]
lenList[r] = 0
def... | from heapq import heappush, heappop
N, M, s = list(map(int, input().split()))
Adj = [[] for i in range(N)]
for i in range(M):
ui, vi, ci = list(map(int, input().split()))
Adj[ui].append((vi, ci))
d = [float("inf")] * N
d[s] = 0
pq = [(0, s)]
fixed = 0
while pq:
di, v = heappop(pq)
if... | p02361 |
import heapq
import math
def main():
nvertices, nedges, s = list(map(int, input().split()))
edges = [[] for i in range(nvertices)]
for i in range(nedges):
u, v, w = list(map(int, input().split()))
edges[u].append((v, w))
INF = float('inf')
hq = []
for i in range(nve... | import heapq
import math
def main():
nvertices, nedges, s = list(map(int, input().split()))
edges = [[] for i in range(nvertices)]
for i in range(nedges):
u, v, w = list(map(int, input().split()))
edges[u].append((v, w))
INF = float('inf')
hq = [(0, s)]
weights = [I... | p02361 |
from collections import deque
import sys
def solve():
readline = sys.stdin.readline
N, M, K = list(map(int, readline().split()))
*A, = list(map(int, readline().split()))
S = A[:]
T = [0]*N
zeros = [0]*N
for k in range(K-1):
que0 = deque()
que1 = deque()
... | import sys
def solve():
readline = sys.stdin.readline
N, M, K = list(map(int, readline().split()))
*A, = list(map(int, readline().split()))
S = A[:]
T = [0]*N
Q0 = [0]*N; Q1 = [0]*N
for k in range(2, K+1):
s = t = 0
for i in range(k-1, N):
a = S[i... | p03899 |
from sys import stderr
def reads():
return [int(x) for x in input().split()]
INF = 1 << 63
N, M, K = reads()
A = reads()
dp = A
for j in range(2, K+1):
deq = [0] * N; l = r = 0
q = [-INF] * N
for i in range(N):
# pop
while l < r and deq[l] < i-M:
l += 1
# max
q[i] = ... | from sys import stderr
def reads():
return [int(x) for x in input().split()]
N, M, K = reads()
A = reads()
dp = [[0] * N, list(A)]
deq = [0] * N
for j in range(2, K+1):
l = r = 0
b = j & 1
prev = dp[1-b]; curr = dp[b]
for i in range(N):
# pop
while l < r and deq[l] < i-M:
l +... | p03899 |
from sys import stdin
N,K=[int(x) for x in stdin.readline().rstrip().split()]
if K == 1:
print("YES")
else:
if N+1-(K*2) >=0:
print("YES")
else:
print("NO") | from sys import stdin
N,K = [int(x) for x in stdin.readline().rstrip().split()]
if len(list(range(1,N+1))[0::2]) >= K:
print("YES")
else:
print("NO") | p03129 |
n,k = list(map(int, input().split()))
if n==1 or n==2:
if k==1:
print('YES')
else:
print('NO')
elif n%2==0:
cnt = n/2
if(cnt>=k):
print('YES')
else:
print('NO')
else:
cnt = n//2 + 1
if(cnt>=k):
print('YES')
else:
print('NO'... | n,k = list(map(int, input().split()))
x = (n+1)//2
bl = (x>=k)
ans = 'YES' if bl else 'NO'
print(ans) | p03129 |
from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
c = Counter()
for ai in A:
c[ai] += 1
more_than_2 = []
for k, v in list(c.items()):
if v >= 4:
more_than_2.append(k)
if v >= 2:
more_than_2.append(k)
if len(more_than_2) < 2:
... | from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
# print(A)
lines = []
cnt = 1
before = 'XXX'
for ai in A + ['YYY']:
if ai == before:
cnt += 1
else:
if cnt >= 4:
lines.append(before)
lines.... | p03625 |
from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
# print(A)
lines = []
cnt = 1
before = 'XXX'
for ai in A + ['YYY']:
if ai == before:
cnt += 1
else:
if cnt >= 4:
lines.append(before)
lines.... | def main():
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
lines = []
prev = ''
for ai in A:
if ai == prev:
lines.append(ai)
prev = ''
else:
prev = ai
if len(lines) >= 2:
print((... | p03625 |
from collections import Counter
N = int(eval(input()))
A = [int(Ai) for Ai in input().split()]
c = Counter(A).most_common()
c.sort(key=lambda x: x[0], reverse=True)
e1 = None
result = None
for k, v in c:
if e1 is None and v >= 4:
result = k**2
break
elif v >= 2:
if e1 is None... | N = int(eval(input()))
A = sorted([int(Ai) for Ai in input().split()], reverse=True)
x, y = 0, 0
current = A[0]
for Ai in A[1:]:
if current is None or current != Ai:
current = Ai
else:
if x == 0:
x = current
current = None
else:
y = current... | p03625 |
from sys import stdin
input = stdin.readline
n = int(eval(input()))
re_nums = []
nums = []
A = list(map(int, input().split()))
for a in A:
if a not in re_nums:
re_nums.append(a)
else:
nums.append(a)
nums.sort(reverse=True)
l = len(nums)
ans = 0
if l < 2:
ans = 0
else:
... | from sys import stdin
input = stdin.readline
n = int(eval(input()))
dic = {}
A = list(map(int, input().split()))
for a in A:
if a not in dic:
dic[a] = 1
else:
dic[a] += 1
nums = list(dic.items())
nums.sort(reverse = True)
l = len(nums)
l1 = 0
for i in range(l):
if l1 == 0 an... | p03625 |
from collections import Counter
eval(input())
ans = []
for i, j in list(Counter(list(map(int, input().split()))).items()):
if j >= 4:
ans.append(i)
if j >= 2:
ans.append(i)
if len(ans) >= 2:
ans.sort()
print((ans[-1] * ans[-2]))
else:
print((0))
| from collections import Counter
eval(input())
ans = [0, 0]
for i, j in list(Counter(list(map(int, input().split()))).items()):
if j >= 4:
ans.append(i)
if j >= 2:
ans.append(i)
ans.sort()
print((ans[-1] * ans[-2]))
| p03625 |
n=int(eval(input()))
a=list(map(int,input().split()))
a.sort(reverse=True)
memo=[]
h=0; w=0
for element in a:
if element in memo: pass
else:
memo.append(element)
num=a.count(element)
if num>=4 and h==0: h=w=element
elif num>=2 and h==0: h=element
elif num>=2... | n=int(eval(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)
| p03625 |
N = int(eval(input()))
A = [int(x) for x in input().split()]
pair = []
unpair = []
for a in A:
if a in unpair:
pair.append(a)
unpair.remove(a)
else:
unpair.append(a)
pair.sort()
pair.reverse()
if len(pair) <= 1:
ans = 0
else:
ans = pair[0] * pair[1]
print(ans) | N = int(eval(input()))
A = [int(x) for x in input().split()]
pair = []
unpair = set()
for a in A:
if a in unpair:
pair.append(a)
unpair.remove(a)
else:
unpair.add(a)
pair.sort()
pair.reverse()
if len(pair) <= 1:
ans = 0
else:
ans = pair[0] * pair[1]
print(ans) | p03625 |
import collections
n = int(eval(input()))
a = list(map(int, input().split()))
rec_hen = 0
a_set = sorted(set(a), reverse=True)
for ai in a_set:
ac = a.count(ai)
if ac >= 4:
if rec_hen != 0:
print((rec_hen * ai))
exit(0)
print((ai * ai))
exit(0)
if ac >= 2:
if rec_hen !=... | import collections
n = int(eval(input()))
a = list(map(int, input().split()))
rec_hen = 0
#a_set = sorted(set(a), reverse=True)
acc = collections.Counter(a)
ssa = sorted(list(acc.items()), key=lambda x: x, reverse=True)
for i, c in ssa:
if c >= 4:
if rec_hen != 0:
print((rec_hen * i))
exi... | p03625 |
N = int(eval(input()))
bar = [int(x) for x in input().split()]
ls = []
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.append(x)
print((a*b... | N = int(eval(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... | p03625 |
import sys
input = sys.stdin.readline
n = int(eval(input()))
a = list(map(int, input().split()))
aset = set(a)
b = []
c = []
for i in aset:
if a.count(i)>1:
b.append(i)
if a.count(i)>3:
c.append(i)
b.sort()
c.sort()
m = len(b)
if m<2:
if len(c)<1:
print((0))
... | import sys
input = sys.stdin.readline
n = int(eval(input()))
a = list(map(int, input().split()))
a.sort(reverse=True)
i = 1
j = 1
l = []
while i<n:
if a[i]==a[i-1]:
l.append(a[i])
i+=2
else:
i+=1
l.append(0)
l.append(0)
print((l[0]*l[1])) | p03625 |
eval(input())
from collections import *
c=Counter(list(map(int,input().split())))
a=0
r=sorted(-k for k,v in list(c.items()) if v>1)
if len(r)>1: a=r[0]*r[1]
s=sorted(-k for k,v in list(c.items()) if v>3)
if s: a=max(a,s[0]**2)
print(a) | eval(input())
from collections import *
c=Counter(list(map(int,input().split())))
f=lambda x:sorted(-k for k,v in list(c.items()) if v>x)
a=0;r=f(1);s=f(3)
if len(r)>1: a=r[0]*r[1]
if s: a=max(a,s[0]**2)
print(a) | p03625 |
n = int(eval(input()))
a = list(map(int,input().split()))
x=0
y=0
a.sort()
i=1
while (i<len(a)):
if a[i-1]==a[i]:
x=y
y=a[i]
i+=2
else:
i+=1
print((x*y)) | n = int(eval(input()))
a = list(map(int,input().split()))
x=0
y=0
a.sort()
i=len(a)-1
while (i>0):
if a[i-1]==a[i]:
x=y
y=a[i]
i-=2
else:
i-=1
if x>0:
break
print((x*y))
| p03625 |
n = int(eval(input()))
a = list(map(int,input().split()))
x=0
y=0
a.sort()
i=len(a)-1
while (i>0):
if a[i-1]==a[i]:
x=y
y=a[i]
i-=2
else:
i-=1
if x>0:
break
print((x*y))
| n = int(eval(input()))
a = list(map(int,input().split()))
x=0
y=0
a.sort()
i=n-1
while (i>0):
if a[i-1]==a[i]:
x=y
y=a[i]
if x>0:
break
i-=2
else:
i-=1
print((x*y)) | p03625 |
import collections
N = int(eval(input()))
A = [int(i) for i in input().split()]
stick_num = collections.Counter(A)
flag = True
ans = 0
for i in sorted(stick_num, reverse=True):
if stick_num[i] >= 4:
ans = i * i if flag else a * i
break
elif stick_num[i] >= 2:
if flag:
... | N = int(eval(input()))
A = [int(i) for i in input().split()]
A.sort(reverse=True)
flag_h = True
flag_v = True
h, v = 0, 0
for i in A:
if flag_h:
if h == i:
flag_h = False
else:
h = i
elif flag_v:
if v == i:
flag_v = False
els... | p03625 |
from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
count = Counter(a)
ans = [0]*2
t = 0
for i in sorted(list(count.items()), reverse=True):
if i[1] >= 4:
if t == 0:
ans[0],ans[1] = i[0],i[0]
t = 2
elif t == 1:
ans[t] = i[0]
t += 1
... | n = int(eval(input()))
a = list(map(int, input().split()))
d = {}
for i in a:
if i in d: d[i] += 1
else: d[i] = 1
t = 0
ans = []
for k,v in sorted(list(d.items()), key=lambda x: x[0], reverse=True):
if v >= 4 and t == 0:
print((k*k))
exit()
elif v >= 2:
ans.append(k)
t += 1
... | p03625 |
N = int(eval(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]))
| N = int(eval(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]))
| p03625 |
from collections import Counter
import sys
N = int(eval(input()))
A = [int(_) for _ in input().split()]
key_val_lis = []
for key, value in list(Counter(A).items()):
if value >= 2:
key_val_lis.append((key, value))
ans_lis = sorted(key_val_lis, key=lambda x: -x[0])
if len(ans_lis) <= 1 or ans_l... | from collections import Counter
import sys
N = int(eval(input()))
A = [int(_) for _ in input().split()]
key_val_lis = []
for key, value in list(Counter(A).items()):
if value >= 2:
key_val_lis.append((key, value))
ans_lis = sorted(key_val_lis, key=lambda x: -x[0])
#print(ans_lis)
if not ans_lis... | p03625 |
import collections
n=int(eval(input()))
A=list(map(int,input().split()))
X=collections.Counter(A)
ans=1
cnt_1=0
cnt_2=0
for k,v in sorted(list(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:
... |
n=int(eval(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)) | p03625 |
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
l1, l2 = 0, 0
while len(A) > 1:
if A[-1] == A[-2] and l1 == 0:
l1 = A[-1]
A = A[:-2]
elif A[-1] == A[-2] and l2 == 0:
l2 = A[-1]
break
else:
A = A[:-1]
print((l1 * l2))
| N = int(eval(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:
... | p03625 |
eval(input())
a = list(map(int,input().split()))
sa = list(set(a))
b = [ i for i in sa if a.count(i)>=2 ]
c = [ i for i in sa if a.count(i)>=4 ]
b=b+c
b.sort(reverse=True)
if len(b)>=2:
print((b[0]*b[1]))
else:
print((0))
| n = int(eval(input()))
a = list(map(int,input().split()))
a.sort(reverse=True)
bn = 0
ans = 0
count = 0
i = 0
while(i<n):
if bn==a[i]:
if count == 0:
ans = a[i]
if i+1<n:
bn = a[i+1]
i += 1
count +=1
else:
... | p03625 |
from sys import stdin
n, *a = list(map(int, stdin.read().split()))
lengths = sorted(set(a), reverse=1)
a.sort()
long_side, short_side = 0, 0
for l in lengths:
c = a.count(l)
if c != 1:
if not long_side:
if c >= 4:
print((l ** 2))
exit()
... | from sys import stdin
n, *a = list(map(int, stdin.read().split()))
a.sort(reverse=1)
l_count = {}
for l in a:
l_count.update({l: l_count.get(l, 0) + 1})
long_side, short_side = 0, 0
for l, c in sorted(list(l_count.items()), reverse=1):
if c != 1:
if not long_side:
if c ... | p03625 |
from sys import stdin
n, *a = list(map(int, stdin.read().split()))
a.sort(reverse=1)
l_count = {}
for l in a:
l_count.update({l: l_count.get(l, 0) + 1})
long_side, short_side = 0, 0
for l, c in sorted(list(l_count.items()), reverse=1):
if c != 1:
if not long_side:
if c ... | from sys import stdin
n, *a = list(map(int, stdin.read().split()))
l_count = {}
for l in a:
l_count.update({l: l_count.get(l, 0) + 1})
long_side, short_side = 0, 0
for l, c in sorted(list(l_count.items()), reverse=1):
if c != 1:
if not long_side:
if c >= 4:
... | p03625 |
import sys
n, *l = list(map(int, sys.stdin.read().split()))
def main():
l.sort(reverse=True)
a = b = 0
i = 0
while i <= n - 2:
if l[i] == l[i+1]:
if a:
b = l[i]
break
else:
a = l[i]
i += 2
... | import sys
n, *a = list(map(int, sys.stdin.read().split()))
def main():
a.sort()
y = x = 0
i = n - 1
while i > 0:
if a[i] == a[i-1]:
if not y:
y = a[i]
i -= 1
else:
x = a[i]
break
i ... | p03625 |
import sys
import math
import collections
import itertools
import array
import inspect
# Set max recursion limit
sys.setrecursionlimit(1000000)
# Debug output
def chkprint(*args):
names = {
id(v): k
for k, v in list(inspect.currentframe().f_back.f_locals.items())
}
print(... | import sys
import math
import collections
import itertools
import array
import inspect
# Set max recursion limit
sys.setrecursionlimit(1000000)
# Debug output
def chkprint(*args):
names = {
id(v): k
for k, v in list(inspect.currentframe().f_back.f_locals.items())
}
print(... | p03625 |
import sys
import math
import collections
import itertools
import array
import inspect
# Set max recursion limit
sys.setrecursionlimit(1000000)
# Debug output
def chkprint(*args):
names = {
id(v): k
for k, v in list(inspect.currentframe().f_back.f_locals.items())
}
print(... | N = int(eval(input()))
A = list(map(int,input().split()))
Acount = {}
q = []
for a in A:
if a not in Acount:
Acount[a] = 0
Acount[a] += 1
for key, val in list(Acount.items()):
if val >= 2:
q.append(key)
if val >= 4:
q.append(key)
q.sort(reverse=True)
if len(q) ... | p03625 |
N = int(eval(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.count(P[i]) >= 2:
a = P[i]
P[i] = -i
P[i+1] = -i -1
elif b == 0:
if P.coun... | N = int(eval(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[... | p03625 |
import collections
N = int(eval(input()))
A = sorted(list(map(int,input().split())), reverse = True)
edge = []
for i in range(N):
a = A[i]
if A.count(a) >= 2 and a not in edge:
edge.append(a)
if len(edge) == 2:
print((edge[0]*edge[1]))
exit()
if A.c... | import collections
N = int(eval(input()))
A = list(map(int,input().split()))
B = collections.Counter(A)
C = []
for a,c in list(B.items()):
C += [a] * (c//2)
C.sort()
if len(C) >= 2:
print((C[-1]*C[-2]))
else:
print((0))
| p03625 |
from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))
d = defaultdict(int)
for i in A:
d[i] += 1
d = [x for x in list(d.items()) if x[1]>=2]
ans = 0
for i1,j1 in d:
for i2,j2 in d:
if j1 >= 2 and j2 >= 2 and i1 != i2:
ans = max(ans,i1*i2)... | N = int(eval(input()))
a = list(map(int, input().split()))
a.sort(reverse=True)
b = []
i = 0
while i+1<N:
if len(b)==2:
break
if a[i] == a[i+1]:
b += [a[i]]
i += 2
else:
i += 1
if len(b)<2:
print((0))
else:
print((b[0]*b[1])) | p03625 |
from collections import Counter
N = int(eval(input()))
A = list(map(int,input().split()))
C = sorted(Counter(A).most_common(),reverse=True)
D = list([x for x in C if x[1]>=2])
if len(D)<2:
print((0))
else:
print((D[0][0]**2 if D[0][1]>=4 else D[0][0]*D[1][0])) | N = int(eval(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:
... | p03625 |
from itertools import combinations
n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
a = [i for i in a if a.count(i) > 1]
b = [j for j in a if a.count(j) > 3]
a = set(a)
b = set(b)
a -= b
a = list(a)
b = list(b)
for v in combinations(a, 2):
ans = max(ans, v[0] * v[1])
for s in rang... | n = int(eval(input()))
a = list(map(int, input().split()))
d = {}
for x in a:
d[x] = d.get(x, 0) + 1
l = []
ans = 0
for num, cnt in sorted(list(d.items()), key=lambda x: x[0], reverse=True):
if cnt > 3:
if len(l) == 0:
ans = num ** 2
print(ans)
exit()
... | p03625 |
from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
c = Counter()
for a in A:
c[a] += 1
candidate = []
for k, v in c.most_common():
if v >= 4:
candidate.append(k)
candidate.append(k)
elif v >= 2:
candidate.append(k)
candidate.sort()... | N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
res = A[0]
cnt = 1
use = []
for i in range(1, N):
if A[i] == res:
cnt += 1
else:
cnt = 1
res = A[i]
if cnt >= 2:
use.append(A[i])
cnt -= 2
if len(use) >= 2:
... | p03625 |
def main():
N = int(input())
A = [int(i) for i in input().split()]
from collections import Counter
c = Counter(A)
li = [(k, v) for k, v in c.items() if v >= 2]
li.sort(reverse=True)
if li and li[0][1] >= 4:
return print(li[0][0] * li[0][0])
elif len(li) <= 1:
re... | def main():
_ = int(eval(input()))
A = [int(i) for i in input().split()]
from collections import Counter
c = Counter(A)
li = [(k, v) for k, v in list(c.items()) if v >= 2]
li.sort(reverse=True)
if li and li[0][1] >= 4:
print((li[0][0] * li[0][0]))
elif len(li) <= 1:
... | p03625 |
from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
counter = sorted(
list(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((l... | from collections import Counter
n = int(eval(input()))
A = list(map(int, input().split()))
# 長さと個数の辞書
length_num = Counter(A)
# 長い順からの長さのリスト
lengths = sorted(list(length_num.keys()), reverse=True)
ans = 0
sides = []
# 長い辺の順にループ
for l in lengths:
if length_num[l] >= 4:
ans = max(ans, l * l)
... | p03625 |
def main():
N = int(eval(input()))
a = [int(i) for i in input().split()]
area = 0
u_len = []
#sort_a = sorted(set(a), reverse=True)
#print(sort_a)
max_num = max(a)
for num in range(max_num, 0, -1):
#print(num)
c_num = a.count(num)
if(c_num >= 4):
... | def main():
N = int(eval(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:
... | p03625 |
n = int(eval(input()))
a = list(map(int,input().split()))
a.sort(reverse=True)
ans=[]
i=0
while i<n-1:
if a[i]==a[i+1]:
ans.append(a[i])
i+=1
i+=1
if len(ans) >= 2:
print((ans[0]*ans[1]))
else:
print((0)) | n = int(eval(input()))
a = list(map(int,input().split()))
a.sort(reverse=True)
flag=True
for i in range(0,n-4+1):
if a[i]==a[i+1]:
for j in range(i+2,n-1+1):
if a[j]==a[j+1]:
print((a[i]*a[j]))
flag=False
break
break
if flag:
... | p03625 |
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
n = int(eval(input()))
a = list(map(int,input().split()))
x = [0 for i in range(max(a)+1)]
for i in range(n):
x[a[i]]+=1
li2 = [0]
li4 = [0]
for i in ran... | import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
n = int(eval(input()))
a = list(map(int,input().split()))
c = collections.Counter(a)
li2 = [0,0]
li4 = [0]
for key,value in list(c.items()):
if value>=4:
... | p03625 |
# ABC071-C
N = int(eval(input()))
A_list = list(map(int, input().split()))
A_set = sorted(set(A_list), reverse = True)
side_list = [0, 0]
for i in range(len(A_set)): # 大きい順に取っていき,リストで個数を確認する
if len(side_list) >= 4:
break
count = A_list.count(A_set[i]) # リストの個数を確認
if count == 2 o... | # ABC071-C
N = int(eval(input()))
A = sorted(list(map(int, input().split())), reverse = True)
for i in range(N-1):
if A[i] == A[i+1]:
A[i+1] = 0
elif A[i] != A[i+1]:
A[i] = 0
A.sort(reverse = True)
print((A[0] * A[1])) | p03625 |
n = int(eval(input()))
list1 = [int(x) for x in input().split()]
set1 = set(list1)
listans = []
for i in set1:
if list1.count(i) > 1 and list1.count(i) < 4:
listans.append(i)
elif list1.count(i) >3:
listans.append(i)
listans.append(i)
if len(listans) < 2:
print((0))
else:
... | n = int(eval(input()))
list1 = [int(x) for x in input().split()]
list2 = list(reversed(sorted(list1)))
fflag = 0
ans = []
for i in range(len(list2) - 1):
if fflag ==0:
if list2[i] == list2[i + 1]:
ans.append(list2[i])
fflag = 1
elif fflag == 1:
fflag = 0
continue
if len(ans)... | p03625 |
from collections import Counter
import sys
n = int(eval(input()))
a = list(map(int, input().split()))
count_a = list(Counter(a).items())
count_a = sorted(count_a, reverse=True)
result = 1
c = 0
for x, y in count_a:
if y>=2:
result *= x
c += 1
if y>=4 and c == 1:
resu... | from collections import Counter
import sys
n = int(eval(input()))
a = list(map(int, input().split()))
count_a = list(Counter(a).items())
count_a = sorted(count_a, reverse=True)
result = 1
c = 0
for x, y in count_a:
if y>=2:
result *= x
c += 1
if c == 1 and y>=4:
resu... | p03625 |
#!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
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): r... | #!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(... | p03625 |
import math
import calendar
import fractions
import itertools
n = int(eval(input()))
a = list(map(int, input().split()))
b = sorted(set(a))[::-1]
ans = 1
cnt = 0
for i in b:
if cnt == 2:
break
if a.count(i) < 2:
continue
if cnt == 1:
ans *= i
cnt += 1
... | import math
import calendar
import fractions
import itertools
n = int(eval(input()))
a = sorted(map(int, input().split()), reverse=True)
h = 0
w = 0
index = -1
for i in range(n - 3):
if a[i] == a[i + 1]:
h = a[i]
index = i + 2
break
for i in range(index, n - 1):
if a[i... | p03625 |
from collections import Counter
N = int(eval(input()))
A = [int(x) for x in input().split()]
c = Counter(A)
ans = []
for k, v in sorted(list(c.items()), reverse=True):
if v > 3 and len(ans) == 0:
ans.append(k)
ans.append(k)
elif v > 1:
ans.append(k)
if len(ans) == 2:
... | from collections import Counter
N = int(eval(input()))
A = [int(x) for x in input().split()]
ans = []
for k, v in sorted(list(Counter(A).items()), reverse=True):
if v >= 4:
ans.append(k)
ans.append(k)
elif v >= 2:
ans.append(k)
if len(ans) >= 2:
break
if len(a... | p03625 |
import sys
line = sys.stdin.readline
n = int(line())
a = list(map(int, line().split()))
l = [0 for i in range(max(a)+1)]
for i in a: l[i] += 1
l.reverse()
h = 0
for i in range(len(l)):
if l[i] > 4:
print((l[i]))
sys.exit()
if l[i] >= 2 and h:
print(((len(l) - 1 - i) * h))
... | import sys
line = sys.stdin.readline
n = int(line())
a = list(map(int, line().split()))
a.sort(reverse=True)
summ = 0
h = 0
for i in range(len(a)):
summ += 1
if i and a[i] != a[i-1]:
summ = 1
if summ == 2:
if h:
print((a[i] * h))
sys.exit()
el... | p03625 |
def makerectangle(n , a):
listmax = []
a.sort(reverse=True)
for i in range(n):
if a.count(a[i]) > 1 and listmax.count(a[i]) == 0:
if a.count(a[i]) > 3 and len(listmax) == 0:
return a[i] * a[i]
else:
listmax.append(a[i])
if le... | def makerectangle(n , a):
listmax = []
a.sort(reverse=True)
for i in range(n):
if len(a) > i + 1 and a[i] == a[i + 1] and listmax.count(a[i]) == 0:
if len(a) > i + 3 and a[i] == a[i + 3] and len(listmax) == 0:
return a[i] * a[i]
else:
... | p03625 |
import collections
N = int(eval(input()))
A = collections.Counter(list(map(int, input().split())))
seihou = []
tyouhou = []
ans = 0
for i in list(A.keys()):
if A[i] >= 2:
tyouhou = tyouhou+[i]
if A[i] >= 4:
seihou = seihou+[i]
if len(seihou) >= 1:
ans = max(seihou)**2
if l... | import collections
N = int(eval(input()))
A = collections.Counter(list(map(int, input().split())))
seihou = []
tyouhou = []
ans = 0
for i in list(A.keys()):
if A[i] >= 2:
tyouhou.append(i)
if A[i] >= 4:
seihou.append(i)
if len(seihou) >= 1:
ans = max(seihou)**2
if len(tyou... | p03625 |
import collections
N = int(eval(input()))
A = [int(i) for i in input().split()]
con = collections.Counter(A).most_common()
ans = 0
for a, b in sorted(con, reverse= True):
if b >= 4 and ans == 0:
print((a**2))
break
elif b >= 2 and ans == 0:
ans = a
elif b >= 2:
... | import collections
N = int(eval(input()))
A = [int(i) for i in input().split()]
dic = collections.Counter(A).most_common()
tmp = []
check = 0
dic.sort(reverse=True)
for a, b in dic:
if b >= 2:
check += 1
tmp.append(a)
if b>= 4:
break
if check == 2:
... | p03625 |
n = int(eval(input()))
a = list(map(int, input().split()))
aset = set(a)
aset = sorted(aset, reverse = True)
res = 0
for i in aset:
count = a.count(i)
if count >= 4 and res == 0:
print((i*i))
exit()
elif count >= 2 and res == 0:
res = i
elif count >= 2:
print... | n = int(eval(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(list(d.items()), reverse = True):
if i >= 4 and res == 0:
print((k*k))
exit()
elif i >= 2 and res == 0:
res = k
... | p03625 |
n = int(eval(input()))
*l, = list(map(int,input().split()))
rect = [i for i in set(l) if l.count(i)>=2]
squ = [i for i in rect if l.count(i)>=4]
rect.sort()
squ.sort()
if len(rect)>=2:
srect = rect[-1]*rect[-2]
else:
srect = 0
if len(squ)>=1:
ssqu=squ[-1]**2
else:
ssqu=0
print((max([srect,ssqu])))... | n = int(eval(input()))
l = list(map(int,input().split()))
l.sort()
l.reverse()
squ = 0
rec = []
count = 0
tmp = 0
for i in l:
if i == tmp:
count += 1
else:
tmp = i
count = 1
if count == 2:
rec.append(tmp)
elif count == 4:
squ = max([squ,tmp])
if len(rec)<2:
print((... | p03625 |
N = int(eval(input()))
A = list(map(int, input().split()))
A = sorted(A, reverse=True)
n4 = []
n2 = set()
for a in A:
if A.count(a) >= 4:
if len(n4) >= 1:
break
n4.append(a)
elif A.count(a) >= 2:
if len(n2) >= 2:
break
n2.add(a)
n2 = list(n... | N = int(eval(input()))
A = list(map(int, input().split()))
A = sorted(A, reverse=True)
kouho = set()
for i in range(N):
if i == 0:
continue
elif A[i-1] == A[i]:
kouho.add(A[i])
if A.count(A[i]) >= 4 or len(kouho) >= 2:
break
else:
ans = 0
kouho = list(kou... | p03625 |
N = int(eval(input()))
A = list(map(int, input().split(' ')))
x = 0
y = 0
S = []
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.append(a)
print((x*y))... | N = int(eval(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))... | p03625 |
n = int(eval(input()))
a = [int(_) for _ in input().split()]
a_sorted = sorted(a, reverse=True)
x = 0
y = 0
while True:
if len(a_sorted) == 0:
break
max = a_sorted[0]
if x != 0 and y != 0:
break
if a_sorted.count(max) >= 2:
if x == 0:
x = max
... | n = int(eval(input()))
a = [int(_) for _ in input().split()]
a_sorted = sorted(a, reverse=True)
x = 0
y = 0
while True:
if len(a_sorted) <= 1:
break
max = a_sorted[0]
if x != 0 and y != 0:
break
if a_sorted[1] == max:
if x == 0:
x = max
else:... | p03625 |
def inpl():
return input().split()
n = int(eval(input()))
a = list(map(int, inpl()))
a = sorted(a, reverse=True)
ans = 1
cnt = 0
bf = a[0]
i = 1
while (i < n) and (cnt < 2):
a_i = a[i]
if bf == a_i:
ans *= a_i
bf = -1
cnt += 1
else:
bf = a_i
i += ... | n = int(eval(input()))
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
anss = []
t = -1
for i in range(n):
if t == a[i]:
anss.append(t)
t = -1
if len(anss) >= 2:
break
else:
t = a[i]
if len(anss) >= 2:
ans = 1
for x in anss:
... | p03625 |
import sys
N = int(eval(input()))
A = list(map(int, input().split()))
A = sorted([e for e in A if A.count(e) > 1], reverse = True)
c = None
for a in A:
if A.count(a) >= 2:
if c is not None:
print((c * a))
sys.exit()
c = a
A.remove(a)
A.remove(a)
print((0)... | import sys
N = int(eval(input()))
A = sorted(list(map(int, input().split())), reverse = True)
mstack = []
stack = [0]
for a in A:
if a == stack[-1]:
mstack.append(a)
stack.pop()
if len(mstack) >= 2:
print((mstack[-1] * mstack[-2]))
sys.exit()
else:... | p03625 |
n=int(eval(input()))
l=[int(i) for i in input().split()]
from collections import Counter
c=Counter(l)
ans=[]
for i in c:
if c[i]>=2:
ans=ans+[i]*(c[i]//2)
ans.sort(reverse=1)
if len(ans)<=1:
print((0))
else:
print((ans[0]*ans[1])) | n=int(input())
l=[int(i) for i in input().split()]
from collections import Counter
c=Counter(l)
ans=[]
for i in c:
if c[i]>=2:
ans=ans+[i]*(c[i]//2)
ans.sort(reverse=1)
if len(ans)<=1:
print((0))
else:
print((ans[0]*ans[1])) | p03625 |
n=int(eval(input()))
a=list(map(int,input().split()))
b=[]
max1=0;max2=0
for i in range(n-1):
for j in range(i+1,n):
if a[i]==a[j]:
if a[i]>max1:
max2=max1
max1=a[i]
elif a[i]>max2:
max2=a[i]
a[j]=0
break
print((max1*max2))
| n=int(eval(input()))
a=list(map(int,input().split()))
a.sort()
a.reverse()
max1=0;max2=0
count=0
for i in range(n-3):
if a[i]==a[i+1]:
max1=a[i]
a[i+1]=0
count=i+1
break
if count==0:
print((0))
exit()
for j in range(count,n-1):
if a[j]==a[j+1]:
max2=a[j]
break
print((m... | p03625 |
import sys
stdin = sys.stdin
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return... | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li(): return list(map(int, stdin.readline().split()))
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return list(map(float, stdin.readline().split()))
def ls(): return stdin.readline().split()
def ns(): return stdin.re... | p03625 |
N = int(eval(input()))
arr = list(map(int,input().split()))
arr = sorted(arr,reverse=True)
to_multiply = []
while len(to_multiply) < 2 and len(arr) > 1:
if arr[0] == arr[1]:
to_multiply.append(arr[0])
arr = arr[2:]
if len(to_multiply) == 2:
print((to_multiply[0] * to_multiply[1]))
else... | N = int(eval(input()))
freq = {}
arr = list(map(int,input().split()))
for i in arr:
try:
freq[i] += 1
except KeyError:
freq[i] = 1
to_multiply = []
for i in sorted(list(freq.keys()),reverse=True):
if freq[i] >= 4:
to_multiply.append(i)
to_multiply.append(i... | p03625 |
from collections import Counter
n = eval(input())
bou = list(map(int,input().split()))
bous = Counter(bou)
hen = []
ans = -1
i = 0
while(i<2):
if len(bous) == 0:
ans = 0
break
mkey = max(bous.keys())
if bous[mkey] > 3:
bous[mkey] = bous[mkey] - 2
hen... | n = int(eval(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:
... | p03625 |
n=int(eval(input()))
a=sorted(list(map(int,input().split())),reverse=True)
x,y=0,0
def groupby(a):
a2=[[a[0],1]]
for i in range(1,len(a)):
if a2[-1][0]==a[i]:
a2[-1][1]+=1
else:
a2.append([a[i],1])
return a2
b=groupby(a)
l=len(b)
for i in range(l):
i... | n =int(eval(input()))
a = list(map(int,input().split()))
a.sort()
x,y,i = 0,0,0
while i<n:
if a[i-1] == a[i]:
x,y = y,a[i]
i += 1
i += 1
print((x*y))
| p03625 |
from collections import*
n,*a=list(map(int,open(0).read().split()))
r=[];s=[]
for k,v in list(Counter(a).items()):
if v>1:
r+=[k]
if v>3:
s+=[k]
if len(r)<2 and len(s)<1:
print((0))
exit()
r+=[0,0]
s+=[0]
r.sort()
s.sort()
print((max(r[-1]*r[-2],s[-1]**2))) | from collections import*
n,*a=list(map(int,open(0).read().split()))
r=[0,0];s=[0]
for k,v in list(Counter(a).items()):
if v>1:
r+=[k]
if v>3:
s+=[k]
r.sort();s.sort()
print((max(r[-1]*r[-2],s[-1]**2))) | p03625 |
N = int(eval(input()))
A = list(map(int, input().split()))
import collections
ans = 0
c = collections.Counter(A)
lis = []
for k,v in list(c.items()):
if v>=2:
lis.append(k)
if v>=4:
lis.append(k)
if len(lis)>=2:
lis.sort()
ans = lis[-1]*lis[-2]
print(ans)
#print(*ans, sep='\n')
| from collections import Counter
def solve():
ans = 0
N = int(eval(input()))
A = list(map(int, input().split()))
C = Counter(A)
D = [[0,0],[0,0]]
for k,v in list(C.items()):
if v>=2:
D.append([k,v])
D.sort(reverse=True)
if D[0][1]>=4:
return D[0][0]... | p03625 |
n=int(eval(input()))
a=list(map(int,input().split()))
b=[]
for i in a:
if a.count(i)>=2:
b.append(i)
b=sorted(b,reverse=True)
if len(b)<=1:
print((0))
elif b.count(b[0])>=4:
print((b[0]*2))
else:
b=list(set(b))
b=sorted(b,reverse=True)
print((b[0]*b[1])) | n=int(eval(input()))
a=sorted(list(map(int,input().split())),reverse=True)
h,w,i=0,0,0
while i<n-1:
if a[i]==a[i+1]:
if h==0:
h=a[i]
i+=1 #
else:
w=a[i]
break
i+=1
print((h*w)) | p03625 |
import collections
n = int(eval(input()))
a = [int(i) for i in input().split()]
a.sort()
a = a[::-1]
x,answer,num = collections.Counter(a),1,-1
while a != []:
if x[a[0]]>=4 and num==-1:
print((a[0]**2))
break
elif x[a[0]]>=2:
answer *= a[0]
num += 1
if num==1:
print(answer)
break
a = ... | import collections
n = int(eval(input()))
a = [int(i) for i in input().split()]
x,y,z = collections.Counter(a),[0],[0,0]
for i in list(x.keys()):
if x[i]>=4:
y.append(i)
if x[i]>=2:
z.append(i)
y,z = sorted(y),sorted(z)
print((max(y[-1]**2,z[-1]*z[-2]))) | p03625 |
r = int(eval(input()))
stick = [int(v) for v in input().split()]
stick = sorted(stick, reverse=True)
s_stick = sorted(set(stick), reverse=True)
line = []
for v in s_stick:
if stick.count(v) >= 4:
if len(line) == 0:
print((v * v))
exit()
else:
prin... | def main2():
r = int(eval(input()))
stick = [int(v) for v in input().split()]
stick = sorted(stick, reverse=True)
line = []
tmp = -1
for i in range(0, len(stick), 1):
if tmp == stick[i]:
line.append(stick[i])
tmp = -1
else:
tmp =... | p03625 |
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
s1 = 0
s2 = 0
t = -1
for a in A:
if a != t:
ac = A.count(a)
if ac >= 4:
s1 = a
s2 = a
elif ac >= 2:
s2 = s1
s1 = a
t = a
print((s1 * s2))
| N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
s1 = 0
s2 = 0
at = -1
atc = 0
for a in A:
if at == a:
atc += 1
else:
if atc >= 4:
s1 = at
s2 = at
elif atc >= 2:
s2 = s1
s1 = at
... | p03625 |
N = int(eval(input()))
A = list(map(int,input().split()))
B = sorted([a for a in set(A) if 2<=A.count(a)])[::-1]
x = 0
y = 0
for b in B:
if x==0:
if 4<=A.count(b):
x = b
y = b
elif 2<=A.count(b):
x = b
else:
if 2<=A.count(b):
y = b
if x*y!=0:
break
pr... | N = int(eval(input()))
A = sorted(list(map(int,input().split())))[::-1]
for n in range(N-1):
if A[n]==A[n+1]:
A[n+1]=0
else:
A[n]=0
A = sorted(A)[::-1]
print((A[0]*A[1])) | p03625 |
eval(input())
xs = list(map(int, input().split()))
d = dict()
for x in xs:
if x in list(d.keys()):
d[x] += 1
else:
d[x] = 1
res = 0
for x, c1 in list(d.items()):
if c1 >= 4:
if res < x * x: res = x * x
for y, c2 in list(d.items()):
if x != y and c1 >= 2... |
eval(input())
xs = list(map(int, input().split()))
d = dict()
for x in xs:
if x in list(d.keys()):
d[x] += 1
else:
d[x] = 1
res = 0
for x, c1 in list(d.items()):
if c1 >= 4:
if res < x * x: res = x * x
v = sorted(list([s[0] for s in ([x for x in list(d.items()) if... | p03625 |
from collections import deque
n = int(eval(input()))
a = list(map(int, input().split()))
b = sorted(set(a), reverse=True)
c = deque([])
for i in b:
if a.count(i) >= 4 and c == deque([]):
print((i*i))
exit(0)
elif a.count(i) >= 2:
c.append(i)
if len(c)==2:
... | from collections import Counter, deque
n = int(eval(input()))
a = list(map(int, input().split()))
b = Counter(a)
c = deque([])
for k in list(b.keys()):
if b[k]>=4:
c.append(k)
c.append(k)
elif b[k]>=2:
c.append(k)
c = sorted(c, reverse = True)
print((c[0]*c[1] if c else 0)) | p03625 |
N = int(eval(input()))
A = list(map(int,input().split()))
import collections
a = collections.Counter(A)
b = []
for i in range(len(a)):
if a.most_common()[i][1] >= 2:
b.append(a.most_common()[i])
else:
break
b.sort()
if len(b) >= 1 and b[-1][1] >= 4:
print((b[-1][0] ** 2))
elif l... | N = int(eval(input()))
A = list(map(int,input().split()))
import collections
a = collections.Counter(A)
b = []
for i, j in list(a.items()):
if j >= 2:
b.append([i,j])
b.sort(reverse=True)
if len(b) >= 1 and b[0][1] >= 4:
print((b[0][0] ** 2))
elif len(b) >= 2:
print((b[0][0] * b[1][0]))
... | p03625 |
from collections import defaultdict
n = int(eval(input()))
a_list = [int(x) for x in input().split()]
d = defaultdict(int)
for a in a_list:
d[a] += 1
temp_list = sorted([(k, v) for k, v in list(d.items()) if v >= 2], reverse=True)
if len(temp_list) >= 2:
print((temp_list[0][0] ** 2 if temp_list[0][1] >=... | n = int(eval(input()))
a_list = sorted([int(x) for x in input().split()], reverse=True)
ans = 0
temp = 0
count = 0
e = None
for i in range(n):
if a_list[i] == temp:
count += 1
if count == 2:
if e is None:
e = temp
count -= 2
else:
... | p03625 |
n=eval(input())
temp=[]
l=[int(x) for x in input().split()]
for x in l:
if x not in temp:
y=l.count(x)
if y>3:
temp.append(x)
if(y>1):
temp.append(x)
if len(temp)<2:
print((0))
else:
x=max(temp)
temp.remove(x)
print((x*max(temp)))
| n=int(eval(input()))
a=[int(x) for x in input().split()]
a.sort()
lar=sec=i=0
while(i<n-1):
if a[i]==a[i+1]:
i+=1
if a[i]>lar:
sec=lar
lar=a[i]
elif a[i]>sec:
sec=a[i]
i+=1
print((lar*sec))
| p03625 |
n = int(eval(input()))
sList = list(map(int,input().split()))
sEdit = sorted(list(set(sList)),reverse=True)
res = 0
for i in sEdit:
dcount = sList.count(i)//2
if dcount >= 2 and res == 0:
print((i*i))
exit(0)
elif dcount >= 1 and res == 0:
res = i
elif dcount >= 1 and res != 0:
pri... | n = int(eval(input()))
sList = sorted(list(map(int,input().split())),reverse=True)
res = []
acc = False
for i in range(n-1):
if acc:
acc = False
else:
if sList[i] == sList[i+1]:
res.append(sList[i])
acc = True
if len(res) == 2:
print((res[0]*res[1]))
ex... | p03625 |
n = int(eval(input()))
a = list(input().split())
num_list = []
for i in range(len(a)-1):
for j in range(i+1, len(a)):
if a[i] == a[j] and int(a[i]) not in num_list:
num_list.append(int(a[i]))
break
if len(num_list) < 2:
print("0")
else:
num_list.sort()
pri... | n = int(eval(input()))
a_in = list(input().split())
a = list(map(int,a_in))
a.sort(reverse=True)
ans = 0
t = 0
c = 1
for i in range(n-1):
if a[i] == a[i+1]:
c = c + 1
if t == 0:
t = int(a[i])
elif t != int(a[i]):
ans = t * int(a[i])
break
... | p03625 |
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
from collections import Counter
c = Counter(A)
w = 0
h = 0
for k, v in sorted(list(c.items()), key=lambda x: -x[0]):
if v < 2:
continue
if v >= 4:
if w == 0:
w = h = k
break
else:
... | N = int(eval(input()))
A = sorted(list(map(int, input().split())))
from collections import Counter
c = Counter(A)
w = 0
h = 0
for k, v in sorted(list(c.items()), key=lambda x: -x[0]):
if v >= 4:
if w == 0:
w = h = k
break
else:
h = k
br... | p03625 |
def 解():
iN = int(eval(input()))
iC = 0
d = {}
for a in reversed(sorted([int(_) for _ in input().split()])):
if a in d:
if d[a] == 3:
print((a*a))
exit()
elif iC and iC != a:
print((iC * a))
exit()... | def 解():
iN = int(eval(input()))
iNow = 0
iMem = 0
iC = 0
d = {}
for a in reversed(sorted([int(_) for _ in input().split()])):
if iNow == a:
iC += 1
else:
iC = 1
iNow = a
if iC == 2:
if iMem :
p... | p03625 |
def 解():
iN = int(eval(input()))
iNow = 0
iMem = 0
iC = 0
d = {}
for a in reversed(sorted([int(_) for _ in input().split()])):
if iNow == a:
iC += 1
else:
iC = 1
iNow = a
if iC == 2:
if iMem :
p... | def 解():
iN = int(eval(input()))
m2_2 = 0 #複数あるものの二つ目
m2 = 0 #複数あるもので最大
m3 = 0 #3個あるもので最大
m4 = 0 #4個あるもので最大
d = set()
for a in [int(_) for _ in input().split()]:
if a in d:
if m2 < a :
m2_2 = m2
m2 = a
elif m2 == a ... | p03625 |
N = int(eval(input()))
A = list(map(int,input().split()))
c = {a: A.count(a) for a in A if A.count(a) >= 2}
cc = sorted(c)
x = len(c)
if(x <= 1):
ans = 0
elif(c.get(cc[x-1]) >= 4):
ans = cc[x-1] * cc[x-1]
else:
ans = cc[x-1] * cc[x-2]
print(ans) | N = int(eval(input()))
A = list(map(int,input().split()))
d = {}
for a in A:
if(a in d):
d[a] += 1
else:
d[a] = 1
x, y = 0, 0
for k, v in list(d.items()):
if(v >= 2 and k > y):
if(k >= x):
if(v >= 4):
y = k
else:
y = x
x = k
else:
y = k
pr... | p03625 |
n = int(eval(input()))
a = list(map(int,input().split()))
a.sort(reverse=True)
d = {}
ans = []
for i in range(n):
if a[i] in list(d.keys()):
d[a[i]] += 1
else:
d[a[i]] = 1
if d[a[i]]==4:
ans.append(a[i])
elif d[a[i]]==2:
ans.append(a[i])
if len(ans)> 1:
... | n = int(eval(input()))
a = list(map(int,input().split()))
a.sort(reverse=True)
d = 0
ans = []
ap = 0
for i in range(n):
if ap == a[i]:
d += 1
if d == 2:
ans.append(a[i])
elif d == 4:
ans.append(a[i])
else:
d = 1
ap = a[i]
if... | p03625 |
# -*- coding: utf-8 -*-
from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
c = Counter(a)
li = sorted(list(c.items()), key=lambda x: x[0], reverse=True)
cands = []
for num, cnt in li:
if cnt >= 4:
cands += [num, num]
elif cnt >= 2:
cands... | # -*- coding: utf-8 -*-
from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
pair = [0, 0]
c = Counter(a)
for num, cnt in list(c.items()):
pair += [num] * (cnt // 2)
pair.sort(reverse=True)
ans = pair[0] * pair[1]
print(ans)
| p03625 |
n = int(eval(input()))
a_list = list(map(int, input().split()))
nums = list(set(a_list))
nums.sort(reverse=True)
a = 0
b = 0
for num in nums:
count = a_list.count(num)
if count > 1:
if a == 0:
a = num
if count > 3:
b = num
break
else:
b = num
break
r = a * b
print(r) | n = int(eval(input()))
a_list = list(map(int, input().split()))
counts = {}
for a in a_list:
if a in counts:
counts[a] += 1
else:
counts[a] = 1
counts = sorted(list(counts.items()), reverse=True, key=lambda x: x[0])
a = 0
b = 0
for key, value in counts:
if value > 1:
if a == 0:
a = key
if ... | p03625 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.