user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
list
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
list
u022979415
p03821
python
s792090465
s760865759
410
335
15,016
11,048
Accepted
Accepted
18.29
from math import ceil def main(): length = int(eval(input())) sequence = [0 for _ in range(length)] target = [0 for _ in range(length)] for i in range(length): a, b = list(map(int, input().split())) sequence[i] = a target[i] = b answer = 0 cumulative_push = 0 for i in range(-1, -length - 1, -1): sequence[i] += cumulative_push now_push = ceil(sequence[i] / target[i]) * target[i] - sequence[i] cumulative_push += now_push answer += now_push print(answer) if __name__ == '__main__': main()
from math import ceil def main(): n = int(eval(input())) a = [0 for _ in range(n)] b = [0 for _ in range(n)] for i in range(n): a[i], b[i] = list(map(int, input().split())) added = 0 for i in range(n - 1, -1, -1): added += ceil((a[i] + added) / b[i]) * b[i] - (a[i] + added) print(added) if __name__ == '__main__': main()
24
18
598
380
from math import ceil def main(): length = int(eval(input())) sequence = [0 for _ in range(length)] target = [0 for _ in range(length)] for i in range(length): a, b = list(map(int, input().split())) sequence[i] = a target[i] = b answer = 0 cumulative_push = 0 for i in range(-1, -length - 1, -1): sequence[i] += cumulative_push now_push = ceil(sequence[i] / target[i]) * target[i] - sequence[i] cumulative_push += now_push answer += now_push print(answer) if __name__ == "__main__": main()
from math import ceil def main(): n = int(eval(input())) a = [0 for _ in range(n)] b = [0 for _ in range(n)] for i in range(n): a[i], b[i] = list(map(int, input().split())) added = 0 for i in range(n - 1, -1, -1): added += ceil((a[i] + added) / b[i]) * b[i] - (a[i] + added) print(added) if __name__ == "__main__": main()
false
25
[ "- length = int(eval(input()))", "- sequence = [0 for _ in range(length)]", "- target = [0 for _ in range(length)]", "- for i in range(length):", "- a, b = list(map(int, input().split()))", "- sequence[i] = a", "- target[i] = b", "- answer = 0", "- cumulative_push = 0", "- for i in range(-1, -length - 1, -1):", "- sequence[i] += cumulative_push", "- now_push = ceil(sequence[i] / target[i]) * target[i] - sequence[i]", "- cumulative_push += now_push", "- answer += now_push", "- print(answer)", "+ n = int(eval(input()))", "+ a = [0 for _ in range(n)]", "+ b = [0 for _ in range(n)]", "+ for i in range(n):", "+ a[i], b[i] = list(map(int, input().split()))", "+ added = 0", "+ for i in range(n - 1, -1, -1):", "+ added += ceil((a[i] + added) / b[i]) * b[i] - (a[i] + added)", "+ print(added)" ]
false
0.038397
0.038776
0.990236
[ "s792090465", "s760865759" ]
u312025627
p03319
python
s984933777
s168131614
218
189
52,476
52,464
Accepted
Accepted
13.3
def main(): N, K = (int(i) for i in input().split()) A = [int(i) for i in input().split()] mi = min(A) idx = A.index(mi) h1 = idx h2 = N - idx - 1 ans = N for k in range(K): cur = (max(0, (h1 - k))+(K-1)-1)//(K-1) + \ (max(0, (h2 - ((K-1) - k)))+(K-1)-1)//(K-1) + 1 ans = min(ans, cur) print(ans) if __name__ == '__main__': main()
def main(): import sys input = sys.stdin.buffer.readline N, K = (int(i)-1 for i in input().split()) _ = [int(i) for i in input().split()] print(((N + K - 1)//K)) if __name__ == '__main__': main()
17
10
417
229
def main(): N, K = (int(i) for i in input().split()) A = [int(i) for i in input().split()] mi = min(A) idx = A.index(mi) h1 = idx h2 = N - idx - 1 ans = N for k in range(K): cur = ( (max(0, (h1 - k)) + (K - 1) - 1) // (K - 1) + (max(0, (h2 - ((K - 1) - k))) + (K - 1) - 1) // (K - 1) + 1 ) ans = min(ans, cur) print(ans) if __name__ == "__main__": main()
def main(): import sys input = sys.stdin.buffer.readline N, K = (int(i) - 1 for i in input().split()) _ = [int(i) for i in input().split()] print(((N + K - 1) // K)) if __name__ == "__main__": main()
false
41.176471
[ "- N, K = (int(i) for i in input().split())", "- A = [int(i) for i in input().split()]", "- mi = min(A)", "- idx = A.index(mi)", "- h1 = idx", "- h2 = N - idx - 1", "- ans = N", "- for k in range(K):", "- cur = (", "- (max(0, (h1 - k)) + (K - 1) - 1) // (K - 1)", "- + (max(0, (h2 - ((K - 1) - k))) + (K - 1) - 1) // (K - 1)", "- + 1", "- )", "- ans = min(ans, cur)", "- print(ans)", "+ import sys", "+", "+ input = sys.stdin.buffer.readline", "+ N, K = (int(i) - 1 for i in input().split())", "+ _ = [int(i) for i in input().split()]", "+ print(((N + K - 1) // K))" ]
false
0.039195
0.040788
0.960929
[ "s984933777", "s168131614" ]
u933096856
p02419
python
s902100891
s609198708
60
30
7,640
7,544
Accepted
Accepted
50
import re c=0 p=input().upper() ptn=re.compile(r'^'+p+r'$') while True: s=eval(input()) if s =='END_OF_TEXT': break a=s.upper().split() for i in a: if re.match(ptn, i): c+=1 print(c)
import re c=0 ptn=re.compile(r'^'+input().upper()+r'$') while True: s=eval(input()) if s =='END_OF_TEXT': break a=s.upper().split() for i in a: if re.match(ptn, i): c+=1 print(c)
15
14
236
231
import re c = 0 p = input().upper() ptn = re.compile(r"^" + p + r"$") while True: s = eval(input()) if s == "END_OF_TEXT": break a = s.upper().split() for i in a: if re.match(ptn, i): c += 1 print(c)
import re c = 0 ptn = re.compile(r"^" + input().upper() + r"$") while True: s = eval(input()) if s == "END_OF_TEXT": break a = s.upper().split() for i in a: if re.match(ptn, i): c += 1 print(c)
false
6.666667
[ "-p = input().upper()", "-ptn = re.compile(r\"^\" + p + r\"$\")", "+ptn = re.compile(r\"^\" + input().upper() + r\"$\")" ]
false
0.040326
0.039894
1.01082
[ "s902100891", "s609198708" ]
u863442865
p02725
python
s417803983
s269773418
186
141
25,432
25,432
Accepted
Accepted
24.19
#どっちで出すか注意, rstrip注意 #提出前に見返すこと! def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque #from collections import defaultdict from itertools import combinations, permutations, accumulate #from itertools import product from bisect import bisect_left,bisect_right import heapq from math import floor, ceil #from operator import itemgetter #inf = 10**17 #mod = 10**9 + 7 K,N = list(map(int, input().split())) a = list(map(int, input().split())) res = 10**20 for i in range(1, N-1): res = min(K-(a[i+1]-a[i]), K-(a[i]-a[i-1]), res) res = min(K-(a[1]-a[0]), res, a[N-1]-a[0]) res = min(res, K-(a[N-1]-a[N-2])) print(res) if __name__ == '__main__': main()
#どっちで出すか注意, rstrip注意 #提出前に見返すこと! def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque #from collections import defaultdict from itertools import combinations, permutations, accumulate #from itertools import product from bisect import bisect_left,bisect_right import heapq from math import floor, ceil #from operator import itemgetter #inf = 10**17 #mod = 10**9 + 7 k,n = list(map(int, input().split())) a = list(map(int, input().split())) res = 0 for i in range(n-1): res = max(res, a[i+1]-a[i]) res = max(res, a[0]+k-a[n-1]) print((k-res)) if __name__ == '__main__': main()
31
28
832
749
# どっちで出すか注意, rstrip注意 # 提出前に見返すこと! def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque # from collections import defaultdict from itertools import combinations, permutations, accumulate # from itertools import product from bisect import bisect_left, bisect_right import heapq from math import floor, ceil # from operator import itemgetter # inf = 10**17 # mod = 10**9 + 7 K, N = list(map(int, input().split())) a = list(map(int, input().split())) res = 10**20 for i in range(1, N - 1): res = min(K - (a[i + 1] - a[i]), K - (a[i] - a[i - 1]), res) res = min(K - (a[1] - a[0]), res, a[N - 1] - a[0]) res = min(res, K - (a[N - 1] - a[N - 2])) print(res) if __name__ == "__main__": main()
# どっちで出すか注意, rstrip注意 # 提出前に見返すこと! def main(): import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter, deque # from collections import defaultdict from itertools import combinations, permutations, accumulate # from itertools import product from bisect import bisect_left, bisect_right import heapq from math import floor, ceil # from operator import itemgetter # inf = 10**17 # mod = 10**9 + 7 k, n = list(map(int, input().split())) a = list(map(int, input().split())) res = 0 for i in range(n - 1): res = max(res, a[i + 1] - a[i]) res = max(res, a[0] + k - a[n - 1]) print((k - res)) if __name__ == "__main__": main()
false
9.677419
[ "- K, N = list(map(int, input().split()))", "+ k, n = list(map(int, input().split()))", "- res = 10**20", "- for i in range(1, N - 1):", "- res = min(K - (a[i + 1] - a[i]), K - (a[i] - a[i - 1]), res)", "- res = min(K - (a[1] - a[0]), res, a[N - 1] - a[0])", "- res = min(res, K - (a[N - 1] - a[N - 2]))", "- print(res)", "+ res = 0", "+ for i in range(n - 1):", "+ res = max(res, a[i + 1] - a[i])", "+ res = max(res, a[0] + k - a[n - 1])", "+ print((k - res))" ]
false
0.04148
0.047462
0.873971
[ "s417803983", "s269773418" ]
u200887663
p02785
python
s257496182
s804068874
169
151
26,764
26,024
Accepted
Accepted
10.65
n,k=list(map(int,input().split())) hl=list(map(int,input().split())) ans=0 if n<=k: print((0)) else: hl.sort(reverse=True) temp=hl[(k+1)-1:n] for v in temp: ans+=v print(ans)
#n=int(input()) n,k=list(map(int,input().split())) l=list(map(int,input().split())) #l=[list(map(int,input().split())) for i in range(n)] if n<=k: print((0)) else: l.sort(reverse=True) print((sum(l[k:n])))
11
10
205
218
n, k = list(map(int, input().split())) hl = list(map(int, input().split())) ans = 0 if n <= k: print((0)) else: hl.sort(reverse=True) temp = hl[(k + 1) - 1 : n] for v in temp: ans += v print(ans)
# n=int(input()) n, k = list(map(int, input().split())) l = list(map(int, input().split())) # l=[list(map(int,input().split())) for i in range(n)] if n <= k: print((0)) else: l.sort(reverse=True) print((sum(l[k:n])))
false
9.090909
[ "+# n=int(input())", "-hl = list(map(int, input().split()))", "-ans = 0", "+l = list(map(int, input().split()))", "+# l=[list(map(int,input().split())) for i in range(n)]", "- hl.sort(reverse=True)", "- temp = hl[(k + 1) - 1 : n]", "- for v in temp:", "- ans += v", "- print(ans)", "+ l.sort(reverse=True)", "+ print((sum(l[k:n])))" ]
false
0.043908
0.044103
0.995589
[ "s257496182", "s804068874" ]
u094191970
p02845
python
s211219060
s952171561
105
89
14,364
14,072
Accepted
Accepted
15.24
n=int(eval(input())) a=list(map(int,input().split())) mod=1000000007 ans=1 r,b,g=0,0,0 r2,b2,g2=-1,-1,-1 for i in a: if r2==r and b2==b and g2==g: print((0)) exit() r2=r b2=b g2=g if i==r and i==b and i==g: ans*=3 ans%=mod r+=1 elif (i==r and i==b) or (i==g and i==r): ans*=2 ans%=mod r+=1 elif i==b and i==g: ans*=2 ans%=mod g+=1 elif i==r: r+=1 elif i==b: b+=1 elif i==g: g+=1 else: print((0)) exit() print(ans)
n=int(eval(input())) a=list(map(int,input().split())) mod=1000000007 ans=1 r,b,g=0,0,0 for i in a: if i==r and i==b and i==g: ans*=3 ans%=mod r+=1 elif (i==r and i==b) or (i==g and i==r): ans*=2 ans%=mod r+=1 elif i==b and i==g: ans*=2 ans%=mod g+=1 elif i==r: r+=1 elif i==b: b+=1 elif i==g: g+=1 else: print((0)) exit() print(ans)
38
29
615
493
n = int(eval(input())) a = list(map(int, input().split())) mod = 1000000007 ans = 1 r, b, g = 0, 0, 0 r2, b2, g2 = -1, -1, -1 for i in a: if r2 == r and b2 == b and g2 == g: print((0)) exit() r2 = r b2 = b g2 = g if i == r and i == b and i == g: ans *= 3 ans %= mod r += 1 elif (i == r and i == b) or (i == g and i == r): ans *= 2 ans %= mod r += 1 elif i == b and i == g: ans *= 2 ans %= mod g += 1 elif i == r: r += 1 elif i == b: b += 1 elif i == g: g += 1 else: print((0)) exit() print(ans)
n = int(eval(input())) a = list(map(int, input().split())) mod = 1000000007 ans = 1 r, b, g = 0, 0, 0 for i in a: if i == r and i == b and i == g: ans *= 3 ans %= mod r += 1 elif (i == r and i == b) or (i == g and i == r): ans *= 2 ans %= mod r += 1 elif i == b and i == g: ans *= 2 ans %= mod g += 1 elif i == r: r += 1 elif i == b: b += 1 elif i == g: g += 1 else: print((0)) exit() print(ans)
false
23.684211
[ "-r2, b2, g2 = -1, -1, -1", "- if r2 == r and b2 == b and g2 == g:", "- print((0))", "- exit()", "- r2 = r", "- b2 = b", "- g2 = g" ]
false
0.037779
0.038399
0.983848
[ "s211219060", "s952171561" ]
u514401521
p03290
python
s009676493
s499427701
177
158
3,064
3,064
Accepted
Accepted
10.73
D, G = list(map(int, input().split())) P = [] C = [] for i in range(D): p, c = list(map(int, input().split())) P.append(p) C.append(c) ans = 100000000 for i in range(2 ** D): a = 0 b = 0 for j in range(D): if i >> j & 1: a += 100 * P[j] * (j + 1) + C[j] b += P[j] for k in range(D-1, -1, -1): if i >> k & 1: continue if a >= G: break for l in range(P[k]): a += 100 * (k + 1) b += 1 if a >= G: break ans = min(ans, b) print(ans)
""" bit全探索 """ D, G = list(map(int, input().split())) P = [] C = [] for i in range(D): p, c = list(map(int, input().split())) P.append(p) C.append(c) ans = 100000000 for i in range(2 ** D): a = 0 b = 0 for j in range(D): if i >> j & 1: a += 100 * P[j] * (j + 1) + C[j] b += P[j] for k in range(D-1, -1, -1): if i >> k & 1: continue if a >= G: break for l in range(P[k] - 1): a += 100 * (k + 1) b += 1 if a >= G: break if a >= G: ans = min(ans, b) print(ans)
28
33
607
651
D, G = list(map(int, input().split())) P = [] C = [] for i in range(D): p, c = list(map(int, input().split())) P.append(p) C.append(c) ans = 100000000 for i in range(2**D): a = 0 b = 0 for j in range(D): if i >> j & 1: a += 100 * P[j] * (j + 1) + C[j] b += P[j] for k in range(D - 1, -1, -1): if i >> k & 1: continue if a >= G: break for l in range(P[k]): a += 100 * (k + 1) b += 1 if a >= G: break ans = min(ans, b) print(ans)
""" bit全探索 """ D, G = list(map(int, input().split())) P = [] C = [] for i in range(D): p, c = list(map(int, input().split())) P.append(p) C.append(c) ans = 100000000 for i in range(2**D): a = 0 b = 0 for j in range(D): if i >> j & 1: a += 100 * P[j] * (j + 1) + C[j] b += P[j] for k in range(D - 1, -1, -1): if i >> k & 1: continue if a >= G: break for l in range(P[k] - 1): a += 100 * (k + 1) b += 1 if a >= G: break if a >= G: ans = min(ans, b) print(ans)
false
15.151515
[ "+\"\"\"", "+bit全探索", "+\"\"\"", "- for l in range(P[k]):", "+ for l in range(P[k] - 1):", "- ans = min(ans, b)", "+ if a >= G:", "+ ans = min(ans, b)" ]
false
0.045423
0.076073
0.597103
[ "s009676493", "s499427701" ]
u301624971
p02773
python
s837558084
s356518857
904
795
44,248
47,248
Accepted
Accepted
12.06
N = int(eval(input())) C = dict() for i in range(N): a = eval(input()) if(a not in list(C.keys())): C[a] = 1 else: val = C[a] C[a] = val + 1 m=0 for i in list(C.values()): if(i > m): m=i ans = sorted(C.items()) for i in ans: if(m==i[1]): print((i[0]))
def myAnswer(N:int,S:list) -> None: dic = {} for s in S: if(s in list(dic.keys())): dic[s]+=1 else: dic[s]=1 MAX = max(dic.values()) dic2 = sorted(dic.items()) for key,value in dic2: if(MAX == value): print(key) def modelAnswer(): tmp=1 def main(): N = int(eval(input())) S = [] for _ in range(N): S.append(eval(input())) myAnswer(N,S[:]) if __name__ == '__main__': main()
22
24
312
466
N = int(eval(input())) C = dict() for i in range(N): a = eval(input()) if a not in list(C.keys()): C[a] = 1 else: val = C[a] C[a] = val + 1 m = 0 for i in list(C.values()): if i > m: m = i ans = sorted(C.items()) for i in ans: if m == i[1]: print((i[0]))
def myAnswer(N: int, S: list) -> None: dic = {} for s in S: if s in list(dic.keys()): dic[s] += 1 else: dic[s] = 1 MAX = max(dic.values()) dic2 = sorted(dic.items()) for key, value in dic2: if MAX == value: print(key) def modelAnswer(): tmp = 1 def main(): N = int(eval(input())) S = [] for _ in range(N): S.append(eval(input())) myAnswer(N, S[:]) if __name__ == "__main__": main()
false
8.333333
[ "-N = int(eval(input()))", "-C = dict()", "-for i in range(N):", "- a = eval(input())", "- if a not in list(C.keys()):", "- C[a] = 1", "- else:", "- val = C[a]", "- C[a] = val + 1", "-m = 0", "-for i in list(C.values()):", "- if i > m:", "- m = i", "-ans = sorted(C.items())", "-for i in ans:", "- if m == i[1]:", "- print((i[0]))", "+def myAnswer(N: int, S: list) -> None:", "+ dic = {}", "+ for s in S:", "+ if s in list(dic.keys()):", "+ dic[s] += 1", "+ else:", "+ dic[s] = 1", "+ MAX = max(dic.values())", "+ dic2 = sorted(dic.items())", "+ for key, value in dic2:", "+ if MAX == value:", "+ print(key)", "+", "+", "+def modelAnswer():", "+ tmp = 1", "+", "+", "+def main():", "+ N = int(eval(input()))", "+ S = []", "+ for _ in range(N):", "+ S.append(eval(input()))", "+ myAnswer(N, S[:])", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.09852
0.042185
2.335409
[ "s837558084", "s356518857" ]
u644907318
p03005
python
s740375757
s400069525
178
64
38,384
61,808
Accepted
Accepted
64.04
N,K = list(map(int,input().split())) if K>1: print((N-K)) else: print((0))
N,K = list(map(int,input().split())) if K==1: print((0)) else: print((N-K))
5
5
76
77
N, K = list(map(int, input().split())) if K > 1: print((N - K)) else: print((0))
N, K = list(map(int, input().split())) if K == 1: print((0)) else: print((N - K))
false
0
[ "-if K > 1:", "+if K == 1:", "+ print((0))", "+else:", "-else:", "- print((0))" ]
false
0.059085
0.035942
1.643905
[ "s740375757", "s400069525" ]
u496744988
p03575
python
s125119170
s617358894
73
63
6,972
6,208
Accepted
Accepted
13.7
from collections import Counter from functools import reduce # import statistics import bisect import copy import fractions import math import random import pprint import sys import time sys.setrecursionlimit(10**7) INF = 10 ** 18 MOD = 10 ** 9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def MI(): return list(map(int, sys.stdin.readline().split())) def II(): return int(sys.stdin.readline()) def IS(): return eval(input()) def C(x): return Counter(x) def GCD_LIST(numbers): return reduce(fractions.gcd, numbers) def LCM_LIST(numbers): return reduce(LCM, numbers) def LCM(m, n): return (m * n // fractions.gcd(m, n)) def unite(x, y): # それぞれのノードの根を求める x = root(x) y = root(y) if x == y: return # node[x]の根をyに変更する node[x] = y def same(x,y): return bool(root(x) == root(y)) def root(x): if node[x] == x: # xが根の場合 return x else: node[x] = root(node[x]) # 経路圧縮 return node[x] def dfs(v): # ノードに訪れた visited[v] = True for v2 in range(n): if graph[v][v2] == False: # そもそもvとv2が辺でつながっていない continue if visited[v2] == True: # もう見た continue dfs(v2) # nは頂点の数 n, m = MI() ans = 0 sides = [LI() for _ in range(m)] visited = [False] * n # 隣接行列を用いてグラフの管理をする graph = [[False] * n for _ in range(n)] # 初期化、graph[i-1][j-1] = 1ならば頂点i,jは連結している for a, b in sides: graph[a-1][b-1] = True graph[b-1][a-1] = True # pprint.pprint(graph) for a, b in sides: # 辺の削除 graph[a-1][b-1] = False graph[b-1][a-1] = False for i in range(n): visited[i] = False dfs(0) # 探索実行後訪れていないノードが1つでもあれば # 削除した辺は橋である for i in range(n): if visited[i] == False: ans += 1 break # 辺を元に戻す graph[a-1][b-1] = True graph[b-1][a-1] = True print(ans)
from collections import Counter from functools import reduce # import statistics import bisect import copy import fractions import math import random import pprint import sys import time sys.setrecursionlimit(10**7) INF = 10 ** 18 MOD = 10 ** 9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def MI(): return list(map(int, sys.stdin.readline().split())) def II(): return int(sys.stdin.readline()) def IS(): return eval(input()) def C(x): return Counter(x) def GCD_LIST(numbers): return reduce(fractions.gcd, numbers) def LCM_LIST(numbers): return reduce(LCM, numbers) def LCM(m, n): return (m * n // fractions.gcd(m, n)) def unite(x, y): # それぞれのノードの根を求める x = root(x) y = root(y) if x == y: return # node[x]の根をyに変更する node[x] = y def same(x,y): return bool(root(x) == root(y)) def root(x): if node[x] == x: # xが根の場合 return x else: node[x] = root(node[x]) # 経路圧縮 return node[x] def dfs(v): # ノードに訪れた visited[v] = True for v2 in range(n): if graph[v][v2] == False: # そもそもvとv2が辺でつながっていない continue if visited[v2] == True: # もう見た continue dfs(v2) # nは頂点の数 n, m = MI() ans = 0 sides = [LI() for _ in range(m)] # 隣接行列を用いてグラフの管理をする # graph = [[False] * n for _ in range(n)] # もしグラフ全体が連結ならばuf[i]=iとなる頂点がただ1つだけある # Union-Find for i in range(m): # 最初各ノードの根は自分自身 node = [k for k in range(n)] for j, side in enumerate(sides): # 連結しない if i == j: continue unite(side[0]-1, side[1]-1) # 根が自分自身であるものが2つ以上存在する場合、グラフは非連結である # 1である場合連結なのでのぞいた辺は橋「ではない」 if sum(node[num] == num for num in range(len(node))) != 1: ans += 1 print(ans)
90
81
2,051
1,939
from collections import Counter from functools import reduce # import statistics import bisect import copy import fractions import math import random import pprint import sys import time sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def MI(): return list(map(int, sys.stdin.readline().split())) def II(): return int(sys.stdin.readline()) def IS(): return eval(input()) def C(x): return Counter(x) def GCD_LIST(numbers): return reduce(fractions.gcd, numbers) def LCM_LIST(numbers): return reduce(LCM, numbers) def LCM(m, n): return m * n // fractions.gcd(m, n) def unite(x, y): # それぞれのノードの根を求める x = root(x) y = root(y) if x == y: return # node[x]の根をyに変更する node[x] = y def same(x, y): return bool(root(x) == root(y)) def root(x): if node[x] == x: # xが根の場合 return x else: node[x] = root(node[x]) # 経路圧縮 return node[x] def dfs(v): # ノードに訪れた visited[v] = True for v2 in range(n): if graph[v][v2] == False: # そもそもvとv2が辺でつながっていない continue if visited[v2] == True: # もう見た continue dfs(v2) # nは頂点の数 n, m = MI() ans = 0 sides = [LI() for _ in range(m)] visited = [False] * n # 隣接行列を用いてグラフの管理をする graph = [[False] * n for _ in range(n)] # 初期化、graph[i-1][j-1] = 1ならば頂点i,jは連結している for a, b in sides: graph[a - 1][b - 1] = True graph[b - 1][a - 1] = True # pprint.pprint(graph) for a, b in sides: # 辺の削除 graph[a - 1][b - 1] = False graph[b - 1][a - 1] = False for i in range(n): visited[i] = False dfs(0) # 探索実行後訪れていないノードが1つでもあれば # 削除した辺は橋である for i in range(n): if visited[i] == False: ans += 1 break # 辺を元に戻す graph[a - 1][b - 1] = True graph[b - 1][a - 1] = True print(ans)
from collections import Counter from functools import reduce # import statistics import bisect import copy import fractions import math import random import pprint import sys import time sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def MI(): return list(map(int, sys.stdin.readline().split())) def II(): return int(sys.stdin.readline()) def IS(): return eval(input()) def C(x): return Counter(x) def GCD_LIST(numbers): return reduce(fractions.gcd, numbers) def LCM_LIST(numbers): return reduce(LCM, numbers) def LCM(m, n): return m * n // fractions.gcd(m, n) def unite(x, y): # それぞれのノードの根を求める x = root(x) y = root(y) if x == y: return # node[x]の根をyに変更する node[x] = y def same(x, y): return bool(root(x) == root(y)) def root(x): if node[x] == x: # xが根の場合 return x else: node[x] = root(node[x]) # 経路圧縮 return node[x] def dfs(v): # ノードに訪れた visited[v] = True for v2 in range(n): if graph[v][v2] == False: # そもそもvとv2が辺でつながっていない continue if visited[v2] == True: # もう見た continue dfs(v2) # nは頂点の数 n, m = MI() ans = 0 sides = [LI() for _ in range(m)] # 隣接行列を用いてグラフの管理をする # graph = [[False] * n for _ in range(n)] # もしグラフ全体が連結ならばuf[i]=iとなる頂点がただ1つだけある # Union-Find for i in range(m): # 最初各ノードの根は自分自身 node = [k for k in range(n)] for j, side in enumerate(sides): # 連結しない if i == j: continue unite(side[0] - 1, side[1] - 1) # 根が自分自身であるものが2つ以上存在する場合、グラフは非連結である # 1である場合連結なのでのぞいた辺は橋「ではない」 if sum(node[num] == num for num in range(len(node))) != 1: ans += 1 print(ans)
false
10
[ "-visited = [False] * n", "-graph = [[False] * n for _ in range(n)]", "-# 初期化、graph[i-1][j-1] = 1ならば頂点i,jは連結している", "-for a, b in sides:", "- graph[a - 1][b - 1] = True", "- graph[b - 1][a - 1] = True", "-# pprint.pprint(graph)", "-for a, b in sides:", "- # 辺の削除", "- graph[a - 1][b - 1] = False", "- graph[b - 1][a - 1] = False", "- for i in range(n):", "- visited[i] = False", "- dfs(0)", "- # 探索実行後訪れていないノードが1つでもあれば", "- # 削除した辺は橋である", "- for i in range(n):", "- if visited[i] == False:", "- ans += 1", "- break", "- # 辺を元に戻す", "- graph[a - 1][b - 1] = True", "- graph[b - 1][a - 1] = True", "+# graph = [[False] * n for _ in range(n)]", "+# もしグラフ全体が連結ならばuf[i]=iとなる頂点がただ1つだけある", "+# Union-Find", "+for i in range(m):", "+ # 最初各ノードの根は自分自身", "+ node = [k for k in range(n)]", "+ for j, side in enumerate(sides):", "+ # 連結しない", "+ if i == j:", "+ continue", "+ unite(side[0] - 1, side[1] - 1)", "+ # 根が自分自身であるものが2つ以上存在する場合、グラフは非連結である", "+ # 1である場合連結なのでのぞいた辺は橋「ではない」", "+ if sum(node[num] == num for num in range(len(node))) != 1:", "+ ans += 1" ]
false
0.056497
0.047088
1.199823
[ "s125119170", "s617358894" ]
u152992875
p02950
python
s769810473
s119193196
864
768
175,004
174,748
Accepted
Accepted
11.11
p = eval(input()) a = list(map(int, input().strip().split())) b = [0] * p p2 = p * p s = [] for i in range(p): if a[i]: s.append(i) ncr = [[0 for i in range(p)] for j in range(p)] for i in range(p): ncr[i][0] = ncr[i][i] = 1 ncr[i][1] = i for n in range(2, p): for r in range(2, n): ncr[n][r] = ncr[n - 1][r] + ncr[n - 1][r - 1] if (ncr[n][r] >= p): ncr[n][r] -= p jpow = [[0 for i in range(p)] for j in range(p)] jpow[0][0] = 1 for i in range(1, p): val = 1 for j in range(p): jpow[i][j] = val val *= i if (val >= p2): val %= p for r in range(1, p): for j in s: x = ncr[p - 1][r] x *= jpow[j][p - 1 - r] if (x >= p2): x %= p if (p - r) & 1: b[r] -= x else: b[r] += x if b[r] >= p or b[r] < 0: b[r] %= p if a[0]: b[0] = 1 print(' '.join(map(str, b)))
p = eval(input()) a = list(map(int, input().strip().split())) b = [0] * p p2 = p * p s = [] for i in range(p): if a[i]: s.append(i) ncr = [[0 for i in range(p)] for j in range(p)] for i in range(p): ncr[i][0] = ncr[i][i] = 1 ncr[i][1] = i for n in range(2, p): for r in range(2, n): ncr[n][r] = ncr[n - 1][r] + ncr[n - 1][r - 1] if (ncr[n][r] >= p): ncr[n][r] -= p jpow = [[0 for i in range(p)] for j in range(p)] jpow[0][0] = 1 for i in range(1, p): val = 1 for j in range(p): jpow[i][j] = val val *= i if (val >= p): val %= p for r in range(1, p): for j in s: x = ncr[p - 1][r] x *= jpow[j][p - 1 - r] if (x >= p2): x %= p if (p - r) & 1: b[r] -= x else: b[r] += x if b[r] >= p or b[r] < 0: b[r] %= p if a[0]: b[0] = 1 print(' '.join(map(str, b)))
45
45
920
919
p = eval(input()) a = list(map(int, input().strip().split())) b = [0] * p p2 = p * p s = [] for i in range(p): if a[i]: s.append(i) ncr = [[0 for i in range(p)] for j in range(p)] for i in range(p): ncr[i][0] = ncr[i][i] = 1 ncr[i][1] = i for n in range(2, p): for r in range(2, n): ncr[n][r] = ncr[n - 1][r] + ncr[n - 1][r - 1] if ncr[n][r] >= p: ncr[n][r] -= p jpow = [[0 for i in range(p)] for j in range(p)] jpow[0][0] = 1 for i in range(1, p): val = 1 for j in range(p): jpow[i][j] = val val *= i if val >= p2: val %= p for r in range(1, p): for j in s: x = ncr[p - 1][r] x *= jpow[j][p - 1 - r] if x >= p2: x %= p if (p - r) & 1: b[r] -= x else: b[r] += x if b[r] >= p or b[r] < 0: b[r] %= p if a[0]: b[0] = 1 print(" ".join(map(str, b)))
p = eval(input()) a = list(map(int, input().strip().split())) b = [0] * p p2 = p * p s = [] for i in range(p): if a[i]: s.append(i) ncr = [[0 for i in range(p)] for j in range(p)] for i in range(p): ncr[i][0] = ncr[i][i] = 1 ncr[i][1] = i for n in range(2, p): for r in range(2, n): ncr[n][r] = ncr[n - 1][r] + ncr[n - 1][r - 1] if ncr[n][r] >= p: ncr[n][r] -= p jpow = [[0 for i in range(p)] for j in range(p)] jpow[0][0] = 1 for i in range(1, p): val = 1 for j in range(p): jpow[i][j] = val val *= i if val >= p: val %= p for r in range(1, p): for j in s: x = ncr[p - 1][r] x *= jpow[j][p - 1 - r] if x >= p2: x %= p if (p - r) & 1: b[r] -= x else: b[r] += x if b[r] >= p or b[r] < 0: b[r] %= p if a[0]: b[0] = 1 print(" ".join(map(str, b)))
false
0
[ "- if val >= p2:", "+ if val >= p:" ]
false
0.086503
0.035987
2.40374
[ "s769810473", "s119193196" ]
u723711163
p02813
python
s904701881
s538198428
273
120
54,236
82,156
Accepted
Accepted
56.04
N = int(eval(input())) p1 = tuple(map(int,input().split())) p2 = tuple(map(int,input().split())) def dfs(pair=[]): global lst if len(pair) == N: lst.append(tuple(pair)) else: for j in range(1,N+1): if j not in pair: pair.append(j) dfs(pair) pair.pop() lst = [] dfs() lst.sort() print((abs(lst.index(p1) - lst.index(p2))))
def LI(): return list(map(int, input().split())) N = int(eval(input())) P = LI() Q = LI() result = [] def permutations(N, cur): if len(cur) == N: result.append(cur) return for i in range(1, N+1): if i not in cur: permutations(N, cur+[i]) permutations(N,[]) result.sort() print((abs(result.index(P) - result.index(Q))))
18
20
375
357
N = int(eval(input())) p1 = tuple(map(int, input().split())) p2 = tuple(map(int, input().split())) def dfs(pair=[]): global lst if len(pair) == N: lst.append(tuple(pair)) else: for j in range(1, N + 1): if j not in pair: pair.append(j) dfs(pair) pair.pop() lst = [] dfs() lst.sort() print((abs(lst.index(p1) - lst.index(p2))))
def LI(): return list(map(int, input().split())) N = int(eval(input())) P = LI() Q = LI() result = [] def permutations(N, cur): if len(cur) == N: result.append(cur) return for i in range(1, N + 1): if i not in cur: permutations(N, cur + [i]) permutations(N, []) result.sort() print((abs(result.index(P) - result.index(Q))))
false
10
[ "-N = int(eval(input()))", "-p1 = tuple(map(int, input().split()))", "-p2 = tuple(map(int, input().split()))", "+def LI():", "+ return list(map(int, input().split()))", "-def dfs(pair=[]):", "- global lst", "- if len(pair) == N:", "- lst.append(tuple(pair))", "- else:", "- for j in range(1, N + 1):", "- if j not in pair:", "- pair.append(j)", "- dfs(pair)", "- pair.pop()", "+N = int(eval(input()))", "+P = LI()", "+Q = LI()", "+result = []", "-lst = []", "-dfs()", "-lst.sort()", "-print((abs(lst.index(p1) - lst.index(p2))))", "+def permutations(N, cur):", "+ if len(cur) == N:", "+ result.append(cur)", "+ return", "+ for i in range(1, N + 1):", "+ if i not in cur:", "+ permutations(N, cur + [i])", "+", "+", "+permutations(N, [])", "+result.sort()", "+print((abs(result.index(P) - result.index(Q))))" ]
false
0.043951
0.118813
0.36992
[ "s904701881", "s538198428" ]
u867848444
p02803
python
s599121091
s521677969
444
408
3,316
3,316
Accepted
Accepted
8.11
#BFS from collections import deque def bfs(i,j): q=deque() q.append((i,j)) log=[[-1]*w for i in range(h)] log[i][j]=0 dx=[0,1,0,-1] dy=[1,0,-1,0] long=0 while q: #qの先頭を取り出す p=q.popleft() for i in range(4): nx=p[0]+dx[i] ny=p[1]+dy[i] if not(0<=nx<h and 0<=ny<w):continue if maze[nx][ny]=='#':continue if log[nx][ny]!=-1:continue log[nx][ny]=log[p[0]][p[1]]+1 q.append((nx,ny)) if int<=log[nx][ny]:long=log[nx][ny] return int h,w=list(map(int,input().split())) maze=[list(eval(input())) for i in range(h)] ans=0 for i in range(h): for j in range(w): if maze[i][j]=='.': temp=bfs(i,j) if ans<temp:ans=temp print(ans)
#BFS from collections import deque def bfs(i, j): q=deque() q.append((i, j)) log = [[-1] * w for i in range(h)] log[i][j] = 0 distance = 0 d = [(1, 0), (0, 1), (-1, 0), (0, -1)] while q: #qの先頭を取り出す p=q.popleft() for x, y in d: nx = p[0] + x ny = p[1] + y if not(0 <= nx <h and 0 <= ny < w):continue if s[nx][ny] == "#":continue if log[nx][ny] >= 0:continue log[nx][ny] = log[p[0]][p[1]] + 1 q.append((nx, ny)) if distance < log[nx][ny]:distance = log[nx][ny] return distance h, w = list(map(int,input().split())) s = [list(eval(input())) for i in range(h)] distance = 0 for i in range(h): for j in range(w): if s[i][j] == "#":continue temp = bfs(i, j) if temp >= distance:distance = temp print(distance)
35
35
833
910
# BFS from collections import deque def bfs(i, j): q = deque() q.append((i, j)) log = [[-1] * w for i in range(h)] log[i][j] = 0 dx = [0, 1, 0, -1] dy = [1, 0, -1, 0] long = 0 while q: # qの先頭を取り出す p = q.popleft() for i in range(4): nx = p[0] + dx[i] ny = p[1] + dy[i] if not (0 <= nx < h and 0 <= ny < w): continue if maze[nx][ny] == "#": continue if log[nx][ny] != -1: continue log[nx][ny] = log[p[0]][p[1]] + 1 q.append((nx, ny)) if int <= log[nx][ny]: long = log[nx][ny] return int h, w = list(map(int, input().split())) maze = [list(eval(input())) for i in range(h)] ans = 0 for i in range(h): for j in range(w): if maze[i][j] == ".": temp = bfs(i, j) if ans < temp: ans = temp print(ans)
# BFS from collections import deque def bfs(i, j): q = deque() q.append((i, j)) log = [[-1] * w for i in range(h)] log[i][j] = 0 distance = 0 d = [(1, 0), (0, 1), (-1, 0), (0, -1)] while q: # qの先頭を取り出す p = q.popleft() for x, y in d: nx = p[0] + x ny = p[1] + y if not (0 <= nx < h and 0 <= ny < w): continue if s[nx][ny] == "#": continue if log[nx][ny] >= 0: continue log[nx][ny] = log[p[0]][p[1]] + 1 q.append((nx, ny)) if distance < log[nx][ny]: distance = log[nx][ny] return distance h, w = list(map(int, input().split())) s = [list(eval(input())) for i in range(h)] distance = 0 for i in range(h): for j in range(w): if s[i][j] == "#": continue temp = bfs(i, j) if temp >= distance: distance = temp print(distance)
false
0
[ "- dx = [0, 1, 0, -1]", "- dy = [1, 0, -1, 0]", "- long = 0", "+ distance = 0", "+ d = [(1, 0), (0, 1), (-1, 0), (0, -1)]", "- for i in range(4):", "- nx = p[0] + dx[i]", "- ny = p[1] + dy[i]", "+ for x, y in d:", "+ nx = p[0] + x", "+ ny = p[1] + y", "- if maze[nx][ny] == \"#\":", "+ if s[nx][ny] == \"#\":", "- if log[nx][ny] != -1:", "+ if log[nx][ny] >= 0:", "- if int <= log[nx][ny]:", "- long = log[nx][ny]", "- return int", "+ if distance < log[nx][ny]:", "+ distance = log[nx][ny]", "+ return distance", "-maze = [list(eval(input())) for i in range(h)]", "-ans = 0", "+s = [list(eval(input())) for i in range(h)]", "+distance = 0", "- if maze[i][j] == \".\":", "- temp = bfs(i, j)", "- if ans < temp:", "- ans = temp", "-print(ans)", "+ if s[i][j] == \"#\":", "+ continue", "+ temp = bfs(i, j)", "+ if temp >= distance:", "+ distance = temp", "+print(distance)" ]
false
0.099578
0.037703
2.641137
[ "s599121091", "s521677969" ]
u777299405
p02257
python
s587666356
s342514540
2,370
560
6,724
6,724
Accepted
Accepted
76.37
def isprime(n): i = 2 while i ** 2 <= n: if n % i == 0: return False i += 1 return True result = 0 for i in range(int(eval(input()))): result += isprime(int(eval(input()))) print(result)
def isprime(n): if n == 2: return True if n % 2 == 0: return False i = 3 while i * i <= n: if n % i == 0: return False i += 2 return True result = 0 for i in range(int(eval(input()))): result += isprime(int(eval(input()))) print(result)
12
16
230
308
def isprime(n): i = 2 while i**2 <= n: if n % i == 0: return False i += 1 return True result = 0 for i in range(int(eval(input()))): result += isprime(int(eval(input()))) print(result)
def isprime(n): if n == 2: return True if n % 2 == 0: return False i = 3 while i * i <= n: if n % i == 0: return False i += 2 return True result = 0 for i in range(int(eval(input()))): result += isprime(int(eval(input()))) print(result)
false
25
[ "- i = 2", "- while i**2 <= n:", "+ if n == 2:", "+ return True", "+ if n % 2 == 0:", "+ return False", "+ i = 3", "+ while i * i <= n:", "- i += 1", "+ i += 2" ]
false
0.036838
0.160795
0.229101
[ "s587666356", "s342514540" ]
u579699847
p03497
python
s568774558
s726621122
122
107
32,564
32,568
Accepted
Accepted
12.3
import collections,sys def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N,K = LI() A = collections.Counter(LI()) count_A = sorted([v for v in list(A.values())]) surplus = max(0,len(A)-K) print((sum(count_A[:surplus])))
import collections,sys def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N,K = LI() A = collections.Counter(LI()) value_A = sorted(A.values()) surplus = max(0,len(A)-K) print((sum(value_A[:surplus])))
7
7
238
225
import collections, sys def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) N, K = LI() A = collections.Counter(LI()) count_A = sorted([v for v in list(A.values())]) surplus = max(0, len(A) - K) print((sum(count_A[:surplus])))
import collections, sys def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) N, K = LI() A = collections.Counter(LI()) value_A = sorted(A.values()) surplus = max(0, len(A) - K) print((sum(value_A[:surplus])))
false
0
[ "-count_A = sorted([v for v in list(A.values())])", "+value_A = sorted(A.values())", "-print((sum(count_A[:surplus])))", "+print((sum(value_A[:surplus])))" ]
false
0.047177
0.046904
1.005822
[ "s568774558", "s726621122" ]
u670180528
p02728
python
s463168092
s768319782
2,765
2,327
80,736
93,780
Accepted
Accepted
15.84
import sys sys.setrecursionlimit(1234567890) n, *L = map(int, open(0).read().split()) mod = 10 ** 9 + 7 con = [[] for _ in range(n + 1)] sz = [1] * (n + 1) par = [0] * (n + 1) for s, t in zip(*[iter(L)] * 2): con[s] += t, con[t] += s, def prepare(m, mod=10 ** 9 + 7): fac = [1] * (m + 1) inv = [1] * (m + 1) for i in range(1, m + 1): fac[i] = fac[i - 1] * i % mod inv[-1] = pow(fac[-1], mod - 2, mod) for i in range(m - 1, -1, -1): inv[i] = inv[i + 1] * (i + 1) % mod return fac, inv fac, inv = prepare(n) def dfs1(cur, pre): par[cur] = pre for nxt in con[cur]: if nxt != pre: dfs1(nxt, cur) sz[cur] += sz[nxt] dp1[cur] *= dp1[nxt] * inv[sz[nxt]] % mod dp1[cur] %= mod dp1[cur] *= fac[sz[cur] - 1] dp1[cur] %= mod def dfs2(cur, pre): dp2[cur] *= dp1[cur] * inv[sz[cur] - 1] % mod dp2[cur] %= mod dp2[cur] *= fac[n - 1] dp2[cur] %= mod for nxt in con[cur]: if nxt != pre: dp2[nxt] = fac[sz[nxt]] * pow(n - sz[nxt], mod - 2, mod) * pow(dp1[nxt], mod - 2, mod) * dp2[cur] * inv[n - 1] % mod dfs2(nxt, cur) dp1 = [1] * (n + 1) dfs1(1, 0) dp2 = [1] * (n + 1) dfs2(1, 0) print(*dp2[1:], sep="\n")
import sys sys.setrecursionlimit(1234567890) from collections import deque n, *L = list(map(int, open(0).read().split())) mod = 10 ** 9 + 7 def prepare(m, mod=10 ** 9 + 7): fac = [1] * (m + 1) inv = [1] * (m + 1) for i in range(1, m + 1): fac[i] = fac[i - 1] * i % mod inv[-1] = pow(fac[-1], mod - 2, mod) for i in range(m - 1, -1, -1): inv[i] = inv[i + 1] * (i + 1) % mod return fac, inv fac, inv = prepare(n) con = [[] for _ in range(n)] for s, t in zip(*[iter(L)] * 2): con[s - 1] += t - 1, con[t - 1] += s - 1, par = [-1] * n q = deque([0]) odr = [] while q: cur = q.popleft() odr += cur, for nxt in con[cur]: if nxt != par[cur]: par[nxt] = cur q.append(nxt) sz = [1] * (n + 1) st = 1 for i in odr[::-1]: sz[par[i]] += sz[i] st *= pow(sz[i], mod - 2, mod) st %= mod # inv[n-1]*fac[sz[i]]*inv[sz[i]-1]*inv[n-sz[i]]*fac[n-sz[i]-1]*fac[n-1]=sz[i]*(n-sz[i])^-1 ans = [st * fac[n] % mod] + [0] * (n - 1) for i in odr[1:]: ans[i] = ans[par[i]] * sz[i] % mod * pow(n - sz[i], mod - 2, mod) % mod print((*ans))
57
49
1,203
1,083
import sys sys.setrecursionlimit(1234567890) n, *L = map(int, open(0).read().split()) mod = 10**9 + 7 con = [[] for _ in range(n + 1)] sz = [1] * (n + 1) par = [0] * (n + 1) for s, t in zip(*[iter(L)] * 2): con[s] += (t,) con[t] += (s,) def prepare(m, mod=10**9 + 7): fac = [1] * (m + 1) inv = [1] * (m + 1) for i in range(1, m + 1): fac[i] = fac[i - 1] * i % mod inv[-1] = pow(fac[-1], mod - 2, mod) for i in range(m - 1, -1, -1): inv[i] = inv[i + 1] * (i + 1) % mod return fac, inv fac, inv = prepare(n) def dfs1(cur, pre): par[cur] = pre for nxt in con[cur]: if nxt != pre: dfs1(nxt, cur) sz[cur] += sz[nxt] dp1[cur] *= dp1[nxt] * inv[sz[nxt]] % mod dp1[cur] %= mod dp1[cur] *= fac[sz[cur] - 1] dp1[cur] %= mod def dfs2(cur, pre): dp2[cur] *= dp1[cur] * inv[sz[cur] - 1] % mod dp2[cur] %= mod dp2[cur] *= fac[n - 1] dp2[cur] %= mod for nxt in con[cur]: if nxt != pre: dp2[nxt] = ( fac[sz[nxt]] * pow(n - sz[nxt], mod - 2, mod) * pow(dp1[nxt], mod - 2, mod) * dp2[cur] * inv[n - 1] % mod ) dfs2(nxt, cur) dp1 = [1] * (n + 1) dfs1(1, 0) dp2 = [1] * (n + 1) dfs2(1, 0) print(*dp2[1:], sep="\n")
import sys sys.setrecursionlimit(1234567890) from collections import deque n, *L = list(map(int, open(0).read().split())) mod = 10**9 + 7 def prepare(m, mod=10**9 + 7): fac = [1] * (m + 1) inv = [1] * (m + 1) for i in range(1, m + 1): fac[i] = fac[i - 1] * i % mod inv[-1] = pow(fac[-1], mod - 2, mod) for i in range(m - 1, -1, -1): inv[i] = inv[i + 1] * (i + 1) % mod return fac, inv fac, inv = prepare(n) con = [[] for _ in range(n)] for s, t in zip(*[iter(L)] * 2): con[s - 1] += (t - 1,) con[t - 1] += (s - 1,) par = [-1] * n q = deque([0]) odr = [] while q: cur = q.popleft() odr += (cur,) for nxt in con[cur]: if nxt != par[cur]: par[nxt] = cur q.append(nxt) sz = [1] * (n + 1) st = 1 for i in odr[::-1]: sz[par[i]] += sz[i] st *= pow(sz[i], mod - 2, mod) st %= mod # inv[n-1]*fac[sz[i]]*inv[sz[i]-1]*inv[n-sz[i]]*fac[n-sz[i]-1]*fac[n-1]=sz[i]*(n-sz[i])^-1 ans = [st * fac[n] % mod] + [0] * (n - 1) for i in odr[1:]: ans[i] = ans[par[i]] * sz[i] % mod * pow(n - sz[i], mod - 2, mod) % mod print((*ans))
false
14.035088
[ "-n, *L = map(int, open(0).read().split())", "+from collections import deque", "+", "+n, *L = list(map(int, open(0).read().split()))", "-con = [[] for _ in range(n + 1)]", "-sz = [1] * (n + 1)", "-par = [0] * (n + 1)", "-for s, t in zip(*[iter(L)] * 2):", "- con[s] += (t,)", "- con[t] += (s,)", "-", "-", "-def dfs1(cur, pre):", "- par[cur] = pre", "+con = [[] for _ in range(n)]", "+for s, t in zip(*[iter(L)] * 2):", "+ con[s - 1] += (t - 1,)", "+ con[t - 1] += (s - 1,)", "+par = [-1] * n", "+q = deque([0])", "+odr = []", "+while q:", "+ cur = q.popleft()", "+ odr += (cur,)", "- if nxt != pre:", "- dfs1(nxt, cur)", "- sz[cur] += sz[nxt]", "- dp1[cur] *= dp1[nxt] * inv[sz[nxt]] % mod", "- dp1[cur] %= mod", "- dp1[cur] *= fac[sz[cur] - 1]", "- dp1[cur] %= mod", "-", "-", "-def dfs2(cur, pre):", "- dp2[cur] *= dp1[cur] * inv[sz[cur] - 1] % mod", "- dp2[cur] %= mod", "- dp2[cur] *= fac[n - 1]", "- dp2[cur] %= mod", "- for nxt in con[cur]:", "- if nxt != pre:", "- dp2[nxt] = (", "- fac[sz[nxt]]", "- * pow(n - sz[nxt], mod - 2, mod)", "- * pow(dp1[nxt], mod - 2, mod)", "- * dp2[cur]", "- * inv[n - 1]", "- % mod", "- )", "- dfs2(nxt, cur)", "-", "-", "-dp1 = [1] * (n + 1)", "-dfs1(1, 0)", "-dp2 = [1] * (n + 1)", "-dfs2(1, 0)", "-print(*dp2[1:], sep=\"\\n\")", "+ if nxt != par[cur]:", "+ par[nxt] = cur", "+ q.append(nxt)", "+sz = [1] * (n + 1)", "+st = 1", "+for i in odr[::-1]:", "+ sz[par[i]] += sz[i]", "+ st *= pow(sz[i], mod - 2, mod)", "+ st %= mod", "+# inv[n-1]*fac[sz[i]]*inv[sz[i]-1]*inv[n-sz[i]]*fac[n-sz[i]-1]*fac[n-1]=sz[i]*(n-sz[i])^-1", "+ans = [st * fac[n] % mod] + [0] * (n - 1)", "+for i in odr[1:]:", "+ ans[i] = ans[par[i]] * sz[i] % mod * pow(n - sz[i], mod - 2, mod) % mod", "+print((*ans))" ]
false
0.098855
0.045843
2.15637
[ "s463168092", "s768319782" ]
u113835532
p02772
python
s156706982
s812053696
30
27
9,172
9,148
Accepted
Accepted
10
N = int(eval(input())) ints = list(map(int, input().split())) for i in ints: if i % 2 == 0: if i % 3 != 0 and i % 5 != 0: print('DENIED') exit() print('APPROVED')
N = eval(input()) ints = (i for i in map(int, input().split()) if i % 2 == 0) ints = (i % 3 == 0 or i % 5 == 0 for i in ints) print(('APPROVED' if all(ints) else 'DENIED'))
10
4
197
167
N = int(eval(input())) ints = list(map(int, input().split())) for i in ints: if i % 2 == 0: if i % 3 != 0 and i % 5 != 0: print("DENIED") exit() print("APPROVED")
N = eval(input()) ints = (i for i in map(int, input().split()) if i % 2 == 0) ints = (i % 3 == 0 or i % 5 == 0 for i in ints) print(("APPROVED" if all(ints) else "DENIED"))
false
60
[ "-N = int(eval(input()))", "-ints = list(map(int, input().split()))", "-for i in ints:", "- if i % 2 == 0:", "- if i % 3 != 0 and i % 5 != 0:", "- print(\"DENIED\")", "- exit()", "-print(\"APPROVED\")", "+N = eval(input())", "+ints = (i for i in map(int, input().split()) if i % 2 == 0)", "+ints = (i % 3 == 0 or i % 5 == 0 for i in ints)", "+print((\"APPROVED\" if all(ints) else \"DENIED\"))" ]
false
0.044464
0.044936
0.989498
[ "s156706982", "s812053696" ]
u835283937
p03945
python
s822822613
s240749887
50
40
9,628
9,668
Accepted
Accepted
20
def main(): S = list(eval(input())) r = 0 for i in range(len(S) - 1): if S[i] != S[i + 1]: r += 1 S.reverse() l = 0 for i in range(len(S) - 1): if S[i] != S[i + 1]: l += 1 print((min(r, l))) if __name__ == "__main__": main()
def main(): S = list(eval(input())) ans = 0 for i in range(len(S) - 1): if S[i] != S[i + 1]: ans += 1 print(ans) if __name__ == "__main__": main()
18
11
317
192
def main(): S = list(eval(input())) r = 0 for i in range(len(S) - 1): if S[i] != S[i + 1]: r += 1 S.reverse() l = 0 for i in range(len(S) - 1): if S[i] != S[i + 1]: l += 1 print((min(r, l))) if __name__ == "__main__": main()
def main(): S = list(eval(input())) ans = 0 for i in range(len(S) - 1): if S[i] != S[i + 1]: ans += 1 print(ans) if __name__ == "__main__": main()
false
38.888889
[ "- r = 0", "+ ans = 0", "- r += 1", "- S.reverse()", "- l = 0", "- for i in range(len(S) - 1):", "- if S[i] != S[i + 1]:", "- l += 1", "- print((min(r, l)))", "+ ans += 1", "+ print(ans)" ]
false
0.046844
0.04776
0.980822
[ "s822822613", "s240749887" ]
u934442292
p03013
python
s433099026
s515589820
315
62
7,028
13,780
Accepted
Accepted
80.32
MOD = 10**9 + 7 N, M = [int(i) for i in input().strip().split()] dirty_step_idxs = [0] * M for i in range(M): dirty_step_idx = int(eval(input())) dirty_step_idxs[i] = dirty_step_idx def fibonacci(n): # 0, 1, 1, 2, 3, 5, 8, ... a, b = 0, 1 for i in range(n-1): a, b = b, a + b return a if M == 0: res = fibonacci(N + 2) else: res = 1 now_step_idx = 0 for i in range(M): n_step = dirty_step_idxs[i] - now_step_idx - 1 if n_step == -1: res = 0 break res *= fibonacci(n_step + 2) now_step_idx = dirty_step_idxs[i] + 1 rest_steps = N - now_step_idx res *= fibonacci(rest_steps + 2) print((res % MOD))
import sys input = sys.stdin.readline P = 10 ** 9 + 7 def main(): N, M = list(map(int, input().split())) A = [0] * M for i in range(M): A[i] = int(eval(input())) for i in range(M - 1): if A[i] + 1 == A[i + 1]: print((0)) exit() broken = [False] * (N + 1) for a in A: broken[a] = True dp = [0] * (N + 1) dp[0] = 1 dp[1] = 1 if not broken[1] else 0 for i in range(2, N + 1): if broken[i]: dp[i] = 0 else: dp[i] = (dp[i - 1] + dp[i - 2]) % P ans = dp[N] print(ans) if __name__ == "__main__": main()
31
38
685
674
MOD = 10**9 + 7 N, M = [int(i) for i in input().strip().split()] dirty_step_idxs = [0] * M for i in range(M): dirty_step_idx = int(eval(input())) dirty_step_idxs[i] = dirty_step_idx def fibonacci(n): # 0, 1, 1, 2, 3, 5, 8, ... a, b = 0, 1 for i in range(n - 1): a, b = b, a + b return a if M == 0: res = fibonacci(N + 2) else: res = 1 now_step_idx = 0 for i in range(M): n_step = dirty_step_idxs[i] - now_step_idx - 1 if n_step == -1: res = 0 break res *= fibonacci(n_step + 2) now_step_idx = dirty_step_idxs[i] + 1 rest_steps = N - now_step_idx res *= fibonacci(rest_steps + 2) print((res % MOD))
import sys input = sys.stdin.readline P = 10**9 + 7 def main(): N, M = list(map(int, input().split())) A = [0] * M for i in range(M): A[i] = int(eval(input())) for i in range(M - 1): if A[i] + 1 == A[i + 1]: print((0)) exit() broken = [False] * (N + 1) for a in A: broken[a] = True dp = [0] * (N + 1) dp[0] = 1 dp[1] = 1 if not broken[1] else 0 for i in range(2, N + 1): if broken[i]: dp[i] = 0 else: dp[i] = (dp[i - 1] + dp[i - 2]) % P ans = dp[N] print(ans) if __name__ == "__main__": main()
false
18.421053
[ "-MOD = 10**9 + 7", "-N, M = [int(i) for i in input().strip().split()]", "-dirty_step_idxs = [0] * M", "-for i in range(M):", "- dirty_step_idx = int(eval(input()))", "- dirty_step_idxs[i] = dirty_step_idx", "+import sys", "+", "+input = sys.stdin.readline", "+P = 10**9 + 7", "-def fibonacci(n):", "- # 0, 1, 1, 2, 3, 5, 8, ...", "- a, b = 0, 1", "- for i in range(n - 1):", "- a, b = b, a + b", "- return a", "+def main():", "+ N, M = list(map(int, input().split()))", "+ A = [0] * M", "+ for i in range(M):", "+ A[i] = int(eval(input()))", "+ for i in range(M - 1):", "+ if A[i] + 1 == A[i + 1]:", "+ print((0))", "+ exit()", "+ broken = [False] * (N + 1)", "+ for a in A:", "+ broken[a] = True", "+ dp = [0] * (N + 1)", "+ dp[0] = 1", "+ dp[1] = 1 if not broken[1] else 0", "+ for i in range(2, N + 1):", "+ if broken[i]:", "+ dp[i] = 0", "+ else:", "+ dp[i] = (dp[i - 1] + dp[i - 2]) % P", "+ ans = dp[N]", "+ print(ans)", "-if M == 0:", "- res = fibonacci(N + 2)", "-else:", "- res = 1", "- now_step_idx = 0", "- for i in range(M):", "- n_step = dirty_step_idxs[i] - now_step_idx - 1", "- if n_step == -1:", "- res = 0", "- break", "- res *= fibonacci(n_step + 2)", "- now_step_idx = dirty_step_idxs[i] + 1", "- rest_steps = N - now_step_idx", "- res *= fibonacci(rest_steps + 2)", "-print((res % MOD))", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.034946
0.035923
0.972803
[ "s433099026", "s515589820" ]
u088552457
p03681
python
s814876548
s117657979
371
282
47,580
86,676
Accepted
Accepted
23.99
import math a, b = list(map(int, input().split())) fa = math.factorial(a) fb = math.factorial(b) mod = 10**9 + 7 fa %= mod fb %= mod k = fa*fb if abs(a-b) >= 2: print((0)) elif abs(a-b) == 1: print((k%mod)) elif abs(a-b) == 0: print(((2*k) % mod))
import sys input = sys.stdin.readline import math def main(): n, m = input_list() if abs(n-m) > 1: print((0)) exit() mod = 10**9 + 7 diff = abs(n-m) if diff == 1: ans = math.factorial(n) * math.factorial(m) print((ans % mod)) else: ans = 2 * (math.factorial(n) * math.factorial(m)) print((ans % mod)) def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def permutations_count(n, r): return math.factorial(n) // math.factorial(n - r) def input_list(): return list(map(int, input().split())) def input_list_str(): return list(map(str, input().split())) if __name__ == "__main__": main()
16
35
258
764
import math a, b = list(map(int, input().split())) fa = math.factorial(a) fb = math.factorial(b) mod = 10**9 + 7 fa %= mod fb %= mod k = fa * fb if abs(a - b) >= 2: print((0)) elif abs(a - b) == 1: print((k % mod)) elif abs(a - b) == 0: print(((2 * k) % mod))
import sys input = sys.stdin.readline import math def main(): n, m = input_list() if abs(n - m) > 1: print((0)) exit() mod = 10**9 + 7 diff = abs(n - m) if diff == 1: ans = math.factorial(n) * math.factorial(m) print((ans % mod)) else: ans = 2 * (math.factorial(n) * math.factorial(m)) print((ans % mod)) def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def permutations_count(n, r): return math.factorial(n) // math.factorial(n - r) def input_list(): return list(map(int, input().split())) def input_list_str(): return list(map(str, input().split())) if __name__ == "__main__": main()
false
54.285714
[ "+import sys", "+", "+input = sys.stdin.readline", "-a, b = list(map(int, input().split()))", "-fa = math.factorial(a)", "-fb = math.factorial(b)", "-mod = 10**9 + 7", "-fa %= mod", "-fb %= mod", "-k = fa * fb", "-if abs(a - b) >= 2:", "- print((0))", "-elif abs(a - b) == 1:", "- print((k % mod))", "-elif abs(a - b) == 0:", "- print(((2 * k) % mod))", "+", "+def main():", "+ n, m = input_list()", "+ if abs(n - m) > 1:", "+ print((0))", "+ exit()", "+ mod = 10**9 + 7", "+ diff = abs(n - m)", "+ if diff == 1:", "+ ans = math.factorial(n) * math.factorial(m)", "+ print((ans % mod))", "+ else:", "+ ans = 2 * (math.factorial(n) * math.factorial(m))", "+ print((ans % mod))", "+", "+", "+def combinations_count(n, r):", "+ return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))", "+", "+", "+def permutations_count(n, r):", "+ return math.factorial(n) // math.factorial(n - r)", "+", "+", "+def input_list():", "+ return list(map(int, input().split()))", "+", "+", "+def input_list_str():", "+ return list(map(str, input().split()))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.045958
0.052084
0.882373
[ "s814876548", "s117657979" ]
u967268722
p02413
python
s723863892
s762435373
30
20
6,228
5,688
Accepted
Accepted
33.33
m,n=map(int,input().split()) a =[] for _ in range(m): a.append(list(map(int,input().split()))) for index in range(m): a[index].append(sum(a[index])) for a_column in a: for num in a_column[:-1]: print(num, end=' ') print(a_column[-1]) for row_index in range(n): sum = 0 for a_column in a: sum += a_column[row_index] print(sum, end=' ') sum = 0 for a_column in a: sum += a_column[-1] print(sum)
m,n=list(map(int,input().split())) a =[] for _ in range(m): a.append(list(map(int,input().split()))) for index in range(m): a[index].append(sum(a[index])) for a_column in a: print((' '.join(map(str, a_column)))) a.append([0]*(n+1)) for row_index in range(n+1): for a_column in a[:-1]: a[-1][row_index] += a_column[row_index] print((' '.join(map(str, a[-1]))))
20
14
461
388
m, n = map(int, input().split()) a = [] for _ in range(m): a.append(list(map(int, input().split()))) for index in range(m): a[index].append(sum(a[index])) for a_column in a: for num in a_column[:-1]: print(num, end=" ") print(a_column[-1]) for row_index in range(n): sum = 0 for a_column in a: sum += a_column[row_index] print(sum, end=" ") sum = 0 for a_column in a: sum += a_column[-1] print(sum)
m, n = list(map(int, input().split())) a = [] for _ in range(m): a.append(list(map(int, input().split()))) for index in range(m): a[index].append(sum(a[index])) for a_column in a: print((" ".join(map(str, a_column)))) a.append([0] * (n + 1)) for row_index in range(n + 1): for a_column in a[:-1]: a[-1][row_index] += a_column[row_index] print((" ".join(map(str, a[-1]))))
false
30
[ "-m, n = map(int, input().split())", "+m, n = list(map(int, input().split()))", "- for num in a_column[:-1]:", "- print(num, end=\" \")", "- print(a_column[-1])", "-for row_index in range(n):", "- sum = 0", "- for a_column in a:", "- sum += a_column[row_index]", "- print(sum, end=\" \")", "-sum = 0", "-for a_column in a:", "- sum += a_column[-1]", "-print(sum)", "+ print((\" \".join(map(str, a_column))))", "+a.append([0] * (n + 1))", "+for row_index in range(n + 1):", "+ for a_column in a[:-1]:", "+ a[-1][row_index] += a_column[row_index]", "+print((\" \".join(map(str, a[-1]))))" ]
false
0.124793
0.038061
3.278773
[ "s723863892", "s762435373" ]
u285891772
p03240
python
s848174420
s027746665
680
550
5,204
5,316
Accepted
Accepted
19.12
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce 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(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 #from decimal import * N = INT() xyh = [LIST() for _ in range(N)] h_dict = defaultdict(int) xyh.sort(key = lambda x:[x[0], x[1]]) for Cx in range(101): for Cy in range(101): H = 0 H_max = INF for x, y, h in xyh: if h == 0: H_max = min(H_max, h + abs(x-Cx) + abs(y-Cy)) else: if H == 0: H = h + abs(x-Cx) + abs(y-Cy) else: if H != h + abs(x-Cx) + abs(y-Cy): break else: if H <= H_max: print((Cx, Cy, H)) break else: continue break
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce 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(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 #from decimal import * N = INT() xyh = [LIST() for _ in range(N)] xyh.sort(key = lambda x:[x[0], x[1]]) for Cx in range(101): for Cy in range(101): H = 0 H_max = INF for x, y, h in xyh: if h == 0: H_max = min(H_max, h + abs(x-Cx) + abs(y-Cy)) else: if H == 0: H = h + abs(x-Cx) + abs(y-Cy) else: if H != h + abs(x-Cx) + abs(y-Cy): break else: if H <= H_max: print((Cx, Cy, H)) break else: continue break
49
46
1,389
1,358
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, ) from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce 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(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 # from decimal import * N = INT() xyh = [LIST() for _ in range(N)] h_dict = defaultdict(int) xyh.sort(key=lambda x: [x[0], x[1]]) for Cx in range(101): for Cy in range(101): H = 0 H_max = INF for x, y, h in xyh: if h == 0: H_max = min(H_max, h + abs(x - Cx) + abs(y - Cy)) else: if H == 0: H = h + abs(x - Cx) + abs(y - Cy) else: if H != h + abs(x - Cx) + abs(y - Cy): break else: if H <= H_max: print((Cx, Cy, H)) break else: continue break
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, ) from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce 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(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 # from decimal import * N = INT() xyh = [LIST() for _ in range(N)] xyh.sort(key=lambda x: [x[0], x[1]]) for Cx in range(101): for Cy in range(101): H = 0 H_max = INF for x, y, h in xyh: if h == 0: H_max = min(H_max, h + abs(x - Cx) + abs(y - Cy)) else: if H == 0: H = h + abs(x - Cx) + abs(y - Cy) else: if H != h + abs(x - Cx) + abs(y - Cy): break else: if H <= H_max: print((Cx, Cy, H)) break else: continue break
false
6.122449
[ "-h_dict = defaultdict(int)" ]
false
0.108519
0.083927
1.293013
[ "s848174420", "s027746665" ]
u144913062
p03677
python
s570521433
s418212717
165
96
82,204
91,776
Accepted
Accepted
41.82
import sys input = sys.stdin.readline class BIT: def __init__(self, size): self.bit = [0] * (size + 1) self.size = size def sum(self, i): i += 1 s = 0 while i > 0: s += self.bit[i] i -= i & -i return s def add(self, i, x): i += 1 while i <= self.size: self.bit[i] += x i += i & -i n, m = list(map(int, input().split())) a = list([int(x) - 1 for x in input().split()]) bit0 = BIT(m) bit1 = BIT(m) for i in range(n-1): x, y = a[i], a[i+1] bit1.add(0, (y - x) % m) if (y - x) % m < 2: continue x = (x + 2) % m if x <= y: bit0.add(x, -1) bit1.add(x, x - 1) bit0.add(y + 1, 1) bit1.add(y + 1, -(x - 1)) else: bit0.add(x, -1) bit1.add(x, x - 1) b = (0 - (x - 1)) % m bit0.add(0, -1) bit1.add(0, -b) bit0.add(y + 1, 1) bit1.add(y + 1, b) ans = min(bit0.sum(i) * i + bit1.sum(i) for i in range(m)) print(ans)
from itertools import accumulate import sys input = sys.stdin.readline n, m = list(map(int, input().split())) a = list([int(x) - 1 for x in input().split()]) cnt0 = [0] * m cnt1 = [0] * m for i in range(n-1): cnt0[a[i+1]] += (a[i+1] - a[i]) % m - 1 if (a[i] + 1) % m <= a[i+1]: cnt1[(a[i]+1) % m] += 1 cnt1[a[i+1]] -= 1 else: cnt1[(a[i]+1) % m] += 1 cnt1[0] += 1 cnt1[a[i+1]] -= 1 cnt1 = list(accumulate(cnt1)) ans = float('inf') tmp = 0 for i in range(n-1): tmp += min((a[i+1] - a[i]) % m, a[i+1] + 1) ans = tmp for i in range(m-1): tmp += cnt0[i] - cnt1[i] ans = min(ans, tmp) print(ans)
50
29
1,100
684
import sys input = sys.stdin.readline class BIT: def __init__(self, size): self.bit = [0] * (size + 1) self.size = size def sum(self, i): i += 1 s = 0 while i > 0: s += self.bit[i] i -= i & -i return s def add(self, i, x): i += 1 while i <= self.size: self.bit[i] += x i += i & -i n, m = list(map(int, input().split())) a = list([int(x) - 1 for x in input().split()]) bit0 = BIT(m) bit1 = BIT(m) for i in range(n - 1): x, y = a[i], a[i + 1] bit1.add(0, (y - x) % m) if (y - x) % m < 2: continue x = (x + 2) % m if x <= y: bit0.add(x, -1) bit1.add(x, x - 1) bit0.add(y + 1, 1) bit1.add(y + 1, -(x - 1)) else: bit0.add(x, -1) bit1.add(x, x - 1) b = (0 - (x - 1)) % m bit0.add(0, -1) bit1.add(0, -b) bit0.add(y + 1, 1) bit1.add(y + 1, b) ans = min(bit0.sum(i) * i + bit1.sum(i) for i in range(m)) print(ans)
from itertools import accumulate import sys input = sys.stdin.readline n, m = list(map(int, input().split())) a = list([int(x) - 1 for x in input().split()]) cnt0 = [0] * m cnt1 = [0] * m for i in range(n - 1): cnt0[a[i + 1]] += (a[i + 1] - a[i]) % m - 1 if (a[i] + 1) % m <= a[i + 1]: cnt1[(a[i] + 1) % m] += 1 cnt1[a[i + 1]] -= 1 else: cnt1[(a[i] + 1) % m] += 1 cnt1[0] += 1 cnt1[a[i + 1]] -= 1 cnt1 = list(accumulate(cnt1)) ans = float("inf") tmp = 0 for i in range(n - 1): tmp += min((a[i + 1] - a[i]) % m, a[i + 1] + 1) ans = tmp for i in range(m - 1): tmp += cnt0[i] - cnt1[i] ans = min(ans, tmp) print(ans)
false
42
[ "+from itertools import accumulate", "-", "-", "-class BIT:", "- def __init__(self, size):", "- self.bit = [0] * (size + 1)", "- self.size = size", "-", "- def sum(self, i):", "- i += 1", "- s = 0", "- while i > 0:", "- s += self.bit[i]", "- i -= i & -i", "- return s", "-", "- def add(self, i, x):", "- i += 1", "- while i <= self.size:", "- self.bit[i] += x", "- i += i & -i", "-", "-", "-bit0 = BIT(m)", "-bit1 = BIT(m)", "+cnt0 = [0] * m", "+cnt1 = [0] * m", "- x, y = a[i], a[i + 1]", "- bit1.add(0, (y - x) % m)", "- if (y - x) % m < 2:", "- continue", "- x = (x + 2) % m", "- if x <= y:", "- bit0.add(x, -1)", "- bit1.add(x, x - 1)", "- bit0.add(y + 1, 1)", "- bit1.add(y + 1, -(x - 1))", "+ cnt0[a[i + 1]] += (a[i + 1] - a[i]) % m - 1", "+ if (a[i] + 1) % m <= a[i + 1]:", "+ cnt1[(a[i] + 1) % m] += 1", "+ cnt1[a[i + 1]] -= 1", "- bit0.add(x, -1)", "- bit1.add(x, x - 1)", "- b = (0 - (x - 1)) % m", "- bit0.add(0, -1)", "- bit1.add(0, -b)", "- bit0.add(y + 1, 1)", "- bit1.add(y + 1, b)", "-ans = min(bit0.sum(i) * i + bit1.sum(i) for i in range(m))", "+ cnt1[(a[i] + 1) % m] += 1", "+ cnt1[0] += 1", "+ cnt1[a[i + 1]] -= 1", "+cnt1 = list(accumulate(cnt1))", "+ans = float(\"inf\")", "+tmp = 0", "+for i in range(n - 1):", "+ tmp += min((a[i + 1] - a[i]) % m, a[i + 1] + 1)", "+ans = tmp", "+for i in range(m - 1):", "+ tmp += cnt0[i] - cnt1[i]", "+ ans = min(ans, tmp)" ]
false
0.084282
0.044372
1.89942
[ "s570521433", "s418212717" ]
u629540524
p03644
python
s911868218
s989606918
20
17
2,940
2,940
Accepted
Accepted
15
n = int(eval(input())) count = 0 while 2**count <= n: count += 1 print((2**(count-1)))
n = int(eval(input())) count = 0 while 2**count <= n: x = 2**count count += 1 print(x)
5
6
86
93
n = int(eval(input())) count = 0 while 2**count <= n: count += 1 print((2 ** (count - 1)))
n = int(eval(input())) count = 0 while 2**count <= n: x = 2**count count += 1 print(x)
false
16.666667
[ "+ x = 2**count", "-print((2 ** (count - 1)))", "+print(x)" ]
false
0.045395
0.04968
0.913751
[ "s911868218", "s989606918" ]
u957470671
p02316
python
s439230348
s948410095
960
540
15,692
5,724
Accepted
Accepted
43.75
# Knapsack Problem N, W = [int(x) for x in input().split()] items = [] for i in range(N): items.append(tuple(int(x) for x in input().split())) DP = [[0] * (W+1) for _ in range(N+1)] for i in range(N): for j in range(W+1): v, w = items[i] if w <= j: DP[i+1][j] = max(DP[i][j], v + DP[i+1][j-w]) else: DP[i+1][j] = DP[i][j] print((DP[-1][-1]))
# Knapsack Problem N, W = [int(x) for x in input().split()] items = [] for i in range(N): items.append(tuple(int(x) for x in input().split())) DP = [0] * (W+1) for i in range(N): v, w = items[i] for j in range(w, W+1): DP[j] = max(DP[j], v + DP[j-w]) print((DP[-1]))
17
14
414
300
# Knapsack Problem N, W = [int(x) for x in input().split()] items = [] for i in range(N): items.append(tuple(int(x) for x in input().split())) DP = [[0] * (W + 1) for _ in range(N + 1)] for i in range(N): for j in range(W + 1): v, w = items[i] if w <= j: DP[i + 1][j] = max(DP[i][j], v + DP[i + 1][j - w]) else: DP[i + 1][j] = DP[i][j] print((DP[-1][-1]))
# Knapsack Problem N, W = [int(x) for x in input().split()] items = [] for i in range(N): items.append(tuple(int(x) for x in input().split())) DP = [0] * (W + 1) for i in range(N): v, w = items[i] for j in range(w, W + 1): DP[j] = max(DP[j], v + DP[j - w]) print((DP[-1]))
false
17.647059
[ "-DP = [[0] * (W + 1) for _ in range(N + 1)]", "+DP = [0] * (W + 1)", "- for j in range(W + 1):", "- v, w = items[i]", "- if w <= j:", "- DP[i + 1][j] = max(DP[i][j], v + DP[i + 1][j - w])", "- else:", "- DP[i + 1][j] = DP[i][j]", "-print((DP[-1][-1]))", "+ v, w = items[i]", "+ for j in range(w, W + 1):", "+ DP[j] = max(DP[j], v + DP[j - w])", "+print((DP[-1]))" ]
false
0.039886
0.038715
1.030262
[ "s439230348", "s948410095" ]
u757117214
p03105
python
s243778133
s800974480
19
17
2,940
2,940
Accepted
Accepted
10.53
A,B,C=list(map(int,input().split())) s=B//A print((s if s<C else C))
a,b,c = list(map(int,input().split())) print((min(c, b//a)))
3
2
62
53
A, B, C = list(map(int, input().split())) s = B // A print((s if s < C else C))
a, b, c = list(map(int, input().split())) print((min(c, b // a)))
false
33.333333
[ "-A, B, C = list(map(int, input().split()))", "-s = B // A", "-print((s if s < C else C))", "+a, b, c = list(map(int, input().split()))", "+print((min(c, b // a)))" ]
false
0.050359
0.04998
1.00758
[ "s243778133", "s800974480" ]
u278356323
p03610
python
s661018831
s870283413
72
28
4,596
3,188
Accepted
Accepted
61.11
# ABC073b import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) s = input() for i in range(0, len(s), 2): print(s[i], end='')
# ABC073b import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) s = eval(input()) ans = '' for i in range(0, len(s), 2): ans += s[i] print(ans)
9
11
152
166
# ABC073b import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) s = input() for i in range(0, len(s), 2): print(s[i], end="")
# ABC073b import sys input = sys.stdin.readline sys.setrecursionlimit(10**6) s = eval(input()) ans = "" for i in range(0, len(s), 2): ans += s[i] print(ans)
false
18.181818
[ "-s = input()", "+s = eval(input())", "+ans = \"\"", "- print(s[i], end=\"\")", "+ ans += s[i]", "+print(ans)" ]
false
0.0439
0.042203
1.040201
[ "s661018831", "s870283413" ]
u844789719
p02803
python
s265362006
s396540950
386
203
52,572
40,264
Accepted
Accepted
47.41
import copy, collections, itertools H, W = [int(_) for _ in input().split()] S_ = [['#'] * (W + 2)] + [['#'] + list(eval(input())) + ['#'] for _ in range(H)] + [['#'] * (W + 2)] ans = 0 for i, j in itertools.product(list(range(1, H + 1)), list(range(1, W + 1))): if S_[i][j] == '.': S = copy.deepcopy(S_) S[i][j] = '#' q = collections.deque([(i, j, 0)]) while q: x, y, d = q.popleft() for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]: if S[x + dx][y + dy] == '.': X, Y = x + dx, y + dy S[X][Y] = '#' q += [(X, Y, d + 1)] ans = max(d, ans) print(ans)
import collections import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall H, W, *S = open(0).read().split() H, W = [int(_) for _ in [H, W]] A = [] B = [] C = [] for i in range(H * W): x, y = divmod(i, W) if S[x][y] == '.': for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)): nx, ny = x + dx, y + dy if not (0 <= nx < H and 0 <= ny < W): continue if S[nx][ny] == '.': A += [i] B += [nx * W + ny] C += [1] F = floyd_warshall(csr_matrix((C, (A, B)), shape=(H*W, H*W))) print((int(np.max(F[F!=np.inf]))))
19
23
720
684
import copy, collections, itertools H, W = [int(_) for _ in input().split()] S_ = ( [["#"] * (W + 2)] + [["#"] + list(eval(input())) + ["#"] for _ in range(H)] + [["#"] * (W + 2)] ) ans = 0 for i, j in itertools.product(list(range(1, H + 1)), list(range(1, W + 1))): if S_[i][j] == ".": S = copy.deepcopy(S_) S[i][j] = "#" q = collections.deque([(i, j, 0)]) while q: x, y, d = q.popleft() for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]: if S[x + dx][y + dy] == ".": X, Y = x + dx, y + dy S[X][Y] = "#" q += [(X, Y, d + 1)] ans = max(d, ans) print(ans)
import collections import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall H, W, *S = open(0).read().split() H, W = [int(_) for _ in [H, W]] A = [] B = [] C = [] for i in range(H * W): x, y = divmod(i, W) if S[x][y] == ".": for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)): nx, ny = x + dx, y + dy if not (0 <= nx < H and 0 <= ny < W): continue if S[nx][ny] == ".": A += [i] B += [nx * W + ny] C += [1] F = floyd_warshall(csr_matrix((C, (A, B)), shape=(H * W, H * W))) print((int(np.max(F[F != np.inf]))))
false
17.391304
[ "-import copy, collections, itertools", "+import collections", "+import numpy as np", "+from scipy.sparse import csr_matrix", "+from scipy.sparse.csgraph import floyd_warshall", "-H, W = [int(_) for _ in input().split()]", "-S_ = (", "- [[\"#\"] * (W + 2)]", "- + [[\"#\"] + list(eval(input())) + [\"#\"] for _ in range(H)]", "- + [[\"#\"] * (W + 2)]", "-)", "-ans = 0", "-for i, j in itertools.product(list(range(1, H + 1)), list(range(1, W + 1))):", "- if S_[i][j] == \".\":", "- S = copy.deepcopy(S_)", "- S[i][j] = \"#\"", "- q = collections.deque([(i, j, 0)])", "- while q:", "- x, y, d = q.popleft()", "- for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]:", "- if S[x + dx][y + dy] == \".\":", "- X, Y = x + dx, y + dy", "- S[X][Y] = \"#\"", "- q += [(X, Y, d + 1)]", "- ans = max(d, ans)", "-print(ans)", "+H, W, *S = open(0).read().split()", "+H, W = [int(_) for _ in [H, W]]", "+A = []", "+B = []", "+C = []", "+for i in range(H * W):", "+ x, y = divmod(i, W)", "+ if S[x][y] == \".\":", "+ for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):", "+ nx, ny = x + dx, y + dy", "+ if not (0 <= nx < H and 0 <= ny < W):", "+ continue", "+ if S[nx][ny] == \".\":", "+ A += [i]", "+ B += [nx * W + ny]", "+ C += [1]", "+F = floyd_warshall(csr_matrix((C, (A, B)), shape=(H * W, H * W)))", "+print((int(np.max(F[F != np.inf]))))" ]
false
0.040499
0.334866
0.120941
[ "s265362006", "s396540950" ]
u375616706
p03614
python
s393350272
s013445093
80
67
13,876
13,876
Accepted
Accepted
16.25
# python template for atcoder1 import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) seq = 0 ans = 0 for i in range(N): A[i] -= i+1 if A[i] == 0: seq += 1 else: ans += (seq+1)//2 seq = 0 ans += (seq+1)//2 print(ans)
# python template for atcoder1 import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) seq = 0 ans = 0 for i in range(1, N+1): if A[i-1] == i: seq += 1 else: ans += (seq+1)//2 seq = 0 ans += (seq+1)//2 print(ans)
19
18
338
328
# python template for atcoder1 import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) seq = 0 ans = 0 for i in range(N): A[i] -= i + 1 if A[i] == 0: seq += 1 else: ans += (seq + 1) // 2 seq = 0 ans += (seq + 1) // 2 print(ans)
# python template for atcoder1 import sys sys.setrecursionlimit(10**9) input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) seq = 0 ans = 0 for i in range(1, N + 1): if A[i - 1] == i: seq += 1 else: ans += (seq + 1) // 2 seq = 0 ans += (seq + 1) // 2 print(ans)
false
5.263158
[ "-for i in range(N):", "- A[i] -= i + 1", "- if A[i] == 0:", "+for i in range(1, N + 1):", "+ if A[i - 1] == i:" ]
false
0.136686
0.094508
1.446288
[ "s393350272", "s013445093" ]
u798818115
p02924
python
s050715797
s377235080
21
17
3,060
2,940
Accepted
Accepted
19.05
# coding: utf-8 # Your code here! N=int(eval(input())) print((int(N*(N-1)//2)))
# coding: utf-8 # Your code here! N=int(eval(input())) print((N*(N-1)//2))
5
6
77
73
# coding: utf-8 # Your code here! N = int(eval(input())) print((int(N * (N - 1) // 2)))
# coding: utf-8 # Your code here! N = int(eval(input())) print((N * (N - 1) // 2))
false
16.666667
[ "-print((int(N * (N - 1) // 2)))", "+print((N * (N - 1) // 2))" ]
false
0.049182
0.048855
1.006687
[ "s050715797", "s377235080" ]
u375695365
p03503
python
s402782281
s011336229
267
139
3,064
3,064
Accepted
Accepted
47.94
from itertools import product n=int(eval(input())) f=[list(map(int,input().split())) for _ in range(n)] #曜日 p=[list(map(int,input().split())) for _ in range(n)] #利益 ans=-10**50 for z in product((0, 1), repeat=10):#bit全探索のくみあわせを勝手に作ってくれるので使うとよい profit_count=0 #利益の合計 for i in range(n): work_count=0 #働く時間帯が同じ回数 for j in range(10): #個数を調べる if f[i][j]==1 and z[j]==1: #f[i][j]==z[j]だと両方0の時もcountしちゃう work_count+=1 profit_count+=p[i][work_count] if ans<profit_count: #ans=max(ans,profit_count)だと000000000000の時確認できない if 1 in z: #1日以上働いているかの確認 ans=profit_count print(ans)
#Forestの n = int(eval(input())) f = [list(map(int, input().split())) for _ in range(n)] p = [list(map(int, input().split())) for _ in range(n)] ans = -10 ** 30 for i in range(1, 2 ** 10): cnt = [0] * n calc = 0 #print(cnt) for j in range(10): if i >> j & 1: for k in range(n): if f[k][j] == 1: cnt[k] += 1 for k in range(n): calc += p[k][cnt[k]] ans = max(ans, calc) print(ans)
21
23
673
511
from itertools import product n = int(eval(input())) f = [list(map(int, input().split())) for _ in range(n)] # 曜日 p = [list(map(int, input().split())) for _ in range(n)] # 利益 ans = -(10**50) for z in product((0, 1), repeat=10): # bit全探索のくみあわせを勝手に作ってくれるので使うとよい profit_count = 0 # 利益の合計 for i in range(n): work_count = 0 # 働く時間帯が同じ回数 for j in range(10): # 個数を調べる if f[i][j] == 1 and z[j] == 1: # f[i][j]==z[j]だと両方0の時もcountしちゃう work_count += 1 profit_count += p[i][work_count] if ans < profit_count: # ans=max(ans,profit_count)だと000000000000の時確認できない if 1 in z: # 1日以上働いているかの確認 ans = profit_count print(ans)
# Forestの n = int(eval(input())) f = [list(map(int, input().split())) for _ in range(n)] p = [list(map(int, input().split())) for _ in range(n)] ans = -(10**30) for i in range(1, 2**10): cnt = [0] * n calc = 0 # print(cnt) for j in range(10): if i >> j & 1: for k in range(n): if f[k][j] == 1: cnt[k] += 1 for k in range(n): calc += p[k][cnt[k]] ans = max(ans, calc) print(ans)
false
8.695652
[ "-from itertools import product", "-", "+# Forestの", "-# 曜日", "-# 利益", "-ans = -(10**50)", "-for z in product((0, 1), repeat=10): # bit全探索のくみあわせを勝手に作ってくれるので使うとよい", "- profit_count = 0 # 利益の合計", "- for i in range(n):", "- work_count = 0 # 働く時間帯が同じ回数", "- for j in range(10): # 個数を調べる", "- if f[i][j] == 1 and z[j] == 1: # f[i][j]==z[j]だと両方0の時もcountしちゃう", "- work_count += 1", "- profit_count += p[i][work_count]", "- if ans < profit_count: # ans=max(ans,profit_count)だと000000000000の時確認できない", "- if 1 in z: # 1日以上働いているかの確認", "- ans = profit_count", "+ans = -(10**30)", "+for i in range(1, 2**10):", "+ cnt = [0] * n", "+ calc = 0", "+ # print(cnt)", "+ for j in range(10):", "+ if i >> j & 1:", "+ for k in range(n):", "+ if f[k][j] == 1:", "+ cnt[k] += 1", "+ for k in range(n):", "+ calc += p[k][cnt[k]]", "+ ans = max(ans, calc)" ]
false
0.04142
0.068488
0.604773
[ "s402782281", "s011336229" ]
u416011173
p03031
python
s588095589
s314908686
38
35
9,252
9,216
Accepted
Accepted
7.89
# -*- coding: utf-8 -*- def get_input() -> tuple: """ 標準入力を取得する. Returns:\n tuple: 標準入力 """ # 標準入力を取得 N, M = list(map(int, input().split())) k, s = [], [] for m in range(M): l = list(map(int, input().split())) k_m, s_m = l[0], l[1:] k.append(k_m) s.append(s_m) p = list(map(int, input().split())) return N, M, k, s, p def lights_on(M: int, s: list, p: list, switches: int) -> bool: """ 電球がすべて点灯しているかどうかを確認する. Args:\n M (int): 電球の数 s (list): 電球に対応するスイッチ p (list): スイッチと電球の点灯の関係 switches (int): スイッチの状態 Returns:\n bool: 電球がすべて点灯していれば真、そうでなければ偽 """ result = True for m in range(M): switch_on_count = 0 for s_m_km in s[m]: if switches & (1 << (s_m_km - 1)): switch_on_count += 1 if switch_on_count % 2 != p[m]: result = False return result def main(N: int, M: int, s: list, p: list) -> None: """ メイン処理. Args:\n N (int): スイッチの数 M (int): 電球の数 s (list): 電球に対応するスイッチ p (list): スイッチと電球の点灯の関係 """ # 求解処理 ans = 0 for switches in range(1 << N): if lights_on(M, s, p, switches): ans += 1 # 結果出力 print(ans) if __name__ == "__main__": # 標準入力を取得 N, M, k, s, p = get_input() # メイン処理 main(N, M, s, p)
# -*- coding: utf-8 -*- # 標準入力を取得 N, M = list(map(int, input().split())) k, s = [], [] for m in range(M): l = list(map(int, input().split())) k.append(l[0]) s.append(l[1:]) p = list(map(int, input().split())) # 求解処理 ans = 0 for bit in range(1 << N): is_light_on = True for m in range(M): on_count = 0 for s_i in s[m]: if ((bit >> (s_i - 1)) & 1): on_count += 1 if on_count % 2 != p[m]: is_light_on = False break if is_light_on: ans += 1 # 結果出力 print(ans)
73
27
1,490
591
# -*- coding: utf-8 -*- def get_input() -> tuple: """ 標準入力を取得する. Returns:\n tuple: 標準入力 """ # 標準入力を取得 N, M = list(map(int, input().split())) k, s = [], [] for m in range(M): l = list(map(int, input().split())) k_m, s_m = l[0], l[1:] k.append(k_m) s.append(s_m) p = list(map(int, input().split())) return N, M, k, s, p def lights_on(M: int, s: list, p: list, switches: int) -> bool: """ 電球がすべて点灯しているかどうかを確認する. Args:\n M (int): 電球の数 s (list): 電球に対応するスイッチ p (list): スイッチと電球の点灯の関係 switches (int): スイッチの状態 Returns:\n bool: 電球がすべて点灯していれば真、そうでなければ偽 """ result = True for m in range(M): switch_on_count = 0 for s_m_km in s[m]: if switches & (1 << (s_m_km - 1)): switch_on_count += 1 if switch_on_count % 2 != p[m]: result = False return result def main(N: int, M: int, s: list, p: list) -> None: """ メイン処理. Args:\n N (int): スイッチの数 M (int): 電球の数 s (list): 電球に対応するスイッチ p (list): スイッチと電球の点灯の関係 """ # 求解処理 ans = 0 for switches in range(1 << N): if lights_on(M, s, p, switches): ans += 1 # 結果出力 print(ans) if __name__ == "__main__": # 標準入力を取得 N, M, k, s, p = get_input() # メイン処理 main(N, M, s, p)
# -*- coding: utf-8 -*- # 標準入力を取得 N, M = list(map(int, input().split())) k, s = [], [] for m in range(M): l = list(map(int, input().split())) k.append(l[0]) s.append(l[1:]) p = list(map(int, input().split())) # 求解処理 ans = 0 for bit in range(1 << N): is_light_on = True for m in range(M): on_count = 0 for s_i in s[m]: if (bit >> (s_i - 1)) & 1: on_count += 1 if on_count % 2 != p[m]: is_light_on = False break if is_light_on: ans += 1 # 結果出力 print(ans)
false
63.013699
[ "-def get_input() -> tuple:", "- \"\"\"", "- 標準入力を取得する.", "- Returns:\\n", "- tuple: 標準入力", "- \"\"\"", "- # 標準入力を取得", "- N, M = list(map(int, input().split()))", "- k, s = [], []", "+# 標準入力を取得", "+N, M = list(map(int, input().split()))", "+k, s = [], []", "+for m in range(M):", "+ l = list(map(int, input().split()))", "+ k.append(l[0])", "+ s.append(l[1:])", "+p = list(map(int, input().split()))", "+# 求解処理", "+ans = 0", "+for bit in range(1 << N):", "+ is_light_on = True", "- l = list(map(int, input().split()))", "- k_m, s_m = l[0], l[1:]", "- k.append(k_m)", "- s.append(s_m)", "- p = list(map(int, input().split()))", "- return N, M, k, s, p", "-", "-", "-def lights_on(M: int, s: list, p: list, switches: int) -> bool:", "- \"\"\"", "- 電球がすべて点灯しているかどうかを確認する.", "- Args:\\n", "- M (int): 電球の数", "- s (list): 電球に対応するスイッチ", "- p (list): スイッチと電球の点灯の関係", "- switches (int): スイッチの状態", "- Returns:\\n", "- bool: 電球がすべて点灯していれば真、そうでなければ偽", "- \"\"\"", "- result = True", "- for m in range(M):", "- switch_on_count = 0", "- for s_m_km in s[m]:", "- if switches & (1 << (s_m_km - 1)):", "- switch_on_count += 1", "- if switch_on_count % 2 != p[m]:", "- result = False", "- return result", "-", "-", "-def main(N: int, M: int, s: list, p: list) -> None:", "- \"\"\"", "- メイン処理.", "- Args:\\n", "- N (int): スイッチの数", "- M (int): 電球の数", "- s (list): 電球に対応するスイッチ", "- p (list): スイッチと電球の点灯の関係", "- \"\"\"", "- # 求解処理", "- ans = 0", "- for switches in range(1 << N):", "- if lights_on(M, s, p, switches):", "- ans += 1", "- # 結果出力", "- print(ans)", "-", "-", "-if __name__ == \"__main__\":", "- # 標準入力を取得", "- N, M, k, s, p = get_input()", "- # メイン処理", "- main(N, M, s, p)", "+ on_count = 0", "+ for s_i in s[m]:", "+ if (bit >> (s_i - 1)) & 1:", "+ on_count += 1", "+ if on_count % 2 != p[m]:", "+ is_light_on = False", "+ break", "+ if is_light_on:", "+ ans += 1", "+# 結果出力", "+print(ans)" ]
false
0.03793
0.085544
0.443392
[ "s588095589", "s314908686" ]
u760248716
p03911
python
s531243069
s014005122
933
826
167,136
167,088
Accepted
Accepted
11.47
from networkx import* g=[] for _,*t in[*list(map(str.split,open(i:=0)))][1:]: for j in t:g+=(i,'!'+j), i+=1 print(('NYOE S'[is_connected(Graph(g))::2]))
from networkx import* g=[] for t in[*open(i:=0)][1:]: for j in t.split()[1:]:g+=(i,'!'+j), i+=1 print(('NYOE S'[is_connected(Graph(g))::2]))
6
6
151
145
from networkx import * g = [] for _, *t in [*list(map(str.split, open(i := 0)))][1:]: for j in t: g += ((i, "!" + j),) i += 1 print(("NYOE S"[is_connected(Graph(g)) :: 2]))
from networkx import * g = [] for t in [*open(i := 0)][1:]: for j in t.split()[1:]: g += ((i, "!" + j),) i += 1 print(("NYOE S"[is_connected(Graph(g)) :: 2]))
false
0
[ "-for _, *t in [*list(map(str.split, open(i := 0)))][1:]:", "- for j in t:", "+for t in [*open(i := 0)][1:]:", "+ for j in t.split()[1:]:" ]
false
0.033897
0.04285
0.791058
[ "s531243069", "s014005122" ]
u011062360
p03329
python
s202411598
s786790516
425
209
3,860
8,876
Accepted
Accepted
50.82
n = int(eval(input())) dp = [0] for i in range(1, n+1): q = [] q.append(1+dp[i-1]) a = 1 while True: a *= 6 if a > i: break q.append(1+dp[i-a]) b = 1 while True: b *= 9 if b > i: break q.append(1+dp[i-b]) dp.append(min(q)) print((dp[n]))
n = int(eval(input())) ans = pow(10, 10) for i in range(n+1): cnt = 0 j = n - i while i > 0: cnt += i % 6 i //= 6 while j > 0: cnt += j % 9 j //= 9 ans = min(ans, cnt) print(ans)
24
17
357
244
n = int(eval(input())) dp = [0] for i in range(1, n + 1): q = [] q.append(1 + dp[i - 1]) a = 1 while True: a *= 6 if a > i: break q.append(1 + dp[i - a]) b = 1 while True: b *= 9 if b > i: break q.append(1 + dp[i - b]) dp.append(min(q)) print((dp[n]))
n = int(eval(input())) ans = pow(10, 10) for i in range(n + 1): cnt = 0 j = n - i while i > 0: cnt += i % 6 i //= 6 while j > 0: cnt += j % 9 j //= 9 ans = min(ans, cnt) print(ans)
false
29.166667
[ "-dp = [0]", "-for i in range(1, n + 1):", "- q = []", "- q.append(1 + dp[i - 1])", "- a = 1", "- while True:", "- a *= 6", "- if a > i:", "- break", "- q.append(1 + dp[i - a])", "- b = 1", "- while True:", "- b *= 9", "- if b > i:", "- break", "- q.append(1 + dp[i - b])", "- dp.append(min(q))", "-print((dp[n]))", "+ans = pow(10, 10)", "+for i in range(n + 1):", "+ cnt = 0", "+ j = n - i", "+ while i > 0:", "+ cnt += i % 6", "+ i //= 6", "+ while j > 0:", "+ cnt += j % 9", "+ j //= 9", "+ ans = min(ans, cnt)", "+print(ans)" ]
false
0.159826
0.064313
2.485118
[ "s202411598", "s786790516" ]
u077291787
p02658
python
s397166112
s668187580
51
40
21,584
19,280
Accepted
Accepted
21.57
# B - Multiplication 2 def main(): _, *A = list(map(int, open(0).read().split())) if 0 in A: print((0)) return prod = 1 LIM = 10 ** 18 for i in A: prod *= i if prod > LIM: print((-1)) return print(prod) if __name__ == "__main__": main()
# B - Multiplication 2 def main(): _, *A = open(0).read().split() if "0" in A: print((0)) return prod = 1 LIM = 10 ** 18 for i in A: prod *= int(i) if prod > LIM: print((-1)) return print(prod) if __name__ == "__main__": main()
18
18
331
327
# B - Multiplication 2 def main(): _, *A = list(map(int, open(0).read().split())) if 0 in A: print((0)) return prod = 1 LIM = 10**18 for i in A: prod *= i if prod > LIM: print((-1)) return print(prod) if __name__ == "__main__": main()
# B - Multiplication 2 def main(): _, *A = open(0).read().split() if "0" in A: print((0)) return prod = 1 LIM = 10**18 for i in A: prod *= int(i) if prod > LIM: print((-1)) return print(prod) if __name__ == "__main__": main()
false
0
[ "- _, *A = list(map(int, open(0).read().split()))", "- if 0 in A:", "+ _, *A = open(0).read().split()", "+ if \"0\" in A:", "- prod *= i", "+ prod *= int(i)" ]
false
0.041339
0.04211
0.981695
[ "s397166112", "s668187580" ]
u785795721
p02947
python
s895751869
s796915005
391
355
19,504
19,400
Accepted
Accepted
9.21
n = int(eval(input())) S = ["".join(list(sorted(eval(input())))) for _ in range(n)] d = {} for i in S: d.setdefault(i, 0) d[i] += 1 ans = 0 for value in list(d.values()): ans += value * (value - 1) / 2 print((int(ans)))
n = int(eval(input())) S = [''.join(sorted(eval(input()))) for _ in range(n)] d = {} for i in S: d.setdefault(i, 0) d[i] += 1 ans = 0 for value in list(d.values()): ans += value * (value - 1) // 2 print(ans)
10
10
220
210
n = int(eval(input())) S = ["".join(list(sorted(eval(input())))) for _ in range(n)] d = {} for i in S: d.setdefault(i, 0) d[i] += 1 ans = 0 for value in list(d.values()): ans += value * (value - 1) / 2 print((int(ans)))
n = int(eval(input())) S = ["".join(sorted(eval(input()))) for _ in range(n)] d = {} for i in S: d.setdefault(i, 0) d[i] += 1 ans = 0 for value in list(d.values()): ans += value * (value - 1) // 2 print(ans)
false
0
[ "-S = [\"\".join(list(sorted(eval(input())))) for _ in range(n)]", "+S = [\"\".join(sorted(eval(input()))) for _ in range(n)]", "- ans += value * (value - 1) / 2", "-print((int(ans)))", "+ ans += value * (value - 1) // 2", "+print(ans)" ]
false
0.042395
0.035146
1.206248
[ "s895751869", "s796915005" ]
u903005414
p03294
python
s699480961
s035013113
23
18
3,316
3,316
Accepted
Accepted
21.74
def gcd(a, b): return a if b == 0 else gcd(b, a % b) def lcm(a, b): return a * b // gcd(a, b) N = int(eval(input())) A = list(map(int, input().split())) l = 0 for i in range(1, len(A)): l = lcm(A[i - 1], A[i]) ans = l - 1 ans = sum(A) - len(A) print(ans)
N = int(eval(input())) A = list(map(int, input().split())) ans = sum(A) - len(A) print(ans)
17
4
282
89
def gcd(a, b): return a if b == 0 else gcd(b, a % b) def lcm(a, b): return a * b // gcd(a, b) N = int(eval(input())) A = list(map(int, input().split())) l = 0 for i in range(1, len(A)): l = lcm(A[i - 1], A[i]) ans = l - 1 ans = sum(A) - len(A) print(ans)
N = int(eval(input())) A = list(map(int, input().split())) ans = sum(A) - len(A) print(ans)
false
76.470588
[ "-def gcd(a, b):", "- return a if b == 0 else gcd(b, a % b)", "-", "-", "-def lcm(a, b):", "- return a * b // gcd(a, b)", "-", "-", "-l = 0", "-for i in range(1, len(A)):", "- l = lcm(A[i - 1], A[i])", "-ans = l - 1" ]
false
0.078201
0.075941
1.029753
[ "s699480961", "s035013113" ]
u496744988
p03835
python
s657374516
s036720956
1,267
251
2,940
41,324
Accepted
Accepted
80.19
k,s=list(map(int,input().split())) cnt=0 for x in range(k+1): for y in range(k+1): if 0 <= s-x-y <=k: cnt+=1 print(cnt)
k, s = list(map(int, input().split())) ans = 0 for x in range(k+1): for y in range(k+1): if 0 <= s - x - y <= k: ans += 1 print(ans)
7
7
144
157
k, s = list(map(int, input().split())) cnt = 0 for x in range(k + 1): for y in range(k + 1): if 0 <= s - x - y <= k: cnt += 1 print(cnt)
k, s = list(map(int, input().split())) ans = 0 for x in range(k + 1): for y in range(k + 1): if 0 <= s - x - y <= k: ans += 1 print(ans)
false
0
[ "-cnt = 0", "+ans = 0", "- cnt += 1", "-print(cnt)", "+ ans += 1", "+print(ans)" ]
false
0.032099
0.056004
0.573154
[ "s657374516", "s036720956" ]
u600402037
p03018
python
s829809748
s391352179
79
49
4,968
3,500
Accepted
Accepted
37.97
import sys stdin = sys.stdin ri = lambda: int(rs()) rl = lambda: list(map(int, stdin.readline().split())) rs = lambda: stdin.readline().rstrip() # ignore trailing spaces S = list(rs()) cur = 'D' answer = 0 A_cnt = 0 for s in S: if cur == 'A': if s == 'A': A_cnt += 1 elif s == 'B': cur = s else: cur = 'D' A_cnt = 0 elif cur == 'B': if s == 'A': A_cnt = 1 cur = s elif s == 'B': A_cnt = 0 cur = 'D' elif s == 'C': answer += A_cnt cur = s else: cur = 'D' A_cnt = 0 elif cur == 'C': if s == 'A': A_cnt += 1 cur = s elif s == 'B': cur = s else: cur = 'D' A_cnt = 0 else: if s == 'A': A_cnt += 1 cur = s else: A_cnt = 0 cur = 'D' print(answer)
import sys stdin = sys.stdin ri = lambda: int(rs()) rl = lambda: list(map(int, stdin.readline().split())) rs = lambda: stdin.readline().rstrip() # ignore trailing spaces S = rs() S = S.replace('BC', 'D') cnt_A = 0 answer = 0 for s in S: if s == 'A': cnt_A += 1 elif s == 'D': answer += cnt_A else: cnt_A = 0 print(answer)
51
19
1,059
379
import sys stdin = sys.stdin ri = lambda: int(rs()) rl = lambda: list(map(int, stdin.readline().split())) rs = lambda: stdin.readline().rstrip() # ignore trailing spaces S = list(rs()) cur = "D" answer = 0 A_cnt = 0 for s in S: if cur == "A": if s == "A": A_cnt += 1 elif s == "B": cur = s else: cur = "D" A_cnt = 0 elif cur == "B": if s == "A": A_cnt = 1 cur = s elif s == "B": A_cnt = 0 cur = "D" elif s == "C": answer += A_cnt cur = s else: cur = "D" A_cnt = 0 elif cur == "C": if s == "A": A_cnt += 1 cur = s elif s == "B": cur = s else: cur = "D" A_cnt = 0 else: if s == "A": A_cnt += 1 cur = s else: A_cnt = 0 cur = "D" print(answer)
import sys stdin = sys.stdin ri = lambda: int(rs()) rl = lambda: list(map(int, stdin.readline().split())) rs = lambda: stdin.readline().rstrip() # ignore trailing spaces S = rs() S = S.replace("BC", "D") cnt_A = 0 answer = 0 for s in S: if s == "A": cnt_A += 1 elif s == "D": answer += cnt_A else: cnt_A = 0 print(answer)
false
62.745098
[ "-S = list(rs())", "-cur = \"D\"", "+S = rs()", "+S = S.replace(\"BC\", \"D\")", "+cnt_A = 0", "-A_cnt = 0", "- if cur == \"A\":", "- if s == \"A\":", "- A_cnt += 1", "- elif s == \"B\":", "- cur = s", "- else:", "- cur = \"D\"", "- A_cnt = 0", "- elif cur == \"B\":", "- if s == \"A\":", "- A_cnt = 1", "- cur = s", "- elif s == \"B\":", "- A_cnt = 0", "- cur = \"D\"", "- elif s == \"C\":", "- answer += A_cnt", "- cur = s", "- else:", "- cur = \"D\"", "- A_cnt = 0", "- elif cur == \"C\":", "- if s == \"A\":", "- A_cnt += 1", "- cur = s", "- elif s == \"B\":", "- cur = s", "- else:", "- cur = \"D\"", "- A_cnt = 0", "+ if s == \"A\":", "+ cnt_A += 1", "+ elif s == \"D\":", "+ answer += cnt_A", "- if s == \"A\":", "- A_cnt += 1", "- cur = s", "- else:", "- A_cnt = 0", "- cur = \"D\"", "+ cnt_A = 0" ]
false
0.066659
0.04693
1.420389
[ "s829809748", "s391352179" ]
u936985471
p03163
python
s416786273
s509474462
1,879
658
9,772
171,912
Accepted
Accepted
64.98
def calc(): N,W=list(map(int,input().split())) dp=[-1]*(W+1) dp[0]=0 for i in range(N): w,v=list(map(int,input().split())) for j in range(W-w,-1,-1): if dp[j]!=-1: if dp[j+w]<dp[j]+v: dp[j+w]=dp[j]+v print((max(dp))) calc()
N,W=list(map(int,input().split())) weight=[0]*N values=[0]*N for i in range(N): weight[i],values[i]=list(map(int,input().split())) dp=[[0 for i in range(W+1)] for j in range(N+1)] for i in range(N): for w in range(W+1): if w>=weight[i]: dp[i+1][w]=max(dp[i][w],dp[i][w-weight[i]]+values[i]) else: dp[i+1][w]=dp[i][w] print((dp[N][W]))
13
16
266
369
def calc(): N, W = list(map(int, input().split())) dp = [-1] * (W + 1) dp[0] = 0 for i in range(N): w, v = list(map(int, input().split())) for j in range(W - w, -1, -1): if dp[j] != -1: if dp[j + w] < dp[j] + v: dp[j + w] = dp[j] + v print((max(dp))) calc()
N, W = list(map(int, input().split())) weight = [0] * N values = [0] * N for i in range(N): weight[i], values[i] = list(map(int, input().split())) dp = [[0 for i in range(W + 1)] for j in range(N + 1)] for i in range(N): for w in range(W + 1): if w >= weight[i]: dp[i + 1][w] = max(dp[i][w], dp[i][w - weight[i]] + values[i]) else: dp[i + 1][w] = dp[i][w] print((dp[N][W]))
false
18.75
[ "-def calc():", "- N, W = list(map(int, input().split()))", "- dp = [-1] * (W + 1)", "- dp[0] = 0", "- for i in range(N):", "- w, v = list(map(int, input().split()))", "- for j in range(W - w, -1, -1):", "- if dp[j] != -1:", "- if dp[j + w] < dp[j] + v:", "- dp[j + w] = dp[j] + v", "- print((max(dp)))", "-", "-", "-calc()", "+N, W = list(map(int, input().split()))", "+weight = [0] * N", "+values = [0] * N", "+for i in range(N):", "+ weight[i], values[i] = list(map(int, input().split()))", "+dp = [[0 for i in range(W + 1)] for j in range(N + 1)]", "+for i in range(N):", "+ for w in range(W + 1):", "+ if w >= weight[i]:", "+ dp[i + 1][w] = max(dp[i][w], dp[i][w - weight[i]] + values[i])", "+ else:", "+ dp[i + 1][w] = dp[i][w]", "+print((dp[N][W]))" ]
false
0.045104
0.044828
1.006155
[ "s416786273", "s509474462" ]
u761320129
p03231
python
s875042333
s557364076
123
47
5,688
5,560
Accepted
Accepted
61.79
import fractions N,M = list(map(int,input().split())) S = eval(input()) T = eval(input()) g = fractions.gcd(N,M) lcm = N*M // g for i in range(g): a = S[N//g * i] b = T[M//g * i] if a != b: print((-1)) exit() print(lcm)
from fractions import gcd N,M = list(map(int,input().split())) S = eval(input()) T = eval(input()) g = gcd(N,M) ans = N*M//g print((ans if S[::N//g] == T[::M//g] else -1))
14
7
241
157
import fractions N, M = list(map(int, input().split())) S = eval(input()) T = eval(input()) g = fractions.gcd(N, M) lcm = N * M // g for i in range(g): a = S[N // g * i] b = T[M // g * i] if a != b: print((-1)) exit() print(lcm)
from fractions import gcd N, M = list(map(int, input().split())) S = eval(input()) T = eval(input()) g = gcd(N, M) ans = N * M // g print((ans if S[:: N // g] == T[:: M // g] else -1))
false
50
[ "-import fractions", "+from fractions import gcd", "-g = fractions.gcd(N, M)", "-lcm = N * M // g", "-for i in range(g):", "- a = S[N // g * i]", "- b = T[M // g * i]", "- if a != b:", "- print((-1))", "- exit()", "-print(lcm)", "+g = gcd(N, M)", "+ans = N * M // g", "+print((ans if S[:: N // g] == T[:: M // g] else -1))" ]
false
0.100122
0.18075
0.553925
[ "s875042333", "s557364076" ]
u519939795
p02899
python
s311939460
s887603190
316
111
21,464
14,008
Accepted
Accepted
64.87
N=int(input()) A=list(map(int,input().split())) ANS=[] for i in range(N): ANS+=[[A[i],i+1]] ANS.sort() for i in range(N): print(ANS[i][1], end=' ')
n = int(eval(input())) l = list(map(int,input().split())) ans = [0] * n for i in range(n): ans[l[i]-1] = i + 1 print((*ans))
8
7
162
126
N = int(input()) A = list(map(int, input().split())) ANS = [] for i in range(N): ANS += [[A[i], i + 1]] ANS.sort() for i in range(N): print(ANS[i][1], end=" ")
n = int(eval(input())) l = list(map(int, input().split())) ans = [0] * n for i in range(n): ans[l[i] - 1] = i + 1 print((*ans))
false
12.5
[ "-N = int(input())", "-A = list(map(int, input().split()))", "-ANS = []", "-for i in range(N):", "- ANS += [[A[i], i + 1]]", "-ANS.sort()", "-for i in range(N):", "- print(ANS[i][1], end=\" \")", "+n = int(eval(input()))", "+l = list(map(int, input().split()))", "+ans = [0] * n", "+for i in range(n):", "+ ans[l[i] - 1] = i + 1", "+print((*ans))" ]
false
0.036476
0.037271
0.97866
[ "s311939460", "s887603190" ]
u936985471
p02912
python
s182131593
s623395247
244
159
14,380
14,224
Accepted
Accepted
34.84
import heapq n,m=list(map(int,input().split())) a=list(map(int,input().split())) hq=[] for i in range(len(a)): heapq.heappush(hq,-a[i]) if n==1: for i in range(m): hq[0]=(((-1)*hq[0])//2)*(-1) else: for i in range(m): v=heapq.heappop(hq) heapq.heappush(hq,((v*-1)//2)*(-1)) ans=0 for i in range(len(hq)): ans=ans+(-1)*heapq.heappop(hq) print(ans)
n,m=list(map(int,input().split())) a=list(map(int,input().split())) for i in range(len(a)): a[i]*=(-1) import heapq heapq.heapify(a) for i in range(m): val=heapq.heappop(a) heapq.heappush(a,((val*(-1))//2)*(-1)) print((sum(a)*(-1)))
21
13
386
245
import heapq n, m = list(map(int, input().split())) a = list(map(int, input().split())) hq = [] for i in range(len(a)): heapq.heappush(hq, -a[i]) if n == 1: for i in range(m): hq[0] = (((-1) * hq[0]) // 2) * (-1) else: for i in range(m): v = heapq.heappop(hq) heapq.heappush(hq, ((v * -1) // 2) * (-1)) ans = 0 for i in range(len(hq)): ans = ans + (-1) * heapq.heappop(hq) print(ans)
n, m = list(map(int, input().split())) a = list(map(int, input().split())) for i in range(len(a)): a[i] *= -1 import heapq heapq.heapify(a) for i in range(m): val = heapq.heappop(a) heapq.heappush(a, ((val * (-1)) // 2) * (-1)) print((sum(a) * (-1)))
false
38.095238
[ "+n, m = list(map(int, input().split()))", "+a = list(map(int, input().split()))", "+for i in range(len(a)):", "+ a[i] *= -1", "-n, m = list(map(int, input().split()))", "-a = list(map(int, input().split()))", "-hq = []", "-for i in range(len(a)):", "- heapq.heappush(hq, -a[i])", "-if n == 1:", "- for i in range(m):", "- hq[0] = (((-1) * hq[0]) // 2) * (-1)", "-else:", "- for i in range(m):", "- v = heapq.heappop(hq)", "- heapq.heappush(hq, ((v * -1) // 2) * (-1))", "-ans = 0", "-for i in range(len(hq)):", "- ans = ans + (-1) * heapq.heappop(hq)", "-print(ans)", "+heapq.heapify(a)", "+for i in range(m):", "+ val = heapq.heappop(a)", "+ heapq.heappush(a, ((val * (-1)) // 2) * (-1))", "+print((sum(a) * (-1)))" ]
false
0.141405
0.128153
1.103414
[ "s182131593", "s623395247" ]
u620084012
p03575
python
s044127082
s033107759
1,859
201
3,316
42,348
Accepted
Accepted
89.19
N, M = list(map(int, input().split())) E = [list(map(int, input().split())) for k in range(M)] ans = 0 for k in range(M): F = E[:k]+E[k+1:] D = [[10**9+7 for l in range(N)] for m in range(N)] for p in range(N): D[p][p] = 0 for n in F: D[n[0]-1][n[1]-1] = D[n[1]-1][n[0]-1] = 1 for s in range(N): for t in range(N): for u in range(N): if D[t][u] > D[t][s] + D[s][u]: D[t][u] = D[t][s] + D[s][u] f = 0 for p in range(N): for q in range(N): if D[p][q] > N: f = 1 ans += f print(ans)
N, M = list(map(int,input().split())) P = [list(map(int,input().split())) for k in range(M)] ans = 0 for i in range(M): T = P[:i]+P[i+1:] G = [[] for k in range(N)] V = [0 for k in range(N)] for e in T: G[e[0]-1].append(e[1]-1) G[e[1]-1].append(e[0]-1) def dfs(visited,graph,ima): for e in graph[ima]: if visited[e] == 0: visited[e] = 1 dfs(visited,graph,e) dfs(V,G,0) if sum(V) != N: ans += 1 print(ans)
23
21
636
525
N, M = list(map(int, input().split())) E = [list(map(int, input().split())) for k in range(M)] ans = 0 for k in range(M): F = E[:k] + E[k + 1 :] D = [[10**9 + 7 for l in range(N)] for m in range(N)] for p in range(N): D[p][p] = 0 for n in F: D[n[0] - 1][n[1] - 1] = D[n[1] - 1][n[0] - 1] = 1 for s in range(N): for t in range(N): for u in range(N): if D[t][u] > D[t][s] + D[s][u]: D[t][u] = D[t][s] + D[s][u] f = 0 for p in range(N): for q in range(N): if D[p][q] > N: f = 1 ans += f print(ans)
N, M = list(map(int, input().split())) P = [list(map(int, input().split())) for k in range(M)] ans = 0 for i in range(M): T = P[:i] + P[i + 1 :] G = [[] for k in range(N)] V = [0 for k in range(N)] for e in T: G[e[0] - 1].append(e[1] - 1) G[e[1] - 1].append(e[0] - 1) def dfs(visited, graph, ima): for e in graph[ima]: if visited[e] == 0: visited[e] = 1 dfs(visited, graph, e) dfs(V, G, 0) if sum(V) != N: ans += 1 print(ans)
false
8.695652
[ "-E = [list(map(int, input().split())) for k in range(M)]", "+P = [list(map(int, input().split())) for k in range(M)]", "-for k in range(M):", "- F = E[:k] + E[k + 1 :]", "- D = [[10**9 + 7 for l in range(N)] for m in range(N)]", "- for p in range(N):", "- D[p][p] = 0", "- for n in F:", "- D[n[0] - 1][n[1] - 1] = D[n[1] - 1][n[0] - 1] = 1", "- for s in range(N):", "- for t in range(N):", "- for u in range(N):", "- if D[t][u] > D[t][s] + D[s][u]:", "- D[t][u] = D[t][s] + D[s][u]", "- f = 0", "- for p in range(N):", "- for q in range(N):", "- if D[p][q] > N:", "- f = 1", "- ans += f", "+for i in range(M):", "+ T = P[:i] + P[i + 1 :]", "+ G = [[] for k in range(N)]", "+ V = [0 for k in range(N)]", "+ for e in T:", "+ G[e[0] - 1].append(e[1] - 1)", "+ G[e[1] - 1].append(e[0] - 1)", "+", "+ def dfs(visited, graph, ima):", "+ for e in graph[ima]:", "+ if visited[e] == 0:", "+ visited[e] = 1", "+ dfs(visited, graph, e)", "+", "+ dfs(V, G, 0)", "+ if sum(V) != N:", "+ ans += 1" ]
false
0.059369
0.035989
1.649657
[ "s044127082", "s033107759" ]
u686230543
p02713
python
s301161149
s984868175
1,103
21
9,180
9,196
Accepted
Accepted
98.1
from math import gcd k = int(eval(input())) sum_ = 0 for a in range(1, k + 1): for b in range(1, k + 1): gcd_ab = gcd(a, b) for c in range(1, k + 1): sum_ += gcd(c, gcd_ab) print(sum_)
k = int(eval(input())) count = [pow(k // max(i, 1), 3) for i in range(k + 1)] for i in range(k, 0, -1): for j in range(2 * i, k + 1, i): count[i] -= count[j] sum_ = 0 for i in range(k + 1): sum_ += i * count[i] print(sum_)
10
13
204
240
from math import gcd k = int(eval(input())) sum_ = 0 for a in range(1, k + 1): for b in range(1, k + 1): gcd_ab = gcd(a, b) for c in range(1, k + 1): sum_ += gcd(c, gcd_ab) print(sum_)
k = int(eval(input())) count = [pow(k // max(i, 1), 3) for i in range(k + 1)] for i in range(k, 0, -1): for j in range(2 * i, k + 1, i): count[i] -= count[j] sum_ = 0 for i in range(k + 1): sum_ += i * count[i] print(sum_)
false
23.076923
[ "-from math import gcd", "-", "+count = [pow(k // max(i, 1), 3) for i in range(k + 1)]", "+for i in range(k, 0, -1):", "+ for j in range(2 * i, k + 1, i):", "+ count[i] -= count[j]", "-for a in range(1, k + 1):", "- for b in range(1, k + 1):", "- gcd_ab = gcd(a, b)", "- for c in range(1, k + 1):", "- sum_ += gcd(c, gcd_ab)", "+for i in range(k + 1):", "+ sum_ += i * count[i]" ]
false
0.165642
0.045712
3.623572
[ "s301161149", "s984868175" ]
u513081876
p04031
python
s854019149
s056418850
23
18
2,940
3,060
Accepted
Accepted
21.74
N = int(eval(input())) a = sorted(map(int, input().split())) cost = 10**9 for y in range(a[0], a[-1]+1): cost = min(cost, sum([(x-y)**2 for x in a])) print(cost)
N = int(eval(input())) A = [int(i) for i in input().split()] che1 = sum(A)//N che2 = sum(A)//N + 1 ans1 = 0 ans2 = 0 for i in A: ans1 += (i-che1)**2 ans2 += (i-che2)**2 print((min(ans1, ans2)))
7
12
166
210
N = int(eval(input())) a = sorted(map(int, input().split())) cost = 10**9 for y in range(a[0], a[-1] + 1): cost = min(cost, sum([(x - y) ** 2 for x in a])) print(cost)
N = int(eval(input())) A = [int(i) for i in input().split()] che1 = sum(A) // N che2 = sum(A) // N + 1 ans1 = 0 ans2 = 0 for i in A: ans1 += (i - che1) ** 2 ans2 += (i - che2) ** 2 print((min(ans1, ans2)))
false
41.666667
[ "-a = sorted(map(int, input().split()))", "-cost = 10**9", "-for y in range(a[0], a[-1] + 1):", "- cost = min(cost, sum([(x - y) ** 2 for x in a]))", "-print(cost)", "+A = [int(i) for i in input().split()]", "+che1 = sum(A) // N", "+che2 = sum(A) // N + 1", "+ans1 = 0", "+ans2 = 0", "+for i in A:", "+ ans1 += (i - che1) ** 2", "+ ans2 += (i - che2) ** 2", "+print((min(ans1, ans2)))" ]
false
0.056746
0.036336
1.561698
[ "s854019149", "s056418850" ]
u421674761
p02695
python
s513745742
s785008063
1,967
1,181
9,024
9,108
Accepted
Accepted
39.96
import itertools n,m,q = list(map(int,input().split())) abcd = [list(map(int,input().split())) for i in range(q)] ans = 0 for iter in itertools.combinations_with_replacement(list(range(1,m+1)),n): result = 0 for i in range(q): a,b,c,d = abcd[i][0],abcd[i][1],abcd[i][2],abcd[i][3] if iter[b-1] - iter[a-1] == c: result += d ans = max(ans, result) print(ans)
import itertools n,m,q = list(map(int,input().split())) abcd = [list(map(int,input().split())) for i in range(q)] ans = 0 for A in itertools.combinations_with_replacement(list(range(1,m+1)),n): tmp = 0 for i in range(q): a,b,c,d = abcd[i] if A[b-1] - A[a-1] == c: tmp += d ans = max(tmp, ans) print(ans)
14
15
407
355
import itertools n, m, q = list(map(int, input().split())) abcd = [list(map(int, input().split())) for i in range(q)] ans = 0 for iter in itertools.combinations_with_replacement(list(range(1, m + 1)), n): result = 0 for i in range(q): a, b, c, d = abcd[i][0], abcd[i][1], abcd[i][2], abcd[i][3] if iter[b - 1] - iter[a - 1] == c: result += d ans = max(ans, result) print(ans)
import itertools n, m, q = list(map(int, input().split())) abcd = [list(map(int, input().split())) for i in range(q)] ans = 0 for A in itertools.combinations_with_replacement(list(range(1, m + 1)), n): tmp = 0 for i in range(q): a, b, c, d = abcd[i] if A[b - 1] - A[a - 1] == c: tmp += d ans = max(tmp, ans) print(ans)
false
6.666667
[ "-for iter in itertools.combinations_with_replacement(list(range(1, m + 1)), n):", "- result = 0", "+for A in itertools.combinations_with_replacement(list(range(1, m + 1)), n):", "+ tmp = 0", "- a, b, c, d = abcd[i][0], abcd[i][1], abcd[i][2], abcd[i][3]", "- if iter[b - 1] - iter[a - 1] == c:", "- result += d", "- ans = max(ans, result)", "+ a, b, c, d = abcd[i]", "+ if A[b - 1] - A[a - 1] == c:", "+ tmp += d", "+ ans = max(tmp, ans)" ]
false
0.059853
0.047533
1.259195
[ "s513745742", "s785008063" ]
u285891772
p03785
python
s697111746
s339700277
261
176
9,564
9,584
Accepted
Accepted
32.57
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce from decimal import Decimal 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(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 from decimal import * N, C, K = MAP() T = [INT() for _ in range(N)] T.sort() idx = 0 ans = 0 while idx < N : tmp = T[idx] if idx+C <= bisect(T, tmp+K): idx += C else: idx = bisect(T, tmp+K) ans += 1 print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce from decimal import Decimal 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(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10**9 + 7 from decimal import * N, C, K = MAP() T = [INT() for _ in range(N)] T.sort() ans = 1 cnt = 1 t_limit = T[0] + K for i in range(1, N): if cnt == C: #人数上限 t_limit = T[i] + K cnt = 1 ans += 1 elif T[i] <= t_limit: #乗れる cnt += 1 else: #待ち時間上限 t_limit = T[i] + K cnt = 1 ans += 1 print(ans)
38
43
1,142
1,244
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, ) # , log2, log from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce from decimal import Decimal 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(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 from decimal import * N, C, K = MAP() T = [INT() for _ in range(N)] T.sort() idx = 0 ans = 0 while idx < N: tmp = T[idx] if idx + C <= bisect(T, tmp + K): idx += C else: idx = bisect(T, tmp + K) ans += 1 print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, ) # , log2, log from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce from decimal import Decimal 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(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 from decimal import * N, C, K = MAP() T = [INT() for _ in range(N)] T.sort() ans = 1 cnt = 1 t_limit = T[0] + K for i in range(1, N): if cnt == C: # 人数上限 t_limit = T[i] + K cnt = 1 ans += 1 elif T[i] <= t_limit: # 乗れる cnt += 1 else: # 待ち時間上限 t_limit = T[i] + K cnt = 1 ans += 1 print(ans)
false
11.627907
[ "-idx = 0", "-ans = 0", "-while idx < N:", "- tmp = T[idx]", "- if idx + C <= bisect(T, tmp + K):", "- idx += C", "- else:", "- idx = bisect(T, tmp + K)", "- ans += 1", "+ans = 1", "+cnt = 1", "+t_limit = T[0] + K", "+for i in range(1, N):", "+ if cnt == C: # 人数上限", "+ t_limit = T[i] + K", "+ cnt = 1", "+ ans += 1", "+ elif T[i] <= t_limit: # 乗れる", "+ cnt += 1", "+ else: # 待ち時間上限", "+ t_limit = T[i] + K", "+ cnt = 1", "+ ans += 1" ]
false
0.038942
0.03836
1.015177
[ "s697111746", "s339700277" ]
u699089116
p03721
python
s736562396
s270218218
597
216
53,720
11,640
Accepted
Accepted
63.82
from collections import Counter n, k = list(map(int, input().split())) c = Counter() for _ in range(n): a, b = list(map(int, input().split())) c[a] += b c = sorted(list(c.items()), key=lambda x: x[0]) for i, v in c: k -= v if k <= 0: print(i) exit()
N, K = list(map(int, input().split())) bucket = [0] * (10 ** 5 + 1) for _ in range(N): a, b = list(map(int, input().split())) bucket[a] += b cnt = 0 for i, c in enumerate(bucket): if c == 0: continue cnt += c if cnt >= K: print(i) exit()
14
15
278
285
from collections import Counter n, k = list(map(int, input().split())) c = Counter() for _ in range(n): a, b = list(map(int, input().split())) c[a] += b c = sorted(list(c.items()), key=lambda x: x[0]) for i, v in c: k -= v if k <= 0: print(i) exit()
N, K = list(map(int, input().split())) bucket = [0] * (10**5 + 1) for _ in range(N): a, b = list(map(int, input().split())) bucket[a] += b cnt = 0 for i, c in enumerate(bucket): if c == 0: continue cnt += c if cnt >= K: print(i) exit()
false
6.666667
[ "-from collections import Counter", "-", "-n, k = list(map(int, input().split()))", "-c = Counter()", "-for _ in range(n):", "+N, K = list(map(int, input().split()))", "+bucket = [0] * (10**5 + 1)", "+for _ in range(N):", "- c[a] += b", "-c = sorted(list(c.items()), key=lambda x: x[0])", "-for i, v in c:", "- k -= v", "- if k <= 0:", "+ bucket[a] += b", "+cnt = 0", "+for i, c in enumerate(bucket):", "+ if c == 0:", "+ continue", "+ cnt += c", "+ if cnt >= K:" ]
false
0.044159
0.046073
0.958463
[ "s736562396", "s270218218" ]
u624475441
p03633
python
s618568787
s049415945
38
35
5,304
5,048
Accepted
Accepted
7.89
import fractions import functools lcm=lambda x,y:x*y//fractions.gcd(x,y) print((functools.reduce(lcm,[int(eval(input()))for _ in[0]*int(eval(input()))])))
from fractions import gcd l=1 for _ in[0]*int(eval(input())): t=int(eval(input())) l=l*t//gcd(l,t) print(l)
4
6
143
108
import fractions import functools lcm = lambda x, y: x * y // fractions.gcd(x, y) print((functools.reduce(lcm, [int(eval(input())) for _ in [0] * int(eval(input()))])))
from fractions import gcd l = 1 for _ in [0] * int(eval(input())): t = int(eval(input())) l = l * t // gcd(l, t) print(l)
false
33.333333
[ "-import fractions", "-import functools", "+from fractions import gcd", "-lcm = lambda x, y: x * y // fractions.gcd(x, y)", "-print((functools.reduce(lcm, [int(eval(input())) for _ in [0] * int(eval(input()))])))", "+l = 1", "+for _ in [0] * int(eval(input())):", "+ t = int(eval(input()))", "+ l = l * t // gcd(l, t)", "+print(l)" ]
false
0.079626
0.171873
0.463287
[ "s618568787", "s049415945" ]
u133936772
p02916
python
s342744973
s253541113
19
17
3,060
3,060
Accepted
Accepted
10.53
f=lambda:list(map(int,input().split())) n=int(eval(input())) a,b,c=f(),f(),f() print((sum(b)+sum(c[a[i]-1] for i in range(n-1) if a[i+1]-a[i]==1)))
f=lambda:list(map(int,input().split())) n,a,b,c=f()[0],f(),f(),f() print((sum(b)+sum(c[a[i]-1] for i in range(n-1) if a[i+1]-a[i]==1)))
4
3
142
135
f = lambda: list(map(int, input().split())) n = int(eval(input())) a, b, c = f(), f(), f() print((sum(b) + sum(c[a[i] - 1] for i in range(n - 1) if a[i + 1] - a[i] == 1)))
f = lambda: list(map(int, input().split())) n, a, b, c = f()[0], f(), f(), f() print((sum(b) + sum(c[a[i] - 1] for i in range(n - 1) if a[i + 1] - a[i] == 1)))
false
25
[ "-n = int(eval(input()))", "-a, b, c = f(), f(), f()", "+n, a, b, c = f()[0], f(), f(), f()" ]
false
0.040143
0.041771
0.961037
[ "s342744973", "s253541113" ]
u970348538
p02573
python
s152871322
s284657698
1,227
1,043
291,236
291,436
Accepted
Accepted
15
import sys sys.setrecursionlimit(int(1e6)) def search(x, num): nodes.remove(x) for y in edge[x]: edge[y].discard(x) for y in list(edge[x]): if y in nodes: num = search(y, num) return num + 1 (n,m),*d = [list(map(int, s.split())) for s in open(0)] edge = [set() for _ in range(n+1)] for x in d: edge[x[0]].add(x[1]) edge[x[1]].add(x[0]) nodes = set(range(1,n+1)) ans = 1 for x in list(nodes): if x in nodes: ans = max(ans, search(x, 0)) print(ans)
import sys sys.setrecursionlimit(int(1e6)) def search(x, num): nodes.remove(x) # for y in edge[x]: for y in list(edge[x]): edge[y].remove(x) if y in nodes: num = search(y, num) return num + 1 (n,m),*d = [list(map(int, s.split())) for s in open(0)] edge = [set() for _ in range(n+1)] for x in d: edge[x[0]].add(x[1]) edge[x[1]].add(x[0]) nodes = set(range(1,n+1)) ans = 1 for x in list(nodes): if x in nodes: ans = max(ans, search(x, 0)) print(ans)
25
25
539
540
import sys sys.setrecursionlimit(int(1e6)) def search(x, num): nodes.remove(x) for y in edge[x]: edge[y].discard(x) for y in list(edge[x]): if y in nodes: num = search(y, num) return num + 1 (n, m), *d = [list(map(int, s.split())) for s in open(0)] edge = [set() for _ in range(n + 1)] for x in d: edge[x[0]].add(x[1]) edge[x[1]].add(x[0]) nodes = set(range(1, n + 1)) ans = 1 for x in list(nodes): if x in nodes: ans = max(ans, search(x, 0)) print(ans)
import sys sys.setrecursionlimit(int(1e6)) def search(x, num): nodes.remove(x) # for y in edge[x]: for y in list(edge[x]): edge[y].remove(x) if y in nodes: num = search(y, num) return num + 1 (n, m), *d = [list(map(int, s.split())) for s in open(0)] edge = [set() for _ in range(n + 1)] for x in d: edge[x[0]].add(x[1]) edge[x[1]].add(x[0]) nodes = set(range(1, n + 1)) ans = 1 for x in list(nodes): if x in nodes: ans = max(ans, search(x, 0)) print(ans)
false
0
[ "- for y in edge[x]:", "- edge[y].discard(x)", "+ # for y in edge[x]:", "+ edge[y].remove(x)" ]
false
0.060048
0.056038
1.07156
[ "s152871322", "s284657698" ]
u226155577
p03602
python
s106383086
s979134799
891
510
48,092
44,380
Accepted
Accepted
42.76
n = int(eval(input())) A = [list(map(int, input().split())) for i in range(n)] B = [e[:] for e in A] for k in range(n): for i in range(n): for j in range(n): B[i][j] = min(B[i][k] + B[k][j], B[i][j]) ok = 1 for i in range(n): for j in range(n): if A[i][j] != B[i][j]: ok = 0 if not ok: print((-1)) exit(0) ans = 0 for i in range(n): for j in range(i+1, n): need = 1 for k in range(n): if i == k or j == k: continue if A[i][k] + A[k][j] == A[i][j]: need = 0 if need: ans += A[i][j] print(ans)
n = int(eval(input())) A = [list(map(int, input().split())) for i in range(n)] ans = 0; ok = 1 for i in range(n): for j in range(i+1, n): cost = A[i][j] for k in range(n): if i == k or j == k: continue if A[i][k] + A[k][j] < A[i][j]: ok = 0 elif A[i][k] + A[k][j] == A[i][j]: cost = 0 ans += cost print((ans if ok else -1))
29
16
666
443
n = int(eval(input())) A = [list(map(int, input().split())) for i in range(n)] B = [e[:] for e in A] for k in range(n): for i in range(n): for j in range(n): B[i][j] = min(B[i][k] + B[k][j], B[i][j]) ok = 1 for i in range(n): for j in range(n): if A[i][j] != B[i][j]: ok = 0 if not ok: print((-1)) exit(0) ans = 0 for i in range(n): for j in range(i + 1, n): need = 1 for k in range(n): if i == k or j == k: continue if A[i][k] + A[k][j] == A[i][j]: need = 0 if need: ans += A[i][j] print(ans)
n = int(eval(input())) A = [list(map(int, input().split())) for i in range(n)] ans = 0 ok = 1 for i in range(n): for j in range(i + 1, n): cost = A[i][j] for k in range(n): if i == k or j == k: continue if A[i][k] + A[k][j] < A[i][j]: ok = 0 elif A[i][k] + A[k][j] == A[i][j]: cost = 0 ans += cost print((ans if ok else -1))
false
44.827586
[ "-B = [e[:] for e in A]", "-for k in range(n):", "- for i in range(n):", "- for j in range(n):", "- B[i][j] = min(B[i][k] + B[k][j], B[i][j])", "+ans = 0", "- for j in range(n):", "- if A[i][j] != B[i][j]:", "- ok = 0", "-if not ok:", "- print((-1))", "- exit(0)", "-ans = 0", "-for i in range(n):", "- need = 1", "+ cost = A[i][j]", "- if A[i][k] + A[k][j] == A[i][j]:", "- need = 0", "- if need:", "- ans += A[i][j]", "-print(ans)", "+ if A[i][k] + A[k][j] < A[i][j]:", "+ ok = 0", "+ elif A[i][k] + A[k][j] == A[i][j]:", "+ cost = 0", "+ ans += cost", "+print((ans if ok else -1))" ]
false
0.132256
0.105574
1.252726
[ "s106383086", "s979134799" ]
u693378622
p02685
python
s459165807
s896527742
434
105
32,680
112,668
Accepted
Accepted
75.81
class Facts: def __init__(self, mod=10**9+7, n_max=1): self.mod = mod self.n_max = n_max self.fact = [1, 1] self.inv = [0, 1] self.factinv = [1, 1] if 1 < n_max: setup_table(n_max) def cmb(self, n, r): if r < 0 or n < r: return 0 if self.n_max < n: self.setup_table(n) return self.fact[n] * (self.factinv[r] * self.factinv[n-r] % self.mod) % self.mod def setup_table(self, t): for i in range(self.n_max+1,t+1): self.fact.append( self.fact[-1] * i % self.mod ) self.inv.append( -self.inv[mod % i] * (self.mod // i) % self.mod ) self.factinv.append( self.factinv[-1] * self.inv[-1] % self.mod ) self.n_max = t mod = 998244353 n, m, k = list(map(int, input().split())) ans = 0 f = Facts(mod) t = m * pow(m-1, n-1-k, mod) for i in range(k,-1,-1): ans += f.cmb(n-1,i) * t % mod t = t * (m-1) % mod print((ans % mod))
class Facts: def __init__(self, mod=10**9+7, n_max=1): self.mod = mod self.n_max = n_max self.fact = [1, 1] self.inv = [0, 1] self.factinv = [1, 1] if 1 < n_max: self.setup_table(n_max) def cmb(self, n, r): if r < 0 or n < r: return 0 if self.n_max < n: self.setup_table(n) return self.fact[n] * (self.factinv[r] * self.factinv[n-r] % self.mod) % self.mod def setup_table(self, t): for i in range(self.n_max+1,t+1): self.fact.append( self.fact[-1] * i % self.mod ) self.inv.append( -self.inv[mod % i] * (self.mod // i) % self.mod ) self.factinv.append( self.factinv[-1] * self.inv[-1] % self.mod ) self.n_max = t # ABC167 E 2020/5/11 mod = 998244353 n, m, k = list(map(int, input().split())) ans = 0 f = Facts(mod) t = m * pow(m-1, n-1-k, mod) for i in range(k,-1,-1): ans += f.cmb(n-1,i) * t % mod t = t * (m-1) % mod print((ans % mod))
38
39
958
979
class Facts: def __init__(self, mod=10**9 + 7, n_max=1): self.mod = mod self.n_max = n_max self.fact = [1, 1] self.inv = [0, 1] self.factinv = [1, 1] if 1 < n_max: setup_table(n_max) def cmb(self, n, r): if r < 0 or n < r: return 0 if self.n_max < n: self.setup_table(n) return ( self.fact[n] * (self.factinv[r] * self.factinv[n - r] % self.mod) % self.mod ) def setup_table(self, t): for i in range(self.n_max + 1, t + 1): self.fact.append(self.fact[-1] * i % self.mod) self.inv.append(-self.inv[mod % i] * (self.mod // i) % self.mod) self.factinv.append(self.factinv[-1] * self.inv[-1] % self.mod) self.n_max = t mod = 998244353 n, m, k = list(map(int, input().split())) ans = 0 f = Facts(mod) t = m * pow(m - 1, n - 1 - k, mod) for i in range(k, -1, -1): ans += f.cmb(n - 1, i) * t % mod t = t * (m - 1) % mod print((ans % mod))
class Facts: def __init__(self, mod=10**9 + 7, n_max=1): self.mod = mod self.n_max = n_max self.fact = [1, 1] self.inv = [0, 1] self.factinv = [1, 1] if 1 < n_max: self.setup_table(n_max) def cmb(self, n, r): if r < 0 or n < r: return 0 if self.n_max < n: self.setup_table(n) return ( self.fact[n] * (self.factinv[r] * self.factinv[n - r] % self.mod) % self.mod ) def setup_table(self, t): for i in range(self.n_max + 1, t + 1): self.fact.append(self.fact[-1] * i % self.mod) self.inv.append(-self.inv[mod % i] * (self.mod // i) % self.mod) self.factinv.append(self.factinv[-1] * self.inv[-1] % self.mod) self.n_max = t # ABC167 E 2020/5/11 mod = 998244353 n, m, k = list(map(int, input().split())) ans = 0 f = Facts(mod) t = m * pow(m - 1, n - 1 - k, mod) for i in range(k, -1, -1): ans += f.cmb(n - 1, i) * t % mod t = t * (m - 1) % mod print((ans % mod))
false
2.564103
[ "- setup_table(n_max)", "+ self.setup_table(n_max)", "+# ABC167 E 2020/5/11" ]
false
0.25742
0.234991
1.095448
[ "s459165807", "s896527742" ]
u071269360
p03478
python
s388375071
s048968187
50
46
9,420
9,624
Accepted
Accepted
8
from functools import reduce n,a,b = [int(x) for x in input().split(" ")] ans = 0 for ni in range(a,n+1): if ni <= 9 : if a <= ni and ni <= b: ans += ni else: add_each_dig = reduce(lambda x, y: int(x) + int(y), str(ni) ) if a <= add_each_dig and add_each_dig <= b: ans += ni print(ans)
from functools import reduce n,a,b = [int(x) for x in input().split(" ")] ans = 0 for ni in range(a,n+1): add_each_dig = int(reduce(lambda x, y: int(x) + int(y), str(ni) )) if a <= add_each_dig and add_each_dig <= b: ans += ni print(ans)
15
11
361
269
from functools import reduce n, a, b = [int(x) for x in input().split(" ")] ans = 0 for ni in range(a, n + 1): if ni <= 9: if a <= ni and ni <= b: ans += ni else: add_each_dig = reduce(lambda x, y: int(x) + int(y), str(ni)) if a <= add_each_dig and add_each_dig <= b: ans += ni print(ans)
from functools import reduce n, a, b = [int(x) for x in input().split(" ")] ans = 0 for ni in range(a, n + 1): add_each_dig = int(reduce(lambda x, y: int(x) + int(y), str(ni))) if a <= add_each_dig and add_each_dig <= b: ans += ni print(ans)
false
26.666667
[ "- if ni <= 9:", "- if a <= ni and ni <= b:", "- ans += ni", "- else:", "- add_each_dig = reduce(lambda x, y: int(x) + int(y), str(ni))", "- if a <= add_each_dig and add_each_dig <= b:", "- ans += ni", "+ add_each_dig = int(reduce(lambda x, y: int(x) + int(y), str(ni)))", "+ if a <= add_each_dig and add_each_dig <= b:", "+ ans += ni" ]
false
0.071831
0.042196
1.702309
[ "s388375071", "s048968187" ]
u554096168
p02683
python
s709706594
s134861809
149
40
27,300
9,204
Accepted
Accepted
73.15
import numpy as np N, M, X = list(map(int, input().split())) C = [0]*N A = np.zeros((N, M), int) for i in range(N): C[i], *A[i] = list(map(int, input().split())) ans = 12345678 for bit in range(1, 2**N): c = [C[i] for i in range(N) if bit & (1 << i)] a = [A[i] for i in range(N) if bit & (1 << i)] a = np.array(a) if all(a.sum(0) >= X): ans = min(ans, sum(c)) print((-1 if ans == 12345678 else ans))
(N, M, X), *T = [[*list(map(int, line.split()))] for line in open(0)] ans = 12345678 for bit in range(1, 2**N): t = [T[i] for i in range(N) if bit & (1 << i)] c, *a = list(map(sum, list(zip(*t)))) if all(e >= X for e in a): ans = min(ans, c) print((-1 if ans == 12345678 else ans))
19
10
437
293
import numpy as np N, M, X = list(map(int, input().split())) C = [0] * N A = np.zeros((N, M), int) for i in range(N): C[i], *A[i] = list(map(int, input().split())) ans = 12345678 for bit in range(1, 2**N): c = [C[i] for i in range(N) if bit & (1 << i)] a = [A[i] for i in range(N) if bit & (1 << i)] a = np.array(a) if all(a.sum(0) >= X): ans = min(ans, sum(c)) print((-1 if ans == 12345678 else ans))
(N, M, X), *T = [[*list(map(int, line.split()))] for line in open(0)] ans = 12345678 for bit in range(1, 2**N): t = [T[i] for i in range(N) if bit & (1 << i)] c, *a = list(map(sum, list(zip(*t)))) if all(e >= X for e in a): ans = min(ans, c) print((-1 if ans == 12345678 else ans))
false
47.368421
[ "-import numpy as np", "-", "-N, M, X = list(map(int, input().split()))", "-C = [0] * N", "-A = np.zeros((N, M), int)", "-for i in range(N):", "- C[i], *A[i] = list(map(int, input().split()))", "+(N, M, X), *T = [[*list(map(int, line.split()))] for line in open(0)]", "- c = [C[i] for i in range(N) if bit & (1 << i)]", "- a = [A[i] for i in range(N) if bit & (1 << i)]", "- a = np.array(a)", "- if all(a.sum(0) >= X):", "- ans = min(ans, sum(c))", "+ t = [T[i] for i in range(N) if bit & (1 << i)]", "+ c, *a = list(map(sum, list(zip(*t))))", "+ if all(e >= X for e in a):", "+ ans = min(ans, c)" ]
false
0.307534
0.129084
2.382433
[ "s709706594", "s134861809" ]
u556069480
p02735
python
s514114301
s895782578
92
46
6,120
3,316
Accepted
Accepted
50
import itertools H,W=list(map(int, input().split())) garden=[] for i in range(H): garden.append(list(input().replace(".","1").replace("#","0"))) #print(garden) dct=[(1,0),(0,1),(-1,0),(0,-1)] #garden=[[1,0,1,0,1],[0,1,0,1,0],[1,0,1,0,1],[0,1,0,1,0],[1,0,1,0,1]] #H,W=5,5 start=(0,0) goal=(H-1,W-1) path=[start] d=[ [i+j for i in range(W)] for j in range(H)] #print(d) done=[(0,0)] for i, j in itertools.product(list(range(H)),list(range(W))): color=garden[i][j] for each in dct: di,dj=each[0],each[1] if i+di<H and j+dj< W and i+di>=0 and j+dj>=0 and garden[i+di][j+dj]==color: d[i+di][j+dj]=min(d[i+di][j+dj],d[i][j]) done.append((i+di,j+dj)) #print((i,j),(i+di,j+dj)) #print("same") elif i+di<H and j+dj< W and i+di>=0 and j+dj>=0 : d[i+di][j+dj]=min(d[i+di][j+dj],d[i][j]+1) done.append((i+di,j+dj)) #print((i,j),(i+di,j+dj)) #print("not same") #print(d) if int(garden[0][0])+int(garden[H-1][W-1])==0: print((int((d[H-1][W-1]+1)/2)+1)) else: print((int((d[H-1][W-1]+1)/2)))
import itertools H,W=list(map(int, input().split())) garden=[] for i in range(H): garden.append(list(input().replace(".","1").replace("#","0"))) dct=[(1,0),(0,1)] d=[ [i+j for i in range(W)] for j in range(H)] for i, j in itertools.product(list(range(H)),list(range(W))): color=garden[i][j] for each in dct: di,dj=each[0],each[1] if i+di<H and j+dj< W and garden[i+di][j+dj]==color: d[i+di][j+dj]=min(d[i+di][j+dj],d[i][j]) elif i+di<H and j+dj< W: d[i+di][j+dj]=min(d[i+di][j+dj],d[i][j]+1) if int(garden[0][0])+int(garden[H-1][W-1])==0: print((int((d[H-1][W-1]+1)/2)+1)) else: print((int((d[H-1][W-1]+1)/2)))
37
25
1,134
686
import itertools H, W = list(map(int, input().split())) garden = [] for i in range(H): garden.append(list(input().replace(".", "1").replace("#", "0"))) # print(garden) dct = [(1, 0), (0, 1), (-1, 0), (0, -1)] # garden=[[1,0,1,0,1],[0,1,0,1,0],[1,0,1,0,1],[0,1,0,1,0],[1,0,1,0,1]] # H,W=5,5 start = (0, 0) goal = (H - 1, W - 1) path = [start] d = [[i + j for i in range(W)] for j in range(H)] # print(d) done = [(0, 0)] for i, j in itertools.product(list(range(H)), list(range(W))): color = garden[i][j] for each in dct: di, dj = each[0], each[1] if ( i + di < H and j + dj < W and i + di >= 0 and j + dj >= 0 and garden[i + di][j + dj] == color ): d[i + di][j + dj] = min(d[i + di][j + dj], d[i][j]) done.append((i + di, j + dj)) # print((i,j),(i+di,j+dj)) # print("same") elif i + di < H and j + dj < W and i + di >= 0 and j + dj >= 0: d[i + di][j + dj] = min(d[i + di][j + dj], d[i][j] + 1) done.append((i + di, j + dj)) # print((i,j),(i+di,j+dj)) # print("not same") # print(d) if int(garden[0][0]) + int(garden[H - 1][W - 1]) == 0: print((int((d[H - 1][W - 1] + 1) / 2) + 1)) else: print((int((d[H - 1][W - 1] + 1) / 2)))
import itertools H, W = list(map(int, input().split())) garden = [] for i in range(H): garden.append(list(input().replace(".", "1").replace("#", "0"))) dct = [(1, 0), (0, 1)] d = [[i + j for i in range(W)] for j in range(H)] for i, j in itertools.product(list(range(H)), list(range(W))): color = garden[i][j] for each in dct: di, dj = each[0], each[1] if i + di < H and j + dj < W and garden[i + di][j + dj] == color: d[i + di][j + dj] = min(d[i + di][j + dj], d[i][j]) elif i + di < H and j + dj < W: d[i + di][j + dj] = min(d[i + di][j + dj], d[i][j] + 1) if int(garden[0][0]) + int(garden[H - 1][W - 1]) == 0: print((int((d[H - 1][W - 1] + 1) / 2) + 1)) else: print((int((d[H - 1][W - 1] + 1) / 2)))
false
32.432432
[ "-# print(garden)", "-dct = [(1, 0), (0, 1), (-1, 0), (0, -1)]", "-# garden=[[1,0,1,0,1],[0,1,0,1,0],[1,0,1,0,1],[0,1,0,1,0],[1,0,1,0,1]]", "-# H,W=5,5", "-start = (0, 0)", "-goal = (H - 1, W - 1)", "-path = [start]", "+dct = [(1, 0), (0, 1)]", "-# print(d)", "-done = [(0, 0)]", "- if (", "- i + di < H", "- and j + dj < W", "- and i + di >= 0", "- and j + dj >= 0", "- and garden[i + di][j + dj] == color", "- ):", "+ if i + di < H and j + dj < W and garden[i + di][j + dj] == color:", "- done.append((i + di, j + dj))", "- # print((i,j),(i+di,j+dj))", "- # print(\"same\")", "- elif i + di < H and j + dj < W and i + di >= 0 and j + dj >= 0:", "+ elif i + di < H and j + dj < W:", "- done.append((i + di, j + dj))", "- # print((i,j),(i+di,j+dj))", "- # print(\"not same\")", "- # print(d)" ]
false
0.036176
0.037232
0.971638
[ "s514114301", "s895782578" ]
u340781749
p02793
python
s118153609
s236084692
1,560
966
4,580
6,112
Accepted
Accepted
38.08
def prime_factorize(n): i = 2 res = {} while i * i <= n: if n % i != 0: i += 1 continue res[i] = 0 while n % i == 0: res[i] += 1 n //= i i += 1 if n != 1: res[n] = 1 return res n = int(eval(input())) aaa = list(map(int, input().split())) MOD = 10 ** 9 + 7 lcm_ppf = prime_factorize(aaa[0]) for a in aaa[1:]: for p, c in list(prime_factorize(a).items()): if p in lcm_ppf: lcm_ppf[p] = max(lcm_ppf[p], c) else: lcm_ppf[p] = c lcm = 1 for p, c in list(lcm_ppf.items()): lcm = lcm * pow(p, c, MOD) % MOD # print(lcm) ans = 0 for a in aaa: ra = pow(a, MOD - 2, MOD) ans = (ans + lcm * ra) % MOD print(ans)
from fractions import gcd n = int(eval(input())) aaa = list(map(int, input().split())) MOD = 10 ** 9 + 7 lcm = aaa[0] for a in aaa[1:]: lcm = lcm * a // gcd(lcm, a) lcm %= MOD ans = 0 for a in aaa: ans = (ans + lcm * pow(a, MOD - 2, MOD)) % MOD print(ans)
38
14
788
273
def prime_factorize(n): i = 2 res = {} while i * i <= n: if n % i != 0: i += 1 continue res[i] = 0 while n % i == 0: res[i] += 1 n //= i i += 1 if n != 1: res[n] = 1 return res n = int(eval(input())) aaa = list(map(int, input().split())) MOD = 10**9 + 7 lcm_ppf = prime_factorize(aaa[0]) for a in aaa[1:]: for p, c in list(prime_factorize(a).items()): if p in lcm_ppf: lcm_ppf[p] = max(lcm_ppf[p], c) else: lcm_ppf[p] = c lcm = 1 for p, c in list(lcm_ppf.items()): lcm = lcm * pow(p, c, MOD) % MOD # print(lcm) ans = 0 for a in aaa: ra = pow(a, MOD - 2, MOD) ans = (ans + lcm * ra) % MOD print(ans)
from fractions import gcd n = int(eval(input())) aaa = list(map(int, input().split())) MOD = 10**9 + 7 lcm = aaa[0] for a in aaa[1:]: lcm = lcm * a // gcd(lcm, a) lcm %= MOD ans = 0 for a in aaa: ans = (ans + lcm * pow(a, MOD - 2, MOD)) % MOD print(ans)
false
63.157895
[ "-def prime_factorize(n):", "- i = 2", "- res = {}", "- while i * i <= n:", "- if n % i != 0:", "- i += 1", "- continue", "- res[i] = 0", "- while n % i == 0:", "- res[i] += 1", "- n //= i", "- i += 1", "- if n != 1:", "- res[n] = 1", "- return res", "-", "+from fractions import gcd", "-lcm_ppf = prime_factorize(aaa[0])", "+lcm = aaa[0]", "- for p, c in list(prime_factorize(a).items()):", "- if p in lcm_ppf:", "- lcm_ppf[p] = max(lcm_ppf[p], c)", "- else:", "- lcm_ppf[p] = c", "-lcm = 1", "-for p, c in list(lcm_ppf.items()):", "- lcm = lcm * pow(p, c, MOD) % MOD", "-# print(lcm)", "+ lcm = lcm * a // gcd(lcm, a)", "+lcm %= MOD", "- ra = pow(a, MOD - 2, MOD)", "- ans = (ans + lcm * ra) % MOD", "+ ans = (ans + lcm * pow(a, MOD - 2, MOD)) % MOD" ]
false
0.038355
0.060152
0.637626
[ "s118153609", "s236084692" ]
u669284080
p02242
python
s552636900
s510054992
190
30
7,900
8,516
Accepted
Accepted
84.21
#!/usr/bin/python3 n = int(eval(input())) inf = 100 * 100000 M = [[inf for i in range(n)] for j in range(n)] for i in range(n): L = list(map(int, input().split())) u = L[0] k = L[1] v = L[2::2] c = L[3::2] for j in range(k): M[u][v[j]] = c[j] S = set() V = set(range(n)) S.add(0) d = [inf for i in range(n)] d[0] = 0 count = 0 while len(V - S) != 0: T = V - S nd = [inf for i in range(n)] for s in S: for m, c in enumerate(M[s]): if d[s] + c < nd[m] and m in T: nd[m] = d[s] + c min_nd = min(nd) u = nd.index(min_nd) S.add(u) d[u] = min_nd for i, v in enumerate(d): print((i, v))
#!/usr/bin/python3 from heapq import heappop, heappush n = int(eval(input())) inf = 100 * 100000 M = [[] for i in range(n)] for i in range(n): L = list(map(int, input().split())) u = L[0] k = L[1] v = L[2::2] c = L[3::2] for j in range(k): M[u].append((v[j], c[j])) result = [0] * n S = set() V = set(range(n)) S.add(0) d = [] for m in M[0]: heappush(d, (m[1], m[0])) T = V - S while len(T) != 0: c, v = heappop(d) while v in S: c, v = heappop(d) result[v] = c S.add(v) T.remove(v) for m in M[v]: if m[0] in T: heappush(d, (result[v] + m[1], m[0])) for i, v in enumerate(result): print((i, v))
37
37
713
717
#!/usr/bin/python3 n = int(eval(input())) inf = 100 * 100000 M = [[inf for i in range(n)] for j in range(n)] for i in range(n): L = list(map(int, input().split())) u = L[0] k = L[1] v = L[2::2] c = L[3::2] for j in range(k): M[u][v[j]] = c[j] S = set() V = set(range(n)) S.add(0) d = [inf for i in range(n)] d[0] = 0 count = 0 while len(V - S) != 0: T = V - S nd = [inf for i in range(n)] for s in S: for m, c in enumerate(M[s]): if d[s] + c < nd[m] and m in T: nd[m] = d[s] + c min_nd = min(nd) u = nd.index(min_nd) S.add(u) d[u] = min_nd for i, v in enumerate(d): print((i, v))
#!/usr/bin/python3 from heapq import heappop, heappush n = int(eval(input())) inf = 100 * 100000 M = [[] for i in range(n)] for i in range(n): L = list(map(int, input().split())) u = L[0] k = L[1] v = L[2::2] c = L[3::2] for j in range(k): M[u].append((v[j], c[j])) result = [0] * n S = set() V = set(range(n)) S.add(0) d = [] for m in M[0]: heappush(d, (m[1], m[0])) T = V - S while len(T) != 0: c, v = heappop(d) while v in S: c, v = heappop(d) result[v] = c S.add(v) T.remove(v) for m in M[v]: if m[0] in T: heappush(d, (result[v] + m[1], m[0])) for i, v in enumerate(result): print((i, v))
false
0
[ "+from heapq import heappop, heappush", "+", "-M = [[inf for i in range(n)] for j in range(n)]", "+M = [[] for i in range(n)]", "- M[u][v[j]] = c[j]", "+ M[u].append((v[j], c[j]))", "+result = [0] * n", "-d = [inf for i in range(n)]", "-d[0] = 0", "-count = 0", "-while len(V - S) != 0:", "- T = V - S", "- nd = [inf for i in range(n)]", "- for s in S:", "- for m, c in enumerate(M[s]):", "- if d[s] + c < nd[m] and m in T:", "- nd[m] = d[s] + c", "- min_nd = min(nd)", "- u = nd.index(min_nd)", "- S.add(u)", "- d[u] = min_nd", "-for i, v in enumerate(d):", "+d = []", "+for m in M[0]:", "+ heappush(d, (m[1], m[0]))", "+T = V - S", "+while len(T) != 0:", "+ c, v = heappop(d)", "+ while v in S:", "+ c, v = heappop(d)", "+ result[v] = c", "+ S.add(v)", "+ T.remove(v)", "+ for m in M[v]:", "+ if m[0] in T:", "+ heappush(d, (result[v] + m[1], m[0]))", "+for i, v in enumerate(result):" ]
false
0.037394
0.03883
0.963005
[ "s552636900", "s510054992" ]
u883048396
p03240
python
s760934057
s144784473
733
33
3,064
3,064
Accepted
Accepted
95.5
import sys iN = int(eval(input())) aData = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()] aData.sort(key=lambda x:x[2],reverse=True) for cx in range(0,101) : for cy in range(0,101) : aH = [] uH = False bF = True for x,y,z in aData : d = abs(x-cx)+abs(y-cy) if z > 0 : aH.append( z + d ) else : if aH[0] > d: bF = False if uH : uH = min(uH,d) else : uH = d for i in range(1,len(aH)) : if aH[0] != aH[i] : bF = False if uH : if uH < aH[0] : bF = False if bF : print((cx,cy,aH[0])) exit()
import sys iN = int(eval(input())) aData = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()] aData.sort(key=lambda x:x[2],reverse=True) for cx in range(0,101) : for cy in range(0,101) : h = 0 bF = True for x,y,z in aData : d = abs(x-cx)+abs(y-cy) if z > 0 : if h == 0 : h = z + d else : if h != z + d: bF = False break else : if h > d: bF = False break if bF : print((cx,cy,h)) exit()
30
25
830
693
import sys iN = int(eval(input())) aData = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()] aData.sort(key=lambda x: x[2], reverse=True) for cx in range(0, 101): for cy in range(0, 101): aH = [] uH = False bF = True for x, y, z in aData: d = abs(x - cx) + abs(y - cy) if z > 0: aH.append(z + d) else: if aH[0] > d: bF = False if uH: uH = min(uH, d) else: uH = d for i in range(1, len(aH)): if aH[0] != aH[i]: bF = False if uH: if uH < aH[0]: bF = False if bF: print((cx, cy, aH[0])) exit()
import sys iN = int(eval(input())) aData = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()] aData.sort(key=lambda x: x[2], reverse=True) for cx in range(0, 101): for cy in range(0, 101): h = 0 bF = True for x, y, z in aData: d = abs(x - cx) + abs(y - cy) if z > 0: if h == 0: h = z + d else: if h != z + d: bF = False break else: if h > d: bF = False break if bF: print((cx, cy, h)) exit()
false
16.666667
[ "- aH = []", "- uH = False", "+ h = 0", "- aH.append(z + d)", "+ if h == 0:", "+ h = z + d", "+ else:", "+ if h != z + d:", "+ bF = False", "+ break", "- if aH[0] > d:", "+ if h > d:", "- if uH:", "- uH = min(uH, d)", "- else:", "- uH = d", "- for i in range(1, len(aH)):", "- if aH[0] != aH[i]:", "- bF = False", "- if uH:", "- if uH < aH[0]:", "- bF = False", "+ break", "- print((cx, cy, aH[0]))", "+ print((cx, cy, h))" ]
false
0.067959
0.037286
1.822664
[ "s760934057", "s144784473" ]
u368249389
p03017
python
s843843180
s434588360
202
171
61,296
40,816
Accepted
Accepted
15.35
# Problem A - Kenken Race # input N, A, B, C, D = list(map(int, input().split())) S = list(eval(input())) # check if C<D: # B check is_ok = True for i in range(B, D-1): if S[i]=='#' and S[i+1]=='#': is_ok = False break # A check for i in range(A, C-1): if S[i]=='#' and S[i+1]=='#': is_ok = False break # output if is_ok: print("Yes") else: print("No") else: is_ok = False # B check for i in range(B, D): if S[i]=='#' and S[i+1]=='#': is_ok = False break for i in range(B-1, D): if S[i-1]=='.' and S[i]=='.' and S[i+1]=='.': is_ok = True # A check for i in range(A, C-1): if S[i]=='#' and S[i+1]=='#': is_ok = False break # output if is_ok: print("Yes") else: print("No")
# Problem A - Kenken Race # input N, A, B, C, D = list(map(int, input().split())) S = eval(input()) # initialization is_ok = True # search if C>D: # b check if "##" in S[B-1:D] or not "..." in S[B-2:D+1]: is_ok = False # a check if "##" in S[A-1:C]: is_ok = False else: # b check if "##" in S[B-1:D]: is_ok = False # a check if "##" in S[A-1:C]: is_ok = False # output if is_ok: print("Yes") else: print("No")
44
32
953
507
# Problem A - Kenken Race # input N, A, B, C, D = list(map(int, input().split())) S = list(eval(input())) # check if C < D: # B check is_ok = True for i in range(B, D - 1): if S[i] == "#" and S[i + 1] == "#": is_ok = False break # A check for i in range(A, C - 1): if S[i] == "#" and S[i + 1] == "#": is_ok = False break # output if is_ok: print("Yes") else: print("No") else: is_ok = False # B check for i in range(B, D): if S[i] == "#" and S[i + 1] == "#": is_ok = False break for i in range(B - 1, D): if S[i - 1] == "." and S[i] == "." and S[i + 1] == ".": is_ok = True # A check for i in range(A, C - 1): if S[i] == "#" and S[i + 1] == "#": is_ok = False break # output if is_ok: print("Yes") else: print("No")
# Problem A - Kenken Race # input N, A, B, C, D = list(map(int, input().split())) S = eval(input()) # initialization is_ok = True # search if C > D: # b check if "##" in S[B - 1 : D] or not "..." in S[B - 2 : D + 1]: is_ok = False # a check if "##" in S[A - 1 : C]: is_ok = False else: # b check if "##" in S[B - 1 : D]: is_ok = False # a check if "##" in S[A - 1 : C]: is_ok = False # output if is_ok: print("Yes") else: print("No")
false
27.272727
[ "-S = list(eval(input()))", "-# check", "-if C < D:", "- # B check", "- is_ok = True", "- for i in range(B, D - 1):", "- if S[i] == \"#\" and S[i + 1] == \"#\":", "- is_ok = False", "- break", "- # A check", "- for i in range(A, C - 1):", "- if S[i] == \"#\" and S[i + 1] == \"#\":", "- is_ok = False", "- break", "- # output", "- if is_ok:", "- print(\"Yes\")", "- else:", "- print(\"No\")", "+S = eval(input())", "+# initialization", "+is_ok = True", "+# search", "+if C > D:", "+ # b check", "+ if \"##\" in S[B - 1 : D] or not \"...\" in S[B - 2 : D + 1]:", "+ is_ok = False", "+ # a check", "+ if \"##\" in S[A - 1 : C]:", "+ is_ok = False", "- is_ok = False", "- # B check", "- for i in range(B, D):", "- if S[i] == \"#\" and S[i + 1] == \"#\":", "- is_ok = False", "- break", "- for i in range(B - 1, D):", "- if S[i - 1] == \".\" and S[i] == \".\" and S[i + 1] == \".\":", "- is_ok = True", "- # A check", "- for i in range(A, C - 1):", "- if S[i] == \"#\" and S[i + 1] == \"#\":", "- is_ok = False", "- break", "- # output", "- if is_ok:", "- print(\"Yes\")", "- else:", "- print(\"No\")", "+ # b check", "+ if \"##\" in S[B - 1 : D]:", "+ is_ok = False", "+ # a check", "+ if \"##\" in S[A - 1 : C]:", "+ is_ok = False", "+# output", "+if is_ok:", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.038443
0.067614
0.568565
[ "s843843180", "s434588360" ]
u135454978
p02844
python
s097585201
s270102236
267
186
40,556
38,384
Accepted
Accepted
30.34
# 三井住友信託銀行プログラミングコンテスト 2019 D - Lucky PIN import sys def main(): N = int(eval(input())) # 桁数 S = str(eval(input())) ans = set() digit1 = set() for i in range(0, N - 2): if S[i] in digit1: continue digit1.add(S[i]) digit2 = set() for j in range(i + 1, N - 1): if S[j] in digit2: continue digit2.add(S[j]) digit3 = set() for k in range(j + 1, N): if len(digit3) == 10: break code = S[i] + S[j] + S[k] ans.add(code) print((len(ans))) if __name__ == '__main__': main()
# 三井住友信託銀行プログラミングコンテスト 2019 D - Lucky PIN import sys N = int(eval(input())) S = str(eval(input())) ans = 0 for i in range(10): code1 = S.find(str(i)) if code1 == -1: continue for j in range(10): code2 = S.find(str(j), code1 + 1) if code2 == -1: continue for k in range(10): code3 = S.find(str(k), code2 + 1) if code3 != -1: ans += 1 print(ans)
35
22
700
453
# 三井住友信託銀行プログラミングコンテスト 2019 D - Lucky PIN import sys def main(): N = int(eval(input())) # 桁数 S = str(eval(input())) ans = set() digit1 = set() for i in range(0, N - 2): if S[i] in digit1: continue digit1.add(S[i]) digit2 = set() for j in range(i + 1, N - 1): if S[j] in digit2: continue digit2.add(S[j]) digit3 = set() for k in range(j + 1, N): if len(digit3) == 10: break code = S[i] + S[j] + S[k] ans.add(code) print((len(ans))) if __name__ == "__main__": main()
# 三井住友信託銀行プログラミングコンテスト 2019 D - Lucky PIN import sys N = int(eval(input())) S = str(eval(input())) ans = 0 for i in range(10): code1 = S.find(str(i)) if code1 == -1: continue for j in range(10): code2 = S.find(str(j), code1 + 1) if code2 == -1: continue for k in range(10): code3 = S.find(str(k), code2 + 1) if code3 != -1: ans += 1 print(ans)
false
37.142857
[ "-", "-def main():", "- N = int(eval(input())) # 桁数", "- S = str(eval(input()))", "- ans = set()", "- digit1 = set()", "- for i in range(0, N - 2):", "- if S[i] in digit1:", "+N = int(eval(input()))", "+S = str(eval(input()))", "+ans = 0", "+for i in range(10):", "+ code1 = S.find(str(i))", "+ if code1 == -1:", "+ continue", "+ for j in range(10):", "+ code2 = S.find(str(j), code1 + 1)", "+ if code2 == -1:", "- digit1.add(S[i])", "- digit2 = set()", "- for j in range(i + 1, N - 1):", "- if S[j] in digit2:", "- continue", "- digit2.add(S[j])", "- digit3 = set()", "- for k in range(j + 1, N):", "- if len(digit3) == 10:", "- break", "- code = S[i] + S[j] + S[k]", "- ans.add(code)", "- print((len(ans)))", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+ for k in range(10):", "+ code3 = S.find(str(k), code2 + 1)", "+ if code3 != -1:", "+ ans += 1", "+print(ans)" ]
false
0.060284
0.037319
1.615365
[ "s097585201", "s270102236" ]
u492447501
p03212
python
s353906456
s698540855
319
134
3,064
3,188
Accepted
Accepted
57.99
N = int(eval(input())) l = len(str(10**9)) def dfs(A):#配列Aからできる753数 global N if len(A)>0 and(int("".join(map(str, A)))>N): return 0 ans = 0 if(all(A.count(i)==0 for i in [0, 1, 2, 4, 6, 8, 9]) and (A.count(3) >0 and A.count(5) >0 and A.count(7) >0)): ans = ans + 1 for i in [3, 5, 7]: A.append(i) ans = ans + dfs(A) A.pop() return ans print((dfs([])))
N = int(eval(input())) import sys sys.setrecursionlimit(500000) def dfs(l): global N if l!=[] and N<int("".join(l)): return 0 ans = 0 if all(l.count(i)>0 for i in ["3", "5", "7"]): ans = 1 for i in ["3", "5", "7"]: l.append(i) #参照渡し ans += dfs(l) l.pop() return ans print((dfs([])))
19
20
442
368
N = int(eval(input())) l = len(str(10**9)) def dfs(A): # 配列Aからできる753数 global N if len(A) > 0 and (int("".join(map(str, A))) > N): return 0 ans = 0 if all(A.count(i) == 0 for i in [0, 1, 2, 4, 6, 8, 9]) and ( A.count(3) > 0 and A.count(5) > 0 and A.count(7) > 0 ): ans = ans + 1 for i in [3, 5, 7]: A.append(i) ans = ans + dfs(A) A.pop() return ans print((dfs([])))
N = int(eval(input())) import sys sys.setrecursionlimit(500000) def dfs(l): global N if l != [] and N < int("".join(l)): return 0 ans = 0 if all(l.count(i) > 0 for i in ["3", "5", "7"]): ans = 1 for i in ["3", "5", "7"]: l.append(i) # 参照渡し ans += dfs(l) l.pop() return ans print((dfs([])))
false
5
[ "-l = len(str(10**9))", "+import sys", "+", "+sys.setrecursionlimit(500000)", "-def dfs(A): # 配列Aからできる753数", "+def dfs(l):", "- if len(A) > 0 and (int(\"\".join(map(str, A))) > N):", "+ if l != [] and N < int(\"\".join(l)):", "- if all(A.count(i) == 0 for i in [0, 1, 2, 4, 6, 8, 9]) and (", "- A.count(3) > 0 and A.count(5) > 0 and A.count(7) > 0", "- ):", "- ans = ans + 1", "- for i in [3, 5, 7]:", "- A.append(i)", "- ans = ans + dfs(A)", "- A.pop()", "+ if all(l.count(i) > 0 for i in [\"3\", \"5\", \"7\"]):", "+ ans = 1", "+ for i in [\"3\", \"5\", \"7\"]:", "+ l.append(i)", "+ # 参照渡し", "+ ans += dfs(l)", "+ l.pop()" ]
false
0.131519
0.059645
2.205045
[ "s353906456", "s698540855" ]
u416011173
p02597
python
s175768889
s952596166
138
94
9,316
9,476
Accepted
Accepted
31.88
# -*- coding: utf-8 -*- # 標準入力を取得 N = int(eval(input())) c = eval(input()) # 求解処理 w = 0 r = c.count("R") ans = max(w, r) for n in range(N): c_n = c[n] if c_n == "W": w += 1 else: r -= 1 ans = min(ans, max(w, r)) # 結果出力 print(ans)
# -*- coding: utf-8 -*- def get_input() -> tuple: """ 標準入力を取得する. Returns:\n tuple: 標準入力 """ N = int(eval(input())) c = eval(input()) return N, c def main(N: int, c: str) -> None: """ メイン処理. Args:\n N (int): 石の個数(2 <= N <= 200000) c (str): 石の色 """ # 求解処理 w = 0 r = c.count("R") ans = max(w, r) for n in range(N): c_n = c[n] if c_n == "W": w += 1 else: r -= 1 ans = min(ans, max(w, r)) # 結果出力 print(ans) if __name__ == "__main__": # 標準入力を取得 N, c = get_input() # メイン処理 main(N, c)
19
45
270
687
# -*- coding: utf-8 -*- # 標準入力を取得 N = int(eval(input())) c = eval(input()) # 求解処理 w = 0 r = c.count("R") ans = max(w, r) for n in range(N): c_n = c[n] if c_n == "W": w += 1 else: r -= 1 ans = min(ans, max(w, r)) # 結果出力 print(ans)
# -*- coding: utf-8 -*- def get_input() -> tuple: """ 標準入力を取得する. Returns:\n tuple: 標準入力 """ N = int(eval(input())) c = eval(input()) return N, c def main(N: int, c: str) -> None: """ メイン処理. Args:\n N (int): 石の個数(2 <= N <= 200000) c (str): 石の色 """ # 求解処理 w = 0 r = c.count("R") ans = max(w, r) for n in range(N): c_n = c[n] if c_n == "W": w += 1 else: r -= 1 ans = min(ans, max(w, r)) # 結果出力 print(ans) if __name__ == "__main__": # 標準入力を取得 N, c = get_input() # メイン処理 main(N, c)
false
57.777778
[ "-# 標準入力を取得", "-N = int(eval(input()))", "-c = eval(input())", "-# 求解処理", "-w = 0", "-r = c.count(\"R\")", "-ans = max(w, r)", "-for n in range(N):", "- c_n = c[n]", "- if c_n == \"W\":", "- w += 1", "- else:", "- r -= 1", "- ans = min(ans, max(w, r))", "-# 結果出力", "-print(ans)", "+def get_input() -> tuple:", "+ \"\"\"", "+ 標準入力を取得する.", "+ Returns:\\n", "+ tuple: 標準入力", "+ \"\"\"", "+ N = int(eval(input()))", "+ c = eval(input())", "+ return N, c", "+", "+", "+def main(N: int, c: str) -> None:", "+ \"\"\"", "+ メイン処理.", "+ Args:\\n", "+ N (int): 石の個数(2 <= N <= 200000)", "+ c (str): 石の色", "+ \"\"\"", "+ # 求解処理", "+ w = 0", "+ r = c.count(\"R\")", "+ ans = max(w, r)", "+ for n in range(N):", "+ c_n = c[n]", "+ if c_n == \"W\":", "+ w += 1", "+ else:", "+ r -= 1", "+ ans = min(ans, max(w, r))", "+ # 結果出力", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ # 標準入力を取得", "+ N, c = get_input()", "+ # メイン処理", "+ main(N, c)" ]
false
0.038169
0.109225
0.349451
[ "s175768889", "s952596166" ]
u968166680
p02936
python
s073802508
s510659249
965
658
296,968
90,808
Accepted
Accepted
31.81
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, Q = list(map(int, readline().split())) G = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, readline().split())) G[a - 1].append(b - 1) G[b - 1].append(a - 1) P = [0] * N (*PX,) = list(map(int, read().split())) for p, x in zip(*[iter(PX)] * 2): P[p - 1] += x def dfs(v, p): for nv in G[v]: if nv == p: continue P[nv] += P[v] dfs(nv, v) dfs(0, -1) print((' '.join(map(str, P)))) return if __name__ == '__main__': main()
import sys from collections import deque read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, Q = list(map(int, readline().split())) G = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, readline().split())) G[a - 1].append(b - 1) G[b - 1].append(a - 1) P = [0] * N (*PX,) = list(map(int, read().split())) for p, x in zip(*[iter(PX)] * 2): P[p - 1] += x stack = deque([0]) seen = [False] * N while stack: v = stack.pop() seen[v] = True for nv in G[v]: if seen[nv]: continue P[nv] += P[v] stack.append(nv) print((' '.join(map(str, P)))) return if __name__ == '__main__': main()
38
41
771
886
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N, Q = list(map(int, readline().split())) G = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, readline().split())) G[a - 1].append(b - 1) G[b - 1].append(a - 1) P = [0] * N (*PX,) = list(map(int, read().split())) for p, x in zip(*[iter(PX)] * 2): P[p - 1] += x def dfs(v, p): for nv in G[v]: if nv == p: continue P[nv] += P[v] dfs(nv, v) dfs(0, -1) print((" ".join(map(str, P)))) return if __name__ == "__main__": main()
import sys from collections import deque read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N, Q = list(map(int, readline().split())) G = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, readline().split())) G[a - 1].append(b - 1) G[b - 1].append(a - 1) P = [0] * N (*PX,) = list(map(int, read().split())) for p, x in zip(*[iter(PX)] * 2): P[p - 1] += x stack = deque([0]) seen = [False] * N while stack: v = stack.pop() seen[v] = True for nv in G[v]: if seen[nv]: continue P[nv] += P[v] stack.append(nv) print((" ".join(map(str, P)))) return if __name__ == "__main__": main()
false
7.317073
[ "+from collections import deque", "-", "- def dfs(v, p):", "+ stack = deque([0])", "+ seen = [False] * N", "+ while stack:", "+ v = stack.pop()", "+ seen[v] = True", "- if nv == p:", "+ if seen[nv]:", "- dfs(nv, v)", "-", "- dfs(0, -1)", "+ stack.append(nv)" ]
false
0.036309
0.037102
0.978624
[ "s073802508", "s510659249" ]
u339199690
p02695
python
s627678705
s155841572
860
235
21,472
77,012
Accepted
Accepted
72.67
from itertools import combinations_with_replacement as cwd N, M, Q = list(map(int, input().split())) A = list(cwd(list(range(1, M + 1)), N)) ABCD = [] for i in range(Q): a, b, c, d = list(map(int, input().split())) a, b = a - 1, b - 1 ABCD.append([a, b, c, d]) res = 0 for i in A: tmp = 0 for j in ABCD: if i[j[1]] - i[j[0]] == j[2]: tmp += j[3] res = max(res, tmp) print(res)
N, M, Q = list(map(int, input().split())) res = 0 def dfs(L: list): global res A = L[::] if len(A) == N + 1: now = 0 for i in range(Q): if A[b[i]] - A[a[i]] == c[i]: now += d[i] res = max(res, now) # print(A, now) return A.append(A[-1]) while A[-1] <= M: dfs(A) A[-1] += 1 a, b, c, d = [], [], [], [] for _ in range(Q): _a, _b, _c, _d = list(map(int, input().split())) a.append(_a) b.append(_b) c.append(_c) d.append(_d) dfs([1]) print(res)
20
30
426
594
from itertools import combinations_with_replacement as cwd N, M, Q = list(map(int, input().split())) A = list(cwd(list(range(1, M + 1)), N)) ABCD = [] for i in range(Q): a, b, c, d = list(map(int, input().split())) a, b = a - 1, b - 1 ABCD.append([a, b, c, d]) res = 0 for i in A: tmp = 0 for j in ABCD: if i[j[1]] - i[j[0]] == j[2]: tmp += j[3] res = max(res, tmp) print(res)
N, M, Q = list(map(int, input().split())) res = 0 def dfs(L: list): global res A = L[::] if len(A) == N + 1: now = 0 for i in range(Q): if A[b[i]] - A[a[i]] == c[i]: now += d[i] res = max(res, now) # print(A, now) return A.append(A[-1]) while A[-1] <= M: dfs(A) A[-1] += 1 a, b, c, d = [], [], [], [] for _ in range(Q): _a, _b, _c, _d = list(map(int, input().split())) a.append(_a) b.append(_b) c.append(_c) d.append(_d) dfs([1]) print(res)
false
33.333333
[ "-from itertools import combinations_with_replacement as cwd", "+N, M, Q = list(map(int, input().split()))", "+res = 0", "-N, M, Q = list(map(int, input().split()))", "-A = list(cwd(list(range(1, M + 1)), N))", "-ABCD = []", "-for i in range(Q):", "- a, b, c, d = list(map(int, input().split()))", "- a, b = a - 1, b - 1", "- ABCD.append([a, b, c, d])", "-res = 0", "-for i in A:", "- tmp = 0", "- for j in ABCD:", "- if i[j[1]] - i[j[0]] == j[2]:", "- tmp += j[3]", "- res = max(res, tmp)", "+", "+def dfs(L: list):", "+ global res", "+ A = L[::]", "+ if len(A) == N + 1:", "+ now = 0", "+ for i in range(Q):", "+ if A[b[i]] - A[a[i]] == c[i]:", "+ now += d[i]", "+ res = max(res, now)", "+ # print(A, now)", "+ return", "+ A.append(A[-1])", "+ while A[-1] <= M:", "+ dfs(A)", "+ A[-1] += 1", "+", "+", "+a, b, c, d = [], [], [], []", "+for _ in range(Q):", "+ _a, _b, _c, _d = list(map(int, input().split()))", "+ a.append(_a)", "+ b.append(_b)", "+ c.append(_c)", "+ d.append(_d)", "+dfs([1])" ]
false
0.057569
0.133472
0.431318
[ "s627678705", "s155841572" ]
u119127920
p02315
python
s569430667
s478328145
2,180
1,140
136,244
44,312
Accepted
Accepted
47.71
from collections import defaultdict memo = {} def dfs(i, w, item_list, W): if i >= len(item_list): return 0 if (i, w) in memo: return memo[(i, w)] ans = 0 # use new_w = w + item_list[i][1] if new_w <= W: ans = max(ans, dfs(i + 1, new_w, item_list, W) + item_list[i][0]) # not use ans = max(ans, dfs(i + 1, w, item_list, W)) memo[(i, w)] = ans return ans def main(): N, W = list(map(int, input().split())) item_list = [] for _ in range(N): v, w = list(map(int, input().split())) item_list.append((v, w)) print((dfs(0, 0, item_list, W))) if __name__ == '__main__': main()
from collections import defaultdict def solve(N, W, vs, ws): dp = [[0] * (W + 1) for _ in range(N + 1)] for i in range(N): v, w = vs[i], ws[i] for j in range(len(dp[0])): dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]) if j + w < len(dp[0]): dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v) ans = 0 for line in dp: ans = max(line) return ans def main(): N, W = list(map(int, input().split())) vs, ws = [], [] for _ in range(N): v, w = list(map(int, input().split())) vs.append(v) ws.append(w) print((solve(N, W, vs, ws))) if __name__ == '__main__': main()
34
29
697
704
from collections import defaultdict memo = {} def dfs(i, w, item_list, W): if i >= len(item_list): return 0 if (i, w) in memo: return memo[(i, w)] ans = 0 # use new_w = w + item_list[i][1] if new_w <= W: ans = max(ans, dfs(i + 1, new_w, item_list, W) + item_list[i][0]) # not use ans = max(ans, dfs(i + 1, w, item_list, W)) memo[(i, w)] = ans return ans def main(): N, W = list(map(int, input().split())) item_list = [] for _ in range(N): v, w = list(map(int, input().split())) item_list.append((v, w)) print((dfs(0, 0, item_list, W))) if __name__ == "__main__": main()
from collections import defaultdict def solve(N, W, vs, ws): dp = [[0] * (W + 1) for _ in range(N + 1)] for i in range(N): v, w = vs[i], ws[i] for j in range(len(dp[0])): dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]) if j + w < len(dp[0]): dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v) ans = 0 for line in dp: ans = max(line) return ans def main(): N, W = list(map(int, input().split())) vs, ws = [], [] for _ in range(N): v, w = list(map(int, input().split())) vs.append(v) ws.append(w) print((solve(N, W, vs, ws))) if __name__ == "__main__": main()
false
14.705882
[ "-memo = {}", "-", "-def dfs(i, w, item_list, W):", "- if i >= len(item_list):", "- return 0", "- if (i, w) in memo:", "- return memo[(i, w)]", "+def solve(N, W, vs, ws):", "+ dp = [[0] * (W + 1) for _ in range(N + 1)]", "+ for i in range(N):", "+ v, w = vs[i], ws[i]", "+ for j in range(len(dp[0])):", "+ dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])", "+ if j + w < len(dp[0]):", "+ dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v)", "- # use", "- new_w = w + item_list[i][1]", "- if new_w <= W:", "- ans = max(ans, dfs(i + 1, new_w, item_list, W) + item_list[i][0])", "- # not use", "- ans = max(ans, dfs(i + 1, w, item_list, W))", "- memo[(i, w)] = ans", "+ for line in dp:", "+ ans = max(line)", "- item_list = []", "+ vs, ws = [], []", "- item_list.append((v, w))", "- print((dfs(0, 0, item_list, W)))", "+ vs.append(v)", "+ ws.append(w)", "+ print((solve(N, W, vs, ws)))" ]
false
0.009278
0.041811
0.221902
[ "s569430667", "s478328145" ]
u677523557
p03044
python
s835737194
s757883647
740
509
79,488
65,808
Accepted
Accepted
31.22
N = int(eval(input())) import sys sys.setrecursionlimit(90000) graph = [[] for _ in range(N)] for _ in range(N-1): a, b, c = list(map(int, input().split())) graph[a-1].append((b-1, c)) graph[b-1].append((a-1, c)) color = [-1 for _ in range(N)] def dfs(p, c, color): color[p] = c cinv = 0 if c == 1 else 1 for q, d in graph[p]: if color[q] != -1: continue if d % 2 == 1: color = dfs(q, cinv, color) else: color = dfs(q, c, color) return color A = dfs(0, 0, color) for a in A: print(a)
import sys input = sys.stdin.readline N = int(input()) graph = [[] for _ in range(N)] for _ in range(N-1): a, b, w = map(int, input().split()) graph[a-1].append((b-1, w)) graph[b-1].append((a-1, w)) def dfs(s): Ind = [0]*N stack = [s] Color = [0]*N while stack: p = stack[-1] if Ind[p] == len(graph[p]): stack.pop() elif len(stack) > 1 and stack[-2] == graph[p][Ind[p]][0]: Ind[p] += 1 else: ch, w = graph[p][Ind[p]] Ind[p] += 1 stack.append(ch) Color[ch] = Color[p]^(w%2) return Color Color = dfs(0) print(*Color, sep="\n")
26
30
591
694
N = int(eval(input())) import sys sys.setrecursionlimit(90000) graph = [[] for _ in range(N)] for _ in range(N - 1): a, b, c = list(map(int, input().split())) graph[a - 1].append((b - 1, c)) graph[b - 1].append((a - 1, c)) color = [-1 for _ in range(N)] def dfs(p, c, color): color[p] = c cinv = 0 if c == 1 else 1 for q, d in graph[p]: if color[q] != -1: continue if d % 2 == 1: color = dfs(q, cinv, color) else: color = dfs(q, c, color) return color A = dfs(0, 0, color) for a in A: print(a)
import sys input = sys.stdin.readline N = int(input()) graph = [[] for _ in range(N)] for _ in range(N - 1): a, b, w = map(int, input().split()) graph[a - 1].append((b - 1, w)) graph[b - 1].append((a - 1, w)) def dfs(s): Ind = [0] * N stack = [s] Color = [0] * N while stack: p = stack[-1] if Ind[p] == len(graph[p]): stack.pop() elif len(stack) > 1 and stack[-2] == graph[p][Ind[p]][0]: Ind[p] += 1 else: ch, w = graph[p][Ind[p]] Ind[p] += 1 stack.append(ch) Color[ch] = Color[p] ^ (w % 2) return Color Color = dfs(0) print(*Color, sep="\n")
false
13.333333
[ "-N = int(eval(input()))", "-sys.setrecursionlimit(90000)", "+input = sys.stdin.readline", "+N = int(input())", "- a, b, c = list(map(int, input().split()))", "- graph[a - 1].append((b - 1, c))", "- graph[b - 1].append((a - 1, c))", "-color = [-1 for _ in range(N)]", "+ a, b, w = map(int, input().split())", "+ graph[a - 1].append((b - 1, w))", "+ graph[b - 1].append((a - 1, w))", "-def dfs(p, c, color):", "- color[p] = c", "- cinv = 0 if c == 1 else 1", "- for q, d in graph[p]:", "- if color[q] != -1:", "- continue", "- if d % 2 == 1:", "- color = dfs(q, cinv, color)", "+def dfs(s):", "+ Ind = [0] * N", "+ stack = [s]", "+ Color = [0] * N", "+ while stack:", "+ p = stack[-1]", "+ if Ind[p] == len(graph[p]):", "+ stack.pop()", "+ elif len(stack) > 1 and stack[-2] == graph[p][Ind[p]][0]:", "+ Ind[p] += 1", "- color = dfs(q, c, color)", "- return color", "+ ch, w = graph[p][Ind[p]]", "+ Ind[p] += 1", "+ stack.append(ch)", "+ Color[ch] = Color[p] ^ (w % 2)", "+ return Color", "-A = dfs(0, 0, color)", "-for a in A:", "- print(a)", "+Color = dfs(0)", "+print(*Color, sep=\"\\n\")" ]
false
0.149578
0.113616
1.316517
[ "s835737194", "s757883647" ]
u871980676
p02821
python
s743073889
s111609106
1,561
1,153
14,396
59,664
Accepted
Accepted
26.14
import sys import bisect input = sys.stdin.readline class Bisect(object): def bisect_max(self, reva, func,M): ok = 0 # exist ng = 4*(10**5) # not exist while abs(ok-ng) > 1: cnt = (ok + ng) // 2 if func(cnt,reva,M): ok = cnt else: ng = cnt return ok def bisect_min(self, reva, func,M): ok = 10**5 # exist ng = 0 # not exist while abs(ok-ng) > 1: cnt = (ok + ng) // 2 if func(cnt,reva,M): ok = cnt else: ng = cnt return ok def solve1(tgt,reva,M): res=0 n = len(reva) for i in range(n): tmp = bisect.bisect_left(reva,tgt-reva[i]) tmp = n - tmp res += tmp if M <= res: return True else: return False def solve2(tgt): print(tgt) if tgt > 12: return True else: return False N,M = list(map(int,input().split())) a = list(map(int,input().split())) a.sort(reverse=True) reva = a[::-1] bs = Bisect() Kmax = (bs.bisect_max(reva,solve1,M)) r=[0] for i in range(N): r.append(r[i]+a[i]) res = 0 cnt = 0 t = 0 for i in range(N): tmp = bisect.bisect_left(reva,Kmax-reva[N-i-1]) tmp2 = bisect.bisect_right(reva,Kmax-reva[N-i-1]) if tmp!=tmp2: t = 1 tmp = N - tmp cnt += tmp res += tmp*a[i]+r[tmp] if t==1: res -= (cnt-M)*Kmax print(res)
import sys import bisect input = sys.stdin.readline class Bisect(object): def bisect_max(self, reva, func,M): ok = 0 # exist ng = 4*(10**5) # not exist while abs(ok-ng) > 1: cnt = (ok + ng) // 2 if func(cnt,reva,M): ok = cnt else: ng = cnt return ok def solve1(tgt,reva,M): res=0 n = len(reva) for i in range(n): tmp = bisect.bisect_left(reva,tgt-reva[i]) tmp = n - tmp res += tmp if M <= res: return True else: return False N,M = list(map(int,input().split())) a = list(map(int,input().split())) a.sort(reverse=True) reva = a[::-1] bs = Bisect() Kmax = (bs.bisect_max(reva,solve1,M)) r=[0] for i in range(N): r.append(r[i]+a[i]) res = 0 cnt = 0 t = 0 for i in range(N): tmp = bisect.bisect_left(reva,Kmax-reva[N-i-1]) tmp2 = bisect.bisect_right(reva,Kmax-reva[N-i-1]) if tmp!=tmp2: t = 1 tmp = N - tmp cnt += tmp res += tmp*a[i]+r[tmp] if t==1: res -= (cnt-M)*Kmax print(res)
70
53
1,526
1,132
import sys import bisect input = sys.stdin.readline class Bisect(object): def bisect_max(self, reva, func, M): ok = 0 # exist ng = 4 * (10**5) # not exist while abs(ok - ng) > 1: cnt = (ok + ng) // 2 if func(cnt, reva, M): ok = cnt else: ng = cnt return ok def bisect_min(self, reva, func, M): ok = 10**5 # exist ng = 0 # not exist while abs(ok - ng) > 1: cnt = (ok + ng) // 2 if func(cnt, reva, M): ok = cnt else: ng = cnt return ok def solve1(tgt, reva, M): res = 0 n = len(reva) for i in range(n): tmp = bisect.bisect_left(reva, tgt - reva[i]) tmp = n - tmp res += tmp if M <= res: return True else: return False def solve2(tgt): print(tgt) if tgt > 12: return True else: return False N, M = list(map(int, input().split())) a = list(map(int, input().split())) a.sort(reverse=True) reva = a[::-1] bs = Bisect() Kmax = bs.bisect_max(reva, solve1, M) r = [0] for i in range(N): r.append(r[i] + a[i]) res = 0 cnt = 0 t = 0 for i in range(N): tmp = bisect.bisect_left(reva, Kmax - reva[N - i - 1]) tmp2 = bisect.bisect_right(reva, Kmax - reva[N - i - 1]) if tmp != tmp2: t = 1 tmp = N - tmp cnt += tmp res += tmp * a[i] + r[tmp] if t == 1: res -= (cnt - M) * Kmax print(res)
import sys import bisect input = sys.stdin.readline class Bisect(object): def bisect_max(self, reva, func, M): ok = 0 # exist ng = 4 * (10**5) # not exist while abs(ok - ng) > 1: cnt = (ok + ng) // 2 if func(cnt, reva, M): ok = cnt else: ng = cnt return ok def solve1(tgt, reva, M): res = 0 n = len(reva) for i in range(n): tmp = bisect.bisect_left(reva, tgt - reva[i]) tmp = n - tmp res += tmp if M <= res: return True else: return False N, M = list(map(int, input().split())) a = list(map(int, input().split())) a.sort(reverse=True) reva = a[::-1] bs = Bisect() Kmax = bs.bisect_max(reva, solve1, M) r = [0] for i in range(N): r.append(r[i] + a[i]) res = 0 cnt = 0 t = 0 for i in range(N): tmp = bisect.bisect_left(reva, Kmax - reva[N - i - 1]) tmp2 = bisect.bisect_right(reva, Kmax - reva[N - i - 1]) if tmp != tmp2: t = 1 tmp = N - tmp cnt += tmp res += tmp * a[i] + r[tmp] if t == 1: res -= (cnt - M) * Kmax print(res)
false
24.285714
[ "- def bisect_min(self, reva, func, M):", "- ok = 10**5 # exist", "- ng = 0 # not exist", "- while abs(ok - ng) > 1:", "- cnt = (ok + ng) // 2", "- if func(cnt, reva, M):", "- ok = cnt", "- else:", "- ng = cnt", "- return ok", "-", "- return True", "- else:", "- return False", "-", "-", "-def solve2(tgt):", "- print(tgt)", "- if tgt > 12:" ]
false
0.007427
0.174867
0.042473
[ "s743073889", "s111609106" ]
u073852194
p03286
python
s158428784
s582402470
21
18
3,316
3,064
Accepted
Accepted
14.29
n = int(eval(input())) I = [[0,1]] while n < I[-1][0] or I[-1][1] < n: if len(I)%2 != 0: I += [[I[-1][0]-2**(len(I)),I[-1][1]]] else: I += [[I[-1][0],I[-1][1]+2**(len(I))]] ans = '' for i in range(len(I)): if abs((I[-i-1][0]+I[-i-1][1])/2) < abs(n) and n * (-1)**(len(I)-i-1) > 0: ans += '1' n -= (-2)**(len(I)-i-1) else: ans += '0' print((int(ans)))
N = int(eval(input())) lt = [0 for _ in range(50)] rt = [0 for _ in range(50)] lt[0] = 1 rt[0] = 1 lt[1] = -2 rt[1] = -1 for i in range(2, 50): if i % 2 == 0: lt[i] = rt[i - 2] + 1 rt[i] = lt[i] + 2**i - 1 else: rt[i] = lt[i - 2] - 1 lt[i] = rt[i] - 2**i + 1 res = [0 for _ in range(50)] while N: for i in range(50): if lt[i] <= N <= rt[i]: res[~i] = 1 N -= (-2)**i break print((int(''.join(map(str, res)))))
15
28
384
533
n = int(eval(input())) I = [[0, 1]] while n < I[-1][0] or I[-1][1] < n: if len(I) % 2 != 0: I += [[I[-1][0] - 2 ** (len(I)), I[-1][1]]] else: I += [[I[-1][0], I[-1][1] + 2 ** (len(I))]] ans = "" for i in range(len(I)): if ( abs((I[-i - 1][0] + I[-i - 1][1]) / 2) < abs(n) and n * (-1) ** (len(I) - i - 1) > 0 ): ans += "1" n -= (-2) ** (len(I) - i - 1) else: ans += "0" print((int(ans)))
N = int(eval(input())) lt = [0 for _ in range(50)] rt = [0 for _ in range(50)] lt[0] = 1 rt[0] = 1 lt[1] = -2 rt[1] = -1 for i in range(2, 50): if i % 2 == 0: lt[i] = rt[i - 2] + 1 rt[i] = lt[i] + 2**i - 1 else: rt[i] = lt[i - 2] - 1 lt[i] = rt[i] - 2**i + 1 res = [0 for _ in range(50)] while N: for i in range(50): if lt[i] <= N <= rt[i]: res[~i] = 1 N -= (-2) ** i break print((int("".join(map(str, res)))))
false
46.428571
[ "-n = int(eval(input()))", "-I = [[0, 1]]", "-while n < I[-1][0] or I[-1][1] < n:", "- if len(I) % 2 != 0:", "- I += [[I[-1][0] - 2 ** (len(I)), I[-1][1]]]", "+N = int(eval(input()))", "+lt = [0 for _ in range(50)]", "+rt = [0 for _ in range(50)]", "+lt[0] = 1", "+rt[0] = 1", "+lt[1] = -2", "+rt[1] = -1", "+for i in range(2, 50):", "+ if i % 2 == 0:", "+ lt[i] = rt[i - 2] + 1", "+ rt[i] = lt[i] + 2**i - 1", "- I += [[I[-1][0], I[-1][1] + 2 ** (len(I))]]", "-ans = \"\"", "-for i in range(len(I)):", "- if (", "- abs((I[-i - 1][0] + I[-i - 1][1]) / 2) < abs(n)", "- and n * (-1) ** (len(I) - i - 1) > 0", "- ):", "- ans += \"1\"", "- n -= (-2) ** (len(I) - i - 1)", "- else:", "- ans += \"0\"", "-print((int(ans)))", "+ rt[i] = lt[i - 2] - 1", "+ lt[i] = rt[i] - 2**i + 1", "+res = [0 for _ in range(50)]", "+while N:", "+ for i in range(50):", "+ if lt[i] <= N <= rt[i]:", "+ res[~i] = 1", "+ N -= (-2) ** i", "+ break", "+print((int(\"\".join(map(str, res)))))" ]
false
0.044064
0.044691
0.985954
[ "s158428784", "s582402470" ]
u057109575
p02832
python
s060874918
s404823704
242
113
91,288
103,460
Accepted
Accepted
53.31
N, *A = list(map(int, open(0).read().split())) cnt = 0 ans = 0 for i in range(N): if cnt + 1 == A[i]: cnt += 1 else: ans += 1 if ans == N: print((-1)) else: print(ans)
N, *A = list(map(int, open(0).read().split())) cur = 0 for i in range(N): if A[i] == cur + 1: cur += 1 if cur == 0: print((-1)) else: print((N - cur))
14
11
207
173
N, *A = list(map(int, open(0).read().split())) cnt = 0 ans = 0 for i in range(N): if cnt + 1 == A[i]: cnt += 1 else: ans += 1 if ans == N: print((-1)) else: print(ans)
N, *A = list(map(int, open(0).read().split())) cur = 0 for i in range(N): if A[i] == cur + 1: cur += 1 if cur == 0: print((-1)) else: print((N - cur))
false
21.428571
[ "-cnt = 0", "-ans = 0", "+cur = 0", "- if cnt + 1 == A[i]:", "- cnt += 1", "- else:", "- ans += 1", "-if ans == N:", "+ if A[i] == cur + 1:", "+ cur += 1", "+if cur == 0:", "- print(ans)", "+ print((N - cur))" ]
false
0.04695
0.047804
0.982138
[ "s060874918", "s404823704" ]
u857547702
p02641
python
s406226174
s818143574
26
20
9,232
9,196
Accepted
Accepted
23.08
from bisect import bisect_left import sys X,N=list(map(int,input().split())) if N==0: print(X) sys.exit() P=list(map(int,input().split())) P=sorted(P) x=bisect_left(P,X) if x>=len(P): print(X) sys.exit() if P[x]!=X: print(X) sys.exit() A=X B=X while True: A-=1 B+=1 x1=bisect_left(P,A) x2=bisect_left(P,B) if x1<len(P) and P[x1]!=A: print(A) break if x2<len(P) and P[x2]!=B: print(B) break if x2==len(P): print(B) break
import sys X,N=list(map(int,input().split())) P=list(map(int,input().split())) if not X in P: print(X) sys.exit() A=X B=X while True: A-=1 B+=1 if not A in P: print(A) sys.exit() if not B in P: print(B) sys.exit()
31
17
550
285
from bisect import bisect_left import sys X, N = list(map(int, input().split())) if N == 0: print(X) sys.exit() P = list(map(int, input().split())) P = sorted(P) x = bisect_left(P, X) if x >= len(P): print(X) sys.exit() if P[x] != X: print(X) sys.exit() A = X B = X while True: A -= 1 B += 1 x1 = bisect_left(P, A) x2 = bisect_left(P, B) if x1 < len(P) and P[x1] != A: print(A) break if x2 < len(P) and P[x2] != B: print(B) break if x2 == len(P): print(B) break
import sys X, N = list(map(int, input().split())) P = list(map(int, input().split())) if not X in P: print(X) sys.exit() A = X B = X while True: A -= 1 B += 1 if not A in P: print(A) sys.exit() if not B in P: print(B) sys.exit()
false
45.16129
[ "-from bisect import bisect_left", "-if N == 0:", "- print(X)", "- sys.exit()", "-P = sorted(P)", "-x = bisect_left(P, X)", "-if x >= len(P):", "- print(X)", "- sys.exit()", "-if P[x] != X:", "+if not X in P:", "- x1 = bisect_left(P, A)", "- x2 = bisect_left(P, B)", "- if x1 < len(P) and P[x1] != A:", "+ if not A in P:", "- break", "- if x2 < len(P) and P[x2] != B:", "+ sys.exit()", "+ if not B in P:", "- break", "- if x2 == len(P):", "- print(B)", "- break", "+ sys.exit()" ]
false
0.039303
0.045403
0.865666
[ "s406226174", "s818143574" ]
u089230684
p02608
python
s711255860
s201399378
154
98
9,296
75,372
Accepted
Accepted
36.36
n = int(eval(input())) a = [0] * (n + 1) for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): c = x * x + y * y + z * z + x * y + y * z + z * x if c <= n: a[c] +=1 else: break for i in a[1:]: print(i)
from sys import stdin inp = lambda : stdin.readline().strip() n = int(inp()) a = [0]*10**5 for i in range(1,101): for j in range(1,101): for k in range(1,101): a[i**2 + j**2 + k**2 + i*j + i*k + k*j] += 1 for i in a[1:n+1]: print(i)
12
11
309
272
n = int(eval(input())) a = [0] * (n + 1) for x in range(1, 101): for y in range(1, 101): for z in range(1, 101): c = x * x + y * y + z * z + x * y + y * z + z * x if c <= n: a[c] += 1 else: break for i in a[1:]: print(i)
from sys import stdin inp = lambda: stdin.readline().strip() n = int(inp()) a = [0] * 10**5 for i in range(1, 101): for j in range(1, 101): for k in range(1, 101): a[i**2 + j**2 + k**2 + i * j + i * k + k * j] += 1 for i in a[1 : n + 1]: print(i)
false
8.333333
[ "-n = int(eval(input()))", "-a = [0] * (n + 1)", "-for x in range(1, 101):", "- for y in range(1, 101):", "- for z in range(1, 101):", "- c = x * x + y * y + z * z + x * y + y * z + z * x", "- if c <= n:", "- a[c] += 1", "- else:", "- break", "-for i in a[1:]:", "+from sys import stdin", "+", "+inp = lambda: stdin.readline().strip()", "+n = int(inp())", "+a = [0] * 10**5", "+for i in range(1, 101):", "+ for j in range(1, 101):", "+ for k in range(1, 101):", "+ a[i**2 + j**2 + k**2 + i * j + i * k + k * j] += 1", "+for i in a[1 : n + 1]:" ]
false
0.046272
2.355563
0.019644
[ "s711255860", "s201399378" ]
u678167152
p02802
python
s143410073
s827058016
326
179
3,828
74,992
Accepted
Accepted
45.09
import math N, M = list(map(int, input().split())) judge = [0]*N ac = 0 wa = 0 for i in range(M): p, S = input().split() if judge[int(p)-1] == 'AC': pass elif S == 'AC': wa += judge[int(p)-1] judge[int(p)-1] = 'AC' ac += 1 else: judge[int(p)-1] += 1 print((ac,wa))
def solve(): ans = [0,0] N, M = list(map(int, input().split())) WAs = [0]*N for i in range(M): p, S = input().split() p = int(p) if WAs[p-1]>=0: if S=='WA': WAs[p-1] += 1 if S=='AC': ans[0] += 1 ans[1] += WAs[p-1] WAs[p-1] = -1 return ans print((*solve()))
16
16
299
329
import math N, M = list(map(int, input().split())) judge = [0] * N ac = 0 wa = 0 for i in range(M): p, S = input().split() if judge[int(p) - 1] == "AC": pass elif S == "AC": wa += judge[int(p) - 1] judge[int(p) - 1] = "AC" ac += 1 else: judge[int(p) - 1] += 1 print((ac, wa))
def solve(): ans = [0, 0] N, M = list(map(int, input().split())) WAs = [0] * N for i in range(M): p, S = input().split() p = int(p) if WAs[p - 1] >= 0: if S == "WA": WAs[p - 1] += 1 if S == "AC": ans[0] += 1 ans[1] += WAs[p - 1] WAs[p - 1] = -1 return ans print((*solve()))
false
0
[ "-import math", "+def solve():", "+ ans = [0, 0]", "+ N, M = list(map(int, input().split()))", "+ WAs = [0] * N", "+ for i in range(M):", "+ p, S = input().split()", "+ p = int(p)", "+ if WAs[p - 1] >= 0:", "+ if S == \"WA\":", "+ WAs[p - 1] += 1", "+ if S == \"AC\":", "+ ans[0] += 1", "+ ans[1] += WAs[p - 1]", "+ WAs[p - 1] = -1", "+ return ans", "-N, M = list(map(int, input().split()))", "-judge = [0] * N", "-ac = 0", "-wa = 0", "-for i in range(M):", "- p, S = input().split()", "- if judge[int(p) - 1] == \"AC\":", "- pass", "- elif S == \"AC\":", "- wa += judge[int(p) - 1]", "- judge[int(p) - 1] = \"AC\"", "- ac += 1", "- else:", "- judge[int(p) - 1] += 1", "-print((ac, wa))", "+", "+print((*solve()))" ]
false
0.084374
0.039125
2.1565
[ "s143410073", "s827058016" ]
u811817592
p02713
python
s200390835
s039494789
1,140
859
9,620
9,208
Accepted
Accepted
24.65
# -*- coding: utf-8 -*- K = int(eval(input())) # lcm & gcd not math library def gcd(a, b): while b: a, b = b, a % b return a from functools import reduce def gcd_multi(num_list): return reduce(gcd, num_list) ans = 0 for i in range(1, K + 1): for j in range(i, K + 1): for k in range(j, K + 1): if i == j and j == k: dup_num = 1 elif i == j or j == k: dup_num = 3 else: dup_num = 6 ans += gcd_multi([i, j, k]) * dup_num print(ans)
# -*- coding: utf-8 -*- K = int(eval(input())) # lcm & gcd not math library def gcd(a, b): while b: a, b = b, a % b return a ans = 0 for i in range(1, K + 1): for j in range(i, K + 1): for k in range(j, K + 1): if i == j and j == k: dup_num = 1 elif i == j or j == k: dup_num = 3 else: dup_num = 6 ans += gcd(gcd(i, j), k) * dup_num print(ans)
26
21
580
483
# -*- coding: utf-8 -*- K = int(eval(input())) # lcm & gcd not math library def gcd(a, b): while b: a, b = b, a % b return a from functools import reduce def gcd_multi(num_list): return reduce(gcd, num_list) ans = 0 for i in range(1, K + 1): for j in range(i, K + 1): for k in range(j, K + 1): if i == j and j == k: dup_num = 1 elif i == j or j == k: dup_num = 3 else: dup_num = 6 ans += gcd_multi([i, j, k]) * dup_num print(ans)
# -*- coding: utf-8 -*- K = int(eval(input())) # lcm & gcd not math library def gcd(a, b): while b: a, b = b, a % b return a ans = 0 for i in range(1, K + 1): for j in range(i, K + 1): for k in range(j, K + 1): if i == j and j == k: dup_num = 1 elif i == j or j == k: dup_num = 3 else: dup_num = 6 ans += gcd(gcd(i, j), k) * dup_num print(ans)
false
19.230769
[ "-", "-", "-from functools import reduce", "-", "-", "-def gcd_multi(num_list):", "- return reduce(gcd, num_list)", "- ans += gcd_multi([i, j, k]) * dup_num", "+ ans += gcd(gcd(i, j), k) * dup_num" ]
false
0.095933
0.074441
1.288709
[ "s200390835", "s039494789" ]
u624689667
p02844
python
s805413818
s655778848
298
185
41,324
38,384
Accepted
Accepted
37.92
n = int(eval(input())) s = eval(input()) done_1 = set() done_2 = set() done_3 = set() for i in range(n): if s[i] in done_1: continue for j in range(i+1, n): if s[i] + s[j] in done_2: continue for k in range(j+1, n): pin = s[i] + s[j] + s[k] done_3.add(pin) done_2.add(pin[:2]) done_1.add(pin[0]) print((len(done_3)))
n = int(eval(input())) s = eval(input()) ans = 0 for i in range(1000): pin = str(i).zfill(3) p = s.find(pin[0]) if p == -1 or p >= n - 1: continue q = s.find(pin[1], p+1) if q == -1 or q == n - 1: continue r = s.find(pin[2], q+1) if r == -1: continue ans += 1 print(ans)
18
18
401
334
n = int(eval(input())) s = eval(input()) done_1 = set() done_2 = set() done_3 = set() for i in range(n): if s[i] in done_1: continue for j in range(i + 1, n): if s[i] + s[j] in done_2: continue for k in range(j + 1, n): pin = s[i] + s[j] + s[k] done_3.add(pin) done_2.add(pin[:2]) done_1.add(pin[0]) print((len(done_3)))
n = int(eval(input())) s = eval(input()) ans = 0 for i in range(1000): pin = str(i).zfill(3) p = s.find(pin[0]) if p == -1 or p >= n - 1: continue q = s.find(pin[1], p + 1) if q == -1 or q == n - 1: continue r = s.find(pin[2], q + 1) if r == -1: continue ans += 1 print(ans)
false
0
[ "-done_1 = set()", "-done_2 = set()", "-done_3 = set()", "-for i in range(n):", "- if s[i] in done_1:", "+ans = 0", "+for i in range(1000):", "+ pin = str(i).zfill(3)", "+ p = s.find(pin[0])", "+ if p == -1 or p >= n - 1:", "- for j in range(i + 1, n):", "- if s[i] + s[j] in done_2:", "- continue", "- for k in range(j + 1, n):", "- pin = s[i] + s[j] + s[k]", "- done_3.add(pin)", "- done_2.add(pin[:2])", "- done_1.add(pin[0])", "-print((len(done_3)))", "+ q = s.find(pin[1], p + 1)", "+ if q == -1 or q == n - 1:", "+ continue", "+ r = s.find(pin[2], q + 1)", "+ if r == -1:", "+ continue", "+ ans += 1", "+print(ans)" ]
false
0.096507
0.037675
2.561562
[ "s805413818", "s655778848" ]
u631277801
p03450
python
s837123648
s840874930
1,676
999
40,312
74,480
Accepted
Accepted
40.39
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x)-1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) class WeightedUnionFind: def __init__(self, node:int) -> None: self.n = node self.par = [i for i in range(self.n)] self.rank = [0 for i in range(self.n)] self.diff_weight = [0 for i in range(self.n)] # ノードxのルートを求める def find(self, x:int) -> int: if x == self.par[x]: return x else: r = self.find(self.par[x]) self.diff_weight[x] += self.diff_weight[self.par[x]] self.par[x] = r return self.par[x] # ノードxのルートからの距離を求める def weight(self, x:int) -> int: self.find(x) return self.diff_weight[x] # weight(y) - weight(x) = w となるようにする def unite(self, x:int, y:int, w:int) -> bool: if self.isSame(x,y): return False w += self.weight(x) w -= self.weight(y) rx = self.find(x) ry = self.find(y) if self.rank[rx] < self.rank[ry]: rx, ry = ry, rx w = -w self.par[ry] = self.par[rx] self.diff_weight[ry] = w if self.rank[rx] == self.rank[ry]: self.rank[rx] += 1 return True def isSame(self, x:int, y:int) -> bool: return self.find(x) == self.find(y) def diff(self, x:int, y:int) -> int: if self.isSame(x,y): return self.weight(y)-self.weight(x) else: raise ValueError("xとyは同じ木に属していません") n,m = li() lrd = [] for _ in range(m): l,r,d = li() l -= 1 r -= 1 lrd.append((l,r,d)) exist = True wuf = WeightedUnionFind(n) for l,r,d in lrd: wuf.unite(l,r,d) if wuf.diff(l,r) != d: exist = False break if exist: print("Yes") else: print("No")
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x)-1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) n,m = li() graph = [[] for _ in range(n)] for _ in range(m): l,r,d = li() l -= 1 r -= 1 graph[l].append((d,r)) graph[r].append((-d,l)) searched = [False]*n dist = [float("inf") for _ in range(n)] exist = True for i in range(n): if not searched[i]: dist[i] = 0 searched[i] = True stack = [(0,i)] while stack: cost, cur = stack.pop() for nex_cost, nex_node in graph[cur]: if searched[nex_node]: if cost + nex_cost != dist[nex_node]: exist = False else: stack.append((cost+nex_cost, nex_node)) dist[nex_node] = cost + nex_cost searched[nex_node] = True if exist: print("Yes") else: print("No")
93
50
2,341
1,356
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x) - 1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) class WeightedUnionFind: def __init__(self, node: int) -> None: self.n = node self.par = [i for i in range(self.n)] self.rank = [0 for i in range(self.n)] self.diff_weight = [0 for i in range(self.n)] # ノードxのルートを求める def find(self, x: int) -> int: if x == self.par[x]: return x else: r = self.find(self.par[x]) self.diff_weight[x] += self.diff_weight[self.par[x]] self.par[x] = r return self.par[x] # ノードxのルートからの距離を求める def weight(self, x: int) -> int: self.find(x) return self.diff_weight[x] # weight(y) - weight(x) = w となるようにする def unite(self, x: int, y: int, w: int) -> bool: if self.isSame(x, y): return False w += self.weight(x) w -= self.weight(y) rx = self.find(x) ry = self.find(y) if self.rank[rx] < self.rank[ry]: rx, ry = ry, rx w = -w self.par[ry] = self.par[rx] self.diff_weight[ry] = w if self.rank[rx] == self.rank[ry]: self.rank[rx] += 1 return True def isSame(self, x: int, y: int) -> bool: return self.find(x) == self.find(y) def diff(self, x: int, y: int) -> int: if self.isSame(x, y): return self.weight(y) - self.weight(x) else: raise ValueError("xとyは同じ木に属していません") n, m = li() lrd = [] for _ in range(m): l, r, d = li() l -= 1 r -= 1 lrd.append((l, r, d)) exist = True wuf = WeightedUnionFind(n) for l, r, d in lrd: wuf.unite(l, r, d) if wuf.diff(l, r) != d: exist = False break if exist: print("Yes") else: print("No")
import sys stdin = sys.stdin sys.setrecursionlimit(10**5) def li(): return list(map(int, stdin.readline().split())) def li_(): return [int(x) - 1 for x in stdin.readline().split()] def lf(): return list(map(float, stdin.readline().split())) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) n, m = li() graph = [[] for _ in range(n)] for _ in range(m): l, r, d = li() l -= 1 r -= 1 graph[l].append((d, r)) graph[r].append((-d, l)) searched = [False] * n dist = [float("inf") for _ in range(n)] exist = True for i in range(n): if not searched[i]: dist[i] = 0 searched[i] = True stack = [(0, i)] while stack: cost, cur = stack.pop() for nex_cost, nex_node in graph[cur]: if searched[nex_node]: if cost + nex_cost != dist[nex_node]: exist = False else: stack.append((cost + nex_cost, nex_node)) dist[nex_node] = cost + nex_cost searched[nex_node] = True if exist: print("Yes") else: print("No")
false
46.236559
[ "-class WeightedUnionFind:", "- def __init__(self, node: int) -> None:", "- self.n = node", "- self.par = [i for i in range(self.n)]", "- self.rank = [0 for i in range(self.n)]", "- self.diff_weight = [0 for i in range(self.n)]", "-", "- # ノードxのルートを求める", "- def find(self, x: int) -> int:", "- if x == self.par[x]:", "- return x", "- else:", "- r = self.find(self.par[x])", "- self.diff_weight[x] += self.diff_weight[self.par[x]]", "- self.par[x] = r", "- return self.par[x]", "-", "- # ノードxのルートからの距離を求める", "- def weight(self, x: int) -> int:", "- self.find(x)", "- return self.diff_weight[x]", "-", "- # weight(y) - weight(x) = w となるようにする", "- def unite(self, x: int, y: int, w: int) -> bool:", "- if self.isSame(x, y):", "- return False", "- w += self.weight(x)", "- w -= self.weight(y)", "- rx = self.find(x)", "- ry = self.find(y)", "- if self.rank[rx] < self.rank[ry]:", "- rx, ry = ry, rx", "- w = -w", "- self.par[ry] = self.par[rx]", "- self.diff_weight[ry] = w", "- if self.rank[rx] == self.rank[ry]:", "- self.rank[rx] += 1", "- return True", "-", "- def isSame(self, x: int, y: int) -> bool:", "- return self.find(x) == self.find(y)", "-", "- def diff(self, x: int, y: int) -> int:", "- if self.isSame(x, y):", "- return self.weight(y) - self.weight(x)", "- else:", "- raise ValueError(\"xとyは同じ木に属していません\")", "-", "-", "-lrd = []", "+graph = [[] for _ in range(n)]", "- lrd.append((l, r, d))", "+ graph[l].append((d, r))", "+ graph[r].append((-d, l))", "+searched = [False] * n", "+dist = [float(\"inf\") for _ in range(n)]", "-wuf = WeightedUnionFind(n)", "-for l, r, d in lrd:", "- wuf.unite(l, r, d)", "- if wuf.diff(l, r) != d:", "- exist = False", "- break", "+for i in range(n):", "+ if not searched[i]:", "+ dist[i] = 0", "+ searched[i] = True", "+ stack = [(0, i)]", "+ while stack:", "+ cost, cur = stack.pop()", "+ for nex_cost, nex_node in graph[cur]:", "+ if searched[nex_node]:", "+ if cost + nex_cost != dist[nex_node]:", "+ exist = False", "+ else:", "+ stack.append((cost + nex_cost, nex_node))", "+ dist[nex_node] = cost + nex_cost", "+ searched[nex_node] = True" ]
false
0.039118
0.040196
0.973169
[ "s837123648", "s840874930" ]
u638282348
p02714
python
s566411927
s498194695
1,808
460
27,228
76,036
Accepted
Accepted
74.56
from numpy import prod N = int(eval(input())) S = eval(input()) appearances = {"R": 0, "G": 0, "B": 0} for c in S: appearances[c] += 1 print((prod(list(appearances.values())) - sum(sum(len(set(S[start] + S[start + step] + S[start + step * 2])) == 3 for start in range(N - step * 2)) for step in range(1, N // 2 + 1))))
from functools import reduce from operator import mul N = int(eval(input())) S = eval(input()) appearances = {"R": 0, "G": 0, "B": 0} for c in S: appearances[c] += 1 print((reduce(mul, list(appearances.values())) - sum(sum(len(set(S[start] + S[start + step] + S[start + step * 2])) == 3 for start in range(N - step * 2)) for step in range(1, N // 2 + 1))))
7
8
315
354
from numpy import prod N = int(eval(input())) S = eval(input()) appearances = {"R": 0, "G": 0, "B": 0} for c in S: appearances[c] += 1 print( ( prod(list(appearances.values())) - sum( sum( len(set(S[start] + S[start + step] + S[start + step * 2])) == 3 for start in range(N - step * 2) ) for step in range(1, N // 2 + 1) ) ) )
from functools import reduce from operator import mul N = int(eval(input())) S = eval(input()) appearances = {"R": 0, "G": 0, "B": 0} for c in S: appearances[c] += 1 print( ( reduce(mul, list(appearances.values())) - sum( sum( len(set(S[start] + S[start + step] + S[start + step * 2])) == 3 for start in range(N - step * 2) ) for step in range(1, N // 2 + 1) ) ) )
false
12.5
[ "-from numpy import prod", "+from functools import reduce", "+from operator import mul", "- prod(list(appearances.values()))", "+ reduce(mul, list(appearances.values()))" ]
false
0.292045
0.061992
4.711016
[ "s566411927", "s498194695" ]
u200887663
p02573
python
s710690636
s377657786
1,689
1,252
575,372
107,964
Accepted
Accepted
25.87
#n = int(input()) import random import sys sys.setrecursionlimit(10 ** 7) n, m = list(map(int, input().split())) #n=200000 #m=200000 #al = list(map(int, input().split())) #l = [list(map(int,input().split())) for i in range(n)] adjl = [[] for _ in range(n+1)] NIL = -1 appear = {} isalone = {} for i in range(m): a, b = list(map(int, input().split())) #a=random.randrange(1,n+1) #b=random.randrange(1,n+1) #while a==b: # b=random.randrange(1,n+1) #print(a,b) if appear.get((a, b), False) or appear.get((a, b), False): continue appear[(a, b)] = True appear[(b, a)] = True isalone[a] = False isalone[b] = False adjl[a].append(b) adjl[b].append(a) color = [NIL for i in range(n+1)] color_id = 0 def dfs(u, color_id): global color color[u] = color_id for v in adjl[u]: if color[v] == NIL: # 未到達なら再起呼び出し color[v] = color_id dfs(v, color_id) for u in range(1, n+1): if color[u] == NIL: color_id += 1 dfs(u, color_id) group = {} for i in range(1, n+1): if isalone.get(i, True): continue group[color[i]] = group.get(color[i], 0)+1 mx = 1 for k, v in list(group.items()): mx = max(mx, v) print(mx)
#n = int(input()) from collections import deque n, m = list(map(int, input().split())) # n=200000 # m=200000 #al = list(map(int, input().split())) #l = [list(map(int,input().split())) for i in range(n)] adjl = [[] for _ in range(n+1)] NIL = -1 appear = {} isalone = {} for i in range(m): a, b = list(map(int, input().split())) if appear.get((a, b), False) or appear.get((a, b), False): continue appear[(a, b)] = True appear[(b, a)] = True isalone[a] = False isalone[b] = False adjl[a].append(b) adjl[b].append(a) NIL = -1 # 未発見を示す値 d = [-1 for i in range(n+1)] # 頂点1からの距離を格納するリスト color = [NIL for i in range(n+1)] # 未到達かを示すリスト def bfs(start_node, color_id): # uは探索の開始点 global color, d q = deque([start_node]) d[start_node] = 0 color[start_node] = color_id while len(q) != 0: u = q.popleft() for v in adjl[u]: if color[v] == NIL: d[v] = d[u]+1 color[v] = color_id q.append(v) color_id = 0 for u in range(1, n+1): if color[u] == NIL: color_id += 1 bfs(u, color_id) group = {} for i in range(1, n+1): if isalone.get(i, True): continue group[color[i]] = group.get(color[i], 0)+1 mx = 1 for k, v in list(group.items()): mx = max(mx, v) print(mx)
58
58
1,283
1,368
# n = int(input()) import random import sys sys.setrecursionlimit(10**7) n, m = list(map(int, input().split())) # n=200000 # m=200000 # al = list(map(int, input().split())) # l = [list(map(int,input().split())) for i in range(n)] adjl = [[] for _ in range(n + 1)] NIL = -1 appear = {} isalone = {} for i in range(m): a, b = list(map(int, input().split())) # a=random.randrange(1,n+1) # b=random.randrange(1,n+1) # while a==b: # b=random.randrange(1,n+1) # print(a,b) if appear.get((a, b), False) or appear.get((a, b), False): continue appear[(a, b)] = True appear[(b, a)] = True isalone[a] = False isalone[b] = False adjl[a].append(b) adjl[b].append(a) color = [NIL for i in range(n + 1)] color_id = 0 def dfs(u, color_id): global color color[u] = color_id for v in adjl[u]: if color[v] == NIL: # 未到達なら再起呼び出し color[v] = color_id dfs(v, color_id) for u in range(1, n + 1): if color[u] == NIL: color_id += 1 dfs(u, color_id) group = {} for i in range(1, n + 1): if isalone.get(i, True): continue group[color[i]] = group.get(color[i], 0) + 1 mx = 1 for k, v in list(group.items()): mx = max(mx, v) print(mx)
# n = int(input()) from collections import deque n, m = list(map(int, input().split())) # n=200000 # m=200000 # al = list(map(int, input().split())) # l = [list(map(int,input().split())) for i in range(n)] adjl = [[] for _ in range(n + 1)] NIL = -1 appear = {} isalone = {} for i in range(m): a, b = list(map(int, input().split())) if appear.get((a, b), False) or appear.get((a, b), False): continue appear[(a, b)] = True appear[(b, a)] = True isalone[a] = False isalone[b] = False adjl[a].append(b) adjl[b].append(a) NIL = -1 # 未発見を示す値 d = [-1 for i in range(n + 1)] # 頂点1からの距離を格納するリスト color = [NIL for i in range(n + 1)] # 未到達かを示すリスト def bfs(start_node, color_id): # uは探索の開始点 global color, d q = deque([start_node]) d[start_node] = 0 color[start_node] = color_id while len(q) != 0: u = q.popleft() for v in adjl[u]: if color[v] == NIL: d[v] = d[u] + 1 color[v] = color_id q.append(v) color_id = 0 for u in range(1, n + 1): if color[u] == NIL: color_id += 1 bfs(u, color_id) group = {} for i in range(1, n + 1): if isalone.get(i, True): continue group[color[i]] = group.get(color[i], 0) + 1 mx = 1 for k, v in list(group.items()): mx = max(mx, v) print(mx)
false
0
[ "-import random", "-import sys", "+from collections import deque", "-sys.setrecursionlimit(10**7)", "- # a=random.randrange(1,n+1)", "- # b=random.randrange(1,n+1)", "- # while a==b:", "- # b=random.randrange(1,n+1)", "- # print(a,b)", "-color = [NIL for i in range(n + 1)]", "-color_id = 0", "+NIL = -1 # 未発見を示す値", "+d = [-1 for i in range(n + 1)] # 頂点1からの距離を格納するリスト", "+color = [NIL for i in range(n + 1)] # 未到達かを示すリスト", "-def dfs(u, color_id):", "- global color", "- color[u] = color_id", "- for v in adjl[u]:", "- if color[v] == NIL: # 未到達なら再起呼び出し", "- color[v] = color_id", "- dfs(v, color_id)", "+def bfs(start_node, color_id): # uは探索の開始点", "+ global color, d", "+ q = deque([start_node])", "+ d[start_node] = 0", "+ color[start_node] = color_id", "+ while len(q) != 0:", "+ u = q.popleft()", "+ for v in adjl[u]:", "+ if color[v] == NIL:", "+ d[v] = d[u] + 1", "+ color[v] = color_id", "+ q.append(v)", "+color_id = 0", "- dfs(u, color_id)", "+ bfs(u, color_id)" ]
false
0.040128
0.038541
1.041189
[ "s710690636", "s377657786" ]
u397460030
p02314
python
s296424144
s559903523
970
680
47,252
11,760
Accepted
Accepted
29.9
from itertools import product class DP: def __init__(self, value, variety, coins): self.value = value self.variety = variety self.coins = coins self.DP = [[0 for _ in range(value + 1)] for _ in range(variety)] self.DPinit() def DPinit(self): for row in self.DP: row[1] = 1 self.DP[0] = [i for i in range(self.value + 1)] def DPcomp(self): for (m, n) in product(list(range(1, self.variety)),list(range(self.value + 1))): self.DP[m][n] = self.numberOfCoin(m, n) def numberOfCoin(self, m, n): if n >= self.coins[m]: return min(self.DP[m - 1][n], self.DP[m][n - self.coins[m]] + 1) else: return self.DP[m - 1][n] def answer(self): self.DPcomp() return self.DP[self.variety - 1][self.value] if __name__ == "__main__": status = list(map(int,input().split())) coins = list(map(int,input().split())) dp = DP(status[0],status[1],coins) print((dp.answer()))
from itertools import product value, variety = list(map(int, input().split())) coins = list(map(int, input().split())) dp = [float("inf") for _ in range(value + 1)] dp[0] = 0 for (c,j) in product(coins,list(range(value + 1))): if c <= j: dp[j] = min(dp[j], dp[j - c] + 1) else: dp[j] = dp[j] print((dp[value]))
35
12
1,070
338
from itertools import product class DP: def __init__(self, value, variety, coins): self.value = value self.variety = variety self.coins = coins self.DP = [[0 for _ in range(value + 1)] for _ in range(variety)] self.DPinit() def DPinit(self): for row in self.DP: row[1] = 1 self.DP[0] = [i for i in range(self.value + 1)] def DPcomp(self): for (m, n) in product( list(range(1, self.variety)), list(range(self.value + 1)) ): self.DP[m][n] = self.numberOfCoin(m, n) def numberOfCoin(self, m, n): if n >= self.coins[m]: return min(self.DP[m - 1][n], self.DP[m][n - self.coins[m]] + 1) else: return self.DP[m - 1][n] def answer(self): self.DPcomp() return self.DP[self.variety - 1][self.value] if __name__ == "__main__": status = list(map(int, input().split())) coins = list(map(int, input().split())) dp = DP(status[0], status[1], coins) print((dp.answer()))
from itertools import product value, variety = list(map(int, input().split())) coins = list(map(int, input().split())) dp = [float("inf") for _ in range(value + 1)] dp[0] = 0 for (c, j) in product(coins, list(range(value + 1))): if c <= j: dp[j] = min(dp[j], dp[j - c] + 1) else: dp[j] = dp[j] print((dp[value]))
false
65.714286
[ "-", "-class DP:", "- def __init__(self, value, variety, coins):", "- self.value = value", "- self.variety = variety", "- self.coins = coins", "- self.DP = [[0 for _ in range(value + 1)] for _ in range(variety)]", "- self.DPinit()", "-", "- def DPinit(self):", "- for row in self.DP:", "- row[1] = 1", "- self.DP[0] = [i for i in range(self.value + 1)]", "-", "- def DPcomp(self):", "- for (m, n) in product(", "- list(range(1, self.variety)), list(range(self.value + 1))", "- ):", "- self.DP[m][n] = self.numberOfCoin(m, n)", "-", "- def numberOfCoin(self, m, n):", "- if n >= self.coins[m]:", "- return min(self.DP[m - 1][n], self.DP[m][n - self.coins[m]] + 1)", "- else:", "- return self.DP[m - 1][n]", "-", "- def answer(self):", "- self.DPcomp()", "- return self.DP[self.variety - 1][self.value]", "-", "-", "-if __name__ == \"__main__\":", "- status = list(map(int, input().split()))", "- coins = list(map(int, input().split()))", "- dp = DP(status[0], status[1], coins)", "- print((dp.answer()))", "+value, variety = list(map(int, input().split()))", "+coins = list(map(int, input().split()))", "+dp = [float(\"inf\") for _ in range(value + 1)]", "+dp[0] = 0", "+for (c, j) in product(coins, list(range(value + 1))):", "+ if c <= j:", "+ dp[j] = min(dp[j], dp[j - c] + 1)", "+ else:", "+ dp[j] = dp[j]", "+print((dp[value]))" ]
false
0.085518
0.086173
0.992398
[ "s296424144", "s559903523" ]
u241159583
p03212
python
s104540311
s303902817
56
51
4,060
9,076
Accepted
Accepted
8.93
import itertools n = eval(input()) number = list("753") N = [] flag = False for i in range(3, 10): for v in itertools.product(number, repeat=i): if "7" in v and "5" in v and "3" in v: if int("".join(v)) <= int(n): N.append(int("".join(v))) print((len(N)))
import itertools n = int(eval(input())) cnt = 0 for i in range(3,len(str(n))+1): for v in itertools.product(["3","5","7"], repeat=i): if len(set(v))!=3: continue x = int("".join(v)) if n >= x: cnt += 1 print(cnt)
10
10
268
244
import itertools n = eval(input()) number = list("753") N = [] flag = False for i in range(3, 10): for v in itertools.product(number, repeat=i): if "7" in v and "5" in v and "3" in v: if int("".join(v)) <= int(n): N.append(int("".join(v))) print((len(N)))
import itertools n = int(eval(input())) cnt = 0 for i in range(3, len(str(n)) + 1): for v in itertools.product(["3", "5", "7"], repeat=i): if len(set(v)) != 3: continue x = int("".join(v)) if n >= x: cnt += 1 print(cnt)
false
0
[ "-n = eval(input())", "-number = list(\"753\")", "-N = []", "-flag = False", "-for i in range(3, 10):", "- for v in itertools.product(number, repeat=i):", "- if \"7\" in v and \"5\" in v and \"3\" in v:", "- if int(\"\".join(v)) <= int(n):", "- N.append(int(\"\".join(v)))", "-print((len(N)))", "+n = int(eval(input()))", "+cnt = 0", "+for i in range(3, len(str(n)) + 1):", "+ for v in itertools.product([\"3\", \"5\", \"7\"], repeat=i):", "+ if len(set(v)) != 3:", "+ continue", "+ x = int(\"\".join(v))", "+ if n >= x:", "+ cnt += 1", "+print(cnt)" ]
false
0.085642
0.04306
1.988904
[ "s104540311", "s303902817" ]
u312025627
p04019
python
s824825520
s790041200
177
17
38,256
2,940
Accepted
Accepted
90.4
s = {st for st in eval(input())} if ({'S','N'} & s == {'S','N'} or {'S','N'} & s == set()) and ({'E','W'} & s == {'E','W'} or {'E','W'} & s == set()): print("Yes") else: print("No")
def main(): S = eval(input()) we = ("W" in S and "E" in S) or ("W" not in S and "E" not in S) ns = ("N" in S and "S" in S) or ("N" not in S and "S" not in S) if we and ns: print("Yes") else: print("No") if __name__ == '__main__': main()
5
12
187
284
s = {st for st in eval(input())} if ({"S", "N"} & s == {"S", "N"} or {"S", "N"} & s == set()) and ( {"E", "W"} & s == {"E", "W"} or {"E", "W"} & s == set() ): print("Yes") else: print("No")
def main(): S = eval(input()) we = ("W" in S and "E" in S) or ("W" not in S and "E" not in S) ns = ("N" in S and "S" in S) or ("N" not in S and "S" not in S) if we and ns: print("Yes") else: print("No") if __name__ == "__main__": main()
false
58.333333
[ "-s = {st for st in eval(input())}", "-if ({\"S\", \"N\"} & s == {\"S\", \"N\"} or {\"S\", \"N\"} & s == set()) and (", "- {\"E\", \"W\"} & s == {\"E\", \"W\"} or {\"E\", \"W\"} & s == set()", "-):", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+def main():", "+ S = eval(input())", "+ we = (\"W\" in S and \"E\" in S) or (\"W\" not in S and \"E\" not in S)", "+ ns = (\"N\" in S and \"S\" in S) or (\"N\" not in S and \"S\" not in S)", "+ if we and ns:", "+ print(\"Yes\")", "+ else:", "+ print(\"No\")", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.042674
0.039167
1.089554
[ "s824825520", "s790041200" ]
u684120680
p03037
python
s780658594
s818665101
320
292
11,084
3,060
Accepted
Accepted
8.75
n, m = [int(i) for i in input().split()] l = [] r = [] for _ in range(m): l_tmp, r_tmp = [int(i) for i in input().split()] l.append(l_tmp) r.append(r_tmp) l_max = max(l) r_min = min(r) ans = r_min - l_max + 1 if ans > 0: print(ans) else: print((0))
n, m = [int(i) for i in input().split()] l_max = 0 r_min = float('inf') for _ in range(m): l, r = [int(i) for i in input().split()] if l > l_max: l_max = l if r < r_min: r_min = r ans = r_min - l_max + 1 if ans > 0: print(ans) else: print((0))
18
17
280
279
n, m = [int(i) for i in input().split()] l = [] r = [] for _ in range(m): l_tmp, r_tmp = [int(i) for i in input().split()] l.append(l_tmp) r.append(r_tmp) l_max = max(l) r_min = min(r) ans = r_min - l_max + 1 if ans > 0: print(ans) else: print((0))
n, m = [int(i) for i in input().split()] l_max = 0 r_min = float("inf") for _ in range(m): l, r = [int(i) for i in input().split()] if l > l_max: l_max = l if r < r_min: r_min = r ans = r_min - l_max + 1 if ans > 0: print(ans) else: print((0))
false
5.555556
[ "-l = []", "-r = []", "+l_max = 0", "+r_min = float(\"inf\")", "- l_tmp, r_tmp = [int(i) for i in input().split()]", "- l.append(l_tmp)", "- r.append(r_tmp)", "-l_max = max(l)", "-r_min = min(r)", "+ l, r = [int(i) for i in input().split()]", "+ if l > l_max:", "+ l_max = l", "+ if r < r_min:", "+ r_min = r" ]
false
0.043299
0.035751
1.211099
[ "s780658594", "s818665101" ]
u553987207
p02802
python
s823015781
s565365432
277
95
5,528
11,188
Accepted
Accepted
65.7
N, M = list(map(int, input().split())) ac = [False] * N wa = [0] * N for _ in range(M): p, s = input().split() p = int(p) - 1 if not ac[p]: if s == "AC": ac[p] = True else: wa[p] += 1 accnt = len([1 for x in ac if x]) wacnt = sum([wa[i] for i in range(N) if ac[i]]) print((accnt, wacnt))
import sys N, M = list(map(int, input().split())) ac = [0] * N wa = [0] * N for _ in range(M): p, s = sys.stdin.readline().split() p = int(p) - 1 if s == "AC": ac[p] = 1 else: if not ac[p]: wa[p] += 1 acnum = sum(ac) wanum = sum([c for i, c in enumerate(wa) if ac[i] == 1]) print((acnum, wanum))
14
16
344
347
N, M = list(map(int, input().split())) ac = [False] * N wa = [0] * N for _ in range(M): p, s = input().split() p = int(p) - 1 if not ac[p]: if s == "AC": ac[p] = True else: wa[p] += 1 accnt = len([1 for x in ac if x]) wacnt = sum([wa[i] for i in range(N) if ac[i]]) print((accnt, wacnt))
import sys N, M = list(map(int, input().split())) ac = [0] * N wa = [0] * N for _ in range(M): p, s = sys.stdin.readline().split() p = int(p) - 1 if s == "AC": ac[p] = 1 else: if not ac[p]: wa[p] += 1 acnum = sum(ac) wanum = sum([c for i, c in enumerate(wa) if ac[i] == 1]) print((acnum, wanum))
false
12.5
[ "+import sys", "+", "-ac = [False] * N", "+ac = [0] * N", "- p, s = input().split()", "+ p, s = sys.stdin.readline().split()", "- if not ac[p]:", "- if s == \"AC\":", "- ac[p] = True", "- else:", "+ if s == \"AC\":", "+ ac[p] = 1", "+ else:", "+ if not ac[p]:", "-accnt = len([1 for x in ac if x])", "-wacnt = sum([wa[i] for i in range(N) if ac[i]])", "-print((accnt, wacnt))", "+acnum = sum(ac)", "+wanum = sum([c for i, c in enumerate(wa) if ac[i] == 1])", "+print((acnum, wanum))" ]
false
0.039125
0.129595
0.3019
[ "s823015781", "s565365432" ]
u040298438
p03659
python
s755307743
s444233858
160
125
47,704
37,764
Accepted
Accepted
21.88
from itertools import accumulate eval(input()) a = list(map(int, input().split())) b = list(accumulate(a)) c = [abs(y * 2 - b[-1]) for y in b][:-1] print((min([abs(y * 2 - b[-1]) for y in b][:-1])))
from itertools import accumulate eval(input()) a = list(map(int, input().split())) b = list(accumulate(a)) print((min([abs(y * 2 - b[-1]) for y in b][:-1])))
7
6
197
155
from itertools import accumulate eval(input()) a = list(map(int, input().split())) b = list(accumulate(a)) c = [abs(y * 2 - b[-1]) for y in b][:-1] print((min([abs(y * 2 - b[-1]) for y in b][:-1])))
from itertools import accumulate eval(input()) a = list(map(int, input().split())) b = list(accumulate(a)) print((min([abs(y * 2 - b[-1]) for y in b][:-1])))
false
14.285714
[ "-c = [abs(y * 2 - b[-1]) for y in b][:-1]" ]
false
0.079647
0.07996
0.996086
[ "s755307743", "s444233858" ]
u367130284
p04039
python
s276681967
s808975093
181
126
3,188
2,940
Accepted
Accepted
30.39
s=set(range(10)) n,k,*a=list(map(int,open(0).read().split())) a=s-set(a) #使っていい数字 for t in range(n,100000): if set(list(map(int,list(str(t)))))<=a: print(t) break
x=lambda:input().split() n,_=x();a=x();n=int(n) while any(s in set(a)for s in str(n)):n+=1 print(n)
7
4
182
102
s = set(range(10)) n, k, *a = list(map(int, open(0).read().split())) a = s - set(a) # 使っていい数字 for t in range(n, 100000): if set(list(map(int, list(str(t))))) <= a: print(t) break
x = lambda: input().split() n, _ = x() a = x() n = int(n) while any(s in set(a) for s in str(n)): n += 1 print(n)
false
42.857143
[ "-s = set(range(10))", "-n, k, *a = list(map(int, open(0).read().split()))", "-a = s - set(a) # 使っていい数字", "-for t in range(n, 100000):", "- if set(list(map(int, list(str(t))))) <= a:", "- print(t)", "- break", "+x = lambda: input().split()", "+n, _ = x()", "+a = x()", "+n = int(n)", "+while any(s in set(a) for s in str(n)):", "+ n += 1", "+print(n)" ]
false
0.046915
0.042709
1.098463
[ "s276681967", "s808975093" ]
u901080241
p00474
python
s249117267
s175872778
430
350
28,172
20,456
Accepted
Accepted
18.6
n, l = list(map(int,input().split())) ai = [[int(eval(input())),i] for i in range(n)] ai.sort(key = lambda x: x[0]) time = [0]*(n+2) for i in ai: idx = i[1] time[idx+1] = max(time[idx],time[idx+2]) + l - i[0] print((max(time)))
n, l = list(map(int,input().split())) #ai = [[int(input()),i] for i in range(n)] ai = [[] for _ in range(l)] for i in range(n): ai[int(eval(input()))].append(i) time = [0]*(n+2) for i in range(l-1,0,-1): for j in ai[i]: time[j+1] = max(time[j],time[j+2]) + l - i print((max(time)))
10
12
232
296
n, l = list(map(int, input().split())) ai = [[int(eval(input())), i] for i in range(n)] ai.sort(key=lambda x: x[0]) time = [0] * (n + 2) for i in ai: idx = i[1] time[idx + 1] = max(time[idx], time[idx + 2]) + l - i[0] print((max(time)))
n, l = list(map(int, input().split())) # ai = [[int(input()),i] for i in range(n)] ai = [[] for _ in range(l)] for i in range(n): ai[int(eval(input()))].append(i) time = [0] * (n + 2) for i in range(l - 1, 0, -1): for j in ai[i]: time[j + 1] = max(time[j], time[j + 2]) + l - i print((max(time)))
false
16.666667
[ "-ai = [[int(eval(input())), i] for i in range(n)]", "-ai.sort(key=lambda x: x[0])", "+# ai = [[int(input()),i] for i in range(n)]", "+ai = [[] for _ in range(l)]", "+for i in range(n):", "+ ai[int(eval(input()))].append(i)", "-for i in ai:", "- idx = i[1]", "- time[idx + 1] = max(time[idx], time[idx + 2]) + l - i[0]", "+for i in range(l - 1, 0, -1):", "+ for j in ai[i]:", "+ time[j + 1] = max(time[j], time[j + 2]) + l - i" ]
false
0.102959
0.031631
3.254997
[ "s249117267", "s175872778" ]
u921729430
p02676
python
s545853075
s844027023
22
20
9,132
9,184
Accepted
Accepted
9.09
K = int(input()) S = input() for i ,s in enumerate(S): if i == K: print('...') break print(s, end='')
K = int(eval(input())) S = eval(input()) if len(S) <= K: print(S) else: print((S[:K] + "..."))
7
6
119
90
K = int(input()) S = input() for i, s in enumerate(S): if i == K: print("...") break print(s, end="")
K = int(eval(input())) S = eval(input()) if len(S) <= K: print(S) else: print((S[:K] + "..."))
false
14.285714
[ "-K = int(input())", "-S = input()", "-for i, s in enumerate(S):", "- if i == K:", "- print(\"...\")", "- break", "- print(s, end=\"\")", "+K = int(eval(input()))", "+S = eval(input())", "+if len(S) <= K:", "+ print(S)", "+else:", "+ print((S[:K] + \"...\"))" ]
false
0.047244
0.045116
1.047171
[ "s545853075", "s844027023" ]
u814986259
p03380
python
s695560382
s523639821
247
80
19,164
14,348
Accepted
Accepted
67.61
n = int(eval(input())) a = list(map(int, input().split())) ans=a.pop(a.index(max(a))) for i in range(n - 1): if a[i] > ans / 2: a[i] = [ans - a[i],a[i]] else: a[i] = [a[i],a[i]] a = sorted(a,reverse = True) print((str(ans) + " " + str(a[0][1])))
import math import bisect n = int(eval(input())) a = list(map(int, input().split())) a.sort() ncr = 0 ans = [0, 0] id = bisect.bisect_left(a[:n-1], a[n-1]//2) if abs(a[-1]/2 - a[id]) < abs(a[-1]/2 - a[id-1]): ans = id else: ans = id-1 print((a[-1], a[ans]))
14
19
278
282
n = int(eval(input())) a = list(map(int, input().split())) ans = a.pop(a.index(max(a))) for i in range(n - 1): if a[i] > ans / 2: a[i] = [ans - a[i], a[i]] else: a[i] = [a[i], a[i]] a = sorted(a, reverse=True) print((str(ans) + " " + str(a[0][1])))
import math import bisect n = int(eval(input())) a = list(map(int, input().split())) a.sort() ncr = 0 ans = [0, 0] id = bisect.bisect_left(a[: n - 1], a[n - 1] // 2) if abs(a[-1] / 2 - a[id]) < abs(a[-1] / 2 - a[id - 1]): ans = id else: ans = id - 1 print((a[-1], a[ans]))
false
26.315789
[ "+import math", "+import bisect", "+", "-ans = a.pop(a.index(max(a)))", "-for i in range(n - 1):", "- if a[i] > ans / 2:", "- a[i] = [ans - a[i], a[i]]", "- else:", "- a[i] = [a[i], a[i]]", "-a = sorted(a, reverse=True)", "-print((str(ans) + \" \" + str(a[0][1])))", "+a.sort()", "+ncr = 0", "+ans = [0, 0]", "+id = bisect.bisect_left(a[: n - 1], a[n - 1] // 2)", "+if abs(a[-1] / 2 - a[id]) < abs(a[-1] / 2 - a[id - 1]):", "+ ans = id", "+else:", "+ ans = id - 1", "+print((a[-1], a[ans]))" ]
false
0.045521
0.042756
1.064666
[ "s695560382", "s523639821" ]
u123135189
p03304
python
s037903618
s799804829
20
17
3,316
2,940
Accepted
Accepted
15
n, m, d = list(map(int,input().split())) if d == 0: p = n elif n < d: p = 0 else: p = (n * 2 - d * 2) r = p / (n * n) a = r * (m - 1) print((round(a, 8)))
n, m, d = list(map(int,input().split())) if d == 0: p = n else: p = (n * 2 - d * 2) r = p / (n * n) a = r * (m - 1) print((round(a, 8)))
10
8
168
144
n, m, d = list(map(int, input().split())) if d == 0: p = n elif n < d: p = 0 else: p = n * 2 - d * 2 r = p / (n * n) a = r * (m - 1) print((round(a, 8)))
n, m, d = list(map(int, input().split())) if d == 0: p = n else: p = n * 2 - d * 2 r = p / (n * n) a = r * (m - 1) print((round(a, 8)))
false
20
[ "-elif n < d:", "- p = 0" ]
false
0.048456
0.048317
1.002882
[ "s037903618", "s799804829" ]
u535423069
p03371
python
s483424211
s726547596
65
17
3,064
3,064
Accepted
Accepted
73.85
import sys stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() nas = lambda: stdin.readline().split() a, b, c, x, y = na() ans = 0 while x or y: if x and y: if a + b > c * 2: x -= 1 y -= 1 ans += c * 2 else: x -= 1 y -= 1 ans += a + b else: q = c * 2 * (x + y) if q <= a * x + b * y: ans += c * 2 * (x + y) x = 0 y = 0 if x: ans += a * x x = 0 if y: ans += b * y y = 0 print(ans)
import sys stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() nas = lambda: stdin.readline().split() a, b, c, x, y = na() ans = 0 while x or y: if x and y: if a + b > c * 2: z = min(x, y) x -= z y -= z ans += c * 2 * z else: z = min(x, y) x -= z y -= z ans += (a + b) * z else: q = c * 2 * (x + y) if q <= a * x + b * y: ans += c * 2 * (x + y) x = 0 y = 0 if x: ans += a * x x = 0 if y: ans += b * y y = 0 print(ans)
36
38
715
779
import sys stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() nas = lambda: stdin.readline().split() a, b, c, x, y = na() ans = 0 while x or y: if x and y: if a + b > c * 2: x -= 1 y -= 1 ans += c * 2 else: x -= 1 y -= 1 ans += a + b else: q = c * 2 * (x + y) if q <= a * x + b * y: ans += c * 2 * (x + y) x = 0 y = 0 if x: ans += a * x x = 0 if y: ans += b * y y = 0 print(ans)
import sys stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() nas = lambda: stdin.readline().split() a, b, c, x, y = na() ans = 0 while x or y: if x and y: if a + b > c * 2: z = min(x, y) x -= z y -= z ans += c * 2 * z else: z = min(x, y) x -= z y -= z ans += (a + b) * z else: q = c * 2 * (x + y) if q <= a * x + b * y: ans += c * 2 * (x + y) x = 0 y = 0 if x: ans += a * x x = 0 if y: ans += b * y y = 0 print(ans)
false
5.263158
[ "- x -= 1", "- y -= 1", "- ans += c * 2", "+ z = min(x, y)", "+ x -= z", "+ y -= z", "+ ans += c * 2 * z", "- x -= 1", "- y -= 1", "- ans += a + b", "+ z = min(x, y)", "+ x -= z", "+ y -= z", "+ ans += (a + b) * z" ]
false
0.058129
0.046868
1.240277
[ "s483424211", "s726547596" ]
u246809151
p02711
python
s804137706
s893944353
22
20
9,096
9,028
Accepted
Accepted
9.09
import sys A = eval(input()) for i in range(len(A)): if A[i] == '7': print('Yes') sys.exit() print('No')
N = eval(input()) ans = list(set(N)) #print(ans) if ans.count('7'): print('Yes') else: print('No')
9
7
128
107
import sys A = eval(input()) for i in range(len(A)): if A[i] == "7": print("Yes") sys.exit() print("No")
N = eval(input()) ans = list(set(N)) # print(ans) if ans.count("7"): print("Yes") else: print("No")
false
22.222222
[ "-import sys", "-", "-A = eval(input())", "-for i in range(len(A)):", "- if A[i] == \"7\":", "- print(\"Yes\")", "- sys.exit()", "-print(\"No\")", "+N = eval(input())", "+ans = list(set(N))", "+# print(ans)", "+if ans.count(\"7\"):", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.092966
0.104074
0.89327
[ "s804137706", "s893944353" ]
u888092736
p02725
python
s637666815
s736419591
149
118
26,460
31,664
Accepted
Accepted
20.81
k, n = list(map(int, input().split())) A = list(map(int, input().split())) max_dist = 0 for i in range(n - 1): max_dist = max(max_dist, A[i + 1] - A[i]) max_dist = max(max_dist, A[0] + k - A[i + 1]) print((k - max_dist))
K, N, *A = list(map(int, open(0).read().split())) A = [A[-1] - K] + A max_gap = 0 for a1, a2 in zip(A, A[1:]): max_gap = max(max_gap, a2 - a1) print((K - max_gap))
9
7
227
167
k, n = list(map(int, input().split())) A = list(map(int, input().split())) max_dist = 0 for i in range(n - 1): max_dist = max(max_dist, A[i + 1] - A[i]) max_dist = max(max_dist, A[0] + k - A[i + 1]) print((k - max_dist))
K, N, *A = list(map(int, open(0).read().split())) A = [A[-1] - K] + A max_gap = 0 for a1, a2 in zip(A, A[1:]): max_gap = max(max_gap, a2 - a1) print((K - max_gap))
false
22.222222
[ "-k, n = list(map(int, input().split()))", "-A = list(map(int, input().split()))", "-max_dist = 0", "-for i in range(n - 1):", "- max_dist = max(max_dist, A[i + 1] - A[i])", "-max_dist = max(max_dist, A[0] + k - A[i + 1])", "-print((k - max_dist))", "+K, N, *A = list(map(int, open(0).read().split()))", "+A = [A[-1] - K] + A", "+max_gap = 0", "+for a1, a2 in zip(A, A[1:]):", "+ max_gap = max(max_gap, a2 - a1)", "+print((K - max_gap))" ]
false
0.043852
0.040637
1.0791
[ "s637666815", "s736419591" ]
u864013199
p02731
python
s231320964
s183925724
37
18
5,332
2,940
Accepted
Accepted
51.35
from decimal import Decimal L = int(eval(input())) print((Decimal(L/3)**3))
L = int(eval(input())) print(((L/3)**3))
3
2
70
33
from decimal import Decimal L = int(eval(input())) print((Decimal(L / 3) ** 3))
L = int(eval(input())) print(((L / 3) ** 3))
false
33.333333
[ "-from decimal import Decimal", "-", "-print((Decimal(L / 3) ** 3))", "+print(((L / 3) ** 3))" ]
false
0.037928
0.039625
0.957165
[ "s231320964", "s183925724" ]
u426572476
p03671
python
s545856294
s764782001
19
17
2,940
2,940
Accepted
Accepted
10.53
import math a, b, c = list(map(int, input().split())) print((min(a + b, b + c, c + a)))
import math a = [int(i) for i in input().split()] print((sum(a) - max(a)))
4
4
83
76
import math a, b, c = list(map(int, input().split())) print((min(a + b, b + c, c + a)))
import math a = [int(i) for i in input().split()] print((sum(a) - max(a)))
false
0
[ "-a, b, c = list(map(int, input().split()))", "-print((min(a + b, b + c, c + a)))", "+a = [int(i) for i in input().split()]", "+print((sum(a) - max(a)))" ]
false
0.069515
0.008485
8.192269
[ "s545856294", "s764782001" ]
u203843959
p04000
python
s381951987
s139698080
2,199
1,864
150,516
186,608
Accepted
Accepted
15.23
H,W,N=list(map(int,input().split())) allcase=(H-2)*(W-2) abset=set() for _ in range(N): a,b=list(map(int,input().split())) abset.add((a-1,b-1)) #print(abset) memo={} def count_black(x,y): if (x,y) in memo: return memo[(x,y)] num_black=0 for ii in range(3): for jj in range(3): if (x+ii,y+jj) in abset: num_black+=1 memo[(x,y)]=num_black return num_black case_list=[0]*10 for a,b in abset: for j in range(3): if a-j<0 or H-2<=a-j: continue for k in range(3): if b-k<0 or W-2<=b-k: continue count_black(a-j,b-k) #print(memo) case_list=[0]*10 for v in list(memo.values()): case_list[v]+=1 case_list[0]=allcase-sum(case_list[1:]) #print(case_list) for i in range(10): print((case_list[i]))
from collections import defaultdict H,W,N=list(map(int,input().split())) allcase=(H-2)*(W-2) abset=set() for _ in range(N): a,b=list(map(int,input().split())) abset.add((a-1,b-1)) #print(abset) memo=defaultdict(int) for a,b in abset: for j in range(-2,1): if a+j<0 or H-2<=a+j: continue for k in range(-2,1): if b+k<0 or W-2<=b+k: continue memo[(a+j,b+k)]+=1 #print(memo) case_list=[0]*10 for v in list(memo.values()): case_list[v]+=1 case_list[0]=allcase-sum(case_list[1:]) #print(case_list) for i in range(10): print((case_list[i]))
43
30
807
598
H, W, N = list(map(int, input().split())) allcase = (H - 2) * (W - 2) abset = set() for _ in range(N): a, b = list(map(int, input().split())) abset.add((a - 1, b - 1)) # print(abset) memo = {} def count_black(x, y): if (x, y) in memo: return memo[(x, y)] num_black = 0 for ii in range(3): for jj in range(3): if (x + ii, y + jj) in abset: num_black += 1 memo[(x, y)] = num_black return num_black case_list = [0] * 10 for a, b in abset: for j in range(3): if a - j < 0 or H - 2 <= a - j: continue for k in range(3): if b - k < 0 or W - 2 <= b - k: continue count_black(a - j, b - k) # print(memo) case_list = [0] * 10 for v in list(memo.values()): case_list[v] += 1 case_list[0] = allcase - sum(case_list[1:]) # print(case_list) for i in range(10): print((case_list[i]))
from collections import defaultdict H, W, N = list(map(int, input().split())) allcase = (H - 2) * (W - 2) abset = set() for _ in range(N): a, b = list(map(int, input().split())) abset.add((a - 1, b - 1)) # print(abset) memo = defaultdict(int) for a, b in abset: for j in range(-2, 1): if a + j < 0 or H - 2 <= a + j: continue for k in range(-2, 1): if b + k < 0 or W - 2 <= b + k: continue memo[(a + j, b + k)] += 1 # print(memo) case_list = [0] * 10 for v in list(memo.values()): case_list[v] += 1 case_list[0] = allcase - sum(case_list[1:]) # print(case_list) for i in range(10): print((case_list[i]))
false
30.232558
[ "+from collections import defaultdict", "+", "-memo = {}", "-", "-", "-def count_black(x, y):", "- if (x, y) in memo:", "- return memo[(x, y)]", "- num_black = 0", "- for ii in range(3):", "- for jj in range(3):", "- if (x + ii, y + jj) in abset:", "- num_black += 1", "- memo[(x, y)] = num_black", "- return num_black", "-", "-", "-case_list = [0] * 10", "+memo = defaultdict(int)", "- for j in range(3):", "- if a - j < 0 or H - 2 <= a - j:", "+ for j in range(-2, 1):", "+ if a + j < 0 or H - 2 <= a + j:", "- for k in range(3):", "- if b - k < 0 or W - 2 <= b - k:", "+ for k in range(-2, 1):", "+ if b + k < 0 or W - 2 <= b + k:", "- count_black(a - j, b - k)", "+ memo[(a + j, b + k)] += 1" ]
false
0.081275
0.151641
0.535968
[ "s381951987", "s139698080" ]
u810735437
p03320
python
s579759296
s684650460
405
358
81,880
70,764
Accepted
Accepted
11.6
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import array from bisect import * from collections import * import fractions import heapq from itertools import * import math import random import re import string import sys def T(k): orig_k = k sk = 0 while k > 0: sk += k % 10 k //= 10 return orig_k / sk d = {} MAX = int(1e15) + 1e9 for i in range(1, 9999): t = i while t < MAX: d[t] = T(t) t = t * 10 + 9 keys = sorted(list(d.keys())) # for k in keys: # print(k, d[k]) mn = None ans = [] for k in reversed(keys): if mn == None: ans.append(k) mn = d[k] else: if mn >= d[k]: ans.append(k) mn = min(mn, d[k]) ans.reverse() K = int(eval(input())) ans = ans[:K] for a in ans: print(a)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import array from bisect import * from collections import * import fractions import heapq from itertools import * import math import random import re import string import sys def T(k): orig_k = k sk = 0 while k > 0: sk += k % 10 k //= 10 return orig_k / sk d = {} MAX = int(1e15) + 1e9 for i in range(1, 999): t = i while t < MAX: d[t] = T(t) t = t * 10 + 9 keys = sorted(list(d.keys())) # for k in keys: # print(k, d[k]) mn = None ans = [] for k in reversed(keys): if mn == None: ans.append(k) mn = d[k] else: if mn >= d[k]: ans.append(k) mn = min(mn, d[k]) ans.reverse() K = int(eval(input())) ans = ans[:K] for a in ans: print(a)
53
53
856
855
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import array from bisect import * from collections import * import fractions import heapq from itertools import * import math import random import re import string import sys def T(k): orig_k = k sk = 0 while k > 0: sk += k % 10 k //= 10 return orig_k / sk d = {} MAX = int(1e15) + 1e9 for i in range(1, 9999): t = i while t < MAX: d[t] = T(t) t = t * 10 + 9 keys = sorted(list(d.keys())) # for k in keys: # print(k, d[k]) mn = None ans = [] for k in reversed(keys): if mn == None: ans.append(k) mn = d[k] else: if mn >= d[k]: ans.append(k) mn = min(mn, d[k]) ans.reverse() K = int(eval(input())) ans = ans[:K] for a in ans: print(a)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import array from bisect import * from collections import * import fractions import heapq from itertools import * import math import random import re import string import sys def T(k): orig_k = k sk = 0 while k > 0: sk += k % 10 k //= 10 return orig_k / sk d = {} MAX = int(1e15) + 1e9 for i in range(1, 999): t = i while t < MAX: d[t] = T(t) t = t * 10 + 9 keys = sorted(list(d.keys())) # for k in keys: # print(k, d[k]) mn = None ans = [] for k in reversed(keys): if mn == None: ans.append(k) mn = d[k] else: if mn >= d[k]: ans.append(k) mn = min(mn, d[k]) ans.reverse() K = int(eval(input())) ans = ans[:K] for a in ans: print(a)
false
0
[ "-for i in range(1, 9999):", "+for i in range(1, 999):" ]
false
0.353994
0.091284
3.877953
[ "s579759296", "s684650460" ]
u367701763
p03557
python
s529277756
s937066011
487
449
107,108
106,980
Accepted
Accepted
7.8
from bisect import bisect_left from collections import defaultdict N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) num_a = 0 num_c = 0 res = 0 pre_b = -1 dict_C = defaultdict(int) for b in B: if b == pre_b: res += num_a * num_c continue num_a = bisect_left(A, b) # a < b となるAの要素数 pre_num_c = bisect_left(C, b) num_c = N - pre_num_c # c > b となるAの要素数 if pre_num_c != N and C[pre_num_c] == b: num_c = N - bisect_left(C, b+1) res += num_a * num_c pre_b = b print(res)
from bisect import bisect_left from bisect import bisect_right N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) num_a = 0 num_c = 0 res = 0 pre_b = -1 for b in B: if b == pre_b: res += num_a * num_c continue num_a = bisect_left(A, b) # a < b となるAの要素数 pre_num_c = bisect_right(C, b) num_c = N - pre_num_c # c > b となるAの要素数 res += num_a * num_c pre_b = b print(res)
29
25
651
532
from bisect import bisect_left from collections import defaultdict N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) num_a = 0 num_c = 0 res = 0 pre_b = -1 dict_C = defaultdict(int) for b in B: if b == pre_b: res += num_a * num_c continue num_a = bisect_left(A, b) # a < b となるAの要素数 pre_num_c = bisect_left(C, b) num_c = N - pre_num_c # c > b となるAの要素数 if pre_num_c != N and C[pre_num_c] == b: num_c = N - bisect_left(C, b + 1) res += num_a * num_c pre_b = b print(res)
from bisect import bisect_left from bisect import bisect_right N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) num_a = 0 num_c = 0 res = 0 pre_b = -1 for b in B: if b == pre_b: res += num_a * num_c continue num_a = bisect_left(A, b) # a < b となるAの要素数 pre_num_c = bisect_right(C, b) num_c = N - pre_num_c # c > b となるAの要素数 res += num_a * num_c pre_b = b print(res)
false
13.793103
[ "-from collections import defaultdict", "+from bisect import bisect_right", "-dict_C = defaultdict(int)", "- pre_num_c = bisect_left(C, b)", "+ pre_num_c = bisect_right(C, b)", "- if pre_num_c != N and C[pre_num_c] == b:", "- num_c = N - bisect_left(C, b + 1)" ]
false
0.042531
0.03955
1.075381
[ "s529277756", "s937066011" ]
u707124227
p03095
python
s720639460
s180469853
38
25
3,444
3,444
Accepted
Accepted
34.21
from collections import defaultdict n=int(eval(input())) s=eval(input()) mod=pow(10,9)+7 sd=defaultdict(lambda:1) for i in range(n): sd[s[i]]+=1 ans=1 for k in list(sd.keys()): ans*=(sd[k])%mod print((ans%mod-1))
from collections import Counter mod=pow(10,9)+7 n=int(eval(input())) s=eval(input()) cs=Counter(s) ans=1 for a in list(cs.values()): ans*=a+1 ans%=mod print((ans-1))
11
10
215
158
from collections import defaultdict n = int(eval(input())) s = eval(input()) mod = pow(10, 9) + 7 sd = defaultdict(lambda: 1) for i in range(n): sd[s[i]] += 1 ans = 1 for k in list(sd.keys()): ans *= (sd[k]) % mod print((ans % mod - 1))
from collections import Counter mod = pow(10, 9) + 7 n = int(eval(input())) s = eval(input()) cs = Counter(s) ans = 1 for a in list(cs.values()): ans *= a + 1 ans %= mod print((ans - 1))
false
9.090909
[ "-from collections import defaultdict", "+from collections import Counter", "+mod = pow(10, 9) + 7", "-mod = pow(10, 9) + 7", "-sd = defaultdict(lambda: 1)", "-for i in range(n):", "- sd[s[i]] += 1", "+cs = Counter(s)", "-for k in list(sd.keys()):", "- ans *= (sd[k]) % mod", "-print((ans % mod - 1))", "+for a in list(cs.values()):", "+ ans *= a + 1", "+ ans %= mod", "+print((ans - 1))" ]
false
0.038341
0.046753
0.820077
[ "s720639460", "s180469853" ]
u094191970
p03476
python
s119823502
s815598764
1,915
867
4,356
5,292
Accepted
Accepted
54.73
def factorization(n): p=2 fcr=[] while p*p<=n: while n%p==0: fcr.append(p) n//=p p+=1 if n>1: fcr.append(n) return fcr q=int(eval(input())) cnt=1 p_list=[1] q_list=[0] for i in range(3,10**5+1,2): a=factorization(i) b=factorization((i+1)//2) if len(a)==len(b)==1: cnt+=1 q_list.append(1) else: q_list.append(0) p_list.append(cnt) for i in range(q): l,r=list(map(int,input().split())) c=p_list[r//2]-p_list[l//2] if q_list[l//2]==1: print((c+1)) else: print(c)
def eratosthenes(n): is_p=[1]*n p_list=[] is_p[0]=0 is_p[1]=0 for i in range(2,n): if is_p[i]: p_list.append(i) for j in range(i*i,n,i): is_p[j] = 0 # return p_list return is_p q=int(eval(input())) lim=10**5+1 is_p=eratosthenes(lim) #print(is_p) b=[0] for i in range(1,lim+1): if is_p[i-1]==1 and is_p[i//2]==1: b.append(b[i-1]+1) else: b.append(b[i-1]) #print(b) for i in range(q): l,r=list(map(int,input().split())) print((b[r+1]-b[l]))
37
35
523
493
def factorization(n): p = 2 fcr = [] while p * p <= n: while n % p == 0: fcr.append(p) n //= p p += 1 if n > 1: fcr.append(n) return fcr q = int(eval(input())) cnt = 1 p_list = [1] q_list = [0] for i in range(3, 10**5 + 1, 2): a = factorization(i) b = factorization((i + 1) // 2) if len(a) == len(b) == 1: cnt += 1 q_list.append(1) else: q_list.append(0) p_list.append(cnt) for i in range(q): l, r = list(map(int, input().split())) c = p_list[r // 2] - p_list[l // 2] if q_list[l // 2] == 1: print((c + 1)) else: print(c)
def eratosthenes(n): is_p = [1] * n p_list = [] is_p[0] = 0 is_p[1] = 0 for i in range(2, n): if is_p[i]: p_list.append(i) for j in range(i * i, n, i): is_p[j] = 0 # return p_list return is_p q = int(eval(input())) lim = 10**5 + 1 is_p = eratosthenes(lim) # print(is_p) b = [0] for i in range(1, lim + 1): if is_p[i - 1] == 1 and is_p[i // 2] == 1: b.append(b[i - 1] + 1) else: b.append(b[i - 1]) # print(b) for i in range(q): l, r = list(map(int, input().split())) print((b[r + 1] - b[l]))
false
5.405405
[ "-def factorization(n):", "- p = 2", "- fcr = []", "- while p * p <= n:", "- while n % p == 0:", "- fcr.append(p)", "- n //= p", "- p += 1", "- if n > 1:", "- fcr.append(n)", "- return fcr", "+def eratosthenes(n):", "+ is_p = [1] * n", "+ p_list = []", "+ is_p[0] = 0", "+ is_p[1] = 0", "+ for i in range(2, n):", "+ if is_p[i]:", "+ p_list.append(i)", "+ for j in range(i * i, n, i):", "+ is_p[j] = 0", "+ # return p_list", "+ return is_p", "-cnt = 1", "-p_list = [1]", "-q_list = [0]", "-for i in range(3, 10**5 + 1, 2):", "- a = factorization(i)", "- b = factorization((i + 1) // 2)", "- if len(a) == len(b) == 1:", "- cnt += 1", "- q_list.append(1)", "+lim = 10**5 + 1", "+is_p = eratosthenes(lim)", "+# print(is_p)", "+b = [0]", "+for i in range(1, lim + 1):", "+ if is_p[i - 1] == 1 and is_p[i // 2] == 1:", "+ b.append(b[i - 1] + 1)", "- q_list.append(0)", "- p_list.append(cnt)", "+ b.append(b[i - 1])", "+# print(b)", "- c = p_list[r // 2] - p_list[l // 2]", "- if q_list[l // 2] == 1:", "- print((c + 1))", "- else:", "- print(c)", "+ print((b[r + 1] - b[l]))" ]
false
3.075451
0.463357
6.637331
[ "s119823502", "s815598764" ]