user_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| language
stringclasses 1
value | submission_id_v0
stringlengths 10
10
| submission_id_v1
stringlengths 10
10
| cpu_time_v0
int64 10
38.3k
| cpu_time_v1
int64 0
24.7k
| memory_v0
int64 2.57k
1.02M
| memory_v1
int64 2.57k
869k
| status_v0
stringclasses 1
value | status_v1
stringclasses 1
value | improvement_frac
float64 7.51
100
| input
stringlengths 20
4.55k
| target
stringlengths 17
3.34k
| code_v0_loc
int64 1
148
| code_v1_loc
int64 1
184
| code_v0_num_chars
int64 13
4.55k
| code_v1_num_chars
int64 14
3.34k
| code_v0_no_empty_lines
stringlengths 21
6.88k
| code_v1_no_empty_lines
stringlengths 20
4.93k
| code_same
bool 1
class | relative_loc_diff_percent
float64 0
79.8
| diff
sequence | diff_only_import_comment
bool 1
class | measured_runtime_v0
float64 0.01
4.45
| measured_runtime_v1
float64 0.01
4.31
| runtime_lift
float64 0
359
| key
sequence |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u636684559 | p02861 | python | s689028640 | s912985357 | 219 | 112 | 4,404 | 3,444 | Accepted | Accepted | 48.86 | import math
def calc(now,points,length,M,ans):
if len(points)==0:
#print(length).
ans.append(length)
return 0
for i in range(len(points)):
#print(points,points[:i]+points[i+1:])
tmp=length + math.sqrt( ((now[0]-M[points[i]][0])**2) + ((now[1]-M[points[i]][1])**2) )
#print(tmp)
#return length + calc(M[points[i]],points[:i]+points[i+1:],tmp,M)
calc(M[points[i]],points[:i]+points[i+1:],tmp,M,ans)
n=int(eval(input()))
M=[]
for i in range(n):
M.append(list(map(int,input().split())))
ans=[]
points=[]
num=1
for i in range(n):
points.append(i)
num=num*(i+1)
for i in range(n):
#print(i,points[:i]+points[i+1:])
#ans.append(calc(M[i],points[:i]+points[i+1:],0.0,M))
calc(M[i],points[:i]+points[i+1:],0.0,M,ans)
#print(ans)
print((sum(ans)/num)) | import itertools
import math
N=int(eval(input()))
X=[]
Y=[]
dist=[ [ 0 for j in range(N) ] for i in range(N) ]
for n in range(N):
x,y=list(map(int,input().split()))
X.append(x)
Y.append(y)
for i in range(N):
for j in range(N):
dist[i][j]=math.sqrt( (X[i]-X[j])**2 + (Y[i]-Y[j])**2 )
l=[ i for i in range(N) ]
P=itertools.permutations(l,N)
ans=0
for p in P:
p=list(p)
for i in range(N-1):
ans+=dist[p[i]][p[i+1]]
print((ans/math.factorial(N))) | 28 | 24 | 808 | 474 | import math
def calc(now, points, length, M, ans):
if len(points) == 0:
# print(length).
ans.append(length)
return 0
for i in range(len(points)):
# print(points,points[:i]+points[i+1:])
tmp = length + math.sqrt(
((now[0] - M[points[i]][0]) ** 2) + ((now[1] - M[points[i]][1]) ** 2)
)
# print(tmp)
# return length + calc(M[points[i]],points[:i]+points[i+1:],tmp,M)
calc(M[points[i]], points[:i] + points[i + 1 :], tmp, M, ans)
n = int(eval(input()))
M = []
for i in range(n):
M.append(list(map(int, input().split())))
ans = []
points = []
num = 1
for i in range(n):
points.append(i)
num = num * (i + 1)
for i in range(n):
# print(i,points[:i]+points[i+1:])
# ans.append(calc(M[i],points[:i]+points[i+1:],0.0,M))
calc(M[i], points[:i] + points[i + 1 :], 0.0, M, ans)
# print(ans)
print((sum(ans) / num))
| import itertools
import math
N = int(eval(input()))
X = []
Y = []
dist = [[0 for j in range(N)] for i in range(N)]
for n in range(N):
x, y = list(map(int, input().split()))
X.append(x)
Y.append(y)
for i in range(N):
for j in range(N):
dist[i][j] = math.sqrt((X[i] - X[j]) ** 2 + (Y[i] - Y[j]) ** 2)
l = [i for i in range(N)]
P = itertools.permutations(l, N)
ans = 0
for p in P:
p = list(p)
for i in range(N - 1):
ans += dist[p[i]][p[i + 1]]
print((ans / math.factorial(N)))
| false | 14.285714 | [
"+import itertools",
"-",
"-def calc(now, points, length, M, ans):",
"- if len(points) == 0:",
"- # print(length).",
"- ans.append(length)",
"- return 0",
"- for i in range(len(points)):",
"- # print(points,points[:i]+points[i+1:])",
"- tmp = length + math.sqrt(",
"- ((now[0] - M[points[i]][0]) ** 2) + ((now[1] - M[points[i]][1]) ** 2)",
"- )",
"- # print(tmp)",
"- # return length + calc(M[points[i]],points[:i]+points[i+1:],tmp,M)",
"- calc(M[points[i]], points[:i] + points[i + 1 :], tmp, M, ans)",
"-",
"-",
"-n = int(eval(input()))",
"-M = []",
"-for i in range(n):",
"- M.append(list(map(int, input().split())))",
"-ans = []",
"-points = []",
"-num = 1",
"-for i in range(n):",
"- points.append(i)",
"- num = num * (i + 1)",
"-for i in range(n):",
"- # print(i,points[:i]+points[i+1:])",
"- # ans.append(calc(M[i],points[:i]+points[i+1:],0.0,M))",
"- calc(M[i], points[:i] + points[i + 1 :], 0.0, M, ans)",
"-# print(ans)",
"-print((sum(ans) / num))",
"+N = int(eval(input()))",
"+X = []",
"+Y = []",
"+dist = [[0 for j in range(N)] for i in range(N)]",
"+for n in range(N):",
"+ x, y = list(map(int, input().split()))",
"+ X.append(x)",
"+ Y.append(y)",
"+for i in range(N):",
"+ for j in range(N):",
"+ dist[i][j] = math.sqrt((X[i] - X[j]) ** 2 + (Y[i] - Y[j]) ** 2)",
"+l = [i for i in range(N)]",
"+P = itertools.permutations(l, N)",
"+ans = 0",
"+for p in P:",
"+ p = list(p)",
"+ for i in range(N - 1):",
"+ ans += dist[p[i]][p[i + 1]]",
"+print((ans / math.factorial(N)))"
] | false | 0.039684 | 0.038606 | 1.027922 | [
"s689028640",
"s912985357"
] |
u156815136 | p03624 | python | s577341855 | s881190384 | 44 | 39 | 10,272 | 10,296 | Accepted | Accepted | 11.36 | #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int,readline().split()))
def readTuples():
return tuple(map(int,readline().split()))
def I():
return int(readline())
ans = "abcdefghijklmnopqrstuvwxyz"
s = eval(input())
s = sorted(list(set(s)))
for v in ans:
flag = True
for j in range(len(s)):
if s[j] == v:
flag = False
if flag:
print(v)
exit()
print(None)
| #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int,readline().split()))
def readTuples():
return tuple(map(int,readline().split()))
def I():
return int(readline())
s = eval(input())
lis = "abcdefghijklmnopqrstuvwxyz"
for i in range(len(lis)):
if lis[i] in s:
pass
else:
print((lis[i]))
exit()
print('None')
| 50 | 49 | 1,186 | 1,147 | # from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations, permutations, accumulate, product # (string,3) 3回
# from collections import deque
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
# mod = 9982443453
# mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int, readline().split()))
def readTuples():
return tuple(map(int, readline().split()))
def I():
return int(readline())
ans = "abcdefghijklmnopqrstuvwxyz"
s = eval(input())
s = sorted(list(set(s)))
for v in ans:
flag = True
for j in range(len(s)):
if s[j] == v:
flag = False
if flag:
print(v)
exit()
print(None)
| # from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations, permutations, accumulate, product # (string,3) 3回
# from collections import deque
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
# mod = 9982443453
# mod = 998244353
INF = float("inf")
from sys import stdin
readline = stdin.readline
def readInts():
return list(map(int, readline().split()))
def readTuples():
return tuple(map(int, readline().split()))
def I():
return int(readline())
s = eval(input())
lis = "abcdefghijklmnopqrstuvwxyz"
for i in range(len(lis)):
if lis[i] in s:
pass
else:
print((lis[i]))
exit()
print("None")
| false | 2 | [
"-from fractions import gcd",
"+from math import gcd",
"+import heapq",
"+INF = float(\"inf\")",
"-ans = \"abcdefghijklmnopqrstuvwxyz\"",
"-s = sorted(list(set(s)))",
"-for v in ans:",
"- flag = True",
"- for j in range(len(s)):",
"- if s[j] == v:",
"- flag = False",
"- if flag:",
"- print(v)",
"+lis = \"abcdefghijklmnopqrstuvwxyz\"",
"+for i in range(len(lis)):",
"+ if lis[i] in s:",
"+ pass",
"+ else:",
"+ print((lis[i]))",
"-print(None)",
"+print(\"None\")"
] | false | 0.040034 | 0.0424 | 0.944202 | [
"s577341855",
"s881190384"
] |
u347640436 | p03457 | python | s295315048 | s039943483 | 580 | 413 | 60,376 | 27,300 | Accepted | Accepted | 28.79 | import sys
def main():
_int = int
n = int(eval(input()))
data = [[_int(e) for e in input().split()] for _ in range(n)]
t, x, y = 0, 0, 0
for d in data:
rt = d[0] - t - abs(x - d[1]) - abs(y - d[2])
if rt < 0 or rt & 1 == 1:
print('No')
sys.exit()
t, x, y = d
print('Yes')
main()
| from sys import exit
n = int(eval(input()))
data = [list(map(int, input().split())) for _ in range(n)]
t = 0
x = 0
y = 0
for d in data:
duration = d[0] - t
distance = abs(x - d[1]) + abs(y - d[2])
if (distance > duration) or ((duration - distance) % 2 == 1):
print('No')
exit()
t = d[0]
x = d[1]
y = d[2]
print('Yes')
| 14 | 16 | 322 | 347 | import sys
def main():
_int = int
n = int(eval(input()))
data = [[_int(e) for e in input().split()] for _ in range(n)]
t, x, y = 0, 0, 0
for d in data:
rt = d[0] - t - abs(x - d[1]) - abs(y - d[2])
if rt < 0 or rt & 1 == 1:
print("No")
sys.exit()
t, x, y = d
print("Yes")
main()
| from sys import exit
n = int(eval(input()))
data = [list(map(int, input().split())) for _ in range(n)]
t = 0
x = 0
y = 0
for d in data:
duration = d[0] - t
distance = abs(x - d[1]) + abs(y - d[2])
if (distance > duration) or ((duration - distance) % 2 == 1):
print("No")
exit()
t = d[0]
x = d[1]
y = d[2]
print("Yes")
| false | 12.5 | [
"-import sys",
"+from sys import exit",
"-",
"-def main():",
"- _int = int",
"- n = int(eval(input()))",
"- data = [[_int(e) for e in input().split()] for _ in range(n)]",
"- t, x, y = 0, 0, 0",
"- for d in data:",
"- rt = d[0] - t - abs(x - d[1]) - abs(y - d[2])",
"- if rt < 0 or rt & 1 == 1:",
"- print(\"No\")",
"- sys.exit()",
"- t, x, y = d",
"- print(\"Yes\")",
"-",
"-",
"-main()",
"+n = int(eval(input()))",
"+data = [list(map(int, input().split())) for _ in range(n)]",
"+t = 0",
"+x = 0",
"+y = 0",
"+for d in data:",
"+ duration = d[0] - t",
"+ distance = abs(x - d[1]) + abs(y - d[2])",
"+ if (distance > duration) or ((duration - distance) % 2 == 1):",
"+ print(\"No\")",
"+ exit()",
"+ t = d[0]",
"+ x = d[1]",
"+ y = d[2]",
"+print(\"Yes\")"
] | false | 0.041349 | 0.035928 | 1.150864 | [
"s295315048",
"s039943483"
] |
u203843959 | p02678 | python | s972187672 | s386782347 | 1,420 | 800 | 170,820 | 37,840 | Accepted | Accepted | 43.66 | N,M=list(map(int,input().split()))
import heapq
def dijkstra_heap(s):
#始点sから各頂点への最短距離
dist=[float("inf")]*size_v
used=[False]*size_v
dist[s]=0
used[s]=True
hq_edge=[]
for v,w,i in graph[s]:
heapq.heappush(hq_edge,(w,v,i))
while hq_edge:
min_w,min_v,i=heapq.heappop(hq_edge)
#まだ使われてない頂点の中から最小の距離のものを探す
if used[min_v]:
continue
dist[min_v]=min_w
used[min_v]=True
prev[min_v]=i
for v,w,i2 in graph[min_v]:
if not used[v]:
heapq.heappush(hq_edge,(min_w+w,v,i2))
return dist
ablist=[]
graph=[[] for _ in range(N+1)]
for i in range(M):
a,b=list(map(int,input().split()))
graph[a].append((b,1,i))
graph[b].append((a,1,i))
ablist.append((a,b))
#print(graph)
size_v=N+1
prev=[None]*size_v
dist=dijkstra_heap(1)
#print(dist)
#print(prev)
print("Yes")
for i in range(2,N+1):
prev_e=ablist[prev[i]]
if i==prev_e[0]:
print((prev_e[1]))
else:
print((prev_e[0]))
| N,M=list(map(int,input().split()))
graph=[[] for _ in range(N+1)]
for i in range(M):
a,b=list(map(int,input().split()))
graph[a].append(b)
graph[b].append(a)
#print(graph)
queue=[1]
d=0
dist=[-1]*(N+1)
while queue:
new_queue=set()
for q in queue:
if dist[q]!=-1:
continue
dist[q]=d
for v in graph[q]:
if dist[v]==-1:
new_queue.add(v)
queue=list(new_queue)
d+=1
#print(dist)
parent=[-1]*(N+1)
for i in range(1,N+1):
for v in graph[i]:
if dist[v]==dist[i]+1:
parent[v]=i
#print(parent)
print("Yes")
for i in range(2,N+1):
print((parent[i])) | 51 | 36 | 982 | 638 | N, M = list(map(int, input().split()))
import heapq
def dijkstra_heap(s):
# 始点sから各頂点への最短距離
dist = [float("inf")] * size_v
used = [False] * size_v
dist[s] = 0
used[s] = True
hq_edge = []
for v, w, i in graph[s]:
heapq.heappush(hq_edge, (w, v, i))
while hq_edge:
min_w, min_v, i = heapq.heappop(hq_edge)
# まだ使われてない頂点の中から最小の距離のものを探す
if used[min_v]:
continue
dist[min_v] = min_w
used[min_v] = True
prev[min_v] = i
for v, w, i2 in graph[min_v]:
if not used[v]:
heapq.heappush(hq_edge, (min_w + w, v, i2))
return dist
ablist = []
graph = [[] for _ in range(N + 1)]
for i in range(M):
a, b = list(map(int, input().split()))
graph[a].append((b, 1, i))
graph[b].append((a, 1, i))
ablist.append((a, b))
# print(graph)
size_v = N + 1
prev = [None] * size_v
dist = dijkstra_heap(1)
# print(dist)
# print(prev)
print("Yes")
for i in range(2, N + 1):
prev_e = ablist[prev[i]]
if i == prev_e[0]:
print((prev_e[1]))
else:
print((prev_e[0]))
| N, M = list(map(int, input().split()))
graph = [[] for _ in range(N + 1)]
for i in range(M):
a, b = list(map(int, input().split()))
graph[a].append(b)
graph[b].append(a)
# print(graph)
queue = [1]
d = 0
dist = [-1] * (N + 1)
while queue:
new_queue = set()
for q in queue:
if dist[q] != -1:
continue
dist[q] = d
for v in graph[q]:
if dist[v] == -1:
new_queue.add(v)
queue = list(new_queue)
d += 1
# print(dist)
parent = [-1] * (N + 1)
for i in range(1, N + 1):
for v in graph[i]:
if dist[v] == dist[i] + 1:
parent[v] = i
# print(parent)
print("Yes")
for i in range(2, N + 1):
print((parent[i]))
| false | 29.411765 | [
"-import heapq",
"-",
"-",
"-def dijkstra_heap(s):",
"- # 始点sから各頂点への最短距離",
"- dist = [float(\"inf\")] * size_v",
"- used = [False] * size_v",
"- dist[s] = 0",
"- used[s] = True",
"- hq_edge = []",
"- for v, w, i in graph[s]:",
"- heapq.heappush(hq_edge, (w, v, i))",
"- while hq_edge:",
"- min_w, min_v, i = heapq.heappop(hq_edge)",
"- # まだ使われてない頂点の中から最小の距離のものを探す",
"- if used[min_v]:",
"- continue",
"- dist[min_v] = min_w",
"- used[min_v] = True",
"- prev[min_v] = i",
"- for v, w, i2 in graph[min_v]:",
"- if not used[v]:",
"- heapq.heappush(hq_edge, (min_w + w, v, i2))",
"- return dist",
"-",
"-",
"-ablist = []",
"- graph[a].append((b, 1, i))",
"- graph[b].append((a, 1, i))",
"- ablist.append((a, b))",
"+ graph[a].append(b)",
"+ graph[b].append(a)",
"-size_v = N + 1",
"-prev = [None] * size_v",
"-dist = dijkstra_heap(1)",
"+queue = [1]",
"+d = 0",
"+dist = [-1] * (N + 1)",
"+while queue:",
"+ new_queue = set()",
"+ for q in queue:",
"+ if dist[q] != -1:",
"+ continue",
"+ dist[q] = d",
"+ for v in graph[q]:",
"+ if dist[v] == -1:",
"+ new_queue.add(v)",
"+ queue = list(new_queue)",
"+ d += 1",
"-# print(prev)",
"+parent = [-1] * (N + 1)",
"+for i in range(1, N + 1):",
"+ for v in graph[i]:",
"+ if dist[v] == dist[i] + 1:",
"+ parent[v] = i",
"+# print(parent)",
"- prev_e = ablist[prev[i]]",
"- if i == prev_e[0]:",
"- print((prev_e[1]))",
"- else:",
"- print((prev_e[0]))",
"+ print((parent[i]))"
] | false | 0.105526 | 0.037701 | 2.799047 | [
"s972187672",
"s386782347"
] |
u691018832 | p02918 | python | s230723110 | s509064063 | 49 | 35 | 3,316 | 3,380 | Accepted | Accepted | 28.57 | n, k = list(map(int, input().split()))
s = eval(input())
ans = n - 1
for i in range(1, n):
if s[i] != s[i - 1]:
ans -= 1
print((min(n - 1, ans + 2 * k)))
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
n, k = list(map(int, readline().split()))
s = read().rstrip().decode()
ans = n - 1
for bf, af in zip(s, s[1:]):
if bf != af:
ans -= 1
print((min(n - 1, ans + k * 2)))
| 7 | 13 | 158 | 331 | n, k = list(map(int, input().split()))
s = eval(input())
ans = n - 1
for i in range(1, n):
if s[i] != s[i - 1]:
ans -= 1
print((min(n - 1, ans + 2 * k)))
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
n, k = list(map(int, readline().split()))
s = read().rstrip().decode()
ans = n - 1
for bf, af in zip(s, s[1:]):
if bf != af:
ans -= 1
print((min(n - 1, ans + k * 2)))
| false | 46.153846 | [
"-n, k = list(map(int, input().split()))",
"-s = eval(input())",
"+import sys",
"+",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+sys.setrecursionlimit(10**7)",
"+n, k = list(map(int, readline().split()))",
"+s = read().rstrip().decode()",
"-for i in range(1, n):",
"- if s[i] != s[i - 1]:",
"+for bf, af in zip(s, s[1:]):",
"+ if bf != af:",
"-print((min(n - 1, ans + 2 * k)))",
"+print((min(n - 1, ans + k * 2)))"
] | false | 0.036597 | 0.036239 | 1.009881 | [
"s230723110",
"s509064063"
] |
u891635666 | p03148 | python | s552263258 | s227751052 | 462 | 367 | 41,720 | 37,132 | Accepted | Accepted | 20.56 | import collections
import heapq
import operator
import sys
input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]
n, k = ril()
ls = rils(n)
ls.sort(key=operator.itemgetter(1), reverse=True)
counter0 = collections.Counter()
counter1 = collections.Counter()
ls0 = []
ls1 = []
base = 0
for i, (t, d) in enumerate(ls):
if i < k:
if counter0[t] > 0:
heapq.heappush(ls0, (d, t))
counter0[t] += 1
base += d
else:
if t not in counter0 and t not in counter1:
heapq.heappush(ls1, (-d, t))
counter1[t] += 1
m = len(counter0)
res = base + m**2
for _ in range(k):
if len(ls0) == 0 or len(ls1) == 0:
break
d, _ = heapq.heappop(ls0)
base -= d
d, _ = heapq.heappop(ls1)
base += -d
m += 1
res = max(res, base + m**2)
print(res) | import heapq
import operator
import sys
input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]
n, k = ril()
ls = rils(n)
ls.sort(key=operator.itemgetter(1), reverse=True)
selected0 = set()
selected1 = set()
ls0 = []
ls1 = []
base = 0
for i, (t, d) in enumerate(ls):
if i < k:
if t in selected0:
heapq.heappush(ls0, (d, t))
selected0.add(t)
base += d
else:
if t not in selected0 and t not in selected1:
heapq.heappush(ls1, (-d, t))
selected1.add(t)
m = len(selected0)
res = base + m**2
for _ in range(k):
if len(ls0) == 0 or len(ls1) == 0:
break
d, _ = heapq.heappop(ls0)
base -= d
d, _ = heapq.heappop(ls1)
base += -d
m += 1
res = max(res, base + m**2)
print(res) | 48 | 47 | 1,155 | 1,107 | import collections
import heapq
import operator
import sys
input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]
n, k = ril()
ls = rils(n)
ls.sort(key=operator.itemgetter(1), reverse=True)
counter0 = collections.Counter()
counter1 = collections.Counter()
ls0 = []
ls1 = []
base = 0
for i, (t, d) in enumerate(ls):
if i < k:
if counter0[t] > 0:
heapq.heappush(ls0, (d, t))
counter0[t] += 1
base += d
else:
if t not in counter0 and t not in counter1:
heapq.heappush(ls1, (-d, t))
counter1[t] += 1
m = len(counter0)
res = base + m**2
for _ in range(k):
if len(ls0) == 0 or len(ls1) == 0:
break
d, _ = heapq.heappop(ls0)
base -= d
d, _ = heapq.heappop(ls1)
base += -d
m += 1
res = max(res, base + m**2)
print(res)
| import heapq
import operator
import sys
input = sys.stdin.readline
ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]
n, k = ril()
ls = rils(n)
ls.sort(key=operator.itemgetter(1), reverse=True)
selected0 = set()
selected1 = set()
ls0 = []
ls1 = []
base = 0
for i, (t, d) in enumerate(ls):
if i < k:
if t in selected0:
heapq.heappush(ls0, (d, t))
selected0.add(t)
base += d
else:
if t not in selected0 and t not in selected1:
heapq.heappush(ls1, (-d, t))
selected1.add(t)
m = len(selected0)
res = base + m**2
for _ in range(k):
if len(ls0) == 0 or len(ls1) == 0:
break
d, _ = heapq.heappop(ls0)
base -= d
d, _ = heapq.heappop(ls1)
base += -d
m += 1
res = max(res, base + m**2)
print(res)
| false | 2.083333 | [
"-import collections",
"-counter0 = collections.Counter()",
"-counter1 = collections.Counter()",
"+selected0 = set()",
"+selected1 = set()",
"- if counter0[t] > 0:",
"+ if t in selected0:",
"- counter0[t] += 1",
"+ selected0.add(t)",
"- if t not in counter0 and t not in counter1:",
"+ if t not in selected0 and t not in selected1:",
"- counter1[t] += 1",
"-m = len(counter0)",
"+ selected1.add(t)",
"+m = len(selected0)"
] | false | 0.043231 | 0.041593 | 1.039377 | [
"s552263258",
"s227751052"
] |
u333945892 | p03270 | python | s546178206 | s451247436 | 774 | 626 | 62,164 | 55,256 | Accepted | Accepted | 19.12 | from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 998244353
eps = 10**-7
def inp(): return int(eval(input()))
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
K,N = inpl()
MAX = K+N+10
fac = [1]*(MAX+1)
for i in range(1,MAX+1):
fac[i] = (fac[i-1]*i)%mod
gyakugen = [1]*(MAX+1)
gyakugen[MAX] = pow(fac[MAX],mod-2,mod)
for i in range(MAX,0,-1):
gyakugen[i-1] = (gyakugen[i]*i)%mod
def Comb(n,k):#nCk
return (fac[n]*gyakugen[k]*gyakugen[n-k])%mod
#K=k,N=n,0pair = 0
def calc(k,n,i):
#i=2に帰着させる
pairs = (i-2)//2
k -= pairs
n -= pairs
#色々と例外処理
if n < 0 or k <= 0:
return 0
elif k == 1 and n >= 2:
return 0
if n == 0: #球が0個なら1通り
ans = 1
else:
ans = 0
#i=2の時の数え上げ
for x in range(2):
ball = n-x #球
box = k-1 #箱
ans += Comb(box-1+ball,ball)%mod
ans *= pow(2,pairs,mod) #0pairの選び方
return ans % mod
ans = []
for i in range(2,K+2):
if i%2 == 0:
pairs = (i-2)//2
tmp = 0
for p0 in range(pairs+1): #p0 = 0pairの数
tmp1 = calc(K-p0*2 , N , i-p0*2) %mod #k-p0*2,i-p0*2で0pairが0組
tmp2 = Comb(pairs,p0) %mod #0pairの選び方
tmp += tmp1 * tmp2
tmp %= mod
ans.append(tmp)
print(tmp)
ans = ans[::-1]
for i in range(1,K):
print((ans[i]))
| K,N = list(map(int, input().split()))
MAX = K+N+3
mod = 998244353
fac = [1]*(MAX+1)
for i in range(1,MAX+1):
fac[i] = (fac[i-1]*i)%mod
rev_m = [1]*(MAX+1)
rev_m[MAX] = pow(fac[MAX],mod-2,mod)
for i in range(MAX,0,-1):
rev_m[i-1] = (rev_m[i]*i)%mod
def Comb(n,k):#nCk
return (fac[n]*rev_m[k]*rev_m[n-k])%mod
def f(n,k,i):
if i == 2:
if n < 0 or (k==1 and n>=2): #例外処理
return 0
if n == 0:
ans = 1
else:
ans = Comb(k-2+n,n) + Comb(k-2+n-1,n-1)
return ans % mod
else: #i>2
Sp = i//2-1
ans = 0
for p in range(Sp+1):
ans += g(n,k,i,p)
return ans % mod
def g(n,k,i,p):
Sp = i//2-1
if p == 0:
return f(n-Sp,k-Sp,2) * pow(2,Sp,mod) % mod
else: #p>0
return g(n,k-2*p,i-2*p,0) * Comb(Sp,p)
ans = []
for i in range(2,K+2):
if i%2 == 0:
tmp = f(N,K,i)
ans.append(tmp)
print(tmp)
ans = ans[::-1]
for i in range(1,K):
print((ans[i]))
| 66 | 51 | 1,384 | 922 | from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, datetime
sys.setrecursionlimit(10**8)
INF = float("inf")
mod = 998244353
eps = 10**-7
def inp():
return int(eval(input()))
def inpl():
return list(map(int, input().split()))
def inpls():
return list(input().split())
K, N = inpl()
MAX = K + N + 10
fac = [1] * (MAX + 1)
for i in range(1, MAX + 1):
fac[i] = (fac[i - 1] * i) % mod
gyakugen = [1] * (MAX + 1)
gyakugen[MAX] = pow(fac[MAX], mod - 2, mod)
for i in range(MAX, 0, -1):
gyakugen[i - 1] = (gyakugen[i] * i) % mod
def Comb(n, k): # nCk
return (fac[n] * gyakugen[k] * gyakugen[n - k]) % mod
# K=k,N=n,0pair = 0
def calc(k, n, i):
# i=2に帰着させる
pairs = (i - 2) // 2
k -= pairs
n -= pairs
# 色々と例外処理
if n < 0 or k <= 0:
return 0
elif k == 1 and n >= 2:
return 0
if n == 0: # 球が0個なら1通り
ans = 1
else:
ans = 0
# i=2の時の数え上げ
for x in range(2):
ball = n - x # 球
box = k - 1 # 箱
ans += Comb(box - 1 + ball, ball) % mod
ans *= pow(2, pairs, mod) # 0pairの選び方
return ans % mod
ans = []
for i in range(2, K + 2):
if i % 2 == 0:
pairs = (i - 2) // 2
tmp = 0
for p0 in range(pairs + 1): # p0 = 0pairの数
tmp1 = calc(K - p0 * 2, N, i - p0 * 2) % mod # k-p0*2,i-p0*2で0pairが0組
tmp2 = Comb(pairs, p0) % mod # 0pairの選び方
tmp += tmp1 * tmp2
tmp %= mod
ans.append(tmp)
print(tmp)
ans = ans[::-1]
for i in range(1, K):
print((ans[i]))
| K, N = list(map(int, input().split()))
MAX = K + N + 3
mod = 998244353
fac = [1] * (MAX + 1)
for i in range(1, MAX + 1):
fac[i] = (fac[i - 1] * i) % mod
rev_m = [1] * (MAX + 1)
rev_m[MAX] = pow(fac[MAX], mod - 2, mod)
for i in range(MAX, 0, -1):
rev_m[i - 1] = (rev_m[i] * i) % mod
def Comb(n, k): # nCk
return (fac[n] * rev_m[k] * rev_m[n - k]) % mod
def f(n, k, i):
if i == 2:
if n < 0 or (k == 1 and n >= 2): # 例外処理
return 0
if n == 0:
ans = 1
else:
ans = Comb(k - 2 + n, n) + Comb(k - 2 + n - 1, n - 1)
return ans % mod
else: # i>2
Sp = i // 2 - 1
ans = 0
for p in range(Sp + 1):
ans += g(n, k, i, p)
return ans % mod
def g(n, k, i, p):
Sp = i // 2 - 1
if p == 0:
return f(n - Sp, k - Sp, 2) * pow(2, Sp, mod) % mod
else: # p>0
return g(n, k - 2 * p, i - 2 * p, 0) * Comb(Sp, p)
ans = []
for i in range(2, K + 2):
if i % 2 == 0:
tmp = f(N, K, i)
ans.append(tmp)
print(tmp)
ans = ans[::-1]
for i in range(1, K):
print((ans[i]))
| false | 22.727273 | [
"-from collections import defaultdict, deque",
"-import sys, heapq, bisect, math, itertools, string, queue, datetime",
"-",
"-sys.setrecursionlimit(10**8)",
"-INF = float(\"inf\")",
"+K, N = list(map(int, input().split()))",
"+MAX = K + N + 3",
"-eps = 10**-7",
"-",
"-",
"-def inp():",
"- return int(eval(input()))",
"-",
"-",
"-def inpl():",
"- return list(map(int, input().split()))",
"-",
"-",
"-def inpls():",
"- return list(input().split())",
"-",
"-",
"-K, N = inpl()",
"-MAX = K + N + 10",
"-gyakugen = [1] * (MAX + 1)",
"-gyakugen[MAX] = pow(fac[MAX], mod - 2, mod)",
"+rev_m = [1] * (MAX + 1)",
"+rev_m[MAX] = pow(fac[MAX], mod - 2, mod)",
"- gyakugen[i - 1] = (gyakugen[i] * i) % mod",
"+ rev_m[i - 1] = (rev_m[i] * i) % mod",
"- return (fac[n] * gyakugen[k] * gyakugen[n - k]) % mod",
"+ return (fac[n] * rev_m[k] * rev_m[n - k]) % mod",
"-# K=k,N=n,0pair = 0",
"-def calc(k, n, i):",
"- # i=2に帰着させる",
"- pairs = (i - 2) // 2",
"- k -= pairs",
"- n -= pairs",
"- # 色々と例外処理",
"- if n < 0 or k <= 0:",
"- return 0",
"- elif k == 1 and n >= 2:",
"- return 0",
"- if n == 0: # 球が0個なら1通り",
"- ans = 1",
"- else:",
"+def f(n, k, i):",
"+ if i == 2:",
"+ if n < 0 or (k == 1 and n >= 2): # 例外処理",
"+ return 0",
"+ if n == 0:",
"+ ans = 1",
"+ else:",
"+ ans = Comb(k - 2 + n, n) + Comb(k - 2 + n - 1, n - 1)",
"+ return ans % mod",
"+ else: # i>2",
"+ Sp = i // 2 - 1",
"- # i=2の時の数え上げ",
"- for x in range(2):",
"- ball = n - x # 球",
"- box = k - 1 # 箱",
"- ans += Comb(box - 1 + ball, ball) % mod",
"- ans *= pow(2, pairs, mod) # 0pairの選び方",
"- return ans % mod",
"+ for p in range(Sp + 1):",
"+ ans += g(n, k, i, p)",
"+ return ans % mod",
"+",
"+",
"+def g(n, k, i, p):",
"+ Sp = i // 2 - 1",
"+ if p == 0:",
"+ return f(n - Sp, k - Sp, 2) * pow(2, Sp, mod) % mod",
"+ else: # p>0",
"+ return g(n, k - 2 * p, i - 2 * p, 0) * Comb(Sp, p)",
"- pairs = (i - 2) // 2",
"- tmp = 0",
"- for p0 in range(pairs + 1): # p0 = 0pairの数",
"- tmp1 = calc(K - p0 * 2, N, i - p0 * 2) % mod # k-p0*2,i-p0*2で0pairが0組",
"- tmp2 = Comb(pairs, p0) % mod # 0pairの選び方",
"- tmp += tmp1 * tmp2",
"- tmp %= mod",
"+ tmp = f(N, K, i)"
] | false | 0.038467 | 0.039669 | 0.96969 | [
"s546178206",
"s451247436"
] |
u102461423 | p03987 | python | s856045721 | s119927975 | 639 | 322 | 73,072 | 36,380 | Accepted | Accepted | 49.61 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
# 大きい数字から追加していく。そのときの連結成分の大きさだけ足される。
# union findっぽく。各成分の左端を根として持つ
N = int(eval(input()))
A = [int(x) for x in input().split()]
x_to_i = {x:i for i,x in enumerate(A)}
V = set()
root = dict()
size = dict()
def find_root(x):
y = root[x]
if x == y:
return y
ry = find_root(y)
root[x] = ry
return ry
def merge(x,y):
rx = find_root(x)
ry = find_root(y)
sx = size[rx]
sy = size[ry]
if sx > sy:
rx,ry = ry,rx
sx,sy = sy,sx
root[rx] = ry
size[ry] += sx
answer = 0
for x in range(N,0,-1):
i = x_to_i[x]
V.add(i)
size[i] = 1
root[i] = i
left = 0
right = 0
if i-1 in V:
left = size[find_root(i-1)]
merge(i-1,i)
if i+1 in V:
right = size[find_root(i+1)]
merge(i+1,i)
cnt = (left+1) * (right+1)
answer += x * cnt
print(answer) | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
"""
・大きい数から挿入していく
・連結成分の両端を管理する
"""
N,*A = list(map(int,read().split()))
A = [0] + A + [0]
ind = [0] * (N+1)
for i,x in enumerate(A):
ind[x] = i
left = list(range(1,len(A)+1))
right = list(range(-1,len(A)-1))
answer = 0
for i in ind[:0:-1]:
# i番目に数を挿入
l = left[i-1]; r = right[i+1]
left[r] = l; right[l] = r
x = i - l + 1; y = r - i + 1
answer += A[i] * (x * y)
print(answer) | 53 | 28 | 980 | 541 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
# 大きい数字から追加していく。そのときの連結成分の大きさだけ足される。
# union findっぽく。各成分の左端を根として持つ
N = int(eval(input()))
A = [int(x) for x in input().split()]
x_to_i = {x: i for i, x in enumerate(A)}
V = set()
root = dict()
size = dict()
def find_root(x):
y = root[x]
if x == y:
return y
ry = find_root(y)
root[x] = ry
return ry
def merge(x, y):
rx = find_root(x)
ry = find_root(y)
sx = size[rx]
sy = size[ry]
if sx > sy:
rx, ry = ry, rx
sx, sy = sy, sx
root[rx] = ry
size[ry] += sx
answer = 0
for x in range(N, 0, -1):
i = x_to_i[x]
V.add(i)
size[i] = 1
root[i] = i
left = 0
right = 0
if i - 1 in V:
left = size[find_root(i - 1)]
merge(i - 1, i)
if i + 1 in V:
right = size[find_root(i + 1)]
merge(i + 1, i)
cnt = (left + 1) * (right + 1)
answer += x * cnt
print(answer)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
"""
・大きい数から挿入していく
・連結成分の両端を管理する
"""
N, *A = list(map(int, read().split()))
A = [0] + A + [0]
ind = [0] * (N + 1)
for i, x in enumerate(A):
ind[x] = i
left = list(range(1, len(A) + 1))
right = list(range(-1, len(A) - 1))
answer = 0
for i in ind[:0:-1]:
# i番目に数を挿入
l = left[i - 1]
r = right[i + 1]
left[r] = l
right[l] = r
x = i - l + 1
y = r - i + 1
answer += A[i] * (x * y)
print(answer)
| false | 47.169811 | [
"-input = sys.stdin.readline",
"-sys.setrecursionlimit(10**7)",
"-# 大きい数字から追加していく。そのときの連結成分の大きさだけ足される。",
"-# union findっぽく。各成分の左端を根として持つ",
"-N = int(eval(input()))",
"-A = [int(x) for x in input().split()]",
"-x_to_i = {x: i for i, x in enumerate(A)}",
"-V = set()",
"-root = dict()",
"-size = dict()",
"-",
"-",
"-def find_root(x):",
"- y = root[x]",
"- if x == y:",
"- return y",
"- ry = find_root(y)",
"- root[x] = ry",
"- return ry",
"-",
"-",
"-def merge(x, y):",
"- rx = find_root(x)",
"- ry = find_root(y)",
"- sx = size[rx]",
"- sy = size[ry]",
"- if sx > sy:",
"- rx, ry = ry, rx",
"- sx, sy = sy, sx",
"- root[rx] = ry",
"- size[ry] += sx",
"-",
"-",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+\"\"\"",
"+・大きい数から挿入していく",
"+・連結成分の両端を管理する",
"+\"\"\"",
"+N, *A = list(map(int, read().split()))",
"+A = [0] + A + [0]",
"+ind = [0] * (N + 1)",
"+for i, x in enumerate(A):",
"+ ind[x] = i",
"+left = list(range(1, len(A) + 1))",
"+right = list(range(-1, len(A) - 1))",
"-for x in range(N, 0, -1):",
"- i = x_to_i[x]",
"- V.add(i)",
"- size[i] = 1",
"- root[i] = i",
"- left = 0",
"- right = 0",
"- if i - 1 in V:",
"- left = size[find_root(i - 1)]",
"- merge(i - 1, i)",
"- if i + 1 in V:",
"- right = size[find_root(i + 1)]",
"- merge(i + 1, i)",
"- cnt = (left + 1) * (right + 1)",
"- answer += x * cnt",
"+for i in ind[:0:-1]:",
"+ # i番目に数を挿入",
"+ l = left[i - 1]",
"+ r = right[i + 1]",
"+ left[r] = l",
"+ right[l] = r",
"+ x = i - l + 1",
"+ y = r - i + 1",
"+ answer += A[i] * (x * y)"
] | false | 0.037085 | 0.049656 | 0.746844 | [
"s856045721",
"s119927975"
] |
u970197315 | p02861 | python | s620582724 | s875953985 | 427 | 268 | 9,460 | 13,908 | Accepted | Accepted | 37.24 | n=int(eval(input()))
xy=[]
for i in range(n):
xx,yy=list(map(int,input().split()))
xy.append((xx,yy))
from itertools import permutations
a=list(permutations(xy))
d=[]
for aa in a:
t=0
for i in range(len(aa)-1):
t+=((aa[i+1][0]-aa[i][0])**2+(aa[i+1][1]-aa[i][1])**2)**0.5
d.append(t)
print((sum(d)/len(d)))
| n = int(eval(input()))
xy = [list(map(int,input().split())) for _ in range(n)]
from itertools import permutations
count = 0
dist = 0
for l in list(permutations(xy)):
tmp = 0
for i in range(len(l)-1):
tmp += ((l[i+1][0]-l[i][0])**2+(l[i+1][1]-l[i][1])**2)**0.5
dist += tmp
count += 1
print((dist/count))
| 14 | 14 | 319 | 334 | n = int(eval(input()))
xy = []
for i in range(n):
xx, yy = list(map(int, input().split()))
xy.append((xx, yy))
from itertools import permutations
a = list(permutations(xy))
d = []
for aa in a:
t = 0
for i in range(len(aa) - 1):
t += ((aa[i + 1][0] - aa[i][0]) ** 2 + (aa[i + 1][1] - aa[i][1]) ** 2) ** 0.5
d.append(t)
print((sum(d) / len(d)))
| n = int(eval(input()))
xy = [list(map(int, input().split())) for _ in range(n)]
from itertools import permutations
count = 0
dist = 0
for l in list(permutations(xy)):
tmp = 0
for i in range(len(l) - 1):
tmp += ((l[i + 1][0] - l[i][0]) ** 2 + (l[i + 1][1] - l[i][1]) ** 2) ** 0.5
dist += tmp
count += 1
print((dist / count))
| false | 0 | [
"-xy = []",
"-for i in range(n):",
"- xx, yy = list(map(int, input().split()))",
"- xy.append((xx, yy))",
"+xy = [list(map(int, input().split())) for _ in range(n)]",
"-a = list(permutations(xy))",
"-d = []",
"-for aa in a:",
"- t = 0",
"- for i in range(len(aa) - 1):",
"- t += ((aa[i + 1][0] - aa[i][0]) ** 2 + (aa[i + 1][1] - aa[i][1]) ** 2) ** 0.5",
"- d.append(t)",
"-print((sum(d) / len(d)))",
"+count = 0",
"+dist = 0",
"+for l in list(permutations(xy)):",
"+ tmp = 0",
"+ for i in range(len(l) - 1):",
"+ tmp += ((l[i + 1][0] - l[i][0]) ** 2 + (l[i + 1][1] - l[i][1]) ** 2) ** 0.5",
"+ dist += tmp",
"+ count += 1",
"+print((dist / count))"
] | false | 0.051837 | 0.039259 | 1.320362 | [
"s620582724",
"s875953985"
] |
u992910889 | p03627 | python | s404007847 | s676586696 | 298 | 267 | 71,832 | 69,912 | Accepted | Accepted | 10.4 | # import bisect
from collections import Counter, deque
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
def resolve():
N = int(eval(input()))
A = list(map(int, input().split()))
AA = Counter(A).most_common()
ls = []
for i in range(len(AA)):
if AA[i][1] >= 2:
ls.append(AA[i])
else:
break
ls=sorted(ls, key=lambda x: x[0])
try:
ans = ls[-1][0] * ls[-2][0]
for i in reversed(list(range(len(ls)))):
if ls[i][1] >= 4:
ans = max(ans, ls[i][0] ** 2)
print(ans)
except:
print((0))
resolve() | # import bisect
from collections import Counter, deque
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
def resolve():
N=int(eval(input()))
A=sorted(list(map(int,input().split())),reverse=True)
temp=-1
maxans=0
AA=Counter(A)
for (i,j) in list(AA.items()):
if j>=4:
maxans=max(i**2,maxans)
if j>=2:
if temp>=0:
maxans=max(maxans,temp*i)
temp=max(i,temp)
print(maxans)
resolve() | 42 | 33 | 946 | 792 | # import bisect
from collections import Counter, deque
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys
sys.setrecursionlimit(10**5 + 10)
# input = sys.stdin.readline
def resolve():
N = int(eval(input()))
A = list(map(int, input().split()))
AA = Counter(A).most_common()
ls = []
for i in range(len(AA)):
if AA[i][1] >= 2:
ls.append(AA[i])
else:
break
ls = sorted(ls, key=lambda x: x[0])
try:
ans = ls[-1][0] * ls[-2][0]
for i in reversed(list(range(len(ls)))):
if ls[i][1] >= 4:
ans = max(ans, ls[i][0] ** 2)
print(ans)
except:
print((0))
resolve()
| # import bisect
from collections import Counter, deque
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys
sys.setrecursionlimit(10**5 + 10)
# input = sys.stdin.readline
def resolve():
N = int(eval(input()))
A = sorted(list(map(int, input().split())), reverse=True)
temp = -1
maxans = 0
AA = Counter(A)
for (i, j) in list(AA.items()):
if j >= 4:
maxans = max(i**2, maxans)
if j >= 2:
if temp >= 0:
maxans = max(maxans, temp * i)
temp = max(i, temp)
print(maxans)
resolve()
| false | 21.428571 | [
"- A = list(map(int, input().split()))",
"- AA = Counter(A).most_common()",
"- ls = []",
"- for i in range(len(AA)):",
"- if AA[i][1] >= 2:",
"- ls.append(AA[i])",
"- else:",
"- break",
"- ls = sorted(ls, key=lambda x: x[0])",
"- try:",
"- ans = ls[-1][0] * ls[-2][0]",
"- for i in reversed(list(range(len(ls)))):",
"- if ls[i][1] >= 4:",
"- ans = max(ans, ls[i][0] ** 2)",
"- print(ans)",
"- except:",
"- print((0))",
"+ A = sorted(list(map(int, input().split())), reverse=True)",
"+ temp = -1",
"+ maxans = 0",
"+ AA = Counter(A)",
"+ for (i, j) in list(AA.items()):",
"+ if j >= 4:",
"+ maxans = max(i**2, maxans)",
"+ if j >= 2:",
"+ if temp >= 0:",
"+ maxans = max(maxans, temp * i)",
"+ temp = max(i, temp)",
"+ print(maxans)"
] | false | 0.008531 | 0.084117 | 0.101422 | [
"s404007847",
"s676586696"
] |
u337080722 | p03081 | python | s862741167 | s250813563 | 1,775 | 530 | 41,400 | 41,388 | Accepted | Accepted | 70.14 | def search_right(a, x, lo=0, hi=None, key=lambda x: x):
if lo < 0:
raise ValueError('lo must be non-negative')
if hi is None:
hi = len(a)
while lo < hi:
mid = (lo+hi)//2
if x < key(a[mid]): hi = mid
else: lo = mid+1
return lo
def search_left(a, x, lo=0, hi=None, key=lambda x: x):
if lo < 0:
raise ValueError('lo must be non-negative')
if hi is None:
hi = len(a)
while lo < hi:
mid = (lo+hi)//2
if key(a[mid]) < x: lo = mid+1
else: hi = mid
return lo
def get_fin_pos(s, td, golem_pos):
for t, d in td:
if 0 <= golem_pos < len(s) and s[golem_pos] == t:
golem_pos += 1 if d == "R" else -1
return golem_pos
n, q = list(map(int, input().split()))
s = "_{}_".format(eval(input()))
spells = [input().split() for _ in range(q)]
left = search_right(list(range(len(s))), 0, key=lambda golem: get_fin_pos(s, spells, golem))
right = search_left(list(range(len(s))), len(s) - 1, key=lambda golem: get_fin_pos(s, spells, golem))
print((right - left)) | n, q = list(map(int, input().split()))
s = "_{}_".format(eval(input()))
td = [input().split() for _ in range(q)]
current_l = 0
current_r = len(s) - 1
for t, d in reversed(td):
if current_l + 1 < len(s) - 1 and t == s[current_l + 1] and d == "L":
current_l += 1
elif t == s[current_l] and d == "R":
current_l -= 1
if 0 < current_r - 1 and t == s[current_r - 1] and d == "R":
current_r -= 1
elif t == s[current_r] and d == "L":
current_r += 1
print((max(current_r - current_l - 1, 0)))
| 39 | 20 | 1,097 | 542 | def search_right(a, x, lo=0, hi=None, key=lambda x: x):
if lo < 0:
raise ValueError("lo must be non-negative")
if hi is None:
hi = len(a)
while lo < hi:
mid = (lo + hi) // 2
if x < key(a[mid]):
hi = mid
else:
lo = mid + 1
return lo
def search_left(a, x, lo=0, hi=None, key=lambda x: x):
if lo < 0:
raise ValueError("lo must be non-negative")
if hi is None:
hi = len(a)
while lo < hi:
mid = (lo + hi) // 2
if key(a[mid]) < x:
lo = mid + 1
else:
hi = mid
return lo
def get_fin_pos(s, td, golem_pos):
for t, d in td:
if 0 <= golem_pos < len(s) and s[golem_pos] == t:
golem_pos += 1 if d == "R" else -1
return golem_pos
n, q = list(map(int, input().split()))
s = "_{}_".format(eval(input()))
spells = [input().split() for _ in range(q)]
left = search_right(
list(range(len(s))), 0, key=lambda golem: get_fin_pos(s, spells, golem)
)
right = search_left(
list(range(len(s))), len(s) - 1, key=lambda golem: get_fin_pos(s, spells, golem)
)
print((right - left))
| n, q = list(map(int, input().split()))
s = "_{}_".format(eval(input()))
td = [input().split() for _ in range(q)]
current_l = 0
current_r = len(s) - 1
for t, d in reversed(td):
if current_l + 1 < len(s) - 1 and t == s[current_l + 1] and d == "L":
current_l += 1
elif t == s[current_l] and d == "R":
current_l -= 1
if 0 < current_r - 1 and t == s[current_r - 1] and d == "R":
current_r -= 1
elif t == s[current_r] and d == "L":
current_r += 1
print((max(current_r - current_l - 1, 0)))
| false | 48.717949 | [
"-def search_right(a, x, lo=0, hi=None, key=lambda x: x):",
"- if lo < 0:",
"- raise ValueError(\"lo must be non-negative\")",
"- if hi is None:",
"- hi = len(a)",
"- while lo < hi:",
"- mid = (lo + hi) // 2",
"- if x < key(a[mid]):",
"- hi = mid",
"- else:",
"- lo = mid + 1",
"- return lo",
"-",
"-",
"-def search_left(a, x, lo=0, hi=None, key=lambda x: x):",
"- if lo < 0:",
"- raise ValueError(\"lo must be non-negative\")",
"- if hi is None:",
"- hi = len(a)",
"- while lo < hi:",
"- mid = (lo + hi) // 2",
"- if key(a[mid]) < x:",
"- lo = mid + 1",
"- else:",
"- hi = mid",
"- return lo",
"-",
"-",
"-def get_fin_pos(s, td, golem_pos):",
"- for t, d in td:",
"- if 0 <= golem_pos < len(s) and s[golem_pos] == t:",
"- golem_pos += 1 if d == \"R\" else -1",
"- return golem_pos",
"-",
"-",
"-spells = [input().split() for _ in range(q)]",
"-left = search_right(",
"- list(range(len(s))), 0, key=lambda golem: get_fin_pos(s, spells, golem)",
"-)",
"-right = search_left(",
"- list(range(len(s))), len(s) - 1, key=lambda golem: get_fin_pos(s, spells, golem)",
"-)",
"-print((right - left))",
"+td = [input().split() for _ in range(q)]",
"+current_l = 0",
"+current_r = len(s) - 1",
"+for t, d in reversed(td):",
"+ if current_l + 1 < len(s) - 1 and t == s[current_l + 1] and d == \"L\":",
"+ current_l += 1",
"+ elif t == s[current_l] and d == \"R\":",
"+ current_l -= 1",
"+ if 0 < current_r - 1 and t == s[current_r - 1] and d == \"R\":",
"+ current_r -= 1",
"+ elif t == s[current_r] and d == \"L\":",
"+ current_r += 1",
"+print((max(current_r - current_l - 1, 0)))"
] | false | 0.041455 | 0.040325 | 1.028038 | [
"s862741167",
"s250813563"
] |
u745087332 | p03241 | python | s037635922 | s409876889 | 490 | 26 | 40,044 | 3,060 | Accepted | Accepted | 94.69 | # coding:utf-8
def inpl(): return list(map(int, input().split()))
N, M = inpl()
n = M // N
while n > 0:
if M % n == 0:
print(n)
break
else:
n -= 1
| # coding:utf-8
def inpl(): return list(map(int, input().split()))
N, M = inpl()
A = 1
ans = 1
while A * A <= M:
# 約数判定
if M % A != 0:
A += 1
continue
B = M // A
# dはM // N以下
if A * N <= M:
ans = max(ans, A)
# M = A * BでAはsqrt(M)までしか探索しない
# 答えがsqrt(M)以上M // N以下のときWAになるので
# AだけではなくBでも判定を行う
# だから全探索の時は必要なかったのか...
if B * N <= M:
ans = max(ans, B)
A += 1
print(ans)
| 15 | 30 | 198 | 476 | # coding:utf-8
def inpl():
return list(map(int, input().split()))
N, M = inpl()
n = M // N
while n > 0:
if M % n == 0:
print(n)
break
else:
n -= 1
| # coding:utf-8
def inpl():
return list(map(int, input().split()))
N, M = inpl()
A = 1
ans = 1
while A * A <= M:
# 約数判定
if M % A != 0:
A += 1
continue
B = M // A
# dはM // N以下
if A * N <= M:
ans = max(ans, A)
# M = A * BでAはsqrt(M)までしか探索しない
# 答えがsqrt(M)以上M // N以下のときWAになるので
# AだけではなくBでも判定を行う
# だから全探索の時は必要なかったのか...
if B * N <= M:
ans = max(ans, B)
A += 1
print(ans)
| false | 50 | [
"-n = M // N",
"-while n > 0:",
"- if M % n == 0:",
"- print(n)",
"- break",
"- else:",
"- n -= 1",
"+A = 1",
"+ans = 1",
"+while A * A <= M:",
"+ # 約数判定",
"+ if M % A != 0:",
"+ A += 1",
"+ continue",
"+ B = M // A",
"+ # dはM // N以下",
"+ if A * N <= M:",
"+ ans = max(ans, A)",
"+ # M = A * BでAはsqrt(M)までしか探索しない",
"+ # 答えがsqrt(M)以上M // N以下のときWAになるので",
"+ # AだけではなくBでも判定を行う",
"+ # だから全探索の時は必要なかったのか...",
"+ if B * N <= M:",
"+ ans = max(ans, B)",
"+ A += 1",
"+print(ans)"
] | false | 0.102673 | 0.040378 | 2.542791 | [
"s037635922",
"s409876889"
] |
u888092736 | p03695 | python | s758200944 | s088174376 | 21 | 17 | 3,316 | 2,940 | Accepted | Accepted | 19.05 | from collections import Counter
def get_color(rating):
if rating >= 3200:
return 8
else:
return rating // 400
eval(input())
a = Counter([get_color(int(x)) for x in input().split()])
min_color_cnt = len([i for i in a if i < 8])
print((max(1, min_color_cnt), min_color_cnt + a[8]))
| eval(input())
super_coders_cnt = 0
coders = set()
for r in map(int, input().split()):
if r >= 3200:
super_coders_cnt += 1
else:
coders.add(r // 400)
print((max(1, len(coders)), len(coders) + super_coders_cnt))
| 14 | 9 | 318 | 234 | from collections import Counter
def get_color(rating):
if rating >= 3200:
return 8
else:
return rating // 400
eval(input())
a = Counter([get_color(int(x)) for x in input().split()])
min_color_cnt = len([i for i in a if i < 8])
print((max(1, min_color_cnt), min_color_cnt + a[8]))
| eval(input())
super_coders_cnt = 0
coders = set()
for r in map(int, input().split()):
if r >= 3200:
super_coders_cnt += 1
else:
coders.add(r // 400)
print((max(1, len(coders)), len(coders) + super_coders_cnt))
| false | 35.714286 | [
"-from collections import Counter",
"-",
"-",
"-def get_color(rating):",
"- if rating >= 3200:",
"- return 8",
"+eval(input())",
"+super_coders_cnt = 0",
"+coders = set()",
"+for r in map(int, input().split()):",
"+ if r >= 3200:",
"+ super_coders_cnt += 1",
"- return rating // 400",
"-",
"-",
"-eval(input())",
"-a = Counter([get_color(int(x)) for x in input().split()])",
"-min_color_cnt = len([i for i in a if i < 8])",
"-print((max(1, min_color_cnt), min_color_cnt + a[8]))",
"+ coders.add(r // 400)",
"+print((max(1, len(coders)), len(coders) + super_coders_cnt))"
] | false | 0.10563 | 0.041352 | 2.554442 | [
"s758200944",
"s088174376"
] |
u200887663 | p02947 | python | s832520883 | s729114347 | 418 | 260 | 17,808 | 22,148 | Accepted | Accepted | 37.8 | n=int(eval(input()))
#n,p=map(int,input().split())
#hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
#素因数分解した結果を2次元配列にして返す
dic={}
ans=0
for i in range(n):
s=list(eval(input()))
s.sort()
st="".join(s)
v=dic.get(st,0)
ans+=v
dic[st]=v+1
print(ans)
| n=int(eval(input()))
#n,m=map(int,input().split())
#t=int(input())
#pl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
dic={}
res=0
for i in range(n):
s=list(eval(input()))
s="".join(sorted(s))
count=dic.get(s,0)
if count>0:
res+=count
dic[s]=count+1
print(res)
| 16 | 15 | 313 | 329 | n = int(eval(input()))
# n,p=map(int,input().split())
# hl=list(map(int,input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
# 素因数分解した結果を2次元配列にして返す
dic = {}
ans = 0
for i in range(n):
s = list(eval(input()))
s.sort()
st = "".join(s)
v = dic.get(st, 0)
ans += v
dic[st] = v + 1
print(ans)
| n = int(eval(input()))
# n,m=map(int,input().split())
# t=int(input())
# pl=list(map(int,input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
dic = {}
res = 0
for i in range(n):
s = list(eval(input()))
s = "".join(sorted(s))
count = dic.get(s, 0)
if count > 0:
res += count
dic[s] = count + 1
print(res)
| false | 6.25 | [
"-# n,p=map(int,input().split())",
"-# hl=list(map(int,input().split()))",
"+# n,m=map(int,input().split())",
"+# t=int(input())",
"+# pl=list(map(int,input().split()))",
"-# 素因数分解した結果を2次元配列にして返す",
"-ans = 0",
"+res = 0",
"- s.sort()",
"- st = \"\".join(s)",
"- v = dic.get(st, 0)",
"- ans += v",
"- dic[st] = v + 1",
"-print(ans)",
"+ s = \"\".join(sorted(s))",
"+ count = dic.get(s, 0)",
"+ if count > 0:",
"+ res += count",
"+ dic[s] = count + 1",
"+print(res)"
] | false | 0.172763 | 0.041394 | 4.173669 | [
"s832520883",
"s729114347"
] |
u059262067 | p03274 | python | s085322233 | s282245627 | 395 | 103 | 23,084 | 14,224 | Accepted | Accepted | 73.92 | import numpy as np
b = list(map(int, input().split()))
a = list(map(int, input().split()))
x = b[0]-b[1]+1
res = 10**15
for i in range(x):
tmp = i + b[1] - 1
if res > (a[tmp]-a[i] + min(abs(a[i]),abs(a[tmp]))):
res = a[tmp]-a[i] + min(abs(a[i]),abs(a[tmp]))
print(res) | b = list(map(int, input().split()))
a = list(map(int, input().split()))
x = b[0]-b[1]+1
res = 10**15
for i in range(x):
tmp = i + b[1] - 1
if res > (a[tmp]-a[i] + min(abs(a[i]),abs(a[tmp]))):
res = a[tmp]-a[i] + min(abs(a[i]),abs(a[tmp]))
print(res) | 12 | 11 | 303 | 283 | import numpy as np
b = list(map(int, input().split()))
a = list(map(int, input().split()))
x = b[0] - b[1] + 1
res = 10**15
for i in range(x):
tmp = i + b[1] - 1
if res > (a[tmp] - a[i] + min(abs(a[i]), abs(a[tmp]))):
res = a[tmp] - a[i] + min(abs(a[i]), abs(a[tmp]))
print(res)
| b = list(map(int, input().split()))
a = list(map(int, input().split()))
x = b[0] - b[1] + 1
res = 10**15
for i in range(x):
tmp = i + b[1] - 1
if res > (a[tmp] - a[i] + min(abs(a[i]), abs(a[tmp]))):
res = a[tmp] - a[i] + min(abs(a[i]), abs(a[tmp]))
print(res)
| false | 8.333333 | [
"-import numpy as np",
"-"
] | false | 0.045803 | 0.044478 | 1.029791 | [
"s085322233",
"s282245627"
] |
u133936772 | p02684 | python | s750855081 | s150063479 | 175 | 140 | 31,728 | 31,788 | Accepted | Accepted | 20 | n,k,*a=list(map(int,open(0).read().split()))
v=[0]+[-1]*n
p=0
for i in range(n):
t=a[p]-1
if v[t]>=0: l,r=v[t],i+1; break
v[t]=i+1; p=t
print((v.index(min(k,l+(k-l)%(r-l)))+1)) | n,k,*a=list(map(int,open(0).read().split()))
v=[0]+[-1]*n
t=a[0]-1
c=1
while v[t]<0:
v[t]=c
t=a[t]-1
c+=1
l=v[t]
c-=l
print((v.index(min(k,l+(k-l)%c))+1)) | 8 | 11 | 181 | 162 | n, k, *a = list(map(int, open(0).read().split()))
v = [0] + [-1] * n
p = 0
for i in range(n):
t = a[p] - 1
if v[t] >= 0:
l, r = v[t], i + 1
break
v[t] = i + 1
p = t
print((v.index(min(k, l + (k - l) % (r - l))) + 1))
| n, k, *a = list(map(int, open(0).read().split()))
v = [0] + [-1] * n
t = a[0] - 1
c = 1
while v[t] < 0:
v[t] = c
t = a[t] - 1
c += 1
l = v[t]
c -= l
print((v.index(min(k, l + (k - l) % c)) + 1))
| false | 27.272727 | [
"-p = 0",
"-for i in range(n):",
"- t = a[p] - 1",
"- if v[t] >= 0:",
"- l, r = v[t], i + 1",
"- break",
"- v[t] = i + 1",
"- p = t",
"-print((v.index(min(k, l + (k - l) % (r - l))) + 1))",
"+t = a[0] - 1",
"+c = 1",
"+while v[t] < 0:",
"+ v[t] = c",
"+ t = a[t] - 1",
"+ c += 1",
"+l = v[t]",
"+c -= l",
"+print((v.index(min(k, l + (k - l) % c)) + 1))"
] | false | 0.038705 | 0.039661 | 0.975886 | [
"s750855081",
"s150063479"
] |
u821624310 | p02413 | python | s542456510 | s823858481 | 50 | 40 | 8,336 | 8,196 | Accepted | Accepted | 20 | r, c = map(int, input().split())
a = [[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
l = list(map(int, input().split()))
for j in range(c):
a[i][j] = l[j]
a[i][c] += a[i][j]
for i in range(c+1):
for j in range(r):
a[r][i] += a[j][i]
for i in range(r+1):
for j in range(c+1):
if j == c:
print(str(a[i][j]))
else:
print(str(a[i][j]) + " ", end="")
| r, c = map(int, input().split())
a = [[int(i) for i in input().split()] for j in range(r)]
b = [[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
for j in range(c):
b[i][j] = a[i][j]
b[i][c] += a[i][j]
for i in range(c+1):
for j in range(r):
b[r][i] += b[j][i]
for i in range(r+1):
for j in range(c+1):
if j == c:
print(b[i][j])
else:
print("{0} ".format(b[i][j]), end = "")
| 18 | 18 | 461 | 487 | r, c = map(int, input().split())
a = [[0 for i in range(c + 1)] for j in range(r + 1)]
for i in range(r):
l = list(map(int, input().split()))
for j in range(c):
a[i][j] = l[j]
a[i][c] += a[i][j]
for i in range(c + 1):
for j in range(r):
a[r][i] += a[j][i]
for i in range(r + 1):
for j in range(c + 1):
if j == c:
print(str(a[i][j]))
else:
print(str(a[i][j]) + " ", end="")
| r, c = map(int, input().split())
a = [[int(i) for i in input().split()] for j in range(r)]
b = [[0 for i in range(c + 1)] for j in range(r + 1)]
for i in range(r):
for j in range(c):
b[i][j] = a[i][j]
b[i][c] += a[i][j]
for i in range(c + 1):
for j in range(r):
b[r][i] += b[j][i]
for i in range(r + 1):
for j in range(c + 1):
if j == c:
print(b[i][j])
else:
print("{0} ".format(b[i][j]), end="")
| false | 0 | [
"-a = [[0 for i in range(c + 1)] for j in range(r + 1)]",
"+a = [[int(i) for i in input().split()] for j in range(r)]",
"+b = [[0 for i in range(c + 1)] for j in range(r + 1)]",
"- l = list(map(int, input().split()))",
"- a[i][j] = l[j]",
"- a[i][c] += a[i][j]",
"+ b[i][j] = a[i][j]",
"+ b[i][c] += a[i][j]",
"- a[r][i] += a[j][i]",
"+ b[r][i] += b[j][i]",
"- print(str(a[i][j]))",
"+ print(b[i][j])",
"- print(str(a[i][j]) + \" \", end=\"\")",
"+ print(\"{0} \".format(b[i][j]), end=\"\")"
] | false | 0.046936 | 0.101594 | 0.461998 | [
"s542456510",
"s823858481"
] |
u756595712 | p02259 | python | s897633678 | s658773272 | 50 | 40 | 7,716 | 7,700 | Accepted | Accepted | 20 | length = int(eval(input()))
eles = [int(l) for l in input().split()]
times = 0
for i in range(length):
flag = 1
while flag > 0:
flag = 0
for j in range(length-1, 0, -1):
if eles[j] < eles[j - 1]:
_temp = eles[j]
eles[j] = eles[j-1]
eles[j-1] = _temp
flag = 1
times += 1
print((*eles))
print(times) | length = int(eval(input()))
eles = [int(l) for l in input().split()]
times = 0
for i in range(length):
flag = 1
while flag > 0:
flag = 0
for j in range(length-1, i, -1):
if eles[j] < eles[j - 1]:
_temp = eles[j]
eles[j] = eles[j-1]
eles[j-1] = _temp
flag = 1
times += 1
print((*eles))
print(times) | 18 | 18 | 424 | 424 | length = int(eval(input()))
eles = [int(l) for l in input().split()]
times = 0
for i in range(length):
flag = 1
while flag > 0:
flag = 0
for j in range(length - 1, 0, -1):
if eles[j] < eles[j - 1]:
_temp = eles[j]
eles[j] = eles[j - 1]
eles[j - 1] = _temp
flag = 1
times += 1
print((*eles))
print(times)
| length = int(eval(input()))
eles = [int(l) for l in input().split()]
times = 0
for i in range(length):
flag = 1
while flag > 0:
flag = 0
for j in range(length - 1, i, -1):
if eles[j] < eles[j - 1]:
_temp = eles[j]
eles[j] = eles[j - 1]
eles[j - 1] = _temp
flag = 1
times += 1
print((*eles))
print(times)
| false | 0 | [
"- for j in range(length - 1, 0, -1):",
"+ for j in range(length - 1, i, -1):"
] | false | 0.045517 | 0.101064 | 0.450379 | [
"s897633678",
"s658773272"
] |
u887207211 | p03221 | python | s305007694 | s770957003 | 660 | 563 | 30,076 | 36,380 | Accepted | Accepted | 14.7 | N, M = list(map(int,input().split()))
PY = [list(map(int,input().split())) + [0] for _ in range(M)]
sort_PY = sorted(PY, key = lambda x: x[1])
city = {}
for i in range(M):
p, y = sort_PY[i][0], sort_PY[i][1]
if p in city:
city[p] += 1
else:
city[p] = 1
sort_PY[i][2] = city[p]
for p, y, z in PY:
print((str(p).zfill(6)+str(z).zfill(6))) | import sys
stdin = sys.stdin
sn = lambda : stdin.readline().rstrip()
an = lambda : list(map(int, stdin.readline().split()))
ni = lambda : int(sn())
n, m = an()
py = []
for _ in range(m):
py.append(list(an()) + [0])
sortPy = sorted(py, key = lambda x : (x[0], x[1]))
d = {}
for i, (p, y, n) in enumerate(sortPy):
if p in d:
d[p] += 1
else:
d[p] = 1
sortPy[i][2] = d[p]
for p, y, n in py:
print((str(p).zfill(6) + str(n).zfill(6))) | 13 | 25 | 358 | 469 | N, M = list(map(int, input().split()))
PY = [list(map(int, input().split())) + [0] for _ in range(M)]
sort_PY = sorted(PY, key=lambda x: x[1])
city = {}
for i in range(M):
p, y = sort_PY[i][0], sort_PY[i][1]
if p in city:
city[p] += 1
else:
city[p] = 1
sort_PY[i][2] = city[p]
for p, y, z in PY:
print((str(p).zfill(6) + str(z).zfill(6)))
| import sys
stdin = sys.stdin
sn = lambda: stdin.readline().rstrip()
an = lambda: list(map(int, stdin.readline().split()))
ni = lambda: int(sn())
n, m = an()
py = []
for _ in range(m):
py.append(list(an()) + [0])
sortPy = sorted(py, key=lambda x: (x[0], x[1]))
d = {}
for i, (p, y, n) in enumerate(sortPy):
if p in d:
d[p] += 1
else:
d[p] = 1
sortPy[i][2] = d[p]
for p, y, n in py:
print((str(p).zfill(6) + str(n).zfill(6)))
| false | 48 | [
"-N, M = list(map(int, input().split()))",
"-PY = [list(map(int, input().split())) + [0] for _ in range(M)]",
"-sort_PY = sorted(PY, key=lambda x: x[1])",
"-city = {}",
"-for i in range(M):",
"- p, y = sort_PY[i][0], sort_PY[i][1]",
"- if p in city:",
"- city[p] += 1",
"+import sys",
"+",
"+stdin = sys.stdin",
"+sn = lambda: stdin.readline().rstrip()",
"+an = lambda: list(map(int, stdin.readline().split()))",
"+ni = lambda: int(sn())",
"+n, m = an()",
"+py = []",
"+for _ in range(m):",
"+ py.append(list(an()) + [0])",
"+sortPy = sorted(py, key=lambda x: (x[0], x[1]))",
"+d = {}",
"+for i, (p, y, n) in enumerate(sortPy):",
"+ if p in d:",
"+ d[p] += 1",
"- city[p] = 1",
"- sort_PY[i][2] = city[p]",
"-for p, y, z in PY:",
"- print((str(p).zfill(6) + str(z).zfill(6)))",
"+ d[p] = 1",
"+ sortPy[i][2] = d[p]",
"+for p, y, n in py:",
"+ print((str(p).zfill(6) + str(n).zfill(6)))"
] | false | 0.048236 | 0.048789 | 0.988664 | [
"s305007694",
"s770957003"
] |
u588341295 | p03212 | python | s374561314 | s675973866 | 802 | 429 | 44,464 | 3,060 | Accepted | Accepted | 46.51 | # -*- coding: utf-8 -*-
from itertools import product
N = int(eval(input()))
cnt = 0
# 候補となりうる10桁までの数字を列挙
for prod in product(['0', '3', '5', '7'], repeat=10):
# チェック用に変形
num = int(''.join(prod))
s = str(num)
# 753数ではない
if (s.find('3') == -1 or s.find('5') == -1
or s.find('7') == -1 or s.find('0') != -1):
continue
# N以下ではない
if num > N:
continue
cnt += 1
print(cnt)
| # -*- coding: utf-8 -*-
from itertools import product
N = int(eval(input()))
cnt = 0
# 候補となりうる9桁までの数字を列挙
for prod in product(['0', '3', '5', '7'], repeat=9):
# チェック用に変形
num = int(''.join(prod))
s = str(num)
# 753数ではない
if (s.find('3') == -1 or s.find('5') == -1
or s.find('7') == -1 or s.find('0') != -1):
continue
# N以下ではない
if num > N:
continue
cnt += 1
print(cnt)
| 21 | 21 | 444 | 442 | # -*- coding: utf-8 -*-
from itertools import product
N = int(eval(input()))
cnt = 0
# 候補となりうる10桁までの数字を列挙
for prod in product(["0", "3", "5", "7"], repeat=10):
# チェック用に変形
num = int("".join(prod))
s = str(num)
# 753数ではない
if s.find("3") == -1 or s.find("5") == -1 or s.find("7") == -1 or s.find("0") != -1:
continue
# N以下ではない
if num > N:
continue
cnt += 1
print(cnt)
| # -*- coding: utf-8 -*-
from itertools import product
N = int(eval(input()))
cnt = 0
# 候補となりうる9桁までの数字を列挙
for prod in product(["0", "3", "5", "7"], repeat=9):
# チェック用に変形
num = int("".join(prod))
s = str(num)
# 753数ではない
if s.find("3") == -1 or s.find("5") == -1 or s.find("7") == -1 or s.find("0") != -1:
continue
# N以下ではない
if num > N:
continue
cnt += 1
print(cnt)
| false | 0 | [
"-# 候補となりうる10桁までの数字を列挙",
"-for prod in product([\"0\", \"3\", \"5\", \"7\"], repeat=10):",
"+# 候補となりうる9桁までの数字を列挙",
"+for prod in product([\"0\", \"3\", \"5\", \"7\"], repeat=9):"
] | false | 2.032379 | 0.636855 | 3.191276 | [
"s374561314",
"s675973866"
] |
u821588465 | p02886 | python | s316957674 | s294738961 | 30 | 27 | 9,044 | 9,136 | Accepted | Accepted | 10 | N = int(eval(input()))
D = list(map(int, input().split()))
from itertools import accumulate
print((sum(list(d*c for d, c in zip(D[1:], accumulate(D))))))
| N = int(eval(input()))
D = list(map(int, input().split()))
from itertools import combinations
ans = 0
for i , j in combinations(D,2):
ans += i*j
print(ans) | 4 | 7 | 149 | 159 | N = int(eval(input()))
D = list(map(int, input().split()))
from itertools import accumulate
print((sum(list(d * c for d, c in zip(D[1:], accumulate(D))))))
| N = int(eval(input()))
D = list(map(int, input().split()))
from itertools import combinations
ans = 0
for i, j in combinations(D, 2):
ans += i * j
print(ans)
| false | 42.857143 | [
"-from itertools import accumulate",
"+from itertools import combinations",
"-print((sum(list(d * c for d, c in zip(D[1:], accumulate(D))))))",
"+ans = 0",
"+for i, j in combinations(D, 2):",
"+ ans += i * j",
"+print(ans)"
] | false | 0.037691 | 0.047151 | 0.799366 | [
"s316957674",
"s294738961"
] |
u537782349 | p03073 | python | s934873167 | s145471297 | 143 | 82 | 4,852 | 3,956 | Accepted | Accepted | 42.66 | a = eval(input())
b = [bool(int(a[i])) for i in range(len(a))]
b.insert(0, True)
c = [bool(int(a[i])) for i in range(len(a))]
c.insert(0, False)
bc = 0
cc = 0
for i in range(1, len(b)):
if b[i-1] == b[i]:
b[i] = not b[i-1]
bc += 1
if c[i-1] == c[i]:
c[i] = not c[i - 1]
cc += 1
print((min(bc, cc)))
| a = eval(input())
a = [bool(int(a[i])) for i in range(len(a))]
b = True
c = 0
d = 0
for i in range(len(a)):
if b is a[i]:
c += 1
if b is not a[i]:
d += 1
b = not b
print((min(c, d)))
| 17 | 12 | 349 | 214 | a = eval(input())
b = [bool(int(a[i])) for i in range(len(a))]
b.insert(0, True)
c = [bool(int(a[i])) for i in range(len(a))]
c.insert(0, False)
bc = 0
cc = 0
for i in range(1, len(b)):
if b[i - 1] == b[i]:
b[i] = not b[i - 1]
bc += 1
if c[i - 1] == c[i]:
c[i] = not c[i - 1]
cc += 1
print((min(bc, cc)))
| a = eval(input())
a = [bool(int(a[i])) for i in range(len(a))]
b = True
c = 0
d = 0
for i in range(len(a)):
if b is a[i]:
c += 1
if b is not a[i]:
d += 1
b = not b
print((min(c, d)))
| false | 29.411765 | [
"-b = [bool(int(a[i])) for i in range(len(a))]",
"-b.insert(0, True)",
"-c = [bool(int(a[i])) for i in range(len(a))]",
"-c.insert(0, False)",
"-bc = 0",
"-cc = 0",
"-for i in range(1, len(b)):",
"- if b[i - 1] == b[i]:",
"- b[i] = not b[i - 1]",
"- bc += 1",
"- if c[i - 1] == c[i]:",
"- c[i] = not c[i - 1]",
"- cc += 1",
"-print((min(bc, cc)))",
"+a = [bool(int(a[i])) for i in range(len(a))]",
"+b = True",
"+c = 0",
"+d = 0",
"+for i in range(len(a)):",
"+ if b is a[i]:",
"+ c += 1",
"+ if b is not a[i]:",
"+ d += 1",
"+ b = not b",
"+print((min(c, d)))"
] | false | 0.084471 | 0.065251 | 1.294555 | [
"s934873167",
"s145471297"
] |
u620868411 | p03253 | python | s143090127 | s846781672 | 266 | 108 | 62,960 | 15,212 | Accepted | Accepted | 59.4 | # -*- coding: utf-8 -*-
from collections import defaultdict
# mod mでの二項係数を求める
class BiCoeff(object):
def __init__(self, MAX, m):
super(BiCoeff, self).__init__()
fac = [0]*MAX
finv = [0]*MAX
inv = [0]*MAX
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2,MAX):
fac[i] = (fac[i-1]*i)%m
inv[i] = m - (inv[m%i] * (m//i))%m
finv[i] = (finv[i-1] * inv[i])%m
self.MAX = MAX
self.m = m
self.fac = fac
self.finv = finv
self.inv = inv
def calc(self,n,k):
if n<k:
return 0
if n<0 or k<0:
return 0
return (self.fac[n] * (self.finv[k]*self.finv[n-k])%self.m)%self.m
MOD = 10**9+7
n, m = list(map(int, input().split()))
pl = defaultdict(int)
x = m
p = 2
while p*p<x+10:
while x%p==0:
pl[p] += 1
x //= p
p += 1
if x>1:
pl[x] += 1
coeff = BiCoeff(10**6, MOD)
res = 1
for k in pl:
res *= coeff.calc(n+pl[k]-1, pl[k])
res %= MOD
print(res)
| # -*- coding: utf-8 -*-
def primeFactors(n):
res = []
while n%2==0:
res.append(2)
n //= 2
x = 3
while n>1 and n>=x*x:
while n%x==0:
res.append(x)
n //= x
x += 2
if n>1:
res.append(n)
return res
class BiCoeff(object):
def __init__(self, MAX, m):
super(BiCoeff, self).__init__()
fac = [0]*MAX
finv = [0]*MAX
inv = [0]*MAX
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2,MAX):
fac[i] = (fac[i-1]*i)%m
inv[i] = m - (inv[m%i] * (m//i))%m
finv[i] = (finv[i-1] * inv[i])%m
self.MAX = MAX
self.m = m
self.fac = fac
self.finv = finv
self.inv = inv
def calc(self,n,k):
if n<k:
return 0
if n<0 or k<0:
return 0
return (self.fac[n] * (self.finv[k]*self.finv[n-k])%self.m)%self.m
from collections import defaultdict
MOD = 10**9 + 7
n,m = list(map(int, input().split()))
bicoeff = BiCoeff(n+100,MOD)
d = defaultdict(int)
for p in primeFactors(m):
d[p] += 1
res = 1
for v in list(d.values()):
res *= bicoeff.calc(n-1+v,n-1)
res %= MOD
print(res)
| 55 | 61 | 1,150 | 1,325 | # -*- coding: utf-8 -*-
from collections import defaultdict
# mod mでの二項係数を求める
class BiCoeff(object):
def __init__(self, MAX, m):
super(BiCoeff, self).__init__()
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fac[i] = (fac[i - 1] * i) % m
inv[i] = m - (inv[m % i] * (m // i)) % m
finv[i] = (finv[i - 1] * inv[i]) % m
self.MAX = MAX
self.m = m
self.fac = fac
self.finv = finv
self.inv = inv
def calc(self, n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return (self.fac[n] * (self.finv[k] * self.finv[n - k]) % self.m) % self.m
MOD = 10**9 + 7
n, m = list(map(int, input().split()))
pl = defaultdict(int)
x = m
p = 2
while p * p < x + 10:
while x % p == 0:
pl[p] += 1
x //= p
p += 1
if x > 1:
pl[x] += 1
coeff = BiCoeff(10**6, MOD)
res = 1
for k in pl:
res *= coeff.calc(n + pl[k] - 1, pl[k])
res %= MOD
print(res)
| # -*- coding: utf-8 -*-
def primeFactors(n):
res = []
while n % 2 == 0:
res.append(2)
n //= 2
x = 3
while n > 1 and n >= x * x:
while n % x == 0:
res.append(x)
n //= x
x += 2
if n > 1:
res.append(n)
return res
class BiCoeff(object):
def __init__(self, MAX, m):
super(BiCoeff, self).__init__()
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
fac[i] = (fac[i - 1] * i) % m
inv[i] = m - (inv[m % i] * (m // i)) % m
finv[i] = (finv[i - 1] * inv[i]) % m
self.MAX = MAX
self.m = m
self.fac = fac
self.finv = finv
self.inv = inv
def calc(self, n, k):
if n < k:
return 0
if n < 0 or k < 0:
return 0
return (self.fac[n] * (self.finv[k] * self.finv[n - k]) % self.m) % self.m
from collections import defaultdict
MOD = 10**9 + 7
n, m = list(map(int, input().split()))
bicoeff = BiCoeff(n + 100, MOD)
d = defaultdict(int)
for p in primeFactors(m):
d[p] += 1
res = 1
for v in list(d.values()):
res *= bicoeff.calc(n - 1 + v, n - 1)
res %= MOD
print(res)
| false | 9.836066 | [
"-from collections import defaultdict",
"+def primeFactors(n):",
"+ res = []",
"+ while n % 2 == 0:",
"+ res.append(2)",
"+ n //= 2",
"+ x = 3",
"+ while n > 1 and n >= x * x:",
"+ while n % x == 0:",
"+ res.append(x)",
"+ n //= x",
"+ x += 2",
"+ if n > 1:",
"+ res.append(n)",
"+ return res",
"-# mod mでの二項係数を求める",
"+",
"+from collections import defaultdict",
"+",
"-pl = defaultdict(int)",
"-x = m",
"-p = 2",
"-while p * p < x + 10:",
"- while x % p == 0:",
"- pl[p] += 1",
"- x //= p",
"- p += 1",
"-if x > 1:",
"- pl[x] += 1",
"-coeff = BiCoeff(10**6, MOD)",
"+bicoeff = BiCoeff(n + 100, MOD)",
"+d = defaultdict(int)",
"+for p in primeFactors(m):",
"+ d[p] += 1",
"-for k in pl:",
"- res *= coeff.calc(n + pl[k] - 1, pl[k])",
"+for v in list(d.values()):",
"+ res *= bicoeff.calc(n - 1 + v, n - 1)"
] | false | 1.692955 | 0.082015 | 20.642106 | [
"s143090127",
"s846781672"
] |
u852690916 | p02793 | python | s137090506 | s100393322 | 379 | 283 | 56,412 | 45,148 | Accepted | Accepted | 25.33 | from collections import defaultdict
N=int(eval(input()))
A=list(map(int,input().split()))
MOD=10**9+7
inv=[1]*(10**6+1)
for i in range(2,10**6+1):
inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
LCM=defaultdict(int)
def f(n):
tmp=0
p=2
while n%p==0:
tmp+=1
n//=p
LCM[p]=max(LCM[p],tmp)
p=3
while p*p<=n:
tmp=0
while n%p==0:
tmp+=1
n//=p
LCM[p]=max(LCM[p],tmp)
p+=2
if n>1:
LCM[n]=max(LCM[n],1)
for a in A: f(a)
l=1
for p,n in list(LCM.items()):
l=l*pow(p,n,MOD)%MOD
ans=0
for a in A:
ans+=l*inv[a]%MOD
print((ans%MOD)) | from collections import defaultdict
N=int(eval(input()))
A=list(map(int,input().split()))
MOD=10**9+7
primes=[]
is_prime=[True]*(10**3)
for i in range(2,10**3):
if not is_prime[i]: continue
primes.append(i)
for j in range(2*i,10**3,i):
is_prime[j]=False
LCM=defaultdict(int)
for n in A:
for p in primes:
tmp=0
while n%p==0:
tmp+=1
n//=p
LCM[p]=max(LCM[p],tmp)
if n!=1:
LCM[n]=max(LCM[n],1)
l=1
for p,n in list(LCM.items()):
l=l*pow(p,n,MOD)%MOD
ans=0
for a in A:
ans+=l*pow(a,MOD-2,MOD)
ans%=MOD
print(ans) | 40 | 34 | 657 | 628 | from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
inv = [1] * (10**6 + 1)
for i in range(2, 10**6 + 1):
inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
LCM = defaultdict(int)
def f(n):
tmp = 0
p = 2
while n % p == 0:
tmp += 1
n //= p
LCM[p] = max(LCM[p], tmp)
p = 3
while p * p <= n:
tmp = 0
while n % p == 0:
tmp += 1
n //= p
LCM[p] = max(LCM[p], tmp)
p += 2
if n > 1:
LCM[n] = max(LCM[n], 1)
for a in A:
f(a)
l = 1
for p, n in list(LCM.items()):
l = l * pow(p, n, MOD) % MOD
ans = 0
for a in A:
ans += l * inv[a] % MOD
print((ans % MOD))
| from collections import defaultdict
N = int(eval(input()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
primes = []
is_prime = [True] * (10**3)
for i in range(2, 10**3):
if not is_prime[i]:
continue
primes.append(i)
for j in range(2 * i, 10**3, i):
is_prime[j] = False
LCM = defaultdict(int)
for n in A:
for p in primes:
tmp = 0
while n % p == 0:
tmp += 1
n //= p
LCM[p] = max(LCM[p], tmp)
if n != 1:
LCM[n] = max(LCM[n], 1)
l = 1
for p, n in list(LCM.items()):
l = l * pow(p, n, MOD) % MOD
ans = 0
for a in A:
ans += l * pow(a, MOD - 2, MOD)
ans %= MOD
print(ans)
| false | 15 | [
"-inv = [1] * (10**6 + 1)",
"-for i in range(2, 10**6 + 1):",
"- inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD",
"+primes = []",
"+is_prime = [True] * (10**3)",
"+for i in range(2, 10**3):",
"+ if not is_prime[i]:",
"+ continue",
"+ primes.append(i)",
"+ for j in range(2 * i, 10**3, i):",
"+ is_prime[j] = False",
"-",
"-",
"-def f(n):",
"- tmp = 0",
"- p = 2",
"- while n % p == 0:",
"- tmp += 1",
"- n //= p",
"- LCM[p] = max(LCM[p], tmp)",
"- p = 3",
"- while p * p <= n:",
"+for n in A:",
"+ for p in primes:",
"- p += 2",
"- if n > 1:",
"+ if n != 1:",
"-",
"-",
"-for a in A:",
"- f(a)",
"- ans += l * inv[a] % MOD",
"-print((ans % MOD))",
"+ ans += l * pow(a, MOD - 2, MOD)",
"+ ans %= MOD",
"+print(ans)"
] | false | 1.656227 | 0.112109 | 14.773312 | [
"s137090506",
"s100393322"
] |
u358919705 | p02270 | python | s169973323 | s216887734 | 960 | 820 | 11,656 | 11,580 | Accepted | Accepted | 14.58 | n, k = list(map(int, input().split()))
ww = [int(eval(input())) for _ in range(n)]
def chk(p):
c = 1
s = 0
for w in ww:
if w > p:
return False
if s + w <= p:
s += w
else:
c += 1
s = w
if c > k:
return False
return True
def search(l, r):
if r - l < 10:
for i in range(l, r):
if chk(i):
return i
m = (l + r) // 2
if chk(m):
return search(l, m + 1)
else:
return search(m, r)
print((search(0, 2 ** 30))) | n, k = list(map(int, input().split()))
ww = [int(eval(input())) for _ in range(n)]
def chk(p):
c = 1
s = 0
for w in ww:
if w > p:
return False
if s + w <= p:
s += w
else:
c += 1
s = w
if c > k:
return False
return True
def search(l, r):
if r - l < 10:
for i in range(l, r):
if chk(i):
return i
m = (l + r) // 2
if chk(m):
return search(l, m + 1)
else:
return search(m + 1, r)
print((search(0, 2 ** 30))) | 27 | 27 | 587 | 591 | n, k = list(map(int, input().split()))
ww = [int(eval(input())) for _ in range(n)]
def chk(p):
c = 1
s = 0
for w in ww:
if w > p:
return False
if s + w <= p:
s += w
else:
c += 1
s = w
if c > k:
return False
return True
def search(l, r):
if r - l < 10:
for i in range(l, r):
if chk(i):
return i
m = (l + r) // 2
if chk(m):
return search(l, m + 1)
else:
return search(m, r)
print((search(0, 2**30)))
| n, k = list(map(int, input().split()))
ww = [int(eval(input())) for _ in range(n)]
def chk(p):
c = 1
s = 0
for w in ww:
if w > p:
return False
if s + w <= p:
s += w
else:
c += 1
s = w
if c > k:
return False
return True
def search(l, r):
if r - l < 10:
for i in range(l, r):
if chk(i):
return i
m = (l + r) // 2
if chk(m):
return search(l, m + 1)
else:
return search(m + 1, r)
print((search(0, 2**30)))
| false | 0 | [
"- return search(m, r)",
"+ return search(m + 1, r)"
] | false | 0.034115 | 0.033552 | 1.016777 | [
"s169973323",
"s216887734"
] |
u287500079 | p02662 | python | s636323375 | s339698066 | 352 | 265 | 149,200 | 149,304 | Accepted | Accepted | 24.72 | import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
if debugmode:
print((*args))
def input(): return sys.stdin.readline().strip()
def STR(): return eval(input())
def INT(): return int(eval(input()))
def FLOAT(): return float(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 998244353
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True
n2 = [1 for _ in range(3010)]
for i in range(1, 3010):
n2[i] = n2[i - 1] * 2 % mod
n, s = MAP()
a = LIST()
dp = [[0 for _ in range(s + 1)] for _ in range(n)]
if s >= a[0]:
dp[0][a[0]] = 1
#print(a[0], dp[0])
for i in range(1, n):
for j in range(1, min(s + 1, a[i])):
dp[i][j] = dp[i - 1][j] * 2
dp[i][j] %= mod
if a[i] <= s:
dp[i][a[i]] = dp[i - 1][a[i]] * 2 + n2[i]
dp[i][a[i]] %= mod
for j in range(a[i] + 1, s + 1):
dp[i][j] = dp[i - 1][j] * 2
if dp[i - 1][j - a[i]]:
dp[i][j] += dp[i - 1][j - a[i]]# * 2 + dp[i - 1][j - a[i]]
dp[i][j] %= mod
#print(a[i], dp[i])
print((dp[n - 1][s])) | import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
if debugmode:
print((*args))
def input(): return sys.stdin.readline().strip()
def STR(): return eval(input())
def INT(): return int(eval(input()))
def FLOAT(): return float(eval(input()))
def MAP(): return list(map(int, input().split()))
def S_MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 998244353
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True
n2 = [1 for _ in range(3010)]
for i in range(1, 3010):
n2[i] = n2[i - 1] * 2 % mod
n, s = MAP()
a = LIST()
dp = [[0 for _ in range(s + 1)] for _ in range(n)]
if s >= a[0]:
dp[0][a[0]] = 1
for i in range(1, n):
for j in range(1, min(s + 1, a[i])):
dp[i][j] = dp[i - 1][j] * 2
dp[i][j] %= mod
if a[i] <= s:
dp[i][a[i]] = dp[i - 1][a[i]] * 2 + n2[i]
dp[i][a[i]] %= mod
for j in range(a[i] + 1, s + 1):
dp[i][j] = dp[i - 1][j] * 2 + dp[i - 1][j - a[i]]
dp[i][j] %= mod
print((dp[n - 1][s]))
| 51 | 47 | 1,736 | 1,608 | import sys, re, os
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
radians,
acos,
atan,
asin,
log,
log10,
gcd,
)
from itertools import (
permutations,
combinations,
product,
accumulate,
combinations_with_replacement,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
# from fractions import gcd
def debug(*args):
if debugmode:
print((*args))
def input():
return sys.stdin.readline().strip()
def STR():
return eval(input())
def INT():
return int(eval(input()))
def FLOAT():
return float(eval(input()))
def MAP():
return list(map(int, input().split()))
def S_MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
def lcm(a, b):
return a * b // gcd(a, b)
sys.setrecursionlimit(10**9)
inf = sys.maxsize
mod = 998244353
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True
n2 = [1 for _ in range(3010)]
for i in range(1, 3010):
n2[i] = n2[i - 1] * 2 % mod
n, s = MAP()
a = LIST()
dp = [[0 for _ in range(s + 1)] for _ in range(n)]
if s >= a[0]:
dp[0][a[0]] = 1
# print(a[0], dp[0])
for i in range(1, n):
for j in range(1, min(s + 1, a[i])):
dp[i][j] = dp[i - 1][j] * 2
dp[i][j] %= mod
if a[i] <= s:
dp[i][a[i]] = dp[i - 1][a[i]] * 2 + n2[i]
dp[i][a[i]] %= mod
for j in range(a[i] + 1, s + 1):
dp[i][j] = dp[i - 1][j] * 2
if dp[i - 1][j - a[i]]:
dp[i][j] += dp[i - 1][j - a[i]] # * 2 + dp[i - 1][j - a[i]]
dp[i][j] %= mod
# print(a[i], dp[i])
print((dp[n - 1][s]))
| import sys, re, os
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
radians,
acos,
atan,
asin,
log,
log10,
gcd,
)
from itertools import (
permutations,
combinations,
product,
accumulate,
combinations_with_replacement,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
# from fractions import gcd
def debug(*args):
if debugmode:
print((*args))
def input():
return sys.stdin.readline().strip()
def STR():
return eval(input())
def INT():
return int(eval(input()))
def FLOAT():
return float(eval(input()))
def MAP():
return list(map(int, input().split()))
def S_MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def S_LIST():
return list(map(str, input().split()))
def lcm(a, b):
return a * b // gcd(a, b)
sys.setrecursionlimit(10**9)
inf = sys.maxsize
mod = 998244353
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True
n2 = [1 for _ in range(3010)]
for i in range(1, 3010):
n2[i] = n2[i - 1] * 2 % mod
n, s = MAP()
a = LIST()
dp = [[0 for _ in range(s + 1)] for _ in range(n)]
if s >= a[0]:
dp[0][a[0]] = 1
for i in range(1, n):
for j in range(1, min(s + 1, a[i])):
dp[i][j] = dp[i - 1][j] * 2
dp[i][j] %= mod
if a[i] <= s:
dp[i][a[i]] = dp[i - 1][a[i]] * 2 + n2[i]
dp[i][a[i]] %= mod
for j in range(a[i] + 1, s + 1):
dp[i][j] = dp[i - 1][j] * 2 + dp[i - 1][j - a[i]]
dp[i][j] %= mod
print((dp[n - 1][s]))
| false | 7.843137 | [
"-# print(a[0], dp[0])",
"- dp[i][j] = dp[i - 1][j] * 2",
"- if dp[i - 1][j - a[i]]:",
"- dp[i][j] += dp[i - 1][j - a[i]] # * 2 + dp[i - 1][j - a[i]]",
"+ dp[i][j] = dp[i - 1][j] * 2 + dp[i - 1][j - a[i]]",
"- # print(a[i], dp[i])"
] | false | 0.037869 | 0.038254 | 0.98995 | [
"s636323375",
"s339698066"
] |
u022407960 | p02469 | python | s906683849 | s348923824 | 50 | 40 | 10,224 | 8,296 | Accepted | Accepted | 20 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
4
1 2 3 5
output:
30
"""
import sys
import fractions
from functools import reduce
def gcd(x, y):
if x < y:
x, y = y, x
while y > 0:
r = x % y
x = y
y = r
return x
def lcm(a, b):
return a * b // fractions.gcd(a, b)
def solve(_n_list):
return reduce(lcm, _n_list)
if __name__ == '__main__':
_input = sys.stdin.readlines()
cnt = int(_input[0])
n_list = tuple(map(int, _input[1].split()))
print((solve(n_list))) | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
4
1 2 3 5
output:
30
"""
import sys
from functools import reduce
def gcd(x, y):
if x < y:
x, y = y, x
while y > 0:
r = x % y
x = y
y = r
return x
def lcm(a, b):
return a * b // gcd(a, b)
def solve(_n_list):
return reduce(lcm, _n_list)
if __name__ == '__main__':
_input = sys.stdin.readlines()
cnt = int(_input[0])
n_list = tuple(map(int, _input[1].split()))
print((solve(n_list))) | 42 | 41 | 584 | 556 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
4
1 2 3 5
output:
30
"""
import sys
import fractions
from functools import reduce
def gcd(x, y):
if x < y:
x, y = y, x
while y > 0:
r = x % y
x = y
y = r
return x
def lcm(a, b):
return a * b // fractions.gcd(a, b)
def solve(_n_list):
return reduce(lcm, _n_list)
if __name__ == "__main__":
_input = sys.stdin.readlines()
cnt = int(_input[0])
n_list = tuple(map(int, _input[1].split()))
print((solve(n_list)))
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
4
1 2 3 5
output:
30
"""
import sys
from functools import reduce
def gcd(x, y):
if x < y:
x, y = y, x
while y > 0:
r = x % y
x = y
y = r
return x
def lcm(a, b):
return a * b // gcd(a, b)
def solve(_n_list):
return reduce(lcm, _n_list)
if __name__ == "__main__":
_input = sys.stdin.readlines()
cnt = int(_input[0])
n_list = tuple(map(int, _input[1].split()))
print((solve(n_list)))
| false | 2.380952 | [
"-import fractions",
"- return a * b // fractions.gcd(a, b)",
"+ return a * b // gcd(a, b)"
] | false | 0.055999 | 0.043503 | 1.287225 | [
"s906683849",
"s348923824"
] |
u581187895 | p03387 | python | s124948672 | s313623617 | 20 | 17 | 3,316 | 3,064 | Accepted | Accepted | 15 | a, b, c = list(map(int, input().split()))
ans = 0
while not (a==b==c):
a, b, c = sorted([a, b, c])
if a+2 <= c:
a += 2
else:
a += 1
b += 1
ans += 1
print(ans) | A = list(map(int, input().split()))
# 偶数、奇数の個数を数える
odds = 0
even = 0
for a in A:
if a%2 == 0:
even += 1
else:
odds += 1
ans = 0
# 操作1をするため個数が多いものを少ないものに偶奇を合わせる
if even == 2: # 偶数を奇数にする
ans += 1
for i in range(3):
if A[i]%2==0:
A[i] += 1
elif odds == 2:
ans += 1
for i in range(3):# 奇数を偶数にする
if A[i]%2==1:
A[i] += 1
# 最大値に合わせるよう+2を加えて数を合わせる
ma = max(A)
for i in range(3):
ans += (ma-A[i])//2
print(ans) | 11 | 31 | 184 | 492 | a, b, c = list(map(int, input().split()))
ans = 0
while not (a == b == c):
a, b, c = sorted([a, b, c])
if a + 2 <= c:
a += 2
else:
a += 1
b += 1
ans += 1
print(ans)
| A = list(map(int, input().split()))
# 偶数、奇数の個数を数える
odds = 0
even = 0
for a in A:
if a % 2 == 0:
even += 1
else:
odds += 1
ans = 0
# 操作1をするため個数が多いものを少ないものに偶奇を合わせる
if even == 2: # 偶数を奇数にする
ans += 1
for i in range(3):
if A[i] % 2 == 0:
A[i] += 1
elif odds == 2:
ans += 1
for i in range(3): # 奇数を偶数にする
if A[i] % 2 == 1:
A[i] += 1
# 最大値に合わせるよう+2を加えて数を合わせる
ma = max(A)
for i in range(3):
ans += (ma - A[i]) // 2
print(ans)
| false | 64.516129 | [
"-a, b, c = list(map(int, input().split()))",
"+A = list(map(int, input().split()))",
"+# 偶数、奇数の個数を数える",
"+odds = 0",
"+even = 0",
"+for a in A:",
"+ if a % 2 == 0:",
"+ even += 1",
"+ else:",
"+ odds += 1",
"-while not (a == b == c):",
"- a, b, c = sorted([a, b, c])",
"- if a + 2 <= c:",
"- a += 2",
"- else:",
"- a += 1",
"- b += 1",
"+# 操作1をするため個数が多いものを少ないものに偶奇を合わせる",
"+if even == 2: # 偶数を奇数にする",
"+ for i in range(3):",
"+ if A[i] % 2 == 0:",
"+ A[i] += 1",
"+elif odds == 2:",
"+ ans += 1",
"+ for i in range(3): # 奇数を偶数にする",
"+ if A[i] % 2 == 1:",
"+ A[i] += 1",
"+# 最大値に合わせるよう+2を加えて数を合わせる",
"+ma = max(A)",
"+for i in range(3):",
"+ ans += (ma - A[i]) // 2"
] | false | 0.049271 | 0.049352 | 0.998365 | [
"s124948672",
"s313623617"
] |
u743272507 | p02773 | python | s006744086 | s457381182 | 944 | 773 | 59,800 | 62,308 | Accepted | Accepted | 18.11 | from collections import defaultdict
n = int(eval(input()))
d = defaultdict(int)
for i in range(n): d[eval(input())]+=1
ds = sorted(list(d.items()), key = lambda x : (-x[1], x[0]))
nmx = ds[0][1]
for i in ds:
if nmx != i[1]: break
print((i[0]))
| from collections import defaultdict
d = defaultdict(int)
n = int(eval(input()))
for _ in range(n): d[eval(input())] += 1
s = sorted(list(d.items()), key=lambda x: (-x[1], x[0]))
nmax = s[0][1]
for i in s:
if i[1] != nmax: break
print((i[0])) | 9 | 9 | 236 | 233 | from collections import defaultdict
n = int(eval(input()))
d = defaultdict(int)
for i in range(n):
d[eval(input())] += 1
ds = sorted(list(d.items()), key=lambda x: (-x[1], x[0]))
nmx = ds[0][1]
for i in ds:
if nmx != i[1]:
break
print((i[0]))
| from collections import defaultdict
d = defaultdict(int)
n = int(eval(input()))
for _ in range(n):
d[eval(input())] += 1
s = sorted(list(d.items()), key=lambda x: (-x[1], x[0]))
nmax = s[0][1]
for i in s:
if i[1] != nmax:
break
print((i[0]))
| false | 0 | [
"+d = defaultdict(int)",
"-d = defaultdict(int)",
"-for i in range(n):",
"+for _ in range(n):",
"-ds = sorted(list(d.items()), key=lambda x: (-x[1], x[0]))",
"-nmx = ds[0][1]",
"-for i in ds:",
"- if nmx != i[1]:",
"+s = sorted(list(d.items()), key=lambda x: (-x[1], x[0]))",
"+nmax = s[0][1]",
"+for i in s:",
"+ if i[1] != nmax:"
] | false | 0.114262 | 0.047943 | 2.383284 | [
"s006744086",
"s457381182"
] |
u426534722 | p02283 | python | s052219514 | s677642319 | 7,370 | 6,000 | 105,028 | 57,536 | Accepted | Accepted | 18.59 | import sys
readline = sys.stdin.readline
NIL = None
class Tree:
def __init__(self, key = None):
self.key = key
self.p = NIL
self.left = NIL
self.right = NIL
n = int(input())
tree = {"root":NIL}
def insert(T, z):
y = NIL
x = T["root"]
while x != NIL:
y = x
if z.key < x.key:
x = x.left
else:
x = x.right
z.p = y
if y == NIL:
T["root"] = z
elif z.key < y.key:
y.left = z
else:
y.right = z
def preorder_tree_walk(T):
print(f" {T.key}", end="")
if T.left != NIL:
preorder_tree_walk(T.left)
if T.right != NIL:
preorder_tree_walk(T.right)
def inorder_tree_walk(T):
if T.left != NIL:
inorder_tree_walk(T.left)
print(f" {T.key}", end="")
if T.right != NIL:
inorder_tree_walk(T.right)
for _ in range(n):
ss = readline()
if ss[0] == "i":
s, v = ss.split()
insert(tree, Tree(int(v)))
else:
inorder_tree_walk(tree["root"])
print()
preorder_tree_walk(tree["root"])
print()
| import sys
readline = sys.stdin.readline
NIL = None
class Tree:
__slots__ = ['key', 'p', 'left', 'right']
def __init__(self, key = None):
self.key = key
self.p = NIL
self.left = NIL
self.right = NIL
n = int(input())
tree = {"root":NIL}
def insert(T, z):
y = NIL
x = T["root"]
while x != NIL:
y = x
if z.key < x.key:
x = x.left
else:
x = x.right
z.p = y
if y == NIL:
T["root"] = z
elif z.key < y.key:
y.left = z
else:
y.right = z
def preorder_tree_walk(T):
print(f" {T.key}", end="")
if T.left != NIL:
preorder_tree_walk(T.left)
if T.right != NIL:
preorder_tree_walk(T.right)
def inorder_tree_walk(T):
if T.left != NIL:
inorder_tree_walk(T.left)
print(f" {T.key}", end="")
if T.right != NIL:
inorder_tree_walk(T.right)
for _ in range(n):
ss = readline()
if ss[0] == "i":
s, v = ss.split()
insert(tree, Tree(int(v)))
else:
inorder_tree_walk(tree["root"])
print()
preorder_tree_walk(tree["root"])
print()
| 50 | 51 | 1,162 | 1,209 | import sys
readline = sys.stdin.readline
NIL = None
class Tree:
def __init__(self, key=None):
self.key = key
self.p = NIL
self.left = NIL
self.right = NIL
n = int(input())
tree = {"root": NIL}
def insert(T, z):
y = NIL
x = T["root"]
while x != NIL:
y = x
if z.key < x.key:
x = x.left
else:
x = x.right
z.p = y
if y == NIL:
T["root"] = z
elif z.key < y.key:
y.left = z
else:
y.right = z
def preorder_tree_walk(T):
print(f" {T.key}", end="")
if T.left != NIL:
preorder_tree_walk(T.left)
if T.right != NIL:
preorder_tree_walk(T.right)
def inorder_tree_walk(T):
if T.left != NIL:
inorder_tree_walk(T.left)
print(f" {T.key}", end="")
if T.right != NIL:
inorder_tree_walk(T.right)
for _ in range(n):
ss = readline()
if ss[0] == "i":
s, v = ss.split()
insert(tree, Tree(int(v)))
else:
inorder_tree_walk(tree["root"])
print()
preorder_tree_walk(tree["root"])
print()
| import sys
readline = sys.stdin.readline
NIL = None
class Tree:
__slots__ = ["key", "p", "left", "right"]
def __init__(self, key=None):
self.key = key
self.p = NIL
self.left = NIL
self.right = NIL
n = int(input())
tree = {"root": NIL}
def insert(T, z):
y = NIL
x = T["root"]
while x != NIL:
y = x
if z.key < x.key:
x = x.left
else:
x = x.right
z.p = y
if y == NIL:
T["root"] = z
elif z.key < y.key:
y.left = z
else:
y.right = z
def preorder_tree_walk(T):
print(f" {T.key}", end="")
if T.left != NIL:
preorder_tree_walk(T.left)
if T.right != NIL:
preorder_tree_walk(T.right)
def inorder_tree_walk(T):
if T.left != NIL:
inorder_tree_walk(T.left)
print(f" {T.key}", end="")
if T.right != NIL:
inorder_tree_walk(T.right)
for _ in range(n):
ss = readline()
if ss[0] == "i":
s, v = ss.split()
insert(tree, Tree(int(v)))
else:
inorder_tree_walk(tree["root"])
print()
preorder_tree_walk(tree["root"])
print()
| false | 1.960784 | [
"+ __slots__ = [\"key\", \"p\", \"left\", \"right\"]",
"+"
] | false | 0.11235 | 0.110865 | 1.013394 | [
"s052219514",
"s677642319"
] |
u670180528 | p03162 | python | s965353022 | s295798290 | 263 | 184 | 37,148 | 35,636 | Accepted | Accepted | 30.04 | n,*l=list(map(int,open(0).read().split()))
a=l[::3]
b=l[1::3]
c=l[2::3]
dp=[[0]*3 for _ in range(n)]
dp[0]=[a[0],b[0],c[0]]
A,B,C=dp[0]
for i in range(1,n):
dp[i]=[ a[i]+max(B,C) , b[i]+max(C,A) , c[i]+max(A,B) ]
A,B,C=dp[i]
print((max(dp[-1]))) | n,*l=list(map(int,open(0).read().split()))
a=l[::3];b=l[1::3];c=l[2::3]
A,B,C=a[0],b[0],c[0]
M=max
for i in range(1,n):
A,B,C=a[i]+M(B,C),b[i]+M(C,A),c[i]+M(A,B)
print((M(A,B,C))) | 11 | 7 | 249 | 178 | n, *l = list(map(int, open(0).read().split()))
a = l[::3]
b = l[1::3]
c = l[2::3]
dp = [[0] * 3 for _ in range(n)]
dp[0] = [a[0], b[0], c[0]]
A, B, C = dp[0]
for i in range(1, n):
dp[i] = [a[i] + max(B, C), b[i] + max(C, A), c[i] + max(A, B)]
A, B, C = dp[i]
print((max(dp[-1])))
| n, *l = list(map(int, open(0).read().split()))
a = l[::3]
b = l[1::3]
c = l[2::3]
A, B, C = a[0], b[0], c[0]
M = max
for i in range(1, n):
A, B, C = a[i] + M(B, C), b[i] + M(C, A), c[i] + M(A, B)
print((M(A, B, C)))
| false | 36.363636 | [
"-dp = [[0] * 3 for _ in range(n)]",
"-dp[0] = [a[0], b[0], c[0]]",
"-A, B, C = dp[0]",
"+A, B, C = a[0], b[0], c[0]",
"+M = max",
"- dp[i] = [a[i] + max(B, C), b[i] + max(C, A), c[i] + max(A, B)]",
"- A, B, C = dp[i]",
"-print((max(dp[-1])))",
"+ A, B, C = a[i] + M(B, C), b[i] + M(C, A), c[i] + M(A, B)",
"+print((M(A, B, C)))"
] | false | 0.044686 | 0.038494 | 1.160847 | [
"s965353022",
"s295798290"
] |
u648868410 | p03176 | python | s195006815 | s328111268 | 1,265 | 297 | 41,056 | 146,536 | Accepted | Accepted | 76.52 |
# EDPC Q - Flowers
# 重み付きのLISと言って良いような問題
# これは、LISのdpを少し改造すれば解ける
# import numpy as np
## test data
# 4
# 3 1 4 2
# 10 20 30 40
## ans=60
# import bisect
class BIT:
def __init__(self,size):
self.N = size
self.bit = [0] * (self.N+1)
def getSum(self,i):
s = 0
while 0 < i:
s += self.bit[i]
i -= i & -i
return s
def getMax(self,i):
s = 0
while 0 < i:
s = max(s, self.bit[i])
i -= i & -i
return s
def add(self,i,val):
while i <= self.N:
# for range summary query
# self.bit[i] += val
# for range maximum query
self.bit[i] = max( self.bit[i], val )
i += i & -i
def LongestIncreaseSeaquence(H,A):
# === Coordinate compression ===
# unique and sort asc
N = len(H)
# sortedA = sorted(list(set(A)))
lis = 0
# === Range Maximum Query ===
# ここでは、各要素iに、最後の値がiの時のLISを登録
tree = BIT(N)
for n in range(N):
tree.add( H[n], tree.getMax(H[n]) + A[n] )
lis = tree.getMax(N)
return lis
def main():
N = int(eval(input()))
# 高さは、N以下で全部違うらしい
H = list(map(int, input().split()))
A = list(map(int, input().split()))
# A = [ int(input()) for _ in range(N)]
print((LongestIncreaseSeaquence(H,A)))
if __name__ == "__main__":
main()
| # EDPC Q - Flowers
# 重み付きのLISと言って良いような問題
# これは、LISのdpを少し改造すれば解ける
## test data
# 4
# 3 1 4 2
# 10 20 30 40
## ans=60
import bisect
class SegTree:
"""
1-indexed
"""
def __init__(self,size,func,init_val,undef):
self.specSize = size
self.datSize = 1
self.compareFunc = func # suppose to min or max
self.INIT_VAL = init_val # 0 etc
self.UNDEFINED_VAL = undef # 1e18 -1e18 etc
# num:size以上の最小の2のべき乗
# self.datSize = 2**(size-1).bit_length()
self.datSize = 2**size.bit_length()
# while self.datSize < size: self.datSize *= 2
# the tree is implemented by sequencial list
# (1-indexed, 0 is not use.)
self.datTree = [self.INIT_VAL for _ in range(2*self.datSize+1)]
def update(self, i, val ):
"""
i: index(1-ordered)
"""
# i -= 1 # 1-orderで指定され、内部では0-Order想定?
# i += (self.datSize - 1)
i += self.datSize
# print("upd",i,val)
self.datTree[i] = val
while 1 < i:
# i = (i-1) >> 1 # (i-1)//2
i >>= 1
self.datTree[i] = self.compareFunc( self.datTree[i<<1|0], self.datTree[i<<1|1] )
# print("upd",i,self.datTree[i])
# self.printTree()
def query(self,a,b):
return self.query_(a,b,1,0,self.datSize)
def query_(self,a,b,i,l,r):
""" get minimun/maximum value of range[a,b)
all 1-indexed
i is the root vertex of search
l,r is range of the root vertex(not use)
"""
ret = self.UNDEFINED_VAL
a += self.datSize
b += self.datSize
while a < b:
if b & 1:
b -= 1
ret = self.compareFunc(ret, self.datTree[b])
if a & 1:
ret = self.compareFunc(ret, self.datTree[a])
a += 1
a >>= 1; b >>= 1
return ret
def query_recursive(self,a,b,i,l,r):
""" get minimun/maximum value of range[a,b)
all 1-indexed
i is the root vertex of search
l,r is range of the root vertex
"""
if r <= a or b <= l:
# (a,b) and (l,r) is not intersected
return self.UNDEFINED_VAL
if a <= l and r <= b:
# i is index required
return self.datTree[i]
else:
# search children
m = (l+r) >> 1 #(l+r) // 2
# vl = self.query_(a, b, i*2 + 1, l, m )
# vr = self.query_(a, b, i*2 + 2, m, r )
vl = self.query_(a, b, (i>>1) + 1, l, m )
vr = self.query_(a, b, (i>>1) + 2, m, r )
return self.compareFunc(vl,vr)
def printTree(self):
print((self.datTree))
# print("root")
def LongestIncreaseSeaquence(H,A):
# === Coordinate compression ===
# unique and sort asc
N = len(H)
# sortedA = sorted(list(set(A)))
lis = 0
# === Range Maximum Query ===
# ここでは、各要素iに、最後の値がiの時のLISを登録
tree = SegTree(N,max,0,-1e18)
for n in range(N):
# i=bisect.bisect_left(sortedA,A[n])
maxValOfCurrentRange = tree.query(0,H[n])
# valOfNext = tree.query(H[n],H[n]+1)
# # i+=1
# if valOfNext < maxValOfCurrentRange + A[n]:
# print( H[n], maxValOfCurrentRange + A[n] )
# tree.debugPrint()
tree.update( H[n], maxValOfCurrentRange + A[n] )
# tree.printTree()
lis = tree.query(0,N+1)
return lis
def main():
N = int(eval(input()))
# 高さは、N以下で全部違うらしい
H = list(map(int, input().split()))
A = list(map(int, input().split()))
# A = [ int(input()) for _ in range(N)]
print((LongestIncreaseSeaquence(H,A)))
if __name__ == "__main__":
main()
| 76 | 141 | 1,259 | 3,278 | # EDPC Q - Flowers
# 重み付きのLISと言って良いような問題
# これは、LISのdpを少し改造すれば解ける
# import numpy as np
## test data
# 4
# 3 1 4 2
# 10 20 30 40
## ans=60
# import bisect
class BIT:
def __init__(self, size):
self.N = size
self.bit = [0] * (self.N + 1)
def getSum(self, i):
s = 0
while 0 < i:
s += self.bit[i]
i -= i & -i
return s
def getMax(self, i):
s = 0
while 0 < i:
s = max(s, self.bit[i])
i -= i & -i
return s
def add(self, i, val):
while i <= self.N:
# for range summary query
# self.bit[i] += val
# for range maximum query
self.bit[i] = max(self.bit[i], val)
i += i & -i
def LongestIncreaseSeaquence(H, A):
# === Coordinate compression ===
# unique and sort asc
N = len(H)
# sortedA = sorted(list(set(A)))
lis = 0
# === Range Maximum Query ===
# ここでは、各要素iに、最後の値がiの時のLISを登録
tree = BIT(N)
for n in range(N):
tree.add(H[n], tree.getMax(H[n]) + A[n])
lis = tree.getMax(N)
return lis
def main():
N = int(eval(input()))
# 高さは、N以下で全部違うらしい
H = list(map(int, input().split()))
A = list(map(int, input().split()))
# A = [ int(input()) for _ in range(N)]
print((LongestIncreaseSeaquence(H, A)))
if __name__ == "__main__":
main()
| # EDPC Q - Flowers
# 重み付きのLISと言って良いような問題
# これは、LISのdpを少し改造すれば解ける
## test data
# 4
# 3 1 4 2
# 10 20 30 40
## ans=60
import bisect
class SegTree:
"""
1-indexed
"""
def __init__(self, size, func, init_val, undef):
self.specSize = size
self.datSize = 1
self.compareFunc = func # suppose to min or max
self.INIT_VAL = init_val # 0 etc
self.UNDEFINED_VAL = undef # 1e18 -1e18 etc
# num:size以上の最小の2のべき乗
# self.datSize = 2**(size-1).bit_length()
self.datSize = 2 ** size.bit_length()
# while self.datSize < size: self.datSize *= 2
# the tree is implemented by sequencial list
# (1-indexed, 0 is not use.)
self.datTree = [self.INIT_VAL for _ in range(2 * self.datSize + 1)]
def update(self, i, val):
"""
i: index(1-ordered)
"""
# i -= 1 # 1-orderで指定され、内部では0-Order想定?
# i += (self.datSize - 1)
i += self.datSize
# print("upd",i,val)
self.datTree[i] = val
while 1 < i:
# i = (i-1) >> 1 # (i-1)//2
i >>= 1
self.datTree[i] = self.compareFunc(
self.datTree[i << 1 | 0], self.datTree[i << 1 | 1]
)
# print("upd",i,self.datTree[i])
# self.printTree()
def query(self, a, b):
return self.query_(a, b, 1, 0, self.datSize)
def query_(self, a, b, i, l, r):
"""get minimun/maximum value of range[a,b)
all 1-indexed
i is the root vertex of search
l,r is range of the root vertex(not use)
"""
ret = self.UNDEFINED_VAL
a += self.datSize
b += self.datSize
while a < b:
if b & 1:
b -= 1
ret = self.compareFunc(ret, self.datTree[b])
if a & 1:
ret = self.compareFunc(ret, self.datTree[a])
a += 1
a >>= 1
b >>= 1
return ret
def query_recursive(self, a, b, i, l, r):
"""get minimun/maximum value of range[a,b)
all 1-indexed
i is the root vertex of search
l,r is range of the root vertex
"""
if r <= a or b <= l:
# (a,b) and (l,r) is not intersected
return self.UNDEFINED_VAL
if a <= l and r <= b:
# i is index required
return self.datTree[i]
else:
# search children
m = (l + r) >> 1 # (l+r) // 2
# vl = self.query_(a, b, i*2 + 1, l, m )
# vr = self.query_(a, b, i*2 + 2, m, r )
vl = self.query_(a, b, (i >> 1) + 1, l, m)
vr = self.query_(a, b, (i >> 1) + 2, m, r)
return self.compareFunc(vl, vr)
def printTree(self):
print((self.datTree))
# print("root")
def LongestIncreaseSeaquence(H, A):
# === Coordinate compression ===
# unique and sort asc
N = len(H)
# sortedA = sorted(list(set(A)))
lis = 0
# === Range Maximum Query ===
# ここでは、各要素iに、最後の値がiの時のLISを登録
tree = SegTree(N, max, 0, -1e18)
for n in range(N):
# i=bisect.bisect_left(sortedA,A[n])
maxValOfCurrentRange = tree.query(0, H[n])
# valOfNext = tree.query(H[n],H[n]+1)
# # i+=1
# if valOfNext < maxValOfCurrentRange + A[n]:
# print( H[n], maxValOfCurrentRange + A[n] )
# tree.debugPrint()
tree.update(H[n], maxValOfCurrentRange + A[n])
# tree.printTree()
lis = tree.query(0, N + 1)
return lis
def main():
N = int(eval(input()))
# 高さは、N以下で全部違うらしい
H = list(map(int, input().split()))
A = list(map(int, input().split()))
# A = [ int(input()) for _ in range(N)]
print((LongestIncreaseSeaquence(H, A)))
if __name__ == "__main__":
main()
| false | 46.099291 | [
"-# import numpy as np",
"-# import bisect",
"-class BIT:",
"- def __init__(self, size):",
"- self.N = size",
"- self.bit = [0] * (self.N + 1)",
"+import bisect",
"- def getSum(self, i):",
"- s = 0",
"- while 0 < i:",
"- s += self.bit[i]",
"- i -= i & -i",
"- return s",
"- def getMax(self, i):",
"- s = 0",
"- while 0 < i:",
"- s = max(s, self.bit[i])",
"- i -= i & -i",
"- return s",
"+class SegTree:",
"+ \"\"\"",
"+ 1-indexed",
"+ \"\"\"",
"- def add(self, i, val):",
"- while i <= self.N:",
"- # for range summary query",
"- # self.bit[i] += val",
"- # for range maximum query",
"- self.bit[i] = max(self.bit[i], val)",
"- i += i & -i",
"+ def __init__(self, size, func, init_val, undef):",
"+ self.specSize = size",
"+ self.datSize = 1",
"+ self.compareFunc = func # suppose to min or max",
"+ self.INIT_VAL = init_val # 0 etc",
"+ self.UNDEFINED_VAL = undef # 1e18 -1e18 etc",
"+ # num:size以上の最小の2のべき乗",
"+ # self.datSize = 2**(size-1).bit_length()",
"+ self.datSize = 2 ** size.bit_length()",
"+ # while self.datSize < size: self.datSize *= 2",
"+ # the tree is implemented by sequencial list",
"+ # (1-indexed, 0 is not use.)",
"+ self.datTree = [self.INIT_VAL for _ in range(2 * self.datSize + 1)]",
"+",
"+ def update(self, i, val):",
"+ \"\"\"",
"+ i: index(1-ordered)",
"+ \"\"\"",
"+ # i -= 1\t# 1-orderで指定され、内部では0-Order想定?",
"+ # i += (self.datSize - 1)",
"+ i += self.datSize",
"+ # print(\"upd\",i,val)",
"+ self.datTree[i] = val",
"+ while 1 < i:",
"+ # i = (i-1) >> 1\t# (i-1)//2",
"+ i >>= 1",
"+ self.datTree[i] = self.compareFunc(",
"+ self.datTree[i << 1 | 0], self.datTree[i << 1 | 1]",
"+ )",
"+ # print(\"upd\",i,self.datTree[i])",
"+ # self.printTree()",
"+",
"+ def query(self, a, b):",
"+ return self.query_(a, b, 1, 0, self.datSize)",
"+",
"+ def query_(self, a, b, i, l, r):",
"+ \"\"\"get minimun/maximum value of range[a,b)",
"+ all 1-indexed",
"+ i is the root vertex of search",
"+ l,r is range of the root vertex(not use)",
"+ \"\"\"",
"+ ret = self.UNDEFINED_VAL",
"+ a += self.datSize",
"+ b += self.datSize",
"+ while a < b:",
"+ if b & 1:",
"+ b -= 1",
"+ ret = self.compareFunc(ret, self.datTree[b])",
"+ if a & 1:",
"+ ret = self.compareFunc(ret, self.datTree[a])",
"+ a += 1",
"+ a >>= 1",
"+ b >>= 1",
"+ return ret",
"+",
"+ def query_recursive(self, a, b, i, l, r):",
"+ \"\"\"get minimun/maximum value of range[a,b)",
"+ all 1-indexed",
"+ i is the root vertex of search",
"+ l,r is range of the root vertex",
"+ \"\"\"",
"+ if r <= a or b <= l:",
"+ # (a,b) and (l,r) is not intersected",
"+ return self.UNDEFINED_VAL",
"+ if a <= l and r <= b:",
"+ # i is index required",
"+ return self.datTree[i]",
"+ else:",
"+ # search children",
"+ m = (l + r) >> 1 # (l+r) // 2",
"+ # vl = self.query_(a, b, i*2 + 1, l, m )",
"+ # vr = self.query_(a, b, i*2 + 2, m, r )",
"+ vl = self.query_(a, b, (i >> 1) + 1, l, m)",
"+ vr = self.query_(a, b, (i >> 1) + 2, m, r)",
"+ return self.compareFunc(vl, vr)",
"+",
"+ def printTree(self):",
"+ print((self.datTree))",
"+ # print(\"root\")",
"- tree = BIT(N)",
"+ tree = SegTree(N, max, 0, -1e18)",
"- tree.add(H[n], tree.getMax(H[n]) + A[n])",
"- lis = tree.getMax(N)",
"+ # i=bisect.bisect_left(sortedA,A[n])",
"+ maxValOfCurrentRange = tree.query(0, H[n])",
"+ # valOfNext = tree.query(H[n],H[n]+1)",
"+ # # i+=1",
"+ # if valOfNext < maxValOfCurrentRange + A[n]:",
"+ # print( H[n], maxValOfCurrentRange + A[n] )",
"+ # tree.debugPrint()",
"+ tree.update(H[n], maxValOfCurrentRange + A[n])",
"+ # tree.printTree()",
"+ lis = tree.query(0, N + 1)"
] | false | 0.070743 | 0.039438 | 1.79378 | [
"s195006815",
"s328111268"
] |
u813387707 | p03625 | python | s838986024 | s821402828 | 94 | 80 | 22,196 | 19,788 | Accepted | Accepted | 14.89 | 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] >= 4 else temp_list[0][0] * temp_list[1][0]))
else:
print((0)) | 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:
ans = e * temp
break
else:
temp = a_list[i]
count = 1
print(ans) | 11 | 20 | 370 | 436 | 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] >= 4
else temp_list[0][0] * temp_list[1][0]
)
)
else:
print((0))
| 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:
ans = e * temp
break
else:
temp = a_list[i]
count = 1
print(ans)
| false | 45 | [
"-from collections import defaultdict",
"-",
"-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] >= 4",
"- else temp_list[0][0] * temp_list[1][0]",
"- )",
"- )",
"-else:",
"- print((0))",
"+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:",
"+ ans = e * temp",
"+ break",
"+ else:",
"+ temp = a_list[i]",
"+ count = 1",
"+print(ans)"
] | false | 0.044389 | 0.050397 | 0.880793 | [
"s838986024",
"s821402828"
] |
u974231963 | p02548 | python | s137209442 | s815663188 | 313 | 269 | 9,120 | 9,184 | Accepted | Accepted | 14.06 |
n = int(eval(input()))
ans = 0
count = 0
a, b, c = 1, 1, 1
while a <= n:
# print("A : {0}".format(a))
# print("追加パターン : {0}".format( (n // a) ))
if a == 1 :
ans = ans + ( (n // a) - 1)
else :
if n // a == 1 :
ans = ans + 1
else :
if n % a == 0 :
ans = ans + ( (n // a) - 1)
else :
ans = ans + ( (n // a) )
# if n % a == 0 :
# ans = ans + ( (n / a) - 1 )
# else :
# ans = ans + ( (n // a) - 1 )
# ans = ans + (n / a) - 1
# print("A : {0}".format(a))
# while a * b < n:
# print("B : {0}".format(b))
# ans += 1
# b += 1
# c = 1
a += 1
b, c = 1, 1
# print("計算実行回数 : {0}".format(count))
print((ans - 1)) |
n = int(eval(input()))
ans = 0
a = 1
while a <= n:
if a == 1 :
ans = ans + (n - 1)
else :
if n % a == 0 :
ans = ans + ( (n // a) - 1)
else :
ans = ans + ( (n // a) )
a += 1
print(ans) | 53 | 20 | 860 | 265 | n = int(eval(input()))
ans = 0
count = 0
a, b, c = 1, 1, 1
while a <= n:
# print("A : {0}".format(a))
# print("追加パターン : {0}".format( (n // a) ))
if a == 1:
ans = ans + ((n // a) - 1)
else:
if n // a == 1:
ans = ans + 1
else:
if n % a == 0:
ans = ans + ((n // a) - 1)
else:
ans = ans + ((n // a))
# if n % a == 0 :
# ans = ans + ( (n / a) - 1 )
# else :
# ans = ans + ( (n // a) - 1 )
# ans = ans + (n / a) - 1
# print("A : {0}".format(a))
# while a * b < n:
# print("B : {0}".format(b))
# ans += 1
# b += 1
# c = 1
a += 1
b, c = 1, 1
# print("計算実行回数 : {0}".format(count))
print((ans - 1))
| n = int(eval(input()))
ans = 0
a = 1
while a <= n:
if a == 1:
ans = ans + (n - 1)
else:
if n % a == 0:
ans = ans + ((n // a) - 1)
else:
ans = ans + ((n // a))
a += 1
print(ans)
| false | 62.264151 | [
"-count = 0",
"-a, b, c = 1, 1, 1",
"+a = 1",
"- # print(\"A : {0}\".format(a))",
"- # print(\"追加パターン : {0}\".format( (n // a) ))",
"- ans = ans + ((n // a) - 1)",
"+ ans = ans + (n - 1)",
"- if n // a == 1:",
"- ans = ans + 1",
"+ if n % a == 0:",
"+ ans = ans + ((n // a) - 1)",
"- if n % a == 0:",
"- ans = ans + ((n // a) - 1)",
"- else:",
"- ans = ans + ((n // a))",
"- # if n % a == 0 :",
"- # ans = ans + ( (n / a) - 1 )",
"- # else :",
"- # ans = ans + ( (n // a) - 1 )",
"- # ans = ans + (n / a) - 1",
"- # print(\"A : {0}\".format(a))",
"- # while a * b < n:",
"- # print(\"B : {0}\".format(b))",
"- # ans += 1",
"- # b += 1",
"- # c = 1",
"+ ans = ans + ((n // a))",
"- b, c = 1, 1",
"-# print(\"計算実行回数 : {0}\".format(count))",
"-print((ans - 1))",
"+print(ans)"
] | false | 0.39541 | 0.27969 | 1.413745 | [
"s137209442",
"s815663188"
] |
u327532412 | p03160 | python | s194176007 | s093042353 | 131 | 118 | 20,640 | 20,444 | Accepted | Accepted | 9.92 | N = int(eval(input()))
*h, = list(map(int, input().split()))
dp = [0] * N
for i in range(1, N):
if i == 1:
dp[i] = dp[i-1] + abs(h[i] - h[i-1])
else:
dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))
print((dp[-1])) | N = int(eval(input()))
*h, = list(map(int, input().split()))
dp = [0] * N
dp[1] = abs(h[0] - h[1])
for i in range(2, N):
dp[i] = min(dp[i-2] + abs(h[i-2] - h[i]), dp[i-1] + abs(h[i-1] - h[i]))
print((dp[-1])) | 9 | 7 | 255 | 204 | N = int(eval(input()))
(*h,) = list(map(int, input().split()))
dp = [0] * N
for i in range(1, N):
if i == 1:
dp[i] = dp[i - 1] + abs(h[i] - h[i - 1])
else:
dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
print((dp[-1]))
| N = int(eval(input()))
(*h,) = list(map(int, input().split()))
dp = [0] * N
dp[1] = abs(h[0] - h[1])
for i in range(2, N):
dp[i] = min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i]))
print((dp[-1]))
| false | 22.222222 | [
"-for i in range(1, N):",
"- if i == 1:",
"- dp[i] = dp[i - 1] + abs(h[i] - h[i - 1])",
"- else:",
"- dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))",
"+dp[1] = abs(h[0] - h[1])",
"+for i in range(2, N):",
"+ dp[i] = min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i]))"
] | false | 0.036555 | 0.040242 | 0.908357 | [
"s194176007",
"s093042353"
] |
u729133443 | p03273 | python | s064663944 | s194474837 | 159 | 18 | 12,532 | 3,060 | Accepted | Accepted | 88.68 | from numpy import*
h,w=int8(input().split())
a=array(eval('list(input()),'*h))
print((*list(map(''.join,a[any(a<'.',1)][:,any(a<'.',0)])))) | f=lambda s:list(zip(*[t for t in s if'#'in t]));print((*list(map(''.join,f(f(open(0))))))) | 4 | 1 | 134 | 76 | from numpy import *
h, w = int8(input().split())
a = array(eval("list(input())," * h))
print((*list(map("".join, a[any(a < ".", 1)][:, any(a < ".", 0)]))))
| f = lambda s: list(zip(*[t for t in s if "#" in t]))
print((*list(map("".join, f(f(open(0)))))))
| false | 75 | [
"-from numpy import *",
"-",
"-h, w = int8(input().split())",
"-a = array(eval(\"list(input()),\" * h))",
"-print((*list(map(\"\".join, a[any(a < \".\", 1)][:, any(a < \".\", 0)]))))",
"+f = lambda s: list(zip(*[t for t in s if \"#\" in t]))",
"+print((*list(map(\"\".join, f(f(open(0)))))))"
] | false | 0.21245 | 0.037233 | 5.70591 | [
"s064663944",
"s194474837"
] |
u017810624 | p02925 | python | s415885255 | s543767970 | 981 | 639 | 54,236 | 53,980 | Accepted | Accepted | 34.86 | n=int(eval(input()));l=[list(map(int,input().split()))for i in[0]*n];a=[0 for i in[0]*n];d=1;k=n*(n-1)
while sum(a)<k and 0<d<9999:
L=[];y=0;d+=1
for i in range(n):
if a[i]<n-1:
x=l[i][a[i]]-1
if not(l[x][a[x]]-1!=i or x in L or i in L):
a[i]+=1;a[x]+=1;L+=[i,x];y=1
d*=y
print(([k//2,d-1][d<9999])) | n=int(eval(input()));l=[list(map(int,input().split()))for i in[0]*n];a=[0]*n;d=1;k=n*(n-1)
while sum(a)<k and 0<d<9999:
L=[0]*n;y=0;d+=1
for i in range(n):
if a[i]<n-1:
x=l[i][a[i]]-1
if l[x][a[x]]-1==i and L[x]+L[i]<1:
a[i]+=1;a[x]+=1;L[i]=L[x]=y=1
d*=y
print(([k//2,d-1][d<9999])) | 10 | 10 | 315 | 298 | n = int(eval(input()))
l = [list(map(int, input().split())) for i in [0] * n]
a = [0 for i in [0] * n]
d = 1
k = n * (n - 1)
while sum(a) < k and 0 < d < 9999:
L = []
y = 0
d += 1
for i in range(n):
if a[i] < n - 1:
x = l[i][a[i]] - 1
if not (l[x][a[x]] - 1 != i or x in L or i in L):
a[i] += 1
a[x] += 1
L += [i, x]
y = 1
d *= y
print(([k // 2, d - 1][d < 9999]))
| n = int(eval(input()))
l = [list(map(int, input().split())) for i in [0] * n]
a = [0] * n
d = 1
k = n * (n - 1)
while sum(a) < k and 0 < d < 9999:
L = [0] * n
y = 0
d += 1
for i in range(n):
if a[i] < n - 1:
x = l[i][a[i]] - 1
if l[x][a[x]] - 1 == i and L[x] + L[i] < 1:
a[i] += 1
a[x] += 1
L[i] = L[x] = y = 1
d *= y
print(([k // 2, d - 1][d < 9999]))
| false | 0 | [
"-a = [0 for i in [0] * n]",
"+a = [0] * n",
"- L = []",
"+ L = [0] * n",
"- if not (l[x][a[x]] - 1 != i or x in L or i in L):",
"+ if l[x][a[x]] - 1 == i and L[x] + L[i] < 1:",
"- L += [i, x]",
"- y = 1",
"+ L[i] = L[x] = y = 1"
] | false | 0.041498 | 0.036283 | 1.143727 | [
"s415885255",
"s543767970"
] |
u577170763 | p03162 | python | s035289746 | s690804195 | 319 | 276 | 54,124 | 42,860 | Accepted | Accepted | 13.48 | # import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
import sys
readline = sys.stdin.buffer.readline
geta = lambda fn: list(map(fn, readline().split()))
gete = lambda fn: fn(readline())
def main():
n=gete(int)
dp=[[0]*3 for _ in range(n+1)]
for i in range(n):
a,b,c = geta(int)
dp[i+1][0] = max(dp[i][1], dp[i][2]) + a
dp[i+1][1] = max(dp[i][2], dp[i][0]) + b
dp[i+1][2] = max(dp[i][0], dp[i][1]) + c
print((max(dp[n][0],dp[n][1],dp[n][2])))
if __name__ == "__main__":
main() | # import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
import sys
readline = sys.stdin.buffer.readline
geta = lambda fn: list(map(fn, readline().split()))
gete = lambda fn: fn(readline())
def main():
N = gete(int)
cur, prev = [0]*3, [0]*3
for _ in range(N):
a, b, c = geta(int)
prev, cur = cur, prev
cur[0] = max(prev[1], prev[2]) + a
cur[1] = max(prev[2], prev[0]) + b
cur[2] = max(prev[0], prev[1]) + c
print((max(cur)))
if __name__ == "__main__":
main() | 25 | 26 | 553 | 578 | # import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
import sys
readline = sys.stdin.buffer.readline
geta = lambda fn: list(map(fn, readline().split()))
gete = lambda fn: fn(readline())
def main():
n = gete(int)
dp = [[0] * 3 for _ in range(n + 1)]
for i in range(n):
a, b, c = geta(int)
dp[i + 1][0] = max(dp[i][1], dp[i][2]) + a
dp[i + 1][1] = max(dp[i][2], dp[i][0]) + b
dp[i + 1][2] = max(dp[i][0], dp[i][1]) + c
print((max(dp[n][0], dp[n][1], dp[n][2])))
if __name__ == "__main__":
main()
| # import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
import sys
readline = sys.stdin.buffer.readline
geta = lambda fn: list(map(fn, readline().split()))
gete = lambda fn: fn(readline())
def main():
N = gete(int)
cur, prev = [0] * 3, [0] * 3
for _ in range(N):
a, b, c = geta(int)
prev, cur = cur, prev
cur[0] = max(prev[1], prev[2]) + a
cur[1] = max(prev[2], prev[0]) + b
cur[2] = max(prev[0], prev[1]) + c
print((max(cur)))
if __name__ == "__main__":
main()
| false | 3.846154 | [
"- n = gete(int)",
"- dp = [[0] * 3 for _ in range(n + 1)]",
"- for i in range(n):",
"+ N = gete(int)",
"+ cur, prev = [0] * 3, [0] * 3",
"+ for _ in range(N):",
"- dp[i + 1][0] = max(dp[i][1], dp[i][2]) + a",
"- dp[i + 1][1] = max(dp[i][2], dp[i][0]) + b",
"- dp[i + 1][2] = max(dp[i][0], dp[i][1]) + c",
"- print((max(dp[n][0], dp[n][1], dp[n][2])))",
"+ prev, cur = cur, prev",
"+ cur[0] = max(prev[1], prev[2]) + a",
"+ cur[1] = max(prev[2], prev[0]) + b",
"+ cur[2] = max(prev[0], prev[1]) + c",
"+ print((max(cur)))"
] | false | 0.036797 | 0.035566 | 1.034631 | [
"s035289746",
"s690804195"
] |
u419877586 | p02780 | python | s508042017 | s716111823 | 250 | 183 | 75,784 | 24,812 | Accepted | Accepted | 26.8 | import itertools
N, K=list(map(int, input().split()))
p=list(map(int, input().split()))
acup=list(itertools.accumulate([(x+1)/2 for x in p]))
ans=acup[K-1]
for i in range(K, N):
ans=max(ans, acup[i]-acup[i-K])
print(ans) | N, K = list(map(int, input().split()))
p = list(map(int, input().split()))
exp = [(1+p[i])/2 for i in range(N)]
s = sum(exp[:K])
ans = s
for i in range(K, N):
s -= exp[i-K]
s += exp[i]
ans = max(ans, s)
print(ans) | 9 | 11 | 231 | 230 | import itertools
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))
acup = list(itertools.accumulate([(x + 1) / 2 for x in p]))
ans = acup[K - 1]
for i in range(K, N):
ans = max(ans, acup[i] - acup[i - K])
print(ans)
| N, K = list(map(int, input().split()))
p = list(map(int, input().split()))
exp = [(1 + p[i]) / 2 for i in range(N)]
s = sum(exp[:K])
ans = s
for i in range(K, N):
s -= exp[i - K]
s += exp[i]
ans = max(ans, s)
print(ans)
| false | 18.181818 | [
"-import itertools",
"-",
"-acup = list(itertools.accumulate([(x + 1) / 2 for x in p]))",
"-ans = acup[K - 1]",
"+exp = [(1 + p[i]) / 2 for i in range(N)]",
"+s = sum(exp[:K])",
"+ans = s",
"- ans = max(ans, acup[i] - acup[i - K])",
"+ s -= exp[i - K]",
"+ s += exp[i]",
"+ ans = max(ans, s)"
] | false | 0.03645 | 0.037905 | 0.961618 | [
"s508042017",
"s716111823"
] |
u707500405 | p03548 | python | s557125224 | s800106905 | 27 | 17 | 2,940 | 2,940 | Accepted | Accepted | 37.04 | X, Y, Z = list(map(int, input().split()))
ans = 1
while ans * (Y + Z) + Z <= X:
ans += 1
print((ans - 1))
| X, Y, Z = list(map(int, input().split()))
print(((X - Z) // (Y + Z)))
| 5 | 2 | 103 | 63 | X, Y, Z = list(map(int, input().split()))
ans = 1
while ans * (Y + Z) + Z <= X:
ans += 1
print((ans - 1))
| X, Y, Z = list(map(int, input().split()))
print(((X - Z) // (Y + Z)))
| false | 60 | [
"-ans = 1",
"-while ans * (Y + Z) + Z <= X:",
"- ans += 1",
"-print((ans - 1))",
"+print(((X - Z) // (Y + Z)))"
] | false | 0.139555 | 0.090801 | 1.536925 | [
"s557125224",
"s800106905"
] |
u249218427 | p02574 | python | s628488423 | s974047172 | 1,266 | 329 | 126,252 | 231,404 | Accepted | Accepted | 74.01 | N = int(eval(input()))
A = list(map(int, input().split()))
maxA = max(A)
counts = [0 for _ in range(maxA+1)]
for a in A:
counts[a] += 1
integers = [1 for _ in range(maxA+1)]
integers[0] = 0
integers[1] = 0
max_count = 0
for i in range(maxA+1):
if integers[i] >= 1:
count = 0
for j in range(i,maxA+1,i):
count += counts[j]
integers[j] = 0
max_count = max(max_count,count)
if max_count == N:
answer = 'not coprime'
elif max_count >= 2:
answer = 'setwise coprime'
else:
answer = 'pairwise coprime'
print(answer) | N = int(eval(input()))
A = list(map(int, input().split()))
M = 10**6 + 1
counts = [0 for _ in range(M)]
for a in A:
counts[a] += 1
integers = [1 for _ in range(M)]
integers[0] = 0
integers[1] = 0
max_count = 0
for i in range(M):
if integers[i] >= 1:
count = 0
for j in range(i,M,i):
count += counts[j]
integers[j] = 0
max_count = max(max_count,count)
if max_count == N:
answer = 'not coprime'
elif max_count >= 2:
answer = 'setwise coprime'
else:
answer = 'pairwise coprime'
print(answer) | 28 | 28 | 568 | 548 | N = int(eval(input()))
A = list(map(int, input().split()))
maxA = max(A)
counts = [0 for _ in range(maxA + 1)]
for a in A:
counts[a] += 1
integers = [1 for _ in range(maxA + 1)]
integers[0] = 0
integers[1] = 0
max_count = 0
for i in range(maxA + 1):
if integers[i] >= 1:
count = 0
for j in range(i, maxA + 1, i):
count += counts[j]
integers[j] = 0
max_count = max(max_count, count)
if max_count == N:
answer = "not coprime"
elif max_count >= 2:
answer = "setwise coprime"
else:
answer = "pairwise coprime"
print(answer)
| N = int(eval(input()))
A = list(map(int, input().split()))
M = 10**6 + 1
counts = [0 for _ in range(M)]
for a in A:
counts[a] += 1
integers = [1 for _ in range(M)]
integers[0] = 0
integers[1] = 0
max_count = 0
for i in range(M):
if integers[i] >= 1:
count = 0
for j in range(i, M, i):
count += counts[j]
integers[j] = 0
max_count = max(max_count, count)
if max_count == N:
answer = "not coprime"
elif max_count >= 2:
answer = "setwise coprime"
else:
answer = "pairwise coprime"
print(answer)
| false | 0 | [
"-maxA = max(A)",
"-counts = [0 for _ in range(maxA + 1)]",
"+M = 10**6 + 1",
"+counts = [0 for _ in range(M)]",
"-integers = [1 for _ in range(maxA + 1)]",
"+integers = [1 for _ in range(M)]",
"-for i in range(maxA + 1):",
"+for i in range(M):",
"- for j in range(i, maxA + 1, i):",
"+ for j in range(i, M, i):"
] | false | 0.074891 | 1.093013 | 0.068518 | [
"s628488423",
"s974047172"
] |
u976225138 | p03612 | python | s220602041 | s659808455 | 76 | 65 | 19,948 | 19,960 | Accepted | Accepted | 14.47 | n = int(eval(input()))
p = [int(x) for x in input().split()]
cnt = 0
for i in range(n):
if p[i] == i + 1:
cnt += 1
if i != n - 1:
p[i], p[i+1] = p[i+1], p[i]
else:
print(cnt) | n = int(eval(input()))
p = [int(x) for x in input().split()]
skip = False
cnt = 0
for i in range(n):
if skip:
skip = False
elif p[i] == i + 1:
cnt += 1
skip = True
else:
print(cnt) | 11 | 13 | 215 | 223 | n = int(eval(input()))
p = [int(x) for x in input().split()]
cnt = 0
for i in range(n):
if p[i] == i + 1:
cnt += 1
if i != n - 1:
p[i], p[i + 1] = p[i + 1], p[i]
else:
print(cnt)
| n = int(eval(input()))
p = [int(x) for x in input().split()]
skip = False
cnt = 0
for i in range(n):
if skip:
skip = False
elif p[i] == i + 1:
cnt += 1
skip = True
else:
print(cnt)
| false | 15.384615 | [
"+skip = False",
"- if p[i] == i + 1:",
"+ if skip:",
"+ skip = False",
"+ elif p[i] == i + 1:",
"- if i != n - 1:",
"- p[i], p[i + 1] = p[i + 1], p[i]",
"+ skip = True"
] | false | 0.113276 | 0.046853 | 2.417683 | [
"s220602041",
"s659808455"
] |
u970197315 | p03627 | python | s684777539 | s883036734 | 101 | 79 | 18,600 | 18,600 | Accepted | Accepted | 21.78 | from collections import Counter
n=eval(input())
a=list(map(int,input().split()))
a=Counter(a)
f,t=[],[]
for k in a:
if a[k]>=4:
f.append(k)
if a[k]>=2:
t.append(k)
# print('f:',f)
# print('t:',t)
ans1=0
for ff in f:
ans1=max(ans1,ff**2)
ans2=0
t.sort(reverse=True)
if len(t)>=2:
ans2=t[0]*t[1]
print((max(ans1,ans2)))
| from collections import Counter
n=int(eval(input()))
a=list(map(int,input().split()))
c=Counter(a)
l4,l2=[],[]
for k,v in list(c.items()):
if v>=4:l4.append(k)
if v>=2:l2.append(k)
l4.sort(reverse=True)
l2.sort(reverse=True)
if len(l4)<=2:l4+=[0,0]
if len(l2)<=2:l2+=[0,0]
print((max(l4[0]*l4[1],l4[0]*l2[0],l2[0]*l2[1])))
| 22 | 15 | 365 | 333 | from collections import Counter
n = eval(input())
a = list(map(int, input().split()))
a = Counter(a)
f, t = [], []
for k in a:
if a[k] >= 4:
f.append(k)
if a[k] >= 2:
t.append(k)
# print('f:',f)
# print('t:',t)
ans1 = 0
for ff in f:
ans1 = max(ans1, ff**2)
ans2 = 0
t.sort(reverse=True)
if len(t) >= 2:
ans2 = t[0] * t[1]
print((max(ans1, ans2)))
| from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
c = Counter(a)
l4, l2 = [], []
for k, v in list(c.items()):
if v >= 4:
l4.append(k)
if v >= 2:
l2.append(k)
l4.sort(reverse=True)
l2.sort(reverse=True)
if len(l4) <= 2:
l4 += [0, 0]
if len(l2) <= 2:
l2 += [0, 0]
print((max(l4[0] * l4[1], l4[0] * l2[0], l2[0] * l2[1])))
| false | 31.818182 | [
"-n = eval(input())",
"+n = int(eval(input()))",
"-a = Counter(a)",
"-f, t = [], []",
"-for k in a:",
"- if a[k] >= 4:",
"- f.append(k)",
"- if a[k] >= 2:",
"- t.append(k)",
"-# print('f:',f)",
"-# print('t:',t)",
"-ans1 = 0",
"-for ff in f:",
"- ans1 = max(ans1, ff**2)",
"-ans2 = 0",
"-t.sort(reverse=True)",
"-if len(t) >= 2:",
"- ans2 = t[0] * t[1]",
"-print((max(ans1, ans2)))",
"+c = Counter(a)",
"+l4, l2 = [], []",
"+for k, v in list(c.items()):",
"+ if v >= 4:",
"+ l4.append(k)",
"+ if v >= 2:",
"+ l2.append(k)",
"+l4.sort(reverse=True)",
"+l2.sort(reverse=True)",
"+if len(l4) <= 2:",
"+ l4 += [0, 0]",
"+if len(l2) <= 2:",
"+ l2 += [0, 0]",
"+print((max(l4[0] * l4[1], l4[0] * l2[0], l2[0] * l2[1])))"
] | false | 0.046692 | 0.04673 | 0.99918 | [
"s684777539",
"s883036734"
] |
u790710233 | p03102 | python | s995825468 | s457628921 | 162 | 17 | 13,160 | 2,940 | Accepted | Accepted | 89.51 | import numpy as np
n, m, c = list(map(int, input().split()))
b = np.array(list(map(int, input().split())))
ans = []
for i in range(n):
a = np.array(list(map(int, input().split())))
if b.dot(a)+c > 0:
ans.append(i+1)
print((len(ans)))
| n, m, c = list(map(int, input().split()))
b_l = list(map(int, input().split()))
ans = []
for i in range(n):
a_l = list(map(int, input().split()))
if sum(a*b for a, b in zip(a_l, b_l)) + c > 0:
ans.append(i)
print((len(ans)))
| 10 | 8 | 252 | 240 | import numpy as np
n, m, c = list(map(int, input().split()))
b = np.array(list(map(int, input().split())))
ans = []
for i in range(n):
a = np.array(list(map(int, input().split())))
if b.dot(a) + c > 0:
ans.append(i + 1)
print((len(ans)))
| n, m, c = list(map(int, input().split()))
b_l = list(map(int, input().split()))
ans = []
for i in range(n):
a_l = list(map(int, input().split()))
if sum(a * b for a, b in zip(a_l, b_l)) + c > 0:
ans.append(i)
print((len(ans)))
| false | 20 | [
"-import numpy as np",
"-",
"-b = np.array(list(map(int, input().split())))",
"+b_l = list(map(int, input().split()))",
"- a = np.array(list(map(int, input().split())))",
"- if b.dot(a) + c > 0:",
"- ans.append(i + 1)",
"+ a_l = list(map(int, input().split()))",
"+ if sum(a * b for a, b in zip(a_l, b_l)) + c > 0:",
"+ ans.append(i)"
] | false | 0.253695 | 0.037004 | 6.855807 | [
"s995825468",
"s457628921"
] |
u408260374 | p00874 | python | s570055819 | s803161223 | 40 | 20 | 7,880 | 6,624 | Accepted | Accepted | 50 | from collections import Counter
while True:
W, D = list(map(int, input().split()))
if not (W | D):
break
hw = [int(x) for x in input().split()]
hd = [int(x) for x in input().split()]
print((sum(hw) + sum(hd) - sum(k * v for k, v in list((Counter(hw) & Counter(hd)).items())))) | from collections import Counter
import sys
if sys.version[0] == '2':
range, input = xrange, raw_input
while True:
W, D = list(map(int, input().split()))
if not (W | D):
break
hw = [int(x) for x in input().split()]
hd = [int(x) for x in input().split()]
print((sum(hw) + sum(hd) - sum(k * v for k, v in list((Counter(hw) & Counter(hd)).items())))) | 8 | 11 | 297 | 374 | from collections import Counter
while True:
W, D = list(map(int, input().split()))
if not (W | D):
break
hw = [int(x) for x in input().split()]
hd = [int(x) for x in input().split()]
print(
(
sum(hw)
+ sum(hd)
- sum(k * v for k, v in list((Counter(hw) & Counter(hd)).items()))
)
)
| from collections import Counter
import sys
if sys.version[0] == "2":
range, input = xrange, raw_input
while True:
W, D = list(map(int, input().split()))
if not (W | D):
break
hw = [int(x) for x in input().split()]
hd = [int(x) for x in input().split()]
print(
(
sum(hw)
+ sum(hd)
- sum(k * v for k, v in list((Counter(hw) & Counter(hd)).items()))
)
)
| false | 27.272727 | [
"+import sys",
"+if sys.version[0] == \"2\":",
"+ range, input = xrange, raw_input"
] | false | 0.041968 | 0.042529 | 0.986788 | [
"s570055819",
"s803161223"
] |
u761320129 | p02889 | python | s139525732 | s304645917 | 1,861 | 1,086 | 96,348 | 99,992 | Accepted | Accepted | 41.64 | import sys
input = sys.stdin.readline
N,M,L = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]
Q = int(input())
ST = [tuple(map(int,input().split())) for i in range(Q)]
INF = 10**20
g = [[INF]*N for _ in range(N)]
for a,b,c in ABC:
a,b = a-1,b-1
g[a][b] = g[b][a] = c
for i in range(N):
g[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
if g[i][j] > g[i][k] + g[k][j]:
g[i][j] = g[i][k] + g[k][j]
h = [[N]*N for _ in range(N)]
for i in range(N-1):
for j in range(i+1,N):
if g[i][j] <= L:
h[i][j] = h[j][i] = 1
for i in range(N):
h[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
if h[i][j] > h[i][k] + h[k][j]:
h[i][j] = h[i][k] + h[k][j]
ans = []
for s,t in ST:
s,t = s-1,t-1
if h[s][t] == N:
ans.append(-1)
else:
ans.append(h[s][t] - 1)
print(*ans, sep='\n')
| import sys
input = sys.stdin.readline
N,M,L = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]
Q = int(input())
ST = [tuple(map(int,input().split())) for i in range(Q)]
INF = float('inf')
ds = [[INF]*N for i in range(N)]
for a,b,c in ABC:
a,b = a-1,b-1
ds[a][b] = ds[b][a] = c
for i in range(N):
ds[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
ds[i][j] = min(ds[i][j], ds[i][k]+ds[k][j])
ls = [[INF]*N for i in range(N)]
for i in range(N-1):
for j in range(i+1,N):
if ds[i][j] <= L:
ls[i][j] = ls[j][i] = 1
for i in range(N):
ls[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
ls[i][j] = min(ls[i][j], ls[i][k]+ls[k][j])
ans = []
for s,t in ST:
ans.append(-1 if ls[s-1][t-1]==INF else ls[s-1][t-1] - 1)
print(*ans, sep='\n')
| 41 | 37 | 1,023 | 932 | import sys
input = sys.stdin.readline
N, M, L = map(int, input().split())
ABC = [tuple(map(int, input().split())) for i in range(M)]
Q = int(input())
ST = [tuple(map(int, input().split())) for i in range(Q)]
INF = 10**20
g = [[INF] * N for _ in range(N)]
for a, b, c in ABC:
a, b = a - 1, b - 1
g[a][b] = g[b][a] = c
for i in range(N):
g[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
if g[i][j] > g[i][k] + g[k][j]:
g[i][j] = g[i][k] + g[k][j]
h = [[N] * N for _ in range(N)]
for i in range(N - 1):
for j in range(i + 1, N):
if g[i][j] <= L:
h[i][j] = h[j][i] = 1
for i in range(N):
h[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
if h[i][j] > h[i][k] + h[k][j]:
h[i][j] = h[i][k] + h[k][j]
ans = []
for s, t in ST:
s, t = s - 1, t - 1
if h[s][t] == N:
ans.append(-1)
else:
ans.append(h[s][t] - 1)
print(*ans, sep="\n")
| import sys
input = sys.stdin.readline
N, M, L = map(int, input().split())
ABC = [tuple(map(int, input().split())) for i in range(M)]
Q = int(input())
ST = [tuple(map(int, input().split())) for i in range(Q)]
INF = float("inf")
ds = [[INF] * N for i in range(N)]
for a, b, c in ABC:
a, b = a - 1, b - 1
ds[a][b] = ds[b][a] = c
for i in range(N):
ds[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j])
ls = [[INF] * N for i in range(N)]
for i in range(N - 1):
for j in range(i + 1, N):
if ds[i][j] <= L:
ls[i][j] = ls[j][i] = 1
for i in range(N):
ls[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
ls[i][j] = min(ls[i][j], ls[i][k] + ls[k][j])
ans = []
for s, t in ST:
ans.append(-1 if ls[s - 1][t - 1] == INF else ls[s - 1][t - 1] - 1)
print(*ans, sep="\n")
| false | 9.756098 | [
"-INF = 10**20",
"-g = [[INF] * N for _ in range(N)]",
"+INF = float(\"inf\")",
"+ds = [[INF] * N for i in range(N)]",
"- g[a][b] = g[b][a] = c",
"+ ds[a][b] = ds[b][a] = c",
"- g[i][i] = 0",
"+ ds[i][i] = 0",
"- if g[i][j] > g[i][k] + g[k][j]:",
"- g[i][j] = g[i][k] + g[k][j]",
"-h = [[N] * N for _ in range(N)]",
"+ ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j])",
"+ls = [[INF] * N for i in range(N)]",
"- if g[i][j] <= L:",
"- h[i][j] = h[j][i] = 1",
"+ if ds[i][j] <= L:",
"+ ls[i][j] = ls[j][i] = 1",
"- h[i][i] = 0",
"+ ls[i][i] = 0",
"- if h[i][j] > h[i][k] + h[k][j]:",
"- h[i][j] = h[i][k] + h[k][j]",
"+ ls[i][j] = min(ls[i][j], ls[i][k] + ls[k][j])",
"- s, t = s - 1, t - 1",
"- if h[s][t] == N:",
"- ans.append(-1)",
"- else:",
"- ans.append(h[s][t] - 1)",
"+ ans.append(-1 if ls[s - 1][t - 1] == INF else ls[s - 1][t - 1] - 1)"
] | false | 0.038447 | 0.037493 | 1.025459 | [
"s139525732",
"s304645917"
] |
u561083515 | p03963 | python | s020703046 | s679503467 | 18 | 16 | 2,940 | 2,940 | Accepted | Accepted | 11.11 | N,K = [int(i) for i in input().split()]
ans = K
for _ in range(N-1):
ans *= K - 1
print(ans) | N,K = list(map(int, input().split()))
ans = K
for _ in range(N - 1):
ans *= K - 1
print(ans) | 7 | 6 | 104 | 96 | N, K = [int(i) for i in input().split()]
ans = K
for _ in range(N - 1):
ans *= K - 1
print(ans)
| N, K = list(map(int, input().split()))
ans = K
for _ in range(N - 1):
ans *= K - 1
print(ans)
| false | 14.285714 | [
"-N, K = [int(i) for i in input().split()]",
"+N, K = list(map(int, input().split()))"
] | false | 0.037043 | 0.042989 | 0.8617 | [
"s020703046",
"s679503467"
] |
u609061751 | p02921 | python | s643466205 | s042229459 | 170 | 17 | 38,460 | 2,940 | Accepted | Accepted | 90 | S=list(eval(input()))
T=list(eval(input()))
cnt = 0
for i in range(3):
if S[i] == T[i]:
cnt += 1
print(cnt) | import sys
input = sys.stdin.readline
s = input().rstrip()
t = input().rstrip()
cnt = 0
for i in range(3):
if s[i] == t[i]:
cnt += 1
print(cnt)
| 7 | 15 | 113 | 179 | S = list(eval(input()))
T = list(eval(input()))
cnt = 0
for i in range(3):
if S[i] == T[i]:
cnt += 1
print(cnt)
| import sys
input = sys.stdin.readline
s = input().rstrip()
t = input().rstrip()
cnt = 0
for i in range(3):
if s[i] == t[i]:
cnt += 1
print(cnt)
| false | 53.333333 | [
"-S = list(eval(input()))",
"-T = list(eval(input()))",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+s = input().rstrip()",
"+t = input().rstrip()",
"- if S[i] == T[i]:",
"+ if s[i] == t[i]:"
] | false | 0.121572 | 0.041995 | 2.894903 | [
"s643466205",
"s042229459"
] |
u163320134 | p02616 | python | s942942420 | s771488515 | 237 | 199 | 31,636 | 31,696 | Accepted | Accepted | 16.03 | mod=10**9+7
n,k=list(map(int,input().split()))
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True,key=lambda x:abs(x))
if k==n:
ans=1
for i in range(n):
ans*=arr[i]
ans%=mod
print(ans)
else:
if k%2==1 and max(arr)<0:
ans=1
for i in range(k):
ans*=arr[n-1-i]
ans%=mod
print(ans)
else:
ans=1
cnt=0
for i in range(k):
if arr[i]<0:
cnt+=1
ans*=arr[i]
ans%=mod
if cnt%2==0:
print(ans)
else:
min_plus=-1
min_minus=1
for i in range(k):
if arr[i]>=0:
min_plus=arr[i]
else:
min_minus=arr[i]
max_plus=-1
max_minus=1
for i in range(k,n):
if arr[i]>=0 and max_plus==-1:
max_plus=arr[i]
if arr[i]<0 and max_minus==1:
max_minus=arr[i]
if min_plus==-1:
arr.remove(min_minus)
ans=1
for i in range(k-1):
ans*=arr[i]
ans%=mod
ans*=max_plus
ans%=mod
elif min_minus==1:
arr.remove(min_plus)
ans=1
for i in range(k-1):
ans*=arr[i]
ans%=mod
ans*=max_minus
ans%=mod
elif min_plus*max_plus>=min_minus*max_minus:
arr.remove(min_minus)
ans=1
for i in range(k-1):
ans*=arr[i]
ans%=mod
ans*=max_plus
ans%=mod
else:
arr.remove(min_plus)
ans=1
for i in range(k-1):
ans*=arr[i]
ans%=mod
ans*=max_minus
ans%=mod
print(ans) | mod=10**9+7
n,k=list(map(int,input().split()))
arr=list(map(int,input().split()))
cnt_plus=0
cnt_zero=0
cnt_minus=0
arr_plus=[]
arr_minus=[]
for i in range(n):
if arr[i]>0:
cnt_plus+=1
arr_plus.append(arr[i])
elif arr[i]<0:
cnt_minus+=1
arr_minus.append(-arr[i])
else:
cnt_zero+=1
if cnt_plus+cnt_minus<k:
print((0))
exit()
if k==n:
if cnt_zero!=0:
print((0))
else:
ans=1
for i in range(cnt_plus):
ans*=arr_plus[i]
ans%=mod
for i in range(cnt_minus):
ans*=arr_minus[i]
ans%=mod
if cnt_minus%2==0:
print(ans)
else:
print(((-ans)%mod))
exit()
if cnt_plus==0 and k%2==1:
if cnt_zero!=0:
print((0))
else:
arr_minus=sorted(arr_minus)
tmp=1
for i in range(k):
tmp*=arr_minus[i]
tmp%=mod
print(((-tmp)%mod))
exit()
else:
arr_plus=sorted(arr_plus,reverse=True)
arr_minus=sorted(arr_minus,reverse=True)
if k%2==0:
ans=1
pos_plus=0
pos_minus=0
cnt=0
while cnt<k:
cand1=0
if pos_plus<=cnt_plus-2:
cand1=arr_plus[pos_plus]*arr_plus[pos_plus+1]
cand2=0
if pos_minus<=cnt_minus-2:
cand2=arr_minus[pos_minus]*arr_minus[pos_minus+1]
if cand1>=cand2:
pos_plus+=2
ans*=cand1
ans%=mod
else:
pos_minus+=2
ans*=cand2
ans%=mod
cnt+=2
print(ans)
else:
ans=arr_plus[0]
pos_plus=1
pos_minus=0
cnt=1
while cnt<k:
cand1=0
if pos_plus<=cnt_plus-2:
cand1=arr_plus[pos_plus]*arr_plus[pos_plus+1]
cand2=0
if pos_minus<=cnt_minus-2:
cand2=arr_minus[pos_minus]*arr_minus[pos_minus+1]
if cand1>=cand2:
pos_plus+=2
ans*=cand1
ans%=mod
else:
pos_minus+=2
ans*=cand2
ans%=mod
cnt+=2
print(ans)
exit() | 75 | 95 | 1,658 | 1,957 | mod = 10**9 + 7
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr = sorted(arr, reverse=True, key=lambda x: abs(x))
if k == n:
ans = 1
for i in range(n):
ans *= arr[i]
ans %= mod
print(ans)
else:
if k % 2 == 1 and max(arr) < 0:
ans = 1
for i in range(k):
ans *= arr[n - 1 - i]
ans %= mod
print(ans)
else:
ans = 1
cnt = 0
for i in range(k):
if arr[i] < 0:
cnt += 1
ans *= arr[i]
ans %= mod
if cnt % 2 == 0:
print(ans)
else:
min_plus = -1
min_minus = 1
for i in range(k):
if arr[i] >= 0:
min_plus = arr[i]
else:
min_minus = arr[i]
max_plus = -1
max_minus = 1
for i in range(k, n):
if arr[i] >= 0 and max_plus == -1:
max_plus = arr[i]
if arr[i] < 0 and max_minus == 1:
max_minus = arr[i]
if min_plus == -1:
arr.remove(min_minus)
ans = 1
for i in range(k - 1):
ans *= arr[i]
ans %= mod
ans *= max_plus
ans %= mod
elif min_minus == 1:
arr.remove(min_plus)
ans = 1
for i in range(k - 1):
ans *= arr[i]
ans %= mod
ans *= max_minus
ans %= mod
elif min_plus * max_plus >= min_minus * max_minus:
arr.remove(min_minus)
ans = 1
for i in range(k - 1):
ans *= arr[i]
ans %= mod
ans *= max_plus
ans %= mod
else:
arr.remove(min_plus)
ans = 1
for i in range(k - 1):
ans *= arr[i]
ans %= mod
ans *= max_minus
ans %= mod
print(ans)
| mod = 10**9 + 7
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
cnt_plus = 0
cnt_zero = 0
cnt_minus = 0
arr_plus = []
arr_minus = []
for i in range(n):
if arr[i] > 0:
cnt_plus += 1
arr_plus.append(arr[i])
elif arr[i] < 0:
cnt_minus += 1
arr_minus.append(-arr[i])
else:
cnt_zero += 1
if cnt_plus + cnt_minus < k:
print((0))
exit()
if k == n:
if cnt_zero != 0:
print((0))
else:
ans = 1
for i in range(cnt_plus):
ans *= arr_plus[i]
ans %= mod
for i in range(cnt_minus):
ans *= arr_minus[i]
ans %= mod
if cnt_minus % 2 == 0:
print(ans)
else:
print(((-ans) % mod))
exit()
if cnt_plus == 0 and k % 2 == 1:
if cnt_zero != 0:
print((0))
else:
arr_minus = sorted(arr_minus)
tmp = 1
for i in range(k):
tmp *= arr_minus[i]
tmp %= mod
print(((-tmp) % mod))
exit()
else:
arr_plus = sorted(arr_plus, reverse=True)
arr_minus = sorted(arr_minus, reverse=True)
if k % 2 == 0:
ans = 1
pos_plus = 0
pos_minus = 0
cnt = 0
while cnt < k:
cand1 = 0
if pos_plus <= cnt_plus - 2:
cand1 = arr_plus[pos_plus] * arr_plus[pos_plus + 1]
cand2 = 0
if pos_minus <= cnt_minus - 2:
cand2 = arr_minus[pos_minus] * arr_minus[pos_minus + 1]
if cand1 >= cand2:
pos_plus += 2
ans *= cand1
ans %= mod
else:
pos_minus += 2
ans *= cand2
ans %= mod
cnt += 2
print(ans)
else:
ans = arr_plus[0]
pos_plus = 1
pos_minus = 0
cnt = 1
while cnt < k:
cand1 = 0
if pos_plus <= cnt_plus - 2:
cand1 = arr_plus[pos_plus] * arr_plus[pos_plus + 1]
cand2 = 0
if pos_minus <= cnt_minus - 2:
cand2 = arr_minus[pos_minus] * arr_minus[pos_minus + 1]
if cand1 >= cand2:
pos_plus += 2
ans *= cand1
ans %= mod
else:
pos_minus += 2
ans *= cand2
ans %= mod
cnt += 2
print(ans)
exit()
| false | 21.052632 | [
"-arr = sorted(arr, reverse=True, key=lambda x: abs(x))",
"+cnt_plus = 0",
"+cnt_zero = 0",
"+cnt_minus = 0",
"+arr_plus = []",
"+arr_minus = []",
"+for i in range(n):",
"+ if arr[i] > 0:",
"+ cnt_plus += 1",
"+ arr_plus.append(arr[i])",
"+ elif arr[i] < 0:",
"+ cnt_minus += 1",
"+ arr_minus.append(-arr[i])",
"+ else:",
"+ cnt_zero += 1",
"+if cnt_plus + cnt_minus < k:",
"+ print((0))",
"+ exit()",
"- ans = 1",
"- for i in range(n):",
"- ans *= arr[i]",
"- ans %= mod",
"- print(ans)",
"+ if cnt_zero != 0:",
"+ print((0))",
"+ else:",
"+ ans = 1",
"+ for i in range(cnt_plus):",
"+ ans *= arr_plus[i]",
"+ ans %= mod",
"+ for i in range(cnt_minus):",
"+ ans *= arr_minus[i]",
"+ ans %= mod",
"+ if cnt_minus % 2 == 0:",
"+ print(ans)",
"+ else:",
"+ print(((-ans) % mod))",
"+ exit()",
"+if cnt_plus == 0 and k % 2 == 1:",
"+ if cnt_zero != 0:",
"+ print((0))",
"+ else:",
"+ arr_minus = sorted(arr_minus)",
"+ tmp = 1",
"+ for i in range(k):",
"+ tmp *= arr_minus[i]",
"+ tmp %= mod",
"+ print(((-tmp) % mod))",
"+ exit()",
"- if k % 2 == 1 and max(arr) < 0:",
"+ arr_plus = sorted(arr_plus, reverse=True)",
"+ arr_minus = sorted(arr_minus, reverse=True)",
"+ if k % 2 == 0:",
"- for i in range(k):",
"- ans *= arr[n - 1 - i]",
"- ans %= mod",
"+ pos_plus = 0",
"+ pos_minus = 0",
"+ cnt = 0",
"+ while cnt < k:",
"+ cand1 = 0",
"+ if pos_plus <= cnt_plus - 2:",
"+ cand1 = arr_plus[pos_plus] * arr_plus[pos_plus + 1]",
"+ cand2 = 0",
"+ if pos_minus <= cnt_minus - 2:",
"+ cand2 = arr_minus[pos_minus] * arr_minus[pos_minus + 1]",
"+ if cand1 >= cand2:",
"+ pos_plus += 2",
"+ ans *= cand1",
"+ ans %= mod",
"+ else:",
"+ pos_minus += 2",
"+ ans *= cand2",
"+ ans %= mod",
"+ cnt += 2",
"- ans = 1",
"- cnt = 0",
"- for i in range(k):",
"- if arr[i] < 0:",
"- cnt += 1",
"- ans *= arr[i]",
"- ans %= mod",
"- if cnt % 2 == 0:",
"- print(ans)",
"- else:",
"- min_plus = -1",
"- min_minus = 1",
"- for i in range(k):",
"- if arr[i] >= 0:",
"- min_plus = arr[i]",
"- else:",
"- min_minus = arr[i]",
"- max_plus = -1",
"- max_minus = 1",
"- for i in range(k, n):",
"- if arr[i] >= 0 and max_plus == -1:",
"- max_plus = arr[i]",
"- if arr[i] < 0 and max_minus == 1:",
"- max_minus = arr[i]",
"- if min_plus == -1:",
"- arr.remove(min_minus)",
"- ans = 1",
"- for i in range(k - 1):",
"- ans *= arr[i]",
"- ans %= mod",
"- ans *= max_plus",
"- ans %= mod",
"- elif min_minus == 1:",
"- arr.remove(min_plus)",
"- ans = 1",
"- for i in range(k - 1):",
"- ans *= arr[i]",
"- ans %= mod",
"- ans *= max_minus",
"- ans %= mod",
"- elif min_plus * max_plus >= min_minus * max_minus:",
"- arr.remove(min_minus)",
"- ans = 1",
"- for i in range(k - 1):",
"- ans *= arr[i]",
"- ans %= mod",
"- ans *= max_plus",
"+ ans = arr_plus[0]",
"+ pos_plus = 1",
"+ pos_minus = 0",
"+ cnt = 1",
"+ while cnt < k:",
"+ cand1 = 0",
"+ if pos_plus <= cnt_plus - 2:",
"+ cand1 = arr_plus[pos_plus] * arr_plus[pos_plus + 1]",
"+ cand2 = 0",
"+ if pos_minus <= cnt_minus - 2:",
"+ cand2 = arr_minus[pos_minus] * arr_minus[pos_minus + 1]",
"+ if cand1 >= cand2:",
"+ pos_plus += 2",
"+ ans *= cand1",
"- arr.remove(min_plus)",
"- ans = 1",
"- for i in range(k - 1):",
"- ans *= arr[i]",
"- ans %= mod",
"- ans *= max_minus",
"+ pos_minus += 2",
"+ ans *= cand2",
"- print(ans)",
"+ cnt += 2",
"+ print(ans)",
"+ exit()"
] | false | 0.0721 | 0.09509 | 0.758226 | [
"s942942420",
"s771488515"
] |
u562935282 | p03579 | python | s817793622 | s070567474 | 789 | 580 | 75,500 | 35,216 | Accepted | Accepted | 26.49 | from collections import deque
n, m = list(map(int, input().split()))
e = [set() for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
e[a].add(b)
e[b].add(a)
dq = deque()
dq.append(0)
p = [None] * n
p[0] = 0
is_bipartite = True
while dq:
v = dq.popleft()
for u in e[v]:
if p[u] is None:
p[u] = 1 ^ p[v]
dq.append(u)
elif p[u] == p[v]:
is_bipartite = False
break
else:
# p[u] == p[v] ^ 1
pass
if is_bipartite:
# 同じ色の頂点には辺を張らない
sp = sum(p)
print((sp * (n - sp) - m))
else:
# 全ての頂点間に辺を張る
print((n * (n - 1) // 2 - m))
| from collections import deque
n, m = list(map(int, input().split()))
g = [set() for _ in range(n)]
for _ in range(m):
a, b = (int(x) - 1 for x in input().split())
g[a].add(b)
g[b].add(a)
par = [-1] * n
def is_bipartite():
dq = deque()
dq.append(0)
par[0] = 0
while dq:
v = dq.popleft()
for u in g[v]:
if par[u] != -1:
if par[u] == (par[v] ^ 1):
continue
else:
return False
else:
par[u] = (par[v] ^ 1)
dq.append(u)
return True
if is_bipartite():
# print('bipartite', par)
evens = par.count(0)
odds = n - evens
print((odds * evens - m))
else:
# print('not bipartite', par)
print((n * (n - 1) // 2 - m))
# 全ての奇数路にパスが張れる
# 1 : 既に張られている
# 3 : 張れる
# >= 5 : 途中に長さ3のパスを張ると長さが2減るので、奇数のまま2ずつ減らして3になる
# 二部グラフでない場合、奇サイクルが存在するので、
# 偶数路だったパスには、奇サイクルを挟んだ奇数路がある
# すべての頂点間にパスが張れる
| 39 | 49 | 724 | 1,011 | from collections import deque
n, m = list(map(int, input().split()))
e = [set() for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
e[a].add(b)
e[b].add(a)
dq = deque()
dq.append(0)
p = [None] * n
p[0] = 0
is_bipartite = True
while dq:
v = dq.popleft()
for u in e[v]:
if p[u] is None:
p[u] = 1 ^ p[v]
dq.append(u)
elif p[u] == p[v]:
is_bipartite = False
break
else:
# p[u] == p[v] ^ 1
pass
if is_bipartite:
# 同じ色の頂点には辺を張らない
sp = sum(p)
print((sp * (n - sp) - m))
else:
# 全ての頂点間に辺を張る
print((n * (n - 1) // 2 - m))
| from collections import deque
n, m = list(map(int, input().split()))
g = [set() for _ in range(n)]
for _ in range(m):
a, b = (int(x) - 1 for x in input().split())
g[a].add(b)
g[b].add(a)
par = [-1] * n
def is_bipartite():
dq = deque()
dq.append(0)
par[0] = 0
while dq:
v = dq.popleft()
for u in g[v]:
if par[u] != -1:
if par[u] == (par[v] ^ 1):
continue
else:
return False
else:
par[u] = par[v] ^ 1
dq.append(u)
return True
if is_bipartite():
# print('bipartite', par)
evens = par.count(0)
odds = n - evens
print((odds * evens - m))
else:
# print('not bipartite', par)
print((n * (n - 1) // 2 - m))
# 全ての奇数路にパスが張れる
# 1 : 既に張られている
# 3 : 張れる
# >= 5 : 途中に長さ3のパスを張ると長さが2減るので、奇数のまま2ずつ減らして3になる
# 二部グラフでない場合、奇サイクルが存在するので、
# 偶数路だったパスには、奇サイクルを挟んだ奇数路がある
# すべての頂点間にパスが張れる
| false | 20.408163 | [
"-e = [set() for _ in range(n)]",
"+g = [set() for _ in range(n)]",
"- a, b = list(map(int, input().split()))",
"- a -= 1",
"- b -= 1",
"- e[a].add(b)",
"- e[b].add(a)",
"-dq = deque()",
"-dq.append(0)",
"-p = [None] * n",
"-p[0] = 0",
"-is_bipartite = True",
"-while dq:",
"- v = dq.popleft()",
"- for u in e[v]:",
"- if p[u] is None:",
"- p[u] = 1 ^ p[v]",
"- dq.append(u)",
"- elif p[u] == p[v]:",
"- is_bipartite = False",
"- break",
"- else:",
"- # p[u] == p[v] ^ 1",
"- pass",
"-if is_bipartite:",
"- # 同じ色の頂点には辺を張らない",
"- sp = sum(p)",
"- print((sp * (n - sp) - m))",
"+ a, b = (int(x) - 1 for x in input().split())",
"+ g[a].add(b)",
"+ g[b].add(a)",
"+par = [-1] * n",
"+",
"+",
"+def is_bipartite():",
"+ dq = deque()",
"+ dq.append(0)",
"+ par[0] = 0",
"+ while dq:",
"+ v = dq.popleft()",
"+ for u in g[v]:",
"+ if par[u] != -1:",
"+ if par[u] == (par[v] ^ 1):",
"+ continue",
"+ else:",
"+ return False",
"+ else:",
"+ par[u] = par[v] ^ 1",
"+ dq.append(u)",
"+ return True",
"+",
"+",
"+if is_bipartite():",
"+ # print('bipartite', par)",
"+ evens = par.count(0)",
"+ odds = n - evens",
"+ print((odds * evens - m))",
"- # 全ての頂点間に辺を張る",
"+ # print('not bipartite', par)",
"+# 全ての奇数路にパスが張れる",
"+# 1 : 既に張られている",
"+# 3 : 張れる",
"+# >= 5 : 途中に長さ3のパスを張ると長さが2減るので、奇数のまま2ずつ減らして3になる",
"+# 二部グラフでない場合、奇サイクルが存在するので、",
"+# 偶数路だったパスには、奇サイクルを挟んだ奇数路がある",
"+# すべての頂点間にパスが張れる"
] | false | 0.036598 | 0.0331 | 1.105695 | [
"s817793622",
"s070567474"
] |
u159994501 | p03127 | python | s578724354 | s151008987 | 126 | 85 | 14,252 | 14,252 | Accepted | Accepted | 32.54 | def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
N = int(eval(input()))
A = list(map(int,input().split()))
A.sort(reverse=True)
a = A[0]
for i in range(1,N):
a = gcd(a,A[i])
print(a)
| def gcd(a, b):
if b > a:
a,b = b,a
if b == 0:
return a
else:
return gcd(b, a % b)
N = int(eval(input()))
A = list(map(int,input().split()))
a = A[0]
for i in range(1,N):
a = gcd(a,A[i])
print(a)
| 12 | 13 | 229 | 241 | def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
a = A[0]
for i in range(1, N):
a = gcd(a, A[i])
print(a)
| def gcd(a, b):
if b > a:
a, b = b, a
if b == 0:
return a
else:
return gcd(b, a % b)
N = int(eval(input()))
A = list(map(int, input().split()))
a = A[0]
for i in range(1, N):
a = gcd(a, A[i])
print(a)
| false | 7.692308 | [
"+ if b > a:",
"+ a, b = b, a",
"-A.sort(reverse=True)"
] | false | 0.081472 | 0.035657 | 2.284901 | [
"s578724354",
"s151008987"
] |
u260036763 | p02713 | python | s154165344 | s165609397 | 1,901 | 446 | 9,576 | 9,568 | Accepted | Accepted | 76.54 | import math
# from itertools import product
from functools import reduce
def main():
# def gcd(*numbers): return reduce(math.gcd, numbers)
K = int(eval(input()))
ans = 0
# valiation = list(itertools.product(range(1, K+1), repeat=3))
# for v in valiation:
# ans += gcd(v)
for i in range(1, K+1):
for j in range(1, K+1):
for k in range(1, K+1):
ans += math.gcd(math.gcd(i, j), k)
print(ans)
if __name__ == '__main__':
main() | import math
# from itertools import product
from functools import reduce
def main():
# def gcd(*numbers): return reduce(math.gcd, numbers)
K = int(eval(input()))
ans = 0
# valiation = list(itertools.product(range(1, K+1), repeat=3))
# for v in valiation:
# ans += gcd(v)
for i in range(1, K+1):
for j in range(i, K+1):
for k in range(j, K+1):
x = math.gcd(math.gcd(i, j), k)
if i == j == k:
ans += x
elif i != j and j != k and k != i:
ans += 6 * x
else:
ans += 3 * x
print(ans)
if __name__ == '__main__':
main() | 20 | 26 | 526 | 729 | import math
# from itertools import product
from functools import reduce
def main():
# def gcd(*numbers): return reduce(math.gcd, numbers)
K = int(eval(input()))
ans = 0
# valiation = list(itertools.product(range(1, K+1), repeat=3))
# for v in valiation:
# ans += gcd(v)
for i in range(1, K + 1):
for j in range(1, K + 1):
for k in range(1, K + 1):
ans += math.gcd(math.gcd(i, j), k)
print(ans)
if __name__ == "__main__":
main()
| import math
# from itertools import product
from functools import reduce
def main():
# def gcd(*numbers): return reduce(math.gcd, numbers)
K = int(eval(input()))
ans = 0
# valiation = list(itertools.product(range(1, K+1), repeat=3))
# for v in valiation:
# ans += gcd(v)
for i in range(1, K + 1):
for j in range(i, K + 1):
for k in range(j, K + 1):
x = math.gcd(math.gcd(i, j), k)
if i == j == k:
ans += x
elif i != j and j != k and k != i:
ans += 6 * x
else:
ans += 3 * x
print(ans)
if __name__ == "__main__":
main()
| false | 23.076923 | [
"- for j in range(1, K + 1):",
"- for k in range(1, K + 1):",
"- ans += math.gcd(math.gcd(i, j), k)",
"+ for j in range(i, K + 1):",
"+ for k in range(j, K + 1):",
"+ x = math.gcd(math.gcd(i, j), k)",
"+ if i == j == k:",
"+ ans += x",
"+ elif i != j and j != k and k != i:",
"+ ans += 6 * x",
"+ else:",
"+ ans += 3 * x"
] | false | 0.11196 | 0.053914 | 2.076629 | [
"s154165344",
"s165609397"
] |
u124498235 | p02813 | python | s255668768 | s290131957 | 114 | 98 | 3,064 | 6,040 | Accepted | Accepted | 14.04 | import itertools
n = int(eval(input()))
p = list(map(int, input().split()))
pp = "".join((str(n) for n in p))
q = list(map(int, input().split()))
qq = "".join((str(n) for n in q))
a = [i+1 for i in range(n)]
b = 0
c = 0
d = 0
for i in itertools.permutations(a):
d += 1
x = "".join((str(n) for n in i))
if pp == x:
b = d
if qq == x:
c = d
print((abs(b-c))) | import itertools
n = int(eval(input()))
p = list(map(int, input().split()))
pp = "".join([str(i) for i in p])
q = list(map(int, input().split()))
qq = "".join([str(i) for i in q])
x = [i+1 for i in range(n)]
z = []
for v in itertools.permutations(x):
y = "".join([str(i) for i in v])
z.append(y)
a = z.index(pp)
b = z.index(qq)
print((abs(a-b))) | 18 | 14 | 373 | 353 | import itertools
n = int(eval(input()))
p = list(map(int, input().split()))
pp = "".join((str(n) for n in p))
q = list(map(int, input().split()))
qq = "".join((str(n) for n in q))
a = [i + 1 for i in range(n)]
b = 0
c = 0
d = 0
for i in itertools.permutations(a):
d += 1
x = "".join((str(n) for n in i))
if pp == x:
b = d
if qq == x:
c = d
print((abs(b - c)))
| import itertools
n = int(eval(input()))
p = list(map(int, input().split()))
pp = "".join([str(i) for i in p])
q = list(map(int, input().split()))
qq = "".join([str(i) for i in q])
x = [i + 1 for i in range(n)]
z = []
for v in itertools.permutations(x):
y = "".join([str(i) for i in v])
z.append(y)
a = z.index(pp)
b = z.index(qq)
print((abs(a - b)))
| false | 22.222222 | [
"-pp = \"\".join((str(n) for n in p))",
"+pp = \"\".join([str(i) for i in p])",
"-qq = \"\".join((str(n) for n in q))",
"-a = [i + 1 for i in range(n)]",
"-b = 0",
"-c = 0",
"-d = 0",
"-for i in itertools.permutations(a):",
"- d += 1",
"- x = \"\".join((str(n) for n in i))",
"- if pp == x:",
"- b = d",
"- if qq == x:",
"- c = d",
"-print((abs(b - c)))",
"+qq = \"\".join([str(i) for i in q])",
"+x = [i + 1 for i in range(n)]",
"+z = []",
"+for v in itertools.permutations(x):",
"+ y = \"\".join([str(i) for i in v])",
"+ z.append(y)",
"+a = z.index(pp)",
"+b = z.index(qq)",
"+print((abs(a - b)))"
] | false | 0.049455 | 0.048639 | 1.01677 | [
"s255668768",
"s290131957"
] |
u780962115 | p02838 | python | s234456965 | s030985985 | 1,948 | 1,164 | 38,968 | 178,600 | Accepted | Accepted | 40.25 | import sys
input=sys.stdin.readline
n=int(eval(input()))
lists=list(map(int,input().split()))
length=61
use=[0 for i in range(61)]
a,b=divmod(n,9)
anslist=[0 for i in range(a+1)]
for j in range(n):
k=format(lists[j],"0%ib"%length)
k=k[::-1]
p,q=divmod(j,9)
if p>a:
anslist.append(str(k))
else:
anslist[p]+=int(k)
answer=0
for some in anslist:
some=str(some)
some=some.zfill(61)
for j in range(61):
if int(some[j])!=0:
use[j]+=int(some[j])
for j in range(61):
answer+=(2**j)*use[j]*(n-use[j])%(10**9+7)
print((answer%(10**9+7)))
| #昔はtleの回答、今は通る?
import sys
input=sys.stdin.readline
n=int(eval(input()))
lists=list(map(int,input().split()))
aa=[0 for i in range(n)]
bb=[0 for i in range(n)]
length=61
use=[0 for i in range(61)]
for j in range(n):
k=format(lists[j],"0%ib"%length)
k=k[::-1]
aa[j]=k[:30]
bb[j]=k[30:]
for p in aa:
for some in range(30):
use[some]+=int(p[some])
for q in bb:
for some in range(31):
use[some+30]+=int(q[some])
answer=0
for j in range(61):
answer+=(2**j)*use[j]*(n-use[j])%(10**9+7)
print((answer%(10**9+7)))
| 27 | 25 | 620 | 578 | import sys
input = sys.stdin.readline
n = int(eval(input()))
lists = list(map(int, input().split()))
length = 61
use = [0 for i in range(61)]
a, b = divmod(n, 9)
anslist = [0 for i in range(a + 1)]
for j in range(n):
k = format(lists[j], "0%ib" % length)
k = k[::-1]
p, q = divmod(j, 9)
if p > a:
anslist.append(str(k))
else:
anslist[p] += int(k)
answer = 0
for some in anslist:
some = str(some)
some = some.zfill(61)
for j in range(61):
if int(some[j]) != 0:
use[j] += int(some[j])
for j in range(61):
answer += (2**j) * use[j] * (n - use[j]) % (10**9 + 7)
print((answer % (10**9 + 7)))
| # 昔はtleの回答、今は通る?
import sys
input = sys.stdin.readline
n = int(eval(input()))
lists = list(map(int, input().split()))
aa = [0 for i in range(n)]
bb = [0 for i in range(n)]
length = 61
use = [0 for i in range(61)]
for j in range(n):
k = format(lists[j], "0%ib" % length)
k = k[::-1]
aa[j] = k[:30]
bb[j] = k[30:]
for p in aa:
for some in range(30):
use[some] += int(p[some])
for q in bb:
for some in range(31):
use[some + 30] += int(q[some])
answer = 0
for j in range(61):
answer += (2**j) * use[j] * (n - use[j]) % (10**9 + 7)
print((answer % (10**9 + 7)))
| false | 7.407407 | [
"+# 昔はtleの回答、今は通る?",
"+aa = [0 for i in range(n)]",
"+bb = [0 for i in range(n)]",
"-a, b = divmod(n, 9)",
"-anslist = [0 for i in range(a + 1)]",
"- p, q = divmod(j, 9)",
"- if p > a:",
"- anslist.append(str(k))",
"- else:",
"- anslist[p] += int(k)",
"+ aa[j] = k[:30]",
"+ bb[j] = k[30:]",
"+for p in aa:",
"+ for some in range(30):",
"+ use[some] += int(p[some])",
"+for q in bb:",
"+ for some in range(31):",
"+ use[some + 30] += int(q[some])",
"-for some in anslist:",
"- some = str(some)",
"- some = some.zfill(61)",
"- for j in range(61):",
"- if int(some[j]) != 0:",
"- use[j] += int(some[j])"
] | false | 0.037377 | 0.066571 | 0.561457 | [
"s234456965",
"s030985985"
] |
u301624971 | p02873 | python | s093538507 | s504489354 | 345 | 192 | 35,292 | 30,652 | Accepted | Accepted | 44.35 |
def modelAnswer(S:list) -> int:
l = [0 for i in range(len(S)+1)]
for n,s in enumerate(S):
if(s == "<"):
l[n+1] = l[n] + 1
for n,s in enumerate(S[::-1]):
if(s == ">"):
tmp = l[len(S) - n] + 1
if (tmp > l[len(S) - n - 1]):
l[len(S) -n - 1] = tmp
return sum(l)
def main():
S = list(eval(input()))
print((modelAnswer(S[:])))
if __name__ == '__main__':
main() | def myAnswer(S:list) -> int:
N = len(S)+1
ans = [0]*N
for i in range(len(S)-1,-1,-1):
if(S[i] == ">"):
ans[i] = ans[i+1]+1
# print(ans)
for i in range(len(S)):
if(S[i]== "<"):
if(ans[i] >= ans[i + 1]):
ans[i + 1] = ans[i]+1
# print(ans)
return sum(ans)
def modelAnswer(S:list) -> int:
l = [0 for i in range(len(S)+1)]
for n,s in enumerate(S):
if(s == "<"):
l[n+1] = l[n] + 1
for n,s in enumerate(S[::-1]):
if(s == ">"):
tmp = l[len(S) - n] + 1
if (tmp > l[len(S) - n - 1]):
l[len(S) -n - 1] = tmp
return sum(l)
def main():
S = list(eval(input()))
print((myAnswer(S[:])))
if __name__ == '__main__':
main() | 17 | 29 | 435 | 759 | def modelAnswer(S: list) -> int:
l = [0 for i in range(len(S) + 1)]
for n, s in enumerate(S):
if s == "<":
l[n + 1] = l[n] + 1
for n, s in enumerate(S[::-1]):
if s == ">":
tmp = l[len(S) - n] + 1
if tmp > l[len(S) - n - 1]:
l[len(S) - n - 1] = tmp
return sum(l)
def main():
S = list(eval(input()))
print((modelAnswer(S[:])))
if __name__ == "__main__":
main()
| def myAnswer(S: list) -> int:
N = len(S) + 1
ans = [0] * N
for i in range(len(S) - 1, -1, -1):
if S[i] == ">":
ans[i] = ans[i + 1] + 1
# print(ans)
for i in range(len(S)):
if S[i] == "<":
if ans[i] >= ans[i + 1]:
ans[i + 1] = ans[i] + 1
# print(ans)
return sum(ans)
def modelAnswer(S: list) -> int:
l = [0 for i in range(len(S) + 1)]
for n, s in enumerate(S):
if s == "<":
l[n + 1] = l[n] + 1
for n, s in enumerate(S[::-1]):
if s == ">":
tmp = l[len(S) - n] + 1
if tmp > l[len(S) - n - 1]:
l[len(S) - n - 1] = tmp
return sum(l)
def main():
S = list(eval(input()))
print((myAnswer(S[:])))
if __name__ == "__main__":
main()
| false | 41.37931 | [
"+def myAnswer(S: list) -> int:",
"+ N = len(S) + 1",
"+ ans = [0] * N",
"+ for i in range(len(S) - 1, -1, -1):",
"+ if S[i] == \">\":",
"+ ans[i] = ans[i + 1] + 1",
"+ # print(ans)",
"+ for i in range(len(S)):",
"+ if S[i] == \"<\":",
"+ if ans[i] >= ans[i + 1]:",
"+ ans[i + 1] = ans[i] + 1",
"+ # print(ans)",
"+ return sum(ans)",
"+",
"+",
"- print((modelAnswer(S[:])))",
"+ print((myAnswer(S[:])))"
] | false | 0.138106 | 0.035404 | 3.90082 | [
"s093538507",
"s504489354"
] |
u912237403 | p00033 | python | s528203069 | s192314905 | 20 | 10 | 4,200 | 4,204 | Accepted | Accepted | 50 | n=eval(input())
for i in range(n):
dt=list(map(int, input().split()))
a1=0
a2=0
for e in dt:
if e>a1: a1=e
elif e>a2: a2=e
else:
print("NO")
break
else:
print("YES") | def f(x):
a,b=0,0
for e in x:
if e>a: a=e
elif e>b: b=e
else: return False
return True
n=eval(input())
for i in range(n):
dt=list(map(int, input().split()))
if f(dt): print("YES")
else: print("NO") | 13 | 13 | 243 | 248 | n = eval(input())
for i in range(n):
dt = list(map(int, input().split()))
a1 = 0
a2 = 0
for e in dt:
if e > a1:
a1 = e
elif e > a2:
a2 = e
else:
print("NO")
break
else:
print("YES")
| def f(x):
a, b = 0, 0
for e in x:
if e > a:
a = e
elif e > b:
b = e
else:
return False
return True
n = eval(input())
for i in range(n):
dt = list(map(int, input().split()))
if f(dt):
print("YES")
else:
print("NO")
| false | 0 | [
"+def f(x):",
"+ a, b = 0, 0",
"+ for e in x:",
"+ if e > a:",
"+ a = e",
"+ elif e > b:",
"+ b = e",
"+ else:",
"+ return False",
"+ return True",
"+",
"+",
"- a1 = 0",
"- a2 = 0",
"- for e in dt:",
"- if e > a1:",
"- a1 = e",
"- elif e > a2:",
"- a2 = e",
"- else:",
"- print(\"NO\")",
"- break",
"+ if f(dt):",
"+ print(\"YES\")",
"- print(\"YES\")",
"+ print(\"NO\")"
] | false | 0.115029 | 0.047068 | 2.443893 | [
"s528203069",
"s192314905"
] |
u193264896 | p02999 | python | s696511461 | s915846870 | 35 | 17 | 5,076 | 3,060 | Accepted | Accepted | 51.43 | from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
def main():
x, a = list(map(int, readline().split()))
if x<a:
print((0))
else:
print((10))
if __name__ == '__main__':
main() | import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
def main():
X, A = list(map(int, readline().split()))
if X<A:
print('0')
else:
print('10')
if __name__ == '__main__':
main() | 32 | 15 | 892 | 282 | from collections import deque
from collections import Counter
from itertools import product, permutations, combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
# pypyではscipy, numpyは使えない
# from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
# from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
# import numpy as np
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float("inf")
def main():
x, a = list(map(int, readline().split()))
if x < a:
print((0))
else:
print((10))
if __name__ == "__main__":
main()
| import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9 + 7
def main():
X, A = list(map(int, readline().split()))
if X < A:
print("0")
else:
print("10")
if __name__ == "__main__":
main()
| false | 53.125 | [
"-from collections import deque",
"-from collections import Counter",
"-from itertools import product, permutations, combinations",
"-from operator import itemgetter",
"-from heapq import heappop, heappush",
"-from bisect import bisect_left, bisect_right, bisect",
"-",
"-# pypyではscipy, numpyは使えない",
"-# from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree",
"-# from scipy.sparse import csr_matrix, coo_matrix, lil_matrix",
"-# import numpy as np",
"-from fractions import gcd",
"-from math import ceil, floor, sqrt, cos, sin, pi, factorial",
"-read = sys.stdin.buffer.read",
"-readlines = sys.stdin.buffer.readlines",
"+MOD = 10**9 + 7",
"- x, a = list(map(int, readline().split()))",
"- if x < a:",
"- print((0))",
"+ X, A = list(map(int, readline().split()))",
"+ if X < A:",
"+ print(\"0\")",
"- print((10))",
"+ print(\"10\")"
] | false | 0.045313 | 0.045474 | 0.996479 | [
"s696511461",
"s915846870"
] |
u690536347 | p03722 | python | s425673877 | s245794398 | 1,316 | 315 | 3,316 | 44,904 | Accepted | Accepted | 76.06 | n,m=list(map(int,input().split()))
inf=float("inf")
l=[tuple(map(int,input().split())) for i in range(m)]
d=[inf]*n
d[0]=0
for i in range(n):
for a,b,c in l:
a,b,c=a-1,b-1,-c
if d[a]!=inf and d[b]>d[a]+c:
d[b]=d[a]+c
if i==n-1 and b==n-1:
print("inf")
exit()
print((-d[-1])) | n,m=list(map(int,input().split()))
es=[list(map(int,input().split())) for _ in range(m)]
inf=float("inf")
d=[-inf]*(n+1)
d[1]=0
def bellman_ford():
for i in range(n):
isUpdated=False
for e_from,e_to,cost in es:
if d[e_to]<d[e_from]+cost:
d[e_to]=d[e_from]+cost
isUpdated=True
if i==n-1 and e_to==n:return inf
if not isUpdated:
break
return d[n]
print((bellman_ford())) | 16 | 19 | 322 | 432 | n, m = list(map(int, input().split()))
inf = float("inf")
l = [tuple(map(int, input().split())) for i in range(m)]
d = [inf] * n
d[0] = 0
for i in range(n):
for a, b, c in l:
a, b, c = a - 1, b - 1, -c
if d[a] != inf and d[b] > d[a] + c:
d[b] = d[a] + c
if i == n - 1 and b == n - 1:
print("inf")
exit()
print((-d[-1]))
| n, m = list(map(int, input().split()))
es = [list(map(int, input().split())) for _ in range(m)]
inf = float("inf")
d = [-inf] * (n + 1)
d[1] = 0
def bellman_ford():
for i in range(n):
isUpdated = False
for e_from, e_to, cost in es:
if d[e_to] < d[e_from] + cost:
d[e_to] = d[e_from] + cost
isUpdated = True
if i == n - 1 and e_to == n:
return inf
if not isUpdated:
break
return d[n]
print((bellman_ford()))
| false | 15.789474 | [
"+es = [list(map(int, input().split())) for _ in range(m)]",
"-l = [tuple(map(int, input().split())) for i in range(m)]",
"-d = [inf] * n",
"-d[0] = 0",
"-for i in range(n):",
"- for a, b, c in l:",
"- a, b, c = a - 1, b - 1, -c",
"- if d[a] != inf and d[b] > d[a] + c:",
"- d[b] = d[a] + c",
"- if i == n - 1 and b == n - 1:",
"- print(\"inf\")",
"- exit()",
"-print((-d[-1]))",
"+d = [-inf] * (n + 1)",
"+d[1] = 0",
"+",
"+",
"+def bellman_ford():",
"+ for i in range(n):",
"+ isUpdated = False",
"+ for e_from, e_to, cost in es:",
"+ if d[e_to] < d[e_from] + cost:",
"+ d[e_to] = d[e_from] + cost",
"+ isUpdated = True",
"+ if i == n - 1 and e_to == n:",
"+ return inf",
"+ if not isUpdated:",
"+ break",
"+ return d[n]",
"+",
"+",
"+print((bellman_ford()))"
] | false | 0.087617 | 0.129801 | 0.675008 | [
"s425673877",
"s245794398"
] |
u384124931 | p02690 | python | s718807303 | s590824739 | 73 | 64 | 64,612 | 9,108 | Accepted | Accepted | 12.33 | import sys
x = int(eval(input()))
for i in range(-200, 200):
for j in range(-200, 200):
if i**5-j**5 ==x:
print((i,j))
sys.exit() | import sys
def main():
x = int(eval(input()))
for i in range(-200, 200):
for j in range(-200, 200):
if i**5-j**5 ==x:
print((i,j))
sys.exit()
if __name__ == "__main__":
main() | 7 | 10 | 145 | 204 | import sys
x = int(eval(input()))
for i in range(-200, 200):
for j in range(-200, 200):
if i**5 - j**5 == x:
print((i, j))
sys.exit()
| import sys
def main():
x = int(eval(input()))
for i in range(-200, 200):
for j in range(-200, 200):
if i**5 - j**5 == x:
print((i, j))
sys.exit()
if __name__ == "__main__":
main()
| false | 30 | [
"-x = int(eval(input()))",
"-for i in range(-200, 200):",
"- for j in range(-200, 200):",
"- if i**5 - j**5 == x:",
"- print((i, j))",
"- sys.exit()",
"+",
"+def main():",
"+ x = int(eval(input()))",
"+ for i in range(-200, 200):",
"+ for j in range(-200, 200):",
"+ if i**5 - j**5 == x:",
"+ print((i, j))",
"+ sys.exit()",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.133391 | 0.086824 | 1.536345 | [
"s718807303",
"s590824739"
] |
u425177436 | p03146 | python | s317129764 | s258314416 | 27 | 17 | 10,740 | 2,940 | Accepted | Accepted | 37.04 | a = int(eval(input()))
t = [0]*1000000
t[a] = 1
for i in range(2,1000001):
if a % 2 == 0:
a //= 2
else:
a = 3*a + 1
if t[a]:
break
t[a] = 1
print(i) | a = int(eval(input()))
t = set()
t.add(a)
for i in range(2,1000001):
if a % 2 == 0:
a //= 2
else:
a = 3*a + 1
if a in t:
break
t.add(a)
print(i) | 12 | 12 | 193 | 189 | a = int(eval(input()))
t = [0] * 1000000
t[a] = 1
for i in range(2, 1000001):
if a % 2 == 0:
a //= 2
else:
a = 3 * a + 1
if t[a]:
break
t[a] = 1
print(i)
| a = int(eval(input()))
t = set()
t.add(a)
for i in range(2, 1000001):
if a % 2 == 0:
a //= 2
else:
a = 3 * a + 1
if a in t:
break
t.add(a)
print(i)
| false | 0 | [
"-t = [0] * 1000000",
"-t[a] = 1",
"+t = set()",
"+t.add(a)",
"- if t[a]:",
"+ if a in t:",
"- t[a] = 1",
"+ t.add(a)"
] | false | 0.04432 | 0.040844 | 1.085112 | [
"s317129764",
"s258314416"
] |
u968166680 | p02726 | python | s817417446 | s987575906 | 128 | 110 | 74,312 | 74,464 | Accepted | Accepted | 14.06 | import sys
from collections import deque
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, X, Y = list(map(int, readline().split()))
X -= 1
Y -= 1
ans = [0] * N
for i in range(N - 1):
for j in range(i + 1, N):
d = min(j - i, abs(i - X) + 1 + abs(Y - j), abs(j - X) + 1 + abs(X - i))
ans[d] += 1
print(('\n'.join(map(str, ans[1:]))))
return
if __name__ == '__main__':
main()
| import sys
from collections import deque
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, X, Y = list(map(int, readline().split()))
X -= 1
Y -= 1
ans = [0] * N
for i in range(N - 1):
for j in range(i + 1, N):
d = min(j - i, abs(i - X) + 1 + abs(Y - j))
ans[d] += 1
print(('\n'.join(map(str, ans[1:]))))
return
if __name__ == '__main__':
main()
| 30 | 30 | 579 | 550 | import sys
from collections import deque
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, X, Y = list(map(int, readline().split()))
X -= 1
Y -= 1
ans = [0] * N
for i in range(N - 1):
for j in range(i + 1, N):
d = min(j - i, abs(i - X) + 1 + abs(Y - j), abs(j - X) + 1 + abs(X - i))
ans[d] += 1
print(("\n".join(map(str, ans[1:]))))
return
if __name__ == "__main__":
main()
| import sys
from collections import deque
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, X, Y = list(map(int, readline().split()))
X -= 1
Y -= 1
ans = [0] * N
for i in range(N - 1):
for j in range(i + 1, N):
d = min(j - i, abs(i - X) + 1 + abs(Y - j))
ans[d] += 1
print(("\n".join(map(str, ans[1:]))))
return
if __name__ == "__main__":
main()
| false | 0 | [
"- d = min(j - i, abs(i - X) + 1 + abs(Y - j), abs(j - X) + 1 + abs(X - i))",
"+ d = min(j - i, abs(i - X) + 1 + abs(Y - j))"
] | false | 0.035563 | 0.047178 | 0.753797 | [
"s817417446",
"s987575906"
] |
u340781749 | p02591 | python | s450115815 | s964433109 | 1,951 | 389 | 108,424 | 32,604 | Accepted | Accepted | 80.06 | import sys
h, *ppp = list(map(int, sys.stdin.buffer.read().split()))
n = 1 << (h - 1)
ppp = [p + n - 1 for p in ppp]
MOD = 10 ** 9 + 7
cumprods = [1] * (2 * n) # 根から頂点vまでの経路の累積積
cumprods_rev = [1] * n # ..の逆数
cumprods_through = [0] * n # 木1の根から木2の根まで、木1の i 番目の葉を経由する経路の積
for i in range(2, 2 * n):
cumprods[i] = cumprods[i >> 1] * i % MOD
for i in range(n):
cumprods_rev[i] = pow(cumprods[i], MOD - 2, MOD)
cumprods_through[i] = cumprods[i + n] * cumprods[ppp[i]] % MOD
# 現在考慮中の木1側のLCAを起点として、木2側の各頂点に至るまでの累積積
# 木1からたどり着かないものは0
cumprods_from_tree1 = [0] * (2 * n)
ans = 0
for lca in range(1, n):
digit = h - lca.bit_length()
leftmost_leaf_in_left_subtree = lca << digit
leftmost_leaf_in_right_subtree = ((lca << 1) + 1) << (digit - 1)
rightmost_leaf_in_right_subtree = (lca + 1) << digit
rev = cumprods_rev[lca >> 1]
for leaf in range(leftmost_leaf_in_left_subtree, leftmost_leaf_in_right_subtree):
v = ppp[leaf - n]
cp = cumprods_through[leaf - n] * rev % MOD
while v > 1:
cumprods_from_tree1[v] += cp * cumprods_rev[v >> 1] % MOD
v >>= 1
rev = cumprods_rev[lca]
for leaf in range(leftmost_leaf_in_right_subtree, rightmost_leaf_in_right_subtree):
v = ppp[leaf - n]
cp = cumprods_through[leaf - n] * rev % MOD
while v > 1:
ans = (ans + cumprods_from_tree1[v ^ 1] * cp * cumprods_rev[v >> 2]) % MOD
v >>= 1
for leaf in range(leftmost_leaf_in_left_subtree, leftmost_leaf_in_right_subtree):
v = ppp[leaf - n]
while cumprods_from_tree1[v] != 0:
cumprods_from_tree1[v] = 0
v >>= 1
print(ans)
| import os
import sys
import numpy as np
def solve(inp):
def mod_pow(x, a, MOD):
ret = 1
cur = x
while a:
if a & 1:
ret = ret * cur % MOD
cur = cur * cur % MOD
a >>= 1
return ret
h = inp[0]
ppp = inp[1:]
n = 1 << (h - 1)
ppp += n - 1
MOD = 10 ** 9 + 7
cumprods = np.ones(2 * n, dtype=np.int64)
cumprods_rev = np.ones(n, dtype=np.int64)
cumprods_through = np.zeros(n, dtype=np.int64)
for i in range(2, 2 * n):
cumprods[i] = cumprods[i >> 1] * i % MOD
for i in range(n):
cumprods_rev[i] = mod_pow(cumprods[i], MOD - 2, MOD)
cumprods_through[i] = cumprods[i + n] * cumprods[ppp[i]] % MOD
cumprods_from_tree1 = np.zeros(2 * n, dtype=np.int64)
ans = 0
for lca in range(1, n):
d = lca
digit = h
while d:
d >>= 1
digit -= 1
leftmost_leaf_in_left_subtree = lca << digit
leftmost_leaf_in_right_subtree = ((lca << 1) + 1) << (digit - 1)
rightmost_leaf_in_right_subtree = (lca + 1) << digit
rev = cumprods_rev[lca >> 1]
for leaf in range(leftmost_leaf_in_left_subtree, leftmost_leaf_in_right_subtree):
v = ppp[leaf - n]
cp = cumprods_through[leaf - n] * rev % MOD
while v > 1:
cumprods_from_tree1[v] += cp * cumprods_rev[v >> 1] % MOD
v >>= 1
rev = cumprods_rev[lca]
for leaf in range(leftmost_leaf_in_right_subtree, rightmost_leaf_in_right_subtree):
v = ppp[leaf - n]
cp = cumprods_through[leaf - n] * rev % MOD
while v > 1:
ans += cumprods_from_tree1[v ^ 1] % MOD * cp % MOD * cumprods_rev[v >> 2] % MOD
v >>= 1
ans %= MOD
for leaf in range(leftmost_leaf_in_left_subtree, leftmost_leaf_in_right_subtree):
v = ppp[leaf - n]
while cumprods_from_tree1[v] != 0:
cumprods_from_tree1[v] = 0
v >>= 1
return ans
if sys.argv[-1] == 'ONLINE_JUDGE':
from numba.pycc import CC
cc = CC('my_module')
cc.export('solve', '(i8[:],)')(solve)
cc.compile()
exit()
if os.name == 'posix':
# noinspection PyUnresolvedReferences
from my_module import solve
else:
from numba import njit
solve = njit('(i8[:],)', cache=True)(solve)
print('compiled', file=sys.stderr)
inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print(ans)
| 51 | 92 | 1,725 | 2,655 | import sys
h, *ppp = list(map(int, sys.stdin.buffer.read().split()))
n = 1 << (h - 1)
ppp = [p + n - 1 for p in ppp]
MOD = 10**9 + 7
cumprods = [1] * (2 * n) # 根から頂点vまでの経路の累積積
cumprods_rev = [1] * n # ..の逆数
cumprods_through = [0] * n # 木1の根から木2の根まで、木1の i 番目の葉を経由する経路の積
for i in range(2, 2 * n):
cumprods[i] = cumprods[i >> 1] * i % MOD
for i in range(n):
cumprods_rev[i] = pow(cumprods[i], MOD - 2, MOD)
cumprods_through[i] = cumprods[i + n] * cumprods[ppp[i]] % MOD
# 現在考慮中の木1側のLCAを起点として、木2側の各頂点に至るまでの累積積
# 木1からたどり着かないものは0
cumprods_from_tree1 = [0] * (2 * n)
ans = 0
for lca in range(1, n):
digit = h - lca.bit_length()
leftmost_leaf_in_left_subtree = lca << digit
leftmost_leaf_in_right_subtree = ((lca << 1) + 1) << (digit - 1)
rightmost_leaf_in_right_subtree = (lca + 1) << digit
rev = cumprods_rev[lca >> 1]
for leaf in range(leftmost_leaf_in_left_subtree, leftmost_leaf_in_right_subtree):
v = ppp[leaf - n]
cp = cumprods_through[leaf - n] * rev % MOD
while v > 1:
cumprods_from_tree1[v] += cp * cumprods_rev[v >> 1] % MOD
v >>= 1
rev = cumprods_rev[lca]
for leaf in range(leftmost_leaf_in_right_subtree, rightmost_leaf_in_right_subtree):
v = ppp[leaf - n]
cp = cumprods_through[leaf - n] * rev % MOD
while v > 1:
ans = (ans + cumprods_from_tree1[v ^ 1] * cp * cumprods_rev[v >> 2]) % MOD
v >>= 1
for leaf in range(leftmost_leaf_in_left_subtree, leftmost_leaf_in_right_subtree):
v = ppp[leaf - n]
while cumprods_from_tree1[v] != 0:
cumprods_from_tree1[v] = 0
v >>= 1
print(ans)
| import os
import sys
import numpy as np
def solve(inp):
def mod_pow(x, a, MOD):
ret = 1
cur = x
while a:
if a & 1:
ret = ret * cur % MOD
cur = cur * cur % MOD
a >>= 1
return ret
h = inp[0]
ppp = inp[1:]
n = 1 << (h - 1)
ppp += n - 1
MOD = 10**9 + 7
cumprods = np.ones(2 * n, dtype=np.int64)
cumprods_rev = np.ones(n, dtype=np.int64)
cumprods_through = np.zeros(n, dtype=np.int64)
for i in range(2, 2 * n):
cumprods[i] = cumprods[i >> 1] * i % MOD
for i in range(n):
cumprods_rev[i] = mod_pow(cumprods[i], MOD - 2, MOD)
cumprods_through[i] = cumprods[i + n] * cumprods[ppp[i]] % MOD
cumprods_from_tree1 = np.zeros(2 * n, dtype=np.int64)
ans = 0
for lca in range(1, n):
d = lca
digit = h
while d:
d >>= 1
digit -= 1
leftmost_leaf_in_left_subtree = lca << digit
leftmost_leaf_in_right_subtree = ((lca << 1) + 1) << (digit - 1)
rightmost_leaf_in_right_subtree = (lca + 1) << digit
rev = cumprods_rev[lca >> 1]
for leaf in range(
leftmost_leaf_in_left_subtree, leftmost_leaf_in_right_subtree
):
v = ppp[leaf - n]
cp = cumprods_through[leaf - n] * rev % MOD
while v > 1:
cumprods_from_tree1[v] += cp * cumprods_rev[v >> 1] % MOD
v >>= 1
rev = cumprods_rev[lca]
for leaf in range(
leftmost_leaf_in_right_subtree, rightmost_leaf_in_right_subtree
):
v = ppp[leaf - n]
cp = cumprods_through[leaf - n] * rev % MOD
while v > 1:
ans += (
cumprods_from_tree1[v ^ 1]
% MOD
* cp
% MOD
* cumprods_rev[v >> 2]
% MOD
)
v >>= 1
ans %= MOD
for leaf in range(
leftmost_leaf_in_left_subtree, leftmost_leaf_in_right_subtree
):
v = ppp[leaf - n]
while cumprods_from_tree1[v] != 0:
cumprods_from_tree1[v] = 0
v >>= 1
return ans
if sys.argv[-1] == "ONLINE_JUDGE":
from numba.pycc import CC
cc = CC("my_module")
cc.export("solve", "(i8[:],)")(solve)
cc.compile()
exit()
if os.name == "posix":
# noinspection PyUnresolvedReferences
from my_module import solve
else:
from numba import njit
solve = njit("(i8[:],)", cache=True)(solve)
print("compiled", file=sys.stderr)
inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=" ")
ans = solve(inp)
print(ans)
| false | 44.565217 | [
"+import os",
"+import numpy as np",
"-h, *ppp = list(map(int, sys.stdin.buffer.read().split()))",
"-n = 1 << (h - 1)",
"-ppp = [p + n - 1 for p in ppp]",
"-MOD = 10**9 + 7",
"-cumprods = [1] * (2 * n) # 根から頂点vまでの経路の累積積",
"-cumprods_rev = [1] * n # ..の逆数",
"-cumprods_through = [0] * n # 木1の根から木2の根まで、木1の i 番目の葉を経由する経路の積",
"-for i in range(2, 2 * n):",
"- cumprods[i] = cumprods[i >> 1] * i % MOD",
"-for i in range(n):",
"- cumprods_rev[i] = pow(cumprods[i], MOD - 2, MOD)",
"- cumprods_through[i] = cumprods[i + n] * cumprods[ppp[i]] % MOD",
"-# 現在考慮中の木1側のLCAを起点として、木2側の各頂点に至るまでの累積積",
"-# 木1からたどり着かないものは0",
"-cumprods_from_tree1 = [0] * (2 * n)",
"-ans = 0",
"-for lca in range(1, n):",
"- digit = h - lca.bit_length()",
"- leftmost_leaf_in_left_subtree = lca << digit",
"- leftmost_leaf_in_right_subtree = ((lca << 1) + 1) << (digit - 1)",
"- rightmost_leaf_in_right_subtree = (lca + 1) << digit",
"- rev = cumprods_rev[lca >> 1]",
"- for leaf in range(leftmost_leaf_in_left_subtree, leftmost_leaf_in_right_subtree):",
"- v = ppp[leaf - n]",
"- cp = cumprods_through[leaf - n] * rev % MOD",
"- while v > 1:",
"- cumprods_from_tree1[v] += cp * cumprods_rev[v >> 1] % MOD",
"- v >>= 1",
"- rev = cumprods_rev[lca]",
"- for leaf in range(leftmost_leaf_in_right_subtree, rightmost_leaf_in_right_subtree):",
"- v = ppp[leaf - n]",
"- cp = cumprods_through[leaf - n] * rev % MOD",
"- while v > 1:",
"- ans = (ans + cumprods_from_tree1[v ^ 1] * cp * cumprods_rev[v >> 2]) % MOD",
"- v >>= 1",
"- for leaf in range(leftmost_leaf_in_left_subtree, leftmost_leaf_in_right_subtree):",
"- v = ppp[leaf - n]",
"- while cumprods_from_tree1[v] != 0:",
"- cumprods_from_tree1[v] = 0",
"- v >>= 1",
"+",
"+def solve(inp):",
"+ def mod_pow(x, a, MOD):",
"+ ret = 1",
"+ cur = x",
"+ while a:",
"+ if a & 1:",
"+ ret = ret * cur % MOD",
"+ cur = cur * cur % MOD",
"+ a >>= 1",
"+ return ret",
"+",
"+ h = inp[0]",
"+ ppp = inp[1:]",
"+ n = 1 << (h - 1)",
"+ ppp += n - 1",
"+ MOD = 10**9 + 7",
"+ cumprods = np.ones(2 * n, dtype=np.int64)",
"+ cumprods_rev = np.ones(n, dtype=np.int64)",
"+ cumprods_through = np.zeros(n, dtype=np.int64)",
"+ for i in range(2, 2 * n):",
"+ cumprods[i] = cumprods[i >> 1] * i % MOD",
"+ for i in range(n):",
"+ cumprods_rev[i] = mod_pow(cumprods[i], MOD - 2, MOD)",
"+ cumprods_through[i] = cumprods[i + n] * cumprods[ppp[i]] % MOD",
"+ cumprods_from_tree1 = np.zeros(2 * n, dtype=np.int64)",
"+ ans = 0",
"+ for lca in range(1, n):",
"+ d = lca",
"+ digit = h",
"+ while d:",
"+ d >>= 1",
"+ digit -= 1",
"+ leftmost_leaf_in_left_subtree = lca << digit",
"+ leftmost_leaf_in_right_subtree = ((lca << 1) + 1) << (digit - 1)",
"+ rightmost_leaf_in_right_subtree = (lca + 1) << digit",
"+ rev = cumprods_rev[lca >> 1]",
"+ for leaf in range(",
"+ leftmost_leaf_in_left_subtree, leftmost_leaf_in_right_subtree",
"+ ):",
"+ v = ppp[leaf - n]",
"+ cp = cumprods_through[leaf - n] * rev % MOD",
"+ while v > 1:",
"+ cumprods_from_tree1[v] += cp * cumprods_rev[v >> 1] % MOD",
"+ v >>= 1",
"+ rev = cumprods_rev[lca]",
"+ for leaf in range(",
"+ leftmost_leaf_in_right_subtree, rightmost_leaf_in_right_subtree",
"+ ):",
"+ v = ppp[leaf - n]",
"+ cp = cumprods_through[leaf - n] * rev % MOD",
"+ while v > 1:",
"+ ans += (",
"+ cumprods_from_tree1[v ^ 1]",
"+ % MOD",
"+ * cp",
"+ % MOD",
"+ * cumprods_rev[v >> 2]",
"+ % MOD",
"+ )",
"+ v >>= 1",
"+ ans %= MOD",
"+ for leaf in range(",
"+ leftmost_leaf_in_left_subtree, leftmost_leaf_in_right_subtree",
"+ ):",
"+ v = ppp[leaf - n]",
"+ while cumprods_from_tree1[v] != 0:",
"+ cumprods_from_tree1[v] = 0",
"+ v >>= 1",
"+ return ans",
"+",
"+",
"+if sys.argv[-1] == \"ONLINE_JUDGE\":",
"+ from numba.pycc import CC",
"+",
"+ cc = CC(\"my_module\")",
"+ cc.export(\"solve\", \"(i8[:],)\")(solve)",
"+ cc.compile()",
"+ exit()",
"+if os.name == \"posix\":",
"+ # noinspection PyUnresolvedReferences",
"+ from my_module import solve",
"+else:",
"+ from numba import njit",
"+",
"+ solve = njit(\"(i8[:],)\", cache=True)(solve)",
"+ print(\"compiled\", file=sys.stderr)",
"+inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=\" \")",
"+ans = solve(inp)"
] | false | 0.041209 | 0.950986 | 0.043333 | [
"s450115815",
"s964433109"
] |
u569960318 | p02277 | python | s186976808 | s473132945 | 2,400 | 1,350 | 42,512 | 42,572 | Accepted | Accepted | 43.75 | from collections import namedtuple
Card = namedtuple('Card', 'suit value')
def partition(A,p,r):
x = A[r]
i = p
for j in range(p,r):
if A[j].value <= x.value:
A[i],A[j] = A[j],A[i]
i += 1
A[i],A[r] = A[r],A[i]
return i
def quickSort(A,p,r):
if p < r:
q = partition(A,p,r)
quickSort(A,p,q-1)
quickSort(A,q+1,r)
def merge(L,R):
global cnt
n = len(L)+len(R)
A = []
i = j = 0
L.append(Card('X',-1))
R.append(Card('X',-1))
for _ in range(n):
if L[i].value > R[j].value:
A.append(L[i])
i += 1
else:
A.append(R[j])
j += 1
return A
def mergeSort(A):
if len(A)==1: return A
m = len(A)//2
return merge(mergeSort(A[:m]),mergeSort(A[m:]))
if __name__=='__main__':
n = int(eval(input()))
Co = list([Card(X[0],int(X[1])) for X in [input().split() for _ in range(n)]])
Cq = Co[:]
Cm = mergeSort(Co[:])
quickSort(Cq,0,n-1)
print(("Stable" if Cq==Cm[::-1] else "Not stable"))
for c in Cq: print((c.suit,c.value)) | from collections import namedtuple
Card = namedtuple('Card', 'suit value')
def partition(A,p,r):
x = A[r]
i = p
for j in range(p,r):
if A[j].value <= x.value:
A[i],A[j] = A[j],A[i]
i += 1
A[i],A[r] = A[r],A[i]
return i
def quickSort(A,p,r):
if p < r:
q = partition(A,p,r)
quickSort(A,p,q-1)
quickSort(A,q+1,r)
def isStable(Co,Cs):
C = Cs[:]
for ci in Co:
j = C.index(ci)
if j > 0:
if Cs[j-1].value == ci.value:
return False
del C[j]
return True
if __name__=='__main__':
n = int(eval(input()))
Co = list([Card(X[0],int(X[1])) for X in [input().split() for _ in range(n)]])
Cs = Co[:]
quickSort(Cs,0,n-1)
print(("Stable" if isStable(Co,Cs) else "Not stable"))
for c in Cs: print((c.suit,c.value)) | 48 | 36 | 1,160 | 897 | from collections import namedtuple
Card = namedtuple("Card", "suit value")
def partition(A, p, r):
x = A[r]
i = p
for j in range(p, r):
if A[j].value <= x.value:
A[i], A[j] = A[j], A[i]
i += 1
A[i], A[r] = A[r], A[i]
return i
def quickSort(A, p, r):
if p < r:
q = partition(A, p, r)
quickSort(A, p, q - 1)
quickSort(A, q + 1, r)
def merge(L, R):
global cnt
n = len(L) + len(R)
A = []
i = j = 0
L.append(Card("X", -1))
R.append(Card("X", -1))
for _ in range(n):
if L[i].value > R[j].value:
A.append(L[i])
i += 1
else:
A.append(R[j])
j += 1
return A
def mergeSort(A):
if len(A) == 1:
return A
m = len(A) // 2
return merge(mergeSort(A[:m]), mergeSort(A[m:]))
if __name__ == "__main__":
n = int(eval(input()))
Co = list([Card(X[0], int(X[1])) for X in [input().split() for _ in range(n)]])
Cq = Co[:]
Cm = mergeSort(Co[:])
quickSort(Cq, 0, n - 1)
print(("Stable" if Cq == Cm[::-1] else "Not stable"))
for c in Cq:
print((c.suit, c.value))
| from collections import namedtuple
Card = namedtuple("Card", "suit value")
def partition(A, p, r):
x = A[r]
i = p
for j in range(p, r):
if A[j].value <= x.value:
A[i], A[j] = A[j], A[i]
i += 1
A[i], A[r] = A[r], A[i]
return i
def quickSort(A, p, r):
if p < r:
q = partition(A, p, r)
quickSort(A, p, q - 1)
quickSort(A, q + 1, r)
def isStable(Co, Cs):
C = Cs[:]
for ci in Co:
j = C.index(ci)
if j > 0:
if Cs[j - 1].value == ci.value:
return False
del C[j]
return True
if __name__ == "__main__":
n = int(eval(input()))
Co = list([Card(X[0], int(X[1])) for X in [input().split() for _ in range(n)]])
Cs = Co[:]
quickSort(Cs, 0, n - 1)
print(("Stable" if isStable(Co, Cs) else "Not stable"))
for c in Cs:
print((c.suit, c.value))
| false | 25 | [
"-def merge(L, R):",
"- global cnt",
"- n = len(L) + len(R)",
"- A = []",
"- i = j = 0",
"- L.append(Card(\"X\", -1))",
"- R.append(Card(\"X\", -1))",
"- for _ in range(n):",
"- if L[i].value > R[j].value:",
"- A.append(L[i])",
"- i += 1",
"- else:",
"- A.append(R[j])",
"- j += 1",
"- return A",
"-",
"-",
"-def mergeSort(A):",
"- if len(A) == 1:",
"- return A",
"- m = len(A) // 2",
"- return merge(mergeSort(A[:m]), mergeSort(A[m:]))",
"+def isStable(Co, Cs):",
"+ C = Cs[:]",
"+ for ci in Co:",
"+ j = C.index(ci)",
"+ if j > 0:",
"+ if Cs[j - 1].value == ci.value:",
"+ return False",
"+ del C[j]",
"+ return True",
"- Cq = Co[:]",
"- Cm = mergeSort(Co[:])",
"- quickSort(Cq, 0, n - 1)",
"- print((\"Stable\" if Cq == Cm[::-1] else \"Not stable\"))",
"- for c in Cq:",
"+ Cs = Co[:]",
"+ quickSort(Cs, 0, n - 1)",
"+ print((\"Stable\" if isStable(Co, Cs) else \"Not stable\"))",
"+ for c in Cs:"
] | false | 0.077978 | 0.037795 | 2.06318 | [
"s186976808",
"s473132945"
] |
u564589929 | p02714 | python | s441589916 | s091873918 | 1,011 | 169 | 9,228 | 68,524 | Accepted | Accepted | 83.28 | # import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def solve():
n = II()
S = list(eval(input()))
R = []
G = []
B = []
for i, s in enumerate(S):
if s == 'R':
R.append(i)
elif s == 'G':
G.append(i)
else:
B.append(i)
cnt = 0
for i in range(0, n):
for j in range(i+1, n):
k = 2 * j - i
if k >= n:
continue
if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
# print(i, j, k)
cnt = cnt + 1
print((len(R) * len(G) * len(B) - cnt))
if __name__ == '__main__':
solve()
| import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def MI1(): return list(map(int1, input().split()))
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
INF = float('inf')
def solve():
n = II()
S = list(eval(input()))
# print(S)
n = len(S)
R = []
G = []
B = []
rcnt = 0
gcnt = 0
bcnt = 0
for idx, s in enumerate(S):
if s == 'R':
R.append(idx+1)
rcnt += 1
elif s == 'G':
G.append(idx+1)
gcnt += 1
else:
B.append(idx+1)
bcnt += 1
# print(R)
# print(G)
# print(B)
ans = rcnt * gcnt * bcnt
# print(ans)
for i in range(n):
for j in range(i+1, n):
k = 2 * j - i
if k >= n:
continue
# print(i, j, k)
if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
ans -= 1
print(ans)
if __name__ == '__main__':
solve()
| 41 | 59 | 945 | 1,258 | # import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MI1():
return list(map(int1, input().split()))
def LI():
return list(map(int, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def solve():
n = II()
S = list(eval(input()))
R = []
G = []
B = []
for i, s in enumerate(S):
if s == "R":
R.append(i)
elif s == "G":
G.append(i)
else:
B.append(i)
cnt = 0
for i in range(0, n):
for j in range(i + 1, n):
k = 2 * j - i
if k >= n:
continue
if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
# print(i, j, k)
cnt = cnt + 1
print((len(R) * len(G) * len(B) - cnt))
if __name__ == "__main__":
solve()
| import sys
sys.setrecursionlimit(10**6)
# input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def MI1():
return list(map(int1, input().split()))
def LI():
return list(map(int, input().split()))
def LI1():
return list(map(int1, input().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
INF = float("inf")
def solve():
n = II()
S = list(eval(input()))
# print(S)
n = len(S)
R = []
G = []
B = []
rcnt = 0
gcnt = 0
bcnt = 0
for idx, s in enumerate(S):
if s == "R":
R.append(idx + 1)
rcnt += 1
elif s == "G":
G.append(idx + 1)
gcnt += 1
else:
B.append(idx + 1)
bcnt += 1
# print(R)
# print(G)
# print(B)
ans = rcnt * gcnt * bcnt
# print(ans)
for i in range(n):
for j in range(i + 1, n):
k = 2 * j - i
if k >= n:
continue
# print(i, j, k)
if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
ans -= 1
print(ans)
if __name__ == "__main__":
solve()
| false | 30.508475 | [
"-# import sys",
"-# sys.setrecursionlimit(10 ** 6)",
"+import sys",
"+",
"+sys.setrecursionlimit(10**6)",
"+# input = sys.stdin.readline ####",
"+def LI1():",
"+ return list(map(int1, input().split()))",
"+",
"+",
"+",
"+",
"+INF = float(\"inf\")",
"+ # print(S)",
"+ n = len(S)",
"- for i, s in enumerate(S):",
"+ rcnt = 0",
"+ gcnt = 0",
"+ bcnt = 0",
"+ for idx, s in enumerate(S):",
"- R.append(i)",
"+ R.append(idx + 1)",
"+ rcnt += 1",
"- G.append(i)",
"+ G.append(idx + 1)",
"+ gcnt += 1",
"- B.append(i)",
"- cnt = 0",
"- for i in range(0, n):",
"+ B.append(idx + 1)",
"+ bcnt += 1",
"+ # print(R)",
"+ # print(G)",
"+ # print(B)",
"+ ans = rcnt * gcnt * bcnt",
"+ # print(ans)",
"+ for i in range(n):",
"+ # print(i, j, k)",
"- # print(i, j, k)",
"- cnt = cnt + 1",
"- print((len(R) * len(G) * len(B) - cnt))",
"+ ans -= 1",
"+ print(ans)"
] | false | 0.054614 | 0.054739 | 0.997716 | [
"s441589916",
"s091873918"
] |
u597622207 | p03745 | python | s761359694 | s083974118 | 121 | 99 | 14,484 | 14,052 | Accepted | Accepted | 18.18 | N = int(eval(input()))
A = list(map(int, input().split()))
count = 1
state = ""
for i in range(N-1):
if A[i] > A[i+1] and state == "":
state = "minus"
elif A[i] > A[i+1] and state == "plus":
state = ""
count += 1
elif A[i] > A[i+1] and state == "minus":
continue
elif A[i] < A[i+1] and state == "":
state = "plus"
elif A[i] < A[i+1] and state == "minus":
state = ""
count += 1
elif A[i] < A[i+1] and state == "plus":
continue
else:
continue
print(count) | """
覚えておきたい
"""
n,*a=list(map(int,open(0).read().split()))
ans=1
tmp=0
for i in range(1,n):
if (a[i]-a[i-1])*tmp<0:
ans+=1
tmp=0
elif not a[i]-a[i-1]==0:
tmp=a[i]-a[i-1]
print(ans) | 23 | 14 | 570 | 204 | N = int(eval(input()))
A = list(map(int, input().split()))
count = 1
state = ""
for i in range(N - 1):
if A[i] > A[i + 1] and state == "":
state = "minus"
elif A[i] > A[i + 1] and state == "plus":
state = ""
count += 1
elif A[i] > A[i + 1] and state == "minus":
continue
elif A[i] < A[i + 1] and state == "":
state = "plus"
elif A[i] < A[i + 1] and state == "minus":
state = ""
count += 1
elif A[i] < A[i + 1] and state == "plus":
continue
else:
continue
print(count)
| """
覚えておきたい
"""
n, *a = list(map(int, open(0).read().split()))
ans = 1
tmp = 0
for i in range(1, n):
if (a[i] - a[i - 1]) * tmp < 0:
ans += 1
tmp = 0
elif not a[i] - a[i - 1] == 0:
tmp = a[i] - a[i - 1]
print(ans)
| false | 39.130435 | [
"-N = int(eval(input()))",
"-A = list(map(int, input().split()))",
"-count = 1",
"-state = \"\"",
"-for i in range(N - 1):",
"- if A[i] > A[i + 1] and state == \"\":",
"- state = \"minus\"",
"- elif A[i] > A[i + 1] and state == \"plus\":",
"- state = \"\"",
"- count += 1",
"- elif A[i] > A[i + 1] and state == \"minus\":",
"- continue",
"- elif A[i] < A[i + 1] and state == \"\":",
"- state = \"plus\"",
"- elif A[i] < A[i + 1] and state == \"minus\":",
"- state = \"\"",
"- count += 1",
"- elif A[i] < A[i + 1] and state == \"plus\":",
"- continue",
"- else:",
"- continue",
"-print(count)",
"+\"\"\"",
"+覚えておきたい",
"+\"\"\"",
"+n, *a = list(map(int, open(0).read().split()))",
"+ans = 1",
"+tmp = 0",
"+for i in range(1, n):",
"+ if (a[i] - a[i - 1]) * tmp < 0:",
"+ ans += 1",
"+ tmp = 0",
"+ elif not a[i] - a[i - 1] == 0:",
"+ tmp = a[i] - a[i - 1]",
"+print(ans)"
] | false | 0.035297 | 0.030613 | 1.153004 | [
"s761359694",
"s083974118"
] |
u604839890 | p02639 | python | s267516311 | s416384121 | 85 | 68 | 61,820 | 61,700 | Accepted | Accepted | 20 | x = list(map(int, input().split()))
for i in range(5):
if x[i] == 0:
print((i+1))
exit()
| x = list(map(int, input().split()))
print((x.index(0)+1)) | 5 | 2 | 101 | 56 | x = list(map(int, input().split()))
for i in range(5):
if x[i] == 0:
print((i + 1))
exit()
| x = list(map(int, input().split()))
print((x.index(0) + 1))
| false | 60 | [
"-for i in range(5):",
"- if x[i] == 0:",
"- print((i + 1))",
"- exit()",
"+print((x.index(0) + 1))"
] | false | 0.034588 | 0.03552 | 0.973742 | [
"s267516311",
"s416384121"
] |
u463775490 | p03325 | python | s181795075 | s541630650 | 92 | 76 | 4,148 | 4,148 | Accepted | Accepted | 17.39 | n = int(eval(input()))
a = [int(i) for i in input().split()]
ans = 0
for i in a:
while i % 2 == 0:
i //= 2
ans += 1
print(ans) | n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in a:
while not (i & 1):
ans += 1
i //= 2
print(ans) | 8 | 8 | 147 | 146 | n = int(eval(input()))
a = [int(i) for i in input().split()]
ans = 0
for i in a:
while i % 2 == 0:
i //= 2
ans += 1
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in a:
while not (i & 1):
ans += 1
i //= 2
print(ans)
| false | 0 | [
"-a = [int(i) for i in input().split()]",
"+a = list(map(int, input().split()))",
"- while i % 2 == 0:",
"+ while not (i & 1):",
"+ ans += 1",
"- ans += 1"
] | false | 0.112255 | 0.04656 | 2.410997 | [
"s181795075",
"s541630650"
] |
u219417113 | p03168 | python | s301053190 | s052356519 | 879 | 746 | 252,296 | 275,464 | Accepted | Accepted | 15.13 | N = int(eval(input()))
P = list(map(float, input().split()))
"""
dp[i][j]: i枚投げた時にj枚表の確率
"""
dp = [[0] * (N+1) for _ in range(N+1)]
dp[1][0] = 1 - P[0]
dp[1][1] = P[0]
for i in range(1, N+1):
for j in range(1, N+1):
dp[i][j] += dp[i-1][j-1] * P[i-1]
dp[i][j-1] += dp[i-1][j-1] * (1-P[i-1])
ans = 0
for i in range(N+1):
if N//2 < i:
ans += dp[N][i]
print(ans)
| import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
P = list(map(float, input().split()))
dp = [[0] * (N+1) for _ in range((N+1))]
dp[0][0] = 1
for i in range(1, N+1):
for j in range(i+1):
dp[i][j] = dp[i-1][j]*(1-P[i-1]) + dp[i-1][j-1]*P[i-1]
print((sum(dp[N][N//2+1:])))
if __name__ == '__main__':
main() | 20 | 15 | 407 | 383 | N = int(eval(input()))
P = list(map(float, input().split()))
"""
dp[i][j]: i枚投げた時にj枚表の確率
"""
dp = [[0] * (N + 1) for _ in range(N + 1)]
dp[1][0] = 1 - P[0]
dp[1][1] = P[0]
for i in range(1, N + 1):
for j in range(1, N + 1):
dp[i][j] += dp[i - 1][j - 1] * P[i - 1]
dp[i][j - 1] += dp[i - 1][j - 1] * (1 - P[i - 1])
ans = 0
for i in range(N + 1):
if N // 2 < i:
ans += dp[N][i]
print(ans)
| import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
P = list(map(float, input().split()))
dp = [[0] * (N + 1) for _ in range((N + 1))]
dp[0][0] = 1
for i in range(1, N + 1):
for j in range(i + 1):
dp[i][j] = dp[i - 1][j] * (1 - P[i - 1]) + dp[i - 1][j - 1] * P[i - 1]
print((sum(dp[N][N // 2 + 1 :])))
if __name__ == "__main__":
main()
| false | 25 | [
"-N = int(eval(input()))",
"-P = list(map(float, input().split()))",
"-\"\"\"",
"-dp[i][j]: i枚投げた時にj枚表の確率",
"-\"\"\"",
"-dp = [[0] * (N + 1) for _ in range(N + 1)]",
"-dp[1][0] = 1 - P[0]",
"-dp[1][1] = P[0]",
"-for i in range(1, N + 1):",
"- for j in range(1, N + 1):",
"- dp[i][j] += dp[i - 1][j - 1] * P[i - 1]",
"- dp[i][j - 1] += dp[i - 1][j - 1] * (1 - P[i - 1])",
"-ans = 0",
"-for i in range(N + 1):",
"- if N // 2 < i:",
"- ans += dp[N][i]",
"-print(ans)",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+",
"+",
"+def main():",
"+ N = int(eval(input()))",
"+ P = list(map(float, input().split()))",
"+ dp = [[0] * (N + 1) for _ in range((N + 1))]",
"+ dp[0][0] = 1",
"+ for i in range(1, N + 1):",
"+ for j in range(i + 1):",
"+ dp[i][j] = dp[i - 1][j] * (1 - P[i - 1]) + dp[i - 1][j - 1] * P[i - 1]",
"+ print((sum(dp[N][N // 2 + 1 :])))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.037135 | 0.086195 | 0.430821 | [
"s301053190",
"s052356519"
] |
u197968862 | p03288 | python | s133503592 | s772246210 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | r = int(eval(input()))
if r < 1200:
print('ABC')
elif r < 2800:
print('ARC')
else:
print('AGC') | r = int(eval(input()))
if r < 1200:
print('ABC')
elif 1200 <= r < 2800:
print('ARC')
else:
print('AGC') | 7 | 7 | 107 | 115 | r = int(eval(input()))
if r < 1200:
print("ABC")
elif r < 2800:
print("ARC")
else:
print("AGC")
| r = int(eval(input()))
if r < 1200:
print("ABC")
elif 1200 <= r < 2800:
print("ARC")
else:
print("AGC")
| false | 0 | [
"-elif r < 2800:",
"+elif 1200 <= r < 2800:"
] | false | 0.05784 | 0.053127 | 1.08871 | [
"s133503592",
"s772246210"
] |
u790012205 | p03479 | python | s932859448 | s807116408 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | X, Y = list(map(int, input().split()))
Z = X
c = 0
while Z <= Y:
c += 1
Z = 2 * Z
print(c) | X, Y = list(map(int, input().split()))
n = 0
A = X
while A <= Y:
n += 1
A *= 2
print(n) | 7 | 7 | 98 | 95 | X, Y = list(map(int, input().split()))
Z = X
c = 0
while Z <= Y:
c += 1
Z = 2 * Z
print(c)
| X, Y = list(map(int, input().split()))
n = 0
A = X
while A <= Y:
n += 1
A *= 2
print(n)
| false | 0 | [
"-Z = X",
"-c = 0",
"-while Z <= Y:",
"- c += 1",
"- Z = 2 * Z",
"-print(c)",
"+n = 0",
"+A = X",
"+while A <= Y:",
"+ n += 1",
"+ A *= 2",
"+print(n)"
] | false | 0.042781 | 0.043867 | 0.975248 | [
"s932859448",
"s807116408"
] |
u711539583 | p02726 | python | s418497835 | s477845804 | 1,063 | 886 | 71,904 | 59,612 | Accepted | Accepted | 16.65 | import heapq
# 単一始点最短経路。2地点間ではなく、始点が一つで各点へのコストを計算する
# eは隣接リストでe[v] = [(u1,cost1), (u2,cost2)]みたいな形を想定
# 辺の重みは正である必要がある
# O(ElogV)
def dijkstra(e,n,s):
inf = 10**18
d = [inf]*n
d[s] = 0
q = [(d[s],s)] # priority queueのソートキーが第一要素
heapq.heapify([q])
while len(q)>0:
_,v = heapq.heappop(q)
for u,c in e[v]:
if d[v]+c>=d[u]:
continue
d[u] = d[v] + c
heapq.heappush(q, (d[u],u))
return d
n,x,y = list(map(int, input().split()))
g = [[] for _ in range(n)]
for i in range(n-1):
g[i].append((i+1,1))
g[i+1].append((i,1))
g[x-1].append((y-1,1))
g[y-1].append((x-1,1))
res = [0]*n
for i in range(n):
d = dijkstra(g,n,i)
for j in range(i+1,n):
res[d[j]] += 1
for i in range(1,n):
print((res[i]))
| from heapq import heappush, heappop
INF = 10 ** 18
def dijkstra(n, G, s):
dist = [INF] * n
dist[s] = 0
h = []
heappush(h, (0, s))
while h:
# 使っていない頂点のうち、現時点で最も距離の近いものを選びvとする
d, v = heappop(h)
if dist[v] < d:
continue
# vから到達可能な頂点について、距離が短くなれば更新
for b, cost in G[v]:
if dist[b] > dist[v] + cost:
dist[b] = dist[v] + cost
heappush(h, (dist[b], b))
return dist
n, x, y = list(map(int, input().split()))
g = [[] for i in range(n)]
for i in range(n-1):
g[i].append((i+1, 1))
g[i+1].append((i, 1))
g[x-1].append((y-1, 1))
g[y-1].append((x-1, 1))
ans = [0] * n
for i in range(n):
for d in dijkstra(n, g, i):
ans[d] += 1
for item in ans[1:]:
print((item // 2))
| 39 | 42 | 848 | 841 | import heapq
# 単一始点最短経路。2地点間ではなく、始点が一つで各点へのコストを計算する
# eは隣接リストでe[v] = [(u1,cost1), (u2,cost2)]みたいな形を想定
# 辺の重みは正である必要がある
# O(ElogV)
def dijkstra(e, n, s):
inf = 10**18
d = [inf] * n
d[s] = 0
q = [(d[s], s)] # priority queueのソートキーが第一要素
heapq.heapify([q])
while len(q) > 0:
_, v = heapq.heappop(q)
for u, c in e[v]:
if d[v] + c >= d[u]:
continue
d[u] = d[v] + c
heapq.heappush(q, (d[u], u))
return d
n, x, y = list(map(int, input().split()))
g = [[] for _ in range(n)]
for i in range(n - 1):
g[i].append((i + 1, 1))
g[i + 1].append((i, 1))
g[x - 1].append((y - 1, 1))
g[y - 1].append((x - 1, 1))
res = [0] * n
for i in range(n):
d = dijkstra(g, n, i)
for j in range(i + 1, n):
res[d[j]] += 1
for i in range(1, n):
print((res[i]))
| from heapq import heappush, heappop
INF = 10**18
def dijkstra(n, G, s):
dist = [INF] * n
dist[s] = 0
h = []
heappush(h, (0, s))
while h:
# 使っていない頂点のうち、現時点で最も距離の近いものを選びvとする
d, v = heappop(h)
if dist[v] < d:
continue
# vから到達可能な頂点について、距離が短くなれば更新
for b, cost in G[v]:
if dist[b] > dist[v] + cost:
dist[b] = dist[v] + cost
heappush(h, (dist[b], b))
return dist
n, x, y = list(map(int, input().split()))
g = [[] for i in range(n)]
for i in range(n - 1):
g[i].append((i + 1, 1))
g[i + 1].append((i, 1))
g[x - 1].append((y - 1, 1))
g[y - 1].append((x - 1, 1))
ans = [0] * n
for i in range(n):
for d in dijkstra(n, g, i):
ans[d] += 1
for item in ans[1:]:
print((item // 2))
| false | 7.142857 | [
"-import heapq",
"+from heapq import heappush, heappop",
"-# 単一始点最短経路。2地点間ではなく、始点が一つで各点へのコストを計算する",
"-# eは隣接リストでe[v] = [(u1,cost1), (u2,cost2)]みたいな形を想定",
"-# 辺の重みは正である必要がある",
"-# O(ElogV)",
"-def dijkstra(e, n, s):",
"- inf = 10**18",
"- d = [inf] * n",
"- d[s] = 0",
"- q = [(d[s], s)] # priority queueのソートキーが第一要素",
"- heapq.heapify([q])",
"- while len(q) > 0:",
"- _, v = heapq.heappop(q)",
"- for u, c in e[v]:",
"- if d[v] + c >= d[u]:",
"- continue",
"- d[u] = d[v] + c",
"- heapq.heappush(q, (d[u], u))",
"- return d",
"+INF = 10**18",
"+",
"+",
"+def dijkstra(n, G, s):",
"+ dist = [INF] * n",
"+ dist[s] = 0",
"+ h = []",
"+ heappush(h, (0, s))",
"+ while h:",
"+ # 使っていない頂点のうち、現時点で最も距離の近いものを選びvとする",
"+ d, v = heappop(h)",
"+ if dist[v] < d:",
"+ continue",
"+ # vから到達可能な頂点について、距離が短くなれば更新",
"+ for b, cost in G[v]:",
"+ if dist[b] > dist[v] + cost:",
"+ dist[b] = dist[v] + cost",
"+ heappush(h, (dist[b], b))",
"+ return dist",
"-g = [[] for _ in range(n)]",
"+g = [[] for i in range(n)]",
"-res = [0] * n",
"+ans = [0] * n",
"- d = dijkstra(g, n, i)",
"- for j in range(i + 1, n):",
"- res[d[j]] += 1",
"-for i in range(1, n):",
"- print((res[i]))",
"+ for d in dijkstra(n, g, i):",
"+ ans[d] += 1",
"+for item in ans[1:]:",
"+ print((item // 2))"
] | false | 0.076491 | 0.037762 | 2.025605 | [
"s418497835",
"s477845804"
] |
u901447859 | p02928 | python | s167920234 | s900129570 | 238 | 33 | 3,188 | 3,316 | Accepted | Accepted | 86.13 | N,K=list(map(int, input().split()))
A=list(map(int, input().split()))
MOD=10**9+7
def count(A,N):
arr=[0]*N
for i, ai in enumerate(A[:-1]):
cnt=0
for aj in A[i+1:]:
if ai > aj:
cnt+=1
arr[i]=cnt
return arr
s1=sum(count(A,N))
s2=sum(count(sorted(A,reverse=True),N))
v=K*(K-1)//2
print(((s1*K+v*s2)%MOD)) | MOD = 10 ** 9 + 7
def MAP():
return list(map(int, input().split()))
class BinaryIndexedTree:
def __init__(self, tree_size):
self.tree_size = tree_size
self.tree = [0] * (self.tree_size + 1)
def add(self, i, x):
while 0 < i <= self.tree_size:
self.tree[i] += x
i += i & -i
def sum(self, i):
s = 0
while 0 < i:
s += self.tree[i]
i -= i & -i
return s
def count_inversion(A, max_num):
bit = BinaryIndexedTree(max_num)
x = 0
for i, a in enumerate(A, start=1):
bit.add(a, 1)
x += i - bit.sum(a)
return x
def main():
N, K = MAP()
A = MAP()
tento_int = count_inversion(A, 2000) # Aの内部で発生する転倒数
tento_ext = count_inversion(sorted(A, reverse=True), 2000) # AiとAjの間で発生する転倒数
x = tento_int * K
y = tento_ext * K * (K - 1) // 2
print(((x + y) % MOD))
if __name__ == "__main__":
main()
| 19 | 48 | 385 | 1,007 | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
def count(A, N):
arr = [0] * N
for i, ai in enumerate(A[:-1]):
cnt = 0
for aj in A[i + 1 :]:
if ai > aj:
cnt += 1
arr[i] = cnt
return arr
s1 = sum(count(A, N))
s2 = sum(count(sorted(A, reverse=True), N))
v = K * (K - 1) // 2
print(((s1 * K + v * s2) % MOD))
| MOD = 10**9 + 7
def MAP():
return list(map(int, input().split()))
class BinaryIndexedTree:
def __init__(self, tree_size):
self.tree_size = tree_size
self.tree = [0] * (self.tree_size + 1)
def add(self, i, x):
while 0 < i <= self.tree_size:
self.tree[i] += x
i += i & -i
def sum(self, i):
s = 0
while 0 < i:
s += self.tree[i]
i -= i & -i
return s
def count_inversion(A, max_num):
bit = BinaryIndexedTree(max_num)
x = 0
for i, a in enumerate(A, start=1):
bit.add(a, 1)
x += i - bit.sum(a)
return x
def main():
N, K = MAP()
A = MAP()
tento_int = count_inversion(A, 2000) # Aの内部で発生する転倒数
tento_ext = count_inversion(sorted(A, reverse=True), 2000) # AiとAjの間で発生する転倒数
x = tento_int * K
y = tento_ext * K * (K - 1) // 2
print(((x + y) % MOD))
if __name__ == "__main__":
main()
| false | 60.416667 | [
"-N, K = list(map(int, input().split()))",
"-A = list(map(int, input().split()))",
"-def count(A, N):",
"- arr = [0] * N",
"- for i, ai in enumerate(A[:-1]):",
"- cnt = 0",
"- for aj in A[i + 1 :]:",
"- if ai > aj:",
"- cnt += 1",
"- arr[i] = cnt",
"- return arr",
"+def MAP():",
"+ return list(map(int, input().split()))",
"-s1 = sum(count(A, N))",
"-s2 = sum(count(sorted(A, reverse=True), N))",
"-v = K * (K - 1) // 2",
"-print(((s1 * K + v * s2) % MOD))",
"+class BinaryIndexedTree:",
"+ def __init__(self, tree_size):",
"+ self.tree_size = tree_size",
"+ self.tree = [0] * (self.tree_size + 1)",
"+",
"+ def add(self, i, x):",
"+ while 0 < i <= self.tree_size:",
"+ self.tree[i] += x",
"+ i += i & -i",
"+",
"+ def sum(self, i):",
"+ s = 0",
"+ while 0 < i:",
"+ s += self.tree[i]",
"+ i -= i & -i",
"+ return s",
"+",
"+",
"+def count_inversion(A, max_num):",
"+ bit = BinaryIndexedTree(max_num)",
"+ x = 0",
"+ for i, a in enumerate(A, start=1):",
"+ bit.add(a, 1)",
"+ x += i - bit.sum(a)",
"+ return x",
"+",
"+",
"+def main():",
"+ N, K = MAP()",
"+ A = MAP()",
"+ tento_int = count_inversion(A, 2000) # Aの内部で発生する転倒数",
"+ tento_ext = count_inversion(sorted(A, reverse=True), 2000) # AiとAjの間で発生する転倒数",
"+ x = tento_int * K",
"+ y = tento_ext * K * (K - 1) // 2",
"+ print(((x + y) % MOD))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.053347 | 0.037056 | 1.439644 | [
"s167920234",
"s900129570"
] |
u143509139 | p02954 | python | s738428769 | s544403587 | 214 | 190 | 51,952 | 51,264 | Accepted | Accepted | 11.21 | s = eval(input())
n = len(s)
i = 0
ans = [0] * n
for i in range(n - 1):
if s[i] == 'R' and s[i + 1] == 'L':
j = 0
while i - j >= 0 and s[i - j] == 'R':
if j % 2:
ans[i + 1] += 1
else:
ans[i] += 1
j += 1
j = 1
while i + j < n and s[i + j] == 'L':
if j % 2:
ans[i + 1] += 1
else:
ans[i] += 1
j += 1
print((' '.join(map(str, ans)))) | s = eval(input())
n = len(s)
l = [0]
for i in range(n - 1):
if s[i] != s[i + 1]:
l.append(i + 1)
l.append(n)
ans = [0] * n
for i in range(1, len(l) - 1, 2):
p = l[i] - l[i - 1]
q = l[i + 1] - l[i]
ans[l[i] - 1] = (p + 1) // 2 + q // 2
ans[l[i]] = p // 2 + (q + 1) // 2
print((' '.join(map(str, ans))))
| 21 | 14 | 513 | 335 | s = eval(input())
n = len(s)
i = 0
ans = [0] * n
for i in range(n - 1):
if s[i] == "R" and s[i + 1] == "L":
j = 0
while i - j >= 0 and s[i - j] == "R":
if j % 2:
ans[i + 1] += 1
else:
ans[i] += 1
j += 1
j = 1
while i + j < n and s[i + j] == "L":
if j % 2:
ans[i + 1] += 1
else:
ans[i] += 1
j += 1
print((" ".join(map(str, ans))))
| s = eval(input())
n = len(s)
l = [0]
for i in range(n - 1):
if s[i] != s[i + 1]:
l.append(i + 1)
l.append(n)
ans = [0] * n
for i in range(1, len(l) - 1, 2):
p = l[i] - l[i - 1]
q = l[i + 1] - l[i]
ans[l[i] - 1] = (p + 1) // 2 + q // 2
ans[l[i]] = p // 2 + (q + 1) // 2
print((" ".join(map(str, ans))))
| false | 33.333333 | [
"-i = 0",
"+l = [0]",
"+for i in range(n - 1):",
"+ if s[i] != s[i + 1]:",
"+ l.append(i + 1)",
"+l.append(n)",
"-for i in range(n - 1):",
"- if s[i] == \"R\" and s[i + 1] == \"L\":",
"- j = 0",
"- while i - j >= 0 and s[i - j] == \"R\":",
"- if j % 2:",
"- ans[i + 1] += 1",
"- else:",
"- ans[i] += 1",
"- j += 1",
"- j = 1",
"- while i + j < n and s[i + j] == \"L\":",
"- if j % 2:",
"- ans[i + 1] += 1",
"- else:",
"- ans[i] += 1",
"- j += 1",
"+for i in range(1, len(l) - 1, 2):",
"+ p = l[i] - l[i - 1]",
"+ q = l[i + 1] - l[i]",
"+ ans[l[i] - 1] = (p + 1) // 2 + q // 2",
"+ ans[l[i]] = p // 2 + (q + 1) // 2"
] | false | 0.038557 | 0.16622 | 0.231966 | [
"s738428769",
"s544403587"
] |
u998435601 | p02396 | python | s108103558 | s781436824 | 40 | 30 | 6,312 | 6,320 | Accepted | Accepted | 25 | i = 1
while True:
a = input()
if a == '0':
break
print("Case %d: %s" % (i,a))
i += 1 | i = 1
while True:
a = input()
if a == '0':
break
print("Case %s: %s" % (i,a))
i += 1 | 7 | 7 | 99 | 99 | i = 1
while True:
a = input()
if a == "0":
break
print("Case %d: %s" % (i, a))
i += 1
| i = 1
while True:
a = input()
if a == "0":
break
print("Case %s: %s" % (i, a))
i += 1
| false | 0 | [
"- print(\"Case %d: %s\" % (i, a))",
"+ print(\"Case %s: %s\" % (i, a))"
] | false | 0.048481 | 0.048414 | 1.001387 | [
"s108103558",
"s781436824"
] |
u133936772 | p02983 | python | s903005436 | s775545863 | 539 | 420 | 2,940 | 2,940 | Accepted | Accepted | 22.08 | l,r=list(map(int,input().split()))
M=2019;s=list(range(l,r+1))
print((0 if r//M-l//M>0 else min(i*j%M for i in s for j in s if i<j))) | M=2019;l,r=list(map(int,input().split()))
print((0 if r//M-l//M>0 else min(i*j%M for i in range(l,r) for j in range(i+1,r+1)))) | 3 | 2 | 121 | 120 | l, r = list(map(int, input().split()))
M = 2019
s = list(range(l, r + 1))
print((0 if r // M - l // M > 0 else min(i * j % M for i in s for j in s if i < j)))
| M = 2019
l, r = list(map(int, input().split()))
print(
(
0
if r // M - l // M > 0
else min(i * j % M for i in range(l, r) for j in range(i + 1, r + 1))
)
)
| false | 33.333333 | [
"+M = 2019",
"-M = 2019",
"-s = list(range(l, r + 1))",
"-print((0 if r // M - l // M > 0 else min(i * j % M for i in s for j in s if i < j)))",
"+print(",
"+ (",
"+ 0",
"+ if r // M - l // M > 0",
"+ else min(i * j % M for i in range(l, r) for j in range(i + 1, r + 1))",
"+ )",
"+)"
] | false | 0.09104 | 0.101796 | 0.894342 | [
"s903005436",
"s775545863"
] |
u980205854 | p03665 | python | s351832561 | s188924585 | 318 | 77 | 21,048 | 65,720 | Accepted | Accepted | 75.79 | # A - Biscuits
import numpy as np
N, P = list(map(int, input().split()))
A = list(map(int, input().split()))
odd = len([i for i in A if i%2!=0])
if odd==0 and P==0:
ans = 2**N
elif odd==0 and P==1:
ans = 0
else:
ans = 2**(N-1)
print(ans) | import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *
sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7
def lcm(x,y):
return x*y//gcd(x,y)
def mint():
return map(int,input().split())
def lint():
return list(map(int,input().split()))
def ilint():
return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
print(l[0] if x else l[1])
def lprint(l, sep='\n'):
for x in l:
print(x, end=sep)
def ston(c, c0='a'):
return ord(c)-ord(c0)
def ntos(x, c0='a'):
return chr(x+ord(c0))
N,P = mint()
A = lint()
even = len([a for a in A if a%2==0])
odd = N-even
if odd==0:
print(0 if P else 2**N)
else:
print(2**(N-1))
| 13 | 38 | 256 | 892 | # A - Biscuits
import numpy as np
N, P = list(map(int, input().split()))
A = list(map(int, input().split()))
odd = len([i for i in A if i % 2 != 0])
if odd == 0 and P == 0:
ans = 2**N
elif odd == 0 and P == 1:
ans = 0
else:
ans = 2 ** (N - 1)
print(ans)
| import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right # func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *
sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9 + 7
def lcm(x, y):
return x * y // gcd(x, y)
def mint():
return map(int, input().split())
def lint():
return list(map(int, input().split()))
def ilint():
return int(input()), list(map(int, input().split()))
def judge(x, l=["Yes", "No"]):
print(l[0] if x else l[1])
def lprint(l, sep="\n"):
for x in l:
print(x, end=sep)
def ston(c, c0="a"):
return ord(c) - ord(c0)
def ntos(x, c0="a"):
return chr(x + ord(c0))
N, P = mint()
A = lint()
even = len([a for a in A if a % 2 == 0])
odd = N - even
if odd == 0:
print(0 if P else 2**N)
else:
print(2 ** (N - 1))
| false | 65.789474 | [
"-# A - Biscuits",
"-import numpy as np",
"+import sys",
"+from sys import exit",
"+from collections import deque",
"+from bisect import bisect_left, bisect_right, insort_left, insort_right # func(リスト,値)",
"+from heapq import heapify, heappop, heappush",
"+from math import *",
"-N, P = list(map(int, input().split()))",
"-A = list(map(int, input().split()))",
"-odd = len([i for i in A if i % 2 != 0])",
"-if odd == 0 and P == 0:",
"- ans = 2**N",
"-elif odd == 0 and P == 1:",
"- ans = 0",
"+sys.setrecursionlimit(10**6)",
"+INF = 10**20",
"+eps = 1.0e-20",
"+MOD = 10**9 + 7",
"+",
"+",
"+def lcm(x, y):",
"+ return x * y // gcd(x, y)",
"+",
"+",
"+def mint():",
"+ return map(int, input().split())",
"+",
"+",
"+def lint():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def ilint():",
"+ return int(input()), list(map(int, input().split()))",
"+",
"+",
"+def judge(x, l=[\"Yes\", \"No\"]):",
"+ print(l[0] if x else l[1])",
"+",
"+",
"+def lprint(l, sep=\"\\n\"):",
"+ for x in l:",
"+ print(x, end=sep)",
"+",
"+",
"+def ston(c, c0=\"a\"):",
"+ return ord(c) - ord(c0)",
"+",
"+",
"+def ntos(x, c0=\"a\"):",
"+ return chr(x + ord(c0))",
"+",
"+",
"+N, P = mint()",
"+A = lint()",
"+even = len([a for a in A if a % 2 == 0])",
"+odd = N - even",
"+if odd == 0:",
"+ print(0 if P else 2**N)",
"- ans = 2 ** (N - 1)",
"-print(ans)",
"+ print(2 ** (N - 1))"
] | false | 0.061146 | 0.061403 | 0.9958 | [
"s351832561",
"s188924585"
] |
u130900604 | p03775 | python | s246117551 | s466064682 | 35 | 30 | 2,940 | 3,060 | Accepted | Accepted | 14.29 | #n 10**10
#sqrtn 10**5
ans=10**6
n=int(eval(input()))
for i in range(1,int(n**0.5)+1):
if n%i==0:
ans=min(len(str(n//i)),ans)
print(ans) | def F(a,b):
return max(len(str(a)),len(str(b)))
n=int(eval(input()))
ans=10**15
for i in range(1,int(n**0.5)+1):
if n%i==0:
a=i
b=n//i
ans=min(ans,F(a,b))
print(ans) | 9 | 12 | 149 | 192 | # n 10**10
# sqrtn 10**5
ans = 10**6
n = int(eval(input()))
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
ans = min(len(str(n // i)), ans)
print(ans)
| def F(a, b):
return max(len(str(a)), len(str(b)))
n = int(eval(input()))
ans = 10**15
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
a = i
b = n // i
ans = min(ans, F(a, b))
print(ans)
| false | 25 | [
"-# n 10**10",
"-# sqrtn 10**5",
"-ans = 10**6",
"+def F(a, b):",
"+ return max(len(str(a)), len(str(b)))",
"+",
"+",
"+ans = 10**15",
"- ans = min(len(str(n // i)), ans)",
"+ a = i",
"+ b = n // i",
"+ ans = min(ans, F(a, b))"
] | false | 0.045044 | 0.050506 | 0.891861 | [
"s246117551",
"s466064682"
] |
u098012509 | p03329 | python | s556808590 | s896028087 | 239 | 92 | 3,828 | 73,340 | Accepted | Accepted | 61.51 | import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
dp = [0] * (10 ** 5 + 1)
dp[1] = 1
x = [1]
x.extend([6 ** x for x in range(1, 8)])
x.extend([9 ** x for x in range(1, 6)])
for i in range(2, 10 ** 5 + 1):
tmp = []
for v in x:
if i >= v:
tmp.append(dp[i - v] + 1)
dp[i] = min(tmp)
print((dp[N]))
if __name__ == '__main__':
main()
| N = int(eval(input()))
dp = [0] * 100001
dp[1] = 1
for i in range(2, N + 1):
dp[i] = dp[i - 1] + 1
j = 1
while 6 ** j <= i:
dp[i] = min(dp[i], dp[i - (6 ** j)] + 1)
j += 1
j = 1
while 9 ** j <= i:
dp[i] = min(dp[i], dp[i - (9 ** j)] + 1)
j += 1
print((dp[N]))
| 29 | 18 | 471 | 325 | import sys
input = sys.stdin.readline
def main():
N = int(eval(input()))
dp = [0] * (10**5 + 1)
dp[1] = 1
x = [1]
x.extend([6**x for x in range(1, 8)])
x.extend([9**x for x in range(1, 6)])
for i in range(2, 10**5 + 1):
tmp = []
for v in x:
if i >= v:
tmp.append(dp[i - v] + 1)
dp[i] = min(tmp)
print((dp[N]))
if __name__ == "__main__":
main()
| N = int(eval(input()))
dp = [0] * 100001
dp[1] = 1
for i in range(2, N + 1):
dp[i] = dp[i - 1] + 1
j = 1
while 6**j <= i:
dp[i] = min(dp[i], dp[i - (6**j)] + 1)
j += 1
j = 1
while 9**j <= i:
dp[i] = min(dp[i], dp[i - (9**j)] + 1)
j += 1
print((dp[N]))
| false | 37.931034 | [
"-import sys",
"-",
"-input = sys.stdin.readline",
"-",
"-",
"-def main():",
"- N = int(eval(input()))",
"- dp = [0] * (10**5 + 1)",
"- dp[1] = 1",
"- x = [1]",
"- x.extend([6**x for x in range(1, 8)])",
"- x.extend([9**x for x in range(1, 6)])",
"- for i in range(2, 10**5 + 1):",
"- tmp = []",
"- for v in x:",
"- if i >= v:",
"- tmp.append(dp[i - v] + 1)",
"- dp[i] = min(tmp)",
"- print((dp[N]))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+N = int(eval(input()))",
"+dp = [0] * 100001",
"+dp[1] = 1",
"+for i in range(2, N + 1):",
"+ dp[i] = dp[i - 1] + 1",
"+ j = 1",
"+ while 6**j <= i:",
"+ dp[i] = min(dp[i], dp[i - (6**j)] + 1)",
"+ j += 1",
"+ j = 1",
"+ while 9**j <= i:",
"+ dp[i] = min(dp[i], dp[i - (9**j)] + 1)",
"+ j += 1",
"+print((dp[N]))"
] | false | 1.22556 | 0.72485 | 1.690778 | [
"s556808590",
"s896028087"
] |
u680851063 | p03161 | python | s742909542 | s624971731 | 423 | 376 | 58,332 | 58,332 | Accepted | Accepted | 11.11 | import sys
input = sys.stdin.readline
n,k = list(map(int,input().split()))
h = tuple(map(int,input().split()))
dp = [0] + [float("inf")]*(n-1)
#print(dp)
for i in range(1,n):
for j in range(max(0,i-k),i):
dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]))
#print(dp)
print((dp[-1]))
| import sys
input = sys.stdin.readline
n,k = map(int,input().split())
h = tuple(map(int,input().split()))
def frog_2(N, H, K):
dp = [0] + [float("inf")]*(n-1)
#print(dp)
for i in range(1,n):
for j in range(max(0,i-k),i):
dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]))
#print(dp)
return print(dp[-1])
frog_2(n,h,k)
| 15 | 20 | 294 | 380 | import sys
input = sys.stdin.readline
n, k = list(map(int, input().split()))
h = tuple(map(int, input().split()))
dp = [0] + [float("inf")] * (n - 1)
# print(dp)
for i in range(1, n):
for j in range(max(0, i - k), i):
dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))
# print(dp)
print((dp[-1]))
| import sys
input = sys.stdin.readline
n, k = map(int, input().split())
h = tuple(map(int, input().split()))
def frog_2(N, H, K):
dp = [0] + [float("inf")] * (n - 1)
# print(dp)
for i in range(1, n):
for j in range(max(0, i - k), i):
dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))
# print(dp)
return print(dp[-1])
frog_2(n, h, k)
| false | 25 | [
"-n, k = list(map(int, input().split()))",
"+n, k = map(int, input().split())",
"-dp = [0] + [float(\"inf\")] * (n - 1)",
"-# print(dp)",
"-for i in range(1, n):",
"- for j in range(max(0, i - k), i):",
"- dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))",
"-# print(dp)",
"-print((dp[-1]))",
"+",
"+",
"+def frog_2(N, H, K):",
"+ dp = [0] + [float(\"inf\")] * (n - 1)",
"+ # print(dp)",
"+ for i in range(1, n):",
"+ for j in range(max(0, i - k), i):",
"+ dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))",
"+ # print(dp)",
"+ return print(dp[-1])",
"+",
"+",
"+frog_2(n, h, k)"
] | false | 0.036952 | 0.039577 | 0.933689 | [
"s742909542",
"s624971731"
] |
u576432509 | p02989 | python | s964889299 | s958090435 | 88 | 76 | 14,428 | 13,992 | Accepted | Accepted | 13.64 | n=int(eval(input()))
# print(n)
di=[]
for i in map(int,input().split()):
di.append(i)
di.sort()
n1=int(n/2)
m=di[n1] -di[n1-1]
print(m) |
n=int(eval(input()))
d=list(map(int,input().split()))
d.sort()
print((d[n//2]-d[n//2-1]))
| 9 | 7 | 141 | 91 | n = int(eval(input()))
# print(n)
di = []
for i in map(int, input().split()):
di.append(i)
di.sort()
n1 = int(n / 2)
m = di[n1] - di[n1 - 1]
print(m)
| n = int(eval(input()))
d = list(map(int, input().split()))
d.sort()
print((d[n // 2] - d[n // 2 - 1]))
| false | 22.222222 | [
"-# print(n)",
"-di = []",
"-for i in map(int, input().split()):",
"- di.append(i)",
"-di.sort()",
"-n1 = int(n / 2)",
"-m = di[n1] - di[n1 - 1]",
"-print(m)",
"+d = list(map(int, input().split()))",
"+d.sort()",
"+print((d[n // 2] - d[n // 2 - 1]))"
] | false | 0.035205 | 0.066852 | 0.526614 | [
"s964889299",
"s958090435"
] |
u306664745 | p02983 | python | s653814058 | s877695480 | 945 | 72 | 2,940 | 3,060 | Accepted | Accepted | 92.38 | l, r=list(map(int, input().split()))
x, y=l//2019, r//2019
p=0
if x==y:
p=2019
for i in range(l, r):
for j in range(i+1, r+1):
p=min(p, (((i%2019)*(j%2019))%2019))
print(p) | l, r=list(map(int, input().split()))
x, y=l//2019, r//2019
p=0
if x==y:
p=2019
for i in range(l, r):
for j in range(i+1, r+1):
p=min(p, (((i%2019)*(j%2019))%2019))
if not p:
break
if not p:
break
print(p) | 9 | 13 | 181 | 229 | l, r = list(map(int, input().split()))
x, y = l // 2019, r // 2019
p = 0
if x == y:
p = 2019
for i in range(l, r):
for j in range(i + 1, r + 1):
p = min(p, (((i % 2019) * (j % 2019)) % 2019))
print(p)
| l, r = list(map(int, input().split()))
x, y = l // 2019, r // 2019
p = 0
if x == y:
p = 2019
for i in range(l, r):
for j in range(i + 1, r + 1):
p = min(p, (((i % 2019) * (j % 2019)) % 2019))
if not p:
break
if not p:
break
print(p)
| false | 30.769231 | [
"+ if not p:",
"+ break",
"+ if not p:",
"+ break"
] | false | 0.11381 | 0.0344 | 3.308435 | [
"s653814058",
"s877695480"
] |
u225388820 | p02936 | python | s708964516 | s447161328 | 767 | 638 | 93,716 | 60,692 | Accepted | Accepted | 16.82 | import sys
input = sys.stdin.readline
from collections import deque
def main():
n,q = list(map(int,input().split()))
node = [[]for _ in range(n)]
looked = [1]*n
for i in range(n-1):
a,b = list(map(int,input().split()))
node[b-1].append(a-1)
node[a-1].append(b-1)
counter = [0]*n
for i in range(q):
p,x = list(map(int,input().split()))
counter[p-1] += x
queue = deque([0])
looked[0] = 0
while queue:
now = queue.pop()
for i in node[now]:
if looked[i]:
queue.append(i)
counter[i] += counter[now]
looked[i] = 0
print((*counter))
main() | from collections import deque
import os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def main():
n, q = list(map(int, input().split()))
node = [[]for _ in range(n)]
looked = [1] * n
for i in range(n - 1):
a, b = list(map(int, input().split()))
node[b - 1].append(a - 1)
node[a - 1].append(b - 1)
counter = [0] * n
for i in range(q):
p, x = list(map(int, input().split()))
counter[p - 1] += x
queue = deque([0])
looked[0] = 0
while queue:
now = queue.pop()
for i in node[now]:
if looked[i]:
queue.append(i)
counter[i] += counter[now]
looked[i] = 0
print((*counter))
main()
| 26 | 30 | 693 | 766 | import sys
input = sys.stdin.readline
from collections import deque
def main():
n, q = list(map(int, input().split()))
node = [[] for _ in range(n)]
looked = [1] * n
for i in range(n - 1):
a, b = list(map(int, input().split()))
node[b - 1].append(a - 1)
node[a - 1].append(b - 1)
counter = [0] * n
for i in range(q):
p, x = list(map(int, input().split()))
counter[p - 1] += x
queue = deque([0])
looked[0] = 0
while queue:
now = queue.pop()
for i in node[now]:
if looked[i]:
queue.append(i)
counter[i] += counter[now]
looked[i] = 0
print((*counter))
main()
| from collections import deque
import os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def main():
n, q = list(map(int, input().split()))
node = [[] for _ in range(n)]
looked = [1] * n
for i in range(n - 1):
a, b = list(map(int, input().split()))
node[b - 1].append(a - 1)
node[a - 1].append(b - 1)
counter = [0] * n
for i in range(q):
p, x = list(map(int, input().split()))
counter[p - 1] += x
queue = deque([0])
looked[0] = 0
while queue:
now = queue.pop()
for i in node[now]:
if looked[i]:
queue.append(i)
counter[i] += counter[now]
looked[i] = 0
print((*counter))
main()
| false | 13.333333 | [
"-import sys",
"+from collections import deque",
"+import os",
"+import io",
"-input = sys.stdin.readline",
"-from collections import deque",
"+input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline"
] | false | 0.063515 | 0.070063 | 0.906543 | [
"s708964516",
"s447161328"
] |
u984276646 | p03381 | python | s099288055 | s672857732 | 1,088 | 447 | 47,552 | 25,228 | Accepted | Accepted | 58.92 | N = int(eval(input()))
X = list(map(int, input().split()))
L = []
for i in range(N):
L.append([X[i], i])
L.sort()
for i in range(N):
if i < N // 2:
L[i].append(L[N // 2][0])
else:
L[i].append(L[N // 2 - 1][0])
for i in range(N):
L[i][0], L[i][1] = L[i][1], L[i][0]
L.sort()
for i in range(N):
print((L[i][2])) | N = int(eval(input()))
X = list(map(int, input().split()))
L = [0 for _ in range(N)]
for i in range(N):
X[i] = X[i] * N + i
X.sort()
d = N // 2
for i in range(N):
if i < d:
L[X[i]%N] = X[d] // N
else:
L[X[i]%N] = X[d-1] // N
for i in range(N):
print((L[i])) | 16 | 14 | 334 | 278 | N = int(eval(input()))
X = list(map(int, input().split()))
L = []
for i in range(N):
L.append([X[i], i])
L.sort()
for i in range(N):
if i < N // 2:
L[i].append(L[N // 2][0])
else:
L[i].append(L[N // 2 - 1][0])
for i in range(N):
L[i][0], L[i][1] = L[i][1], L[i][0]
L.sort()
for i in range(N):
print((L[i][2]))
| N = int(eval(input()))
X = list(map(int, input().split()))
L = [0 for _ in range(N)]
for i in range(N):
X[i] = X[i] * N + i
X.sort()
d = N // 2
for i in range(N):
if i < d:
L[X[i] % N] = X[d] // N
else:
L[X[i] % N] = X[d - 1] // N
for i in range(N):
print((L[i]))
| false | 12.5 | [
"-L = []",
"+L = [0 for _ in range(N)]",
"- L.append([X[i], i])",
"-L.sort()",
"+ X[i] = X[i] * N + i",
"+X.sort()",
"+d = N // 2",
"- if i < N // 2:",
"- L[i].append(L[N // 2][0])",
"+ if i < d:",
"+ L[X[i] % N] = X[d] // N",
"- L[i].append(L[N // 2 - 1][0])",
"+ L[X[i] % N] = X[d - 1] // N",
"- L[i][0], L[i][1] = L[i][1], L[i][0]",
"-L.sort()",
"-for i in range(N):",
"- print((L[i][2]))",
"+ print((L[i]))"
] | false | 0.047124 | 0.047715 | 0.987615 | [
"s099288055",
"s672857732"
] |
u119148115 | p02588 | python | s033301255 | s153425833 | 266 | 244 | 87,388 | 91,656 | Accepted | Accepted | 8.27 | import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N = I()
A = []
for _ in range(N):
a = LS2()
if not '.' in a:
a = int(''.join(a))
a *= 10**9
b,c = 0,0
while a % 2 == 0:
a //= 2
b += 1
while a % 5 == 0:
a //= 5
c += 1
A.append((b-9,c-9))
else:
i = a.index('.')
l = len(a)
del a[i]
a += ['0']*(9-l+1+i)
a = int(''.join(a))
b, c = 0, 0
while a % 2 == 0:
a //= 2
b += 1
while a % 5 == 0:
a //= 5
c += 1
A.append((b - 9, c - 9))
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
d[A[i]] += 1
ans = 0
for a in list(d.keys()):
b,c = a
x = 0
for e in list(d.keys()):
f,g = e
if f >= -b and g >= -c:
x += d[e]
ans += d[a]*x
for a in list(d.keys()):
b,c = a
if b >= 0 and c >= 0:
ans -= d[a]
print((ans//2))
| import sys
def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N = I()
A = [] # A[i] = A_iが2,5で各々何回割り切れるか
for _ in range(N):
a = LS2()
if not '.' in a:
a = int(''.join(a))
b,c = 0,0
while a % 2 == 0:
a //= 2
b += 1
while a % 5 == 0:
a //= 5
c += 1
A.append((b,c))
else:
i = a.index('.')
l = len(a)
del a[i]
a += ['0']*(9-l+1+i)
a = int(''.join(a)) # 与えられた実数を10**9倍したもの
b,c = 0,0
while a % 2 == 0:
a //= 2
b += 1
while a % 5 == 0:
a //= 5
c += 1
A.append((b-9,c-9))
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
d[A[i]] += 1
ans = 0
for a in list(d.keys()):
b,c = a
x = 0
for e in list(d.keys()):
f,g = e
if f >= -b and g >= -c: # 積が整数
x += d[e]
ans += d[a]*x
# 自分自身どうしの積が整数となるものを取り除く
for a in list(d.keys()):
b,c = a
if b >= 0 and c >= 0:
ans -= d[a]
print((ans//2))
| 63 | 56 | 1,493 | 1,185 | import sys
sys.setrecursionlimit(10**7)
def I():
return int(sys.stdin.readline().rstrip())
def MI():
return list(map(int, sys.stdin.readline().rstrip().split()))
def LI():
return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり
def LI2():
return list(map(int, sys.stdin.readline().rstrip())) # 空白なし
def S():
return sys.stdin.readline().rstrip()
def LS():
return list(sys.stdin.readline().rstrip().split()) # 空白あり
def LS2():
return list(sys.stdin.readline().rstrip()) # 空白なし
N = I()
A = []
for _ in range(N):
a = LS2()
if not "." in a:
a = int("".join(a))
a *= 10**9
b, c = 0, 0
while a % 2 == 0:
a //= 2
b += 1
while a % 5 == 0:
a //= 5
c += 1
A.append((b - 9, c - 9))
else:
i = a.index(".")
l = len(a)
del a[i]
a += ["0"] * (9 - l + 1 + i)
a = int("".join(a))
b, c = 0, 0
while a % 2 == 0:
a //= 2
b += 1
while a % 5 == 0:
a //= 5
c += 1
A.append((b - 9, c - 9))
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
d[A[i]] += 1
ans = 0
for a in list(d.keys()):
b, c = a
x = 0
for e in list(d.keys()):
f, g = e
if f >= -b and g >= -c:
x += d[e]
ans += d[a] * x
for a in list(d.keys()):
b, c = a
if b >= 0 and c >= 0:
ans -= d[a]
print((ans // 2))
| import sys
def I():
return int(sys.stdin.readline().rstrip())
def LS2():
return list(sys.stdin.readline().rstrip()) # 空白なし
N = I()
A = [] # A[i] = A_iが2,5で各々何回割り切れるか
for _ in range(N):
a = LS2()
if not "." in a:
a = int("".join(a))
b, c = 0, 0
while a % 2 == 0:
a //= 2
b += 1
while a % 5 == 0:
a //= 5
c += 1
A.append((b, c))
else:
i = a.index(".")
l = len(a)
del a[i]
a += ["0"] * (9 - l + 1 + i)
a = int("".join(a)) # 与えられた実数を10**9倍したもの
b, c = 0, 0
while a % 2 == 0:
a //= 2
b += 1
while a % 5 == 0:
a //= 5
c += 1
A.append((b - 9, c - 9))
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
d[A[i]] += 1
ans = 0
for a in list(d.keys()):
b, c = a
x = 0
for e in list(d.keys()):
f, g = e
if f >= -b and g >= -c: # 積が整数
x += d[e]
ans += d[a] * x
# 自分自身どうしの積が整数となるものを取り除く
for a in list(d.keys()):
b, c = a
if b >= 0 and c >= 0:
ans -= d[a]
print((ans // 2))
| false | 11.111111 | [
"-",
"-sys.setrecursionlimit(10**7)",
"-",
"-",
"-def MI():",
"- return list(map(int, sys.stdin.readline().rstrip().split()))",
"-",
"-",
"-def LI():",
"- return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり",
"-",
"-",
"-def LI2():",
"- return list(map(int, sys.stdin.readline().rstrip())) # 空白なし",
"-",
"-",
"-def S():",
"- return sys.stdin.readline().rstrip()",
"-",
"-",
"-def LS():",
"- return list(sys.stdin.readline().rstrip().split()) # 空白あり",
"-A = []",
"+A = [] # A[i] = A_iが2,5で各々何回割り切れるか",
"- a *= 10**9",
"- A.append((b - 9, c - 9))",
"+ A.append((b, c))",
"- a = int(\"\".join(a))",
"+ a = int(\"\".join(a)) # 与えられた実数を10**9倍したもの",
"- if f >= -b and g >= -c:",
"+ if f >= -b and g >= -c: # 積が整数",
"+# 自分自身どうしの積が整数となるものを取り除く"
] | false | 0.050017 | 0.110527 | 0.452529 | [
"s033301255",
"s153425833"
] |
u075012704 | p02954 | python | s756472764 | s852174672 | 127 | 117 | 9,712 | 6,508 | Accepted | Accepted | 7.87 | from math import ceil
import re
S = input()
N = len(S)
X = re.findall('R+L+', S)
ans = [0] * N
i = 0
for x in X:
x_len = len(x)
start = x.find('RL')
ans[i + start] += (x_len - start - 1) // 2 + ceil((start + 1) / 2)
ans[i + start + 1] += (start + 1) // 2 + ceil((x_len - start - 1) / 2)
i += x_len
print(*ans, sep=' ')
| S = input()
N = len(S)
ans = [0] * N
cnt = 0
for i, s in enumerate(S):
if s == 'R':
cnt += 1
else:
ans[i] += cnt // 2
ans[i - 1] += (cnt + 1) // 2
cnt = 0
cnt = 0
ans = ans[::-1]
for i, s in enumerate(S[::-1]):
if s == 'L':
cnt += 1
else:
ans[i] += cnt // 2
ans[i - 1] += (cnt + 1) // 2
cnt = 0
print(*ans[::-1], sep=' ')
| 19 | 26 | 362 | 432 | from math import ceil
import re
S = input()
N = len(S)
X = re.findall("R+L+", S)
ans = [0] * N
i = 0
for x in X:
x_len = len(x)
start = x.find("RL")
ans[i + start] += (x_len - start - 1) // 2 + ceil((start + 1) / 2)
ans[i + start + 1] += (start + 1) // 2 + ceil((x_len - start - 1) / 2)
i += x_len
print(*ans, sep=" ")
| S = input()
N = len(S)
ans = [0] * N
cnt = 0
for i, s in enumerate(S):
if s == "R":
cnt += 1
else:
ans[i] += cnt // 2
ans[i - 1] += (cnt + 1) // 2
cnt = 0
cnt = 0
ans = ans[::-1]
for i, s in enumerate(S[::-1]):
if s == "L":
cnt += 1
else:
ans[i] += cnt // 2
ans[i - 1] += (cnt + 1) // 2
cnt = 0
print(*ans[::-1], sep=" ")
| false | 26.923077 | [
"-from math import ceil",
"-import re",
"-",
"-X = re.findall(\"R+L+\", S)",
"-i = 0",
"-for x in X:",
"- x_len = len(x)",
"- start = x.find(\"RL\")",
"- ans[i + start] += (x_len - start - 1) // 2 + ceil((start + 1) / 2)",
"- ans[i + start + 1] += (start + 1) // 2 + ceil((x_len - start - 1) / 2)",
"- i += x_len",
"-print(*ans, sep=\" \")",
"+cnt = 0",
"+for i, s in enumerate(S):",
"+ if s == \"R\":",
"+ cnt += 1",
"+ else:",
"+ ans[i] += cnt // 2",
"+ ans[i - 1] += (cnt + 1) // 2",
"+ cnt = 0",
"+cnt = 0",
"+ans = ans[::-1]",
"+for i, s in enumerate(S[::-1]):",
"+ if s == \"L\":",
"+ cnt += 1",
"+ else:",
"+ ans[i] += cnt // 2",
"+ ans[i - 1] += (cnt + 1) // 2",
"+ cnt = 0",
"+print(*ans[::-1], sep=\" \")"
] | false | 0.13799 | 0.045633 | 3.023933 | [
"s756472764",
"s852174672"
] |
u964494353 | p03252 | python | s642697374 | s091992147 | 164 | 125 | 6,716 | 3,632 | Accepted | Accepted | 23.78 | S = eval(input())
T = eval(input())
sid = {}
tid = {}
ss = []
tt = []
sn = 0
tn = 0
for i in range(len(S)):
if not S[i] in sid:
sid[S[i]] = sn
sn += 1
ss += [sid[S[i]]]
if not T[i] in tid:
tid[T[i]] = tn
tn += 1
tt += [tid[T[i]]]
if ss == tt:
print('Yes')
else:
print('No') | S = eval(input())
T = eval(input())
for i in range(len(S)):
if S.find(S[i]) != T.find(T[i]):
print('No')
exit()
print('Yes') | 21 | 7 | 337 | 138 | S = eval(input())
T = eval(input())
sid = {}
tid = {}
ss = []
tt = []
sn = 0
tn = 0
for i in range(len(S)):
if not S[i] in sid:
sid[S[i]] = sn
sn += 1
ss += [sid[S[i]]]
if not T[i] in tid:
tid[T[i]] = tn
tn += 1
tt += [tid[T[i]]]
if ss == tt:
print("Yes")
else:
print("No")
| S = eval(input())
T = eval(input())
for i in range(len(S)):
if S.find(S[i]) != T.find(T[i]):
print("No")
exit()
print("Yes")
| false | 66.666667 | [
"-sid = {}",
"-tid = {}",
"-ss = []",
"-tt = []",
"-sn = 0",
"-tn = 0",
"- if not S[i] in sid:",
"- sid[S[i]] = sn",
"- sn += 1",
"- ss += [sid[S[i]]]",
"- if not T[i] in tid:",
"- tid[T[i]] = tn",
"- tn += 1",
"- tt += [tid[T[i]]]",
"-if ss == tt:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+ if S.find(S[i]) != T.find(T[i]):",
"+ print(\"No\")",
"+ exit()",
"+print(\"Yes\")"
] | false | 0.037867 | 0.070876 | 0.534269 | [
"s642697374",
"s091992147"
] |
u077291787 | p03821 | python | s804679676 | s811177140 | 186 | 87 | 17,380 | 25,124 | Accepted | Accepted | 53.23 | # AGC009A - Multiple Array
# greedy algorithm
import sys
input = sys.stdin.readline
def main():
n = int(eval(input()))
A = tuple(tuple(map(int, input().split())) for _ in range(n))
ans = 0
for i, j in A[::-1]: # # decide from the last one
ans += -(i + ans) % j
print(ans)
if __name__ == "__main__":
main() | # AGC009A - Multiple Array
def main():
N, *AB = list(map(int, open(0).read().split()))
ans = 0
for i, j in zip(*[iter(AB[::-1])] * 2): # decide from the last one greedily
ans += -(j + ans) % i
print(ans)
if __name__ == "__main__":
main() | 16 | 11 | 350 | 272 | # AGC009A - Multiple Array
# greedy algorithm
import sys
input = sys.stdin.readline
def main():
n = int(eval(input()))
A = tuple(tuple(map(int, input().split())) for _ in range(n))
ans = 0
for i, j in A[::-1]: # # decide from the last one
ans += -(i + ans) % j
print(ans)
if __name__ == "__main__":
main()
| # AGC009A - Multiple Array
def main():
N, *AB = list(map(int, open(0).read().split()))
ans = 0
for i, j in zip(*[iter(AB[::-1])] * 2): # decide from the last one greedily
ans += -(j + ans) % i
print(ans)
if __name__ == "__main__":
main()
| false | 31.25 | [
"-# greedy algorithm",
"-import sys",
"-",
"-input = sys.stdin.readline",
"-",
"-",
"- n = int(eval(input()))",
"- A = tuple(tuple(map(int, input().split())) for _ in range(n))",
"+ N, *AB = list(map(int, open(0).read().split()))",
"- for i, j in A[::-1]: # # decide from the last one",
"- ans += -(i + ans) % j",
"+ for i, j in zip(*[iter(AB[::-1])] * 2): # decide from the last one greedily",
"+ ans += -(j + ans) % i"
] | false | 0.079797 | 0.0424 | 1.882005 | [
"s804679676",
"s811177140"
] |
u923279197 | p03060 | python | s256245768 | s309364334 | 181 | 18 | 38,704 | 3,060 | Accepted | Accepted | 90.06 | n = int(eval(input()))
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(n):
ans += max(v[i]-c[i],0)
print(ans) | n = int(eval(input()))
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(n):
if v[i]-c[i] >0:
ans += v[i]-c[i]
print(ans) | 8 | 10 | 160 | 181 | n = int(eval(input()))
v = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
for i in range(n):
ans += max(v[i] - c[i], 0)
print(ans)
| n = int(eval(input()))
v = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
for i in range(n):
if v[i] - c[i] > 0:
ans += v[i] - c[i]
print(ans)
| false | 20 | [
"- ans += max(v[i] - c[i], 0)",
"+ if v[i] - c[i] > 0:",
"+ ans += v[i] - c[i]"
] | false | 0.05502 | 0.035484 | 1.550554 | [
"s256245768",
"s309364334"
] |
u094999522 | p02580 | python | s758850830 | s372179546 | 504 | 348 | 68,332 | 127,216 | Accepted | Accepted | 30.95 | (h,w,m),*s=[[*list(map(int,i.split()))]for i in open(0)]
r,c=[0]*-~h,[0]*-~w
for x,y in s:
r[x]+=1
c[y]+=1
print(((R:=max(r))+(C:=max(c))-(r.count(R)*c.count(C)==sum(r[x]+c[y]==R+C for x,y in s))))
| (h,w,m),*s=[[*list(map(int,i.split()))]for i in open(0)]
r,c=[0]*-~h,[0]*-~w
for x,y in s:
r[x]+=1
c[y]+=1
R,C=max(r),max(c)
print((R+C-(r.count(R)*c.count(C)==sum(r[x]+c[y]==R+C for x,y in s))))
| 6 | 7 | 203 | 202 | (h, w, m), *s = [[*list(map(int, i.split()))] for i in open(0)]
r, c = [0] * -~h, [0] * -~w
for x, y in s:
r[x] += 1
c[y] += 1
print(
(
(R := max(r))
+ (C := max(c))
- (r.count(R) * c.count(C) == sum(r[x] + c[y] == R + C for x, y in s))
)
)
| (h, w, m), *s = [[*list(map(int, i.split()))] for i in open(0)]
r, c = [0] * -~h, [0] * -~w
for x, y in s:
r[x] += 1
c[y] += 1
R, C = max(r), max(c)
print((R + C - (r.count(R) * c.count(C) == sum(r[x] + c[y] == R + C for x, y in s))))
| false | 14.285714 | [
"-print(",
"- (",
"- (R := max(r))",
"- + (C := max(c))",
"- - (r.count(R) * c.count(C) == sum(r[x] + c[y] == R + C for x, y in s))",
"- )",
"-)",
"+R, C = max(r), max(c)",
"+print((R + C - (r.count(R) * c.count(C) == sum(r[x] + c[y] == R + C for x, y in s))))"
] | false | 0.046713 | 0.039831 | 1.172772 | [
"s758850830",
"s372179546"
] |
u803848678 | p03702 | python | s834499700 | s905210324 | 1,128 | 884 | 7,892 | 7,192 | Accepted | Accepted | 21.63 | n, a, b = list(map(int, input().split()))
h = [int(eval(input())) for i in range(n)]
h.sort()
def check(k):
top = 0
tmp = h[::]
for i in range(n):
amari = tmp[i] - b*k
if amari > 0:
top += -(-amari//(a-b))
return top <= k
# 二分探索
left = 0
right = -(-1*sum(h)//b)
while(right-left>1):
next_ind = (left + right)//2
if check(next_ind):
right = next_ind
else:
left = next_ind
print(right) | n, a, b = list(map(int, input().split()))
h = [int(eval(input())) for i in range(n)]
def check(k):
cnt = 0
for i in h:
hp = i - k*b
if hp > 0:
cnt += -(-hp//(a-b))
return cnt <= k
left = 0
right = 10**10
while right - left>1:
mid = (right + left)//2
if check(mid):
right = mid
else:
left = mid
print(right)
| 23 | 20 | 473 | 384 | n, a, b = list(map(int, input().split()))
h = [int(eval(input())) for i in range(n)]
h.sort()
def check(k):
top = 0
tmp = h[::]
for i in range(n):
amari = tmp[i] - b * k
if amari > 0:
top += -(-amari // (a - b))
return top <= k
# 二分探索
left = 0
right = -(-1 * sum(h) // b)
while right - left > 1:
next_ind = (left + right) // 2
if check(next_ind):
right = next_ind
else:
left = next_ind
print(right)
| n, a, b = list(map(int, input().split()))
h = [int(eval(input())) for i in range(n)]
def check(k):
cnt = 0
for i in h:
hp = i - k * b
if hp > 0:
cnt += -(-hp // (a - b))
return cnt <= k
left = 0
right = 10**10
while right - left > 1:
mid = (right + left) // 2
if check(mid):
right = mid
else:
left = mid
print(right)
| false | 13.043478 | [
"-h.sort()",
"- top = 0",
"- tmp = h[::]",
"- for i in range(n):",
"- amari = tmp[i] - b * k",
"- if amari > 0:",
"- top += -(-amari // (a - b))",
"- return top <= k",
"+ cnt = 0",
"+ for i in h:",
"+ hp = i - k * b",
"+ if hp > 0:",
"+ cnt += -(-hp // (a - b))",
"+ return cnt <= k",
"-# 二分探索",
"-right = -(-1 * sum(h) // b)",
"+right = 10**10",
"- next_ind = (left + right) // 2",
"- if check(next_ind):",
"- right = next_ind",
"+ mid = (right + left) // 2",
"+ if check(mid):",
"+ right = mid",
"- left = next_ind",
"+ left = mid"
] | false | 0.049662 | 0.124662 | 0.398376 | [
"s834499700",
"s905210324"
] |
u489959379 | p02756 | python | s593253028 | s780999906 | 622 | 468 | 8,676 | 33,652 | Accepted | Accepted | 24.76 | from collections import deque
s = list(eval(input()))
q = int(eval(input()))
s = deque(s)
flg = "order"
for i in range(q):
t, *f = list(map(str, input().split()))
if t == "1":
if flg == "order":
flg = "reverse"
else:
flg = "order"
else:
if f[0] == "1":
if flg == "order":
s.appendleft(f[1])
else:
s.append(f[1])
else:
if flg == "order":
s.append(f[1])
else:
s.appendleft(f[1])
if flg == "order":
print(("".join(s)))
else:
s.reverse()
print(("".join(s))) | import sys
from collections import deque
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
s = eval(input())
q = int(eval(input()))
query = [list(input().split()) for _ in range(q)]
S = deque([s])
flg = 1
for i in range(q):
if query[i][0] == "1":
flg ^= 1
else:
_, f, c = query[i]
if f == "1":
S.appendleft(c) if flg else S.append(c)
else:
S.append(c) if flg else S.appendleft(c)
print(("".join(S) if flg else "".join(S)[::-1]))
if __name__ == '__main__':
resolve()
| 31 | 31 | 656 | 653 | from collections import deque
s = list(eval(input()))
q = int(eval(input()))
s = deque(s)
flg = "order"
for i in range(q):
t, *f = list(map(str, input().split()))
if t == "1":
if flg == "order":
flg = "reverse"
else:
flg = "order"
else:
if f[0] == "1":
if flg == "order":
s.appendleft(f[1])
else:
s.append(f[1])
else:
if flg == "order":
s.append(f[1])
else:
s.appendleft(f[1])
if flg == "order":
print(("".join(s)))
else:
s.reverse()
print(("".join(s)))
| import sys
from collections import deque
sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7
def resolve():
s = eval(input())
q = int(eval(input()))
query = [list(input().split()) for _ in range(q)]
S = deque([s])
flg = 1
for i in range(q):
if query[i][0] == "1":
flg ^= 1
else:
_, f, c = query[i]
if f == "1":
S.appendleft(c) if flg else S.append(c)
else:
S.append(c) if flg else S.appendleft(c)
print(("".join(S) if flg else "".join(S)[::-1]))
if __name__ == "__main__":
resolve()
| false | 0 | [
"+import sys",
"-s = list(eval(input()))",
"-q = int(eval(input()))",
"-s = deque(s)",
"-flg = \"order\"",
"-for i in range(q):",
"- t, *f = list(map(str, input().split()))",
"- if t == \"1\":",
"- if flg == \"order\":",
"- flg = \"reverse\"",
"+sys.setrecursionlimit(10**7)",
"+f_inf = float(\"inf\")",
"+mod = 10**9 + 7",
"+",
"+",
"+def resolve():",
"+ s = eval(input())",
"+ q = int(eval(input()))",
"+ query = [list(input().split()) for _ in range(q)]",
"+ S = deque([s])",
"+ flg = 1",
"+ for i in range(q):",
"+ if query[i][0] == \"1\":",
"+ flg ^= 1",
"- flg = \"order\"",
"- else:",
"- if f[0] == \"1\":",
"- if flg == \"order\":",
"- s.appendleft(f[1])",
"+ _, f, c = query[i]",
"+ if f == \"1\":",
"+ S.appendleft(c) if flg else S.append(c)",
"- s.append(f[1])",
"- else:",
"- if flg == \"order\":",
"- s.append(f[1])",
"- else:",
"- s.appendleft(f[1])",
"-if flg == \"order\":",
"- print((\"\".join(s)))",
"-else:",
"- s.reverse()",
"- print((\"\".join(s)))",
"+ S.append(c) if flg else S.appendleft(c)",
"+ print((\"\".join(S) if flg else \"\".join(S)[::-1]))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ resolve()"
] | false | 0.070898 | 0.042928 | 1.651549 | [
"s593253028",
"s780999906"
] |
u947883560 | p02796 | python | s665932510 | s800121338 | 631 | 414 | 27,540 | 52,316 | Accepted | Accepted | 34.39 | #!/usr/bin/env python3
import sys
INF = float("inf")
def solve(N: int, X: "List[int]", L: "List[int]"):
# 区間に変換する
segs = [(x-l, x+l) for x, l in zip(X, L)]
segs.sort(key=lambda x: x[1]) # 尻でソート
# DP i個目の区間まで考えた時の残せる数
DP = [0]*N
DP[0] = 1
for i in range(1, N):
# 重なっていなければ
if segs[i-1][1] <= segs[i][0]:
DP[i] = DP[i-1]+1
else:
# 加えないか
DP[i] = DP[i-1]
# 重なるものを抜いた場合の個数+1
left = -1
right = i-1
while right-left > 1:
mid = (right+left)//2
if segs[mid][1] <= segs[i][0]:
left = mid
else:
right = mid
# すべて重なるケースは区別
if left == -1:
buf = 1
else:
buf = DP[left]+1
DP[i] = max(buf, DP[i-1])
print((DP[-1]))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
X = [int()] * (N) # type: "List[int]"
L = [int()] * (N) # type: "List[int]"
for i in range(N):
X[i] = int(next(tokens))
L[i] = int(next(tokens))
solve(N, X, L)
if __name__ == '__main__':
main()
| #!/usr/bin/env python3
import sys
INF = float("inf")
def solve(N: int, X: "List[int]", L: "List[int]"):
# 区間に変換する
segs = [(x-l, x+l) for x, l in zip(X, L)]
segs.sort(key=lambda x: x[1]) # 尻でソート
last = -INF
count = 0
for i in range(N):
if last <= segs[i][0]:
last = segs[i][1]
count += 1
print(count)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
X = [int()] * (N) # type: "List[int]"
L = [int()] * (N) # type: "List[int]"
for i in range(N):
X[i] = int(next(tokens))
L[i] = int(next(tokens))
solve(N, X, L)
if __name__ == '__main__':
main()
| 59 | 40 | 1,420 | 856 | #!/usr/bin/env python3
import sys
INF = float("inf")
def solve(N: int, X: "List[int]", L: "List[int]"):
# 区間に変換する
segs = [(x - l, x + l) for x, l in zip(X, L)]
segs.sort(key=lambda x: x[1]) # 尻でソート
# DP i個目の区間まで考えた時の残せる数
DP = [0] * N
DP[0] = 1
for i in range(1, N):
# 重なっていなければ
if segs[i - 1][1] <= segs[i][0]:
DP[i] = DP[i - 1] + 1
else:
# 加えないか
DP[i] = DP[i - 1]
# 重なるものを抜いた場合の個数+1
left = -1
right = i - 1
while right - left > 1:
mid = (right + left) // 2
if segs[mid][1] <= segs[i][0]:
left = mid
else:
right = mid
# すべて重なるケースは区別
if left == -1:
buf = 1
else:
buf = DP[left] + 1
DP[i] = max(buf, DP[i - 1])
print((DP[-1]))
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
X = [int()] * (N) # type: "List[int]"
L = [int()] * (N) # type: "List[int]"
for i in range(N):
X[i] = int(next(tokens))
L[i] = int(next(tokens))
solve(N, X, L)
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
import sys
INF = float("inf")
def solve(N: int, X: "List[int]", L: "List[int]"):
# 区間に変換する
segs = [(x - l, x + l) for x, l in zip(X, L)]
segs.sort(key=lambda x: x[1]) # 尻でソート
last = -INF
count = 0
for i in range(N):
if last <= segs[i][0]:
last = segs[i][1]
count += 1
print(count)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
X = [int()] * (N) # type: "List[int]"
L = [int()] * (N) # type: "List[int]"
for i in range(N):
X[i] = int(next(tokens))
L[i] = int(next(tokens))
solve(N, X, L)
if __name__ == "__main__":
main()
| false | 32.20339 | [
"- # DP i個目の区間まで考えた時の残せる数",
"- DP = [0] * N",
"- DP[0] = 1",
"- for i in range(1, N):",
"- # 重なっていなければ",
"- if segs[i - 1][1] <= segs[i][0]:",
"- DP[i] = DP[i - 1] + 1",
"- else:",
"- # 加えないか",
"- DP[i] = DP[i - 1]",
"- # 重なるものを抜いた場合の個数+1",
"- left = -1",
"- right = i - 1",
"- while right - left > 1:",
"- mid = (right + left) // 2",
"- if segs[mid][1] <= segs[i][0]:",
"- left = mid",
"- else:",
"- right = mid",
"- # すべて重なるケースは区別",
"- if left == -1:",
"- buf = 1",
"- else:",
"- buf = DP[left] + 1",
"- DP[i] = max(buf, DP[i - 1])",
"- print((DP[-1]))",
"+ last = -INF",
"+ count = 0",
"+ for i in range(N):",
"+ if last <= segs[i][0]:",
"+ last = segs[i][1]",
"+ count += 1",
"+ print(count)"
] | false | 0.042115 | 0.040338 | 1.044037 | [
"s665932510",
"s800121338"
] |
u515740713 | p02536 | python | s829952074 | s206582327 | 1,695 | 207 | 966,480 | 79,252 | Accepted | Accepted | 87.79 | # -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,M = list(map(int,readline().split()))
road = [[] for _ in range(N+1)]
visit = [0]*(N+1)
for i in range(M):
x,y = list(map(int,readline().split()))
road[x].append(y)
road[y].append(x)
def dfs(v,prev):
for x in road[v]:
if x == prev:
continue
if visit[x] != 0:
continue
visit[x] = 1
dfs(x,v)
return
count = 0
for i in range(1,N+1):
if visit[i] == 0:
dfs(i,-1)
count += 1
print((count-1)) | # -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
#Union Find
#xの根を求める
def find(x):
if par[x] < 0:
return x
else:
par[x] = find(par[x])
return par[x]
#xとyの属する集合の併合
def union(x,y):
x = find(x)
y = find(y)
if x != y:
#sizeの大きいほうがx
if par[x] > par[y]:
x,y = y,x
par[x] += par[y] #xにyの個数くっつける
par[y] = x #yをxにくっつける
return
#xとyが同じ集合に属するかの判定
def same(x,y):
return find(x) == find(y)
#xが属する集合の個数
def size(x):
return -par[find(x)]
N,Q = list(map(int,readline().split()))
#0-index
par = [-1]*N
for _ in range(Q):
x,y = list(map(int,readline().split()))
x-=1; y-=1
union(x,y)
ans = set()
for i in range(N):
ans.add(find(i))
print((len(ans)-1)) | 33 | 48 | 684 | 914 | # -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, M = list(map(int, readline().split()))
road = [[] for _ in range(N + 1)]
visit = [0] * (N + 1)
for i in range(M):
x, y = list(map(int, readline().split()))
road[x].append(y)
road[y].append(x)
def dfs(v, prev):
for x in road[v]:
if x == prev:
continue
if visit[x] != 0:
continue
visit[x] = 1
dfs(x, v)
return
count = 0
for i in range(1, N + 1):
if visit[i] == 0:
dfs(i, -1)
count += 1
print((count - 1))
| # -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# Union Find
# xの根を求める
def find(x):
if par[x] < 0:
return x
else:
par[x] = find(par[x])
return par[x]
# xとyの属する集合の併合
def union(x, y):
x = find(x)
y = find(y)
if x != y:
# sizeの大きいほうがx
if par[x] > par[y]:
x, y = y, x
par[x] += par[y] # xにyの個数くっつける
par[y] = x # yをxにくっつける
return
# xとyが同じ集合に属するかの判定
def same(x, y):
return find(x) == find(y)
# xが属する集合の個数
def size(x):
return -par[find(x)]
N, Q = list(map(int, readline().split()))
# 0-index
par = [-1] * N
for _ in range(Q):
x, y = list(map(int, readline().split()))
x -= 1
y -= 1
union(x, y)
ans = set()
for i in range(N):
ans.add(find(i))
print((len(ans) - 1))
| false | 31.25 | [
"-N, M = list(map(int, readline().split()))",
"-road = [[] for _ in range(N + 1)]",
"-visit = [0] * (N + 1)",
"-for i in range(M):",
"- x, y = list(map(int, readline().split()))",
"- road[x].append(y)",
"- road[y].append(x)",
"+# Union Find",
"+# xの根を求める",
"+def find(x):",
"+ if par[x] < 0:",
"+ return x",
"+ else:",
"+ par[x] = find(par[x])",
"+ return par[x]",
"-def dfs(v, prev):",
"- for x in road[v]:",
"- if x == prev:",
"- continue",
"- if visit[x] != 0:",
"- continue",
"- visit[x] = 1",
"- dfs(x, v)",
"- return",
"+# xとyの属する集合の併合",
"+def union(x, y):",
"+ x = find(x)",
"+ y = find(y)",
"+ if x != y:",
"+ # sizeの大きいほうがx",
"+ if par[x] > par[y]:",
"+ x, y = y, x",
"+ par[x] += par[y] # xにyの個数くっつける",
"+ par[y] = x # yをxにくっつける",
"+ return",
"-count = 0",
"-for i in range(1, N + 1):",
"- if visit[i] == 0:",
"- dfs(i, -1)",
"- count += 1",
"-print((count - 1))",
"+# xとyが同じ集合に属するかの判定",
"+def same(x, y):",
"+ return find(x) == find(y)",
"+",
"+",
"+# xが属する集合の個数",
"+def size(x):",
"+ return -par[find(x)]",
"+",
"+",
"+N, Q = list(map(int, readline().split()))",
"+# 0-index",
"+par = [-1] * N",
"+for _ in range(Q):",
"+ x, y = list(map(int, readline().split()))",
"+ x -= 1",
"+ y -= 1",
"+ union(x, y)",
"+ans = set()",
"+for i in range(N):",
"+ ans.add(find(i))",
"+print((len(ans) - 1))"
] | false | 0.061354 | 0.036201 | 1.694825 | [
"s829952074",
"s206582327"
] |
u539281377 | p02953 | python | s531971572 | s263296538 | 85 | 61 | 15,020 | 14,396 | Accepted | Accepted | 28.24 | N=int(eval(input()))
H=list(map(int,input().split()))
flag=True
for i in range(1,N):
if H[i]>H[i-1]:
H[i]-=1
elif H[i]==H[i-1]:
pass
elif H[i]<H[i-1]:
flag=False
print(("Yes" if flag else "No")) | N=int(eval(input()))
H=list(map(int,input().split()))
pre=0
for h in H:
if h<pre:
print("No");exit()
elif h>pre:
pre=h-1
print("Yes") | 11 | 9 | 232 | 159 | N = int(eval(input()))
H = list(map(int, input().split()))
flag = True
for i in range(1, N):
if H[i] > H[i - 1]:
H[i] -= 1
elif H[i] == H[i - 1]:
pass
elif H[i] < H[i - 1]:
flag = False
print(("Yes" if flag else "No"))
| N = int(eval(input()))
H = list(map(int, input().split()))
pre = 0
for h in H:
if h < pre:
print("No")
exit()
elif h > pre:
pre = h - 1
print("Yes")
| false | 18.181818 | [
"-flag = True",
"-for i in range(1, N):",
"- if H[i] > H[i - 1]:",
"- H[i] -= 1",
"- elif H[i] == H[i - 1]:",
"- pass",
"- elif H[i] < H[i - 1]:",
"- flag = False",
"-print((\"Yes\" if flag else \"No\"))",
"+pre = 0",
"+for h in H:",
"+ if h < pre:",
"+ print(\"No\")",
"+ exit()",
"+ elif h > pre:",
"+ pre = h - 1",
"+print(\"Yes\")"
] | false | 0.03416 | 0.033912 | 1.00731 | [
"s531971572",
"s263296538"
] |
u226849101 | p02693 | python | s363688900 | s248573902 | 21 | 19 | 9,104 | 9,068 | Accepted | Accepted | 9.52 | k =int(eval(input()))
a , b=list(map(int,input().split()))
flag = False
if b-a >= k:
flag=True
else:
for i in range(a,b+1):
if i%k==0:
flag=True
if flag :
print("OK")
else:
print("NG")
| k =int(eval(input()))
a , b=list(map(int,input().split()))
flag = False
for i in range(a,b+1):#range(a,b+1)=[a,a+1,a+2,.....,b]
if i % k == 0:
flag=True
if flag :
print("OK")
else:
print("NG")
| 16 | 15 | 218 | 219 | k = int(eval(input()))
a, b = list(map(int, input().split()))
flag = False
if b - a >= k:
flag = True
else:
for i in range(a, b + 1):
if i % k == 0:
flag = True
if flag:
print("OK")
else:
print("NG")
| k = int(eval(input()))
a, b = list(map(int, input().split()))
flag = False
for i in range(a, b + 1): # range(a,b+1)=[a,a+1,a+2,.....,b]
if i % k == 0:
flag = True
if flag:
print("OK")
else:
print("NG")
| false | 6.25 | [
"-if b - a >= k:",
"- flag = True",
"-else:",
"- for i in range(a, b + 1):",
"- if i % k == 0:",
"- flag = True",
"+for i in range(a, b + 1): # range(a,b+1)=[a,a+1,a+2,.....,b]",
"+ if i % k == 0:",
"+ flag = True"
] | false | 0.036174 | 0.091665 | 0.394627 | [
"s363688900",
"s248573902"
] |
u971811058 | p03338 | python | s685468011 | s960427547 | 32 | 28 | 9,056 | 9,056 | Accepted | Accepted | 12.5 | n = int(eval(input()))
s = eval(input())
M = 0
for i in range(1, n):
cnt = 0
s1 = s[:i]
s2 = s[i:]
t = {}
for x in s1:
if x not in t: t[x]=1
for k in s2:
if k not in t: t[k]=0
if t[k] == 1: t[k]+=1
for x, y in list(t.items()):
if y==2: cnt+=1
M = max(cnt, M)
print(M) | n = int(eval(input()))
s = eval(input())
ans = 0
for i in range(1,len(s)):
s1 = set(s[:i])
s2 = set(s[i:])
ans = max(ans, len(s1&s2))
print(ans) | 17 | 8 | 329 | 151 | n = int(eval(input()))
s = eval(input())
M = 0
for i in range(1, n):
cnt = 0
s1 = s[:i]
s2 = s[i:]
t = {}
for x in s1:
if x not in t:
t[x] = 1
for k in s2:
if k not in t:
t[k] = 0
if t[k] == 1:
t[k] += 1
for x, y in list(t.items()):
if y == 2:
cnt += 1
M = max(cnt, M)
print(M)
| n = int(eval(input()))
s = eval(input())
ans = 0
for i in range(1, len(s)):
s1 = set(s[:i])
s2 = set(s[i:])
ans = max(ans, len(s1 & s2))
print(ans)
| false | 52.941176 | [
"-M = 0",
"-for i in range(1, n):",
"- cnt = 0",
"- s1 = s[:i]",
"- s2 = s[i:]",
"- t = {}",
"- for x in s1:",
"- if x not in t:",
"- t[x] = 1",
"- for k in s2:",
"- if k not in t:",
"- t[k] = 0",
"- if t[k] == 1:",
"- t[k] += 1",
"- for x, y in list(t.items()):",
"- if y == 2:",
"- cnt += 1",
"- M = max(cnt, M)",
"-print(M)",
"+ans = 0",
"+for i in range(1, len(s)):",
"+ s1 = set(s[:i])",
"+ s2 = set(s[i:])",
"+ ans = max(ans, len(s1 & s2))",
"+print(ans)"
] | false | 0.039826 | 0.143276 | 0.277965 | [
"s685468011",
"s960427547"
] |
u223264651 | p02598 | python | s088056088 | s559349060 | 419 | 303 | 104,416 | 104,396 | Accepted | Accepted | 27.68 | N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
left = 1
right= max(A)
import math
dict_X = {}
while True:
cl = 0
for i in range(N):
cl += math.ceil(A[i]/left) - 1
cr = 0
for i in range(N):
cr += math.ceil(A[i]/right) - 1
mid = (left + right)//2
cm = 0
for i in range(N):
cm += math.ceil(A[i]/mid) - 1
if(cl<=K):
right = left
break
elif(cm<=K):
right = mid
else:
left = mid
if(left>=right-1):
break
print(right)
| N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
left = 1
right= max(A)
import math
while True:
cl = 0
for i in range(N):
cl += math.ceil(A[i]/left) - 1
mid = (left + right)//2
cm = 0
for i in range(N):
cm += math.ceil(A[i]/mid) - 1
if(cl<=K):
right = left
break
if(cm<=K):
right = mid
else:
left = mid
if(abs(left-right)<=1):
break
print(right)
| 50 | 46 | 583 | 500 | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
left = 1
right = max(A)
import math
dict_X = {}
while True:
cl = 0
for i in range(N):
cl += math.ceil(A[i] / left) - 1
cr = 0
for i in range(N):
cr += math.ceil(A[i] / right) - 1
mid = (left + right) // 2
cm = 0
for i in range(N):
cm += math.ceil(A[i] / mid) - 1
if cl <= K:
right = left
break
elif cm <= K:
right = mid
else:
left = mid
if left >= right - 1:
break
print(right)
| N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
left = 1
right = max(A)
import math
while True:
cl = 0
for i in range(N):
cl += math.ceil(A[i] / left) - 1
mid = (left + right) // 2
cm = 0
for i in range(N):
cm += math.ceil(A[i] / mid) - 1
if cl <= K:
right = left
break
if cm <= K:
right = mid
else:
left = mid
if abs(left - right) <= 1:
break
print(right)
| false | 8 | [
"-dict_X = {}",
"- cr = 0",
"- for i in range(N):",
"- cr += math.ceil(A[i] / right) - 1",
"- elif cm <= K:",
"+ if cm <= K:",
"- if left >= right - 1:",
"+ if abs(left - right) <= 1:"
] | false | 0.085747 | 0.036281 | 2.363431 | [
"s088056088",
"s559349060"
] |
u667024514 | p03130 | python | s224650642 | s028996385 | 20 | 18 | 3,316 | 3,060 | Accepted | Accepted | 10 | from collections import Counter
lis = [0 for i in range(4)]
for i in range(3):
a,b = list(map(int,input().split()))
lis[a-1] += 1
lis[b-1] += 1
if lis.count(2) == 2:
print("YES")
else:print("NO") | lis = [1,2,2,3,3,4]
li = []
for i in range(3):
a,b, = list(map(int,input().split()))
li.append(a)
li.append(b)
li.sort()
if li == lis:
print("YES")
else:
print("NO") | 9 | 11 | 213 | 189 | from collections import Counter
lis = [0 for i in range(4)]
for i in range(3):
a, b = list(map(int, input().split()))
lis[a - 1] += 1
lis[b - 1] += 1
if lis.count(2) == 2:
print("YES")
else:
print("NO")
| lis = [1, 2, 2, 3, 3, 4]
li = []
for i in range(3):
(
a,
b,
) = list(map(int, input().split()))
li.append(a)
li.append(b)
li.sort()
if li == lis:
print("YES")
else:
print("NO")
| false | 18.181818 | [
"-from collections import Counter",
"-",
"-lis = [0 for i in range(4)]",
"+lis = [1, 2, 2, 3, 3, 4]",
"+li = []",
"- a, b = list(map(int, input().split()))",
"- lis[a - 1] += 1",
"- lis[b - 1] += 1",
"-if lis.count(2) == 2:",
"+ (",
"+ a,",
"+ b,",
"+ ) = list(map(int, input().split()))",
"+ li.append(a)",
"+ li.append(b)",
"+li.sort()",
"+if li == lis:"
] | false | 0.159486 | 0.253216 | 0.62984 | [
"s224650642",
"s028996385"
] |
u894258749 | p03103 | python | s300853618 | s202469212 | 1,235 | 466 | 15,576 | 29,024 | Accepted | Accepted | 62.27 | import numpy as np
N,M = list(map(int,input().split()))
A = np.empty(N,dtype=np.int64)
B = np.empty(N,dtype=np.int64)
for i in range(N):
A[i],B[i] = list(map(np.int64, input().split()))
order = A.argsort()
A = A[order]
B = B[order]
Y = 0
for i in range(N):
if B[i] >= M:
Y += A[i]*M
break
else:
Y += A[i]*B[i]
M -= B[i]
print(Y) | inpl = lambda: list(map(int,input().split()))
N,M = inpl()
A = []
for i in range(N):
A.append(inpl())
A.sort(key=lambda x: x[0])
Y = 0
for i in range(N):
if A[i][1] >= M:
Y += A[i][0]*M
break
else:
Y += A[i][0]*A[i][1]
M -= A[i][1]
print(Y) | 20 | 17 | 381 | 302 | import numpy as np
N, M = list(map(int, input().split()))
A = np.empty(N, dtype=np.int64)
B = np.empty(N, dtype=np.int64)
for i in range(N):
A[i], B[i] = list(map(np.int64, input().split()))
order = A.argsort()
A = A[order]
B = B[order]
Y = 0
for i in range(N):
if B[i] >= M:
Y += A[i] * M
break
else:
Y += A[i] * B[i]
M -= B[i]
print(Y)
| inpl = lambda: list(map(int, input().split()))
N, M = inpl()
A = []
for i in range(N):
A.append(inpl())
A.sort(key=lambda x: x[0])
Y = 0
for i in range(N):
if A[i][1] >= M:
Y += A[i][0] * M
break
else:
Y += A[i][0] * A[i][1]
M -= A[i][1]
print(Y)
| false | 15 | [
"-import numpy as np",
"-",
"-N, M = list(map(int, input().split()))",
"-A = np.empty(N, dtype=np.int64)",
"-B = np.empty(N, dtype=np.int64)",
"+inpl = lambda: list(map(int, input().split()))",
"+N, M = inpl()",
"+A = []",
"- A[i], B[i] = list(map(np.int64, input().split()))",
"-order = A.argsort()",
"-A = A[order]",
"-B = B[order]",
"+ A.append(inpl())",
"+A.sort(key=lambda x: x[0])",
"- if B[i] >= M:",
"- Y += A[i] * M",
"+ if A[i][1] >= M:",
"+ Y += A[i][0] * M",
"- Y += A[i] * B[i]",
"- M -= B[i]",
"+ Y += A[i][0] * A[i][1]",
"+ M -= A[i][1]"
] | false | 0.311191 | 0.042119 | 7.388442 | [
"s300853618",
"s202469212"
] |
u747602774 | p03745 | python | s163772501 | s868943339 | 94 | 86 | 14,440 | 14,252 | Accepted | Accepted | 8.51 | N = int(eval(input()))
A = list(map(int,input().split()))
ans = 1
#state0は未定、1は広義単調増加、2は広義単調減少
state = 0
m = A[0]
i = 1
while i <= N-1:
if m < A[i]:
if state == 0:
state = 1
m = A[i]
elif state == 1:
m = A[i]
else:
ans += 1
state = 0
m = A[i]
elif m > A[i]:
if state == 0:
state = 2
m = A[i]
elif state == 1:
ans += 1
state = 0
m = A[i]
else:
m = A[i]
i += 1
print(ans)
| N = int(eval(input()))
A = list(map(int,input().split()))
ans = 1
#state0は未定、1は広義単調増加、2は広義単調減少
state = 0
m = A[0]
i = 1
while i <= N-1:
if m < A[i]:
if state == 0:
state = 1
elif state == 2:
ans += 1
state = 0
elif m > A[i]:
if state == 0:
state = 2
elif state == 1:
ans += 1
state = 0
m = A[i]
i += 1
print(ans)
| 33 | 27 | 603 | 457 | N = int(eval(input()))
A = list(map(int, input().split()))
ans = 1
# state0は未定、1は広義単調増加、2は広義単調減少
state = 0
m = A[0]
i = 1
while i <= N - 1:
if m < A[i]:
if state == 0:
state = 1
m = A[i]
elif state == 1:
m = A[i]
else:
ans += 1
state = 0
m = A[i]
elif m > A[i]:
if state == 0:
state = 2
m = A[i]
elif state == 1:
ans += 1
state = 0
m = A[i]
else:
m = A[i]
i += 1
print(ans)
| N = int(eval(input()))
A = list(map(int, input().split()))
ans = 1
# state0は未定、1は広義単調増加、2は広義単調減少
state = 0
m = A[0]
i = 1
while i <= N - 1:
if m < A[i]:
if state == 0:
state = 1
elif state == 2:
ans += 1
state = 0
elif m > A[i]:
if state == 0:
state = 2
elif state == 1:
ans += 1
state = 0
m = A[i]
i += 1
print(ans)
| false | 18.181818 | [
"- m = A[i]",
"- elif state == 1:",
"- m = A[i]",
"- else:",
"+ elif state == 2:",
"- m = A[i]",
"- m = A[i]",
"- m = A[i]",
"- else:",
"- m = A[i]",
"+ m = A[i]"
] | false | 0.035161 | 0.121255 | 0.289976 | [
"s163772501",
"s868943339"
] |