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 list | 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 list |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u268793453 | p03142 | python | s975177464 | s925490143 | 1,808 | 1,067 | 316,036 | 146,652 | Accepted | Accepted | 40.98 | from sys import setrecursionlimit
setrecursionlimit(10 ** 9)
n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n + m - 1)]
T = [[] for i in range(n+1)]
RT = [set() for i in range(n+1)]
for a, b in A:
T[a].append(b)
RT[b].add(a)
D = [0] * (n+1)
P = [0] * (n+1)
used = [0] * (n+1)
def dfs(p, i, depth):
if used[i]:
return None
D[i] = depth
P[i] = p
used[i] = True
for t in tuple(T[i]):
RT[t].remove(i)
for t in tuple(T[i]):
if not RT[t]:
dfs(i, t, depth+1)
def root(i):
if not RT[i]:
return i
return root(tuple(RT[i])[0])
dfs(0, root(1), 1)
for p in P[1:]:
print(p) | from sys import setrecursionlimit
setrecursionlimit(10 ** 9)
n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n + m - 1)]
T = [[] for i in range(n+1)]
RT = [[] for i in range(n+1)]
IN = [0] * (n+1)
for a, b in A:
T[a].append(b)
RT[b].append(a)
IN[b] += 1
D = [0] * (n+1)
P = [0] * (n+1)
used = [0] * (n+1)
def dfs(p, i, depth):
if used[i]:
return None
D[i] = depth
P[i] = p
used[i] = True
for t in tuple(T[i]):
IN[t] -= 1
for t in tuple(T[i]):
if IN[t] == 0:
dfs(i, t, depth+1)
def root(i):
if not RT[i]:
return i
return root(RT[i][0])
dfs(0, root(1), 1)
for p in P[1:]:
print(p) | 37 | 39 | 739 | 762 | from sys import setrecursionlimit
setrecursionlimit(10**9)
n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n + m - 1)]
T = [[] for i in range(n + 1)]
RT = [set() for i in range(n + 1)]
for a, b in A:
T[a].append(b)
RT[b].add(a)
D = [0] * (n + 1)
P = [0] * (n + 1)
used = [0] * (n + 1)
def dfs(p, i, depth):
if used[i]:
return None
D[i] = depth
P[i] = p
used[i] = True
for t in tuple(T[i]):
RT[t].remove(i)
for t in tuple(T[i]):
if not RT[t]:
dfs(i, t, depth + 1)
def root(i):
if not RT[i]:
return i
return root(tuple(RT[i])[0])
dfs(0, root(1), 1)
for p in P[1:]:
print(p)
| from sys import setrecursionlimit
setrecursionlimit(10**9)
n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n + m - 1)]
T = [[] for i in range(n + 1)]
RT = [[] for i in range(n + 1)]
IN = [0] * (n + 1)
for a, b in A:
T[a].append(b)
RT[b].append(a)
IN[b] += 1
D = [0] * (n + 1)
P = [0] * (n + 1)
used = [0] * (n + 1)
def dfs(p, i, depth):
if used[i]:
return None
D[i] = depth
P[i] = p
used[i] = True
for t in tuple(T[i]):
IN[t] -= 1
for t in tuple(T[i]):
if IN[t] == 0:
dfs(i, t, depth + 1)
def root(i):
if not RT[i]:
return i
return root(RT[i][0])
dfs(0, root(1), 1)
for p in P[1:]:
print(p)
| false | 5.128205 | [
"-RT = [set() for i in range(n + 1)]",
"+RT = [[] for i in range(n + 1)]",
"+IN = [0] * (n + 1)",
"- RT[b].add(a)",
"+ RT[b].append(a)",
"+ IN[b] += 1",
"- RT[t].remove(i)",
"+ IN[t] -= 1",
"- if not RT[t]:",
"+ if IN[t] == 0:",
"- return root(tuple(RT[i])... | false | 0.043466 | 0.037146 | 1.170138 | [
"s975177464",
"s925490143"
] |
u133936772 | p02707 | python | s730236824 | s550574952 | 194 | 169 | 33,628 | 46,944 | Accepted | Accepted | 12.89 | n=int(eval(input()))
l=list(map(int,input().split()))
from collections import *
c=Counter(l)
for i in range(n): print((c[i+1])) | n=int(eval(input()))
from collections import *
c=Counter(list(map(int,input().split())))
for i in range(n): print((c[i+1])) | 5 | 4 | 123 | 112 | n = int(eval(input()))
l = list(map(int, input().split()))
from collections import *
c = Counter(l)
for i in range(n):
print((c[i + 1]))
| n = int(eval(input()))
from collections import *
c = Counter(list(map(int, input().split())))
for i in range(n):
print((c[i + 1]))
| false | 20 | [
"-l = list(map(int, input().split()))",
"-c = Counter(l)",
"+c = Counter(list(map(int, input().split())))"
] | false | 0.046738 | 0.045569 | 1.025661 | [
"s730236824",
"s550574952"
] |
u492910842 | p03486 | python | s281719258 | s724724064 | 128 | 68 | 61,276 | 61,680 | Accepted | Accepted | 46.88 | s=sorted(eval(input()))
t=sorted(eval(input()),reverse=True)
print(("Yes" if s<t else "No")) | print(("Yes" if sorted(eval(input()))<sorted(eval(input()))[::-1] else "No")) | 4 | 1 | 82 | 63 | s = sorted(eval(input()))
t = sorted(eval(input()), reverse=True)
print(("Yes" if s < t else "No"))
| print(("Yes" if sorted(eval(input())) < sorted(eval(input()))[::-1] else "No"))
| false | 75 | [
"-s = sorted(eval(input()))",
"-t = sorted(eval(input()), reverse=True)",
"-print((\"Yes\" if s < t else \"No\"))",
"+print((\"Yes\" if sorted(eval(input())) < sorted(eval(input()))[::-1] else \"No\"))"
] | false | 0.059888 | 0.059976 | 0.998527 | [
"s281719258",
"s724724064"
] |
u533039576 | p02603 | python | s823831206 | s689235520 | 31 | 28 | 9,212 | 9,168 | Accepted | Accepted | 9.68 | n = int(eval(input()))
a = [-1] + list(map(int, input().split()))
# dp[i] = (i+1)日目終了時点での金額の最大値
# dp[i] = max(dp[i-1], {dp[j-1] % a[j] + (dp[j-1] // a[j]) * a[i] | j<i})
dp = [0] * (n + 1)
dp[0] = dp[1] = 1000
dp[2] = max(dp[0] % a[1] + (dp[0] // a[1]) * a[2], dp[1])
for i in range(1, n + 1):
cand = dp[i - 1]
for j in range(1, i):
cand = max(cand, dp[j - 1] % a[j] + (dp[j - 1] // a[j]) * a[i])
dp[i] = cand
print((dp[n]))
| n = int(eval(input()))
a = list(map(int, input().split()))
ans = 1000
for i in range(n - 1):
if a[i] < a[i + 1]:
ans = ans % a[i] + (ans // a[i]) * a[i + 1]
print(ans)
| 16 | 9 | 455 | 184 | n = int(eval(input()))
a = [-1] + list(map(int, input().split()))
# dp[i] = (i+1)日目終了時点での金額の最大値
# dp[i] = max(dp[i-1], {dp[j-1] % a[j] + (dp[j-1] // a[j]) * a[i] | j<i})
dp = [0] * (n + 1)
dp[0] = dp[1] = 1000
dp[2] = max(dp[0] % a[1] + (dp[0] // a[1]) * a[2], dp[1])
for i in range(1, n + 1):
cand = dp[i - 1]
for j in range(1, i):
cand = max(cand, dp[j - 1] % a[j] + (dp[j - 1] // a[j]) * a[i])
dp[i] = cand
print((dp[n]))
| n = int(eval(input()))
a = list(map(int, input().split()))
ans = 1000
for i in range(n - 1):
if a[i] < a[i + 1]:
ans = ans % a[i] + (ans // a[i]) * a[i + 1]
print(ans)
| false | 43.75 | [
"-a = [-1] + list(map(int, input().split()))",
"-# dp[i] = (i+1)日目終了時点での金額の最大値",
"-# dp[i] = max(dp[i-1], {dp[j-1] % a[j] + (dp[j-1] // a[j]) * a[i] | j<i})",
"-dp = [0] * (n + 1)",
"-dp[0] = dp[1] = 1000",
"-dp[2] = max(dp[0] % a[1] + (dp[0] // a[1]) * a[2], dp[1])",
"-for i in range(1, n + 1):",
"- ... | false | 0.077326 | 0.109131 | 0.708559 | [
"s823831206",
"s689235520"
] |
u474561976 | p02598 | python | s082135178 | s421987428 | 1,077 | 615 | 30,740 | 30,732 | Accepted | Accepted | 42.9 | def main():
n,k = list(map(int,input().split()))
A = list(map(int,input().split()))
left = 0
right = max(A)
while abs(right-left)>1:
cent = (right+left)//2
ct = 0
for a in A:
ct+=(a-0.1)//cent
if ct <= k:
right=cent
else:
left=cent
print(right)
main() | def main():
n,k = list(map(int,input().split()))
A = list(map(int,input().split()))
left = 0
right = max(A)
while abs(right-left)>1:
cent = (right+left)//2
ct = 0
for a in A:
ct+=a//cent
if a%cent==0:
ct-=1
if ct <= k:
right=cent
else:
left=cent
print(right)
main() | 21 | 23 | 390 | 434 | def main():
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
left = 0
right = max(A)
while abs(right - left) > 1:
cent = (right + left) // 2
ct = 0
for a in A:
ct += (a - 0.1) // cent
if ct <= k:
right = cent
else:
left = cent
print(right)
main()
| def main():
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
left = 0
right = max(A)
while abs(right - left) > 1:
cent = (right + left) // 2
ct = 0
for a in A:
ct += a // cent
if a % cent == 0:
ct -= 1
if ct <= k:
right = cent
else:
left = cent
print(right)
main()
| false | 8.695652 | [
"- ct += (a - 0.1) // cent",
"+ ct += a // cent",
"+ if a % cent == 0:",
"+ ct -= 1"
] | false | 0.078144 | 0.03645 | 2.143836 | [
"s082135178",
"s421987428"
] |
u130900604 | p02861 | python | s640363599 | s157928945 | 166 | 17 | 38,512 | 3,064 | Accepted | Accepted | 89.76 | n=int(eval(input()))
x=[0]*n
y=[0]*n
for i in range(n):
x[i],y[i]=list(map(int,input().split()))
dist=0
for i in range(n):
for j in range(n):
dist+=((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5
print((dist/n))
| n=int(eval(input()))
x=[]
y=[]
for i in range(n):
a,b=list(map(int,input().split()))
x.append(a)
y.append(b)
def fac(n):
if n==0:
return 1
if n==1:
return 1
return n*fac(n-1)
ans=0
for i in range(n):
for j in range(n):
tmp=(((x[i]-x[j])**2+(y[i]-y[j])**2)**.5)
ans+=tmp
print((ans/n)) | 14 | 23 | 228 | 329 | n = int(eval(input()))
x = [0] * n
y = [0] * n
for i in range(n):
x[i], y[i] = list(map(int, input().split()))
dist = 0
for i in range(n):
for j in range(n):
dist += ((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2) ** 0.5
print((dist / n))
| n = int(eval(input()))
x = []
y = []
for i in range(n):
a, b = list(map(int, input().split()))
x.append(a)
y.append(b)
def fac(n):
if n == 0:
return 1
if n == 1:
return 1
return n * fac(n - 1)
ans = 0
for i in range(n):
for j in range(n):
tmp = ((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2) ** 0.5
ans += tmp
print((ans / n))
| false | 39.130435 | [
"-x = [0] * n",
"-y = [0] * n",
"+x = []",
"+y = []",
"- x[i], y[i] = list(map(int, input().split()))",
"-dist = 0",
"+ a, b = list(map(int, input().split()))",
"+ x.append(a)",
"+ y.append(b)",
"+",
"+",
"+def fac(n):",
"+ if n == 0:",
"+ return 1",
"+ if n == 1... | false | 0.048468 | 0.047473 | 1.020946 | [
"s640363599",
"s157928945"
] |
u413165887 | p03611 | python | s467695610 | s376753509 | 144 | 115 | 14,564 | 14,944 | Accepted | Accepted | 20.14 | from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
count_a = Counter(a)
result = []
for i in range(min(a),max(a)+1):
result.append(count_a[i]+count_a[i-1]+count_a[i+1])
print((max(result))) | from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
set_a = list(set(a))
#set_a = sorted(set_a)
count_a = Counter(a)
result = []
for i in set_a:
result.append(count_a[i]+count_a[i-1]+count_a[i+1])
print((max(result))) | 9 | 11 | 234 | 263 | from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
count_a = Counter(a)
result = []
for i in range(min(a), max(a) + 1):
result.append(count_a[i] + count_a[i - 1] + count_a[i + 1])
print((max(result)))
| from collections import Counter
n = int(eval(input()))
a = list(map(int, input().split()))
set_a = list(set(a))
# set_a = sorted(set_a)
count_a = Counter(a)
result = []
for i in set_a:
result.append(count_a[i] + count_a[i - 1] + count_a[i + 1])
print((max(result)))
| false | 18.181818 | [
"+set_a = list(set(a))",
"+# set_a = sorted(set_a)",
"-for i in range(min(a), max(a) + 1):",
"+for i in set_a:"
] | false | 0.04671 | 0.044689 | 1.045224 | [
"s467695610",
"s376753509"
] |
u102461423 | p02733 | python | s299453854 | s740671572 | 652 | 579 | 56,668 | 107,340 | Accepted | Accepted | 11.2 | #!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools
H, W, K = list(map(int, readline().split()))
S = [list(map(int, line.rstrip().decode())) for line in readlines()]
# transpose
S = tuple(itertools.chain(*list(zip(*S))))
INF = 10 ** 9
def solve(s):
dp = list(S)
for j in range(H - 1):
if s & (1 << j):
for n in range(0, H * W, H):
dp[n + j + 1] += dp[n + j]
cut = H - 1 - bin(s).count('1')
for n in range(0, H * W, H):
if any(dp[n + i] > K for i in range(H)):
return INF
if n + H == H * W:
return cut
if any(dp[n + i] + dp[n + i + H] > K for i in range(H)):
cut += 1
continue
for i in range(H):
dp[n + i + H] += dp[n + i]
return cut
answer = min(solve(s) for s in range(1 << (H - 1)))
print(answer)
| import sys
import numpy as np
import numba
from numba import njit
from numba.types import Omitted
i4 = numba.int32
i8 = numba.int64
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit((i8[:, :], i8), cache=True)
def main(S, K):
H, W = S.shape
ans = H + W + 100
for s in range(1 << H - 1):
cost = 0
T = S.copy()
for i in range(H - 1):
if s & 1 << i:
T[i + 1] += T[i]
else:
cost += 1
if np.any(T > K):
continue
cumsum = np.zeros(H, np.int64)
for w in range(W):
if np.any(cumsum + T[:, w] > K):
cumsum[:] = 0
cost += 1
cumsum += T[:, w]
ans = min(ans, cost)
return ans
H, W, K = list(map(int, readline().split()))
S = np.empty((H, W), np.int64)
for h in range(H):
S[h] = np.array(list(readline().rstrip().decode()))
print((main(S, K))) | 36 | 41 | 978 | 1,027 | #!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools
H, W, K = list(map(int, readline().split()))
S = [list(map(int, line.rstrip().decode())) for line in readlines()]
# transpose
S = tuple(itertools.chain(*list(zip(*S))))
INF = 10**9
def solve(s):
dp = list(S)
for j in range(H - 1):
if s & (1 << j):
for n in range(0, H * W, H):
dp[n + j + 1] += dp[n + j]
cut = H - 1 - bin(s).count("1")
for n in range(0, H * W, H):
if any(dp[n + i] > K for i in range(H)):
return INF
if n + H == H * W:
return cut
if any(dp[n + i] + dp[n + i + H] > K for i in range(H)):
cut += 1
continue
for i in range(H):
dp[n + i + H] += dp[n + i]
return cut
answer = min(solve(s) for s in range(1 << (H - 1)))
print(answer)
| import sys
import numpy as np
import numba
from numba import njit
from numba.types import Omitted
i4 = numba.int32
i8 = numba.int64
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit((i8[:, :], i8), cache=True)
def main(S, K):
H, W = S.shape
ans = H + W + 100
for s in range(1 << H - 1):
cost = 0
T = S.copy()
for i in range(H - 1):
if s & 1 << i:
T[i + 1] += T[i]
else:
cost += 1
if np.any(T > K):
continue
cumsum = np.zeros(H, np.int64)
for w in range(W):
if np.any(cumsum + T[:, w] > K):
cumsum[:] = 0
cost += 1
cumsum += T[:, w]
ans = min(ans, cost)
return ans
H, W, K = list(map(int, readline().split()))
S = np.empty((H, W), np.int64)
for h in range(H):
S[h] = np.array(list(readline().rstrip().decode()))
print((main(S, K)))
| false | 12.195122 | [
"-#!/usr/bin/ python3.8",
"+import numpy as np",
"+import numba",
"+from numba import njit",
"+from numba.types import Omitted",
"+i4 = numba.int32",
"+i8 = numba.int64",
"-import itertools",
"+",
"+",
"+@njit((i8[:, :], i8), cache=True)",
"+def main(S, K):",
"+ H, W = S.shape",
"+ a... | false | 0.104185 | 0.205549 | 0.506863 | [
"s299453854",
"s740671572"
] |
u588341295 | p02918 | python | s199881942 | s478158527 | 150 | 134 | 17,352 | 16,472 | Accepted | Accepted | 10.67 | # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N, K = MAP()
S = eval(input())
is_ok = [0] * N
for i in range(N):
if S[i] == 'L':
if i != 0 and S[i-1] == 'L':
is_ok[i] = 1
else:
if i != N-1 and S[i+1] == 'R':
is_ok[i] = 1
cur = S[0]
A = []
st = 0
tmp = is_ok[0]
for i in range(1, N):
if S[i] == cur:
tmp += is_ok[i]
else:
A.append((tmp, st, i, cur))
st = i
tmp = is_ok[i]
cur = S[i]
A.append((tmp, st, N, cur))
LR = {'L': [], 'R': []}
for cnt, st, end, d in A:
if st == 0 and end == N:
pass
elif st == 0 or end == N:
LR[d].append(1)
else:
LR[d].append(2)
LR['L'].sort(reverse=True)
LR['R'].sort(reverse=True)
ans = sum(is_ok)
# if ans == N-1:
# print(ans)
# exit()
ans += max(sum(LR['L'][:K]), sum(LR['R'][:K]))
print(ans)
| # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N, K = MAP()
S = eval(input())
# 初期状態でOKなものを数えておく
is_ok = [0] * N
for i in range(N):
if S[i] == 'L':
if i != 0 and S[i-1] == 'L':
is_ok[i] = 1
else:
if i != N-1 and S[i+1] == 'R':
is_ok[i] = 1
# LかRが連続する区間毎にまとめる
A = []
st = 0
for i in range(1, N):
if S[i] != S[i-1]:
A.append((st, i, S[i-1]))
st = i
A.append((st, N, S[-1]))
# その区間を逆にしたらいくつ増やせるかを格納するLR
LR = {'L': [], 'R': []}
# ずっとLかRだけなら何も増やせない
if len(A) >= 2:
for st, end, d in A:
# 先頭と末尾だけは+1
if st == 0 or end == N:
LR[d].append(1)
# 他の場所は+2できる
else:
LR[d].append(2)
LR['L'].sort(reverse=True)
LR['R'].sort(reverse=True)
# 大きい値から貪欲にK回変えてみて、Lを変えるとRを変えるの良い方
ans = sum(is_ok) + max(sum(LR['L'][:K]), sum(LR['R'][:K]))
print(ans)
| 65 | 59 | 1,530 | 1,516 | # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
N, K = MAP()
S = eval(input())
is_ok = [0] * N
for i in range(N):
if S[i] == "L":
if i != 0 and S[i - 1] == "L":
is_ok[i] = 1
else:
if i != N - 1 and S[i + 1] == "R":
is_ok[i] = 1
cur = S[0]
A = []
st = 0
tmp = is_ok[0]
for i in range(1, N):
if S[i] == cur:
tmp += is_ok[i]
else:
A.append((tmp, st, i, cur))
st = i
tmp = is_ok[i]
cur = S[i]
A.append((tmp, st, N, cur))
LR = {"L": [], "R": []}
for cnt, st, end, d in A:
if st == 0 and end == N:
pass
elif st == 0 or end == N:
LR[d].append(1)
else:
LR[d].append(2)
LR["L"].sort(reverse=True)
LR["R"].sort(reverse=True)
ans = sum(is_ok)
# if ans == N-1:
# print(ans)
# exit()
ans += max(sum(LR["L"][:K]), sum(LR["R"][:K]))
print(ans)
| # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
N, K = MAP()
S = eval(input())
# 初期状態でOKなものを数えておく
is_ok = [0] * N
for i in range(N):
if S[i] == "L":
if i != 0 and S[i - 1] == "L":
is_ok[i] = 1
else:
if i != N - 1 and S[i + 1] == "R":
is_ok[i] = 1
# LかRが連続する区間毎にまとめる
A = []
st = 0
for i in range(1, N):
if S[i] != S[i - 1]:
A.append((st, i, S[i - 1]))
st = i
A.append((st, N, S[-1]))
# その区間を逆にしたらいくつ増やせるかを格納するLR
LR = {"L": [], "R": []}
# ずっとLかRだけなら何も増やせない
if len(A) >= 2:
for st, end, d in A:
# 先頭と末尾だけは+1
if st == 0 or end == N:
LR[d].append(1)
# 他の場所は+2できる
else:
LR[d].append(2)
LR["L"].sort(reverse=True)
LR["R"].sort(reverse=True)
# 大きい値から貪欲にK回変えてみて、Lを変えるとRを変えるの良い方
ans = sum(is_ok) + max(sum(LR["L"][:K]), sum(LR["R"][:K]))
print(ans)
| false | 9.230769 | [
"+# 初期状態でOKなものを数えておく",
"-cur = S[0]",
"+# LかRが連続する区間毎にまとめる",
"-tmp = is_ok[0]",
"- if S[i] == cur:",
"- tmp += is_ok[i]",
"- else:",
"- A.append((tmp, st, i, cur))",
"+ if S[i] != S[i - 1]:",
"+ A.append((st, i, S[i - 1]))",
"- tmp = is_ok[i]",
"- cu... | false | 0.008546 | 0.042304 | 0.202006 | [
"s199881942",
"s478158527"
] |
u788068140 | p03160 | python | s902694395 | s847492474 | 154 | 110 | 13,908 | 13,928 | Accepted | Accepted | 28.57 | # N = 4
# HRR = [10, 30, 40, 20]
# N = 2
# HRR = [10, 10]
N = int(eval(input()))
HRR = list(map(int,input().split()))
result = []
for i in range(N):
if i == 0:
result.append(0)
elif i == 1:
s1 = result[i - 1] + abs(HRR[i] - HRR[i - 1])
result.append(s1)
else:
s1 = result[i - 1] + abs(HRR[i] - HRR[i - 1])
s2 = result[i - 2] + abs(HRR[i] - HRR[i - 2])
result.append(min(s1, s2))
print((result[-1]))
| N = int(eval(input()))
HRR = list(map(int,input().split()))
def calculate(n, hrr):
result = []
for index,value in enumerate(hrr):
if index == 0:
result.append(0)
elif index == 1:
result.append(abs(hrr[index]-hrr[index-1]) + result[index-1])
else:
s1 = abs(hrr[index] - hrr[index-1]) + result[index - 1]
s2 = abs(hrr[index] - hrr[index-2]) + result[index - 2]
result.append(min(s1,s2))
print((result[-1]))
calculate(N,HRR)
| 20 | 22 | 472 | 538 | # N = 4
# HRR = [10, 30, 40, 20]
# N = 2
# HRR = [10, 10]
N = int(eval(input()))
HRR = list(map(int, input().split()))
result = []
for i in range(N):
if i == 0:
result.append(0)
elif i == 1:
s1 = result[i - 1] + abs(HRR[i] - HRR[i - 1])
result.append(s1)
else:
s1 = result[i - 1] + abs(HRR[i] - HRR[i - 1])
s2 = result[i - 2] + abs(HRR[i] - HRR[i - 2])
result.append(min(s1, s2))
print((result[-1]))
| N = int(eval(input()))
HRR = list(map(int, input().split()))
def calculate(n, hrr):
result = []
for index, value in enumerate(hrr):
if index == 0:
result.append(0)
elif index == 1:
result.append(abs(hrr[index] - hrr[index - 1]) + result[index - 1])
else:
s1 = abs(hrr[index] - hrr[index - 1]) + result[index - 1]
s2 = abs(hrr[index] - hrr[index - 2]) + result[index - 2]
result.append(min(s1, s2))
print((result[-1]))
calculate(N, HRR)
| false | 9.090909 | [
"-# N = 4",
"-# HRR = [10, 30, 40, 20]",
"-# N = 2",
"-# HRR = [10, 10]",
"-result = []",
"-for i in range(N):",
"- if i == 0:",
"- result.append(0)",
"- elif i == 1:",
"- s1 = result[i - 1] + abs(HRR[i] - HRR[i - 1])",
"- result.append(s1)",
"- else:",
"- ... | false | 0.079249 | 0.037844 | 2.094094 | [
"s902694395",
"s847492474"
] |
u077291787 | p02983 | python | s312255006 | s095217935 | 44 | 32 | 3,064 | 3,064 | Accepted | Accepted | 27.27 | # ABC133C - Remainder Minimization 2019
def main():
L, R = list(map(int, input().rstrip().split()))
MOD = 2019
if R - L + 1 >= MOD: # L <= 2019n <= R
print((0))
else: # max: 2018 * 2017 patterns
L, R = L % MOD, R % MOD
if L <= 3 and R >= 673:
print((0))
return
ans = float("inf")
for i in range(L, R):
for j in range(i + 1, R + 1):
ans = min(ans, (i * j) % MOD)
print(ans)
if __name__ == "__main__":
main() | # ABC133C - Remainder Minimization 2019
def main():
L, R = list(map(int, input().rstrip().split()))
MOD = 2019
if R - L + 1 >= MOD: # L <= 2019n <= R
print((0))
else: # max: 2018 * 2017 patterns
L, R = L % MOD, R % MOD
if L <= 3 and R >= 673: # 2019 = 3 * 673
print((0))
return
ans = float("inf")
for i in range(L, R):
for j in range(i + 1, R + 1):
tmp = (i * j) % MOD
if tmp < ans:
ans = tmp
print(ans)
if __name__ == "__main__":
main() | 20 | 22 | 545 | 615 | # ABC133C - Remainder Minimization 2019
def main():
L, R = list(map(int, input().rstrip().split()))
MOD = 2019
if R - L + 1 >= MOD: # L <= 2019n <= R
print((0))
else: # max: 2018 * 2017 patterns
L, R = L % MOD, R % MOD
if L <= 3 and R >= 673:
print((0))
return
ans = float("inf")
for i in range(L, R):
for j in range(i + 1, R + 1):
ans = min(ans, (i * j) % MOD)
print(ans)
if __name__ == "__main__":
main()
| # ABC133C - Remainder Minimization 2019
def main():
L, R = list(map(int, input().rstrip().split()))
MOD = 2019
if R - L + 1 >= MOD: # L <= 2019n <= R
print((0))
else: # max: 2018 * 2017 patterns
L, R = L % MOD, R % MOD
if L <= 3 and R >= 673: # 2019 = 3 * 673
print((0))
return
ans = float("inf")
for i in range(L, R):
for j in range(i + 1, R + 1):
tmp = (i * j) % MOD
if tmp < ans:
ans = tmp
print(ans)
if __name__ == "__main__":
main()
| false | 9.090909 | [
"- if L <= 3 and R >= 673:",
"+ if L <= 3 and R >= 673: # 2019 = 3 * 673",
"- ans = min(ans, (i * j) % MOD)",
"+ tmp = (i * j) % MOD",
"+ if tmp < ans:",
"+ ans = tmp"
] | false | 0.042269 | 0.060816 | 0.695026 | [
"s312255006",
"s095217935"
] |
u285891772 | p02659 | python | s246106735 | s890762256 | 32 | 29 | 10,544 | 10,712 | Accepted | Accepted | 9.38 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, floor
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
from decimal import *
A, B = MAP()
A = int(A)
b = ""
for x in B:
if x != ".":
b += x
b = int(b)
print((A*b//100)) | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, floor
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(str, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
from decimal import *
def MAP(): return list(map(str, input().split()))
a, b = MAP()
print((int(Decimal(a)*Decimal(b)))) | 30 | 24 | 983 | 973 | import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
gcd,
floor,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# import numpy as np
from decimal import *
A, B = MAP()
A = int(A)
b = ""
for x in B:
if x != ".":
b += x
b = int(b)
print((A * b // 100))
| import sys, re
from collections import deque, defaultdict, Counter
from math import (
ceil,
sqrt,
hypot,
factorial,
pi,
sin,
cos,
tan,
asin,
acos,
atan,
radians,
degrees,
log2,
gcd,
floor,
)
from itertools import (
accumulate,
permutations,
combinations,
combinations_with_replacement,
product,
groupby,
)
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(str, input().split()))
def LIST():
return list(map(int, input().split()))
def ZIP(n):
return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
# import numpy as np
from decimal import *
def MAP():
return list(map(str, input().split()))
a, b = MAP()
print((int(Decimal(a) * Decimal(b))))
| false | 20 | [
"-A, B = MAP()",
"-A = int(A)",
"-b = \"\"",
"-for x in B:",
"- if x != \".\":",
"- b += x",
"-b = int(b)",
"-print((A * b // 100))",
"+",
"+def MAP():",
"+ return list(map(str, input().split()))",
"+",
"+",
"+a, b = MAP()",
"+print((int(Decimal(a) * Decimal(b))))"
] | false | 0.037921 | 0.100596 | 0.376961 | [
"s246106735",
"s890762256"
] |
u600402037 | p02690 | python | s683912721 | s806775076 | 300 | 60 | 80,020 | 68,140 | Accepted | Accepted | 80 | # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# (X - Y) (X^4 + X^3 Y + X^2 Y^2 + X Y^3 + Y^4)
X = ir()
def make_divisors(n): # nの約数を列挙
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
U = 5 * 10 ** 6
div = make_divisors(X)
for b in range(U):
for d in div:
a = b + d
if a ** 5 - b ** 5 == X:
print((a, b))
exit()
a = b - d
if b ** 5 - a ** 5 == X:
print((b, a))
exit()
| # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# (X - Y) (X^4 + X^3 Y + X^2 Y^2 + X Y^3 + Y^4)
X = ir()
def make_divisors(n): # nの約数を列挙
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
U = 10 ** 4
div = make_divisors(X)
for a in range(U):
for d in div:
b = a - d
if a ** 5 - b ** 5 == X:
print((a, b))
exit()
| 32 | 28 | 748 | 645 | # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# (X - Y) (X^4 + X^3 Y + X^2 Y^2 + X Y^3 + Y^4)
X = ir()
def make_divisors(n): # nの約数を列挙
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort()
return divisors
U = 5 * 10**6
div = make_divisors(X)
for b in range(U):
for d in div:
a = b + d
if a**5 - b**5 == X:
print((a, b))
exit()
a = b - d
if b**5 - a**5 == X:
print((b, a))
exit()
| # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# (X - Y) (X^4 + X^3 Y + X^2 Y^2 + X Y^3 + Y^4)
X = ir()
def make_divisors(n): # nの約数を列挙
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort()
return divisors
U = 10**4
div = make_divisors(X)
for a in range(U):
for d in div:
b = a - d
if a**5 - b**5 == X:
print((a, b))
exit()
| false | 12.5 | [
"-U = 5 * 10**6",
"+U = 10**4",
"-for b in range(U):",
"+for a in range(U):",
"- a = b + d",
"+ b = a - d",
"- a = b - d",
"- if b**5 - a**5 == X:",
"- print((b, a))",
"- exit()"
] | false | 0.039612 | 0.073552 | 0.538558 | [
"s683912721",
"s806775076"
] |
u133936772 | p02725 | python | s011219558 | s135213146 | 109 | 99 | 25,124 | 31,832 | Accepted | Accepted | 9.17 | k,n,*l=list(map(int,open(0).read().split()));print((min((l[i-1]-l[i])%k for i in range(n)))) | k,n,*l=list(map(int,open(0).read().split()))
print((k-max((l[i]-l[i-1])%k for i in range(n)))) | 1 | 2 | 84 | 87 | k, n, *l = list(map(int, open(0).read().split()))
print((min((l[i - 1] - l[i]) % k for i in range(n))))
| k, n, *l = list(map(int, open(0).read().split()))
print((k - max((l[i] - l[i - 1]) % k for i in range(n))))
| false | 50 | [
"-print((min((l[i - 1] - l[i]) % k for i in range(n))))",
"+print((k - max((l[i] - l[i - 1]) % k for i in range(n))))"
] | false | 0.037236 | 0.036434 | 1.022016 | [
"s011219558",
"s135213146"
] |
u423665486 | p03945 | python | s736550971 | s893201060 | 180 | 33 | 39,280 | 3,188 | Accepted | Accepted | 81.67 | def resolve():
s = eval(input())
c = 0
for i in range(len(s) - 1):
if s[i] != s[i+1]:
c += 1
print(c)
resolve() | def resolve():
s = eval(input())
c = 0
for i in range(len(s) - 1):
if s[i] != s[i+1]:
c += 1
if not c:
print((0))
return
print(c)
resolve() | 8 | 11 | 121 | 155 | def resolve():
s = eval(input())
c = 0
for i in range(len(s) - 1):
if s[i] != s[i + 1]:
c += 1
print(c)
resolve()
| def resolve():
s = eval(input())
c = 0
for i in range(len(s) - 1):
if s[i] != s[i + 1]:
c += 1
if not c:
print((0))
return
print(c)
resolve()
| false | 27.272727 | [
"+ if not c:",
"+ print((0))",
"+ return"
] | false | 0.036426 | 0.034921 | 1.043088 | [
"s736550971",
"s893201060"
] |
u860002137 | p02819 | python | s910217471 | s838953928 | 529 | 51 | 92,964 | 14,884 | Accepted | Accepted | 90.36 | import numpy as np
n = 1000003
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
primes.difference_update(list(range(i*2, n+1, i)))
primes = np.array(list(primes))
x = int(eval(input()))
print((primes[np.where(primes>=x)][0])) | n = 10**5 + 3
primes = set(range(3, n+1, 2))
for i in range(3, int(n**0.5+1)):
primes.difference_update(list(range(i*2, n+1, i)))
primes.add(2)
primes = list(primes)
primes.sort()
x = int(eval(input()))
primes = [y for y in primes if y >= x]
print((primes[0])) | 13 | 14 | 245 | 267 | import numpy as np
n = 1000003
primes = set(range(2, n + 1))
for i in range(2, int(n**0.5 + 1)):
primes.difference_update(list(range(i * 2, n + 1, i)))
primes = np.array(list(primes))
x = int(eval(input()))
print((primes[np.where(primes >= x)][0]))
| n = 10**5 + 3
primes = set(range(3, n + 1, 2))
for i in range(3, int(n**0.5 + 1)):
primes.difference_update(list(range(i * 2, n + 1, i)))
primes.add(2)
primes = list(primes)
primes.sort()
x = int(eval(input()))
primes = [y for y in primes if y >= x]
print((primes[0]))
| false | 7.142857 | [
"-import numpy as np",
"-",
"-n = 1000003",
"-primes = set(range(2, n + 1))",
"-for i in range(2, int(n**0.5 + 1)):",
"+n = 10**5 + 3",
"+primes = set(range(3, n + 1, 2))",
"+for i in range(3, int(n**0.5 + 1)):",
"-primes = np.array(list(primes))",
"+primes.add(2)",
"+primes = list(primes)",
"... | false | 1.5578 | 0.12451 | 12.511435 | [
"s910217471",
"s838953928"
] |
u510829608 | p02316 | python | s410206116 | s436958672 | 1,890 | 1,180 | 18,288 | 18,304 | Accepted | Accepted | 37.57 | INF = 10 ** 12
N, W = list(map(int, input().split()))
items =[] * N
for i in range(N):
v, w = list(map(int, input().split()))
items.append([v,w])
dp = [[INF for i in range(W+1)] for j in range(N+1)]
for i in range(W+1):
dp[0][i] = 0
for i in range(N+1):
dp[i][0] = 0
for i in range(1,N+1): #1<= i <= N
for j in range(1, W+1): # 1 <= j <= W
if j - items[i-1][1] >= 0:
dp[i][j] = max(dp[i-1][j], dp[i-1][j - items[i-1][1]] + items[i-1][0], dp[i][j - items[i-1][1]] + items[i-1][0])
else:
dp[i][j] = dp[i-1][j]
print((dp[N][W])) | def solve():
INF = 10 ** 12
N, W = list(map(int, input().split()))
items =[] * N
for i in range(N):
v, w = list(map(int, input().split()))
items.append([v,w])
dp = [[INF for i in range(W+1)] for j in range(N+1)]
for i in range(W+1):
dp[0][i] = 0
for i in range(N+1):
dp[i][0] = 0
for i in range(1,N+1): #1<= i <= N
for j in range(1, W+1): # 1 <= j <= W
if j - items[i-1][1] >= 0:
dp[i][j] = max(dp[i-1][j], dp[i-1][j - items[i-1][1]] + items[i-1][0], dp[i][j - items[i-1][1]] + items[i-1][0])
else:
dp[i][j] = dp[i-1][j]
print((dp[N][W]))
if __name__ == '__main__':
solve() | 26 | 31 | 604 | 771 | INF = 10**12
N, W = list(map(int, input().split()))
items = [] * N
for i in range(N):
v, w = list(map(int, input().split()))
items.append([v, w])
dp = [[INF for i in range(W + 1)] for j in range(N + 1)]
for i in range(W + 1):
dp[0][i] = 0
for i in range(N + 1):
dp[i][0] = 0
for i in range(1, N + 1): # 1<= i <= N
for j in range(1, W + 1): # 1 <= j <= W
if j - items[i - 1][1] >= 0:
dp[i][j] = max(
dp[i - 1][j],
dp[i - 1][j - items[i - 1][1]] + items[i - 1][0],
dp[i][j - items[i - 1][1]] + items[i - 1][0],
)
else:
dp[i][j] = dp[i - 1][j]
print((dp[N][W]))
| def solve():
INF = 10**12
N, W = list(map(int, input().split()))
items = [] * N
for i in range(N):
v, w = list(map(int, input().split()))
items.append([v, w])
dp = [[INF for i in range(W + 1)] for j in range(N + 1)]
for i in range(W + 1):
dp[0][i] = 0
for i in range(N + 1):
dp[i][0] = 0
for i in range(1, N + 1): # 1<= i <= N
for j in range(1, W + 1): # 1 <= j <= W
if j - items[i - 1][1] >= 0:
dp[i][j] = max(
dp[i - 1][j],
dp[i - 1][j - items[i - 1][1]] + items[i - 1][0],
dp[i][j - items[i - 1][1]] + items[i - 1][0],
)
else:
dp[i][j] = dp[i - 1][j]
print((dp[N][W]))
if __name__ == "__main__":
solve()
| false | 16.129032 | [
"-INF = 10**12",
"-N, W = list(map(int, input().split()))",
"-items = [] * N",
"-for i in range(N):",
"- v, w = list(map(int, input().split()))",
"- items.append([v, w])",
"-dp = [[INF for i in range(W + 1)] for j in range(N + 1)]",
"-for i in range(W + 1):",
"- dp[0][i] = 0",
"-for i in ... | false | 0.077276 | 0.077922 | 0.991709 | [
"s410206116",
"s436958672"
] |
u002459665 | p02614 | python | s954524888 | s075781481 | 74 | 62 | 9,108 | 9,184 | Accepted | Accepted | 16.22 | H, W, K = list(map(int, input().split()))
c = []
for i in range(H):
row = eval(input())
c.append(row)
a1 = []
a2 = []
def f():
pass
at1 = [None] * H
def dfs1(pos: int):
if pos == H:
# print(a)
a1.append(at1.copy())
return
at1[pos] = 0
dfs1(pos + 1)
at1[pos] = 1
dfs1(pos + 1)
at2 = [None] * W
def dfs2(pos: int):
if pos == W:
# print(a)
a2.append(at2.copy())
return
at2[pos] = 0
dfs2(pos + 1)
at2[pos] = 1
dfs2(pos + 1)
dfs1(0)
dfs2(0)
# print(a1)
# print(a2)
ans = 0
for ai in a1:
for aj in a2:
g = []
for i in range(H):
arr = [None] * W
g.append(arr)
for i, aii in enumerate(ai):
if aii == 1:
g[i] = ['r'] * W
for i, aji in enumerate(aj):
if aji == 1:
for j in range(H):
g[j][i] = 'r'
# print(ai, aj, g)
# count
cnt = 0
for i, row in enumerate(g):
for j, col in enumerate(row):
if col is None:
if c[i][j] == '#':
cnt += 1
if cnt == K:
ans += 1
print(ans) | H, W, K = list(map(int, input().split()))
s = []
for i in range(H):
row = eval(input())
s.append(row)
ans = 0
for i in range(1 << H):
for j in range(1 << W):
cnt = 0
for hi in range(H):
for wi in range(W):
if i >> hi & 1:
continue
if j >> wi & 1:
continue
if s[hi][wi] == '#':
cnt += 1
if cnt == K:
ans += 1
print(ans)
| 84 | 22 | 1,319 | 504 | H, W, K = list(map(int, input().split()))
c = []
for i in range(H):
row = eval(input())
c.append(row)
a1 = []
a2 = []
def f():
pass
at1 = [None] * H
def dfs1(pos: int):
if pos == H:
# print(a)
a1.append(at1.copy())
return
at1[pos] = 0
dfs1(pos + 1)
at1[pos] = 1
dfs1(pos + 1)
at2 = [None] * W
def dfs2(pos: int):
if pos == W:
# print(a)
a2.append(at2.copy())
return
at2[pos] = 0
dfs2(pos + 1)
at2[pos] = 1
dfs2(pos + 1)
dfs1(0)
dfs2(0)
# print(a1)
# print(a2)
ans = 0
for ai in a1:
for aj in a2:
g = []
for i in range(H):
arr = [None] * W
g.append(arr)
for i, aii in enumerate(ai):
if aii == 1:
g[i] = ["r"] * W
for i, aji in enumerate(aj):
if aji == 1:
for j in range(H):
g[j][i] = "r"
# print(ai, aj, g)
# count
cnt = 0
for i, row in enumerate(g):
for j, col in enumerate(row):
if col is None:
if c[i][j] == "#":
cnt += 1
if cnt == K:
ans += 1
print(ans)
| H, W, K = list(map(int, input().split()))
s = []
for i in range(H):
row = eval(input())
s.append(row)
ans = 0
for i in range(1 << H):
for j in range(1 << W):
cnt = 0
for hi in range(H):
for wi in range(W):
if i >> hi & 1:
continue
if j >> wi & 1:
continue
if s[hi][wi] == "#":
cnt += 1
if cnt == K:
ans += 1
print(ans)
| false | 73.809524 | [
"-c = []",
"+s = []",
"- c.append(row)",
"-a1 = []",
"-a2 = []",
"-",
"-",
"-def f():",
"- pass",
"-",
"-",
"-at1 = [None] * H",
"-",
"-",
"-def dfs1(pos: int):",
"- if pos == H:",
"- # print(a)",
"- a1.append(at1.copy())",
"- return",
"- at1[po... | false | 0.048614 | 0.162367 | 0.299411 | [
"s954524888",
"s075781481"
] |
u690536347 | p03032 | python | s372097665 | s726705364 | 218 | 48 | 3,064 | 3,064 | Accepted | Accepted | 77.98 | from itertools import accumulate
N, K = list(map(int, input().split()))
*V, = list(map(int, input().split()))
ans = 0
for a in range(N+1):
for b in range(N+1):
if a+b>N:continue
if a and b:
qa, qb = list(accumulate([0]+sorted(V[:a]))), list(accumulate([0]+sorted(V[-b:])))
sa, sb = sum(V[:a]), sum(V[-b:])
for c in range(a+1):
for d in range(b+1):
if a+b+c+d<=K:
ans = max(ans, sa+sb-qa[c]-qb[d])
elif a:
qa = list(accumulate([0]+sorted(V[:a])))
sa = sum(V[:a])
for c in range(a+1):
if a+c<=K:
ans = max(ans, sa-qa[c])
elif b:
qb = list(accumulate([0]+sorted(V[-b:])))
sb = sum(V[-b:])
for d in range(b+1):
if b+d<=K:
ans = max(ans, sb-qb[d])
print(ans) | from itertools import accumulate
N, K = list(map(int, input().split()))
*V, = list(map(int, input().split()))
ans = 0
for a in range(N+1):
for b in range(N+1):
if a+b>N:continue
t = []
if a:
t += V[:a]
if b:
t += V[-b:]
t.sort()
t = [0]+t
v = sum(t)
for c in range(a+b+1):
v -= t[c]
if a+b+c<=K:
ans = max(ans, v)
print(ans) | 30 | 23 | 957 | 477 | from itertools import accumulate
N, K = list(map(int, input().split()))
(*V,) = list(map(int, input().split()))
ans = 0
for a in range(N + 1):
for b in range(N + 1):
if a + b > N:
continue
if a and b:
qa, qb = list(accumulate([0] + sorted(V[:a]))), list(
accumulate([0] + sorted(V[-b:]))
)
sa, sb = sum(V[:a]), sum(V[-b:])
for c in range(a + 1):
for d in range(b + 1):
if a + b + c + d <= K:
ans = max(ans, sa + sb - qa[c] - qb[d])
elif a:
qa = list(accumulate([0] + sorted(V[:a])))
sa = sum(V[:a])
for c in range(a + 1):
if a + c <= K:
ans = max(ans, sa - qa[c])
elif b:
qb = list(accumulate([0] + sorted(V[-b:])))
sb = sum(V[-b:])
for d in range(b + 1):
if b + d <= K:
ans = max(ans, sb - qb[d])
print(ans)
| from itertools import accumulate
N, K = list(map(int, input().split()))
(*V,) = list(map(int, input().split()))
ans = 0
for a in range(N + 1):
for b in range(N + 1):
if a + b > N:
continue
t = []
if a:
t += V[:a]
if b:
t += V[-b:]
t.sort()
t = [0] + t
v = sum(t)
for c in range(a + b + 1):
v -= t[c]
if a + b + c <= K:
ans = max(ans, v)
print(ans)
| false | 23.333333 | [
"- if a and b:",
"- qa, qb = list(accumulate([0] + sorted(V[:a]))), list(",
"- accumulate([0] + sorted(V[-b:]))",
"- )",
"- sa, sb = sum(V[:a]), sum(V[-b:])",
"- for c in range(a + 1):",
"- for d in range(b + 1):",
"- ... | false | 0.086336 | 0.084096 | 1.026634 | [
"s372097665",
"s726705364"
] |
u620868411 | p03081 | python | s033293822 | s748732075 | 1,898 | 533 | 41,396 | 39,348 | Accepted | Accepted | 71.92 | # -*- coding: utf-8 -*-
n,q = list(map(int, input().split()))
s = eval(input())
td = [input().split() for _ in range(q)]
def check(idx, x):
for t,d in td:
if idx==x:
return True
elif idx==n or idx==-1:
return False
if s[idx]==t:
if d=="L":
idx -= 1
else:
idx += 1
return idx==x
ok = -1
ng = n
while abs(ok-ng)>1:
mid = (ok+ng)//2
if check(mid, -1):
ok = mid
else:
ng = mid
res = ok+1
ok = n
ng = -1
while abs(ok-ng)>1:
mid = (ok+ng)//2
if check(mid, n):
ok = mid
else:
ng = mid
res += n-ok
print((n-res))
| # -*- coding: utf-8 -*-
n,q = list(map(int, input().split()))
s = eval(input())
td = [input().split() for _ in range(q)]
l = 0
r = n - 1
for i in range(q-1,-1,-1):
t,d = td[i]
if n>l>=0:
if s[l]==t and d=="L":
l += 1
elif l>0 and s[l-1]==t and d=="R":
l -= 1
if n>r>=0:
if s[r]==t and d=="R":
r -= 1
elif r<n-1 and s[r+1]==t and d=="L":
r += 1
print((n - l - (n-1-r)))
| 40 | 23 | 703 | 473 | # -*- coding: utf-8 -*-
n, q = list(map(int, input().split()))
s = eval(input())
td = [input().split() for _ in range(q)]
def check(idx, x):
for t, d in td:
if idx == x:
return True
elif idx == n or idx == -1:
return False
if s[idx] == t:
if d == "L":
idx -= 1
else:
idx += 1
return idx == x
ok = -1
ng = n
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if check(mid, -1):
ok = mid
else:
ng = mid
res = ok + 1
ok = n
ng = -1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if check(mid, n):
ok = mid
else:
ng = mid
res += n - ok
print((n - res))
| # -*- coding: utf-8 -*-
n, q = list(map(int, input().split()))
s = eval(input())
td = [input().split() for _ in range(q)]
l = 0
r = n - 1
for i in range(q - 1, -1, -1):
t, d = td[i]
if n > l >= 0:
if s[l] == t and d == "L":
l += 1
elif l > 0 and s[l - 1] == t and d == "R":
l -= 1
if n > r >= 0:
if s[r] == t and d == "R":
r -= 1
elif r < n - 1 and s[r + 1] == t and d == "L":
r += 1
print((n - l - (n - 1 - r)))
| false | 42.5 | [
"-",
"-",
"-def check(idx, x):",
"- for t, d in td:",
"- if idx == x:",
"- return True",
"- elif idx == n or idx == -1:",
"- return False",
"- if s[idx] == t:",
"- if d == \"L\":",
"- idx -= 1",
"- else:",
"- ... | false | 0.041516 | 0.036851 | 1.1266 | [
"s033293822",
"s748732075"
] |
u057109575 | p02623 | python | s860625229 | s141453538 | 183 | 145 | 111,000 | 118,212 | Accepted | Accepted | 20.77 | from bisect import bisect_right
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
x = [0] * (N + 1)
for i in range(N):
x[i + 1] = x[i] + A[i]
y = [0] * (M + 1)
for i in range(M):
y[i + 1] = y[i] + B[i]
ans = 0
for i in range(N + 1):
res = K - x[i]
if res > 0:
j = bisect_right(y, res)
j -= 1
elif res == 0:
j = 0
else:
continue
ans = max(ans, i + j)
print(ans)
|
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
x = [0] * (N + 1)
y = [0] * (M + 1)
for i in range(N):
x[i + 1] = x[i] + A[i]
for i in range(M):
y[i + 1] = y[i] + B[i]
j = M
ans = 0
for i in range(N + 1):
if x[i] > K:
continue
while j >= 0 and x[i] + y[j] > K:
j -= 1
ans = max(ans, i + j)
print(ans)
| 27 | 22 | 514 | 422 | from bisect import bisect_right
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
x = [0] * (N + 1)
for i in range(N):
x[i + 1] = x[i] + A[i]
y = [0] * (M + 1)
for i in range(M):
y[i + 1] = y[i] + B[i]
ans = 0
for i in range(N + 1):
res = K - x[i]
if res > 0:
j = bisect_right(y, res)
j -= 1
elif res == 0:
j = 0
else:
continue
ans = max(ans, i + j)
print(ans)
| N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
x = [0] * (N + 1)
y = [0] * (M + 1)
for i in range(N):
x[i + 1] = x[i] + A[i]
for i in range(M):
y[i + 1] = y[i] + B[i]
j = M
ans = 0
for i in range(N + 1):
if x[i] > K:
continue
while j >= 0 and x[i] + y[j] > K:
j -= 1
ans = max(ans, i + j)
print(ans)
| false | 18.518519 | [
"-from bisect import bisect_right",
"-",
"+y = [0] * (M + 1)",
"-y = [0] * (M + 1)",
"+j = M",
"- res = K - x[i]",
"- if res > 0:",
"- j = bisect_right(y, res)",
"+ if x[i] > K:",
"+ continue",
"+ while j >= 0 and x[i] + y[j] > K:",
"- elif res == 0:",
"- ... | false | 0.083972 | 0.065797 | 1.276232 | [
"s860625229",
"s141453538"
] |
u508732591 | p02258 | python | s505155993 | s391364011 | 520 | 450 | 7,672 | 7,692 | Accepted | Accepted | 13.46 | n = int(eval(input()))
minv = int(eval(input()))
maxv = -1000000000
for i in range(1,n):
r = int(eval(input()))
maxv = max(maxv,r-minv)
minv = min(r,minv)
print(maxv) | n = int(eval(input()))
minv = int(eval(input()))
maxv = -1000000000
for i in range(1,n):
r = int(eval(input()))
m = r-minv
if maxv < m < 0:
maxv = m
minv = r
elif maxv < m:
maxv = m
elif m < 0:
minv = r
print(maxv) | 10 | 16 | 165 | 239 | n = int(eval(input()))
minv = int(eval(input()))
maxv = -1000000000
for i in range(1, n):
r = int(eval(input()))
maxv = max(maxv, r - minv)
minv = min(r, minv)
print(maxv)
| n = int(eval(input()))
minv = int(eval(input()))
maxv = -1000000000
for i in range(1, n):
r = int(eval(input()))
m = r - minv
if maxv < m < 0:
maxv = m
minv = r
elif maxv < m:
maxv = m
elif m < 0:
minv = r
print(maxv)
| false | 37.5 | [
"- maxv = max(maxv, r - minv)",
"- minv = min(r, minv)",
"+ m = r - minv",
"+ if maxv < m < 0:",
"+ maxv = m",
"+ minv = r",
"+ elif maxv < m:",
"+ maxv = m",
"+ elif m < 0:",
"+ minv = r"
] | false | 0.037264 | 0.04411 | 0.844809 | [
"s505155993",
"s391364011"
] |
u685263709 | p03457 | python | s566759422 | s566989020 | 463 | 415 | 18,180 | 18,092 | Accepted | Accepted | 10.37 | n = int(eval(input()))
travel_plan = []
for i in range(n):
travel_plan.append(tuple(map(int, input().split())))
travel_plan = [(0, 0, 0)] + travel_plan
for i in range(n):
t1 = travel_plan[i][0]
x1 = travel_plan[i][1]
y1 = travel_plan[i][2]
t2 = travel_plan[i+1][0]
x2 = travel_plan[i+1][1]
y2 = travel_plan[i+1][2]
x = abs(x1 - x2)
y = abs(y1 - y2)
t = t2 - t1
if x + y > t or (x + y) % 2 != t % 2:
print("No")
exit()
print("Yes") | n = int(eval(input()))
travel_plan = [tuple(map(int, input().split())) for i in range(n)]
travel_plan = [(0, 0, 0)] + travel_plan
for i in range(n):
t1 = travel_plan[i][0]
x1 = travel_plan[i][1]
y1 = travel_plan[i][2]
t2 = travel_plan[i+1][0]
x2 = travel_plan[i+1][1]
y2 = travel_plan[i+1][2]
x = abs(x1 - x2)
y = abs(y1 - y2)
t = t2 - t1
if x + y > t or (x + y) % 2 != t % 2:
print("No")
exit()
print("Yes") | 20 | 18 | 504 | 476 | n = int(eval(input()))
travel_plan = []
for i in range(n):
travel_plan.append(tuple(map(int, input().split())))
travel_plan = [(0, 0, 0)] + travel_plan
for i in range(n):
t1 = travel_plan[i][0]
x1 = travel_plan[i][1]
y1 = travel_plan[i][2]
t2 = travel_plan[i + 1][0]
x2 = travel_plan[i + 1][1]
y2 = travel_plan[i + 1][2]
x = abs(x1 - x2)
y = abs(y1 - y2)
t = t2 - t1
if x + y > t or (x + y) % 2 != t % 2:
print("No")
exit()
print("Yes")
| n = int(eval(input()))
travel_plan = [tuple(map(int, input().split())) for i in range(n)]
travel_plan = [(0, 0, 0)] + travel_plan
for i in range(n):
t1 = travel_plan[i][0]
x1 = travel_plan[i][1]
y1 = travel_plan[i][2]
t2 = travel_plan[i + 1][0]
x2 = travel_plan[i + 1][1]
y2 = travel_plan[i + 1][2]
x = abs(x1 - x2)
y = abs(y1 - y2)
t = t2 - t1
if x + y > t or (x + y) % 2 != t % 2:
print("No")
exit()
print("Yes")
| false | 10 | [
"-travel_plan = []",
"-for i in range(n):",
"- travel_plan.append(tuple(map(int, input().split())))",
"+travel_plan = [tuple(map(int, input().split())) for i in range(n)]"
] | false | 0.044217 | 0.043115 | 1.025569 | [
"s566759422",
"s566989020"
] |
u074220993 | p03699 | python | s715872165 | s714393998 | 239 | 127 | 9,200 | 9,204 | Accepted | Accepted | 46.86 | N = int(eval(input()))
maxs = 0
s = []
for i in range(N):
cin = int(eval(input()))
s.append(cin)
maxs = max(maxs, cin)
M = maxs * N
dp = [False] * (M+1)
dp[0] = True
for x in s:
for i in range(M+1):
if M-i < x: continue
if dp[M-i-x]: dp[M-i] = True
for i in range(M+1):
if (M-i)%10 != 0 and dp[M-i]:
print((M-i))
break
else:
print((0)) | with open(0) as f:
N, *S = list(map(int, f.read().split()))
Score = [True if i == 0 else False for i in range(10000)]
for s in S:
for i in reversed(list(range(s, 10000))):
if Score[i-s]:
Score[i] = True
for i in reversed(list(range(10000))):
if Score[i] and i % 10 != 0:
print(i)
break
else:
print((0)) | 23 | 14 | 405 | 349 | N = int(eval(input()))
maxs = 0
s = []
for i in range(N):
cin = int(eval(input()))
s.append(cin)
maxs = max(maxs, cin)
M = maxs * N
dp = [False] * (M + 1)
dp[0] = True
for x in s:
for i in range(M + 1):
if M - i < x:
continue
if dp[M - i - x]:
dp[M - i] = True
for i in range(M + 1):
if (M - i) % 10 != 0 and dp[M - i]:
print((M - i))
break
else:
print((0))
| with open(0) as f:
N, *S = list(map(int, f.read().split()))
Score = [True if i == 0 else False for i in range(10000)]
for s in S:
for i in reversed(list(range(s, 10000))):
if Score[i - s]:
Score[i] = True
for i in reversed(list(range(10000))):
if Score[i] and i % 10 != 0:
print(i)
break
else:
print((0))
| false | 39.130435 | [
"-N = int(eval(input()))",
"-maxs = 0",
"-s = []",
"-for i in range(N):",
"- cin = int(eval(input()))",
"- s.append(cin)",
"- maxs = max(maxs, cin)",
"-M = maxs * N",
"-dp = [False] * (M + 1)",
"-dp[0] = True",
"-for x in s:",
"- for i in range(M + 1):",
"- if M - i < x:",... | false | 0.038701 | 0.102145 | 0.378884 | [
"s715872165",
"s714393998"
] |
u811436126 | p03805 | python | s289547555 | s562390606 | 30 | 27 | 3,064 | 3,064 | Accepted | Accepted | 10 | n, m = list(map(int, input().split()))
graph = [[] for _ in range(n + 1)]
for _ in range(m):
a, b = list(map(int, input().split()))
graph[a].append(b)
graph[b].append(a)
visit = [0] * (n + 1)
def dfs(now, depth):
if visit[now]:
return 0
if depth == n:
return 1
count = 0
visit[now] = 1
if graph[now]:
for i in graph[now]:
count += dfs(i, depth + 1)
visit[now] = 0
return count
ans = dfs(1, 1)
print(ans)
| n, m = list(map(int, input().split()))
graph = [[] for _ in range(n + 1)]
for _ in range(m):
a, b = list(map(int, input().split()))
graph[a].append(b)
graph[b].append(a)
visit = [0] * (n + 1)
ans = 0
def dfs(now, depth):
global ans
if visit[now]:
pass
if depth == n:
ans += 1
visit[now] = 1
if graph[now]:
for i in graph[now]:
if visit[i] == 0:
dfs(i, depth + 1)
visit[now] = 0
dfs(1, 1)
print(ans)
| 28 | 28 | 502 | 508 | n, m = list(map(int, input().split()))
graph = [[] for _ in range(n + 1)]
for _ in range(m):
a, b = list(map(int, input().split()))
graph[a].append(b)
graph[b].append(a)
visit = [0] * (n + 1)
def dfs(now, depth):
if visit[now]:
return 0
if depth == n:
return 1
count = 0
visit[now] = 1
if graph[now]:
for i in graph[now]:
count += dfs(i, depth + 1)
visit[now] = 0
return count
ans = dfs(1, 1)
print(ans)
| n, m = list(map(int, input().split()))
graph = [[] for _ in range(n + 1)]
for _ in range(m):
a, b = list(map(int, input().split()))
graph[a].append(b)
graph[b].append(a)
visit = [0] * (n + 1)
ans = 0
def dfs(now, depth):
global ans
if visit[now]:
pass
if depth == n:
ans += 1
visit[now] = 1
if graph[now]:
for i in graph[now]:
if visit[i] == 0:
dfs(i, depth + 1)
visit[now] = 0
dfs(1, 1)
print(ans)
| false | 0 | [
"+ans = 0",
"+ global ans",
"- return 0",
"+ pass",
"- return 1",
"- count = 0",
"+ ans += 1",
"- count += dfs(i, depth + 1)",
"+ if visit[i] == 0:",
"+ dfs(i, depth + 1)",
"- return count",
"-ans = dfs(1, 1)",
"+dfs(1... | false | 0.041201 | 0.04077 | 1.01059 | [
"s289547555",
"s562390606"
] |
u681323954 | p02554 | python | s416476317 | s418456794 | 483 | 391 | 9,188 | 10,660 | Accepted | Accepted | 19.05 | """
int(input())
map(int, input().split())
list(map(int, input().split()))
input()
input().split()
"""
n = int(eval(input()))
mod = 1000000007
tmp = 1
diff = 1
eight = 1
for i in range(n):
tmp *= 10
tmp %= mod
diff *= 9
diff %= mod
eight *= 8
eight %= mod
ans = tmp - 2*diff + eight
ans %= mod
print(ans)
# tmp = (10**n)%mod
# diff = 2*(9**n)%mod
# eight = (8**n)%mod
# ans = tmp - diff + eight
# print(ans) | """
int(input())
map(int, input().split())
list(map(int, input().split()))
input()
input().split()
"""
n = int(eval(input()))
mod = 1000000007
tmp = (10**n)%mod
diff = 2*(9**n)%mod
eight = (8**n)%mod
ans = tmp - diff + eight
ans%=mod
print(ans)
| 34 | 18 | 465 | 259 | """
int(input())
map(int, input().split())
list(map(int, input().split()))
input()
input().split()
"""
n = int(eval(input()))
mod = 1000000007
tmp = 1
diff = 1
eight = 1
for i in range(n):
tmp *= 10
tmp %= mod
diff *= 9
diff %= mod
eight *= 8
eight %= mod
ans = tmp - 2 * diff + eight
ans %= mod
print(ans)
# tmp = (10**n)%mod
# diff = 2*(9**n)%mod
# eight = (8**n)%mod
# ans = tmp - diff + eight
# print(ans)
| """
int(input())
map(int, input().split())
list(map(int, input().split()))
input()
input().split()
"""
n = int(eval(input()))
mod = 1000000007
tmp = (10**n) % mod
diff = 2 * (9**n) % mod
eight = (8**n) % mod
ans = tmp - diff + eight
ans %= mod
print(ans)
| false | 47.058824 | [
"-tmp = 1",
"-diff = 1",
"-eight = 1",
"-for i in range(n):",
"- tmp *= 10",
"- tmp %= mod",
"- diff *= 9",
"- diff %= mod",
"- eight *= 8",
"- eight %= mod",
"-ans = tmp - 2 * diff + eight",
"+tmp = (10**n) % mod",
"+diff = 2 * (9**n) % mod",
"+eight = (8**n) % mod",
"... | false | 0.354592 | 0.353431 | 1.003286 | [
"s416476317",
"s418456794"
] |
u223646582 | p03062 | python | s852626855 | s904969405 | 226 | 94 | 64,880 | 14,412 | Accepted | Accepted | 58.41 | N = int(eval(input()))
A = [int(i) for i in input().split()]
cnt = 0
s = 0
minabs = 10**11
for a in A:
if a <= -1:
cnt += 1
s += abs(a)
minabs = min(minabs, abs(a))
if cnt % 2 == 0:
print(s)
else:
print((s-minabs*2))
| N = int(eval(input()))
A = [int(i) for i in input().split()]
m = 10**20
c = 0
for a in A:
if a < 0:
c += 1
m = min(m, abs(a))
if c % 2 == 0:
ans = sum([abs(a) for a in A])
else:
ans = sum([abs(a) for a in A]) - m*2
print(ans)
| 16 | 16 | 254 | 262 | N = int(eval(input()))
A = [int(i) for i in input().split()]
cnt = 0
s = 0
minabs = 10**11
for a in A:
if a <= -1:
cnt += 1
s += abs(a)
minabs = min(minabs, abs(a))
if cnt % 2 == 0:
print(s)
else:
print((s - minabs * 2))
| N = int(eval(input()))
A = [int(i) for i in input().split()]
m = 10**20
c = 0
for a in A:
if a < 0:
c += 1
m = min(m, abs(a))
if c % 2 == 0:
ans = sum([abs(a) for a in A])
else:
ans = sum([abs(a) for a in A]) - m * 2
print(ans)
| false | 0 | [
"-cnt = 0",
"-s = 0",
"-minabs = 10**11",
"+m = 10**20",
"+c = 0",
"- if a <= -1:",
"- cnt += 1",
"- s += abs(a)",
"- minabs = min(minabs, abs(a))",
"-if cnt % 2 == 0:",
"- print(s)",
"+ if a < 0:",
"+ c += 1",
"+ m = min(m, abs(a))",
"+if c % 2 == 0:",
... | false | 0.034849 | 0.033465 | 1.041367 | [
"s852626855",
"s904969405"
] |
u940102677 | p03127 | python | s550103821 | s953856488 | 114 | 90 | 16,240 | 16,240 | Accepted | Accepted | 21.05 | import fractions
n = int(eval(input()))
a = list(map(int,input().split()))
d = a[0]
for t in a:
d = fractions.gcd(d, t)
print(d) | import fractions
n = int(eval(input()))
a = list(map(int,input().split()))
d = min(a)
for t in a:
d = fractions.gcd(d, t)
print(d) | 7 | 7 | 130 | 132 | import fractions
n = int(eval(input()))
a = list(map(int, input().split()))
d = a[0]
for t in a:
d = fractions.gcd(d, t)
print(d)
| import fractions
n = int(eval(input()))
a = list(map(int, input().split()))
d = min(a)
for t in a:
d = fractions.gcd(d, t)
print(d)
| false | 0 | [
"-d = a[0]",
"+d = min(a)"
] | false | 0.049524 | 0.04856 | 1.019857 | [
"s550103821",
"s953856488"
] |
u250944591 | p03737 | python | s674005340 | s117745989 | 27 | 24 | 9,020 | 9,092 | Accepted | Accepted | 11.11 | a,b,c=input().split()
print((a[0].upper()+b[0].upper()+c[0].upper())) | a,b,c=input().split()
print(((a[0]+b[0]+c[0]).upper())) | 2 | 2 | 68 | 54 | a, b, c = input().split()
print((a[0].upper() + b[0].upper() + c[0].upper()))
| a, b, c = input().split()
print(((a[0] + b[0] + c[0]).upper()))
| false | 0 | [
"-print((a[0].upper() + b[0].upper() + c[0].upper()))",
"+print(((a[0] + b[0] + c[0]).upper()))"
] | false | 0.044409 | 0.047271 | 0.939458 | [
"s674005340",
"s117745989"
] |
u226108478 | p03326 | python | s450409642 | s296186814 | 30 | 27 | 3,444 | 3,316 | Accepted | Accepted | 10 | # -*- coding: utf-8 -*-
# AtCoder Beginner Contest
if __name__ == '__main__':
from itertools import product
from heapq import nlargest
n, m = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for i in range(n)]
ans = 0
# See:
# https://beta.atcoder.jp/contests/abc100/submissions/2691346
for a, b, c in product((-1, 1), repeat=3):
summed_xyz = [0 for _ in range(n)]
i = 0
for x, y, z in xyz:
summed_xyz[i] = (x * a) + (y * b) + (z * c)
i += 1
ans = max(ans, sum(nlargest(m, summed_xyz)))
print(ans)
| # -*- coding: utf-8 -*-
def main():
from itertools import product
n, m = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for op1, op2, op3 in list(product([1, -1], repeat=3)):
tmp = [[0, 0, 0]] * n
for index, value in enumerate(xyz):
tmp[index] = sum([op1 * value[0], op2 * value[1], op3 * value[2]])
camdidates = sorted(tmp, reverse=True)
ans = max(ans, sum(camdidates[:m]))
print(ans)
if __name__ == '__main__':
main()
| 25 | 24 | 643 | 569 | # -*- coding: utf-8 -*-
# AtCoder Beginner Contest
if __name__ == "__main__":
from itertools import product
from heapq import nlargest
n, m = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for i in range(n)]
ans = 0
# See:
# https://beta.atcoder.jp/contests/abc100/submissions/2691346
for a, b, c in product((-1, 1), repeat=3):
summed_xyz = [0 for _ in range(n)]
i = 0
for x, y, z in xyz:
summed_xyz[i] = (x * a) + (y * b) + (z * c)
i += 1
ans = max(ans, sum(nlargest(m, summed_xyz)))
print(ans)
| # -*- coding: utf-8 -*-
def main():
from itertools import product
n, m = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for op1, op2, op3 in list(product([1, -1], repeat=3)):
tmp = [[0, 0, 0]] * n
for index, value in enumerate(xyz):
tmp[index] = sum([op1 * value[0], op2 * value[1], op3 * value[2]])
camdidates = sorted(tmp, reverse=True)
ans = max(ans, sum(camdidates[:m]))
print(ans)
if __name__ == "__main__":
main()
| false | 4 | [
"-# AtCoder Beginner Contest",
"-if __name__ == \"__main__\":",
"+def main():",
"- from heapq import nlargest",
"- xyz = [list(map(int, input().split())) for i in range(n)]",
"+ xyz = [list(map(int, input().split())) for _ in range(n)]",
"- # See:",
"- # https://beta.atcoder.jp/contests... | false | 0.050967 | 0.050381 | 1.011632 | [
"s450409642",
"s296186814"
] |
u275392848 | p02756 | python | s703335909 | s392500755 | 1,862 | 1,426 | 4,412 | 4,400 | Accepted | Accepted | 23.42 | s=eval(input())
count=0
s1=str()
s2=str()
for _ in range(int(eval(input()))):
l=list(map(str,input().split()))
if l[0]=='1':
count+=1
elif count%2==0:
if l[1]=='1':
s1=l[2]+s1
else:
s2=s2+l[2]
else:
if l[1]=='2':
s1=l[2]+s1
else:
s2=s2+l[2]
s=s1+s+s2
if count%2!=0:
s=s[::-1]
print(s) | import sys
input = lambda: sys.stdin.readline().rstrip()
s=eval(input())
count=0
s1=str()
s2=str()
for _ in range(int(eval(input()))):
l=list(map(str,input().split()))
if l[0]=='1':
count+=1
elif count%2==0:
if l[1]=='1':
s1=l[2]+s1
else:
s2=s2+l[2]
else:
if l[1]=='2':
s1=l[2]+s1
else:
s2=s2+l[2]
s=s1+s+s2
if count%2!=0:
s=s[::-1]
print(s) | 23 | 25 | 351 | 411 | s = eval(input())
count = 0
s1 = str()
s2 = str()
for _ in range(int(eval(input()))):
l = list(map(str, input().split()))
if l[0] == "1":
count += 1
elif count % 2 == 0:
if l[1] == "1":
s1 = l[2] + s1
else:
s2 = s2 + l[2]
else:
if l[1] == "2":
s1 = l[2] + s1
else:
s2 = s2 + l[2]
s = s1 + s + s2
if count % 2 != 0:
s = s[::-1]
print(s)
| import sys
input = lambda: sys.stdin.readline().rstrip()
s = eval(input())
count = 0
s1 = str()
s2 = str()
for _ in range(int(eval(input()))):
l = list(map(str, input().split()))
if l[0] == "1":
count += 1
elif count % 2 == 0:
if l[1] == "1":
s1 = l[2] + s1
else:
s2 = s2 + l[2]
else:
if l[1] == "2":
s1 = l[2] + s1
else:
s2 = s2 + l[2]
s = s1 + s + s2
if count % 2 != 0:
s = s[::-1]
print(s)
| false | 8 | [
"+import sys",
"+",
"+input = lambda: sys.stdin.readline().rstrip()"
] | false | 0.102509 | 0.070396 | 1.456176 | [
"s703335909",
"s392500755"
] |
u622570247 | p02727 | python | s193342863 | s373314390 | 674 | 244 | 43,296 | 22,508 | Accepted | Accepted | 63.8 | import heapq
x, y, a, b, c = list(map(int, input().split()))
pp = list([(-int(x), 1) for x in input().split()])
qq = list([(-int(x), 2) for x in input().split()])
rr = list([(-int(x), 3) for x in input().split()])
xx = pp + qq + rr
heapq.heapify(xx)
t = x + y
ans = 0
for _ in range(t):
while len(xx) > 0:
v = heapq.heappop(xx)
if v[1] == 1 and x <= 0:
continue
if v[1] == 2 and y <= 0:
continue
break
if v[1] == 1:
x -= 1
if v[1] == 2:
y -= 1
ans += v[0]
print((-ans))
| x, y, a, b, c = list(map(int, input().split()))
pp = list(sorted(map(int, input().split()), reverse=True))[:x]
qq = list(sorted(map(int, input().split()), reverse=True))[:y]
rr = list(map(int, input().split()))
xx = list(sorted(pp + qq + rr, reverse=True))[:x+y]
print((sum(xx)))
| 27 | 7 | 595 | 279 | import heapq
x, y, a, b, c = list(map(int, input().split()))
pp = list([(-int(x), 1) for x in input().split()])
qq = list([(-int(x), 2) for x in input().split()])
rr = list([(-int(x), 3) for x in input().split()])
xx = pp + qq + rr
heapq.heapify(xx)
t = x + y
ans = 0
for _ in range(t):
while len(xx) > 0:
v = heapq.heappop(xx)
if v[1] == 1 and x <= 0:
continue
if v[1] == 2 and y <= 0:
continue
break
if v[1] == 1:
x -= 1
if v[1] == 2:
y -= 1
ans += v[0]
print((-ans))
| x, y, a, b, c = list(map(int, input().split()))
pp = list(sorted(map(int, input().split()), reverse=True))[:x]
qq = list(sorted(map(int, input().split()), reverse=True))[:y]
rr = list(map(int, input().split()))
xx = list(sorted(pp + qq + rr, reverse=True))[: x + y]
print((sum(xx)))
| false | 74.074074 | [
"-import heapq",
"-",
"-pp = list([(-int(x), 1) for x in input().split()])",
"-qq = list([(-int(x), 2) for x in input().split()])",
"-rr = list([(-int(x), 3) for x in input().split()])",
"-xx = pp + qq + rr",
"-heapq.heapify(xx)",
"-t = x + y",
"-ans = 0",
"-for _ in range(t):",
"- while len(... | false | 0.071067 | 0.044427 | 1.599632 | [
"s193342863",
"s373314390"
] |
u620084012 | p03860 | python | s136974041 | s421167861 | 193 | 175 | 38,256 | 38,256 | Accepted | Accepted | 9.33 | S = input().split()
print(("A"+S[1][0]+"C"))
| a, b, c = input().split()
print((a[0]+b[0]+c[0]))
| 2 | 2 | 44 | 49 | S = input().split()
print(("A" + S[1][0] + "C"))
| a, b, c = input().split()
print((a[0] + b[0] + c[0]))
| false | 0 | [
"-S = input().split()",
"-print((\"A\" + S[1][0] + \"C\"))",
"+a, b, c = input().split()",
"+print((a[0] + b[0] + c[0]))"
] | false | 0.048733 | 0.047836 | 1.018757 | [
"s136974041",
"s421167861"
] |
u860002137 | p03774 | python | s049425673 | s604763264 | 173 | 117 | 12,868 | 27,168 | Accepted | Accepted | 32.37 | import numpy as np
N, M = list(map(int, input().split()))
ab = []
for i in range(N):
tmp = list(map(int, input().split()))
ab.append(tmp)
ab = np.array(ab)
dist = np.full([N, M], np.inf)
for m in range(M):
tmp = np.array(list(map(int, input().split())))
for n in range(N):
dist[n, m] = np.abs(ab[n] - tmp).sum()
dist = dist.astype("int")
for d in dist:
print((d.argmin()+1)) | import numpy as np
n, m = map(int, input().split())
ab = []
for _ in range(n):
a, b = map(int, input().split())
ab.append((a, b))
result = np.zeros([m, n], dtype=np.int64)
cd = []
for i in range(m):
c, d = map(int, input().split())
for j, (a, b) in enumerate(ab):
result[i, j] = abs(a - c) + abs(b - d)
print(*result.argmin(axis=0) + 1, sep="\n")
| 21 | 18 | 420 | 392 | import numpy as np
N, M = list(map(int, input().split()))
ab = []
for i in range(N):
tmp = list(map(int, input().split()))
ab.append(tmp)
ab = np.array(ab)
dist = np.full([N, M], np.inf)
for m in range(M):
tmp = np.array(list(map(int, input().split())))
for n in range(N):
dist[n, m] = np.abs(ab[n] - tmp).sum()
dist = dist.astype("int")
for d in dist:
print((d.argmin() + 1))
| import numpy as np
n, m = map(int, input().split())
ab = []
for _ in range(n):
a, b = map(int, input().split())
ab.append((a, b))
result = np.zeros([m, n], dtype=np.int64)
cd = []
for i in range(m):
c, d = map(int, input().split())
for j, (a, b) in enumerate(ab):
result[i, j] = abs(a - c) + abs(b - d)
print(*result.argmin(axis=0) + 1, sep="\n")
| false | 14.285714 | [
"-N, M = list(map(int, input().split()))",
"+n, m = map(int, input().split())",
"-for i in range(N):",
"- tmp = list(map(int, input().split()))",
"- ab.append(tmp)",
"-ab = np.array(ab)",
"-dist = np.full([N, M], np.inf)",
"-for m in range(M):",
"- tmp = np.array(list(map(int, input().split... | false | 0.473463 | 0.31322 | 1.511596 | [
"s049425673",
"s604763264"
] |
u627691992 | p04044 | python | s457733511 | s293233663 | 27 | 24 | 9,160 | 9,096 | Accepted | Accepted | 11.11 | N, L = map(int, input().split())
s = [input() for i in range(N)]
s.sort()
print(*s, sep="")
| N, L = map(int, input().split())
s = sorted([input() for i in range(N)])
print(*s, sep="")
| 4 | 3 | 95 | 93 | N, L = map(int, input().split())
s = [input() for i in range(N)]
s.sort()
print(*s, sep="")
| N, L = map(int, input().split())
s = sorted([input() for i in range(N)])
print(*s, sep="")
| false | 25 | [
"-s = [input() for i in range(N)]",
"-s.sort()",
"+s = sorted([input() for i in range(N)])"
] | false | 0.079189 | 0.130561 | 0.606532 | [
"s457733511",
"s293233663"
] |
u314050667 | p03095 | python | s791395795 | s942004478 | 59 | 39 | 3,956 | 3,188 | Accepted | Accepted | 33.9 | mod = 10**9 + 7
N = int(eval(input()))
S = list(eval(input()))
al = [chr(ord("a") + i ) for i in range(26)]
cntAl = [ S.count(chr(ord("a") + i )) for i in range(26)]
ans = 1
for a in cntAl:
if a != 0:ans *= (a+1)%mod
print(((ans-1)%mod)) | n = int(eval(input()))
s = eval(input())
mod = 10**9 + 7
car = [0] * 26
for i in range(n):
car[ord(s[i])-97] += 1
ans = 1
for i in range(26):
if car[i] == 0:
continue
else:
ans *= (car[i]+1)
ans %= mod
print((ans - 1)) | 9 | 17 | 235 | 232 | mod = 10**9 + 7
N = int(eval(input()))
S = list(eval(input()))
al = [chr(ord("a") + i) for i in range(26)]
cntAl = [S.count(chr(ord("a") + i)) for i in range(26)]
ans = 1
for a in cntAl:
if a != 0:
ans *= (a + 1) % mod
print(((ans - 1) % mod))
| n = int(eval(input()))
s = eval(input())
mod = 10**9 + 7
car = [0] * 26
for i in range(n):
car[ord(s[i]) - 97] += 1
ans = 1
for i in range(26):
if car[i] == 0:
continue
else:
ans *= car[i] + 1
ans %= mod
print((ans - 1))
| false | 47.058824 | [
"+n = int(eval(input()))",
"+s = eval(input())",
"-N = int(eval(input()))",
"-S = list(eval(input()))",
"-al = [chr(ord(\"a\") + i) for i in range(26)]",
"-cntAl = [S.count(chr(ord(\"a\") + i)) for i in range(26)]",
"+car = [0] * 26",
"+for i in range(n):",
"+ car[ord(s[i]) - 97] += 1",
"-for a... | false | 0.047262 | 0.048141 | 0.98175 | [
"s791395795",
"s942004478"
] |
u050708958 | p02934 | python | s251359147 | s325024254 | 22 | 17 | 3,572 | 2,940 | Accepted | Accepted | 22.73 | from functools import reduce
eval(input())
a = [int(i) for i in input().split()]
print((1 / reduce(lambda x, y: x + 1/y, [0] + a)))
| eval(input())
print((1 / sum(1/int(x) for x in input().split())))
| 4 | 2 | 127 | 59 | from functools import reduce
eval(input())
a = [int(i) for i in input().split()]
print((1 / reduce(lambda x, y: x + 1 / y, [0] + a)))
| eval(input())
print((1 / sum(1 / int(x) for x in input().split())))
| false | 50 | [
"-from functools import reduce",
"-",
"-a = [int(i) for i in input().split()]",
"-print((1 / reduce(lambda x, y: x + 1 / y, [0] + a)))",
"+print((1 / sum(1 / int(x) for x in input().split())))"
] | false | 0.039906 | 0.037258 | 1.071053 | [
"s251359147",
"s325024254"
] |
u909716307 | p03137 | python | s234345096 | s985991256 | 123 | 96 | 13,960 | 13,960 | Accepted | Accepted | 21.95 | N,M=list(map(int,input().split()))
X=list(map(int,input().split()))
if(N>=M):
print((0))
else:
X.sort()
b=[]
for i in range(M-1):
b.append(X[i+1]-X[i])
b.sort()
for _ in range(N-1):
b.pop()
print((sum(b)))
| n,m=list(map(int,input().split()))
l=sorted(list(map(int,input().split())))
if n>=m:
print((0))
exit()
s=l[-1]-l[0]
l=sorted([a-b for a,b in zip(l[1:],l)], reverse=True)
print((s-sum(l[:n-1])))
| 13 | 8 | 252 | 199 | N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
if N >= M:
print((0))
else:
X.sort()
b = []
for i in range(M - 1):
b.append(X[i + 1] - X[i])
b.sort()
for _ in range(N - 1):
b.pop()
print((sum(b)))
| n, m = list(map(int, input().split()))
l = sorted(list(map(int, input().split())))
if n >= m:
print((0))
exit()
s = l[-1] - l[0]
l = sorted([a - b for a, b in zip(l[1:], l)], reverse=True)
print((s - sum(l[: n - 1])))
| false | 38.461538 | [
"-N, M = list(map(int, input().split()))",
"-X = list(map(int, input().split()))",
"-if N >= M:",
"+n, m = list(map(int, input().split()))",
"+l = sorted(list(map(int, input().split())))",
"+if n >= m:",
"-else:",
"- X.sort()",
"- b = []",
"- for i in range(M - 1):",
"- b.append(... | false | 0.054948 | 0.036531 | 1.504143 | [
"s234345096",
"s985991256"
] |
u261103969 | p02553 | python | s281281756 | s705072928 | 95 | 29 | 61,708 | 9,108 | Accepted | Accepted | 69.47 | import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
a, b, c, d = list(map(int, readline().split()))
ans = -INF
for x in (a, b):
for y in (c, d):
ans = max(ans, x * y)
print(ans)
if __name__ == '__main__':
main()
| a, b, c, d = list(map(int, input().split()))
ans = -float("INF") # 答えがマイナスになることがあるので、負の無限大を初期値にしておきます
for x in (a, b):
for y in (c, d):
ans = max(ans, x * y)
print(ans) | 22 | 9 | 344 | 186 | import sys
readline = sys.stdin.readline
MOD = 10**9 + 7
INF = float("INF")
sys.setrecursionlimit(10**5)
def main():
a, b, c, d = list(map(int, readline().split()))
ans = -INF
for x in (a, b):
for y in (c, d):
ans = max(ans, x * y)
print(ans)
if __name__ == "__main__":
main()
| a, b, c, d = list(map(int, input().split()))
ans = -float("INF") # 答えがマイナスになることがあるので、負の無限大を初期値にしておきます
for x in (a, b):
for y in (c, d):
ans = max(ans, x * y)
print(ans)
| false | 59.090909 | [
"-import sys",
"-",
"-readline = sys.stdin.readline",
"-MOD = 10**9 + 7",
"-INF = float(\"INF\")",
"-sys.setrecursionlimit(10**5)",
"-",
"-",
"-def main():",
"- a, b, c, d = list(map(int, readline().split()))",
"- ans = -INF",
"- for x in (a, b):",
"- for y in (c, d):",
"- ... | false | 0.056069 | 0.053942 | 1.039434 | [
"s281281756",
"s705072928"
] |
u867826040 | p02935 | python | s620924412 | s007254932 | 31 | 25 | 9,396 | 9,092 | Accepted | Accepted | 19.35 | from collections import deque
n = int(eval(input()))
v = sorted(map(float, input().split()))
ans = 0
v = deque(v)
while(len(v) > 1):
v.appendleft(((v.popleft() + v.popleft()) / 2))
print((v[0])) | n = int(eval(input()))
v = sorted(map(float, input().split()))
ans = v[0]
for i in range(n - 1):
ans = (ans + v[i + 1]) / 2
print(ans)
| 8 | 6 | 197 | 138 | from collections import deque
n = int(eval(input()))
v = sorted(map(float, input().split()))
ans = 0
v = deque(v)
while len(v) > 1:
v.appendleft(((v.popleft() + v.popleft()) / 2))
print((v[0]))
| n = int(eval(input()))
v = sorted(map(float, input().split()))
ans = v[0]
for i in range(n - 1):
ans = (ans + v[i + 1]) / 2
print(ans)
| false | 25 | [
"-from collections import deque",
"-",
"-ans = 0",
"-v = deque(v)",
"-while len(v) > 1:",
"- v.appendleft(((v.popleft() + v.popleft()) / 2))",
"-print((v[0]))",
"+ans = v[0]",
"+for i in range(n - 1):",
"+ ans = (ans + v[i + 1]) / 2",
"+print(ans)"
] | false | 0.039491 | 0.039967 | 0.98809 | [
"s620924412",
"s007254932"
] |
u499381410 | p03372 | python | s047873555 | s537817399 | 385 | 209 | 89,948 | 109,056 | Accepted | Accepted | 45.71 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, c = LI()
clock_pos = []
value = []
for pos, v in LIR(n):
clock_pos += [pos]
value += [v]
rounding_max = [0]
counter_rounding_max = [0]
return_max = [0]
counter_return_max = [0]
ret = 0
counter_ret = 0
for i in range(n):
ret += value[i]
counter_ret += value[-i - 1]
rounding_max += [max(rounding_max[-1], ret - clock_pos[i])]
counter_rounding_max += [max(counter_rounding_max[-1], counter_ret - (c - clock_pos[-i - 1]))]
return_max += [max(return_max[-1], ret - clock_pos[i] * 2)]
counter_return_max += [max(counter_return_max[-1], counter_ret - (c - clock_pos[-i - 1]) * 2)]
ans = max(rounding_max[-1], counter_rounding_max[-1])
for j in range(1, n + 1):
ans = max(ans, return_max[j] + counter_rounding_max[n - j], counter_return_max[j] + rounding_max[n - j])
print(ans) | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, c = LI()
clock_pos = []
value = []
for pos, v in LIR(n):
clock_pos += [pos]
value += [v]
r1 = 0
r2 = 0
A1 = [0]
A2 = [0]
for i in range(n):
r1 += value[i]
r2 += value[-i - 1]
A1 += [max(A1[i], r1 - clock_pos[i])]
A2 += [max(A2[i], r2 - (c - clock_pos[-i-1]))]
ans = 0
for j in range(n-1):
ans = max(ans, A1[j+1] + A2[n - j - 1] - clock_pos[j], A2[j+1] + A1[n - j - 1] - (c - clock_pos[-j-1]))
print((max(ans, A1[-1], A2[-1]))) | 63 | 55 | 1,952 | 1,572 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(2147483647)
INF = 10**13
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def I():
return int(sys.stdin.buffer.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, c = LI()
clock_pos = []
value = []
for pos, v in LIR(n):
clock_pos += [pos]
value += [v]
rounding_max = [0]
counter_rounding_max = [0]
return_max = [0]
counter_return_max = [0]
ret = 0
counter_ret = 0
for i in range(n):
ret += value[i]
counter_ret += value[-i - 1]
rounding_max += [max(rounding_max[-1], ret - clock_pos[i])]
counter_rounding_max += [
max(counter_rounding_max[-1], counter_ret - (c - clock_pos[-i - 1]))
]
return_max += [max(return_max[-1], ret - clock_pos[i] * 2)]
counter_return_max += [
max(counter_return_max[-1], counter_ret - (c - clock_pos[-i - 1]) * 2)
]
ans = max(rounding_max[-1], counter_rounding_max[-1])
for j in range(1, n + 1):
ans = max(
ans,
return_max[j] + counter_rounding_max[n - j],
counter_return_max[j] + rounding_max[n - j],
)
print(ans)
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(2147483647)
INF = 10**13
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, c = LI()
clock_pos = []
value = []
for pos, v in LIR(n):
clock_pos += [pos]
value += [v]
r1 = 0
r2 = 0
A1 = [0]
A2 = [0]
for i in range(n):
r1 += value[i]
r2 += value[-i - 1]
A1 += [max(A1[i], r1 - clock_pos[i])]
A2 += [max(A2[i], r2 - (c - clock_pos[-i - 1]))]
ans = 0
for j in range(n - 1):
ans = max(
ans,
A1[j + 1] + A2[n - j - 1] - clock_pos[j],
A2[j + 1] + A1[n - j - 1] - (c - clock_pos[-j - 1]),
)
print((max(ans, A1[-1], A2[-1])))
| false | 12.698413 | [
"- return list(map(int, sys.stdin.buffer.readline().split()))",
"+ return list(map(int, sys.stdin.readline().split()))",
"- return int(sys.stdin.buffer.readline())",
"+ return int(sys.stdin.readline())",
"-rounding_max = [0]",
"-counter_rounding_max = [0]",
"-return_max = [0]",
"-counter_r... | false | 0.058845 | 0.038063 | 1.545991 | [
"s047873555",
"s537817399"
] |
u241159583 | p03730 | python | s724184122 | s587826110 | 32 | 29 | 9,088 | 9,036 | Accepted | Accepted | 9.38 | a,b,c = list(map(int, input().split()))
ans = "NO"
for x in range(b+1):
if (a*x) % b == c:
ans = "YES"
break
print(ans) | a,b,c = list(map(int, input().split()))
ans = "NO"
for i in range(1, b+1):
if (a*i) % b == c:
ans = "YES"
break
print(ans) | 7 | 7 | 139 | 142 | a, b, c = list(map(int, input().split()))
ans = "NO"
for x in range(b + 1):
if (a * x) % b == c:
ans = "YES"
break
print(ans)
| a, b, c = list(map(int, input().split()))
ans = "NO"
for i in range(1, b + 1):
if (a * i) % b == c:
ans = "YES"
break
print(ans)
| false | 0 | [
"-for x in range(b + 1):",
"- if (a * x) % b == c:",
"+for i in range(1, b + 1):",
"+ if (a * i) % b == c:"
] | false | 0.045711 | 0.036013 | 1.269297 | [
"s724184122",
"s587826110"
] |
u525065967 | p03574 | python | s601042534 | s615827835 | 38 | 31 | 9,264 | 9,252 | Accepted | Accepted | 18.42 | h, w = map(int, input().split())
S = [input() for _ in range(h)]
ans = [[-1]*w for _ in range(h)]
dy = [-1, 1, 0, 0, -1, 1, -1, 1]
dx = [ 0, 0,-1, 1, -1, 1, 1,-1]
for i in range(h):
for j in range(w):
if S[i][j] == '#': continue
ans[i][j] = 0
for k in range(8):
y = i + dy[k]
x = j + dx[k]
if y<0 or h<=y: continue
if x<0 or w<=x: continue
if S[y][x] == '#':
ans[i][j] += 1
for i in range(h):
for j in range(w):
if ans[i][j] == -1:
print('#',end='')
else:
print(ans[i][j],end='')
print('')
# print(h,w)
# print(*S,sep='\n')
# print(*ans,sep='\n')
| dy = [-1, 1, 0, 0, -1, 1, -1, 1]
dx = [ 0, 0,-1, 1, -1, 1, 1,-1]
h, w = map(int, input().split())
S = [input() for _ in range(h)]
ans = [[-1]*w for _ in range(h)]
for i in range(h):
for j in range(w):
if S[i][j] == '#': continue
ans[i][j] = 0
for k in range(8):
y = i + dy[k]; x = j + dx[k]
if y<0 or h<=y or x<0 or w<=x: continue
if S[y][x] == '#': ans[i][j] += 1
for i in range(h):
for j in range(w): print('#' if ans[i][j] < 0 else ans[i][j], end='')
print('')
| 31 | 16 | 735 | 552 | h, w = map(int, input().split())
S = [input() for _ in range(h)]
ans = [[-1] * w for _ in range(h)]
dy = [-1, 1, 0, 0, -1, 1, -1, 1]
dx = [0, 0, -1, 1, -1, 1, 1, -1]
for i in range(h):
for j in range(w):
if S[i][j] == "#":
continue
ans[i][j] = 0
for k in range(8):
y = i + dy[k]
x = j + dx[k]
if y < 0 or h <= y:
continue
if x < 0 or w <= x:
continue
if S[y][x] == "#":
ans[i][j] += 1
for i in range(h):
for j in range(w):
if ans[i][j] == -1:
print("#", end="")
else:
print(ans[i][j], end="")
print("")
# print(h,w)
# print(*S,sep='\n')
# print(*ans,sep='\n')
| dy = [-1, 1, 0, 0, -1, 1, -1, 1]
dx = [0, 0, -1, 1, -1, 1, 1, -1]
h, w = map(int, input().split())
S = [input() for _ in range(h)]
ans = [[-1] * w for _ in range(h)]
for i in range(h):
for j in range(w):
if S[i][j] == "#":
continue
ans[i][j] = 0
for k in range(8):
y = i + dy[k]
x = j + dx[k]
if y < 0 or h <= y or x < 0 or w <= x:
continue
if S[y][x] == "#":
ans[i][j] += 1
for i in range(h):
for j in range(w):
print("#" if ans[i][j] < 0 else ans[i][j], end="")
print("")
| false | 48.387097 | [
"+dy = [-1, 1, 0, 0, -1, 1, -1, 1]",
"+dx = [0, 0, -1, 1, -1, 1, 1, -1]",
"-dy = [-1, 1, 0, 0, -1, 1, -1, 1]",
"-dx = [0, 0, -1, 1, -1, 1, 1, -1]",
"- if y < 0 or h <= y:",
"- continue",
"- if x < 0 or w <= x:",
"+ if y < 0 or h <= y or x < 0 or w <= x:"... | false | 0.042556 | 0.043342 | 0.98188 | [
"s601042534",
"s615827835"
] |
u261103969 | p02584 | python | s699373336 | s744713449 | 32 | 28 | 9,140 | 9,044 | Accepted | Accepted | 12.5 | x, k, d = list(map(int, input().split()))
cur = abs(x) # 座標を正にしてしまいます
rem = k # 残りの移動回数です
cnt = min(cur // d, k) # 0に向かって移動する回数です
cur -= d * cnt
rem -= cnt
# 残り回数が0回の場合分けをする必要はないのですが、一応
if rem > 0:
if rem % 2 == 1:
cur = abs(cur - d)
print(cur) | x, k, d = list(map(int, input().split()))
cur = abs(x) # 座標を正にしてしまいます
rem = k # 残りの移動回数です
cnt = min(cur // d, k) # 0に向かって移動する回数です
cur -= d * cnt
rem -= cnt
# 0 % 2 = 0なので、残り回数の場合分けをする必要はないのですが、一応
if rem > 0:
if rem % 2 == 1:
cur = cur - d
ans = abs(cur)
print(ans) | 15 | 16 | 271 | 292 | x, k, d = list(map(int, input().split()))
cur = abs(x) # 座標を正にしてしまいます
rem = k # 残りの移動回数です
cnt = min(cur // d, k) # 0に向かって移動する回数です
cur -= d * cnt
rem -= cnt
# 残り回数が0回の場合分けをする必要はないのですが、一応
if rem > 0:
if rem % 2 == 1:
cur = abs(cur - d)
print(cur)
| x, k, d = list(map(int, input().split()))
cur = abs(x) # 座標を正にしてしまいます
rem = k # 残りの移動回数です
cnt = min(cur // d, k) # 0に向かって移動する回数です
cur -= d * cnt
rem -= cnt
# 0 % 2 = 0なので、残り回数の場合分けをする必要はないのですが、一応
if rem > 0:
if rem % 2 == 1:
cur = cur - d
ans = abs(cur)
print(ans)
| false | 6.25 | [
"-# 残り回数が0回の場合分けをする必要はないのですが、一応",
"+# 0 % 2 = 0なので、残り回数の場合分けをする必要はないのですが、一応",
"- cur = abs(cur - d)",
"-print(cur)",
"+ cur = cur - d",
"+ans = abs(cur)",
"+print(ans)"
] | false | 0.031252 | 0.084243 | 0.370971 | [
"s699373336",
"s744713449"
] |
u363610900 | p03544 | python | s622324017 | s840983120 | 20 | 17 | 2,940 | 2,940 | Accepted | Accepted | 15 | N = int(eval(input()))
L = [2, 1]
for i in range(2, N+2):
Li = L[i-1] + L[i-2]
L.append(Li)
print((L[N])) | N = int(eval(input()))
L = [2, 1]
for i in range(2, N+2):
L.append(L[i-1]+L[i-2])
print((L[N])) | 6 | 6 | 110 | 97 | N = int(eval(input()))
L = [2, 1]
for i in range(2, N + 2):
Li = L[i - 1] + L[i - 2]
L.append(Li)
print((L[N]))
| N = int(eval(input()))
L = [2, 1]
for i in range(2, N + 2):
L.append(L[i - 1] + L[i - 2])
print((L[N]))
| false | 0 | [
"- Li = L[i - 1] + L[i - 2]",
"- L.append(Li)",
"+ L.append(L[i - 1] + L[i - 2])"
] | false | 0.049399 | 0.048828 | 1.011695 | [
"s622324017",
"s840983120"
] |
u540761833 | p03611 | python | s202927399 | s648240005 | 266 | 205 | 14,004 | 14,092 | Accepted | Accepted | 22.93 | import bisect
N = int(eval(input()))
A = sorted(list(map(int,input().split())))
ans = 1
def search(A,a,b):
import bisect
ans = bisect.bisect_right(A,b) - bisect.bisect_left(A,a)
return ans
for i in range(A[-1]+1):
ans = max(ans,search(A,i-1,i+1))
print(ans) | import bisect
N = int(eval(input()))
A = sorted(list(map(int,input().split())))
ans = 1
for i in range(A[-1]+1):
ans = max(ans,bisect.bisect_right(A,i+1) - bisect.bisect_left(A,i-1))
print(ans) | 13 | 8 | 281 | 199 | import bisect
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
ans = 1
def search(A, a, b):
import bisect
ans = bisect.bisect_right(A, b) - bisect.bisect_left(A, a)
return ans
for i in range(A[-1] + 1):
ans = max(ans, search(A, i - 1, i + 1))
print(ans)
| import bisect
N = int(eval(input()))
A = sorted(list(map(int, input().split())))
ans = 1
for i in range(A[-1] + 1):
ans = max(ans, bisect.bisect_right(A, i + 1) - bisect.bisect_left(A, i - 1))
print(ans)
| false | 38.461538 | [
"-",
"-",
"-def search(A, a, b):",
"- import bisect",
"-",
"- ans = bisect.bisect_right(A, b) - bisect.bisect_left(A, a)",
"- return ans",
"-",
"-",
"- ans = max(ans, search(A, i - 1, i + 1))",
"+ ans = max(ans, bisect.bisect_right(A, i + 1) - bisect.bisect_left(A, i - 1))"
] | false | 0.046347 | 0.044521 | 1.041025 | [
"s202927399",
"s648240005"
] |
u060938295 | p03167 | python | s426891053 | s158662041 | 1,431 | 1,308 | 25,172 | 25,188 | Accepted | Accepted | 8.6 | import sys
import numpy as np
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
H, W = list(map(int,input().split()))
#A = [list(map(int,input().split())) for _ in range(H)]
A = np.array([list(eval(input())) for _ in range(H)], 'U1')
eq = A == '.'
dp = np.zeros(W+1, dtype=int)
dp[1] = 1
for i in range(1,H+1):
prev = dp.copy()
for j in range(1,W+1):
if eq[i-1][j-1]:
dp[j] = prev[j] + dp[j-1]
else:
dp[j] = 0
dp %= mod
print((dp[-1])) | import sys
import numpy as np
def input():
return sys.stdin.readline()[:-1]
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
H, W = list(map(int,input().split()))
#A = [list(map(int,input().split())) for _ in range(H)]
A = np.array([list(eval(input())) for _ in range(H)], 'U1')
eq = A == '.'
dp = np.zeros(W+1, dtype=int)
dp[1] = 1
for i in range(1,H+1):
prev = dp.copy()
for j in range(1,W+1):
if eq[i-1][j-1]:
dp[j] = prev[j] + dp[j-1]
else:
dp[j] = 0
dp %= mod
print((dp[-1])) | 24 | 27 | 496 | 552 | import sys
import numpy as np
sys.setrecursionlimit(10**9)
mod = 10**9 + 7
H, W = list(map(int, input().split()))
# A = [list(map(int,input().split())) for _ in range(H)]
A = np.array([list(eval(input())) for _ in range(H)], "U1")
eq = A == "."
dp = np.zeros(W + 1, dtype=int)
dp[1] = 1
for i in range(1, H + 1):
prev = dp.copy()
for j in range(1, W + 1):
if eq[i - 1][j - 1]:
dp[j] = prev[j] + dp[j - 1]
else:
dp[j] = 0
dp %= mod
print((dp[-1]))
| import sys
import numpy as np
def input():
return sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**9)
mod = 10**9 + 7
H, W = list(map(int, input().split()))
# A = [list(map(int,input().split())) for _ in range(H)]
A = np.array([list(eval(input())) for _ in range(H)], "U1")
eq = A == "."
dp = np.zeros(W + 1, dtype=int)
dp[1] = 1
for i in range(1, H + 1):
prev = dp.copy()
for j in range(1, W + 1):
if eq[i - 1][j - 1]:
dp[j] = prev[j] + dp[j - 1]
else:
dp[j] = 0
dp %= mod
print((dp[-1]))
| false | 11.111111 | [
"+",
"+",
"+def input():",
"+ return sys.stdin.readline()[:-1]",
"+"
] | false | 0.315421 | 0.320257 | 0.984899 | [
"s426891053",
"s158662041"
] |
u078276601 | p02582 | python | s153655918 | s957274220 | 36 | 27 | 9,096 | 9,096 | Accepted | Accepted | 25 | S = eval(input())
if S.count("RRR") == 1:
print((3))
elif S.count("RRS") == 1 or S.count("SRR") == 1:
print((2))
elif S.count("SSS") == 1:
print((0))
else:
print((1)) | S=eval(input())
if "RRR" in S:
print((3))
elif "RR" in S:
print((2))
elif "R" in S:
print((1))
else:
print((0)) | 10 | 10 | 178 | 123 | S = eval(input())
if S.count("RRR") == 1:
print((3))
elif S.count("RRS") == 1 or S.count("SRR") == 1:
print((2))
elif S.count("SSS") == 1:
print((0))
else:
print((1))
| S = eval(input())
if "RRR" in S:
print((3))
elif "RR" in S:
print((2))
elif "R" in S:
print((1))
else:
print((0))
| false | 0 | [
"-if S.count(\"RRR\") == 1:",
"+if \"RRR\" in S:",
"-elif S.count(\"RRS\") == 1 or S.count(\"SRR\") == 1:",
"+elif \"RR\" in S:",
"-elif S.count(\"SSS\") == 1:",
"+elif \"R\" in S:",
"+ print((1))",
"+else:",
"-else:",
"- print((1))"
] | false | 0.047641 | 0.04713 | 1.010841 | [
"s153655918",
"s957274220"
] |
u219086885 | p03220 | python | s047372410 | s040424789 | 20 | 18 | 3,188 | 3,060 | Accepted | Accepted | 10 |
n = int(eval(input()))
t, a = [int(x) for x in input().split()]
locations =[int(x) for x in input().split()]
print((min([(i+1,abs(a - (t - x * 6e-3))) for i, x in enumerate(locations)],key=(lambda j:j[1]))[0]))
|
n = int(eval(input()))
t, a = [int(x) for x in input().split()]
locations =[int(x) for x in input().split()]
# print(min([(i+1,abs(a - (t - x * 6e-3))) for i, x in enumerate(locations)],key=(lambda j:j[1]))[0])
diff = [abs(a - (t - x * 6e-3)) for x in locations]
print((diff.index(min(diff))+1))
| 5 | 7 | 208 | 295 | n = int(eval(input()))
t, a = [int(x) for x in input().split()]
locations = [int(x) for x in input().split()]
print(
(
min(
[(i + 1, abs(a - (t - x * 6e-3))) for i, x in enumerate(locations)],
key=(lambda j: j[1]),
)[0]
)
)
| n = int(eval(input()))
t, a = [int(x) for x in input().split()]
locations = [int(x) for x in input().split()]
# print(min([(i+1,abs(a - (t - x * 6e-3))) for i, x in enumerate(locations)],key=(lambda j:j[1]))[0])
diff = [abs(a - (t - x * 6e-3)) for x in locations]
print((diff.index(min(diff)) + 1))
| false | 28.571429 | [
"-print(",
"- (",
"- min(",
"- [(i + 1, abs(a - (t - x * 6e-3))) for i, x in enumerate(locations)],",
"- key=(lambda j: j[1]),",
"- )[0]",
"- )",
"-)",
"+# print(min([(i+1,abs(a - (t - x * 6e-3))) for i, x in enumerate(locations)],key=(lambda j:j[1]))[0])",
... | false | 0.040145 | 0.039229 | 1.023343 | [
"s047372410",
"s040424789"
] |
u737311644 | p02388 | python | s476219242 | s021104534 | 30 | 20 | 7,624 | 5,572 | Accepted | Accepted | 33.33 | x=int(eval(input()))
a= x*x*x
print (a) | a=int(eval(input()))
print((a*a*a))
| 3 | 2 | 35 | 29 | x = int(eval(input()))
a = x * x * x
print(a)
| a = int(eval(input()))
print((a * a * a))
| false | 33.333333 | [
"-x = int(eval(input()))",
"-a = x * x * x",
"-print(a)",
"+a = int(eval(input()))",
"+print((a * a * a))"
] | false | 0.036487 | 0.051574 | 0.707474 | [
"s476219242",
"s021104534"
] |
u863309603 | p02683 | python | s362504778 | s696936461 | 87 | 79 | 9,212 | 9,228 | Accepted | Accepted | 9.2 | N, M, X = list(map(int, input().split()))
books = [list(map(int, input().split())) for _ in range(N)]
ans = -1
for bits in range(1 << N):
cost = 0
a = [0] * M
for i in range(N):
if (bits >> i) & 1 == 1:
cost += books[i][0]
for j in range(M):
a[j] += books[i][j + 1]
if min(a) >= X:
ans = min(cost, ans) if ans >= 0 else cost
print(ans)
| import itertools
N, M, X = list(map(int, input().split()))
books = [list(map(int, input().split())) for _ in range(N)]
ans = -1
for i in range(N):
for choices in itertools.combinations(list(range(N)), i + 1):
cost = 0
a = [0] * M
for choice in choices:
cost += books[choice][0]
for j in range(M):
a[j] += books[choice][j + 1]
if min(a) >= X:
ans = min(cost, ans) if ans >= 0 else cost
print(ans)
| 18 | 20 | 423 | 496 | N, M, X = list(map(int, input().split()))
books = [list(map(int, input().split())) for _ in range(N)]
ans = -1
for bits in range(1 << N):
cost = 0
a = [0] * M
for i in range(N):
if (bits >> i) & 1 == 1:
cost += books[i][0]
for j in range(M):
a[j] += books[i][j + 1]
if min(a) >= X:
ans = min(cost, ans) if ans >= 0 else cost
print(ans)
| import itertools
N, M, X = list(map(int, input().split()))
books = [list(map(int, input().split())) for _ in range(N)]
ans = -1
for i in range(N):
for choices in itertools.combinations(list(range(N)), i + 1):
cost = 0
a = [0] * M
for choice in choices:
cost += books[choice][0]
for j in range(M):
a[j] += books[choice][j + 1]
if min(a) >= X:
ans = min(cost, ans) if ans >= 0 else cost
print(ans)
| false | 10 | [
"+import itertools",
"+",
"-for bits in range(1 << N):",
"- cost = 0",
"- a = [0] * M",
"- for i in range(N):",
"- if (bits >> i) & 1 == 1:",
"- cost += books[i][0]",
"+for i in range(N):",
"+ for choices in itertools.combinations(list(range(N)), i + 1):",
"+ ... | false | 0.047095 | 0.115424 | 0.408017 | [
"s362504778",
"s696936461"
] |
u357751375 | p03910 | python | s649792443 | s035479523 | 35 | 29 | 9,328 | 9,276 | Accepted | Accepted | 17.14 | n = int(eval(input()))
a = []
b = 0
i = 1
while b < n:
a.append(i)
b += i
i += 1
b -= n
for i in a:
if i != b:
print(i) | n = int(eval(input()))
ans = []
a = 0
for i in range(1,n+1):
a += i
ans.append(i)
if a >= n:
break
a -= n
for x in ans:
if x != a:
print(x) | 12 | 12 | 148 | 176 | n = int(eval(input()))
a = []
b = 0
i = 1
while b < n:
a.append(i)
b += i
i += 1
b -= n
for i in a:
if i != b:
print(i)
| n = int(eval(input()))
ans = []
a = 0
for i in range(1, n + 1):
a += i
ans.append(i)
if a >= n:
break
a -= n
for x in ans:
if x != a:
print(x)
| false | 0 | [
"-a = []",
"-b = 0",
"-i = 1",
"-while b < n:",
"- a.append(i)",
"- b += i",
"- i += 1",
"-b -= n",
"-for i in a:",
"- if i != b:",
"- print(i)",
"+ans = []",
"+a = 0",
"+for i in range(1, n + 1):",
"+ a += i",
"+ ans.append(i)",
"+ if a >= n:",
"+ ... | false | 0.042651 | 0.097214 | 0.438734 | [
"s649792443",
"s035479523"
] |
u881590806 | p02238 | python | s157349383 | s511282156 | 30 | 10 | 6,408 | 6,504 | Accepted | Accepted | 66.67 | n = int(input())
def dfs(u,t):
global graph
global found
global timestamp
if u in found: return t
found.add(u)
timestamp[u] = [-1,-1]
timestamp[u][0] = t
t += 1
for v in graph[u]:
t = dfs(v,t)
timestamp[u][1] = t
t += 1
return t
graph = [[] for i in range(n)]
found = set()
timestamp = {}
for i in range(n):
entry = list(map(int,input().strip().split(' ')))
u = entry[0]
u -= 1
for v in entry[2:]:
v -= 1
graph[u].append(v)
t = 1
for i in range(n):
t = dfs(i,t)
for i in timestamp:
print(i+1,timestamp[i][0],timestamp[i][1]) | class Node:
def __init__(self,v):
self.v = v
self.c = []
def dfs(n,f,d,t,visited):
visited.add(n.v)
f[n.v] = t
t2 = t
for c in sorted(n.c,key=lambda x:x.v):
if not c.v in visited:
t2 = dfs(c,f,d,t2+1,visited)
d[n.v] = t2+1
return t2+1
n = int(input())
nodes = {}
for _ in range(n):
entry = list(map(int,input().split(' ')))
nid = entry[0]
if not nid in nodes: nodes[nid] = Node(nid)
k = entry[1]
if k > 0:
children = entry[2:]
for c in children:
if not c in nodes: nodes[c] = Node(c)
nodes[nid].c.append(nodes[c])
f = {}
d = {}
visited = set()
t = dfs(nodes[1],f,d,1,visited)
while len(visited) < len(nodes):
for nid in nodes:
if not nid in visited:
t = dfs(nodes[nid],f,d,t+1,visited)
for k in f:
print(k,f[k],d[k]) | 37 | 39 | 664 | 911 | n = int(input())
def dfs(u, t):
global graph
global found
global timestamp
if u in found:
return t
found.add(u)
timestamp[u] = [-1, -1]
timestamp[u][0] = t
t += 1
for v in graph[u]:
t = dfs(v, t)
timestamp[u][1] = t
t += 1
return t
graph = [[] for i in range(n)]
found = set()
timestamp = {}
for i in range(n):
entry = list(map(int, input().strip().split(" ")))
u = entry[0]
u -= 1
for v in entry[2:]:
v -= 1
graph[u].append(v)
t = 1
for i in range(n):
t = dfs(i, t)
for i in timestamp:
print(i + 1, timestamp[i][0], timestamp[i][1])
| class Node:
def __init__(self, v):
self.v = v
self.c = []
def dfs(n, f, d, t, visited):
visited.add(n.v)
f[n.v] = t
t2 = t
for c in sorted(n.c, key=lambda x: x.v):
if not c.v in visited:
t2 = dfs(c, f, d, t2 + 1, visited)
d[n.v] = t2 + 1
return t2 + 1
n = int(input())
nodes = {}
for _ in range(n):
entry = list(map(int, input().split(" ")))
nid = entry[0]
if not nid in nodes:
nodes[nid] = Node(nid)
k = entry[1]
if k > 0:
children = entry[2:]
for c in children:
if not c in nodes:
nodes[c] = Node(c)
nodes[nid].c.append(nodes[c])
f = {}
d = {}
visited = set()
t = dfs(nodes[1], f, d, 1, visited)
while len(visited) < len(nodes):
for nid in nodes:
if not nid in visited:
t = dfs(nodes[nid], f, d, t + 1, visited)
for k in f:
print(k, f[k], d[k])
| false | 5.128205 | [
"-n = int(input())",
"+class Node:",
"+ def __init__(self, v):",
"+ self.v = v",
"+ self.c = []",
"-def dfs(u, t):",
"- global graph",
"- global found",
"- global timestamp",
"- if u in found:",
"- return t",
"- found.add(u)",
"- timestamp[u] = [-1, ... | false | 0.038729 | 0.037156 | 1.04233 | [
"s157349383",
"s511282156"
] |
u320567105 | p03458 | python | s134705429 | s164673112 | 1,037 | 783 | 91,868 | 63,836 | Accepted | Accepted | 24.49 | ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
INF = 10**18
N,K=rl()
W = [[0 for _ in range(2*K+3)] for _ in range(2*K+3)]
for i in range(N):
x,y,c=input().split()
x = int(x)%(2*K)
y = (int(y) if c=='W' else int(y)+K)%(2*K)
if (x<K)^(y<K):
x %= K
y %= K
W[0][y+1] += 1
W[0][y+K+1] -= 1
W[x+1][0] += 1
W[x+1][y+1] -= 2
W[x+1][y+K+1] += 2
W[x+1][2*K] -= 1
W[x+K+1][0] -= 1
W[x+K+1][y+1] += 2
W[x+K+1][y+K+1] -= 2
W[x+K+1][2*K] += 1
W[2*K][y+1] -= 1
W[2*K][y+K+1] += 1
else:
x %= K
y %= K
W[0][0] += 1
W[x+1][0] -= 1
W[0][y+1] -= 1
W[x+1][y+1] += 2
W[x+K+1][y+1] -= 2
W[x+1][y+K+1] -= 2
W[x+K+1][y+K+1] += 1
W[x+K+1][0] += 1
W[2*K][0] -= 1
W[2*K][y+1] += 1
W[0][y+K+1] += 1
W[0][2*K] -= 1
W[x+1][2*K] += 1
ans = 0
for x in range(0,2*K+1):
for y in range(0,2*K+1):
W[x][y] += W[x][y-1]
for y in range(0,2*K+1):
for x in range(0,2*K+1):
W[x][y] += W[x-1][y]
ans = max(ans,W[x][y])
print(ans)
| ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
INF = 10**18
N,K=rl()
W = [[0 for _ in range(K+3)] for _ in range(K+3)]
for i in range(N):
x,y,c=input().split()
x = int(x)%(2*K)
y = (int(y) if c=='W' else int(y)+K)%(2*K)
if (x<K)^(y<K):
x %= K
y %= K
W[0][y+1] += 1
W[x+1][y+1] -= 2
W[0][K+1] -= 1
W[x+1][K+1] += 1
W[x+1][0] += 1
W[K+1][0] -= 1
W[K+1][y+1] += 1
else:
x %= K
y %= K
W[0][0] += 1
W[x+1][0] -= 1
W[0][y+1] -= 1
W[x+1][y+1] += 2
W[K+1][y+1] -= 1
W[x+1][K+1] -= 1
W[K+1][K+1] += 1
for x in range(0,K+2):
for y in range(0,K+2):
W[x][y] += W[x][y-1]
for y in range(0,K+2):
for x in range(0,K+2):
W[x][y] += W[x-1][y]
ans = 0
for x in range(K+1):
for y in range(K+1):
res = W[x][y]
ans = max(ans,res,N-res)
print(ans)
| 55 | 48 | 1,341 | 1,103 | ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print("YES") if b else print("NO")
INF = 10**18
N, K = rl()
W = [[0 for _ in range(2 * K + 3)] for _ in range(2 * K + 3)]
for i in range(N):
x, y, c = input().split()
x = int(x) % (2 * K)
y = (int(y) if c == "W" else int(y) + K) % (2 * K)
if (x < K) ^ (y < K):
x %= K
y %= K
W[0][y + 1] += 1
W[0][y + K + 1] -= 1
W[x + 1][0] += 1
W[x + 1][y + 1] -= 2
W[x + 1][y + K + 1] += 2
W[x + 1][2 * K] -= 1
W[x + K + 1][0] -= 1
W[x + K + 1][y + 1] += 2
W[x + K + 1][y + K + 1] -= 2
W[x + K + 1][2 * K] += 1
W[2 * K][y + 1] -= 1
W[2 * K][y + K + 1] += 1
else:
x %= K
y %= K
W[0][0] += 1
W[x + 1][0] -= 1
W[0][y + 1] -= 1
W[x + 1][y + 1] += 2
W[x + K + 1][y + 1] -= 2
W[x + 1][y + K + 1] -= 2
W[x + K + 1][y + K + 1] += 1
W[x + K + 1][0] += 1
W[2 * K][0] -= 1
W[2 * K][y + 1] += 1
W[0][y + K + 1] += 1
W[0][2 * K] -= 1
W[x + 1][2 * K] += 1
ans = 0
for x in range(0, 2 * K + 1):
for y in range(0, 2 * K + 1):
W[x][y] += W[x][y - 1]
for y in range(0, 2 * K + 1):
for x in range(0, 2 * K + 1):
W[x][y] += W[x - 1][y]
ans = max(ans, W[x][y])
print(ans)
| ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print("YES") if b else print("NO")
INF = 10**18
N, K = rl()
W = [[0 for _ in range(K + 3)] for _ in range(K + 3)]
for i in range(N):
x, y, c = input().split()
x = int(x) % (2 * K)
y = (int(y) if c == "W" else int(y) + K) % (2 * K)
if (x < K) ^ (y < K):
x %= K
y %= K
W[0][y + 1] += 1
W[x + 1][y + 1] -= 2
W[0][K + 1] -= 1
W[x + 1][K + 1] += 1
W[x + 1][0] += 1
W[K + 1][0] -= 1
W[K + 1][y + 1] += 1
else:
x %= K
y %= K
W[0][0] += 1
W[x + 1][0] -= 1
W[0][y + 1] -= 1
W[x + 1][y + 1] += 2
W[K + 1][y + 1] -= 1
W[x + 1][K + 1] -= 1
W[K + 1][K + 1] += 1
for x in range(0, K + 2):
for y in range(0, K + 2):
W[x][y] += W[x][y - 1]
for y in range(0, K + 2):
for x in range(0, K + 2):
W[x][y] += W[x - 1][y]
ans = 0
for x in range(K + 1):
for y in range(K + 1):
res = W[x][y]
ans = max(ans, res, N - res)
print(ans)
| false | 12.727273 | [
"-W = [[0 for _ in range(2 * K + 3)] for _ in range(2 * K + 3)]",
"+W = [[0 for _ in range(K + 3)] for _ in range(K + 3)]",
"- W[0][y + K + 1] -= 1",
"+ W[x + 1][y + 1] -= 2",
"+ W[0][K + 1] -= 1",
"+ W[x + 1][K + 1] += 1",
"- W[x + 1][y + 1] -= 2",
"- W[x + 1... | false | 1.013227 | 0.516437 | 1.961957 | [
"s134705429",
"s164673112"
] |
u947883560 | p03282 | python | s330762252 | s190458735 | 29 | 17 | 4,184 | 3,060 | Accepted | Accepted | 41.38 | #!/usr/bin/env python3
import sys
import itertools
import collections
import functools
import math
from queue import Queue
# import numpy as np
INF = float("inf")
def solve(S: int, K: int):
n = -1
nc = 1
for i, c in enumerate(str(S)):
if c != "1":
n = i+1
nc = c
break
# print(n, nc, K)
if n == -1:
print((1))
return
if K < n:
print((1))
else:
print(nc)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
solve(S, K)
if __name__ == '__main__':
main()
| #!/usr/bin/env python3
import sys
INF = float("inf")
def solve(S: str, K: int):
for i in range(K):
if S[i] != "1":
c = S[i]
break
else:
print((1))
return
print(c)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = str(next(tokens)) # type: str
K = int(next(tokens)) # type: int
solve(S, K)
if __name__ == '__main__':
main()
| 46 | 33 | 815 | 569 | #!/usr/bin/env python3
import sys
import itertools
import collections
import functools
import math
from queue import Queue
# import numpy as np
INF = float("inf")
def solve(S: int, K: int):
n = -1
nc = 1
for i, c in enumerate(str(S)):
if c != "1":
n = i + 1
nc = c
break
# print(n, nc, K)
if n == -1:
print((1))
return
if K < n:
print((1))
else:
print(nc)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
solve(S, K)
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
import sys
INF = float("inf")
def solve(S: str, K: int):
for i in range(K):
if S[i] != "1":
c = S[i]
break
else:
print((1))
return
print(c)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = str(next(tokens)) # type: str
K = int(next(tokens)) # type: int
solve(S, K)
if __name__ == "__main__":
main()
| false | 28.26087 | [
"-import itertools",
"-import collections",
"-import functools",
"-import math",
"-from queue import Queue",
"-# import numpy as np",
"-def solve(S: int, K: int):",
"- n = -1",
"- nc = 1",
"- for i, c in enumerate(str(S)):",
"- if c != \"1\":",
"- n = i + 1",
"- ... | false | 0.087545 | 0.065116 | 1.344457 | [
"s330762252",
"s190458735"
] |
u454557108 | p03053 | python | s880582074 | s719695093 | 929 | 846 | 158,064 | 167,676 | Accepted | Accepted | 8.93 | from collections import deque
def bfs(maze, visited, s, h, w):
queue = deque(s)
# 返り値
va = 0
while queue:
y,x = queue.popleft()
for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
new_y, new_x = y+j, x+k
if new_x < 0 or new_x >= w or new_y < 0 or new_y >=h :
continue
if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:
# 移動回数の計算
visited[new_y][new_x] = visited[y][x] + 1
va = max(va,visited[new_y][new_x])
queue.append([new_y, new_x])
return va
############
h,w = list(map(int,input().split()))
maze = [['' for j in range(w)] for i in range(h)]
for i in range(h) :
m1 = eval(input())
for j in range(w) :
maze[i][j] = m1[j]
visited = [[-1]*(w) for _ in range(h)]
ans = []
s = []
s_append = s.append
for sy in range(h) :
for sx in range(w):
if maze[sy][sx] == '#' :
s_append([sy,sx])
maze[sy][sx] = '.'
visited[sy][sx] = 0
print((bfs(maze, visited, s, h, w))) | from collections import deque
def bfs(maze, visited, s, h, w):
queue = deque(s)
# 返り値
va = 0
while queue:
y,x = queue.popleft()
for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
new_y, new_x = y+j, x+k
if new_x < 0 or new_x >= w or new_y < 0 or new_y >=h :
continue
if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:
# 移動回数の計算
visited[new_y][new_x] = visited[y][x] + 1
va = max(va,visited[new_y][new_x])
queue.append([new_y, new_x])
return va
############
h,w = list(map(int,input().split()))
maze = [['.' for j in range(w)] for i in range(h)]
visited = [[-1]*(w) for _ in range(h)]
s = []
s_append = s.append
for i in range(h) :
m1 = eval(input())
for j in range(w) :
if m1[j] == '#' :
s_append([i,j])
visited[i][j] = 0
print((bfs(maze, visited, s, h, w))) | 40 | 34 | 1,002 | 885 | from collections import deque
def bfs(maze, visited, s, h, w):
queue = deque(s)
# 返り値
va = 0
while queue:
y, x = queue.popleft()
for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
new_y, new_x = y + j, x + k
if new_x < 0 or new_x >= w or new_y < 0 or new_y >= h:
continue
if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:
# 移動回数の計算
visited[new_y][new_x] = visited[y][x] + 1
va = max(va, visited[new_y][new_x])
queue.append([new_y, new_x])
return va
############
h, w = list(map(int, input().split()))
maze = [["" for j in range(w)] for i in range(h)]
for i in range(h):
m1 = eval(input())
for j in range(w):
maze[i][j] = m1[j]
visited = [[-1] * (w) for _ in range(h)]
ans = []
s = []
s_append = s.append
for sy in range(h):
for sx in range(w):
if maze[sy][sx] == "#":
s_append([sy, sx])
maze[sy][sx] = "."
visited[sy][sx] = 0
print((bfs(maze, visited, s, h, w)))
| from collections import deque
def bfs(maze, visited, s, h, w):
queue = deque(s)
# 返り値
va = 0
while queue:
y, x = queue.popleft()
for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
new_y, new_x = y + j, x + k
if new_x < 0 or new_x >= w or new_y < 0 or new_y >= h:
continue
if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:
# 移動回数の計算
visited[new_y][new_x] = visited[y][x] + 1
va = max(va, visited[new_y][new_x])
queue.append([new_y, new_x])
return va
############
h, w = list(map(int, input().split()))
maze = [["." for j in range(w)] for i in range(h)]
visited = [[-1] * (w) for _ in range(h)]
s = []
s_append = s.append
for i in range(h):
m1 = eval(input())
for j in range(w):
if m1[j] == "#":
s_append([i, j])
visited[i][j] = 0
print((bfs(maze, visited, s, h, w)))
| false | 15 | [
"-maze = [[\"\" for j in range(w)] for i in range(h)]",
"+maze = [[\".\" for j in range(w)] for i in range(h)]",
"+visited = [[-1] * (w) for _ in range(h)]",
"+s = []",
"+s_append = s.append",
"- maze[i][j] = m1[j]",
"-visited = [[-1] * (w) for _ in range(h)]",
"-ans = []",
"-s = []",
"-s_a... | false | 0.044887 | 0.047076 | 0.953509 | [
"s880582074",
"s719695093"
] |
u554133763 | p02718 | python | s122087295 | s165377592 | 186 | 89 | 77,144 | 61,628 | Accepted | Accepted | 52.15 | from decimal import Decimal
n,m = list(map(int, input().split()))
A = list(map(int, input().split()))
line = Decimal(sum(A) / (4 * m))
cnt = 0
for a in A:
if a >= line:
cnt += 1
if cnt >= m:
print('Yes')
break
else:
print('No') | n,m = list(map(int, input().split()))
A = sorted(list(map(int, input().split())), reverse = True)
s = sum(A)
cnt = 0
for a in A:
if a*4*m >= s:
cnt += 1
if cnt >= m:
print('Yes')
break
else:
print('No') | 14 | 12 | 271 | 243 | from decimal import Decimal
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
line = Decimal(sum(A) / (4 * m))
cnt = 0
for a in A:
if a >= line:
cnt += 1
if cnt >= m:
print("Yes")
break
else:
print("No")
| n, m = list(map(int, input().split()))
A = sorted(list(map(int, input().split())), reverse=True)
s = sum(A)
cnt = 0
for a in A:
if a * 4 * m >= s:
cnt += 1
if cnt >= m:
print("Yes")
break
else:
print("No")
| false | 14.285714 | [
"-from decimal import Decimal",
"-",
"-A = list(map(int, input().split()))",
"-line = Decimal(sum(A) / (4 * m))",
"+A = sorted(list(map(int, input().split())), reverse=True)",
"+s = sum(A)",
"- if a >= line:",
"+ if a * 4 * m >= s:"
] | false | 0.054255 | 0.037656 | 1.440802 | [
"s122087295",
"s165377592"
] |
u052499405 | p02913 | python | s158247330 | s522438508 | 239 | 221 | 46,428 | 44,016 | Accepted | Accepted | 7.53 | class RollingHash():
def __init__(self, s):
self.length = len(s)
self.base1 = 1009
self.base2 = 1007
self.mod1 = 10**9 + 7
self.mod2 = 10**9 + 9
self.hash1 = [0] * (self.length + 1)
self.hash2 = [0] * (self.length + 1)
self.pow1 = [1] * (self.length + 1)
self.pow2 = [1] * (self.length + 1)
for i in range(self.length):
self.hash1[i+1] = (self.hash1[i] + ord(s[i])) * self.base1 % self.mod1
self.hash2[i+1] = (self.hash2[i] + ord(s[i])) * self.base2 % self.mod2
self.pow1[i+1] = self.pow1[i] * self.base1 % self.mod1
self.pow2[i+1] = self.pow2[i] * self.base2 % self.mod2
def get(self, l, r):
t1 = self.hash1[r] - self.hash1[l] * self.pow1[r-l] % self.mod1
t1 = (t1 + self.mod1) % self.mod1
t2 = self.hash2[r] - self.hash2[l] * self.pow2[r-l] % self.mod2
t2 = (t2 + self.mod2) % self.mod2
return (t1, t2)
class FastRollingHash():
def __init__(self, s):
self.length = len(s)
self.base = 1009
self.mod = (1 << 61) - 1
self.hash = [0] * (self.length + 1)
self.pow = [1] * (self.length + 1)
for i in range(self.length):
self.hash[i+1] = (self.hash[i] + ord(s[i])) * self.base % self.mod
self.pow[i+1] = self.pow[i] * self.base % self.mod
def get(self, l, r):
t = self.hash[r] - self.hash[l] * self.pow[r-l] % self.mod
t = (t + self.mod) % self.mod
return t
n = int(eval(input()))
s = eval(input())
RH = FastRollingHash(s)
def check(l):
place = {}
for i in range(n - l + 1):
hs = RH.get(i, i + l)
if hs in place:
if i - place[hs] >= l:
return True
else:
place[hs] = i
return False
l = 0; r = n // 2 + 1
while r - l > 1:
m = (l + r) // 2
if check(m):
l = m
else:
r = m
print(l) | class RollingHash():
def __init__(self, s):
self.length = len(s)
self.base1 = 1009
self.base2 = 1007
self.mod1 = 10**9 + 7
self.mod2 = 10**9 + 9
self.hash1 = [0] * (self.length + 1)
self.hash2 = [0] * (self.length + 1)
self.pow1 = [1] * (self.length + 1)
self.pow2 = [1] * (self.length + 1)
for i in range(self.length):
self.hash1[i+1] = (self.hash1[i] + ord(s[i])) * self.base1 % self.mod1
self.hash2[i+1] = (self.hash2[i] + ord(s[i])) * self.base2 % self.mod2
self.pow1[i+1] = self.pow1[i] * self.base1 % self.mod1
self.pow2[i+1] = self.pow2[i] * self.base2 % self.mod2
def get(self, l, r):
t1 = self.hash1[r] - self.hash1[l] * self.pow1[r-l] % self.mod1
t1 = (t1 + self.mod1) % self.mod1
t2 = self.hash2[r] - self.hash2[l] * self.pow2[r-l] % self.mod2
t2 = (t2 + self.mod2) % self.mod2
return (t1, t2)
class FastRollingHash():
def __init__(self, s):
self.length = len(s)
self.base = 1009
self.mod = (1 << 61) - 1
self.hash = [0] * (self.length + 1)
self.pow = [1] * (self.length + 1)
for i in range(self.length):
self.hash[i+1] = (self.hash[i] + ord(s[i])) * self.base % self.mod
self.pow[i+1] = self.pow[i] * self.base % self.mod
def get(self, l, r):
t = self.hash[r] - self.hash[l] * self.pow[r-l] % self.mod
t = (t + self.mod) % self.mod
return t
n = int(eval(input()))
s = eval(input())
RH = RollingHash(s)
def check(l):
place = {}
for i in range(n - l + 1):
hs = RH.get(i, i + l)
if hs in place:
if i - place[hs] >= l:
return True
else:
place[hs] = i
return False
l = 0; r = n // 2 + 1
while r - l > 1:
m = (l + r) // 2
if check(m):
l = m
else:
r = m
print(l) | 66 | 66 | 2,025 | 2,021 | class RollingHash:
def __init__(self, s):
self.length = len(s)
self.base1 = 1009
self.base2 = 1007
self.mod1 = 10**9 + 7
self.mod2 = 10**9 + 9
self.hash1 = [0] * (self.length + 1)
self.hash2 = [0] * (self.length + 1)
self.pow1 = [1] * (self.length + 1)
self.pow2 = [1] * (self.length + 1)
for i in range(self.length):
self.hash1[i + 1] = (self.hash1[i] + ord(s[i])) * self.base1 % self.mod1
self.hash2[i + 1] = (self.hash2[i] + ord(s[i])) * self.base2 % self.mod2
self.pow1[i + 1] = self.pow1[i] * self.base1 % self.mod1
self.pow2[i + 1] = self.pow2[i] * self.base2 % self.mod2
def get(self, l, r):
t1 = self.hash1[r] - self.hash1[l] * self.pow1[r - l] % self.mod1
t1 = (t1 + self.mod1) % self.mod1
t2 = self.hash2[r] - self.hash2[l] * self.pow2[r - l] % self.mod2
t2 = (t2 + self.mod2) % self.mod2
return (t1, t2)
class FastRollingHash:
def __init__(self, s):
self.length = len(s)
self.base = 1009
self.mod = (1 << 61) - 1
self.hash = [0] * (self.length + 1)
self.pow = [1] * (self.length + 1)
for i in range(self.length):
self.hash[i + 1] = (self.hash[i] + ord(s[i])) * self.base % self.mod
self.pow[i + 1] = self.pow[i] * self.base % self.mod
def get(self, l, r):
t = self.hash[r] - self.hash[l] * self.pow[r - l] % self.mod
t = (t + self.mod) % self.mod
return t
n = int(eval(input()))
s = eval(input())
RH = FastRollingHash(s)
def check(l):
place = {}
for i in range(n - l + 1):
hs = RH.get(i, i + l)
if hs in place:
if i - place[hs] >= l:
return True
else:
place[hs] = i
return False
l = 0
r = n // 2 + 1
while r - l > 1:
m = (l + r) // 2
if check(m):
l = m
else:
r = m
print(l)
| class RollingHash:
def __init__(self, s):
self.length = len(s)
self.base1 = 1009
self.base2 = 1007
self.mod1 = 10**9 + 7
self.mod2 = 10**9 + 9
self.hash1 = [0] * (self.length + 1)
self.hash2 = [0] * (self.length + 1)
self.pow1 = [1] * (self.length + 1)
self.pow2 = [1] * (self.length + 1)
for i in range(self.length):
self.hash1[i + 1] = (self.hash1[i] + ord(s[i])) * self.base1 % self.mod1
self.hash2[i + 1] = (self.hash2[i] + ord(s[i])) * self.base2 % self.mod2
self.pow1[i + 1] = self.pow1[i] * self.base1 % self.mod1
self.pow2[i + 1] = self.pow2[i] * self.base2 % self.mod2
def get(self, l, r):
t1 = self.hash1[r] - self.hash1[l] * self.pow1[r - l] % self.mod1
t1 = (t1 + self.mod1) % self.mod1
t2 = self.hash2[r] - self.hash2[l] * self.pow2[r - l] % self.mod2
t2 = (t2 + self.mod2) % self.mod2
return (t1, t2)
class FastRollingHash:
def __init__(self, s):
self.length = len(s)
self.base = 1009
self.mod = (1 << 61) - 1
self.hash = [0] * (self.length + 1)
self.pow = [1] * (self.length + 1)
for i in range(self.length):
self.hash[i + 1] = (self.hash[i] + ord(s[i])) * self.base % self.mod
self.pow[i + 1] = self.pow[i] * self.base % self.mod
def get(self, l, r):
t = self.hash[r] - self.hash[l] * self.pow[r - l] % self.mod
t = (t + self.mod) % self.mod
return t
n = int(eval(input()))
s = eval(input())
RH = RollingHash(s)
def check(l):
place = {}
for i in range(n - l + 1):
hs = RH.get(i, i + l)
if hs in place:
if i - place[hs] >= l:
return True
else:
place[hs] = i
return False
l = 0
r = n // 2 + 1
while r - l > 1:
m = (l + r) // 2
if check(m):
l = m
else:
r = m
print(l)
| false | 0 | [
"-RH = FastRollingHash(s)",
"+RH = RollingHash(s)"
] | false | 0.071224 | 0.071569 | 0.995174 | [
"s158247330",
"s522438508"
] |
u037221289 | p03037 | python | s053642723 | s348183294 | 365 | 318 | 11,440 | 3,060 | Accepted | Accepted | 12.88 | N,M = list(map(int,input().split(' ')))
L = []
R = []
for i in range(M):
l,r = list(map(int,input().split(' ')))
L.append(l)
R.append(r)
L.sort()
R.sort()
A = R[0] - L[-1] +1
print((max(A,0))) | N,M = list(map(int,input().split(' ')))
left,right = list(map(int,input().split(' ')))
for i in range(M-1):
L,R = list(map(int,input().split(' ')))
left = max(L,left)
right = min(R,right)
print((max(right-left+1,0)))
| 12 | 8 | 196 | 211 | N, M = list(map(int, input().split(" ")))
L = []
R = []
for i in range(M):
l, r = list(map(int, input().split(" ")))
L.append(l)
R.append(r)
L.sort()
R.sort()
A = R[0] - L[-1] + 1
print((max(A, 0)))
| N, M = list(map(int, input().split(" ")))
left, right = list(map(int, input().split(" ")))
for i in range(M - 1):
L, R = list(map(int, input().split(" ")))
left = max(L, left)
right = min(R, right)
print((max(right - left + 1, 0)))
| false | 33.333333 | [
"-L = []",
"-R = []",
"-for i in range(M):",
"- l, r = list(map(int, input().split(\" \")))",
"- L.append(l)",
"- R.append(r)",
"-L.sort()",
"-R.sort()",
"-A = R[0] - L[-1] + 1",
"-print((max(A, 0)))",
"+left, right = list(map(int, input().split(\" \")))",
"+for i in range(M - 1):",
... | false | 0.008221 | 0.03803 | 0.21617 | [
"s053642723",
"s348183294"
] |
u312025627 | p03167 | python | s130636275 | s454085386 | 174 | 119 | 92,152 | 82,960 | Accepted | Accepted | 31.61 | MOD = 10**9 + 7
def main():
from collections import deque
H, W = (int(i) for i in input().split())
c = [eval(input()) for i in range(H)]
dist = [[-1]*W for i in range(H)]
def bfs_2d(sy=0, sx=0):
que = deque()
dist[sy][sx] = 1
que.append((sy, sx))
d = ((0, 1), (1, 0))
while que:
uh, uw = que.popleft()
for dy, dx in d:
next_h = uh + dy
next_w = uw + dx
if not(0 <= next_h < H and 0 <= next_w < W):
continue
if dist[next_h][next_w] != -1:
dist[next_h][next_w] += dist[uh][uw]
dist[next_h][next_w] %= MOD
continue
if c[next_h][next_w] == '#':
continue
dist[next_h][next_w] = dist[uh][uw]
dist[next_h][next_w] %= MOD
que.append((next_h, next_w))
bfs_2d()
print((dist[H-1][W-1] if dist[H-1][W-1] != -1 else 0))
if __name__ == '__main__':
main()
| MOD = 10**9 + 7
def main():
# もらうDP
H, W = (int(i) for i in input().split())
c = [eval(input()) for i in range(H)]
dp = [[0]*W for i in range(H)]
dp[0][0] = 1
for h in range(H):
for w in range(W):
le = 0
up = 0
if 0 <= w - 1 and c[h][w-1] != "#":
le = dp[h][w-1]
if 0 <= h - 1 and c[h-1][w] != "#":
up = dp[h-1][w]
dp[h][w] += le + up
dp[h][w] %= MOD
print((dp[-1][-1]))
if __name__ == '__main__':
main()
| 38 | 25 | 1,101 | 570 | MOD = 10**9 + 7
def main():
from collections import deque
H, W = (int(i) for i in input().split())
c = [eval(input()) for i in range(H)]
dist = [[-1] * W for i in range(H)]
def bfs_2d(sy=0, sx=0):
que = deque()
dist[sy][sx] = 1
que.append((sy, sx))
d = ((0, 1), (1, 0))
while que:
uh, uw = que.popleft()
for dy, dx in d:
next_h = uh + dy
next_w = uw + dx
if not (0 <= next_h < H and 0 <= next_w < W):
continue
if dist[next_h][next_w] != -1:
dist[next_h][next_w] += dist[uh][uw]
dist[next_h][next_w] %= MOD
continue
if c[next_h][next_w] == "#":
continue
dist[next_h][next_w] = dist[uh][uw]
dist[next_h][next_w] %= MOD
que.append((next_h, next_w))
bfs_2d()
print((dist[H - 1][W - 1] if dist[H - 1][W - 1] != -1 else 0))
if __name__ == "__main__":
main()
| MOD = 10**9 + 7
def main():
# もらうDP
H, W = (int(i) for i in input().split())
c = [eval(input()) for i in range(H)]
dp = [[0] * W for i in range(H)]
dp[0][0] = 1
for h in range(H):
for w in range(W):
le = 0
up = 0
if 0 <= w - 1 and c[h][w - 1] != "#":
le = dp[h][w - 1]
if 0 <= h - 1 and c[h - 1][w] != "#":
up = dp[h - 1][w]
dp[h][w] += le + up
dp[h][w] %= MOD
print((dp[-1][-1]))
if __name__ == "__main__":
main()
| false | 34.210526 | [
"- from collections import deque",
"-",
"+ # もらうDP",
"- dist = [[-1] * W for i in range(H)]",
"-",
"- def bfs_2d(sy=0, sx=0):",
"- que = deque()",
"- dist[sy][sx] = 1",
"- que.append((sy, sx))",
"- d = ((0, 1), (1, 0))",
"- while que:",
"- ... | false | 0.035076 | 0.035622 | 0.984685 | [
"s130636275",
"s454085386"
] |
u585819925 | p02912 | python | s346979951 | s500952127 | 162 | 146 | 14,180 | 14,180 | Accepted | Accepted | 9.88 | import heapq
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A = [-i for i in A]
heapq.heapify(A)
for _ in range(M):
#Hは全部マイナスをつけたからaは最大値的なのはいる
a = heapq.heappop(A)
heapq.heappush(A, int(a/2))
print((-sum(A))) | import heapq
N, M = list(map(int, input().split()))
A = [-int(i) for i in input().split()]
heapq.heapify(A)
for _ in range(M):
heapq.heapreplace(A, int(A[0]/2))
print((-sum(A)))
| 11 | 10 | 247 | 186 | import heapq
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A = [-i for i in A]
heapq.heapify(A)
for _ in range(M):
# Hは全部マイナスをつけたからaは最大値的なのはいる
a = heapq.heappop(A)
heapq.heappush(A, int(a / 2))
print((-sum(A)))
| import heapq
N, M = list(map(int, input().split()))
A = [-int(i) for i in input().split()]
heapq.heapify(A)
for _ in range(M):
heapq.heapreplace(A, int(A[0] / 2))
print((-sum(A)))
| false | 9.090909 | [
"-A = list(map(int, input().split()))",
"-A = [-i for i in A]",
"+A = [-int(i) for i in input().split()]",
"- # Hは全部マイナスをつけたからaは最大値的なのはいる",
"- a = heapq.heappop(A)",
"- heapq.heappush(A, int(a / 2))",
"+ heapq.heapreplace(A, int(A[0] / 2))"
] | false | 0.008544 | 0.03549 | 0.24074 | [
"s346979951",
"s500952127"
] |
u585482323 | p03033 | python | s870044795 | s818159744 | 1,698 | 1,315 | 124,740 | 96,460 | Accepted | Accepted | 22.56 | #!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LS()
return l
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
a,p = LI()
print(((a*3+p)//2))
return
#B
def B():
n = I()
s = [None for i in range(n)]
for i in range(n):
l = input().split()
s[i] = l+[i]
s.sort(key = lambda x:(x[0],-int(x[1])))
for i,a,b in s:
print((b+1))
return
#C
def C():
def dfs(d,k):
if d == n:
l.append(k)
else:
dfs(d+1,k+[0])
dfs(d+1,k+[1])
n,m = LI()
l = []
dfs(0,[])
qu = LIR(m)
p = LI()
ans = 0
for k in l:
s = 0
for q in range(m):
num = qu[q][0]
lis = list([x-1 for x in qu[q][1:]])
su = 0
for i in lis:
su ^= k[i]
if su == p[q]:
s += 1
if s == m:
ans += 1
print(ans)
return
#D
def D():
n,k = LI()
v = LI()
ans = -float("inf")
for l in range(min(k,n)+1):
for r in range(min(k,n)-l+1):
m = 0
q = v[:l]+v[n-r:]
q.sort()
res = max(0,k-r-l)
for i in range(len(q)):
if q[i] < 0 and res > 0:
res -= 1
else:
m += q[i]
if m > ans:
ans = m
print(ans)
return
#E
def E():
n,Q = LI()
e = []
for i in range(n):
s,t,x = LI()
e.append((s-x,x,1))
e.append((t-x-0.1,x,0))
e.sort(key = lambda x : x[0])
m = 2*n
q = set()
j = 0
ans = float("inf")
for i in range(Q):
d = I()
while j < m:
t,x,k = e[j]
if d < t:
break
if k:
q.add(x)
if x < ans:
ans = x
else:
q.remove(x)
if ans == x:
if q:
ans = min(q)
else:
ans = float("inf")
j += 1
print((-1 if ans == float("inf") else ans))
return
#F
def F():
n = I()
return
#Solve
if __name__ == "__main__":
E()
| #!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):l[i] = LS()
return l
sys.setrecursionlimit(1000000)
mod = 1000000007
#A
def A():
a,p = LI()
print((a*3+p)//2)
return
#B
def B():
n = I()
s = [None for i in range(n)]
for i in range(n):
l = input().split()
s[i] = l+[i]
s.sort(key = lambda x:(x[0],-int(x[1])))
for i,a,b in s:
print(b+1)
return
#C
def C():
def dfs(d,k):
if d == n:
l.append(k)
else:
dfs(d+1,k+[0])
dfs(d+1,k+[1])
n,m = LI()
l = []
dfs(0,[])
qu = LIR(m)
p = LI()
ans = 0
for k in l:
s = 0
for q in range(m):
num = qu[q][0]
lis = list(map(lambda x:x-1, qu[q][1:]))
su = 0
for i in lis:
su ^= k[i]
if su == p[q]:
s += 1
if s == m:
ans += 1
print(ans)
return
#D
def D():
n,k = LI()
v = LI()
ans = -float("inf")
for l in range(min(k,n)+1):
for r in range(min(k,n)-l+1):
m = 0
q = v[:l]+v[n-r:]
q.sort()
res = max(0,k-r-l)
for i in range(len(q)):
if q[i] < 0 and res > 0:
res -= 1
else:
m += q[i]
if m > ans:
ans = m
print(ans)
return
#E
def E():
n,q = LI()
a = LIR(n)
a.sort(key = lambda x : x[2])
d = IR(q)
ans = [-1]*(q+1)
right = [0]*q
for s,t,x in a:
l = bisect.bisect_left(d,s-x)
r = bisect.bisect_left(d,t-x)
while l < r:
while ans[l] != -1:
l = right[l]
if r <= l:
break
ans[l] = x
right[l] = r
l += 1
print(*ans[:-1], sep = "\n")
return
#F
def F():
n = I()
return
#Solve
if __name__ == "__main__":
E()
| 142 | 130 | 3,074 | 2,775 | #!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return list(map(list, sys.stdin.readline().split()))
def S():
return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = LS()
return l
sys.setrecursionlimit(1000000)
mod = 1000000007
# A
def A():
a, p = LI()
print(((a * 3 + p) // 2))
return
# B
def B():
n = I()
s = [None for i in range(n)]
for i in range(n):
l = input().split()
s[i] = l + [i]
s.sort(key=lambda x: (x[0], -int(x[1])))
for i, a, b in s:
print((b + 1))
return
# C
def C():
def dfs(d, k):
if d == n:
l.append(k)
else:
dfs(d + 1, k + [0])
dfs(d + 1, k + [1])
n, m = LI()
l = []
dfs(0, [])
qu = LIR(m)
p = LI()
ans = 0
for k in l:
s = 0
for q in range(m):
num = qu[q][0]
lis = list([x - 1 for x in qu[q][1:]])
su = 0
for i in lis:
su ^= k[i]
if su == p[q]:
s += 1
if s == m:
ans += 1
print(ans)
return
# D
def D():
n, k = LI()
v = LI()
ans = -float("inf")
for l in range(min(k, n) + 1):
for r in range(min(k, n) - l + 1):
m = 0
q = v[:l] + v[n - r :]
q.sort()
res = max(0, k - r - l)
for i in range(len(q)):
if q[i] < 0 and res > 0:
res -= 1
else:
m += q[i]
if m > ans:
ans = m
print(ans)
return
# E
def E():
n, Q = LI()
e = []
for i in range(n):
s, t, x = LI()
e.append((s - x, x, 1))
e.append((t - x - 0.1, x, 0))
e.sort(key=lambda x: x[0])
m = 2 * n
q = set()
j = 0
ans = float("inf")
for i in range(Q):
d = I()
while j < m:
t, x, k = e[j]
if d < t:
break
if k:
q.add(x)
if x < ans:
ans = x
else:
q.remove(x)
if ans == x:
if q:
ans = min(q)
else:
ans = float("inf")
j += 1
print((-1 if ans == float("inf") else ans))
return
# F
def F():
n = I()
return
# Solve
if __name__ == "__main__":
E()
| #!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return list(map(list, sys.stdin.readline().split()))
def S():
return list(sys.stdin.readline())[:-1]
def IR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = I()
return l
def LIR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = LI()
return l
def SR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = S()
return l
def LSR(n):
l = [None for i in range(n)]
for i in range(n):
l[i] = LS()
return l
sys.setrecursionlimit(1000000)
mod = 1000000007
# A
def A():
a, p = LI()
print((a * 3 + p) // 2)
return
# B
def B():
n = I()
s = [None for i in range(n)]
for i in range(n):
l = input().split()
s[i] = l + [i]
s.sort(key=lambda x: (x[0], -int(x[1])))
for i, a, b in s:
print(b + 1)
return
# C
def C():
def dfs(d, k):
if d == n:
l.append(k)
else:
dfs(d + 1, k + [0])
dfs(d + 1, k + [1])
n, m = LI()
l = []
dfs(0, [])
qu = LIR(m)
p = LI()
ans = 0
for k in l:
s = 0
for q in range(m):
num = qu[q][0]
lis = list(map(lambda x: x - 1, qu[q][1:]))
su = 0
for i in lis:
su ^= k[i]
if su == p[q]:
s += 1
if s == m:
ans += 1
print(ans)
return
# D
def D():
n, k = LI()
v = LI()
ans = -float("inf")
for l in range(min(k, n) + 1):
for r in range(min(k, n) - l + 1):
m = 0
q = v[:l] + v[n - r :]
q.sort()
res = max(0, k - r - l)
for i in range(len(q)):
if q[i] < 0 and res > 0:
res -= 1
else:
m += q[i]
if m > ans:
ans = m
print(ans)
return
# E
def E():
n, q = LI()
a = LIR(n)
a.sort(key=lambda x: x[2])
d = IR(q)
ans = [-1] * (q + 1)
right = [0] * q
for s, t, x in a:
l = bisect.bisect_left(d, s - x)
r = bisect.bisect_left(d, t - x)
while l < r:
while ans[l] != -1:
l = right[l]
if r <= l:
break
ans[l] = x
right[l] = r
l += 1
print(*ans[:-1], sep="\n")
return
# F
def F():
n = I()
return
# Solve
if __name__ == "__main__":
E()
| false | 8.450704 | [
"- print(((a * 3 + p) // 2))",
"+ print((a * 3 + p) // 2)",
"- print((b + 1))",
"+ print(b + 1)",
"- lis = list([x - 1 for x in qu[q][1:]])",
"+ lis = list(map(lambda x: x - 1, qu[q][1:]))",
"- n, Q = LI()",
"- e = []",
"- for i in range(n):",
"- ... | false | 0.094125 | 0.088007 | 1.069514 | [
"s870044795",
"s818159744"
] |
u663710122 | p03951 | python | s484891855 | s036564355 | 21 | 18 | 2,940 | 2,940 | Accepted | Accepted | 14.29 | N = int(eval(input()))
S = eval(input())
T = eval(input())
k = 0
for i in range(N):
for j in range(N):
s = S[i:]
t = T[:j + 1]
if s == t:
k = max(k, len(s))
print((2 * N - k))
| N = int(eval(input()))
S = eval(input())
T = eval(input())
for l in range(N, 2 * N + 1):
if S[N - 2 * N + l:] == T[:2 * N - l]:
print(l)
exit()
| 14 | 8 | 212 | 154 | N = int(eval(input()))
S = eval(input())
T = eval(input())
k = 0
for i in range(N):
for j in range(N):
s = S[i:]
t = T[: j + 1]
if s == t:
k = max(k, len(s))
print((2 * N - k))
| N = int(eval(input()))
S = eval(input())
T = eval(input())
for l in range(N, 2 * N + 1):
if S[N - 2 * N + l :] == T[: 2 * N - l]:
print(l)
exit()
| false | 42.857143 | [
"-k = 0",
"-for i in range(N):",
"- for j in range(N):",
"- s = S[i:]",
"- t = T[: j + 1]",
"- if s == t:",
"- k = max(k, len(s))",
"-print((2 * N - k))",
"+for l in range(N, 2 * N + 1):",
"+ if S[N - 2 * N + l :] == T[: 2 * N - l]:",
"+ print(l)",
... | false | 0.045473 | 0.045285 | 1.00415 | [
"s484891855",
"s036564355"
] |
u633068244 | p00740 | python | s582334071 | s712749980 | 3,810 | 3,390 | 4,208 | 4,204 | Accepted | Accepted | 11.02 | while 1:
n,p = list(map(int,input().split()))
if n == 0: break
have = [0]*n
stone = p
i = count = 0
while 1:
count += 1
if stone > 0:
have[i] += 1
stone -= 1
else:
stone += have[i]
have[i] = 0
if have[i] == p:
break
i = (i+1)%n
print(i) | while 1:
n,p = list(map(int,input().split()))
if n == 0: break
have = [0]*n
stone = p
i = 0
while 1:
if stone > 0:
have[i] += 1
stone -= 1
else:
stone += have[i]
have[i] = 0
if have[i] == p:
break
i = (i+1)%n
print(i) | 18 | 17 | 282 | 260 | while 1:
n, p = list(map(int, input().split()))
if n == 0:
break
have = [0] * n
stone = p
i = count = 0
while 1:
count += 1
if stone > 0:
have[i] += 1
stone -= 1
else:
stone += have[i]
have[i] = 0
if have[i] == p:
break
i = (i + 1) % n
print(i)
| while 1:
n, p = list(map(int, input().split()))
if n == 0:
break
have = [0] * n
stone = p
i = 0
while 1:
if stone > 0:
have[i] += 1
stone -= 1
else:
stone += have[i]
have[i] = 0
if have[i] == p:
break
i = (i + 1) % n
print(i)
| false | 5.555556 | [
"- i = count = 0",
"+ i = 0",
"- count += 1"
] | false | 0.537945 | 0.618253 | 0.870105 | [
"s582334071",
"s712749980"
] |
u391731808 | p03576 | python | s132779045 | s115405979 | 1,366 | 778 | 3,064 | 3,064 | Accepted | Accepted | 43.05 | N,K = list(map(int,input().split()))
XY = [list(map(int,input().split())) for _ in [0]*N]
iX = sorted(x for x,y in XY)
iY = sorted(y for x,y in XY)
X = {x:i for i,x in enumerate(iX)}
Y = {y:i for i,y in enumerate(iY)}
c = [[0]*(N+1) for i in [0]*(N+1)]
for x,y in XY:
c[Y[y]+1][X[x]+1] = 1
for i in range(N):
for j in range(N):
c[i+1][j+1] += c[i+1][j]
for i in range(N):
for j in range(N):
c[i+1][j+1] += c[i][j+1]
ans = 10**20
for l in range(N):
for r in range(l+1,N):
for u in range(N):
for d in range(u+1,N):
if c[d+1][r+1]+c[u][l]-c[u][r+1]-c[d+1][l] >=K:
ans = min(ans,
(iX[r]-iX[l])*(iY[d]-iY[u]))
print(ans) | N,K = list(map(int,input().split()))
XY = [list(map(int,input().split())) for _ in [0]*N]
iX = sorted(x for x,y in XY)
iY = sorted(y for x,y in XY)
X = {x:i for i,x in enumerate(iX)}
Y = {y:i for i,y in enumerate(iY)}
c = [[0]*(N+1) for i in [0]*(N+1)]
for x,y in XY:
c[Y[y]+1][X[x]+1] = 1
for i in range(N):
for j in range(N):
c[i+1][j+1] += c[i+1][j]
for i in range(N):
for j in range(N):
c[i+1][j+1] += c[i][j+1]
ans = 10**20
for l in range(N):
for u in range(N):
for r in range(l+1,N):
for d in range(u+1,N):
if c[d+1][r+1]+c[u][l]-c[u][r+1]-c[d+1][l] >=K:
ans = min(ans,
(iX[r]-iX[l])*(iY[d]-iY[u]))
break
print(ans) | 29 | 30 | 759 | 786 | N, K = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in [0] * N]
iX = sorted(x for x, y in XY)
iY = sorted(y for x, y in XY)
X = {x: i for i, x in enumerate(iX)}
Y = {y: i for i, y in enumerate(iY)}
c = [[0] * (N + 1) for i in [0] * (N + 1)]
for x, y in XY:
c[Y[y] + 1][X[x] + 1] = 1
for i in range(N):
for j in range(N):
c[i + 1][j + 1] += c[i + 1][j]
for i in range(N):
for j in range(N):
c[i + 1][j + 1] += c[i][j + 1]
ans = 10**20
for l in range(N):
for r in range(l + 1, N):
for u in range(N):
for d in range(u + 1, N):
if c[d + 1][r + 1] + c[u][l] - c[u][r + 1] - c[d + 1][l] >= K:
ans = min(ans, (iX[r] - iX[l]) * (iY[d] - iY[u]))
print(ans)
| N, K = list(map(int, input().split()))
XY = [list(map(int, input().split())) for _ in [0] * N]
iX = sorted(x for x, y in XY)
iY = sorted(y for x, y in XY)
X = {x: i for i, x in enumerate(iX)}
Y = {y: i for i, y in enumerate(iY)}
c = [[0] * (N + 1) for i in [0] * (N + 1)]
for x, y in XY:
c[Y[y] + 1][X[x] + 1] = 1
for i in range(N):
for j in range(N):
c[i + 1][j + 1] += c[i + 1][j]
for i in range(N):
for j in range(N):
c[i + 1][j + 1] += c[i][j + 1]
ans = 10**20
for l in range(N):
for u in range(N):
for r in range(l + 1, N):
for d in range(u + 1, N):
if c[d + 1][r + 1] + c[u][l] - c[u][r + 1] - c[d + 1][l] >= K:
ans = min(ans, (iX[r] - iX[l]) * (iY[d] - iY[u]))
break
print(ans)
| false | 3.333333 | [
"- for r in range(l + 1, N):",
"- for u in range(N):",
"+ for u in range(N):",
"+ for r in range(l + 1, N):",
"+ break"
] | false | 0.007427 | 0.157983 | 0.047014 | [
"s132779045",
"s115405979"
] |
u766477342 | p00004 | python | s412618871 | s173094197 | 50 | 20 | 7,532 | 7,588 | Accepted | Accepted | 60 | try:
while 1:
a,b,c,d,e,f = list(map(int,input().split()))
y = (c * d - f * a) / (d * b - a * e)
x = (c - b * y) / a
print(("{:.3f} {:.3f}".format(x, y)))
except Exception:
pass | def _round(x, d=0):
p = 10 ** d
return (x * p * 2 + 1) // 2 / p
try:
while 1:
a, b, c, d, e, f = list(map(int, input().split()))
s = (a * e - b * d)
x = e * c - b * f
y = -c * d + a * f
print(("{:0.3f}".format(_round(x / s, 4)), "{:0.3f}".format(_round(y / s, 4))))
except:
pass | 10 | 15 | 227 | 349 | try:
while 1:
a, b, c, d, e, f = list(map(int, input().split()))
y = (c * d - f * a) / (d * b - a * e)
x = (c - b * y) / a
print(("{:.3f} {:.3f}".format(x, y)))
except Exception:
pass
| def _round(x, d=0):
p = 10**d
return (x * p * 2 + 1) // 2 / p
try:
while 1:
a, b, c, d, e, f = list(map(int, input().split()))
s = a * e - b * d
x = e * c - b * f
y = -c * d + a * f
print(("{:0.3f}".format(_round(x / s, 4)), "{:0.3f}".format(_round(y / s, 4))))
except:
pass
| false | 33.333333 | [
"+def _round(x, d=0):",
"+ p = 10**d",
"+ return (x * p * 2 + 1) // 2 / p",
"+",
"+",
"- y = (c * d - f * a) / (d * b - a * e)",
"- x = (c - b * y) / a",
"- print((\"{:.3f} {:.3f}\".format(x, y)))",
"-except Exception:",
"+ s = a * e - b * d",
"+ x = e * ... | false | 0.035724 | 0.041226 | 0.86654 | [
"s412618871",
"s173094197"
] |
u418149936 | p02641 | python | s867577312 | s256075298 | 31 | 26 | 9,208 | 9,128 | Accepted | Accepted | 16.13 | X, N = list(map(int, input().split(' ')))
diff, rst = -1, 0
if N == 0:
print(X)
else:
P_ls = list(map(int, input().split(' ')))
for i in range(101, -1, -1):
if i not in P_ls:
if diff == -1:
diff = abs(X - i)
rst = i
else:
diff = min(diff, abs(X - i))
if diff == abs(X - i):
rst = i
print(rst) | X, N = list(map(int, input().split(' ')))
if N == 0:
print(X)
else:
P_ls = list(map(int, input().split(' ')))
diff, rst = -1, 0
for i in range(101, -1, -1):
if i not in P_ls:
if diff == -1:
diff = abs(X - i)
rst = i
else:
diff = min(diff, abs(X - i))
if diff == abs(X - i):
rst = i
print(rst) | 16 | 16 | 433 | 437 | X, N = list(map(int, input().split(" ")))
diff, rst = -1, 0
if N == 0:
print(X)
else:
P_ls = list(map(int, input().split(" ")))
for i in range(101, -1, -1):
if i not in P_ls:
if diff == -1:
diff = abs(X - i)
rst = i
else:
diff = min(diff, abs(X - i))
if diff == abs(X - i):
rst = i
print(rst)
| X, N = list(map(int, input().split(" ")))
if N == 0:
print(X)
else:
P_ls = list(map(int, input().split(" ")))
diff, rst = -1, 0
for i in range(101, -1, -1):
if i not in P_ls:
if diff == -1:
diff = abs(X - i)
rst = i
else:
diff = min(diff, abs(X - i))
if diff == abs(X - i):
rst = i
print(rst)
| false | 0 | [
"-diff, rst = -1, 0",
"+ diff, rst = -1, 0"
] | false | 0.056937 | 0.035704 | 1.594709 | [
"s867577312",
"s256075298"
] |
u094155508 | p03140 | python | s135441196 | s364439570 | 19 | 17 | 3,064 | 3,060 | Accepted | Accepted | 10.53 | n=int(eval(input()))
a= list(eval(input()))
b= list(eval(input()))
c= list(eval(input()))
alphabet = [chr(i) for i in range(97, 97+26)]
ans = 0
for i in range(n):
cnt = 200
for j in range(26):
cnt_tmp = 0
if (a[i] != alphabet[j]):
cnt_tmp += 1
if (b[i] != alphabet[j]):
cnt_tmp += 1
if (c[i] != alphabet[j]):
cnt_tmp += 1
cnt = min(cnt, cnt_tmp)
ans += cnt
print(ans)
'''
west
east
wait
'''
| n=int(eval(input()))
a= list(eval(input()))
b= list(eval(input()))
c= list(eval(input()))
ans = 0
for i in range(n):
ans += len({a[i], b[i], c[i]}) - 1
print(ans)
'''
west
east
wait
{'w', 'e', 'w'}
{'w', 'e'}
len → 2
1文字は使って良い -1
''' | 34 | 26 | 518 | 268 | n = int(eval(input()))
a = list(eval(input()))
b = list(eval(input()))
c = list(eval(input()))
alphabet = [chr(i) for i in range(97, 97 + 26)]
ans = 0
for i in range(n):
cnt = 200
for j in range(26):
cnt_tmp = 0
if a[i] != alphabet[j]:
cnt_tmp += 1
if b[i] != alphabet[j]:
cnt_tmp += 1
if c[i] != alphabet[j]:
cnt_tmp += 1
cnt = min(cnt, cnt_tmp)
ans += cnt
print(ans)
"""
west
east
wait
"""
| n = int(eval(input()))
a = list(eval(input()))
b = list(eval(input()))
c = list(eval(input()))
ans = 0
for i in range(n):
ans += len({a[i], b[i], c[i]}) - 1
print(ans)
"""
west
east
wait
{'w', 'e', 'w'}
{'w', 'e'}
len → 2
1文字は使って良い -1
"""
| false | 23.529412 | [
"-alphabet = [chr(i) for i in range(97, 97 + 26)]",
"- cnt = 200",
"- for j in range(26):",
"- cnt_tmp = 0",
"- if a[i] != alphabet[j]:",
"- cnt_tmp += 1",
"- if b[i] != alphabet[j]:",
"- cnt_tmp += 1",
"- if c[i] != alphabet[j]:",
"- ... | false | 0.051432 | 0.059086 | 0.870471 | [
"s135441196",
"s364439570"
] |
u118642796 | p03163 | python | s044686511 | s708872935 | 466 | 291 | 120,172 | 41,708 | Accepted | Accepted | 37.55 | N,W = list(map(int,input().split()))
dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(N):
w,v = list(map(int,input().split()))
for j in range(W+1):
dp[i+1][j] = max(dp[i+1][j],dp[i][j])
if j+w<=W:
dp[i+1][j+w] = max(dp[i][j]+v,dp[i+1][j+w])
print((max(dp[N]))) | N,W = list(map(int,input().split()))
dp = [0]*(W+1)
for i in range(N):
w,v = list(map(int,input().split()))
for j in range(W-w,-1,-1):
dp[j+w] = max(dp[j]+v,dp[j+w])
print((max(dp))) | 9 | 7 | 275 | 182 | N, W = list(map(int, input().split()))
dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(N):
w, v = list(map(int, input().split()))
for j in range(W + 1):
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
if j + w <= W:
dp[i + 1][j + w] = max(dp[i][j] + v, dp[i + 1][j + w])
print((max(dp[N])))
| N, W = list(map(int, input().split()))
dp = [0] * (W + 1)
for i in range(N):
w, v = list(map(int, input().split()))
for j in range(W - w, -1, -1):
dp[j + w] = max(dp[j] + v, dp[j + w])
print((max(dp)))
| false | 22.222222 | [
"-dp = [[0] * (W + 1) for _ in range(N + 1)]",
"+dp = [0] * (W + 1)",
"- for j in range(W + 1):",
"- dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])",
"- if j + w <= W:",
"- dp[i + 1][j + w] = max(dp[i][j] + v, dp[i + 1][j + w])",
"-print((max(dp[N])))",
"+ for j in range(W -... | false | 0.041715 | 0.040574 | 1.028116 | [
"s044686511",
"s708872935"
] |
u260216890 | p02647 | python | s789894601 | s185547307 | 581 | 415 | 183,528 | 184,076 | Accepted | Accepted | 28.57 | n,k=list(map(int, input().split()))
a=list(map(int, input().split()))
from itertools import accumulate
for _ in range(k):
new=[0]*n
for i in range(n):
j=a[i]
l=max(0,i-j)
r=min(n-1,i+j)
new[l]+=1
if r+1<n:
new[r+1]-=1
new=list(accumulate(new))
a=new
if all([i==n for i in a]):
break
print((*a))
| n,k=list(map(int, input().split()))
a=list(map(int, input().split()))
from itertools import accumulate
for _ in range(min(50,k)):
new=[0]*n
for i in range(n):
j=a[i]
l=max(0,i-j)
r=min(n-1,i+j)
new[l]+=1
if r+1<n:
new[r+1]-=1
new=list(accumulate(new))
a=new
print((*a)) | 17 | 15 | 383 | 343 | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
from itertools import accumulate
for _ in range(k):
new = [0] * n
for i in range(n):
j = a[i]
l = max(0, i - j)
r = min(n - 1, i + j)
new[l] += 1
if r + 1 < n:
new[r + 1] -= 1
new = list(accumulate(new))
a = new
if all([i == n for i in a]):
break
print((*a))
| n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
from itertools import accumulate
for _ in range(min(50, k)):
new = [0] * n
for i in range(n):
j = a[i]
l = max(0, i - j)
r = min(n - 1, i + j)
new[l] += 1
if r + 1 < n:
new[r + 1] -= 1
new = list(accumulate(new))
a = new
print((*a))
| false | 11.764706 | [
"-for _ in range(k):",
"+for _ in range(min(50, k)):",
"- if all([i == n for i in a]):",
"- break"
] | false | 0.036249 | 0.042189 | 0.859224 | [
"s789894601",
"s185547307"
] |
u123310422 | p03645 | python | s154465010 | s349125060 | 396 | 366 | 37,424 | 37,440 | Accepted | Accepted | 7.58 | import sys
input = sys.stdin.readline
N, M = list(map(int, input().split(" ")))
m = set()
for _ in range(M):
a, b = list(map(int, input().split(" ")))
if a < b:
m.add((a,b))
else:
m.add((b,a))
for i in range(2, N):
if (1, i) in m and (i, N) in m:
print("POSSIBLE")
break
else:
print("IMPOSSIBLE")
| import sys
input = sys.stdin.readline
def main():
N, M = list(map(int, input().split(" ")))
m = set()
for _ in range(M):
a, b = list(map(int, input().split(" ")))
if a < b:
m.add((a,b))
else:
m.add((b,a))
for i in range(2, N):
if (1, i) in m and (i, N) in m:
print("POSSIBLE")
break
else:
print("IMPOSSIBLE")
main() | 22 | 20 | 364 | 432 | import sys
input = sys.stdin.readline
N, M = list(map(int, input().split(" ")))
m = set()
for _ in range(M):
a, b = list(map(int, input().split(" ")))
if a < b:
m.add((a, b))
else:
m.add((b, a))
for i in range(2, N):
if (1, i) in m and (i, N) in m:
print("POSSIBLE")
break
else:
print("IMPOSSIBLE")
| import sys
input = sys.stdin.readline
def main():
N, M = list(map(int, input().split(" ")))
m = set()
for _ in range(M):
a, b = list(map(int, input().split(" ")))
if a < b:
m.add((a, b))
else:
m.add((b, a))
for i in range(2, N):
if (1, i) in m and (i, N) in m:
print("POSSIBLE")
break
else:
print("IMPOSSIBLE")
main()
| false | 9.090909 | [
"-N, M = list(map(int, input().split(\" \")))",
"-m = set()",
"-for _ in range(M):",
"- a, b = list(map(int, input().split(\" \")))",
"- if a < b:",
"- m.add((a, b))",
"+",
"+",
"+def main():",
"+ N, M = list(map(int, input().split(\" \")))",
"+ m = set()",
"+ for _ in ra... | false | 0.114437 | 0.040937 | 2.795446 | [
"s154465010",
"s349125060"
] |
u118019047 | p03399 | python | s776541441 | s222506356 | 20 | 17 | 3,316 | 2,940 | Accepted | Accepted | 15 | a=int(eval(input()))
b=int(eval(input()))
c=int(eval(input()))
d=int(eval(input()))
e = min(a,b)
f = min(c,d)
print((e + f)) | a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
d = int(eval(input()))
print((min(a,b)+min(c,d))) | 7 | 6 | 104 | 98 | a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
d = int(eval(input()))
e = min(a, b)
f = min(c, d)
print((e + f))
| a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))
d = int(eval(input()))
print((min(a, b) + min(c, d)))
| false | 14.285714 | [
"-e = min(a, b)",
"-f = min(c, d)",
"-print((e + f))",
"+print((min(a, b) + min(c, d)))"
] | false | 0.040874 | 0.039777 | 1.027568 | [
"s776541441",
"s222506356"
] |
u070201429 | p02558 | python | s385519185 | s166657046 | 383 | 282 | 12,496 | 78,076 | Accepted | Accepted | 26.37 | # 参考URL https://note.nkmk.me/python-union-find/
class UnionFind():
# 各要素の親要素の番号を格納するリスト
# 要素が根(ルート)の場合は-(そのグループの要素数)を格納する
def __init__(self, n):
self.n = n
self.parents = [-1] * n
# 要素xが属するグループの根を返す
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
# 要素xが属するグループと要素yが属するグループとを併合する
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
# 要素x, yが同じグループに属するかどうかを返す
def same(self, x, y):
return self.find(x) == self.find(y)
def main():
from sys import stdin
def input():
return stdin.readline().strip()
n, q = list(map(int, input().split()))
uf = UnionFind(n)
ans = []
for _ in range(q):
t, u, v = list(map(int, input().split()))
if t == 0:
uf.union(u, v)
else:
if uf.same(u, v):
ans.append(1)
else:
ans.append(0)
for i in ans:
print(i)
main() | # Reference: https://note.nkmk.me/python-union-find/
class UnionFind:
# 各要素の親要素の番号を格納するリスト
# 要素が根(ルート)の場合は-(そのグループの要素数)を格納する
def __init__(self, n):
self.n = n
self.parents = [-1] * n
# 要素xが属するグループの根を返す
def find(self, x):
history = []
while self.parents[x] >= 0:
history.append(x)
x = self.parents[x]
for node in history:
self.parents[node] = x
return x
# 要素xが属するグループと要素yが属するグループとを併合する
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
# 要素x, yが同じグループに属するかどうかを返す
def same(self, x, y):
return self.find(x) == self.find(y)
def main():
from sys import stdin
input = stdin.buffer.readline
n, q = list(map(int, input().split()))
uf = UnionFind(n)
ans = []
for _ in range(q):
t, u, v = list(map(int, input().split()))
if t == 0:
uf.union(u, v)
else:
if uf.same(u, v):
ans.append(1)
else:
ans.append(0)
for i in ans:
print(i)
main() | 58 | 56 | 1,322 | 1,342 | # 参考URL https://note.nkmk.me/python-union-find/
class UnionFind:
# 各要素の親要素の番号を格納するリスト
# 要素が根(ルート)の場合は-(そのグループの要素数)を格納する
def __init__(self, n):
self.n = n
self.parents = [-1] * n
# 要素xが属するグループの根を返す
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
# 要素xが属するグループと要素yが属するグループとを併合する
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
# 要素x, yが同じグループに属するかどうかを返す
def same(self, x, y):
return self.find(x) == self.find(y)
def main():
from sys import stdin
def input():
return stdin.readline().strip()
n, q = list(map(int, input().split()))
uf = UnionFind(n)
ans = []
for _ in range(q):
t, u, v = list(map(int, input().split()))
if t == 0:
uf.union(u, v)
else:
if uf.same(u, v):
ans.append(1)
else:
ans.append(0)
for i in ans:
print(i)
main()
| # Reference: https://note.nkmk.me/python-union-find/
class UnionFind:
# 各要素の親要素の番号を格納するリスト
# 要素が根(ルート)の場合は-(そのグループの要素数)を格納する
def __init__(self, n):
self.n = n
self.parents = [-1] * n
# 要素xが属するグループの根を返す
def find(self, x):
history = []
while self.parents[x] >= 0:
history.append(x)
x = self.parents[x]
for node in history:
self.parents[node] = x
return x
# 要素xが属するグループと要素yが属するグループとを併合する
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
# 要素x, yが同じグループに属するかどうかを返す
def same(self, x, y):
return self.find(x) == self.find(y)
def main():
from sys import stdin
input = stdin.buffer.readline
n, q = list(map(int, input().split()))
uf = UnionFind(n)
ans = []
for _ in range(q):
t, u, v = list(map(int, input().split()))
if t == 0:
uf.union(u, v)
else:
if uf.same(u, v):
ans.append(1)
else:
ans.append(0)
for i in ans:
print(i)
main()
| false | 3.448276 | [
"-# 参考URL https://note.nkmk.me/python-union-find/",
"+# Reference: https://note.nkmk.me/python-union-find/",
"- if self.parents[x] < 0:",
"- return x",
"- else:",
"- self.parents[x] = self.find(self.parents[x])",
"- return self.parents[x]",
"+ hist... | false | 0.036416 | 0.03761 | 0.968253 | [
"s385519185",
"s166657046"
] |
u131984977 | p02412 | python | s044370265 | s518724893 | 330 | 220 | 6,724 | 6,724 | Accepted | Accepted | 33.33 | while True:
(n, x) = [int(i) for i in input().split()]
if n == x == 0:
break
count = 0
start = n if n < x else x
for a in range(start, 0, -1):
if a >= x:
continue
for b in range(a - 1, 0, -1):
if a + b >= x:
continue
for c in range(b - 1, 0, -1):
if a + b + c == x:
count += 1
print(count) | while True:
(n, x) = [int(i) for i in input().split()]
if n == x == 0:
break
count = 0
start = n if n < x else x
for a in range(start, 0, -1):
if a >= x:
continue
for b in range(a - 1, 0, -1):
if a + b >= x:
continue
for c in range(b - 1, 0, -1):
total = a + b + c
if total == x:
count += 1
elif total < x:
break
print(count) | 17 | 20 | 442 | 533 | while True:
(n, x) = [int(i) for i in input().split()]
if n == x == 0:
break
count = 0
start = n if n < x else x
for a in range(start, 0, -1):
if a >= x:
continue
for b in range(a - 1, 0, -1):
if a + b >= x:
continue
for c in range(b - 1, 0, -1):
if a + b + c == x:
count += 1
print(count)
| while True:
(n, x) = [int(i) for i in input().split()]
if n == x == 0:
break
count = 0
start = n if n < x else x
for a in range(start, 0, -1):
if a >= x:
continue
for b in range(a - 1, 0, -1):
if a + b >= x:
continue
for c in range(b - 1, 0, -1):
total = a + b + c
if total == x:
count += 1
elif total < x:
break
print(count)
| false | 15 | [
"- if a + b + c == x:",
"+ total = a + b + c",
"+ if total == x:",
"+ elif total < x:",
"+ break"
] | false | 0.036786 | 0.05075 | 0.724841 | [
"s044370265",
"s518724893"
] |
u426764965 | p02936 | python | s969854704 | s736754447 | 1,041 | 726 | 98,780 | 78,192 | Accepted | Accepted | 30.26 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def abc138_d():
N, _ = map(int, readline().strip().split())
input_data = [tuple(map(int, ln.strip().split())) for ln in readlines()]
# 隣接リスト作成
graph = [[] for _ in range(N+1)]
for a, b in input_data[:N-1]:
graph[a].append(b)
graph[b].append(a)
# クエリをもとにスコア加算 ※頂点pだけに加算し、子へは加算しない
val = [0] * (N+1)
for p, x in input_data[N-1:]:
val[p] += x
# DFSで根元から順に足していく
stack = [1]
visited = [False] * (N+1)
visited[1] = True
while stack:
x = stack.pop()
for y in graph[x]:
if visited[y]: continue
stack.append(y)
visited[y] = True
val[y] += val[x]
print(*val[1:], sep=' ')
abc138_d()
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def abc138_d():
N, _ = map(int, readline().strip().split())
input_data = list(map(int, read().split()))
AB = iter(input_data[:N+N-2])
PX = iter(input_data[N+N-2:])
# 隣接リスト作成
graph = [[] for _ in range(N+1)]
for a, b in zip(AB, AB):
graph[a].append(b)
graph[b].append(a)
# クエリをもとにスコア加算 ※頂点pだけに加算し、子へは加算しない
val = [0] * (N+1)
for p, x in zip(PX, PX):
val[p] += x
# DFSで根元から順に足していく
stack = [1]
visited = [False] * (N+1)
visited[1] = True
while stack:
x = stack.pop()
for y in graph[x]:
if visited[y]: continue
stack.append(y)
visited[y] = True
val[y] += val[x]
print(*val[1:], sep=' ')
abc138_d()
| 35 | 37 | 871 | 902 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def abc138_d():
N, _ = map(int, readline().strip().split())
input_data = [tuple(map(int, ln.strip().split())) for ln in readlines()]
# 隣接リスト作成
graph = [[] for _ in range(N + 1)]
for a, b in input_data[: N - 1]:
graph[a].append(b)
graph[b].append(a)
# クエリをもとにスコア加算 ※頂点pだけに加算し、子へは加算しない
val = [0] * (N + 1)
for p, x in input_data[N - 1 :]:
val[p] += x
# DFSで根元から順に足していく
stack = [1]
visited = [False] * (N + 1)
visited[1] = True
while stack:
x = stack.pop()
for y in graph[x]:
if visited[y]:
continue
stack.append(y)
visited[y] = True
val[y] += val[x]
print(*val[1:], sep=" ")
abc138_d()
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def abc138_d():
N, _ = map(int, readline().strip().split())
input_data = list(map(int, read().split()))
AB = iter(input_data[: N + N - 2])
PX = iter(input_data[N + N - 2 :])
# 隣接リスト作成
graph = [[] for _ in range(N + 1)]
for a, b in zip(AB, AB):
graph[a].append(b)
graph[b].append(a)
# クエリをもとにスコア加算 ※頂点pだけに加算し、子へは加算しない
val = [0] * (N + 1)
for p, x in zip(PX, PX):
val[p] += x
# DFSで根元から順に足していく
stack = [1]
visited = [False] * (N + 1)
visited[1] = True
while stack:
x = stack.pop()
for y in graph[x]:
if visited[y]:
continue
stack.append(y)
visited[y] = True
val[y] += val[x]
print(*val[1:], sep=" ")
abc138_d()
| false | 5.405405 | [
"- input_data = [tuple(map(int, ln.strip().split())) for ln in readlines()]",
"+ input_data = list(map(int, read().split()))",
"+ AB = iter(input_data[: N + N - 2])",
"+ PX = iter(input_data[N + N - 2 :])",
"- for a, b in input_data[: N - 1]:",
"+ for a, b in zip(AB, AB):",
"- for p... | false | 0.087927 | 0.035051 | 2.508513 | [
"s969854704",
"s736754447"
] |
u312025627 | p03408 | python | s311199219 | s179147773 | 169 | 22 | 38,384 | 3,316 | Accepted | Accepted | 86.98 | def main():
N = int(eval(input()))
A = [eval(input()) for i in range(N)]
M = int(eval(input()))
B = [eval(input()) for i in range(M)]
ans = 0
from collections import Counter
S = Counter(A)
T = Counter(B)
for k, v in list(S.items()):
ans = max(ans, v - T[k])
print(ans)
if __name__ == '__main__':
main()
| def main():
N = int(eval(input()))
S = [eval(input()) for i in range(N)]
M = int(eval(input()))
T = [eval(input()) for i in range(M)]
ans = 0
from collections import Counter
c = Counter(S)
cT = Counter(T)
for k, v in list(c.items()):
ans = max(ans, v - cT[k])
print(ans)
if __name__ == '__main__':
main()
| 16 | 16 | 342 | 344 | def main():
N = int(eval(input()))
A = [eval(input()) for i in range(N)]
M = int(eval(input()))
B = [eval(input()) for i in range(M)]
ans = 0
from collections import Counter
S = Counter(A)
T = Counter(B)
for k, v in list(S.items()):
ans = max(ans, v - T[k])
print(ans)
if __name__ == "__main__":
main()
| def main():
N = int(eval(input()))
S = [eval(input()) for i in range(N)]
M = int(eval(input()))
T = [eval(input()) for i in range(M)]
ans = 0
from collections import Counter
c = Counter(S)
cT = Counter(T)
for k, v in list(c.items()):
ans = max(ans, v - cT[k])
print(ans)
if __name__ == "__main__":
main()
| false | 0 | [
"- A = [eval(input()) for i in range(N)]",
"+ S = [eval(input()) for i in range(N)]",
"- B = [eval(input()) for i in range(M)]",
"+ T = [eval(input()) for i in range(M)]",
"- S = Counter(A)",
"- T = Counter(B)",
"- for k, v in list(S.items()):",
"- ans = max(ans, v - T[k])"... | false | 0.036386 | 0.035628 | 1.021273 | [
"s311199219",
"s179147773"
] |
u645250356 | p03695 | python | s575614441 | s876226306 | 180 | 55 | 38,640 | 5,476 | Accepted | Accepted | 69.44 | from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
n = inp()
a = inpl()
d = defaultdict(int)
for i in a:
d[i//400] += 1
c = 0
f = 0
for key in list(d.keys()):
if key < 8:
c += 1
else:
f += d[key]
if c == 0:
print((1,f))
else:
print((c,c+f))
| from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
bo = [False] * 8
free = 0
for x in a:
now = x//400
if now < 8:
bo[now] = True
else:
free += 1
mi = sum(bo) if sum(bo) > 0 else 1
print((mi, sum(bo) + free)) | 26 | 22 | 625 | 576 | from collections import Counter, defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
def inpl_str():
return list(sys.stdin.readline().split())
def inpln(n):
return list(int(sys.stdin.readline()) for i in range(n))
n = inp()
a = inpl()
d = defaultdict(int)
for i in a:
d[i // 400] += 1
c = 0
f = 0
for key in list(d.keys()):
if key < 8:
c += 1
else:
f += d[key]
if c == 0:
print((1, f))
else:
print((c, c + f))
| from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions, pprint
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
bo = [False] * 8
free = 0
for x in a:
now = x // 400
if now < 8:
bo[now] = True
else:
free += 1
mi = sum(bo) if sum(bo) > 0 else 1
print((mi, sum(bo) + free))
| false | 15.384615 | [
"-import sys, heapq, bisect, math, itertools, string, queue",
"+from heapq import heappop, heappush, heapify",
"+from bisect import bisect_left, bisect_right",
"+import sys, math, itertools, fractions, pprint",
"+INF = float(\"inf\")",
"-def inpl_str():",
"- return list(sys.stdin.readline().split())"... | false | 0.065499 | 0.110198 | 0.594371 | [
"s575614441",
"s876226306"
] |
u197955752 | p02844 | python | s100192232 | s801728319 | 1,179 | 843 | 3,188 | 3,188 | Accepted | Accepted | 28.5 | N = int(eval(input()))
S = eval(input())
pin1 = {}
pin12 = {}
pin123 = {}
for i in range(N):
if S[i] not in pin1:
pin1[S[i]] = 1
for j in range(i + 1, N):
if S[i] + S[j] not in pin12:
pin12[S[i] + S[j]] = 1
for k in range(j + 1, N):
if S[i] + S[j] + S[k] not in pin123:
pin123[S[i] + S[j] + S[k]] = 1
print((len(pin123)))
| N = int(eval(input()))
S = eval(input())
pin = [[[False] * 11 for _ in range(11)] for _ in range(11)]
for i in range(0, N):
c = int(S[i])
for a in range(10):
for b in range(10):
if pin[a][b][-1]:
pin[a][b][c] = True
if pin[a][-1][-1]:
pin[a][c][-1] = True
pin[c][-1][-1] = True
ans = 0
for a in range(10):
for b in range(10):
for c in range(10):
ans += int(pin[a][b][c])
print(ans) | 18 | 22 | 436 | 486 | N = int(eval(input()))
S = eval(input())
pin1 = {}
pin12 = {}
pin123 = {}
for i in range(N):
if S[i] not in pin1:
pin1[S[i]] = 1
for j in range(i + 1, N):
if S[i] + S[j] not in pin12:
pin12[S[i] + S[j]] = 1
for k in range(j + 1, N):
if S[i] + S[j] + S[k] not in pin123:
pin123[S[i] + S[j] + S[k]] = 1
print((len(pin123)))
| N = int(eval(input()))
S = eval(input())
pin = [[[False] * 11 for _ in range(11)] for _ in range(11)]
for i in range(0, N):
c = int(S[i])
for a in range(10):
for b in range(10):
if pin[a][b][-1]:
pin[a][b][c] = True
if pin[a][-1][-1]:
pin[a][c][-1] = True
pin[c][-1][-1] = True
ans = 0
for a in range(10):
for b in range(10):
for c in range(10):
ans += int(pin[a][b][c])
print(ans)
| false | 18.181818 | [
"-pin1 = {}",
"-pin12 = {}",
"-pin123 = {}",
"-for i in range(N):",
"- if S[i] not in pin1:",
"- pin1[S[i]] = 1",
"- for j in range(i + 1, N):",
"- if S[i] + S[j] not in pin12:",
"- pin12[S[i] + S[j]] = 1",
"- for k in range(j + 1, N):",
... | false | 0.042006 | 0.036321 | 1.156513 | [
"s100192232",
"s801728319"
] |
u238940874 | p02755 | python | s616061061 | s807266053 | 20 | 18 | 3,064 | 3,064 | Accepted | Accepted | 10 | a,b=list(map(int,input().split()))
for i in range(b*10,b*10+9):
if int(i*0.08)==a:
print(i)
break
else:
print((-1)) | a,b=list(map(int,input().split()))
for i in range(1,1001):
if int(i*0.08)==a and int(i*0.1)==b:
print(i)
break
else:
print((-1)) | 7 | 7 | 137 | 150 | a, b = list(map(int, input().split()))
for i in range(b * 10, b * 10 + 9):
if int(i * 0.08) == a:
print(i)
break
else:
print((-1))
| a, b = list(map(int, input().split()))
for i in range(1, 1001):
if int(i * 0.08) == a and int(i * 0.1) == b:
print(i)
break
else:
print((-1))
| false | 0 | [
"-for i in range(b * 10, b * 10 + 9):",
"- if int(i * 0.08) == a:",
"+for i in range(1, 1001):",
"+ if int(i * 0.08) == a and int(i * 0.1) == b:"
] | false | 0.044338 | 0.045777 | 0.968553 | [
"s616061061",
"s807266053"
] |
u533039576 | p02774 | python | s963546957 | s922819936 | 649 | 491 | 125,300 | 95,188 | Accepted | Accepted | 24.35 | from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
a_minus = a_zero = a_plus = 0
for i in range(n):
if a[i] > 0:
a_plus += 1
elif a[i] == 0:
a_zero += 1
else:
a_minus += 1
aa_minus = a_minus * a_plus
aa_zero = a_zero * (n - a_zero) + a_zero * (a_zero - 1) // 2
def check_minus(x):
# k番目の数がx(<0)以下であるか
# x以下の数字がk個以上あるか
cnt = 0
j = a_minus + a_zero
for i in range(a_minus):
# a[i] < 0
while j < n and a[i] * a[j] > x:
j += 1
cnt += n - j
return cnt >= k
def check_plus(x):
# k番目の数がx(>0)以下であるか
# x以下の数字がk個以上あるか
def func(b, m):
# 昇順ソート済みの数列b (長さm)
# 掛け算してx以下となる数を求める
c = 0
j = m - 1
for i in range(m):
while j > 0 and b[i] * b[j] > x:
j -= 1
c += max(j - i, 0)
return c
cnt = aa_minus + aa_zero
cnt += func(a[-a_plus:], a_plus)
cnt += func(list(reversed(a[:a_minus])), a_minus)
return cnt >= k
if k <= aa_minus:
# k番目の数は負の数
lb = a[0] * a[-1] - 1 # False
ub = 0 # True
while ub - lb > 1:
mid = (ub + lb) // 2
if check_minus(mid):
ub = mid
else:
lb = mid
ans = ub
elif k <= aa_minus + aa_zero:
# k番目の数は0
ans = 0
else:
# k番目の数はプラス
lb = 0 # False
ub = max(a[0]**2, a[-1]**2) + 1 # True
while ub - lb > 1:
mid = (ub + lb) // 2
if check_plus(mid):
ub = mid
else:
lb = mid
ans = ub
print(ans)
| from bisect import bisect_left, bisect_right
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
n_m = bisect_left(a, 0) # a[i] < 0 の数
n_0 = bisect_right(a, 0) - n_m # a[i] = 0 の数
n_p = n - n_m - n_0 # a[i] > 0 の数
nn_m = n_m * n_p # 積が負になるペア数
nn_0 = n_0 * (n - n_0) + n_0 * (n_0 - 1) // 2 # 積が0になるペア数
nn_p = n * (n - 1) // 2 - nn_m - nn_0 # 積が正になるペア数
if k <= nn_m:
# k番目の値は負
def check_minus(x):
# k番目の値がx(<0)以下
# a[i] * a[j] <= x
# a[i] * a[j] <= x : a[j] >= abs(x) / abs(a[i])
# a[i+1] * a[j] <= x : a[j] >= abs(x) / abs(a[i+1])
# a[i] <= a[i+1] < 0
# abs(a[i]) >= abs(a[i+1])
# a: [-------00000+++++++]
# i jjjjj
# i jjjj
# i jj
# a[i] * a[j] <= -7
# n_m = 4
# n_0 = 3
# a = [-5, -3, -2, -1, 0, 0, 0, 1, 2, 3, 4, 5]
# i j (j j j)
# i j (j j)
# i j
# i j
# a[i] * a[j] = -5
# -2 * 4 = -6
cnt = 0
j = n_m + n_0
for i in range(n_m):
while j < n and a[i] * a[j] > x:
j += 1
# a[i] * a[j] <= x
# [j, n)
cnt += n - j
return cnt >= k
# a[i] * a[j] <= x
lb = -10**18 # False
ub = -1 # True
while ub - lb > 1:
mid = (ub + lb) // 2
if check_minus(mid):
ub = mid
else:
lb = mid
ans = ub
elif k <= nn_m + nn_0:
# k番目の値は0
ans = 0
else:
# k番目の値は正
a_p = a[n_m + n_0:]
a_m = [-a[i] for i in reversed(list(range(n_m)))]
def check_plus(x):
# k番目の値がx(>=0)以下
def func(b):
# b [++++++++++++++]
# ijjjjjjjjjjj
# ijjjjjjjj
# ijjjj
# ij
# b[i] * b[j] <= x
# b[i] * b[j] <= x : b[j] <= x / b[i]
# b[i+1] * b[j] <= x : b[j] <= x / b[i+1]
c = 0
j = len(b) - 1
for i in range(len(b)):
if i >= j:
break
# i < j
while i < j and b[i] * b[j] > x:
j -= 1
# b[i] * b[j] <= x
# (i, j]
c += j - i
return c
cnt = nn_m + nn_0
cnt += func(a_p)
cnt += func(a_m)
return cnt >= k
# a[i] * a[j] <= x
lb = 0 # False
ub = 10**18 + 1 # True
while ub - lb > 1:
mid = (ub + lb) // 2
if check_plus(mid):
ub = mid
else:
lb = mid
ans = ub
print(ans)
| 85 | 112 | 1,751 | 2,949 | from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
a_minus = a_zero = a_plus = 0
for i in range(n):
if a[i] > 0:
a_plus += 1
elif a[i] == 0:
a_zero += 1
else:
a_minus += 1
aa_minus = a_minus * a_plus
aa_zero = a_zero * (n - a_zero) + a_zero * (a_zero - 1) // 2
def check_minus(x):
# k番目の数がx(<0)以下であるか
# x以下の数字がk個以上あるか
cnt = 0
j = a_minus + a_zero
for i in range(a_minus):
# a[i] < 0
while j < n and a[i] * a[j] > x:
j += 1
cnt += n - j
return cnt >= k
def check_plus(x):
# k番目の数がx(>0)以下であるか
# x以下の数字がk個以上あるか
def func(b, m):
# 昇順ソート済みの数列b (長さm)
# 掛け算してx以下となる数を求める
c = 0
j = m - 1
for i in range(m):
while j > 0 and b[i] * b[j] > x:
j -= 1
c += max(j - i, 0)
return c
cnt = aa_minus + aa_zero
cnt += func(a[-a_plus:], a_plus)
cnt += func(list(reversed(a[:a_minus])), a_minus)
return cnt >= k
if k <= aa_minus:
# k番目の数は負の数
lb = a[0] * a[-1] - 1 # False
ub = 0 # True
while ub - lb > 1:
mid = (ub + lb) // 2
if check_minus(mid):
ub = mid
else:
lb = mid
ans = ub
elif k <= aa_minus + aa_zero:
# k番目の数は0
ans = 0
else:
# k番目の数はプラス
lb = 0 # False
ub = max(a[0] ** 2, a[-1] ** 2) + 1 # True
while ub - lb > 1:
mid = (ub + lb) // 2
if check_plus(mid):
ub = mid
else:
lb = mid
ans = ub
print(ans)
| from bisect import bisect_left, bisect_right
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
n_m = bisect_left(a, 0) # a[i] < 0 の数
n_0 = bisect_right(a, 0) - n_m # a[i] = 0 の数
n_p = n - n_m - n_0 # a[i] > 0 の数
nn_m = n_m * n_p # 積が負になるペア数
nn_0 = n_0 * (n - n_0) + n_0 * (n_0 - 1) // 2 # 積が0になるペア数
nn_p = n * (n - 1) // 2 - nn_m - nn_0 # 積が正になるペア数
if k <= nn_m:
# k番目の値は負
def check_minus(x):
# k番目の値がx(<0)以下
# a[i] * a[j] <= x
# a[i] * a[j] <= x : a[j] >= abs(x) / abs(a[i])
# a[i+1] * a[j] <= x : a[j] >= abs(x) / abs(a[i+1])
# a[i] <= a[i+1] < 0
# abs(a[i]) >= abs(a[i+1])
# a: [-------00000+++++++]
# i jjjjj
# i jjjj
# i jj
# a[i] * a[j] <= -7
# n_m = 4
# n_0 = 3
# a = [-5, -3, -2, -1, 0, 0, 0, 1, 2, 3, 4, 5]
# i j (j j j)
# i j (j j)
# i j
# i j
# a[i] * a[j] = -5
# -2 * 4 = -6
cnt = 0
j = n_m + n_0
for i in range(n_m):
while j < n and a[i] * a[j] > x:
j += 1
# a[i] * a[j] <= x
# [j, n)
cnt += n - j
return cnt >= k
# a[i] * a[j] <= x
lb = -(10**18) # False
ub = -1 # True
while ub - lb > 1:
mid = (ub + lb) // 2
if check_minus(mid):
ub = mid
else:
lb = mid
ans = ub
elif k <= nn_m + nn_0:
# k番目の値は0
ans = 0
else:
# k番目の値は正
a_p = a[n_m + n_0 :]
a_m = [-a[i] for i in reversed(list(range(n_m)))]
def check_plus(x):
# k番目の値がx(>=0)以下
def func(b):
# b [++++++++++++++]
# ijjjjjjjjjjj
# ijjjjjjjj
# ijjjj
# ij
# b[i] * b[j] <= x
# b[i] * b[j] <= x : b[j] <= x / b[i]
# b[i+1] * b[j] <= x : b[j] <= x / b[i+1]
c = 0
j = len(b) - 1
for i in range(len(b)):
if i >= j:
break
# i < j
while i < j and b[i] * b[j] > x:
j -= 1
# b[i] * b[j] <= x
# (i, j]
c += j - i
return c
cnt = nn_m + nn_0
cnt += func(a_p)
cnt += func(a_m)
return cnt >= k
# a[i] * a[j] <= x
lb = 0 # False
ub = 10**18 + 1 # True
while ub - lb > 1:
mid = (ub + lb) // 2
if check_plus(mid):
ub = mid
else:
lb = mid
ans = ub
print(ans)
| false | 24.107143 | [
"-import sys",
"-input = sys.stdin.readline",
"-a_minus = a_zero = a_plus = 0",
"-for i in range(n):",
"- if a[i] > 0:",
"- a_plus += 1",
"- elif a[i] == 0:",
"- a_zero += 1",
"- else:",
"- a_minus += 1",
"-aa_minus = a_minus * a_plus",
"-aa_zero = a_zero * (n - a... | false | 0.049146 | 0.050958 | 0.964446 | [
"s963546957",
"s922819936"
] |
u678167152 | p03352 | python | s123671846 | s973050242 | 28 | 25 | 9,392 | 9,124 | Accepted | Accepted | 10.71 | #素因数分解して列挙する関数、約数列挙ではない!
from collections import Counter
def factorize(n):
b = 2
fct = []
while b * b <= n:
while n % b == 0:
n //= b
fct.append(b)
b = b + 1
if n > 1:
fct.append(n)
f = list(Counter(fct).values())
if 1 not in f and len(set(f))==1:
return True
return False
X = int(eval(input()))
for i in range(X,0,-1):
f = factorize(i)
if f==True or i==1:
print(i)
break | def solve():
ans = 0
X = int(eval(input()))
lis = [False]*(X+1)
lis[1] = True
for b in range(2,X+1):
p = 2
while b**p<=X:
lis[b**p] = True
p += 1
for i in range(X,-1,-1):
if lis[i]==True:
return i
print((solve())) | 23 | 14 | 436 | 260 | # 素因数分解して列挙する関数、約数列挙ではない!
from collections import Counter
def factorize(n):
b = 2
fct = []
while b * b <= n:
while n % b == 0:
n //= b
fct.append(b)
b = b + 1
if n > 1:
fct.append(n)
f = list(Counter(fct).values())
if 1 not in f and len(set(f)) == 1:
return True
return False
X = int(eval(input()))
for i in range(X, 0, -1):
f = factorize(i)
if f == True or i == 1:
print(i)
break
| def solve():
ans = 0
X = int(eval(input()))
lis = [False] * (X + 1)
lis[1] = True
for b in range(2, X + 1):
p = 2
while b**p <= X:
lis[b**p] = True
p += 1
for i in range(X, -1, -1):
if lis[i] == True:
return i
print((solve()))
| false | 39.130435 | [
"-# 素因数分解して列挙する関数、約数列挙ではない!",
"-from collections import Counter",
"+def solve():",
"+ ans = 0",
"+ X = int(eval(input()))",
"+ lis = [False] * (X + 1)",
"+ lis[1] = True",
"+ for b in range(2, X + 1):",
"+ p = 2",
"+ while b**p <= X:",
"+ lis[b**p] = True"... | false | 0.04065 | 0.037046 | 1.097283 | [
"s123671846",
"s973050242"
] |
u151625340 | p03380 | python | s925334179 | s569751496 | 101 | 80 | 14,428 | 14,424 | Accepted | Accepted | 20.79 | n = int(eval(input()))
a = list(map(int,input().split()))
a.sort()
m = a[-1]
def near_abs_id(l,n): # リストlの中で絶対値がもっともnに近い要素のindex
idx = 0
m = 10**12
for i in range(len(l)):
if abs(l[i]-n) < m:
m = abs(l[i]-n)
idx= i
return idx
j = near_abs_id(a,m/2)
if j==n-1:
j-=1
print((m,a[j])) |
import bisect
def near_abs_id(a,target,fast=True): # a:listの中で絶対値がもっともtargetに近い要素のindex
# 複数存在する場合は一番indexが小さいもの
if fast: # O(logn) ### 昇順にソート済みで,全て正の数であることが必要
idx = bisect.bisect_left(a,target)
if idx==0: return idx
elif idx==len(a): return len(a)-1
else:
if idx==len(a)-1:
if abs(a[idx-1]-target)<=abs(a[idx]-target):
return idx-1
else:
return idx
else:
now = abs(a[idx+1]-target)
ans = idx+1
for i in (0,-1):
if abs(a[idx+i]-target)<=now:
ans -= 1
now = abs(a[idx+i]-target)
return ans
else: # O(n)
idx = 0
m = float('inf')
for i in range(len(a)):
if abs(a[i]-target) < m:
m = abs(a[i]-target)
idx= i
return idx
n = int(eval(input()))
a = list(map(int,input().split()))
a.sort()
m = a[-1]
j=near_abs_id(a,m/2)
if j==n-1:
j-=1
print((m,a[j]))
| 17 | 40 | 341 | 1,131 | n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
m = a[-1]
def near_abs_id(l, n): # リストlの中で絶対値がもっともnに近い要素のindex
idx = 0
m = 10**12
for i in range(len(l)):
if abs(l[i] - n) < m:
m = abs(l[i] - n)
idx = i
return idx
j = near_abs_id(a, m / 2)
if j == n - 1:
j -= 1
print((m, a[j]))
| import bisect
def near_abs_id(a, target, fast=True): # a:listの中で絶対値がもっともtargetに近い要素のindex
# 複数存在する場合は一番indexが小さいもの
if fast: # O(logn) ### 昇順にソート済みで,全て正の数であることが必要
idx = bisect.bisect_left(a, target)
if idx == 0:
return idx
elif idx == len(a):
return len(a) - 1
else:
if idx == len(a) - 1:
if abs(a[idx - 1] - target) <= abs(a[idx] - target):
return idx - 1
else:
return idx
else:
now = abs(a[idx + 1] - target)
ans = idx + 1
for i in (0, -1):
if abs(a[idx + i] - target) <= now:
ans -= 1
now = abs(a[idx + i] - target)
return ans
else: # O(n)
idx = 0
m = float("inf")
for i in range(len(a)):
if abs(a[i] - target) < m:
m = abs(a[i] - target)
idx = i
return idx
n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
m = a[-1]
j = near_abs_id(a, m / 2)
if j == n - 1:
j -= 1
print((m, a[j]))
| false | 57.5 | [
"+import bisect",
"+",
"+",
"+def near_abs_id(a, target, fast=True): # a:listの中で絶対値がもっともtargetに近い要素のindex",
"+ # 複数存在する場合は一番indexが小さいもの",
"+ if fast: # O(logn) ### 昇順にソート済みで,全て正の数であることが必要",
"+ idx = bisect.bisect_left(a, target)",
"+ if idx == 0:",
"+ return idx",
... | false | 0.04094 | 0.038016 | 1.076923 | [
"s925334179",
"s569751496"
] |
u600402037 | p03332 | python | s556733635 | s609964425 | 1,977 | 778 | 24,212 | 26,592 | Accepted | Accepted | 60.65 | # coding: utf-8
import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
MOD = 998244353
N, A, B, K = lr()
answer = 0
# A * x + B * y = K
# nCx * nCy
def cmb(n, k):
if k < 0 or k > n: return 0
return fact_N * fact_inv[k] % MOD * fact_inv[n-k] % MOD
def cumprod(arr, MOD):
L = len(arr); Lsq = int(L**.5+1)
arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
for n in range(1, Lsq):
arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD
for n in range(1, Lsq):
arr[n] *= arr[n-1, -1]; arr[n] %= MOD
return arr.ravel()[:L]
def make_fact(U, MOD):
x = np.arange(U, dtype=np.int64); x[0] = 1
fact = cumprod(x, MOD)
x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
fact_inv = cumprod(x, MOD)[::-1]
return fact, fact_inv
U = N + 100 # 階乗テーブルの上限
fact, fact_inv = make_fact(U, MOD)
fact_N = fact[N]
for x in range(N+1):
temp = K-A*x
if temp%B != 0:
continue
y = temp // B
if y > N:
continue
if y < 0:
break
answer += cmb(N, x) * cmb(N, y)
answer %= MOD
print((answer % MOD))
| # coding: utf-8
import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
MOD = 998244353
N, A, B, K = lr()
answer = 0
# A * x + B * y = K
# nCx * nCy
def cmb(n, k):
if k < 0 or k > n: return 0
return fact_N * fact_inv[k] % MOD * fact_inv[n-k] % MOD
def cumprod(arr, MOD):
L = len(arr); Lsq = int(L**.5+1)
arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
for n in range(1, Lsq):
arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD
for n in range(1, Lsq):
arr[n] *= arr[n-1, -1]; arr[n] %= MOD
return arr.ravel()[:L]
def make_fact(U, MOD):
x = np.arange(U, dtype=np.int64); x[0] = 1
fact = cumprod(x, MOD)
x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
fact_inv = cumprod(x, MOD)[::-1]
return fact, fact_inv
U = N + 1 # 階乗テーブルの上限
fact, fact_inv = make_fact(U, MOD)
fact_N = fact[N]
comb = fact_N * fact_inv % MOD * fact_inv[::-1] % MOD
for x in range(N+1):
temp = K-A*x
if temp%B != 0:
continue
y = temp // B
if y > N:
continue
if y < 0:
break
answer += comb[x] * comb[y]
answer %= MOD
print((answer % MOD))
| 51 | 52 | 1,233 | 1,282 | # coding: utf-8
import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
MOD = 998244353
N, A, B, K = lr()
answer = 0
# A * x + B * y = K
# nCx * nCy
def cmb(n, k):
if k < 0 or k > n:
return 0
return fact_N * fact_inv[k] % MOD * fact_inv[n - k] % MOD
def cumprod(arr, MOD):
L = len(arr)
Lsq = int(L**0.5 + 1)
arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
for n in range(1, Lsq):
arr[:, n] *= arr[:, n - 1]
arr[:, n] %= MOD
for n in range(1, Lsq):
arr[n] *= arr[n - 1, -1]
arr[n] %= MOD
return arr.ravel()[:L]
def make_fact(U, MOD):
x = np.arange(U, dtype=np.int64)
x[0] = 1
fact = cumprod(x, MOD)
x = np.arange(U, 0, -1, dtype=np.int64)
x[0] = pow(int(fact[-1]), MOD - 2, MOD)
fact_inv = cumprod(x, MOD)[::-1]
return fact, fact_inv
U = N + 100 # 階乗テーブルの上限
fact, fact_inv = make_fact(U, MOD)
fact_N = fact[N]
for x in range(N + 1):
temp = K - A * x
if temp % B != 0:
continue
y = temp // B
if y > N:
continue
if y < 0:
break
answer += cmb(N, x) * cmb(N, y)
answer %= MOD
print((answer % MOD))
| # coding: utf-8
import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
MOD = 998244353
N, A, B, K = lr()
answer = 0
# A * x + B * y = K
# nCx * nCy
def cmb(n, k):
if k < 0 or k > n:
return 0
return fact_N * fact_inv[k] % MOD * fact_inv[n - k] % MOD
def cumprod(arr, MOD):
L = len(arr)
Lsq = int(L**0.5 + 1)
arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
for n in range(1, Lsq):
arr[:, n] *= arr[:, n - 1]
arr[:, n] %= MOD
for n in range(1, Lsq):
arr[n] *= arr[n - 1, -1]
arr[n] %= MOD
return arr.ravel()[:L]
def make_fact(U, MOD):
x = np.arange(U, dtype=np.int64)
x[0] = 1
fact = cumprod(x, MOD)
x = np.arange(U, 0, -1, dtype=np.int64)
x[0] = pow(int(fact[-1]), MOD - 2, MOD)
fact_inv = cumprod(x, MOD)[::-1]
return fact, fact_inv
U = N + 1 # 階乗テーブルの上限
fact, fact_inv = make_fact(U, MOD)
fact_N = fact[N]
comb = fact_N * fact_inv % MOD * fact_inv[::-1] % MOD
for x in range(N + 1):
temp = K - A * x
if temp % B != 0:
continue
y = temp // B
if y > N:
continue
if y < 0:
break
answer += comb[x] * comb[y]
answer %= MOD
print((answer % MOD))
| false | 1.923077 | [
"-U = N + 100 # 階乗テーブルの上限",
"+U = N + 1 # 階乗テーブルの上限",
"+comb = fact_N * fact_inv % MOD * fact_inv[::-1] % MOD",
"- answer += cmb(N, x) * cmb(N, y)",
"+ answer += comb[x] * comb[y]"
] | false | 0.199469 | 0.276008 | 0.722696 | [
"s556733635",
"s609964425"
] |
u633450100 | p03713 | python | s884848401 | s280117757 | 366 | 331 | 9,180 | 9,264 | Accepted | Accepted | 9.56 | H,W = [int(i) for i in input().split()]
ans = H * W
for x in range(1,W):
y1 = H // 2
Sa1 = H * x
Sb1 = (W - x) * y1
Sc1 = (W - x) * (H - y1)
M = max(Sa1,Sb1,Sc1)
m = min(Sa1,Sb1,Sc1)
y2 = (W - x) // 2
Sa2 = H * x
Sb2 = H * y2
Sc2 = H * (W - x - y2)
M2 = max(Sa2,Sb2,Sc2)
m2 = min(Sa2,Sb2,Sc2)
if ans > min(M-m,M2-m2):
ans = min(M-m,M2-m2)
H,W = W,H
for x in range(1,W):
y = H // 2
Sa1 = H * x
Sb1 = (W - x) * y
Sc1 = (W - x) * (H - y)
M = max(Sa1,Sb1,Sc1)
m = min(Sa1,Sb1,Sc1)
y2 = (W - x) // 2
Sa2 = H * x
Sb2 = H * y2
Sc2 = H * (W - x - y2)
M2 = max(Sa2,Sb2,Sc2)
m2 = min(Sa2,Sb2,Sc2)
if ans > min(M-m,M2-m2):
ans = min(M-m,M2-m2)
print(ans)
| def answer(H,W,ans_kari):
for x in range(1,W):
y1 = H // 2
Sa1 = H * x
Sb1 = (W - x) * y1
Sc1 = (W - x) * (H - y1)
M = max(Sa1,Sb1,Sc1)
m = min(Sa1,Sb1,Sc1)
y2 = (W - x) // 2
Sa2 = H * x
Sb2 = H * y2
Sc2 = H * (W - x - y2)
M2 = max(Sa2,Sb2,Sc2)
m2 = min(Sa2,Sb2,Sc2)
if ans_kari > min(M-m,M2-m2):
ans_kari = min(M-m,M2-m2)
return ans_kari
if __name__ == '__main__':
H,W = [int(i) for i in input().split()]
ans = H * W
ans = answer(H,W,ans)
H,W = W,H
if answer(H,W,ans) < ans:
ans = answer(H,W,ans)
print(ans)
| 41 | 33 | 811 | 709 | H, W = [int(i) for i in input().split()]
ans = H * W
for x in range(1, W):
y1 = H // 2
Sa1 = H * x
Sb1 = (W - x) * y1
Sc1 = (W - x) * (H - y1)
M = max(Sa1, Sb1, Sc1)
m = min(Sa1, Sb1, Sc1)
y2 = (W - x) // 2
Sa2 = H * x
Sb2 = H * y2
Sc2 = H * (W - x - y2)
M2 = max(Sa2, Sb2, Sc2)
m2 = min(Sa2, Sb2, Sc2)
if ans > min(M - m, M2 - m2):
ans = min(M - m, M2 - m2)
H, W = W, H
for x in range(1, W):
y = H // 2
Sa1 = H * x
Sb1 = (W - x) * y
Sc1 = (W - x) * (H - y)
M = max(Sa1, Sb1, Sc1)
m = min(Sa1, Sb1, Sc1)
y2 = (W - x) // 2
Sa2 = H * x
Sb2 = H * y2
Sc2 = H * (W - x - y2)
M2 = max(Sa2, Sb2, Sc2)
m2 = min(Sa2, Sb2, Sc2)
if ans > min(M - m, M2 - m2):
ans = min(M - m, M2 - m2)
print(ans)
| def answer(H, W, ans_kari):
for x in range(1, W):
y1 = H // 2
Sa1 = H * x
Sb1 = (W - x) * y1
Sc1 = (W - x) * (H - y1)
M = max(Sa1, Sb1, Sc1)
m = min(Sa1, Sb1, Sc1)
y2 = (W - x) // 2
Sa2 = H * x
Sb2 = H * y2
Sc2 = H * (W - x - y2)
M2 = max(Sa2, Sb2, Sc2)
m2 = min(Sa2, Sb2, Sc2)
if ans_kari > min(M - m, M2 - m2):
ans_kari = min(M - m, M2 - m2)
return ans_kari
if __name__ == "__main__":
H, W = [int(i) for i in input().split()]
ans = H * W
ans = answer(H, W, ans)
H, W = W, H
if answer(H, W, ans) < ans:
ans = answer(H, W, ans)
print(ans)
| false | 19.512195 | [
"-H, W = [int(i) for i in input().split()]",
"-ans = H * W",
"-for x in range(1, W):",
"- y1 = H // 2",
"- Sa1 = H * x",
"- Sb1 = (W - x) * y1",
"- Sc1 = (W - x) * (H - y1)",
"- M = max(Sa1, Sb1, Sc1)",
"- m = min(Sa1, Sb1, Sc1)",
"- y2 = (W - x) // 2",
"- Sa2 = H * x",
... | false | 0.596583 | 0.714771 | 0.834648 | [
"s884848401",
"s280117757"
] |
u186838327 | p02888 | python | s019073808 | s994857901 | 833 | 769 | 45,320 | 43,884 | Accepted | Accepted | 7.68 | n = int(eval(input()))
l = list(map(int, input().split()))
l.sort(reverse=True)
m = sorted(l)
#print(l)
# print(m)
import bisect
ans = 0
for i in range(n-2):
a = l[i]
for j in range(i+1,n-1):
b = l[j]
x = a-b
ind = bisect.bisect_right(m,x)
#print(a, b, j, ind)
if n-1-j-ind >= 0:
ans += n-1-j-ind
print(ans)
| n = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
import bisect
ans = 0
for i in range(n-2):
b = L[i]
for j in range(i+1, n-1):
c = L[j]
p = bisect.bisect_left(L, b+c)
#print(b, c, j, p, p-j-1)
ans += max(p-j-1, 0)
print(ans) | 22 | 14 | 357 | 291 | n = int(eval(input()))
l = list(map(int, input().split()))
l.sort(reverse=True)
m = sorted(l)
# print(l)
# print(m)
import bisect
ans = 0
for i in range(n - 2):
a = l[i]
for j in range(i + 1, n - 1):
b = l[j]
x = a - b
ind = bisect.bisect_right(m, x)
# print(a, b, j, ind)
if n - 1 - j - ind >= 0:
ans += n - 1 - j - ind
print(ans)
| n = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
import bisect
ans = 0
for i in range(n - 2):
b = L[i]
for j in range(i + 1, n - 1):
c = L[j]
p = bisect.bisect_left(L, b + c)
# print(b, c, j, p, p-j-1)
ans += max(p - j - 1, 0)
print(ans)
| false | 36.363636 | [
"-l = list(map(int, input().split()))",
"-l.sort(reverse=True)",
"-m = sorted(l)",
"-# print(l)",
"-# print(m)",
"+L = list(map(int, input().split()))",
"+L.sort()",
"- a = l[i]",
"+ b = L[i]",
"- b = l[j]",
"- x = a - b",
"- ind = bisect.bisect_right(m, x)",
"- ... | false | 0.048357 | 0.044551 | 1.085443 | [
"s019073808",
"s994857901"
] |
u814986259 | p02796 | python | s045058446 | s461820828 | 401 | 281 | 21,824 | 26,980 | Accepted | Accepted | 29.93 | N = int(eval(input()))
XL = [tuple(map(int, input().split())) for i in range(N)]
XL.sort(key=lambda x: x[0]+x[1])
right = -10**9
removed = 0
for x, l in XL:
if x-l < right:
removed += 1
else:
right = x+l
print((N-removed))
| N = int(eval(input()))
XL = [tuple(map(int, input().split())) for i in range(N)]
XL.sort(key=lambda x: x[0] + x[1])
ans = 0
prev = - 10**9
for x, l in XL:
if prev <= x - l:
ans += 1
prev = x + l
print(ans)
| 12 | 12 | 251 | 233 | N = int(eval(input()))
XL = [tuple(map(int, input().split())) for i in range(N)]
XL.sort(key=lambda x: x[0] + x[1])
right = -(10**9)
removed = 0
for x, l in XL:
if x - l < right:
removed += 1
else:
right = x + l
print((N - removed))
| N = int(eval(input()))
XL = [tuple(map(int, input().split())) for i in range(N)]
XL.sort(key=lambda x: x[0] + x[1])
ans = 0
prev = -(10**9)
for x, l in XL:
if prev <= x - l:
ans += 1
prev = x + l
print(ans)
| false | 0 | [
"-right = -(10**9)",
"-removed = 0",
"+ans = 0",
"+prev = -(10**9)",
"- if x - l < right:",
"- removed += 1",
"- else:",
"- right = x + l",
"-print((N - removed))",
"+ if prev <= x - l:",
"+ ans += 1",
"+ prev = x + l",
"+print(ans)"
] | false | 0.130826 | 0.059872 | 2.185098 | [
"s045058446",
"s461820828"
] |
u375172966 | p03409 | python | s948338506 | s292159892 | 20 | 18 | 3,064 | 3,064 | Accepted | Accepted | 10 | n = int(eval(input()))
ab = []
cd = []
for _ in range(n):
a, b = list(map(int, input().split()))
ab.append([a, b])
for _ in range(n):
c, d = list(map(int, input().split()))
cd.append([c, d])
cd.sort()
ab.sort(reverse=True, key=lambda x:x[1])
tableA = [False for _ in range(n)]
tableB = [False for _ in range(n)]
ans = 0
for b in range(n):
for r in range(n):
if tableA[r] is True or tableB[b] is True:
continue
if cd[b][0]>ab[r][0] and cd[b][1]>ab[r][1]:
tableA[r] = True
tableB[b] = True
ans += 1
print(ans) | n = int(eval(input()))
R = [list(map(int, input().split())) for _ in range(n)]
B = [list(map(int, input().split())) for _ in range(n)]
R.sort()
B.sort()
pair = []
for bx, by in B:
tmp = [r for r in R if r[0] < bx]
tmp.sort(key=lambda x: x[1])
for rx, ry in tmp[::-1]:
if ry < by:
pair.append([[rx, ry], [bx, by]])
R.pop(R.index([rx, ry]))
break
print((len(pair))) | 23 | 17 | 595 | 429 | n = int(eval(input()))
ab = []
cd = []
for _ in range(n):
a, b = list(map(int, input().split()))
ab.append([a, b])
for _ in range(n):
c, d = list(map(int, input().split()))
cd.append([c, d])
cd.sort()
ab.sort(reverse=True, key=lambda x: x[1])
tableA = [False for _ in range(n)]
tableB = [False for _ in range(n)]
ans = 0
for b in range(n):
for r in range(n):
if tableA[r] is True or tableB[b] is True:
continue
if cd[b][0] > ab[r][0] and cd[b][1] > ab[r][1]:
tableA[r] = True
tableB[b] = True
ans += 1
print(ans)
| n = int(eval(input()))
R = [list(map(int, input().split())) for _ in range(n)]
B = [list(map(int, input().split())) for _ in range(n)]
R.sort()
B.sort()
pair = []
for bx, by in B:
tmp = [r for r in R if r[0] < bx]
tmp.sort(key=lambda x: x[1])
for rx, ry in tmp[::-1]:
if ry < by:
pair.append([[rx, ry], [bx, by]])
R.pop(R.index([rx, ry]))
break
print((len(pair)))
| false | 26.086957 | [
"-ab = []",
"-cd = []",
"-for _ in range(n):",
"- a, b = list(map(int, input().split()))",
"- ab.append([a, b])",
"-for _ in range(n):",
"- c, d = list(map(int, input().split()))",
"- cd.append([c, d])",
"-cd.sort()",
"-ab.sort(reverse=True, key=lambda x: x[1])",
"-tableA = [False fo... | false | 0.046105 | 0.047261 | 0.975543 | [
"s948338506",
"s292159892"
] |
u339199690 | p02996 | python | s220263260 | s639727239 | 1,271 | 851 | 91,352 | 33,968 | Accepted | Accepted | 33.04 | N = int(eval(input()))
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda ab: ab[1])
cnt = 0
for a, b in AB:
if cnt + a <= b:
cnt += a
else:
print("No")
exit()
print("Yes")
| import sys, heapq, bisect, math, fractions
from collections import deque
N = int(eval(input()))
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1])
time = 0
for i in range(N):
time += AB[i][0]
if time > AB[i][1]:
print("No")
exit()
print("Yes") | 13 | 16 | 238 | 315 | N = int(eval(input()))
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda ab: ab[1])
cnt = 0
for a, b in AB:
if cnt + a <= b:
cnt += a
else:
print("No")
exit()
print("Yes")
| import sys, heapq, bisect, math, fractions
from collections import deque
N = int(eval(input()))
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x: x[1])
time = 0
for i in range(N):
time += AB[i][0]
if time > AB[i][1]:
print("No")
exit()
print("Yes")
| false | 18.75 | [
"+import sys, heapq, bisect, math, fractions",
"+from collections import deque",
"+",
"-AB = [list(map(int, input().split())) for _ in range(N)]",
"-AB.sort(key=lambda ab: ab[1])",
"-cnt = 0",
"-for a, b in AB:",
"- if cnt + a <= b:",
"- cnt += a",
"- else:",
"+AB = [tuple(map(int, ... | false | 0.044478 | 0.007741 | 5.745536 | [
"s220263260",
"s639727239"
] |
u444856278 | p03101 | python | s935509249 | s424408835 | 23 | 18 | 3,572 | 2,940 | Accepted | Accepted | 21.74 | [print(f.reduce(o.mul,f.reduce(lambda x,y:[x[0]-y[0],x[1]-y[1]],[[int(i)for i in input().split()],[int(i)for i in input().split()]])))for f,o in[[__import__('functools'),__import__('operator')]]]
| [print((H-h)*(W-w))for H,W,h,w in[map(int,open(0).read().split())]]
| 1 | 1 | 195 | 67 | [
print(
f.reduce(
o.mul,
f.reduce(
lambda x, y: [x[0] - y[0], x[1] - y[1]],
[[int(i) for i in input().split()], [int(i) for i in input().split()]],
),
)
)
for f, o in [[__import__("functools"), __import__("operator")]]
]
| [print((H - h) * (W - w)) for H, W, h, w in [map(int, open(0).read().split())]]
| false | 0 | [
"-[",
"- print(",
"- f.reduce(",
"- o.mul,",
"- f.reduce(",
"- lambda x, y: [x[0] - y[0], x[1] - y[1]],",
"- [[int(i) for i in input().split()], [int(i) for i in input().split()]],",
"- ),",
"- )",
"- )",
"- fo... | false | 0.047992 | 0.047046 | 1.020123 | [
"s935509249",
"s424408835"
] |
u588341295 | p03409 | python | s879213699 | s223304670 | 35 | 24 | 3,444 | 3,192 | Accepted | Accepted | 31.43 | # -*- coding: utf-8 -*-
"""
参考:https://www.hamayanhamayan.com/entry/2018/03/18/085108
http://vartkw.hatenablog.com/entry/2016/12/02/002703
https://ikatakos.com/pot/programming_algorithm/graph_theory/maximum_flow
・二部最大マッチング
・最大流アルゴリズム(Dinic法)
・まだ理解不十分な点はあると思うけど、初めて見た時よりは見慣れた。
"""
from collections import deque
class BipartiteMatching:
def __init__(self, n, m):
self.n = n
self.m = m
# ペアとして有りうる相手を格納する
self.E = [[] * (n+m+2) for i in range(n+m+2)]
# 決まったペアを格納する
self.match = [0] * (n+m+2)
# 距離(付け替え候補を決める時の深さみたいなものが入ってる)
self.dist = [0] * (n+m+2)
def bfs(self):
que = deque()
for i in range(1, self.n+1):
# マッチングの決まっていないノードをキューに詰める
if not self.match[i]:
self.dist[i] = 0
que.append(i)
else:
self.dist[i] = float('inf')
self.dist[0] = float('inf')
while len(que) != 0:
u = que.popleft()
if u != 0:
for v in self.E[u]:
if self.dist[self.match[v]] == float('inf'):
self.dist[self.match[v]] = self.dist[u] + 1
# 付け替えの候補になりうるノードがここで追加されていく
que.append(self.match[v])
# フローを流せるエッジが存在しなければ、dist[0]がINFのまま(Falseを返して終了)
return self.dist[0] != float('inf')
def dfs(self, u):
if u != 0:
for v in self.E[u]:
if self.dist[self.match[v]] == self.dist[u] + 1:
if self.dfs(self.match[v]):
# ペア確定(あとで変わることもある)
self.match[v] = u
self.match[u] = v
return True
# 今回決められなかったノード
self.dist[u] = float('inf')
return False
return True
def add(self, a, b):
b += self.n
self.E[a+1].append(b+1)
self.E[b+1].append(a+1)
def whois(self, x):
return self.match[x+1]-1
def solve(self):
for i in range(self.n+self.m+1):
self.match[i] = 0
res = 0
while self.bfs():
for i in range(1, self.n+1):
# 前から順に繋げる所は繋いでいって、
# もっといいのがあれば後から付け替える
if not self.match[i] and self.dfs(i):
res += 1
return res
N = int(eval(input()))
aN, bN, cN, dN = [0] * N, [0] * N, [0] * N, [0] * N
# 赤い点
for i in range(N):
aN[i], bN[i] = list(map(int, input().split()))
# 青い点
for i in range(N):
cN[i], dN[i] = list(map(int, input().split()))
# (赤い点の数, 青い点の数)
bm = BipartiteMatching(N, N)
for i in range(N):
for j in range(N):
if aN[i] < cN[j] and bN[i] < dN[j]:
# ペア候補として適切な組を追加していく(0-indexed)
bm.add(i, j)
print((bm.solve()))
| # -*- coding: utf-8 -*-
"""
参考:https://ikatakos.com/pot/programming_algorithm/graph_theory/bipartite_matching
・二部最大マッチング
"""
class BipartiteMatching:
"""
XとYの二部グラフの最大マッチング X={0,1,2,...|X|-1} Y={0,1,2,...,|Y|-1}
edges[x]: xとつながるYの頂点のset
match1[x]: xとマッチングされたYの頂点
match2[y]: yとマッチングされたXの頂点
"""
def __init__(self, n, m):
self.n = n
self.m = m
self.edges = [set() for _ in range(n)]
self.match1 = [-1] * n
self.match2 = [-1] * m
def dfs(self, v, visited):
"""
:param v: X側の未マッチングの頂点の1つ
:param visited: 空のsetを渡す(外部からの呼び出し時)
:return: 増大路が見つかればTrue
"""
for u in self.edges[v]:
if u in visited:
continue
visited.add(u)
if self.match2[u] == -1 or self.dfs(self.match2[u], visited):
self.match2[u] = v
self.match1[v] = u
return True
return False
def add(self, a, b):
self.edges[a].add(b)
def whois1(self, a):
""" :param: グループ1の頂点 :return: ペアになるグループ2の頂点 """
return self.match1[a]
def whois2(self, a):
""" :param: グループ2の頂点 :return: ペアになるグループ1の頂点 """
return self.match2[a]
def solve(self):
# 増大路発見に成功したらTrue(=1)。合計することでマッチング数となる
return sum(self.dfs(i, set()) for i in range(self.n))
N = int(eval(input()))
aN, bN, cN, dN = [0] * N, [0] * N, [0] * N, [0] * N
# 赤い点
for i in range(N):
aN[i], bN[i] = list(map(int, input().split()))
# 青い点
for i in range(N):
cN[i], dN[i] = list(map(int, input().split()))
# (赤い点の数, 青い点の数)
bm = BipartiteMatching(N, N)
for i in range(N):
for j in range(N):
if aN[i] < cN[j] and bN[i] < dN[j]:
# ペア候補として適切な組を追加していく(0-indexed)
bm.add(i, j)
print((bm.solve()))
| 97 | 71 | 2,343 | 1,851 | # -*- coding: utf-8 -*-
"""
参考:https://www.hamayanhamayan.com/entry/2018/03/18/085108
http://vartkw.hatenablog.com/entry/2016/12/02/002703
https://ikatakos.com/pot/programming_algorithm/graph_theory/maximum_flow
・二部最大マッチング
・最大流アルゴリズム(Dinic法)
・まだ理解不十分な点はあると思うけど、初めて見た時よりは見慣れた。
"""
from collections import deque
class BipartiteMatching:
def __init__(self, n, m):
self.n = n
self.m = m
# ペアとして有りうる相手を格納する
self.E = [[] * (n + m + 2) for i in range(n + m + 2)]
# 決まったペアを格納する
self.match = [0] * (n + m + 2)
# 距離(付け替え候補を決める時の深さみたいなものが入ってる)
self.dist = [0] * (n + m + 2)
def bfs(self):
que = deque()
for i in range(1, self.n + 1):
# マッチングの決まっていないノードをキューに詰める
if not self.match[i]:
self.dist[i] = 0
que.append(i)
else:
self.dist[i] = float("inf")
self.dist[0] = float("inf")
while len(que) != 0:
u = que.popleft()
if u != 0:
for v in self.E[u]:
if self.dist[self.match[v]] == float("inf"):
self.dist[self.match[v]] = self.dist[u] + 1
# 付け替えの候補になりうるノードがここで追加されていく
que.append(self.match[v])
# フローを流せるエッジが存在しなければ、dist[0]がINFのまま(Falseを返して終了)
return self.dist[0] != float("inf")
def dfs(self, u):
if u != 0:
for v in self.E[u]:
if self.dist[self.match[v]] == self.dist[u] + 1:
if self.dfs(self.match[v]):
# ペア確定(あとで変わることもある)
self.match[v] = u
self.match[u] = v
return True
# 今回決められなかったノード
self.dist[u] = float("inf")
return False
return True
def add(self, a, b):
b += self.n
self.E[a + 1].append(b + 1)
self.E[b + 1].append(a + 1)
def whois(self, x):
return self.match[x + 1] - 1
def solve(self):
for i in range(self.n + self.m + 1):
self.match[i] = 0
res = 0
while self.bfs():
for i in range(1, self.n + 1):
# 前から順に繋げる所は繋いでいって、
# もっといいのがあれば後から付け替える
if not self.match[i] and self.dfs(i):
res += 1
return res
N = int(eval(input()))
aN, bN, cN, dN = [0] * N, [0] * N, [0] * N, [0] * N
# 赤い点
for i in range(N):
aN[i], bN[i] = list(map(int, input().split()))
# 青い点
for i in range(N):
cN[i], dN[i] = list(map(int, input().split()))
# (赤い点の数, 青い点の数)
bm = BipartiteMatching(N, N)
for i in range(N):
for j in range(N):
if aN[i] < cN[j] and bN[i] < dN[j]:
# ペア候補として適切な組を追加していく(0-indexed)
bm.add(i, j)
print((bm.solve()))
| # -*- coding: utf-8 -*-
"""
参考:https://ikatakos.com/pot/programming_algorithm/graph_theory/bipartite_matching
・二部最大マッチング
"""
class BipartiteMatching:
"""
XとYの二部グラフの最大マッチング X={0,1,2,...|X|-1} Y={0,1,2,...,|Y|-1}
edges[x]: xとつながるYの頂点のset
match1[x]: xとマッチングされたYの頂点
match2[y]: yとマッチングされたXの頂点
"""
def __init__(self, n, m):
self.n = n
self.m = m
self.edges = [set() for _ in range(n)]
self.match1 = [-1] * n
self.match2 = [-1] * m
def dfs(self, v, visited):
"""
:param v: X側の未マッチングの頂点の1つ
:param visited: 空のsetを渡す(外部からの呼び出し時)
:return: 増大路が見つかればTrue
"""
for u in self.edges[v]:
if u in visited:
continue
visited.add(u)
if self.match2[u] == -1 or self.dfs(self.match2[u], visited):
self.match2[u] = v
self.match1[v] = u
return True
return False
def add(self, a, b):
self.edges[a].add(b)
def whois1(self, a):
""":param: グループ1の頂点 :return: ペアになるグループ2の頂点"""
return self.match1[a]
def whois2(self, a):
""":param: グループ2の頂点 :return: ペアになるグループ1の頂点"""
return self.match2[a]
def solve(self):
# 増大路発見に成功したらTrue(=1)。合計することでマッチング数となる
return sum(self.dfs(i, set()) for i in range(self.n))
N = int(eval(input()))
aN, bN, cN, dN = [0] * N, [0] * N, [0] * N, [0] * N
# 赤い点
for i in range(N):
aN[i], bN[i] = list(map(int, input().split()))
# 青い点
for i in range(N):
cN[i], dN[i] = list(map(int, input().split()))
# (赤い点の数, 青い点の数)
bm = BipartiteMatching(N, N)
for i in range(N):
for j in range(N):
if aN[i] < cN[j] and bN[i] < dN[j]:
# ペア候補として適切な組を追加していく(0-indexed)
bm.add(i, j)
print((bm.solve()))
| false | 26.804124 | [
"-参考:https://www.hamayanhamayan.com/entry/2018/03/18/085108",
"- http://vartkw.hatenablog.com/entry/2016/12/02/002703",
"- https://ikatakos.com/pot/programming_algorithm/graph_theory/maximum_flow",
"+参考:https://ikatakos.com/pot/programming_algorithm/graph_theory/bipartite_matching",
"-・最大流アルゴリズム(Dinic法)... | false | 0.075327 | 0.066095 | 1.139677 | [
"s879213699",
"s223304670"
] |
u035210736 | p03861 | python | s486311239 | s084458966 | 36 | 29 | 9,988 | 9,100 | Accepted | Accepted | 19.44 | from decimal import *
a, b, x = list(map(int, input().split()))
ax = int(Decimal(a) / Decimal(x))
bx = int(Decimal(b) / Decimal(x))
am = a % x
bm = b % x
if ax == bx and am != 0 and bm != 0:
print((0))
elif am == 0:
print((bx - ax + 1))
else:
print((bx - ax)) | a, b, x = list(map(int, input().split()))
ans = b // x - a // x
if a % x == 0:
ans += 1
print(ans) | 12 | 5 | 264 | 98 | from decimal import *
a, b, x = list(map(int, input().split()))
ax = int(Decimal(a) / Decimal(x))
bx = int(Decimal(b) / Decimal(x))
am = a % x
bm = b % x
if ax == bx and am != 0 and bm != 0:
print((0))
elif am == 0:
print((bx - ax + 1))
else:
print((bx - ax))
| a, b, x = list(map(int, input().split()))
ans = b // x - a // x
if a % x == 0:
ans += 1
print(ans)
| false | 58.333333 | [
"-from decimal import *",
"-",
"-ax = int(Decimal(a) / Decimal(x))",
"-bx = int(Decimal(b) / Decimal(x))",
"-am = a % x",
"-bm = b % x",
"-if ax == bx and am != 0 and bm != 0:",
"- print((0))",
"-elif am == 0:",
"- print((bx - ax + 1))",
"-else:",
"- print((bx - ax))",
"+ans = b // ... | false | 0.037106 | 0.068301 | 0.543277 | [
"s486311239",
"s084458966"
] |
u729679908 | p03455 | python | s658166943 | s109186312 | 31 | 24 | 9,168 | 9,092 | Accepted | Accepted | 22.58 | x = input().split()
a =int(x[0])
b =int(x[1])
if (a*b) % 2:
print("Odd")
else:
print("Even") | x = input().split()
y = int(x[0])*int(x[1])
if y % 2:
print("Odd")
else:
print("Even") | 7 | 6 | 102 | 95 | x = input().split()
a = int(x[0])
b = int(x[1])
if (a * b) % 2:
print("Odd")
else:
print("Even")
| x = input().split()
y = int(x[0]) * int(x[1])
if y % 2:
print("Odd")
else:
print("Even")
| false | 14.285714 | [
"-a = int(x[0])",
"-b = int(x[1])",
"-if (a * b) % 2:",
"+y = int(x[0]) * int(x[1])",
"+if y % 2:"
] | false | 0.04445 | 0.142165 | 0.312666 | [
"s658166943",
"s109186312"
] |
u864013199 | p03163 | python | s545463506 | s897498032 | 451 | 172 | 120,556 | 14,684 | Accepted | Accepted | 61.86 | import sys
input = sys.stdin.readline #文字列入力では注意!
N,W = list(map(int,input().split()))
dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(N):
w,v = list(map(int,input().split()))
for j in range(W+1):
if j+w <= W:
dp[i+1][j+w] = dp[i][j]+v
dp[i+1][j] = max(dp[i+1][j],dp[i][j])
print((dp[N][W]))
| import numpy as np
import sys
input = sys.stdin.readline #文字列入力では注意!
N,W = list(map(int,input().split()))
dp = np.zeros(W+1, dtype=np.int64)
for i in range(N):
w,v = list(map(int,input().split()))
np.maximum(dp[:-w]+v, dp[w:], out = dp[w:])
print((dp[-1]))
| 14 | 12 | 335 | 266 | import sys
input = sys.stdin.readline # 文字列入力では注意!
N, W = list(map(int, input().split()))
dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(N):
w, v = list(map(int, input().split()))
for j in range(W + 1):
if j + w <= W:
dp[i + 1][j + w] = dp[i][j] + v
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print((dp[N][W]))
| import numpy as np
import sys
input = sys.stdin.readline # 文字列入力では注意!
N, W = list(map(int, input().split()))
dp = np.zeros(W + 1, dtype=np.int64)
for i in range(N):
w, v = list(map(int, input().split()))
np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])
print((dp[-1]))
| false | 14.285714 | [
"+import numpy as np",
"-dp = [[0] * (W + 1) for _ in range(N + 1)]",
"+dp = np.zeros(W + 1, dtype=np.int64)",
"- for j in range(W + 1):",
"- if j + w <= W:",
"- dp[i + 1][j + w] = dp[i][j] + v",
"- dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])",
"-print((dp[N][W]))",
"+ ... | false | 0.13794 | 0.424472 | 0.32497 | [
"s545463506",
"s897498032"
] |
u834832056 | p02712 | python | s399401390 | s440124577 | 157 | 117 | 9,116 | 29,728 | Accepted | Accepted | 25.48 | def solve(n):
ans = 0
for i in range(1, n+1):
if (i % 3 == 0 and i % 5 == 0) or (i % 3 == 0) or (i % 5 == 0):
continue
else:
ans += i
print(ans)
if __name__ == "__main__":
n = int(eval(input()))
solve(n) | def solve(n):
arr = [i for i in range(1, n+1) if i % 3 != 0 and i % 5 != 0]
print((sum(arr)))
if __name__ == "__main__":
n = int(eval(input()))
solve(n) | 12 | 7 | 269 | 167 | def solve(n):
ans = 0
for i in range(1, n + 1):
if (i % 3 == 0 and i % 5 == 0) or (i % 3 == 0) or (i % 5 == 0):
continue
else:
ans += i
print(ans)
if __name__ == "__main__":
n = int(eval(input()))
solve(n)
| def solve(n):
arr = [i for i in range(1, n + 1) if i % 3 != 0 and i % 5 != 0]
print((sum(arr)))
if __name__ == "__main__":
n = int(eval(input()))
solve(n)
| false | 41.666667 | [
"- ans = 0",
"- for i in range(1, n + 1):",
"- if (i % 3 == 0 and i % 5 == 0) or (i % 3 == 0) or (i % 5 == 0):",
"- continue",
"- else:",
"- ans += i",
"- print(ans)",
"+ arr = [i for i in range(1, n + 1) if i % 3 != 0 and i % 5 != 0]",
"+ print((su... | false | 0.231116 | 0.191453 | 1.207165 | [
"s399401390",
"s440124577"
] |
u305366205 | p03363 | python | s631763878 | s446207022 | 190 | 172 | 41,472 | 41,728 | Accepted | Accepted | 9.47 | from collections import Counter
N = int(eval(input()))
A = [int(i) for i in input().split()]
cum = [0]
for a in A:
cum.append(cum[-1] + a)
count = Counter(cum)
ans = 0
for v in list(count.values()):
ans += v * (v - 1) // 2
print(ans) | from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
cum = [0]
for a in A:
cum.append(cum[-1] + a)
count = Counter(cum)
ans = 0
for v in list(count.values()):
ans += v * (v - 1) // 2
print(ans)
| 11 | 11 | 239 | 238 | from collections import Counter
N = int(eval(input()))
A = [int(i) for i in input().split()]
cum = [0]
for a in A:
cum.append(cum[-1] + a)
count = Counter(cum)
ans = 0
for v in list(count.values()):
ans += v * (v - 1) // 2
print(ans)
| from collections import Counter
N = int(eval(input()))
A = list(map(int, input().split()))
cum = [0]
for a in A:
cum.append(cum[-1] + a)
count = Counter(cum)
ans = 0
for v in list(count.values()):
ans += v * (v - 1) // 2
print(ans)
| false | 0 | [
"-A = [int(i) for i in input().split()]",
"+A = list(map(int, input().split()))"
] | false | 0.036849 | 0.040674 | 0.905957 | [
"s631763878",
"s446207022"
] |
u155757809 | p03962 | python | s337280686 | s541009885 | 27 | 24 | 9,044 | 8,992 | Accepted | Accepted | 11.11 | l = [ int(x) for x in input().split() ]
l = set(l)
print((len(list(l))))
| l = [ int(x) for x in input().split() ]
print((len(set(l))))
| 3 | 2 | 73 | 60 | l = [int(x) for x in input().split()]
l = set(l)
print((len(list(l))))
| l = [int(x) for x in input().split()]
print((len(set(l))))
| false | 33.333333 | [
"-l = set(l)",
"-print((len(list(l))))",
"+print((len(set(l))))"
] | false | 0.038127 | 0.03866 | 0.986204 | [
"s337280686",
"s541009885"
] |
u970197315 | p02848 | python | s131581412 | s929706426 | 25 | 21 | 3,188 | 3,060 | Accepted | Accepted | 16 | #ABC146 B
si = lambda: eval(input())
ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))
N = ni()
S = si()
# SS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
# SSS = 'NOPQRSTUVWXYZABCDEFGHIJKLM'
S1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'
ans = []
for i,s in enumerate(S) :
idx = S1.find(s)
idx += N
ans.append(S1[idx:idx+1])
aans = ''
for a in ans:
aans += a
print(aans) | # B
si = lambda: eval(input())
ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))
n=ni()
s=si()
ans=''
for ss in s:
ans+=chr((ord(ss)+n-65)%26+65)
print(ans)
| 24 | 12 | 468 | 228 | # ABC146 B
si = lambda: eval(input())
ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))
N = ni()
S = si()
# SS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
# SSS = 'NOPQRSTUVWXYZABCDEFGHIJKLM'
S1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
ans = []
for i, s in enumerate(S):
idx = S1.find(s)
idx += N
ans.append(S1[idx : idx + 1])
aans = ""
for a in ans:
aans += a
print(aans)
| # B
si = lambda: eval(input())
ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))
n = ni()
s = si()
ans = ""
for ss in s:
ans += chr((ord(ss) + n - 65) % 26 + 65)
print(ans)
| false | 50 | [
"-# ABC146 B",
"+# B",
"-N = ni()",
"-S = si()",
"-# SS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'",
"-# SSS = 'NOPQRSTUVWXYZABCDEFGHIJKLM'",
"-S1 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ\"",
"-ans = []",
"-for i, s in enumerate(S):",
"- idx = S1.find(s)",
"- idx += N",
"- ans.app... | false | 0.034412 | 0.040082 | 0.85854 | [
"s131581412",
"s929706426"
] |
u693933222 | p03416 | python | s956429611 | s602557576 | 75 | 50 | 2,940 | 2,940 | Accepted | Accepted | 33.33 | a,b = list(map(int,input().split()))
ans = 0
for i in range(a,b+1):
li = list(str(i))
if(li[0] == li[4] and li[1] == li[3]):
ans += 1
print(ans) | a, b = list(map(int, input().split()))
ans = 0
for i in range(a, b + 1):
val = str(i)
if (val[0] == val[4] and val[1] == val[3]):
ans += 1
print(ans) | 10 | 9 | 174 | 169 | a, b = list(map(int, input().split()))
ans = 0
for i in range(a, b + 1):
li = list(str(i))
if li[0] == li[4] and li[1] == li[3]:
ans += 1
print(ans)
| a, b = list(map(int, input().split()))
ans = 0
for i in range(a, b + 1):
val = str(i)
if val[0] == val[4] and val[1] == val[3]:
ans += 1
print(ans)
| false | 10 | [
"- li = list(str(i))",
"- if li[0] == li[4] and li[1] == li[3]:",
"+ val = str(i)",
"+ if val[0] == val[4] and val[1] == val[3]:"
] | false | 0.175611 | 0.116061 | 1.513097 | [
"s956429611",
"s602557576"
] |
u389910364 | p03801 | python | s561172878 | s917998235 | 1,046 | 271 | 32,544 | 24,048 | Accepted | Accepted | 74.09 | import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
class BinaryIndexedTree:
# http://hos.ac/slides/20140319_bit.pdf
def __init__(self, size):
"""
:param int size:
"""
self._bit = [0] * size
self._size = size
def add(self, i, w):
"""
i 番目に w を加える
:param int i:
:param int w:
:return:
"""
x = i + 1
while x <= self._size:
self._bit[x - 1] += w
x += x & -x
def sum(self, i):
"""
0 番目から i 番目までの合計
:param int i:
:return:
"""
ret = 0
x = i + 1
while x > 0:
ret += self._bit[x - 1]
x -= x & -x
return ret
def __len__(self):
return self._size
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
A = np.array(A, dtype=int)
ans = np.zeros(N, dtype=int)
# for i in range(N):
# if A[i] <= 0:
# continue
# ans[i] = np.minimum(A, A[i]).sum()
# A = np.maximum(0, A - A[i])
# print(ans)
counts = Counter(A)
counts[0] = 0
counts[IINF] = 0
keys = list(sorted(counts.keys()))
ki = 0
cnt = 0
s = 0
for i in range(N):
if A[i] - s <= 0:
continue
m = A[i]
# s 以上 m 以下のやつの合計
p = s
while keys[ki] <= m:
ans[i] += (keys[ki] - p) * (N - cnt)
p = keys[ki]
cnt += counts[keys[ki]]
ki += 1
s = A[i]
print(*ans, sep='\n')
# [10 7 0 4 0 3 0 2 3 0]
| import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
XY = [(a, i) for i, a in enumerate(A)]
XY.sort(reverse=True)
# 解説
ans = [0] * N
min_y = IINF
for i, (x, y) in enumerate(XY):
min_y = min(min_y, y)
x2 = XY[i + 1][0] if i + 1 < N else 0
ans[min_y] += (x - x2) * (i + 1)
print(*ans, sep='\n')
| 101 | 25 | 2,054 | 528 | import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
class BinaryIndexedTree:
# http://hos.ac/slides/20140319_bit.pdf
def __init__(self, size):
"""
:param int size:
"""
self._bit = [0] * size
self._size = size
def add(self, i, w):
"""
i 番目に w を加える
:param int i:
:param int w:
:return:
"""
x = i + 1
while x <= self._size:
self._bit[x - 1] += w
x += x & -x
def sum(self, i):
"""
0 番目から i 番目までの合計
:param int i:
:return:
"""
ret = 0
x = i + 1
while x > 0:
ret += self._bit[x - 1]
x -= x & -x
return ret
def __len__(self):
return self._size
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
A = np.array(A, dtype=int)
ans = np.zeros(N, dtype=int)
# for i in range(N):
# if A[i] <= 0:
# continue
# ans[i] = np.minimum(A, A[i]).sum()
# A = np.maximum(0, A - A[i])
# print(ans)
counts = Counter(A)
counts[0] = 0
counts[IINF] = 0
keys = list(sorted(counts.keys()))
ki = 0
cnt = 0
s = 0
for i in range(N):
if A[i] - s <= 0:
continue
m = A[i]
# s 以上 m 以下のやつの合計
p = s
while keys[ki] <= m:
ans[i] += (keys[ki] - p) * (N - cnt)
p = keys[ki]
cnt += counts[keys[ki]]
ki += 1
s = A[i]
print(*ans, sep="\n")
# [10 7 0 4 0 3 0 2 3 0]
| import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
XY = [(a, i) for i, a in enumerate(A)]
XY.sort(reverse=True)
# 解説
ans = [0] * N
min_y = IINF
for i, (x, y) in enumerate(XY):
min_y = min(min_y, y)
x2 = XY[i + 1][0] if i + 1 < N else 0
ans[min_y] += (x - x2) * (i + 1)
print(*ans, sep="\n")
| false | 75.247525 | [
"-import bisect",
"-import heapq",
"-import itertools",
"-import math",
"-import operator",
"-import re",
"-import string",
"-from collections import Counter, deque, defaultdict",
"-from copy import deepcopy",
"-from decimal import Decimal",
"-from fractions import gcd",
"-from functools impor... | false | 0.278692 | 0.041525 | 6.711353 | [
"s561172878",
"s917998235"
] |
u112364985 | p02659 | python | s999852510 | s565802236 | 142 | 25 | 71,584 | 10,084 | Accepted | Accepted | 82.39 | import math
from decimal import Decimal
a,b=input().split()
a=int(a)
new_a=Decimal(a)
new_b=Decimal(b)
print((math.floor(new_a*new_b))) | import math
from decimal import Decimal
a,b=input().split()
new_a=Decimal(a)
new_b=Decimal(b)
print((math.floor(new_a*new_b))) | 7 | 6 | 139 | 129 | import math
from decimal import Decimal
a, b = input().split()
a = int(a)
new_a = Decimal(a)
new_b = Decimal(b)
print((math.floor(new_a * new_b)))
| import math
from decimal import Decimal
a, b = input().split()
new_a = Decimal(a)
new_b = Decimal(b)
print((math.floor(new_a * new_b)))
| false | 14.285714 | [
"-a = int(a)"
] | false | 0.039258 | 0.045348 | 0.865718 | [
"s999852510",
"s565802236"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.