user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
list
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
list
u562016607
p03294
python
s548527005
s442930762
171
18
38,896
3,188
Accepted
Accepted
89.47
N=int(eval(input())) A=[int(i) for i in input().split()] print((sum(A)-N))
print((-int(eval(input()))+sum(map(int,input().split()))))
3
1
69
50
N = int(eval(input())) A = [int(i) for i in input().split()] print((sum(A) - N))
print((-int(eval(input())) + sum(map(int, input().split()))))
false
66.666667
[ "-N = int(eval(input()))", "-A = [int(i) for i in input().split()]", "-print((sum(A) - N))", "+print((-int(eval(input())) + sum(map(int, input().split()))))" ]
false
0.035901
0.036773
0.976305
[ "s548527005", "s442930762" ]
u759412327
p02861
python
s394357694
s567699254
158
122
12,644
27,272
Accepted
Accepted
22.78
import numpy as np N = int(eval(input())) R = np.array([list(map(int,input().split())) for i in range(N)]) print((sum(np.linalg.norm(i-j) for i in R for j in R)/N))
import numpy as np N = int(eval(input())) R = np.array([list(map(int,input().split())) for n in range(N)]) print((sum(np.linalg.norm(i-j) for i in R for j in R)/N))
4
4
159
159
import numpy as np N = int(eval(input())) R = np.array([list(map(int, input().split())) for i in range(N)]) print((sum(np.linalg.norm(i - j) for i in R for j in R) / N))
import numpy as np N = int(eval(input())) R = np.array([list(map(int, input().split())) for n in range(N)]) print((sum(np.linalg.norm(i - j) for i in R for j in R) / N))
false
0
[ "-R = np.array([list(map(int, input().split())) for i in range(N)])", "+R = np.array([list(map(int, input().split())) for n in range(N)])" ]
false
0.182062
0.173846
1.047261
[ "s394357694", "s567699254" ]
u188827677
p02778
python
s503668668
s386048979
19
17
3,188
2,940
Accepted
Accepted
10.53
# -*- coding:utf-8 -*- import re s = eval(input()) print((re.sub(r'[a-z]', 'x', s)))
s = eval(input()) print(('x'*len(s)))
6
2
83
30
# -*- coding:utf-8 -*- import re s = eval(input()) print((re.sub(r"[a-z]", "x", s)))
s = eval(input()) print(("x" * len(s)))
false
66.666667
[ "-# -*- coding:utf-8 -*-", "-import re", "-", "-print((re.sub(r\"[a-z]\", \"x\", s)))", "+print((\"x\" * len(s)))" ]
false
0.045754
0.042438
1.078135
[ "s503668668", "s386048979" ]
u375282392
p03043
python
s096442740
s583368542
66
48
5,048
2,940
Accepted
Accepted
27.27
from fractions import Fraction N,K = list(map(int, input().split())) proba = 0 for i in range(1,N+1): deme = i con = 0 while deme < K: deme *= 2 con += 1 proba += (1/N)*((1/2)**con) print((float(proba)))
N,K = list(map(int, input().split())) proba = 0 for i in range(1,N+1): deme = i con = 0 while deme < K: deme *= 2 con += 1 proba += (1/N)*((1/2)**con) print((float(proba)))
15
13
225
191
from fractions import Fraction N, K = list(map(int, input().split())) proba = 0 for i in range(1, N + 1): deme = i con = 0 while deme < K: deme *= 2 con += 1 proba += (1 / N) * ((1 / 2) ** con) print((float(proba)))
N, K = list(map(int, input().split())) proba = 0 for i in range(1, N + 1): deme = i con = 0 while deme < K: deme *= 2 con += 1 proba += (1 / N) * ((1 / 2) ** con) print((float(proba)))
false
13.333333
[ "-from fractions import Fraction", "-" ]
false
0.072285
0.055981
1.291246
[ "s096442740", "s583368542" ]
u775681539
p02623
python
s443799215
s309836246
192
161
140,100
139,492
Accepted
Accepted
16.15
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import deque def main(): N, M, K = list(map(int, readline().split())) A = [int(i) for i in readline().split()] B = [int(i) for i in readline().split()] #方針:A,Bそれぞれ前からi,j番目までとったときの合計がK以内であるときのi+jを求める #A,Bそれぞれの山の一番上の本だけを比較して時間が小さい方を選ぶことを繰り返すのは間違い。 csumA = [0] for i in range(N): csumA.append(csumA[i] + A[i]) csumB = [0] for i in range(M): csumB.append(csumB[i] + B[i]) mx = 0 for i in range(N+1): # r:= Aの山の上からi番目までの本を読むとき、残りの時間 r = K-csumA[i] if r < 0: break left = -1 right = M+1 while right-left>1: mid = (left+right)//2 if r >= csumB[mid]: left = mid else: right = mid mx = max(mx, i+left) print(mx) if __name__ == '__main__': main()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import deque def main(): N, M, K = list(map(int, readline().split())) A = [int(i) for i in readline().split()] B = [int(i) for i in readline().split()] ca = [0] cb = [0] for i in range(N): ca.append(ca[i] + A[i]) for i in range(M): cb.append(cb[i] + B[i]) ans = 0 j = M for i in range(N+1): if K < ca[i]: break while cb[j] > K-ca[i]: j -= 1 ans = max(ans, i+j) print(ans) if __name__ == '__main__': main()
41
28
1,015
676
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import deque def main(): N, M, K = list(map(int, readline().split())) A = [int(i) for i in readline().split()] B = [int(i) for i in readline().split()] # 方針:A,Bそれぞれ前からi,j番目までとったときの合計がK以内であるときのi+jを求める # A,Bそれぞれの山の一番上の本だけを比較して時間が小さい方を選ぶことを繰り返すのは間違い。 csumA = [0] for i in range(N): csumA.append(csumA[i] + A[i]) csumB = [0] for i in range(M): csumB.append(csumB[i] + B[i]) mx = 0 for i in range(N + 1): # r:= Aの山の上からi番目までの本を読むとき、残りの時間 r = K - csumA[i] if r < 0: break left = -1 right = M + 1 while right - left > 1: mid = (left + right) // 2 if r >= csumB[mid]: left = mid else: right = mid mx = max(mx, i + left) print(mx) if __name__ == "__main__": main()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import deque def main(): N, M, K = list(map(int, readline().split())) A = [int(i) for i in readline().split()] B = [int(i) for i in readline().split()] ca = [0] cb = [0] for i in range(N): ca.append(ca[i] + A[i]) for i in range(M): cb.append(cb[i] + B[i]) ans = 0 j = M for i in range(N + 1): if K < ca[i]: break while cb[j] > K - ca[i]: j -= 1 ans = max(ans, i + j) print(ans) if __name__ == "__main__": main()
false
31.707317
[ "- # 方針:A,Bそれぞれ前からi,j番目までとったときの合計がK以内であるときのi+jを求める", "- # A,Bそれぞれの山の一番上の本だけを比較して時間が小さい方を選ぶことを繰り返すのは間違い。", "- csumA = [0]", "+ ca = [0]", "+ cb = [0]", "- csumA.append(csumA[i] + A[i])", "- csumB = [0]", "+ ca.append(ca[i] + A[i])", "- csumB.append(csumB[i] + B[i])", "- mx = 0", "+ cb.append(cb[i] + B[i])", "+ ans = 0", "+ j = M", "- # r:= Aの山の上からi番目までの本を読むとき、残りの時間", "- r = K - csumA[i]", "- if r < 0:", "+ if K < ca[i]:", "- left = -1", "- right = M + 1", "- while right - left > 1:", "- mid = (left + right) // 2", "- if r >= csumB[mid]:", "- left = mid", "- else:", "- right = mid", "- mx = max(mx, i + left)", "- print(mx)", "+ while cb[j] > K - ca[i]:", "+ j -= 1", "+ ans = max(ans, i + j)", "+ print(ans)" ]
false
0.044052
0.045044
0.977973
[ "s443799215", "s309836246" ]
u116002573
p03290
python
s485686318
s849990499
23
21
3,444
3,188
Accepted
Accepted
8.7
def main(): D, G = list(map(int, input().split())) A = [] for i in range(D): p, c = list(map(int, input().split())) A.append([i, p, c]) A = A[::-1] cur = [[0, 0]] used = [set()] for i, p, c in A: temp = [] temp_used = [] for j in range(len(cur)): temp.append(cur[j]) temp_used.append(used[j]) temp.append([cur[j][0]+ 100*(i+1)*p+c, cur[j][1] + p]) temp_used.append(used[j] | {i}) cur = temp used = temp_used # # print(cur) # print(used) ans = float('inf') for j in range(len(cur)): if cur[j][0] >= G: ans = min(ans, cur[j][1]) else: for i, p, c in A: if i not in used[j]: if cur[j][0] + 100 * (i+1) * (p-1) < G: cur[j][0] += 100 * (i+1) * (p-1) cur[j][1] += p-1 else: if (G - cur[j][0]) % (100*(i+1)) == 0: ans = min(ans, cur[j][1] + (G - cur[j][0]) // (100*(i+1))) else: ans = min(ans, cur[j][1] + (G - cur[j][0]) // (100*(i+1)) + 1) break return ans if __name__ == '__main__': print((main()))
def main(): D, G = list(map(int, input().split())) A = [] for i in range(D): p, c = list(map(int, input().split())) A.append([i, p, c]) A = A[::-1] hs = [[0, 0, 0]] for i, p, c in A: temp = [] for h, v, q in hs: temp.append([h|(1 << i), v+100*(i+1)*p+c, q+p]) hs += temp # print(hs) ans = float('inf') for h, v, q in hs: if v >= G: ans = min(ans, q) else: for i, p, c in A: if (h >> i) % 2 == 0: if v + 100*(i+1)*(p-1) < G: v += 100*(i+1)*(p-1) q += p-1 else: if (G-v) % (100*(i+1)) == 0: ans = min(ans, q + (G-v) // (100*(i+1))) else: ans = min(ans, q + 1 + (G-v) // (100*(i+1))) break return ans if __name__ == '__main__': print((main()))
48
37
1,367
1,023
def main(): D, G = list(map(int, input().split())) A = [] for i in range(D): p, c = list(map(int, input().split())) A.append([i, p, c]) A = A[::-1] cur = [[0, 0]] used = [set()] for i, p, c in A: temp = [] temp_used = [] for j in range(len(cur)): temp.append(cur[j]) temp_used.append(used[j]) temp.append([cur[j][0] + 100 * (i + 1) * p + c, cur[j][1] + p]) temp_used.append(used[j] | {i}) cur = temp used = temp_used # # print(cur) # print(used) ans = float("inf") for j in range(len(cur)): if cur[j][0] >= G: ans = min(ans, cur[j][1]) else: for i, p, c in A: if i not in used[j]: if cur[j][0] + 100 * (i + 1) * (p - 1) < G: cur[j][0] += 100 * (i + 1) * (p - 1) cur[j][1] += p - 1 else: if (G - cur[j][0]) % (100 * (i + 1)) == 0: ans = min( ans, cur[j][1] + (G - cur[j][0]) // (100 * (i + 1)) ) else: ans = min( ans, cur[j][1] + (G - cur[j][0]) // (100 * (i + 1)) + 1 ) break return ans if __name__ == "__main__": print((main()))
def main(): D, G = list(map(int, input().split())) A = [] for i in range(D): p, c = list(map(int, input().split())) A.append([i, p, c]) A = A[::-1] hs = [[0, 0, 0]] for i, p, c in A: temp = [] for h, v, q in hs: temp.append([h | (1 << i), v + 100 * (i + 1) * p + c, q + p]) hs += temp # print(hs) ans = float("inf") for h, v, q in hs: if v >= G: ans = min(ans, q) else: for i, p, c in A: if (h >> i) % 2 == 0: if v + 100 * (i + 1) * (p - 1) < G: v += 100 * (i + 1) * (p - 1) q += p - 1 else: if (G - v) % (100 * (i + 1)) == 0: ans = min(ans, q + (G - v) // (100 * (i + 1))) else: ans = min(ans, q + 1 + (G - v) // (100 * (i + 1))) break return ans if __name__ == "__main__": print((main()))
false
22.916667
[ "- cur = [[0, 0]]", "- used = [set()]", "+ hs = [[0, 0, 0]]", "- temp_used = []", "- for j in range(len(cur)):", "- temp.append(cur[j])", "- temp_used.append(used[j])", "- temp.append([cur[j][0] + 100 * (i + 1) * p + c, cur[j][1] + p])", "- temp_used.append(used[j] | {i})", "- cur = temp", "- used = temp_used", "- #", "- # print(cur)", "- # print(used)", "+ for h, v, q in hs:", "+ temp.append([h | (1 << i), v + 100 * (i + 1) * p + c, q + p])", "+ hs += temp", "+ # print(hs)", "- for j in range(len(cur)):", "- if cur[j][0] >= G:", "- ans = min(ans, cur[j][1])", "+ for h, v, q in hs:", "+ if v >= G:", "+ ans = min(ans, q)", "- if i not in used[j]:", "- if cur[j][0] + 100 * (i + 1) * (p - 1) < G:", "- cur[j][0] += 100 * (i + 1) * (p - 1)", "- cur[j][1] += p - 1", "+ if (h >> i) % 2 == 0:", "+ if v + 100 * (i + 1) * (p - 1) < G:", "+ v += 100 * (i + 1) * (p - 1)", "+ q += p - 1", "- if (G - cur[j][0]) % (100 * (i + 1)) == 0:", "- ans = min(", "- ans, cur[j][1] + (G - cur[j][0]) // (100 * (i + 1))", "- )", "+ if (G - v) % (100 * (i + 1)) == 0:", "+ ans = min(ans, q + (G - v) // (100 * (i + 1)))", "- ans = min(", "- ans, cur[j][1] + (G - cur[j][0]) // (100 * (i + 1)) + 1", "- )", "+ ans = min(ans, q + 1 + (G - v) // (100 * (i + 1)))" ]
false
0.065526
0.035039
1.870103
[ "s485686318", "s849990499" ]
u368780724
p03430
python
s513439809
s479805126
794
651
142,728
125,404
Accepted
Accepted
18.01
import sys readline = sys.stdin.readline S = list(map(ord, readline().strip())) N = len(S) S = [None] + S + [None] K = int(readline()) if N == 1: ans = 1 elif N == 2: ans = 1 if S[1] == S[2]: ans = 2 if K: ans = 2 else: dp1 = [[0]*(K+1) for _ in range(N+2)] dp2 = [[0]*(K+1) for _ in range(N+2)] for i in range(1, N+1): dp1[i][0] = 1 for i in range(1, N): dp2[i][0] = 1 if S[i] == S[i+1]: dp2[i][0] = 2 elif K: dp2[i][1] = 2 for s in range(3, N+1): dp3 = [[0]*(K+1) for _ in range(N+2)] for i in range(1, N-s+2): j = i+s-1 if S[i] == S[j]: for k in range(K+1): dp3[i][k] = max(dp2[i+1][k], dp2[i][k], 2+dp1[i+1][k]) else: dp3[i][0] = max(dp2[i+1][0], dp2[i][0], dp2[i+1][0]) for k in range(1, K+1): dp3[i][k] = max(dp2[i+1][k], dp2[i][k], dp1[i+1][k], 2+dp1[i+1][k-1]) dp1 = [k[:] for k in dp2] dp2 = [k[:] for k in dp3] ans = max(dp3[1][k] for k in range(K+1)) print(ans) ''' MLEした dp = [[[0]*(K+1) for _ in range(N+2)] for _ in range(N+2)] for i in range(1, N+1): dp[i][i][0] = 1 for i in range(1, N): dp[i][i+1][0] = 1 if S[i] == S[i+1]: dp[i][i+1][0] = 2 elif K: dp[i][i+1][1] = 2 for s in range(3, N+1): for i in range(1, N-s+2): j = i+s-1 if S[i] == S[j]: for k in range(K+1): dp[i][j][k] = max(dp[i+1][j][k], dp[i][j-1][k], 2+dp[i+1][j-1][k]) else: dp[i][j][0] = max(dp[i+1][j][0], dp[i][j-1][0], dp[i+1][j-1][0]) for k in range(1, K+1): dp[i][j][k] = max(dp[i+1][j][k], dp[i][j-1][k], dp[i+1][j-1][k], 2+dp[i+1][j-1][k-1], dp[i+1][j-1][k]) print(max(dp[1][N][k] for k in range(K+1))) '''
import sys readline = sys.stdin.readline S = list(map(ord, readline().strip())) N = len(S) S = [None] + S + [None] K = int(readline()) if N == 1: ans = 1 elif N == 2: ans = 1 if S[1] == S[2]: ans = 2 if K: ans = 2 else: dp1 = [[0]*(K+1) for _ in range(N+2)] dp2 = [[0]*(K+1) for _ in range(N+2)] for i in range(1, N+1): dp1[i][0] = 1 for i in range(1, N): dp2[i][0] = 1 if S[i] == S[i+1]: dp2[i][0] = 2 elif K: dp2[i][1] = 2 for s in range(3, N+1): dp3 = [[0]*(K+1) for _ in range(N+2)] for i in range(1, N-s+2): j = i+s-1 if S[i] == S[j]: for k in range(K+1): dp3[i][k] = max(dp2[i+1][k], dp2[i][k], 2+dp1[i+1][k]) else: dp3[i][0] = max(dp2[i+1][0], dp2[i][0], dp2[i+1][0]) for k in range(1, K+1): dp3[i][k] = max(dp2[i+1][k], dp2[i][k], dp1[i+1][k], 2+dp1[i+1][k-1]) ''' dp1 = [k[:] for k in dp2] dp2 = [k[:] for k in dp3] ''' dp1 = dp2[:] dp2 = dp3[:] ans = max(dp3[1][k] for k in range(K+1)) print(ans) ''' MLEした dp = [[[0]*(K+1) for _ in range(N+2)] for _ in range(N+2)] for i in range(1, N+1): dp[i][i][0] = 1 for i in range(1, N): dp[i][i+1][0] = 1 if S[i] == S[i+1]: dp[i][i+1][0] = 2 elif K: dp[i][i+1][1] = 2 for s in range(3, N+1): for i in range(1, N-s+2): j = i+s-1 if S[i] == S[j]: for k in range(K+1): dp[i][j][k] = max(dp[i+1][j][k], dp[i][j-1][k], 2+dp[i+1][j-1][k]) else: dp[i][j][0] = max(dp[i+1][j][0], dp[i][j-1][0], dp[i+1][j-1][0]) for k in range(1, K+1): dp[i][j][k] = max(dp[i+1][j][k], dp[i][j-1][k], dp[i+1][j-1][k], 2+dp[i+1][j-1][k-1], dp[i+1][j-1][k]) print(max(dp[1][N][k] for k in range(K+1))) '''
65
69
1,980
2,050
import sys readline = sys.stdin.readline S = list(map(ord, readline().strip())) N = len(S) S = [None] + S + [None] K = int(readline()) if N == 1: ans = 1 elif N == 2: ans = 1 if S[1] == S[2]: ans = 2 if K: ans = 2 else: dp1 = [[0] * (K + 1) for _ in range(N + 2)] dp2 = [[0] * (K + 1) for _ in range(N + 2)] for i in range(1, N + 1): dp1[i][0] = 1 for i in range(1, N): dp2[i][0] = 1 if S[i] == S[i + 1]: dp2[i][0] = 2 elif K: dp2[i][1] = 2 for s in range(3, N + 1): dp3 = [[0] * (K + 1) for _ in range(N + 2)] for i in range(1, N - s + 2): j = i + s - 1 if S[i] == S[j]: for k in range(K + 1): dp3[i][k] = max(dp2[i + 1][k], dp2[i][k], 2 + dp1[i + 1][k]) else: dp3[i][0] = max(dp2[i + 1][0], dp2[i][0], dp2[i + 1][0]) for k in range(1, K + 1): dp3[i][k] = max( dp2[i + 1][k], dp2[i][k], dp1[i + 1][k], 2 + dp1[i + 1][k - 1] ) dp1 = [k[:] for k in dp2] dp2 = [k[:] for k in dp3] ans = max(dp3[1][k] for k in range(K + 1)) print(ans) """ MLEした dp = [[[0]*(K+1) for _ in range(N+2)] for _ in range(N+2)] for i in range(1, N+1): dp[i][i][0] = 1 for i in range(1, N): dp[i][i+1][0] = 1 if S[i] == S[i+1]: dp[i][i+1][0] = 2 elif K: dp[i][i+1][1] = 2 for s in range(3, N+1): for i in range(1, N-s+2): j = i+s-1 if S[i] == S[j]: for k in range(K+1): dp[i][j][k] = max(dp[i+1][j][k], dp[i][j-1][k], 2+dp[i+1][j-1][k]) else: dp[i][j][0] = max(dp[i+1][j][0], dp[i][j-1][0], dp[i+1][j-1][0]) for k in range(1, K+1): dp[i][j][k] = max(dp[i+1][j][k], dp[i][j-1][k], dp[i+1][j-1][k], 2+dp[i+1][j-1][k-1], dp[i+1][j-1][k]) print(max(dp[1][N][k] for k in range(K+1))) """
import sys readline = sys.stdin.readline S = list(map(ord, readline().strip())) N = len(S) S = [None] + S + [None] K = int(readline()) if N == 1: ans = 1 elif N == 2: ans = 1 if S[1] == S[2]: ans = 2 if K: ans = 2 else: dp1 = [[0] * (K + 1) for _ in range(N + 2)] dp2 = [[0] * (K + 1) for _ in range(N + 2)] for i in range(1, N + 1): dp1[i][0] = 1 for i in range(1, N): dp2[i][0] = 1 if S[i] == S[i + 1]: dp2[i][0] = 2 elif K: dp2[i][1] = 2 for s in range(3, N + 1): dp3 = [[0] * (K + 1) for _ in range(N + 2)] for i in range(1, N - s + 2): j = i + s - 1 if S[i] == S[j]: for k in range(K + 1): dp3[i][k] = max(dp2[i + 1][k], dp2[i][k], 2 + dp1[i + 1][k]) else: dp3[i][0] = max(dp2[i + 1][0], dp2[i][0], dp2[i + 1][0]) for k in range(1, K + 1): dp3[i][k] = max( dp2[i + 1][k], dp2[i][k], dp1[i + 1][k], 2 + dp1[i + 1][k - 1] ) """ dp1 = [k[:] for k in dp2] dp2 = [k[:] for k in dp3] """ dp1 = dp2[:] dp2 = dp3[:] ans = max(dp3[1][k] for k in range(K + 1)) print(ans) """ MLEした dp = [[[0]*(K+1) for _ in range(N+2)] for _ in range(N+2)] for i in range(1, N+1): dp[i][i][0] = 1 for i in range(1, N): dp[i][i+1][0] = 1 if S[i] == S[i+1]: dp[i][i+1][0] = 2 elif K: dp[i][i+1][1] = 2 for s in range(3, N+1): for i in range(1, N-s+2): j = i+s-1 if S[i] == S[j]: for k in range(K+1): dp[i][j][k] = max(dp[i+1][j][k], dp[i][j-1][k], 2+dp[i+1][j-1][k]) else: dp[i][j][0] = max(dp[i+1][j][0], dp[i][j-1][0], dp[i+1][j-1][0]) for k in range(1, K+1): dp[i][j][k] = max(dp[i+1][j][k], dp[i][j-1][k], dp[i+1][j-1][k], 2+dp[i+1][j-1][k-1], dp[i+1][j-1][k]) print(max(dp[1][N][k] for k in range(K+1))) """
false
5.797101
[ "+ \"\"\"", "+ \"\"\"", "+ dp1 = dp2[:]", "+ dp2 = dp3[:]" ]
false
0.035303
0.039637
0.89065
[ "s513439809", "s479805126" ]
u002459665
p02972
python
s278812974
s470124489
744
544
17,204
17,204
Accepted
Accepted
26.88
N = int(eval(input())) A = list(map(int, input().split())) r = [0] * N def f(n): """ nの倍数のボールの数 """ cnt = 0 i = 2 while n * i <= N: cnt += r[n*i-1] i += 1 return cnt for i in range(N): n = N - i x = f(n) if x % 2 == A[n-1]: pass else: r[n-1] += 1 # print(r) ans = [] for i, ri in enumerate(r): if ri == 1: ans.append(str(i+1)) if len(ans) == 0: print((0)) else: print((len(ans))) print((" ".join(ans)))
N = int(eval(input())) A = list(map(int, input().split())) r = [0] * N def f(n): """ nの倍数のボールの数 """ cnt = 0 t = n + n while t <= N: cnt += r[t-1] t += n return cnt for i in range(N): n = N - i x = f(n) if x % 2 == A[n-1]: pass else: r[n-1] += 1 # print(r) ans = [] for i, ri in enumerate(r): if ri == 1: ans.append(str(i+1)) if len(ans) == 0: print((0)) else: print((len(ans))) print((" ".join(ans)))
38
38
535
533
N = int(eval(input())) A = list(map(int, input().split())) r = [0] * N def f(n): """ nの倍数のボールの数 """ cnt = 0 i = 2 while n * i <= N: cnt += r[n * i - 1] i += 1 return cnt for i in range(N): n = N - i x = f(n) if x % 2 == A[n - 1]: pass else: r[n - 1] += 1 # print(r) ans = [] for i, ri in enumerate(r): if ri == 1: ans.append(str(i + 1)) if len(ans) == 0: print((0)) else: print((len(ans))) print((" ".join(ans)))
N = int(eval(input())) A = list(map(int, input().split())) r = [0] * N def f(n): """ nの倍数のボールの数 """ cnt = 0 t = n + n while t <= N: cnt += r[t - 1] t += n return cnt for i in range(N): n = N - i x = f(n) if x % 2 == A[n - 1]: pass else: r[n - 1] += 1 # print(r) ans = [] for i, ri in enumerate(r): if ri == 1: ans.append(str(i + 1)) if len(ans) == 0: print((0)) else: print((len(ans))) print((" ".join(ans)))
false
0
[ "- i = 2", "- while n * i <= N:", "- cnt += r[n * i - 1]", "- i += 1", "+ t = n + n", "+ while t <= N:", "+ cnt += r[t - 1]", "+ t += n" ]
false
0.036828
0.037264
0.988304
[ "s278812974", "s470124489" ]
u923270446
p02928
python
s733255589
s387849039
1,153
1,004
3,188
9,112
Accepted
Accepted
12.92
n, k = list(map(int, input().split())) a = list(map(int, input().split())) cnt = 0 l = [] for i in range(n): for j in range(n): if a[i] > a[j]: cnt += (k + 1) * k // 2 if j > i else k * (k - 1) // 2 print((cnt % 1000000007))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) mod = 10 ** 9 + 7 cnt = 0 l = [] for i in range(n): for j in range(n): if a[i] > a[j]: cnt += (k + 1) * k // 2 if j > i else k * (k - 1) // 2 cnt %= mod print((cnt % mod))
9
11
248
284
n, k = list(map(int, input().split())) a = list(map(int, input().split())) cnt = 0 l = [] for i in range(n): for j in range(n): if a[i] > a[j]: cnt += (k + 1) * k // 2 if j > i else k * (k - 1) // 2 print((cnt % 1000000007))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) mod = 10**9 + 7 cnt = 0 l = [] for i in range(n): for j in range(n): if a[i] > a[j]: cnt += (k + 1) * k // 2 if j > i else k * (k - 1) // 2 cnt %= mod print((cnt % mod))
false
18.181818
[ "+mod = 10**9 + 7", "-print((cnt % 1000000007))", "+ cnt %= mod", "+print((cnt % mod))" ]
false
0.036141
0.038138
0.947616
[ "s733255589", "s387849039" ]
u790012205
p02595
python
s596631908
s179021592
437
391
9,628
9,184
Accepted
Accepted
10.53
N, D = list(map(int, input().split())) n = 0 for _ in range(N): X, Y = list(map(int, input().split())) d = (X * X + Y * Y) ** 0.5 if d <= D: n += 1 print(n)
N, D = list(map(int, input().split())) D2 = D * D n = 0 for _ in range(N): X, Y = list(map(int, input().split())) d2 = X * X + Y * Y if d2 <= D2: n += 1 print(n)
8
9
171
177
N, D = list(map(int, input().split())) n = 0 for _ in range(N): X, Y = list(map(int, input().split())) d = (X * X + Y * Y) ** 0.5 if d <= D: n += 1 print(n)
N, D = list(map(int, input().split())) D2 = D * D n = 0 for _ in range(N): X, Y = list(map(int, input().split())) d2 = X * X + Y * Y if d2 <= D2: n += 1 print(n)
false
11.111111
[ "+D2 = D * D", "- d = (X * X + Y * Y) ** 0.5", "- if d <= D:", "+ d2 = X * X + Y * Y", "+ if d2 <= D2:" ]
false
0.051194
0.050949
1.004814
[ "s596631908", "s179021592" ]
u970197315
p03945
python
s452842807
s263554069
59
45
3,956
3,188
Accepted
Accepted
23.73
#ABC047 C - 一次元リバーシ / 1D Reversi S = eval(input()) cur_s = '' SS=[] for i,s in enumerate(S): if i==0: cur_s = s SS.append(s) continue if i==len(S): if cur_s == s: continue else: SS.append(s) continue if cur_s == s: continue else: SS.append(s) cur_s = s n = len(SS) m = n//2 if n==1: print((0)) exit() if n%2==1: print((m*2)) else: print((((n//2)*2)-1))
si = lambda: eval(input()) ni = lambda: int(eval(input())) nm = lambda: list(map(int, input().split())) nl = lambda: list(map(int, input().split())) s=eval(input()) cur=s[0] counter=1 for i,ss in enumerate(s): if i==0: continue if ss!=cur: counter+=1 cur=ss print((counter-1))
32
14
508
295
# ABC047 C - 一次元リバーシ / 1D Reversi S = eval(input()) cur_s = "" SS = [] for i, s in enumerate(S): if i == 0: cur_s = s SS.append(s) continue if i == len(S): if cur_s == s: continue else: SS.append(s) continue if cur_s == s: continue else: SS.append(s) cur_s = s n = len(SS) m = n // 2 if n == 1: print((0)) exit() if n % 2 == 1: print((m * 2)) else: print((((n // 2) * 2) - 1))
si = lambda: eval(input()) ni = lambda: int(eval(input())) nm = lambda: list(map(int, input().split())) nl = lambda: list(map(int, input().split())) s = eval(input()) cur = s[0] counter = 1 for i, ss in enumerate(s): if i == 0: continue if ss != cur: counter += 1 cur = ss print((counter - 1))
false
56.25
[ "-# ABC047 C - 一次元リバーシ / 1D Reversi", "-S = eval(input())", "-cur_s = \"\"", "-SS = []", "-for i, s in enumerate(S):", "+si = lambda: eval(input())", "+ni = lambda: int(eval(input()))", "+nm = lambda: list(map(int, input().split()))", "+nl = lambda: list(map(int, input().split()))", "+s = eval(input())", "+cur = s[0]", "+counter = 1", "+for i, ss in enumerate(s):", "- cur_s = s", "- SS.append(s)", "- if i == len(S):", "- if cur_s == s:", "- continue", "- else:", "- SS.append(s)", "- continue", "- if cur_s == s:", "- continue", "- else:", "- SS.append(s)", "- cur_s = s", "-n = len(SS)", "-m = n // 2", "-if n == 1:", "- print((0))", "- exit()", "-if n % 2 == 1:", "- print((m * 2))", "-else:", "- print((((n // 2) * 2) - 1))", "+ if ss != cur:", "+ counter += 1", "+ cur = ss", "+print((counter - 1))" ]
false
0.069251
0.070096
0.987952
[ "s452842807", "s263554069" ]
u893063840
p03252
python
s050311483
s888546538
129
75
3,632
9,660
Accepted
Accepted
41.86
def main(): s = eval(input()) t = eval(input()) r = [[-1] * 26 for _ in range(2)] bl = True for se, te in zip(s, t): si = ord(se) - ord("a") ti = ord(te) - ord("a") if r[0][si] < 0: r[0][si] = ti else: if r[0][si] != ti: bl = False break if r[1][ti] < 0: r[1][ti] = si else: if r[1][ti] != si: bl = False break print(("Yes" if bl else "No")) if __name__ == "__main__": main()
from collections import defaultdict s = eval(input()) t = eval(input()) in_deg = defaultdict(set) out_deg = defaultdict(set) for es, et in zip(s, t): out_deg[es].add(et) in_deg[et].add(es) in_deg_mx = max(list(map(len, list(in_deg.values())))) out_deg_mx = max(list(map(len, list(out_deg.values())))) if in_deg_mx <= 1 and out_deg_mx <= 1: ans = "Yes" else: ans = "No" print(ans)
30
21
586
386
def main(): s = eval(input()) t = eval(input()) r = [[-1] * 26 for _ in range(2)] bl = True for se, te in zip(s, t): si = ord(se) - ord("a") ti = ord(te) - ord("a") if r[0][si] < 0: r[0][si] = ti else: if r[0][si] != ti: bl = False break if r[1][ti] < 0: r[1][ti] = si else: if r[1][ti] != si: bl = False break print(("Yes" if bl else "No")) if __name__ == "__main__": main()
from collections import defaultdict s = eval(input()) t = eval(input()) in_deg = defaultdict(set) out_deg = defaultdict(set) for es, et in zip(s, t): out_deg[es].add(et) in_deg[et].add(es) in_deg_mx = max(list(map(len, list(in_deg.values())))) out_deg_mx = max(list(map(len, list(out_deg.values())))) if in_deg_mx <= 1 and out_deg_mx <= 1: ans = "Yes" else: ans = "No" print(ans)
false
30
[ "-def main():", "- s = eval(input())", "- t = eval(input())", "- r = [[-1] * 26 for _ in range(2)]", "- bl = True", "- for se, te in zip(s, t):", "- si = ord(se) - ord(\"a\")", "- ti = ord(te) - ord(\"a\")", "- if r[0][si] < 0:", "- r[0][si] = ti", "- else:", "- if r[0][si] != ti:", "- bl = False", "- break", "- if r[1][ti] < 0:", "- r[1][ti] = si", "- else:", "- if r[1][ti] != si:", "- bl = False", "- break", "- print((\"Yes\" if bl else \"No\"))", "+from collections import defaultdict", "-", "-if __name__ == \"__main__\":", "- main()", "+s = eval(input())", "+t = eval(input())", "+in_deg = defaultdict(set)", "+out_deg = defaultdict(set)", "+for es, et in zip(s, t):", "+ out_deg[es].add(et)", "+ in_deg[et].add(es)", "+in_deg_mx = max(list(map(len, list(in_deg.values()))))", "+out_deg_mx = max(list(map(len, list(out_deg.values()))))", "+if in_deg_mx <= 1 and out_deg_mx <= 1:", "+ ans = \"Yes\"", "+else:", "+ ans = \"No\"", "+print(ans)" ]
false
0.077558
0.077013
1.007075
[ "s050311483", "s888546538" ]
u133936772
p04013
python
s252331075
s252367576
148
118
3,188
3,064
Accepted
Accepted
20.27
n,a,*l=list(map(int,open(0).read().split())) R=2500 dp=[[0]*R*2,[0]*R*2] dp[0][0]=1 for i in range(n): for s in range(-R,R): dp[i+1&1][s]=dp[i&1][s]+dp[i&1][s-l[i]+a] print((dp[n&1][0]-1))
n,a,*l=list(map(int,open(0).read().split())) R=2500 dp=[[0]*R*2,[0]*R*2] dp[0][0]=1 t=0 for i in range(n): u=1-t for s in range(-R,R): dp[u][s]=dp[t][s]+dp[t][s-l[i]+a] t=u print((dp[t][0]-1))
8
11
193
204
n, a, *l = list(map(int, open(0).read().split())) R = 2500 dp = [[0] * R * 2, [0] * R * 2] dp[0][0] = 1 for i in range(n): for s in range(-R, R): dp[i + 1 & 1][s] = dp[i & 1][s] + dp[i & 1][s - l[i] + a] print((dp[n & 1][0] - 1))
n, a, *l = list(map(int, open(0).read().split())) R = 2500 dp = [[0] * R * 2, [0] * R * 2] dp[0][0] = 1 t = 0 for i in range(n): u = 1 - t for s in range(-R, R): dp[u][s] = dp[t][s] + dp[t][s - l[i] + a] t = u print((dp[t][0] - 1))
false
27.272727
[ "+t = 0", "+ u = 1 - t", "- dp[i + 1 & 1][s] = dp[i & 1][s] + dp[i & 1][s - l[i] + a]", "-print((dp[n & 1][0] - 1))", "+ dp[u][s] = dp[t][s] + dp[t][s - l[i] + a]", "+ t = u", "+print((dp[t][0] - 1))" ]
false
0.062098
0.058586
1.059958
[ "s252331075", "s252367576" ]
u947883560
p02726
python
s920085735
s633393904
1,595
1,170
120,168
3,828
Accepted
Accepted
26.65
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) import heapq from collections import defaultdict INF = float("inf") class Graph(object): def __init__(self, N): self.N = N self.E = defaultdict(list) def add_edge(self, s, t, w=1): self.E[s].append((t, w)) self.E[t].append((s, w)) def shortestPath(g: Graph, s: int): # 返り値 (dist, prev) # dist: 始点からの距離が格納されたリスト # prev: 始点から最短経路で移動する場合、各頂点に至る前の頂点のリスト dist = [INF]*g.N dist[s] = 0 prev = [None]*g.N Q = [] heapq.heappush(Q, (dist[s], s)) while len(Q) > 0: _, u = heapq.heappop(Q) for v, w in g.E[u]: if dist[v] > dist[u] + w: dist[v] = dist[u] + w prev[v] = u heapq.heappush(Q, (dist[v], v)) return dist, prev def solve(N: int, X: int, Y: int): g = Graph(N) for i in range(1, N): g.add_edge(i-1, i) g.add_edge(X-1, Y-1) ans = [0]*N for i in range(N): dist, prev = shortestPath(g, i) for j, d in enumerate(dist): if i < j: ans[d] += 1 print(*ans[1:], sep="\n") return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int X = int(next(tokens)) # type: int Y = int(next(tokens)) # type: int solve(N, X, Y) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) import heapq from collections import defaultdict INF = float("inf") def solve(N: int, X: int, Y: int): if X > Y: X, Y = Y, X ans = [0]*N for i in range(N): for j in range(i+1, N): d = min(abs(j-i), abs(i-(X-1))+1+abs(j-(Y-1))) ans[d] += 1 print(*ans[1:], sep="\n") return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int X = int(next(tokens)) # type: int Y = int(next(tokens)) # type: int solve(N, X, Y) if __name__ == '__main__': main()
72
36
1,590
776
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) import heapq from collections import defaultdict INF = float("inf") class Graph(object): def __init__(self, N): self.N = N self.E = defaultdict(list) def add_edge(self, s, t, w=1): self.E[s].append((t, w)) self.E[t].append((s, w)) def shortestPath(g: Graph, s: int): # 返り値 (dist, prev) # dist: 始点からの距離が格納されたリスト # prev: 始点から最短経路で移動する場合、各頂点に至る前の頂点のリスト dist = [INF] * g.N dist[s] = 0 prev = [None] * g.N Q = [] heapq.heappush(Q, (dist[s], s)) while len(Q) > 0: _, u = heapq.heappop(Q) for v, w in g.E[u]: if dist[v] > dist[u] + w: dist[v] = dist[u] + w prev[v] = u heapq.heappush(Q, (dist[v], v)) return dist, prev def solve(N: int, X: int, Y: int): g = Graph(N) for i in range(1, N): g.add_edge(i - 1, i) g.add_edge(X - 1, Y - 1) ans = [0] * N for i in range(N): dist, prev = shortestPath(g, i) for j, d in enumerate(dist): if i < j: ans[d] += 1 print(*ans[1:], sep="\n") return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int X = int(next(tokens)) # type: int Y = int(next(tokens)) # type: int solve(N, X, Y) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) import heapq from collections import defaultdict INF = float("inf") def solve(N: int, X: int, Y: int): if X > Y: X, Y = Y, X ans = [0] * N for i in range(N): for j in range(i + 1, N): d = min(abs(j - i), abs(i - (X - 1)) + 1 + abs(j - (Y - 1))) ans[d] += 1 print(*ans[1:], sep="\n") return def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int X = int(next(tokens)) # type: int Y = int(next(tokens)) # type: int solve(N, X, Y) if __name__ == "__main__": main()
false
50
[ "-class Graph(object):", "- def __init__(self, N):", "- self.N = N", "- self.E = defaultdict(list)", "-", "- def add_edge(self, s, t, w=1):", "- self.E[s].append((t, w))", "- self.E[t].append((s, w))", "-", "-", "-def shortestPath(g: Graph, s: int):", "- # 返り値 (dist, prev)", "- # dist: 始点からの距離が格納されたリスト", "- # prev: 始点から最短経路で移動する場合、各頂点に至る前の頂点のリスト", "- dist = [INF] * g.N", "- dist[s] = 0", "- prev = [None] * g.N", "- Q = []", "- heapq.heappush(Q, (dist[s], s))", "- while len(Q) > 0:", "- _, u = heapq.heappop(Q)", "- for v, w in g.E[u]:", "- if dist[v] > dist[u] + w:", "- dist[v] = dist[u] + w", "- prev[v] = u", "- heapq.heappush(Q, (dist[v], v))", "- return dist, prev", "-", "-", "- g = Graph(N)", "- for i in range(1, N):", "- g.add_edge(i - 1, i)", "- g.add_edge(X - 1, Y - 1)", "+ if X > Y:", "+ X, Y = Y, X", "- dist, prev = shortestPath(g, i)", "- for j, d in enumerate(dist):", "- if i < j:", "- ans[d] += 1", "+ for j in range(i + 1, N):", "+ d = min(abs(j - i), abs(i - (X - 1)) + 1 + abs(j - (Y - 1)))", "+ ans[d] += 1" ]
false
0.059028
0.063685
0.926873
[ "s920085735", "s633393904" ]
u058202717
p02264
python
s523323888
s461670836
1,060
770
16,836
36,640
Accepted
Accepted
27.36
class Queue: queue_list = [] def enqueue(self, a): self.queue_list.append(a) def dequeue(self): return self.queue_list.pop(0) def isEmpty(self): return len(self.queue_list) == 0 n, q = list([int(x) for x in input().strip().split()]) queue = Queue() for i in range(n): queue.enqueue(input().strip().split()) sum_time = 0 while not queue.isEmpty(): name, time = queue.dequeue() if int(time) <= q: sum_time += int(time) print((name + ' ' + str(sum_time))) else: queue.enqueue([name, str(int(time) - q)]) sum_time += q
class Queue: queue_list = [] start = 0 def enqueue(self, a): self.queue_list.append(a) def dequeue(self): assert self.start != len(self.queue_list), "オーバーフローが発生しました。" self.start += 1 return self.queue_list[self.start - 1] def isEmpty(self): return self.start == len(self.queue_list) n, q = list([int(x) for x in input().strip().split()]) queue = Queue() for i in range(n): queue.enqueue(input().strip().split()) sum_time = 0 while not queue.isEmpty(): name, time = queue.dequeue() if int(time) <= q: sum_time += int(time) print((name + ' ' + str(sum_time))) else: queue.enqueue([name, str(int(time) - q)]) sum_time += q
27
29
638
764
class Queue: queue_list = [] def enqueue(self, a): self.queue_list.append(a) def dequeue(self): return self.queue_list.pop(0) def isEmpty(self): return len(self.queue_list) == 0 n, q = list([int(x) for x in input().strip().split()]) queue = Queue() for i in range(n): queue.enqueue(input().strip().split()) sum_time = 0 while not queue.isEmpty(): name, time = queue.dequeue() if int(time) <= q: sum_time += int(time) print((name + " " + str(sum_time))) else: queue.enqueue([name, str(int(time) - q)]) sum_time += q
class Queue: queue_list = [] start = 0 def enqueue(self, a): self.queue_list.append(a) def dequeue(self): assert self.start != len(self.queue_list), "オーバーフローが発生しました。" self.start += 1 return self.queue_list[self.start - 1] def isEmpty(self): return self.start == len(self.queue_list) n, q = list([int(x) for x in input().strip().split()]) queue = Queue() for i in range(n): queue.enqueue(input().strip().split()) sum_time = 0 while not queue.isEmpty(): name, time = queue.dequeue() if int(time) <= q: sum_time += int(time) print((name + " " + str(sum_time))) else: queue.enqueue([name, str(int(time) - q)]) sum_time += q
false
6.896552
[ "+ start = 0", "- return self.queue_list.pop(0)", "+ assert self.start != len(self.queue_list), \"オーバーフローが発生しました。\"", "+ self.start += 1", "+ return self.queue_list[self.start - 1]", "- return len(self.queue_list) == 0", "+ return self.start == len(self.queue_list)" ]
false
0.036049
0.036098
0.998656
[ "s523323888", "s461670836" ]
u201234972
p02605
python
s199414631
s448620700
1,058
974
144,564
103,076
Accepted
Accepted
7.94
def get_collision(A,ans): A.sort() nowkey = -10**10 prevcoor = -10**10 ret = ans[0] for key, coor, a in A: if key != nowkey: if a == 1: nowkey = key prevcoor = coor continue else: continue if a == 1: prevcoor = coor continue if (coor - prevcoor)*5 < ret: ret = (coor - prevcoor)*5 ans[0] = ret def main(): N = int( eval(input())) XYU = [ tuple( input().split()) for _ in range(N)] U = [] R = [] D = [] L = [] for x, y, u in XYU: x, y = int(x), int(y) if u == "U": U.append((x,y)) elif u == "D": D.append((x,y)) elif u == "L": L.append((x,y)) else: R.append((x,y)) ans = [10**10] UD = [(x,y,1) for x, y in U] + [(x,y,-1) for x, y in D] get_collision(UD, ans) LR = [(y,x,1) for x, y in R] + [(y,x,-1) for x, y in L] get_collision(LR, ans) RU = [(x+y,x-y,1) for x, y in R] + [(x+y,x-y,-1) for x,y in U] get_collision(RU, ans) LD = [(x+y,x-y,1) for x, y in D] + [(x+y,x-y,-1) for x,y in L] get_collision(LD,ans) LU = [(x-y,x+y,1) for x,y in U] + [(x-y,x+y,-1) for x,y in L] get_collision(LU,ans) RD = [(x-y,x+y,1) for x,y in R] + [(x-y,x+y,-1) for x,y in D] get_collision(RD,ans) if ans[0] < 10**10: print((ans[0])) else: print("SAFE") if __name__ == '__main__': main()
N = int( eval(input())) XYU = [ tuple( input().split()) for _ in range(N)] U = [] R = [] D = [] L = [] for x, y, u in XYU: x, y = int(x), int(y) if u == "U": U.append((x,y)) elif u == "D": D.append((x,y)) elif u == "L": L.append((x,y)) else: R.append((x,y)) ans = [10**9] def z(A): A.sort() n = -10**10 p = -10**10 for k, c, a in A: if k != n: if a == 1: n = k p = c continue else: continue if a == 1: p = c continue if (c - p)*5 < ans[0]: ans[0] = (c - p)*5 z([(x,y,1) for x, y in U] + [(x,y,-1) for x, y in D]) z([(y,x,1) for x, y in R] + [(y,x,-1) for x, y in L]) z([(x+y,x-y,1) for x, y in R] + [(x+y,x-y,-1) for x,y in U]) z([(x+y,x-y,1) for x, y in D] + [(x+y,x-y,-1) for x,y in L]) z([(x-y,x+y,1) for x,y in U] + [(x-y,x+y,-1) for x,y in L]) z([(x-y,x+y,1) for x,y in R] + [(x-y,x+y,-1) for x,y in D]) if ans[0] < 10**9: print((ans[0])) else: print("SAFE")
58
44
1,594
1,123
def get_collision(A, ans): A.sort() nowkey = -(10**10) prevcoor = -(10**10) ret = ans[0] for key, coor, a in A: if key != nowkey: if a == 1: nowkey = key prevcoor = coor continue else: continue if a == 1: prevcoor = coor continue if (coor - prevcoor) * 5 < ret: ret = (coor - prevcoor) * 5 ans[0] = ret def main(): N = int(eval(input())) XYU = [tuple(input().split()) for _ in range(N)] U = [] R = [] D = [] L = [] for x, y, u in XYU: x, y = int(x), int(y) if u == "U": U.append((x, y)) elif u == "D": D.append((x, y)) elif u == "L": L.append((x, y)) else: R.append((x, y)) ans = [10**10] UD = [(x, y, 1) for x, y in U] + [(x, y, -1) for x, y in D] get_collision(UD, ans) LR = [(y, x, 1) for x, y in R] + [(y, x, -1) for x, y in L] get_collision(LR, ans) RU = [(x + y, x - y, 1) for x, y in R] + [(x + y, x - y, -1) for x, y in U] get_collision(RU, ans) LD = [(x + y, x - y, 1) for x, y in D] + [(x + y, x - y, -1) for x, y in L] get_collision(LD, ans) LU = [(x - y, x + y, 1) for x, y in U] + [(x - y, x + y, -1) for x, y in L] get_collision(LU, ans) RD = [(x - y, x + y, 1) for x, y in R] + [(x - y, x + y, -1) for x, y in D] get_collision(RD, ans) if ans[0] < 10**10: print((ans[0])) else: print("SAFE") if __name__ == "__main__": main()
N = int(eval(input())) XYU = [tuple(input().split()) for _ in range(N)] U = [] R = [] D = [] L = [] for x, y, u in XYU: x, y = int(x), int(y) if u == "U": U.append((x, y)) elif u == "D": D.append((x, y)) elif u == "L": L.append((x, y)) else: R.append((x, y)) ans = [10**9] def z(A): A.sort() n = -(10**10) p = -(10**10) for k, c, a in A: if k != n: if a == 1: n = k p = c continue else: continue if a == 1: p = c continue if (c - p) * 5 < ans[0]: ans[0] = (c - p) * 5 z([(x, y, 1) for x, y in U] + [(x, y, -1) for x, y in D]) z([(y, x, 1) for x, y in R] + [(y, x, -1) for x, y in L]) z([(x + y, x - y, 1) for x, y in R] + [(x + y, x - y, -1) for x, y in U]) z([(x + y, x - y, 1) for x, y in D] + [(x + y, x - y, -1) for x, y in L]) z([(x - y, x + y, 1) for x, y in U] + [(x - y, x + y, -1) for x, y in L]) z([(x - y, x + y, 1) for x, y in R] + [(x - y, x + y, -1) for x, y in D]) if ans[0] < 10**9: print((ans[0])) else: print("SAFE")
false
24.137931
[ "-def get_collision(A, ans):", "+N = int(eval(input()))", "+XYU = [tuple(input().split()) for _ in range(N)]", "+U = []", "+R = []", "+D = []", "+L = []", "+for x, y, u in XYU:", "+ x, y = int(x), int(y)", "+ if u == \"U\":", "+ U.append((x, y))", "+ elif u == \"D\":", "+ D.append((x, y))", "+ elif u == \"L\":", "+ L.append((x, y))", "+ else:", "+ R.append((x, y))", "+ans = [10**9]", "+", "+", "+def z(A):", "- nowkey = -(10**10)", "- prevcoor = -(10**10)", "- ret = ans[0]", "- for key, coor, a in A:", "- if key != nowkey:", "+ n = -(10**10)", "+ p = -(10**10)", "+ for k, c, a in A:", "+ if k != n:", "- nowkey = key", "- prevcoor = coor", "+ n = k", "+ p = c", "- prevcoor = coor", "+ p = c", "- if (coor - prevcoor) * 5 < ret:", "- ret = (coor - prevcoor) * 5", "- ans[0] = ret", "+ if (c - p) * 5 < ans[0]:", "+ ans[0] = (c - p) * 5", "-def main():", "- N = int(eval(input()))", "- XYU = [tuple(input().split()) for _ in range(N)]", "- U = []", "- R = []", "- D = []", "- L = []", "- for x, y, u in XYU:", "- x, y = int(x), int(y)", "- if u == \"U\":", "- U.append((x, y))", "- elif u == \"D\":", "- D.append((x, y))", "- elif u == \"L\":", "- L.append((x, y))", "- else:", "- R.append((x, y))", "- ans = [10**10]", "- UD = [(x, y, 1) for x, y in U] + [(x, y, -1) for x, y in D]", "- get_collision(UD, ans)", "- LR = [(y, x, 1) for x, y in R] + [(y, x, -1) for x, y in L]", "- get_collision(LR, ans)", "- RU = [(x + y, x - y, 1) for x, y in R] + [(x + y, x - y, -1) for x, y in U]", "- get_collision(RU, ans)", "- LD = [(x + y, x - y, 1) for x, y in D] + [(x + y, x - y, -1) for x, y in L]", "- get_collision(LD, ans)", "- LU = [(x - y, x + y, 1) for x, y in U] + [(x - y, x + y, -1) for x, y in L]", "- get_collision(LU, ans)", "- RD = [(x - y, x + y, 1) for x, y in R] + [(x - y, x + y, -1) for x, y in D]", "- get_collision(RD, ans)", "- if ans[0] < 10**10:", "- print((ans[0]))", "- else:", "- print(\"SAFE\")", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+z([(x, y, 1) for x, y in U] + [(x, y, -1) for x, y in D])", "+z([(y, x, 1) for x, y in R] + [(y, x, -1) for x, y in L])", "+z([(x + y, x - y, 1) for x, y in R] + [(x + y, x - y, -1) for x, y in U])", "+z([(x + y, x - y, 1) for x, y in D] + [(x + y, x - y, -1) for x, y in L])", "+z([(x - y, x + y, 1) for x, y in U] + [(x - y, x + y, -1) for x, y in L])", "+z([(x - y, x + y, 1) for x, y in R] + [(x - y, x + y, -1) for x, y in D])", "+if ans[0] < 10**9:", "+ print((ans[0]))", "+else:", "+ print(\"SAFE\")" ]
false
0.044606
0.044373
1.005246
[ "s199414631", "s448620700" ]
u455707769
p02984
python
s558428161
s622401193
319
262
23,064
23,976
Accepted
Accepted
17.87
import numpy as np import sys n = int(input()) a = list(map(int, input().split())) a_sum = sum(a) # x[i]はi番目のダムに溜まった水の半分 x = [] x_0 = int(a_sum/2) for i in range(int((n-1)/2)): x_0 -= a[2*i+1] x.append(x_0) x_tmp = x_0 for i in range(n-1): x_tmp = a[i] - x_tmp x.append(x_tmp) for wa in x: print(wa*2, end=' ')
import numpy as np import sys n = int(input()) a = list(map(int, input().split())) a_sum = sum(a) # x[i]はi番目のダムに溜まった水の半分 x = [] x_0 = int(a_sum/2) for i in range(int((n-1)/2)): x_0 -= a[2*i+1] x.append(x_0) x_tmp = x_0 for i in range(n-1): x_tmp = a[i] - x_tmp x.append(x_tmp) x = list(map(lambda y: y*2, x)) print(*x, sep=' ')
25
26
359
374
import numpy as np import sys n = int(input()) a = list(map(int, input().split())) a_sum = sum(a) # x[i]はi番目のダムに溜まった水の半分 x = [] x_0 = int(a_sum / 2) for i in range(int((n - 1) / 2)): x_0 -= a[2 * i + 1] x.append(x_0) x_tmp = x_0 for i in range(n - 1): x_tmp = a[i] - x_tmp x.append(x_tmp) for wa in x: print(wa * 2, end=" ")
import numpy as np import sys n = int(input()) a = list(map(int, input().split())) a_sum = sum(a) # x[i]はi番目のダムに溜まった水の半分 x = [] x_0 = int(a_sum / 2) for i in range(int((n - 1) / 2)): x_0 -= a[2 * i + 1] x.append(x_0) x_tmp = x_0 for i in range(n - 1): x_tmp = a[i] - x_tmp x.append(x_tmp) x = list(map(lambda y: y * 2, x)) print(*x, sep=" ")
false
3.846154
[ "-for wa in x:", "- print(wa * 2, end=\" \")", "+x = list(map(lambda y: y * 2, x))", "+print(*x, sep=\" \")" ]
false
0.047046
0.047139
0.99803
[ "s558428161", "s622401193" ]
u867848444
p04030
python
s041261733
s978761760
19
17
3,060
2,940
Accepted
Accepted
10.53
s=eval(input()) ans='' for i in s: if i=='0' or i=='1': ans+=i else: ans=ans[:-1] print(ans)
s=eval(input()) ans='' for i in range(len(s)): a=s[i] if a=='0': ans+='0' elif a=='1': ans+='1' else: if len(ans)!=0: ans=ans[:-1] print(ans)
9
13
119
200
s = eval(input()) ans = "" for i in s: if i == "0" or i == "1": ans += i else: ans = ans[:-1] print(ans)
s = eval(input()) ans = "" for i in range(len(s)): a = s[i] if a == "0": ans += "0" elif a == "1": ans += "1" else: if len(ans) != 0: ans = ans[:-1] print(ans)
false
30.769231
[ "-for i in s:", "- if i == \"0\" or i == \"1\":", "- ans += i", "+for i in range(len(s)):", "+ a = s[i]", "+ if a == \"0\":", "+ ans += \"0\"", "+ elif a == \"1\":", "+ ans += \"1\"", "- ans = ans[:-1]", "+ if len(ans) != 0:", "+ ans = ans[:-1]" ]
false
0.068617
0.065772
1.043255
[ "s041261733", "s978761760" ]
u692453235
p03624
python
s105459053
s122754341
38
30
9,900
9,188
Accepted
Accepted
21.05
import string al = string.ascii_lowercase S = set(eval(input())) for i in al: if i not in S: print(i) exit() print("None")
S = set(eval(input())) Flag = [True]*26 for i in S: Flag[ord(i)-97] = False for i in range(26): if Flag[i]: print((chr(97+i))) exit() print("None")
11
12
139
165
import string al = string.ascii_lowercase S = set(eval(input())) for i in al: if i not in S: print(i) exit() print("None")
S = set(eval(input())) Flag = [True] * 26 for i in S: Flag[ord(i) - 97] = False for i in range(26): if Flag[i]: print((chr(97 + i))) exit() print("None")
false
8.333333
[ "-import string", "-", "-al = string.ascii_lowercase", "-for i in al:", "- if i not in S:", "- print(i)", "+Flag = [True] * 26", "+for i in S:", "+ Flag[ord(i) - 97] = False", "+for i in range(26):", "+ if Flag[i]:", "+ print((chr(97 + i)))" ]
false
0.101978
0.047328
2.154718
[ "s105459053", "s122754341" ]
u144540235
p02686
python
s398311799
s781937073
1,426
1,175
42,432
26,600
Accepted
Accepted
17.6
def process(tab, first, end): #print(tab) #print(first, end) total = first for i in tab: if (i[1] > total): return ("No") total += i[0] if (total < 0): return ("No") if (total == end): return ("Yes") return ("No") N = int(eval(input())) first = 0 last = 0 clean = 0 tab = [] total = 0 for i in range(N): s = eval(input()) avant = 0 apres = 0 for j in s: if (j == '('): apres += 1 elif (j == ')'): if (apres > 0): apres -= 1 else: avant += 1 if (avant == 0 and apres > 0): first += apres elif (apres == 0 and avant > 0): last += avant elif (avant > 0 or apres > 0): tab.append((apres - avant, avant, apres, s)) else: clean += 1 total += avant - apres if (first == -1 and clean > 0): first = 0 clean -= 1 if (last == -1 and clean > 0): last = 0 tab = sorted(tab) tab = tab[::-1] if (total == 0 and first > -1 and last > -1): res = process(tab, first, last) else: if (total == 0 and N == 1): res = "Yes" else: res = "No" print(res)
# **************************************************************************** # # # # __ __ .____ .__ __. ____ # # F-bracketSequencing.py | | | || _ \ | \/ | / | # # | | | || |_| || \ / || ,--' # # By: ayahyao <[email protected]> | | | || __/ | |\/| || | # # | `-' || | | | | || `--. # # Created: 2020/05/10 18:38 by Anas \_____/ |_| |_| |_| \____| # # Updated: 2020/05/10 18:42 by Anas # # # # **************************************************************************** # def process(tab, beginning, end): total = beginning for i in tab: if (i[1] > total or total + i[0] < 0): return ("No") total += i[0] if (total == end): return ("Yes") return ("No") def parsing(N): beginning, ending = 0,0 clean = 0 total = 0 tab = [] for i in range(N): s = eval(input()) before, after = 0, 0 for j in s: if (j == '('): after += 1 elif (j == ')'): if (after > 0): after -= 1 else: before += 1 if (before == 0 and after > 0): beginning += after elif (after == 0 and before > 0): ending += before elif (before > 0 or after > 0): tab.append((after - before, before, after)) else: clean += 1 total += before - after tab = sorted(tab)[::-1] return tab, total, beginning, ending, clean N = int(eval(input())) tab, total, beginning, ending, clean = parsing(N) if (total == 0 and N == 1): res = "Yes" elif ((total != 0) or ((min(beginning, ending) == 0 and clean == 0) or (max(beginning, ending) == 0 and clean == 1))): res = "No" else: res = process(tab, beginning, ending) print(res)
71
62
1,280
2,281
def process(tab, first, end): # print(tab) # print(first, end) total = first for i in tab: if i[1] > total: return "No" total += i[0] if total < 0: return "No" if total == end: return "Yes" return "No" N = int(eval(input())) first = 0 last = 0 clean = 0 tab = [] total = 0 for i in range(N): s = eval(input()) avant = 0 apres = 0 for j in s: if j == "(": apres += 1 elif j == ")": if apres > 0: apres -= 1 else: avant += 1 if avant == 0 and apres > 0: first += apres elif apres == 0 and avant > 0: last += avant elif avant > 0 or apres > 0: tab.append((apres - avant, avant, apres, s)) else: clean += 1 total += avant - apres if first == -1 and clean > 0: first = 0 clean -= 1 if last == -1 and clean > 0: last = 0 tab = sorted(tab) tab = tab[::-1] if total == 0 and first > -1 and last > -1: res = process(tab, first, last) else: if total == 0 and N == 1: res = "Yes" else: res = "No" print(res)
# **************************************************************************** # # # # __ __ .____ .__ __. ____ # # F-bracketSequencing.py | | | || _ \ | \/ | / | # # | | | || |_| || \ / || ,--' # # By: ayahyao <[email protected]> | | | || __/ | |\/| || | # # | `-' || | | | | || `--. # # Created: 2020/05/10 18:38 by Anas \_____/ |_| |_| |_| \____| # # Updated: 2020/05/10 18:42 by Anas # # # # **************************************************************************** # def process(tab, beginning, end): total = beginning for i in tab: if i[1] > total or total + i[0] < 0: return "No" total += i[0] if total == end: return "Yes" return "No" def parsing(N): beginning, ending = 0, 0 clean = 0 total = 0 tab = [] for i in range(N): s = eval(input()) before, after = 0, 0 for j in s: if j == "(": after += 1 elif j == ")": if after > 0: after -= 1 else: before += 1 if before == 0 and after > 0: beginning += after elif after == 0 and before > 0: ending += before elif before > 0 or after > 0: tab.append((after - before, before, after)) else: clean += 1 total += before - after tab = sorted(tab)[::-1] return tab, total, beginning, ending, clean N = int(eval(input())) tab, total, beginning, ending, clean = parsing(N) if total == 0 and N == 1: res = "Yes" elif (total != 0) or ( (min(beginning, ending) == 0 and clean == 0) or (max(beginning, ending) == 0 and clean == 1) ): res = "No" else: res = process(tab, beginning, ending) print(res)
false
12.676056
[ "-def process(tab, first, end):", "- # print(tab)", "- # print(first, end)", "- total = first", "+# **************************************************************************** #", "+# #", "+# __ __ .____ .__ __. ____ #", "+# F-bracketSequencing.py | | | || _ \\ | \\/ | / | #", "+# | | | || |_| || \\ / || ,--' #", "+# By: ayahyao <[email protected]> | | | || __/ | |\\/| || | #", "+# | `-' || | | | | || `--. #", "+# Created: 2020/05/10 18:38 by Anas \\_____/ |_| |_| |_| \\____| #", "+# Updated: 2020/05/10 18:42 by Anas #", "+# #", "+# **************************************************************************** #", "+def process(tab, beginning, end):", "+ total = beginning", "- if i[1] > total:", "+ if i[1] > total or total + i[0] < 0:", "- if total < 0:", "- return \"No\"", "+def parsing(N):", "+ beginning, ending = 0, 0", "+ clean = 0", "+ total = 0", "+ tab = []", "+ for i in range(N):", "+ s = eval(input())", "+ before, after = 0, 0", "+ for j in s:", "+ if j == \"(\":", "+ after += 1", "+ elif j == \")\":", "+ if after > 0:", "+ after -= 1", "+ else:", "+ before += 1", "+ if before == 0 and after > 0:", "+ beginning += after", "+ elif after == 0 and before > 0:", "+ ending += before", "+ elif before > 0 or after > 0:", "+ tab.append((after - before, before, after))", "+ else:", "+ clean += 1", "+ total += before - after", "+ tab = sorted(tab)[::-1]", "+ return tab, total, beginning, ending, clean", "+", "+", "-first = 0", "-last = 0", "-clean = 0", "-tab = []", "-total = 0", "-for i in range(N):", "- s = eval(input())", "- avant = 0", "- apres = 0", "- for j in s:", "- if j == \"(\":", "- apres += 1", "- elif j == \")\":", "- if apres > 0:", "- apres -= 1", "- else:", "- avant += 1", "- if avant == 0 and apres > 0:", "- first += apres", "- elif apres == 0 and avant > 0:", "- last += avant", "- elif avant > 0 or apres > 0:", "- tab.append((apres - avant, avant, apres, s))", "- else:", "- clean += 1", "- total += avant - apres", "-if first == -1 and clean > 0:", "- first = 0", "- clean -= 1", "-if last == -1 and clean > 0:", "- last = 0", "-tab = sorted(tab)", "-tab = tab[::-1]", "-if total == 0 and first > -1 and last > -1:", "- res = process(tab, first, last)", "+tab, total, beginning, ending, clean = parsing(N)", "+if total == 0 and N == 1:", "+ res = \"Yes\"", "+elif (total != 0) or (", "+ (min(beginning, ending) == 0 and clean == 0)", "+ or (max(beginning, ending) == 0 and clean == 1)", "+):", "+ res = \"No\"", "- if total == 0 and N == 1:", "- res = \"Yes\"", "- else:", "- res = \"No\"", "+ res = process(tab, beginning, ending)" ]
false
0.036929
0.048066
0.768306
[ "s398311799", "s781937073" ]
u009961299
p02412
python
s855987120
s832622330
580
280
5,632
5,652
Accepted
Accepted
51.72
import itertools while True: c = input().split() n, x = int(c[0]), int(c[1]) if n == x == 0: break count = 0 for i, j, k in itertools.combinations(list(range(1, n + 1)), 3): if i + j + k == x: count += 1 print(count)
import itertools while True: c = input().split() n, x = int(c[0]), int(c[1]) if n == x == 0: break print((sum([1 for i, j, k in itertools.combinations(list(range(1, n + 1)), 3) if i + j + k == x])))
13
9
277
225
import itertools while True: c = input().split() n, x = int(c[0]), int(c[1]) if n == x == 0: break count = 0 for i, j, k in itertools.combinations(list(range(1, n + 1)), 3): if i + j + k == x: count += 1 print(count)
import itertools while True: c = input().split() n, x = int(c[0]), int(c[1]) if n == x == 0: break print( ( sum( [ 1 for i, j, k in itertools.combinations(list(range(1, n + 1)), 3) if i + j + k == x ] ) ) )
false
30.769231
[ "- count = 0", "- for i, j, k in itertools.combinations(list(range(1, n + 1)), 3):", "- if i + j + k == x:", "- count += 1", "- print(count)", "+ print(", "+ (", "+ sum(", "+ [", "+ 1", "+ for i, j, k in itertools.combinations(list(range(1, n + 1)), 3)", "+ if i + j + k == x", "+ ]", "+ )", "+ )", "+ )" ]
false
0.038376
0.038614
0.993827
[ "s855987120", "s832622330" ]
u354411673
p03478
python
s861148999
s085773801
46
29
3,404
3,060
Accepted
Accepted
36.96
n,a,b = list(map(int, input().split())) ns = str(n) numarr = list(range(1, n+1)) keta = [0] for num in numarr: sum1 = 0 for i in range(len(str(num))): sum1 += int(str(num)[i]) if (a <= sum1 and sum1 <= b): keta.append(num) print((sum(keta)))
n,a,b = list(map(int, input().split())) nums = list(range(1,n + 1)) ans = 0 for num in nums: sum = 0 sum += num % 10 wari = num // 10 while wari > 0: sum += wari % 10 wari = wari // 10 if sum >= a and sum <= b: ans += num print(ans)
20
19
283
296
n, a, b = list(map(int, input().split())) ns = str(n) numarr = list(range(1, n + 1)) keta = [0] for num in numarr: sum1 = 0 for i in range(len(str(num))): sum1 += int(str(num)[i]) if a <= sum1 and sum1 <= b: keta.append(num) print((sum(keta)))
n, a, b = list(map(int, input().split())) nums = list(range(1, n + 1)) ans = 0 for num in nums: sum = 0 sum += num % 10 wari = num // 10 while wari > 0: sum += wari % 10 wari = wari // 10 if sum >= a and sum <= b: ans += num print(ans)
false
5
[ "-ns = str(n)", "-numarr = list(range(1, n + 1))", "-keta = [0]", "-for num in numarr:", "- sum1 = 0", "- for i in range(len(str(num))):", "- sum1 += int(str(num)[i])", "- if a <= sum1 and sum1 <= b:", "- keta.append(num)", "-print((sum(keta)))", "+nums = list(range(1, n + 1))", "+ans = 0", "+for num in nums:", "+ sum = 0", "+ sum += num % 10", "+ wari = num // 10", "+ while wari > 0:", "+ sum += wari % 10", "+ wari = wari // 10", "+ if sum >= a and sum <= b:", "+ ans += num", "+print(ans)" ]
false
0.043675
0.037686
1.158908
[ "s861148999", "s085773801" ]
u631277801
p03283
python
s704969729
s901853708
1,129
811
98,140
46,652
Accepted
Accepted
28.17
from itertools import accumulate import sys sdin = sys.stdin.readline n,m,q = list(map(int, sdin().split())) lr = [] for i in range(m): l,r = list(map(int, sdin().split())) lr.append(tuple([l-1, r-1])) pq = [] for _ in range(q): p,q = list(map(int, sdin().split())) pq.append(tuple([p-1, q-1])) # n×nフィールドを用意して各列車のl,r点をプロット field = [[0 for _ in range(n)] for _ in range(n)] for l, r in lr: field[l][r] += 1 # fieldのx方向の累積和を取る field_cum = [list(accumulate(field[i])) for i in range(n)] # 各クエリに対し、rがpからqの間に入っているものを足し合わせる for p,q in pq: ans = 0 for i in range(p,q+1): ans += field_cum[i][q] print(ans)
from itertools import accumulate import sys sdin = sys.stdin.readline n,m,q = list(map(int, sdin().split())) lr = [] for i in range(m): l,r = list(map(int, sdin().split())) lr.append(tuple([l-1, r-1])) pq = [] for _ in range(q): p,q = list(map(int, sdin().split())) pq.append(tuple([p-1, q-1])) # n×nフィールドを用意して各列車のl,r点をプロット field = [[0 for _ in range(n)] for _ in range(n)] for l, r in lr: field[l][r] += 1 # fieldのx方向の累積和を取る field_cum = [list(accumulate(field[i])) for i in range(n)] # field_cumのy方向の累積和をとる for r in range(1,n): for l in range(n): field_cum[r][l] += field_cum[r-1][l] # 各クエリに対し、長方形内部にあるものの個数を求める for p,q in pq: if p > 0: print((field_cum[q][q] - field_cum[p-1][q] - field_cum[q][p-1] + field_cum[p-1][p-1])) else: print((field_cum[q][q]))
31
37
673
862
from itertools import accumulate import sys sdin = sys.stdin.readline n, m, q = list(map(int, sdin().split())) lr = [] for i in range(m): l, r = list(map(int, sdin().split())) lr.append(tuple([l - 1, r - 1])) pq = [] for _ in range(q): p, q = list(map(int, sdin().split())) pq.append(tuple([p - 1, q - 1])) # n×nフィールドを用意して各列車のl,r点をプロット field = [[0 for _ in range(n)] for _ in range(n)] for l, r in lr: field[l][r] += 1 # fieldのx方向の累積和を取る field_cum = [list(accumulate(field[i])) for i in range(n)] # 各クエリに対し、rがpからqの間に入っているものを足し合わせる for p, q in pq: ans = 0 for i in range(p, q + 1): ans += field_cum[i][q] print(ans)
from itertools import accumulate import sys sdin = sys.stdin.readline n, m, q = list(map(int, sdin().split())) lr = [] for i in range(m): l, r = list(map(int, sdin().split())) lr.append(tuple([l - 1, r - 1])) pq = [] for _ in range(q): p, q = list(map(int, sdin().split())) pq.append(tuple([p - 1, q - 1])) # n×nフィールドを用意して各列車のl,r点をプロット field = [[0 for _ in range(n)] for _ in range(n)] for l, r in lr: field[l][r] += 1 # fieldのx方向の累積和を取る field_cum = [list(accumulate(field[i])) for i in range(n)] # field_cumのy方向の累積和をとる for r in range(1, n): for l in range(n): field_cum[r][l] += field_cum[r - 1][l] # 各クエリに対し、長方形内部にあるものの個数を求める for p, q in pq: if p > 0: print( ( field_cum[q][q] - field_cum[p - 1][q] - field_cum[q][p - 1] + field_cum[p - 1][p - 1] ) ) else: print((field_cum[q][q]))
false
16.216216
[ "-# 各クエリに対し、rがpからqの間に入っているものを足し合わせる", "+# field_cumのy方向の累積和をとる", "+for r in range(1, n):", "+ for l in range(n):", "+ field_cum[r][l] += field_cum[r - 1][l]", "+# 各クエリに対し、長方形内部にあるものの個数を求める", "- ans = 0", "- for i in range(p, q + 1):", "- ans += field_cum[i][q]", "- print(ans)", "+ if p > 0:", "+ print(", "+ (", "+ field_cum[q][q]", "+ - field_cum[p - 1][q]", "+ - field_cum[q][p - 1]", "+ + field_cum[p - 1][p - 1]", "+ )", "+ )", "+ else:", "+ print((field_cum[q][q]))" ]
false
0.057749
0.042323
1.364482
[ "s704969729", "s901853708" ]
u883048396
p03659
python
s557565267
s598255141
166
144
23,788
23,788
Accepted
Accepted
13.25
def 解(): iN = int(eval(input())) aA = [int(_) for _ in input().split()] #itertools をつかわず 累積和でやってみると? aAc = [0]*iN aAc[0] = aA[0] for i in range(1,iN): aAc[i] = aAc[i-1] + aA[i] iD = aAc[-1] minDiff = 10**9 *2 for i in range(iN-1): minDiff = min(minDiff,abs(iD-2*aAc[i])) print(minDiff) 解()
def 解(): iN = int(eval(input())) aA = [int(_) for _ in input().split()] iD = sum(aA) iF = 0 minDiff = 10**9 * 2 for a in aA[:-1] : iF += a thisDiff = abs(iD - 2*iF) minDiff = min(minDiff , thisDiff) print(minDiff) 解()
15
13
355
277
def 解(): iN = int(eval(input())) aA = [int(_) for _ in input().split()] # itertools をつかわず 累積和でやってみると? aAc = [0] * iN aAc[0] = aA[0] for i in range(1, iN): aAc[i] = aAc[i - 1] + aA[i] iD = aAc[-1] minDiff = 10**9 * 2 for i in range(iN - 1): minDiff = min(minDiff, abs(iD - 2 * aAc[i])) print(minDiff) 解()
def 解(): iN = int(eval(input())) aA = [int(_) for _ in input().split()] iD = sum(aA) iF = 0 minDiff = 10**9 * 2 for a in aA[:-1]: iF += a thisDiff = abs(iD - 2 * iF) minDiff = min(minDiff, thisDiff) print(minDiff) 解()
false
13.333333
[ "- # itertools をつかわず 累積和でやってみると?", "- aAc = [0] * iN", "- aAc[0] = aA[0]", "- for i in range(1, iN):", "- aAc[i] = aAc[i - 1] + aA[i]", "- iD = aAc[-1]", "+ iD = sum(aA)", "+ iF = 0", "- for i in range(iN - 1):", "- minDiff = min(minDiff, abs(iD - 2 * aAc[i]))", "+ for a in aA[:-1]:", "+ iF += a", "+ thisDiff = abs(iD - 2 * iF)", "+ minDiff = min(minDiff, thisDiff)" ]
false
0.036836
0.036465
1.010158
[ "s557565267", "s598255141" ]
u490489966
p03042
python
s920107022
s346578537
22
17
3,060
3,060
Accepted
Accepted
22.73
#B s = list(eval(input())) left = int(s[0])*10+int(s[1]) right = int(s[2])*10+int(s[3]) if 0 < left <= 12: if 0 < right <= 12: print("AMBIGUOUS") else: print('MMYY') elif 0 < right <= 12: print('YYMM') else: print('NA')
#B s = eval(input()) # print(int(s[0:2]), int(s[2:4])) if 1 <= int(s[0:2]) <= 12 and 1 <= int(s[2:4]) <= 12: print('AMBIGUOUS') elif 1 <= int(s[0:2]) <= 12: print('MMYY') elif 1 <= int(s[2:4]) <= 12: print('YYMM') else: print('NA')
13
11
258
252
# B s = list(eval(input())) left = int(s[0]) * 10 + int(s[1]) right = int(s[2]) * 10 + int(s[3]) if 0 < left <= 12: if 0 < right <= 12: print("AMBIGUOUS") else: print("MMYY") elif 0 < right <= 12: print("YYMM") else: print("NA")
# B s = eval(input()) # print(int(s[0:2]), int(s[2:4])) if 1 <= int(s[0:2]) <= 12 and 1 <= int(s[2:4]) <= 12: print("AMBIGUOUS") elif 1 <= int(s[0:2]) <= 12: print("MMYY") elif 1 <= int(s[2:4]) <= 12: print("YYMM") else: print("NA")
false
15.384615
[ "-s = list(eval(input()))", "-left = int(s[0]) * 10 + int(s[1])", "-right = int(s[2]) * 10 + int(s[3])", "-if 0 < left <= 12:", "- if 0 < right <= 12:", "- print(\"AMBIGUOUS\")", "- else:", "- print(\"MMYY\")", "-elif 0 < right <= 12:", "+s = eval(input())", "+# print(int(s[0:2]), int(s[2:4]))", "+if 1 <= int(s[0:2]) <= 12 and 1 <= int(s[2:4]) <= 12:", "+ print(\"AMBIGUOUS\")", "+elif 1 <= int(s[0:2]) <= 12:", "+ print(\"MMYY\")", "+elif 1 <= int(s[2:4]) <= 12:" ]
false
0.110558
0.138077
0.800699
[ "s920107022", "s346578537" ]
u638456847
p02971
python
s576071661
s174118735
701
267
15,676
25,036
Accepted
Accepted
61.91
N = int(eval(input())) a = [int(eval(input())) for i in range(N)] lmax = [0] rmax = [0] for i in range(N-1): lmax.append(max(lmax[i], a[i])) rmax.append(max(rmax[i], a[-(i+1)])) for i in range(N): print((max(lmax[i], rmax[-(i+1)])))
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): N,*A = list(map(int, read().split())) A_ = sorted(A) m = max(A) for a in A: if a == m: print((A_[-2])) else: print(m) if __name__ == "__main__": main()
12
20
244
335
N = int(eval(input())) a = [int(eval(input())) for i in range(N)] lmax = [0] rmax = [0] for i in range(N - 1): lmax.append(max(lmax[i], a[i])) rmax.append(max(rmax[i], a[-(i + 1)])) for i in range(N): print((max(lmax[i], rmax[-(i + 1)])))
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): N, *A = list(map(int, read().split())) A_ = sorted(A) m = max(A) for a in A: if a == m: print((A_[-2])) else: print(m) if __name__ == "__main__": main()
false
40
[ "-N = int(eval(input()))", "-a = [int(eval(input())) for i in range(N)]", "-lmax = [0]", "-rmax = [0]", "-for i in range(N - 1):", "- lmax.append(max(lmax[i], a[i]))", "- rmax.append(max(rmax[i], a[-(i + 1)]))", "-for i in range(N):", "- print((max(lmax[i], rmax[-(i + 1)])))", "+import sys", "+", "+read = sys.stdin.read", "+readline = sys.stdin.readline", "+readlines = sys.stdin.readlines", "+", "+", "+def main():", "+ N, *A = list(map(int, read().split()))", "+ A_ = sorted(A)", "+ m = max(A)", "+ for a in A:", "+ if a == m:", "+ print((A_[-2]))", "+ else:", "+ print(m)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.116842
0.079581
1.468217
[ "s576071661", "s174118735" ]
u893063840
p02939
python
s864957796
s677626839
100
69
3,500
3,500
Accepted
Accepted
31
# -*- coding: utf-8 -*- s = eval(input()) i = 1 tmp = s[0] cnt = 1 while i < len(s): if s[i] == tmp: if i == len(s) - 1: break tmp = s[i:i+2] i += 2 else: tmp = s[i] i += 1 cnt += 1 print(cnt)
s = eval(input()) prev = "" lets = "" ans = 0 for e in s: lets += e if lets != prev: ans += 1 prev = lets lets = "" print(ans)
20
13
274
167
# -*- coding: utf-8 -*- s = eval(input()) i = 1 tmp = s[0] cnt = 1 while i < len(s): if s[i] == tmp: if i == len(s) - 1: break tmp = s[i : i + 2] i += 2 else: tmp = s[i] i += 1 cnt += 1 print(cnt)
s = eval(input()) prev = "" lets = "" ans = 0 for e in s: lets += e if lets != prev: ans += 1 prev = lets lets = "" print(ans)
false
35
[ "-# -*- coding: utf-8 -*-", "-i = 1", "-tmp = s[0]", "-cnt = 1", "-while i < len(s):", "- if s[i] == tmp:", "- if i == len(s) - 1:", "- break", "- tmp = s[i : i + 2]", "- i += 2", "- else:", "- tmp = s[i]", "- i += 1", "- cnt += 1", "-print(cnt)", "+prev = \"\"", "+lets = \"\"", "+ans = 0", "+for e in s:", "+ lets += e", "+ if lets != prev:", "+ ans += 1", "+ prev = lets", "+ lets = \"\"", "+print(ans)" ]
false
0.038325
0.038805
0.987625
[ "s864957796", "s677626839" ]
u191829404
p03086
python
s933857685
s305816540
1,768
171
21,724
38,256
Accepted
Accepted
90.33
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0 # abcde s=input() s='abcde' # abcde s=list(input()) s=['a', 'b', 'c', 'd', 'e'] # 5(1つだけ) a=int(input()) a=5 # 1 2 | x,y = s_inpl() | x=1,y=2 # 1 2 3 4 5 ... n   li = input().split() li=['1','2','3',...,'n'] # 1 2 3 4 5 ... n   li = inpl() li=[1,2,3,4,5,...,n] # FFFTFTTFF   li = input().split('T') li=['FFF', 'F', '', 'FF'] # INPUT # 3 # hoge # foo # bar # ANSWER # n=int(input()) # string_list=[input() for i in range(n)] import math import numpy as np import copy from collections import defaultdict, Counter from itertools import product from bisect import bisect_left, bisect_right def s_inpl(): return list(map(int,input().split())) def inpl(): return list(map(int, input().split())) S = eval(input()) ans = 0 tmp = 0 for si in S: if si == "A" or si == "T" or si == "C" or si == "G": tmp += 1 else: if tmp > ans: ans = tmp tmp = 0 if tmp > ans: ans = tmp print(ans)
import math import copy from operator import mul from functools import reduce from collections import defaultdict from collections import Counter from collections import deque # 直積 A={a, b, c}, B={d, e}:のとき,A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B) from itertools import product # 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n) from itertools import permutations # 組み合わせ {}_len(seq) C_n: combinations(seq, n) from itertools import combinations from bisect import bisect_left, bisect_right # import numpy as np def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W # 四方向: 右, 下, 左, 上 dy = [0, -1, 0, 1] dx = [1, 0, -1, 0] def i_inpl(): return int(eval(input())) def l_inpl(): return list(map(int, input().split())) INF = float("inf") ###### # URL: https://atcoder.jp/contests/abc122/tasks/abc122_b ###### def main(): S = eval(input()) ans = 0 for begin in range(len(S)): for end in range(begin, len(S)): if sum([ "ACGT".count(s) for s in S[begin:end+1]]) == len(S[begin:end+1]): ans = max(ans, len(S[begin:end+1])) print(ans) if __name__ == "__main__": main()
44
42
1,024
1,190
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0 # abcde s=input() s='abcde' # abcde s=list(input()) s=['a', 'b', 'c', 'd', 'e'] # 5(1つだけ) a=int(input()) a=5 # 1 2 | x,y = s_inpl() | x=1,y=2 # 1 2 3 4 5 ... n   li = input().split() li=['1','2','3',...,'n'] # 1 2 3 4 5 ... n   li = inpl() li=[1,2,3,4,5,...,n] # FFFTFTTFF   li = input().split('T') li=['FFF', 'F', '', 'FF'] # INPUT # 3 # hoge # foo # bar # ANSWER # n=int(input()) # string_list=[input() for i in range(n)] import math import numpy as np import copy from collections import defaultdict, Counter from itertools import product from bisect import bisect_left, bisect_right def s_inpl(): return list(map(int, input().split())) def inpl(): return list(map(int, input().split())) S = eval(input()) ans = 0 tmp = 0 for si in S: if si == "A" or si == "T" or si == "C" or si == "G": tmp += 1 else: if tmp > ans: ans = tmp tmp = 0 if tmp > ans: ans = tmp print(ans)
import math import copy from operator import mul from functools import reduce from collections import defaultdict from collections import Counter from collections import deque # 直積 A={a, b, c}, B={d, e}:のとき,A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B) from itertools import product # 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n) from itertools import permutations # 組み合わせ {}_len(seq) C_n: combinations(seq, n) from itertools import combinations from bisect import bisect_left, bisect_right # import numpy as np def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W # 四方向: 右, 下, 左, 上 dy = [0, -1, 0, 1] dx = [1, 0, -1, 0] def i_inpl(): return int(eval(input())) def l_inpl(): return list(map(int, input().split())) INF = float("inf") ###### # URL: https://atcoder.jp/contests/abc122/tasks/abc122_b ###### def main(): S = eval(input()) ans = 0 for begin in range(len(S)): for end in range(begin, len(S)): if sum(["ACGT".count(s) for s in S[begin : end + 1]]) == len( S[begin : end + 1] ): ans = max(ans, len(S[begin : end + 1])) print(ans) if __name__ == "__main__": main()
false
4.545455
[ "-# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0", "-# abcde\ts=input()\ts='abcde'", "-# abcde\ts=list(input())\ts=['a', 'b', 'c', 'd', 'e']", "-# 5(1つだけ)\ta=int(input())\ta=5", "-# 1 2\t| x,y = s_inpl() |\tx=1,y=2", "-# 1 2 3 4 5 ... n  \tli = input().split()\tli=['1','2','3',...,'n']", "-# 1 2 3 4 5 ... n  \tli = inpl()\tli=[1,2,3,4,5,...,n]", "-# FFFTFTTFF  \tli = input().split('T')\tli=['FFF', 'F', '', 'FF']", "-# INPUT", "-# 3", "-# hoge", "-# foo", "-# bar", "-# ANSWER", "-# n=int(input())", "-# string_list=[input() for i in range(n)]", "-import numpy as np", "-from collections import defaultdict, Counter", "+from operator import mul", "+from functools import reduce", "+from collections import defaultdict", "+from collections import Counter", "+from collections import deque", "+", "+# 直積 A={a, b, c}, B={d, e}:のとき,A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)", "+", "+# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)", "+from itertools import permutations", "+", "+# 組み合わせ {}_len(seq) C_n: combinations(seq, n)", "+from itertools import combinations", "+# import numpy as np", "+def inside(y, x, H, W):", "+ return 0 <= y < H and 0 <= x < W", "-def s_inpl():", "+", "+# 四方向: 右, 下, 左, 上", "+dy = [0, -1, 0, 1]", "+dx = [1, 0, -1, 0]", "+", "+", "+def i_inpl():", "+ return int(eval(input()))", "+", "+", "+def l_inpl():", "-def inpl():", "- return list(map(int, input().split()))", "+INF = float(\"inf\")", "+######", "+# URL: https://atcoder.jp/contests/abc122/tasks/abc122_b", "+######", "+def main():", "+ S = eval(input())", "+ ans = 0", "+ for begin in range(len(S)):", "+ for end in range(begin, len(S)):", "+ if sum([\"ACGT\".count(s) for s in S[begin : end + 1]]) == len(", "+ S[begin : end + 1]", "+ ):", "+ ans = max(ans, len(S[begin : end + 1]))", "+ print(ans)", "-S = eval(input())", "-ans = 0", "-tmp = 0", "-for si in S:", "- if si == \"A\" or si == \"T\" or si == \"C\" or si == \"G\":", "- tmp += 1", "- else:", "- if tmp > ans:", "- ans = tmp", "- tmp = 0", "- if tmp > ans:", "- ans = tmp", "-print(ans)", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.079357
0.036686
2.163144
[ "s933857685", "s305816540" ]
u033606236
p03160
python
s947720970
s228391209
242
202
13,928
17,460
Accepted
Accepted
16.53
nums = int(eval(input())) ary = list(map(int,input().split())) dp = [0 for i in range(nums)] for i in range(1,nums): dp[i] = float("inf") jump_min = 0 for i in range(1,nums): for x in range(1,3): jump = i-x if i-x < 0: continue jump = dp[i-x] + abs(ary[i-x] - ary[i]) if jump < dp[i]: dp[i] = jump print((dp[nums-1]))
n = int(eval(input())) dp = [float("Inf") for _ in range(n)] ary = list(map(int,input().split())) dp[0] = 0 for i in range(n-1): dp[i+1] = min(dp[i+1],abs(ary[i]-ary[i+1])+dp[i]) if i +2 <= n-1: dp[i+2] = min(dp[i+2],abs(ary[i]-ary[i+2])+dp[i]) print((dp[n-1]))
14
9
374
278
nums = int(eval(input())) ary = list(map(int, input().split())) dp = [0 for i in range(nums)] for i in range(1, nums): dp[i] = float("inf") jump_min = 0 for i in range(1, nums): for x in range(1, 3): jump = i - x if i - x < 0: continue jump = dp[i - x] + abs(ary[i - x] - ary[i]) if jump < dp[i]: dp[i] = jump print((dp[nums - 1]))
n = int(eval(input())) dp = [float("Inf") for _ in range(n)] ary = list(map(int, input().split())) dp[0] = 0 for i in range(n - 1): dp[i + 1] = min(dp[i + 1], abs(ary[i] - ary[i + 1]) + dp[i]) if i + 2 <= n - 1: dp[i + 2] = min(dp[i + 2], abs(ary[i] - ary[i + 2]) + dp[i]) print((dp[n - 1]))
false
35.714286
[ "-nums = int(eval(input()))", "+n = int(eval(input()))", "+dp = [float(\"Inf\") for _ in range(n)]", "-dp = [0 for i in range(nums)]", "-for i in range(1, nums):", "- dp[i] = float(\"inf\")", "-jump_min = 0", "-for i in range(1, nums):", "- for x in range(1, 3):", "- jump = i - x", "- if i - x < 0:", "- continue", "- jump = dp[i - x] + abs(ary[i - x] - ary[i])", "- if jump < dp[i]:", "- dp[i] = jump", "-print((dp[nums - 1]))", "+dp[0] = 0", "+for i in range(n - 1):", "+ dp[i + 1] = min(dp[i + 1], abs(ary[i] - ary[i + 1]) + dp[i])", "+ if i + 2 <= n - 1:", "+ dp[i + 2] = min(dp[i + 2], abs(ary[i] - ary[i + 2]) + dp[i])", "+print((dp[n - 1]))" ]
false
0.044652
0.045059
0.990961
[ "s947720970", "s228391209" ]
u347600233
p03042
python
s081583999
s109559637
31
28
9,020
9,052
Accepted
Accepted
9.68
s = eval(input()) ans = {(False, False): 'NA', (False, True): 'YYMM', (True, False): 'MMYY', (True, True): 'AMBIGUOUS'} print((ans[1 <= int(s[:2]) <= 12, 1 <= int(s[2:]) <= 12]))
s = eval(input()) F, T = False, True ans = {(F, F): 'NA', (F, T): 'YYMM', (T, F): 'MMYY', (T, T): 'AMBIGUOUS'} print((ans[1 <= int(s[:2]) <= 12, 1 <= int(s[2:]) <= 12]))
3
4
172
164
s = eval(input()) ans = { (False, False): "NA", (False, True): "YYMM", (True, False): "MMYY", (True, True): "AMBIGUOUS", } print((ans[1 <= int(s[:2]) <= 12, 1 <= int(s[2:]) <= 12]))
s = eval(input()) F, T = False, True ans = {(F, F): "NA", (F, T): "YYMM", (T, F): "MMYY", (T, T): "AMBIGUOUS"} print((ans[1 <= int(s[:2]) <= 12, 1 <= int(s[2:]) <= 12]))
false
25
[ "-ans = {", "- (False, False): \"NA\",", "- (False, True): \"YYMM\",", "- (True, False): \"MMYY\",", "- (True, True): \"AMBIGUOUS\",", "-}", "+F, T = False, True", "+ans = {(F, F): \"NA\", (F, T): \"YYMM\", (T, F): \"MMYY\", (T, T): \"AMBIGUOUS\"}" ]
false
0.047148
0.113137
0.416728
[ "s081583999", "s109559637" ]
u699296734
p02958
python
s049080097
s965519851
31
26
9,184
9,104
Accepted
Accepted
16.13
n = int(eval(input())) p = list(map(int, input().split())) wrong = 0 for i in range(1, n + 1): if i == p[i - 1]: pass else: wrong += 1 if wrong <= 2: print("YES") else: print("NO")
n = int(eval(input())) p = list(map(int, input().split())) swap = 0 for i in range(n): min_num = p[i] min_j = i for j in range(i, n): if min_num > p[j]: min_num = p[j] min_j = j if min_j != i: p[i] ,p[min_j] = p[min_j], p[i] swap += 1 # print(swap) # print(p) if swap <= 1: print("YES") else: print("NO")
14
21
222
402
n = int(eval(input())) p = list(map(int, input().split())) wrong = 0 for i in range(1, n + 1): if i == p[i - 1]: pass else: wrong += 1 if wrong <= 2: print("YES") else: print("NO")
n = int(eval(input())) p = list(map(int, input().split())) swap = 0 for i in range(n): min_num = p[i] min_j = i for j in range(i, n): if min_num > p[j]: min_num = p[j] min_j = j if min_j != i: p[i], p[min_j] = p[min_j], p[i] swap += 1 # print(swap) # print(p) if swap <= 1: print("YES") else: print("NO")
false
33.333333
[ "-wrong = 0", "-for i in range(1, n + 1):", "- if i == p[i - 1]:", "- pass", "- else:", "- wrong += 1", "-if wrong <= 2:", "+swap = 0", "+for i in range(n):", "+ min_num = p[i]", "+ min_j = i", "+ for j in range(i, n):", "+ if min_num > p[j]:", "+ min_num = p[j]", "+ min_j = j", "+ if min_j != i:", "+ p[i], p[min_j] = p[min_j], p[i]", "+ swap += 1", "+ # print(swap)", "+ # print(p)", "+if swap <= 1:" ]
false
0.037412
0.039377
0.950096
[ "s049080097", "s965519851" ]
u363369454
p02634
python
s374245362
s009717032
220
201
133,604
133,808
Accepted
Accepted
8.64
a,b,c,d=list(map(int,input().split())) m=998244353 D=[[0]*(d+1)for _ in range(c+1)] D[a][b]=1 for i in range(a,c+1): for j in range(b,d+1): D[i][j]+=(D[i][j-1]*i+D[i-1][j]*j-D[i-1][j-1]*(i-1)*(j-1))%m print((D[c][d]))
a,b,c,d=list(map(int,input().split()));m=998244353;D=[[0]*(d+1)for _ in range(c+1)];D[a][b]=1 for i in range(a,c+1): for j in range(b,d+1): x=D[i-1] D[i][j]+=(D[i][j-1]*i+x[j]*j-x[j-1]*(i-1)*(j-1))%m print((D[c][d]))
8
6
219
218
a, b, c, d = list(map(int, input().split())) m = 998244353 D = [[0] * (d + 1) for _ in range(c + 1)] D[a][b] = 1 for i in range(a, c + 1): for j in range(b, d + 1): D[i][j] += ( D[i][j - 1] * i + D[i - 1][j] * j - D[i - 1][j - 1] * (i - 1) * (j - 1) ) % m print((D[c][d]))
a, b, c, d = list(map(int, input().split())) m = 998244353 D = [[0] * (d + 1) for _ in range(c + 1)] D[a][b] = 1 for i in range(a, c + 1): for j in range(b, d + 1): x = D[i - 1] D[i][j] += (D[i][j - 1] * i + x[j] * j - x[j - 1] * (i - 1) * (j - 1)) % m print((D[c][d]))
false
25
[ "- D[i][j] += (", "- D[i][j - 1] * i + D[i - 1][j] * j - D[i - 1][j - 1] * (i - 1) * (j - 1)", "- ) % m", "+ x = D[i - 1]", "+ D[i][j] += (D[i][j - 1] * i + x[j] * j - x[j - 1] * (i - 1) * (j - 1)) % m" ]
false
0.063303
0.06119
1.034532
[ "s374245362", "s009717032" ]
u729133443
p02733
python
s922312847
s520167857
1,716
987
3,188
50,904
Accepted
Accepted
42.48
def main(): h,*s=open(0) h,w,k=list(map(int,h.split())) s=[list(map(int,t[:w]))for t in s] m=9e9 for i in range(1<<h-1): t=[] b=v=l=0 for j in range(h): if i>>j&1: t+=list(map(sum,list(zip(*s[b:j+1])))), b=j+1 l+=1 t+=list(map(sum,list(zip(*s[b:])))), l+=1 c=[0]*l for i in range(w): f=g=0 u=[] for j,d in enumerate(t): d=d.__next__() u+=d, if d>k: g=1 break c[j]+=d f|=c[j]>k else: if f: c=u v+=1 if g:break else: if v+l-1<m:m=v+l-1 print(m) main()
r=range h,*s=open(0) h,w,k=list(map(int,h.split())) m=9e9 for i in r(1<<h-1): t,v,l=[],-1,1 for j in r(h): if i>>j&1: t+=j+1, l+=1 t+=h, c=[0]*l for i in r(w): b=f=g=0 u=[] for j in r(l): d,b=sum(s[j][i]=='1'for j in r(b,t[j])),t[j] u+=d, if d>k: g=1 break c[j]+=d f|=c[j]>k else: v+=f if f:c=u if g:break else:m=min(m,v+l) print(m)
36
29
652
460
def main(): h, *s = open(0) h, w, k = list(map(int, h.split())) s = [list(map(int, t[:w])) for t in s] m = 9e9 for i in range(1 << h - 1): t = [] b = v = l = 0 for j in range(h): if i >> j & 1: t += (list(map(sum, list(zip(*s[b : j + 1])))),) b = j + 1 l += 1 t += (list(map(sum, list(zip(*s[b:])))),) l += 1 c = [0] * l for i in range(w): f = g = 0 u = [] for j, d in enumerate(t): d = d.__next__() u += (d,) if d > k: g = 1 break c[j] += d f |= c[j] > k else: if f: c = u v += 1 if g: break else: if v + l - 1 < m: m = v + l - 1 print(m) main()
r = range h, *s = open(0) h, w, k = list(map(int, h.split())) m = 9e9 for i in r(1 << h - 1): t, v, l = [], -1, 1 for j in r(h): if i >> j & 1: t += (j + 1,) l += 1 t += (h,) c = [0] * l for i in r(w): b = f = g = 0 u = [] for j in r(l): d, b = sum(s[j][i] == "1" for j in r(b, t[j])), t[j] u += (d,) if d > k: g = 1 break c[j] += d f |= c[j] > k else: v += f if f: c = u if g: break else: m = min(m, v + l) print(m)
false
19.444444
[ "-def main():", "- h, *s = open(0)", "- h, w, k = list(map(int, h.split()))", "- s = [list(map(int, t[:w])) for t in s]", "- m = 9e9", "- for i in range(1 << h - 1):", "- t = []", "- b = v = l = 0", "- for j in range(h):", "- if i >> j & 1:", "- t += (list(map(sum, list(zip(*s[b : j + 1])))),)", "- b = j + 1", "- l += 1", "- t += (list(map(sum, list(zip(*s[b:])))),)", "- l += 1", "- c = [0] * l", "- for i in range(w):", "- f = g = 0", "- u = []", "- for j, d in enumerate(t):", "- d = d.__next__()", "- u += (d,)", "- if d > k:", "- g = 1", "- break", "- c[j] += d", "- f |= c[j] > k", "- else:", "- if f:", "- c = u", "- v += 1", "- if g:", "+r = range", "+h, *s = open(0)", "+h, w, k = list(map(int, h.split()))", "+m = 9e9", "+for i in r(1 << h - 1):", "+ t, v, l = [], -1, 1", "+ for j in r(h):", "+ if i >> j & 1:", "+ t += (j + 1,)", "+ l += 1", "+ t += (h,)", "+ c = [0] * l", "+ for i in r(w):", "+ b = f = g = 0", "+ u = []", "+ for j in r(l):", "+ d, b = sum(s[j][i] == \"1\" for j in r(b, t[j])), t[j]", "+ u += (d,)", "+ if d > k:", "+ g = 1", "+ c[j] += d", "+ f |= c[j] > k", "- if v + l - 1 < m:", "- m = v + l - 1", "- print(m)", "-", "-", "-main()", "+ v += f", "+ if f:", "+ c = u", "+ if g:", "+ break", "+ else:", "+ m = min(m, v + l)", "+print(m)" ]
false
0.044552
0.13928
0.319872
[ "s922312847", "s520167857" ]
u562935282
p02720
python
s133905631
s997948564
745
133
96,472
12,404
Accepted
Accepted
82.15
def main(): from functools import lru_cache import sys sys.setrecursionlimit(10 ** 7) @lru_cache(maxsize=None) def make_number(digit, p=0): if digit == 0: memo.append(p) if len(memo) == k + 1: print(p) exit() return if p == 0: # 前の位がない for x in range(1, 10): make_number(digit - 1, x) else: r = p % 10 # 前の位がある for x in range(max(0, r - 1), min(9, r + 1) + 1): make_number(digit - 1, p * 10 + x) k = int(eval(input())) memo = [] for digit in range(11): make_number(digit) if __name__ == '__main__': main() # import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split())
from collections import deque K = int(eval(input())) dq = deque() for x in range(1, 10): dq.append(x) idx = 1 while idx < K: x = dq.popleft() idx += 1 r = x % 10 if r > 0: nx = (x * 10) + (r - 1) dq.append(nx) nx = (x * 10) + (r) dq.append(nx) if r < 9: nx = (x * 10) + (r + 1) dq.append(nx) ans = dq.popleft() print(ans)
45
28
915
415
def main(): from functools import lru_cache import sys sys.setrecursionlimit(10**7) @lru_cache(maxsize=None) def make_number(digit, p=0): if digit == 0: memo.append(p) if len(memo) == k + 1: print(p) exit() return if p == 0: # 前の位がない for x in range(1, 10): make_number(digit - 1, x) else: r = p % 10 # 前の位がある for x in range(max(0, r - 1), min(9, r + 1) + 1): make_number(digit - 1, p * 10 + x) k = int(eval(input())) memo = [] for digit in range(11): make_number(digit) if __name__ == "__main__": main() # import sys # # sys.setrecursionlimit(10 ** 7) # # input = sys.stdin.readline # rstrip() # int(input()) # map(int, input().split())
from collections import deque K = int(eval(input())) dq = deque() for x in range(1, 10): dq.append(x) idx = 1 while idx < K: x = dq.popleft() idx += 1 r = x % 10 if r > 0: nx = (x * 10) + (r - 1) dq.append(nx) nx = (x * 10) + (r) dq.append(nx) if r < 9: nx = (x * 10) + (r + 1) dq.append(nx) ans = dq.popleft() print(ans)
false
37.777778
[ "-def main():", "- from functools import lru_cache", "- import sys", "+from collections import deque", "- sys.setrecursionlimit(10**7)", "-", "- @lru_cache(maxsize=None)", "- def make_number(digit, p=0):", "- if digit == 0:", "- memo.append(p)", "- if len(memo) == k + 1:", "- print(p)", "- exit()", "- return", "- if p == 0:", "- # 前の位がない", "- for x in range(1, 10):", "- make_number(digit - 1, x)", "- else:", "- r = p % 10", "- # 前の位がある", "- for x in range(max(0, r - 1), min(9, r + 1) + 1):", "- make_number(digit - 1, p * 10 + x)", "-", "- k = int(eval(input()))", "- memo = []", "- for digit in range(11):", "- make_number(digit)", "-", "-", "-if __name__ == \"__main__\":", "- main()", "-# import sys", "-#", "-# sys.setrecursionlimit(10 ** 7)", "-#", "-# input = sys.stdin.readline", "-# rstrip()", "-# int(input())", "-# map(int, input().split())", "+K = int(eval(input()))", "+dq = deque()", "+for x in range(1, 10):", "+ dq.append(x)", "+idx = 1", "+while idx < K:", "+ x = dq.popleft()", "+ idx += 1", "+ r = x % 10", "+ if r > 0:", "+ nx = (x * 10) + (r - 1)", "+ dq.append(nx)", "+ nx = (x * 10) + (r)", "+ dq.append(nx)", "+ if r < 9:", "+ nx = (x * 10) + (r + 1)", "+ dq.append(nx)", "+ans = dq.popleft()", "+print(ans)" ]
false
0.193565
0.067397
2.872018
[ "s133905631", "s997948564" ]
u254871849
p03085
python
s041965973
s155043212
19
17
3,060
2,940
Accepted
Accepted
10.53
import sys corresponding = dict(list(zip('ACGT', 'TGCA'))) b = sys.stdin.readline().rstrip() def main(): return corresponding[b] if __name__ == '__main__': ans = main() print(ans)
import sys pair = dict(list(zip('ACGT', 'TGCA'))) b = sys.stdin.readline().rstrip() def main(): print((pair[b])) if __name__ == '__main__': main()
12
11
200
161
import sys corresponding = dict(list(zip("ACGT", "TGCA"))) b = sys.stdin.readline().rstrip() def main(): return corresponding[b] if __name__ == "__main__": ans = main() print(ans)
import sys pair = dict(list(zip("ACGT", "TGCA"))) b = sys.stdin.readline().rstrip() def main(): print((pair[b])) if __name__ == "__main__": main()
false
8.333333
[ "-corresponding = dict(list(zip(\"ACGT\", \"TGCA\")))", "+pair = dict(list(zip(\"ACGT\", \"TGCA\")))", "- return corresponding[b]", "+ print((pair[b]))", "- ans = main()", "- print(ans)", "+ main()" ]
false
0.080253
0.08312
0.965504
[ "s041965973", "s155043212" ]
u382748202
p03583
python
s119034356
s954581977
1,702
19
3,060
3,064
Accepted
Accepted
98.88
N = int(eval(input())) for h in range(1, 3501): for n in range(h, 3501): q = 4 * h * n - N * h - N * n if q <= 0: continue p = N * h * n if p % q == 0: w = int(p / q) print((str(h) + ' ' + str(n) + ' ' + str(w))) exit()
N = int(eval(input())) for h in range(1, 3501): a = 4 * h - N if a <= 0: continue b = N * h for n in range(max(h, b // a + 1), 3501): q = 4 * h * n - N * h - N * n if q <= 0: continue p = N * h * n if p % q == 0: w = int(p / q) print((str(h) + ' ' + str(n) + ' ' + str(w))) exit()
12
16
307
392
N = int(eval(input())) for h in range(1, 3501): for n in range(h, 3501): q = 4 * h * n - N * h - N * n if q <= 0: continue p = N * h * n if p % q == 0: w = int(p / q) print((str(h) + " " + str(n) + " " + str(w))) exit()
N = int(eval(input())) for h in range(1, 3501): a = 4 * h - N if a <= 0: continue b = N * h for n in range(max(h, b // a + 1), 3501): q = 4 * h * n - N * h - N * n if q <= 0: continue p = N * h * n if p % q == 0: w = int(p / q) print((str(h) + " " + str(n) + " " + str(w))) exit()
false
25
[ "- for n in range(h, 3501):", "+ a = 4 * h - N", "+ if a <= 0:", "+ continue", "+ b = N * h", "+ for n in range(max(h, b // a + 1), 3501):" ]
false
1.769313
0.068357
25.883527
[ "s119034356", "s954581977" ]
u930705402
p03409
python
s350913773
s648399368
180
101
39,152
77,348
Accepted
Accepted
43.89
INF=10**30 N=int(eval(input())) ball=[list(map(int,input().split()))+['r'] for i in range(N)] ball[len(ball):len(ball)]=[list(map(int,input().split()))+['b'] for i in range(N)] ball.sort(key=lambda x:x[0]) cnt=0 for i in range(len(ball)): if(ball[i][2]=='b'): match=INF Ym=-1 for j in range(i): if(ball[j][2]=='r'): if(ball[j][1]>Ym and ball[i][1]>ball[j][1]): Ym=ball[j][1] match=j if(match!=INF): ball[match][1]=INF cnt+=1 print(cnt)
from collections import defaultdict import sys sys.setrecursionlimit(10**7) def dfs(v,t,f,used): if v==t: return f used[v]=True for nv,cap in list(G[v].items()): if not used[nv] and cap>0: d=dfs(nv,t,min(f,cap),used) if d>0: G[v][nv]-=d G[nv][v]+=d return d return 0 def Max_Flow(s,t): flow=0 while(True): used=[False]*(2*N+2) f=dfs(s,t,INF,used) if f==0: return flow flow+=f INF=float('inf') N=int(eval(input())) G=[defaultdict(int) for i in range(2*N+2)] arr=[] for i in range(2*N): x,y=list(map(int,input().split())) arr.append((x,y)) for i in range(N,2*N): for j in range(N): a,b=arr[i] c,d=arr[j] if a>c and b>d: G[i+1][j+1]=1 G[j+1][i+1]=0 for i in range(N): G[0][N+i+1]=1 G[N+i+1][0]=0 G[i+1][2*N+1]=1 G[2*N+1][i+1]=0 res=Max_Flow(0,2*N+1) print(res)
19
49
575
1,024
INF = 10**30 N = int(eval(input())) ball = [list(map(int, input().split())) + ["r"] for i in range(N)] ball[len(ball) : len(ball)] = [ list(map(int, input().split())) + ["b"] for i in range(N) ] ball.sort(key=lambda x: x[0]) cnt = 0 for i in range(len(ball)): if ball[i][2] == "b": match = INF Ym = -1 for j in range(i): if ball[j][2] == "r": if ball[j][1] > Ym and ball[i][1] > ball[j][1]: Ym = ball[j][1] match = j if match != INF: ball[match][1] = INF cnt += 1 print(cnt)
from collections import defaultdict import sys sys.setrecursionlimit(10**7) def dfs(v, t, f, used): if v == t: return f used[v] = True for nv, cap in list(G[v].items()): if not used[nv] and cap > 0: d = dfs(nv, t, min(f, cap), used) if d > 0: G[v][nv] -= d G[nv][v] += d return d return 0 def Max_Flow(s, t): flow = 0 while True: used = [False] * (2 * N + 2) f = dfs(s, t, INF, used) if f == 0: return flow flow += f INF = float("inf") N = int(eval(input())) G = [defaultdict(int) for i in range(2 * N + 2)] arr = [] for i in range(2 * N): x, y = list(map(int, input().split())) arr.append((x, y)) for i in range(N, 2 * N): for j in range(N): a, b = arr[i] c, d = arr[j] if a > c and b > d: G[i + 1][j + 1] = 1 G[j + 1][i + 1] = 0 for i in range(N): G[0][N + i + 1] = 1 G[N + i + 1][0] = 0 G[i + 1][2 * N + 1] = 1 G[2 * N + 1][i + 1] = 0 res = Max_Flow(0, 2 * N + 1) print(res)
false
61.22449
[ "-INF = 10**30", "+from collections import defaultdict", "+import sys", "+", "+sys.setrecursionlimit(10**7)", "+", "+", "+def dfs(v, t, f, used):", "+ if v == t:", "+ return f", "+ used[v] = True", "+ for nv, cap in list(G[v].items()):", "+ if not used[nv] and cap > 0:", "+ d = dfs(nv, t, min(f, cap), used)", "+ if d > 0:", "+ G[v][nv] -= d", "+ G[nv][v] += d", "+ return d", "+ return 0", "+", "+", "+def Max_Flow(s, t):", "+ flow = 0", "+ while True:", "+ used = [False] * (2 * N + 2)", "+ f = dfs(s, t, INF, used)", "+ if f == 0:", "+ return flow", "+ flow += f", "+", "+", "+INF = float(\"inf\")", "-ball = [list(map(int, input().split())) + [\"r\"] for i in range(N)]", "-ball[len(ball) : len(ball)] = [", "- list(map(int, input().split())) + [\"b\"] for i in range(N)", "-]", "-ball.sort(key=lambda x: x[0])", "-cnt = 0", "-for i in range(len(ball)):", "- if ball[i][2] == \"b\":", "- match = INF", "- Ym = -1", "- for j in range(i):", "- if ball[j][2] == \"r\":", "- if ball[j][1] > Ym and ball[i][1] > ball[j][1]:", "- Ym = ball[j][1]", "- match = j", "- if match != INF:", "- ball[match][1] = INF", "- cnt += 1", "-print(cnt)", "+G = [defaultdict(int) for i in range(2 * N + 2)]", "+arr = []", "+for i in range(2 * N):", "+ x, y = list(map(int, input().split()))", "+ arr.append((x, y))", "+for i in range(N, 2 * N):", "+ for j in range(N):", "+ a, b = arr[i]", "+ c, d = arr[j]", "+ if a > c and b > d:", "+ G[i + 1][j + 1] = 1", "+ G[j + 1][i + 1] = 0", "+for i in range(N):", "+ G[0][N + i + 1] = 1", "+ G[N + i + 1][0] = 0", "+ G[i + 1][2 * N + 1] = 1", "+ G[2 * N + 1][i + 1] = 0", "+res = Max_Flow(0, 2 * N + 1)", "+print(res)" ]
false
0.046534
0.064454
0.721973
[ "s350913773", "s648399368" ]
u022979415
p03659
python
s159074631
s704155726
171
155
25,060
30,680
Accepted
Accepted
9.36
def main(): n = int(eval(input())) a = [int(x) for x in input().split()] for i in range(1, n): a[i] += a[i - 1] answer = float("inf") for i in range(n - 1): answer = min(answer, abs(a[-1] - 2 * a[i])) print(answer) if __name__ == '__main__': main()
def main(): n = int(eval(input())) a = list(map(int, input().split())) for i in range(1, n): a[i] += a[i - 1] ans = float("inf") for i in range(n - 1): ans = min(ans, abs(a[-1] - 2 * a[i])) print(ans) if __name__ == '__main__': main()
14
14
303
289
def main(): n = int(eval(input())) a = [int(x) for x in input().split()] for i in range(1, n): a[i] += a[i - 1] answer = float("inf") for i in range(n - 1): answer = min(answer, abs(a[-1] - 2 * a[i])) print(answer) if __name__ == "__main__": main()
def main(): n = int(eval(input())) a = list(map(int, input().split())) for i in range(1, n): a[i] += a[i - 1] ans = float("inf") for i in range(n - 1): ans = min(ans, abs(a[-1] - 2 * a[i])) print(ans) if __name__ == "__main__": main()
false
0
[ "- a = [int(x) for x in input().split()]", "+ a = list(map(int, input().split()))", "- answer = float(\"inf\")", "+ ans = float(\"inf\")", "- answer = min(answer, abs(a[-1] - 2 * a[i]))", "- print(answer)", "+ ans = min(ans, abs(a[-1] - 2 * a[i]))", "+ print(ans)" ]
false
0.04016
0.03918
1.025014
[ "s159074631", "s704155726" ]
u926678805
p03112
python
s005646284
s063015225
1,918
1,770
14,368
12,840
Accepted
Accepted
7.72
import bisect import sys def input_function(): return sys.stdin.readline().rstrip() input=input_function a,b,q=list(map(int,input().split())) s=sorted([int(eval(input())) for i in range(a)]) t=sorted([int(eval(input())) for i in range(b)]) for i in range(q): ans=999999999999 x=int(eval(input())) w=bisect.bisect_left(s,x) for j in range(2): if not 0<=w-j<len(s): continue z=bisect.bisect_left(t,s[w-j]) for k in range(2): if not 0<=z-k<len(t): continue ans=min(ans,abs(x-s[w-j])+abs(s[w-j]-t[z-k])) w=bisect.bisect_left(t,x) for j in range(2): if not 0<=w-j<len(t): continue z=bisect.bisect_left(s,t[w-j]) for k in range(2): if not 0<=z-k<len(s): continue ans=min(ans,abs(x-t[w-j])+abs(t[w-j]-s[z-k])) print(ans)
import bisect import sys input=lambda : sys.stdin.readline().rstrip() a,b,q=list(map(int,input().split())) s=sorted([int(eval(input())) for i in range(a)]) t=sorted([int(eval(input())) for i in range(b)]) for i in range(q): ans=999999999999 x=int(eval(input())) w=bisect.bisect_left(s,x) for j in range(2): if not 0<=w-j<len(s): continue z=bisect.bisect_left(t,s[w-j]) for k in range(2): if not 0<=z-k<len(t): continue ans=min(ans,abs(x-s[w-j])+abs(s[w-j]-t[z-k])) w=bisect.bisect_left(t,x) for j in range(2): if not 0<=w-j<len(t): continue z=bisect.bisect_left(s,t[w-j]) for k in range(2): if not 0<=z-k<len(s): continue ans=min(ans,abs(x-t[w-j])+abs(t[w-j]-s[z-k])) print(ans)
30
28
902
861
import bisect import sys def input_function(): return sys.stdin.readline().rstrip() input = input_function a, b, q = list(map(int, input().split())) s = sorted([int(eval(input())) for i in range(a)]) t = sorted([int(eval(input())) for i in range(b)]) for i in range(q): ans = 999999999999 x = int(eval(input())) w = bisect.bisect_left(s, x) for j in range(2): if not 0 <= w - j < len(s): continue z = bisect.bisect_left(t, s[w - j]) for k in range(2): if not 0 <= z - k < len(t): continue ans = min(ans, abs(x - s[w - j]) + abs(s[w - j] - t[z - k])) w = bisect.bisect_left(t, x) for j in range(2): if not 0 <= w - j < len(t): continue z = bisect.bisect_left(s, t[w - j]) for k in range(2): if not 0 <= z - k < len(s): continue ans = min(ans, abs(x - t[w - j]) + abs(t[w - j] - s[z - k])) print(ans)
import bisect import sys input = lambda: sys.stdin.readline().rstrip() a, b, q = list(map(int, input().split())) s = sorted([int(eval(input())) for i in range(a)]) t = sorted([int(eval(input())) for i in range(b)]) for i in range(q): ans = 999999999999 x = int(eval(input())) w = bisect.bisect_left(s, x) for j in range(2): if not 0 <= w - j < len(s): continue z = bisect.bisect_left(t, s[w - j]) for k in range(2): if not 0 <= z - k < len(t): continue ans = min(ans, abs(x - s[w - j]) + abs(s[w - j] - t[z - k])) w = bisect.bisect_left(t, x) for j in range(2): if not 0 <= w - j < len(t): continue z = bisect.bisect_left(s, t[w - j]) for k in range(2): if not 0 <= z - k < len(s): continue ans = min(ans, abs(x - t[w - j]) + abs(t[w - j] - s[z - k])) print(ans)
false
6.666667
[ "-", "-def input_function():", "- return sys.stdin.readline().rstrip()", "-", "-", "-input = input_function", "+input = lambda: sys.stdin.readline().rstrip()" ]
false
0.049716
0.045166
1.100757
[ "s005646284", "s063015225" ]
u440566786
p02863
python
s252011051
s506939179
355
328
43,228
43,228
Accepted
Accepted
7.61
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def resolve(): n,T=list(map(int,input().split())) AB=[tuple(map(int,input().split())) for _ in range(n)] AB.sort() dp=[0]*T ans=-INF for i in range(n): a,b=AB[i] ndp=dp[:] for t in range(T): if(t+a<T): ndp[t+a]=max(ndp[t+a],dp[t]+b) else: ans=max(ans,dp[t]+b) dp=ndp print((max(ans,max(dp)))) resolve()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def resolve(): n,T=list(map(int,input().split())) AB=[tuple(map(int,input().split())) for _ in range(n)] AB.sort() dp=[0]*T ans=-INF for i in range(n): a,b=AB[i] ndp=dp[:] for t in range(T): if(t+a<T): ndp[t+a]=max(ndp[t+a],dp[t]+b) else: ans=max(ans,dp[t]+b) dp=ndp print(ans) resolve()
23
23
551
538
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() def resolve(): n, T = list(map(int, input().split())) AB = [tuple(map(int, input().split())) for _ in range(n)] AB.sort() dp = [0] * T ans = -INF for i in range(n): a, b = AB[i] ndp = dp[:] for t in range(T): if t + a < T: ndp[t + a] = max(ndp[t + a], dp[t] + b) else: ans = max(ans, dp[t] + b) dp = ndp print((max(ans, max(dp)))) resolve()
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() def resolve(): n, T = list(map(int, input().split())) AB = [tuple(map(int, input().split())) for _ in range(n)] AB.sort() dp = [0] * T ans = -INF for i in range(n): a, b = AB[i] ndp = dp[:] for t in range(T): if t + a < T: ndp[t + a] = max(ndp[t + a], dp[t] + b) else: ans = max(ans, dp[t] + b) dp = ndp print(ans) resolve()
false
0
[ "- print((max(ans, max(dp))))", "+ print(ans)" ]
false
0.071318
0.03767
1.893208
[ "s252011051", "s506939179" ]
u254871849
p02813
python
s802876336
s782380242
27
18
8,052
3,064
Accepted
Accepted
33.33
import sys from itertools import permutations n = int(sys.stdin.readline().rstrip()) p, q = [tuple(map(int, sys.stdin.readline().split())) for _ in range(2)] def main(): perms = list(permutations(list(range(1, n+1)))) return abs(perms.index(p) - perms.index(q)) if __name__ == '__main__': ans = main() print(ans)
import sys n = int(sys.stdin.readline().rstrip()) *p, = list(map(int, sys.stdin.readline().split())) *q, = list(map(int, sys.stdin.readline().split())) factorial = [1] * (n + 1) for i in range(n): factorial[i+1] = factorial[i] * (i + 1) def main(): d = 0 a = [0] * (n + 1); b = [0] * (n + 1) for i in range(n - 1): a[p[i]] = b[q[i]] = 1 c1 = c2 = 0 for j in range(1, p[i]): c1 += a[j] for j in range(1, q[i]): c2 += b[j] d += ((q[i] - c2) - (p[i] - c1)) * factorial[n-(i+1)] print((abs(d))) if __name__ == '__main__': main()
13
22
337
596
import sys from itertools import permutations n = int(sys.stdin.readline().rstrip()) p, q = [tuple(map(int, sys.stdin.readline().split())) for _ in range(2)] def main(): perms = list(permutations(list(range(1, n + 1)))) return abs(perms.index(p) - perms.index(q)) if __name__ == "__main__": ans = main() print(ans)
import sys n = int(sys.stdin.readline().rstrip()) (*p,) = list(map(int, sys.stdin.readline().split())) (*q,) = list(map(int, sys.stdin.readline().split())) factorial = [1] * (n + 1) for i in range(n): factorial[i + 1] = factorial[i] * (i + 1) def main(): d = 0 a = [0] * (n + 1) b = [0] * (n + 1) for i in range(n - 1): a[p[i]] = b[q[i]] = 1 c1 = c2 = 0 for j in range(1, p[i]): c1 += a[j] for j in range(1, q[i]): c2 += b[j] d += ((q[i] - c2) - (p[i] - c1)) * factorial[n - (i + 1)] print((abs(d))) if __name__ == "__main__": main()
false
40.909091
[ "-from itertools import permutations", "-p, q = [tuple(map(int, sys.stdin.readline().split())) for _ in range(2)]", "+(*p,) = list(map(int, sys.stdin.readline().split()))", "+(*q,) = list(map(int, sys.stdin.readline().split()))", "+factorial = [1] * (n + 1)", "+for i in range(n):", "+ factorial[i + 1] = factorial[i] * (i + 1)", "- perms = list(permutations(list(range(1, n + 1))))", "- return abs(perms.index(p) - perms.index(q))", "+ d = 0", "+ a = [0] * (n + 1)", "+ b = [0] * (n + 1)", "+ for i in range(n - 1):", "+ a[p[i]] = b[q[i]] = 1", "+ c1 = c2 = 0", "+ for j in range(1, p[i]):", "+ c1 += a[j]", "+ for j in range(1, q[i]):", "+ c2 += b[j]", "+ d += ((q[i] - c2) - (p[i] - c1)) * factorial[n - (i + 1)]", "+ print((abs(d)))", "- ans = main()", "- print(ans)", "+ main()" ]
false
0.0411
0.067601
0.607976
[ "s802876336", "s782380242" ]
u046187684
p03417
python
s298196019
s108013993
20
18
3,316
3,060
Accepted
Accepted
10
n, m = list(map(int, input().strip().split(" "))) if n == 1 and m == 1: print((1)) elif n == 1 or m == 1: print((max(n - 2, m - 2))) elif n == 2 or m == 2: print((0)) else: print(((n - 2) * (m - 2)))
def solve(string): n, m = list(map(int, string.split())) if n == 1 and m == 1: return "1" elif n == 1 or m == 1: return str(max(n - 2, m - 2)) elif n == 2 or m == 2: return "0" else: return str((n - 2) * (m - 2)) if __name__ == '__main__': print((solve(eval(input()))))
9
14
210
327
n, m = list(map(int, input().strip().split(" "))) if n == 1 and m == 1: print((1)) elif n == 1 or m == 1: print((max(n - 2, m - 2))) elif n == 2 or m == 2: print((0)) else: print(((n - 2) * (m - 2)))
def solve(string): n, m = list(map(int, string.split())) if n == 1 and m == 1: return "1" elif n == 1 or m == 1: return str(max(n - 2, m - 2)) elif n == 2 or m == 2: return "0" else: return str((n - 2) * (m - 2)) if __name__ == "__main__": print((solve(eval(input()))))
false
35.714286
[ "-n, m = list(map(int, input().strip().split(\" \")))", "-if n == 1 and m == 1:", "- print((1))", "-elif n == 1 or m == 1:", "- print((max(n - 2, m - 2)))", "-elif n == 2 or m == 2:", "- print((0))", "-else:", "- print(((n - 2) * (m - 2)))", "+def solve(string):", "+ n, m = list(map(int, string.split()))", "+ if n == 1 and m == 1:", "+ return \"1\"", "+ elif n == 1 or m == 1:", "+ return str(max(n - 2, m - 2))", "+ elif n == 2 or m == 2:", "+ return \"0\"", "+ else:", "+ return str((n - 2) * (m - 2))", "+", "+", "+if __name__ == \"__main__\":", "+ print((solve(eval(input()))))" ]
false
0.007981
0.040115
0.198953
[ "s298196019", "s108013993" ]
u094191970
p03476
python
s275998785
s488244657
854
338
9,204
5,900
Accepted
Accepted
60.42
def eratosthenes(n): is_p=[1]*n # p_list=[] is_p[0]=0 is_p[1]=0 for i in range(2,n): if is_p[i]: # p_list.append(i) for j in range(i*i,n,i): is_p[j] = 0 return is_p#, p_list lim=10**5+1 #is_p, p_list=eratosthenes(lim) is_p=eratosthenes(lim) q=int(eval(input())) ''' b=[0] for i in range(1,lim+1): if is_p[i-1] and is_p[i//2]: b.append(b[i-1]+1) else: b.append(b[i-1]) ''' a = [0] * (10**5+2) for i in range(3, 10**5+1, 2): if is_p[i] and is_p[(i+1)//2]: a[i] = 1 for i in range(1, 10**5+1): a[i+1] += a[i] for i in range(q): l,r=list(map(int,input().split())) # print(b[r+1]-b[l]) print((a[r]-a[l-1]))
def eratosthenes(n): is_p=[1]*n p_list=[] is_p[0]=0 is_p[1]=0 for i in range(2,n): if is_p[i]: p_list.append(i) for j in range(i*i,n,i): is_p[j] = 0 return is_p, p_list lim=10**5+1 is_p, p_list=eratosthenes(lim) q=int(eval(input())) b=[0] for i in range(1,lim+1): if is_p[i-1] and is_p[i//2]: b.append(b[i-1]+1) else: b.append(b[i-1]) import sys stdin=sys.stdin temp=lambda: list(map(int, stdin.readline().split())) for i in range(q): # l,r=map(int,input().split()) l,r=temp() print((b[r+1]-b[l]))
40
35
673
557
def eratosthenes(n): is_p = [1] * n # p_list=[] is_p[0] = 0 is_p[1] = 0 for i in range(2, n): if is_p[i]: # p_list.append(i) for j in range(i * i, n, i): is_p[j] = 0 return is_p # , p_list lim = 10**5 + 1 # is_p, p_list=eratosthenes(lim) is_p = eratosthenes(lim) q = int(eval(input())) """ b=[0] for i in range(1,lim+1): if is_p[i-1] and is_p[i//2]: b.append(b[i-1]+1) else: b.append(b[i-1]) """ a = [0] * (10**5 + 2) for i in range(3, 10**5 + 1, 2): if is_p[i] and is_p[(i + 1) // 2]: a[i] = 1 for i in range(1, 10**5 + 1): a[i + 1] += a[i] for i in range(q): l, r = list(map(int, input().split())) # print(b[r+1]-b[l]) print((a[r] - a[l - 1]))
def eratosthenes(n): is_p = [1] * n p_list = [] is_p[0] = 0 is_p[1] = 0 for i in range(2, n): if is_p[i]: p_list.append(i) for j in range(i * i, n, i): is_p[j] = 0 return is_p, p_list lim = 10**5 + 1 is_p, p_list = eratosthenes(lim) q = int(eval(input())) b = [0] for i in range(1, lim + 1): if is_p[i - 1] and is_p[i // 2]: b.append(b[i - 1] + 1) else: b.append(b[i - 1]) import sys stdin = sys.stdin temp = lambda: list(map(int, stdin.readline().split())) for i in range(q): # l,r=map(int,input().split()) l, r = temp() print((b[r + 1] - b[l]))
false
12.5
[ "- # p_list=[]", "+ p_list = []", "- # p_list.append(i)", "+ p_list.append(i)", "- return is_p # , p_list", "+ return is_p, p_list", "-# is_p, p_list=eratosthenes(lim)", "-is_p = eratosthenes(lim)", "+is_p, p_list = eratosthenes(lim)", "-\"\"\"", "-b=[0]", "-for i in range(1,lim+1):", "- if is_p[i-1] and is_p[i//2]:", "- b.append(b[i-1]+1)", "- else:", "- b.append(b[i-1])", "-\"\"\"", "-a = [0] * (10**5 + 2)", "-for i in range(3, 10**5 + 1, 2):", "- if is_p[i] and is_p[(i + 1) // 2]:", "- a[i] = 1", "-for i in range(1, 10**5 + 1):", "- a[i + 1] += a[i]", "+b = [0]", "+for i in range(1, lim + 1):", "+ if is_p[i - 1] and is_p[i // 2]:", "+ b.append(b[i - 1] + 1)", "+ else:", "+ b.append(b[i - 1])", "+import sys", "+", "+stdin = sys.stdin", "+temp = lambda: list(map(int, stdin.readline().split()))", "- l, r = list(map(int, input().split()))", "- # print(b[r+1]-b[l])", "- print((a[r] - a[l - 1]))", "+ # l,r=map(int,input().split())", "+ l, r = temp()", "+ print((b[r + 1] - b[l]))" ]
false
0.123517
0.185858
0.664577
[ "s275998785", "s488244657" ]
u088078693
p03796
python
s669908213
s244862297
40
35
2,940
2,940
Accepted
Accepted
12.5
ans=1 n=int(eval(input())) for i in range(1,n+1): ans*=i ans=ans%(10**9+7) print(ans)
ans=1 n=int(eval(input())) for i in range(1,n+1): ans=i*ans%(10**9+7) print(ans)
6
5
92
82
ans = 1 n = int(eval(input())) for i in range(1, n + 1): ans *= i ans = ans % (10**9 + 7) print(ans)
ans = 1 n = int(eval(input())) for i in range(1, n + 1): ans = i * ans % (10**9 + 7) print(ans)
false
16.666667
[ "- ans *= i", "- ans = ans % (10**9 + 7)", "+ ans = i * ans % (10**9 + 7)" ]
false
0.055219
0.057354
0.962761
[ "s669908213", "s244862297" ]
u991542950
p02571
python
s261763915
s959665145
75
66
67,804
73,680
Accepted
Accepted
12
import sys input = sys.stdin.readline S = input().strip() T = input().strip() score_list = [] for i in range(len(S) - len(T) + 1): s = S[i:i+len(T)] score = 0 for i in range(len(s)): if s[i] != T[i]: score += 1 score_list.append(score) print((min(score_list)))
S = eval(input()) T = eval(input()) ans = 999999 for i in range(len(S) - len(T) + 1): s = S[i:i + len(T)] score = 0 for i in range(len(s)): if s[i] != T[i]: score += 1 ans = min(ans, score) print(ans)
13
12
288
219
import sys input = sys.stdin.readline S = input().strip() T = input().strip() score_list = [] for i in range(len(S) - len(T) + 1): s = S[i : i + len(T)] score = 0 for i in range(len(s)): if s[i] != T[i]: score += 1 score_list.append(score) print((min(score_list)))
S = eval(input()) T = eval(input()) ans = 999999 for i in range(len(S) - len(T) + 1): s = S[i : i + len(T)] score = 0 for i in range(len(s)): if s[i] != T[i]: score += 1 ans = min(ans, score) print(ans)
false
7.692308
[ "-import sys", "-", "-input = sys.stdin.readline", "-S = input().strip()", "-T = input().strip()", "-score_list = []", "+S = eval(input())", "+T = eval(input())", "+ans = 999999", "- score_list.append(score)", "-print((min(score_list)))", "+ ans = min(ans, score)", "+print(ans)" ]
false
0.084857
0.085523
0.992209
[ "s261763915", "s959665145" ]
u644907318
p03835
python
s508890789
s376560019
297
197
40,684
67,120
Accepted
Accepted
33.67
K,S = list(map(int,input().split())) cnt = 0 for i in range(K+1): for j in range(K+1): k = S-i-j if 0<=k<=K: cnt += 1 print(cnt)
K,S = list(map(int,input().split())) cnt = 0 for X in range(0,K+1): for Y in range(0,K+1): if 0<=S-X-Y<=K: cnt += 1 print(cnt)
8
7
161
150
K, S = list(map(int, input().split())) cnt = 0 for i in range(K + 1): for j in range(K + 1): k = S - i - j if 0 <= k <= K: cnt += 1 print(cnt)
K, S = list(map(int, input().split())) cnt = 0 for X in range(0, K + 1): for Y in range(0, K + 1): if 0 <= S - X - Y <= K: cnt += 1 print(cnt)
false
12.5
[ "-for i in range(K + 1):", "- for j in range(K + 1):", "- k = S - i - j", "- if 0 <= k <= K:", "+for X in range(0, K + 1):", "+ for Y in range(0, K + 1):", "+ if 0 <= S - X - Y <= K:" ]
false
0.03814
0.038316
0.995405
[ "s508890789", "s376560019" ]
u666550725
p02555
python
s080380094
s481484769
287
164
68,432
64,352
Accepted
Accepted
42.86
S = int(eval(input())) M = 10 ** 9 + 7 def mod_pow(a, b, mod): bin_b = [] while b: bin_b.append(b % 2) b >>= 1 ret = 1 for j in reversed(bin_b): ret = (ret * ret) % mod if j == 1: ret = (ret * a) % mod return ret def mod_comb(n, k, mod): ret = 1 for i in range(1, k+1): ret = (ret * (n+1-i)) % mod ret = (ret * mod_pow(i, mod-2, mod)) % mod return ret ans = 0 for K in range(1, S // 3 + 1): ans = (ans + mod_comb(S - 2 * K - 1, K - 1, M)) % M print(ans)
S = int(eval(input())) M = 10 ** 9 + 7 def mod_comb(n, k, mod): ret = 1 for i in range(1, k+1): ret = (ret * (n+1-i)) % mod ret = (ret * pow(i, mod-2, mod)) % mod return ret ans = 0 for K in range(1, S // 3 + 1): ans = (ans + mod_comb(S - 2 * K - 1, K - 1, M)) % M print(ans)
23
12
494
290
S = int(eval(input())) M = 10**9 + 7 def mod_pow(a, b, mod): bin_b = [] while b: bin_b.append(b % 2) b >>= 1 ret = 1 for j in reversed(bin_b): ret = (ret * ret) % mod if j == 1: ret = (ret * a) % mod return ret def mod_comb(n, k, mod): ret = 1 for i in range(1, k + 1): ret = (ret * (n + 1 - i)) % mod ret = (ret * mod_pow(i, mod - 2, mod)) % mod return ret ans = 0 for K in range(1, S // 3 + 1): ans = (ans + mod_comb(S - 2 * K - 1, K - 1, M)) % M print(ans)
S = int(eval(input())) M = 10**9 + 7 def mod_comb(n, k, mod): ret = 1 for i in range(1, k + 1): ret = (ret * (n + 1 - i)) % mod ret = (ret * pow(i, mod - 2, mod)) % mod return ret ans = 0 for K in range(1, S // 3 + 1): ans = (ans + mod_comb(S - 2 * K - 1, K - 1, M)) % M print(ans)
false
47.826087
[ "-", "-", "-def mod_pow(a, b, mod):", "- bin_b = []", "- while b:", "- bin_b.append(b % 2)", "- b >>= 1", "- ret = 1", "- for j in reversed(bin_b):", "- ret = (ret * ret) % mod", "- if j == 1:", "- ret = (ret * a) % mod", "- return ret", "- ret = (ret * mod_pow(i, mod - 2, mod)) % mod", "+ ret = (ret * pow(i, mod - 2, mod)) % mod" ]
false
0.262432
0.130353
2.013242
[ "s080380094", "s481484769" ]
u017415492
p02989
python
s471382098
s203149175
102
76
14,428
14,428
Accepted
Accepted
25.49
n=int(eval(input())) d=list(map(int,input().split())) d.sort() gn=0 a=d[int(n/2)]-d[int((n/2)-1)]-1 if d[int(n/2)]!=d[int((n/2)-1)]: for i in d: if i==d[int(n/2)]: gn+=1 if gn>=1: a+=1 print(a) else: print((0))
n=int(eval(input())) d=list(map(int,input().split())) d.sort() x=d[int((n-1)/2)]+1 y=d[int(n/2)] print((y-x+1))
16
7
246
110
n = int(eval(input())) d = list(map(int, input().split())) d.sort() gn = 0 a = d[int(n / 2)] - d[int((n / 2) - 1)] - 1 if d[int(n / 2)] != d[int((n / 2) - 1)]: for i in d: if i == d[int(n / 2)]: gn += 1 if gn >= 1: a += 1 print(a) else: print((0))
n = int(eval(input())) d = list(map(int, input().split())) d.sort() x = d[int((n - 1) / 2)] + 1 y = d[int(n / 2)] print((y - x + 1))
false
56.25
[ "-gn = 0", "-a = d[int(n / 2)] - d[int((n / 2) - 1)] - 1", "-if d[int(n / 2)] != d[int((n / 2) - 1)]:", "- for i in d:", "- if i == d[int(n / 2)]:", "- gn += 1", "- if gn >= 1:", "- a += 1", "- print(a)", "-else:", "- print((0))", "+x = d[int((n - 1) / 2)] + 1", "+y = d[int(n / 2)]", "+print((y - x + 1))" ]
false
0.03574
0.036655
0.975036
[ "s471382098", "s203149175" ]
u438662618
p03796
python
s653096452
s783900175
231
46
3,972
3,060
Accepted
Accepted
80.09
import math N = int(eval(input())) power = math.factorial(N) print((power % (10 ** 9 + 7)))
import math N = int(eval(input())) power = 1 NUM = 10 ** 9 + 7 for i in range(1, N + 1) : power *= i if power >= NUM : power %= NUM print(power) """ power = math.factorial(N) print(power % (10 ** 9 + 7)) """
7
17
93
239
import math N = int(eval(input())) power = math.factorial(N) print((power % (10**9 + 7)))
import math N = int(eval(input())) power = 1 NUM = 10**9 + 7 for i in range(1, N + 1): power *= i if power >= NUM: power %= NUM print(power) """ power = math.factorial(N) print(power % (10 ** 9 + 7)) """
false
58.823529
[ "+power = 1", "+NUM = 10**9 + 7", "+for i in range(1, N + 1):", "+ power *= i", "+ if power >= NUM:", "+ power %= NUM", "+print(power)", "+\"\"\"", "-print((power % (10**9 + 7)))", "+print(power % (10 ** 9 + 7))", "+\"\"\"" ]
false
0.075777
0.043126
1.757103
[ "s653096452", "s783900175" ]
u077291787
p03087
python
s858627942
s871608448
475
275
30,660
19,816
Accepted
Accepted
42.11
# ABC122C - GeT AC n, q = list(map(int, input().rstrip().split())) s = input().rstrip() arr = [list(map(int, input().rstrip().split())) for _ in range(q)] cnt = [0] * (n + 1) for i in range(n): if s[i : i + 2] == "AC": cnt[i + 1] = cnt[i] + 1 else: cnt[i + 1] = cnt[i] for i, j in arr: print((cnt[j - 1] - cnt[i - 1]))
# ABC122C - GeT AC import sys input = sys.stdin.readline def main(): n, q = list(map(int, input().rstrip().split())) s = input().rstrip() arr = tuple(tuple(map(int, input().split())) for _ in range(q)) cnt = [0] * (n + 1) for i in range(n): if s[i : i + 2] == "AC": cnt[i + 1] = cnt[i] + 1 else: cnt[i + 1] = cnt[i] for i, j in arr: print((cnt[j - 1] - cnt[i - 1])) if __name__ == "__main__": main()
12
21
356
497
# ABC122C - GeT AC n, q = list(map(int, input().rstrip().split())) s = input().rstrip() arr = [list(map(int, input().rstrip().split())) for _ in range(q)] cnt = [0] * (n + 1) for i in range(n): if s[i : i + 2] == "AC": cnt[i + 1] = cnt[i] + 1 else: cnt[i + 1] = cnt[i] for i, j in arr: print((cnt[j - 1] - cnt[i - 1]))
# ABC122C - GeT AC import sys input = sys.stdin.readline def main(): n, q = list(map(int, input().rstrip().split())) s = input().rstrip() arr = tuple(tuple(map(int, input().split())) for _ in range(q)) cnt = [0] * (n + 1) for i in range(n): if s[i : i + 2] == "AC": cnt[i + 1] = cnt[i] + 1 else: cnt[i + 1] = cnt[i] for i, j in arr: print((cnt[j - 1] - cnt[i - 1])) if __name__ == "__main__": main()
false
42.857143
[ "-n, q = list(map(int, input().rstrip().split()))", "-s = input().rstrip()", "-arr = [list(map(int, input().rstrip().split())) for _ in range(q)]", "-cnt = [0] * (n + 1)", "-for i in range(n):", "- if s[i : i + 2] == \"AC\":", "- cnt[i + 1] = cnt[i] + 1", "- else:", "- cnt[i + 1] = cnt[i]", "-for i, j in arr:", "- print((cnt[j - 1] - cnt[i - 1]))", "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "+def main():", "+ n, q = list(map(int, input().rstrip().split()))", "+ s = input().rstrip()", "+ arr = tuple(tuple(map(int, input().split())) for _ in range(q))", "+ cnt = [0] * (n + 1)", "+ for i in range(n):", "+ if s[i : i + 2] == \"AC\":", "+ cnt[i + 1] = cnt[i] + 1", "+ else:", "+ cnt[i + 1] = cnt[i]", "+ for i, j in arr:", "+ print((cnt[j - 1] - cnt[i - 1]))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.036522
0.03692
0.989214
[ "s858627942", "s871608448" ]
u498511622
p02417
python
s562981434
s188629269
30
20
7,484
7,452
Accepted
Accepted
33.33
s='' try: while True: sentence=eval(input()) s+=sentence except: pass sentence2=s.lower() for i in[chr(i) for i in range(97,97+26)]: print((i,':',sentence2.count(i)))
s='' try: while True: sentence=eval(input()) s+=sentence.lower() except: for i in[chr(i) for i in range(97,97+26)]: print((i,':',s.count(i)))
10
8
192
157
s = "" try: while True: sentence = eval(input()) s += sentence except: pass sentence2 = s.lower() for i in [chr(i) for i in range(97, 97 + 26)]: print((i, ":", sentence2.count(i)))
s = "" try: while True: sentence = eval(input()) s += sentence.lower() except: for i in [chr(i) for i in range(97, 97 + 26)]: print((i, ":", s.count(i)))
false
20
[ "- s += sentence", "+ s += sentence.lower()", "- pass", "- sentence2 = s.lower()", "- print((i, \":\", sentence2.count(i)))", "+ print((i, \":\", s.count(i)))" ]
false
0.130801
0.050962
2.566609
[ "s562981434", "s188629269" ]
u844646164
p02984
python
s099968601
s793088612
367
294
67,684
77,796
Accepted
Accepted
19.89
from collections import deque N = int(input()) A = list(map(int, input().split())) X = [0]*(N+1) S = sum(A) even_list = [A[i] for i in range(1, N) if (i+1) % 2 == 0] odd_list = [A[i] for i in range(1, N) if (i+1) % 2 != 0] X[1] = S - 2 * sum(even_list) X[2] = S - 2 * sum(odd_list) even = sum(even_list) odd = sum(odd_list) s_even_idx = 2 s_odd_idx = 3 t_even_idx = N-1 t_odd_idx = N A = A + A for i in range(3, N+1): if i%2: even -= A[s_even_idx-1] s_even_idx += 2 t_even_idx += 2 even += A[t_even_idx-1] X[i] = S - 2 * even else: odd -= A[s_odd_idx-1] s_odd_idx += 2 t_odd_idx += 2 odd += A[t_odd_idx-1] X[i] = S - 2 * odd for i in range(1, N+1): print(X[i], end=" ")
N = int(eval(input())) A = list(map(int,input().split())) S = sum(A) A = A + A b_odd = sum([A[i] for i in range(1, N) if (i+1)%2==0 ]) b_even = sum([A[i] for i in range(2, N) if (i+1)%2!=0 ]) b_odd_s, b_odd_t = 2, N-1 b_even_s, b_even_t = 3, N B = [0]*N B[0] = str(S - 2*b_odd) B[1] = str(S - 2*b_even) for i in range(2, N): if (i+1) % 2: b_odd -= A[b_odd_s-1] b_odd_s += 2 b_odd_t += 2 b_odd += A[b_odd_t-1] B[i] = str(S - 2*b_odd) else: b_even -= A[b_even_s-1] b_even_s += 2 b_even_t += 2 b_even += A[b_even_t-1] B[i] = str(S - 2*b_even) print((*B))
37
28
764
623
from collections import deque N = int(input()) A = list(map(int, input().split())) X = [0] * (N + 1) S = sum(A) even_list = [A[i] for i in range(1, N) if (i + 1) % 2 == 0] odd_list = [A[i] for i in range(1, N) if (i + 1) % 2 != 0] X[1] = S - 2 * sum(even_list) X[2] = S - 2 * sum(odd_list) even = sum(even_list) odd = sum(odd_list) s_even_idx = 2 s_odd_idx = 3 t_even_idx = N - 1 t_odd_idx = N A = A + A for i in range(3, N + 1): if i % 2: even -= A[s_even_idx - 1] s_even_idx += 2 t_even_idx += 2 even += A[t_even_idx - 1] X[i] = S - 2 * even else: odd -= A[s_odd_idx - 1] s_odd_idx += 2 t_odd_idx += 2 odd += A[t_odd_idx - 1] X[i] = S - 2 * odd for i in range(1, N + 1): print(X[i], end=" ")
N = int(eval(input())) A = list(map(int, input().split())) S = sum(A) A = A + A b_odd = sum([A[i] for i in range(1, N) if (i + 1) % 2 == 0]) b_even = sum([A[i] for i in range(2, N) if (i + 1) % 2 != 0]) b_odd_s, b_odd_t = 2, N - 1 b_even_s, b_even_t = 3, N B = [0] * N B[0] = str(S - 2 * b_odd) B[1] = str(S - 2 * b_even) for i in range(2, N): if (i + 1) % 2: b_odd -= A[b_odd_s - 1] b_odd_s += 2 b_odd_t += 2 b_odd += A[b_odd_t - 1] B[i] = str(S - 2 * b_odd) else: b_even -= A[b_even_s - 1] b_even_s += 2 b_even_t += 2 b_even += A[b_even_t - 1] B[i] = str(S - 2 * b_even) print((*B))
false
24.324324
[ "-from collections import deque", "-", "-N = int(input())", "+N = int(eval(input()))", "-X = [0] * (N + 1)", "-even_list = [A[i] for i in range(1, N) if (i + 1) % 2 == 0]", "-odd_list = [A[i] for i in range(1, N) if (i + 1) % 2 != 0]", "-X[1] = S - 2 * sum(even_list)", "-X[2] = S - 2 * sum(odd_list)", "-even = sum(even_list)", "-odd = sum(odd_list)", "-s_even_idx = 2", "-s_odd_idx = 3", "-t_even_idx = N - 1", "-t_odd_idx = N", "-for i in range(3, N + 1):", "- if i % 2:", "- even -= A[s_even_idx - 1]", "- s_even_idx += 2", "- t_even_idx += 2", "- even += A[t_even_idx - 1]", "- X[i] = S - 2 * even", "+b_odd = sum([A[i] for i in range(1, N) if (i + 1) % 2 == 0])", "+b_even = sum([A[i] for i in range(2, N) if (i + 1) % 2 != 0])", "+b_odd_s, b_odd_t = 2, N - 1", "+b_even_s, b_even_t = 3, N", "+B = [0] * N", "+B[0] = str(S - 2 * b_odd)", "+B[1] = str(S - 2 * b_even)", "+for i in range(2, N):", "+ if (i + 1) % 2:", "+ b_odd -= A[b_odd_s - 1]", "+ b_odd_s += 2", "+ b_odd_t += 2", "+ b_odd += A[b_odd_t - 1]", "+ B[i] = str(S - 2 * b_odd)", "- odd -= A[s_odd_idx - 1]", "- s_odd_idx += 2", "- t_odd_idx += 2", "- odd += A[t_odd_idx - 1]", "- X[i] = S - 2 * odd", "-for i in range(1, N + 1):", "- print(X[i], end=\" \")", "+ b_even -= A[b_even_s - 1]", "+ b_even_s += 2", "+ b_even_t += 2", "+ b_even += A[b_even_t - 1]", "+ B[i] = str(S - 2 * b_even)", "+print((*B))" ]
false
0.050313
0.043957
1.144612
[ "s099968601", "s793088612" ]
u922449550
p03525
python
s253419450
s267884267
518
21
3,572
3,064
Accepted
Accepted
95.95
N = int(eval(input())) D = [0] + list(map(int, input().split())) Diffs = [[[0, 0] for i in range(N+1)] for j in range(N+1)] # ある都市間の時差の取りうる値は2種類のみ # 先ずはそれを全列挙 candidates = [] for i in range(N+1): for j in range(i+1, N+1): di, dj = D[i], D[j] diff1, diff2 = abs(di-dj), min(24-di-dj, di+dj) candidates.extend([[i, j, diff1, 0], [i, j, diff2, 1]]) Diffs[i][j] = [diff1, diff2] # 上で全列挙した時差に関して、その時差が全体の最小値となり得るかどうかを確認していく # 最小値となり得るかどうかを確認したい時差の値をdiffとすると、 # 任意の2都市間の時差がdiff以上となる必要があり、そのような時間の設定方法があるかどうかを確認する # 矛盾するかどうかは都市を2色で塗り分ける要領で確認できる ans = 0 for idx1, idx2, diff, c in candidates: conditions = [-1] * (N+1) if c == 0: conditions[idx1] = conditions[idx2] = 0 else: conditions[idx1] = 0; conditions[idx2] = 1 res = True for i in range(N+1): for j in range(i+1, N+1): if idx1 == i and idx2 == j: continue diff1, diff2 = Diffs[i][j] if diff1 < diff and diff2 < diff: res = False break elif diff1 < diff: c1, c2 = conditions[i], conditions[j] if c1 < 0 and c2 < 0: conditions[i] = 0; conditions[j] = 1 elif c1 < 0: conditions[i] = 1 - c2 elif c2 < 0: conditions[j] = 1 - c1 else: if c1 == c2: res = False break elif diff2 < diff: c1, c2 = conditions[i], conditions[j] if c1 < 0 and c2 < 0: conditions[i] = conditions[j] = 0 elif c1 < 0: conditions[i] = c2 elif c2 < 0: conditions[j] = c1 else: if c1 != c2: res = False break else: continue break if res: ans = max(ans, diff) print(ans)
# 想定解法 N = int(eval(input())) D = list(map(int, input().split())) num_time = [0] * 13 num_time[0] = 2 num_time[12] = 1 fixed = [0] unfixed = [] for d in D: num_time[d] += 1 if d == 12: fixed.append(12) if num_time[d] >= 3: print((0)) quit() for t in range(1, 12): if num_time[t] == 2: fixed.extend([t, 24 - t]) elif num_time[t] == 1: unfixed.append(t) ans = 0 n = len(unfixed) for i in range(2**n): t = fixed.copy() + [24] # bitが0のものはt, 1のものは24-tとして設定する for j in range(n): if i >> j & 1: t.append(unfixed[j]) else: t.append(24 - unfixed[j]) t.sort() s = 24 m = len(t) for k in range(m-1): _s = t[k+1] - t[k] s = min(s, _s) ans = max(ans, s) print(ans)
65
43
1,767
764
N = int(eval(input())) D = [0] + list(map(int, input().split())) Diffs = [[[0, 0] for i in range(N + 1)] for j in range(N + 1)] # ある都市間の時差の取りうる値は2種類のみ # 先ずはそれを全列挙 candidates = [] for i in range(N + 1): for j in range(i + 1, N + 1): di, dj = D[i], D[j] diff1, diff2 = abs(di - dj), min(24 - di - dj, di + dj) candidates.extend([[i, j, diff1, 0], [i, j, diff2, 1]]) Diffs[i][j] = [diff1, diff2] # 上で全列挙した時差に関して、その時差が全体の最小値となり得るかどうかを確認していく # 最小値となり得るかどうかを確認したい時差の値をdiffとすると、 # 任意の2都市間の時差がdiff以上となる必要があり、そのような時間の設定方法があるかどうかを確認する # 矛盾するかどうかは都市を2色で塗り分ける要領で確認できる ans = 0 for idx1, idx2, diff, c in candidates: conditions = [-1] * (N + 1) if c == 0: conditions[idx1] = conditions[idx2] = 0 else: conditions[idx1] = 0 conditions[idx2] = 1 res = True for i in range(N + 1): for j in range(i + 1, N + 1): if idx1 == i and idx2 == j: continue diff1, diff2 = Diffs[i][j] if diff1 < diff and diff2 < diff: res = False break elif diff1 < diff: c1, c2 = conditions[i], conditions[j] if c1 < 0 and c2 < 0: conditions[i] = 0 conditions[j] = 1 elif c1 < 0: conditions[i] = 1 - c2 elif c2 < 0: conditions[j] = 1 - c1 else: if c1 == c2: res = False break elif diff2 < diff: c1, c2 = conditions[i], conditions[j] if c1 < 0 and c2 < 0: conditions[i] = conditions[j] = 0 elif c1 < 0: conditions[i] = c2 elif c2 < 0: conditions[j] = c1 else: if c1 != c2: res = False break else: continue break if res: ans = max(ans, diff) print(ans)
# 想定解法 N = int(eval(input())) D = list(map(int, input().split())) num_time = [0] * 13 num_time[0] = 2 num_time[12] = 1 fixed = [0] unfixed = [] for d in D: num_time[d] += 1 if d == 12: fixed.append(12) if num_time[d] >= 3: print((0)) quit() for t in range(1, 12): if num_time[t] == 2: fixed.extend([t, 24 - t]) elif num_time[t] == 1: unfixed.append(t) ans = 0 n = len(unfixed) for i in range(2**n): t = fixed.copy() + [24] # bitが0のものはt, 1のものは24-tとして設定する for j in range(n): if i >> j & 1: t.append(unfixed[j]) else: t.append(24 - unfixed[j]) t.sort() s = 24 m = len(t) for k in range(m - 1): _s = t[k + 1] - t[k] s = min(s, _s) ans = max(ans, s) print(ans)
false
33.846154
[ "+# 想定解法", "-D = [0] + list(map(int, input().split()))", "-Diffs = [[[0, 0] for i in range(N + 1)] for j in range(N + 1)]", "-# ある都市間の時差の取りうる値は2種類のみ", "-# 先ずはそれを全列挙", "-candidates = []", "-for i in range(N + 1):", "- for j in range(i + 1, N + 1):", "- di, dj = D[i], D[j]", "- diff1, diff2 = abs(di - dj), min(24 - di - dj, di + dj)", "- candidates.extend([[i, j, diff1, 0], [i, j, diff2, 1]])", "- Diffs[i][j] = [diff1, diff2]", "-# 上で全列挙した時差に関して、その時差が全体の最小値となり得るかどうかを確認していく", "-# 最小値となり得るかどうかを確認したい時差の値をdiffとすると、", "-# 任意の2都市間の時差がdiff以上となる必要があり、そのような時間の設定方法があるかどうかを確認する", "-# 矛盾するかどうかは都市を2色で塗り分ける要領で確認できる", "+D = list(map(int, input().split()))", "+num_time = [0] * 13", "+num_time[0] = 2", "+num_time[12] = 1", "+fixed = [0]", "+unfixed = []", "+for d in D:", "+ num_time[d] += 1", "+ if d == 12:", "+ fixed.append(12)", "+ if num_time[d] >= 3:", "+ print((0))", "+ quit()", "+for t in range(1, 12):", "+ if num_time[t] == 2:", "+ fixed.extend([t, 24 - t])", "+ elif num_time[t] == 1:", "+ unfixed.append(t)", "-for idx1, idx2, diff, c in candidates:", "- conditions = [-1] * (N + 1)", "- if c == 0:", "- conditions[idx1] = conditions[idx2] = 0", "- else:", "- conditions[idx1] = 0", "- conditions[idx2] = 1", "- res = True", "- for i in range(N + 1):", "- for j in range(i + 1, N + 1):", "- if idx1 == i and idx2 == j:", "- continue", "- diff1, diff2 = Diffs[i][j]", "- if diff1 < diff and diff2 < diff:", "- res = False", "- break", "- elif diff1 < diff:", "- c1, c2 = conditions[i], conditions[j]", "- if c1 < 0 and c2 < 0:", "- conditions[i] = 0", "- conditions[j] = 1", "- elif c1 < 0:", "- conditions[i] = 1 - c2", "- elif c2 < 0:", "- conditions[j] = 1 - c1", "- else:", "- if c1 == c2:", "- res = False", "- break", "- elif diff2 < diff:", "- c1, c2 = conditions[i], conditions[j]", "- if c1 < 0 and c2 < 0:", "- conditions[i] = conditions[j] = 0", "- elif c1 < 0:", "- conditions[i] = c2", "- elif c2 < 0:", "- conditions[j] = c1", "- else:", "- if c1 != c2:", "- res = False", "- break", "+n = len(unfixed)", "+for i in range(2**n):", "+ t = fixed.copy() + [24]", "+ # bitが0のものはt, 1のものは24-tとして設定する", "+ for j in range(n):", "+ if i >> j & 1:", "+ t.append(unfixed[j])", "- continue", "- break", "- if res:", "- ans = max(ans, diff)", "+ t.append(24 - unfixed[j])", "+ t.sort()", "+ s = 24", "+ m = len(t)", "+ for k in range(m - 1):", "+ _s = t[k + 1] - t[k]", "+ s = min(s, _s)", "+ ans = max(ans, s)" ]
false
0.037948
0.038686
0.980915
[ "s253419450", "s267884267" ]
u006880673
p03835
python
s255005712
s724129805
423
268
130,940
41,196
Accepted
Accepted
36.64
k, s = list(map(int, input().split())) l=[] for x in range(0, k+1): for y in range(0, k+1): if s-x-y > k or s-x-y < 0: continue else: l.append(s-x-y) print((len(l)))
k, s = list(map(int, input().split())) c=0 for x in range(k+1): for y in range(k+1): z = s-x-y if z > k or z < 0: continue c += 1 print(c)
9
9
209
180
k, s = list(map(int, input().split())) l = [] for x in range(0, k + 1): for y in range(0, k + 1): if s - x - y > k or s - x - y < 0: continue else: l.append(s - x - y) print((len(l)))
k, s = list(map(int, input().split())) c = 0 for x in range(k + 1): for y in range(k + 1): z = s - x - y if z > k or z < 0: continue c += 1 print(c)
false
0
[ "-l = []", "-for x in range(0, k + 1):", "- for y in range(0, k + 1):", "- if s - x - y > k or s - x - y < 0:", "+c = 0", "+for x in range(k + 1):", "+ for y in range(k + 1):", "+ z = s - x - y", "+ if z > k or z < 0:", "- else:", "- l.append(s - x - y)", "-print((len(l)))", "+ c += 1", "+print(c)" ]
false
0.035308
0.112602
0.313566
[ "s255005712", "s724129805" ]
u970197315
p02695
python
s856213933
s900711927
1,045
581
21,524
9,240
Accepted
Accepted
44.4
n,m,q=list(map(int,input().split())) a,b=[],[] c,d=[],[] for i in range(q): aa,bb,cc,dd=list(map(int,input().split())) a.append(aa-1) b.append(bb-1) c.append(cc) d.append(dd) l=[int(i) for i in range(1,m+1)] from itertools import combinations_with_replacement ans=0 for ll in list(combinations_with_replacement(l,n)): t=0 for i in range(q): if ll[b[i]]-ll[a[i]]==c[i]: t+=d[i] ans=max(ans,t) print(ans)
def calc(l): t=0 for ai,bi,ci,di in zip(a,b,c,d): if l[bi]-l[ai]==ci: t+=di return t def dfs(l): if len(l)==n: return calc(l) res=0 prev_last=0 if len(l)>0: prev_last=l[-1] for v in range(prev_last,m): l.append(v) res=max(res,dfs(l)) l.pop() return res n,m,q=list(map(int,input().split())) a,b=[],[] c,d=[],[] for i in range(q): aa,bb,cc,dd=list(map(int,input().split())) a.append(aa-1) b.append(bb-1) c.append(cc) d.append(dd) print((dfs([])))
19
33
434
526
n, m, q = list(map(int, input().split())) a, b = [], [] c, d = [], [] for i in range(q): aa, bb, cc, dd = list(map(int, input().split())) a.append(aa - 1) b.append(bb - 1) c.append(cc) d.append(dd) l = [int(i) for i in range(1, m + 1)] from itertools import combinations_with_replacement ans = 0 for ll in list(combinations_with_replacement(l, n)): t = 0 for i in range(q): if ll[b[i]] - ll[a[i]] == c[i]: t += d[i] ans = max(ans, t) print(ans)
def calc(l): t = 0 for ai, bi, ci, di in zip(a, b, c, d): if l[bi] - l[ai] == ci: t += di return t def dfs(l): if len(l) == n: return calc(l) res = 0 prev_last = 0 if len(l) > 0: prev_last = l[-1] for v in range(prev_last, m): l.append(v) res = max(res, dfs(l)) l.pop() return res n, m, q = list(map(int, input().split())) a, b = [], [] c, d = [], [] for i in range(q): aa, bb, cc, dd = list(map(int, input().split())) a.append(aa - 1) b.append(bb - 1) c.append(cc) d.append(dd) print((dfs([])))
false
42.424242
[ "+def calc(l):", "+ t = 0", "+ for ai, bi, ci, di in zip(a, b, c, d):", "+ if l[bi] - l[ai] == ci:", "+ t += di", "+ return t", "+", "+", "+def dfs(l):", "+ if len(l) == n:", "+ return calc(l)", "+ res = 0", "+ prev_last = 0", "+ if len(l) > 0:", "+ prev_last = l[-1]", "+ for v in range(prev_last, m):", "+ l.append(v)", "+ res = max(res, dfs(l))", "+ l.pop()", "+ return res", "+", "+", "-l = [int(i) for i in range(1, m + 1)]", "-from itertools import combinations_with_replacement", "-", "-ans = 0", "-for ll in list(combinations_with_replacement(l, n)):", "- t = 0", "- for i in range(q):", "- if ll[b[i]] - ll[a[i]] == c[i]:", "- t += d[i]", "- ans = max(ans, t)", "-print(ans)", "+print((dfs([])))" ]
false
0.049398
0.054841
0.900753
[ "s856213933", "s900711927" ]
u223646582
p02984
python
s871870483
s434039567
278
120
69,732
14,092
Accepted
Accepted
56.83
N = int(eval(input())) A = [int(i) for i in input().split()] ans = [] m = sum(A[::2])-sum(A[1::2]) ans.append(m) for i in range(N-1): m = 2*A[i]-m ans.append(m) print((*ans))
N = int(eval(input())) A = [int(i) for i in input().split()] p = 0 for a in A: p = a*2-p ans = [p//2] for a in A[:-1]: ans.append(a*2-ans[-1]) print((*ans))
11
11
187
169
N = int(eval(input())) A = [int(i) for i in input().split()] ans = [] m = sum(A[::2]) - sum(A[1::2]) ans.append(m) for i in range(N - 1): m = 2 * A[i] - m ans.append(m) print((*ans))
N = int(eval(input())) A = [int(i) for i in input().split()] p = 0 for a in A: p = a * 2 - p ans = [p // 2] for a in A[:-1]: ans.append(a * 2 - ans[-1]) print((*ans))
false
0
[ "-ans = []", "-m = sum(A[::2]) - sum(A[1::2])", "-ans.append(m)", "-for i in range(N - 1):", "- m = 2 * A[i] - m", "- ans.append(m)", "+p = 0", "+for a in A:", "+ p = a * 2 - p", "+ans = [p // 2]", "+for a in A[:-1]:", "+ ans.append(a * 2 - ans[-1])" ]
false
0.066678
0.174421
0.382283
[ "s871870483", "s434039567" ]
u645250356
p03244
python
s719650509
s597779834
174
106
20,036
22,348
Accepted
Accepted
39.08
import math,fractions from collections import Counter n = int(eval(input())) v = [int(i) for i in input().split()] a = [v[i] for i in range(n) if i%2] b = [v[i] for i in range(n) if i%2==0] cnt_a = Counter(a) cnt_b = Counter(b) max_a = cnt_a.most_common()[0][1] max_b = cnt_b.most_common()[0][1] str_a = cnt_a.most_common()[0][0] str_b = cnt_b.most_common()[0][0] max_2a = 0 max_2b = 0 for i in cnt_a: if str_a != i and cnt_a[i] > max_2a: max_2a = cnt_a[i] for i in cnt_b: if str_b != i and cnt_b[i] > max_2b: max_2b = cnt_b[i] if str_a != str_b: print((n//2 - max_a + n//2 - max_b)) else: tmp_a = n//2 - max_2a + n//2 - max_b tmp_b = n//2 - max_a + n//2 - max_2b print((min(tmp_a,tmp_b)))
import math,fractions from collections import Counter n = int(eval(input())) v = [int(i) for i in input().split()] a = Counter(v[1::2]).most_common() b = Counter(v[0::2]).most_common() a.append((0,0)) b.append((0,0)) if a[0][0] != b[0][0]: print((n//2 - a[0][1] + n//2 - b[0][1])) else: tmp_x = n//2 - a[1][1] + n//2 - b[0][1] tmp_y = n//2 - a[0][1] + n//2 - b[1][1] print((min(tmp_x, tmp_y)))
31
15
756
415
import math, fractions from collections import Counter n = int(eval(input())) v = [int(i) for i in input().split()] a = [v[i] for i in range(n) if i % 2] b = [v[i] for i in range(n) if i % 2 == 0] cnt_a = Counter(a) cnt_b = Counter(b) max_a = cnt_a.most_common()[0][1] max_b = cnt_b.most_common()[0][1] str_a = cnt_a.most_common()[0][0] str_b = cnt_b.most_common()[0][0] max_2a = 0 max_2b = 0 for i in cnt_a: if str_a != i and cnt_a[i] > max_2a: max_2a = cnt_a[i] for i in cnt_b: if str_b != i and cnt_b[i] > max_2b: max_2b = cnt_b[i] if str_a != str_b: print((n // 2 - max_a + n // 2 - max_b)) else: tmp_a = n // 2 - max_2a + n // 2 - max_b tmp_b = n // 2 - max_a + n // 2 - max_2b print((min(tmp_a, tmp_b)))
import math, fractions from collections import Counter n = int(eval(input())) v = [int(i) for i in input().split()] a = Counter(v[1::2]).most_common() b = Counter(v[0::2]).most_common() a.append((0, 0)) b.append((0, 0)) if a[0][0] != b[0][0]: print((n // 2 - a[0][1] + n // 2 - b[0][1])) else: tmp_x = n // 2 - a[1][1] + n // 2 - b[0][1] tmp_y = n // 2 - a[0][1] + n // 2 - b[1][1] print((min(tmp_x, tmp_y)))
false
51.612903
[ "-a = [v[i] for i in range(n) if i % 2]", "-b = [v[i] for i in range(n) if i % 2 == 0]", "-cnt_a = Counter(a)", "-cnt_b = Counter(b)", "-max_a = cnt_a.most_common()[0][1]", "-max_b = cnt_b.most_common()[0][1]", "-str_a = cnt_a.most_common()[0][0]", "-str_b = cnt_b.most_common()[0][0]", "-max_2a = 0", "-max_2b = 0", "-for i in cnt_a:", "- if str_a != i and cnt_a[i] > max_2a:", "- max_2a = cnt_a[i]", "-for i in cnt_b:", "- if str_b != i and cnt_b[i] > max_2b:", "- max_2b = cnt_b[i]", "-if str_a != str_b:", "- print((n // 2 - max_a + n // 2 - max_b))", "+a = Counter(v[1::2]).most_common()", "+b = Counter(v[0::2]).most_common()", "+a.append((0, 0))", "+b.append((0, 0))", "+if a[0][0] != b[0][0]:", "+ print((n // 2 - a[0][1] + n // 2 - b[0][1]))", "- tmp_a = n // 2 - max_2a + n // 2 - max_b", "- tmp_b = n // 2 - max_a + n // 2 - max_2b", "- print((min(tmp_a, tmp_b)))", "+ tmp_x = n // 2 - a[1][1] + n // 2 - b[0][1]", "+ tmp_y = n // 2 - a[0][1] + n // 2 - b[1][1]", "+ print((min(tmp_x, tmp_y)))" ]
false
0.036411
0.036396
1.000409
[ "s719650509", "s597779834" ]
u922449550
p04000
python
s768242617
s543598032
2,087
1,919
70,488
64,344
Accepted
Accepted
8.05
H, W, N = map(int, input().split()) ab = set(tuple(map(int, input().split())) for i in range(N)) dxy = {0:[0, 1, 2], 1:[-1, 0, 1], 2:[-2, -1, 0]} num_all = (H - 2) * (W - 2) num = [0] * 10 for a, b in ab: for i in range(3): Da = dxy[i] for j in range(3): n = 0 flag = False Db = dxy[j] for da in Da: aa = a + da for db in Db: bb = b + db if aa < 1 or H < aa or bb < 1 or W < bb: flag = True break if (aa, bb) in ab: n += 1 if flag: break if flag: continue num[n] += 1 for i in range(2, 10): num[i] //= i num[0] = num_all - sum(num[1:]) print(*num, sep='\n')
import sys input = sys.stdin.readline H, W, N = map(int, input().split()) ab = set(tuple(map(int, input().split())) for i in range(N)) dxy = {0:[0, 1, 2], 1:[-1, 0, 1], 2:[-2, -1, 0]} num_all = (H - 2) * (W - 2) num = [0] * 10 for a, b in ab: for i in range(3): Da = dxy[i] for j in range(3): n = 0 flag = False Db = dxy[j] for da in Da: aa = a + da for db in Db: bb = b + db if aa < 1 or H < aa or bb < 1 or W < bb: flag = True break if (aa, bb) in ab: n += 1 if flag: break if flag: continue num[n] += 1 for i in range(2, 10): num[i] //= i num[0] = num_all - sum(num[1:]) print(*num, sep='\n')
33
36
748
790
H, W, N = map(int, input().split()) ab = set(tuple(map(int, input().split())) for i in range(N)) dxy = {0: [0, 1, 2], 1: [-1, 0, 1], 2: [-2, -1, 0]} num_all = (H - 2) * (W - 2) num = [0] * 10 for a, b in ab: for i in range(3): Da = dxy[i] for j in range(3): n = 0 flag = False Db = dxy[j] for da in Da: aa = a + da for db in Db: bb = b + db if aa < 1 or H < aa or bb < 1 or W < bb: flag = True break if (aa, bb) in ab: n += 1 if flag: break if flag: continue num[n] += 1 for i in range(2, 10): num[i] //= i num[0] = num_all - sum(num[1:]) print(*num, sep="\n")
import sys input = sys.stdin.readline H, W, N = map(int, input().split()) ab = set(tuple(map(int, input().split())) for i in range(N)) dxy = {0: [0, 1, 2], 1: [-1, 0, 1], 2: [-2, -1, 0]} num_all = (H - 2) * (W - 2) num = [0] * 10 for a, b in ab: for i in range(3): Da = dxy[i] for j in range(3): n = 0 flag = False Db = dxy[j] for da in Da: aa = a + da for db in Db: bb = b + db if aa < 1 or H < aa or bb < 1 or W < bb: flag = True break if (aa, bb) in ab: n += 1 if flag: break if flag: continue num[n] += 1 for i in range(2, 10): num[i] //= i num[0] = num_all - sum(num[1:]) print(*num, sep="\n")
false
8.333333
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.033009
0.032479
1.016322
[ "s768242617", "s543598032" ]
u500376440
p03363
python
s700159134
s923020523
182
162
139,488
145,232
Accepted
Accepted
10.99
from collections import * from itertools import * N=int(eval(input())) A=list(map(int,input().split())) s1=[0]+list(accumulate(A)) nums=defaultdict(int) for i in range(N+1): nums[s1[i]]+=1 ans=0 s2=set(s1) for x in s2: ans+=nums[x]*(nums[x]-1)//2 print(ans)
from collections import * from itertools import * N=int(eval(input())) A=list(map(int,input().split())) s=[0]+list(accumulate(A)) s_cnt=Counter(s) ans=0 for x in list(s_cnt.values()): ans+=(x*(x-1))//2 print(ans)
17
14
276
220
from collections import * from itertools import * N = int(eval(input())) A = list(map(int, input().split())) s1 = [0] + list(accumulate(A)) nums = defaultdict(int) for i in range(N + 1): nums[s1[i]] += 1 ans = 0 s2 = set(s1) for x in s2: ans += nums[x] * (nums[x] - 1) // 2 print(ans)
from collections import * from itertools import * N = int(eval(input())) A = list(map(int, input().split())) s = [0] + list(accumulate(A)) s_cnt = Counter(s) ans = 0 for x in list(s_cnt.values()): ans += (x * (x - 1)) // 2 print(ans)
false
17.647059
[ "-s1 = [0] + list(accumulate(A))", "-nums = defaultdict(int)", "-for i in range(N + 1):", "- nums[s1[i]] += 1", "+s = [0] + list(accumulate(A))", "+s_cnt = Counter(s)", "-s2 = set(s1)", "-for x in s2:", "- ans += nums[x] * (nums[x] - 1) // 2", "+for x in list(s_cnt.values()):", "+ ans += (x * (x - 1)) // 2" ]
false
0.040462
0.039341
1.028504
[ "s700159134", "s923020523" ]
u133936772
p02814
python
s044338750
s296849356
240
104
63,984
14,244
Accepted
Accepted
56.67
n, m = list(map(int, input().split())) l = list(map(int, input().split())) def gcd(x, y): return x if y == 0 else gcd(y, x % y) def lcm(x, y): return (x * y) // gcd(x, y) k = 1 for i in l: i //= 2 k = lcm(k, i) if (k // i) % 2 == 0 or k > m: print((0)) break else: print((m // k - m // (k * 2)))
f=lambda:list(map(int,input().split())) n,m=f() l=list(f()) def g(x,y): while y: x,y=y,x%y return x k=1 for i in l: i//=2; k=k*i//g(k,i) if (k//i)%2<1 or k>m: print((0)); break else: print((m//k-m//(k*2)))
18
12
345
216
n, m = list(map(int, input().split())) l = list(map(int, input().split())) def gcd(x, y): return x if y == 0 else gcd(y, x % y) def lcm(x, y): return (x * y) // gcd(x, y) k = 1 for i in l: i //= 2 k = lcm(k, i) if (k // i) % 2 == 0 or k > m: print((0)) break else: print((m // k - m // (k * 2)))
f = lambda: list(map(int, input().split())) n, m = f() l = list(f()) def g(x, y): while y: x, y = y, x % y return x k = 1 for i in l: i //= 2 k = k * i // g(k, i) if (k // i) % 2 < 1 or k > m: print((0)) break else: print((m // k - m // (k * 2)))
false
33.333333
[ "-n, m = list(map(int, input().split()))", "-l = list(map(int, input().split()))", "+f = lambda: list(map(int, input().split()))", "+n, m = f()", "+l = list(f())", "-def gcd(x, y):", "- return x if y == 0 else gcd(y, x % y)", "-", "-", "-def lcm(x, y):", "- return (x * y) // gcd(x, y)", "+def g(x, y):", "+ while y:", "+ x, y = y, x % y", "+ return x", "- k = lcm(k, i)", "- if (k // i) % 2 == 0 or k > m:", "+ k = k * i // g(k, i)", "+ if (k // i) % 2 < 1 or k > m:" ]
false
0.039245
0.107915
0.363669
[ "s044338750", "s296849356" ]
u781535828
p02689
python
s944259853
s162828042
710
601
54,440
54,380
Accepted
Accepted
15.35
class Observatory: def __init__(self, height, around=[]): self.height = height x = [] self.around = x def is_good(self, li, dic): flag = True for i in self.around: o = li[i-1] if o.height >= self.height: flag = False else: dic[i-1] = False return flag n, m = list(map(int, input().split())) h = [int(i) for i in input().split()] observatories = [Observatory(h[i]) for i in range(n)] dic = {} for i in range(n): dic[i] = True for i in range(m): a, b = list(map(int, input().split())) observatories[a-1].around.append(b) observatories[b-1].around.append(a) ans = 0 for i in range(n): o = observatories[i] if dic[i]: if o.is_good(observatories, dic): ans += 1 print(ans)
class Observatory: def __init__(self, height): self.height = height self.around = [] def is_good(self, li, di): flag = True for i in self.around: oo = li[i - 1] if oo.height >= self.height: flag = False else: di[i - 1] = False return flag n, m = list(map(int, input().split())) h = [int(i) for i in input().split()] observatories = [Observatory(h[i]) for i in range(n)] dic = {} for i in range(n): dic[i] = True for i in range(m): a, b = list(map(int, input().split())) observatories[a - 1].around.append(b) observatories[b - 1].around.append(a) ans = 0 for i in range(n): o = observatories[i] if dic[i]: if o.is_good(observatories, dic): ans += 1 print(ans)
36
37
868
850
class Observatory: def __init__(self, height, around=[]): self.height = height x = [] self.around = x def is_good(self, li, dic): flag = True for i in self.around: o = li[i - 1] if o.height >= self.height: flag = False else: dic[i - 1] = False return flag n, m = list(map(int, input().split())) h = [int(i) for i in input().split()] observatories = [Observatory(h[i]) for i in range(n)] dic = {} for i in range(n): dic[i] = True for i in range(m): a, b = list(map(int, input().split())) observatories[a - 1].around.append(b) observatories[b - 1].around.append(a) ans = 0 for i in range(n): o = observatories[i] if dic[i]: if o.is_good(observatories, dic): ans += 1 print(ans)
class Observatory: def __init__(self, height): self.height = height self.around = [] def is_good(self, li, di): flag = True for i in self.around: oo = li[i - 1] if oo.height >= self.height: flag = False else: di[i - 1] = False return flag n, m = list(map(int, input().split())) h = [int(i) for i in input().split()] observatories = [Observatory(h[i]) for i in range(n)] dic = {} for i in range(n): dic[i] = True for i in range(m): a, b = list(map(int, input().split())) observatories[a - 1].around.append(b) observatories[b - 1].around.append(a) ans = 0 for i in range(n): o = observatories[i] if dic[i]: if o.is_good(observatories, dic): ans += 1 print(ans)
false
2.702703
[ "- def __init__(self, height, around=[]):", "+ def __init__(self, height):", "- x = []", "- self.around = x", "+ self.around = []", "- def is_good(self, li, dic):", "+ def is_good(self, li, di):", "- o = li[i - 1]", "- if o.height >= self.height:", "+ oo = li[i - 1]", "+ if oo.height >= self.height:", "- dic[i - 1] = False", "+ di[i - 1] = False" ]
false
0.07137
0.037871
1.884576
[ "s944259853", "s162828042" ]
u867848444
p02820
python
s892122729
s864561907
78
68
4,084
4,084
Accepted
Accepted
12.82
n,k=list(map(int,input().split())) get_score=list(map(int,input().split())) t=list(eval(input())) dic={'r':0,'s':1,'p':2} ans=0 for i in range(n): if t[i]=='D':continue if i+k<n and t[i]==t[i+k]: t[i+k]='D' ans+=get_score[(dic[t[i]]+2)%3] print(ans)
n,k = list(map(int,input().split())) r, s, p = list(map(int,input().split())) t = list(eval(input())) dic = {'r':p, 's':r, 'p':s} score = 0 for i in range(n): if t[i] == 0:continue score += dic[t[i]] if i + k < n and t[i + k] == t[i]: t[i + k] = 0 print(score)
13
12
271
274
n, k = list(map(int, input().split())) get_score = list(map(int, input().split())) t = list(eval(input())) dic = {"r": 0, "s": 1, "p": 2} ans = 0 for i in range(n): if t[i] == "D": continue if i + k < n and t[i] == t[i + k]: t[i + k] = "D" ans += get_score[(dic[t[i]] + 2) % 3] print(ans)
n, k = list(map(int, input().split())) r, s, p = list(map(int, input().split())) t = list(eval(input())) dic = {"r": p, "s": r, "p": s} score = 0 for i in range(n): if t[i] == 0: continue score += dic[t[i]] if i + k < n and t[i + k] == t[i]: t[i + k] = 0 print(score)
false
7.692308
[ "-get_score = list(map(int, input().split()))", "+r, s, p = list(map(int, input().split()))", "-dic = {\"r\": 0, \"s\": 1, \"p\": 2}", "-ans = 0", "+dic = {\"r\": p, \"s\": r, \"p\": s}", "+score = 0", "- if t[i] == \"D\":", "+ if t[i] == 0:", "- if i + k < n and t[i] == t[i + k]:", "- t[i + k] = \"D\"", "- ans += get_score[(dic[t[i]] + 2) % 3]", "-print(ans)", "+ score += dic[t[i]]", "+ if i + k < n and t[i + k] == t[i]:", "+ t[i + k] = 0", "+print(score)" ]
false
0.039491
0.175806
0.22463
[ "s892122729", "s864561907" ]
u008357982
p03317
python
s746661911
s653371100
19
17
4,280
2,940
Accepted
Accepted
10.53
n,k=list(map(int,input().split()));eval(input()) print((-(-~-n//~-k)))
n,k=list(map(int,input().split()));print((-(-~-n//~-k)))
2
1
57
48
n, k = list(map(int, input().split())) eval(input()) print((-(-~-n // ~-k)))
n, k = list(map(int, input().split())) print((-(-~-n // ~-k)))
false
50
[ "-eval(input())" ]
false
0.040451
0.039694
1.01908
[ "s746661911", "s653371100" ]
u753803401
p03111
python
s788808420
s638676947
686
339
75,376
51,292
Accepted
Accepted
50.58
def slove(): import sys, itertools input = sys.stdin.readline n, a, b, c = list(map(int, input().rstrip('\n').split())) l = [int(input().rstrip('\n')) for _ in range(n)] ls = [0, 1, 2, 3] m_cost = 10 ** 10 for it in itertools.product(ls, repeat=n): if 1 in it and 2 in it and 3 in it: lst = [0] * 4 cost = 0 for i, v in enumerate(it): lst[v] += l[i] if v == 1 or v == 2 or v == 3: cost += 10 cost -= 30 cost += (abs(lst[1] - a) + abs(lst[2] - b) + abs(lst[3] - c)) m_cost = min(m_cost, cost) print(m_cost) if __name__ == '__main__': slove()
def slove(): import sys import itertools input = sys.stdin.readline n, a, b, c = list(map(int, input().rstrip('\n').split())) l = [int(input().rstrip('\n')) for _ in range(n)] mt = 10 ** 10 for v in itertools.product([i for i in range(4)], repeat=n): nl = [[] for _ in range(4)] for i, vv in enumerate(v): nl[vv].append(l[i]) if len(nl[1]) != 0 and len(nl[2]) != 0 and len(nl[3]) != 0: t = 0 t += ((len(nl[1]) - 1) * 10 + abs(a - sum(nl[1]))) t += ((len(nl[2]) - 1) * 10 + abs(b - sum(nl[2]))) t += ((len(nl[3]) - 1) * 10 + abs(c - sum(nl[3]))) mt = min(t, mt) print(mt) if __name__ == '__main__': slove()
24
22
735
761
def slove(): import sys, itertools input = sys.stdin.readline n, a, b, c = list(map(int, input().rstrip("\n").split())) l = [int(input().rstrip("\n")) for _ in range(n)] ls = [0, 1, 2, 3] m_cost = 10**10 for it in itertools.product(ls, repeat=n): if 1 in it and 2 in it and 3 in it: lst = [0] * 4 cost = 0 for i, v in enumerate(it): lst[v] += l[i] if v == 1 or v == 2 or v == 3: cost += 10 cost -= 30 cost += abs(lst[1] - a) + abs(lst[2] - b) + abs(lst[3] - c) m_cost = min(m_cost, cost) print(m_cost) if __name__ == "__main__": slove()
def slove(): import sys import itertools input = sys.stdin.readline n, a, b, c = list(map(int, input().rstrip("\n").split())) l = [int(input().rstrip("\n")) for _ in range(n)] mt = 10**10 for v in itertools.product([i for i in range(4)], repeat=n): nl = [[] for _ in range(4)] for i, vv in enumerate(v): nl[vv].append(l[i]) if len(nl[1]) != 0 and len(nl[2]) != 0 and len(nl[3]) != 0: t = 0 t += (len(nl[1]) - 1) * 10 + abs(a - sum(nl[1])) t += (len(nl[2]) - 1) * 10 + abs(b - sum(nl[2])) t += (len(nl[3]) - 1) * 10 + abs(c - sum(nl[3])) mt = min(t, mt) print(mt) if __name__ == "__main__": slove()
false
8.333333
[ "- import sys, itertools", "+ import sys", "+ import itertools", "- ls = [0, 1, 2, 3]", "- m_cost = 10**10", "- for it in itertools.product(ls, repeat=n):", "- if 1 in it and 2 in it and 3 in it:", "- lst = [0] * 4", "- cost = 0", "- for i, v in enumerate(it):", "- lst[v] += l[i]", "- if v == 1 or v == 2 or v == 3:", "- cost += 10", "- cost -= 30", "- cost += abs(lst[1] - a) + abs(lst[2] - b) + abs(lst[3] - c)", "- m_cost = min(m_cost, cost)", "- print(m_cost)", "+ mt = 10**10", "+ for v in itertools.product([i for i in range(4)], repeat=n):", "+ nl = [[] for _ in range(4)]", "+ for i, vv in enumerate(v):", "+ nl[vv].append(l[i])", "+ if len(nl[1]) != 0 and len(nl[2]) != 0 and len(nl[3]) != 0:", "+ t = 0", "+ t += (len(nl[1]) - 1) * 10 + abs(a - sum(nl[1]))", "+ t += (len(nl[2]) - 1) * 10 + abs(b - sum(nl[2]))", "+ t += (len(nl[3]) - 1) * 10 + abs(c - sum(nl[3]))", "+ mt = min(t, mt)", "+ print(mt)" ]
false
0.135277
0.224632
0.602218
[ "s788808420", "s638676947" ]
u753803401
p02842
python
s214160308
s675445357
193
178
39,408
38,640
Accepted
Accepted
7.77
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 n = int(readline()) for i in range(1, 50001): if int(i * 1.08) == n: print(i) exit() print(":(") if __name__ == '__main__': solve()
import sys def solve(): input = sys.stdin.readline mod = 10 ** 9 + 7 n = int(input().rstrip('\n')) for i in range(1, 50000): if (i * 1.08) // 1 == n: print(i) exit() print(":(") if __name__ == '__main__': solve()
16
16
286
288
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10**9 + 7 n = int(readline()) for i in range(1, 50001): if int(i * 1.08) == n: print(i) exit() print(":(") if __name__ == "__main__": solve()
import sys def solve(): input = sys.stdin.readline mod = 10**9 + 7 n = int(input().rstrip("\n")) for i in range(1, 50000): if (i * 1.08) // 1 == n: print(i) exit() print(":(") if __name__ == "__main__": solve()
false
0
[ "- readline = sys.stdin.buffer.readline", "+ input = sys.stdin.readline", "- n = int(readline())", "- for i in range(1, 50001):", "- if int(i * 1.08) == n:", "+ n = int(input().rstrip(\"\\n\"))", "+ for i in range(1, 50000):", "+ if (i * 1.08) // 1 == n:" ]
false
0.041083
0.052157
0.78768
[ "s214160308", "s675445357" ]
u078042885
p00028
python
s202468780
s820362381
30
20
7,500
7,744
Accepted
Accepted
33.33
a=[0]*100 while 1: try: n=int(eval(input())) a[n-1]+=1 except: for i in range(100): if a[i]==max(a): print((i+1)) break
a=[0]*100 while 1: try:a[int(input())-1]+=1 except:break [print(i+1)for i in range(100)if a[i]==max(a)]
9
5
171
115
a = [0] * 100 while 1: try: n = int(eval(input())) a[n - 1] += 1 except: for i in range(100): if a[i] == max(a): print((i + 1)) break
a = [0] * 100 while 1: try: a[int(input()) - 1] += 1 except: break [print(i + 1) for i in range(100) if a[i] == max(a)]
false
44.444444
[ "- n = int(eval(input()))", "- a[n - 1] += 1", "+ a[int(input()) - 1] += 1", "- for i in range(100):", "- if a[i] == max(a):", "- print((i + 1))", "+[print(i + 1) for i in range(100) if a[i] == max(a)]" ]
false
0.056851
0.067441
0.842966
[ "s202468780", "s820362381" ]
u136090046
p03495
python
s263553911
s609319065
1,103
779
114,072
106,512
Accepted
Accepted
29.37
import collections from collections import OrderedDict num = [int(x) for x in input().split()] val = input().split() count_dict = collections.Counter(val) cant = 0 if len(count_dict) <= num[1]: print((0)) else: sort_dict = OrderedDict(sorted(list(count_dict.items()), key=lambda x:x[1], reverse= True)) value_dict = list(sort_dict.values()) print((sum(list(value_dict)[num[1]:])))
import collections n, k = list(map(int, input().split())) array = [int(x) for x in input().split()] _dict = collections.Counter(array) res = 0 tmp = len(list(_dict.values())) if len(list(_dict.values())) < k: print((0)) else: sort_dict = collections.OrderedDict(sorted(list(_dict.items()), key=lambda x: x[1], reverse=True)) value_dict = list(sort_dict.values()) print((sum(list(value_dict)[k:])))
16
14
400
394
import collections from collections import OrderedDict num = [int(x) for x in input().split()] val = input().split() count_dict = collections.Counter(val) cant = 0 if len(count_dict) <= num[1]: print((0)) else: sort_dict = OrderedDict( sorted(list(count_dict.items()), key=lambda x: x[1], reverse=True) ) value_dict = list(sort_dict.values()) print((sum(list(value_dict)[num[1] :])))
import collections n, k = list(map(int, input().split())) array = [int(x) for x in input().split()] _dict = collections.Counter(array) res = 0 tmp = len(list(_dict.values())) if len(list(_dict.values())) < k: print((0)) else: sort_dict = collections.OrderedDict( sorted(list(_dict.items()), key=lambda x: x[1], reverse=True) ) value_dict = list(sort_dict.values()) print((sum(list(value_dict)[k:])))
false
12.5
[ "-from collections import OrderedDict", "-num = [int(x) for x in input().split()]", "-val = input().split()", "-count_dict = collections.Counter(val)", "-cant = 0", "-if len(count_dict) <= num[1]:", "+n, k = list(map(int, input().split()))", "+array = [int(x) for x in input().split()]", "+_dict = collections.Counter(array)", "+res = 0", "+tmp = len(list(_dict.values()))", "+if len(list(_dict.values())) < k:", "- sort_dict = OrderedDict(", "- sorted(list(count_dict.items()), key=lambda x: x[1], reverse=True)", "+ sort_dict = collections.OrderedDict(", "+ sorted(list(_dict.items()), key=lambda x: x[1], reverse=True)", "- print((sum(list(value_dict)[num[1] :])))", "+ print((sum(list(value_dict)[k:])))" ]
false
0.076717
0.181438
0.422829
[ "s263553911", "s609319065" ]
u968166680
p02610
python
s294597188
s373982595
624
381
94,092
100,996
Accepted
Accepted
38.94
import sys from heapq import heappush, heappop readline = sys.stdin.readline def solve(): N = int(readline()) left = [] right = [] ans = 0 for _ in range(N): K, L, R = list(map(int, readline().split())) if L > R: ans += R left.append((K - 1, R - L)) else: ans += L right.append((N - K - 1, L - R)) for vec in (left, right): vec.sort() hq = [] for idx in range(len(vec) - 1, -1, -1): while vec and idx <= vec[-1][0]: heappush(hq, vec.pop()[1]) if hq: ans -= heappop(hq) return ans def main(): T = int(readline()) ans = [0] * T for i in range(T): ans[i] = solve() print(('\n'.join(map(str, ans)))) return if __name__ == '__main__': main()
import sys from heapq import heappush, heappop readline = sys.stdin.readline def solve(): N = int(readline()) left = [[] for _ in range(N)] right = [[] for _ in range(N)] ans = 0 for _ in range(N): K, L, R = list(map(int, readline().split())) if L > R: ans += R left[K - 1].append(R - L) else: ans += L if 0 <= N - K - 1: right[N - K - 1].append(L - R) for vec in (left, right): hq = [] n = len(vec) for idx in range(N - 1, -1, -1): for p in vec[idx]: heappush(hq, p) if idx < n and hq: ans -= heappop(hq) return ans def main(): T = int(readline()) ans = [0] * T for i in range(T): ans[i] = solve() print(('\n'.join(map(str, ans)))) return if __name__ == '__main__': main()
46
47
898
952
import sys from heapq import heappush, heappop readline = sys.stdin.readline def solve(): N = int(readline()) left = [] right = [] ans = 0 for _ in range(N): K, L, R = list(map(int, readline().split())) if L > R: ans += R left.append((K - 1, R - L)) else: ans += L right.append((N - K - 1, L - R)) for vec in (left, right): vec.sort() hq = [] for idx in range(len(vec) - 1, -1, -1): while vec and idx <= vec[-1][0]: heappush(hq, vec.pop()[1]) if hq: ans -= heappop(hq) return ans def main(): T = int(readline()) ans = [0] * T for i in range(T): ans[i] = solve() print(("\n".join(map(str, ans)))) return if __name__ == "__main__": main()
import sys from heapq import heappush, heappop readline = sys.stdin.readline def solve(): N = int(readline()) left = [[] for _ in range(N)] right = [[] for _ in range(N)] ans = 0 for _ in range(N): K, L, R = list(map(int, readline().split())) if L > R: ans += R left[K - 1].append(R - L) else: ans += L if 0 <= N - K - 1: right[N - K - 1].append(L - R) for vec in (left, right): hq = [] n = len(vec) for idx in range(N - 1, -1, -1): for p in vec[idx]: heappush(hq, p) if idx < n and hq: ans -= heappop(hq) return ans def main(): T = int(readline()) ans = [0] * T for i in range(T): ans[i] = solve() print(("\n".join(map(str, ans)))) return if __name__ == "__main__": main()
false
2.12766
[ "- left = []", "- right = []", "+ left = [[] for _ in range(N)]", "+ right = [[] for _ in range(N)]", "- left.append((K - 1, R - L))", "+ left[K - 1].append(R - L)", "- right.append((N - K - 1, L - R))", "+ if 0 <= N - K - 1:", "+ right[N - K - 1].append(L - R)", "- vec.sort()", "- for idx in range(len(vec) - 1, -1, -1):", "- while vec and idx <= vec[-1][0]:", "- heappush(hq, vec.pop()[1])", "- if hq:", "+ n = len(vec)", "+ for idx in range(N - 1, -1, -1):", "+ for p in vec[idx]:", "+ heappush(hq, p)", "+ if idx < n and hq:" ]
false
0.031112
0.034517
0.901346
[ "s294597188", "s373982595" ]
u395620499
p02972
python
s975228263
s780620035
553
326
7,276
8,380
Accepted
Accepted
41.05
n = int(eval(input())) a = [int(x) for x in input().split()] ans = [0]*n for i in range(n-1, -1, -1): now = 0 for j in range(i+i+1, n, i+1): now += ans[j] if now % 2 != a[i]: ans[i] = 1 print((sum(ans))) for i in range(n): if ans[i] == 1: print((i+1))
n = int(eval(input())) a = [int(x) for x in input().split()] ans = [0]*n for i in range(n-1, -1, -1): ans[i] = sum(ans[i+i+1:n:i+1]) % 2 != a[i] print((sum(ans))) for i in range(n): if ans[i] == 1: print((i+1))
15
11
277
220
n = int(eval(input())) a = [int(x) for x in input().split()] ans = [0] * n for i in range(n - 1, -1, -1): now = 0 for j in range(i + i + 1, n, i + 1): now += ans[j] if now % 2 != a[i]: ans[i] = 1 print((sum(ans))) for i in range(n): if ans[i] == 1: print((i + 1))
n = int(eval(input())) a = [int(x) for x in input().split()] ans = [0] * n for i in range(n - 1, -1, -1): ans[i] = sum(ans[i + i + 1 : n : i + 1]) % 2 != a[i] print((sum(ans))) for i in range(n): if ans[i] == 1: print((i + 1))
false
26.666667
[ "- now = 0", "- for j in range(i + i + 1, n, i + 1):", "- now += ans[j]", "- if now % 2 != a[i]:", "- ans[i] = 1", "+ ans[i] = sum(ans[i + i + 1 : n : i + 1]) % 2 != a[i]" ]
false
0.107449
0.042569
2.52415
[ "s975228263", "s780620035" ]
u497952650
p03106
python
s915257612
s903275135
26
17
2,940
2,940
Accepted
Accepted
34.62
A,B,K = list(map(int,input().split())) a = [] for i in range(1,100000): if A%i == 0 and B%i == 0: a.append(i) print((a[-K]))
A,B,K = list(map(int,input().split())) a = [] for i in range(1,101): if A%i == 0 and B%i == 0: a.append(i) print((a[-K]))
10
10
149
146
A, B, K = list(map(int, input().split())) a = [] for i in range(1, 100000): if A % i == 0 and B % i == 0: a.append(i) print((a[-K]))
A, B, K = list(map(int, input().split())) a = [] for i in range(1, 101): if A % i == 0 and B % i == 0: a.append(i) print((a[-K]))
false
0
[ "-for i in range(1, 100000):", "+for i in range(1, 101):" ]
false
0.120961
0.136798
0.884237
[ "s915257612", "s903275135" ]
u131984977
p02408
python
s246323084
s226708908
30
20
6,720
7,668
Accepted
Accepted
33.33
cards = { 'S': [0 for _ in range(13)], 'H': [0 for _ in range(13)], 'C': [0 for _ in range(13)], 'D': [0 for _ in range(13)], } n = int(eval(input())) for _ in range(n): (s, r) = input().split() cards[s][int(r) - 1] = 1 for s in ('S', 'H', 'C', 'D'): for r in range(13): if cards[s][r] == 0: print((s, r + 1))
data = [ "{0} {1}".format(s, r) for s in ('S', 'H', 'C', 'D') for r in range(1, 13 + 1) ] count = int(eval(input())) for c in range(count): card = eval(input()) data.remove(card) for c in data: print(c)
15
13
380
232
cards = { "S": [0 for _ in range(13)], "H": [0 for _ in range(13)], "C": [0 for _ in range(13)], "D": [0 for _ in range(13)], } n = int(eval(input())) for _ in range(n): (s, r) = input().split() cards[s][int(r) - 1] = 1 for s in ("S", "H", "C", "D"): for r in range(13): if cards[s][r] == 0: print((s, r + 1))
data = ["{0} {1}".format(s, r) for s in ("S", "H", "C", "D") for r in range(1, 13 + 1)] count = int(eval(input())) for c in range(count): card = eval(input()) data.remove(card) for c in data: print(c)
false
13.333333
[ "-cards = {", "- \"S\": [0 for _ in range(13)],", "- \"H\": [0 for _ in range(13)],", "- \"C\": [0 for _ in range(13)],", "- \"D\": [0 for _ in range(13)],", "-}", "-n = int(eval(input()))", "-for _ in range(n):", "- (s, r) = input().split()", "- cards[s][int(r) - 1] = 1", "-for s in (\"S\", \"H\", \"C\", \"D\"):", "- for r in range(13):", "- if cards[s][r] == 0:", "- print((s, r + 1))", "+data = [\"{0} {1}\".format(s, r) for s in (\"S\", \"H\", \"C\", \"D\") for r in range(1, 13 + 1)]", "+count = int(eval(input()))", "+for c in range(count):", "+ card = eval(input())", "+ data.remove(card)", "+for c in data:", "+ print(c)" ]
false
0.040181
0.045993
0.873644
[ "s246323084", "s226708908" ]
u223133214
p03627
python
s817276829
s698542682
160
125
79,928
101,228
Accepted
Accepted
21.88
import sys sys.setrecursionlimit(10**9) N = int(eval(input())) A = list(map(int, input().split())) A = sorted(A, reverse=True) def chouhoukei(count, ans, num): if count == 4: return ans else: if num >= N - 1: return 0 if A[num] == A[num + 1]: return chouhoukei(count + 2, ans * A[num], num + 2) else: return chouhoukei(count, ans, num + 1) print((chouhoukei(0, 1, 0)))
from collections import Counter n = int(eval(input())) A = list(map(int, input().split())) cnt_A = Counter(A) # print(cnt_A) kouho = [] ans = 0 for key in cnt_A: if cnt_A[key] >= 2: kouho.append(key) if cnt_A[key] >= 4: ans = max(ans, key ** 2) if len(kouho) < 2: print(ans) exit() kouho.sort() ans = max(ans, kouho[-1] * kouho[-2]) print(ans)
20
24
460
399
import sys sys.setrecursionlimit(10**9) N = int(eval(input())) A = list(map(int, input().split())) A = sorted(A, reverse=True) def chouhoukei(count, ans, num): if count == 4: return ans else: if num >= N - 1: return 0 if A[num] == A[num + 1]: return chouhoukei(count + 2, ans * A[num], num + 2) else: return chouhoukei(count, ans, num + 1) print((chouhoukei(0, 1, 0)))
from collections import Counter n = int(eval(input())) A = list(map(int, input().split())) cnt_A = Counter(A) # print(cnt_A) kouho = [] ans = 0 for key in cnt_A: if cnt_A[key] >= 2: kouho.append(key) if cnt_A[key] >= 4: ans = max(ans, key**2) if len(kouho) < 2: print(ans) exit() kouho.sort() ans = max(ans, kouho[-1] * kouho[-2]) print(ans)
false
16.666667
[ "-import sys", "+from collections import Counter", "-sys.setrecursionlimit(10**9)", "-N = int(eval(input()))", "+n = int(eval(input()))", "-A = sorted(A, reverse=True)", "-", "-", "-def chouhoukei(count, ans, num):", "- if count == 4:", "- return ans", "- else:", "- if num >= N - 1:", "- return 0", "- if A[num] == A[num + 1]:", "- return chouhoukei(count + 2, ans * A[num], num + 2)", "- else:", "- return chouhoukei(count, ans, num + 1)", "-", "-", "-print((chouhoukei(0, 1, 0)))", "+cnt_A = Counter(A)", "+# print(cnt_A)", "+kouho = []", "+ans = 0", "+for key in cnt_A:", "+ if cnt_A[key] >= 2:", "+ kouho.append(key)", "+ if cnt_A[key] >= 4:", "+ ans = max(ans, key**2)", "+if len(kouho) < 2:", "+ print(ans)", "+ exit()", "+kouho.sort()", "+ans = max(ans, kouho[-1] * kouho[-2])", "+print(ans)" ]
false
0.04044
0.034582
1.1694
[ "s817276829", "s698542682" ]
u197956883
p02678
python
s955070245
s035404263
508
460
126,424
126,164
Accepted
Accepted
9.45
import sys, re from math import ceil, floor, sqrt, pi, factorial#, gcd from copy import deepcopy from collections import Counter, deque from heapq import heapify, heappop, heappush from itertools import accumulate, product, combinations, combinations_with_replacement from bisect import bisect, bisect_left from functools import reduce # input = sys.stdin.readline def i_input(): return int(eval(input())) def i_map(): return list(map(int, input().split())) def i_list(): return list(i_map()) def i_row(N): return [i_input() for _ in range(N)] def i_row_list(N): return [i_list() for _ in range(N)] def s_input(): return eval(input()) def s_map(): return input().split() def s_list(): return list(s_map()) def s_row(N): return [s_input for _ in range(N)] def s_row_list(N): return [s_list() for _ in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') def lcm(a, b): return a * b // gcd(a, b) sys.setrecursionlimit(10 ** 6) INF = float('inf') MOD = 10 ** 9 + 7 # def bfs(si, sj, str_list, dist, h, w): # q = deque([[si, sj]]) # dist[si][sj] = 0 # max_tmp = 0 # while len(q) != 0: # i, j = q.popleft() # for dx, dy in ([1, 0], [-1, 0], [0, 1], [0, -1]): # ni = i + dx # nj = j + dy # if ni < 0 or ni >= h or nj < 0 or nj >= w: # continue # if str_list[ni][0][nj] != '.': # continue # if dist[ni][nj] != inf: # continue # dist[ni][nj] = dist[i][j] + 1 # q.append([ni, nj]) # max_tmp = max(max_tmp, dist[ni][nj]) # return max_tmp def create_graph(n: int, l: list) -> list: graph = [[] for _ in range(n)] for a, b in l: graph[a-1].append(b-1) graph[b-1].append(a-1) return graph def main(): n, m = i_map() num_list = i_row_list(m) graph = create_graph(n, num_list) q = deque([0]) visited = [INF] * n visited[0] = 1 ans = [0] * n while len(q) != 0: node = q.popleft() for leaf in graph[node]: if visited[leaf] != INF: continue ans[leaf] = node + 1 visited[leaf] = 1 q.append(leaf) Yes() for a in ans[1:]: print(a) if __name__ == '__main__': main()
import sys, re from math import ceil, floor, sqrt, pi, factorial#, gcd from copy import deepcopy from collections import Counter, deque from heapq import heapify, heappop, heappush from itertools import accumulate, product, combinations, combinations_with_replacement from bisect import bisect, bisect_left from functools import reduce # input = sys.stdin.readline def i_input(): return int(eval(input())) def i_map(): return list(map(int, input().split())) def i_list(): return list(i_map()) def i_row(N): return [i_input() for _ in range(N)] def i_row_list(N): return [i_list() for _ in range(N)] def s_input(): return eval(input()) def s_map(): return input().split() def s_list(): return list(s_map()) def s_row(N): return [s_input for _ in range(N)] def s_row_list(N): return [s_list() for _ in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') def lcm(a, b): return a * b // gcd(a, b) sys.setrecursionlimit(10 ** 6) INF = float('inf') MOD = 10 ** 9 + 7 def bfs(graph: list, n: int, start: int, ans: list): q = deque([start]) visited = [INF] * n visited[0] = 1 while len(q) != 0: node = q.popleft() for leaf in graph[node]: if visited[leaf] != INF: continue ans[leaf] = node + 1 visited[leaf] = 1 q.append(leaf) def create_graph(n: int, l: list) -> list: graph = [[] for _ in range(n)] for a, b in l: graph[a-1].append(b-1) graph[b-1].append(a-1) return graph def main(): n, m = i_map() num_list = i_row_list(m) graph = create_graph(n, num_list) ans = [0] * n bfs(graph, n, 0, ans) Yes() for a in ans[1:]: print(a) if __name__ == '__main__': main()
83
64
2,408
1,824
import sys, re from math import ceil, floor, sqrt, pi, factorial # , gcd from copy import deepcopy from collections import Counter, deque from heapq import heapify, heappop, heappush from itertools import accumulate, product, combinations, combinations_with_replacement from bisect import bisect, bisect_left from functools import reduce # input = sys.stdin.readline def i_input(): return int(eval(input())) def i_map(): return list(map(int, input().split())) def i_list(): return list(i_map()) def i_row(N): return [i_input() for _ in range(N)] def i_row_list(N): return [i_list() for _ in range(N)] def s_input(): return eval(input()) def s_map(): return input().split() def s_list(): return list(s_map()) def s_row(N): return [s_input for _ in range(N)] def s_row_list(N): return [s_list() for _ in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") def lcm(a, b): return a * b // gcd(a, b) sys.setrecursionlimit(10**6) INF = float("inf") MOD = 10**9 + 7 # def bfs(si, sj, str_list, dist, h, w): # q = deque([[si, sj]]) # dist[si][sj] = 0 # max_tmp = 0 # while len(q) != 0: # i, j = q.popleft() # for dx, dy in ([1, 0], [-1, 0], [0, 1], [0, -1]): # ni = i + dx # nj = j + dy # if ni < 0 or ni >= h or nj < 0 or nj >= w: # continue # if str_list[ni][0][nj] != '.': # continue # if dist[ni][nj] != inf: # continue # dist[ni][nj] = dist[i][j] + 1 # q.append([ni, nj]) # max_tmp = max(max_tmp, dist[ni][nj]) # return max_tmp def create_graph(n: int, l: list) -> list: graph = [[] for _ in range(n)] for a, b in l: graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) return graph def main(): n, m = i_map() num_list = i_row_list(m) graph = create_graph(n, num_list) q = deque([0]) visited = [INF] * n visited[0] = 1 ans = [0] * n while len(q) != 0: node = q.popleft() for leaf in graph[node]: if visited[leaf] != INF: continue ans[leaf] = node + 1 visited[leaf] = 1 q.append(leaf) Yes() for a in ans[1:]: print(a) if __name__ == "__main__": main()
import sys, re from math import ceil, floor, sqrt, pi, factorial # , gcd from copy import deepcopy from collections import Counter, deque from heapq import heapify, heappop, heappush from itertools import accumulate, product, combinations, combinations_with_replacement from bisect import bisect, bisect_left from functools import reduce # input = sys.stdin.readline def i_input(): return int(eval(input())) def i_map(): return list(map(int, input().split())) def i_list(): return list(i_map()) def i_row(N): return [i_input() for _ in range(N)] def i_row_list(N): return [i_list() for _ in range(N)] def s_input(): return eval(input()) def s_map(): return input().split() def s_list(): return list(s_map()) def s_row(N): return [s_input for _ in range(N)] def s_row_list(N): return [s_list() for _ in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") def lcm(a, b): return a * b // gcd(a, b) sys.setrecursionlimit(10**6) INF = float("inf") MOD = 10**9 + 7 def bfs(graph: list, n: int, start: int, ans: list): q = deque([start]) visited = [INF] * n visited[0] = 1 while len(q) != 0: node = q.popleft() for leaf in graph[node]: if visited[leaf] != INF: continue ans[leaf] = node + 1 visited[leaf] = 1 q.append(leaf) def create_graph(n: int, l: list) -> list: graph = [[] for _ in range(n)] for a, b in l: graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) return graph def main(): n, m = i_map() num_list = i_row_list(m) graph = create_graph(n, num_list) ans = [0] * n bfs(graph, n, 0, ans) Yes() for a in ans[1:]: print(a) if __name__ == "__main__": main()
false
22.891566
[ "-# def bfs(si, sj, str_list, dist, h, w):", "-# q = deque([[si, sj]])", "-# dist[si][sj] = 0", "-# max_tmp = 0", "-# while len(q) != 0:", "-# i, j = q.popleft()", "-# for dx, dy in ([1, 0], [-1, 0], [0, 1], [0, -1]):", "-# ni = i + dx", "-# nj = j + dy", "-# if ni < 0 or ni >= h or nj < 0 or nj >= w:", "-# continue", "-# if str_list[ni][0][nj] != '.':", "-# continue", "-# if dist[ni][nj] != inf:", "-# continue", "-# dist[ni][nj] = dist[i][j] + 1", "-# q.append([ni, nj])", "-# max_tmp = max(max_tmp, dist[ni][nj])", "-# return max_tmp", "+", "+", "+def bfs(graph: list, n: int, start: int, ans: list):", "+ q = deque([start])", "+ visited = [INF] * n", "+ visited[0] = 1", "+ while len(q) != 0:", "+ node = q.popleft()", "+ for leaf in graph[node]:", "+ if visited[leaf] != INF:", "+ continue", "+ ans[leaf] = node + 1", "+ visited[leaf] = 1", "+ q.append(leaf)", "+", "+", "- q = deque([0])", "- visited = [INF] * n", "- visited[0] = 1", "- while len(q) != 0:", "- node = q.popleft()", "- for leaf in graph[node]:", "- if visited[leaf] != INF:", "- continue", "- ans[leaf] = node + 1", "- visited[leaf] = 1", "- q.append(leaf)", "+ bfs(graph, n, 0, ans)" ]
false
0.043221
0.041658
1.037519
[ "s955070245", "s035404263" ]
u417365712
p02775
python
s215115699
s525850527
1,288
854
98,684
20,336
Accepted
Accepted
33.7
n = list(reversed(list(map(int, eval(input()))))) k = len(n) dp1, dp2 = [0] * k, [0] * k dp1[0], dp2[0] = n[0], 11-n[0] for i, x in enumerate(n[1:], 1): dp1[i] = min(x+dp1[i-1], x+dp2[i-1]) dp2[i] = min(11-x+dp1[i-1], 9-x+dp2[i-1]) print((min(dp1[-1], dp2[-1])))
N = list(map(int, eval(input())))[::-1] a, b = N[0], 11-N[0] for n in N[1:]: a, b = min(n+a, n+b), min(11-n+a, 9-n+b) print((min(a, b)))
8
5
269
136
n = list(reversed(list(map(int, eval(input()))))) k = len(n) dp1, dp2 = [0] * k, [0] * k dp1[0], dp2[0] = n[0], 11 - n[0] for i, x in enumerate(n[1:], 1): dp1[i] = min(x + dp1[i - 1], x + dp2[i - 1]) dp2[i] = min(11 - x + dp1[i - 1], 9 - x + dp2[i - 1]) print((min(dp1[-1], dp2[-1])))
N = list(map(int, eval(input())))[::-1] a, b = N[0], 11 - N[0] for n in N[1:]: a, b = min(n + a, n + b), min(11 - n + a, 9 - n + b) print((min(a, b)))
false
37.5
[ "-n = list(reversed(list(map(int, eval(input())))))", "-k = len(n)", "-dp1, dp2 = [0] * k, [0] * k", "-dp1[0], dp2[0] = n[0], 11 - n[0]", "-for i, x in enumerate(n[1:], 1):", "- dp1[i] = min(x + dp1[i - 1], x + dp2[i - 1])", "- dp2[i] = min(11 - x + dp1[i - 1], 9 - x + dp2[i - 1])", "-print((min(dp1[-1], dp2[-1])))", "+N = list(map(int, eval(input())))[::-1]", "+a, b = N[0], 11 - N[0]", "+for n in N[1:]:", "+ a, b = min(n + a, n + b), min(11 - n + a, 9 - n + b)", "+print((min(a, b)))" ]
false
0.037496
0.036742
1.020528
[ "s215115699", "s525850527" ]
u408071652
p02580
python
s332616542
s208407199
319
253
145,748
104,492
Accepted
Accepted
20.69
import sys from collections import deque def input(): return sys.stdin.readline().rstrip() def main(): H, W, M = list(map(int, input().split())) lh = [0] * H lw = [0] * W s = set() for _ in range(M): h, w = list(map(int, input().split())) lh[h - 1] += 1 lw[w - 1] += 1 s.add((h-1, w-1)) maxh = max(lh) maxw = max(lw) wlist=[] for j in range(W): if maxw==lw[j]: wlist.append(j) for i in range(H): if lh[i] !=maxh: continue for j in wlist: if (i,j) not in s: print((maxh+maxw)) exit() print((maxh+maxw-1)) if __name__ == "__main__": main()
import sys from collections import deque def input(): return sys.stdin.readline().rstrip() def main(): H, W, M = list(map(int, input().split())) lh = [0] * H lw = [0] * W ll = [] for _ in range(M): h, w = list(map(int, input().split())) lh[h - 1] += 1 lw[w - 1] += 1 ll.append((h - 1, w - 1)) maxh = max(lh) maxw = max(lw) wlist = [] # for i in range(H): # if lh[i] != maxh: # continue # for j in wlist: # if (i, j) not in s: # print(maxh + maxw) # exit() count = lh.count(maxh) * lw.count(maxw) for h, w in ll: if lh[h] == maxh and lw[w] == maxw: count -= 1 if count: print((maxh + maxw)) else: print((maxh + maxw - 1)) if __name__ == "__main__": main()
42
44
751
892
import sys from collections import deque def input(): return sys.stdin.readline().rstrip() def main(): H, W, M = list(map(int, input().split())) lh = [0] * H lw = [0] * W s = set() for _ in range(M): h, w = list(map(int, input().split())) lh[h - 1] += 1 lw[w - 1] += 1 s.add((h - 1, w - 1)) maxh = max(lh) maxw = max(lw) wlist = [] for j in range(W): if maxw == lw[j]: wlist.append(j) for i in range(H): if lh[i] != maxh: continue for j in wlist: if (i, j) not in s: print((maxh + maxw)) exit() print((maxh + maxw - 1)) if __name__ == "__main__": main()
import sys from collections import deque def input(): return sys.stdin.readline().rstrip() def main(): H, W, M = list(map(int, input().split())) lh = [0] * H lw = [0] * W ll = [] for _ in range(M): h, w = list(map(int, input().split())) lh[h - 1] += 1 lw[w - 1] += 1 ll.append((h - 1, w - 1)) maxh = max(lh) maxw = max(lw) wlist = [] # for i in range(H): # if lh[i] != maxh: # continue # for j in wlist: # if (i, j) not in s: # print(maxh + maxw) # exit() count = lh.count(maxh) * lw.count(maxw) for h, w in ll: if lh[h] == maxh and lw[w] == maxw: count -= 1 if count: print((maxh + maxw)) else: print((maxh + maxw - 1)) if __name__ == "__main__": main()
false
4.545455
[ "- s = set()", "+ ll = []", "- s.add((h - 1, w - 1))", "+ ll.append((h - 1, w - 1))", "- for j in range(W):", "- if maxw == lw[j]:", "- wlist.append(j)", "- for i in range(H):", "- if lh[i] != maxh:", "- continue", "- for j in wlist:", "- if (i, j) not in s:", "- print((maxh + maxw))", "- exit()", "- print((maxh + maxw - 1))", "+ # for i in range(H):", "+ # if lh[i] != maxh:", "+ # continue", "+ # for j in wlist:", "+ # if (i, j) not in s:", "+ # print(maxh + maxw)", "+ # exit()", "+ count = lh.count(maxh) * lw.count(maxw)", "+ for h, w in ll:", "+ if lh[h] == maxh and lw[w] == maxw:", "+ count -= 1", "+ if count:", "+ print((maxh + maxw))", "+ else:", "+ print((maxh + maxw - 1))" ]
false
0.042589
0.045742
0.931081
[ "s332616542", "s208407199" ]
u063596417
p03435
python
s440103208
s294280961
69
62
61,896
61,828
Accepted
Accepted
10.14
c=[list(map(int,input().split())) for i in range(3)] x=c[0][2]-c[0][1] y=c[0][1]-c[0][0] for i in range(1,3): if c[i][1]-c[i][0]!=y: print("No") break if c[i][2]-c[i][1]!=x: print("No") break else: print("Yes")
c = [list(map(int, input().split())) for i in range(3)] x = c[0][2] - c[0][1] y = c[0][1] - c[0][0] ans = 'Yes' for i in range(1, 3): if c[i][2] - c[i][1] != x or c[i][1] - c[i][0] != y: ans = "No" break print(ans)
12
10
265
235
c = [list(map(int, input().split())) for i in range(3)] x = c[0][2] - c[0][1] y = c[0][1] - c[0][0] for i in range(1, 3): if c[i][1] - c[i][0] != y: print("No") break if c[i][2] - c[i][1] != x: print("No") break else: print("Yes")
c = [list(map(int, input().split())) for i in range(3)] x = c[0][2] - c[0][1] y = c[0][1] - c[0][0] ans = "Yes" for i in range(1, 3): if c[i][2] - c[i][1] != x or c[i][1] - c[i][0] != y: ans = "No" break print(ans)
false
16.666667
[ "+ans = \"Yes\"", "- if c[i][1] - c[i][0] != y:", "- print(\"No\")", "+ if c[i][2] - c[i][1] != x or c[i][1] - c[i][0] != y:", "+ ans = \"No\"", "- if c[i][2] - c[i][1] != x:", "- print(\"No\")", "- break", "-else:", "- print(\"Yes\")", "+print(ans)" ]
false
0.036797
0.077148
0.476964
[ "s440103208", "s294280961" ]
u332385682
p03805
python
s138823673
s153977246
29
26
3,188
3,192
Accepted
Accepted
10.34
import sys from itertools import permutations def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None def do_dp(N, Adj): univ = 2**N - 1 dp = [[0]*N for i in range(univ + 1)] dp[1][0] = 1 for S in range(2, univ + 1): for v in range(N): S2 = S & (univ ^ (1 << v)) for u in range(N): if ((1 << u) & S2) and Adj[u][v]: dp[S][v] += dp[S2][u] # debug(dp, locals()) ans = sum(dp[univ][u] for u in range(1, N)) return ans def solve(): N, M = map(int, input().split()) Adj = [[0]*N for i in range(N)] for i in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 Adj[a][b] = 1 Adj[b][a] = 1 ans = do_dp(N, Adj) print(ans) if __name__ == '__main__': solve()
import sys def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr) return None def do_dp(N, Adj): univ = 2**(N-1) - 1 dp = [[0]*(N-1) for i in range(univ + 1)] for u in range(N - 1): if Adj[0][u+1]: dp[1<<u][u] = 1 for S in range(univ + 1): for v in range(N - 1): S2 = S & (univ ^ (1 << v)) for u in range(N): if ((1 << u) & S2) and Adj[u+1][v+1]: dp[S][v] += dp[S2][u] # debug(dp, locals()) ans = sum(dp[univ][u] for u in range(N - 1)) return ans def solve(): N, M = map(int, input().split()) Adj = [[0]*N for i in range(N)] for i in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 Adj[a][b] = 1 Adj[b][a] = 1 ans = do_dp(N, Adj) print(ans) if __name__ == '__main__': solve()
43
45
981
1,025
import sys from itertools import permutations def debug(x, table): for name, val in table.items(): if x is val: print("DEBUG:{} -> {}".format(name, val), file=sys.stderr) return None def do_dp(N, Adj): univ = 2**N - 1 dp = [[0] * N for i in range(univ + 1)] dp[1][0] = 1 for S in range(2, univ + 1): for v in range(N): S2 = S & (univ ^ (1 << v)) for u in range(N): if ((1 << u) & S2) and Adj[u][v]: dp[S][v] += dp[S2][u] # debug(dp, locals()) ans = sum(dp[univ][u] for u in range(1, N)) return ans def solve(): N, M = map(int, input().split()) Adj = [[0] * N for i in range(N)] for i in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 Adj[a][b] = 1 Adj[b][a] = 1 ans = do_dp(N, Adj) print(ans) if __name__ == "__main__": solve()
import sys def debug(x, table): for name, val in table.items(): if x is val: print("DEBUG:{} -> {}".format(name, val), file=sys.stderr) return None def do_dp(N, Adj): univ = 2 ** (N - 1) - 1 dp = [[0] * (N - 1) for i in range(univ + 1)] for u in range(N - 1): if Adj[0][u + 1]: dp[1 << u][u] = 1 for S in range(univ + 1): for v in range(N - 1): S2 = S & (univ ^ (1 << v)) for u in range(N): if ((1 << u) & S2) and Adj[u + 1][v + 1]: dp[S][v] += dp[S2][u] # debug(dp, locals()) ans = sum(dp[univ][u] for u in range(N - 1)) return ans def solve(): N, M = map(int, input().split()) Adj = [[0] * N for i in range(N)] for i in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 Adj[a][b] = 1 Adj[b][a] = 1 ans = do_dp(N, Adj) print(ans) if __name__ == "__main__": solve()
false
4.444444
[ "-from itertools import permutations", "- univ = 2**N - 1", "- dp = [[0] * N for i in range(univ + 1)]", "- dp[1][0] = 1", "- for S in range(2, univ + 1):", "- for v in range(N):", "+ univ = 2 ** (N - 1) - 1", "+ dp = [[0] * (N - 1) for i in range(univ + 1)]", "+ for u in range(N - 1):", "+ if Adj[0][u + 1]:", "+ dp[1 << u][u] = 1", "+ for S in range(univ + 1):", "+ for v in range(N - 1):", "- if ((1 << u) & S2) and Adj[u][v]:", "+ if ((1 << u) & S2) and Adj[u + 1][v + 1]:", "- ans = sum(dp[univ][u] for u in range(1, N))", "+ ans = sum(dp[univ][u] for u in range(N - 1))" ]
false
0.04319
0.105329
0.410052
[ "s138823673", "s153977246" ]
u906428167
p02803
python
s609714335
s449861524
671
305
59,356
46,316
Accepted
Accepted
54.55
from heapq import heappop,heappush h,w = list(map(int, input().split())) s = [[x for x in eval(input())] for _ in range(h)] delta = [(-1,0),(1,0),(0,1),(0,-1)] edges = [[-1 for _ in range(h*w)] for __ in range(h*w)] for i in range(h): for j in range(w): if s[i][j] == '.': for x in delta: to_i = i+x[0] to_j = j+x[1] if 0 <= to_i < h and 0 <= to_j < w: if s[to_i][to_j] == '.': edges[i*w+j][to_i*w+to_j] = 1 edges[to_i*w+to_j][i*w+j] = 1 n = h*w def dijkstra(s,n,edges): #edges[i][j] : the cost of i→j #import 'heap' d = [10**13] * n d[s] = 0 q = [(0,s)] while q: dist_u, u = heappop(q) if d[u] < dist_u: continue for v, c in enumerate(edges[u]): if c >= 0: if d[v] > dist_u + c: d[v] = dist_u + c heappush(q, (d[v], v)) return d ans = 0 for i in range(h): for j in range(w): d = dijkstra(i*w+j,n,edges) for l in d: if l < 10**6: ans = max(ans,l) print(ans)
from collections import deque def solve(S, s): if S[s[0]][s[1]] != ".": return -1 queue = deque([s]) visited = [[-1 for _ in range(W)] for _ in range(H)] visited[s[0]][s[1]] = 0 while queue: y, x = queue.popleft() for j, k in ([1,0], [-1,0], [0,1], [0,-1]): new_y, new_x = y+j, x+k if new_x in range(W) and new_y in range(H) and S[new_y][new_x] == "." and visited[new_y][new_x] == -1: visited[new_y][new_x] = visited[y][x] + 1 queue.append([new_y, new_x]) # for v in visited: # print(v) return max(list(map(max,visited))) H, W = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] ans = -1 for i in range(H): for l in range(W): ans = max(ans, solve(S, [i, l])) print(ans)
49
28
1,223
829
from heapq import heappop, heappush h, w = list(map(int, input().split())) s = [[x for x in eval(input())] for _ in range(h)] delta = [(-1, 0), (1, 0), (0, 1), (0, -1)] edges = [[-1 for _ in range(h * w)] for __ in range(h * w)] for i in range(h): for j in range(w): if s[i][j] == ".": for x in delta: to_i = i + x[0] to_j = j + x[1] if 0 <= to_i < h and 0 <= to_j < w: if s[to_i][to_j] == ".": edges[i * w + j][to_i * w + to_j] = 1 edges[to_i * w + to_j][i * w + j] = 1 n = h * w def dijkstra(s, n, edges): # edges[i][j] : the cost of i→j # import 'heap' d = [10**13] * n d[s] = 0 q = [(0, s)] while q: dist_u, u = heappop(q) if d[u] < dist_u: continue for v, c in enumerate(edges[u]): if c >= 0: if d[v] > dist_u + c: d[v] = dist_u + c heappush(q, (d[v], v)) return d ans = 0 for i in range(h): for j in range(w): d = dijkstra(i * w + j, n, edges) for l in d: if l < 10**6: ans = max(ans, l) print(ans)
from collections import deque def solve(S, s): if S[s[0]][s[1]] != ".": return -1 queue = deque([s]) visited = [[-1 for _ in range(W)] for _ in range(H)] visited[s[0]][s[1]] = 0 while queue: y, x = queue.popleft() for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]): new_y, new_x = y + j, x + k if ( new_x in range(W) and new_y in range(H) and S[new_y][new_x] == "." and visited[new_y][new_x] == -1 ): visited[new_y][new_x] = visited[y][x] + 1 queue.append([new_y, new_x]) # for v in visited: # print(v) return max(list(map(max, visited))) H, W = list(map(int, input().split())) S = [eval(input()) for _ in range(H)] ans = -1 for i in range(H): for l in range(W): ans = max(ans, solve(S, [i, l])) print(ans)
false
42.857143
[ "-from heapq import heappop, heappush", "-", "-h, w = list(map(int, input().split()))", "-s = [[x for x in eval(input())] for _ in range(h)]", "-delta = [(-1, 0), (1, 0), (0, 1), (0, -1)]", "-edges = [[-1 for _ in range(h * w)] for __ in range(h * w)]", "-for i in range(h):", "- for j in range(w):", "- if s[i][j] == \".\":", "- for x in delta:", "- to_i = i + x[0]", "- to_j = j + x[1]", "- if 0 <= to_i < h and 0 <= to_j < w:", "- if s[to_i][to_j] == \".\":", "- edges[i * w + j][to_i * w + to_j] = 1", "- edges[to_i * w + to_j][i * w + j] = 1", "-n = h * w", "+from collections import deque", "-def dijkstra(s, n, edges):", "- # edges[i][j] : the cost of i→j", "- # import 'heap'", "- d = [10**13] * n", "- d[s] = 0", "- q = [(0, s)]", "- while q:", "- dist_u, u = heappop(q)", "- if d[u] < dist_u:", "- continue", "- for v, c in enumerate(edges[u]):", "- if c >= 0:", "- if d[v] > dist_u + c:", "- d[v] = dist_u + c", "- heappush(q, (d[v], v))", "- return d", "+def solve(S, s):", "+ if S[s[0]][s[1]] != \".\":", "+ return -1", "+ queue = deque([s])", "+ visited = [[-1 for _ in range(W)] for _ in range(H)]", "+ visited[s[0]][s[1]] = 0", "+ while queue:", "+ y, x = queue.popleft()", "+ for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):", "+ new_y, new_x = y + j, x + k", "+ if (", "+ new_x in range(W)", "+ and new_y in range(H)", "+ and S[new_y][new_x] == \".\"", "+ and visited[new_y][new_x] == -1", "+ ):", "+ visited[new_y][new_x] = visited[y][x] + 1", "+ queue.append([new_y, new_x])", "+ # for v in visited:", "+ # print(v)", "+ return max(list(map(max, visited)))", "-ans = 0", "-for i in range(h):", "- for j in range(w):", "- d = dijkstra(i * w + j, n, edges)", "- for l in d:", "- if l < 10**6:", "- ans = max(ans, l)", "+H, W = list(map(int, input().split()))", "+S = [eval(input()) for _ in range(H)]", "+ans = -1", "+for i in range(H):", "+ for l in range(W):", "+ ans = max(ans, solve(S, [i, l]))" ]
false
0.038125
0.040737
0.93588
[ "s609714335", "s449861524" ]
u970308980
p03162
python
s763452441
s777915439
1,014
685
47,328
80,436
Accepted
Accepted
32.45
INF = float('inf') N = int(eval(input())) H = [list(map(int, input().split())) for _ in range(N)] dp = [[0 for _ in range(3)] for _ in range(N+1)] for i in range(N): for j in range(3): for k in range(3): if j == k: continue dp[i+1][k] = max(dp[i+1][k], dp[i][j] + H[i][k]) ans = 0 for i in range(3): ans = max(ans, dp[N][i]) print(ans)
N = int(eval(input())) A = [] B = [] C = [] for i in range(N): a, b, c = list(map(int, input().split())) A.append(a) B.append(b) C.append(c) dp = [[0 for _ in range(3)] for _ in range(N)] dp[0][0] = A[0] dp[0][1] = B[0] dp[0][2] = C[0] for i in range(1, N): dp[i][0] = max(dp[i-1][1] + A[i], dp[i-1][2] + A[i]) dp[i][1] = max(dp[i-1][0] + B[i], dp[i-1][2] + B[i]) dp[i][2] = max(dp[i-1][0] + C[i], dp[i-1][1] + C[i]) print((max(dp[N-1][0], dp[N-1][1], dp[N-1][2])))
17
18
405
496
INF = float("inf") N = int(eval(input())) H = [list(map(int, input().split())) for _ in range(N)] dp = [[0 for _ in range(3)] for _ in range(N + 1)] for i in range(N): for j in range(3): for k in range(3): if j == k: continue dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + H[i][k]) ans = 0 for i in range(3): ans = max(ans, dp[N][i]) print(ans)
N = int(eval(input())) A = [] B = [] C = [] for i in range(N): a, b, c = list(map(int, input().split())) A.append(a) B.append(b) C.append(c) dp = [[0 for _ in range(3)] for _ in range(N)] dp[0][0] = A[0] dp[0][1] = B[0] dp[0][2] = C[0] for i in range(1, N): dp[i][0] = max(dp[i - 1][1] + A[i], dp[i - 1][2] + A[i]) dp[i][1] = max(dp[i - 1][0] + B[i], dp[i - 1][2] + B[i]) dp[i][2] = max(dp[i - 1][0] + C[i], dp[i - 1][1] + C[i]) print((max(dp[N - 1][0], dp[N - 1][1], dp[N - 1][2])))
false
5.555556
[ "-INF = float(\"inf\")", "-H = [list(map(int, input().split())) for _ in range(N)]", "-dp = [[0 for _ in range(3)] for _ in range(N + 1)]", "+A = []", "+B = []", "+C = []", "- for j in range(3):", "- for k in range(3):", "- if j == k:", "- continue", "- dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + H[i][k])", "-ans = 0", "-for i in range(3):", "- ans = max(ans, dp[N][i])", "-print(ans)", "+ a, b, c = list(map(int, input().split()))", "+ A.append(a)", "+ B.append(b)", "+ C.append(c)", "+dp = [[0 for _ in range(3)] for _ in range(N)]", "+dp[0][0] = A[0]", "+dp[0][1] = B[0]", "+dp[0][2] = C[0]", "+for i in range(1, N):", "+ dp[i][0] = max(dp[i - 1][1] + A[i], dp[i - 1][2] + A[i])", "+ dp[i][1] = max(dp[i - 1][0] + B[i], dp[i - 1][2] + B[i])", "+ dp[i][2] = max(dp[i - 1][0] + C[i], dp[i - 1][1] + C[i])", "+print((max(dp[N - 1][0], dp[N - 1][1], dp[N - 1][2])))" ]
false
0.076752
0.070233
1.09281
[ "s763452441", "s777915439" ]
u157020659
p02623
python
s982796324
s854024772
291
241
39,760
40,480
Accepted
Accepted
17.18
n, m, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) cnt = 0 cost = 0 for i, x in enumerate(a): cost += x if cost > k: cnt = i cost -= x break else: for j, y in enumerate(b): cost += y if cost > k: cnt = n + j cost -= y break else: cnt = n + m if cnt <= n: i_max, j = cnt - 1, 0 else: i_max, j = n - 1, cnt - n while j < m and cost + b[j] <= k: cost += b[j] j += 1 cnt += 1 ans = cnt for i in range(i_max, -1, -1): if j == m: break cost -= a[i] cnt -= 1 while j < m and cost + b[j] <= k: cost += b[j] j += 1 cnt += 1 ans = max(cnt, ans) print(ans)
n, m, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) j = m - 1 cost = sum(b) cnt = m ans = 0 for i in range(n + 1): if i != 0: cost += a[i - 1] cnt += 1 while cost > k and j >= 0: cost -= b[j] cnt -= 1 j -= 1 if cost <= k: ans = max(cnt, ans) print(ans)
45
19
816
387
n, m, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) cnt = 0 cost = 0 for i, x in enumerate(a): cost += x if cost > k: cnt = i cost -= x break else: for j, y in enumerate(b): cost += y if cost > k: cnt = n + j cost -= y break else: cnt = n + m if cnt <= n: i_max, j = cnt - 1, 0 else: i_max, j = n - 1, cnt - n while j < m and cost + b[j] <= k: cost += b[j] j += 1 cnt += 1 ans = cnt for i in range(i_max, -1, -1): if j == m: break cost -= a[i] cnt -= 1 while j < m and cost + b[j] <= k: cost += b[j] j += 1 cnt += 1 ans = max(cnt, ans) print(ans)
n, m, k = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) j = m - 1 cost = sum(b) cnt = m ans = 0 for i in range(n + 1): if i != 0: cost += a[i - 1] cnt += 1 while cost > k and j >= 0: cost -= b[j] cnt -= 1 j -= 1 if cost <= k: ans = max(cnt, ans) print(ans)
false
57.777778
[ "-cnt = 0", "-cost = 0", "-for i, x in enumerate(a):", "- cost += x", "- if cost > k:", "- cnt = i", "- cost -= x", "- break", "-else:", "- for j, y in enumerate(b):", "- cost += y", "- if cost > k:", "- cnt = n + j", "- cost -= y", "- break", "- else:", "- cnt = n + m", "-if cnt <= n:", "- i_max, j = cnt - 1, 0", "-else:", "- i_max, j = n - 1, cnt - n", "-while j < m and cost + b[j] <= k:", "- cost += b[j]", "- j += 1", "- cnt += 1", "-ans = cnt", "-for i in range(i_max, -1, -1):", "- if j == m:", "- break", "- cost -= a[i]", "- cnt -= 1", "- while j < m and cost + b[j] <= k:", "- cost += b[j]", "- j += 1", "+j = m - 1", "+cost = sum(b)", "+cnt = m", "+ans = 0", "+for i in range(n + 1):", "+ if i != 0:", "+ cost += a[i - 1]", "- ans = max(cnt, ans)", "+ while cost > k and j >= 0:", "+ cost -= b[j]", "+ cnt -= 1", "+ j -= 1", "+ if cost <= k:", "+ ans = max(cnt, ans)" ]
false
0.094915
0.040606
2.337473
[ "s982796324", "s854024772" ]
u067729694
p02900
python
s252162339
s776057292
337
274
66,664
64,108
Accepted
Accepted
18.69
A, B = list(map(int, input().split())) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) return divisors import math def is_prime(n): if n == 1: return True for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True import fractions x = fractions.gcd(A, B) divisors = make_divisors(x) ans = 0 for d in divisors: if is_prime(d): ans += 1 print(ans)
A, B = list(map(int, input().split())) def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a import fractions x = fractions.gcd(A, B) ans = prime_factorize(x) print((len(set(ans))+1))
31
23
597
419
A, B = list(map(int, input().split())) def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors import math def is_prime(n): if n == 1: return True for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True import fractions x = fractions.gcd(A, B) divisors = make_divisors(x) ans = 0 for d in divisors: if is_prime(d): ans += 1 print(ans)
A, B = list(map(int, input().split())) def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a import fractions x = fractions.gcd(A, B) ans = prime_factorize(x) print((len(set(ans)) + 1))
false
25.806452
[ "-def make_divisors(n):", "- divisors = []", "- for i in range(1, int(n**0.5) + 1):", "- if n % i == 0:", "- divisors.append(i)", "- if i != n // i:", "- divisors.append(n // i)", "- return divisors", "-", "-", "-import math", "-", "-", "-def is_prime(n):", "- if n == 1:", "- return True", "- for k in range(2, int(math.sqrt(n)) + 1):", "- if n % k == 0:", "- return False", "- return True", "+def prime_factorize(n):", "+ a = []", "+ while n % 2 == 0:", "+ a.append(2)", "+ n //= 2", "+ f = 3", "+ while f * f <= n:", "+ if n % f == 0:", "+ a.append(f)", "+ n //= f", "+ else:", "+ f += 2", "+ if n != 1:", "+ a.append(n)", "+ return a", "-divisors = make_divisors(x)", "-ans = 0", "-for d in divisors:", "- if is_prime(d):", "- ans += 1", "-print(ans)", "+ans = prime_factorize(x)", "+print((len(set(ans)) + 1))" ]
false
0.062422
0.050821
1.228293
[ "s252162339", "s776057292" ]
u488401358
p02586
python
s347205640
s662653336
2,669
656
229,708
151,304
Accepted
Accepted
75.42
mycode = r''' # distutils: language=c++ # cython: language_level=3, boundscheck=False, wraparound=False, cdivision=True ctypedef long long LL # cython: cdivision=True from libc.stdio cimport scanf from libcpp.vector cimport vector ctypedef vector[LL] vec cdef LL R,C,K,i,j,k scanf("%lld %lld %lld",&R,&C,&K) cdef vector[vector[LL]] dp = [[0 for j in range(3)] for i in range(C)] cdef vector[vector[LL]] ndp = [[0 for j in range(3)] for i in range(C)] cdef vector[vector[LL]] item = [[0 for j in range(C)] for i in range(R)] cdef LL r,c,v for i in range(K): scanf("%lld %lld %lld",&r,&c,&v) item[r-1][c-1] = v dp[C-1][0] = item[R-1][C-1] dp[C-1][1] = item[R-1][C-1] dp[C-1][2] = item[R-1][C-1] for j in range(C-2,-1,-1): dp[j][0]=max(dp[j+1][1]+item[R-1][j],dp[j+1][0]) dp[j][1]=max(dp[j+1][2]+item[R-1][j],dp[j+1][1]) dp[j][2]=max(item[R-1][j],dp[j+1][2]) for i in range(R-2,-1,-1): ndp = [[0 for j in range(3)] for i in range(C)] ndp[C-1][0]=dp[C-1][0]+item[i][C-1] ndp[C-1][1]=dp[C-1][0]+item[i][C-1] ndp[C-1][2]=dp[C-1][0]+item[i][C-1] for j in range(C-2,-1,-1): ndp[j][0]=max(max(dp[j][0],ndp[j+1][1])+item[i][j],ndp[j+1][0]) ndp[j][1]=max(max(dp[j][0],ndp[j+1][2])+item[i][j],ndp[j+1][1]) ndp[j][2]=max(dp[j][0]+item[i][j],ndp[j+1][2]) dp=ndp print(dp[0][0]) ''' import sys import os if sys.argv[-1] == 'ONLINE_JUDGE': # コンパイル時 with open('mycode.pyx', 'w') as f: f.write(mycode) os.system('cythonize -i -3 -b mycode.pyx') import mycode
mycode = r''' # distutils: language=c++ # cython: language_level=3, boundscheck=False, wraparound=False, cdivision=True ctypedef long long LL # cython: cdivision=True from libc.stdio cimport scanf from libcpp.vector cimport vector ctypedef vector[LL] vec ctypedef vector[vec] vec_vec cdef LL R,C,K,i,j,k scanf("%lld %lld %lld",&R,&C,&K) cdef vec_vec dp,ndp,item dp = vec_vec(C,vec(3,0)) ndp = vec_vec(C,vec(3,0)) item = vec_vec(R,vec(C,0)) cdef LL r,c,v for i in range(K): scanf("%lld %lld %lld",&r,&c,&v) item[r-1][c-1] = v dp[C-1][0] = item[R-1][C-1] dp[C-1][1] = item[R-1][C-1] dp[C-1][2] = item[R-1][C-1] for j in range(C-2,-1,-1): dp[j][0]=max(dp[j+1][1]+item[R-1][j],dp[j+1][0]) dp[j][1]=max(dp[j+1][2]+item[R-1][j],dp[j+1][1]) dp[j][2]=max(item[R-1][j],dp[j+1][2]) for i in range(R-2,-1,-1): ndp = vec_vec(C,vec(3,0)) ndp[C-1][0]=dp[C-1][0]+item[i][C-1] ndp[C-1][1]=dp[C-1][0]+item[i][C-1] ndp[C-1][2]=dp[C-1][0]+item[i][C-1] for j in range(C-2,-1,-1): ndp[j][0]=max(max(dp[j][0],ndp[j+1][1])+item[i][j],ndp[j+1][0]) ndp[j][1]=max(max(dp[j][0],ndp[j+1][2])+item[i][j],ndp[j+1][1]) ndp[j][2]=max(dp[j][0]+item[i][j],ndp[j+1][2]) dp=ndp print(dp[0][0]) ''' import sys import os if sys.argv[-1] == 'ONLINE_JUDGE': # コンパイル時 with open('mycode.pyx', 'w') as f: f.write(mycode) os.system('cythonize -i -3 -b mycode.pyx') import mycode
54
59
1,589
1,492
mycode = r""" # distutils: language=c++ # cython: language_level=3, boundscheck=False, wraparound=False, cdivision=True ctypedef long long LL # cython: cdivision=True from libc.stdio cimport scanf from libcpp.vector cimport vector ctypedef vector[LL] vec cdef LL R,C,K,i,j,k scanf("%lld %lld %lld",&R,&C,&K) cdef vector[vector[LL]] dp = [[0 for j in range(3)] for i in range(C)] cdef vector[vector[LL]] ndp = [[0 for j in range(3)] for i in range(C)] cdef vector[vector[LL]] item = [[0 for j in range(C)] for i in range(R)] cdef LL r,c,v for i in range(K): scanf("%lld %lld %lld",&r,&c,&v) item[r-1][c-1] = v dp[C-1][0] = item[R-1][C-1] dp[C-1][1] = item[R-1][C-1] dp[C-1][2] = item[R-1][C-1] for j in range(C-2,-1,-1): dp[j][0]=max(dp[j+1][1]+item[R-1][j],dp[j+1][0]) dp[j][1]=max(dp[j+1][2]+item[R-1][j],dp[j+1][1]) dp[j][2]=max(item[R-1][j],dp[j+1][2]) for i in range(R-2,-1,-1): ndp = [[0 for j in range(3)] for i in range(C)] ndp[C-1][0]=dp[C-1][0]+item[i][C-1] ndp[C-1][1]=dp[C-1][0]+item[i][C-1] ndp[C-1][2]=dp[C-1][0]+item[i][C-1] for j in range(C-2,-1,-1): ndp[j][0]=max(max(dp[j][0],ndp[j+1][1])+item[i][j],ndp[j+1][0]) ndp[j][1]=max(max(dp[j][0],ndp[j+1][2])+item[i][j],ndp[j+1][1]) ndp[j][2]=max(dp[j][0]+item[i][j],ndp[j+1][2]) dp=ndp print(dp[0][0]) """ import sys import os if sys.argv[-1] == "ONLINE_JUDGE": # コンパイル時 with open("mycode.pyx", "w") as f: f.write(mycode) os.system("cythonize -i -3 -b mycode.pyx") import mycode
mycode = r""" # distutils: language=c++ # cython: language_level=3, boundscheck=False, wraparound=False, cdivision=True ctypedef long long LL # cython: cdivision=True from libc.stdio cimport scanf from libcpp.vector cimport vector ctypedef vector[LL] vec ctypedef vector[vec] vec_vec cdef LL R,C,K,i,j,k scanf("%lld %lld %lld",&R,&C,&K) cdef vec_vec dp,ndp,item dp = vec_vec(C,vec(3,0)) ndp = vec_vec(C,vec(3,0)) item = vec_vec(R,vec(C,0)) cdef LL r,c,v for i in range(K): scanf("%lld %lld %lld",&r,&c,&v) item[r-1][c-1] = v dp[C-1][0] = item[R-1][C-1] dp[C-1][1] = item[R-1][C-1] dp[C-1][2] = item[R-1][C-1] for j in range(C-2,-1,-1): dp[j][0]=max(dp[j+1][1]+item[R-1][j],dp[j+1][0]) dp[j][1]=max(dp[j+1][2]+item[R-1][j],dp[j+1][1]) dp[j][2]=max(item[R-1][j],dp[j+1][2]) for i in range(R-2,-1,-1): ndp = vec_vec(C,vec(3,0)) ndp[C-1][0]=dp[C-1][0]+item[i][C-1] ndp[C-1][1]=dp[C-1][0]+item[i][C-1] ndp[C-1][2]=dp[C-1][0]+item[i][C-1] for j in range(C-2,-1,-1): ndp[j][0]=max(max(dp[j][0],ndp[j+1][1])+item[i][j],ndp[j+1][0]) ndp[j][1]=max(max(dp[j][0],ndp[j+1][2])+item[i][j],ndp[j+1][1]) ndp[j][2]=max(dp[j][0]+item[i][j],ndp[j+1][2]) dp=ndp print(dp[0][0]) """ import sys import os if sys.argv[-1] == "ONLINE_JUDGE": # コンパイル時 with open("mycode.pyx", "w") as f: f.write(mycode) os.system("cythonize -i -3 -b mycode.pyx") import mycode
false
8.474576
[ "+ctypedef vector[vec] vec_vec", "-cdef vector[vector[LL]] dp = [[0 for j in range(3)] for i in range(C)]", "-cdef vector[vector[LL]] ndp = [[0 for j in range(3)] for i in range(C)]", "-cdef vector[vector[LL]] item = [[0 for j in range(C)] for i in range(R)]", "+cdef vec_vec dp,ndp,item", "+dp = vec_vec(C,vec(3,0))", "+ndp = vec_vec(C,vec(3,0))", "+item = vec_vec(R,vec(C,0))", "- ndp = [[0 for j in range(3)] for i in range(C)]", "+ ndp = vec_vec(C,vec(3,0))" ]
false
0.075251
0.056758
1.325808
[ "s347205640", "s662653336" ]
u368796742
p02558
python
s436828408
s385831429
445
393
81,180
79,212
Accepted
Accepted
11.69
import sys input = sys.stdin.readline class Unionfind: def __init__(self,n): self.uf = [-1]*n def find(self,x): if self.uf[x] < 0: return x else: self.uf[x] = self.find(self.uf[x]) return self.uf[x] def same(self,x,y): return self.find(x) == self.find(y) def union(self,x,y): x = self.find(x) y = self.find(y) if x == y: return False if self.uf[x] > self.uf[y]: x,y = y,x self.uf[x] += self.uf[y] self.uf[y] = x return True def size(self,x): x = self.find(x) return -self.uf[x] def main(): n,q = list(map(int,input().split())) U = Unionfind(n) for i in range(q): t,u,v = list(map(int,input().split())) if t == 0: U.union(u,v) else: print((int(U.same(u,v)))) if __name__ == "__main__": main()
import sys input = sys.stdin.readline class Unionfind: def __init__(self,n): self.uf = [-1]*n def find(self,x): if self.uf[x] < 0: return x else: self.uf[x] = self.find(self.uf[x]) return self.uf[x] def same(self,x,y): return self.find(x) == self.find(y) def union(self,x,y): x = self.find(x) y = self.find(y) if x == y: return False if self.uf[x] > self.uf[y]: x,y = y,x self.uf[x] += self.uf[y] self.uf[y] = x return True def size(self,x): x = self.find(x) return -self.uf[x] n,q = list(map(int,input().split())) U = Unionfind(n) for i in range(q): t,u,v = list(map(int,input().split())) if t == 0: U.union(u,v) else: print((int(U.same(u,v))))
43
40
982
898
import sys input = sys.stdin.readline class Unionfind: def __init__(self, n): self.uf = [-1] * n def find(self, x): if self.uf[x] < 0: return x else: self.uf[x] = self.find(self.uf[x]) return self.uf[x] def same(self, x, y): return self.find(x) == self.find(y) def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return False if self.uf[x] > self.uf[y]: x, y = y, x self.uf[x] += self.uf[y] self.uf[y] = x return True def size(self, x): x = self.find(x) return -self.uf[x] def main(): n, q = list(map(int, input().split())) U = Unionfind(n) for i in range(q): t, u, v = list(map(int, input().split())) if t == 0: U.union(u, v) else: print((int(U.same(u, v)))) if __name__ == "__main__": main()
import sys input = sys.stdin.readline class Unionfind: def __init__(self, n): self.uf = [-1] * n def find(self, x): if self.uf[x] < 0: return x else: self.uf[x] = self.find(self.uf[x]) return self.uf[x] def same(self, x, y): return self.find(x) == self.find(y) def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return False if self.uf[x] > self.uf[y]: x, y = y, x self.uf[x] += self.uf[y] self.uf[y] = x return True def size(self, x): x = self.find(x) return -self.uf[x] n, q = list(map(int, input().split())) U = Unionfind(n) for i in range(q): t, u, v = list(map(int, input().split())) if t == 0: U.union(u, v) else: print((int(U.same(u, v))))
false
6.976744
[ "-def main():", "- n, q = list(map(int, input().split()))", "- U = Unionfind(n)", "- for i in range(q):", "- t, u, v = list(map(int, input().split()))", "- if t == 0:", "- U.union(u, v)", "- else:", "- print((int(U.same(u, v))))", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+n, q = list(map(int, input().split()))", "+U = Unionfind(n)", "+for i in range(q):", "+ t, u, v = list(map(int, input().split()))", "+ if t == 0:", "+ U.union(u, v)", "+ else:", "+ print((int(U.same(u, v))))" ]
false
0.085876
0.042936
2.000093
[ "s436828408", "s385831429" ]
u638456847
p02733
python
s474723209
s218639739
752
394
3,316
3,188
Accepted
Accepted
47.61
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): H,W,K = list(map(int, readline().split())) S = [list(map(int, readline().strip())) for j in range(H)] white = 0 for line in S: white += sum(line) if white <= K: print((0)) exit() # 横線の決め方を全探索 ans = 10**5 for pattern in range(2**(H-1)): # 初期化 impossible = False x = 0 ly = bin(pattern).count("1") y = [[0]*W]*(ly + 1) line = 0 for i in range(H): y[line] = [y[line][j] + S[i][j] for j in range(W)] if (pattern >> i) & 1: line += 1 # 各列の値を加算していく count = [0]*(ly + 1) for j in range(W): for i in range(line+1): if y[i][j] > K : impossible = True break count[i] += y[i][j] if count[i] > K: x += 1 for i in range(line+1): count[i] = y[i][j] break if x + ly > ans or impossible: impossible = True break if impossible: x = 10**6 ans = min(ans, x + ly) print(ans) if __name__ == "__main__": main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): H,W,K = list(map(int, readline().split())) S = [list(map(int, readline().strip())) for j in range(H)] white = 0 for line in S: white += sum(line) if white <= K: print((0)) exit() # 横線の決め方を全探索 ans = 10**5 for pattern in range(2**(H-1)): # 初期化 impossible = False x = 0 ly = bin(pattern).count("1") y = [S[0]] line = 0 for i in range(1,H): if (pattern >> i-1) & 1: line += 1 y.append(S[i]) else: y[line] = [y[line][j] + S[i][j] for j in range(W)] # 各列の値を加算していく count = [0]*(ly + 1) for j in range(W): for i in range(line+1): if y[i][j] > K : impossible = True break count[i] += y[i][j] if count[i] > K: x += 1 for i in range(line+1): count[i] = y[i][j] break if x + ly > ans or impossible: impossible = True break if impossible: x = 10**6 ans = min(ans, x + ly) print(ans) if __name__ == "__main__": main()
58
60
1,397
1,446
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): H, W, K = list(map(int, readline().split())) S = [list(map(int, readline().strip())) for j in range(H)] white = 0 for line in S: white += sum(line) if white <= K: print((0)) exit() # 横線の決め方を全探索 ans = 10**5 for pattern in range(2 ** (H - 1)): # 初期化 impossible = False x = 0 ly = bin(pattern).count("1") y = [[0] * W] * (ly + 1) line = 0 for i in range(H): y[line] = [y[line][j] + S[i][j] for j in range(W)] if (pattern >> i) & 1: line += 1 # 各列の値を加算していく count = [0] * (ly + 1) for j in range(W): for i in range(line + 1): if y[i][j] > K: impossible = True break count[i] += y[i][j] if count[i] > K: x += 1 for i in range(line + 1): count[i] = y[i][j] break if x + ly > ans or impossible: impossible = True break if impossible: x = 10**6 ans = min(ans, x + ly) print(ans) if __name__ == "__main__": main()
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines def main(): H, W, K = list(map(int, readline().split())) S = [list(map(int, readline().strip())) for j in range(H)] white = 0 for line in S: white += sum(line) if white <= K: print((0)) exit() # 横線の決め方を全探索 ans = 10**5 for pattern in range(2 ** (H - 1)): # 初期化 impossible = False x = 0 ly = bin(pattern).count("1") y = [S[0]] line = 0 for i in range(1, H): if (pattern >> i - 1) & 1: line += 1 y.append(S[i]) else: y[line] = [y[line][j] + S[i][j] for j in range(W)] # 各列の値を加算していく count = [0] * (ly + 1) for j in range(W): for i in range(line + 1): if y[i][j] > K: impossible = True break count[i] += y[i][j] if count[i] > K: x += 1 for i in range(line + 1): count[i] = y[i][j] break if x + ly > ans or impossible: impossible = True break if impossible: x = 10**6 ans = min(ans, x + ly) print(ans) if __name__ == "__main__": main()
false
3.333333
[ "- y = [[0] * W] * (ly + 1)", "+ y = [S[0]]", "- for i in range(H):", "- y[line] = [y[line][j] + S[i][j] for j in range(W)]", "- if (pattern >> i) & 1:", "+ for i in range(1, H):", "+ if (pattern >> i - 1) & 1:", "+ y.append(S[i])", "+ else:", "+ y[line] = [y[line][j] + S[i][j] for j in range(W)]" ]
false
0.03845
0.044094
0.872007
[ "s474723209", "s218639739" ]
u767797498
p02623
python
s231074401
s007883422
717
625
41,400
41,480
Accepted
Accepted
12.83
import math def solve(n,m,k,a_lst,b_lst): #机ごと、読書時間の累積をリストにする。ただし、リスト化はk時間内で読める範囲とする aa_lst = make_sum_list(a_lst,k) bb_lst = make_sum_list(b_lst,k) len_aa = len(aa_lst) len_bb = len(bb_lst) #A,Bいずれかが一冊も読めないケースを考慮 if len_aa == 0: if len_bb == 0: return 0 else: return len_bb elif len_bb == 0: return len_aa #全て読めるケースを考慮 if aa_lst[-1] + bb_lst[-1] <= k: return len_aa + len_bb #A,Bいずれかのみ読むケースを考慮 max_read = max(len_aa,len_bb) #リスト範囲でA+Bの最大値を探索する。2分探索を用いる for i in reversed(list(range(len_aa))): time = aa_lst[i] read = i + 1 if read + len_bb + 1 <= max_read: break imax = len_bb-1 imin = 0 imid = len_bb // 2 while True: if time + bb_lst[imid] <= k: #OK。大を調べる if imax - imid <= 1: #探査終了 if time + bb_lst[imax] <= k: read += imax + 1 else: read += imid + 1 break imin = imid else: #NG。小を調べる if imid - imin <= 1: #探査完了 if time + bb_lst[imin] <= k: read += imin + 1 break imax = imid imid = (imin + imax) // 2 max_read = max(read,max_read) return max_read def make_sum_list(lst,max): sum_lst = [] sum = 0 for n in lst: sum += n if sum > max: break sum_lst.append(sum) return sum_lst n,m,k = list(map(int, input().split())) a_lst = list(map(int, input().split())) b_lst = list(map(int, input().split())) ans = solve(n,m,k,a_lst,b_lst) print(ans)
import math def solve(n,m,k,a_lst,b_lst): #机ごと、読書時間の累積をリストにする。ただし、リスト化はk時間内で読める範囲とする aa_lst = make_sum_list(a_lst,k) bb_lst = make_sum_list(b_lst,k) len_aa = len(aa_lst) len_bb = len(bb_lst) #A,Bいずれかが一冊も読めないケースを考慮 if len_aa == 0: return len_bb elif len_bb == 0: return len_aa #全て読めるケースを考慮 if aa_lst[-1] + bb_lst[-1] <= k: return len_aa + len_bb #A,Bいずれかのみ読むケースを考慮 max_read = max(len_aa,len_bb) #リスト範囲でA+Bの最大値を探索する。2分探索を用いる for i in reversed(list(range(len_aa))): limit = k - aa_lst[i] read = i + 1 if read + len_bb + 1 <= max_read: #以後 read は増えない break imax = len_bb-1 imin = 0 imid = len_bb // 2 while True: if bb_lst[imid] <= limit: #OK。大を調べる if imax - imid <= 1: #探査終了 if bb_lst[imax] <= limit: read += imax + 1 else: read += imid + 1 break imin = imid else: #NG。小を調べる if imid - imin <= 1: #探査完了 if bb_lst[imin] <= limit: read += imin + 1 break imax = imid imid = (imin + imax) // 2 max_read = max(read,max_read) return max_read def make_sum_list(lst,max): sum_lst = [] sum = 0 for n in lst: sum += n if sum > max: break sum_lst.append(sum) return sum_lst n,m,k = list(map(int, input().split())) a_lst = list(map(int, input().split())) b_lst = list(map(int, input().split())) ans = solve(n,m,k,a_lst,b_lst) print(ans)
69
68
1,861
1,838
import math def solve(n, m, k, a_lst, b_lst): # 机ごと、読書時間の累積をリストにする。ただし、リスト化はk時間内で読める範囲とする aa_lst = make_sum_list(a_lst, k) bb_lst = make_sum_list(b_lst, k) len_aa = len(aa_lst) len_bb = len(bb_lst) # A,Bいずれかが一冊も読めないケースを考慮 if len_aa == 0: if len_bb == 0: return 0 else: return len_bb elif len_bb == 0: return len_aa # 全て読めるケースを考慮 if aa_lst[-1] + bb_lst[-1] <= k: return len_aa + len_bb # A,Bいずれかのみ読むケースを考慮 max_read = max(len_aa, len_bb) # リスト範囲でA+Bの最大値を探索する。2分探索を用いる for i in reversed(list(range(len_aa))): time = aa_lst[i] read = i + 1 if read + len_bb + 1 <= max_read: break imax = len_bb - 1 imin = 0 imid = len_bb // 2 while True: if time + bb_lst[imid] <= k: # OK。大を調べる if imax - imid <= 1: # 探査終了 if time + bb_lst[imax] <= k: read += imax + 1 else: read += imid + 1 break imin = imid else: # NG。小を調べる if imid - imin <= 1: # 探査完了 if time + bb_lst[imin] <= k: read += imin + 1 break imax = imid imid = (imin + imax) // 2 max_read = max(read, max_read) return max_read def make_sum_list(lst, max): sum_lst = [] sum = 0 for n in lst: sum += n if sum > max: break sum_lst.append(sum) return sum_lst n, m, k = list(map(int, input().split())) a_lst = list(map(int, input().split())) b_lst = list(map(int, input().split())) ans = solve(n, m, k, a_lst, b_lst) print(ans)
import math def solve(n, m, k, a_lst, b_lst): # 机ごと、読書時間の累積をリストにする。ただし、リスト化はk時間内で読める範囲とする aa_lst = make_sum_list(a_lst, k) bb_lst = make_sum_list(b_lst, k) len_aa = len(aa_lst) len_bb = len(bb_lst) # A,Bいずれかが一冊も読めないケースを考慮 if len_aa == 0: return len_bb elif len_bb == 0: return len_aa # 全て読めるケースを考慮 if aa_lst[-1] + bb_lst[-1] <= k: return len_aa + len_bb # A,Bいずれかのみ読むケースを考慮 max_read = max(len_aa, len_bb) # リスト範囲でA+Bの最大値を探索する。2分探索を用いる for i in reversed(list(range(len_aa))): limit = k - aa_lst[i] read = i + 1 if read + len_bb + 1 <= max_read: # 以後 read は増えない break imax = len_bb - 1 imin = 0 imid = len_bb // 2 while True: if bb_lst[imid] <= limit: # OK。大を調べる if imax - imid <= 1: # 探査終了 if bb_lst[imax] <= limit: read += imax + 1 else: read += imid + 1 break imin = imid else: # NG。小を調べる if imid - imin <= 1: # 探査完了 if bb_lst[imin] <= limit: read += imin + 1 break imax = imid imid = (imin + imax) // 2 max_read = max(read, max_read) return max_read def make_sum_list(lst, max): sum_lst = [] sum = 0 for n in lst: sum += n if sum > max: break sum_lst.append(sum) return sum_lst n, m, k = list(map(int, input().split())) a_lst = list(map(int, input().split())) b_lst = list(map(int, input().split())) ans = solve(n, m, k, a_lst, b_lst) print(ans)
false
1.449275
[ "- if len_bb == 0:", "- return 0", "- else:", "- return len_bb", "+ return len_bb", "- time = aa_lst[i]", "+ limit = k - aa_lst[i]", "+ # 以後 read は増えない", "- if time + bb_lst[imid] <= k:", "+ if bb_lst[imid] <= limit:", "- if time + bb_lst[imax] <= k:", "+ if bb_lst[imax] <= limit:", "- if time + bb_lst[imin] <= k:", "+ if bb_lst[imin] <= limit:" ]
false
0.081632
0.109464
0.745747
[ "s231074401", "s007883422" ]
u317440328
p03473
python
s881417738
s612516990
20
17
2,940
2,940
Accepted
Accepted
15
M=int(eval(input())) print((48-M))
print((48-int(eval(input()))))
2
1
27
22
M = int(eval(input())) print((48 - M))
print((48 - int(eval(input()))))
false
50
[ "-M = int(eval(input()))", "-print((48 - M))", "+print((48 - int(eval(input()))))" ]
false
0.046819
0.063334
0.739247
[ "s881417738", "s612516990" ]
u803848678
p03216
python
s186192431
s190053124
2,469
1,774
55,804
55,660
Accepted
Accepted
28.15
def main(): n = int(eval(input())) s = eval(input()) q = int(eval(input())) k = list(map(int, input().split())) for ki in k: ans = 0 DMC = [0]*3 for i in range(n): c = s[i] if c == "D": DMC[0] += 1 elif c == "M": DMC[1] += 1 DMC[2] += DMC[0] elif c == "C": ans += DMC[2] if i >= ki-1: j = i-ki+1 if s[j] == "D": DMC[0] -= 1 DMC[2] -= DMC[1] elif s[j] == "M": DMC[1] -= 1 print(ans) if __name__ == "__main__": main()
def main(): n = int(eval(input())) s = eval(input()) q = int(eval(input())) k = list(map(int, input().split())) for ki in k: ans = 0 DMC = [0]*3 for i in range(n): if s[i] == "D": DMC[0] += 1 elif s[i] == "M": DMC[1] += 1 DMC[2] += DMC[0] if i >= ki: j = i-ki if s[j] == "D": DMC[0] -= 1 DMC[2] -= DMC[1] elif s[j] == "M": DMC[1] -= 1 if s[i] == "C": ans += DMC[2] print(ans) if __name__ == "__main__": main()
27
27
711
694
def main(): n = int(eval(input())) s = eval(input()) q = int(eval(input())) k = list(map(int, input().split())) for ki in k: ans = 0 DMC = [0] * 3 for i in range(n): c = s[i] if c == "D": DMC[0] += 1 elif c == "M": DMC[1] += 1 DMC[2] += DMC[0] elif c == "C": ans += DMC[2] if i >= ki - 1: j = i - ki + 1 if s[j] == "D": DMC[0] -= 1 DMC[2] -= DMC[1] elif s[j] == "M": DMC[1] -= 1 print(ans) if __name__ == "__main__": main()
def main(): n = int(eval(input())) s = eval(input()) q = int(eval(input())) k = list(map(int, input().split())) for ki in k: ans = 0 DMC = [0] * 3 for i in range(n): if s[i] == "D": DMC[0] += 1 elif s[i] == "M": DMC[1] += 1 DMC[2] += DMC[0] if i >= ki: j = i - ki if s[j] == "D": DMC[0] -= 1 DMC[2] -= DMC[1] elif s[j] == "M": DMC[1] -= 1 if s[i] == "C": ans += DMC[2] print(ans) if __name__ == "__main__": main()
false
0
[ "- c = s[i]", "- if c == \"D\":", "+ if s[i] == \"D\":", "- elif c == \"M\":", "+ elif s[i] == \"M\":", "- elif c == \"C\":", "- ans += DMC[2]", "- if i >= ki - 1:", "- j = i - ki + 1", "+ if i >= ki:", "+ j = i - ki", "+ if s[i] == \"C\":", "+ ans += DMC[2]" ]
false
0.040035
0.048437
0.826545
[ "s186192431", "s190053124" ]
u796942881
p03325
python
s930867318
s850470120
96
24
4,084
4,084
Accepted
Accepted
75
input = open(0).read N, *an = list(map(int, input().split())) def main(): ans = 0 for i in range(N): tmp = 0 while an[i]: if an[i] % 2: break else: tmp += 1 an[i] //= 2 ans += tmp print(ans) return main()
def main(): N, *a = list(map(int, open(0).read().split())) print((sum([bin(ai)[::-1].index("1") for ai in a]))) return main()
24
7
342
138
input = open(0).read N, *an = list(map(int, input().split())) def main(): ans = 0 for i in range(N): tmp = 0 while an[i]: if an[i] % 2: break else: tmp += 1 an[i] //= 2 ans += tmp print(ans) return main()
def main(): N, *a = list(map(int, open(0).read().split())) print((sum([bin(ai)[::-1].index("1") for ai in a]))) return main()
false
70.833333
[ "-input = open(0).read", "-N, *an = list(map(int, input().split()))", "-", "-", "- ans = 0", "- for i in range(N):", "- tmp = 0", "- while an[i]:", "- if an[i] % 2:", "- break", "- else:", "- tmp += 1", "- an[i] //= 2", "- ans += tmp", "- print(ans)", "+ N, *a = list(map(int, open(0).read().split()))", "+ print((sum([bin(ai)[::-1].index(\"1\") for ai in a])))" ]
false
0.088762
0.038202
2.323481
[ "s930867318", "s850470120" ]
u957098479
p02622
python
s355226456
s442686380
93
60
9,288
9,204
Accepted
Accepted
35.48
#import s=eval(input()) t=eval(input()) #=int(input()) #=map(str,input().split()) #=list(map(int,input().split())) #=[list(map(int,input().split())) for _ in range()] cnt = 0 i = 0 while i <= (len(s)-1): if s[i] != t[i]: cnt += 1 i += 1 print(cnt)
#import s=eval(input()) t=eval(input()) #=int(input()) #=map(int,input().split()) #=list(map(int,input().split())) #=[list(map(int,input().split())) for _ in range()] cnt = 0 for i in range(len(s)): if s[i] != t[i]: cnt += 1 print(cnt)
15
13
267
249
# import s = eval(input()) t = eval(input()) # =int(input()) # =map(str,input().split()) # =list(map(int,input().split())) # =[list(map(int,input().split())) for _ in range()] cnt = 0 i = 0 while i <= (len(s) - 1): if s[i] != t[i]: cnt += 1 i += 1 print(cnt)
# import s = eval(input()) t = eval(input()) # =int(input()) # =map(int,input().split()) # =list(map(int,input().split())) # =[list(map(int,input().split())) for _ in range()] cnt = 0 for i in range(len(s)): if s[i] != t[i]: cnt += 1 print(cnt)
false
13.333333
[ "-# =map(str,input().split())", "+# =map(int,input().split())", "-i = 0", "-while i <= (len(s) - 1):", "+for i in range(len(s)):", "- i += 1" ]
false
0.037164
0.060503
0.61425
[ "s355226456", "s442686380" ]
u252828980
p03111
python
s865203746
s574532797
248
182
9,332
75,836
Accepted
Accepted
26.61
n,a,b,c,*L = list(map(int,open(0).read().split())) L.sort(reverse = True) from itertools import product from copy import deepcopy li1 = [4,1,2,3] ans = 10**10 for v in product(li1,repeat = n): #print(v) num = 0 A,B,C,NO = [],[],[],[] for i in range(n): if v[i] == 1: #if L[i] not in (a,b,c): A.append(L[i]) elif v[i] == 2: #if L[i] not in (a,b,c): B.append(L[i]) elif v[i] == 3: #if L[i] not in (a,b,c): C.append(L[i]) elif v[i] == 4: NO.append(L[i]) if A and B and C: num +=abs(sum(A)-a) + max(0,(len(A)-1)*10) + abs(sum(B)-b) + max(0,(len(B)-1)*10)+ abs(sum(C)-c) + max(0,(len(C)-1)*10) ans = min(ans,num) #print(num,ans,A,B,C,max(0,(len(A)-1)*10),max(0,(len(B)-1)*10)) print(ans)
from itertools import product n,a,b,c,*L = list(map(int,open(0).read().split())) li1 = [1,2,3,4] ans = 10**10 for v in product(li1,repeat = n): num = 0 A,B,C = [],[],[] for i in range(n): if v[i] == 1: A.append(L[i]) elif v[i] == 2: B.append(L[i]) elif v[i] == 3: C.append(L[i]) if A and B and C: num +=abs(sum(A)-a) + max(0,(len(A)-1)*10) + abs(sum(B)-b) + max(0,(len(B)-1)*10)+ abs(sum(C)-c) + max(0,(len(C)-1)*10) ans = min(ans,num) print(ans)
28
22
860
557
n, a, b, c, *L = list(map(int, open(0).read().split())) L.sort(reverse=True) from itertools import product from copy import deepcopy li1 = [4, 1, 2, 3] ans = 10**10 for v in product(li1, repeat=n): # print(v) num = 0 A, B, C, NO = [], [], [], [] for i in range(n): if v[i] == 1: # if L[i] not in (a,b,c): A.append(L[i]) elif v[i] == 2: # if L[i] not in (a,b,c): B.append(L[i]) elif v[i] == 3: # if L[i] not in (a,b,c): C.append(L[i]) elif v[i] == 4: NO.append(L[i]) if A and B and C: num += ( abs(sum(A) - a) + max(0, (len(A) - 1) * 10) + abs(sum(B) - b) + max(0, (len(B) - 1) * 10) + abs(sum(C) - c) + max(0, (len(C) - 1) * 10) ) ans = min(ans, num) # print(num,ans,A,B,C,max(0,(len(A)-1)*10),max(0,(len(B)-1)*10)) print(ans)
from itertools import product n, a, b, c, *L = list(map(int, open(0).read().split())) li1 = [1, 2, 3, 4] ans = 10**10 for v in product(li1, repeat=n): num = 0 A, B, C = [], [], [] for i in range(n): if v[i] == 1: A.append(L[i]) elif v[i] == 2: B.append(L[i]) elif v[i] == 3: C.append(L[i]) if A and B and C: num += ( abs(sum(A) - a) + max(0, (len(A) - 1) * 10) + abs(sum(B) - b) + max(0, (len(B) - 1) * 10) + abs(sum(C) - c) + max(0, (len(C) - 1) * 10) ) ans = min(ans, num) print(ans)
false
21.428571
[ "+from itertools import product", "+", "-L.sort(reverse=True)", "-from itertools import product", "-from copy import deepcopy", "-", "-li1 = [4, 1, 2, 3]", "+li1 = [1, 2, 3, 4]", "- # print(v)", "- A, B, C, NO = [], [], [], []", "+ A, B, C = [], [], []", "- # if L[i] not in (a,b,c):", "- # if L[i] not in (a,b,c):", "- # if L[i] not in (a,b,c):", "- elif v[i] == 4:", "- NO.append(L[i])", "- # print(num,ans,A,B,C,max(0,(len(A)-1)*10),max(0,(len(B)-1)*10))" ]
false
0.226791
0.205844
1.10176
[ "s865203746", "s574532797" ]
u228232845
p04045
python
s416999636
s937943882
107
81
9,144
9,212
Accepted
Accepted
24.3
# 24 import sys def input(): return sys.stdin.readline().strip() def I(): return int(eval(input())) def LI(): return list(map(int, input().split())) def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def S(): return eval(input()) def LS(): return input().split() INF = float('inf') n, k = LI() d = set(LI()) # 最小金額から条件を満たすまで増やしていく while True: if all([int(j) not in d for j in str(n)]): # 全ての桁の数字が d に属さない print(n) exit() n += 1
# 24 import sys def input(): return sys.stdin.readline().strip() def I(): return int(eval(input())) def LI(): return list(map(int, input().split())) def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def S(): return eval(input()) def LS(): return input().split() INF = float('inf') n, k = LI() d = set(LI()) # 最小金額から条件を満たすまで増やしていく while True: if all(int(j) not in d for j in str(n)): # 全ての桁の数字が d に属さない print(n) exit() n += 1
25
25
548
546
# 24 import sys def input(): return sys.stdin.readline().strip() def I(): return int(eval(input())) def LI(): return list(map(int, input().split())) def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def S(): return eval(input()) def LS(): return input().split() INF = float("inf") n, k = LI() d = set(LI()) # 最小金額から条件を満たすまで増やしていく while True: if all([int(j) not in d for j in str(n)]): # 全ての桁の数字が d に属さない print(n) exit() n += 1
# 24 import sys def input(): return sys.stdin.readline().strip() def I(): return int(eval(input())) def LI(): return list(map(int, input().split())) def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def S(): return eval(input()) def LS(): return input().split() INF = float("inf") n, k = LI() d = set(LI()) # 最小金額から条件を満たすまで増やしていく while True: if all(int(j) not in d for j in str(n)): # 全ての桁の数字が d に属さない print(n) exit() n += 1
false
0
[ "- if all([int(j) not in d for j in str(n)]): # 全ての桁の数字が d に属さない", "+ if all(int(j) not in d for j in str(n)): # 全ての桁の数字が d に属さない" ]
false
0.04239
0.040637
1.043125
[ "s416999636", "s937943882" ]
u729133443
p03433
python
s713624111
s845248387
36
17
27,756
2,940
Accepted
Accepted
52.78
print('YNeos'[eval(input())%500>eval(input())::2])
n,a=list(map(int,open(0)));print(('YNeos'[n%500>a::2]))
1
1
36
47
print("YNeos"[eval(input()) % 500 > eval(input()) :: 2])
n, a = list(map(int, open(0))) print(("YNeos"[n % 500 > a :: 2]))
false
0
[ "-print(\"YNeos\"[eval(input()) % 500 > eval(input()) :: 2])", "+n, a = list(map(int, open(0)))", "+print((\"YNeos\"[n % 500 > a :: 2]))" ]
false
0.052733
0.041054
1.284473
[ "s713624111", "s845248387" ]
u077898957
p03624
python
s682135705
s457492468
176
19
4,280
3,188
Accepted
Accepted
89.2
import sys s = sorted(eval(input())) a = ord('a') for j in range(26): b = a for i in s: if a == ord(i): a += 1 break if a == b: print((chr(a))) sys.exit() print('None')
S=sorted(set(eval(input()))) ans=None for i in range(97,97+26): if chr(i) not in S: ans=chr(i) break print(ans)
13
7
233
122
import sys s = sorted(eval(input())) a = ord("a") for j in range(26): b = a for i in s: if a == ord(i): a += 1 break if a == b: print((chr(a))) sys.exit() print("None")
S = sorted(set(eval(input()))) ans = None for i in range(97, 97 + 26): if chr(i) not in S: ans = chr(i) break print(ans)
false
46.153846
[ "-import sys", "-", "-s = sorted(eval(input()))", "-a = ord(\"a\")", "-for j in range(26):", "- b = a", "- for i in s:", "- if a == ord(i):", "- a += 1", "- break", "- if a == b:", "- print((chr(a)))", "- sys.exit()", "-print(\"None\")", "+S = sorted(set(eval(input())))", "+ans = None", "+for i in range(97, 97 + 26):", "+ if chr(i) not in S:", "+ ans = chr(i)", "+ break", "+print(ans)" ]
false
0.044739
0.047753
0.936895
[ "s682135705", "s457492468" ]
u621935300
p02760
python
s602008641
s359889072
42
36
28,524
28,652
Accepted
Accepted
14.29
def bingo(C): if C[0]==C[1]==C[2] and C[0]==1: return True elif C[3]==C[4]==C[5] and C[3]==1: return True elif C[6]==C[7]==C[8] and C[6]==1: return True elif C[0]==C[3]==C[6] and C[0]==1: return True elif C[1]==C[4]==C[7] and C[1]==1: return True elif C[2]==C[5]==C[8] and C[2]==1: return True elif C[0]==C[4]==C[8] and C[0]==1: return True elif C[2]==C[4]==C[6] and C[2]==1: return True else: return False A=[] for _ in range(3): x1,x2,x3=list(map(int, input().split())) A.append(x1) A.append(x2) A.append(x3) B=[ 0 for _ in range(9) ] N=eval(input()) for _ in range(N): b=eval(input()) for i,x in enumerate(A): if b==x: B[i]=1 if bingo(B): print("Yes") else: print("No")
import sys A1=list(map(int, sys.stdin.readline().split())) A2=list(map(int, sys.stdin.readline().split())) A3=list(map(int, sys.stdin.readline().split())) A=A1+A2+A3 N=eval(input()) def isbingo(): if A[0]==A[1]==A[2]==0: return True elif A[3]==A[4]==A[5]==0: return True elif A[6]==A[7]==A[8]==0: return True elif A[0]==A[3]==A[6]==0: return True elif A[1]==A[4]==A[7]==0: return True elif A[2]==A[5]==A[8]==0: return True elif A[0]==A[4]==A[8]==0: return True elif A[2]==A[4]==A[6]==0: return True else: return False for _ in range(N): b=int(sys.stdin.readline().strip()) for i,a in enumerate(A): if b==a: A[i]=0 if isbingo(): print("Yes") else: print("No")
42
28
875
734
def bingo(C): if C[0] == C[1] == C[2] and C[0] == 1: return True elif C[3] == C[4] == C[5] and C[3] == 1: return True elif C[6] == C[7] == C[8] and C[6] == 1: return True elif C[0] == C[3] == C[6] and C[0] == 1: return True elif C[1] == C[4] == C[7] and C[1] == 1: return True elif C[2] == C[5] == C[8] and C[2] == 1: return True elif C[0] == C[4] == C[8] and C[0] == 1: return True elif C[2] == C[4] == C[6] and C[2] == 1: return True else: return False A = [] for _ in range(3): x1, x2, x3 = list(map(int, input().split())) A.append(x1) A.append(x2) A.append(x3) B = [0 for _ in range(9)] N = eval(input()) for _ in range(N): b = eval(input()) for i, x in enumerate(A): if b == x: B[i] = 1 if bingo(B): print("Yes") else: print("No")
import sys A1 = list(map(int, sys.stdin.readline().split())) A2 = list(map(int, sys.stdin.readline().split())) A3 = list(map(int, sys.stdin.readline().split())) A = A1 + A2 + A3 N = eval(input()) def isbingo(): if A[0] == A[1] == A[2] == 0: return True elif A[3] == A[4] == A[5] == 0: return True elif A[6] == A[7] == A[8] == 0: return True elif A[0] == A[3] == A[6] == 0: return True elif A[1] == A[4] == A[7] == 0: return True elif A[2] == A[5] == A[8] == 0: return True elif A[0] == A[4] == A[8] == 0: return True elif A[2] == A[4] == A[6] == 0: return True else: return False for _ in range(N): b = int(sys.stdin.readline().strip()) for i, a in enumerate(A): if b == a: A[i] = 0 if isbingo(): print("Yes") else: print("No")
false
33.333333
[ "-def bingo(C):", "- if C[0] == C[1] == C[2] and C[0] == 1:", "+import sys", "+", "+A1 = list(map(int, sys.stdin.readline().split()))", "+A2 = list(map(int, sys.stdin.readline().split()))", "+A3 = list(map(int, sys.stdin.readline().split()))", "+A = A1 + A2 + A3", "+N = eval(input())", "+", "+", "+def isbingo():", "+ if A[0] == A[1] == A[2] == 0:", "- elif C[3] == C[4] == C[5] and C[3] == 1:", "+ elif A[3] == A[4] == A[5] == 0:", "- elif C[6] == C[7] == C[8] and C[6] == 1:", "+ elif A[6] == A[7] == A[8] == 0:", "- elif C[0] == C[3] == C[6] and C[0] == 1:", "+ elif A[0] == A[3] == A[6] == 0:", "- elif C[1] == C[4] == C[7] and C[1] == 1:", "+ elif A[1] == A[4] == A[7] == 0:", "- elif C[2] == C[5] == C[8] and C[2] == 1:", "+ elif A[2] == A[5] == A[8] == 0:", "- elif C[0] == C[4] == C[8] and C[0] == 1:", "+ elif A[0] == A[4] == A[8] == 0:", "- elif C[2] == C[4] == C[6] and C[2] == 1:", "+ elif A[2] == A[4] == A[6] == 0:", "-A = []", "-for _ in range(3):", "- x1, x2, x3 = list(map(int, input().split()))", "- A.append(x1)", "- A.append(x2)", "- A.append(x3)", "-B = [0 for _ in range(9)]", "-N = eval(input())", "- b = eval(input())", "- for i, x in enumerate(A):", "- if b == x:", "- B[i] = 1", "-if bingo(B):", "+ b = int(sys.stdin.readline().strip())", "+ for i, a in enumerate(A):", "+ if b == a:", "+ A[i] = 0", "+if isbingo():" ]
false
0.037654
0.071173
0.529047
[ "s602008641", "s359889072" ]
u094191970
p02820
python
s966386377
s116148610
98
80
4,980
4,212
Accepted
Accepted
18.37
n,k=list(map(int,input().split())) R,S,P=list(map(int,input().split())) t=eval(input()) ans=0 win=[] for tt in t: if tt=='r': win+='p' ans+=P elif tt=='s': win+='r' ans+=R else: win+='s' ans+=S for i in range(k): l=win[i::k] # print(l) for j in range(1,len(l)): if l[j]==l[j-1]: if l[j]=='p': ans-=P elif l[j]=='r': ans-=R else: ans-=S l[j]='z' print(ans)
n,k=list(map(int,input().split())) R,S,P=list(map(int,input().split())) t=eval(input()) v=[] ans=0 for i in t: if i=='r': v.append('p') ans+=P if i=='s': v.append('r') ans+=R if i=='p': v.append('s') ans+=S for i in range(k,n): if v[i]==v[i-k]: if v[i]=='r': ans-=R if v[i]=='s': ans-=S if v[i]=='p': ans-=P v[i]='?' print(ans)
31
29
413
407
n, k = list(map(int, input().split())) R, S, P = list(map(int, input().split())) t = eval(input()) ans = 0 win = [] for tt in t: if tt == "r": win += "p" ans += P elif tt == "s": win += "r" ans += R else: win += "s" ans += S for i in range(k): l = win[i::k] # print(l) for j in range(1, len(l)): if l[j] == l[j - 1]: if l[j] == "p": ans -= P elif l[j] == "r": ans -= R else: ans -= S l[j] = "z" print(ans)
n, k = list(map(int, input().split())) R, S, P = list(map(int, input().split())) t = eval(input()) v = [] ans = 0 for i in t: if i == "r": v.append("p") ans += P if i == "s": v.append("r") ans += R if i == "p": v.append("s") ans += S for i in range(k, n): if v[i] == v[i - k]: if v[i] == "r": ans -= R if v[i] == "s": ans -= S if v[i] == "p": ans -= P v[i] = "?" print(ans)
false
6.451613
[ "+v = []", "-win = []", "-for tt in t:", "- if tt == \"r\":", "- win += \"p\"", "+for i in t:", "+ if i == \"r\":", "+ v.append(\"p\")", "- elif tt == \"s\":", "- win += \"r\"", "+ if i == \"s\":", "+ v.append(\"r\")", "- else:", "- win += \"s\"", "+ if i == \"p\":", "+ v.append(\"s\")", "-for i in range(k):", "- l = win[i::k]", "- # print(l)", "- for j in range(1, len(l)):", "- if l[j] == l[j - 1]:", "- if l[j] == \"p\":", "- ans -= P", "- elif l[j] == \"r\":", "- ans -= R", "- else:", "- ans -= S", "- l[j] = \"z\"", "+for i in range(k, n):", "+ if v[i] == v[i - k]:", "+ if v[i] == \"r\":", "+ ans -= R", "+ if v[i] == \"s\":", "+ ans -= S", "+ if v[i] == \"p\":", "+ ans -= P", "+ v[i] = \"?\"" ]
false
0.097154
0.042322
2.295606
[ "s966386377", "s116148610" ]
u014333473
p03845
python
s349230980
s045706452
32
29
9,152
9,180
Accepted
Accepted
9.38
N=int(input());T=list(map(int,input().split()));M=int(input());total=sum(T) px=[list(map(int,input().split())) for _ in range(M)] [print(total + px[i][1] - T[px[i][0]-1]) for i in range(M)]
n,t=int(input()),list(map(int,input().split()));T=sum(t) print(*[T-t[i-1]+j for i,j in [list(map(int,input().split())) for _ in range(int(input()))]],sep='\n')
3
2
191
160
N = int(input()) T = list(map(int, input().split())) M = int(input()) total = sum(T) px = [list(map(int, input().split())) for _ in range(M)] [print(total + px[i][1] - T[px[i][0] - 1]) for i in range(M)]
n, t = int(input()), list(map(int, input().split())) T = sum(t) print( *[ T - t[i - 1] + j for i, j in [list(map(int, input().split())) for _ in range(int(input()))] ], sep="\n" )
false
33.333333
[ "-N = int(input())", "-T = list(map(int, input().split()))", "-M = int(input())", "-total = sum(T)", "-px = [list(map(int, input().split())) for _ in range(M)]", "-[print(total + px[i][1] - T[px[i][0] - 1]) for i in range(M)]", "+n, t = int(input()), list(map(int, input().split()))", "+T = sum(t)", "+print(", "+ *[", "+ T - t[i - 1] + j", "+ for i, j in [list(map(int, input().split())) for _ in range(int(input()))]", "+ ],", "+ sep=\"\\n\"", "+)" ]
false
0.047064
0.132471
0.355279
[ "s349230980", "s045706452" ]
u286955577
p03078
python
s045168817
s993583812
1,993
36
161,256
4,976
Accepted
Accepted
98.19
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) AB = [] for a in A: for b in B: AB.append(a + b) AB.sort(reverse=True) AB = AB[:min(3001, X * Y * Z + 1)] ABC = [] for c in C: for ab in AB: ABC.append(ab + c) ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
from heapq import heappop, heappush X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) counted = set() h = [(-(A[0] + B[0] + C[0]), 0, 0, 0)] for _ in range(K): s, i, j, k = heappop(h) print((-s)) if X > i + 1 and (i + 1, j, k) not in counted: heappush(h, (-(A[i + 1] + B[j] + C[k]), i + 1, j, k)) counted.add((i + 1, j, k)) if Y > j + 1 and (i, j + 1, k) not in counted: heappush(h, (-(A[i] + B[j + 1] + C[k]), i, j + 1, k)) counted.add((i, j + 1, k)) if Z > k + 1 and (i, j, k + 1) not in counted: heappush(h, (-(A[i] + B[j] + C[k + 1]), i, j, k + 1)) counted.add((i, j, k + 1))
20
24
465
831
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) AB = [] for a in A: for b in B: AB.append(a + b) AB.sort(reverse=True) AB = AB[: min(3001, X * Y * Z + 1)] ABC = [] for c in C: for ab in AB: ABC.append(ab + c) ABC.sort(reverse=True) for i in range(K): print((ABC[i]))
from heapq import heappop, heappush X, Y, Z, K = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) C.sort(reverse=True) counted = set() h = [(-(A[0] + B[0] + C[0]), 0, 0, 0)] for _ in range(K): s, i, j, k = heappop(h) print((-s)) if X > i + 1 and (i + 1, j, k) not in counted: heappush(h, (-(A[i + 1] + B[j] + C[k]), i + 1, j, k)) counted.add((i + 1, j, k)) if Y > j + 1 and (i, j + 1, k) not in counted: heappush(h, (-(A[i] + B[j + 1] + C[k]), i, j + 1, k)) counted.add((i, j + 1, k)) if Z > k + 1 and (i, j, k + 1) not in counted: heappush(h, (-(A[i] + B[j] + C[k + 1]), i, j, k + 1)) counted.add((i, j, k + 1))
false
16.666667
[ "+from heapq import heappop, heappush", "+", "-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)", "-AB = []", "-for a in A:", "- for b in B:", "- AB.append(a + b)", "-AB.sort(reverse=True)", "-AB = AB[: min(3001, X * Y * Z + 1)]", "-ABC = []", "-for c in C:", "- for ab in AB:", "- ABC.append(ab + c)", "-ABC.sort(reverse=True)", "-for i in range(K):", "- print((ABC[i]))", "+A = list(map(int, input().split()))", "+B = list(map(int, input().split()))", "+C = list(map(int, input().split()))", "+A.sort(reverse=True)", "+B.sort(reverse=True)", "+C.sort(reverse=True)", "+counted = set()", "+h = [(-(A[0] + B[0] + C[0]), 0, 0, 0)]", "+for _ in range(K):", "+ s, i, j, k = heappop(h)", "+ print((-s))", "+ if X > i + 1 and (i + 1, j, k) not in counted:", "+ heappush(h, (-(A[i + 1] + B[j] + C[k]), i + 1, j, k))", "+ counted.add((i + 1, j, k))", "+ if Y > j + 1 and (i, j + 1, k) not in counted:", "+ heappush(h, (-(A[i] + B[j + 1] + C[k]), i, j + 1, k))", "+ counted.add((i, j + 1, k))", "+ if Z > k + 1 and (i, j, k + 1) not in counted:", "+ heappush(h, (-(A[i] + B[j] + C[k + 1]), i, j, k + 1))", "+ counted.add((i, j, k + 1))" ]
false
0.044105
0.008357
5.277447
[ "s045168817", "s993583812" ]
u759726213
p02779
python
s270883806
s129609779
284
179
25,684
26,808
Accepted
Accepted
36.97
import sys N = int(eval(input())) As = list(map(int, input().split())) As.sort() for i in range(N): for j in range(i + 1, N): if As[i] == As[j]: print('NO') sys.exit(0) if As[j] > As[i]: break print('YES')
import sys N = int(eval(input())) A = list(map(int, input().split())) A.sort() for i in range(N - 1): if A[i] == A[i + 1]: print('NO') sys.exit(0) print('YES')
15
12
272
188
import sys N = int(eval(input())) As = list(map(int, input().split())) As.sort() for i in range(N): for j in range(i + 1, N): if As[i] == As[j]: print("NO") sys.exit(0) if As[j] > As[i]: break print("YES")
import sys N = int(eval(input())) A = list(map(int, input().split())) A.sort() for i in range(N - 1): if A[i] == A[i + 1]: print("NO") sys.exit(0) print("YES")
false
20
[ "-As = list(map(int, input().split()))", "-As.sort()", "-for i in range(N):", "- for j in range(i + 1, N):", "- if As[i] == As[j]:", "- print(\"NO\")", "- sys.exit(0)", "- if As[j] > As[i]:", "- break", "+A = list(map(int, input().split()))", "+A.sort()", "+for i in range(N - 1):", "+ if A[i] == A[i + 1]:", "+ print(\"NO\")", "+ sys.exit(0)" ]
false
0.036814
0.036131
1.018902
[ "s270883806", "s129609779" ]
u306950978
p03200
python
s563015694
s301092970
80
68
3,500
3,500
Accepted
Accepted
15
s = eval(input()) b = s.count("B") n = len(s) cou = 0 ans = 0 for i in reversed(list(range(n))): if s[i] == "B": ans += n - 1 - cou - i cou += 1 print(ans)
s = eval(input()) n = len(s) ans = 0 cou = 0 for i in range(n): if s[i] == "W": ans += i - cou cou += 1 print(ans)
10
10
172
138
s = eval(input()) b = s.count("B") n = len(s) cou = 0 ans = 0 for i in reversed(list(range(n))): if s[i] == "B": ans += n - 1 - cou - i cou += 1 print(ans)
s = eval(input()) n = len(s) ans = 0 cou = 0 for i in range(n): if s[i] == "W": ans += i - cou cou += 1 print(ans)
false
0
[ "-b = s.count(\"B\")", "+ans = 0", "-ans = 0", "-for i in reversed(list(range(n))):", "- if s[i] == \"B\":", "- ans += n - 1 - cou - i", "+for i in range(n):", "+ if s[i] == \"W\":", "+ ans += i - cou" ]
false
0.047209
0.046646
1.012064
[ "s563015694", "s301092970" ]
u512212329
p02691
python
s708629706
s668245228
219
154
67,188
46,308
Accepted
Accepted
29.68
class Map(dict): def __missing__(self, key): self[key] = 0 return 0 def main(): int(eval(input())) d = Map() ans = 0 for i, height in enumerate(input().split()): height = int(height) # 引き算のほうの i は足し算のよりも大きい。 # 従って,このように順番に見ていく必要がある。 d[i + height] += 1 ans += d[i - height] return ans if __name__ == '__main__': print((main())) # 大いに参考にした。 # https://kmjp.hatenablog.jp/entry/2020/05/03/1030
# class Map(dict): # def __missing__(self, key): # # この割当てなしのほうが速い。 # # self[key] = 0 # return 0 def main(): int(eval(input())) d = {} ans = 0 for i, height in enumerate(input().split()): height = int(height) # 引き算のほうの i は足し算のよりも大きい。 # 従って,このように順番に見ていく必要がある。 got = d.get(i + height) or 0 d[i + height] = got + 1 ans += d.get(i - height) or 0 return ans if __name__ == '__main__': print((main())) # 大いに参考にした。 # https://kmjp.hatenablog.jp/entry/2020/05/03/1030
26
28
498
585
class Map(dict): def __missing__(self, key): self[key] = 0 return 0 def main(): int(eval(input())) d = Map() ans = 0 for i, height in enumerate(input().split()): height = int(height) # 引き算のほうの i は足し算のよりも大きい。 # 従って,このように順番に見ていく必要がある。 d[i + height] += 1 ans += d[i - height] return ans if __name__ == "__main__": print((main())) # 大いに参考にした。 # https://kmjp.hatenablog.jp/entry/2020/05/03/1030
# class Map(dict): # def __missing__(self, key): # # この割当てなしのほうが速い。 # # self[key] = 0 # return 0 def main(): int(eval(input())) d = {} ans = 0 for i, height in enumerate(input().split()): height = int(height) # 引き算のほうの i は足し算のよりも大きい。 # 従って,このように順番に見ていく必要がある。 got = d.get(i + height) or 0 d[i + height] = got + 1 ans += d.get(i - height) or 0 return ans if __name__ == "__main__": print((main())) # 大いに参考にした。 # https://kmjp.hatenablog.jp/entry/2020/05/03/1030
false
7.142857
[ "-class Map(dict):", "- def __missing__(self, key):", "- self[key] = 0", "- return 0", "-", "-", "+# class Map(dict):", "+# def __missing__(self, key):", "+# # この割当てなしのほうが速い。", "+# # self[key] = 0", "+# return 0", "- d = Map()", "+ d = {}", "- d[i + height] += 1", "- ans += d[i - height]", "+ got = d.get(i + height) or 0", "+ d[i + height] = got + 1", "+ ans += d.get(i - height) or 0" ]
false
0.038379
0.044754
0.857539
[ "s708629706", "s668245228" ]