user_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| language
stringclasses 1
value | submission_id_v0
stringlengths 10
10
| submission_id_v1
stringlengths 10
10
| cpu_time_v0
int64 10
38.3k
| cpu_time_v1
int64 0
24.7k
| memory_v0
int64 2.57k
1.02M
| memory_v1
int64 2.57k
869k
| status_v0
stringclasses 1
value | status_v1
stringclasses 1
value | improvement_frac
float64 7.51
100
| input
stringlengths 20
4.55k
| target
stringlengths 17
3.34k
| code_v0_loc
int64 1
148
| code_v1_loc
int64 1
184
| code_v0_num_chars
int64 13
4.55k
| code_v1_num_chars
int64 14
3.34k
| code_v0_no_empty_lines
stringlengths 21
6.88k
| code_v1_no_empty_lines
stringlengths 20
4.93k
| code_same
bool 1
class | relative_loc_diff_percent
float64 0
79.8
| diff
sequence | diff_only_import_comment
bool 1
class | measured_runtime_v0
float64 0.01
4.45
| measured_runtime_v1
float64 0.01
4.31
| runtime_lift
float64 0
359
| key
sequence |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u463655976 | p03163 | python | s772181990 | s822888638 | 1,019 | 879 | 139,736 | 122,544 | Accepted | Accepted | 13.74 | # TODO:実装
N, W = list(map(int, input().split()))
DP = {0: 0}
for i in range(N):
wi, vi = list(map(int, input().split()))
DP_dst = DP.copy()
for j in DP:
if j+wi <= W:
DP_dst[j+wi] = max(DP.get(j+wi, 0), DP[j]+vi)
DP = DP_dst
print((max((DP[x] for x in DP))))
| N, W = list(map(int, input().split()))
DP = {0: 0}
for i in range(N):
wi, vi = list(map(int, input().split()))
p = {}
for j in DP:
if j+wi <= W and DP.get(j+wi, 0) < DP[j]+vi:
p[j+wi] = DP[j]+vi
for pi in p:
DP[pi] = p[pi]
print((max((DP[x] for x in DP))))
| 12 | 12 | 293 | 299 | # TODO:実装
N, W = list(map(int, input().split()))
DP = {0: 0}
for i in range(N):
wi, vi = list(map(int, input().split()))
DP_dst = DP.copy()
for j in DP:
if j + wi <= W:
DP_dst[j + wi] = max(DP.get(j + wi, 0), DP[j] + vi)
DP = DP_dst
print((max((DP[x] for x in DP))))
| N, W = list(map(int, input().split()))
DP = {0: 0}
for i in range(N):
wi, vi = list(map(int, input().split()))
p = {}
for j in DP:
if j + wi <= W and DP.get(j + wi, 0) < DP[j] + vi:
p[j + wi] = DP[j] + vi
for pi in p:
DP[pi] = p[pi]
print((max((DP[x] for x in DP))))
| false | 0 | [
"-# TODO:実装",
"- DP_dst = DP.copy()",
"+ p = {}",
"- if j + wi <= W:",
"- DP_dst[j + wi] = max(DP.get(j + wi, 0), DP[j] + vi)",
"- DP = DP_dst",
"+ if j + wi <= W and DP.get(j + wi, 0) < DP[j] + vi:",
"+ p[j + wi] = DP[j] + vi",
"+ for pi in p:",
"+ DP[pi] = p[pi]"
] | false | 0.036902 | 0.106142 | 0.347671 | [
"s772181990",
"s822888638"
] |
u936985471 | p02853 | python | s850453469 | s337696740 | 20 | 17 | 3,316 | 2,940 | Accepted | Accepted | 15 | X,Y=list(map(int,input().split()))
Xp=max((4-X),0)*100000
Yp=max((4-Y),0)*100000
print((Xp+Yp+((0,400000)[X*Y==1]))) | X,Y=list(map(int,input().split()));print(((max((4-X),0)+max((4-Y),0)+((0,4)[X*Y==1]))*10**5)) | 4 | 1 | 111 | 85 | X, Y = list(map(int, input().split()))
Xp = max((4 - X), 0) * 100000
Yp = max((4 - Y), 0) * 100000
print((Xp + Yp + ((0, 400000)[X * Y == 1])))
| X, Y = list(map(int, input().split()))
print(((max((4 - X), 0) + max((4 - Y), 0) + ((0, 4)[X * Y == 1])) * 10**5))
| false | 75 | [
"-Xp = max((4 - X), 0) * 100000",
"-Yp = max((4 - Y), 0) * 100000",
"-print((Xp + Yp + ((0, 400000)[X * Y == 1])))",
"+print(((max((4 - X), 0) + max((4 - Y), 0) + ((0, 4)[X * Y == 1])) * 10**5))"
] | false | 0.043998 | 0.045551 | 0.965909 | [
"s850453469",
"s337696740"
] |
u699296734 | p02743 | python | s744394277 | s315401259 | 35 | 20 | 5,332 | 3,316 | Accepted | Accepted | 42.86 | from decimal import Decimal
import math
a,b,c=list(map(int,input().split()))
if c-a-b>0 and 4*a*b<(c-a-b)**2:
print("Yes")
else:
print("No")
| a,b,c=list(map(int,input().split()))
if 4*a*b < (c-a-b)**2 and (c-a-b)>0:
print("Yes")
else:
print("No") | 7 | 5 | 145 | 106 | from decimal import Decimal
import math
a, b, c = list(map(int, input().split()))
if c - a - b > 0 and 4 * a * b < (c - a - b) ** 2:
print("Yes")
else:
print("No")
| a, b, c = list(map(int, input().split()))
if 4 * a * b < (c - a - b) ** 2 and (c - a - b) > 0:
print("Yes")
else:
print("No")
| false | 28.571429 | [
"-from decimal import Decimal",
"-import math",
"-",
"-if c - a - b > 0 and 4 * a * b < (c - a - b) ** 2:",
"+if 4 * a * b < (c - a - b) ** 2 and (c - a - b) > 0:"
] | false | 0.074366 | 0.037333 | 1.991941 | [
"s744394277",
"s315401259"
] |
u077291787 | p03722 | python | s994342867 | s088305425 | 537 | 432 | 3,316 | 3,312 | Accepted | Accepted | 19.55 | # ABC061D - Score Attack
import sys
input = sys.stdin.readline
def bellman_ford(N: int, M: int, E: "Array[Array[int]]") -> int or None:
INF = float("inf")
dist = [INF] * (N + 1)
dist[1] = 0
# relax edges
for i in range(N):
for v, u, w in E: # w: positive -> -w
if v != INF and dist[v] - w < dist[u]:
dist[u] = dist[v] - w
if i == N - 1 and u == N: # detect negative cycles
return None
return dist[-1]
def main():
# reverse weights -> shortest path problem containing negative cycles
N, M = tuple(map(int, input().split())) # vertices, edges
E = tuple(tuple(map(int, input().split())) for _ in range(M))
ans = bellman_ford(N, M, E)
flg = ans is not None
print((-ans if flg else "inf"))
if __name__ == "__main__":
main() | # ABC061D - Score Attack
import sys
input = sys.stdin.readline
def bellman_ford(N: int, M: int, E: "Array[Array[int]]") -> int or None:
INF = float("inf")
dist = [INF] * (N + 1)
dist[1] = 0
# relax edges
for i in range(N):
for v, u, w in E: # w: positive -> -w
if dist[v] - w < dist[u]:
dist[u] = dist[v] - w
if i == N - 1 and u == N: # detect negative cycles
return None
return dist[-1]
def main():
# reverse weights -> shortest path problem containing negative cycles
N, M = tuple(map(int, input().split())) # vertices, edges
E = tuple(tuple(map(int, input().split())) for _ in range(M))
ans = bellman_ford(N, M, E)
flg = ans is not None
print((-ans if flg else "inf"))
if __name__ == "__main__":
main() | 30 | 30 | 878 | 865 | # ABC061D - Score Attack
import sys
input = sys.stdin.readline
def bellman_ford(N: int, M: int, E: "Array[Array[int]]") -> int or None:
INF = float("inf")
dist = [INF] * (N + 1)
dist[1] = 0
# relax edges
for i in range(N):
for v, u, w in E: # w: positive -> -w
if v != INF and dist[v] - w < dist[u]:
dist[u] = dist[v] - w
if i == N - 1 and u == N: # detect negative cycles
return None
return dist[-1]
def main():
# reverse weights -> shortest path problem containing negative cycles
N, M = tuple(map(int, input().split())) # vertices, edges
E = tuple(tuple(map(int, input().split())) for _ in range(M))
ans = bellman_ford(N, M, E)
flg = ans is not None
print((-ans if flg else "inf"))
if __name__ == "__main__":
main()
| # ABC061D - Score Attack
import sys
input = sys.stdin.readline
def bellman_ford(N: int, M: int, E: "Array[Array[int]]") -> int or None:
INF = float("inf")
dist = [INF] * (N + 1)
dist[1] = 0
# relax edges
for i in range(N):
for v, u, w in E: # w: positive -> -w
if dist[v] - w < dist[u]:
dist[u] = dist[v] - w
if i == N - 1 and u == N: # detect negative cycles
return None
return dist[-1]
def main():
# reverse weights -> shortest path problem containing negative cycles
N, M = tuple(map(int, input().split())) # vertices, edges
E = tuple(tuple(map(int, input().split())) for _ in range(M))
ans = bellman_ford(N, M, E)
flg = ans is not None
print((-ans if flg else "inf"))
if __name__ == "__main__":
main()
| false | 0 | [
"- if v != INF and dist[v] - w < dist[u]:",
"+ if dist[v] - w < dist[u]:"
] | false | 0.047005 | 0.047592 | 0.987664 | [
"s994342867",
"s088305425"
] |
u585742242 | p03291 | python | s392863316 | s274306665 | 476 | 231 | 27,588 | 3,188 | Accepted | Accepted | 51.47 | # -*- coding: utf-8 -*-
S = eval(input())
mod = 10 ** 9 + 7
dp = [[0] * 4 for i in range(len(S) + 1)]
dp[len(S)][3] = 1
for i in range(len(S) - 1, -1, -1):
dp[i][3] += dp[i + 1][3] * 3 if S[i] == '?' else dp[i + 1][3]
dp[i][3] %= mod
for j in range(2, -1, -1):
dp[i][j] += dp[i + 1][j] * 3 if S[i] == '?' else dp[i + 1][j]
dp[i][j] += dp[i + 1][j + 1] if S[i] == 'ABC' [j] or S[i] == '?' else 0
dp[i][j] %= mod
print((dp[0][0]))
|
# AC (faster) ###############################################################
mod = 10**9 + 7
dp = [0, 0, 0, 1]
for s in input()[::-1]:
tmp = dp[:]
dp[3] = tmp[3] * 3 if s == '?' else tmp[3]
dp[3] %= mod
for j in range(2, -1, -1):
dp[j] = tmp[j] * 3 + tmp[j + 1] if s == '?' else \
tmp[j] + tmp[j + 1] if s == 'ABC'[j] else \
tmp[j]
dp[j] %= mod
print(dp[0] % (10**9 + 7))
| 16 | 17 | 475 | 457 | # -*- coding: utf-8 -*-
S = eval(input())
mod = 10**9 + 7
dp = [[0] * 4 for i in range(len(S) + 1)]
dp[len(S)][3] = 1
for i in range(len(S) - 1, -1, -1):
dp[i][3] += dp[i + 1][3] * 3 if S[i] == "?" else dp[i + 1][3]
dp[i][3] %= mod
for j in range(2, -1, -1):
dp[i][j] += dp[i + 1][j] * 3 if S[i] == "?" else dp[i + 1][j]
dp[i][j] += dp[i + 1][j + 1] if S[i] == "ABC"[j] or S[i] == "?" else 0
dp[i][j] %= mod
print((dp[0][0]))
| # AC (faster) ###############################################################
mod = 10**9 + 7
dp = [0, 0, 0, 1]
for s in input()[::-1]:
tmp = dp[:]
dp[3] = tmp[3] * 3 if s == "?" else tmp[3]
dp[3] %= mod
for j in range(2, -1, -1):
dp[j] = (
tmp[j] * 3 + tmp[j + 1]
if s == "?"
else tmp[j] + tmp[j + 1]
if s == "ABC"[j]
else tmp[j]
)
dp[j] %= mod
print(dp[0] % (10**9 + 7))
| false | 5.882353 | [
"-# -*- coding: utf-8 -*-",
"-S = eval(input())",
"+# AC (faster) ###############################################################",
"-dp = [[0] * 4 for i in range(len(S) + 1)]",
"-dp[len(S)][3] = 1",
"-for i in range(len(S) - 1, -1, -1):",
"- dp[i][3] += dp[i + 1][3] * 3 if S[i] == \"?\" else dp[i + 1][3]",
"- dp[i][3] %= mod",
"+dp = [0, 0, 0, 1]",
"+for s in input()[::-1]:",
"+ tmp = dp[:]",
"+ dp[3] = tmp[3] * 3 if s == \"?\" else tmp[3]",
"+ dp[3] %= mod",
"- dp[i][j] += dp[i + 1][j] * 3 if S[i] == \"?\" else dp[i + 1][j]",
"- dp[i][j] += dp[i + 1][j + 1] if S[i] == \"ABC\"[j] or S[i] == \"?\" else 0",
"- dp[i][j] %= mod",
"-print((dp[0][0]))",
"+ dp[j] = (",
"+ tmp[j] * 3 + tmp[j + 1]",
"+ if s == \"?\"",
"+ else tmp[j] + tmp[j + 1]",
"+ if s == \"ABC\"[j]",
"+ else tmp[j]",
"+ )",
"+ dp[j] %= mod",
"+print(dp[0] % (10**9 + 7))"
] | false | 0.036913 | 0.034464 | 1.071043 | [
"s392863316",
"s274306665"
] |
u795630164 | p03494 | python | s523578788 | s807603859 | 20 | 18 | 3,060 | 3,064 | Accepted | Accepted | 10 | N = eval(input())
x = list(map(int, input().split()))
end = True
count = 0
def div2(y):
return y / 2
while end:
for i in x:
if i % 2 == 1:
end = False
break
else:
count += 1
x = list(map(div2, x))
continue
break
print(count) | N = eval(input())
A = list(map(int, input().split()))
ans = 10 ** 9
for a in A:
x = 0
while a > 1:
if a % 2 != 0:
break
a //= 2
x += 1
ans = min(ans, x)
print(ans) | 19 | 14 | 310 | 214 | N = eval(input())
x = list(map(int, input().split()))
end = True
count = 0
def div2(y):
return y / 2
while end:
for i in x:
if i % 2 == 1:
end = False
break
else:
count += 1
x = list(map(div2, x))
continue
break
print(count)
| N = eval(input())
A = list(map(int, input().split()))
ans = 10**9
for a in A:
x = 0
while a > 1:
if a % 2 != 0:
break
a //= 2
x += 1
ans = min(ans, x)
print(ans)
| false | 26.315789 | [
"-x = list(map(int, input().split()))",
"-end = True",
"-count = 0",
"-",
"-",
"-def div2(y):",
"- return y / 2",
"-",
"-",
"-while end:",
"- for i in x:",
"- if i % 2 == 1:",
"- end = False",
"+A = list(map(int, input().split()))",
"+ans = 10**9",
"+for a in A:",
"+ x = 0",
"+ while a > 1:",
"+ if a % 2 != 0:",
"- else:",
"- count += 1",
"- x = list(map(div2, x))",
"- continue",
"- break",
"-print(count)",
"+ a //= 2",
"+ x += 1",
"+ ans = min(ans, x)",
"+print(ans)"
] | false | 0.037518 | 0.037363 | 1.004133 | [
"s523578788",
"s807603859"
] |
u540761833 | p02937 | python | s709277590 | s476835093 | 407 | 133 | 8,052 | 7,796 | Accepted | Accepted | 67.32 | from collections import defaultdict
import bisect
s = eval(input())
t = eval(input())
dicta = defaultdict(list)
for a,b in enumerate(s):
dicta[b] += [a]
snow = -1
count = 0
flag = True
for i in t:
if i not in s:
flag = False
break
nowt = dicta[i]
snowind = bisect.bisect_right(nowt,snow)
if snowind == len(nowt):
count += 1
snow = nowt[0]
else:
snow = nowt[snowind]
if flag:
print((len(s)*count+snow +1))
else:
print((-1))
| from collections import defaultdict
import bisect
s = eval(input())
t = eval(input())
dicta = defaultdict(list)
for a,b in enumerate(s):
dicta[b] += [a]
snow = -1
count = 0
flag = True
for i in t:
if not dicta[i]:
flag = False
break
nowt = dicta[i]
snowind = bisect.bisect_right(nowt,snow)
if snowind == len(nowt):
count += 1
snow = nowt[0]
else:
snow = nowt[snowind]
if flag:
print((len(s)*count+snow +1))
else:
print((-1))
| 26 | 26 | 512 | 514 | from collections import defaultdict
import bisect
s = eval(input())
t = eval(input())
dicta = defaultdict(list)
for a, b in enumerate(s):
dicta[b] += [a]
snow = -1
count = 0
flag = True
for i in t:
if i not in s:
flag = False
break
nowt = dicta[i]
snowind = bisect.bisect_right(nowt, snow)
if snowind == len(nowt):
count += 1
snow = nowt[0]
else:
snow = nowt[snowind]
if flag:
print((len(s) * count + snow + 1))
else:
print((-1))
| from collections import defaultdict
import bisect
s = eval(input())
t = eval(input())
dicta = defaultdict(list)
for a, b in enumerate(s):
dicta[b] += [a]
snow = -1
count = 0
flag = True
for i in t:
if not dicta[i]:
flag = False
break
nowt = dicta[i]
snowind = bisect.bisect_right(nowt, snow)
if snowind == len(nowt):
count += 1
snow = nowt[0]
else:
snow = nowt[snowind]
if flag:
print((len(s) * count + snow + 1))
else:
print((-1))
| false | 0 | [
"- if i not in s:",
"+ if not dicta[i]:"
] | false | 0.039274 | 0.048501 | 0.809768 | [
"s709277590",
"s476835093"
] |
u450180547 | p03160 | python | s039585866 | s449544342 | 141 | 126 | 13,924 | 13,924 | Accepted | Accepted | 10.64 | N = int(eval(input()))
hs = list(map(int, input().split()))
INF = 10 ** 10
dp = [INF] * N
dp[0] = 0
dp[1] = abs(hs[1] - hs[0])
for i in range(1, N):
dp[i] = min(dp[i - 1] + (abs(hs[i] - hs[i - 1])),
dp[i - 2] + (abs(hs[i] - hs[i - 2])))
print((dp[N - 1])) | N = int(eval(input()))
hs = list(map(int, input().split()))
INF = 10 ** 10
dp = [INF] * N
dp[0] = 0
dp[1] = abs(hs[1] - hs[0])
for i in range(2, N):
dp[i] = min(dp[i - 1] + (abs(hs[i] - hs[i - 1])),
dp[i - 2] + (abs(hs[i] - hs[i - 2])))
print((dp[N - 1]))
| 14 | 14 | 284 | 285 | N = int(eval(input()))
hs = list(map(int, input().split()))
INF = 10**10
dp = [INF] * N
dp[0] = 0
dp[1] = abs(hs[1] - hs[0])
for i in range(1, N):
dp[i] = min(
dp[i - 1] + (abs(hs[i] - hs[i - 1])), dp[i - 2] + (abs(hs[i] - hs[i - 2]))
)
print((dp[N - 1]))
| N = int(eval(input()))
hs = list(map(int, input().split()))
INF = 10**10
dp = [INF] * N
dp[0] = 0
dp[1] = abs(hs[1] - hs[0])
for i in range(2, N):
dp[i] = min(
dp[i - 1] + (abs(hs[i] - hs[i - 1])), dp[i - 2] + (abs(hs[i] - hs[i - 2]))
)
print((dp[N - 1]))
| false | 0 | [
"-for i in range(1, N):",
"+for i in range(2, N):"
] | false | 0.059879 | 0.040151 | 1.491359 | [
"s039585866",
"s449544342"
] |
u499381410 | p02990 | python | s247338944 | s471389252 | 298 | 231 | 43,864 | 44,272 | Accepted | Accepted | 22.48 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce
INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
def comb(n, r):
if r > n: return 0
fact = 1
for i in range(n - r + 1, n + 1):
fact = fact * i % mod
divisor = 1
for j in range(1, r + 1):
divisor = divisor * j % mod
return fact * pow(divisor, mod - 2, mod) % mod
n,k = LI()
for i in range(1, k+1):
print((comb(n - k + 1, i) * comb(k - 1, i - 1) % mod)) | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, k = LI()
l = n + k
fac = [1] * (l + 1)
inv = [1] * (l + 1)
for j in range(1, l + 1):
fac[j] = fac[j - 1] * j % mod
inv[l] = pow(fac[l], mod - 2, mod)
for j in range(l - 1, -1, -1):
inv[j] = inv[j + 1] * (j + 1) % mod
def comb(n, r):
if r > n or n < 0 or r < 0:
return 0
return fac[n] * inv[n - r] * inv[r] % mod
if n == k:
for i in range(k):
if i == 0:
print((1))
else:
print((0))
else:
for i in range(k):
print(((comb(k - 1, i) * (comb(n - k - 1, i) * 2 + comb(n - k - 1, i + 1) + comb(n - k - 1, i - 1))) % mod)) | 44 | 65 | 1,262 | 1,739 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce
INF = float("inf")
def LI():
return list(map(int, sys.stdin.readline().split()))
def I():
return int(sys.stdin.readline())
def LS():
return sys.stdin.readline().split()
def S():
return sys.stdin.readline().strip()
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
def comb(n, r):
if r > n:
return 0
fact = 1
for i in range(n - r + 1, n + 1):
fact = fact * i % mod
divisor = 1
for j in range(1, r + 1):
divisor = divisor * j % mod
return fact * pow(divisor, mod - 2, mod) % mod
n, k = LI()
for i in range(1, k + 1):
print((comb(n - k + 1, i) * comb(k - 1, i - 1) % mod))
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint
sys.setrecursionlimit(2147483647)
INF = 10**13
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def I():
return int(sys.stdin.buffer.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, k = LI()
l = n + k
fac = [1] * (l + 1)
inv = [1] * (l + 1)
for j in range(1, l + 1):
fac[j] = fac[j - 1] * j % mod
inv[l] = pow(fac[l], mod - 2, mod)
for j in range(l - 1, -1, -1):
inv[j] = inv[j + 1] * (j + 1) % mod
def comb(n, r):
if r > n or n < 0 or r < 0:
return 0
return fac[n] * inv[n - r] * inv[r] % mod
if n == k:
for i in range(k):
if i == 0:
print((1))
else:
print((0))
else:
for i in range(k):
print(
(
(
comb(k - 1, i)
* (
comb(n - k - 1, i) * 2
+ comb(n - k - 1, i + 1)
+ comb(n - k - 1, i - 1)
)
)
% mod
)
)
| false | 32.307692 | [
"+from pprint import pprint",
"+from copy import deepcopy",
"+from operator import mul",
"+from pprint import pprint",
"-INF = float(\"inf\")",
"+sys.setrecursionlimit(2147483647)",
"+INF = 10**13",
"- return list(map(int, sys.stdin.readline().split()))",
"+ return list(map(int, sys.stdin.buffer.readline().split()))",
"- return int(sys.stdin.readline())",
"+ return int(sys.stdin.buffer.readline())",
"- return sys.stdin.readline().split()",
"+ return sys.stdin.buffer.readline().rstrip().decode(\"utf-8\").split()",
"- return sys.stdin.readline().strip()",
"+ return sys.stdin.buffer.readline().rstrip().decode(\"utf-8\")",
"+n, k = LI()",
"+l = n + k",
"+fac = [1] * (l + 1)",
"+inv = [1] * (l + 1)",
"+for j in range(1, l + 1):",
"+ fac[j] = fac[j - 1] * j % mod",
"+inv[l] = pow(fac[l], mod - 2, mod)",
"+for j in range(l - 1, -1, -1):",
"+ inv[j] = inv[j + 1] * (j + 1) % mod",
"- if r > n:",
"+ if r > n or n < 0 or r < 0:",
"- fact = 1",
"- for i in range(n - r + 1, n + 1):",
"- fact = fact * i % mod",
"- divisor = 1",
"- for j in range(1, r + 1):",
"- divisor = divisor * j % mod",
"- return fact * pow(divisor, mod - 2, mod) % mod",
"+ return fac[n] * inv[n - r] * inv[r] % mod",
"-n, k = LI()",
"-for i in range(1, k + 1):",
"- print((comb(n - k + 1, i) * comb(k - 1, i - 1) % mod))",
"+if n == k:",
"+ for i in range(k):",
"+ if i == 0:",
"+ print((1))",
"+ else:",
"+ print((0))",
"+else:",
"+ for i in range(k):",
"+ print(",
"+ (",
"+ (",
"+ comb(k - 1, i)",
"+ * (",
"+ comb(n - k - 1, i) * 2",
"+ + comb(n - k - 1, i + 1)",
"+ + comb(n - k - 1, i - 1)",
"+ )",
"+ )",
"+ % mod",
"+ )",
"+ )"
] | false | 0.039787 | 0.040133 | 0.991365 | [
"s247338944",
"s471389252"
] |
u130860911 | p02838 | python | s323220441 | s648866319 | 1,991 | 313 | 42,156 | 48,824 | Accepted | Accepted | 84.28 | M = 10**9+7
N = int(eval(input()))
A = list(map(int,input().split()))
ans = 0
for k in range(61):
N1 = 0
N1 = sum([1 for a in A if ( (a >> k) & 1)])
ans += (((1<<k)) *(N-N1) *N1)
ans %= M
print(ans) | import numpy as np
M = 10**9+7
N = int(eval(input()))
A = np.array(list(map(int,input().split())),dtype='int64')
ans = 0
maxA = np.amax(A)
K = len(str(bin(maxA)))-2
for k in range(K):
N1 = 0
N1 = np.sum((A >> k) & 1)
N0 = N-N1
ans += (((1<<k)%M) *N0%M) *N1%M
ans %= M
print(ans) | 12 | 17 | 225 | 311 | M = 10**9 + 7
N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
for k in range(61):
N1 = 0
N1 = sum([1 for a in A if ((a >> k) & 1)])
ans += ((1 << k)) * (N - N1) * N1
ans %= M
print(ans)
| import numpy as np
M = 10**9 + 7
N = int(eval(input()))
A = np.array(list(map(int, input().split())), dtype="int64")
ans = 0
maxA = np.amax(A)
K = len(str(bin(maxA))) - 2
for k in range(K):
N1 = 0
N1 = np.sum((A >> k) & 1)
N0 = N - N1
ans += (((1 << k) % M) * N0 % M) * N1 % M
ans %= M
print(ans)
| false | 29.411765 | [
"+import numpy as np",
"+",
"-A = list(map(int, input().split()))",
"+A = np.array(list(map(int, input().split())), dtype=\"int64\")",
"-for k in range(61):",
"+maxA = np.amax(A)",
"+K = len(str(bin(maxA))) - 2",
"+for k in range(K):",
"- N1 = sum([1 for a in A if ((a >> k) & 1)])",
"- ans += ((1 << k)) * (N - N1) * N1",
"+ N1 = np.sum((A >> k) & 1)",
"+ N0 = N - N1",
"+ ans += (((1 << k) % M) * N0 % M) * N1 % M"
] | false | 0.052223 | 0.173259 | 0.301418 | [
"s323220441",
"s648866319"
] |
u279483260 | p02400 | python | s072070314 | s548653290 | 30 | 20 | 5,624 | 5,620 | Accepted | Accepted | 33.33 | from math import pi
r=float(eval(input()))
print(("{} {}".format(r*r*pi,2*pi*r)))
| from math import pi
r = float(eval(input()))
# 面積
circle_area = r * r * pi
# 円周
circumference = 2.0 * r * pi
print(("{} {}".format(circle_area, circumference)))
| 3 | 10 | 76 | 165 | from math import pi
r = float(eval(input()))
print(("{} {}".format(r * r * pi, 2 * pi * r)))
| from math import pi
r = float(eval(input()))
# 面積
circle_area = r * r * pi
# 円周
circumference = 2.0 * r * pi
print(("{} {}".format(circle_area, circumference)))
| false | 70 | [
"-print((\"{} {}\".format(r * r * pi, 2 * pi * r)))",
"+# 面積",
"+circle_area = r * r * pi",
"+# 円周",
"+circumference = 2.0 * r * pi",
"+print((\"{} {}\".format(circle_area, circumference)))"
] | false | 0.111101 | 0.040982 | 2.710982 | [
"s072070314",
"s548653290"
] |
u644907318 | p03817 | python | s165216795 | s883152383 | 182 | 68 | 38,256 | 61,764 | Accepted | Accepted | 62.64 | x = int(eval(input()))
n = x//11
k = x%11
if k==0:
print((2*n))
elif 0<k<=6:
print((2*n+1))
else:
print((2*n+2)) | x = int(eval(input()))
n = x//11
a = x%11
if a==0:
ans = 2*n
elif 1<=a<=6:
ans = 2*n+1
else:
ans = 2*n+2
print(ans) | 9 | 10 | 120 | 130 | x = int(eval(input()))
n = x // 11
k = x % 11
if k == 0:
print((2 * n))
elif 0 < k <= 6:
print((2 * n + 1))
else:
print((2 * n + 2))
| x = int(eval(input()))
n = x // 11
a = x % 11
if a == 0:
ans = 2 * n
elif 1 <= a <= 6:
ans = 2 * n + 1
else:
ans = 2 * n + 2
print(ans)
| false | 10 | [
"-k = x % 11",
"-if k == 0:",
"- print((2 * n))",
"-elif 0 < k <= 6:",
"- print((2 * n + 1))",
"+a = x % 11",
"+if a == 0:",
"+ ans = 2 * n",
"+elif 1 <= a <= 6:",
"+ ans = 2 * n + 1",
"- print((2 * n + 2))",
"+ ans = 2 * n + 2",
"+print(ans)"
] | false | 0.03895 | 0.041802 | 0.931782 | [
"s165216795",
"s883152383"
] |
u761320129 | p03287 | python | s841532593 | s321930609 | 128 | 89 | 14,920 | 16,556 | Accepted | Accepted | 30.47 | from collections import Counter
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
ctr = Counter()
ctr[0] = 1
cum = 0
for a in A:
cum = (cum + a) % M
ctr[cum] += 1
ans = 0
for v in list(ctr.values()):
ans += v*(v-1)//2
print(ans) | from collections import Counter
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
cums = [0]
for a in A:
cums.append((cums[-1] + a) % M)
ctr = Counter(cums)
ans = 0
for v in list(ctr.values()):
ans += v*(v-1)//2
print(ans) | 16 | 15 | 268 | 258 | from collections import Counter
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
ctr = Counter()
ctr[0] = 1
cum = 0
for a in A:
cum = (cum + a) % M
ctr[cum] += 1
ans = 0
for v in list(ctr.values()):
ans += v * (v - 1) // 2
print(ans)
| from collections import Counter
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
cums = [0]
for a in A:
cums.append((cums[-1] + a) % M)
ctr = Counter(cums)
ans = 0
for v in list(ctr.values()):
ans += v * (v - 1) // 2
print(ans)
| false | 6.25 | [
"-ctr = Counter()",
"-ctr[0] = 1",
"-cum = 0",
"+cums = [0]",
"- cum = (cum + a) % M",
"- ctr[cum] += 1",
"+ cums.append((cums[-1] + a) % M)",
"+ctr = Counter(cums)"
] | false | 0.042758 | 0.202974 | 0.210655 | [
"s841532593",
"s321930609"
] |
u556225812 | p03408 | python | s870594210 | s927486664 | 21 | 17 | 3,316 | 3,064 | Accepted | Accepted | 19.05 | from collections import Counter
blue = []
red = []
N = int(eval(input()))
for i in range(N):
blue.append(eval(input()))
M = int(eval(input()))
for j in range(M):
red.append(eval(input()))
b = Counter(blue)
r = Counter(red)
print((max([0] + [b[x] - r[x] for x in b])))
| N = int(eval(input()))
dic = {}
for i in range(N):
s = eval(input())
if s not in dic:
dic[s] = 1
else:
dic[s] += 1
M = int(eval(input()))
for i in range(M):
s = eval(input())
if s not in dic:
dic[s] = -1
else:
dic[s] -= 1
lst = list(dic.values())
lst.append(0)
print((max(lst))) | 13 | 18 | 265 | 297 | from collections import Counter
blue = []
red = []
N = int(eval(input()))
for i in range(N):
blue.append(eval(input()))
M = int(eval(input()))
for j in range(M):
red.append(eval(input()))
b = Counter(blue)
r = Counter(red)
print((max([0] + [b[x] - r[x] for x in b])))
| N = int(eval(input()))
dic = {}
for i in range(N):
s = eval(input())
if s not in dic:
dic[s] = 1
else:
dic[s] += 1
M = int(eval(input()))
for i in range(M):
s = eval(input())
if s not in dic:
dic[s] = -1
else:
dic[s] -= 1
lst = list(dic.values())
lst.append(0)
print((max(lst)))
| false | 27.777778 | [
"-from collections import Counter",
"-",
"-blue = []",
"-red = []",
"+dic = {}",
"- blue.append(eval(input()))",
"+ s = eval(input())",
"+ if s not in dic:",
"+ dic[s] = 1",
"+ else:",
"+ dic[s] += 1",
"-for j in range(M):",
"- red.append(eval(input()))",
"-b = Counter(blue)",
"-r = Counter(red)",
"-print((max([0] + [b[x] - r[x] for x in b])))",
"+for i in range(M):",
"+ s = eval(input())",
"+ if s not in dic:",
"+ dic[s] = -1",
"+ else:",
"+ dic[s] -= 1",
"+lst = list(dic.values())",
"+lst.append(0)",
"+print((max(lst)))"
] | false | 0.040458 | 0.039478 | 1.02484 | [
"s870594210",
"s927486664"
] |
u972658925 | p02843 | python | s981162359 | s631128512 | 236 | 218 | 9,524 | 9,408 | Accepted | Accepted | 7.63 | x = int(eval(input()))
dp = [0]*(x + 105 + 1)
dp[100] = 1
dp[101] = 1
dp[102] = 1
dp[103] = 1
dp[104] = 1
dp[105] = 1
for i in range(100,x-105+6):
for j in range(100,106):
dp[i+j] = max(dp[i] , dp[i+j])
print((dp[x])) | x = int(eval(input()))
dp = [0]*(x + 105 + 1)
dp[100] = 1
dp[101] = 1
dp[102] = 1
dp[103] = 1
dp[104] = 1
dp[105] = 1
for i in range(100,x+1):
for j in range(100,106):
dp[i+j] = max(dp[i] , dp[i+j])
print((dp[x])) | 14 | 14 | 237 | 233 | x = int(eval(input()))
dp = [0] * (x + 105 + 1)
dp[100] = 1
dp[101] = 1
dp[102] = 1
dp[103] = 1
dp[104] = 1
dp[105] = 1
for i in range(100, x - 105 + 6):
for j in range(100, 106):
dp[i + j] = max(dp[i], dp[i + j])
print((dp[x]))
| x = int(eval(input()))
dp = [0] * (x + 105 + 1)
dp[100] = 1
dp[101] = 1
dp[102] = 1
dp[103] = 1
dp[104] = 1
dp[105] = 1
for i in range(100, x + 1):
for j in range(100, 106):
dp[i + j] = max(dp[i], dp[i + j])
print((dp[x]))
| false | 0 | [
"-for i in range(100, x - 105 + 6):",
"+for i in range(100, x + 1):"
] | false | 0.065921 | 0.045847 | 1.437867 | [
"s981162359",
"s631128512"
] |
u489959379 | p03212 | python | s054242404 | s762740447 | 237 | 74 | 3,060 | 2,940 | Accepted | Accepted | 68.78 | from itertools import product
n = int(eval(input()))
res = 0
for pattern in product(["0", "3", "5", "7"], repeat=len(str(n))):
p = int("".join(pattern))
if "0" not in str(p):
if p <= n:
for i in ["3", "5", "7"]:
if i not in str(p):
break
else:
res += 1
print(res)
| n = int(eval(input()))
def dfs(s):
if int(s) > n:
return 0
for i in '753':
if s.count(i) == 0:
res = 0
break
else:
res = 1
for i in '753':
res += dfs(s + i)
return res
print((dfs('0')))
| 15 | 19 | 366 | 277 | from itertools import product
n = int(eval(input()))
res = 0
for pattern in product(["0", "3", "5", "7"], repeat=len(str(n))):
p = int("".join(pattern))
if "0" not in str(p):
if p <= n:
for i in ["3", "5", "7"]:
if i not in str(p):
break
else:
res += 1
print(res)
| n = int(eval(input()))
def dfs(s):
if int(s) > n:
return 0
for i in "753":
if s.count(i) == 0:
res = 0
break
else:
res = 1
for i in "753":
res += dfs(s + i)
return res
print((dfs("0")))
| false | 21.052632 | [
"-from itertools import product",
"+n = int(eval(input()))",
"-n = int(eval(input()))",
"-res = 0",
"-for pattern in product([\"0\", \"3\", \"5\", \"7\"], repeat=len(str(n))):",
"- p = int(\"\".join(pattern))",
"- if \"0\" not in str(p):",
"- if p <= n:",
"- for i in [\"3\", \"5\", \"7\"]:",
"- if i not in str(p):",
"- break",
"- else:",
"- res += 1",
"-print(res)",
"+",
"+def dfs(s):",
"+ if int(s) > n:",
"+ return 0",
"+ for i in \"753\":",
"+ if s.count(i) == 0:",
"+ res = 0",
"+ break",
"+ else:",
"+ res = 1",
"+ for i in \"753\":",
"+ res += dfs(s + i)",
"+ return res",
"+",
"+",
"+print((dfs(\"0\")))"
] | false | 0.079698 | 0.044585 | 1.787569 | [
"s054242404",
"s762740447"
] |
u047796752 | p02846 | python | s577094229 | s929176894 | 169 | 72 | 38,384 | 61,948 | Accepted | Accepted | 57.4 | T1, T2 = list(map(int, input().split()))
A1, A2 = list(map(int, input().split()))
B1, B2 = list(map(int, input().split()))
a = A1*T1-B1*T1
b = A2*T2-B2*T2
if a<0:
if b<0:
print((0))
elif b==0:
print((0))
elif b>0:
if a<-b:
print((0))
elif a==-b:
print('infinity')
else:
d = a+b
if a%d==0:
n = (-a)//d-1
print((2*n+2))
else:
n = (-a)//d
print((2*n+1))
elif a==0:
if b<0:
print((1))
elif b==0:
print('infinity')
elif b>0:
print((1))
elif a>0:
if b<0:
if a>-b:
print((0))
elif a==-b:
print('infinity')
else:
d = -a-b
if a%d==0:
n = a//d-1
print((2*n+2))
else:
n = a//d
print((2*n+1))
elif b==0:
print((0))
elif b>0:
print((0)) | T1, T2 = list(map(int, input().split()))
A1, A2 = list(map(int, input().split()))
B1, B2 = list(map(int, input().split()))
d1 = (A1-B1)*T1
d2 = (A2-B2)*T2
if d1*d2>0:
print((0))
exit()
if d1<0:
d1 *= -1
d2 *= -1
if d1+d2>0:
print((0))
exit()
if d1+d2==0:
print('infinity')
exit()
t = -d2-d1
if d1%t==0:
print((d1//t*2))
else:
print((d1//t*2+1)) | 51 | 28 | 1,046 | 391 | T1, T2 = list(map(int, input().split()))
A1, A2 = list(map(int, input().split()))
B1, B2 = list(map(int, input().split()))
a = A1 * T1 - B1 * T1
b = A2 * T2 - B2 * T2
if a < 0:
if b < 0:
print((0))
elif b == 0:
print((0))
elif b > 0:
if a < -b:
print((0))
elif a == -b:
print("infinity")
else:
d = a + b
if a % d == 0:
n = (-a) // d - 1
print((2 * n + 2))
else:
n = (-a) // d
print((2 * n + 1))
elif a == 0:
if b < 0:
print((1))
elif b == 0:
print("infinity")
elif b > 0:
print((1))
elif a > 0:
if b < 0:
if a > -b:
print((0))
elif a == -b:
print("infinity")
else:
d = -a - b
if a % d == 0:
n = a // d - 1
print((2 * n + 2))
else:
n = a // d
print((2 * n + 1))
elif b == 0:
print((0))
elif b > 0:
print((0))
| T1, T2 = list(map(int, input().split()))
A1, A2 = list(map(int, input().split()))
B1, B2 = list(map(int, input().split()))
d1 = (A1 - B1) * T1
d2 = (A2 - B2) * T2
if d1 * d2 > 0:
print((0))
exit()
if d1 < 0:
d1 *= -1
d2 *= -1
if d1 + d2 > 0:
print((0))
exit()
if d1 + d2 == 0:
print("infinity")
exit()
t = -d2 - d1
if d1 % t == 0:
print((d1 // t * 2))
else:
print((d1 // t * 2 + 1))
| false | 45.098039 | [
"-a = A1 * T1 - B1 * T1",
"-b = A2 * T2 - B2 * T2",
"-if a < 0:",
"- if b < 0:",
"- print((0))",
"- elif b == 0:",
"- print((0))",
"- elif b > 0:",
"- if a < -b:",
"- print((0))",
"- elif a == -b:",
"- print(\"infinity\")",
"- else:",
"- d = a + b",
"- if a % d == 0:",
"- n = (-a) // d - 1",
"- print((2 * n + 2))",
"- else:",
"- n = (-a) // d",
"- print((2 * n + 1))",
"-elif a == 0:",
"- if b < 0:",
"- print((1))",
"- elif b == 0:",
"- print(\"infinity\")",
"- elif b > 0:",
"- print((1))",
"-elif a > 0:",
"- if b < 0:",
"- if a > -b:",
"- print((0))",
"- elif a == -b:",
"- print(\"infinity\")",
"- else:",
"- d = -a - b",
"- if a % d == 0:",
"- n = a // d - 1",
"- print((2 * n + 2))",
"- else:",
"- n = a // d",
"- print((2 * n + 1))",
"- elif b == 0:",
"- print((0))",
"- elif b > 0:",
"- print((0))",
"+d1 = (A1 - B1) * T1",
"+d2 = (A2 - B2) * T2",
"+if d1 * d2 > 0:",
"+ print((0))",
"+ exit()",
"+if d1 < 0:",
"+ d1 *= -1",
"+ d2 *= -1",
"+if d1 + d2 > 0:",
"+ print((0))",
"+ exit()",
"+if d1 + d2 == 0:",
"+ print(\"infinity\")",
"+ exit()",
"+t = -d2 - d1",
"+if d1 % t == 0:",
"+ print((d1 // t * 2))",
"+else:",
"+ print((d1 // t * 2 + 1))"
] | false | 0.043046 | 0.03632 | 1.185171 | [
"s577094229",
"s929176894"
] |
u222668979 | p02733 | python | s846818730 | s985964121 | 393 | 310 | 76,668 | 76,576 | Accepted | Accepted | 21.12 | from itertools import product
def makelist(BIT):
LIST, tmp = [], s[0]
for si, bi in zip(s[1:], BIT):
if bi == 1:
LIST.append(tmp)
tmp = si
elif bi == 0:
tmp = [t + sij for t, sij in zip(tmp, si)]
else:
LIST.append(tmp)
return LIST
def solve(LIST):
CNT, tmp = 0, [li[0] for li in LIST]
if any(num > k for num in tmp):
return h * w
for j in range(1, w):
cal = [t + li[j] for t, li in zip(tmp, LIST)]
if any(num > k for num in cal):
CNT += 1
tmp = [li[j] for li in LIST]
else:
tmp = cal[:]
return CNT
h, w, k = list(map(int, input().split()))
s = [[int(sij) for sij in eval(input())] for _ in range(h)]
ans = h * w
for bit in product([0, 1], repeat=(h - 1)):
numlist = makelist(bit)
ans = min(ans, solve(numlist) + sum(bit))
print(ans)
| from itertools import product
def makelist(BIT):
LIST, tmp = [], s[0]
for si, bi in zip(s[1:], BIT):
if bi == 1:
LIST.append(tmp)
tmp = si
elif bi == 0:
tmp = [t + sij for t, sij in zip(tmp, si)]
else:
LIST.append(tmp)
return LIST
def solve(LIST):
COST, cnt = 0, [li[0] for li in LIST]
if any(num > k for num in cnt):
return h * w
for j in range(1, w):
tmp = [t + li[j] for t, li in zip(cnt, LIST)]
if any(num > k for num in tmp):
COST += 1
cnt = [li[j] for li in LIST]
else:
cnt = tmp[:]
return COST
h, w, k = list(map(int, input().split()))
s = [[int(sij) for sij in eval(input())] for _ in range(h)]
ans = h * w
for bit in product([0, 1], repeat=(h - 1)):
numlist = makelist(bit)
ans = min(ans, solve(numlist) + sum(bit))
print(ans)
| 38 | 38 | 933 | 936 | from itertools import product
def makelist(BIT):
LIST, tmp = [], s[0]
for si, bi in zip(s[1:], BIT):
if bi == 1:
LIST.append(tmp)
tmp = si
elif bi == 0:
tmp = [t + sij for t, sij in zip(tmp, si)]
else:
LIST.append(tmp)
return LIST
def solve(LIST):
CNT, tmp = 0, [li[0] for li in LIST]
if any(num > k for num in tmp):
return h * w
for j in range(1, w):
cal = [t + li[j] for t, li in zip(tmp, LIST)]
if any(num > k for num in cal):
CNT += 1
tmp = [li[j] for li in LIST]
else:
tmp = cal[:]
return CNT
h, w, k = list(map(int, input().split()))
s = [[int(sij) for sij in eval(input())] for _ in range(h)]
ans = h * w
for bit in product([0, 1], repeat=(h - 1)):
numlist = makelist(bit)
ans = min(ans, solve(numlist) + sum(bit))
print(ans)
| from itertools import product
def makelist(BIT):
LIST, tmp = [], s[0]
for si, bi in zip(s[1:], BIT):
if bi == 1:
LIST.append(tmp)
tmp = si
elif bi == 0:
tmp = [t + sij for t, sij in zip(tmp, si)]
else:
LIST.append(tmp)
return LIST
def solve(LIST):
COST, cnt = 0, [li[0] for li in LIST]
if any(num > k for num in cnt):
return h * w
for j in range(1, w):
tmp = [t + li[j] for t, li in zip(cnt, LIST)]
if any(num > k for num in tmp):
COST += 1
cnt = [li[j] for li in LIST]
else:
cnt = tmp[:]
return COST
h, w, k = list(map(int, input().split()))
s = [[int(sij) for sij in eval(input())] for _ in range(h)]
ans = h * w
for bit in product([0, 1], repeat=(h - 1)):
numlist = makelist(bit)
ans = min(ans, solve(numlist) + sum(bit))
print(ans)
| false | 0 | [
"- CNT, tmp = 0, [li[0] for li in LIST]",
"- if any(num > k for num in tmp):",
"+ COST, cnt = 0, [li[0] for li in LIST]",
"+ if any(num > k for num in cnt):",
"- cal = [t + li[j] for t, li in zip(tmp, LIST)]",
"- if any(num > k for num in cal):",
"- CNT += 1",
"- tmp = [li[j] for li in LIST]",
"+ tmp = [t + li[j] for t, li in zip(cnt, LIST)]",
"+ if any(num > k for num in tmp):",
"+ COST += 1",
"+ cnt = [li[j] for li in LIST]",
"- tmp = cal[:]",
"- return CNT",
"+ cnt = tmp[:]",
"+ return COST"
] | false | 0.043223 | 0.044136 | 0.979332 | [
"s846818730",
"s985964121"
] |
u924691798 | p02678 | python | s484779665 | s114800271 | 977 | 819 | 114,468 | 39,936 | Accepted | Accepted | 16.17 | # Graph
import heapq
INF = 10**18
def dijkstra(start, G):
done = [False]*(len(G))
dist = [INF]*(len(G))
dist[start] = 0
fr = [0]*N
h = []
heapq.heappush(h, [0, start])
while h:
_, cur = heapq.heappop(h)
if done[cur]: continue
done[cur] = True
for to, cost in G[cur]:
if dist[cur]+cost < dist[to]:
dist[to] = dist[cur]+cost
fr[to] = cur
heapq.heappush(h, [dist[to], to])
return fr, dist
N, M = list(map(int, input().split()))
G = [[] for i in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
G[a].append((b, 1))
G[b].append((a, 1))
ans, dis = dijkstra(0, G)
print("Yes")
for i in range(1, N):
print((ans[i]+1))
| from collections import deque
N, M = list(map(int, input().split()))
G = [[] for i in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
G[a].append(b)
G[b].append(a)
q = deque()
done = [-1]*N
def bfs(fr, now):
done[now] = fr
for to in G[now]:
if done[to] != -1: continue
q.appendleft((now, to))
q.appendleft((0, 0))
while q:
fr, now = q.pop()
if done[now] == -1:
bfs(fr, now)
print("Yes")
for fr in done[1:]:
print((fr+1))
| 34 | 25 | 812 | 530 | # Graph
import heapq
INF = 10**18
def dijkstra(start, G):
done = [False] * (len(G))
dist = [INF] * (len(G))
dist[start] = 0
fr = [0] * N
h = []
heapq.heappush(h, [0, start])
while h:
_, cur = heapq.heappop(h)
if done[cur]:
continue
done[cur] = True
for to, cost in G[cur]:
if dist[cur] + cost < dist[to]:
dist[to] = dist[cur] + cost
fr[to] = cur
heapq.heappush(h, [dist[to], to])
return fr, dist
N, M = list(map(int, input().split()))
G = [[] for i in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
G[a].append((b, 1))
G[b].append((a, 1))
ans, dis = dijkstra(0, G)
print("Yes")
for i in range(1, N):
print((ans[i] + 1))
| from collections import deque
N, M = list(map(int, input().split()))
G = [[] for i in range(N)]
for i in range(M):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
G[a].append(b)
G[b].append(a)
q = deque()
done = [-1] * N
def bfs(fr, now):
done[now] = fr
for to in G[now]:
if done[to] != -1:
continue
q.appendleft((now, to))
q.appendleft((0, 0))
while q:
fr, now = q.pop()
if done[now] == -1:
bfs(fr, now)
print("Yes")
for fr in done[1:]:
print((fr + 1))
| false | 26.470588 | [
"-# Graph",
"-import heapq",
"-",
"-INF = 10**18",
"-",
"-",
"-def dijkstra(start, G):",
"- done = [False] * (len(G))",
"- dist = [INF] * (len(G))",
"- dist[start] = 0",
"- fr = [0] * N",
"- h = []",
"- heapq.heappush(h, [0, start])",
"- while h:",
"- _, cur = heapq.heappop(h)",
"- if done[cur]:",
"- continue",
"- done[cur] = True",
"- for to, cost in G[cur]:",
"- if dist[cur] + cost < dist[to]:",
"- dist[to] = dist[cur] + cost",
"- fr[to] = cur",
"- heapq.heappush(h, [dist[to], to])",
"- return fr, dist",
"-",
"+from collections import deque",
"- G[a].append((b, 1))",
"- G[b].append((a, 1))",
"-ans, dis = dijkstra(0, G)",
"+ G[a].append(b)",
"+ G[b].append(a)",
"+q = deque()",
"+done = [-1] * N",
"+",
"+",
"+def bfs(fr, now):",
"+ done[now] = fr",
"+ for to in G[now]:",
"+ if done[to] != -1:",
"+ continue",
"+ q.appendleft((now, to))",
"+",
"+",
"+q.appendleft((0, 0))",
"+while q:",
"+ fr, now = q.pop()",
"+ if done[now] == -1:",
"+ bfs(fr, now)",
"-for i in range(1, N):",
"- print((ans[i] + 1))",
"+for fr in done[1:]:",
"+ print((fr + 1))"
] | false | 0.035649 | 0.038886 | 0.916756 | [
"s484779665",
"s114800271"
] |
u723444827 | p02898 | python | s964324204 | s738757608 | 120 | 104 | 12,000 | 13,568 | Accepted | Accepted | 13.33 | import heapq
N , K = list(map(int,input().split()))
h_list = list(map(int,input().split()))
ans = 0
heap = []
for i in range(N):
heapq.heappush(heap, h_list[i]*(-1))
for i in range(N):
if (heapq.heappop(heap)*(-1) < K):
break
else:
ans += 1
print(ans) | import heapq
def minus(x):
y = int(x)
return y*(-1)
N , K = list(map(int,input().split()))
h_list = list(map(minus,input().split()))
ans = 0
heapq.heapify(h_list)
for i in range(N):
if (heapq.heappop(h_list)*(-1) < K):
break
else:
ans += 1
print(ans) | 19 | 20 | 297 | 301 | import heapq
N, K = list(map(int, input().split()))
h_list = list(map(int, input().split()))
ans = 0
heap = []
for i in range(N):
heapq.heappush(heap, h_list[i] * (-1))
for i in range(N):
if heapq.heappop(heap) * (-1) < K:
break
else:
ans += 1
print(ans)
| import heapq
def minus(x):
y = int(x)
return y * (-1)
N, K = list(map(int, input().split()))
h_list = list(map(minus, input().split()))
ans = 0
heapq.heapify(h_list)
for i in range(N):
if heapq.heappop(h_list) * (-1) < K:
break
else:
ans += 1
print(ans)
| false | 5 | [
"+",
"+def minus(x):",
"+ y = int(x)",
"+ return y * (-1)",
"+",
"+",
"-h_list = list(map(int, input().split()))",
"+h_list = list(map(minus, input().split()))",
"-heap = []",
"+heapq.heapify(h_list)",
"- heapq.heappush(heap, h_list[i] * (-1))",
"-for i in range(N):",
"- if heapq.heappop(heap) * (-1) < K:",
"+ if heapq.heappop(h_list) * (-1) < K:"
] | false | 0.03924 | 0.044784 | 0.876223 | [
"s964324204",
"s738757608"
] |
u072053884 | p02266 | python | s661153221 | s840224075 | 80 | 60 | 8,368 | 8,472 | Accepted | Accepted | 25 | import collections
import sys
S1 = collections.deque()
S2 = collections.deque()
S3 = collections.deque()
for i, j in enumerate(sys.stdin.readline()):
if j == '\\':
S1.append(i)
elif j == '/':
if S1:
left_edge = S1.pop()
new_puddle = i - left_edge
while S2 and (S2[-1] > left_edge):
S2.pop()
new_puddle += S3.pop()
S2.append(left_edge)
S3.append(new_puddle)
else:
pass
print((sum(S3)))
print((len(S3), *S3)) | import collections
import sys
S1 = collections.deque()
S2 = collections.deque()
for i, j in enumerate(sys.stdin.readline()):
if j == '\\':
S1.append(i)
elif j == '/':
if S1:
left_edge = S1.pop()
new_puddle = i - left_edge
while S2 and (S2[-1][0] > left_edge):
new_puddle += S2[-1][1]
S2.pop()
S2.append((left_edge, new_puddle))
else:
pass
print((sum(j for i, j in S2)))
print((len(S2), *(j for i, j in S2))) | 26 | 24 | 568 | 555 | import collections
import sys
S1 = collections.deque()
S2 = collections.deque()
S3 = collections.deque()
for i, j in enumerate(sys.stdin.readline()):
if j == "\\":
S1.append(i)
elif j == "/":
if S1:
left_edge = S1.pop()
new_puddle = i - left_edge
while S2 and (S2[-1] > left_edge):
S2.pop()
new_puddle += S3.pop()
S2.append(left_edge)
S3.append(new_puddle)
else:
pass
print((sum(S3)))
print((len(S3), *S3))
| import collections
import sys
S1 = collections.deque()
S2 = collections.deque()
for i, j in enumerate(sys.stdin.readline()):
if j == "\\":
S1.append(i)
elif j == "/":
if S1:
left_edge = S1.pop()
new_puddle = i - left_edge
while S2 and (S2[-1][0] > left_edge):
new_puddle += S2[-1][1]
S2.pop()
S2.append((left_edge, new_puddle))
else:
pass
print((sum(j for i, j in S2)))
print((len(S2), *(j for i, j in S2)))
| false | 7.692308 | [
"-S3 = collections.deque()",
"- while S2 and (S2[-1] > left_edge):",
"+ while S2 and (S2[-1][0] > left_edge):",
"+ new_puddle += S2[-1][1]",
"- new_puddle += S3.pop()",
"- S2.append(left_edge)",
"- S3.append(new_puddle)",
"+ S2.append((left_edge, new_puddle))",
"-print((sum(S3)))",
"-print((len(S3), *S3))",
"+print((sum(j for i, j in S2)))",
"+print((len(S2), *(j for i, j in S2)))"
] | false | 0.037376 | 0.036597 | 1.021301 | [
"s661153221",
"s840224075"
] |
u272525952 | p02572 | python | s632738810 | s768764399 | 129 | 110 | 94,136 | 105,224 | Accepted | Accepted | 14.73 | n=int(eval(input()))
l=list(map(int,input().split()))
suml=sum(l)
num=0
for i in range(n-1):
suml-=l[i]
num+=(l[i]*suml)%(10**9+7)
print((num%(10**9+7))) | n=int(eval(input()))
l=list(map(int,input().split()))
suml=sum(l)
num=0
for i in range(n):
num+=l[i]**2
print(((suml**2-num)//2%(10**9+7)))
| 8 | 7 | 160 | 142 | n = int(eval(input()))
l = list(map(int, input().split()))
suml = sum(l)
num = 0
for i in range(n - 1):
suml -= l[i]
num += (l[i] * suml) % (10**9 + 7)
print((num % (10**9 + 7)))
| n = int(eval(input()))
l = list(map(int, input().split()))
suml = sum(l)
num = 0
for i in range(n):
num += l[i] ** 2
print(((suml**2 - num) // 2 % (10**9 + 7)))
| false | 12.5 | [
"-for i in range(n - 1):",
"- suml -= l[i]",
"- num += (l[i] * suml) % (10**9 + 7)",
"-print((num % (10**9 + 7)))",
"+for i in range(n):",
"+ num += l[i] ** 2",
"+print(((suml**2 - num) // 2 % (10**9 + 7)))"
] | false | 0.041322 | 0.041735 | 0.990106 | [
"s632738810",
"s768764399"
] |
u952467214 | p03160 | python | s992648497 | s105517406 | 143 | 132 | 13,928 | 13,708 | Accepted | Accepted | 7.69 | N = int(eval(input()))
h = [int(i) for i in input().split()]
dp=[0 for i in range(N)]
dp[1] = abs(h[1] - h[0])
for i in range(N-2):
dp[i+2]=min(dp[i+1]+ abs(h[i+2]-h[i+1]), dp[i]+ abs(h[i+2]-h[i]))
print((dp[N-1]))
| N = int(eval(input()))
h = [int(i) for i in input().split()]
dp = [0]*N
dp[1] = abs(h[1] - h[0])
for i in range(N-2):
dp[i+2]=min(dp[i+1]+ abs(h[i+2]-h[i+1]), dp[i]+ abs(h[i+2]-h[i]))
print((dp[N-1])) | 9 | 9 | 219 | 204 | N = int(eval(input()))
h = [int(i) for i in input().split()]
dp = [0 for i in range(N)]
dp[1] = abs(h[1] - h[0])
for i in range(N - 2):
dp[i + 2] = min(dp[i + 1] + abs(h[i + 2] - h[i + 1]), dp[i] + abs(h[i + 2] - h[i]))
print((dp[N - 1]))
| N = int(eval(input()))
h = [int(i) for i in input().split()]
dp = [0] * N
dp[1] = abs(h[1] - h[0])
for i in range(N - 2):
dp[i + 2] = min(dp[i + 1] + abs(h[i + 2] - h[i + 1]), dp[i] + abs(h[i + 2] - h[i]))
print((dp[N - 1]))
| false | 0 | [
"-dp = [0 for i in range(N)]",
"+dp = [0] * N"
] | false | 0.039689 | 0.039278 | 1.010468 | [
"s992648497",
"s105517406"
] |
u567380442 | p02393 | python | s301626026 | s872739654 | 40 | 30 | 6,724 | 6,724 | Accepted | Accepted | 25 | list = [int(a) for a in input().split()]
list.sort()
print((*list)) | print((*sorted(map(int, input().split())))) | 3 | 1 | 67 | 41 | list = [int(a) for a in input().split()]
list.sort()
print((*list))
| print((*sorted(map(int, input().split()))))
| false | 66.666667 | [
"-list = [int(a) for a in input().split()]",
"-list.sort()",
"-print((*list))",
"+print((*sorted(map(int, input().split()))))"
] | false | 0.04757 | 0.126683 | 0.375503 | [
"s301626026",
"s872739654"
] |
u620480037 | p03371 | python | s019434257 | s972935471 | 120 | 66 | 3,064 | 65,836 | Accepted | Accepted | 45 | A,B,C,X,Y=list(map(int,input().split()))
ans=10**10
for i in range(max(X,Y)+1):
cnt=0
cnt+=C*2*i
x=X-i
y=Y-i
cnt+=max(0,x*A)
cnt+=max(0,y*B)
if ans>cnt:
ans=cnt
print(ans) | A,B,C,X,Y=list(map(int,input().split()))
ans=10**12
for i in range(max(X,Y)+1):
cnt=0
cnt+=i*C*2
cnt+=max(0,X-i)*A
cnt+=max(0,Y-i)*B
ans=min(ans,cnt)
print(ans) | 13 | 10 | 214 | 184 | A, B, C, X, Y = list(map(int, input().split()))
ans = 10**10
for i in range(max(X, Y) + 1):
cnt = 0
cnt += C * 2 * i
x = X - i
y = Y - i
cnt += max(0, x * A)
cnt += max(0, y * B)
if ans > cnt:
ans = cnt
print(ans)
| A, B, C, X, Y = list(map(int, input().split()))
ans = 10**12
for i in range(max(X, Y) + 1):
cnt = 0
cnt += i * C * 2
cnt += max(0, X - i) * A
cnt += max(0, Y - i) * B
ans = min(ans, cnt)
print(ans)
| false | 23.076923 | [
"-ans = 10**10",
"+ans = 10**12",
"- cnt += C * 2 * i",
"- x = X - i",
"- y = Y - i",
"- cnt += max(0, x * A)",
"- cnt += max(0, y * B)",
"- if ans > cnt:",
"- ans = cnt",
"+ cnt += i * C * 2",
"+ cnt += max(0, X - i) * A",
"+ cnt += max(0, Y - i) * B",
"+ ans = min(ans, cnt)"
] | false | 0.055802 | 0.056666 | 0.984749 | [
"s019434257",
"s972935471"
] |
u809108154 | p02787 | python | s936734893 | s951657726 | 515 | 429 | 12,516 | 12,500 | Accepted | Accepted | 16.7 | import numpy as np
h, n = list(map(int, input().split()))
ab = np.array([tuple(map(int, input().split())) for _ in range(n)])
dp = np.zeros(h + 1, dtype="int")
for i in range(1, h+1):
dp[i] = np.min(dp[np.maximum(i - ab[:, 0], 0)] + ab[:, 1])
print((dp[-1])) | import numpy as np
h, n = list(map(int, input().split()))
a = []
b = []
for _ in range(n):
ai, bi = list(map(int, input().split()))
a.append(ai)
b.append(bi)
a = np.array(a)
b = np.array(b)
dp = np.zeros(h+1, dtype=np.int)
for c in range(1, h+1):
dp[c] = np.min(dp[np.maximum(0, c-a)] + b)
print((dp[-1])) | 7 | 15 | 264 | 315 | import numpy as np
h, n = list(map(int, input().split()))
ab = np.array([tuple(map(int, input().split())) for _ in range(n)])
dp = np.zeros(h + 1, dtype="int")
for i in range(1, h + 1):
dp[i] = np.min(dp[np.maximum(i - ab[:, 0], 0)] + ab[:, 1])
print((dp[-1]))
| import numpy as np
h, n = list(map(int, input().split()))
a = []
b = []
for _ in range(n):
ai, bi = list(map(int, input().split()))
a.append(ai)
b.append(bi)
a = np.array(a)
b = np.array(b)
dp = np.zeros(h + 1, dtype=np.int)
for c in range(1, h + 1):
dp[c] = np.min(dp[np.maximum(0, c - a)] + b)
print((dp[-1]))
| false | 53.333333 | [
"-ab = np.array([tuple(map(int, input().split())) for _ in range(n)])",
"-dp = np.zeros(h + 1, dtype=\"int\")",
"-for i in range(1, h + 1):",
"- dp[i] = np.min(dp[np.maximum(i - ab[:, 0], 0)] + ab[:, 1])",
"+a = []",
"+b = []",
"+for _ in range(n):",
"+ ai, bi = list(map(int, input().split()))",
"+ a.append(ai)",
"+ b.append(bi)",
"+a = np.array(a)",
"+b = np.array(b)",
"+dp = np.zeros(h + 1, dtype=np.int)",
"+for c in range(1, h + 1):",
"+ dp[c] = np.min(dp[np.maximum(0, c - a)] + b)"
] | false | 0.339967 | 0.47894 | 0.709833 | [
"s936734893",
"s951657726"
] |
u392319141 | p03088 | python | s549681948 | s430672223 | 593 | 87 | 11,244 | 5,568 | Accepted | Accepted | 85.33 | from functools import lru_cache
import sys
sys.setrecursionlimit(10 ** 7)
N = int(eval(input()))
MOD = 10**9 + 7
def isOk(T):
for i in range(4):
t = list(T)
if i >= 1:
t[i - 1], t[i] = t[i], t[i - 1]
if 'AGC' in ''.join(t):
return False
return True
@lru_cache(maxsize=None)
def search(n, prev):
if n == 0:
return 1
ret = 0
for s in ['A', 'G', 'C', 'T']:
t = (prev + s)[1:]
if isOk(t):
ret += search(n - 1, t)
ret %= MOD
return ret
print((search(N, 'ZZZZ'))) | from functools import lru_cache
import sys
sys.setrecursionlimit(10**7)
N = int(eval(input()))
MOD = 10**9 + 7
S = ['A', 'G', 'C', 'T']
M = set(['AGC', 'GAC', 'ACG'])
for s in S:
M.add(s + 'AGC')
M.add(s + 'GAC')
M.add(s + 'ACG')
M.add('A' + s + 'GC')
M.add('AG' + s + 'C')
@lru_cache(maxsize=None)
def search(prev, length):
if length >= N:
return 1
ret = 0
for s in S:
T = prev + s
if not T in M:
T = T[:: -1][: 3][:: -1]
ret += search(T, length + 1)
return ret % MOD
ans = search('', 0)
print(ans)
| 31 | 32 | 605 | 615 | from functools import lru_cache
import sys
sys.setrecursionlimit(10**7)
N = int(eval(input()))
MOD = 10**9 + 7
def isOk(T):
for i in range(4):
t = list(T)
if i >= 1:
t[i - 1], t[i] = t[i], t[i - 1]
if "AGC" in "".join(t):
return False
return True
@lru_cache(maxsize=None)
def search(n, prev):
if n == 0:
return 1
ret = 0
for s in ["A", "G", "C", "T"]:
t = (prev + s)[1:]
if isOk(t):
ret += search(n - 1, t)
ret %= MOD
return ret
print((search(N, "ZZZZ")))
| from functools import lru_cache
import sys
sys.setrecursionlimit(10**7)
N = int(eval(input()))
MOD = 10**9 + 7
S = ["A", "G", "C", "T"]
M = set(["AGC", "GAC", "ACG"])
for s in S:
M.add(s + "AGC")
M.add(s + "GAC")
M.add(s + "ACG")
M.add("A" + s + "GC")
M.add("AG" + s + "C")
@lru_cache(maxsize=None)
def search(prev, length):
if length >= N:
return 1
ret = 0
for s in S:
T = prev + s
if not T in M:
T = T[::-1][:3][::-1]
ret += search(T, length + 1)
return ret % MOD
ans = search("", 0)
print(ans)
| false | 3.125 | [
"-",
"-",
"-def isOk(T):",
"- for i in range(4):",
"- t = list(T)",
"- if i >= 1:",
"- t[i - 1], t[i] = t[i], t[i - 1]",
"- if \"AGC\" in \"\".join(t):",
"- return False",
"- return True",
"+S = [\"A\", \"G\", \"C\", \"T\"]",
"+M = set([\"AGC\", \"GAC\", \"ACG\"])",
"+for s in S:",
"+ M.add(s + \"AGC\")",
"+ M.add(s + \"GAC\")",
"+ M.add(s + \"ACG\")",
"+ M.add(\"A\" + s + \"GC\")",
"+ M.add(\"AG\" + s + \"C\")",
"-def search(n, prev):",
"- if n == 0:",
"+def search(prev, length):",
"+ if length >= N:",
"- for s in [\"A\", \"G\", \"C\", \"T\"]:",
"- t = (prev + s)[1:]",
"- if isOk(t):",
"- ret += search(n - 1, t)",
"- ret %= MOD",
"- return ret",
"+ for s in S:",
"+ T = prev + s",
"+ if not T in M:",
"+ T = T[::-1][:3][::-1]",
"+ ret += search(T, length + 1)",
"+ return ret % MOD",
"-print((search(N, \"ZZZZ\")))",
"+ans = search(\"\", 0)",
"+print(ans)"
] | false | 0.253089 | 0.055826 | 4.533564 | [
"s549681948",
"s430672223"
] |
u835924161 | p02700 | python | s315007329 | s235247015 | 24 | 21 | 9,168 | 9,172 | Accepted | Accepted | 12.5 | a,b,c,d=list(map(int,input().split()))
while True:
c-=b
if c<=0:
print("Yes")
exit()
a-=d
if a<=0:
print("No")
exit() | a,b,c,d=list(map(int,input().split()))
taka=int((c+b-1)/b)
aoki=int((a+d-1)/d)
if taka<=aoki:
print("Yes")
else:
print("No") | 10 | 8 | 168 | 134 | a, b, c, d = list(map(int, input().split()))
while True:
c -= b
if c <= 0:
print("Yes")
exit()
a -= d
if a <= 0:
print("No")
exit()
| a, b, c, d = list(map(int, input().split()))
taka = int((c + b - 1) / b)
aoki = int((a + d - 1) / d)
if taka <= aoki:
print("Yes")
else:
print("No")
| false | 20 | [
"-while True:",
"- c -= b",
"- if c <= 0:",
"- print(\"Yes\")",
"- exit()",
"- a -= d",
"- if a <= 0:",
"- print(\"No\")",
"- exit()",
"+taka = int((c + b - 1) / b)",
"+aoki = int((a + d - 1) / d)",
"+if taka <= aoki:",
"+ print(\"Yes\")",
"+else:",
"+ print(\"No\")"
] | false | 0.03767 | 0.036864 | 1.02187 | [
"s315007329",
"s235247015"
] |
u875291233 | p03558 | python | s341813665 | s199587096 | 420 | 276 | 38,272 | 38,508 | Accepted | Accepted | 34.29 | # coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意
k = int(eval(input()))
g = [[] for _ in range(k)]
for i in range(k):
g[i].append(((i+1)%k,1))
if i: g[i].append((10*i%k,0))
#print(g)
"""
from collections import deque
q = deque([1])
INF = float("inf")
res = [INF]*k
res[1] = 1
while q and res[0] == INF:
# print(q)
v = q.popleft()
for c,d in g[v]:
if res[c] <= res[v] + d: continue
res[c] = res[v] + d
if d: q.append(c)
else: q.appendleft(c)
#print(res)
#print(used)
print(res[0])
"""
from heapq import *
def dijkstra(g,start):
n = len(g)
dist = [float("inf")]*(n) #startからの最短距離
pending = n-1 #未確定の点の個数
dist[start] = 0
q = [(0,start)] #(そこまでの距離、点)
while q and pending:
c,v = heappop(q)
if dist[v] < c: continue
pending -= 1
for to, cost in g[v]:
if dist[v] + cost < dist[to]:
dist[to] = dist[v] + cost
heappush(q, (dist[to], to))
return dist
dist = dijkstra(g,1)
print((dist[0]+1))
| # coding: utf-8
# Your code here!
"""
01-BFS
辺の重みが0 or 1 のとき、dequeを使ってdijkstraを高速化できる
"""
from collections import deque
def bfs01(g,start):
n = len(g)
res = [float("inf")]*n #startからの最短距離
res[start] = 0
pending = n-1 #未確定の点の個数
q = deque([(0,start)]) #(そこまでの距離、点)
while q and pending:
dv,v = q.popleft()
if res[v] < dv: continue
pending -= 1
#if v==goal: break
for to,cost in g[v]:
if dv + cost < res[to]:
res[to] = dv + cost
if cost: q.append((res[to],to))
else: q.appendleft((res[to],to))
return res
######################################################################
#ARC084 small multiple
#
######################################################################
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意
k = int(eval(input()))
g = [[] for _ in range(k)]
for i in range(k):
g[i].append(((i+1)%k,1))
g[i].append((10*i%k,0))
res = bfs01(g,1)
print((res[0]+1))
| 58 | 44 | 1,164 | 1,081 | # coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline # 文字列入力のときは注意
k = int(eval(input()))
g = [[] for _ in range(k)]
for i in range(k):
g[i].append(((i + 1) % k, 1))
if i:
g[i].append((10 * i % k, 0))
# print(g)
"""
from collections import deque
q = deque([1])
INF = float("inf")
res = [INF]*k
res[1] = 1
while q and res[0] == INF:
# print(q)
v = q.popleft()
for c,d in g[v]:
if res[c] <= res[v] + d: continue
res[c] = res[v] + d
if d: q.append(c)
else: q.appendleft(c)
#print(res)
#print(used)
print(res[0])
"""
from heapq import *
def dijkstra(g, start):
n = len(g)
dist = [float("inf")] * (n) # startからの最短距離
pending = n - 1 # 未確定の点の個数
dist[start] = 0
q = [(0, start)] # (そこまでの距離、点)
while q and pending:
c, v = heappop(q)
if dist[v] < c:
continue
pending -= 1
for to, cost in g[v]:
if dist[v] + cost < dist[to]:
dist[to] = dist[v] + cost
heappush(q, (dist[to], to))
return dist
dist = dijkstra(g, 1)
print((dist[0] + 1))
| # coding: utf-8
# Your code here!
"""
01-BFS
辺の重みが0 or 1 のとき、dequeを使ってdijkstraを高速化できる
"""
from collections import deque
def bfs01(g, start):
n = len(g)
res = [float("inf")] * n # startからの最短距離
res[start] = 0
pending = n - 1 # 未確定の点の個数
q = deque([(0, start)]) # (そこまでの距離、点)
while q and pending:
dv, v = q.popleft()
if res[v] < dv:
continue
pending -= 1
# if v==goal: break
for to, cost in g[v]:
if dv + cost < res[to]:
res[to] = dv + cost
if cost:
q.append((res[to], to))
else:
q.appendleft((res[to], to))
return res
######################################################################
# ARC084 small multiple
#
######################################################################
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline # 文字列入力のときは注意
k = int(eval(input()))
g = [[] for _ in range(k)]
for i in range(k):
g[i].append(((i + 1) % k, 1))
g[i].append((10 * i % k, 0))
res = bfs01(g, 1)
print((res[0] + 1))
| false | 24.137931 | [
"+\"\"\"",
"+01-BFS",
"+辺の重みが0 or 1 のとき、dequeを使ってdijkstraを高速化できる",
"+\"\"\"",
"+from collections import deque",
"+",
"+",
"+def bfs01(g, start):",
"+ n = len(g)",
"+ res = [float(\"inf\")] * n # startからの最短距離",
"+ res[start] = 0",
"+ pending = n - 1 # 未確定の点の個数",
"+ q = deque([(0, start)]) # (そこまでの距離、点)",
"+ while q and pending:",
"+ dv, v = q.popleft()",
"+ if res[v] < dv:",
"+ continue",
"+ pending -= 1",
"+ # if v==goal: break",
"+ for to, cost in g[v]:",
"+ if dv + cost < res[to]:",
"+ res[to] = dv + cost",
"+ if cost:",
"+ q.append((res[to], to))",
"+ else:",
"+ q.appendleft((res[to], to))",
"+ return res",
"+",
"+",
"+######################################################################",
"+# ARC084 small multiple",
"+#",
"+######################################################################",
"- if i:",
"- g[i].append((10 * i % k, 0))",
"-# print(g)",
"-\"\"\"",
"-from collections import deque",
"-q = deque([1])",
"-INF = float(\"inf\")",
"-res = [INF]*k",
"-res[1] = 1",
"-while q and res[0] == INF:",
"-# print(q)",
"- v = q.popleft()",
"- for c,d in g[v]:",
"- if res[c] <= res[v] + d: continue",
"- res[c] = res[v] + d",
"- if d: q.append(c)",
"- else: q.appendleft(c)",
"-#print(res)",
"-#print(used)",
"-print(res[0])",
"-\"\"\"",
"-from heapq import *",
"-",
"-",
"-def dijkstra(g, start):",
"- n = len(g)",
"- dist = [float(\"inf\")] * (n) # startからの最短距離",
"- pending = n - 1 # 未確定の点の個数",
"- dist[start] = 0",
"- q = [(0, start)] # (そこまでの距離、点)",
"- while q and pending:",
"- c, v = heappop(q)",
"- if dist[v] < c:",
"- continue",
"- pending -= 1",
"- for to, cost in g[v]:",
"- if dist[v] + cost < dist[to]:",
"- dist[to] = dist[v] + cost",
"- heappush(q, (dist[to], to))",
"- return dist",
"-",
"-",
"-dist = dijkstra(g, 1)",
"-print((dist[0] + 1))",
"+ g[i].append((10 * i % k, 0))",
"+res = bfs01(g, 1)",
"+print((res[0] + 1))"
] | false | 0.10814 | 0.083338 | 1.297605 | [
"s341813665",
"s199587096"
] |
u573754721 | p03037 | python | s618724454 | s195476146 | 385 | 313 | 27,332 | 3,060 | Accepted | Accepted | 18.7 | n,m=list(map(int,input().split()))
L=[list(map(int,input().split())) for _ in range(m)]
lm=0
rm=float('inf')
for i in range(m):
lm=max(L[i][0],lm)
rm=min(L[i][1],rm)
print((max(0,rm-lm+1))) | n,m=list(map(int,input().split()))
ml,mr=0,float('inf')
for i in range(m):
l,r=list(map(int,input().split()))
ml=max(l,ml)
mr=min(r,mr)
print((max(mr-ml+1,0))) | 9 | 7 | 203 | 169 | n, m = list(map(int, input().split()))
L = [list(map(int, input().split())) for _ in range(m)]
lm = 0
rm = float("inf")
for i in range(m):
lm = max(L[i][0], lm)
rm = min(L[i][1], rm)
print((max(0, rm - lm + 1)))
| n, m = list(map(int, input().split()))
ml, mr = 0, float("inf")
for i in range(m):
l, r = list(map(int, input().split()))
ml = max(l, ml)
mr = min(r, mr)
print((max(mr - ml + 1, 0)))
| false | 22.222222 | [
"-L = [list(map(int, input().split())) for _ in range(m)]",
"-lm = 0",
"-rm = float(\"inf\")",
"+ml, mr = 0, float(\"inf\")",
"- lm = max(L[i][0], lm)",
"- rm = min(L[i][1], rm)",
"-print((max(0, rm - lm + 1)))",
"+ l, r = list(map(int, input().split()))",
"+ ml = max(l, ml)",
"+ mr = min(r, mr)",
"+print((max(mr - ml + 1, 0)))"
] | false | 0.041928 | 0.043304 | 0.968221 | [
"s618724454",
"s195476146"
] |
u367130284 | p03474 | python | s481779312 | s283005049 | 21 | 17 | 2,940 | 2,940 | Accepted | Accepted | 19.05 | a=int(input()[0]);s=eval(input());print(("YNeos"[s.count("-")!=1or s[a]>"-"::2])) | a=int(input()[0]);s=eval(input());print(("YNeos"[s.count("-")!=1or"-"<s[a]::2])) | 1 | 1 | 73 | 72 | a = int(input()[0])
s = eval(input())
print(("YNeos"[s.count("-") != 1 or s[a] > "-" :: 2]))
| a = int(input()[0])
s = eval(input())
print(("YNeos"[s.count("-") != 1 or "-" < s[a] :: 2]))
| false | 0 | [
"-print((\"YNeos\"[s.count(\"-\") != 1 or s[a] > \"-\" :: 2]))",
"+print((\"YNeos\"[s.count(\"-\") != 1 or \"-\" < s[a] :: 2]))"
] | false | 0.043012 | 0.041528 | 1.035735 | [
"s481779312",
"s283005049"
] |
u280552586 | p02754 | python | s405654434 | s179557045 | 19 | 17 | 3,316 | 2,940 | Accepted | Accepted | 10.53 | n, a, b = list(map(int, input().split()))
answer = n // (a+b) * a + min((n % (a+b)), a)
print(answer)
| n, a, b = list(map(int, input().split()))
ans = (n // (a+b))*a + min(a, (n % (a+b)))
print(ans)
| 4 | 3 | 100 | 92 | n, a, b = list(map(int, input().split()))
answer = n // (a + b) * a + min((n % (a + b)), a)
print(answer)
| n, a, b = list(map(int, input().split()))
ans = (n // (a + b)) * a + min(a, (n % (a + b)))
print(ans)
| false | 25 | [
"-answer = n // (a + b) * a + min((n % (a + b)), a)",
"-print(answer)",
"+ans = (n // (a + b)) * a + min(a, (n % (a + b)))",
"+print(ans)"
] | false | 0.064107 | 0.063676 | 1.006771 | [
"s405654434",
"s179557045"
] |
u325264482 | p03107 | python | s266827566 | s763314479 | 29 | 18 | 3,572 | 3,188 | Accepted | Accepted | 37.93 | import collections
S = eval(input())
N = len(S)
c = collections.Counter(S)
if len(c) == 1:
print((0))
else:
print((c.most_common()[-1][1]*2))
| S = eval(input())
num_0 = S.count('0')
num_1 = S.count('1')
print((min(num_0, num_1)*2))
| 12 | 6 | 155 | 88 | import collections
S = eval(input())
N = len(S)
c = collections.Counter(S)
if len(c) == 1:
print((0))
else:
print((c.most_common()[-1][1] * 2))
| S = eval(input())
num_0 = S.count("0")
num_1 = S.count("1")
print((min(num_0, num_1) * 2))
| false | 50 | [
"-import collections",
"-",
"-N = len(S)",
"-c = collections.Counter(S)",
"-if len(c) == 1:",
"- print((0))",
"-else:",
"- print((c.most_common()[-1][1] * 2))",
"+num_0 = S.count(\"0\")",
"+num_1 = S.count(\"1\")",
"+print((min(num_0, num_1) * 2))"
] | false | 0.033922 | 0.058947 | 0.575477 | [
"s266827566",
"s763314479"
] |
u514390882 | p02861 | python | s734321219 | s184013090 | 461 | 316 | 8,052 | 9,440 | Accepted | Accepted | 31.45 | import itertools
n = int(eval(input()))
xy = []
for i in range(n):
xy.append(list(map(int, input().split())))
per = list(itertools.permutations([i for i in range(n)]))
dist = 0
for i in per:
for j in range(len(i)-1):
xi = xy[i[j]][0]
yi = xy[i[j]][1]
xj = xy[i[j+1]][0]
yj = xy[i[j+1]][1]
dist += ((xi - xj) ** 2 + (yi - yj) ** 2) ** 0.5
dist /= len(per)
print(dist) | import itertools
N = int(eval(input()))
x = []
y = []
for i in range(N):
xy = list(map(int, input().split()))
x.append(xy[0])
y.append(xy[1])
l = [i for i in range(N)]
ans = 0
cnt = 0
for i in itertools.permutations(l, N):
cnt += 1
for j in range(1, N):
x1 = x[i[j]]
x2 = x[i[j-1]]
y1 = y[i[j]]
y2 = y[i[j-1]]
ans += pow((x1 - x2)**2 + (y1 - y2)**2, 0.5)
# print(i, j, x1, y1, x2, y2)
ans /= cnt
print(ans) | 16 | 24 | 423 | 493 | import itertools
n = int(eval(input()))
xy = []
for i in range(n):
xy.append(list(map(int, input().split())))
per = list(itertools.permutations([i for i in range(n)]))
dist = 0
for i in per:
for j in range(len(i) - 1):
xi = xy[i[j]][0]
yi = xy[i[j]][1]
xj = xy[i[j + 1]][0]
yj = xy[i[j + 1]][1]
dist += ((xi - xj) ** 2 + (yi - yj) ** 2) ** 0.5
dist /= len(per)
print(dist)
| import itertools
N = int(eval(input()))
x = []
y = []
for i in range(N):
xy = list(map(int, input().split()))
x.append(xy[0])
y.append(xy[1])
l = [i for i in range(N)]
ans = 0
cnt = 0
for i in itertools.permutations(l, N):
cnt += 1
for j in range(1, N):
x1 = x[i[j]]
x2 = x[i[j - 1]]
y1 = y[i[j]]
y2 = y[i[j - 1]]
ans += pow((x1 - x2) ** 2 + (y1 - y2) ** 2, 0.5)
# print(i, j, x1, y1, x2, y2)
ans /= cnt
print(ans)
| false | 33.333333 | [
"-n = int(eval(input()))",
"-xy = []",
"-for i in range(n):",
"- xy.append(list(map(int, input().split())))",
"-per = list(itertools.permutations([i for i in range(n)]))",
"-dist = 0",
"-for i in per:",
"- for j in range(len(i) - 1):",
"- xi = xy[i[j]][0]",
"- yi = xy[i[j]][1]",
"- xj = xy[i[j + 1]][0]",
"- yj = xy[i[j + 1]][1]",
"- dist += ((xi - xj) ** 2 + (yi - yj) ** 2) ** 0.5",
"-dist /= len(per)",
"-print(dist)",
"+N = int(eval(input()))",
"+x = []",
"+y = []",
"+for i in range(N):",
"+ xy = list(map(int, input().split()))",
"+ x.append(xy[0])",
"+ y.append(xy[1])",
"+l = [i for i in range(N)]",
"+ans = 0",
"+cnt = 0",
"+for i in itertools.permutations(l, N):",
"+ cnt += 1",
"+ for j in range(1, N):",
"+ x1 = x[i[j]]",
"+ x2 = x[i[j - 1]]",
"+ y1 = y[i[j]]",
"+ y2 = y[i[j - 1]]",
"+ ans += pow((x1 - x2) ** 2 + (y1 - y2) ** 2, 0.5)",
"+ # print(i, j, x1, y1, x2, y2)",
"+ans /= cnt",
"+print(ans)"
] | false | 0.038432 | 0.080029 | 0.480228 | [
"s734321219",
"s184013090"
] |
u588341295 | p03472 | python | s444283239 | s326803177 | 350 | 287 | 12,532 | 11,312 | Accepted | Accepted | 18 | # -*- coding: utf-8 -*-
from bisect import bisect_left
N, H = list(map(int, input().split()))
A, B = [0]*N, [0]*N
for i in range(N):
A[i], B[i] = list(map(int, input().split()))
a_max = max(A)
B.sort()
# 一番強い振る刀より弱い投げる刀はいらない
B2 = list(reversed(B[bisect_left(B, a_max):]))
cnt = 0
# 投げるだけで倒せるか
if H <= sum(B2):
# 強い方から順番に投げる
for i in range(len(B2)):
cnt += 1
H -= B2[i]
if H <= 0:
print(cnt)
exit()
else:
# 全部投げた結果
H -= sum(B2)
cnt += len(B2)
# 倒すまでに振る回数
cnt += -(-H // a_max)
print(cnt)
| # -*- coding: utf-8 -*-
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
N, H = MAP()
A = [0] * N
B = [0] * N
for i in range(N):
a, b = MAP()
A[i] = a
B[i] = b
A.sort(reverse=1)
B.sort(reverse=1)
mxa = A[0]
cnt = 0
for b in B:
if H <= 0 or b <= mxa:
break
H = max(0, H-b)
cnt += 1
cnt += ceil(H, mxa)
print(cnt)
| 31 | 40 | 593 | 989 | # -*- coding: utf-8 -*-
from bisect import bisect_left
N, H = list(map(int, input().split()))
A, B = [0] * N, [0] * N
for i in range(N):
A[i], B[i] = list(map(int, input().split()))
a_max = max(A)
B.sort()
# 一番強い振る刀より弱い投げる刀はいらない
B2 = list(reversed(B[bisect_left(B, a_max) :]))
cnt = 0
# 投げるだけで倒せるか
if H <= sum(B2):
# 強い方から順番に投げる
for i in range(len(B2)):
cnt += 1
H -= B2[i]
if H <= 0:
print(cnt)
exit()
else:
# 全部投げた結果
H -= sum(B2)
cnt += len(B2)
# 倒すまでに振る回数
cnt += -(-H // a_max)
print(cnt)
| # -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(eval(input()))
def MAP():
return list(map(int, input().split()))
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
N, H = MAP()
A = [0] * N
B = [0] * N
for i in range(N):
a, b = MAP()
A[i] = a
B[i] = b
A.sort(reverse=1)
B.sort(reverse=1)
mxa = A[0]
cnt = 0
for b in B:
if H <= 0 or b <= mxa:
break
H = max(0, H - b)
cnt += 1
cnt += ceil(H, mxa)
print(cnt)
| false | 22.5 | [
"-from bisect import bisect_left",
"+import sys",
"-N, H = list(map(int, input().split()))",
"-A, B = [0] * N, [0] * N",
"+",
"+def input():",
"+ return sys.stdin.readline().strip()",
"+",
"+",
"+def list2d(a, b, c):",
"+ return [[c] * b for i in range(a)]",
"+",
"+",
"+def list3d(a, b, c, d):",
"+ return [[[d] * c for j in range(b)] for i in range(a)]",
"+",
"+",
"+def list4d(a, b, c, d, e):",
"+ return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]",
"+",
"+",
"+def ceil(x, y=1):",
"+ return int(-(-x // y))",
"+",
"+",
"+def INT():",
"+ return int(eval(input()))",
"+",
"+",
"+def MAP():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LIST(N=None):",
"+ return list(MAP()) if N is None else [INT() for i in range(N)]",
"+",
"+",
"+def Yes():",
"+ print(\"Yes\")",
"+",
"+",
"+def No():",
"+ print(\"No\")",
"+",
"+",
"+def YES():",
"+ print(\"YES\")",
"+",
"+",
"+def NO():",
"+ print(\"NO\")",
"+",
"+",
"+sys.setrecursionlimit(10**9)",
"+INF = 10**18",
"+MOD = 10**9 + 7",
"+N, H = MAP()",
"+A = [0] * N",
"+B = [0] * N",
"- A[i], B[i] = list(map(int, input().split()))",
"-a_max = max(A)",
"-B.sort()",
"-# 一番強い振る刀より弱い投げる刀はいらない",
"-B2 = list(reversed(B[bisect_left(B, a_max) :]))",
"+ a, b = MAP()",
"+ A[i] = a",
"+ B[i] = b",
"+A.sort(reverse=1)",
"+B.sort(reverse=1)",
"+mxa = A[0]",
"-# 投げるだけで倒せるか",
"-if H <= sum(B2):",
"- # 強い方から順番に投げる",
"- for i in range(len(B2)):",
"- cnt += 1",
"- H -= B2[i]",
"- if H <= 0:",
"- print(cnt)",
"- exit()",
"-else:",
"- # 全部投げた結果",
"- H -= sum(B2)",
"- cnt += len(B2)",
"- # 倒すまでに振る回数",
"- cnt += -(-H // a_max)",
"- print(cnt)",
"+for b in B:",
"+ if H <= 0 or b <= mxa:",
"+ break",
"+ H = max(0, H - b)",
"+ cnt += 1",
"+cnt += ceil(H, mxa)",
"+print(cnt)"
] | false | 0.037757 | 0.094608 | 0.399089 | [
"s444283239",
"s326803177"
] |
u677440371 | p03325 | python | s305614142 | s798123899 | 111 | 96 | 4,148 | 4,148 | Accepted | Accepted | 13.51 | n = int(eval(input()))
a = list(map(int, input().split()))
count = 0
for i in a:
while i % 2 == 0:
i /= 2
count += 1
print(count) | n = int(eval(input()))
a = [int(i) for i in input().split()]
a = sorted(list([x for x in a if (x % 2) == 0]), reverse=True)
ans = 0
for i in a:
while i % 2 == 0:
i //= 2
ans += 1
print((int(ans))) | 8 | 10 | 150 | 222 | n = int(eval(input()))
a = list(map(int, input().split()))
count = 0
for i in a:
while i % 2 == 0:
i /= 2
count += 1
print(count)
| n = int(eval(input()))
a = [int(i) for i in input().split()]
a = sorted(list([x for x in a if (x % 2) == 0]), reverse=True)
ans = 0
for i in a:
while i % 2 == 0:
i //= 2
ans += 1
print((int(ans)))
| false | 20 | [
"-a = list(map(int, input().split()))",
"-count = 0",
"+a = [int(i) for i in input().split()]",
"+a = sorted(list([x for x in a if (x % 2) == 0]), reverse=True)",
"+ans = 0",
"- i /= 2",
"- count += 1",
"-print(count)",
"+ i //= 2",
"+ ans += 1",
"+print((int(ans)))"
] | false | 0.034425 | 0.037143 | 0.926844 | [
"s305614142",
"s798123899"
] |
u691018832 | p02720 | python | s375804827 | s831681060 | 417 | 133 | 5,900 | 22,712 | Accepted | Accepted | 68.11 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
k = int(readline())
q = [(i + 1) for i in range(9)]
if k < 10:
print(k)
exit()
cnt = 9
while q:
x = q.pop(0)
y = int(str(x)[-1])
if y != 0:
cnt += 1
if cnt == k:
print((10 * x + y - 1))
exit()
q.append(10 * x + y - 1)
cnt += 1
if cnt == k:
print((10 * x + y))
exit()
q.append(10 * x + y)
if y != 9:
cnt += 1
if cnt == k:
print((10 * x + y + 1))
exit()
q.append(10 * x + y + 1)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from collections import deque
k = int(readline())
q = deque(list(map(str, list(range(1, 10)))))
for i in range(k - 1):
x = q.popleft()
y = int(x[-1])
if y != 0:
q.append(x + str(y - 1))
q.append(x + x[-1])
if y != 9:
q.append(x + str(y + 1))
print((q[0]))
| 32 | 19 | 698 | 457 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
k = int(readline())
q = [(i + 1) for i in range(9)]
if k < 10:
print(k)
exit()
cnt = 9
while q:
x = q.pop(0)
y = int(str(x)[-1])
if y != 0:
cnt += 1
if cnt == k:
print((10 * x + y - 1))
exit()
q.append(10 * x + y - 1)
cnt += 1
if cnt == k:
print((10 * x + y))
exit()
q.append(10 * x + y)
if y != 9:
cnt += 1
if cnt == k:
print((10 * x + y + 1))
exit()
q.append(10 * x + y + 1)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
from collections import deque
k = int(readline())
q = deque(list(map(str, list(range(1, 10)))))
for i in range(k - 1):
x = q.popleft()
y = int(x[-1])
if y != 0:
q.append(x + str(y - 1))
q.append(x + x[-1])
if y != 9:
q.append(x + str(y + 1))
print((q[0]))
| false | 40.625 | [
"+from collections import deque",
"+",
"-q = [(i + 1) for i in range(9)]",
"-if k < 10:",
"- print(k)",
"- exit()",
"-cnt = 9",
"-while q:",
"- x = q.pop(0)",
"- y = int(str(x)[-1])",
"+q = deque(list(map(str, list(range(1, 10)))))",
"+for i in range(k - 1):",
"+ x = q.popleft()",
"+ y = int(x[-1])",
"- cnt += 1",
"- if cnt == k:",
"- print((10 * x + y - 1))",
"- exit()",
"- q.append(10 * x + y - 1)",
"- cnt += 1",
"- if cnt == k:",
"- print((10 * x + y))",
"- exit()",
"- q.append(10 * x + y)",
"+ q.append(x + str(y - 1))",
"+ q.append(x + x[-1])",
"- cnt += 1",
"- if cnt == k:",
"- print((10 * x + y + 1))",
"- exit()",
"- q.append(10 * x + y + 1)",
"+ q.append(x + str(y + 1))",
"+print((q[0]))"
] | false | 0.081944 | 0.074069 | 1.106313 | [
"s375804827",
"s831681060"
] |
u071211072 | p02578 | python | s798902199 | s883218108 | 149 | 108 | 32,004 | 32,132 | Accepted | Accepted | 27.52 | try:
k = int(eval(input()))
l = list(map(int,input().split(' ')))
c = 0
for i in range(len(l)-1):
x = l[i+1]-l[i]
if x<0:
l[i+1]+=abs(x)
c+=abs(x)
print(c)
except:
pass
| def sol(lis):
m = lis[0]
ans = []
for i in range(len(lis)):
if lis[i]<m:
ans.append(m-lis[i])
lis[i] = m
elif lis[i]!=m:
m = max(m,lis[i])
print((sum(ans)))
eval(input())
lis = list(map(int,input().split(' ')))
sol(lis)
| 12 | 13 | 226 | 293 | try:
k = int(eval(input()))
l = list(map(int, input().split(" ")))
c = 0
for i in range(len(l) - 1):
x = l[i + 1] - l[i]
if x < 0:
l[i + 1] += abs(x)
c += abs(x)
print(c)
except:
pass
| def sol(lis):
m = lis[0]
ans = []
for i in range(len(lis)):
if lis[i] < m:
ans.append(m - lis[i])
lis[i] = m
elif lis[i] != m:
m = max(m, lis[i])
print((sum(ans)))
eval(input())
lis = list(map(int, input().split(" ")))
sol(lis)
| false | 7.692308 | [
"-try:",
"- k = int(eval(input()))",
"- l = list(map(int, input().split(\" \")))",
"- c = 0",
"- for i in range(len(l) - 1):",
"- x = l[i + 1] - l[i]",
"- if x < 0:",
"- l[i + 1] += abs(x)",
"- c += abs(x)",
"- print(c)",
"-except:",
"- pass",
"+def sol(lis):",
"+ m = lis[0]",
"+ ans = []",
"+ for i in range(len(lis)):",
"+ if lis[i] < m:",
"+ ans.append(m - lis[i])",
"+ lis[i] = m",
"+ elif lis[i] != m:",
"+ m = max(m, lis[i])",
"+ print((sum(ans)))",
"+",
"+",
"+eval(input())",
"+lis = list(map(int, input().split(\" \")))",
"+sol(lis)"
] | false | 0.096205 | 0.054042 | 1.7802 | [
"s798902199",
"s883218108"
] |
u017810624 | p03152 | python | s472514094 | s410608787 | 702 | 642 | 3,188 | 3,188 | Accepted | Accepted | 8.55 | n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=set(a);B=set(b)
if len(A)!=len(a) or len(B)!=len(b):
print((0))
else:
c=1;cn=0;cm=0
for k in range(m*n,0,-1):
if k in A and k in B:
cn+=1;cm+=1
elif k in A:
c*=cm;cn+=1
elif k in B:
c*=cn;cm+=1
else:
c*=(cm*cn-m*n+k)
if c==0:
break
c=c%(10**9+7)
print(c) | n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=set(a);B=set(b)
if len(A)!=len(a) or len(B)!=len(b):
print((0))
else:
c=1;cn=0;cm=0
for k in range(m*n,0,-1):
if k in A and k in B:
cn+=1;cm+=1
elif k in A:
c*=cm;cn+=1
elif k in B:
c*=cn;cm+=1
else:
c*=cm*cn-m*n+k
c=c%(10**9+7)
print(c) | 21 | 19 | 431 | 402 | n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = set(a)
B = set(b)
if len(A) != len(a) or len(B) != len(b):
print((0))
else:
c = 1
cn = 0
cm = 0
for k in range(m * n, 0, -1):
if k in A and k in B:
cn += 1
cm += 1
elif k in A:
c *= cm
cn += 1
elif k in B:
c *= cn
cm += 1
else:
c *= cm * cn - m * n + k
if c == 0:
break
c = c % (10**9 + 7)
print(c)
| n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = set(a)
B = set(b)
if len(A) != len(a) or len(B) != len(b):
print((0))
else:
c = 1
cn = 0
cm = 0
for k in range(m * n, 0, -1):
if k in A and k in B:
cn += 1
cm += 1
elif k in A:
c *= cm
cn += 1
elif k in B:
c *= cn
cm += 1
else:
c *= cm * cn - m * n + k
c = c % (10**9 + 7)
print(c)
| false | 9.52381 | [
"- if c == 0:",
"- break"
] | false | 0.099136 | 0.17449 | 0.568149 | [
"s472514094",
"s410608787"
] |
u263830634 | p04000 | python | s275847960 | s568244583 | 2,448 | 2,165 | 128,036 | 127,988 | Accepted | Accepted | 11.56 | import sys
input = sys.stdin.readline
lst = []
lst_append = lst.append
H, W, N = map(int, input().split())
tmplst = [-1, 0, 1]
for _ in range(N):
a, b = map(int, input().split())
a -= 1
b -= 1
for i in range(-1, 2):
for j in range(-1, 2):
if 1 <= a + i <= H - 2 and 1 <= b + j <= W - 2:
lst_append((a + i, b + j))
lst.sort()
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)
tmp = None
count = 0
for i in lst:
if i == tmp:
count += 1
else:
ans[0] -= 1
ans[count] += 1
count = 1
tmp = i
ans[0] -= 1
ans[count] += 1
print (*ans, sep = '\n')
| import sys
input = sys.stdin.readline
lst = []
lst_append = lst.append
H, W, N = map(int, input().split())
tmplst = [-1, 0, 1]
for _ in range(N):
a, b = map(int, input().split())
a -= 1
b -= 1
for i in tmplst:
if 1 <= a + i <= H - 2:
for j in tmplst:
if 1 <= b + j <= W - 2:
lst_append((a + i, b + j))
lst.sort()
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)
tmp = None
count = 0
for i in lst:
if i == tmp:
count += 1
else:
ans[0] -= 1
ans[count] += 1
count = 1
tmp = i
ans[0] -= 1
ans[count] += 1
print (*ans, sep = '\n')
| 34 | 35 | 667 | 676 | import sys
input = sys.stdin.readline
lst = []
lst_append = lst.append
H, W, N = map(int, input().split())
tmplst = [-1, 0, 1]
for _ in range(N):
a, b = map(int, input().split())
a -= 1
b -= 1
for i in range(-1, 2):
for j in range(-1, 2):
if 1 <= a + i <= H - 2 and 1 <= b + j <= W - 2:
lst_append((a + i, b + j))
lst.sort()
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)
tmp = None
count = 0
for i in lst:
if i == tmp:
count += 1
else:
ans[0] -= 1
ans[count] += 1
count = 1
tmp = i
ans[0] -= 1
ans[count] += 1
print(*ans, sep="\n")
| import sys
input = sys.stdin.readline
lst = []
lst_append = lst.append
H, W, N = map(int, input().split())
tmplst = [-1, 0, 1]
for _ in range(N):
a, b = map(int, input().split())
a -= 1
b -= 1
for i in tmplst:
if 1 <= a + i <= H - 2:
for j in tmplst:
if 1 <= b + j <= W - 2:
lst_append((a + i, b + j))
lst.sort()
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)
tmp = None
count = 0
for i in lst:
if i == tmp:
count += 1
else:
ans[0] -= 1
ans[count] += 1
count = 1
tmp = i
ans[0] -= 1
ans[count] += 1
print(*ans, sep="\n")
| false | 2.857143 | [
"- for i in range(-1, 2):",
"- for j in range(-1, 2):",
"- if 1 <= a + i <= H - 2 and 1 <= b + j <= W - 2:",
"- lst_append((a + i, b + j))",
"+ for i in tmplst:",
"+ if 1 <= a + i <= H - 2:",
"+ for j in tmplst:",
"+ if 1 <= b + j <= W - 2:",
"+ lst_append((a + i, b + j))"
] | false | 0.074639 | 0.043578 | 1.712784 | [
"s275847960",
"s568244583"
] |
u298297089 | p02909 | python | s776483549 | s407949798 | 166 | 17 | 38,384 | 2,940 | Accepted | Accepted | 89.76 | s = eval(input())
dic = {'Sunny':'Cloudy', 'Cloudy':'Rainy', 'Rainy':'Sunny' }
print((dic[s])) | s = eval(input())
if s == 'Sunny':
print('Cloudy')
elif s == 'Cloudy':
print('Rainy')
else :
print('Sunny') | 3 | 7 | 88 | 113 | s = eval(input())
dic = {"Sunny": "Cloudy", "Cloudy": "Rainy", "Rainy": "Sunny"}
print((dic[s]))
| s = eval(input())
if s == "Sunny":
print("Cloudy")
elif s == "Cloudy":
print("Rainy")
else:
print("Sunny")
| false | 57.142857 | [
"-dic = {\"Sunny\": \"Cloudy\", \"Cloudy\": \"Rainy\", \"Rainy\": \"Sunny\"}",
"-print((dic[s]))",
"+if s == \"Sunny\":",
"+ print(\"Cloudy\")",
"+elif s == \"Cloudy\":",
"+ print(\"Rainy\")",
"+else:",
"+ print(\"Sunny\")"
] | false | 0.044916 | 0.045678 | 0.983315 | [
"s776483549",
"s407949798"
] |
u562935282 | p02603 | python | s796274320 | s136090050 | 34 | 29 | 9,160 | 9,180 | Accepted | Accepted | 14.71 | def main():
N = int(eval(input()))
*A, = list(map(int, input().split()))
money = 1000
low = A[0]
high = -1
for x in A:
if high < x:
high = x
continue
if high > x:
money += (high - low) * (money // low)
low = high = x
money += max(0, high - low) * (money // low)
print(money)
if __name__ == '__main__':
main()
| def main():
N = int(eval(input()))
*A, = list(map(int, input().split()))
money = 1000
low = A[0]
p = A[0]
for x in A:
if p > x:
money += (p - low) * (money // low)
low = x
p = x
money += max(0, p - low) * (money // low)
print(money)
if __name__ == '__main__':
main()
| 24 | 21 | 427 | 357 | def main():
N = int(eval(input()))
(*A,) = list(map(int, input().split()))
money = 1000
low = A[0]
high = -1
for x in A:
if high < x:
high = x
continue
if high > x:
money += (high - low) * (money // low)
low = high = x
money += max(0, high - low) * (money // low)
print(money)
if __name__ == "__main__":
main()
| def main():
N = int(eval(input()))
(*A,) = list(map(int, input().split()))
money = 1000
low = A[0]
p = A[0]
for x in A:
if p > x:
money += (p - low) * (money // low)
low = x
p = x
money += max(0, p - low) * (money // low)
print(money)
if __name__ == "__main__":
main()
| false | 12.5 | [
"- high = -1",
"+ p = A[0]",
"- if high < x:",
"- high = x",
"- continue",
"- if high > x:",
"- money += (high - low) * (money // low)",
"- low = high = x",
"- money += max(0, high - low) * (money // low)",
"+ if p > x:",
"+ money += (p - low) * (money // low)",
"+ low = x",
"+ p = x",
"+ money += max(0, p - low) * (money // low)"
] | false | 0.045682 | 0.043137 | 1.059016 | [
"s796274320",
"s136090050"
] |
u761320129 | p03476 | python | s675194173 | s649165499 | 457 | 417 | 21,012 | 25,840 | Accepted | Accepted | 8.75 | Q = int(eval(input()))
qs = [tuple(map(int,input().split())) for i in range(Q)]
MAXN = 10**5+10
sieve = [0,0] + [1]*MAXN
p = 2
while p*p <= MAXN:
if sieve[p]:
for q in range(2*p,MAXN+1,p):
sieve[q] = 0
p += 1
cums = [0]
for i in range(1,MAXN):
valid = sieve[i] and sieve[(i+1)//2]
cums.append(cums[-1] + int(valid))
for l,r in qs:
ans = cums[r] - cums[l-1]
print(ans) | Q = int(input())
LR = [tuple(map(int,input().split())) for i in range(Q)]
MAXN = 10**5+10
sieve = [0,0] + [1]*MAXN
p = 2
while p*p <= MAXN:
if sieve[p]:
for q in range(2*p,MAXN+1,p):
sieve[q] = 0
p += 1
likes = [0] * MAXN
for i in range(3,MAXN,2):
if sieve[i] and sieve[(i+1)//2]:
likes[i] += 1
cl = [0]
for l in likes:
cl.append(l + cl[-1])
ans = []
for l,r in LR:
ans.append(cl[r+1] - cl[l])
print(*ans, sep='\n')
| 20 | 24 | 427 | 489 | Q = int(eval(input()))
qs = [tuple(map(int, input().split())) for i in range(Q)]
MAXN = 10**5 + 10
sieve = [0, 0] + [1] * MAXN
p = 2
while p * p <= MAXN:
if sieve[p]:
for q in range(2 * p, MAXN + 1, p):
sieve[q] = 0
p += 1
cums = [0]
for i in range(1, MAXN):
valid = sieve[i] and sieve[(i + 1) // 2]
cums.append(cums[-1] + int(valid))
for l, r in qs:
ans = cums[r] - cums[l - 1]
print(ans)
| Q = int(input())
LR = [tuple(map(int, input().split())) for i in range(Q)]
MAXN = 10**5 + 10
sieve = [0, 0] + [1] * MAXN
p = 2
while p * p <= MAXN:
if sieve[p]:
for q in range(2 * p, MAXN + 1, p):
sieve[q] = 0
p += 1
likes = [0] * MAXN
for i in range(3, MAXN, 2):
if sieve[i] and sieve[(i + 1) // 2]:
likes[i] += 1
cl = [0]
for l in likes:
cl.append(l + cl[-1])
ans = []
for l, r in LR:
ans.append(cl[r + 1] - cl[l])
print(*ans, sep="\n")
| false | 16.666667 | [
"-Q = int(eval(input()))",
"-qs = [tuple(map(int, input().split())) for i in range(Q)]",
"+Q = int(input())",
"+LR = [tuple(map(int, input().split())) for i in range(Q)]",
"-cums = [0]",
"-for i in range(1, MAXN):",
"- valid = sieve[i] and sieve[(i + 1) // 2]",
"- cums.append(cums[-1] + int(valid))",
"-for l, r in qs:",
"- ans = cums[r] - cums[l - 1]",
"- print(ans)",
"+likes = [0] * MAXN",
"+for i in range(3, MAXN, 2):",
"+ if sieve[i] and sieve[(i + 1) // 2]:",
"+ likes[i] += 1",
"+cl = [0]",
"+for l in likes:",
"+ cl.append(l + cl[-1])",
"+ans = []",
"+for l, r in LR:",
"+ ans.append(cl[r + 1] - cl[l])",
"+print(*ans, sep=\"\\n\")"
] | false | 0.142317 | 0.109668 | 1.297711 | [
"s675194173",
"s649165499"
] |
u905203728 | p02609 | python | s184141437 | s110951518 | 345 | 303 | 87,888 | 81,860 | Accepted | Accepted | 12.17 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def popcnt(n):
return bin(n).count("1")
def mod(n, cnt):
if n == 0:
return cnt
n = n % popcnt(n)
cnt += 1
return mod(n, cnt)
n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int(''.join(x2), 2)
c = x2.count('1')
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c - 1 != 0 else 0
for i in range(n):
if x2[i] == '0':
t = (mod1 + pow(2, n - i - 1, c + 1)) % (c + 1)
else:
if c - 1 != 0:
t = (mod2 - pow(2, n - i - 1, c - 1)) % (c - 1)
else:
print((0))
continue
print((mod(t, 1)))
| def popcount(x):
return bin(x).count("1")
n=int(eval(input()))
x=eval(input())
num=int(x,2)
cnt=popcount(num)
mod1=num%(cnt+1)
mod2=num%(cnt-1) if cnt-1!=0 else 0
for i in range(n):
if x[i]=="0":
ans=(mod1+pow(2,n-i-1,cnt+1))%(cnt+1)
else:
if cnt-1==0:
print((0))
continue
else:
ans=(mod2-pow(2,n-i-1,cnt-1))%(cnt-1)
point=1
while ans!=0:
ans %=popcount(ans)
point +=1
print(point) | 36 | 26 | 745 | 496 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def popcnt(n):
return bin(n).count("1")
def mod(n, cnt):
if n == 0:
return cnt
n = n % popcnt(n)
cnt += 1
return mod(n, cnt)
n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int("".join(x2), 2)
c = x2.count("1")
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c - 1 != 0 else 0
for i in range(n):
if x2[i] == "0":
t = (mod1 + pow(2, n - i - 1, c + 1)) % (c + 1)
else:
if c - 1 != 0:
t = (mod2 - pow(2, n - i - 1, c - 1)) % (c - 1)
else:
print((0))
continue
print((mod(t, 1)))
| def popcount(x):
return bin(x).count("1")
n = int(eval(input()))
x = eval(input())
num = int(x, 2)
cnt = popcount(num)
mod1 = num % (cnt + 1)
mod2 = num % (cnt - 1) if cnt - 1 != 0 else 0
for i in range(n):
if x[i] == "0":
ans = (mod1 + pow(2, n - i - 1, cnt + 1)) % (cnt + 1)
else:
if cnt - 1 == 0:
print((0))
continue
else:
ans = (mod2 - pow(2, n - i - 1, cnt - 1)) % (cnt - 1)
point = 1
while ans != 0:
ans %= popcount(ans)
point += 1
print(point)
| false | 27.777778 | [
"-import sys",
"-",
"-read = sys.stdin.buffer.read",
"-readline = sys.stdin.buffer.readline",
"-readlines = sys.stdin.buffer.readlines",
"+def popcount(x):",
"+ return bin(x).count(\"1\")",
"-def popcnt(n):",
"- return bin(n).count(\"1\")",
"-",
"-",
"-def mod(n, cnt):",
"- if n == 0:",
"- return cnt",
"- n = n % popcnt(n)",
"- cnt += 1",
"- return mod(n, cnt)",
"-",
"-",
"-n = int(readline())",
"-x2 = list(readline().decode().rstrip())",
"-x10 = int(\"\".join(x2), 2)",
"-c = x2.count(\"1\")",
"-mod1 = x10 % (c + 1)",
"-mod2 = x10 % (c - 1) if c - 1 != 0 else 0",
"+n = int(eval(input()))",
"+x = eval(input())",
"+num = int(x, 2)",
"+cnt = popcount(num)",
"+mod1 = num % (cnt + 1)",
"+mod2 = num % (cnt - 1) if cnt - 1 != 0 else 0",
"- if x2[i] == \"0\":",
"- t = (mod1 + pow(2, n - i - 1, c + 1)) % (c + 1)",
"+ if x[i] == \"0\":",
"+ ans = (mod1 + pow(2, n - i - 1, cnt + 1)) % (cnt + 1)",
"- if c - 1 != 0:",
"- t = (mod2 - pow(2, n - i - 1, c - 1)) % (c - 1)",
"- else:",
"+ if cnt - 1 == 0:",
"- print((mod(t, 1)))",
"+ else:",
"+ ans = (mod2 - pow(2, n - i - 1, cnt - 1)) % (cnt - 1)",
"+ point = 1",
"+ while ans != 0:",
"+ ans %= popcount(ans)",
"+ point += 1",
"+ print(point)"
] | false | 0.045725 | 0.046142 | 0.99096 | [
"s184141437",
"s110951518"
] |
u540761833 | p03854 | python | s322935156 | s457661534 | 361 | 19 | 3,440 | 3,188 | Accepted | Accepted | 94.74 | S = eval(input())
sr = ''
for i in S:
sr = i + sr
lista = ['remaerd','resare','esare','maerd']
c = 0
while c == 0:
c = 1
for i in lista:
if sr[0:len(i)] == i:
sr = sr[len(i):]
c = 0
if sr == '':
print('YES')
else:
print('NO')
| s = eval(input())
s = s[-1::-1]
word = ['resare','esare','remaerd','maerd',]
for i in word:
s = s.replace(i,'')
if s:
print('NO')
else:
print('YES') | 18 | 9 | 299 | 162 | S = eval(input())
sr = ""
for i in S:
sr = i + sr
lista = ["remaerd", "resare", "esare", "maerd"]
c = 0
while c == 0:
c = 1
for i in lista:
if sr[0 : len(i)] == i:
sr = sr[len(i) :]
c = 0
if sr == "":
print("YES")
else:
print("NO")
| s = eval(input())
s = s[-1::-1]
word = [
"resare",
"esare",
"remaerd",
"maerd",
]
for i in word:
s = s.replace(i, "")
if s:
print("NO")
else:
print("YES")
| false | 50 | [
"-S = eval(input())",
"-sr = \"\"",
"-for i in S:",
"- sr = i + sr",
"-lista = [\"remaerd\", \"resare\", \"esare\", \"maerd\"]",
"-c = 0",
"-while c == 0:",
"- c = 1",
"- for i in lista:",
"- if sr[0 : len(i)] == i:",
"- sr = sr[len(i) :]",
"- c = 0",
"-if sr == \"\":",
"+s = eval(input())",
"+s = s[-1::-1]",
"+word = [",
"+ \"resare\",",
"+ \"esare\",",
"+ \"remaerd\",",
"+ \"maerd\",",
"+]",
"+for i in word:",
"+ s = s.replace(i, \"\")",
"+if s:",
"+ print(\"NO\")",
"+else:",
"-else:",
"- print(\"NO\")"
] | false | 0.125994 | 0.033241 | 3.790333 | [
"s322935156",
"s457661534"
] |
u968166680 | p02973 | python | s900840516 | s685579840 | 160 | 126 | 8,844 | 11,764 | Accepted | Accepted | 21.25 | from sys import stdin, setrecursionlimit
from bisect import bisect_left
from collections import deque
setrecursionlimit(10 ** 9)
INF = 1 << 60
def input():
return stdin.readline().strip()
def main():
N = int(eval(input()))
A = tuple(int(eval(input())) for _ in range(N))
B =deque([A[0]])
for a in A[1:]:
if a <= B[0]:
B.appendleft(a)
else:
B[bisect_left(B, a) - 1] = a
print((len(B)))
if __name__ == '__main__':
main()
| from sys import stdin, setrecursionlimit
from bisect import bisect_right
setrecursionlimit(10 ** 9)
INF = 1 << 60
def input():
return stdin.readline().strip()
def main():
N = int(eval(input()))
A = tuple(int(eval(input())) for _ in range(N))
B = [-A[0]]
for a in A[1:]:
if a <= -B[-1]:
B.append(-a)
else:
B[bisect_right(B, -a)] = -a
print((len(B)))
if __name__ == '__main__':
main()
| 28 | 27 | 509 | 472 | from sys import stdin, setrecursionlimit
from bisect import bisect_left
from collections import deque
setrecursionlimit(10**9)
INF = 1 << 60
def input():
return stdin.readline().strip()
def main():
N = int(eval(input()))
A = tuple(int(eval(input())) for _ in range(N))
B = deque([A[0]])
for a in A[1:]:
if a <= B[0]:
B.appendleft(a)
else:
B[bisect_left(B, a) - 1] = a
print((len(B)))
if __name__ == "__main__":
main()
| from sys import stdin, setrecursionlimit
from bisect import bisect_right
setrecursionlimit(10**9)
INF = 1 << 60
def input():
return stdin.readline().strip()
def main():
N = int(eval(input()))
A = tuple(int(eval(input())) for _ in range(N))
B = [-A[0]]
for a in A[1:]:
if a <= -B[-1]:
B.append(-a)
else:
B[bisect_right(B, -a)] = -a
print((len(B)))
if __name__ == "__main__":
main()
| false | 3.571429 | [
"-from bisect import bisect_left",
"-from collections import deque",
"+from bisect import bisect_right",
"- B = deque([A[0]])",
"+ B = [-A[0]]",
"- if a <= B[0]:",
"- B.appendleft(a)",
"+ if a <= -B[-1]:",
"+ B.append(-a)",
"- B[bisect_left(B, a) - 1] = a",
"+ B[bisect_right(B, -a)] = -a"
] | false | 0.046251 | 0.131975 | 0.350456 | [
"s900840516",
"s685579840"
] |
u672898046 | p03060 | python | s209562161 | s536587016 | 150 | 17 | 12,488 | 3,060 | Accepted | Accepted | 88.67 | import numpy as np
n = int(eval(input()))
v = np.array(list(map(int, input().split())))
c = np.array(list(map(int, input().split())))
ans = 0
for i,j in zip(v,c):
if i-j>=0:
ans+=(i-j)
print(ans) | n = int(eval(input()))
v = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
for i,j in zip(v,c):
if i-j>=0:
ans+=(i-j)
print(ans) | 9 | 8 | 203 | 163 | import numpy as np
n = int(eval(input()))
v = np.array(list(map(int, input().split())))
c = np.array(list(map(int, input().split())))
ans = 0
for i, j in zip(v, c):
if i - j >= 0:
ans += i - j
print(ans)
| n = int(eval(input()))
v = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
for i, j in zip(v, c):
if i - j >= 0:
ans += i - j
print(ans)
| false | 11.111111 | [
"-import numpy as np",
"-",
"-v = np.array(list(map(int, input().split())))",
"-c = np.array(list(map(int, input().split())))",
"+v = list(map(int, input().split()))",
"+c = list(map(int, input().split()))"
] | false | 0.44796 | 0.075018 | 5.971337 | [
"s209562161",
"s536587016"
] |
u647766105 | p02363 | python | s188545422 | s265328726 | 1,350 | 700 | 8,260 | 8,496 | Accepted | Accepted | 48.15 | def warshall_floyd(graph, edges):
N = len(graph)
inf = Infinity() # !_!
for i in range(N):
for j in range(N):
if i == j:
graph[i][j] = 0
else:
graph[i][j] = inf
for e in edges:
graph[e.source][e.destination] = e.weight
for k in range(N):
for i in range(N):
for j in range(N):
graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
for k in range(N):
for i in range(N):
for j in range(N):
if inf in (graph[i][j], graph[i][k], graph[k][j]): # !_!
continue
if graph[i][j] > graph[i][k] + graph[k][j]:
raise NegativeCycleError
def main():
V, E = list(map(int, input().split()))
graph = [[None] * V for _ in range(V)]
edges = []
for _ in range(E):
s, t, d = list(map(int, input().split()))
edges.append(Edge(s, t, d))
try:
warshall_floyd(graph, edges)
for g in graph:
print(" ".join(map(str, g)))
except NegativeCycleError:
print("NEGATIVE CYCLE")
class Infinity(object):
def __eq__(self, other):
return other is self
def __lt__(self, other):
return False
def __gt__(self, other):
return True
def __add__(self, other):
return self
def __radd__(self, other):
return self
def __str__(self):
return "INF"
__repr__ = __str__
class NegativeCycleError(Exception):
pass
class Edge(object):
def __init__(self, source, destination, weight):
self.source = source
self.destination = destination
self.weight = weight
if __name__ == "__main__":
main() | def warshall_floyd(graph, edges):
N = len(graph)
for i in range(N):
for j in range(N):
if i == j:
graph[i][j] = 0
else:
graph[i][j] = Infinity()
for e in edges:
graph[e.source][e.destination] = e.weight
for k in range(N):
for i in range(N):
for j in range(N):
graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
for i in range(N):
if graph[i][i] < 0:
raise NegativeCycleError
def main():
V, E = list(map(int, input().split()))
graph = [[None] * V for _ in range(V)]
edges = []
for _ in range(E):
s, t, d = list(map(int, input().split()))
edges.append(Edge(s, t, d))
try:
warshall_floyd(graph, edges)
for g in graph:
print(" ".join(map(str, g)))
except NegativeCycleError:
print("NEGATIVE CYCLE")
class Infinity(object):
def __eq__(self, other):
return other is self
def __lt__(self, other):
return False
def __gt__(self, other):
return True
def __add__(self, other):
return self
def __radd__(self, other):
return self
def __str__(self):
return "INF"
__repr__ = __str__
class NegativeCycleError(Exception):
pass
class Edge(object):
def __init__(self, source, destination, weight):
self.source = source
self.destination = destination
self.weight = weight
if __name__ == "__main__":
main() | 68 | 63 | 1,831 | 1,602 | def warshall_floyd(graph, edges):
N = len(graph)
inf = Infinity() # !_!
for i in range(N):
for j in range(N):
if i == j:
graph[i][j] = 0
else:
graph[i][j] = inf
for e in edges:
graph[e.source][e.destination] = e.weight
for k in range(N):
for i in range(N):
for j in range(N):
graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
for k in range(N):
for i in range(N):
for j in range(N):
if inf in (graph[i][j], graph[i][k], graph[k][j]): # !_!
continue
if graph[i][j] > graph[i][k] + graph[k][j]:
raise NegativeCycleError
def main():
V, E = list(map(int, input().split()))
graph = [[None] * V for _ in range(V)]
edges = []
for _ in range(E):
s, t, d = list(map(int, input().split()))
edges.append(Edge(s, t, d))
try:
warshall_floyd(graph, edges)
for g in graph:
print(" ".join(map(str, g)))
except NegativeCycleError:
print("NEGATIVE CYCLE")
class Infinity(object):
def __eq__(self, other):
return other is self
def __lt__(self, other):
return False
def __gt__(self, other):
return True
def __add__(self, other):
return self
def __radd__(self, other):
return self
def __str__(self):
return "INF"
__repr__ = __str__
class NegativeCycleError(Exception):
pass
class Edge(object):
def __init__(self, source, destination, weight):
self.source = source
self.destination = destination
self.weight = weight
if __name__ == "__main__":
main()
| def warshall_floyd(graph, edges):
N = len(graph)
for i in range(N):
for j in range(N):
if i == j:
graph[i][j] = 0
else:
graph[i][j] = Infinity()
for e in edges:
graph[e.source][e.destination] = e.weight
for k in range(N):
for i in range(N):
for j in range(N):
graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
for i in range(N):
if graph[i][i] < 0:
raise NegativeCycleError
def main():
V, E = list(map(int, input().split()))
graph = [[None] * V for _ in range(V)]
edges = []
for _ in range(E):
s, t, d = list(map(int, input().split()))
edges.append(Edge(s, t, d))
try:
warshall_floyd(graph, edges)
for g in graph:
print(" ".join(map(str, g)))
except NegativeCycleError:
print("NEGATIVE CYCLE")
class Infinity(object):
def __eq__(self, other):
return other is self
def __lt__(self, other):
return False
def __gt__(self, other):
return True
def __add__(self, other):
return self
def __radd__(self, other):
return self
def __str__(self):
return "INF"
__repr__ = __str__
class NegativeCycleError(Exception):
pass
class Edge(object):
def __init__(self, source, destination, weight):
self.source = source
self.destination = destination
self.weight = weight
if __name__ == "__main__":
main()
| false | 7.352941 | [
"- inf = Infinity() # !_!",
"- graph[i][j] = inf",
"+ graph[i][j] = Infinity()",
"- for k in range(N):",
"- for i in range(N):",
"- for j in range(N):",
"- if inf in (graph[i][j], graph[i][k], graph[k][j]): # !_!",
"- continue",
"- if graph[i][j] > graph[i][k] + graph[k][j]:",
"- raise NegativeCycleError",
"+ for i in range(N):",
"+ if graph[i][i] < 0:",
"+ raise NegativeCycleError"
] | false | 0.043564 | 0.043516 | 1.001107 | [
"s188545422",
"s265328726"
] |
u561083515 | p02803 | python | s489990973 | s202462925 | 342 | 298 | 22,424 | 3,444 | Accepted | Accepted | 12.87 | H,W = list(map(int,input().split()))
S = [[True]*(W+2)]
S += [[True] + [x == '#' for x in input().rstrip()] + [True] for _ in range(H)]
S.append([True]*(W+2))
dx = [0,0,1,-1]
dy = [1,-1,0,0]
edge = []
for i in range(1,H+1):
for j in range(1,W+1):
if S[i][j]:
continue
for d in range(4):
x = dx[d]
y = dy[d]
if (not S[i+y][j+x]) and (not ((i+y-1)*W+(j+x),(i-1)*W+j) in edge):
edge.append(((i-1)*W+j,(i+y-1)*W+(j+x)))
S = [[float("inf")] * (H*W) for _ in range(H*W)]
for i in range(H*W):
S[i][i] = 0
for a,b in edge:
S[a-1][b-1] = 1
S[b-1][a-1] = 1
from scipy.sparse.csgraph import floyd_warshall
S = floyd_warshall(S)
answer = 0
for i in range(H*W):
for j in range(i):
if S[i][j] < float("inf"):
answer = max(answer, S[i][j])
print((int(answer))) | H,W = list(map(int, input().split()))
S = [["#"] * (W + 2)]
S += [["#"] + list(eval(input())) + ["#"] for _ in range(H)]
S.append(["#"] * (W + 2))
DX = [0,0,-1,1]
DY = [-1,1,0,0]
from collections import deque
def bfs(y,x):
dist = [[-1] * (W + 2) for _ in range(H + 2)]
que = deque([(y, x)])
dist[y][x] = 0
while que:
y, x = que.popleft()
d = dist[y][x]
for dy,dx in zip(DY,DX):
ny, nx = y + dy, x + dx
if S[ny][nx] == "#": continue
if dist[ny][nx] < 0:
dist[ny][nx] = d + 1
que.append((ny,nx))
ans = -1
for i in range(1, H + 1):
for j in range(1, W + 1):
ans = max(ans, dist[i][j])
return ans
ans = 0
for i in range(1, H + 1):
for j in range(1, W + 1):
if S[i][j] == "#": continue
ans = max(ans, bfs(i, j))
print(ans) | 37 | 38 | 900 | 918 | H, W = list(map(int, input().split()))
S = [[True] * (W + 2)]
S += [[True] + [x == "#" for x in input().rstrip()] + [True] for _ in range(H)]
S.append([True] * (W + 2))
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
edge = []
for i in range(1, H + 1):
for j in range(1, W + 1):
if S[i][j]:
continue
for d in range(4):
x = dx[d]
y = dy[d]
if (not S[i + y][j + x]) and (
not ((i + y - 1) * W + (j + x), (i - 1) * W + j) in edge
):
edge.append(((i - 1) * W + j, (i + y - 1) * W + (j + x)))
S = [[float("inf")] * (H * W) for _ in range(H * W)]
for i in range(H * W):
S[i][i] = 0
for a, b in edge:
S[a - 1][b - 1] = 1
S[b - 1][a - 1] = 1
from scipy.sparse.csgraph import floyd_warshall
S = floyd_warshall(S)
answer = 0
for i in range(H * W):
for j in range(i):
if S[i][j] < float("inf"):
answer = max(answer, S[i][j])
print((int(answer)))
| H, W = list(map(int, input().split()))
S = [["#"] * (W + 2)]
S += [["#"] + list(eval(input())) + ["#"] for _ in range(H)]
S.append(["#"] * (W + 2))
DX = [0, 0, -1, 1]
DY = [-1, 1, 0, 0]
from collections import deque
def bfs(y, x):
dist = [[-1] * (W + 2) for _ in range(H + 2)]
que = deque([(y, x)])
dist[y][x] = 0
while que:
y, x = que.popleft()
d = dist[y][x]
for dy, dx in zip(DY, DX):
ny, nx = y + dy, x + dx
if S[ny][nx] == "#":
continue
if dist[ny][nx] < 0:
dist[ny][nx] = d + 1
que.append((ny, nx))
ans = -1
for i in range(1, H + 1):
for j in range(1, W + 1):
ans = max(ans, dist[i][j])
return ans
ans = 0
for i in range(1, H + 1):
for j in range(1, W + 1):
if S[i][j] == "#":
continue
ans = max(ans, bfs(i, j))
print(ans)
| false | 2.631579 | [
"-S = [[True] * (W + 2)]",
"-S += [[True] + [x == \"#\" for x in input().rstrip()] + [True] for _ in range(H)]",
"-S.append([True] * (W + 2))",
"-dx = [0, 0, 1, -1]",
"-dy = [1, -1, 0, 0]",
"-edge = []",
"+S = [[\"#\"] * (W + 2)]",
"+S += [[\"#\"] + list(eval(input())) + [\"#\"] for _ in range(H)]",
"+S.append([\"#\"] * (W + 2))",
"+DX = [0, 0, -1, 1]",
"+DY = [-1, 1, 0, 0]",
"+from collections import deque",
"+",
"+",
"+def bfs(y, x):",
"+ dist = [[-1] * (W + 2) for _ in range(H + 2)]",
"+ que = deque([(y, x)])",
"+ dist[y][x] = 0",
"+ while que:",
"+ y, x = que.popleft()",
"+ d = dist[y][x]",
"+ for dy, dx in zip(DY, DX):",
"+ ny, nx = y + dy, x + dx",
"+ if S[ny][nx] == \"#\":",
"+ continue",
"+ if dist[ny][nx] < 0:",
"+ dist[ny][nx] = d + 1",
"+ que.append((ny, nx))",
"+ ans = -1",
"+ for i in range(1, H + 1):",
"+ for j in range(1, W + 1):",
"+ ans = max(ans, dist[i][j])",
"+ return ans",
"+",
"+",
"+ans = 0",
"- if S[i][j]:",
"+ if S[i][j] == \"#\":",
"- for d in range(4):",
"- x = dx[d]",
"- y = dy[d]",
"- if (not S[i + y][j + x]) and (",
"- not ((i + y - 1) * W + (j + x), (i - 1) * W + j) in edge",
"- ):",
"- edge.append(((i - 1) * W + j, (i + y - 1) * W + (j + x)))",
"-S = [[float(\"inf\")] * (H * W) for _ in range(H * W)]",
"-for i in range(H * W):",
"- S[i][i] = 0",
"-for a, b in edge:",
"- S[a - 1][b - 1] = 1",
"- S[b - 1][a - 1] = 1",
"-from scipy.sparse.csgraph import floyd_warshall",
"-",
"-S = floyd_warshall(S)",
"-answer = 0",
"-for i in range(H * W):",
"- for j in range(i):",
"- if S[i][j] < float(\"inf\"):",
"- answer = max(answer, S[i][j])",
"-print((int(answer)))",
"+ ans = max(ans, bfs(i, j))",
"+print(ans)"
] | false | 0.362705 | 0.045048 | 8.051547 | [
"s489990973",
"s202462925"
] |
u941047297 | p03425 | python | s390807506 | s365403380 | 155 | 135 | 4,224 | 9,472 | Accepted | Accepted | 12.9 | from collections import Counter
from itertools import combinations
n = int(eval(input()))
S = [input()[0] for _ in range(n)]
C = Counter(S)
ans = 0
for i, j, k in combinations(['M', 'A', 'R', 'C', 'H'], 3):
ans += C[i] * C[j] * C[k]
print(ans)
| from collections import defaultdict
from itertools import combinations
def main():
n = int(eval(input()))
d = defaultdict(int)
for _ in range(n):
s = eval(input())
d[s[0]] += 1
ans = 0
for i, j, k in combinations('MARCH', 3):
ans += d[i] * d[j] * d[k]
print(ans)
if __name__ == '__main__':
main()
| 9 | 15 | 250 | 352 | from collections import Counter
from itertools import combinations
n = int(eval(input()))
S = [input()[0] for _ in range(n)]
C = Counter(S)
ans = 0
for i, j, k in combinations(["M", "A", "R", "C", "H"], 3):
ans += C[i] * C[j] * C[k]
print(ans)
| from collections import defaultdict
from itertools import combinations
def main():
n = int(eval(input()))
d = defaultdict(int)
for _ in range(n):
s = eval(input())
d[s[0]] += 1
ans = 0
for i, j, k in combinations("MARCH", 3):
ans += d[i] * d[j] * d[k]
print(ans)
if __name__ == "__main__":
main()
| false | 40 | [
"-from collections import Counter",
"+from collections import defaultdict",
"-n = int(eval(input()))",
"-S = [input()[0] for _ in range(n)]",
"-C = Counter(S)",
"-ans = 0",
"-for i, j, k in combinations([\"M\", \"A\", \"R\", \"C\", \"H\"], 3):",
"- ans += C[i] * C[j] * C[k]",
"-print(ans)",
"+",
"+def main():",
"+ n = int(eval(input()))",
"+ d = defaultdict(int)",
"+ for _ in range(n):",
"+ s = eval(input())",
"+ d[s[0]] += 1",
"+ ans = 0",
"+ for i, j, k in combinations(\"MARCH\", 3):",
"+ ans += d[i] * d[j] * d[k]",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.04511 | 0.044542 | 1.012758 | [
"s390807506",
"s365403380"
] |
u426534722 | p02243 | python | s480015958 | s004827551 | 910 | 440 | 49,928 | 40,508 | Accepted | Accepted | 51.65 | import sys
readline = sys.stdin.readline
from heapq import heapify, heappush, heappop
INF = float("inf")
def MAIN():
n = int(eval(input()))
G = [[i, INF] for i in range(n)]
G[0][1] = 0
m = {}
for _ in range(n):
A = list(map(int, readline().split()))
m[A[0]] = {}
for i in range(2, len(A), 2):
m[A[0]][A[i]] = A[i + 1]
dp = [(0, 0)]
while dp:
cost, u = heappop(dp)
for v, c in list(m[u].items()):
if G[v][1] > G[u][1] + c:
G[v][1] = G[u][1] + c
heappush(dp, (G[v][1], v))
print(("\n".join(" ".join(map(str, a)) for a in G)))
MAIN()
| import heapq
import sys
readline = sys.stdin.readline
def dijkstra(n):
inf = 10 ** 6 + 1
dist = [0] + [inf] * (n - 1)
q = [(0, 0)]
while q:
u = heapq.heappop(q)[1]
for (v, c) in edge[u]:
alt = dist[u] + c
if dist[v] > alt:
dist[v] = alt
heapq.heappush(q, (alt, v))
return dist
n = int(eval(input()))
edge = [[]] * n
for _ in range(n):
l = list(map(int, readline().split()))
edge[l[0]] = (e for e in zip(l[2::2], l[3::2]))
for i, c in enumerate(dijkstra(n)):
print((i, c))
| 24 | 22 | 669 | 589 | import sys
readline = sys.stdin.readline
from heapq import heapify, heappush, heappop
INF = float("inf")
def MAIN():
n = int(eval(input()))
G = [[i, INF] for i in range(n)]
G[0][1] = 0
m = {}
for _ in range(n):
A = list(map(int, readline().split()))
m[A[0]] = {}
for i in range(2, len(A), 2):
m[A[0]][A[i]] = A[i + 1]
dp = [(0, 0)]
while dp:
cost, u = heappop(dp)
for v, c in list(m[u].items()):
if G[v][1] > G[u][1] + c:
G[v][1] = G[u][1] + c
heappush(dp, (G[v][1], v))
print(("\n".join(" ".join(map(str, a)) for a in G)))
MAIN()
| import heapq
import sys
readline = sys.stdin.readline
def dijkstra(n):
inf = 10**6 + 1
dist = [0] + [inf] * (n - 1)
q = [(0, 0)]
while q:
u = heapq.heappop(q)[1]
for (v, c) in edge[u]:
alt = dist[u] + c
if dist[v] > alt:
dist[v] = alt
heapq.heappush(q, (alt, v))
return dist
n = int(eval(input()))
edge = [[]] * n
for _ in range(n):
l = list(map(int, readline().split()))
edge[l[0]] = (e for e in zip(l[2::2], l[3::2]))
for i, c in enumerate(dijkstra(n)):
print((i, c))
| false | 8.333333 | [
"+import heapq",
"-from heapq import heapify, heappush, heappop",
"-",
"-INF = float(\"inf\")",
"-def MAIN():",
"- n = int(eval(input()))",
"- G = [[i, INF] for i in range(n)]",
"- G[0][1] = 0",
"- m = {}",
"- for _ in range(n):",
"- A = list(map(int, readline().split()))",
"- m[A[0]] = {}",
"- for i in range(2, len(A), 2):",
"- m[A[0]][A[i]] = A[i + 1]",
"- dp = [(0, 0)]",
"- while dp:",
"- cost, u = heappop(dp)",
"- for v, c in list(m[u].items()):",
"- if G[v][1] > G[u][1] + c:",
"- G[v][1] = G[u][1] + c",
"- heappush(dp, (G[v][1], v))",
"- print((\"\\n\".join(\" \".join(map(str, a)) for a in G)))",
"+def dijkstra(n):",
"+ inf = 10**6 + 1",
"+ dist = [0] + [inf] * (n - 1)",
"+ q = [(0, 0)]",
"+ while q:",
"+ u = heapq.heappop(q)[1]",
"+ for (v, c) in edge[u]:",
"+ alt = dist[u] + c",
"+ if dist[v] > alt:",
"+ dist[v] = alt",
"+ heapq.heappush(q, (alt, v))",
"+ return dist",
"-MAIN()",
"+n = int(eval(input()))",
"+edge = [[]] * n",
"+for _ in range(n):",
"+ l = list(map(int, readline().split()))",
"+ edge[l[0]] = (e for e in zip(l[2::2], l[3::2]))",
"+for i, c in enumerate(dijkstra(n)):",
"+ print((i, c))"
] | false | 0.035825 | 0.047152 | 0.75976 | [
"s480015958",
"s004827551"
] |
u633255271 | p02684 | python | s435031175 | s748687279 | 159 | 147 | 32,376 | 32,336 | Accepted | Accepted | 7.55 | N, K = list(map(int, input().split()))
A = list([int(x) - 1 for x in input().split()])
now = 0
seen = []
while True:
seen.append(now)
teleporter = A[now]
A[now] = 'used'
if teleporter == 'used':
break
else:
now = teleporter
loop_s = seen.index(seen[-1])
size = len(seen) - loop_s - 1
if K <= loop_s:
print((seen[K] + 1))
else:
print((seen[loop_s +(K - loop_s) % size] + 1)) | N, K = list(map(int, input().split()))
A = list([int(x) - 1 for x in input().split()])
now = 0
seen = []
while True:
seen.append(now)
teleporter = A[now]
A[now] = 'used'
if teleporter == 'used':
break
else:
now = teleporter
loop_s = seen.index(now)
size = len(seen) - loop_s - 1
if K <= loop_s:
print((seen[K] + 1))
else:
print((seen[loop_s +(K - loop_s) % size] + 1)) | 21 | 21 | 443 | 438 | N, K = list(map(int, input().split()))
A = list([int(x) - 1 for x in input().split()])
now = 0
seen = []
while True:
seen.append(now)
teleporter = A[now]
A[now] = "used"
if teleporter == "used":
break
else:
now = teleporter
loop_s = seen.index(seen[-1])
size = len(seen) - loop_s - 1
if K <= loop_s:
print((seen[K] + 1))
else:
print((seen[loop_s + (K - loop_s) % size] + 1))
| N, K = list(map(int, input().split()))
A = list([int(x) - 1 for x in input().split()])
now = 0
seen = []
while True:
seen.append(now)
teleporter = A[now]
A[now] = "used"
if teleporter == "used":
break
else:
now = teleporter
loop_s = seen.index(now)
size = len(seen) - loop_s - 1
if K <= loop_s:
print((seen[K] + 1))
else:
print((seen[loop_s + (K - loop_s) % size] + 1))
| false | 0 | [
"-loop_s = seen.index(seen[-1])",
"+loop_s = seen.index(now)"
] | false | 0.043248 | 0.099753 | 0.433549 | [
"s435031175",
"s748687279"
] |
u796942881 | p03252 | python | s212425844 | s747427960 | 129 | 114 | 3,632 | 3,632 | Accepted | Accepted | 11.63 | from sys import stdin
def main():
S = stdin.readline().strip()
T = stdin.readline().strip()
lst = [""] * (ord("z") - ord("a") + 1)
flg = True
for s, t in zip(S, T):
# 同アルファベット、違アルファベット変換チェック
if lst[ord(s) - ord("a")] and lst[ord(s) - ord("a")] != t:
flg = False
break
lst[ord(s) - ord("a")] = t
lst = [i for i in lst if i != ""]
# 変換先の重複チェック
if len(lst) != len(set(lst)):
flg = False
print(("Yes" if flg else "No"))
return
main()
| def main():
S = eval(input())
T = eval(input())
lst = [""] * (ord("z") - ord("a") + 1)
flg = True
for s, t in zip(S, T):
# 同アルファベット、違アルファベット変換チェック
if lst[ord(s) - ord("a")] and lst[ord(s) - ord("a")] != t:
flg = False
break
lst[ord(s) - ord("a")] = t
lst = [i for i in lst if i != ""]
# 変換先の重複チェック
if len(lst) != len(set(lst)):
flg = False
print(("Yes" if flg else "No"))
return
main()
| 23 | 20 | 550 | 489 | from sys import stdin
def main():
S = stdin.readline().strip()
T = stdin.readline().strip()
lst = [""] * (ord("z") - ord("a") + 1)
flg = True
for s, t in zip(S, T):
# 同アルファベット、違アルファベット変換チェック
if lst[ord(s) - ord("a")] and lst[ord(s) - ord("a")] != t:
flg = False
break
lst[ord(s) - ord("a")] = t
lst = [i for i in lst if i != ""]
# 変換先の重複チェック
if len(lst) != len(set(lst)):
flg = False
print(("Yes" if flg else "No"))
return
main()
| def main():
S = eval(input())
T = eval(input())
lst = [""] * (ord("z") - ord("a") + 1)
flg = True
for s, t in zip(S, T):
# 同アルファベット、違アルファベット変換チェック
if lst[ord(s) - ord("a")] and lst[ord(s) - ord("a")] != t:
flg = False
break
lst[ord(s) - ord("a")] = t
lst = [i for i in lst if i != ""]
# 変換先の重複チェック
if len(lst) != len(set(lst)):
flg = False
print(("Yes" if flg else "No"))
return
main()
| false | 13.043478 | [
"-from sys import stdin",
"-",
"-",
"- S = stdin.readline().strip()",
"- T = stdin.readline().strip()",
"+ S = eval(input())",
"+ T = eval(input())"
] | false | 0.057991 | 0.035315 | 1.642082 | [
"s212425844",
"s747427960"
] |
u688587139 | p02725 | python | s091397614 | s569941307 | 162 | 119 | 26,436 | 26,444 | Accepted | Accepted | 26.54 | K, N = list(map(int, input().split()))
loc = list(map(int, input().split()))
distances = []
total = []
for i in range(N-1):
distances.append(loc[i+1] - loc[i])
distances.append(loc[0] + K - loc[N-1])
for i in range(N):
total.append(K - distances[i])
print((min(total)))
| K, N = list(map(int, input().split()))
loc = list(map(int, input().split()))
distances = []
total = []
for i in range(N-1):
distances.append(loc[i+1] - loc[i])
distances.append(loc[0] + K - loc[N-1])
max_dis = max(distances)
print((K - max_dis))
| 14 | 12 | 287 | 256 | K, N = list(map(int, input().split()))
loc = list(map(int, input().split()))
distances = []
total = []
for i in range(N - 1):
distances.append(loc[i + 1] - loc[i])
distances.append(loc[0] + K - loc[N - 1])
for i in range(N):
total.append(K - distances[i])
print((min(total)))
| K, N = list(map(int, input().split()))
loc = list(map(int, input().split()))
distances = []
total = []
for i in range(N - 1):
distances.append(loc[i + 1] - loc[i])
distances.append(loc[0] + K - loc[N - 1])
max_dis = max(distances)
print((K - max_dis))
| false | 14.285714 | [
"-for i in range(N):",
"- total.append(K - distances[i])",
"-print((min(total)))",
"+max_dis = max(distances)",
"+print((K - max_dis))"
] | false | 0.063836 | 0.082115 | 0.777398 | [
"s091397614",
"s569941307"
] |
u681444474 | p03311 | python | s946892933 | s374046835 | 254 | 140 | 32,312 | 107,844 | Accepted | Accepted | 44.88 | # coding: utf-8
import math
n = int(eval(input()))
#x, y = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
B= []
for i in range(n):
B.append(A[i]-(i+1))
B.sort()
if n==1:
m=B[0]
m2=B[0]
else:
m = B[n//2]
m2=B[n//2+1]
tmp1=0
tmp2=0
#print(m,m2)
for i in range(n):
tmp1 += abs(A[i]-(i+1)-m)
tmp2 += abs(A[i]-(i+1)-m2)
print((min(tmp1, tmp2))) | # coding: utf-8
n = int(eval(input()))
A = list(map(int,input().split()))
L=[]
for i in range(n):
L.append(A[i]-(i+1))
L.sort()
#print(L)
if n==1:
b1=L[0]
b2=L[0]
elif n==2:
b1=L[0]
b2=L[1]
else:
b1=L[n//2]
b2=L[n//2-1]
ans=0
cnt1=0
cnt2=0
for i in range(n):
cnt1+=abs(L[i]-b1)
cnt2+=abs(L[i]-b2)
print((min(cnt1,cnt2))) | 23 | 24 | 403 | 371 | # coding: utf-8
import math
n = int(eval(input()))
# x, y = map(int,input().split())
A = list(map(int, input().split()))
ans = 0
B = []
for i in range(n):
B.append(A[i] - (i + 1))
B.sort()
if n == 1:
m = B[0]
m2 = B[0]
else:
m = B[n // 2]
m2 = B[n // 2 + 1]
tmp1 = 0
tmp2 = 0
# print(m,m2)
for i in range(n):
tmp1 += abs(A[i] - (i + 1) - m)
tmp2 += abs(A[i] - (i + 1) - m2)
print((min(tmp1, tmp2)))
| # coding: utf-8
n = int(eval(input()))
A = list(map(int, input().split()))
L = []
for i in range(n):
L.append(A[i] - (i + 1))
L.sort()
# print(L)
if n == 1:
b1 = L[0]
b2 = L[0]
elif n == 2:
b1 = L[0]
b2 = L[1]
else:
b1 = L[n // 2]
b2 = L[n // 2 - 1]
ans = 0
cnt1 = 0
cnt2 = 0
for i in range(n):
cnt1 += abs(L[i] - b1)
cnt2 += abs(L[i] - b2)
print((min(cnt1, cnt2)))
| false | 4.166667 | [
"-import math",
"-",
"-# x, y = map(int,input().split())",
"+L = []",
"+for i in range(n):",
"+ L.append(A[i] - (i + 1))",
"+L.sort()",
"+# print(L)",
"+if n == 1:",
"+ b1 = L[0]",
"+ b2 = L[0]",
"+elif n == 2:",
"+ b1 = L[0]",
"+ b2 = L[1]",
"+else:",
"+ b1 = L[n // 2]",
"+ b2 = L[n // 2 - 1]",
"-B = []",
"+cnt1 = 0",
"+cnt2 = 0",
"- B.append(A[i] - (i + 1))",
"-B.sort()",
"-if n == 1:",
"- m = B[0]",
"- m2 = B[0]",
"-else:",
"- m = B[n // 2]",
"- m2 = B[n // 2 + 1]",
"-tmp1 = 0",
"-tmp2 = 0",
"-# print(m,m2)",
"-for i in range(n):",
"- tmp1 += abs(A[i] - (i + 1) - m)",
"- tmp2 += abs(A[i] - (i + 1) - m2)",
"-print((min(tmp1, tmp2)))",
"+ cnt1 += abs(L[i] - b1)",
"+ cnt2 += abs(L[i] - b2)",
"+print((min(cnt1, cnt2)))"
] | false | 0.03752 | 0.055051 | 0.681549 | [
"s946892933",
"s374046835"
] |
u995102075 | p02936 | python | s144133149 | s195223437 | 1,865 | 1,234 | 100,976 | 66,528 | Accepted | Accepted | 33.83 | N, Q = list(map(int, input().split()))
tree = {}
for i in range(1, N + 1):
tree[i] = []
for i in range(N - 1):
a, b = list(map(int, input().split()))
tree[a] += [b]
count = [0] * (N + 1)
for i in range(Q):
p, x = list(map(int, input().split()))
count[p] += x
stack = [1]
while stack:
label = stack.pop()
if tree[label] != []:
for next_label in tree[label]:
count[next_label] += count[label]
stack += tree[label]
print((*count[1:]))
| import sys
def input():
return sys.stdin.readline()[:-1]
N, Q = list(map(int, input().split()))
tree = {}
for i in range(1, N + 1):
tree[i] = []
for i in range(N - 1):
a, b = list(map(int, input().split()))
tree[a] += [b]
count = [0] * (N + 1)
for i in range(Q):
p, x = list(map(int, input().split()))
count[p] += x
stack = [1]
while stack:
label = stack.pop()
if tree[label] != []:
for next_label in tree[label]:
count[next_label] += count[label]
stack += tree[label]
ans = count[1:]
print((*ans))
| 23 | 31 | 494 | 577 | N, Q = list(map(int, input().split()))
tree = {}
for i in range(1, N + 1):
tree[i] = []
for i in range(N - 1):
a, b = list(map(int, input().split()))
tree[a] += [b]
count = [0] * (N + 1)
for i in range(Q):
p, x = list(map(int, input().split()))
count[p] += x
stack = [1]
while stack:
label = stack.pop()
if tree[label] != []:
for next_label in tree[label]:
count[next_label] += count[label]
stack += tree[label]
print((*count[1:]))
| import sys
def input():
return sys.stdin.readline()[:-1]
N, Q = list(map(int, input().split()))
tree = {}
for i in range(1, N + 1):
tree[i] = []
for i in range(N - 1):
a, b = list(map(int, input().split()))
tree[a] += [b]
count = [0] * (N + 1)
for i in range(Q):
p, x = list(map(int, input().split()))
count[p] += x
stack = [1]
while stack:
label = stack.pop()
if tree[label] != []:
for next_label in tree[label]:
count[next_label] += count[label]
stack += tree[label]
ans = count[1:]
print((*ans))
| false | 25.806452 | [
"+import sys",
"+",
"+",
"+def input():",
"+ return sys.stdin.readline()[:-1]",
"+",
"+",
"-print((*count[1:]))",
"+ans = count[1:]",
"+print((*ans))"
] | false | 0.045439 | 0.144082 | 0.315367 | [
"s144133149",
"s195223437"
] |
u591589288 | p02861 | python | s741449154 | s313292744 | 268 | 219 | 43,612 | 41,580 | Accepted | Accepted | 18.28 | #!/usr/bin/env python
import sys
from math import sqrt
def _s(): return sys.stdin.readline().strip()
def _i(): return int(sys.stdin.readline().strip())
def _ia(): return [ int(x) for x in sys.stdin.readline().strip().split() ]
def g(a):
if len(a)==1:
yield a
else:
for i in range(len(a)):
ai = a[i]
for aa in g(a[:i]+a[i+1:]):
yield [ ai ] + aa
n = _i()
xy = [ _ia() for _ in range(n) ]
s = 0
c = 0
for a in g(xy):
dist = 0
prev = None
for nxt in a:
if prev:
dist += sqrt( (prev[0]-nxt[0])**2 + (prev[1]-nxt[1])**2 )
prev = nxt
s += dist
c +=1
#
print((s/c))
| #!/usr/bin/env python
import sys
from math import sqrt, factorial
from itertools import permutations
def _i(): return int(sys.stdin.readline().strip())
def _ia(): return [int(x) for x in sys.stdin.readline().strip().split()]
n = _i()
xy = [_ia() for _ in range(n)]
tot = 0
for s in permutations([i for i in range(n)]):
i = s[0]
tmp = 0
for j in s[1:]:
dx = xy[i][0] - xy[j][0]
dy = xy[i][1] - xy[j][1]
tmp += sqrt(dx ** 2 + dy ** 2)
i = j
tot += tmp
print((tot / factorial(n)))
| 35 | 24 | 717 | 552 | #!/usr/bin/env python
import sys
from math import sqrt
def _s():
return sys.stdin.readline().strip()
def _i():
return int(sys.stdin.readline().strip())
def _ia():
return [int(x) for x in sys.stdin.readline().strip().split()]
def g(a):
if len(a) == 1:
yield a
else:
for i in range(len(a)):
ai = a[i]
for aa in g(a[:i] + a[i + 1 :]):
yield [ai] + aa
n = _i()
xy = [_ia() for _ in range(n)]
s = 0
c = 0
for a in g(xy):
dist = 0
prev = None
for nxt in a:
if prev:
dist += sqrt((prev[0] - nxt[0]) ** 2 + (prev[1] - nxt[1]) ** 2)
prev = nxt
s += dist
c += 1
#
print((s / c))
| #!/usr/bin/env python
import sys
from math import sqrt, factorial
from itertools import permutations
def _i():
return int(sys.stdin.readline().strip())
def _ia():
return [int(x) for x in sys.stdin.readline().strip().split()]
n = _i()
xy = [_ia() for _ in range(n)]
tot = 0
for s in permutations([i for i in range(n)]):
i = s[0]
tmp = 0
for j in s[1:]:
dx = xy[i][0] - xy[j][0]
dy = xy[i][1] - xy[j][1]
tmp += sqrt(dx**2 + dy**2)
i = j
tot += tmp
print((tot / factorial(n)))
| false | 31.428571 | [
"-from math import sqrt",
"-",
"-",
"-def _s():",
"- return sys.stdin.readline().strip()",
"+from math import sqrt, factorial",
"+from itertools import permutations",
"-def g(a):",
"- if len(a) == 1:",
"- yield a",
"- else:",
"- for i in range(len(a)):",
"- ai = a[i]",
"- for aa in g(a[:i] + a[i + 1 :]):",
"- yield [ai] + aa",
"-",
"-",
"-s = 0",
"-c = 0",
"-for a in g(xy):",
"- dist = 0",
"- prev = None",
"- for nxt in a:",
"- if prev:",
"- dist += sqrt((prev[0] - nxt[0]) ** 2 + (prev[1] - nxt[1]) ** 2)",
"- prev = nxt",
"- s += dist",
"- c += 1",
"-#",
"-print((s / c))",
"+tot = 0",
"+for s in permutations([i for i in range(n)]):",
"+ i = s[0]",
"+ tmp = 0",
"+ for j in s[1:]:",
"+ dx = xy[i][0] - xy[j][0]",
"+ dy = xy[i][1] - xy[j][1]",
"+ tmp += sqrt(dx**2 + dy**2)",
"+ i = j",
"+ tot += tmp",
"+print((tot / factorial(n)))"
] | false | 0.077538 | 0.1136 | 0.682555 | [
"s741449154",
"s313292744"
] |
u802963389 | p03244 | python | s127800585 | s269692414 | 119 | 74 | 23,776 | 23,004 | Accepted | Accepted | 37.82 | from collections import Counter
n = int(eval(input()))
s = list(map(int, input().split()))
evenL = []
oddL = []
for i, v in enumerate(s):
if i % 2 == 0:
evenL.append(v)
else:
oddL.append(v)
evenLc = Counter(evenL)
oddLc = Counter(oddL)
evenLcs = sorted(list(evenLc.items()), key=lambda x: -x[1])
oddLcs = sorted(list(oddLc.items()), key=lambda x: -x[1])
if evenLcs[0][0] != oddLcs[0][0]:
print((n - evenLcs[0][1] - oddLcs[0][1]))
else:
if len(evenLc) == 1 and len(oddLc) == 1:
print((n - len(evenL)))
exit()
if evenLcs[0][1] > oddLcs[0][1]:
print((n - evenLcs[0][1] - oddLcs[1][1]))
elif evenLcs[0][1] < oddLcs[0][1]:
print((n - evenLcs[1][1] - oddLcs[0][1]))
else:
print((n - evenLcs[0][1] - max(evenLcs[1][1], oddLcs[1][1]))) | from collections import Counter as C
n = int(eval(input()))
V = list(input().split())
V1 = C(V[::2]).most_common()
V2 = C(V[1::2]).most_common()
if V1[0][0] != V2[0][0]:
ans = n - (V1[0][1] + V2[0][1])
else:
l = V1[0][1] + V2[1][1] if len(V2) > 1 else V1[0][1]
r = V1[1][1] + V2[0][1] if len(V1) > 1 else V2[0][1]
if l >= r:
ans = n - l
else:
ans = n - r
print(ans) | 29 | 17 | 776 | 396 | from collections import Counter
n = int(eval(input()))
s = list(map(int, input().split()))
evenL = []
oddL = []
for i, v in enumerate(s):
if i % 2 == 0:
evenL.append(v)
else:
oddL.append(v)
evenLc = Counter(evenL)
oddLc = Counter(oddL)
evenLcs = sorted(list(evenLc.items()), key=lambda x: -x[1])
oddLcs = sorted(list(oddLc.items()), key=lambda x: -x[1])
if evenLcs[0][0] != oddLcs[0][0]:
print((n - evenLcs[0][1] - oddLcs[0][1]))
else:
if len(evenLc) == 1 and len(oddLc) == 1:
print((n - len(evenL)))
exit()
if evenLcs[0][1] > oddLcs[0][1]:
print((n - evenLcs[0][1] - oddLcs[1][1]))
elif evenLcs[0][1] < oddLcs[0][1]:
print((n - evenLcs[1][1] - oddLcs[0][1]))
else:
print((n - evenLcs[0][1] - max(evenLcs[1][1], oddLcs[1][1])))
| from collections import Counter as C
n = int(eval(input()))
V = list(input().split())
V1 = C(V[::2]).most_common()
V2 = C(V[1::2]).most_common()
if V1[0][0] != V2[0][0]:
ans = n - (V1[0][1] + V2[0][1])
else:
l = V1[0][1] + V2[1][1] if len(V2) > 1 else V1[0][1]
r = V1[1][1] + V2[0][1] if len(V1) > 1 else V2[0][1]
if l >= r:
ans = n - l
else:
ans = n - r
print(ans)
| false | 41.37931 | [
"-from collections import Counter",
"+from collections import Counter as C",
"-s = list(map(int, input().split()))",
"-evenL = []",
"-oddL = []",
"-for i, v in enumerate(s):",
"- if i % 2 == 0:",
"- evenL.append(v)",
"+V = list(input().split())",
"+V1 = C(V[::2]).most_common()",
"+V2 = C(V[1::2]).most_common()",
"+if V1[0][0] != V2[0][0]:",
"+ ans = n - (V1[0][1] + V2[0][1])",
"+else:",
"+ l = V1[0][1] + V2[1][1] if len(V2) > 1 else V1[0][1]",
"+ r = V1[1][1] + V2[0][1] if len(V1) > 1 else V2[0][1]",
"+ if l >= r:",
"+ ans = n - l",
"- oddL.append(v)",
"-evenLc = Counter(evenL)",
"-oddLc = Counter(oddL)",
"-evenLcs = sorted(list(evenLc.items()), key=lambda x: -x[1])",
"-oddLcs = sorted(list(oddLc.items()), key=lambda x: -x[1])",
"-if evenLcs[0][0] != oddLcs[0][0]:",
"- print((n - evenLcs[0][1] - oddLcs[0][1]))",
"-else:",
"- if len(evenLc) == 1 and len(oddLc) == 1:",
"- print((n - len(evenL)))",
"- exit()",
"- if evenLcs[0][1] > oddLcs[0][1]:",
"- print((n - evenLcs[0][1] - oddLcs[1][1]))",
"- elif evenLcs[0][1] < oddLcs[0][1]:",
"- print((n - evenLcs[1][1] - oddLcs[0][1]))",
"- else:",
"- print((n - evenLcs[0][1] - max(evenLcs[1][1], oddLcs[1][1])))",
"+ ans = n - r",
"+print(ans)"
] | false | 0.03765 | 0.038573 | 0.976054 | [
"s127800585",
"s269692414"
] |
u375616706 | p02703 | python | s164421145 | s059267684 | 1,183 | 550 | 175,132 | 135,644 | Accepted | Accepted | 53.51 | from collections import defaultdict
import heapq
N,M,S = list(map(int,input().split()))
Edges=[list(map(int,input().split())) for _ in range(M)]
Exchanges=[list(map(int,input().split())) for _ in range(N)]
max_money=max([a for _,_,a,_ in Edges])*N
Graph=defaultdict(lambda :[])
#nodeと状態は tupleで管理する。(node,money)
#Graph[cur_state]=[ (cost,next_state),...]
for u,v,a,b in Edges:
u-=1;v-=1
for cur_money in range(max_money+1):
if cur_money-a<0:#お金が足りなくて移動できない
continue
from_state_u=(u,cur_money)
to_state_v=(v,cur_money-a)
Graph[from_state_u].append((b,to_state_v))
from_state_v=(v,cur_money)
to_state_u=(u,cur_money-a)
Graph[from_state_v].append((b,to_state_u))
for n,[c,d] in enumerate(Exchanges):
for cur_money in range(max_money+1):
after_money=min(max_money,cur_money+c)#両替後のお金(money_max以上は同じにする)
from_state=(n,cur_money)
to_state=(n,after_money)
Graph[from_state].append((d,to_state))
# Dijksttra する
#startの状態(Sがmax_moneyより大きいならmax_moneyにする)
start=(0,min(max_money,S))
Q=[(0,start)]
dist=defaultdict(lambda :float('inf'))
dist[start]=0
while Q:
q = heapq.heappop(Q)
cur_time,cur_state=q
if dist[cur_state]<cur_time:
continue
for cost,next_state in Graph[cur_state]:
next_time = cost+cur_time
if dist[next_state]>next_time:
dist[next_state]=next_time
heapq.heappush(Q,(next_time,next_state))
for dest in range(1,N):
ans=float("inf")
#goal次の所持金は関係ないので、ある頂点のあらゆる所持金に対してminをとる
for a in range(max_money+1):
state=(dest,a)
ans=min(ans,dist[state])
print(ans)
| from collections import defaultdict
import heapq
class Dijkstra:
"""
dijkstraの最短経路問題を解く
input:
S: start node
adj: adj[a]=[(b,dist)]//なんとなく
"""
def __init__(self, start, num_node, adj):
"""
adj: adj[a]=[(b,dist)]
num_node: num of nodes
dist: dist from start_node
prev: 最短経路において、一つ前のノードを記憶。経路復元に使う?
"""
self.start_node = start
self.adj= adj
self.num_node = num_node
self.dist = [float('inf')]*num_node
self.prev = defaultdict(lambda: None)
# dist form S to S = 0
self.dist[start] = 0
def calc_dist(self):
"""
最短経路 distを計算する
Q: content (dist_from_start,node)
Qはheapqとして使う。dist_from_startの小さい順になる
Qには、dist*N+nodeを入れることで高速化
"""
Q = []
heapq.heappush(Q, self.start_node)
while Q:
dist_to_node, node = divmod(heapq.heappop(Q),self.num_node)
# 現在の値よりも大きくて、更新にならない場合
if self.dist[node] < dist_to_node:
continue
# 次のホップを計算する
for nex,weight in self.adj[node]:
cand = dist_to_node + weight
if self.dist[nex] > cand: # update
self.dist[nex] = cand
self.prev[nex] = node
heapq.heappush(Q, cand*self.num_node+nex)
def get_dist(self, d):
"""
startからdまでの距離を返す
これの前にcalc()を実行しておく
たどり着けない場合は、float('inf')がかえる
"""
return self.dist[d]
def get_path(self,dst):
"""
startからdstまでのpathをlistでreturn
valifyしてないので怪しい
"""
cur=dst
ret=[cur]
while cur!=self.start_node:
cur=self.prev[cur]
ret.append(cur)
return list(reversed(ret))
N,M,S = list(map(int,input().split()))
edges=[list(map(int,input().split())) for _ in range(M)]
C=[list(map(int,input().split())) for _ in range(N)]
max_c=2501
def toId(node,cur):
return node*max_c+cur
def revId(id):
return id//max_c,id%max_c
states=N*max_c
adj=[[] for _ in range(states)]
for a,b,c,d in edges:
a-=1
b-=1
for cc in range(max_c-c):
adj[toId(a,cc+c)].append((toId(b,cc),d))
adj[toId(b,cc+c)].append((toId(a,cc),d))
for i,(c,d) in enumerate(C):
for cc in range(max_c-c):
adj[toId(i,cc)].append(((toId(i,cc+c),d)))
#for i,a in enumerate(adj):
# print("from {}".format(revId(i)))
# for v,d in a:
# print("\t: {} cost:{}".format(revId(v),d))
S=min(S,max_c-1)
start=toId(0,S)
D=Dijkstra(start,states,adj)
D.calc_dist()
for i in range(1,N):
ans=float("inf")
path=None
for cc in range(max_c):
if ans>D.get_dist(toId(i,cc)):
ans=D.get_dist(toId(i,cc))
path=D.get_path(toId(i,cc))
print(ans)
| 66 | 119 | 1,740 | 2,986 | from collections import defaultdict
import heapq
N, M, S = list(map(int, input().split()))
Edges = [list(map(int, input().split())) for _ in range(M)]
Exchanges = [list(map(int, input().split())) for _ in range(N)]
max_money = max([a for _, _, a, _ in Edges]) * N
Graph = defaultdict(lambda: [])
# nodeと状態は tupleで管理する。(node,money)
# Graph[cur_state]=[ (cost,next_state),...]
for u, v, a, b in Edges:
u -= 1
v -= 1
for cur_money in range(max_money + 1):
if cur_money - a < 0: # お金が足りなくて移動できない
continue
from_state_u = (u, cur_money)
to_state_v = (v, cur_money - a)
Graph[from_state_u].append((b, to_state_v))
from_state_v = (v, cur_money)
to_state_u = (u, cur_money - a)
Graph[from_state_v].append((b, to_state_u))
for n, [c, d] in enumerate(Exchanges):
for cur_money in range(max_money + 1):
after_money = min(max_money, cur_money + c) # 両替後のお金(money_max以上は同じにする)
from_state = (n, cur_money)
to_state = (n, after_money)
Graph[from_state].append((d, to_state))
# Dijksttra する
# startの状態(Sがmax_moneyより大きいならmax_moneyにする)
start = (0, min(max_money, S))
Q = [(0, start)]
dist = defaultdict(lambda: float("inf"))
dist[start] = 0
while Q:
q = heapq.heappop(Q)
cur_time, cur_state = q
if dist[cur_state] < cur_time:
continue
for cost, next_state in Graph[cur_state]:
next_time = cost + cur_time
if dist[next_state] > next_time:
dist[next_state] = next_time
heapq.heappush(Q, (next_time, next_state))
for dest in range(1, N):
ans = float("inf")
# goal次の所持金は関係ないので、ある頂点のあらゆる所持金に対してminをとる
for a in range(max_money + 1):
state = (dest, a)
ans = min(ans, dist[state])
print(ans)
| from collections import defaultdict
import heapq
class Dijkstra:
"""
dijkstraの最短経路問題を解く
input:
S: start node
adj: adj[a]=[(b,dist)]//なんとなく
"""
def __init__(self, start, num_node, adj):
"""
adj: adj[a]=[(b,dist)]
num_node: num of nodes
dist: dist from start_node
prev: 最短経路において、一つ前のノードを記憶。経路復元に使う?
"""
self.start_node = start
self.adj = adj
self.num_node = num_node
self.dist = [float("inf")] * num_node
self.prev = defaultdict(lambda: None)
# dist form S to S = 0
self.dist[start] = 0
def calc_dist(self):
"""
最短経路 distを計算する
Q: content (dist_from_start,node)
Qはheapqとして使う。dist_from_startの小さい順になる
Qには、dist*N+nodeを入れることで高速化
"""
Q = []
heapq.heappush(Q, self.start_node)
while Q:
dist_to_node, node = divmod(heapq.heappop(Q), self.num_node)
# 現在の値よりも大きくて、更新にならない場合
if self.dist[node] < dist_to_node:
continue
# 次のホップを計算する
for nex, weight in self.adj[node]:
cand = dist_to_node + weight
if self.dist[nex] > cand: # update
self.dist[nex] = cand
self.prev[nex] = node
heapq.heappush(Q, cand * self.num_node + nex)
def get_dist(self, d):
"""
startからdまでの距離を返す
これの前にcalc()を実行しておく
たどり着けない場合は、float('inf')がかえる
"""
return self.dist[d]
def get_path(self, dst):
"""
startからdstまでのpathをlistでreturn
valifyしてないので怪しい
"""
cur = dst
ret = [cur]
while cur != self.start_node:
cur = self.prev[cur]
ret.append(cur)
return list(reversed(ret))
N, M, S = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(M)]
C = [list(map(int, input().split())) for _ in range(N)]
max_c = 2501
def toId(node, cur):
return node * max_c + cur
def revId(id):
return id // max_c, id % max_c
states = N * max_c
adj = [[] for _ in range(states)]
for a, b, c, d in edges:
a -= 1
b -= 1
for cc in range(max_c - c):
adj[toId(a, cc + c)].append((toId(b, cc), d))
adj[toId(b, cc + c)].append((toId(a, cc), d))
for i, (c, d) in enumerate(C):
for cc in range(max_c - c):
adj[toId(i, cc)].append(((toId(i, cc + c), d)))
# for i,a in enumerate(adj):
# print("from {}".format(revId(i)))
# for v,d in a:
# print("\t: {} cost:{}".format(revId(v),d))
S = min(S, max_c - 1)
start = toId(0, S)
D = Dijkstra(start, states, adj)
D.calc_dist()
for i in range(1, N):
ans = float("inf")
path = None
for cc in range(max_c):
if ans > D.get_dist(toId(i, cc)):
ans = D.get_dist(toId(i, cc))
path = D.get_path(toId(i, cc))
print(ans)
| false | 44.537815 | [
"+",
"+class Dijkstra:",
"+ \"\"\"",
"+ dijkstraの最短経路問題を解く",
"+ input:",
"+ S: start node",
"+ adj: adj[a]=[(b,dist)]//なんとなく",
"+ \"\"\"",
"+",
"+ def __init__(self, start, num_node, adj):",
"+ \"\"\"",
"+ adj: adj[a]=[(b,dist)]",
"+ num_node: num of nodes",
"+ dist: dist from start_node",
"+ prev: 最短経路において、一つ前のノードを記憶。経路復元に使う?",
"+ \"\"\"",
"+ self.start_node = start",
"+ self.adj = adj",
"+ self.num_node = num_node",
"+ self.dist = [float(\"inf\")] * num_node",
"+ self.prev = defaultdict(lambda: None)",
"+ # dist form S to S = 0",
"+ self.dist[start] = 0",
"+",
"+ def calc_dist(self):",
"+ \"\"\"",
"+ 最短経路 distを計算する",
"+ Q: content (dist_from_start,node)",
"+ Qはheapqとして使う。dist_from_startの小さい順になる",
"+ Qには、dist*N+nodeを入れることで高速化",
"+ \"\"\"",
"+ Q = []",
"+ heapq.heappush(Q, self.start_node)",
"+ while Q:",
"+ dist_to_node, node = divmod(heapq.heappop(Q), self.num_node)",
"+ # 現在の値よりも大きくて、更新にならない場合",
"+ if self.dist[node] < dist_to_node:",
"+ continue",
"+ # 次のホップを計算する",
"+ for nex, weight in self.adj[node]:",
"+ cand = dist_to_node + weight",
"+ if self.dist[nex] > cand: # update",
"+ self.dist[nex] = cand",
"+ self.prev[nex] = node",
"+ heapq.heappush(Q, cand * self.num_node + nex)",
"+",
"+ def get_dist(self, d):",
"+ \"\"\"",
"+ startからdまでの距離を返す",
"+ これの前にcalc()を実行しておく",
"+ たどり着けない場合は、float('inf')がかえる",
"+ \"\"\"",
"+ return self.dist[d]",
"+",
"+ def get_path(self, dst):",
"+ \"\"\"",
"+ startからdstまでのpathをlistでreturn",
"+ valifyしてないので怪しい",
"+ \"\"\"",
"+ cur = dst",
"+ ret = [cur]",
"+ while cur != self.start_node:",
"+ cur = self.prev[cur]",
"+ ret.append(cur)",
"+ return list(reversed(ret))",
"+",
"+",
"-Edges = [list(map(int, input().split())) for _ in range(M)]",
"-Exchanges = [list(map(int, input().split())) for _ in range(N)]",
"-max_money = max([a for _, _, a, _ in Edges]) * N",
"-Graph = defaultdict(lambda: [])",
"-# nodeと状態は tupleで管理する。(node,money)",
"-# Graph[cur_state]=[ (cost,next_state),...]",
"-for u, v, a, b in Edges:",
"- u -= 1",
"- v -= 1",
"- for cur_money in range(max_money + 1):",
"- if cur_money - a < 0: # お金が足りなくて移動できない",
"- continue",
"- from_state_u = (u, cur_money)",
"- to_state_v = (v, cur_money - a)",
"- Graph[from_state_u].append((b, to_state_v))",
"- from_state_v = (v, cur_money)",
"- to_state_u = (u, cur_money - a)",
"- Graph[from_state_v].append((b, to_state_u))",
"-for n, [c, d] in enumerate(Exchanges):",
"- for cur_money in range(max_money + 1):",
"- after_money = min(max_money, cur_money + c) # 両替後のお金(money_max以上は同じにする)",
"- from_state = (n, cur_money)",
"- to_state = (n, after_money)",
"- Graph[from_state].append((d, to_state))",
"-# Dijksttra する",
"-# startの状態(Sがmax_moneyより大きいならmax_moneyにする)",
"-start = (0, min(max_money, S))",
"-Q = [(0, start)]",
"-dist = defaultdict(lambda: float(\"inf\"))",
"-dist[start] = 0",
"-while Q:",
"- q = heapq.heappop(Q)",
"- cur_time, cur_state = q",
"- if dist[cur_state] < cur_time:",
"- continue",
"- for cost, next_state in Graph[cur_state]:",
"- next_time = cost + cur_time",
"- if dist[next_state] > next_time:",
"- dist[next_state] = next_time",
"- heapq.heappush(Q, (next_time, next_state))",
"-for dest in range(1, N):",
"+edges = [list(map(int, input().split())) for _ in range(M)]",
"+C = [list(map(int, input().split())) for _ in range(N)]",
"+max_c = 2501",
"+",
"+",
"+def toId(node, cur):",
"+ return node * max_c + cur",
"+",
"+",
"+def revId(id):",
"+ return id // max_c, id % max_c",
"+",
"+",
"+states = N * max_c",
"+adj = [[] for _ in range(states)]",
"+for a, b, c, d in edges:",
"+ a -= 1",
"+ b -= 1",
"+ for cc in range(max_c - c):",
"+ adj[toId(a, cc + c)].append((toId(b, cc), d))",
"+ adj[toId(b, cc + c)].append((toId(a, cc), d))",
"+for i, (c, d) in enumerate(C):",
"+ for cc in range(max_c - c):",
"+ adj[toId(i, cc)].append(((toId(i, cc + c), d)))",
"+# for i,a in enumerate(adj):",
"+# print(\"from {}\".format(revId(i)))",
"+# for v,d in a:",
"+# print(\"\\t: {} cost:{}\".format(revId(v),d))",
"+S = min(S, max_c - 1)",
"+start = toId(0, S)",
"+D = Dijkstra(start, states, adj)",
"+D.calc_dist()",
"+for i in range(1, N):",
"- # goal次の所持金は関係ないので、ある頂点のあらゆる所持金に対してminをとる",
"- for a in range(max_money + 1):",
"- state = (dest, a)",
"- ans = min(ans, dist[state])",
"+ path = None",
"+ for cc in range(max_c):",
"+ if ans > D.get_dist(toId(i, cc)):",
"+ ans = D.get_dist(toId(i, cc))",
"+ path = D.get_path(toId(i, cc))"
] | false | 0.042122 | 0.126896 | 0.331943 | [
"s164421145",
"s059267684"
] |
u186838327 | p02785 | python | s952189566 | s527835458 | 312 | 142 | 88,908 | 105,208 | Accepted | Accepted | 54.49 | n, k = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort(reverse=True)
if k >= len(l):
print((0))
else:
print((sum(l[k:])))
| n, k = list(map(int, input().split()))
H = list(map(int, input().split()))
H.sort(reverse=True)
print((sum(H[k:])))
| 9 | 4 | 154 | 111 | n, k = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort(reverse=True)
if k >= len(l):
print((0))
else:
print((sum(l[k:])))
| n, k = list(map(int, input().split()))
H = list(map(int, input().split()))
H.sort(reverse=True)
print((sum(H[k:])))
| false | 55.555556 | [
"-l = list(map(int, input().split()))",
"-l.sort(reverse=True)",
"-if k >= len(l):",
"- print((0))",
"-else:",
"- print((sum(l[k:])))",
"+H = list(map(int, input().split()))",
"+H.sort(reverse=True)",
"+print((sum(H[k:])))"
] | false | 0.040088 | 0.11492 | 0.348835 | [
"s952189566",
"s527835458"
] |
u392319141 | p03240 | python | s200432834 | s142080923 | 613 | 34 | 46,300 | 3,316 | Accepted | Accepted | 94.45 | N = int(eval(input()))
axis = []
for i in range(N) :
x, y, h = list(map(int, input().split()))
axis.append((x, y, h))
def sol() :
for cx in range(0, 101) :
for cy in range(0, 101) :
axis.sort(key = lambda A : abs(A[0] - cx) + abs(A[1] - cy))
H = axis[0][2] + abs(axis[0][0] - cx) + abs(axis[0][1] - cy)
for x, y, h in axis :
if not h == max(H - abs(x - cx) - abs(y - cy), 0) :
break
else :
return (cx, cy, H)
return (-1, -1, -1)
cx, cy, H = sol()
if cx == -1 :
print('-1')
else :
print(('{} {} {}'.format(cx, cy, H)))
| import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
def sol():
N = int(eval(input()))
points = [tuple(map(int, input().split())) for _ in range(N)]
points.sort(key=itemgetter(2), reverse=True)
for cx in range(101):
for cy in range(101):
bx, by, bh = points[0]
H = bh + abs(cx - bx) + abs(cy - by)
for x, y, h in points:
nowH = max(H - abs(cx - x) - abs(cy - y), 0)
if h != nowH:
break
else:
print((cx, cy, H))
return
sol() | 24 | 26 | 662 | 748 | N = int(eval(input()))
axis = []
for i in range(N):
x, y, h = list(map(int, input().split()))
axis.append((x, y, h))
def sol():
for cx in range(0, 101):
for cy in range(0, 101):
axis.sort(key=lambda A: abs(A[0] - cx) + abs(A[1] - cy))
H = axis[0][2] + abs(axis[0][0] - cx) + abs(axis[0][1] - cy)
for x, y, h in axis:
if not h == max(H - abs(x - cx) - abs(y - cy), 0):
break
else:
return (cx, cy, H)
return (-1, -1, -1)
cx, cy, H = sol()
if cx == -1:
print("-1")
else:
print(("{} {} {}".format(cx, cy, H)))
| import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
def sol():
N = int(eval(input()))
points = [tuple(map(int, input().split())) for _ in range(N)]
points.sort(key=itemgetter(2), reverse=True)
for cx in range(101):
for cy in range(101):
bx, by, bh = points[0]
H = bh + abs(cx - bx) + abs(cy - by)
for x, y, h in points:
nowH = max(H - abs(cx - x) - abs(cy - y), 0)
if h != nowH:
break
else:
print((cx, cy, H))
return
sol()
| false | 7.692308 | [
"-N = int(eval(input()))",
"-axis = []",
"-for i in range(N):",
"- x, y, h = list(map(int, input().split()))",
"- axis.append((x, y, h))",
"+import sys",
"+import heapq",
"+from operator import itemgetter",
"+from collections import deque, defaultdict",
"+from bisect import bisect_left, bisect_right",
"+",
"+input = sys.stdin.readline",
"+sys.setrecursionlimit(10**7)",
"- for cx in range(0, 101):",
"- for cy in range(0, 101):",
"- axis.sort(key=lambda A: abs(A[0] - cx) + abs(A[1] - cy))",
"- H = axis[0][2] + abs(axis[0][0] - cx) + abs(axis[0][1] - cy)",
"- for x, y, h in axis:",
"- if not h == max(H - abs(x - cx) - abs(y - cy), 0):",
"+ N = int(eval(input()))",
"+ points = [tuple(map(int, input().split())) for _ in range(N)]",
"+ points.sort(key=itemgetter(2), reverse=True)",
"+ for cx in range(101):",
"+ for cy in range(101):",
"+ bx, by, bh = points[0]",
"+ H = bh + abs(cx - bx) + abs(cy - by)",
"+ for x, y, h in points:",
"+ nowH = max(H - abs(cx - x) - abs(cy - y), 0)",
"+ if h != nowH:",
"- return (cx, cy, H)",
"- return (-1, -1, -1)",
"+ print((cx, cy, H))",
"+ return",
"-cx, cy, H = sol()",
"-if cx == -1:",
"- print(\"-1\")",
"-else:",
"- print((\"{} {} {}\".format(cx, cy, H)))",
"+sol()"
] | false | 0.039934 | 0.037348 | 1.06924 | [
"s200432834",
"s142080923"
] |
u777283665 | p03437 | python | s971801798 | s376516424 | 1,826 | 17 | 3,060 | 2,940 | Accepted | Accepted | 99.07 | x, y = list(map(int, input().split()))
if x == y:
print((-1))
exit()
if y == 1:
print((-1))
exit()
for i in range(1, y):
temp = x * i
if temp <= 10 ** 18 and temp % y != 0:
print((x*i))
exit()
print((-1)) | x, y = list(map(int, input().split()))
if x % y == 0:
print((-1))
else:
print(x) | 17 | 6 | 230 | 82 | x, y = list(map(int, input().split()))
if x == y:
print((-1))
exit()
if y == 1:
print((-1))
exit()
for i in range(1, y):
temp = x * i
if temp <= 10**18 and temp % y != 0:
print((x * i))
exit()
print((-1))
| x, y = list(map(int, input().split()))
if x % y == 0:
print((-1))
else:
print(x)
| false | 64.705882 | [
"-if x == y:",
"+if x % y == 0:",
"- exit()",
"-if y == 1:",
"- print((-1))",
"- exit()",
"-for i in range(1, y):",
"- temp = x * i",
"- if temp <= 10**18 and temp % y != 0:",
"- print((x * i))",
"- exit()",
"-print((-1))",
"+else:",
"+ print(x)"
] | false | 0.045899 | 0.047227 | 0.97187 | [
"s971801798",
"s376516424"
] |
u186838327 | p03674 | python | s497930564 | s670939456 | 1,538 | 193 | 142,552 | 101,468 | Accepted | Accepted | 87.45 | n = int(eval(input()))
A =list(map(int, input().split()))
mod = 10**9+7
d = {}
for i in range(n+1):
if A[i] not in d:
d[A[i]] = i
else:
l = d[A[i]]
r = i
break
#print(l, r)
def cmb1(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
for k in range(1, n+2):
ans = cmb1(n+1, k, mod) - cmb1(l+n-r, k-1, mod)
print((ans%mod))
| n = int(eval(input()))
A = list(map(int, input().split()))
mod = 10**9+7
from collections import Counter
C = Counter(A)
for k, v in list(C.items()):
if v == 2:
t = k
flag = False
for i in range(n+1):
if not flag:
if A[i] == t:
l = i
flag = True
else:
if A[i] == t:
r = i
r = n-r
#print(l, r)
N = 10**5+50
fac = [1]*(N+1)
finv = [1]*(N+1)
for i in range(N):
fac[i+1] = fac[i] * (i+1) % mod
finv[-1] = pow(fac[-1], mod-2, mod)
for i in reversed(list(range(N))):
finv[i] = finv[i+1] * (i+1) % mod
def cmb1(n, r, mod):
if r <0 or r > n:
return 0
r = min(r, n-r)
return fac[n] * finv[r] * finv[n-r] % mod
for k in range(1, n+2):
ans = cmb1(n+1, k, mod)-cmb1(l+r, k-1, mod)
print((ans%mod))
| 34 | 42 | 738 | 821 | n = int(eval(input()))
A = list(map(int, input().split()))
mod = 10**9 + 7
d = {}
for i in range(n + 1):
if A[i] not in d:
d[A[i]] = i
else:
l = d[A[i]]
r = i
break
# print(l, r)
def cmb1(n, r, mod):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % mod
mod = 10**9 + 7 # 出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル
for i in range(2, N + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
for k in range(1, n + 2):
ans = cmb1(n + 1, k, mod) - cmb1(l + n - r, k - 1, mod)
print((ans % mod))
| n = int(eval(input()))
A = list(map(int, input().split()))
mod = 10**9 + 7
from collections import Counter
C = Counter(A)
for k, v in list(C.items()):
if v == 2:
t = k
flag = False
for i in range(n + 1):
if not flag:
if A[i] == t:
l = i
flag = True
else:
if A[i] == t:
r = i
r = n - r
# print(l, r)
N = 10**5 + 50
fac = [1] * (N + 1)
finv = [1] * (N + 1)
for i in range(N):
fac[i + 1] = fac[i] * (i + 1) % mod
finv[-1] = pow(fac[-1], mod - 2, mod)
for i in reversed(list(range(N))):
finv[i] = finv[i + 1] * (i + 1) % mod
def cmb1(n, r, mod):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return fac[n] * finv[r] * finv[n - r] % mod
for k in range(1, n + 2):
ans = cmb1(n + 1, k, mod) - cmb1(l + r, k - 1, mod)
print((ans % mod))
| false | 19.047619 | [
"-d = {}",
"+from collections import Counter",
"+",
"+C = Counter(A)",
"+for k, v in list(C.items()):",
"+ if v == 2:",
"+ t = k",
"+flag = False",
"- if A[i] not in d:",
"- d[A[i]] = i",
"+ if not flag:",
"+ if A[i] == t:",
"+ l = i",
"+ flag = True",
"- l = d[A[i]]",
"- r = i",
"- break",
"+ if A[i] == t:",
"+ r = i",
"+r = n - r",
"+N = 10**5 + 50",
"+fac = [1] * (N + 1)",
"+finv = [1] * (N + 1)",
"+for i in range(N):",
"+ fac[i + 1] = fac[i] * (i + 1) % mod",
"+finv[-1] = pow(fac[-1], mod - 2, mod)",
"+for i in reversed(list(range(N))):",
"+ finv[i] = finv[i + 1] * (i + 1) % mod",
"+",
"+",
"- return g1[n] * g2[r] * g2[n - r] % mod",
"+ return fac[n] * finv[r] * finv[n - r] % mod",
"-mod = 10**9 + 7 # 出力の制限",
"-N = 10**6",
"-g1 = [1, 1] # 元テーブル",
"-g2 = [1, 1] # 逆元テーブル",
"-inverse = [0, 1] # 逆元テーブル計算用テーブル",
"-for i in range(2, N + 1):",
"- g1.append((g1[-1] * i) % mod)",
"- inverse.append((-inverse[mod % i] * (mod // i)) % mod)",
"- g2.append((g2[-1] * inverse[-1]) % mod)",
"- ans = cmb1(n + 1, k, mod) - cmb1(l + n - r, k - 1, mod)",
"+ ans = cmb1(n + 1, k, mod) - cmb1(l + r, k - 1, mod)"
] | false | 2.509397 | 0.170545 | 14.714 | [
"s497930564",
"s670939456"
] |
u930705402 | p02775 | python | s544962766 | s171232530 | 533 | 425 | 246,636 | 252,020 | Accepted | Accepted | 20.26 | INF=10**30
N=list(map(int,list(eval(input()))))[::-1]
l=len(N)
dp=[[INF,INF] for i in range(l+1)]
dp[0][0]=0
for i in range(l):
dp[i+1][0]=min([dp[i+1][0],dp[i][0]+N[i],dp[i][1]+N[i]+1])
dp[i+1][1]=min([dp[i+1][1],dp[i][0]+(10-N[i]),dp[i][1]+(9-N[i])])
ans=min(dp[l][0],dp[l][1]+1)
print(ans) | INF=10**30
N=list(map(int,list(eval(input()))))[::-1]
l=len(N)
dp=[[INF,INF] for i in range(l+1)]
dp[0][0]=0
for i in range(l):
dp[i+1][0]=min(dp[i][0]+N[i],dp[i][1]+N[i]+1)
dp[i+1][1]=min(dp[i][0]+(10-N[i]),dp[i][1]+(9-N[i]))
print((min(dp[l][0],dp[l][1]+1))) | 10 | 9 | 303 | 268 | INF = 10**30
N = list(map(int, list(eval(input()))))[::-1]
l = len(N)
dp = [[INF, INF] for i in range(l + 1)]
dp[0][0] = 0
for i in range(l):
dp[i + 1][0] = min([dp[i + 1][0], dp[i][0] + N[i], dp[i][1] + N[i] + 1])
dp[i + 1][1] = min([dp[i + 1][1], dp[i][0] + (10 - N[i]), dp[i][1] + (9 - N[i])])
ans = min(dp[l][0], dp[l][1] + 1)
print(ans)
| INF = 10**30
N = list(map(int, list(eval(input()))))[::-1]
l = len(N)
dp = [[INF, INF] for i in range(l + 1)]
dp[0][0] = 0
for i in range(l):
dp[i + 1][0] = min(dp[i][0] + N[i], dp[i][1] + N[i] + 1)
dp[i + 1][1] = min(dp[i][0] + (10 - N[i]), dp[i][1] + (9 - N[i]))
print((min(dp[l][0], dp[l][1] + 1)))
| false | 10 | [
"- dp[i + 1][0] = min([dp[i + 1][0], dp[i][0] + N[i], dp[i][1] + N[i] + 1])",
"- dp[i + 1][1] = min([dp[i + 1][1], dp[i][0] + (10 - N[i]), dp[i][1] + (9 - N[i])])",
"-ans = min(dp[l][0], dp[l][1] + 1)",
"-print(ans)",
"+ dp[i + 1][0] = min(dp[i][0] + N[i], dp[i][1] + N[i] + 1)",
"+ dp[i + 1][1] = min(dp[i][0] + (10 - N[i]), dp[i][1] + (9 - N[i]))",
"+print((min(dp[l][0], dp[l][1] + 1)))"
] | false | 0.070868 | 0.046512 | 1.523653 | [
"s544962766",
"s171232530"
] |
u357751375 | p03830 | python | s884409280 | s879622574 | 72 | 43 | 65,928 | 9,120 | Accepted | Accepted | 40.28 | from math import factorial
n = int(eval(input()))
m = factorial(n)
s = 2
ans = 1
while m != 1:
c = 1
while m % s == 0:
c += 1
m = m // s
ans *= c
s += 1
print((ans % (10**9+7))) | from math import factorial
n = int(eval(input()))
m = factorial(n)
s = 2
ans = 1
while m > 1:
c = 1
while m % s == 0:
c += 1
m = m // s
ans *= c
s += 1
print((ans % (10**9+7))) | 13 | 13 | 213 | 212 | from math import factorial
n = int(eval(input()))
m = factorial(n)
s = 2
ans = 1
while m != 1:
c = 1
while m % s == 0:
c += 1
m = m // s
ans *= c
s += 1
print((ans % (10**9 + 7)))
| from math import factorial
n = int(eval(input()))
m = factorial(n)
s = 2
ans = 1
while m > 1:
c = 1
while m % s == 0:
c += 1
m = m // s
ans *= c
s += 1
print((ans % (10**9 + 7)))
| false | 0 | [
"-while m != 1:",
"+while m > 1:"
] | false | 0.040113 | 0.038312 | 1.046987 | [
"s884409280",
"s879622574"
] |
u695811449 | p02562 | python | s290357147 | s338075324 | 1,942 | 1,135 | 82,008 | 74,572 | Accepted | Accepted | 41.56 | N,K=list(map(int,input().split()))
MAP=[list(map(int,input().split())) for i in range(N)]
start = 2*N+1
goal = 2*N+2
V=2*N+5
EDGE=[[[0,0] for j in range(V)] for i in range(V)]
# 0 ~ N : 縦
# N+1 ~ 2*N : 横
# 2*N+1 : start
# 2*N+2 : goal
for i in range(N):
EDGE[start][i]=[K,0]
EDGE[N+i][goal]=[K,0]
for i in range(N):
for j in range(N):
EDGE[i][N+j]=[1,-MAP[i][j]]
EDGE[N+j][i]=[0,MAP[i][j]]
EDGE[start][goal]=[float("inf"),0]
BACK=[-1]*V
LA=0
for flow in range(K*N):
ANS=[float("inf")]*V
ANS[start]=0
for rep in range(V):
flag=0
for fr in range(V):
for to in range(V):
c,d=EDGE[fr][to]
if c>0 and ANS[to]>ANS[fr]+d:
ANS[to]=ANS[fr]+d
flag=1
BACK[to]=fr
if flag==0:
break
if ANS[goal]==0:
break
LA+=ANS[goal]
NOW=goal
while NOW!=start:
fr=BACK[NOW]
EDGE[fr][NOW][0]-=1
EDGE[NOW][fr][0]+=1
NOW=fr
print((-LA))
ALIST=[["."]*N for i in range(N)]
for i in range(N):
for j in range(N):
if EDGE[i][N+j][0]==0:
ALIST[i][j]="X"
for alist in ALIST:
print(("".join(alist))) | N,K=list(map(int,input().split()))
MAP=[list(map(int,input().split())) for i in range(N)]
start = 2*N+1
goal = 2*N+2
V=2*N+5
EDGE=[[[0,0] for j in range(V)] for i in range(V)]
# 0 ~ N : 縦
# N+1 ~ 2*N : 横
# 2*N+1 : start
# 2*N+2 : goal
for i in range(N):
EDGE[start][i]=[K,0]
EDGE[N+i][goal]=[K,0]
for i in range(N):
for j in range(N):
EDGE[i][N+j]=[1,10**9-MAP[i][j]]
EDGE[N+j][i]=[0,-(10**9-MAP[i][j])]
EDGE[start][goal]=[float("inf"),10**9]
BACK=[-1]*V
LA=0
import heapq
for flow in range(K*N):
ANS=[float("inf")]*V
Q=[(0,start)]
ANS[start]=0
while Q:
time,fr=heapq.heappop(Q)
if time>ANS[fr]:
continue
for to in range(V):
c,d = EDGE[fr][to]
if c>0 and ANS[to]>ANS[fr]+d:
ANS[to]=ANS[fr]+d
BACK[to]=fr
heapq.heappush(Q,(ANS[to],to))
LA+=ANS[goal]
NOW=goal
while NOW!=start:
fr=BACK[NOW]
EDGE[fr][NOW][0]-=1
EDGE[NOW][fr][0]+=1
NOW=fr
print((K*N*10**9-LA))
ALIST=[["."]*N for i in range(N)]
for i in range(N):
for j in range(N):
if EDGE[i][N+j][0]==0:
ALIST[i][j]="X"
for alist in ALIST:
print(("".join(alist))) | 70 | 67 | 1,323 | 1,318 | N, K = list(map(int, input().split()))
MAP = [list(map(int, input().split())) for i in range(N)]
start = 2 * N + 1
goal = 2 * N + 2
V = 2 * N + 5
EDGE = [[[0, 0] for j in range(V)] for i in range(V)]
# 0 ~ N : 縦
# N+1 ~ 2*N : 横
# 2*N+1 : start
# 2*N+2 : goal
for i in range(N):
EDGE[start][i] = [K, 0]
EDGE[N + i][goal] = [K, 0]
for i in range(N):
for j in range(N):
EDGE[i][N + j] = [1, -MAP[i][j]]
EDGE[N + j][i] = [0, MAP[i][j]]
EDGE[start][goal] = [float("inf"), 0]
BACK = [-1] * V
LA = 0
for flow in range(K * N):
ANS = [float("inf")] * V
ANS[start] = 0
for rep in range(V):
flag = 0
for fr in range(V):
for to in range(V):
c, d = EDGE[fr][to]
if c > 0 and ANS[to] > ANS[fr] + d:
ANS[to] = ANS[fr] + d
flag = 1
BACK[to] = fr
if flag == 0:
break
if ANS[goal] == 0:
break
LA += ANS[goal]
NOW = goal
while NOW != start:
fr = BACK[NOW]
EDGE[fr][NOW][0] -= 1
EDGE[NOW][fr][0] += 1
NOW = fr
print((-LA))
ALIST = [["."] * N for i in range(N)]
for i in range(N):
for j in range(N):
if EDGE[i][N + j][0] == 0:
ALIST[i][j] = "X"
for alist in ALIST:
print(("".join(alist)))
| N, K = list(map(int, input().split()))
MAP = [list(map(int, input().split())) for i in range(N)]
start = 2 * N + 1
goal = 2 * N + 2
V = 2 * N + 5
EDGE = [[[0, 0] for j in range(V)] for i in range(V)]
# 0 ~ N : 縦
# N+1 ~ 2*N : 横
# 2*N+1 : start
# 2*N+2 : goal
for i in range(N):
EDGE[start][i] = [K, 0]
EDGE[N + i][goal] = [K, 0]
for i in range(N):
for j in range(N):
EDGE[i][N + j] = [1, 10**9 - MAP[i][j]]
EDGE[N + j][i] = [0, -(10**9 - MAP[i][j])]
EDGE[start][goal] = [float("inf"), 10**9]
BACK = [-1] * V
LA = 0
import heapq
for flow in range(K * N):
ANS = [float("inf")] * V
Q = [(0, start)]
ANS[start] = 0
while Q:
time, fr = heapq.heappop(Q)
if time > ANS[fr]:
continue
for to in range(V):
c, d = EDGE[fr][to]
if c > 0 and ANS[to] > ANS[fr] + d:
ANS[to] = ANS[fr] + d
BACK[to] = fr
heapq.heappush(Q, (ANS[to], to))
LA += ANS[goal]
NOW = goal
while NOW != start:
fr = BACK[NOW]
EDGE[fr][NOW][0] -= 1
EDGE[NOW][fr][0] += 1
NOW = fr
print((K * N * 10**9 - LA))
ALIST = [["."] * N for i in range(N)]
for i in range(N):
for j in range(N):
if EDGE[i][N + j][0] == 0:
ALIST[i][j] = "X"
for alist in ALIST:
print(("".join(alist)))
| false | 4.285714 | [
"- EDGE[i][N + j] = [1, -MAP[i][j]]",
"- EDGE[N + j][i] = [0, MAP[i][j]]",
"-EDGE[start][goal] = [float(\"inf\"), 0]",
"+ EDGE[i][N + j] = [1, 10**9 - MAP[i][j]]",
"+ EDGE[N + j][i] = [0, -(10**9 - MAP[i][j])]",
"+EDGE[start][goal] = [float(\"inf\"), 10**9]",
"+import heapq",
"+",
"+ Q = [(0, start)]",
"- for rep in range(V):",
"- flag = 0",
"- for fr in range(V):",
"- for to in range(V):",
"- c, d = EDGE[fr][to]",
"- if c > 0 and ANS[to] > ANS[fr] + d:",
"- ANS[to] = ANS[fr] + d",
"- flag = 1",
"- BACK[to] = fr",
"- if flag == 0:",
"- break",
"- if ANS[goal] == 0:",
"- break",
"+ while Q:",
"+ time, fr = heapq.heappop(Q)",
"+ if time > ANS[fr]:",
"+ continue",
"+ for to in range(V):",
"+ c, d = EDGE[fr][to]",
"+ if c > 0 and ANS[to] > ANS[fr] + d:",
"+ ANS[to] = ANS[fr] + d",
"+ BACK[to] = fr",
"+ heapq.heappush(Q, (ANS[to], to))",
"-print((-LA))",
"+print((K * N * 10**9 - LA))"
] | false | 0.038449 | 0.043456 | 0.884776 | [
"s290357147",
"s338075324"
] |
u367701763 | p02936 | python | s976580782 | s997902291 | 865 | 474 | 264,992 | 166,644 | Accepted | Accepted | 45.2 | # https://atcoder.jp/contests/abc138/tasks/abc138_d
import sys
input = sys.stdin.readline
import marshal
class Graph:
def __init__(self, n, dictated=False, decrement=True, edge=[]):
self.n = n
self.dictated = dictated
self.decrement = decrement
self.edge = [set() for _ in range(self.n)]
self.parent = [-1]*self.n
self.info = [-1]*self.n
for x, y in edge:
self.add_edge(x,y)
def add_edge(self, x, y):
if self.decrement:
x -= 1
y -= 1
self.edge[x].add(y)
if self.dictated == False:
self.edge[y].add(x)
def add_adjacent_list(self, i, adjacent_list):
if self.decrement:
self.edge[i] = set([x-1 for x in adjacent_list])
else:
self.edge[i] = set(adjacent_list)
def dfs2(self, info, start, goal=-1, time=0, save=False):
"""
:param info: 各頂点の付加情報
:param start: スタート地点
:param goal: ゴール地点
:param save: True = 前回の探索結果を保持する
:return: ゴール地点までの距離。存在しなければ -1
"""
if self.decrement:
start -= 1
goal -= 1
if not save:
self.parent = [-1] * self.n
edge2 = marshal.loads(marshal.dumps(self.edge))
p, t = start, time
self.parent[p] = -2
while True:
if edge2[p]:
q = edge2[p].pop()
if q == self.parent[p] and not self.dictated:
""" 逆流した時の処理 """
""""""""""""""""""""
continue
if self.parent[q] != -1:
""" サイクルで同一点を訪れた時の処理 """
""""""""""""""""""""
continue
if q == goal:
""" ゴール時の処理"""
# return t + 1
""""""""""""""""""""
continue
""" p から q への引継ぎ"""
info[q] += info[p]
""""""""""""""""""""
self.parent[q] = p
p, t = q, t + 1
else:
""" 探索完了時の処理 """
""""""""""""""""""""
if p == start and t == time:
break
p, t = self.parent[p], t-1
""" 二度目に訪問時の処理 """
""""""""""""""""""""
return info
######################################################################################################
N, Q = list(map(int, input().split())) # N:頂点数, Q: クエリの数
M = N-1
graph = Graph(N, dictated=False)
for _ in range(M):
x, y = list(map(int, input().split()))
graph.add_edge(x,y)
info = [0] * N
for _ in range(Q):
p, x = list(map(int, input().split()))
info[p - 1] += x
print((*graph.dfs2(info, start=1)))
| # https://atcoder.jp/contests/abc138/tasks/abc138_d
import sys
input = sys.stdin.readline
import marshal
class Graph:
def __init__(self, n, dictated=False, decrement=True, destroy=False, edge=[]):
self.n = n
self.dictated = dictated
self.decrement = decrement
self.destroy = destroy
self.edge = [set() for _ in range(self.n)]
self.parent = [-1]*self.n
self.info = [-1]*self.n
for x, y in edge:
self.add_edge(x,y)
def add_edge(self, x, y):
if self.decrement:
x -= 1
y -= 1
self.edge[x].add(y)
if self.dictated == False:
self.edge[y].add(x)
def add_adjacent_list(self, i, adjacent_list):
if self.decrement:
self.edge[i] = set([x-1 for x in adjacent_list])
else:
self.edge[i] = set(adjacent_list)
def dfs2(self, info, start, goal=-1, time=0, save=False):
"""
:param info: 各頂点の付加情報
:param start: スタート地点
:param goal: ゴール地点
:param save: True = 前回の探索結果を保持する
:return: ゴール地点までの距離。存在しなければ -1
"""
if self.decrement:
start -= 1
goal -= 1
if not save:
self.parent = [-1] * self.n
if self.destroy:
edge2 = self.edge
else:
edge2 = marshal.loads(marshal.dumps(self.edge))
p, t = start, time
self.parent[p] = -2
while True:
if edge2[p]:
q = edge2[p].pop()
if q == self.parent[p] and not self.dictated:
""" 逆流した時の処理 """
""""""""""""""""""""
continue
if self.parent[q] != -1:
""" サイクルで同一点を訪れた時の処理 """
""""""""""""""""""""
continue
if q == goal:
""" ゴール時の処理"""
# return t + 1
""""""""""""""""""""
continue
""" p から q への引継ぎ"""
info[q] += info[p]
""""""""""""""""""""
self.parent[q] = p
p, t = q, t + 1
else:
""" 探索完了時の処理 """
""""""""""""""""""""
if p == start and t == time:
break
p, t = self.parent[p], t-1
""" 二度目に訪問時の処理 """
""""""""""""""""""""
return info
######################################################################################################
N, Q = list(map(int, input().split())) # N:頂点数, Q: クエリの数
M = N-1
graph = Graph(N, dictated=False, destroy=True)
for _ in range(M):
x, y = list(map(int, input().split()))
graph.add_edge(x,y)
info = [0] * N
for _ in range(Q):
p, x = list(map(int, input().split()))
info[p - 1] += x
print((*graph.dfs2(info, start=1)))
| 102 | 105 | 2,901 | 3,036 | # https://atcoder.jp/contests/abc138/tasks/abc138_d
import sys
input = sys.stdin.readline
import marshal
class Graph:
def __init__(self, n, dictated=False, decrement=True, edge=[]):
self.n = n
self.dictated = dictated
self.decrement = decrement
self.edge = [set() for _ in range(self.n)]
self.parent = [-1] * self.n
self.info = [-1] * self.n
for x, y in edge:
self.add_edge(x, y)
def add_edge(self, x, y):
if self.decrement:
x -= 1
y -= 1
self.edge[x].add(y)
if self.dictated == False:
self.edge[y].add(x)
def add_adjacent_list(self, i, adjacent_list):
if self.decrement:
self.edge[i] = set([x - 1 for x in adjacent_list])
else:
self.edge[i] = set(adjacent_list)
def dfs2(self, info, start, goal=-1, time=0, save=False):
"""
:param info: 各頂点の付加情報
:param start: スタート地点
:param goal: ゴール地点
:param save: True = 前回の探索結果を保持する
:return: ゴール地点までの距離。存在しなければ -1
"""
if self.decrement:
start -= 1
goal -= 1
if not save:
self.parent = [-1] * self.n
edge2 = marshal.loads(marshal.dumps(self.edge))
p, t = start, time
self.parent[p] = -2
while True:
if edge2[p]:
q = edge2[p].pop()
if q == self.parent[p] and not self.dictated:
"""逆流した時の処理"""
"""""" """""" """""" ""
continue
if self.parent[q] != -1:
"""サイクルで同一点を訪れた時の処理"""
"""""" """""" """""" ""
continue
if q == goal:
"""ゴール時の処理"""
# return t + 1
"""""" """""" """""" ""
continue
""" p から q への引継ぎ"""
info[q] += info[p]
"""""" """""" """""" ""
self.parent[q] = p
p, t = q, t + 1
else:
"""探索完了時の処理"""
"""""" """""" """""" ""
if p == start and t == time:
break
p, t = self.parent[p], t - 1
""" 二度目に訪問時の処理 """
"""""" """""" """""" ""
return info
######################################################################################################
N, Q = list(map(int, input().split())) # N:頂点数, Q: クエリの数
M = N - 1
graph = Graph(N, dictated=False)
for _ in range(M):
x, y = list(map(int, input().split()))
graph.add_edge(x, y)
info = [0] * N
for _ in range(Q):
p, x = list(map(int, input().split()))
info[p - 1] += x
print((*graph.dfs2(info, start=1)))
| # https://atcoder.jp/contests/abc138/tasks/abc138_d
import sys
input = sys.stdin.readline
import marshal
class Graph:
def __init__(self, n, dictated=False, decrement=True, destroy=False, edge=[]):
self.n = n
self.dictated = dictated
self.decrement = decrement
self.destroy = destroy
self.edge = [set() for _ in range(self.n)]
self.parent = [-1] * self.n
self.info = [-1] * self.n
for x, y in edge:
self.add_edge(x, y)
def add_edge(self, x, y):
if self.decrement:
x -= 1
y -= 1
self.edge[x].add(y)
if self.dictated == False:
self.edge[y].add(x)
def add_adjacent_list(self, i, adjacent_list):
if self.decrement:
self.edge[i] = set([x - 1 for x in adjacent_list])
else:
self.edge[i] = set(adjacent_list)
def dfs2(self, info, start, goal=-1, time=0, save=False):
"""
:param info: 各頂点の付加情報
:param start: スタート地点
:param goal: ゴール地点
:param save: True = 前回の探索結果を保持する
:return: ゴール地点までの距離。存在しなければ -1
"""
if self.decrement:
start -= 1
goal -= 1
if not save:
self.parent = [-1] * self.n
if self.destroy:
edge2 = self.edge
else:
edge2 = marshal.loads(marshal.dumps(self.edge))
p, t = start, time
self.parent[p] = -2
while True:
if edge2[p]:
q = edge2[p].pop()
if q == self.parent[p] and not self.dictated:
"""逆流した時の処理"""
"""""" """""" """""" ""
continue
if self.parent[q] != -1:
"""サイクルで同一点を訪れた時の処理"""
"""""" """""" """""" ""
continue
if q == goal:
"""ゴール時の処理"""
# return t + 1
"""""" """""" """""" ""
continue
""" p から q への引継ぎ"""
info[q] += info[p]
"""""" """""" """""" ""
self.parent[q] = p
p, t = q, t + 1
else:
"""探索完了時の処理"""
"""""" """""" """""" ""
if p == start and t == time:
break
p, t = self.parent[p], t - 1
""" 二度目に訪問時の処理 """
"""""" """""" """""" ""
return info
######################################################################################################
N, Q = list(map(int, input().split())) # N:頂点数, Q: クエリの数
M = N - 1
graph = Graph(N, dictated=False, destroy=True)
for _ in range(M):
x, y = list(map(int, input().split()))
graph.add_edge(x, y)
info = [0] * N
for _ in range(Q):
p, x = list(map(int, input().split()))
info[p - 1] += x
print((*graph.dfs2(info, start=1)))
| false | 2.857143 | [
"- def __init__(self, n, dictated=False, decrement=True, edge=[]):",
"+ def __init__(self, n, dictated=False, decrement=True, destroy=False, edge=[]):",
"+ self.destroy = destroy",
"- edge2 = marshal.loads(marshal.dumps(self.edge))",
"+ if self.destroy:",
"+ edge2 = self.edge",
"+ else:",
"+ edge2 = marshal.loads(marshal.dumps(self.edge))",
"-graph = Graph(N, dictated=False)",
"+graph = Graph(N, dictated=False, destroy=True)"
] | false | 0.046925 | 0.111147 | 0.422188 | [
"s976580782",
"s997902291"
] |
u875361824 | p03317 | python | s948931280 | s188633799 | 81 | 40 | 13,812 | 13,940 | Accepted | Accepted | 50.62 | import sys
import math
def main():
"""
2 <= K <= N <= 10^5
1 <= ai <= N
1 <= i <= N
"""
N, K = list(map(int, input().split()))
*A, = list(map(int, input().split()))
ans = f_K(N, K, A)
#ans = editorial(N, K, A)
print(ans)
def test_examples():
nka_ans = [
(4, 3, [2, 3, 1, 4], 2),
(3, 3, [1, 2, 3], 1),
(8, 3, [7, 3, 1, 8, 4, 6, 2, 5], 4),
]
for N, K, A, ans in nka_ans:
assert editorial(N, K, A) == ans
assert f_K(N, K, A) == ans
def test_ans():
nka_ans = [
(5, 2, [1, 2, 3, 4, 5], 4),
(5, 3, [1, 2, 3, 4, 5], 2),
(5, 2, [5, 4, 3, 2, 1], 4),
(5, 3, [5, 4, 3, 2, 1], 2),
]
for N, K, A, ans in nka_ans:
assert editorial(N, K, A) == ans
assert f_K(N, K, A) == ans
def f_K(N, K, A):
"""
最初に置く範囲は、 1_idx - K + 1 から 1_idx
"""
idx = [i for i, a in enumerate(A) if a == 1][0]
left_idx = max(0, idx - K)
ans = float("inf")
for i in range(left_idx, idx + 1):
left = i
right = max(0, N - left - K)
tmp = (left + (K - 1) - 1) // (K - 1)
tmp += 1
tmp += (right + (K - 1) - 1) // (K - 1)
ans = min(ans, tmp)
return ans
if __name__ == '__main__':
main()
| import sys
import math
def main():
"""
2 <= K <= N <= 10^5
1 <= ai <= N
1 <= i <= N
"""
N, K = list(map(int, input().split()))
*A, = list(map(int, input().split()))
#ans = f_K(N, K, A)
ans = editorial(N, K, A)
print(ans)
def test_examples():
nka_ans = [
(4, 3, [2, 3, 1, 4], 2),
(3, 3, [1, 2, 3], 1),
(8, 3, [7, 3, 1, 8, 4, 6, 2, 5], 4),
]
for N, K, A, ans in nka_ans:
assert editorial(N, K, A) == ans
assert f_K(N, K, A) == ans
def test_ans():
nka_ans = [
(5, 2, [1, 2, 3, 4, 5], 4),
(5, 3, [1, 2, 3, 4, 5], 2),
(5, 2, [5, 4, 3, 2, 1], 4),
(5, 3, [5, 4, 3, 2, 1], 2),
]
for N, K, A, ans in nka_ans:
assert editorial(N, K, A) == ans
assert f_K(N, K, A) == ans
def f_K(N, K, A):
"""
最初に置く範囲は、 1_idx - K + 1 から 1_idx
"""
idx = [i for i, a in enumerate(A) if a == 1][0]
left_idx = max(0, idx - K)
ans = float("inf")
for i in range(left_idx, idx + 1):
left = i
right = max(0, N - left - K)
tmp = (left + (K - 1) - 1) // (K - 1)
tmp += 1
tmp += (right + (K - 1) - 1) // (K - 1)
ans = min(ans, tmp)
return ans
def editorial(N, K, A):
"""
端から端までカバーしていく
K + (K - 1) * N (N >= 0)
これは仮に1番左に1があったとき
結果的には順番は気にしなくて良い
上記でカバーしていくと、いつかは最初の1をカバーする
カバーした順番を1をカバーしたことを最初に行えば変わらない
TODO: editorial pdfの意味
1 + g(K − 1) ≤ p ≤ 1 + (g + 1)(K − 1) なる整数 g
"""
return ((N-1) + (K-1) - 1) // (K-1)
if __name__ == '__main__':
main()
| 63 | 79 | 1,338 | 1,684 | import sys
import math
def main():
"""
2 <= K <= N <= 10^5
1 <= ai <= N
1 <= i <= N
"""
N, K = list(map(int, input().split()))
(*A,) = list(map(int, input().split()))
ans = f_K(N, K, A)
# ans = editorial(N, K, A)
print(ans)
def test_examples():
nka_ans = [
(4, 3, [2, 3, 1, 4], 2),
(3, 3, [1, 2, 3], 1),
(8, 3, [7, 3, 1, 8, 4, 6, 2, 5], 4),
]
for N, K, A, ans in nka_ans:
assert editorial(N, K, A) == ans
assert f_K(N, K, A) == ans
def test_ans():
nka_ans = [
(5, 2, [1, 2, 3, 4, 5], 4),
(5, 3, [1, 2, 3, 4, 5], 2),
(5, 2, [5, 4, 3, 2, 1], 4),
(5, 3, [5, 4, 3, 2, 1], 2),
]
for N, K, A, ans in nka_ans:
assert editorial(N, K, A) == ans
assert f_K(N, K, A) == ans
def f_K(N, K, A):
"""
最初に置く範囲は、 1_idx - K + 1 から 1_idx
"""
idx = [i for i, a in enumerate(A) if a == 1][0]
left_idx = max(0, idx - K)
ans = float("inf")
for i in range(left_idx, idx + 1):
left = i
right = max(0, N - left - K)
tmp = (left + (K - 1) - 1) // (K - 1)
tmp += 1
tmp += (right + (K - 1) - 1) // (K - 1)
ans = min(ans, tmp)
return ans
if __name__ == "__main__":
main()
| import sys
import math
def main():
"""
2 <= K <= N <= 10^5
1 <= ai <= N
1 <= i <= N
"""
N, K = list(map(int, input().split()))
(*A,) = list(map(int, input().split()))
# ans = f_K(N, K, A)
ans = editorial(N, K, A)
print(ans)
def test_examples():
nka_ans = [
(4, 3, [2, 3, 1, 4], 2),
(3, 3, [1, 2, 3], 1),
(8, 3, [7, 3, 1, 8, 4, 6, 2, 5], 4),
]
for N, K, A, ans in nka_ans:
assert editorial(N, K, A) == ans
assert f_K(N, K, A) == ans
def test_ans():
nka_ans = [
(5, 2, [1, 2, 3, 4, 5], 4),
(5, 3, [1, 2, 3, 4, 5], 2),
(5, 2, [5, 4, 3, 2, 1], 4),
(5, 3, [5, 4, 3, 2, 1], 2),
]
for N, K, A, ans in nka_ans:
assert editorial(N, K, A) == ans
assert f_K(N, K, A) == ans
def f_K(N, K, A):
"""
最初に置く範囲は、 1_idx - K + 1 から 1_idx
"""
idx = [i for i, a in enumerate(A) if a == 1][0]
left_idx = max(0, idx - K)
ans = float("inf")
for i in range(left_idx, idx + 1):
left = i
right = max(0, N - left - K)
tmp = (left + (K - 1) - 1) // (K - 1)
tmp += 1
tmp += (right + (K - 1) - 1) // (K - 1)
ans = min(ans, tmp)
return ans
def editorial(N, K, A):
"""
端から端までカバーしていく
K + (K - 1) * N (N >= 0)
これは仮に1番左に1があったとき
結果的には順番は気にしなくて良い
上記でカバーしていくと、いつかは最初の1をカバーする
カバーした順番を1をカバーしたことを最初に行えば変わらない
TODO: editorial pdfの意味
1 + g(K − 1) ≤ p ≤ 1 + (g + 1)(K − 1) なる整数 g
"""
return ((N - 1) + (K - 1) - 1) // (K - 1)
if __name__ == "__main__":
main()
| false | 20.253165 | [
"- ans = f_K(N, K, A)",
"- # ans = editorial(N, K, A)",
"+ # ans = f_K(N, K, A)",
"+ ans = editorial(N, K, A)",
"+def editorial(N, K, A):",
"+ \"\"\"",
"+ 端から端までカバーしていく",
"+ K + (K - 1) * N (N >= 0)",
"+ これは仮に1番左に1があったとき",
"+ 結果的には順番は気にしなくて良い",
"+ 上記でカバーしていくと、いつかは最初の1をカバーする",
"+ カバーした順番を1をカバーしたことを最初に行えば変わらない",
"+ TODO: editorial pdfの意味",
"+ 1 + g(K − 1) ≤ p ≤ 1 + (g + 1)(K − 1) なる整数 g",
"+ \"\"\"",
"+ return ((N - 1) + (K - 1) - 1) // (K - 1)",
"+",
"+"
] | false | 0.055454 | 0.042278 | 1.311662 | [
"s948931280",
"s188633799"
] |
u678167152 | p03103 | python | s021124600 | s370158023 | 470 | 432 | 20,056 | 27,756 | Accepted | Accepted | 8.09 | N, M = list(map(int, input().split()))
A = [0]*N
for i in range(N):
A[i] = [0,0]
A[i][0],A[i][1] = list(map(int, input().split()))
A.sort()
sum = 0
for a in A:
if a[1]<M:
sum += a[0]*a[1]
M -= a[1]
else:
sum += a[0]*M
print(sum)
exit()
| def solve():
N, M = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
A.sort()
ans = 0
cnt = 0
for a in A:
if cnt + a[1] <= M:
ans += a[1]*a[0]
cnt += a[1]
else:
ans += a[0]*(M-cnt)
break
return ans
print((solve())) | 16 | 15 | 268 | 351 | N, M = list(map(int, input().split()))
A = [0] * N
for i in range(N):
A[i] = [0, 0]
A[i][0], A[i][1] = list(map(int, input().split()))
A.sort()
sum = 0
for a in A:
if a[1] < M:
sum += a[0] * a[1]
M -= a[1]
else:
sum += a[0] * M
print(sum)
exit()
| def solve():
N, M = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
A.sort()
ans = 0
cnt = 0
for a in A:
if cnt + a[1] <= M:
ans += a[1] * a[0]
cnt += a[1]
else:
ans += a[0] * (M - cnt)
break
return ans
print((solve()))
| false | 6.25 | [
"-N, M = list(map(int, input().split()))",
"-A = [0] * N",
"-for i in range(N):",
"- A[i] = [0, 0]",
"- A[i][0], A[i][1] = list(map(int, input().split()))",
"-A.sort()",
"-sum = 0",
"-for a in A:",
"- if a[1] < M:",
"- sum += a[0] * a[1]",
"- M -= a[1]",
"- else:",
"- sum += a[0] * M",
"- print(sum)",
"- exit()",
"+def solve():",
"+ N, M = list(map(int, input().split()))",
"+ A = [list(map(int, input().split())) for _ in range(N)]",
"+ A.sort()",
"+ ans = 0",
"+ cnt = 0",
"+ for a in A:",
"+ if cnt + a[1] <= M:",
"+ ans += a[1] * a[0]",
"+ cnt += a[1]",
"+ else:",
"+ ans += a[0] * (M - cnt)",
"+ break",
"+ return ans",
"+",
"+",
"+print((solve()))"
] | false | 0.038484 | 0.040945 | 0.93988 | [
"s021124600",
"s370158023"
] |
u150984829 | p02235 | python | s353011814 | s726297063 | 2,870 | 2,380 | 5,624 | 5,628 | Accepted | Accepted | 17.07 | e=input
a=[]
for _ in[0]*int(e()):
X,z=e(),[]
for y in e():
s=i=0
for k in z:
t=X.find(y,s)+1
if t<1:break
if t<k:z[i]=t
s=k;i+=1
else:
t=X.find(y,s)+1
if t:z+=[t]
a+=[len(z)]
print(*a,sep='\n')
| e=input
a=''
for _ in[0]*int(e()):
X,z=e(),[]
for y in e():
s=i=0
for k in z:
t=X.find(y,s)+1
if t<1:break
if t<k:z[i]=t
s=k;i+=1
else:
t=X.find(y,s)+1
if t:z+=[t]
a+=f'\n{len(z)}'
print((a[1:]))
| 16 | 16 | 237 | 236 | e = input
a = []
for _ in [0] * int(e()):
X, z = e(), []
for y in e():
s = i = 0
for k in z:
t = X.find(y, s) + 1
if t < 1:
break
if t < k:
z[i] = t
s = k
i += 1
else:
t = X.find(y, s) + 1
if t:
z += [t]
a += [len(z)]
print(*a, sep="\n")
| e = input
a = ""
for _ in [0] * int(e()):
X, z = e(), []
for y in e():
s = i = 0
for k in z:
t = X.find(y, s) + 1
if t < 1:
break
if t < k:
z[i] = t
s = k
i += 1
else:
t = X.find(y, s) + 1
if t:
z += [t]
a += f"\n{len(z)}"
print((a[1:]))
| false | 0 | [
"-a = []",
"+a = \"\"",
"- a += [len(z)]",
"-print(*a, sep=\"\\n\")",
"+ a += f\"\\n{len(z)}\"",
"+print((a[1:]))"
] | false | 0.041209 | 0.059701 | 0.690255 | [
"s353011814",
"s726297063"
] |
u257162238 | p02584 | python | s930097427 | s202455779 | 34 | 30 | 9,184 | 9,196 | Accepted | Accepted | 11.76 | import sys
input = sys.stdin.readline
import math
def read():
X, K, D = list(map(int, input().strip().split()))
return X, K, D
def solve(X, K, D):
m = (-X + K*D) / (2*D)
mc = min(max(0, math.ceil(m)), K)
mf = min(max(0, math.floor(m)), K)
ans = min(abs(X - K*D + 2 * mc * D), abs(X - K*D + 2 * mf * D))
return ans
if __name__ == '__main__':
inputs = read()
outputs = solve(*inputs)
if outputs is not None:
print(("%s" % str(outputs)))
| import sys
input = sys.stdin.readline
import math
def read():
X, K, D = list(map(int, input().strip().split()))
return X, K, D
def solve(X, K, D):
X = abs(X)
k = X // D
if K % 2 == 0:
if k % 2 == 0:
i = min(X // D, K)
else:
i = min(X // D + 1, K)
else:
if k % 2 == 0:
i = min(X // D + 1, K)
else:
i = min(X // D, K)
ans = X - i * D
return abs(ans)
if __name__ == '__main__':
inputs = read()
outputs = solve(*inputs)
if outputs is not None:
print(("%s" % str(outputs)))
| 23 | 32 | 503 | 631 | import sys
input = sys.stdin.readline
import math
def read():
X, K, D = list(map(int, input().strip().split()))
return X, K, D
def solve(X, K, D):
m = (-X + K * D) / (2 * D)
mc = min(max(0, math.ceil(m)), K)
mf = min(max(0, math.floor(m)), K)
ans = min(abs(X - K * D + 2 * mc * D), abs(X - K * D + 2 * mf * D))
return ans
if __name__ == "__main__":
inputs = read()
outputs = solve(*inputs)
if outputs is not None:
print(("%s" % str(outputs)))
| import sys
input = sys.stdin.readline
import math
def read():
X, K, D = list(map(int, input().strip().split()))
return X, K, D
def solve(X, K, D):
X = abs(X)
k = X // D
if K % 2 == 0:
if k % 2 == 0:
i = min(X // D, K)
else:
i = min(X // D + 1, K)
else:
if k % 2 == 0:
i = min(X // D + 1, K)
else:
i = min(X // D, K)
ans = X - i * D
return abs(ans)
if __name__ == "__main__":
inputs = read()
outputs = solve(*inputs)
if outputs is not None:
print(("%s" % str(outputs)))
| false | 28.125 | [
"- m = (-X + K * D) / (2 * D)",
"- mc = min(max(0, math.ceil(m)), K)",
"- mf = min(max(0, math.floor(m)), K)",
"- ans = min(abs(X - K * D + 2 * mc * D), abs(X - K * D + 2 * mf * D))",
"- return ans",
"+ X = abs(X)",
"+ k = X // D",
"+ if K % 2 == 0:",
"+ if k % 2 == 0:",
"+ i = min(X // D, K)",
"+ else:",
"+ i = min(X // D + 1, K)",
"+ else:",
"+ if k % 2 == 0:",
"+ i = min(X // D + 1, K)",
"+ else:",
"+ i = min(X // D, K)",
"+ ans = X - i * D",
"+ return abs(ans)"
] | false | 0.047879 | 0.095398 | 0.501883 | [
"s930097427",
"s202455779"
] |
u794173881 | p02820 | python | s886393076 | s783413868 | 467 | 343 | 75,116 | 63,596 | Accepted | Accepted | 26.55 | n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
dp = [[0]*3 for i in range(n+1)]
# dp[i][今回の手]
for i in range(n):
if t[i] == "r":
dp[i+1][0] = max(dp[max(i+1-k, 0)][1] + p, dp[i+1][0])
dp[i+1][0] = max(dp[max(i+1-k, 0)][2] + p, dp[i+1][0])
if t[i] == "s":
dp[i+1][1] = max(dp[max(i+1-k, 0)][0] + r, dp[i+1][1])
dp[i+1][1] = max(dp[max(i+1-k, 0)][2] + r, dp[i+1][1])
if t[i] == "p":
dp[i+1][2] = max(dp[max(i+1-k, 0)][0] + s, dp[i+1][2])
dp[i+1][2] = max(dp[max(i+1-k, 0)][1] + s, dp[i+1][2])
dp[i+1][0] = max(dp[max(i+1-k, 0)][1], dp[i+1][0])
dp[i+1][0] = max(dp[max(i+1-k, 0)][2], dp[i+1][0])
dp[i+1][1] = max(dp[max(i+1-k, 0)][0], dp[i+1][1])
dp[i+1][1] = max(dp[max(i+1-k, 0)][2], dp[i+1][1])
dp[i+1][2] = max(dp[max(i+1-k, 0)][0], dp[i+1][2])
dp[i+1][2] = max(dp[max(i+1-k, 0)][1], dp[i+1][2])
ans = 0
for i in range(k):
ans += max(dp[n-i])
print(ans) | n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
dp = [[0] * 3 for i in range(n + 1)]
for i in range(n):
if i + 1 - k < 0:
if t[i] == "r":
dp[i + 1][0] = p
if t[i] == "s":
dp[i + 1][1] = r
if t[i] == "p":
dp[i + 1][2] = s
else:
if t[i] == "r":
dp[i + 1][0] = p + max(dp[i + 1 - k][1], dp[i + 1 - k][2])
dp[i + 1][1] = max(dp[i + 1 - k][2], dp[i + 1 - k][0])
dp[i + 1][2] = max(dp[i + 1 - k][0], dp[i + 1 - k][1])
if t[i] == "s":
dp[i + 1][0] = max(dp[i + 1 - k][1], dp[i + 1 - k][2])
dp[i + 1][1] = r + max(dp[i + 1 - k][2], dp[i + 1 - k][0])
dp[i + 1][2] = max(dp[i + 1 - k][0], dp[i + 1 - k][1])
if t[i] == "p":
dp[i + 1][0] = max(dp[i + 1 - k][1], dp[i + 1 - k][2])
dp[i + 1][1] = max(dp[i + 1 - k][2], dp[i + 1 - k][0])
dp[i + 1][2] = s + max(dp[i + 1 - k][0], dp[i + 1 - k][1])
ans = 0
for i in range(k):
ans += max(dp[-i - 1])
print(ans) | 28 | 30 | 1,006 | 1,109 | n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
dp = [[0] * 3 for i in range(n + 1)]
# dp[i][今回の手]
for i in range(n):
if t[i] == "r":
dp[i + 1][0] = max(dp[max(i + 1 - k, 0)][1] + p, dp[i + 1][0])
dp[i + 1][0] = max(dp[max(i + 1 - k, 0)][2] + p, dp[i + 1][0])
if t[i] == "s":
dp[i + 1][1] = max(dp[max(i + 1 - k, 0)][0] + r, dp[i + 1][1])
dp[i + 1][1] = max(dp[max(i + 1 - k, 0)][2] + r, dp[i + 1][1])
if t[i] == "p":
dp[i + 1][2] = max(dp[max(i + 1 - k, 0)][0] + s, dp[i + 1][2])
dp[i + 1][2] = max(dp[max(i + 1 - k, 0)][1] + s, dp[i + 1][2])
dp[i + 1][0] = max(dp[max(i + 1 - k, 0)][1], dp[i + 1][0])
dp[i + 1][0] = max(dp[max(i + 1 - k, 0)][2], dp[i + 1][0])
dp[i + 1][1] = max(dp[max(i + 1 - k, 0)][0], dp[i + 1][1])
dp[i + 1][1] = max(dp[max(i + 1 - k, 0)][2], dp[i + 1][1])
dp[i + 1][2] = max(dp[max(i + 1 - k, 0)][0], dp[i + 1][2])
dp[i + 1][2] = max(dp[max(i + 1 - k, 0)][1], dp[i + 1][2])
ans = 0
for i in range(k):
ans += max(dp[n - i])
print(ans)
| n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = eval(input())
dp = [[0] * 3 for i in range(n + 1)]
for i in range(n):
if i + 1 - k < 0:
if t[i] == "r":
dp[i + 1][0] = p
if t[i] == "s":
dp[i + 1][1] = r
if t[i] == "p":
dp[i + 1][2] = s
else:
if t[i] == "r":
dp[i + 1][0] = p + max(dp[i + 1 - k][1], dp[i + 1 - k][2])
dp[i + 1][1] = max(dp[i + 1 - k][2], dp[i + 1 - k][0])
dp[i + 1][2] = max(dp[i + 1 - k][0], dp[i + 1 - k][1])
if t[i] == "s":
dp[i + 1][0] = max(dp[i + 1 - k][1], dp[i + 1 - k][2])
dp[i + 1][1] = r + max(dp[i + 1 - k][2], dp[i + 1 - k][0])
dp[i + 1][2] = max(dp[i + 1 - k][0], dp[i + 1 - k][1])
if t[i] == "p":
dp[i + 1][0] = max(dp[i + 1 - k][1], dp[i + 1 - k][2])
dp[i + 1][1] = max(dp[i + 1 - k][2], dp[i + 1 - k][0])
dp[i + 1][2] = s + max(dp[i + 1 - k][0], dp[i + 1 - k][1])
ans = 0
for i in range(k):
ans += max(dp[-i - 1])
print(ans)
| false | 6.666667 | [
"-# dp[i][今回の手]",
"- if t[i] == \"r\":",
"- dp[i + 1][0] = max(dp[max(i + 1 - k, 0)][1] + p, dp[i + 1][0])",
"- dp[i + 1][0] = max(dp[max(i + 1 - k, 0)][2] + p, dp[i + 1][0])",
"- if t[i] == \"s\":",
"- dp[i + 1][1] = max(dp[max(i + 1 - k, 0)][0] + r, dp[i + 1][1])",
"- dp[i + 1][1] = max(dp[max(i + 1 - k, 0)][2] + r, dp[i + 1][1])",
"- if t[i] == \"p\":",
"- dp[i + 1][2] = max(dp[max(i + 1 - k, 0)][0] + s, dp[i + 1][2])",
"- dp[i + 1][2] = max(dp[max(i + 1 - k, 0)][1] + s, dp[i + 1][2])",
"- dp[i + 1][0] = max(dp[max(i + 1 - k, 0)][1], dp[i + 1][0])",
"- dp[i + 1][0] = max(dp[max(i + 1 - k, 0)][2], dp[i + 1][0])",
"- dp[i + 1][1] = max(dp[max(i + 1 - k, 0)][0], dp[i + 1][1])",
"- dp[i + 1][1] = max(dp[max(i + 1 - k, 0)][2], dp[i + 1][1])",
"- dp[i + 1][2] = max(dp[max(i + 1 - k, 0)][0], dp[i + 1][2])",
"- dp[i + 1][2] = max(dp[max(i + 1 - k, 0)][1], dp[i + 1][2])",
"+ if i + 1 - k < 0:",
"+ if t[i] == \"r\":",
"+ dp[i + 1][0] = p",
"+ if t[i] == \"s\":",
"+ dp[i + 1][1] = r",
"+ if t[i] == \"p\":",
"+ dp[i + 1][2] = s",
"+ else:",
"+ if t[i] == \"r\":",
"+ dp[i + 1][0] = p + max(dp[i + 1 - k][1], dp[i + 1 - k][2])",
"+ dp[i + 1][1] = max(dp[i + 1 - k][2], dp[i + 1 - k][0])",
"+ dp[i + 1][2] = max(dp[i + 1 - k][0], dp[i + 1 - k][1])",
"+ if t[i] == \"s\":",
"+ dp[i + 1][0] = max(dp[i + 1 - k][1], dp[i + 1 - k][2])",
"+ dp[i + 1][1] = r + max(dp[i + 1 - k][2], dp[i + 1 - k][0])",
"+ dp[i + 1][2] = max(dp[i + 1 - k][0], dp[i + 1 - k][1])",
"+ if t[i] == \"p\":",
"+ dp[i + 1][0] = max(dp[i + 1 - k][1], dp[i + 1 - k][2])",
"+ dp[i + 1][1] = max(dp[i + 1 - k][2], dp[i + 1 - k][0])",
"+ dp[i + 1][2] = s + max(dp[i + 1 - k][0], dp[i + 1 - k][1])",
"- ans += max(dp[n - i])",
"+ ans += max(dp[-i - 1])"
] | false | 0.045812 | 0.045711 | 1.002216 | [
"s886393076",
"s783413868"
] |
u987164499 | p03241 | python | s170139914 | s475083547 | 25 | 20 | 3,064 | 3,064 | Accepted | Accepted | 20 | from sys import stdin
n,m = list(map(int,stdin.readline().rstrip().split()))
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
li = make_divisors(m)
point = 1
if n == 1:
print(m)
exit()
for i in range(1,len(li)):
if m//li[i] < n:
point = li[i-1]
break
print(point) | from sys import stdin
n,m = list(map(int,stdin.readline().rstrip().split()))
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
divisors.sort()
return divisors
li = make_divisors(m)
point = m
for i in range(1,len(li)):
if m//li[i] < n:
point = li[i-1]
break
print(point) | 21 | 18 | 494 | 456 | from sys import stdin
n, m = list(map(int, stdin.readline().rstrip().split()))
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort()
return divisors
li = make_divisors(m)
point = 1
if n == 1:
print(m)
exit()
for i in range(1, len(li)):
if m // li[i] < n:
point = li[i - 1]
break
print(point)
| from sys import stdin
n, m = list(map(int, stdin.readline().rstrip().split()))
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
divisors.sort()
return divisors
li = make_divisors(m)
point = m
for i in range(1, len(li)):
if m // li[i] < n:
point = li[i - 1]
break
print(point)
| false | 14.285714 | [
"-point = 1",
"-if n == 1:",
"- print(m)",
"- exit()",
"+point = m"
] | false | 0.050142 | 0.042567 | 1.177944 | [
"s170139914",
"s475083547"
] |
u694665829 | p03475 | python | s512197521 | s848087010 | 93 | 71 | 9,220 | 9,240 | Accepted | Accepted | 23.66 | n = int(eval(input()))
csf = [list(map(int,input().split())) for _ in range(n-1)]
for i in range(n):
time = 0
while True:
if i == n-1:
print(time)
break
if time < csf[i][1]:
time = csf[i][1] + csf[i][0]
else:
if time%csf[i][2] == 0:
time += csf[i][0]
else:
time += csf[i][0] + csf[i][2] - time%csf[i][2]
i += 1
| def solve():
n = int(eval(input()))
csf = [list(map(int,input().split())) for _ in range(n-1)]
for i in range(n):
time = 0
while True:
if i == n-1:
print(time)
break
if time < csf[i][1]:
time = csf[i][1] + csf[i][0]
else:
if time%csf[i][2] == 0:
time += csf[i][0]
else:
time += csf[i][0] + csf[i][2] - time%csf[i][2]
i += 1
if __name__ == "__main__":
solve() | 17 | 21 | 455 | 579 | n = int(eval(input()))
csf = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(n):
time = 0
while True:
if i == n - 1:
print(time)
break
if time < csf[i][1]:
time = csf[i][1] + csf[i][0]
else:
if time % csf[i][2] == 0:
time += csf[i][0]
else:
time += csf[i][0] + csf[i][2] - time % csf[i][2]
i += 1
| def solve():
n = int(eval(input()))
csf = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(n):
time = 0
while True:
if i == n - 1:
print(time)
break
if time < csf[i][1]:
time = csf[i][1] + csf[i][0]
else:
if time % csf[i][2] == 0:
time += csf[i][0]
else:
time += csf[i][0] + csf[i][2] - time % csf[i][2]
i += 1
if __name__ == "__main__":
solve()
| false | 19.047619 | [
"-n = int(eval(input()))",
"-csf = [list(map(int, input().split())) for _ in range(n - 1)]",
"-for i in range(n):",
"- time = 0",
"- while True:",
"- if i == n - 1:",
"- print(time)",
"- break",
"- if time < csf[i][1]:",
"- time = csf[i][1] + csf[i][0]",
"- else:",
"- if time % csf[i][2] == 0:",
"- time += csf[i][0]",
"+def solve():",
"+ n = int(eval(input()))",
"+ csf = [list(map(int, input().split())) for _ in range(n - 1)]",
"+ for i in range(n):",
"+ time = 0",
"+ while True:",
"+ if i == n - 1:",
"+ print(time)",
"+ break",
"+ if time < csf[i][1]:",
"+ time = csf[i][1] + csf[i][0]",
"- time += csf[i][0] + csf[i][2] - time % csf[i][2]",
"- i += 1",
"+ if time % csf[i][2] == 0:",
"+ time += csf[i][0]",
"+ else:",
"+ time += csf[i][0] + csf[i][2] - time % csf[i][2]",
"+ i += 1",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ solve()"
] | false | 0.093597 | 0.044713 | 2.093293 | [
"s512197521",
"s848087010"
] |
u212328220 | p02684 | python | s114155599 | s902978882 | 169 | 150 | 33,804 | 32,376 | Accepted | Accepted | 11.24 | from collections import defaultdict
def inpl():
return list(map(int, input().split()))
N, K = inpl()
aa = inpl()
s = 1
route = [s]
ed = set([s])
for i in range(1, K + 1):
s = aa[s - 1]
if s in ed:
Li = route.index(s)
Ri = len(route)
idx = Li + (K - Li) % (Ri - Li)
print((route[idx]))
break
else:
route.append(s)
ed.add(s)
continue
else:
print(s)
| N, K = list(map(int, input().split()))
al = list(map(int, input().split()))
visited= [1]
ed = set([1])
for i in range(K):
next_town = al[visited[i] - 1]
if next_town in ed:
loop_sta = visited.index((next_town)) # visited_townsにおけるループ開始のインデックス
loop_end = len(visited) #visited_townsにおけるループの終わりのインデックス
loop_length = loop_end - loop_sta #繰り返すループの長さ
amari = (K - loop_sta) % loop_length
ans = visited[loop_sta + amari]
print(ans)
exit()
else:
visited.append(next_town)
ed.add(next_town)
continue
else:
print((visited[-1]))
| 29 | 23 | 464 | 633 | from collections import defaultdict
def inpl():
return list(map(int, input().split()))
N, K = inpl()
aa = inpl()
s = 1
route = [s]
ed = set([s])
for i in range(1, K + 1):
s = aa[s - 1]
if s in ed:
Li = route.index(s)
Ri = len(route)
idx = Li + (K - Li) % (Ri - Li)
print((route[idx]))
break
else:
route.append(s)
ed.add(s)
continue
else:
print(s)
| N, K = list(map(int, input().split()))
al = list(map(int, input().split()))
visited = [1]
ed = set([1])
for i in range(K):
next_town = al[visited[i] - 1]
if next_town in ed:
loop_sta = visited.index((next_town)) # visited_townsにおけるループ開始のインデックス
loop_end = len(visited) # visited_townsにおけるループの終わりのインデックス
loop_length = loop_end - loop_sta # 繰り返すループの長さ
amari = (K - loop_sta) % loop_length
ans = visited[loop_sta + amari]
print(ans)
exit()
else:
visited.append(next_town)
ed.add(next_town)
continue
else:
print((visited[-1]))
| false | 20.689655 | [
"-from collections import defaultdict",
"-",
"-",
"-def inpl():",
"- return list(map(int, input().split()))",
"-",
"-",
"-N, K = inpl()",
"-aa = inpl()",
"-s = 1",
"-route = [s]",
"-ed = set([s])",
"-for i in range(1, K + 1):",
"- s = aa[s - 1]",
"- if s in ed:",
"- Li = route.index(s)",
"- Ri = len(route)",
"- idx = Li + (K - Li) % (Ri - Li)",
"- print((route[idx]))",
"- break",
"+N, K = list(map(int, input().split()))",
"+al = list(map(int, input().split()))",
"+visited = [1]",
"+ed = set([1])",
"+for i in range(K):",
"+ next_town = al[visited[i] - 1]",
"+ if next_town in ed:",
"+ loop_sta = visited.index((next_town)) # visited_townsにおけるループ開始のインデックス",
"+ loop_end = len(visited) # visited_townsにおけるループの終わりのインデックス",
"+ loop_length = loop_end - loop_sta # 繰り返すループの長さ",
"+ amari = (K - loop_sta) % loop_length",
"+ ans = visited[loop_sta + amari]",
"+ print(ans)",
"+ exit()",
"- route.append(s)",
"- ed.add(s)",
"+ visited.append(next_town)",
"+ ed.add(next_town)",
"- print(s)",
"+ print((visited[-1]))"
] | false | 0.033972 | 0.094794 | 0.358383 | [
"s114155599",
"s902978882"
] |
u600402037 | p02714 | python | s405217831 | s146001793 | 202 | 165 | 68,896 | 68,840 | Accepted | Accepted | 18.32 | # coding: utf-8
import sys
from collections import Counter
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# 1の条件を満たすものを調べたのち、2の条件のものを引く
N = ir()
S = list(sr())
counter = Counter(S)
r = counter['R']
g = counter['G']
b = counter['B']
answer = r * g * b
for i in range(N-1):
for j in range(i+1, N):
if j + (j - i) >= N:
continue
x = S[i]; y = S[j]; z = S[j+j-i]
if x != y and y != z and z != x:
answer -= 1
print(answer)
| # coding: utf-8
import sys
from collections import Counter
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
S = sr()
counter = Counter(S)
r = counter['R']; g = counter['G']; b = counter['B']
answer = r * g * b
for i in range(N):
for j in range(i+1, N):
if S[i] == S[j]:
continue
diff = j - i
if j + diff >= N:
break
x = S[i]; y = S[j]
z = S[j+diff]
if x != z and y != z:
answer -= 1
print(answer)
| 25 | 26 | 558 | 581 | # coding: utf-8
import sys
from collections import Counter
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# 1の条件を満たすものを調べたのち、2の条件のものを引く
N = ir()
S = list(sr())
counter = Counter(S)
r = counter["R"]
g = counter["G"]
b = counter["B"]
answer = r * g * b
for i in range(N - 1):
for j in range(i + 1, N):
if j + (j - i) >= N:
continue
x = S[i]
y = S[j]
z = S[j + j - i]
if x != y and y != z and z != x:
answer -= 1
print(answer)
| # coding: utf-8
import sys
from collections import Counter
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
S = sr()
counter = Counter(S)
r = counter["R"]
g = counter["G"]
b = counter["B"]
answer = r * g * b
for i in range(N):
for j in range(i + 1, N):
if S[i] == S[j]:
continue
diff = j - i
if j + diff >= N:
break
x = S[i]
y = S[j]
z = S[j + diff]
if x != z and y != z:
answer -= 1
print(answer)
| false | 3.846154 | [
"-# 1の条件を満たすものを調べたのち、2の条件のものを引く",
"-S = list(sr())",
"+S = sr()",
"-for i in range(N - 1):",
"+for i in range(N):",
"- if j + (j - i) >= N:",
"+ if S[i] == S[j]:",
"+ diff = j - i",
"+ if j + diff >= N:",
"+ break",
"- z = S[j + j - i]",
"- if x != y and y != z and z != x:",
"+ z = S[j + diff]",
"+ if x != z and y != z:"
] | false | 0.036608 | 0.035837 | 1.021523 | [
"s405217831",
"s146001793"
] |
u197615397 | p02270 | python | s854382865 | s044359958 | 1,000 | 370 | 12,352 | 9,580 | Accepted | Accepted | 63 | import math
n, k = list(map(int, input().split()))
a = [int(eval(input())) for _ in [None]*n]
lb = max(a)
ub = lb * n
while True:
mid = (ub+lb) // 2
remain = k - 1
cw = 0
for w in a:
cw += w
if cw > mid:
remain -= 1
cw = w
if remain < 0:
break
if remain < 0:
if lb == mid:
print((lb+1))
break
lb = mid
else:
if lb == mid:
print(lb)
break
ub = mid | def solve():
import sys
n, k = list(map(int, input().split()))
ws = tuple(map(int, sys.stdin))
ok, ng = sum(ws), max(ws)-1
while ok-ng > 1:
mid = (ok+ng+1)//2
current = 0
count = 0
for w in ws:
if current + w > mid:
current = w
count += 1
else:
current += w
if count < k:
ok = mid
else:
ng = mid
print(ok)
if __name__ == "__main__":
solve()
| 28 | 27 | 525 | 538 | import math
n, k = list(map(int, input().split()))
a = [int(eval(input())) for _ in [None] * n]
lb = max(a)
ub = lb * n
while True:
mid = (ub + lb) // 2
remain = k - 1
cw = 0
for w in a:
cw += w
if cw > mid:
remain -= 1
cw = w
if remain < 0:
break
if remain < 0:
if lb == mid:
print((lb + 1))
break
lb = mid
else:
if lb == mid:
print(lb)
break
ub = mid
| def solve():
import sys
n, k = list(map(int, input().split()))
ws = tuple(map(int, sys.stdin))
ok, ng = sum(ws), max(ws) - 1
while ok - ng > 1:
mid = (ok + ng + 1) // 2
current = 0
count = 0
for w in ws:
if current + w > mid:
current = w
count += 1
else:
current += w
if count < k:
ok = mid
else:
ng = mid
print(ok)
if __name__ == "__main__":
solve()
| false | 3.571429 | [
"-import math",
"+def solve():",
"+ import sys",
"-n, k = list(map(int, input().split()))",
"-a = [int(eval(input())) for _ in [None] * n]",
"-lb = max(a)",
"-ub = lb * n",
"-while True:",
"- mid = (ub + lb) // 2",
"- remain = k - 1",
"- cw = 0",
"- for w in a:",
"- cw += w",
"- if cw > mid:",
"- remain -= 1",
"- cw = w",
"- if remain < 0:",
"- break",
"- if remain < 0:",
"- if lb == mid:",
"- print((lb + 1))",
"- break",
"- lb = mid",
"- else:",
"- if lb == mid:",
"- print(lb)",
"- break",
"- ub = mid",
"+ n, k = list(map(int, input().split()))",
"+ ws = tuple(map(int, sys.stdin))",
"+ ok, ng = sum(ws), max(ws) - 1",
"+ while ok - ng > 1:",
"+ mid = (ok + ng + 1) // 2",
"+ current = 0",
"+ count = 0",
"+ for w in ws:",
"+ if current + w > mid:",
"+ current = w",
"+ count += 1",
"+ else:",
"+ current += w",
"+ if count < k:",
"+ ok = mid",
"+ else:",
"+ ng = mid",
"+ print(ok)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ solve()"
] | false | 0.035215 | 0.03639 | 0.967724 | [
"s854382865",
"s044359958"
] |
u538276565 | p02888 | python | s432873783 | s838743901 | 1,536 | 727 | 3,188 | 3,188 | Accepted | Accepted | 52.67 | n = int(eval(input()))
d = list([int(x) for x in input().split()])
d.sort()
res = 0
for i in range(n-2):
k = i + 2
for j in range(i+1, n-1):
while k < n and d[i] + d[j] > d[k]:
k += 1
if k > j:
res += k - j - 1
print(res) | def find_triangle_count(d):
n = len(d)
d.sort()
res = 0
for i in range(n - 2):
k = i + 2
for j in range(i + 1, n - 1):
while k < n and d[i] + d[j] > d[k]:
k += 1
if k > j:
res += k - j - 1
return res
def solve():
eval(input())
input_list = list([int(x) for x in input().split()])
print((find_triangle_count(input_list)))
if __name__ == '__main__':
solve() | 15 | 22 | 285 | 485 | n = int(eval(input()))
d = list([int(x) for x in input().split()])
d.sort()
res = 0
for i in range(n - 2):
k = i + 2
for j in range(i + 1, n - 1):
while k < n and d[i] + d[j] > d[k]:
k += 1
if k > j:
res += k - j - 1
print(res)
| def find_triangle_count(d):
n = len(d)
d.sort()
res = 0
for i in range(n - 2):
k = i + 2
for j in range(i + 1, n - 1):
while k < n and d[i] + d[j] > d[k]:
k += 1
if k > j:
res += k - j - 1
return res
def solve():
eval(input())
input_list = list([int(x) for x in input().split()])
print((find_triangle_count(input_list)))
if __name__ == "__main__":
solve()
| false | 31.818182 | [
"-n = int(eval(input()))",
"-d = list([int(x) for x in input().split()])",
"-d.sort()",
"-res = 0",
"-for i in range(n - 2):",
"- k = i + 2",
"- for j in range(i + 1, n - 1):",
"- while k < n and d[i] + d[j] > d[k]:",
"- k += 1",
"- if k > j:",
"- res += k - j - 1",
"-print(res)",
"+def find_triangle_count(d):",
"+ n = len(d)",
"+ d.sort()",
"+ res = 0",
"+ for i in range(n - 2):",
"+ k = i + 2",
"+ for j in range(i + 1, n - 1):",
"+ while k < n and d[i] + d[j] > d[k]:",
"+ k += 1",
"+ if k > j:",
"+ res += k - j - 1",
"+ return res",
"+",
"+",
"+def solve():",
"+ eval(input())",
"+ input_list = list([int(x) for x in input().split()])",
"+ print((find_triangle_count(input_list)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ solve()"
] | false | 0.111896 | 0.076683 | 1.459202 | [
"s432873783",
"s838743901"
] |
u694294905 | p04043 | python | s217793693 | s074386918 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | List=list(map(int,input().split()))
print(('YES' if List.count(7)==1 and List.count(5)==2 else 'NO')) | l=list(input().split())
print(('YES' if l.count('5')==2 and l.count('7')==1 else 'NO')) | 2 | 2 | 100 | 87 | List = list(map(int, input().split()))
print(("YES" if List.count(7) == 1 and List.count(5) == 2 else "NO"))
| l = list(input().split())
print(("YES" if l.count("5") == 2 and l.count("7") == 1 else "NO"))
| false | 0 | [
"-List = list(map(int, input().split()))",
"-print((\"YES\" if List.count(7) == 1 and List.count(5) == 2 else \"NO\"))",
"+l = list(input().split())",
"+print((\"YES\" if l.count(\"5\") == 2 and l.count(\"7\") == 1 else \"NO\"))"
] | false | 0.067224 | 0.068018 | 0.988338 | [
"s217793693",
"s074386918"
] |
u411203878 | p03131 | python | s894715271 | s930844882 | 181 | 73 | 38,392 | 61,920 | Accepted | Accepted | 59.67 | k,a,b = list(map(int,input().split()))
if b-a <= 1 or k <= a:
print((k+1))
else:
print((((k-(a+1))//2)*(b-a)+b+((k-(a+1))%2))) | K,A,B = list(map(int,input().split()))
if B-A < 3:
print((K+1))
else:
if A > K-1:
print((K+1))
else:
count = K-A+1
shou = count//2
if count%2 == 1:
print((A+(B-A)*shou+1))
else:
print((A+(B-A)*shou)) | 7 | 14 | 132 | 275 | k, a, b = list(map(int, input().split()))
if b - a <= 1 or k <= a:
print((k + 1))
else:
print((((k - (a + 1)) // 2) * (b - a) + b + ((k - (a + 1)) % 2)))
| K, A, B = list(map(int, input().split()))
if B - A < 3:
print((K + 1))
else:
if A > K - 1:
print((K + 1))
else:
count = K - A + 1
shou = count // 2
if count % 2 == 1:
print((A + (B - A) * shou + 1))
else:
print((A + (B - A) * shou))
| false | 50 | [
"-k, a, b = list(map(int, input().split()))",
"-if b - a <= 1 or k <= a:",
"- print((k + 1))",
"+K, A, B = list(map(int, input().split()))",
"+if B - A < 3:",
"+ print((K + 1))",
"- print((((k - (a + 1)) // 2) * (b - a) + b + ((k - (a + 1)) % 2)))",
"+ if A > K - 1:",
"+ print((K + 1))",
"+ else:",
"+ count = K - A + 1",
"+ shou = count // 2",
"+ if count % 2 == 1:",
"+ print((A + (B - A) * shou + 1))",
"+ else:",
"+ print((A + (B - A) * shou))"
] | false | 0.053699 | 0.036528 | 1.470079 | [
"s894715271",
"s930844882"
] |
u423585790 | p03295 | python | s314055595 | s203309357 | 398 | 341 | 55,900 | 55,772 | Accepted | Accepted | 14.32 | #!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list([int(x)-1 for x in stdin.readline().split()])
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
#A
def A():
a, b, c = LI()
ans = 10 ** 5
ans = min(ans, abs(a - b) + abs(b - c))
ans = min(ans, abs(a - c) + abs(b - c))
ans = min(ans, abs(a - c) + abs(a - b))
print(ans)
return
#B
def B():
s, t = S(), S()
f = 0
for i in range(len(s)):
f = f or s[i:] + s[:i] == t
print((["No","Yes"][f]))
return
#C
def C():
return
# D
# 解説AC
# 貪欲かよ
# 言われればその通りでbi昇順でソートしていれば
# 直前で取り除いたものに関してはその橋より左側
# の街について絶対に橋が途切れているからね
# fuck!!!
def D():
n, m = LI()
d = defaultdict(int)
for _ in range(m):
a, b = LI_()
d[a] = max(d[a], n-b)
mi = 0
ans = 0
for i in range(n-1):
mi = max(mi, d[i])
if i == n - mi - 1:
mi = 0
ans += 1
print(ans)
return
#Solve
if __name__ == '__main__':
D()
| #!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list([int(x)-1 for x in stdin.readline().split()])
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
#A
def A():
a, b, c = LI()
ans = 10 ** 5
ans = min(ans, abs(a - b) + abs(b - c))
ans = min(ans, abs(a - c) + abs(b - c))
ans = min(ans, abs(a - c) + abs(a - b))
print(ans)
return
#B
def B():
s, t = S(), S()
f = 0
for i in range(len(s)):
f = f or s[i:] + s[:i] == t
print((["No","Yes"][f]))
return
#C
def C():
return
# D
# 解説AC
# 貪欲かよ
# 言われればその通りでbi昇順でソートしていれば
# 直前で取り除いたものに関してはその橋より左側
# の街について絶対に橋が途切れているからね
# fuck!!!
def D():
n, m = LI()
d = defaultdict(int)
for _ in range(m):
a, b = LI_()
d[a] = max(d[a], n-b)
mi = 0
ans = 0
for i in range(n - 1):
if mi < d[i]:
mi = d[i]
if i == n - mi - 1:
mi = 0
ans += 1
print(ans)
return
#Solve
if __name__ == '__main__':
D()
| 79 | 80 | 1,924 | 1,944 | #!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI():
return list(map(int, stdin.readline().split()))
def LF():
return list(map(float, stdin.readline().split()))
def LI_():
return list([int(x) - 1 for x in stdin.readline().split()])
def II():
return int(stdin.readline())
def IF():
return float(stdin.readline())
def LS():
return list(map(list, stdin.readline().split()))
def S():
return list(stdin.readline().rstrip())
def IR(n):
return [II() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
def FR(n):
return [IF() for _ in range(n)]
def LFR(n):
return [LI() for _ in range(n)]
def LIR_(n):
return [LI_() for _ in range(n)]
def SR(n):
return [S() for _ in range(n)]
def LSR(n):
return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")
# A
def A():
a, b, c = LI()
ans = 10**5
ans = min(ans, abs(a - b) + abs(b - c))
ans = min(ans, abs(a - c) + abs(b - c))
ans = min(ans, abs(a - c) + abs(a - b))
print(ans)
return
# B
def B():
s, t = S(), S()
f = 0
for i in range(len(s)):
f = f or s[i:] + s[:i] == t
print((["No", "Yes"][f]))
return
# C
def C():
return
# D
# 解説AC
# 貪欲かよ
# 言われればその通りでbi昇順でソートしていれば
# 直前で取り除いたものに関してはその橋より左側
# の街について絶対に橋が途切れているからね
# fuck!!!
def D():
n, m = LI()
d = defaultdict(int)
for _ in range(m):
a, b = LI_()
d[a] = max(d[a], n - b)
mi = 0
ans = 0
for i in range(n - 1):
mi = max(mi, d[i])
if i == n - mi - 1:
mi = 0
ans += 1
print(ans)
return
# Solve
if __name__ == "__main__":
D()
| #!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI():
return list(map(int, stdin.readline().split()))
def LF():
return list(map(float, stdin.readline().split()))
def LI_():
return list([int(x) - 1 for x in stdin.readline().split()])
def II():
return int(stdin.readline())
def IF():
return float(stdin.readline())
def LS():
return list(map(list, stdin.readline().split()))
def S():
return list(stdin.readline().rstrip())
def IR(n):
return [II() for _ in range(n)]
def LIR(n):
return [LI() for _ in range(n)]
def FR(n):
return [IF() for _ in range(n)]
def LFR(n):
return [LI() for _ in range(n)]
def LIR_(n):
return [LI_() for _ in range(n)]
def SR(n):
return [S() for _ in range(n)]
def LSR(n):
return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")
# A
def A():
a, b, c = LI()
ans = 10**5
ans = min(ans, abs(a - b) + abs(b - c))
ans = min(ans, abs(a - c) + abs(b - c))
ans = min(ans, abs(a - c) + abs(a - b))
print(ans)
return
# B
def B():
s, t = S(), S()
f = 0
for i in range(len(s)):
f = f or s[i:] + s[:i] == t
print((["No", "Yes"][f]))
return
# C
def C():
return
# D
# 解説AC
# 貪欲かよ
# 言われればその通りでbi昇順でソートしていれば
# 直前で取り除いたものに関してはその橋より左側
# の街について絶対に橋が途切れているからね
# fuck!!!
def D():
n, m = LI()
d = defaultdict(int)
for _ in range(m):
a, b = LI_()
d[a] = max(d[a], n - b)
mi = 0
ans = 0
for i in range(n - 1):
if mi < d[i]:
mi = d[i]
if i == n - mi - 1:
mi = 0
ans += 1
print(ans)
return
# Solve
if __name__ == "__main__":
D()
| false | 1.25 | [
"- mi = max(mi, d[i])",
"+ if mi < d[i]:",
"+ mi = d[i]"
] | false | 0.046855 | 0.050417 | 0.929335 | [
"s314055595",
"s203309357"
] |
u645250356 | p03425 | python | s659288287 | s451541919 | 302 | 153 | 5,324 | 10,268 | Accepted | Accepted | 49.34 | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
d = defaultdict(int)
s = ['M','A','R','C','H']
for _ in range(n):
a = eval(input())
for i,t in enumerate(s):
if a[0] == t:
d[i] += 1
res = 0
for i in range(3):
for j in range(i+1,4):
for k in range(j+1,5):
res += d[i]*d[j]*d[k]
print(res) | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
d = defaultdict(int)
for _ in range(n):
s = eval(input())
d[s[0]] += 1
res = 0
li = ['M','A','R','C','H']
for i in range(3):
a = li[i]
for j in range(i+1,4):
b = li[j]
for k in range(j+1,5):
c = li[k]
res += d[a] * d[b] * d[c]
print(res) | 24 | 25 | 652 | 659 | from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n = inp()
d = defaultdict(int)
s = ["M", "A", "R", "C", "H"]
for _ in range(n):
a = eval(input())
for i, t in enumerate(s):
if a[0] == t:
d[i] += 1
res = 0
for i in range(3):
for j in range(i + 1, 4):
for k in range(j + 1, 5):
res += d[i] * d[j] * d[k]
print(res)
| from collections import Counter, defaultdict, deque
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n = inp()
d = defaultdict(int)
for _ in range(n):
s = eval(input())
d[s[0]] += 1
res = 0
li = ["M", "A", "R", "C", "H"]
for i in range(3):
a = li[i]
for j in range(i + 1, 4):
b = li[j]
for k in range(j + 1, 5):
c = li[k]
res += d[a] * d[b] * d[c]
print(res)
| false | 4 | [
"-from heapq import heappop, heappush, heapify",
"-import sys, bisect, math, itertools, fractions",
"-from decimal import Decimal",
"+from heapq import heappop, heappush",
"+from bisect import bisect_left, bisect_right",
"+import sys, math, itertools, fractions",
"-s = [\"M\", \"A\", \"R\", \"C\", \"H\"]",
"- a = eval(input())",
"- for i, t in enumerate(s):",
"- if a[0] == t:",
"- d[i] += 1",
"+ s = eval(input())",
"+ d[s[0]] += 1",
"+li = [\"M\", \"A\", \"R\", \"C\", \"H\"]",
"+ a = li[i]",
"+ b = li[j]",
"- res += d[i] * d[j] * d[k]",
"+ c = li[k]",
"+ res += d[a] * d[b] * d[c]"
] | false | 0.044756 | 0.034876 | 1.28332 | [
"s659288287",
"s451541919"
] |
u863442865 | p03031 | python | s071664121 | s826878249 | 40 | 35 | 3,316 | 3,188 | Accepted | Accepted | 12.5 | '''
https://atcoder.jp/contests/abc128/tasks/abc128_c
'''
def main():
import sys
#input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import Counter, deque
#mod = 1000000007
n, m = list(map(int, input().split()))
switch_list = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ret = 0
for j in range(2**n):
cnt = 0
for i in range(m):
total = 0
for k in switch_list[i][1:]:
if j & 2**(k-1):
total += 1
if total%2 == p[i]:
cnt += 1
else:
break
if cnt == m:
ret += 1
print(ret)
if __name__ == '__main__':
main() | def main():
n, m = list(map(int, input().split()))
switch_list = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ret = 0
for j in range(2**n):
for i in range(m):
total = 0
flag = 1
for k in switch_list[i][1:]:
if j & 2**(k-1):
total += 1
if not total%2 == p[i]:
flag = 0
break
if flag:
ret += 1
print(ret)
if __name__ == '__main__':
main() | 31 | 21 | 796 | 566 | """
https://atcoder.jp/contests/abc128/tasks/abc128_c
"""
def main():
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10000000)
from collections import Counter, deque
# mod = 1000000007
n, m = list(map(int, input().split()))
switch_list = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ret = 0
for j in range(2**n):
cnt = 0
for i in range(m):
total = 0
for k in switch_list[i][1:]:
if j & 2 ** (k - 1):
total += 1
if total % 2 == p[i]:
cnt += 1
else:
break
if cnt == m:
ret += 1
print(ret)
if __name__ == "__main__":
main()
| def main():
n, m = list(map(int, input().split()))
switch_list = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))
ret = 0
for j in range(2**n):
for i in range(m):
total = 0
flag = 1
for k in switch_list[i][1:]:
if j & 2 ** (k - 1):
total += 1
if not total % 2 == p[i]:
flag = 0
break
if flag:
ret += 1
print(ret)
if __name__ == "__main__":
main()
| false | 32.258065 | [
"-\"\"\"",
"-https://atcoder.jp/contests/abc128/tasks/abc128_c",
"-\"\"\"",
"-",
"-",
"- import sys",
"-",
"- # input = sys.stdin.readline",
"- sys.setrecursionlimit(10000000)",
"- from collections import Counter, deque",
"-",
"- # mod = 1000000007",
"- cnt = 0",
"+ flag = 1",
"- if total % 2 == p[i]:",
"- cnt += 1",
"- else:",
"+ if not total % 2 == p[i]:",
"+ flag = 0",
"- if cnt == m:",
"+ if flag:"
] | false | 0.039335 | 0.040909 | 0.961531 | [
"s071664121",
"s826878249"
] |
u906501980 | p02744 | python | s781107624 | s759513991 | 797 | 447 | 97,784 | 49,092 | Accepted | Accepted | 43.91 | n = int(eval(input()))
s = set(list("abcdefghijk"))
class Node:
def __init__(self, char, parents):
self.children = []
self.string = parents+char
self.charset = set(self.string)
def get_children(self):
parents = self.string
for c in sorted(list(self.charset|set(min(s-self.charset)))):
self.children.append(Node(c, parents))
return self.children
root = Node("a", "")
children = [root]
for _ in range(n-1):
parents, children = children, []
for parent in parents:
children.extend(parent.get_children())
for child in children:
print((child.string)) | n = int(eval(input()))
s = "abcdefghij"
class Node:
def __init__(self, string, index):
self.children = []
self.string = string
self.index = index
def get_children(self):
parent = self.string
for i, c in enumerate(s[:self.index+1]):
self.children.append(Node(parent+c, self.index if self.index>i else i+1))
return self.children
root = Node("a", 1)
children = [root]
for _ in range(n-1):
parents, children = children, []
for parent in parents:
children.extend(parent.get_children())
for child in children:
print((child.string)) | 23 | 23 | 649 | 630 | n = int(eval(input()))
s = set(list("abcdefghijk"))
class Node:
def __init__(self, char, parents):
self.children = []
self.string = parents + char
self.charset = set(self.string)
def get_children(self):
parents = self.string
for c in sorted(list(self.charset | set(min(s - self.charset)))):
self.children.append(Node(c, parents))
return self.children
root = Node("a", "")
children = [root]
for _ in range(n - 1):
parents, children = children, []
for parent in parents:
children.extend(parent.get_children())
for child in children:
print((child.string))
| n = int(eval(input()))
s = "abcdefghij"
class Node:
def __init__(self, string, index):
self.children = []
self.string = string
self.index = index
def get_children(self):
parent = self.string
for i, c in enumerate(s[: self.index + 1]):
self.children.append(
Node(parent + c, self.index if self.index > i else i + 1)
)
return self.children
root = Node("a", 1)
children = [root]
for _ in range(n - 1):
parents, children = children, []
for parent in parents:
children.extend(parent.get_children())
for child in children:
print((child.string))
| false | 0 | [
"-s = set(list(\"abcdefghijk\"))",
"+s = \"abcdefghij\"",
"- def __init__(self, char, parents):",
"+ def __init__(self, string, index):",
"- self.string = parents + char",
"- self.charset = set(self.string)",
"+ self.string = string",
"+ self.index = index",
"- parents = self.string",
"- for c in sorted(list(self.charset | set(min(s - self.charset)))):",
"- self.children.append(Node(c, parents))",
"+ parent = self.string",
"+ for i, c in enumerate(s[: self.index + 1]):",
"+ self.children.append(",
"+ Node(parent + c, self.index if self.index > i else i + 1)",
"+ )",
"-root = Node(\"a\", \"\")",
"+root = Node(\"a\", 1)"
] | false | 0.039053 | 0.086444 | 0.451775 | [
"s781107624",
"s759513991"
] |
u340781749 | p02949 | python | s126171336 | s117681622 | 1,359 | 1,206 | 99,164 | 100,060 | Accepted | Accepted | 11.26 | import sys
from collections import defaultdict
def reverse_search(n, parents):
q = [n - 1]
visited = set()
while q:
v = q.pop()
if v in visited:
continue
visited.add(v)
q.extend(u for u in parents[v] if u not in visited)
return visited
n, m, p = list(map(int, input().split()))
INF = 10 ** 12
links = [set() for _ in range(n)]
parents = [set() for _ in range(n)]
costs = [[INF] * n for _ in range(n)]
for line in sys.stdin:
a, b, c = list(map(int, line.split()))
a -= 1
b -= 1
links[a].add(b)
parents[b].add(a)
costs[a][b] = min(costs[a][b], p - c)
reachable = reverse_search(n, parents)
dist = [INF] * n
dist[0] = 0
for _ in range(len(reachable)):
updated = False
for v in reachable:
d = dist[v]
if d == INF:
continue
cv = costs[v]
for u in links[v]:
if dist[u] > d + cv[u]:
dist[u] = d + cv[u]
updated = True
if not updated:
break
else:
print((-1))
exit()
print((max(0, -dist[n - 1])))
| import sys
from collections import defaultdict
def reverse_search(n, parents):
q = [n - 1]
visited = set()
while q:
v = q.pop()
if v in visited:
continue
visited.add(v)
q.extend(u for u in parents[v] if u not in visited)
return visited
n, m, p = list(map(int, input().split()))
INF = 10 ** 12
links = [set() for _ in range(n)]
parents = [set() for _ in range(n)]
costs = [[INF] * n for _ in range(n)]
for line in sys.stdin:
a, b, c = list(map(int, line.split()))
a -= 1
b -= 1
links[a].add(b)
parents[b].add(a)
costs[a][b] = min(costs[a][b], p - c)
reachable = reverse_search(n, parents)
links = list(map(reachable.intersection, links))
dist = [INF] * n
dist[0] = 0
for _ in range(len(reachable)):
updated = False
for v in reachable:
d = dist[v]
if d == INF:
continue
cv = costs[v]
for u in links[v]:
if dist[u] > d + cv[u]:
dist[u] = d + cv[u]
updated = True
if not updated:
break
else:
print((-1))
exit()
print((max(0, -dist[n - 1])))
| 50 | 51 | 1,133 | 1,183 | import sys
from collections import defaultdict
def reverse_search(n, parents):
q = [n - 1]
visited = set()
while q:
v = q.pop()
if v in visited:
continue
visited.add(v)
q.extend(u for u in parents[v] if u not in visited)
return visited
n, m, p = list(map(int, input().split()))
INF = 10**12
links = [set() for _ in range(n)]
parents = [set() for _ in range(n)]
costs = [[INF] * n for _ in range(n)]
for line in sys.stdin:
a, b, c = list(map(int, line.split()))
a -= 1
b -= 1
links[a].add(b)
parents[b].add(a)
costs[a][b] = min(costs[a][b], p - c)
reachable = reverse_search(n, parents)
dist = [INF] * n
dist[0] = 0
for _ in range(len(reachable)):
updated = False
for v in reachable:
d = dist[v]
if d == INF:
continue
cv = costs[v]
for u in links[v]:
if dist[u] > d + cv[u]:
dist[u] = d + cv[u]
updated = True
if not updated:
break
else:
print((-1))
exit()
print((max(0, -dist[n - 1])))
| import sys
from collections import defaultdict
def reverse_search(n, parents):
q = [n - 1]
visited = set()
while q:
v = q.pop()
if v in visited:
continue
visited.add(v)
q.extend(u for u in parents[v] if u not in visited)
return visited
n, m, p = list(map(int, input().split()))
INF = 10**12
links = [set() for _ in range(n)]
parents = [set() for _ in range(n)]
costs = [[INF] * n for _ in range(n)]
for line in sys.stdin:
a, b, c = list(map(int, line.split()))
a -= 1
b -= 1
links[a].add(b)
parents[b].add(a)
costs[a][b] = min(costs[a][b], p - c)
reachable = reverse_search(n, parents)
links = list(map(reachable.intersection, links))
dist = [INF] * n
dist[0] = 0
for _ in range(len(reachable)):
updated = False
for v in reachable:
d = dist[v]
if d == INF:
continue
cv = costs[v]
for u in links[v]:
if dist[u] > d + cv[u]:
dist[u] = d + cv[u]
updated = True
if not updated:
break
else:
print((-1))
exit()
print((max(0, -dist[n - 1])))
| false | 1.960784 | [
"+links = list(map(reachable.intersection, links))"
] | false | 0.043931 | 0.043396 | 1.012326 | [
"s126171336",
"s117681622"
] |
u636683284 | p02813 | python | s640607749 | s529445552 | 182 | 74 | 44,912 | 73,516 | Accepted | Accepted | 59.34 | import itertools
n = int(eval(input()))
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
l = [i+1 for i in range(n)]
r = list(itertools.permutations(l))
j = 0
flagp = True
flagq = True
while flagp:
if r[j] == p:
x = j+1
flagp = False
j += 1
j = 0
while flagq:
if r[j] == q:
y = j+1
flagq = False
j += 1
print((abs(y-x))) | from itertools import permutations
n = int(eval(input()))
p = tuple(input().split())
q = tuple(input().split())
# print(p)
# print(q)
l = [str(i+1) for i in range(n)]
cnt = 1
for v in permutations(l,n):
if p == v:
a = cnt
if q == v:
b = cnt
cnt += 1
print((abs(a-b))) | 21 | 18 | 379 | 307 | import itertools
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
l = [i + 1 for i in range(n)]
r = list(itertools.permutations(l))
j = 0
flagp = True
flagq = True
while flagp:
if r[j] == p:
x = j + 1
flagp = False
j += 1
j = 0
while flagq:
if r[j] == q:
y = j + 1
flagq = False
j += 1
print((abs(y - x)))
| from itertools import permutations
n = int(eval(input()))
p = tuple(input().split())
q = tuple(input().split())
# print(p)
# print(q)
l = [str(i + 1) for i in range(n)]
cnt = 1
for v in permutations(l, n):
if p == v:
a = cnt
if q == v:
b = cnt
cnt += 1
print((abs(a - b)))
| false | 14.285714 | [
"-import itertools",
"+from itertools import permutations",
"-p = tuple(map(int, input().split()))",
"-q = tuple(map(int, input().split()))",
"-l = [i + 1 for i in range(n)]",
"-r = list(itertools.permutations(l))",
"-j = 0",
"-flagp = True",
"-flagq = True",
"-while flagp:",
"- if r[j] == p:",
"- x = j + 1",
"- flagp = False",
"- j += 1",
"-j = 0",
"-while flagq:",
"- if r[j] == q:",
"- y = j + 1",
"- flagq = False",
"- j += 1",
"-print((abs(y - x)))",
"+p = tuple(input().split())",
"+q = tuple(input().split())",
"+# print(p)",
"+# print(q)",
"+l = [str(i + 1) for i in range(n)]",
"+cnt = 1",
"+for v in permutations(l, n):",
"+ if p == v:",
"+ a = cnt",
"+ if q == v:",
"+ b = cnt",
"+ cnt += 1",
"+print((abs(a - b)))"
] | false | 0.046722 | 0.045872 | 1.018522 | [
"s640607749",
"s529445552"
] |
u393253137 | p03611 | python | s893287210 | s258987296 | 113 | 67 | 14,008 | 13,964 | Accepted | Accepted | 40.71 | n = int(eval(input()))
A = sorted(map(int, input().split()))
D = [0]*(A[-1]+3)
for a in A:
D[a-1] += 1
D[a] += 1
D[a+1] += 1
print((max(D))) | n = int(eval(input()))
A = list(map(int, input().split()))
cnt = [0] * 10**5
for a in A:
cnt[a] += 1
print((max(list(map(sum, list(zip(cnt, cnt[1:], cnt[2:]))))))) | 8 | 6 | 151 | 152 | n = int(eval(input()))
A = sorted(map(int, input().split()))
D = [0] * (A[-1] + 3)
for a in A:
D[a - 1] += 1
D[a] += 1
D[a + 1] += 1
print((max(D)))
| n = int(eval(input()))
A = list(map(int, input().split()))
cnt = [0] * 10**5
for a in A:
cnt[a] += 1
print((max(list(map(sum, list(zip(cnt, cnt[1:], cnt[2:])))))))
| false | 25 | [
"-A = sorted(map(int, input().split()))",
"-D = [0] * (A[-1] + 3)",
"+A = list(map(int, input().split()))",
"+cnt = [0] * 10**5",
"- D[a - 1] += 1",
"- D[a] += 1",
"- D[a + 1] += 1",
"-print((max(D)))",
"+ cnt[a] += 1",
"+print((max(list(map(sum, list(zip(cnt, cnt[1:], cnt[2:])))))))"
] | false | 0.055422 | 0.077961 | 0.710896 | [
"s893287210",
"s258987296"
] |
u332906195 | p02629 | python | s123769253 | s343868563 | 34 | 31 | 9,072 | 8,964 | Accepted | Accepted | 8.82 | N, ans = int(eval(input())), []
while N > 0:
N = N - 1
ans.append(chr(N % 26 + ord('a')))
N = N // 26
print((''.join(ans[::-1])))
| N, ans = int(eval(input())), ''
while N > 0:
N = N - 1
ans += chr(N % 26 + ord('a'))
N //= 26
print((ans[::-1]))
| 6 | 6 | 139 | 122 | N, ans = int(eval(input())), []
while N > 0:
N = N - 1
ans.append(chr(N % 26 + ord("a")))
N = N // 26
print(("".join(ans[::-1])))
| N, ans = int(eval(input())), ""
while N > 0:
N = N - 1
ans += chr(N % 26 + ord("a"))
N //= 26
print((ans[::-1]))
| false | 0 | [
"-N, ans = int(eval(input())), []",
"+N, ans = int(eval(input())), \"\"",
"- ans.append(chr(N % 26 + ord(\"a\")))",
"- N = N // 26",
"-print((\"\".join(ans[::-1])))",
"+ ans += chr(N % 26 + ord(\"a\"))",
"+ N //= 26",
"+print((ans[::-1]))"
] | false | 0.04729 | 0.048689 | 0.971263 | [
"s123769253",
"s343868563"
] |
u678167152 | p03544 | python | s457229543 | s708046352 | 164 | 61 | 38,256 | 61,780 | Accepted | Accepted | 62.8 | N = int(eval(input()))
L = [0]*(N+1)
L[0],L[1]=2,1
for i in range(2,N+1):
L[i] = L[i-1]+L[i-2]
print((L[N])) | def solve():
ans = 0
N = int(eval(input()))
dp = [0]*(N+1)
dp[0]=2
dp[1]=1
for i in range(2,N+1):
dp[i] = dp[i-1]+dp[i-2]
return dp[-1]
print((solve())) | 6 | 10 | 107 | 189 | N = int(eval(input()))
L = [0] * (N + 1)
L[0], L[1] = 2, 1
for i in range(2, N + 1):
L[i] = L[i - 1] + L[i - 2]
print((L[N]))
| def solve():
ans = 0
N = int(eval(input()))
dp = [0] * (N + 1)
dp[0] = 2
dp[1] = 1
for i in range(2, N + 1):
dp[i] = dp[i - 1] + dp[i - 2]
return dp[-1]
print((solve()))
| false | 40 | [
"-N = int(eval(input()))",
"-L = [0] * (N + 1)",
"-L[0], L[1] = 2, 1",
"-for i in range(2, N + 1):",
"- L[i] = L[i - 1] + L[i - 2]",
"-print((L[N]))",
"+def solve():",
"+ ans = 0",
"+ N = int(eval(input()))",
"+ dp = [0] * (N + 1)",
"+ dp[0] = 2",
"+ dp[1] = 1",
"+ for i in range(2, N + 1):",
"+ dp[i] = dp[i - 1] + dp[i - 2]",
"+ return dp[-1]",
"+",
"+",
"+print((solve()))"
] | false | 0.11369 | 0.126212 | 0.900781 | [
"s457229543",
"s708046352"
] |
u285443936 | p03290 | python | s569374309 | s584038066 | 54 | 40 | 3,064 | 9,236 | Accepted | Accepted | 25.93 | D, G = list(map(int, input().split()))
table = []
for i in range(D):
p,c = list(map(int, input().split()))
table.append((i+1,p,c))
ans = 10**3
for i in range(1<<D):
count = 0
score = 0
remain = []
for j in range(D):
d,p,c = table[j]
if i & (1<<j):
score += 100*(d)*p+c
count += p
else:
remain.append((d,p,c))
if score < G:
remain.sort(reverse=True)
d,p,c = remain[0]
while score < G and p > 0:
score += 100*d
count += 1
p -= 1
if score >= G:
ans = min(ans,count)
print(ans) | D, G = list(map(int,input().split()))
table = []
ans = 0
for i in range(D):
p,c = list(map(int,input().split()))
ans += p
table.append((p,c))
for i in range(2**D):
score = 0
n = 0
solved = [0] * D
for j in range(D):
if i>>j & 1:
p,c = table[j]
solved[j] = 1
score += 100*(j+1)*p+c
n += p
if score<G:
for k in range(D-1,-1,-1):
if solved[k] == 0:
p = table[k][0]
for l in range(1,p):
score += 100*(k+1)
n += 1
if score>=G:
break
break
if score>=G:
ans = min(n,ans)
print(ans) | 27 | 34 | 647 | 751 | D, G = list(map(int, input().split()))
table = []
for i in range(D):
p, c = list(map(int, input().split()))
table.append((i + 1, p, c))
ans = 10**3
for i in range(1 << D):
count = 0
score = 0
remain = []
for j in range(D):
d, p, c = table[j]
if i & (1 << j):
score += 100 * (d) * p + c
count += p
else:
remain.append((d, p, c))
if score < G:
remain.sort(reverse=True)
d, p, c = remain[0]
while score < G and p > 0:
score += 100 * d
count += 1
p -= 1
if score >= G:
ans = min(ans, count)
print(ans)
| D, G = list(map(int, input().split()))
table = []
ans = 0
for i in range(D):
p, c = list(map(int, input().split()))
ans += p
table.append((p, c))
for i in range(2**D):
score = 0
n = 0
solved = [0] * D
for j in range(D):
if i >> j & 1:
p, c = table[j]
solved[j] = 1
score += 100 * (j + 1) * p + c
n += p
if score < G:
for k in range(D - 1, -1, -1):
if solved[k] == 0:
p = table[k][0]
for l in range(1, p):
score += 100 * (k + 1)
n += 1
if score >= G:
break
break
if score >= G:
ans = min(n, ans)
print(ans)
| false | 20.588235 | [
"+ans = 0",
"- table.append((i + 1, p, c))",
"-ans = 10**3",
"-for i in range(1 << D):",
"- count = 0",
"+ ans += p",
"+ table.append((p, c))",
"+for i in range(2**D):",
"- remain = []",
"+ n = 0",
"+ solved = [0] * D",
"- d, p, c = table[j]",
"- if i & (1 << j):",
"- score += 100 * (d) * p + c",
"- count += p",
"- else:",
"- remain.append((d, p, c))",
"+ if i >> j & 1:",
"+ p, c = table[j]",
"+ solved[j] = 1",
"+ score += 100 * (j + 1) * p + c",
"+ n += p",
"- remain.sort(reverse=True)",
"- d, p, c = remain[0]",
"- while score < G and p > 0:",
"- score += 100 * d",
"- count += 1",
"- p -= 1",
"+ for k in range(D - 1, -1, -1):",
"+ if solved[k] == 0:",
"+ p = table[k][0]",
"+ for l in range(1, p):",
"+ score += 100 * (k + 1)",
"+ n += 1",
"+ if score >= G:",
"+ break",
"+ break",
"- ans = min(ans, count)",
"+ ans = min(n, ans)"
] | false | 0.043086 | 0.042505 | 1.013678 | [
"s569374309",
"s584038066"
] |
u328751895 | p03339 | python | s753133202 | s573950654 | 165 | 78 | 3,672 | 3,700 | Accepted | Accepted | 52.73 | N = int(eval(input()))
S = eval(input())
l = 0
r = S.count("E", 1, len(S))
ans = l + r
for i in range(1, len(S)):
if S[i] == "E":
r -= 1
if S[i - 1] == "W":
l += 1
ans = ans if ans <= l + r else l + r
print(ans) | eval(input())
S = eval(input())
ans = ans_cur = S.count("E")
for c in S:
if c == "E":
ans_cur -= 1
else:
ans_cur += 1
ans = ans if ans <= ans_cur else ans_cur
print(ans) | 15 | 11 | 244 | 196 | N = int(eval(input()))
S = eval(input())
l = 0
r = S.count("E", 1, len(S))
ans = l + r
for i in range(1, len(S)):
if S[i] == "E":
r -= 1
if S[i - 1] == "W":
l += 1
ans = ans if ans <= l + r else l + r
print(ans)
| eval(input())
S = eval(input())
ans = ans_cur = S.count("E")
for c in S:
if c == "E":
ans_cur -= 1
else:
ans_cur += 1
ans = ans if ans <= ans_cur else ans_cur
print(ans)
| false | 26.666667 | [
"-N = int(eval(input()))",
"+eval(input())",
"-l = 0",
"-r = S.count(\"E\", 1, len(S))",
"-ans = l + r",
"-for i in range(1, len(S)):",
"- if S[i] == \"E\":",
"- r -= 1",
"- if S[i - 1] == \"W\":",
"- l += 1",
"- ans = ans if ans <= l + r else l + r",
"+ans = ans_cur = S.count(\"E\")",
"+for c in S:",
"+ if c == \"E\":",
"+ ans_cur -= 1",
"+ else:",
"+ ans_cur += 1",
"+ ans = ans if ans <= ans_cur else ans_cur"
] | false | 0.045699 | 0.047148 | 0.969263 | [
"s753133202",
"s573950654"
] |
u352394527 | p00441 | python | s207111064 | s294427625 | 19,810 | 15,870 | 6,392 | 6,396 | Accepted | Accepted | 19.89 | def main():
#points = [[False for i in range(5001)] for j in range(5001)]
while True:
n = int(eval(input()))
if not n:
break
ps = []
dic = {}
for i in range(n):
x, y = list(map(int,input().split()))
dic[(x, y)] = 1;
#points[x][y] = True
ps.append((x,y))
ans = 0
for i in range(n):
for j in range(n):
p1 = ps[i]
p2 = ps[j]
vx = p2[0] - p1[0]
vy = p2[1] - p1[1]
#if 0 <= p1[0] + vy <= 5000 and 0 <= p1[1] - vx <= 5000 and 0 <= p2[0] + vy <= 5000 and 0 <= p2[1] - vx <= 5000:
# if points[p1[0] + vy][p1[1] - vx] and points[p2[0] + vy][p2[1] - vx]:
if (p1[0] + vy, p1[1] - vx) in dic and (p2[0] + vy, p2[1] - vx) in dic:
ans = max(ans, vx ** 2 + vy ** 2)
#for p in ps:
# points[p[0]][p[1]] = False
print(ans)
main()
| def main():
while True:
n = int(eval(input()))
if not n:
break
ps = []
dic = {}
for i in range(n):
x, y = list(map(int,input().split()))
dic[(x, y)] = 1;
ps.append((x,y))
ans = 0
for i in range(n):
for j in range(n):
p1 = ps[i]
p2 = ps[j]
p1x = p1[0]
p1y = p1[1]
p2x = p2[0]
p2y = p2[1]
vx = p2x - p1x
vy = p2y - p1y
if (p1x + vy, p1y - vx) in dic and (p2x + vy, p2y - vx) in dic:
ans = max(ans, vx ** 2 + vy ** 2)
print(ans)
main()
| 36 | 34 | 903 | 618 | def main():
# points = [[False for i in range(5001)] for j in range(5001)]
while True:
n = int(eval(input()))
if not n:
break
ps = []
dic = {}
for i in range(n):
x, y = list(map(int, input().split()))
dic[(x, y)] = 1
# points[x][y] = True
ps.append((x, y))
ans = 0
for i in range(n):
for j in range(n):
p1 = ps[i]
p2 = ps[j]
vx = p2[0] - p1[0]
vy = p2[1] - p1[1]
# if 0 <= p1[0] + vy <= 5000 and 0 <= p1[1] - vx <= 5000 and 0 <= p2[0] + vy <= 5000 and 0 <= p2[1] - vx <= 5000:
# if points[p1[0] + vy][p1[1] - vx] and points[p2[0] + vy][p2[1] - vx]:
if (p1[0] + vy, p1[1] - vx) in dic and (p2[0] + vy, p2[1] - vx) in dic:
ans = max(ans, vx**2 + vy**2)
# for p in ps:
# points[p[0]][p[1]] = False
print(ans)
main()
| def main():
while True:
n = int(eval(input()))
if not n:
break
ps = []
dic = {}
for i in range(n):
x, y = list(map(int, input().split()))
dic[(x, y)] = 1
ps.append((x, y))
ans = 0
for i in range(n):
for j in range(n):
p1 = ps[i]
p2 = ps[j]
p1x = p1[0]
p1y = p1[1]
p2x = p2[0]
p2y = p2[1]
vx = p2x - p1x
vy = p2y - p1y
if (p1x + vy, p1y - vx) in dic and (p2x + vy, p2y - vx) in dic:
ans = max(ans, vx**2 + vy**2)
print(ans)
main()
| false | 5.555556 | [
"- # points = [[False for i in range(5001)] for j in range(5001)]",
"- # points[x][y] = True",
"- vx = p2[0] - p1[0]",
"- vy = p2[1] - p1[1]",
"- # if 0 <= p1[0] + vy <= 5000 and 0 <= p1[1] - vx <= 5000 and 0 <= p2[0] + vy <= 5000 and 0 <= p2[1] - vx <= 5000:",
"- # if points[p1[0] + vy][p1[1] - vx] and points[p2[0] + vy][p2[1] - vx]:",
"- if (p1[0] + vy, p1[1] - vx) in dic and (p2[0] + vy, p2[1] - vx) in dic:",
"+ p1x = p1[0]",
"+ p1y = p1[1]",
"+ p2x = p2[0]",
"+ p2y = p2[1]",
"+ vx = p2x - p1x",
"+ vy = p2y - p1y",
"+ if (p1x + vy, p1y - vx) in dic and (p2x + vy, p2y - vx) in dic:",
"- # for p in ps:",
"- # points[p[0]][p[1]] = False"
] | false | 0.039836 | 0.040216 | 0.990555 | [
"s207111064",
"s294427625"
] |
u958693198 | p02850 | python | s664625712 | s690161642 | 420 | 383 | 30,860 | 27,732 | Accepted | Accepted | 8.81 | import sys
input = sys.stdin.readline
N = int(eval(input()))
X = [[] for _ in range(N)]
P = [-1] * N
for i in range(N-1):
a, b = list(map(int, input().split()))
X[a-1].append((i, b-1))
#print(X)
P[b-1] = a-1
Q = [(0, -1)]
ANS = [-1] * (N-1)
while Q:
x, c0 = Q.pop()
c = 1
for i, y in X[x]:
if c == c0: c += 1
ANS[i] = c
Q.append((y, c))
c += 1
print((max(ANS)))
for ans in ANS:
print(ans) | import sys
input = sys.stdin.readline
N = int(eval(input()))
X = [[] for _ in range(N)]
P = [-1] * N
for i in range(N-1):
a, b = list(map(int, input().split()))
X[a-1].append((i, b-1))
#print(X)
#P[b-1] = a-1
#print(X)
Q = [(0, -1)]
ANS = [-1] * (N-1)
maxc = 0
while Q:
x, c0 = Q.pop()
c = 1
for i, y in X[x]:
if c == c0: c += 1
ANS[i] = c
if c>maxc:maxc=c
Q.append((y, c))
c += 1
print(maxc)
for ans in ANS:
print(ans) | 25 | 28 | 464 | 508 | import sys
input = sys.stdin.readline
N = int(eval(input()))
X = [[] for _ in range(N)]
P = [-1] * N
for i in range(N - 1):
a, b = list(map(int, input().split()))
X[a - 1].append((i, b - 1))
# print(X)
P[b - 1] = a - 1
Q = [(0, -1)]
ANS = [-1] * (N - 1)
while Q:
x, c0 = Q.pop()
c = 1
for i, y in X[x]:
if c == c0:
c += 1
ANS[i] = c
Q.append((y, c))
c += 1
print((max(ANS)))
for ans in ANS:
print(ans)
| import sys
input = sys.stdin.readline
N = int(eval(input()))
X = [[] for _ in range(N)]
P = [-1] * N
for i in range(N - 1):
a, b = list(map(int, input().split()))
X[a - 1].append((i, b - 1))
# print(X)
# P[b-1] = a-1
# print(X)
Q = [(0, -1)]
ANS = [-1] * (N - 1)
maxc = 0
while Q:
x, c0 = Q.pop()
c = 1
for i, y in X[x]:
if c == c0:
c += 1
ANS[i] = c
if c > maxc:
maxc = c
Q.append((y, c))
c += 1
print(maxc)
for ans in ANS:
print(ans)
| false | 10.714286 | [
"- P[b - 1] = a - 1",
"+ # P[b-1] = a-1",
"+# print(X)",
"+maxc = 0",
"+ if c > maxc:",
"+ maxc = c",
"-print((max(ANS)))",
"+print(maxc)"
] | false | 0.046567 | 0.046108 | 1.009964 | [
"s664625712",
"s690161642"
] |
u540762794 | p03435 | python | s751099650 | s010076954 | 119 | 28 | 27,120 | 9,100 | Accepted | Accepted | 76.47 | # -*- coding: utf-8 -*-
import numpy as np
# worst order: 101^6 => 10^8
c = []
c.append(list(map(int, input().split())))
c.append(list(map(int, input().split())))
c.append(list(map(int, input().split())))
arr_c = np.array(c)
a_max = np.amax(arr_c, axis=1)
b_max = np.amax(arr_c, axis=0)
a = []
b = []
for i in range(3):
if len(list(range(0, a_max[i]+1, 1)))==0:
a.append([0])
else:
a.append(list(range(0, a_max[i]+1, 1)))
if len(list(range(0, b_max[i]+1, 1)))==0:
b.append([0])
else:
b.append(list(range(0, b_max[i]+1, 1)))
ans = 'No'
cnt = 0
for a0 in a[0]:
for b0 in b[0]:
if c[0][0] != a0 + b0:
continue
for a1 in a[1]:
if c[1][0] != a1 + b0:
continue
for b1 in b[1]:
if c[0][1] != a0 + b1 or c[1][1] != a1 + b1:
continue
for a2 in a[2]:
if c[2][0] != a2 + b0 or c[2][1] != a2 + b1:
continue
for b2 in b[2]:
if c[0][2] != a0 + b2 or c[1][2] != a1 + b2 or c[2][2] != a2 + b2:
continue
print("Yes")
exit(0)
print(ans) | # -*- coding: utf-8 -*-
c = [list(map(int, input().split())) for _ in range(3)]
a = [0] * 3
b = [0] * 3
for j in range(3):
b[j] = c[0][j] - a[0]
for i in range(1,3,1):
a[i] = c[i][0] - b[0]
for i in range(3):
for j in range(3):
if c[i][j] != a[i] + b[j]:
print("No")
exit()
print("Yes")
| 50 | 20 | 1,318 | 356 | # -*- coding: utf-8 -*-
import numpy as np
# worst order: 101^6 => 10^8
c = []
c.append(list(map(int, input().split())))
c.append(list(map(int, input().split())))
c.append(list(map(int, input().split())))
arr_c = np.array(c)
a_max = np.amax(arr_c, axis=1)
b_max = np.amax(arr_c, axis=0)
a = []
b = []
for i in range(3):
if len(list(range(0, a_max[i] + 1, 1))) == 0:
a.append([0])
else:
a.append(list(range(0, a_max[i] + 1, 1)))
if len(list(range(0, b_max[i] + 1, 1))) == 0:
b.append([0])
else:
b.append(list(range(0, b_max[i] + 1, 1)))
ans = "No"
cnt = 0
for a0 in a[0]:
for b0 in b[0]:
if c[0][0] != a0 + b0:
continue
for a1 in a[1]:
if c[1][0] != a1 + b0:
continue
for b1 in b[1]:
if c[0][1] != a0 + b1 or c[1][1] != a1 + b1:
continue
for a2 in a[2]:
if c[2][0] != a2 + b0 or c[2][1] != a2 + b1:
continue
for b2 in b[2]:
if (
c[0][2] != a0 + b2
or c[1][2] != a1 + b2
or c[2][2] != a2 + b2
):
continue
print("Yes")
exit(0)
print(ans)
| # -*- coding: utf-8 -*-
c = [list(map(int, input().split())) for _ in range(3)]
a = [0] * 3
b = [0] * 3
for j in range(3):
b[j] = c[0][j] - a[0]
for i in range(1, 3, 1):
a[i] = c[i][0] - b[0]
for i in range(3):
for j in range(3):
if c[i][j] != a[i] + b[j]:
print("No")
exit()
print("Yes")
| false | 60 | [
"-import numpy as np",
"-",
"-# worst order: 101^6 => 10^8",
"-c = []",
"-c.append(list(map(int, input().split())))",
"-c.append(list(map(int, input().split())))",
"-c.append(list(map(int, input().split())))",
"-arr_c = np.array(c)",
"-a_max = np.amax(arr_c, axis=1)",
"-b_max = np.amax(arr_c, axis=0)",
"-a = []",
"-b = []",
"+c = [list(map(int, input().split())) for _ in range(3)]",
"+a = [0] * 3",
"+b = [0] * 3",
"+for j in range(3):",
"+ b[j] = c[0][j] - a[0]",
"+for i in range(1, 3, 1):",
"+ a[i] = c[i][0] - b[0]",
"- if len(list(range(0, a_max[i] + 1, 1))) == 0:",
"- a.append([0])",
"- else:",
"- a.append(list(range(0, a_max[i] + 1, 1)))",
"- if len(list(range(0, b_max[i] + 1, 1))) == 0:",
"- b.append([0])",
"- else:",
"- b.append(list(range(0, b_max[i] + 1, 1)))",
"-ans = \"No\"",
"-cnt = 0",
"-for a0 in a[0]:",
"- for b0 in b[0]:",
"- if c[0][0] != a0 + b0:",
"- continue",
"- for a1 in a[1]:",
"- if c[1][0] != a1 + b0:",
"- continue",
"- for b1 in b[1]:",
"- if c[0][1] != a0 + b1 or c[1][1] != a1 + b1:",
"- continue",
"- for a2 in a[2]:",
"- if c[2][0] != a2 + b0 or c[2][1] != a2 + b1:",
"- continue",
"- for b2 in b[2]:",
"- if (",
"- c[0][2] != a0 + b2",
"- or c[1][2] != a1 + b2",
"- or c[2][2] != a2 + b2",
"- ):",
"- continue",
"- print(\"Yes\")",
"- exit(0)",
"-print(ans)",
"+ for j in range(3):",
"+ if c[i][j] != a[i] + b[j]:",
"+ print(\"No\")",
"+ exit()",
"+print(\"Yes\")"
] | false | 0.223581 | 0.036499 | 6.125656 | [
"s751099650",
"s010076954"
] |
u124498235 | p02713 | python | s842176409 | s575113461 | 1,332 | 1,169 | 10,428 | 9,184 | Accepted | Accepted | 12.24 | n = int(eval(input()))
import math
from fractions import gcd
s = 0
for i in range(1,n+1):
for j in range(1,n+1):
x = math.gcd(i,j)
for k in range(1,n+1):
s += math.gcd(x,k)
print (s) | from math import gcd
n = int(eval(input()))
s = 0
for i in range(1,n+1):
for j in range(1,n+1):
x = gcd(i,j)
for k in range(1,n+1):
s += gcd(x,k)
print (s) | 10 | 9 | 193 | 165 | n = int(eval(input()))
import math
from fractions import gcd
s = 0
for i in range(1, n + 1):
for j in range(1, n + 1):
x = math.gcd(i, j)
for k in range(1, n + 1):
s += math.gcd(x, k)
print(s)
| from math import gcd
n = int(eval(input()))
s = 0
for i in range(1, n + 1):
for j in range(1, n + 1):
x = gcd(i, j)
for k in range(1, n + 1):
s += gcd(x, k)
print(s)
| false | 10 | [
"+from math import gcd",
"+",
"-import math",
"-from fractions import gcd",
"-",
"- x = math.gcd(i, j)",
"+ x = gcd(i, j)",
"- s += math.gcd(x, k)",
"+ s += gcd(x, k)"
] | false | 0.006772 | 0.141651 | 0.047806 | [
"s842176409",
"s575113461"
] |
u057109575 | p02726 | python | s182038508 | s460725783 | 368 | 142 | 49,628 | 75,076 | Accepted | Accepted | 61.41 | N, X, Y = list(map(int, input().split()))
from collections import defaultdict
ans = defaultdict(int)
for i in range(N):
for j in range(i + 1, N):
idx = min(j - i, abs(j + 1 - Y) + 1 + abs(X - i - 1))
ans[idx] += 1
for i in range(1, N):
print((ans[i]))
|
from collections import defaultdict
N, X, Y = list(map(int, input().split()))
ctr = defaultdict(int)
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
d = min(j - i, abs(i - X) + 1 + abs(j - Y))
ctr[d] += 1
for i in range(1, N):
print((ctr[i]))
| 11 | 14 | 288 | 285 | N, X, Y = list(map(int, input().split()))
from collections import defaultdict
ans = defaultdict(int)
for i in range(N):
for j in range(i + 1, N):
idx = min(j - i, abs(j + 1 - Y) + 1 + abs(X - i - 1))
ans[idx] += 1
for i in range(1, N):
print((ans[i]))
| from collections import defaultdict
N, X, Y = list(map(int, input().split()))
ctr = defaultdict(int)
for i in range(1, N + 1):
for j in range(i + 1, N + 1):
d = min(j - i, abs(i - X) + 1 + abs(j - Y))
ctr[d] += 1
for i in range(1, N):
print((ctr[i]))
| false | 21.428571 | [
"-N, X, Y = list(map(int, input().split()))",
"-ans = defaultdict(int)",
"-for i in range(N):",
"- for j in range(i + 1, N):",
"- idx = min(j - i, abs(j + 1 - Y) + 1 + abs(X - i - 1))",
"- ans[idx] += 1",
"+N, X, Y = list(map(int, input().split()))",
"+ctr = defaultdict(int)",
"+for i in range(1, N + 1):",
"+ for j in range(i + 1, N + 1):",
"+ d = min(j - i, abs(i - X) + 1 + abs(j - Y))",
"+ ctr[d] += 1",
"- print((ans[i]))",
"+ print((ctr[i]))"
] | false | 0.034581 | 0.044003 | 0.785861 | [
"s182038508",
"s460725783"
] |
u102795616 | p02984 | python | s965181530 | s418042573 | 231 | 212 | 14,152 | 14,092 | Accepted | Accepted | 8.23 | N = int(input())
A = [int(i) for i in input().split()]
a = sum(A)
i = 1
while i < N:
a -= A[i] * 2
i += 2
print(str(a) + ' ', end='')
i = 1
while i < N:
a = A[i - 1] * 2 - a
print(str(a) + ' ', end='')
i += 1
| N = int(input())
A = [int(i) for i in input().split()]
a = sum(A)
i = 1
while i < N:
a -= A[i] * 2
i += 2
print(a, end=' ')
i = 1
while i < N:
a = A[i - 1] * 2 - a
print(a, end=' ')
i += 1
| 13 | 13 | 225 | 205 | N = int(input())
A = [int(i) for i in input().split()]
a = sum(A)
i = 1
while i < N:
a -= A[i] * 2
i += 2
print(str(a) + " ", end="")
i = 1
while i < N:
a = A[i - 1] * 2 - a
print(str(a) + " ", end="")
i += 1
| N = int(input())
A = [int(i) for i in input().split()]
a = sum(A)
i = 1
while i < N:
a -= A[i] * 2
i += 2
print(a, end=" ")
i = 1
while i < N:
a = A[i - 1] * 2 - a
print(a, end=" ")
i += 1
| false | 0 | [
"-print(str(a) + \" \", end=\"\")",
"+print(a, end=\" \")",
"- print(str(a) + \" \", end=\"\")",
"+ print(a, end=\" \")"
] | false | 0.100941 | 0.008677 | 11.633687 | [
"s965181530",
"s418042573"
] |
u747602774 | p03834 | python | s770892945 | s980851004 | 170 | 17 | 38,256 | 2,940 | Accepted | Accepted | 90 | s=input().split(',')
print((s[0],s[1],s[2])) | S = input().split(',')
print((' '.join(S)))
| 2 | 2 | 43 | 43 | s = input().split(",")
print((s[0], s[1], s[2]))
| S = input().split(",")
print((" ".join(S)))
| false | 0 | [
"-s = input().split(\",\")",
"-print((s[0], s[1], s[2]))",
"+S = input().split(\",\")",
"+print((\" \".join(S)))"
] | false | 0.103177 | 0.046807 | 2.204306 | [
"s770892945",
"s980851004"
] |
u312025627 | p03860 | python | s743537138 | s200604170 | 170 | 17 | 38,256 | 2,940 | Accepted | Accepted | 90 | a,b,c = (i for i in input().split())
print((a[0]+b[0]+c[0])) | def main():
a = [i for i in input().split()]
print(a[0][0], a[1][0], a[2][0], sep="")
if __name__ == '__main__':
main()
| 2 | 7 | 59 | 140 | a, b, c = (i for i in input().split())
print((a[0] + b[0] + c[0]))
| def main():
a = [i for i in input().split()]
print(a[0][0], a[1][0], a[2][0], sep="")
if __name__ == "__main__":
main()
| false | 71.428571 | [
"-a, b, c = (i for i in input().split())",
"-print((a[0] + b[0] + c[0]))",
"+def main():",
"+ a = [i for i in input().split()]",
"+ print(a[0][0], a[1][0], a[2][0], sep=\"\")",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.084992 | 0.03543 | 2.398864 | [
"s743537138",
"s200604170"
] |
u077291787 | p02928 | python | s023903277 | s533992587 | 46 | 40 | 10,284 | 9,364 | Accepted | Accepted | 13.04 | # B - Kleene Inversion
from typing import Optional, Sequence
class BinaryIndexedTree:
"""Binary Indexed Tree (Fenwick Tree)
Each operation runs in O(logN).
References:
http://hos.ac/slides/20140319_bit.pdf
"""
__slots__ = ["_size", "_tree", "is_zero_origin"]
def __init__(
self,
size: int,
initial_values: Optional[Sequence[int]] = None,
is_zero_origin: bool = True,
):
self._size = size
self._tree = [0] * (size + 1)
self.is_zero_origin = is_zero_origin
if initial_values:
self._build(initial_values)
def _build(self, initial_values: Sequence[int]):
for i, a in enumerate(initial_values):
self.add(i, a)
def add(self, index: int, value: int) -> None:
"""Add value to tree[index], O(logN)."""
if self.is_zero_origin:
index += 1
while index <= self._size:
self._tree[index] += value
index += index & -index
def sum(self, index: int) -> int:
"""Return the sum of [1, index] in O(logN)."""
ret = 0
while index > 0:
ret += self._tree[index]
index -= index & -index
return ret
def range_sum(self, left: int, right: int) -> int:
"""Return the range sum of [left, right] in O(logN)."""
if not self.is_zero_origin:
left -= 1
return self.sum(right) - self.sum(left)
def main():
N, K, *A = list(map(int, open(0).read().split()))
tree = BinaryIndexedTree(2000, is_zero_origin=False)
x = 0
for i, a in enumerate(A, 1): # internal inversion
tree.add(a, 1)
x += i - tree.sum(a)
y = -x
for i, a in enumerate(A, 1): # external inversion
tree.add(a, 1)
y += i + N - tree.sum(a)
MOD = 10 ** 9 + 7
print(((x * K + y * K * (K - 1) // 2) % MOD))
if __name__ == "__main__":
main()
| # jsc2019-qualB - Kleene Inversion
class BIT: # Binary Indexed Tree (Fenwick Tree)
def __init__(self, lim):
self.size = lim
self.tree = [0] * (lim + 1) # 1-idx
def add(self, i, x): # add x to tree[i], O(logN)
while i <= self.size:
self.tree[i] += x
i += i & -i
def sum(self, i): # sum of [1, i], O(logN)
ret = 0
while i > 0:
ret += self.tree[i]
i -= i & -i
return ret
def range_sum(self, l, r): # range sum of [l, r]
return self.sum(r) - self.sum(l - 1)
def main():
N, K = tuple(map(int, input().split()))
A = tuple(map(int, input().split()))
MOD = 10 ** 9 + 7
bit = BIT(2000)
x = 0
for i, a in enumerate(A, 1): # internal inversion
bit.add(a, 1)
x += i - bit.sum(a)
y = -x
for i, a in enumerate(A, 1): # external inversion
bit.add(a, 1)
y += i + N - bit.sum(a)
ans = (x * K + y * K * (K - 1) // 2) % MOD
print(ans)
if __name__ == "__main__":
main()
| 70 | 41 | 2,003 | 1,100 | # B - Kleene Inversion
from typing import Optional, Sequence
class BinaryIndexedTree:
"""Binary Indexed Tree (Fenwick Tree)
Each operation runs in O(logN).
References:
http://hos.ac/slides/20140319_bit.pdf
"""
__slots__ = ["_size", "_tree", "is_zero_origin"]
def __init__(
self,
size: int,
initial_values: Optional[Sequence[int]] = None,
is_zero_origin: bool = True,
):
self._size = size
self._tree = [0] * (size + 1)
self.is_zero_origin = is_zero_origin
if initial_values:
self._build(initial_values)
def _build(self, initial_values: Sequence[int]):
for i, a in enumerate(initial_values):
self.add(i, a)
def add(self, index: int, value: int) -> None:
"""Add value to tree[index], O(logN)."""
if self.is_zero_origin:
index += 1
while index <= self._size:
self._tree[index] += value
index += index & -index
def sum(self, index: int) -> int:
"""Return the sum of [1, index] in O(logN)."""
ret = 0
while index > 0:
ret += self._tree[index]
index -= index & -index
return ret
def range_sum(self, left: int, right: int) -> int:
"""Return the range sum of [left, right] in O(logN)."""
if not self.is_zero_origin:
left -= 1
return self.sum(right) - self.sum(left)
def main():
N, K, *A = list(map(int, open(0).read().split()))
tree = BinaryIndexedTree(2000, is_zero_origin=False)
x = 0
for i, a in enumerate(A, 1): # internal inversion
tree.add(a, 1)
x += i - tree.sum(a)
y = -x
for i, a in enumerate(A, 1): # external inversion
tree.add(a, 1)
y += i + N - tree.sum(a)
MOD = 10**9 + 7
print(((x * K + y * K * (K - 1) // 2) % MOD))
if __name__ == "__main__":
main()
| # jsc2019-qualB - Kleene Inversion
class BIT: # Binary Indexed Tree (Fenwick Tree)
def __init__(self, lim):
self.size = lim
self.tree = [0] * (lim + 1) # 1-idx
def add(self, i, x): # add x to tree[i], O(logN)
while i <= self.size:
self.tree[i] += x
i += i & -i
def sum(self, i): # sum of [1, i], O(logN)
ret = 0
while i > 0:
ret += self.tree[i]
i -= i & -i
return ret
def range_sum(self, l, r): # range sum of [l, r]
return self.sum(r) - self.sum(l - 1)
def main():
N, K = tuple(map(int, input().split()))
A = tuple(map(int, input().split()))
MOD = 10**9 + 7
bit = BIT(2000)
x = 0
for i, a in enumerate(A, 1): # internal inversion
bit.add(a, 1)
x += i - bit.sum(a)
y = -x
for i, a in enumerate(A, 1): # external inversion
bit.add(a, 1)
y += i + N - bit.sum(a)
ans = (x * K + y * K * (K - 1) // 2) % MOD
print(ans)
if __name__ == "__main__":
main()
| false | 41.428571 | [
"-# B - Kleene Inversion",
"-from typing import Optional, Sequence",
"+# jsc2019-qualB - Kleene Inversion",
"+class BIT: # Binary Indexed Tree (Fenwick Tree)",
"+ def __init__(self, lim):",
"+ self.size = lim",
"+ self.tree = [0] * (lim + 1) # 1-idx",
"+ def add(self, i, x): # add x to tree[i], O(logN)",
"+ while i <= self.size:",
"+ self.tree[i] += x",
"+ i += i & -i",
"-class BinaryIndexedTree:",
"- \"\"\"Binary Indexed Tree (Fenwick Tree)",
"- Each operation runs in O(logN).",
"- References:",
"- http://hos.ac/slides/20140319_bit.pdf",
"- \"\"\"",
"-",
"- __slots__ = [\"_size\", \"_tree\", \"is_zero_origin\"]",
"-",
"- def __init__(",
"- self,",
"- size: int,",
"- initial_values: Optional[Sequence[int]] = None,",
"- is_zero_origin: bool = True,",
"- ):",
"- self._size = size",
"- self._tree = [0] * (size + 1)",
"- self.is_zero_origin = is_zero_origin",
"- if initial_values:",
"- self._build(initial_values)",
"-",
"- def _build(self, initial_values: Sequence[int]):",
"- for i, a in enumerate(initial_values):",
"- self.add(i, a)",
"-",
"- def add(self, index: int, value: int) -> None:",
"- \"\"\"Add value to tree[index], O(logN).\"\"\"",
"- if self.is_zero_origin:",
"- index += 1",
"- while index <= self._size:",
"- self._tree[index] += value",
"- index += index & -index",
"-",
"- def sum(self, index: int) -> int:",
"- \"\"\"Return the sum of [1, index] in O(logN).\"\"\"",
"+ def sum(self, i): # sum of [1, i], O(logN)",
"- while index > 0:",
"- ret += self._tree[index]",
"- index -= index & -index",
"+ while i > 0:",
"+ ret += self.tree[i]",
"+ i -= i & -i",
"- def range_sum(self, left: int, right: int) -> int:",
"- \"\"\"Return the range sum of [left, right] in O(logN).\"\"\"",
"- if not self.is_zero_origin:",
"- left -= 1",
"- return self.sum(right) - self.sum(left)",
"+ def range_sum(self, l, r): # range sum of [l, r]",
"+ return self.sum(r) - self.sum(l - 1)",
"- N, K, *A = list(map(int, open(0).read().split()))",
"- tree = BinaryIndexedTree(2000, is_zero_origin=False)",
"+ N, K = tuple(map(int, input().split()))",
"+ A = tuple(map(int, input().split()))",
"+ MOD = 10**9 + 7",
"+ bit = BIT(2000)",
"- tree.add(a, 1)",
"- x += i - tree.sum(a)",
"+ bit.add(a, 1)",
"+ x += i - bit.sum(a)",
"- tree.add(a, 1)",
"- y += i + N - tree.sum(a)",
"- MOD = 10**9 + 7",
"- print(((x * K + y * K * (K - 1) // 2) % MOD))",
"+ bit.add(a, 1)",
"+ y += i + N - bit.sum(a)",
"+ ans = (x * K + y * K * (K - 1) // 2) % MOD",
"+ print(ans)"
] | false | 0.160741 | 0.086326 | 1.86201 | [
"s023903277",
"s533992587"
] |