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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u704658587 | p02659 | python | s271052096 | s530943766 | 29 | 21 | 9,872 | 9,164 | Accepted | Accepted | 27.59 | from decimal import *
a, b = input().split()
b = b.replace('.', '')
print((Decimal(a) * Decimal(b) // 100)) | a, b = input().split()
b = b.replace('.', '')
print((int(a) * int(b) // 100)) | 5 | 4 | 110 | 79 | from decimal import *
a, b = input().split()
b = b.replace(".", "")
print((Decimal(a) * Decimal(b) // 100))
| a, b = input().split()
b = b.replace(".", "")
print((int(a) * int(b) // 100))
| false | 20 | [
"-from decimal import *",
"-",
"-print((Decimal(a) * Decimal(b) // 100))",
"+print((int(a) * int(b) // 100))"
] | false | 0.041089 | 0.037477 | 1.096375 | [
"s271052096",
"s530943766"
] |
u581187895 | p03835 | python | s235775393 | s414175868 | 1,460 | 19 | 2,940 | 3,060 | Accepted | Accepted | 98.7 | K, S = list(map(int, input().split()))
ans = 0
for x in range(K+1):
for y in range(K+1):
z = S-x-y
if 0 <= z <= K:
ans += 1
print(ans) | """
Y+Z=S−X が成り立つことは分かるものの1通りには決まりません。
満たすべき条件は 0≤Y,Z≤K と Y+Z=S−X なので、変数 Z を消去すると以下の不等式が得られます。
0≤Y≤K
0≤Z=S−Y−X≤K
変形して、Y≤S−X かつ S−X−K≤Y
つまり Y の下限は Ymin=max(0,S−X−K) 、
上限は Ymax=min(K,S−X) となります。
"""
K, S = list(map(int, input().split()))
ans = 0
for x in range(K+1):
mn = max(0, S-x-K)
mx = min(K, S-x)
ans += max(0, mx-mn+1)
print(ans)
| 8 | 21 | 157 | 365 | K, S = list(map(int, input().split()))
ans = 0
for x in range(K + 1):
for y in range(K + 1):
z = S - x - y
if 0 <= z <= K:
ans += 1
print(ans)
| """
Y+Z=S−X が成り立つことは分かるものの1通りには決まりません。
満たすべき条件は 0≤Y,Z≤K と Y+Z=S−X なので、変数 Z を消去すると以下の不等式が得られます。
0≤Y≤K
0≤Z=S−Y−X≤K
変形して、Y≤S−X かつ S−X−K≤Y
つまり Y の下限は Ymin=max(0,S−X−K) 、
上限は Ymax=min(K,S−X) となります。
"""
K, S = list(map(int, input().split()))
ans = 0
for x in range(K + 1):
mn = max(0, S - x - K)
mx = min(K, S - x)
ans += max(0, mx - mn + 1)
print(ans)
| false | 61.904762 | [
"+\"\"\"",
"+Y+Z=S−X が成り立つことは分かるものの1通りには決まりません。",
"+満たすべき条件は 0≤Y,Z≤K と Y+Z=S−X なので、変数 Z を消去すると以下の不等式が得られます。",
"+0≤Y≤K",
"+0≤Z=S−Y−X≤K",
"+変形して、Y≤S−X かつ S−X−K≤Y",
"+つまり Y の下限は Ymin=max(0,S−X−K) 、",
"+上限は Ymax=min(K,S−X) となります。",
"+\"\"\"",
"- for y in range(K + 1):",
"- z = S - x - y",
"- if 0 <= z <= K:",
"- ans += 1",
"+ mn = max(0, S - x - K)",
"+ mx = min(K, S - x)",
"+ ans += max(0, mx - mn + 1)"
] | false | 0.067194 | 0.044092 | 1.523971 | [
"s235775393",
"s414175868"
] |
u014333473 | p03860 | python | s495126473 | s137913429 | 28 | 25 | 9,084 | 8,952 | Accepted | Accepted | 10.71 | print(*[i[0] for i in input().split()],sep='')
| print(f'A{input()[8]}C') | 1 | 1 | 46 | 24 | print(*[i[0] for i in input().split()], sep="")
| print(f"A{input()[8]}C")
| false | 0 | [
"-print(*[i[0] for i in input().split()], sep=\"\")",
"+print(f\"A{input()[8]}C\")"
] | false | 0.073127 | 0.060797 | 1.202812 | [
"s495126473",
"s137913429"
] |
u626467464 | p03493 | python | s914956207 | s657244789 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | line = eval(input())
count = 0
for i in range(3):
if line[i] == "1":
count += 1
print(count) | line = eval(input())
answer = line.count("1")
print(answer) | 6 | 3 | 97 | 55 | line = eval(input())
count = 0
for i in range(3):
if line[i] == "1":
count += 1
print(count)
| line = eval(input())
answer = line.count("1")
print(answer)
| false | 50 | [
"-count = 0",
"-for i in range(3):",
"- if line[i] == \"1\":",
"- count += 1",
"-print(count)",
"+answer = line.count(\"1\")",
"+print(answer)"
] | false | 0.042757 | 0.042212 | 1.012907 | [
"s914956207",
"s657244789"
] |
u707498674 | p03212 | python | s721075548 | s590384831 | 97 | 72 | 2,940 | 6,004 | Accepted | Accepted | 25.77 | N = int(eval(input()))
def dfs(s):
if int(s) > N:
return 0
ret = 1 if all(s.count(c) > 0 for c in "753") else 0
for c in "753":
ret += dfs(s + c)
return ret
print((dfs("0"))) | import bisect
N = int(eval(input()))
seven53 = []
def dfs(cur, s):
if all(s.count(c) > 0 for c in "753"):
seven53.append(s)
if cur > 8:
return
else:
for i in "753":
dfs(cur + 1, s+i)
dfs(0, "")
seven53 = list(map(int, seven53))
seven53.sort()
print((bisect.bisect_right(seven53, N))) | 9 | 15 | 182 | 337 | N = int(eval(input()))
def dfs(s):
if int(s) > N:
return 0
ret = 1 if all(s.count(c) > 0 for c in "753") else 0
for c in "753":
ret += dfs(s + c)
return ret
print((dfs("0")))
| import bisect
N = int(eval(input()))
seven53 = []
def dfs(cur, s):
if all(s.count(c) > 0 for c in "753"):
seven53.append(s)
if cur > 8:
return
else:
for i in "753":
dfs(cur + 1, s + i)
dfs(0, "")
seven53 = list(map(int, seven53))
seven53.sort()
print((bisect.bisect_right(seven53, N)))
| false | 40 | [
"+import bisect",
"+",
"+seven53 = []",
"-def dfs(s):",
"- if int(s) > N:",
"- return 0",
"- ret = 1 if all(s.count(c) > 0 for c in \"753\") else 0",
"- for c in \"753\":",
"- ret += dfs(s + c)",
"- return ret",
"+def dfs(cur, s):",
"+ if all(s.count(c) > 0 for c in \"753\"):",
"+ seven53.append(s)",
"+ if cur > 8:",
"+ return",
"+ else:",
"+ for i in \"753\":",
"+ dfs(cur + 1, s + i)",
"-print((dfs(\"0\")))",
"+dfs(0, \"\")",
"+seven53 = list(map(int, seven53))",
"+seven53.sort()",
"+print((bisect.bisect_right(seven53, N)))"
] | false | 0.045449 | 0.078906 | 0.575993 | [
"s721075548",
"s590384831"
] |
u111365362 | p03031 | python | s891697370 | s598708478 | 54 | 35 | 3,064 | 3,064 | Accepted | Accepted | 35.19 | n,m = list(map(int,input().split()))
ss = []
for mi in range(m):
splus = [0]*n
s = list(map(int,input().split()))[1:]
for ni in range(n):
if (ni+1) in s:
splus[ni] = 1
ss.append(splus)
p = list(map(int,input().split()))
score = 0
swi = [0]*n
while True:
judge = 1
for mi in range(m):
count = 0
for ni in range(n):
count += ss[mi][ni] * swi[ni]
judge *= bool(count%2==p[mi])
if judge == 1:
score += 1
swi[0] +=1
for ni in range(n-1):
if swi[ni] == 2:
swi[ni] = 0
swi[ni+1] += 1
if swi[-1] == 2:
break
print(score) | n,m = list(map(int,input().split()))
time = [0 for _ in range(n)]
def nex(time):
for i in range(n):
if time[i] == 0:
time[i] += 1
break
else:
time[i] = 0
else:
time = 'over'
return time
s = []
for _ in range(m):
raw = list(map(int,input().split()))
add = [0 for _ in range(n)]
for j in range(1,raw[0]+1):
add[raw[j]-1] = 1
s.append(add)
p = list(map(int,input().split()))
ans = 0
while time != 'over':
for k in range(m):
tmp = p[k]
for i in range(n):
tmp ^= time[i] * s[k][i]
if tmp == 1:
break
else:
ans += 1
time = nex(time)
print(ans) | 29 | 32 | 606 | 644 | n, m = list(map(int, input().split()))
ss = []
for mi in range(m):
splus = [0] * n
s = list(map(int, input().split()))[1:]
for ni in range(n):
if (ni + 1) in s:
splus[ni] = 1
ss.append(splus)
p = list(map(int, input().split()))
score = 0
swi = [0] * n
while True:
judge = 1
for mi in range(m):
count = 0
for ni in range(n):
count += ss[mi][ni] * swi[ni]
judge *= bool(count % 2 == p[mi])
if judge == 1:
score += 1
swi[0] += 1
for ni in range(n - 1):
if swi[ni] == 2:
swi[ni] = 0
swi[ni + 1] += 1
if swi[-1] == 2:
break
print(score)
| n, m = list(map(int, input().split()))
time = [0 for _ in range(n)]
def nex(time):
for i in range(n):
if time[i] == 0:
time[i] += 1
break
else:
time[i] = 0
else:
time = "over"
return time
s = []
for _ in range(m):
raw = list(map(int, input().split()))
add = [0 for _ in range(n)]
for j in range(1, raw[0] + 1):
add[raw[j] - 1] = 1
s.append(add)
p = list(map(int, input().split()))
ans = 0
while time != "over":
for k in range(m):
tmp = p[k]
for i in range(n):
tmp ^= time[i] * s[k][i]
if tmp == 1:
break
else:
ans += 1
time = nex(time)
print(ans)
| false | 9.375 | [
"-ss = []",
"-for mi in range(m):",
"- splus = [0] * n",
"- s = list(map(int, input().split()))[1:]",
"- for ni in range(n):",
"- if (ni + 1) in s:",
"- splus[ni] = 1",
"- ss.append(splus)",
"+time = [0 for _ in range(n)]",
"+",
"+",
"+def nex(time):",
"+ for i in range(n):",
"+ if time[i] == 0:",
"+ time[i] += 1",
"+ break",
"+ else:",
"+ time[i] = 0",
"+ else:",
"+ time = \"over\"",
"+ return time",
"+",
"+",
"+s = []",
"+for _ in range(m):",
"+ raw = list(map(int, input().split()))",
"+ add = [0 for _ in range(n)]",
"+ for j in range(1, raw[0] + 1):",
"+ add[raw[j] - 1] = 1",
"+ s.append(add)",
"-score = 0",
"-swi = [0] * n",
"-while True:",
"- judge = 1",
"- for mi in range(m):",
"- count = 0",
"- for ni in range(n):",
"- count += ss[mi][ni] * swi[ni]",
"- judge *= bool(count % 2 == p[mi])",
"- if judge == 1:",
"- score += 1",
"- swi[0] += 1",
"- for ni in range(n - 1):",
"- if swi[ni] == 2:",
"- swi[ni] = 0",
"- swi[ni + 1] += 1",
"- if swi[-1] == 2:",
"- break",
"-print(score)",
"+ans = 0",
"+while time != \"over\":",
"+ for k in range(m):",
"+ tmp = p[k]",
"+ for i in range(n):",
"+ tmp ^= time[i] * s[k][i]",
"+ if tmp == 1:",
"+ break",
"+ else:",
"+ ans += 1",
"+ time = nex(time)",
"+print(ans)"
] | false | 0.06679 | 0.061349 | 1.088695 | [
"s891697370",
"s598708478"
] |
u648212584 | p03221 | python | s130362748 | s850876456 | 990 | 619 | 46,972 | 37,864 | Accepted | Accepted | 37.47 | def main():
N,M = list(map(int,input().split()))
X = [list(map(int,input().split())) for _ in range(M)]
for i in range(M):
X[i].append(i)
X.sort(key=lambda X:(X[0],X[1]))
anslist = [[0,0] for _ in range(M)]
tmp = 0
count = 1
for i in range(M):
if tmp != X[i][0]:
tmp = X[i][0]
count = 1
anslist[i][0] = "0"*(6-len(str(X[i][0])))+str(X[i][0])+"0"*(6-len(str(count)))+str(count)
anslist[i][1] = X[i][2]
else:
count += 1
anslist[i][0] = "0"*(6-len(str(X[i][0])))+str(X[i][0])+"0"*(6-len(str(count)))+str(count)
anslist[i][1] = X[i][2]
anslist.sort(key=lambda X:X[1])
for i in range(M):
print((anslist[i][0]))
if __name__ == "__main__":
main() | from operator import itemgetter
import sys
input = sys.stdin.readline
def main():
N,M = list(map(int,input().split()))
f = []
for i in range(M):
P,Y = list(map(int,input().split()))
f.append([P,Y,i])
f.sort(key = itemgetter(0,1))
s = 1
count = 0
for i in range(M):
if s != f[i][0]:
s = f[i][0]
count = 1
f[i][1] = count
else:
count += 1
f[i][1] = count
ans = []
for i in range(M):
p,y,num = f[i]
lp,ly = len(str(p)),len(str(y))
ad = "0"*(6-lp) + str(p) + "0"*(6-ly) + str(y)
ans.append((num,ad))
ans.sort(key = itemgetter(0))
for i in range(M):print((ans[i][1]))
if __name__ == "__main__":
main()
| 27 | 35 | 832 | 826 | def main():
N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(M)]
for i in range(M):
X[i].append(i)
X.sort(key=lambda X: (X[0], X[1]))
anslist = [[0, 0] for _ in range(M)]
tmp = 0
count = 1
for i in range(M):
if tmp != X[i][0]:
tmp = X[i][0]
count = 1
anslist[i][0] = (
"0" * (6 - len(str(X[i][0])))
+ str(X[i][0])
+ "0" * (6 - len(str(count)))
+ str(count)
)
anslist[i][1] = X[i][2]
else:
count += 1
anslist[i][0] = (
"0" * (6 - len(str(X[i][0])))
+ str(X[i][0])
+ "0" * (6 - len(str(count)))
+ str(count)
)
anslist[i][1] = X[i][2]
anslist.sort(key=lambda X: X[1])
for i in range(M):
print((anslist[i][0]))
if __name__ == "__main__":
main()
| from operator import itemgetter
import sys
input = sys.stdin.readline
def main():
N, M = list(map(int, input().split()))
f = []
for i in range(M):
P, Y = list(map(int, input().split()))
f.append([P, Y, i])
f.sort(key=itemgetter(0, 1))
s = 1
count = 0
for i in range(M):
if s != f[i][0]:
s = f[i][0]
count = 1
f[i][1] = count
else:
count += 1
f[i][1] = count
ans = []
for i in range(M):
p, y, num = f[i]
lp, ly = len(str(p)), len(str(y))
ad = "0" * (6 - lp) + str(p) + "0" * (6 - ly) + str(y)
ans.append((num, ad))
ans.sort(key=itemgetter(0))
for i in range(M):
print((ans[i][1]))
if __name__ == "__main__":
main()
| false | 22.857143 | [
"+from operator import itemgetter",
"+import sys",
"+",
"+input = sys.stdin.readline",
"+",
"+",
"- X = [list(map(int, input().split())) for _ in range(M)]",
"+ f = []",
"- X[i].append(i)",
"- X.sort(key=lambda X: (X[0], X[1]))",
"- anslist = [[0, 0] for _ in range(M)]",
"- tmp = 0",
"- count = 1",
"+ P, Y = list(map(int, input().split()))",
"+ f.append([P, Y, i])",
"+ f.sort(key=itemgetter(0, 1))",
"+ s = 1",
"+ count = 0",
"- if tmp != X[i][0]:",
"- tmp = X[i][0]",
"+ if s != f[i][0]:",
"+ s = f[i][0]",
"- anslist[i][0] = (",
"- \"0\" * (6 - len(str(X[i][0])))",
"- + str(X[i][0])",
"- + \"0\" * (6 - len(str(count)))",
"- + str(count)",
"- )",
"- anslist[i][1] = X[i][2]",
"+ f[i][1] = count",
"- anslist[i][0] = (",
"- \"0\" * (6 - len(str(X[i][0])))",
"- + str(X[i][0])",
"- + \"0\" * (6 - len(str(count)))",
"- + str(count)",
"- )",
"- anslist[i][1] = X[i][2]",
"- anslist.sort(key=lambda X: X[1])",
"+ f[i][1] = count",
"+ ans = []",
"- print((anslist[i][0]))",
"+ p, y, num = f[i]",
"+ lp, ly = len(str(p)), len(str(y))",
"+ ad = \"0\" * (6 - lp) + str(p) + \"0\" * (6 - ly) + str(y)",
"+ ans.append((num, ad))",
"+ ans.sort(key=itemgetter(0))",
"+ for i in range(M):",
"+ print((ans[i][1]))"
] | false | 0.039877 | 0.046684 | 0.854205 | [
"s130362748",
"s850876456"
] |
u968166680 | p02863 | python | s233881624 | s050742864 | 655 | 274 | 215,852 | 144,960 | Accepted | Accepted | 58.17 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, T, *AB = list(map(int, read().split()))
A = AB[::2]
B = AB[1::2]
dp1 = [[0] * T for _ in range(N + 1)]
for i in range(N):
for t in range(T):
if 0 <= t - A[i]:
dp1[i + 1][t] = dp1[i][t - A[i]] + B[i]
if dp1[i + 1][t] < dp1[i][t]:
dp1[i + 1][t] = dp1[i][t]
dp2 = [[0] * T for _ in range(N + 1)]
for i in range(N - 1, -1, -1):
for t in range(T):
if 0 <= t - A[i]:
dp2[i][t] = dp2[i + 1][t - A[i]] + B[i]
if dp2[i][t] < dp2[i + 1][t]:
dp2[i][t] = dp2[i + 1][t]
ans = 0
for i in range(N):
tmp = max(dp1[i][t] + dp2[i + 1][T - t - 1] for t in range(T)) + B[i]
if ans < tmp:
ans = tmp
print(ans)
return
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, T, *AB = list(map(int, read().split()))
D = [(a, b) for a, b in zip(*[iter(AB)] * 2)]
D.sort()
A, B = list(zip(*D))
dp = [[0] * T for _ in range(N + 1)]
for i in range(N):
for t in range(T):
if 0 <= t - A[i]:
dp[i + 1][t] = dp[i][t - A[i]] + B[i]
if dp[i + 1][t] < dp[i][t]:
dp[i + 1][t] = dp[i][t]
ans = 0
for i in range(N):
tmp = dp[i+1][T - 1] + max(B[i + 1 :], default=0)
if ans < tmp:
ans = tmp
print(ans)
return
if __name__ == '__main__':
main()
| 43 | 37 | 1,051 | 793 | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, T, *AB = list(map(int, read().split()))
A = AB[::2]
B = AB[1::2]
dp1 = [[0] * T for _ in range(N + 1)]
for i in range(N):
for t in range(T):
if 0 <= t - A[i]:
dp1[i + 1][t] = dp1[i][t - A[i]] + B[i]
if dp1[i + 1][t] < dp1[i][t]:
dp1[i + 1][t] = dp1[i][t]
dp2 = [[0] * T for _ in range(N + 1)]
for i in range(N - 1, -1, -1):
for t in range(T):
if 0 <= t - A[i]:
dp2[i][t] = dp2[i + 1][t - A[i]] + B[i]
if dp2[i][t] < dp2[i + 1][t]:
dp2[i][t] = dp2[i + 1][t]
ans = 0
for i in range(N):
tmp = max(dp1[i][t] + dp2[i + 1][T - t - 1] for t in range(T)) + B[i]
if ans < tmp:
ans = tmp
print(ans)
return
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, T, *AB = list(map(int, read().split()))
D = [(a, b) for a, b in zip(*[iter(AB)] * 2)]
D.sort()
A, B = list(zip(*D))
dp = [[0] * T for _ in range(N + 1)]
for i in range(N):
for t in range(T):
if 0 <= t - A[i]:
dp[i + 1][t] = dp[i][t - A[i]] + B[i]
if dp[i + 1][t] < dp[i][t]:
dp[i + 1][t] = dp[i][t]
ans = 0
for i in range(N):
tmp = dp[i + 1][T - 1] + max(B[i + 1 :], default=0)
if ans < tmp:
ans = tmp
print(ans)
return
if __name__ == "__main__":
main()
| false | 13.953488 | [
"- A = AB[::2]",
"- B = AB[1::2]",
"- dp1 = [[0] * T for _ in range(N + 1)]",
"+ D = [(a, b) for a, b in zip(*[iter(AB)] * 2)]",
"+ D.sort()",
"+ A, B = list(zip(*D))",
"+ dp = [[0] * T for _ in range(N + 1)]",
"- dp1[i + 1][t] = dp1[i][t - A[i]] + B[i]",
"- if dp1[i + 1][t] < dp1[i][t]:",
"- dp1[i + 1][t] = dp1[i][t]",
"- dp2 = [[0] * T for _ in range(N + 1)]",
"- for i in range(N - 1, -1, -1):",
"- for t in range(T):",
"- if 0 <= t - A[i]:",
"- dp2[i][t] = dp2[i + 1][t - A[i]] + B[i]",
"- if dp2[i][t] < dp2[i + 1][t]:",
"- dp2[i][t] = dp2[i + 1][t]",
"+ dp[i + 1][t] = dp[i][t - A[i]] + B[i]",
"+ if dp[i + 1][t] < dp[i][t]:",
"+ dp[i + 1][t] = dp[i][t]",
"- tmp = max(dp1[i][t] + dp2[i + 1][T - t - 1] for t in range(T)) + B[i]",
"+ tmp = dp[i + 1][T - 1] + max(B[i + 1 :], default=0)"
] | false | 0.034778 | 0.057257 | 0.607403 | [
"s233881624",
"s050742864"
] |
u930705402 | p03286 | python | s568223147 | s927218240 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | N=int(eval(input()))
if(N==0):
print((0))
exit()
res=''
while(N!=0):
r=N%2
if(r<0):
r+=2
res+=str(r)
N=(N-r)//(-2)
print((res[::-1])) | N=int(eval(input()))
s=''
if(N==0):
print((0))
exit()
while(N!=0):
m=N%2
s+=str(m)
N=(N-m)//-2
print((s[::-1])) | 12 | 10 | 166 | 130 | N = int(eval(input()))
if N == 0:
print((0))
exit()
res = ""
while N != 0:
r = N % 2
if r < 0:
r += 2
res += str(r)
N = (N - r) // (-2)
print((res[::-1]))
| N = int(eval(input()))
s = ""
if N == 0:
print((0))
exit()
while N != 0:
m = N % 2
s += str(m)
N = (N - m) // -2
print((s[::-1]))
| false | 16.666667 | [
"+s = \"\"",
"-res = \"\"",
"- r = N % 2",
"- if r < 0:",
"- r += 2",
"- res += str(r)",
"- N = (N - r) // (-2)",
"-print((res[::-1]))",
"+ m = N % 2",
"+ s += str(m)",
"+ N = (N - m) // -2",
"+print((s[::-1]))"
] | false | 0.037571 | 0.038495 | 0.975989 | [
"s568223147",
"s927218240"
] |
u631277801 | p03285 | python | s396306238 | s061793524 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | N = int(eval(input()))
four = [4*i for i in range(26)]
seven = [7*i for i in range(15)]
exist = False
for f in four:
for s in seven:
sm = f+s
if sm == N:
exist = True
if exist:
print("Yes")
else:
print("No") | N = int(eval(input()))
four = [4*i for i in range(26)]
seven = [7*i for i in range(15)]
exist = False
for f in four:
for s in seven:
if f+s == N:
exist = True
if exist:
print("Yes")
else:
print("No")
| 16 | 15 | 271 | 262 | N = int(eval(input()))
four = [4 * i for i in range(26)]
seven = [7 * i for i in range(15)]
exist = False
for f in four:
for s in seven:
sm = f + s
if sm == N:
exist = True
if exist:
print("Yes")
else:
print("No")
| N = int(eval(input()))
four = [4 * i for i in range(26)]
seven = [7 * i for i in range(15)]
exist = False
for f in four:
for s in seven:
if f + s == N:
exist = True
if exist:
print("Yes")
else:
print("No")
| false | 6.25 | [
"- sm = f + s",
"- if sm == N:",
"+ if f + s == N:"
] | false | 0.108927 | 0.046266 | 2.354356 | [
"s396306238",
"s061793524"
] |
u191394596 | p03290 | python | s264803426 | s234364596 | 237 | 63 | 46,296 | 3,444 | Accepted | Accepted | 73.42 | import sys
INF = sys.maxsize
D, G = list(map(int, input().split()))
class P:
def __init__(self, index, number, bonus):
self.index = index
self.number = number
self.bonus = bonus
@property
def score(self):
return (self.index + 1) * 100
@property
def complete_score(self):
return self.score * self.number + self.bonus
# score 獲得するのに必要な解答数
def cost_of(self, score):
if score > self.complete_score:
return INF
if score == 0:
return 0
if score < self.score:
return 1
return min(score // self.score, self.number)
problems = []
for i in range(D):
p, c = list(map(int, input().split()))
problems.append(P(i, p, c))
min_number_of_solved = INF
for m in range(1 << D):
total = 0
number_of_solved = 0
uncompleted = set()
for i, p in enumerate(problems):
if 1 << i & m: # 完答
total += p.complete_score
number_of_solved += p.number
else:
uncompleted.add(p)
# 他の問題を解かなくても条件を満たしている
if total >= G:
min_number_of_solved = min(
min_number_of_solved,
number_of_solved
)
# 残りの必要点数を最小コストで獲得できる問題を中途半端に解く
else:
# 不足する点を最小コストで獲得できる問題を探す
m = min(uncompleted, key=lambda x: x.cost_of(G - total))
min_number_of_solved = min(
min_number_of_solved,
number_of_solved + m.cost_of(G - total)
)
print(min_number_of_solved)
| import sys
from collections import namedtuple
# 完答 + 最大1種類の問題が半端に解けている状態のとき最適
# 1. 完投する問題を全探索する 2^10
# 2. 残りの問題から配点が一番高い問題を目標に達するまで解く
# 3. 1,2の中で最も回答問題数が少ないケースが答え
Problem = namedtuple('Problem', 'score number bonus')
D, G = list(map(int, input().split()))
problems = []
for i in range(D):
p, c = list(map(int, input().split()))
problems.append(
Problem(
score = (i + 1) * 100,
number = p,
bonus = c
)
)
min_num_solved = sys.maxsize
for m in range(1 << D):
score = 0
num_solved = 0
partial = None # 部分的に解く問題
for i, p in enumerate(problems):
if 1 << i & m:
# 完答
score += p.score * p.number + p.bonus
num_solved += p.number
else:
partial = p
# 中途半端に解かなくてもいいのなら次へ
if score >= G:
min_num_solved = min(min_num_solved, num_solved)
continue
if partial is None:
raise Exception('全問題完答したのに目標に届かない')
# 中途半端に解く
extra_num_solved = 0
while extra_num_solved <= partial.number:
if score >= G:
min_num_solved = min(
min_num_solved,
num_solved + extra_num_solved
)
break
score += partial.score
extra_num_solved += 1
print(min_num_solved) | 66 | 61 | 1,465 | 1,277 | import sys
INF = sys.maxsize
D, G = list(map(int, input().split()))
class P:
def __init__(self, index, number, bonus):
self.index = index
self.number = number
self.bonus = bonus
@property
def score(self):
return (self.index + 1) * 100
@property
def complete_score(self):
return self.score * self.number + self.bonus
# score 獲得するのに必要な解答数
def cost_of(self, score):
if score > self.complete_score:
return INF
if score == 0:
return 0
if score < self.score:
return 1
return min(score // self.score, self.number)
problems = []
for i in range(D):
p, c = list(map(int, input().split()))
problems.append(P(i, p, c))
min_number_of_solved = INF
for m in range(1 << D):
total = 0
number_of_solved = 0
uncompleted = set()
for i, p in enumerate(problems):
if 1 << i & m: # 完答
total += p.complete_score
number_of_solved += p.number
else:
uncompleted.add(p)
# 他の問題を解かなくても条件を満たしている
if total >= G:
min_number_of_solved = min(min_number_of_solved, number_of_solved)
# 残りの必要点数を最小コストで獲得できる問題を中途半端に解く
else:
# 不足する点を最小コストで獲得できる問題を探す
m = min(uncompleted, key=lambda x: x.cost_of(G - total))
min_number_of_solved = min(
min_number_of_solved, number_of_solved + m.cost_of(G - total)
)
print(min_number_of_solved)
| import sys
from collections import namedtuple
# 完答 + 最大1種類の問題が半端に解けている状態のとき最適
# 1. 完投する問題を全探索する 2^10
# 2. 残りの問題から配点が一番高い問題を目標に達するまで解く
# 3. 1,2の中で最も回答問題数が少ないケースが答え
Problem = namedtuple("Problem", "score number bonus")
D, G = list(map(int, input().split()))
problems = []
for i in range(D):
p, c = list(map(int, input().split()))
problems.append(Problem(score=(i + 1) * 100, number=p, bonus=c))
min_num_solved = sys.maxsize
for m in range(1 << D):
score = 0
num_solved = 0
partial = None # 部分的に解く問題
for i, p in enumerate(problems):
if 1 << i & m:
# 完答
score += p.score * p.number + p.bonus
num_solved += p.number
else:
partial = p
# 中途半端に解かなくてもいいのなら次へ
if score >= G:
min_num_solved = min(min_num_solved, num_solved)
continue
if partial is None:
raise Exception("全問題完答したのに目標に届かない")
# 中途半端に解く
extra_num_solved = 0
while extra_num_solved <= partial.number:
if score >= G:
min_num_solved = min(min_num_solved, num_solved + extra_num_solved)
break
score += partial.score
extra_num_solved += 1
print(min_num_solved)
| false | 7.575758 | [
"+from collections import namedtuple",
"-INF = sys.maxsize",
"+# 完答 + 最大1種類の問題が半端に解けている状態のとき最適",
"+# 1. 完投する問題を全探索する 2^10",
"+# 2. 残りの問題から配点が一番高い問題を目標に達するまで解く",
"+# 3. 1,2の中で最も回答問題数が少ないケースが答え",
"+Problem = namedtuple(\"Problem\", \"score number bonus\")",
"-",
"-",
"-class P:",
"- def __init__(self, index, number, bonus):",
"- self.index = index",
"- self.number = number",
"- self.bonus = bonus",
"-",
"- @property",
"- def score(self):",
"- return (self.index + 1) * 100",
"-",
"- @property",
"- def complete_score(self):",
"- return self.score * self.number + self.bonus",
"-",
"- # score 獲得するのに必要な解答数",
"- def cost_of(self, score):",
"- if score > self.complete_score:",
"- return INF",
"- if score == 0:",
"- return 0",
"- if score < self.score:",
"- return 1",
"- return min(score // self.score, self.number)",
"-",
"-",
"- problems.append(P(i, p, c))",
"-min_number_of_solved = INF",
"+ problems.append(Problem(score=(i + 1) * 100, number=p, bonus=c))",
"+min_num_solved = sys.maxsize",
"- total = 0",
"- number_of_solved = 0",
"- uncompleted = set()",
"+ score = 0",
"+ num_solved = 0",
"+ partial = None # 部分的に解く問題",
"- if 1 << i & m: # 完答",
"- total += p.complete_score",
"- number_of_solved += p.number",
"+ if 1 << i & m:",
"+ # 完答",
"+ score += p.score * p.number + p.bonus",
"+ num_solved += p.number",
"- uncompleted.add(p)",
"- # 他の問題を解かなくても条件を満たしている",
"- if total >= G:",
"- min_number_of_solved = min(min_number_of_solved, number_of_solved)",
"- # 残りの必要点数を最小コストで獲得できる問題を中途半端に解く",
"- else:",
"- # 不足する点を最小コストで獲得できる問題を探す",
"- m = min(uncompleted, key=lambda x: x.cost_of(G - total))",
"- min_number_of_solved = min(",
"- min_number_of_solved, number_of_solved + m.cost_of(G - total)",
"- )",
"-print(min_number_of_solved)",
"+ partial = p",
"+ # 中途半端に解かなくてもいいのなら次へ",
"+ if score >= G:",
"+ min_num_solved = min(min_num_solved, num_solved)",
"+ continue",
"+ if partial is None:",
"+ raise Exception(\"全問題完答したのに目標に届かない\")",
"+ # 中途半端に解く",
"+ extra_num_solved = 0",
"+ while extra_num_solved <= partial.number:",
"+ if score >= G:",
"+ min_num_solved = min(min_num_solved, num_solved + extra_num_solved)",
"+ break",
"+ score += partial.score",
"+ extra_num_solved += 1",
"+print(min_num_solved)"
] | false | 0.096412 | 0.061901 | 1.557524 | [
"s264803426",
"s234364596"
] |
u525227429 | p02918 | python | s613038110 | s812369291 | 171 | 45 | 20,364 | 3,316 | Accepted | Accepted | 73.68 | N, K = list(map(int, input().split()))
S = list(eval(input()))
l = []
tmp = 0
for i in range(1, N):
if S[i - 1] != S[i]:
l.append([tmp, i - 1, i - tmp])
tmp = i
if i == N - 1:
l.append([tmp, i, i - tmp + 1])
for k in range(K):
i = 2 * k + 1
if i >= len(l):
break
if S[l[i][0]] == "L":
S[l[i][0] : l[i][1] + 1] = "R" * l[i][2]
else:
S[l[i][0] : l[i][1] + 1] = "L" * l[i][2]
ans = 0
for i in range(N - 1):
if S[i] == S[i + 1]:
ans += 1
print(ans) | N, K = list(map(int, input().split()))
S = eval(input())
ans = K * 2
for i in range(N - 1):
if S[i] == S[i + 1]:
ans += 1
ans = min(ans, N - 1)
print(ans) | 27 | 9 | 504 | 157 | N, K = list(map(int, input().split()))
S = list(eval(input()))
l = []
tmp = 0
for i in range(1, N):
if S[i - 1] != S[i]:
l.append([tmp, i - 1, i - tmp])
tmp = i
if i == N - 1:
l.append([tmp, i, i - tmp + 1])
for k in range(K):
i = 2 * k + 1
if i >= len(l):
break
if S[l[i][0]] == "L":
S[l[i][0] : l[i][1] + 1] = "R" * l[i][2]
else:
S[l[i][0] : l[i][1] + 1] = "L" * l[i][2]
ans = 0
for i in range(N - 1):
if S[i] == S[i + 1]:
ans += 1
print(ans)
| N, K = list(map(int, input().split()))
S = eval(input())
ans = K * 2
for i in range(N - 1):
if S[i] == S[i + 1]:
ans += 1
ans = min(ans, N - 1)
print(ans)
| false | 66.666667 | [
"-S = list(eval(input()))",
"-l = []",
"-tmp = 0",
"-for i in range(1, N):",
"- if S[i - 1] != S[i]:",
"- l.append([tmp, i - 1, i - tmp])",
"- tmp = i",
"- if i == N - 1:",
"- l.append([tmp, i, i - tmp + 1])",
"-for k in range(K):",
"- i = 2 * k + 1",
"- if i >= len(l):",
"- break",
"- if S[l[i][0]] == \"L\":",
"- S[l[i][0] : l[i][1] + 1] = \"R\" * l[i][2]",
"- else:",
"- S[l[i][0] : l[i][1] + 1] = \"L\" * l[i][2]",
"-ans = 0",
"+S = eval(input())",
"+ans = K * 2",
"+ans = min(ans, N - 1)"
] | false | 0.100957 | 0.040509 | 2.492243 | [
"s613038110",
"s812369291"
] |
u597374218 | p03821 | python | s270570692 | s880024712 | 276 | 253 | 32,160 | 28,108 | Accepted | Accepted | 8.33 | N=int(eval(input()))
AB=[list(map(int,input().split())) for i in range(N)][::-1]
count=0
for i in range(N):
AB[i][0]+=count
if AB[i][0]%AB[i][1]!=0:
count+=AB[i][1]-(AB[i][0]%AB[i][1])
print(count) | N=int(eval(input()))
AB=[list(map(int,input().split())) for i in range(N)]
count=0
for a,b in AB[::-1]:
a+=count
if a%b!=0:
count+=b-(a%b)
print(count) | 8 | 8 | 214 | 168 | N = int(eval(input()))
AB = [list(map(int, input().split())) for i in range(N)][::-1]
count = 0
for i in range(N):
AB[i][0] += count
if AB[i][0] % AB[i][1] != 0:
count += AB[i][1] - (AB[i][0] % AB[i][1])
print(count)
| N = int(eval(input()))
AB = [list(map(int, input().split())) for i in range(N)]
count = 0
for a, b in AB[::-1]:
a += count
if a % b != 0:
count += b - (a % b)
print(count)
| false | 0 | [
"-AB = [list(map(int, input().split())) for i in range(N)][::-1]",
"+AB = [list(map(int, input().split())) for i in range(N)]",
"-for i in range(N):",
"- AB[i][0] += count",
"- if AB[i][0] % AB[i][1] != 0:",
"- count += AB[i][1] - (AB[i][0] % AB[i][1])",
"+for a, b in AB[::-1]:",
"+ a += count",
"+ if a % b != 0:",
"+ count += b - (a % b)"
] | false | 0.04298 | 0.039892 | 1.077412 | [
"s270570692",
"s880024712"
] |
u249218427 | p02714 | python | s590638447 | s745351142 | 1,501 | 1,321 | 9,216 | 9,108 | Accepted | Accepted | 11.99 | # -*- coding: utf-8 -*-
N = int(eval(input()))
S = eval(input())
R = 0
G = 0
B = 0
for i in range(N):
if S[i] == 'R':
R += 1
elif S[i] == 'G':
G += 1
else:
B += 1
count = 0
for i in range(N-1):
for j in range(i+1,N):
if 2*j-i>=N:
break
if S[i]!=S[j] and S[2*j-i]!=S[i] and S[2*j-i]!=S[j]:
count += 1
print((R*G*B-count)) | # -*- coding: utf-8 -*-
N = int(eval(input()))
S = eval(input())
R = 0
G = 0
B = 0
for i in range(N):
if S[i] == 'R':
R += 1
elif S[i] == 'G':
G += 1
else:
B += 1
count = 0
for i in range(N-2):
for j in range(i+1,N-1):
k = 2*j-i
if k>=N:
break
if S[i]!=S[j] and S[k]!=S[i] and S[k]!=S[j]:
count += 1
print((R*G*B-count)) | 25 | 26 | 378 | 379 | # -*- coding: utf-8 -*-
N = int(eval(input()))
S = eval(input())
R = 0
G = 0
B = 0
for i in range(N):
if S[i] == "R":
R += 1
elif S[i] == "G":
G += 1
else:
B += 1
count = 0
for i in range(N - 1):
for j in range(i + 1, N):
if 2 * j - i >= N:
break
if S[i] != S[j] and S[2 * j - i] != S[i] and S[2 * j - i] != S[j]:
count += 1
print((R * G * B - count))
| # -*- coding: utf-8 -*-
N = int(eval(input()))
S = eval(input())
R = 0
G = 0
B = 0
for i in range(N):
if S[i] == "R":
R += 1
elif S[i] == "G":
G += 1
else:
B += 1
count = 0
for i in range(N - 2):
for j in range(i + 1, N - 1):
k = 2 * j - i
if k >= N:
break
if S[i] != S[j] and S[k] != S[i] and S[k] != S[j]:
count += 1
print((R * G * B - count))
| false | 3.846154 | [
"-for i in range(N - 1):",
"- for j in range(i + 1, N):",
"- if 2 * j - i >= N:",
"+for i in range(N - 2):",
"+ for j in range(i + 1, N - 1):",
"+ k = 2 * j - i",
"+ if k >= N:",
"- if S[i] != S[j] and S[2 * j - i] != S[i] and S[2 * j - i] != S[j]:",
"+ if S[i] != S[j] and S[k] != S[i] and S[k] != S[j]:"
] | false | 0.105741 | 0.048953 | 2.16004 | [
"s590638447",
"s745351142"
] |
u075012704 | p02925 | python | s498788676 | s721888188 | 581 | 518 | 55,388 | 55,388 | Accepted | Accepted | 10.84 | N = int(eval(input()))
A = [list([int(x) - 1 for x in input().split()]) + [-1] for i in range(N)]
ans = 0
matched = 0
marker = [0] * N
que = list(range(N))
while matched < N * (N - 1) // 2:
already_matched = set()
no_matched = True
next_que = []
while que:
player = que.pop()
partner = A[player][marker[player]]
if A[partner][marker[partner]] == player:
if not ((player not in already_matched) and (partner not in already_matched)):
continue
matched += 1
marker[player] += 1
marker[partner] += 1
already_matched.add(player)
already_matched.add(partner)
next_que.append(player)
next_que.append(partner)
no_matched = False
ans += 1
que = next_que[:]
if no_matched:
print((-1))
break
else:
print(ans)
| N = int(eval(input()))
A = [list([int(x) - 1 for x in input().split()]) + [-1] for i in range(N)]
ans = 0
matched = 0
marker = [0] * N
que = list(range(N))
while matched < N * (N - 1) // 2:
already_matched = set()
next_que = []
while que:
player = que.pop()
partner = A[player][marker[player]]
if A[partner][marker[partner]] == player:
if not ((player not in already_matched) and (partner not in already_matched)):
continue
matched += 1
marker[player] += 1
marker[partner] += 1
already_matched.add(player)
already_matched.add(partner)
next_que.append(player)
next_que.append(partner)
if not next_que:
print((-1))
break
ans += 1
que = next_que[:]
else:
print(ans)
| 42 | 40 | 943 | 890 | N = int(eval(input()))
A = [list([int(x) - 1 for x in input().split()]) + [-1] for i in range(N)]
ans = 0
matched = 0
marker = [0] * N
que = list(range(N))
while matched < N * (N - 1) // 2:
already_matched = set()
no_matched = True
next_que = []
while que:
player = que.pop()
partner = A[player][marker[player]]
if A[partner][marker[partner]] == player:
if not (
(player not in already_matched) and (partner not in already_matched)
):
continue
matched += 1
marker[player] += 1
marker[partner] += 1
already_matched.add(player)
already_matched.add(partner)
next_que.append(player)
next_que.append(partner)
no_matched = False
ans += 1
que = next_que[:]
if no_matched:
print((-1))
break
else:
print(ans)
| N = int(eval(input()))
A = [list([int(x) - 1 for x in input().split()]) + [-1] for i in range(N)]
ans = 0
matched = 0
marker = [0] * N
que = list(range(N))
while matched < N * (N - 1) // 2:
already_matched = set()
next_que = []
while que:
player = que.pop()
partner = A[player][marker[player]]
if A[partner][marker[partner]] == player:
if not (
(player not in already_matched) and (partner not in already_matched)
):
continue
matched += 1
marker[player] += 1
marker[partner] += 1
already_matched.add(player)
already_matched.add(partner)
next_que.append(player)
next_que.append(partner)
if not next_que:
print((-1))
break
ans += 1
que = next_que[:]
else:
print(ans)
| false | 4.761905 | [
"- no_matched = True",
"- no_matched = False",
"+ if not next_que:",
"+ print((-1))",
"+ break",
"- if no_matched:",
"- print((-1))",
"- break"
] | false | 0.038373 | 0.040998 | 0.935979 | [
"s498788676",
"s721888188"
] |
u089830331 | p02258 | python | s598775910 | s682039050 | 500 | 240 | 7,644 | 21,884 | Accepted | Accepted | 52 | n = int(eval(input()))
max_diff = - 10 ** 9
min_n = int(eval(input()))
for i in range(1, n):
n = int(eval(input()))
max_diff = max(max_diff, n - min_n)
min_n = min(min_n, n)
print(max_diff) | import sys
n = int(eval(input()))
max_diff = - 10 ** 9
min_n = int(eval(input()))
for n in map(int, sys.stdin.readlines()):
max_diff = max(max_diff, n - min_n)
min_n = min(min_n, n)
print(max_diff) | 11 | 12 | 190 | 204 | n = int(eval(input()))
max_diff = -(10**9)
min_n = int(eval(input()))
for i in range(1, n):
n = int(eval(input()))
max_diff = max(max_diff, n - min_n)
min_n = min(min_n, n)
print(max_diff)
| import sys
n = int(eval(input()))
max_diff = -(10**9)
min_n = int(eval(input()))
for n in map(int, sys.stdin.readlines()):
max_diff = max(max_diff, n - min_n)
min_n = min(min_n, n)
print(max_diff)
| false | 8.333333 | [
"+import sys",
"+",
"-for i in range(1, n):",
"- n = int(eval(input()))",
"+for n in map(int, sys.stdin.readlines()):"
] | false | 0.040821 | 0.049091 | 0.831543 | [
"s598775910",
"s682039050"
] |
u660912567 | p00767 | python | s547297270 | s770550345 | 80 | 60 | 9,060 | 8,964 | Accepted | Accepted | 25 | l = [[i**2+j**2,i,j] for j in range(1,151) for i in range(1,151) if i!=j and i<j]
l = sorted(l)
while True:
h,w = map(int,input().split())
if w==h==0: break
i = l.index([w**2+h**2,h,w])+1
print(*l[i][1:],sep=' ')
| import bisect
l = [[i**2+j**2,i,j] for j in range(1,151) for i in range(1,151) if i!=j and i<j]
l.sort()
while True:
h,w = list(map(int,input().split()))
if w==h==0: break
r = l[bisect.bisect_right(l,[w**2+h**2,h,w])]
print((r[1],r[2])) | 7 | 8 | 234 | 251 | l = [
[i**2 + j**2, i, j]
for j in range(1, 151)
for i in range(1, 151)
if i != j and i < j
]
l = sorted(l)
while True:
h, w = map(int, input().split())
if w == h == 0:
break
i = l.index([w**2 + h**2, h, w]) + 1
print(*l[i][1:], sep=" ")
| import bisect
l = [
[i**2 + j**2, i, j]
for j in range(1, 151)
for i in range(1, 151)
if i != j and i < j
]
l.sort()
while True:
h, w = list(map(int, input().split()))
if w == h == 0:
break
r = l[bisect.bisect_right(l, [w**2 + h**2, h, w])]
print((r[1], r[2]))
| false | 12.5 | [
"+import bisect",
"+",
"-l = sorted(l)",
"+l.sort()",
"- h, w = map(int, input().split())",
"+ h, w = list(map(int, input().split()))",
"- i = l.index([w**2 + h**2, h, w]) + 1",
"- print(*l[i][1:], sep=\" \")",
"+ r = l[bisect.bisect_right(l, [w**2 + h**2, h, w])]",
"+ print((r[1], r[2]))"
] | false | 0.079849 | 0.067458 | 1.183686 | [
"s547297270",
"s770550345"
] |
u072717685 | p02608 | python | s577573444 | s133956629 | 990 | 805 | 11,684 | 11,796 | Accepted | Accepted | 18.69 | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
n = int(eval(input()))
if n == 1:
print((0))
sys.exit()
r = defaultdict(int)
for i1 in range(1,101):
for i2 in range(1,101):
for i3 in range(1,101):
t = pow(i1, 2) + pow(i2, 2) + pow(i3, 2) + i1*i2 + i2*i3 + i1*i3
t = int(t)
r[t] += 1
for i1 in range(1, n+1):
print((int(r[i1])))
if __name__ == '__main__':
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from math import sqrt
from collections import defaultdict
def main():
n = int(eval(input()))
n2 = int(sqrt(n) + 1)
d1 = defaultdict(int)
for i1 in range(1, n2):
for i2 in range(1, n2):
for i3 in range(1, n2):
#p = (i1 + i2) ** 2 - (i1 * i2) + i3 * (i1 + i2 + i3)
p = i1 ** 2 + i2 ** 2 + i3 ** 2 + i1 * i2 + i2 * i3 + i1 * i3
d1[p] += 1
for j1 in range(1, n + 1):
print((d1[j1]))
if __name__ == '__main__':
main()
| 21 | 23 | 554 | 625 | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
n = int(eval(input()))
if n == 1:
print((0))
sys.exit()
r = defaultdict(int)
for i1 in range(1, 101):
for i2 in range(1, 101):
for i3 in range(1, 101):
t = pow(i1, 2) + pow(i2, 2) + pow(i3, 2) + i1 * i2 + i2 * i3 + i1 * i3
t = int(t)
r[t] += 1
for i1 in range(1, n + 1):
print((int(r[i1])))
if __name__ == "__main__":
main()
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from math import sqrt
from collections import defaultdict
def main():
n = int(eval(input()))
n2 = int(sqrt(n) + 1)
d1 = defaultdict(int)
for i1 in range(1, n2):
for i2 in range(1, n2):
for i3 in range(1, n2):
# p = (i1 + i2) ** 2 - (i1 * i2) + i3 * (i1 + i2 + i3)
p = i1**2 + i2**2 + i3**2 + i1 * i2 + i2 * i3 + i1 * i3
d1[p] += 1
for j1 in range(1, n + 1):
print((d1[j1]))
if __name__ == "__main__":
main()
| false | 8.695652 | [
"+readline = sys.stdin.readline",
"+from math import sqrt",
"- if n == 1:",
"- print((0))",
"- sys.exit()",
"- r = defaultdict(int)",
"- for i1 in range(1, 101):",
"- for i2 in range(1, 101):",
"- for i3 in range(1, 101):",
"- t = pow(i1, 2) + pow(i2, 2) + pow(i3, 2) + i1 * i2 + i2 * i3 + i1 * i3",
"- t = int(t)",
"- r[t] += 1",
"- for i1 in range(1, n + 1):",
"- print((int(r[i1])))",
"+ n2 = int(sqrt(n) + 1)",
"+ d1 = defaultdict(int)",
"+ for i1 in range(1, n2):",
"+ for i2 in range(1, n2):",
"+ for i3 in range(1, n2):",
"+ # p = (i1 + i2) ** 2 - (i1 * i2) + i3 * (i1 + i2 + i3)",
"+ p = i1**2 + i2**2 + i3**2 + i1 * i2 + i2 * i3 + i1 * i3",
"+ d1[p] += 1",
"+ for j1 in range(1, n + 1):",
"+ print((d1[j1]))"
] | false | 2.533074 | 0.048803 | 51.904332 | [
"s577573444",
"s133956629"
] |
u562935282 | p03240 | python | s756112612 | s445844673 | 120 | 61 | 3,064 | 3,700 | Accepted | Accepted | 49.17 | N = int(eval(input()))
xyh = [tuple(map(int, input().split())) for _ in range(N)]
for cx in range(100 + 1):
for cy in range(100 + 1):
# すべての中心候補に対して
H = -1
for x, y, h in xyh:
if h > 0:
t = h + abs(x - cx) + abs(y - cy)
if H == -1:
H = t
else:
if H != t:
# 適切な中心を選んでいるときは、すべてのHが一致する
break
else:
for x, y, h in xyh:
if h != max(H - abs(x - cx) - abs(y - cy), 0):
break
else:
if H >= 1:
print((cx, cy, H))
exit()
| def solve():
cands = []
for cx in range(100 + 1):
for cy in range(100 + 1):
is_center = True
temp_h = -1
for x, y, h in m:
if h != 0:
calc_h = h + abs(cx - x) + abs(cy - y)
if temp_h == -1:
temp_h = calc_h
else:
if temp_h != calc_h:
is_center = False
break
if is_center:
cands.append((cx, cy, temp_h))
for cx, cy, temp_h in cands:
is_answer = True
for x, y, h in m:
if h == 0:
if temp_h - abs(cx - x) - abs(cy - y) > 0:
# h=0の位置では、計算された高さは0以下の必要がある
is_answer = False
break
if is_answer:
return cx, cy, temp_h
return -1, -1, -1
n = int(eval(input()))
m = tuple(tuple(map(int, input().split())) for _ in range(n))
print((*solve()))
| 24 | 35 | 727 | 1,052 | N = int(eval(input()))
xyh = [tuple(map(int, input().split())) for _ in range(N)]
for cx in range(100 + 1):
for cy in range(100 + 1):
# すべての中心候補に対して
H = -1
for x, y, h in xyh:
if h > 0:
t = h + abs(x - cx) + abs(y - cy)
if H == -1:
H = t
else:
if H != t:
# 適切な中心を選んでいるときは、すべてのHが一致する
break
else:
for x, y, h in xyh:
if h != max(H - abs(x - cx) - abs(y - cy), 0):
break
else:
if H >= 1:
print((cx, cy, H))
exit()
| def solve():
cands = []
for cx in range(100 + 1):
for cy in range(100 + 1):
is_center = True
temp_h = -1
for x, y, h in m:
if h != 0:
calc_h = h + abs(cx - x) + abs(cy - y)
if temp_h == -1:
temp_h = calc_h
else:
if temp_h != calc_h:
is_center = False
break
if is_center:
cands.append((cx, cy, temp_h))
for cx, cy, temp_h in cands:
is_answer = True
for x, y, h in m:
if h == 0:
if temp_h - abs(cx - x) - abs(cy - y) > 0:
# h=0の位置では、計算された高さは0以下の必要がある
is_answer = False
break
if is_answer:
return cx, cy, temp_h
return -1, -1, -1
n = int(eval(input()))
m = tuple(tuple(map(int, input().split())) for _ in range(n))
print((*solve()))
| false | 31.428571 | [
"-N = int(eval(input()))",
"-xyh = [tuple(map(int, input().split())) for _ in range(N)]",
"-for cx in range(100 + 1):",
"- for cy in range(100 + 1):",
"- # すべての中心候補に対して",
"- H = -1",
"- for x, y, h in xyh:",
"- if h > 0:",
"- t = h + abs(x - cx) + abs(y - cy)",
"- if H == -1:",
"- H = t",
"- else:",
"- if H != t:",
"- # 適切な中心を選んでいるときは、すべてのHが一致する",
"- break",
"- else:",
"- for x, y, h in xyh:",
"- if h != max(H - abs(x - cx) - abs(y - cy), 0):",
"+def solve():",
"+ cands = []",
"+ for cx in range(100 + 1):",
"+ for cy in range(100 + 1):",
"+ is_center = True",
"+ temp_h = -1",
"+ for x, y, h in m:",
"+ if h != 0:",
"+ calc_h = h + abs(cx - x) + abs(cy - y)",
"+ if temp_h == -1:",
"+ temp_h = calc_h",
"+ else:",
"+ if temp_h != calc_h:",
"+ is_center = False",
"+ break",
"+ if is_center:",
"+ cands.append((cx, cy, temp_h))",
"+ for cx, cy, temp_h in cands:",
"+ is_answer = True",
"+ for x, y, h in m:",
"+ if h == 0:",
"+ if temp_h - abs(cx - x) - abs(cy - y) > 0:",
"+ # h=0の位置では、計算された高さは0以下の必要がある",
"+ is_answer = False",
"- else:",
"- if H >= 1:",
"- print((cx, cy, H))",
"- exit()",
"+ if is_answer:",
"+ return cx, cy, temp_h",
"+ return -1, -1, -1",
"+",
"+",
"+n = int(eval(input()))",
"+m = tuple(tuple(map(int, input().split())) for _ in range(n))",
"+print((*solve()))"
] | false | 0.037464 | 0.043871 | 0.853948 | [
"s756112612",
"s445844673"
] |
u058781705 | p03289 | python | s446025974 | s157667986 | 171 | 64 | 38,384 | 61,812 | Accepted | Accepted | 62.57 |
def solve():
s = list(eval(input()))
if s[0] == "A" and s[2:-1].count("C") == 1:
s.remove("A")
s.remove("C")
if "".join(s).islower():
print("AC")
exit()
print("WA")
if __name__ == "__main__":
solve()
| S = eval(input())
if S[0] == "A":
if S.count("C") == 1:
if S[2:-1].count("C") == 1:
S = S.replace("A", "")
S = S.replace("C", "")
if S.islower():
print("AC")
exit()
print("WA")
| 17 | 12 | 280 | 264 | def solve():
s = list(eval(input()))
if s[0] == "A" and s[2:-1].count("C") == 1:
s.remove("A")
s.remove("C")
if "".join(s).islower():
print("AC")
exit()
print("WA")
if __name__ == "__main__":
solve()
| S = eval(input())
if S[0] == "A":
if S.count("C") == 1:
if S[2:-1].count("C") == 1:
S = S.replace("A", "")
S = S.replace("C", "")
if S.islower():
print("AC")
exit()
print("WA")
| false | 29.411765 | [
"-def solve():",
"- s = list(eval(input()))",
"- if s[0] == \"A\" and s[2:-1].count(\"C\") == 1:",
"- s.remove(\"A\")",
"- s.remove(\"C\")",
"- if \"\".join(s).islower():",
"- print(\"AC\")",
"- exit()",
"- print(\"WA\")",
"-",
"-",
"-if __name__ == \"__main__\":",
"- solve()",
"+S = eval(input())",
"+if S[0] == \"A\":",
"+ if S.count(\"C\") == 1:",
"+ if S[2:-1].count(\"C\") == 1:",
"+ S = S.replace(\"A\", \"\")",
"+ S = S.replace(\"C\", \"\")",
"+ if S.islower():",
"+ print(\"AC\")",
"+ exit()",
"+print(\"WA\")"
] | false | 0.037694 | 0.037752 | 0.998481 | [
"s446025974",
"s157667986"
] |
u278714855 | p02388 | python | s145162015 | s549206399 | 20 | 10 | 4,188 | 6,424 | Accepted | Accepted | 50 | x=int(input())
print(x*x*x) | a = input()
print(int(a)**3) | 2 | 2 | 31 | 32 | x = int(input())
print(x * x * x)
| a = input()
print(int(a) ** 3)
| false | 0 | [
"-x = int(input())",
"-print(x * x * x)",
"+a = input()",
"+print(int(a) ** 3)"
] | false | 0.037277 | 0.067176 | 0.554911 | [
"s145162015",
"s549206399"
] |
u796942881 | p03775 | python | s342655219 | s610340629 | 53 | 23 | 3,188 | 3,060 | Accepted | Accepted | 56.6 | import math
def divisor(div, N):
# 約数
i = 1
n = N
while i <= math.sqrt(n):
if n % i == 0:
div.append([i, n // i])
i += 1
def main():
N = int(eval(input()))
div = []
divisor(div, N)
print((max(int(math.log10(div[-1][0]) + 1),
int(math.log10(div[-1][1]) + 1))))
return
main()
| import math
def divisor(div, n):
# 約数
ini = 1 if n % 2 else 2
for i in range(ini, int(math.sqrt(n)) + 1, 2):
if n % i == 0:
div.append([i, n // i])
def main():
N = int(eval(input()))
div = []
divisor(div, N)
print((max(int(math.log10(div[-1][0]) + 1),
int(math.log10(div[-1][1]) + 1))))
return
main()
| 24 | 21 | 374 | 385 | import math
def divisor(div, N):
# 約数
i = 1
n = N
while i <= math.sqrt(n):
if n % i == 0:
div.append([i, n // i])
i += 1
def main():
N = int(eval(input()))
div = []
divisor(div, N)
print((max(int(math.log10(div[-1][0]) + 1), int(math.log10(div[-1][1]) + 1))))
return
main()
| import math
def divisor(div, n):
# 約数
ini = 1 if n % 2 else 2
for i in range(ini, int(math.sqrt(n)) + 1, 2):
if n % i == 0:
div.append([i, n // i])
def main():
N = int(eval(input()))
div = []
divisor(div, N)
print((max(int(math.log10(div[-1][0]) + 1), int(math.log10(div[-1][1]) + 1))))
return
main()
| false | 12.5 | [
"-def divisor(div, N):",
"+def divisor(div, n):",
"- i = 1",
"- n = N",
"- while i <= math.sqrt(n):",
"+ ini = 1 if n % 2 else 2",
"+ for i in range(ini, int(math.sqrt(n)) + 1, 2):",
"- i += 1"
] | false | 0.040891 | 0.121572 | 0.336353 | [
"s342655219",
"s610340629"
] |
u316464887 | p03372 | python | s916722527 | s864000786 | 907 | 625 | 75,992 | 72,280 | Accepted | Accepted | 31.09 | class SegTree:
def __init__(self, a, func):
self.n = 2**(len(a) - 1).bit_length()
self.f = func
self.d = [0] * (2 * self.n - 1)
self.d[self.n - 1:self.n - 1 + len(a)] = a
for i in reversed(list(range(self.n - 1))):
self.d[i] = self.f(self.d[2 * i + 1], self.d[2 * i + 2])
def update(self, i, v):
i += self.n - 1
self.d[i] = v
while i:
i = (i - 1) // 2
self.d[i] = self.f(self.d[2 * i + 1], self.d[2 * i + 2])
def query(self, l, r):
assert l <= r
l += self.n
r += self.n
s = self.d[l - 1]
while l < r:
if l & 1:
s = self.f(s, self.d[l - 1])
l += 1
if r & 1:
r -= 1
s = self.f(s, self.d[r - 1])
l //= 2
r //= 2
return s
def main():
N, C = list(map(int, input().split()))
S = []
for i in range(N):
x, v = list(map(int, input().split()))
S.append((x,v))
r = [S[0][1] - S[0][0]]
for i, v in enumerate(S[1:], start=1):
r.append(r[-1] + v[1] - (v[0] - S[i-1][0]))
l = [S[-1][1] + S[-1][0] - C]
for i, v in enumerate(reversed(S[:-1]), start=1):
l.append(l[-1] + v[1] - (S[N-i][0] - v[0]))
l.reverse()
def func(x,y):
return max(x, y)
rs = SegTree(r, func)
ls = SegTree(l, func)
m = 0
for i in range(N):
rr = r[i] - S[i][0] + ls.query(i+1, N) if i < N-1 else 0
ll = l[i] + S[i][0] - C + rs.query(0, i) if i > 0 else 0
m = max(m, r[i], rr, ll, l[i])
return m
print((main()))
| #AC dattakedo segtree iranaikara keshita
def main():
N, C = list(map(int, input().split()))
S = []
for i in range(N):
x, v = list(map(int, input().split()))
S.append((x,v))
r = [S[0][1] - S[0][0]]
rm = [S[0][1] - S[0][0]]
for i, v in enumerate(S[1:], start=1):
r.append(r[-1] + v[1] - (v[0] - S[i-1][0]))
rm.append(max(rm[-1], r[-1]))
l = [S[-1][1] + S[-1][0] - C]
lm = [S[-1][1] + S[-1][0] - C]
for i, v in enumerate(reversed(S[:-1]), start=1):
l.append(l[-1] + v[1] - (S[N-i][0] - v[0]))
lm.append(max(lm[-1], l[-1]))
l.reverse()
lm.reverse()
def func(x,y):
return max(x, y)
m = 0
for i in range(N):
rr = r[i] - S[i][0] + lm[i+1] if i < N-1 else 0
ll = l[i] + S[i][0] - C + rm[i-1] if i > 0 else 0
m = max(m, r[i], rr, ll, l[i])
return m
print((main()))
| 55 | 28 | 1,692 | 909 | class SegTree:
def __init__(self, a, func):
self.n = 2 ** (len(a) - 1).bit_length()
self.f = func
self.d = [0] * (2 * self.n - 1)
self.d[self.n - 1 : self.n - 1 + len(a)] = a
for i in reversed(list(range(self.n - 1))):
self.d[i] = self.f(self.d[2 * i + 1], self.d[2 * i + 2])
def update(self, i, v):
i += self.n - 1
self.d[i] = v
while i:
i = (i - 1) // 2
self.d[i] = self.f(self.d[2 * i + 1], self.d[2 * i + 2])
def query(self, l, r):
assert l <= r
l += self.n
r += self.n
s = self.d[l - 1]
while l < r:
if l & 1:
s = self.f(s, self.d[l - 1])
l += 1
if r & 1:
r -= 1
s = self.f(s, self.d[r - 1])
l //= 2
r //= 2
return s
def main():
N, C = list(map(int, input().split()))
S = []
for i in range(N):
x, v = list(map(int, input().split()))
S.append((x, v))
r = [S[0][1] - S[0][0]]
for i, v in enumerate(S[1:], start=1):
r.append(r[-1] + v[1] - (v[0] - S[i - 1][0]))
l = [S[-1][1] + S[-1][0] - C]
for i, v in enumerate(reversed(S[:-1]), start=1):
l.append(l[-1] + v[1] - (S[N - i][0] - v[0]))
l.reverse()
def func(x, y):
return max(x, y)
rs = SegTree(r, func)
ls = SegTree(l, func)
m = 0
for i in range(N):
rr = r[i] - S[i][0] + ls.query(i + 1, N) if i < N - 1 else 0
ll = l[i] + S[i][0] - C + rs.query(0, i) if i > 0 else 0
m = max(m, r[i], rr, ll, l[i])
return m
print((main()))
| # AC dattakedo segtree iranaikara keshita
def main():
N, C = list(map(int, input().split()))
S = []
for i in range(N):
x, v = list(map(int, input().split()))
S.append((x, v))
r = [S[0][1] - S[0][0]]
rm = [S[0][1] - S[0][0]]
for i, v in enumerate(S[1:], start=1):
r.append(r[-1] + v[1] - (v[0] - S[i - 1][0]))
rm.append(max(rm[-1], r[-1]))
l = [S[-1][1] + S[-1][0] - C]
lm = [S[-1][1] + S[-1][0] - C]
for i, v in enumerate(reversed(S[:-1]), start=1):
l.append(l[-1] + v[1] - (S[N - i][0] - v[0]))
lm.append(max(lm[-1], l[-1]))
l.reverse()
lm.reverse()
def func(x, y):
return max(x, y)
m = 0
for i in range(N):
rr = r[i] - S[i][0] + lm[i + 1] if i < N - 1 else 0
ll = l[i] + S[i][0] - C + rm[i - 1] if i > 0 else 0
m = max(m, r[i], rr, ll, l[i])
return m
print((main()))
| false | 49.090909 | [
"-class SegTree:",
"- def __init__(self, a, func):",
"- self.n = 2 ** (len(a) - 1).bit_length()",
"- self.f = func",
"- self.d = [0] * (2 * self.n - 1)",
"- self.d[self.n - 1 : self.n - 1 + len(a)] = a",
"- for i in reversed(list(range(self.n - 1))):",
"- self.d[i] = self.f(self.d[2 * i + 1], self.d[2 * i + 2])",
"-",
"- def update(self, i, v):",
"- i += self.n - 1",
"- self.d[i] = v",
"- while i:",
"- i = (i - 1) // 2",
"- self.d[i] = self.f(self.d[2 * i + 1], self.d[2 * i + 2])",
"-",
"- def query(self, l, r):",
"- assert l <= r",
"- l += self.n",
"- r += self.n",
"- s = self.d[l - 1]",
"- while l < r:",
"- if l & 1:",
"- s = self.f(s, self.d[l - 1])",
"- l += 1",
"- if r & 1:",
"- r -= 1",
"- s = self.f(s, self.d[r - 1])",
"- l //= 2",
"- r //= 2",
"- return s",
"-",
"-",
"+# AC dattakedo segtree iranaikara keshita",
"+ rm = [S[0][1] - S[0][0]]",
"+ rm.append(max(rm[-1], r[-1]))",
"+ lm = [S[-1][1] + S[-1][0] - C]",
"+ lm.append(max(lm[-1], l[-1]))",
"+ lm.reverse()",
"- rs = SegTree(r, func)",
"- ls = SegTree(l, func)",
"- rr = r[i] - S[i][0] + ls.query(i + 1, N) if i < N - 1 else 0",
"- ll = l[i] + S[i][0] - C + rs.query(0, i) if i > 0 else 0",
"+ rr = r[i] - S[i][0] + lm[i + 1] if i < N - 1 else 0",
"+ ll = l[i] + S[i][0] - C + rm[i - 1] if i > 0 else 0"
] | false | 0.096969 | 0.081373 | 1.191657 | [
"s916722527",
"s864000786"
] |
u036104576 | p02924 | python | s243092109 | s140799382 | 151 | 17 | 12,400 | 2,940 | Accepted | Accepted | 88.74 | import sys
import itertools
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(eval(input()))
print(((n) * (n-1)//2)) | N = int(eval(input()))
print((N * (N - 1) // 2)) | 11 | 3 | 204 | 43 | import sys
import itertools
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(eval(input()))
print(((n) * (n - 1) // 2))
| N = int(eval(input()))
print((N * (N - 1) // 2))
| false | 72.727273 | [
"-import sys",
"-import itertools",
"-import numpy as np",
"-",
"-read = sys.stdin.buffer.read",
"-readline = sys.stdin.buffer.readline",
"-readlines = sys.stdin.buffer.readlines",
"-n = int(eval(input()))",
"-print(((n) * (n - 1) // 2))",
"+N = int(eval(input()))",
"+print((N * (N - 1) // 2))"
] | false | 0.034519 | 0.035258 | 0.979044 | [
"s243092109",
"s140799382"
] |
u621935300 | p03078 | python | s358076063 | s306450267 | 745 | 119 | 155,080 | 39,452 | Accepted | Accepted | 84.03 | X,Y,Z,K=list(map(int, input().split()))
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))
L=[]
for a in A:
for b in B:
L.append(a+b)
L.sort(reverse=True)
L=L[:K]
L2=[]
for ab in L:
for c in C:
L2.append(ab+c)
L2.sort(reverse=True)
for i in range(K):
print(L2[i]) | X,Y,Z,K=list(map(int, input().split()))
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
L=[]
for ia, a in enumerate(A):
for ib, b in enumerate(B):
for ic, c in enumerate(C):
if (ia+1)*(ib+1)*(ic+1)<=K:
L.append(a+b+c)
else:
break
L.sort(reverse=True)
for i in range(K):
print(L[i]) | 22 | 22 | 338 | 432 | X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
L = []
for a in A:
for b in B:
L.append(a + b)
L.sort(reverse=True)
L = L[:K]
L2 = []
for ab in L:
for c in C:
L2.append(ab + c)
L2.sort(reverse=True)
for i in range(K):
print(L2[i])
| X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
L = []
for ia, a in enumerate(A):
for ib, b in enumerate(B):
for ic, c in enumerate(C):
if (ia + 1) * (ib + 1) * (ic + 1) <= K:
L.append(a + b + c)
else:
break
L.sort(reverse=True)
for i in range(K):
print(L[i])
| false | 0 | [
"+A.sort(reverse=True)",
"+B.sort(reverse=True)",
"+C.sort(reverse=True)",
"-for a in A:",
"- for b in B:",
"- L.append(a + b)",
"+for ia, a in enumerate(A):",
"+ for ib, b in enumerate(B):",
"+ for ic, c in enumerate(C):",
"+ if (ia + 1) * (ib + 1) * (ic + 1) <= K:",
"+ L.append(a + b + c)",
"+ else:",
"+ break",
"-L = L[:K]",
"-L2 = []",
"-for ab in L:",
"- for c in C:",
"- L2.append(ab + c)",
"-L2.sort(reverse=True)",
"- print(L2[i])",
"+ print(L[i])"
] | false | 0.047773 | 0.04205 | 1.136104 | [
"s358076063",
"s306450267"
] |
u761320129 | p03634 | python | s508522665 | s588394997 | 1,510 | 1,268 | 44,300 | 71,188 | Accepted | Accepted | 16.03 | import heapq
N = int(eval(input()))
es = [[] for i in range(N)]
for i in range(N-1):
a,b,c = list(map(int,input().split()))
a,b = a-1, b-1
es[a].append((b,c))
es[b].append((a,c))
Q,K = list(map(int, input().split()))
K -= 1
INF = float('inf')
ds = [INF for i in range(N)]
ds[K] = 0
visited = [0 for i in range(N)]
q = [K]
heapq.heapify(q)
while q:
now = heapq.heappop(q)
visited[now] = 1
for to,cost in es[now]:
ds[to] = min(ds[to], ds[now]+cost)
if visited[to]: continue
heapq.heappush(q,to)
for i in range(Q):
x,y = list(map(int, input().split()))
x,y = x-1, y-1
print((ds[x] + ds[y]))
| import heapq
N = int(eval(input()))
src = [tuple(map(int,input().split())) for i in range(N-1)]
Q,K = list(map(int,input().split()))
K -= 1
qs = [tuple(map(int,input().split())) for i in range(Q)]
es = [[] for i in range(N)]
for a,b,c in src:
a,b = a-1,b-1
es[a].append((c,b))
es[b].append((c,a))
INF = float('inf')
dists = [INF] * N
dists[K] = 0
hq = [(0,K)]
heapq.heapify(hq)
while hq:
dist,v = heapq.heappop(hq)
dists[v] = dist
for dd,to in es[v]:
if dists[to] != INF: continue
heapq.heappush(hq, (dist+dd, to))
for a,b in qs:
a,b = a-1,b-1
print((dists[a] + dists[b])) | 29 | 29 | 656 | 638 | import heapq
N = int(eval(input()))
es = [[] for i in range(N)]
for i in range(N - 1):
a, b, c = list(map(int, input().split()))
a, b = a - 1, b - 1
es[a].append((b, c))
es[b].append((a, c))
Q, K = list(map(int, input().split()))
K -= 1
INF = float("inf")
ds = [INF for i in range(N)]
ds[K] = 0
visited = [0 for i in range(N)]
q = [K]
heapq.heapify(q)
while q:
now = heapq.heappop(q)
visited[now] = 1
for to, cost in es[now]:
ds[to] = min(ds[to], ds[now] + cost)
if visited[to]:
continue
heapq.heappush(q, to)
for i in range(Q):
x, y = list(map(int, input().split()))
x, y = x - 1, y - 1
print((ds[x] + ds[y]))
| import heapq
N = int(eval(input()))
src = [tuple(map(int, input().split())) for i in range(N - 1)]
Q, K = list(map(int, input().split()))
K -= 1
qs = [tuple(map(int, input().split())) for i in range(Q)]
es = [[] for i in range(N)]
for a, b, c in src:
a, b = a - 1, b - 1
es[a].append((c, b))
es[b].append((c, a))
INF = float("inf")
dists = [INF] * N
dists[K] = 0
hq = [(0, K)]
heapq.heapify(hq)
while hq:
dist, v = heapq.heappop(hq)
dists[v] = dist
for dd, to in es[v]:
if dists[to] != INF:
continue
heapq.heappush(hq, (dist + dd, to))
for a, b in qs:
a, b = a - 1, b - 1
print((dists[a] + dists[b]))
| false | 0 | [
"-es = [[] for i in range(N)]",
"-for i in range(N - 1):",
"- a, b, c = list(map(int, input().split()))",
"- a, b = a - 1, b - 1",
"- es[a].append((b, c))",
"- es[b].append((a, c))",
"+src = [tuple(map(int, input().split())) for i in range(N - 1)]",
"+qs = [tuple(map(int, input().split())) for i in range(Q)]",
"+es = [[] for i in range(N)]",
"+for a, b, c in src:",
"+ a, b = a - 1, b - 1",
"+ es[a].append((c, b))",
"+ es[b].append((c, a))",
"-ds = [INF for i in range(N)]",
"-ds[K] = 0",
"-visited = [0 for i in range(N)]",
"-q = [K]",
"-heapq.heapify(q)",
"-while q:",
"- now = heapq.heappop(q)",
"- visited[now] = 1",
"- for to, cost in es[now]:",
"- ds[to] = min(ds[to], ds[now] + cost)",
"- if visited[to]:",
"+dists = [INF] * N",
"+dists[K] = 0",
"+hq = [(0, K)]",
"+heapq.heapify(hq)",
"+while hq:",
"+ dist, v = heapq.heappop(hq)",
"+ dists[v] = dist",
"+ for dd, to in es[v]:",
"+ if dists[to] != INF:",
"- heapq.heappush(q, to)",
"-for i in range(Q):",
"- x, y = list(map(int, input().split()))",
"- x, y = x - 1, y - 1",
"- print((ds[x] + ds[y]))",
"+ heapq.heappush(hq, (dist + dd, to))",
"+for a, b in qs:",
"+ a, b = a - 1, b - 1",
"+ print((dists[a] + dists[b]))"
] | false | 0.042714 | 0.043319 | 0.986047 | [
"s508522665",
"s588394997"
] |
u724687935 | p03494 | python | s683092441 | s335673829 | 177 | 18 | 38,640 | 2,940 | Accepted | Accepted | 89.83 | def main():
_ = eval(input())
li = list(map(int, input().split()))
cnt = 0
while True:
if 1 in [x % 2 for x in li]:
break
else:
cnt += 1
li = [x // 2 for x in li]
print(cnt)
if __name__ == '__main__':
main()
| N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
B = []
for a in A:
cnt = 0
while a % 2 == 0:
a //= 2
cnt += 1
B.append(cnt)
print((min(B)))
| 16 | 13 | 296 | 193 | def main():
_ = eval(input())
li = list(map(int, input().split()))
cnt = 0
while True:
if 1 in [x % 2 for x in li]:
break
else:
cnt += 1
li = [x // 2 for x in li]
print(cnt)
if __name__ == "__main__":
main()
| N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
B = []
for a in A:
cnt = 0
while a % 2 == 0:
a //= 2
cnt += 1
B.append(cnt)
print((min(B)))
| false | 18.75 | [
"-def main():",
"- _ = eval(input())",
"- li = list(map(int, input().split()))",
"+N = int(eval(input()))",
"+A = list(map(int, input().split()))",
"+ans = 0",
"+B = []",
"+for a in A:",
"- while True:",
"- if 1 in [x % 2 for x in li]:",
"- break",
"- else:",
"- cnt += 1",
"- li = [x // 2 for x in li]",
"- print(cnt)",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+ while a % 2 == 0:",
"+ a //= 2",
"+ cnt += 1",
"+ B.append(cnt)",
"+print((min(B)))"
] | false | 0.045183 | 0.042147 | 1.072034 | [
"s683092441",
"s335673829"
] |
u221898645 | p03798 | python | s234328486 | s139879576 | 1,349 | 231 | 3,500 | 3,444 | Accepted | Accepted | 82.88 | global S,ans
def check_at(i):
global S,ans
if ans[i] == "S":
if (S[i] == "o" and ans[i-1] != ans[i+1]) or (S[i] == "x" and ans[i-1] == ans[i+1]):
return True
else:
if (S[i] == "o" and ans[i-1] == ans[i+1]) or (S[i] == "x" and ans[i-1] != ans[i+1]):
return True
N = int(eval(input()))
S = eval(input())
opposite = {"S": "W",
"W": "S"}
for ans in ["SS","SW","WS","WW"]:
for i in range(1,N-1):
if ans[i] == "S" and S[i] == "o":
ans += ans[i-1]
elif ans[i] == "S" and S[i] == "x":
ans += opposite[ans[i-1]]
elif ans[i] == "W" and S[i] == "o":
ans += opposite[ans[i-1]]
elif ans[i] == "W" and S[i] == "x":
ans += ans[i-1]
if (not check_at(-1)) and (not check_at(0)):
print(ans)
break
else:
print((-1)) | N = int(eval(input()))
S = eval(input())
opposite = {"S": "W",
"W": "S"}
for ans in ["SS","SW","WS","WW"]:
for i in range(1,N-1):
if ans[i] == "S" and S[i] == "o":
ans += ans[i-1]
elif ans[i] == "S" and S[i] == "x":
ans += opposite[ans[i-1]]
elif ans[i] == "W" and S[i] == "o":
ans += opposite[ans[i-1]]
elif ans[i] == "W" and S[i] == "x":
ans += ans[i-1]
for i in [-1,0]:
if ans[i] == "S":
if (S[i] == "o" and ans[i-1] != ans[i+1]) or (S[i] == "x" and ans[i-1] == ans[i+1]):
break
else:
if (S[i] == "o" and ans[i-1] == ans[i+1]) or (S[i] == "x" and ans[i-1] != ans[i+1]):
break
else:
print(ans)
break
else:
print((-1)) | 34 | 29 | 815 | 742 | global S, ans
def check_at(i):
global S, ans
if ans[i] == "S":
if (S[i] == "o" and ans[i - 1] != ans[i + 1]) or (
S[i] == "x" and ans[i - 1] == ans[i + 1]
):
return True
else:
if (S[i] == "o" and ans[i - 1] == ans[i + 1]) or (
S[i] == "x" and ans[i - 1] != ans[i + 1]
):
return True
N = int(eval(input()))
S = eval(input())
opposite = {"S": "W", "W": "S"}
for ans in ["SS", "SW", "WS", "WW"]:
for i in range(1, N - 1):
if ans[i] == "S" and S[i] == "o":
ans += ans[i - 1]
elif ans[i] == "S" and S[i] == "x":
ans += opposite[ans[i - 1]]
elif ans[i] == "W" and S[i] == "o":
ans += opposite[ans[i - 1]]
elif ans[i] == "W" and S[i] == "x":
ans += ans[i - 1]
if (not check_at(-1)) and (not check_at(0)):
print(ans)
break
else:
print((-1))
| N = int(eval(input()))
S = eval(input())
opposite = {"S": "W", "W": "S"}
for ans in ["SS", "SW", "WS", "WW"]:
for i in range(1, N - 1):
if ans[i] == "S" and S[i] == "o":
ans += ans[i - 1]
elif ans[i] == "S" and S[i] == "x":
ans += opposite[ans[i - 1]]
elif ans[i] == "W" and S[i] == "o":
ans += opposite[ans[i - 1]]
elif ans[i] == "W" and S[i] == "x":
ans += ans[i - 1]
for i in [-1, 0]:
if ans[i] == "S":
if (S[i] == "o" and ans[i - 1] != ans[i + 1]) or (
S[i] == "x" and ans[i - 1] == ans[i + 1]
):
break
else:
if (S[i] == "o" and ans[i - 1] == ans[i + 1]) or (
S[i] == "x" and ans[i - 1] != ans[i + 1]
):
break
else:
print(ans)
break
else:
print((-1))
| false | 14.705882 | [
"-global S, ans",
"-",
"-",
"-def check_at(i):",
"- global S, ans",
"- if ans[i] == \"S\":",
"- if (S[i] == \"o\" and ans[i - 1] != ans[i + 1]) or (",
"- S[i] == \"x\" and ans[i - 1] == ans[i + 1]",
"- ):",
"- return True",
"- else:",
"- if (S[i] == \"o\" and ans[i - 1] == ans[i + 1]) or (",
"- S[i] == \"x\" and ans[i - 1] != ans[i + 1]",
"- ):",
"- return True",
"-",
"-",
"- if (not check_at(-1)) and (not check_at(0)):",
"+ for i in [-1, 0]:",
"+ if ans[i] == \"S\":",
"+ if (S[i] == \"o\" and ans[i - 1] != ans[i + 1]) or (",
"+ S[i] == \"x\" and ans[i - 1] == ans[i + 1]",
"+ ):",
"+ break",
"+ else:",
"+ if (S[i] == \"o\" and ans[i - 1] == ans[i + 1]) or (",
"+ S[i] == \"x\" and ans[i - 1] != ans[i + 1]",
"+ ):",
"+ break",
"+ else:"
] | false | 0.079967 | 0.035699 | 2.240044 | [
"s234328486",
"s139879576"
] |
u708255304 | p02787 | python | s601370940 | s052241605 | 1,164 | 602 | 289,416 | 122,476 | Accepted | Accepted | 48.28 | H, N = list(map(int, input().split()))
A = []
B = []
for _ in range(N):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
# 個数制限なしナップサック
# i番目までの魔法を使ったときにHダメージを実現できるときの最小の魔力
dp = [[float('inf')]*(H+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
for j in range(H+1):
# i番目の魔法を使わない時
dp[i+1][j] = min(dp[i+1][j], dp[i][j])
# i番目の魔法を使う時
dp[i+1][min(H, j+A[i])] = min(dp[i][j]+B[i], dp[i+1][j]+B[i], dp[i+1][min(j+A[i], H)])
print((dp[N][H]))
| H, N = list(map(int, input().split()))
A = []
B = []
for _ in range(N):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
# 個数制限なしナップサック
# i番目までの魔法を使ったときにHダメージを実現できるときの最小の魔力
dp = [[10**10]*(H+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
for j in range(H+1):
# i番目の魔法を使わない時
dp[i+1][j] = min(dp[i+1][j], dp[i][j])
# i番目の魔法を使う時
dp[i+1][min(H, j+A[i])] = min(dp[i][j]+B[i], dp[i+1][j]+B[i], dp[i+1][min(j+A[i], H)])
print((dp[N][H]))
| 20 | 20 | 515 | 509 | H, N = list(map(int, input().split()))
A = []
B = []
for _ in range(N):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
# 個数制限なしナップサック
# i番目までの魔法を使ったときにHダメージを実現できるときの最小の魔力
dp = [[float("inf")] * (H + 1) for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
for j in range(H + 1):
# i番目の魔法を使わない時
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
# i番目の魔法を使う時
dp[i + 1][min(H, j + A[i])] = min(
dp[i][j] + B[i], dp[i + 1][j] + B[i], dp[i + 1][min(j + A[i], H)]
)
print((dp[N][H]))
| H, N = list(map(int, input().split()))
A = []
B = []
for _ in range(N):
a, b = list(map(int, input().split()))
A.append(a)
B.append(b)
# 個数制限なしナップサック
# i番目までの魔法を使ったときにHダメージを実現できるときの最小の魔力
dp = [[10**10] * (H + 1) for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
for j in range(H + 1):
# i番目の魔法を使わない時
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
# i番目の魔法を使う時
dp[i + 1][min(H, j + A[i])] = min(
dp[i][j] + B[i], dp[i + 1][j] + B[i], dp[i + 1][min(j + A[i], H)]
)
print((dp[N][H]))
| false | 0 | [
"-dp = [[float(\"inf\")] * (H + 1) for _ in range(N + 1)]",
"+dp = [[10**10] * (H + 1) for _ in range(N + 1)]"
] | false | 0.148462 | 0.146661 | 1.01228 | [
"s601370940",
"s052241605"
] |
u550535134 | p02712 | python | s464765952 | s615566208 | 170 | 156 | 9,160 | 9,156 | Accepted | Accepted | 8.24 | N = int(eval(input()))
total = 0
for i in range(1, N+1):
if (i%3) != 0 and (i%5) != 0:
total = total + i
print(total)
| N = int(eval(input()))
total = 0
for i in range(1, N+1):
if (i%3) != 0 and (i%5) != 0:
total += i
print(total)
| 6 | 6 | 124 | 116 | N = int(eval(input()))
total = 0
for i in range(1, N + 1):
if (i % 3) != 0 and (i % 5) != 0:
total = total + i
print(total)
| N = int(eval(input()))
total = 0
for i in range(1, N + 1):
if (i % 3) != 0 and (i % 5) != 0:
total += i
print(total)
| false | 0 | [
"- total = total + i",
"+ total += i"
] | false | 0.433711 | 0.295662 | 1.466914 | [
"s464765952",
"s615566208"
] |
u113971909 | p03487 | python | s470575476 | s754775282 | 150 | 110 | 21,236 | 21,220 | Accepted | Accepted | 26.67 | N=int(eval(input()))
A=list(map(int,input().split()))
A.sort()
from collections import Counter
A=Counter(A)
ret=0
for i in A.most_common():
if i[0]>i[1]:
ret+=i[1]
else:
ret+=i[1]-i[0]
print(ret) | N=int(eval(input()))
A=list(map(int,input().split()))
from collections import Counter
A=Counter(A)
ret=0
for i in A.most_common():
if i[0]>i[1]:
ret+=i[1]
else:
ret+=i[1]-i[0]
print(ret) | 12 | 11 | 212 | 202 | N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
from collections import Counter
A = Counter(A)
ret = 0
for i in A.most_common():
if i[0] > i[1]:
ret += i[1]
else:
ret += i[1] - i[0]
print(ret)
| N = int(eval(input()))
A = list(map(int, input().split()))
from collections import Counter
A = Counter(A)
ret = 0
for i in A.most_common():
if i[0] > i[1]:
ret += i[1]
else:
ret += i[1] - i[0]
print(ret)
| false | 8.333333 | [
"-A.sort()"
] | false | 0.082811 | 0.034339 | 2.411579 | [
"s470575476",
"s754775282"
] |
u813102292 | p03476 | python | s634261414 | s756371356 | 558 | 500 | 29,796 | 29,812 | Accepted | Accepted | 10.39 | q = int(eval(input()))
a = [list(int(i) for i in input().split()) for i in range(q)]
MAX = 10**5
is_prime = [1]*MAX
for i in range(2, MAX):
if not is_prime[i]:
continue
for j in range(i*2, MAX, i):
is_prime[j] = 0
s = [0]*MAX
for i in range(3,MAX):
s[i] = s[i-1] + 1 if is_prime[i] and is_prime[(i+1)//2] else s[i-1]
for i in range(q):
l,r = a[i]
print((s[r]-s[l-1])) | def main():
q = int(eval(input()))
a = [list(int(i) for i in input().split()) for i in range(q)]
MAX = 10**5
is_prime = [1]*MAX
for i in range(2, MAX):
if not is_prime[i]:
continue
for j in range(i*2, MAX, i):
is_prime[j] = 0
s = [0]*MAX
for i in range(3,MAX):
s[i] = s[i-1] + 1 if is_prime[i] and is_prime[(i+1)//2] else s[i-1]
for i in range(q):
l,r = a[i]
print((s[r]-s[l-1]))
if __name__ == '__main__':
main() | 15 | 19 | 409 | 524 | q = int(eval(input()))
a = [list(int(i) for i in input().split()) for i in range(q)]
MAX = 10**5
is_prime = [1] * MAX
for i in range(2, MAX):
if not is_prime[i]:
continue
for j in range(i * 2, MAX, i):
is_prime[j] = 0
s = [0] * MAX
for i in range(3, MAX):
s[i] = s[i - 1] + 1 if is_prime[i] and is_prime[(i + 1) // 2] else s[i - 1]
for i in range(q):
l, r = a[i]
print((s[r] - s[l - 1]))
| def main():
q = int(eval(input()))
a = [list(int(i) for i in input().split()) for i in range(q)]
MAX = 10**5
is_prime = [1] * MAX
for i in range(2, MAX):
if not is_prime[i]:
continue
for j in range(i * 2, MAX, i):
is_prime[j] = 0
s = [0] * MAX
for i in range(3, MAX):
s[i] = s[i - 1] + 1 if is_prime[i] and is_prime[(i + 1) // 2] else s[i - 1]
for i in range(q):
l, r = a[i]
print((s[r] - s[l - 1]))
if __name__ == "__main__":
main()
| false | 21.052632 | [
"-q = int(eval(input()))",
"-a = [list(int(i) for i in input().split()) for i in range(q)]",
"-MAX = 10**5",
"-is_prime = [1] * MAX",
"-for i in range(2, MAX):",
"- if not is_prime[i]:",
"- continue",
"- for j in range(i * 2, MAX, i):",
"- is_prime[j] = 0",
"-s = [0] * MAX",
"-for i in range(3, MAX):",
"- s[i] = s[i - 1] + 1 if is_prime[i] and is_prime[(i + 1) // 2] else s[i - 1]",
"-for i in range(q):",
"- l, r = a[i]",
"- print((s[r] - s[l - 1]))",
"+def main():",
"+ q = int(eval(input()))",
"+ a = [list(int(i) for i in input().split()) for i in range(q)]",
"+ MAX = 10**5",
"+ is_prime = [1] * MAX",
"+ for i in range(2, MAX):",
"+ if not is_prime[i]:",
"+ continue",
"+ for j in range(i * 2, MAX, i):",
"+ is_prime[j] = 0",
"+ s = [0] * MAX",
"+ for i in range(3, MAX):",
"+ s[i] = s[i - 1] + 1 if is_prime[i] and is_prime[(i + 1) // 2] else s[i - 1]",
"+ for i in range(q):",
"+ l, r = a[i]",
"+ print((s[r] - s[l - 1]))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.14386 | 0.124637 | 1.154232 | [
"s634261414",
"s756371356"
] |
u707124227 | p02775 | python | s940007931 | s237893101 | 806 | 112 | 236,020 | 75,868 | Accepted | Accepted | 86.1 | s='0'
s+=eval(input())
n=len(s)
inf=float('inf')
dp=[[inf]*2 for _ in range(n+1)]
dp[0][0]=0
for i in range(n):
for j in range(2):
si=int(s[-i-1])
si+=j
for a in range(10):
ni=i+1
nj=0
b=a-si
if b<0:
nj=1
b+=10
dp[ni][nj]=min(dp[ni][nj],dp[i][j]+a+b)
print((dp[n][0])) | s=eval(input())
n=len(s)
dp=0,1
for i in range(n):
si=int(s[i])
a=min(dp[0]+si,dp[1]+10-si)
b=min(dp[0]+si+1,dp[1]+10-(si+1))
dp=a,b
print((dp[0])) | 19 | 9 | 338 | 155 | s = "0"
s += eval(input())
n = len(s)
inf = float("inf")
dp = [[inf] * 2 for _ in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for j in range(2):
si = int(s[-i - 1])
si += j
for a in range(10):
ni = i + 1
nj = 0
b = a - si
if b < 0:
nj = 1
b += 10
dp[ni][nj] = min(dp[ni][nj], dp[i][j] + a + b)
print((dp[n][0]))
| s = eval(input())
n = len(s)
dp = 0, 1
for i in range(n):
si = int(s[i])
a = min(dp[0] + si, dp[1] + 10 - si)
b = min(dp[0] + si + 1, dp[1] + 10 - (si + 1))
dp = a, b
print((dp[0]))
| false | 52.631579 | [
"-s = \"0\"",
"-s += eval(input())",
"+s = eval(input())",
"-inf = float(\"inf\")",
"-dp = [[inf] * 2 for _ in range(n + 1)]",
"-dp[0][0] = 0",
"+dp = 0, 1",
"- for j in range(2):",
"- si = int(s[-i - 1])",
"- si += j",
"- for a in range(10):",
"- ni = i + 1",
"- nj = 0",
"- b = a - si",
"- if b < 0:",
"- nj = 1",
"- b += 10",
"- dp[ni][nj] = min(dp[ni][nj], dp[i][j] + a + b)",
"-print((dp[n][0]))",
"+ si = int(s[i])",
"+ a = min(dp[0] + si, dp[1] + 10 - si)",
"+ b = min(dp[0] + si + 1, dp[1] + 10 - (si + 1))",
"+ dp = a, b",
"+print((dp[0]))"
] | false | 0.037675 | 0.046332 | 0.81314 | [
"s940007931",
"s237893101"
] |
u273010357 | p03160 | python | s529688605 | s695906652 | 155 | 139 | 13,928 | 13,928 | Accepted | Accepted | 10.32 | def chmin(a, b):
if a > b:
return b
else:
return a
# input
N = int(eval(input()))
h = list(map(int, input().split()))
# dp table
dp = [float('inf')]*(10**5 + 10)
# 初期条件
dp[0] = 0
for i in range(1,N):
dp[i] = chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
if i > 1:
dp[i] = chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]))
# ans
print((dp[N-1])) | N = int(eval(input()))
h = list(map(int, input().split()))
dp = [float('inf')]*(10**5 + 10)
dp[0] = 0
for i in range(1,N):
dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))
print((dp[N-1])) | 23 | 10 | 393 | 226 | def chmin(a, b):
if a > b:
return b
else:
return a
# input
N = int(eval(input()))
h = list(map(int, input().split()))
# dp table
dp = [float("inf")] * (10**5 + 10)
# 初期条件
dp[0] = 0
for i in range(1, N):
dp[i] = chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))
if i > 1:
dp[i] = chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))
# ans
print((dp[N - 1]))
| N = int(eval(input()))
h = list(map(int, input().split()))
dp = [float("inf")] * (10**5 + 10)
dp[0] = 0
for i in range(1, N):
dp[i] = min(
dp[i], dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])
)
print((dp[N - 1]))
| false | 56.521739 | [
"-def chmin(a, b):",
"- if a > b:",
"- return b",
"- else:",
"- return a",
"-",
"-",
"-# input",
"-# dp table",
"-# 初期条件",
"- dp[i] = chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]))",
"- if i > 1:",
"- dp[i] = chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]))",
"-# ans",
"+ dp[i] = min(",
"+ dp[i], dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])",
"+ )"
] | false | 0.042851 | 0.041988 | 1.020553 | [
"s529688605",
"s695906652"
] |
u175034939 | p03221 | python | s541681165 | s706492944 | 1,077 | 924 | 49,468 | 39,372 | Accepted | Accepted | 14.21 | n,m = list(map(int,input().split()))
ken = []
for i in range(m):
p,y = list(map(int,input().split()))
ken.append([p,y,i+1])
k = sorted(ken)
a = []
cnt = 1
for i in range(m):
if i >= 1:
if k[i][0] == k[i-1][0]:
cnt += 1
else:
cnt = 1
a.append([k[i][-1],k[i][0],cnt])
aa = sorted(a)
b = []
for i in range(m):
b.append([aa[i][1],aa[i][2]])
for i in range(m):
print(("{0:06d}".format(b[i][0]) + "{0:06d}".format(b[i][1]))) | n,m = list(map(int,input().split()))
ken = []
for i in range(m):
p,y = list(map(int,input().split()))
ken.append([p,y,i+1])
k = sorted(ken)
a = []
cnt = 1
for i in range(m):
if i >= 1:
if k[i][0] == k[i-1][0]:
cnt += 1
else:
cnt = 1
a.append([k[i][-1],k[i][0],cnt])
aa = sorted(a)
for i in range(m):
print(("{0:06d}".format(aa[i][1]) + "{0:06d}".format(aa[i][2]))) | 24 | 20 | 498 | 432 | n, m = list(map(int, input().split()))
ken = []
for i in range(m):
p, y = list(map(int, input().split()))
ken.append([p, y, i + 1])
k = sorted(ken)
a = []
cnt = 1
for i in range(m):
if i >= 1:
if k[i][0] == k[i - 1][0]:
cnt += 1
else:
cnt = 1
a.append([k[i][-1], k[i][0], cnt])
aa = sorted(a)
b = []
for i in range(m):
b.append([aa[i][1], aa[i][2]])
for i in range(m):
print(("{0:06d}".format(b[i][0]) + "{0:06d}".format(b[i][1])))
| n, m = list(map(int, input().split()))
ken = []
for i in range(m):
p, y = list(map(int, input().split()))
ken.append([p, y, i + 1])
k = sorted(ken)
a = []
cnt = 1
for i in range(m):
if i >= 1:
if k[i][0] == k[i - 1][0]:
cnt += 1
else:
cnt = 1
a.append([k[i][-1], k[i][0], cnt])
aa = sorted(a)
for i in range(m):
print(("{0:06d}".format(aa[i][1]) + "{0:06d}".format(aa[i][2])))
| false | 16.666667 | [
"-b = []",
"- b.append([aa[i][1], aa[i][2]])",
"-for i in range(m):",
"- print((\"{0:06d}\".format(b[i][0]) + \"{0:06d}\".format(b[i][1])))",
"+ print((\"{0:06d}\".format(aa[i][1]) + \"{0:06d}\".format(aa[i][2])))"
] | false | 0.04237 | 0.04098 | 1.033908 | [
"s541681165",
"s706492944"
] |
u608088992 | p02983 | python | s867722944 | s480495734 | 1,210 | 606 | 3,060 | 3,060 | Accepted | Accepted | 49.92 | import sys
def solve():
input = sys.stdin.readline
L, R = list(map(int, input().split()))
if R - L >= 2018: print((0))
else:
ans = 2019
for i in range(L, R):
for j in range(L + 1, R + 1):
ans = min(ans, (i * j) % 2019)
print(ans)
return 0
if __name__ == "__main__":
solve() | import sys
def solve():
input = sys.stdin.readline
L, R = list(map(int, input().split()))
if R - L >= 2019: print((0))
else:
minMod = 2019
for i in range(L, R):
for j in range(i + 1, R + 1):
minMod = min((i * j) % 2019, minMod)
print(minMod)
return 0
if __name__ == "__main__":
solve() | 17 | 17 | 364 | 372 | import sys
def solve():
input = sys.stdin.readline
L, R = list(map(int, input().split()))
if R - L >= 2018:
print((0))
else:
ans = 2019
for i in range(L, R):
for j in range(L + 1, R + 1):
ans = min(ans, (i * j) % 2019)
print(ans)
return 0
if __name__ == "__main__":
solve()
| import sys
def solve():
input = sys.stdin.readline
L, R = list(map(int, input().split()))
if R - L >= 2019:
print((0))
else:
minMod = 2019
for i in range(L, R):
for j in range(i + 1, R + 1):
minMod = min((i * j) % 2019, minMod)
print(minMod)
return 0
if __name__ == "__main__":
solve()
| false | 0 | [
"- if R - L >= 2018:",
"+ if R - L >= 2019:",
"- ans = 2019",
"+ minMod = 2019",
"- for j in range(L + 1, R + 1):",
"- ans = min(ans, (i * j) % 2019)",
"- print(ans)",
"+ for j in range(i + 1, R + 1):",
"+ minMod = min((i * j) % 2019, minMod)",
"+ print(minMod)"
] | false | 0.191998 | 0.110206 | 1.742175 | [
"s867722944",
"s480495734"
] |
u533039576 | p03111 | python | s717616682 | s567740627 | 427 | 69 | 3,064 | 3,064 | Accepted | Accepted | 83.84 | n, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
ans = 3000
for bits in range(4**n):
xa = xb = xc = 0
tmp_ans = 0
for i in range(n):
f = (bits//(4**i)) % 4
if f == 1:
if xa != 0:
tmp_ans += 10
xa += l[i]
elif f == 2:
if xb != 0:
tmp_ans += 10
xb += l[i]
elif f == 3:
if xc != 0:
tmp_ans += 10
xc += l[i]
if xa == 0 or xb == 0 or xc == 0:
continue
tmp_ans += abs(a - xa) + abs(b - xb) + abs(c - xc)
ans = min(ans, tmp_ans)
print(ans)
| n, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
INF = 10**9
def dfs(index, x, y, z):
if index == n:
return abs(a-x) + abs(b-y) + abs(c-z) - 30 if min(x, y, z) > 0 else INF
cand1 = dfs(index+1, x+l[index], y, z) + 10
cand2 = dfs(index+1, x, y+l[index], z) + 10
cand3 = dfs(index+1, x, y, z+l[index]) + 10
cand4 = dfs(index+1, x, y, z)
return min(cand1, cand2, cand3, cand4)
print((dfs(0, 0, 0, 0)))
| 29 | 16 | 680 | 475 | n, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
ans = 3000
for bits in range(4**n):
xa = xb = xc = 0
tmp_ans = 0
for i in range(n):
f = (bits // (4**i)) % 4
if f == 1:
if xa != 0:
tmp_ans += 10
xa += l[i]
elif f == 2:
if xb != 0:
tmp_ans += 10
xb += l[i]
elif f == 3:
if xc != 0:
tmp_ans += 10
xc += l[i]
if xa == 0 or xb == 0 or xc == 0:
continue
tmp_ans += abs(a - xa) + abs(b - xb) + abs(c - xc)
ans = min(ans, tmp_ans)
print(ans)
| n, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
INF = 10**9
def dfs(index, x, y, z):
if index == n:
return abs(a - x) + abs(b - y) + abs(c - z) - 30 if min(x, y, z) > 0 else INF
cand1 = dfs(index + 1, x + l[index], y, z) + 10
cand2 = dfs(index + 1, x, y + l[index], z) + 10
cand3 = dfs(index + 1, x, y, z + l[index]) + 10
cand4 = dfs(index + 1, x, y, z)
return min(cand1, cand2, cand3, cand4)
print((dfs(0, 0, 0, 0)))
| false | 44.827586 | [
"-ans = 3000",
"-for bits in range(4**n):",
"- xa = xb = xc = 0",
"- tmp_ans = 0",
"- for i in range(n):",
"- f = (bits // (4**i)) % 4",
"- if f == 1:",
"- if xa != 0:",
"- tmp_ans += 10",
"- xa += l[i]",
"- elif f == 2:",
"- if xb != 0:",
"- tmp_ans += 10",
"- xb += l[i]",
"- elif f == 3:",
"- if xc != 0:",
"- tmp_ans += 10",
"- xc += l[i]",
"- if xa == 0 or xb == 0 or xc == 0:",
"- continue",
"- tmp_ans += abs(a - xa) + abs(b - xb) + abs(c - xc)",
"- ans = min(ans, tmp_ans)",
"-print(ans)",
"+INF = 10**9",
"+",
"+",
"+def dfs(index, x, y, z):",
"+ if index == n:",
"+ return abs(a - x) + abs(b - y) + abs(c - z) - 30 if min(x, y, z) > 0 else INF",
"+ cand1 = dfs(index + 1, x + l[index], y, z) + 10",
"+ cand2 = dfs(index + 1, x, y + l[index], z) + 10",
"+ cand3 = dfs(index + 1, x, y, z + l[index]) + 10",
"+ cand4 = dfs(index + 1, x, y, z)",
"+ return min(cand1, cand2, cand3, cand4)",
"+",
"+",
"+print((dfs(0, 0, 0, 0)))"
] | false | 0.40253 | 0.089098 | 4.517823 | [
"s717616682",
"s567740627"
] |
u545368057 | p03612 | python | s803448324 | s010004552 | 78 | 71 | 14,008 | 20,540 | Accepted | Accepted | 8.97 | N = int(eval(input()))
ps = list(map(int,input().split()))
# p_swap = [-1]*N
ans = 0
for i in range(N-1):
if i+1 == ps[i]:
p1,p2 = ps[i:i+2]
ps[i] = p2
ps[i+1] = p1
ans += 1
if ps[N-1] == N:
ans += 1
print(ans) | # 前から順番に後ろに向けてswap
n = int(eval(input()))
ps = list(map(int, input().split()))
cnt = 0
for i in range(n-1):
if i + 1 == ps[i]:
tmp = ps[i]
ps[i] = ps[i+1]
ps[i+1] = tmp
cnt += 1
# 最後残っていたら直前とswap
if ps[n-1] == n:
cnt += 1
print(cnt)
| 13 | 16 | 256 | 284 | N = int(eval(input()))
ps = list(map(int, input().split()))
# p_swap = [-1]*N
ans = 0
for i in range(N - 1):
if i + 1 == ps[i]:
p1, p2 = ps[i : i + 2]
ps[i] = p2
ps[i + 1] = p1
ans += 1
if ps[N - 1] == N:
ans += 1
print(ans)
| # 前から順番に後ろに向けてswap
n = int(eval(input()))
ps = list(map(int, input().split()))
cnt = 0
for i in range(n - 1):
if i + 1 == ps[i]:
tmp = ps[i]
ps[i] = ps[i + 1]
ps[i + 1] = tmp
cnt += 1
# 最後残っていたら直前とswap
if ps[n - 1] == n:
cnt += 1
print(cnt)
| false | 18.75 | [
"-N = int(eval(input()))",
"+# 前から順番に後ろに向けてswap",
"+n = int(eval(input()))",
"-# p_swap = [-1]*N",
"-ans = 0",
"-for i in range(N - 1):",
"+cnt = 0",
"+for i in range(n - 1):",
"- p1, p2 = ps[i : i + 2]",
"- ps[i] = p2",
"- ps[i + 1] = p1",
"- ans += 1",
"-if ps[N - 1] == N:",
"- ans += 1",
"-print(ans)",
"+ tmp = ps[i]",
"+ ps[i] = ps[i + 1]",
"+ ps[i + 1] = tmp",
"+ cnt += 1",
"+# 最後残っていたら直前とswap",
"+if ps[n - 1] == n:",
"+ cnt += 1",
"+print(cnt)"
] | false | 0.040901 | 0.147908 | 0.276533 | [
"s803448324",
"s010004552"
] |
u757030836 | p03086 | python | s927251444 | s381761464 | 21 | 19 | 3,188 | 3,188 | Accepted | Accepted | 9.52 | import re
print((max(list(map(len,re.findall("[ACGT]*",eval(input()))))))) | import re
s = eval(input())
print((max(list(map(len,re.split("[^ACGT]",s)))))) | 2 | 4 | 61 | 68 | import re
print((max(list(map(len, re.findall("[ACGT]*", eval(input())))))))
| import re
s = eval(input())
print((max(list(map(len, re.split("[^ACGT]", s))))))
| false | 50 | [
"-print((max(list(map(len, re.findall(\"[ACGT]*\", eval(input())))))))",
"+s = eval(input())",
"+print((max(list(map(len, re.split(\"[^ACGT]\", s))))))"
] | false | 0.196008 | 0.119426 | 1.641254 | [
"s927251444",
"s381761464"
] |
u902151549 | p03078 | python | s049186741 | s813942400 | 778 | 133 | 142,120 | 8,708 | Accepted | Accepted | 82.9 | import math
xyzk = list(map(int,input().split()))
abc = [list(map(int,input().split())) for a in range(3)]
ab=[]
for a in abc[0]:
for b in abc[1]:
ab.append(a+b)
ab.sort()
ab.reverse()
abc[2].sort()
abc[2].reverse()
abc2=[]
for c in range(len(abc[2])):
for a in range(min([math.ceil(xyzk[3]),len(ab)])):
abc2.append(abc[2][c]+ab[a])
abc2.sort()
abc2.reverse()
for a in range(xyzk[3]):
print((abc2[a])) | import math
xyzk = list(map(int,input().split()))
abc = [list(map(int,input().split())) for a in range(3)]
for a in range(3):
abc[a].sort()
abc[a].reverse()
abc2=[]
for a in range(len(abc[0])):
for b in range(len(abc[1])):
if (a+1)*(b+1)>xyzk[3]:
break
for c in range(len(abc[2])):
if (a+1)*(b+1)*(c+1)>xyzk[3] :
break
abc2.append(abc[0][a]+abc[1][b]+abc[2][c])
abc2.sort()
abc2.reverse()
for a in range(xyzk[3]):
print((abc2[a])) | 19 | 19 | 445 | 530 | import math
xyzk = list(map(int, input().split()))
abc = [list(map(int, input().split())) for a in range(3)]
ab = []
for a in abc[0]:
for b in abc[1]:
ab.append(a + b)
ab.sort()
ab.reverse()
abc[2].sort()
abc[2].reverse()
abc2 = []
for c in range(len(abc[2])):
for a in range(min([math.ceil(xyzk[3]), len(ab)])):
abc2.append(abc[2][c] + ab[a])
abc2.sort()
abc2.reverse()
for a in range(xyzk[3]):
print((abc2[a]))
| import math
xyzk = list(map(int, input().split()))
abc = [list(map(int, input().split())) for a in range(3)]
for a in range(3):
abc[a].sort()
abc[a].reverse()
abc2 = []
for a in range(len(abc[0])):
for b in range(len(abc[1])):
if (a + 1) * (b + 1) > xyzk[3]:
break
for c in range(len(abc[2])):
if (a + 1) * (b + 1) * (c + 1) > xyzk[3]:
break
abc2.append(abc[0][a] + abc[1][b] + abc[2][c])
abc2.sort()
abc2.reverse()
for a in range(xyzk[3]):
print((abc2[a]))
| false | 0 | [
"-ab = []",
"-for a in abc[0]:",
"- for b in abc[1]:",
"- ab.append(a + b)",
"-ab.sort()",
"-ab.reverse()",
"-abc[2].sort()",
"-abc[2].reverse()",
"+for a in range(3):",
"+ abc[a].sort()",
"+ abc[a].reverse()",
"-for c in range(len(abc[2])):",
"- for a in range(min([math.ceil(xyzk[3]), len(ab)])):",
"- abc2.append(abc[2][c] + ab[a])",
"+for a in range(len(abc[0])):",
"+ for b in range(len(abc[1])):",
"+ if (a + 1) * (b + 1) > xyzk[3]:",
"+ break",
"+ for c in range(len(abc[2])):",
"+ if (a + 1) * (b + 1) * (c + 1) > xyzk[3]:",
"+ break",
"+ abc2.append(abc[0][a] + abc[1][b] + abc[2][c])"
] | false | 0.045497 | 0.116615 | 0.390147 | [
"s049186741",
"s813942400"
] |
u488178971 | p02819 | python | s715415791 | s664564477 | 230 | 18 | 7,576 | 3,060 | Accepted | Accepted | 92.17 | X = int(eval(input()))
import math
def get_prime(n):
if n <=1:
return []
prime = [2]
limit = int(math.sqrt(n))
# 奇数のリストを作成
data = [i+1 for i in range(2,n,2)]
while limit > data[0]:
prime.append(data[0])
data = [j for j in data if j % data[0] !=0]
return prime + data
for x in get_prime(2*X):
if x >=X:
print(x)
break
| X = int(eval(input()))
def is_prime(n):
if n <= 1:
return False
for i in range(2,int(n**0.5)+1):
if n % i ==0:
return False
return True
for i in range(X,(X*2)+100,):
if is_prime(i):
print(i)
break
| 20 | 15 | 414 | 283 | X = int(eval(input()))
import math
def get_prime(n):
if n <= 1:
return []
prime = [2]
limit = int(math.sqrt(n))
# 奇数のリストを作成
data = [i + 1 for i in range(2, n, 2)]
while limit > data[0]:
prime.append(data[0])
data = [j for j in data if j % data[0] != 0]
return prime + data
for x in get_prime(2 * X):
if x >= X:
print(x)
break
| X = int(eval(input()))
def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
for i in range(
X,
(X * 2) + 100,
):
if is_prime(i):
print(i)
break
| false | 25 | [
"-import math",
"-def get_prime(n):",
"+def is_prime(n):",
"- return []",
"- prime = [2]",
"- limit = int(math.sqrt(n))",
"- # 奇数のリストを作成",
"- data = [i + 1 for i in range(2, n, 2)]",
"- while limit > data[0]:",
"- prime.append(data[0])",
"- data = [j for j in data if j % data[0] != 0]",
"- return prime + data",
"+ return False",
"+ for i in range(2, int(n**0.5) + 1):",
"+ if n % i == 0:",
"+ return False",
"+ return True",
"-for x in get_prime(2 * X):",
"- if x >= X:",
"- print(x)",
"+for i in range(",
"+ X,",
"+ (X * 2) + 100,",
"+):",
"+ if is_prime(i):",
"+ print(i)"
] | false | 0.178061 | 0.036816 | 4.83653 | [
"s715415791",
"s664564477"
] |
u368796742 | p02703 | python | s484165848 | s059418361 | 1,010 | 567 | 99,456 | 26,236 | Accepted | Accepted | 43.86 | def main():
import heapq
def dijkstra(graph,start,cd,s):
dist = [[float("inf")]*2505 for _ in range(n)]
q = []
dist[start][s] = 0
heapq.heappush(q, (0,start,s))
while q:
cost, cur_node,coin = heapq.heappop(q)
if dist[cur_node][coin] < cost:
continue
for nex_node,nex_cost,nex_time in graph[cur_node]:
if coin >= nex_cost and dist[nex_node][coin-nex_cost] > cost+nex_time:
dist[nex_node][coin-nex_cost] = cost+nex_time
heapq.heappush(q, (cost+nex_time,nex_node,coin-nex_cost))
if dist[cur_node][min(2500,coin+cd[cur_node][0])] > cost+cd[cur_node][1]:
dist[cur_node][min(2500,coin+cd[cur_node][0])] = cost+cd[cur_node][1]
heapq.heappush(q,(cost+cd[cur_node][1],cur_node,min(2500,coin+cd[cur_node][0])))
for i in dist[1:]:
print((min(i)))
n,m,s = list(map(int,input().split()))
E = [[] for i in range(n)]
la = []
for i in range(m):
u,v,a,b = list(map(int,input().split()))
u -= 1
v-= 1
la.append(a)
E[u].append((v,a,b))
E[v].append((u,a,b))
cd = [list(map(int,input().split())) for i in range(n)]
dijkstra(E,0,cd,min(s,2500))
if __name__ == "__main__":
main() | def main():
import heapq
def dijkstra(graph,s,cd,c):
dist = [[float("inf")]*2505 for _ in range(n)]
q = []
dist[s][c] = 0
heapq.heappush(q, (0,s,c))
while q:
d, p,c = heapq.heappop(q)
if dist[p][c] < d:
continue
for nn,nc,nt in graph[p]:
if c >= nc and dist[nn][c-nc] > d+nt:
dist[nn][c-nc] = d+nt
heapq.heappush(q,(d+nt,nn,c-nc))
if c+cd[p][0] < 2500:
if dist[p][c+cd[p][0]] > d+cd[p][1]:
dist[p][c+cd[p][0]] = d+cd[p][1]
heapq.heappush(q, (d+cd[p][1],p,c+cd[p][0]))
else:
if dist[p][2500] > d+cd[p][1]:
dist[p][2500] = d+cd[p][1]
heapq.heappush(q, (d+cd[p][1],p,2500))
for i in dist[1:]:
print((min(i)))
n,m,s = list(map(int,input().split()))
E = [[] for i in range(n)]
la = []
for i in range(m):
u,v,a,b = list(map(int,input().split()))
u -= 1
v-= 1
la.append(a)
E[u].append((v,a,b))
E[v].append((u,a,b))
cd = [list(map(int,input().split())) for i in range(n)]
dijkstra(E,0,cd,min(s,2500))
if __name__ == "__main__":
main() | 41 | 46 | 1,444 | 1,416 | def main():
import heapq
def dijkstra(graph, start, cd, s):
dist = [[float("inf")] * 2505 for _ in range(n)]
q = []
dist[start][s] = 0
heapq.heappush(q, (0, start, s))
while q:
cost, cur_node, coin = heapq.heappop(q)
if dist[cur_node][coin] < cost:
continue
for nex_node, nex_cost, nex_time in graph[cur_node]:
if (
coin >= nex_cost
and dist[nex_node][coin - nex_cost] > cost + nex_time
):
dist[nex_node][coin - nex_cost] = cost + nex_time
heapq.heappush(q, (cost + nex_time, nex_node, coin - nex_cost))
if (
dist[cur_node][min(2500, coin + cd[cur_node][0])]
> cost + cd[cur_node][1]
):
dist[cur_node][min(2500, coin + cd[cur_node][0])] = (
cost + cd[cur_node][1]
)
heapq.heappush(
q,
(
cost + cd[cur_node][1],
cur_node,
min(2500, coin + cd[cur_node][0]),
),
)
for i in dist[1:]:
print((min(i)))
n, m, s = list(map(int, input().split()))
E = [[] for i in range(n)]
la = []
for i in range(m):
u, v, a, b = list(map(int, input().split()))
u -= 1
v -= 1
la.append(a)
E[u].append((v, a, b))
E[v].append((u, a, b))
cd = [list(map(int, input().split())) for i in range(n)]
dijkstra(E, 0, cd, min(s, 2500))
if __name__ == "__main__":
main()
| def main():
import heapq
def dijkstra(graph, s, cd, c):
dist = [[float("inf")] * 2505 for _ in range(n)]
q = []
dist[s][c] = 0
heapq.heappush(q, (0, s, c))
while q:
d, p, c = heapq.heappop(q)
if dist[p][c] < d:
continue
for nn, nc, nt in graph[p]:
if c >= nc and dist[nn][c - nc] > d + nt:
dist[nn][c - nc] = d + nt
heapq.heappush(q, (d + nt, nn, c - nc))
if c + cd[p][0] < 2500:
if dist[p][c + cd[p][0]] > d + cd[p][1]:
dist[p][c + cd[p][0]] = d + cd[p][1]
heapq.heappush(q, (d + cd[p][1], p, c + cd[p][0]))
else:
if dist[p][2500] > d + cd[p][1]:
dist[p][2500] = d + cd[p][1]
heapq.heappush(q, (d + cd[p][1], p, 2500))
for i in dist[1:]:
print((min(i)))
n, m, s = list(map(int, input().split()))
E = [[] for i in range(n)]
la = []
for i in range(m):
u, v, a, b = list(map(int, input().split()))
u -= 1
v -= 1
la.append(a)
E[u].append((v, a, b))
E[v].append((u, a, b))
cd = [list(map(int, input().split())) for i in range(n)]
dijkstra(E, 0, cd, min(s, 2500))
if __name__ == "__main__":
main()
| false | 10.869565 | [
"- def dijkstra(graph, start, cd, s):",
"+ def dijkstra(graph, s, cd, c):",
"- dist[start][s] = 0",
"- heapq.heappush(q, (0, start, s))",
"+ dist[s][c] = 0",
"+ heapq.heappush(q, (0, s, c))",
"- cost, cur_node, coin = heapq.heappop(q)",
"- if dist[cur_node][coin] < cost:",
"+ d, p, c = heapq.heappop(q)",
"+ if dist[p][c] < d:",
"- for nex_node, nex_cost, nex_time in graph[cur_node]:",
"- if (",
"- coin >= nex_cost",
"- and dist[nex_node][coin - nex_cost] > cost + nex_time",
"- ):",
"- dist[nex_node][coin - nex_cost] = cost + nex_time",
"- heapq.heappush(q, (cost + nex_time, nex_node, coin - nex_cost))",
"- if (",
"- dist[cur_node][min(2500, coin + cd[cur_node][0])]",
"- > cost + cd[cur_node][1]",
"- ):",
"- dist[cur_node][min(2500, coin + cd[cur_node][0])] = (",
"- cost + cd[cur_node][1]",
"- )",
"- heapq.heappush(",
"- q,",
"- (",
"- cost + cd[cur_node][1],",
"- cur_node,",
"- min(2500, coin + cd[cur_node][0]),",
"- ),",
"- )",
"+ for nn, nc, nt in graph[p]:",
"+ if c >= nc and dist[nn][c - nc] > d + nt:",
"+ dist[nn][c - nc] = d + nt",
"+ heapq.heappush(q, (d + nt, nn, c - nc))",
"+ if c + cd[p][0] < 2500:",
"+ if dist[p][c + cd[p][0]] > d + cd[p][1]:",
"+ dist[p][c + cd[p][0]] = d + cd[p][1]",
"+ heapq.heappush(q, (d + cd[p][1], p, c + cd[p][0]))",
"+ else:",
"+ if dist[p][2500] > d + cd[p][1]:",
"+ dist[p][2500] = d + cd[p][1]",
"+ heapq.heappush(q, (d + cd[p][1], p, 2500))"
] | false | 0.122137 | 0.204051 | 0.598563 | [
"s484165848",
"s059418361"
] |
u596276291 | p03425 | python | s673157180 | s026930183 | 454 | 177 | 12,028 | 3,956 | Accepted | Accepted | 61.01 | from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
INF = float("inf")
import sys
sys.setrecursionlimit(10000)
def solve(N, S):
d = Counter([s[0] for s in S if s[0] in "MARCH"])
ans = 0
for comb in combinations("MARCH", 3):
a = 1
for c in comb:
a *= d[c]
ans += a
return ans
def main():
N = int(eval(input()))
S = []
for i in range(0, N):
S.append(eval(input()))
print((solve(N, S)))
if __name__ == '__main__':
main()
| #!/usr/bin/python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def main():
N = int(eval(input()))
d = defaultdict(int)
for _ in range(N):
s = eval(input())
d[s[0]] += 1
ans = 0
for a in combinations("MARCH", 3):
ans += d[a[0]] * d[a[1]] * d[a[2]]
print(ans)
if __name__ == '__main__':
main()
| 33 | 36 | 765 | 853 | from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
INF = float("inf")
import sys
sys.setrecursionlimit(10000)
def solve(N, S):
d = Counter([s[0] for s in S if s[0] in "MARCH"])
ans = 0
for comb in combinations("MARCH", 3):
a = 1
for c in comb:
a *= d[c]
ans += a
return ans
def main():
N = int(eval(input()))
S = []
for i in range(0, N):
S.append(eval(input()))
print((solve(N, S)))
if __name__ == "__main__":
main()
| #!/usr/bin/python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def main():
N = int(eval(input()))
d = defaultdict(int)
for _ in range(N):
s = eval(input())
d[s[0]] += 1
ans = 0
for a in combinations("MARCH", 3):
ans += d[a[0]] * d[a[1]] * d[a[2]]
print(ans)
if __name__ == "__main__":
main()
| false | 8.333333 | [
"+#!/usr/bin/python3",
"-",
"-INF = float(\"inf\")",
"+INF = float(\"inf\")",
"+YES, Yes, yes, NO, No, no = \"YES\", \"Yes\", \"yes\", \"NO\", \"No\", \"no\"",
"+dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]",
"-def solve(N, S):",
"- d = Counter([s[0] for s in S if s[0] in \"MARCH\"])",
"- ans = 0",
"- for comb in combinations(\"MARCH\", 3):",
"- a = 1",
"- for c in comb:",
"- a *= d[c]",
"- ans += a",
"- return ans",
"+def inside(y, x, H, W):",
"+ return 0 <= y < H and 0 <= x < W",
"- S = []",
"- for i in range(0, N):",
"- S.append(eval(input()))",
"- print((solve(N, S)))",
"+ d = defaultdict(int)",
"+ for _ in range(N):",
"+ s = eval(input())",
"+ d[s[0]] += 1",
"+ ans = 0",
"+ for a in combinations(\"MARCH\", 3):",
"+ ans += d[a[0]] * d[a[1]] * d[a[2]]",
"+ print(ans)"
] | false | 0.037161 | 0.007331 | 5.0687 | [
"s673157180",
"s026930183"
] |
u994988729 | p03111 | python | s120794933 | s786305223 | 388 | 273 | 3,064 | 3,064 | Accepted | Accepted | 29.64 | from itertools import product
n,a,b,c=list(map(int,input().split()))
abc=[a,b,c]
l=tuple(int(eval(input())) for _ in range(n))
ans=10**18
for a in product(list(range(4)), repeat=n):
MP=0
take=[[] for _ in range(4)]
for i in range(n):
take[a[i]].append(l[i])
if take[0] and take[1] and take[2]:
for i,t in enumerate(take[:-1]):
MP+=max(0, 10*(len(t)-1))
MP+=abs(abc[i] - sum(t))
else:
continue
ans=min(ans, MP)
print(ans)
| from itertools import product
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
ans = 10 ** 18
for alloc in product(list(range(4)), repeat=N):
La = 0
Lb = 0
Lc = 0
use_a = 0
use_b = 0
use_c = 0
for i, f in enumerate(alloc):
if f == 0:
La += L[i]
use_a += 1
elif f == 1:
Lb += L[i]
use_b += 1
elif f == 2:
Lc += L[i]
use_c += 1
else:
pass
if not all([use_a, use_b, use_c]):
continue
score = 0
score += 10 * (use_a - 1)
score += 10 * (use_b - 1)
score += 10 * (use_c - 1)
score += abs(A - La)
score += abs(B - Lb)
score += abs(C - Lc)
ans = min(ans, score)
print(ans) | 23 | 42 | 507 | 895 | from itertools import product
n, a, b, c = list(map(int, input().split()))
abc = [a, b, c]
l = tuple(int(eval(input())) for _ in range(n))
ans = 10**18
for a in product(list(range(4)), repeat=n):
MP = 0
take = [[] for _ in range(4)]
for i in range(n):
take[a[i]].append(l[i])
if take[0] and take[1] and take[2]:
for i, t in enumerate(take[:-1]):
MP += max(0, 10 * (len(t) - 1))
MP += abs(abc[i] - sum(t))
else:
continue
ans = min(ans, MP)
print(ans)
| from itertools import product
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
N, A, B, C = list(map(int, input().split()))
L = [int(eval(input())) for _ in range(N)]
ans = 10**18
for alloc in product(list(range(4)), repeat=N):
La = 0
Lb = 0
Lc = 0
use_a = 0
use_b = 0
use_c = 0
for i, f in enumerate(alloc):
if f == 0:
La += L[i]
use_a += 1
elif f == 1:
Lb += L[i]
use_b += 1
elif f == 2:
Lc += L[i]
use_c += 1
else:
pass
if not all([use_a, use_b, use_c]):
continue
score = 0
score += 10 * (use_a - 1)
score += 10 * (use_b - 1)
score += 10 * (use_c - 1)
score += abs(A - La)
score += abs(B - Lb)
score += abs(C - Lc)
ans = min(ans, score)
print(ans)
| false | 45.238095 | [
"+import sys",
"-n, a, b, c = list(map(int, input().split()))",
"-abc = [a, b, c]",
"-l = tuple(int(eval(input())) for _ in range(n))",
"+input = sys.stdin.buffer.readline",
"+sys.setrecursionlimit(10**7)",
"+N, A, B, C = list(map(int, input().split()))",
"+L = [int(eval(input())) for _ in range(N)]",
"-for a in product(list(range(4)), repeat=n):",
"- MP = 0",
"- take = [[] for _ in range(4)]",
"- for i in range(n):",
"- take[a[i]].append(l[i])",
"- if take[0] and take[1] and take[2]:",
"- for i, t in enumerate(take[:-1]):",
"- MP += max(0, 10 * (len(t) - 1))",
"- MP += abs(abc[i] - sum(t))",
"- else:",
"+for alloc in product(list(range(4)), repeat=N):",
"+ La = 0",
"+ Lb = 0",
"+ Lc = 0",
"+ use_a = 0",
"+ use_b = 0",
"+ use_c = 0",
"+ for i, f in enumerate(alloc):",
"+ if f == 0:",
"+ La += L[i]",
"+ use_a += 1",
"+ elif f == 1:",
"+ Lb += L[i]",
"+ use_b += 1",
"+ elif f == 2:",
"+ Lc += L[i]",
"+ use_c += 1",
"+ else:",
"+ pass",
"+ if not all([use_a, use_b, use_c]):",
"- ans = min(ans, MP)",
"+ score = 0",
"+ score += 10 * (use_a - 1)",
"+ score += 10 * (use_b - 1)",
"+ score += 10 * (use_c - 1)",
"+ score += abs(A - La)",
"+ score += abs(B - Lb)",
"+ score += abs(C - Lc)",
"+ ans = min(ans, score)"
] | false | 0.249262 | 0.49926 | 0.499262 | [
"s120794933",
"s786305223"
] |
u600402037 | p03456 | python | s719689928 | s630266968 | 20 | 17 | 2,940 | 2,940 | Accepted | Accepted | 15 | a,b=input().split()
print(('Yes' if (int(a+b)**.5).is_integer() else 'No')) | print(('No' if int(input().replace(' ',''))**.5%1 else 'Yes')) | 2 | 1 | 74 | 60 | a, b = input().split()
print(("Yes" if (int(a + b) ** 0.5).is_integer() else "No"))
| print(("No" if int(input().replace(" ", "")) ** 0.5 % 1 else "Yes"))
| false | 50 | [
"-a, b = input().split()",
"-print((\"Yes\" if (int(a + b) ** 0.5).is_integer() else \"No\"))",
"+print((\"No\" if int(input().replace(\" \", \"\")) ** 0.5 % 1 else \"Yes\"))"
] | false | 0.074231 | 0.069325 | 1.07077 | [
"s719689928",
"s630266968"
] |
u600402037 | p02886 | python | s370748348 | s855987778 | 301 | 147 | 21,496 | 12,488 | Accepted | Accepted | 51.16 | import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
D = np.array(lr())
recover = D[:, None] * D[None, :]
np.fill_diagonal(recover, 0)
answer = recover.sum() // 2
print(answer)
| import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
D = np.array(lr())
recover = D[:, None] * D[None, :]
answer = recover.sum() - np.diag(recover).sum()
print((answer // 2))
| 13 | 12 | 285 | 280 | import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
D = np.array(lr())
recover = D[:, None] * D[None, :]
np.fill_diagonal(recover, 0)
answer = recover.sum() // 2
print(answer)
| import sys
import numpy as np
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
D = np.array(lr())
recover = D[:, None] * D[None, :]
answer = recover.sum() - np.diag(recover).sum()
print((answer // 2))
| false | 7.692308 | [
"-np.fill_diagonal(recover, 0)",
"-answer = recover.sum() // 2",
"-print(answer)",
"+answer = recover.sum() - np.diag(recover).sum()",
"+print((answer // 2))"
] | false | 0.218973 | 0.229043 | 0.956036 | [
"s370748348",
"s855987778"
] |
u852690916 | p03994 | python | s084820531 | s361797301 | 208 | 183 | 55,408 | 46,832 | Accepted | Accepted | 12.02 | s = eval(input())
K = int(eval(input()))
c = [ord(s1)-ord('a') for s1 in s]
sl = list(s)
for i in range(len(s)):
if c[i] and 26-c[i] <= K:
sl[i] = 'a'
K -= 26-c[i]
sl[len(s)-1] = chr((ord(sl[len(s)-1]) - ord('a') + K) % 26 + ord('a'))
print((''.join(sl))) | import sys
def main():
input = sys.stdin.readline
s = input().rstrip()
K = int(eval(input()))
def c(x): return ord(x) - ord('a')
def d(x): return chr(x + ord('a'))
ans = []
i = 0
while i < (len(s) - 1):
to_a = (26 - c(s[i])) % 26
if to_a <= K:
ans.append('a')
K -= to_a
else:
ans.append(s[i])
i += 1
if K > 0:
ans.append(d((c(s[-1]) + K) % 26))
else:
ans.append(s[i])
print((''.join(ans)))
if __name__ == '__main__':
main() | 13 | 26 | 276 | 574 | s = eval(input())
K = int(eval(input()))
c = [ord(s1) - ord("a") for s1 in s]
sl = list(s)
for i in range(len(s)):
if c[i] and 26 - c[i] <= K:
sl[i] = "a"
K -= 26 - c[i]
sl[len(s) - 1] = chr((ord(sl[len(s) - 1]) - ord("a") + K) % 26 + ord("a"))
print(("".join(sl)))
| import sys
def main():
input = sys.stdin.readline
s = input().rstrip()
K = int(eval(input()))
def c(x):
return ord(x) - ord("a")
def d(x):
return chr(x + ord("a"))
ans = []
i = 0
while i < (len(s) - 1):
to_a = (26 - c(s[i])) % 26
if to_a <= K:
ans.append("a")
K -= to_a
else:
ans.append(s[i])
i += 1
if K > 0:
ans.append(d((c(s[-1]) + K) % 26))
else:
ans.append(s[i])
print(("".join(ans)))
if __name__ == "__main__":
main()
| false | 50 | [
"-s = eval(input())",
"-K = int(eval(input()))",
"-c = [ord(s1) - ord(\"a\") for s1 in s]",
"-sl = list(s)",
"-for i in range(len(s)):",
"- if c[i] and 26 - c[i] <= K:",
"- sl[i] = \"a\"",
"- K -= 26 - c[i]",
"-sl[len(s) - 1] = chr((ord(sl[len(s) - 1]) - ord(\"a\") + K) % 26 + ord(\"a\"))",
"-print((\"\".join(sl)))",
"+import sys",
"+",
"+",
"+def main():",
"+ input = sys.stdin.readline",
"+ s = input().rstrip()",
"+ K = int(eval(input()))",
"+",
"+ def c(x):",
"+ return ord(x) - ord(\"a\")",
"+",
"+ def d(x):",
"+ return chr(x + ord(\"a\"))",
"+",
"+ ans = []",
"+ i = 0",
"+ while i < (len(s) - 1):",
"+ to_a = (26 - c(s[i])) % 26",
"+ if to_a <= K:",
"+ ans.append(\"a\")",
"+ K -= to_a",
"+ else:",
"+ ans.append(s[i])",
"+ i += 1",
"+ if K > 0:",
"+ ans.append(d((c(s[-1]) + K) % 26))",
"+ else:",
"+ ans.append(s[i])",
"+ print((\"\".join(ans)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.076436 | 0.09525 | 0.802483 | [
"s084820531",
"s361797301"
] |
u759412327 | p03574 | python | s216427089 | s812047631 | 34 | 27 | 9,340 | 9,164 | Accepted | Accepted | 20.59 | import itertools
H,W = map(int,input().split())
S = [input() for h in range(H)]
a = [[0 if cell=="." else "#" for cell in row] for row in S]
for h in range(H):
for w in range(W):
if S[h][w]!="#":
continue
for dx,dy in itertools.product([-1,0,1],repeat=2):
x = h+dx
y = w+dy
if x<0 or H<=x:
continue
if y<0 or W<=y:
continue
if S[x][y]=="#":
continue
a[x][y]+=1
for row in a:
print(*row,sep="")
| H,W = list(map(int,input().split()))
S = [(2+W)*"."]+["."+eval(input())+"." for h in range(H)]+[(2+W)*"."]
for h in range(1,1+H):
for w in range(1,1+W):
if S[h][w]!="#":
s = S[h-1][w-1:w+2]+S[h][w-1]+S[h][w+1]+S[h+1][w-1:w+2]
S[h]=S[h][:w]+str(s.count("#"))+S[h][w+1:]
for h in range(1,1+H):
print((S[h][1:1+W])) | 22 | 11 | 494 | 330 | import itertools
H, W = map(int, input().split())
S = [input() for h in range(H)]
a = [[0 if cell == "." else "#" for cell in row] for row in S]
for h in range(H):
for w in range(W):
if S[h][w] != "#":
continue
for dx, dy in itertools.product([-1, 0, 1], repeat=2):
x = h + dx
y = w + dy
if x < 0 or H <= x:
continue
if y < 0 or W <= y:
continue
if S[x][y] == "#":
continue
a[x][y] += 1
for row in a:
print(*row, sep="")
| H, W = list(map(int, input().split()))
S = [(2 + W) * "."] + ["." + eval(input()) + "." for h in range(H)] + [(2 + W) * "."]
for h in range(1, 1 + H):
for w in range(1, 1 + W):
if S[h][w] != "#":
s = (
S[h - 1][w - 1 : w + 2]
+ S[h][w - 1]
+ S[h][w + 1]
+ S[h + 1][w - 1 : w + 2]
)
S[h] = S[h][:w] + str(s.count("#")) + S[h][w + 1 :]
for h in range(1, 1 + H):
print((S[h][1 : 1 + W]))
| false | 50 | [
"-import itertools",
"-",
"-H, W = map(int, input().split())",
"-S = [input() for h in range(H)]",
"-a = [[0 if cell == \".\" else \"#\" for cell in row] for row in S]",
"-for h in range(H):",
"- for w in range(W):",
"+H, W = list(map(int, input().split()))",
"+S = [(2 + W) * \".\"] + [\".\" + eval(input()) + \".\" for h in range(H)] + [(2 + W) * \".\"]",
"+for h in range(1, 1 + H):",
"+ for w in range(1, 1 + W):",
"- continue",
"- for dx, dy in itertools.product([-1, 0, 1], repeat=2):",
"- x = h + dx",
"- y = w + dy",
"- if x < 0 or H <= x:",
"- continue",
"- if y < 0 or W <= y:",
"- continue",
"- if S[x][y] == \"#\":",
"- continue",
"- a[x][y] += 1",
"-for row in a:",
"- print(*row, sep=\"\")",
"+ s = (",
"+ S[h - 1][w - 1 : w + 2]",
"+ + S[h][w - 1]",
"+ + S[h][w + 1]",
"+ + S[h + 1][w - 1 : w + 2]",
"+ )",
"+ S[h] = S[h][:w] + str(s.count(\"#\")) + S[h][w + 1 :]",
"+for h in range(1, 1 + H):",
"+ print((S[h][1 : 1 + W]))"
] | false | 0.043151 | 0.084246 | 0.512198 | [
"s216427089",
"s812047631"
] |
u380524497 | p02750 | python | s070048107 | s856594318 | 1,587 | 593 | 58,592 | 95,632 | Accepted | Accepted | 62.63 | def main():
import itertools
import sys
buf = sys.stdin.buffer
n, t = list(map(int, buf.readline().split()))
m = list(map(int, buf.read().split()))
shops = []
shopsA0 = [0]
for a, b in zip(m, m):
if a == 0:
shopsA0.append(b + 1)
else:
shops.append([a, b])
shopsA0.sort()
shops.sort(reverse=True, key=lambda x: x[0]/(x[1]+1))
DP = [t+10] * 30
DP[0] = 0
for a, b in shops:
for num in range(28, -1, -1):
candidate = (DP[num]+1) * (a+1) + b
if candidate < DP[num+1]:
DP[num+1] = candidate
cumA0 = list(itertools.accumulate(shopsA0))
ans = [0]
count_A0 = len(cumA0) - 1
for count, spend_time in enumerate(DP):
residue = t - spend_time
if residue < 0:
break
while count_A0 > 0 and cumA0[count_A0] > residue:
count_A0 -= 1
ans.append(count_A0 + count)
print((max(ans)))
if __name__ == '__main__':
main() | def main():
import itertools
import sys
buf = sys.stdin.buffer
n, t = list(map(int, buf.readline().split()))
m = list(map(int, buf.read().split()))
shops = []
shopsA0 = [0]
for a, b in zip(m, m):
if a == 0:
shopsA0.append(b + 1)
else:
shops.append([a, b])
shopsA0.sort()
shops.sort(reverse=True, key=lambda x: x[0]/(x[1]+1))
DP = [t+10] * 30
DP[0] = 0
for a, b in shops:
for num in range(28, -1, -1):
candidate = (DP[num]+1) * (a+1) + b
if candidate < DP[num+1]:
DP[num+1] = candidate
cumA0 = list(itertools.accumulate(shopsA0))
ans = [0]
count_A = 28
for count, spend_time in enumerate(cumA0):
residue = t - spend_time
if residue < 0:
break
while DP[count_A] > residue:
count_A -= 1
ans.append(count_A + count)
print((max(ans)))
if __name__ == '__main__':
main() | 46 | 46 | 1,058 | 1,025 | def main():
import itertools
import sys
buf = sys.stdin.buffer
n, t = list(map(int, buf.readline().split()))
m = list(map(int, buf.read().split()))
shops = []
shopsA0 = [0]
for a, b in zip(m, m):
if a == 0:
shopsA0.append(b + 1)
else:
shops.append([a, b])
shopsA0.sort()
shops.sort(reverse=True, key=lambda x: x[0] / (x[1] + 1))
DP = [t + 10] * 30
DP[0] = 0
for a, b in shops:
for num in range(28, -1, -1):
candidate = (DP[num] + 1) * (a + 1) + b
if candidate < DP[num + 1]:
DP[num + 1] = candidate
cumA0 = list(itertools.accumulate(shopsA0))
ans = [0]
count_A0 = len(cumA0) - 1
for count, spend_time in enumerate(DP):
residue = t - spend_time
if residue < 0:
break
while count_A0 > 0 and cumA0[count_A0] > residue:
count_A0 -= 1
ans.append(count_A0 + count)
print((max(ans)))
if __name__ == "__main__":
main()
| def main():
import itertools
import sys
buf = sys.stdin.buffer
n, t = list(map(int, buf.readline().split()))
m = list(map(int, buf.read().split()))
shops = []
shopsA0 = [0]
for a, b in zip(m, m):
if a == 0:
shopsA0.append(b + 1)
else:
shops.append([a, b])
shopsA0.sort()
shops.sort(reverse=True, key=lambda x: x[0] / (x[1] + 1))
DP = [t + 10] * 30
DP[0] = 0
for a, b in shops:
for num in range(28, -1, -1):
candidate = (DP[num] + 1) * (a + 1) + b
if candidate < DP[num + 1]:
DP[num + 1] = candidate
cumA0 = list(itertools.accumulate(shopsA0))
ans = [0]
count_A = 28
for count, spend_time in enumerate(cumA0):
residue = t - spend_time
if residue < 0:
break
while DP[count_A] > residue:
count_A -= 1
ans.append(count_A + count)
print((max(ans)))
if __name__ == "__main__":
main()
| false | 0 | [
"- count_A0 = len(cumA0) - 1",
"- for count, spend_time in enumerate(DP):",
"+ count_A = 28",
"+ for count, spend_time in enumerate(cumA0):",
"- while count_A0 > 0 and cumA0[count_A0] > residue:",
"- count_A0 -= 1",
"- ans.append(count_A0 + count)",
"+ while DP[count_A] > residue:",
"+ count_A -= 1",
"+ ans.append(count_A + count)"
] | false | 0.032365 | 0.077658 | 0.416763 | [
"s070048107",
"s856594318"
] |
u223663729 | p02760 | python | s339404702 | s612782849 | 171 | 18 | 38,384 | 3,064 | Accepted | Accepted | 89.47 | def f():
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
A = a1+a2+a3
N = int(eval(input()))
c = [False]*9
for i in range(N):
b = int(eval(input()))
if b in A:
c[A.index(b)] = True
for i in range(3):
if c[i] and c[3+i] and c[6+i]:
return 'Yes'
elif c[3*i] and c[3*i+1] and c[3*i+2]:
return 'Yes'
if c[0] and c[4] and c[8]:
return 'Yes'
elif c[2] and c[4] and c[6]:
return 'Yes'
return 'No'
print((f())) | *A, = list(map(int, open(0).read().split()))
N = A[9]
B = A[10:]
A = A[:9]
T = [False]*9
for b in B:
if b in A:
T[A.index(b)] = True
bingo = [(0, 1, 2), (3, 4, 5), (6, 7, 8), (0, 3, 6),
(1, 4, 7), (2, 5, 8), (0, 4, 8), (2, 4, 6)]
for a, b, c in bingo:
if T[a] and T[b] and T[c]:
print('Yes')
break
else:
print('No')
| 28 | 20 | 548 | 378 | def f():
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
A = a1 + a2 + a3
N = int(eval(input()))
c = [False] * 9
for i in range(N):
b = int(eval(input()))
if b in A:
c[A.index(b)] = True
for i in range(3):
if c[i] and c[3 + i] and c[6 + i]:
return "Yes"
elif c[3 * i] and c[3 * i + 1] and c[3 * i + 2]:
return "Yes"
if c[0] and c[4] and c[8]:
return "Yes"
elif c[2] and c[4] and c[6]:
return "Yes"
return "No"
print((f()))
| (*A,) = list(map(int, open(0).read().split()))
N = A[9]
B = A[10:]
A = A[:9]
T = [False] * 9
for b in B:
if b in A:
T[A.index(b)] = True
bingo = [
(0, 1, 2),
(3, 4, 5),
(6, 7, 8),
(0, 3, 6),
(1, 4, 7),
(2, 5, 8),
(0, 4, 8),
(2, 4, 6),
]
for a, b, c in bingo:
if T[a] and T[b] and T[c]:
print("Yes")
break
else:
print("No")
| false | 28.571429 | [
"-def f():",
"- a1 = list(map(int, input().split()))",
"- a2 = list(map(int, input().split()))",
"- a3 = list(map(int, input().split()))",
"- A = a1 + a2 + a3",
"- N = int(eval(input()))",
"- c = [False] * 9",
"- for i in range(N):",
"- b = int(eval(input()))",
"- if b in A:",
"- c[A.index(b)] = True",
"- for i in range(3):",
"- if c[i] and c[3 + i] and c[6 + i]:",
"- return \"Yes\"",
"- elif c[3 * i] and c[3 * i + 1] and c[3 * i + 2]:",
"- return \"Yes\"",
"- if c[0] and c[4] and c[8]:",
"- return \"Yes\"",
"- elif c[2] and c[4] and c[6]:",
"- return \"Yes\"",
"- return \"No\"",
"-",
"-",
"-print((f()))",
"+(*A,) = list(map(int, open(0).read().split()))",
"+N = A[9]",
"+B = A[10:]",
"+A = A[:9]",
"+T = [False] * 9",
"+for b in B:",
"+ if b in A:",
"+ T[A.index(b)] = True",
"+bingo = [",
"+ (0, 1, 2),",
"+ (3, 4, 5),",
"+ (6, 7, 8),",
"+ (0, 3, 6),",
"+ (1, 4, 7),",
"+ (2, 5, 8),",
"+ (0, 4, 8),",
"+ (2, 4, 6),",
"+]",
"+for a, b, c in bingo:",
"+ if T[a] and T[b] and T[c]:",
"+ print(\"Yes\")",
"+ break",
"+else:",
"+ print(\"No\")"
] | false | 0.098472 | 0.036563 | 2.69317 | [
"s339404702",
"s612782849"
] |
u029315034 | p03946 | python | s927352454 | s345576117 | 119 | 97 | 14,244 | 14,244 | Accepted | Accepted | 18.49 | N, T = [int(v) for v in input().split()]
a = [int(v) for v in input().split()]
max_profit = 0
ans = 1
left = 0
right = 1
while right < N:
if a[left] < a[right]:
profit = a[right] - a[left]
if profit == max_profit:
ans += 1
else:
max_profit = max(max_profit, profit)
else:
left = right
right += 1
print(ans)
| N, T = [int(v) for v in input().split()]
a = [int(v) for v in input().split()]
max_profit = 0
ans = 1
left = 0
right = 1
min_a = a[0]
for i in range(1, N):
if min_a < a[i]:
profit = a[i] - min_a
if profit == max_profit:
ans += 1
else:
max_profit = max(max_profit, profit)
else:
min_a = min(min_a, a[i])
print(ans)
| 20 | 20 | 397 | 400 | N, T = [int(v) for v in input().split()]
a = [int(v) for v in input().split()]
max_profit = 0
ans = 1
left = 0
right = 1
while right < N:
if a[left] < a[right]:
profit = a[right] - a[left]
if profit == max_profit:
ans += 1
else:
max_profit = max(max_profit, profit)
else:
left = right
right += 1
print(ans)
| N, T = [int(v) for v in input().split()]
a = [int(v) for v in input().split()]
max_profit = 0
ans = 1
left = 0
right = 1
min_a = a[0]
for i in range(1, N):
if min_a < a[i]:
profit = a[i] - min_a
if profit == max_profit:
ans += 1
else:
max_profit = max(max_profit, profit)
else:
min_a = min(min_a, a[i])
print(ans)
| false | 0 | [
"-while right < N:",
"- if a[left] < a[right]:",
"- profit = a[right] - a[left]",
"+min_a = a[0]",
"+for i in range(1, N):",
"+ if min_a < a[i]:",
"+ profit = a[i] - min_a",
"- left = right",
"- right += 1",
"+ min_a = min(min_a, a[i])"
] | false | 0.122965 | 0.080222 | 1.532801 | [
"s927352454",
"s345576117"
] |
u912237403 | p00025 | python | s480718581 | s509838873 | 20 | 10 | 4,204 | 4,208 | Accepted | Accepted | 50 | import sys
f=0
for s in sys.stdin:
f=1-f
b=list(map(int,s.split()))
if f:
a=b
continue
c1=0
c2=0
for i,e in enumerate(b):
if e==a[i]: c1+=1
elif e in a: c2+=1
print(c1, c2) | import sys
f=1
for s in sys.stdin:
b=list(map(int,s.split()))
if f:
a=b
f=0
continue
c1=0
c2=0
for i,e in enumerate(b):
if e==a[i]: c1+=1
elif e in a: c2+=1
print(c1, c2)
f=1 | 14 | 15 | 238 | 249 | import sys
f = 0
for s in sys.stdin:
f = 1 - f
b = list(map(int, s.split()))
if f:
a = b
continue
c1 = 0
c2 = 0
for i, e in enumerate(b):
if e == a[i]:
c1 += 1
elif e in a:
c2 += 1
print(c1, c2)
| import sys
f = 1
for s in sys.stdin:
b = list(map(int, s.split()))
if f:
a = b
f = 0
continue
c1 = 0
c2 = 0
for i, e in enumerate(b):
if e == a[i]:
c1 += 1
elif e in a:
c2 += 1
print(c1, c2)
f = 1
| false | 6.666667 | [
"-f = 0",
"+f = 1",
"- f = 1 - f",
"+ f = 0",
"+ f = 1"
] | false | 0.049162 | 0.045751 | 1.074569 | [
"s480718581",
"s509838873"
] |
u225528554 | p03546 | python | s420395415 | s305871737 | 48 | 44 | 5,872 | 3,444 | Accepted | Accepted | 8.33 | def dijkstra(graph,src):
if graph is None:
return None
nodes = [i for i in range(len(graph))]
visited=[]
if src in nodes:
visited.append(src)
nodes.remove(src)
else:
return None
distance={src:0}
for i in nodes:
distance[i]=int(graph[src][i])
path={src:{src:[]}}
k=pre=src
while nodes:
mid_distance=float('inf')
for v in visited:
for d in nodes:
new_distance = int(graph[src][v])+int(graph[v][d])
if new_distance < mid_distance:
mid_distance=new_distance
graph[src][d]=str(new_distance)
k=d
pre=v
distance[k]=mid_distance
path[src][k]=[i for i in path[src][pre]]
path[src][k].append(k)
visited.append(k)
nodes.remove(k)
return distance
if __name__=="__main__":
sum = 0
s = input().split(" ")
x, y = s[0], s[1]
c = [n for n in range(0,10)]
d = []
matrix =[i for i in range(0,int(x))]*int(y)
c[0] = list(input().split(" "))
c[1] = list(input().split(" "))
c[2] = list(input().split(" "))
c[3] = list(input().split(" "))
c[4] = list(input().split(" "))
c[5] = list(input().split(" "))
c[6] = list(input().split(" "))
c[7] = list(input().split(" "))
c[8] = list(input().split(" "))
c[9] = list(input().split(" "))
for m in range(0,10):
d.append(dijkstra(c,m))
for i in range(0,int(x)):
matrix[i] = input().split(" ")
for j in range(0,int(y)):
n = int(matrix[i][j])
if n==-1:
continue
else:
sum = sum + int(d[n][1])
print(sum)
| if __name__=="__main__":
sum = 0
x,y = list(map(int,input().split()))
c = [list(map(int,input().split())) for n in range(10)]
for k in range(10):
for i in range(10):
for j in range(10):
if c[i][j]>c[i][k]+c[k][j]:
c[i][j] = c[i][k]+c[k][j]
m = [list(map(int,input().split())) for n in range(int(x))]
for i in range(x):
for j in range(y):
if m[i][j]!=-1:
sum+=int(c[m[i][j]][1])
print(sum)
| 63 | 19 | 1,819 | 525 | def dijkstra(graph, src):
if graph is None:
return None
nodes = [i for i in range(len(graph))]
visited = []
if src in nodes:
visited.append(src)
nodes.remove(src)
else:
return None
distance = {src: 0}
for i in nodes:
distance[i] = int(graph[src][i])
path = {src: {src: []}}
k = pre = src
while nodes:
mid_distance = float("inf")
for v in visited:
for d in nodes:
new_distance = int(graph[src][v]) + int(graph[v][d])
if new_distance < mid_distance:
mid_distance = new_distance
graph[src][d] = str(new_distance)
k = d
pre = v
distance[k] = mid_distance
path[src][k] = [i for i in path[src][pre]]
path[src][k].append(k)
visited.append(k)
nodes.remove(k)
return distance
if __name__ == "__main__":
sum = 0
s = input().split(" ")
x, y = s[0], s[1]
c = [n for n in range(0, 10)]
d = []
matrix = [i for i in range(0, int(x))] * int(y)
c[0] = list(input().split(" "))
c[1] = list(input().split(" "))
c[2] = list(input().split(" "))
c[3] = list(input().split(" "))
c[4] = list(input().split(" "))
c[5] = list(input().split(" "))
c[6] = list(input().split(" "))
c[7] = list(input().split(" "))
c[8] = list(input().split(" "))
c[9] = list(input().split(" "))
for m in range(0, 10):
d.append(dijkstra(c, m))
for i in range(0, int(x)):
matrix[i] = input().split(" ")
for j in range(0, int(y)):
n = int(matrix[i][j])
if n == -1:
continue
else:
sum = sum + int(d[n][1])
print(sum)
| if __name__ == "__main__":
sum = 0
x, y = list(map(int, input().split()))
c = [list(map(int, input().split())) for n in range(10)]
for k in range(10):
for i in range(10):
for j in range(10):
if c[i][j] > c[i][k] + c[k][j]:
c[i][j] = c[i][k] + c[k][j]
m = [list(map(int, input().split())) for n in range(int(x))]
for i in range(x):
for j in range(y):
if m[i][j] != -1:
sum += int(c[m[i][j]][1])
print(sum)
| false | 69.84127 | [
"-def dijkstra(graph, src):",
"- if graph is None:",
"- return None",
"- nodes = [i for i in range(len(graph))]",
"- visited = []",
"- if src in nodes:",
"- visited.append(src)",
"- nodes.remove(src)",
"- else:",
"- return None",
"- distance = {src: 0}",
"- for i in nodes:",
"- distance[i] = int(graph[src][i])",
"- path = {src: {src: []}}",
"- k = pre = src",
"- while nodes:",
"- mid_distance = float(\"inf\")",
"- for v in visited:",
"- for d in nodes:",
"- new_distance = int(graph[src][v]) + int(graph[v][d])",
"- if new_distance < mid_distance:",
"- mid_distance = new_distance",
"- graph[src][d] = str(new_distance)",
"- k = d",
"- pre = v",
"- distance[k] = mid_distance",
"- path[src][k] = [i for i in path[src][pre]]",
"- path[src][k].append(k)",
"- visited.append(k)",
"- nodes.remove(k)",
"- return distance",
"-",
"-",
"- s = input().split(\" \")",
"- x, y = s[0], s[1]",
"- c = [n for n in range(0, 10)]",
"- d = []",
"- matrix = [i for i in range(0, int(x))] * int(y)",
"- c[0] = list(input().split(\" \"))",
"- c[1] = list(input().split(\" \"))",
"- c[2] = list(input().split(\" \"))",
"- c[3] = list(input().split(\" \"))",
"- c[4] = list(input().split(\" \"))",
"- c[5] = list(input().split(\" \"))",
"- c[6] = list(input().split(\" \"))",
"- c[7] = list(input().split(\" \"))",
"- c[8] = list(input().split(\" \"))",
"- c[9] = list(input().split(\" \"))",
"- for m in range(0, 10):",
"- d.append(dijkstra(c, m))",
"- for i in range(0, int(x)):",
"- matrix[i] = input().split(\" \")",
"- for j in range(0, int(y)):",
"- n = int(matrix[i][j])",
"- if n == -1:",
"- continue",
"- else:",
"- sum = sum + int(d[n][1])",
"+ x, y = list(map(int, input().split()))",
"+ c = [list(map(int, input().split())) for n in range(10)]",
"+ for k in range(10):",
"+ for i in range(10):",
"+ for j in range(10):",
"+ if c[i][j] > c[i][k] + c[k][j]:",
"+ c[i][j] = c[i][k] + c[k][j]",
"+ m = [list(map(int, input().split())) for n in range(int(x))]",
"+ for i in range(x):",
"+ for j in range(y):",
"+ if m[i][j] != -1:",
"+ sum += int(c[m[i][j]][1])"
] | false | 0.151501 | 0.179664 | 0.843245 | [
"s420395415",
"s305871737"
] |
u525065967 | p02888 | python | s900786040 | s109185174 | 1,846 | 1,579 | 3,188 | 3,188 | Accepted | Accepted | 14.46 | import bisect
N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
ans = 0
for b in range(N):
l = b + 1
for a in range(b):
maxL = L[a] + L[b]
r = bisect.bisect_left(L, maxL)
ans += max(0, r-l)
print(ans) | N = int(eval(input()))
L = list(map(int,input().split()))
L.sort()
ans = 0
for b in range(N):
l = b + 1
r = l
for a in range(b):
maxL = L[a] + L[b]
while r<N and L[r]<maxL: r += 1
ans += max(0, r-l)
print(ans) | 12 | 12 | 254 | 250 | import bisect
N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
ans = 0
for b in range(N):
l = b + 1
for a in range(b):
maxL = L[a] + L[b]
r = bisect.bisect_left(L, maxL)
ans += max(0, r - l)
print(ans)
| N = int(eval(input()))
L = list(map(int, input().split()))
L.sort()
ans = 0
for b in range(N):
l = b + 1
r = l
for a in range(b):
maxL = L[a] + L[b]
while r < N and L[r] < maxL:
r += 1
ans += max(0, r - l)
print(ans)
| false | 0 | [
"-import bisect",
"-",
"+ r = l",
"- r = bisect.bisect_left(L, maxL)",
"+ while r < N and L[r] < maxL:",
"+ r += 1"
] | false | 0.034337 | 0.067081 | 0.511873 | [
"s900786040",
"s109185174"
] |
u389910364 | p02856 | python | s059316232 | s062928294 | 1,065 | 395 | 79,708 | 45,428 | Accepted | Accepted | 62.91 | import itertools
import os
import sys
from functools import lru_cache
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
M = int(sys.stdin.buffer.readline())
DC = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
def test(n):
round = {str(n)}
ret = 0
while round:
next_round = set()
for n in round:
for i in range(len(n) - 1):
s = n[:i] + str(int(n[i]) + int(n[i + 1])) + n[i + 2:]
if len(s) > 1:
next_round.add(s)
round = next_round
print(round)
ret += 1
print(('test:', ret))
print()
@lru_cache(maxsize=None)
def solve(n):
n = str(n)
if len(n) == 1:
return 0, int(n)
num = 0
ret = 0
for c in str(n):
ret += 1
num += int(c)
while num >= 10:
ret += 1
num = num % 10 + 1
return ret - 1, num
# ans = 0
# num = 0
# for d, c in DC:
# if d == 0:
# ans += c
# n = num + d * c
# ans += n // 10
# num = n % 10
# if d == 1:
# ans += c
# n = num + d * c
# ans += n // 10
# num = n % 10
# if d == 2:
# ans += c
# n1 = c // 5
#
# n
# n = num + d * c
# ans += c
# ans += n // 10
# num = n % 10
memo = [[None] * 11 for _ in range(10)]
for i, j in itertools.product(list(range(10)), list(range(11))):
memo[i][j] = solve(str(i) * j)
def kurikaesi(d, c):
if c < 10:
return memo[d][c]
cnt, n1 = memo[d][10]
ret = cnt * (c // 10)
c2, n2 = kurikaesi(n1, c // 10)
c3, n3 = memo[d][c % 10]
ret += c2
ret += c3
c4, n4 = solve(str(n2) + str(n3))
ret += c4
return ret, n4
#
# n = ''
# for d, c in DC:
# n += str(d) * c
# test(n)
# print(solve(n))
ans = 0
num = 0
for d, c in DC:
cnt, n = kurikaesi(d, c)
ans += cnt
c2, n2 = solve(str(num) + str(n))
ans += c2
num = n2
print((ans - 1))
| import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
# 桁数*9 + 総和が 9 ずつ減る
M = int(sys.stdin.buffer.readline())
DC = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
s = 0
l = 0
for d, c in DC:
l += c
s += d * c
ans = (l * 9 + s - 1) // 9 - 1
print(ans)
| 111 | 24 | 2,216 | 441 | import itertools
import os
import sys
from functools import lru_cache
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
M = int(sys.stdin.buffer.readline())
DC = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
def test(n):
round = {str(n)}
ret = 0
while round:
next_round = set()
for n in round:
for i in range(len(n) - 1):
s = n[:i] + str(int(n[i]) + int(n[i + 1])) + n[i + 2 :]
if len(s) > 1:
next_round.add(s)
round = next_round
print(round)
ret += 1
print(("test:", ret))
print()
@lru_cache(maxsize=None)
def solve(n):
n = str(n)
if len(n) == 1:
return 0, int(n)
num = 0
ret = 0
for c in str(n):
ret += 1
num += int(c)
while num >= 10:
ret += 1
num = num % 10 + 1
return ret - 1, num
# ans = 0
# num = 0
# for d, c in DC:
# if d == 0:
# ans += c
# n = num + d * c
# ans += n // 10
# num = n % 10
# if d == 1:
# ans += c
# n = num + d * c
# ans += n // 10
# num = n % 10
# if d == 2:
# ans += c
# n1 = c // 5
#
# n
# n = num + d * c
# ans += c
# ans += n // 10
# num = n % 10
memo = [[None] * 11 for _ in range(10)]
for i, j in itertools.product(list(range(10)), list(range(11))):
memo[i][j] = solve(str(i) * j)
def kurikaesi(d, c):
if c < 10:
return memo[d][c]
cnt, n1 = memo[d][10]
ret = cnt * (c // 10)
c2, n2 = kurikaesi(n1, c // 10)
c3, n3 = memo[d][c % 10]
ret += c2
ret += c3
c4, n4 = solve(str(n2) + str(n3))
ret += c4
return ret, n4
#
# n = ''
# for d, c in DC:
# n += str(d) * c
# test(n)
# print(solve(n))
ans = 0
num = 0
for d, c in DC:
cnt, n = kurikaesi(d, c)
ans += cnt
c2, n2 = solve(str(num) + str(n))
ans += c2
num = n2
print((ans - 1))
| import os
import sys
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
# 桁数*9 + 総和が 9 ずつ減る
M = int(sys.stdin.buffer.readline())
DC = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
s = 0
l = 0
for d, c in DC:
l += c
s += d * c
ans = (l * 9 + s - 1) // 9 - 1
print(ans)
| false | 78.378378 | [
"-import itertools",
"-from functools import lru_cache",
"+# 桁数*9 + 総和が 9 ずつ減る",
"-",
"-",
"-def test(n):",
"- round = {str(n)}",
"- ret = 0",
"- while round:",
"- next_round = set()",
"- for n in round:",
"- for i in range(len(n) - 1):",
"- s = n[:i] + str(int(n[i]) + int(n[i + 1])) + n[i + 2 :]",
"- if len(s) > 1:",
"- next_round.add(s)",
"- round = next_round",
"- print(round)",
"- ret += 1",
"- print((\"test:\", ret))",
"- print()",
"-",
"-",
"-@lru_cache(maxsize=None)",
"-def solve(n):",
"- n = str(n)",
"- if len(n) == 1:",
"- return 0, int(n)",
"- num = 0",
"- ret = 0",
"- for c in str(n):",
"- ret += 1",
"- num += int(c)",
"- while num >= 10:",
"- ret += 1",
"- num = num % 10 + 1",
"- return ret - 1, num",
"-",
"-",
"-# ans = 0",
"-# num = 0",
"-# for d, c in DC:",
"-# if d == 0:",
"-# ans += c",
"-# n = num + d * c",
"-# ans += n // 10",
"-# num = n % 10",
"-# if d == 1:",
"-# ans += c",
"-# n = num + d * c",
"-# ans += n // 10",
"-# num = n % 10",
"-# if d == 2:",
"-# ans += c",
"-# n1 = c // 5",
"-#",
"-# n",
"-# n = num + d * c",
"-# ans += c",
"-# ans += n // 10",
"-# num = n % 10",
"-memo = [[None] * 11 for _ in range(10)]",
"-for i, j in itertools.product(list(range(10)), list(range(11))):",
"- memo[i][j] = solve(str(i) * j)",
"-",
"-",
"-def kurikaesi(d, c):",
"- if c < 10:",
"- return memo[d][c]",
"- cnt, n1 = memo[d][10]",
"- ret = cnt * (c // 10)",
"- c2, n2 = kurikaesi(n1, c // 10)",
"- c3, n3 = memo[d][c % 10]",
"- ret += c2",
"- ret += c3",
"- c4, n4 = solve(str(n2) + str(n3))",
"- ret += c4",
"- return ret, n4",
"-",
"-",
"-#",
"-# n = ''",
"-# for d, c in DC:",
"-# n += str(d) * c",
"-# test(n)",
"-# print(solve(n))",
"-ans = 0",
"-num = 0",
"+s = 0",
"+l = 0",
"- cnt, n = kurikaesi(d, c)",
"- ans += cnt",
"- c2, n2 = solve(str(num) + str(n))",
"- ans += c2",
"- num = n2",
"-print((ans - 1))",
"+ l += c",
"+ s += d * c",
"+ans = (l * 9 + s - 1) // 9 - 1",
"+print(ans)"
] | false | 0.118014 | 0.07561 | 1.560822 | [
"s059316232",
"s062928294"
] |
u587669944 | p02947 | python | s348654789 | s232167071 | 656 | 419 | 62,040 | 17,852 | Accepted | Accepted | 36.13 | # coding: utf-8
n = int(eval(input()))
dic = {}
for i in range(n):
t = ''.join(sorted(eval(input())))
dic.setdefault(t, 0)
dic[t] += 1
ans = 0
for x in list(dic.values()):
ans += x * (x - 1) // 2
print(ans) | # coding: utf-8
n = int(eval(input()))
dic = {}
for i in range(n):
s = "".join(sorted(eval(input())))
dic.setdefault(s, 0)
dic[s] += 1
ans = 0
for x in list(dic.values()):
ans += int(x * (x - 1) / 2)
print(ans) | 11 | 11 | 214 | 218 | # coding: utf-8
n = int(eval(input()))
dic = {}
for i in range(n):
t = "".join(sorted(eval(input())))
dic.setdefault(t, 0)
dic[t] += 1
ans = 0
for x in list(dic.values()):
ans += x * (x - 1) // 2
print(ans)
| # coding: utf-8
n = int(eval(input()))
dic = {}
for i in range(n):
s = "".join(sorted(eval(input())))
dic.setdefault(s, 0)
dic[s] += 1
ans = 0
for x in list(dic.values()):
ans += int(x * (x - 1) / 2)
print(ans)
| false | 0 | [
"- t = \"\".join(sorted(eval(input())))",
"- dic.setdefault(t, 0)",
"- dic[t] += 1",
"+ s = \"\".join(sorted(eval(input())))",
"+ dic.setdefault(s, 0)",
"+ dic[s] += 1",
"- ans += x * (x - 1) // 2",
"+ ans += int(x * (x - 1) / 2)"
] | false | 0.046126 | 0.044324 | 1.040644 | [
"s348654789",
"s232167071"
] |
u968166680 | p02861 | python | s788280811 | s576340170 | 176 | 18 | 39,024 | 3,064 | Accepted | Accepted | 89.77 | import sys
from itertools import permutations
from math import factorial
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def distance2(x1, y1, x2, y2):
return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
def main():
N = int(readline())
C = [tuple(map(int, readline().split())) for _ in range(N)]
dist = [[0] * N for _ in range(N)]
for i in range(N):
for j in range(i + 1, N):
dist[i][j] = dist[j][i] = distance2(C[i][0], C[i][1], C[j][0], C[j][1])
ans = 0
for perm in permutations(list(range(N))):
for i in range(N - 1):
ans += dist[perm[i]][perm[i + 1]]
print((ans / factorial(N)))
return
if __name__ == '__main__':
main()
| import sys
from itertools import permutations
from math import factorial
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def distance2(x1, y1, x2, y2):
return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
def main():
N = int(readline())
C = [tuple(map(int, readline().split())) for _ in range(N)]
ans = 0
for i in range(N):
for j in range(i + 1, N):
ans += ((C[i][0] - C[j][0]) ** 2 + (C[i][1] - C[j][1]) ** 2) ** 0.5
print((2 * ans / N))
return
if __name__ == '__main__':
main()
| 35 | 30 | 817 | 644 | import sys
from itertools import permutations
from math import factorial
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
def distance2(x1, y1, x2, y2):
return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
def main():
N = int(readline())
C = [tuple(map(int, readline().split())) for _ in range(N)]
dist = [[0] * N for _ in range(N)]
for i in range(N):
for j in range(i + 1, N):
dist[i][j] = dist[j][i] = distance2(C[i][0], C[i][1], C[j][0], C[j][1])
ans = 0
for perm in permutations(list(range(N))):
for i in range(N - 1):
ans += dist[perm[i]][perm[i + 1]]
print((ans / factorial(N)))
return
if __name__ == "__main__":
main()
| import sys
from itertools import permutations
from math import factorial
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
def distance2(x1, y1, x2, y2):
return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
def main():
N = int(readline())
C = [tuple(map(int, readline().split())) for _ in range(N)]
ans = 0
for i in range(N):
for j in range(i + 1, N):
ans += ((C[i][0] - C[j][0]) ** 2 + (C[i][1] - C[j][1]) ** 2) ** 0.5
print((2 * ans / N))
return
if __name__ == "__main__":
main()
| false | 14.285714 | [
"- dist = [[0] * N for _ in range(N)]",
"+ ans = 0",
"- dist[i][j] = dist[j][i] = distance2(C[i][0], C[i][1], C[j][0], C[j][1])",
"- ans = 0",
"- for perm in permutations(list(range(N))):",
"- for i in range(N - 1):",
"- ans += dist[perm[i]][perm[i + 1]]",
"- print((ans / factorial(N)))",
"+ ans += ((C[i][0] - C[j][0]) ** 2 + (C[i][1] - C[j][1]) ** 2) ** 0.5",
"+ print((2 * ans / N))"
] | false | 0.154398 | 0.039869 | 3.872613 | [
"s788280811",
"s576340170"
] |
u491763171 | p00014 | python | s798145305 | s745969824 | 20 | 10 | 4,200 | 4,200 | Accepted | Accepted | 50 | L = []
while 1:
try:
d = eval(input())
x = 600
ret = 0
for i in range(0, 600, d):
ret += d * (i ** 2)
print(ret)
except:
break | while 1:
try:
d = eval(input())
print(sum(d * (i ** 2) for i in range(0, 600, d)))
except:
break | 11 | 6 | 197 | 126 | L = []
while 1:
try:
d = eval(input())
x = 600
ret = 0
for i in range(0, 600, d):
ret += d * (i**2)
print(ret)
except:
break
| while 1:
try:
d = eval(input())
print(sum(d * (i**2) for i in range(0, 600, d)))
except:
break
| false | 45.454545 | [
"-L = []",
"- x = 600",
"- ret = 0",
"- for i in range(0, 600, d):",
"- ret += d * (i**2)",
"- print(ret)",
"+ print(sum(d * (i**2) for i in range(0, 600, d)))"
] | false | 0.046796 | 0.111349 | 0.420259 | [
"s798145305",
"s745969824"
] |
u281610856 | p03449 | python | s741670343 | s440167957 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | n = int(eval(input()))
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
ans = 0
if n == 1:
print((a1[0] + a2[0]))
exit()
for i in range(1, n):
ans = max(sum(a1[:i])+sum(a2[i-1:]), ans)
print(ans)
| n = int(eval(input()))
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
sum_list = [sum(a1[:i]) + sum(a2[i-1:]) for i in range(1, n+1)]
print((max(sum_list)))
| 10 | 6 | 234 | 182 | n = int(eval(input()))
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
ans = 0
if n == 1:
print((a1[0] + a2[0]))
exit()
for i in range(1, n):
ans = max(sum(a1[:i]) + sum(a2[i - 1 :]), ans)
print(ans)
| n = int(eval(input()))
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
sum_list = [sum(a1[:i]) + sum(a2[i - 1 :]) for i in range(1, n + 1)]
print((max(sum_list)))
| false | 40 | [
"-ans = 0",
"-if n == 1:",
"- print((a1[0] + a2[0]))",
"- exit()",
"-for i in range(1, n):",
"- ans = max(sum(a1[:i]) + sum(a2[i - 1 :]), ans)",
"-print(ans)",
"+sum_list = [sum(a1[:i]) + sum(a2[i - 1 :]) for i in range(1, n + 1)]",
"+print((max(sum_list)))"
] | false | 0.050769 | 0.048832 | 1.039669 | [
"s741670343",
"s440167957"
] |
u753803401 | p03807 | python | s163062373 | s340179881 | 338 | 205 | 88,940 | 56,816 | Accepted | Accepted | 39.35 | import sys
import bisect
import collections
import fractions
import heapq
def slove():
input = sys.stdin.readline
n = int(input().rstrip('\n'))
a = list(map(int, input().rstrip('\n').split()))
cnt = 0
for i in range(n):
if a[i] % 2 != 0:
cnt += 1
if cnt % 2 == 0:
print("YES")
else:
print("NO")
if __name__ == '__main__':
slove()
| import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n = int(readline())
a = list(map(int, readline().split()))
cnt = 0
for v in a:
if v % 2 != 0:
cnt += 1
print(("YES" if cnt % 2 == 0 else "NO"))
if __name__ == '__main__':
solve()
| 23 | 17 | 424 | 328 | import sys
import bisect
import collections
import fractions
import heapq
def slove():
input = sys.stdin.readline
n = int(input().rstrip("\n"))
a = list(map(int, input().rstrip("\n").split()))
cnt = 0
for i in range(n):
if a[i] % 2 != 0:
cnt += 1
if cnt % 2 == 0:
print("YES")
else:
print("NO")
if __name__ == "__main__":
slove()
| import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10**9 + 7
n = int(readline())
a = list(map(int, readline().split()))
cnt = 0
for v in a:
if v % 2 != 0:
cnt += 1
print(("YES" if cnt % 2 == 0 else "NO"))
if __name__ == "__main__":
solve()
| false | 26.086957 | [
"-import bisect",
"-import collections",
"-import fractions",
"-import heapq",
"-def slove():",
"- input = sys.stdin.readline",
"- n = int(input().rstrip(\"\\n\"))",
"- a = list(map(int, input().rstrip(\"\\n\").split()))",
"+def solve():",
"+ readline = sys.stdin.buffer.readline",
"+ mod = 10**9 + 7",
"+ n = int(readline())",
"+ a = list(map(int, readline().split()))",
"- for i in range(n):",
"- if a[i] % 2 != 0:",
"+ for v in a:",
"+ if v % 2 != 0:",
"- if cnt % 2 == 0:",
"- print(\"YES\")",
"- else:",
"- print(\"NO\")",
"+ print((\"YES\" if cnt % 2 == 0 else \"NO\"))",
"- slove()",
"+ solve()"
] | false | 0.120783 | 0.105226 | 1.147843 | [
"s163062373",
"s340179881"
] |
u192154323 | p03262 | python | s524753446 | s266619385 | 220 | 94 | 19,608 | 85,572 | Accepted | Accepted | 57.27 | import math
from fractions import gcd
from functools import reduce
n,x = list(map(int, input().split()))
y_ls = list(map(int, input().split()))
y_ls.sort()
d_ls = [0] * (n-1)
if n != 1:
first_ls = []
for i in range(n):
first = abs(x - y_ls[i])
first_ls.append(first)
for i in range(n-1):
distance = y_ls[i+1] - y_ls[i]
d_ls.append(distance)
points_gcd = reduce(gcd, d_ls)
ans = 0
for i in range(n):
D = gcd(points_gcd, first_ls[i])
if D > ans:
ans = D
else:
ans = abs(x - y_ls[0])
print(ans)
| from math import gcd
n,start = list(map(int,input().split()))
x_ls = list(map(int, input().split()))
diff_ls = [0] * n
for i in range(n):
diff_ls[i] = abs(start-x_ls[i])
ans = diff_ls[0]
for i in range(1,n):
ans = gcd(ans,diff_ls[i])
print(ans) | 29 | 13 | 608 | 261 | import math
from fractions import gcd
from functools import reduce
n, x = list(map(int, input().split()))
y_ls = list(map(int, input().split()))
y_ls.sort()
d_ls = [0] * (n - 1)
if n != 1:
first_ls = []
for i in range(n):
first = abs(x - y_ls[i])
first_ls.append(first)
for i in range(n - 1):
distance = y_ls[i + 1] - y_ls[i]
d_ls.append(distance)
points_gcd = reduce(gcd, d_ls)
ans = 0
for i in range(n):
D = gcd(points_gcd, first_ls[i])
if D > ans:
ans = D
else:
ans = abs(x - y_ls[0])
print(ans)
| from math import gcd
n, start = list(map(int, input().split()))
x_ls = list(map(int, input().split()))
diff_ls = [0] * n
for i in range(n):
diff_ls[i] = abs(start - x_ls[i])
ans = diff_ls[0]
for i in range(1, n):
ans = gcd(ans, diff_ls[i])
print(ans)
| false | 55.172414 | [
"-import math",
"-from fractions import gcd",
"-from functools import reduce",
"+from math import gcd",
"-n, x = list(map(int, input().split()))",
"-y_ls = list(map(int, input().split()))",
"-y_ls.sort()",
"-d_ls = [0] * (n - 1)",
"-if n != 1:",
"- first_ls = []",
"- for i in range(n):",
"- first = abs(x - y_ls[i])",
"- first_ls.append(first)",
"- for i in range(n - 1):",
"- distance = y_ls[i + 1] - y_ls[i]",
"- d_ls.append(distance)",
"- points_gcd = reduce(gcd, d_ls)",
"- ans = 0",
"- for i in range(n):",
"- D = gcd(points_gcd, first_ls[i])",
"- if D > ans:",
"- ans = D",
"-else:",
"- ans = abs(x - y_ls[0])",
"+n, start = list(map(int, input().split()))",
"+x_ls = list(map(int, input().split()))",
"+diff_ls = [0] * n",
"+for i in range(n):",
"+ diff_ls[i] = abs(start - x_ls[i])",
"+ans = diff_ls[0]",
"+for i in range(1, n):",
"+ ans = gcd(ans, diff_ls[i])"
] | false | 0.129576 | 0.039385 | 3.289998 | [
"s524753446",
"s266619385"
] |
u745087332 | p03687 | python | s843624923 | s302984127 | 61 | 35 | 3,316 | 3,316 | Accepted | Accepted | 42.62 | # coding:utf-8
from collections import Counter
def inpl(): return list(map(int, input().split()))
S = eval(input())
C = Counter(S)
if len(S) == 1:
print((0))
exit()
ans = 100
for key in list(C.keys()):
prev_S = list(S)
cnt = 0
t = len(S) - 1
while t > 0:
if all([1 if s == key else 0 for s in prev_S]):
ans = min(ans, cnt)
break
SS = []
for i in range(t):
if key in prev_S[i: i + 2]:
SS.append(key)
else:
SS.append(prev_S[i])
cnt += 1
t -= 1
prev_S = SS[:]
# print(cnt, prev_S)
print(ans)
| # coding:utf-8
import sys
from collections import Counter
INF = float('inf')
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return eval(input())
def main():
s = SI()
char_cnt = Counter(s)
res = INF
for c in list(char_cnt.keys()):
r = s[:]
cnt = 0
while len(set(r)) != 1:
t = ''
for ss in zip(r[:-1], r[1:]):
if c in ss:
t += c
else:
t += ss[0]
cnt += 1
r = t
# print(r)
res = min(res, cnt)
return res
print((main()))
| 35 | 39 | 672 | 837 | # coding:utf-8
from collections import Counter
def inpl():
return list(map(int, input().split()))
S = eval(input())
C = Counter(S)
if len(S) == 1:
print((0))
exit()
ans = 100
for key in list(C.keys()):
prev_S = list(S)
cnt = 0
t = len(S) - 1
while t > 0:
if all([1 if s == key else 0 for s in prev_S]):
ans = min(ans, cnt)
break
SS = []
for i in range(t):
if key in prev_S[i : i + 2]:
SS.append(key)
else:
SS.append(prev_S[i])
cnt += 1
t -= 1
prev_S = SS[:]
# print(cnt, prev_S)
print(ans)
| # coding:utf-8
import sys
from collections import Counter
INF = float("inf")
MOD = 10**9 + 7
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return eval(input())
def main():
s = SI()
char_cnt = Counter(s)
res = INF
for c in list(char_cnt.keys()):
r = s[:]
cnt = 0
while len(set(r)) != 1:
t = ""
for ss in zip(r[:-1], r[1:]):
if c in ss:
t += c
else:
t += ss[0]
cnt += 1
r = t
# print(r)
res = min(res, cnt)
return res
print((main()))
| false | 10.25641 | [
"+import sys",
"-",
"-def inpl():",
"- return list(map(int, input().split()))",
"+INF = float(\"inf\")",
"+MOD = 10**9 + 7",
"-S = eval(input())",
"-C = Counter(S)",
"-if len(S) == 1:",
"- print((0))",
"- exit()",
"-ans = 100",
"-for key in list(C.keys()):",
"- prev_S = list(S)",
"- cnt = 0",
"- t = len(S) - 1",
"- while t > 0:",
"- if all([1 if s == key else 0 for s in prev_S]):",
"- ans = min(ans, cnt)",
"- break",
"- SS = []",
"- for i in range(t):",
"- if key in prev_S[i : i + 2]:",
"- SS.append(key)",
"- else:",
"- SS.append(prev_S[i])",
"- cnt += 1",
"- t -= 1",
"- prev_S = SS[:]",
"- # print(cnt, prev_S)",
"-print(ans)",
"+def LI():",
"+ return [int(x) for x in sys.stdin.readline().split()]",
"+",
"+",
"+def LI_():",
"+ return [int(x) - 1 for x in sys.stdin.readline().split()]",
"+",
"+",
"+def LS():",
"+ return sys.stdin.readline().split()",
"+",
"+",
"+def II():",
"+ return int(sys.stdin.readline())",
"+",
"+",
"+def SI():",
"+ return eval(input())",
"+",
"+",
"+def main():",
"+ s = SI()",
"+ char_cnt = Counter(s)",
"+ res = INF",
"+ for c in list(char_cnt.keys()):",
"+ r = s[:]",
"+ cnt = 0",
"+ while len(set(r)) != 1:",
"+ t = \"\"",
"+ for ss in zip(r[:-1], r[1:]):",
"+ if c in ss:",
"+ t += c",
"+ else:",
"+ t += ss[0]",
"+ cnt += 1",
"+ r = t",
"+ # print(r)",
"+ res = min(res, cnt)",
"+ return res",
"+",
"+",
"+print((main()))"
] | false | 0.045667 | 0.038012 | 1.201376 | [
"s843624923",
"s302984127"
] |
u528470578 | p03329 | python | s206408963 | s096054672 | 221 | 103 | 42,080 | 80,264 | Accepted | Accepted | 53.39 | N = int(eval(input()))
INF = int(1e10)
dp = [INF] * N
dp[0] = 1
dp = [0] + dp
bt = set()
for i in range(1, 100):
if 6**i > N:
break
bt.add(6**i)
for i in range(1, 100):
if 9**i > N:
break
bt.add(9**i)
bt = sorted(bt)
for i in range(1, N+1):
dp[i] = dp[i-1] + 1
for j in bt:
if i - j >= 0:
dp[i] = min(dp[i], dp[i - j] + 1)
print((dp[N]))
| N = int(eval(input()))
inf = float("inf")
dp = [inf for _ in range(N+1)]
l6 = 7
l9 = 6
dp[0] = 0
# DP
for i in range(1, N+1):
# 1円を引き出す
dp[i] = min(dp[i], dp[i-1] + 1)
# 6の累乗円を引き出す
for j in range(1, l6):
if i - 6**j >= 0:
dp[i] = min(dp[i], dp[i - 6**j] + 1)
# 9の累乗円を引き出す
for j in range(1, l9):
if i - 9**j >= 0:
dp[i] = min(dp[i], dp[i - 9**j] + 1)
print((dp[N])) | 26 | 23 | 420 | 458 | N = int(eval(input()))
INF = int(1e10)
dp = [INF] * N
dp[0] = 1
dp = [0] + dp
bt = set()
for i in range(1, 100):
if 6**i > N:
break
bt.add(6**i)
for i in range(1, 100):
if 9**i > N:
break
bt.add(9**i)
bt = sorted(bt)
for i in range(1, N + 1):
dp[i] = dp[i - 1] + 1
for j in bt:
if i - j >= 0:
dp[i] = min(dp[i], dp[i - j] + 1)
print((dp[N]))
| N = int(eval(input()))
inf = float("inf")
dp = [inf for _ in range(N + 1)]
l6 = 7
l9 = 6
dp[0] = 0
# DP
for i in range(1, N + 1):
# 1円を引き出す
dp[i] = min(dp[i], dp[i - 1] + 1)
# 6の累乗円を引き出す
for j in range(1, l6):
if i - 6**j >= 0:
dp[i] = min(dp[i], dp[i - 6**j] + 1)
# 9の累乗円を引き出す
for j in range(1, l9):
if i - 9**j >= 0:
dp[i] = min(dp[i], dp[i - 9**j] + 1)
print((dp[N]))
| false | 11.538462 | [
"-INF = int(1e10)",
"-dp = [INF] * N",
"-dp[0] = 1",
"-dp = [0] + dp",
"-bt = set()",
"-for i in range(1, 100):",
"- if 6**i > N:",
"- break",
"- bt.add(6**i)",
"-for i in range(1, 100):",
"- if 9**i > N:",
"- break",
"- bt.add(9**i)",
"-bt = sorted(bt)",
"+inf = float(\"inf\")",
"+dp = [inf for _ in range(N + 1)]",
"+l6 = 7",
"+l9 = 6",
"+dp[0] = 0",
"+# DP",
"- dp[i] = dp[i - 1] + 1",
"- for j in bt:",
"- if i - j >= 0:",
"- dp[i] = min(dp[i], dp[i - j] + 1)",
"+ # 1円を引き出す",
"+ dp[i] = min(dp[i], dp[i - 1] + 1)",
"+ # 6の累乗円を引き出す",
"+ for j in range(1, l6):",
"+ if i - 6**j >= 0:",
"+ dp[i] = min(dp[i], dp[i - 6**j] + 1)",
"+ # 9の累乗円を引き出す",
"+ for j in range(1, l9):",
"+ if i - 9**j >= 0:",
"+ dp[i] = min(dp[i], dp[i - 9**j] + 1)"
] | false | 0.200092 | 0.212 | 0.943829 | [
"s206408963",
"s096054672"
] |
u426534722 | p02412 | python | s548653187 | s096945549 | 730 | 580 | 5,628 | 5,648 | Accepted | Accepted | 20.55 | from itertools import combinations
while True:
n, x = list(map(int, input().split()))
if n == x == 0:
break
cnt = 0
for li in combinations(list(range(1, n + 1)), 3):
if sum(li) == x:
cnt += 1
print(cnt)
| from itertools import combinations
while True:
n, x = list(map(int, input().split()))
if n == x == 0:
break
print((sum(1 for li in combinations(list(range(1, n + 1)), 3) if sum(li) == x)))
| 11 | 6 | 250 | 200 | from itertools import combinations
while True:
n, x = list(map(int, input().split()))
if n == x == 0:
break
cnt = 0
for li in combinations(list(range(1, n + 1)), 3):
if sum(li) == x:
cnt += 1
print(cnt)
| from itertools import combinations
while True:
n, x = list(map(int, input().split()))
if n == x == 0:
break
print((sum(1 for li in combinations(list(range(1, n + 1)), 3) if sum(li) == x)))
| false | 45.454545 | [
"- cnt = 0",
"- for li in combinations(list(range(1, n + 1)), 3):",
"- if sum(li) == x:",
"- cnt += 1",
"- print(cnt)",
"+ print((sum(1 for li in combinations(list(range(1, n + 1)), 3) if sum(li) == x)))"
] | false | 0.036219 | 0.041642 | 0.869764 | [
"s548653187",
"s096945549"
] |
u729133443 | p02803 | python | s511599669 | s861004568 | 413 | 298 | 31,908 | 55,336 | Accepted | Accepted | 27.85 | from scipy.sparse import*
_,*s=open(0)
M=999
*g,=eval('[0]*M,'*M)
i=0
for t in s:
i+=1;j=0
for u in t:k=i*20+j;g[k][k+20]=u>'#'<(s+['#'*M])[i][j];j+=1;g[k][k+1]=u>'#'<t[j]
a=csgraph.johnson(csr_matrix(g),0)
print((int(max(a[a<M])))) | from scipy.sparse import*
_,*s=open(i:=0)
M=999
*g,=eval('[0]*M,'*M)
for t in s:
i+=1;j=0
for u in t:k=i*20+j;g[k][k+20]=u>'#'<(s+['#'*M])[i][j];j+=1;g[k][k+1]=u>'#'<t[j]
a=csgraph.johnson(csr_matrix(g),0)
print((int(max(a[a<M])))) | 10 | 9 | 241 | 239 | from scipy.sparse import *
_, *s = open(0)
M = 999
(*g,) = eval("[0]*M," * M)
i = 0
for t in s:
i += 1
j = 0
for u in t:
k = i * 20 + j
g[k][k + 20] = u > "#" < (s + ["#" * M])[i][j]
j += 1
g[k][k + 1] = u > "#" < t[j]
a = csgraph.johnson(csr_matrix(g), 0)
print((int(max(a[a < M]))))
| from scipy.sparse import *
_, *s = open(i := 0)
M = 999
(*g,) = eval("[0]*M," * M)
for t in s:
i += 1
j = 0
for u in t:
k = i * 20 + j
g[k][k + 20] = u > "#" < (s + ["#" * M])[i][j]
j += 1
g[k][k + 1] = u > "#" < t[j]
a = csgraph.johnson(csr_matrix(g), 0)
print((int(max(a[a < M]))))
| false | 10 | [
"-_, *s = open(0)",
"+_, *s = open(i := 0)",
"-i = 0"
] | false | 1.60242 | 0.915975 | 1.749415 | [
"s511599669",
"s861004568"
] |
u260980560 | p00179 | python | s686786682 | s444022052 | 2,740 | 2,330 | 6,752 | 6,752 | Accepted | Accepted | 14.96 | import queue
que = queue.PriorityQueue()
dic = {
ord('r')+ord('g'): 'b',
ord('g')+ord('b'): 'r',
ord('b')+ord('r'): 'g',
}
while True:
s = input()
if s=='0':
break
while not que.empty():
que.get()
cost = {}
cost[s] = 0
que.put((0, s))
ans = -1
while not que.empty():
nn, ss = que.get()
if all(e == ss[0] for e in ss):
ans = nn
break
if cost[ss] < nn:
continue
for i in range(len(ss)-1):
c0, c1 = ss[i], ss[i+1]
if c0 != c1:
code = dic[ord(c0)+ord(c1)]
sa = ss[:i] + code*2 + ss[i+2:]
if sa not in cost or nn+1 < cost[sa]:
cost[sa] = nn+1
que.put((nn+1, sa))
print("NA" if ans<0 else ans) | import queue
dic = {
'rg':'b', 'gr':'b',
'gb':'r', 'bg':'r',
'br':'g', 'rb':'g',
}
while True:
s = input()
if s=='0':
break
que = queue.PriorityQueue()
l = len(s)
cost = {}
cost[s] = 0
que.put((0, s))
ans = -1
while not que.empty():
nn, ss = que.get()
if all(e == ss[0] for e in ss):
ans = nn
break
if cost[ss] < nn:
continue
for i in range(l-1):
cc = ss[i:i+2]
if cc[0]!=cc[1]:
code = dic[cc]
sa = ss[:i] + code*2 + ss[i+2:]
if sa not in cost or nn+1 < cost[sa]:
cost[sa] = nn+1
que.put((nn+1, sa))
print("NA" if ans<0 else ans) | 33 | 32 | 887 | 824 | import queue
que = queue.PriorityQueue()
dic = {
ord("r") + ord("g"): "b",
ord("g") + ord("b"): "r",
ord("b") + ord("r"): "g",
}
while True:
s = input()
if s == "0":
break
while not que.empty():
que.get()
cost = {}
cost[s] = 0
que.put((0, s))
ans = -1
while not que.empty():
nn, ss = que.get()
if all(e == ss[0] for e in ss):
ans = nn
break
if cost[ss] < nn:
continue
for i in range(len(ss) - 1):
c0, c1 = ss[i], ss[i + 1]
if c0 != c1:
code = dic[ord(c0) + ord(c1)]
sa = ss[:i] + code * 2 + ss[i + 2 :]
if sa not in cost or nn + 1 < cost[sa]:
cost[sa] = nn + 1
que.put((nn + 1, sa))
print("NA" if ans < 0 else ans)
| import queue
dic = {
"rg": "b",
"gr": "b",
"gb": "r",
"bg": "r",
"br": "g",
"rb": "g",
}
while True:
s = input()
if s == "0":
break
que = queue.PriorityQueue()
l = len(s)
cost = {}
cost[s] = 0
que.put((0, s))
ans = -1
while not que.empty():
nn, ss = que.get()
if all(e == ss[0] for e in ss):
ans = nn
break
if cost[ss] < nn:
continue
for i in range(l - 1):
cc = ss[i : i + 2]
if cc[0] != cc[1]:
code = dic[cc]
sa = ss[:i] + code * 2 + ss[i + 2 :]
if sa not in cost or nn + 1 < cost[sa]:
cost[sa] = nn + 1
que.put((nn + 1, sa))
print("NA" if ans < 0 else ans)
| false | 3.030303 | [
"-que = queue.PriorityQueue()",
"- ord(\"r\") + ord(\"g\"): \"b\",",
"- ord(\"g\") + ord(\"b\"): \"r\",",
"- ord(\"b\") + ord(\"r\"): \"g\",",
"+ \"rg\": \"b\",",
"+ \"gr\": \"b\",",
"+ \"gb\": \"r\",",
"+ \"bg\": \"r\",",
"+ \"br\": \"g\",",
"+ \"rb\": \"g\",",
"- while not que.empty():",
"- que.get()",
"+ que = queue.PriorityQueue()",
"+ l = len(s)",
"- for i in range(len(ss) - 1):",
"- c0, c1 = ss[i], ss[i + 1]",
"- if c0 != c1:",
"- code = dic[ord(c0) + ord(c1)]",
"+ for i in range(l - 1):",
"+ cc = ss[i : i + 2]",
"+ if cc[0] != cc[1]:",
"+ code = dic[cc]"
] | false | 0.275571 | 0.2936 | 0.938593 | [
"s686786682",
"s444022052"
] |
u968166680 | p03732 | python | s024716278 | s579855640 | 497 | 194 | 9,228 | 9,160 | Accepted | Accepted | 60.97 | import sys
from itertools import accumulate
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, W, *WV = list(map(int, read().split()))
weight = WV[::2]
value = WV[1::2]
w_min = min(weight)
items = [[] for _ in range(4)]
for w, v in zip(weight, value):
items[w - w_min].append(v)
for i in range(4):
items[i].sort(reverse=True)
csums = [0] * 4
for i in range(4):
csums[i] = [0]
csums[i].extend(accumulate(items[i]))
def rec(i, vec):
if i == 4:
ans = 0
w_total = 0
for j in range(4):
w_total += (w_min + j) * vec[j]
if w_total > W:
return -1
for j in range(4):
ans += csums[j][vec[j]]
return ans
ans = 0
for j in range(len(csums[i])):
vec.append(j)
ans = max(ans, rec(i + 1, vec))
vec.pop()
return ans
print((rec(0, [])))
return
if __name__ == '__main__':
main()
| import sys
from itertools import accumulate
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007
def main():
N, W, *WV = list(map(int, read().split()))
weight = WV[::2]
value = WV[1::2]
w_min = min(weight)
items = [[] for _ in range(4)]
for w, v in zip(weight, value):
items[w - w_min].append(v)
for i in range(4):
items[i].sort(reverse=True)
csums = [0] * 4
for i in range(4):
csums[i] = [0]
csums[i].extend(accumulate(items[i]))
def rec(i, w, v):
if i == 4:
if w <= W:
return v
else:
return -1
ans = 0
for j in range(len(csums[i])):
ans = max(ans, rec(i + 1, w + (w_min + i) * j, v + csums[i][j]))
return ans
print((rec(0, 0, 0)))
return
if __name__ == '__main__':
main()
| 53 | 47 | 1,196 | 1,000 | import sys
from itertools import accumulate
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, W, *WV = list(map(int, read().split()))
weight = WV[::2]
value = WV[1::2]
w_min = min(weight)
items = [[] for _ in range(4)]
for w, v in zip(weight, value):
items[w - w_min].append(v)
for i in range(4):
items[i].sort(reverse=True)
csums = [0] * 4
for i in range(4):
csums[i] = [0]
csums[i].extend(accumulate(items[i]))
def rec(i, vec):
if i == 4:
ans = 0
w_total = 0
for j in range(4):
w_total += (w_min + j) * vec[j]
if w_total > W:
return -1
for j in range(4):
ans += csums[j][vec[j]]
return ans
ans = 0
for j in range(len(csums[i])):
vec.append(j)
ans = max(ans, rec(i + 1, vec))
vec.pop()
return ans
print((rec(0, [])))
return
if __name__ == "__main__":
main()
| import sys
from itertools import accumulate
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF = 1 << 60
MOD = 1000000007
def main():
N, W, *WV = list(map(int, read().split()))
weight = WV[::2]
value = WV[1::2]
w_min = min(weight)
items = [[] for _ in range(4)]
for w, v in zip(weight, value):
items[w - w_min].append(v)
for i in range(4):
items[i].sort(reverse=True)
csums = [0] * 4
for i in range(4):
csums[i] = [0]
csums[i].extend(accumulate(items[i]))
def rec(i, w, v):
if i == 4:
if w <= W:
return v
else:
return -1
ans = 0
for j in range(len(csums[i])):
ans = max(ans, rec(i + 1, w + (w_min + i) * j, v + csums[i][j]))
return ans
print((rec(0, 0, 0)))
return
if __name__ == "__main__":
main()
| false | 11.320755 | [
"- def rec(i, vec):",
"+ def rec(i, w, v):",
"- ans = 0",
"- w_total = 0",
"- for j in range(4):",
"- w_total += (w_min + j) * vec[j]",
"- if w_total > W:",
"+ if w <= W:",
"+ return v",
"+ else:",
"- for j in range(4):",
"- ans += csums[j][vec[j]]",
"- return ans",
"- vec.append(j)",
"- ans = max(ans, rec(i + 1, vec))",
"- vec.pop()",
"+ ans = max(ans, rec(i + 1, w + (w_min + i) * j, v + csums[i][j]))",
"- print((rec(0, [])))",
"+ print((rec(0, 0, 0)))"
] | false | 0.040624 | 0.040356 | 1.006657 | [
"s024716278",
"s579855640"
] |
u806976856 | p02678 | python | s732716057 | s854884712 | 835 | 571 | 45,620 | 123,388 | Accepted | Accepted | 31.62 | from collections import deque
n,m=list(map(int,input().split()))
r=[[] for i in range(n+1)]
R=[[] for i in range(n+1)]
for i in range(m):
a,b=list(map(int,input().split()))
r[a].append(b)
r[b].append(a)
R[a].append(b)
R[b].append(a)
dep=[-1]*(n+1)
dep[0]=0
dep[1]=0
data=deque([1])
d=0
while len(data)>0:
p=data.popleft()
for i in r[p]:
if dep[i]==-1:
dep[i]=dep[p]+1
data.append(i)
r[p]=[]
if not all(dep[i+1]>=0 for i in range(n)):
print("No")
else:
print("Yes")
for i in range(2,n+1):
for j in R[i]:
if dep[j]==dep[i]-1:
print(j)
break
| from collections import deque
n,m=list(map(int,input().split()))
r=[[] for i in range(n+1)]
R=[[] for i in range(n+1)]
for i in range(m):
a,b=list(map(int,input().split()))
r[a].append(b)
r[b].append(a)
R[a].append(b)
R[b].append(a)
dep=[-1]*(n+1)
dep[0]=0
dep[1]=0
data=deque([1])
d=0
while len(data)>0:
p=data.popleft()
for i in r[p]:
if dep[i]==-1:
dep[i]=dep[p]+1
data.append(i)
if not all(dep[i+1]>=0 for i in range(n)):
print("No")
else:
print("Yes")
for i in range(2,n+1):
for j in R[i]:
if dep[j]==dep[i]-1:
print(j)
break
| 31 | 31 | 685 | 678 | from collections import deque
n, m = list(map(int, input().split()))
r = [[] for i in range(n + 1)]
R = [[] for i in range(n + 1)]
for i in range(m):
a, b = list(map(int, input().split()))
r[a].append(b)
r[b].append(a)
R[a].append(b)
R[b].append(a)
dep = [-1] * (n + 1)
dep[0] = 0
dep[1] = 0
data = deque([1])
d = 0
while len(data) > 0:
p = data.popleft()
for i in r[p]:
if dep[i] == -1:
dep[i] = dep[p] + 1
data.append(i)
r[p] = []
if not all(dep[i + 1] >= 0 for i in range(n)):
print("No")
else:
print("Yes")
for i in range(2, n + 1):
for j in R[i]:
if dep[j] == dep[i] - 1:
print(j)
break
| from collections import deque
n, m = list(map(int, input().split()))
r = [[] for i in range(n + 1)]
R = [[] for i in range(n + 1)]
for i in range(m):
a, b = list(map(int, input().split()))
r[a].append(b)
r[b].append(a)
R[a].append(b)
R[b].append(a)
dep = [-1] * (n + 1)
dep[0] = 0
dep[1] = 0
data = deque([1])
d = 0
while len(data) > 0:
p = data.popleft()
for i in r[p]:
if dep[i] == -1:
dep[i] = dep[p] + 1
data.append(i)
if not all(dep[i + 1] >= 0 for i in range(n)):
print("No")
else:
print("Yes")
for i in range(2, n + 1):
for j in R[i]:
if dep[j] == dep[i] - 1:
print(j)
break
| false | 0 | [
"- r[p] = []"
] | false | 0.036559 | 0.035602 | 1.026892 | [
"s732716057",
"s854884712"
] |
u672475305 | p02695 | python | s044054776 | s176682642 | 1,077 | 483 | 9,200 | 9,072 | Accepted | Accepted | 55.15 | from itertools import *
n,m,q = list(map(int,input().split()))
lst = [list(map(int,input().split())) for _ in range(q)]
A = [i for i in range(1, m+1)]
ans = 0
for l in combinations_with_replacement(A, n):
l = list(l)
tmp = 0
for a,b,c,d in lst:
if l[b-1] - l[a-1] == c:
tmp += d
ans = max(ans, tmp)
print(ans) | def dfs(nums, length, min_lim):
ans = 0
if length == n:
score_ret = 0
for a,b,c,d in req:
if nums[b] - nums[a] == c:
score_ret += d
return score_ret
else:
for nu in range(min_lim, m+1):
new_nums = nums + [nu]
score = dfs(new_nums, length+1, nu)
ans = max(ans, score)
return ans
n,m,q = list(map(int,input().split()))
req = [list(map(int,input().split())) for _ in range(q)]
ans = dfs([-1], 0, 1)
print(ans) | 13 | 20 | 339 | 537 | from itertools import *
n, m, q = list(map(int, input().split()))
lst = [list(map(int, input().split())) for _ in range(q)]
A = [i for i in range(1, m + 1)]
ans = 0
for l in combinations_with_replacement(A, n):
l = list(l)
tmp = 0
for a, b, c, d in lst:
if l[b - 1] - l[a - 1] == c:
tmp += d
ans = max(ans, tmp)
print(ans)
| def dfs(nums, length, min_lim):
ans = 0
if length == n:
score_ret = 0
for a, b, c, d in req:
if nums[b] - nums[a] == c:
score_ret += d
return score_ret
else:
for nu in range(min_lim, m + 1):
new_nums = nums + [nu]
score = dfs(new_nums, length + 1, nu)
ans = max(ans, score)
return ans
n, m, q = list(map(int, input().split()))
req = [list(map(int, input().split())) for _ in range(q)]
ans = dfs([-1], 0, 1)
print(ans)
| false | 35 | [
"-from itertools import *",
"+def dfs(nums, length, min_lim):",
"+ ans = 0",
"+ if length == n:",
"+ score_ret = 0",
"+ for a, b, c, d in req:",
"+ if nums[b] - nums[a] == c:",
"+ score_ret += d",
"+ return score_ret",
"+ else:",
"+ for nu in range(min_lim, m + 1):",
"+ new_nums = nums + [nu]",
"+ score = dfs(new_nums, length + 1, nu)",
"+ ans = max(ans, score)",
"+ return ans",
"+",
"-lst = [list(map(int, input().split())) for _ in range(q)]",
"-A = [i for i in range(1, m + 1)]",
"-ans = 0",
"-for l in combinations_with_replacement(A, n):",
"- l = list(l)",
"- tmp = 0",
"- for a, b, c, d in lst:",
"- if l[b - 1] - l[a - 1] == c:",
"- tmp += d",
"- ans = max(ans, tmp)",
"+req = [list(map(int, input().split())) for _ in range(q)]",
"+ans = dfs([-1], 0, 1)"
] | false | 0.061995 | 0.068366 | 0.906817 | [
"s044054776",
"s176682642"
] |
u360116509 | p03722 | python | s211999526 | s432457141 | 1,669 | 1,372 | 3,404 | 3,304 | Accepted | Accepted | 17.8 | def main():
N, M = list(map(int, input().split()))
g = [[] for _ in range(N + 1)]
d = [float('INF')] * (N + 1)
d[1] = 0
for _ in range(M):
a, b, c = list(map(int, input().split()))
c = -c
g[a].append((b, c))
for i in range(2 * N):
for x, r in enumerate(g):
for y, c in r:
if d[x] != float('INF') and d[y] > d[x] + c:
d[y] = d[x] + c
if y == N and i > N:
print("inf")
exit()
print((-d[-1]))
main()
| def main():
N, M = list(map(int, input().split()))
g = []
d = [float('INF')] * (N + 1)
d[1] = 0
for _ in range(M):
a, b, c = list(map(int, input().split()))
g.append((a, b, -c))
for i in range(2 * N):
for x, y, z in g:
if d[x] != float('INF') and d[y] > d[x] + z:
d[y] = d[x] + z
if y == N and i > N:
print("inf")
exit()
print((-d[-1]))
main()
| 22 | 20 | 583 | 488 | def main():
N, M = list(map(int, input().split()))
g = [[] for _ in range(N + 1)]
d = [float("INF")] * (N + 1)
d[1] = 0
for _ in range(M):
a, b, c = list(map(int, input().split()))
c = -c
g[a].append((b, c))
for i in range(2 * N):
for x, r in enumerate(g):
for y, c in r:
if d[x] != float("INF") and d[y] > d[x] + c:
d[y] = d[x] + c
if y == N and i > N:
print("inf")
exit()
print((-d[-1]))
main()
| def main():
N, M = list(map(int, input().split()))
g = []
d = [float("INF")] * (N + 1)
d[1] = 0
for _ in range(M):
a, b, c = list(map(int, input().split()))
g.append((a, b, -c))
for i in range(2 * N):
for x, y, z in g:
if d[x] != float("INF") and d[y] > d[x] + z:
d[y] = d[x] + z
if y == N and i > N:
print("inf")
exit()
print((-d[-1]))
main()
| false | 9.090909 | [
"- g = [[] for _ in range(N + 1)]",
"+ g = []",
"- c = -c",
"- g[a].append((b, c))",
"+ g.append((a, b, -c))",
"- for x, r in enumerate(g):",
"- for y, c in r:",
"- if d[x] != float(\"INF\") and d[y] > d[x] + c:",
"- d[y] = d[x] + c",
"- if y == N and i > N:",
"- print(\"inf\")",
"- exit()",
"+ for x, y, z in g:",
"+ if d[x] != float(\"INF\") and d[y] > d[x] + z:",
"+ d[y] = d[x] + z",
"+ if y == N and i > N:",
"+ print(\"inf\")",
"+ exit()"
] | false | 0.046026 | 0.042243 | 1.089552 | [
"s211999526",
"s432457141"
] |
u210827208 | p02629 | python | s714747270 | s436640950 | 168 | 73 | 61,444 | 61,072 | Accepted | Accepted | 56.55 | n=int(eval(input()))
x=1
X='abcdefghijklmnopqrstuvwxyz'
for i in range(1,100):
if x<=n<x+26**i:
n-=x
cnt=i
break
else:
x+=26**i
ans=''
for i in reversed(list(range(cnt))):
ans+=X[n//(26**i)]
n%=(26**i)
print(ans) | n=int(eval(input()))
x=1
X='abcdefghijklmnopqrstuvwxyz'
for i in range(1,100):
if x<=n<x+26**i:
n-=x
cnt=i
break
else:
x+=26**i
ans=''
for i in range(cnt):
ans=ans+X[n%26]
n//=26
print((ans[::-1])) | 15 | 16 | 262 | 253 | n = int(eval(input()))
x = 1
X = "abcdefghijklmnopqrstuvwxyz"
for i in range(1, 100):
if x <= n < x + 26**i:
n -= x
cnt = i
break
else:
x += 26**i
ans = ""
for i in reversed(list(range(cnt))):
ans += X[n // (26**i)]
n %= 26**i
print(ans)
| n = int(eval(input()))
x = 1
X = "abcdefghijklmnopqrstuvwxyz"
for i in range(1, 100):
if x <= n < x + 26**i:
n -= x
cnt = i
break
else:
x += 26**i
ans = ""
for i in range(cnt):
ans = ans + X[n % 26]
n //= 26
print((ans[::-1]))
| false | 6.25 | [
"-for i in reversed(list(range(cnt))):",
"- ans += X[n // (26**i)]",
"- n %= 26**i",
"-print(ans)",
"+for i in range(cnt):",
"+ ans = ans + X[n % 26]",
"+ n //= 26",
"+print((ans[::-1]))"
] | false | 0.042121 | 0.037675 | 1.118025 | [
"s714747270",
"s436640950"
] |
u842555843 | p02688 | python | s115128926 | s863664522 | 27 | 23 | 9,128 | 9,044 | Accepted | Accepted | 14.81 | N, K = list(map(int, input().split()))
s = set([i for i in range(1, N+1)])
ss = set()
for i in range(K):
int(eval(input()))
ss = ss | set(list(map(int, input().split())))
print((len(s - ss))) | N, K = list(map(int, input().split()))
s = set([i for i in range(1, N+1)])
ss = []
for i in range(K):
int(eval(input()))
ss += list(map(int, input().split()))
print((len(s - set(ss)))) | 7 | 7 | 195 | 185 | N, K = list(map(int, input().split()))
s = set([i for i in range(1, N + 1)])
ss = set()
for i in range(K):
int(eval(input()))
ss = ss | set(list(map(int, input().split())))
print((len(s - ss)))
| N, K = list(map(int, input().split()))
s = set([i for i in range(1, N + 1)])
ss = []
for i in range(K):
int(eval(input()))
ss += list(map(int, input().split()))
print((len(s - set(ss))))
| false | 0 | [
"-ss = set()",
"+ss = []",
"- ss = ss | set(list(map(int, input().split())))",
"-print((len(s - ss)))",
"+ ss += list(map(int, input().split()))",
"+print((len(s - set(ss))))"
] | false | 0.050699 | 0.068878 | 0.736066 | [
"s115128926",
"s863664522"
] |
u514118270 | p02642 | python | s262606560 | s503585475 | 795 | 414 | 176,144 | 33,268 | Accepted | Accepted | 47.92 | M=10**7
_,*l=list(map(int,open(0).read().split()))
a=[0]*M
for i in sorted(l):
a[i]+=1
if a[i]==1:
for j in range(2*i,M,i):a[j]+=9
print((a.count(1))) | M=10**6+1
_,*l=list(map(int,open(0).read().split()))
a=[0]*M
for i in sorted(l):
a[i]+=1
if a[i]==1:
for j in range(2*i,M,i):a[j]+=9
print((a.count(1))) | 8 | 8 | 157 | 159 | M = 10**7
_, *l = list(map(int, open(0).read().split()))
a = [0] * M
for i in sorted(l):
a[i] += 1
if a[i] == 1:
for j in range(2 * i, M, i):
a[j] += 9
print((a.count(1)))
| M = 10**6 + 1
_, *l = list(map(int, open(0).read().split()))
a = [0] * M
for i in sorted(l):
a[i] += 1
if a[i] == 1:
for j in range(2 * i, M, i):
a[j] += 9
print((a.count(1)))
| false | 0 | [
"-M = 10**7",
"+M = 10**6 + 1"
] | false | 1.825467 | 0.174985 | 10.432125 | [
"s262606560",
"s503585475"
] |
u270681687 | p03111 | python | s077290904 | s105261201 | 217 | 81 | 44,252 | 3,064 | Accepted | Accepted | 62.67 | import sys
sys.setrecursionlimit(10**7)
n, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
ans = []
def f(i, anum, alen, bnum, blen, cnum, clen):
if i == n:
if alen * blen * clen == 0:
return
mp = abs(anum-a)+10*(alen-1) + abs(bnum-b)+10*(blen-1) + abs(cnum-c)+10*(clen-1)
ans.append(mp)
else:
f(i+1, anum+l[i], alen+1, bnum, blen, cnum, clen)
f(i+1, anum, alen, bnum+l[i], blen+1, cnum, clen)
f(i+1, anum, alen, bnum, blen, cnum+l[i], clen+1)
f(i+1, anum, alen, bnum, blen, cnum, clen)
f(0, 0, 0, 0, 0, 0, 0)
res = float('inf')
for i in ans:
res = min(res, i)
print(res) | import sys
sys.setrecursionlimit(10**7)
n, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
mp = float('inf')
def f(i, anum, alen, bnum, blen, cnum, clen):
global mp
if i == n:
if alen * blen * clen == 0:
return
mp = min(mp, abs(anum-a)+10*(alen-1) + abs(bnum-b)+10*(blen-1) + abs(cnum-c)+10*(clen-1))
else:
f(i+1, anum+l[i], alen+1, bnum, blen, cnum, clen)
f(i+1, anum, alen, bnum+l[i], blen+1, cnum, clen)
f(i+1, anum, alen, bnum, blen, cnum+l[i], clen+1)
f(i+1, anum, alen, bnum, blen, cnum, clen)
f(0, 0, 0, 0, 0, 0, 0)
print(mp) | 26 | 23 | 706 | 656 | import sys
sys.setrecursionlimit(10**7)
n, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
ans = []
def f(i, anum, alen, bnum, blen, cnum, clen):
if i == n:
if alen * blen * clen == 0:
return
mp = (
abs(anum - a)
+ 10 * (alen - 1)
+ abs(bnum - b)
+ 10 * (blen - 1)
+ abs(cnum - c)
+ 10 * (clen - 1)
)
ans.append(mp)
else:
f(i + 1, anum + l[i], alen + 1, bnum, blen, cnum, clen)
f(i + 1, anum, alen, bnum + l[i], blen + 1, cnum, clen)
f(i + 1, anum, alen, bnum, blen, cnum + l[i], clen + 1)
f(i + 1, anum, alen, bnum, blen, cnum, clen)
f(0, 0, 0, 0, 0, 0, 0)
res = float("inf")
for i in ans:
res = min(res, i)
print(res)
| import sys
sys.setrecursionlimit(10**7)
n, a, b, c = list(map(int, input().split()))
l = [int(eval(input())) for _ in range(n)]
mp = float("inf")
def f(i, anum, alen, bnum, blen, cnum, clen):
global mp
if i == n:
if alen * blen * clen == 0:
return
mp = min(
mp,
abs(anum - a)
+ 10 * (alen - 1)
+ abs(bnum - b)
+ 10 * (blen - 1)
+ abs(cnum - c)
+ 10 * (clen - 1),
)
else:
f(i + 1, anum + l[i], alen + 1, bnum, blen, cnum, clen)
f(i + 1, anum, alen, bnum + l[i], blen + 1, cnum, clen)
f(i + 1, anum, alen, bnum, blen, cnum + l[i], clen + 1)
f(i + 1, anum, alen, bnum, blen, cnum, clen)
f(0, 0, 0, 0, 0, 0, 0)
print(mp)
| false | 11.538462 | [
"-ans = []",
"+mp = float(\"inf\")",
"+ global mp",
"- mp = (",
"+ mp = min(",
"+ mp,",
"- + 10 * (clen - 1)",
"+ + 10 * (clen - 1),",
"- ans.append(mp)",
"-res = float(\"inf\")",
"-for i in ans:",
"- res = min(res, i)",
"-print(res)",
"+print(mp)"
] | false | 0.343735 | 0.07535 | 4.561844 | [
"s077290904",
"s105261201"
] |
u630566146 | p02268 | python | s120460803 | s991692993 | 230 | 210 | 16,708 | 16,712 | Accepted | Accepted | 8.7 | def binary_search(l, t):
left = 0
right = len(l) - 1
while left <= right:
mid = (left + right)//2
if l[mid] < t:
left = mid + 1
elif t < l[mid]:
right = mid - 1
else:
return True
def main():
n = int(eval(input()))
s = list(map(int, input().split()))
q = int(eval(input()))
t = list(map(int, input().split()))
cnt = 0
for et in t:
bl = binary_search(s, et)
if bl:
cnt += 1
print(cnt)
if __name__ == '__main__':
main()
| def binary_search(l, t):
left = 0
right = len(l)
while left < right:
mid = (left + right)//2
if l[mid] < t:
left = mid + 1
elif t < l[mid]:
right = mid
else:
return True
def main():
n = int(eval(input()))
s = list(map(int, input().split()))
q = int(eval(input()))
t = list(map(int, input().split()))
cnt = 0
for et in t:
bl = binary_search(s, et)
if bl:
cnt += 1
print(cnt)
if __name__ == '__main__':
main()
| 30 | 30 | 580 | 571 | def binary_search(l, t):
left = 0
right = len(l) - 1
while left <= right:
mid = (left + right) // 2
if l[mid] < t:
left = mid + 1
elif t < l[mid]:
right = mid - 1
else:
return True
def main():
n = int(eval(input()))
s = list(map(int, input().split()))
q = int(eval(input()))
t = list(map(int, input().split()))
cnt = 0
for et in t:
bl = binary_search(s, et)
if bl:
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
| def binary_search(l, t):
left = 0
right = len(l)
while left < right:
mid = (left + right) // 2
if l[mid] < t:
left = mid + 1
elif t < l[mid]:
right = mid
else:
return True
def main():
n = int(eval(input()))
s = list(map(int, input().split()))
q = int(eval(input()))
t = list(map(int, input().split()))
cnt = 0
for et in t:
bl = binary_search(s, et)
if bl:
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
| false | 0 | [
"- right = len(l) - 1",
"- while left <= right:",
"+ right = len(l)",
"+ while left < right:",
"- right = mid - 1",
"+ right = mid"
] | false | 0.035279 | 0.038316 | 0.920757 | [
"s120460803",
"s991692993"
] |
u788703383 | p03860 | python | s082251530 | s755628892 | 171 | 17 | 38,384 | 2,940 | Accepted | Accepted | 90.06 | a = input().split()
x = a[1]
print(('A' + x[0] + 'C')) | print(('A'+input()[8]+'C')) | 3 | 1 | 54 | 25 | a = input().split()
x = a[1]
print(("A" + x[0] + "C"))
| print(("A" + input()[8] + "C"))
| false | 66.666667 | [
"-a = input().split()",
"-x = a[1]",
"-print((\"A\" + x[0] + \"C\"))",
"+print((\"A\" + input()[8] + \"C\"))"
] | false | 0.038296 | 0.047214 | 0.811113 | [
"s082251530",
"s755628892"
] |
u562935282 | p03062 | python | s954005127 | s378078310 | 998 | 97 | 22,600 | 14,412 | Accepted | Accepted | 90.28 | import numpy as np
inf = float('inf')
N = int(eval(input()))
a = list(map(int, input().split()))
dp = np.empty((N + 1, 2))
dp[0][0] = 0
dp[0][1] = -inf
# dp[i][0]:=1-indexedで、a_iとa_i+1を反転させない場合の最大値
# dp[i][1]:=1-indexedで、a_iとa_i+1を反転させる場合の最大値
for i, aa in enumerate(a, 0):
dp[i + 1][0] = max(dp[i][0] + aa, dp[i][1] - aa)
dp[i + 1][1] = max(dp[i][0] - aa, dp[i][1] + aa)
print((int(dp[N][0])))
# np.emptyのせいか、float型になっているので、WA扱いになる
# np.zerosよりも、np.emptyの方が速い? | n = int(eval(input()))
a = tuple(map(int, input().split()))
minus_count = len(tuple([x for x in a if x < 0]))
b = tuple(sorted(map(abs, a)))
s = sum(b)
if minus_count % 2 == 1:
s -= b[0] * 2
print(s)
| 20 | 9 | 478 | 210 | import numpy as np
inf = float("inf")
N = int(eval(input()))
a = list(map(int, input().split()))
dp = np.empty((N + 1, 2))
dp[0][0] = 0
dp[0][1] = -inf
# dp[i][0]:=1-indexedで、a_iとa_i+1を反転させない場合の最大値
# dp[i][1]:=1-indexedで、a_iとa_i+1を反転させる場合の最大値
for i, aa in enumerate(a, 0):
dp[i + 1][0] = max(dp[i][0] + aa, dp[i][1] - aa)
dp[i + 1][1] = max(dp[i][0] - aa, dp[i][1] + aa)
print((int(dp[N][0])))
# np.emptyのせいか、float型になっているので、WA扱いになる
# np.zerosよりも、np.emptyの方が速い?
| n = int(eval(input()))
a = tuple(map(int, input().split()))
minus_count = len(tuple([x for x in a if x < 0]))
b = tuple(sorted(map(abs, a)))
s = sum(b)
if minus_count % 2 == 1:
s -= b[0] * 2
print(s)
| false | 55 | [
"-import numpy as np",
"-",
"-inf = float(\"inf\")",
"-N = int(eval(input()))",
"-a = list(map(int, input().split()))",
"-dp = np.empty((N + 1, 2))",
"-dp[0][0] = 0",
"-dp[0][1] = -inf",
"-# dp[i][0]:=1-indexedで、a_iとa_i+1を反転させない場合の最大値",
"-# dp[i][1]:=1-indexedで、a_iとa_i+1を反転させる場合の最大値",
"-for i, aa in enumerate(a, 0):",
"- dp[i + 1][0] = max(dp[i][0] + aa, dp[i][1] - aa)",
"- dp[i + 1][1] = max(dp[i][0] - aa, dp[i][1] + aa)",
"-print((int(dp[N][0])))",
"-# np.emptyのせいか、float型になっているので、WA扱いになる",
"-# np.zerosよりも、np.emptyの方が速い?",
"+n = int(eval(input()))",
"+a = tuple(map(int, input().split()))",
"+minus_count = len(tuple([x for x in a if x < 0]))",
"+b = tuple(sorted(map(abs, a)))",
"+s = sum(b)",
"+if minus_count % 2 == 1:",
"+ s -= b[0] * 2",
"+print(s)"
] | false | 0.54501 | 0.038855 | 14.026767 | [
"s954005127",
"s378078310"
] |
u427984570 | p02756 | python | s025784400 | s332353082 | 749 | 669 | 8,820 | 8,692 | Accepted | Accepted | 10.68 | from collections import deque
s = deque(eval(input()))
#s = input()
n = int(eval(input()))
f = 1
for i in range(n):
l = list(map(str, input().split()))
if l[0] == "2":
tmp = int(l[1])*f
if tmp == 1 or tmp == -2:
s.appendleft(l[2])
else:
s.append(l[2])
else:
f *= -1
if f == -1:
s.reverse()
print(("".join(s)))
| from collections import deque
s = deque(eval(input()))
n = int(eval(input()))
f = 0
for i in range(n):
l = list(map(str, input().split()))
if l[0] == "2":
if (l[1] == "1" and f == 0) or (l[1] == "2" and f == 1):
s.appendleft(l[2])
else:
s.append(l[2])
else:
if f == 0:
f = 1
else:
f = 0
if f == 1:
s.reverse()
print(("".join(s)))
| 19 | 19 | 351 | 382 | from collections import deque
s = deque(eval(input()))
# s = input()
n = int(eval(input()))
f = 1
for i in range(n):
l = list(map(str, input().split()))
if l[0] == "2":
tmp = int(l[1]) * f
if tmp == 1 or tmp == -2:
s.appendleft(l[2])
else:
s.append(l[2])
else:
f *= -1
if f == -1:
s.reverse()
print(("".join(s)))
| from collections import deque
s = deque(eval(input()))
n = int(eval(input()))
f = 0
for i in range(n):
l = list(map(str, input().split()))
if l[0] == "2":
if (l[1] == "1" and f == 0) or (l[1] == "2" and f == 1):
s.appendleft(l[2])
else:
s.append(l[2])
else:
if f == 0:
f = 1
else:
f = 0
if f == 1:
s.reverse()
print(("".join(s)))
| false | 0 | [
"-# s = input()",
"-f = 1",
"+f = 0",
"- tmp = int(l[1]) * f",
"- if tmp == 1 or tmp == -2:",
"+ if (l[1] == \"1\" and f == 0) or (l[1] == \"2\" and f == 1):",
"- f *= -1",
"-if f == -1:",
"+ if f == 0:",
"+ f = 1",
"+ else:",
"+ f = 0",
"+if f == 1:"
] | false | 0.044576 | 0.046544 | 0.957722 | [
"s025784400",
"s332353082"
] |
u581603131 | p02706 | python | s421864832 | s979116727 | 25 | 23 | 10,040 | 10,196 | Accepted | Accepted | 8 | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(M):
N -= A[i]
if N>=0:
print(N)
elif N < 0:
print((-1)) | #先にAの合計値を出してもよい
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
suma = sum(A)
if N-suma>=0:
print((N-suma))
else:
print((-1)) | 8 | 8 | 156 | 157 | N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
for i in range(M):
N -= A[i]
if N >= 0:
print(N)
elif N < 0:
print((-1))
| # 先にAの合計値を出してもよい
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
suma = sum(A)
if N - suma >= 0:
print((N - suma))
else:
print((-1))
| false | 0 | [
"+# 先にAの合計値を出してもよい",
"-for i in range(M):",
"- N -= A[i]",
"-if N >= 0:",
"- print(N)",
"-elif N < 0:",
"+suma = sum(A)",
"+if N - suma >= 0:",
"+ print((N - suma))",
"+else:"
] | false | 0.044089 | 0.071783 | 0.6142 | [
"s421864832",
"s979116727"
] |
u090361088 | p03854 | python | s301744876 | s448586516 | 37 | 19 | 3,188 | 3,188 | Accepted | Accepted | 48.65 | S = str(eval(input()))
T = ''
cnt = 0
while True:
if S[cnt:cnt+5] == 'dream':
try:
if S[cnt:cnt+7] == 'dreamer' and (S[cnt+7] != 'a'):
cnt += 7
T = T + 'dreamer'
else:
T = T + 'dream'
cnt += 5
except IndexError:
cnt += 7
T = T + 'dreamer'
elif S[cnt:cnt+5] == 'erase':
try:
if S[cnt:cnt+6] == 'eraser' and S[cnt+6] != 'a':
cnt += 6
T = T + 'eraser'
else:
cnt += 5
T = T + 'erase'
except IndexError:
cnt += 6
T = T + 'eraser'
else:
break
if len(S) <= cnt:
break
if S == T:
print('YES')
else:
print('NO') | s = eval(input())
l = ['eraser', 'dreamer', 'erase', 'dream', 'ase']
for i in l:
s = s.replace(i, '')
if len(s) == 0:
print('YES')
else:
print('NO') | 37 | 8 | 831 | 161 | S = str(eval(input()))
T = ""
cnt = 0
while True:
if S[cnt : cnt + 5] == "dream":
try:
if S[cnt : cnt + 7] == "dreamer" and (S[cnt + 7] != "a"):
cnt += 7
T = T + "dreamer"
else:
T = T + "dream"
cnt += 5
except IndexError:
cnt += 7
T = T + "dreamer"
elif S[cnt : cnt + 5] == "erase":
try:
if S[cnt : cnt + 6] == "eraser" and S[cnt + 6] != "a":
cnt += 6
T = T + "eraser"
else:
cnt += 5
T = T + "erase"
except IndexError:
cnt += 6
T = T + "eraser"
else:
break
if len(S) <= cnt:
break
if S == T:
print("YES")
else:
print("NO")
| s = eval(input())
l = ["eraser", "dreamer", "erase", "dream", "ase"]
for i in l:
s = s.replace(i, "")
if len(s) == 0:
print("YES")
else:
print("NO")
| false | 78.378378 | [
"-S = str(eval(input()))",
"-T = \"\"",
"-cnt = 0",
"-while True:",
"- if S[cnt : cnt + 5] == \"dream\":",
"- try:",
"- if S[cnt : cnt + 7] == \"dreamer\" and (S[cnt + 7] != \"a\"):",
"- cnt += 7",
"- T = T + \"dreamer\"",
"- else:",
"- T = T + \"dream\"",
"- cnt += 5",
"- except IndexError:",
"- cnt += 7",
"- T = T + \"dreamer\"",
"- elif S[cnt : cnt + 5] == \"erase\":",
"- try:",
"- if S[cnt : cnt + 6] == \"eraser\" and S[cnt + 6] != \"a\":",
"- cnt += 6",
"- T = T + \"eraser\"",
"- else:",
"- cnt += 5",
"- T = T + \"erase\"",
"- except IndexError:",
"- cnt += 6",
"- T = T + \"eraser\"",
"- else:",
"- break",
"- if len(S) <= cnt:",
"- break",
"-if S == T:",
"+s = eval(input())",
"+l = [\"eraser\", \"dreamer\", \"erase\", \"dream\", \"ase\"]",
"+for i in l:",
"+ s = s.replace(i, \"\")",
"+if len(s) == 0:"
] | false | 0.047054 | 0.046793 | 1.005584 | [
"s301744876",
"s448586516"
] |
u656771711 | p02960 | python | s708301866 | s459817617 | 1,467 | 1,262 | 43,772 | 44,224 | Accepted | Accepted | 13.97 | S=eval(input())
d=[0]*13
d[0]=1
for i in range(len(S)):
n=[0]*13
for j in range(13):
for k in range(10):
n[(10*j+k)%13]+=(1 if S[i]=='?' or int(S[i])==k else 0)*d[j]
for j in range(13): d[j]=n[j]%(10**9+7)
print((d[5])) | S=eval(input())
d=[0]*13
d[0]=1
for i in range(len(S)):
n=[0]*13
for j in range(13):
for k in range(10):
if S[i]=='?' or int(S[i])==k: n[(10*j+k)%13]+=d[j]
for j in range(13): d[j]=n[j]%(10**9+7)
print((d[5])) | 10 | 10 | 236 | 226 | S = eval(input())
d = [0] * 13
d[0] = 1
for i in range(len(S)):
n = [0] * 13
for j in range(13):
for k in range(10):
n[(10 * j + k) % 13] += (1 if S[i] == "?" or int(S[i]) == k else 0) * d[j]
for j in range(13):
d[j] = n[j] % (10**9 + 7)
print((d[5]))
| S = eval(input())
d = [0] * 13
d[0] = 1
for i in range(len(S)):
n = [0] * 13
for j in range(13):
for k in range(10):
if S[i] == "?" or int(S[i]) == k:
n[(10 * j + k) % 13] += d[j]
for j in range(13):
d[j] = n[j] % (10**9 + 7)
print((d[5]))
| false | 0 | [
"- n[(10 * j + k) % 13] += (1 if S[i] == \"?\" or int(S[i]) == k else 0) * d[j]",
"+ if S[i] == \"?\" or int(S[i]) == k:",
"+ n[(10 * j + k) % 13] += d[j]"
] | false | 0.100548 | 0.038405 | 2.618073 | [
"s708301866",
"s459817617"
] |
u389910364 | p02815 | python | s674877289 | s485455650 | 381 | 287 | 31,020 | 30,996 | Accepted | Accepted | 24.67 | import os
import sys
import numpy as np
# from libs.debug import debug
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
N = int(sys.stdin.buffer.readline())
C = list(map(int, sys.stdin.buffer.readline().split()))
C.sort()
#
# @debug
# def f(S, T, C):
# S = np.array(S, dtype=bool)
# T = np.array(T, dtype=bool)
# C = np.array(C, dtype=int)
# costs = np.msort(C[S != T])
# return int(np.dot(costs[::-1], np.arange(1, len(costs) + 1)))
#
#
# def test(N, C):
# ans = 0
# for s in itertools.product([True, False], repeat=N):
# for t in itertools.product([True, False], repeat=N):
# ans += f(s, t, C)
# ans %= MOD
# print(ans)
#
#
# test(N, C)
# R = np.zeros((N + 1, N), dtype=int)
# R[0] = 0
# R[1] = 1
# for r in range(2, N + 1):
# for c in range(N):
# R[r, c] = R[r - 1][:c].sum()
# print(R)
# print(R * np.arange(N + 1)[:, None])
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]))
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1])
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1]).sum())
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1]).sum() * (2 ** N) % MOD)
#
# print()
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]))
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1])).sum(axis=0))
# print(np.diff((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1])).sum(axis=0)))
if N == 1:
arr = np.ones(1, dtype=int)
else:
arr = np.full(N + 1, pow(2, N - 2, MOD), dtype=int)
arr = arr.cumsum()[1:]
arr %= MOD
# print(arr)
ans = arr * np.msort(C)[::-1] % MOD
print((sum(ans) % MOD * pow(2, N, MOD) % MOD))
# print(ans.sum() * pow(2, N, MOD) % MOD)
| import os
import sys
import numpy as np
# from libs.debug import debug
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
N = int(sys.stdin.buffer.readline())
C = list(map(int, sys.stdin.buffer.readline().split()))
# @debug
# def f(S, T, C):
# S = np.array(S, dtype=bool)
# T = np.array(T, dtype=bool)
# C = np.array(C, dtype=int)
# costs = np.msort(C[S != T])
# return int(np.dot(costs[::-1], np.arange(1, len(costs) + 1)))
#
#
# def test(N, C):
# ans = 0
# for s in itertools.product([True, False], repeat=N):
# for t in itertools.product([True, False], repeat=N):
# ans += f(s, t, C)
# ans %= MOD
# print(ans)
#
#
# test(N, C)
# R[d][i]: C が降順にソートされてるとして、C[i] が上から d 番目の大きさになる選び方の数
# R = np.zeros((N + 1, N), dtype=int)
# R[0] = 0
# R[1] = 1
# for r in range(2, N + 1):
# for c in range(N):
# R[r, c] = R[r - 1][:c].sum()
# # 自分より大きいのの選び方の総数
# print(R)
# # 順位かける
# print(R * np.arange(N + 1)[:, None])
# # 自分より小さいのの選び方をかける
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]))
# # 順位が小さいのに大きいのをかける
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1])
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1]).sum())
# # 同じ選び方が 2**N 個ある
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1]).sum() * (2 ** N) % MOD)
# print()
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]))
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1])).sum(axis=0))
# print(np.diff((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1])).sum(axis=0)))
if N == 1:
arr = np.ones(1, dtype=int)
else:
arr = np.arange(N, dtype=int) * pow(2, N - 2, MOD) + pow(2, N - 1, MOD)
ans = arr % MOD * np.msort(C)[::-1] % MOD
print((sum(ans) % MOD * pow(2, N, MOD) % MOD))
| 70 | 71 | 1,990 | 2,056 | import os
import sys
import numpy as np
# from libs.debug import debug
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
N = int(sys.stdin.buffer.readline())
C = list(map(int, sys.stdin.buffer.readline().split()))
C.sort()
#
# @debug
# def f(S, T, C):
# S = np.array(S, dtype=bool)
# T = np.array(T, dtype=bool)
# C = np.array(C, dtype=int)
# costs = np.msort(C[S != T])
# return int(np.dot(costs[::-1], np.arange(1, len(costs) + 1)))
#
#
# def test(N, C):
# ans = 0
# for s in itertools.product([True, False], repeat=N):
# for t in itertools.product([True, False], repeat=N):
# ans += f(s, t, C)
# ans %= MOD
# print(ans)
#
#
# test(N, C)
# R = np.zeros((N + 1, N), dtype=int)
# R[0] = 0
# R[1] = 1
# for r in range(2, N + 1):
# for c in range(N):
# R[r, c] = R[r - 1][:c].sum()
# print(R)
# print(R * np.arange(N + 1)[:, None])
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]))
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1])
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1]).sum())
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1]).sum() * (2 ** N) % MOD)
#
# print()
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]))
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1])).sum(axis=0))
# print(np.diff((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1])).sum(axis=0)))
if N == 1:
arr = np.ones(1, dtype=int)
else:
arr = np.full(N + 1, pow(2, N - 2, MOD), dtype=int)
arr = arr.cumsum()[1:]
arr %= MOD
# print(arr)
ans = arr * np.msort(C)[::-1] % MOD
print((sum(ans) % MOD * pow(2, N, MOD) % MOD))
# print(ans.sum() * pow(2, N, MOD) % MOD)
| import os
import sys
import numpy as np
# from libs.debug import debug
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10**9)
INF = float("inf")
IINF = 10**18
MOD = 10**9 + 7
# MOD = 998244353
N = int(sys.stdin.buffer.readline())
C = list(map(int, sys.stdin.buffer.readline().split()))
# @debug
# def f(S, T, C):
# S = np.array(S, dtype=bool)
# T = np.array(T, dtype=bool)
# C = np.array(C, dtype=int)
# costs = np.msort(C[S != T])
# return int(np.dot(costs[::-1], np.arange(1, len(costs) + 1)))
#
#
# def test(N, C):
# ans = 0
# for s in itertools.product([True, False], repeat=N):
# for t in itertools.product([True, False], repeat=N):
# ans += f(s, t, C)
# ans %= MOD
# print(ans)
#
#
# test(N, C)
# R[d][i]: C が降順にソートされてるとして、C[i] が上から d 番目の大きさになる選び方の数
# R = np.zeros((N + 1, N), dtype=int)
# R[0] = 0
# R[1] = 1
# for r in range(2, N + 1):
# for c in range(N):
# R[r, c] = R[r - 1][:c].sum()
# # 自分より大きいのの選び方の総数
# print(R)
# # 順位かける
# print(R * np.arange(N + 1)[:, None])
# # 自分より小さいのの選び方をかける
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]))
# # 順位が小さいのに大きいのをかける
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1])
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1]).sum())
# # 同じ選び方が 2**N 個ある
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]) * np.msort(C)[::-1]).sum() * (2 ** N) % MOD)
# print()
# print(R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1]))
# print((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1])).sum(axis=0))
# print(np.diff((R * np.arange(N + 1)[:, None] * (2 ** np.arange(N)[::-1])).sum(axis=0)))
if N == 1:
arr = np.ones(1, dtype=int)
else:
arr = np.arange(N, dtype=int) * pow(2, N - 2, MOD) + pow(2, N - 1, MOD)
ans = arr % MOD * np.msort(C)[::-1] % MOD
print((sum(ans) % MOD * pow(2, N, MOD) % MOD))
| false | 1.408451 | [
"-C.sort()",
"-#",
"+# R[d][i]: C が降順にソートされてるとして、C[i] が上から d 番目の大きさになる選び方の数",
"+# # 自分より大きいのの選び方の総数",
"+# # 順位かける",
"+# # 自分より小さいのの選び方をかける",
"+# # 順位が小さいのに大きいのをかける",
"+# # 同じ選び方が 2**N 個ある",
"-#",
"- arr = np.full(N + 1, pow(2, N - 2, MOD), dtype=int)",
"- arr = arr.cumsum()[1:]",
"- arr %= MOD",
"-# print(arr)",
"-ans = arr * np.msort(C)[::-1] % MOD",
"+ arr = np.arange(N, dtype=int) * pow(2, N - 2, MOD) + pow(2, N - 1, MOD)",
"+ans = arr % MOD * np.msort(C)[::-1] % MOD",
"-# print(ans.sum() * pow(2, N, MOD) % MOD)"
] | false | 0.22167 | 0.220786 | 1.004008 | [
"s674877289",
"s485455650"
] |
u797673668 | p02271 | python | s853691083 | s572964006 | 5,640 | 1,970 | 228,988 | 220,828 | Accepted | Accepted | 65.07 | from itertools import combinations
n, a, q, ms = int(eval(input())), list(map(int, input().split())), eval(input()), list(map(int, input().split()))
cache = {}
def sum_a(tmp, t):
global a, cache
if t in cache:
return tmp + cache[t]
elif len(t) == 1:
return tmp + a[t[0]]
else:
cache[t] = result = sum_a(tmp + a[t[0]], t[1:])
return result
l = list(sum_a(0, t) for i in range(n) for t in combinations(list(range(n)), i + 1))
for m in ms:
print(('yes' if m in l else 'no')) | from itertools import combinations
n, a, q, ms, cache = int(eval(input())), list(map(int, input().split())), eval(input()), list(map(int, input().split())), {}
def sum_a(tmp, t):
global a, cache
if t in cache:
return tmp + cache[t]
elif len(t) == 1:
return tmp + a[t[0]]
else:
cache[t] = result = sum_a(tmp + a[t[0]], t[1:])
return result
l = set(sum_a(0, t) for i in range(n) for t in combinations(list(range(n)), i + 1))
for m in ms:
print(('yes' if m in l else 'no')) | 22 | 20 | 525 | 521 | from itertools import combinations
n, a, q, ms = (
int(eval(input())),
list(map(int, input().split())),
eval(input()),
list(map(int, input().split())),
)
cache = {}
def sum_a(tmp, t):
global a, cache
if t in cache:
return tmp + cache[t]
elif len(t) == 1:
return tmp + a[t[0]]
else:
cache[t] = result = sum_a(tmp + a[t[0]], t[1:])
return result
l = list(sum_a(0, t) for i in range(n) for t in combinations(list(range(n)), i + 1))
for m in ms:
print(("yes" if m in l else "no"))
| from itertools import combinations
n, a, q, ms, cache = (
int(eval(input())),
list(map(int, input().split())),
eval(input()),
list(map(int, input().split())),
{},
)
def sum_a(tmp, t):
global a, cache
if t in cache:
return tmp + cache[t]
elif len(t) == 1:
return tmp + a[t[0]]
else:
cache[t] = result = sum_a(tmp + a[t[0]], t[1:])
return result
l = set(sum_a(0, t) for i in range(n) for t in combinations(list(range(n)), i + 1))
for m in ms:
print(("yes" if m in l else "no"))
| false | 9.090909 | [
"-n, a, q, ms = (",
"+n, a, q, ms, cache = (",
"+ {},",
"-cache = {}",
"-l = list(sum_a(0, t) for i in range(n) for t in combinations(list(range(n)), i + 1))",
"+l = set(sum_a(0, t) for i in range(n) for t in combinations(list(range(n)), i + 1))"
] | false | 0.047118 | 0.253562 | 0.185823 | [
"s853691083",
"s572964006"
] |
u971091945 | p02576 | python | s451586005 | s700357798 | 30 | 24 | 9,088 | 9,024 | Accepted | Accepted | 20 | n, x, t = list(map(int, input().split()))
print((-(-n//x)*t)) | import math
n, x, t = list(map(int, input().split()))
print((math.ceil(n/x)*t)) | 2 | 3 | 54 | 73 | n, x, t = list(map(int, input().split()))
print((-(-n // x) * t))
| import math
n, x, t = list(map(int, input().split()))
print((math.ceil(n / x) * t))
| false | 33.333333 | [
"+import math",
"+",
"-print((-(-n // x) * t))",
"+print((math.ceil(n / x) * t))"
] | false | 0.084756 | 0.120854 | 0.701313 | [
"s451586005",
"s700357798"
] |
u214617707 | p03343 | python | s692618122 | s371295280 | 1,728 | 1,460 | 3,188 | 3,316 | Accepted | Accepted | 15.51 | N, K, Q = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = float("inf")
for i in range(N):
tmp = []
rec = []
for j in range(N):
if a[i] <= a[j]:
tmp.append(a[j])
else:
if len(tmp) >= K:
tmp = sorted(tmp)
rec += tmp[:len(tmp) - K + 1]
tmp = []
if len(tmp) >= K:
tmp = sorted(tmp)
rec += tmp[:len(tmp) - K + 1]
if Q <= len(rec):
rec = sorted(rec)
ans = min(ans, rec[Q - 1] - rec[0])
print(ans) | N, K, Q = list(map(int, input().split()))
A = list(map(int, input().split()))
D = set()
for i in range(N):
D.add(A[i])
D = list(D)
ans = float('inf')
for Y in D:
T = []
tmp = []
for j in range(N):
if A[j] >= Y:
tmp.append(A[j])
else:
if len(tmp) >= K:
tmp = sorted(tmp)
T += tmp[:len(tmp) - K + 1]
tmp = []
if len(tmp) >= K:
tmp = sorted(tmp)
T += tmp[:len(tmp) - K + 1]
if len(T) >= Q:
T = sorted(T)
T = T[:Q]
ans = min(ans, T[-1] - T[0])
print(ans)
| 22 | 30 | 568 | 626 | N, K, Q = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = float("inf")
for i in range(N):
tmp = []
rec = []
for j in range(N):
if a[i] <= a[j]:
tmp.append(a[j])
else:
if len(tmp) >= K:
tmp = sorted(tmp)
rec += tmp[: len(tmp) - K + 1]
tmp = []
if len(tmp) >= K:
tmp = sorted(tmp)
rec += tmp[: len(tmp) - K + 1]
if Q <= len(rec):
rec = sorted(rec)
ans = min(ans, rec[Q - 1] - rec[0])
print(ans)
| N, K, Q = list(map(int, input().split()))
A = list(map(int, input().split()))
D = set()
for i in range(N):
D.add(A[i])
D = list(D)
ans = float("inf")
for Y in D:
T = []
tmp = []
for j in range(N):
if A[j] >= Y:
tmp.append(A[j])
else:
if len(tmp) >= K:
tmp = sorted(tmp)
T += tmp[: len(tmp) - K + 1]
tmp = []
if len(tmp) >= K:
tmp = sorted(tmp)
T += tmp[: len(tmp) - K + 1]
if len(T) >= Q:
T = sorted(T)
T = T[:Q]
ans = min(ans, T[-1] - T[0])
print(ans)
| false | 26.666667 | [
"-a = list(map(int, input().split()))",
"+A = list(map(int, input().split()))",
"+D = set()",
"+for i in range(N):",
"+ D.add(A[i])",
"+D = list(D)",
"-for i in range(N):",
"+for Y in D:",
"+ T = []",
"- rec = []",
"- if a[i] <= a[j]:",
"- tmp.append(a[j])",
"+ if A[j] >= Y:",
"+ tmp.append(A[j])",
"- rec += tmp[: len(tmp) - K + 1]",
"+ T += tmp[: len(tmp) - K + 1]",
"- rec += tmp[: len(tmp) - K + 1]",
"- if Q <= len(rec):",
"- rec = sorted(rec)",
"- ans = min(ans, rec[Q - 1] - rec[0])",
"+ T += tmp[: len(tmp) - K + 1]",
"+ if len(T) >= Q:",
"+ T = sorted(T)",
"+ T = T[:Q]",
"+ ans = min(ans, T[-1] - T[0])"
] | false | 0.04069 | 0.041604 | 0.978031 | [
"s692618122",
"s371295280"
] |
u633068244 | p00515 | python | s113018882 | s769641316 | 20 | 10 | 4,188 | 4,188 | Accepted | Accepted | 50 | print(sum([max(40,eval(input())) for i in [1]*5])/5) | print(sum([max(8,eval(input())/5) for i in [1]*5])) | 1 | 1 | 45 | 44 | print(sum([max(40, eval(input())) for i in [1] * 5]) / 5)
| print(sum([max(8, eval(input()) / 5) for i in [1] * 5]))
| false | 0 | [
"-print(sum([max(40, eval(input())) for i in [1] * 5]) / 5)",
"+print(sum([max(8, eval(input()) / 5) for i in [1] * 5]))"
] | false | 0.047014 | 0.048556 | 0.968237 | [
"s113018882",
"s769641316"
] |
u191874006 | p03712 | python | s465541739 | s530304892 | 168 | 78 | 38,384 | 66,020 | Accepted | Accepted | 53.57 | #!/usr/bin/env python3
#ABC62 B
h,w = list(map(int,input().split()))
x = ['#']*(w+2)
a = [list(eval(input())) for _ in range(h)]
for i in range(h):
a[i].insert(0,'#')
a[i].append('#')
a.insert(0,x)
a.append(x)
for i in range(h+2):
print((''.join(a[i])))
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
h, w = LI()
a = ['#' + eval(input()) + '#' for _ in range(h)]
a = ['#'*(w+2)] + a + ['#'*(w+2)]
for i in a:
print(i) | 14 | 24 | 267 | 678 | #!/usr/bin/env python3
# ABC62 B
h, w = list(map(int, input().split()))
x = ["#"] * (w + 2)
a = [list(eval(input())) for _ in range(h)]
for i in range(h):
a[i].insert(0, "#")
a[i].append("#")
a.insert(0, x)
a.append(x)
for i in range(h + 2):
print(("".join(a[i])))
| #!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop, heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float("inf")
def I():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
h, w = LI()
a = ["#" + eval(input()) + "#" for _ in range(h)]
a = ["#" * (w + 2)] + a + ["#" * (w + 2)]
for i in a:
print(i)
| false | 41.666667 | [
"-# ABC62 B",
"-h, w = list(map(int, input().split()))",
"-x = [\"#\"] * (w + 2)",
"-a = [list(eval(input())) for _ in range(h)]",
"-for i in range(h):",
"- a[i].insert(0, \"#\")",
"- a[i].append(\"#\")",
"-a.insert(0, x)",
"-a.append(x)",
"-for i in range(h + 2):",
"- print((\"\".join(a[i])))",
"+import sys",
"+import math",
"+from bisect import bisect_right as br",
"+from bisect import bisect_left as bl",
"+",
"+sys.setrecursionlimit(2147483647)",
"+from heapq import heappush, heappop, heappushpop",
"+from collections import defaultdict",
"+from itertools import accumulate",
"+from collections import Counter",
"+from collections import deque",
"+from operator import itemgetter",
"+from itertools import permutations",
"+",
"+mod = 10**9 + 7",
"+inf = float(\"inf\")",
"+",
"+",
"+def I():",
"+ return int(sys.stdin.readline())",
"+",
"+",
"+def LI():",
"+ return list(map(int, sys.stdin.readline().split()))",
"+",
"+",
"+h, w = LI()",
"+a = [\"#\" + eval(input()) + \"#\" for _ in range(h)]",
"+a = [\"#\" * (w + 2)] + a + [\"#\" * (w + 2)]",
"+for i in a:",
"+ print(i)"
] | false | 0.044988 | 0.044485 | 1.011306 | [
"s465541739",
"s530304892"
] |
u707498674 | p02703 | python | s437623083 | s578317329 | 1,156 | 1,028 | 39,268 | 36,544 | Accepted | Accepted | 11.07 | from heapq import heappop, heappush
import sys
def input():return sys.stdin.readline().strip()
def main():
N, M, S = list(map(int, input().split()))
to = [{} for _ in range(N)]
for _ in range(M):
u, v, a, b = list(map(int, input().split()))
u -= 1
v -= 1
to[u][v] = (a, b)
to[v][u] = (a, b)
info = tuple(tuple(map(int, input().split())) for _ in range(N))
MAX_SILVER = 50 * (N-1)
INF = 10 ** 18
# dijkstra (time, vertex, money)
visited = [[False]*(MAX_SILVER+1) for _ in range(N)]
cost = [[INF]*(MAX_SILVER+1) for _ in range(N)]
q = []
S = min(S, MAX_SILVER)
heappush(q, (0, 0, S)) # (time, vertex, silver)
while q:
t, now, s = heappop(q)
if visited[now][s]:continue
visited[now][s] = True
cost[now][s] = t
# next node
for nv, (a, b) in list(to[now].items()):
nt = t + b
rest = s - a
if rest >= 0:
if cost[nv][rest] <= nt : continue
heappush(q, (nt, nv, rest))
# exchange gold with silver
rate, time = info[now]
nt = t + time
ns = min(s+rate, MAX_SILVER)
heappush(q, (nt, now, ns))
for i in range(1, N):
print((min(cost[i])))
if __name__ == "__main__":
main() | from heapq import heappop, heappush
import sys
def input():return sys.stdin.readline().strip()
def main():
N, M, S = list(map(int, input().split()))
to = [{} for _ in range(N)]
for _ in range(M):
u, v, a, b = list(map(int, input().split()))
u -= 1
v -= 1
to[u][v] = (a, b)
to[v][u] = (a, b)
info = tuple(tuple(map(int, input().split())) for _ in range(N))
MAX_SILVER = 50 * (N-1)
INF = 10 ** 18
# dijkstra (time, vertex, money)
visited = [[False]*(MAX_SILVER+1) for _ in range(N)]
cost = [[INF]*(MAX_SILVER+1) for _ in range(N)]
q = []
S = min(S, MAX_SILVER)
heappush(q, (0, 0, S)) # (time, vertex, silver)
while q:
t, now, s = heappop(q)
if visited[now][s]:continue
visited[now][s] = True
cost[now][s] = t
# next node
for nv, (a, b) in list(to[now].items()):
nt = t + b
rest = s - a
if rest >= 0:
if cost[nv][rest] <= nt : continue
heappush(q, (nt, nv, rest))
# exchange gold with silver
rate, time = info[now]
nt = t + time
ns = min(s+rate, MAX_SILVER)
if cost[now][ns] <= nt : continue
heappush(q, (nt, now, ns))
for i in range(1, N):
print((min(cost[i])))
if __name__ == "__main__":
main() | 51 | 52 | 1,384 | 1,427 | from heapq import heappop, heappush
import sys
def input():
return sys.stdin.readline().strip()
def main():
N, M, S = list(map(int, input().split()))
to = [{} for _ in range(N)]
for _ in range(M):
u, v, a, b = list(map(int, input().split()))
u -= 1
v -= 1
to[u][v] = (a, b)
to[v][u] = (a, b)
info = tuple(tuple(map(int, input().split())) for _ in range(N))
MAX_SILVER = 50 * (N - 1)
INF = 10**18
# dijkstra (time, vertex, money)
visited = [[False] * (MAX_SILVER + 1) for _ in range(N)]
cost = [[INF] * (MAX_SILVER + 1) for _ in range(N)]
q = []
S = min(S, MAX_SILVER)
heappush(q, (0, 0, S)) # (time, vertex, silver)
while q:
t, now, s = heappop(q)
if visited[now][s]:
continue
visited[now][s] = True
cost[now][s] = t
# next node
for nv, (a, b) in list(to[now].items()):
nt = t + b
rest = s - a
if rest >= 0:
if cost[nv][rest] <= nt:
continue
heappush(q, (nt, nv, rest))
# exchange gold with silver
rate, time = info[now]
nt = t + time
ns = min(s + rate, MAX_SILVER)
heappush(q, (nt, now, ns))
for i in range(1, N):
print((min(cost[i])))
if __name__ == "__main__":
main()
| from heapq import heappop, heappush
import sys
def input():
return sys.stdin.readline().strip()
def main():
N, M, S = list(map(int, input().split()))
to = [{} for _ in range(N)]
for _ in range(M):
u, v, a, b = list(map(int, input().split()))
u -= 1
v -= 1
to[u][v] = (a, b)
to[v][u] = (a, b)
info = tuple(tuple(map(int, input().split())) for _ in range(N))
MAX_SILVER = 50 * (N - 1)
INF = 10**18
# dijkstra (time, vertex, money)
visited = [[False] * (MAX_SILVER + 1) for _ in range(N)]
cost = [[INF] * (MAX_SILVER + 1) for _ in range(N)]
q = []
S = min(S, MAX_SILVER)
heappush(q, (0, 0, S)) # (time, vertex, silver)
while q:
t, now, s = heappop(q)
if visited[now][s]:
continue
visited[now][s] = True
cost[now][s] = t
# next node
for nv, (a, b) in list(to[now].items()):
nt = t + b
rest = s - a
if rest >= 0:
if cost[nv][rest] <= nt:
continue
heappush(q, (nt, nv, rest))
# exchange gold with silver
rate, time = info[now]
nt = t + time
ns = min(s + rate, MAX_SILVER)
if cost[now][ns] <= nt:
continue
heappush(q, (nt, now, ns))
for i in range(1, N):
print((min(cost[i])))
if __name__ == "__main__":
main()
| false | 1.923077 | [
"+ if cost[now][ns] <= nt:",
"+ continue"
] | false | 0.124245 | 0.114805 | 1.082227 | [
"s437623083",
"s578317329"
] |
u130900604 | p03476 | python | s353729530 | s023426004 | 876 | 437 | 7,124 | 82,920 | Accepted | Accepted | 50.11 | # coding: utf-8
# Your code here!
U=10**5
is_prime=[True]*(U+1)
is_prime[0]=False
is_prime[1]=False
for p in range(2,U+1):
if p*p>U:
break
if is_prime[p]:
for j in range(p*p,U+1,p):
is_prime[j]=False
is_2017like=[0]*(U+1)
for p in range(1,U+1):
if (p+1)//2>U:
break
tmp=(is_prime[p] and is_prime[(p+1)//2])
is_2017like[p]=is_2017like[p-1]+tmp
for i in range(int(eval(input()))):
l,r=list(map(int,input().split()))
ans=is_2017like[r]-is_2017like[l-1]
print(ans)
| def like2017(x):
if isprime[x]:
if isprime[(x+1)//2]:
return True
return False
n=108000
isprime=[True]*(n+1)
isprime[0]=isprime[1]=False
for i in range(2,n+1):
if isprime[i]:
for j in range(i*i,n+1,i):
isprime[j]=False
cum=[]
cum.append(like2017(0))
for i in range(1,n+1):
tmp=0
if isprime[i]:
if isprime[(i+1)//2]:
tmp=1
cum.append(cum[-1]+tmp)
#print(cum)
q=int(eval(input()))
for _ in range(q):
l,r=list(map(int,input().split()))
print((cum[r]-cum[l-1]))
| 24 | 27 | 546 | 519 | # coding: utf-8
# Your code here!
U = 10**5
is_prime = [True] * (U + 1)
is_prime[0] = False
is_prime[1] = False
for p in range(2, U + 1):
if p * p > U:
break
if is_prime[p]:
for j in range(p * p, U + 1, p):
is_prime[j] = False
is_2017like = [0] * (U + 1)
for p in range(1, U + 1):
if (p + 1) // 2 > U:
break
tmp = is_prime[p] and is_prime[(p + 1) // 2]
is_2017like[p] = is_2017like[p - 1] + tmp
for i in range(int(eval(input()))):
l, r = list(map(int, input().split()))
ans = is_2017like[r] - is_2017like[l - 1]
print(ans)
| def like2017(x):
if isprime[x]:
if isprime[(x + 1) // 2]:
return True
return False
n = 108000
isprime = [True] * (n + 1)
isprime[0] = isprime[1] = False
for i in range(2, n + 1):
if isprime[i]:
for j in range(i * i, n + 1, i):
isprime[j] = False
cum = []
cum.append(like2017(0))
for i in range(1, n + 1):
tmp = 0
if isprime[i]:
if isprime[(i + 1) // 2]:
tmp = 1
cum.append(cum[-1] + tmp)
# print(cum)
q = int(eval(input()))
for _ in range(q):
l, r = list(map(int, input().split()))
print((cum[r] - cum[l - 1]))
| false | 11.111111 | [
"-# coding: utf-8",
"-# Your code here!",
"-U = 10**5",
"-is_prime = [True] * (U + 1)",
"-is_prime[0] = False",
"-is_prime[1] = False",
"-for p in range(2, U + 1):",
"- if p * p > U:",
"- break",
"- if is_prime[p]:",
"- for j in range(p * p, U + 1, p):",
"- is_prime[j] = False",
"-is_2017like = [0] * (U + 1)",
"-for p in range(1, U + 1):",
"- if (p + 1) // 2 > U:",
"- break",
"- tmp = is_prime[p] and is_prime[(p + 1) // 2]",
"- is_2017like[p] = is_2017like[p - 1] + tmp",
"-for i in range(int(eval(input()))):",
"+def like2017(x):",
"+ if isprime[x]:",
"+ if isprime[(x + 1) // 2]:",
"+ return True",
"+ return False",
"+",
"+",
"+n = 108000",
"+isprime = [True] * (n + 1)",
"+isprime[0] = isprime[1] = False",
"+for i in range(2, n + 1):",
"+ if isprime[i]:",
"+ for j in range(i * i, n + 1, i):",
"+ isprime[j] = False",
"+cum = []",
"+cum.append(like2017(0))",
"+for i in range(1, n + 1):",
"+ tmp = 0",
"+ if isprime[i]:",
"+ if isprime[(i + 1) // 2]:",
"+ tmp = 1",
"+ cum.append(cum[-1] + tmp)",
"+# print(cum)",
"+q = int(eval(input()))",
"+for _ in range(q):",
"- ans = is_2017like[r] - is_2017like[l - 1]",
"- print(ans)",
"+ print((cum[r] - cum[l - 1]))"
] | false | 0.1967 | 0.116563 | 1.687505 | [
"s353729530",
"s023426004"
] |
u592547545 | p02842 | python | s050447132 | s431195805 | 31 | 27 | 9,188 | 9,184 | Accepted | Accepted | 12.9 | def readinput():
n=int(eval(input()))
return n
def main(n):
x7=int(n/1.07)
x8=int(n/1.08)
x9=int(n/1.09)
n100=n*100
for x in range(max(1,x9-1),x7+1+1):
xx=x*108//100
#print(x,xx)
if xx==n:
print(x)
break
else:
print(':(')
if __name__=='__main__':
n=readinput()
main(n)
| def readinput():
n=int(eval(input()))
return n
def main(n):
x7=int(n/1.07)+1
x9=int(n/1.09)-1
n100=n*100
for x in range(max(1,x9),x7+1):
xx=x*108//100
#print(x,xx)
if xx==n:
print(x)
break
else:
print(':(')
if __name__=='__main__':
n=readinput()
main(n)
| 23 | 22 | 393 | 373 | def readinput():
n = int(eval(input()))
return n
def main(n):
x7 = int(n / 1.07)
x8 = int(n / 1.08)
x9 = int(n / 1.09)
n100 = n * 100
for x in range(max(1, x9 - 1), x7 + 1 + 1):
xx = x * 108 // 100
# print(x,xx)
if xx == n:
print(x)
break
else:
print(":(")
if __name__ == "__main__":
n = readinput()
main(n)
| def readinput():
n = int(eval(input()))
return n
def main(n):
x7 = int(n / 1.07) + 1
x9 = int(n / 1.09) - 1
n100 = n * 100
for x in range(max(1, x9), x7 + 1):
xx = x * 108 // 100
# print(x,xx)
if xx == n:
print(x)
break
else:
print(":(")
if __name__ == "__main__":
n = readinput()
main(n)
| false | 4.347826 | [
"- x7 = int(n / 1.07)",
"- x8 = int(n / 1.08)",
"- x9 = int(n / 1.09)",
"+ x7 = int(n / 1.07) + 1",
"+ x9 = int(n / 1.09) - 1",
"- for x in range(max(1, x9 - 1), x7 + 1 + 1):",
"+ for x in range(max(1, x9), x7 + 1):"
] | false | 0.04492 | 0.046178 | 0.972753 | [
"s050447132",
"s431195805"
] |
u350049649 | p03078 | python | s578854341 | s695576165 | 688 | 40 | 8,708 | 5,224 | Accepted | Accepted | 94.19 | X, Y, Z, K= list(map(int,input().split()))
A=list(map(int,input().split()))
A.sort(reverse=True)
B=list(map(int,input().split()))
B.sort(reverse=True)
C=list(map(int,input().split()))
C.sort(reverse=True)
ABC=[]
for i in range(X):
for j in range(Y):
for k in range(Z):
if (i+1)*(j+1)*(k+1)<=K:
ABC.append(A[i] + B[j] + C[k])
else:
break
ABC.sort(reverse=True)
for i in range(K):
print((ABC[i])) | import heapq
hq=[]
X, Y, Z, K= list(map(int,input().split()))
A=list(map(int,input().split()))
A.sort(reverse=True)
B=list(map(int,input().split()))
B.sort(reverse=True)
C=list(map(int,input().split()))
C.sort(reverse=True)
searched={(0,0,0)}
heapq.heappush(hq,(-(A[0]+B[0]+C[0]),0,0,0))
D=[[1,0,0],[0,1,0],[0,0,1]]
for _ in range(K):
abc,x,y,z=heapq.heappop(hq)
print((-abc))
for dx,dy,dz in D:
if x+dx<X and y+dy < Y and z+dz < Z and (x+dx,y+dy,z+dz) not in searched:
heapq.heappush(hq,(-(A[x+dx]+B[y+dy]+C[z+dz]),x+dx,y+dy,z+dz))
searched.add((x+dx,y+dy,z+dz)) | 21 | 20 | 481 | 619 | X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort(reverse=True)
B = list(map(int, input().split()))
B.sort(reverse=True)
C = list(map(int, input().split()))
C.sort(reverse=True)
ABC = []
for i in range(X):
for j in range(Y):
for k in range(Z):
if (i + 1) * (j + 1) * (k + 1) <= K:
ABC.append(A[i] + B[j] + C[k])
else:
break
ABC.sort(reverse=True)
for i in range(K):
print((ABC[i]))
| import heapq
hq = []
X, Y, Z, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort(reverse=True)
B = list(map(int, input().split()))
B.sort(reverse=True)
C = list(map(int, input().split()))
C.sort(reverse=True)
searched = {(0, 0, 0)}
heapq.heappush(hq, (-(A[0] + B[0] + C[0]), 0, 0, 0))
D = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
for _ in range(K):
abc, x, y, z = heapq.heappop(hq)
print((-abc))
for dx, dy, dz in D:
if (
x + dx < X
and y + dy < Y
and z + dz < Z
and (x + dx, y + dy, z + dz) not in searched
):
heapq.heappush(
hq, (-(A[x + dx] + B[y + dy] + C[z + dz]), x + dx, y + dy, z + dz)
)
searched.add((x + dx, y + dy, z + dz))
| false | 4.761905 | [
"+import heapq",
"+",
"+hq = []",
"-ABC = []",
"-for i in range(X):",
"- for j in range(Y):",
"- for k in range(Z):",
"- if (i + 1) * (j + 1) * (k + 1) <= K:",
"- ABC.append(A[i] + B[j] + C[k])",
"- else:",
"- break",
"-ABC.sort(reverse=True)",
"-for i in range(K):",
"- print((ABC[i]))",
"+searched = {(0, 0, 0)}",
"+heapq.heappush(hq, (-(A[0] + B[0] + C[0]), 0, 0, 0))",
"+D = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]",
"+for _ in range(K):",
"+ abc, x, y, z = heapq.heappop(hq)",
"+ print((-abc))",
"+ for dx, dy, dz in D:",
"+ if (",
"+ x + dx < X",
"+ and y + dy < Y",
"+ and z + dz < Z",
"+ and (x + dx, y + dy, z + dz) not in searched",
"+ ):",
"+ heapq.heappush(",
"+ hq, (-(A[x + dx] + B[y + dy] + C[z + dz]), x + dx, y + dy, z + dz)",
"+ )",
"+ searched.add((x + dx, y + dy, z + dz))"
] | false | 0.077235 | 0.036482 | 2.117062 | [
"s578854341",
"s695576165"
] |
u796060588 | p03274 | python | s384806048 | s882767831 | 106 | 88 | 11,880 | 11,880 | Accepted | Accepted | 16.98 | # vim: set fileencoding=utf-8:
import bisect
def main():
N, K = list(map(int, input().split()))
x = [int(ele) for ele in input().split()]
o = bisect.bisect_right(x, 0)
top = min(o + K, N)
bottom = max(o - K, 0)
best = 999999999999
for i in range(K):
if top < bottom + i + K:
break
if x[bottom + i + K - 1] < 0:
best = min(best, abs(x[bottom + i]))
elif x[bottom + i] < 0 <= x[bottom + i + K - 1]:
ans1 = 2 * min(abs(x[bottom + i]), x[bottom + i + K - 1])
ans2 = max(abs(x[bottom + i]), x[bottom + i + K - 1])
ans = min(best, ans1 + ans2)
best = min(best, ans)
elif 0 <= x[bottom + i]:
best = min(best, x[bottom + i + K - 1])
print(best)
if __name__ == "__main__":
main()
| # vim: set fileencoding=utf-8:
import bisect
def main():
N, K = list(map(int, input().split()))
x = [int(ele) for ele in input().split()]
o = bisect.bisect_right(x, 0)
top = min(o + K, N)
bottom = max(o - K, 0)
best = 999999999999
for i in range(K):
if top < bottom + i + K:
break
l = x[bottom + i]
r = x[bottom + i + K - 1]
if l < 0 <= r:
best = min(best, 2 * min(abs(l), r) + max(abs(l), r))
elif l < 0 and r < 0:
best = min(best, abs(l))
elif 0 <= l and 0 <= r:
best = min(best, abs(r))
print(best)
if __name__ == "__main__":
main()
| 30 | 29 | 861 | 705 | # vim: set fileencoding=utf-8:
import bisect
def main():
N, K = list(map(int, input().split()))
x = [int(ele) for ele in input().split()]
o = bisect.bisect_right(x, 0)
top = min(o + K, N)
bottom = max(o - K, 0)
best = 999999999999
for i in range(K):
if top < bottom + i + K:
break
if x[bottom + i + K - 1] < 0:
best = min(best, abs(x[bottom + i]))
elif x[bottom + i] < 0 <= x[bottom + i + K - 1]:
ans1 = 2 * min(abs(x[bottom + i]), x[bottom + i + K - 1])
ans2 = max(abs(x[bottom + i]), x[bottom + i + K - 1])
ans = min(best, ans1 + ans2)
best = min(best, ans)
elif 0 <= x[bottom + i]:
best = min(best, x[bottom + i + K - 1])
print(best)
if __name__ == "__main__":
main()
| # vim: set fileencoding=utf-8:
import bisect
def main():
N, K = list(map(int, input().split()))
x = [int(ele) for ele in input().split()]
o = bisect.bisect_right(x, 0)
top = min(o + K, N)
bottom = max(o - K, 0)
best = 999999999999
for i in range(K):
if top < bottom + i + K:
break
l = x[bottom + i]
r = x[bottom + i + K - 1]
if l < 0 <= r:
best = min(best, 2 * min(abs(l), r) + max(abs(l), r))
elif l < 0 and r < 0:
best = min(best, abs(l))
elif 0 <= l and 0 <= r:
best = min(best, abs(r))
print(best)
if __name__ == "__main__":
main()
| false | 3.333333 | [
"- if x[bottom + i + K - 1] < 0:",
"- best = min(best, abs(x[bottom + i]))",
"- elif x[bottom + i] < 0 <= x[bottom + i + K - 1]:",
"- ans1 = 2 * min(abs(x[bottom + i]), x[bottom + i + K - 1])",
"- ans2 = max(abs(x[bottom + i]), x[bottom + i + K - 1])",
"- ans = min(best, ans1 + ans2)",
"- best = min(best, ans)",
"- elif 0 <= x[bottom + i]:",
"- best = min(best, x[bottom + i + K - 1])",
"+ l = x[bottom + i]",
"+ r = x[bottom + i + K - 1]",
"+ if l < 0 <= r:",
"+ best = min(best, 2 * min(abs(l), r) + max(abs(l), r))",
"+ elif l < 0 and r < 0:",
"+ best = min(best, abs(l))",
"+ elif 0 <= l and 0 <= r:",
"+ best = min(best, abs(r))"
] | false | 0.065258 | 0.035753 | 1.825237 | [
"s384806048",
"s882767831"
] |
u670180528 | p03043 | python | s193747837 | s394848751 | 179 | 59 | 39,536 | 2,940 | Accepted | Accepted | 67.04 | n,k = list(map(int, input().split()))
ans = 0
for i in range(n):
score = i+1
count = 0
while score <= k-1:
count += 1
temp = score
score = temp*2
ans += 1/n * ((1/2)**count)
print(ans) | n,k=list(map(int, input().split()))
a=0
for i in range(n):
s=i+1;c=0
while s<=k-1:
c+=1;s*=2
a+=1/n*(1/2**c)
print(a) | 11 | 8 | 209 | 129 | n, k = list(map(int, input().split()))
ans = 0
for i in range(n):
score = i + 1
count = 0
while score <= k - 1:
count += 1
temp = score
score = temp * 2
ans += 1 / n * ((1 / 2) ** count)
print(ans)
| n, k = list(map(int, input().split()))
a = 0
for i in range(n):
s = i + 1
c = 0
while s <= k - 1:
c += 1
s *= 2
a += 1 / n * (1 / 2**c)
print(a)
| false | 27.272727 | [
"-ans = 0",
"+a = 0",
"- score = i + 1",
"- count = 0",
"- while score <= k - 1:",
"- count += 1",
"- temp = score",
"- score = temp * 2",
"- ans += 1 / n * ((1 / 2) ** count)",
"-print(ans)",
"+ s = i + 1",
"+ c = 0",
"+ while s <= k - 1:",
"+ c += 1",
"+ s *= 2",
"+ a += 1 / n * (1 / 2**c)",
"+print(a)"
] | false | 0.05828 | 0.062711 | 0.929343 | [
"s193747837",
"s394848751"
] |
u533039576 | p03241 | python | s161469678 | s276676236 | 468 | 20 | 40,044 | 3,060 | Accepted | Accepted | 95.73 | n, m = list(map(int, input().split()))
p = m // n
while m % p != 0:
p -= 1
print(p)
| import math
n, m = list(map(int, input().split()))
def divisor(m):
ans = []
for i in range(1, int(math.sqrt(m)) + 1):
if m % i == 0:
ans.append(i)
ans.append(m // i)
return sorted(ans)
divs = divisor(m)
j = len(divs) - 1
while True:
if divs[j] * n <= m:
print((divs[j]))
break
j -= 1
| 7 | 20 | 90 | 367 | n, m = list(map(int, input().split()))
p = m // n
while m % p != 0:
p -= 1
print(p)
| import math
n, m = list(map(int, input().split()))
def divisor(m):
ans = []
for i in range(1, int(math.sqrt(m)) + 1):
if m % i == 0:
ans.append(i)
ans.append(m // i)
return sorted(ans)
divs = divisor(m)
j = len(divs) - 1
while True:
if divs[j] * n <= m:
print((divs[j]))
break
j -= 1
| false | 65 | [
"+import math",
"+",
"-p = m // n",
"-while m % p != 0:",
"- p -= 1",
"-print(p)",
"+",
"+",
"+def divisor(m):",
"+ ans = []",
"+ for i in range(1, int(math.sqrt(m)) + 1):",
"+ if m % i == 0:",
"+ ans.append(i)",
"+ ans.append(m // i)",
"+ return sorted(ans)",
"+",
"+",
"+divs = divisor(m)",
"+j = len(divs) - 1",
"+while True:",
"+ if divs[j] * n <= m:",
"+ print((divs[j]))",
"+ break",
"+ j -= 1"
] | false | 0.051211 | 0.037 | 1.384066 | [
"s161469678",
"s276676236"
] |
u581187895 | p03579 | python | s521155409 | s083211406 | 549 | 499 | 55,780 | 34,652 | Accepted | Accepted | 9.11 | import sys
sys.setrecursionlimit(10 ** 7)
N, M = list(map(int, input().split()))
AB = [[int(x) for x in input().split()] for _ in range(M)]
G = [[] for _ in range(N+1)]
for a,b in AB:
G[a].append(b)
G[b].append(a)
color = [None]*(N+1)
# 二部グラフ判定
def dfs(v, c):
color[v] = c
for e in G[v]:
if color[e] == None:
color[e] = 1 - color[v]
dfs(e, c^1) # c^1 == xor (0+1==True)
dfs(1, 0)
bl = all(color[a] != color[b] for a, b in AB)
# ans
if bl:
# 二部グラフ
x = sum(color[1:])
y = N-x
print((x*y-M))
else:
# 完全グラフ
print((N*(N-1)//2-M)) | import sys
sys.setrecursionlimit(10 ** 7)
N, M = list(map(int, input().split()))
AB = [[int(x) for x in input().split()] for _ in range(M)]
G = [[] for _ in range(N+1)]
for a,b in AB:
G[a].append(b)
G[b].append(a)
color = [None]*(N+1)
color[1] = 0
q = [1]
# 二部グラフ判定
while q:
x = q.pop()
for y in G[x]:
if color[y] is None:
color[y] = 1 - color[x]
q.append(y)
bl = all(color[a] != color[b] for a, b in AB)
# ans
if bl:
# 二部グラフ
x = sum(color[1:])
y = N-x
print((x*y-M))
else:
# 完全グラフ
print((N*(N-1)//2-M)) | 28 | 29 | 600 | 568 | import sys
sys.setrecursionlimit(10**7)
N, M = list(map(int, input().split()))
AB = [[int(x) for x in input().split()] for _ in range(M)]
G = [[] for _ in range(N + 1)]
for a, b in AB:
G[a].append(b)
G[b].append(a)
color = [None] * (N + 1)
# 二部グラフ判定
def dfs(v, c):
color[v] = c
for e in G[v]:
if color[e] == None:
color[e] = 1 - color[v]
dfs(e, c ^ 1) # c^1 == xor (0+1==True)
dfs(1, 0)
bl = all(color[a] != color[b] for a, b in AB)
# ans
if bl:
# 二部グラフ
x = sum(color[1:])
y = N - x
print((x * y - M))
else:
# 完全グラフ
print((N * (N - 1) // 2 - M))
| import sys
sys.setrecursionlimit(10**7)
N, M = list(map(int, input().split()))
AB = [[int(x) for x in input().split()] for _ in range(M)]
G = [[] for _ in range(N + 1)]
for a, b in AB:
G[a].append(b)
G[b].append(a)
color = [None] * (N + 1)
color[1] = 0
q = [1]
# 二部グラフ判定
while q:
x = q.pop()
for y in G[x]:
if color[y] is None:
color[y] = 1 - color[x]
q.append(y)
bl = all(color[a] != color[b] for a, b in AB)
# ans
if bl:
# 二部グラフ
x = sum(color[1:])
y = N - x
print((x * y - M))
else:
# 完全グラフ
print((N * (N - 1) // 2 - M))
| false | 3.448276 | [
"+color[1] = 0",
"+q = [1]",
"-def dfs(v, c):",
"- color[v] = c",
"- for e in G[v]:",
"- if color[e] == None:",
"- color[e] = 1 - color[v]",
"- dfs(e, c ^ 1) # c^1 == xor (0+1==True)",
"-",
"-",
"-dfs(1, 0)",
"+while q:",
"+ x = q.pop()",
"+ for y in G[x]:",
"+ if color[y] is None:",
"+ color[y] = 1 - color[x]",
"+ q.append(y)"
] | false | 0.038806 | 0.089638 | 0.432916 | [
"s521155409",
"s083211406"
] |
u367130284 | p03387 | python | s621881511 | s292318300 | 20 | 18 | 2,940 | 2,940 | Accepted | Accepted | 10 | a=list(map(int,input().split()))
s=max(a)*3-sum(a);print(([s//2+2,s//2][s%2<1])) | a,b,c=sorted(map(int,input().split()))
print((c-b+(b-a+1)//2+((b-a)&1))) | 2 | 2 | 79 | 71 | a = list(map(int, input().split()))
s = max(a) * 3 - sum(a)
print(([s // 2 + 2, s // 2][s % 2 < 1]))
| a, b, c = sorted(map(int, input().split()))
print((c - b + (b - a + 1) // 2 + ((b - a) & 1)))
| false | 0 | [
"-a = list(map(int, input().split()))",
"-s = max(a) * 3 - sum(a)",
"-print(([s // 2 + 2, s // 2][s % 2 < 1]))",
"+a, b, c = sorted(map(int, input().split()))",
"+print((c - b + (b - a + 1) // 2 + ((b - a) & 1)))"
] | false | 0.048129 | 0.047856 | 1.005703 | [
"s621881511",
"s292318300"
] |
u057109575 | p02780 | python | s681292907 | s516991545 | 118 | 107 | 106,000 | 98,660 | Accepted | Accepted | 9.32 | N, K, *X = list(map(int, open(0).read().split()))
y = [float(x * (x + 1) / 2 / x) for x in X]
ans = sum(y[:K])
res = ans
for i in range(K, N):
res = res - y[i - K] + y[i]
ans = max(ans, res)
print(ans)
|
N, K = list(map(int, input().split()))
X = list(map(int, input().split()))
cur = sum((X[i] + 1) / 2 for i in range(K))
ans = cur
for i in range(K, N):
cur += (X[i] + 1) / 2 - (X[i - K] + 1) / 2
ans = max(ans, cur)
print(ans)
| 9 | 11 | 213 | 240 | N, K, *X = list(map(int, open(0).read().split()))
y = [float(x * (x + 1) / 2 / x) for x in X]
ans = sum(y[:K])
res = ans
for i in range(K, N):
res = res - y[i - K] + y[i]
ans = max(ans, res)
print(ans)
| N, K = list(map(int, input().split()))
X = list(map(int, input().split()))
cur = sum((X[i] + 1) / 2 for i in range(K))
ans = cur
for i in range(K, N):
cur += (X[i] + 1) / 2 - (X[i - K] + 1) / 2
ans = max(ans, cur)
print(ans)
| false | 18.181818 | [
"-N, K, *X = list(map(int, open(0).read().split()))",
"-y = [float(x * (x + 1) / 2 / x) for x in X]",
"-ans = sum(y[:K])",
"-res = ans",
"+N, K = list(map(int, input().split()))",
"+X = list(map(int, input().split()))",
"+cur = sum((X[i] + 1) / 2 for i in range(K))",
"+ans = cur",
"- res = res - y[i - K] + y[i]",
"- ans = max(ans, res)",
"+ cur += (X[i] + 1) / 2 - (X[i - K] + 1) / 2",
"+ ans = max(ans, cur)"
] | false | 0.036418 | 0.036834 | 0.988706 | [
"s681292907",
"s516991545"
] |
u203222829 | p02409 | python | s904142024 | s484944626 | 30 | 20 | 5,632 | 5,628 | Accepted | Accepted | 33.33 | # coding: utf-8
def showBuilding(buildings):
for i, tou in enumerate(buildings):
for wow in tou:
for room in wow:
print(' ' + str(room), end='')
print()
if i != 3:
print('####################')
if __name__ == '__main__':
buildings = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]
for _ in range(int(input())):
b, f, r, v = map(int, input().split())
if buildings[b - 1][f - 1][r - 1] + v >= 9:
buildings[b - 1][f - 1][r - 1] = 9
elif buildings[b - 1][f - 1][r - 1] + v < 0:
buildings[b - 1][f - 1][r - 1] = 0
else:
buildings[b - 1][f - 1][r - 1] += v
showBuilding(buildings)
| # coding: utf-8
def showBuilding(mansion):
for i, building in enumerate(mansion):
for line in building:
for room in line:
print(' ' + str(room), end='')
print()
if i != 3:
print('####################')
def calcMoving(mansion, moving_status):
b, f, r, v = moving_status
live_in_person = mansion[b-1][f-1][r-1]
if live_in_person + v >= 9:
live_in_person = 9
elif live_in_person + v < 0:
live_in_person = 0
else:
live_in_person += v
mansion[b-1][f-1][r-1] = live_in_person
if __name__ == '__main__':
mansion = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]
for _ in range(int(input())):
calcMoving(mansion, map(int, input().split()))
showBuilding(mansion)
| 28 | 32 | 797 | 860 | # coding: utf-8
def showBuilding(buildings):
for i, tou in enumerate(buildings):
for wow in tou:
for room in wow:
print(" " + str(room), end="")
print()
if i != 3:
print("####################")
if __name__ == "__main__":
buildings = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]
for _ in range(int(input())):
b, f, r, v = map(int, input().split())
if buildings[b - 1][f - 1][r - 1] + v >= 9:
buildings[b - 1][f - 1][r - 1] = 9
elif buildings[b - 1][f - 1][r - 1] + v < 0:
buildings[b - 1][f - 1][r - 1] = 0
else:
buildings[b - 1][f - 1][r - 1] += v
showBuilding(buildings)
| # coding: utf-8
def showBuilding(mansion):
for i, building in enumerate(mansion):
for line in building:
for room in line:
print(" " + str(room), end="")
print()
if i != 3:
print("####################")
def calcMoving(mansion, moving_status):
b, f, r, v = moving_status
live_in_person = mansion[b - 1][f - 1][r - 1]
if live_in_person + v >= 9:
live_in_person = 9
elif live_in_person + v < 0:
live_in_person = 0
else:
live_in_person += v
mansion[b - 1][f - 1][r - 1] = live_in_person
if __name__ == "__main__":
mansion = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]
for _ in range(int(input())):
calcMoving(mansion, map(int, input().split()))
showBuilding(mansion)
| false | 12.5 | [
"-def showBuilding(buildings):",
"- for i, tou in enumerate(buildings):",
"- for wow in tou:",
"- for room in wow:",
"+def showBuilding(mansion):",
"+ for i, building in enumerate(mansion):",
"+ for line in building:",
"+ for room in line:",
"+def calcMoving(mansion, moving_status):",
"+ b, f, r, v = moving_status",
"+ live_in_person = mansion[b - 1][f - 1][r - 1]",
"+ if live_in_person + v >= 9:",
"+ live_in_person = 9",
"+ elif live_in_person + v < 0:",
"+ live_in_person = 0",
"+ else:",
"+ live_in_person += v",
"+ mansion[b - 1][f - 1][r - 1] = live_in_person",
"+",
"+",
"- buildings = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]",
"+ mansion = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]",
"- b, f, r, v = map(int, input().split())",
"- if buildings[b - 1][f - 1][r - 1] + v >= 9:",
"- buildings[b - 1][f - 1][r - 1] = 9",
"- elif buildings[b - 1][f - 1][r - 1] + v < 0:",
"- buildings[b - 1][f - 1][r - 1] = 0",
"- else:",
"- buildings[b - 1][f - 1][r - 1] += v",
"- showBuilding(buildings)",
"+ calcMoving(mansion, map(int, input().split()))",
"+ showBuilding(mansion)"
] | false | 0.048432 | 0.047893 | 1.011249 | [
"s904142024",
"s484944626"
] |
u754022296 | p03083 | python | s738206694 | s161661718 | 783 | 618 | 36,796 | 36,768 | Accepted | Accepted | 21.07 | U = 2*10**5
MOD = 10**9+7
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
two = [1]*(U+1)
two_inv = [1]*(U+1)
for i in range(1,U+1):
fact[i] = (fact[i-1]*i)%MOD
two[i] = (two[i-1]*2)%MOD
fact_inv[U] = pow(fact[U], MOD-2, MOD)
two_inv[U] = pow(two[U], MOD-2, MOD)
for i in range(U,0,-1):
fact_inv[i-1] = (fact_inv[i]*i)%MOD
two_inv[i-1] = (two_inv[i]*2)%MOD
def comb(n, k):
if k < 0 or k > n:
return 0
z = fact[n]
z *= fact_inv[k]
z %= MOD
z *= fact_inv[n-k]
z %= MOD
return z
B, W = list(map(int, input().split()))
p = 0
q = 0
for i in range(1, B+W+1):
ans = 1 - p + q
ans %= MOD
ans *= two_inv[1]
ans %= MOD
print(ans)
p += comb(i-1, B-1) * two_inv[i] % MOD
p %= MOD
q += comb(i-1, W-1) * two_inv[i] % MOD
q %= MOD | def main():
U = 2*10**5
MOD = 10**9+7
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
two = [1]*(U+1)
two_inv = [1]*(U+1)
for i in range(1,U+1):
fact[i] = (fact[i-1]*i)%MOD
two[i] = (two[i-1]*2)%MOD
fact_inv[U] = pow(fact[U], MOD-2, MOD)
two_inv[U] = pow(two[U], MOD-2, MOD)
for i in range(U,0,-1):
fact_inv[i-1] = (fact_inv[i]*i)%MOD
two_inv[i-1] = (two_inv[i]*2)%MOD
def comb(n, k):
if k < 0 or k > n:
return 0
z = fact[n]
z *= fact_inv[k]
z %= MOD
z *= fact_inv[n-k]
z %= MOD
return z
B, W = list(map(int, input().split()))
p = 0
q = 0
for i in range(1, B+W+1):
ans = 1 - p + q
ans %= MOD
ans *= two_inv[1]
ans %= MOD
print(ans)
p += comb(i-1, B-1) * two_inv[i] % MOD
p %= MOD
q += comb(i-1, W-1) * two_inv[i] % MOD
q %= MOD
if __name__ == "__main__":
main() | 41 | 46 | 819 | 945 | U = 2 * 10**5
MOD = 10**9 + 7
fact = [1] * (U + 1)
fact_inv = [1] * (U + 1)
two = [1] * (U + 1)
two_inv = [1] * (U + 1)
for i in range(1, U + 1):
fact[i] = (fact[i - 1] * i) % MOD
two[i] = (two[i - 1] * 2) % MOD
fact_inv[U] = pow(fact[U], MOD - 2, MOD)
two_inv[U] = pow(two[U], MOD - 2, MOD)
for i in range(U, 0, -1):
fact_inv[i - 1] = (fact_inv[i] * i) % MOD
two_inv[i - 1] = (two_inv[i] * 2) % MOD
def comb(n, k):
if k < 0 or k > n:
return 0
z = fact[n]
z *= fact_inv[k]
z %= MOD
z *= fact_inv[n - k]
z %= MOD
return z
B, W = list(map(int, input().split()))
p = 0
q = 0
for i in range(1, B + W + 1):
ans = 1 - p + q
ans %= MOD
ans *= two_inv[1]
ans %= MOD
print(ans)
p += comb(i - 1, B - 1) * two_inv[i] % MOD
p %= MOD
q += comb(i - 1, W - 1) * two_inv[i] % MOD
q %= MOD
| def main():
U = 2 * 10**5
MOD = 10**9 + 7
fact = [1] * (U + 1)
fact_inv = [1] * (U + 1)
two = [1] * (U + 1)
two_inv = [1] * (U + 1)
for i in range(1, U + 1):
fact[i] = (fact[i - 1] * i) % MOD
two[i] = (two[i - 1] * 2) % MOD
fact_inv[U] = pow(fact[U], MOD - 2, MOD)
two_inv[U] = pow(two[U], MOD - 2, MOD)
for i in range(U, 0, -1):
fact_inv[i - 1] = (fact_inv[i] * i) % MOD
two_inv[i - 1] = (two_inv[i] * 2) % MOD
def comb(n, k):
if k < 0 or k > n:
return 0
z = fact[n]
z *= fact_inv[k]
z %= MOD
z *= fact_inv[n - k]
z %= MOD
return z
B, W = list(map(int, input().split()))
p = 0
q = 0
for i in range(1, B + W + 1):
ans = 1 - p + q
ans %= MOD
ans *= two_inv[1]
ans %= MOD
print(ans)
p += comb(i - 1, B - 1) * two_inv[i] % MOD
p %= MOD
q += comb(i - 1, W - 1) * two_inv[i] % MOD
q %= MOD
if __name__ == "__main__":
main()
| false | 10.869565 | [
"-U = 2 * 10**5",
"-MOD = 10**9 + 7",
"-fact = [1] * (U + 1)",
"-fact_inv = [1] * (U + 1)",
"-two = [1] * (U + 1)",
"-two_inv = [1] * (U + 1)",
"-for i in range(1, U + 1):",
"- fact[i] = (fact[i - 1] * i) % MOD",
"- two[i] = (two[i - 1] * 2) % MOD",
"-fact_inv[U] = pow(fact[U], MOD - 2, MOD)",
"-two_inv[U] = pow(two[U], MOD - 2, MOD)",
"-for i in range(U, 0, -1):",
"- fact_inv[i - 1] = (fact_inv[i] * i) % MOD",
"- two_inv[i - 1] = (two_inv[i] * 2) % MOD",
"+def main():",
"+ U = 2 * 10**5",
"+ MOD = 10**9 + 7",
"+ fact = [1] * (U + 1)",
"+ fact_inv = [1] * (U + 1)",
"+ two = [1] * (U + 1)",
"+ two_inv = [1] * (U + 1)",
"+ for i in range(1, U + 1):",
"+ fact[i] = (fact[i - 1] * i) % MOD",
"+ two[i] = (two[i - 1] * 2) % MOD",
"+ fact_inv[U] = pow(fact[U], MOD - 2, MOD)",
"+ two_inv[U] = pow(two[U], MOD - 2, MOD)",
"+ for i in range(U, 0, -1):",
"+ fact_inv[i - 1] = (fact_inv[i] * i) % MOD",
"+ two_inv[i - 1] = (two_inv[i] * 2) % MOD",
"+",
"+ def comb(n, k):",
"+ if k < 0 or k > n:",
"+ return 0",
"+ z = fact[n]",
"+ z *= fact_inv[k]",
"+ z %= MOD",
"+ z *= fact_inv[n - k]",
"+ z %= MOD",
"+ return z",
"+",
"+ B, W = list(map(int, input().split()))",
"+ p = 0",
"+ q = 0",
"+ for i in range(1, B + W + 1):",
"+ ans = 1 - p + q",
"+ ans %= MOD",
"+ ans *= two_inv[1]",
"+ ans %= MOD",
"+ print(ans)",
"+ p += comb(i - 1, B - 1) * two_inv[i] % MOD",
"+ p %= MOD",
"+ q += comb(i - 1, W - 1) * two_inv[i] % MOD",
"+ q %= MOD",
"-def comb(n, k):",
"- if k < 0 or k > n:",
"- return 0",
"- z = fact[n]",
"- z *= fact_inv[k]",
"- z %= MOD",
"- z *= fact_inv[n - k]",
"- z %= MOD",
"- return z",
"-",
"-",
"-B, W = list(map(int, input().split()))",
"-p = 0",
"-q = 0",
"-for i in range(1, B + W + 1):",
"- ans = 1 - p + q",
"- ans %= MOD",
"- ans *= two_inv[1]",
"- ans %= MOD",
"- print(ans)",
"- p += comb(i - 1, B - 1) * two_inv[i] % MOD",
"- p %= MOD",
"- q += comb(i - 1, W - 1) * two_inv[i] % MOD",
"- q %= MOD",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.551909 | 0.84646 | 0.65202 | [
"s738206694",
"s161661718"
] |
u309977459 | p03504 | python | s538592105 | s927256431 | 1,984 | 538 | 54,752 | 51,860 | Accepted | Accepted | 72.88 | from itertools import accumulate
N, C = list(map(int, input().split()))
STC = [list(map(int, input().split())) for _ in range(N)]
M = 10**5+1
merge = [[0]*(M+1) for _ in range(31)]
for i in range(N):
s, t, c = STC[i]
merge[c][s] += 1
merge[c][t+1] -= 1
for c in range(31):
merge[c] = list([int(bool(x)) for x in accumulate(merge[c])])
ans = []
for i in range(M+1):
res = 0
for j in range(31):
res += merge[j][i]
ans.append(res)
print((max(ans)))
| from itertools import accumulate
N, C = list(map(int, input().split()))
STC = [list(map(int, input().split())) for _ in range(N)]
M = 10**5+1
merge = [[0]*(M+1) for _ in range(31)]
for i in range(N):
s, t, c = STC[i]
#merge[c][s] += 1
#merge[c][t+1] -= 1
merge[c][s:t+1] = [1]*(t-s+1)
#for c in range(31):
# merge[c] = list(map(lambda x: int(bool(x)), accumulate(merge[c])))
print((max(list(map(sum, list(zip(*merge)))))))
#ans = []
#for i in range(M+1):
# res = 0
# for j in range(31):
# res += merge[j][i]
# ans.append(res)
#print(max(ans))
| 20 | 22 | 500 | 581 | from itertools import accumulate
N, C = list(map(int, input().split()))
STC = [list(map(int, input().split())) for _ in range(N)]
M = 10**5 + 1
merge = [[0] * (M + 1) for _ in range(31)]
for i in range(N):
s, t, c = STC[i]
merge[c][s] += 1
merge[c][t + 1] -= 1
for c in range(31):
merge[c] = list([int(bool(x)) for x in accumulate(merge[c])])
ans = []
for i in range(M + 1):
res = 0
for j in range(31):
res += merge[j][i]
ans.append(res)
print((max(ans)))
| from itertools import accumulate
N, C = list(map(int, input().split()))
STC = [list(map(int, input().split())) for _ in range(N)]
M = 10**5 + 1
merge = [[0] * (M + 1) for _ in range(31)]
for i in range(N):
s, t, c = STC[i]
# merge[c][s] += 1
# merge[c][t+1] -= 1
merge[c][s : t + 1] = [1] * (t - s + 1)
# for c in range(31):
# merge[c] = list(map(lambda x: int(bool(x)), accumulate(merge[c])))
print((max(list(map(sum, list(zip(*merge)))))))
# ans = []
# for i in range(M+1):
# res = 0
# for j in range(31):
# res += merge[j][i]
# ans.append(res)
# print(max(ans))
| false | 9.090909 | [
"- merge[c][s] += 1",
"- merge[c][t + 1] -= 1",
"-for c in range(31):",
"- merge[c] = list([int(bool(x)) for x in accumulate(merge[c])])",
"-ans = []",
"-for i in range(M + 1):",
"- res = 0",
"- for j in range(31):",
"- res += merge[j][i]",
"- ans.append(res)",
"-print((max(ans)))",
"+ # merge[c][s] += 1",
"+ # merge[c][t+1] -= 1",
"+ merge[c][s : t + 1] = [1] * (t - s + 1)",
"+# for c in range(31):",
"+# merge[c] = list(map(lambda x: int(bool(x)), accumulate(merge[c])))",
"+print((max(list(map(sum, list(zip(*merge)))))))",
"+# ans = []",
"+# for i in range(M+1):",
"+# res = 0",
"+# for j in range(31):",
"+# res += merge[j][i]",
"+# ans.append(res)",
"+# print(max(ans))"
] | false | 2.281797 | 0.531036 | 4.296879 | [
"s538592105",
"s927256431"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.