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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u077291787 | p03044 | python | s189557664 | s852876281 | 436 | 267 | 42,796 | 126,100 | Accepted | Accepted | 38.76 | # ABC126D - Even Relation
def dfs(r: int) -> None:
stack = [r]
while stack:
v = stack.pop()
for u, w in T[v]:
if D[u] == -1:
D[u] = (D[v] + w) % 2
stack += [u]
def main():
global T, D
N, *A = map(int, open(0).read().split())
T = [[] for _ in range(N + 1)]
for i in range(0, (N - 1) * 3, 3):
v, u, w = A[i : i + 3]
T[v] += [(u, w)]
T[u] += [(v, w)]
D = [-1] * (N + 1) # D[i] := parity of distance from vertex 1 (root)
D[1] = 0
dfs(1)
print(*D[1:], sep="\n")
if __name__ == "__main__":
main()
| # D - Even Relation
from typing import List, Tuple
def main():
N, *X = list(map(int, open(0).read().split()))
tree: List[List[Tuple[int, int]]] = [[] for _ in range(N + 1)]
for u, v, w in zip(*[iter(X)] * 3):
w %= 2
tree[u].append((v, w)), tree[v].append((u, w))
color = [-1] * (N + 1)
color[1] = 1
stack = [1]
while stack:
u = stack.pop()
cur = color[u]
for v, w in tree[u]:
if color[v] != -1:
continue
color[v] = cur ^ w
stack.append(v)
print(("\n".join(map(str, color[1:]))))
if __name__ == "__main__":
main()
| 27 | 28 | 650 | 666 | # ABC126D - Even Relation
def dfs(r: int) -> None:
stack = [r]
while stack:
v = stack.pop()
for u, w in T[v]:
if D[u] == -1:
D[u] = (D[v] + w) % 2
stack += [u]
def main():
global T, D
N, *A = map(int, open(0).read().split())
T = [[] for _ in range(N + 1)]
for i in range(0, (N - 1) * 3, 3):
v, u, w = A[i : i + 3]
T[v] += [(u, w)]
T[u] += [(v, w)]
D = [-1] * (N + 1) # D[i] := parity of distance from vertex 1 (root)
D[1] = 0
dfs(1)
print(*D[1:], sep="\n")
if __name__ == "__main__":
main()
| # D - Even Relation
from typing import List, Tuple
def main():
N, *X = list(map(int, open(0).read().split()))
tree: List[List[Tuple[int, int]]] = [[] for _ in range(N + 1)]
for u, v, w in zip(*[iter(X)] * 3):
w %= 2
tree[u].append((v, w)), tree[v].append((u, w))
color = [-1] * (N + 1)
color[1] = 1
stack = [1]
while stack:
u = stack.pop()
cur = color[u]
for v, w in tree[u]:
if color[v] != -1:
continue
color[v] = cur ^ w
stack.append(v)
print(("\n".join(map(str, color[1:]))))
if __name__ == "__main__":
main()
| false | 3.571429 | [
"-# ABC126D - Even Relation",
"-def dfs(r: int) -> None:",
"- stack = [r]",
"- while stack:",
"- v = stack.pop()",
"- for u, w in T[v]:",
"- if D[u] == -1:",
"- D[u] = (D[v] + w) % 2",
"- stack += [u]",
"+# D - Even Relation",
"+from t... | false | 0.038515 | 0.057193 | 0.673429 | [
"s189557664",
"s852876281"
] |
u481187938 | p02888 | python | s245003855 | s690998898 | 1,655 | 146 | 83,504 | 73,276 | Accepted | Accepted | 91.18 | #!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools
import math, fractions
import sys, copy
def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(1000000)
def main():
N = I()
L = sorted(LI())
ans = 0
for i in range(N):
for j in range(i+1, N):
a, b = L[i], L[j]
# print(L[j+1:], abs(a - b), a+b, bisect_left(L[j+1:], abs(a - b)), bisect_left(L[j+1:], a + b))
ans += bisect_left(L[j+1:], a + b) - bisect_left(L[j+1:], abs(a - b))
print(ans)
if __name__ == '__main__':
main() | #!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools
import math, fractions
import sys, copy
def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(1000000)
def main():
N = I()
L = sorted(LI())
ans = 0
for i in range(N):
k = i
for j in range(i+1, N):
while k < N and L[k] < L[i] + L[j]: k += 1
ans += k - (j + 1)
print(ans)
if __name__ == '__main__':
main() | 53 | 53 | 1,960 | 1,839 | #!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools
import math, fractions
import sys, copy
def L():
return sys.stdin.readline().split()
def I():
return int(sys.stdin.readline().rstrip())
def SL():
return list(sys.stdin.readline().rstrip())
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI1():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def R(n):
return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n):
return [L() for _ in range(n)]
def IR(n):
return [I() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
def LIR1(n):
return [LI1() for _ in range(n)]
def SR(n):
return [SL() for _ in range(n)]
def LSR(n):
return [LS() for _ in range(n)]
def perm(n, r):
return math.factorial(n) // math.factorial(r)
def comb(n, r):
return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))
def make_list(n, *args, default=0):
return (
[make_list(*args, default=default) for _ in range(n)]
if len(args) > 0
else [default for _ in range(n)]
)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(1000000)
def main():
N = I()
L = sorted(LI())
ans = 0
for i in range(N):
for j in range(i + 1, N):
a, b = L[i], L[j]
# print(L[j+1:], abs(a - b), a+b, bisect_left(L[j+1:], abs(a - b)), bisect_left(L[j+1:], a + b))
ans += bisect_left(L[j + 1 :], a + b) - bisect_left(L[j + 1 :], abs(a - b))
print(ans)
if __name__ == "__main__":
main()
| #!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools
import math, fractions
import sys, copy
def L():
return sys.stdin.readline().split()
def I():
return int(sys.stdin.readline().rstrip())
def SL():
return list(sys.stdin.readline().rstrip())
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI1():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def R(n):
return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n):
return [L() for _ in range(n)]
def IR(n):
return [I() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
def LIR1(n):
return [LI1() for _ in range(n)]
def SR(n):
return [SL() for _ in range(n)]
def LSR(n):
return [LS() for _ in range(n)]
def perm(n, r):
return math.factorial(n) // math.factorial(r)
def comb(n, r):
return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))
def make_list(n, *args, default=0):
return (
[make_list(*args, default=default) for _ in range(n)]
if len(args) > 0
else [default for _ in range(n)]
)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(1000000)
def main():
N = I()
L = sorted(LI())
ans = 0
for i in range(N):
k = i
for j in range(i + 1, N):
while k < N and L[k] < L[i] + L[j]:
k += 1
ans += k - (j + 1)
print(ans)
if __name__ == "__main__":
main()
| false | 0 | [
"+ k = i",
"- a, b = L[i], L[j]",
"- # print(L[j+1:], abs(a - b), a+b, bisect_left(L[j+1:], abs(a - b)), bisect_left(L[j+1:], a + b))",
"- ans += bisect_left(L[j + 1 :], a + b) - bisect_left(L[j + 1 :], abs(a - b))",
"+ while k < N and L[k] < L[i] + L[j]:",... | false | 0.079008 | 0.068213 | 1.158253 | [
"s245003855",
"s690998898"
] |
u690536347 | p02990 | python | s249826021 | s533995073 | 468 | 28 | 3,444 | 3,444 | Accepted | Accepted | 94.02 | N, K = list(map(int, input().split()))
mod = 10**9+7
fac = [1]*(N+1)
rev = [1]*(N+1)
for i in range(1,N+1):
fac[i] = i*fac[i-1]%mod
rev[i] = pow(fac[i], mod-2, mod)
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%mod
for i in range(1, K+1):
v1 = comb(K-1, i-1)
v2 = 0
if i == 1:
v2 = N-K+1
else:
for j in range(i-1, N-K+1):
v2 += comb(j-1, i-2) * (N-K-j+1)
print(((v1*v2)%mod)) | N, K = list(map(int, input().split()))
mod = 10**9+7
fac = [1]*(N+1)
rev = [1]*(N+1)
for i in range(1,N+1):
fac[i] = i*fac[i-1]%mod
rev[i] = pow(fac[i], mod-2, mod)
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%mod
for i in range(1, K+1):
ans = (comb(K-1, i-1)*comb(N-K+1, i))%mod if N-K+1>=i else 0
print(ans) | 22 | 14 | 444 | 331 | N, K = list(map(int, input().split()))
mod = 10**9 + 7
fac = [1] * (N + 1)
rev = [1] * (N + 1)
for i in range(1, N + 1):
fac[i] = i * fac[i - 1] % mod
rev[i] = pow(fac[i], mod - 2, mod)
comb = lambda a, b: (fac[a] * rev[a - b] * rev[b]) % mod
for i in range(1, K + 1):
v1 = comb(K - 1, i - 1)
v2 = 0
if i == 1:
v2 = N - K + 1
else:
for j in range(i - 1, N - K + 1):
v2 += comb(j - 1, i - 2) * (N - K - j + 1)
print(((v1 * v2) % mod))
| N, K = list(map(int, input().split()))
mod = 10**9 + 7
fac = [1] * (N + 1)
rev = [1] * (N + 1)
for i in range(1, N + 1):
fac[i] = i * fac[i - 1] % mod
rev[i] = pow(fac[i], mod - 2, mod)
comb = lambda a, b: (fac[a] * rev[a - b] * rev[b]) % mod
for i in range(1, K + 1):
ans = (comb(K - 1, i - 1) * comb(N - K + 1, i)) % mod if N - K + 1 >= i else 0
print(ans)
| false | 36.363636 | [
"- v1 = comb(K - 1, i - 1)",
"- v2 = 0",
"- if i == 1:",
"- v2 = N - K + 1",
"- else:",
"- for j in range(i - 1, N - K + 1):",
"- v2 += comb(j - 1, i - 2) * (N - K - j + 1)",
"- print(((v1 * v2) % mod))",
"+ ans = (comb(K - 1, i - 1) * comb(N - K + 1, i)) %... | false | 0.107614 | 0.037702 | 2.854315 | [
"s249826021",
"s533995073"
] |
u119983020 | p03478 | python | s122177262 | s090307219 | 34 | 29 | 3,060 | 3,060 | Accepted | Accepted | 14.71 | N, A, B = list(map(int,input().split()))
sum = 0
for num in range(1,N+1):
digit_sum = 0
num_temp = num
while num_temp > 0:
digit_sum += num_temp%10
num_temp = int(num_temp/10)
if (A <= digit_sum) and (digit_sum <= B):
sum += num
print(sum) | N,A,B = list(map(int, input().split()))
def find_sum_of_digit(n):
sum = 0
while True:
sum += n%10
n = int(n/10)
if n == 0:
break
return sum
ans = 0
for i in range(1,N+1):
a = find_sum_of_digit(i)
if a>=A and a<=B:
ans += i
print(ans) | 11 | 15 | 263 | 305 | N, A, B = list(map(int, input().split()))
sum = 0
for num in range(1, N + 1):
digit_sum = 0
num_temp = num
while num_temp > 0:
digit_sum += num_temp % 10
num_temp = int(num_temp / 10)
if (A <= digit_sum) and (digit_sum <= B):
sum += num
print(sum)
| N, A, B = list(map(int, input().split()))
def find_sum_of_digit(n):
sum = 0
while True:
sum += n % 10
n = int(n / 10)
if n == 0:
break
return sum
ans = 0
for i in range(1, N + 1):
a = find_sum_of_digit(i)
if a >= A and a <= B:
ans += i
print(ans)
| false | 26.666667 | [
"-sum = 0",
"-for num in range(1, N + 1):",
"- digit_sum = 0",
"- num_temp = num",
"- while num_temp > 0:",
"- digit_sum += num_temp % 10",
"- num_temp = int(num_temp / 10)",
"- if (A <= digit_sum) and (digit_sum <= B):",
"- sum += num",
"-print(sum)",
"+",
"+"... | false | 0.043291 | 0.093132 | 0.464832 | [
"s122177262",
"s090307219"
] |
u434872492 | p02972 | python | s077295207 | s228429049 | 523 | 160 | 14,140 | 107,520 | Accepted | Accepted | 69.41 | N=int(eval(input()))
a=list(map(int,input().split()))
res=[0]*(N+1)
for i in range(1,N+1)[::-1]:
sum_res=sum(res[x] for x in range(i,N+1,i))
if sum_res % 2!=a[i-1]:
res[i] = 1
print((sum(res)))
if sum(res):
ans=[]
for i,ele in enumerate(res):
if ele:
ans.append(i)
print((*ans)) | N = int(eval(input()))
A = list(map(int,input().split()))
ans = [0 for i in range(N)]
for i in range(N-1,-1,-1):
val = i+1
if val*2>N:
if A[i]==0:
ans[i] = 0
else:
ans[i] = 1
else:
tmp = 0
res = val
while(1):
if val>N:
break
tmp += ans[val-1]
val += res
if A[i]==0:
if tmp%2==0:
ans[i]=0
else:
ans[i]=1
else:
if tmp%2==0:
ans[i]=1
else:
ans[i]=0
#print(*ans)
cnt = 0
b=[]
for i in range(N):
if ans[i]==0:
continue
cnt += 1
b.append(i+1)
print(cnt)
print((*b))
| 17 | 41 | 335 | 771 | N = int(eval(input()))
a = list(map(int, input().split()))
res = [0] * (N + 1)
for i in range(1, N + 1)[::-1]:
sum_res = sum(res[x] for x in range(i, N + 1, i))
if sum_res % 2 != a[i - 1]:
res[i] = 1
print((sum(res)))
if sum(res):
ans = []
for i, ele in enumerate(res):
if ele:
ans.append(i)
print((*ans))
| N = int(eval(input()))
A = list(map(int, input().split()))
ans = [0 for i in range(N)]
for i in range(N - 1, -1, -1):
val = i + 1
if val * 2 > N:
if A[i] == 0:
ans[i] = 0
else:
ans[i] = 1
else:
tmp = 0
res = val
while 1:
if val > N:
break
tmp += ans[val - 1]
val += res
if A[i] == 0:
if tmp % 2 == 0:
ans[i] = 0
else:
ans[i] = 1
else:
if tmp % 2 == 0:
ans[i] = 1
else:
ans[i] = 0
# print(*ans)
cnt = 0
b = []
for i in range(N):
if ans[i] == 0:
continue
cnt += 1
b.append(i + 1)
print(cnt)
print((*b))
| false | 58.536585 | [
"-a = list(map(int, input().split()))",
"-res = [0] * (N + 1)",
"-for i in range(1, N + 1)[::-1]:",
"- sum_res = sum(res[x] for x in range(i, N + 1, i))",
"- if sum_res % 2 != a[i - 1]:",
"- res[i] = 1",
"-print((sum(res)))",
"-if sum(res):",
"- ans = []",
"- for i, ele in enume... | false | 0.065475 | 0.090727 | 0.721672 | [
"s077295207",
"s228429049"
] |
u439063038 | p03167 | python | s687954276 | s175977862 | 904 | 577 | 49,236 | 51,216 | Accepted | Accepted | 36.17 | MOD = 10**9+7
H, W = list(map(int, input().split()))
a = [eval(input()) for _ in range(H)]
dp = [[0] * W for _ in range(H)]
dp[0][0] = 1
for i in range(H):
for j in range(W):
if j+1 < W:
if a[i][j+1] != '#':
dp[i][j+1] += dp[i][j] % MOD
if i+1 < H:
if a[i+1][j] != '#':
dp[i+1][j] += dp[i][j] % MOD
print((dp[H-1][W-1] % MOD)) | H, W = list(map(int, input().split()))
a = [eval(input()) for _ in range(H)]
MOD = 10**9 + 7
dp = [[0]*1100 for _ in range(1100)]
dp[1][1] = 1
for h in range(1, H+1):
for w in range(1, W+1):
if h == 1 and w == 1:
continue
if a[h-1][w-1] == '#':
dp[h][w] = 0
else:
dp[h][w] += (dp[h-1][w] + dp[h][w-1]) % MOD
print((dp[H][W] % MOD)) | 16 | 15 | 417 | 396 | MOD = 10**9 + 7
H, W = list(map(int, input().split()))
a = [eval(input()) for _ in range(H)]
dp = [[0] * W for _ in range(H)]
dp[0][0] = 1
for i in range(H):
for j in range(W):
if j + 1 < W:
if a[i][j + 1] != "#":
dp[i][j + 1] += dp[i][j] % MOD
if i + 1 < H:
if a[i + 1][j] != "#":
dp[i + 1][j] += dp[i][j] % MOD
print((dp[H - 1][W - 1] % MOD))
| H, W = list(map(int, input().split()))
a = [eval(input()) for _ in range(H)]
MOD = 10**9 + 7
dp = [[0] * 1100 for _ in range(1100)]
dp[1][1] = 1
for h in range(1, H + 1):
for w in range(1, W + 1):
if h == 1 and w == 1:
continue
if a[h - 1][w - 1] == "#":
dp[h][w] = 0
else:
dp[h][w] += (dp[h - 1][w] + dp[h][w - 1]) % MOD
print((dp[H][W] % MOD))
| false | 6.25 | [
"-MOD = 10**9 + 7",
"-dp = [[0] * W for _ in range(H)]",
"-dp[0][0] = 1",
"-for i in range(H):",
"- for j in range(W):",
"- if j + 1 < W:",
"- if a[i][j + 1] != \"#\":",
"- dp[i][j + 1] += dp[i][j] % MOD",
"- if i + 1 < H:",
"- if a[i + 1][j] !... | false | 0.046872 | 0.04764 | 0.983886 | [
"s687954276",
"s175977862"
] |
u593567568 | p02913 | python | s293346555 | s596112272 | 753 | 154 | 51,780 | 5,008 | Accepted | Accepted | 79.55 | import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# 文字列アルゴリズム
# Z-Algorithm
# ZAlgorithm
# AC
N = int(eval(input()))
S = list(eval(input()))
ans = 0
def Z_Algorithm(S):
L = len(S)
Z = [0] * L
Z[0] = L
i = 1
j = 0
while i < L:
# 同じなら引き伸ばす
# 前回のjを引き継ぐ
while i + j < L and S[j] == S[i + j]:
j += 1
Z[i] = j
# j = 0なら次
if j == 0:
i += 1
continue
# 同じ数字分横にずらす
# 右にそれ以上の文字があればcontinue
k = 1
while k < j and k + Z[k] < j:
Z[i + k] = Z[k]
k += 1
i += k
j -= k
return Z
ans = 0
for i in range(N):
Z = Z_Algorithm(S[i:])
L = len(Z)
for j in range(1, L):
l = min(Z[j], j)
ans = max(l, ans)
print(ans)
| import sys
import random
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# 文字列アルゴリズム
# RollingHash
# ローリングハッシュ
# 64bit 溢れないように
class RollingHash:
MASK30 = (1 << 30) - 1
MASK31 = (1 << 31) - 1
MOD = (1 << 61) - 1
POSITVIZER = MOD * ((1 << 3) - 1)
def __init__(self, S):
# 事前計算
Base = random.randrange(129, (1 << 61) - 1)
self.Base = Base
L = len(S)
powMemo = [0] * (L + 1)
rhash = [0] * (L + 1)
powMemo[0] = 1
for i in range(1, L + 1):
powMemo[i] = self.calcMod(self.Mul(powMemo[i - 1], Base))
for i in range(L):
rhash[i + 1] = self.calcMod(self.Mul(rhash[i], Base) + ord(S[i]))
self.powMemo = powMemo
self.rhash = rhash
def getHash(self, begin, length):
r = self.calcMod(
self.rhash[begin + length]
+ self.POSITVIZER
- self.Mul(self.rhash[begin], self.powMemo[length])
)
return r
def Mul(self, l, r):
lu = l >> 31
ld = l & self.MASK31
ru = r >> 31
rd = r & self.MASK31
middle = ld * ru + lu * rd
return (
((lu * ru) << 1) + ld * rd + ((middle & self.MASK30) << 31) + (middle >> 30)
)
def calcMod(self, val):
val = (val & self.MOD) + (val >> 61)
if self.MOD <= val:
val -= self.MOD
return val
N = int(eval(input()))
S = eval(input())
RH = RollingHash(S)
def check(n, RH):
ret = False
cnt = defaultdict(int)
for i in range(0, N - n + 1):
h = RH.getHash(i, n)
if not cnt[h]:
cnt[h] = i + 1
else:
f = cnt[h]
if f + n <= i + 1:
ret = True
break
return ret
l = 0 # OK
r = (N // 2) + 1 # NG
while (r - l) != 1:
mid = (l + r) // 2
if check(mid, RH):
l = mid
else:
r = mid
print(l)
| 63 | 101 | 967 | 2,156 | import sys
sys.setrecursionlimit(10**7)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# 文字列アルゴリズム
# Z-Algorithm
# ZAlgorithm
# AC
N = int(eval(input()))
S = list(eval(input()))
ans = 0
def Z_Algorithm(S):
L = len(S)
Z = [0] * L
Z[0] = L
i = 1
j = 0
while i < L:
# 同じなら引き伸ばす
# 前回のjを引き継ぐ
while i + j < L and S[j] == S[i + j]:
j += 1
Z[i] = j
# j = 0なら次
if j == 0:
i += 1
continue
# 同じ数字分横にずらす
# 右にそれ以上の文字があればcontinue
k = 1
while k < j and k + Z[k] < j:
Z[i + k] = Z[k]
k += 1
i += k
j -= k
return Z
ans = 0
for i in range(N):
Z = Z_Algorithm(S[i:])
L = len(Z)
for j in range(1, L):
l = min(Z[j], j)
ans = max(l, ans)
print(ans)
| import sys
import random
from collections import defaultdict
sys.setrecursionlimit(10**7)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# 文字列アルゴリズム
# RollingHash
# ローリングハッシュ
# 64bit 溢れないように
class RollingHash:
MASK30 = (1 << 30) - 1
MASK31 = (1 << 31) - 1
MOD = (1 << 61) - 1
POSITVIZER = MOD * ((1 << 3) - 1)
def __init__(self, S):
# 事前計算
Base = random.randrange(129, (1 << 61) - 1)
self.Base = Base
L = len(S)
powMemo = [0] * (L + 1)
rhash = [0] * (L + 1)
powMemo[0] = 1
for i in range(1, L + 1):
powMemo[i] = self.calcMod(self.Mul(powMemo[i - 1], Base))
for i in range(L):
rhash[i + 1] = self.calcMod(self.Mul(rhash[i], Base) + ord(S[i]))
self.powMemo = powMemo
self.rhash = rhash
def getHash(self, begin, length):
r = self.calcMod(
self.rhash[begin + length]
+ self.POSITVIZER
- self.Mul(self.rhash[begin], self.powMemo[length])
)
return r
def Mul(self, l, r):
lu = l >> 31
ld = l & self.MASK31
ru = r >> 31
rd = r & self.MASK31
middle = ld * ru + lu * rd
return (
((lu * ru) << 1) + ld * rd + ((middle & self.MASK30) << 31) + (middle >> 30)
)
def calcMod(self, val):
val = (val & self.MOD) + (val >> 61)
if self.MOD <= val:
val -= self.MOD
return val
N = int(eval(input()))
S = eval(input())
RH = RollingHash(S)
def check(n, RH):
ret = False
cnt = defaultdict(int)
for i in range(0, N - n + 1):
h = RH.getHash(i, n)
if not cnt[h]:
cnt[h] = i + 1
else:
f = cnt[h]
if f + n <= i + 1:
ret = True
break
return ret
l = 0 # OK
r = (N // 2) + 1 # NG
while (r - l) != 1:
mid = (l + r) // 2
if check(mid, RH):
l = mid
else:
r = mid
print(l)
| false | 37.623762 | [
"+import random",
"+from collections import defaultdict",
"-# Z-Algorithm",
"-# ZAlgorithm",
"-# AC",
"-N = int(eval(input()))",
"-S = list(eval(input()))",
"-ans = 0",
"+# RollingHash",
"+# ローリングハッシュ",
"+# 64bit 溢れないように",
"+class RollingHash:",
"+ MASK30 = (1 << 30) - 1",
"+ MASK31 ... | false | 0.115853 | 0.034272 | 3.380402 | [
"s293346555",
"s596112272"
] |
u739721456 | p03478 | python | s729088227 | s731148638 | 82 | 39 | 3,060 | 2,940 | Accepted | Accepted | 52.44 | def sums(n):
return(sum(list(map(int,[str(n)[i] for i in range(len(str(n)))]))))
n,a,b=list(map(int,input().split()))
ans=0
for j in range(n+1):
if sums(j)>=a and sums(j)<=b:
ans+=j
print(ans)
| n,a,b=list(map(int,input().split()))
ans=0
for i in range(1,n+1):
i=str(i)
m=0
for j in range(len(i)):
m+=int(i[j])
if m>=a and m<=b:
ans+=int(i)
print(ans)
| 11 | 12 | 216 | 196 | def sums(n):
return sum(list(map(int, [str(n)[i] for i in range(len(str(n)))])))
n, a, b = list(map(int, input().split()))
ans = 0
for j in range(n + 1):
if sums(j) >= a and sums(j) <= b:
ans += j
print(ans)
| n, a, b = list(map(int, input().split()))
ans = 0
for i in range(1, n + 1):
i = str(i)
m = 0
for j in range(len(i)):
m += int(i[j])
if m >= a and m <= b:
ans += int(i)
print(ans)
| false | 8.333333 | [
"-def sums(n):",
"- return sum(list(map(int, [str(n)[i] for i in range(len(str(n)))])))",
"-",
"-",
"-for j in range(n + 1):",
"- if sums(j) >= a and sums(j) <= b:",
"- ans += j",
"+for i in range(1, n + 1):",
"+ i = str(i)",
"+ m = 0",
"+ for j in range(len(i)):",
"+ ... | false | 0.037494 | 0.036673 | 1.022396 | [
"s729088227",
"s731148638"
] |
u186838327 | p03831 | python | s504443255 | s214854987 | 222 | 96 | 62,704 | 84,712 | Accepted | Accepted | 56.76 | n, a, b = list(map(int, input().split()))
l = list(map(int, input().split()))
ans = 0
for i in range(n-1):
if (l[i+1]-l[i])*a <= b:
ans += (l[i+1]-l[i])*a
else:
ans += b
print(ans) | n, a, b = list(map(int, input().split()))
X = list(map(int, input().split()))
ans = 0
for i in range(n-1):
if a*(X[i+1]-X[i]) <= b:
ans += a*(X[i+1]-X[i])
else:
ans += b
print(ans)
| 9 | 10 | 194 | 209 | n, a, b = list(map(int, input().split()))
l = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
if (l[i + 1] - l[i]) * a <= b:
ans += (l[i + 1] - l[i]) * a
else:
ans += b
print(ans)
| n, a, b = list(map(int, input().split()))
X = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
if a * (X[i + 1] - X[i]) <= b:
ans += a * (X[i + 1] - X[i])
else:
ans += b
print(ans)
| false | 10 | [
"-l = list(map(int, input().split()))",
"+X = list(map(int, input().split()))",
"- if (l[i + 1] - l[i]) * a <= b:",
"- ans += (l[i + 1] - l[i]) * a",
"+ if a * (X[i + 1] - X[i]) <= b:",
"+ ans += a * (X[i + 1] - X[i])"
] | false | 0.040132 | 0.037116 | 1.081255 | [
"s504443255",
"s214854987"
] |
u603958124 | p03212 | python | s406153960 | s152381024 | 884 | 86 | 10,164 | 10,184 | Accepted | Accepted | 90.27 | from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(eval(input()))
def MAP() : return list(map(int,input().split()))
def LIST() : return list(MAP())
n = INT()
ans = 0
for x in product([0, 3, 5, 7], repeat=9):
y = 0
for i in range(9):
y += x[8-i] * 10**i
if y > n:
break
if str(y).count('0') == 0 and x.count(3) > 0 and x.count(5) > 0 and x.count(7) > 0:
ans += 1
print(ans) | from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(eval(input()))
def MAP() : return list(map(int,input().split()))
def LIST() : return list(MAP())
n = INT()
def dfs(s):
if int(s) > n:
return 0
ret = 1 if all(s.count(c) > 0 for c in '753') else 0
for c in '753':
ret += dfs(s+c)
return ret
print((dfs('0'))) | 28 | 28 | 983 | 910 | from math import (
ceil,
floor,
factorial,
gcd,
sqrt,
log2,
cos,
sin,
tan,
acos,
asin,
atan,
degrees,
radians,
pi,
inf,
)
from itertools import (
accumulate,
groupby,
permutations,
combinations,
product,
combinations_with_replacement,
)
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(MAP())
n = INT()
ans = 0
for x in product([0, 3, 5, 7], repeat=9):
y = 0
for i in range(9):
y += x[8 - i] * 10**i
if y > n:
break
if str(y).count("0") == 0 and x.count(3) > 0 and x.count(5) > 0 and x.count(7) > 0:
ans += 1
print(ans)
| from math import (
ceil,
floor,
factorial,
gcd,
sqrt,
log2,
cos,
sin,
tan,
acos,
asin,
atan,
degrees,
radians,
pi,
inf,
)
from itertools import (
accumulate,
groupby,
permutations,
combinations,
product,
combinations_with_replacement,
)
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(MAP())
n = INT()
def dfs(s):
if int(s) > n:
return 0
ret = 1 if all(s.count(c) > 0 for c in "753") else 0
for c in "753":
ret += dfs(s + c)
return ret
print((dfs("0")))
| false | 0 | [
"-ans = 0",
"-for x in product([0, 3, 5, 7], repeat=9):",
"- y = 0",
"- for i in range(9):",
"- y += x[8 - i] * 10**i",
"- if y > n:",
"- break",
"- if str(y).count(\"0\") == 0 and x.count(3) > 0 and x.count(5) > 0 and x.count(7) > 0:",
"- ans += 1",
"-print(ans)",... | false | 0.288349 | 0.045197 | 6.379824 | [
"s406153960",
"s152381024"
] |
u273010357 | p03373 | python | s167847511 | s425978133 | 99 | 91 | 3,060 | 3,060 | Accepted | Accepted | 8.08 | a,b,c,x,y = list(map(int, input().split()))
ans = float('inf')
for i in range(10**5+1):
tmp = i*2*c + max(0, x-i)*a + max(0, y-i)*b
if ans > tmp:
ans = tmp
print(ans) | a,b,c,x,y = list(map(int, input().split()))
ans = float('inf')
for i in range(10**5+1):
tmp = i*2*c
if i>=x:
pass
else:
tmp += (x-i)*a
if i>=y:
pass
else:
tmp += (y-i)*b
if ans > tmp:
ans = tmp
print(ans) | 8 | 17 | 184 | 280 | a, b, c, x, y = list(map(int, input().split()))
ans = float("inf")
for i in range(10**5 + 1):
tmp = i * 2 * c + max(0, x - i) * a + max(0, y - i) * b
if ans > tmp:
ans = tmp
print(ans)
| a, b, c, x, y = list(map(int, input().split()))
ans = float("inf")
for i in range(10**5 + 1):
tmp = i * 2 * c
if i >= x:
pass
else:
tmp += (x - i) * a
if i >= y:
pass
else:
tmp += (y - i) * b
if ans > tmp:
ans = tmp
print(ans)
| false | 52.941176 | [
"- tmp = i * 2 * c + max(0, x - i) * a + max(0, y - i) * b",
"+ tmp = i * 2 * c",
"+ if i >= x:",
"+ pass",
"+ else:",
"+ tmp += (x - i) * a",
"+ if i >= y:",
"+ pass",
"+ else:",
"+ tmp += (y - i) * b"
] | false | 0.123344 | 0.172143 | 0.716523 | [
"s167847511",
"s425978133"
] |
u731368968 | p02947 | python | s613010181 | s801472088 | 581 | 505 | 21,988 | 24,560 | Accepted | Accepted | 13.08 | n = int(eval(input()))
d={}
for i in range(n):
s=str(sorted(eval(input())))
try:
d[s]+=1
except:
d[s]=1
ans=0
for i in list(d.values()):
ans+=i*(i-1)//2
print(ans) | import collections
ss = []
N = int(eval(input()))
for i in range(N):
s = str(sorted(eval(input())))
ss.append(s)
c = collections.Counter(ss)
ans = 0
for v in list(c.values()):
ans += v * (v - 1) // 2
print(ans)
| 13 | 16 | 194 | 225 | n = int(eval(input()))
d = {}
for i in range(n):
s = str(sorted(eval(input())))
try:
d[s] += 1
except:
d[s] = 1
ans = 0
for i in list(d.values()):
ans += i * (i - 1) // 2
print(ans)
| import collections
ss = []
N = int(eval(input()))
for i in range(N):
s = str(sorted(eval(input())))
ss.append(s)
c = collections.Counter(ss)
ans = 0
for v in list(c.values()):
ans += v * (v - 1) // 2
print(ans)
| false | 18.75 | [
"-n = int(eval(input()))",
"-d = {}",
"-for i in range(n):",
"+import collections",
"+",
"+ss = []",
"+N = int(eval(input()))",
"+for i in range(N):",
"- try:",
"- d[s] += 1",
"- except:",
"- d[s] = 1",
"+ ss.append(s)",
"+c = collections.Counter(ss)",
"-for i in l... | false | 0.089421 | 0.169802 | 0.526615 | [
"s613010181",
"s801472088"
] |
u191874006 | p02995 | python | s477451344 | s436428508 | 170 | 71 | 38,484 | 65,648 | Accepted | Accepted | 58.24 | #!/usr/bin/env python3
#ABC131 C
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def gcd(n,m):
if m == 0:
return n
else:
return gcd(m,n%m)
def lcm(n,m):
return (n*m)//gcd(n,m)
a,b,c,d = LI()
i,j,k = (a-1)//c,(a-1)//d,(a-1)//lcm(c,d)
s,t,u = b//c,b//d,b//lcm(c,d)
x = b - s - t + u
y = (a-1) - i - j + k
print((x -y))
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
a, b, c, d = LI()
ans = b - a + 1
lcm = c * d // math.gcd(c, d)
ans -= b // c - ((a-1) // c + 1) + 1
ans -= b // d - ((a-1) // d + 1) + 1
ans += b // lcm - ((a-1) // lcm + 1) + 1
print(ans) | 33 | 26 | 785 | 755 | #!/usr/bin/env python3
# ABC131 C
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def gcd(n, m):
if m == 0:
return n
else:
return gcd(m, n % m)
def lcm(n, m):
return (n * m) // gcd(n, m)
a, b, c, d = LI()
i, j, k = (a - 1) // c, (a - 1) // d, (a - 1) // lcm(c, d)
s, t, u = b // c, b // d, b // lcm(c, d)
x = b - s - t + u
y = (a - 1) - i - j + k
print((x - y))
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
a, b, c, d = LI()
ans = b - a + 1
lcm = c * d // math.gcd(c, d)
ans -= b // c - ((a - 1) // c + 1) + 1
ans -= b // d - ((a - 1) // d + 1) + 1
ans += b // lcm - ((a - 1) // lcm + 1) + 1
print(ans)
| false | 21.212121 | [
"-# ABC131 C",
"-import bisect",
"+from bisect import bisect_right as br",
"+from bisect import bisect_left as bl",
"-sys.setrecursionlimit(1000000000)",
"+sys.setrecursionlimit(2147483647)",
"-def gcd(n, m):",
"- if m == 0:",
"- return n",
"- else:",
"- return gcd(m, n % m)"... | false | 0.041386 | 0.041635 | 0.994013 | [
"s477451344",
"s436428508"
] |
u170349801 | p02548 | python | s493007393 | s497325170 | 238 | 152 | 9,184 | 8,892 | Accepted | Accepted | 36.13 | N = int(eval(input()))
count = 0
count += int(N/2)
if int(N/2)-N/2 == 0:
for i in range(1,int(N/2)):
if int(N/i)-N/i == 0:
count += int(N/i)-1
else:
count += int(N/i)
else:
for i in range(1,int(N/2)+1):
if int(N/i)-N/i == 0:
count += int(N/i)-1
else:
count += int(N/i)
print(count) | n = int(eval(input()))
ans = 0
for a in range(1, n):
ans += (n - 1) // a
print(ans)
| 20 | 5 | 386 | 84 | N = int(eval(input()))
count = 0
count += int(N / 2)
if int(N / 2) - N / 2 == 0:
for i in range(1, int(N / 2)):
if int(N / i) - N / i == 0:
count += int(N / i) - 1
else:
count += int(N / i)
else:
for i in range(1, int(N / 2) + 1):
if int(N / i) - N / i == 0:
count += int(N / i) - 1
else:
count += int(N / i)
print(count)
| n = int(eval(input()))
ans = 0
for a in range(1, n):
ans += (n - 1) // a
print(ans)
| false | 75 | [
"-N = int(eval(input()))",
"-count = 0",
"-count += int(N / 2)",
"-if int(N / 2) - N / 2 == 0:",
"- for i in range(1, int(N / 2)):",
"- if int(N / i) - N / i == 0:",
"- count += int(N / i) - 1",
"- else:",
"- count += int(N / i)",
"-else:",
"- for i in r... | false | 0.07194 | 0.08573 | 0.839147 | [
"s493007393",
"s497325170"
] |
u017603316 | p02861 | python | s272483957 | s193550320 | 241 | 105 | 63,728 | 80,892 | Accepted | Accepted | 56.43 |
N = int(eval(input()))
xy = []
for i in range(N):
xy.append(list(map(int,input().split())))
from itertools import permutations
a = list(range(N))
Ps = list(permutations(a))
#print('Ps', Ps)
keiro = []
for P in Ps:
#print('P', P)
for i in range(N-1):
keiro.append( ((xy[P[i]][0] - xy[P[i+1]][0])**2 + (xy[P[i]][1] - xy[P[i+1]][1])**2 )**0.5 )
out=sum(keiro)/len(Ps)
#print('keiro', keiro)
print(out) | N = int(eval(input()))
xy = []
for i in range(N):
xy.append(list(map(int,input().split())))
from itertools import permutations
a=list(range(1,N+1))
ps = list(permutations(a))
#print(ps)
dammy=0
for p in ps:
#print('p:',p)
for j in range(1,N):
dammy += ((xy[p[j-1]-1][0] - xy[p[j]-1][0])**2 + (xy[p[j-1]-1][1] - xy[p[j]-1][1])**2) ** (1/2)
#print(dammy)
print((dammy/len(ps)))
| 19 | 18 | 427 | 410 | N = int(eval(input()))
xy = []
for i in range(N):
xy.append(list(map(int, input().split())))
from itertools import permutations
a = list(range(N))
Ps = list(permutations(a))
# print('Ps', Ps)
keiro = []
for P in Ps:
# print('P', P)
for i in range(N - 1):
keiro.append(
(
(xy[P[i]][0] - xy[P[i + 1]][0]) ** 2
+ (xy[P[i]][1] - xy[P[i + 1]][1]) ** 2
)
** 0.5
)
out = sum(keiro) / len(Ps)
# print('keiro', keiro)
print(out)
| N = int(eval(input()))
xy = []
for i in range(N):
xy.append(list(map(int, input().split())))
from itertools import permutations
a = list(range(1, N + 1))
ps = list(permutations(a))
# print(ps)
dammy = 0
for p in ps:
# print('p:',p)
for j in range(1, N):
dammy += (
(xy[p[j - 1] - 1][0] - xy[p[j] - 1][0]) ** 2
+ (xy[p[j - 1] - 1][1] - xy[p[j] - 1][1]) ** 2
) ** (1 / 2)
# print(dammy)
print((dammy / len(ps)))
| false | 5.263158 | [
"-a = list(range(N))",
"-Ps = list(permutations(a))",
"-# print('Ps', Ps)",
"-keiro = []",
"-for P in Ps:",
"- # print('P', P)",
"- for i in range(N - 1):",
"- keiro.append(",
"- (",
"- (xy[P[i]][0] - xy[P[i + 1]][0]) ** 2",
"- + (xy[P[i]][1]... | false | 0.041046 | 0.047964 | 0.855779 | [
"s272483957",
"s193550320"
] |
u581187895 | p03170 | python | s490841267 | s614810345 | 1,772 | 1,452 | 9,576 | 9,668 | Accepted | Accepted | 18.06 |
def resolve():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
dp = [False]*(K+1)
for i in range(K+1):
for j in range(N):
if i - A[j] >= 0:
dp[i] |= ~dp[i-A[j]]
if dp[K]:
print("First")
else:
print("Second")
if __name__ == "__main__":
resolve() |
def resolve():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
dp = [False]*(K+1)
for i in range(K+1):
for j in range(N):
if i - A[j] >= 0:
dp[i] |= not dp[i-A[j]]
if dp[K]:
print("First")
else:
print("Second")
if __name__ == "__main__":
resolve() | 19 | 19 | 368 | 379 | def resolve():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
dp = [False] * (K + 1)
for i in range(K + 1):
for j in range(N):
if i - A[j] >= 0:
dp[i] |= ~dp[i - A[j]]
if dp[K]:
print("First")
else:
print("Second")
if __name__ == "__main__":
resolve()
| def resolve():
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
dp = [False] * (K + 1)
for i in range(K + 1):
for j in range(N):
if i - A[j] >= 0:
dp[i] |= not dp[i - A[j]]
if dp[K]:
print("First")
else:
print("Second")
if __name__ == "__main__":
resolve()
| false | 0 | [
"- dp[i] |= ~dp[i - A[j]]",
"+ dp[i] |= not dp[i - A[j]]"
] | false | 0.036953 | 0.036895 | 1.001556 | [
"s490841267",
"s614810345"
] |
u596276291 | p04030 | python | s851401642 | s448020805 | 24 | 20 | 3,064 | 3,316 | Accepted | Accepted | 16.67 | def main():
s = eval(input())
ans = ""
for c in s:
if c == "0":
ans += "0"
elif c == "1":
ans += "1"
elif c == "B":
ans = ans[:-1]
print(ans)
if __name__ == '__main__':
main()
| from collections import defaultdict
def main():
s = eval(input())
ans = ""
for c in s:
if c in ["0", "1"]:
ans += c
elif c == "B" and len(ans) > 0:
ans = ans[:len(ans) - 1]
print(ans)
if __name__ == '__main__':
main()
| 14 | 15 | 264 | 289 | def main():
s = eval(input())
ans = ""
for c in s:
if c == "0":
ans += "0"
elif c == "1":
ans += "1"
elif c == "B":
ans = ans[:-1]
print(ans)
if __name__ == "__main__":
main()
| from collections import defaultdict
def main():
s = eval(input())
ans = ""
for c in s:
if c in ["0", "1"]:
ans += c
elif c == "B" and len(ans) > 0:
ans = ans[: len(ans) - 1]
print(ans)
if __name__ == "__main__":
main()
| false | 6.666667 | [
"+from collections import defaultdict",
"+",
"+",
"- if c == \"0\":",
"- ans += \"0\"",
"- elif c == \"1\":",
"- ans += \"1\"",
"- elif c == \"B\":",
"- ans = ans[:-1]",
"+ if c in [\"0\", \"1\"]:",
"+ ans += c",
"+ ... | false | 0.038667 | 0.06551 | 0.59025 | [
"s851401642",
"s448020805"
] |
u606045429 | p02998 | python | s073055290 | s126336295 | 455 | 356 | 38,580 | 38,580 | Accepted | Accepted | 21.76 | from collections import Counter
def main():
class UnionFind:
def __init__(self, size):
self.data = [-1] * size
def find(self, x):
if self.data[x] < 0:
return x
else:
self.data[x] = self.find(self.data[x])
return self.data[x]
def union(self, x, y):
x, y = self.find(x), self.find(y)
if x != y:
if self.data[y] < self.data[x]:
x, y = y, x
self.data[x] += self.data[y]
self.data[y] = x
return (x != y)
MAX = 10 ** 5 + 1
uf = UnionFind(2 * MAX)
N, *XY = list(map(int, open(0).read().split()))
for x, y in zip(*[iter(XY)] * 2):
uf.union(x, y + MAX)
X = Counter(uf.find(i) for i in range(MAX))
Y = Counter(uf.find(i) for i in range(MAX, MAX * 2))
res = sum(X[i] * Y[i] for i in range(MAX * 2))
print((res - N))
if __name__ == '__main__':
main()
| from collections import Counter
def main():
MAX = 10 ** 5 + 1
data = [-1] * (2 * MAX)
def find(x):
if data[x] < 0:
return x
else:
data[x] = find(data[x])
return data[x]
def union(x, y):
x, y = find(x), find(y)
if x != y:
if data[y] < data[x]:
x, y = y, x
data[x] += data[y]
data[y] = x
return (x != y)
N, *XY = list(map(int, open(0).read().split()))
for x, y in zip(*[iter(XY)] * 2):
union(x, y + MAX)
X = Counter(find(i) for i in range(MAX))
Y = Counter(find(i) for i in range(MAX, MAX * 2))
res = sum(X[i] * Y[i] for i in range(MAX * 2))
print((res - N))
if __name__ == '__main__':
main() | 41 | 39 | 1,042 | 812 | from collections import Counter
def main():
class UnionFind:
def __init__(self, size):
self.data = [-1] * size
def find(self, x):
if self.data[x] < 0:
return x
else:
self.data[x] = self.find(self.data[x])
return self.data[x]
def union(self, x, y):
x, y = self.find(x), self.find(y)
if x != y:
if self.data[y] < self.data[x]:
x, y = y, x
self.data[x] += self.data[y]
self.data[y] = x
return x != y
MAX = 10**5 + 1
uf = UnionFind(2 * MAX)
N, *XY = list(map(int, open(0).read().split()))
for x, y in zip(*[iter(XY)] * 2):
uf.union(x, y + MAX)
X = Counter(uf.find(i) for i in range(MAX))
Y = Counter(uf.find(i) for i in range(MAX, MAX * 2))
res = sum(X[i] * Y[i] for i in range(MAX * 2))
print((res - N))
if __name__ == "__main__":
main()
| from collections import Counter
def main():
MAX = 10**5 + 1
data = [-1] * (2 * MAX)
def find(x):
if data[x] < 0:
return x
else:
data[x] = find(data[x])
return data[x]
def union(x, y):
x, y = find(x), find(y)
if x != y:
if data[y] < data[x]:
x, y = y, x
data[x] += data[y]
data[y] = x
return x != y
N, *XY = list(map(int, open(0).read().split()))
for x, y in zip(*[iter(XY)] * 2):
union(x, y + MAX)
X = Counter(find(i) for i in range(MAX))
Y = Counter(find(i) for i in range(MAX, MAX * 2))
res = sum(X[i] * Y[i] for i in range(MAX * 2))
print((res - N))
if __name__ == "__main__":
main()
| false | 4.878049 | [
"- class UnionFind:",
"- def __init__(self, size):",
"- self.data = [-1] * size",
"+ MAX = 10**5 + 1",
"+ data = [-1] * (2 * MAX)",
"- def find(self, x):",
"- if self.data[x] < 0:",
"- return x",
"- else:",
"- se... | false | 0.268606 | 0.34305 | 0.782993 | [
"s073055290",
"s126336295"
] |
u562935282 | p03986 | python | s390559784 | s901559292 | 60 | 45 | 3,500 | 3,500 | Accepted | Accepted | 25 | x = eval(input())
ans = 0
cnt = 0
for i in range(len(x)):
if x[i] == 'S':
cnt += 1
elif x[i] == 'T':
if cnt > 0:
cnt -= 1
else:
ans += 2
print(ans) | x = eval(input())
ans = 0
cnt_s = 0
for xx in x:
if xx == 'T':
if cnt_s > 0:
cnt_s -= 1
else:
ans += 2
else:
cnt_s += 1
print(ans)
| 13 | 13 | 214 | 194 | x = eval(input())
ans = 0
cnt = 0
for i in range(len(x)):
if x[i] == "S":
cnt += 1
elif x[i] == "T":
if cnt > 0:
cnt -= 1
else:
ans += 2
print(ans)
| x = eval(input())
ans = 0
cnt_s = 0
for xx in x:
if xx == "T":
if cnt_s > 0:
cnt_s -= 1
else:
ans += 2
else:
cnt_s += 1
print(ans)
| false | 0 | [
"-cnt = 0",
"-for i in range(len(x)):",
"- if x[i] == \"S\":",
"- cnt += 1",
"- elif x[i] == \"T\":",
"- if cnt > 0:",
"- cnt -= 1",
"+cnt_s = 0",
"+for xx in x:",
"+ if xx == \"T\":",
"+ if cnt_s > 0:",
"+ cnt_s -= 1",
"+ else:",
"+ ... | false | 0.04533 | 0.04976 | 0.910963 | [
"s390559784",
"s901559292"
] |
u814781830 | p02574 | python | s877297821 | s080434243 | 708 | 392 | 225,148 | 189,256 | Accepted | Accepted | 44.63 | import math
NOTCOM = "not coprime"
SETWISE = "setwise coprime"
PAIRWISE = "pairwise coprime"
def calc_prime(N):
prime, i = set(), 1
while i * i <= N:
if N % i == 0:
yield i
if i != N//i: yield N//i
i += 1
def main():
N = int(eval(input()))
A = list(map(int, input().split()))
A = list(set(A))
cnt2 = 0
cnt3 = 0
allgcd = A[0]
for a in A:
allgcd = math.gcd(allgcd, a)
if a % 2 == 0:
cnt2 += 1
if a % 3 == 0:
cnt3 += 1
if allgcd != 1:
return NOTCOM
if cnt2 >= 2 or cnt3 >= 2:
return SETWISE
allprime = set()
for a in A:
for t in calc_prime(a):
if t in allprime and t != 1:
return SETWISE
allprime.add(t)
return PAIRWISE
print((main()))
| import math
NOTCOM = "not coprime"
SETWISE = "setwise coprime"
PAIRWISE = "pairwise coprime"
MAX_A = 10 ** 6 + 5
def main():
N = int(eval(input()))
A = list(map(int, input().split()))
c = [0] * MAX_A
for a in A:
c[a] += 1
pairwse = True
for i in range(2, MAX_A):
cnt = 0
for j in range(i, MAX_A, i):
cnt += c[j]
if cnt > 1: pairwse = False
if pairwse:
return PAIRWISE
allgcd = A[0]
for a in A:
allgcd = math.gcd(allgcd, a)
if allgcd == 1: return SETWISE
return NOTCOM
print((main()))
| 41 | 28 | 882 | 614 | import math
NOTCOM = "not coprime"
SETWISE = "setwise coprime"
PAIRWISE = "pairwise coprime"
def calc_prime(N):
prime, i = set(), 1
while i * i <= N:
if N % i == 0:
yield i
if i != N // i:
yield N // i
i += 1
def main():
N = int(eval(input()))
A = list(map(int, input().split()))
A = list(set(A))
cnt2 = 0
cnt3 = 0
allgcd = A[0]
for a in A:
allgcd = math.gcd(allgcd, a)
if a % 2 == 0:
cnt2 += 1
if a % 3 == 0:
cnt3 += 1
if allgcd != 1:
return NOTCOM
if cnt2 >= 2 or cnt3 >= 2:
return SETWISE
allprime = set()
for a in A:
for t in calc_prime(a):
if t in allprime and t != 1:
return SETWISE
allprime.add(t)
return PAIRWISE
print((main()))
| import math
NOTCOM = "not coprime"
SETWISE = "setwise coprime"
PAIRWISE = "pairwise coprime"
MAX_A = 10**6 + 5
def main():
N = int(eval(input()))
A = list(map(int, input().split()))
c = [0] * MAX_A
for a in A:
c[a] += 1
pairwse = True
for i in range(2, MAX_A):
cnt = 0
for j in range(i, MAX_A, i):
cnt += c[j]
if cnt > 1:
pairwse = False
if pairwse:
return PAIRWISE
allgcd = A[0]
for a in A:
allgcd = math.gcd(allgcd, a)
if allgcd == 1:
return SETWISE
return NOTCOM
print((main()))
| false | 31.707317 | [
"-",
"-",
"-def calc_prime(N):",
"- prime, i = set(), 1",
"- while i * i <= N:",
"- if N % i == 0:",
"- yield i",
"- if i != N // i:",
"- yield N // i",
"- i += 1",
"+MAX_A = 10**6 + 5",
"- A = list(set(A))",
"- cnt2 = 0",
"- ... | false | 0.035712 | 2.796256 | 0.012771 | [
"s877297821",
"s080434243"
] |
u254871849 | p03946 | python | s431117641 | s446886761 | 149 | 88 | 23,512 | 22,112 | Accepted | Accepted | 40.94 | import sys
from heapq import heappush, heappop
from collections import Counter
n, t, *a = list(map(int, sys.stdin.read().split()))
def main():
cand = []
hq = [a[0]]
for x in a[1:]:
y = heappop(hq)
cand.append(x - y)
heappush(hq, x)
heappush(hq, y)
c = Counter(cand)
ans = c[max(c.keys())]
print(ans)
if __name__ == '__main__':
main() | import sys
from collections import Counter
n, t, *a = list(map(int, sys.stdin.read().split()))
def main():
cand = []
mi = a[0]
for x in a[1:]:
cand.append(x - mi)
mi = min(mi, x)
c = Counter(cand)
ans = c[max(c.keys())]
print(ans)
if __name__ == '__main__':
main() | 20 | 17 | 381 | 301 | import sys
from heapq import heappush, heappop
from collections import Counter
n, t, *a = list(map(int, sys.stdin.read().split()))
def main():
cand = []
hq = [a[0]]
for x in a[1:]:
y = heappop(hq)
cand.append(x - y)
heappush(hq, x)
heappush(hq, y)
c = Counter(cand)
ans = c[max(c.keys())]
print(ans)
if __name__ == "__main__":
main()
| import sys
from collections import Counter
n, t, *a = list(map(int, sys.stdin.read().split()))
def main():
cand = []
mi = a[0]
for x in a[1:]:
cand.append(x - mi)
mi = min(mi, x)
c = Counter(cand)
ans = c[max(c.keys())]
print(ans)
if __name__ == "__main__":
main()
| false | 15 | [
"-from heapq import heappush, heappop",
"- hq = [a[0]]",
"+ mi = a[0]",
"- y = heappop(hq)",
"- cand.append(x - y)",
"- heappush(hq, x)",
"- heappush(hq, y)",
"+ cand.append(x - mi)",
"+ mi = min(mi, x)"
] | false | 0.040009 | 0.039348 | 1.016802 | [
"s431117641",
"s446886761"
] |
u043048943 | p03475 | python | s931078078 | s397640491 | 242 | 207 | 43,884 | 41,708 | Accepted | Accepted | 14.46 | N = int(eval(input()))
dia = [0]*(N-1)
for i in range(N-1):
c,s,f = list(map(int,input().split()))
dia[i] = (c,s,f)
for i in range(N-1):
time = 0
for j in range(i,N-1):
c,s,f = dia[j]
if time > s:
x = (time - s)/f
if x.is_integer():
s += int(x)*f
else:
s += int(x+1)*f
time = s + c
print(time)
print((0))
| N = int(eval(input()))
dia = [0]*(N-1)
for i in range(N-1):
c,s,f = list(map(int,input().split()))
dia[i] = (c,s,f)
for i in range(N-1):
time = 0
for j in range(i,N-1):
c,s,f = dia[j]
if time > s:
if time % f == 0:
s = time
else:
s = time + f - time % f
time = s + c
print(time)
print((0))
| 26 | 25 | 437 | 409 | N = int(eval(input()))
dia = [0] * (N - 1)
for i in range(N - 1):
c, s, f = list(map(int, input().split()))
dia[i] = (c, s, f)
for i in range(N - 1):
time = 0
for j in range(i, N - 1):
c, s, f = dia[j]
if time > s:
x = (time - s) / f
if x.is_integer():
s += int(x) * f
else:
s += int(x + 1) * f
time = s + c
print(time)
print((0))
| N = int(eval(input()))
dia = [0] * (N - 1)
for i in range(N - 1):
c, s, f = list(map(int, input().split()))
dia[i] = (c, s, f)
for i in range(N - 1):
time = 0
for j in range(i, N - 1):
c, s, f = dia[j]
if time > s:
if time % f == 0:
s = time
else:
s = time + f - time % f
time = s + c
print(time)
print((0))
| false | 3.846154 | [
"- x = (time - s) / f",
"- if x.is_integer():",
"- s += int(x) * f",
"+ if time % f == 0:",
"+ s = time",
"- s += int(x + 1) * f",
"+ s = time + f - time % f"
] | false | 0.036229 | 0.036496 | 0.99269 | [
"s931078078",
"s397640491"
] |
u227082700 | p03805 | python | s599508824 | s303957688 | 380 | 31 | 3,064 | 3,064 | Accepted | Accepted | 91.84 | z,m=list(map(int,input().split()));a=[[],[]];ans=0
for i in range(m):aa,bb=list(map(int,input().split()));a[0].append(aa);a[1].append(bb)
def d(n,nl,ml):
if sorted(nl+[n])==[i+1for i in range(z)]:return 1
if n in nl:return 0
l=len(ml[0]);ans=0
for i in range(l):
c=[ml[0][:i]+ml[0][i+1:],ml[1][:i]+ml[1][i+1:]]
if ml[0][i]==n:ans+=d(ml[1][i],nl+[n],c)
if ml[1][i]==n:ans+=d(ml[0][i],nl+[n],c)
return ans
for i in range(m):
if a[0][i]==1:
c=[a[0][:i]+a[0][i+1:],a[1][:i]+a[1][i+1:]]
ans+=d(a[1][i],[1],c)
print(ans) | n,m=list(map(int,input().split()))
edge=[n*[0]for _ in range(n)]
for i in range(m):
a,b=list(map(int,input().split()))
a-=1
b-=1
edge[a][b]=edge[b][a]=1
from itertools import permutations
ans=0
for i in permutations([j for j in range(1,n)],n-1):
f=True
t=[0]+list(i)
for j in range(1,n):
if edge[t[j-1]][t[j]]==0:f=False
if f:ans+=1
print(ans) | 16 | 16 | 549 | 356 | z, m = list(map(int, input().split()))
a = [[], []]
ans = 0
for i in range(m):
aa, bb = list(map(int, input().split()))
a[0].append(aa)
a[1].append(bb)
def d(n, nl, ml):
if sorted(nl + [n]) == [i + 1 for i in range(z)]:
return 1
if n in nl:
return 0
l = len(ml[0])
ans = 0
for i in range(l):
c = [ml[0][:i] + ml[0][i + 1 :], ml[1][:i] + ml[1][i + 1 :]]
if ml[0][i] == n:
ans += d(ml[1][i], nl + [n], c)
if ml[1][i] == n:
ans += d(ml[0][i], nl + [n], c)
return ans
for i in range(m):
if a[0][i] == 1:
c = [a[0][:i] + a[0][i + 1 :], a[1][:i] + a[1][i + 1 :]]
ans += d(a[1][i], [1], c)
print(ans)
| n, m = list(map(int, input().split()))
edge = [n * [0] for _ in range(n)]
for i in range(m):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
edge[a][b] = edge[b][a] = 1
from itertools import permutations
ans = 0
for i in permutations([j for j in range(1, n)], n - 1):
f = True
t = [0] + list(i)
for j in range(1, n):
if edge[t[j - 1]][t[j]] == 0:
f = False
if f:
ans += 1
print(ans)
| false | 0 | [
"-z, m = list(map(int, input().split()))",
"-a = [[], []]",
"+n, m = list(map(int, input().split()))",
"+edge = [n * [0] for _ in range(n)]",
"+for i in range(m):",
"+ a, b = list(map(int, input().split()))",
"+ a -= 1",
"+ b -= 1",
"+ edge[a][b] = edge[b][a] = 1",
"+from itertools imp... | false | 0.072733 | 0.063881 | 1.138557 | [
"s599508824",
"s303957688"
] |
u983918956 | p03524 | python | s995234856 | s691649754 | 168 | 39 | 3,188 | 3,188 | Accepted | Accepted | 76.79 | S = eval(input())
cnt = [0]*3
for s in S:
cnt[ord(s)-97] += 1
cnt.sort()
ans = "YES"
prepre = -1
pre = -1
while cnt != [0]*3:
for i in range(3)[::-1]:
if cnt[i] > 0:
if prepre == i or pre == i:
ans = "NO"
cnt[i] -= 1
prepre = pre
pre = i
print(ans) | S = eval(input())
cnt = [0]*3
for s in S:
cnt[ord(s)-97] += 1
if max(cnt) - min(cnt) <= 1:
print("YES")
else:
print("NO") | 22 | 11 | 348 | 140 | S = eval(input())
cnt = [0] * 3
for s in S:
cnt[ord(s) - 97] += 1
cnt.sort()
ans = "YES"
prepre = -1
pre = -1
while cnt != [0] * 3:
for i in range(3)[::-1]:
if cnt[i] > 0:
if prepre == i or pre == i:
ans = "NO"
cnt[i] -= 1
prepre = pre
pre = i
print(ans)
| S = eval(input())
cnt = [0] * 3
for s in S:
cnt[ord(s) - 97] += 1
if max(cnt) - min(cnt) <= 1:
print("YES")
else:
print("NO")
| false | 50 | [
"-cnt.sort()",
"-ans = \"YES\"",
"-prepre = -1",
"-pre = -1",
"-while cnt != [0] * 3:",
"- for i in range(3)[::-1]:",
"- if cnt[i] > 0:",
"- if prepre == i or pre == i:",
"- ans = \"NO\"",
"- cnt[i] -= 1",
"- prepre = pre",
"- ... | false | 0.103775 | 0.039667 | 2.616149 | [
"s995234856",
"s691649754"
] |
u263830634 | p03045 | python | s292795125 | s825446819 | 693 | 538 | 5,376 | 5,424 | Accepted | Accepted | 22.37 | class UnionFind(object):
def __init__(self, N):
self.parent = [-1] * N #parent[i] は(i+1)番目の要素が含まれる要素数の(-1)倍
#要素が負-->その数を親とするグループに属する要素の数×(-1)
#要素が正-->親のindex
#Aがどのグループに属しているかを調べる
def root(self, A):
if self.parent[A-1] < 0: #負の数-->その数は親
return A
self.parent[A-1] = self.root(self.parent[A-1]) #負では無い時、親の場所が入っているから、親が属しているグループを、自分自身に入れる(一度確認したところは直接親を見れるようにする)
return self.parent[A-1] #親の位置を返す
#Aが含まれているグループに属している数を返す
def size(self, A):
return -1 * self.parent[self.root(A)-1]
#AとBをくっ付ける
def connect(self, A, B):
A = self.root(A) #Aを含むグループの親を返す
B = self.root(B) #Bを含むグループの親を返す
if A == B: #親が同じならなにもしない
return False
#大きい方(A)に小さい方(B)をつなぎたい
if self.size(A) < self.size(B): #大小関係が逆の時は入れ替える
A, B = B, A
self.parent[A-1] += self.parent[B-1] #大きい方に小さい方を加える (負の数+負の数 = 新しいグループに含まれる数×(-1))
self.parent[B-1] = A #加えられた親の値を、加えた先の親の位置に書き変える
return True
def same(self, A, B):
if self.root(A) == self.root(B):
return True
else:
return False
# N, Q = map(int, input().split())
# uni = UnionFind(N)
# for _ in range(Q):
# P, A, B = map(int, input().split())
# if P == 1:
# if uni.root(A) == uni.root(B): #親が同じかどうか
# print ('Yes')
# else:
# print ('No')
# else:
# uni.connect(A, B)
N, M = list(map(int, input().split()))
uni = UnionFind(N)
ans = N
for _ in range(M):
x, y, z = list(map(int, input().split()))
x -= 1
y -= 1
if uni.root(x) == uni.root(y): #親が同じ時
pass
else:
ans -= 1
uni.connect(x, y)
print (ans)
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7
N, M = list(map(int, input().split()))
class UnionFind(object):
def __init__(self, N):
self.parent = [-1] * N #parent[i] は(i+1)番目の要素が含まれる要素数の(-1)倍
#要素が負-->その数を親とするグループに属する要素の数×(-1)
#要素が正-->親のindex
#Aがどのグループに属しているかを調べる
def root(self, A):
if self.parent[A-1] < 0: #負の数-->その数は親
return A
self.parent[A-1] = self.root(self.parent[A-1]) #負では無い時、親の場所が入っているから、親が属しているグループを、自分自身に入れる(一度確認したところは直接親を見れるようにする)
return self.parent[A-1] #親の位置を返す
#Aが含まれているグループに属している数を返す
def size(self, A):
return -1 * self.parent[self.root(A)-1]
#AとBをくっ付ける
def connect(self, A, B):
A = self.root(A) #Aを含むグループの親を返す
B = self.root(B) #Bを含むグループの親を返す
if A == B: #親が同じならなにもしない
return False
#大きい方(A)に小さい方(B)をつなぎたい
if self.size(A) < self.size(B): #大小関係が逆の時は入れ替える
A, B = B, A
self.parent[A-1] += self.parent[B-1] #大きい方に小さい方を加える (負の数+負の数 = 新しいグループに含まれる数×(-1))
self.parent[B-1] = A #加えられた親の値を、加えた先の親の位置に書き変える
return True
def same(self, A, B):
if self.root(A) == self.root(B):
return True
else:
return False
ans = N
uni = UnionFind(N + 1)
for _ in range(M):
x, y, z = list(map(int, input().split()))
if uni.same(x, y):
continue
uni.connect(x, y)
ans -= 1
print (ans) | 64 | 55 | 1,808 | 1,525 | class UnionFind(object):
def __init__(self, N):
self.parent = [-1] * N # parent[i] は(i+1)番目の要素が含まれる要素数の(-1)倍
# 要素が負-->その数を親とするグループに属する要素の数×(-1)
# 要素が正-->親のindex
# Aがどのグループに属しているかを調べる
def root(self, A):
if self.parent[A - 1] < 0: # 負の数-->その数は親
return A
self.parent[A - 1] = self.root(
self.parent[A - 1]
) # 負では無い時、親の場所が入っているから、親が属しているグループを、自分自身に入れる(一度確認したところは直接親を見れるようにする)
return self.parent[A - 1] # 親の位置を返す
# Aが含まれているグループに属している数を返す
def size(self, A):
return -1 * self.parent[self.root(A) - 1]
# AとBをくっ付ける
def connect(self, A, B):
A = self.root(A) # Aを含むグループの親を返す
B = self.root(B) # Bを含むグループの親を返す
if A == B: # 親が同じならなにもしない
return False
# 大きい方(A)に小さい方(B)をつなぎたい
if self.size(A) < self.size(B): # 大小関係が逆の時は入れ替える
A, B = B, A
self.parent[A - 1] += self.parent[
B - 1
] # 大きい方に小さい方を加える (負の数+負の数 = 新しいグループに含まれる数×(-1))
self.parent[B - 1] = A # 加えられた親の値を、加えた先の親の位置に書き変える
return True
def same(self, A, B):
if self.root(A) == self.root(B):
return True
else:
return False
# N, Q = map(int, input().split())
# uni = UnionFind(N)
# for _ in range(Q):
# P, A, B = map(int, input().split())
# if P == 1:
# if uni.root(A) == uni.root(B): #親が同じかどうか
# print ('Yes')
# else:
# print ('No')
# else:
# uni.connect(A, B)
N, M = list(map(int, input().split()))
uni = UnionFind(N)
ans = N
for _ in range(M):
x, y, z = list(map(int, input().split()))
x -= 1
y -= 1
if uni.root(x) == uni.root(y): # 親が同じ時
pass
else:
ans -= 1
uni.connect(x, y)
print(ans)
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
MOD = 10**9 + 7
N, M = list(map(int, input().split()))
class UnionFind(object):
def __init__(self, N):
self.parent = [-1] * N # parent[i] は(i+1)番目の要素が含まれる要素数の(-1)倍
# 要素が負-->その数を親とするグループに属する要素の数×(-1)
# 要素が正-->親のindex
# Aがどのグループに属しているかを調べる
def root(self, A):
if self.parent[A - 1] < 0: # 負の数-->その数は親
return A
self.parent[A - 1] = self.root(
self.parent[A - 1]
) # 負では無い時、親の場所が入っているから、親が属しているグループを、自分自身に入れる(一度確認したところは直接親を見れるようにする)
return self.parent[A - 1] # 親の位置を返す
# Aが含まれているグループに属している数を返す
def size(self, A):
return -1 * self.parent[self.root(A) - 1]
# AとBをくっ付ける
def connect(self, A, B):
A = self.root(A) # Aを含むグループの親を返す
B = self.root(B) # Bを含むグループの親を返す
if A == B: # 親が同じならなにもしない
return False
# 大きい方(A)に小さい方(B)をつなぎたい
if self.size(A) < self.size(B): # 大小関係が逆の時は入れ替える
A, B = B, A
self.parent[A - 1] += self.parent[
B - 1
] # 大きい方に小さい方を加える (負の数+負の数 = 新しいグループに含まれる数×(-1))
self.parent[B - 1] = A # 加えられた親の値を、加えた先の親の位置に書き変える
return True
def same(self, A, B):
if self.root(A) == self.root(B):
return True
else:
return False
ans = N
uni = UnionFind(N + 1)
for _ in range(M):
x, y, z = list(map(int, input().split()))
if uni.same(x, y):
continue
uni.connect(x, y)
ans -= 1
print(ans)
| false | 14.0625 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"+sys.setrecursionlimit(10**9)",
"+MOD = 10**9 + 7",
"+N, M = list(map(int, input().split()))",
"+",
"+",
"-# N, Q = map(int, input().split())",
"-# uni = UnionFind(N)",
"-# for _ in range(Q):",
"-# P, A, B = map(int, input().split())",
... | false | 0.087287 | 0.112742 | 0.774214 | [
"s292795125",
"s825446819"
] |
u970197315 | p02971 | python | s655588320 | s724074245 | 563 | 488 | 14,112 | 20,112 | Accepted | Accepted | 13.32 | N = int(eval(input()))
a = []
b = []
a_max = 0
a_second = 0
for i in range(N):
a.append(int(eval(input())))
b = a[:]
a.sort(reverse=True)
a_max = a[0]
a_second = a[1]
for i in range(N):
if b[i] == a_max:
print(a_second)
else:
print(a_max)
| n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
l=[0]*n
r=[0]*n
t=0
for i in range(n):
t=max(t,a[i])
l[i]=t
t=0
for i in range(n-1,-1,-1):
t=max(t,a[i])
r[i]=t
# print(l)
# print(r)
for i in range(n):
if i==0:
print((r[i+1]))
continue
if i==n-1:
print((l[i-1]))
continue
print((max(r[i+1],l[i-1])))
| 20 | 22 | 278 | 346 | N = int(eval(input()))
a = []
b = []
a_max = 0
a_second = 0
for i in range(N):
a.append(int(eval(input())))
b = a[:]
a.sort(reverse=True)
a_max = a[0]
a_second = a[1]
for i in range(N):
if b[i] == a_max:
print(a_second)
else:
print(a_max)
| n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
l = [0] * n
r = [0] * n
t = 0
for i in range(n):
t = max(t, a[i])
l[i] = t
t = 0
for i in range(n - 1, -1, -1):
t = max(t, a[i])
r[i] = t
# print(l)
# print(r)
for i in range(n):
if i == 0:
print((r[i + 1]))
continue
if i == n - 1:
print((l[i - 1]))
continue
print((max(r[i + 1], l[i - 1])))
| false | 9.090909 | [
"-N = int(eval(input()))",
"-a = []",
"-b = []",
"-a_max = 0",
"-a_second = 0",
"-for i in range(N):",
"- a.append(int(eval(input())))",
"-b = a[:]",
"-a.sort(reverse=True)",
"-a_max = a[0]",
"-a_second = a[1]",
"-for i in range(N):",
"- if b[i] == a_max:",
"- print(a_second)"... | false | 0.04117 | 0.036716 | 1.121325 | [
"s655588320",
"s724074245"
] |
u623819879 | p03221 | python | s076856318 | s643104491 | 1,023 | 829 | 88,920 | 80,416 | Accepted | Accepted | 18.96 | from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
sys.setrecursionlimit(10**6)
def SI():
return input().split()
def MI():
return list(map(int,input().split()))
def I():
return int(eval(input()))
def LI():
return [int(i) for i in input().split()]
YN=['Yes','No']
mo=10**9+7
n,m=MI()
pref=[]
for i in range(m):
p,y=MI()
pref+=[(p,i,y)]
pref.sort(key=lambda x:x[0]*10**10+x[2])
c=0
pre=pref[0][0]
ans=[]
for p,i,y in pref:
pid='0'*(6-len(str(p)))+str(p)
if pre==p:
c+=1
cid='0'*(6-len(str(c)))+str(c)
else:
c=1
cid='0'*(6-len(str(c)))+str(c)
ans+=[(i,pid+cid)]
pre=p
ans.sort(key=lambda x:x[0])
for i,iid in ans:
print(iid)
| from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
sys.setrecursionlimit(10**6)
def SI():
return input().split()
def MI():
return list(map(int,input().split()))
def I():
return int(eval(input()))
def LI():
return [int(i) for i in input().split()]
YN=['Yes','No']
mo=10**9+7
n,m=MI()
ids=[0]*m
pref=[[] for i in range(1+n)]
for i in range(m):
p,y=MI()
pref[p]+=[(i,y)]
for p in range(1,n+1):
ls=pref[p]
ls.sort(key=lambda x:x[1])
c=1
for i,y in ls:
pid='0'*(6-len(str(p)))+str(p)
cid='0'*(6-len(str(c)))+str(c)
c+=1
ids[i]=pid+cid
for iid in ids:
print(iid)
| 41 | 37 | 857 | 793 | from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
sys.setrecursionlimit(10**6)
def SI():
return input().split()
def MI():
return list(map(int, input().split()))
def I():
return int(eval(input()))
def LI():
return [int(i) for i in input().split()]
YN = ["Yes", "No"]
mo = 10**9 + 7
n, m = MI()
pref = []
for i in range(m):
p, y = MI()
pref += [(p, i, y)]
pref.sort(key=lambda x: x[0] * 10**10 + x[2])
c = 0
pre = pref[0][0]
ans = []
for p, i, y in pref:
pid = "0" * (6 - len(str(p))) + str(p)
if pre == p:
c += 1
cid = "0" * (6 - len(str(c))) + str(c)
else:
c = 1
cid = "0" * (6 - len(str(c))) + str(c)
ans += [(i, pid + cid)]
pre = p
ans.sort(key=lambda x: x[0])
for i, iid in ans:
print(iid)
| from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations
import sys
import bisect
import string
sys.setrecursionlimit(10**6)
def SI():
return input().split()
def MI():
return list(map(int, input().split()))
def I():
return int(eval(input()))
def LI():
return [int(i) for i in input().split()]
YN = ["Yes", "No"]
mo = 10**9 + 7
n, m = MI()
ids = [0] * m
pref = [[] for i in range(1 + n)]
for i in range(m):
p, y = MI()
pref[p] += [(i, y)]
for p in range(1, n + 1):
ls = pref[p]
ls.sort(key=lambda x: x[1])
c = 1
for i, y in ls:
pid = "0" * (6 - len(str(p))) + str(p)
cid = "0" * (6 - len(str(c))) + str(c)
c += 1
ids[i] = pid + cid
for iid in ids:
print(iid)
| false | 9.756098 | [
"-pref = []",
"+ids = [0] * m",
"+pref = [[] for i in range(1 + n)]",
"- pref += [(p, i, y)]",
"-pref.sort(key=lambda x: x[0] * 10**10 + x[2])",
"-c = 0",
"-pre = pref[0][0]",
"-ans = []",
"-for p, i, y in pref:",
"- pid = \"0\" * (6 - len(str(p))) + str(p)",
"- if pre == p:",
"+ p... | false | 0.041882 | 0.039452 | 1.061586 | [
"s076856318",
"s643104491"
] |
u740284863 | p04047 | python | s117957140 | s892975584 | 23 | 18 | 3,316 | 2,940 | Accepted | Accepted | 21.74 | N = int(eval(input()))
kushi = sorted(list(map(int,input().split())))
sum = 0
for i in range(2*N):
if i % 2 == 0:
sum += kushi[i]
print(sum)
| N = int(eval(input()))
kushi = sorted(list(map(int,input().split())))
sum = 0
for i in range(0,2*N,2):
sum += kushi[i]
print(sum)
| 7 | 6 | 153 | 133 | N = int(eval(input()))
kushi = sorted(list(map(int, input().split())))
sum = 0
for i in range(2 * N):
if i % 2 == 0:
sum += kushi[i]
print(sum)
| N = int(eval(input()))
kushi = sorted(list(map(int, input().split())))
sum = 0
for i in range(0, 2 * N, 2):
sum += kushi[i]
print(sum)
| false | 14.285714 | [
"-for i in range(2 * N):",
"- if i % 2 == 0:",
"- sum += kushi[i]",
"+for i in range(0, 2 * N, 2):",
"+ sum += kushi[i]"
] | false | 0.041606 | 0.118245 | 0.351865 | [
"s117957140",
"s892975584"
] |
u279493135 | p03013 | python | s918354394 | s107831959 | 176 | 136 | 11,552 | 11,580 | Accepted | Accepted | 22.73 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N, M = MAP()
a = [INT() for _ in range(M)]
ng = [0]*(N+1)
for i in a:
ng[i] = 1
dp = [0]*(N+1)
dp[0] = 1
dp[1] = 1
for i in range(2, N+1):
for j in range(1, 3):
if not ng[i-j]:
dp[i] = (dp[i]+dp[i-j])%mod
print((dp[N]))
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, 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 fractions import gcd
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(int, 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
N, M = MAP()
a = [INT() for _ in range(M)]
is_broken = [0]*(N+1)
for x in a:
is_broken[x] = 1
dp = [0]*(N+1)
dp[0] = 1
dp[1] = 1
for i in range(2, N+1):
if not is_broken[i-1]:
dp[i] += dp[i-1]
if not is_broken[i-2]:
dp[i] += dp[i-2]
dp[i] %= mod
print((dp[N])) | 34 | 38 | 935 | 1,069 | import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
def input():
return sys.stdin.readline().strip()
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST():
return list(map(int, input().split()))
sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
N, M = MAP()
a = [INT() for _ in range(M)]
ng = [0] * (N + 1)
for i in a:
ng[i] = 1
dp = [0] * (N + 1)
dp[0] = 1
dp[1] = 1
for i in range(2, N + 1):
for j in range(1, 3):
if not ng[i - j]:
dp[i] = (dp[i] + dp[i - j]) % mod
print((dp[N]))
| import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, 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 fractions import gcd
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(int, 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
N, M = MAP()
a = [INT() for _ in range(M)]
is_broken = [0] * (N + 1)
for x in a:
is_broken[x] = 1
dp = [0] * (N + 1)
dp[0] = 1
dp[1] = 1
for i in range(2, N + 1):
if not is_broken[i - 1]:
dp[i] += dp[i - 1]
if not is_broken[i - 2]:
dp[i] += dp[i - 2]
dp[i] %= mod
print((dp[N]))
| false | 10.526316 | [
"-from itertools import accumulate, permutations, combinations, product",
"+from itertools import accumulate, permutations, combinations, product, groupby",
"+from functools import reduce",
"+def ZIP(n):",
"+ return list(zip(*(MAP() for _ in range(n))))",
"+",
"+",
"-ng = [0] * (N + 1)",
"-for i ... | false | 0.071123 | 0.047937 | 1.483675 | [
"s918354394",
"s107831959"
] |
u869919400 | p03031 | python | s693266866 | s265275697 | 217 | 40 | 41,456 | 9,128 | Accepted | Accepted | 81.57 | N, M = list(map(int, input().split()))
KS = [list(map(int, input().split())) for i in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
bit = str(bin(i))[2:].zfill(N)
for (_, *s), p in zip(KS, P):
ons = 0
for si in s:
ons += int(bit[si-1])
if ons % 2 != p:
break
else:
ans += 1
print(ans) | N, M = list(map(int, input().split()))
KS = [list(map(int, input().split())) for i in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
switches = bin(i)[2:].zfill(N)
all_light_on = True
for j in range(M):
_, *S = KS[j]
on = 0
for k, s in enumerate(switches, 1):
if s == '1' and k in S:
on += 1
if on % 2 == P[j]:
continue
else:
all_light_on = False
break
if all_light_on:
ans += 1
print(ans) | 17 | 22 | 394 | 562 | N, M = list(map(int, input().split()))
KS = [list(map(int, input().split())) for i in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
bit = str(bin(i))[2:].zfill(N)
for (_, *s), p in zip(KS, P):
ons = 0
for si in s:
ons += int(bit[si - 1])
if ons % 2 != p:
break
else:
ans += 1
print(ans)
| N, M = list(map(int, input().split()))
KS = [list(map(int, input().split())) for i in range(M)]
P = list(map(int, input().split()))
ans = 0
for i in range(2**N):
switches = bin(i)[2:].zfill(N)
all_light_on = True
for j in range(M):
_, *S = KS[j]
on = 0
for k, s in enumerate(switches, 1):
if s == "1" and k in S:
on += 1
if on % 2 == P[j]:
continue
else:
all_light_on = False
break
if all_light_on:
ans += 1
print(ans)
| false | 22.727273 | [
"- bit = str(bin(i))[2:].zfill(N)",
"- for (_, *s), p in zip(KS, P):",
"- ons = 0",
"- for si in s:",
"- ons += int(bit[si - 1])",
"- if ons % 2 != p:",
"+ switches = bin(i)[2:].zfill(N)",
"+ all_light_on = True",
"+ for j in range(M):",
"+ _, ... | false | 0.054109 | 0.03667 | 1.475566 | [
"s693266866",
"s265275697"
] |
u309120194 | p03060 | python | s577559061 | s324693634 | 30 | 26 | 9,156 | 9,164 | Accepted | Accepted | 13.33 | N = int(eval(input()))
V = list(map(int, input().split()))
C = list(map(int, input().split()))
D = [V[i] - C[i] for i in range(N)]
ans = 0
for i in range(N):
if D[i] > 0: ans += D[i]
print(ans) | N = int(eval(input()))
V = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
for i in range(N):
tmp = V[i] - C[i]
if tmp > 0: ans += tmp
print(ans) | 10 | 10 | 200 | 183 | N = int(eval(input()))
V = list(map(int, input().split()))
C = list(map(int, input().split()))
D = [V[i] - C[i] for i in range(N)]
ans = 0
for i in range(N):
if D[i] > 0:
ans += D[i]
print(ans)
| N = int(eval(input()))
V = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
for i in range(N):
tmp = V[i] - C[i]
if tmp > 0:
ans += tmp
print(ans)
| false | 0 | [
"-D = [V[i] - C[i] for i in range(N)]",
"- if D[i] > 0:",
"- ans += D[i]",
"+ tmp = V[i] - C[i]",
"+ if tmp > 0:",
"+ ans += tmp"
] | false | 0.03974 | 0.03979 | 0.998739 | [
"s577559061",
"s324693634"
] |
u094191970 | p02936 | python | s368376425 | s144360782 | 1,794 | 1,587 | 62,780 | 62,804 | Accepted | Accepted | 11.54 | from collections import deque
n,q=list(map(int,input().split()))
tree=[[] for i in range(n)]
for i in range(n-1):
i,j=list(map(int,input().split()))
tree[i-1].append(j-1)
tree[j-1].append(i-1)
cnt=[0 for i in range(n)]
for i in range(q):
p,x=list(map(int,input().split()))
cnt[p-1]+=x
seen=set([0])
dq=deque()
dq.append(0)
while dq:
x=dq.popleft()
for i in tree[x]:
# if cnt[i]==-1:
if i not in seen:
seen.add(i)
dq.append(i)
cnt[i]+=cnt[x]
print((*cnt)) | from collections import deque
def main():
n,q=list(map(int,input().split()))
tree=[[] for i in range(n)]
for i in range(n-1):
i,j=list(map(int,input().split()))
tree[i-1].append(j-1)
tree[j-1].append(i-1)
cnt=[0 for i in range(n)]
for i in range(q):
p,x=list(map(int,input().split()))
cnt[p-1]+=x
seen=set([0])
dq=deque()
dq.append(0)
while dq:
x=dq.popleft()
for i in tree[x]:
# if cnt[i]==-1:
if i not in seen:
seen.add(i)
dq.append(i)
cnt[i]+=cnt[x]
print((*cnt))
if __name__ == "__main__":
main() | 30 | 34 | 489 | 563 | from collections import deque
n, q = list(map(int, input().split()))
tree = [[] for i in range(n)]
for i in range(n - 1):
i, j = list(map(int, input().split()))
tree[i - 1].append(j - 1)
tree[j - 1].append(i - 1)
cnt = [0 for i in range(n)]
for i in range(q):
p, x = list(map(int, input().split()))
cnt[p - 1] += x
seen = set([0])
dq = deque()
dq.append(0)
while dq:
x = dq.popleft()
for i in tree[x]:
# if cnt[i]==-1:
if i not in seen:
seen.add(i)
dq.append(i)
cnt[i] += cnt[x]
print((*cnt))
| from collections import deque
def main():
n, q = list(map(int, input().split()))
tree = [[] for i in range(n)]
for i in range(n - 1):
i, j = list(map(int, input().split()))
tree[i - 1].append(j - 1)
tree[j - 1].append(i - 1)
cnt = [0 for i in range(n)]
for i in range(q):
p, x = list(map(int, input().split()))
cnt[p - 1] += x
seen = set([0])
dq = deque()
dq.append(0)
while dq:
x = dq.popleft()
for i in tree[x]:
# if cnt[i]==-1:
if i not in seen:
seen.add(i)
dq.append(i)
cnt[i] += cnt[x]
print((*cnt))
if __name__ == "__main__":
main()
| false | 11.764706 | [
"-n, q = list(map(int, input().split()))",
"-tree = [[] for i in range(n)]",
"-for i in range(n - 1):",
"- i, j = list(map(int, input().split()))",
"- tree[i - 1].append(j - 1)",
"- tree[j - 1].append(i - 1)",
"-cnt = [0 for i in range(n)]",
"-for i in range(q):",
"- p, x = list(map(int,... | false | 0.042091 | 0.043661 | 0.964039 | [
"s368376425",
"s144360782"
] |
u965397031 | p02595 | python | s077735285 | s543215038 | 880 | 443 | 116,644 | 9,016 | Accepted | Accepted | 49.66 | n, d = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]
ans = 0
d = d ** 2
for i in range(n):
if ( x[i] ** 2 + y[i] ** 2 ) <= d:
ans += 1
print(ans) | #下手にlist作って呼び出すよりも、逐次計算するほうが早い?
n, d = list(map(int, input().split()))
ans = 0
d = d ** 2
for i in range(n):
x, y = list(map(int, input().split()))
if d >= x ** 2 + y ** 2:
ans += 1
print(ans) | 11 | 11 | 235 | 208 | n, d = list(map(int, input().split()))
xy = [list(map(int, input().split())) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]
ans = 0
d = d**2
for i in range(n):
if (x[i] ** 2 + y[i] ** 2) <= d:
ans += 1
print(ans)
| # 下手にlist作って呼び出すよりも、逐次計算するほうが早い?
n, d = list(map(int, input().split()))
ans = 0
d = d**2
for i in range(n):
x, y = list(map(int, input().split()))
if d >= x**2 + y**2:
ans += 1
print(ans)
| false | 0 | [
"+# 下手にlist作って呼び出すよりも、逐次計算するほうが早い?",
"-xy = [list(map(int, input().split())) for _ in range(n)]",
"-x, y = [list(i) for i in zip(*xy)]",
"- if (x[i] ** 2 + y[i] ** 2) <= d:",
"+ x, y = list(map(int, input().split()))",
"+ if d >= x**2 + y**2:"
] | false | 0.039647 | 0.087111 | 0.45513 | [
"s077735285",
"s543215038"
] |
u396961814 | p03273 | python | s117196071 | s650834238 | 21 | 18 | 3,188 | 3,188 | Accepted | Accepted | 14.29 | h, w = [int(x) for x in input().split()]
A = []
rm_pos = []
for i in range(h):
a = eval(input())
if a != '.' * w:
A += [list(a)]
flg = True
# 白マスのみの列 検索
for j in range(w):
for i in range(len(A)):
if A[i][j] != '.':
flg = False
break
if flg == True:
rm_pos += [j]
flg = True
rm_pos = reversed(rm_pos)
# 列の削除
for j in rm_pos:
for i in range(len(A)):
del A[i][j]
# 回答出力
for i in range(len(A)):
print((''.join(A[i]))) | h, w = [int(x) for x in input().split()]
A = []
# 列削除用フラグ初期化 1で削除
rm_pos = [1]*w
# 白マスのみの行はリスト追加しない
for i in range(h):
a = eval(input())
if a != '.' * w:
A += [list(a)]
# 白マスのみの列 検索、. が含まれていない場合は 削除フラグを0に
for j in range(w):
for i in range(len(A)):
if A[i][j] != '.':
rm_pos[j] = 0
break
# 後ろ側から 列削除フラグが 1 の列を削除
for j in range(w)[::-1]:
if rm_pos[j] == 1:
for i in range(len(A)):
del A[i][j]
# 回答出力
for i in range(len(A)):
print((''.join(A[i]))) | 31 | 27 | 525 | 548 | h, w = [int(x) for x in input().split()]
A = []
rm_pos = []
for i in range(h):
a = eval(input())
if a != "." * w:
A += [list(a)]
flg = True
# 白マスのみの列 検索
for j in range(w):
for i in range(len(A)):
if A[i][j] != ".":
flg = False
break
if flg == True:
rm_pos += [j]
flg = True
rm_pos = reversed(rm_pos)
# 列の削除
for j in rm_pos:
for i in range(len(A)):
del A[i][j]
# 回答出力
for i in range(len(A)):
print(("".join(A[i])))
| h, w = [int(x) for x in input().split()]
A = []
# 列削除用フラグ初期化 1で削除
rm_pos = [1] * w
# 白マスのみの行はリスト追加しない
for i in range(h):
a = eval(input())
if a != "." * w:
A += [list(a)]
# 白マスのみの列 検索、. が含まれていない場合は 削除フラグを0に
for j in range(w):
for i in range(len(A)):
if A[i][j] != ".":
rm_pos[j] = 0
break
# 後ろ側から 列削除フラグが 1 の列を削除
for j in range(w)[::-1]:
if rm_pos[j] == 1:
for i in range(len(A)):
del A[i][j]
# 回答出力
for i in range(len(A)):
print(("".join(A[i])))
| false | 12.903226 | [
"-rm_pos = []",
"+# 列削除用フラグ初期化 1で削除",
"+rm_pos = [1] * w",
"+# 白マスのみの行はリスト追加しない",
"-flg = True",
"-# 白マスのみの列 検索",
"+# 白マスのみの列 検索、. が含まれていない場合は 削除フラグを0に",
"- flg = False",
"+ rm_pos[j] = 0",
"- if flg == True:",
"- rm_pos += [j]",
"- flg = True",
"-rm_pos = ... | false | 0.037225 | 0.036837 | 1.010527 | [
"s117196071",
"s650834238"
] |
u753682919 | p02887 | python | s088373073 | s327842501 | 1,532 | 42 | 4,664 | 3,316 | Accepted | Accepted | 97.26 | N=int(eval(input()))
S=list(eval(input()))
s=S.copy()
n=0
for i in range(N-1):
if S[i]==S[i+1]:
del s[i+1-n]
n+=1
print((len(s))) | N=int(eval(input()))
S=eval(input())
n=0
for i in range(N-1):
if S[i]==S[i+1]:
n+=1
print((N-n)) | 9 | 7 | 133 | 94 | N = int(eval(input()))
S = list(eval(input()))
s = S.copy()
n = 0
for i in range(N - 1):
if S[i] == S[i + 1]:
del s[i + 1 - n]
n += 1
print((len(s)))
| N = int(eval(input()))
S = eval(input())
n = 0
for i in range(N - 1):
if S[i] == S[i + 1]:
n += 1
print((N - n))
| false | 22.222222 | [
"-S = list(eval(input()))",
"-s = S.copy()",
"+S = eval(input())",
"- del s[i + 1 - n]",
"-print((len(s)))",
"+print((N - n))"
] | false | 0.061501 | 0.042553 | 1.445297 | [
"s088373073",
"s327842501"
] |
u200887663 | p03013 | python | s544955945 | s865255311 | 199 | 174 | 7,832 | 21,256 | Accepted | Accepted | 12.56 | n,m=list(map(int,input().split()))
broken=[False for i in range(n+1)]
for i in range(m):
a=int(eval(input()))
broken[a]=True
ans=[1]
if broken[1]:
ans.append(0)
else:
ans.append(1)
for i in range(2,n+1):
if broken[i]:
ans.append(0)
else:
ans.append((ans[i-1]+ans[i-2])%1000000007)
print((ans[n]))
| #n=int(input())
n,m=list(map(int,input().split()))
#t=int(input())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
dp=[0]*(n+1)
mod=10**9+7
broken={i:False for i in range(1,n+1)}
for i in range(m):
a=int(eval(input()))
broken[a]=True
if broken[1]:
dp[1]=0
else:
dp[1]=1
dp[0]=1
for i in range(2,n+1):
if not broken[i]:
dp[i]=(dp[i-1]+dp[i-2])%mod
print((dp[n]))
| 16 | 22 | 338 | 440 | n, m = list(map(int, input().split()))
broken = [False for i in range(n + 1)]
for i in range(m):
a = int(eval(input()))
broken[a] = True
ans = [1]
if broken[1]:
ans.append(0)
else:
ans.append(1)
for i in range(2, n + 1):
if broken[i]:
ans.append(0)
else:
ans.append((ans[i - 1] + ans[i - 2]) % 1000000007)
print((ans[n]))
| # n=int(input())
n, m = list(map(int, input().split()))
# t=int(input())
# al=list(map(int,input().split()))
# l=[list(map(int,input().split())) for i in range(n)]
dp = [0] * (n + 1)
mod = 10**9 + 7
broken = {i: False for i in range(1, n + 1)}
for i in range(m):
a = int(eval(input()))
broken[a] = True
if broken[1]:
dp[1] = 0
else:
dp[1] = 1
dp[0] = 1
for i in range(2, n + 1):
if not broken[i]:
dp[i] = (dp[i - 1] + dp[i - 2]) % mod
print((dp[n]))
| false | 27.272727 | [
"+# n=int(input())",
"-broken = [False for i in range(n + 1)]",
"+# t=int(input())",
"+# al=list(map(int,input().split()))",
"+# l=[list(map(int,input().split())) for i in range(n)]",
"+dp = [0] * (n + 1)",
"+mod = 10**9 + 7",
"+broken = {i: False for i in range(1, n + 1)}",
"-ans = [1]",
"- an... | false | 0.037588 | 0.037992 | 0.989367 | [
"s544955945",
"s865255311"
] |
u137226361 | p02996 | python | s575139223 | s021939783 | 820 | 721 | 39,796 | 39,768 | Accepted | Accepted | 12.07 | n = int(eval(input()))
ls = []
for _ in range(n):
a, b = list(map(int, input().split()))
ls.append([b,a])
ls = sorted(ls)
t=0
for i in ls:
t += i[1]
if t > i[0]:
print('No')
exit(0)
print('Yes') | def main():
n = int(eval(input()))
ls = []
for _ in range(n):
a, b = list(map(int, input().split()))
ls.append([b,a])
ls = sorted(ls)
t=0
for i in ls:
t += i[1]
if t > i[0]:
print('No')
exit(0)
print('Yes')
if __name__ == '__main__':
main() | 13 | 16 | 227 | 332 | n = int(eval(input()))
ls = []
for _ in range(n):
a, b = list(map(int, input().split()))
ls.append([b, a])
ls = sorted(ls)
t = 0
for i in ls:
t += i[1]
if t > i[0]:
print("No")
exit(0)
print("Yes")
| def main():
n = int(eval(input()))
ls = []
for _ in range(n):
a, b = list(map(int, input().split()))
ls.append([b, a])
ls = sorted(ls)
t = 0
for i in ls:
t += i[1]
if t > i[0]:
print("No")
exit(0)
print("Yes")
if __name__ == "__main__":
main()
| false | 18.75 | [
"-n = int(eval(input()))",
"-ls = []",
"-for _ in range(n):",
"- a, b = list(map(int, input().split()))",
"- ls.append([b, a])",
"-ls = sorted(ls)",
"-t = 0",
"-for i in ls:",
"- t += i[1]",
"- if t > i[0]:",
"- print(\"No\")",
"- exit(0)",
"-print(\"Yes\")",
"+de... | false | 0.139409 | 0.043805 | 3.182468 | [
"s575139223",
"s021939783"
] |
u150984829 | p00012 | python | s708872570 | s126693480 | 30 | 20 | 5,592 | 5,588 | Accepted | Accepted | 33.33 | import sys
def f(h,i,j,k):
z=(j-h)*(y-k)-(k-i)*(x-j);return([-1,1][z>0],0)[z==0]
for e in sys.stdin:
p,q,r,s,t,u,x,y=list(map(float,e.split()))
g=[p,q,r,s,t,u]
print((['NO','YES'][f(*g[:4])==f(*g[2:6])==f(*g[4:],*g[:2])]))
| import sys
def f(h,i,j,k):
z=(j-h)*(y-k)-(k-i)*(x-j);return([-1,1][z>0],0)[z==0]
for e in sys.stdin:
p,q,r,s,t,u,x,y=list(map(float,e.split()))
print((['NO','YES'][f(p,q,r,s)==f(r,s,t,u)==f(t,u,p,q)]))
| 7 | 6 | 225 | 202 | import sys
def f(h, i, j, k):
z = (j - h) * (y - k) - (k - i) * (x - j)
return ([-1, 1][z > 0], 0)[z == 0]
for e in sys.stdin:
p, q, r, s, t, u, x, y = list(map(float, e.split()))
g = [p, q, r, s, t, u]
print((["NO", "YES"][f(*g[:4]) == f(*g[2:6]) == f(*g[4:], *g[:2])]))
| import sys
def f(h, i, j, k):
z = (j - h) * (y - k) - (k - i) * (x - j)
return ([-1, 1][z > 0], 0)[z == 0]
for e in sys.stdin:
p, q, r, s, t, u, x, y = list(map(float, e.split()))
print((["NO", "YES"][f(p, q, r, s) == f(r, s, t, u) == f(t, u, p, q)]))
| false | 14.285714 | [
"- g = [p, q, r, s, t, u]",
"- print(([\"NO\", \"YES\"][f(*g[:4]) == f(*g[2:6]) == f(*g[4:], *g[:2])]))",
"+ print(([\"NO\", \"YES\"][f(p, q, r, s) == f(r, s, t, u) == f(t, u, p, q)]))"
] | false | 0.041288 | 0.066831 | 0.617791 | [
"s708872570",
"s126693480"
] |
u620084012 | p03831 | python | s760509029 | s607012657 | 244 | 223 | 62,704 | 62,704 | Accepted | Accepted | 8.61 | import sys
import math
def input():
return sys.stdin.readline()[:-1]
def main():
N, A, B = list(map(int,input().split()))
X = sorted(list(map(int,input().split())))
Y = [0 for k in range(N)]
for k in range(1,N):
Y[k-1] = X[k] - X[k-1]
Y = sorted(Y)
ans = 0
for e in Y:
ans += min(e*A,B)
print(ans)
if __name__ == '__main__':
main()
| N, A, B = list(map(int,input().split()))
X = list(map(int,input().split()))
ans = 0
for k in range(N-1):
ans += min((X[k+1]-X[k])*A,B)
print(ans)
| 20 | 6 | 404 | 149 | import sys
import math
def input():
return sys.stdin.readline()[:-1]
def main():
N, A, B = list(map(int, input().split()))
X = sorted(list(map(int, input().split())))
Y = [0 for k in range(N)]
for k in range(1, N):
Y[k - 1] = X[k] - X[k - 1]
Y = sorted(Y)
ans = 0
for e in Y:
ans += min(e * A, B)
print(ans)
if __name__ == "__main__":
main()
| N, A, B = list(map(int, input().split()))
X = list(map(int, input().split()))
ans = 0
for k in range(N - 1):
ans += min((X[k + 1] - X[k]) * A, B)
print(ans)
| false | 70 | [
"-import sys",
"-import math",
"-",
"-",
"-def input():",
"- return sys.stdin.readline()[:-1]",
"-",
"-",
"-def main():",
"- N, A, B = list(map(int, input().split()))",
"- X = sorted(list(map(int, input().split())))",
"- Y = [0 for k in range(N)]",
"- for k in range(1, N):",
... | false | 0.068652 | 0.036863 | 1.862362 | [
"s760509029",
"s607012657"
] |
u600402037 | p03045 | python | s151861846 | s411070296 | 562 | 411 | 23,508 | 14,616 | Accepted | Accepted | 26.87 | import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M = lr()
# Aでxの根を求める
def find(A, x):
p = A[x]
if p == x:
return x
a = find(A, p)
A[x] = a
return a
# Aでxとyの属する集合の併合
def union(A, x, y):
if find(A, x) > find(A, y):
bx, by = find(A, y), find(A, x)
else:
bx, by = find(A, x), find(A, y)
# 根をbx(値の小さい方)に統一
A[by] = bx
V = [i for i in range(N)]
for i in range(M):
x, y, z = lr()
if find(V, x-1) != find(V, y-1):
union(V, x-1, y-1)
answer = [find(V, x) for x in set(V)]
print((len(set(answer))))
# 36
| # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# Aでxの根を求める
def find(A,x):
p = A[x]
if p == x: return x
a = find(A,p)
A[x] = a
return a
# Aでxとyの属する集合の併合
def union(A, x, y):
if find(A,x) > find(A,y):
bx, by = find(A,y), find(A,x)
else:
bx, by = find(A,x), find(A,y)
A[by] = bx # 根をbxに統一
N, M = lr()
V = [x for x in range(N+1)]
for _ in range(M):
x, y, z = lr()
if find(V, x) != find(V, y):
union(V, x, y)
V = [find(V, x) for x in V]
s = set(V[1:])
answer = len(s)
print(answer)
# 55
| 37 | 34 | 733 | 670 | import sys
import numpy as np
sys.setrecursionlimit(10**7)
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M = lr()
# Aでxの根を求める
def find(A, x):
p = A[x]
if p == x:
return x
a = find(A, p)
A[x] = a
return a
# Aでxとyの属する集合の併合
def union(A, x, y):
if find(A, x) > find(A, y):
bx, by = find(A, y), find(A, x)
else:
bx, by = find(A, x), find(A, y)
# 根をbx(値の小さい方)に統一
A[by] = bx
V = [i for i in range(N)]
for i in range(M):
x, y, z = lr()
if find(V, x - 1) != find(V, y - 1):
union(V, x - 1, y - 1)
answer = [find(V, x) for x in set(V)]
print((len(set(answer))))
# 36
| # coding: utf-8
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# Aでxの根を求める
def find(A, x):
p = A[x]
if p == x:
return x
a = find(A, p)
A[x] = a
return a
# Aでxとyの属する集合の併合
def union(A, x, y):
if find(A, x) > find(A, y):
bx, by = find(A, y), find(A, x)
else:
bx, by = find(A, x), find(A, y)
A[by] = bx # 根をbxに統一
N, M = lr()
V = [x for x in range(N + 1)]
for _ in range(M):
x, y, z = lr()
if find(V, x) != find(V, y):
union(V, x, y)
V = [find(V, x) for x in V]
s = set(V[1:])
answer = len(s)
print(answer)
# 55
| false | 8.108108 | [
"+# coding: utf-8",
"-import numpy as np",
"-sys.setrecursionlimit(10**7)",
"-N, M = lr()",
"- # 根をbx(値の小さい方)に統一",
"- A[by] = bx",
"+ A[by] = bx # 根をbxに統一",
"-V = [i for i in range(N)]",
"-for i in range(M):",
"+N, M = lr()",
"+V = [x for x in range(N + 1)]",
"+for _ in range(M):",
... | false | 0.073988 | 0.077181 | 0.958623 | [
"s151861846",
"s411070296"
] |
u636683284 | p03574 | python | s532154013 | s153901232 | 183 | 95 | 39,920 | 68,356 | Accepted | Accepted | 48.09 | h,w = list(map(int,input().split()))
l=[]
for i in range(h):
s = list(eval(input()))
l.append(s)
for i in range(h):
for j in range(w):
kazu = 0
if l[i][j] == '.':
if j != 0 and l[i][j-1] == '#':
kazu += 1
if j != w-1 and l[i][j+1] == '#':
kazu += 1
if i != 0 and l[i-1][j]== '#':
kazu += 1
if i != h-1 and l[i+1][j] == '#':
kazu += 1
if i >= 1 and j >= 1 and l[i-1][j-1] == '#':
kazu += 1
if i >= 1 and j <= w-2 and l[i-1][j+1] == '#':
kazu += 1
if i <= h-2 and j >= 1 and l[i+1][j-1] == '#':
kazu += 1
if i <= h-2 and j <= w-2 and l[i+1][j+1] == '#':
kazu += 1
l[i][j] = str(kazu)
for i in range(h):
print((''.join(l[i]))) | h,w = list(map(int,input().split()))
l = [['*']*(w+2)]
for i in range(h):
l.append(['*']+list(eval(input()))+['*'])
l.append(['*']*(w+2))
for i in range(1,h+1):
s = ''
for j in range(1,w+1):
directions = [(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1),(-1,0),(-1,1)]
alist = [(i+dir[0],j+dir[1]) for dir in directions]
cnt = 0
for a in alist:
if l[a[0]][a[1]] == '#':
cnt += 1
if l[i][j] == '#':
s += '#'
else:
s += str(cnt)
print(s) | 28 | 21 | 770 | 552 | h, w = list(map(int, input().split()))
l = []
for i in range(h):
s = list(eval(input()))
l.append(s)
for i in range(h):
for j in range(w):
kazu = 0
if l[i][j] == ".":
if j != 0 and l[i][j - 1] == "#":
kazu += 1
if j != w - 1 and l[i][j + 1] == "#":
kazu += 1
if i != 0 and l[i - 1][j] == "#":
kazu += 1
if i != h - 1 and l[i + 1][j] == "#":
kazu += 1
if i >= 1 and j >= 1 and l[i - 1][j - 1] == "#":
kazu += 1
if i >= 1 and j <= w - 2 and l[i - 1][j + 1] == "#":
kazu += 1
if i <= h - 2 and j >= 1 and l[i + 1][j - 1] == "#":
kazu += 1
if i <= h - 2 and j <= w - 2 and l[i + 1][j + 1] == "#":
kazu += 1
l[i][j] = str(kazu)
for i in range(h):
print(("".join(l[i])))
| h, w = list(map(int, input().split()))
l = [["*"] * (w + 2)]
for i in range(h):
l.append(["*"] + list(eval(input())) + ["*"])
l.append(["*"] * (w + 2))
for i in range(1, h + 1):
s = ""
for j in range(1, w + 1):
directions = [
(0, 1),
(1, 1),
(1, 0),
(1, -1),
(0, -1),
(-1, -1),
(-1, 0),
(-1, 1),
]
alist = [(i + dir[0], j + dir[1]) for dir in directions]
cnt = 0
for a in alist:
if l[a[0]][a[1]] == "#":
cnt += 1
if l[i][j] == "#":
s += "#"
else:
s += str(cnt)
print(s)
| false | 25 | [
"-l = []",
"+l = [[\"*\"] * (w + 2)]",
"- s = list(eval(input()))",
"- l.append(s)",
"-for i in range(h):",
"- for j in range(w):",
"- kazu = 0",
"- if l[i][j] == \".\":",
"- if j != 0 and l[i][j - 1] == \"#\":",
"- kazu += 1",
"- if j ... | false | 0.061277 | 0.051191 | 1.197028 | [
"s532154013",
"s153901232"
] |
u995053308 | p03986 | python | s501252669 | s010178375 | 133 | 117 | 5,648 | 5,652 | Accepted | Accepted | 12.03 | # -*- coding: cp932 -*-
import sys
import os
import re
import datetime
import bisect
### main ###
X = eval(input())
restS = []
for c in X:
#print("c = {}".format(c))
restS.append(c)
if c == 'T':
while(len(restS) >= 2):
#print("restS = {}, last 2 string = {} ".format(restS, restS[-2:]))
if("".join(restS[-2:]) == 'ST'):
#print("hit")
#restS = restS[:-2] # TLE
del restS[-2:]
#print("new restS = {}".format(restS))
else:
#print("no hit")
break # out of while
print((len(restS))) | # -*- coding: cp932 -*-
import sys
import os
import re
import datetime
import bisect
### main ###
X = eval(input())
restS = []
for c in X:
#print("c = {}".format(c))
restS.append(c)
if c == 'T':
while(len(restS) >= 2):
#print("restS = {}, last 2 string = {} ".format(restS, restS[-2:]))
#if("".join(restS[-2:]) == 'ST'):
if(restS[-2] == 'S' and restS[-1] == 'T'): # Higher Speed than join ?
#print("hit restS[-2] = {}, restS[-1] = {}".format(restS[-2], restS[-1]))
#restS = restS[:-2] # TLE
del restS[-2:]
#print("new restS = {}".format(restS))
else:
#print("no hit restS = {}".format(restS))
break # out of while
print((len(restS))) | 29 | 30 | 654 | 823 | # -*- coding: cp932 -*-
import sys
import os
import re
import datetime
import bisect
### main ###
X = eval(input())
restS = []
for c in X:
# print("c = {}".format(c))
restS.append(c)
if c == "T":
while len(restS) >= 2:
# print("restS = {}, last 2 string = {} ".format(restS, restS[-2:]))
if "".join(restS[-2:]) == "ST":
# print("hit")
# restS = restS[:-2] # TLE
del restS[-2:]
# print("new restS = {}".format(restS))
else:
# print("no hit")
break # out of while
print((len(restS)))
| # -*- coding: cp932 -*-
import sys
import os
import re
import datetime
import bisect
### main ###
X = eval(input())
restS = []
for c in X:
# print("c = {}".format(c))
restS.append(c)
if c == "T":
while len(restS) >= 2:
# print("restS = {}, last 2 string = {} ".format(restS, restS[-2:]))
# if("".join(restS[-2:]) == 'ST'):
if restS[-2] == "S" and restS[-1] == "T": # Higher Speed than join ?
# print("hit restS[-2] = {}, restS[-1] = {}".format(restS[-2], restS[-1]))
# restS = restS[:-2] # TLE
del restS[-2:]
# print("new restS = {}".format(restS))
else:
# print("no hit restS = {}".format(restS))
break # out of while
print((len(restS)))
| false | 3.333333 | [
"- if \"\".join(restS[-2:]) == \"ST\":",
"- # print(\"hit\")",
"+ # if(\"\".join(restS[-2:]) == 'ST'):",
"+ if restS[-2] == \"S\" and restS[-1] == \"T\": # Higher Speed than join ?",
"+ # print(\"hit restS[-2] = {}, restS[-1] = {}\".format(rest... | false | 0.167676 | 0.049993 | 3.353995 | [
"s501252669",
"s010178375"
] |
u606878291 | p02983 | python | s644369973 | s228643952 | 750 | 60 | 2,940 | 2,940 | Accepted | Accepted | 92 | L, R = list(map(int, input().split(' ')))
if R - L >= 2018:
print((0))
else:
min_value = 2018
for i in range(L, R):
for j in range(i + 1, R + 1):
min_value = min(min_value, i * j % 2019)
print(min_value)
| L, R = list(map(int, input().split(' ')))
min_value = 2018
for i in range(L, R):
for j in range(i + 1, R + 1):
min_value = min(min_value, i * j % 2019)
if min_value == 0:
break
else:
continue
break
print(min_value)
| 10 | 13 | 242 | 275 | L, R = list(map(int, input().split(" ")))
if R - L >= 2018:
print((0))
else:
min_value = 2018
for i in range(L, R):
for j in range(i + 1, R + 1):
min_value = min(min_value, i * j % 2019)
print(min_value)
| L, R = list(map(int, input().split(" ")))
min_value = 2018
for i in range(L, R):
for j in range(i + 1, R + 1):
min_value = min(min_value, i * j % 2019)
if min_value == 0:
break
else:
continue
break
print(min_value)
| false | 23.076923 | [
"-if R - L >= 2018:",
"- print((0))",
"-else:",
"- min_value = 2018",
"- for i in range(L, R):",
"- for j in range(i + 1, R + 1):",
"- min_value = min(min_value, i * j % 2019)",
"- print(min_value)",
"+min_value = 2018",
"+for i in range(L, R):",
"+ for j in rang... | false | 0.068139 | 0.007032 | 9.689758 | [
"s644369973",
"s228643952"
] |
u562935282 | p02913 | python | s936370814 | s737964494 | 573 | 524 | 231,560 | 229,768 | Accepted | Accepted | 8.55 | # 解説
def main():
N = int(eval(input()))
s = eval(input())
dp = [[0] * N for _ in range(N)]
ans = 0
for i in reversed(list(range(N))):
for j in reversed(list(range(i, N))):
if s[i] == s[j]:
if i + 1 < N and j + 1 < N:
dp[i][j] = min(dp[i + 1][j + 1] + 1, j - i)
ans = max(ans, dp[i][j])
else:
dp[i][j] = 1
else:
dp[i][j] = 0
print(ans)
if __name__ == '__main__':
main()
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
| # 解説
def main():
N = int(eval(input()))
s = eval(input())
dp = [[0] * (N + 1) for _ in range(N + 1)]
ans = 0
for i in reversed(list(range(N))):
for j in reversed(list(range(i, N))):
if s[i] == s[j]:
dp[i][j] = min(dp[i + 1][j + 1] + 1, j - i)
ans = max(ans, dp[i][j])
print(ans)
if __name__ == '__main__':
main()
| 32 | 18 | 682 | 390 | # 解説
def main():
N = int(eval(input()))
s = eval(input())
dp = [[0] * N for _ in range(N)]
ans = 0
for i in reversed(list(range(N))):
for j in reversed(list(range(i, N))):
if s[i] == s[j]:
if i + 1 < N and j + 1 < N:
dp[i][j] = min(dp[i + 1][j + 1] + 1, j - i)
ans = max(ans, dp[i][j])
else:
dp[i][j] = 1
else:
dp[i][j] = 0
print(ans)
if __name__ == "__main__":
main()
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
| # 解説
def main():
N = int(eval(input()))
s = eval(input())
dp = [[0] * (N + 1) for _ in range(N + 1)]
ans = 0
for i in reversed(list(range(N))):
for j in reversed(list(range(i, N))):
if s[i] == s[j]:
dp[i][j] = min(dp[i + 1][j + 1] + 1, j - i)
ans = max(ans, dp[i][j])
print(ans)
if __name__ == "__main__":
main()
| false | 43.75 | [
"- dp = [[0] * N for _ in range(N)]",
"+ dp = [[0] * (N + 1) for _ in range(N + 1)]",
"- if i + 1 < N and j + 1 < N:",
"- dp[i][j] = min(dp[i + 1][j + 1] + 1, j - i)",
"- ans = max(ans, dp[i][j])",
"- else:",
"- ... | false | 0.038418 | 0.035986 | 1.067603 | [
"s936370814",
"s737964494"
] |
u815878613 | p02843 | python | s961251340 | s092235169 | 1,614 | 17 | 21,356 | 2,940 | Accepted | Accepted | 98.95 | import sys
import numpy as np
def main():
X = int(eval(input()))
V = (100, 101, 102, 103, 104, 105)
m1 = X // 100
if m1 == 0:
print((0))
sys.exit()
dp = np.full([(m1 + 1) * 105], 10**9, np.int32)
dp[0] = 0
for j in range(1, m1 + 1):
for v in V:
w = v * j
p_dp = dp.copy()
np.minimum(dp[w:], p_dp[:-w] + w, out=dp[w:])
if X in dp:
print((1))
else:
print((0))
main()
| X = int(eval(input()))
for i in range(1000):
if 100 * i <= X and X <= 105 * i:
print((1))
break
else:
print((0))
| 27 | 7 | 497 | 133 | import sys
import numpy as np
def main():
X = int(eval(input()))
V = (100, 101, 102, 103, 104, 105)
m1 = X // 100
if m1 == 0:
print((0))
sys.exit()
dp = np.full([(m1 + 1) * 105], 10**9, np.int32)
dp[0] = 0
for j in range(1, m1 + 1):
for v in V:
w = v * j
p_dp = dp.copy()
np.minimum(dp[w:], p_dp[:-w] + w, out=dp[w:])
if X in dp:
print((1))
else:
print((0))
main()
| X = int(eval(input()))
for i in range(1000):
if 100 * i <= X and X <= 105 * i:
print((1))
break
else:
print((0))
| false | 74.074074 | [
"-import sys",
"-import numpy as np",
"-",
"-",
"-def main():",
"- X = int(eval(input()))",
"- V = (100, 101, 102, 103, 104, 105)",
"- m1 = X // 100",
"- if m1 == 0:",
"- print((0))",
"- sys.exit()",
"- dp = np.full([(m1 + 1) * 105], 10**9, np.int32)",
"- dp[0... | false | 0.435306 | 0.074286 | 5.859869 | [
"s961251340",
"s092235169"
] |
u380524497 | p02901 | python | s401920463 | s282583299 | 769 | 430 | 3,188 | 3,836 | Accepted | Accepted | 44.08 | def main():
n, m = list(map(int, input().split()))
all_patterns = 2**n
DP = [10**9] * all_patterns
DP[0] = 0
for _ in range(m):
cost, types = list(map(int, input().split()))
to_open = list(map(int, input().split()))
openable = 0
for open in to_open:
openable += 1 << (open-1)
for opened in range(all_patterns):
pattern = opened | openable
new_cost = DP[opened] + cost
if DP[pattern] > new_cost:
DP[pattern] = new_cost
full_open = 2**n - 1
ans = DP[full_open]
if ans == 10 ** 9:
ans = -1
print(ans)
if __name__ == '__main__':
main()
| def main():
n, m = list(map(int, input().split()))
DP = [10**9] * 2**n
DP[0] = 0
updated_patterns = {0}
for _ in range(m):
cost, types = list(map(int, input().split()))
to_open = list(map(int, input().split()))
openable = 0
for open in to_open:
openable += 1 << (open-1)
new_updated = set()
for opened in updated_patterns:
pattern = opened | openable
new_cost = DP[opened] + cost
if DP[pattern] > new_cost:
DP[pattern] = new_cost
new_updated.add(pattern)
updated_patterns |= new_updated
full_open = 2**n - 1
ans = DP[full_open]
if ans == 10 ** 9:
ans = -1
print(ans)
if __name__ == '__main__':
main()
| 29 | 32 | 714 | 810 | def main():
n, m = list(map(int, input().split()))
all_patterns = 2**n
DP = [10**9] * all_patterns
DP[0] = 0
for _ in range(m):
cost, types = list(map(int, input().split()))
to_open = list(map(int, input().split()))
openable = 0
for open in to_open:
openable += 1 << (open - 1)
for opened in range(all_patterns):
pattern = opened | openable
new_cost = DP[opened] + cost
if DP[pattern] > new_cost:
DP[pattern] = new_cost
full_open = 2**n - 1
ans = DP[full_open]
if ans == 10**9:
ans = -1
print(ans)
if __name__ == "__main__":
main()
| def main():
n, m = list(map(int, input().split()))
DP = [10**9] * 2**n
DP[0] = 0
updated_patterns = {0}
for _ in range(m):
cost, types = list(map(int, input().split()))
to_open = list(map(int, input().split()))
openable = 0
for open in to_open:
openable += 1 << (open - 1)
new_updated = set()
for opened in updated_patterns:
pattern = opened | openable
new_cost = DP[opened] + cost
if DP[pattern] > new_cost:
DP[pattern] = new_cost
new_updated.add(pattern)
updated_patterns |= new_updated
full_open = 2**n - 1
ans = DP[full_open]
if ans == 10**9:
ans = -1
print(ans)
if __name__ == "__main__":
main()
| false | 9.375 | [
"- all_patterns = 2**n",
"- DP = [10**9] * all_patterns",
"+ DP = [10**9] * 2**n",
"+ updated_patterns = {0}",
"- for opened in range(all_patterns):",
"+ new_updated = set()",
"+ for opened in updated_patterns:",
"+ new_updated.add(pattern)",
"+ ... | false | 0.035374 | 0.041624 | 0.84984 | [
"s401920463",
"s282583299"
] |
u493520238 | p02948 | python | s981321878 | s697942871 | 452 | 307 | 27,344 | 89,376 | Accepted | Accepted | 32.08 | import heapq
N, M = list(map(int, input().split()))
day_rew = {}
for _ in range(N):
a, b = list(map(int, input().split()))
day_rew.setdefault(a,[])
day_rew[a].append(b)
ans = 0
job_rew = []
heapq.heapify(job_rew)
for i in range(1, M+1):
if i in day_rew:
for r in day_rew[i]:
heapq.heappush(job_rew, r*(-1))
if job_rew:
this_day_rew = heapq.heappop(job_rew)*(-1)
ans += this_day_rew
print(ans)
| import heapq
n,m = list(map(int, input().split()))
day_rews_l = [ [] for _ in range(m+1)]
for _ in range(n):
a,b = list(map(int, input().split()))
if a > m: continue
day_rews_l[a].append(b)
jobs = []
ans = 0
for i in range(1,m+1):
for rew in day_rews_l[i]:
heapq.heappush(jobs, (-1)*rew)
if jobs:
rew_i = heapq.heappop(jobs)
ans += (-1)*rew_i
print(ans)
| 23 | 21 | 466 | 414 | import heapq
N, M = list(map(int, input().split()))
day_rew = {}
for _ in range(N):
a, b = list(map(int, input().split()))
day_rew.setdefault(a, [])
day_rew[a].append(b)
ans = 0
job_rew = []
heapq.heapify(job_rew)
for i in range(1, M + 1):
if i in day_rew:
for r in day_rew[i]:
heapq.heappush(job_rew, r * (-1))
if job_rew:
this_day_rew = heapq.heappop(job_rew) * (-1)
ans += this_day_rew
print(ans)
| import heapq
n, m = list(map(int, input().split()))
day_rews_l = [[] for _ in range(m + 1)]
for _ in range(n):
a, b = list(map(int, input().split()))
if a > m:
continue
day_rews_l[a].append(b)
jobs = []
ans = 0
for i in range(1, m + 1):
for rew in day_rews_l[i]:
heapq.heappush(jobs, (-1) * rew)
if jobs:
rew_i = heapq.heappop(jobs)
ans += (-1) * rew_i
print(ans)
| false | 8.695652 | [
"-N, M = list(map(int, input().split()))",
"-day_rew = {}",
"-for _ in range(N):",
"+n, m = list(map(int, input().split()))",
"+day_rews_l = [[] for _ in range(m + 1)]",
"+for _ in range(n):",
"- day_rew.setdefault(a, [])",
"- day_rew[a].append(b)",
"+ if a > m:",
"+ continue",
"... | false | 0.068643 | 0.036688 | 1.87101 | [
"s981321878",
"s697942871"
] |
u371763408 | p03212 | python | s692606310 | s870631519 | 324 | 96 | 19,228 | 2,940 | Accepted | Accepted | 70.37 | n=int(eval(input()))
s=[]
def dfs(string,cur):
if cur==len(str(n)):
if string.count('3')>0 and string.count('5')>0 and string.count('7'):
s.append(string)
return
dfs(string+"",cur+1)
dfs(string+"7",cur+1)
dfs(string+"5",cur+1)
dfs(string+"3",cur+1)
dfs("",0)
cnt=0
for i in set(s):
if int(i)<=n:
cnt+=1
print(cnt) | n=int(eval(input()))
def dfs(s):
if int(s)>n:
return 0
ret = 1 if all(s.count(c) for c in "753") else 0
for c in '753':
ret+=dfs(s+c)
return ret
print((dfs("0"))) | 18 | 9 | 355 | 178 | n = int(eval(input()))
s = []
def dfs(string, cur):
if cur == len(str(n)):
if string.count("3") > 0 and string.count("5") > 0 and string.count("7"):
s.append(string)
return
dfs(string + "", cur + 1)
dfs(string + "7", cur + 1)
dfs(string + "5", cur + 1)
dfs(string + "3", cur + 1)
dfs("", 0)
cnt = 0
for i in set(s):
if int(i) <= n:
cnt += 1
print(cnt)
| n = int(eval(input()))
def dfs(s):
if int(s) > n:
return 0
ret = 1 if all(s.count(c) for c in "753") else 0
for c in "753":
ret += dfs(s + c)
return ret
print((dfs("0")))
| false | 50 | [
"-s = []",
"-def dfs(string, cur):",
"- if cur == len(str(n)):",
"- if string.count(\"3\") > 0 and string.count(\"5\") > 0 and string.count(\"7\"):",
"- s.append(string)",
"- return",
"- dfs(string + \"\", cur + 1)",
"- dfs(string + \"7\", cur + 1)",
"- dfs(strin... | false | 0.120618 | 0.045291 | 2.663184 | [
"s692606310",
"s870631519"
] |
u692746605 | p02888 | python | s476430691 | s063078282 | 1,632 | 1,324 | 3,188 | 3,188 | Accepted | Accepted | 18.87 | import bisect
n=int(eval(input()))
l=sorted(map(int,input().split()))
t=0
for i in range(n):
for j in range(i+1,n):
a = j+1
b = bisect.bisect_left(l,l[i]+l[j])
t += b-a if b>a else 0
print(t)
| import bisect
n=int(eval(input()))
l=sorted(map(int,input().split()))
t=0
for i in range(n):
for j in range(i+1,n):
t += bisect.bisect_left(l,l[i]+l[j]) - j - 1
print(t)
| 13 | 11 | 215 | 183 | import bisect
n = int(eval(input()))
l = sorted(map(int, input().split()))
t = 0
for i in range(n):
for j in range(i + 1, n):
a = j + 1
b = bisect.bisect_left(l, l[i] + l[j])
t += b - a if b > a else 0
print(t)
| import bisect
n = int(eval(input()))
l = sorted(map(int, input().split()))
t = 0
for i in range(n):
for j in range(i + 1, n):
t += bisect.bisect_left(l, l[i] + l[j]) - j - 1
print(t)
| false | 15.384615 | [
"- a = j + 1",
"- b = bisect.bisect_left(l, l[i] + l[j])",
"- t += b - a if b > a else 0",
"+ t += bisect.bisect_left(l, l[i] + l[j]) - j - 1"
] | false | 0.043221 | 0.136992 | 0.3155 | [
"s476430691",
"s063078282"
] |
u393253137 | p02954 | python | s680591957 | s679942598 | 165 | 81 | 10,324 | 6,400 | Accepted | Accepted | 50.91 | S = eval(input())
N = len(S)
# Rなら右隣, Lなら左隣のindexを格納
X = [i-1 if S[i] == "L" else i+1 for i in range(N)]
# ループを何度行ってもi番目の元はi+偶数番目にしか移動しない.
# RLの部分は互換の後, 恒等写像なので不変.
# RRRやLLLの部分は 1ループで2の冪乗で精度が上がる.
# ex.) RRRRRRR だと, k回ループで index i の元が i + 2**kに移動する.
# log(2**20)=6.01より10**5程度なら20回ループで十分.
for _ in range(20):
X = [X[x] for x in X]
# はじめにi番目のマスにいた子どもがX[i]番目のマスに移動した.
A = [0]*N
for x in X:
A[x] += 1
print((*A)) | #別解
def main():
S = eval(input())
Ans = [0]*len(S)
# 左隣までに Rがr個, Lがl個連続して並んでいる.
r, l = 1, 0
# 左からS+'R'をcheckしていく.
# RRRRRは全て0.
# RLが出てきたら 続くLLLLLの部分は全て0で
# 次にRが出れば初めのRLを決定できる.
for i, s in enumerate(S[1:]+'R', 1):
if s == 'R':
# Rの左隣がLのとき
if l :
Ans[i - l] = r//2 + (l+1)//2
Ans[i - l - 1] = (r+1)//2 + l//2
r, l = 1, 0
# Rの左隣がRのとき
else:
r += 1
else:
l += 1
print((*Ans))
main() | 17 | 27 | 425 | 627 | S = eval(input())
N = len(S)
# Rなら右隣, Lなら左隣のindexを格納
X = [i - 1 if S[i] == "L" else i + 1 for i in range(N)]
# ループを何度行ってもi番目の元はi+偶数番目にしか移動しない.
# RLの部分は互換の後, 恒等写像なので不変.
# RRRやLLLの部分は 1ループで2の冪乗で精度が上がる.
# ex.) RRRRRRR だと, k回ループで index i の元が i + 2**kに移動する.
# log(2**20)=6.01より10**5程度なら20回ループで十分.
for _ in range(20):
X = [X[x] for x in X]
# はじめにi番目のマスにいた子どもがX[i]番目のマスに移動した.
A = [0] * N
for x in X:
A[x] += 1
print((*A))
| # 別解
def main():
S = eval(input())
Ans = [0] * len(S)
# 左隣までに Rがr個, Lがl個連続して並んでいる.
r, l = 1, 0
# 左からS+'R'をcheckしていく.
# RRRRRは全て0.
# RLが出てきたら 続くLLLLLの部分は全て0で
# 次にRが出れば初めのRLを決定できる.
for i, s in enumerate(S[1:] + "R", 1):
if s == "R":
# Rの左隣がLのとき
if l:
Ans[i - l] = r // 2 + (l + 1) // 2
Ans[i - l - 1] = (r + 1) // 2 + l // 2
r, l = 1, 0
# Rの左隣がRのとき
else:
r += 1
else:
l += 1
print((*Ans))
main()
| false | 37.037037 | [
"-S = eval(input())",
"-N = len(S)",
"-# Rなら右隣, Lなら左隣のindexを格納",
"-X = [i - 1 if S[i] == \"L\" else i + 1 for i in range(N)]",
"-# ループを何度行ってもi番目の元はi+偶数番目にしか移動しない.",
"-# RLの部分は互換の後, 恒等写像なので不変.",
"-# RRRやLLLの部分は 1ループで2の冪乗で精度が上がる.",
"-# ex.) RRRRRRR だと, k回ループで index i の元が i + 2**kに移動する.",
"-# log(2**20... | false | 0.037309 | 0.049905 | 0.74761 | [
"s680591957",
"s679942598"
] |
u638057737 | p02708 | python | s427949887 | s776223404 | 80 | 20 | 9,152 | 9,192 | Accepted | Accepted | 75 | MOD = 10**9 + 7
N,K = list(map(int,input().split()))
s = 0
for k in range(K, N+2):
s = (s + N*k - k*k + k + 1) % MOD
print(s) | N,K = list(map(int,input().split()))
print(((((N+1)*(N+2-K)*(K+N+1))//2 - ((N+1)*(N+2)*(2*N+3))//6 + (K*(K-1)*(2*K-1))//6 + N + 2 - K) % (10**9 + 7))) | 7 | 2 | 127 | 143 | MOD = 10**9 + 7
N, K = list(map(int, input().split()))
s = 0
for k in range(K, N + 2):
s = (s + N * k - k * k + k + 1) % MOD
print(s)
| N, K = list(map(int, input().split()))
print(
(
(
((N + 1) * (N + 2 - K) * (K + N + 1)) // 2
- ((N + 1) * (N + 2) * (2 * N + 3)) // 6
+ (K * (K - 1) * (2 * K - 1)) // 6
+ N
+ 2
- K
)
% (10**9 + 7)
)
)
| false | 71.428571 | [
"-MOD = 10**9 + 7",
"-s = 0",
"-for k in range(K, N + 2):",
"- s = (s + N * k - k * k + k + 1) % MOD",
"-print(s)",
"+print(",
"+ (",
"+ (",
"+ ((N + 1) * (N + 2 - K) * (K + N + 1)) // 2",
"+ - ((N + 1) * (N + 2) * (2 * N + 3)) // 6",
"+ + (K * (K - ... | false | 0.047279 | 0.039418 | 1.199426 | [
"s427949887",
"s776223404"
] |
u191874006 | p03073 | python | s487358547 | s563706350 | 183 | 78 | 40,176 | 73,928 | Accepted | Accepted | 57.38 | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
s = eval(input())
n = len(s)
ans1 = 0
for i in range(n):
if i % 2 == 0:
if s[i] == '0':
ans1 += 1
else:
if s[i] == '1':
ans1 += 1
ans2 = 0
for i in range(n):
if i % 2 == 0:
if s[i] == '1':
ans2 += 1
else:
if s[i] == '0':
ans2 += 1
ans = min(ans1,ans2)
print(ans) | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
s = eval(input())
n = len(s)
cnt1 = 0
for i in range(n):
if i % 2:
if s[i] == '0':
cnt1 += 1
else:
if s[i] == '1':
cnt1 += 1
cnt2 = 0
for i in range(n):
if i % 2:
if s[i] == '1':
cnt2 += 1
else:
if s[i] == '0':
cnt2 += 1
ans = min(cnt1, cnt2)
print(ans) | 39 | 39 | 931 | 923 | #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
s = eval(input())
n = len(s)
ans1 = 0
for i in range(n):
if i % 2 == 0:
if s[i] == "0":
ans1 += 1
else:
if s[i] == "1":
ans1 += 1
ans2 = 0
for i in range(n):
if i % 2 == 0:
if s[i] == "1":
ans2 += 1
else:
if s[i] == "0":
ans2 += 1
ans = min(ans1, ans2)
print(ans)
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
s = eval(input())
n = len(s)
cnt1 = 0
for i in range(n):
if i % 2:
if s[i] == "0":
cnt1 += 1
else:
if s[i] == "1":
cnt1 += 1
cnt2 = 0
for i in range(n):
if i % 2:
if s[i] == "1":
cnt2 += 1
else:
if s[i] == "0":
cnt2 += 1
ans = min(cnt1, cnt2)
print(ans)
| false | 0 | [
"-ans1 = 0",
"+cnt1 = 0",
"- if i % 2 == 0:",
"+ if i % 2:",
"- ans1 += 1",
"+ cnt1 += 1",
"- ans1 += 1",
"-ans2 = 0",
"+ cnt1 += 1",
"+cnt2 = 0",
"- if i % 2 == 0:",
"+ if i % 2:",
"- ans2 += 1",
"+ cnt2 += 1",
... | false | 0.078115 | 0.058445 | 1.336545 | [
"s487358547",
"s563706350"
] |
u703950586 | p02956 | python | s721815470 | s832689594 | 1,647 | 1,505 | 124,220 | 123,928 | Accepted | Accepted | 8.62 | import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
MOD = 998244353
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N = NI()
dat = [LI() for _ in range(N)]
dat.sort()
yo = [y for _,y in dat]
yo.sort()
up = [0] * N
dw = [0] * N
bit = [0] * (N+1)
def bit_add(i):
while i <= N:
bit[i] += 1
i += i & -i
def bit_sum(i):
ret = 0
while i > 0:
ret += bit[i]
i -= i & -i
return ret
for i in range(N):
x,y = dat[i]
y = bisect.bisect_left(yo,y) + 1
up[i] = bit_sum(y)
bit_add(y)
bit = [0] * (N+1)
for i in range(N-1,-1,-1):
x,y = dat[i]
y = bisect.bisect_left(yo,y) + 1
dw[i] = bit_sum(y)
bit_add(y)
ans = N * pow(2,N-1,MOD)
for i in range(N):
a = i - up[i]
b = up[i]
c = N-(i+1) - dw[i]
d = dw[i]
p = (pow(2,a+d,MOD)-1) - (pow(2,a,MOD)-1) - (pow(2,d,MOD)-1)
q = (pow(2,b+c,MOD)-1) - (pow(2,b,MOD)-1) - (pow(2,c,MOD)-1)
x = p * (pow(2,b,MOD) + pow(2,c,MOD)-1)
y = q * (pow(2,a,MOD) + pow(2,d,MOD)-1)
z = p * q
ans = (ans + x + y + z) % MOD
print(ans)
if __name__ == '__main__':
main() | import sys,queue,math,copy,itertools,bisect,collections,heapq
def main():
MOD = 998244353
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N = NI()
dat = [LI() for _ in range(N)]
dat.sort()
yo = [y for _,y in dat]
yo.sort()
up = [0] * N
dw = [0] * N
bit = [0] * (N+1)
def bit_add(i):
while i <= N:
bit[i] += 1
i += i & -i
def bit_sum(i):
ret = 0
while i > 0:
ret += bit[i]
i -= i & -i
return ret
for i in range(N):
x,y = dat[i]
y = bisect.bisect_left(yo,y) + 1
up[i] = bit_sum(y)
bit_add(y)
bit = [0] * (N+1)
for i in range(N-1,-1,-1):
x,y = dat[i]
y = bisect.bisect_left(yo,y) + 1
dw[i] = bit_sum(y)
bit_add(y)
ans = N * pow(2,N-1,MOD)
for i in range(N):
a = i - up[i]
b = up[i]
c = N-(i+1) - dw[i]
d = dw[i]
pa = pow(2,a,MOD)
pb = pow(2,b,MOD)
pc = pow(2,c,MOD)
pd = pow(2,d,MOD)
p = (pow(2,a+d,MOD)-1) - (pa-1) - (pd-1)
q = (pow(2,b+c,MOD)-1) - (pb-1) - (pc-1)
x = p * (pb + pc - 1)
y = q * (pa + pd - 1)
z = p * q
ans = (ans + x + y + z) % MOD
print(ans)
if __name__ == '__main__':
main() | 59 | 63 | 1,420 | 1,452 | import sys, queue, math, copy, itertools, bisect, collections, heapq
def main():
MOD = 998244353
LI = lambda: [int(x) for x in sys.stdin.readline().split()]
NI = lambda: int(sys.stdin.readline())
N = NI()
dat = [LI() for _ in range(N)]
dat.sort()
yo = [y for _, y in dat]
yo.sort()
up = [0] * N
dw = [0] * N
bit = [0] * (N + 1)
def bit_add(i):
while i <= N:
bit[i] += 1
i += i & -i
def bit_sum(i):
ret = 0
while i > 0:
ret += bit[i]
i -= i & -i
return ret
for i in range(N):
x, y = dat[i]
y = bisect.bisect_left(yo, y) + 1
up[i] = bit_sum(y)
bit_add(y)
bit = [0] * (N + 1)
for i in range(N - 1, -1, -1):
x, y = dat[i]
y = bisect.bisect_left(yo, y) + 1
dw[i] = bit_sum(y)
bit_add(y)
ans = N * pow(2, N - 1, MOD)
for i in range(N):
a = i - up[i]
b = up[i]
c = N - (i + 1) - dw[i]
d = dw[i]
p = (pow(2, a + d, MOD) - 1) - (pow(2, a, MOD) - 1) - (pow(2, d, MOD) - 1)
q = (pow(2, b + c, MOD) - 1) - (pow(2, b, MOD) - 1) - (pow(2, c, MOD) - 1)
x = p * (pow(2, b, MOD) + pow(2, c, MOD) - 1)
y = q * (pow(2, a, MOD) + pow(2, d, MOD) - 1)
z = p * q
ans = (ans + x + y + z) % MOD
print(ans)
if __name__ == "__main__":
main()
| import sys, queue, math, copy, itertools, bisect, collections, heapq
def main():
MOD = 998244353
LI = lambda: [int(x) for x in sys.stdin.readline().split()]
NI = lambda: int(sys.stdin.readline())
N = NI()
dat = [LI() for _ in range(N)]
dat.sort()
yo = [y for _, y in dat]
yo.sort()
up = [0] * N
dw = [0] * N
bit = [0] * (N + 1)
def bit_add(i):
while i <= N:
bit[i] += 1
i += i & -i
def bit_sum(i):
ret = 0
while i > 0:
ret += bit[i]
i -= i & -i
return ret
for i in range(N):
x, y = dat[i]
y = bisect.bisect_left(yo, y) + 1
up[i] = bit_sum(y)
bit_add(y)
bit = [0] * (N + 1)
for i in range(N - 1, -1, -1):
x, y = dat[i]
y = bisect.bisect_left(yo, y) + 1
dw[i] = bit_sum(y)
bit_add(y)
ans = N * pow(2, N - 1, MOD)
for i in range(N):
a = i - up[i]
b = up[i]
c = N - (i + 1) - dw[i]
d = dw[i]
pa = pow(2, a, MOD)
pb = pow(2, b, MOD)
pc = pow(2, c, MOD)
pd = pow(2, d, MOD)
p = (pow(2, a + d, MOD) - 1) - (pa - 1) - (pd - 1)
q = (pow(2, b + c, MOD) - 1) - (pb - 1) - (pc - 1)
x = p * (pb + pc - 1)
y = q * (pa + pd - 1)
z = p * q
ans = (ans + x + y + z) % MOD
print(ans)
if __name__ == "__main__":
main()
| false | 6.349206 | [
"- p = (pow(2, a + d, MOD) - 1) - (pow(2, a, MOD) - 1) - (pow(2, d, MOD) - 1)",
"- q = (pow(2, b + c, MOD) - 1) - (pow(2, b, MOD) - 1) - (pow(2, c, MOD) - 1)",
"- x = p * (pow(2, b, MOD) + pow(2, c, MOD) - 1)",
"- y = q * (pow(2, a, MOD) + pow(2, d, MOD) - 1)",
"+ pa = pow... | false | 0.107779 | 0.106714 | 1.009983 | [
"s721815470",
"s832689594"
] |
u254871849 | p02773 | python | s095234848 | s680769568 | 468 | 344 | 45,292 | 38,392 | Accepted | Accepted | 26.5 | import sys
from collections import Counter
n, *s = sys.stdin.read().split()
def main():
cnt = sorted(Counter(s).items(), key=lambda x: -x[1])
m = cnt[0][1]
ans = [s for s, c in cnt if c == m]
print(*sorted(ans), sep='\n')
if __name__ == '__main__':
main()
| import sys
from collections import Counter
n, *s = sys.stdin.read().split()
def main():
c = Counter(s)
m = max(c.values())
ans = [s for s, v in c.items() if v == m]
print(*sorted(ans), sep='\n')
if __name__ == '__main__':
main()
| 14 | 13 | 302 | 273 | import sys
from collections import Counter
n, *s = sys.stdin.read().split()
def main():
cnt = sorted(Counter(s).items(), key=lambda x: -x[1])
m = cnt[0][1]
ans = [s for s, c in cnt if c == m]
print(*sorted(ans), sep="\n")
if __name__ == "__main__":
main()
| import sys
from collections import Counter
n, *s = sys.stdin.read().split()
def main():
c = Counter(s)
m = max(c.values())
ans = [s for s, v in c.items() if v == m]
print(*sorted(ans), sep="\n")
if __name__ == "__main__":
main()
| false | 7.142857 | [
"- cnt = sorted(Counter(s).items(), key=lambda x: -x[1])",
"- m = cnt[0][1]",
"- ans = [s for s, c in cnt if c == m]",
"+ c = Counter(s)",
"+ m = max(c.values())",
"+ ans = [s for s, v in c.items() if v == m]"
] | false | 0.042713 | 0.043522 | 0.981419 | [
"s095234848",
"s680769568"
] |
u272336707 | p02781 | python | s318977781 | s539765068 | 768 | 29 | 3,064 | 3,940 | Accepted | Accepted | 96.22 | N = int(eval(input()))
K = int(eval(input()))
def dp(n, k): #0以上n以下の数で0でない数字がちょうどk個あるもの。
if k == 0:
return 1
elif n == 0:
return 0
else:
n = int(n)
s = str(n)
digit = len(s)
m, fdigit = divmod(n,10)
if m >= 1:
return int(dp(m, k-1) * fdigit + dp(m-1, k-1)* (9-fdigit) + dp(m, k))
elif k == 1:
return n
elif k == 2 or k == 3:
return 0
else:
return 1
if K == 0:
answer = dp(N, K)-1
else:
answer = dp(N, K)
print((int(answer))) | N = int(eval(input()))
K = int(eval(input()))
from functools import lru_cache
@lru_cache(maxsize=1000)
def dp(n, k): #0以上n以下の数で0でない数字がちょうどk個あるもの。
if k == 0:
return 1
elif n == 0:
return 0
else:
n = int(n)
s = str(n)
digit = len(s)
m, fdigit = divmod(n,10)
if m >= 1:
return int(dp(m, k-1) * fdigit + dp(m-1, k-1)* (9-fdigit) + dp(m, k))
elif k == 1:
return n
elif k == 2 or k == 3:
return 0
else:
return 1
if K == 0:
answer = dp(N, K)-1
else:
answer = dp(N, K)
print((int(answer))) | 25 | 28 | 520 | 581 | N = int(eval(input()))
K = int(eval(input()))
def dp(n, k): # 0以上n以下の数で0でない数字がちょうどk個あるもの。
if k == 0:
return 1
elif n == 0:
return 0
else:
n = int(n)
s = str(n)
digit = len(s)
m, fdigit = divmod(n, 10)
if m >= 1:
return int(
dp(m, k - 1) * fdigit + dp(m - 1, k - 1) * (9 - fdigit) + dp(m, k)
)
elif k == 1:
return n
elif k == 2 or k == 3:
return 0
else:
return 1
if K == 0:
answer = dp(N, K) - 1
else:
answer = dp(N, K)
print((int(answer)))
| N = int(eval(input()))
K = int(eval(input()))
from functools import lru_cache
@lru_cache(maxsize=1000)
def dp(n, k): # 0以上n以下の数で0でない数字がちょうどk個あるもの。
if k == 0:
return 1
elif n == 0:
return 0
else:
n = int(n)
s = str(n)
digit = len(s)
m, fdigit = divmod(n, 10)
if m >= 1:
return int(
dp(m, k - 1) * fdigit + dp(m - 1, k - 1) * (9 - fdigit) + dp(m, k)
)
elif k == 1:
return n
elif k == 2 or k == 3:
return 0
else:
return 1
if K == 0:
answer = dp(N, K) - 1
else:
answer = dp(N, K)
print((int(answer)))
| false | 10.714286 | [
"+from functools import lru_cache",
"+@lru_cache(maxsize=1000)"
] | false | 0.171383 | 0.036458 | 4.700801 | [
"s318977781",
"s539765068"
] |
u179169725 | p03108 | python | s259706379 | s655232969 | 857 | 709 | 42,088 | 42,092 | Accepted | Accepted | 17.27 | def readln():
import sys
read = sys.stdin.readline
return list(map(int, read().split()))
N, M = readln()
AB = [readln() for _ in range(M)]
A = [ab[0]-1 for ab in AB[::-1]]
B = [ab[1]-1 for ab in AB[::-1]]
class UnionFind:
def __init__(self, N):
self.N = N # ノード数
# 親ノードをしめす。負は自身が親ということ。
self.parent = [-1] * N # idxが各ノードに対応。
def root(self, A):
# print(A)
# ノード番号を受け取って一番上の親ノードの番号を帰す
if (self.parent[A] < 0):
return A
self.parent[A] = self.root(self.parent[A]) # 経由したノードすべての親を上書き
return self.parent[A]
def size(self, A):
# ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。
return -self.parent[self.root(A)]
def concat(self, A, B):
# ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。
# 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。
A = self.root(A)
B = self.root(B)
# すでにくっついている場合
if (A == B):
return False
# 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較
if (self.size(A) < self.size(B)):
A, B = B, A
# くっつける
self.parent[A] += self.parent[B] # sizeの更新
self.parent[B] = A # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる
return True
ans = [N * (N - 1) // 2]
uni = UnionFind(N)
for a, b in zip(A, B):
if uni.root(a) == uni.root(b):
ans.append(ans[-1])
else:
ans.append(ans[-1] - uni.size(a) * uni.size(b))
uni.concat(a, b)
for a in ans[-2::-1]:
print(a)
| import sys
read = sys.stdin.readline
def readln():
return list(map(int, read().split()))
N, M = readln()
AB = [readln() for _ in range(M)]
A = [ab[0]-1 for ab in AB[::-1]]
B = [ab[1]-1 for ab in AB[::-1]]
class UnionFind:
def __init__(self, N):
self.N = N # ノード数
# 親ノードをしめす。負は自身が親ということ。
self.parent = [-1] * N # idxが各ノードに対応。
def root(self, A):
# print(A)
# ノード番号を受け取って一番上の親ノードの番号を帰す
if (self.parent[A] < 0):
return A
self.parent[A] = self.root(self.parent[A]) # 経由したノードすべての親を上書き
return self.parent[A]
def size(self, A):
# ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。
return -self.parent[self.root(A)]
def concat(self, A, B):
# ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。
# 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。
A = self.root(A)
B = self.root(B)
# すでにくっついている場合
if (A == B):
return False
# 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較
if (self.size(A) < self.size(B)):
A, B = B, A
# くっつける
self.parent[A] += self.parent[B] # sizeの更新
self.parent[B] = A # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる
return True
ans = [N * (N - 1) // 2]
uni = UnionFind(N)
for a, b in zip(A, B):
if uni.root(a) == uni.root(b):
ans.append(ans[-1])
else:
ans.append(ans[-1] - uni.size(a) * uni.size(b))
uni.concat(a, b)
for a in ans[-2::-1]:
print(a)
| 62 | 64 | 1,541 | 1,537 | def readln():
import sys
read = sys.stdin.readline
return list(map(int, read().split()))
N, M = readln()
AB = [readln() for _ in range(M)]
A = [ab[0] - 1 for ab in AB[::-1]]
B = [ab[1] - 1 for ab in AB[::-1]]
class UnionFind:
def __init__(self, N):
self.N = N # ノード数
# 親ノードをしめす。負は自身が親ということ。
self.parent = [-1] * N # idxが各ノードに対応。
def root(self, A):
# print(A)
# ノード番号を受け取って一番上の親ノードの番号を帰す
if self.parent[A] < 0:
return A
self.parent[A] = self.root(self.parent[A]) # 経由したノードすべての親を上書き
return self.parent[A]
def size(self, A):
# ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。
return -self.parent[self.root(A)]
def concat(self, A, B):
# ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。
# 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。
A = self.root(A)
B = self.root(B)
# すでにくっついている場合
if A == B:
return False
# 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較
if self.size(A) < self.size(B):
A, B = B, A
# くっつける
self.parent[A] += self.parent[B] # sizeの更新
self.parent[B] = A # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる
return True
ans = [N * (N - 1) // 2]
uni = UnionFind(N)
for a, b in zip(A, B):
if uni.root(a) == uni.root(b):
ans.append(ans[-1])
else:
ans.append(ans[-1] - uni.size(a) * uni.size(b))
uni.concat(a, b)
for a in ans[-2::-1]:
print(a)
| import sys
read = sys.stdin.readline
def readln():
return list(map(int, read().split()))
N, M = readln()
AB = [readln() for _ in range(M)]
A = [ab[0] - 1 for ab in AB[::-1]]
B = [ab[1] - 1 for ab in AB[::-1]]
class UnionFind:
def __init__(self, N):
self.N = N # ノード数
# 親ノードをしめす。負は自身が親ということ。
self.parent = [-1] * N # idxが各ノードに対応。
def root(self, A):
# print(A)
# ノード番号を受け取って一番上の親ノードの番号を帰す
if self.parent[A] < 0:
return A
self.parent[A] = self.root(self.parent[A]) # 経由したノードすべての親を上書き
return self.parent[A]
def size(self, A):
# ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。
return -self.parent[self.root(A)]
def concat(self, A, B):
# ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。
# 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。
A = self.root(A)
B = self.root(B)
# すでにくっついている場合
if A == B:
return False
# 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較
if self.size(A) < self.size(B):
A, B = B, A
# くっつける
self.parent[A] += self.parent[B] # sizeの更新
self.parent[B] = A # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる
return True
ans = [N * (N - 1) // 2]
uni = UnionFind(N)
for a, b in zip(A, B):
if uni.root(a) == uni.root(b):
ans.append(ans[-1])
else:
ans.append(ans[-1] - uni.size(a) * uni.size(b))
uni.concat(a, b)
for a in ans[-2::-1]:
print(a)
| false | 3.125 | [
"+import sys",
"+",
"+read = sys.stdin.readline",
"+",
"+",
"- import sys",
"-",
"- read = sys.stdin.readline"
] | false | 0.03887 | 0.037461 | 1.037636 | [
"s259706379",
"s655232969"
] |
u150984829 | p02386 | python | s054326734 | s639485261 | 70 | 30 | 5,608 | 5,616 | Accepted | Accepted | 57.14 | n=int(eval(input()))
a=[list(map(int,input().split()))for _ in range(n)]
def f():
for i in range(n-1):
d=a[i][:];d[3],d[4]=d[4],d[3]
for j in range(i+1,n):
e=a[j][:];e[3],e[4]=e[4],e[3]
for p in('012345','152043','215304','302541','410352','514320'):
f=[d[int(k)]for k in p]
if f[0]==e[0]and f[5]==e[5]:
f=f[1:5]*2
for k in range(4):
if f[k:k+4]==e[1:5]:return'No'
return'Yes'
print((f()))
| n=int(eval(input()))
a=[list(map(int,input().split()))for _ in range(n)]
def f():
for i in range(n-1):
d=a[i][:];d[3],d[4]=d[4],d[3]
for j in range(i+1,n):
e=a[j][:];e[3],e[4]=e[4],e[3]
for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):
f=[d[k]for k in p]
if f[0]==e[0]and f[5]==e[5]:
f=f[1:5]*2
for k in range(4):
if f[k:k+4]==e[1:5]:return'No'
return'Yes'
print((f()))
| 15 | 15 | 432 | 457 | n = int(eval(input()))
a = [list(map(int, input().split())) for _ in range(n)]
def f():
for i in range(n - 1):
d = a[i][:]
d[3], d[4] = d[4], d[3]
for j in range(i + 1, n):
e = a[j][:]
e[3], e[4] = e[4], e[3]
for p in ("012345", "152043", "215304", "302541", "410352", "514320"):
f = [d[int(k)] for k in p]
if f[0] == e[0] and f[5] == e[5]:
f = f[1:5] * 2
for k in range(4):
if f[k : k + 4] == e[1:5]:
return "No"
return "Yes"
print((f()))
| n = int(eval(input()))
a = [list(map(int, input().split())) for _ in range(n)]
def f():
for i in range(n - 1):
d = a[i][:]
d[3], d[4] = d[4], d[3]
for j in range(i + 1, n):
e = a[j][:]
e[3], e[4] = e[4], e[3]
for p in (
[0, 1, 2, 3, 4, 5],
[1, 5, 2, 0, 4, 3],
[2, 1, 5, 3, 0, 4],
[3, 0, 2, 5, 4, 1],
[4, 1, 0, 3, 5, 2],
[5, 1, 4, 3, 2, 0],
):
f = [d[k] for k in p]
if f[0] == e[0] and f[5] == e[5]:
f = f[1:5] * 2
for k in range(4):
if f[k : k + 4] == e[1:5]:
return "No"
return "Yes"
print((f()))
| false | 0 | [
"- for p in (\"012345\", \"152043\", \"215304\", \"302541\", \"410352\", \"514320\"):",
"- f = [d[int(k)] for k in p]",
"+ for p in (",
"+ [0, 1, 2, 3, 4, 5],",
"+ [1, 5, 2, 0, 4, 3],",
"+ [2, 1, 5, 3, 0, 4],",
"+ ... | false | 0.041067 | 0.036625 | 1.12127 | [
"s054326734",
"s639485261"
] |
u525065967 | p03290 | python | s347312364 | s479602857 | 252 | 29 | 3,064 | 3,064 | Accepted | Accepted | 88.49 | d,g = list(map(int,input().split()))
P,C = [],[]
for i in range(1, d+1):
p,c = list(map(int,input().split()))
P.append(p)
C.append(c)
ans = 10**9
for bin in range(1, 1<<d):
cnt = tot = 0
for j in range(d):
if bin & 1<<j:
cnt += P[j]
tot += P[j]*(j+1)*100 + C[j]
if tot < g: continue
ans = min(ans, cnt)
for j in range(d):
if bin & 1<<j:
now_cnt = cnt
now_tot = tot - C[j]
for k in range(P[j]-1):
now_cnt -= 1
now_tot -= (j+1)*100
if now_tot >= g: ans = min(ans, now_cnt)
print(ans)
| d,g = list(map(int,input().split()))
g //= 100
P,C = [],[]
for i in range(1, d+1):
p,c = list(map(int,input().split()))
P.append(p)
C.append(c//100)
ans = 10**9
# print(P)
# print(C)
for bin in range(1, 1<<d):
cnt = tot = 0
for j in range(d):
if bin & 1<<j:
cnt += P[j]
tot += P[j]*(j+1) + C[j]
if tot < g: continue
ans = min(ans, cnt)
# print('tot',tot, end=' ')
# print('cnt',cnt, end='\n')
for j in range(d):
if bin & 1<<j:
init_cnt = cnt - P[j]
init_tot = tot - (P[j]*(j+1) + C[j])
rest_g = g - init_tot
k = max(0, (rest_g+j)//(j+1)) # round up, required quantity
# print('Pj',P[j], end=' ')
# print('Cj',C[j], end=' ')
# print('init_cnt',init_cnt, end=' ')
# print('init_tot',init_tot, end=' ')
# print('rest_g',rest_g, end=' ')
# print('k',k, end='\n')
if k < P[j]:
# ans = init_cnt + k
ans = min(ans, init_cnt + k)
# print('init_cnt+k',init_cnt+k, end='\n')
print(ans)
| 24 | 37 | 649 | 1,160 | d, g = list(map(int, input().split()))
P, C = [], []
for i in range(1, d + 1):
p, c = list(map(int, input().split()))
P.append(p)
C.append(c)
ans = 10**9
for bin in range(1, 1 << d):
cnt = tot = 0
for j in range(d):
if bin & 1 << j:
cnt += P[j]
tot += P[j] * (j + 1) * 100 + C[j]
if tot < g:
continue
ans = min(ans, cnt)
for j in range(d):
if bin & 1 << j:
now_cnt = cnt
now_tot = tot - C[j]
for k in range(P[j] - 1):
now_cnt -= 1
now_tot -= (j + 1) * 100
if now_tot >= g:
ans = min(ans, now_cnt)
print(ans)
| d, g = list(map(int, input().split()))
g //= 100
P, C = [], []
for i in range(1, d + 1):
p, c = list(map(int, input().split()))
P.append(p)
C.append(c // 100)
ans = 10**9
# print(P)
# print(C)
for bin in range(1, 1 << d):
cnt = tot = 0
for j in range(d):
if bin & 1 << j:
cnt += P[j]
tot += P[j] * (j + 1) + C[j]
if tot < g:
continue
ans = min(ans, cnt)
# print('tot',tot, end=' ')
# print('cnt',cnt, end='\n')
for j in range(d):
if bin & 1 << j:
init_cnt = cnt - P[j]
init_tot = tot - (P[j] * (j + 1) + C[j])
rest_g = g - init_tot
k = max(0, (rest_g + j) // (j + 1)) # round up, required quantity
# print('Pj',P[j], end=' ')
# print('Cj',C[j], end=' ')
# print('init_cnt',init_cnt, end=' ')
# print('init_tot',init_tot, end=' ')
# print('rest_g',rest_g, end=' ')
# print('k',k, end='\n')
if k < P[j]:
# ans = init_cnt + k
ans = min(ans, init_cnt + k)
# print('init_cnt+k',init_cnt+k, end='\n')
print(ans)
| false | 35.135135 | [
"+g //= 100",
"- C.append(c)",
"+ C.append(c // 100)",
"+# print(P)",
"+# print(C)",
"- tot += P[j] * (j + 1) * 100 + C[j]",
"+ tot += P[j] * (j + 1) + C[j]",
"+ # print('tot',tot, end=' ')",
"+ # print('cnt',cnt, end='\\n')",
"- now_cnt = cnt",
"- ... | false | 0.055625 | 0.051124 | 1.08805 | [
"s347312364",
"s479602857"
] |
u572122511 | p02831 | python | s205212725 | s242946128 | 41 | 36 | 5,432 | 5,048 | Accepted | Accepted | 12.2 | from fractions import gcd
A, B = list(map(int, input().split()))
print((A * B // gcd(A, B))) | from fractions import gcd
def lcm(x, y):
return x * y // gcd(x, y)
A, B = list(map(int, input().split()))
print((lcm(A, B)))
| 5 | 8 | 90 | 131 | from fractions import gcd
A, B = list(map(int, input().split()))
print((A * B // gcd(A, B)))
| from fractions import gcd
def lcm(x, y):
return x * y // gcd(x, y)
A, B = list(map(int, input().split()))
print((lcm(A, B)))
| false | 37.5 | [
"+",
"+def lcm(x, y):",
"+ return x * y // gcd(x, y)",
"+",
"+",
"-print((A * B // gcd(A, B)))",
"+print((lcm(A, B)))"
] | false | 0.087532 | 0.047767 | 1.832479 | [
"s205212725",
"s242946128"
] |
u535803878 | p03660 | python | s830038314 | s007019675 | 300 | 246 | 114,624 | 91,244 | Accepted | Accepted | 18 | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
### 木の読み込み tree
# サイズが大きいとdefaultdictが早い(for文を書かなくて済む)
from collections import defaultdict
n = int(eval(input()))
ns = defaultdict(set)
for _ in range(n-1):
u,v = list(map(int, input().split()))
u -= 1
v -= 1
ns[u].add(v)
ns[v].add(u)
### BFS 幅優先探索
def bfs(start):
from collections import deque
q = deque([start])
seen = [None] * n
seen[start] = 0
while q:
u = q.pop()
d = seen[u]
for v in ns[u]:
if seen[v] is None:
seen[v] = d + 1
q.appendleft(v)
return seen
d1 = bfs(0)
d2 = bfs(n-1)
v = sum(d1[i]<=d2[i] for i in range(n))
v2 = n-v
if v>v2:
print("Fennec")
else:
print("Snuke") | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
### 木の読み込み tree
# サイズが大きいとdefaultdictが早い(for文を書かなくて済む)
from collections import defaultdict
n = int(eval(input()))
ns = [[] for _ in range(n)]
for _ in range(n-1):
u,v = list(map(int, input().split()))
u -= 1
v -= 1
ns[u].append(v)
ns[v].append(u)
### BFS 幅優先探索
def bfs(start):
from collections import deque
q = deque([start])
seen = [None] * n
seen[start] = 0
while q:
u = q.pop()
d = seen[u]
for v in ns[u]:
if seen[v] is None:
seen[v] = d + 1
q.appendleft(v)
return seen
d1 = bfs(0)
d2 = bfs(n-1)
v = sum(d1[i]<=d2[i] for i in range(n))
v2 = n-v
if v>v2:
print("Fennec")
else:
print("Snuke") | 42 | 42 | 880 | 892 | import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
### 木の読み込み tree
# サイズが大きいとdefaultdictが早い(for文を書かなくて済む)
from collections import defaultdict
n = int(eval(input()))
ns = defaultdict(set)
for _ in range(n - 1):
u, v = list(map(int, input().split()))
u -= 1
v -= 1
ns[u].add(v)
ns[v].add(u)
### BFS 幅優先探索
def bfs(start):
from collections import deque
q = deque([start])
seen = [None] * n
seen[start] = 0
while q:
u = q.pop()
d = seen[u]
for v in ns[u]:
if seen[v] is None:
seen[v] = d + 1
q.appendleft(v)
return seen
d1 = bfs(0)
d2 = bfs(n - 1)
v = sum(d1[i] <= d2[i] for i in range(n))
v2 = n - v
if v > v2:
print("Fennec")
else:
print("Snuke")
| import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
### 木の読み込み tree
# サイズが大きいとdefaultdictが早い(for文を書かなくて済む)
from collections import defaultdict
n = int(eval(input()))
ns = [[] for _ in range(n)]
for _ in range(n - 1):
u, v = list(map(int, input().split()))
u -= 1
v -= 1
ns[u].append(v)
ns[v].append(u)
### BFS 幅優先探索
def bfs(start):
from collections import deque
q = deque([start])
seen = [None] * n
seen[start] = 0
while q:
u = q.pop()
d = seen[u]
for v in ns[u]:
if seen[v] is None:
seen[v] = d + 1
q.appendleft(v)
return seen
d1 = bfs(0)
d2 = bfs(n - 1)
v = sum(d1[i] <= d2[i] for i in range(n))
v2 = n - v
if v > v2:
print("Fennec")
else:
print("Snuke")
| false | 0 | [
"-ns = defaultdict(set)",
"+ns = [[] for _ in range(n)]",
"- ns[u].add(v)",
"- ns[v].add(u)",
"+ ns[u].append(v)",
"+ ns[v].append(u)"
] | false | 0.032115 | 0.111977 | 0.286802 | [
"s830038314",
"s007019675"
] |
u836737505 | p03574 | python | s613726467 | s409010082 | 185 | 31 | 12,880 | 3,188 | Accepted | Accepted | 83.24 | import numpy as np
h,w = map(int, input().split())
a = [list(input()) for i in range(h)]
a = np.array(a)
for hi in range(h):
for wi in range(w):
c = 0
if a[hi][wi] == "#":
print('#',end='')
else:
print(np.count_nonzero(a[max(0,hi-1):hi+2,max(0,wi-1):wi+2] == "#"),end='',)
print()
| h,w = list(map(int, input().split()))
f = [list(eval(input())) for _ in range(h)]
for k in range(h):
for l in range(w):
if f[k][l] == ".":
c = 0
for i in range(-1,2):
for j in range(-1,2):
xi,yi = k+i,l+j
#xi,yiが範囲内で水溜りなら
if 0 <= xi < h and 0 <= yi < w and f[xi][yi] == "#":
c += 1
f[k][l] = str(c)
for m in range(h):
print((''.join(f[m]))) | 12 | 16 | 347 | 495 | import numpy as np
h, w = map(int, input().split())
a = [list(input()) for i in range(h)]
a = np.array(a)
for hi in range(h):
for wi in range(w):
c = 0
if a[hi][wi] == "#":
print("#", end="")
else:
print(
np.count_nonzero(
a[max(0, hi - 1) : hi + 2, max(0, wi - 1) : wi + 2] == "#"
),
end="",
)
print()
| h, w = list(map(int, input().split()))
f = [list(eval(input())) for _ in range(h)]
for k in range(h):
for l in range(w):
if f[k][l] == ".":
c = 0
for i in range(-1, 2):
for j in range(-1, 2):
xi, yi = k + i, l + j
# xi,yiが範囲内で水溜りなら
if 0 <= xi < h and 0 <= yi < w and f[xi][yi] == "#":
c += 1
f[k][l] = str(c)
for m in range(h):
print(("".join(f[m])))
| false | 25 | [
"-import numpy as np",
"-",
"-h, w = map(int, input().split())",
"-a = [list(input()) for i in range(h)]",
"-a = np.array(a)",
"-for hi in range(h):",
"- for wi in range(w):",
"- c = 0",
"- if a[hi][wi] == \"#\":",
"- print(\"#\", end=\"\")",
"- else:",
"- ... | false | 0.255936 | 0.036113 | 7.087156 | [
"s613726467",
"s409010082"
] |
u057109575 | p02597 | python | s326426101 | s449332817 | 127 | 69 | 77,688 | 63,072 | Accepted | Accepted | 45.67 |
N = int(eval(input()))
S = list(eval(input()))
cnt = S.count("R")
ans = S[cnt:].count("R")
print(ans)
|
N = int(eval(input()))
S = eval(input())
c = S.count("R")
res = S[c:].count("R")
print(res)
| 7 | 7 | 98 | 88 | N = int(eval(input()))
S = list(eval(input()))
cnt = S.count("R")
ans = S[cnt:].count("R")
print(ans)
| N = int(eval(input()))
S = eval(input())
c = S.count("R")
res = S[c:].count("R")
print(res)
| false | 0 | [
"-S = list(eval(input()))",
"-cnt = S.count(\"R\")",
"-ans = S[cnt:].count(\"R\")",
"-print(ans)",
"+S = eval(input())",
"+c = S.count(\"R\")",
"+res = S[c:].count(\"R\")",
"+print(res)"
] | false | 0.064731 | 0.069396 | 0.932767 | [
"s326426101",
"s449332817"
] |
u408260374 | p02373 | python | s259590242 | s738807195 | 1,910 | 1,520 | 110,136 | 38,688 | Accepted | Accepted | 20.42 | import sys
if sys.version[0] == '2':
range, input = xrange, raw_input
class Edge:
def __init__(self, dst, weight):
self.dst, self.weight = dst, weight
def __lt__(self, e):
return self.weight > e.weight
class Graph:
def __init__(self, V):
self.V = V
self.E = [[] for _ in range(V)]
def add_edge(self, src, dst, weight):
self.E[src].append(Edge(dst, weight))
class HeavyLightDecomposition:
def __init__(self, g, root=0):
self.g = g
self.vid, self.head, self.heavy, self.parent = [0] * g.V, [-1] * g.V, [-1] * g.V, [-1] * g.V
self.dfs(root)
self.bfs(root)
def dfs(self, root):
stack = [(root, -1)]
sub, max_sub = [1] * self.g.V, [(0, -1)] * self.g.V
used = [False] * self.g.V
while stack:
v, par = stack.pop()
if not used[v]:
used[v] = True
self.parent[v] = par
stack.append((v, par))
stack.extend((e.dst, v) for e in self.g.E[v] if e.dst != par)
else:
if par != -1:
sub[par] += sub[v]
max_sub[par] = max(max_sub[par], (sub[v], v))
self.heavy[v] = max_sub[v][1]
def bfs(self, root=0):
from collections import deque
k, que = 0, deque([root])
while que:
r = v = que.popleft()
while v != -1:
self.vid[v], self.head[v] = k, r
for e in self.g.E[v]:
if e.dst != self.parent[v] and e.dst != self.heavy[v]:
que.append(e.dst)
k += 1
v = self.heavy[v]
def lca(self, u, v):
while self.head[u] != self.head[v]:
if self.vid[u] > self.vid[v]:
u, v = v, u
v = self.parent[self.head[v]]
else:
if self.vid[u] > self.vid[v]:
u, v = v, u
return u
N = int(eval(input()))
g = Graph(N)
for i in range(N):
for c in map(int, input().split()[1:]):
g.add_edge(i, c, 1)
g.add_edge(c, i, 1)
hld = HeavyLightDecomposition(g)
Q = int(eval(input()))
for _ in range(Q):
u, v = list(map(int, input().split()))
print((hld.lca(u, v))) | import sys
if sys.version[0] == '2':
range, input = xrange, raw_input
class HeavyLightDecomposition:
def __init__(self, g, root=0):
self.g = g
self.vid, self.head, self.heavy, self.parent = [0] * len(g), [-1] * len(g), [-1] * len(g), [-1] * len(g)
self.dfs(root)
self.bfs(root)
def dfs(self, root):
stack = [(root, -1)]
sub, max_sub = [1] * len(self.g), [(0, -1)] * len(self.g)
used = [False] * len(self.g)
while stack:
v, par = stack.pop()
if not used[v]:
used[v] = True
self.parent[v] = par
stack.append((v, par))
stack.extend((c, v) for c in self.g[v] if c != par)
else:
if par != -1:
sub[par] += sub[v]
max_sub[par] = max(max_sub[par], (sub[v], v))
self.heavy[v] = max_sub[v][1]
def bfs(self, root=0):
from collections import deque
k, que = 0, deque([root])
while que:
r = v = que.popleft()
while v != -1:
self.vid[v], self.head[v] = k, r
for c in self.g[v]:
if c != self.parent[v] and c != self.heavy[v]:
que.append(c)
k += 1
v = self.heavy[v]
def lca(self, u, v):
while self.head[u] != self.head[v]:
if self.vid[u] > self.vid[v]:
u, v = v, u
v = self.parent[self.head[v]]
else:
if self.vid[u] > self.vid[v]:
u, v = v, u
return u
N = int(eval(input()))
g = [[] for _ in range(N)]
for i in range(N):
for c in map(int, input().split()[1:]):
g[i].append(c)
g[c].append(i)
hld = HeavyLightDecomposition(g)
Q = int(eval(input()))
for _ in range(Q):
u, v = list(map(int, input().split()))
print((hld.lca(u, v))) | 81 | 63 | 2,357 | 1,995 | import sys
if sys.version[0] == "2":
range, input = xrange, raw_input
class Edge:
def __init__(self, dst, weight):
self.dst, self.weight = dst, weight
def __lt__(self, e):
return self.weight > e.weight
class Graph:
def __init__(self, V):
self.V = V
self.E = [[] for _ in range(V)]
def add_edge(self, src, dst, weight):
self.E[src].append(Edge(dst, weight))
class HeavyLightDecomposition:
def __init__(self, g, root=0):
self.g = g
self.vid, self.head, self.heavy, self.parent = (
[0] * g.V,
[-1] * g.V,
[-1] * g.V,
[-1] * g.V,
)
self.dfs(root)
self.bfs(root)
def dfs(self, root):
stack = [(root, -1)]
sub, max_sub = [1] * self.g.V, [(0, -1)] * self.g.V
used = [False] * self.g.V
while stack:
v, par = stack.pop()
if not used[v]:
used[v] = True
self.parent[v] = par
stack.append((v, par))
stack.extend((e.dst, v) for e in self.g.E[v] if e.dst != par)
else:
if par != -1:
sub[par] += sub[v]
max_sub[par] = max(max_sub[par], (sub[v], v))
self.heavy[v] = max_sub[v][1]
def bfs(self, root=0):
from collections import deque
k, que = 0, deque([root])
while que:
r = v = que.popleft()
while v != -1:
self.vid[v], self.head[v] = k, r
for e in self.g.E[v]:
if e.dst != self.parent[v] and e.dst != self.heavy[v]:
que.append(e.dst)
k += 1
v = self.heavy[v]
def lca(self, u, v):
while self.head[u] != self.head[v]:
if self.vid[u] > self.vid[v]:
u, v = v, u
v = self.parent[self.head[v]]
else:
if self.vid[u] > self.vid[v]:
u, v = v, u
return u
N = int(eval(input()))
g = Graph(N)
for i in range(N):
for c in map(int, input().split()[1:]):
g.add_edge(i, c, 1)
g.add_edge(c, i, 1)
hld = HeavyLightDecomposition(g)
Q = int(eval(input()))
for _ in range(Q):
u, v = list(map(int, input().split()))
print((hld.lca(u, v)))
| import sys
if sys.version[0] == "2":
range, input = xrange, raw_input
class HeavyLightDecomposition:
def __init__(self, g, root=0):
self.g = g
self.vid, self.head, self.heavy, self.parent = (
[0] * len(g),
[-1] * len(g),
[-1] * len(g),
[-1] * len(g),
)
self.dfs(root)
self.bfs(root)
def dfs(self, root):
stack = [(root, -1)]
sub, max_sub = [1] * len(self.g), [(0, -1)] * len(self.g)
used = [False] * len(self.g)
while stack:
v, par = stack.pop()
if not used[v]:
used[v] = True
self.parent[v] = par
stack.append((v, par))
stack.extend((c, v) for c in self.g[v] if c != par)
else:
if par != -1:
sub[par] += sub[v]
max_sub[par] = max(max_sub[par], (sub[v], v))
self.heavy[v] = max_sub[v][1]
def bfs(self, root=0):
from collections import deque
k, que = 0, deque([root])
while que:
r = v = que.popleft()
while v != -1:
self.vid[v], self.head[v] = k, r
for c in self.g[v]:
if c != self.parent[v] and c != self.heavy[v]:
que.append(c)
k += 1
v = self.heavy[v]
def lca(self, u, v):
while self.head[u] != self.head[v]:
if self.vid[u] > self.vid[v]:
u, v = v, u
v = self.parent[self.head[v]]
else:
if self.vid[u] > self.vid[v]:
u, v = v, u
return u
N = int(eval(input()))
g = [[] for _ in range(N)]
for i in range(N):
for c in map(int, input().split()[1:]):
g[i].append(c)
g[c].append(i)
hld = HeavyLightDecomposition(g)
Q = int(eval(input()))
for _ in range(Q):
u, v = list(map(int, input().split()))
print((hld.lca(u, v)))
| false | 22.222222 | [
"-class Edge:",
"- def __init__(self, dst, weight):",
"- self.dst, self.weight = dst, weight",
"-",
"- def __lt__(self, e):",
"- return self.weight > e.weight",
"-",
"-",
"-class Graph:",
"- def __init__(self, V):",
"- self.V = V",
"- self.E = [[] for _ in ... | false | 0.043248 | 0.094637 | 0.45699 | [
"s259590242",
"s738807195"
] |
u141429472 | p02818 | python | s203729466 | s429628640 | 236 | 62 | 51,564 | 6,080 | Accepted | Accepted | 73.73 | import sys
input = sys.stdin.readline
A,B,K=list(map(int,input().rstrip().split()))
def resolve():
if(A>K):
ansA=int(A)-int(K)
ansB=int(B)
else:
ansA=0
ansB=int(B)-(int(K)-int(A))
if(ansB<0):
ansB=0
print((str(int(ansA))+" "+str(int(ansB))))
import sys
from io import StringIO
import unittest
#1000000000000 1000000000000 1000000000001
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """2 3 3"""
output = """0 2"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """500000000000 500000000000 1000000000000"""
output = """0 0"""
self.assertIO(input, output)
if __name__ == "__main__":
#unittest.main()
resolve() | import sys
input = sys.stdin.readline
A,B,K=list(map(int,input().rstrip().split()))
"""
def resolve():
if(A>K):
ansA=int(A)-int(K)
ansB=int(B)
else:
ansA=0
ansB=int(B)-(int(K)-int(A))
if(ansB<0):
ansB=0
print(str(int(ansA))+" "+str(int(ansB)))
"""
def resolve():
if(A>K):
ansA=int(A)-int(K)
ansB=int(B)
else:
ansA=0
ansB=int(B)-(int(K)-int(A))
if(ansB<0):
ansB=0
print((ansA,ansB))
import sys
from io import StringIO
import unittest
#1000000000000 1000000000000 1000000000001
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """2 3 3"""
output = """0 2"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """500000000000 500000000000 1000000000000"""
output = """0 0"""
self.assertIO(input, output)
if __name__ == "__main__":
#unittest.main()
resolve() | 41 | 54 | 1,118 | 1,334 | import sys
input = sys.stdin.readline
A, B, K = list(map(int, input().rstrip().split()))
def resolve():
if A > K:
ansA = int(A) - int(K)
ansB = int(B)
else:
ansA = 0
ansB = int(B) - (int(K) - int(A))
if ansB < 0:
ansB = 0
print((str(int(ansA)) + " " + str(int(ansB))))
import sys
from io import StringIO
import unittest
# 1000000000000 1000000000000 1000000000001
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """2 3 3"""
output = """0 2"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """500000000000 500000000000 1000000000000"""
output = """0 0"""
self.assertIO(input, output)
if __name__ == "__main__":
# unittest.main()
resolve()
| import sys
input = sys.stdin.readline
A, B, K = list(map(int, input().rstrip().split()))
"""
def resolve():
if(A>K):
ansA=int(A)-int(K)
ansB=int(B)
else:
ansA=0
ansB=int(B)-(int(K)-int(A))
if(ansB<0):
ansB=0
print(str(int(ansA))+" "+str(int(ansB)))
"""
def resolve():
if A > K:
ansA = int(A) - int(K)
ansB = int(B)
else:
ansA = 0
ansB = int(B) - (int(K) - int(A))
if ansB < 0:
ansB = 0
print((ansA, ansB))
import sys
from io import StringIO
import unittest
# 1000000000000 1000000000000 1000000000001
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """2 3 3"""
output = """0 2"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """500000000000 500000000000 1000000000000"""
output = """0 0"""
self.assertIO(input, output)
if __name__ == "__main__":
# unittest.main()
resolve()
| false | 24.074074 | [
"+\"\"\"",
"+def resolve():",
"+ if(A>K):",
"+ ansA=int(A)-int(K)",
"+ ansB=int(B)",
"+ else:",
"+ ansA=0",
"+ ansB=int(B)-(int(K)-int(A))",
"+ if(ansB<0):",
"+ ansB=0",
"+ print(str(int(ansA))+\" \"+str(int(ansB)))",
"+\"\"\"",
"- pr... | false | 0.122105 | 0.28043 | 0.435421 | [
"s203729466",
"s429628640"
] |
u759412327 | p04031 | python | s132525578 | s859358608 | 33 | 26 | 9,108 | 9,064 | Accepted | Accepted | 21.21 | N = int(eval(input()))
A = list(map(int,input().split()))
print((min(sum((a-n)**2 for a in A) for n in range(min(A),1+max(A))))) | N = int(eval(input()))
A = list(map(int,input().split()))
m = round(sum(A)/N)
print((sum((a-m)**2 for a in A))) | 3 | 4 | 122 | 106 | N = int(eval(input()))
A = list(map(int, input().split()))
print((min(sum((a - n) ** 2 for a in A) for n in range(min(A), 1 + max(A)))))
| N = int(eval(input()))
A = list(map(int, input().split()))
m = round(sum(A) / N)
print((sum((a - m) ** 2 for a in A)))
| false | 25 | [
"-print((min(sum((a - n) ** 2 for a in A) for n in range(min(A), 1 + max(A)))))",
"+m = round(sum(A) / N)",
"+print((sum((a - m) ** 2 for a in A)))"
] | false | 0.149908 | 0.041777 | 3.588245 | [
"s132525578",
"s859358608"
] |
u183754334 | p03854 | python | s640485314 | s360884684 | 105 | 18 | 3,480 | 3,188 | Accepted | Accepted | 82.86 | # coding: utf-8
"""this is python work script"""
CHECK_WORDS = ['dream', 'dreamer', 'erase', 'eraser']
def check_word(word, check_word_list):
find_word = False
# print(word, check_word_list)
for i, cw in enumerate(check_word_list):
find_result = word.find(cw)
# print(i, cw, find_result)
# # remove check word if not find it in string
# if find_result == -1:
# check_word_list.remove(cw)
# remove word if find it in string head
if find_result == 0:
word_length = len(cw)
word = word[word_length:]
find_word = True
# print(word, check_word_list)
return find_word, word
def solver(word, check_word_list):
"""solve this problem"""
wip = True
while wip:
wip, word = check_word(word, check_word_list)
answer = 'NO'
if len(word) == 0:
answer = 'YES'
return answer
def reverse_string_list(string_list):
answer_list = []
for word in string_list:
answer_list.append(word[::-1])
return answer_list
def main():
"""main function"""
word = input().rstrip()[::-1]
word_list = reverse_string_list(CHECK_WORDS)
answer = solver(word=word, check_word_list=word_list)
print(answer)
if __name__ == '__main__':
main()
| # coding: utf-8
"""this is python work script"""
def solver(word):
"""solve this problem"""
check_result = word.replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '')
answer = 'YES'
if check_result:
answer = 'NO'
return answer
def main():
"""main function"""
input_word = input().rstrip()
answer = solver(input_word)
print(answer)
if __name__ == '__main__':
main()
| 53 | 21 | 1,350 | 470 | # coding: utf-8
"""this is python work script"""
CHECK_WORDS = ["dream", "dreamer", "erase", "eraser"]
def check_word(word, check_word_list):
find_word = False
# print(word, check_word_list)
for i, cw in enumerate(check_word_list):
find_result = word.find(cw)
# print(i, cw, find_result)
# # remove check word if not find it in string
# if find_result == -1:
# check_word_list.remove(cw)
# remove word if find it in string head
if find_result == 0:
word_length = len(cw)
word = word[word_length:]
find_word = True
# print(word, check_word_list)
return find_word, word
def solver(word, check_word_list):
"""solve this problem"""
wip = True
while wip:
wip, word = check_word(word, check_word_list)
answer = "NO"
if len(word) == 0:
answer = "YES"
return answer
def reverse_string_list(string_list):
answer_list = []
for word in string_list:
answer_list.append(word[::-1])
return answer_list
def main():
"""main function"""
word = input().rstrip()[::-1]
word_list = reverse_string_list(CHECK_WORDS)
answer = solver(word=word, check_word_list=word_list)
print(answer)
if __name__ == "__main__":
main()
| # coding: utf-8
"""this is python work script"""
def solver(word):
"""solve this problem"""
check_result = (
word.replace("eraser", "")
.replace("erase", "")
.replace("dreamer", "")
.replace("dream", "")
)
answer = "YES"
if check_result:
answer = "NO"
return answer
def main():
"""main function"""
input_word = input().rstrip()
answer = solver(input_word)
print(answer)
if __name__ == "__main__":
main()
| false | 60.377358 | [
"-CHECK_WORDS = [\"dream\", \"dreamer\", \"erase\", \"eraser\"]",
"-def check_word(word, check_word_list):",
"- find_word = False",
"- # print(word, check_word_list)",
"- for i, cw in enumerate(check_word_list):",
"- find_result = word.find(cw)",
"- # print(i, cw, find_result)",
... | false | 0.038168 | 0.037606 | 1.01494 | [
"s640485314",
"s360884684"
] |
u922965680 | p02900 | python | s143480135 | s956033128 | 216 | 191 | 38,612 | 38,512 | Accepted | Accepted | 11.57 | import sys
import math
def main():
a, b = [int(s) for s in sys.stdin.readline().strip().split()]
def factorize(x):
ret = set()
for n in range(2, int(math.sqrt(x))+2):
if x % n == 0:
while x % n == 0:
x //= n
ret.add(n)
if x != 1:
ret.add(x)
return ret
a_primes = factorize(a)
b_primes = factorize(b)
shared = a_primes.intersection(b_primes)
print((len(shared) + 1))
main()
| import sys
import math
def main():
a, b = [int(s) for s in sys.stdin.readline().strip().split()]
def factorize(x):
ret = set()
for n in range(2, int(math.sqrt(x))+1):
if x % n == 0:
while x % n == 0:
x //= n
ret.add(n)
if x != 1:
ret.add(x)
return ret
a_primes = factorize(a)
b_primes = factorize(b)
shared = a_primes.intersection(b_primes)
print((len(shared) + 1))
main()
| 24 | 25 | 531 | 533 | import sys
import math
def main():
a, b = [int(s) for s in sys.stdin.readline().strip().split()]
def factorize(x):
ret = set()
for n in range(2, int(math.sqrt(x)) + 2):
if x % n == 0:
while x % n == 0:
x //= n
ret.add(n)
if x != 1:
ret.add(x)
return ret
a_primes = factorize(a)
b_primes = factorize(b)
shared = a_primes.intersection(b_primes)
print((len(shared) + 1))
main()
| import sys
import math
def main():
a, b = [int(s) for s in sys.stdin.readline().strip().split()]
def factorize(x):
ret = set()
for n in range(2, int(math.sqrt(x)) + 1):
if x % n == 0:
while x % n == 0:
x //= n
ret.add(n)
if x != 1:
ret.add(x)
return ret
a_primes = factorize(a)
b_primes = factorize(b)
shared = a_primes.intersection(b_primes)
print((len(shared) + 1))
main()
| false | 4 | [
"- for n in range(2, int(math.sqrt(x)) + 2):",
"+ for n in range(2, int(math.sqrt(x)) + 1):"
] | false | 0.065228 | 0.067117 | 0.97185 | [
"s143480135",
"s956033128"
] |
u072717685 | p02720 | python | s067777404 | s560060939 | 294 | 266 | 13,868 | 38,380 | Accepted | Accepted | 9.52 | import sys
sys.setrecursionlimit(10**6)
from copy import deepcopy
def main():
k = int(eval(input()))
l = []
ll = [1,2,3,4,5,6,7,8,9]
def dfs(num, keta):
#print(num,len(num),keta)
if len(num) == keta:
ll.append(int(num))
#print(len(l))
else:
if num[-1] == '0':
dfs(num + '0', keta)
dfs(num + '1', keta)
elif num[-1] == '9':
dfs(num + '9', keta)
dfs(num + '8', keta)
else:
dfs(num + str(int(num[-1]) + 1), keta)
dfs(num + str(int(num[-1])), keta)
dfs(num + str(int(num[-1]) - 1), keta)
for i in range(2,10000):
l = l + ll
if len(l) > k:
l.sort()
print((l[k-1]))
break
else:
tmp_ll = deepcopy(ll)
ll = []
for el in tmp_ll:
dfs(str(el), i)
if __name__ == '__main__':
main()
| import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil, log
def main():
k = int(eval(input()))
k2 = int(log(ceil(k / 10), 3)) + 1
def getlun(n, keta, last):
lunluns.append(n)
if keta > k2:
pass
else:
l1 = n * 10 + last
getlun(l1, keta + 1, last)
if last > 0:
l2 = n * 10 + last - 1
getlun(l2, keta + 1, last - 1)
if last < 9:
l3 = n * 10 + last + 1
getlun(l3, keta + 1, last + 1)
lunluns = []
for i1 in range(1, 10):
getlun(i1, 0, i1)
lunluns.sort()
print((lunluns[k-1]))
if __name__ == '__main__':
main()
| 43 | 29 | 1,043 | 776 | import sys
sys.setrecursionlimit(10**6)
from copy import deepcopy
def main():
k = int(eval(input()))
l = []
ll = [1, 2, 3, 4, 5, 6, 7, 8, 9]
def dfs(num, keta):
# print(num,len(num),keta)
if len(num) == keta:
ll.append(int(num))
# print(len(l))
else:
if num[-1] == "0":
dfs(num + "0", keta)
dfs(num + "1", keta)
elif num[-1] == "9":
dfs(num + "9", keta)
dfs(num + "8", keta)
else:
dfs(num + str(int(num[-1]) + 1), keta)
dfs(num + str(int(num[-1])), keta)
dfs(num + str(int(num[-1]) - 1), keta)
for i in range(2, 10000):
l = l + ll
if len(l) > k:
l.sort()
print((l[k - 1]))
break
else:
tmp_ll = deepcopy(ll)
ll = []
for el in tmp_ll:
dfs(str(el), i)
if __name__ == "__main__":
main()
| import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil, log
def main():
k = int(eval(input()))
k2 = int(log(ceil(k / 10), 3)) + 1
def getlun(n, keta, last):
lunluns.append(n)
if keta > k2:
pass
else:
l1 = n * 10 + last
getlun(l1, keta + 1, last)
if last > 0:
l2 = n * 10 + last - 1
getlun(l2, keta + 1, last - 1)
if last < 9:
l3 = n * 10 + last + 1
getlun(l3, keta + 1, last + 1)
lunluns = []
for i1 in range(1, 10):
getlun(i1, 0, i1)
lunluns.sort()
print((lunluns[k - 1]))
if __name__ == "__main__":
main()
| false | 32.55814 | [
"-from copy import deepcopy",
"+read = sys.stdin.read",
"+readlines = sys.stdin.readlines",
"+from math import ceil, log",
"- l = []",
"- ll = [1, 2, 3, 4, 5, 6, 7, 8, 9]",
"+ k2 = int(log(ceil(k / 10), 3)) + 1",
"- def dfs(num, keta):",
"- # print(num,len(num),keta)",
"- ... | false | 0.070691 | 0.083078 | 0.850902 | [
"s067777404",
"s560060939"
] |
u957198490 | p03371 | python | s675883106 | s177851215 | 180 | 29 | 38,384 | 9,160 | Accepted | Accepted | 83.89 | A, B, C, X, Y = list(map(int, input().split()))
ans = 0
if A + B <= 2*C:
ans = A*X + B*Y
else:
ans += 2*C*min(X, Y)
if X >= Y:
ans += min(A, 2*C) * (X-Y)
else:
ans += min(B, 2*C) * (Y-X)
print (ans)
| A,B,C,x,y = list(map(int,input().split()))
ans = 0
if A+B > 2*C:
ans += min(x,y)*C*2
else:
ans += x*A + y*B
print(ans)
exit()
if x >= y:
x -= y
y = 0
if A <2*C:
ans += x*A
else:
ans += x*2*C
else:
y -= x
x = 0
if B < 2*C:
ans += y*B
else:
ans += y*2*C
print(ans) | 12 | 24 | 237 | 369 | A, B, C, X, Y = list(map(int, input().split()))
ans = 0
if A + B <= 2 * C:
ans = A * X + B * Y
else:
ans += 2 * C * min(X, Y)
if X >= Y:
ans += min(A, 2 * C) * (X - Y)
else:
ans += min(B, 2 * C) * (Y - X)
print(ans)
| A, B, C, x, y = list(map(int, input().split()))
ans = 0
if A + B > 2 * C:
ans += min(x, y) * C * 2
else:
ans += x * A + y * B
print(ans)
exit()
if x >= y:
x -= y
y = 0
if A < 2 * C:
ans += x * A
else:
ans += x * 2 * C
else:
y -= x
x = 0
if B < 2 * C:
ans += y * B
else:
ans += y * 2 * C
print(ans)
| false | 50 | [
"-A, B, C, X, Y = list(map(int, input().split()))",
"+A, B, C, x, y = list(map(int, input().split()))",
"-if A + B <= 2 * C:",
"- ans = A * X + B * Y",
"+if A + B > 2 * C:",
"+ ans += min(x, y) * C * 2",
"- ans += 2 * C * min(X, Y)",
"- if X >= Y:",
"- ans += min(A, 2 * C) * (X - ... | false | 0.05426 | 0.035434 | 1.531277 | [
"s675883106",
"s177851215"
] |
u454093752 | p02551 | python | s092554924 | s003137194 | 1,946 | 1,250 | 127,408 | 101,636 | Accepted | Accepted | 35.77 | class LazySegmentTree:
"""
init(init_val, ide_ele): 配列init_valで初期化 O(N)
update(l, r, x): 区間[l, r)をxに更新 O(logN)
query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
"""
def __init__(self, init_val, segfunc, ide_ele):
"""
init_val: 配列の初期値
segfunc: 区間にしたい操作
ide_ele: 単位元
num: n以上の最小の2のべき乗
data: 値配列(1-index)
lazy: 遅延配列(1-index)
"""
n = len(init_val)
self.segfunc = segfunc
self.ide_ele = ide_ele
self.num = 1 << (n - 1).bit_length()
self.data = [ide_ele] * 2 * self.num
self.lazy = [None] * 2 * self.num
# 配列の値を葉にセット
for i in range(n):
self.data[self.num + i] = init_val[i]
# 構築していく
for i in range(self.num - 1, 0, -1):
self.data[i] = self.segfunc(self.data[2 * i], self.data[2 * i + 1])
def gindex(self, l, r):
"""
伝搬する対象の区間を求める
lm: 伝搬する必要のある最大の左閉区間
rm: 伝搬する必要のある最大の右開区間
"""
l += self.num
r += self.num
lm = l >> (l & -l).bit_length()
rm = r >> (r & -r).bit_length()
while r > l:
if l <= lm:
yield l
if r <= rm:
yield r
r >>= 1
l >>= 1
while l:
yield l
l >>= 1
def propagates(self, *ids):
"""
遅延伝搬処理
ids: 伝搬する対象の区間
"""
for i in reversed(ids):
v = self.lazy[i]
if v is None:
continue
self.lazy[2 * i] = v
self.lazy[2 * i + 1] = v
self.data[2 * i] = v
self.data[2 * i + 1] = v
self.lazy[i] = None
def update(self, l, r, x):
"""
区間[l, r)の値をxに更新
l, r: index(0-index)
x: update value
"""
*ids, = self.gindex(l, r)
self.propagates(*ids)
l += self.num
r += self.num
while l < r:
if l & 1:
self.lazy[l] = x
self.data[l] = x
l += 1
if r & 1:
self.lazy[r - 1] = x
self.data[r - 1] = x
r >>= 1
l >>= 1
for i in ids:
self.data[i] = self.segfunc(self.data[2 * i], self.data[2 * i + 1])
def query(self, l, r):
"""
[l, r)のsegfuncしたものを得る
l: index(0-index)
r: index(0-index)
"""
*ids, = self.gindex(l, r)
self.propagates(*ids)
res = self.ide_ele
l += self.num
r += self.num
while l < r:
if l & 1:
res = self.segfunc(res, self.data[l])
l += 1
if r & 1:
res = self.segfunc(res, self.data[r - 1])
l >>= 1
r >>= 1
return res
def segfunc(x, y):
return min(x, y)
ide_ele = 10**9
N, Q = list(map(int, input().split()))
ans = (N-2)*(N-2)
R = [N]*(N+1)
W = [N]*(N+1)
seg_r = LazySegmentTree(R, segfunc, ide_ele)
seg_w = LazySegmentTree(W, segfunc, ide_ele)
for i in range(Q):
a, b = list(map(int, input().split()))
if a == 1:
t = seg_r.query(b, b+1)
ans -= max(0, t - 2)
if b <= seg_w.query(1, 2):
seg_w.update(1, t+1, b)
seg_r.update(b, b+1, 0)
else:
t = seg_w.query(b, b+1)
ans -= max(0, t - 2)
if b <= seg_r.query(1, 2):
seg_r.update(1, t+1, b)
seg_w.update(b, b+1, 0)
print(ans) | class LazySegmentTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.segfunc = segfunc
self.ide_ele = ide_ele
self.num = 1 << (n - 1).bit_length()
self.data = [ide_ele] * 2 * self.num
self.lazy = [None] * 2 * self.num
for i in range(n):
self.data[self.num + i] = init_val[i]
for i in range(self.num - 1, 0, -1):
self.data[i] = self.segfunc(self.data[2 * i], self.data[2 * i + 1])
def gindex(self, l, r):
l += self.num
r += self.num
lm = l >> (l & -l).bit_length()
rm = r >> (r & -r).bit_length()
while r > l:
if l <= lm:
yield l
if r <= rm:
yield r
r >>= 1
l >>= 1
while l:
yield l
l >>= 1
def propagates(self, *ids):
for i in reversed(ids):
v = self.lazy[i]
if v is None:
continue
self.lazy[2 * i] = v
self.lazy[2 * i + 1] = v
self.data[2 * i] = v
self.data[2 * i + 1] = v
self.lazy[i] = None
def update(self, l, r, x):
*ids, = self.gindex(l, r)
self.propagates(*ids)
l += self.num
r += self.num
while l < r:
if l & 1:
self.lazy[l] = x
self.data[l] = x
l += 1
if r & 1:
self.lazy[r - 1] = x
self.data[r - 1] = x
r >>= 1
l >>= 1
for i in ids:
self.data[i] = self.segfunc(self.data[2 * i], self.data[2 * i + 1])
def query(self, l, r):
*ids, = self.gindex(l, r)
self.propagates(*ids)
res = self.ide_ele
l += self.num
r += self.num
while l < r:
if l & 1:
res = self.segfunc(res, self.data[l])
l += 1
if r & 1:
res = self.segfunc(res, self.data[r - 1])
l >>= 1
r >>= 1
return res
def segfunc(x, y):
return min(x, y)
ide_ele = 10**9
N, Q = list(map(int, input().split()))
ans = (N-2)*(N-2)
R = [N]*(N+1)
W = [N]*(N+1)
seg_r = LazySegmentTree(R, segfunc, ide_ele)
seg_w = LazySegmentTree(W, segfunc, ide_ele)
for i in range(Q):
a, b = list(map(int, input().split()))
if a == 1:
t = seg_r.query(b, b+1)
ans -= max(0, t - 2)
if b <= seg_w.query(1, 2):
seg_w.update(1, t+1, b)
else:
t = seg_w.query(b, b+1)
ans -= max(0, t - 2)
if b <= seg_r.query(1, 2):
seg_r.update(1, t+1, b)
print(ans) | 139 | 106 | 3,725 | 2,866 | class LazySegmentTree:
"""
init(init_val, ide_ele): 配列init_valで初期化 O(N)
update(l, r, x): 区間[l, r)をxに更新 O(logN)
query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
"""
def __init__(self, init_val, segfunc, ide_ele):
"""
init_val: 配列の初期値
segfunc: 区間にしたい操作
ide_ele: 単位元
num: n以上の最小の2のべき乗
data: 値配列(1-index)
lazy: 遅延配列(1-index)
"""
n = len(init_val)
self.segfunc = segfunc
self.ide_ele = ide_ele
self.num = 1 << (n - 1).bit_length()
self.data = [ide_ele] * 2 * self.num
self.lazy = [None] * 2 * self.num
# 配列の値を葉にセット
for i in range(n):
self.data[self.num + i] = init_val[i]
# 構築していく
for i in range(self.num - 1, 0, -1):
self.data[i] = self.segfunc(self.data[2 * i], self.data[2 * i + 1])
def gindex(self, l, r):
"""
伝搬する対象の区間を求める
lm: 伝搬する必要のある最大の左閉区間
rm: 伝搬する必要のある最大の右開区間
"""
l += self.num
r += self.num
lm = l >> (l & -l).bit_length()
rm = r >> (r & -r).bit_length()
while r > l:
if l <= lm:
yield l
if r <= rm:
yield r
r >>= 1
l >>= 1
while l:
yield l
l >>= 1
def propagates(self, *ids):
"""
遅延伝搬処理
ids: 伝搬する対象の区間
"""
for i in reversed(ids):
v = self.lazy[i]
if v is None:
continue
self.lazy[2 * i] = v
self.lazy[2 * i + 1] = v
self.data[2 * i] = v
self.data[2 * i + 1] = v
self.lazy[i] = None
def update(self, l, r, x):
"""
区間[l, r)の値をxに更新
l, r: index(0-index)
x: update value
"""
(*ids,) = self.gindex(l, r)
self.propagates(*ids)
l += self.num
r += self.num
while l < r:
if l & 1:
self.lazy[l] = x
self.data[l] = x
l += 1
if r & 1:
self.lazy[r - 1] = x
self.data[r - 1] = x
r >>= 1
l >>= 1
for i in ids:
self.data[i] = self.segfunc(self.data[2 * i], self.data[2 * i + 1])
def query(self, l, r):
"""
[l, r)のsegfuncしたものを得る
l: index(0-index)
r: index(0-index)
"""
(*ids,) = self.gindex(l, r)
self.propagates(*ids)
res = self.ide_ele
l += self.num
r += self.num
while l < r:
if l & 1:
res = self.segfunc(res, self.data[l])
l += 1
if r & 1:
res = self.segfunc(res, self.data[r - 1])
l >>= 1
r >>= 1
return res
def segfunc(x, y):
return min(x, y)
ide_ele = 10**9
N, Q = list(map(int, input().split()))
ans = (N - 2) * (N - 2)
R = [N] * (N + 1)
W = [N] * (N + 1)
seg_r = LazySegmentTree(R, segfunc, ide_ele)
seg_w = LazySegmentTree(W, segfunc, ide_ele)
for i in range(Q):
a, b = list(map(int, input().split()))
if a == 1:
t = seg_r.query(b, b + 1)
ans -= max(0, t - 2)
if b <= seg_w.query(1, 2):
seg_w.update(1, t + 1, b)
seg_r.update(b, b + 1, 0)
else:
t = seg_w.query(b, b + 1)
ans -= max(0, t - 2)
if b <= seg_r.query(1, 2):
seg_r.update(1, t + 1, b)
seg_w.update(b, b + 1, 0)
print(ans)
| class LazySegmentTree:
def __init__(self, init_val, segfunc, ide_ele):
n = len(init_val)
self.segfunc = segfunc
self.ide_ele = ide_ele
self.num = 1 << (n - 1).bit_length()
self.data = [ide_ele] * 2 * self.num
self.lazy = [None] * 2 * self.num
for i in range(n):
self.data[self.num + i] = init_val[i]
for i in range(self.num - 1, 0, -1):
self.data[i] = self.segfunc(self.data[2 * i], self.data[2 * i + 1])
def gindex(self, l, r):
l += self.num
r += self.num
lm = l >> (l & -l).bit_length()
rm = r >> (r & -r).bit_length()
while r > l:
if l <= lm:
yield l
if r <= rm:
yield r
r >>= 1
l >>= 1
while l:
yield l
l >>= 1
def propagates(self, *ids):
for i in reversed(ids):
v = self.lazy[i]
if v is None:
continue
self.lazy[2 * i] = v
self.lazy[2 * i + 1] = v
self.data[2 * i] = v
self.data[2 * i + 1] = v
self.lazy[i] = None
def update(self, l, r, x):
(*ids,) = self.gindex(l, r)
self.propagates(*ids)
l += self.num
r += self.num
while l < r:
if l & 1:
self.lazy[l] = x
self.data[l] = x
l += 1
if r & 1:
self.lazy[r - 1] = x
self.data[r - 1] = x
r >>= 1
l >>= 1
for i in ids:
self.data[i] = self.segfunc(self.data[2 * i], self.data[2 * i + 1])
def query(self, l, r):
(*ids,) = self.gindex(l, r)
self.propagates(*ids)
res = self.ide_ele
l += self.num
r += self.num
while l < r:
if l & 1:
res = self.segfunc(res, self.data[l])
l += 1
if r & 1:
res = self.segfunc(res, self.data[r - 1])
l >>= 1
r >>= 1
return res
def segfunc(x, y):
return min(x, y)
ide_ele = 10**9
N, Q = list(map(int, input().split()))
ans = (N - 2) * (N - 2)
R = [N] * (N + 1)
W = [N] * (N + 1)
seg_r = LazySegmentTree(R, segfunc, ide_ele)
seg_w = LazySegmentTree(W, segfunc, ide_ele)
for i in range(Q):
a, b = list(map(int, input().split()))
if a == 1:
t = seg_r.query(b, b + 1)
ans -= max(0, t - 2)
if b <= seg_w.query(1, 2):
seg_w.update(1, t + 1, b)
else:
t = seg_w.query(b, b + 1)
ans -= max(0, t - 2)
if b <= seg_r.query(1, 2):
seg_r.update(1, t + 1, b)
print(ans)
| false | 23.741007 | [
"- \"\"\"",
"- init(init_val, ide_ele): 配列init_valで初期化 O(N)",
"- update(l, r, x): 区間[l, r)をxに更新 O(logN)",
"- query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)",
"- \"\"\"",
"-",
"- \"\"\"",
"- init_val: 配列の初期値",
"- segfunc: 区間にしたい操作",
"- ide_ele: 単位元",
"- ... | false | 0.740363 | 0.39967 | 1.852434 | [
"s092554924",
"s003137194"
] |
u185249212 | p03031 | python | s945280374 | s366120875 | 402 | 32 | 59,868 | 3,188 | Accepted | Accepted | 92.04 |
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
# import math
# import string
# import fractions
# from fractions import Fraction
# from fractions import gcd
# def lcm(n,m):
# return int(n*m/gcd(n,m))
# import re
# import array
# import copy
# import functools
# import operator
# import collections
# import itertools
# import bisect
# import heapq
# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace
# from queue import PriorityQueue as pq
# # from itertools import accumulate
# # from collections import deque
# import random
def main():
n,m = list(map(int, input().split())) # n represents switch, m represents lights
lights=[]
for i in range(m):
ll=list(map(int, input().split()))
lights.append(ll[1:])
p = list(map(int, input().split()))
eprint(lights)
# eprint(s)
# l=s
# l[1]=[]
# eprint(l,s)
# cnt_ans=0
ans=0
for case in range((1<<n)):
eprint(bin(case))
# cnt_switch_on = 0
ii=0
f_flag=0
for light in lights:
cnt_on=0
for i in light:
if (case>>(i-1))&1:
cnt_on+=1
eprint(cnt_on,p[ii])
if cnt_on%2!=p[ii]:
f_flag=1
ii+=1
if f_flag==0:
ans+=1
print(ans)
# for i in range(n):
# if (case>>i)&1:
# cnt_switch_on +=1
# eprint("cnt_switch_on",cnt_switch_on)
# f_flag=0
# for light in range(m):
# if cnt_switch_on % 2 == p[light]:
# eprint("剰余",cnt_switch_on % 2,"p",p[light])
# else:
# f_flag=1
# if f_flag==0:
# cnt_ans+=1
# eprint("cnt_ans",cnt_ans)
# print(cnt_ans)
if __name__ == '__main__':
main()
|
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
def main():
n,m = list(map(int, input().split())) # n represents switch, m represents lights
lights=[]
for i in range(m):
ll=list(map(int, input().split()))
lights.append(ll[1:])
p = list(map(int, input().split()))
# eprint(lights)
# eprint(s)
ans=0
for case in range((1<<n)):
# eprint(bin(case))
# cnt_switch_on = 0
ii=0
f_flag=0
for light in lights:
cnt_on=0
for i in light:
if (case>>(i-1))&1:
cnt_on+=1
# eprint(cnt_on,p[ii])
if cnt_on%2!=p[ii]:
f_flag=1
ii+=1
if f_flag==0:
ans+=1
print(ans)
if __name__ == '__main__':
main()
| 97 | 38 | 2,185 | 986 | # import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
# import math
# import string
# import fractions
# from fractions import Fraction
# from fractions import gcd
# def lcm(n,m):
# return int(n*m/gcd(n,m))
# import re
# import array
# import copy
# import functools
# import operator
# import collections
# import itertools
# import bisect
# import heapq
# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace
# from queue import PriorityQueue as pq
# # from itertools import accumulate
# # from collections import deque
# import random
def main():
n, m = list(map(int, input().split())) # n represents switch, m represents lights
lights = []
for i in range(m):
ll = list(map(int, input().split()))
lights.append(ll[1:])
p = list(map(int, input().split()))
eprint(lights)
# eprint(s)
# l=s
# l[1]=[]
# eprint(l,s)
# cnt_ans=0
ans = 0
for case in range((1 << n)):
eprint(bin(case))
# cnt_switch_on = 0
ii = 0
f_flag = 0
for light in lights:
cnt_on = 0
for i in light:
if (case >> (i - 1)) & 1:
cnt_on += 1
eprint(cnt_on, p[ii])
if cnt_on % 2 != p[ii]:
f_flag = 1
ii += 1
if f_flag == 0:
ans += 1
print(ans)
# for i in range(n):
# if (case>>i)&1:
# cnt_switch_on +=1
# eprint("cnt_switch_on",cnt_switch_on)
# f_flag=0
# for light in range(m):
# if cnt_switch_on % 2 == p[light]:
# eprint("剰余",cnt_switch_on % 2,"p",p[light])
# else:
# f_flag=1
# if f_flag==0:
# cnt_ans+=1
# eprint("cnt_ans",cnt_ans)
# print(cnt_ans)
if __name__ == "__main__":
main()
| # import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
def main():
n, m = list(map(int, input().split())) # n represents switch, m represents lights
lights = []
for i in range(m):
ll = list(map(int, input().split()))
lights.append(ll[1:])
p = list(map(int, input().split()))
# eprint(lights)
# eprint(s)
ans = 0
for case in range((1 << n)):
# eprint(bin(case))
# cnt_switch_on = 0
ii = 0
f_flag = 0
for light in lights:
cnt_on = 0
for i in light:
if (case >> (i - 1)) & 1:
cnt_on += 1
# eprint(cnt_on,p[ii])
if cnt_on % 2 != p[ii]:
f_flag = 1
ii += 1
if f_flag == 0:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| false | 60.824742 | [
"-# import math",
"-# import string",
"-# import fractions",
"-# from fractions import Fraction",
"-# from fractions import gcd",
"-# def lcm(n,m):",
"-# return int(n*m/gcd(n,m))",
"-# import re",
"-# import array",
"-# import copy",
"-# import functools",
"-# import operator",
"-# impor... | false | 0.038727 | 0.040464 | 0.957092 | [
"s945280374",
"s366120875"
] |
u896741788 | p03475 | python | s829354703 | s071664529 | 75 | 66 | 3,188 | 3,188 | Accepted | Accepted | 12 | def f():
n=int(eval(input()))
l=tuple(tuple(map(int,input().split())) for i in range(n-1))
for i in range(n):
now=0
for a,s,d in l[i:]:
now=a+s-(-max(0,now-s)//d)*d
print(now)
if __name__=="__main__":
f() | import sys
input = sys.stdin.readline
def f():
n=int(eval(input()))
l=tuple(tuple(map(int,input().split())) for i in range(n-1))
for i in range(n):
now=0
for a,s,d in l[i:]:
now=a+s-(-max(0,now-s)//d)*d
print(now)
if __name__=="__main__":
f()
| 10 | 12 | 233 | 274 | def f():
n = int(eval(input()))
l = tuple(tuple(map(int, input().split())) for i in range(n - 1))
for i in range(n):
now = 0
for a, s, d in l[i:]:
now = a + s - (-max(0, now - s) // d) * d
print(now)
if __name__ == "__main__":
f()
| import sys
input = sys.stdin.readline
def f():
n = int(eval(input()))
l = tuple(tuple(map(int, input().split())) for i in range(n - 1))
for i in range(n):
now = 0
for a, s, d in l[i:]:
now = a + s - (-max(0, now - s) // d) * d
print(now)
if __name__ == "__main__":
f()
| false | 16.666667 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"+",
"+"
] | false | 0.042786 | 0.035436 | 1.20741 | [
"s829354703",
"s071664529"
] |
u608007704 | p02537 | python | s289747745 | s010343308 | 1,663 | 1,399 | 102,952 | 102,152 | Accepted | Accepted | 15.87 | def op(a,b):
return max(a,b)
class segmentTree:
def __init__(self,n,op,init_value):
dataLen=1 << (n - 1).bit_length()
self.data=[init_value]*(2*dataLen)
self.op=op
self.length=dataLen
def getIdx(self,left,right):
idxs=[]
l=left
r=right
while True:
idx=1
valueL=0
valueR=self.length-1
while l!=valueL or valueR>=r:
if l<=(valueR+valueL)//2:
valueR-=(valueR-valueL+1)//2
idx*=2
else:
valueL+=(valueR-valueL+1)//2
idx=idx*2+1
idxs.append(idx)
if valueR==r-1:
break
l=valueR+1
return idxs
def get(self,n):
return self.data[self.getIdx(n,n+1)[0]]
def set(self,n,value):
if n<0 or n>=self.length:
return False
idx1=self.getIdx(n,n+1)[0]
self.data[idx1]=value
while idx1!=1:
idx2=idx1^1
if idx1>idx2:
idx1,idx2=idx2,idx1
self.data[idx1//2]=self.op(self.data[idx1],self.data[idx2])
idx1//=2
return True
def query(self,l,r):
idxs=self.getIdx(l,r)
ret=self.data[idxs[0]]
for idx in idxs:
ret=self.op(ret,self.data[idx])
return ret
N,K=list(map(int,input().split()))
A=[]
for i in range(N):
A.append(int(eval(input())))
N=300000
seg = segmentTree(N, op, 0)
for i in A:
l=min(N,max(0,i-K))
r=max(0,min(N,i+K))
v=seg.query(l,r+1)
seg.set(i,v+1)
print((seg.query(0,N))) | def op(a,b):
return max(a,b)
class segmentTree:
def __init__(self,n,op,init_value):
dataLen=1 << (n - 1).bit_length()
self.data=[init_value]*(2*dataLen)
self.op=op
self.length=dataLen
def getIdx(self,left,right):
idxs=[]
l=left
r=right
while True:
idx=1
valueL=0
valueR=self.length-1
while l!=valueL or valueR>=r:
if l<=(valueR+valueL)//2:
valueR-=(valueR-valueL+1)//2
idx*=2
else:
valueL+=(valueR-valueL+1)//2
idx=idx*2+1
idxs.append(idx)
if valueR==r-1:
break
l=valueR+1
return idxs
def get(self,n):
return self.data[n+self.length]
def set(self,n,value):
idx1=n+self.length
self.data[idx1]=value
while idx1!=1:
idx2=idx1^1
if idx1>idx2:
idx1,idx2=idx2,idx1
self.data[idx1//2]=self.op(self.data[idx1],self.data[idx2])
idx1//=2
def query(self,l,r):
idxs=self.getIdx(l,r)
ret=self.data[idxs[0]]
for idx in idxs:
ret=self.op(ret,self.data[idx])
return ret
N,K=list(map(int,input().split()))
A=[]
for i in range(N):
A.append(int(eval(input())))
N=300000
seg = segmentTree(N, op, 0)
for i in A:
l=min(N,max(0,i-K))
r=max(0,min(N,i+K))
v=seg.query(l,r+1)
seg.set(i,v+1)
print((seg.query(0,N)))
| 66 | 63 | 1,696 | 1,601 | def op(a, b):
return max(a, b)
class segmentTree:
def __init__(self, n, op, init_value):
dataLen = 1 << (n - 1).bit_length()
self.data = [init_value] * (2 * dataLen)
self.op = op
self.length = dataLen
def getIdx(self, left, right):
idxs = []
l = left
r = right
while True:
idx = 1
valueL = 0
valueR = self.length - 1
while l != valueL or valueR >= r:
if l <= (valueR + valueL) // 2:
valueR -= (valueR - valueL + 1) // 2
idx *= 2
else:
valueL += (valueR - valueL + 1) // 2
idx = idx * 2 + 1
idxs.append(idx)
if valueR == r - 1:
break
l = valueR + 1
return idxs
def get(self, n):
return self.data[self.getIdx(n, n + 1)[0]]
def set(self, n, value):
if n < 0 or n >= self.length:
return False
idx1 = self.getIdx(n, n + 1)[0]
self.data[idx1] = value
while idx1 != 1:
idx2 = idx1 ^ 1
if idx1 > idx2:
idx1, idx2 = idx2, idx1
self.data[idx1 // 2] = self.op(self.data[idx1], self.data[idx2])
idx1 //= 2
return True
def query(self, l, r):
idxs = self.getIdx(l, r)
ret = self.data[idxs[0]]
for idx in idxs:
ret = self.op(ret, self.data[idx])
return ret
N, K = list(map(int, input().split()))
A = []
for i in range(N):
A.append(int(eval(input())))
N = 300000
seg = segmentTree(N, op, 0)
for i in A:
l = min(N, max(0, i - K))
r = max(0, min(N, i + K))
v = seg.query(l, r + 1)
seg.set(i, v + 1)
print((seg.query(0, N)))
| def op(a, b):
return max(a, b)
class segmentTree:
def __init__(self, n, op, init_value):
dataLen = 1 << (n - 1).bit_length()
self.data = [init_value] * (2 * dataLen)
self.op = op
self.length = dataLen
def getIdx(self, left, right):
idxs = []
l = left
r = right
while True:
idx = 1
valueL = 0
valueR = self.length - 1
while l != valueL or valueR >= r:
if l <= (valueR + valueL) // 2:
valueR -= (valueR - valueL + 1) // 2
idx *= 2
else:
valueL += (valueR - valueL + 1) // 2
idx = idx * 2 + 1
idxs.append(idx)
if valueR == r - 1:
break
l = valueR + 1
return idxs
def get(self, n):
return self.data[n + self.length]
def set(self, n, value):
idx1 = n + self.length
self.data[idx1] = value
while idx1 != 1:
idx2 = idx1 ^ 1
if idx1 > idx2:
idx1, idx2 = idx2, idx1
self.data[idx1 // 2] = self.op(self.data[idx1], self.data[idx2])
idx1 //= 2
def query(self, l, r):
idxs = self.getIdx(l, r)
ret = self.data[idxs[0]]
for idx in idxs:
ret = self.op(ret, self.data[idx])
return ret
N, K = list(map(int, input().split()))
A = []
for i in range(N):
A.append(int(eval(input())))
N = 300000
seg = segmentTree(N, op, 0)
for i in A:
l = min(N, max(0, i - K))
r = max(0, min(N, i + K))
v = seg.query(l, r + 1)
seg.set(i, v + 1)
print((seg.query(0, N)))
| false | 4.545455 | [
"- return self.data[self.getIdx(n, n + 1)[0]]",
"+ return self.data[n + self.length]",
"- if n < 0 or n >= self.length:",
"- return False",
"- idx1 = self.getIdx(n, n + 1)[0]",
"+ idx1 = n + self.length",
"- return True"
] | false | 0.075439 | 0.075531 | 0.99878 | [
"s289747745",
"s010343308"
] |
u816631826 | p03272 | python | s053699673 | s733357264 | 183 | 17 | 38,256 | 2,940 | Accepted | Accepted | 90.71 | N,i= list(map(int,input().split()))
print((N-i+1)) | n, i = list(map(int, input().split()))
print((n + 1 - i))
| 3 | 2 | 131 | 51 | N, i = list(map(int, input().split()))
print((N - i + 1))
| n, i = list(map(int, input().split()))
print((n + 1 - i))
| false | 33.333333 | [
"-N, i = list(map(int, input().split()))",
"-print((N - i + 1))",
"+n, i = list(map(int, input().split()))",
"+print((n + 1 - i))"
] | false | 0.04803 | 0.053366 | 0.900011 | [
"s053699673",
"s733357264"
] |
u163320134 | p02743 | python | s900291474 | s692952826 | 34 | 18 | 5,076 | 2,940 | Accepted | Accepted | 47.06 | from decimal import *
a,b,c=list(map(int,input().split()))
a,b,c=Decimal(a),Decimal(b),Decimal(c)
if c**Decimal(0.5)>a**Decimal(0.5)+b**Decimal(0.5):
print('Yes')
else:
print('No') | a,b,c=list(map(int,input().split()))
if 4*a*b<(c-a-b)**2 and a+b<c:
print('Yes')
else:
print('No') | 8 | 5 | 186 | 100 | from decimal import *
a, b, c = list(map(int, input().split()))
a, b, c = Decimal(a), Decimal(b), Decimal(c)
if c ** Decimal(0.5) > a ** Decimal(0.5) + b ** Decimal(0.5):
print("Yes")
else:
print("No")
| a, b, c = list(map(int, input().split()))
if 4 * a * b < (c - a - b) ** 2 and a + b < c:
print("Yes")
else:
print("No")
| false | 37.5 | [
"-from decimal import *",
"-",
"-a, b, c = Decimal(a), Decimal(b), Decimal(c)",
"-if c ** Decimal(0.5) > a ** Decimal(0.5) + b ** Decimal(0.5):",
"+if 4 * a * b < (c - a - b) ** 2 and a + b < c:"
] | false | 0.065149 | 0.035449 | 1.837806 | [
"s900291474",
"s692952826"
] |
u199588618 | p02693 | python | s086003145 | s684809993 | 68 | 55 | 61,592 | 61,820 | Accepted | Accepted | 19.12 | k = int(eval(input()))
a, b = list(map(int, input().split()))
for i in range(a, b+1):
if i%k == 0:
print('OK')
exit()
print('NG') | K=int(eval(input()))
A,B=list(map(int,input().split()))
t=A%K
if t>=1 and B>=A+(K-t):
print("OK")
elif t==0 and A<=B:
print("OK")
else:
print("NG") | 9 | 9 | 147 | 155 | k = int(eval(input()))
a, b = list(map(int, input().split()))
for i in range(a, b + 1):
if i % k == 0:
print("OK")
exit()
print("NG")
| K = int(eval(input()))
A, B = list(map(int, input().split()))
t = A % K
if t >= 1 and B >= A + (K - t):
print("OK")
elif t == 0 and A <= B:
print("OK")
else:
print("NG")
| false | 0 | [
"-k = int(eval(input()))",
"-a, b = list(map(int, input().split()))",
"-for i in range(a, b + 1):",
"- if i % k == 0:",
"- print(\"OK\")",
"- exit()",
"-print(\"NG\")",
"+K = int(eval(input()))",
"+A, B = list(map(int, input().split()))",
"+t = A % K",
"+if t >= 1 and B >= A + (... | false | 0.094811 | 0.041307 | 2.295299 | [
"s086003145",
"s684809993"
] |
u075595666 | p02973 | python | s797057385 | s463400768 | 529 | 418 | 27,108 | 8,092 | Accepted | Accepted | 20.98 | import sys
input = sys.stdin.readline
n = int(eval(input()))
if n == 1:
print((1))
exit()
chk = []
for i in range(n):
a = int(eval(input()))
chk.append((i,a))
from bisect import bisect_left,insort_left
from collections import deque
ans = 1
c = deque([])
for j in chk:
i,a = j
if i == 0:
c.append((a,n-i))
else:
ind = bisect_left(c,(a,n-i))
if ind == 0:
ans += 1
c.appendleft((a,n-i))
else:
c[ind-1] = (a,n-i)
print(ans) | import sys
input = sys.stdin.readline
n = int(eval(input()))
if n == 1:
print((1))
exit()
chk = []
for i in range(n):
a = int(eval(input()))
chk.append(a)
from bisect import bisect_left,insort_left
from collections import deque
ans = 0
c = deque([])
for j in chk:
if i == 0:
c.append(j)
else:
ind = bisect_left(c,j)
if ind == 0:
ans += 1
c.appendleft(j)
else:
c[ind-1] = (j)
print(ans) | 30 | 29 | 496 | 459 | import sys
input = sys.stdin.readline
n = int(eval(input()))
if n == 1:
print((1))
exit()
chk = []
for i in range(n):
a = int(eval(input()))
chk.append((i, a))
from bisect import bisect_left, insort_left
from collections import deque
ans = 1
c = deque([])
for j in chk:
i, a = j
if i == 0:
c.append((a, n - i))
else:
ind = bisect_left(c, (a, n - i))
if ind == 0:
ans += 1
c.appendleft((a, n - i))
else:
c[ind - 1] = (a, n - i)
print(ans)
| import sys
input = sys.stdin.readline
n = int(eval(input()))
if n == 1:
print((1))
exit()
chk = []
for i in range(n):
a = int(eval(input()))
chk.append(a)
from bisect import bisect_left, insort_left
from collections import deque
ans = 0
c = deque([])
for j in chk:
if i == 0:
c.append(j)
else:
ind = bisect_left(c, j)
if ind == 0:
ans += 1
c.appendleft(j)
else:
c[ind - 1] = j
print(ans)
| false | 3.333333 | [
"- chk.append((i, a))",
"+ chk.append(a)",
"-ans = 1",
"+ans = 0",
"- i, a = j",
"- c.append((a, n - i))",
"+ c.append(j)",
"- ind = bisect_left(c, (a, n - i))",
"+ ind = bisect_left(c, j)",
"- c.appendleft((a, n - i))",
"+ c.appendleft(... | false | 0.042848 | 0.037743 | 1.135262 | [
"s797057385",
"s463400768"
] |
u891635666 | p03354 | python | s019908626 | s450583417 | 788 | 704 | 76,352 | 36,072 | Accepted | Accepted | 10.66 | n, m = list(map(int, input().split()))
ps = list(map(int, input().split()))
ls = [list(map(int, input().split())) for _ in range(m)]
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = list(range(n + 1))
self.ranks = [0 for _ in range(n + 1)]
def get_root(self, x):
if self.parents[x] == x:
return x
self.parents[x] = self.get_root(self.parents[x])
return self.parents[x]
def merge(self, x, y):
x = self.get_root(x)
y = self.get_root(y)
if x != y:
if self.ranks[x] < self.ranks[y]:
self.parents[x] = y
else:
self.parents[y] = x
if self.ranks[x] == self.ranks[y]:
self.ranks[x] += 1
uf = UnionFind(n)
for a, b in ls:
uf.merge(a, b)
for i in range(1, n + 1):
uf.get_root(i)
cs = uf.parents
s0 = {c: [] for c in set(cs[1:])}
s1 = {c: [] for c in set(cs[1:])}
for i in range(1, n + 1):
c = cs[i]
s0[c].append(ps[i - 1])
s1[c].append(i)
res = 0
for c in set(cs[1:]):
res += len(set(s0[c]) & set(s1[c]))
print(res) | n, m = list(map(int, input().split()))
ps = list(map(int, input().split()))
ls = [list(map(int, input().split())) for _ in range(m)]
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = list(range(n + 1))
self.ranks = [0 for _ in range(n + 1)]
def get_root(self, x):
if self.parents[x] == x:
return x
self.parents[x] = self.get_root(self.parents[x])
return self.parents[x]
def merge(self, x, y):
x = self.get_root(x)
y = self.get_root(y)
if x != y:
if self.ranks[x] < self.ranks[y]:
self.parents[x] = y
else:
self.parents[y] = x
if self.ranks[x] == self.ranks[y]:
self.ranks[x] += 1
uf = UnionFind(n)
for a, b in ls:
uf.merge(a, b)
res = 0
for i in range(1, n + 1):
p0 = uf.get_root(i)
p1 = uf.get_root(ps[i - 1])
if p0 == p1:
res += 1
print(res) | 46 | 39 | 1,180 | 1,009 | n, m = list(map(int, input().split()))
ps = list(map(int, input().split()))
ls = [list(map(int, input().split())) for _ in range(m)]
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = list(range(n + 1))
self.ranks = [0 for _ in range(n + 1)]
def get_root(self, x):
if self.parents[x] == x:
return x
self.parents[x] = self.get_root(self.parents[x])
return self.parents[x]
def merge(self, x, y):
x = self.get_root(x)
y = self.get_root(y)
if x != y:
if self.ranks[x] < self.ranks[y]:
self.parents[x] = y
else:
self.parents[y] = x
if self.ranks[x] == self.ranks[y]:
self.ranks[x] += 1
uf = UnionFind(n)
for a, b in ls:
uf.merge(a, b)
for i in range(1, n + 1):
uf.get_root(i)
cs = uf.parents
s0 = {c: [] for c in set(cs[1:])}
s1 = {c: [] for c in set(cs[1:])}
for i in range(1, n + 1):
c = cs[i]
s0[c].append(ps[i - 1])
s1[c].append(i)
res = 0
for c in set(cs[1:]):
res += len(set(s0[c]) & set(s1[c]))
print(res)
| n, m = list(map(int, input().split()))
ps = list(map(int, input().split()))
ls = [list(map(int, input().split())) for _ in range(m)]
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = list(range(n + 1))
self.ranks = [0 for _ in range(n + 1)]
def get_root(self, x):
if self.parents[x] == x:
return x
self.parents[x] = self.get_root(self.parents[x])
return self.parents[x]
def merge(self, x, y):
x = self.get_root(x)
y = self.get_root(y)
if x != y:
if self.ranks[x] < self.ranks[y]:
self.parents[x] = y
else:
self.parents[y] = x
if self.ranks[x] == self.ranks[y]:
self.ranks[x] += 1
uf = UnionFind(n)
for a, b in ls:
uf.merge(a, b)
res = 0
for i in range(1, n + 1):
p0 = uf.get_root(i)
p1 = uf.get_root(ps[i - 1])
if p0 == p1:
res += 1
print(res)
| false | 15.217391 | [
"+res = 0",
"- uf.get_root(i)",
"-cs = uf.parents",
"-s0 = {c: [] for c in set(cs[1:])}",
"-s1 = {c: [] for c in set(cs[1:])}",
"-for i in range(1, n + 1):",
"- c = cs[i]",
"- s0[c].append(ps[i - 1])",
"- s1[c].append(i)",
"-res = 0",
"-for c in set(cs[1:]):",
"- res += len(set(... | false | 0.043128 | 0.037938 | 1.136817 | [
"s019908626",
"s450583417"
] |
u589276934 | p00100 | python | s100440095 | s693858034 | 90 | 80 | 7,968 | 7,840 | Accepted | Accepted | 11.11 | # coding: utf-8
# Here your code !
employeeSalesList = []
def resetDataset():
del employeeSalesList[0 : len(employeeSalesList) + 1]
def readDataCount():
return int(eval(input()))
def searchEmployeeSales(employeeId):
for data in employeeSalesList:
if data[0] == employeeId:
return data
newData = [employeeId, 0]
employeeSalesList.append(newData)
return newData
answerList = []
def printEmployeeOfDataset():
found = False
for data in employeeSalesList:
if data[1] >= 1000000:
answerList.append(data[0])
found = True
if not found:
answerList.append("NA")
resetDataset()
dataCount = readDataCount()
while dataCount > 0:
for _ in range(dataCount):
employeeId, price, volume = list(map(int, input().split(" ")))
employeeSales = searchEmployeeSales(employeeId)
employeeSales[1] += price * volume
printEmployeeOfDataset()
resetDataset()
dataCount = readDataCount()
for row in answerList:
print(row) | # coding: utf-8
# Here your code !
employeeSalesList = []
def resetDataset():
del employeeSalesList[0 : len(employeeSalesList) + 1]
def readDataCount():
return int(eval(input()))
def searchEmployeeSales(employeeId):
for data in employeeSalesList:
if data[0] == employeeId:
return data
newData = [employeeId, 0]
employeeSalesList.append(newData)
return newData
def printEmployeeOfDataset():
answerList = [data[0] for data in employeeSalesList if data[1] >= 1000000]
if len(answerList) == 0:
print("NA")
else:
print(("\n".join(map(str, answerList))))
resetDataset()
dataCount = readDataCount()
while dataCount > 0:
for _ in range(dataCount):
employeeId, price, volume = list(map(int, input().split(" ")))
employeeSales = searchEmployeeSales(employeeId)
employeeSales[1] += price * volume
printEmployeeOfDataset()
resetDataset()
dataCount = readDataCount() | 42 | 36 | 1,076 | 1,002 | # coding: utf-8
# Here your code !
employeeSalesList = []
def resetDataset():
del employeeSalesList[0 : len(employeeSalesList) + 1]
def readDataCount():
return int(eval(input()))
def searchEmployeeSales(employeeId):
for data in employeeSalesList:
if data[0] == employeeId:
return data
newData = [employeeId, 0]
employeeSalesList.append(newData)
return newData
answerList = []
def printEmployeeOfDataset():
found = False
for data in employeeSalesList:
if data[1] >= 1000000:
answerList.append(data[0])
found = True
if not found:
answerList.append("NA")
resetDataset()
dataCount = readDataCount()
while dataCount > 0:
for _ in range(dataCount):
employeeId, price, volume = list(map(int, input().split(" ")))
employeeSales = searchEmployeeSales(employeeId)
employeeSales[1] += price * volume
printEmployeeOfDataset()
resetDataset()
dataCount = readDataCount()
for row in answerList:
print(row)
| # coding: utf-8
# Here your code !
employeeSalesList = []
def resetDataset():
del employeeSalesList[0 : len(employeeSalesList) + 1]
def readDataCount():
return int(eval(input()))
def searchEmployeeSales(employeeId):
for data in employeeSalesList:
if data[0] == employeeId:
return data
newData = [employeeId, 0]
employeeSalesList.append(newData)
return newData
def printEmployeeOfDataset():
answerList = [data[0] for data in employeeSalesList if data[1] >= 1000000]
if len(answerList) == 0:
print("NA")
else:
print(("\n".join(map(str, answerList))))
resetDataset()
dataCount = readDataCount()
while dataCount > 0:
for _ in range(dataCount):
employeeId, price, volume = list(map(int, input().split(" ")))
employeeSales = searchEmployeeSales(employeeId)
employeeSales[1] += price * volume
printEmployeeOfDataset()
resetDataset()
dataCount = readDataCount()
| false | 14.285714 | [
"-answerList = []",
"-",
"-",
"- found = False",
"- for data in employeeSalesList:",
"- if data[1] >= 1000000:",
"- answerList.append(data[0])",
"- found = True",
"- if not found:",
"- answerList.append(\"NA\")",
"+ answerList = [data[0] for data i... | false | 0.038789 | 0.068396 | 0.567122 | [
"s100440095",
"s693858034"
] |
u260980560 | p01105 | python | s021974341 | s956724924 | 780 | 700 | 7,956 | 7,736 | Accepted | Accepted | 10.26 | def calc(s):
s = s.replace("-", "-~-")
res = 0
for bit in range(16):
a, b, c, d = list(map(int, format(bit, '04b')))
if eval(s):
res += 1 << bit
return res
base = "abcd10"
L = {}
for e in base:
state = calc(e)
L[state] = 1
ALL = 2**16-1
MAX = 10**18
for i in range(6):
R = dict(L)
for p in R:
if R[p] < 16:
L[p ^ ALL] = min(L.get(p ^ ALL, MAX), R[p] + 1)
if R[p]+3 < 16:
for q in R:
if R[p] + R[q] + 3 <= 16:
L[p & q] = min(L.get(p & q, MAX), R[p] + R[q] + 3)
L[p ^ q] = min(L.get(p ^ q, MAX), R[p] + R[q] + 3)
while 1:
s = eval(input())
if s == '.':
break
print((L[calc(s)])) | a=65280; b=61680; c=52428; d=43690; e=65535
def calc(s):
res = eval(s.replace("-", "~").replace("*", "&").replace("1", "e"))
return e ^ ~res if res < 0 else res
base = [a, b, c, d, e, 0]
L = {el: 1 for el in base}
for i in range(6):
R = dict(L)
for p in R:
if R[p] < 16:
L[p ^ e] = min(L.get(p ^ e, 16), R[p] + 1)
if R[p]+3 < 16:
for q in R:
if R[p] + R[q] + 3 <= 16:
L[p & q] = min(L.get(p & q, 16), R[p] + R[q] + 3)
L[p ^ q] = min(L.get(p ^ q, 16), R[p] + R[q] + 3)
while 1:
s = eval(input())
if s == '.':
break
print((L[calc(s)])) | 30 | 21 | 767 | 677 | def calc(s):
s = s.replace("-", "-~-")
res = 0
for bit in range(16):
a, b, c, d = list(map(int, format(bit, "04b")))
if eval(s):
res += 1 << bit
return res
base = "abcd10"
L = {}
for e in base:
state = calc(e)
L[state] = 1
ALL = 2**16 - 1
MAX = 10**18
for i in range(6):
R = dict(L)
for p in R:
if R[p] < 16:
L[p ^ ALL] = min(L.get(p ^ ALL, MAX), R[p] + 1)
if R[p] + 3 < 16:
for q in R:
if R[p] + R[q] + 3 <= 16:
L[p & q] = min(L.get(p & q, MAX), R[p] + R[q] + 3)
L[p ^ q] = min(L.get(p ^ q, MAX), R[p] + R[q] + 3)
while 1:
s = eval(input())
if s == ".":
break
print((L[calc(s)]))
| a = 65280
b = 61680
c = 52428
d = 43690
e = 65535
def calc(s):
res = eval(s.replace("-", "~").replace("*", "&").replace("1", "e"))
return e ^ ~res if res < 0 else res
base = [a, b, c, d, e, 0]
L = {el: 1 for el in base}
for i in range(6):
R = dict(L)
for p in R:
if R[p] < 16:
L[p ^ e] = min(L.get(p ^ e, 16), R[p] + 1)
if R[p] + 3 < 16:
for q in R:
if R[p] + R[q] + 3 <= 16:
L[p & q] = min(L.get(p & q, 16), R[p] + R[q] + 3)
L[p ^ q] = min(L.get(p ^ q, 16), R[p] + R[q] + 3)
while 1:
s = eval(input())
if s == ".":
break
print((L[calc(s)]))
| false | 30 | [
"-def calc(s):",
"- s = s.replace(\"-\", \"-~-\")",
"- res = 0",
"- for bit in range(16):",
"- a, b, c, d = list(map(int, format(bit, \"04b\")))",
"- if eval(s):",
"- res += 1 << bit",
"- return res",
"+a = 65280",
"+b = 61680",
"+c = 52428",
"+d = 43690",
... | false | 1.493906 | 1.397945 | 1.068644 | [
"s021974341",
"s956724924"
] |
u790710233 | p04034 | python | s669293519 | s835619834 | 460 | 390 | 15,204 | 5,364 | Accepted | Accepted | 15.22 | n, m = list(map(int, input().split()))
A = [[1, 1]] + [[0, 1] for _ in range(n-1)]
for _ in range(m):
x, y = [int(x) - 1 for x in input().split()]
A[x][1] -= 1
A[y][1] += 1
if A[x][0]:
A[y][0] = 1
if A[x][1] == 0:
A[x][0] = 0
print((sum(a[0] for a in A))) | n, m = list(map(int, input().split()))
num = [1]*n
red = [1] + [0]*(n-1)
for _ in range(m):
x, y = [int(x)-1 for x in input().split()]
num[x] -= 1
num[y] += 1
if red[x]:
red[y] = 1
if num[x] == 0:
red[x] = 0
print((sum(red))) | 16 | 16 | 308 | 277 | n, m = list(map(int, input().split()))
A = [[1, 1]] + [[0, 1] for _ in range(n - 1)]
for _ in range(m):
x, y = [int(x) - 1 for x in input().split()]
A[x][1] -= 1
A[y][1] += 1
if A[x][0]:
A[y][0] = 1
if A[x][1] == 0:
A[x][0] = 0
print((sum(a[0] for a in A)))
| n, m = list(map(int, input().split()))
num = [1] * n
red = [1] + [0] * (n - 1)
for _ in range(m):
x, y = [int(x) - 1 for x in input().split()]
num[x] -= 1
num[y] += 1
if red[x]:
red[y] = 1
if num[x] == 0:
red[x] = 0
print((sum(red)))
| false | 0 | [
"-A = [[1, 1]] + [[0, 1] for _ in range(n - 1)]",
"+num = [1] * n",
"+red = [1] + [0] * (n - 1)",
"- A[x][1] -= 1",
"- A[y][1] += 1",
"- if A[x][0]:",
"- A[y][0] = 1",
"- if A[x][1] == 0:",
"- A[x][0] = 0",
"-print((sum(a[0] for a in A)))",
"+ num[x] -= 1",
"+ n... | false | 0.042846 | 0.039861 | 1.074883 | [
"s669293519",
"s835619834"
] |
u368796742 | p02549 | python | s746796275 | s017734103 | 157 | 141 | 80,632 | 82,716 | Accepted | Accepted | 10.19 | mod = 998244353
n,k = list(map(int,input().split()))
K = [list(map(int,input().split())) for i in range(k)]
dp = [0]*(n+5)
dp[1] = 1
dp2 = [0]*(n+5)
for i in range(1,n+1):
dp[i] = (dp[i]+dp2[i]+dp2[i-1])%mod
dp2[i] = (dp2[i]+dp2[i-1])%mod
for l,r in K:
dp2[min(i+l,n+2)] += dp[i]
dp2[min(i+l,n+2)] %= mod
dp2[min(i+r+1,n+2)] -= dp[i]
dp2[min(i+r+1,n+2)] %= mod
print((dp[n]%mod))
| mod = 998244353
n,k = list(map(int,input().split()))
K = [list(map(int,input().split())) for i in range(k)]
dp = [0]*(n+1)
dp[0] = 1
dp2 = [0]*(n+1)
for i in range(n):
dp2[i] = (dp2[i]+dp2[i-1])%mod
dp[i] = (dp[i]+dp2[i])%mod
for l,r in K:
dp2[min(i+l,n)] = (dp2[min(i+l,n)]+dp[i])%mod
dp2[min(i+r+1,n)] = (dp2[min(i+r+1,n)]-dp[i])%mod
print((dp[n-1]%mod))
| 16 | 14 | 432 | 391 | mod = 998244353
n, k = list(map(int, input().split()))
K = [list(map(int, input().split())) for i in range(k)]
dp = [0] * (n + 5)
dp[1] = 1
dp2 = [0] * (n + 5)
for i in range(1, n + 1):
dp[i] = (dp[i] + dp2[i] + dp2[i - 1]) % mod
dp2[i] = (dp2[i] + dp2[i - 1]) % mod
for l, r in K:
dp2[min(i + l, n + 2)] += dp[i]
dp2[min(i + l, n + 2)] %= mod
dp2[min(i + r + 1, n + 2)] -= dp[i]
dp2[min(i + r + 1, n + 2)] %= mod
print((dp[n] % mod))
| mod = 998244353
n, k = list(map(int, input().split()))
K = [list(map(int, input().split())) for i in range(k)]
dp = [0] * (n + 1)
dp[0] = 1
dp2 = [0] * (n + 1)
for i in range(n):
dp2[i] = (dp2[i] + dp2[i - 1]) % mod
dp[i] = (dp[i] + dp2[i]) % mod
for l, r in K:
dp2[min(i + l, n)] = (dp2[min(i + l, n)] + dp[i]) % mod
dp2[min(i + r + 1, n)] = (dp2[min(i + r + 1, n)] - dp[i]) % mod
print((dp[n - 1] % mod))
| false | 12.5 | [
"-dp = [0] * (n + 5)",
"-dp[1] = 1",
"-dp2 = [0] * (n + 5)",
"-for i in range(1, n + 1):",
"- dp[i] = (dp[i] + dp2[i] + dp2[i - 1]) % mod",
"+dp = [0] * (n + 1)",
"+dp[0] = 1",
"+dp2 = [0] * (n + 1)",
"+for i in range(n):",
"+ dp[i] = (dp[i] + dp2[i]) % mod",
"- dp2[min(i + l, n + 2... | false | 0.036942 | 0.044463 | 0.830852 | [
"s746796275",
"s017734103"
] |
u831725332 | p00003 | python | s752121389 | s810221166 | 50 | 40 | 5,600 | 5,596 | Accepted | Accepted | 20 | N = int(eval(input()))
for i in range(N):
sides = sorted(list(map(int, input().split())))
if sides[0]**2 + sides[1]**2 == sides[2]**2:
print('YES')
else:
print('NO')
| N = int(eval(input()))
for i in range(N):
adjacent_side_1, adjacent_side_2, hypotenuse = sorted(list(map(int, input().split())))
if adjacent_side_1**2 + adjacent_side_2**2 == hypotenuse**2:
print('YES')
else:
print('NO')
| 9 | 9 | 198 | 253 | N = int(eval(input()))
for i in range(N):
sides = sorted(list(map(int, input().split())))
if sides[0] ** 2 + sides[1] ** 2 == sides[2] ** 2:
print("YES")
else:
print("NO")
| N = int(eval(input()))
for i in range(N):
adjacent_side_1, adjacent_side_2, hypotenuse = sorted(
list(map(int, input().split()))
)
if adjacent_side_1**2 + adjacent_side_2**2 == hypotenuse**2:
print("YES")
else:
print("NO")
| false | 0 | [
"- sides = sorted(list(map(int, input().split())))",
"- if sides[0] ** 2 + sides[1] ** 2 == sides[2] ** 2:",
"+ adjacent_side_1, adjacent_side_2, hypotenuse = sorted(",
"+ list(map(int, input().split()))",
"+ )",
"+ if adjacent_side_1**2 + adjacent_side_2**2 == hypotenuse**2:"
] | false | 0.044551 | 0.039292 | 1.133836 | [
"s752121389",
"s810221166"
] |
u606878291 | p02900 | python | s234616096 | s930198760 | 805 | 166 | 119,776 | 9,608 | Accepted | Accepted | 79.38 | from functools import lru_cache
@lru_cache(maxsize=None)
def get_dividers(n):
"""
正の整数 n の約数を取得する
"""
dividers = {i for i in range(1, int(n ** 0.5) + 1) if n % i == 0}
return dividers | {n // d for d in dividers}
A, B = list(map(int, input().split(' ')))
a_dividers = get_dividers(A)
b_dividers = get_dividers(B)
common_dividers = a_dividers & b_dividers
ans = []
for cd in sorted(common_dividers):
dividers = get_dividers(cd) - {1}
for d in ans:
if d & dividers:
break
else:
ans.append(dividers)
print((len(ans)))
| from functools import lru_cache
@lru_cache(maxsize=None)
def prime_factorization(n):
"""
nを素因数分解して素因数のリストを返却する
"""
primes = []
while n % 2 == 0:
primes.append(2)
n //= 2
i = 3
while i ** 2 <= n:
while n % i == 0:
primes.append(i)
n //= i
i += 2
if n != 1:
primes.append(n)
return primes
A, B = list(map(int, input().split(' ')))
a_primes = set(prime_factorization(A))
b_primes = set(prime_factorization(B))
print((len(a_primes & b_primes) + 1))
| 29 | 29 | 603 | 571 | from functools import lru_cache
@lru_cache(maxsize=None)
def get_dividers(n):
"""
正の整数 n の約数を取得する
"""
dividers = {i for i in range(1, int(n**0.5) + 1) if n % i == 0}
return dividers | {n // d for d in dividers}
A, B = list(map(int, input().split(" ")))
a_dividers = get_dividers(A)
b_dividers = get_dividers(B)
common_dividers = a_dividers & b_dividers
ans = []
for cd in sorted(common_dividers):
dividers = get_dividers(cd) - {1}
for d in ans:
if d & dividers:
break
else:
ans.append(dividers)
print((len(ans)))
| from functools import lru_cache
@lru_cache(maxsize=None)
def prime_factorization(n):
"""
nを素因数分解して素因数のリストを返却する
"""
primes = []
while n % 2 == 0:
primes.append(2)
n //= 2
i = 3
while i**2 <= n:
while n % i == 0:
primes.append(i)
n //= i
i += 2
if n != 1:
primes.append(n)
return primes
A, B = list(map(int, input().split(" ")))
a_primes = set(prime_factorization(A))
b_primes = set(prime_factorization(B))
print((len(a_primes & b_primes) + 1))
| false | 0 | [
"-def get_dividers(n):",
"+def prime_factorization(n):",
"- 正の整数 n の約数を取得する",
"+ nを素因数分解して素因数のリストを返却する",
"- dividers = {i for i in range(1, int(n**0.5) + 1) if n % i == 0}",
"- return dividers | {n // d for d in dividers}",
"+ primes = []",
"+ while n % 2 == 0:",
"+ primes.a... | false | 0.080257 | 0.037723 | 2.127536 | [
"s234616096",
"s930198760"
] |
u753803401 | p03303 | python | s670790415 | s845775678 | 194 | 177 | 38,384 | 38,256 | Accepted | Accepted | 8.76 | def slove():
import sys
input = sys.stdin.readline
s = list(str(input().rstrip('\n')))
w = int(input().rstrip('\n'))
print(("".join(s[::w])))
if __name__ == '__main__':
slove()
| import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
s = str(readline().rstrip().decode('utf-8'))
w = int(readline())
ans = []
for i in range(0, len(s), w):
ans.append(s[i])
print(("".join(ans)))
if __name__ == '__main__':
solve()
| 10 | 16 | 210 | 314 | def slove():
import sys
input = sys.stdin.readline
s = list(str(input().rstrip("\n")))
w = int(input().rstrip("\n"))
print(("".join(s[::w])))
if __name__ == "__main__":
slove()
| import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10**9 + 7
s = str(readline().rstrip().decode("utf-8"))
w = int(readline())
ans = []
for i in range(0, len(s), w):
ans.append(s[i])
print(("".join(ans)))
if __name__ == "__main__":
solve()
| false | 37.5 | [
"-def slove():",
"- import sys",
"+import sys",
"- input = sys.stdin.readline",
"- s = list(str(input().rstrip(\"\\n\")))",
"- w = int(input().rstrip(\"\\n\"))",
"- print((\"\".join(s[::w])))",
"+",
"+def solve():",
"+ readline = sys.stdin.buffer.readline",
"+ mod = 10**9 + ... | false | 0.035751 | 0.034587 | 1.033641 | [
"s670790415",
"s845775678"
] |
u489959379 | p03408 | python | s894337300 | s024574960 | 24 | 21 | 3,564 | 3,316 | Accepted | Accepted | 12.5 | from collections import Counter
n = int(eval(input()))
s = list(eval(input()) for _ in range(n))
m = int(eval(input()))
t = list(eval(input()) for _ in range(m))
res = Counter(s)
for i in range(m):
if t[i] in res:
res[t[i]] -= 1
ans = 0
for v in list(res.values()):
ans = max(ans, v)
print(ans) | import sys
from collections import Counter
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n = int(eval(input()))
S = [eval(input()) for _ in range(n)]
m = int(eval(input()))
T = [eval(input()) for _ in range(m)]
D_S = Counter(S)
D_T = Counter(T)
res = 0
for k, v in list(D_S.items()):
cnt = v - D_T.get(k, 0)
res = max(res, cnt)
print(res)
if __name__ == '__main__':
resolve()
| 17 | 25 | 300 | 471 | from collections import Counter
n = int(eval(input()))
s = list(eval(input()) for _ in range(n))
m = int(eval(input()))
t = list(eval(input()) for _ in range(m))
res = Counter(s)
for i in range(m):
if t[i] in res:
res[t[i]] -= 1
ans = 0
for v in list(res.values()):
ans = max(ans, v)
print(ans)
| import sys
from collections import Counter
sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 10**9 + 7
def resolve():
n = int(eval(input()))
S = [eval(input()) for _ in range(n)]
m = int(eval(input()))
T = [eval(input()) for _ in range(m)]
D_S = Counter(S)
D_T = Counter(T)
res = 0
for k, v in list(D_S.items()):
cnt = v - D_T.get(k, 0)
res = max(res, cnt)
print(res)
if __name__ == "__main__":
resolve()
| false | 32 | [
"+import sys",
"-n = int(eval(input()))",
"-s = list(eval(input()) for _ in range(n))",
"-m = int(eval(input()))",
"-t = list(eval(input()) for _ in range(m))",
"-res = Counter(s)",
"-for i in range(m):",
"- if t[i] in res:",
"- res[t[i]] -= 1",
"-ans = 0",
"-for v in list(res.values()... | false | 0.042537 | 0.084981 | 0.500544 | [
"s894337300",
"s024574960"
] |
u759412327 | p03339 | python | s932573434 | s320767350 | 147 | 111 | 9,632 | 9,632 | Accepted | Accepted | 24.49 | N = int(eval(input()))
S = eval(input())
l = 0
r = S[1:N].count('E')
ans = l+r
for n in range(1,N):
if S[n-1]=="W":
l+=1
if S[n]=="E":
r-=1
ans=min(ans,l+r)
print(ans) | N = int(eval(input()))
S = eval(input())
a = S.count("E")
c = a
for s in S:
if s=="E":
c-=1
else:
c+=1
a=min(a,c)
print(a) | 14 | 13 | 184 | 139 | N = int(eval(input()))
S = eval(input())
l = 0
r = S[1:N].count("E")
ans = l + r
for n in range(1, N):
if S[n - 1] == "W":
l += 1
if S[n] == "E":
r -= 1
ans = min(ans, l + r)
print(ans)
| N = int(eval(input()))
S = eval(input())
a = S.count("E")
c = a
for s in S:
if s == "E":
c -= 1
else:
c += 1
a = min(a, c)
print(a)
| false | 7.142857 | [
"-l = 0",
"-r = S[1:N].count(\"E\")",
"-ans = l + r",
"-for n in range(1, N):",
"- if S[n - 1] == \"W\":",
"- l += 1",
"- if S[n] == \"E\":",
"- r -= 1",
"- ans = min(ans, l + r)",
"-print(ans)",
"+a = S.count(\"E\")",
"+c = a",
"+for s in S:",
"+ if s == \"E\":",... | false | 0.04841 | 0.046957 | 1.030946 | [
"s932573434",
"s320767350"
] |
u728611988 | p03845 | python | s454010432 | s795111479 | 23 | 18 | 3,444 | 3,060 | Accepted | Accepted | 21.74 | import copy
n = int(eval(input()))
T = list(map(int, input().split()))
m = int(eval(input()))
for i in range(m):
t = copy.copy(T)
p, x = list(map(int, input().split()))
t[p-1] = x
print((sum(t))) | n = int(eval(input()))
T = list(map(int, input().split()))
m = int(eval(input()))
for i in range(m):
t = T.copy()
p, x = list(map(int, input().split()))
t[p-1] = x
print((sum(t))) | 9 | 8 | 199 | 182 | import copy
n = int(eval(input()))
T = list(map(int, input().split()))
m = int(eval(input()))
for i in range(m):
t = copy.copy(T)
p, x = list(map(int, input().split()))
t[p - 1] = x
print((sum(t)))
| n = int(eval(input()))
T = list(map(int, input().split()))
m = int(eval(input()))
for i in range(m):
t = T.copy()
p, x = list(map(int, input().split()))
t[p - 1] = x
print((sum(t)))
| false | 11.111111 | [
"-import copy",
"-",
"- t = copy.copy(T)",
"+ t = T.copy()"
] | false | 0.038933 | 0.042284 | 0.920756 | [
"s454010432",
"s795111479"
] |
u644907318 | p02707 | python | s495984740 | s692342376 | 295 | 192 | 60,332 | 121,752 | Accepted | Accepted | 34.92 | N = int(eval(input()))
A = list(map(int,input().split()))
A.insert(0,0)
A.insert(0,0)
G = {i:[] for i in range(1,N+1)}
for i in range(2,N+1):
G[A[i]].append(i)
for i in range(1,N+1):
print((len(G[i]))) | N = int(eval(input()))
A = list(map(int,input().split()))
A.insert(0,0)
A.insert(0,0)
C = {i:0 for i in range(1,N+1)}
for i in range(2,N+1):
a = A[i]
C[a] += 1
for i in range(1,N+1):
print((C[i])) | 9 | 10 | 209 | 209 | N = int(eval(input()))
A = list(map(int, input().split()))
A.insert(0, 0)
A.insert(0, 0)
G = {i: [] for i in range(1, N + 1)}
for i in range(2, N + 1):
G[A[i]].append(i)
for i in range(1, N + 1):
print((len(G[i])))
| N = int(eval(input()))
A = list(map(int, input().split()))
A.insert(0, 0)
A.insert(0, 0)
C = {i: 0 for i in range(1, N + 1)}
for i in range(2, N + 1):
a = A[i]
C[a] += 1
for i in range(1, N + 1):
print((C[i]))
| false | 10 | [
"-G = {i: [] for i in range(1, N + 1)}",
"+C = {i: 0 for i in range(1, N + 1)}",
"- G[A[i]].append(i)",
"+ a = A[i]",
"+ C[a] += 1",
"- print((len(G[i])))",
"+ print((C[i]))"
] | false | 0.115086 | 0.040365 | 2.851116 | [
"s495984740",
"s692342376"
] |
u802963389 | p03031 | python | s992336251 | s875480000 | 45 | 37 | 3,064 | 9,136 | Accepted | Accepted | 17.78 | N, M = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
# print(N, M)
# print(ks)
# print(p)
ans = 0
import itertools
for i in itertools.product([0,1], repeat=N):
righted = 0
for iter, j in enumerate(ks):
# print(iter, j )
cnt = 0
for k in range(1,len(j)):
cnt += i[j[k]-1]
if cnt % 2 == p[iter]:
righted += 1
if len(ks) == righted:
ans += 1
print(ans)
| n, m = list(map(int, input().split()))
S = [list(map(int, input().split()))[1:] for _ in range(m)]
P = list(map(int, input().split()))
ans = 0
for b in range(2 ** n):
onswitch = [i + 1 for i in range(n) if (b >> i) & 1]
if all(sum(o in s for o in onswitch) % 2 == p for s, p in zip(S, P)):
ans += 1
print(ans) | 23 | 11 | 489 | 329 | N, M = list(map(int, input().split()))
ks = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))
# print(N, M)
# print(ks)
# print(p)
ans = 0
import itertools
for i in itertools.product([0, 1], repeat=N):
righted = 0
for iter, j in enumerate(ks):
# print(iter, j )
cnt = 0
for k in range(1, len(j)):
cnt += i[j[k] - 1]
if cnt % 2 == p[iter]:
righted += 1
if len(ks) == righted:
ans += 1
print(ans)
| n, m = list(map(int, input().split()))
S = [list(map(int, input().split()))[1:] for _ in range(m)]
P = list(map(int, input().split()))
ans = 0
for b in range(2**n):
onswitch = [i + 1 for i in range(n) if (b >> i) & 1]
if all(sum(o in s for o in onswitch) % 2 == p for s, p in zip(S, P)):
ans += 1
print(ans)
| false | 52.173913 | [
"-N, M = list(map(int, input().split()))",
"-ks = [list(map(int, input().split())) for _ in range(M)]",
"-p = list(map(int, input().split()))",
"-# print(N, M)",
"-# print(ks)",
"-# print(p)",
"+n, m = list(map(int, input().split()))",
"+S = [list(map(int, input().split()))[1:] for _ in range(m)]",
... | false | 0.04858 | 0.046395 | 1.047103 | [
"s992336251",
"s875480000"
] |
u506858457 | p02761 | python | s656257705 | s515299772 | 20 | 18 | 3,064 | 3,064 | Accepted | Accepted | 10 | def check(x):
if len(str(x))!=N:
return False
for i in range(M):
if str(x)[S[i]]!=str(C[i]):
return False
return True
N,M=list(map(int,input().split()))
S=[]
C=[]
for i in range(M):
s,c=list(map(int,input().split()))
s-=1
S.append(s)
C.append(c)
#print(S,C)
for i in range(1000):
if check(i):
print(i)
exit()
print((-1)) | N,M=list(map(int,input().split()))
#SC=[s,c for input().split() in range(M)]
SC=[list(input().split()) for i in range(M)]
'''
SC=[]
for i in range(M):
SC.append((input().split()))
'''
def check(x):
x=str(x)
if len(x)!=N:
return False
for s,c in SC:
if x[int(s)-1]!=c:
return False
return True
for i in range(1000):
if check(i):
print(i)
exit()
print((-1)) | 22 | 21 | 373 | 401 | def check(x):
if len(str(x)) != N:
return False
for i in range(M):
if str(x)[S[i]] != str(C[i]):
return False
return True
N, M = list(map(int, input().split()))
S = []
C = []
for i in range(M):
s, c = list(map(int, input().split()))
s -= 1
S.append(s)
C.append(c)
# print(S,C)
for i in range(1000):
if check(i):
print(i)
exit()
print((-1))
| N, M = list(map(int, input().split()))
# SC=[s,c for input().split() in range(M)]
SC = [list(input().split()) for i in range(M)]
"""
SC=[]
for i in range(M):
SC.append((input().split()))
"""
def check(x):
x = str(x)
if len(x) != N:
return False
for s, c in SC:
if x[int(s) - 1] != c:
return False
return True
for i in range(1000):
if check(i):
print(i)
exit()
print((-1))
| false | 4.545455 | [
"+N, M = list(map(int, input().split()))",
"+# SC=[s,c for input().split() in range(M)]",
"+SC = [list(input().split()) for i in range(M)]",
"+\"\"\"",
"+SC=[]",
"+for i in range(M):",
"+ SC.append((input().split()))",
"+\"\"\"",
"+",
"+",
"- if len(str(x)) != N:",
"+ x = str(x)",
"+ ... | false | 0.036114 | 0.036074 | 1.001113 | [
"s656257705",
"s515299772"
] |
u087218797 | p02915 | python | s980641075 | s804293850 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | i = int(eval(input()))
print((str(i*i*i))) | tmp = int(eval(input()))
ans = tmp * tmp * tmp
print(ans)
| 2 | 7 | 35 | 62 | i = int(eval(input()))
print((str(i * i * i)))
| tmp = int(eval(input()))
ans = tmp * tmp * tmp
print(ans)
| false | 71.428571 | [
"-i = int(eval(input()))",
"-print((str(i * i * i)))",
"+tmp = int(eval(input()))",
"+ans = tmp * tmp * tmp",
"+print(ans)"
] | false | 0.043051 | 0.041339 | 1.041417 | [
"s980641075",
"s804293850"
] |
u263830634 | p02787 | python | s597718122 | s610491341 | 528 | 318 | 119,388 | 42,220 | Accepted | Accepted | 39.77 | INF = 10 ** 18
H, N = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
dp = [[INF] * (H + 1) for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
for j in range(H + 1):
if j < AB[i][0]:
dp[i + 1][j] = min(dp[i][j], dp[i + 1][0] + AB[i][1])
else:
dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - AB[i][0]] + AB[i][1])
print((dp[N][H]))
# for d in dp:
# print (d) | import sys
input = sys.stdin.readline
INF = 10 ** 18
H, N = list(map(int, input().split()))
dp = [INF] * (H + 1)
dp[0] = 0
for i in range(N):
A, B = list(map(int, input().split()))
for j in range(H + 1):
if j < A:
dp[j] = min(dp[j], dp[0] + B)
else:
dp[j] = min(dp[j], dp[j - A] + B)
print((dp[H]))
# for d in dp:
# print (d) | 19 | 22 | 465 | 395 | INF = 10**18
H, N = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
dp = [[INF] * (H + 1) for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
for j in range(H + 1):
if j < AB[i][0]:
dp[i + 1][j] = min(dp[i][j], dp[i + 1][0] + AB[i][1])
else:
dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - AB[i][0]] + AB[i][1])
print((dp[N][H]))
# for d in dp:
# print (d)
| import sys
input = sys.stdin.readline
INF = 10**18
H, N = list(map(int, input().split()))
dp = [INF] * (H + 1)
dp[0] = 0
for i in range(N):
A, B = list(map(int, input().split()))
for j in range(H + 1):
if j < A:
dp[j] = min(dp[j], dp[0] + B)
else:
dp[j] = min(dp[j], dp[j - A] + B)
print((dp[H]))
# for d in dp:
# print (d)
| false | 13.636364 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"-AB = [list(map(int, input().split())) for _ in range(N)]",
"-dp = [[INF] * (H + 1) for _ in range(N + 1)]",
"-dp[0][0] = 0",
"+dp = [INF] * (H + 1)",
"+dp[0] = 0",
"+ A, B = list(map(int, input().split()))",
"- if j < AB[i][0]:",
"- ... | false | 0.38338 | 0.189203 | 2.026286 | [
"s597718122",
"s610491341"
] |
u641406334 | p02832 | python | s787281580 | s216927133 | 871 | 93 | 25,244 | 24,744 | Accepted | Accepted | 89.32 | from collections import deque
n = int(eval(input()))
r = deque(list(map(int, input().split())))
i=0
while True:
if max(len(r),i)==i:
break
if r[i]!=i+1:
r.popleft()
else:
i+=1
print(('-1' if len(r)==0 else n-len(r))) | n = int(eval(input()))
R = list(map(int, input().split()))
c, i = 0, 1
for r in R:
if r==i: i+=1
else: c+=1
print((c if c<n else '-1'))
| 12 | 7 | 249 | 138 | from collections import deque
n = int(eval(input()))
r = deque(list(map(int, input().split())))
i = 0
while True:
if max(len(r), i) == i:
break
if r[i] != i + 1:
r.popleft()
else:
i += 1
print(("-1" if len(r) == 0 else n - len(r)))
| n = int(eval(input()))
R = list(map(int, input().split()))
c, i = 0, 1
for r in R:
if r == i:
i += 1
else:
c += 1
print((c if c < n else "-1"))
| false | 41.666667 | [
"-from collections import deque",
"-",
"-r = deque(list(map(int, input().split())))",
"-i = 0",
"-while True:",
"- if max(len(r), i) == i:",
"- break",
"- if r[i] != i + 1:",
"- r.popleft()",
"+R = list(map(int, input().split()))",
"+c, i = 0, 1",
"+for r in R:",
"+ if... | false | 0.118833 | 0.044039 | 2.69837 | [
"s787281580",
"s216927133"
] |
u883048396 | p03201 | python | s454605380 | s358336790 | 417 | 373 | 42,296 | 44,560 | Accepted | Accepted | 10.55 | N = int(eval(input()))
dA1 ={}
dA0 ={}
def lenbin(a):
return len(bin(a)) - 2
def addData(oDict,a):
if a in oDict:
oDict[a]+=1
else:
oDict[a]=1
for a in input().split():
a = int(a)
if a % 2 :
addData(dA1,a)
else:
addData(dA0,a)
def searchPair(oD):
iC = 0
for a in sorted(list(oD.keys()),reverse=True):
t = ( 1 << lenbin(a)) - a
if t == a:
iAT = oD[a] // 2
iC += iAT
oD[a] -= iAT *2
elif t in oD:
iAT = min(oD[a],oD[t])
iC += iAT
oD[a] -= iAT
oD[t] -= iAT
return iC
#iC = 0
#iC += searchPair(dA1)
#iC += searchPair(dA0)
print((searchPair(dA1)+searchPair(dA0)))
|
#偶奇合わせてたのはグルグル回してたからだが
#一意に決めるんなら偶奇合わせる必要ないのでは
def 解():
N = int(eval(input()))
dA ={}
def lenbin(a):
return len(bin(a)) - 2
def addData(oDict,a):
if a in oDict:
oDict[a]+=1
else:
oDict[a]=1
for a in map(int,input().split()):
addData(dA,a)
def searchPair(oD):
iC = 0
for a in sorted(list(oD.keys()),reverse=True):
if oD[a]:
t = ( 1 << lenbin(a)) - a
if t == a:
iAT = oD[a] // 2
iC += iAT
oD[a] -= iAT *2
elif t in oD:
iAT = min(oD[a],oD[t])
iC += iAT
oD[a] -= iAT
oD[t] -= iAT
return iC
print((searchPair(dA)))
解()
| 35 | 32 | 756 | 840 | N = int(eval(input()))
dA1 = {}
dA0 = {}
def lenbin(a):
return len(bin(a)) - 2
def addData(oDict, a):
if a in oDict:
oDict[a] += 1
else:
oDict[a] = 1
for a in input().split():
a = int(a)
if a % 2:
addData(dA1, a)
else:
addData(dA0, a)
def searchPair(oD):
iC = 0
for a in sorted(list(oD.keys()), reverse=True):
t = (1 << lenbin(a)) - a
if t == a:
iAT = oD[a] // 2
iC += iAT
oD[a] -= iAT * 2
elif t in oD:
iAT = min(oD[a], oD[t])
iC += iAT
oD[a] -= iAT
oD[t] -= iAT
return iC
# iC = 0
# iC += searchPair(dA1)
# iC += searchPair(dA0)
print((searchPair(dA1) + searchPair(dA0)))
| # 偶奇合わせてたのはグルグル回してたからだが
# 一意に決めるんなら偶奇合わせる必要ないのでは
def 解():
N = int(eval(input()))
dA = {}
def lenbin(a):
return len(bin(a)) - 2
def addData(oDict, a):
if a in oDict:
oDict[a] += 1
else:
oDict[a] = 1
for a in map(int, input().split()):
addData(dA, a)
def searchPair(oD):
iC = 0
for a in sorted(list(oD.keys()), reverse=True):
if oD[a]:
t = (1 << lenbin(a)) - a
if t == a:
iAT = oD[a] // 2
iC += iAT
oD[a] -= iAT * 2
elif t in oD:
iAT = min(oD[a], oD[t])
iC += iAT
oD[a] -= iAT
oD[t] -= iAT
return iC
print((searchPair(dA)))
解()
| false | 8.571429 | [
"-N = int(eval(input()))",
"-dA1 = {}",
"-dA0 = {}",
"+# 偶奇合わせてたのはグルグル回してたからだが",
"+# 一意に決めるんなら偶奇合わせる必要ないのでは",
"+def 解():",
"+ N = int(eval(input()))",
"+ dA = {}",
"+",
"+ def lenbin(a):",
"+ return len(bin(a)) - 2",
"+",
"+ def addData(oDict, a):",
"+ if a in oDi... | false | 0.118827 | 0.088897 | 1.336675 | [
"s454605380",
"s358336790"
] |
u024782094 | p03161 | python | s118275333 | s422408835 | 452 | 396 | 55,264 | 57,696 | Accepted | Accepted | 12.39 | from collections import Counter
from collections import deque
import math
import bisect
import sys
def input(): return sys.stdin.readline().strip()
def mp(): return list(map(int,input().split()))
def lmp(): return list(map(int,input().split()))
n,k=mp()
h=lmp()
h.insert(0,0)
dp=[float("inf")]*(n+1)
dp[1]=0
for i in range(1,n+1):
for j in range(1,k+1):
if i+j<=n:
dp[i+j]=min(dp[i+j],abs(h[i+j]-h[i])+dp[i])
print((dp[n]))
| n,k = list(map(int,input().split()))
height = list(map(int,input().split()))
cost_list = []
for m in range(1,n+1):
if m <= k:
cost_list.append(abs(height[m-1]-height[0]))
else:
Min = cost_list[-1] + abs(height[m-2]-height[m-1])
if k > 1:
for x in range(2,k+1):
money2 = cost_list[-x] + abs(height[m-x-1]-height[m-1])
if money2 < Min:
Min = money2
cost_list.append(Min)
print((cost_list[-1])) | 20 | 15 | 461 | 450 | from collections import Counter
from collections import deque
import math
import bisect
import sys
def input():
return sys.stdin.readline().strip()
def mp():
return list(map(int, input().split()))
def lmp():
return list(map(int, input().split()))
n, k = mp()
h = lmp()
h.insert(0, 0)
dp = [float("inf")] * (n + 1)
dp[1] = 0
for i in range(1, n + 1):
for j in range(1, k + 1):
if i + j <= n:
dp[i + j] = min(dp[i + j], abs(h[i + j] - h[i]) + dp[i])
print((dp[n]))
| n, k = list(map(int, input().split()))
height = list(map(int, input().split()))
cost_list = []
for m in range(1, n + 1):
if m <= k:
cost_list.append(abs(height[m - 1] - height[0]))
else:
Min = cost_list[-1] + abs(height[m - 2] - height[m - 1])
if k > 1:
for x in range(2, k + 1):
money2 = cost_list[-x] + abs(height[m - x - 1] - height[m - 1])
if money2 < Min:
Min = money2
cost_list.append(Min)
print((cost_list[-1]))
| false | 25 | [
"-from collections import Counter",
"-from collections import deque",
"-import math",
"-import bisect",
"-import sys",
"-",
"-",
"-def input():",
"- return sys.stdin.readline().strip()",
"-",
"-",
"-def mp():",
"- return list(map(int, input().split()))",
"-",
"-",
"-def lmp():",
... | false | 0.046703 | 0.047553 | 0.982142 | [
"s118275333",
"s422408835"
] |
u599547273 | p03325 | python | s144152043 | s990642047 | 72 | 60 | 4,452 | 4,148 | Accepted | Accepted | 16.67 | from functools import reduce
def count_two(n):
two_count = 0
while n != 0 and n % 2 == 0:
two_count += 1
n //= 2
return two_count
n = int(eval(input()))
a = list(map(int, input().split()))
a_two_count_sum = sum([count_two(ai) for ai in a])
print(a_two_count_sum) | def count_two(n):
two = 0
while n%2 == 0:
n //= 2
two += 1
return two
n = int(eval(input()))
a = [int(m) for m in input().split(" ")]
print((sum([count_two(a_n) for a_n in a]))) | 13 | 11 | 271 | 188 | from functools import reduce
def count_two(n):
two_count = 0
while n != 0 and n % 2 == 0:
two_count += 1
n //= 2
return two_count
n = int(eval(input()))
a = list(map(int, input().split()))
a_two_count_sum = sum([count_two(ai) for ai in a])
print(a_two_count_sum)
| def count_two(n):
two = 0
while n % 2 == 0:
n //= 2
two += 1
return two
n = int(eval(input()))
a = [int(m) for m in input().split(" ")]
print((sum([count_two(a_n) for a_n in a])))
| false | 15.384615 | [
"-from functools import reduce",
"-",
"-",
"- two_count = 0",
"- while n != 0 and n % 2 == 0:",
"- two_count += 1",
"+ two = 0",
"+ while n % 2 == 0:",
"- return two_count",
"+ two += 1",
"+ return two",
"-a = list(map(int, input().split()))",
"-a_two_count_su... | false | 0.040113 | 0.040091 | 1.000555 | [
"s144152043",
"s990642047"
] |
u294385082 | p03308 | python | s688414957 | s706961627 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | n = int(eval(input()))
a = list(map(int,input().split()))
maxabs = 0
for i in range(n):
for j in range(i+1,n):
c = abs(a[i] - a[j])
maxabs = max(maxabs,c)
print(maxabs)
| n = int(eval(input()))
a = list(map(int,input().split()))
print((max(a)-min(a))) | 10 | 4 | 188 | 76 | n = int(eval(input()))
a = list(map(int, input().split()))
maxabs = 0
for i in range(n):
for j in range(i + 1, n):
c = abs(a[i] - a[j])
maxabs = max(maxabs, c)
print(maxabs)
| n = int(eval(input()))
a = list(map(int, input().split()))
print((max(a) - min(a)))
| false | 60 | [
"-maxabs = 0",
"-for i in range(n):",
"- for j in range(i + 1, n):",
"- c = abs(a[i] - a[j])",
"- maxabs = max(maxabs, c)",
"-print(maxabs)",
"+print((max(a) - min(a)))"
] | false | 0.051063 | 0.048038 | 1.062965 | [
"s688414957",
"s706961627"
] |
u186838327 | p03963 | python | s064140117 | s160175803 | 179 | 16 | 38,256 | 2,940 | Accepted | Accepted | 91.06 | n, k = list(map(int, input().split()))
ans = k*((k-1)**(n-1))
print(ans)
| n, k = list(map(int, input().split()))
print((k*(k-1)**(n-1)))
| 3 | 2 | 73 | 56 | n, k = list(map(int, input().split()))
ans = k * ((k - 1) ** (n - 1))
print(ans)
| n, k = list(map(int, input().split()))
print((k * (k - 1) ** (n - 1)))
| false | 33.333333 | [
"-ans = k * ((k - 1) ** (n - 1))",
"-print(ans)",
"+print((k * (k - 1) ** (n - 1)))"
] | false | 0.067551 | 0.037332 | 1.809473 | [
"s064140117",
"s160175803"
] |
u297574184 | p03879 | python | s600962160 | s518602955 | 24 | 19 | 3,444 | 3,188 | Accepted | Accepted | 20.83 | from math import acos, tan, hypot
def getRad1(s12, s13, s23):
return acos((s12*s12 + s13*s13 - s23*s23) / (2*s12*s13))
def getMaxR(s12, rad1, rad2):
tan1 = tan(rad1 / 2)
tan2 = tan(rad2 / 2)
h = s12 * (tan1*tan2) / (tan1+tan2)
return h * (tan1+tan2) / (2*tan1*tan2 + tan1 + tan2)
x1, y1 = list(map(int, input().split()))
x2, y2 = list(map(int, input().split()))
x3, y3 = list(map(int, input().split()))
s12 = hypot(x1-x2, y1-y2)
s23 = hypot(x2-x3, y2-y3)
s31 = hypot(x3-x1, y3-y1)
rad1 = getRad1(s12, s31, s23)
rad2 = getRad1(s23, s12, s31)
rad3 = getRad1(s31, s23, s12)
maxRs = [
getMaxR(s12, rad1, rad2),
getMaxR(s23, rad2, rad3),
getMaxR(s31, rad3, rad1)
]
print((max(maxRs)))
| from math import acos, tan, hypot
def getRad1(s12, s13, s23):
return acos((s12*s12 + s13*s13 - s23*s23) / (2*s12*s13))
def getMaxR(s12, rad1, rad2):
tan1 = tan(rad1 / 2)
tan2 = tan(rad2 / 2)
h = s12 * (tan1*tan2) / (tan1+tan2)
def isOK(mid):
return s12 - mid/tan1 - mid/tan2 <= 2*mid
ng, ok = 0, h
while abs(ok-ng) > 10**-12:
mid = (ng+ok) / 2
if isOK(mid):
ok = mid
else:
ng = mid
return ok
x1, y1 = list(map(int, input().split()))
x2, y2 = list(map(int, input().split()))
x3, y3 = list(map(int, input().split()))
s12 = hypot(x1-x2, y1-y2)
s23 = hypot(x2-x3, y2-y3)
s31 = hypot(x3-x1, y3-y1)
rad1 = getRad1(s12, s31, s23)
rad2 = getRad1(s23, s12, s31)
rad3 = getRad1(s31, s23, s12)
maxRs = [
getMaxR(s12, rad1, rad2),
getMaxR(s23, rad2, rad3),
getMaxR(s31, rad3, rad1)
]
print((max(maxRs)))
| 29 | 40 | 727 | 920 | from math import acos, tan, hypot
def getRad1(s12, s13, s23):
return acos((s12 * s12 + s13 * s13 - s23 * s23) / (2 * s12 * s13))
def getMaxR(s12, rad1, rad2):
tan1 = tan(rad1 / 2)
tan2 = tan(rad2 / 2)
h = s12 * (tan1 * tan2) / (tan1 + tan2)
return h * (tan1 + tan2) / (2 * tan1 * tan2 + tan1 + tan2)
x1, y1 = list(map(int, input().split()))
x2, y2 = list(map(int, input().split()))
x3, y3 = list(map(int, input().split()))
s12 = hypot(x1 - x2, y1 - y2)
s23 = hypot(x2 - x3, y2 - y3)
s31 = hypot(x3 - x1, y3 - y1)
rad1 = getRad1(s12, s31, s23)
rad2 = getRad1(s23, s12, s31)
rad3 = getRad1(s31, s23, s12)
maxRs = [getMaxR(s12, rad1, rad2), getMaxR(s23, rad2, rad3), getMaxR(s31, rad3, rad1)]
print((max(maxRs)))
| from math import acos, tan, hypot
def getRad1(s12, s13, s23):
return acos((s12 * s12 + s13 * s13 - s23 * s23) / (2 * s12 * s13))
def getMaxR(s12, rad1, rad2):
tan1 = tan(rad1 / 2)
tan2 = tan(rad2 / 2)
h = s12 * (tan1 * tan2) / (tan1 + tan2)
def isOK(mid):
return s12 - mid / tan1 - mid / tan2 <= 2 * mid
ng, ok = 0, h
while abs(ok - ng) > 10**-12:
mid = (ng + ok) / 2
if isOK(mid):
ok = mid
else:
ng = mid
return ok
x1, y1 = list(map(int, input().split()))
x2, y2 = list(map(int, input().split()))
x3, y3 = list(map(int, input().split()))
s12 = hypot(x1 - x2, y1 - y2)
s23 = hypot(x2 - x3, y2 - y3)
s31 = hypot(x3 - x1, y3 - y1)
rad1 = getRad1(s12, s31, s23)
rad2 = getRad1(s23, s12, s31)
rad3 = getRad1(s31, s23, s12)
maxRs = [getMaxR(s12, rad1, rad2), getMaxR(s23, rad2, rad3), getMaxR(s31, rad3, rad1)]
print((max(maxRs)))
| false | 27.5 | [
"- return h * (tan1 + tan2) / (2 * tan1 * tan2 + tan1 + tan2)",
"+",
"+ def isOK(mid):",
"+ return s12 - mid / tan1 - mid / tan2 <= 2 * mid",
"+",
"+ ng, ok = 0, h",
"+ while abs(ok - ng) > 10**-12:",
"+ mid = (ng + ok) / 2",
"+ if isOK(mid):",
"+ ok = m... | false | 0.036957 | 0.071235 | 0.518807 | [
"s600962160",
"s518602955"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.