user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
sequence
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
sequence
u708255304
p02807
python
s634821934
s950740171
700
218
74,656
26,748
Accepted
Accepted
68.86
# 二項係数を"やるだけ"にしてくれるライブラリ MAX = 510000 MOD = 1000000007 factrial = [0]*MAX inverse = [0]*MAX factrial_inverse = [0]*MAX # テーブルを作る前処理 def COMinit(): global factrial, inverse, factrial_inverse factrial[0] = 1 factrial[1] = 1 inverse[1] = 1 factrial_inverse[0] = 1 factrial_inverse[1] = 1 for i in range(2, MAX): factrial[i] = factrial[i-1] * i % MOD inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD # 二項係数計算 def COM(n, k): global factrial, inverse, factrial_inverse if n < k: return 0 if n < 0 or k < 0: return 0 return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD # 前処理完了 COMinit() N = int(eval(input())) X = list(map(int, input().split())) # expected_value = [1] # for i in range(2, N): # expected_value.append(expected_value[-1]+(1/i)) ans = 0 f = factrial[N-1] c = 0 for i in range(1, N): c += f * inverse[i] c %= MOD ans += c * (X[i] - X[i-1]) ans %= MOD print((ans % MOD))
# 二項係数を"やるだけ"にしてくれるライブラリ MAX = 100005 MOD = 1000000007 factrial = [0]*MAX inverse = [0]*MAX factrial_inverse = [0]*MAX # テーブルを作る前処理 def COMinit(): global factrial, inverse, factrial_inverse factrial[0] = 1 factrial[1] = 1 inverse[1] = 1 factrial_inverse[0] = 1 factrial_inverse[1] = 1 for i in range(2, MAX): factrial[i] = factrial[i-1] * i % MOD inverse[i] = MOD - inverse[MOD % i] * (MOD//i) % MOD factrial_inverse[i] = factrial_inverse[i-1] * inverse[i] % MOD # 二項係数計算 def COM(n, k): global factrial, inverse, factrial_inverse if n < k: return 0 if n < 0 or k < 0: return 0 return factrial[n] * (factrial_inverse[k] * factrial_inverse[n-k] % MOD) % MOD # 前処理完了 COMinit() N = int(eval(input())) X = list(map(int, input().split())) ans = 0 prepro = [1] for i in range(2, N+1): prepro.append((prepro[-1]+inverse[i]) % MOD) for i in range(N-1): ans += (X[i+1]-X[i]) * prepro[i] % MOD ans *= factrial[N-1] # 期待値の総和に(N-1)!をかける print((ans % MOD))
50
49
1,123
1,087
# 二項係数を"やるだけ"にしてくれるライブラリ MAX = 510000 MOD = 1000000007 factrial = [0] * MAX inverse = [0] * MAX factrial_inverse = [0] * MAX # テーブルを作る前処理 def COMinit(): global factrial, inverse, factrial_inverse factrial[0] = 1 factrial[1] = 1 inverse[1] = 1 factrial_inverse[0] = 1 factrial_inverse[1] = 1 for i in range(2, MAX): factrial[i] = factrial[i - 1] * i % MOD inverse[i] = MOD - inverse[MOD % i] * (MOD // i) % MOD factrial_inverse[i] = factrial_inverse[i - 1] * inverse[i] % MOD # 二項係数計算 def COM(n, k): global factrial, inverse, factrial_inverse if n < k: return 0 if n < 0 or k < 0: return 0 return factrial[n] * (factrial_inverse[k] * factrial_inverse[n - k] % MOD) % MOD # 前処理完了 COMinit() N = int(eval(input())) X = list(map(int, input().split())) # expected_value = [1] # for i in range(2, N): # expected_value.append(expected_value[-1]+(1/i)) ans = 0 f = factrial[N - 1] c = 0 for i in range(1, N): c += f * inverse[i] c %= MOD ans += c * (X[i] - X[i - 1]) ans %= MOD print((ans % MOD))
# 二項係数を"やるだけ"にしてくれるライブラリ MAX = 100005 MOD = 1000000007 factrial = [0] * MAX inverse = [0] * MAX factrial_inverse = [0] * MAX # テーブルを作る前処理 def COMinit(): global factrial, inverse, factrial_inverse factrial[0] = 1 factrial[1] = 1 inverse[1] = 1 factrial_inverse[0] = 1 factrial_inverse[1] = 1 for i in range(2, MAX): factrial[i] = factrial[i - 1] * i % MOD inverse[i] = MOD - inverse[MOD % i] * (MOD // i) % MOD factrial_inverse[i] = factrial_inverse[i - 1] * inverse[i] % MOD # 二項係数計算 def COM(n, k): global factrial, inverse, factrial_inverse if n < k: return 0 if n < 0 or k < 0: return 0 return factrial[n] * (factrial_inverse[k] * factrial_inverse[n - k] % MOD) % MOD # 前処理完了 COMinit() N = int(eval(input())) X = list(map(int, input().split())) ans = 0 prepro = [1] for i in range(2, N + 1): prepro.append((prepro[-1] + inverse[i]) % MOD) for i in range(N - 1): ans += (X[i + 1] - X[i]) * prepro[i] % MOD ans *= factrial[N - 1] # 期待値の総和に(N-1)!をかける print((ans % MOD))
false
2
[ "-MAX = 510000", "+MAX = 100005", "-# expected_value = [1]", "-# for i in range(2, N):", "-# expected_value.append(expected_value[-1]+(1/i))", "-f = factrial[N - 1]", "-c = 0", "-for i in range(1, N):", "- c += f * inverse[i]", "- c %= MOD", "- ans += c * (X[i] - X[i - 1])", "- ans %= MOD", "+prepro = [1]", "+for i in range(2, N + 1):", "+ prepro.append((prepro[-1] + inverse[i]) % MOD)", "+for i in range(N - 1):", "+ ans += (X[i + 1] - X[i]) * prepro[i] % MOD", "+ans *= factrial[N - 1] # 期待値の総和に(N-1)!をかける" ]
false
1.295694
0.195219
6.637121
[ "s634821934", "s950740171" ]
u747602774
p02754
python
s678727315
s379745745
19
17
3,064
2,940
Accepted
Accepted
10.53
N,A,B = list(map(int,input().split())) a = N//(A+B) ans = a*A + min((N-a*(A+B)),A) print(ans)
N,A,B = list(map(int,input().split())) print((N//(A+B)*A + min((N-N//(A+B)*(A+B)),A)))
4
2
91
80
N, A, B = list(map(int, input().split())) a = N // (A + B) ans = a * A + min((N - a * (A + B)), A) print(ans)
N, A, B = list(map(int, input().split())) print((N // (A + B) * A + min((N - N // (A + B) * (A + B)), A)))
false
50
[ "-a = N // (A + B)", "-ans = a * A + min((N - a * (A + B)), A)", "-print(ans)", "+print((N // (A + B) * A + min((N - N // (A + B) * (A + B)), A)))" ]
false
0.068197
0.070041
0.973675
[ "s678727315", "s379745745" ]
u853952087
p03221
python
s557518269
s293201884
1,039
923
43,172
43,172
Accepted
Accepted
11.16
a,b=list(map(int,input().split())) L=[[] for i in range(a)] u=0 for i in range(b): u+=1 c=list(map(int,input().split())) c.append(u) L[int(c[0])-1].append(c) for i in L: i.sort(key=lambda x:x[1]) for i in L: e=0 for j in i: e+=1 j.append(e) q=[] for w in L: q.extend(w) q.sort(key=lambda x:x[2]) for r in range(b): print((str(q[r][0]).zfill(6)+str(q[r][3]).zfill(6)))
a,b=list(map(int,input().split())) L=[[] for i in range(a)] u=0 # i番目の県の情報([i,年,入力順])をLのi番目に入れる for i in range(b): u+=1 c=list(map(int,input().split())) c.append(u) L[int(c[0])-1].append(c) # Lの要素を年でソート for i in L: i.sort(key=lambda x:x[1]) # ソートしたので、要素ごとに何番目にできたかを末尾に付け加えておく for i in L: e=0 for j in i: e+=1 j.append(e) q=[] for w in L: q.extend(w)# flatten # 入力順に並べ替えて、入力した順に出力できるようにする q.sort(key=lambda x:x[2]) for r in range(b): print((str(q[r][0]).zfill(6)+str(q[r][3]).zfill(6)))# zfill
21
25
435
563
a, b = list(map(int, input().split())) L = [[] for i in range(a)] u = 0 for i in range(b): u += 1 c = list(map(int, input().split())) c.append(u) L[int(c[0]) - 1].append(c) for i in L: i.sort(key=lambda x: x[1]) for i in L: e = 0 for j in i: e += 1 j.append(e) q = [] for w in L: q.extend(w) q.sort(key=lambda x: x[2]) for r in range(b): print((str(q[r][0]).zfill(6) + str(q[r][3]).zfill(6)))
a, b = list(map(int, input().split())) L = [[] for i in range(a)] u = 0 # i番目の県の情報([i,年,入力順])をLのi番目に入れる for i in range(b): u += 1 c = list(map(int, input().split())) c.append(u) L[int(c[0]) - 1].append(c) # Lの要素を年でソート for i in L: i.sort(key=lambda x: x[1]) #  ソートしたので、要素ごとに何番目にできたかを末尾に付け加えておく for i in L: e = 0 for j in i: e += 1 j.append(e) q = [] for w in L: q.extend(w) # flatten # 入力順に並べ替えて、入力した順に出力できるようにする q.sort(key=lambda x: x[2]) for r in range(b): print((str(q[r][0]).zfill(6) + str(q[r][3]).zfill(6))) # zfill
false
16
[ "+# i番目の県の情報([i,年,入力順])をLのi番目に入れる", "+# Lの要素を年でソート", "+#  ソートしたので、要素ごとに何番目にできたかを末尾に付け加えておく", "- q.extend(w)", "+ q.extend(w) # flatten", "+# 入力順に並べ替えて、入力した順に出力できるようにする", "- print((str(q[r][0]).zfill(6) + str(q[r][3]).zfill(6)))", "+ print((str(q[r][0]).zfill(6) + str(q[r][3]).zfill(6))) # zfill" ]
false
0.04594
0.078486
0.585328
[ "s557518269", "s293201884" ]
u620084012
p03221
python
s191384351
s234611687
1,181
985
83,800
81,712
Accepted
Accepted
16.6
N, M = list(map(int,input().split())) L = [list(map(int,input().split())) for k in range(M)] for k in range(M): L[k].append(k) L = sorted(L) A = [[L[0][0],1,L[0][2]]] t = 1 for k in range(1,M): if L[k-1][0] != L[k][0]: t = 1 else: t += 1 A.append([L[k][0],t,L[k][2]]) A = sorted(A, key = lambda x: x[2]) for a in A: print((str(a[0]).zfill(6) + str(a[1]).zfill(6)))
N, M = list(map(int,input().split())) P = [[] for k in range(N)] A = [0 for k in range(M)] for k in range(M): s, t = list(map(int,input().split())) P[s-1].append([t,k]) for k in range(N): P[k].sort() for l in range(len(P[k])): A[P[k][l][1]] = str(k+1).zfill(6) + str(l+1).zfill(6) for a in A: print(("".join(a)))
21
15
417
343
N, M = list(map(int, input().split())) L = [list(map(int, input().split())) for k in range(M)] for k in range(M): L[k].append(k) L = sorted(L) A = [[L[0][0], 1, L[0][2]]] t = 1 for k in range(1, M): if L[k - 1][0] != L[k][0]: t = 1 else: t += 1 A.append([L[k][0], t, L[k][2]]) A = sorted(A, key=lambda x: x[2]) for a in A: print((str(a[0]).zfill(6) + str(a[1]).zfill(6)))
N, M = list(map(int, input().split())) P = [[] for k in range(N)] A = [0 for k in range(M)] for k in range(M): s, t = list(map(int, input().split())) P[s - 1].append([t, k]) for k in range(N): P[k].sort() for l in range(len(P[k])): A[P[k][l][1]] = str(k + 1).zfill(6) + str(l + 1).zfill(6) for a in A: print(("".join(a)))
false
28.571429
[ "-L = [list(map(int, input().split())) for k in range(M)]", "+P = [[] for k in range(N)]", "+A = [0 for k in range(M)]", "- L[k].append(k)", "-L = sorted(L)", "-A = [[L[0][0], 1, L[0][2]]]", "-t = 1", "-for k in range(1, M):", "- if L[k - 1][0] != L[k][0]:", "- t = 1", "- else:", "- t += 1", "- A.append([L[k][0], t, L[k][2]])", "-A = sorted(A, key=lambda x: x[2])", "+ s, t = list(map(int, input().split()))", "+ P[s - 1].append([t, k])", "+for k in range(N):", "+ P[k].sort()", "+ for l in range(len(P[k])):", "+ A[P[k][l][1]] = str(k + 1).zfill(6) + str(l + 1).zfill(6)", "- print((str(a[0]).zfill(6) + str(a[1]).zfill(6)))", "+ print((\"\".join(a)))" ]
false
0.033524
0.033964
0.987025
[ "s191384351", "s234611687" ]
u688564053
p02712
python
s538201170
s741268441
132
120
179,368
141,900
Accepted
Accepted
9.09
N = int(eval(input())) l = [i for i in range(1, N + 1)] s = [] for i in l: if i % 3 != 0 and i % 5 != 0: s.append(i) print((sum(s)))
N = int(eval(input())) l = [i for i in range(1, N + 1)] s = 0 for i in l: if i % 3 != 0 and i % 5 != 0: s += i print(s)
7
8
143
133
N = int(eval(input())) l = [i for i in range(1, N + 1)] s = [] for i in l: if i % 3 != 0 and i % 5 != 0: s.append(i) print((sum(s)))
N = int(eval(input())) l = [i for i in range(1, N + 1)] s = 0 for i in l: if i % 3 != 0 and i % 5 != 0: s += i print(s)
false
12.5
[ "-s = []", "+s = 0", "- s.append(i)", "-print((sum(s)))", "+ s += i", "+print(s)" ]
false
0.49187
0.453377
1.084904
[ "s538201170", "s741268441" ]
u102126195
p03032
python
s114404201
s320615503
154
138
76,632
75,748
Accepted
Accepted
10.39
import heapq, copy n, k = list(map(int, input().split())) v = list(map(int, input().split())) ans = -10 ** 10 for a in range(min(n, k) + 1): have = [] for i in range(a): have.append(v[i]) o_have = copy.deepcopy(have) for b in range(min(n, k) - a + 1): for i in range(b): have.append(v[n-i-1]) heapq.heapify(have) # print(1, have) for c in range(k - a - b): if len(have) <= 0: break item = heapq.heappop(have) # print(c, item, have) if item >= 0: have.append(item) break ans = max(ans, sum(have)) # print(2, have, ans, a, b) have = copy.deepcopy(o_have) print(ans)
import heapq, copy n, k = list(map(int, input().split())) v = list(map(int, input().split())) ans = -10 ** 10 for a in range(min(n, k) + 1): for b in range(min(n, k) - a + 1): have = [] for i in range(a): have.append(v[i]) for i in range(b): have.append(v[n-i-1]) heapq.heapify(have) for c in range(k - a - b): if len(have) <= 0: break item = heapq.heappop(have) if item >= 0: have.append(item) break ans = max(ans, sum(have)) print(ans)
30
25
779
636
import heapq, copy n, k = list(map(int, input().split())) v = list(map(int, input().split())) ans = -(10**10) for a in range(min(n, k) + 1): have = [] for i in range(a): have.append(v[i]) o_have = copy.deepcopy(have) for b in range(min(n, k) - a + 1): for i in range(b): have.append(v[n - i - 1]) heapq.heapify(have) # print(1, have) for c in range(k - a - b): if len(have) <= 0: break item = heapq.heappop(have) # print(c, item, have) if item >= 0: have.append(item) break ans = max(ans, sum(have)) # print(2, have, ans, a, b) have = copy.deepcopy(o_have) print(ans)
import heapq, copy n, k = list(map(int, input().split())) v = list(map(int, input().split())) ans = -(10**10) for a in range(min(n, k) + 1): for b in range(min(n, k) - a + 1): have = [] for i in range(a): have.append(v[i]) for i in range(b): have.append(v[n - i - 1]) heapq.heapify(have) for c in range(k - a - b): if len(have) <= 0: break item = heapq.heappop(have) if item >= 0: have.append(item) break ans = max(ans, sum(have)) print(ans)
false
16.666667
[ "- have = []", "- for i in range(a):", "- have.append(v[i])", "- o_have = copy.deepcopy(have)", "+ have = []", "+ for i in range(a):", "+ have.append(v[i])", "- # print(1, have)", "- # print(c, item, have)", "- # print(2, have, ans, a, b)", "- have = copy.deepcopy(o_have)" ]
false
0.046857
0.043653
1.073415
[ "s114404201", "s320615503" ]
u891504219
p02773
python
s551093188
s285216352
597
397
45,288
45,288
Accepted
Accepted
33.5
def main(): import sys import collections input = sys.stdin.readline N = int(input()) S = [input() for i in range(N)] c = collections.Counter(S) max_num = c.most_common(1)[0][1] ss = [cc[0] for cc in c.most_common() if cc[1] == max_num] ss.sort() for s in ss: print(s,end="") if __name__ == "__main__": main()
def main(): import sys import collections input = sys.stdin.readline N = int(eval(input())) S = [eval(input()) for i in range(N)] c = collections.Counter(S) max_num = c.most_common(1)[0][1] ss = [cc[0] for cc in c.most_common() if cc[1] == max_num] ss.sort() print(("\n".join(ss))) if __name__ == "__main__": main()
15
14
377
359
def main(): import sys import collections input = sys.stdin.readline N = int(input()) S = [input() for i in range(N)] c = collections.Counter(S) max_num = c.most_common(1)[0][1] ss = [cc[0] for cc in c.most_common() if cc[1] == max_num] ss.sort() for s in ss: print(s, end="") if __name__ == "__main__": main()
def main(): import sys import collections input = sys.stdin.readline N = int(eval(input())) S = [eval(input()) for i in range(N)] c = collections.Counter(S) max_num = c.most_common(1)[0][1] ss = [cc[0] for cc in c.most_common() if cc[1] == max_num] ss.sort() print(("\n".join(ss))) if __name__ == "__main__": main()
false
6.666667
[ "- N = int(input())", "- S = [input() for i in range(N)]", "+ N = int(eval(input()))", "+ S = [eval(input()) for i in range(N)]", "- for s in ss:", "- print(s, end=\"\")", "+ print((\"\\n\".join(ss)))" ]
false
0.041595
0.036332
1.144866
[ "s551093188", "s285216352" ]
u345966487
p03559
python
s802216252
s045786574
354
297
22,720
22,720
Accepted
Accepted
16.1
from bisect import* (N,),A,B,C=[sorted(map(int,input().split()))for _ in range(4)] w,i=[0]*(N+1),N while i:i-=1;w[i]=w[i+1]+N-bisect(C,B[i]) print((sum(w[bisect(B,a)]for a in A)))
from bisect import* (N,),A,B,C=[sorted(map(int,input().split()))for _ in[0]*4] print((sum(bisect_left(A,b)*(N-bisect(C,b))for b in B)))
5
3
181
135
from bisect import * (N,), A, B, C = [sorted(map(int, input().split())) for _ in range(4)] w, i = [0] * (N + 1), N while i: i -= 1 w[i] = w[i + 1] + N - bisect(C, B[i]) print((sum(w[bisect(B, a)] for a in A)))
from bisect import * (N,), A, B, C = [sorted(map(int, input().split())) for _ in [0] * 4] print((sum(bisect_left(A, b) * (N - bisect(C, b)) for b in B)))
false
40
[ "-(N,), A, B, C = [sorted(map(int, input().split())) for _ in range(4)]", "-w, i = [0] * (N + 1), N", "-while i:", "- i -= 1", "- w[i] = w[i + 1] + N - bisect(C, B[i])", "-print((sum(w[bisect(B, a)] for a in A)))", "+(N,), A, B, C = [sorted(map(int, input().split())) for _ in [0] * 4]", "+print((sum(bisect_left(A, b) * (N - bisect(C, b)) for b in B)))" ]
false
0.103691
0.047519
2.182114
[ "s802216252", "s045786574" ]
u201928947
p02768
python
s896015068
s498215386
148
126
3,064
9,188
Accepted
Accepted
14.86
def pow(a,b,c): ans = 1 while b > 0: if b & 1: ans = ans*a % c a = a*a % c b = b >> 1 return ans def cmb(a,b,c): b = min(b,a-b) num = 1 for i in range(b): num = num*(n-i) % c den = 1 for i in range(b): den = den*(i+1) % c return num*pow(den,c-2,c) % c mod = 10**9+7 n,a,b = list(map(int,input().split())) ans = (pow(2,n,mod)-cmb(n,a,mod)-cmb(n,b,mod)-1) % mod if ans < 0: ans = ans + mod print(ans)
def cmb(a,b,c): b = min(b,a-b) num = 1 for i in range(b): num = num*(n-i) % c den = 1 for i in range(b): den = den*(i+1) % c return num*pow(den,-1,c) % c mod = 10**9+7 n,a,b = list(map(int,input().split())) ans = (pow(2,n,mod)-cmb(n,a,mod)-cmb(n,b,mod)-1) % mod if ans < 0: ans = ans + mod print(ans)
23
15
507
353
def pow(a, b, c): ans = 1 while b > 0: if b & 1: ans = ans * a % c a = a * a % c b = b >> 1 return ans def cmb(a, b, c): b = min(b, a - b) num = 1 for i in range(b): num = num * (n - i) % c den = 1 for i in range(b): den = den * (i + 1) % c return num * pow(den, c - 2, c) % c mod = 10**9 + 7 n, a, b = list(map(int, input().split())) ans = (pow(2, n, mod) - cmb(n, a, mod) - cmb(n, b, mod) - 1) % mod if ans < 0: ans = ans + mod print(ans)
def cmb(a, b, c): b = min(b, a - b) num = 1 for i in range(b): num = num * (n - i) % c den = 1 for i in range(b): den = den * (i + 1) % c return num * pow(den, -1, c) % c mod = 10**9 + 7 n, a, b = list(map(int, input().split())) ans = (pow(2, n, mod) - cmb(n, a, mod) - cmb(n, b, mod) - 1) % mod if ans < 0: ans = ans + mod print(ans)
false
34.782609
[ "-def pow(a, b, c):", "- ans = 1", "- while b > 0:", "- if b & 1:", "- ans = ans * a % c", "- a = a * a % c", "- b = b >> 1", "- return ans", "-", "-", "- return num * pow(den, c - 2, c) % c", "+ return num * pow(den, -1, c) % c" ]
false
0.171099
0.221708
0.771731
[ "s896015068", "s498215386" ]
u918601425
p03416
python
s650044684
s487688493
46
17
2,940
3,060
Accepted
Accepted
63.04
def palindromeQ(num): if num%10==num//10000: if (num%100)//10==(num//1000)%10: return(1) else: return(0) else: return(0) ans=0 A,B=[int(s) for s in input().split()] for i in range(A,B+1): ans+=palindromeQ(i) print(ans)
A,B=[int(s) for s in input().split()] a=A//100 b=B//100 def pal(num): return num*101-num%10-(num//100)*99 ans=b-a-1 if pal(a)>=A: ans+=1 if pal(b)<=B: ans+=1 print(ans)
14
12
264
188
def palindromeQ(num): if num % 10 == num // 10000: if (num % 100) // 10 == (num // 1000) % 10: return 1 else: return 0 else: return 0 ans = 0 A, B = [int(s) for s in input().split()] for i in range(A, B + 1): ans += palindromeQ(i) print(ans)
A, B = [int(s) for s in input().split()] a = A // 100 b = B // 100 def pal(num): return num * 101 - num % 10 - (num // 100) * 99 ans = b - a - 1 if pal(a) >= A: ans += 1 if pal(b) <= B: ans += 1 print(ans)
false
14.285714
[ "-def palindromeQ(num):", "- if num % 10 == num // 10000:", "- if (num % 100) // 10 == (num // 1000) % 10:", "- return 1", "- else:", "- return 0", "- else:", "- return 0", "+A, B = [int(s) for s in input().split()]", "+a = A // 100", "+b = B // 100", "-ans = 0", "-A, B = [int(s) for s in input().split()]", "-for i in range(A, B + 1):", "- ans += palindromeQ(i)", "+def pal(num):", "+ return num * 101 - num % 10 - (num // 100) * 99", "+", "+", "+ans = b - a - 1", "+if pal(a) >= A:", "+ ans += 1", "+if pal(b) <= B:", "+ ans += 1" ]
false
0.048218
0.039974
1.206232
[ "s650044684", "s487688493" ]
u415905784
p03816
python
s196520755
s403390873
56
50
11,820
11,196
Accepted
Accepted
10.71
import functools N = int(eval(input())) A = list(map(int, input().split())) d = [0 for i in range(10 ** 5 + 1)] for a in A: d[a] = 1 s = sum(d) print((s - (0 if s % 2 else 1)))
N = int(eval(input())) A = list(map(int, input().split())) d = [0 for i in range(10 ** 5 + 1)] for a in A: d[a] = 1 s = sum(d) print((s - (0 if s % 2 else 1)))
8
7
173
155
import functools N = int(eval(input())) A = list(map(int, input().split())) d = [0 for i in range(10**5 + 1)] for a in A: d[a] = 1 s = sum(d) print((s - (0 if s % 2 else 1)))
N = int(eval(input())) A = list(map(int, input().split())) d = [0 for i in range(10**5 + 1)] for a in A: d[a] = 1 s = sum(d) print((s - (0 if s % 2 else 1)))
false
12.5
[ "-import functools", "-" ]
false
0.04295
0.04366
0.983727
[ "s196520755", "s403390873" ]
u806403461
p03435
python
s169312152
s370898144
362
62
21,640
3,064
Accepted
Accepted
82.87
import numpy as np c = [[0]*3] * 3 for i in range(3): c[i] = list(map(int, input().split())) c = np.array(c) if len(set(c[0] - c[1])) == 1 and len(set(c[1] - c[2])) == 1 and len(set(c[:,0] - c[:,1])) == 1 and len(set(c[:,1] - c[:,2])) == 1: print("Yes") else: print("No")
grid = list() for a in range(3): a, b, c = list(map(int, input().split())) grid.append([a, b, c]) ans = 'No' for a1 in range(0, 101): for a2 in range(0, 101): b1 = grid[0][0] - a1 b2 = grid[1][1] - a2 a3 = grid[2][1] - b2 b3 = grid[2][2] - a3 a_list = [a1, a2, a3] b_list = [b1, b2, b3] count = 0 for x in range(3): for y in range(3): if grid[x][y] == a_list[x] + b_list[y]: count += 1 if count == 9: ans = 'Yes' break print(ans)
15
27
304
611
import numpy as np c = [[0] * 3] * 3 for i in range(3): c[i] = list(map(int, input().split())) c = np.array(c) if ( len(set(c[0] - c[1])) == 1 and len(set(c[1] - c[2])) == 1 and len(set(c[:, 0] - c[:, 1])) == 1 and len(set(c[:, 1] - c[:, 2])) == 1 ): print("Yes") else: print("No")
grid = list() for a in range(3): a, b, c = list(map(int, input().split())) grid.append([a, b, c]) ans = "No" for a1 in range(0, 101): for a2 in range(0, 101): b1 = grid[0][0] - a1 b2 = grid[1][1] - a2 a3 = grid[2][1] - b2 b3 = grid[2][2] - a3 a_list = [a1, a2, a3] b_list = [b1, b2, b3] count = 0 for x in range(3): for y in range(3): if grid[x][y] == a_list[x] + b_list[y]: count += 1 if count == 9: ans = "Yes" break print(ans)
false
44.444444
[ "-import numpy as np", "-", "-c = [[0] * 3] * 3", "-for i in range(3):", "- c[i] = list(map(int, input().split()))", "-c = np.array(c)", "-if (", "- len(set(c[0] - c[1])) == 1", "- and len(set(c[1] - c[2])) == 1", "- and len(set(c[:, 0] - c[:, 1])) == 1", "- and len(set(c[:, 1] - c[:, 2])) == 1", "-):", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+grid = list()", "+for a in range(3):", "+ a, b, c = list(map(int, input().split()))", "+ grid.append([a, b, c])", "+ans = \"No\"", "+for a1 in range(0, 101):", "+ for a2 in range(0, 101):", "+ b1 = grid[0][0] - a1", "+ b2 = grid[1][1] - a2", "+ a3 = grid[2][1] - b2", "+ b3 = grid[2][2] - a3", "+ a_list = [a1, a2, a3]", "+ b_list = [b1, b2, b3]", "+ count = 0", "+ for x in range(3):", "+ for y in range(3):", "+ if grid[x][y] == a_list[x] + b_list[y]:", "+ count += 1", "+ if count == 9:", "+ ans = \"Yes\"", "+ break", "+print(ans)" ]
false
0.420536
0.0802
5.243583
[ "s169312152", "s370898144" ]
u223646582
p02787
python
s259509895
s140623016
837
507
268,808
43,228
Accepted
Accepted
39.43
H, N = list(map(int, input().split())) INF = 10 ** 12 M = [] for i in range(N): A, B = list(map(int, input().split())) M.append((A, B)) dp = [[INF for j in range(H+10**4+1)] for i in range(N+1)] # for i in range(N+1): # dp[0][i] = 0 for i in range(N+1): dp[i][0] = 0 for i in range(1, N+1): # 1<= i <= N # for j in range(1, H+10**4+1): # 1 <= j <= H for j in range(1, H+1): # 1 <= j <= H # print(i, j) if j - M[i-1][0] >= 0: dp[i][j] = min(dp[i-1][j], dp[i-1][j - M[i-1][0]] + M[i-1][1], dp[i][j - M[i-1][0]] + M[i-1][1]) else: dp[i][j] = min(dp[i-1][j], dp[i][0]+M[i-1][1]) # for i in range(N+1): # print(dp[i][H]) # ans = INF # for i in range(H, H+10**4+1): # ans = min(ans, dp[N][i]) # print(ans) print((dp[N][H]))
H, N = list(map(int, input().split())) INF = 10 ** 12 M = [] for i in range(N): A, B = list(map(int, input().split())) M.append((A, B)) dp = [INF for j in range(H+10**4+1)] dp[0] = 0 for i in range(N): for j in range(1, H+10**4+1): if j - M[i][0] >= 0: dp[j] = min(dp[j], dp[j-M[i][0]] + M[i][1]) ans = INF for i in range(10**4+1): ans = min(ans, dp[H+i]) print(ans)
38
20
862
414
H, N = list(map(int, input().split())) INF = 10**12 M = [] for i in range(N): A, B = list(map(int, input().split())) M.append((A, B)) dp = [[INF for j in range(H + 10**4 + 1)] for i in range(N + 1)] # for i in range(N+1): # dp[0][i] = 0 for i in range(N + 1): dp[i][0] = 0 for i in range(1, N + 1): # 1<= i <= N # for j in range(1, H+10**4+1): # 1 <= j <= H for j in range(1, H + 1): # 1 <= j <= H # print(i, j) if j - M[i - 1][0] >= 0: dp[i][j] = min( dp[i - 1][j], dp[i - 1][j - M[i - 1][0]] + M[i - 1][1], dp[i][j - M[i - 1][0]] + M[i - 1][1], ) else: dp[i][j] = min(dp[i - 1][j], dp[i][0] + M[i - 1][1]) # for i in range(N+1): # print(dp[i][H]) # ans = INF # for i in range(H, H+10**4+1): # ans = min(ans, dp[N][i]) # print(ans) print((dp[N][H]))
H, N = list(map(int, input().split())) INF = 10**12 M = [] for i in range(N): A, B = list(map(int, input().split())) M.append((A, B)) dp = [INF for j in range(H + 10**4 + 1)] dp[0] = 0 for i in range(N): for j in range(1, H + 10**4 + 1): if j - M[i][0] >= 0: dp[j] = min(dp[j], dp[j - M[i][0]] + M[i][1]) ans = INF for i in range(10**4 + 1): ans = min(ans, dp[H + i]) print(ans)
false
47.368421
[ "-dp = [[INF for j in range(H + 10**4 + 1)] for i in range(N + 1)]", "-# for i in range(N+1):", "-# dp[0][i] = 0", "-for i in range(N + 1):", "- dp[i][0] = 0", "-for i in range(1, N + 1): # 1<= i <= N", "- # for j in range(1, H+10**4+1): # 1 <= j <= H", "- for j in range(1, H + 1): # 1 <= j <= H", "- # print(i, j)", "- if j - M[i - 1][0] >= 0:", "- dp[i][j] = min(", "- dp[i - 1][j],", "- dp[i - 1][j - M[i - 1][0]] + M[i - 1][1],", "- dp[i][j - M[i - 1][0]] + M[i - 1][1],", "- )", "- else:", "- dp[i][j] = min(dp[i - 1][j], dp[i][0] + M[i - 1][1])", "-# for i in range(N+1):", "-# print(dp[i][H])", "-# ans = INF", "-# for i in range(H, H+10**4+1):", "-# ans = min(ans, dp[N][i])", "-# print(ans)", "-print((dp[N][H]))", "+dp = [INF for j in range(H + 10**4 + 1)]", "+dp[0] = 0", "+for i in range(N):", "+ for j in range(1, H + 10**4 + 1):", "+ if j - M[i][0] >= 0:", "+ dp[j] = min(dp[j], dp[j - M[i][0]] + M[i][1])", "+ans = INF", "+for i in range(10**4 + 1):", "+ ans = min(ans, dp[H + i])", "+print(ans)" ]
false
0.380125
0.280651
1.35444
[ "s259509895", "s140623016" ]
u725391514
p02400
python
s826928322
s097569471
40
20
7,512
7,432
Accepted
Accepted
50
import math r=float(eval(input())) print(('{:.5f} {:.5f}'.format(r*r*math.pi, 2*r*math.pi)))
import math r=float(eval(input())) print(('{:.5f}'.format(r*r*math.pi),'{:.5f}'.format(2*r*math.pi)))
3
3
86
95
import math r = float(eval(input())) print(("{:.5f} {:.5f}".format(r * r * math.pi, 2 * r * math.pi)))
import math r = float(eval(input())) print(("{:.5f}".format(r * r * math.pi), "{:.5f}".format(2 * r * math.pi)))
false
0
[ "-print((\"{:.5f} {:.5f}\".format(r * r * math.pi, 2 * r * math.pi)))", "+print((\"{:.5f}\".format(r * r * math.pi), \"{:.5f}\".format(2 * r * math.pi)))" ]
false
0.046574
0.04282
1.087686
[ "s826928322", "s097569471" ]
u116002573
p03379
python
s629631239
s301086368
355
323
25,556
26,772
Accepted
Accepted
9.01
def main(): N = int(eval(input())) X = [int(x) for x in input().split()] Xsort = sorted(X) for i in range(N): if X[i] <= Xsort[N//2-1]: print((Xsort[N//2])) else: print((Xsort[N//2-1])) if __name__ == '__main__': main()
def main(): N = int(eval(input())) X = list(map(int, input().split())) Y = sorted(X) for i in range(N): if X[i] < Y[N//2]: print((Y[N//2])) else: print((Y[N//2-1])) if __name__ == '__main__': # print(main()) main()
12
14
282
284
def main(): N = int(eval(input())) X = [int(x) for x in input().split()] Xsort = sorted(X) for i in range(N): if X[i] <= Xsort[N // 2 - 1]: print((Xsort[N // 2])) else: print((Xsort[N // 2 - 1])) if __name__ == "__main__": main()
def main(): N = int(eval(input())) X = list(map(int, input().split())) Y = sorted(X) for i in range(N): if X[i] < Y[N // 2]: print((Y[N // 2])) else: print((Y[N // 2 - 1])) if __name__ == "__main__": # print(main()) main()
false
14.285714
[ "- X = [int(x) for x in input().split()]", "- Xsort = sorted(X)", "+ X = list(map(int, input().split()))", "+ Y = sorted(X)", "- if X[i] <= Xsort[N // 2 - 1]:", "- print((Xsort[N // 2]))", "+ if X[i] < Y[N // 2]:", "+ print((Y[N // 2]))", "- print((Xsort[N // 2 - 1]))", "+ print((Y[N // 2 - 1]))", "+ # print(main())" ]
false
0.047457
0.044727
1.06104
[ "s629631239", "s301086368" ]
u893063840
p03108
python
s217098976
s431906238
1,054
880
40,940
38,132
Accepted
Accepted
16.51
n, m = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(m)] class UnionFind: def __init__(self, n): self.n = n self.p = [e for e in range(n)] self.rank = [0] * n self.size = [1] * n def same(self, u, v): return self.find_set(u) == self.find_set(v) def unite(self, u, v): self.link(self.find_set(u), self.find_set(v)) def find_set(self, u): if u != self.p[u]: self.p[u] = self.find_set(self.p[u]) return self.p[u] def link(self, u, v): if self.rank[u] > self.rank[v]: self.p[v] = u self.size[u] += self.size[v] else: self.p[u] = v self.size[v] += self.size[u] if self.rank[u] == self.rank[v]: self.rank[v] += 1 def update_p(self): for u in range(self.n): self.find_set(u) def get_size(self, u): return self.size[self.find_set(u)] def comb(self, u): sz = self.get_size(u) return sz * (sz - 1) // 2 uf = UnionFind(n) ans = [0] sm = 0 for a, b in ab[-1:0:-1]: a -= 1 b -= 1 if not uf.same(a, b): sm -= uf.comb(a) + uf.comb(b) uf.unite(a, b) sm += uf.comb(a) ans.append(sm) ans = [n * (n - 1) // 2 - e for e in ans[::-1]] print(*ans, sep="\n")
n, m = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(m)] class UnionFind: def __init__(self, n): self.n = n self.p = [e for e in range(n)] self.rank = [0] * n self.size = [1] * n def same(self, u, v): return self.find_set(u) == self.find_set(v) def unite(self, u, v): self.link(self.find_set(u), self.find_set(v)) def find_set(self, u): if u != self.p[u]: self.p[u] = self.find_set(self.p[u]) return self.p[u] def link(self, u, v): if self.rank[u] > self.rank[v]: self.p[v] = u self.size[u] += self.size[v] else: self.p[u] = v self.size[v] += self.size[u] if self.rank[u] == self.rank[v]: self.rank[v] += 1 def update_p(self): for u in range(self.n): self.find_set(u) def get_size(self, u): return self.size[self.find_set(u)] uf = UnionFind(n) sm = n * (n - 1) // 2 ans = [sm] for a, b in ab[-1:0:-1]: a -= 1 b -= 1 if not uf.same(a, b): sm -= uf.get_size(a) * uf.get_size(b) uf.unite(a, b) ans.append(sm) print(*ans[::-1], sep="\n")
60
54
1,426
1,289
n, m = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(m)] class UnionFind: def __init__(self, n): self.n = n self.p = [e for e in range(n)] self.rank = [0] * n self.size = [1] * n def same(self, u, v): return self.find_set(u) == self.find_set(v) def unite(self, u, v): self.link(self.find_set(u), self.find_set(v)) def find_set(self, u): if u != self.p[u]: self.p[u] = self.find_set(self.p[u]) return self.p[u] def link(self, u, v): if self.rank[u] > self.rank[v]: self.p[v] = u self.size[u] += self.size[v] else: self.p[u] = v self.size[v] += self.size[u] if self.rank[u] == self.rank[v]: self.rank[v] += 1 def update_p(self): for u in range(self.n): self.find_set(u) def get_size(self, u): return self.size[self.find_set(u)] def comb(self, u): sz = self.get_size(u) return sz * (sz - 1) // 2 uf = UnionFind(n) ans = [0] sm = 0 for a, b in ab[-1:0:-1]: a -= 1 b -= 1 if not uf.same(a, b): sm -= uf.comb(a) + uf.comb(b) uf.unite(a, b) sm += uf.comb(a) ans.append(sm) ans = [n * (n - 1) // 2 - e for e in ans[::-1]] print(*ans, sep="\n")
n, m = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(m)] class UnionFind: def __init__(self, n): self.n = n self.p = [e for e in range(n)] self.rank = [0] * n self.size = [1] * n def same(self, u, v): return self.find_set(u) == self.find_set(v) def unite(self, u, v): self.link(self.find_set(u), self.find_set(v)) def find_set(self, u): if u != self.p[u]: self.p[u] = self.find_set(self.p[u]) return self.p[u] def link(self, u, v): if self.rank[u] > self.rank[v]: self.p[v] = u self.size[u] += self.size[v] else: self.p[u] = v self.size[v] += self.size[u] if self.rank[u] == self.rank[v]: self.rank[v] += 1 def update_p(self): for u in range(self.n): self.find_set(u) def get_size(self, u): return self.size[self.find_set(u)] uf = UnionFind(n) sm = n * (n - 1) // 2 ans = [sm] for a, b in ab[-1:0:-1]: a -= 1 b -= 1 if not uf.same(a, b): sm -= uf.get_size(a) * uf.get_size(b) uf.unite(a, b) ans.append(sm) print(*ans[::-1], sep="\n")
false
10
[ "- def comb(self, u):", "- sz = self.get_size(u)", "- return sz * (sz - 1) // 2", "-", "-ans = [0]", "-sm = 0", "+sm = n * (n - 1) // 2", "+ans = [sm]", "- sm -= uf.comb(a) + uf.comb(b)", "+ sm -= uf.get_size(a) * uf.get_size(b)", "- sm += uf.comb(a)", "-ans = [n * (n - 1) // 2 - e for e in ans[::-1]]", "-print(*ans, sep=\"\\n\")", "+print(*ans[::-1], sep=\"\\n\")" ]
false
0.096691
0.040106
2.410861
[ "s217098976", "s431906238" ]
u606878291
p02669
python
s501672795
s374273875
360
244
27,600
20,540
Accepted
Accepted
32.22
import math from functools import lru_cache T = int(eval(input())) class Resolver: def __init__(self, a, b, c, d): self.a = a self.b = b self.c = c self.d = d @lru_cache(maxsize=None) def resolve(self, n): if n == 0: return 0 elif n == 1: return self.d else: div5f = n // 5 div5c = (n + 4) // 5 div3f = n // 3 div3c = (n + 2) // 3 div2f = n // 2 div2c = (n + 1) // 2 return min( self.d * n, self.d * abs(n - div5f * 5) + self.c + self.resolve(div5f), self.d * abs(n - div5c * 5) + self.c + self.resolve(div5c), self.d * abs(n - div3f * 3) + self.b + self.resolve(div3f), self.d * abs(n - div3c * 3) + self.b + self.resolve(div3c), self.d * abs(n - div2f * 2) + self.a + self.resolve(div2f), self.d * abs(n - div2c * 2) + self.a + self.resolve(div2c), ) for _ in range(T): N, A, B, C, D = list(map(int, input().split(' '))) resolver = Resolver(A, B, C, D) print((resolver.resolve(N)))
from functools import lru_cache T = int(eval(input())) def resolver(a, b, c, d): @lru_cache(maxsize=None) def _resolver(n): if n == 0: return 0 elif n == 1: return d else: div5f = n // 5 div5c = (n + 4) // 5 div3f = n // 3 div3c = (n + 2) // 3 div2f = n // 2 div2c = (n + 1) // 2 return min( d * n, d * abs(n - div5f * 5) + c + _resolver(div5f), d * abs(n - div5c * 5) + c + _resolver(div5c), d * abs(n - div3f * 3) + b + _resolver(div3f), d * abs(n - div3c * 3) + b + _resolver(div3c), d * abs(n - div2f * 2) + a + _resolver(div2f), d * abs(n - div2c * 2) + a + _resolver(div2c), ) return _resolver for _ in range(T): N, A, B, C, D = list(map(int, input().split(' '))) print((resolver(A, B, C, D)(N)))
41
35
1,228
1,005
import math from functools import lru_cache T = int(eval(input())) class Resolver: def __init__(self, a, b, c, d): self.a = a self.b = b self.c = c self.d = d @lru_cache(maxsize=None) def resolve(self, n): if n == 0: return 0 elif n == 1: return self.d else: div5f = n // 5 div5c = (n + 4) // 5 div3f = n // 3 div3c = (n + 2) // 3 div2f = n // 2 div2c = (n + 1) // 2 return min( self.d * n, self.d * abs(n - div5f * 5) + self.c + self.resolve(div5f), self.d * abs(n - div5c * 5) + self.c + self.resolve(div5c), self.d * abs(n - div3f * 3) + self.b + self.resolve(div3f), self.d * abs(n - div3c * 3) + self.b + self.resolve(div3c), self.d * abs(n - div2f * 2) + self.a + self.resolve(div2f), self.d * abs(n - div2c * 2) + self.a + self.resolve(div2c), ) for _ in range(T): N, A, B, C, D = list(map(int, input().split(" "))) resolver = Resolver(A, B, C, D) print((resolver.resolve(N)))
from functools import lru_cache T = int(eval(input())) def resolver(a, b, c, d): @lru_cache(maxsize=None) def _resolver(n): if n == 0: return 0 elif n == 1: return d else: div5f = n // 5 div5c = (n + 4) // 5 div3f = n // 3 div3c = (n + 2) // 3 div2f = n // 2 div2c = (n + 1) // 2 return min( d * n, d * abs(n - div5f * 5) + c + _resolver(div5f), d * abs(n - div5c * 5) + c + _resolver(div5c), d * abs(n - div3f * 3) + b + _resolver(div3f), d * abs(n - div3c * 3) + b + _resolver(div3c), d * abs(n - div2f * 2) + a + _resolver(div2f), d * abs(n - div2c * 2) + a + _resolver(div2c), ) return _resolver for _ in range(T): N, A, B, C, D = list(map(int, input().split(" "))) print((resolver(A, B, C, D)(N)))
false
14.634146
[ "-import math", "-class Resolver:", "- def __init__(self, a, b, c, d):", "- self.a = a", "- self.b = b", "- self.c = c", "- self.d = d", "-", "+def resolver(a, b, c, d):", "- def resolve(self, n):", "+ def _resolver(n):", "- return self.d", "+ return d", "- self.d * n,", "- self.d * abs(n - div5f * 5) + self.c + self.resolve(div5f),", "- self.d * abs(n - div5c * 5) + self.c + self.resolve(div5c),", "- self.d * abs(n - div3f * 3) + self.b + self.resolve(div3f),", "- self.d * abs(n - div3c * 3) + self.b + self.resolve(div3c),", "- self.d * abs(n - div2f * 2) + self.a + self.resolve(div2f),", "- self.d * abs(n - div2c * 2) + self.a + self.resolve(div2c),", "+ d * n,", "+ d * abs(n - div5f * 5) + c + _resolver(div5f),", "+ d * abs(n - div5c * 5) + c + _resolver(div5c),", "+ d * abs(n - div3f * 3) + b + _resolver(div3f),", "+ d * abs(n - div3c * 3) + b + _resolver(div3c),", "+ d * abs(n - div2f * 2) + a + _resolver(div2f),", "+ d * abs(n - div2c * 2) + a + _resolver(div2c),", "+", "+ return _resolver", "- resolver = Resolver(A, B, C, D)", "- print((resolver.resolve(N)))", "+ print((resolver(A, B, C, D)(N)))" ]
false
0.422926
0.213066
1.984952
[ "s501672795", "s374273875" ]
u186838327
p03030
python
s164572107
s145025586
182
74
38,384
62,852
Accepted
Accepted
59.34
n = int(eval(input())) X = [] for i in range(n): s, p = list(map(str, input().split())) p = int(p) X.append((s, p, i+1)) X.sort(key= lambda x: (x[0], -x[1])) for s, p, i in X: print(i)
n = int(eval(input())) SP = [] for i in range(n): s, p = list(map(str, input().split())) p = int(p) SP.append((s, p, i+1)) SP.sort(key=lambda x: (x[0], -x[1])) for s, p, j in SP: print(j)
10
9
199
200
n = int(eval(input())) X = [] for i in range(n): s, p = list(map(str, input().split())) p = int(p) X.append((s, p, i + 1)) X.sort(key=lambda x: (x[0], -x[1])) for s, p, i in X: print(i)
n = int(eval(input())) SP = [] for i in range(n): s, p = list(map(str, input().split())) p = int(p) SP.append((s, p, i + 1)) SP.sort(key=lambda x: (x[0], -x[1])) for s, p, j in SP: print(j)
false
10
[ "-X = []", "+SP = []", "- X.append((s, p, i + 1))", "-X.sort(key=lambda x: (x[0], -x[1]))", "-for s, p, i in X:", "- print(i)", "+ SP.append((s, p, i + 1))", "+SP.sort(key=lambda x: (x[0], -x[1]))", "+for s, p, j in SP:", "+ print(j)" ]
false
0.130094
0.076625
1.69779
[ "s164572107", "s145025586" ]
u609061751
p02703
python
s147526832
s287267533
1,542
1,420
188,732
180,136
Accepted
Accepted
7.91
import sys input = lambda: sys.stdin.readline().rstrip() n, m, s = list(map(int, input().split())) s = min(s, 2500) from collections import defaultdict # O(ElogV) import heapq def dijkstra(s, x): # 始点sから各頂点への最短距離 d = defaultdict(lambda: float("inf")) d[(s, x)] = 0 # 各頂点が訪問済みかどうか used = defaultdict(lambda: False) used[(s, x)] = True # 仮の距離を記録するヒープ que = [] for e in edge[(s, x)]: heapq.heappush(que, e) while que: minedge = heapq.heappop(que) if used[minedge[1]]: continue v = minedge[1] d[v] = minedge[0] used[v] = True for e in edge[v]: if not used[e[1]]: heapq.heappush(que, (e[0] + d[v], e[1])) return d max_money = 2500 edge = defaultdict(list) for _ in range(m): u, v, a, b = list(map(int, input().split())) u -= 1 v -= 1 for i in range(a, max_money + 1): edge[(u, i)].append((b, (v, i - a))) edge[(v, i)].append((b, (u, i - a))) for j in range(n): c, d = list(map(int, input().split())) for i in range(max_money): if i + c <= max_money: edge[(j, i)].append((d, (j, i + c))) ans = [10**18]*n d = dijkstra(0, s) for i in d: x, y = i cost = d[i] ans[x] = min(ans[x], cost) for i in ans[1:]: print(i)
def main(): import sys input = lambda: sys.stdin.readline().rstrip() n, m, s = list(map(int, input().split())) s = min(s, 2500) from collections import defaultdict # O(ElogV) import heapq def dijkstra(s, x): # 始点sから各頂点への最短距離 d = defaultdict(lambda: float("inf")) d[(s, x)] = 0 # 各頂点が訪問済みかどうか used = defaultdict(lambda: False) used[(s, x)] = True # 仮の距離を記録するヒープ que = [] for e in edge[(s, x)]: heapq.heappush(que, e) while que: minedge = heapq.heappop(que) if used[minedge[1]]: continue v = minedge[1] d[v] = minedge[0] used[v] = True for e in edge[v]: if not used[e[1]]: heapq.heappush(que, (e[0] + d[v], e[1])) return d max_money = 2500 edge = defaultdict(list) for _ in range(m): u, v, a, b = list(map(int, input().split())) u -= 1 v -= 1 for i in range(a, max_money + 1): edge[(u, i)].append((b, (v, i - a))) edge[(v, i)].append((b, (u, i - a))) for j in range(n): c, d = list(map(int, input().split())) for i in range(max_money): if i + c <= max_money: edge[(j, i)].append((d, (j, i + c))) ans = [10**18]*n d = dijkstra(0, s) for i in d: x, y = i cost = d[i] ans[x] = min(ans[x], cost) for i in ans[1:]: print(i) main()
55
57
1,361
1,586
import sys input = lambda: sys.stdin.readline().rstrip() n, m, s = list(map(int, input().split())) s = min(s, 2500) from collections import defaultdict # O(ElogV) import heapq def dijkstra(s, x): # 始点sから各頂点への最短距離 d = defaultdict(lambda: float("inf")) d[(s, x)] = 0 # 各頂点が訪問済みかどうか used = defaultdict(lambda: False) used[(s, x)] = True # 仮の距離を記録するヒープ que = [] for e in edge[(s, x)]: heapq.heappush(que, e) while que: minedge = heapq.heappop(que) if used[minedge[1]]: continue v = minedge[1] d[v] = minedge[0] used[v] = True for e in edge[v]: if not used[e[1]]: heapq.heappush(que, (e[0] + d[v], e[1])) return d max_money = 2500 edge = defaultdict(list) for _ in range(m): u, v, a, b = list(map(int, input().split())) u -= 1 v -= 1 for i in range(a, max_money + 1): edge[(u, i)].append((b, (v, i - a))) edge[(v, i)].append((b, (u, i - a))) for j in range(n): c, d = list(map(int, input().split())) for i in range(max_money): if i + c <= max_money: edge[(j, i)].append((d, (j, i + c))) ans = [10**18] * n d = dijkstra(0, s) for i in d: x, y = i cost = d[i] ans[x] = min(ans[x], cost) for i in ans[1:]: print(i)
def main(): import sys input = lambda: sys.stdin.readline().rstrip() n, m, s = list(map(int, input().split())) s = min(s, 2500) from collections import defaultdict # O(ElogV) import heapq def dijkstra(s, x): # 始点sから各頂点への最短距離 d = defaultdict(lambda: float("inf")) d[(s, x)] = 0 # 各頂点が訪問済みかどうか used = defaultdict(lambda: False) used[(s, x)] = True # 仮の距離を記録するヒープ que = [] for e in edge[(s, x)]: heapq.heappush(que, e) while que: minedge = heapq.heappop(que) if used[minedge[1]]: continue v = minedge[1] d[v] = minedge[0] used[v] = True for e in edge[v]: if not used[e[1]]: heapq.heappush(que, (e[0] + d[v], e[1])) return d max_money = 2500 edge = defaultdict(list) for _ in range(m): u, v, a, b = list(map(int, input().split())) u -= 1 v -= 1 for i in range(a, max_money + 1): edge[(u, i)].append((b, (v, i - a))) edge[(v, i)].append((b, (u, i - a))) for j in range(n): c, d = list(map(int, input().split())) for i in range(max_money): if i + c <= max_money: edge[(j, i)].append((d, (j, i + c))) ans = [10**18] * n d = dijkstra(0, s) for i in d: x, y = i cost = d[i] ans[x] = min(ans[x], cost) for i in ans[1:]: print(i) main()
false
3.508772
[ "-import sys", "+def main():", "+ import sys", "-input = lambda: sys.stdin.readline().rstrip()", "-n, m, s = list(map(int, input().split()))", "-s = min(s, 2500)", "-from collections import defaultdict", "+ input = lambda: sys.stdin.readline().rstrip()", "+ n, m, s = list(map(int, input().split()))", "+ s = min(s, 2500)", "+ from collections import defaultdict", "-# O(ElogV)", "-import heapq", "+ # O(ElogV)", "+ import heapq", "+", "+ def dijkstra(s, x):", "+ # 始点sから各頂点への最短距離", "+ d = defaultdict(lambda: float(\"inf\"))", "+ d[(s, x)] = 0", "+ # 各頂点が訪問済みかどうか", "+ used = defaultdict(lambda: False)", "+ used[(s, x)] = True", "+ # 仮の距離を記録するヒープ", "+ que = []", "+ for e in edge[(s, x)]:", "+ heapq.heappush(que, e)", "+ while que:", "+ minedge = heapq.heappop(que)", "+ if used[minedge[1]]:", "+ continue", "+ v = minedge[1]", "+ d[v] = minedge[0]", "+ used[v] = True", "+ for e in edge[v]:", "+ if not used[e[1]]:", "+ heapq.heappush(que, (e[0] + d[v], e[1]))", "+ return d", "+", "+ max_money = 2500", "+ edge = defaultdict(list)", "+ for _ in range(m):", "+ u, v, a, b = list(map(int, input().split()))", "+ u -= 1", "+ v -= 1", "+ for i in range(a, max_money + 1):", "+ edge[(u, i)].append((b, (v, i - a)))", "+ edge[(v, i)].append((b, (u, i - a)))", "+ for j in range(n):", "+ c, d = list(map(int, input().split()))", "+ for i in range(max_money):", "+ if i + c <= max_money:", "+ edge[(j, i)].append((d, (j, i + c)))", "+ ans = [10**18] * n", "+ d = dijkstra(0, s)", "+ for i in d:", "+ x, y = i", "+ cost = d[i]", "+ ans[x] = min(ans[x], cost)", "+ for i in ans[1:]:", "+ print(i)", "-def dijkstra(s, x):", "- # 始点sから各頂点への最短距離", "- d = defaultdict(lambda: float(\"inf\"))", "- d[(s, x)] = 0", "- # 各頂点が訪問済みかどうか", "- used = defaultdict(lambda: False)", "- used[(s, x)] = True", "- # 仮の距離を記録するヒープ", "- que = []", "- for e in edge[(s, x)]:", "- heapq.heappush(que, e)", "- while que:", "- minedge = heapq.heappop(que)", "- if used[minedge[1]]:", "- continue", "- v = minedge[1]", "- d[v] = minedge[0]", "- used[v] = True", "- for e in edge[v]:", "- if not used[e[1]]:", "- heapq.heappush(que, (e[0] + d[v], e[1]))", "- return d", "-", "-", "-max_money = 2500", "-edge = defaultdict(list)", "-for _ in range(m):", "- u, v, a, b = list(map(int, input().split()))", "- u -= 1", "- v -= 1", "- for i in range(a, max_money + 1):", "- edge[(u, i)].append((b, (v, i - a)))", "- edge[(v, i)].append((b, (u, i - a)))", "-for j in range(n):", "- c, d = list(map(int, input().split()))", "- for i in range(max_money):", "- if i + c <= max_money:", "- edge[(j, i)].append((d, (j, i + c)))", "-ans = [10**18] * n", "-d = dijkstra(0, s)", "-for i in d:", "- x, y = i", "- cost = d[i]", "- ans[x] = min(ans[x], cost)", "-for i in ans[1:]:", "- print(i)", "+main()" ]
false
0.282722
0.142794
1.979933
[ "s147526832", "s287267533" ]
u746419473
p03161
python
s722669323
s700421358
1,883
539
13,980
58,336
Accepted
Accepted
71.38
n, k = list(map(int, input().split())) *h, = list(map(int, input().split())) dp = [float("inf")]*(n+1) dp[0] = 0 for i in range(1, n): if i < k: dp[i] = min([dpj+abs(hj-h[i]) for dpj, hj in zip(dp[:i], h[:i])]) else: dp[i] = min([dpj+abs(hj-h[i]) for dpj, hj in zip(dp[i-k:i], h[i-k:i])]) print((dp[n-1]))
n, k = list(map(int, input().split())) *h, = list(map(int, input().split())) dp = [float("inf")]*n dp[0] = 0 for i in range(1, n): if i == 1: dp[1] = dp[0] + abs(h[0]-h[1]) continue dp[i] = min([dp[i-j] + abs(h[i-j]-h[i]) for j in range(1, k+1)]) print((dp[n-1]))
13
14
331
291
n, k = list(map(int, input().split())) (*h,) = list(map(int, input().split())) dp = [float("inf")] * (n + 1) dp[0] = 0 for i in range(1, n): if i < k: dp[i] = min([dpj + abs(hj - h[i]) for dpj, hj in zip(dp[:i], h[:i])]) else: dp[i] = min( [dpj + abs(hj - h[i]) for dpj, hj in zip(dp[i - k : i], h[i - k : i])] ) print((dp[n - 1]))
n, k = list(map(int, input().split())) (*h,) = list(map(int, input().split())) dp = [float("inf")] * n dp[0] = 0 for i in range(1, n): if i == 1: dp[1] = dp[0] + abs(h[0] - h[1]) continue dp[i] = min([dp[i - j] + abs(h[i - j] - h[i]) for j in range(1, k + 1)]) print((dp[n - 1]))
false
7.142857
[ "-dp = [float(\"inf\")] * (n + 1)", "+dp = [float(\"inf\")] * n", "- if i < k:", "- dp[i] = min([dpj + abs(hj - h[i]) for dpj, hj in zip(dp[:i], h[:i])])", "- else:", "- dp[i] = min(", "- [dpj + abs(hj - h[i]) for dpj, hj in zip(dp[i - k : i], h[i - k : i])]", "- )", "+ if i == 1:", "+ dp[1] = dp[0] + abs(h[0] - h[1])", "+ continue", "+ dp[i] = min([dp[i - j] + abs(h[i - j] - h[i]) for j in range(1, k + 1)])" ]
false
0.039796
0.042446
0.937577
[ "s722669323", "s700421358" ]
u463864151
p02678
python
s099404526
s492816189
983
860
34,528
34,668
Accepted
Accepted
12.51
# -*- coding: utf-8 -*- """ @author: H_Hoshigi """ import queue def main(): N, M = list(map(int, input().split())) connedted_room_list = [ [] for i in range(N)] # ここでNとMを書き間違えていた。 for i in range(M): A, B = list(map(int, input().split())) connedted_room_list[A-1].append(B-1) connedted_room_list[B-1].append(A-1) answer_list = [ -1 for i in range(N)] answer_list[0] = 0 next_rooms_queue = queue.Queue() next_rooms_queue.put(0) now_room = int() while not next_rooms_queue.empty(): now_room = next_rooms_queue.get() for i in connedted_room_list[now_room]: if answer_list[i] == -1: answer_list[i] = now_room next_rooms_queue.put(i) is_escapable = True for i in range(1, N): if answer_list[i] == -1: is_escapable = False break if is_escapable: print("Yes") for i in range(1, N): print((answer_list[i]+1)) else: print("No") if __name__ == "__main__": main()
# -*- coding: utf-8 -*- """ @author: H_Hoshigi """ import queue def main(): N, M = list(map(int, input().split())) connedted_room_list = [ [] for i in range(N)] # ここでNとMを書き間違えていた。 for i in range(M): A, B = list(map(int, input().split())) connedted_room_list[A-1].append(B-1) connedted_room_list[B-1].append(A-1) answer_list = [ -1 for i in range(N)] answer_list[0] = 0 next_rooms_queue = queue.Queue() next_rooms_queue.put(0) now_room = int() while not next_rooms_queue.empty(): now_room = next_rooms_queue.get() for i in connedted_room_list[now_room]: if answer_list[i] == -1: answer_list[i] = now_room next_rooms_queue.put(i) is_escapable = True ''' for i in range(1, N): if answer_list[i] == -1: is_escapable = False break ''' if is_escapable: print("Yes") for i in range(1, N): print((answer_list[i]+1)) else: print("No") if __name__ == "__main__": main()
47
49
1,107
1,125
# -*- coding: utf-8 -*- """ @author: H_Hoshigi """ import queue def main(): N, M = list(map(int, input().split())) connedted_room_list = [[] for i in range(N)] # ここでNとMを書き間違えていた。 for i in range(M): A, B = list(map(int, input().split())) connedted_room_list[A - 1].append(B - 1) connedted_room_list[B - 1].append(A - 1) answer_list = [-1 for i in range(N)] answer_list[0] = 0 next_rooms_queue = queue.Queue() next_rooms_queue.put(0) now_room = int() while not next_rooms_queue.empty(): now_room = next_rooms_queue.get() for i in connedted_room_list[now_room]: if answer_list[i] == -1: answer_list[i] = now_room next_rooms_queue.put(i) is_escapable = True for i in range(1, N): if answer_list[i] == -1: is_escapable = False break if is_escapable: print("Yes") for i in range(1, N): print((answer_list[i] + 1)) else: print("No") if __name__ == "__main__": main()
# -*- coding: utf-8 -*- """ @author: H_Hoshigi """ import queue def main(): N, M = list(map(int, input().split())) connedted_room_list = [[] for i in range(N)] # ここでNとMを書き間違えていた。 for i in range(M): A, B = list(map(int, input().split())) connedted_room_list[A - 1].append(B - 1) connedted_room_list[B - 1].append(A - 1) answer_list = [-1 for i in range(N)] answer_list[0] = 0 next_rooms_queue = queue.Queue() next_rooms_queue.put(0) now_room = int() while not next_rooms_queue.empty(): now_room = next_rooms_queue.get() for i in connedted_room_list[now_room]: if answer_list[i] == -1: answer_list[i] = now_room next_rooms_queue.put(i) is_escapable = True """ for i in range(1, N): if answer_list[i] == -1: is_escapable = False break """ if is_escapable: print("Yes") for i in range(1, N): print((answer_list[i] + 1)) else: print("No") if __name__ == "__main__": main()
false
4.081633
[ "+ \"\"\"", "+ \"\"\"" ]
false
0.13235
0.033818
3.913573
[ "s099404526", "s492816189" ]
u729133443
p02555
python
s358073366
s861436631
85
52
77,736
22,236
Accepted
Accepted
38.82
a,b,c=1,0,0 exec('a,b,c=b,c,a+c;'*int(eval(input()))) print((a%(10**9+7)))
a=1 b=c=0 exec('a,b,c=b,c,a+c;'*int(eval(input()))) print((a%(10**9+7)))
3
4
68
67
a, b, c = 1, 0, 0 exec("a,b,c=b,c,a+c;" * int(eval(input()))) print((a % (10**9 + 7)))
a = 1 b = c = 0 exec("a,b,c=b,c,a+c;" * int(eval(input()))) print((a % (10**9 + 7)))
false
25
[ "-a, b, c = 1, 0, 0", "+a = 1", "+b = c = 0" ]
false
0.040899
0.086333
0.47373
[ "s358073366", "s861436631" ]
u934442292
p03163
python
s172560613
s573231018
1,195
727
192,500
189,884
Accepted
Accepted
39.16
import sys import numba as nb import numpy as np input = sys.stdin.readline @nb.njit("i8(i8, i8)") def chmax(a, b): if a > b: return a else: return b @nb.njit("i8(i8,i8,i8[:,:])") def solve(N, W, wv): dp = [[0] * (W + 1) for _ in range(N + 1)] for i in range(1, N + 1): w, v = wv[i - 1] for j in range(1, W + 1): if j < w: dp[i][j] = dp[i - 1][j] else: dp[i][j] = chmax(dp[i - 1][j - w] + v, dp[i - 1][j]) return dp[-1][-1] def main(): N, W = list(map(int, input().split())) wv = np.zeros(shape=(N, 2), dtype=np.int64) for i in range(N): w, v = list(map(int, input().split())) wv[i] = w, v ans = solve(N, W, wv) print(ans) if __name__ == "__main__": main()
import sys import numba as nb import numpy as np input = sys.stdin.readline @nb.njit("i8(i8, i8)") def chmax(a, b): if a > b: return a else: return b @nb.njit("i8(i8,i8,i8[:,:])") def solve(N, W, wv): dp = np.zeros(shape=(N + 1, W + 1), dtype=np.int64) for i in range(1, N + 1): w, v = wv[i - 1] for j in range(1, W + 1): if j < w: dp[i, j] = dp[i - 1, j] else: dp[i, j] = chmax(dp[i - 1, j - w] + v, dp[i - 1, j]) return dp[-1, -1] def main(): N, W = list(map(int, input().split())) wv = np.zeros(shape=(N, 2), dtype=np.int64) for i in range(N): w, v = list(map(int, input().split())) wv[i] = w, v ans = solve(N, W, wv) print(ans) if __name__ == "__main__": main()
42
42
845
854
import sys import numba as nb import numpy as np input = sys.stdin.readline @nb.njit("i8(i8, i8)") def chmax(a, b): if a > b: return a else: return b @nb.njit("i8(i8,i8,i8[:,:])") def solve(N, W, wv): dp = [[0] * (W + 1) for _ in range(N + 1)] for i in range(1, N + 1): w, v = wv[i - 1] for j in range(1, W + 1): if j < w: dp[i][j] = dp[i - 1][j] else: dp[i][j] = chmax(dp[i - 1][j - w] + v, dp[i - 1][j]) return dp[-1][-1] def main(): N, W = list(map(int, input().split())) wv = np.zeros(shape=(N, 2), dtype=np.int64) for i in range(N): w, v = list(map(int, input().split())) wv[i] = w, v ans = solve(N, W, wv) print(ans) if __name__ == "__main__": main()
import sys import numba as nb import numpy as np input = sys.stdin.readline @nb.njit("i8(i8, i8)") def chmax(a, b): if a > b: return a else: return b @nb.njit("i8(i8,i8,i8[:,:])") def solve(N, W, wv): dp = np.zeros(shape=(N + 1, W + 1), dtype=np.int64) for i in range(1, N + 1): w, v = wv[i - 1] for j in range(1, W + 1): if j < w: dp[i, j] = dp[i - 1, j] else: dp[i, j] = chmax(dp[i - 1, j - w] + v, dp[i - 1, j]) return dp[-1, -1] def main(): N, W = list(map(int, input().split())) wv = np.zeros(shape=(N, 2), dtype=np.int64) for i in range(N): w, v = list(map(int, input().split())) wv[i] = w, v ans = solve(N, W, wv) print(ans) if __name__ == "__main__": main()
false
0
[ "- dp = [[0] * (W + 1) for _ in range(N + 1)]", "+ dp = np.zeros(shape=(N + 1, W + 1), dtype=np.int64)", "- dp[i][j] = dp[i - 1][j]", "+ dp[i, j] = dp[i - 1, j]", "- dp[i][j] = chmax(dp[i - 1][j - w] + v, dp[i - 1][j])", "- return dp[-1][-1]", "+ dp[i, j] = chmax(dp[i - 1, j - w] + v, dp[i - 1, j])", "+ return dp[-1, -1]" ]
false
0.132809
0.168341
0.788929
[ "s172560613", "s573231018" ]
u631277801
p03363
python
s318638287
s868597014
197
168
41,728
41,728
Accepted
Accepted
14.72
from collections import Counter from itertools import accumulate n = int(eval(input())) a = list(map(int, input().split())) a_cum = list(accumulate(a)) cnt = Counter(a_cum) ans = 0 for k, v in list(cnt.items()): if k == 0: ans += v + v*(v-1) // 2 elif v > 0: ans += v*(v-1) // 2 print(ans)
from collections import Counter from itertools import accumulate n = int(eval(input())) a = list(map(int, input().split())) cnt = Counter(list(accumulate(a))) ans = 0 for k,v in list(cnt.items()): if k == 0: ans += v ans += v*(v-1)//2 print(ans)
17
14
329
265
from collections import Counter from itertools import accumulate n = int(eval(input())) a = list(map(int, input().split())) a_cum = list(accumulate(a)) cnt = Counter(a_cum) ans = 0 for k, v in list(cnt.items()): if k == 0: ans += v + v * (v - 1) // 2 elif v > 0: ans += v * (v - 1) // 2 print(ans)
from collections import Counter from itertools import accumulate n = int(eval(input())) a = list(map(int, input().split())) cnt = Counter(list(accumulate(a))) ans = 0 for k, v in list(cnt.items()): if k == 0: ans += v ans += v * (v - 1) // 2 print(ans)
false
17.647059
[ "-a_cum = list(accumulate(a))", "-cnt = Counter(a_cum)", "+cnt = Counter(list(accumulate(a)))", "- ans += v + v * (v - 1) // 2", "- elif v > 0:", "- ans += v * (v - 1) // 2", "+ ans += v", "+ ans += v * (v - 1) // 2" ]
false
0.037685
0.037634
1.001341
[ "s318638287", "s868597014" ]
u374531474
p02804
python
s014570697
s397530708
831
168
14,040
14,040
Accepted
Accepted
79.78
N, K = list(map(int, input().split())) A = list(map(int, input().split())) MOD = 10 ** 9 + 7 def mpow(x, t): if t == 0: return 1 a = mpow(x, t >> 1) return a * a * (x ** (t & 1)) % MOD A.sort() ans = 0 C = 1 for i in range(K, N + 1): ans += (A[i - 1] - A[N - i]) * C ans %= MOD C = C * i * mpow(i - K + 1, MOD - 2) C %= MOD print(ans)
N, K = list(map(int, input().split())) A = list(map(int, input().split())) MOD = 10 ** 9 + 7 inv_t = [0, 1] + [0] * (N - 1) for i in range(2, N + 1): inv_t[i] = inv_t[MOD % i] * (MOD - MOD // i) % MOD A.sort() ans = 0 C = 1 for i in range(K, N + 1): ans += (A[i - 1] - A[N - i]) * C ans %= MOD C = C * i * inv_t[i - K + 1] C %= MOD print(ans)
21
17
389
375
N, K = list(map(int, input().split())) A = list(map(int, input().split())) MOD = 10**9 + 7 def mpow(x, t): if t == 0: return 1 a = mpow(x, t >> 1) return a * a * (x ** (t & 1)) % MOD A.sort() ans = 0 C = 1 for i in range(K, N + 1): ans += (A[i - 1] - A[N - i]) * C ans %= MOD C = C * i * mpow(i - K + 1, MOD - 2) C %= MOD print(ans)
N, K = list(map(int, input().split())) A = list(map(int, input().split())) MOD = 10**9 + 7 inv_t = [0, 1] + [0] * (N - 1) for i in range(2, N + 1): inv_t[i] = inv_t[MOD % i] * (MOD - MOD // i) % MOD A.sort() ans = 0 C = 1 for i in range(K, N + 1): ans += (A[i - 1] - A[N - i]) * C ans %= MOD C = C * i * inv_t[i - K + 1] C %= MOD print(ans)
false
19.047619
[ "-", "-", "-def mpow(x, t):", "- if t == 0:", "- return 1", "- a = mpow(x, t >> 1)", "- return a * a * (x ** (t & 1)) % MOD", "-", "-", "+inv_t = [0, 1] + [0] * (N - 1)", "+for i in range(2, N + 1):", "+ inv_t[i] = inv_t[MOD % i] * (MOD - MOD // i) % MOD", "- C = C * i * mpow(i - K + 1, MOD - 2)", "+ C = C * i * inv_t[i - K + 1]" ]
false
0.037037
0.035316
1.04873
[ "s014570697", "s397530708" ]
u102461423
p02937
python
s448212263
s753874268
161
142
7,864
9,004
Accepted
Accepted
11.8
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 7) from collections import defaultdict from bisect import bisect_left S = input().rstrip() T = input().rstrip() LS = len(S) index = defaultdict(list) # alphabet to indices for i,s in enumerate(S): index[s].append(i) index x = -1 # 今見た場所。次はx+1以上からとる。 for t in T: arr = index[t] if len(arr) == 0: x = -2 break y = (x+1)%LS i = bisect_left(arr,y) if i < len(arr): next_x = (x+1) + arr[i] - y else: next_x = (x+1) + arr[0] - y + LS x = next_x answer = x+1 print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from bisect import bisect_right S = [ord(x)-ord('a') for x in readline().rstrip().decode('utf-8')] T = [ord(x)-ord('a') for x in readline().rstrip().decode('utf-8')] index = [[] for _ in range(26)] for i,x in enumerate(S): index[x].append(i) LS = len(S) for x in index: if x: x.append(x[0] + LS) ptr = -1 # 最後に使った文字 complete = True for t in T: seq = index[t] if not seq: complete = False break i = ptr%LS j = bisect_right(seq,i) ptr += seq[j]-i if complete: answer = ptr + 1 else: answer = -1 print(answer)
35
35
637
722
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import defaultdict from bisect import bisect_left S = input().rstrip() T = input().rstrip() LS = len(S) index = defaultdict(list) # alphabet to indices for i, s in enumerate(S): index[s].append(i) index x = -1 # 今見た場所。次はx+1以上からとる。 for t in T: arr = index[t] if len(arr) == 0: x = -2 break y = (x + 1) % LS i = bisect_left(arr, y) if i < len(arr): next_x = (x + 1) + arr[i] - y else: next_x = (x + 1) + arr[0] - y + LS x = next_x answer = x + 1 print(answer)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from bisect import bisect_right S = [ord(x) - ord("a") for x in readline().rstrip().decode("utf-8")] T = [ord(x) - ord("a") for x in readline().rstrip().decode("utf-8")] index = [[] for _ in range(26)] for i, x in enumerate(S): index[x].append(i) LS = len(S) for x in index: if x: x.append(x[0] + LS) ptr = -1 # 最後に使った文字 complete = True for t in T: seq = index[t] if not seq: complete = False break i = ptr % LS j = bisect_right(seq, i) ptr += seq[j] - i if complete: answer = ptr + 1 else: answer = -1 print(answer)
false
0
[ "-input = sys.stdin.readline", "-sys.setrecursionlimit(10**7)", "-from collections import defaultdict", "-from bisect import bisect_left", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+from bisect import bisect_right", "-S = input().rstrip()", "-T = input().rstrip()", "+S = [ord(x) - ord(\"a\") for x in readline().rstrip().decode(\"utf-8\")]", "+T = [ord(x) - ord(\"a\") for x in readline().rstrip().decode(\"utf-8\")]", "+index = [[] for _ in range(26)]", "+for i, x in enumerate(S):", "+ index[x].append(i)", "-index = defaultdict(list) # alphabet to indices", "-for i, s in enumerate(S):", "- index[s].append(i)", "-index", "-x = -1 # 今見た場所。次はx+1以上からとる。", "+for x in index:", "+ if x:", "+ x.append(x[0] + LS)", "+ptr = -1 # 最後に使った文字", "+complete = True", "- arr = index[t]", "- if len(arr) == 0:", "- x = -2", "+ seq = index[t]", "+ if not seq:", "+ complete = False", "- y = (x + 1) % LS", "- i = bisect_left(arr, y)", "- if i < len(arr):", "- next_x = (x + 1) + arr[i] - y", "- else:", "- next_x = (x + 1) + arr[0] - y + LS", "- x = next_x", "-answer = x + 1", "+ i = ptr % LS", "+ j = bisect_right(seq, i)", "+ ptr += seq[j] - i", "+if complete:", "+ answer = ptr + 1", "+else:", "+ answer = -1" ]
false
0.061391
0.043981
1.395836
[ "s448212263", "s753874268" ]
u256678932
p02261
python
s232421168
s054667790
30
20
7,828
5,616
Accepted
Accepted
33.33
from operator import lt def main(): N = int(eval(input())) A = list(input().split(' ')) Ab = bubbleSort(A[:], N, lambda a, b: int(a[1]) < int(b[1])) As = selectionSort(A[:], N, lambda a, b: int(a[1]) < int(b[1])) print((' '.join([str(a) for a in Ab]))) print('Stable') print((' '.join([str(a) for a in As]))) print(('Stable' if Ab == As else 'Not stable')) def bubbleSort(A, N, comp=lt): flag = True while flag: flag = False for j in range(N-1, 0, -1): if comp(A[j], A[j-1]): A[j], A[j-1] = A[j-1], A[j] flag = True return A def selectionSort(A, N, comp=lt): for i in range(0, N-1): minj = i for j in range(i, N): if comp(A[j], A[minj]): minj = j if i != minj: A[i], A[minj] = A[minj], A[i] return A if __name__ == '__main__': main()
def bubble_sort(cards, n): for i in range(n): for j in range(n-1, i, -1): if cards[j][1] < cards[j-1][1]: cards[j], cards[j-1] = cards[j-1], cards[j] return cards def selection_sort(cards, n): for i in range(n): minj = i for j in range(i, n): if cards[j][1] < cards[minj][1]: minj = j if i != minj: cards[i], cards[minj] = cards[minj], cards[i] return cards def is_stable(cards, sorted_cards): hashed = {} for m, v in cards: if v not in hashed: hashed[v] = [] hashed[v].append((m, v)) for sm, sv in sorted_cards: if hashed[sv][0] != (sm, sv): return False hashed[sv] = hashed[sv][1:] return True def print_cards(cards, sorted_cards): print((' '.join([card[0]+str(card[1]) for card in sorted_cards]))) if is_stable(cards, sorted_cards): print('Stable') else: print('Not stable') def main(): n = int(eval(input())) cards = [(card[0], int(card[1])) for card in input().split()] sorted_cards = bubble_sort(cards[:], n) print_cards(cards, sorted_cards) sorted_cards = selection_sort(cards[:], n) print_cards(cards, sorted_cards) if __name__ == '__main__': main()
43
59
956
1,370
from operator import lt def main(): N = int(eval(input())) A = list(input().split(" ")) Ab = bubbleSort(A[:], N, lambda a, b: int(a[1]) < int(b[1])) As = selectionSort(A[:], N, lambda a, b: int(a[1]) < int(b[1])) print((" ".join([str(a) for a in Ab]))) print("Stable") print((" ".join([str(a) for a in As]))) print(("Stable" if Ab == As else "Not stable")) def bubbleSort(A, N, comp=lt): flag = True while flag: flag = False for j in range(N - 1, 0, -1): if comp(A[j], A[j - 1]): A[j], A[j - 1] = A[j - 1], A[j] flag = True return A def selectionSort(A, N, comp=lt): for i in range(0, N - 1): minj = i for j in range(i, N): if comp(A[j], A[minj]): minj = j if i != minj: A[i], A[minj] = A[minj], A[i] return A if __name__ == "__main__": main()
def bubble_sort(cards, n): for i in range(n): for j in range(n - 1, i, -1): if cards[j][1] < cards[j - 1][1]: cards[j], cards[j - 1] = cards[j - 1], cards[j] return cards def selection_sort(cards, n): for i in range(n): minj = i for j in range(i, n): if cards[j][1] < cards[minj][1]: minj = j if i != minj: cards[i], cards[minj] = cards[minj], cards[i] return cards def is_stable(cards, sorted_cards): hashed = {} for m, v in cards: if v not in hashed: hashed[v] = [] hashed[v].append((m, v)) for sm, sv in sorted_cards: if hashed[sv][0] != (sm, sv): return False hashed[sv] = hashed[sv][1:] return True def print_cards(cards, sorted_cards): print((" ".join([card[0] + str(card[1]) for card in sorted_cards]))) if is_stable(cards, sorted_cards): print("Stable") else: print("Not stable") def main(): n = int(eval(input())) cards = [(card[0], int(card[1])) for card in input().split()] sorted_cards = bubble_sort(cards[:], n) print_cards(cards, sorted_cards) sorted_cards = selection_sort(cards[:], n) print_cards(cards, sorted_cards) if __name__ == "__main__": main()
false
27.118644
[ "-from operator import lt", "+def bubble_sort(cards, n):", "+ for i in range(n):", "+ for j in range(n - 1, i, -1):", "+ if cards[j][1] < cards[j - 1][1]:", "+ cards[j], cards[j - 1] = cards[j - 1], cards[j]", "+ return cards", "+", "+", "+def selection_sort(cards, n):", "+ for i in range(n):", "+ minj = i", "+ for j in range(i, n):", "+ if cards[j][1] < cards[minj][1]:", "+ minj = j", "+ if i != minj:", "+ cards[i], cards[minj] = cards[minj], cards[i]", "+ return cards", "+", "+", "+def is_stable(cards, sorted_cards):", "+ hashed = {}", "+ for m, v in cards:", "+ if v not in hashed:", "+ hashed[v] = []", "+ hashed[v].append((m, v))", "+ for sm, sv in sorted_cards:", "+ if hashed[sv][0] != (sm, sv):", "+ return False", "+ hashed[sv] = hashed[sv][1:]", "+ return True", "+", "+", "+def print_cards(cards, sorted_cards):", "+ print((\" \".join([card[0] + str(card[1]) for card in sorted_cards])))", "+ if is_stable(cards, sorted_cards):", "+ print(\"Stable\")", "+ else:", "+ print(\"Not stable\")", "- N = int(eval(input()))", "- A = list(input().split(\" \"))", "- Ab = bubbleSort(A[:], N, lambda a, b: int(a[1]) < int(b[1]))", "- As = selectionSort(A[:], N, lambda a, b: int(a[1]) < int(b[1]))", "- print((\" \".join([str(a) for a in Ab])))", "- print(\"Stable\")", "- print((\" \".join([str(a) for a in As])))", "- print((\"Stable\" if Ab == As else \"Not stable\"))", "-", "-", "-def bubbleSort(A, N, comp=lt):", "- flag = True", "- while flag:", "- flag = False", "- for j in range(N - 1, 0, -1):", "- if comp(A[j], A[j - 1]):", "- A[j], A[j - 1] = A[j - 1], A[j]", "- flag = True", "- return A", "-", "-", "-def selectionSort(A, N, comp=lt):", "- for i in range(0, N - 1):", "- minj = i", "- for j in range(i, N):", "- if comp(A[j], A[minj]):", "- minj = j", "- if i != minj:", "- A[i], A[minj] = A[minj], A[i]", "- return A", "+ n = int(eval(input()))", "+ cards = [(card[0], int(card[1])) for card in input().split()]", "+ sorted_cards = bubble_sort(cards[:], n)", "+ print_cards(cards, sorted_cards)", "+ sorted_cards = selection_sort(cards[:], n)", "+ print_cards(cards, sorted_cards)" ]
false
0.04226
0.04131
1.023003
[ "s232421168", "s054667790" ]
u721316601
p02773
python
s045095501
s177125443
869
447
36,032
38,364
Accepted
Accepted
48.56
from collections import * N = int(eval(input())) c = Counter() m = 0 for i in range(N): S = eval(input()) c[S] += 1 m = max(m, c[S]) ans = sorted([k for k, v in list(c.items()) if v == m]) print(('\n'.join(ans)))
from collections import * import sys input = sys.stdin.readline def main(): N = int(eval(input())) c = Counter() m = 0 S = [eval(input()) for i in range(N)] for s in S: c[s] += 1 m = max(m, c[s]) ans = sorted([k for k, v in list(c.items()) if v == m]) print(('\n'.join(ans))) if __name__ == '__main__': main()
12
17
217
355
from collections import * N = int(eval(input())) c = Counter() m = 0 for i in range(N): S = eval(input()) c[S] += 1 m = max(m, c[S]) ans = sorted([k for k, v in list(c.items()) if v == m]) print(("\n".join(ans)))
from collections import * import sys input = sys.stdin.readline def main(): N = int(eval(input())) c = Counter() m = 0 S = [eval(input()) for i in range(N)] for s in S: c[s] += 1 m = max(m, c[s]) ans = sorted([k for k, v in list(c.items()) if v == m]) print(("\n".join(ans))) if __name__ == "__main__": main()
false
29.411765
[ "+import sys", "-N = int(eval(input()))", "-c = Counter()", "-m = 0", "-for i in range(N):", "- S = eval(input())", "- c[S] += 1", "- m = max(m, c[S])", "-ans = sorted([k for k, v in list(c.items()) if v == m])", "-print((\"\\n\".join(ans)))", "+input = sys.stdin.readline", "+", "+", "+def main():", "+ N = int(eval(input()))", "+ c = Counter()", "+ m = 0", "+ S = [eval(input()) for i in range(N)]", "+ for s in S:", "+ c[s] += 1", "+ m = max(m, c[s])", "+ ans = sorted([k for k, v in list(c.items()) if v == m])", "+ print((\"\\n\".join(ans)))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.03726
0.037538
0.992591
[ "s045095501", "s177125443" ]
u077291787
p03503
python
s426963250
s562886780
63
58
3,064
3,064
Accepted
Accepted
7.94
# ABC080C - Shopping Street import sys input = sys.stdin.readline def main(): N = int(eval(input())) F = tuple(int(input().replace(" ", ""), 2) for _ in range(N)) P = tuple(tuple(map(int, input().split())) for _ in range(N)) ans = [] for i in range(1, 2 ** 10): cnt = sum(p[bin(i & f).count("1")] for f, p in zip(F, P)) ans += [cnt] print((max(ans))) if __name__ == "__main__": main()
# ABC080C - Shopping Street # exhaustive search import sys input = sys.stdin.readline def main(): N = int(eval(input())) F = tuple(int(input().replace(" ", ""), 2) for _ in range(N)) # str -> bit -> int P = tuple(tuple(map(int, input().split())) for _ in range(N)) # set of sum of profit in each pattern (2^10) ans = { sum(p[bin(i & f).count("1")] for f, p in zip(F, P)) for i in range(1, 2 ** 10) } print((max(ans))) if __name__ == "__main__": main()
17
18
439
504
# ABC080C - Shopping Street import sys input = sys.stdin.readline def main(): N = int(eval(input())) F = tuple(int(input().replace(" ", ""), 2) for _ in range(N)) P = tuple(tuple(map(int, input().split())) for _ in range(N)) ans = [] for i in range(1, 2**10): cnt = sum(p[bin(i & f).count("1")] for f, p in zip(F, P)) ans += [cnt] print((max(ans))) if __name__ == "__main__": main()
# ABC080C - Shopping Street # exhaustive search import sys input = sys.stdin.readline def main(): N = int(eval(input())) F = tuple(int(input().replace(" ", ""), 2) for _ in range(N)) # str -> bit -> int P = tuple(tuple(map(int, input().split())) for _ in range(N)) # set of sum of profit in each pattern (2^10) ans = { sum(p[bin(i & f).count("1")] for f, p in zip(F, P)) for i in range(1, 2**10) } print((max(ans))) if __name__ == "__main__": main()
false
5.555556
[ "+# exhaustive search", "- F = tuple(int(input().replace(\" \", \"\"), 2) for _ in range(N))", "+ F = tuple(int(input().replace(\" \", \"\"), 2) for _ in range(N)) # str -> bit -> int", "- ans = []", "- for i in range(1, 2**10):", "- cnt = sum(p[bin(i & f).count(\"1\")] for f, p in zip(F, P))", "- ans += [cnt]", "+ # set of sum of profit in each pattern (2^10)", "+ ans = {", "+ sum(p[bin(i & f).count(\"1\")] for f, p in zip(F, P)) for i in range(1, 2**10)", "+ }" ]
false
0.041181
0.082039
0.501968
[ "s426963250", "s562886780" ]
u941047297
p03730
python
s647235303
s576880262
164
18
38,384
2,940
Accepted
Accepted
89.02
a, b, c = list(map(int, input().split())) d = [] for i in range(b): d.append(a * (i + 1) % b) d = set(d) if c in d: print('YES') else: print('NO')
a, b, c = list(map(int, input().split())) R = [(a * i) % b for i in range(b)] if c in R: print('YES') else: print('NO')
9
6
167
132
a, b, c = list(map(int, input().split())) d = [] for i in range(b): d.append(a * (i + 1) % b) d = set(d) if c in d: print("YES") else: print("NO")
a, b, c = list(map(int, input().split())) R = [(a * i) % b for i in range(b)] if c in R: print("YES") else: print("NO")
false
33.333333
[ "-d = []", "-for i in range(b):", "- d.append(a * (i + 1) % b)", "-d = set(d)", "-if c in d:", "+R = [(a * i) % b for i in range(b)]", "+if c in R:" ]
false
0.044869
0.037792
1.18726
[ "s647235303", "s576880262" ]
u347600233
p03062
python
s702237435
s029622989
86
66
14,224
14,284
Accepted
Accepted
23.26
n = int(eval(input())) a = [int(i) for i in input().split()] sum_abs, min_abs, cnt_minus = 0, 10**9, 0 for ai in a: if ai < 0: cnt_minus += 1 abs_ai = abs(ai) sum_abs += abs_ai if abs_ai < min_abs: min_abs = abs_ai if cnt_minus % 2 == 0 or 0 in a: print(sum_abs) else: print((sum_abs - 2*min_abs))
# knk_kei 0 in a の条件は不要 n = int(eval(input())) a = [int(i) for i in input().split()] if len([i for i in a if i < 0]) % 2 == 0: print((sum([abs(i) for i in a]))) else: print((sum([abs(i) for i in a]) - 2*min([abs(i) for i in a])))
14
7
342
235
n = int(eval(input())) a = [int(i) for i in input().split()] sum_abs, min_abs, cnt_minus = 0, 10**9, 0 for ai in a: if ai < 0: cnt_minus += 1 abs_ai = abs(ai) sum_abs += abs_ai if abs_ai < min_abs: min_abs = abs_ai if cnt_minus % 2 == 0 or 0 in a: print(sum_abs) else: print((sum_abs - 2 * min_abs))
# knk_kei 0 in a の条件は不要 n = int(eval(input())) a = [int(i) for i in input().split()] if len([i for i in a if i < 0]) % 2 == 0: print((sum([abs(i) for i in a]))) else: print((sum([abs(i) for i in a]) - 2 * min([abs(i) for i in a])))
false
50
[ "+# knk_kei 0 in a の条件は不要", "-sum_abs, min_abs, cnt_minus = 0, 10**9, 0", "-for ai in a:", "- if ai < 0:", "- cnt_minus += 1", "- abs_ai = abs(ai)", "- sum_abs += abs_ai", "- if abs_ai < min_abs:", "- min_abs = abs_ai", "-if cnt_minus % 2 == 0 or 0 in a:", "- print(sum_abs)", "+if len([i for i in a if i < 0]) % 2 == 0:", "+ print((sum([abs(i) for i in a])))", "- print((sum_abs - 2 * min_abs))", "+ print((sum([abs(i) for i in a]) - 2 * min([abs(i) for i in a])))" ]
false
0.035292
0.036474
0.967609
[ "s702237435", "s029622989" ]
u312025627
p03000
python
s353502537
s283498849
179
64
38,256
62,000
Accepted
Accepted
64.25
def main(): N, X = (int(i) for i in input().split()) L = [int(i) for i in input().split()] from itertools import accumulate S = accumulate([0] + L) ans = 0 for s in S: if s <= X: ans += 1 else: break print(ans) if __name__ == '__main__': main()
def main(): N, X = (int(i) for i in input().split()) L = [int(i) for i in input().split()] from itertools import accumulate S = list(accumulate([0] + L)) ans = 0 for s in S: if X < s: break ans += 1 print(ans) if __name__ == '__main__': main()
16
15
334
320
def main(): N, X = (int(i) for i in input().split()) L = [int(i) for i in input().split()] from itertools import accumulate S = accumulate([0] + L) ans = 0 for s in S: if s <= X: ans += 1 else: break print(ans) if __name__ == "__main__": main()
def main(): N, X = (int(i) for i in input().split()) L = [int(i) for i in input().split()] from itertools import accumulate S = list(accumulate([0] + L)) ans = 0 for s in S: if X < s: break ans += 1 print(ans) if __name__ == "__main__": main()
false
6.25
[ "- S = accumulate([0] + L)", "+ S = list(accumulate([0] + L))", "- if s <= X:", "- ans += 1", "- else:", "+ if X < s:", "+ ans += 1" ]
false
0.075869
0.076907
0.986503
[ "s353502537", "s283498849" ]
u442948527
p03777
python
s155841579
s501887571
28
21
8,916
9,020
Accepted
Accepted
25
a,b=input().split() print(('DH'[a==b]))
a,b=input().split() print((["D","H"][a==b]))
2
2
38
43
a, b = input().split() print(("DH"[a == b]))
a, b = input().split() print((["D", "H"][a == b]))
false
0
[ "-print((\"DH\"[a == b]))", "+print(([\"D\", \"H\"][a == b]))" ]
false
0.036455
0.037604
0.969441
[ "s155841579", "s501887571" ]
u485319545
p02720
python
s987276950
s470609565
90
55
12,720
13,344
Accepted
Accepted
38.89
k=int(eval(input())) if k<=9: print(k) exit(0) ans=[1,2,3,4,5,6,7,8,9] i=0 while len(ans)<k: v=str(ans[i]) n=len(v) #最後の桁 v_last=int(v[-1]) if v_last==0: ans.append(int(v+'0')) ans.append(int(v+'1')) elif v_last==9: ans.append(int(v+'8')) ans.append(int(v+'9')) else: ans.append(int(v+str(v_last-1))) ans.append(int(v+str(v_last))) ans.append(int(v+str(v_last+1))) i+=1 print((ans[k-1]))
k=int(eval(input())) if k<=9: print(k) exit(0) ans=[1,2,3,4,5,6,7,8,9] i=0 while len(ans)<k: v=ans[i] mod=v%10 if mod==0: ans.append(10*v+mod) ans.append(10*v+mod+1) elif mod==9: ans.append(10*v+mod-1) ans.append(10*v+mod) else: ans.append(10*v+mod-1) ans.append(10*v+mod) ans.append(10*v+mod+1) i+=1 print((ans[k-1]))
33
31
518
447
k = int(eval(input())) if k <= 9: print(k) exit(0) ans = [1, 2, 3, 4, 5, 6, 7, 8, 9] i = 0 while len(ans) < k: v = str(ans[i]) n = len(v) # 最後の桁 v_last = int(v[-1]) if v_last == 0: ans.append(int(v + "0")) ans.append(int(v + "1")) elif v_last == 9: ans.append(int(v + "8")) ans.append(int(v + "9")) else: ans.append(int(v + str(v_last - 1))) ans.append(int(v + str(v_last))) ans.append(int(v + str(v_last + 1))) i += 1 print((ans[k - 1]))
k = int(eval(input())) if k <= 9: print(k) exit(0) ans = [1, 2, 3, 4, 5, 6, 7, 8, 9] i = 0 while len(ans) < k: v = ans[i] mod = v % 10 if mod == 0: ans.append(10 * v + mod) ans.append(10 * v + mod + 1) elif mod == 9: ans.append(10 * v + mod - 1) ans.append(10 * v + mod) else: ans.append(10 * v + mod - 1) ans.append(10 * v + mod) ans.append(10 * v + mod + 1) i += 1 print((ans[k - 1]))
false
6.060606
[ "- v = str(ans[i])", "- n = len(v)", "- # 最後の桁", "- v_last = int(v[-1])", "- if v_last == 0:", "- ans.append(int(v + \"0\"))", "- ans.append(int(v + \"1\"))", "- elif v_last == 9:", "- ans.append(int(v + \"8\"))", "- ans.append(int(v + \"9\"))", "+ v = ans[i]", "+ mod = v % 10", "+ if mod == 0:", "+ ans.append(10 * v + mod)", "+ ans.append(10 * v + mod + 1)", "+ elif mod == 9:", "+ ans.append(10 * v + mod - 1)", "+ ans.append(10 * v + mod)", "- ans.append(int(v + str(v_last - 1)))", "- ans.append(int(v + str(v_last)))", "- ans.append(int(v + str(v_last + 1)))", "+ ans.append(10 * v + mod - 1)", "+ ans.append(10 * v + mod)", "+ ans.append(10 * v + mod + 1)" ]
false
0.10047
0.055186
1.820566
[ "s987276950", "s470609565" ]
u396890425
p03487
python
s449929095
s792599899
173
75
27,760
18,676
Accepted
Accepted
56.65
import collections N=int(eval(input())) List=sorted(list(map(int, input().split()))) c = collections.Counter(List) #要素と出現回数の辞書 value, count = list(zip(*c.most_common())) newList=[] for i in range(len(value)): if N-len(newList)>=value[i] and count[i]>=value[i]: for j in range(value[i]): newList.append(value[i]) else: continue #print(newList) Ans=len(List)-len(newList) print(Ans)
import collections N = int(eval(input())) A = list(map(int, input().split())) c = collections.Counter(A) #要素と出現回数の辞書 #print(c) ans = 0 for k,v in list(c.items()): ans += v if v<k else v-k print(ans)
22
12
432
204
import collections N = int(eval(input())) List = sorted(list(map(int, input().split()))) c = collections.Counter(List) # 要素と出現回数の辞書 value, count = list(zip(*c.most_common())) newList = [] for i in range(len(value)): if N - len(newList) >= value[i] and count[i] >= value[i]: for j in range(value[i]): newList.append(value[i]) else: continue # print(newList) Ans = len(List) - len(newList) print(Ans)
import collections N = int(eval(input())) A = list(map(int, input().split())) c = collections.Counter(A) # 要素と出現回数の辞書 # print(c) ans = 0 for k, v in list(c.items()): ans += v if v < k else v - k print(ans)
false
45.454545
[ "-List = sorted(list(map(int, input().split())))", "-c = collections.Counter(List) # 要素と出現回数の辞書", "-value, count = list(zip(*c.most_common()))", "-newList = []", "-for i in range(len(value)):", "- if N - len(newList) >= value[i] and count[i] >= value[i]:", "- for j in range(value[i]):", "- newList.append(value[i])", "- else:", "- continue", "-# print(newList)", "-Ans = len(List) - len(newList)", "-print(Ans)", "+A = list(map(int, input().split()))", "+c = collections.Counter(A) # 要素と出現回数の辞書", "+# print(c)", "+ans = 0", "+for k, v in list(c.items()):", "+ ans += v if v < k else v - k", "+print(ans)" ]
false
0.039011
0.042447
0.919054
[ "s449929095", "s792599899" ]
u028973125
p02727
python
s822146941
s719293695
389
347
92,568
100,904
Accepted
Accepted
10.8
import sys X, Y, A, B, C = list(map(int, sys.stdin.readline().strip().split())) P = list(map(int, sys.stdin.readline().strip().split())) Q = list(map(int, sys.stdin.readline().strip().split())) R = list(map(int, sys.stdin.readline().strip().split())) P.sort(reverse=True) Q.sort(reverse=True) R.sort(reverse=True) P = P[:X] P.sort() Q = Q[:Y] Q.sort() ans = 0 i, j, k = 0, 0, 0 while C > k: if X > i and Y > j: if P[i] >= Q[j]: if R[k] > Q[j] and Y > j: Q[j] = R[k] j += 1 k += 1 elif R[k] > P[i] and X > i: P[i] = R[k] i += 1 k += 1 else: break elif P[i] < Q[j]: if R[k] > P[i] and X > i: P[i] = R[k] i += 1 k += 1 elif R[k] > Q[j] and Y > j: Q[j] = R[k] j += 1 k += 1 else: break elif X > i: if R[k] > P[i]: P[i] = R[k] i += 1 k += 1 else: break elif Y > j: if R[k] > Q[j]: Q[j] = R[k] j += 1 k += 1 else: break # print(P) # print(Q) print((sum(P) + sum(Q)))
import sys X, Y, A, B, C = list(map(int, sys.stdin.readline().strip().split())) P = list(map(int, sys.stdin.readline().strip().split())) Q = list(map(int, sys.stdin.readline().strip().split())) R = list(map(int, sys.stdin.readline().strip().split())) P.sort(reverse=True) Q.sort(reverse=True) R.sort(reverse=True) ans = P[:X] + Q[:Y] + R ans.sort(reverse=True) print((sum(ans[:X+Y])))
63
15
1,367
394
import sys X, Y, A, B, C = list(map(int, sys.stdin.readline().strip().split())) P = list(map(int, sys.stdin.readline().strip().split())) Q = list(map(int, sys.stdin.readline().strip().split())) R = list(map(int, sys.stdin.readline().strip().split())) P.sort(reverse=True) Q.sort(reverse=True) R.sort(reverse=True) P = P[:X] P.sort() Q = Q[:Y] Q.sort() ans = 0 i, j, k = 0, 0, 0 while C > k: if X > i and Y > j: if P[i] >= Q[j]: if R[k] > Q[j] and Y > j: Q[j] = R[k] j += 1 k += 1 elif R[k] > P[i] and X > i: P[i] = R[k] i += 1 k += 1 else: break elif P[i] < Q[j]: if R[k] > P[i] and X > i: P[i] = R[k] i += 1 k += 1 elif R[k] > Q[j] and Y > j: Q[j] = R[k] j += 1 k += 1 else: break elif X > i: if R[k] > P[i]: P[i] = R[k] i += 1 k += 1 else: break elif Y > j: if R[k] > Q[j]: Q[j] = R[k] j += 1 k += 1 else: break # print(P) # print(Q) print((sum(P) + sum(Q)))
import sys X, Y, A, B, C = list(map(int, sys.stdin.readline().strip().split())) P = list(map(int, sys.stdin.readline().strip().split())) Q = list(map(int, sys.stdin.readline().strip().split())) R = list(map(int, sys.stdin.readline().strip().split())) P.sort(reverse=True) Q.sort(reverse=True) R.sort(reverse=True) ans = P[:X] + Q[:Y] + R ans.sort(reverse=True) print((sum(ans[: X + Y])))
false
76.190476
[ "-P = P[:X]", "-P.sort()", "-Q = Q[:Y]", "-Q.sort()", "-ans = 0", "-i, j, k = 0, 0, 0", "-while C > k:", "- if X > i and Y > j:", "- if P[i] >= Q[j]:", "- if R[k] > Q[j] and Y > j:", "- Q[j] = R[k]", "- j += 1", "- k += 1", "- elif R[k] > P[i] and X > i:", "- P[i] = R[k]", "- i += 1", "- k += 1", "- else:", "- break", "- elif P[i] < Q[j]:", "- if R[k] > P[i] and X > i:", "- P[i] = R[k]", "- i += 1", "- k += 1", "- elif R[k] > Q[j] and Y > j:", "- Q[j] = R[k]", "- j += 1", "- k += 1", "- else:", "- break", "- elif X > i:", "- if R[k] > P[i]:", "- P[i] = R[k]", "- i += 1", "- k += 1", "- else:", "- break", "- elif Y > j:", "- if R[k] > Q[j]:", "- Q[j] = R[k]", "- j += 1", "- k += 1", "- else:", "- break", "-# print(P)", "-# print(Q)", "-print((sum(P) + sum(Q)))", "+ans = P[:X] + Q[:Y] + R", "+ans.sort(reverse=True)", "+print((sum(ans[: X + Y])))" ]
false
0.033953
0.043602
0.778713
[ "s822146941", "s719293695" ]
u729133443
p02559
python
s010288445
s819089153
170
122
12,936
12,920
Accepted
Accepted
28.24
import sys if sys.argv[-1] == 'ONLINE_JUDGE': import os, zlib, base64 open('solve.pyx', 'wb').write(zlib.decompress(base64.b85decode("c${@p+is&U5Pe7DA4Xbjg}0;ysg)|!>{s+H$^#gajF#A`FSPypj<G3D+MO57oWq$j<KY+Z4|`Oy0p8<;29?~tXeaV)(CQSyyK}4CaTFtPJe`%caMrCnETj=TerIft>I**z%a5%t;q2nU2-~@Vp0-!c<{9tB0HczJ-D5>j@1c)L&)?Nmh&|9(7r>)W<yp`xf?VlYEYeU~@*xWbQXOz?@(d`xpsoZCTc|?%?TDj*I+A>J1V;M>ThllY@(d484Rl(x|5n7Sargsu1-Hc65GR0ISf?fM=xb8g11GnIZyU^i{Nc4ZlbUlo+!MjT?@({4HCu$+E!69~f%|((L@{ar6Q!V?W`e}#Lc&M9!eXu+Cn828l1~@P!&AhUL|w78`?l|kxyN#D_5E@L(GomwK_=q8Z<#uKzv>j>1~!;%5*T+1@;{6=5Uyv7@E58k9T^Gxf@!VIS}VC$ldPNcE8thIgxB>*UD9T{5~e(RLwme1H7HH0DC4hGNY;e$(52R8kYGPkUs>YVF7?)w`<|M<r)VE+6ZX;1ZDO>!{@_?bn(uk`<$|w?z)#J>6B_"))) os.system('cythonize -i -3 -b solve.pyx') import solve
import sys if sys.argv[-1] == 'ONLINE_JUDGE': import os, zlib, base64 open('solve.pyx', 'wb').write(zlib.decompress(base64.b85decode("c${rg(Qbk;6n!V*A8xX2!mLJ;Em?@{EB5AmfVRNRYOAH7`}?&PrB3@)&N<wB?zw#e`fFMxbD#_d>`=+#OZPmEYOQu7x!jk!6oLz&xZ5jjV6RKrTtosZy6g-?b>$mwXj^Jxg(yuON0jjzgp$qXePvI!1vY|~x4+3G1*sYoc^rW~SE?dFp@5Z#k1Yxg*(h?SvgFt;NhcU<%dFw;BZo@!@@HaPH43kgtzd373#;*@=BC#Y=;&)u$e?5_aW0UY&75vcdN&B`0%Tx`ZEy?o0#1P)_l@uZ3k<S=uHX6c4~F-G|Dz*(!Yb(1xx%ht*lRKM3I^+fz@-bpg-+lwUG0>HKu=(Zqa&L3##F7et%`EoeInD`$75s6h%b>omLAf;vAOh{p#B~j?jgHUlaCK7nLP{kEobB$;gH%jx=Wu1dM-NdE%x5xV97snn#0W"))) os.system('cythonize -i -3 -b solve.pyx') import solve
6
6
768
644
import sys if sys.argv[-1] == "ONLINE_JUDGE": import os, zlib, base64 open("solve.pyx", "wb").write( zlib.decompress( base64.b85decode( "c${@p+is&U5Pe7DA4Xbjg}0;ysg)|!>{s+H$^#gajF#A`FSPypj<G3D+MO57oWq$j<KY+Z4|`Oy0p8<;29?~tXeaV)(CQSyyK}4CaTFtPJe`%caMrCnETj=TerIft>I**z%a5%t;q2nU2-~@Vp0-!c<{9tB0HczJ-D5>j@1c)L&)?Nmh&|9(7r>)W<yp`xf?VlYEYeU~@*xWbQXOz?@(d`xpsoZCTc|?%?TDj*I+A>J1V;M>ThllY@(d484Rl(x|5n7Sargsu1-Hc65GR0ISf?fM=xb8g11GnIZyU^i{Nc4ZlbUlo+!MjT?@({4HCu$+E!69~f%|((L@{ar6Q!V?W`e}#Lc&M9!eXu+Cn828l1~@P!&AhUL|w78`?l|kxyN#D_5E@L(GomwK_=q8Z<#uKzv>j>1~!;%5*T+1@;{6=5Uyv7@E58k9T^Gxf@!VIS}VC$ldPNcE8thIgxB>*UD9T{5~e(RLwme1H7HH0DC4hGNY;e$(52R8kYGPkUs>YVF7?)w`<|M<r)VE+6ZX;1ZDO>!{@_?bn(uk`<$|w?z)#J>6B_" ) ) ) os.system("cythonize -i -3 -b solve.pyx") import solve
import sys if sys.argv[-1] == "ONLINE_JUDGE": import os, zlib, base64 open("solve.pyx", "wb").write( zlib.decompress( base64.b85decode( "c${rg(Qbk;6n!V*A8xX2!mLJ;Em?@{EB5AmfVRNRYOAH7`}?&PrB3@)&N<wB?zw#e`fFMxbD#_d>`=+#OZPmEYOQu7x!jk!6oLz&xZ5jjV6RKrTtosZy6g-?b>$mwXj^Jxg(yuON0jjzgp$qXePvI!1vY|~x4+3G1*sYoc^rW~SE?dFp@5Z#k1Yxg*(h?SvgFt;NhcU<%dFw;BZo@!@@HaPH43kgtzd373#;*@=BC#Y=;&)u$e?5_aW0UY&75vcdN&B`0%Tx`ZEy?o0#1P)_l@uZ3k<S=uHX6c4~F-G|Dz*(!Yb(1xx%ht*lRKM3I^+fz@-bpg-+lwUG0>HKu=(Zqa&L3##F7et%`EoeInD`$75s6h%b>omLAf;vAOh{p#B~j?jgHUlaCK7nLP{kEobB$;gH%jx=Wu1dM-NdE%x5xV97snn#0W" ) ) ) os.system("cythonize -i -3 -b solve.pyx") import solve
false
0
[ "- \"c${@p+is&U5Pe7DA4Xbjg}0;ysg)|!>{s+H$^#gajF#A`FSPypj<G3D+MO57oWq$j<KY+Z4|`Oy0p8<;29?~tXeaV)(CQSyyK}4CaTFtPJe`%caMrCnETj=TerIft>I**z%a5%t;q2nU2-~@Vp0-!c<{9tB0HczJ-D5>j@1c)L&)?Nmh&|9(7r>)W<yp`xf?VlYEYeU~@*xWbQXOz?@(d`xpsoZCTc|?%?TDj*I+A>J1V;M>ThllY@(d484Rl(x|5n7Sargsu1-Hc65GR0ISf?fM=xb8g11GnIZyU^i{Nc4ZlbUlo+!MjT?@({4HCu$+E!69~f%|((L@{ar6Q!V?W`e}#Lc&M9!eXu+Cn828l1~@P!&AhUL|w78`?l|kxyN#D_5E@L(GomwK_=q8Z<#uKzv>j>1~!;%5*T+1@;{6=5Uyv7@E58k9T^Gxf@!VIS}VC$ldPNcE8thIgxB>*UD9T{5~e(RLwme1H7HH0DC4hGNY;e$(52R8kYGPkUs>YVF7?)w`<|M<r)VE+6ZX;1ZDO>!{@_?bn(uk`<$|w?z)#J>6B_\"" ]
false
0.045669
0.048326
0.945012
[ "s010288445", "s819089153" ]
u794544096
p03000
python
s955217022
s785186691
76
66
61,868
61,840
Accepted
Accepted
13.16
n, x = list(map(int, input().split())) l = list(map(int, input().split())) count = 1 d = 0 for i in range(n): d += l[i] if d <= x: count += 1 print(count)
n, x = list(map(int, input().split())) l = list(map(int, input().split())) cnt = 1 z = 0 for i in range(n): z += l[i] if z <= x: cnt += 1 print(cnt)
11
12
184
180
n, x = list(map(int, input().split())) l = list(map(int, input().split())) count = 1 d = 0 for i in range(n): d += l[i] if d <= x: count += 1 print(count)
n, x = list(map(int, input().split())) l = list(map(int, input().split())) cnt = 1 z = 0 for i in range(n): z += l[i] if z <= x: cnt += 1 print(cnt)
false
8.333333
[ "-count = 1", "-d = 0", "+cnt = 1", "+z = 0", "- d += l[i]", "- if d <= x:", "- count += 1", "-print(count)", "+ z += l[i]", "+ if z <= x:", "+ cnt += 1", "+print(cnt)" ]
false
0.03138
0.036487
0.860012
[ "s955217022", "s785186691" ]
u905268546
p03767
python
s358768336
s016512278
264
203
37,084
39,492
Accepted
Accepted
23.11
print(sum(sorted(list([float(None==exec("N=int(input())"))] + list(map(int, input().split()))), reverse=True,key=lambda x: 10 ** 10 if type(x) == float else x)[2:2*N+1:2]))
print(sum(sorted(list(map(int,exec("N=int(input())")or input().split())))[-2:-2*N-1:-2]))
1
1
172
89
print( sum( sorted( list( [float(None == exec("N=int(input())"))] + list(map(int, input().split())) ), reverse=True, key=lambda x: 10**10 if type(x) == float else x, )[2 : 2 * N + 1 : 2] ) )
print( sum( sorted(list(map(int, exec("N=int(input())") or input().split())))[ -2 : -2 * N - 1 : -2 ] ) )
false
0
[ "- sorted(", "- list(", "- [float(None == exec(\"N=int(input())\"))]", "- + list(map(int, input().split()))", "- ),", "- reverse=True,", "- key=lambda x: 10**10 if type(x) == float else x,", "- )[2 : 2 * N + 1 : 2]", "+ sorted(list(map(int, exec(\"N=int(input())\") or input().split())))[", "+ -2 : -2 * N - 1 : -2", "+ ]" ]
false
0.045516
0.040172
1.133038
[ "s358768336", "s016512278" ]
u315078622
p02998
python
s571534326
s255920982
889
722
38,508
36,844
Accepted
Accepted
18.79
class UnionFindTree: """Disjoint-Set Data Structure Union-Find Tree complexity: init: O(n) find, unite, same: O(alpha(n)) used in SRM505 div.2 900, ATC001 A, DSL1A(AOJ) """ def __init__(self, n): self.par = list(range(n)) # parent self.rank = [0] * n # depth of tree def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x, y): x, y = self.find(x), self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same(self, x, y): return self.find(x) == self.find(y) N = int(eval(input())) M = 10 ** 5 uft = UnionFindTree(N + 2 * M) for i in range(N): x, y = list(map(int, input().split())) x, y = x-1, y-1 uft.unite(i, x + N) uft.unite(i, y + N + M) x_dict, y_dict = dict(), dict() for x in range(N, M + N): par_x = uft.find(x) x_dict[par_x] = x_dict.get(par_x, 0) + 1 for y in range(N + M, N + 2 * M): par_y = uft.find(y) y_dict[par_y] = y_dict.get(par_y, 0) + 1 ans = -N for r in list(x_dict.keys()): ans += x_dict.get(r, 0) * y_dict.get(r, 0) print(ans)
class UnionFindTree: """Disjoint-Set Data Structure Union-Find Tree complexity: init: O(n) find, unite, same: O(alpha(n)) used in SRM505 div.2 900, ATC001 A, DSL1A(AOJ) """ def __init__(self, n): self.par = list(range(n)) # parent self.rank = [0] * n # depth of tree def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x, y): x, y = self.find(x), self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same(self, x, y): return self.find(x) == self.find(y) N = int(eval(input())) M = 10 ** 5 uft = UnionFindTree(2 * M) for _ in range(N): x, y = list(map(int, input().split())) x, y = x-1, y-1 uft.unite(x, y + M) x_dict, y_dict = dict(), dict() for x in range(M): par_x = uft.find(x) x_dict[par_x] = x_dict.get(par_x, 0) + 1 for y in range(M, 2 * M): par_y = uft.find(y) y_dict[par_y] = y_dict.get(par_y, 0) + 1 ans = -N for r in list(x_dict.keys()): ans += x_dict.get(r, 0) * y_dict.get(r, 0) print(ans)
54
53
1,439
1,391
class UnionFindTree: """Disjoint-Set Data Structure Union-Find Tree complexity: init: O(n) find, unite, same: O(alpha(n)) used in SRM505 div.2 900, ATC001 A, DSL1A(AOJ) """ def __init__(self, n): self.par = list(range(n)) # parent self.rank = [0] * n # depth of tree def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x, y): x, y = self.find(x), self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same(self, x, y): return self.find(x) == self.find(y) N = int(eval(input())) M = 10**5 uft = UnionFindTree(N + 2 * M) for i in range(N): x, y = list(map(int, input().split())) x, y = x - 1, y - 1 uft.unite(i, x + N) uft.unite(i, y + N + M) x_dict, y_dict = dict(), dict() for x in range(N, M + N): par_x = uft.find(x) x_dict[par_x] = x_dict.get(par_x, 0) + 1 for y in range(N + M, N + 2 * M): par_y = uft.find(y) y_dict[par_y] = y_dict.get(par_y, 0) + 1 ans = -N for r in list(x_dict.keys()): ans += x_dict.get(r, 0) * y_dict.get(r, 0) print(ans)
class UnionFindTree: """Disjoint-Set Data Structure Union-Find Tree complexity: init: O(n) find, unite, same: O(alpha(n)) used in SRM505 div.2 900, ATC001 A, DSL1A(AOJ) """ def __init__(self, n): self.par = list(range(n)) # parent self.rank = [0] * n # depth of tree def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x, y): x, y = self.find(x), self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.par[x] = y else: self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 def same(self, x, y): return self.find(x) == self.find(y) N = int(eval(input())) M = 10**5 uft = UnionFindTree(2 * M) for _ in range(N): x, y = list(map(int, input().split())) x, y = x - 1, y - 1 uft.unite(x, y + M) x_dict, y_dict = dict(), dict() for x in range(M): par_x = uft.find(x) x_dict[par_x] = x_dict.get(par_x, 0) + 1 for y in range(M, 2 * M): par_y = uft.find(y) y_dict[par_y] = y_dict.get(par_y, 0) + 1 ans = -N for r in list(x_dict.keys()): ans += x_dict.get(r, 0) * y_dict.get(r, 0) print(ans)
false
1.851852
[ "-uft = UnionFindTree(N + 2 * M)", "-for i in range(N):", "+uft = UnionFindTree(2 * M)", "+for _ in range(N):", "- uft.unite(i, x + N)", "- uft.unite(i, y + N + M)", "+ uft.unite(x, y + M)", "-for x in range(N, M + N):", "+for x in range(M):", "-for y in range(N + M, N + 2 * M):", "+for y in range(M, 2 * M):" ]
false
0.409898
0.283342
1.44665
[ "s571534326", "s255920982" ]
u077291787
p03495
python
s471139711
s768563323
98
79
41,500
35,996
Accepted
Accepted
19.39
# ARC086C - Not so Diverse (ABC081C) from collections import Counter def main(): n, k = list(map(int, input().rstrip().split())) A = sorted(list(Counter(list(map(int, input().split()))).values()), reverse=True) print((sum(A[k:]))) if __name__ == "__main__": main()
# ABC081C - Not so Diverse (ARC086C) from collections import Counter def main(): n, k = list(map(int, input().rstrip().split())) A = sorted(list(Counter(input().split()).values()), reverse=True) print((sum(A[k:]))) if __name__ == "__main__": main()
12
12
281
271
# ARC086C - Not so Diverse (ABC081C) from collections import Counter def main(): n, k = list(map(int, input().rstrip().split())) A = sorted(list(Counter(list(map(int, input().split()))).values()), reverse=True) print((sum(A[k:]))) if __name__ == "__main__": main()
# ABC081C - Not so Diverse (ARC086C) from collections import Counter def main(): n, k = list(map(int, input().rstrip().split())) A = sorted(list(Counter(input().split()).values()), reverse=True) print((sum(A[k:]))) if __name__ == "__main__": main()
false
0
[ "-# ARC086C - Not so Diverse (ABC081C)", "+# ABC081C - Not so Diverse (ARC086C)", "- A = sorted(list(Counter(list(map(int, input().split()))).values()), reverse=True)", "+ A = sorted(list(Counter(input().split()).values()), reverse=True)" ]
false
0.041247
0.121013
0.340846
[ "s471139711", "s768563323" ]
u790710233
p03157
python
s526345352
s203991966
989
700
130,808
273,928
Accepted
Accepted
29.22
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) h, w = list(map(int, input().split())) n = h*w fld = ''.join([input().rstrip()for _ in range(h)]) edges = [set() for _ in range(n)] def to_v(i, j): return i*w+j for i in range(h): for j in range(w): v = to_v(i, j) dirc = [(-1, 0), (0, 1), (1, 0), (0, -1)] for di, dj in dirc: x, y = i+di, j+dj if x < 0 or h <= x or y < 0 or w <= y: continue v2 = to_v(x, y) if fld[v] != fld[v2]: edges[v].add(v2) edges[v2].add(v) def dfs(v, c=0): if visited[v]: return visited[v] = 1 cnt[c] += 1 for v2 in edges[v]: dfs(v2, c ^ 1) visited = [0]*n ans = 0 for v in range(n): if visited[v]: continue cnt = [0, 0] dfs(v) ans += cnt[0]*cnt[1] print(ans)
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) h, w = list(map(int, input().split())) n = h*w fld = ''.join([input().rstrip()for _ in range(h)]) def to_v(i, j): return i*w+j def generate_v2(v): i, j = divmod(v, w) if 0 < i: yield v-w if i < h-1: yield v+w if 0 < j: yield v-1 if j < w-1: yield v+1 def dfs(v, c=0): if visited[v]: return visited[v] = 1 cnt[c] += 1 for v2 in generate_v2(v): if fld[v] == fld[v2]: continue dfs(v2, c ^ 1) visited = [0]*n ans = 0 for v in range(n): if visited[v]: continue cnt = [0, 0] dfs(v) ans += cnt[0]*cnt[1] print(ans)
45
44
931
751
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) h, w = list(map(int, input().split())) n = h * w fld = "".join([input().rstrip() for _ in range(h)]) edges = [set() for _ in range(n)] def to_v(i, j): return i * w + j for i in range(h): for j in range(w): v = to_v(i, j) dirc = [(-1, 0), (0, 1), (1, 0), (0, -1)] for di, dj in dirc: x, y = i + di, j + dj if x < 0 or h <= x or y < 0 or w <= y: continue v2 = to_v(x, y) if fld[v] != fld[v2]: edges[v].add(v2) edges[v2].add(v) def dfs(v, c=0): if visited[v]: return visited[v] = 1 cnt[c] += 1 for v2 in edges[v]: dfs(v2, c ^ 1) visited = [0] * n ans = 0 for v in range(n): if visited[v]: continue cnt = [0, 0] dfs(v) ans += cnt[0] * cnt[1] print(ans)
import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) h, w = list(map(int, input().split())) n = h * w fld = "".join([input().rstrip() for _ in range(h)]) def to_v(i, j): return i * w + j def generate_v2(v): i, j = divmod(v, w) if 0 < i: yield v - w if i < h - 1: yield v + w if 0 < j: yield v - 1 if j < w - 1: yield v + 1 def dfs(v, c=0): if visited[v]: return visited[v] = 1 cnt[c] += 1 for v2 in generate_v2(v): if fld[v] == fld[v2]: continue dfs(v2, c ^ 1) visited = [0] * n ans = 0 for v in range(n): if visited[v]: continue cnt = [0, 0] dfs(v) ans += cnt[0] * cnt[1] print(ans)
false
2.222222
[ "-edges = [set() for _ in range(n)]", "-for i in range(h):", "- for j in range(w):", "- v = to_v(i, j)", "- dirc = [(-1, 0), (0, 1), (1, 0), (0, -1)]", "- for di, dj in dirc:", "- x, y = i + di, j + dj", "- if x < 0 or h <= x or y < 0 or w <= y:", "- continue", "- v2 = to_v(x, y)", "- if fld[v] != fld[v2]:", "- edges[v].add(v2)", "- edges[v2].add(v)", "+def generate_v2(v):", "+ i, j = divmod(v, w)", "+ if 0 < i:", "+ yield v - w", "+ if i < h - 1:", "+ yield v + w", "+ if 0 < j:", "+ yield v - 1", "+ if j < w - 1:", "+ yield v + 1", "- for v2 in edges[v]:", "+ for v2 in generate_v2(v):", "+ if fld[v] == fld[v2]:", "+ continue" ]
false
0.12222
0.077197
1.583227
[ "s526345352", "s203991966" ]
u778814286
p03403
python
s488520765
s974321423
276
249
14,172
13,920
Accepted
Accepted
9.78
n = int(eval(input())) tmpa = list(map(int, input().split())) A = [0] * (n+2) A[0] = 0 A[n+1] = 0 for i in range(1,n+1,1): A[i] = tmpa[i-1] #普通に総和を出す sum = 0 for i, a in enumerate(A): if i == n+1: break #n+1はゴールなので先に行かない sum += abs(a - A[i+1]) #a:A[i] #引いて足す for i in range(1, n+1, 1): #1~Nを省いたとき nowsum = sum nowsum -= abs(A[i-1]-A[i]) nowsum -= abs(A[i]-A[i+1]) nowsum += abs(A[i-1]-A[i+1]) print(nowsum)
n = int(eval(input())) A = [0] + list(map(int, input().split())) + [0] #普通に総和を出す sum = 0 for i, a in enumerate(A): if i == n+1: break #n+1はゴールなので先に行かない sum += abs(a - A[i+1]) #a:A[i] #引いて足す for i in range(1, n+1, 1): #1~Nを省いたとき nowsum = sum nowsum -= abs(A[i-1]-A[i]) nowsum -= abs(A[i]-A[i+1]) nowsum += abs(A[i-1]-A[i+1]) print(nowsum)
21
16
440
364
n = int(eval(input())) tmpa = list(map(int, input().split())) A = [0] * (n + 2) A[0] = 0 A[n + 1] = 0 for i in range(1, n + 1, 1): A[i] = tmpa[i - 1] # 普通に総和を出す sum = 0 for i, a in enumerate(A): if i == n + 1: break # n+1はゴールなので先に行かない sum += abs(a - A[i + 1]) # a:A[i] # 引いて足す for i in range(1, n + 1, 1): # 1~Nを省いたとき nowsum = sum nowsum -= abs(A[i - 1] - A[i]) nowsum -= abs(A[i] - A[i + 1]) nowsum += abs(A[i - 1] - A[i + 1]) print(nowsum)
n = int(eval(input())) A = [0] + list(map(int, input().split())) + [0] # 普通に総和を出す sum = 0 for i, a in enumerate(A): if i == n + 1: break # n+1はゴールなので先に行かない sum += abs(a - A[i + 1]) # a:A[i] # 引いて足す for i in range(1, n + 1, 1): # 1~Nを省いたとき nowsum = sum nowsum -= abs(A[i - 1] - A[i]) nowsum -= abs(A[i] - A[i + 1]) nowsum += abs(A[i - 1] - A[i + 1]) print(nowsum)
false
23.809524
[ "-tmpa = list(map(int, input().split()))", "-A = [0] * (n + 2)", "-A[0] = 0", "-A[n + 1] = 0", "-for i in range(1, n + 1, 1):", "- A[i] = tmpa[i - 1]", "+A = [0] + list(map(int, input().split())) + [0]" ]
false
0.039261
0.038409
1.022174
[ "s488520765", "s974321423" ]
u098968285
p03639
python
s785065239
s719315810
230
71
63,472
11,480
Accepted
Accepted
69.13
# def makelist(n, m): # return [[0 for i in range(m)] for j in range(n)] # n = int(input()) # a, b = map(int, input().split()) # s = input() yes = "Yes" no = "No" N = int(eval(input())) a = list(map(int, input().split())) four = 0 two = 0 none = 0 for e in a: if e % 4 == 0: four += 1 elif e % 2 != 0: none += 1 else: two += 1 if four >= none or (two == 0 and four+1 >= none): print(yes) else: print(no)
N = int(eval(input())) four = 0 two = 0 one = 0 for e in map(int, input().split()): if e % 4 == 0: four += 1 elif e % 2 != 0: one += 1 else: two += 1 if four >= one: print("Yes") else: if two == 0 and four == one - 1: print("Yes") else: print("No")
30
18
446
324
# def makelist(n, m): # return [[0 for i in range(m)] for j in range(n)] # n = int(input()) # a, b = map(int, input().split()) # s = input() yes = "Yes" no = "No" N = int(eval(input())) a = list(map(int, input().split())) four = 0 two = 0 none = 0 for e in a: if e % 4 == 0: four += 1 elif e % 2 != 0: none += 1 else: two += 1 if four >= none or (two == 0 and four + 1 >= none): print(yes) else: print(no)
N = int(eval(input())) four = 0 two = 0 one = 0 for e in map(int, input().split()): if e % 4 == 0: four += 1 elif e % 2 != 0: one += 1 else: two += 1 if four >= one: print("Yes") else: if two == 0 and four == one - 1: print("Yes") else: print("No")
false
40
[ "-# def makelist(n, m):", "-# \treturn [[0 for i in range(m)] for j in range(n)]", "-# n = int(input())", "-# a, b = map(int, input().split())", "-# s = input()", "-yes = \"Yes\"", "-no = \"No\"", "-a = list(map(int, input().split()))", "-none = 0", "-for e in a:", "+one = 0", "+for e in map(int, input().split()):", "- none += 1", "+ one += 1", "-if four >= none or (two == 0 and four + 1 >= none):", "- print(yes)", "+if four >= one:", "+ print(\"Yes\")", "- print(no)", "+ if two == 0 and four == one - 1:", "+ print(\"Yes\")", "+ else:", "+ print(\"No\")" ]
false
0.0569
0.042884
1.326851
[ "s785065239", "s719315810" ]
u022979415
p03504
python
s788163126
s305386778
459
326
35,388
28,608
Accepted
Accepted
28.98
from heapq import heappop, heappush def main(): n, c = list(map(int, input().split())) program = [[] for _ in range(c)] for _ in range(n): s, t, cc = list(map(int, input().split())) cc -= 1 s *= 2 t *= 2 program[cc].append([s - 1, t]) all_p = [] for i in range(c): if len(program[i]) == 0: continue now = program[i] now.sort(key=lambda x: x[1]) last_begin, last_end = now[0] for begin, end in now[1:]: if begin + 1 == last_end: last_end = end else: all_p.append([last_begin, last_end, i]) last_begin = begin last_end = end all_p.append([last_begin, last_end, i]) all_p.sort() q = [(-1, -1)] for begin, end, now_channel in all_p: last_end, last_channel = q[0] if last_end < begin or now_channel == last_channel: heappop(q) heappush(q, (end, now_channel)) print((len(q))) if __name__ == '__main__': main()
from itertools import accumulate def main(): n, c = list(map(int, input().split())) p = [[] for _ in range(c + 1)] for _ in range(n): *st, cc = list(map(int, input().split())) p[cc].append(st) all_p = [0] * (10 ** 5 + 10) for pp in p: if len(pp) == 0: continue pp.sort() last_start, last_end = pp[0] for start, end in pp[1:]: if start == last_end: last_end = end else: all_p[last_start - 1] += 1 all_p[last_end] -= 1 last_start, last_end = start, end all_p[last_start - 1] += 1 all_p[last_end] -= 1 print((max(accumulate(all_p)))) if __name__ == '__main__': main()
39
29
1,096
775
from heapq import heappop, heappush def main(): n, c = list(map(int, input().split())) program = [[] for _ in range(c)] for _ in range(n): s, t, cc = list(map(int, input().split())) cc -= 1 s *= 2 t *= 2 program[cc].append([s - 1, t]) all_p = [] for i in range(c): if len(program[i]) == 0: continue now = program[i] now.sort(key=lambda x: x[1]) last_begin, last_end = now[0] for begin, end in now[1:]: if begin + 1 == last_end: last_end = end else: all_p.append([last_begin, last_end, i]) last_begin = begin last_end = end all_p.append([last_begin, last_end, i]) all_p.sort() q = [(-1, -1)] for begin, end, now_channel in all_p: last_end, last_channel = q[0] if last_end < begin or now_channel == last_channel: heappop(q) heappush(q, (end, now_channel)) print((len(q))) if __name__ == "__main__": main()
from itertools import accumulate def main(): n, c = list(map(int, input().split())) p = [[] for _ in range(c + 1)] for _ in range(n): *st, cc = list(map(int, input().split())) p[cc].append(st) all_p = [0] * (10**5 + 10) for pp in p: if len(pp) == 0: continue pp.sort() last_start, last_end = pp[0] for start, end in pp[1:]: if start == last_end: last_end = end else: all_p[last_start - 1] += 1 all_p[last_end] -= 1 last_start, last_end = start, end all_p[last_start - 1] += 1 all_p[last_end] -= 1 print((max(accumulate(all_p)))) if __name__ == "__main__": main()
false
25.641026
[ "-from heapq import heappop, heappush", "+from itertools import accumulate", "- program = [[] for _ in range(c)]", "+ p = [[] for _ in range(c + 1)]", "- s, t, cc = list(map(int, input().split()))", "- cc -= 1", "- s *= 2", "- t *= 2", "- program[cc].append([s - 1, t])", "- all_p = []", "- for i in range(c):", "- if len(program[i]) == 0:", "+ *st, cc = list(map(int, input().split()))", "+ p[cc].append(st)", "+ all_p = [0] * (10**5 + 10)", "+ for pp in p:", "+ if len(pp) == 0:", "- now = program[i]", "- now.sort(key=lambda x: x[1])", "- last_begin, last_end = now[0]", "- for begin, end in now[1:]:", "- if begin + 1 == last_end:", "+ pp.sort()", "+ last_start, last_end = pp[0]", "+ for start, end in pp[1:]:", "+ if start == last_end:", "- all_p.append([last_begin, last_end, i])", "- last_begin = begin", "- last_end = end", "- all_p.append([last_begin, last_end, i])", "- all_p.sort()", "- q = [(-1, -1)]", "- for begin, end, now_channel in all_p:", "- last_end, last_channel = q[0]", "- if last_end < begin or now_channel == last_channel:", "- heappop(q)", "- heappush(q, (end, now_channel))", "- print((len(q)))", "+ all_p[last_start - 1] += 1", "+ all_p[last_end] -= 1", "+ last_start, last_end = start, end", "+ all_p[last_start - 1] += 1", "+ all_p[last_end] -= 1", "+ print((max(accumulate(all_p))))" ]
false
0.041874
0.039517
1.059643
[ "s788163126", "s305386778" ]
u780475861
p02814
python
s789076430
s569117791
208
117
14,532
14,508
Accepted
Accepted
43.75
import sys readline = sys.stdin.buffer.readline from fractions import gcd from functools import reduce n,m = list(map(int,readline().split())) alst = list(map(int,readline().split())) def lcm(x,y): g=gcd(x,y) if x//g %2==0 or y//g%2==0: return 0 return x*y//g g=reduce(lcm,alst) if g==0: print((0)) quit() else: res=(2*m//g) print((res//2+res%2))
import sys read = sys.stdin.buffer.read from fractions import gcd from functools import reduce n,m,*alst = list(map(int,read().split())) mm=2*m def lcm(x,y): g=gcd(x,y) if x//g %2==0 or y//g%2==0: return 0 g=x*y//g if g>mm: return 0 return g g=reduce(lcm,alst) if g==0: print((0)) quit() else: res=(mm//g) print((res//2+res%2))
20
22
375
372
import sys readline = sys.stdin.buffer.readline from fractions import gcd from functools import reduce n, m = list(map(int, readline().split())) alst = list(map(int, readline().split())) def lcm(x, y): g = gcd(x, y) if x // g % 2 == 0 or y // g % 2 == 0: return 0 return x * y // g g = reduce(lcm, alst) if g == 0: print((0)) quit() else: res = 2 * m // g print((res // 2 + res % 2))
import sys read = sys.stdin.buffer.read from fractions import gcd from functools import reduce n, m, *alst = list(map(int, read().split())) mm = 2 * m def lcm(x, y): g = gcd(x, y) if x // g % 2 == 0 or y // g % 2 == 0: return 0 g = x * y // g if g > mm: return 0 return g g = reduce(lcm, alst) if g == 0: print((0)) quit() else: res = mm // g print((res // 2 + res % 2))
false
9.090909
[ "-readline = sys.stdin.buffer.readline", "+read = sys.stdin.buffer.read", "-n, m = list(map(int, readline().split()))", "-alst = list(map(int, readline().split()))", "+n, m, *alst = list(map(int, read().split()))", "+mm = 2 * m", "- return x * y // g", "+ g = x * y // g", "+ if g > mm:", "+ return 0", "+ return g", "- res = 2 * m // g", "+ res = mm // g" ]
false
0.057574
0.04843
1.188795
[ "s789076430", "s569117791" ]
u645436608
p02721
python
s752593698
s106873241
525
363
20,612
20,616
Accepted
Accepted
30.86
n, k, c = list(map(int, input().split())) s = eval(input()) l = [-1] * k r = [-1] * k nowl = 0 indl = 0 while nowl < n and indl < k: for i in range(nowl, n): if s[i] == "o": l[indl] = i nowl = i + c + 1 indl += 1 break nowr = n - 1 indr = k - 1 while nowr >= 0 and indr >= 0: for i in range(nowr, -1, -1): if s[i] == "o": r[indr] = i nowr = i - c - 1 indr -= 1 break for i in range(k): if l[i] == r[i]: print((l[i] + 1))
N, K, C = list(map(int, input().split())) S = eval(input()) L = [-1] * K R = [-1] * K L_index = 0 L_count = 0 R_index = N - 1 R_count = K - 1 while L_index < N and L_count < K: if S[L_index] == "o": L[L_count] = L_index L_index += (C + 1) L_count += 1 else: L_index += 1 while R_index >= 0 and R_count >= 0: if S[R_index] == "o": R[R_count] = R_index R_index -= (C + 1) R_count -= 1 else: R_index -= 1 for i in range(K): if L[i] == R[i]: print((L[i] + 1))
25
27
563
561
n, k, c = list(map(int, input().split())) s = eval(input()) l = [-1] * k r = [-1] * k nowl = 0 indl = 0 while nowl < n and indl < k: for i in range(nowl, n): if s[i] == "o": l[indl] = i nowl = i + c + 1 indl += 1 break nowr = n - 1 indr = k - 1 while nowr >= 0 and indr >= 0: for i in range(nowr, -1, -1): if s[i] == "o": r[indr] = i nowr = i - c - 1 indr -= 1 break for i in range(k): if l[i] == r[i]: print((l[i] + 1))
N, K, C = list(map(int, input().split())) S = eval(input()) L = [-1] * K R = [-1] * K L_index = 0 L_count = 0 R_index = N - 1 R_count = K - 1 while L_index < N and L_count < K: if S[L_index] == "o": L[L_count] = L_index L_index += C + 1 L_count += 1 else: L_index += 1 while R_index >= 0 and R_count >= 0: if S[R_index] == "o": R[R_count] = R_index R_index -= C + 1 R_count -= 1 else: R_index -= 1 for i in range(K): if L[i] == R[i]: print((L[i] + 1))
false
7.407407
[ "-n, k, c = list(map(int, input().split()))", "-s = eval(input())", "-l = [-1] * k", "-r = [-1] * k", "-nowl = 0", "-indl = 0", "-while nowl < n and indl < k:", "- for i in range(nowl, n):", "- if s[i] == \"o\":", "- l[indl] = i", "- nowl = i + c + 1", "- indl += 1", "- break", "-nowr = n - 1", "-indr = k - 1", "-while nowr >= 0 and indr >= 0:", "- for i in range(nowr, -1, -1):", "- if s[i] == \"o\":", "- r[indr] = i", "- nowr = i - c - 1", "- indr -= 1", "- break", "-for i in range(k):", "- if l[i] == r[i]:", "- print((l[i] + 1))", "+N, K, C = list(map(int, input().split()))", "+S = eval(input())", "+L = [-1] * K", "+R = [-1] * K", "+L_index = 0", "+L_count = 0", "+R_index = N - 1", "+R_count = K - 1", "+while L_index < N and L_count < K:", "+ if S[L_index] == \"o\":", "+ L[L_count] = L_index", "+ L_index += C + 1", "+ L_count += 1", "+ else:", "+ L_index += 1", "+while R_index >= 0 and R_count >= 0:", "+ if S[R_index] == \"o\":", "+ R[R_count] = R_index", "+ R_index -= C + 1", "+ R_count -= 1", "+ else:", "+ R_index -= 1", "+for i in range(K):", "+ if L[i] == R[i]:", "+ print((L[i] + 1))" ]
false
0.047051
0.039831
1.181246
[ "s752593698", "s106873241" ]
u680851063
p02995
python
s251321142
s382585600
39
35
5,104
5,104
Accepted
Accepted
10.26
a, b, c, d = list(map(int, input().split())) from fractions import gcd #lcm = c * d // gcd(c, d) lcm = int(c * d / gcd(c, d)) a_num = (a-1)//c + (a-1)//d - (a-1)//lcm b_num = (b)//c + (b)//d - (b)//lcm print((b-a+1 - (b_num - a_num)))
a, b, c, d = list(map(int, input().split())) from fractions import gcd lcm = c * d // gcd(c, d) #lcm = int(c * d / gcd(c, d)) a_num = (a-1)//c + (a-1)//d - (a-1)//lcm b_num = (b)//c + (b)//d - (b)//lcm print((b-a+1 - (b_num - a_num)))
10
10
238
238
a, b, c, d = list(map(int, input().split())) from fractions import gcd # lcm = c * d // gcd(c, d) lcm = int(c * d / gcd(c, d)) a_num = (a - 1) // c + (a - 1) // d - (a - 1) // lcm b_num = (b) // c + (b) // d - (b) // lcm print((b - a + 1 - (b_num - a_num)))
a, b, c, d = list(map(int, input().split())) from fractions import gcd lcm = c * d // gcd(c, d) # lcm = int(c * d / gcd(c, d)) a_num = (a - 1) // c + (a - 1) // d - (a - 1) // lcm b_num = (b) // c + (b) // d - (b) // lcm print((b - a + 1 - (b_num - a_num)))
false
0
[ "-# lcm = c * d // gcd(c, d)", "-lcm = int(c * d / gcd(c, d))", "+lcm = c * d // gcd(c, d)", "+# lcm = int(c * d / gcd(c, d))" ]
false
0.064088
0.063591
1.00782
[ "s251321142", "s382585600" ]
u893063840
p03327
python
s809521404
s927888464
19
17
3,316
2,940
Accepted
Accepted
10.53
n = int(eval(input())) if n <= 999: print("ABC") else: print("ABD")
n = int(eval(input())) if n < 1000: ans = "ABC" else: ans = "ABD" print(ans)
6
7
76
86
n = int(eval(input())) if n <= 999: print("ABC") else: print("ABD")
n = int(eval(input())) if n < 1000: ans = "ABC" else: ans = "ABD" print(ans)
false
14.285714
[ "-if n <= 999:", "- print(\"ABC\")", "+if n < 1000:", "+ ans = \"ABC\"", "- print(\"ABD\")", "+ ans = \"ABD\"", "+print(ans)" ]
false
0.043989
0.050967
0.86308
[ "s809521404", "s927888464" ]
u918601425
p03078
python
s491916630
s096477236
752
244
164,488
46,588
Accepted
Accepted
67.55
X,Y,Z,K=[int(s) for s in input().split()] xls=sorted([int(s) for s in input().split()],reverse=True) yls=sorted([int(s) for s in input().split()],reverse=True) zls=sorted([int(s) for s in input().split()],reverse=True) xyls=[] for x in xls[:K]: for y in yls[:K]: xyls.append(x+y) xyls=sorted(xyls,reverse=True) cake=[] for xy in xyls[:K]: for z in zls[:K]: cake.append(xy+z) cake=sorted(cake,reverse=True) for i in range(K): print((cake[i]))
X,Y,Z,K=[int(s) for s in input().split()] xls=sorted([int(s) for s in input().split()],reverse=True) yls=sorted([int(s) for s in input().split()],reverse=True) zls=sorted([int(s) for s in input().split()],reverse=True) cake=[] for a in range(X): for b in range(Y): ab=(a+1)*(b+1) for c in range(Z): if ab*(c+1)>K: break cake.append(xls[a]+yls[b]+zls[c]) if ab>K: break cake=sorted(cake,reverse=True) for i in range(K): print((cake[i]))
16
17
468
491
X, Y, Z, K = [int(s) for s in input().split()] xls = sorted([int(s) for s in input().split()], reverse=True) yls = sorted([int(s) for s in input().split()], reverse=True) zls = sorted([int(s) for s in input().split()], reverse=True) xyls = [] for x in xls[:K]: for y in yls[:K]: xyls.append(x + y) xyls = sorted(xyls, reverse=True) cake = [] for xy in xyls[:K]: for z in zls[:K]: cake.append(xy + z) cake = sorted(cake, reverse=True) for i in range(K): print((cake[i]))
X, Y, Z, K = [int(s) for s in input().split()] xls = sorted([int(s) for s in input().split()], reverse=True) yls = sorted([int(s) for s in input().split()], reverse=True) zls = sorted([int(s) for s in input().split()], reverse=True) cake = [] for a in range(X): for b in range(Y): ab = (a + 1) * (b + 1) for c in range(Z): if ab * (c + 1) > K: break cake.append(xls[a] + yls[b] + zls[c]) if ab > K: break cake = sorted(cake, reverse=True) for i in range(K): print((cake[i]))
false
5.882353
[ "-xyls = []", "-for x in xls[:K]:", "- for y in yls[:K]:", "- xyls.append(x + y)", "-xyls = sorted(xyls, reverse=True)", "-for xy in xyls[:K]:", "- for z in zls[:K]:", "- cake.append(xy + z)", "+for a in range(X):", "+ for b in range(Y):", "+ ab = (a + 1) * (b + 1)", "+ for c in range(Z):", "+ if ab * (c + 1) > K:", "+ break", "+ cake.append(xls[a] + yls[b] + zls[c])", "+ if ab > K:", "+ break" ]
false
0.036065
0.044502
0.810411
[ "s491916630", "s096477236" ]
u399298563
p04001
python
s134130410
s907493830
181
167
38,384
38,256
Accepted
Accepted
7.73
S = eval(input()) if len(S) == 1: print((int(S))) exit() else: def count(n): if len(n) == 1: return 0 else: a = 0 for i in range(1, len(n)): a += int(n[:i]) * 2 ** (len(n) - 1 - i) + int(n[i:]) + count(n[i:]) return a ans = int(S) + count(S) print(ans)
s=eval(input()) if len(s)==1: print((int(s))) else: def count(num): # basecase if len(num)==1: return 0 else: a=0 for j in range(1,len(num)): a+=int(num[:j])*2**(len(num[j:])-1)+int(num[j:])+count(num[j:]) return a ans=int(s)+count(s) print(ans)
15
17
308
363
S = eval(input()) if len(S) == 1: print((int(S))) exit() else: def count(n): if len(n) == 1: return 0 else: a = 0 for i in range(1, len(n)): a += int(n[:i]) * 2 ** (len(n) - 1 - i) + int(n[i:]) + count(n[i:]) return a ans = int(S) + count(S) print(ans)
s = eval(input()) if len(s) == 1: print((int(s))) else: def count(num): # basecase if len(num) == 1: return 0 else: a = 0 for j in range(1, len(num)): a += ( int(num[:j]) * 2 ** (len(num[j:]) - 1) + int(num[j:]) + count(num[j:]) ) return a ans = int(s) + count(s) print(ans)
false
11.764706
[ "-S = eval(input())", "-if len(S) == 1:", "- print((int(S)))", "- exit()", "+s = eval(input())", "+if len(s) == 1:", "+ print((int(s)))", "- def count(n):", "- if len(n) == 1:", "+ def count(num):", "+ # basecase", "+ if len(num) == 1:", "- for i in range(1, len(n)):", "- a += int(n[:i]) * 2 ** (len(n) - 1 - i) + int(n[i:]) + count(n[i:])", "+ for j in range(1, len(num)):", "+ a += (", "+ int(num[:j]) * 2 ** (len(num[j:]) - 1)", "+ + int(num[j:])", "+ + count(num[j:])", "+ )", "- ans = int(S) + count(S)", "+ ans = int(s) + count(s)" ]
false
0.087963
0.090328
0.97381
[ "s134130410", "s907493830" ]
u387774811
p02684
python
s372789990
s340394791
751
448
310,180
217,248
Accepted
Accepted
40.35
N,K=list(map(int,input().split())) T=str(bin(K)) S=len(T)-2 A = list(map(int,input().split())) lst=[[0 for e in range(N+1)] for f in range(S)] for i in range(1,N+1): lst[0][i]=A[i-1] for j in range(1,S): for i in range(1,N+1): lst[j][i]=lst[j-1][lst[j-1][i]] ans=[[e for e in range(N+1)] for f in range(S+1)] for k in range(S): if int(T[k+2])==1: for l in range(1,N+1): ans[k+1][l]=lst[S-1-k][ans[k][l]] else: for l in range(1,N+1): ans[k+1][l]=ans[k][l] print((ans[S][1]))
N,K=list(map(int,input().split())) T=str(bin(K)) S=len(T)-2 A = list(map(int,input().split())) lst=[[0 for e in range(N+1)] for f in range(S)] for i in range(1,N+1): lst[0][i]=A[i-1] for j in range(1,S): for i in range(1,N+1): lst[j][i]=lst[j-1][lst[j-1][i]] ans=1 for k in range(S): if int(T[k+2])==1: ans=lst[S-1-k][ans] print(ans)
19
15
500
348
N, K = list(map(int, input().split())) T = str(bin(K)) S = len(T) - 2 A = list(map(int, input().split())) lst = [[0 for e in range(N + 1)] for f in range(S)] for i in range(1, N + 1): lst[0][i] = A[i - 1] for j in range(1, S): for i in range(1, N + 1): lst[j][i] = lst[j - 1][lst[j - 1][i]] ans = [[e for e in range(N + 1)] for f in range(S + 1)] for k in range(S): if int(T[k + 2]) == 1: for l in range(1, N + 1): ans[k + 1][l] = lst[S - 1 - k][ans[k][l]] else: for l in range(1, N + 1): ans[k + 1][l] = ans[k][l] print((ans[S][1]))
N, K = list(map(int, input().split())) T = str(bin(K)) S = len(T) - 2 A = list(map(int, input().split())) lst = [[0 for e in range(N + 1)] for f in range(S)] for i in range(1, N + 1): lst[0][i] = A[i - 1] for j in range(1, S): for i in range(1, N + 1): lst[j][i] = lst[j - 1][lst[j - 1][i]] ans = 1 for k in range(S): if int(T[k + 2]) == 1: ans = lst[S - 1 - k][ans] print(ans)
false
21.052632
[ "-ans = [[e for e in range(N + 1)] for f in range(S + 1)]", "+ans = 1", "- for l in range(1, N + 1):", "- ans[k + 1][l] = lst[S - 1 - k][ans[k][l]]", "- else:", "- for l in range(1, N + 1):", "- ans[k + 1][l] = ans[k][l]", "-print((ans[S][1]))", "+ ans = lst[S - 1 - k][ans]", "+print(ans)" ]
false
0.079396
0.097792
0.811885
[ "s372789990", "s340394791" ]
u887207211
p03545
python
s622884472
s934290891
20
18
3,188
3,060
Accepted
Accepted
10
import itertools A, B, C, D = list(eval(input())) op = ['+','-'] for op1,op2,op3 in itertools.product(op,op,op): x = A + op1 + B + op2 + C + op3 + D if(eval(x) == 7): print((x + "=7")) break
N = eval(input()) A, B, C, D = N[0], N[1], N[2], N[3] ops = ['+','-'] for op1 in ops: for op2 in ops: for op3 in ops: if(eval(A + op1 + B + op2 + C + op3 + D) == 7): print((A + op1 + B + op2 + C + op3 + D + "=7")) exit()
10
10
205
250
import itertools A, B, C, D = list(eval(input())) op = ["+", "-"] for op1, op2, op3 in itertools.product(op, op, op): x = A + op1 + B + op2 + C + op3 + D if eval(x) == 7: print((x + "=7")) break
N = eval(input()) A, B, C, D = N[0], N[1], N[2], N[3] ops = ["+", "-"] for op1 in ops: for op2 in ops: for op3 in ops: if eval(A + op1 + B + op2 + C + op3 + D) == 7: print((A + op1 + B + op2 + C + op3 + D + "=7")) exit()
false
0
[ "-import itertools", "-", "-A, B, C, D = list(eval(input()))", "-op = [\"+\", \"-\"]", "-for op1, op2, op3 in itertools.product(op, op, op):", "- x = A + op1 + B + op2 + C + op3 + D", "- if eval(x) == 7:", "- print((x + \"=7\"))", "- break", "+N = eval(input())", "+A, B, C, D = N[0], N[1], N[2], N[3]", "+ops = [\"+\", \"-\"]", "+for op1 in ops:", "+ for op2 in ops:", "+ for op3 in ops:", "+ if eval(A + op1 + B + op2 + C + op3 + D) == 7:", "+ print((A + op1 + B + op2 + C + op3 + D + \"=7\"))", "+ exit()" ]
false
0.094366
0.0485
1.94569
[ "s622884472", "s934290891" ]
u353919145
p02622
python
s007571012
s810228613
63
47
9,276
9,340
Accepted
Accepted
25.4
S = eval(input()) T = eval(input()) if len(S) != len(T): quit() sum = 0 for i in range(len(S)): if T[i] != S[i]: sum = sum + 1 print(sum)
def main(): s = eval(input()) t = eval(input()) count = 0 for i in range(len(s)): if s[i] != t[i]: count += 1 print(count) if __name__ == "__main__": main()
8
16
144
233
S = eval(input()) T = eval(input()) if len(S) != len(T): quit() sum = 0 for i in range(len(S)): if T[i] != S[i]: sum = sum + 1 print(sum)
def main(): s = eval(input()) t = eval(input()) count = 0 for i in range(len(s)): if s[i] != t[i]: count += 1 print(count) if __name__ == "__main__": main()
false
50
[ "-S = eval(input())", "-T = eval(input())", "-if len(S) != len(T):", "- quit()", "-sum = 0", "-for i in range(len(S)):", "- if T[i] != S[i]:", "- sum = sum + 1", "-print(sum)", "+def main():", "+ s = eval(input())", "+ t = eval(input())", "+ count = 0", "+ for i in range(len(s)):", "+ if s[i] != t[i]:", "+ count += 1", "+ print(count)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.037783
0.03634
1.039711
[ "s007571012", "s810228613" ]
u709304134
p02713
python
s892619934
s256626023
1,887
1,181
9,176
9,184
Accepted
Accepted
37.41
from math import gcd K = int(eval(input())) ans = 0 for i in range(1,K+1): for j in range(1,K+1): for k in range(1,K+1): ans += gcd(gcd(i,j),k) print (ans)
from math import gcd K = int(eval(input())) ans = 0 for i in range(1,K+1): for j in range(1,K+1): gcd_ij = gcd(i, j) for k in range(1,K+1): ans += gcd(gcd_ij, k) print (ans)
8
9
180
207
from math import gcd K = int(eval(input())) ans = 0 for i in range(1, K + 1): for j in range(1, K + 1): for k in range(1, K + 1): ans += gcd(gcd(i, j), k) print(ans)
from math import gcd K = int(eval(input())) ans = 0 for i in range(1, K + 1): for j in range(1, K + 1): gcd_ij = gcd(i, j) for k in range(1, K + 1): ans += gcd(gcd_ij, k) print(ans)
false
11.111111
[ "+ gcd_ij = gcd(i, j)", "- ans += gcd(gcd(i, j), k)", "+ ans += gcd(gcd_ij, k)" ]
false
0.00819
0.192211
0.04261
[ "s892619934", "s256626023" ]
u756518877
p03012
python
s590138428
s637798696
20
17
3,064
3,060
Accepted
Accepted
15
# -*- coding: utf-8 -*- n=int(eval(input())) W=list(map(int,input().split())) t=0 while sum(W[:t])<sum(W[t:]) and t<n: t=t+1 print((min(abs(sum(W[:t])-sum(W[t:])),abs(sum(W[:t-1])-sum(W[t-1:])))))
# -*- coding: utf-8 -*- n=int(eval(input())) W=list(map(int,input().split())) for i in range(n): if sum(W[:i])>sum(W[i:]) or i==n-1: print((min(sum(W[i-1:])-sum(W[:i-1]),sum(W[:i])-sum(W[i:])))) break
7
7
196
218
# -*- coding: utf-8 -*- n = int(eval(input())) W = list(map(int, input().split())) t = 0 while sum(W[:t]) < sum(W[t:]) and t < n: t = t + 1 print((min(abs(sum(W[:t]) - sum(W[t:])), abs(sum(W[: t - 1]) - sum(W[t - 1 :])))))
# -*- coding: utf-8 -*- n = int(eval(input())) W = list(map(int, input().split())) for i in range(n): if sum(W[:i]) > sum(W[i:]) or i == n - 1: print((min(sum(W[i - 1 :]) - sum(W[: i - 1]), sum(W[:i]) - sum(W[i:])))) break
false
0
[ "-t = 0", "-while sum(W[:t]) < sum(W[t:]) and t < n:", "- t = t + 1", "-print((min(abs(sum(W[:t]) - sum(W[t:])), abs(sum(W[: t - 1]) - sum(W[t - 1 :])))))", "+for i in range(n):", "+ if sum(W[:i]) > sum(W[i:]) or i == n - 1:", "+ print((min(sum(W[i - 1 :]) - sum(W[: i - 1]), sum(W[:i]) - sum(W[i:]))))", "+ break" ]
false
0.03999
0.038664
1.034296
[ "s590138428", "s637798696" ]
u696444274
p03042
python
s606041956
s491936235
36
17
5,148
3,060
Accepted
Accepted
52.78
import math import itertools import statistics #n = int(input()) s=eval(input()) a = int(s[0])*10+int(s[1]) b = int(s[2])*10+int(s[3]) # yymm yy>12 and 12>=mm>=1 # mmyy 1<=mm<=12 and yy > 12 # doble 1<=yy<=12 and 1<=mm<=12 # na mm=0 and yy?12 if 0<a<13 and 0<b<13: print("AMBIGUOUS") elif a > 12 and 0<b<13: print("YYMM") elif 0<a<13 and b > 13: print("MMYY") else: if 0<a<13 and b==0: print("MMYY") elif a==0 and 0<b<13: print("YYMM") else: print("NA")
s = eval(input()) start = int(s[0]+s[1]) end = int(s[2]+s[3]) if 1 <= start <= 12 and 1 <= end <= 12: print("AMBIGUOUS") elif 1 <= start <= 12 and (end > 12 or end == 0): print("MMYY") elif (start > 12 or start == 0) and 1 <= end <= 12: print("YYMM") else: print("NA")
24
12
523
291
import math import itertools import statistics # n = int(input()) s = eval(input()) a = int(s[0]) * 10 + int(s[1]) b = int(s[2]) * 10 + int(s[3]) # yymm yy>12 and 12>=mm>=1 # mmyy 1<=mm<=12 and yy > 12 # doble 1<=yy<=12 and 1<=mm<=12 # na mm=0 and yy?12 if 0 < a < 13 and 0 < b < 13: print("AMBIGUOUS") elif a > 12 and 0 < b < 13: print("YYMM") elif 0 < a < 13 and b > 13: print("MMYY") else: if 0 < a < 13 and b == 0: print("MMYY") elif a == 0 and 0 < b < 13: print("YYMM") else: print("NA")
s = eval(input()) start = int(s[0] + s[1]) end = int(s[2] + s[3]) if 1 <= start <= 12 and 1 <= end <= 12: print("AMBIGUOUS") elif 1 <= start <= 12 and (end > 12 or end == 0): print("MMYY") elif (start > 12 or start == 0) and 1 <= end <= 12: print("YYMM") else: print("NA")
false
50
[ "-import math", "-import itertools", "-import statistics", "-", "-# n = int(input())", "-a = int(s[0]) * 10 + int(s[1])", "-b = int(s[2]) * 10 + int(s[3])", "-# yymm yy>12 and 12>=mm>=1", "-# mmyy 1<=mm<=12 and yy > 12", "-# doble 1<=yy<=12 and 1<=mm<=12", "-# na mm=0 and yy?12", "-if 0 < a < 13 and 0 < b < 13:", "+start = int(s[0] + s[1])", "+end = int(s[2] + s[3])", "+if 1 <= start <= 12 and 1 <= end <= 12:", "-elif a > 12 and 0 < b < 13:", "+elif 1 <= start <= 12 and (end > 12 or end == 0):", "+ print(\"MMYY\")", "+elif (start > 12 or start == 0) and 1 <= end <= 12:", "-elif 0 < a < 13 and b > 13:", "- print(\"MMYY\")", "- if 0 < a < 13 and b == 0:", "- print(\"MMYY\")", "- elif a == 0 and 0 < b < 13:", "- print(\"YYMM\")", "- else:", "- print(\"NA\")", "+ print(\"NA\")" ]
false
0.03795
0.037078
1.023523
[ "s606041956", "s491936235" ]
u624475441
p03611
python
s117664322
s971609412
91
66
14,856
14,732
Accepted
Accepted
27.47
cnt = [0]*10**5; eval(input()) a = list(map(int,input().split())) for x in a:cnt[x]+=1 print((max(sum(cnt[i:i+3])for i in range(10**5))))
cnt = [0]*10**5; eval(input()) a = list(map(int,input().split())) for x in a:cnt[x]+=1 print((max(list(map(sum,list(zip(cnt,cnt[1:],cnt[2:])))))))
4
4
132
129
cnt = [0] * 10**5 eval(input()) a = list(map(int, input().split())) for x in a: cnt[x] += 1 print((max(sum(cnt[i : i + 3]) for i in range(10**5))))
cnt = [0] * 10**5 eval(input()) a = list(map(int, input().split())) for x in a: cnt[x] += 1 print((max(list(map(sum, list(zip(cnt, cnt[1:], cnt[2:])))))))
false
0
[ "-print((max(sum(cnt[i : i + 3]) for i in range(10**5))))", "+print((max(list(map(sum, list(zip(cnt, cnt[1:], cnt[2:])))))))" ]
false
0.087954
0.111419
0.789395
[ "s117664322", "s971609412" ]
u077898957
p03338
python
s224849126
s301976209
309
18
21,500
3,060
Accepted
Accepted
94.17
import numpy as np import sys n = int(eval(input())) s = eval(input()) ans = 0 for i in range(n-2): count = len(set(s[:i+1]))+len(set(s[i+1:]))-len(set(list(set(s[:i+1]))+list(set(s[i+1:])))) ans = max(ans,count) print(ans)
n=int(eval(input())) s=eval(input()) ans=0 for i in range(n): x=list(set(s[:i+1])) y=list(set(s[i+1:])) cnt=0 for j in range(min(len(x),len(y))): if i<=n//2: if x[j] in y: cnt+=1 else: if y[j] in x: cnt+=1 ans=max(ans,cnt) print(ans)
9
16
228
329
import numpy as np import sys n = int(eval(input())) s = eval(input()) ans = 0 for i in range(n - 2): count = ( len(set(s[: i + 1])) + len(set(s[i + 1 :])) - len(set(list(set(s[: i + 1])) + list(set(s[i + 1 :])))) ) ans = max(ans, count) print(ans)
n = int(eval(input())) s = eval(input()) ans = 0 for i in range(n): x = list(set(s[: i + 1])) y = list(set(s[i + 1 :])) cnt = 0 for j in range(min(len(x), len(y))): if i <= n // 2: if x[j] in y: cnt += 1 else: if y[j] in x: cnt += 1 ans = max(ans, cnt) print(ans)
false
43.75
[ "-import numpy as np", "-import sys", "-", "-for i in range(n - 2):", "- count = (", "- len(set(s[: i + 1]))", "- + len(set(s[i + 1 :]))", "- - len(set(list(set(s[: i + 1])) + list(set(s[i + 1 :]))))", "- )", "- ans = max(ans, count)", "+for i in range(n):", "+ x = list(set(s[: i + 1]))", "+ y = list(set(s[i + 1 :]))", "+ cnt = 0", "+ for j in range(min(len(x), len(y))):", "+ if i <= n // 2:", "+ if x[j] in y:", "+ cnt += 1", "+ else:", "+ if y[j] in x:", "+ cnt += 1", "+ ans = max(ans, cnt)" ]
false
0.036459
0.039706
0.918224
[ "s224849126", "s301976209" ]
u498487134
p02821
python
s620591362
s579259734
1,112
700
55,892
33,548
Accepted
Accepted
37.05
N,M = list(map(int,input().split())) A = list(map(int,input().split())) A.sort(reverse=True) #幸福度をX以上増やせる手が何通りあるか?を二分探索. #左手で握る人は線形探索,右手が二分探索で探す #最後は累積和で計算 inf = 2*10**5+1 X_top = inf X_bot = 0 #M手以上の組み合わせが作れる最大値 #幸福度をX以上挙げられる手の通り数ががMになる境界を探す while X_top - X_bot !=1: X=(X_top+X_bot)//2 num=0 for i in range(N): ok=-1 ng=N h1=A[i] #右手と左手の合計がXになる境界を探す while ng-ok!=1: med=(ok+ng)//2 h2=A[med] if h1+h2>=X: ok=med else: ng=med num+=ok+1 if num>=M: X_bot = X else: X_top = X ok_list=[0]*N #各左手に対して何個okなくみがあるか探す for i in range(N): ok=-1 ng=N h1=A[i] X = X_bot #右手と左手の合計がXになる境界を探す while ng-ok!=1: med=(ok+ng)//2 h2=A[med] if h1+h2>=X: ok=med else: ng=med ok_list[i]=ok S=[0]*(N+1) for i in range(N): S[i+1]=S[i]+A[i] ans=0 for i in range(N): ans += A[i]*(ok_list[i]+1)+S[ok_list[i]+1] if sum(ok_list)+N>M: ans-=(sum(ok_list)+N-M)*X print(ans)
import numpy as np N,M = list(map(int,input().split())) A = list(map(int,input().split())) Amax=max(A) n0 = 2**int(np.ceil(np.log2(2*Amax+1)))#Amax+1以上となる最小の2のべき乗数 Afre=np.zeros(n0).astype(int)#パワーの頻度(1~Amax+1) for i in range(N): Afre[A[i]]+=1 #astype(int)は切り捨てなので,rintで四捨五入してから. S = np.rint(np.fft.irfft(np.fft.rfft(Afre)*np.fft.rfft(Afre))).astype(int) Scum =S.cumsum()#累積和 bd = N*N-M#上からM個を取り出したい i=np.searchsorted(Scum,bd)#価値iを生み出せる組みがM個以上ある #価値iが生み出せる選び方の余分なものを引きたい remove=((Scum[-1]-Scum[i])-M)*i ans=0 for j in range(i+1,n0): ans+=S[j]*j print((ans-remove))
65
23
1,243
590
N, M = list(map(int, input().split())) A = list(map(int, input().split())) A.sort(reverse=True) # 幸福度をX以上増やせる手が何通りあるか?を二分探索. # 左手で握る人は線形探索,右手が二分探索で探す # 最後は累積和で計算 inf = 2 * 10**5 + 1 X_top = inf X_bot = 0 # M手以上の組み合わせが作れる最大値 # 幸福度をX以上挙げられる手の通り数ががMになる境界を探す while X_top - X_bot != 1: X = (X_top + X_bot) // 2 num = 0 for i in range(N): ok = -1 ng = N h1 = A[i] # 右手と左手の合計がXになる境界を探す while ng - ok != 1: med = (ok + ng) // 2 h2 = A[med] if h1 + h2 >= X: ok = med else: ng = med num += ok + 1 if num >= M: X_bot = X else: X_top = X ok_list = [0] * N # 各左手に対して何個okなくみがあるか探す for i in range(N): ok = -1 ng = N h1 = A[i] X = X_bot # 右手と左手の合計がXになる境界を探す while ng - ok != 1: med = (ok + ng) // 2 h2 = A[med] if h1 + h2 >= X: ok = med else: ng = med ok_list[i] = ok S = [0] * (N + 1) for i in range(N): S[i + 1] = S[i] + A[i] ans = 0 for i in range(N): ans += A[i] * (ok_list[i] + 1) + S[ok_list[i] + 1] if sum(ok_list) + N > M: ans -= (sum(ok_list) + N - M) * X print(ans)
import numpy as np N, M = list(map(int, input().split())) A = list(map(int, input().split())) Amax = max(A) n0 = 2 ** int(np.ceil(np.log2(2 * Amax + 1))) # Amax+1以上となる最小の2のべき乗数 Afre = np.zeros(n0).astype(int) # パワーの頻度(1~Amax+1) for i in range(N): Afre[A[i]] += 1 # astype(int)は切り捨てなので,rintで四捨五入してから. S = np.rint(np.fft.irfft(np.fft.rfft(Afre) * np.fft.rfft(Afre))).astype(int) Scum = S.cumsum() # 累積和 bd = N * N - M # 上からM個を取り出したい i = np.searchsorted(Scum, bd) # 価値iを生み出せる組みがM個以上ある # 価値iが生み出せる選び方の余分なものを引きたい remove = ((Scum[-1] - Scum[i]) - M) * i ans = 0 for j in range(i + 1, n0): ans += S[j] * j print((ans - remove))
false
64.615385
[ "+import numpy as np", "+", "-A.sort(reverse=True)", "-# 幸福度をX以上増やせる手が何通りあるか?を二分探索.", "-# 左手で握る人は線形探索,右手が二分探索で探す", "-# 最後は累積和で計算", "-inf = 2 * 10**5 + 1", "-X_top = inf", "-X_bot = 0 # M手以上の組み合わせが作れる最大値", "-# 幸福度をX以上挙げられる手の通り数ががMになる境界を探す", "-while X_top - X_bot != 1:", "- X = (X_top + X_bot) // 2", "- num = 0", "- for i in range(N):", "- ok = -1", "- ng = N", "- h1 = A[i]", "- # 右手と左手の合計がXになる境界を探す", "- while ng - ok != 1:", "- med = (ok + ng) // 2", "- h2 = A[med]", "- if h1 + h2 >= X:", "- ok = med", "- else:", "- ng = med", "- num += ok + 1", "- if num >= M:", "- X_bot = X", "- else:", "- X_top = X", "-ok_list = [0] * N", "-# 各左手に対して何個okなくみがあるか探す", "+Amax = max(A)", "+n0 = 2 ** int(np.ceil(np.log2(2 * Amax + 1))) # Amax+1以上となる最小の2のべき乗数", "+Afre = np.zeros(n0).astype(int) # パワーの頻度(1~Amax+1)", "- ok = -1", "- ng = N", "- h1 = A[i]", "- X = X_bot", "- # 右手と左手の合計がXになる境界を探す", "- while ng - ok != 1:", "- med = (ok + ng) // 2", "- h2 = A[med]", "- if h1 + h2 >= X:", "- ok = med", "- else:", "- ng = med", "- ok_list[i] = ok", "-S = [0] * (N + 1)", "-for i in range(N):", "- S[i + 1] = S[i] + A[i]", "+ Afre[A[i]] += 1", "+# astype(int)は切り捨てなので,rintで四捨五入してから.", "+S = np.rint(np.fft.irfft(np.fft.rfft(Afre) * np.fft.rfft(Afre))).astype(int)", "+Scum = S.cumsum() # 累積和", "+bd = N * N - M # 上からM個を取り出したい", "+i = np.searchsorted(Scum, bd) # 価値iを生み出せる組みがM個以上ある", "+# 価値iが生み出せる選び方の余分なものを引きたい", "+remove = ((Scum[-1] - Scum[i]) - M) * i", "-for i in range(N):", "- ans += A[i] * (ok_list[i] + 1) + S[ok_list[i] + 1]", "-if sum(ok_list) + N > M:", "- ans -= (sum(ok_list) + N - M) * X", "-print(ans)", "+for j in range(i + 1, n0):", "+ ans += S[j] * j", "+print((ans - remove))" ]
false
0.041448
0.209946
0.197422
[ "s620591362", "s579259734" ]
u899909022
p02972
python
s840966649
s181076958
1,078
958
12,088
10,612
Accepted
Accepted
11.13
N=int(eval(input())) A=list(map(int,input().split())) B=[0] * N ans = [] for i in reversed(list(range(1, N+1))): a = 0 for j in range(1, N+1): tmp = i * j if tmp > N: break a = (B[tmp-1] + a) % 2 if (A[i-1] + a) % 2 == 1: ans.append(i) B[i-1] = (A[i-1] + a) % 2 print((len(ans))) for a in ans: print(a)
N=int(eval(input())) A=list(map(int,input().split())) ans = [] for i in reversed(list(range(1, N+1))): a = A[i-1] for j in range(2, N+1): tmp = i * j if tmp > N: break a += A[tmp-1] if a % 2 == 1: ans.append(i) A[i-1] = a % 2 print((len(ans))) for a in ans: print(a)
16
16
363
331
N = int(eval(input())) A = list(map(int, input().split())) B = [0] * N ans = [] for i in reversed(list(range(1, N + 1))): a = 0 for j in range(1, N + 1): tmp = i * j if tmp > N: break a = (B[tmp - 1] + a) % 2 if (A[i - 1] + a) % 2 == 1: ans.append(i) B[i - 1] = (A[i - 1] + a) % 2 print((len(ans))) for a in ans: print(a)
N = int(eval(input())) A = list(map(int, input().split())) ans = [] for i in reversed(list(range(1, N + 1))): a = A[i - 1] for j in range(2, N + 1): tmp = i * j if tmp > N: break a += A[tmp - 1] if a % 2 == 1: ans.append(i) A[i - 1] = a % 2 print((len(ans))) for a in ans: print(a)
false
0
[ "-B = [0] * N", "- a = 0", "- for j in range(1, N + 1):", "+ a = A[i - 1]", "+ for j in range(2, N + 1):", "- a = (B[tmp - 1] + a) % 2", "- if (A[i - 1] + a) % 2 == 1:", "+ a += A[tmp - 1]", "+ if a % 2 == 1:", "- B[i - 1] = (A[i - 1] + a) % 2", "+ A[i - 1] = a % 2" ]
false
0.064524
0.062736
1.028501
[ "s840966649", "s181076958" ]
u662145476
p02923
python
s451756071
s120095464
86
79
14,252
14,252
Accepted
Accepted
8.14
import sys import math N = sys.stdin.readline() H = list(map(int, sys.stdin.readline().split(' '))) t = list(map(lambda x, y: 1 if x >= y else 0, H[:-1], H[1:])) m = 0 s = 0 for x in t: if x: s += 1 m = max(s, m) else: s = 0 print(m)
import sys import math N = sys.stdin.readline() H = list(map(int, sys.stdin.readline().split(' '))) m = 0 s = 0 for x, y in zip(H[:-1], H[1:]): if x >= y: s += 1 m = max(s, m) else: s = 0 print(m)
17
16
285
246
import sys import math N = sys.stdin.readline() H = list(map(int, sys.stdin.readline().split(" "))) t = list(map(lambda x, y: 1 if x >= y else 0, H[:-1], H[1:])) m = 0 s = 0 for x in t: if x: s += 1 m = max(s, m) else: s = 0 print(m)
import sys import math N = sys.stdin.readline() H = list(map(int, sys.stdin.readline().split(" "))) m = 0 s = 0 for x, y in zip(H[:-1], H[1:]): if x >= y: s += 1 m = max(s, m) else: s = 0 print(m)
false
5.882353
[ "-t = list(map(lambda x, y: 1 if x >= y else 0, H[:-1], H[1:]))", "-for x in t:", "- if x:", "+for x, y in zip(H[:-1], H[1:]):", "+ if x >= y:" ]
false
0.036919
0.035127
1.051034
[ "s451756071", "s120095464" ]
u966508131
p03455
python
s890762516
s401622552
173
17
38,256
2,940
Accepted
Accepted
90.17
a,b=list(map(int,input().split())) print(("Even" if a*b%2==0 else "Odd"))
a, b = list(map(int, input().split())) if a * b % 2 == 0: print('Even') else: print('Odd')
2
5
66
97
a, b = list(map(int, input().split())) print(("Even" if a * b % 2 == 0 else "Odd"))
a, b = list(map(int, input().split())) if a * b % 2 == 0: print("Even") else: print("Odd")
false
60
[ "-print((\"Even\" if a * b % 2 == 0 else \"Odd\"))", "+if a * b % 2 == 0:", "+ print(\"Even\")", "+else:", "+ print(\"Odd\")" ]
false
0.047052
0.042862
1.097747
[ "s890762516", "s401622552" ]
u391731808
p03480
python
s914907593
s208213361
37
19
3,188
3,188
Accepted
Accepted
48.65
S = eval(input()) l = len(S) i = 0 if l%2: c = S[l//2] for i in range(1,l//2+1): if S[l//2-i] != c or S[l//2 + i] != c: break else: i += 1 print((l//2+i)) else: c = S[l//2] for i in range(l//2): if S[l//2-1-i] != c or S[l//2 + i] != c: break else: i += 1 pass print((l//2 + i))
S = eval(input()) N = len(S) def f(k): s = S[-k:k] if s == "":return False return s.count(s[0])!=len(s) def binary_search(l,r,func): if func(l):return l-1 if not func(r):return r while l+1<r: i = (l+r)//2 if func(i): r = i else: l = i return l print((binary_search(0,N,f)))
20
20
382
363
S = eval(input()) l = len(S) i = 0 if l % 2: c = S[l // 2] for i in range(1, l // 2 + 1): if S[l // 2 - i] != c or S[l // 2 + i] != c: break else: i += 1 print((l // 2 + i)) else: c = S[l // 2] for i in range(l // 2): if S[l // 2 - 1 - i] != c or S[l // 2 + i] != c: break else: i += 1 pass print((l // 2 + i))
S = eval(input()) N = len(S) def f(k): s = S[-k:k] if s == "": return False return s.count(s[0]) != len(s) def binary_search(l, r, func): if func(l): return l - 1 if not func(r): return r while l + 1 < r: i = (l + r) // 2 if func(i): r = i else: l = i return l print((binary_search(0, N, f)))
false
0
[ "-l = len(S)", "-i = 0", "-if l % 2:", "- c = S[l // 2]", "- for i in range(1, l // 2 + 1):", "- if S[l // 2 - i] != c or S[l // 2 + i] != c:", "- break", "- else:", "- i += 1", "- print((l // 2 + i))", "-else:", "- c = S[l // 2]", "- for i in range(l // 2):", "- if S[l // 2 - 1 - i] != c or S[l // 2 + i] != c:", "- break", "- else:", "- i += 1", "- pass", "- print((l // 2 + i))", "+N = len(S)", "+", "+", "+def f(k):", "+ s = S[-k:k]", "+ if s == \"\":", "+ return False", "+ return s.count(s[0]) != len(s)", "+", "+", "+def binary_search(l, r, func):", "+ if func(l):", "+ return l - 1", "+ if not func(r):", "+ return r", "+ while l + 1 < r:", "+ i = (l + r) // 2", "+ if func(i):", "+ r = i", "+ else:", "+ l = i", "+ return l", "+", "+", "+print((binary_search(0, N, f)))" ]
false
0.03866
0.036017
1.073382
[ "s914907593", "s208213361" ]
u798803522
p02376
python
s811579048
s793576132
1,270
90
8,352
6,224
Accepted
Accepted
92.91
from collections import defaultdict def dfs(source, sink, flow, connect): if source == sink: return flow used[source] = 1 for i, (target, cost, rev_i) in enumerate(connect[source]): if not used[target] and cost > 0: that_flow = dfs(target, sink, min(flow, cost), connect) if that_flow > 0: connect[source][i][1] -= that_flow connect[target][rev_i][1] += that_flow return that_flow return 0 v_num, e_num = (int(n) for n in input().split(" ")) connect = defaultdict(list) for _ in range(e_num): s, t, cost = (int(n) for n in input().split(" ")) connect[s].append([t, cost, len(connect[t])]) connect[t].append([s, 0, len(connect[s]) - 1]) answer = 0 base_used = [0 for n in range(v_num)] while True: used = base_used.copy() now_flow = dfs(0, v_num - 1, float("inf"), connect) if now_flow == 0: break answer += now_flow print(answer)
from collections import defaultdict def bfs(start, end, connect, v_num, flow): level = [-1] * v_num level[start] = 0 queue = [start] while queue: v = queue.pop() for next_v in connect[v]: if flow[v][next_v] > 0 and level[next_v] < 0: level[next_v] = level[v] + 1 queue.append(next_v) return level def dfs(here, end, connect, level, flow, minimum_f, visited): if here == end: return minimum_f for next_v in connect[here]: if not visited[here][next_v] and flow[here][next_v] > 0 and level[here] < level[next_v]: visited[here][next_v] = 1 temp_f = dfs(next_v, end, connect, level, flow, min(flow[here][next_v], minimum_f), visited) if temp_f: flow[here][next_v] -= temp_f flow[next_v][here] += temp_f # print(flow) return temp_f return 0 v_num, e_num = (int(n) for n in input().split(" ")) connect = defaultdict(list) flow = defaultdict(lambda: defaultdict(int)) for _ in range(e_num): s, t, c = list(map(int, input().split(" "))) connect[s].append(t) connect[t].append(s) flow[s][t] = c start = 0 end = v_num - 1 answer = 0 while True: level = bfs(start, end, connect, v_num, flow) if level[end] < 0: print(answer) break visited = defaultdict(lambda: defaultdict(int)) temp_f = dfs(start, end, connect, level, flow, float("inf"), visited) while temp_f > 0: answer += temp_f temp_f = dfs(start, end, connect, level, flow, float("inf"), visited)
31
50
1,002
1,665
from collections import defaultdict def dfs(source, sink, flow, connect): if source == sink: return flow used[source] = 1 for i, (target, cost, rev_i) in enumerate(connect[source]): if not used[target] and cost > 0: that_flow = dfs(target, sink, min(flow, cost), connect) if that_flow > 0: connect[source][i][1] -= that_flow connect[target][rev_i][1] += that_flow return that_flow return 0 v_num, e_num = (int(n) for n in input().split(" ")) connect = defaultdict(list) for _ in range(e_num): s, t, cost = (int(n) for n in input().split(" ")) connect[s].append([t, cost, len(connect[t])]) connect[t].append([s, 0, len(connect[s]) - 1]) answer = 0 base_used = [0 for n in range(v_num)] while True: used = base_used.copy() now_flow = dfs(0, v_num - 1, float("inf"), connect) if now_flow == 0: break answer += now_flow print(answer)
from collections import defaultdict def bfs(start, end, connect, v_num, flow): level = [-1] * v_num level[start] = 0 queue = [start] while queue: v = queue.pop() for next_v in connect[v]: if flow[v][next_v] > 0 and level[next_v] < 0: level[next_v] = level[v] + 1 queue.append(next_v) return level def dfs(here, end, connect, level, flow, minimum_f, visited): if here == end: return minimum_f for next_v in connect[here]: if ( not visited[here][next_v] and flow[here][next_v] > 0 and level[here] < level[next_v] ): visited[here][next_v] = 1 temp_f = dfs( next_v, end, connect, level, flow, min(flow[here][next_v], minimum_f), visited, ) if temp_f: flow[here][next_v] -= temp_f flow[next_v][here] += temp_f # print(flow) return temp_f return 0 v_num, e_num = (int(n) for n in input().split(" ")) connect = defaultdict(list) flow = defaultdict(lambda: defaultdict(int)) for _ in range(e_num): s, t, c = list(map(int, input().split(" "))) connect[s].append(t) connect[t].append(s) flow[s][t] = c start = 0 end = v_num - 1 answer = 0 while True: level = bfs(start, end, connect, v_num, flow) if level[end] < 0: print(answer) break visited = defaultdict(lambda: defaultdict(int)) temp_f = dfs(start, end, connect, level, flow, float("inf"), visited) while temp_f > 0: answer += temp_f temp_f = dfs(start, end, connect, level, flow, float("inf"), visited)
false
38
[ "-def dfs(source, sink, flow, connect):", "- if source == sink:", "- return flow", "- used[source] = 1", "- for i, (target, cost, rev_i) in enumerate(connect[source]):", "- if not used[target] and cost > 0:", "- that_flow = dfs(target, sink, min(flow, cost), connect)", "- if that_flow > 0:", "- connect[source][i][1] -= that_flow", "- connect[target][rev_i][1] += that_flow", "- return that_flow", "+def bfs(start, end, connect, v_num, flow):", "+ level = [-1] * v_num", "+ level[start] = 0", "+ queue = [start]", "+ while queue:", "+ v = queue.pop()", "+ for next_v in connect[v]:", "+ if flow[v][next_v] > 0 and level[next_v] < 0:", "+ level[next_v] = level[v] + 1", "+ queue.append(next_v)", "+ return level", "+", "+", "+def dfs(here, end, connect, level, flow, minimum_f, visited):", "+ if here == end:", "+ return minimum_f", "+ for next_v in connect[here]:", "+ if (", "+ not visited[here][next_v]", "+ and flow[here][next_v] > 0", "+ and level[here] < level[next_v]", "+ ):", "+ visited[here][next_v] = 1", "+ temp_f = dfs(", "+ next_v,", "+ end,", "+ connect,", "+ level,", "+ flow,", "+ min(flow[here][next_v], minimum_f),", "+ visited,", "+ )", "+ if temp_f:", "+ flow[here][next_v] -= temp_f", "+ flow[next_v][here] += temp_f", "+ # print(flow)", "+ return temp_f", "+flow = defaultdict(lambda: defaultdict(int))", "- s, t, cost = (int(n) for n in input().split(\" \"))", "- connect[s].append([t, cost, len(connect[t])])", "- connect[t].append([s, 0, len(connect[s]) - 1])", "+ s, t, c = list(map(int, input().split(\" \")))", "+ connect[s].append(t)", "+ connect[t].append(s)", "+ flow[s][t] = c", "+start = 0", "+end = v_num - 1", "-base_used = [0 for n in range(v_num)]", "- used = base_used.copy()", "- now_flow = dfs(0, v_num - 1, float(\"inf\"), connect)", "- if now_flow == 0:", "+ level = bfs(start, end, connect, v_num, flow)", "+ if level[end] < 0:", "+ print(answer)", "- answer += now_flow", "-print(answer)", "+ visited = defaultdict(lambda: defaultdict(int))", "+ temp_f = dfs(start, end, connect, level, flow, float(\"inf\"), visited)", "+ while temp_f > 0:", "+ answer += temp_f", "+ temp_f = dfs(start, end, connect, level, flow, float(\"inf\"), visited)" ]
false
0.080451
0.036106
2.2282
[ "s811579048", "s793576132" ]
u997641430
p02659
python
s176632245
s452565771
60
22
61,812
9,148
Accepted
Accepted
63.33
a, b = input().split() a = int(a) b = b.split('.') b = int(b[0] + b[1]) ans = str(a * b) if len(ans) <= 2: print((0)) else: print((ans[:-2]))
a, b = input().split() a = int(a) b = int(b.replace('.', '')) print((a * b // 100))
9
4
154
85
a, b = input().split() a = int(a) b = b.split(".") b = int(b[0] + b[1]) ans = str(a * b) if len(ans) <= 2: print((0)) else: print((ans[:-2]))
a, b = input().split() a = int(a) b = int(b.replace(".", "")) print((a * b // 100))
false
55.555556
[ "-b = b.split(\".\")", "-b = int(b[0] + b[1])", "-ans = str(a * b)", "-if len(ans) <= 2:", "- print((0))", "-else:", "- print((ans[:-2]))", "+b = int(b.replace(\".\", \"\"))", "+print((a * b // 100))" ]
false
0.040798
0.040372
1.010539
[ "s176632245", "s452565771" ]
u263830634
p03426
python
s997432884
s239511813
996
459
17,800
26,760
Accepted
Accepted
53.92
H, W, D = list(map(int, input().split())) #盤面を取得 lst = [0] * (H * W + 1) for i in range(1, H + 1): tmp = list(map(int, input().split())) for j in range(1, W + 1): lst[tmp[j - 1]] = [i, j] #前処理 #xからyに移動するのにかかるコストを返す関数 def cost(x, y): return abs(lst[x][0] - lst[y][0]) + abs(lst[x][1] - lst[y][1]) check_lst = [False] * (H * W + 1) cost_lst = [0] * (H * W + 1) for i in range(1, D + 1): if check_lst[i]: continue check_lst[i] = True tmp = i while tmp + D <= H * W: cost_lst[tmp + D] = cost_lst[tmp] + cost(tmp, tmp + D) check_lst[tmp + D] = True tmp += D #出力 Q = int(eval(input())) for _ in range(Q): L, R = list(map(int, input().split())) print((cost_lst[R] - cost_lst[L]))
import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 9) MOD = 10 ** 9 + 7 from collections import defaultdict H, W, D = list(map(int, input().split())) A = [list(map(int, input().split())) for _ in range(H)] dic = defaultdict(list) for h in range(H): for w in range(W): dic[A[h][w]] = [h, w] def calc(l, r): return abs(dic[l][0] - dic[r][0]) + abs(dic[l][1] - dic[r][1]) lst = [0] * (H * W + 1) for d in range(1, D + 1): tmp = d while tmp + D <= (H * W): lst[tmp + D] = lst[tmp] + calc(tmp, tmp + D) tmp += D # print (lst) Q = int(eval(input())) for _ in range(Q): L, R = list(map(int, input().split())) ans = lst[R] - lst[L] print (ans)
31
32
766
724
H, W, D = list(map(int, input().split())) # 盤面を取得 lst = [0] * (H * W + 1) for i in range(1, H + 1): tmp = list(map(int, input().split())) for j in range(1, W + 1): lst[tmp[j - 1]] = [i, j] # 前処理 # xからyに移動するのにかかるコストを返す関数 def cost(x, y): return abs(lst[x][0] - lst[y][0]) + abs(lst[x][1] - lst[y][1]) check_lst = [False] * (H * W + 1) cost_lst = [0] * (H * W + 1) for i in range(1, D + 1): if check_lst[i]: continue check_lst[i] = True tmp = i while tmp + D <= H * W: cost_lst[tmp + D] = cost_lst[tmp] + cost(tmp, tmp + D) check_lst[tmp + D] = True tmp += D # 出力 Q = int(eval(input())) for _ in range(Q): L, R = list(map(int, input().split())) print((cost_lst[R] - cost_lst[L]))
import sys input = sys.stdin.readline sys.setrecursionlimit(10**9) MOD = 10**9 + 7 from collections import defaultdict H, W, D = list(map(int, input().split())) A = [list(map(int, input().split())) for _ in range(H)] dic = defaultdict(list) for h in range(H): for w in range(W): dic[A[h][w]] = [h, w] def calc(l, r): return abs(dic[l][0] - dic[r][0]) + abs(dic[l][1] - dic[r][1]) lst = [0] * (H * W + 1) for d in range(1, D + 1): tmp = d while tmp + D <= (H * W): lst[tmp + D] = lst[tmp] + calc(tmp, tmp + D) tmp += D # print (lst) Q = int(eval(input())) for _ in range(Q): L, R = list(map(int, input().split())) ans = lst[R] - lst[L] print(ans)
false
3.125
[ "+import sys", "+", "+input = sys.stdin.readline", "+sys.setrecursionlimit(10**9)", "+MOD = 10**9 + 7", "+from collections import defaultdict", "+", "-# 盤面を取得", "-lst = [0] * (H * W + 1)", "-for i in range(1, H + 1):", "- tmp = list(map(int, input().split()))", "- for j in range(1, W + 1):", "- lst[tmp[j - 1]] = [i, j]", "-# 前処理", "-# xからyに移動するのにかかるコストを返す関数", "-def cost(x, y):", "- return abs(lst[x][0] - lst[y][0]) + abs(lst[x][1] - lst[y][1])", "+A = [list(map(int, input().split())) for _ in range(H)]", "+dic = defaultdict(list)", "+for h in range(H):", "+ for w in range(W):", "+ dic[A[h][w]] = [h, w]", "-check_lst = [False] * (H * W + 1)", "-cost_lst = [0] * (H * W + 1)", "-for i in range(1, D + 1):", "- if check_lst[i]:", "- continue", "- check_lst[i] = True", "- tmp = i", "- while tmp + D <= H * W:", "- cost_lst[tmp + D] = cost_lst[tmp] + cost(tmp, tmp + D)", "- check_lst[tmp + D] = True", "+def calc(l, r):", "+ return abs(dic[l][0] - dic[r][0]) + abs(dic[l][1] - dic[r][1])", "+", "+", "+lst = [0] * (H * W + 1)", "+for d in range(1, D + 1):", "+ tmp = d", "+ while tmp + D <= (H * W):", "+ lst[tmp + D] = lst[tmp] + calc(tmp, tmp + D)", "-# 出力", "+# print (lst)", "- print((cost_lst[R] - cost_lst[L]))", "+ ans = lst[R] - lst[L]", "+ print(ans)" ]
false
0.073063
0.078992
0.924938
[ "s997432884", "s239511813" ]
u813384600
p00036
python
s166889890
s029535198
20
10
4,212
4,208
Accepted
Accepted
50
import re while True: try: s = ''.join([input() for s in range(8)]) print(' C GAE D F B'[len(re.findall('1.*1', s)[0])]) input() except EOFError: break
import sys;import re for s in sys.stdin.read().split('\n\n'):print(' C GAE D F B'[len(re.findall('1.*1', s.replace('\n',''))[0])])
8
2
219
144
import re while True: try: s = "".join([input() for s in range(8)]) print(" C GAE D F B"[len(re.findall("1.*1", s)[0])]) input() except EOFError: break
import sys import re for s in sys.stdin.read().split("\n\n"): print(" C GAE D F B"[len(re.findall("1.*1", s.replace("\n", ""))[0])])
false
75
[ "+import sys", "-while True:", "- try:", "- s = \"\".join([input() for s in range(8)])", "- print(\" C GAE D F B\"[len(re.findall(\"1.*1\", s)[0])])", "- input()", "- except EOFError:", "- break", "+for s in sys.stdin.read().split(\"\\n\\n\"):", "+ print(\" C GAE D F B\"[len(re.findall(\"1.*1\", s.replace(\"\\n\", \"\"))[0])])" ]
false
0.064239
0.06452
0.995655
[ "s166889890", "s029535198" ]
u296518383
p02695
python
s472030372
s418604671
239
180
93,700
84,668
Accepted
Accepted
24.69
import sys input = sys.stdin.buffer.readline from heapq import heappush, heappop from bisect import bisect_left, bisect_right from collections import deque, defaultdict from itertools import combinations, permutations from itertools import accumulate from math import ceil, sqrt, pi MOD = 10 ** 9 + 7 INF = 10 ** 18 N, M, Q = list(map(int, input().split())) ABCD = [list(map(int, input().split())) for _ in range(Q)] #print(ABCD) lst = [] def dfs(i, n, tmp): if n == N: lst.append(tmp) return 0 for j in range(i, M + 1): dfs(j, n + 1, tmp + [j]) dfs(1, 0, []) #print(lst) ans = 0 for l in lst: tmp = 0 for abcd in ABCD: a, b, c, d = abcd if l[b - 1] - l[a - 1] == c: tmp += d ans = max(tmp, ans) print(ans)
import sys input = sys.stdin.buffer.readline from itertools import combinations_with_replacement N, M, Q = list(map(int, input().split())) ABCD = [list(map(int, input().split())) for _ in range(Q)] lst = list(combinations_with_replacement(list(range(1, M + 1)), N)) ans = 0 for l in lst: tmp = 0 for a, b, c, d in ABCD: if l[b - 1] - l[a - 1] == c: tmp += d ans = max(tmp, ans) print(ans)
40
19
826
437
import sys input = sys.stdin.buffer.readline from heapq import heappush, heappop from bisect import bisect_left, bisect_right from collections import deque, defaultdict from itertools import combinations, permutations from itertools import accumulate from math import ceil, sqrt, pi MOD = 10**9 + 7 INF = 10**18 N, M, Q = list(map(int, input().split())) ABCD = [list(map(int, input().split())) for _ in range(Q)] # print(ABCD) lst = [] def dfs(i, n, tmp): if n == N: lst.append(tmp) return 0 for j in range(i, M + 1): dfs(j, n + 1, tmp + [j]) dfs(1, 0, []) # print(lst) ans = 0 for l in lst: tmp = 0 for abcd in ABCD: a, b, c, d = abcd if l[b - 1] - l[a - 1] == c: tmp += d ans = max(tmp, ans) print(ans)
import sys input = sys.stdin.buffer.readline from itertools import combinations_with_replacement N, M, Q = list(map(int, input().split())) ABCD = [list(map(int, input().split())) for _ in range(Q)] lst = list(combinations_with_replacement(list(range(1, M + 1)), N)) ans = 0 for l in lst: tmp = 0 for a, b, c, d in ABCD: if l[b - 1] - l[a - 1] == c: tmp += d ans = max(tmp, ans) print(ans)
false
52.5
[ "-from heapq import heappush, heappop", "-from bisect import bisect_left, bisect_right", "-from collections import deque, defaultdict", "-from itertools import combinations, permutations", "-from itertools import accumulate", "-from math import ceil, sqrt, pi", "+from itertools import combinations_with_replacement", "-MOD = 10**9 + 7", "-INF = 10**18", "-# print(ABCD)", "-lst = []", "-", "-", "-def dfs(i, n, tmp):", "- if n == N:", "- lst.append(tmp)", "- return 0", "- for j in range(i, M + 1):", "- dfs(j, n + 1, tmp + [j])", "-", "-", "-dfs(1, 0, [])", "-# print(lst)", "+lst = list(combinations_with_replacement(list(range(1, M + 1)), N))", "- for abcd in ABCD:", "- a, b, c, d = abcd", "+ for a, b, c, d in ABCD:" ]
false
0.117697
0.050593
2.326339
[ "s472030372", "s418604671" ]
u186838327
p02813
python
s906282245
s908791583
217
83
43,504
79,264
Accepted
Accepted
61.75
n = int(eval(input())) P = list(map(int, input().split())) Q = list(map(int, input().split())) import itertools X= [] a = 0 b = 0 for p in itertools.permutations(list(range(1, n+1))): for i in range(n): if p[i] < P[i]: a += 1 break elif p[i] > P[i]: break else: continue for i in range(n): if p[i] < Q[i]: b += 1 break elif p[i] > Q[i]: break else: continue print((abs((a+1)-(b+1))))
n = int(eval(input())) P = tuple(map(int, input().split())) Q = tuple(map(int, input().split())) ##print(P) #print(Q) import itertools X = [] for p in itertools.permutations(list(range(1, n+1))): X.append(p) #print(X) for i in range(len(X)): if P == X[i]: a = i break for i in range(len(X)): if Q == X[i]: b = i break print((abs(a-b)))
27
19
550
384
n = int(eval(input())) P = list(map(int, input().split())) Q = list(map(int, input().split())) import itertools X = [] a = 0 b = 0 for p in itertools.permutations(list(range(1, n + 1))): for i in range(n): if p[i] < P[i]: a += 1 break elif p[i] > P[i]: break else: continue for i in range(n): if p[i] < Q[i]: b += 1 break elif p[i] > Q[i]: break else: continue print((abs((a + 1) - (b + 1))))
n = int(eval(input())) P = tuple(map(int, input().split())) Q = tuple(map(int, input().split())) ##print(P) # print(Q) import itertools X = [] for p in itertools.permutations(list(range(1, n + 1))): X.append(p) # print(X) for i in range(len(X)): if P == X[i]: a = i break for i in range(len(X)): if Q == X[i]: b = i break print((abs(a - b)))
false
29.62963
[ "-P = list(map(int, input().split()))", "-Q = list(map(int, input().split()))", "+P = tuple(map(int, input().split()))", "+Q = tuple(map(int, input().split()))", "+##print(P)", "+# print(Q)", "-a = 0", "-b = 0", "- for i in range(n):", "- if p[i] < P[i]:", "- a += 1", "- break", "- elif p[i] > P[i]:", "- break", "- else:", "- continue", "- for i in range(n):", "- if p[i] < Q[i]:", "- b += 1", "- break", "- elif p[i] > Q[i]:", "- break", "- else:", "- continue", "-print((abs((a + 1) - (b + 1))))", "+ X.append(p)", "+# print(X)", "+for i in range(len(X)):", "+ if P == X[i]:", "+ a = i", "+ break", "+for i in range(len(X)):", "+ if Q == X[i]:", "+ b = i", "+ break", "+print((abs(a - b)))" ]
false
0.040243
0.131989
0.304895
[ "s906282245", "s908791583" ]
u736443076
p02687
python
s290999021
s577453232
24
22
9,012
9,092
Accepted
Accepted
8.33
def solve(): S = eval(input()) if S == "ABC": print("ARC") else: print("ABC") if __name__ == '__main__': solve()
def solve(): S = eval(input()) if S == "ABC": print("ARC") exit() else: print("ABC") if __name__ == '__main__': solve()
10
11
150
166
def solve(): S = eval(input()) if S == "ABC": print("ARC") else: print("ABC") if __name__ == "__main__": solve()
def solve(): S = eval(input()) if S == "ABC": print("ARC") exit() else: print("ABC") if __name__ == "__main__": solve()
false
9.090909
[ "+ exit()" ]
false
0.038025
0.03918
0.970517
[ "s290999021", "s577453232" ]
u179169725
p02573
python
s915532606
s972987501
291
146
44,232
20,256
Accepted
Accepted
49.83
mycode = r''' # distutils: language=c++ # cython: language_level=3, boundscheck=False, wraparound=False # cython: cdivision=True # False:Cython はCの型に対する除算・剰余演算子に関する仕様を、(被演算子間の符号が異なる場合の振る舞いが異なる)Pythonのintの仕様に合わせ、除算する数が0の場合にZeroDivisionErrorを送出します。この処理を行わせると、速度に 35% ぐらいのペナルティが生じます。 True:チェックを行いません。 ctypedef long long LL import numpy as np from functools import partial array=partial(np.array, dtype=np.int64) zeros=partial(np.zeros, dtype=np.int64) full=partial(np.full, dtype=np.int64) import sys readline = sys.stdin.buffer.readline read = sys.stdin.readline #文字列読み込む時はこっち cdef ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64) cdef read_matrix(LL H,LL W): #return np.ndarray shape=(H,W) matrix lines=[] cdef LL _ for _ in range(H): lines.append(read()) lines=' '.join(lines) #byte同士の結合ができないのでreadlineでなくreadで return np.fromstring(lines, sep=' ',dtype=np.int64).reshape(H,W) cdef class UnionFind: cdef: public LL N,n_groups public LL[::1] parent def __init__(self, LL N): self.N = N # ノード数 self.n_groups = N # グループ数 # 親ノードをしめす。負は自身が親ということ。 self.parent = full(N,-1) # idxが各ノードに対応。 cdef LL root(self, LL A): # print(A) # ノード番号を受け取って一番上の親ノードの番号を帰す if (self.parent[A] < 0): return A self.parent[A] = self.root(self.parent[A]) # 経由したノードすべての親を上書き return self.parent[A] cdef LL size(self, LL A): # ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。 return -self.parent[self.root(A)] cdef bint unite(self,LL A,LL B): # ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。 # 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。 A = self.root(A) B = self.root(B) # すでにくっついている場合 if (A == B): return False # 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較 if (self.size(A) < self.size(B)): A, B = B, A # くっつける self.parent[A] += self.parent[B] # sizeの更新 self.parent[B] = A # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる self.n_groups -= 1 return True cdef bint is_in_same(self,LL A,LL B): return self.root(A) == self.root(B) cdef LL N,M N, M = ints() AB=read_matrix(M,2)-1 cdef UnionFind uf = UnionFind(N) cdef LL a,b for a,b in AB: uf.unite(a, b) print(-np.min(uf.parent)) ''' 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 # cython: cdivision=True # False:Cython はCの型に対する除算・剰余演算子に関する仕様を、(被演算子間の符号が異なる場合の振る舞いが異なる)Pythonのintの仕様に合わせ、除算する数が0の場合にZeroDivisionErrorを送出します。この処理を行わせると、速度に 35% ぐらいのペナルティが生じます。 True:チェックを行いません。 ctypedef long long LL from libcpp.vector cimport vector ctypedef vector[LL] vec import sys readline = sys.stdin.buffer.readline read = sys.stdin.readline #文字列読み込む時はこっち def ints(): return map(int,readline().split()) cdef class UnionFind: cdef: public LL N,n_groups public vec parent def __init__(self, LL N): self.N = N # ノード数 self.n_groups = N # グループ数 # 親ノードをしめす。負は自身が親ということ。 self.parent = vec(N,-1) # idxが各ノードに対応。 cdef LL root(self, LL A): # print(A) # ノード番号を受け取って一番上の親ノードの番号を帰す if (self.parent[A] < 0): return A self.parent[A] = self.root(self.parent[A]) # 経由したノードすべての親を上書き return self.parent[A] cdef LL size(self, LL A): # ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。 return -self.parent[self.root(A)] cdef bint unite(self,LL A,LL B): # ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。 # 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。 A = self.root(A) B = self.root(B) # すでにくっついている場合 if (A == B): return False # 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較 if (self.size(A) < self.size(B)): A, B = B, A # くっつける self.parent[A] += self.parent[B] # sizeの更新 self.parent[B] = A # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる self.n_groups -= 1 return True cdef bint is_in_same(self,LL A,LL B): return self.root(A) == self.root(B) cdef LL N,M,_ N, M = ints() cdef UnionFind uf = UnionFind(N) cdef LL a,b for _ in range(M): a,b=ints() uf.unite(a-1, b-1) print(-min(uf.parent)) ''' 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
96
89
2,631
2,210
mycode = r""" # distutils: language=c++ # cython: language_level=3, boundscheck=False, wraparound=False # cython: cdivision=True # False:Cython はCの型に対する除算・剰余演算子に関する仕様を、(被演算子間の符号が異なる場合の振る舞いが異なる)Pythonのintの仕様に合わせ、除算する数が0の場合にZeroDivisionErrorを送出します。この処理を行わせると、速度に 35% ぐらいのペナルティが生じます。 True:チェックを行いません。 ctypedef long long LL import numpy as np from functools import partial array=partial(np.array, dtype=np.int64) zeros=partial(np.zeros, dtype=np.int64) full=partial(np.full, dtype=np.int64) import sys readline = sys.stdin.buffer.readline read = sys.stdin.readline #文字列読み込む時はこっち cdef ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64) cdef read_matrix(LL H,LL W): #return np.ndarray shape=(H,W) matrix lines=[] cdef LL _ for _ in range(H): lines.append(read()) lines=' '.join(lines) #byte同士の結合ができないのでreadlineでなくreadで return np.fromstring(lines, sep=' ',dtype=np.int64).reshape(H,W) cdef class UnionFind: cdef: public LL N,n_groups public LL[::1] parent def __init__(self, LL N): self.N = N # ノード数 self.n_groups = N # グループ数 # 親ノードをしめす。負は自身が親ということ。 self.parent = full(N,-1) # idxが各ノードに対応。 cdef LL root(self, LL A): # print(A) # ノード番号を受け取って一番上の親ノードの番号を帰す if (self.parent[A] < 0): return A self.parent[A] = self.root(self.parent[A]) # 経由したノードすべての親を上書き return self.parent[A] cdef LL size(self, LL A): # ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。 return -self.parent[self.root(A)] cdef bint unite(self,LL A,LL B): # ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。 # 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。 A = self.root(A) B = self.root(B) # すでにくっついている場合 if (A == B): return False # 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較 if (self.size(A) < self.size(B)): A, B = B, A # くっつける self.parent[A] += self.parent[B] # sizeの更新 self.parent[B] = A # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる self.n_groups -= 1 return True cdef bint is_in_same(self,LL A,LL B): return self.root(A) == self.root(B) cdef LL N,M N, M = ints() AB=read_matrix(M,2)-1 cdef UnionFind uf = UnionFind(N) cdef LL a,b for a,b in AB: uf.unite(a, b) print(-np.min(uf.parent)) """ 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 # cython: cdivision=True # False:Cython はCの型に対する除算・剰余演算子に関する仕様を、(被演算子間の符号が異なる場合の振る舞いが異なる)Pythonのintの仕様に合わせ、除算する数が0の場合にZeroDivisionErrorを送出します。この処理を行わせると、速度に 35% ぐらいのペナルティが生じます。 True:チェックを行いません。 ctypedef long long LL from libcpp.vector cimport vector ctypedef vector[LL] vec import sys readline = sys.stdin.buffer.readline read = sys.stdin.readline #文字列読み込む時はこっち def ints(): return map(int,readline().split()) cdef class UnionFind: cdef: public LL N,n_groups public vec parent def __init__(self, LL N): self.N = N # ノード数 self.n_groups = N # グループ数 # 親ノードをしめす。負は自身が親ということ。 self.parent = vec(N,-1) # idxが各ノードに対応。 cdef LL root(self, LL A): # print(A) # ノード番号を受け取って一番上の親ノードの番号を帰す if (self.parent[A] < 0): return A self.parent[A] = self.root(self.parent[A]) # 経由したノードすべての親を上書き return self.parent[A] cdef LL size(self, LL A): # ノード番号を受け取って、そのノードが含まれている集合のサイズを返す。 return -self.parent[self.root(A)] cdef bint unite(self,LL A,LL B): # ノード番号を2つ受け取って、そのノード同士をつなげる処理を行う。 # 引数のノードを直接つなぐ代わりに、親同士を連結する処理にする。 A = self.root(A) B = self.root(B) # すでにくっついている場合 if (A == B): return False # 大きい方に小さい方をくっつけたほうが処理が軽いので大小比較 if (self.size(A) < self.size(B)): A, B = B, A # くっつける self.parent[A] += self.parent[B] # sizeの更新 self.parent[B] = A # self.rootが呼び出されればBにくっついてるノードもすべて親がAだと上書きされる self.n_groups -= 1 return True cdef bint is_in_same(self,LL A,LL B): return self.root(A) == self.root(B) cdef LL N,M,_ N, M = ints() cdef UnionFind uf = UnionFind(N) cdef LL a,b for _ in range(M): a,b=ints() uf.unite(a-1, b-1) print(-min(uf.parent)) """ 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
7.291667
[ "-import numpy as np", "-from functools import partial", "-array=partial(np.array, dtype=np.int64)", "-zeros=partial(np.zeros, dtype=np.int64)", "-full=partial(np.full, dtype=np.int64)", "+from libcpp.vector cimport vector", "+ctypedef vector[LL] vec", "-cdef ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)", "-cdef read_matrix(LL H,LL W):", "- #return np.ndarray shape=(H,W) matrix", "- lines=[]", "- cdef LL _", "- for _ in range(H):", "- lines.append(read())", "- lines=' '.join(lines) #byte同士の結合ができないのでreadlineでなくreadで", "- return np.fromstring(lines, sep=' ',dtype=np.int64).reshape(H,W)", "+def ints(): return map(int,readline().split())", "- public LL[::1] parent", "+ public vec parent", "- self.parent = full(N,-1) # idxが各ノードに対応。", "+ self.parent = vec(N,-1) # idxが各ノードに対応。", "-cdef LL N,M", "+cdef LL N,M,_", "-AB=read_matrix(M,2)-1", "-for a,b in AB:", "- uf.unite(a, b)", "-print(-np.min(uf.parent))", "+for _ in range(M):", "+ a,b=ints()", "+ uf.unite(a-1, b-1)", "+print(-min(uf.parent))" ]
false
0.075986
0.07145
1.063485
[ "s915532606", "s972987501" ]
u261103969
p03798
python
s532010839
s795655065
875
93
109,844
77,476
Accepted
Accepted
89.37
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): n = int(readline()) s = eval(input()) if s[1] == "o": first = ((True, True, True), (False, True, False), (True, False, False), (False, False, True)) else: first = ((True, True, False), (False, True, True), (True, False, True), (False, False, False)) for a, b, c in first: kinds = [None] * (n + 1) kinds[1] = b kinds[0] = a kinds[2] = c for i in range(2, n): if kinds[i]: if s[i] == "o": kinds[i + 1] = kinds[i - 1] else: kinds[i + 1] = not kinds[i - 1] else: if s[i] == "o": kinds[i + 1] = not kinds[i - 1] else: kinds[i + 1] = kinds[i - 1] res = "" flag = True for i in range(n): left = kinds[(i - 1) % n] right = kinds[(i + 1) % n] res += "S" if kinds[i] else "W" if (s[i] == "o" and kinds[i]) or (s[i] == "x" and not kinds[i]): if left != right: flag = False break else: if left == right: flag = False break if flag: print(res) sys.exit() print((-1)) if __name__ == '__main__': main()
import sys from enum import Enum readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): from itertools import product n = int(readline()) s = eval(input()) for a, b in product(("S", "W"), repeat=2): kinds = [""] * n kinds[0] = a kinds[1] = b for i in range(1, n - 1): if kinds[i] is "S": if s[i] == "o": kinds[i + 1] = kinds[i - 1] else: if kinds[i - 1] == "S": kinds[i + 1] = "W" else: kinds[i + 1] = "S" else: if s[i] == "o": if kinds[i - 1] == "S": kinds[i + 1] = "W" else: kinds[i + 1] = "S" else: kinds[i + 1] = kinds[i - 1] ff = (s[n - 1] == "o") ^ (kinds[n - 1] == "W") fs = (s[0] == "o") ^ (kinds[0] == "W") f1 = False f2 = False if ff and (kinds[n - 2] == kinds[0]): f1 = True if not ff and (kinds[n - 2] != kinds[0]): f1 = True if fs and (kinds[n - 1] == kinds[1]): f2 = True if not fs and (kinds[n - 1] != kinds[1]): f2 = True if f1 and f2: res = "".join(kinds) print(res) sys.exit() print((-1)) if __name__ == '__main__': main()
64
58
1,656
1,569
import sys readline = sys.stdin.readline MOD = 10**9 + 7 INF = float("INF") sys.setrecursionlimit(10**5) def main(): n = int(readline()) s = eval(input()) if s[1] == "o": first = ( (True, True, True), (False, True, False), (True, False, False), (False, False, True), ) else: first = ( (True, True, False), (False, True, True), (True, False, True), (False, False, False), ) for a, b, c in first: kinds = [None] * (n + 1) kinds[1] = b kinds[0] = a kinds[2] = c for i in range(2, n): if kinds[i]: if s[i] == "o": kinds[i + 1] = kinds[i - 1] else: kinds[i + 1] = not kinds[i - 1] else: if s[i] == "o": kinds[i + 1] = not kinds[i - 1] else: kinds[i + 1] = kinds[i - 1] res = "" flag = True for i in range(n): left = kinds[(i - 1) % n] right = kinds[(i + 1) % n] res += "S" if kinds[i] else "W" if (s[i] == "o" and kinds[i]) or (s[i] == "x" and not kinds[i]): if left != right: flag = False break else: if left == right: flag = False break if flag: print(res) sys.exit() print((-1)) if __name__ == "__main__": main()
import sys from enum import Enum readline = sys.stdin.readline MOD = 10**9 + 7 INF = float("INF") sys.setrecursionlimit(10**5) def main(): from itertools import product n = int(readline()) s = eval(input()) for a, b in product(("S", "W"), repeat=2): kinds = [""] * n kinds[0] = a kinds[1] = b for i in range(1, n - 1): if kinds[i] is "S": if s[i] == "o": kinds[i + 1] = kinds[i - 1] else: if kinds[i - 1] == "S": kinds[i + 1] = "W" else: kinds[i + 1] = "S" else: if s[i] == "o": if kinds[i - 1] == "S": kinds[i + 1] = "W" else: kinds[i + 1] = "S" else: kinds[i + 1] = kinds[i - 1] ff = (s[n - 1] == "o") ^ (kinds[n - 1] == "W") fs = (s[0] == "o") ^ (kinds[0] == "W") f1 = False f2 = False if ff and (kinds[n - 2] == kinds[0]): f1 = True if not ff and (kinds[n - 2] != kinds[0]): f1 = True if fs and (kinds[n - 1] == kinds[1]): f2 = True if not fs and (kinds[n - 1] != kinds[1]): f2 = True if f1 and f2: res = "".join(kinds) print(res) sys.exit() print((-1)) if __name__ == "__main__": main()
false
9.375
[ "+from enum import Enum", "+ from itertools import product", "+", "- if s[1] == \"o\":", "- first = (", "- (True, True, True),", "- (False, True, False),", "- (True, False, False),", "- (False, False, True),", "- )", "- else:", "- first = (", "- (True, True, False),", "- (False, True, True),", "- (True, False, True),", "- (False, False, False),", "- )", "- for a, b, c in first:", "- kinds = [None] * (n + 1)", "+ for a, b in product((\"S\", \"W\"), repeat=2):", "+ kinds = [\"\"] * n", "+ kinds[0] = a", "- kinds[0] = a", "- kinds[2] = c", "- for i in range(2, n):", "- if kinds[i]:", "+ for i in range(1, n - 1):", "+ if kinds[i] is \"S\":", "- kinds[i + 1] = not kinds[i - 1]", "+ if kinds[i - 1] == \"S\":", "+ kinds[i + 1] = \"W\"", "+ else:", "+ kinds[i + 1] = \"S\"", "- kinds[i + 1] = not kinds[i - 1]", "+ if kinds[i - 1] == \"S\":", "+ kinds[i + 1] = \"W\"", "+ else:", "+ kinds[i + 1] = \"S\"", "- res = \"\"", "- flag = True", "- for i in range(n):", "- left = kinds[(i - 1) % n]", "- right = kinds[(i + 1) % n]", "- res += \"S\" if kinds[i] else \"W\"", "- if (s[i] == \"o\" and kinds[i]) or (s[i] == \"x\" and not kinds[i]):", "- if left != right:", "- flag = False", "- break", "- else:", "- if left == right:", "- flag = False", "- break", "- if flag:", "+ ff = (s[n - 1] == \"o\") ^ (kinds[n - 1] == \"W\")", "+ fs = (s[0] == \"o\") ^ (kinds[0] == \"W\")", "+ f1 = False", "+ f2 = False", "+ if ff and (kinds[n - 2] == kinds[0]):", "+ f1 = True", "+ if not ff and (kinds[n - 2] != kinds[0]):", "+ f1 = True", "+ if fs and (kinds[n - 1] == kinds[1]):", "+ f2 = True", "+ if not fs and (kinds[n - 1] != kinds[1]):", "+ f2 = True", "+ if f1 and f2:", "+ res = \"\".join(kinds)" ]
false
0.096962
0.044066
2.200386
[ "s532010839", "s795655065" ]
u506858457
p03111
python
s853148868
s942936210
429
71
3,828
3,064
Accepted
Accepted
83.45
import itertools n,*abc=list(map(int,input().split())) l=[int(eval(input())) for i in range(n)] inf=100000000000000 mi=inf for i in list(itertools.product([i for i in range(3)],repeat=n)):#(1)↓ sub=[[] for j in range(3)] for j in range(n): sub[i[j]].append(j) mi_sub=0 for j in range(3): l_sub=len(sub[j]) if l_sub==0:#(2) mi_sub=inf break mi_subsub=inf for k in range(2**l_sub):#(3)↓ mi_subsubsub=[0,0] for l_subsub in range(l_sub):#(5)↓ if ((k>>l_subsub) &1): mi_subsubsub[0]+=1 mi_subsubsub[1]+=l[sub[j][l_subsub]] if mi_subsubsub[0]!=0:#(4) mi_subsub=min(mi_subsub,abs(mi_subsubsub[1]-abc[j])+mi_subsubsub[0]*10-10) mi_sub+=mi_subsub mi=min(mi,mi_sub) print(mi)
N, A, B, C = list(map(int, input().split())) l = [int(eval(input())) for i in range(N)] INF = 10 ** 9 def dfs(cur, a, b, c): ''' 深さがNだったら使用MPを評価 N本の竹を使うときに必要な合成回数はN-1のため,最後に-1*10*3(?) 1本も竹を使用していなかったら棄却→MPを無限に使うこととしている ''' if cur == N: return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF ''' cur番目の竹に対して ret0:ABCどれにも使わない ret1:Aに使う(合成:MP+10) ret2:Bに使う(合成:MP+10) ret3:Cに使う(合成:MP+10) ''' ret0 = dfs(cur + 1, a, b, c) ret1 = dfs(cur + 1, a + l[cur], b, c) + 10 ret2 = dfs(cur + 1, a, b + l[cur], c) + 10 ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10 return min(ret0, ret1, ret2, ret3) print((dfs(0, 0, 0, 0)))
27
26
879
736
import itertools n, *abc = list(map(int, input().split())) l = [int(eval(input())) for i in range(n)] inf = 100000000000000 mi = inf for i in list(itertools.product([i for i in range(3)], repeat=n)): # (1)↓ sub = [[] for j in range(3)] for j in range(n): sub[i[j]].append(j) mi_sub = 0 for j in range(3): l_sub = len(sub[j]) if l_sub == 0: # (2) mi_sub = inf break mi_subsub = inf for k in range(2**l_sub): # (3)↓ mi_subsubsub = [0, 0] for l_subsub in range(l_sub): # (5)↓ if (k >> l_subsub) & 1: mi_subsubsub[0] += 1 mi_subsubsub[1] += l[sub[j][l_subsub]] if mi_subsubsub[0] != 0: # (4) mi_subsub = min( mi_subsub, abs(mi_subsubsub[1] - abc[j]) + mi_subsubsub[0] * 10 - 10 ) mi_sub += mi_subsub mi = min(mi, mi_sub) print(mi)
N, A, B, C = list(map(int, input().split())) l = [int(eval(input())) for i in range(N)] INF = 10**9 def dfs(cur, a, b, c): """ 深さがNだったら使用MPを評価 N本の竹を使うときに必要な合成回数はN-1のため,最後に-1*10*3(?) 1本も竹を使用していなかったら棄却→MPを無限に使うこととしている """ if cur == N: return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF """ cur番目の竹に対して ret0:ABCどれにも使わない ret1:Aに使う(合成:MP+10) ret2:Bに使う(合成:MP+10) ret3:Cに使う(合成:MP+10) """ ret0 = dfs(cur + 1, a, b, c) ret1 = dfs(cur + 1, a + l[cur], b, c) + 10 ret2 = dfs(cur + 1, a, b + l[cur], c) + 10 ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10 return min(ret0, ret1, ret2, ret3) print((dfs(0, 0, 0, 0)))
false
3.703704
[ "-import itertools", "+N, A, B, C = list(map(int, input().split()))", "+l = [int(eval(input())) for i in range(N)]", "+INF = 10**9", "-n, *abc = list(map(int, input().split()))", "-l = [int(eval(input())) for i in range(n)]", "-inf = 100000000000000", "-mi = inf", "-for i in list(itertools.product([i for i in range(3)], repeat=n)): # (1)↓", "- sub = [[] for j in range(3)]", "- for j in range(n):", "- sub[i[j]].append(j)", "- mi_sub = 0", "- for j in range(3):", "- l_sub = len(sub[j])", "- if l_sub == 0: # (2)", "- mi_sub = inf", "- break", "- mi_subsub = inf", "- for k in range(2**l_sub): # (3)↓", "- mi_subsubsub = [0, 0]", "- for l_subsub in range(l_sub): # (5)↓", "- if (k >> l_subsub) & 1:", "- mi_subsubsub[0] += 1", "- mi_subsubsub[1] += l[sub[j][l_subsub]]", "- if mi_subsubsub[0] != 0: # (4)", "- mi_subsub = min(", "- mi_subsub, abs(mi_subsubsub[1] - abc[j]) + mi_subsubsub[0] * 10 - 10", "- )", "- mi_sub += mi_subsub", "- mi = min(mi, mi_sub)", "-print(mi)", "+", "+def dfs(cur, a, b, c):", "+ \"\"\"", "+ 深さがNだったら使用MPを評価", "+ N本の竹を使うときに必要な合成回数はN-1のため,最後に-1*10*3(?)", "+ 1本も竹を使用していなかったら棄却→MPを無限に使うこととしている", "+ \"\"\"", "+ if cur == N:", "+ return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF", "+ \"\"\"", "+ cur番目の竹に対して", "+ ret0:ABCどれにも使わない", "+ ret1:Aに使う(合成:MP+10)", "+ ret2:Bに使う(合成:MP+10)", "+ ret3:Cに使う(合成:MP+10)", "+ \"\"\"", "+ ret0 = dfs(cur + 1, a, b, c)", "+ ret1 = dfs(cur + 1, a + l[cur], b, c) + 10", "+ ret2 = dfs(cur + 1, a, b + l[cur], c) + 10", "+ ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10", "+ return min(ret0, ret1, ret2, ret3)", "+", "+", "+print((dfs(0, 0, 0, 0)))" ]
false
0.659085
0.058267
11.311545
[ "s853148868", "s942936210" ]
u672475305
p03575
python
s261079212
s861243843
37
21
3,316
3,064
Accepted
Accepted
43.24
from collections import deque n,m = list(map(int,input().split())) G = [[0]*n for _ in range(n)] E = [] for i in range(m): a,b = list(map(int,input().split())) a,b = a-1, b-1 G[a][b] = 1 G[b][a] = 1 E.append((a,b)) ans = 0 for e in E: del_a, del_b = e #対象の辺を消す G[del_a][del_b] = 0 G[del_b][del_a] = 0 que = ([0]) visited = [False]*n while que: node = que.pop() if visited[node] == True: continue visited[node] = True for j in range(n): if G[node][j] == 1: que.append(j) if False in visited: ans += 1 #対象の辺を戻す G[del_a][del_b] = 1 G[del_b][del_a] = 1 print(ans)
class UnionFind: #要素数nで初期化 #インスタンス変数の初期化 def __init__(self, n): #root : 木の要素数 #rnk : 木の高さ(rank) self.n = n self.root = [-1]*(n+1) self.rnk = [0]*(n+1) """ノードxのrootノードを見つける""" def Find_Root(self, x): if self.root[x] < 0: return x else: self.root[x] = self.Find_Root(self.root[x]) return self.root[x] """木の合併""" def Union(self, x, y): #入力ノードの親を探索 x = self.Find_Root(x) y = self.Find_Root(y) #既に同じ木に所属する場合 if (x==y): return #異なる木に所属する場合 -> rnkから判断して合併する elif (self.rnk[x] > self.rnk[y]): self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y #rnkが同じ(深さが同じ)場合 if self.rnk[x]==self.rnk[y]: self.rnk[y] += 1 """xとyが同じグループに所属するか""" def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) """ノードxが属する木のサイズ""" def Count(self, x): return -self.root[self.Find_Root(x)] n,m = list(map(int,input().split())) edge = [] for i in range(m): a,b = list(map(int,input().split())) edge.append([a,b]) res = 0 for i in range(m): tmp_edge = edge[:i] + edge[i+1:] uf = UnionFind(n) for j in range(len(tmp_edge)): uf.Union(tmp_edge[j][0], tmp_edge[j][1]) if not uf.isSameGroup(edge[i][0], edge[i][1]): res += 1 print(res)
37
65
744
1,632
from collections import deque n, m = list(map(int, input().split())) G = [[0] * n for _ in range(n)] E = [] for i in range(m): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 G[a][b] = 1 G[b][a] = 1 E.append((a, b)) ans = 0 for e in E: del_a, del_b = e # 対象の辺を消す G[del_a][del_b] = 0 G[del_b][del_a] = 0 que = [0] visited = [False] * n while que: node = que.pop() if visited[node] == True: continue visited[node] = True for j in range(n): if G[node][j] == 1: que.append(j) if False in visited: ans += 1 # 対象の辺を戻す G[del_a][del_b] = 1 G[del_b][del_a] = 1 print(ans)
class UnionFind: # 要素数nで初期化 # インスタンス変数の初期化 def __init__(self, n): # root : 木の要素数 # rnk : 木の高さ(rank) self.n = n self.root = [-1] * (n + 1) self.rnk = [0] * (n + 1) """ノードxのrootノードを見つける""" def Find_Root(self, x): if self.root[x] < 0: return x else: self.root[x] = self.Find_Root(self.root[x]) return self.root[x] """木の合併""" def Union(self, x, y): # 入力ノードの親を探索 x = self.Find_Root(x) y = self.Find_Root(y) # 既に同じ木に所属する場合 if x == y: return # 異なる木に所属する場合 -> rnkから判断して合併する elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さが同じ)場合 if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 """xとyが同じグループに所属するか""" def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) """ノードxが属する木のサイズ""" def Count(self, x): return -self.root[self.Find_Root(x)] n, m = list(map(int, input().split())) edge = [] for i in range(m): a, b = list(map(int, input().split())) edge.append([a, b]) res = 0 for i in range(m): tmp_edge = edge[:i] + edge[i + 1 :] uf = UnionFind(n) for j in range(len(tmp_edge)): uf.Union(tmp_edge[j][0], tmp_edge[j][1]) if not uf.isSameGroup(edge[i][0], edge[i][1]): res += 1 print(res)
false
43.076923
[ "-from collections import deque", "+class UnionFind:", "+ # 要素数nで初期化", "+ # インスタンス変数の初期化", "+ def __init__(self, n):", "+ # root : 木の要素数", "+ # rnk : 木の高さ(rank)", "+ self.n = n", "+ self.root = [-1] * (n + 1)", "+ self.rnk = [0] * (n + 1)", "+", "+ \"\"\"ノードxのrootノードを見つける\"\"\"", "+", "+ def Find_Root(self, x):", "+ if self.root[x] < 0:", "+ return x", "+ else:", "+ self.root[x] = self.Find_Root(self.root[x])", "+ return self.root[x]", "+", "+ \"\"\"木の合併\"\"\"", "+", "+ def Union(self, x, y):", "+ # 入力ノードの親を探索", "+ x = self.Find_Root(x)", "+ y = self.Find_Root(y)", "+ # 既に同じ木に所属する場合", "+ if x == y:", "+ return", "+ # 異なる木に所属する場合 -> rnkから判断して合併する", "+ elif self.rnk[x] > self.rnk[y]:", "+ self.root[x] += self.root[y]", "+ self.root[y] = x", "+ else:", "+ self.root[y] += self.root[x]", "+ self.root[x] = y", "+ # rnkが同じ(深さが同じ)場合", "+ if self.rnk[x] == self.rnk[y]:", "+ self.rnk[y] += 1", "+", "+ \"\"\"xとyが同じグループに所属するか\"\"\"", "+", "+ def isSameGroup(self, x, y):", "+ return self.Find_Root(x) == self.Find_Root(y)", "+", "+ \"\"\"ノードxが属する木のサイズ\"\"\"", "+", "+ def Count(self, x):", "+ return -self.root[self.Find_Root(x)]", "+", "-G = [[0] * n for _ in range(n)]", "-E = []", "+edge = []", "- a, b = a - 1, b - 1", "- G[a][b] = 1", "- G[b][a] = 1", "- E.append((a, b))", "-ans = 0", "-for e in E:", "- del_a, del_b = e", "- # 対象の辺を消す", "- G[del_a][del_b] = 0", "- G[del_b][del_a] = 0", "- que = [0]", "- visited = [False] * n", "- while que:", "- node = que.pop()", "- if visited[node] == True:", "- continue", "- visited[node] = True", "- for j in range(n):", "- if G[node][j] == 1:", "- que.append(j)", "- if False in visited:", "- ans += 1", "- # 対象の辺を戻す", "- G[del_a][del_b] = 1", "- G[del_b][del_a] = 1", "-print(ans)", "+ edge.append([a, b])", "+res = 0", "+for i in range(m):", "+ tmp_edge = edge[:i] + edge[i + 1 :]", "+ uf = UnionFind(n)", "+ for j in range(len(tmp_edge)):", "+ uf.Union(tmp_edge[j][0], tmp_edge[j][1])", "+ if not uf.isSameGroup(edge[i][0], edge[i][1]):", "+ res += 1", "+print(res)" ]
false
0.059795
0.038064
1.570905
[ "s261079212", "s861243843" ]
u832399163
p03478
python
s384085486
s281835330
46
34
3,060
3,064
Accepted
Accepted
26.09
from sys import stdin (n, a, b) = stdin.readline().rstrip().split() n = int(n) a = int(a) b = int(b) total=0 POW_MAX=4 for i in range(1, n+1): sub_total=0 for j in range(0, len(str(i))): #sub_total = sub_total + math.floor(i / (10 ** j) ) #sub_total = sub_total + i // (10 ** j) sub_total = sub_total + int(str(i)[j]) if a <= sub_total and sub_total <= b: #print("n:%d sub_total:%d" % (i, sub_total)) total = total + i print(total)
from sys import stdin (n, a, b) = stdin.readline().rstrip().split() n = int(n) a = int(a) b = int(b) total=0 POW_MAX=4 for i in range(1, n+1): sub_total=0 num = i for j in range(0, POW_MAX+1): mod = num % 10 sub_total = sub_total + mod sho = num // 10 num = sho if sho == 0: break if a <= sub_total and sub_total <= b: total = total + i print(total)
21
26
508
457
from sys import stdin (n, a, b) = stdin.readline().rstrip().split() n = int(n) a = int(a) b = int(b) total = 0 POW_MAX = 4 for i in range(1, n + 1): sub_total = 0 for j in range(0, len(str(i))): # sub_total = sub_total + math.floor(i / (10 ** j) ) # sub_total = sub_total + i // (10 ** j) sub_total = sub_total + int(str(i)[j]) if a <= sub_total and sub_total <= b: # print("n:%d sub_total:%d" % (i, sub_total)) total = total + i print(total)
from sys import stdin (n, a, b) = stdin.readline().rstrip().split() n = int(n) a = int(a) b = int(b) total = 0 POW_MAX = 4 for i in range(1, n + 1): sub_total = 0 num = i for j in range(0, POW_MAX + 1): mod = num % 10 sub_total = sub_total + mod sho = num // 10 num = sho if sho == 0: break if a <= sub_total and sub_total <= b: total = total + i print(total)
false
19.230769
[ "- for j in range(0, len(str(i))):", "- # sub_total = sub_total + math.floor(i / (10 ** j) )", "- # sub_total = sub_total + i // (10 ** j)", "- sub_total = sub_total + int(str(i)[j])", "+ num = i", "+ for j in range(0, POW_MAX + 1):", "+ mod = num % 10", "+ sub_total = sub_total + mod", "+ sho = num // 10", "+ num = sho", "+ if sho == 0:", "+ break", "- # print(\"n:%d sub_total:%d\" % (i, sub_total))" ]
false
0.038095
0.036491
1.043959
[ "s384085486", "s281835330" ]
u427344224
p02991
python
s015495558
s666455003
1,543
871
151,988
79,644
Accepted
Accepted
43.55
import heapq class Dijkstra: def __init__(self, rote_map, start_point, goal_point=None): self.rote_map = rote_map self.start_point = start_point self.goal_point = goal_point def execute(self): num_of_city = 3 * 10 ** 5 + 10 dist = [float("inf") for _ in range(num_of_city)] prev = [float("inf") for _ in range(num_of_city)] dist[self.start_point] = 0 heap_q = [] heapq.heappush(heap_q, (0, self.start_point)) route_count = [0 for _ in range(num_of_city)] route_count[self.start_point] = 1 while len(heap_q) != 0: prev_cost, src = heapq.heappop(heap_q) if dist[src] < prev_cost: continue for dest, cost in list(self.rote_map[src].items()): if cost != float("inf") and dist[dest] > dist[src] + cost: dist[dest] = dist[src] + cost heapq.heappush(heap_q, (dist[dest], dest)) prev[dest] = src if dist[dest] == dist[src] + cost: route_count[dest] += route_count[src] if self.goal_point is not None: return self._get_path(self.goal_point, prev) else: return dist, route_count def _get_path(self, goal, prev): path = [goal] dest = goal while prev[dest] != float("inf"): path.append(prev[dest]) dest = prev[dest] return list(reversed(path)) N, M = list(map(int, input().split())) from collections import defaultdict graph = defaultdict(dict) for i in range(M): u, v = list(map(int, input().split())) u -= 1 v -= 1 graph[u][v + N] = 1 graph[u + N][v + 2 * N] = 1 graph[u + 2 * N][v] = 1 S, T = list(map(int, input().split())) S -= 1 T -= 1 dj = Dijkstra(graph, S) dist, _ = dj.execute() if dist[T] % 3 == 0: print((dist[T] // 3)) else: print((-1))
N, M = list(map(int, input().split())) from collections import defaultdict, deque graph = defaultdict(list) for i in range(M): u, v = list(map(int, input().split())) u -= 1 v -= 1 graph[u].append(v + N) graph[u + N].append(v + 2 * N) graph[u + 2 * N].append(v) S, T = list(map(int, input().split())) S -= 1 T -= 1 dist = [-1] * (3*N) dist[S] = 0 q = deque([S]) while q: v = q.popleft() d = dist[v] Vs = graph[v] for u in Vs: if dist[u] == -1: q.append(u) dist[u] = d + 1 if dist[T] != float("inf") and dist[T] % 3 == 0: print((dist[T] // 3)) else: print((-1))
71
30
1,995
649
import heapq class Dijkstra: def __init__(self, rote_map, start_point, goal_point=None): self.rote_map = rote_map self.start_point = start_point self.goal_point = goal_point def execute(self): num_of_city = 3 * 10**5 + 10 dist = [float("inf") for _ in range(num_of_city)] prev = [float("inf") for _ in range(num_of_city)] dist[self.start_point] = 0 heap_q = [] heapq.heappush(heap_q, (0, self.start_point)) route_count = [0 for _ in range(num_of_city)] route_count[self.start_point] = 1 while len(heap_q) != 0: prev_cost, src = heapq.heappop(heap_q) if dist[src] < prev_cost: continue for dest, cost in list(self.rote_map[src].items()): if cost != float("inf") and dist[dest] > dist[src] + cost: dist[dest] = dist[src] + cost heapq.heappush(heap_q, (dist[dest], dest)) prev[dest] = src if dist[dest] == dist[src] + cost: route_count[dest] += route_count[src] if self.goal_point is not None: return self._get_path(self.goal_point, prev) else: return dist, route_count def _get_path(self, goal, prev): path = [goal] dest = goal while prev[dest] != float("inf"): path.append(prev[dest]) dest = prev[dest] return list(reversed(path)) N, M = list(map(int, input().split())) from collections import defaultdict graph = defaultdict(dict) for i in range(M): u, v = list(map(int, input().split())) u -= 1 v -= 1 graph[u][v + N] = 1 graph[u + N][v + 2 * N] = 1 graph[u + 2 * N][v] = 1 S, T = list(map(int, input().split())) S -= 1 T -= 1 dj = Dijkstra(graph, S) dist, _ = dj.execute() if dist[T] % 3 == 0: print((dist[T] // 3)) else: print((-1))
N, M = list(map(int, input().split())) from collections import defaultdict, deque graph = defaultdict(list) for i in range(M): u, v = list(map(int, input().split())) u -= 1 v -= 1 graph[u].append(v + N) graph[u + N].append(v + 2 * N) graph[u + 2 * N].append(v) S, T = list(map(int, input().split())) S -= 1 T -= 1 dist = [-1] * (3 * N) dist[S] = 0 q = deque([S]) while q: v = q.popleft() d = dist[v] Vs = graph[v] for u in Vs: if dist[u] == -1: q.append(u) dist[u] = d + 1 if dist[T] != float("inf") and dist[T] % 3 == 0: print((dist[T] // 3)) else: print((-1))
false
57.746479
[ "-import heapq", "+N, M = list(map(int, input().split()))", "+from collections import defaultdict, deque", "-", "-class Dijkstra:", "- def __init__(self, rote_map, start_point, goal_point=None):", "- self.rote_map = rote_map", "- self.start_point = start_point", "- self.goal_point = goal_point", "-", "- def execute(self):", "- num_of_city = 3 * 10**5 + 10", "- dist = [float(\"inf\") for _ in range(num_of_city)]", "- prev = [float(\"inf\") for _ in range(num_of_city)]", "- dist[self.start_point] = 0", "- heap_q = []", "- heapq.heappush(heap_q, (0, self.start_point))", "- route_count = [0 for _ in range(num_of_city)]", "- route_count[self.start_point] = 1", "- while len(heap_q) != 0:", "- prev_cost, src = heapq.heappop(heap_q)", "- if dist[src] < prev_cost:", "- continue", "- for dest, cost in list(self.rote_map[src].items()):", "- if cost != float(\"inf\") and dist[dest] > dist[src] + cost:", "- dist[dest] = dist[src] + cost", "- heapq.heappush(heap_q, (dist[dest], dest))", "- prev[dest] = src", "- if dist[dest] == dist[src] + cost:", "- route_count[dest] += route_count[src]", "- if self.goal_point is not None:", "- return self._get_path(self.goal_point, prev)", "- else:", "- return dist, route_count", "-", "- def _get_path(self, goal, prev):", "- path = [goal]", "- dest = goal", "- while prev[dest] != float(\"inf\"):", "- path.append(prev[dest])", "- dest = prev[dest]", "- return list(reversed(path))", "-", "-", "-N, M = list(map(int, input().split()))", "-from collections import defaultdict", "-", "-graph = defaultdict(dict)", "+graph = defaultdict(list)", "- graph[u][v + N] = 1", "- graph[u + N][v + 2 * N] = 1", "- graph[u + 2 * N][v] = 1", "+ graph[u].append(v + N)", "+ graph[u + N].append(v + 2 * N)", "+ graph[u + 2 * N].append(v)", "-dj = Dijkstra(graph, S)", "-dist, _ = dj.execute()", "-if dist[T] % 3 == 0:", "+dist = [-1] * (3 * N)", "+dist[S] = 0", "+q = deque([S])", "+while q:", "+ v = q.popleft()", "+ d = dist[v]", "+ Vs = graph[v]", "+ for u in Vs:", "+ if dist[u] == -1:", "+ q.append(u)", "+ dist[u] = d + 1", "+if dist[T] != float(\"inf\") and dist[T] % 3 == 0:" ]
false
0.479398
0.035432
13.529982
[ "s015495558", "s666455003" ]
u947883560
p02598
python
s790012681
s242611674
464
203
94,164
104,352
Accepted
Accepted
56.25
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) import math def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return [LIST() for _ in range(n)] def NSTR(n): return [eval(input()) for _ in range(n)] INF = float("inf") MOD = 10**9 + 7 def main(): N, K = MAP() A = LIST() if K == 0: print((max(A))) return # X決め打ち二分探索 left = 0 right = 10**9+7 for i in range(100): # while right - left > 1.0e-6: mid = (right + left) / 2 count = 0 for a in A: count += int(math.ceil(a / mid))-1 if count <= K: right = mid else: left = mid print((int(math.ceil(left)))) return if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) from bisect import bisect_left from itertools import product import math def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def LI_(): return list([int(x)-1 for x in input().split()]) def LF(): return list(map(float, input().split())) def LC(): return [c for c in input().split()] def LLI(n): return [LI() for _ in range(n)] def NSTR(n): return [eval(input()) for _ in range(n)] def array2d(N, M, initial=0): return [[initial]*M for _ in range(N)] def copy2d(orig, N, M): ret = array2d(N, M) for i in range(N): for j in range(M): ret[i][j] = orig[i][j] return ret INF = float("inf") MOD = 10**9 + 7 def main(): N, K = MAP() A = LI() if K == 0: print((max(A))) return # 決め打ち二分探索 left = 0 right = 10**9+7 # for i in range(100): while right - left > 1: mid = (right + left) // 2 count = 0 for a in A: count += int(math.ceil(a / mid))-1 if count <= K: right = mid else: left = mid # print(int(math.ceil(left))) print(right) return if __name__ == '__main__': main()
44
60
923
1,389
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) import math def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return [LIST() for _ in range(n)] def NSTR(n): return [eval(input()) for _ in range(n)] INF = float("inf") MOD = 10**9 + 7 def main(): N, K = MAP() A = LIST() if K == 0: print((max(A))) return # X決め打ち二分探索 left = 0 right = 10**9 + 7 for i in range(100): # while right - left > 1.0e-6: mid = (right + left) / 2 count = 0 for a in A: count += int(math.ceil(a / mid)) - 1 if count <= K: right = mid else: left = mid print((int(math.ceil(left)))) return if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) from bisect import bisect_left from itertools import product import math def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def LI_(): return list([int(x) - 1 for x in input().split()]) def LF(): return list(map(float, input().split())) def LC(): return [c for c in input().split()] def LLI(n): return [LI() for _ in range(n)] def NSTR(n): return [eval(input()) for _ in range(n)] def array2d(N, M, initial=0): return [[initial] * M for _ in range(N)] def copy2d(orig, N, M): ret = array2d(N, M) for i in range(N): for j in range(M): ret[i][j] = orig[i][j] return ret INF = float("inf") MOD = 10**9 + 7 def main(): N, K = MAP() A = LI() if K == 0: print((max(A))) return # 決め打ち二分探索 left = 0 right = 10**9 + 7 # for i in range(100): while right - left > 1: mid = (right + left) // 2 count = 0 for a in A: count += int(math.ceil(a / mid)) - 1 if count <= K: right = mid else: left = mid # print(int(math.ceil(left))) print(right) return if __name__ == "__main__": main()
false
26.666667
[ "+from bisect import bisect_left", "+from itertools import product", "-def LIST():", "+def LI():", "-def ZIP(n):", "- return [LIST() for _ in range(n)]", "+def LI_():", "+ return list([int(x) - 1 for x in input().split()])", "+", "+", "+def LF():", "+ return list(map(float, input().split()))", "+", "+", "+def LC():", "+ return [c for c in input().split()]", "+", "+", "+def LLI(n):", "+ return [LI() for _ in range(n)]", "+", "+", "+def array2d(N, M, initial=0):", "+ return [[initial] * M for _ in range(N)]", "+", "+", "+def copy2d(orig, N, M):", "+ ret = array2d(N, M)", "+ for i in range(N):", "+ for j in range(M):", "+ ret[i][j] = orig[i][j]", "+ return ret", "- A = LIST()", "+ A = LI()", "- # X決め打ち二分探索", "+ # 決め打ち二分探索", "- for i in range(100):", "- # while right - left > 1.0e-6:", "- mid = (right + left) / 2", "+ # for i in range(100):", "+ while right - left > 1:", "+ mid = (right + left) // 2", "- print((int(math.ceil(left))))", "+ # print(int(math.ceil(left)))", "+ print(right)" ]
false
0.036388
0.041948
0.867454
[ "s790012681", "s242611674" ]
u567380442
p02383
python
s502279503
s514943974
40
30
6,772
6,724
Accepted
Accepted
25
def get_dice(pips): return [[0, pips[4], 0, 0], [pips[3], pips[0], pips[2], pips[5]], [0, pips[1], 0, 0]] def move_e(dice): dice[1] = dice[1][3:] + dice[1][:3] return dice def move_n(dice): return [[0, dice[1][1], 0, 0], [dice[1][0], dice[2][1], dice[1][2], dice[0][1]], [0, dice[1][3], 0, 0]] def move_s(dice): return [[0, dice[1][3], 0, 0], [dice[1][0], dice[0][1], dice[1][2], dice[2][1]], [0, dice[1][1], 0, 0]] def move_w(dice): dice[1] = dice[1][1:] + dice[1][:1] return dice func = {'E':move_e,'N':move_n,'S':move_s,'W':move_w} dice = get_dice(list(map(int, input().split()))) for c in eval(input()): dice = func[c](dice) print((dice[1][1]))
mask = {'N':(1, 5, 2, 3, 0, 4), 'E':(3, 1, 0, 5, 4, 2), 'S':(4, 0, 2, 3, 5, 1), 'W':(2, 1, 5, 0, 4,3)} dice = input().split() for c in eval(input()): dice = [dice[i] for i in mask[c]] print((dice[0]))
31
8
848
206
def get_dice(pips): return [ [0, pips[4], 0, 0], [pips[3], pips[0], pips[2], pips[5]], [0, pips[1], 0, 0], ] def move_e(dice): dice[1] = dice[1][3:] + dice[1][:3] return dice def move_n(dice): return [ [0, dice[1][1], 0, 0], [dice[1][0], dice[2][1], dice[1][2], dice[0][1]], [0, dice[1][3], 0, 0], ] def move_s(dice): return [ [0, dice[1][3], 0, 0], [dice[1][0], dice[0][1], dice[1][2], dice[2][1]], [0, dice[1][1], 0, 0], ] def move_w(dice): dice[1] = dice[1][1:] + dice[1][:1] return dice func = {"E": move_e, "N": move_n, "S": move_s, "W": move_w} dice = get_dice(list(map(int, input().split()))) for c in eval(input()): dice = func[c](dice) print((dice[1][1]))
mask = { "N": (1, 5, 2, 3, 0, 4), "E": (3, 1, 0, 5, 4, 2), "S": (4, 0, 2, 3, 5, 1), "W": (2, 1, 5, 0, 4, 3), } dice = input().split() for c in eval(input()): dice = [dice[i] for i in mask[c]] print((dice[0]))
false
74.193548
[ "-def get_dice(pips):", "- return [", "- [0, pips[4], 0, 0],", "- [pips[3], pips[0], pips[2], pips[5]],", "- [0, pips[1], 0, 0],", "- ]", "-", "-", "-def move_e(dice):", "- dice[1] = dice[1][3:] + dice[1][:3]", "- return dice", "-", "-", "-def move_n(dice):", "- return [", "- [0, dice[1][1], 0, 0],", "- [dice[1][0], dice[2][1], dice[1][2], dice[0][1]],", "- [0, dice[1][3], 0, 0],", "- ]", "-", "-", "-def move_s(dice):", "- return [", "- [0, dice[1][3], 0, 0],", "- [dice[1][0], dice[0][1], dice[1][2], dice[2][1]],", "- [0, dice[1][1], 0, 0],", "- ]", "-", "-", "-def move_w(dice):", "- dice[1] = dice[1][1:] + dice[1][:1]", "- return dice", "-", "-", "-func = {\"E\": move_e, \"N\": move_n, \"S\": move_s, \"W\": move_w}", "-dice = get_dice(list(map(int, input().split())))", "+mask = {", "+ \"N\": (1, 5, 2, 3, 0, 4),", "+ \"E\": (3, 1, 0, 5, 4, 2),", "+ \"S\": (4, 0, 2, 3, 5, 1),", "+ \"W\": (2, 1, 5, 0, 4, 3),", "+}", "+dice = input().split()", "- dice = func[c](dice)", "-print((dice[1][1]))", "+ dice = [dice[i] for i in mask[c]]", "+print((dice[0]))" ]
false
0.108928
0.086837
1.254394
[ "s502279503", "s514943974" ]
u481942026
p03163
python
s573707940
s699360429
589
511
120,304
119,280
Accepted
Accepted
13.24
def knapsack(sizes, vals, volume): n = len(sizes) dp = [[0] * (volume+1) for _ in range(n)] # j is 0...volume for i in range(n): for j in range(volume+1): dp[i][j] = max(dp[i][j], dp[i-1][j]) if j - sizes[i] >= 0: dp[i][j] = max(dp[i][j], dp[i-1][j-sizes[i]] + vals[i]) dp[i][j] = max(dp[i][j], dp[i-1][j]) return dp[-1][-1] if __name__ == "__main__": n, volume = [int(x) for x in input().split()] sizes, vals = [], [] for _ in range(n): s, v = [int(x) for x in input().split()] sizes.append(s) vals.append(v) print((knapsack(sizes, vals, volume)))
def knapsack(sizes, vals, volume): n = len(sizes) dp = [[0] * (volume+1) for _ in range(n)] # j is 0...volume for i in range(n): for j in range(volume+1): dp[i][j] = max(dp[i][j], dp[i-1][j]) if j - sizes[i] >= 0: dp[i][j] = max(dp[i][j], dp[i-1][j-sizes[i]] + vals[i]) #dp[i][j] = max(dp[i][j], dp[i-1][j]) return dp[-1][-1] if __name__ == "__main__": n, volume = [int(x) for x in input().split()] sizes, vals = [], [] for _ in range(n): s, v = [int(x) for x in input().split()] sizes.append(s) vals.append(v) print((knapsack(sizes, vals, volume)))
23
23
690
691
def knapsack(sizes, vals, volume): n = len(sizes) dp = [[0] * (volume + 1) for _ in range(n)] # j is 0...volume for i in range(n): for j in range(volume + 1): dp[i][j] = max(dp[i][j], dp[i - 1][j]) if j - sizes[i] >= 0: dp[i][j] = max(dp[i][j], dp[i - 1][j - sizes[i]] + vals[i]) dp[i][j] = max(dp[i][j], dp[i - 1][j]) return dp[-1][-1] if __name__ == "__main__": n, volume = [int(x) for x in input().split()] sizes, vals = [], [] for _ in range(n): s, v = [int(x) for x in input().split()] sizes.append(s) vals.append(v) print((knapsack(sizes, vals, volume)))
def knapsack(sizes, vals, volume): n = len(sizes) dp = [[0] * (volume + 1) for _ in range(n)] # j is 0...volume for i in range(n): for j in range(volume + 1): dp[i][j] = max(dp[i][j], dp[i - 1][j]) if j - sizes[i] >= 0: dp[i][j] = max(dp[i][j], dp[i - 1][j - sizes[i]] + vals[i]) # dp[i][j] = max(dp[i][j], dp[i-1][j]) return dp[-1][-1] if __name__ == "__main__": n, volume = [int(x) for x in input().split()] sizes, vals = [], [] for _ in range(n): s, v = [int(x) for x in input().split()] sizes.append(s) vals.append(v) print((knapsack(sizes, vals, volume)))
false
0
[ "- dp[i][j] = max(dp[i][j], dp[i - 1][j])", "+ # dp[i][j] = max(dp[i][j], dp[i-1][j])" ]
false
0.040251
0.082947
0.485257
[ "s573707940", "s699360429" ]
u905203728
p02781
python
s357582742
s550914206
202
21
40,944
3,064
Accepted
Accepted
89.6
n=eval(input()) K=int(eval(input())) m=len(n) DP=[[[0]*(K+2) for _ in range(2)] for _ in range(m+1)] DP[0][0][0]=1 for i in range(1,m+1): for flag in range(2): num=9 if flag else int(n[i-1]) for j in range(K+1): for k in range(num+1): if k==0:DP[i][flag or k<num][j] +=DP[i-1][flag][j] else:DP[i][flag or k<num][j+1] +=DP[i-1][flag][j] print((DP[-1][0][K]+DP[-1][1][K]))
n=eval(input()) K=int(eval(input())) m=len(n) DP=[[[0]*(K+2) for _ in range(2)] for _ in range(m+1)] DP[0][0][0]=1 for i in range(1,m+1): for flag in range(2): num=9 if flag else int(n[i-1]) for j in range(K+1): for k in range(num+1): if k==0:DP[i][flag or k<num][j] +=DP[i-1][flag][j] else:DP[i][flag or k<num][j] +=DP[i-1][flag][j-1] print((DP[m][0][K]+DP[m][1][K]))
16
16
438
436
n = eval(input()) K = int(eval(input())) m = len(n) DP = [[[0] * (K + 2) for _ in range(2)] for _ in range(m + 1)] DP[0][0][0] = 1 for i in range(1, m + 1): for flag in range(2): num = 9 if flag else int(n[i - 1]) for j in range(K + 1): for k in range(num + 1): if k == 0: DP[i][flag or k < num][j] += DP[i - 1][flag][j] else: DP[i][flag or k < num][j + 1] += DP[i - 1][flag][j] print((DP[-1][0][K] + DP[-1][1][K]))
n = eval(input()) K = int(eval(input())) m = len(n) DP = [[[0] * (K + 2) for _ in range(2)] for _ in range(m + 1)] DP[0][0][0] = 1 for i in range(1, m + 1): for flag in range(2): num = 9 if flag else int(n[i - 1]) for j in range(K + 1): for k in range(num + 1): if k == 0: DP[i][flag or k < num][j] += DP[i - 1][flag][j] else: DP[i][flag or k < num][j] += DP[i - 1][flag][j - 1] print((DP[m][0][K] + DP[m][1][K]))
false
0
[ "- DP[i][flag or k < num][j + 1] += DP[i - 1][flag][j]", "-print((DP[-1][0][K] + DP[-1][1][K]))", "+ DP[i][flag or k < num][j] += DP[i - 1][flag][j - 1]", "+print((DP[m][0][K] + DP[m][1][K]))" ]
false
0.035027
0.034271
1.022049
[ "s357582742", "s550914206" ]
u347640436
p03504
python
s251354781
s018920583
1,380
570
29,428
36,564
Accepted
Accepted
58.7
N, C = list(map(int, input().split())) tt = [[0] * (10 ** 5 + 1) for _ in range(C)] for _ in range(N): s, t, c = list(map(int, input().split())) for i in range(s - 1, t): tt[c - 1][i] = 1 ct = [0] * (10 ** 5 + 1) for i in range(C): for j in range(10 ** 5 + 1): ct[j] += tt[i][j] print((max(ct)))
# imos 法 from operator import itemgetter N, C = list(map(int, input().split())) stc = [list(map(int, input().split())) for _ in range(N)] stc.sort(key=itemgetter(2, 0)) cs = [0] * (10 ** 5 + 1) pt, pc = -1, -1 for s, t, c in stc: if pt == s and pc == c: cs[s] += 1 else: cs[s - 1] += 1 cs[t] -= 1 pt, pc = t, c for i in range(1, 10 ** 5 + 1): cs[i] += cs[i - 1] print((max(cs)))
14
21
326
431
N, C = list(map(int, input().split())) tt = [[0] * (10**5 + 1) for _ in range(C)] for _ in range(N): s, t, c = list(map(int, input().split())) for i in range(s - 1, t): tt[c - 1][i] = 1 ct = [0] * (10**5 + 1) for i in range(C): for j in range(10**5 + 1): ct[j] += tt[i][j] print((max(ct)))
# imos 法 from operator import itemgetter N, C = list(map(int, input().split())) stc = [list(map(int, input().split())) for _ in range(N)] stc.sort(key=itemgetter(2, 0)) cs = [0] * (10**5 + 1) pt, pc = -1, -1 for s, t, c in stc: if pt == s and pc == c: cs[s] += 1 else: cs[s - 1] += 1 cs[t] -= 1 pt, pc = t, c for i in range(1, 10**5 + 1): cs[i] += cs[i - 1] print((max(cs)))
false
33.333333
[ "+# imos 法", "+from operator import itemgetter", "+", "-tt = [[0] * (10**5 + 1) for _ in range(C)]", "-for _ in range(N):", "- s, t, c = list(map(int, input().split()))", "- for i in range(s - 1, t):", "- tt[c - 1][i] = 1", "-ct = [0] * (10**5 + 1)", "-for i in range(C):", "- for j in range(10**5 + 1):", "- ct[j] += tt[i][j]", "-print((max(ct)))", "+stc = [list(map(int, input().split())) for _ in range(N)]", "+stc.sort(key=itemgetter(2, 0))", "+cs = [0] * (10**5 + 1)", "+pt, pc = -1, -1", "+for s, t, c in stc:", "+ if pt == s and pc == c:", "+ cs[s] += 1", "+ else:", "+ cs[s - 1] += 1", "+ cs[t] -= 1", "+ pt, pc = t, c", "+for i in range(1, 10**5 + 1):", "+ cs[i] += cs[i - 1]", "+print((max(cs)))" ]
false
0.230706
0.065523
3.521
[ "s251354781", "s018920583" ]
u463655976
p03068
python
s419582553
s541680311
19
17
3,188
2,940
Accepted
Accepted
10.53
import re N = int(eval(input())) S = eval(input()) K = int(eval(input())) w = S[K-1] print((re.sub("[^#]", "*", S.replace(w, "#")).replace("#", w)))
eval(input()) s = list(eval(input())) print(("".join(("*" if x != y else x for x in s[int(eval(input()))-1] for y in s ))))
7
3
136
106
import re N = int(eval(input())) S = eval(input()) K = int(eval(input())) w = S[K - 1] print((re.sub("[^#]", "*", S.replace(w, "#")).replace("#", w)))
eval(input()) s = list(eval(input())) print(("".join(("*" if x != y else x for x in s[int(eval(input())) - 1] for y in s))))
false
57.142857
[ "-import re", "-", "-N = int(eval(input()))", "-S = eval(input())", "-K = int(eval(input()))", "-w = S[K - 1]", "-print((re.sub(\"[^#]\", \"*\", S.replace(w, \"#\")).replace(\"#\", w)))", "+eval(input())", "+s = list(eval(input()))", "+print((\"\".join((\"*\" if x != y else x for x in s[int(eval(input())) - 1] for y in s))))" ]
false
0.060842
0.052873
1.150712
[ "s419582553", "s541680311" ]
u753803401
p03591
python
s221816201
s563578158
184
169
38,384
38,256
Accepted
Accepted
8.15
def slove(): import sys input = sys.stdin.readline s = str(input().rstrip('\n')) print(("Yes" if s[:4] == "YAKI" else "No")) if __name__ == '__main__': slove()
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 s = str(readline().rstrip().decode('utf-8')) print(("Yes" if s[:4] == "YAKI" else "No")) if __name__ == '__main__': solve()
9
12
188
236
def slove(): import sys input = sys.stdin.readline s = str(input().rstrip("\n")) print(("Yes" if s[:4] == "YAKI" else "No")) if __name__ == "__main__": slove()
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10**9 + 7 s = str(readline().rstrip().decode("utf-8")) print(("Yes" if s[:4] == "YAKI" else "No")) if __name__ == "__main__": solve()
false
25
[ "-def slove():", "- import sys", "+import sys", "- input = sys.stdin.readline", "- s = str(input().rstrip(\"\\n\"))", "+", "+def solve():", "+ readline = sys.stdin.buffer.readline", "+ mod = 10**9 + 7", "+ s = str(readline().rstrip().decode(\"utf-8\"))", "- slove()", "+ solve()" ]
false
0.09224
0.10402
0.886755
[ "s221816201", "s563578158" ]
u427984570
p03487
python
s502445112
s287346291
108
90
17,780
23,284
Accepted
Accepted
16.67
n = int(eval(input())) l = list(map(int, input().split())) dic = {} count = 0 for i in range(n): dic.setdefault(l[i],0) dic[l[i]] += 1 for x,y in list(dic.items()): if x <= y: count += y - x else: count += y print(count)
n = int(eval(input())) l = list(map(int,input().split())) d = {} ans = 0 for i in l: if i not in d: d[i] = 1 else: d[i] += 1 for k,v in list(d.items()): if k != v: if k < v: ans += v - k else: ans += v print(ans)
15
16
241
243
n = int(eval(input())) l = list(map(int, input().split())) dic = {} count = 0 for i in range(n): dic.setdefault(l[i], 0) dic[l[i]] += 1 for x, y in list(dic.items()): if x <= y: count += y - x else: count += y print(count)
n = int(eval(input())) l = list(map(int, input().split())) d = {} ans = 0 for i in l: if i not in d: d[i] = 1 else: d[i] += 1 for k, v in list(d.items()): if k != v: if k < v: ans += v - k else: ans += v print(ans)
false
6.25
[ "-dic = {}", "-count = 0", "-for i in range(n):", "- dic.setdefault(l[i], 0)", "- dic[l[i]] += 1", "-for x, y in list(dic.items()):", "- if x <= y:", "- count += y - x", "+d = {}", "+ans = 0", "+for i in l:", "+ if i not in d:", "+ d[i] = 1", "- count += y", "-print(count)", "+ d[i] += 1", "+for k, v in list(d.items()):", "+ if k != v:", "+ if k < v:", "+ ans += v - k", "+ else:", "+ ans += v", "+print(ans)" ]
false
0.044812
0.208828
0.214587
[ "s502445112", "s287346291" ]
u802963389
p03612
python
s853727854
s000849918
242
129
65,004
19,364
Accepted
Accepted
46.69
from itertools import groupby def ceil(x, y): return (x -1) // y + 1 eval(input()) li = list(map(int, input().split())) lii = [] for itr, val in enumerate(li): if itr + 1 == val: lii.append(True) else: lii.append(False) gbli = [[key, len(list(group))] for key, group in groupby(lii)] ans = 0 for i,j in gbli: if i == True: ans += ceil(j, 2) print(ans)
from itertools import groupby n = eval(input()) li = list(map(int, input().split())) lii = [val == (itr + 1) for itr, val in enumerate(li)] gbli = [[key, len(list(group))] for key, group in groupby(lii)] ans = 0 for key, val in gbli: if key: ans += (val - 1) // 2 + 1 print(ans)
20
13
388
299
from itertools import groupby def ceil(x, y): return (x - 1) // y + 1 eval(input()) li = list(map(int, input().split())) lii = [] for itr, val in enumerate(li): if itr + 1 == val: lii.append(True) else: lii.append(False) gbli = [[key, len(list(group))] for key, group in groupby(lii)] ans = 0 for i, j in gbli: if i == True: ans += ceil(j, 2) print(ans)
from itertools import groupby n = eval(input()) li = list(map(int, input().split())) lii = [val == (itr + 1) for itr, val in enumerate(li)] gbli = [[key, len(list(group))] for key, group in groupby(lii)] ans = 0 for key, val in gbli: if key: ans += (val - 1) // 2 + 1 print(ans)
false
35
[ "-", "-def ceil(x, y):", "- return (x - 1) // y + 1", "-", "-", "-eval(input())", "+n = eval(input())", "-lii = []", "-for itr, val in enumerate(li):", "- if itr + 1 == val:", "- lii.append(True)", "- else:", "- lii.append(False)", "+lii = [val == (itr + 1) for itr, val in enumerate(li)]", "-for i, j in gbli:", "- if i == True:", "- ans += ceil(j, 2)", "+for key, val in gbli:", "+ if key:", "+ ans += (val - 1) // 2 + 1" ]
false
0.045145
0.045366
0.995129
[ "s853727854", "s000849918" ]
u057079894
p02868
python
s940687289
s555660151
1,214
969
58,540
93,600
Accepted
Accepted
20.18
import heapq import numpy as np import sys n,m = list(map(int,input().split())) da = [[] for i in range(n)] for i in range(1,n): da[i].append([i-1,0]) for i in range(m): l,r,c = list(map(int,input().split())) da[l-1].append([r-1,c]) pq=[] ju = np.zeros(n,dtype=bool) ju[0] = True for i in da[0]: heapq.heappush(pq, [i[1],i[0]]) while(len(pq)): now = heapq.heappop(pq) if now[1] == n-1: print((now[0])) sys.exit() if ju[now[1]]: continue ju[now[1]] = True for i in da[now[1]]: if ju[i[0]]: continue heapq.heappush(pq,[now[0]+i[1],i[0]]) print((-1))
import heapq import sys class rode(): def __init__(self,x,y): self.x = x self.y = y def __lt__(self, other): return self.y < other.y def __gt__(self, other): return other > self def __le__(self, other): return not(other > self) def __ge__(self, other): return not(self > other) n,m = list(map(int,input().split())) da = [[] for i in range(n)] for i in range(m): l,r,c = list(map(int,input().split())) da[l-1].append([r-1,c]) for i in range(1,n): da[i].append([i-1,0]) pq=[] ju = [False for i in range(n)] ju[0] = True for i in da[0]: heapq.heappush(pq, rode(i[0],i[1])) while(len(pq)): now = heapq.heappop(pq) if now.x == n-1: print((now.y)) sys.exit() if ju[now.x]: continue ju[now.x] = True for i in da[now.x]: if ju[i[0]]: continue heapq.heappush(pq,rode(i[0],now.y+i[1])) print((-1))
29
41
648
970
import heapq import numpy as np import sys n, m = list(map(int, input().split())) da = [[] for i in range(n)] for i in range(1, n): da[i].append([i - 1, 0]) for i in range(m): l, r, c = list(map(int, input().split())) da[l - 1].append([r - 1, c]) pq = [] ju = np.zeros(n, dtype=bool) ju[0] = True for i in da[0]: heapq.heappush(pq, [i[1], i[0]]) while len(pq): now = heapq.heappop(pq) if now[1] == n - 1: print((now[0])) sys.exit() if ju[now[1]]: continue ju[now[1]] = True for i in da[now[1]]: if ju[i[0]]: continue heapq.heappush(pq, [now[0] + i[1], i[0]]) print((-1))
import heapq import sys class rode: def __init__(self, x, y): self.x = x self.y = y def __lt__(self, other): return self.y < other.y def __gt__(self, other): return other > self def __le__(self, other): return not (other > self) def __ge__(self, other): return not (self > other) n, m = list(map(int, input().split())) da = [[] for i in range(n)] for i in range(m): l, r, c = list(map(int, input().split())) da[l - 1].append([r - 1, c]) for i in range(1, n): da[i].append([i - 1, 0]) pq = [] ju = [False for i in range(n)] ju[0] = True for i in da[0]: heapq.heappush(pq, rode(i[0], i[1])) while len(pq): now = heapq.heappop(pq) if now.x == n - 1: print((now.y)) sys.exit() if ju[now.x]: continue ju[now.x] = True for i in da[now.x]: if ju[i[0]]: continue heapq.heappush(pq, rode(i[0], now.y + i[1])) print((-1))
false
29.268293
[ "-import numpy as np", "+", "+", "+class rode:", "+ def __init__(self, x, y):", "+ self.x = x", "+ self.y = y", "+", "+ def __lt__(self, other):", "+ return self.y < other.y", "+", "+ def __gt__(self, other):", "+ return other > self", "+", "+ def __le__(self, other):", "+ return not (other > self)", "+", "+ def __ge__(self, other):", "+ return not (self > other)", "+", "-for i in range(1, n):", "- da[i].append([i - 1, 0])", "+for i in range(1, n):", "+ da[i].append([i - 1, 0])", "-ju = np.zeros(n, dtype=bool)", "+ju = [False for i in range(n)]", "- heapq.heappush(pq, [i[1], i[0]])", "+ heapq.heappush(pq, rode(i[0], i[1]))", "- if now[1] == n - 1:", "- print((now[0]))", "+ if now.x == n - 1:", "+ print((now.y))", "- if ju[now[1]]:", "+ if ju[now.x]:", "- ju[now[1]] = True", "- for i in da[now[1]]:", "+ ju[now.x] = True", "+ for i in da[now.x]:", "- heapq.heappush(pq, [now[0] + i[1], i[0]])", "+ heapq.heappush(pq, rode(i[0], now.y + i[1]))" ]
false
0.297815
0.045414
6.557736
[ "s940687289", "s555660151" ]
u113971909
p02991
python
s485774996
s293501264
518
477
47,284
47,240
Accepted
Accepted
7.92
#!/usr/bin python3 # -*- coding: utf-8 -*- # 双方向グラフで幅優先探索 from collections import deque n, m = list(map(int, input().split())) g = [set([]) for _ in range(n)] #隣接リストの作成 for i in range(m): a, b = list(map(int, input().split())) a, b = a-1, b-1 g[a].add(b) s, t = list(map(int, input().split())) s, t = s-1, t-1 #幅優先探索 q = deque() level = [[-1]*n for i in range(3)] q.append((s, 0)) level[0][s] = 0 while len(q)>0: cur, hp = q.popleft() lvl = level[hp][cur] for i in g[cur]: if level[(hp+1)%3][i]==-1: #階層 level[(hp+1)%3][i] = lvl + 1 q.append((i, (hp+1)%3)) print((level[0][t]//3))
#!/usr/bin python3 # -*- coding: utf-8 -*- # 双方向グラフで幅優先探索 from collections import deque n, m = list(map(int, input().split())) g = [set([]) for _ in range(n)] #隣接リストの作成 for i in range(m): a, b = list(map(int, input().split())) a, b = a-1, b-1 g[a].add(b) s, t = list(map(int, input().split())) s, t = s-1, t-1 #幅優先探索 q = deque() level = [[-1]*n for i in range(3)] q.append((s, 0)) level[0][s] = 0 while len(q)>0: cur, lvl = q.popleft() nxtl = lvl + 1 nxthp = nxtl%3 for i in g[cur]: if level[nxthp][i]==-1: #階層 level[nxthp][i] = nxtl q.append((i, nxtl)) print((level[0][t]//3))
32
33
665
667
#!/usr/bin python3 # -*- coding: utf-8 -*- # 双方向グラフで幅優先探索 from collections import deque n, m = list(map(int, input().split())) g = [set([]) for _ in range(n)] # 隣接リストの作成 for i in range(m): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 g[a].add(b) s, t = list(map(int, input().split())) s, t = s - 1, t - 1 # 幅優先探索 q = deque() level = [[-1] * n for i in range(3)] q.append((s, 0)) level[0][s] = 0 while len(q) > 0: cur, hp = q.popleft() lvl = level[hp][cur] for i in g[cur]: if level[(hp + 1) % 3][i] == -1: # 階層 level[(hp + 1) % 3][i] = lvl + 1 q.append((i, (hp + 1) % 3)) print((level[0][t] // 3))
#!/usr/bin python3 # -*- coding: utf-8 -*- # 双方向グラフで幅優先探索 from collections import deque n, m = list(map(int, input().split())) g = [set([]) for _ in range(n)] # 隣接リストの作成 for i in range(m): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 g[a].add(b) s, t = list(map(int, input().split())) s, t = s - 1, t - 1 # 幅優先探索 q = deque() level = [[-1] * n for i in range(3)] q.append((s, 0)) level[0][s] = 0 while len(q) > 0: cur, lvl = q.popleft() nxtl = lvl + 1 nxthp = nxtl % 3 for i in g[cur]: if level[nxthp][i] == -1: # 階層 level[nxthp][i] = nxtl q.append((i, nxtl)) print((level[0][t] // 3))
false
3.030303
[ "- cur, hp = q.popleft()", "- lvl = level[hp][cur]", "+ cur, lvl = q.popleft()", "+ nxtl = lvl + 1", "+ nxthp = nxtl % 3", "- if level[(hp + 1) % 3][i] == -1:", "+ if level[nxthp][i] == -1:", "- level[(hp + 1) % 3][i] = lvl + 1", "- q.append((i, (hp + 1) % 3))", "+ level[nxthp][i] = nxtl", "+ q.append((i, nxtl))" ]
false
0.042386
0.041134
1.030428
[ "s485774996", "s293501264" ]
u442877951
p02719
python
s764383630
s655145337
19
17
3,060
2,940
Accepted
Accepted
10.53
N,K = list(map(int,input().split())) print((min(N%K,abs(N%K-K))))
N,K = list(map(int,input().split())) ans = min(N%K, abs(N%K-K)) print(ans)
2
3
58
70
N, K = list(map(int, input().split())) print((min(N % K, abs(N % K - K))))
N, K = list(map(int, input().split())) ans = min(N % K, abs(N % K - K)) print(ans)
false
33.333333
[ "-print((min(N % K, abs(N % K - K))))", "+ans = min(N % K, abs(N % K - K))", "+print(ans)" ]
false
0.048053
0.045681
1.051908
[ "s764383630", "s655145337" ]
u964904181
p02725
python
s345961710
s146442508
144
122
36,140
34,752
Accepted
Accepted
15.28
K, N = list(map(int, input().split())) A = list(map(int, input().split())) A2 = [K+a for a in A] A3 = A + A2 dist = [0] * N for i in range(N): j = i + N - 1 dist[i] = A3[j] - A[i] print((min(dist)))
K, N = list(map(int, input().split())) A = list(map(int, input().split())) A3 = A + [K+a for a in A] dist = [A3[i+N-1] - A[i] for i in range(N)] print((min(dist)))
13
8
215
166
K, N = list(map(int, input().split())) A = list(map(int, input().split())) A2 = [K + a for a in A] A3 = A + A2 dist = [0] * N for i in range(N): j = i + N - 1 dist[i] = A3[j] - A[i] print((min(dist)))
K, N = list(map(int, input().split())) A = list(map(int, input().split())) A3 = A + [K + a for a in A] dist = [A3[i + N - 1] - A[i] for i in range(N)] print((min(dist)))
false
38.461538
[ "-A2 = [K + a for a in A]", "-A3 = A + A2", "-dist = [0] * N", "-for i in range(N):", "- j = i + N - 1", "- dist[i] = A3[j] - A[i]", "+A3 = A + [K + a for a in A]", "+dist = [A3[i + N - 1] - A[i] for i in range(N)]" ]
false
0.041803
0.032706
1.278153
[ "s345961710", "s146442508" ]
u691018832
p03363
python
s274477181
s761281509
211
145
42,852
42,852
Accepted
Accepted
31.28
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from collections import defaultdict from itertools import accumulate n, *a = list(map(int, read().split())) dict = defaultdict(int) ans = 0 for aa in list(accumulate([0] + a)): dict[aa] += 1 for v in list(dict.values()): ans += v * (v - 1) // 2 print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from collections import Counter from itertools import accumulate n, *a = list(map(int, read().split())) ans = 0 for v in list(Counter([0] + list(accumulate(a))).values()): ans += v * (v - 1) // 2 print(ans)
17
14
417
361
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) from collections import defaultdict from itertools import accumulate n, *a = list(map(int, read().split())) dict = defaultdict(int) ans = 0 for aa in list(accumulate([0] + a)): dict[aa] += 1 for v in list(dict.values()): ans += v * (v - 1) // 2 print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) from collections import Counter from itertools import accumulate n, *a = list(map(int, read().split())) ans = 0 for v in list(Counter([0] + list(accumulate(a))).values()): ans += v * (v - 1) // 2 print(ans)
false
17.647059
[ "-from collections import defaultdict", "+from collections import Counter", "-dict = defaultdict(int)", "-for aa in list(accumulate([0] + a)):", "- dict[aa] += 1", "-for v in list(dict.values()):", "+for v in list(Counter([0] + list(accumulate(a))).values()):" ]
false
0.035976
0.134958
0.266574
[ "s274477181", "s761281509" ]
u076917070
p02995
python
s278906677
s085651263
42
35
5,432
5,104
Accepted
Accepted
16.67
import fractions def lcm(x, y): return (x * y) // fractions.gcd(x, y) a,b,c,d = list(map(int, input().split())) x = (b//c - (a-1)//c) + (b//d - (a-1)//d -(b//lcm(c,d)) + (a-1)//lcm(c,d)) print((b-a+1-x))
import sys input = sys.stdin.readline A, B, C, D = list(map(int, input().split())) import fractions def lcm(x, y): return (x * y) // fractions.gcd(x, y) def f(d): return B//d - (A-1)//d def main(): ans = (B-A+1) - f(C) - f(D) + f(lcm(C, D)) print(ans) if __name__ == '__main__': main()
9
23
211
332
import fractions def lcm(x, y): return (x * y) // fractions.gcd(x, y) a, b, c, d = list(map(int, input().split())) x = (b // c - (a - 1) // c) + ( b // d - (a - 1) // d - (b // lcm(c, d)) + (a - 1) // lcm(c, d) ) print((b - a + 1 - x))
import sys input = sys.stdin.readline A, B, C, D = list(map(int, input().split())) import fractions def lcm(x, y): return (x * y) // fractions.gcd(x, y) def f(d): return B // d - (A - 1) // d def main(): ans = (B - A + 1) - f(C) - f(D) + f(lcm(C, D)) print(ans) if __name__ == "__main__": main()
false
60.869565
[ "+import sys", "+", "+input = sys.stdin.readline", "+A, B, C, D = list(map(int, input().split()))", "-a, b, c, d = list(map(int, input().split()))", "-x = (b // c - (a - 1) // c) + (", "- b // d - (a - 1) // d - (b // lcm(c, d)) + (a - 1) // lcm(c, d)", "-)", "-print((b - a + 1 - x))", "+def f(d):", "+ return B // d - (A - 1) // d", "+", "+", "+def main():", "+ ans = (B - A + 1) - f(C) - f(D) + f(lcm(C, D))", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.060372
0.048682
1.240137
[ "s278906677", "s085651263" ]
u852690916
p02762
python
s503286171
s407025351
1,061
626
68,528
62,296
Accepted
Accepted
41
#!/usr/bin/env python3 import sys input = sys.stdin.readline N, M, K=list(map(int, input().split())) class UnionFindTree: def __init__(self, n): self.parent = [-1] * n def root(self, x): p, s = self.parent[x], list() while p >= 0: s.append(x) x, p = p, self.parent[p] for c in s: self.parent[c] = x return x def same(self, x, y): return self.root(x) == self.root(y) def count(self, x): return -self.parent[self.root(x)] def unite(self, x, y): xr, yr = self.root(x), self.root(y) if xr == yr: return if self.parent[xr] > self.parent[yr]: xr, yr = yr, xr self.parent[xr] += self.parent[yr] self.parent[yr] = xr friend_or_block = [set() for _ in range(N)] friends_chain = UnionFindTree(N) for _ in range(M): a, b = list(map(int, input().split())) a, b = a-1, b-1 friends_chain.unite(a, b) friend_or_block[a].add(b) friend_or_block[b].add(a) for _ in range(K): c, d = list(map(int, input().split())) c, d = c-1, d-1 if friends_chain.same(c, d): friend_or_block[c].add(d) friend_or_block[d].add(c) print((' '.join(map(str, [friends_chain.count(i) - len(friend_or_block[i]) - 1 for i in range(N)]))))
import sys input = sys.stdin.readline def main(): N, M, K=list(map(int, input().split())) friend_or_block = [0] * N friends_chain = UnionFindTree(N) for _ in range(M): a, b = list(map(int, input().split())) a, b = a-1, b-1 friends_chain.unite(a, b) friend_or_block[a] += 1 friend_or_block[b] += 1 for _ in range(K): c, d = list(map(int, input().split())) c, d = c-1, d-1 if friends_chain.same(c, d): friend_or_block[c] += 1 friend_or_block[d] += 1 print((*[friends_chain.count(i) - friend_or_block[i] - 1 for i in range(N)])) class UnionFindTree: def __init__(self, n): self.parent = [-1] * n def root(self, x): p, s = self.parent[x], list() while p >= 0: s.append(x) x, p = p, self.parent[p] for c in s: self.parent[c] = x return x def same(self, x, y): return self.root(x) == self.root(y) def count(self, x): return -self.parent[self.root(x)] def unite(self, x, y): xr, yr = self.root(x), self.root(y) if xr == yr: return if self.parent[xr] > self.parent[yr]: xr, yr = yr, xr self.parent[xr] += self.parent[yr] self.parent[yr] = xr if __name__ == '__main__': main()
47
49
1,303
1,346
#!/usr/bin/env python3 import sys input = sys.stdin.readline N, M, K = list(map(int, input().split())) class UnionFindTree: def __init__(self, n): self.parent = [-1] * n def root(self, x): p, s = self.parent[x], list() while p >= 0: s.append(x) x, p = p, self.parent[p] for c in s: self.parent[c] = x return x def same(self, x, y): return self.root(x) == self.root(y) def count(self, x): return -self.parent[self.root(x)] def unite(self, x, y): xr, yr = self.root(x), self.root(y) if xr == yr: return if self.parent[xr] > self.parent[yr]: xr, yr = yr, xr self.parent[xr] += self.parent[yr] self.parent[yr] = xr friend_or_block = [set() for _ in range(N)] friends_chain = UnionFindTree(N) for _ in range(M): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 friends_chain.unite(a, b) friend_or_block[a].add(b) friend_or_block[b].add(a) for _ in range(K): c, d = list(map(int, input().split())) c, d = c - 1, d - 1 if friends_chain.same(c, d): friend_or_block[c].add(d) friend_or_block[d].add(c) print( ( " ".join( map( str, [ friends_chain.count(i) - len(friend_or_block[i]) - 1 for i in range(N) ], ) ) ) )
import sys input = sys.stdin.readline def main(): N, M, K = list(map(int, input().split())) friend_or_block = [0] * N friends_chain = UnionFindTree(N) for _ in range(M): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 friends_chain.unite(a, b) friend_or_block[a] += 1 friend_or_block[b] += 1 for _ in range(K): c, d = list(map(int, input().split())) c, d = c - 1, d - 1 if friends_chain.same(c, d): friend_or_block[c] += 1 friend_or_block[d] += 1 print((*[friends_chain.count(i) - friend_or_block[i] - 1 for i in range(N)])) class UnionFindTree: def __init__(self, n): self.parent = [-1] * n def root(self, x): p, s = self.parent[x], list() while p >= 0: s.append(x) x, p = p, self.parent[p] for c in s: self.parent[c] = x return x def same(self, x, y): return self.root(x) == self.root(y) def count(self, x): return -self.parent[self.root(x)] def unite(self, x, y): xr, yr = self.root(x), self.root(y) if xr == yr: return if self.parent[xr] > self.parent[yr]: xr, yr = yr, xr self.parent[xr] += self.parent[yr] self.parent[yr] = xr if __name__ == "__main__": main()
false
4.081633
[ "-#!/usr/bin/env python3", "-N, M, K = list(map(int, input().split()))", "+", "+", "+def main():", "+ N, M, K = list(map(int, input().split()))", "+ friend_or_block = [0] * N", "+ friends_chain = UnionFindTree(N)", "+ for _ in range(M):", "+ a, b = list(map(int, input().split()))", "+ a, b = a - 1, b - 1", "+ friends_chain.unite(a, b)", "+ friend_or_block[a] += 1", "+ friend_or_block[b] += 1", "+ for _ in range(K):", "+ c, d = list(map(int, input().split()))", "+ c, d = c - 1, d - 1", "+ if friends_chain.same(c, d):", "+ friend_or_block[c] += 1", "+ friend_or_block[d] += 1", "+ print((*[friends_chain.count(i) - friend_or_block[i] - 1 for i in range(N)]))", "-friend_or_block = [set() for _ in range(N)]", "-friends_chain = UnionFindTree(N)", "-for _ in range(M):", "- a, b = list(map(int, input().split()))", "- a, b = a - 1, b - 1", "- friends_chain.unite(a, b)", "- friend_or_block[a].add(b)", "- friend_or_block[b].add(a)", "-for _ in range(K):", "- c, d = list(map(int, input().split()))", "- c, d = c - 1, d - 1", "- if friends_chain.same(c, d):", "- friend_or_block[c].add(d)", "- friend_or_block[d].add(c)", "-print(", "- (", "- \" \".join(", "- map(", "- str,", "- [", "- friends_chain.count(i) - len(friend_or_block[i]) - 1", "- for i in range(N)", "- ],", "- )", "- )", "- )", "-)", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.058023
0.041027
1.414285
[ "s503286171", "s407025351" ]
u519939795
p02641
python
s376147005
s332133634
24
20
9,176
9,260
Accepted
Accepted
16.67
import sys x,n=list(map(int,input().split())) ans=10000 ansaa=10000 ans1=[] ans2=[] ans3=[] if n>0: l=list(map(int,input().split())) else: print(x) sys.exit() for i in range(len(l)): if abs(ans-l[i])<ans: ans1.append(l[i]) ans1.append(l[i]-1) ans1.append(l[i]+1) ans1=sorted(ans1) for j in range(len(ans1)): if abs(x-ans1[j])<ans and ans1[j] not in l: ans2.append(ans1[j]) ans=min(ans,x-ans1[j]) print((max(ans2)))
import sys x,n=list(map(int,input().split())) ans=10000 ans1=[] ans2=[] if n>0: l=list(map(int,input().split())) else: print(x) sys.exit() for i in range(len(l)): if abs(ans-l[i])<ans: ans1.append(l[i]) ans1.append(l[i]-1) ans1.append(l[i]+1) ans1=sorted(ans1) for j in range(len(ans1)): if abs(x-ans1[j])<ans and ans1[j] not in l: ans2.append(ans1[j]) ans=min(ans,x-ans1[j]) print((max(ans2)))
23
21
488
466
import sys x, n = list(map(int, input().split())) ans = 10000 ansaa = 10000 ans1 = [] ans2 = [] ans3 = [] if n > 0: l = list(map(int, input().split())) else: print(x) sys.exit() for i in range(len(l)): if abs(ans - l[i]) < ans: ans1.append(l[i]) ans1.append(l[i] - 1) ans1.append(l[i] + 1) ans1 = sorted(ans1) for j in range(len(ans1)): if abs(x - ans1[j]) < ans and ans1[j] not in l: ans2.append(ans1[j]) ans = min(ans, x - ans1[j]) print((max(ans2)))
import sys x, n = list(map(int, input().split())) ans = 10000 ans1 = [] ans2 = [] if n > 0: l = list(map(int, input().split())) else: print(x) sys.exit() for i in range(len(l)): if abs(ans - l[i]) < ans: ans1.append(l[i]) ans1.append(l[i] - 1) ans1.append(l[i] + 1) ans1 = sorted(ans1) for j in range(len(ans1)): if abs(x - ans1[j]) < ans and ans1[j] not in l: ans2.append(ans1[j]) ans = min(ans, x - ans1[j]) print((max(ans2)))
false
8.695652
[ "-ansaa = 10000", "-ans3 = []" ]
false
0.043453
0.039749
1.09318
[ "s376147005", "s332133634" ]
u766684188
p02901
python
s976274194
s206223910
476
250
141,020
43,628
Accepted
Accepted
47.48
import sys input=sys.stdin.readline def main(): n,m=list(map(int,input().split())) Cost=[0]*m Key=[0]*m for i in range(m): a,b=list(map(int,input().split())) C=tuple(map(int,input().split())) Cost[i]=a for c in C: Key[i]+=1<<(c-1) DP=[[float('inf')]*(1<<n) for _ in range(m+1)] DP[0][0]=0 for i,(c,k) in enumerate(zip(Cost,Key)): for j in range(1<<n): DP[i+1][j]=min(DP[i][j],DP[i+1][j]) DP[i+1][j|k]=min(DP[i+1][j|k],DP[i][j]+c) print((-1 if DP[-1][-1]==float('inf') else DP[-1][-1])) if __name__=='__main__': main()
import sys input=sys.stdin.readline def main(): inf=float('inf') n,m=list(map(int,input().split())) Cost=[0]*m Key=[0]*m for i in range(m): a,b=list(map(int,input().split())) C=tuple(map(int,input().split())) Cost[i]=a for c in C: Key[i]+=1<<(c-1) DP=[inf]*(1<<n) DP[0]=0 for c,k in zip(Cost,Key): for i in range(1<<n): DP[i|k]=min(DP[i|k],DP[i]+c) print((-1 if DP[-1]==inf else DP[-1])) if __name__=='__main__': main()
23
23
639
533
import sys input = sys.stdin.readline def main(): n, m = list(map(int, input().split())) Cost = [0] * m Key = [0] * m for i in range(m): a, b = list(map(int, input().split())) C = tuple(map(int, input().split())) Cost[i] = a for c in C: Key[i] += 1 << (c - 1) DP = [[float("inf")] * (1 << n) for _ in range(m + 1)] DP[0][0] = 0 for i, (c, k) in enumerate(zip(Cost, Key)): for j in range(1 << n): DP[i + 1][j] = min(DP[i][j], DP[i + 1][j]) DP[i + 1][j | k] = min(DP[i + 1][j | k], DP[i][j] + c) print((-1 if DP[-1][-1] == float("inf") else DP[-1][-1])) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): inf = float("inf") n, m = list(map(int, input().split())) Cost = [0] * m Key = [0] * m for i in range(m): a, b = list(map(int, input().split())) C = tuple(map(int, input().split())) Cost[i] = a for c in C: Key[i] += 1 << (c - 1) DP = [inf] * (1 << n) DP[0] = 0 for c, k in zip(Cost, Key): for i in range(1 << n): DP[i | k] = min(DP[i | k], DP[i] + c) print((-1 if DP[-1] == inf else DP[-1])) if __name__ == "__main__": main()
false
0
[ "+ inf = float(\"inf\")", "- DP = [[float(\"inf\")] * (1 << n) for _ in range(m + 1)]", "- DP[0][0] = 0", "- for i, (c, k) in enumerate(zip(Cost, Key)):", "- for j in range(1 << n):", "- DP[i + 1][j] = min(DP[i][j], DP[i + 1][j])", "- DP[i + 1][j | k] = min(DP[i + 1][j | k], DP[i][j] + c)", "- print((-1 if DP[-1][-1] == float(\"inf\") else DP[-1][-1]))", "+ DP = [inf] * (1 << n)", "+ DP[0] = 0", "+ for c, k in zip(Cost, Key):", "+ for i in range(1 << n):", "+ DP[i | k] = min(DP[i | k], DP[i] + c)", "+ print((-1 if DP[-1] == inf else DP[-1]))" ]
false
0.087423
0.042929
2.036464
[ "s976274194", "s206223910" ]
u600402037
p03103
python
s047599025
s361488859
418
347
27,840
27,788
Accepted
Accepted
16.99
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() AB = [lr() for _ in range(N)] AB.sort() drink = 0 answer = 0 for i in range(N): cost = AB[i][0] limit = AB[i][1] if drink + limit < M: answer += cost * limit drink += limit else: x = M - drink answer += cost * x break print(answer)
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() AB = [lr() for _ in range(N)] AB.sort() answer = 0 for cost, num in AB: if M - num > 0: answer += cost * num M -= num else: answer += cost * M break print(answer)
24
20
461
372
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() AB = [lr() for _ in range(N)] AB.sort() drink = 0 answer = 0 for i in range(N): cost = AB[i][0] limit = AB[i][1] if drink + limit < M: answer += cost * limit drink += limit else: x = M - drink answer += cost * x break print(answer)
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M = lr() AB = [lr() for _ in range(N)] AB.sort() answer = 0 for cost, num in AB: if M - num > 0: answer += cost * num M -= num else: answer += cost * M break print(answer)
false
16.666667
[ "-drink = 0", "-for i in range(N):", "- cost = AB[i][0]", "- limit = AB[i][1]", "- if drink + limit < M:", "- answer += cost * limit", "- drink += limit", "+for cost, num in AB:", "+ if M - num > 0:", "+ answer += cost * num", "+ M -= num", "- x = M - drink", "- answer += cost * x", "+ answer += cost * M" ]
false
0.076379
0.03552
2.150333
[ "s047599025", "s361488859" ]
u694810977
p03145
python
s340060350
s693128839
19
17
2,940
2,940
Accepted
Accepted
10.53
AB,BC,CA = list(map(int,input().split())) print(((AB*BC) // 2))
a,b,c = list(map(int,input().split())) menseki = (a * b) // 2 print(menseki)
2
3
56
72
AB, BC, CA = list(map(int, input().split())) print(((AB * BC) // 2))
a, b, c = list(map(int, input().split())) menseki = (a * b) // 2 print(menseki)
false
33.333333
[ "-AB, BC, CA = list(map(int, input().split()))", "-print(((AB * BC) // 2))", "+a, b, c = list(map(int, input().split()))", "+menseki = (a * b) // 2", "+print(menseki)" ]
false
0.057963
0.053191
1.089725
[ "s340060350", "s693128839" ]
u977661421
p02779
python
s650408654
s646530884
190
91
25,168
25,168
Accepted
Accepted
52.11
# -*- coding: utf-8 -*- n = int(eval(input())) a = [int(i) for i in input().split()] """ if len(set(a)) == len(a): print("YES") else: print("NO") """ flag = True a.sort() for i in range(n - 1): if a[i] == a[i + 1]: flag = False if flag: print("YES") else: print("NO")
# -*- coding: utf-8 -*- n = int(eval(input())) a = [int(i) for i in input().split()] if len(set(a)) == n: print("YES") else: print("NO")
20
8
311
148
# -*- coding: utf-8 -*- n = int(eval(input())) a = [int(i) for i in input().split()] """ if len(set(a)) == len(a): print("YES") else: print("NO") """ flag = True a.sort() for i in range(n - 1): if a[i] == a[i + 1]: flag = False if flag: print("YES") else: print("NO")
# -*- coding: utf-8 -*- n = int(eval(input())) a = [int(i) for i in input().split()] if len(set(a)) == n: print("YES") else: print("NO")
false
60
[ "-\"\"\"", "-if len(set(a)) == len(a):", "+if len(set(a)) == n:", "-\"\"\"", "-flag = True", "-a.sort()", "-for i in range(n - 1):", "- if a[i] == a[i + 1]:", "- flag = False", "-if flag:", "- print(\"YES\")", "-else:", "- print(\"NO\")" ]
false
0.043422
0.045423
0.955947
[ "s650408654", "s646530884" ]
u762420987
p03814
python
s217972763
s987173276
26
18
6,180
3,516
Accepted
Accepted
30.77
s = list(eval(input())) a_index = s.index("A") z_index = s[::-1].index("Z") print((len(s) - (z_index) - a_index))
s = eval(input()) A = s.index("A") Z = s[::-1].index("Z") print((len(s) - Z - A))
4
4
109
77
s = list(eval(input())) a_index = s.index("A") z_index = s[::-1].index("Z") print((len(s) - (z_index) - a_index))
s = eval(input()) A = s.index("A") Z = s[::-1].index("Z") print((len(s) - Z - A))
false
0
[ "-s = list(eval(input()))", "-a_index = s.index(\"A\")", "-z_index = s[::-1].index(\"Z\")", "-print((len(s) - (z_index) - a_index))", "+s = eval(input())", "+A = s.index(\"A\")", "+Z = s[::-1].index(\"Z\")", "+print((len(s) - Z - A))" ]
false
0.040723
0.041479
0.981768
[ "s217972763", "s987173276" ]
u218834617
p03341
python
s883557914
s636558262
253
110
32,872
9,752
Accepted
Accepted
56.52
N=int(eval(input())) S=eval(input()) l,r=[0]*N,[0]*N for i in range(N-1): l[i+1]+=l[i]+(S[i]=='W') for i in range(N-1,0,-1): r[i-1]+=r[i]+(S[i]=='E') ans=r[i] for i in range(1,N): ans=min(ans,l[i]+r[i]) print(ans)
N=int(eval(input())) S=eval(input()) ans=cur=S.count('W') for c in reversed(S): if c=='W': cur-=1 else: cur+=1 ans=min(ans,cur) print(ans)
11
10
224
164
N = int(eval(input())) S = eval(input()) l, r = [0] * N, [0] * N for i in range(N - 1): l[i + 1] += l[i] + (S[i] == "W") for i in range(N - 1, 0, -1): r[i - 1] += r[i] + (S[i] == "E") ans = r[i] for i in range(1, N): ans = min(ans, l[i] + r[i]) print(ans)
N = int(eval(input())) S = eval(input()) ans = cur = S.count("W") for c in reversed(S): if c == "W": cur -= 1 else: cur += 1 ans = min(ans, cur) print(ans)
false
9.090909
[ "-l, r = [0] * N, [0] * N", "-for i in range(N - 1):", "- l[i + 1] += l[i] + (S[i] == \"W\")", "-for i in range(N - 1, 0, -1):", "- r[i - 1] += r[i] + (S[i] == \"E\")", "-ans = r[i]", "-for i in range(1, N):", "- ans = min(ans, l[i] + r[i])", "+ans = cur = S.count(\"W\")", "+for c in reversed(S):", "+ if c == \"W\":", "+ cur -= 1", "+ else:", "+ cur += 1", "+ ans = min(ans, cur)" ]
false
0.13766
0.037076
3.712938
[ "s883557914", "s636558262" ]