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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u754022296 | p02977 | python | s918531405 | s761588925 | 268 | 242 | 5,780 | 5,436 | Accepted | Accepted | 9.7 | n = int(eval(input()))
b = 1 << (n.bit_length()-1)
if n - b == 0:
print("No")
else:
print("Yes")
print((1, 2))
print((2, 3))
print((3, n+1))
print((n+1, n+2))
print((n+2, n+3))
for i in range(4, n, 2):
print((i, i+1))
print((i+n, i+n+1))
print((1+n, i+n))
print((1+n, i+1))
if (~n)&1:
print((n, b+n))
a = n ^ b ^ 1
print((n+n, a)) | n=int(input());p=print;b=1<<(n.bit_length()-1)
if n==b:p("No");exit()
p("Yes");p(n+1,n+2)
for i in range(3,n+1,2):p(1,i);p(1,i-1);p(i,n+i-1);p(i-1,n+i)
if~n&1:p(b,n);p(n^1^b,n+n)
| 20 | 5 | 367 | 182 | n = int(eval(input()))
b = 1 << (n.bit_length() - 1)
if n - b == 0:
print("No")
else:
print("Yes")
print((1, 2))
print((2, 3))
print((3, n + 1))
print((n + 1, n + 2))
print((n + 2, n + 3))
for i in range(4, n, 2):
print((i, i + 1))
print((i + n, i + n + 1))
print((1 + n, i + n))
print((1 + n, i + 1))
if (~n) & 1:
print((n, b + n))
a = n ^ b ^ 1
print((n + n, a))
| n = int(input())
p = print
b = 1 << (n.bit_length() - 1)
if n == b:
p("No")
exit()
p("Yes")
p(n + 1, n + 2)
for i in range(3, n + 1, 2):
p(1, i)
p(1, i - 1)
p(i, n + i - 1)
p(i - 1, n + i)
if ~n & 1:
p(b, n)
p(n ^ 1 ^ b, n + n)
| false | 75 | [
"-n = int(eval(input()))",
"+n = int(input())",
"+p = print",
"-if n - b == 0:",
"- print(\"No\")",
"-else:",
"- print(\"Yes\")",
"- print((1, 2))",
"- print((2, 3))",
"- print((3, n + 1))",
"- print((n + 1, n + 2))",
"- print((n + 2, n + 3))",
"- for i in range(4, n, 2):",
"- print((i, i + 1))",
"- print((i + n, i + n + 1))",
"- print((1 + n, i + n))",
"- print((1 + n, i + 1))",
"- if (~n) & 1:",
"- print((n, b + n))",
"- a = n ^ b ^ 1",
"- print((n + n, a))",
"+if n == b:",
"+ p(\"No\")",
"+ exit()",
"+p(\"Yes\")",
"+p(n + 1, n + 2)",
"+for i in range(3, n + 1, 2):",
"+ p(1, i)",
"+ p(1, i - 1)",
"+ p(i, n + i - 1)",
"+ p(i - 1, n + i)",
"+if ~n & 1:",
"+ p(b, n)",
"+ p(n ^ 1 ^ b, n + n)"
] | false | 0.041627 | 0.038195 | 1.089851 | [
"s918531405",
"s761588925"
] |
u143509139 | p02988 | python | s015756530 | s496835197 | 20 | 17 | 3,316 | 3,060 | Accepted | Accepted | 15 | n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
if a[i - 1] < a[i] < a[i + 1] or a[i - 1] > a[i] > a[i + 1]:
ans += 1
print(ans) | n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(n - 2):
if a[i] < a[i + 1] < a[i + 2]:
ans += 1
if a[i] > a[i + 1] > a[i + 2]:
ans += 1
print(ans) | 7 | 9 | 185 | 206 | n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(1, n - 1):
if a[i - 1] < a[i] < a[i + 1] or a[i - 1] > a[i] > a[i + 1]:
ans += 1
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for i in range(n - 2):
if a[i] < a[i + 1] < a[i + 2]:
ans += 1
if a[i] > a[i + 1] > a[i + 2]:
ans += 1
print(ans)
| false | 22.222222 | [
"-for i in range(1, n - 1):",
"- if a[i - 1] < a[i] < a[i + 1] or a[i - 1] > a[i] > a[i + 1]:",
"+for i in range(n - 2):",
"+ if a[i] < a[i + 1] < a[i + 2]:",
"+ ans += 1",
"+ if a[i] > a[i + 1] > a[i + 2]:"
] | false | 0.040036 | 0.038836 | 1.030899 | [
"s015756530",
"s496835197"
] |
u630941334 | p04015 | python | s637895782 | s611382911 | 1,557 | 1,348 | 54,088 | 58,612 | Accepted | Accepted | 13.42 | def main():
N, A = list(map(int, input().split()))
x = list(map(int, input().split()))
x.insert(0, 0)
dp = [[[0] * (N * A + 1) for _ in range(N + 1)] for _ in range(N + 1)]
for i in range(N + 1):
dp[i][0][0] = 1
for i in range(1, N + 1):
for j in range(1, i + 1):
for k in range(1, N * A + 1):
dp[i][j][k] = dp[i - 1][j][k]
if k >= x[i]:
dp[i][j][k] += dp[i - 1][j - 1][k - x[i]]
ans = 0
for j in range(1, N + 1):
ans += dp[N][j][A * j]
print(ans)
if __name__ == '__main__':
main()
| def main():
N, A = list(map(int, input().split()))
x = [0]
x.extend(list(map(int, input().split())))
dp = [[[0 for _ in range(N * A + 1)] for _ in range(N + 1)] for _ in range(N + 1)]
for i in range(N + 1):
dp[i][0][0] = 1
for i in range(1, N + 1):
for j in range(1, i + 1):
for k in range(1, N * A + 1):
if k < x[i]:
dp[i][j][k] = dp[i - 1][j][k]
else:
dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]]
ans = 0
for j in range(1, N + 1):
ans += dp[N][j][A * j]
print(ans)
if __name__ == '__main__':
main()
| 26 | 26 | 636 | 688 | def main():
N, A = list(map(int, input().split()))
x = list(map(int, input().split()))
x.insert(0, 0)
dp = [[[0] * (N * A + 1) for _ in range(N + 1)] for _ in range(N + 1)]
for i in range(N + 1):
dp[i][0][0] = 1
for i in range(1, N + 1):
for j in range(1, i + 1):
for k in range(1, N * A + 1):
dp[i][j][k] = dp[i - 1][j][k]
if k >= x[i]:
dp[i][j][k] += dp[i - 1][j - 1][k - x[i]]
ans = 0
for j in range(1, N + 1):
ans += dp[N][j][A * j]
print(ans)
if __name__ == "__main__":
main()
| def main():
N, A = list(map(int, input().split()))
x = [0]
x.extend(list(map(int, input().split())))
dp = [[[0 for _ in range(N * A + 1)] for _ in range(N + 1)] for _ in range(N + 1)]
for i in range(N + 1):
dp[i][0][0] = 1
for i in range(1, N + 1):
for j in range(1, i + 1):
for k in range(1, N * A + 1):
if k < x[i]:
dp[i][j][k] = dp[i - 1][j][k]
else:
dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]]
ans = 0
for j in range(1, N + 1):
ans += dp[N][j][A * j]
print(ans)
if __name__ == "__main__":
main()
| false | 0 | [
"- x = list(map(int, input().split()))",
"- x.insert(0, 0)",
"- dp = [[[0] * (N * A + 1) for _ in range(N + 1)] for _ in range(N + 1)]",
"+ x = [0]",
"+ x.extend(list(map(int, input().split())))",
"+ dp = [[[0 for _ in range(N * A + 1)] for _ in range(N + 1)] for _ in range(N + 1)]",
"- dp[i][j][k] = dp[i - 1][j][k]",
"- if k >= x[i]:",
"- dp[i][j][k] += dp[i - 1][j - 1][k - x[i]]",
"+ if k < x[i]:",
"+ dp[i][j][k] = dp[i - 1][j][k]",
"+ else:",
"+ dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]]"
] | false | 0.129507 | 0.121781 | 1.063449 | [
"s637895782",
"s611382911"
] |
u677267454 | p02955 | python | s328923131 | s616289414 | 244 | 151 | 3,188 | 3,064 | Accepted | Accepted | 38.11 | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
sumA = sum(A)
divisors = []
for i in range(1, sumA + 1):
if i * i > sumA:
break
if sumA % i != 0:
continue
divisors.append(i)
if sumA // i != i:
divisors.append(sumA // i)
divisors.sort(reverse=True)
ans = 0
for d in divisors:
costs = [a % d for a in A]
costs.sort(reverse=True)
plus = sum(costs)
minus = 0
for j in range(N):
if plus == minus:
break
else:
plus -= costs[j]
minus += d - costs[j]
if plus <= K:
print(d)
break | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
sumA = sum(A)
divisors = []
for i in range(1, sumA + 1):
if i * i > sumA:
break
if sumA % i != 0:
continue
divisors.append(i)
if sumA // i != i:
divisors.append(sumA // i)
divisors.sort(reverse=True)
for d in divisors:
# 一旦全部マイナス方向に調整することにしたら総和はXの倍数になる
# どれか一つ符号を逆転すると総和がx減るので、総和/d番目が境目になる
# A = [8, 20]
# d = 7
# costs = [1, 6]
# 20をプラス方向に調整することにすると、マイナス方向の調整は6減ってプラス方向に(7 - 1)増える
# 1個をマイナス方向をプラス方向に変更すると、マイナス方向のコストの総和の差とプラス方向のコストの総和の差がdだけ詰まる
# よって、最初全部マイナス方向に調整したときのコストの総和7を7で割ったところが境目
# プラス方向にはcostが大きい方から変更したい(調整の量が少なくてすむ)ので、最初にソートしておく
costs = [a % d for a in A]
costs.sort(reverse=True)
if sum(costs[sum(costs) // d:]) <= K:
print(d)
break
| 32 | 31 | 659 | 851 | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
sumA = sum(A)
divisors = []
for i in range(1, sumA + 1):
if i * i > sumA:
break
if sumA % i != 0:
continue
divisors.append(i)
if sumA // i != i:
divisors.append(sumA // i)
divisors.sort(reverse=True)
ans = 0
for d in divisors:
costs = [a % d for a in A]
costs.sort(reverse=True)
plus = sum(costs)
minus = 0
for j in range(N):
if plus == minus:
break
else:
plus -= costs[j]
minus += d - costs[j]
if plus <= K:
print(d)
break
| N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
sumA = sum(A)
divisors = []
for i in range(1, sumA + 1):
if i * i > sumA:
break
if sumA % i != 0:
continue
divisors.append(i)
if sumA // i != i:
divisors.append(sumA // i)
divisors.sort(reverse=True)
for d in divisors:
# 一旦全部マイナス方向に調整することにしたら総和はXの倍数になる
# どれか一つ符号を逆転すると総和がx減るので、総和/d番目が境目になる
# A = [8, 20]
# d = 7
# costs = [1, 6]
# 20をプラス方向に調整することにすると、マイナス方向の調整は6減ってプラス方向に(7 - 1)増える
# 1個をマイナス方向をプラス方向に変更すると、マイナス方向のコストの総和の差とプラス方向のコストの総和の差がdだけ詰まる
# よって、最初全部マイナス方向に調整したときのコストの総和7を7で割ったところが境目
# プラス方向にはcostが大きい方から変更したい(調整の量が少なくてすむ)ので、最初にソートしておく
costs = [a % d for a in A]
costs.sort(reverse=True)
if sum(costs[sum(costs) // d :]) <= K:
print(d)
break
| false | 3.125 | [
"-ans = 0",
"+ # 一旦全部マイナス方向に調整することにしたら総和はXの倍数になる",
"+ # どれか一つ符号を逆転すると総和がx減るので、総和/d番目が境目になる",
"+ # A = [8, 20]",
"+ # d = 7",
"+ # costs = [1, 6]",
"+ # 20をプラス方向に調整することにすると、マイナス方向の調整は6減ってプラス方向に(7 - 1)増える",
"+ # 1個をマイナス方向をプラス方向に変更すると、マイナス方向のコストの総和の差とプラス方向のコストの総和の差がdだけ詰まる",
"+ # よって、最初全部マイナス方向に調整したときのコストの総和7を7で割ったところが境目",
"+ # プラス方向にはcostが大きい方から変更したい(調整の量が少なくてすむ)ので、最初にソートしておく",
"- plus = sum(costs)",
"- minus = 0",
"- for j in range(N):",
"- if plus == minus:",
"- break",
"- else:",
"- plus -= costs[j]",
"- minus += d - costs[j]",
"- if plus <= K:",
"+ if sum(costs[sum(costs) // d :]) <= K:"
] | false | 0.054717 | 0.076352 | 0.716632 | [
"s328923131",
"s616289414"
] |
u106797249 | p03078 | python | s550487254 | s447229105 | 700 | 266 | 142,076 | 47,748 | Accepted | Accepted | 62 | def resolve():
X, Y, Z, K = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
AB = []
for a in A:
for b in B:
AB.append(a+b)
AB = sorted(AB, reverse=True)[:K]
ABC = []
for ab in AB:
for c in C:
ABC.append(ab+c)
ABC = sorted(ABC, reverse=True)
[print(ABC[i]) for i in range(K)]
if '__main__' == __name__:
resolve()
| def resolve():
X, Y, Z, K = list(map(int, input().split()))
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), 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):
break
ABC.append(A[i]+B[j]+C[k])
ABC = sorted(ABC, reverse=True)
[print(ABC[i]) for i in range(K)]
if '__main__' == __name__:
resolve()
| 21 | 18 | 538 | 590 | def resolve():
X, Y, Z, K = list(map(int, input().split()))
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
AB = []
for a in A:
for b in B:
AB.append(a + b)
AB = sorted(AB, reverse=True)[:K]
ABC = []
for ab in AB:
for c in C:
ABC.append(ab + c)
ABC = sorted(ABC, reverse=True)
[print(ABC[i]) for i in range(K)]
if "__main__" == __name__:
resolve()
| def resolve():
X, Y, Z, K = list(map(int, input().split()))
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), 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:
break
ABC.append(A[i] + B[j] + C[k])
ABC = sorted(ABC, reverse=True)
[print(ABC[i]) for i in range(K)]
if "__main__" == __name__:
resolve()
| false | 14.285714 | [
"- A = sorted(list(map(int, input().split())))",
"- B = sorted(list(map(int, input().split())))",
"- C = sorted(list(map(int, input().split())))",
"- AB = []",
"- for a in A:",
"- for b in B:",
"- AB.append(a + b)",
"- AB = sorted(AB, reverse=True)[:K]",
"+ A = sorted(list(map(int, input().split())), reverse=True)",
"+ B = sorted(list(map(int, input().split())), reverse=True)",
"+ C = sorted(list(map(int, input().split())), reverse=True)",
"- for ab in AB:",
"- for c in C:",
"- ABC.append(ab + c)",
"+ for i in range(X):",
"+ for j in range(Y):",
"+ for k in range(Z):",
"+ if (i + 1) * (j + 1) * (k + 1) > K:",
"+ break",
"+ ABC.append(A[i] + B[j] + C[k])"
] | false | 0.078004 | 0.077811 | 1.002485 | [
"s550487254",
"s447229105"
] |
u939814144 | p02258 | python | s669732265 | s155046021 | 470 | 160 | 7,700 | 21,936 | Accepted | Accepted | 65.96 | import sys
def get_maximum_profit():
element_number = int(eval(input()))
v0 = int(eval(input()))
v1 = int(eval(input()))
min_v = min(v0, v1)
max_profit = v1-v0
for i in range(element_number-2):
v = int(eval(input()))
max_profit = max(max_profit, v-min_v)
min_v = min(min_v, v)
print(max_profit)
if __name__ == '__main__':
get_maximum_profit() | import sys
def get_maximum_profit():
element_number = int(eval(input()))
v0 = int(eval(input()))
v1 = int(eval(input()))
min_v = min(v0, v1)
max_profit = v1-v0
for v in map(int, sys.stdin.readlines()):
max_profit = max(max_profit, v-min_v)
min_v = min(min_v, v)
print(max_profit)
if __name__ == '__main__':
get_maximum_profit() | 19 | 18 | 397 | 379 | import sys
def get_maximum_profit():
element_number = int(eval(input()))
v0 = int(eval(input()))
v1 = int(eval(input()))
min_v = min(v0, v1)
max_profit = v1 - v0
for i in range(element_number - 2):
v = int(eval(input()))
max_profit = max(max_profit, v - min_v)
min_v = min(min_v, v)
print(max_profit)
if __name__ == "__main__":
get_maximum_profit()
| import sys
def get_maximum_profit():
element_number = int(eval(input()))
v0 = int(eval(input()))
v1 = int(eval(input()))
min_v = min(v0, v1)
max_profit = v1 - v0
for v in map(int, sys.stdin.readlines()):
max_profit = max(max_profit, v - min_v)
min_v = min(min_v, v)
print(max_profit)
if __name__ == "__main__":
get_maximum_profit()
| false | 5.263158 | [
"- for i in range(element_number - 2):",
"- v = int(eval(input()))",
"+ for v in map(int, sys.stdin.readlines()):"
] | false | 0.06393 | 0.069115 | 0.924979 | [
"s669732265",
"s155046021"
] |
u129214942 | p03207 | python | s491382245 | s432312867 | 150 | 17 | 12,500 | 2,940 | Accepted | Accepted | 88.67 | import numpy as np
# 初期値を入力
N = int(eval(input()))
P = []
max = 0
number = 0
for i in range(N):
p = int(eval(input()))
if max < p:
max = p
number = i
P.append(p)
# メインプログラム
P[number] = max/2
print((int(sum(P))))
|
N = int(eval(input()))
P = []
max = 0
number = 0
for i in range(N):
p = int(eval(input()))
if max < p:
max = p
number = i
P.append(p)
P[number] = max/2
print((int(sum(P))))
| 24 | 20 | 258 | 214 | import numpy as np
# 初期値を入力
N = int(eval(input()))
P = []
max = 0
number = 0
for i in range(N):
p = int(eval(input()))
if max < p:
max = p
number = i
P.append(p)
# メインプログラム
P[number] = max / 2
print((int(sum(P))))
| N = int(eval(input()))
P = []
max = 0
number = 0
for i in range(N):
p = int(eval(input()))
if max < p:
max = p
number = i
P.append(p)
P[number] = max / 2
print((int(sum(P))))
| false | 16.666667 | [
"-import numpy as np",
"-",
"-# 初期値を入力",
"-# メインプログラム"
] | false | 0.041162 | 0.037527 | 1.096846 | [
"s491382245",
"s432312867"
] |
u773265208 | p03001 | python | s257350724 | s275893593 | 178 | 17 | 38,384 | 2,940 | Accepted | Accepted | 90.45 | w,h,x,y = list(map(int,input().split()))
if 2 * x == w and 2 * y == h:
print((w * h / 2, '1'))
else:
print((w * h / 2, '0'))
| w,h,x,y = list(map(int,input().split()))
if x == w/2 and y == h/2:
print((w*h/2,1))
else:
print((w*h/2,0))
| 6 | 7 | 123 | 113 | w, h, x, y = list(map(int, input().split()))
if 2 * x == w and 2 * y == h:
print((w * h / 2, "1"))
else:
print((w * h / 2, "0"))
| w, h, x, y = list(map(int, input().split()))
if x == w / 2 and y == h / 2:
print((w * h / 2, 1))
else:
print((w * h / 2, 0))
| false | 14.285714 | [
"-if 2 * x == w and 2 * y == h:",
"- print((w * h / 2, \"1\"))",
"+if x == w / 2 and y == h / 2:",
"+ print((w * h / 2, 1))",
"- print((w * h / 2, \"0\"))",
"+ print((w * h / 2, 0))"
] | false | 0.088176 | 0.066263 | 1.330708 | [
"s257350724",
"s275893593"
] |
u829391045 | p03162 | python | s690192945 | s643451193 | 802 | 173 | 189,320 | 98,256 | Accepted | Accepted | 78.43 | from sys import stdin,stdout,setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n,sep="\n"):
stdout.write(str(n))
stdout.write(sep)
def gil():
return list(map(int, input().split()))
n = int(eval(input()))
a, b, c = [], [], []
for i in range(n):
x,y,z = gil()
a.append(x)
b.append(y)
c.append(z)
mem = [[-1 for _ in range(3)] for _ in range(n+1)]
def rp(i, p):
global a,b,c,n
if i >= n:
return 0
if mem[i][p] != -1:
return mem[i][p]
av = [a[i] + rp(i+1, 0), b[i] + rp(i+1, 1), c[i] + rp(i+1, 2)]
if p != -1:
av[p] = 0
ans = max(av)
mem[i][p] = ans
return ans
ans = rp(0, -1)
print(ans)
# on recursive mem sols, build the solution from the base case,
# ie, return 0 on basecase, and build up the solution.
# because state-cases below will not carry values from above, they only take values from below
| from sys import stdin,stdout,setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n,sep="\n"):
stdout.write(str(n))
stdout.write(sep)
def gil():
return list(map(int, input().split()))
n = int(eval(input()))
d = []
for i in range(n):
d.append(gil())
dp = [[0,0,0]]
for dz in range(n):
ndp = [0] * 3
for i in range(3):
for j in range(3):
if i != j:
ndp[i] = max(ndp[i], dp[dz][j] + d[dz][i])
dp.append(ndp)
#print(dp)
print((max(dp[-1])))
# tabular approach
| 41 | 28 | 1,008 | 613 | from sys import stdin, stdout, setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n, sep="\n"):
stdout.write(str(n))
stdout.write(sep)
def gil():
return list(map(int, input().split()))
n = int(eval(input()))
a, b, c = [], [], []
for i in range(n):
x, y, z = gil()
a.append(x)
b.append(y)
c.append(z)
mem = [[-1 for _ in range(3)] for _ in range(n + 1)]
def rp(i, p):
global a, b, c, n
if i >= n:
return 0
if mem[i][p] != -1:
return mem[i][p]
av = [a[i] + rp(i + 1, 0), b[i] + rp(i + 1, 1), c[i] + rp(i + 1, 2)]
if p != -1:
av[p] = 0
ans = max(av)
mem[i][p] = ans
return ans
ans = rp(0, -1)
print(ans)
# on recursive mem sols, build the solution from the base case,
# ie, return 0 on basecase, and build up the solution.
# because state-cases below will not carry values from above, they only take values from below
| from sys import stdin, stdout, setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n, sep="\n"):
stdout.write(str(n))
stdout.write(sep)
def gil():
return list(map(int, input().split()))
n = int(eval(input()))
d = []
for i in range(n):
d.append(gil())
dp = [[0, 0, 0]]
for dz in range(n):
ndp = [0] * 3
for i in range(3):
for j in range(3):
if i != j:
ndp[i] = max(ndp[i], dp[dz][j] + d[dz][i])
dp.append(ndp)
# print(dp)
print((max(dp[-1])))
# tabular approach
| false | 31.707317 | [
"-a, b, c = [], [], []",
"+d = []",
"- x, y, z = gil()",
"- a.append(x)",
"- b.append(y)",
"- c.append(z)",
"-mem = [[-1 for _ in range(3)] for _ in range(n + 1)]",
"-",
"-",
"-def rp(i, p):",
"- global a, b, c, n",
"- if i >= n:",
"- return 0",
"- if mem[i][p] != -1:",
"- return mem[i][p]",
"- av = [a[i] + rp(i + 1, 0), b[i] + rp(i + 1, 1), c[i] + rp(i + 1, 2)]",
"- if p != -1:",
"- av[p] = 0",
"- ans = max(av)",
"- mem[i][p] = ans",
"- return ans",
"-",
"-",
"-ans = rp(0, -1)",
"-print(ans)",
"-# on recursive mem sols, build the solution from the base case,",
"-# ie, return 0 on basecase, and build up the solution.",
"-# because state-cases below will not carry values from above, they only take values from below",
"+ d.append(gil())",
"+dp = [[0, 0, 0]]",
"+for dz in range(n):",
"+ ndp = [0] * 3",
"+ for i in range(3):",
"+ for j in range(3):",
"+ if i != j:",
"+ ndp[i] = max(ndp[i], dp[dz][j] + d[dz][i])",
"+ dp.append(ndp)",
"+# print(dp)",
"+print((max(dp[-1])))",
"+# tabular approach"
] | false | 0.037511 | 0.04416 | 0.84943 | [
"s690192945",
"s643451193"
] |
u297574184 | p03038 | python | s487818635 | s904510252 | 470 | 293 | 22,116 | 22,184 | Accepted | Accepted | 37.66 | N, M = list(map(int, input().split()))
As = list(map(int, input().split()))
BCs = [tuple(map(int, input().split())) for _ in range(M)]
As.sort()
BCs.sort(key=lambda x: x[1], reverse=True)
iA = 0
for B, C in BCs:
for j in range(B):
if As[iA] < C:
As[iA] = C
iA += 1
if iA >= N:
break
else:
break
else:
continue
break
print((sum(As)))
| import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
As = list(map(int, input().split()))
BCs = [tuple(map(int, input().split())) for _ in range(M)]
As.sort()
BCs.sort(reverse=True, key=lambda x: x[1])
i = 0
for B, C in BCs:
num = min(N-i, B)
for j in range(i, i+num):
if As[j] >= C:
break
As[j] = C
else:
i += B
if i >= N:
break
continue
break
#print('As:', As)
print((sum(As)))
| 22 | 26 | 449 | 505 | N, M = list(map(int, input().split()))
As = list(map(int, input().split()))
BCs = [tuple(map(int, input().split())) for _ in range(M)]
As.sort()
BCs.sort(key=lambda x: x[1], reverse=True)
iA = 0
for B, C in BCs:
for j in range(B):
if As[iA] < C:
As[iA] = C
iA += 1
if iA >= N:
break
else:
break
else:
continue
break
print((sum(As)))
| import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
As = list(map(int, input().split()))
BCs = [tuple(map(int, input().split())) for _ in range(M)]
As.sort()
BCs.sort(reverse=True, key=lambda x: x[1])
i = 0
for B, C in BCs:
num = min(N - i, B)
for j in range(i, i + num):
if As[j] >= C:
break
As[j] = C
else:
i += B
if i >= N:
break
continue
break
# print('As:', As)
print((sum(As)))
| false | 15.384615 | [
"+import sys",
"+",
"+input = sys.stdin.readline",
"-BCs.sort(key=lambda x: x[1], reverse=True)",
"-iA = 0",
"+BCs.sort(reverse=True, key=lambda x: x[1])",
"+i = 0",
"- for j in range(B):",
"- if As[iA] < C:",
"- As[iA] = C",
"- iA += 1",
"- if iA >= N:",
"- break",
"- else:",
"+ num = min(N - i, B)",
"+ for j in range(i, i + num):",
"+ if As[j] >= C:",
"+ As[j] = C",
"+ i += B",
"+ if i >= N:",
"+ break",
"+# print('As:', As)"
] | false | 0.036695 | 0.037361 | 0.982173 | [
"s487818635",
"s904510252"
] |
u119148115 | p03470 | python | s838372912 | s112609266 | 136 | 64 | 61,596 | 61,856 | Accepted | Accepted | 52.94 | import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
N = I()
s = set()
for i in range(N):
s.add(I())
print((len(s)))
| import sys
def I(): return int(sys.stdin.readline().rstrip())
N = I()
s = set()
for _ in range(N):
s.add(I())
print((len(s)))
| 18 | 10 | 564 | 140 | import sys
sys.setrecursionlimit(10**7)
def I():
return int(sys.stdin.readline().rstrip())
def MI():
return list(map(int, sys.stdin.readline().rstrip().split()))
def LI():
return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり
def LI2():
return list(map(int, sys.stdin.readline().rstrip())) # 空白なし
def S():
return sys.stdin.readline().rstrip()
def LS():
return list(sys.stdin.readline().rstrip().split()) # 空白あり
def LS2():
return list(sys.stdin.readline().rstrip()) # 空白なし
N = I()
s = set()
for i in range(N):
s.add(I())
print((len(s)))
| import sys
def I():
return int(sys.stdin.readline().rstrip())
N = I()
s = set()
for _ in range(N):
s.add(I())
print((len(s)))
| false | 44.444444 | [
"-",
"-sys.setrecursionlimit(10**7)",
"-def MI():",
"- return list(map(int, sys.stdin.readline().rstrip().split()))",
"-",
"-",
"-def LI():",
"- return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり",
"-",
"-",
"-def LI2():",
"- return list(map(int, sys.stdin.readline().rstrip())) # 空白なし",
"-",
"-",
"-def S():",
"- return sys.stdin.readline().rstrip()",
"-",
"-",
"-def LS():",
"- return list(sys.stdin.readline().rstrip().split()) # 空白あり",
"-",
"-",
"-def LS2():",
"- return list(sys.stdin.readline().rstrip()) # 空白なし",
"-",
"-",
"-for i in range(N):",
"+for _ in range(N):"
] | false | 0.044526 | 0.042147 | 1.056432 | [
"s838372912",
"s112609266"
] |
u015768390 | p03222 | python | s756240289 | s072787360 | 230 | 138 | 3,064 | 3,064 | Accepted | Accepted | 40 | def check(pattern):
for i in range(W - 2):
mask = 0b11 << i
if pattern & mask == mask:
return False
return True
def simulate(a1, pattern):
pat = [pattern & (1 << w) != 0 for w in range(W - 1)]
if a1 != W - 1 and pat[a1]:
return a1 + 1
elif a1 != 0 and pat[a1 - 1]:
return a1 - 1
else:
return a1
H, W, K = list(map(int, input().split()))
dp = [[0] * W for h in range(H + 1)]
dp[0][0] = 1
for h in range(1, H + 1):
for pattern in range(2 ** (W - 1)):
for w in range(W):
if check(pattern):
dp[h][simulate(w, pattern)] += dp[h - 1][w]
dp[h][simulate(w, pattern)] %= 1000000007
print((dp[H][K - 1]))
| def check(pat):
for i in range(W - 2):
mask = 0b11 << i
if pat & mask == mask:
return False
return True
def simulate(a1, pat):
if a1 != W - 1 and pat & 1 << a1 != 0:
return a1 + 1
elif a1 != 0 and pat & 1 << a1 - 1 != 0:
return a1 - 1
else:
return a1
H, W, K = list(map(int, input().split()))
dp = [[0] * W for h in range(H + 1)]
dp[0][0] = 1
for h in range(1, H + 1):
for pat in range(2 ** (W - 1)):
for w in range(W):
if check(pat):
dp[h][simulate(w, pat)] += dp[h - 1][w]
dp[h][simulate(w, pat)] %= 1000000007
print((dp[H][K - 1]))
| 28 | 27 | 750 | 685 | def check(pattern):
for i in range(W - 2):
mask = 0b11 << i
if pattern & mask == mask:
return False
return True
def simulate(a1, pattern):
pat = [pattern & (1 << w) != 0 for w in range(W - 1)]
if a1 != W - 1 and pat[a1]:
return a1 + 1
elif a1 != 0 and pat[a1 - 1]:
return a1 - 1
else:
return a1
H, W, K = list(map(int, input().split()))
dp = [[0] * W for h in range(H + 1)]
dp[0][0] = 1
for h in range(1, H + 1):
for pattern in range(2 ** (W - 1)):
for w in range(W):
if check(pattern):
dp[h][simulate(w, pattern)] += dp[h - 1][w]
dp[h][simulate(w, pattern)] %= 1000000007
print((dp[H][K - 1]))
| def check(pat):
for i in range(W - 2):
mask = 0b11 << i
if pat & mask == mask:
return False
return True
def simulate(a1, pat):
if a1 != W - 1 and pat & 1 << a1 != 0:
return a1 + 1
elif a1 != 0 and pat & 1 << a1 - 1 != 0:
return a1 - 1
else:
return a1
H, W, K = list(map(int, input().split()))
dp = [[0] * W for h in range(H + 1)]
dp[0][0] = 1
for h in range(1, H + 1):
for pat in range(2 ** (W - 1)):
for w in range(W):
if check(pat):
dp[h][simulate(w, pat)] += dp[h - 1][w]
dp[h][simulate(w, pat)] %= 1000000007
print((dp[H][K - 1]))
| false | 3.571429 | [
"-def check(pattern):",
"+def check(pat):",
"- if pattern & mask == mask:",
"+ if pat & mask == mask:",
"-def simulate(a1, pattern):",
"- pat = [pattern & (1 << w) != 0 for w in range(W - 1)]",
"- if a1 != W - 1 and pat[a1]:",
"+def simulate(a1, pat):",
"+ if a1 != W - 1 and pat & 1 << a1 != 0:",
"- elif a1 != 0 and pat[a1 - 1]:",
"+ elif a1 != 0 and pat & 1 << a1 - 1 != 0:",
"- for pattern in range(2 ** (W - 1)):",
"+ for pat in range(2 ** (W - 1)):",
"- if check(pattern):",
"- dp[h][simulate(w, pattern)] += dp[h - 1][w]",
"- dp[h][simulate(w, pattern)] %= 1000000007",
"+ if check(pat):",
"+ dp[h][simulate(w, pat)] += dp[h - 1][w]",
"+ dp[h][simulate(w, pat)] %= 1000000007"
] | false | 0.083012 | 0.059385 | 1.397847 | [
"s756240289",
"s072787360"
] |
u788137651 | p02793 | python | s366261775 | s520670408 | 1,045 | 943 | 68,056 | 68,732 | Accepted | Accepted | 9.76 | #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
# from math import floor,ceil,sqrt,factorial,hypot,log #log2ないyp
# from heapq import heappop, heappush, heappushpop
# from collections import Counter,defaultdict,deque
# from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
# from bisect import bisect_left,bisect_right
# from copy import deepcopy
from fractions import gcd
inf=float('inf')
mod = 10**9+7
def pprint(*A):
for a in A: print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
#mint
class ModInt:
def __init__(self, x):
self.x = x % mod
def __str__(self):
return str(self.x)
__repr__ = __str__
def __add__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x + other.x)
else:
return ModInt(self.x + other)
__radd__ = __add__
def __sub__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x - other.x)
else:
return ModInt(self.x - other)
def __rsub__(self, other):
if isinstance(other, ModInt):
return ModInt(other.x - self.x)
else:
return ModInt(other - self.x)
def __mul__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x * other.x)
else:
return ModInt(self.x * other)
__rmul__ = __mul__
def __truediv__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x * pow(other.x, mod-2,mod))
else:
return ModInt(self.x * pow(other, mod - 2, mod))
def __rtruediv(self, other):
if isinstance(other, self):
return ModInt(other * pow(self.x, mod - 2, mod))
else:
return ModInt(other.x * pow(self.x, mod - 2, mod))
def __pow__(self, other):
if isinstance(other, ModInt):
return ModInt(pow(self.x, other.x, mod))
else:
return ModInt(pow(self.x, other, mod))
def __rpow__(self, other):
if isinstance(other, ModInt):
return ModInt(pow(other.x, self.x, mod))
else:
return ModInt(pow(other, self.x, mod))
def main():
N=I()
A=LI()
l = 1
for a in A:
l *= a//gcd(l,a)
ans = 0
for a in A:
ans += ModInt(l)/a
print(ans)
if __name__ == '__main__':
main()
| #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
# from math import floor,ceil,sqrt,factorial,hypot,log #log2ないyp
# from heapq import heappop, heappush, heappushpop
# from collections import Counter,defaultdict,deque
# from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
# from bisect import bisect_left,bisect_right
# from copy import deepcopy
from fractions import gcd
inf=float('inf')
mod = 10**9+7
def pprint(*A):
for a in A: print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
#mint
class ModInt:
def __init__(self, x):
self.x = x % mod
def __str__(self):
return str(self.x)
__repr__ = __str__
def __add__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x + other.x)
else:
return ModInt(self.x + other)
__radd__ = __add__
def __sub__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x - other.x)
else:
return ModInt(self.x - other)
def __rsub__(self, other):
if isinstance(other, ModInt):
return ModInt(other.x - self.x)
else:
return ModInt(other - self.x)
def __mul__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x * other.x)
else:
return ModInt(self.x * other)
__rmul__ = __mul__
def __truediv__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x * pow(other.x, mod-2,mod))
else:
return ModInt(self.x * pow(other, mod - 2, mod))
def __rtruediv(self, other):
if isinstance(other, self):
return ModInt(other * pow(self.x, mod - 2, mod))
else:
return ModInt(other.x * pow(self.x, mod - 2, mod))
def __pow__(self, other):
if isinstance(other, ModInt):
return ModInt(pow(self.x, other.x, mod))
else:
return ModInt(pow(self.x, other, mod))
def __rpow__(self, other):
if isinstance(other, ModInt):
return ModInt(pow(other.x, self.x, mod))
else:
return ModInt(pow(other, self.x, mod))
def main():
N=I()
A=LI()
l = 1
for a in A:
l *= a//gcd(l,a)
ans = 0
l = ModInt(l)
for a in A:
ans += l/a
print(ans)
if __name__ == '__main__':
main()
| 115 | 116 | 3,239 | 3,250 | #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
# from math import floor,ceil,sqrt,factorial,hypot,log #log2ないyp
# from heapq import heappop, heappush, heappushpop
# from collections import Counter,defaultdict,deque
# from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
# from bisect import bisect_left,bisect_right
# from copy import deepcopy
from fractions import gcd
inf = float("inf")
mod = 10**9 + 7
def pprint(*A):
for a in A:
print(*a, sep="\n")
def INT_(n):
return int(n) - 1
def MI():
return map(int, input().split())
def MF():
return map(float, input().split())
def MI_():
return map(INT_, input().split())
def LI():
return list(MI())
def LI_():
return [int(x) - 1 for x in input().split()]
def LF():
return list(MF())
def LIN(n: int):
return [I() for _ in range(n)]
def LLIN(n: int):
return [LI() for _ in range(n)]
def LLIN_(n: int):
return [LI_() for _ in range(n)]
def LLI():
return [list(map(int, l.split())) for l in input()]
def I():
return int(input())
def F():
return float(input())
def ST():
return input().replace("\n", "")
# mint
class ModInt:
def __init__(self, x):
self.x = x % mod
def __str__(self):
return str(self.x)
__repr__ = __str__
def __add__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x + other.x)
else:
return ModInt(self.x + other)
__radd__ = __add__
def __sub__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x - other.x)
else:
return ModInt(self.x - other)
def __rsub__(self, other):
if isinstance(other, ModInt):
return ModInt(other.x - self.x)
else:
return ModInt(other - self.x)
def __mul__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x * other.x)
else:
return ModInt(self.x * other)
__rmul__ = __mul__
def __truediv__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x * pow(other.x, mod - 2, mod))
else:
return ModInt(self.x * pow(other, mod - 2, mod))
def __rtruediv(self, other):
if isinstance(other, self):
return ModInt(other * pow(self.x, mod - 2, mod))
else:
return ModInt(other.x * pow(self.x, mod - 2, mod))
def __pow__(self, other):
if isinstance(other, ModInt):
return ModInt(pow(self.x, other.x, mod))
else:
return ModInt(pow(self.x, other, mod))
def __rpow__(self, other):
if isinstance(other, ModInt):
return ModInt(pow(other.x, self.x, mod))
else:
return ModInt(pow(other, self.x, mod))
def main():
N = I()
A = LI()
l = 1
for a in A:
l *= a // gcd(l, a)
ans = 0
for a in A:
ans += ModInt(l) / a
print(ans)
if __name__ == "__main__":
main()
| #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
# from math import floor,ceil,sqrt,factorial,hypot,log #log2ないyp
# from heapq import heappop, heappush, heappushpop
# from collections import Counter,defaultdict,deque
# from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
# from bisect import bisect_left,bisect_right
# from copy import deepcopy
from fractions import gcd
inf = float("inf")
mod = 10**9 + 7
def pprint(*A):
for a in A:
print(*a, sep="\n")
def INT_(n):
return int(n) - 1
def MI():
return map(int, input().split())
def MF():
return map(float, input().split())
def MI_():
return map(INT_, input().split())
def LI():
return list(MI())
def LI_():
return [int(x) - 1 for x in input().split()]
def LF():
return list(MF())
def LIN(n: int):
return [I() for _ in range(n)]
def LLIN(n: int):
return [LI() for _ in range(n)]
def LLIN_(n: int):
return [LI_() for _ in range(n)]
def LLI():
return [list(map(int, l.split())) for l in input()]
def I():
return int(input())
def F():
return float(input())
def ST():
return input().replace("\n", "")
# mint
class ModInt:
def __init__(self, x):
self.x = x % mod
def __str__(self):
return str(self.x)
__repr__ = __str__
def __add__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x + other.x)
else:
return ModInt(self.x + other)
__radd__ = __add__
def __sub__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x - other.x)
else:
return ModInt(self.x - other)
def __rsub__(self, other):
if isinstance(other, ModInt):
return ModInt(other.x - self.x)
else:
return ModInt(other - self.x)
def __mul__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x * other.x)
else:
return ModInt(self.x * other)
__rmul__ = __mul__
def __truediv__(self, other):
if isinstance(other, ModInt):
return ModInt(self.x * pow(other.x, mod - 2, mod))
else:
return ModInt(self.x * pow(other, mod - 2, mod))
def __rtruediv(self, other):
if isinstance(other, self):
return ModInt(other * pow(self.x, mod - 2, mod))
else:
return ModInt(other.x * pow(self.x, mod - 2, mod))
def __pow__(self, other):
if isinstance(other, ModInt):
return ModInt(pow(self.x, other.x, mod))
else:
return ModInt(pow(self.x, other, mod))
def __rpow__(self, other):
if isinstance(other, ModInt):
return ModInt(pow(other.x, self.x, mod))
else:
return ModInt(pow(other, self.x, mod))
def main():
N = I()
A = LI()
l = 1
for a in A:
l *= a // gcd(l, a)
ans = 0
l = ModInt(l)
for a in A:
ans += l / a
print(ans)
if __name__ == "__main__":
main()
| false | 0.862069 | [
"+ l = ModInt(l)",
"- ans += ModInt(l) / a",
"+ ans += l / a"
] | false | 0.057248 | 0.064163 | 0.892225 | [
"s366261775",
"s520670408"
] |
u932945921 | p02958 | python | s263525414 | s191543895 | 22 | 17 | 3,064 | 2,940 | Accepted | Accepted | 22.73 | def main():
n = int(eval(input()))
p = list(map(int, input().split(' ')))
c = 0
if judge(p):
print('YES')
else:
for i in range(n):
for j in range(i+1, n):
a = p.copy()
a[i], a[j] = a[j], a[i]
if judge(a):
c += 1
print('YES')
if c == 0:
print('NO')
def judge(l):
return True if l == sorted(l) else False
if __name__ == '__main__':
main() | def main():
n = int(eval(input()))
p = list(map(int, input().split(' ')))
c = 0
for i in range(n):
c += 0 if i+1 == p[i] else 1
print(('YES' if c <= 2 else 'NO'))
if __name__ == '__main__':
main() | 24 | 11 | 439 | 216 | def main():
n = int(eval(input()))
p = list(map(int, input().split(" ")))
c = 0
if judge(p):
print("YES")
else:
for i in range(n):
for j in range(i + 1, n):
a = p.copy()
a[i], a[j] = a[j], a[i]
if judge(a):
c += 1
print("YES")
if c == 0:
print("NO")
def judge(l):
return True if l == sorted(l) else False
if __name__ == "__main__":
main()
| def main():
n = int(eval(input()))
p = list(map(int, input().split(" ")))
c = 0
for i in range(n):
c += 0 if i + 1 == p[i] else 1
print(("YES" if c <= 2 else "NO"))
if __name__ == "__main__":
main()
| false | 54.166667 | [
"- if judge(p):",
"- print(\"YES\")",
"- else:",
"- for i in range(n):",
"- for j in range(i + 1, n):",
"- a = p.copy()",
"- a[i], a[j] = a[j], a[i]",
"- if judge(a):",
"- c += 1",
"- print(\"YES\")",
"- if c == 0:",
"- print(\"NO\")",
"-",
"-",
"-def judge(l):",
"- return True if l == sorted(l) else False",
"+ for i in range(n):",
"+ c += 0 if i + 1 == p[i] else 1",
"+ print((\"YES\" if c <= 2 else \"NO\"))"
] | false | 0.068748 | 0.042979 | 1.599586 | [
"s263525414",
"s191543895"
] |
u903005414 | p03274 | python | s810372180 | s165074331 | 324 | 90 | 23,108 | 14,384 | Accepted | Accepted | 72.22 | import numpy as np
N, K = list(map(int, input().split()))
X = np.array(list(map(int, input().split())))
arr = X[K - 1:] - X[:-K + 1]
arr1 = arr + np.abs(X[:-K + 1])
arr2 = arr + np.abs(X[K - 1:])
if len(arr) == 0:
print((0))
else:
ans = min(arr1.min(), arr2.min())
print(ans)
| N, K = list(map(int, input().split()))
X = list(map(int, input().split()))
ans = 10**18
for i in range(N - K + 1):
d1 = X[i + K - 1] - X[i] + abs(X[i])
d2 = X[i + K - 1] - X[i] + abs(X[i + K - 1])
# print('d', d)
ans = min(ans, d1, d2)
print(ans)
| 11 | 10 | 290 | 267 | import numpy as np
N, K = list(map(int, input().split()))
X = np.array(list(map(int, input().split())))
arr = X[K - 1 :] - X[: -K + 1]
arr1 = arr + np.abs(X[: -K + 1])
arr2 = arr + np.abs(X[K - 1 :])
if len(arr) == 0:
print((0))
else:
ans = min(arr1.min(), arr2.min())
print(ans)
| N, K = list(map(int, input().split()))
X = list(map(int, input().split()))
ans = 10**18
for i in range(N - K + 1):
d1 = X[i + K - 1] - X[i] + abs(X[i])
d2 = X[i + K - 1] - X[i] + abs(X[i + K - 1])
# print('d', d)
ans = min(ans, d1, d2)
print(ans)
| false | 9.090909 | [
"-import numpy as np",
"-",
"-X = np.array(list(map(int, input().split())))",
"-arr = X[K - 1 :] - X[: -K + 1]",
"-arr1 = arr + np.abs(X[: -K + 1])",
"-arr2 = arr + np.abs(X[K - 1 :])",
"-if len(arr) == 0:",
"- print((0))",
"-else:",
"- ans = min(arr1.min(), arr2.min())",
"- print(ans)",
"+X = list(map(int, input().split()))",
"+ans = 10**18",
"+for i in range(N - K + 1):",
"+ d1 = X[i + K - 1] - X[i] + abs(X[i])",
"+ d2 = X[i + K - 1] - X[i] + abs(X[i + K - 1])",
"+ # print('d', d)",
"+ ans = min(ans, d1, d2)",
"+print(ans)"
] | false | 0.167582 | 0.036543 | 4.585926 | [
"s810372180",
"s165074331"
] |
u200887663 | p02837 | python | s944351861 | s523287445 | 388 | 321 | 3,064 | 3,064 | Accepted | Accepted | 17.27 | n=int(eval(input()))
al=[]
l=[]
for i in range(n):
a=int(eval(input()))
al.append(a)
templ=[list(map(int,input().split())) for i in range(a)]
l.append(templ)
ans=0
for i in range(2**n):
b=bin(i)
chkdic={}
n_honest=0#正直者の人数をカウント
flag=False#矛盾が生じるかどうか
for j in range(n):
if ((i >> j) & 1):#もし正直者なら
n_honest+=1
#saying_l=l[j]
#a=al[j]
chkdic[j+1]=1
else:
chkdic[j+1]=0
#chkdicをもとに判定
for j in range(n):
if ((i >> j) & 1):
saying_l=l[j]
a=al[j]
for k in range(a):
saying=saying_l[k]
if chkdic[saying[0]]!=saying[1]:
flag=True
break
if flag:
break
if not flag:
ans=max(ans,n_honest)
print(ans)
| n=int(eval(input()))
al=[]
info=[]
for i in range(n):
a=int(eval(input()))
al.append(a)
temp=[]
for j in range(a):
x,y=list(map(int,input().split()))
temp.append([x,y])
info.append(temp)
ans=0
for i in range(2**n):
n_honest=0
dic={}
flag=True
for j in range(n):
if ((i >> j) & 1):
n_honest+=1
dic[j]=1
else:
dic[j]=0
for j in range(n):
if ((i >> j) & 1):
temp=info[j]
a=al[j]
for k in range(a):
l=temp[k]
x=l[0]
y=l[1]
if dic[x-1]!=y:
flag=False
break
if not flag:
break
if flag:
ans=max(n_honest,ans)
print(ans)
| 39 | 41 | 758 | 826 | n = int(eval(input()))
al = []
l = []
for i in range(n):
a = int(eval(input()))
al.append(a)
templ = [list(map(int, input().split())) for i in range(a)]
l.append(templ)
ans = 0
for i in range(2**n):
b = bin(i)
chkdic = {}
n_honest = 0 # 正直者の人数をカウント
flag = False # 矛盾が生じるかどうか
for j in range(n):
if (i >> j) & 1: # もし正直者なら
n_honest += 1
# saying_l=l[j]
# a=al[j]
chkdic[j + 1] = 1
else:
chkdic[j + 1] = 0
# chkdicをもとに判定
for j in range(n):
if (i >> j) & 1:
saying_l = l[j]
a = al[j]
for k in range(a):
saying = saying_l[k]
if chkdic[saying[0]] != saying[1]:
flag = True
break
if flag:
break
if not flag:
ans = max(ans, n_honest)
print(ans)
| n = int(eval(input()))
al = []
info = []
for i in range(n):
a = int(eval(input()))
al.append(a)
temp = []
for j in range(a):
x, y = list(map(int, input().split()))
temp.append([x, y])
info.append(temp)
ans = 0
for i in range(2**n):
n_honest = 0
dic = {}
flag = True
for j in range(n):
if (i >> j) & 1:
n_honest += 1
dic[j] = 1
else:
dic[j] = 0
for j in range(n):
if (i >> j) & 1:
temp = info[j]
a = al[j]
for k in range(a):
l = temp[k]
x = l[0]
y = l[1]
if dic[x - 1] != y:
flag = False
break
if not flag:
break
if flag:
ans = max(n_honest, ans)
print(ans)
| false | 4.878049 | [
"-l = []",
"+info = []",
"- templ = [list(map(int, input().split())) for i in range(a)]",
"- l.append(templ)",
"+ temp = []",
"+ for j in range(a):",
"+ x, y = list(map(int, input().split()))",
"+ temp.append([x, y])",
"+ info.append(temp)",
"- b = bin(i)",
"- chkdic = {}",
"- n_honest = 0 # 正直者の人数をカウント",
"- flag = False # 矛盾が生じるかどうか",
"- for j in range(n):",
"- if (i >> j) & 1: # もし正直者なら",
"- n_honest += 1",
"- # saying_l=l[j]",
"- # a=al[j]",
"- chkdic[j + 1] = 1",
"- else:",
"- chkdic[j + 1] = 0",
"- # chkdicをもとに判定",
"+ n_honest = 0",
"+ dic = {}",
"+ flag = True",
"- saying_l = l[j]",
"+ n_honest += 1",
"+ dic[j] = 1",
"+ else:",
"+ dic[j] = 0",
"+ for j in range(n):",
"+ if (i >> j) & 1:",
"+ temp = info[j]",
"- saying = saying_l[k]",
"- if chkdic[saying[0]] != saying[1]:",
"- flag = True",
"+ l = temp[k]",
"+ x = l[0]",
"+ y = l[1]",
"+ if dic[x - 1] != y:",
"+ flag = False",
"- if flag:",
"+ if not flag:",
"- if not flag:",
"- ans = max(ans, n_honest)",
"+ if flag:",
"+ ans = max(n_honest, ans)"
] | false | 0.036506 | 0.105811 | 0.345016 | [
"s944351861",
"s523287445"
] |
u427344224 | p03806 | python | s710278335 | s698152816 | 481 | 417 | 112,604 | 96,604 | Accepted | Accepted | 13.31 | N, Ma, Mb = list(map(int, input().split()))
items = []
for i in range(N):
a, b, c = list(map(int, input().split()))
items.append((a, b, c))
a_sum = sum([item[0] for item in items])
b_sum = sum([item[1] for item in items])
inf = float("inf")
dp = [[[inf for _ in range(a_sum + 50)] for _ in range(b_sum + 50)] for i in range(N + 1)]
dp[0][0][0] = 0
for i in range(N):
for a in range(a_sum):
for b in range(b_sum):
if dp[i + 1][a][b] > dp[i][a][b]:
dp[i + 1][a][b] = dp[i][a][b]
if dp[i + 1][a + items[i][0]][b + items[i][1]] > dp[i][a][b] + items[i][2]:
dp[i + 1][a + items[i][0]][b + items[i][1]] = dp[i][a][b] + items[i][2]
ans = inf
for a in range(1, a_sum + 1):
for b in range(1, b_sum + 1):
if a * Mb == b * Ma:
ans = min(ans, dp[N][a][b])
if ans != inf:
print(ans)
else:
print((-1))
| N, Ma, Mb = list(map(int, input().split()))
items = []
for i in range(N):
a, b, c = list(map(int, input().split()))
items.append((a, b, c))
a_sum = sum([item[0] for item in items])
b_sum = sum([item[1] for item in items])
inf = float("inf")
dp = [[[inf for _ in range(b_sum + 11)] for _ in range(a_sum + 11)] for i in range(N + 1)]
dp[0][0][0] = 0
for i in range(N):
for a in range(a_sum):
for b in range(b_sum):
if dp[i + 1][a][b] > dp[i][a][b]:
dp[i + 1][a][b] = dp[i][a][b]
if dp[i + 1][a + items[i][0]][b + items[i][1]] > dp[i][a][b] + items[i][2]:
dp[i + 1][a + items[i][0]][b + items[i][1]] = dp[i][a][b] + items[i][2]
ans = inf
for a in range(1, a_sum + 1):
for b in range(1, b_sum + 1):
if a * Mb == b * Ma:
ans = min(ans, dp[N][a][b])
if ans != inf:
print(ans)
else:
print((-1))
| 29 | 28 | 913 | 911 | N, Ma, Mb = list(map(int, input().split()))
items = []
for i in range(N):
a, b, c = list(map(int, input().split()))
items.append((a, b, c))
a_sum = sum([item[0] for item in items])
b_sum = sum([item[1] for item in items])
inf = float("inf")
dp = [
[[inf for _ in range(a_sum + 50)] for _ in range(b_sum + 50)] for i in range(N + 1)
]
dp[0][0][0] = 0
for i in range(N):
for a in range(a_sum):
for b in range(b_sum):
if dp[i + 1][a][b] > dp[i][a][b]:
dp[i + 1][a][b] = dp[i][a][b]
if dp[i + 1][a + items[i][0]][b + items[i][1]] > dp[i][a][b] + items[i][2]:
dp[i + 1][a + items[i][0]][b + items[i][1]] = dp[i][a][b] + items[i][2]
ans = inf
for a in range(1, a_sum + 1):
for b in range(1, b_sum + 1):
if a * Mb == b * Ma:
ans = min(ans, dp[N][a][b])
if ans != inf:
print(ans)
else:
print((-1))
| N, Ma, Mb = list(map(int, input().split()))
items = []
for i in range(N):
a, b, c = list(map(int, input().split()))
items.append((a, b, c))
a_sum = sum([item[0] for item in items])
b_sum = sum([item[1] for item in items])
inf = float("inf")
dp = [
[[inf for _ in range(b_sum + 11)] for _ in range(a_sum + 11)] for i in range(N + 1)
]
dp[0][0][0] = 0
for i in range(N):
for a in range(a_sum):
for b in range(b_sum):
if dp[i + 1][a][b] > dp[i][a][b]:
dp[i + 1][a][b] = dp[i][a][b]
if dp[i + 1][a + items[i][0]][b + items[i][1]] > dp[i][a][b] + items[i][2]:
dp[i + 1][a + items[i][0]][b + items[i][1]] = dp[i][a][b] + items[i][2]
ans = inf
for a in range(1, a_sum + 1):
for b in range(1, b_sum + 1):
if a * Mb == b * Ma:
ans = min(ans, dp[N][a][b])
if ans != inf:
print(ans)
else:
print((-1))
| false | 3.448276 | [
"- [[inf for _ in range(a_sum + 50)] for _ in range(b_sum + 50)] for i in range(N + 1)",
"+ [[inf for _ in range(b_sum + 11)] for _ in range(a_sum + 11)] for i in range(N + 1)"
] | false | 0.046556 | 0.046846 | 0.993809 | [
"s710278335",
"s698152816"
] |
u472696272 | p02887 | python | s343208615 | s180536239 | 72 | 52 | 4,648 | 3,956 | Accepted | Accepted | 27.78 | n = int(eval(input()))
s = list(eval(input()))
pointer1 = 0
pointer2 = 1
ans = []
ans.append(s[0])
while (pointer2 <= n-1):
if s[pointer2] == s[pointer1]:
pointer2 += 1
elif s[pointer2] != s[pointer1]:
pointer1 = pointer2
pointer2 = pointer1 + 1
ans.append(s[pointer1])
print((len(ans))) | n = int(eval(input()))
s = list(eval(input()))
count = 1
for i in range(1,n):
if s[i]!=s[i-1]:
count += 1
print(count)
| 16 | 7 | 315 | 119 | n = int(eval(input()))
s = list(eval(input()))
pointer1 = 0
pointer2 = 1
ans = []
ans.append(s[0])
while pointer2 <= n - 1:
if s[pointer2] == s[pointer1]:
pointer2 += 1
elif s[pointer2] != s[pointer1]:
pointer1 = pointer2
pointer2 = pointer1 + 1
ans.append(s[pointer1])
print((len(ans)))
| n = int(eval(input()))
s = list(eval(input()))
count = 1
for i in range(1, n):
if s[i] != s[i - 1]:
count += 1
print(count)
| false | 56.25 | [
"-pointer1 = 0",
"-pointer2 = 1",
"-ans = []",
"-ans.append(s[0])",
"-while pointer2 <= n - 1:",
"- if s[pointer2] == s[pointer1]:",
"- pointer2 += 1",
"- elif s[pointer2] != s[pointer1]:",
"- pointer1 = pointer2",
"- pointer2 = pointer1 + 1",
"- ans.append(s[pointer1])",
"-print((len(ans)))",
"+count = 1",
"+for i in range(1, n):",
"+ if s[i] != s[i - 1]:",
"+ count += 1",
"+print(count)"
] | false | 0.046202 | 0.044971 | 1.027382 | [
"s343208615",
"s180536239"
] |
u416758623 | p03290 | python | s250207127 | s170972437 | 36 | 18 | 3,064 | 3,064 | Accepted | Accepted | 50 | import sys
sys.setrecursionlimit(100000)
inf = float('inf')
def dfs(h, s):
# 停止条件
if h == D:
tmp = 0
p = 0
ans = 0
for i, c in enumerate(s):
if c == '0':
tmp = i
else:
ans += pc[i][0]
p += (i+1) * 100 * pc[i][0] + pc[i][1]
for i in range(pc[tmp][0]-1):
if p < G:
p += (tmp + 1) * 100
ans += 1
if p < G:
return inf
else:
return ans
tmp1 = dfs(h+1, s + '0')
tmp2 = dfs(h+1, s + '1')
return min(tmp1, tmp2)
D, G = list(map(int, input().split()))
pc = [list(map(int, input().split())) for _ in range(D)]
print((dfs(0, ''))) | D, G=list(map(int, input().split()))
PC=[0]+[list(map(int, input().split())) for _ in range(D)]
def function(G, i):
if i==0:
return 1e9
n=min(G//(i*100), PC[i][0])
s=n*i*100
if n==PC[i][0]:
s+=PC[i][1]
if s<G:
n+=function(G-s, i-1)
return min(n, function(G,i-1))
print((function(G, D)))
| 32 | 14 | 761 | 305 | import sys
sys.setrecursionlimit(100000)
inf = float("inf")
def dfs(h, s):
# 停止条件
if h == D:
tmp = 0
p = 0
ans = 0
for i, c in enumerate(s):
if c == "0":
tmp = i
else:
ans += pc[i][0]
p += (i + 1) * 100 * pc[i][0] + pc[i][1]
for i in range(pc[tmp][0] - 1):
if p < G:
p += (tmp + 1) * 100
ans += 1
if p < G:
return inf
else:
return ans
tmp1 = dfs(h + 1, s + "0")
tmp2 = dfs(h + 1, s + "1")
return min(tmp1, tmp2)
D, G = list(map(int, input().split()))
pc = [list(map(int, input().split())) for _ in range(D)]
print((dfs(0, "")))
| D, G = list(map(int, input().split()))
PC = [0] + [list(map(int, input().split())) for _ in range(D)]
def function(G, i):
if i == 0:
return 1e9
n = min(G // (i * 100), PC[i][0])
s = n * i * 100
if n == PC[i][0]:
s += PC[i][1]
if s < G:
n += function(G - s, i - 1)
return min(n, function(G, i - 1))
print((function(G, D)))
| false | 56.25 | [
"-import sys",
"-",
"-sys.setrecursionlimit(100000)",
"-inf = float(\"inf\")",
"+D, G = list(map(int, input().split()))",
"+PC = [0] + [list(map(int, input().split())) for _ in range(D)]",
"-def dfs(h, s):",
"- # 停止条件",
"- if h == D:",
"- tmp = 0",
"- p = 0",
"- ans = 0",
"- for i, c in enumerate(s):",
"- if c == \"0\":",
"- tmp = i",
"- else:",
"- ans += pc[i][0]",
"- p += (i + 1) * 100 * pc[i][0] + pc[i][1]",
"- for i in range(pc[tmp][0] - 1):",
"- if p < G:",
"- p += (tmp + 1) * 100",
"- ans += 1",
"- if p < G:",
"- return inf",
"- else:",
"- return ans",
"- tmp1 = dfs(h + 1, s + \"0\")",
"- tmp2 = dfs(h + 1, s + \"1\")",
"- return min(tmp1, tmp2)",
"+def function(G, i):",
"+ if i == 0:",
"+ return 1e9",
"+ n = min(G // (i * 100), PC[i][0])",
"+ s = n * i * 100",
"+ if n == PC[i][0]:",
"+ s += PC[i][1]",
"+ if s < G:",
"+ n += function(G - s, i - 1)",
"+ return min(n, function(G, i - 1))",
"-D, G = list(map(int, input().split()))",
"-pc = [list(map(int, input().split())) for _ in range(D)]",
"-print((dfs(0, \"\")))",
"+print((function(G, D)))"
] | false | 0.037089 | 0.035346 | 1.049319 | [
"s250207127",
"s170972437"
] |
u506858457 | p02936 | python | s708354080 | s374187343 | 1,244 | 1,137 | 58,148 | 58,052 | Accepted | Accepted | 8.6 | import collections
n,q=list(map(int,input().split()))
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
a,b=list(map(int,input().split()))
g[a].append(b)
g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
v,val=list(map(int,input().split()))
cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
v=q.pop()
checked[v]=1 #頂点を見たかどうかのフラグを更新する
for u in g[v]:
if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
continue
cnt[u]+=cnt[v]
q.append(u) #スタックに子ノードuを積む
print((*cnt[1:])) #各頂点のcountが答えとなる | import collections
#def input():
# return sys.stdin.readline()[:-1]
N , Q = list(map(int,input().split()))
graph = [[] for _ in range(N+1)]
point = [0] * (N+1)
for _ in range(N - 1):
a , b = list(map(int,input().split()))
graph[a].append(b)
graph[b].append(a)
#print(graph)
for _ in range(Q):
a , b = list(map(int,input().split()))
#a = a - 1
point[a] += b
q=collections.deque()
q.append(1)
checked=[0]*(N+1)
while q:
v=q.pop()
checked[v]=1
for u in graph[v]:
if checked[u]==1:
continue
point[u]+=point[v]
q.append(u)
print((*point[1:])) | 24 | 30 | 644 | 608 | import collections
n, q = list(map(int, input().split()))
cnt = [0] * (n + 1)
g = [[] for _ in range(n + 1)]
for _ in range(n - 1): # 木グラフの隣接リストを作成
a, b = list(map(int, input().split()))
g[a].append(b)
g[b].append(a)
for _ in range(q): # 各頂点についてcount[v]を計算
v, val = list(map(int, input().split()))
cnt[v] += val
q = collections.deque()
q.append(1) # DFSのスタックによる実装、まずスタックに始点1を積む
checked = [0] * (n + 1) # 各頂点を見たかどうかのフラグを持っておく
while q:
v = q.pop()
checked[v] = 1 # 頂点を見たかどうかのフラグを更新する
for u in g[v]:
if (
checked[u] == 1
): # vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
continue
cnt[u] += cnt[v]
q.append(u) # スタックに子ノードuを積む
print((*cnt[1:])) # 各頂点のcountが答えとなる
| import collections
# def input():
# return sys.stdin.readline()[:-1]
N, Q = list(map(int, input().split()))
graph = [[] for _ in range(N + 1)]
point = [0] * (N + 1)
for _ in range(N - 1):
a, b = list(map(int, input().split()))
graph[a].append(b)
graph[b].append(a)
# print(graph)
for _ in range(Q):
a, b = list(map(int, input().split()))
# a = a - 1
point[a] += b
q = collections.deque()
q.append(1)
checked = [0] * (N + 1)
while q:
v = q.pop()
checked[v] = 1
for u in graph[v]:
if checked[u] == 1:
continue
point[u] += point[v]
q.append(u)
print((*point[1:]))
| false | 20 | [
"-n, q = list(map(int, input().split()))",
"-cnt = [0] * (n + 1)",
"-g = [[] for _ in range(n + 1)]",
"-for _ in range(n - 1): # 木グラフの隣接リストを作成",
"+# def input():",
"+# return sys.stdin.readline()[:-1]",
"+N, Q = list(map(int, input().split()))",
"+graph = [[] for _ in range(N + 1)]",
"+point = [0] * (N + 1)",
"+for _ in range(N - 1):",
"- g[a].append(b)",
"- g[b].append(a)",
"-for _ in range(q): # 各頂点についてcount[v]を計算",
"- v, val = list(map(int, input().split()))",
"- cnt[v] += val",
"+ graph[a].append(b)",
"+ graph[b].append(a)",
"+# print(graph)",
"+for _ in range(Q):",
"+ a, b = list(map(int, input().split()))",
"+ # a = a - 1",
"+ point[a] += b",
"-q.append(1) # DFSのスタックによる実装、まずスタックに始点1を積む",
"-checked = [0] * (n + 1) # 各頂点を見たかどうかのフラグを持っておく",
"+q.append(1)",
"+checked = [0] * (N + 1)",
"- checked[v] = 1 # 頂点を見たかどうかのフラグを更新する",
"- for u in g[v]:",
"- if (",
"- checked[u] == 1",
"- ): # vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する",
"+ checked[v] = 1",
"+ for u in graph[v]:",
"+ if checked[u] == 1:",
"- cnt[u] += cnt[v]",
"- q.append(u) # スタックに子ノードuを積む",
"-print((*cnt[1:])) # 各頂点のcountが答えとなる",
"+ point[u] += point[v]",
"+ q.append(u)",
"+print((*point[1:]))"
] | false | 0.036999 | 0.038197 | 0.968642 | [
"s708354080",
"s374187343"
] |
u957872856 | p03680 | python | s286241382 | s667741724 | 218 | 197 | 7,852 | 7,084 | Accepted | Accepted | 9.63 | n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
b = [0]*n
b[0] = 1
count = 0
c = a[0]
for i in range(n):
if b[c-1] == 0:
b[c-1] = 1
if c == 2:
print((count+1))
break
else:
print((-1))
break
c = a[c-1]
count += 1 | n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
c, s = 1, a[0]
while s!= 2 and c<n:
c, s = c+1, a[s-1]
print((c if c<n else -1)) | 17 | 6 | 265 | 139 | n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
b = [0] * n
b[0] = 1
count = 0
c = a[0]
for i in range(n):
if b[c - 1] == 0:
b[c - 1] = 1
if c == 2:
print((count + 1))
break
else:
print((-1))
break
c = a[c - 1]
count += 1
| n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
c, s = 1, a[0]
while s != 2 and c < n:
c, s = c + 1, a[s - 1]
print((c if c < n else -1))
| false | 64.705882 | [
"-b = [0] * n",
"-b[0] = 1",
"-count = 0",
"-c = a[0]",
"-for i in range(n):",
"- if b[c - 1] == 0:",
"- b[c - 1] = 1",
"- if c == 2:",
"- print((count + 1))",
"- break",
"- else:",
"- print((-1))",
"- break",
"- c = a[c - 1]",
"- count += 1",
"+c, s = 1, a[0]",
"+while s != 2 and c < n:",
"+ c, s = c + 1, a[s - 1]",
"+print((c if c < n else -1))"
] | false | 0.035849 | 0.03792 | 0.945375 | [
"s286241382",
"s667741724"
] |
u644907318 | p03845 | python | s264568594 | s799187577 | 170 | 62 | 38,256 | 62,744 | Accepted | Accepted | 63.53 | N = int(eval(input()))
T = list(map(int,input().split()))
T.insert(0,0)
tot = sum(T)
M = int(eval(input()))
for _ in range(M):
P,X = list(map(int,input().split()))
print((tot-T[P]+X)) | N = int(eval(input()))
T = list(map(int,input().split()))
T.insert(0,0)
M = int(eval(input()))
X = [list(map(int,input().split())) for _ in range(M)]
tot = sum(T)
for i in range(M):
p,x = X[i]
print((tot-T[p]+x)) | 8 | 9 | 178 | 215 | N = int(eval(input()))
T = list(map(int, input().split()))
T.insert(0, 0)
tot = sum(T)
M = int(eval(input()))
for _ in range(M):
P, X = list(map(int, input().split()))
print((tot - T[P] + X))
| N = int(eval(input()))
T = list(map(int, input().split()))
T.insert(0, 0)
M = int(eval(input()))
X = [list(map(int, input().split())) for _ in range(M)]
tot = sum(T)
for i in range(M):
p, x = X[i]
print((tot - T[p] + x))
| false | 11.111111 | [
"+M = int(eval(input()))",
"+X = [list(map(int, input().split())) for _ in range(M)]",
"-M = int(eval(input()))",
"-for _ in range(M):",
"- P, X = list(map(int, input().split()))",
"- print((tot - T[P] + X))",
"+for i in range(M):",
"+ p, x = X[i]",
"+ print((tot - T[p] + x))"
] | false | 0.038657 | 0.045832 | 0.84344 | [
"s264568594",
"s799187577"
] |
u678247011 | p02388 | python | s841051708 | s424735880 | 20 | 10 | 5,576 | 4,628 | Accepted | Accepted | 50 | x = int(eval(input ()))
print((x**3))
| x = int(eval(input()))
print((x*x*x))
| 2 | 2 | 32 | 32 | x = int(eval(input()))
print((x**3))
| x = int(eval(input()))
print((x * x * x))
| false | 0 | [
"-print((x**3))",
"+print((x * x * x))"
] | false | 0.031603 | 0.041565 | 0.760311 | [
"s841051708",
"s424735880"
] |
u761320129 | p03548 | python | s500372602 | s251408962 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | X,Y,Z = list(map(int,input().split()))
print(((X-Z) // (Y+Z)))
| x,y,z = list(map(int,input().split()))
print(((x-z)//(y+z))) | 2 | 2 | 56 | 53 | X, Y, Z = list(map(int, input().split()))
print(((X - Z) // (Y + Z)))
| x, y, z = list(map(int, input().split()))
print(((x - z) // (y + z)))
| false | 0 | [
"-X, Y, Z = list(map(int, input().split()))",
"-print(((X - Z) // (Y + Z)))",
"+x, y, z = list(map(int, input().split()))",
"+print(((x - z) // (y + z)))"
] | false | 0.069763 | 0.079633 | 0.876053 | [
"s500372602",
"s251408962"
] |
u692746605 | p02579 | python | s086881772 | s218618692 | 1,656 | 1,418 | 24,544 | 24,428 | Accepted | Accepted | 14.37 | from collections import deque
def main():
h,w=list(map(int,input().split()))
cy,cx=list(map(int,input().split()))
dy,dx=list(map(int,input().split()))
M=["##"+eval(input())+"##" for x in range(h)]
for i in range(2):
M.insert(0,"#"*(w+4))
M.append("#"*(w+4))
C=[[-1 if M[j][i]=="." else -2 for i in range(w+4)] for j in range(h+4)]
C[-~cy][-~cx]=0
QA,QB=deque(),deque()
QA.append((-~cy,-~cx,0))
W=[[i,j] for i in range(-2,3) for j in range(-2,3) if abs(i)+abs(j)>1]
while QA:
h,w,c=QA.popleft()
QB.append((h,w,c))
for i,j in [[1,0],[0,1],[-1,0],[0,-1]]:
dh,dw=h+i,w+j
if C[dh][dw]==-1:
C[dh][dw]=c
QA.appendleft((dh,dw,c))
if QA:
continue
while QB:
h,w,c=QB.popleft()
for i,j in W:
dh,dw=h+i,w+j
if C[dh][dw]==-1:
C[dh][dw]=-~c
QA.append((dh,dw,-~c))
print((C[-~dy][-~dx]))
if __name__ == "__main__":
main()
| from collections import deque
def main():
h,w=list(map(int,input().split()))
cy,cx=list(map(int,input().split()))
dy,dx=list(map(int,input().split()))
M=["##"+eval(input())+"##" for x in range(h)]
for i in range(2):
M.insert(0,"#"*(w+4))
M.append("#"*(w+4))
C=[[-1 if M[j][i]=="." else -2 for i in range(w+4)] for j in range(h+4)]
C[-~cy][-~cx]=0
QA,QB=deque(),deque()
QA.append((-~cy,-~cx,0))
W=[[i,j] for i in range(-2,3) for j in range(-2,3) if abs(i)+abs(j)>1]
while QA:
h,w,c=QA.popleft()
QB.append((h,w,c))
for i,j in [[1,0],[0,1],[-1,0],[0,-1]]:
dh,dw=h+i,w+j
if C[dh][dw]==-1:
C[dh][dw]=c
QA.appendleft((dh,dw,c))
if QA:
continue
while QB:
h,w,c=QB.popleft()
for i,j in W:
dh,dw=h+i,w+j
if C[dh][dw]==-1:
C[dh][dw]=-~c
QA.append((dh,dw,-~c))
if C[-~dy][-~dx]!=-1:
print((C[-~dy][-~dx]))
exit()
print((C[-~dy][-~dx]))
if __name__ == "__main__":
main()
| 43 | 47 | 968 | 1,039 | from collections import deque
def main():
h, w = list(map(int, input().split()))
cy, cx = list(map(int, input().split()))
dy, dx = list(map(int, input().split()))
M = ["##" + eval(input()) + "##" for x in range(h)]
for i in range(2):
M.insert(0, "#" * (w + 4))
M.append("#" * (w + 4))
C = [[-1 if M[j][i] == "." else -2 for i in range(w + 4)] for j in range(h + 4)]
C[-~cy][-~cx] = 0
QA, QB = deque(), deque()
QA.append((-~cy, -~cx, 0))
W = [[i, j] for i in range(-2, 3) for j in range(-2, 3) if abs(i) + abs(j) > 1]
while QA:
h, w, c = QA.popleft()
QB.append((h, w, c))
for i, j in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
dh, dw = h + i, w + j
if C[dh][dw] == -1:
C[dh][dw] = c
QA.appendleft((dh, dw, c))
if QA:
continue
while QB:
h, w, c = QB.popleft()
for i, j in W:
dh, dw = h + i, w + j
if C[dh][dw] == -1:
C[dh][dw] = -~c
QA.append((dh, dw, -~c))
print((C[-~dy][-~dx]))
if __name__ == "__main__":
main()
| from collections import deque
def main():
h, w = list(map(int, input().split()))
cy, cx = list(map(int, input().split()))
dy, dx = list(map(int, input().split()))
M = ["##" + eval(input()) + "##" for x in range(h)]
for i in range(2):
M.insert(0, "#" * (w + 4))
M.append("#" * (w + 4))
C = [[-1 if M[j][i] == "." else -2 for i in range(w + 4)] for j in range(h + 4)]
C[-~cy][-~cx] = 0
QA, QB = deque(), deque()
QA.append((-~cy, -~cx, 0))
W = [[i, j] for i in range(-2, 3) for j in range(-2, 3) if abs(i) + abs(j) > 1]
while QA:
h, w, c = QA.popleft()
QB.append((h, w, c))
for i, j in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
dh, dw = h + i, w + j
if C[dh][dw] == -1:
C[dh][dw] = c
QA.appendleft((dh, dw, c))
if QA:
continue
while QB:
h, w, c = QB.popleft()
for i, j in W:
dh, dw = h + i, w + j
if C[dh][dw] == -1:
C[dh][dw] = -~c
QA.append((dh, dw, -~c))
if C[-~dy][-~dx] != -1:
print((C[-~dy][-~dx]))
exit()
print((C[-~dy][-~dx]))
if __name__ == "__main__":
main()
| false | 8.510638 | [
"+ if C[-~dy][-~dx] != -1:",
"+ print((C[-~dy][-~dx]))",
"+ exit()"
] | false | 0.037486 | 0.035839 | 1.045952 | [
"s086881772",
"s218618692"
] |
u059436995 | p03013 | python | s652026512 | s938364994 | 176 | 67 | 7,668 | 7,668 | Accepted | Accepted | 61.93 | n, m = list(map(int, input().split()))
mod = 1000000007
a = [True] * (n + 1)
for i in range(m):
a[int(eval(input()))] = False
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = dp[0] if a[1] else 0
for i in range(2, n + 1):
if a[i]:
dp[i] = (dp[i - 1] + dp[i - 2]) % mod
print((dp[n]))
| import sys
n, m = list(map(int,input().split()))
mod = 1000000007
a = [True] * (n + 1)
for i in range(m):
a[int(sys.stdin.readline())] = False
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = dp[0] if a[1] else 0
for i in range(2, n + 1):
if a[i]:
dp[i] = (dp[i - 1] + dp[i - 2]) % mod
print((dp[n]))
| 15 | 16 | 291 | 315 | n, m = list(map(int, input().split()))
mod = 1000000007
a = [True] * (n + 1)
for i in range(m):
a[int(eval(input()))] = False
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = dp[0] if a[1] else 0
for i in range(2, n + 1):
if a[i]:
dp[i] = (dp[i - 1] + dp[i - 2]) % mod
print((dp[n]))
| import sys
n, m = list(map(int, input().split()))
mod = 1000000007
a = [True] * (n + 1)
for i in range(m):
a[int(sys.stdin.readline())] = False
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = dp[0] if a[1] else 0
for i in range(2, n + 1):
if a[i]:
dp[i] = (dp[i - 1] + dp[i - 2]) % mod
print((dp[n]))
| false | 6.25 | [
"+import sys",
"+",
"- a[int(eval(input()))] = False",
"+ a[int(sys.stdin.readline())] = False"
] | false | 0.03636 | 0.034854 | 1.043208 | [
"s652026512",
"s938364994"
] |
u467736898 | p02698 | python | s413698096 | s419620572 | 1,092 | 580 | 263,264 | 93,608 | Accepted | Accepted | 46.89 | import sys
from bisect import bisect_left
def main():
sys.setrecursionlimit(202020)
N = int(eval(input()))
A = [0] + list(map(int, input().split()))
G = [[] for _ in range(N+1)]
for _ in range(N-1):
u, v = list(map(int, input().split()))
G[u].append(v)
G[v].append(u)
L = [A[1]]
Ans = [0] * (N+1)
def dfs(v):
Ans[v] = len(L)
for u in G[v]:
G[u].remove(v)
Au = A[u]
if Au > L[-1]:
L.append(Au)
dfs(u)
del L[-1]
else:
idx = bisect_left(L, Au)
old = L[idx]
L[idx] = Au
dfs(u)
L[idx] = old
dfs(1)
print(("\n".join(map(str, Ans[1:]))))
main()
| def numba_compile(numba_config):
import os, sys
if sys.argv[-1] == "ONLINE_JUDGE":
from numba import njit
from numba.pycc import CC
cc = CC("my_module")
for func, signature in numba_config:
globals()[func.__name__] = njit(signature)(func)
cc.export(func.__name__, signature)(func)
cc.compile()
exit()
elif os.name == "posix":
exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
for func, _ in numba_config:
globals()[func.__name__] = vars()[func.__name__]
else:
from numba import njit
for func, signature in numba_config:
globals()[func.__name__] = njit(signature, cache=True)(func)
print("compiled!", file=sys.stderr)
import sys
import numpy as np
def solve(N, A, UV):
G = [[0] * 0 for _ in range(N)]
for i in range(N-1):
u, v = UV[i]
G[u].append(v)
G[v].append(u)
L = [A[0]]
Ans = np.zeros(N, dtype=np.int64)
stack = [(0, 0, 0, -1, -1)] # 頂点、状態、見ている子のインデックス、行った行動*2
while stack:
v, state, idx_Gv, idx_L, old = stack.pop()
if state == 0:
Ans[v] = len(L)
if state == 2:
if idx_L == -1:
del L[-1]
else:
L[idx_L] = old
Gv = G[v]
if len(Gv) == idx_Gv:
continue
u = Gv[idx_Gv]
G[u].remove(v)
Au = A[u]
if Au > L[-1]:
L.append(Au)
stack.append((v, 2, idx_Gv + 1, -1, -1))
stack.append((u, 0, 0, -1, -1))
continue
else:
idx_L = np.searchsorted(L, Au)
old = L[idx_L]
L[idx_L] = Au
stack.append((v, 2, idx_Gv + 1, idx_L, old))
stack.append((u, 0, 0, -1, -1))
continue
return Ans
numba_compile([
[solve, "i8[:](i8,i8[:],i8[:,:])"]
])
def main():
input = sys.stdin.buffer.readline
N = int(input())
A = np.array(input().split(), dtype=np.int64)
UV = np.array(sys.stdin.buffer.read().split(), dtype=np.int64).reshape(N-1, 2) - 1
Ans = solve(N, A, UV)
print("\n".join(map(str, Ans.tolist())))
main()
| 32 | 76 | 812 | 2,314 | import sys
from bisect import bisect_left
def main():
sys.setrecursionlimit(202020)
N = int(eval(input()))
A = [0] + list(map(int, input().split()))
G = [[] for _ in range(N + 1)]
for _ in range(N - 1):
u, v = list(map(int, input().split()))
G[u].append(v)
G[v].append(u)
L = [A[1]]
Ans = [0] * (N + 1)
def dfs(v):
Ans[v] = len(L)
for u in G[v]:
G[u].remove(v)
Au = A[u]
if Au > L[-1]:
L.append(Au)
dfs(u)
del L[-1]
else:
idx = bisect_left(L, Au)
old = L[idx]
L[idx] = Au
dfs(u)
L[idx] = old
dfs(1)
print(("\n".join(map(str, Ans[1:]))))
main()
| def numba_compile(numba_config):
import os, sys
if sys.argv[-1] == "ONLINE_JUDGE":
from numba import njit
from numba.pycc import CC
cc = CC("my_module")
for func, signature in numba_config:
globals()[func.__name__] = njit(signature)(func)
cc.export(func.__name__, signature)(func)
cc.compile()
exit()
elif os.name == "posix":
exec(
f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}"
)
for func, _ in numba_config:
globals()[func.__name__] = vars()[func.__name__]
else:
from numba import njit
for func, signature in numba_config:
globals()[func.__name__] = njit(signature, cache=True)(func)
print("compiled!", file=sys.stderr)
import sys
import numpy as np
def solve(N, A, UV):
G = [[0] * 0 for _ in range(N)]
for i in range(N - 1):
u, v = UV[i]
G[u].append(v)
G[v].append(u)
L = [A[0]]
Ans = np.zeros(N, dtype=np.int64)
stack = [(0, 0, 0, -1, -1)] # 頂点、状態、見ている子のインデックス、行った行動*2
while stack:
v, state, idx_Gv, idx_L, old = stack.pop()
if state == 0:
Ans[v] = len(L)
if state == 2:
if idx_L == -1:
del L[-1]
else:
L[idx_L] = old
Gv = G[v]
if len(Gv) == idx_Gv:
continue
u = Gv[idx_Gv]
G[u].remove(v)
Au = A[u]
if Au > L[-1]:
L.append(Au)
stack.append((v, 2, idx_Gv + 1, -1, -1))
stack.append((u, 0, 0, -1, -1))
continue
else:
idx_L = np.searchsorted(L, Au)
old = L[idx_L]
L[idx_L] = Au
stack.append((v, 2, idx_Gv + 1, idx_L, old))
stack.append((u, 0, 0, -1, -1))
continue
return Ans
numba_compile([[solve, "i8[:](i8,i8[:],i8[:,:])"]])
def main():
input = sys.stdin.buffer.readline
N = int(input())
A = np.array(input().split(), dtype=np.int64)
UV = np.array(sys.stdin.buffer.read().split(), dtype=np.int64).reshape(N - 1, 2) - 1
Ans = solve(N, A, UV)
print("\n".join(map(str, Ans.tolist())))
main()
| false | 57.894737 | [
"+def numba_compile(numba_config):",
"+ import os, sys",
"+",
"+ if sys.argv[-1] == \"ONLINE_JUDGE\":",
"+ from numba import njit",
"+ from numba.pycc import CC",
"+",
"+ cc = CC(\"my_module\")",
"+ for func, signature in numba_config:",
"+ globals()[func.__name__] = njit(signature)(func)",
"+ cc.export(func.__name__, signature)(func)",
"+ cc.compile()",
"+ exit()",
"+ elif os.name == \"posix\":",
"+ exec(",
"+ f\"from my_module import {','.join(func.__name__ for func, _ in numba_config)}\"",
"+ )",
"+ for func, _ in numba_config:",
"+ globals()[func.__name__] = vars()[func.__name__]",
"+ else:",
"+ from numba import njit",
"+",
"+ for func, signature in numba_config:",
"+ globals()[func.__name__] = njit(signature, cache=True)(func)",
"+ print(\"compiled!\", file=sys.stderr)",
"+",
"+",
"-from bisect import bisect_left",
"+import numpy as np",
"+",
"+",
"+def solve(N, A, UV):",
"+ G = [[0] * 0 for _ in range(N)]",
"+ for i in range(N - 1):",
"+ u, v = UV[i]",
"+ G[u].append(v)",
"+ G[v].append(u)",
"+ L = [A[0]]",
"+ Ans = np.zeros(N, dtype=np.int64)",
"+ stack = [(0, 0, 0, -1, -1)] # 頂点、状態、見ている子のインデックス、行った行動*2",
"+ while stack:",
"+ v, state, idx_Gv, idx_L, old = stack.pop()",
"+ if state == 0:",
"+ Ans[v] = len(L)",
"+ if state == 2:",
"+ if idx_L == -1:",
"+ del L[-1]",
"+ else:",
"+ L[idx_L] = old",
"+ Gv = G[v]",
"+ if len(Gv) == idx_Gv:",
"+ continue",
"+ u = Gv[idx_Gv]",
"+ G[u].remove(v)",
"+ Au = A[u]",
"+ if Au > L[-1]:",
"+ L.append(Au)",
"+ stack.append((v, 2, idx_Gv + 1, -1, -1))",
"+ stack.append((u, 0, 0, -1, -1))",
"+ continue",
"+ else:",
"+ idx_L = np.searchsorted(L, Au)",
"+ old = L[idx_L]",
"+ L[idx_L] = Au",
"+ stack.append((v, 2, idx_Gv + 1, idx_L, old))",
"+ stack.append((u, 0, 0, -1, -1))",
"+ continue",
"+ return Ans",
"+",
"+",
"+numba_compile([[solve, \"i8[:](i8,i8[:],i8[:,:])\"]])",
"- sys.setrecursionlimit(202020)",
"- N = int(eval(input()))",
"- A = [0] + list(map(int, input().split()))",
"- G = [[] for _ in range(N + 1)]",
"- for _ in range(N - 1):",
"- u, v = list(map(int, input().split()))",
"- G[u].append(v)",
"- G[v].append(u)",
"- L = [A[1]]",
"- Ans = [0] * (N + 1)",
"-",
"- def dfs(v):",
"- Ans[v] = len(L)",
"- for u in G[v]:",
"- G[u].remove(v)",
"- Au = A[u]",
"- if Au > L[-1]:",
"- L.append(Au)",
"- dfs(u)",
"- del L[-1]",
"- else:",
"- idx = bisect_left(L, Au)",
"- old = L[idx]",
"- L[idx] = Au",
"- dfs(u)",
"- L[idx] = old",
"-",
"- dfs(1)",
"- print((\"\\n\".join(map(str, Ans[1:]))))",
"+ input = sys.stdin.buffer.readline",
"+ N = int(input())",
"+ A = np.array(input().split(), dtype=np.int64)",
"+ UV = np.array(sys.stdin.buffer.read().split(), dtype=np.int64).reshape(N - 1, 2) - 1",
"+ Ans = solve(N, A, UV)",
"+ print(\"\\n\".join(map(str, Ans.tolist())))"
] | false | 0.041978 | 0.195109 | 0.21515 | [
"s413698096",
"s419620572"
] |
u493520238 | p02996 | python | s201607500 | s297291821 | 790 | 708 | 38,048 | 94,540 | Accepted | Accepted | 10.38 | def main():
n = int(eval(input()))
abl = []
for _ in range(n):
a, b = list(map(int, input().split()))
abl.append([a,b])
abl.sort(key=lambda x:x[1])
curr_time = 0
for curr_ab in abl:
# print(curr_time)
a,b = curr_ab
curr_time += a
if curr_time > b:
print('No')
return
print('Yes')
if __name__ == "__main__":
main() | n = int(eval(input()))
abl = []
for _ in range(n):
a,b = list(map(int, input().split()))
abl.append((b,a))
abl.sort()
curr = 0
for b,a in abl:
curr += a
if curr > b:
print('No')
break
else:
print('Yes') | 21 | 15 | 429 | 241 | def main():
n = int(eval(input()))
abl = []
for _ in range(n):
a, b = list(map(int, input().split()))
abl.append([a, b])
abl.sort(key=lambda x: x[1])
curr_time = 0
for curr_ab in abl:
# print(curr_time)
a, b = curr_ab
curr_time += a
if curr_time > b:
print("No")
return
print("Yes")
if __name__ == "__main__":
main()
| n = int(eval(input()))
abl = []
for _ in range(n):
a, b = list(map(int, input().split()))
abl.append((b, a))
abl.sort()
curr = 0
for b, a in abl:
curr += a
if curr > b:
print("No")
break
else:
print("Yes")
| false | 28.571429 | [
"-def main():",
"- n = int(eval(input()))",
"- abl = []",
"- for _ in range(n):",
"- a, b = list(map(int, input().split()))",
"- abl.append([a, b])",
"- abl.sort(key=lambda x: x[1])",
"- curr_time = 0",
"- for curr_ab in abl:",
"- # print(curr_time)",
"- a, b = curr_ab",
"- curr_time += a",
"- if curr_time > b:",
"- print(\"No\")",
"- return",
"+n = int(eval(input()))",
"+abl = []",
"+for _ in range(n):",
"+ a, b = list(map(int, input().split()))",
"+ abl.append((b, a))",
"+abl.sort()",
"+curr = 0",
"+for b, a in abl:",
"+ curr += a",
"+ if curr > b:",
"+ print(\"No\")",
"+ break",
"+else:",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()"
] | false | 0.082186 | 0.079374 | 1.035431 | [
"s201607500",
"s297291821"
] |
u498487134 | p02775 | python | s674889021 | s815900352 | 1,114 | 148 | 138,336 | 78,964 | Accepted | Accepted | 86.71 | S="0"+eval(input())
dig=len(S)
#dp[i][j]は下からi桁みたときの最小で,jは繰り下がりの有無
#自分が出す:a お釣り:b
inf=10**10
dp=[[inf,inf] for _ in range(dig+1)]
dp[0]=[0,0]
for i in range(dig):
for j in range(2):
if i==0 and j==1:
break
x=int(S[dig-i-1])
for a in range(10):
jj=0#次のj,繰り下がるかどうか
b=(a-j)-x#j=1なら,繰り下がっているためaが1下がっている
if b<0:
b+=10
jj=1
dp[i+1][jj]=min(dp[i+1][jj] , dp[i][j]+a+b)
print((dp[-1][0]))
|
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
S="00"+eval(input())
S=S[::-1]
N=len(S)-1
def calc(x,nxt):
# 今見てる数字,次の桁の数字,を受けて
# 今使う,繰り上がり,を返す
if x<=4:
return x,0
elif x>=6:
return 10-x,1
else:
# 次が5なら,そのあと5以上ががくればお得,そうでなくとも損しない
if nxt<5:
return 5,0
else:
return 5,1
kuri=0
ans=0
for i in range(N):
now=int(S[i])
nxt=int(S[i+1])
now+=kuri
temp,kuri = calc(now,nxt)
ans+=temp
print(ans)
main()
| 28 | 40 | 539 | 773 | S = "0" + eval(input())
dig = len(S)
# dp[i][j]は下からi桁みたときの最小で,jは繰り下がりの有無
# 自分が出す:a お釣り:b
inf = 10**10
dp = [[inf, inf] for _ in range(dig + 1)]
dp[0] = [0, 0]
for i in range(dig):
for j in range(2):
if i == 0 and j == 1:
break
x = int(S[dig - i - 1])
for a in range(10):
jj = 0 # 次のj,繰り下がるかどうか
b = (a - j) - x # j=1なら,繰り下がっているためaが1下がっている
if b < 0:
b += 10
jj = 1
dp[i + 1][jj] = min(dp[i + 1][jj], dp[i][j] + a + b)
print((dp[-1][0]))
| def I():
return int(eval(input()))
def MI():
return list(map(int, input().split()))
def LI():
return list(map(int, input().split()))
def main():
mod = 10**9 + 7
S = "00" + eval(input())
S = S[::-1]
N = len(S) - 1
def calc(x, nxt):
# 今見てる数字,次の桁の数字,を受けて
# 今使う,繰り上がり,を返す
if x <= 4:
return x, 0
elif x >= 6:
return 10 - x, 1
else:
# 次が5なら,そのあと5以上ががくればお得,そうでなくとも損しない
if nxt < 5:
return 5, 0
else:
return 5, 1
kuri = 0
ans = 0
for i in range(N):
now = int(S[i])
nxt = int(S[i + 1])
now += kuri
temp, kuri = calc(now, nxt)
ans += temp
print(ans)
main()
| false | 30 | [
"-S = \"0\" + eval(input())",
"-dig = len(S)",
"-# dp[i][j]は下からi桁みたときの最小で,jは繰り下がりの有無",
"-# 自分が出す:a お釣り:b",
"-inf = 10**10",
"-dp = [[inf, inf] for _ in range(dig + 1)]",
"-dp[0] = [0, 0]",
"-for i in range(dig):",
"- for j in range(2):",
"- if i == 0 and j == 1:",
"- break",
"- x = int(S[dig - i - 1])",
"- for a in range(10):",
"- jj = 0 # 次のj,繰り下がるかどうか",
"- b = (a - j) - x # j=1なら,繰り下がっているためaが1下がっている",
"- if b < 0:",
"- b += 10",
"- jj = 1",
"- dp[i + 1][jj] = min(dp[i + 1][jj], dp[i][j] + a + b)",
"-print((dp[-1][0]))",
"+def I():",
"+ return int(eval(input()))",
"+",
"+",
"+def MI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def LI():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def main():",
"+ mod = 10**9 + 7",
"+ S = \"00\" + eval(input())",
"+ S = S[::-1]",
"+ N = len(S) - 1",
"+",
"+ def calc(x, nxt):",
"+ # 今見てる数字,次の桁の数字,を受けて",
"+ # 今使う,繰り上がり,を返す",
"+ if x <= 4:",
"+ return x, 0",
"+ elif x >= 6:",
"+ return 10 - x, 1",
"+ else:",
"+ # 次が5なら,そのあと5以上ががくればお得,そうでなくとも損しない",
"+ if nxt < 5:",
"+ return 5, 0",
"+ else:",
"+ return 5, 1",
"+",
"+ kuri = 0",
"+ ans = 0",
"+ for i in range(N):",
"+ now = int(S[i])",
"+ nxt = int(S[i + 1])",
"+ now += kuri",
"+ temp, kuri = calc(now, nxt)",
"+ ans += temp",
"+ print(ans)",
"+",
"+",
"+main()"
] | false | 0.053123 | 0.03545 | 1.498528 | [
"s674889021",
"s815900352"
] |
u941047297 | p03361 | python | s614872190 | s133446245 | 171 | 20 | 39,280 | 3,064 | Accepted | Accepted | 88.3 | from itertools import product
H, W = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
can = True
S = ['.' * (W + 2)] + ['.' + s + '.' for s in S] + ['.' * (W + 2)]
S = [list(s) for s in S]
dHW = [[-1, 0], [1, 0], [0, -1], [0, 1]]
for h, w in product(list(range(1, H + 1)), list(range(1, W + 1))):
if S[h][w] == '#':
exist = False
for (dh, dw) in dHW:
if S[h + dh][w + dw] == '#':
exist = True
break
if exist:
continue
else:
can = False
break
if can:
print('Yes')
else:
print('No') | from itertools import product
H, W = list(map(int, input().split()))
board = [['.'] * W] + [list(eval(input())) for _ in range(H)] + [['.'] * W]
board = [['.'] + b + ['.'] for b in board]
dhw = [[1, 0], [-1, 0], [0, 1], [0, -1]]
for h, w in product(list(range(1, H + 1)), list(range(1, W + 1))):
if board[h][w] == '#':
can = False
for dh, dw in dhw:
if board[h + dh][w + dw] == '#':
can = True
break
if not can:
print('No')
exit()
print('Yes') | 23 | 16 | 629 | 536 | from itertools import product
H, W = list(map(int, input().split()))
S = [eval(input()) for _ in range(H)]
can = True
S = ["." * (W + 2)] + ["." + s + "." for s in S] + ["." * (W + 2)]
S = [list(s) for s in S]
dHW = [[-1, 0], [1, 0], [0, -1], [0, 1]]
for h, w in product(list(range(1, H + 1)), list(range(1, W + 1))):
if S[h][w] == "#":
exist = False
for (dh, dw) in dHW:
if S[h + dh][w + dw] == "#":
exist = True
break
if exist:
continue
else:
can = False
break
if can:
print("Yes")
else:
print("No")
| from itertools import product
H, W = list(map(int, input().split()))
board = [["."] * W] + [list(eval(input())) for _ in range(H)] + [["."] * W]
board = [["."] + b + ["."] for b in board]
dhw = [[1, 0], [-1, 0], [0, 1], [0, -1]]
for h, w in product(list(range(1, H + 1)), list(range(1, W + 1))):
if board[h][w] == "#":
can = False
for dh, dw in dhw:
if board[h + dh][w + dw] == "#":
can = True
break
if not can:
print("No")
exit()
print("Yes")
| false | 30.434783 | [
"-S = [eval(input()) for _ in range(H)]",
"-can = True",
"-S = [\".\" * (W + 2)] + [\".\" + s + \".\" for s in S] + [\".\" * (W + 2)]",
"-S = [list(s) for s in S]",
"-dHW = [[-1, 0], [1, 0], [0, -1], [0, 1]]",
"+board = [[\".\"] * W] + [list(eval(input())) for _ in range(H)] + [[\".\"] * W]",
"+board = [[\".\"] + b + [\".\"] for b in board]",
"+dhw = [[1, 0], [-1, 0], [0, 1], [0, -1]]",
"- if S[h][w] == \"#\":",
"- exist = False",
"- for (dh, dw) in dHW:",
"- if S[h + dh][w + dw] == \"#\":",
"- exist = True",
"+ if board[h][w] == \"#\":",
"+ can = False",
"+ for dh, dw in dhw:",
"+ if board[h + dh][w + dw] == \"#\":",
"+ can = True",
"- if exist:",
"- continue",
"- else:",
"- can = False",
"- break",
"-if can:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+ if not can:",
"+ print(\"No\")",
"+ exit()",
"+print(\"Yes\")"
] | false | 0.038532 | 0.087944 | 0.438138 | [
"s614872190",
"s133446245"
] |
u185405877 | p02718 | python | s971684002 | s846964289 | 19 | 17 | 3,064 | 3,060 | Accepted | Accepted | 10.53 | x,y= list(map(int, input().split()))
i = list(map(int, input().split()))
i.sort(reverse=True)
k=sum(i)
flag=0
if i[y-1]>=k/(4*y):
print("Yes")
else:
print("No") | x,y= list(map(int, input().split()))
i = list(map(int, input().split()))
i.sort(reverse=True)
k=sum(i)
flag=0
for j in range(x):
if i[j]*4*y>=k:
flag+=1
if flag<y:
print("No")
else:
print("Yes") | 9 | 12 | 176 | 225 | x, y = list(map(int, input().split()))
i = list(map(int, input().split()))
i.sort(reverse=True)
k = sum(i)
flag = 0
if i[y - 1] >= k / (4 * y):
print("Yes")
else:
print("No")
| x, y = list(map(int, input().split()))
i = list(map(int, input().split()))
i.sort(reverse=True)
k = sum(i)
flag = 0
for j in range(x):
if i[j] * 4 * y >= k:
flag += 1
if flag < y:
print("No")
else:
print("Yes")
| false | 25 | [
"-if i[y - 1] >= k / (4 * y):",
"+for j in range(x):",
"+ if i[j] * 4 * y >= k:",
"+ flag += 1",
"+if flag < y:",
"+ print(\"No\")",
"+else:",
"-else:",
"- print(\"No\")"
] | false | 0.074624 | 0.071163 | 1.048626 | [
"s971684002",
"s846964289"
] |
u879870653 | p02954 | python | s792018543 | s125841722 | 247 | 127 | 48,124 | 6,520 | Accepted | Accepted | 48.58 | S = eval(input())
N = len(S)
ans = [0]*N
cnt = 0
for i in range(N) :
if S[i] == "R" :
cnt += 1
elif cnt % 2 == 0 :
ans[i] += cnt//2
ans[i-1] += cnt//2
cnt = 0
else :
ans[i] += cnt//2
ans[i-1] += cnt//2 + 1
cnt = 0
cnt = 0
for i in range(N-1,-1,-1) :
if S[i] == "L" :
cnt += 1
elif cnt % 2 == 0 :
ans[i] += cnt//2
ans[i+1] += cnt//2
cnt = 0
else :
ans[i] += cnt//2
ans[i+1] += cnt//2 + 1
cnt = 0
print((*ans))
| S = eval(input())
N = len(S)
A = [0 for i in range(N)]
c = 0
for i in range(N) :
if S[i] == "R" :
c += 1
else :
if c % 2 == 0 :
A[i] += c//2
A[i-1] += c//2
else :
A[i] += c//2
A[i-1] += c//2 + 1
c = 0
c = 0
for i in range(N-1,-1,-1) :
if S[i] == "L" :
c += 1
else :
if c % 2 == 0 :
A[i] += c//2
A[i+1] += c//2
else :
A[i] += c//2
A[i+1] += c//2 + 1
c = 0
print((*A))
| 31 | 31 | 574 | 568 | S = eval(input())
N = len(S)
ans = [0] * N
cnt = 0
for i in range(N):
if S[i] == "R":
cnt += 1
elif cnt % 2 == 0:
ans[i] += cnt // 2
ans[i - 1] += cnt // 2
cnt = 0
else:
ans[i] += cnt // 2
ans[i - 1] += cnt // 2 + 1
cnt = 0
cnt = 0
for i in range(N - 1, -1, -1):
if S[i] == "L":
cnt += 1
elif cnt % 2 == 0:
ans[i] += cnt // 2
ans[i + 1] += cnt // 2
cnt = 0
else:
ans[i] += cnt // 2
ans[i + 1] += cnt // 2 + 1
cnt = 0
print((*ans))
| S = eval(input())
N = len(S)
A = [0 for i in range(N)]
c = 0
for i in range(N):
if S[i] == "R":
c += 1
else:
if c % 2 == 0:
A[i] += c // 2
A[i - 1] += c // 2
else:
A[i] += c // 2
A[i - 1] += c // 2 + 1
c = 0
c = 0
for i in range(N - 1, -1, -1):
if S[i] == "L":
c += 1
else:
if c % 2 == 0:
A[i] += c // 2
A[i + 1] += c // 2
else:
A[i] += c // 2
A[i + 1] += c // 2 + 1
c = 0
print((*A))
| false | 0 | [
"-ans = [0] * N",
"-cnt = 0",
"+A = [0 for i in range(N)]",
"+c = 0",
"- cnt += 1",
"- elif cnt % 2 == 0:",
"- ans[i] += cnt // 2",
"- ans[i - 1] += cnt // 2",
"- cnt = 0",
"+ c += 1",
"- ans[i] += cnt // 2",
"- ans[i - 1] += cnt // 2 + 1",
"- cnt = 0",
"-cnt = 0",
"+ if c % 2 == 0:",
"+ A[i] += c // 2",
"+ A[i - 1] += c // 2",
"+ else:",
"+ A[i] += c // 2",
"+ A[i - 1] += c // 2 + 1",
"+ c = 0",
"+c = 0",
"- cnt += 1",
"- elif cnt % 2 == 0:",
"- ans[i] += cnt // 2",
"- ans[i + 1] += cnt // 2",
"- cnt = 0",
"+ c += 1",
"- ans[i] += cnt // 2",
"- ans[i + 1] += cnt // 2 + 1",
"- cnt = 0",
"-print((*ans))",
"+ if c % 2 == 0:",
"+ A[i] += c // 2",
"+ A[i + 1] += c // 2",
"+ else:",
"+ A[i] += c // 2",
"+ A[i + 1] += c // 2 + 1",
"+ c = 0",
"+print((*A))"
] | false | 0.034032 | 0.039067 | 0.871127 | [
"s792018543",
"s125841722"
] |
u531220228 | p03029 | python | s338773669 | s058902696 | 20 | 17 | 3,316 | 2,940 | Accepted | Accepted | 15 | A,P = list(map(int, input().split()))
print(((3*A+P)//2)) | A, P = list(map(int, input().split()))
import math
print((math.floor((3*A + P)/2))) | 2 | 4 | 50 | 79 | A, P = list(map(int, input().split()))
print(((3 * A + P) // 2))
| A, P = list(map(int, input().split()))
import math
print((math.floor((3 * A + P) / 2)))
| false | 50 | [
"-print(((3 * A + P) // 2))",
"+import math",
"+",
"+print((math.floor((3 * A + P) / 2)))"
] | false | 0.082012 | 0.081886 | 1.001538 | [
"s338773669",
"s058902696"
] |
u922449550 | p02612 | python | s736103326 | s990369598 | 30 | 26 | 9,156 | 9,072 | Accepted | Accepted | 13.33 | N = int(eval(input()))
n = -(-N//1000)
print((n*1000 - N)) | print(((1000 - int(eval(input()))%1000) % 1000)) | 4 | 1 | 54 | 40 | N = int(eval(input()))
n = -(-N // 1000)
print((n * 1000 - N))
| print(((1000 - int(eval(input())) % 1000) % 1000))
| false | 75 | [
"-N = int(eval(input()))",
"-n = -(-N // 1000)",
"-print((n * 1000 - N))",
"+print(((1000 - int(eval(input())) % 1000) % 1000))"
] | false | 0.067575 | 0.14227 | 0.474975 | [
"s736103326",
"s990369598"
] |
u706695185 | p03212 | python | s020489624 | s082105892 | 181 | 106 | 7,028 | 7,028 | Accepted | Accepted | 41.44 | N = int(eval(input()))
dp = []
def dfs(x):
if check(x):
dp.append(x)
if (x <= 10**9):
dfs(10*x+3)
dfs(10*x+5)
dfs(10*x+7)
def check(x):
set_x = set(list(str(x)))
if set_x >= {'3','5','7'} and set_x <= {'3','5','7'}:
return True
dfs(0)
print((len([item for item in dp if item <= N]))) | N = int(eval(input()))
dp = []
def dfs(x):
if len(set(str(x))) == 3:
dp.append(x)
if x < 10**9:
dfs(x*10+3)
dfs(x*10+5)
dfs(x*10+7)
dfs(0)
print((len([item for item in dp if item <= N])))
| 21 | 14 | 357 | 236 | N = int(eval(input()))
dp = []
def dfs(x):
if check(x):
dp.append(x)
if x <= 10**9:
dfs(10 * x + 3)
dfs(10 * x + 5)
dfs(10 * x + 7)
def check(x):
set_x = set(list(str(x)))
if set_x >= {"3", "5", "7"} and set_x <= {"3", "5", "7"}:
return True
dfs(0)
print((len([item for item in dp if item <= N])))
| N = int(eval(input()))
dp = []
def dfs(x):
if len(set(str(x))) == 3:
dp.append(x)
if x < 10**9:
dfs(x * 10 + 3)
dfs(x * 10 + 5)
dfs(x * 10 + 7)
dfs(0)
print((len([item for item in dp if item <= N])))
| false | 33.333333 | [
"- if check(x):",
"+ if len(set(str(x))) == 3:",
"- if x <= 10**9:",
"- dfs(10 * x + 3)",
"- dfs(10 * x + 5)",
"- dfs(10 * x + 7)",
"-",
"-",
"-def check(x):",
"- set_x = set(list(str(x)))",
"- if set_x >= {\"3\", \"5\", \"7\"} and set_x <= {\"3\", \"5\", \"7\"}:",
"- return True",
"+ if x < 10**9:",
"+ dfs(x * 10 + 3)",
"+ dfs(x * 10 + 5)",
"+ dfs(x * 10 + 7)"
] | false | 0.30251 | 0.135942 | 2.225282 | [
"s020489624",
"s082105892"
] |
u183422236 | p02695 | python | s842635962 | s902722192 | 1,539 | 233 | 9,212 | 73,644 | Accepted | Accepted | 84.86 | import itertools
n, m, q = list(map(int, input().split()))
lst = [list(map(int, input().split())) for i in range(q)]
ans = 0
for A in itertools.combinations_with_replacement(list(range(1, m + 1)), n):
flag = 0
for k in range(n - 1):
if A[k + 1] < A[k]:
flag = 1
if flag == 0:
point = 0
for l in range(q):
if A[lst[l][1] - 1] - A[lst[l][0] - 1] == lst[l][2]:
point += lst[l][3]
ans = max(ans, point)
print(ans)
| import sys
sys.setrecursionlimit(1000000)
n, m, q = list(map(int, input().split()))
lst = [list(map(int, input().split())) for i in range(q)]
ans = 0
def dfs(A):
global ans
if len(A) == n + 1:
point = 0
for i in range(q):
if A[lst[i][1]] - A[lst[i][0]] == lst[i][2]:
point += lst[i][3]
ans = max(ans, point)
return
A.append(A[-1])
while A[-1] <= m:
dfs(A[:])
A[-1] += 1
dfs([1])
print(ans)
| 18 | 23 | 501 | 509 | import itertools
n, m, q = list(map(int, input().split()))
lst = [list(map(int, input().split())) for i in range(q)]
ans = 0
for A in itertools.combinations_with_replacement(list(range(1, m + 1)), n):
flag = 0
for k in range(n - 1):
if A[k + 1] < A[k]:
flag = 1
if flag == 0:
point = 0
for l in range(q):
if A[lst[l][1] - 1] - A[lst[l][0] - 1] == lst[l][2]:
point += lst[l][3]
ans = max(ans, point)
print(ans)
| import sys
sys.setrecursionlimit(1000000)
n, m, q = list(map(int, input().split()))
lst = [list(map(int, input().split())) for i in range(q)]
ans = 0
def dfs(A):
global ans
if len(A) == n + 1:
point = 0
for i in range(q):
if A[lst[i][1]] - A[lst[i][0]] == lst[i][2]:
point += lst[i][3]
ans = max(ans, point)
return
A.append(A[-1])
while A[-1] <= m:
dfs(A[:])
A[-1] += 1
dfs([1])
print(ans)
| false | 21.73913 | [
"-import itertools",
"+import sys",
"+sys.setrecursionlimit(1000000)",
"-for A in itertools.combinations_with_replacement(list(range(1, m + 1)), n):",
"- flag = 0",
"- for k in range(n - 1):",
"- if A[k + 1] < A[k]:",
"- flag = 1",
"- if flag == 0:",
"+",
"+",
"+def dfs(A):",
"+ global ans",
"+ if len(A) == n + 1:",
"- for l in range(q):",
"- if A[lst[l][1] - 1] - A[lst[l][0] - 1] == lst[l][2]:",
"- point += lst[l][3]",
"- ans = max(ans, point)",
"+ for i in range(q):",
"+ if A[lst[i][1]] - A[lst[i][0]] == lst[i][2]:",
"+ point += lst[i][3]",
"+ ans = max(ans, point)",
"+ return",
"+ A.append(A[-1])",
"+ while A[-1] <= m:",
"+ dfs(A[:])",
"+ A[-1] += 1",
"+",
"+",
"+dfs([1])"
] | false | 0.509027 | 0.072127 | 7.057356 | [
"s842635962",
"s902722192"
] |
u225388820 | p03628 | python | s998004798 | s343975122 | 64 | 29 | 61,936 | 9,140 | Accepted | Accepted | 54.69 | n = int(eval(input()))
s = eval(input()) + "@"
t = eval(input()) + "@"
mod = 10 ** 9 + 7
# 情報を1次元にして処理しやすくするぜ
# 縦で一致 True 横で一致 False
b = []
for i in range(n):
if s[i] == s[i + 1]:
continue
b.append(s[i] == t[i])
# 処理するぜ
if b[0]:
ans = 3
else:
ans = 6
for i in range(1, len(b)):
if b[i]:
if b[i - 1]:
ans *= 2
else:
if b[i - 1]:
ans *= 2
else:
ans *= 3
ans %= mod
print(ans)
| n = int(eval(input()))
s = eval(input()) + "@"
t = eval(input()) + "@"
mod = 10 ** 9 + 7
# 情報を1次元にして処理しやすくするぜ
# 縦で一致 True 横で一致 False
b = []
for i in range(n):
if s[i] == s[i + 1]:
continue
b.append(s[i] == t[i])
# 処理するぜ
if b[0]:
ans = 3
else:
ans = 6
for i in range(1, len(b)):
if b[i]:
if b[i - 1]:
ans *= 2
else:
if b[i - 1]:
ans *= 2
else:
ans *= 3
print((ans % mod))
| 31 | 31 | 486 | 478 | n = int(eval(input()))
s = eval(input()) + "@"
t = eval(input()) + "@"
mod = 10**9 + 7
# 情報を1次元にして処理しやすくするぜ
# 縦で一致 True 横で一致 False
b = []
for i in range(n):
if s[i] == s[i + 1]:
continue
b.append(s[i] == t[i])
# 処理するぜ
if b[0]:
ans = 3
else:
ans = 6
for i in range(1, len(b)):
if b[i]:
if b[i - 1]:
ans *= 2
else:
if b[i - 1]:
ans *= 2
else:
ans *= 3
ans %= mod
print(ans)
| n = int(eval(input()))
s = eval(input()) + "@"
t = eval(input()) + "@"
mod = 10**9 + 7
# 情報を1次元にして処理しやすくするぜ
# 縦で一致 True 横で一致 False
b = []
for i in range(n):
if s[i] == s[i + 1]:
continue
b.append(s[i] == t[i])
# 処理するぜ
if b[0]:
ans = 3
else:
ans = 6
for i in range(1, len(b)):
if b[i]:
if b[i - 1]:
ans *= 2
else:
if b[i - 1]:
ans *= 2
else:
ans *= 3
print((ans % mod))
| false | 0 | [
"- ans %= mod",
"-print(ans)",
"+print((ans % mod))"
] | false | 0.038625 | 0.038595 | 1.000793 | [
"s998004798",
"s343975122"
] |
u075739430 | p02848 | python | s095214353 | s992427408 | 15 | 13 | 2,568 | 2,692 | Accepted | Accepted | 13.33 | n = int(input())
s = input()
uppercase = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
t = ''
for ch in s:
ind = uppercase.index(ch)
ind = (ind + n) % 26
t += uppercase[ind]
print(t) | s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n= int(input())
x = input()
a = ord('A')
print(''.join([s[(ord(c) - a + n) % 26] for c in x])) | 9 | 5 | 294 | 138 | n = int(input())
s = input()
uppercase = [
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z",
]
t = ""
for ch in s:
ind = uppercase.index(ch)
ind = (ind + n) % 26
t += uppercase[ind]
print(t)
| s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
n = int(input())
x = input()
a = ord("A")
print("".join([s[(ord(c) - a + n) % 26] for c in x]))
| false | 44.444444 | [
"+s = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"",
"-s = input()",
"-uppercase = [",
"- \"A\",",
"- \"B\",",
"- \"C\",",
"- \"D\",",
"- \"E\",",
"- \"F\",",
"- \"G\",",
"- \"H\",",
"- \"I\",",
"- \"J\",",
"- \"K\",",
"- \"L\",",
"- \"M\",",
"- \"N\",",
"- \"O\",",
"- \"P\",",
"- \"Q\",",
"- \"R\",",
"- \"S\",",
"- \"T\",",
"- \"U\",",
"- \"V\",",
"- \"W\",",
"- \"X\",",
"- \"Y\",",
"- \"Z\",",
"-]",
"-t = \"\"",
"-for ch in s:",
"- ind = uppercase.index(ch)",
"- ind = (ind + n) % 26",
"- t += uppercase[ind]",
"-print(t)",
"+x = input()",
"+a = ord(\"A\")",
"+print(\"\".join([s[(ord(c) - a + n) % 26] for c in x]))"
] | false | 0.044503 | 0.045491 | 0.978292 | [
"s095214353",
"s992427408"
] |
u327466606 | p03297 | python | s094373375 | s574262906 | 68 | 30 | 66,188 | 9,060 | Accepted | Accepted | 55.88 | from math import gcd
def solve(a,b,c,d):
if a < b:
return False
if d < b:
return False
g = gcd(b,d)
c += 1
m = c + (a-c)%g
return b <= m
T = int(eval(input()))
for _ in range(T):
print(('Yes' if solve(*list(map(int,input().split()))) else 'No')) | import math
for _ in range(int(eval(input()))):
a,b,c,d = list(map(int,input().split()))
print(('Yes' if b <= min(a, d, c+1+(a-c-1)%math.gcd(b,d)) else 'No')) | 17 | 4 | 297 | 155 | from math import gcd
def solve(a, b, c, d):
if a < b:
return False
if d < b:
return False
g = gcd(b, d)
c += 1
m = c + (a - c) % g
return b <= m
T = int(eval(input()))
for _ in range(T):
print(("Yes" if solve(*list(map(int, input().split()))) else "No"))
| import math
for _ in range(int(eval(input()))):
a, b, c, d = list(map(int, input().split()))
print(("Yes" if b <= min(a, d, c + 1 + (a - c - 1) % math.gcd(b, d)) else "No"))
| false | 76.470588 | [
"-from math import gcd",
"+import math",
"-",
"-def solve(a, b, c, d):",
"- if a < b:",
"- return False",
"- if d < b:",
"- return False",
"- g = gcd(b, d)",
"- c += 1",
"- m = c + (a - c) % g",
"- return b <= m",
"-",
"-",
"-T = int(eval(input()))",
"-for _ in range(T):",
"- print((\"Yes\" if solve(*list(map(int, input().split()))) else \"No\"))",
"+for _ in range(int(eval(input()))):",
"+ a, b, c, d = list(map(int, input().split()))",
"+ print((\"Yes\" if b <= min(a, d, c + 1 + (a - c - 1) % math.gcd(b, d)) else \"No\"))"
] | false | 0.075952 | 0.073323 | 1.035847 | [
"s094373375",
"s574262906"
] |
u089376182 | p03146 | python | s279033138 | s286037061 | 21 | 17 | 3,316 | 3,060 | Accepted | Accepted | 19.05 | s = int(eval(input()))
exist_set = set()
index = 1
while s not in exist_set:
exist_set.add(s)
s = s//2 if s%2==0 else 3*s+1
index += 1
print(index) | s = int(eval(input()))
def f(x):
if x%2==0:
return x//2
else:
return 3*x+1
a = set()
a.add(s)
index = 1
while True:
index += 1
s = f(s)
if s not in a:
a.add(s)
else:
break
print(index) | 11 | 21 | 160 | 236 | s = int(eval(input()))
exist_set = set()
index = 1
while s not in exist_set:
exist_set.add(s)
s = s // 2 if s % 2 == 0 else 3 * s + 1
index += 1
print(index)
| s = int(eval(input()))
def f(x):
if x % 2 == 0:
return x // 2
else:
return 3 * x + 1
a = set()
a.add(s)
index = 1
while True:
index += 1
s = f(s)
if s not in a:
a.add(s)
else:
break
print(index)
| false | 47.619048 | [
"-exist_set = set()",
"+",
"+",
"+def f(x):",
"+ if x % 2 == 0:",
"+ return x // 2",
"+ else:",
"+ return 3 * x + 1",
"+",
"+",
"+a = set()",
"+a.add(s)",
"-while s not in exist_set:",
"- exist_set.add(s)",
"- s = s // 2 if s % 2 == 0 else 3 * s + 1",
"+while True:",
"+ s = f(s)",
"+ if s not in a:",
"+ a.add(s)",
"+ else:",
"+ break"
] | false | 0.042244 | 0.036047 | 1.1719 | [
"s279033138",
"s286037061"
] |
u761529120 | p03078 | python | s890369085 | s053423348 | 957 | 757 | 148,364 | 147,884 | Accepted | Accepted | 20.9 | def main():
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()))
D = []
for a in A:
for b in B:
D.append(a + b)
D.sort(reverse=True)
E = []
for i in range(min(len(D),K)):
for c in C:
E.append(D[i] + c)
E.sort(reverse=True)
for i in range(K):
print((E[i]))
main() | def main():
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()))
AB = []
for a in A:
for b in B:
AB.append(a + b)
AB.sort(reverse=True)
C.sort(reverse=True)
ans = []
for i in range(min(K,X*Y)):
for j in range(min(K,Z)):
ans.append(AB[i] + C[j])
ans.sort(reverse=True)
for k in range(K):
print((ans[k]))
if __name__ == "__main__":
main() | 24 | 25 | 483 | 557 | def main():
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()))
D = []
for a in A:
for b in B:
D.append(a + b)
D.sort(reverse=True)
E = []
for i in range(min(len(D), K)):
for c in C:
E.append(D[i] + c)
E.sort(reverse=True)
for i in range(K):
print((E[i]))
main()
| def main():
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()))
AB = []
for a in A:
for b in B:
AB.append(a + b)
AB.sort(reverse=True)
C.sort(reverse=True)
ans = []
for i in range(min(K, X * Y)):
for j in range(min(K, Z)):
ans.append(AB[i] + C[j])
ans.sort(reverse=True)
for k in range(K):
print((ans[k]))
if __name__ == "__main__":
main()
| false | 4 | [
"- D = []",
"+ AB = []",
"- D.append(a + b)",
"- D.sort(reverse=True)",
"- E = []",
"- for i in range(min(len(D), K)):",
"- for c in C:",
"- E.append(D[i] + c)",
"- E.sort(reverse=True)",
"- for i in range(K):",
"- print((E[i]))",
"+ AB.append(a + b)",
"+ AB.sort(reverse=True)",
"+ C.sort(reverse=True)",
"+ ans = []",
"+ for i in range(min(K, X * Y)):",
"+ for j in range(min(K, Z)):",
"+ ans.append(AB[i] + C[j])",
"+ ans.sort(reverse=True)",
"+ for k in range(K):",
"+ print((ans[k]))",
"-main()",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.047494 | 0.036652 | 1.295795 | [
"s890369085",
"s053423348"
] |
u606045429 | p02936 | python | s063120060 | s260746890 | 1,435 | 842 | 251,188 | 94,828 | Accepted | Accepted | 41.32 | import sys
sys.setrecursionlimit(2 * 10 ** 5 + 10)
N, Q, *ABPX = list(map(int, open(0).read().split()))
AB, PX = ABPX[:2 * (N - 1)], ABPX[2 * (N - 1):]
E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
E[a].append(b)
E[b].append(a)
ans = [0] * (N + 1)
for p, x in zip(*[iter(PX)] * 2):
ans[p] += x
def dfs(v, p):
for c in E[v]:
if c == p:
continue
ans[c] += ans[v]
dfs(c, v)
dfs(1, 0)
print((*ans[1:])) | N, Q, *ABPX = list(map(int, open(0).read().split()))
AB, PX = ABPX[:2 * (N - 1)], ABPX[2 * (N - 1):]
E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
E[a].append(b)
E[b].append(a)
ans = [0] * (N + 1)
for p, x in zip(*[iter(PX)] * 2):
ans[p] += x
stack = [(1, 0)]
while stack:
v, p = stack.pop()
for c in E[v]:
if c == p:
continue
ans[c] += ans[v]
stack.append((c, v))
print((*ans[1:])) | 25 | 23 | 491 | 476 | import sys
sys.setrecursionlimit(2 * 10**5 + 10)
N, Q, *ABPX = list(map(int, open(0).read().split()))
AB, PX = ABPX[: 2 * (N - 1)], ABPX[2 * (N - 1) :]
E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
E[a].append(b)
E[b].append(a)
ans = [0] * (N + 1)
for p, x in zip(*[iter(PX)] * 2):
ans[p] += x
def dfs(v, p):
for c in E[v]:
if c == p:
continue
ans[c] += ans[v]
dfs(c, v)
dfs(1, 0)
print((*ans[1:]))
| N, Q, *ABPX = list(map(int, open(0).read().split()))
AB, PX = ABPX[: 2 * (N - 1)], ABPX[2 * (N - 1) :]
E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
E[a].append(b)
E[b].append(a)
ans = [0] * (N + 1)
for p, x in zip(*[iter(PX)] * 2):
ans[p] += x
stack = [(1, 0)]
while stack:
v, p = stack.pop()
for c in E[v]:
if c == p:
continue
ans[c] += ans[v]
stack.append((c, v))
print((*ans[1:]))
| false | 8 | [
"-import sys",
"-",
"-sys.setrecursionlimit(2 * 10**5 + 10)",
"-",
"-",
"-def dfs(v, p):",
"+stack = [(1, 0)]",
"+while stack:",
"+ v, p = stack.pop()",
"- dfs(c, v)",
"-",
"-",
"-dfs(1, 0)",
"+ stack.append((c, v))"
] | false | 0.116385 | 0.045494 | 2.558245 | [
"s063120060",
"s260746890"
] |
u342869120 | p02616 | python | s418555843 | s679771455 | 386 | 311 | 116,740 | 116,508 | Accepted | Accepted | 19.43 | MOD = 10**9+7
N, K = list(map(int, input().split()))
*A, = list(map(int, input().split()))
allm = True
for a in A:
if a > 0:
allm = False
break
if N == K:
ans = 1
for a in A:
ans = (ans*a) % MOD
print(ans)
elif allm and K % 2 == 1:
A.sort()
A.reverse()
ans = 1
for a in A[:K]:
ans = (ans*a) % MOD
print(ans)
else:
p, m = [], []
for a in A:
if a > 0:
p.append(a)
if a < 0:
m.append(-a)
p.sort(key=lambda k: -k)
m.sort(key=lambda k: -k)
pi, mi = 0, 0
ans = 1
while K > 0:
if K == 1:
ans = (ans*p[pi]) % MOD
break
elif pi < len(p)-1 or mi < len(m)-1:
pv, mv = 0, 0
if pi < len(p)-1:
pv = p[pi]*p[pi+1]
if mi < len(m)-1:
mv = m[mi]*m[mi+1]
if pv > mv:
ans = (ans*pv) % MOD
pi += 2
else:
ans = (ans*mv) % MOD
mi += 2
K -= 2
else:
ans = 0
break
print(ans)
| MOD = 10**9+7
N, K = list(map(int, input().split()))
*A, = list(map(int, input().split()))
allm = True
for a in A:
if a > 0:
allm = False
break
if N == K:
ans = 1
for a in A:
ans = (ans*a) % MOD
print(ans)
elif allm and K % 2 == 1:
A.sort()
A.reverse()
ans = 1
for a in A[:K]:
ans = (ans*a) % MOD
print(ans)
else:
p, m = [], []
for a in A:
if a > 0:
p.append(a)
if a < 0:
m.append(-a)
p.sort(key=lambda k: -k)
m.sort(key=lambda k: -k)
pi, mi = 0, 0
ans = 1
while K > 0:
if K == 1:
ans = (ans*p[pi]) % MOD
break
elif pi < len(p)-1 or mi < len(m)-1:
pv, mv = 0, 0
if pi < len(p)-1:
pv = p[pi]*p[pi+1]
if mi < len(m)-1:
mv = m[mi]*m[mi+1]
if pv > mv:
ans = (ans*p[pi]) % MOD
pi += 1
K -= 1
else:
ans = (ans*mv) % MOD
mi += 2
K -= 2
else:
ans = 0
break
print(ans)
| 56 | 57 | 1,177 | 1,208 | MOD = 10**9 + 7
N, K = list(map(int, input().split()))
(*A,) = list(map(int, input().split()))
allm = True
for a in A:
if a > 0:
allm = False
break
if N == K:
ans = 1
for a in A:
ans = (ans * a) % MOD
print(ans)
elif allm and K % 2 == 1:
A.sort()
A.reverse()
ans = 1
for a in A[:K]:
ans = (ans * a) % MOD
print(ans)
else:
p, m = [], []
for a in A:
if a > 0:
p.append(a)
if a < 0:
m.append(-a)
p.sort(key=lambda k: -k)
m.sort(key=lambda k: -k)
pi, mi = 0, 0
ans = 1
while K > 0:
if K == 1:
ans = (ans * p[pi]) % MOD
break
elif pi < len(p) - 1 or mi < len(m) - 1:
pv, mv = 0, 0
if pi < len(p) - 1:
pv = p[pi] * p[pi + 1]
if mi < len(m) - 1:
mv = m[mi] * m[mi + 1]
if pv > mv:
ans = (ans * pv) % MOD
pi += 2
else:
ans = (ans * mv) % MOD
mi += 2
K -= 2
else:
ans = 0
break
print(ans)
| MOD = 10**9 + 7
N, K = list(map(int, input().split()))
(*A,) = list(map(int, input().split()))
allm = True
for a in A:
if a > 0:
allm = False
break
if N == K:
ans = 1
for a in A:
ans = (ans * a) % MOD
print(ans)
elif allm and K % 2 == 1:
A.sort()
A.reverse()
ans = 1
for a in A[:K]:
ans = (ans * a) % MOD
print(ans)
else:
p, m = [], []
for a in A:
if a > 0:
p.append(a)
if a < 0:
m.append(-a)
p.sort(key=lambda k: -k)
m.sort(key=lambda k: -k)
pi, mi = 0, 0
ans = 1
while K > 0:
if K == 1:
ans = (ans * p[pi]) % MOD
break
elif pi < len(p) - 1 or mi < len(m) - 1:
pv, mv = 0, 0
if pi < len(p) - 1:
pv = p[pi] * p[pi + 1]
if mi < len(m) - 1:
mv = m[mi] * m[mi + 1]
if pv > mv:
ans = (ans * p[pi]) % MOD
pi += 1
K -= 1
else:
ans = (ans * mv) % MOD
mi += 2
K -= 2
else:
ans = 0
break
print(ans)
| false | 1.754386 | [
"- ans = (ans * pv) % MOD",
"- pi += 2",
"+ ans = (ans * p[pi]) % MOD",
"+ pi += 1",
"+ K -= 1",
"- K -= 2",
"+ K -= 2"
] | false | 0.03736 | 0.081459 | 0.45864 | [
"s418555843",
"s679771455"
] |
u434872492 | p02554 | python | s316977150 | s158196669 | 73 | 62 | 63,424 | 61,848 | Accepted | Accepted | 15.07 | N = int(eval(input()))
MOD = 10**9 + 7
n9 = 1
n8 = 1
n10 = 1
for i in range(N):
n9 = (n9*9)%MOD
n8 = (n8*8)%MOD
n10 = (n10*10)%MOD
ans = n10 - 2*n9 + n8
print((ans%MOD)) | N = int(eval(input()))
MOD = 10**9 + 7
val1 = pow(9,N,MOD)
val2 = pow(8,N,MOD)
ans = pow(10,N,MOD) - 2*val1 + val2
print((ans%MOD)) | 14 | 7 | 189 | 130 | N = int(eval(input()))
MOD = 10**9 + 7
n9 = 1
n8 = 1
n10 = 1
for i in range(N):
n9 = (n9 * 9) % MOD
n8 = (n8 * 8) % MOD
n10 = (n10 * 10) % MOD
ans = n10 - 2 * n9 + n8
print((ans % MOD))
| N = int(eval(input()))
MOD = 10**9 + 7
val1 = pow(9, N, MOD)
val2 = pow(8, N, MOD)
ans = pow(10, N, MOD) - 2 * val1 + val2
print((ans % MOD))
| false | 50 | [
"-n9 = 1",
"-n8 = 1",
"-n10 = 1",
"-for i in range(N):",
"- n9 = (n9 * 9) % MOD",
"- n8 = (n8 * 8) % MOD",
"- n10 = (n10 * 10) % MOD",
"-ans = n10 - 2 * n9 + n8",
"+val1 = pow(9, N, MOD)",
"+val2 = pow(8, N, MOD)",
"+ans = pow(10, N, MOD) - 2 * val1 + val2"
] | false | 0.193068 | 0.145556 | 1.326419 | [
"s316977150",
"s158196669"
] |
u989345508 | p02697 | python | s888548416 | s846289921 | 95 | 81 | 69,676 | 9,540 | Accepted | Accepted | 14.74 | n,m=list(map(int,input().split()))
for i in range(m):print((i+1,n-i-((i>=m/2)&~n))) | n,m=map(int,input().split());[print(i+1,n-i-((i>=m/2)&~n)) for i in range(m)]
| 2 | 1 | 76 | 77 | n, m = list(map(int, input().split()))
for i in range(m):
print((i + 1, n - i - ((i >= m / 2) & ~n)))
| n, m = map(int, input().split())
[print(i + 1, n - i - ((i >= m / 2) & ~n)) for i in range(m)]
| false | 50 | [
"-n, m = list(map(int, input().split()))",
"-for i in range(m):",
"- print((i + 1, n - i - ((i >= m / 2) & ~n)))",
"+n, m = map(int, input().split())",
"+[print(i + 1, n - i - ((i >= m / 2) & ~n)) for i in range(m)]"
] | false | 0.050728 | 0.171672 | 0.295491 | [
"s888548416",
"s846289921"
] |
u969190727 | p03283 | python | s999498019 | s518078862 | 792 | 712 | 15,784 | 9,740 | Accepted | Accepted | 10.1 | import sys
input = sys.stdin.readline
n,m,Q=list(map(int,input().split()))
L=[[0 for i in range(n)] for i in range(n)]
LL=[[0 for i in range(n)] for i in range(n)]
for i in range(m):
l,r=list(map(int,input().split()))
L[l-1][r-1]+=1
LL[0][0]=L[0][0]
for i in range(1,n):
LL[i][0]=LL[i-1][0]+L[i][0]
LL[0][i]=LL[0][i-1]+L[0][i]
for i in range(1,n):
for j in range(1,n):
LL[i][j]=LL[i-1][j]+LL[i][j-1]+L[i][j]-LL[i-1][j-1]
for i in range(Q):
p,q=list(map(int,input().split()))
if p==1:
ans=LL[q-1][q-1]
elif q==1:
ans=LL[0][0]
else:
ans=LL[q-1][q-1]-LL[q-1][p-2]-LL[p-2][q-1]+LL[p-2][p-2]
print(ans) | import sys
input=lambda: sys.stdin.readline().rstrip()
n,m,q=list(map(int,input().split()))
T=[[0]*(n+2) for _ in range(n+2)]
for _ in range(m):
l,r=list(map(int,input().split()))
T[l][r]+=1
for i in range(1,n+1)[::-1]:
for j in range(1,n+1):
T[i][j+1]+=T[i][j]
for j in range(1,n+1):
for i in range(1,n+1)[::-1]:
T[i-1][j]+=T[i][j]
for _ in range(q):
p,q=list(map(int,input().split()))
print((T[p][q])) | 24 | 17 | 639 | 421 | import sys
input = sys.stdin.readline
n, m, Q = list(map(int, input().split()))
L = [[0 for i in range(n)] for i in range(n)]
LL = [[0 for i in range(n)] for i in range(n)]
for i in range(m):
l, r = list(map(int, input().split()))
L[l - 1][r - 1] += 1
LL[0][0] = L[0][0]
for i in range(1, n):
LL[i][0] = LL[i - 1][0] + L[i][0]
LL[0][i] = LL[0][i - 1] + L[0][i]
for i in range(1, n):
for j in range(1, n):
LL[i][j] = LL[i - 1][j] + LL[i][j - 1] + L[i][j] - LL[i - 1][j - 1]
for i in range(Q):
p, q = list(map(int, input().split()))
if p == 1:
ans = LL[q - 1][q - 1]
elif q == 1:
ans = LL[0][0]
else:
ans = LL[q - 1][q - 1] - LL[q - 1][p - 2] - LL[p - 2][q - 1] + LL[p - 2][p - 2]
print(ans)
| import sys
input = lambda: sys.stdin.readline().rstrip()
n, m, q = list(map(int, input().split()))
T = [[0] * (n + 2) for _ in range(n + 2)]
for _ in range(m):
l, r = list(map(int, input().split()))
T[l][r] += 1
for i in range(1, n + 1)[::-1]:
for j in range(1, n + 1):
T[i][j + 1] += T[i][j]
for j in range(1, n + 1):
for i in range(1, n + 1)[::-1]:
T[i - 1][j] += T[i][j]
for _ in range(q):
p, q = list(map(int, input().split()))
print((T[p][q]))
| false | 29.166667 | [
"-input = sys.stdin.readline",
"-n, m, Q = list(map(int, input().split()))",
"-L = [[0 for i in range(n)] for i in range(n)]",
"-LL = [[0 for i in range(n)] for i in range(n)]",
"-for i in range(m):",
"+input = lambda: sys.stdin.readline().rstrip()",
"+n, m, q = list(map(int, input().split()))",
"+T = [[0] * (n + 2) for _ in range(n + 2)]",
"+for _ in range(m):",
"- L[l - 1][r - 1] += 1",
"-LL[0][0] = L[0][0]",
"-for i in range(1, n):",
"- LL[i][0] = LL[i - 1][0] + L[i][0]",
"- LL[0][i] = LL[0][i - 1] + L[0][i]",
"-for i in range(1, n):",
"- for j in range(1, n):",
"- LL[i][j] = LL[i - 1][j] + LL[i][j - 1] + L[i][j] - LL[i - 1][j - 1]",
"-for i in range(Q):",
"+ T[l][r] += 1",
"+for i in range(1, n + 1)[::-1]:",
"+ for j in range(1, n + 1):",
"+ T[i][j + 1] += T[i][j]",
"+for j in range(1, n + 1):",
"+ for i in range(1, n + 1)[::-1]:",
"+ T[i - 1][j] += T[i][j]",
"+for _ in range(q):",
"- if p == 1:",
"- ans = LL[q - 1][q - 1]",
"- elif q == 1:",
"- ans = LL[0][0]",
"- else:",
"- ans = LL[q - 1][q - 1] - LL[q - 1][p - 2] - LL[p - 2][q - 1] + LL[p - 2][p - 2]",
"- print(ans)",
"+ print((T[p][q]))"
] | false | 0.074832 | 0.042303 | 1.768946 | [
"s999498019",
"s518078862"
] |
u605880635 | p02630 | python | s510647233 | s187218322 | 372 | 256 | 26,936 | 15,240 | Accepted | Accepted | 31.18 | # 371 ms, 27032 KB
n = int(eval(input()))
a = list(map(int, input().split()))
q = int(eval(input()))
b = []
c = []
for _ in range(q):
bi, ci = list(map(int, input().split()))
b.append(bi)
c.append(ci)
#bc = [map(int, input().split()) for _ in range(q)]
#b, c = [list(i) for i in zip(*bc)]
dic = {}
for aa in a:
dic[aa] = dic.get(aa, 0) + 1
s = sum(a)
for i in range(q):
if b[i] not in dic:
print((str(s)))
continue
s += (c[i]-b[i]) * dic[b[i]]
dic[c[i]] = dic.get(c[i], 0) + dic[b[i]]
del dic[b[i]]
print(s) | import sys
readline = sys.stdin.readline
def st(line):
tmp = ''
for l in line:
if l == '\n':
yield tmp
elif l == ' ':
yield tmp
tmp = ''
else:
tmp += l
def solve():
N = int(eval(input()))
As = st(readline())
d = dict()
total = 0
for a in As:
a = int(a)
if a in d:
d[a] += 1
else:
d[a] = 1
total += a
Q = int(eval(input()))
queries = (list(map(int, readline().strip().split())) for _ in range(Q))
for que in queries:
b, c = que
if b not in d:
print(total)
continue
n_b = d[b]
d[b] = 0
if c not in d:
d[c] = 0
d[c] += n_b
total += (c - b) * n_b
print(total)
def main():
solve()
if __name__ == "__main__":
main() | 27 | 59 | 578 | 959 | # 371 ms, 27032 KB
n = int(eval(input()))
a = list(map(int, input().split()))
q = int(eval(input()))
b = []
c = []
for _ in range(q):
bi, ci = list(map(int, input().split()))
b.append(bi)
c.append(ci)
# bc = [map(int, input().split()) for _ in range(q)]
# b, c = [list(i) for i in zip(*bc)]
dic = {}
for aa in a:
dic[aa] = dic.get(aa, 0) + 1
s = sum(a)
for i in range(q):
if b[i] not in dic:
print((str(s)))
continue
s += (c[i] - b[i]) * dic[b[i]]
dic[c[i]] = dic.get(c[i], 0) + dic[b[i]]
del dic[b[i]]
print(s)
| import sys
readline = sys.stdin.readline
def st(line):
tmp = ""
for l in line:
if l == "\n":
yield tmp
elif l == " ":
yield tmp
tmp = ""
else:
tmp += l
def solve():
N = int(eval(input()))
As = st(readline())
d = dict()
total = 0
for a in As:
a = int(a)
if a in d:
d[a] += 1
else:
d[a] = 1
total += a
Q = int(eval(input()))
queries = (list(map(int, readline().strip().split())) for _ in range(Q))
for que in queries:
b, c = que
if b not in d:
print(total)
continue
n_b = d[b]
d[b] = 0
if c not in d:
d[c] = 0
d[c] += n_b
total += (c - b) * n_b
print(total)
def main():
solve()
if __name__ == "__main__":
main()
| false | 54.237288 | [
"-# 371 ms, 27032 KB",
"-n = int(eval(input()))",
"-a = list(map(int, input().split()))",
"-q = int(eval(input()))",
"-b = []",
"-c = []",
"-for _ in range(q):",
"- bi, ci = list(map(int, input().split()))",
"- b.append(bi)",
"- c.append(ci)",
"-# bc = [map(int, input().split()) for _ in range(q)]",
"-# b, c = [list(i) for i in zip(*bc)]",
"-dic = {}",
"-for aa in a:",
"- dic[aa] = dic.get(aa, 0) + 1",
"-s = sum(a)",
"-for i in range(q):",
"- if b[i] not in dic:",
"- print((str(s)))",
"- continue",
"- s += (c[i] - b[i]) * dic[b[i]]",
"- dic[c[i]] = dic.get(c[i], 0) + dic[b[i]]",
"- del dic[b[i]]",
"- print(s)",
"+import sys",
"+",
"+readline = sys.stdin.readline",
"+",
"+",
"+def st(line):",
"+ tmp = \"\"",
"+ for l in line:",
"+ if l == \"\\n\":",
"+ yield tmp",
"+ elif l == \" \":",
"+ yield tmp",
"+ tmp = \"\"",
"+ else:",
"+ tmp += l",
"+",
"+",
"+def solve():",
"+ N = int(eval(input()))",
"+ As = st(readline())",
"+ d = dict()",
"+ total = 0",
"+ for a in As:",
"+ a = int(a)",
"+ if a in d:",
"+ d[a] += 1",
"+ else:",
"+ d[a] = 1",
"+ total += a",
"+ Q = int(eval(input()))",
"+ queries = (list(map(int, readline().strip().split())) for _ in range(Q))",
"+ for que in queries:",
"+ b, c = que",
"+ if b not in d:",
"+ print(total)",
"+ continue",
"+ n_b = d[b]",
"+ d[b] = 0",
"+ if c not in d:",
"+ d[c] = 0",
"+ d[c] += n_b",
"+ total += (c - b) * n_b",
"+ print(total)",
"+",
"+",
"+def main():",
"+ solve()",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.183497 | 0.046585 | 3.938974 | [
"s510647233",
"s187218322"
] |
u525065967 | p02684 | python | s348308059 | s230559177 | 223 | 181 | 32,448 | 32,376 | Accepted | Accepted | 18.83 | N,K = list(map(int, input().split()))
A = [*[int(x)-1 for x in input().split()]]
index = [-1]*N
path = []
pre = 0
while index[pre] < 0:
index[pre] = len(path)
path += [pre]
pre = A[pre]
one = index[pre]
loops = len(path) - one
k = max(0, K-one) % loops + min(K, one)
pre = 0
for _ in range(k): pre = A[pre]
print((pre + 1))
# if K <= one: print(path[K])
# else: print(path[(K-one) % loops + one]+1)
| N,K = list(map(int, input().split()))
A = [*[int(x)-1 for x in input().split()]]
index = [-1]*N
path = []
pre = 0
while index[pre] < 0:
index[pre] = len(path)
path += [pre]
pre = A[pre]
one = index[pre]
loops = len(path) - one
if K < one: print((path[K]+1))
else: print((path[(K-one) % loops + one]+1))
| 19 | 13 | 427 | 321 | N, K = list(map(int, input().split()))
A = [*[int(x) - 1 for x in input().split()]]
index = [-1] * N
path = []
pre = 0
while index[pre] < 0:
index[pre] = len(path)
path += [pre]
pre = A[pre]
one = index[pre]
loops = len(path) - one
k = max(0, K - one) % loops + min(K, one)
pre = 0
for _ in range(k):
pre = A[pre]
print((pre + 1))
# if K <= one: print(path[K])
# else: print(path[(K-one) % loops + one]+1)
| N, K = list(map(int, input().split()))
A = [*[int(x) - 1 for x in input().split()]]
index = [-1] * N
path = []
pre = 0
while index[pre] < 0:
index[pre] = len(path)
path += [pre]
pre = A[pre]
one = index[pre]
loops = len(path) - one
if K < one:
print((path[K] + 1))
else:
print((path[(K - one) % loops + one] + 1))
| false | 31.578947 | [
"-k = max(0, K - one) % loops + min(K, one)",
"-pre = 0",
"-for _ in range(k):",
"- pre = A[pre]",
"-print((pre + 1))",
"-# if K <= one: print(path[K])",
"-# else: print(path[(K-one) % loops + one]+1)",
"+if K < one:",
"+ print((path[K] + 1))",
"+else:",
"+ print((path[(K - one) % loops + one] + 1))"
] | false | 0.035548 | 0.036692 | 0.968831 | [
"s348308059",
"s230559177"
] |
u268554510 | p02691 | python | s931208120 | s768097793 | 242 | 188 | 32,192 | 32,376 | Accepted | Accepted | 22.31 | N = int(eval(input()))
A = list(map(int,input().split()))
ans = 0
dic = {}
for i in range(1,N):
x = i-A[i]
if x<0:
continue
else:
if x in dic:
dic[x]+=1
else:
dic[x]=1
if A[0] in dic:
ans+=dic[A[0]]
for i in range(1,N):
x = i+A[i]
if i-A[i] in dic:
dic[i-A[i]]-=1
if x in dic:
ans+=dic[x]
print(ans) | N = int(eval(input()))
A = list(map(int,input().split()))
ans = 0
l = [0]*(3*10**5+10)
for i in range(1,N):
x = i-A[i]
if x<0:
continue
else:
l[x]+=1
if A[0]<=2*10**5:
ans+=l[A[0]]
for i in range(1,N):
x = i+A[i]
if x<0:
continue
if x>2*10**5:
continue
if i-A[i]>=0:
l[i-A[i]]-=1
ans+=l[x]
print(ans)
| 25 | 24 | 374 | 362 | N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
dic = {}
for i in range(1, N):
x = i - A[i]
if x < 0:
continue
else:
if x in dic:
dic[x] += 1
else:
dic[x] = 1
if A[0] in dic:
ans += dic[A[0]]
for i in range(1, N):
x = i + A[i]
if i - A[i] in dic:
dic[i - A[i]] -= 1
if x in dic:
ans += dic[x]
print(ans)
| N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
l = [0] * (3 * 10**5 + 10)
for i in range(1, N):
x = i - A[i]
if x < 0:
continue
else:
l[x] += 1
if A[0] <= 2 * 10**5:
ans += l[A[0]]
for i in range(1, N):
x = i + A[i]
if x < 0:
continue
if x > 2 * 10**5:
continue
if i - A[i] >= 0:
l[i - A[i]] -= 1
ans += l[x]
print(ans)
| false | 4 | [
"-dic = {}",
"+l = [0] * (3 * 10**5 + 10)",
"- if x in dic:",
"- dic[x] += 1",
"- else:",
"- dic[x] = 1",
"-if A[0] in dic:",
"- ans += dic[A[0]]",
"+ l[x] += 1",
"+if A[0] <= 2 * 10**5:",
"+ ans += l[A[0]]",
"- if i - A[i] in dic:",
"- dic[i - A[i]] -= 1",
"- if x in dic:",
"- ans += dic[x]",
"+ if x < 0:",
"+ continue",
"+ if x > 2 * 10**5:",
"+ continue",
"+ if i - A[i] >= 0:",
"+ l[i - A[i]] -= 1",
"+ ans += l[x]"
] | false | 0.080514 | 0.040811 | 1.972867 | [
"s931208120",
"s768097793"
] |
u800058906 | p02689 | python | s905362311 | s449653726 | 277 | 252 | 20,064 | 19,920 | Accepted | Accepted | 9.03 | n,m=list(map(int,input().split()))
h=list(map(int,input().split()))
r=[]
t=['W']*n
for i in range(m):
a,b=list(map(int,input().split()))
if h[a-1]>=h[b-1]:
t[b-1]='L'
if h[a-1]<=h[b-1]:
t[a-1]='L'
print((t.count('W'))) | n,m=list(map(int,input().split()))
h=list(map(int,input().split()))
t=['W']*n
for i in range(m):
a,b=list(map(int,input().split()))
if h[a-1]>=h[b-1]:
t[b-1]='L'
if h[a-1]<=h[b-1]:
t[a-1]='L'
print((t.count('W'))) | 13 | 12 | 252 | 240 | n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
r = []
t = ["W"] * n
for i in range(m):
a, b = list(map(int, input().split()))
if h[a - 1] >= h[b - 1]:
t[b - 1] = "L"
if h[a - 1] <= h[b - 1]:
t[a - 1] = "L"
print((t.count("W")))
| n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
t = ["W"] * n
for i in range(m):
a, b = list(map(int, input().split()))
if h[a - 1] >= h[b - 1]:
t[b - 1] = "L"
if h[a - 1] <= h[b - 1]:
t[a - 1] = "L"
print((t.count("W")))
| false | 7.692308 | [
"-r = []"
] | false | 0.098709 | 0.054424 | 1.813691 | [
"s905362311",
"s449653726"
] |
u260980560 | p00226 | python | s232285789 | s115005214 | 170 | 70 | 4,216 | 4,204 | Accepted | Accepted | 58.82 | while 1:
r,a=input().split()
if r=='0' and a=='0': break
h = b = 0
for i in range(4):
if r[i]==a[i]: h+=1
for i in range(10):
b += min(r.count(chr(ord('0')+i)),a.count(chr(ord('0')+i)))
print(h,b-h) | while 1:
r,a=input().split()
if r=='0' and a=='0': break
h = b = 0
for i in range(4):
if r[i]==a[i]: h+=1
for s in r:
for t in a:
if s==t:
b+=1; break;
print(h,b-h) | 9 | 11 | 251 | 246 | while 1:
r, a = input().split()
if r == "0" and a == "0":
break
h = b = 0
for i in range(4):
if r[i] == a[i]:
h += 1
for i in range(10):
b += min(r.count(chr(ord("0") + i)), a.count(chr(ord("0") + i)))
print(h, b - h)
| while 1:
r, a = input().split()
if r == "0" and a == "0":
break
h = b = 0
for i in range(4):
if r[i] == a[i]:
h += 1
for s in r:
for t in a:
if s == t:
b += 1
break
print(h, b - h)
| false | 18.181818 | [
"- for i in range(10):",
"- b += min(r.count(chr(ord(\"0\") + i)), a.count(chr(ord(\"0\") + i)))",
"+ for s in r:",
"+ for t in a:",
"+ if s == t:",
"+ b += 1",
"+ break"
] | false | 0.043606 | 0.081925 | 0.53227 | [
"s232285789",
"s115005214"
] |
u263830634 | p03765 | python | s038580913 | s561835583 | 1,134 | 422 | 64,276 | 13,388 | Accepted | Accepted | 62.79 | S = list(eval(input()))
T = list(eval(input()))
# 前計算
S_n = [0] * (len(S) + 1)
# S_n[0] = 1 if S[0] == 'A' else 2
for i in range(1, len(S) + 1):
if S[i - 1] == 'A':
S_n[i] = S_n[i - 1] + 1
else:
S_n[i] = S_n[i - 1] + 2
T_n = [0] * (len(T) + 1)
# T_n[0] = 1 if T[0] == 'A' else 2
for i in range(1, len(T) + 1):
if T[i - 1] == 'A':
T_n[i] = T_n[i - 1] + 1
else:
T_n[i] = T_n[i - 1] + 2
q = int(eval(input()))
for _ in range(q):
a, b, c, d = list(map(int, input().split()))
#output
S_A = S_n[b] - S_n[a - 1]
T_A = T_n[d] - T_n[c - 1]
delta = abs(S_A - T_A)
if delta % 3 == 0:
print ('YES')
else:
print ('NO')
| S = list(eval(input()))
T = list(eval(input()))
import sys
input = sys.stdin.readline
# 前計算
S_n = [0] * (len(S) + 1)
# S_n[0] = 1 if S[0] == 'A' else 2
for i in range(1, len(S) + 1):
if S[i - 1] == 'A':
S_n[i] = S_n[i - 1] + 1
else:
S_n[i] = S_n[i - 1] + 2
T_n = [0] * (len(T) + 1)
# T_n[0] = 1 if T[0] == 'A' else 2
for i in range(1, len(T) + 1):
if T[i - 1] == 'A':
T_n[i] = T_n[i - 1] + 1
else:
T_n[i] = T_n[i - 1] + 2
q = int(eval(input()))
for _ in range(q):
a, b, c, d = list(map(int, input().split()))
#output
S_A = S_n[b] - S_n[a - 1]
T_A = T_n[d] - T_n[c - 1]
delta = abs(S_A - T_A)
if delta % 3 == 0:
print ('YES')
else:
print ('NO') | 33 | 33 | 715 | 747 | S = list(eval(input()))
T = list(eval(input()))
# 前計算
S_n = [0] * (len(S) + 1)
# S_n[0] = 1 if S[0] == 'A' else 2
for i in range(1, len(S) + 1):
if S[i - 1] == "A":
S_n[i] = S_n[i - 1] + 1
else:
S_n[i] = S_n[i - 1] + 2
T_n = [0] * (len(T) + 1)
# T_n[0] = 1 if T[0] == 'A' else 2
for i in range(1, len(T) + 1):
if T[i - 1] == "A":
T_n[i] = T_n[i - 1] + 1
else:
T_n[i] = T_n[i - 1] + 2
q = int(eval(input()))
for _ in range(q):
a, b, c, d = list(map(int, input().split()))
# output
S_A = S_n[b] - S_n[a - 1]
T_A = T_n[d] - T_n[c - 1]
delta = abs(S_A - T_A)
if delta % 3 == 0:
print("YES")
else:
print("NO")
| S = list(eval(input()))
T = list(eval(input()))
import sys
input = sys.stdin.readline
# 前計算
S_n = [0] * (len(S) + 1)
# S_n[0] = 1 if S[0] == 'A' else 2
for i in range(1, len(S) + 1):
if S[i - 1] == "A":
S_n[i] = S_n[i - 1] + 1
else:
S_n[i] = S_n[i - 1] + 2
T_n = [0] * (len(T) + 1)
# T_n[0] = 1 if T[0] == 'A' else 2
for i in range(1, len(T) + 1):
if T[i - 1] == "A":
T_n[i] = T_n[i - 1] + 1
else:
T_n[i] = T_n[i - 1] + 2
q = int(eval(input()))
for _ in range(q):
a, b, c, d = list(map(int, input().split()))
# output
S_A = S_n[b] - S_n[a - 1]
T_A = T_n[d] - T_n[c - 1]
delta = abs(S_A - T_A)
if delta % 3 == 0:
print("YES")
else:
print("NO")
| false | 0 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.036455 | 0.036737 | 0.992318 | [
"s038580913",
"s561835583"
] |
u014139588 | p03449 | python | s210190818 | s489125352 | 33 | 28 | 9,136 | 9,060 | Accepted | Accepted | 15.15 | n = int(eval(input()))
a = [list(map(int,input().split())),list(map(int,input().split()))]
ame = 0
ame_l = []
for i in range(n): #重複する列の選択
for j in range(n): #各列足してく
if i > j:
ame += a[0][j]
elif i == j:
ame += a[0][j]+a[1][j]
else:
ame += a[1][j]
if j == n-1:
ame_l.append(ame)
ame = 0
print((max(ame_l))) | n = int(eval(input()))
a = [list(map(int,input().split())) for _ in range(2)]
ame = []
for i in range(n):
ame.append(sum(a[0][:i+1])+sum(a[1][i:]))
print((max(ame))) | 16 | 6 | 361 | 164 | n = int(eval(input()))
a = [list(map(int, input().split())), list(map(int, input().split()))]
ame = 0
ame_l = []
for i in range(n): # 重複する列の選択
for j in range(n): # 各列足してく
if i > j:
ame += a[0][j]
elif i == j:
ame += a[0][j] + a[1][j]
else:
ame += a[1][j]
if j == n - 1:
ame_l.append(ame)
ame = 0
print((max(ame_l)))
| n = int(eval(input()))
a = [list(map(int, input().split())) for _ in range(2)]
ame = []
for i in range(n):
ame.append(sum(a[0][: i + 1]) + sum(a[1][i:]))
print((max(ame)))
| false | 62.5 | [
"-a = [list(map(int, input().split())), list(map(int, input().split()))]",
"-ame = 0",
"-ame_l = []",
"-for i in range(n): # 重複する列の選択",
"- for j in range(n): # 各列足してく",
"- if i > j:",
"- ame += a[0][j]",
"- elif i == j:",
"- ame += a[0][j] + a[1][j]",
"- else:",
"- ame += a[1][j]",
"- if j == n - 1:",
"- ame_l.append(ame)",
"- ame = 0",
"-print((max(ame_l)))",
"+a = [list(map(int, input().split())) for _ in range(2)]",
"+ame = []",
"+for i in range(n):",
"+ ame.append(sum(a[0][: i + 1]) + sum(a[1][i:]))",
"+print((max(ame)))"
] | false | 0.047867 | 0.043483 | 1.100824 | [
"s210190818",
"s489125352"
] |
u156815136 | p03048 | python | s357197563 | s093522971 | 346 | 127 | 41,068 | 77,688 | Accepted | Accepted | 63.29 | R,G,B,N = list(map(int,input().split()))
res = 0
for i in range(N//R + 1):
for j in range(N//G + 1):
if i*R + j*G > N: # はそもそもむり
continue
k = (N - R*i - G*j)
if k % B != 0: # その倍数じゃないと無理
continue
res += 1
print(res)
| #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(eval(input()))
R,G,B,N = readInts()
cnt = 0
for r in range(N//R+1):
for g in range(N//G+1):
b = (N - r*R - g*G)//B
#print(r,g,b)
if b >= 0:
if r*R + g*G + b*B == N:
cnt += 1
print(cnt)
| 11 | 37 | 280 | 858 | R, G, B, N = list(map(int, input().split()))
res = 0
for i in range(N // R + 1):
for j in range(N // G + 1):
if i * R + j * G > N: # はそもそもむり
continue
k = N - R * i - G * j
if k % B != 0: # その倍数じゃないと無理
continue
res += 1
print(res)
| # from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations, permutations # (string,3) 3回
# from collections import deque
from collections import deque, defaultdict
# import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
# mod = 9982443453
def readInts():
return list(map(int, input().split()))
def I():
return int(eval(input()))
R, G, B, N = readInts()
cnt = 0
for r in range(N // R + 1):
for g in range(N // G + 1):
b = (N - r * R - g * G) // B
# print(r,g,b)
if b >= 0:
if r * R + g * G + b * B == N:
cnt += 1
print(cnt)
| false | 70.27027 | [
"-R, G, B, N = list(map(int, input().split()))",
"-res = 0",
"-for i in range(N // R + 1):",
"- for j in range(N // G + 1):",
"- if i * R + j * G > N: # はそもそもむり",
"- continue",
"- k = N - R * i - G * j",
"- if k % B != 0: # その倍数じゃないと無理",
"- continue",
"- res += 1",
"-print(res)",
"+# from statistics import median",
"+# import collections",
"+# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]",
"+from fractions import gcd",
"+from itertools import combinations, permutations # (string,3) 3回",
"+",
"+# from collections import deque",
"+from collections import deque, defaultdict",
"+",
"+# import bisect",
"+#",
"+# d = m - k[i] - k[j]",
"+# if kk[bisect.bisect_right(kk,d) - 1] == d:",
"+#",
"+#",
"+#",
"+# pythonで無理なときは、pypyでやると正解するかも!!",
"+#",
"+#",
"+import sys",
"+",
"+sys.setrecursionlimit(10000000)",
"+mod = 10**9 + 7",
"+# mod = 9982443453",
"+def readInts():",
"+ return list(map(int, input().split()))",
"+",
"+",
"+def I():",
"+ return int(eval(input()))",
"+",
"+",
"+R, G, B, N = readInts()",
"+cnt = 0",
"+for r in range(N // R + 1):",
"+ for g in range(N // G + 1):",
"+ b = (N - r * R - g * G) // B",
"+ # print(r,g,b)",
"+ if b >= 0:",
"+ if r * R + g * G + b * B == N:",
"+ cnt += 1",
"+print(cnt)"
] | false | 0.239229 | 0.381274 | 0.627448 | [
"s357197563",
"s093522971"
] |
u622570247 | p02714 | python | s827967858 | s242654766 | 945 | 852 | 9,352 | 9,304 | Accepted | Accepted | 9.84 | import itertools
n = int(eval(input()))
s = input().rstrip()
colname = {'R': 0, 'G': 1, 'B': 2}
color = [[], [], []]
for i in range(n):
ci = colname[s[i]]
color[ci].append(i + 1)
color = sorted(color, key=lambda x: len(x))
color[2] = set(color[2])
nc2 = len(color[2])
x = 0
for r in color[0]:
for g in color[1]:
x += nc2
if r > g:
if (r + (r - g)) in color[2]:
x -= 1
if (g - (r - g)) in color[2]:
x -= 1
else:
if (g + (g - r)) in color[2]:
x -= 1
if (r - (g - r)) in color[2]:
x -= 1
c = r + g
if c % 2 == 0 and (c // 2) in color[2]:
x -= 1
print(x) | import itertools
n = int(eval(input()))
s = input().rstrip()
colname = {'R': 0, 'G': 1, 'B': 2}
color = [[], [], []]
for i in range(n):
ci = colname[s[i]]
color[ci].append(i + 1)
color = sorted(color, key=lambda x: len(x))
color[2] = set(color[2])
nc2 = len(color[2])
x = 0
for r in color[0]:
for g in color[1]:
x += nc2
if (r + r - g) in color[2]:
x -= 1
if (g + g - r) in color[2]:
x -= 1
c = r + g
if c % 2 == 0 and (c // 2) in color[2]:
x -= 1
print(x) | 33 | 27 | 756 | 568 | import itertools
n = int(eval(input()))
s = input().rstrip()
colname = {"R": 0, "G": 1, "B": 2}
color = [[], [], []]
for i in range(n):
ci = colname[s[i]]
color[ci].append(i + 1)
color = sorted(color, key=lambda x: len(x))
color[2] = set(color[2])
nc2 = len(color[2])
x = 0
for r in color[0]:
for g in color[1]:
x += nc2
if r > g:
if (r + (r - g)) in color[2]:
x -= 1
if (g - (r - g)) in color[2]:
x -= 1
else:
if (g + (g - r)) in color[2]:
x -= 1
if (r - (g - r)) in color[2]:
x -= 1
c = r + g
if c % 2 == 0 and (c // 2) in color[2]:
x -= 1
print(x)
| import itertools
n = int(eval(input()))
s = input().rstrip()
colname = {"R": 0, "G": 1, "B": 2}
color = [[], [], []]
for i in range(n):
ci = colname[s[i]]
color[ci].append(i + 1)
color = sorted(color, key=lambda x: len(x))
color[2] = set(color[2])
nc2 = len(color[2])
x = 0
for r in color[0]:
for g in color[1]:
x += nc2
if (r + r - g) in color[2]:
x -= 1
if (g + g - r) in color[2]:
x -= 1
c = r + g
if c % 2 == 0 and (c // 2) in color[2]:
x -= 1
print(x)
| false | 18.181818 | [
"- if r > g:",
"- if (r + (r - g)) in color[2]:",
"- x -= 1",
"- if (g - (r - g)) in color[2]:",
"- x -= 1",
"- else:",
"- if (g + (g - r)) in color[2]:",
"- x -= 1",
"- if (r - (g - r)) in color[2]:",
"- x -= 1",
"+ if (r + r - g) in color[2]:",
"+ x -= 1",
"+ if (g + g - r) in color[2]:",
"+ x -= 1"
] | false | 0.076727 | 0.042144 | 1.820603 | [
"s827967858",
"s242654766"
] |
u620480037 | p02936 | python | s601885077 | s627914584 | 1,920 | 947 | 122,656 | 111,152 | Accepted | Accepted | 50.68 | N,Q=list(map(int,input().split()))
L=[[]for i in range(N+1)]
for i in range(N-1):
a,b=list(map(int,input().split()))
L[a].append(b)
L[b].append(a)
S=[0 for i in range(N+1)]
for i in range(Q):
p,x=list(map(int,input().split()))
S[p]+=x
ANS=[-1 for i in range(N+1)]
ANS[1]=S[1]
l=[]
for i in L[1]:
l.append([i,1,S[1]])
for i in range(N-1):
X=l[i][0]
Y=l[i][1]
Z=l[i][2]
ANS[X]=Z+S[X]
for j in L[X]:
if ANS[j]<0:
l.append([j,X,ANS[X]])
print((*ANS[1:]))
| import sys
input=sys.stdin.readline
N,Q=list(map(int,input().split()))
L=[[]for i in range(N+1)]
for i in range(N-1):
a,b=list(map(int,input().split()))
L[a].append(b)
L[b].append(a)
S=[0 for i in range(N+1)]
for i in range(Q):
p,x=list(map(int,input().split()))
S[p]+=x
ANS=[-1 for i in range(N+1)]
ANS[1]=S[1]
l=[]
for i in L[1]:
l.append([i,1,S[1]])
for i in range(N-1):
X=l[i][0]
Y=l[i][1]
Z=l[i][2]
ANS[X]=Z+S[X]
for j in L[X]:
if ANS[j]<0:
l.append([j,X,ANS[X]])
print((*ANS[1:]))
| 29 | 32 | 551 | 591 | N, Q = list(map(int, input().split()))
L = [[] for i in range(N + 1)]
for i in range(N - 1):
a, b = list(map(int, input().split()))
L[a].append(b)
L[b].append(a)
S = [0 for i in range(N + 1)]
for i in range(Q):
p, x = list(map(int, input().split()))
S[p] += x
ANS = [-1 for i in range(N + 1)]
ANS[1] = S[1]
l = []
for i in L[1]:
l.append([i, 1, S[1]])
for i in range(N - 1):
X = l[i][0]
Y = l[i][1]
Z = l[i][2]
ANS[X] = Z + S[X]
for j in L[X]:
if ANS[j] < 0:
l.append([j, X, ANS[X]])
print((*ANS[1:]))
| import sys
input = sys.stdin.readline
N, Q = list(map(int, input().split()))
L = [[] for i in range(N + 1)]
for i in range(N - 1):
a, b = list(map(int, input().split()))
L[a].append(b)
L[b].append(a)
S = [0 for i in range(N + 1)]
for i in range(Q):
p, x = list(map(int, input().split()))
S[p] += x
ANS = [-1 for i in range(N + 1)]
ANS[1] = S[1]
l = []
for i in L[1]:
l.append([i, 1, S[1]])
for i in range(N - 1):
X = l[i][0]
Y = l[i][1]
Z = l[i][2]
ANS[X] = Z + S[X]
for j in L[X]:
if ANS[j] < 0:
l.append([j, X, ANS[X]])
print((*ANS[1:]))
| false | 9.375 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.046184 | 0.038169 | 1.209988 | [
"s601885077",
"s627914584"
] |
u464205401 | p03403 | python | s691379106 | s431183832 | 179 | 160 | 20,576 | 20,640 | Accepted | Accepted | 10.61 | n = int(eval(input()))
a = [0] + list(map(int,input().split())) + [0]
cost = 0
for i in range(n+1):
cost += abs(a[i+1]-a[i])
for i in range(1,n+1):
if (a[i]>a[i-1] and a[i]>a[i+1]) or (a[i]<a[i-1] and a[i]<a[i+1]):
print((cost - abs(a[i]-a[i-1]) - abs(a[i]-a[i+1]) + abs(a[i+1]-a[i-1])))
else:
print(cost) | n = int(eval(input()))
a = [0] + list(map(int,input().split())) + [0]
cost =sum([abs(a[i+1]-a[i]) for i in range(n+1)])
for i in range(1,n+1):
print((cost - abs(a[i]-a[i-1]) - abs(a[i]-a[i+1]) + abs(a[i+1]-a[i-1])))
| 12 | 5 | 326 | 215 | n = int(eval(input()))
a = [0] + list(map(int, input().split())) + [0]
cost = 0
for i in range(n + 1):
cost += abs(a[i + 1] - a[i])
for i in range(1, n + 1):
if (a[i] > a[i - 1] and a[i] > a[i + 1]) or (a[i] < a[i - 1] and a[i] < a[i + 1]):
print(
(
cost
- abs(a[i] - a[i - 1])
- abs(a[i] - a[i + 1])
+ abs(a[i + 1] - a[i - 1])
)
)
else:
print(cost)
| n = int(eval(input()))
a = [0] + list(map(int, input().split())) + [0]
cost = sum([abs(a[i + 1] - a[i]) for i in range(n + 1)])
for i in range(1, n + 1):
print(
(cost - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i + 1] - a[i - 1]))
)
| false | 58.333333 | [
"-cost = 0",
"-for i in range(n + 1):",
"- cost += abs(a[i + 1] - a[i])",
"+cost = sum([abs(a[i + 1] - a[i]) for i in range(n + 1)])",
"- if (a[i] > a[i - 1] and a[i] > a[i + 1]) or (a[i] < a[i - 1] and a[i] < a[i + 1]):",
"- print(",
"- (",
"- cost",
"- - abs(a[i] - a[i - 1])",
"- - abs(a[i] - a[i + 1])",
"- + abs(a[i + 1] - a[i - 1])",
"- )",
"- )",
"- else:",
"- print(cost)",
"+ print(",
"+ (cost - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i + 1] - a[i - 1]))",
"+ )"
] | false | 0.040691 | 0.09813 | 0.414661 | [
"s691379106",
"s431183832"
] |
u145950990 | p03250 | python | s986503460 | s061772369 | 160 | 25 | 38,256 | 9,048 | Accepted | Accepted | 84.38 | a,b,c = list(map(int,input().split()))
print((max(a,b,c)*9+a+b+c)) | a,b,c = sorted(map(int,input().split()))
print((c*10+b+a)) | 2 | 2 | 59 | 57 | a, b, c = list(map(int, input().split()))
print((max(a, b, c) * 9 + a + b + c))
| a, b, c = sorted(map(int, input().split()))
print((c * 10 + b + a))
| false | 0 | [
"-a, b, c = list(map(int, input().split()))",
"-print((max(a, b, c) * 9 + a + b + c))",
"+a, b, c = sorted(map(int, input().split()))",
"+print((c * 10 + b + a))"
] | false | 0.041044 | 0.035386 | 1.159913 | [
"s986503460",
"s061772369"
] |
u728566015 | p02899 | python | s643396412 | s666582838 | 256 | 197 | 26,296 | 25,628 | Accepted | Accepted | 23.05 | N = int(input())
A = list(map(int, input().split()))
d = {}
for i, s in zip(range(1, N + 1), A):
d[i] = s
d_sorted = sorted(d.items(), key=lambda x: x[1])
for i in range(N):
print(d_sorted[i][0], end=" ")
| N = int(eval(input()))
A = list(map(int, input().split()))
d = {}
for i, s in zip(list(range(1, N + 1)), A):
d[i] = s
d_sorted = sorted(list(d.items()), key=lambda x: x[1])
for i in range(N):
print((d_sorted[i][0])) | 10 | 10 | 223 | 214 | N = int(input())
A = list(map(int, input().split()))
d = {}
for i, s in zip(range(1, N + 1), A):
d[i] = s
d_sorted = sorted(d.items(), key=lambda x: x[1])
for i in range(N):
print(d_sorted[i][0], end=" ")
| N = int(eval(input()))
A = list(map(int, input().split()))
d = {}
for i, s in zip(list(range(1, N + 1)), A):
d[i] = s
d_sorted = sorted(list(d.items()), key=lambda x: x[1])
for i in range(N):
print((d_sorted[i][0]))
| false | 0 | [
"-N = int(input())",
"+N = int(eval(input()))",
"-for i, s in zip(range(1, N + 1), A):",
"+for i, s in zip(list(range(1, N + 1)), A):",
"-d_sorted = sorted(d.items(), key=lambda x: x[1])",
"+d_sorted = sorted(list(d.items()), key=lambda x: x[1])",
"- print(d_sorted[i][0], end=\" \")",
"+ print((d_sorted[i][0]))"
] | false | 0.038206 | 0.042896 | 0.890678 | [
"s643396412",
"s666582838"
] |
u619274787 | p02695 | python | s345702385 | s589216877 | 1,030 | 227 | 9,136 | 46,584 | Accepted | Accepted | 77.96 | import itertools
N,M,Q = list(map(int, input().split()))
AA = itertools.combinations_with_replacement(list(range(1,M+1)), N)
abcd = [list(map(int, input().split())) for _ in range(Q)]
ans = -10**18
for A in AA:
score = 0
for a,b,c,d in abcd:
if A[b-1] - A[a-1] == c:
score += d
ans = max(ans, score)
print(ans) | import sys
import itertools
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,M,Q = list(map(int, readline().split()))
A = np.array(list(itertools.combinations_with_replacement(list(range(1,M+1)), N)))
score = np.zeros(len(A), int)
m = list(map(int, read().split()))
for a,b,c,d in zip(m,m,m,m):
score += (A[:,b-1] - A[:,a-1] == c) * d
print((score.max())) | 14 | 16 | 345 | 434 | import itertools
N, M, Q = list(map(int, input().split()))
AA = itertools.combinations_with_replacement(list(range(1, M + 1)), N)
abcd = [list(map(int, input().split())) for _ in range(Q)]
ans = -(10**18)
for A in AA:
score = 0
for a, b, c, d in abcd:
if A[b - 1] - A[a - 1] == c:
score += d
ans = max(ans, score)
print(ans)
| import sys
import itertools
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, M, Q = list(map(int, readline().split()))
A = np.array(list(itertools.combinations_with_replacement(list(range(1, M + 1)), N)))
score = np.zeros(len(A), int)
m = list(map(int, read().split()))
for a, b, c, d in zip(m, m, m, m):
score += (A[:, b - 1] - A[:, a - 1] == c) * d
print((score.max()))
| false | 12.5 | [
"+import sys",
"+import numpy as np",
"-N, M, Q = list(map(int, input().split()))",
"-AA = itertools.combinations_with_replacement(list(range(1, M + 1)), N)",
"-abcd = [list(map(int, input().split())) for _ in range(Q)]",
"-ans = -(10**18)",
"-for A in AA:",
"- score = 0",
"- for a, b, c, d in abcd:",
"- if A[b - 1] - A[a - 1] == c:",
"- score += d",
"- ans = max(ans, score)",
"-print(ans)",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+N, M, Q = list(map(int, readline().split()))",
"+A = np.array(list(itertools.combinations_with_replacement(list(range(1, M + 1)), N)))",
"+score = np.zeros(len(A), int)",
"+m = list(map(int, read().split()))",
"+for a, b, c, d in zip(m, m, m, m):",
"+ score += (A[:, b - 1] - A[:, a - 1] == c) * d",
"+print((score.max()))"
] | false | 0.099703 | 0.280423 | 0.355545 | [
"s345702385",
"s589216877"
] |
u529386725 | p02258 | python | s072507240 | s526467142 | 580 | 520 | 16,944 | 7,680 | Accepted | Accepted | 10.34 | N = int(eval(input()))
a = []
for i in range(N):
a.append(int(eval(input())))
mins = [a[0]]
for i in range(1, N):
mins.append(min(a[i], mins[i-1]))
mx = -10**12
for j in range(1, N):
mx = max(mx, a[j] - mins[j-1])
print(mx) | N = int(eval(input()))
#R[0]
minv = int(eval(input()))
maxv = -10**12
#R[1..N-1]
for j in range(1, N):
r = int(eval(input()))
maxv = max(maxv, r - minv)
minv = min(minv, r)
print(maxv) | 13 | 13 | 241 | 197 | N = int(eval(input()))
a = []
for i in range(N):
a.append(int(eval(input())))
mins = [a[0]]
for i in range(1, N):
mins.append(min(a[i], mins[i - 1]))
mx = -(10**12)
for j in range(1, N):
mx = max(mx, a[j] - mins[j - 1])
print(mx)
| N = int(eval(input()))
# R[0]
minv = int(eval(input()))
maxv = -(10**12)
# R[1..N-1]
for j in range(1, N):
r = int(eval(input()))
maxv = max(maxv, r - minv)
minv = min(minv, r)
print(maxv)
| false | 0 | [
"-a = []",
"-for i in range(N):",
"- a.append(int(eval(input())))",
"-mins = [a[0]]",
"-for i in range(1, N):",
"- mins.append(min(a[i], mins[i - 1]))",
"-mx = -(10**12)",
"+# R[0]",
"+minv = int(eval(input()))",
"+maxv = -(10**12)",
"+# R[1..N-1]",
"- mx = max(mx, a[j] - mins[j - 1])",
"-print(mx)",
"+ r = int(eval(input()))",
"+ maxv = max(maxv, r - minv)",
"+ minv = min(minv, r)",
"+print(maxv)"
] | false | 0.046318 | 0.069908 | 0.662564 | [
"s072507240",
"s526467142"
] |
u714878632 | p03733 | python | s525028387 | s057809868 | 160 | 122 | 25,200 | 25,196 | Accepted | Accepted | 23.75 | N,T = [int(i) for i in input().split()]
ts = [int(i) for i in input().split()]
ret = 0
# for ind in range (1, N):
# ret += min(T,ts[ind]-ts[ind-1])
for diff in [ts[ind+1]-ts[ind] for ind in range(N-1)]:
ret += min(T,diff)
print((ret+T))
| N,T = [int(i) for i in input().split()]
ts = [int(i) for i in input().split()]
ret = 0
# for ind in range (1, N):
# ret += min(T,ts[ind]-ts[ind-1])
for diff in [ts[ind+1]-ts[ind] for ind in range(N-1)]:
ret += T if T<diff else diff
print((ret+T))
| 8 | 8 | 250 | 260 | N, T = [int(i) for i in input().split()]
ts = [int(i) for i in input().split()]
ret = 0
# for ind in range (1, N):
# ret += min(T,ts[ind]-ts[ind-1])
for diff in [ts[ind + 1] - ts[ind] for ind in range(N - 1)]:
ret += min(T, diff)
print((ret + T))
| N, T = [int(i) for i in input().split()]
ts = [int(i) for i in input().split()]
ret = 0
# for ind in range (1, N):
# ret += min(T,ts[ind]-ts[ind-1])
for diff in [ts[ind + 1] - ts[ind] for ind in range(N - 1)]:
ret += T if T < diff else diff
print((ret + T))
| false | 0 | [
"- ret += min(T, diff)",
"+ ret += T if T < diff else diff"
] | false | 0.053841 | 0.077356 | 0.696013 | [
"s525028387",
"s057809868"
] |
u430726059 | p02547 | python | s055825658 | s229899280 | 33 | 30 | 9,168 | 9,100 | Accepted | Accepted | 9.09 | n=int(eval(input()))
alist=[0]*n
for i in range(n):
a,b=list(map(int, input().split()))
if a==b:
if i==0:
alist[0]=1
else:
alist[i]=alist[i-1]+1
if max(alist)>=3:
print('Yes')
else:
print('No') | n=int(eval(input()))
alist=[0]*n
for i in range(n):
a,b=list(map(int, input().split()))
if a==b:
alist[i]=alist[max(i-1,0)]+1
if max(alist)>=3:
print('Yes')
else:
print('No')
| 13 | 10 | 221 | 186 | n = int(eval(input()))
alist = [0] * n
for i in range(n):
a, b = list(map(int, input().split()))
if a == b:
if i == 0:
alist[0] = 1
else:
alist[i] = alist[i - 1] + 1
if max(alist) >= 3:
print("Yes")
else:
print("No")
| n = int(eval(input()))
alist = [0] * n
for i in range(n):
a, b = list(map(int, input().split()))
if a == b:
alist[i] = alist[max(i - 1, 0)] + 1
if max(alist) >= 3:
print("Yes")
else:
print("No")
| false | 23.076923 | [
"- if i == 0:",
"- alist[0] = 1",
"- else:",
"- alist[i] = alist[i - 1] + 1",
"+ alist[i] = alist[max(i - 1, 0)] + 1"
] | false | 0.03272 | 0.032344 | 1.011639 | [
"s055825658",
"s229899280"
] |
u926412290 | p02952 | python | s339100764 | s431924210 | 57 | 52 | 2,940 | 6,732 | Accepted | Accepted | 8.77 | N = int(eval(input()))
count = 0
for i in range(1, N+1):
if len(str(i)) % 2 == 1:
count += 1
print(count) | N = int(eval(input()))
print((len(list(i for i in range(1, N + 1) if len(str(i)) % 2 == 1)))) | 8 | 2 | 120 | 86 | N = int(eval(input()))
count = 0
for i in range(1, N + 1):
if len(str(i)) % 2 == 1:
count += 1
print(count)
| N = int(eval(input()))
print((len(list(i for i in range(1, N + 1) if len(str(i)) % 2 == 1))))
| false | 75 | [
"-count = 0",
"-for i in range(1, N + 1):",
"- if len(str(i)) % 2 == 1:",
"- count += 1",
"-print(count)",
"+print((len(list(i for i in range(1, N + 1) if len(str(i)) % 2 == 1))))"
] | false | 0.059478 | 0.052322 | 1.13677 | [
"s339100764",
"s431924210"
] |
u502389123 | p03221 | python | s965767846 | s197902341 | 1,052 | 883 | 55,832 | 41,668 | Accepted | Accepted | 16.06 | N, M = list(map(int, input().split()))
P_Y_i = [list(map(int, input().split())) for i in range(M)]
for i in range(M):
P_Y_i[i].append(i)
Ken_index = [[] for i in range(N)]
for i in range(M):
Ken_index[P_Y_i[i][0] - 1].append(P_Y_i[i])
for i in range(N):
if len(Ken_index[i]) != 0:
Ken_index[i].sort(key=lambda x: x[1])
Ken_Update = []
for Ken in Ken_index:
for i in range(len(Ken)):
Ken_Update.append(['{0:06d}'.format(Ken[i][0]) + '{0:06d}'.format(i+1), Ken[i][2]])
Ken_Update.sort(key=lambda x: x[1])
for i in range(len(Ken_Update)):
print((Ken_Update[i][0]))
| N, M = list(map(int, input().split()))
PY = []
for i in range(M):
PY.append(list(map(int, input().split())) + [i])
PY.sort()
l = []
t = 0
for i in range(M):
if t != PY[i][0]:
t = PY[i][0]
cnt = 1
l.append([str(t).zfill(6) + str(cnt).zfill(6), PY[i][2]])
cnt += 1
l.sort(key=lambda x: x[1])
for i in range(M):
print((l[i][0])) | 21 | 20 | 614 | 376 | N, M = list(map(int, input().split()))
P_Y_i = [list(map(int, input().split())) for i in range(M)]
for i in range(M):
P_Y_i[i].append(i)
Ken_index = [[] for i in range(N)]
for i in range(M):
Ken_index[P_Y_i[i][0] - 1].append(P_Y_i[i])
for i in range(N):
if len(Ken_index[i]) != 0:
Ken_index[i].sort(key=lambda x: x[1])
Ken_Update = []
for Ken in Ken_index:
for i in range(len(Ken)):
Ken_Update.append(
["{0:06d}".format(Ken[i][0]) + "{0:06d}".format(i + 1), Ken[i][2]]
)
Ken_Update.sort(key=lambda x: x[1])
for i in range(len(Ken_Update)):
print((Ken_Update[i][0]))
| N, M = list(map(int, input().split()))
PY = []
for i in range(M):
PY.append(list(map(int, input().split())) + [i])
PY.sort()
l = []
t = 0
for i in range(M):
if t != PY[i][0]:
t = PY[i][0]
cnt = 1
l.append([str(t).zfill(6) + str(cnt).zfill(6), PY[i][2]])
cnt += 1
l.sort(key=lambda x: x[1])
for i in range(M):
print((l[i][0]))
| false | 4.761905 | [
"-P_Y_i = [list(map(int, input().split())) for i in range(M)]",
"+PY = []",
"- P_Y_i[i].append(i)",
"-Ken_index = [[] for i in range(N)]",
"+ PY.append(list(map(int, input().split())) + [i])",
"+PY.sort()",
"+l = []",
"+t = 0",
"- Ken_index[P_Y_i[i][0] - 1].append(P_Y_i[i])",
"-for i in range(N):",
"- if len(Ken_index[i]) != 0:",
"- Ken_index[i].sort(key=lambda x: x[1])",
"-Ken_Update = []",
"-for Ken in Ken_index:",
"- for i in range(len(Ken)):",
"- Ken_Update.append(",
"- [\"{0:06d}\".format(Ken[i][0]) + \"{0:06d}\".format(i + 1), Ken[i][2]]",
"- )",
"-Ken_Update.sort(key=lambda x: x[1])",
"-for i in range(len(Ken_Update)):",
"- print((Ken_Update[i][0]))",
"+ if t != PY[i][0]:",
"+ t = PY[i][0]",
"+ cnt = 1",
"+ l.append([str(t).zfill(6) + str(cnt).zfill(6), PY[i][2]])",
"+ cnt += 1",
"+l.sort(key=lambda x: x[1])",
"+for i in range(M):",
"+ print((l[i][0]))"
] | false | 0.154629 | 0.049114 | 3.148373 | [
"s965767846",
"s197902341"
] |
u564902833 | p03063 | python | s088676196 | s732161071 | 141 | 117 | 11,400 | 11,492 | Accepted | Accepted | 17.02 | N = int(eval(input()))
S = eval(input())
dp = [0 for i in range(N + 1)]
for i in range(N):
dp[i + 1] = dp[i] + (S[i] == '#')
ans = min(dp[i] + (N - i - (dp[N] - dp[i])) for i in range(N + 1))
print(ans)
| from itertools import accumulate, chain
# 入力
N = int(eval(input()))
S = eval(input())
# 黒色の石の個数に関する累積和を求めておく
dp = list(
accumulate(
chain(
[0],
[s == '#' for s in S]
)
)
)
# 各iについて、左i個を白色、右N-i個を黒色にする際、色を変更する必要のある石の個数を求め、
# 最小値を解とする。
ans = min(
dp[i] + (N - i - (dp[N] - dp[i]))
for i in range(N + 1)
)
print(ans)
| 8 | 23 | 203 | 387 | N = int(eval(input()))
S = eval(input())
dp = [0 for i in range(N + 1)]
for i in range(N):
dp[i + 1] = dp[i] + (S[i] == "#")
ans = min(dp[i] + (N - i - (dp[N] - dp[i])) for i in range(N + 1))
print(ans)
| from itertools import accumulate, chain
# 入力
N = int(eval(input()))
S = eval(input())
# 黒色の石の個数に関する累積和を求めておく
dp = list(accumulate(chain([0], [s == "#" for s in S])))
# 各iについて、左i個を白色、右N-i個を黒色にする際、色を変更する必要のある石の個数を求め、
# 最小値を解とする。
ans = min(dp[i] + (N - i - (dp[N] - dp[i])) for i in range(N + 1))
print(ans)
| false | 65.217391 | [
"+from itertools import accumulate, chain",
"+",
"+# 入力",
"-dp = [0 for i in range(N + 1)]",
"-for i in range(N):",
"- dp[i + 1] = dp[i] + (S[i] == \"#\")",
"+# 黒色の石の個数に関する累積和を求めておく",
"+dp = list(accumulate(chain([0], [s == \"#\" for s in S])))",
"+# 各iについて、左i個を白色、右N-i個を黒色にする際、色を変更する必要のある石の個数を求め、",
"+# 最小値を解とする。"
] | false | 0.077049 | 0.04321 | 1.783111 | [
"s088676196",
"s732161071"
] |
u047023156 | p03353 | python | s106009277 | s924393824 | 195 | 43 | 40,176 | 5,192 | Accepted | Accepted | 77.95 | import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))
def main():
s = ns()
k = ni()
check = set()
for left in range(0, len(s)):
for right in range(left+1, left+k+1):
check.add(s[left:right])
print((sorted(list(check))[k-1]))
if __name__ == '__main__':
main() | import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))
s = ns()
k = ni()
check = set()
for left in range(0, len(s)):
for right in range(left+1, left+k+1):
check.add(s[left:right])
print((sorted(list(check))[k-1]))
| 28 | 26 | 750 | 668 | import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))
def main():
s = ns()
k = ni()
check = set()
for left in range(0, len(s)):
for right in range(left + 1, left + k + 1):
check.add(s[left:right])
print((sorted(list(check))[k - 1]))
if __name__ == "__main__":
main()
| import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))
s = ns()
k = ni()
check = set()
for left in range(0, len(s)):
for right in range(left + 1, left + k + 1):
check.add(s[left:right])
print((sorted(list(check))[k - 1]))
| false | 7.142857 | [
"-",
"-",
"-def main():",
"- s = ns()",
"- k = ni()",
"- check = set()",
"- for left in range(0, len(s)):",
"- for right in range(left + 1, left + k + 1):",
"- check.add(s[left:right])",
"- print((sorted(list(check))[k - 1]))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+s = ns()",
"+k = ni()",
"+check = set()",
"+for left in range(0, len(s)):",
"+ for right in range(left + 1, left + k + 1):",
"+ check.add(s[left:right])",
"+print((sorted(list(check))[k - 1]))"
] | false | 0.042078 | 0.079398 | 0.529962 | [
"s106009277",
"s924393824"
] |
u014333473 | p03494 | python | s918580655 | s431442699 | 31 | 28 | 9,064 | 9,224 | Accepted | Accepted | 9.68 | eval(input());a=list(map(int,input().split()));c=0
while all([i%2==0 for i in a]):
a=[i//2 for i in a];c+=1
print(c) | eval(input());a=list(map(int,input().split()));c=0
while all([i%2==0 for i in a]):
a=[i/2 for i in a];c+=1
print(c) | 4 | 4 | 115 | 114 | eval(input())
a = list(map(int, input().split()))
c = 0
while all([i % 2 == 0 for i in a]):
a = [i // 2 for i in a]
c += 1
print(c)
| eval(input())
a = list(map(int, input().split()))
c = 0
while all([i % 2 == 0 for i in a]):
a = [i / 2 for i in a]
c += 1
print(c)
| false | 0 | [
"- a = [i // 2 for i in a]",
"+ a = [i / 2 for i in a]"
] | false | 0.047188 | 0.046 | 1.025846 | [
"s918580655",
"s431442699"
] |
u312025627 | p02707 | python | s426257954 | s240979482 | 222 | 186 | 114,832 | 122,244 | Accepted | Accepted | 16.22 | def main():
N = int(eval(input()))
A = [int(i) for i in input().split()]
from collections import Counter
c = Counter(A)
for i in range(N):
print((c[i+1]))
if __name__ == '__main__':
main()
| def main():
N = int(eval(input()))
A = [int(i) for i in input().split()]
from collections import Counter
c = Counter(A)
for i in range(1, N+1):
print((c[i]))
if __name__ == '__main__':
main()
| 11 | 11 | 225 | 228 | def main():
N = int(eval(input()))
A = [int(i) for i in input().split()]
from collections import Counter
c = Counter(A)
for i in range(N):
print((c[i + 1]))
if __name__ == "__main__":
main()
| def main():
N = int(eval(input()))
A = [int(i) for i in input().split()]
from collections import Counter
c = Counter(A)
for i in range(1, N + 1):
print((c[i]))
if __name__ == "__main__":
main()
| false | 0 | [
"- for i in range(N):",
"- print((c[i + 1]))",
"+ for i in range(1, N + 1):",
"+ print((c[i]))"
] | false | 0.037158 | 0.034307 | 1.083102 | [
"s426257954",
"s240979482"
] |
u619458041 | p03038 | python | s728105112 | s915014970 | 676 | 396 | 74,392 | 26,260 | Accepted | Accepted | 41.42 | import sys
from heapq import heappush, heappop
def main():
input = sys.stdin.readline
N, M = list(map(int, input().split()))
heap = []
ans = 0
for a in map(int, input().split()):
heappush(heap, a)
ans += a
BC = []
for _ in range(M):
B, C = list(map(int, input().split()))
BC.append((B, C))
BC = sorted(BC, key=lambda x: -x[1])
for B, C in BC:
for _ in range(B):
a = heappop(heap)
if a < C:
heappush(heap, C)
ans += C - a
else:
heappush(heap, a)
break
return ans
if __name__ == '__main__':
print((main()))
| import sys
from heapq import heappush, heappop
def main():
input = sys.stdin.readline
N, M = list(map(int, input().split()))
heap = []
ans = 0
for a in map(int, input().split()):
heappush(heap, a)
BC = []
for _ in range(M):
B, C = list(map(int, input().split()))
BC.append((B, C))
BC = sorted(BC, key=lambda x: -x[1])
for B, C in BC:
for _ in range(B):
a = heappop(heap)
if a < C:
heappush(heap, C)
else:
heappush(heap, a)
break
return sum(heap)
if __name__ == '__main__':
print((main()))
| 34 | 32 | 715 | 673 | import sys
from heapq import heappush, heappop
def main():
input = sys.stdin.readline
N, M = list(map(int, input().split()))
heap = []
ans = 0
for a in map(int, input().split()):
heappush(heap, a)
ans += a
BC = []
for _ in range(M):
B, C = list(map(int, input().split()))
BC.append((B, C))
BC = sorted(BC, key=lambda x: -x[1])
for B, C in BC:
for _ in range(B):
a = heappop(heap)
if a < C:
heappush(heap, C)
ans += C - a
else:
heappush(heap, a)
break
return ans
if __name__ == "__main__":
print((main()))
| import sys
from heapq import heappush, heappop
def main():
input = sys.stdin.readline
N, M = list(map(int, input().split()))
heap = []
ans = 0
for a in map(int, input().split()):
heappush(heap, a)
BC = []
for _ in range(M):
B, C = list(map(int, input().split()))
BC.append((B, C))
BC = sorted(BC, key=lambda x: -x[1])
for B, C in BC:
for _ in range(B):
a = heappop(heap)
if a < C:
heappush(heap, C)
else:
heappush(heap, a)
break
return sum(heap)
if __name__ == "__main__":
print((main()))
| false | 5.882353 | [
"- ans += a",
"- ans += C - a",
"- return ans",
"+ return sum(heap)"
] | false | 0.059541 | 0.03729 | 1.596689 | [
"s728105112",
"s915014970"
] |
u678167152 | p02659 | python | s283362703 | s430375720 | 59 | 26 | 61,808 | 9,976 | Accepted | Accepted | 55.93 | A, B = input().split()
B = B.split('.')
if B[0]=='0':
B = int(B[1])
else:
B = int(B[0]+B[1])
A = int(A)
ans = A*B//100
print(ans) | from decimal import Decimal
S, T = input().split()
S = Decimal(S)
T = Decimal(T)
print((int(S*T))) | 9 | 7 | 145 | 104 | A, B = input().split()
B = B.split(".")
if B[0] == "0":
B = int(B[1])
else:
B = int(B[0] + B[1])
A = int(A)
ans = A * B // 100
print(ans)
| from decimal import Decimal
S, T = input().split()
S = Decimal(S)
T = Decimal(T)
print((int(S * T)))
| false | 22.222222 | [
"-A, B = input().split()",
"-B = B.split(\".\")",
"-if B[0] == \"0\":",
"- B = int(B[1])",
"-else:",
"- B = int(B[0] + B[1])",
"-A = int(A)",
"-ans = A * B // 100",
"-print(ans)",
"+from decimal import Decimal",
"+",
"+S, T = input().split()",
"+S = Decimal(S)",
"+T = Decimal(T)",
"+print((int(S * T)))"
] | false | 0.042504 | 0.037359 | 1.137721 | [
"s283362703",
"s430375720"
] |
u677121387 | p03779 | python | s591871976 | s568432069 | 29 | 18 | 2,940 | 3,060 | Accepted | Accepted | 37.93 | x = int(eval(input()))
ans = 0
t = 0
d = 0
while x > d:
t += 1
d += t
ans += 1
print(ans) | from math import ceil
x = int(eval(input()))
print((ceil((-1+(-1+8*x)**0.5)/2))) | 11 | 3 | 107 | 74 | x = int(eval(input()))
ans = 0
t = 0
d = 0
while x > d:
t += 1
d += t
ans += 1
print(ans)
| from math import ceil
x = int(eval(input()))
print((ceil((-1 + (-1 + 8 * x) ** 0.5) / 2)))
| false | 72.727273 | [
"+from math import ceil",
"+",
"-ans = 0",
"-t = 0",
"-d = 0",
"-while x > d:",
"- t += 1",
"- d += t",
"- ans += 1",
"-print(ans)",
"+print((ceil((-1 + (-1 + 8 * x) ** 0.5) / 2)))"
] | false | 0.036059 | 0.036368 | 0.991497 | [
"s591871976",
"s568432069"
] |
u324314500 | p03078 | python | s352470525 | s506003546 | 1,920 | 751 | 58,844 | 49,756 | Accepted | Accepted | 60.89 | import sys
#import numpy as np
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
N = 10000
def tokey(i, j, k):
return i*N*N + j*N + k
def dekey(n):
i = int(n / N / N)
j = int(n / N) % N
k = n % N
return i, j, k
def main():
X, Y, Z, K = i2nn()
A = i2nn()
B = i2nn()
C = i2nn()
A.sort()
A.reverse()
B.sort()
B.reverse()
C.sort()
C.reverse()
Q = [(A[0] + B[0] + C[0], 0, 0, 0)]
loop = 0
stored = set()
def next(i, j, k):
if i >= X or j >= Y or k >= Z:
return
key = tokey(i, j, k)
if key not in stored:
stored.add(key)
n = A[i] + B[j] + C[k]
Q.append((n, i, j, k))
while True:
Q.sort(key=lambda v: v[0])
v = Q.pop()
print((v[0]))
loop += 1
if loop >= K:
break
next(v[1]+1, v[2], v[3])
next(v[1], v[2]+1, v[3])
next(v[1], v[2], v[3]+1)
main()
| import sys
#import numpy as np
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
N = 10000
def tokey(i, j, k):
return i*N*N + j*N + k
def dekey(n):
i = int(n / N / N)
j = int(n / N) % N
k = n % N
return i, j, k
def main():
X, Y, Z, K = i2nn()
A = i2nn()
B = i2nn()
C = i2nn()
A.sort()
A.reverse()
B.sort()
B.reverse()
C.sort()
C.reverse()
Q = [(A[0] + B[0] + C[0], 0, 0, 0)]
loop = 0
stored = set()
def next(i, j, k):
if i >= X or j >= Y or k >= Z:
return
key = tokey(i, j, k)
if key not in stored:
stored.add(key)
n = A[i] + B[j] + C[k]
Q.append((n, i, j, k))
while True:
v = max(Q, key=lambda v: v[0])
Q.remove(v)
print((v[0]))
loop += 1
if loop >= K:
break
next(v[1]+1, v[2], v[3])
next(v[1], v[2]+1, v[3])
next(v[1], v[2], v[3]+1)
main()
| 56 | 56 | 1,337 | 1,341 | import sys
# import numpy as np
s2nn = lambda s: [int(c) for c in s.split(" ")]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
N = 10000
def tokey(i, j, k):
return i * N * N + j * N + k
def dekey(n):
i = int(n / N / N)
j = int(n / N) % N
k = n % N
return i, j, k
def main():
X, Y, Z, K = i2nn()
A = i2nn()
B = i2nn()
C = i2nn()
A.sort()
A.reverse()
B.sort()
B.reverse()
C.sort()
C.reverse()
Q = [(A[0] + B[0] + C[0], 0, 0, 0)]
loop = 0
stored = set()
def next(i, j, k):
if i >= X or j >= Y or k >= Z:
return
key = tokey(i, j, k)
if key not in stored:
stored.add(key)
n = A[i] + B[j] + C[k]
Q.append((n, i, j, k))
while True:
Q.sort(key=lambda v: v[0])
v = Q.pop()
print((v[0]))
loop += 1
if loop >= K:
break
next(v[1] + 1, v[2], v[3])
next(v[1], v[2] + 1, v[3])
next(v[1], v[2], v[3] + 1)
main()
| import sys
# import numpy as np
s2nn = lambda s: [int(c) for c in s.split(" ")]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
N = 10000
def tokey(i, j, k):
return i * N * N + j * N + k
def dekey(n):
i = int(n / N / N)
j = int(n / N) % N
k = n % N
return i, j, k
def main():
X, Y, Z, K = i2nn()
A = i2nn()
B = i2nn()
C = i2nn()
A.sort()
A.reverse()
B.sort()
B.reverse()
C.sort()
C.reverse()
Q = [(A[0] + B[0] + C[0], 0, 0, 0)]
loop = 0
stored = set()
def next(i, j, k):
if i >= X or j >= Y or k >= Z:
return
key = tokey(i, j, k)
if key not in stored:
stored.add(key)
n = A[i] + B[j] + C[k]
Q.append((n, i, j, k))
while True:
v = max(Q, key=lambda v: v[0])
Q.remove(v)
print((v[0]))
loop += 1
if loop >= K:
break
next(v[1] + 1, v[2], v[3])
next(v[1], v[2] + 1, v[3])
next(v[1], v[2], v[3] + 1)
main()
| false | 0 | [
"- Q.sort(key=lambda v: v[0])",
"- v = Q.pop()",
"+ v = max(Q, key=lambda v: v[0])",
"+ Q.remove(v)"
] | false | 0.037862 | 0.03827 | 0.989339 | [
"s352470525",
"s506003546"
] |
u150984829 | p02414 | python | s872236291 | s176831170 | 130 | 110 | 7,004 | 7,008 | Accepted | Accepted | 15.38 | n,m,l=map(int,input().split())
a=[list(map(int,input().split()))for _ in range(n)]
b=[list(map(int,input().split()))for _ in range(m)]
[print(*x)for x in[[sum(s*t for s,t in zip(c,l))for l in zip(*b)]for c in a]]
| n,m,l=map(int,input().split())
a=[list(map(int,input().split()))for _ in range(n)]
b=[list(map(int,input().split()))for _ in range(m)]
[print(*x)for x in[[sum([s*t for s,t in zip(c,l)])for l in zip(*b)]for c in a]]
| 4 | 4 | 215 | 217 | n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
[print(*x) for x in [[sum(s * t for s, t in zip(c, l)) for l in zip(*b)] for c in a]]
| n, m, l = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
[print(*x) for x in [[sum([s * t for s, t in zip(c, l)]) for l in zip(*b)] for c in a]]
| false | 0 | [
"-[print(*x) for x in [[sum(s * t for s, t in zip(c, l)) for l in zip(*b)] for c in a]]",
"+[print(*x) for x in [[sum([s * t for s, t in zip(c, l)]) for l in zip(*b)] for c in a]]"
] | false | 0.074562 | 0.070909 | 1.051525 | [
"s872236291",
"s176831170"
] |
u651235280 | p02768 | python | s444548933 | s808375598 | 1,287 | 124 | 9,092 | 9,140 | Accepted | Accepted | 90.37 | import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
mod = 10**9+7
n,a,b = list(map(int, input().split()))
def comb(n, k):
c = 1
for i in range(n - k + 1, n + 1):
c *= i
c %= mod
for i in range(1, k + 1):
c *= pow(i, mod - 2, mod)
c %= mod
return c
ans = pow(2, n, mod) - 1 - comb(n, a) - comb(n, b)
print((ans % mod))
| import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
mod = 10**9+7
n,a,b = list(map(int, input().split()))
# def comb(n, k):
# c = 1
# for i in range(n - k + 1, n + 1):
# c *= i
# c %= mod
#
# for i in range(1, k + 1):
# c *= pow(i, mod - 2, mod)
# c %= mod
#
# return c
def comb(n, k):
c = 1
for i in range(k):
c *= n - i
c %= mod
d = 1
for i in range(1, k + 1):
d *= i
d %= mod
return (c * pow(d, mod - 2, mod)) % mod
ans = pow(2, n, mod) - 1 - comb(n, a) - comb(n, b)
print((ans % mod))
| 22 | 35 | 400 | 637 | import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
mod = 10**9 + 7
n, a, b = list(map(int, input().split()))
def comb(n, k):
c = 1
for i in range(n - k + 1, n + 1):
c *= i
c %= mod
for i in range(1, k + 1):
c *= pow(i, mod - 2, mod)
c %= mod
return c
ans = pow(2, n, mod) - 1 - comb(n, a) - comb(n, b)
print((ans % mod))
| import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
mod = 10**9 + 7
n, a, b = list(map(int, input().split()))
# def comb(n, k):
# c = 1
# for i in range(n - k + 1, n + 1):
# c *= i
# c %= mod
#
# for i in range(1, k + 1):
# c *= pow(i, mod - 2, mod)
# c %= mod
#
# return c
def comb(n, k):
c = 1
for i in range(k):
c *= n - i
c %= mod
d = 1
for i in range(1, k + 1):
d *= i
d %= mod
return (c * pow(d, mod - 2, mod)) % mod
ans = pow(2, n, mod) - 1 - comb(n, a) - comb(n, b)
print((ans % mod))
| false | 37.142857 | [
"-",
"-",
"+# def comb(n, k):",
"+# c = 1",
"+# for i in range(n - k + 1, n + 1):",
"+# c *= i",
"+# c %= mod",
"+#",
"+# for i in range(1, k + 1):",
"+# c *= pow(i, mod - 2, mod)",
"+# c %= mod",
"+#",
"+# return c",
"- for i in range(n - k + 1, n + 1):",
"- c *= i",
"+ for i in range(k):",
"+ c *= n - i",
"+ d = 1",
"- c *= pow(i, mod - 2, mod)",
"- c %= mod",
"- return c",
"+ d *= i",
"+ d %= mod",
"+ return (c * pow(d, mod - 2, mod)) % mod"
] | false | 0.919878 | 0.128511 | 7.157948 | [
"s444548933",
"s808375598"
] |
u480472958 | p03151 | python | s799605597 | s479862069 | 135 | 116 | 19,060 | 18,708 | Accepted | Accepted | 14.07 | n = int(eval(input()))
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
ABs = sorted([a - b for a, b in zip(As, Bs)])
# print(As, Bs, ABs)
if sum(As) < sum(Bs):
print((-1))
exit()
if min(ABs) > 0:
print((-1))
exit()
mABs = [ab for ab in ABs if ab < 0]
msum, ans = sum(mABs), len(mABs)
# print(mABs, msum, ans)
now = -1
while msum < 0:
msum += ABs[now]
ans += 1
now -= 1
print(ans) | n = int(eval(input()))
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
ABs = [a - b for a, b in zip(As, Bs)]
if sum(As) < sum(Bs) or min(ABs) > 0:
print((-1))
exit()
mABs = [ab for ab in ABs if ab < 0]
pABs = [ab for ab in ABs if ab > 0]
ans, t = len(mABs), sum(mABs)
for pab in sorted(pABs, reverse=True):
if t >= 0:
break
ans += 1
t += pab
print(ans) | 20 | 16 | 446 | 417 | n = int(eval(input()))
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
ABs = sorted([a - b for a, b in zip(As, Bs)])
# print(As, Bs, ABs)
if sum(As) < sum(Bs):
print((-1))
exit()
if min(ABs) > 0:
print((-1))
exit()
mABs = [ab for ab in ABs if ab < 0]
msum, ans = sum(mABs), len(mABs)
# print(mABs, msum, ans)
now = -1
while msum < 0:
msum += ABs[now]
ans += 1
now -= 1
print(ans)
| n = int(eval(input()))
As = [int(i) for i in input().split()]
Bs = [int(i) for i in input().split()]
ABs = [a - b for a, b in zip(As, Bs)]
if sum(As) < sum(Bs) or min(ABs) > 0:
print((-1))
exit()
mABs = [ab for ab in ABs if ab < 0]
pABs = [ab for ab in ABs if ab > 0]
ans, t = len(mABs), sum(mABs)
for pab in sorted(pABs, reverse=True):
if t >= 0:
break
ans += 1
t += pab
print(ans)
| false | 20 | [
"-ABs = sorted([a - b for a, b in zip(As, Bs)])",
"-# print(As, Bs, ABs)",
"-if sum(As) < sum(Bs):",
"- print((-1))",
"- exit()",
"-if min(ABs) > 0:",
"+ABs = [a - b for a, b in zip(As, Bs)]",
"+if sum(As) < sum(Bs) or min(ABs) > 0:",
"-msum, ans = sum(mABs), len(mABs)",
"-# print(mABs, msum, ans)",
"-now = -1",
"-while msum < 0:",
"- msum += ABs[now]",
"+pABs = [ab for ab in ABs if ab > 0]",
"+ans, t = len(mABs), sum(mABs)",
"+for pab in sorted(pABs, reverse=True):",
"+ if t >= 0:",
"+ break",
"- now -= 1",
"+ t += pab"
] | false | 0.035609 | 0.03556 | 1.001387 | [
"s799605597",
"s479862069"
] |
u630511239 | p03325 | python | s745101213 | s468562431 | 135 | 80 | 4,148 | 4,148 | Accepted | Accepted | 40.74 | N = int(eval(input()))
A = list(map(int, input().split()))
import math
ans = 0
for i in range(N):
a = A[i]
b = int(math.log2(a))+1
for j in range(b):
if a % 2 == 0:
ans += 1
a = a/2
else:
break
print(ans)
| N = int(eval(input()))
ans = 0
A = list(map(int, input().split()))
for i in range(N):
a = A[i]
while a%2 == 0:
ans += 1
a = a//2
print(ans) | 17 | 9 | 263 | 153 | N = int(eval(input()))
A = list(map(int, input().split()))
import math
ans = 0
for i in range(N):
a = A[i]
b = int(math.log2(a)) + 1
for j in range(b):
if a % 2 == 0:
ans += 1
a = a / 2
else:
break
print(ans)
| N = int(eval(input()))
ans = 0
A = list(map(int, input().split()))
for i in range(N):
a = A[i]
while a % 2 == 0:
ans += 1
a = a // 2
print(ans)
| false | 47.058824 | [
"+ans = 0",
"-import math",
"-",
"-ans = 0",
"- b = int(math.log2(a)) + 1",
"- for j in range(b):",
"- if a % 2 == 0:",
"- ans += 1",
"- a = a / 2",
"- else:",
"- break",
"+ while a % 2 == 0:",
"+ ans += 1",
"+ a = a // 2"
] | false | 0.041623 | 0.036231 | 1.148827 | [
"s745101213",
"s468562431"
] |
u124735330 | p02936 | python | s460383476 | s926592202 | 1,616 | 986 | 86,352 | 86,332 | Accepted | Accepted | 38.99 | from collections import deque
def main():
N, Q = list(map(int, input().split()))
edge = [[] for i in range(N)]
ops = []
ans = [0] * N
for _ in range(N - 1):
a, b = list(map(int, input().split()))
edge[a - 1].append(b - 1)
edge[b - 1].append(a - 1)
for _ in range(Q):
ops.append(tuple(map(int, input().split())))
for op in ops:
node = op[0] - 1
pnt = op[1]
ans[node] += pnt
stack = deque()
stack.append((0, -1))
while stack:
st = stack.pop()
node, parent = st[0], st[1]
children = edge[node]
for child in children:
if child == parent:
continue
ans[child] += ans[node]
stack.append((child, node))
print((*ans))
if __name__ == '__main__':
main()
| import sys
from collections import deque
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline
def main():
N, Q = list(map(int, input().split()))
edge = [[] for i in range(N)]
ops = []
ans = [0] * N
for _ in range(N - 1):
a, b = list(map(int, input().split()))
edge[a - 1].append(b - 1)
edge[b - 1].append(a - 1)
for _ in range(Q):
ops.append(tuple(map(int, input().split())))
for op in ops:
node = op[0] - 1
pnt = op[1]
ans[node] += pnt
stack = deque()
stack.append((0, -1))
while stack:
st = stack.pop()
node, parent = st[0], st[1]
children = edge[node]
for child in children:
if child == parent:
continue
ans[child] += ans[node]
stack.append((child, node))
print((*ans))
if __name__ == '__main__':
main()
| 39 | 42 | 884 | 936 | from collections import deque
def main():
N, Q = list(map(int, input().split()))
edge = [[] for i in range(N)]
ops = []
ans = [0] * N
for _ in range(N - 1):
a, b = list(map(int, input().split()))
edge[a - 1].append(b - 1)
edge[b - 1].append(a - 1)
for _ in range(Q):
ops.append(tuple(map(int, input().split())))
for op in ops:
node = op[0] - 1
pnt = op[1]
ans[node] += pnt
stack = deque()
stack.append((0, -1))
while stack:
st = stack.pop()
node, parent = st[0], st[1]
children = edge[node]
for child in children:
if child == parent:
continue
ans[child] += ans[node]
stack.append((child, node))
print((*ans))
if __name__ == "__main__":
main()
| import sys
from collections import deque
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
def main():
N, Q = list(map(int, input().split()))
edge = [[] for i in range(N)]
ops = []
ans = [0] * N
for _ in range(N - 1):
a, b = list(map(int, input().split()))
edge[a - 1].append(b - 1)
edge[b - 1].append(a - 1)
for _ in range(Q):
ops.append(tuple(map(int, input().split())))
for op in ops:
node = op[0] - 1
pnt = op[1]
ans[node] += pnt
stack = deque()
stack.append((0, -1))
while stack:
st = stack.pop()
node, parent = st[0], st[1]
children = edge[node]
for child in children:
if child == parent:
continue
ans[child] += ans[node]
stack.append((child, node))
print((*ans))
if __name__ == "__main__":
main()
| false | 7.142857 | [
"+import sys",
"+",
"+sys.setrecursionlimit(10**5)",
"+input = sys.stdin.readline"
] | false | 0.15389 | 0.083126 | 1.851286 | [
"s460383476",
"s926592202"
] |
u762420987 | p03624 | python | s976188791 | s417289916 | 21 | 19 | 3,956 | 3,188 | Accepted | Accepted | 9.52 | S = list(eval(input()))
alpha = [chr(ord('a') + i) for i in range(26)]
for char in alpha:
if char not in S:
print(char)
break
else:
print(None)
| S = set(eval(input()))
for a in "abcdefghijklmnopqrstuvwxyz":
if a not in S:
print(a)
break
else:
print("None")
| 8 | 7 | 169 | 136 | S = list(eval(input()))
alpha = [chr(ord("a") + i) for i in range(26)]
for char in alpha:
if char not in S:
print(char)
break
else:
print(None)
| S = set(eval(input()))
for a in "abcdefghijklmnopqrstuvwxyz":
if a not in S:
print(a)
break
else:
print("None")
| false | 12.5 | [
"-S = list(eval(input()))",
"-alpha = [chr(ord(\"a\") + i) for i in range(26)]",
"-for char in alpha:",
"- if char not in S:",
"- print(char)",
"+S = set(eval(input()))",
"+for a in \"abcdefghijklmnopqrstuvwxyz\":",
"+ if a not in S:",
"+ print(a)",
"- print(None)",
"+ print(\"None\")"
] | false | 0.039713 | 0.039493 | 1.005559 | [
"s976188791",
"s417289916"
] |
u330661451 | p02837 | python | s840680056 | s529378979 | 339 | 248 | 3,064 | 3,188 | Accepted | Accepted | 26.84 | n = int(eval(input()))
l = [[] for _ in range(n)]
for i in range(n):
a = int(eval(input()))
for j in range(a):
x,y = list(map(int,(input().split())))
l[i].append([x-1,y])
ans = 0
for i in range(1 << n):
h = []
for j in range(n):
h.append(i & 1 << j != 0)
b = True
for j in range(n):
if i & (1 << j) != 0:
for k in l[j]:
if (k[1] == 1) != h[k[0]]:
b = False
break
if not b:
break
if b:
x = 0
for j in range(n):
if i & 1 << j:
x += 1
ans = max(ans,x)
print(ans)
| n = int(eval(input()))
l = [[] for _ in range(n)]
for i in range(n):
a = int(eval(input()))
for j in range(a):
x,y = list(map(int,(input().split())))
l[i].append([x-1,y])
ans = 0
for i in range(1 << n):
h = []
for j in range(n):
h.append(i & 1 << j != 0)
b = True
for j in range(n):
if i & 1 << j:
for k in l[j]:
if (k[1] == 1) != h[k[0]]:
b = False
break
if not b:
break
if b:
ans = max(ans,h.count(True))
print(ans)
| 33 | 27 | 691 | 585 | n = int(eval(input()))
l = [[] for _ in range(n)]
for i in range(n):
a = int(eval(input()))
for j in range(a):
x, y = list(map(int, (input().split())))
l[i].append([x - 1, y])
ans = 0
for i in range(1 << n):
h = []
for j in range(n):
h.append(i & 1 << j != 0)
b = True
for j in range(n):
if i & (1 << j) != 0:
for k in l[j]:
if (k[1] == 1) != h[k[0]]:
b = False
break
if not b:
break
if b:
x = 0
for j in range(n):
if i & 1 << j:
x += 1
ans = max(ans, x)
print(ans)
| n = int(eval(input()))
l = [[] for _ in range(n)]
for i in range(n):
a = int(eval(input()))
for j in range(a):
x, y = list(map(int, (input().split())))
l[i].append([x - 1, y])
ans = 0
for i in range(1 << n):
h = []
for j in range(n):
h.append(i & 1 << j != 0)
b = True
for j in range(n):
if i & 1 << j:
for k in l[j]:
if (k[1] == 1) != h[k[0]]:
b = False
break
if not b:
break
if b:
ans = max(ans, h.count(True))
print(ans)
| false | 18.181818 | [
"- if i & (1 << j) != 0:",
"+ if i & 1 << j:",
"- x = 0",
"- for j in range(n):",
"- if i & 1 << j:",
"- x += 1",
"- ans = max(ans, x)",
"+ ans = max(ans, h.count(True))"
] | false | 0.034572 | 0.042086 | 0.821454 | [
"s840680056",
"s529378979"
] |
u994521204 | p02911 | python | s372316808 | s123305994 | 563 | 312 | 50,904 | 16,160 | Accepted | Accepted | 44.58 | n,k,q=list(map(int,input().split()))
ans=[-q]*n
for i in range(q):
a=int(eval(input()))
ans[a-1]+=1
for i in range(n):
print(('Yes' if k+ans[i]>0 else 'No')) | from collections import defaultdict
n, k, q = list(map(int, input().split()))
C = defaultdict(int)
for _ in range(q):
a = int(eval(input()))
C[a] += 1
for i in range(1, n + 1):
cnt = q - C[i]
if k - cnt > 0:
print("Yes")
else:
print("No")
| 7 | 13 | 161 | 276 | n, k, q = list(map(int, input().split()))
ans = [-q] * n
for i in range(q):
a = int(eval(input()))
ans[a - 1] += 1
for i in range(n):
print(("Yes" if k + ans[i] > 0 else "No"))
| from collections import defaultdict
n, k, q = list(map(int, input().split()))
C = defaultdict(int)
for _ in range(q):
a = int(eval(input()))
C[a] += 1
for i in range(1, n + 1):
cnt = q - C[i]
if k - cnt > 0:
print("Yes")
else:
print("No")
| false | 46.153846 | [
"+from collections import defaultdict",
"+",
"-ans = [-q] * n",
"-for i in range(q):",
"+C = defaultdict(int)",
"+for _ in range(q):",
"- ans[a - 1] += 1",
"-for i in range(n):",
"- print((\"Yes\" if k + ans[i] > 0 else \"No\"))",
"+ C[a] += 1",
"+for i in range(1, n + 1):",
"+ cnt = q - C[i]",
"+ if k - cnt > 0:",
"+ print(\"Yes\")",
"+ else:",
"+ print(\"No\")"
] | false | 0.036745 | 0.035936 | 1.022509 | [
"s372316808",
"s123305994"
] |
u972591645 | p02550 | python | s080262849 | s117146919 | 798 | 55 | 67,952 | 11,956 | Accepted | Accepted | 93.11 | n, x, m = list(map(int, input().split()))
ans = []
flag = False
for i in range(n):
if x in ans:
v = x
flag = True
break
ans.append(x)
x = x**2 % m
if flag:
p = ans.index(v)
l = len(ans) - p
d, e = divmod(n-p, l)
print((sum(ans[:p]) + d*sum(ans[p:]) + sum(ans[p:p+e])))
else:
print((sum(ans)))
| n, x, m = list(map(int, input().split()))
ans = []
c = [0]*m
flag = False
for i in range(n):
if c[x] == 1:
flag = True
break
ans.append(x)
c[x] = 1
x = x**2 % m
if flag:
p = ans.index(x)
l = len(ans) - p
d, e = divmod(n-p, l)
print((sum(ans[:p]) + d*sum(ans[p:]) + sum(ans[p:p+e])))
else:
print((sum(ans)))
| 18 | 19 | 357 | 368 | n, x, m = list(map(int, input().split()))
ans = []
flag = False
for i in range(n):
if x in ans:
v = x
flag = True
break
ans.append(x)
x = x**2 % m
if flag:
p = ans.index(v)
l = len(ans) - p
d, e = divmod(n - p, l)
print((sum(ans[:p]) + d * sum(ans[p:]) + sum(ans[p : p + e])))
else:
print((sum(ans)))
| n, x, m = list(map(int, input().split()))
ans = []
c = [0] * m
flag = False
for i in range(n):
if c[x] == 1:
flag = True
break
ans.append(x)
c[x] = 1
x = x**2 % m
if flag:
p = ans.index(x)
l = len(ans) - p
d, e = divmod(n - p, l)
print((sum(ans[:p]) + d * sum(ans[p:]) + sum(ans[p : p + e])))
else:
print((sum(ans)))
| false | 5.263158 | [
"+c = [0] * m",
"- if x in ans:",
"- v = x",
"+ if c[x] == 1:",
"+ c[x] = 1",
"- p = ans.index(v)",
"+ p = ans.index(x)"
] | false | 0.04264 | 0.03515 | 1.213069 | [
"s080262849",
"s117146919"
] |
u539692012 | p02690 | python | s158725475 | s983078037 | 34 | 30 | 9,120 | 9,044 | Accepted | Accepted | 11.76 | i=j=x=int(eval(input()))
while i**5-j**5-x:i=-~i%120;j=-~j%217-98
print((i,j)) | i=j=x=int(eval(input()))
while i**5-j**5-x:i=-~i%120;j=j%221-99
print((i,j)) | 3 | 3 | 72 | 70 | i = j = x = int(eval(input()))
while i**5 - j**5 - x:
i = -~i % 120
j = -~j % 217 - 98
print((i, j))
| i = j = x = int(eval(input()))
while i**5 - j**5 - x:
i = -~i % 120
j = j % 221 - 99
print((i, j))
| false | 0 | [
"- j = -~j % 217 - 98",
"+ j = j % 221 - 99"
] | false | 0.051184 | 0.059698 | 0.857378 | [
"s158725475",
"s983078037"
] |
u226155577 | p03062 | python | s715991687 | s992690428 | 254 | 114 | 76,192 | 14,084 | Accepted | Accepted | 55.12 | N = int(eval(input()))
*A, = list(map(int, input().split()))
dp = [[0, 0] for i in range(N+1)]
dp[0][1] = -10**18
for i in range(N):
dp[i+1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i])
dp[i+1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i])
print((dp[-1][0])) | N, *A = list(map(int, open(0).read().split()))
p = 0; q = -10**18
for a in A:
p, q = max(p + a, q - a), max(p - a, q + a)
print(p) | 9 | 6 | 256 | 134 | N = int(eval(input()))
(*A,) = list(map(int, input().split()))
dp = [[0, 0] for i in range(N + 1)]
dp[0][1] = -(10**18)
for i in range(N):
dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i])
dp[i + 1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i])
print((dp[-1][0]))
| N, *A = list(map(int, open(0).read().split()))
p = 0
q = -(10**18)
for a in A:
p, q = max(p + a, q - a), max(p - a, q + a)
print(p)
| false | 33.333333 | [
"-N = int(eval(input()))",
"-(*A,) = list(map(int, input().split()))",
"-dp = [[0, 0] for i in range(N + 1)]",
"-dp[0][1] = -(10**18)",
"-for i in range(N):",
"- dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i])",
"- dp[i + 1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i])",
"-print((dp[-1][0]))",
"+N, *A = list(map(int, open(0).read().split()))",
"+p = 0",
"+q = -(10**18)",
"+for a in A:",
"+ p, q = max(p + a, q - a), max(p - a, q + a)",
"+print(p)"
] | false | 0.05491 | 0.069176 | 0.793782 | [
"s715991687",
"s992690428"
] |
u790710233 | p02803 | python | s394163398 | s474489666 | 1,332 | 311 | 4,080 | 3,316 | Accepted | Accepted | 76.65 | from queue import Queue
h, w = list(map(int, input().split()))
MAZE = ['#'*(w+2)]
for _ in range(h):
MAZE.append("#"+eval(input())+"#")
else:
MAZE.append('#'*(w+2))
INF = 10**3
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]
def bfs(init_x, init_y):
dist = [[INF]*(w+2) for _ in range(h+2)]
q = Queue()
q.put((init_x, init_y))
dist[init_x][init_y] = 0
MAX = 0
while not q.empty():
x, y = q.get()
for i, j in directions:
if MAZE[x+i][y+j] == '#':
continue
if dist[x+i][y+j] <= dist[x][y]+1:
continue
dist[x+i][y+j] = dist[x][y]+1
q.put((x+i, y+j))
MAX = max(MAX, dist[x][y])
return MAX
ans = 0
for i in range(1, h+1):
for j in range(1, w+1):
if MAZE[i][j] == '#':
continue
ans = max(ans, bfs(i, j))
print(ans)
| from collections import deque
h, w = list(map(int, input().split()))
MAZE = ['#'*(w+2)]
for _ in range(h):
MAZE.append("#"+eval(input())+"#")
else:
MAZE.append('#'*(w+2))
INF = 10**3
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]
def bfs(init_x, init_y):
dist = [[INF]*(w+2) for _ in range(h+2)]
q = deque([(init_x, init_y)])
dist[init_x][init_y] = 0
MAX = 0
while q:
x, y = q.popleft()
for i, j in directions:
if MAZE[x+i][y+j] == '#':
continue
if dist[x+i][y+j] <= dist[x][y]+1:
continue
dist[x+i][y+j] = dist[x][y]+1
q.append((x+i, y+j))
MAX = max(MAX, dist[x][y])
return MAX
ans = 0
for i in range(1, h+1):
for j in range(1, w+1):
if MAZE[i][j] == '#':
continue
ans = max(ans, bfs(i, j))
print(ans)
| 38 | 38 | 911 | 903 | from queue import Queue
h, w = list(map(int, input().split()))
MAZE = ["#" * (w + 2)]
for _ in range(h):
MAZE.append("#" + eval(input()) + "#")
else:
MAZE.append("#" * (w + 2))
INF = 10**3
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]
def bfs(init_x, init_y):
dist = [[INF] * (w + 2) for _ in range(h + 2)]
q = Queue()
q.put((init_x, init_y))
dist[init_x][init_y] = 0
MAX = 0
while not q.empty():
x, y = q.get()
for i, j in directions:
if MAZE[x + i][y + j] == "#":
continue
if dist[x + i][y + j] <= dist[x][y] + 1:
continue
dist[x + i][y + j] = dist[x][y] + 1
q.put((x + i, y + j))
MAX = max(MAX, dist[x][y])
return MAX
ans = 0
for i in range(1, h + 1):
for j in range(1, w + 1):
if MAZE[i][j] == "#":
continue
ans = max(ans, bfs(i, j))
print(ans)
| from collections import deque
h, w = list(map(int, input().split()))
MAZE = ["#" * (w + 2)]
for _ in range(h):
MAZE.append("#" + eval(input()) + "#")
else:
MAZE.append("#" * (w + 2))
INF = 10**3
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]
def bfs(init_x, init_y):
dist = [[INF] * (w + 2) for _ in range(h + 2)]
q = deque([(init_x, init_y)])
dist[init_x][init_y] = 0
MAX = 0
while q:
x, y = q.popleft()
for i, j in directions:
if MAZE[x + i][y + j] == "#":
continue
if dist[x + i][y + j] <= dist[x][y] + 1:
continue
dist[x + i][y + j] = dist[x][y] + 1
q.append((x + i, y + j))
MAX = max(MAX, dist[x][y])
return MAX
ans = 0
for i in range(1, h + 1):
for j in range(1, w + 1):
if MAZE[i][j] == "#":
continue
ans = max(ans, bfs(i, j))
print(ans)
| false | 0 | [
"-from queue import Queue",
"+from collections import deque",
"- q = Queue()",
"- q.put((init_x, init_y))",
"+ q = deque([(init_x, init_y)])",
"- while not q.empty():",
"- x, y = q.get()",
"+ while q:",
"+ x, y = q.popleft()",
"- q.put((x + i, y + j))",
"+ q.append((x + i, y + j))"
] | false | 0.083027 | 0.036594 | 2.268851 | [
"s394163398",
"s474489666"
] |
u459150945 | p02814 | python | s104037085 | s845247957 | 1,166 | 245 | 24,216 | 16,312 | Accepted | Accepted | 78.99 | import fractions
from functools import reduce
import numpy as np
import sys
N, M = list(map(int, input().split()))
an = list(map(int, input().split()))
def lcm_base(x, y):
return (x * y) // fractions.gcd(x, y)
def gcd_list(numbers):
return reduce(fractions.gcd, numbers)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def lcm(*numbers):
return reduce(lcm_base, numbers, 1)
def listdivide(list):
numpy = np.array(list)
numpy = numpy//2
return numpy.tolist()
def divide2(x):
res = 0
while x % 2 == 0:
x /= 2
res += 1
return res
# while gcd_list(an) % 2 == 0:
# print(gcd_list(an))
an = listdivide(an)
t = divide2(an[0])
for i in range(1, N):
if divide2(an[i]) != t:
print((0))
sys.exit()
for i in range(t):
an = listdivide(an)
M = M // 2
LCM = lcm_list(an)
if LCM > M == 0:
print((0))
else:
print((-(-(M // LCM)//2)))
| import sys
from fractions import gcd
N, M = list(map(int, input().split()))
an = list([int(x)//2 for x in input().split()])
lcm = an[0]
for a in an[1:]:
l = lcm*a//gcd(lcm, a)
if not (l//lcm % 2 == l//a % 2):
print((0))
sys.exit()
lcm = l
print(((M//lcm+1)//2)) | 59 | 13 | 989 | 297 | import fractions
from functools import reduce
import numpy as np
import sys
N, M = list(map(int, input().split()))
an = list(map(int, input().split()))
def lcm_base(x, y):
return (x * y) // fractions.gcd(x, y)
def gcd_list(numbers):
return reduce(fractions.gcd, numbers)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def lcm(*numbers):
return reduce(lcm_base, numbers, 1)
def listdivide(list):
numpy = np.array(list)
numpy = numpy // 2
return numpy.tolist()
def divide2(x):
res = 0
while x % 2 == 0:
x /= 2
res += 1
return res
# while gcd_list(an) % 2 == 0:
# print(gcd_list(an))
an = listdivide(an)
t = divide2(an[0])
for i in range(1, N):
if divide2(an[i]) != t:
print((0))
sys.exit()
for i in range(t):
an = listdivide(an)
M = M // 2
LCM = lcm_list(an)
if LCM > M == 0:
print((0))
else:
print((-(-(M // LCM) // 2)))
| import sys
from fractions import gcd
N, M = list(map(int, input().split()))
an = list([int(x) // 2 for x in input().split()])
lcm = an[0]
for a in an[1:]:
l = lcm * a // gcd(lcm, a)
if not (l // lcm % 2 == l // a % 2):
print((0))
sys.exit()
lcm = l
print(((M // lcm + 1) // 2))
| false | 77.966102 | [
"-import fractions",
"-from functools import reduce",
"-import numpy as np",
"+from fractions import gcd",
"-an = list(map(int, input().split()))",
"-",
"-",
"-def lcm_base(x, y):",
"- return (x * y) // fractions.gcd(x, y)",
"-",
"-",
"-def gcd_list(numbers):",
"- return reduce(fractions.gcd, numbers)",
"-",
"-",
"-def lcm_list(numbers):",
"- return reduce(lcm_base, numbers, 1)",
"-",
"-",
"-def lcm(*numbers):",
"- return reduce(lcm_base, numbers, 1)",
"-",
"-",
"-def listdivide(list):",
"- numpy = np.array(list)",
"- numpy = numpy // 2",
"- return numpy.tolist()",
"-",
"-",
"-def divide2(x):",
"- res = 0",
"- while x % 2 == 0:",
"- x /= 2",
"- res += 1",
"- return res",
"-",
"-",
"-# while gcd_list(an) % 2 == 0:",
"-# print(gcd_list(an))",
"-an = listdivide(an)",
"-t = divide2(an[0])",
"-for i in range(1, N):",
"- if divide2(an[i]) != t:",
"+an = list([int(x) // 2 for x in input().split()])",
"+lcm = an[0]",
"+for a in an[1:]:",
"+ l = lcm * a // gcd(lcm, a)",
"+ if not (l // lcm % 2 == l // a % 2):",
"-for i in range(t):",
"- an = listdivide(an)",
"- M = M // 2",
"-LCM = lcm_list(an)",
"-if LCM > M == 0:",
"- print((0))",
"-else:",
"- print((-(-(M // LCM) // 2)))",
"+ lcm = l",
"+print(((M // lcm + 1) // 2))"
] | false | 0.149096 | 0.051034 | 2.92148 | [
"s104037085",
"s845247957"
] |
u124735330 | p02936 | python | s416769952 | s460383476 | 1,860 | 1,616 | 86,392 | 86,352 | Accepted | Accepted | 13.12 | from collections import deque
N, Q = list(map(int, input().split()))
edge = [[] for i in range(N)]
ops = []
ans = [0] * N
for _ in range(N - 1):
a, b = list(map(int, input().split()))
edge[a - 1].append(b - 1)
edge[b - 1].append(a - 1)
for _ in range(Q):
ops.append(tuple(map(int, input().split())))
for op in ops:
node = op[0] - 1
pnt = op[1]
ans[node] += pnt
stack = deque()
stack.append((0, -1))
while stack:
st = stack.pop()
node, parent = st[0], st[1]
children = edge[node]
for child in children:
if child == parent:
continue
ans[child] += ans[node]
stack.append((child, node))
print((*ans)) | from collections import deque
def main():
N, Q = list(map(int, input().split()))
edge = [[] for i in range(N)]
ops = []
ans = [0] * N
for _ in range(N - 1):
a, b = list(map(int, input().split()))
edge[a - 1].append(b - 1)
edge[b - 1].append(a - 1)
for _ in range(Q):
ops.append(tuple(map(int, input().split())))
for op in ops:
node = op[0] - 1
pnt = op[1]
ans[node] += pnt
stack = deque()
stack.append((0, -1))
while stack:
st = stack.pop()
node, parent = st[0], st[1]
children = edge[node]
for child in children:
if child == parent:
continue
ans[child] += ans[node]
stack.append((child, node))
print((*ans))
if __name__ == '__main__':
main()
| 33 | 39 | 700 | 884 | from collections import deque
N, Q = list(map(int, input().split()))
edge = [[] for i in range(N)]
ops = []
ans = [0] * N
for _ in range(N - 1):
a, b = list(map(int, input().split()))
edge[a - 1].append(b - 1)
edge[b - 1].append(a - 1)
for _ in range(Q):
ops.append(tuple(map(int, input().split())))
for op in ops:
node = op[0] - 1
pnt = op[1]
ans[node] += pnt
stack = deque()
stack.append((0, -1))
while stack:
st = stack.pop()
node, parent = st[0], st[1]
children = edge[node]
for child in children:
if child == parent:
continue
ans[child] += ans[node]
stack.append((child, node))
print((*ans))
| from collections import deque
def main():
N, Q = list(map(int, input().split()))
edge = [[] for i in range(N)]
ops = []
ans = [0] * N
for _ in range(N - 1):
a, b = list(map(int, input().split()))
edge[a - 1].append(b - 1)
edge[b - 1].append(a - 1)
for _ in range(Q):
ops.append(tuple(map(int, input().split())))
for op in ops:
node = op[0] - 1
pnt = op[1]
ans[node] += pnt
stack = deque()
stack.append((0, -1))
while stack:
st = stack.pop()
node, parent = st[0], st[1]
children = edge[node]
for child in children:
if child == parent:
continue
ans[child] += ans[node]
stack.append((child, node))
print((*ans))
if __name__ == "__main__":
main()
| false | 15.384615 | [
"-N, Q = list(map(int, input().split()))",
"-edge = [[] for i in range(N)]",
"-ops = []",
"-ans = [0] * N",
"-for _ in range(N - 1):",
"- a, b = list(map(int, input().split()))",
"- edge[a - 1].append(b - 1)",
"- edge[b - 1].append(a - 1)",
"-for _ in range(Q):",
"- ops.append(tuple(map(int, input().split())))",
"-for op in ops:",
"- node = op[0] - 1",
"- pnt = op[1]",
"- ans[node] += pnt",
"-stack = deque()",
"-stack.append((0, -1))",
"-while stack:",
"- st = stack.pop()",
"- node, parent = st[0], st[1]",
"- children = edge[node]",
"- for child in children:",
"- if child == parent:",
"- continue",
"- ans[child] += ans[node]",
"- stack.append((child, node))",
"-print((*ans))",
"+",
"+def main():",
"+ N, Q = list(map(int, input().split()))",
"+ edge = [[] for i in range(N)]",
"+ ops = []",
"+ ans = [0] * N",
"+ for _ in range(N - 1):",
"+ a, b = list(map(int, input().split()))",
"+ edge[a - 1].append(b - 1)",
"+ edge[b - 1].append(a - 1)",
"+ for _ in range(Q):",
"+ ops.append(tuple(map(int, input().split())))",
"+ for op in ops:",
"+ node = op[0] - 1",
"+ pnt = op[1]",
"+ ans[node] += pnt",
"+ stack = deque()",
"+ stack.append((0, -1))",
"+ while stack:",
"+ st = stack.pop()",
"+ node, parent = st[0], st[1]",
"+ children = edge[node]",
"+ for child in children:",
"+ if child == parent:",
"+ continue",
"+ ans[child] += ans[node]",
"+ stack.append((child, node))",
"+ print((*ans))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.041301 | 0.15389 | 0.268378 | [
"s416769952",
"s460383476"
] |
u320567105 | p03126 | python | s338248649 | s832614668 | 26 | 18 | 3,444 | 3,060 | Accepted | Accepted | 30.77 | N, M = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
A = [flatten for inner in A for flatten in inner[1:]]
#print(A)
import collections
A_cnt = collections.Counter(A)
print((sum([l[1]==N for l in A_cnt.most_common()])))
| N,M = list(map(int,input().split()))
_, *A = list(map(int,input().split()))
s = set(A)
for i in range(N-1):
_, *B = list(map(int,input().split()))
s &= set(B)
print((len(s))) | 8 | 7 | 262 | 168 | N, M = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
A = [flatten for inner in A for flatten in inner[1:]]
# print(A)
import collections
A_cnt = collections.Counter(A)
print((sum([l[1] == N for l in A_cnt.most_common()])))
| N, M = list(map(int, input().split()))
_, *A = list(map(int, input().split()))
s = set(A)
for i in range(N - 1):
_, *B = list(map(int, input().split()))
s &= set(B)
print((len(s)))
| false | 12.5 | [
"-A = [list(map(int, input().split())) for _ in range(N)]",
"-A = [flatten for inner in A for flatten in inner[1:]]",
"-# print(A)",
"-import collections",
"-",
"-A_cnt = collections.Counter(A)",
"-print((sum([l[1] == N for l in A_cnt.most_common()])))",
"+_, *A = list(map(int, input().split()))",
"+s = set(A)",
"+for i in range(N - 1):",
"+ _, *B = list(map(int, input().split()))",
"+ s &= set(B)",
"+print((len(s)))"
] | false | 0.036669 | 0.043811 | 0.836988 | [
"s338248649",
"s832614668"
] |
u392319141 | p02925 | python | s312732513 | s122542524 | 1,969 | 1,192 | 154,196 | 36,076 | Accepted | Accepted | 39.46 | from collections import deque, defaultdict
N = int(eval(input()))
A = [deque([int(a) - 1 for a in input().split()]) for _ in range(N)]
D = [0] * N
canBattle = defaultdict(lambda: False)
que = deque(list(range(N)))
while que:
i = que.popleft()
j = A[i].popleft()
canBattle[(i, j)] = True
if canBattle[(j, i)]:
day = max(D[i], D[j])
D[i] = D[j] = day + 1
if A[i]:
que.append(i)
if A[j]:
que.append(j)
if all(len(a) == 0 for a in A):
print((max(D)))
else:
print((-1))
| from collections import deque, defaultdict
N = int(eval(input()))
A = [deque([int(a) - 1 for a in input().split()]) for _ in range(N)]
D = [0] * N
Nx = [-1] * N
que = deque(list(range(N)))
while que:
i = que.popleft()
j = A[i].popleft()
Nx[i] = j
if Nx[j] == i:
day = max(D[i], D[j])
D[i] = D[j] = day + 1
if A[i]:
que.append(i)
if A[j]:
que.append(j)
if all(len(a) == 0 for a in A):
print((max(D)))
else:
print((-1))
| 27 | 27 | 566 | 519 | from collections import deque, defaultdict
N = int(eval(input()))
A = [deque([int(a) - 1 for a in input().split()]) for _ in range(N)]
D = [0] * N
canBattle = defaultdict(lambda: False)
que = deque(list(range(N)))
while que:
i = que.popleft()
j = A[i].popleft()
canBattle[(i, j)] = True
if canBattle[(j, i)]:
day = max(D[i], D[j])
D[i] = D[j] = day + 1
if A[i]:
que.append(i)
if A[j]:
que.append(j)
if all(len(a) == 0 for a in A):
print((max(D)))
else:
print((-1))
| from collections import deque, defaultdict
N = int(eval(input()))
A = [deque([int(a) - 1 for a in input().split()]) for _ in range(N)]
D = [0] * N
Nx = [-1] * N
que = deque(list(range(N)))
while que:
i = que.popleft()
j = A[i].popleft()
Nx[i] = j
if Nx[j] == i:
day = max(D[i], D[j])
D[i] = D[j] = day + 1
if A[i]:
que.append(i)
if A[j]:
que.append(j)
if all(len(a) == 0 for a in A):
print((max(D)))
else:
print((-1))
| false | 0 | [
"-canBattle = defaultdict(lambda: False)",
"+Nx = [-1] * N",
"- canBattle[(i, j)] = True",
"- if canBattle[(j, i)]:",
"+ Nx[i] = j",
"+ if Nx[j] == i:"
] | false | 0.106343 | 0.039487 | 2.693128 | [
"s312732513",
"s122542524"
] |
u021548497 | p02580 | python | s846426121 | s304880018 | 722 | 519 | 194,824 | 53,932 | Accepted | Accepted | 28.12 | import sys
from copy import deepcopy as copy
input = sys.stdin.readline
def main():
h, w, m = list(map(int, input().split()))
bomb_h = [0]*h
bomb_w = [0]*w
bomb_w_place = [set() for _ in range(w)]
for i in range(m):
x, y = list(map(int, input().split()))
bomb_h[x-1] += 1
bomb_w[y-1] += 1
bomb_w_place[y-1].add(x-1)
bomb_h2 = [0]*h
for i in range(h):
bomb_h2[i] = [bomb_h[i], i]
bomb_h2.sort(reverse=True)
ans = 0
for i in range(w):
index = 0
key = bomb_w[i]
k1, k2 = True, True
ma = -1
while index < len(bomb_h2):
key2 = bomb_h2[index]
if key2[1] in bomb_w_place[i]:
if ma == -1:
ma = key2[0]-1
index += 1
continue
elif ma == key2[0]-1:
index += 1
continue
else:
break
else:
ma = max(ma, key2[0])
break
index += 1
ans = max(ans, key+ma)
print(ans)
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
h, w, m = list(map(int, input().split()))
bomb = [tuple(map(int, input().split())) for _ in range(m)]
bom_h = [0]*h
bom_w = [0]*w
for i in range(m):
x, y = bomb[i]
bom_h[x-1] += 1
bom_w[y-1] += 1
max_h = max(bom_h)
max_w = max(bom_w)
ans = bom_h.count(max_h)*bom_w.count(max_w)
for i in range(m):
x, y = bomb[i]
if bom_h[x-1] == max_h and bom_w[y-1] == max_w:
ans -= 1
print((max_h+max_w+bool(ans)-1))
if __name__ == "__main__":
main()
| 52 | 32 | 1,247 | 648 | import sys
from copy import deepcopy as copy
input = sys.stdin.readline
def main():
h, w, m = list(map(int, input().split()))
bomb_h = [0] * h
bomb_w = [0] * w
bomb_w_place = [set() for _ in range(w)]
for i in range(m):
x, y = list(map(int, input().split()))
bomb_h[x - 1] += 1
bomb_w[y - 1] += 1
bomb_w_place[y - 1].add(x - 1)
bomb_h2 = [0] * h
for i in range(h):
bomb_h2[i] = [bomb_h[i], i]
bomb_h2.sort(reverse=True)
ans = 0
for i in range(w):
index = 0
key = bomb_w[i]
k1, k2 = True, True
ma = -1
while index < len(bomb_h2):
key2 = bomb_h2[index]
if key2[1] in bomb_w_place[i]:
if ma == -1:
ma = key2[0] - 1
index += 1
continue
elif ma == key2[0] - 1:
index += 1
continue
else:
break
else:
ma = max(ma, key2[0])
break
index += 1
ans = max(ans, key + ma)
print(ans)
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
h, w, m = list(map(int, input().split()))
bomb = [tuple(map(int, input().split())) for _ in range(m)]
bom_h = [0] * h
bom_w = [0] * w
for i in range(m):
x, y = bomb[i]
bom_h[x - 1] += 1
bom_w[y - 1] += 1
max_h = max(bom_h)
max_w = max(bom_w)
ans = bom_h.count(max_h) * bom_w.count(max_w)
for i in range(m):
x, y = bomb[i]
if bom_h[x - 1] == max_h and bom_w[y - 1] == max_w:
ans -= 1
print((max_h + max_w + bool(ans) - 1))
if __name__ == "__main__":
main()
| false | 38.461538 | [
"-from copy import deepcopy as copy",
"- bomb_h = [0] * h",
"- bomb_w = [0] * w",
"- bomb_w_place = [set() for _ in range(w)]",
"+ bomb = [tuple(map(int, input().split())) for _ in range(m)]",
"+ bom_h = [0] * h",
"+ bom_w = [0] * w",
"- x, y = list(map(int, input().split()))",
"- bomb_h[x - 1] += 1",
"- bomb_w[y - 1] += 1",
"- bomb_w_place[y - 1].add(x - 1)",
"- bomb_h2 = [0] * h",
"- for i in range(h):",
"- bomb_h2[i] = [bomb_h[i], i]",
"- bomb_h2.sort(reverse=True)",
"- ans = 0",
"- for i in range(w):",
"- index = 0",
"- key = bomb_w[i]",
"- k1, k2 = True, True",
"- ma = -1",
"- while index < len(bomb_h2):",
"- key2 = bomb_h2[index]",
"- if key2[1] in bomb_w_place[i]:",
"- if ma == -1:",
"- ma = key2[0] - 1",
"- index += 1",
"- continue",
"- elif ma == key2[0] - 1:",
"- index += 1",
"- continue",
"- else:",
"- break",
"- else:",
"- ma = max(ma, key2[0])",
"- break",
"- index += 1",
"- ans = max(ans, key + ma)",
"- print(ans)",
"+ x, y = bomb[i]",
"+ bom_h[x - 1] += 1",
"+ bom_w[y - 1] += 1",
"+ max_h = max(bom_h)",
"+ max_w = max(bom_w)",
"+ ans = bom_h.count(max_h) * bom_w.count(max_w)",
"+ for i in range(m):",
"+ x, y = bomb[i]",
"+ if bom_h[x - 1] == max_h and bom_w[y - 1] == max_w:",
"+ ans -= 1",
"+ print((max_h + max_w + bool(ans) - 1))"
] | false | 0.106909 | 0.101305 | 1.055323 | [
"s846426121",
"s304880018"
] |
u951289777 | p04045 | python | s428499330 | s247495655 | 126 | 63 | 2,940 | 2,940 | Accepted | Accepted | 50 | amount, num = list(map(int, input().split()))
hate_num_list = list(map(str, input().split()))
while(True):
check = 0
for digit in str(amount):
if digit in hate_num_list:
check += 1
if check == 0:
print(amount)
break
else:
amount += 1 | amount, num = list(map(int, input().split()))
hated_digit = list(map(str, input().split()))
while True:
check = 0
for hd in hated_digit:
if hd not in str(amount):
check += 1
else:
amount += 1
if check == num:
print(amount)
break | 19 | 16 | 312 | 309 | amount, num = list(map(int, input().split()))
hate_num_list = list(map(str, input().split()))
while True:
check = 0
for digit in str(amount):
if digit in hate_num_list:
check += 1
if check == 0:
print(amount)
break
else:
amount += 1
| amount, num = list(map(int, input().split()))
hated_digit = list(map(str, input().split()))
while True:
check = 0
for hd in hated_digit:
if hd not in str(amount):
check += 1
else:
amount += 1
if check == num:
print(amount)
break
| false | 15.789474 | [
"-hate_num_list = list(map(str, input().split()))",
"+hated_digit = list(map(str, input().split()))",
"- for digit in str(amount):",
"- if digit in hate_num_list:",
"+ for hd in hated_digit:",
"+ if hd not in str(amount):",
"- if check == 0:",
"+ else:",
"+ amount += 1",
"+ if check == num:",
"- else:",
"- amount += 1"
] | false | 0.041354 | 0.042154 | 0.981007 | [
"s428499330",
"s247495655"
] |
u879870653 | p03048 | python | s753795811 | s914833692 | 259 | 222 | 41,324 | 40,944 | Accepted | Accepted | 14.29 | R,G,B,N = list(map(int,input().split()))
ans = 0
for r in range(N+1) :
for g in range(N+1) :
if (N - (r*R + g*G)) < 0 : continue
if (N - (r*R + g*G)) % B == 0 :
ans += 1
#print(r,g)
print(ans)
| R,G,B,N = list(map(int,input().split()))
ans = 0
for r in range(N//R + 1) :
for g in range((N-r)//G + 1) :
calc = r*R + g*G
if (N-calc) < 0 :
break
if (N-calc) % B == 0 :
ans += 1
print(ans)
| 14 | 14 | 260 | 270 | R, G, B, N = list(map(int, input().split()))
ans = 0
for r in range(N + 1):
for g in range(N + 1):
if (N - (r * R + g * G)) < 0:
continue
if (N - (r * R + g * G)) % B == 0:
ans += 1
# print(r,g)
print(ans)
| R, G, B, N = list(map(int, input().split()))
ans = 0
for r in range(N // R + 1):
for g in range((N - r) // G + 1):
calc = r * R + g * G
if (N - calc) < 0:
break
if (N - calc) % B == 0:
ans += 1
print(ans)
| false | 0 | [
"-for r in range(N + 1):",
"- for g in range(N + 1):",
"- if (N - (r * R + g * G)) < 0:",
"- continue",
"- if (N - (r * R + g * G)) % B == 0:",
"+for r in range(N // R + 1):",
"+ for g in range((N - r) // G + 1):",
"+ calc = r * R + g * G",
"+ if (N - calc) < 0:",
"+ break",
"+ if (N - calc) % B == 0:",
"- # print(r,g)"
] | false | 1.010593 | 0.083933 | 12.040509 | [
"s753795811",
"s914833692"
] |
u571345655 | p02406 | python | s977453385 | s033654449 | 30 | 20 | 4,260 | 4,528 | Accepted | Accepted | 33.33 | # coding=utf-8
def main():
def sub():
n = eval(input())
i = 1
s = ''
# ---------------------------------------------------------------------
# CHECK_NUM
while True:
x = i
if x % 3 == 0:
s += ' '+str(i)
# -----------------------
# END_CHECK_NUM
i += 1
if i <= n:
# goto CHECK_NUM
continue
else:
# END!!
break
# -----------------------
# -----------------------------------------------------
# INCLUDE3
while True:
if x % 10 == 3:
s += ' '+str(i)
# -----------------------
# END_CHECK_NUM
i += 1
if i <= n:
# goto INCLUDE3
break
else:
# END!!
return s
# -----------------------
else:
x /= 10
if x:
# goto INCLUDE3
continue
else:
# -----------------------
# END_CHECK_NUM
i += 1
if i <= n:
# goto CHECK_NUM
break
else:
# END!!
return s
# -----------------------
# -----------------------------------------------------
# ---------------------------------------------------------------------
return s
print(sub())
if __name__ == '__main__':
main() | # coding=utf-8
def main():
n = eval(input())
s = ''
for i in range(1, n + 1):
x = i
if x % 3 == 0:
s += ' ' + str(i)
continue
while x:
if x % 10 == 3:
s += ' ' + str(i)
break
x /= 10
print(s)
if __name__ == '__main__':
main() | 62 | 20 | 1,971 | 368 | # coding=utf-8
def main():
def sub():
n = eval(input())
i = 1
s = ""
# ---------------------------------------------------------------------
# CHECK_NUM
while True:
x = i
if x % 3 == 0:
s += " " + str(i)
# -----------------------
# END_CHECK_NUM
i += 1
if i <= n:
# goto CHECK_NUM
continue
else:
# END!!
break
# -----------------------
# -----------------------------------------------------
# INCLUDE3
while True:
if x % 10 == 3:
s += " " + str(i)
# -----------------------
# END_CHECK_NUM
i += 1
if i <= n:
# goto INCLUDE3
break
else:
# END!!
return s
# -----------------------
else:
x /= 10
if x:
# goto INCLUDE3
continue
else:
# -----------------------
# END_CHECK_NUM
i += 1
if i <= n:
# goto CHECK_NUM
break
else:
# END!!
return s
# -----------------------
# -----------------------------------------------------
# ---------------------------------------------------------------------
return s
print(sub())
if __name__ == "__main__":
main()
| # coding=utf-8
def main():
n = eval(input())
s = ""
for i in range(1, n + 1):
x = i
if x % 3 == 0:
s += " " + str(i)
continue
while x:
if x % 10 == 3:
s += " " + str(i)
break
x /= 10
print(s)
if __name__ == "__main__":
main()
| false | 67.741935 | [
"- def sub():",
"- n = eval(input())",
"- i = 1",
"- s = \"\"",
"- # CHECK_NUM",
"- while True:",
"- x = i",
"- if x % 3 == 0:",
"+ n = eval(input())",
"+ s = \"\"",
"+ for i in range(1, n + 1):",
"+ x = i",
"+ if x % 3 == 0:",
"+ s += \" \" + str(i)",
"+ continue",
"+ while x:",
"+ if x % 10 == 3:",
"- # END_CHECK_NUM",
"- i += 1",
"- if i <= n:",
"- # goto CHECK_NUM",
"- continue",
"- else:",
"- # END!!",
"- break",
"- # INCLUDE3",
"- while True:",
"- if x % 10 == 3:",
"- s += \" \" + str(i)",
"- # END_CHECK_NUM",
"- i += 1",
"- if i <= n:",
"- # goto INCLUDE3",
"- break",
"- else:",
"- # END!!",
"- return s",
"- else:",
"- x /= 10",
"- if x:",
"- # goto INCLUDE3",
"- continue",
"- else:",
"- # END_CHECK_NUM",
"- i += 1",
"- if i <= n:",
"- # goto CHECK_NUM",
"- break",
"- else:",
"- # END!!",
"- return s",
"- return s",
"-",
"- print(sub())",
"+ break",
"+ x /= 10",
"+ print(s)"
] | false | 0.062377 | 0.05397 | 1.155761 | [
"s977453385",
"s033654449"
] |
u553987207 | p03371 | python | s190623381 | s132439912 | 134 | 114 | 3,064 | 9,140 | Accepted | Accepted | 14.93 | A, B, C, X, Y = list(map(int, input().split()))
ans = X * A + Y * B
for nab in range(2, max(X, Y) * 2 + 2, 2):
price = nab * C
price += max(X - (nab // 2), 0) * A
price += max(Y - (nab // 2), 0) * B
ans = min(ans, price)
print(ans) | A, B, C, X, Y = list(map(int, input().split()))
ans = None
for ab_count in range(0, max(X, Y) * 2 + 1, 2):
a_count = max(0, X - ab_count // 2)
b_count = max(0, Y - ab_count // 2)
amount = a_count * A + b_count * B + ab_count * C
if ans is None:
ans = amount
else:
ans = min(ans, amount)
print(ans) | 8 | 11 | 248 | 337 | A, B, C, X, Y = list(map(int, input().split()))
ans = X * A + Y * B
for nab in range(2, max(X, Y) * 2 + 2, 2):
price = nab * C
price += max(X - (nab // 2), 0) * A
price += max(Y - (nab // 2), 0) * B
ans = min(ans, price)
print(ans)
| A, B, C, X, Y = list(map(int, input().split()))
ans = None
for ab_count in range(0, max(X, Y) * 2 + 1, 2):
a_count = max(0, X - ab_count // 2)
b_count = max(0, Y - ab_count // 2)
amount = a_count * A + b_count * B + ab_count * C
if ans is None:
ans = amount
else:
ans = min(ans, amount)
print(ans)
| false | 27.272727 | [
"-ans = X * A + Y * B",
"-for nab in range(2, max(X, Y) * 2 + 2, 2):",
"- price = nab * C",
"- price += max(X - (nab // 2), 0) * A",
"- price += max(Y - (nab // 2), 0) * B",
"- ans = min(ans, price)",
"+ans = None",
"+for ab_count in range(0, max(X, Y) * 2 + 1, 2):",
"+ a_count = max(0, X - ab_count // 2)",
"+ b_count = max(0, Y - ab_count // 2)",
"+ amount = a_count * A + b_count * B + ab_count * C",
"+ if ans is None:",
"+ ans = amount",
"+ else:",
"+ ans = min(ans, amount)"
] | false | 0.129538 | 0.165285 | 0.783726 | [
"s190623381",
"s132439912"
] |
u873139556 | p03260 | python | s784008516 | s304460242 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | # -*- coding: utf-8 -*-
def main():
a, b = list(map(int, input().split()))
for c in range(1, 4):
num = a * b * c
if num % 2 == 1:
print("Yes")
exit()
print("No")
if __name__ == "__main__":
main()
| a, b = list(map(int, input().split()))
for c in range(1, 4):
if (a * b * c % 2) == 1:
print("Yes")
exit()
print("No")
| 15 | 8 | 264 | 141 | # -*- coding: utf-8 -*-
def main():
a, b = list(map(int, input().split()))
for c in range(1, 4):
num = a * b * c
if num % 2 == 1:
print("Yes")
exit()
print("No")
if __name__ == "__main__":
main()
| a, b = list(map(int, input().split()))
for c in range(1, 4):
if (a * b * c % 2) == 1:
print("Yes")
exit()
print("No")
| false | 46.666667 | [
"-# -*- coding: utf-8 -*-",
"-def main():",
"- a, b = list(map(int, input().split()))",
"- for c in range(1, 4):",
"- num = a * b * c",
"- if num % 2 == 1:",
"- print(\"Yes\")",
"- exit()",
"- print(\"No\")",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+a, b = list(map(int, input().split()))",
"+for c in range(1, 4):",
"+ if (a * b * c % 2) == 1:",
"+ print(\"Yes\")",
"+ exit()",
"+print(\"No\")"
] | false | 0.047567 | 0.048037 | 0.99022 | [
"s784008516",
"s304460242"
] |
u677440371 | p03309 | python | s237639105 | s224304280 | 331 | 280 | 26,128 | 26,360 | Accepted | Accepted | 15.41 | n = int(eval(input()))
a = [int(i) for i in input().split()]
import statistics
check = []
for i in range(n):
check.append(a[i] - (i+1))
check = sorted(check)
b = statistics.median(check)
ans = 0
for i in range(n):
ans += abs(a[i] -(b+i+1))
print((int(ans))) | n = int(eval(input()))
a = [int(i) for i in input().split()]
import statistics
check = []
for i in range(n):
check.append(a[i] - (i+1))
b = statistics.median(sorted(check))
ans = 0
for i in range(n):
ans += abs(check[i] - b)
print((int(ans))) | 14 | 13 | 272 | 256 | n = int(eval(input()))
a = [int(i) for i in input().split()]
import statistics
check = []
for i in range(n):
check.append(a[i] - (i + 1))
check = sorted(check)
b = statistics.median(check)
ans = 0
for i in range(n):
ans += abs(a[i] - (b + i + 1))
print((int(ans)))
| n = int(eval(input()))
a = [int(i) for i in input().split()]
import statistics
check = []
for i in range(n):
check.append(a[i] - (i + 1))
b = statistics.median(sorted(check))
ans = 0
for i in range(n):
ans += abs(check[i] - b)
print((int(ans)))
| false | 7.142857 | [
"-check = sorted(check)",
"-b = statistics.median(check)",
"+b = statistics.median(sorted(check))",
"- ans += abs(a[i] - (b + i + 1))",
"+ ans += abs(check[i] - b)"
] | false | 0.132484 | 0.053687 | 2.467738 | [
"s237639105",
"s224304280"
] |
u296518383 | p02580 | python | s759495750 | s952436554 | 983 | 722 | 216,988 | 246,672 | Accepted | Accepted | 26.55 | from sys import stdin, setrecursionlimit
#input = stdin.buffer.readline
setrecursionlimit(10 ** 7)
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos
MOD = 10 ** 9 + 7
INF = 10 ** 6
H, W, M = list(map(int, input().split()))
hw = [list(map(int, input().split())) for _ in range(M)]
cnt = defaultdict(int)
cnt_h = defaultdict(int)
cnt_w = defaultdict(int)
for h, w in hw:
cnt[h * INF + w] += 1
#print(cnt)
for h, w in hw:
cnt_h[h] += 1
cnt_w[w] += 1
cnt_h = list(cnt_h.items())
cnt_w = list(cnt_w.items())
cnt_h.sort(key = lambda x: -x[1])
cnt_w.sort(key = lambda x: -x[1])
#print(cnt_h)
#print(cnt_w)
max_h = []
max_w = []
for h, n in cnt_h:
if n == cnt_h[0][1]:
max_h.append(h)
for w, n in cnt_w:
if n == cnt_w[0][1]:
max_w.append(w)
#print(max_h)
#print(max_w)
answer = cnt_h[0][1] + cnt_w[0][1]
for mh in max_h:
for mw in max_w:
if cnt[mh * INF + mw] == 0:
print(answer)
exit()
print((answer - 1)) | from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
from collections import deque, defaultdict, Counter
H, W, M = list(map(int, input().split()))
hw = [list(map(int, input().split())) for _ in range(M)]
cnt = defaultdict(int)
cnt_h = defaultdict(int)
cnt_w = defaultdict(int)
for h, w in hw:
cnt[(h, w)] += 1
for h, w in hw:
cnt_h[h] += 1
cnt_w[w] += 1
cnt_h = list(cnt_h.items())
cnt_w = list(cnt_w.items())
cnt_h.sort(key = lambda x: -x[1])
cnt_w.sort(key = lambda x: -x[1])
max_h = []
max_w = []
for h, n in cnt_h:
if n == cnt_h[0][1]:
max_h.append(h)
for w, n in cnt_w:
if n == cnt_w[0][1]:
max_w.append(w)
answer = cnt_h[0][1] + cnt_w[0][1]
for mh in max_h:
for mw in max_w:
if cnt[(mh, mw)] == 0:
print(answer)
exit()
print((answer - 1)) | 53 | 40 | 1,269 | 873 | from sys import stdin, setrecursionlimit
# input = stdin.buffer.readline
setrecursionlimit(10**7)
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos
MOD = 10**9 + 7
INF = 10**6
H, W, M = list(map(int, input().split()))
hw = [list(map(int, input().split())) for _ in range(M)]
cnt = defaultdict(int)
cnt_h = defaultdict(int)
cnt_w = defaultdict(int)
for h, w in hw:
cnt[h * INF + w] += 1
# print(cnt)
for h, w in hw:
cnt_h[h] += 1
cnt_w[w] += 1
cnt_h = list(cnt_h.items())
cnt_w = list(cnt_w.items())
cnt_h.sort(key=lambda x: -x[1])
cnt_w.sort(key=lambda x: -x[1])
# print(cnt_h)
# print(cnt_w)
max_h = []
max_w = []
for h, n in cnt_h:
if n == cnt_h[0][1]:
max_h.append(h)
for w, n in cnt_w:
if n == cnt_w[0][1]:
max_w.append(w)
# print(max_h)
# print(max_w)
answer = cnt_h[0][1] + cnt_w[0][1]
for mh in max_h:
for mw in max_w:
if cnt[mh * INF + mw] == 0:
print(answer)
exit()
print((answer - 1))
| from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
from collections import deque, defaultdict, Counter
H, W, M = list(map(int, input().split()))
hw = [list(map(int, input().split())) for _ in range(M)]
cnt = defaultdict(int)
cnt_h = defaultdict(int)
cnt_w = defaultdict(int)
for h, w in hw:
cnt[(h, w)] += 1
for h, w in hw:
cnt_h[h] += 1
cnt_w[w] += 1
cnt_h = list(cnt_h.items())
cnt_w = list(cnt_w.items())
cnt_h.sort(key=lambda x: -x[1])
cnt_w.sort(key=lambda x: -x[1])
max_h = []
max_w = []
for h, n in cnt_h:
if n == cnt_h[0][1]:
max_h.append(h)
for w, n in cnt_w:
if n == cnt_w[0][1]:
max_w.append(w)
answer = cnt_h[0][1] + cnt_w[0][1]
for mh in max_h:
for mw in max_w:
if cnt[(mh, mw)] == 0:
print(answer)
exit()
print((answer - 1))
| false | 24.528302 | [
"-# input = stdin.buffer.readline",
"-setrecursionlimit(10**7)",
"-from heapq import heappush, heappop",
"-from bisect import bisect_left, bisect_right",
"+input = stdin.buffer.readline",
"-from itertools import combinations, permutations, combinations_with_replacement",
"-from itertools import accumulate",
"-from math import ceil, sqrt, pi, radians, sin, cos",
"-MOD = 10**9 + 7",
"-INF = 10**6",
"- cnt[h * INF + w] += 1",
"-# print(cnt)",
"+ cnt[(h, w)] += 1",
"-# print(cnt_h)",
"-# print(cnt_w)",
"-# print(max_h)",
"-# print(max_w)",
"- if cnt[mh * INF + mw] == 0:",
"+ if cnt[(mh, mw)] == 0:"
] | false | 0.037326 | 0.045995 | 0.81152 | [
"s759495750",
"s952436554"
] |
u844646164 | p02900 | python | s443763695 | s234162867 | 296 | 245 | 5,044 | 5,428 | Accepted | Accepted | 17.23 | import fractions
import math
from collections import Counter
a, b = list(map(int, input().split()))
n = fractions.gcd(a, b)
prime_count = Counter()
for i in range(2, math.ceil(math.sqrt(n))+1):
while n % i == 0:
n /= i
prime_count[i] += 1
if n > 1:
prime_count[int(n)] += 1
print((len(prime_count)+1)) | import fractions
import math
from collections import Counter
A, B = list(map(int, input().split()))
C = fractions.gcd(A, B)
prime_count = Counter()
for i in range(2, math.ceil(math.sqrt(C))+1):
while C % i == 0:
C /= i
prime_count[i] += 1
if C > 1:
prime_count[int(C)] += 1
print((len(prime_count)+1)) | 15 | 15 | 321 | 321 | import fractions
import math
from collections import Counter
a, b = list(map(int, input().split()))
n = fractions.gcd(a, b)
prime_count = Counter()
for i in range(2, math.ceil(math.sqrt(n)) + 1):
while n % i == 0:
n /= i
prime_count[i] += 1
if n > 1:
prime_count[int(n)] += 1
print((len(prime_count) + 1))
| import fractions
import math
from collections import Counter
A, B = list(map(int, input().split()))
C = fractions.gcd(A, B)
prime_count = Counter()
for i in range(2, math.ceil(math.sqrt(C)) + 1):
while C % i == 0:
C /= i
prime_count[i] += 1
if C > 1:
prime_count[int(C)] += 1
print((len(prime_count) + 1))
| false | 0 | [
"-a, b = list(map(int, input().split()))",
"-n = fractions.gcd(a, b)",
"+A, B = list(map(int, input().split()))",
"+C = fractions.gcd(A, B)",
"-for i in range(2, math.ceil(math.sqrt(n)) + 1):",
"- while n % i == 0:",
"- n /= i",
"+for i in range(2, math.ceil(math.sqrt(C)) + 1):",
"+ while C % i == 0:",
"+ C /= i",
"-if n > 1:",
"- prime_count[int(n)] += 1",
"+if C > 1:",
"+ prime_count[int(C)] += 1"
] | false | 0.058957 | 0.058969 | 0.999795 | [
"s443763695",
"s234162867"
] |
u883048396 | p04013 | python | s177231433 | s201259687 | 1,833 | 31 | 62,960 | 3,444 | Accepted | Accepted | 98.31 | iN,iA =[int(x) for x in input().split()]
#aX = [int(x) - iA for x in input().split()]
aX = [int(x) for x in input().split()]
#解法1
iMX = max(aX + [iA])
dp = [[[0]*(iN*iMX + 1) for _ in range(iN+1)] for _ in range(iN + 1)]
dp[0][0][0] = 1
for j in range(1,iN+1):
# for k in range(0,iN+1):
for k in range(0,j+1):
# for s in range(0,iN*iMX + 1):
for s in range(0,j*iMX + 1):
if s < aX[j-1]:
dp[j][k][s] = dp[j-1][k][s]
elif k >= 1 and s >= aX[j-1]:
dp[j][k][s] = dp[j-1][k][s]+dp[j-1][k-1][s- aX[j-1]]
else:
dp[j][k][s] = 0
iRet = 0
for k in range(1,iN+1):
iRet += dp[iN][k][k*iA]
print(iRet)
| #分割してみた。これで通るかな?
iN,iA =[int(x) for x in input().split()]
aX = [int(x) - iA for x in input().split()]
aPlus = [x for x in aX if 0 < x ]
aMinus = [-1 * x for x in aX if x < 0 ]
iLenPlus = len(aPlus)
iLenMinus = len(aMinus)
iLen0 = iN - iLenPlus - iLenMinus
def fnCr(iN,iR):
if iN - iR < iR :
iR = iN - iR
if iN == 0 :
return 0
elif iR == 0:
return 1
elif iR == 1:
return iN
return iN / iR * fnCr(iN-1,iR-1)
aFr = [1]*(iN+1)
for i in range(1,iN+1):
aFr[i] = aFr[i-1] * i
iCZero = 2**iLen0 - 1 #sum(k=1..N){nCk} = 2^n -1
iRet = 0
iRet += iCZero
iCZero += 1 #0の場合を追加
iSumPlus = sum(aPlus)
iSumMinus = sum(aMinus)
iUlim = min(iSumPlus , iSumMinus)
iOlim = max(iSumPlus , iSumMinus)
if 0 < iUlim:
dp1 = [[0]*(iOlim +1) for _ in range(iLenPlus)]
dp1[0][0] = 1
dp1[0][aPlus[0]]=1
for j in range(1,iLenPlus):
for k in range(iUlim + 1):
if k < aPlus[j] :
dp1[j][k] = dp1[j-1][k]
else:
dp1[j][k] = dp1[j-1][k] + dp1[j-1][k-aPlus[j]]
dp2 = [[0]*(iOlim +1) for _ in range(iLenMinus)]
dp2[0][0] = 1
dp2[0][aMinus[0]]=1
for j in range(1,iLenMinus):
for k in range(iUlim + 1):
if k < aMinus[j] :
dp2[j][k] = dp2[j-1][k]
else:
dp2[j][k] = dp2[j-1][k] + dp2[j-1][k-aMinus[j]]
for i in range(1,iUlim+1):
iRet += iCZero * dp1[-1][i] * dp2[-1][i]
print(iRet)
| 25 | 59 | 726 | 1,533 | iN, iA = [int(x) for x in input().split()]
# aX = [int(x) - iA for x in input().split()]
aX = [int(x) for x in input().split()]
# 解法1
iMX = max(aX + [iA])
dp = [[[0] * (iN * iMX + 1) for _ in range(iN + 1)] for _ in range(iN + 1)]
dp[0][0][0] = 1
for j in range(1, iN + 1):
# for k in range(0,iN+1):
for k in range(0, j + 1):
# for s in range(0,iN*iMX + 1):
for s in range(0, j * iMX + 1):
if s < aX[j - 1]:
dp[j][k][s] = dp[j - 1][k][s]
elif k >= 1 and s >= aX[j - 1]:
dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - aX[j - 1]]
else:
dp[j][k][s] = 0
iRet = 0
for k in range(1, iN + 1):
iRet += dp[iN][k][k * iA]
print(iRet)
| # 分割してみた。これで通るかな?
iN, iA = [int(x) for x in input().split()]
aX = [int(x) - iA for x in input().split()]
aPlus = [x for x in aX if 0 < x]
aMinus = [-1 * x for x in aX if x < 0]
iLenPlus = len(aPlus)
iLenMinus = len(aMinus)
iLen0 = iN - iLenPlus - iLenMinus
def fnCr(iN, iR):
if iN - iR < iR:
iR = iN - iR
if iN == 0:
return 0
elif iR == 0:
return 1
elif iR == 1:
return iN
return iN / iR * fnCr(iN - 1, iR - 1)
aFr = [1] * (iN + 1)
for i in range(1, iN + 1):
aFr[i] = aFr[i - 1] * i
iCZero = 2**iLen0 - 1 # sum(k=1..N){nCk} = 2^n -1
iRet = 0
iRet += iCZero
iCZero += 1 # 0の場合を追加
iSumPlus = sum(aPlus)
iSumMinus = sum(aMinus)
iUlim = min(iSumPlus, iSumMinus)
iOlim = max(iSumPlus, iSumMinus)
if 0 < iUlim:
dp1 = [[0] * (iOlim + 1) for _ in range(iLenPlus)]
dp1[0][0] = 1
dp1[0][aPlus[0]] = 1
for j in range(1, iLenPlus):
for k in range(iUlim + 1):
if k < aPlus[j]:
dp1[j][k] = dp1[j - 1][k]
else:
dp1[j][k] = dp1[j - 1][k] + dp1[j - 1][k - aPlus[j]]
dp2 = [[0] * (iOlim + 1) for _ in range(iLenMinus)]
dp2[0][0] = 1
dp2[0][aMinus[0]] = 1
for j in range(1, iLenMinus):
for k in range(iUlim + 1):
if k < aMinus[j]:
dp2[j][k] = dp2[j - 1][k]
else:
dp2[j][k] = dp2[j - 1][k] + dp2[j - 1][k - aMinus[j]]
for i in range(1, iUlim + 1):
iRet += iCZero * dp1[-1][i] * dp2[-1][i]
print(iRet)
| false | 57.627119 | [
"+# 分割してみた。これで通るかな?",
"-# aX = [int(x) - iA for x in input().split()]",
"-aX = [int(x) for x in input().split()]",
"-# 解法1",
"-iMX = max(aX + [iA])",
"-dp = [[[0] * (iN * iMX + 1) for _ in range(iN + 1)] for _ in range(iN + 1)]",
"-dp[0][0][0] = 1",
"-for j in range(1, iN + 1):",
"- # for k in range(0,iN+1):",
"- for k in range(0, j + 1):",
"- # for s in range(0,iN*iMX + 1):",
"- for s in range(0, j * iMX + 1):",
"- if s < aX[j - 1]:",
"- dp[j][k][s] = dp[j - 1][k][s]",
"- elif k >= 1 and s >= aX[j - 1]:",
"- dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - aX[j - 1]]",
"+aX = [int(x) - iA for x in input().split()]",
"+aPlus = [x for x in aX if 0 < x]",
"+aMinus = [-1 * x for x in aX if x < 0]",
"+iLenPlus = len(aPlus)",
"+iLenMinus = len(aMinus)",
"+iLen0 = iN - iLenPlus - iLenMinus",
"+",
"+",
"+def fnCr(iN, iR):",
"+ if iN - iR < iR:",
"+ iR = iN - iR",
"+ if iN == 0:",
"+ return 0",
"+ elif iR == 0:",
"+ return 1",
"+ elif iR == 1:",
"+ return iN",
"+ return iN / iR * fnCr(iN - 1, iR - 1)",
"+",
"+",
"+aFr = [1] * (iN + 1)",
"+for i in range(1, iN + 1):",
"+ aFr[i] = aFr[i - 1] * i",
"+iCZero = 2**iLen0 - 1 # sum(k=1..N){nCk} = 2^n -1",
"+iRet = 0",
"+iRet += iCZero",
"+iCZero += 1 # 0の場合を追加",
"+iSumPlus = sum(aPlus)",
"+iSumMinus = sum(aMinus)",
"+iUlim = min(iSumPlus, iSumMinus)",
"+iOlim = max(iSumPlus, iSumMinus)",
"+if 0 < iUlim:",
"+ dp1 = [[0] * (iOlim + 1) for _ in range(iLenPlus)]",
"+ dp1[0][0] = 1",
"+ dp1[0][aPlus[0]] = 1",
"+ for j in range(1, iLenPlus):",
"+ for k in range(iUlim + 1):",
"+ if k < aPlus[j]:",
"+ dp1[j][k] = dp1[j - 1][k]",
"- dp[j][k][s] = 0",
"-iRet = 0",
"-for k in range(1, iN + 1):",
"- iRet += dp[iN][k][k * iA]",
"+ dp1[j][k] = dp1[j - 1][k] + dp1[j - 1][k - aPlus[j]]",
"+ dp2 = [[0] * (iOlim + 1) for _ in range(iLenMinus)]",
"+ dp2[0][0] = 1",
"+ dp2[0][aMinus[0]] = 1",
"+ for j in range(1, iLenMinus):",
"+ for k in range(iUlim + 1):",
"+ if k < aMinus[j]:",
"+ dp2[j][k] = dp2[j - 1][k]",
"+ else:",
"+ dp2[j][k] = dp2[j - 1][k] + dp2[j - 1][k - aMinus[j]]",
"+ for i in range(1, iUlim + 1):",
"+ iRet += iCZero * dp1[-1][i] * dp2[-1][i]"
] | false | 0.075564 | 0.038207 | 1.977737 | [
"s177231433",
"s201259687"
] |
u859742379 | p03910 | python | s068740361 | s506864887 | 1,188 | 31 | 9,296 | 9,328 | Accepted | Accepted | 97.39 | from itertools import accumulate
n=int(eval(input()))
l=list(accumulate(list(range(4473))))
while True:
for i,x in enumerate(l):
if n==x:
for y in range(1,i+1):
print(y)
exit()
elif n<x:
print(i)
n-=i
break | from itertools import accumulate
import bisect
n=int(eval(input()))
l=list(accumulate(list(range(4473))))
while True:
i=bisect.bisect_left(l,n)
if i<1:break
print(i)
n-=i | 14 | 9 | 304 | 182 | from itertools import accumulate
n = int(eval(input()))
l = list(accumulate(list(range(4473))))
while True:
for i, x in enumerate(l):
if n == x:
for y in range(1, i + 1):
print(y)
exit()
elif n < x:
print(i)
n -= i
break
| from itertools import accumulate
import bisect
n = int(eval(input()))
l = list(accumulate(list(range(4473))))
while True:
i = bisect.bisect_left(l, n)
if i < 1:
break
print(i)
n -= i
| false | 35.714286 | [
"+import bisect",
"- for i, x in enumerate(l):",
"- if n == x:",
"- for y in range(1, i + 1):",
"- print(y)",
"- exit()",
"- elif n < x:",
"- print(i)",
"- n -= i",
"- break",
"+ i = bisect.bisect_left(l, n)",
"+ if i < 1:",
"+ break",
"+ print(i)",
"+ n -= i"
] | false | 0.07041 | 0.064967 | 1.08378 | [
"s068740361",
"s506864887"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.