user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
sequence
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
sequence
u462434199
p03283
python
s036876361
s250792567
2,045
1,857
78,460
57,540
Accepted
Accepted
9.19
import numpy as np n,m,q=list(map(int, input().split())) a=[list(map(int, input().split())) for i in range(m)] b=[list(map(int, input().split())) for i in range(q)] x=np.zeros((501, 501), dtype=np.int) for i in range(m): x[a[i][0], a[i][1]]+=1 np.cumsum(x, axis=0, out=x) np.cumsum(x, axis=1, out=x) for i in range(q): v1=b[i][0] v2=b[i][1] a1=x[v2, v2] a2=x[v2, v1-1] a3=x[v1-1, v2] a4=x[v1-1, v1-1] print((a1-a2-a3+a4))
import numpy as np n,m,q=list(map(int, input().split())) a=np.array([list(map(int, input().split())) for i in range(m)]) b=[list(map(int, input().split())) for i in range(q)] x=np.zeros((501, 501), dtype=np.int) np.add.at(x, (a[:, 0], a[:, 1]), 1) np.cumsum(x, axis=0, out=x) np.cumsum(x, axis=1, out=x) for i in range(q): v1=b[i][0] v2=b[i][1] a1=x[v2, v2] a2=x[v2, v1-1] a3=x[v1-1, v2] a4=x[v1-1, v1-1] print((a1-a2-a3+a4))
23
22
480
479
import numpy as np n, m, q = list(map(int, input().split())) a = [list(map(int, input().split())) for i in range(m)] b = [list(map(int, input().split())) for i in range(q)] x = np.zeros((501, 501), dtype=np.int) for i in range(m): x[a[i][0], a[i][1]] += 1 np.cumsum(x, axis=0, out=x) np.cumsum(x, axis=1, out=x) for i in range(q): v1 = b[i][0] v2 = b[i][1] a1 = x[v2, v2] a2 = x[v2, v1 - 1] a3 = x[v1 - 1, v2] a4 = x[v1 - 1, v1 - 1] print((a1 - a2 - a3 + a4))
import numpy as np n, m, q = list(map(int, input().split())) a = np.array([list(map(int, input().split())) for i in range(m)]) b = [list(map(int, input().split())) for i in range(q)] x = np.zeros((501, 501), dtype=np.int) np.add.at(x, (a[:, 0], a[:, 1]), 1) np.cumsum(x, axis=0, out=x) np.cumsum(x, axis=1, out=x) for i in range(q): v1 = b[i][0] v2 = b[i][1] a1 = x[v2, v2] a2 = x[v2, v1 - 1] a3 = x[v1 - 1, v2] a4 = x[v1 - 1, v1 - 1] print((a1 - a2 - a3 + a4))
false
4.347826
[ "-a = [list(map(int, input().split())) for i in range(m)]", "+a = np.array([list(map(int, input().split())) for i in range(m)])", "-for i in range(m):", "- x[a[i][0], a[i][1]] += 1", "+np.add.at(x, (a[:, 0], a[:, 1]), 1)" ]
false
0.198674
0.270614
0.734161
[ "s036876361", "s250792567" ]
u564589929
p02819
python
s030656868
s575860031
30
21
3,316
3,316
Accepted
Accepted
30
import sys sys.setrecursionlimit(10 ** 6) # input = sys.stdin.readline #### def int1(x): return int(x) - 1 def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def MI1(): return list(map(int1, input().split())) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return input().split() def printlist(lst, k='\n'): print((k.join(list(map(str, lst))))) INF = float('inf') from math import ceil, floor, log2 from collections import deque from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product from heapq import heapify, heappop, heappush def solve(): X = II() while 1: for i in range(2, X): if X % i == 0: break else: print(X) return X += 1 if __name__ == '__main__': solve()
import sys sys.setrecursionlimit(10 ** 6) # input = sys.stdin.readline #### def int1(x): return int(x) - 1 def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def MI1(): return list(map(int1, input().split())) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return input().split() def printlist(lst, k='\n'): print((k.join(list(map(str, lst))))) INF = float('inf') from math import ceil, floor, log2 from collections import deque from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product from heapq import heapify, heappop, heappush def solve(): X = II() while 1: for i in range(2, int(pow(X, 0.5))+1): if X % i == 0: break else: print(X) return X += 1 if __name__ == '__main__': solve()
41
41
1,000
1,017
import sys sys.setrecursionlimit(10**6) # input = sys.stdin.readline #### def int1(x): return int(x) - 1 def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def MI1(): return list(map(int1, input().split())) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return input().split() def printlist(lst, k="\n"): print((k.join(list(map(str, lst))))) INF = float("inf") from math import ceil, floor, log2 from collections import deque from itertools import ( combinations as comb, combinations_with_replacement as comb_w, accumulate, product, ) from heapq import heapify, heappop, heappush def solve(): X = II() while 1: for i in range(2, X): if X % i == 0: break else: print(X) return X += 1 if __name__ == "__main__": solve()
import sys sys.setrecursionlimit(10**6) # input = sys.stdin.readline #### def int1(x): return int(x) - 1 def II(): return int(eval(input())) def MI(): return list(map(int, input().split())) def MI1(): return list(map(int1, input().split())) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return input().split() def printlist(lst, k="\n"): print((k.join(list(map(str, lst))))) INF = float("inf") from math import ceil, floor, log2 from collections import deque from itertools import ( combinations as comb, combinations_with_replacement as comb_w, accumulate, product, ) from heapq import heapify, heappop, heappush def solve(): X = II() while 1: for i in range(2, int(pow(X, 0.5)) + 1): if X % i == 0: break else: print(X) return X += 1 if __name__ == "__main__": solve()
false
0
[ "- for i in range(2, X):", "+ for i in range(2, int(pow(X, 0.5)) + 1):" ]
false
0.062059
0.059835
1.037172
[ "s030656868", "s575860031" ]
u644907318
p03862
python
s434806478
s666385373
223
84
63,856
84,948
Accepted
Accepted
62.33
N,x = list(map(int,input().split())) A = list(map(int,input().split())) ans = 0 for i in range(1,N): y = max(A[i]+A[i-1]-x,0) if A[i]>=y: A[i] -= y else: A[i] = 0 ans += y print(ans)
N,x = list(map(int,input().split())) A = list(map(int,input().split())) cnt = 0 for i in range(1,N): if A[i]+A[i-1]>x: d = A[i]+A[i-1]-x if A[i]>=d: A[i] -= d cnt += d else: A[i]=0 cnt += A[i] d -= A[i] A[i-1] -= d cnt += d print(cnt)
11
16
226
355
N, x = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 for i in range(1, N): y = max(A[i] + A[i - 1] - x, 0) if A[i] >= y: A[i] -= y else: A[i] = 0 ans += y print(ans)
N, x = list(map(int, input().split())) A = list(map(int, input().split())) cnt = 0 for i in range(1, N): if A[i] + A[i - 1] > x: d = A[i] + A[i - 1] - x if A[i] >= d: A[i] -= d cnt += d else: A[i] = 0 cnt += A[i] d -= A[i] A[i - 1] -= d cnt += d print(cnt)
false
31.25
[ "-ans = 0", "+cnt = 0", "- y = max(A[i] + A[i - 1] - x, 0)", "- if A[i] >= y:", "- A[i] -= y", "- else:", "- A[i] = 0", "- ans += y", "-print(ans)", "+ if A[i] + A[i - 1] > x:", "+ d = A[i] + A[i - 1] - x", "+ if A[i] >= d:", "+ A[i] -= d", "+ cnt += d", "+ else:", "+ A[i] = 0", "+ cnt += A[i]", "+ d -= A[i]", "+ A[i - 1] -= d", "+ cnt += d", "+print(cnt)" ]
false
0.04032
0.04032
1.000001
[ "s434806478", "s666385373" ]
u729133443
p03251
python
s174496927
s539628531
23
18
2,940
3,060
Accepted
Accepted
21.74
(*z,X,Y),x,y=eval('map(int,input().split()),'*3);print(('No War'[3*(max(X,*x)>=min(Y,*y)):]))
(*_,X,Y),x,y=eval('map(int,input().split()),'*3);print(('No'*(max(X,*x)<min(Y,*y)),'War'))
1
1
91
88
(*z, X, Y), x, y = eval("map(int,input().split())," * 3) print(("No War"[3 * (max(X, *x) >= min(Y, *y)) :]))
(*_, X, Y), x, y = eval("map(int,input().split())," * 3) print(("No" * (max(X, *x) < min(Y, *y)), "War"))
false
0
[ "-(*z, X, Y), x, y = eval(\"map(int,input().split()),\" * 3)", "-print((\"No War\"[3 * (max(X, *x) >= min(Y, *y)) :]))", "+(*_, X, Y), x, y = eval(\"map(int,input().split()),\" * 3)", "+print((\"No\" * (max(X, *x) < min(Y, *y)), \"War\"))" ]
false
0.036291
0.055553
0.653274
[ "s174496927", "s539628531" ]
u864641771
p02713
python
s526298321
s123492433
1,889
1,089
9,120
9,120
Accepted
Accepted
42.35
from math import gcd K = int(eval(input())) ans = 0 for a in range(1, K+1): for b in range(1, K+1): for c in range(1, K+1): ans += gcd(gcd(a, b), c) print(ans)
from math import gcd K = int(eval(input())) ans = 0 for a in range(1, K+1): for b in range(1, K+1): x = gcd(a, b) for c in range(1, K+1): ans += gcd(x, c) print(ans)
9
10
186
201
from math import gcd K = int(eval(input())) ans = 0 for a in range(1, K + 1): for b in range(1, K + 1): for c in range(1, K + 1): ans += gcd(gcd(a, b), c) print(ans)
from math import gcd K = int(eval(input())) ans = 0 for a in range(1, K + 1): for b in range(1, K + 1): x = gcd(a, b) for c in range(1, K + 1): ans += gcd(x, c) print(ans)
false
10
[ "+ x = gcd(a, b)", "- ans += gcd(gcd(a, b), c)", "+ ans += gcd(x, c)" ]
false
0.055061
0.117782
0.467481
[ "s526298321", "s123492433" ]
u678505520
p02724
python
s115207292
s386774589
19
17
3,060
2,940
Accepted
Accepted
10.53
x = int(eval(input())) y = x//500 print((y*1000+(x%500//5)*5))
x = int(eval(input())) print((1000*(x//500) + 5*((x//5)%100)))
3
2
56
55
x = int(eval(input())) y = x // 500 print((y * 1000 + (x % 500 // 5) * 5))
x = int(eval(input())) print((1000 * (x // 500) + 5 * ((x // 5) % 100)))
false
33.333333
[ "-y = x // 500", "-print((y * 1000 + (x % 500 // 5) * 5))", "+print((1000 * (x // 500) + 5 * ((x // 5) % 100)))" ]
false
0.048132
0.049563
0.971126
[ "s115207292", "s386774589" ]
u156815136
p03937
python
s104890711
s226262259
37
21
5,148
3,316
Accepted
Accepted
43.24
from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def main(): H,W = readInts() FIELD = [eval(input()) for _ in range(H)] ARRIVED = [[False]*W for _ in range(H)] def Move(y,x): ARRIVED[y][x] = True if y == H-1 and x == W-1: if FIELD[y][x-1] == '#' and not ARRIVED[y][x-1]: print('Impossible') exit() else: print('Possible') exit() y_ = True x_ = True if y+1 < H: y_ = True else: y_ = False if x+1 < W: x_ = True else: x_ = False xu = True if x - 1 >= 0 else False yu = True if y - 1 >= 0 else False if y_ and FIELD[y+1][x] == '#': if x_ and FIELD[y][x+1] == '#': print('Impossible') exit() elif yu and FIELD[y-1][x] == '#' and not ARRIVED[y-1][x]: #print(y-1,x) print('Impossible') exit() else: Move(y+1,x) elif x_ and FIELD[y][x+1] == '#': if y_ and FIELD[y+1][x] == '#': print('Impossible') exit() elif xu and FIELD[y][x-1] == '#' and not ARRIVED[y][x-1]: #print(y,x-1) print('Impossible') exit() else: Move(y,x+1) else: print('Impossible') exit() # 最初は (0,0)です Move(0,0) if __name__ == '__main__': main()
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] #from fractions import gcd #from itertools import combinations # (string,3) 3回 #from collections import deque from collections import defaultdict #import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 def readInts(): return list(map(int,input().split())) def I(): return int(eval(input())) h,w = readInts() A = [eval(input()) for _ in range(h)] cnt = 0 for y in range(h): for x in range(w): if A[y][x] == '#': cnt += 1 if h + w - 1 == cnt: print('Possible') else: print('Impossible')
76
37
2,106
834
from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int, input().split())) def main(): H, W = readInts() FIELD = [eval(input()) for _ in range(H)] ARRIVED = [[False] * W for _ in range(H)] def Move(y, x): ARRIVED[y][x] = True if y == H - 1 and x == W - 1: if FIELD[y][x - 1] == "#" and not ARRIVED[y][x - 1]: print("Impossible") exit() else: print("Possible") exit() y_ = True x_ = True if y + 1 < H: y_ = True else: y_ = False if x + 1 < W: x_ = True else: x_ = False xu = True if x - 1 >= 0 else False yu = True if y - 1 >= 0 else False if y_ and FIELD[y + 1][x] == "#": if x_ and FIELD[y][x + 1] == "#": print("Impossible") exit() elif yu and FIELD[y - 1][x] == "#" and not ARRIVED[y - 1][x]: # print(y-1,x) print("Impossible") exit() else: Move(y + 1, x) elif x_ and FIELD[y][x + 1] == "#": if y_ and FIELD[y + 1][x] == "#": print("Impossible") exit() elif xu and FIELD[y][x - 1] == "#" and not ARRIVED[y][x - 1]: # print(y,x-1) print("Impossible") exit() else: Move(y, x + 1) else: print("Impossible") exit() # 最初は (0,0)です Move(0, 0) if __name__ == "__main__": main()
# from statistics import median # import collections # aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] # from fractions import gcd # from itertools import combinations # (string,3) 3回 # from collections import deque from collections import defaultdict # import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 # mod = 9982443453 def readInts(): return list(map(int, input().split())) def I(): return int(eval(input())) h, w = readInts() A = [eval(input()) for _ in range(h)] cnt = 0 for y in range(h): for x in range(w): if A[y][x] == "#": cnt += 1 if h + w - 1 == cnt: print("Possible") else: print("Impossible")
false
51.315789
[ "-from statistics import median", "-", "+# from statistics import median", "-from fractions import gcd", "-from itertools import combinations # (string,3) 3回", "-from collections import deque", "+# from fractions import gcd", "+# from itertools import combinations # (string,3) 3回", "+# from collections import deque", "-import bisect", "+# import bisect", "-", "-", "+# mod = 9982443453", "-def main():", "- H, W = readInts()", "- FIELD = [eval(input()) for _ in range(H)]", "- ARRIVED = [[False] * W for _ in range(H)]", "-", "- def Move(y, x):", "- ARRIVED[y][x] = True", "- if y == H - 1 and x == W - 1:", "- if FIELD[y][x - 1] == \"#\" and not ARRIVED[y][x - 1]:", "- print(\"Impossible\")", "- exit()", "- else:", "- print(\"Possible\")", "- exit()", "- y_ = True", "- x_ = True", "- if y + 1 < H:", "- y_ = True", "- else:", "- y_ = False", "- if x + 1 < W:", "- x_ = True", "- else:", "- x_ = False", "- xu = True if x - 1 >= 0 else False", "- yu = True if y - 1 >= 0 else False", "- if y_ and FIELD[y + 1][x] == \"#\":", "- if x_ and FIELD[y][x + 1] == \"#\":", "- print(\"Impossible\")", "- exit()", "- elif yu and FIELD[y - 1][x] == \"#\" and not ARRIVED[y - 1][x]:", "- # print(y-1,x)", "- print(\"Impossible\")", "- exit()", "- else:", "- Move(y + 1, x)", "- elif x_ and FIELD[y][x + 1] == \"#\":", "- if y_ and FIELD[y + 1][x] == \"#\":", "- print(\"Impossible\")", "- exit()", "- elif xu and FIELD[y][x - 1] == \"#\" and not ARRIVED[y][x - 1]:", "- # print(y,x-1)", "- print(\"Impossible\")", "- exit()", "- else:", "- Move(y, x + 1)", "- else:", "- print(\"Impossible\")", "- exit()", "-", "- # 最初は (0,0)です", "- Move(0, 0)", "+def I():", "+ return int(eval(input()))", "-if __name__ == \"__main__\":", "- main()", "+h, w = readInts()", "+A = [eval(input()) for _ in range(h)]", "+cnt = 0", "+for y in range(h):", "+ for x in range(w):", "+ if A[y][x] == \"#\":", "+ cnt += 1", "+if h + w - 1 == cnt:", "+ print(\"Possible\")", "+else:", "+ print(\"Impossible\")" ]
false
0.04295
0.076941
0.558222
[ "s104890711", "s226262259" ]
u576432509
p03127
python
s531034384
s197198640
148
80
15,020
16,196
Accepted
Accepted
45.95
def gcdf(a): a.sort() a0=a[0] a=[int(x%a0) for x in a if x%a0 != 0] if len(a)==0: return a0 else: a.append(a0) a0=min(a) return gcdf(a) n=int(eval(input())) a=list(map(int,input().split())) gcdx=gcdf(a) print(gcdx)
from functools import reduce #from math import gcd from fractions import gcd n=int(eval(input())) a=list(map(int,input().split())) print((reduce(gcd,a)))
17
8
281
158
def gcdf(a): a.sort() a0 = a[0] a = [int(x % a0) for x in a if x % a0 != 0] if len(a) == 0: return a0 else: a.append(a0) a0 = min(a) return gcdf(a) n = int(eval(input())) a = list(map(int, input().split())) gcdx = gcdf(a) print(gcdx)
from functools import reduce # from math import gcd from fractions import gcd n = int(eval(input())) a = list(map(int, input().split())) print((reduce(gcd, a)))
false
52.941176
[ "-def gcdf(a):", "- a.sort()", "- a0 = a[0]", "- a = [int(x % a0) for x in a if x % a0 != 0]", "- if len(a) == 0:", "- return a0", "- else:", "- a.append(a0)", "- a0 = min(a)", "- return gcdf(a)", "+from functools import reduce", "+# from math import gcd", "+from fractions import gcd", "-gcdx = gcdf(a)", "-print(gcdx)", "+print((reduce(gcd, a)))" ]
false
0.03607
0.043404
0.831041
[ "s531034384", "s197198640" ]
u144913062
p02912
python
s257192203
s159238354
1,389
164
15,292
14,252
Accepted
Accepted
88.19
from queue import PriorityQueue N, M = list(map(int, input().split())) A = list(map(int, input().split())) queue = PriorityQueue(N) for a in A: queue.put(-a) for i in range(M): a = -queue.get() a /= 2 queue.put(-a) ans = 0 for i in range(N): ans += int(-queue.get()) print(ans)
from heapq import heapify, heappush, heappop N, M = list(map(int, input().split())) A = list([-int(x) for x in input().split()]) heapify(A) for i in range(M): heappush(A, -(-heappop(A) // 2)) print((-sum(A)))
18
10
313
222
from queue import PriorityQueue N, M = list(map(int, input().split())) A = list(map(int, input().split())) queue = PriorityQueue(N) for a in A: queue.put(-a) for i in range(M): a = -queue.get() a /= 2 queue.put(-a) ans = 0 for i in range(N): ans += int(-queue.get()) print(ans)
from heapq import heapify, heappush, heappop N, M = list(map(int, input().split())) A = list([-int(x) for x in input().split()]) heapify(A) for i in range(M): heappush(A, -(-heappop(A) // 2)) print((-sum(A)))
false
44.444444
[ "-from queue import PriorityQueue", "+from heapq import heapify, heappush, heappop", "-A = list(map(int, input().split()))", "-queue = PriorityQueue(N)", "-for a in A:", "- queue.put(-a)", "+A = list([-int(x) for x in input().split()])", "+heapify(A)", "- a = -queue.get()", "- a /= 2", "- queue.put(-a)", "-ans = 0", "-for i in range(N):", "- ans += int(-queue.get())", "-print(ans)", "+ heappush(A, -(-heappop(A) // 2))", "+print((-sum(A)))" ]
false
0.069158
0.081032
0.853465
[ "s257192203", "s159238354" ]
u581187895
p02972
python
s093186075
s083844624
233
190
17,220
12,700
Accepted
Accepted
18.45
N = int(eval(input())) A = [None] + [int(i) for i in input().split()] ans = [] choose = [0] * (N+1) for n in range(N, 0, -1): x = sum(choose[2*n::n]) if x % 2 == A[n]: continue choose[n] += 1 ans.append(str(n)) print((len(ans))) print((' '.join(ans)))
import sys sys.setrecursionlimit(10 ** 7) read = sys.stdin.buffer.read inp = sys.stdin.buffer.readline def inpS(): return inp().rstrip().decode() readlines = sys.stdin.buffer.readlines MOD = 10**9+7 N = int(inp()) A = [0] + list(map(int, inp().split())) # A[i]余りが1: sum(A[i::i])が奇数 for i in range(N//2, 0, -1): A[i] = sum(A[i::i])&1 ans = [i for i, a in enumerate(A) if a] print((len(ans))) if len(ans) > 0: print((*ans))
14
21
270
454
N = int(eval(input())) A = [None] + [int(i) for i in input().split()] ans = [] choose = [0] * (N + 1) for n in range(N, 0, -1): x = sum(choose[2 * n :: n]) if x % 2 == A[n]: continue choose[n] += 1 ans.append(str(n)) print((len(ans))) print((" ".join(ans)))
import sys sys.setrecursionlimit(10**7) read = sys.stdin.buffer.read inp = sys.stdin.buffer.readline def inpS(): return inp().rstrip().decode() readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 N = int(inp()) A = [0] + list(map(int, inp().split())) # A[i]余りが1: sum(A[i::i])が奇数 for i in range(N // 2, 0, -1): A[i] = sum(A[i::i]) & 1 ans = [i for i, a in enumerate(A) if a] print((len(ans))) if len(ans) > 0: print((*ans))
false
33.333333
[ "-N = int(eval(input()))", "-A = [None] + [int(i) for i in input().split()]", "-ans = []", "-choose = [0] * (N + 1)", "-for n in range(N, 0, -1):", "- x = sum(choose[2 * n :: n])", "- if x % 2 == A[n]:", "- continue", "- choose[n] += 1", "- ans.append(str(n))", "+import sys", "+", "+sys.setrecursionlimit(10**7)", "+read = sys.stdin.buffer.read", "+inp = sys.stdin.buffer.readline", "+", "+", "+def inpS():", "+ return inp().rstrip().decode()", "+", "+", "+readlines = sys.stdin.buffer.readlines", "+MOD = 10**9 + 7", "+N = int(inp())", "+A = [0] + list(map(int, inp().split()))", "+# A[i]余りが1: sum(A[i::i])が奇数", "+for i in range(N // 2, 0, -1):", "+ A[i] = sum(A[i::i]) & 1", "+ans = [i for i, a in enumerate(A) if a]", "-print((\" \".join(ans)))", "+if len(ans) > 0:", "+ print((*ans))" ]
false
0.043675
0.042033
1.039066
[ "s093186075", "s083844624" ]
u968166680
p02793
python
s678861660
s232240991
138
116
86,516
86,120
Accepted
Accepted
15.94
import sys from collections import defaultdict, Counter read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, *A = list(map(int, read().split())) N_MAX = 10 ** 6 min_factor = list(range(N_MAX + 1)) min_factor[2::2] = [2] * (N_MAX // 2) for i in range(3, int(N_MAX ** 0.5) + 2, 2): if min_factor[i] != i: continue for j in range(i * i, N_MAX + 1, 2 * i): if min_factor[j] > i: min_factor[j] = i def prime_factorize_fast(n): a = Counter() while n != 1: f = min_factor[n] p = 0 while min_factor[n] == f: p += 1 n //= f a[f] = p return a lcm_prime = Counter() for a in A: for p, n in list(prime_factorize_fast(a).items()): if lcm_prime[p] < n: lcm_prime[p] = n l = 1 for p, n in list(lcm_prime.items()): l = l * pow(p, n, MOD) % MOD ans = 0 for a in A: ans = (ans + pow(a, MOD - 2, MOD)) % MOD ans = ans * l % MOD print(ans) return if __name__ == '__main__': main()
import sys from collections import defaultdict, Counter read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, *A = list(map(int, read().split())) N_MAX = 10 ** 6 min_factor = list(range(N_MAX + 1)) min_factor[2::2] = [2] * (N_MAX // 2) for i in range(3, int(N_MAX ** 0.5) + 2, 2): if min_factor[i] != i: continue for j in range(i * i, N_MAX + 1, 2 * i): if min_factor[j] > i: min_factor[j] = i def prime_factorize_fast(n): a = Counter() while n != 1: a[min_factor[n]] += 1 n //= min_factor[n] return a lcm_prime = Counter() for a in A: for p, n in list(prime_factorize_fast(a).items()): if lcm_prime[p] < n: lcm_prime[p] = n l = 1 for p, n in list(lcm_prime.items()): l = l * pow(p, n, MOD) % MOD ans = 0 for a in A: ans = (ans + pow(a, MOD - 2, MOD)) % MOD ans = ans * l % MOD print(ans) return if __name__ == '__main__': main()
59
55
1,299
1,207
import sys from collections import defaultdict, Counter read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N, *A = list(map(int, read().split())) N_MAX = 10**6 min_factor = list(range(N_MAX + 1)) min_factor[2::2] = [2] * (N_MAX // 2) for i in range(3, int(N_MAX**0.5) + 2, 2): if min_factor[i] != i: continue for j in range(i * i, N_MAX + 1, 2 * i): if min_factor[j] > i: min_factor[j] = i def prime_factorize_fast(n): a = Counter() while n != 1: f = min_factor[n] p = 0 while min_factor[n] == f: p += 1 n //= f a[f] = p return a lcm_prime = Counter() for a in A: for p, n in list(prime_factorize_fast(a).items()): if lcm_prime[p] < n: lcm_prime[p] = n l = 1 for p, n in list(lcm_prime.items()): l = l * pow(p, n, MOD) % MOD ans = 0 for a in A: ans = (ans + pow(a, MOD - 2, MOD)) % MOD ans = ans * l % MOD print(ans) return if __name__ == "__main__": main()
import sys from collections import defaultdict, Counter read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N, *A = list(map(int, read().split())) N_MAX = 10**6 min_factor = list(range(N_MAX + 1)) min_factor[2::2] = [2] * (N_MAX // 2) for i in range(3, int(N_MAX**0.5) + 2, 2): if min_factor[i] != i: continue for j in range(i * i, N_MAX + 1, 2 * i): if min_factor[j] > i: min_factor[j] = i def prime_factorize_fast(n): a = Counter() while n != 1: a[min_factor[n]] += 1 n //= min_factor[n] return a lcm_prime = Counter() for a in A: for p, n in list(prime_factorize_fast(a).items()): if lcm_prime[p] < n: lcm_prime[p] = n l = 1 for p, n in list(lcm_prime.items()): l = l * pow(p, n, MOD) % MOD ans = 0 for a in A: ans = (ans + pow(a, MOD - 2, MOD)) % MOD ans = ans * l % MOD print(ans) return if __name__ == "__main__": main()
false
6.779661
[ "- f = min_factor[n]", "- p = 0", "- while min_factor[n] == f:", "- p += 1", "- n //= f", "- a[f] = p", "+ a[min_factor[n]] += 1", "+ n //= min_factor[n]" ]
false
0.365909
0.439768
0.832049
[ "s678861660", "s232240991" ]
u832381404
p03448
python
s710088634
s503799645
52
18
3,060
3,060
Accepted
Accepted
65.38
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) cnt = 0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if(500*i+100*j+50*k == x): cnt+=1 print(cnt)
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) cnt = 0 for i in range(a+1): for j in range(b+1): z = x-(500*i+100*j) if(z < 0): break if(z/50 <= c): cnt += 1 print(cnt)
13
15
238
258
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) cnt = 0 for i in range(a + 1): for j in range(b + 1): for k in range(c + 1): if 500 * i + 100 * j + 50 * k == x: cnt += 1 print(cnt)
a = int(eval(input())) b = int(eval(input())) c = int(eval(input())) x = int(eval(input())) cnt = 0 for i in range(a + 1): for j in range(b + 1): z = x - (500 * i + 100 * j) if z < 0: break if z / 50 <= c: cnt += 1 print(cnt)
false
13.333333
[ "- for k in range(c + 1):", "- if 500 * i + 100 * j + 50 * k == x:", "- cnt += 1", "+ z = x - (500 * i + 100 * j)", "+ if z < 0:", "+ break", "+ if z / 50 <= c:", "+ cnt += 1" ]
false
0.108846
0.039291
2.770246
[ "s710088634", "s503799645" ]
u047102107
p03569
python
s124016544
s498437741
223
193
47,216
47,088
Accepted
Accepted
13.45
from collections import Counter s = eval(input()) snotx = "".join([ch for ch in s if ch != 'x']) if s == s[::-1]: print((0)) exit() if snotx != snotx[::-1]: print((-1)) exit() # 回数を合わせる # print(s) # print(snotx) # xのrun-length rl = [] i = 0 while i < len(s): j = i while j < len(s) and s[j] == 'x': j += 1 rl.append(j - i) i = j + 1 if s[-1] != 'x': rl.append(0) # run-lengthの左右を見て合わせる res = 0 i = 0 while i * 2 < len(rl): res += max(rl[i], rl[len(rl) - i - 1]) - min(rl[i], rl[len(rl) - i - 1]) i += 1 print(res)
from collections import Counter s = eval(input()) snotx = "".join([ch for ch in s if ch != 'x']) if s == s[::-1]: print((0)) exit() if snotx != snotx[::-1]: print((-1)) exit() # 両端から見てくる (解説解法) index_l = 0 index_r = len(s) - 1 count = 0 while index_l < index_r: if s[index_l] == s[index_r]: index_l += 1 index_r -= 1 elif s[index_l] == 'x': count += 1 index_l += 1 elif s[index_r] == 'x': count += 1 index_r -= 1 else: print((-1)) exit() print(count)
36
31
598
568
from collections import Counter s = eval(input()) snotx = "".join([ch for ch in s if ch != "x"]) if s == s[::-1]: print((0)) exit() if snotx != snotx[::-1]: print((-1)) exit() # 回数を合わせる # print(s) # print(snotx) # xのrun-length rl = [] i = 0 while i < len(s): j = i while j < len(s) and s[j] == "x": j += 1 rl.append(j - i) i = j + 1 if s[-1] != "x": rl.append(0) # run-lengthの左右を見て合わせる res = 0 i = 0 while i * 2 < len(rl): res += max(rl[i], rl[len(rl) - i - 1]) - min(rl[i], rl[len(rl) - i - 1]) i += 1 print(res)
from collections import Counter s = eval(input()) snotx = "".join([ch for ch in s if ch != "x"]) if s == s[::-1]: print((0)) exit() if snotx != snotx[::-1]: print((-1)) exit() # 両端から見てくる (解説解法) index_l = 0 index_r = len(s) - 1 count = 0 while index_l < index_r: if s[index_l] == s[index_r]: index_l += 1 index_r -= 1 elif s[index_l] == "x": count += 1 index_l += 1 elif s[index_r] == "x": count += 1 index_r -= 1 else: print((-1)) exit() print(count)
false
13.888889
[ "-# 回数を合わせる", "-# print(s)", "-# print(snotx)", "-# xのrun-length", "-rl = []", "-i = 0", "-while i < len(s):", "- j = i", "- while j < len(s) and s[j] == \"x\":", "- j += 1", "- rl.append(j - i)", "- i = j + 1", "-if s[-1] != \"x\":", "- rl.append(0)", "-# run-lengthの左右を見て合わせる", "-res = 0", "-i = 0", "-while i * 2 < len(rl):", "- res += max(rl[i], rl[len(rl) - i - 1]) - min(rl[i], rl[len(rl) - i - 1])", "- i += 1", "-print(res)", "+# 両端から見てくる (解説解法)", "+index_l = 0", "+index_r = len(s) - 1", "+count = 0", "+while index_l < index_r:", "+ if s[index_l] == s[index_r]:", "+ index_l += 1", "+ index_r -= 1", "+ elif s[index_l] == \"x\":", "+ count += 1", "+ index_l += 1", "+ elif s[index_r] == \"x\":", "+ count += 1", "+ index_r -= 1", "+ else:", "+ print((-1))", "+ exit()", "+print(count)" ]
false
0.062727
0.072456
0.865725
[ "s124016544", "s498437741" ]
u453055089
p03163
python
s179038828
s864678611
502
301
120,684
150,256
Accepted
Accepted
40.04
N, W = list(map(int, input().split())) w = [0]*N v = [0]*N for i in range(N): w[i], v[i] = list(map(int, input().split())) dp = [[0]*(W+1) for _ in range(N+1)] # dp[i][sum_w] # i-1番目までの品物から重さがsum_wを超えないように選んだ時の価値の総和 # sum_w = 0, 1, 2, ... ,W for i in range(N): for sum_w in range(W+1): if sum_w - w[i] >= 0: dp[i+1][sum_w] = dp[i][sum_w - w[i]] + v[i] dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w]) print((dp[N][W]))
n, W = list(map(int, input().split())) w, v = [0]*n, [0]*n for i in range(n): w[i], v[i] = list(map(int, input().split())) dp = [[0]*(W+1) for i in range(n+1)] #i品目までの中から重さwを超えないように選んだときの価値の総和の最大値 for i in range(1, n+1): for j in range(W+1): if j - w[i-1] >= 0: dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]] + v[i-1]) dp[i][j] = max(dp[i][j], dp[i-1][j]) print((max(dp[n])))
18
14
462
409
N, W = list(map(int, input().split())) w = [0] * N v = [0] * N for i in range(N): w[i], v[i] = list(map(int, input().split())) dp = [[0] * (W + 1) for _ in range(N + 1)] # dp[i][sum_w] # i-1番目までの品物から重さがsum_wを超えないように選んだ時の価値の総和 # sum_w = 0, 1, 2, ... ,W for i in range(N): for sum_w in range(W + 1): if sum_w - w[i] >= 0: dp[i + 1][sum_w] = dp[i][sum_w - w[i]] + v[i] dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w]) print((dp[N][W]))
n, W = list(map(int, input().split())) w, v = [0] * n, [0] * n for i in range(n): w[i], v[i] = list(map(int, input().split())) dp = [[0] * (W + 1) for i in range(n + 1)] # i品目までの中から重さwを超えないように選んだときの価値の総和の最大値 for i in range(1, n + 1): for j in range(W + 1): if j - w[i - 1] >= 0: dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j]) print((max(dp[n])))
false
22.222222
[ "-N, W = list(map(int, input().split()))", "-w = [0] * N", "-v = [0] * N", "-for i in range(N):", "+n, W = list(map(int, input().split()))", "+w, v = [0] * n, [0] * n", "+for i in range(n):", "-dp = [[0] * (W + 1) for _ in range(N + 1)]", "-# dp[i][sum_w]", "-# i-1番目までの品物から重さがsum_wを超えないように選んだ時の価値の総和", "-# sum_w = 0, 1, 2, ... ,W", "-for i in range(N):", "- for sum_w in range(W + 1):", "- if sum_w - w[i] >= 0:", "- dp[i + 1][sum_w] = dp[i][sum_w - w[i]] + v[i]", "- dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])", "-print((dp[N][W]))", "+dp = [[0] * (W + 1) for i in range(n + 1)]", "+# i品目までの中から重さwを超えないように選んだときの価値の総和の最大値", "+for i in range(1, n + 1):", "+ for j in range(W + 1):", "+ if j - w[i - 1] >= 0:", "+ dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1])", "+ dp[i][j] = max(dp[i][j], dp[i - 1][j])", "+print((max(dp[n])))" ]
false
0.042794
0.044592
0.959675
[ "s179038828", "s864678611" ]
u556225812
p03416
python
s350751198
s918977401
54
45
2,940
2,940
Accepted
Accepted
16.67
A, B = list(map(int, input().split())) cnt = 0 for x in range(A, B + 1): X = str(x) if X == X[::-1]: cnt += 1 print(cnt)
A, B = list(map(int, input().split())) cnt = 0 for i in range(A, B+1): x = str(i) if x[0] == x[4] and x[1] == x[3]: cnt += 1 print(cnt)
7
7
136
143
A, B = list(map(int, input().split())) cnt = 0 for x in range(A, B + 1): X = str(x) if X == X[::-1]: cnt += 1 print(cnt)
A, B = list(map(int, input().split())) cnt = 0 for i in range(A, B + 1): x = str(i) if x[0] == x[4] and x[1] == x[3]: cnt += 1 print(cnt)
false
0
[ "-for x in range(A, B + 1):", "- X = str(x)", "- if X == X[::-1]:", "+for i in range(A, B + 1):", "+ x = str(i)", "+ if x[0] == x[4] and x[1] == x[3]:" ]
false
0.132186
0.131519
1.005072
[ "s350751198", "s918977401" ]
u562935282
p03721
python
s999129912
s346705351
475
315
29,912
16,688
Accepted
Accepted
33.68
def inpl(): return input().split() n, k = list(map(int, inpl())) M = list(list(map(int, inpl())) for _ in range(n)) M = sorted(M, key=lambda x:x[0]) for i in range(n): a, b = M[i] if k <= b: print(a) exit() else: k -= b
def main(): from heapq import heappush, heappop import sys input = sys.stdin.readline N, K = list(map(int, input().split())) h = [] for _ in range(N): a, b = list(map(int, input().split())) heappush(h, (a, b)) while h: a, b = heappop(h) K -= b if K <= 0: print(a) return if __name__ == '__main__': main()
11
23
259
417
def inpl(): return input().split() n, k = list(map(int, inpl())) M = list(list(map(int, inpl())) for _ in range(n)) M = sorted(M, key=lambda x: x[0]) for i in range(n): a, b = M[i] if k <= b: print(a) exit() else: k -= b
def main(): from heapq import heappush, heappop import sys input = sys.stdin.readline N, K = list(map(int, input().split())) h = [] for _ in range(N): a, b = list(map(int, input().split())) heappush(h, (a, b)) while h: a, b = heappop(h) K -= b if K <= 0: print(a) return if __name__ == "__main__": main()
false
52.173913
[ "-def inpl():", "- return input().split()", "+def main():", "+ from heapq import heappush, heappop", "+ import sys", "+", "+ input = sys.stdin.readline", "+ N, K = list(map(int, input().split()))", "+ h = []", "+ for _ in range(N):", "+ a, b = list(map(int, input().split()))", "+ heappush(h, (a, b))", "+ while h:", "+ a, b = heappop(h)", "+ K -= b", "+ if K <= 0:", "+ print(a)", "+ return", "-n, k = list(map(int, inpl()))", "-M = list(list(map(int, inpl())) for _ in range(n))", "-M = sorted(M, key=lambda x: x[0])", "-for i in range(n):", "- a, b = M[i]", "- if k <= b:", "- print(a)", "- exit()", "- else:", "- k -= b", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.066961
0.110233
0.607452
[ "s999129912", "s346705351" ]
u945181840
p03599
python
s254016679
s593708902
391
320
3,064
3,064
Accepted
Accepted
18.16
A, B, C, D, E, F = list(map(int, input().split())) ans = [100 * A, 0] c = 0 for i in range(1, F // (100 * A) + 1): for j in range((F - 100 * A * i) // (100 * B) + 1): a = 100 * A * i + 100 * B * j if a > F: break for k in range((F - a) // C + 1): for l in range((F - a - C * k) // D + 1): b = k * C + l * D concentration = 100 * b / (a + b) if (A * i + B * j) * E >= b and a + b <= F: if concentration > c: c = concentration ans = [a + b, b] else: break print((' '.join(map(str, ans))))
A, B, C, D, E, F = list(map(int, input().split())) ans = [100 * A, 0] c = 0 for i in range(1, F // (100 * A) + 1): for j in range((F - 100 * A * i) // (100 * B) + 1): a = 100 * A * i + 100 * B * j for k in range((F - a) // C + 1): for l in range((F - a - C * k) // D + 1): b = k * C + l * D concentration = 100 * b / (a + b) if (A * i + B * j) * E >= b: if concentration > c: c = concentration ans = [a + b, b] else: break print((' '.join(map(str, ans))))
21
19
704
651
A, B, C, D, E, F = list(map(int, input().split())) ans = [100 * A, 0] c = 0 for i in range(1, F // (100 * A) + 1): for j in range((F - 100 * A * i) // (100 * B) + 1): a = 100 * A * i + 100 * B * j if a > F: break for k in range((F - a) // C + 1): for l in range((F - a - C * k) // D + 1): b = k * C + l * D concentration = 100 * b / (a + b) if (A * i + B * j) * E >= b and a + b <= F: if concentration > c: c = concentration ans = [a + b, b] else: break print((" ".join(map(str, ans))))
A, B, C, D, E, F = list(map(int, input().split())) ans = [100 * A, 0] c = 0 for i in range(1, F // (100 * A) + 1): for j in range((F - 100 * A * i) // (100 * B) + 1): a = 100 * A * i + 100 * B * j for k in range((F - a) // C + 1): for l in range((F - a - C * k) // D + 1): b = k * C + l * D concentration = 100 * b / (a + b) if (A * i + B * j) * E >= b: if concentration > c: c = concentration ans = [a + b, b] else: break print((" ".join(map(str, ans))))
false
9.52381
[ "- if a > F:", "- break", "- if (A * i + B * j) * E >= b and a + b <= F:", "+ if (A * i + B * j) * E >= b:" ]
false
0.089173
0.078213
1.140126
[ "s254016679", "s593708902" ]
u327532412
p03162
python
s219040210
s840101869
419
273
3,064
9,164
Accepted
Accepted
34.84
n = int(eval(input())) dp = [0] * 3 for i in range(n): a, b, c = list(map(int, input().split())) dp = [a + max(dp[1], dp[2]), b + max(dp[0], dp[2]), c + max(dp[0], dp[1])] print((max(dp)))
N = int(eval(input())) dp = [0, 0, 0] for i in range(N): a, b, c = list(map(int, input().split())) tmp_a = a + max(dp[1], dp[2]) tmp_b = b + max(dp[0], dp[2]) tmp_c = c + max(dp[0], dp[1]) dp = [tmp_a, tmp_b, tmp_c] print((max(dp)))
6
9
187
247
n = int(eval(input())) dp = [0] * 3 for i in range(n): a, b, c = list(map(int, input().split())) dp = [a + max(dp[1], dp[2]), b + max(dp[0], dp[2]), c + max(dp[0], dp[1])] print((max(dp)))
N = int(eval(input())) dp = [0, 0, 0] for i in range(N): a, b, c = list(map(int, input().split())) tmp_a = a + max(dp[1], dp[2]) tmp_b = b + max(dp[0], dp[2]) tmp_c = c + max(dp[0], dp[1]) dp = [tmp_a, tmp_b, tmp_c] print((max(dp)))
false
33.333333
[ "-n = int(eval(input()))", "-dp = [0] * 3", "-for i in range(n):", "+N = int(eval(input()))", "+dp = [0, 0, 0]", "+for i in range(N):", "- dp = [a + max(dp[1], dp[2]), b + max(dp[0], dp[2]), c + max(dp[0], dp[1])]", "+ tmp_a = a + max(dp[1], dp[2])", "+ tmp_b = b + max(dp[0], dp[2])", "+ tmp_c = c + max(dp[0], dp[1])", "+ dp = [tmp_a, tmp_b, tmp_c]" ]
false
0.037272
0.036829
1.012018
[ "s219040210", "s840101869" ]
u729133443
p03128
python
s919891518
s787601880
168
154
15,332
15,332
Accepted
Accepted
8.33
n,m,*a=list(map(int,open(0).read().split())) d=[0]*n*9 for i in range(n): for j in a: c=(0,2,5,5,4,5,6,3,7,6)[j] if d[i]or i<1:d[i+c]=max(d[i+c],d[i]*10+j) print((d[n]))
n,m,*a=list(map(int,open(0).read().split())) d=[0]*n*9 for i in range(n): for j in a: if d[i]or i<1:c=i+(0,2,5,5,4,5,6,3,7,6)[j];d[c]=max(d[c],d[i]*10+j) print((d[n]))
7
6
172
167
n, m, *a = list(map(int, open(0).read().split())) d = [0] * n * 9 for i in range(n): for j in a: c = (0, 2, 5, 5, 4, 5, 6, 3, 7, 6)[j] if d[i] or i < 1: d[i + c] = max(d[i + c], d[i] * 10 + j) print((d[n]))
n, m, *a = list(map(int, open(0).read().split())) d = [0] * n * 9 for i in range(n): for j in a: if d[i] or i < 1: c = i + (0, 2, 5, 5, 4, 5, 6, 3, 7, 6)[j] d[c] = max(d[c], d[i] * 10 + j) print((d[n]))
false
14.285714
[ "- c = (0, 2, 5, 5, 4, 5, 6, 3, 7, 6)[j]", "- d[i + c] = max(d[i + c], d[i] * 10 + j)", "+ c = i + (0, 2, 5, 5, 4, 5, 6, 3, 7, 6)[j]", "+ d[c] = max(d[c], d[i] * 10 + j)" ]
false
0.101034
0.095097
1.062429
[ "s919891518", "s787601880" ]
u936985471
p02734
python
s928371273
s373868929
912
805
287,276
287,132
Accepted
Accepted
11.73
import sys readline = sys.stdin.readline DIV = 998244353 N,S = list(map(int,readline().split())) A = list(map(int,readline().split())) # ある数の取り得る状態は以下 # (1)Lの区間がまだ開始していない # (2)L-Rの区間に含まれ、和に使われている # (3)L-Rの区間に含まれ、和に使われていない # (4)Rの区間が終了している # dp[i][j][k] = i - 1個目まで処理したときに、区間の開始状況がjで、総和がkになっている個数 dp = [[[0] * (S + 1) for j in range(3)] for i in range(N + 1)] dp[0][0][0] = 1 for i in range(N): for k in range(S + 1): # (1)まだ区間が開始していない場合 dp[i + 1][0][k] += dp[i][0][k] dp[i + 1][0][k] %= DIV # (2)区間に含まれ、和に使われている(開始していない区間からくる) if k + A[i] <= S: dp[i + 1][1][k + A[i]] += dp[i][0][k] dp[i + 1][1][k + A[i]] %= DIV # (2)区間に含まれ、和に使われている(開始済みの区間からくる) if k + A[i] <= S: dp[i + 1][1][k + A[i]] += dp[i][1][k] dp[i + 1][1][k + A[i]] %= DIV # (3)区間に含まれ、和に使われていない(開始していない区間からくる) dp[i + 1][1][k] += dp[i][0][k] dp[i + 1][1][k] %= DIV # (3)区間に含まれ、和に使われていない(開始済みの区間からくる) dp[i + 1][1][k] += dp[i][1][k] dp[i + 1][1][k] %= DIV # (4)区間が終了している(開始済みの区間からくる) dp[i + 1][2][k] += dp[i][1][k] dp[i + 1][2][k] %= DIV # (4)区間が終了している(終了済みの区間からくる) dp[i + 1][2][k] += dp[i][2][k] dp[i + 1][2][k] %= DIV print(((dp[-1][1][-1] + dp[-1][2][-1]) % DIV))
import sys readline = sys.stdin.readline DIV = 998244353 N,S = list(map(int,readline().split())) A = list(map(int,readline().split())) # ある数の取り得る状態は以下 # (1)Lの区間がまだ開始していない # (2)L-Rの区間に含まれ、和に使われている # (3)L-Rの区間に含まれ、和に使われていない # (4)Rの区間が終了している # dp[i][j][k] = i - 1個目まで処理したときに、区間の開始状況がjで、総和がkになっている個数 dp = [[[0] * (S + 1) for j in range(3)] for i in range(N + 1)] dp[0][0][0] = 1 for i in range(N): for k in range(S + 1): # (1)まだ区間が開始していない場合 dp[i + 1][0][k] += dp[i][0][k] dp[i + 1][0][k] %= DIV # (2)区間に含まれ、和に使われている if k + A[i] <= S: dp[i + 1][1][k + A[i]] += dp[i][0][k] dp[i + 1][1][k + A[i]] += dp[i][1][k] dp[i + 1][1][k + A[i]] %= DIV # (3)区間に含まれ、和に使われていない dp[i + 1][1][k] += dp[i][0][k] dp[i + 1][1][k] += dp[i][1][k] dp[i + 1][1][k] %= DIV # (4)区間が終了している dp[i + 1][2][k] += dp[i][2][k] dp[i + 1][2][k] += dp[i][1][k] dp[i + 1][2][k] %= DIV print(((dp[-1][1][-1] + dp[-1][2][-1]) % DIV))
50
40
1,291
1,001
import sys readline = sys.stdin.readline DIV = 998244353 N, S = list(map(int, readline().split())) A = list(map(int, readline().split())) # ある数の取り得る状態は以下 # (1)Lの区間がまだ開始していない # (2)L-Rの区間に含まれ、和に使われている # (3)L-Rの区間に含まれ、和に使われていない # (4)Rの区間が終了している # dp[i][j][k] = i - 1個目まで処理したときに、区間の開始状況がjで、総和がkになっている個数 dp = [[[0] * (S + 1) for j in range(3)] for i in range(N + 1)] dp[0][0][0] = 1 for i in range(N): for k in range(S + 1): # (1)まだ区間が開始していない場合 dp[i + 1][0][k] += dp[i][0][k] dp[i + 1][0][k] %= DIV # (2)区間に含まれ、和に使われている(開始していない区間からくる) if k + A[i] <= S: dp[i + 1][1][k + A[i]] += dp[i][0][k] dp[i + 1][1][k + A[i]] %= DIV # (2)区間に含まれ、和に使われている(開始済みの区間からくる) if k + A[i] <= S: dp[i + 1][1][k + A[i]] += dp[i][1][k] dp[i + 1][1][k + A[i]] %= DIV # (3)区間に含まれ、和に使われていない(開始していない区間からくる) dp[i + 1][1][k] += dp[i][0][k] dp[i + 1][1][k] %= DIV # (3)区間に含まれ、和に使われていない(開始済みの区間からくる) dp[i + 1][1][k] += dp[i][1][k] dp[i + 1][1][k] %= DIV # (4)区間が終了している(開始済みの区間からくる) dp[i + 1][2][k] += dp[i][1][k] dp[i + 1][2][k] %= DIV # (4)区間が終了している(終了済みの区間からくる) dp[i + 1][2][k] += dp[i][2][k] dp[i + 1][2][k] %= DIV print(((dp[-1][1][-1] + dp[-1][2][-1]) % DIV))
import sys readline = sys.stdin.readline DIV = 998244353 N, S = list(map(int, readline().split())) A = list(map(int, readline().split())) # ある数の取り得る状態は以下 # (1)Lの区間がまだ開始していない # (2)L-Rの区間に含まれ、和に使われている # (3)L-Rの区間に含まれ、和に使われていない # (4)Rの区間が終了している # dp[i][j][k] = i - 1個目まで処理したときに、区間の開始状況がjで、総和がkになっている個数 dp = [[[0] * (S + 1) for j in range(3)] for i in range(N + 1)] dp[0][0][0] = 1 for i in range(N): for k in range(S + 1): # (1)まだ区間が開始していない場合 dp[i + 1][0][k] += dp[i][0][k] dp[i + 1][0][k] %= DIV # (2)区間に含まれ、和に使われている if k + A[i] <= S: dp[i + 1][1][k + A[i]] += dp[i][0][k] dp[i + 1][1][k + A[i]] += dp[i][1][k] dp[i + 1][1][k + A[i]] %= DIV # (3)区間に含まれ、和に使われていない dp[i + 1][1][k] += dp[i][0][k] dp[i + 1][1][k] += dp[i][1][k] dp[i + 1][1][k] %= DIV # (4)区間が終了している dp[i + 1][2][k] += dp[i][2][k] dp[i + 1][2][k] += dp[i][1][k] dp[i + 1][2][k] %= DIV print(((dp[-1][1][-1] + dp[-1][2][-1]) % DIV))
false
20
[ "- # (2)区間に含まれ、和に使われている(開始していない区間からくる)", "+ # (2)区間に含まれ、和に使われている", "- dp[i + 1][1][k + A[i]] %= DIV", "- # (2)区間に含まれ、和に使われている(開始済みの区間からくる)", "- if k + A[i] <= S:", "- # (3)区間に含まれ、和に使われていない(開始していない区間からくる)", "+ # (3)区間に含まれ、和に使われていない", "- dp[i + 1][1][k] %= DIV", "- # (3)区間に含まれ、和に使われていない(開始済みの区間からくる)", "- # (4)区間が終了している(開始済みの区間からくる)", "+ # (4)区間が終了している", "+ dp[i + 1][2][k] += dp[i][2][k]", "- # (4)区間が終了している(終了済みの区間からくる)", "- dp[i + 1][2][k] += dp[i][2][k]", "- dp[i + 1][2][k] %= DIV" ]
false
0.049106
0.048491
1.012683
[ "s928371273", "s373868929" ]
u185249212
p03030
python
s332991632
s043100337
288
28
65,388
4,080
Accepted
Accepted
90.28
# import numpy as np # import numpypy as np import sys input = sys.stdin.readline def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) import math import string import fractions import re import array import copy import functools import operator import collections import itertools import bisect import heapq from heapq import heappush from heapq import heappop # from itertools import accumulate # from collections import deque import random def main(): n = int(eval(input())) dict={} for i in range(n): name, score= input().split() if not(name in dict): dict[name]=[((int(score),i+1))] else: dict[name].append((int(score),i+1)) dict[name].sort(reverse=True) eprint(dict) ll=list(dict.items()) eprint(ll) ll.sort() eprint(ll) for x in ll: for y in x[1]: print(y[1]) if __name__ == '__main__': main()
# import numpy as np # import numpypy as np import sys input = sys.stdin.readline def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) # import math # import string # import fractions # from fractions import Fraction # from fractions import gcd # def lcm(n,m): # return int(n*m/gcd(n,m)) # import re # # import array # import copy # import functools # import operator # import collections # import itertools # import bisect # import heapq # from heapq import heappush # from heapq import heappop # # from itertools import accumulate # # from collections import deque # import random from queue import PriorityQueue as pq # class ReversePriorityQueue(PriorityQueue): # def __cmp__(self, other): # return -cmp(self.degree, other.degree) # # def put(self, tup): # newtup = tup[0] * -1, tup[1] # PriorityQueue.put(self, newtup) # def get(self): # tup = PriorityQueue.get(self) # newtup = tup[0] * -1, tup[1] # return newtup def main(): n = int(eval(input())) dict={} for i in range(1,n+1): str_x,num = input().split() num =int(num) if (str_x in dict): dict[str_x].put((-num,i)) # dict[str_x].sort(key = lambda x : x[1]) else: a=pq() dict[str_x]=a dict[str_x].put((-num,i)) # a.put([num,i]) eprint(dict) ll = sorted(list(dict.items())) eprint(ll) # for i in ll: # for j in i[1]: # print(j[1]) for item in ll: while item[1].qsize(): print((item[1].get())[1]) if __name__ == '__main__': main()
53
74
1,042
1,766
# import numpy as np # import numpypy as np import sys input = sys.stdin.readline def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) import math import string import fractions import re import array import copy import functools import operator import collections import itertools import bisect import heapq from heapq import heappush from heapq import heappop # from itertools import accumulate # from collections import deque import random def main(): n = int(eval(input())) dict = {} for i in range(n): name, score = input().split() if not (name in dict): dict[name] = [((int(score), i + 1))] else: dict[name].append((int(score), i + 1)) dict[name].sort(reverse=True) eprint(dict) ll = list(dict.items()) eprint(ll) ll.sort() eprint(ll) for x in ll: for y in x[1]: print(y[1]) if __name__ == "__main__": main()
# import numpy as np # import numpypy as np import sys input = sys.stdin.readline def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) # import math # import string # import fractions # from fractions import Fraction # from fractions import gcd # def lcm(n,m): # return int(n*m/gcd(n,m)) # import re # # import array # import copy # import functools # import operator # import collections # import itertools # import bisect # import heapq # from heapq import heappush # from heapq import heappop # # from itertools import accumulate # # from collections import deque # import random from queue import PriorityQueue as pq # class ReversePriorityQueue(PriorityQueue): # def __cmp__(self, other): # return -cmp(self.degree, other.degree) # # def put(self, tup): # newtup = tup[0] * -1, tup[1] # PriorityQueue.put(self, newtup) # def get(self): # tup = PriorityQueue.get(self) # newtup = tup[0] * -1, tup[1] # return newtup def main(): n = int(eval(input())) dict = {} for i in range(1, n + 1): str_x, num = input().split() num = int(num) if str_x in dict: dict[str_x].put((-num, i)) # dict[str_x].sort(key = lambda x : x[1]) else: a = pq() dict[str_x] = a dict[str_x].put((-num, i)) # a.put([num,i]) eprint(dict) ll = sorted(list(dict.items())) eprint(ll) # for i in ll: # for j in i[1]: # print(j[1]) for item in ll: while item[1].qsize(): print((item[1].get())[1]) if __name__ == "__main__": main()
false
28.378378
[ "-import math", "-import string", "-import fractions", "-import re", "-import array", "-import copy", "-import functools", "-import operator", "-import collections", "-import itertools", "-import bisect", "-import heapq", "-from heapq import heappush", "-from heapq import heappop", "+# import math", "+# import string", "+# import fractions", "+# from fractions import Fraction", "+# from fractions import gcd", "+# def lcm(n,m):", "+# return int(n*m/gcd(n,m))", "+# import re", "+# # import array", "+# import copy", "+# import functools", "+# import operator", "+# import collections", "+# import itertools", "+# import bisect", "+# import heapq", "+# from heapq import heappush", "+# from heapq import heappop", "+# # from itertools import accumulate", "+# # from collections import deque", "+# import random", "+from queue import PriorityQueue as pq", "-# from itertools import accumulate", "-# from collections import deque", "-import random", "-", "-", "+# class ReversePriorityQueue(PriorityQueue):", "+# def __cmp__(self, other):", "+# return -cmp(self.degree, other.degree)", "+# # def put(self, tup):", "+# newtup = tup[0] * -1, tup[1]", "+# PriorityQueue.put(self, newtup)", "+# def get(self):", "+# tup = PriorityQueue.get(self)", "+# newtup = tup[0] * -1, tup[1]", "+# return newtup", "- for i in range(n):", "- name, score = input().split()", "- if not (name in dict):", "- dict[name] = [((int(score), i + 1))]", "+ for i in range(1, n + 1):", "+ str_x, num = input().split()", "+ num = int(num)", "+ if str_x in dict:", "+ dict[str_x].put((-num, i))", "+ # dict[str_x].sort(key = lambda x : x[1])", "- dict[name].append((int(score), i + 1))", "- dict[name].sort(reverse=True)", "+ a = pq()", "+ dict[str_x] = a", "+ dict[str_x].put((-num, i))", "+ # a.put([num,i])", "- ll = list(dict.items())", "+ ll = sorted(list(dict.items()))", "- ll.sort()", "- eprint(ll)", "- for x in ll:", "- for y in x[1]:", "- print(y[1])", "+ # for i in ll:", "+ # for j in i[1]:", "+ # print(j[1])", "+ for item in ll:", "+ while item[1].qsize():", "+ print((item[1].get())[1])" ]
false
0.043522
0.045372
0.959216
[ "s332991632", "s043100337" ]
u480138356
p03800
python
s481601456
s969979002
178
127
3,700
3,572
Accepted
Accepted
28.65
def main(): N = int(eval(input())) s = eval(input()) # c = ["WS", "SW", "SS", "WW"] c = ["SW", "WS", "SS", "WW"] ok = False for tmp in c: ans = tmp for i in range(1, N): if s[i] == "o":# oの時 if ans[i-1] == "S" and ans[i] == "S": ans += "S" elif ans[i-1] == "W" and ans[i] == "S": ans += "W" elif ans[i-1] == "S" and ans[i] == "W": ans += "W" elif ans[i-1] == "W" and ans[i] == "W": ans += "S" else:# xの時 if ans[i-1] == "S" and ans[i] == "S": ans += "W" elif ans[i-1] == "W" and ans[i] == "S": ans += "S" elif ans[i-1] == "S" and ans[i] == "W": ans += "S" elif ans[i-1] == "W" and ans[i] == "W": ans += "W" if ans[0] == ans[-1]: if ans[0] == "S": if s[0] == "o": if (ans[-2] == "S" and ans[1] == "S") or (ans[-2] == "W" and ans[1] == "W"): ok = True else: if (ans[-2] == "S" and ans[1] == "W") or (ans[-2] == "W" and ans[1] == "S"): ok = True else: if s[0] == "o": if (ans[-2] == "S" and ans[1] == "W") or (ans[-2] == "W" and ans[1] == "S"): ok = True else: if (ans[-2] == "S" and ans[1] == "S") or (ans[-2] == "W" and ans[1] == "W"): ok = True if ok: print((ans[:-1])) # print(len(ans)) break if not ok: print((-1)) if __name__ == "__main__": main()
def main(): N = int(eval(input())) s = eval(input()) c = ["SW", "WS", "SS", "WW"] o_ = {"SS": "S", "WS": "W", "SW": "W", "WW": "S"} x_ = {"SS": "W", "WS": "S", "SW": "S", "WW": "W"} _o_ = ["SSS", "WSW", "SWW", "WWS"] _x_ = ["WSS", "SSW", "SWS", "WWW"] ok = False for tmp in c: ans = tmp for i in range(1, N): if s[i] == "o": # oの時 ans += o_[ans[-2:]] else: # xの時 ans += x_[ans[-2:]] if ans[0] == ans[-1]: jud = ans[-2:] + ans[1] if s[0] == "o": if jud in _o_: ok = True else: if jud in _x_: ok = True if ok: print((ans[:-1])) break if not ok: print((-1)) if __name__ == "__main__": main()
52
33
1,874
892
def main(): N = int(eval(input())) s = eval(input()) # c = ["WS", "SW", "SS", "WW"] c = ["SW", "WS", "SS", "WW"] ok = False for tmp in c: ans = tmp for i in range(1, N): if s[i] == "o": # oの時 if ans[i - 1] == "S" and ans[i] == "S": ans += "S" elif ans[i - 1] == "W" and ans[i] == "S": ans += "W" elif ans[i - 1] == "S" and ans[i] == "W": ans += "W" elif ans[i - 1] == "W" and ans[i] == "W": ans += "S" else: # xの時 if ans[i - 1] == "S" and ans[i] == "S": ans += "W" elif ans[i - 1] == "W" and ans[i] == "S": ans += "S" elif ans[i - 1] == "S" and ans[i] == "W": ans += "S" elif ans[i - 1] == "W" and ans[i] == "W": ans += "W" if ans[0] == ans[-1]: if ans[0] == "S": if s[0] == "o": if (ans[-2] == "S" and ans[1] == "S") or ( ans[-2] == "W" and ans[1] == "W" ): ok = True else: if (ans[-2] == "S" and ans[1] == "W") or ( ans[-2] == "W" and ans[1] == "S" ): ok = True else: if s[0] == "o": if (ans[-2] == "S" and ans[1] == "W") or ( ans[-2] == "W" and ans[1] == "S" ): ok = True else: if (ans[-2] == "S" and ans[1] == "S") or ( ans[-2] == "W" and ans[1] == "W" ): ok = True if ok: print((ans[:-1])) # print(len(ans)) break if not ok: print((-1)) if __name__ == "__main__": main()
def main(): N = int(eval(input())) s = eval(input()) c = ["SW", "WS", "SS", "WW"] o_ = {"SS": "S", "WS": "W", "SW": "W", "WW": "S"} x_ = {"SS": "W", "WS": "S", "SW": "S", "WW": "W"} _o_ = ["SSS", "WSW", "SWW", "WWS"] _x_ = ["WSS", "SSW", "SWS", "WWW"] ok = False for tmp in c: ans = tmp for i in range(1, N): if s[i] == "o": # oの時 ans += o_[ans[-2:]] else: # xの時 ans += x_[ans[-2:]] if ans[0] == ans[-1]: jud = ans[-2:] + ans[1] if s[0] == "o": if jud in _o_: ok = True else: if jud in _x_: ok = True if ok: print((ans[:-1])) break if not ok: print((-1)) if __name__ == "__main__": main()
false
36.538462
[ "- # c = [\"WS\", \"SW\", \"SS\", \"WW\"]", "+ o_ = {\"SS\": \"S\", \"WS\": \"W\", \"SW\": \"W\", \"WW\": \"S\"}", "+ x_ = {\"SS\": \"W\", \"WS\": \"S\", \"SW\": \"S\", \"WW\": \"W\"}", "+ _o_ = [\"SSS\", \"WSW\", \"SWW\", \"WWS\"]", "+ _x_ = [\"WSS\", \"SSW\", \"SWS\", \"WWW\"]", "- if ans[i - 1] == \"S\" and ans[i] == \"S\":", "- ans += \"S\"", "- elif ans[i - 1] == \"W\" and ans[i] == \"S\":", "- ans += \"W\"", "- elif ans[i - 1] == \"S\" and ans[i] == \"W\":", "- ans += \"W\"", "- elif ans[i - 1] == \"W\" and ans[i] == \"W\":", "- ans += \"S\"", "+ ans += o_[ans[-2:]]", "- if ans[i - 1] == \"S\" and ans[i] == \"S\":", "- ans += \"W\"", "- elif ans[i - 1] == \"W\" and ans[i] == \"S\":", "- ans += \"S\"", "- elif ans[i - 1] == \"S\" and ans[i] == \"W\":", "- ans += \"S\"", "- elif ans[i - 1] == \"W\" and ans[i] == \"W\":", "- ans += \"W\"", "+ ans += x_[ans[-2:]]", "- if ans[0] == \"S\":", "- if s[0] == \"o\":", "- if (ans[-2] == \"S\" and ans[1] == \"S\") or (", "- ans[-2] == \"W\" and ans[1] == \"W\"", "- ):", "- ok = True", "- else:", "- if (ans[-2] == \"S\" and ans[1] == \"W\") or (", "- ans[-2] == \"W\" and ans[1] == \"S\"", "- ):", "- ok = True", "+ jud = ans[-2:] + ans[1]", "+ if s[0] == \"o\":", "+ if jud in _o_:", "+ ok = True", "- if s[0] == \"o\":", "- if (ans[-2] == \"S\" and ans[1] == \"W\") or (", "- ans[-2] == \"W\" and ans[1] == \"S\"", "- ):", "- ok = True", "- else:", "- if (ans[-2] == \"S\" and ans[1] == \"S\") or (", "- ans[-2] == \"W\" and ans[1] == \"W\"", "- ):", "- ok = True", "+ if jud in _x_:", "+ ok = True", "- # print(len(ans))" ]
false
0.053521
0.071469
0.748866
[ "s481601456", "s969979002" ]
u338225045
p03556
python
s326843003
s462630232
29
19
3,064
3,060
Accepted
Accepted
34.48
N = int( eval(input()) ) ans = 0 for i in range( int(N**0.5)+1 ): ans = max( ans, i*i ) print( ans )
N = int( eval(input()) ) print(( int(N**0.5)**2 ))
7
3
106
45
N = int(eval(input())) ans = 0 for i in range(int(N**0.5) + 1): ans = max(ans, i * i) print(ans)
N = int(eval(input())) print((int(N**0.5) ** 2))
false
57.142857
[ "-ans = 0", "-for i in range(int(N**0.5) + 1):", "- ans = max(ans, i * i)", "-print(ans)", "+print((int(N**0.5) ** 2))" ]
false
0.038602
0.050452
0.765118
[ "s326843003", "s462630232" ]
u815878613
p02983
python
s912927735
s861895144
832
220
2,940
75,976
Accepted
Accepted
73.56
L, R = list(map(int, input().split())) if R - L >= 2019: ans = 0 else: ans = 2019 for i in range(L, R): x = i % 2019 for j in range(i + 1, R + 1): a = x * j ans = min(a % 2019, ans) print(ans)
import numpy as np L, R = list(map(int, input().split())) if R - L >= 2019: ans = 0 else: A = np.arange(L, R + 1) % 2019 B = A.reshape(1, -1) C = (A.reshape(-1, 1) * B) % 2019 r = np.arange(len(A)) C[r, r] = 2019 ans = np.min(C) print(ans)
13
15
253
279
L, R = list(map(int, input().split())) if R - L >= 2019: ans = 0 else: ans = 2019 for i in range(L, R): x = i % 2019 for j in range(i + 1, R + 1): a = x * j ans = min(a % 2019, ans) print(ans)
import numpy as np L, R = list(map(int, input().split())) if R - L >= 2019: ans = 0 else: A = np.arange(L, R + 1) % 2019 B = A.reshape(1, -1) C = (A.reshape(-1, 1) * B) % 2019 r = np.arange(len(A)) C[r, r] = 2019 ans = np.min(C) print(ans)
false
13.333333
[ "+import numpy as np", "+", "- ans = 2019", "- for i in range(L, R):", "- x = i % 2019", "- for j in range(i + 1, R + 1):", "- a = x * j", "- ans = min(a % 2019, ans)", "+ A = np.arange(L, R + 1) % 2019", "+ B = A.reshape(1, -1)", "+ C = (A.reshape(-1, 1) * B) % 2019", "+ r = np.arange(len(A))", "+ C[r, r] = 2019", "+ ans = np.min(C)" ]
false
0.041164
0.347428
0.118482
[ "s912927735", "s861895144" ]
u209619667
p03632
python
s780023067
s424056817
24
17
3,316
2,940
Accepted
Accepted
29.17
A,B,C,D = list(map(int,input().split())) AC = max(A,C) BD = min(B,D) flag = (BD-AC) <= 0 if flag: print((0)) else: print((BD-AC))
A,B,C,D = list(map(int,input().split())) AC = max(A,C) BD = min(B,D) if (BD-AC) <= 0: print((0)) else: print((BD-AC))
8
7
131
117
A, B, C, D = list(map(int, input().split())) AC = max(A, C) BD = min(B, D) flag = (BD - AC) <= 0 if flag: print((0)) else: print((BD - AC))
A, B, C, D = list(map(int, input().split())) AC = max(A, C) BD = min(B, D) if (BD - AC) <= 0: print((0)) else: print((BD - AC))
false
12.5
[ "-flag = (BD - AC) <= 0", "-if flag:", "+if (BD - AC) <= 0:" ]
false
0.083494
0.036548
2.284504
[ "s780023067", "s424056817" ]
u634576930
p02754
python
s854127364
s152643972
19
17
3,060
2,940
Accepted
Accepted
10.53
N, A, B, =list(map(int, input().split())) ans=N//(A+B)*A rem=N%(A+B) ans+=min(rem,A) print(ans)
N, A, B = list(map(int,input().split())) ans = N//(A + B)*A rem = N%(A + B) ans+=min(rem,A) print(ans)
5
6
94
102
( N, A, B, ) = list(map(int, input().split())) ans = N // (A + B) * A rem = N % (A + B) ans += min(rem, A) print(ans)
N, A, B = list(map(int, input().split())) ans = N // (A + B) * A rem = N % (A + B) ans += min(rem, A) print(ans)
false
16.666667
[ "-(", "- N,", "- A,", "- B,", "-) = list(map(int, input().split()))", "+N, A, B = list(map(int, input().split()))" ]
false
0.052451
0.007534
6.961848
[ "s854127364", "s152643972" ]
u202634017
p02866
python
s714824015
s467988633
191
171
13,908
14,396
Accepted
Accepted
10.47
n = int(eval(input())) d = list(map(int,input().split())) db = [0] * (max(d)+1) MOD = 998244353 #距離iの頂点の数をdb[i]に保存 for i in range(n): db[d[i]] += 1 if (d[0] != 0)|(db[0] != 1): print((0)) exit() ans = 1 for i in range(len(db)-1): ans *= pow(db[i],db[i+1],MOD) print((ans%MOD))
n = int(eval(input())) d = list(map(int,input().split())) db = [0] * (max(d)+1) MOD = 998244353 #距離iの頂点の数をdb[i]に保存 for i in range(n): db[d[i]] += 1 if (d[0] != 0)|(db[0] != 1): print((0)) exit() ans = 1 for i in range(len(db)-1): ans *= db[i]**db[i+1]%MOD print((ans%MOD))
20
19
308
302
n = int(eval(input())) d = list(map(int, input().split())) db = [0] * (max(d) + 1) MOD = 998244353 # 距離iの頂点の数をdb[i]に保存 for i in range(n): db[d[i]] += 1 if (d[0] != 0) | (db[0] != 1): print((0)) exit() ans = 1 for i in range(len(db) - 1): ans *= pow(db[i], db[i + 1], MOD) print((ans % MOD))
n = int(eval(input())) d = list(map(int, input().split())) db = [0] * (max(d) + 1) MOD = 998244353 # 距離iの頂点の数をdb[i]に保存 for i in range(n): db[d[i]] += 1 if (d[0] != 0) | (db[0] != 1): print((0)) exit() ans = 1 for i in range(len(db) - 1): ans *= db[i] ** db[i + 1] % MOD print((ans % MOD))
false
5
[ "- ans *= pow(db[i], db[i + 1], MOD)", "+ ans *= db[i] ** db[i + 1] % MOD" ]
false
0.06442
0.065997
0.976104
[ "s714824015", "s467988633" ]
u735069283
p03220
python
s596182125
s249870568
153
19
13,520
3,064
Accepted
Accepted
87.58
import numpy as np N = int(eval(input())) T,A =list(map(int,input().split())) H = np.array(input().split(),dtype=np.float64) x=np.abs(T-H*0.006-A) ans=np.argmin(x)+1 print(ans)
N=int(eval(input())) T,A=list(map(int,input().split())) H=[int(x) for x in input().split()] answer=0 deff=float('inf') for i in range(N): deff=min(deff,abs(H[i]-(T-A)/0.006)) if deff==abs(H[i]-(T-A)/0.006): answer=i+1 print(answer)
7
10
170
236
import numpy as np N = int(eval(input())) T, A = list(map(int, input().split())) H = np.array(input().split(), dtype=np.float64) x = np.abs(T - H * 0.006 - A) ans = np.argmin(x) + 1 print(ans)
N = int(eval(input())) T, A = list(map(int, input().split())) H = [int(x) for x in input().split()] answer = 0 deff = float("inf") for i in range(N): deff = min(deff, abs(H[i] - (T - A) / 0.006)) if deff == abs(H[i] - (T - A) / 0.006): answer = i + 1 print(answer)
false
30
[ "-import numpy as np", "-", "-H = np.array(input().split(), dtype=np.float64)", "-x = np.abs(T - H * 0.006 - A)", "-ans = np.argmin(x) + 1", "-print(ans)", "+H = [int(x) for x in input().split()]", "+answer = 0", "+deff = float(\"inf\")", "+for i in range(N):", "+ deff = min(deff, abs(H[i] - (T - A) / 0.006))", "+ if deff == abs(H[i] - (T - A) / 0.006):", "+ answer = i + 1", "+print(answer)" ]
false
0.449201
0.044766
10.034499
[ "s596182125", "s249870568" ]
u445624660
p03457
python
s109466024
s362606799
416
256
3,064
9,080
Accepted
Accepted
38.46
# from abs import math n = int(eval(input())) tmpt = 0 tmpx, tmpy = 0, 0 c = 0 def check(t, x, y): if t>=x+y and ( (t%2==0 and (x+y)%2==0) or (t%2==1 and (x+y)%2==1) ): return True else: return False for i in range(n): t, x, y = list(map(int, input().split())) if x==tmpx and y==tmpy: break target = t-tmpt tmpt = t t_x, t_y = abs(x-tmpx), abs(y-tmpy) tmpx = x tmpy = y if check(target, t_x, t_y): c+=1 else: break if n==c: print('Yes') else: print('No')
# 最高で進んでもtを超えることはできない # 1ターンにつき1進むので偶奇をみる n = int(eval(input())) pre = [0, 0, 0] # time, x, y for i in range(n): t, x, y = list(map(int, input().split())) t -= pre[0] x -= pre[1] y -= pre[2] if t < abs(x) + abs(y) or (abs(x) + abs(y)) % 2 != t % 2: print("No") exit() pre = [t, x, y] print("Yes")
32
15
574
340
# from abs import math n = int(eval(input())) tmpt = 0 tmpx, tmpy = 0, 0 c = 0 def check(t, x, y): if t >= x + y and ( (t % 2 == 0 and (x + y) % 2 == 0) or (t % 2 == 1 and (x + y) % 2 == 1) ): return True else: return False for i in range(n): t, x, y = list(map(int, input().split())) if x == tmpx and y == tmpy: break target = t - tmpt tmpt = t t_x, t_y = abs(x - tmpx), abs(y - tmpy) tmpx = x tmpy = y if check(target, t_x, t_y): c += 1 else: break if n == c: print("Yes") else: print("No")
# 最高で進んでもtを超えることはできない # 1ターンにつき1進むので偶奇をみる n = int(eval(input())) pre = [0, 0, 0] # time, x, y for i in range(n): t, x, y = list(map(int, input().split())) t -= pre[0] x -= pre[1] y -= pre[2] if t < abs(x) + abs(y) or (abs(x) + abs(y)) % 2 != t % 2: print("No") exit() pre = [t, x, y] print("Yes")
false
53.125
[ "-# from abs import math", "+# 最高で進んでもtを超えることはできない", "+# 1ターンにつき1進むので偶奇をみる", "-tmpt = 0", "-tmpx, tmpy = 0, 0", "-c = 0", "-", "-", "-def check(t, x, y):", "- if t >= x + y and (", "- (t % 2 == 0 and (x + y) % 2 == 0) or (t % 2 == 1 and (x + y) % 2 == 1)", "- ):", "- return True", "- else:", "- return False", "-", "-", "+pre = [0, 0, 0] # time, x, y", "- if x == tmpx and y == tmpy:", "- break", "- target = t - tmpt", "- tmpt = t", "- t_x, t_y = abs(x - tmpx), abs(y - tmpy)", "- tmpx = x", "- tmpy = y", "- if check(target, t_x, t_y):", "- c += 1", "- else:", "- break", "-if n == c:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+ t -= pre[0]", "+ x -= pre[1]", "+ y -= pre[2]", "+ if t < abs(x) + abs(y) or (abs(x) + abs(y)) % 2 != t % 2:", "+ print(\"No\")", "+ exit()", "+ pre = [t, x, y]", "+print(\"Yes\")" ]
false
0.046775
0.043126
1.08461
[ "s109466024", "s362606799" ]
u497046426
p02768
python
s571652003
s844505391
265
176
19,252
3,064
Accepted
Accepted
33.58
def binom(n, r, mod): if n < r or n < 0 or r < 0: return 0 if n - r < r: r = n - r if r == 0: return 1 elif r == 1: return n numerator = [(n - r + 1 + k) % mod for k in range(r)] # (n-r+1)*(n-r+2)*...*(n-1)*n denominator = [1 + k for k in range(r)] # 1*2*...*(r-1)*r X = 1; Y = 1 for k in range(r): X = (X * ((n - r + 1 + k) % mod)) % mod Y = (Y * ((1 + k) % mod)) % mod return X * pow(Y, mod-2, mod) MOD = 10**9 + 7 n, a, b = list(map(int, input().split())) ans = (pow(2, n, MOD) - 1 - ((binom(n, a, MOD) + binom(n, b, MOD)) % MOD)) % MOD print(ans)
def binom(n, r, mod): if n < r or n < 0 or r < 0: return 0 if n - r < r: r = n - r if r == 0: return 1 elif r == 1: return n X = 1; Y = 1 for k in range(r): X = (X * ((n - r + 1 + k) % mod)) % mod Y = (Y * ((1 + k) % mod)) % mod return X * pow(Y, mod-2, mod) MOD = 10**9 + 7 n, a, b = list(map(int, input().split())) ans = (pow(2, n, MOD) - 1 - ((binom(n, a, MOD) + binom(n, b, MOD)) % MOD)) % MOD print(ans)
20
17
632
469
def binom(n, r, mod): if n < r or n < 0 or r < 0: return 0 if n - r < r: r = n - r if r == 0: return 1 elif r == 1: return n numerator = [(n - r + 1 + k) % mod for k in range(r)] # (n-r+1)*(n-r+2)*...*(n-1)*n denominator = [1 + k for k in range(r)] # 1*2*...*(r-1)*r X = 1 Y = 1 for k in range(r): X = (X * ((n - r + 1 + k) % mod)) % mod Y = (Y * ((1 + k) % mod)) % mod return X * pow(Y, mod - 2, mod) MOD = 10**9 + 7 n, a, b = list(map(int, input().split())) ans = (pow(2, n, MOD) - 1 - ((binom(n, a, MOD) + binom(n, b, MOD)) % MOD)) % MOD print(ans)
def binom(n, r, mod): if n < r or n < 0 or r < 0: return 0 if n - r < r: r = n - r if r == 0: return 1 elif r == 1: return n X = 1 Y = 1 for k in range(r): X = (X * ((n - r + 1 + k) % mod)) % mod Y = (Y * ((1 + k) % mod)) % mod return X * pow(Y, mod - 2, mod) MOD = 10**9 + 7 n, a, b = list(map(int, input().split())) ans = (pow(2, n, MOD) - 1 - ((binom(n, a, MOD) + binom(n, b, MOD)) % MOD)) % MOD print(ans)
false
15
[ "- numerator = [(n - r + 1 + k) % mod for k in range(r)] # (n-r+1)*(n-r+2)*...*(n-1)*n", "- denominator = [1 + k for k in range(r)] # 1*2*...*(r-1)*r" ]
false
0.151024
0.105886
1.426291
[ "s571652003", "s844505391" ]
u530383736
p02685
python
s632682828
s002634273
864
411
9,248
40,300
Accepted
Accepted
52.43
# -*- coding: utf-8 -*- import sys N,M,K = list(map(int, input().rstrip().split())) #----- if (M == 1) and (K == N-1): print((1)) sys.exit() elif (M == 1) and (K < N-1): print((0)) sys.exit() mod = 998244353 a = M * pow(M-1, N-1, mod) inv_M1 = pow((M-1), mod-2, mod ) # inverse element comb = 1 ans = 0 for i in range(K+1): ans += ( comb * a ) ans %= mod # Calculate variables for next step a *= inv_M1 a %= mod inv_i1 = pow(i+1, mod-2, mod) # inverse element comb *= ( (N-1-i) * inv_i1 ) comb %= mod print(ans)
# -*- coding: utf-8 -*- N,M,K = list(map(int, input().rstrip().split())) #----- # Calculate the Factorial and it's Inverse Element fact = [0]*(N+1) fact_inv = [0]*(N+1) inv = [0]*(N+1) mod = 998244353 fact[0] = fact[1] = 1 fact_inv[0] = fact_inv[1] = 1 inv[1] = 1 for i in range(2, N+1): fact[i] = (fact[i-1] * i) % mod inv[i] = mod - ( inv[mod%i] * (mod // i) ) % mod fact_inv[i] = ( fact_inv[i-1] * inv[i] ) % mod #----- # Calculate (M-1) raised to the power of "0 to N-1" pow_M1 = [0]*N pow_M1[0] = 1 for i in range(1, N): pow_M1[i] = ( pow_M1[i-1] * (M-1) ) % mod #----- ans = 0 for i in range(K+1): comb = ( fact[N-1] * fact_inv[i] * fact_inv[N-1-i] ) % mod ans += ( comb * M * pow_M1[N-i-1] ) % mod ans %= mod print(ans)
36
38
612
806
# -*- coding: utf-8 -*- import sys N, M, K = list(map(int, input().rstrip().split())) # ----- if (M == 1) and (K == N - 1): print((1)) sys.exit() elif (M == 1) and (K < N - 1): print((0)) sys.exit() mod = 998244353 a = M * pow(M - 1, N - 1, mod) inv_M1 = pow((M - 1), mod - 2, mod) # inverse element comb = 1 ans = 0 for i in range(K + 1): ans += comb * a ans %= mod # Calculate variables for next step a *= inv_M1 a %= mod inv_i1 = pow(i + 1, mod - 2, mod) # inverse element comb *= (N - 1 - i) * inv_i1 comb %= mod print(ans)
# -*- coding: utf-8 -*- N, M, K = list(map(int, input().rstrip().split())) # ----- # Calculate the Factorial and it's Inverse Element fact = [0] * (N + 1) fact_inv = [0] * (N + 1) inv = [0] * (N + 1) mod = 998244353 fact[0] = fact[1] = 1 fact_inv[0] = fact_inv[1] = 1 inv[1] = 1 for i in range(2, N + 1): fact[i] = (fact[i - 1] * i) % mod inv[i] = mod - (inv[mod % i] * (mod // i)) % mod fact_inv[i] = (fact_inv[i - 1] * inv[i]) % mod # ----- # Calculate (M-1) raised to the power of "0 to N-1" pow_M1 = [0] * N pow_M1[0] = 1 for i in range(1, N): pow_M1[i] = (pow_M1[i - 1] * (M - 1)) % mod # ----- ans = 0 for i in range(K + 1): comb = (fact[N - 1] * fact_inv[i] * fact_inv[N - 1 - i]) % mod ans += (comb * M * pow_M1[N - i - 1]) % mod ans %= mod print(ans)
false
5.263158
[ "-import sys", "-", "-if (M == 1) and (K == N - 1):", "- print((1))", "- sys.exit()", "-elif (M == 1) and (K < N - 1):", "- print((0))", "- sys.exit()", "+# Calculate the Factorial and it's Inverse Element", "+fact = [0] * (N + 1)", "+fact_inv = [0] * (N + 1)", "+inv = [0] * (N + 1)", "-a = M * pow(M - 1, N - 1, mod)", "-inv_M1 = pow((M - 1), mod - 2, mod) # inverse element", "-comb = 1", "+fact[0] = fact[1] = 1", "+fact_inv[0] = fact_inv[1] = 1", "+inv[1] = 1", "+for i in range(2, N + 1):", "+ fact[i] = (fact[i - 1] * i) % mod", "+ inv[i] = mod - (inv[mod % i] * (mod // i)) % mod", "+ fact_inv[i] = (fact_inv[i - 1] * inv[i]) % mod", "+# Calculate (M-1) raised to the power of \"0 to N-1\"", "+pow_M1 = [0] * N", "+pow_M1[0] = 1", "+for i in range(1, N):", "+ pow_M1[i] = (pow_M1[i - 1] * (M - 1)) % mod", "- ans += comb * a", "+ comb = (fact[N - 1] * fact_inv[i] * fact_inv[N - 1 - i]) % mod", "+ ans += (comb * M * pow_M1[N - i - 1]) % mod", "- # Calculate variables for next step", "- a *= inv_M1", "- a %= mod", "- inv_i1 = pow(i + 1, mod - 2, mod) # inverse element", "- comb *= (N - 1 - i) * inv_i1", "- comb %= mod" ]
false
0.0853
0.32911
0.259184
[ "s632682828", "s002634273" ]
u268516119
p03673
python
s068793792
s262620114
220
107
29,620
26,580
Accepted
Accepted
51.36
import sys fastinput=sys.stdin.readline N=int(eval(input())) a=[int(i) for i in fastinput().split()] result=[None]*N if N%2:#odd c=(N-1)//2 for num,i in enumerate(a): r=(num+1)//2 if num==0: result[c]=i else: if num%2:#右半分 result[c+r]=i else: result[c-r]=i else:#even for num,i in enumerate(a): d=(N-num-1)//2 if num%2:#左半分 result[d]=i else: result[N-1-d]=i print((" ".join([str(j) for j in result])))
import sys fastinput=sys.stdin.readline from collections import deque N=int(eval(input())) a=fastinput().split() result=deque() for k,i in enumerate(a): if (N-k)%2: result.appendleft(i) else:result.append(i) print((" ".join(result)))
25
11
582
251
import sys fastinput = sys.stdin.readline N = int(eval(input())) a = [int(i) for i in fastinput().split()] result = [None] * N if N % 2: # odd c = (N - 1) // 2 for num, i in enumerate(a): r = (num + 1) // 2 if num == 0: result[c] = i else: if num % 2: # 右半分 result[c + r] = i else: result[c - r] = i else: # even for num, i in enumerate(a): d = (N - num - 1) // 2 if num % 2: # 左半分 result[d] = i else: result[N - 1 - d] = i print((" ".join([str(j) for j in result])))
import sys fastinput = sys.stdin.readline from collections import deque N = int(eval(input())) a = fastinput().split() result = deque() for k, i in enumerate(a): if (N - k) % 2: result.appendleft(i) else: result.append(i) print((" ".join(result)))
false
56
[ "+from collections import deque", "+", "-a = [int(i) for i in fastinput().split()]", "-result = [None] * N", "-if N % 2: # odd", "- c = (N - 1) // 2", "- for num, i in enumerate(a):", "- r = (num + 1) // 2", "- if num == 0:", "- result[c] = i", "- else:", "- if num % 2: # 右半分", "- result[c + r] = i", "- else:", "- result[c - r] = i", "-else: # even", "- for num, i in enumerate(a):", "- d = (N - num - 1) // 2", "- if num % 2: # 左半分", "- result[d] = i", "- else:", "- result[N - 1 - d] = i", "-print((\" \".join([str(j) for j in result])))", "+a = fastinput().split()", "+result = deque()", "+for k, i in enumerate(a):", "+ if (N - k) % 2:", "+ result.appendleft(i)", "+ else:", "+ result.append(i)", "+print((\" \".join(result)))" ]
false
0.040646
0.03768
1.078712
[ "s068793792", "s262620114" ]
u054106284
p02889
python
s400576954
s358163481
1,874
1,107
20,228
23,864
Accepted
Accepted
40.93
N, M, L = (int(i) for i in input().split()) import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix graph = [[0]*N for i in range(N)] for i in range(M): a, b, c = (int(i) for i in input().split()) graph[a-1][b-1] = c graph[b-1][a-1] = c graph = csr_matrix(graph) d = floyd_warshall(csgraph=graph, directed=False) new_graph = [[0]*N for i in range(N)] for i in range(N): for j in range(N): if d[i][j] <= L: new_graph[i][j] = 1 new_graph[j][i] = 1 graph = csr_matrix(new_graph) d = floyd_warshall(csgraph=graph, directed=False) Q = int(eval(input())) for i in range(Q): s, t = (int(i) for i in input().split()) if d[s-1][t-1] == float("inf"): print("-1") else: print((int(d[s-1][t-1]-1)))
import sys input = sys.stdin.readline N, M, L = (int(i) for i in input().split()) import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix graph = [[0]*N for i in range(N)] for i in range(M): a, b, c = (int(i) for i in input().split()) graph[a-1][b-1] = c graph[b-1][a-1] = c graph = csr_matrix(graph) d = floyd_warshall(csgraph=graph, directed=False) new_graph = [[0]*N for i in range(N)] for i in range(N): for j in range(N): if d[i][j] <= L: new_graph[i][j] = 1 new_graph[j][i] = 1 graph = csr_matrix(new_graph) d = floyd_warshall(csgraph=graph, directed=False) Q = int(eval(input())) for i in range(Q): s, t = (int(i) for i in input().split()) if d[s-1][t-1] == float("inf"): print("-1") else: print((int(d[s-1][t-1]-1)))
31
34
836
878
N, M, L = (int(i) for i in input().split()) import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix graph = [[0] * N for i in range(N)] for i in range(M): a, b, c = (int(i) for i in input().split()) graph[a - 1][b - 1] = c graph[b - 1][a - 1] = c graph = csr_matrix(graph) d = floyd_warshall(csgraph=graph, directed=False) new_graph = [[0] * N for i in range(N)] for i in range(N): for j in range(N): if d[i][j] <= L: new_graph[i][j] = 1 new_graph[j][i] = 1 graph = csr_matrix(new_graph) d = floyd_warshall(csgraph=graph, directed=False) Q = int(eval(input())) for i in range(Q): s, t = (int(i) for i in input().split()) if d[s - 1][t - 1] == float("inf"): print("-1") else: print((int(d[s - 1][t - 1] - 1)))
import sys input = sys.stdin.readline N, M, L = (int(i) for i in input().split()) import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix graph = [[0] * N for i in range(N)] for i in range(M): a, b, c = (int(i) for i in input().split()) graph[a - 1][b - 1] = c graph[b - 1][a - 1] = c graph = csr_matrix(graph) d = floyd_warshall(csgraph=graph, directed=False) new_graph = [[0] * N for i in range(N)] for i in range(N): for j in range(N): if d[i][j] <= L: new_graph[i][j] = 1 new_graph[j][i] = 1 graph = csr_matrix(new_graph) d = floyd_warshall(csgraph=graph, directed=False) Q = int(eval(input())) for i in range(Q): s, t = (int(i) for i in input().split()) if d[s - 1][t - 1] == float("inf"): print("-1") else: print((int(d[s - 1][t - 1] - 1)))
false
8.823529
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
1.05893
0.439762
2.407961
[ "s400576954", "s358163481" ]
u923279197
p03578
python
s510622426
s064859347
446
410
122,960
122,832
Accepted
Accepted
8.07
from collections import Counter n = int(eval(input())) D = list(map(int,input().split())) D = Counter(D) m = int(eval(input())) T = list(map(int,input().split())) T = Counter(T) #print(D) #print(T) for key in T: if D[key] < T[key]: print('NO') exit() print('YES')
n = int(eval(input())) d = list(map(int,input().split())) d.sort() m = int(eval(input())) t = list(map(int,input().split())) t.sort() now = 0 for x in t: if now == n: print("NO") exit() while d[now] != x: now += 1 if now == n: print("NO") exit() now += 1 print("YES")
15
19
286
342
from collections import Counter n = int(eval(input())) D = list(map(int, input().split())) D = Counter(D) m = int(eval(input())) T = list(map(int, input().split())) T = Counter(T) # print(D) # print(T) for key in T: if D[key] < T[key]: print("NO") exit() print("YES")
n = int(eval(input())) d = list(map(int, input().split())) d.sort() m = int(eval(input())) t = list(map(int, input().split())) t.sort() now = 0 for x in t: if now == n: print("NO") exit() while d[now] != x: now += 1 if now == n: print("NO") exit() now += 1 print("YES")
false
21.052632
[ "-from collections import Counter", "-", "-D = list(map(int, input().split()))", "-D = Counter(D)", "+d = list(map(int, input().split()))", "+d.sort()", "-T = list(map(int, input().split()))", "-T = Counter(T)", "-# print(D)", "-# print(T)", "-for key in T:", "- if D[key] < T[key]:", "+t = list(map(int, input().split()))", "+t.sort()", "+now = 0", "+for x in t:", "+ if now == n:", "+ while d[now] != x:", "+ now += 1", "+ if now == n:", "+ print(\"NO\")", "+ exit()", "+ now += 1" ]
false
0.042889
0.046768
0.917072
[ "s510622426", "s064859347" ]
u883040023
p02898
python
s509279568
s956134519
55
49
11,908
11,912
Accepted
Accepted
10.91
N , K = list(map(int , input().split())) h = list(map(int , input().split())) can_ride = [] for i in range(N): if h[i] >= K: can_ride.append(h[i]) print((len(can_ride)))
n,k = list(map(int,input().split())) H = list(map(int,input().split())) ans = 0 for i in H: if i >= k: ans += 1 print(ans)
10
9
193
146
N, K = list(map(int, input().split())) h = list(map(int, input().split())) can_ride = [] for i in range(N): if h[i] >= K: can_ride.append(h[i]) print((len(can_ride)))
n, k = list(map(int, input().split())) H = list(map(int, input().split())) ans = 0 for i in H: if i >= k: ans += 1 print(ans)
false
10
[ "-N, K = list(map(int, input().split()))", "-h = list(map(int, input().split()))", "-can_ride = []", "-for i in range(N):", "- if h[i] >= K:", "- can_ride.append(h[i])", "-print((len(can_ride)))", "+n, k = list(map(int, input().split()))", "+H = list(map(int, input().split()))", "+ans = 0", "+for i in H:", "+ if i >= k:", "+ ans += 1", "+print(ans)" ]
false
0.047569
0.037234
1.277564
[ "s509279568", "s956134519" ]
u653642801
p04031
python
s707418798
s322446647
54
17
5,788
2,940
Accepted
Accepted
68.52
from statistics import mean def main(): n = int(eval(input())) a = list(map(int,input().split())) ave = mean(a) ave = round(ave) ans =0 for i in a: ans += (i-ave)**2 print(ans) if __name__ == "__main__": main()
n = int(eval(input())) a = list(map(int, input().split())) ave = round(sum(a)/n) ans = 0 for i in a: ans += (ave - i)**2 print(ans)
18
10
273
142
from statistics import mean def main(): n = int(eval(input())) a = list(map(int, input().split())) ave = mean(a) ave = round(ave) ans = 0 for i in a: ans += (i - ave) ** 2 print(ans) if __name__ == "__main__": main()
n = int(eval(input())) a = list(map(int, input().split())) ave = round(sum(a) / n) ans = 0 for i in a: ans += (ave - i) ** 2 print(ans)
false
44.444444
[ "-from statistics import mean", "-", "-", "-def main():", "- n = int(eval(input()))", "- a = list(map(int, input().split()))", "- ave = mean(a)", "- ave = round(ave)", "- ans = 0", "- for i in a:", "- ans += (i - ave) ** 2", "- print(ans)", "-", "-", "-if __name__ == \"__main__\":", "- main()", "+n = int(eval(input()))", "+a = list(map(int, input().split()))", "+ave = round(sum(a) / n)", "+ans = 0", "+for i in a:", "+ ans += (ave - i) ** 2", "+print(ans)" ]
false
0.075491
0.080081
0.942682
[ "s707418798", "s322446647" ]
u952708174
p02888
python
s319040038
s461823242
1,012
883
3,188
3,188
Accepted
Accepted
12.75
def d_triangles(): from itertools import combinations from bisect import bisect_right N = int(eval(input())) L = sorted([int(i) for i in input().split()]) ans = 0 for max_index in range(2, N): c = L[max_index] for second_index in range(max_index): b = L[second_index] other_index = bisect_right(L, c - b) if max_index > other_index: ans += max_index - other_index if other_index <= second_index: ans -= 1 return ans // 2 print((d_triangles()))
def d_triangles(): from bisect import bisect_right N = int(eval(input())) L = sorted([int(i) for i in input().split()]) ans = 0 for max_index in range(2, N): for second_index in range(1, max_index): b, c = L[second_index], L[max_index] # b <= c となるように辺を選ぶ (ソートしておけば簡単)。 # 残りの辺の長さを a として、三角不等式は c < a + b ⇔ a > c - b である。 # よって二分探索で長さが c - b より大きく b より小さな辺を求めればよい。 third_index = bisect_right(L, c - b) if third_index < second_index: ans += second_index - third_index return ans print((d_triangles()))
19
18
587
630
def d_triangles(): from itertools import combinations from bisect import bisect_right N = int(eval(input())) L = sorted([int(i) for i in input().split()]) ans = 0 for max_index in range(2, N): c = L[max_index] for second_index in range(max_index): b = L[second_index] other_index = bisect_right(L, c - b) if max_index > other_index: ans += max_index - other_index if other_index <= second_index: ans -= 1 return ans // 2 print((d_triangles()))
def d_triangles(): from bisect import bisect_right N = int(eval(input())) L = sorted([int(i) for i in input().split()]) ans = 0 for max_index in range(2, N): for second_index in range(1, max_index): b, c = L[second_index], L[max_index] # b <= c となるように辺を選ぶ (ソートしておけば簡単)。 # 残りの辺の長さを a として、三角不等式は c < a + b ⇔ a > c - b である。 # よって二分探索で長さが c - b より大きく b より小さな辺を求めればよい。 third_index = bisect_right(L, c - b) if third_index < second_index: ans += second_index - third_index return ans print((d_triangles()))
false
5.263158
[ "- from itertools import combinations", "- c = L[max_index]", "- for second_index in range(max_index):", "- b = L[second_index]", "- other_index = bisect_right(L, c - b)", "- if max_index > other_index:", "- ans += max_index - other_index", "- if other_index <= second_index:", "- ans -= 1", "- return ans // 2", "+ for second_index in range(1, max_index):", "+ b, c = L[second_index], L[max_index]", "+ # b <= c となるように辺を選ぶ (ソートしておけば簡単)。", "+ # 残りの辺の長さを a として、三角不等式は c < a + b ⇔ a > c - b である。", "+ # よって二分探索で長さが c - b より大きく b より小さな辺を求めればよい。", "+ third_index = bisect_right(L, c - b)", "+ if third_index < second_index:", "+ ans += second_index - third_index", "+ return ans" ]
false
0.045585
0.036878
1.236124
[ "s319040038", "s461823242" ]
u047102107
p02579
python
s659268982
s026355694
1,406
925
237,612
132,148
Accepted
Accepted
34.21
from collections import deque INF = int(1e10) def main(): from builtins import int, map H, W = list(map(int, input().split())) Ch, Cw = [int(x) - 1 for x in input().split()] Dh, Dw = [int(x) - 1 for x in input().split()] S = [eval(input()) for _ in range(H)] # dist = defaultdict(lambda: float("inf")) dist = [[float("inf")] * W for _ in range(H)] queue = deque([(Ch, Cw, 0)]) while queue: (h, w, d) = queue.popleft() if dist[h][w] == float("inf") or dist[h][w] > d: dist[h][w] = d # 5x5-grid for ddh in range(-2, 3): for ddw in range(-2, 3): nh, nw = h + ddh, w + ddw if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == '.': # cost-0 move if abs(ddh) + abs(ddw) <= 1: queue.appendleft((nh, nw, d)) # cost-1 move else: queue.append((nh, nw, d + 1)) if dist[Dh][Dw] == float("inf"): print((-1)) else: print((dist[Dh][Dw])) if __name__ == '__main__': main()
from collections import deque INF = int(1e10) dh = [0, 0, 1, -1] dw = [1, -1, 0, 0] def main(): from builtins import int, map H, W = list(map(int, input().split())) Ch, Cw = [int(x) - 1 for x in input().split()] Dh, Dw = [int(x) - 1 for x in input().split()] S = [list(eval(input())) for _ in range(H)] dist = [[INF] * W for _ in range(H)] dist[Ch][Cw] = 0 queue = deque([(Ch, Cw)]) while queue: (h, w) = queue.popleft() for i in range(4): dhi, dwi = dh[i], dw[i] nh, nw = h + dhi, w + dwi if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == '.': if dist[h][w] < dist[nh][nw]: dist[nh][nw] = dist[h][w] queue.appendleft((nh, nw)) # 5x5-grid for ddh in range(-2, 3): for ddw in range(-2, 3): if abs(ddh) + abs(ddw) <= 1: continue nh, nw = h + ddh, w + ddw if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == '.': if dist[nh][nw] > dist[h][w] + 1: dist[nh][nw] = dist[h][w] + 1 queue.append((nh, nw)) if dist[Dh][Dw] == INF: print((-1)) else: print((dist[Dh][Dw])) if __name__ == '__main__': main()
39
47
1,227
1,382
from collections import deque INF = int(1e10) def main(): from builtins import int, map H, W = list(map(int, input().split())) Ch, Cw = [int(x) - 1 for x in input().split()] Dh, Dw = [int(x) - 1 for x in input().split()] S = [eval(input()) for _ in range(H)] # dist = defaultdict(lambda: float("inf")) dist = [[float("inf")] * W for _ in range(H)] queue = deque([(Ch, Cw, 0)]) while queue: (h, w, d) = queue.popleft() if dist[h][w] == float("inf") or dist[h][w] > d: dist[h][w] = d # 5x5-grid for ddh in range(-2, 3): for ddw in range(-2, 3): nh, nw = h + ddh, w + ddw if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == ".": # cost-0 move if abs(ddh) + abs(ddw) <= 1: queue.appendleft((nh, nw, d)) # cost-1 move else: queue.append((nh, nw, d + 1)) if dist[Dh][Dw] == float("inf"): print((-1)) else: print((dist[Dh][Dw])) if __name__ == "__main__": main()
from collections import deque INF = int(1e10) dh = [0, 0, 1, -1] dw = [1, -1, 0, 0] def main(): from builtins import int, map H, W = list(map(int, input().split())) Ch, Cw = [int(x) - 1 for x in input().split()] Dh, Dw = [int(x) - 1 for x in input().split()] S = [list(eval(input())) for _ in range(H)] dist = [[INF] * W for _ in range(H)] dist[Ch][Cw] = 0 queue = deque([(Ch, Cw)]) while queue: (h, w) = queue.popleft() for i in range(4): dhi, dwi = dh[i], dw[i] nh, nw = h + dhi, w + dwi if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == ".": if dist[h][w] < dist[nh][nw]: dist[nh][nw] = dist[h][w] queue.appendleft((nh, nw)) # 5x5-grid for ddh in range(-2, 3): for ddw in range(-2, 3): if abs(ddh) + abs(ddw) <= 1: continue nh, nw = h + ddh, w + ddw if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == ".": if dist[nh][nw] > dist[h][w] + 1: dist[nh][nw] = dist[h][w] + 1 queue.append((nh, nw)) if dist[Dh][Dw] == INF: print((-1)) else: print((dist[Dh][Dw])) if __name__ == "__main__": main()
false
17.021277
[ "+dh = [0, 0, 1, -1]", "+dw = [1, -1, 0, 0]", "- S = [eval(input()) for _ in range(H)]", "- # dist = defaultdict(lambda: float(\"inf\"))", "- dist = [[float(\"inf\")] * W for _ in range(H)]", "- queue = deque([(Ch, Cw, 0)])", "+ S = [list(eval(input())) for _ in range(H)]", "+ dist = [[INF] * W for _ in range(H)]", "+ dist[Ch][Cw] = 0", "+ queue = deque([(Ch, Cw)])", "- (h, w, d) = queue.popleft()", "- if dist[h][w] == float(\"inf\") or dist[h][w] > d:", "- dist[h][w] = d", "- # 5x5-grid", "- for ddh in range(-2, 3):", "- for ddw in range(-2, 3):", "- nh, nw = h + ddh, w + ddw", "- if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == \".\":", "- # cost-0 move", "- if abs(ddh) + abs(ddw) <= 1:", "- queue.appendleft((nh, nw, d))", "- # cost-1 move", "- else:", "- queue.append((nh, nw, d + 1))", "- if dist[Dh][Dw] == float(\"inf\"):", "+ (h, w) = queue.popleft()", "+ for i in range(4):", "+ dhi, dwi = dh[i], dw[i]", "+ nh, nw = h + dhi, w + dwi", "+ if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == \".\":", "+ if dist[h][w] < dist[nh][nw]:", "+ dist[nh][nw] = dist[h][w]", "+ queue.appendleft((nh, nw))", "+ # 5x5-grid", "+ for ddh in range(-2, 3):", "+ for ddw in range(-2, 3):", "+ if abs(ddh) + abs(ddw) <= 1:", "+ continue", "+ nh, nw = h + ddh, w + ddw", "+ if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == \".\":", "+ if dist[nh][nw] > dist[h][w] + 1:", "+ dist[nh][nw] = dist[h][w] + 1", "+ queue.append((nh, nw))", "+ if dist[Dh][Dw] == INF:" ]
false
0.036262
0.100649
0.360283
[ "s659268982", "s026355694" ]
u057668615
p02690
python
s274470040
s315141167
75
35
9,160
9,164
Accepted
Accepted
53.33
X = int(eval(input())) for A in range(1000): for B in range(-500, 500): if A**5-B**5 == X: print((A, B)) exit()
x = int(eval(input())) for a in range(120): for b in range(-120, 120): if a**5 - b**5 == x: print((a, b)) exit(0)
7
6
147
147
X = int(eval(input())) for A in range(1000): for B in range(-500, 500): if A**5 - B**5 == X: print((A, B)) exit()
x = int(eval(input())) for a in range(120): for b in range(-120, 120): if a**5 - b**5 == x: print((a, b)) exit(0)
false
14.285714
[ "-X = int(eval(input()))", "-for A in range(1000):", "- for B in range(-500, 500):", "- if A**5 - B**5 == X:", "- print((A, B))", "- exit()", "+x = int(eval(input()))", "+for a in range(120):", "+ for b in range(-120, 120):", "+ if a**5 - b**5 == x:", "+ print((a, b))", "+ exit(0)" ]
false
0.058791
0.052831
1.112829
[ "s274470040", "s315141167" ]
u654470292
p02954
python
s010836531
s824252032
198
103
50,800
79,956
Accepted
Accepted
47.98
s=eval(input()) n=len(s) guki=[0,0,"r",0] ans=[0]*n for i in range(n): if guki[2]=="r": if s[i]=="R": guki[(i-guki[3])%2]+=1 else: ans[i]+=guki[(i-guki[3])%2] ans[i-1]+=guki[(i-guki[3]+1)%2] guki[0]=0 guki[1]=1 guki[2]="l" guki[3]=i-1 else: if s[i]=="L": guki[(i-guki[3])%2]+=1 else: ans[guki[3]]+=guki[(i-guki[3])%2] ans[guki[3]+1]+=guki[(i-guki[3]+1)%2] guki[0]=1 guki[1]=0 guki[2]="r" guki[3]=i ans[guki[3]]+=guki[(n-guki[3])%2] ans[guki[3]+1]+=guki[(n-guki[3]+1)%2] # print(ans) print((" ".join(map(str,ans))))
import bisect, copy, heapq, math, sys from collections import * from functools import lru_cache from itertools import accumulate, combinations, permutations, product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0]+list(accumulate(lst)) def celi(a,b): return -(-a//b) sys.setrecursionlimit(5000000) mod=pow(10,9)+7 al=[chr(ord('a') + i) for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] s=eval(input()) n=len(s) anslst=[0]*n cnt=0 for i in range(n): if s[i]=="R": cnt+=1 else: anslst[i]+=cnt//2 anslst[i-1]+=(cnt+1)//2 cnt=0 for i in range(n)[::-1]: if s[i]=="L": cnt+=1 else: anslst[i]+=cnt//2 if i+1<n: anslst[i+1]+=(cnt+1)//2 cnt=0 print((*anslst))
31
38
746
822
s = eval(input()) n = len(s) guki = [0, 0, "r", 0] ans = [0] * n for i in range(n): if guki[2] == "r": if s[i] == "R": guki[(i - guki[3]) % 2] += 1 else: ans[i] += guki[(i - guki[3]) % 2] ans[i - 1] += guki[(i - guki[3] + 1) % 2] guki[0] = 0 guki[1] = 1 guki[2] = "l" guki[3] = i - 1 else: if s[i] == "L": guki[(i - guki[3]) % 2] += 1 else: ans[guki[3]] += guki[(i - guki[3]) % 2] ans[guki[3] + 1] += guki[(i - guki[3] + 1) % 2] guki[0] = 1 guki[1] = 0 guki[2] = "r" guki[3] = i ans[guki[3]] += guki[(n - guki[3]) % 2] ans[guki[3] + 1] += guki[(n - guki[3] + 1) % 2] # print(ans) print((" ".join(map(str, ans))))
import bisect, copy, heapq, math, sys from collections import * from functools import lru_cache from itertools import accumulate, combinations, permutations, product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0] + list(accumulate(lst)) def celi(a, b): return -(-a // b) sys.setrecursionlimit(5000000) mod = pow(10, 9) + 7 al = [chr(ord("a") + i) for i in range(26)] direction = [[1, 0], [0, 1], [-1, 0], [0, -1]] s = eval(input()) n = len(s) anslst = [0] * n cnt = 0 for i in range(n): if s[i] == "R": cnt += 1 else: anslst[i] += cnt // 2 anslst[i - 1] += (cnt + 1) // 2 cnt = 0 for i in range(n)[::-1]: if s[i] == "L": cnt += 1 else: anslst[i] += cnt // 2 if i + 1 < n: anslst[i + 1] += (cnt + 1) // 2 cnt = 0 print((*anslst))
false
18.421053
[ "+import bisect, copy, heapq, math, sys", "+from collections import *", "+from functools import lru_cache", "+from itertools import accumulate, combinations, permutations, product", "+", "+", "+def input():", "+ return sys.stdin.readline()[:-1]", "+", "+", "+def ruiseki(lst):", "+ return [0] + list(accumulate(lst))", "+", "+", "+def celi(a, b):", "+ return -(-a // b)", "+", "+", "+sys.setrecursionlimit(5000000)", "+mod = pow(10, 9) + 7", "+al = [chr(ord(\"a\") + i) for i in range(26)]", "+direction = [[1, 0], [0, 1], [-1, 0], [0, -1]]", "-guki = [0, 0, \"r\", 0]", "-ans = [0] * n", "+anslst = [0] * n", "+cnt = 0", "- if guki[2] == \"r\":", "- if s[i] == \"R\":", "- guki[(i - guki[3]) % 2] += 1", "- else:", "- ans[i] += guki[(i - guki[3]) % 2]", "- ans[i - 1] += guki[(i - guki[3] + 1) % 2]", "- guki[0] = 0", "- guki[1] = 1", "- guki[2] = \"l\"", "- guki[3] = i - 1", "+ if s[i] == \"R\":", "+ cnt += 1", "- if s[i] == \"L\":", "- guki[(i - guki[3]) % 2] += 1", "- else:", "- ans[guki[3]] += guki[(i - guki[3]) % 2]", "- ans[guki[3] + 1] += guki[(i - guki[3] + 1) % 2]", "- guki[0] = 1", "- guki[1] = 0", "- guki[2] = \"r\"", "- guki[3] = i", "-ans[guki[3]] += guki[(n - guki[3]) % 2]", "-ans[guki[3] + 1] += guki[(n - guki[3] + 1) % 2]", "-# print(ans)", "-print((\" \".join(map(str, ans))))", "+ anslst[i] += cnt // 2", "+ anslst[i - 1] += (cnt + 1) // 2", "+ cnt = 0", "+for i in range(n)[::-1]:", "+ if s[i] == \"L\":", "+ cnt += 1", "+ else:", "+ anslst[i] += cnt // 2", "+ if i + 1 < n:", "+ anslst[i + 1] += (cnt + 1) // 2", "+ cnt = 0", "+print((*anslst))" ]
false
0.038361
0.039215
0.978214
[ "s010836531", "s824252032" ]
u605879293
p02255
python
s506966321
s231509285
30
20
5,980
5,976
Accepted
Accepted
33.33
def show(array): for i in range(len(array)): if i != len(array) - 1: print(array[i], end=' ') else: print(array[i]) length = int(input()) array = [int(x) for x in input().split()] for i in range(length): v = array[i] j = i-1 while j >= 0 and array[j] > v: array[j+1] = array[j] j -= 1 array[j+1] = v show(array)
def insertionSort(a): n = len(a) print((*a)) for i in range(1, n): v = a[i] j = i-1 while j >= 0 and a[j] > v: a[j+1] = a[j] j += -1 a[j+1] = v print((*a)) n = int(eval(input())) a = [int(x) for x in input().split()] insertionSort(a)
19
17
413
319
def show(array): for i in range(len(array)): if i != len(array) - 1: print(array[i], end=" ") else: print(array[i]) length = int(input()) array = [int(x) for x in input().split()] for i in range(length): v = array[i] j = i - 1 while j >= 0 and array[j] > v: array[j + 1] = array[j] j -= 1 array[j + 1] = v show(array)
def insertionSort(a): n = len(a) print((*a)) for i in range(1, n): v = a[i] j = i - 1 while j >= 0 and a[j] > v: a[j + 1] = a[j] j += -1 a[j + 1] = v print((*a)) n = int(eval(input())) a = [int(x) for x in input().split()] insertionSort(a)
false
10.526316
[ "-def show(array):", "- for i in range(len(array)):", "- if i != len(array) - 1:", "- print(array[i], end=\" \")", "- else:", "- print(array[i])", "+def insertionSort(a):", "+ n = len(a)", "+ print((*a))", "+ for i in range(1, n):", "+ v = a[i]", "+ j = i - 1", "+ while j >= 0 and a[j] > v:", "+ a[j + 1] = a[j]", "+ j += -1", "+ a[j + 1] = v", "+ print((*a))", "-length = int(input())", "-array = [int(x) for x in input().split()]", "-for i in range(length):", "- v = array[i]", "- j = i - 1", "- while j >= 0 and array[j] > v:", "- array[j + 1] = array[j]", "- j -= 1", "- array[j + 1] = v", "- show(array)", "+n = int(eval(input()))", "+a = [int(x) for x in input().split()]", "+insertionSort(a)" ]
false
0.066246
0.050039
1.323883
[ "s506966321", "s231509285" ]
u340781749
p03279
python
s128763070
s776320697
1,435
1,316
61,768
61,768
Accepted
Accepted
8.29
from bisect import bisect from collections import defaultdict class Bit: def __init__(self, n, MOD): self.size = n self.tree = [0] * (n + 1) self.depth = n.bit_length() self.mod = MOD def sum(self, i): s = 0 while i > 0: s = (s + self.tree[i]) % self.mod i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] = (self.tree[i] + x) % self.mod i += i & -i def debug_print(self): for i in range(1, self.size + 1): j = (i & -i).bit_length() print((' ' * j, self.tree[i])) def lower_bound(self, x): sum_ = 0 pos = 0 for i in range(self.depth, -1, -1): k = pos + (1 << i) if k <= self.size and sum_ + self.tree[k] < x: sum_ += self.tree[k] pos += 1 << i return pos + 1, sum_ n, m = list(map(int, input().split())) xxx = list(map(int, input().split())) yyy = list(map(int, input().split())) ab = defaultdict(set) coordinates = set() for x in xxx: if x < yyy[0] or yyy[-1] < x: continue i = bisect(yyy, x) a = x - yyy[i - 1] b = yyy[i] - x ab[a].add(b) coordinates.add(b) # Bitのindexは1から始まるように作っているが、"0"を取れるようにするため、全体を1ずらす cor_dict = {b: i for i, b in enumerate(sorted(coordinates), start=2)} cdg = cor_dict.get MOD = 10 ** 9 + 7 bit = Bit(len(coordinates) + 1, MOD) bit.add(1, 1) for a in sorted(ab): bbb = sorted(map(cdg, ab[a]), reverse=True) for b in bbb: bit.add(b, bit.sum(b - 1)) print((bit.sum(bit.size)))
from bisect import bisect from collections import defaultdict class Bit: def __init__(self, n, MOD): self.size = n self.tree = [0] * (n + 1) self.depth = n.bit_length() self.mod = MOD def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s % self.mod def add(self, i, x): while i <= self.size: self.tree[i] = (self.tree[i] + x) % self.mod i += i & -i def debug_print(self): for i in range(1, self.size + 1): j = (i & -i).bit_length() print((' ' * j, self.tree[i])) def lower_bound(self, x): sum_ = 0 pos = 0 for i in range(self.depth, -1, -1): k = pos + (1 << i) if k <= self.size and sum_ + self.tree[k] < x: sum_ += self.tree[k] pos += 1 << i return pos + 1, sum_ n, m = list(map(int, input().split())) xxx = list(map(int, input().split())) yyy = list(map(int, input().split())) ab = defaultdict(set) coordinates = set() for x in xxx: if x < yyy[0] or yyy[-1] < x: continue i = bisect(yyy, x) a = x - yyy[i - 1] b = yyy[i] - x ab[a].add(b) coordinates.add(b) # Bitのindexは1から始まるように作っているが、"0"を取れるようにするため、全体を1ずらす cor_dict = {b: i for i, b in enumerate(sorted(coordinates), start=2)} cdg = cor_dict.get MOD = 10 ** 9 + 7 bit = Bit(len(coordinates) + 1, MOD) bit.add(1, 1) for a in sorted(ab): bbb = sorted(map(cdg, ab[a]), reverse=True) for b in bbb: bit.add(b, bit.sum(b - 1)) print((bit.sum(bit.size)))
67
67
1,697
1,692
from bisect import bisect from collections import defaultdict class Bit: def __init__(self, n, MOD): self.size = n self.tree = [0] * (n + 1) self.depth = n.bit_length() self.mod = MOD def sum(self, i): s = 0 while i > 0: s = (s + self.tree[i]) % self.mod i -= i & -i return s def add(self, i, x): while i <= self.size: self.tree[i] = (self.tree[i] + x) % self.mod i += i & -i def debug_print(self): for i in range(1, self.size + 1): j = (i & -i).bit_length() print((" " * j, self.tree[i])) def lower_bound(self, x): sum_ = 0 pos = 0 for i in range(self.depth, -1, -1): k = pos + (1 << i) if k <= self.size and sum_ + self.tree[k] < x: sum_ += self.tree[k] pos += 1 << i return pos + 1, sum_ n, m = list(map(int, input().split())) xxx = list(map(int, input().split())) yyy = list(map(int, input().split())) ab = defaultdict(set) coordinates = set() for x in xxx: if x < yyy[0] or yyy[-1] < x: continue i = bisect(yyy, x) a = x - yyy[i - 1] b = yyy[i] - x ab[a].add(b) coordinates.add(b) # Bitのindexは1から始まるように作っているが、"0"を取れるようにするため、全体を1ずらす cor_dict = {b: i for i, b in enumerate(sorted(coordinates), start=2)} cdg = cor_dict.get MOD = 10**9 + 7 bit = Bit(len(coordinates) + 1, MOD) bit.add(1, 1) for a in sorted(ab): bbb = sorted(map(cdg, ab[a]), reverse=True) for b in bbb: bit.add(b, bit.sum(b - 1)) print((bit.sum(bit.size)))
from bisect import bisect from collections import defaultdict class Bit: def __init__(self, n, MOD): self.size = n self.tree = [0] * (n + 1) self.depth = n.bit_length() self.mod = MOD def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i return s % self.mod def add(self, i, x): while i <= self.size: self.tree[i] = (self.tree[i] + x) % self.mod i += i & -i def debug_print(self): for i in range(1, self.size + 1): j = (i & -i).bit_length() print((" " * j, self.tree[i])) def lower_bound(self, x): sum_ = 0 pos = 0 for i in range(self.depth, -1, -1): k = pos + (1 << i) if k <= self.size and sum_ + self.tree[k] < x: sum_ += self.tree[k] pos += 1 << i return pos + 1, sum_ n, m = list(map(int, input().split())) xxx = list(map(int, input().split())) yyy = list(map(int, input().split())) ab = defaultdict(set) coordinates = set() for x in xxx: if x < yyy[0] or yyy[-1] < x: continue i = bisect(yyy, x) a = x - yyy[i - 1] b = yyy[i] - x ab[a].add(b) coordinates.add(b) # Bitのindexは1から始まるように作っているが、"0"を取れるようにするため、全体を1ずらす cor_dict = {b: i for i, b in enumerate(sorted(coordinates), start=2)} cdg = cor_dict.get MOD = 10**9 + 7 bit = Bit(len(coordinates) + 1, MOD) bit.add(1, 1) for a in sorted(ab): bbb = sorted(map(cdg, ab[a]), reverse=True) for b in bbb: bit.add(b, bit.sum(b - 1)) print((bit.sum(bit.size)))
false
0
[ "- s = (s + self.tree[i]) % self.mod", "+ s += self.tree[i]", "- return s", "+ return s % self.mod" ]
false
0.051687
0.076181
0.678483
[ "s128763070", "s776320697" ]
u367130284
p03356
python
s167892262
s383450962
1,530
722
41,276
13,812
Accepted
Accepted
52.81
from numpy import* from collections import* class UNION_FIND(object): def __init__(self,n): #親の番号を格納する。親だった場合は-(その集合のサイズ) #作るときはParentの値を全て-1にする #こうすると全てバラバラになる self.parent=[-1 for i in range(n)] def root(self,x): #Aがどのグループに属しているか調べる if self.parent[x]<0: return x else: self.parent[x]=self.root(self.parent[x]) #親を再帰で探知 再帰は最後に上のifにひっかかる return self.parent[x] def size(self,x): #自分のいるグループの頂点数を調べる return -self.parent[self.root(x)] #親をとってきたい def union(self,x,y): #AとBをくっ付ける #AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける #print(self.parent) x=self.root(x) y=self.root(y) #print(x,y) if x==y: #すでにくっついてるからくっ付けない return False #大きい方(A)に小さいほう(B)をくっ付けたい #大小が逆だったらひっくり返しちゃう。 if self.size(x)<self.size(y): x,y=y,x self.parent[x]+=self.parent[y] #Aのサイズを更新する self.parent[y]=x #Bの親をAに変更する return True a,b=list(map(int,input().split())) *p,=list(map(int,input().split())) u=UNION_FIND(a) d=defaultdict(list) p=array(p) for i in range(b): x,y=list(map(int,input().split())) u.union(x-1,y-1) for k,v in enumerate(u.root(i)for i in range(a)): d[v].append(k) ans=0 for i in list(d.values()): i=array(i) ans+=len(set(i+1)&set(p[i])) print(ans)
class UNION_FIND(object): def __init__(self,n): #親の番号を格納する。親だった場合は-(その集合のサイズ) #作るときはParentの値を全て-1にする #こうすると全てバラバラになる self.parent=[-1 for i in range(n)] def root(self,x): #Aがどのグループに属しているか調べる if self.parent[x]<0: return x else: self.parent[x]=self.root(self.parent[x]) #親を再帰で探知 再帰は最後に上のifにひっかかる return self.parent[x] def size(self,x): #自分のいるグループの頂点数を調べる return -self.parent[self.root(x)] #親をとってきたい def union(self,x,y): #AとBをくっ付ける #AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける #print(self.parent) x=self.root(x) y=self.root(y) #print(x,y) if x==y: #すでにくっついてるからくっ付けない return False #大きい方(A)に小さいほう(B)をくっ付けたい #大小が逆だったらひっくり返しちゃう。 if self.size(x)<self.size(y): x,y=y,x self.parent[x]+=self.parent[y] #Aのサイズを更新する self.parent[y]=x #Bの親をAに変更する return True a,b=list(map(int,input().split())) *p,=list(map(int,input().split())) u=UNION_FIND(a) for i in range(b): x,y=list(map(int,input().split())) u.union(x-1,y-1) ans=0 for i in range(a): ans+=(u.root(i)==u.root(p[i]-1)) print(ans)
56
49
1,464
1,300
from numpy import * from collections import * class UNION_FIND(object): def __init__(self, n): # 親の番号を格納する。親だった場合は-(その集合のサイズ) # 作るときはParentの値を全て-1にする # こうすると全てバラバラになる self.parent = [-1 for i in range(n)] def root(self, x): # Aがどのグループに属しているか調べる if self.parent[x] < 0: return x else: self.parent[x] = self.root(self.parent[x]) # 親を再帰で探知 再帰は最後に上のifにひっかかる return self.parent[x] def size(self, x): # 自分のいるグループの頂点数を調べる return -self.parent[self.root(x)] # 親をとってきたい def union(self, x, y): # AとBをくっ付ける # AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける # print(self.parent) x = self.root(x) y = self.root(y) # print(x,y) if x == y: # すでにくっついてるからくっ付けない return False # 大きい方(A)に小さいほう(B)をくっ付けたい # 大小が逆だったらひっくり返しちゃう。 if self.size(x) < self.size(y): x, y = y, x self.parent[x] += self.parent[y] # Aのサイズを更新する self.parent[y] = x # Bの親をAに変更する return True a, b = list(map(int, input().split())) (*p,) = list(map(int, input().split())) u = UNION_FIND(a) d = defaultdict(list) p = array(p) for i in range(b): x, y = list(map(int, input().split())) u.union(x - 1, y - 1) for k, v in enumerate(u.root(i) for i in range(a)): d[v].append(k) ans = 0 for i in list(d.values()): i = array(i) ans += len(set(i + 1) & set(p[i])) print(ans)
class UNION_FIND(object): def __init__(self, n): # 親の番号を格納する。親だった場合は-(その集合のサイズ) # 作るときはParentの値を全て-1にする # こうすると全てバラバラになる self.parent = [-1 for i in range(n)] def root(self, x): # Aがどのグループに属しているか調べる if self.parent[x] < 0: return x else: self.parent[x] = self.root(self.parent[x]) # 親を再帰で探知 再帰は最後に上のifにひっかかる return self.parent[x] def size(self, x): # 自分のいるグループの頂点数を調べる return -self.parent[self.root(x)] # 親をとってきたい def union(self, x, y): # AとBをくっ付ける # AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける # print(self.parent) x = self.root(x) y = self.root(y) # print(x,y) if x == y: # すでにくっついてるからくっ付けない return False # 大きい方(A)に小さいほう(B)をくっ付けたい # 大小が逆だったらひっくり返しちゃう。 if self.size(x) < self.size(y): x, y = y, x self.parent[x] += self.parent[y] # Aのサイズを更新する self.parent[y] = x # Bの親をAに変更する return True a, b = list(map(int, input().split())) (*p,) = list(map(int, input().split())) u = UNION_FIND(a) for i in range(b): x, y = list(map(int, input().split())) u.union(x - 1, y - 1) ans = 0 for i in range(a): ans += u.root(i) == u.root(p[i] - 1) print(ans)
false
12.5
[ "-from numpy import *", "-from collections import *", "-", "-", "-d = defaultdict(list)", "-p = array(p)", "-for k, v in enumerate(u.root(i) for i in range(a)):", "- d[v].append(k)", "-for i in list(d.values()):", "- i = array(i)", "- ans += len(set(i + 1) & set(p[i]))", "+for i in range(a):", "+ ans += u.root(i) == u.root(p[i] - 1)" ]
false
0.183834
0.039265
4.681834
[ "s167892262", "s383450962" ]
u633068244
p00687
python
s119226523
s119486205
1,130
680
43,784
12,284
Accepted
Accepted
39.82
while 1: n,a,b = list(map(int,input().split())) if n == 0: break dp = [0]*(n+max(a,b)+1) dp[a] = dp[b] = 1 for i in range(n+1): if dp[i]: dp[i+a] = dp[i+b] = 1 print(n - sum(dp[:n+1]))
while 1: n,a,b = list(map(int,input().split())) if n == 0: break S = [1]*(n+1) for i in range(a): s = b*i while s <= n: S[s] = 0 s += a print(sum(S))
9
10
200
170
while 1: n, a, b = list(map(int, input().split())) if n == 0: break dp = [0] * (n + max(a, b) + 1) dp[a] = dp[b] = 1 for i in range(n + 1): if dp[i]: dp[i + a] = dp[i + b] = 1 print(n - sum(dp[: n + 1]))
while 1: n, a, b = list(map(int, input().split())) if n == 0: break S = [1] * (n + 1) for i in range(a): s = b * i while s <= n: S[s] = 0 s += a print(sum(S))
false
10
[ "- dp = [0] * (n + max(a, b) + 1)", "- dp[a] = dp[b] = 1", "- for i in range(n + 1):", "- if dp[i]:", "- dp[i + a] = dp[i + b] = 1", "- print(n - sum(dp[: n + 1]))", "+ S = [1] * (n + 1)", "+ for i in range(a):", "+ s = b * i", "+ while s <= n:", "+ S[s] = 0", "+ s += a", "+ print(sum(S))" ]
false
0.036902
0.037717
0.978397
[ "s119226523", "s119486205" ]
u597374218
p02881
python
s236612400
s464675183
184
144
2,940
9,428
Accepted
Accepted
21.74
N=int(eval(input())) move=int(N**.5) while N%move!=0: move-=1 print((N//move+move-2))
N=int(eval(input())) move=10**12 for n in range(1,int(N**.5)+1): if N%n==0: move=min(move,N//n+n-2) print(move)
5
6
85
122
N = int(eval(input())) move = int(N**0.5) while N % move != 0: move -= 1 print((N // move + move - 2))
N = int(eval(input())) move = 10**12 for n in range(1, int(N**0.5) + 1): if N % n == 0: move = min(move, N // n + n - 2) print(move)
false
16.666667
[ "-move = int(N**0.5)", "-while N % move != 0:", "- move -= 1", "-print((N // move + move - 2))", "+move = 10**12", "+for n in range(1, int(N**0.5) + 1):", "+ if N % n == 0:", "+ move = min(move, N // n + n - 2)", "+print(move)" ]
false
0.095692
0.03931
2.434291
[ "s236612400", "s464675183" ]
u788137651
p03450
python
s588146473
s020217811
1,471
1,096
138,528
10,268
Accepted
Accepted
25.49
import sys input = sys.stdin.readline inf = float('inf') mod = 10**9+7 def INT_(n): return int(n)-1 def MI(): return list(map(int, input().split())) def MF(): return list(map(float, input().split())) def MI_(): return list(map(INT_, input().split())) def LI(): return list(MI()) def LI_(): return [int(x) - 1 for x in input().split()] def LF(): return list(MF()) def LIN(n: int): return [eval(input()) for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] def LLIN_(n: int): return [LI_() for _ in range(n)] def LLI(): return [list(map(int, l.split())) for l in eval(input())] def I(): return int(eval(input())) def F(): return float(eval(input())) def ST(): return input().replace('\n', '') def main(): class WeightedUnionFind(): def __init__(self, n): self.nodes = [-1 for _ in range(n)] self.weight = [0] * n def get_root(self, x): if self.nodes[x] < 0: return x else: y = self.get_root(self.nodes[x]) self.weight[x] += self.weight[self.nodes[x]] self.nodes[x] = y return y def unite(self, x, y, w): w += self.weight[x]-self.weight[y] root_x = self.get_root(x) root_y = self.get_root(y) if root_x != root_y: # 大きい木の方につないだほうが計算量が減る if self.nodes[root_x] > self.nodes[root_y]: root_x, root_y = root_y, root_x w *= -1 self.nodes[root_x] += self.nodes[root_y] self.nodes[root_y] = root_x self.weight[root_y] = w def diff(self, x, y): return self.weight[y] - self.weight[x] def same(self, x, y): return get_root(x) == get_root(y) N, M = MI() edge = [[] for _ in range(N)] uf = WeightedUnionFind(N) get_root, unite, nodes, diff, same = uf.get_root, uf.unite, uf.nodes, uf.diff, uf.same distanse = [0] * N distanse[0] = 0 rev_edge = [[]for _ in range(N)] for _ in range(M): l, r, d = MI_() d += 1 edge[l].append((r, d)) if same(l, r) and diff(l, r) != d: print("No") exit() else: unite(l, r, d) print("Yes") if __name__ == '__main__': main()
import sys input = sys.stdin.readline inf = float('inf') mod = 10**9+7 def INT_(n): return int(n)-1 def MI(): return list(map(int, input().split())) def MF(): return list(map(float, input().split())) def MI_(): return list(map(INT_, input().split())) def LI(): return list(MI()) def LI_(): return [int(x) - 1 for x in input().split()] def LF(): return list(MF()) def LIN(n: int): return [eval(input()) for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] def LLIN_(n: int): return [LI_() for _ in range(n)] def LLI(): return [list(map(int, l.split())) for l in eval(input())] def I(): return int(eval(input())) def F(): return float(eval(input())) def ST(): return input().replace('\n', '') def main(): class WeightedUnionFind(): def __init__(self, n): self.nodes = [-1 for _ in range(n)] self.weight = [0] * n def get_root(self, x): if self.nodes[x] < 0: return x else: y = self.get_root(self.nodes[x]) self.weight[x] += self.weight[self.nodes[x]] self.nodes[x] = y return y def unite(self, x, y, w): w += self.weight[x]-self.weight[y] root_x = self.get_root(x) root_y = self.get_root(y) if root_x != root_y: # 大きい木の方につないだほうが計算量が減る if self.nodes[root_x] > self.nodes[root_y]: root_x, root_y = root_y, root_x w *= -1 self.nodes[root_x] += self.nodes[root_y] self.nodes[root_y] = root_x self.weight[root_y] = w def diff(self, x, y): return self.weight[y] - self.weight[x] def same(self, x, y): return get_root(x) == get_root(y) N, M = MI() uf = WeightedUnionFind(N) get_root, unite, nodes, diff, same = uf.get_root, uf.unite, uf.nodes, uf.diff, uf.same for _ in range(M): l, r, d = MI_() d += 1 if same(l, r) and diff(l, r) != d: print("No") exit() else: unite(l, r, d) print("Yes") if __name__ == '__main__': main()
104
98
2,432
2,280
import sys input = sys.stdin.readline inf = float("inf") mod = 10**9 + 7 def INT_(n): return int(n) - 1 def MI(): return list(map(int, input().split())) def MF(): return list(map(float, input().split())) def MI_(): return list(map(INT_, input().split())) def LI(): return list(MI()) def LI_(): return [int(x) - 1 for x in input().split()] def LF(): return list(MF()) def LIN(n: int): return [eval(input()) for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] def LLIN_(n: int): return [LI_() for _ in range(n)] def LLI(): return [list(map(int, l.split())) for l in eval(input())] def I(): return int(eval(input())) def F(): return float(eval(input())) def ST(): return input().replace("\n", "") def main(): class WeightedUnionFind: def __init__(self, n): self.nodes = [-1 for _ in range(n)] self.weight = [0] * n def get_root(self, x): if self.nodes[x] < 0: return x else: y = self.get_root(self.nodes[x]) self.weight[x] += self.weight[self.nodes[x]] self.nodes[x] = y return y def unite(self, x, y, w): w += self.weight[x] - self.weight[y] root_x = self.get_root(x) root_y = self.get_root(y) if root_x != root_y: # 大きい木の方につないだほうが計算量が減る if self.nodes[root_x] > self.nodes[root_y]: root_x, root_y = root_y, root_x w *= -1 self.nodes[root_x] += self.nodes[root_y] self.nodes[root_y] = root_x self.weight[root_y] = w def diff(self, x, y): return self.weight[y] - self.weight[x] def same(self, x, y): return get_root(x) == get_root(y) N, M = MI() edge = [[] for _ in range(N)] uf = WeightedUnionFind(N) get_root, unite, nodes, diff, same = ( uf.get_root, uf.unite, uf.nodes, uf.diff, uf.same, ) distanse = [0] * N distanse[0] = 0 rev_edge = [[] for _ in range(N)] for _ in range(M): l, r, d = MI_() d += 1 edge[l].append((r, d)) if same(l, r) and diff(l, r) != d: print("No") exit() else: unite(l, r, d) print("Yes") if __name__ == "__main__": main()
import sys input = sys.stdin.readline inf = float("inf") mod = 10**9 + 7 def INT_(n): return int(n) - 1 def MI(): return list(map(int, input().split())) def MF(): return list(map(float, input().split())) def MI_(): return list(map(INT_, input().split())) def LI(): return list(MI()) def LI_(): return [int(x) - 1 for x in input().split()] def LF(): return list(MF()) def LIN(n: int): return [eval(input()) for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] def LLIN_(n: int): return [LI_() for _ in range(n)] def LLI(): return [list(map(int, l.split())) for l in eval(input())] def I(): return int(eval(input())) def F(): return float(eval(input())) def ST(): return input().replace("\n", "") def main(): class WeightedUnionFind: def __init__(self, n): self.nodes = [-1 for _ in range(n)] self.weight = [0] * n def get_root(self, x): if self.nodes[x] < 0: return x else: y = self.get_root(self.nodes[x]) self.weight[x] += self.weight[self.nodes[x]] self.nodes[x] = y return y def unite(self, x, y, w): w += self.weight[x] - self.weight[y] root_x = self.get_root(x) root_y = self.get_root(y) if root_x != root_y: # 大きい木の方につないだほうが計算量が減る if self.nodes[root_x] > self.nodes[root_y]: root_x, root_y = root_y, root_x w *= -1 self.nodes[root_x] += self.nodes[root_y] self.nodes[root_y] = root_x self.weight[root_y] = w def diff(self, x, y): return self.weight[y] - self.weight[x] def same(self, x, y): return get_root(x) == get_root(y) N, M = MI() uf = WeightedUnionFind(N) get_root, unite, nodes, diff, same = ( uf.get_root, uf.unite, uf.nodes, uf.diff, uf.same, ) for _ in range(M): l, r, d = MI_() d += 1 if same(l, r) and diff(l, r) != d: print("No") exit() else: unite(l, r, d) print("Yes") if __name__ == "__main__": main()
false
5.769231
[ "- edge = [[] for _ in range(N)]", "- distanse = [0] * N", "- distanse[0] = 0", "- rev_edge = [[] for _ in range(N)]", "- edge[l].append((r, d))" ]
false
0.056931
0.145104
0.392347
[ "s588146473", "s020217811" ]
u835482198
p03848
python
s628096859
s720439755
90
62
14,812
16,620
Accepted
Accepted
31.11
#!/usr/bin/env python # -*- coding:utf-8 -*- from collections import Counter import sys N = int(eval(input())) A = list(map(int, input().split())) MOD = 10**9 + 7 A = Counter(A) if N % 2 == 1: for num, cnt in list(A.items()): # print(num, cnt) if num == 0: if cnt != 1: print((0)) sys.exit() else: if not (num % 2 == 0 and cnt == 2): print((0)) sys.exit() print(((2 ** (N // 2)) % MOD)) else: for num, cnt in list(A.items()): # print(num, cnt) if not (num % 2 == 1 and cnt == 2): print((0)) sys.exit() print(((2 ** (N // 2)) % MOD))
from collections import Counter N = int(eval(input())) A = list(map(int, input().split())) # N = 5 # A = [2, 4, 4, 0, 2] mod = 10 ** 9 + 7 cnt = Counter(A) if N % 2 == 0: if len(list([c for c in list(cnt.values()) if c != 2])) != 0: print((0)) else: print(((2 ** (N // 2)) % mod)) else: if cnt[0] != 1: print((0)) else: cnt.pop(0) if len(list([c for c in list(cnt.values()) if c != 2])) != 0: print((0)) else: print(((2 ** (N // 2)) % mod))
30
23
705
525
#!/usr/bin/env python # -*- coding:utf-8 -*- from collections import Counter import sys N = int(eval(input())) A = list(map(int, input().split())) MOD = 10**9 + 7 A = Counter(A) if N % 2 == 1: for num, cnt in list(A.items()): # print(num, cnt) if num == 0: if cnt != 1: print((0)) sys.exit() else: if not (num % 2 == 0 and cnt == 2): print((0)) sys.exit() print(((2 ** (N // 2)) % MOD)) else: for num, cnt in list(A.items()): # print(num, cnt) if not (num % 2 == 1 and cnt == 2): print((0)) sys.exit() print(((2 ** (N // 2)) % MOD))
from collections import Counter N = int(eval(input())) A = list(map(int, input().split())) # N = 5 # A = [2, 4, 4, 0, 2] mod = 10**9 + 7 cnt = Counter(A) if N % 2 == 0: if len(list([c for c in list(cnt.values()) if c != 2])) != 0: print((0)) else: print(((2 ** (N // 2)) % mod)) else: if cnt[0] != 1: print((0)) else: cnt.pop(0) if len(list([c for c in list(cnt.values()) if c != 2])) != 0: print((0)) else: print(((2 ** (N // 2)) % mod))
false
23.333333
[ "-#!/usr/bin/env python", "-# -*- coding:utf-8 -*-", "-import sys", "-MOD = 10**9 + 7", "-A = Counter(A)", "-if N % 2 == 1:", "- for num, cnt in list(A.items()):", "- # print(num, cnt)", "- if num == 0:", "- if cnt != 1:", "- print((0))", "- sys.exit()", "+# N = 5", "+# A = [2, 4, 4, 0, 2]", "+mod = 10**9 + 7", "+cnt = Counter(A)", "+if N % 2 == 0:", "+ if len(list([c for c in list(cnt.values()) if c != 2])) != 0:", "+ print((0))", "+ else:", "+ print(((2 ** (N // 2)) % mod))", "+else:", "+ if cnt[0] != 1:", "+ print((0))", "+ else:", "+ cnt.pop(0)", "+ if len(list([c for c in list(cnt.values()) if c != 2])) != 0:", "+ print((0))", "- if not (num % 2 == 0 and cnt == 2):", "- print((0))", "- sys.exit()", "- print(((2 ** (N // 2)) % MOD))", "-else:", "- for num, cnt in list(A.items()):", "- # print(num, cnt)", "- if not (num % 2 == 1 and cnt == 2):", "- print((0))", "- sys.exit()", "- print(((2 ** (N // 2)) % MOD))", "+ print(((2 ** (N // 2)) % mod))" ]
false
0.038233
0.038655
0.989087
[ "s628096859", "s720439755" ]
u644907318
p02846
python
s753595093
s038544850
167
65
38,384
62,100
Accepted
Accepted
61.08
T1,T2 = list(map(int,input().split())) A1,A2 = list(map(int,input().split())) B1,B2 = list(map(int,input().split())) dif = T1*A1+T2*A2-T1*B1-T2*B2 if dif==0: print("infinity") elif dif>0: if B1>A1: k = int(((B1-A1)*T1)/dif) if abs(((B1-A1)*T1)/dif-round(((B1-A1)*T1)/dif))<1e-20: print((2*round(((B1-A1)*T1)/dif))) else: print((2*k+1)) else: print((0)) else: if A1>B1: k = int(((A1-B1)*T1)/abs(dif)) if abs((A1-B1)*T1/abs(dif)-round(((A1-B1)*T1)/abs(dif)))<1e-20: print((2*round(((A1-B1)*T1)/abs(dif)))) else: print((2*k+1)) else: print((0))
T1,T2 = list(map(int,input().split())) A1,A2 = list(map(int,input().split())) B1,B2 = list(map(int,input().split())) if T1*A1+T2*A2==T1*B1+T2*B2: cnt="infinity" elif T1*A1+T2*A2>T1*B1+T2*B2: L = T1*(B1-A1) d = T1*A1+T2*A2-(T1*B1+T2*B2) if L<0: cnt = 0 elif L==0: cnt = 1 else: cnt = 1 n = L//d r = L%d if r>0: cnt += 2*n else: cnt += 2*(n-1)+1 elif T1*A1+T2*A2<T1*B1+T2*B2: L = T1*(A1-B1) d = (T1*B1+T2*B2)-(T1*A1+T2*A2) if L<0: cnt = 0 elif L==0: cnt = 1 else: cnt = 1 n = L//d r = L%d if r>0: cnt += 2*n else: cnt += 2*(n-1)+1 print(cnt)
24
36
666
768
T1, T2 = list(map(int, input().split())) A1, A2 = list(map(int, input().split())) B1, B2 = list(map(int, input().split())) dif = T1 * A1 + T2 * A2 - T1 * B1 - T2 * B2 if dif == 0: print("infinity") elif dif > 0: if B1 > A1: k = int(((B1 - A1) * T1) / dif) if abs(((B1 - A1) * T1) / dif - round(((B1 - A1) * T1) / dif)) < 1e-20: print((2 * round(((B1 - A1) * T1) / dif))) else: print((2 * k + 1)) else: print((0)) else: if A1 > B1: k = int(((A1 - B1) * T1) / abs(dif)) if abs((A1 - B1) * T1 / abs(dif) - round(((A1 - B1) * T1) / abs(dif))) < 1e-20: print((2 * round(((A1 - B1) * T1) / abs(dif)))) else: print((2 * k + 1)) else: print((0))
T1, T2 = list(map(int, input().split())) A1, A2 = list(map(int, input().split())) B1, B2 = list(map(int, input().split())) if T1 * A1 + T2 * A2 == T1 * B1 + T2 * B2: cnt = "infinity" elif T1 * A1 + T2 * A2 > T1 * B1 + T2 * B2: L = T1 * (B1 - A1) d = T1 * A1 + T2 * A2 - (T1 * B1 + T2 * B2) if L < 0: cnt = 0 elif L == 0: cnt = 1 else: cnt = 1 n = L // d r = L % d if r > 0: cnt += 2 * n else: cnt += 2 * (n - 1) + 1 elif T1 * A1 + T2 * A2 < T1 * B1 + T2 * B2: L = T1 * (A1 - B1) d = (T1 * B1 + T2 * B2) - (T1 * A1 + T2 * A2) if L < 0: cnt = 0 elif L == 0: cnt = 1 else: cnt = 1 n = L // d r = L % d if r > 0: cnt += 2 * n else: cnt += 2 * (n - 1) + 1 print(cnt)
false
33.333333
[ "-dif = T1 * A1 + T2 * A2 - T1 * B1 - T2 * B2", "-if dif == 0:", "- print(\"infinity\")", "-elif dif > 0:", "- if B1 > A1:", "- k = int(((B1 - A1) * T1) / dif)", "- if abs(((B1 - A1) * T1) / dif - round(((B1 - A1) * T1) / dif)) < 1e-20:", "- print((2 * round(((B1 - A1) * T1) / dif)))", "+if T1 * A1 + T2 * A2 == T1 * B1 + T2 * B2:", "+ cnt = \"infinity\"", "+elif T1 * A1 + T2 * A2 > T1 * B1 + T2 * B2:", "+ L = T1 * (B1 - A1)", "+ d = T1 * A1 + T2 * A2 - (T1 * B1 + T2 * B2)", "+ if L < 0:", "+ cnt = 0", "+ elif L == 0:", "+ cnt = 1", "+ else:", "+ cnt = 1", "+ n = L // d", "+ r = L % d", "+ if r > 0:", "+ cnt += 2 * n", "- print((2 * k + 1))", "+ cnt += 2 * (n - 1) + 1", "+elif T1 * A1 + T2 * A2 < T1 * B1 + T2 * B2:", "+ L = T1 * (A1 - B1)", "+ d = (T1 * B1 + T2 * B2) - (T1 * A1 + T2 * A2)", "+ if L < 0:", "+ cnt = 0", "+ elif L == 0:", "+ cnt = 1", "- print((0))", "-else:", "- if A1 > B1:", "- k = int(((A1 - B1) * T1) / abs(dif))", "- if abs((A1 - B1) * T1 / abs(dif) - round(((A1 - B1) * T1) / abs(dif))) < 1e-20:", "- print((2 * round(((A1 - B1) * T1) / abs(dif))))", "+ cnt = 1", "+ n = L // d", "+ r = L % d", "+ if r > 0:", "+ cnt += 2 * n", "- print((2 * k + 1))", "- else:", "- print((0))", "+ cnt += 2 * (n - 1) + 1", "+print(cnt)" ]
false
0.058093
0.043549
1.333975
[ "s753595093", "s038544850" ]
u934066963
p02802
python
s215373521
s836397594
241
185
98,212
76,256
Accepted
Accepted
23.24
# input here _INPUT = """\ 2 5 1 WA 1 AC 2 WA 2 AC 2 WA 2 AC """ def main(): n, m= list(map(int, input().split())) ps = [list(map(str,input().split())) for _ in range(m)] str_l = ["WA"]*n int_l = [0]*n num = 0 ac = 0 for pp, s in ps: p = int(pp)-1 if s == "AC": str_l[p] = "AC" else: if str_l[p] != "AC": int_l[p] += 1 for i in range(n): if str_l[i] == "AC": num += int_l[i] ac += 1 print((ac,num)) # n, m = map(int, input().split()) # seikai = [False] * n # matigai = [0] * n # for i in range(m): # p,q = map(str, input().split()) # p = int(p)-1 # if q == "AC": # seikai[p] = True # else: # if seikai[p] != True: # matigai[p] += 1 # correct = seikai.count(True) # mistake = sum(matigai) # print(correct, mistake) if __name__ == '__main__': import io import sys import math import itertools from collections import deque # sys.stdin = io.StringIO(_INPUT) main()
# input here _INPUT = """\ 2 5 1 WA 1 AC 2 WA 2 AC 2 WA 2 AC """ def main(): n, m = list(map(int, input().split())) seikai = [False] * n matigai = [0] * n for i in range(m): p,q = list(map(str, input().split())) p = int(p)-1 if q == "AC": seikai[p] = True else: if seikai[p] != True: matigai[p] += 1 num = 0 ac = 0 for i in range(n): if seikai[i] == True: num += matigai[i] ac += 1 print((ac,num)) if __name__ == '__main__': import io import sys import math import itertools from collections import deque # sys.stdin = io.StringIO(_INPUT) main()
63
44
1,199
757
# input here _INPUT = """\ 2 5 1 WA 1 AC 2 WA 2 AC 2 WA 2 AC """ def main(): n, m = list(map(int, input().split())) ps = [list(map(str, input().split())) for _ in range(m)] str_l = ["WA"] * n int_l = [0] * n num = 0 ac = 0 for pp, s in ps: p = int(pp) - 1 if s == "AC": str_l[p] = "AC" else: if str_l[p] != "AC": int_l[p] += 1 for i in range(n): if str_l[i] == "AC": num += int_l[i] ac += 1 print((ac, num)) # n, m = map(int, input().split()) # seikai = [False] * n # matigai = [0] * n # for i in range(m): # p,q = map(str, input().split()) # p = int(p)-1 # if q == "AC": # seikai[p] = True # else: # if seikai[p] != True: # matigai[p] += 1 # correct = seikai.count(True) # mistake = sum(matigai) # print(correct, mistake) if __name__ == "__main__": import io import sys import math import itertools from collections import deque # sys.stdin = io.StringIO(_INPUT) main()
# input here _INPUT = """\ 2 5 1 WA 1 AC 2 WA 2 AC 2 WA 2 AC """ def main(): n, m = list(map(int, input().split())) seikai = [False] * n matigai = [0] * n for i in range(m): p, q = list(map(str, input().split())) p = int(p) - 1 if q == "AC": seikai[p] = True else: if seikai[p] != True: matigai[p] += 1 num = 0 ac = 0 for i in range(n): if seikai[i] == True: num += matigai[i] ac += 1 print((ac, num)) if __name__ == "__main__": import io import sys import math import itertools from collections import deque # sys.stdin = io.StringIO(_INPUT) main()
false
30.15873
[ "- ps = [list(map(str, input().split())) for _ in range(m)]", "- str_l = [\"WA\"] * n", "- int_l = [0] * n", "+ seikai = [False] * n", "+ matigai = [0] * n", "+ for i in range(m):", "+ p, q = list(map(str, input().split()))", "+ p = int(p) - 1", "+ if q == \"AC\":", "+ seikai[p] = True", "+ else:", "+ if seikai[p] != True:", "+ matigai[p] += 1", "- for pp, s in ps:", "- p = int(pp) - 1", "- if s == \"AC\":", "- str_l[p] = \"AC\"", "- else:", "- if str_l[p] != \"AC\":", "- int_l[p] += 1", "- if str_l[i] == \"AC\":", "- num += int_l[i]", "+ if seikai[i] == True:", "+ num += matigai[i]", "- # n, m = map(int, input().split())", "- # seikai = [False] * n", "- # matigai = [0] * n", "- # for i in range(m):", "- # p,q = map(str, input().split())", "- # p = int(p)-1", "- # if q == \"AC\":", "- # seikai[p] = True", "- # else:", "- # if seikai[p] != True:", "- # matigai[p] += 1", "- # correct = seikai.count(True)", "- # mistake = sum(matigai)", "- # print(correct, mistake)" ]
false
0.045624
0.041156
1.108563
[ "s215373521", "s836397594" ]
u816872429
p03108
python
s109224899
s535581040
867
636
55,476
46,968
Accepted
Accepted
26.64
n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(m)] group = [i for i in range(n)] islands = {i: [i] for i in range(n)} ret = [0] * m + [n * (n - 1) // 2] for i in range(m - 1, -1, -1): a, b = ab[i] ga, gb = group[a - 1], group[b - 1] if ga == gb: ret[i] = ret[i + 1] else: la, lb = len(islands[ga]), len(islands[gb]) ret[i] = ret[i + 1] - la * lb if la > lb: for j in islands[gb]: group[j] = ga islands[ga].append(j) else: for j in islands[ga]: group[j] = gb islands[gb].append(j) for i in range(1, m + 1): print((ret[i]))
import sys sys.setrecursionlimit(100000) n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(m)] parent = [i for i in range(n)] count = [1 for i in range(n)] def root(i): if i == parent[i]: return i parent[i] = root(parent[i]) return parent[i] def merge(i, j): parent[j] = i count[i] += count[j] ret = [0] * m + [n * (n - 1) // 2] for i in range(m - 1, -1, -1): a, b = ab[i] ra, rb = root(a - 1), root(b - 1) if ra == rb: ret[i] = ret[i + 1] else: ret[i] = ret[i + 1] - count[ra] * count[rb] merge(ra, rb) for i in range(1, m + 1): print((ret[i]))
23
30
728
685
n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(m)] group = [i for i in range(n)] islands = {i: [i] for i in range(n)} ret = [0] * m + [n * (n - 1) // 2] for i in range(m - 1, -1, -1): a, b = ab[i] ga, gb = group[a - 1], group[b - 1] if ga == gb: ret[i] = ret[i + 1] else: la, lb = len(islands[ga]), len(islands[gb]) ret[i] = ret[i + 1] - la * lb if la > lb: for j in islands[gb]: group[j] = ga islands[ga].append(j) else: for j in islands[ga]: group[j] = gb islands[gb].append(j) for i in range(1, m + 1): print((ret[i]))
import sys sys.setrecursionlimit(100000) n, m = list(map(int, input().split())) ab = [list(map(int, input().split())) for _ in range(m)] parent = [i for i in range(n)] count = [1 for i in range(n)] def root(i): if i == parent[i]: return i parent[i] = root(parent[i]) return parent[i] def merge(i, j): parent[j] = i count[i] += count[j] ret = [0] * m + [n * (n - 1) // 2] for i in range(m - 1, -1, -1): a, b = ab[i] ra, rb = root(a - 1), root(b - 1) if ra == rb: ret[i] = ret[i + 1] else: ret[i] = ret[i + 1] - count[ra] * count[rb] merge(ra, rb) for i in range(1, m + 1): print((ret[i]))
false
23.333333
[ "+import sys", "+", "+sys.setrecursionlimit(100000)", "-group = [i for i in range(n)]", "-islands = {i: [i] for i in range(n)}", "+parent = [i for i in range(n)]", "+count = [1 for i in range(n)]", "+", "+", "+def root(i):", "+ if i == parent[i]:", "+ return i", "+ parent[i] = root(parent[i])", "+ return parent[i]", "+", "+", "+def merge(i, j):", "+ parent[j] = i", "+ count[i] += count[j]", "+", "+", "- ga, gb = group[a - 1], group[b - 1]", "- if ga == gb:", "+ ra, rb = root(a - 1), root(b - 1)", "+ if ra == rb:", "- la, lb = len(islands[ga]), len(islands[gb])", "- ret[i] = ret[i + 1] - la * lb", "- if la > lb:", "- for j in islands[gb]:", "- group[j] = ga", "- islands[ga].append(j)", "- else:", "- for j in islands[ga]:", "- group[j] = gb", "- islands[gb].append(j)", "+ ret[i] = ret[i + 1] - count[ra] * count[rb]", "+ merge(ra, rb)" ]
false
0.037129
0.037543
0.988973
[ "s109224899", "s535581040" ]
u427344224
p03253
python
s972365749
s517709277
1,954
780
114,396
66,012
Accepted
Accepted
60.08
def prime_factorize(num): """ This function performs prime factorization on the input natural number. The result is returned in the form of a dictionary with the prime number as the key and its number as the value. :param num: :return prime_factor: Dictionary with the prime number as the key and its number as the value. """ prime_factor = {} i = 2 while i ** 2 <= num: while num % i == 0: num //= i if i in list(prime_factor.keys()): prime_factor[i] += 1 else: prime_factor[i] = 1 i += 1 if num > 1: prime_factor[num] = 1 return prime_factor from math import factorial def comb(n, r): return factorial(n) // (factorial(n-r) * factorial(r)) n, m = list(map(int, input().split())) r = 1 prime_fac = prime_factorize(m) for v in list(prime_fac.values()): r *= comb(v+n-1, v) mod = 1000000000 + 7 print((r % mod))
def prime_factorize(num): """ This function performs prime factorization on the input natural number. The result is returned in the form of a dictionary with the prime number as the key and its number as the value. :param num: :return prime_factor: Dictionary with the prime number as the key and its number as the value. """ prime_factor = {} i = 2 while i ** 2 <= num: while num % i == 0: num //= i if i in list(prime_factor.keys()): prime_factor[i] += 1 else: prime_factor[i] = 1 i += 1 if num > 1: prime_factor[num] = 1 return prime_factor from math import factorial def comb(n, r, R): if n not in R: a = factorial(n) R[n] = a else: a = R[n] if n - r not in R: b = factorial(n - r) R[n - r] = b else: b = R[n - r] if r not in R: c = factorial(r) R[r] = c else: c = R[r] return a // (b * c) n, m = list(map(int, input().split())) r = 1 R = dict() prime_fac = prime_factorize(m) for v in list(prime_fac.values()): r *= comb(v + n - 1, v, R) mod = 1000000000 + 7 print((r % mod))
37
56
981
1,269
def prime_factorize(num): """ This function performs prime factorization on the input natural number. The result is returned in the form of a dictionary with the prime number as the key and its number as the value. :param num: :return prime_factor: Dictionary with the prime number as the key and its number as the value. """ prime_factor = {} i = 2 while i**2 <= num: while num % i == 0: num //= i if i in list(prime_factor.keys()): prime_factor[i] += 1 else: prime_factor[i] = 1 i += 1 if num > 1: prime_factor[num] = 1 return prime_factor from math import factorial def comb(n, r): return factorial(n) // (factorial(n - r) * factorial(r)) n, m = list(map(int, input().split())) r = 1 prime_fac = prime_factorize(m) for v in list(prime_fac.values()): r *= comb(v + n - 1, v) mod = 1000000000 + 7 print((r % mod))
def prime_factorize(num): """ This function performs prime factorization on the input natural number. The result is returned in the form of a dictionary with the prime number as the key and its number as the value. :param num: :return prime_factor: Dictionary with the prime number as the key and its number as the value. """ prime_factor = {} i = 2 while i**2 <= num: while num % i == 0: num //= i if i in list(prime_factor.keys()): prime_factor[i] += 1 else: prime_factor[i] = 1 i += 1 if num > 1: prime_factor[num] = 1 return prime_factor from math import factorial def comb(n, r, R): if n not in R: a = factorial(n) R[n] = a else: a = R[n] if n - r not in R: b = factorial(n - r) R[n - r] = b else: b = R[n - r] if r not in R: c = factorial(r) R[r] = c else: c = R[r] return a // (b * c) n, m = list(map(int, input().split())) r = 1 R = dict() prime_fac = prime_factorize(m) for v in list(prime_fac.values()): r *= comb(v + n - 1, v, R) mod = 1000000000 + 7 print((r % mod))
false
33.928571
[ "-def comb(n, r):", "- return factorial(n) // (factorial(n - r) * factorial(r))", "+def comb(n, r, R):", "+ if n not in R:", "+ a = factorial(n)", "+ R[n] = a", "+ else:", "+ a = R[n]", "+ if n - r not in R:", "+ b = factorial(n - r)", "+ R[n - r] = b", "+ else:", "+ b = R[n - r]", "+ if r not in R:", "+ c = factorial(r)", "+ R[r] = c", "+ else:", "+ c = R[r]", "+ return a // (b * c)", "+R = dict()", "- r *= comb(v + n - 1, v)", "+ r *= comb(v + n - 1, v, R)" ]
false
0.200508
0.163878
1.223519
[ "s972365749", "s517709277" ]
u600402037
p02695
python
s391957682
s032154965
195
151
76,284
73,408
Accepted
Accepted
22.56
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M, Q = lr() ABCD = [lr() for _ in range(Q)] A = [1] * N ABCD.sort(key=lambda x: x[3], reverse=True) ABCD.sort(key=lambda x: x[0]) answer = 0 for a in [1]: for b in range(a, M+1): for c in range(b, M+1): for d in range(c, M+1): for e in range(d, M+1): for f in range(e, M+1): for g in range(f, M+1): for h in range(g, M+1): for i in range(h, M+1): for j in range(i, M+1): temp = 0 x = [a,b,c,d,e,f,g,h,i,j] for k, l, m, n in ABCD: if x[l-1] - x[k-1] == m: temp += n if temp > answer: answer = temp print(answer)
# coding: utf-8 import sys from itertools import combinations_with_replacement sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M, Q = lr() ABCD = [lr() for _ in range(Q)] answer = 0 for x in combinations_with_replacement(list(range(1, M+1)), N): temp = 0 for a, b, c, d in ABCD: if x[b-1] - x[a-1] == c: temp += d if temp > answer: answer = temp print(answer) #05
32
21
1,159
483
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M, Q = lr() ABCD = [lr() for _ in range(Q)] A = [1] * N ABCD.sort(key=lambda x: x[3], reverse=True) ABCD.sort(key=lambda x: x[0]) answer = 0 for a in [1]: for b in range(a, M + 1): for c in range(b, M + 1): for d in range(c, M + 1): for e in range(d, M + 1): for f in range(e, M + 1): for g in range(f, M + 1): for h in range(g, M + 1): for i in range(h, M + 1): for j in range(i, M + 1): temp = 0 x = [a, b, c, d, e, f, g, h, i, j] for k, l, m, n in ABCD: if x[l - 1] - x[k - 1] == m: temp += n if temp > answer: answer = temp print(answer)
# coding: utf-8 import sys from itertools import combinations_with_replacement sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M, Q = lr() ABCD = [lr() for _ in range(Q)] answer = 0 for x in combinations_with_replacement(list(range(1, M + 1)), N): temp = 0 for a, b, c, d in ABCD: if x[b - 1] - x[a - 1] == c: temp += d if temp > answer: answer = temp print(answer) # 05
false
34.375
[ "+from itertools import combinations_with_replacement", "-A = [1] * N", "-ABCD.sort(key=lambda x: x[3], reverse=True)", "-ABCD.sort(key=lambda x: x[0])", "-for a in [1]:", "- for b in range(a, M + 1):", "- for c in range(b, M + 1):", "- for d in range(c, M + 1):", "- for e in range(d, M + 1):", "- for f in range(e, M + 1):", "- for g in range(f, M + 1):", "- for h in range(g, M + 1):", "- for i in range(h, M + 1):", "- for j in range(i, M + 1):", "- temp = 0", "- x = [a, b, c, d, e, f, g, h, i, j]", "- for k, l, m, n in ABCD:", "- if x[l - 1] - x[k - 1] == m:", "- temp += n", "- if temp > answer:", "- answer = temp", "+for x in combinations_with_replacement(list(range(1, M + 1)), N):", "+ temp = 0", "+ for a, b, c, d in ABCD:", "+ if x[b - 1] - x[a - 1] == c:", "+ temp += d", "+ if temp > answer:", "+ answer = temp", "+# 05" ]
false
0.064485
0.059629
1.081437
[ "s391957682", "s032154965" ]
u065099501
p03599
python
s454012892
s853105600
83
76
18,004
18,392
Accepted
Accepted
8.43
A,B,C,D,E,F = list(map(int, input().split())) x = sorted(set([w for i in range(0,F+1,A*100) for j in range(0,F+1,B*100) if (w := i + j) < F]))[1::] y = sorted(set([s for i in range(0,F+1,C) for j in range(0,F+1,D) if (s := i + j) < F])) n = 0 WS = S = 0 for w in x: for s in y: if w + s > F: break if w * E//100 >= s: m = s / (w + s) if m >= n: n = m WS, S = w + s , s print((WS,S))
A,B,C,D,E,F = list(map(int, input().split())) x = [] for i in range(0,F+1,A*100): for j in range(0,F+1,B*100): water = i + j if water > F: break x.append(water) y = [] for i in range(0,F+1,C): for j in range(0,F+1,D): sugar = i + j if sugar > F: break y.append(sugar) x = sorted(set(x))[1::] y = sorted(set(y)) n = 0 WS = S = 0 for w in x: for s in y: if w + s > F: break if w * E//100 >= s: m = 100 * s / (w + s) if m >= n: n = m WS, S = w + s , s print((WS,S))
18
34
482
660
A, B, C, D, E, F = list(map(int, input().split())) x = sorted( set( [ w for i in range(0, F + 1, A * 100) for j in range(0, F + 1, B * 100) if (w := i + j) < F ] ) )[1::] y = sorted( set([s for i in range(0, F + 1, C) for j in range(0, F + 1, D) if (s := i + j) < F]) ) n = 0 WS = S = 0 for w in x: for s in y: if w + s > F: break if w * E // 100 >= s: m = s / (w + s) if m >= n: n = m WS, S = w + s, s print((WS, S))
A, B, C, D, E, F = list(map(int, input().split())) x = [] for i in range(0, F + 1, A * 100): for j in range(0, F + 1, B * 100): water = i + j if water > F: break x.append(water) y = [] for i in range(0, F + 1, C): for j in range(0, F + 1, D): sugar = i + j if sugar > F: break y.append(sugar) x = sorted(set(x))[1::] y = sorted(set(y)) n = 0 WS = S = 0 for w in x: for s in y: if w + s > F: break if w * E // 100 >= s: m = 100 * s / (w + s) if m >= n: n = m WS, S = w + s, s print((WS, S))
false
47.058824
[ "-x = sorted(", "- set(", "- [", "- w", "- for i in range(0, F + 1, A * 100)", "- for j in range(0, F + 1, B * 100)", "- if (w := i + j) < F", "- ]", "- )", "-)[1::]", "-y = sorted(", "- set([s for i in range(0, F + 1, C) for j in range(0, F + 1, D) if (s := i + j) < F])", "-)", "+x = []", "+for i in range(0, F + 1, A * 100):", "+ for j in range(0, F + 1, B * 100):", "+ water = i + j", "+ if water > F:", "+ break", "+ x.append(water)", "+y = []", "+for i in range(0, F + 1, C):", "+ for j in range(0, F + 1, D):", "+ sugar = i + j", "+ if sugar > F:", "+ break", "+ y.append(sugar)", "+x = sorted(set(x))[1::]", "+y = sorted(set(y))", "- m = s / (w + s)", "+ m = 100 * s / (w + s)" ]
false
0.049349
0.055787
0.884592
[ "s454012892", "s853105600" ]
u875291233
p02949
python
s793970913
s912237677
1,556
850
49,244
47,068
Accepted
Accepted
45.37
# coding: utf-8 # Your code here! def Bellman_Ford(g,start): n = len(g) dist = [float("inf")]*n dist[start] = 0 a0 = float("inf") negative = [False]*n for i in range((2*n)): updated = False for v in range(n): for to, cost in g[v]: if negative[v]: negative[to] = True if dist[to] <= dist[v] + cost: continue dist[to] = dist[v] + cost updated = True if i >= n: negative[to] = True if not updated: break if negative[-1]: return None, False return dist, True import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline #文字列入力のときは注意 n,m,p = [int(i) for i in readline().split()] g = [[] for _ in range(n)] for i in range(m): a,b,c = [int(i) for i in readline().split()] g[a-1].append((b-1,-c+p)) # g[b-1].append((a-1,c)) dist, TF = Bellman_Ford(g, 0) if TF: print((max(-dist[-1],0))) else: print((-1))
""" Bellman-Ford 始点と終点が決められているとき、 経由する閉路のみを確認する必要がある。 """ def Bellman_Ford2(g,start,goal): n = len(g) dist = [float("inf")]*n dist[start] = 0 a0 = float("inf") for i in range(2*n): updated = False for v in range(n): for to, cost in g[v]: if dist[to] <= dist[v] + cost: continue if i < n: dist[to] = dist[v] + cost else: dist[to] = -float("inf") updated = True if not updated: break if dist[goal] == -float("inf"): return None, False # if negative[-1]: return None, False return dist, True import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline #文字列入力のときは注意 n,m,p = [int(i) for i in readline().split()] g = [[] for _ in range(n)] for i in range(m): a,b,c = [int(i) for i in readline().split()] g[a-1].append((b-1,-c+p)) # g[b-1].append((a-1,c)) dist, TF = Bellman_Ford2(g,0,-1) if TF: print((max(-dist[-1],0))) else: print((-1))
41
41
1,034
1,070
# coding: utf-8 # Your code here! def Bellman_Ford(g, start): n = len(g) dist = [float("inf")] * n dist[start] = 0 a0 = float("inf") negative = [False] * n for i in range((2 * n)): updated = False for v in range(n): for to, cost in g[v]: if negative[v]: negative[to] = True if dist[to] <= dist[v] + cost: continue dist[to] = dist[v] + cost updated = True if i >= n: negative[to] = True if not updated: break if negative[-1]: return None, False return dist, True import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline # 文字列入力のときは注意 n, m, p = [int(i) for i in readline().split()] g = [[] for _ in range(n)] for i in range(m): a, b, c = [int(i) for i in readline().split()] g[a - 1].append((b - 1, -c + p)) # g[b-1].append((a-1,c)) dist, TF = Bellman_Ford(g, 0) if TF: print((max(-dist[-1], 0))) else: print((-1))
""" Bellman-Ford 始点と終点が決められているとき、 経由する閉路のみを確認する必要がある。 """ def Bellman_Ford2(g, start, goal): n = len(g) dist = [float("inf")] * n dist[start] = 0 a0 = float("inf") for i in range(2 * n): updated = False for v in range(n): for to, cost in g[v]: if dist[to] <= dist[v] + cost: continue if i < n: dist[to] = dist[v] + cost else: dist[to] = -float("inf") updated = True if not updated: break if dist[goal] == -float("inf"): return None, False # if negative[-1]: return None, False return dist, True import sys sys.setrecursionlimit(10**6) readline = sys.stdin.readline # 文字列入力のときは注意 n, m, p = [int(i) for i in readline().split()] g = [[] for _ in range(n)] for i in range(m): a, b, c = [int(i) for i in readline().split()] g[a - 1].append((b - 1, -c + p)) # g[b-1].append((a-1,c)) dist, TF = Bellman_Ford2(g, 0, -1) if TF: print((max(-dist[-1], 0))) else: print((-1))
false
0
[ "-# coding: utf-8", "-# Your code here!", "-def Bellman_Ford(g, start):", "+\"\"\"", "+Bellman-Ford", "+始点と終点が決められているとき、", "+経由する閉路のみを確認する必要がある。", "+\"\"\"", "+", "+", "+def Bellman_Ford2(g, start, goal):", "- negative = [False] * n", "- for i in range((2 * n)):", "+ for i in range(2 * n):", "- if negative[v]:", "- negative[to] = True", "- dist[to] = dist[v] + cost", "+ if i < n:", "+ dist[to] = dist[v] + cost", "+ else:", "+ dist[to] = -float(\"inf\")", "- if i >= n:", "- negative[to] = True", "- if negative[-1]:", "+ if dist[goal] == -float(\"inf\"):", "+ # if negative[-1]: return None, False", "-dist, TF = Bellman_Ford(g, 0)", "+dist, TF = Bellman_Ford2(g, 0, -1)" ]
false
0.034485
0.040997
0.841166
[ "s793970913", "s912237677" ]
u561231954
p02698
python
s745014483
s134549212
1,699
1,118
552,304
284,008
Accepted
Accepted
34.2
import sys sys.setrecursionlimit(100000000) input = sys.stdin.readline class SegmentTree(): f = max unit = 0 def __init__(self,array): self.N = len(array) self.tree = [self.unit] * (2*self.N) #self._build(array) def _build(self,array): for i,x in enumerate(array,self.N): self.tree[i] = x for i in range(self.N - 1,0,-1): self.tree[i] = self.f(self.tree[i << 1],self.tree[i << 1|1]) def update(self,k,x): k += self.N self.tree[k] = x while k > 1: k >>= 1 self.tree[k] = self.f(self.tree[k << 1],self.tree[k << 1|1]) def query(self,l,r): l += self.N r += self.N vl = self.unit vr = self.unit while l < r: if l&1: vl = self.f(vl,self.tree[l]) l += 1 if r&1: r -= 1 vr = self.f(self.tree[r],vr) l >>= 1 r >>= 1 return self.f(vl,vr) def __str__(self): return '\n'.join(' '.join(str(v) for v in self.tree[1<<i:1<<(i + 1)]) for i in range((2*self.N).bit_length())) N = int(eval(input())) A = list(map(int,input().split())) G = [[] for _ in range(N)] for _ in range(N - 1): a,b = list(map(int,input().split())) a -= 1 b -= 1 G[a].append(b) G[b].append(a) B = sorted(list(set(A))) M = len(B) toID = {i:j for i,j in zip(B,list(range(1,M + 1)))} dp = SegmentTree([0] * (M + 1)) ans = [0] * N before = [0] * N def dfs(v,p = -1): idx = toID[A[v]] a = dp.query(0,idx) + 1 before[v] = dp.query(idx,idx + 1) flag = False if before[v] < a: flag = True dp.update(idx,a) before_max = dp.query(0,M + 1) ans[v] = max(before_max,a) for e in G[v]: if e == p: continue dfs(e,v) if flag: dp.update(idx,before[v]) dfs(0) print(('\n'.join(map(str,ans))))
import sys sys.setrecursionlimit(100000000) from bisect import bisect_left input = sys.stdin.readline INF = 1 << 30 MAXN = 200005 G = [[] for _ in range(MAXN)] dp = [INF] * MAXN stack = [] ans = [None] * MAXN def dfs(v,A,p = -1): idx = bisect_left(dp,A[v]) stack.append((idx,dp[idx])) dp[idx] = A[v] ans[v] = bisect_left(dp,INF) for e in G[v]: if e == p: continue dfs(e,A,v) idx,p = stack.pop() dp[idx] = p def main(): N = int(eval(input())) A = list(map(int,input().split())) for _ in range(N - 1): a,b = list(map(int,input().split())) a -= 1 b -= 1 G[a].append(b) G[b].append(a) dfs(0,A) print(('\n'.join(map(str,ans[:N])))) if __name__ == '__main__': main()
81
40
2,035
825
import sys sys.setrecursionlimit(100000000) input = sys.stdin.readline class SegmentTree: f = max unit = 0 def __init__(self, array): self.N = len(array) self.tree = [self.unit] * (2 * self.N) # self._build(array) def _build(self, array): for i, x in enumerate(array, self.N): self.tree[i] = x for i in range(self.N - 1, 0, -1): self.tree[i] = self.f(self.tree[i << 1], self.tree[i << 1 | 1]) def update(self, k, x): k += self.N self.tree[k] = x while k > 1: k >>= 1 self.tree[k] = self.f(self.tree[k << 1], self.tree[k << 1 | 1]) def query(self, l, r): l += self.N r += self.N vl = self.unit vr = self.unit while l < r: if l & 1: vl = self.f(vl, self.tree[l]) l += 1 if r & 1: r -= 1 vr = self.f(self.tree[r], vr) l >>= 1 r >>= 1 return self.f(vl, vr) def __str__(self): return "\n".join( " ".join(str(v) for v in self.tree[1 << i : 1 << (i + 1)]) for i in range((2 * self.N).bit_length()) ) N = int(eval(input())) A = list(map(int, input().split())) G = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 G[a].append(b) G[b].append(a) B = sorted(list(set(A))) M = len(B) toID = {i: j for i, j in zip(B, list(range(1, M + 1)))} dp = SegmentTree([0] * (M + 1)) ans = [0] * N before = [0] * N def dfs(v, p=-1): idx = toID[A[v]] a = dp.query(0, idx) + 1 before[v] = dp.query(idx, idx + 1) flag = False if before[v] < a: flag = True dp.update(idx, a) before_max = dp.query(0, M + 1) ans[v] = max(before_max, a) for e in G[v]: if e == p: continue dfs(e, v) if flag: dp.update(idx, before[v]) dfs(0) print(("\n".join(map(str, ans))))
import sys sys.setrecursionlimit(100000000) from bisect import bisect_left input = sys.stdin.readline INF = 1 << 30 MAXN = 200005 G = [[] for _ in range(MAXN)] dp = [INF] * MAXN stack = [] ans = [None] * MAXN def dfs(v, A, p=-1): idx = bisect_left(dp, A[v]) stack.append((idx, dp[idx])) dp[idx] = A[v] ans[v] = bisect_left(dp, INF) for e in G[v]: if e == p: continue dfs(e, A, v) idx, p = stack.pop() dp[idx] = p def main(): N = int(eval(input())) A = list(map(int, input().split())) for _ in range(N - 1): a, b = list(map(int, input().split())) a -= 1 b -= 1 G[a].append(b) G[b].append(a) dfs(0, A) print(("\n".join(map(str, ans[:N])))) if __name__ == "__main__": main()
false
50.617284
[ "+from bisect import bisect_left", "+", "+INF = 1 << 30", "+MAXN = 200005", "+G = [[] for _ in range(MAXN)]", "+dp = [INF] * MAXN", "+stack = []", "+ans = [None] * MAXN", "-class SegmentTree:", "- f = max", "- unit = 0", "-", "- def __init__(self, array):", "- self.N = len(array)", "- self.tree = [self.unit] * (2 * self.N)", "- # self._build(array)", "-", "- def _build(self, array):", "- for i, x in enumerate(array, self.N):", "- self.tree[i] = x", "- for i in range(self.N - 1, 0, -1):", "- self.tree[i] = self.f(self.tree[i << 1], self.tree[i << 1 | 1])", "-", "- def update(self, k, x):", "- k += self.N", "- self.tree[k] = x", "- while k > 1:", "- k >>= 1", "- self.tree[k] = self.f(self.tree[k << 1], self.tree[k << 1 | 1])", "-", "- def query(self, l, r):", "- l += self.N", "- r += self.N", "- vl = self.unit", "- vr = self.unit", "- while l < r:", "- if l & 1:", "- vl = self.f(vl, self.tree[l])", "- l += 1", "- if r & 1:", "- r -= 1", "- vr = self.f(self.tree[r], vr)", "- l >>= 1", "- r >>= 1", "- return self.f(vl, vr)", "-", "- def __str__(self):", "- return \"\\n\".join(", "- \" \".join(str(v) for v in self.tree[1 << i : 1 << (i + 1)])", "- for i in range((2 * self.N).bit_length())", "- )", "-", "-", "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-G = [[] for _ in range(N)]", "-for _ in range(N - 1):", "- a, b = list(map(int, input().split()))", "- a -= 1", "- b -= 1", "- G[a].append(b)", "- G[b].append(a)", "-B = sorted(list(set(A)))", "-M = len(B)", "-toID = {i: j for i, j in zip(B, list(range(1, M + 1)))}", "-dp = SegmentTree([0] * (M + 1))", "-ans = [0] * N", "-before = [0] * N", "-", "-", "-def dfs(v, p=-1):", "- idx = toID[A[v]]", "- a = dp.query(0, idx) + 1", "- before[v] = dp.query(idx, idx + 1)", "- flag = False", "- if before[v] < a:", "- flag = True", "- dp.update(idx, a)", "- before_max = dp.query(0, M + 1)", "- ans[v] = max(before_max, a)", "+def dfs(v, A, p=-1):", "+ idx = bisect_left(dp, A[v])", "+ stack.append((idx, dp[idx]))", "+ dp[idx] = A[v]", "+ ans[v] = bisect_left(dp, INF)", "- dfs(e, v)", "- if flag:", "- dp.update(idx, before[v])", "+ dfs(e, A, v)", "+ idx, p = stack.pop()", "+ dp[idx] = p", "-dfs(0)", "-print((\"\\n\".join(map(str, ans))))", "+def main():", "+ N = int(eval(input()))", "+ A = list(map(int, input().split()))", "+ for _ in range(N - 1):", "+ a, b = list(map(int, input().split()))", "+ a -= 1", "+ b -= 1", "+ G[a].append(b)", "+ G[b].append(a)", "+ dfs(0, A)", "+ print((\"\\n\".join(map(str, ans[:N]))))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.046928
0.198412
0.236519
[ "s745014483", "s134549212" ]
u222668979
p03163
python
s731310451
s394749793
1,380
978
382,080
307,352
Accepted
Accepted
29.13
import sys input = sys.stdin.readline n, w = list(map(int, input().split())) item = [list(map(int, input().split())) for _ in range(n)] dp = [[0] + [0]*w] + [[0] + [-float("inf")]*w for _ in range(n)] wei, val = 0, 1 for i in range(n): for j in range(w+1): if item[i][wei] <= j: dp[i+1][j] = max(dp[i][j], dp[i][j-item[i][wei]] + item[i][val]) else: dp[i+1][j] = dp[i][j] print((dp[n][w]))
import sys input = sys.stdin.readline n, w = list(map(int, input().split())) item = [list(map(int, input().split())) for _ in range(n)] dp = [[0] + [0]*w] + [[-float("inf")]*(w+1) for _ in range(n)] wei, val = 0, 1 for i in range(n): for j in range(w+1): if item[i][wei] <= j: dp[i+1][j] = max(dp[i][j], dp[i][j-item[i][wei]] + item[i][val]) else: dp[i+1][j] = dp[i][j] print((dp[n][w]))
16
16
444
442
import sys input = sys.stdin.readline n, w = list(map(int, input().split())) item = [list(map(int, input().split())) for _ in range(n)] dp = [[0] + [0] * w] + [[0] + [-float("inf")] * w for _ in range(n)] wei, val = 0, 1 for i in range(n): for j in range(w + 1): if item[i][wei] <= j: dp[i + 1][j] = max(dp[i][j], dp[i][j - item[i][wei]] + item[i][val]) else: dp[i + 1][j] = dp[i][j] print((dp[n][w]))
import sys input = sys.stdin.readline n, w = list(map(int, input().split())) item = [list(map(int, input().split())) for _ in range(n)] dp = [[0] + [0] * w] + [[-float("inf")] * (w + 1) for _ in range(n)] wei, val = 0, 1 for i in range(n): for j in range(w + 1): if item[i][wei] <= j: dp[i + 1][j] = max(dp[i][j], dp[i][j - item[i][wei]] + item[i][val]) else: dp[i + 1][j] = dp[i][j] print((dp[n][w]))
false
0
[ "-dp = [[0] + [0] * w] + [[0] + [-float(\"inf\")] * w for _ in range(n)]", "+dp = [[0] + [0] * w] + [[-float(\"inf\")] * (w + 1) for _ in range(n)]" ]
false
0.042136
0.043052
0.978727
[ "s731310451", "s394749793" ]
u188827677
p02695
python
s271708158
s430438458
1,115
914
9,060
9,164
Accepted
Accepted
18.03
from itertools import combinations_with_replacement n,m,q = list(map(int, input().split())) abcd = [list(map(int, input().split())) for _ in range(q)] nums = combinations_with_replacement(list(range(1,m+1)), n) ans = 0 for a in nums: t = 0 for i in abcd: if a[i[1]-1] - a[i[0]-1] == i[2]: t += i[3] if ans < t: ans = t print(ans)
from itertools import combinations_with_replacement n,m,q = list(map(int, input().split())) abcd = [list(map(int, input().split())) for _ in range(q)] ans = 0 for a in combinations_with_replacement(list(range(1,m+1)), n): t = 0 for i in abcd: if a[i[1]-1] - a[i[0]-1] == i[2]: t += i[3] if ans < t: ans = t print(ans)
12
11
339
326
from itertools import combinations_with_replacement n, m, q = list(map(int, input().split())) abcd = [list(map(int, input().split())) for _ in range(q)] nums = combinations_with_replacement(list(range(1, m + 1)), n) ans = 0 for a in nums: t = 0 for i in abcd: if a[i[1] - 1] - a[i[0] - 1] == i[2]: t += i[3] if ans < t: ans = t print(ans)
from itertools import combinations_with_replacement n, m, q = list(map(int, input().split())) abcd = [list(map(int, input().split())) for _ in range(q)] ans = 0 for a in combinations_with_replacement(list(range(1, m + 1)), n): t = 0 for i in abcd: if a[i[1] - 1] - a[i[0] - 1] == i[2]: t += i[3] if ans < t: ans = t print(ans)
false
8.333333
[ "-nums = combinations_with_replacement(list(range(1, m + 1)), n)", "-for a in nums:", "+for a in combinations_with_replacement(list(range(1, m + 1)), n):" ]
false
0.040533
0.061589
0.658122
[ "s271708158", "s430438458" ]
u440566786
p02848
python
s517207489
s439556681
194
170
40,688
38,640
Accepted
Accepted
12.37
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda :sys.stdin.readline().rstrip() def resolve(): n=int(eval(input())) S=list(eval(input())) S=list(map(ord,S)) for i in range(len(S)): s=S[i] S[i]=65+(s+n-65)%26 S=list(map(chr,S)) print((''.join(S))) resolve()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() def resolve(): n=int(eval(input())) ans=[] for s in eval(input()): k=(ord(s)-ord('A')+n)%26+ord('A') ans.append(chr(k)) print((''.join(ans))) resolve()
15
14
334
300
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() def resolve(): n = int(eval(input())) S = list(eval(input())) S = list(map(ord, S)) for i in range(len(S)): s = S[i] S[i] = 65 + (s + n - 65) % 26 S = list(map(chr, S)) print(("".join(S))) resolve()
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() def resolve(): n = int(eval(input())) ans = [] for s in eval(input()): k = (ord(s) - ord("A") + n) % 26 + ord("A") ans.append(chr(k)) print(("".join(ans))) resolve()
false
6.666667
[ "- S = list(eval(input()))", "- S = list(map(ord, S))", "- for i in range(len(S)):", "- s = S[i]", "- S[i] = 65 + (s + n - 65) % 26", "- S = list(map(chr, S))", "- print((\"\".join(S)))", "+ ans = []", "+ for s in eval(input()):", "+ k = (ord(s) - ord(\"A\") + n) % 26 + ord(\"A\")", "+ ans.append(chr(k))", "+ print((\"\".join(ans)))" ]
false
0.044686
0.043917
1.017522
[ "s517207489", "s439556681" ]
u707500405
p04002
python
s545962443
s827825810
2,510
2,132
98,084
98,084
Accepted
Accepted
15.06
from collections import defaultdict def gen_bound(x,B): if x < 3: lb = 2 else: lb = x - 1 if x > B-2: ub = B-1 else: ub = x + 1 return lb,ub+1 def solve(): count = defaultdict(int) ans = [0]*10 H,W,N = list(map(int,input().split())) ans[0] = (H-2)*(W-2) for i in range(N): a,b = list(map(int,input().split())) xlb,xub = gen_bound(a,H) ylb,yub = gen_bound(b,W) for x in range(xlb,xub): for y in range(ylb,yub): k = x+(y<<34) bef_c = count[k] ans[bef_c] -= 1 ans[bef_c+1] += 1 count[k] += 1 for c in ans: print(c) solve()
from collections import defaultdict def gen_bound(x,B): if x < 3: lb = 2 else: lb = x - 1 if x > B-2: ub = B-1 else: ub = x + 1 return lb,ub+1 def solve(): count = defaultdict(int) ans = [0]*10 H,W,N = list(map(int,input().split())) ans[0] = (H-2)*(W-2) for i in range(N): a,b = list(map(int,input().split())) xlb,xub = gen_bound(a,H) ylb,yub = gen_bound(b,W) for x in range(xlb,xub): for y in range(ylb,yub): count[x+(y<<34)] += 1 for v in count.values():ans[v] += 1 ans[0] -= sum(ans[1:]) for c in ans: print(c) solve()
26
23
586
573
from collections import defaultdict def gen_bound(x, B): if x < 3: lb = 2 else: lb = x - 1 if x > B - 2: ub = B - 1 else: ub = x + 1 return lb, ub + 1 def solve(): count = defaultdict(int) ans = [0] * 10 H, W, N = list(map(int, input().split())) ans[0] = (H - 2) * (W - 2) for i in range(N): a, b = list(map(int, input().split())) xlb, xub = gen_bound(a, H) ylb, yub = gen_bound(b, W) for x in range(xlb, xub): for y in range(ylb, yub): k = x + (y << 34) bef_c = count[k] ans[bef_c] -= 1 ans[bef_c + 1] += 1 count[k] += 1 for c in ans: print(c) solve()
from collections import defaultdict def gen_bound(x, B): if x < 3: lb = 2 else: lb = x - 1 if x > B - 2: ub = B - 1 else: ub = x + 1 return lb, ub + 1 def solve(): count = defaultdict(int) ans = [0] * 10 H, W, N = list(map(int, input().split())) ans[0] = (H - 2) * (W - 2) for i in range(N): a, b = list(map(int, input().split())) xlb, xub = gen_bound(a, H) ylb, yub = gen_bound(b, W) for x in range(xlb, xub): for y in range(ylb, yub): count[x + (y << 34)] += 1 for v in count.values(): ans[v] += 1 ans[0] -= sum(ans[1:]) for c in ans: print(c) solve()
false
11.538462
[ "- k = x + (y << 34)", "- bef_c = count[k]", "- ans[bef_c] -= 1", "- ans[bef_c + 1] += 1", "- count[k] += 1", "+ count[x + (y << 34)] += 1", "+ for v in count.values():", "+ ans[v] += 1", "+ ans[0] -= sum(ans[1:])" ]
false
0.042776
0.042681
1.002215
[ "s545962443", "s827825810" ]
u790710233
p02642
python
s458517142
s373572473
386
347
51,420
51,236
Accepted
Accepted
10.1
n = int(eval(input())) A = sorted(map(int, input().split())) U = 10**6 line = [1]*(U+1) ans = set() depricated = set() cnt = [0]*(U+1) for a in A: cnt[a] += 1 if cnt[a] == 2 and line[a]: depricated.add(a) continue if 2 < cnt[a]: continue if line[a]: ans.add(a) for p in range(2*a, U+1, a): line[p] = 0 print((len(ans-depricated)))
n = int(eval(input())) A = sorted(map(int, input().split())) U = A[-1] line = [1]*(U+1) ans = set() depricated = set() cnt = [0]*(U+1) for a in A: if a in ans: depricated.add(a) continue if line[a]: ans.add(a) for p in range(2*a, U+1, a): line[p] = 0 print((len(ans-depricated)))
20
16
411
338
n = int(eval(input())) A = sorted(map(int, input().split())) U = 10**6 line = [1] * (U + 1) ans = set() depricated = set() cnt = [0] * (U + 1) for a in A: cnt[a] += 1 if cnt[a] == 2 and line[a]: depricated.add(a) continue if 2 < cnt[a]: continue if line[a]: ans.add(a) for p in range(2 * a, U + 1, a): line[p] = 0 print((len(ans - depricated)))
n = int(eval(input())) A = sorted(map(int, input().split())) U = A[-1] line = [1] * (U + 1) ans = set() depricated = set() cnt = [0] * (U + 1) for a in A: if a in ans: depricated.add(a) continue if line[a]: ans.add(a) for p in range(2 * a, U + 1, a): line[p] = 0 print((len(ans - depricated)))
false
20
[ "-U = 10**6", "+U = A[-1]", "- cnt[a] += 1", "- if cnt[a] == 2 and line[a]:", "+ if a in ans:", "- continue", "- if 2 < cnt[a]:" ]
false
0.159851
0.079842
2.002091
[ "s458517142", "s373572473" ]
u095021077
p02720
python
s597672313
s877726309
379
121
10,768
11,908
Accepted
Accepted
68.07
import heapq K=int(eval(input())) if K<10: print(K) exit() nums=[1, 2, 3, 4, 5, 6, 7, 8, 9] heapq.heapify(nums) for i in range(K): value=heapq.heappop(nums) tmp=str(value) if tmp[-1]=='0': cand=[int(tmp+'0'), int(tmp+'1')] elif tmp[-1]=='9': cand=[int(tmp+'8'), int(tmp+'9')] else: h=int(tmp[-1]) cand=[int(tmp+str(h-1)), int(tmp+str(h)), int(tmp+str(h+1))] for c in cand: heapq.heappush(nums, c) print(value)
from collections import deque K=int(eval(input())) q=deque() for i in range(1, 10): q.append(i) for i in range(K): v=q.popleft() if v%10!=0: q.append(10*v+v%10-1) q.append(10*v+v%10) if v%10!=9: q.append(10*v+v%10+1) print(v)
21
18
462
271
import heapq K = int(eval(input())) if K < 10: print(K) exit() nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] heapq.heapify(nums) for i in range(K): value = heapq.heappop(nums) tmp = str(value) if tmp[-1] == "0": cand = [int(tmp + "0"), int(tmp + "1")] elif tmp[-1] == "9": cand = [int(tmp + "8"), int(tmp + "9")] else: h = int(tmp[-1]) cand = [int(tmp + str(h - 1)), int(tmp + str(h)), int(tmp + str(h + 1))] for c in cand: heapq.heappush(nums, c) print(value)
from collections import deque K = int(eval(input())) q = deque() for i in range(1, 10): q.append(i) for i in range(K): v = q.popleft() if v % 10 != 0: q.append(10 * v + v % 10 - 1) q.append(10 * v + v % 10) if v % 10 != 9: q.append(10 * v + v % 10 + 1) print(v)
false
14.285714
[ "-import heapq", "+from collections import deque", "-if K < 10:", "- print(K)", "- exit()", "-nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]", "-heapq.heapify(nums)", "+q = deque()", "+for i in range(1, 10):", "+ q.append(i)", "- value = heapq.heappop(nums)", "- tmp = str(value)", "- if tmp[-1] == \"0\":", "- cand = [int(tmp + \"0\"), int(tmp + \"1\")]", "- elif tmp[-1] == \"9\":", "- cand = [int(tmp + \"8\"), int(tmp + \"9\")]", "- else:", "- h = int(tmp[-1])", "- cand = [int(tmp + str(h - 1)), int(tmp + str(h)), int(tmp + str(h + 1))]", "- for c in cand:", "- heapq.heappush(nums, c)", "-print(value)", "+ v = q.popleft()", "+ if v % 10 != 0:", "+ q.append(10 * v + v % 10 - 1)", "+ q.append(10 * v + v % 10)", "+ if v % 10 != 9:", "+ q.append(10 * v + v % 10 + 1)", "+print(v)" ]
false
0.09738
0.046399
2.098727
[ "s597672313", "s877726309" ]
u240096083
p02689
python
s356679298
s227388707
248
223
84,780
84,808
Accepted
Accepted
10.08
#展望台i:1 ~ Nこの展望台 #Hi: 展望台iの高さ from copy import deepcopy from pprint import pprint n,m = list(map(int, input().split())) h = list(map(int,input().split())) anslist = [1]*n for _ in range(m): a,b = list(map(int,input().split())) if h[a-1] > h[b-1]: anslist[b-1] = 0 elif h[a-1] < h[b-1]: anslist[a-1] = 0 elif h[a-1] == h[b-1]: anslist[a-1] = 0 anslist[b-1] = 0 #print(anslist) print((anslist.count(1))) exit()
#展望台i:1 ~ Nこの展望台 #Hi: 展望台iの高さ from copy import deepcopy from pprint import pprint n,m = list(map(int, input().split())) h = list(map(int,input().split())) nolist = [0] * n for _ in range(m): a,b = list(map(int,input().split())) if h[a-1] > h[b-1]: nolist[b-1] = 1 elif h[a-1] < h[b-1]: nolist[a-1] = 1 elif h[a-1] == h[b-1]: nolist[a-1] = 1 nolist[b-1] = 1 #counter = 0 #for j in range(n): # if maxlist[j] ==j and pairlist[j] != 1: # counter += 1 #print(maxlist) #print(pairlist) print((nolist.count(0))) exit()
28
33
486
596
# 展望台i:1 ~ Nこの展望台 # Hi: 展望台iの高さ from copy import deepcopy from pprint import pprint n, m = list(map(int, input().split())) h = list(map(int, input().split())) anslist = [1] * n for _ in range(m): a, b = list(map(int, input().split())) if h[a - 1] > h[b - 1]: anslist[b - 1] = 0 elif h[a - 1] < h[b - 1]: anslist[a - 1] = 0 elif h[a - 1] == h[b - 1]: anslist[a - 1] = 0 anslist[b - 1] = 0 # print(anslist) print((anslist.count(1))) exit()
# 展望台i:1 ~ Nこの展望台 # Hi: 展望台iの高さ from copy import deepcopy from pprint import pprint n, m = list(map(int, input().split())) h = list(map(int, input().split())) nolist = [0] * n for _ in range(m): a, b = list(map(int, input().split())) if h[a - 1] > h[b - 1]: nolist[b - 1] = 1 elif h[a - 1] < h[b - 1]: nolist[a - 1] = 1 elif h[a - 1] == h[b - 1]: nolist[a - 1] = 1 nolist[b - 1] = 1 # counter = 0 # for j in range(n): # if maxlist[j] ==j and pairlist[j] != 1: # counter += 1 # print(maxlist) # print(pairlist) print((nolist.count(0))) exit()
false
15.151515
[ "-anslist = [1] * n", "+nolist = [0] * n", "- anslist[b - 1] = 0", "+ nolist[b - 1] = 1", "- anslist[a - 1] = 0", "+ nolist[a - 1] = 1", "- anslist[a - 1] = 0", "- anslist[b - 1] = 0", "- # print(anslist)", "-print((anslist.count(1)))", "+ nolist[a - 1] = 1", "+ nolist[b - 1] = 1", "+# counter = 0", "+# for j in range(n):", "+# if maxlist[j] ==j and pairlist[j] != 1:", "+# counter += 1", "+# print(maxlist)", "+# print(pairlist)", "+print((nolist.count(0)))" ]
false
0.037294
0.036794
1.013599
[ "s356679298", "s227388707" ]
u562935282
p03160
python
s193171445
s473721506
207
177
13,980
13,928
Accepted
Accepted
14.49
inf = float('inf') n = int(eval(input())) h = list(map(int, input().split())) dp = [inf] * n dp[0] = 0 for i in range(n): for j in 2, 1: if i + j < n: dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i])) print((dp[n - 1]))
inf = float('inf') n = int(eval(input())) h = list(map(int, input().split())) + [inf] dp = [inf] * (n + 1) dp[0] = 0 # 配る for i in range(n - 1): dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i])) dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i])) print((dp[n - 1]))
14
13
260
293
inf = float("inf") n = int(eval(input())) h = list(map(int, input().split())) dp = [inf] * n dp[0] = 0 for i in range(n): for j in 2, 1: if i + j < n: dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i])) print((dp[n - 1]))
inf = float("inf") n = int(eval(input())) h = list(map(int, input().split())) + [inf] dp = [inf] * (n + 1) dp[0] = 0 # 配る for i in range(n - 1): dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i])) dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i])) print((dp[n - 1]))
false
7.142857
[ "-h = list(map(int, input().split()))", "-dp = [inf] * n", "+h = list(map(int, input().split())) + [inf]", "+dp = [inf] * (n + 1)", "-for i in range(n):", "- for j in 2, 1:", "- if i + j < n:", "- dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))", "+# 配る", "+for i in range(n - 1):", "+ dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))", "+ dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))" ]
false
0.045304
0.007649
5.922969
[ "s193171445", "s473721506" ]
u112317104
p02781
python
s028514755
s681442729
1,362
17
122,100
3,064
Accepted
Accepted
98.75
S = eval(input()) N = len(S) K = int(eval(input())) MOD = 10 ** 9 + 7 fact = [1, 1] factinv = [1, 1] inv = [0, 1] # 必要なだけforを回す for i in range(2, 10 ** 6): fact.append((fact[-1] * i) % MOD) inv.append((-inv[MOD % i] * (MOD // i)) % MOD) factinv.append((factinv[-1] * inv[-1]) % MOD) # nCr n個から重複を許さずr個の組み合わせを選ぶ def cmb(n, r): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n-r] % MOD def rec(i, k, isSmaller): if i == N: if k == 0: return 1 else: return 0 if k == 0: return 1 if isSmaller: return cmb(N-i, k) * pow(9, k) else: if S[i] == '0': return rec(i+1, k, False) else: zero = rec(i+1, k, True) between = rec(i+1, k-1, True) * (int(S[i]) - 1) same = rec(i+1, k-1, False) return zero + between + same print((rec(0, K, False)))
S = eval(input()) N = len(S) K = int(eval(input())) def cmb(n, r): if r < 0 or r > n: return 0 if r == 1: return n elif r == 2: return n * (n-1) // 2 else: return n * (n-1) * (n-2) // (3 * 2) def rec(i, k, isSmaller): if i == N: if k == 0: return 1 else: return 0 if k == 0: return 1 if isSmaller: return cmb(N-i, k) * pow(9, k) else: if S[i] == '0': return rec(i+1, k, False) else: zero = rec(i+1, k, True) between = rec(i+1, k-1, True) * (int(S[i]) - 1) same = rec(i+1, k-1, False) return zero + between + same print((rec(0, K, False)))
44
37
996
772
S = eval(input()) N = len(S) K = int(eval(input())) MOD = 10**9 + 7 fact = [1, 1] factinv = [1, 1] inv = [0, 1] # 必要なだけforを回す for i in range(2, 10**6): fact.append((fact[-1] * i) % MOD) inv.append((-inv[MOD % i] * (MOD // i)) % MOD) factinv.append((factinv[-1] * inv[-1]) % MOD) # nCr n個から重複を許さずr個の組み合わせを選ぶ def cmb(n, r): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n - r] % MOD def rec(i, k, isSmaller): if i == N: if k == 0: return 1 else: return 0 if k == 0: return 1 if isSmaller: return cmb(N - i, k) * pow(9, k) else: if S[i] == "0": return rec(i + 1, k, False) else: zero = rec(i + 1, k, True) between = rec(i + 1, k - 1, True) * (int(S[i]) - 1) same = rec(i + 1, k - 1, False) return zero + between + same print((rec(0, K, False)))
S = eval(input()) N = len(S) K = int(eval(input())) def cmb(n, r): if r < 0 or r > n: return 0 if r == 1: return n elif r == 2: return n * (n - 1) // 2 else: return n * (n - 1) * (n - 2) // (3 * 2) def rec(i, k, isSmaller): if i == N: if k == 0: return 1 else: return 0 if k == 0: return 1 if isSmaller: return cmb(N - i, k) * pow(9, k) else: if S[i] == "0": return rec(i + 1, k, False) else: zero = rec(i + 1, k, True) between = rec(i + 1, k - 1, True) * (int(S[i]) - 1) same = rec(i + 1, k - 1, False) return zero + between + same print((rec(0, K, False)))
false
15.909091
[ "-MOD = 10**9 + 7", "-fact = [1, 1]", "-factinv = [1, 1]", "-inv = [0, 1]", "-# 必要なだけforを回す", "-for i in range(2, 10**6):", "- fact.append((fact[-1] * i) % MOD)", "- inv.append((-inv[MOD % i] * (MOD // i)) % MOD)", "- factinv.append((factinv[-1] * inv[-1]) % MOD)", "-# nCr n個から重複を許さずr個の組み合わせを選ぶ", "+", "+", "- if (r < 0) or (n < r):", "+ if r < 0 or r > n:", "- r = min(r, n - r)", "- return fact[n] * factinv[r] * factinv[n - r] % MOD", "+ if r == 1:", "+ return n", "+ elif r == 2:", "+ return n * (n - 1) // 2", "+ else:", "+ return n * (n - 1) * (n - 2) // (3 * 2)" ]
false
0.094099
0.048791
1.928641
[ "s028514755", "s681442729" ]
u416011173
p02629
python
s693872120
s338525787
31
27
9,156
9,080
Accepted
Accepted
12.9
# -*- coding: utf-8 -*- # 標準入力の取得 N = int(eval(input())) def num_to_alpha(num): if num <= 26: return chr(96 + num) elif num % 26 == 0: return num_to_alpha(num // 26 - 1)+chr(122) else: return num_to_alpha(num // 26) + chr(96 + num % 26) # 求解処理 ans = num_to_alpha(N) # 結果出力 print(ans)
# -*- coding: utf-8 -*- def get_input() -> int: """ 標準入力を取得する. Returns:\n int: 標準入力 """ N = int(eval(input())) return N def main(N: int) -> None: """ 求解処理. Args:\n N (int): 整数 """ # 求解処理 ans = "" while N > 0: N -= 1 ans += chr(ord("a") + N % 26) N //= 26 ans = ans[::-1] # 結果出力 print(ans) if __name__ == "__main__": N = get_input() main(N)
19
37
337
492
# -*- coding: utf-8 -*- # 標準入力の取得 N = int(eval(input())) def num_to_alpha(num): if num <= 26: return chr(96 + num) elif num % 26 == 0: return num_to_alpha(num // 26 - 1) + chr(122) else: return num_to_alpha(num // 26) + chr(96 + num % 26) # 求解処理 ans = num_to_alpha(N) # 結果出力 print(ans)
# -*- coding: utf-8 -*- def get_input() -> int: """ 標準入力を取得する. Returns:\n int: 標準入力 """ N = int(eval(input())) return N def main(N: int) -> None: """ 求解処理. Args:\n N (int): 整数 """ # 求解処理 ans = "" while N > 0: N -= 1 ans += chr(ord("a") + N % 26) N //= 26 ans = ans[::-1] # 結果出力 print(ans) if __name__ == "__main__": N = get_input() main(N)
false
48.648649
[ "-# 標準入力の取得", "-N = int(eval(input()))", "+def get_input() -> int:", "+ \"\"\"", "+ 標準入力を取得する.", "+ Returns:\\n", "+ int: 標準入力", "+ \"\"\"", "+ N = int(eval(input()))", "+ return N", "-def num_to_alpha(num):", "- if num <= 26:", "- return chr(96 + num)", "- elif num % 26 == 0:", "- return num_to_alpha(num // 26 - 1) + chr(122)", "- else:", "- return num_to_alpha(num // 26) + chr(96 + num % 26)", "+def main(N: int) -> None:", "+ \"\"\"", "+ 求解処理.", "+ Args:\\n", "+ N (int): 整数", "+ \"\"\"", "+ # 求解処理", "+ ans = \"\"", "+ while N > 0:", "+ N -= 1", "+ ans += chr(ord(\"a\") + N % 26)", "+ N //= 26", "+ ans = ans[::-1]", "+ # 結果出力", "+ print(ans)", "-# 求解処理", "-ans = num_to_alpha(N)", "-# 結果出力", "-print(ans)", "+if __name__ == \"__main__\":", "+ N = get_input()", "+ main(N)" ]
false
0.039776
0.03916
1.015724
[ "s693872120", "s338525787" ]
u058433718
p02388
python
s464054671
s155251641
40
20
7,664
5,580
Accepted
Accepted
50
import sys x = int(sys.stdin.readline().strip()) print(('%d' % (x ** 3)))
import sys x = int(eval(input())) print((x ** 3))
4
4
75
45
import sys x = int(sys.stdin.readline().strip()) print(("%d" % (x**3)))
import sys x = int(eval(input())) print((x**3))
false
0
[ "-x = int(sys.stdin.readline().strip())", "-print((\"%d\" % (x**3)))", "+x = int(eval(input()))", "+print((x**3))" ]
false
0.038873
0.040669
0.955832
[ "s464054671", "s155251641" ]
u886747123
p03171
python
s985573180
s051476706
1,632
553
308,104
113,500
Accepted
Accepted
66.12
import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(1000000000) N = int(eval(input())) a = list(map(int, input().split())) dp = [[float("inf")]*(N+1) for _ in range(N+1)] for shift_i in range(N+1): for i in range(N+1): if i+shift_i >= N+1: continue if shift_i == 0: dp[i][i] = 0 elif ((i+shift_i)-i)%2 == N%2: # 先手番 dp[i][(i+shift_i)] = max(a[i] + dp[i+1][(i+shift_i)], a[(i+shift_i)-1] + dp[i][(i+shift_i)-1]) else: dp[i][(i+shift_i)] = min(-a[i] + dp[i+1][(i+shift_i)], -a[(i+shift_i)-1] + dp[i][(i+shift_i)-1]) print((dp[0][N]))
import sys input = sys.stdin.buffer.readline N = int(eval(input())) a = list(map(int, input().split())) # dp[i][j] 区間a[i,j)だけ残った時点で互いの点数を一旦0とし、ゲームを最後まで続けた場合のX-Yの値 dp = [[0]*(N+1) for _ in range(N+1)] # こちらもメモ化再帰ではpypy3でも間に合わない # j==i+1, i+2, ...とループしてdpテーブルの上三角部分を対角線と平行に埋めていく。jをshift_iと書き換えてループ for shift_i in range(1, N+1): for i in range(N+1): if i+shift_i >= N+1: continue elif ((i+shift_i)-i)%2 == N%2: # 先手番 dp[i][(i+shift_i)] = max(a[i] + dp[i+1][(i+shift_i)], a[(i+shift_i)-1] + dp[i][(i+shift_i)-1]) else: dp[i][(i+shift_i)] = min(-a[i] + dp[i+1][(i+shift_i)], -a[(i+shift_i)-1] + dp[i][(i+shift_i)-1]) print((dp[0][N]))
21
21
646
709
import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(1000000000) N = int(eval(input())) a = list(map(int, input().split())) dp = [[float("inf")] * (N + 1) for _ in range(N + 1)] for shift_i in range(N + 1): for i in range(N + 1): if i + shift_i >= N + 1: continue if shift_i == 0: dp[i][i] = 0 elif ((i + shift_i) - i) % 2 == N % 2: # 先手番 dp[i][(i + shift_i)] = max( a[i] + dp[i + 1][(i + shift_i)], a[(i + shift_i) - 1] + dp[i][(i + shift_i) - 1], ) else: dp[i][(i + shift_i)] = min( -a[i] + dp[i + 1][(i + shift_i)], -a[(i + shift_i) - 1] + dp[i][(i + shift_i) - 1], ) print((dp[0][N]))
import sys input = sys.stdin.buffer.readline N = int(eval(input())) a = list(map(int, input().split())) # dp[i][j] 区間a[i,j)だけ残った時点で互いの点数を一旦0とし、ゲームを最後まで続けた場合のX-Yの値 dp = [[0] * (N + 1) for _ in range(N + 1)] # こちらもメモ化再帰ではpypy3でも間に合わない # j==i+1, i+2, ...とループしてdpテーブルの上三角部分を対角線と平行に埋めていく。jをshift_iと書き換えてループ for shift_i in range(1, N + 1): for i in range(N + 1): if i + shift_i >= N + 1: continue elif ((i + shift_i) - i) % 2 == N % 2: # 先手番 dp[i][(i + shift_i)] = max( a[i] + dp[i + 1][(i + shift_i)], a[(i + shift_i) - 1] + dp[i][(i + shift_i) - 1], ) else: dp[i][(i + shift_i)] = min( -a[i] + dp[i + 1][(i + shift_i)], -a[(i + shift_i) - 1] + dp[i][(i + shift_i) - 1], ) print((dp[0][N]))
false
0
[ "-sys.setrecursionlimit(1000000000)", "-dp = [[float(\"inf\")] * (N + 1) for _ in range(N + 1)]", "-for shift_i in range(N + 1):", "+# dp[i][j] 区間a[i,j)だけ残った時点で互いの点数を一旦0とし、ゲームを最後まで続けた場合のX-Yの値", "+dp = [[0] * (N + 1) for _ in range(N + 1)]", "+# こちらもメモ化再帰ではpypy3でも間に合わない", "+# j==i+1, i+2, ...とループしてdpテーブルの上三角部分を対角線と平行に埋めていく。jをshift_iと書き換えてループ", "+for shift_i in range(1, N + 1):", "- if shift_i == 0:", "- dp[i][i] = 0" ]
false
0.051482
0.059942
0.858865
[ "s985573180", "s051476706" ]
u761087127
p02748
python
s490461812
s112142054
518
443
18,488
18,488
Accepted
Accepted
14.48
A, B, M = [int(n) for n in input().split()] a = [int(n) for n in input().split()] b = [int(n) for n in input().split()] ma = sorted(a)[0] mb = sorted(b)[0] ans = ma + mb for m in range(M): x, y, c = [int(n) for n in input().split()] dv = a[x-1] + b[y-1] - c ans = min(ans , dv) print(ans)
A, B, M = [int(n) for n in input().split()] a = [int(n) for n in input().split()] b = [int(n) for n in input().split()] ans = min(a) + min(b) for m in range(M): x, y, c = [int(n) for n in input().split()] dv = a[x-1] + b[y-1] - c ans = min(ans , dv) print(ans)
12
10
321
292
A, B, M = [int(n) for n in input().split()] a = [int(n) for n in input().split()] b = [int(n) for n in input().split()] ma = sorted(a)[0] mb = sorted(b)[0] ans = ma + mb for m in range(M): x, y, c = [int(n) for n in input().split()] dv = a[x - 1] + b[y - 1] - c ans = min(ans, dv) print(ans)
A, B, M = [int(n) for n in input().split()] a = [int(n) for n in input().split()] b = [int(n) for n in input().split()] ans = min(a) + min(b) for m in range(M): x, y, c = [int(n) for n in input().split()] dv = a[x - 1] + b[y - 1] - c ans = min(ans, dv) print(ans)
false
16.666667
[ "-ma = sorted(a)[0]", "-mb = sorted(b)[0]", "-ans = ma + mb", "+ans = min(a) + min(b)" ]
false
0.048392
0.045868
1.055027
[ "s490461812", "s112142054" ]
u305366205
p03044
python
s256559595
s142527234
757
672
72,096
37,516
Accepted
Accepted
11.23
from collections import deque def main(): def bfs(start): q = deque([start]) while q: u = q.popleft() for v, w in g[u]: if color[v] == -1: q.append(v) if w == 0: color[v] = color[u] else: color[v] = color[u] ^ 1 n = int(eval(input())) g = [[] for _ in range(n)] color = [-1] * n color[0] = 1 for _ in range(n - 1): u, v, w = list(map(int, input().split())) u -= 1 v -= 1 w %= 2 g[u].append((v, w)) g[v].append((u, w)) bfs(0) print((*color)) if __name__ == "__main__": main()
from collections import deque def main(): # 幅優先探索 def bfs(): q = deque([0]) while q: u = q.popleft() # 接続頂点を精査 for v, w in g[u]: # まだチェックしていない頂点をチェック if color[v] == -1: q.append(v) # 偶数なら同じ色で塗る if w == 0: color[v] = color[u] else: color[v] = color[u] ^ 1 n = int(eval(input())) g = [[] for _ in range(n)] # 塗りつぶし結果 color = [-1] * n # スタートは黒で塗っておく color[0] = 1 for _ in range(n - 1): u, v, w = list(map(int, input().split())) u -= 1 v -= 1 w %= 2 g[u].append((v, w)) g[v].append((u, w)) bfs() print((*color)) if __name__ == "__main__": main()
33
39
745
878
from collections import deque def main(): def bfs(start): q = deque([start]) while q: u = q.popleft() for v, w in g[u]: if color[v] == -1: q.append(v) if w == 0: color[v] = color[u] else: color[v] = color[u] ^ 1 n = int(eval(input())) g = [[] for _ in range(n)] color = [-1] * n color[0] = 1 for _ in range(n - 1): u, v, w = list(map(int, input().split())) u -= 1 v -= 1 w %= 2 g[u].append((v, w)) g[v].append((u, w)) bfs(0) print((*color)) if __name__ == "__main__": main()
from collections import deque def main(): # 幅優先探索 def bfs(): q = deque([0]) while q: u = q.popleft() # 接続頂点を精査 for v, w in g[u]: # まだチェックしていない頂点をチェック if color[v] == -1: q.append(v) # 偶数なら同じ色で塗る if w == 0: color[v] = color[u] else: color[v] = color[u] ^ 1 n = int(eval(input())) g = [[] for _ in range(n)] # 塗りつぶし結果 color = [-1] * n # スタートは黒で塗っておく color[0] = 1 for _ in range(n - 1): u, v, w = list(map(int, input().split())) u -= 1 v -= 1 w %= 2 g[u].append((v, w)) g[v].append((u, w)) bfs() print((*color)) if __name__ == "__main__": main()
false
15.384615
[ "- def bfs(start):", "- q = deque([start])", "+ # 幅優先探索", "+ def bfs():", "+ q = deque([0])", "+ # 接続頂点を精査", "+ # まだチェックしていない頂点をチェック", "+ # 偶数なら同じ色で塗る", "+ # 塗りつぶし結果", "+ # スタートは黒で塗っておく", "- bfs(0)", "+ bfs()" ]
false
0.045944
0.044935
1.022445
[ "s256559595", "s142527234" ]
u780962115
p03044
python
s097099116
s136343884
809
656
86,552
86,552
Accepted
Accepted
18.91
import sys sys.setrecursionlimit(100000) n=int(eval(input())) visitedlist=[-1 for i in range(n)] kilist=[[] for i in range(n)] anslist=[0 for i in range(n)] searchedlist=[-1 for i in range(n)] for i in range(n-1): a,b,c=list(map(int,input().split())) kilist[a-1].append((b,c)) kilist[b-1].append((a,c)) def search(i): searchedlist[i-1]=1 visitedlist[i-1]=1 flag=0 for j in kilist[i-1]: if visitedlist[j[0]-1]<0: visitedlist[j[0]-1]=1 flag+=1 anslist[j[0]-1]=anslist[i-1]+j[1] else: pass if flag>0: for k in kilist[i-1]: if searchedlist[k[0]-1]==-1: search(k[0]) search(2) for i in anslist: print((i%2))
import sys sys.setrecursionlimit(100000) input=sys.stdin.readline n=int(eval(input())) visitedlist=[-1 for i in range(n)] kilist=[[] for i in range(n)] anslist=[0 for i in range(n)] searchedlist=[-1 for i in range(n)] for i in range(n-1): a,b,c=list(map(int,input().split())) kilist[a-1].append((b,c)) kilist[b-1].append((a,c)) def search(i): searchedlist[i-1]=1 visitedlist[i-1]=1 flag=0 for j in kilist[i-1]: if visitedlist[j[0]-1]<0: visitedlist[j[0]-1]=1 flag+=1 anslist[j[0]-1]=anslist[i-1]+j[1] else: pass if flag>0: for k in kilist[i-1]: if searchedlist[k[0]-1]==-1: search(k[0]) search(2) for i in anslist: print((i%2))
31
31
822
846
import sys sys.setrecursionlimit(100000) n = int(eval(input())) visitedlist = [-1 for i in range(n)] kilist = [[] for i in range(n)] anslist = [0 for i in range(n)] searchedlist = [-1 for i in range(n)] for i in range(n - 1): a, b, c = list(map(int, input().split())) kilist[a - 1].append((b, c)) kilist[b - 1].append((a, c)) def search(i): searchedlist[i - 1] = 1 visitedlist[i - 1] = 1 flag = 0 for j in kilist[i - 1]: if visitedlist[j[0] - 1] < 0: visitedlist[j[0] - 1] = 1 flag += 1 anslist[j[0] - 1] = anslist[i - 1] + j[1] else: pass if flag > 0: for k in kilist[i - 1]: if searchedlist[k[0] - 1] == -1: search(k[0]) search(2) for i in anslist: print((i % 2))
import sys sys.setrecursionlimit(100000) input = sys.stdin.readline n = int(eval(input())) visitedlist = [-1 for i in range(n)] kilist = [[] for i in range(n)] anslist = [0 for i in range(n)] searchedlist = [-1 for i in range(n)] for i in range(n - 1): a, b, c = list(map(int, input().split())) kilist[a - 1].append((b, c)) kilist[b - 1].append((a, c)) def search(i): searchedlist[i - 1] = 1 visitedlist[i - 1] = 1 flag = 0 for j in kilist[i - 1]: if visitedlist[j[0] - 1] < 0: visitedlist[j[0] - 1] = 1 flag += 1 anslist[j[0] - 1] = anslist[i - 1] + j[1] else: pass if flag > 0: for k in kilist[i - 1]: if searchedlist[k[0] - 1] == -1: search(k[0]) search(2) for i in anslist: print((i % 2))
false
0
[ "+input = sys.stdin.readline" ]
false
0.041703
0.037601
1.109084
[ "s097099116", "s136343884" ]
u268822556
p02614
python
s098610005
s890889032
84
61
9,084
9,204
Accepted
Accepted
27.38
import itertools import copy H, W, K = list(map(int, input().split())) C = [] for _ in range(H): C.append([c for c in eval(input())]) H_list = [i for i in range(H)] H_comb = [] for i in range(1, H): H_comb += itertools.combinations(H_list, i) W_list = [i for i in range(W)] W_comb = [] for i in range(1, W): W_comb += itertools.combinations(W_list, i) ans = 0 cnt = 0 for w in C: cnt += w.count('#') if cnt == K: ans += 1 for wc in W_comb: temp_C0 = copy.deepcopy(C) for i in sorted(wc, reverse=True): for w in temp_C0: w.pop(i) cnt = 0 for w in temp_C0 : cnt += w.count('#') if cnt == K: ans += 1 for hc in H_comb: temp_C1 = copy.deepcopy(C) for i in sorted(hc, reverse=True): temp_C1.pop(i) cnt = 0 for w in temp_C1: cnt += w.count('#') if cnt == K: ans += 1 for wc in W_comb: temp_C2 = copy.deepcopy(temp_C1) for j in sorted(wc, reverse=True): for w in temp_C2: w.pop(j) cnt = 0 for w in temp_C2 : cnt += w.count('#') if cnt == K: ans += 1 print(ans)
H, W, K = list(map(int, input().split())) C = [] for _ in range(H): C.append([c for c in eval(input())]) ans = 0 for i in range(1<<H): for j in range(1<<W): cnt = 0 for m in range(H): for n in range(W): if i>>m&1: continue if j>>n&1: continue if C[m][n] == '#': cnt += 1 if cnt == K: ans += 1 print(ans)
44
14
1,106
392
import itertools import copy H, W, K = list(map(int, input().split())) C = [] for _ in range(H): C.append([c for c in eval(input())]) H_list = [i for i in range(H)] H_comb = [] for i in range(1, H): H_comb += itertools.combinations(H_list, i) W_list = [i for i in range(W)] W_comb = [] for i in range(1, W): W_comb += itertools.combinations(W_list, i) ans = 0 cnt = 0 for w in C: cnt += w.count("#") if cnt == K: ans += 1 for wc in W_comb: temp_C0 = copy.deepcopy(C) for i in sorted(wc, reverse=True): for w in temp_C0: w.pop(i) cnt = 0 for w in temp_C0: cnt += w.count("#") if cnt == K: ans += 1 for hc in H_comb: temp_C1 = copy.deepcopy(C) for i in sorted(hc, reverse=True): temp_C1.pop(i) cnt = 0 for w in temp_C1: cnt += w.count("#") if cnt == K: ans += 1 for wc in W_comb: temp_C2 = copy.deepcopy(temp_C1) for j in sorted(wc, reverse=True): for w in temp_C2: w.pop(j) cnt = 0 for w in temp_C2: cnt += w.count("#") if cnt == K: ans += 1 print(ans)
H, W, K = list(map(int, input().split())) C = [] for _ in range(H): C.append([c for c in eval(input())]) ans = 0 for i in range(1 << H): for j in range(1 << W): cnt = 0 for m in range(H): for n in range(W): if i >> m & 1: continue if j >> n & 1: continue if C[m][n] == "#": cnt += 1 if cnt == K: ans += 1 print(ans)
false
68.181818
[ "-import itertools", "-import copy", "-", "-H_list = [i for i in range(H)]", "-H_comb = []", "-for i in range(1, H):", "- H_comb += itertools.combinations(H_list, i)", "-W_list = [i for i in range(W)]", "-W_comb = []", "-for i in range(1, W):", "- W_comb += itertools.combinations(W_list, i)", "-cnt = 0", "-for w in C:", "- cnt += w.count(\"#\")", "-if cnt == K:", "- ans += 1", "-for wc in W_comb:", "- temp_C0 = copy.deepcopy(C)", "- for i in sorted(wc, reverse=True):", "- for w in temp_C0:", "- w.pop(i)", "- cnt = 0", "- for w in temp_C0:", "- cnt += w.count(\"#\")", "- if cnt == K:", "- ans += 1", "-for hc in H_comb:", "- temp_C1 = copy.deepcopy(C)", "- for i in sorted(hc, reverse=True):", "- temp_C1.pop(i)", "- cnt = 0", "- for w in temp_C1:", "- cnt += w.count(\"#\")", "- if cnt == K:", "- ans += 1", "- for wc in W_comb:", "- temp_C2 = copy.deepcopy(temp_C1)", "- for j in sorted(wc, reverse=True):", "- for w in temp_C2:", "- w.pop(j)", "+for i in range(1 << H):", "+ for j in range(1 << W):", "- for w in temp_C2:", "- cnt += w.count(\"#\")", "+ for m in range(H):", "+ for n in range(W):", "+ if i >> m & 1:", "+ continue", "+ if j >> n & 1:", "+ continue", "+ if C[m][n] == \"#\":", "+ cnt += 1" ]
false
0.053432
0.095275
0.560819
[ "s098610005", "s890889032" ]
u672475305
p03436
python
s827832272
s053691358
192
154
40,688
12,496
Accepted
Accepted
19.79
from collections import deque h,w = list(map(int,input().split())) S = [list(eval(input())) for _ in range(h)] cost = [[-1]*w for _ in range(h)] sy,sx = 0,0 gy,gx = h-1, w-1 que = deque([(sy,sx,0)]) flg = False ret = -1 while que: y,x,c = que.popleft() if y==gy and x==gx: flg = True ret = c break if cost[y][x] != -1: continue cost[y][x] = c for dy,dx in zip((-1, 1, 0, 0), (0, 0, -1, 1)): ny = y + dy nx = x + dx if 0<=ny<h and 0<=nx<w: if S[ny][nx]!='#': que.append((ny,nx,c+1)) if not flg: print((-1)) else: blk, wht = 0, 0 for s in S: for ss in s: if ss=='#': blk += 1 else: wht += 1 print((h*w-ret-1-blk))
R,C = list(map(int,input().split())) sy,sx = 1,1 gy,gx = R,C maze = [list(eval(input())) for _ in range(R)] mx = 0 for m in maze: mx += m.count('.') sx,sy = sx-1, sy-1 gx,gy = gx-1, gy-1 def bfs(R,C,sy,sx,gy,gx,maze): from collections import deque import numpy as np INF = np.inf visited = [[INF]*C for _ in range(R)] visited[sy][sx] = 0 que = deque([(sy,sx)]) while que: y,x = que.popleft() for i,j in ((1,0),(0,1),(-1,0),(0,-1)): ny,nx = y+i, x+j if 0<=ny<R and 0<=nx<C: if (maze[ny][nx]!='#') and visited[ny][nx]==INF: visited[ny][nx] = visited[y][x] + 1 que.append((ny,nx)) if visited[gy][gx]!=INF: return visited[gy][gx] else: return -1 ans = bfs(R,C,sy,sx,gy,gx,maze) print((mx-ans-1 if ans!=-1 else -1))
38
34
819
879
from collections import deque h, w = list(map(int, input().split())) S = [list(eval(input())) for _ in range(h)] cost = [[-1] * w for _ in range(h)] sy, sx = 0, 0 gy, gx = h - 1, w - 1 que = deque([(sy, sx, 0)]) flg = False ret = -1 while que: y, x, c = que.popleft() if y == gy and x == gx: flg = True ret = c break if cost[y][x] != -1: continue cost[y][x] = c for dy, dx in zip((-1, 1, 0, 0), (0, 0, -1, 1)): ny = y + dy nx = x + dx if 0 <= ny < h and 0 <= nx < w: if S[ny][nx] != "#": que.append((ny, nx, c + 1)) if not flg: print((-1)) else: blk, wht = 0, 0 for s in S: for ss in s: if ss == "#": blk += 1 else: wht += 1 print((h * w - ret - 1 - blk))
R, C = list(map(int, input().split())) sy, sx = 1, 1 gy, gx = R, C maze = [list(eval(input())) for _ in range(R)] mx = 0 for m in maze: mx += m.count(".") sx, sy = sx - 1, sy - 1 gx, gy = gx - 1, gy - 1 def bfs(R, C, sy, sx, gy, gx, maze): from collections import deque import numpy as np INF = np.inf visited = [[INF] * C for _ in range(R)] visited[sy][sx] = 0 que = deque([(sy, sx)]) while que: y, x = que.popleft() for i, j in ((1, 0), (0, 1), (-1, 0), (0, -1)): ny, nx = y + i, x + j if 0 <= ny < R and 0 <= nx < C: if (maze[ny][nx] != "#") and visited[ny][nx] == INF: visited[ny][nx] = visited[y][x] + 1 que.append((ny, nx)) if visited[gy][gx] != INF: return visited[gy][gx] else: return -1 ans = bfs(R, C, sy, sx, gy, gx, maze) print((mx - ans - 1 if ans != -1 else -1))
false
10.526316
[ "-from collections import deque", "+R, C = list(map(int, input().split()))", "+sy, sx = 1, 1", "+gy, gx = R, C", "+maze = [list(eval(input())) for _ in range(R)]", "+mx = 0", "+for m in maze:", "+ mx += m.count(\".\")", "+sx, sy = sx - 1, sy - 1", "+gx, gy = gx - 1, gy - 1", "-h, w = list(map(int, input().split()))", "-S = [list(eval(input())) for _ in range(h)]", "-cost = [[-1] * w for _ in range(h)]", "-sy, sx = 0, 0", "-gy, gx = h - 1, w - 1", "-que = deque([(sy, sx, 0)])", "-flg = False", "-ret = -1", "-while que:", "- y, x, c = que.popleft()", "- if y == gy and x == gx:", "- flg = True", "- ret = c", "- break", "- if cost[y][x] != -1:", "- continue", "- cost[y][x] = c", "- for dy, dx in zip((-1, 1, 0, 0), (0, 0, -1, 1)):", "- ny = y + dy", "- nx = x + dx", "- if 0 <= ny < h and 0 <= nx < w:", "- if S[ny][nx] != \"#\":", "- que.append((ny, nx, c + 1))", "-if not flg:", "- print((-1))", "-else:", "- blk, wht = 0, 0", "- for s in S:", "- for ss in s:", "- if ss == \"#\":", "- blk += 1", "- else:", "- wht += 1", "- print((h * w - ret - 1 - blk))", "+", "+def bfs(R, C, sy, sx, gy, gx, maze):", "+ from collections import deque", "+ import numpy as np", "+", "+ INF = np.inf", "+ visited = [[INF] * C for _ in range(R)]", "+ visited[sy][sx] = 0", "+ que = deque([(sy, sx)])", "+ while que:", "+ y, x = que.popleft()", "+ for i, j in ((1, 0), (0, 1), (-1, 0), (0, -1)):", "+ ny, nx = y + i, x + j", "+ if 0 <= ny < R and 0 <= nx < C:", "+ if (maze[ny][nx] != \"#\") and visited[ny][nx] == INF:", "+ visited[ny][nx] = visited[y][x] + 1", "+ que.append((ny, nx))", "+ if visited[gy][gx] != INF:", "+ return visited[gy][gx]", "+ else:", "+ return -1", "+", "+", "+ans = bfs(R, C, sy, sx, gy, gx, maze)", "+print((mx - ans - 1 if ans != -1 else -1))" ]
false
0.048643
0.043223
1.125381
[ "s827832272", "s053691358" ]
u189479417
p02580
python
s990917884
s605083505
931
811
83,408
58,920
Accepted
Accepted
12.89
import sys H, W, M = list(map(int,input().split())) R = [0] * H C = [0] * W S = set() for _ in range(M): h, w = list(map(int,input().split())) S.add((h-1, w-1)) R[h-1] += 1 C[w-1] += 1 r = max(R) c = max(C) HL = [i for i in range(H) if R[i] == r] WL = [i for i in range(W) if C[i] == c] for h in HL: for w in WL: if not (h, w) in S: print((r + c)) sys.exit() print((r + c - 1))
H, W, M = list(map(int,input().split())) R = [0] * H C = [0] * W L = [] for _ in range(M): h, w = list(map(int,input().split())) R[h-1] += 1 C[w-1] += 1 L.append([h-1, w-1]) r = max(R) c = max(C) print((r + c - (R.count(r) * C.count(c) == sum(R[h] + C[w] == r + c for h, w in L))))
27
16
446
302
import sys H, W, M = list(map(int, input().split())) R = [0] * H C = [0] * W S = set() for _ in range(M): h, w = list(map(int, input().split())) S.add((h - 1, w - 1)) R[h - 1] += 1 C[w - 1] += 1 r = max(R) c = max(C) HL = [i for i in range(H) if R[i] == r] WL = [i for i in range(W) if C[i] == c] for h in HL: for w in WL: if not (h, w) in S: print((r + c)) sys.exit() print((r + c - 1))
H, W, M = list(map(int, input().split())) R = [0] * H C = [0] * W L = [] for _ in range(M): h, w = list(map(int, input().split())) R[h - 1] += 1 C[w - 1] += 1 L.append([h - 1, w - 1]) r = max(R) c = max(C) print((r + c - (R.count(r) * C.count(c) == sum(R[h] + C[w] == r + c for h, w in L))))
false
40.740741
[ "-import sys", "-", "-S = set()", "+L = []", "- S.add((h - 1, w - 1))", "+ L.append([h - 1, w - 1])", "-HL = [i for i in range(H) if R[i] == r]", "-WL = [i for i in range(W) if C[i] == c]", "-for h in HL:", "- for w in WL:", "- if not (h, w) in S:", "- print((r + c))", "- sys.exit()", "-print((r + c - 1))", "+print((r + c - (R.count(r) * C.count(c) == sum(R[h] + C[w] == r + c for h, w in L))))" ]
false
0.048898
0.046649
1.048219
[ "s990917884", "s605083505" ]
u334712262
p03476
python
s866457673
s930412096
811
746
92,244
89,172
Accepted
Accepted
8.01
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul sys.setrecursionlimit(10000) def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap def eratosthenes(n): p = [1] t = [True] * n t[1] = True for i in range(2, int(math.ceil(math.sqrt(n)))): if t[i]: p.append(i) for j in range(2*i, n, i): t[j] = False for j in range(i+1, n): if t[j]: p.append(j) return p @mt def slv(Q, LR): N = 100000 p = eratosthenes(N) qt = [0] * N for i in range(2, N): qt[i] = qt[i-1] if i % 2 == 0: continue q = (i+1)//2 qi = bisect.bisect_left(p, q) ii = bisect.bisect_left(p, i) if qi != len(p) and p[qi] == q and ii != len(p) and p[ii] == i: qt[i] += 1 for l, r in LR: print(qt[r] - qt[l-1]) # ans = 0 # return ans def main(): Q = read_int() LR = [read_int_n() for _ in range(Q)] # print(slv(Q, LR)) slv(Q, LR) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul sys.setrecursionlimit(10000) def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap def eratosthenes(n): p = [1] t = [True] * n t[1] = True for i in range(2, int(math.ceil(math.sqrt(n)))): if t[i]: p.append(i) for j in range(2*i, n, i): t[j] = False for j in range(i+1, n): if t[j]: p.append(j) return p, t @mt def slv(Q, LR): N = 100000 p, t = eratosthenes(N) qt = [0] * N for i in range(3, N): qt[i] = qt[i-1] if t[i] and t[(i+1)//2]: qt[i] += 1 for l, r in LR: print(qt[r] - qt[l-1]) def main(): Q = read_int() LR = [read_int_n() for _ in range(Q)] slv(Q, LR) if __name__ == '__main__': main()
106
97
1,995
1,756
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul sys.setrecursionlimit(10000) def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap def eratosthenes(n): p = [1] t = [True] * n t[1] = True for i in range(2, int(math.ceil(math.sqrt(n)))): if t[i]: p.append(i) for j in range(2 * i, n, i): t[j] = False for j in range(i + 1, n): if t[j]: p.append(j) return p @mt def slv(Q, LR): N = 100000 p = eratosthenes(N) qt = [0] * N for i in range(2, N): qt[i] = qt[i - 1] if i % 2 == 0: continue q = (i + 1) // 2 qi = bisect.bisect_left(p, q) ii = bisect.bisect_left(p, i) if qi != len(p) and p[qi] == q and ii != len(p) and p[ii] == i: qt[i] += 1 for l, r in LR: print(qt[r] - qt[l - 1]) # ans = 0 # return ans def main(): Q = read_int() LR = [read_int_n() for _ in range(Q)] # print(slv(Q, LR)) slv(Q, LR) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random import sys from collections import Counter, defaultdict from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul sys.setrecursionlimit(10000) def read_int(): return int(input()) def read_int_n(): return list(map(int, input().split())) def read_float(): return float(input()) def read_float_n(): return list(map(float, input().split())) def read_str(): return input() def read_str_n(): return list(map(str, input().split())) def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap def eratosthenes(n): p = [1] t = [True] * n t[1] = True for i in range(2, int(math.ceil(math.sqrt(n)))): if t[i]: p.append(i) for j in range(2 * i, n, i): t[j] = False for j in range(i + 1, n): if t[j]: p.append(j) return p, t @mt def slv(Q, LR): N = 100000 p, t = eratosthenes(N) qt = [0] * N for i in range(3, N): qt[i] = qt[i - 1] if t[i] and t[(i + 1) // 2]: qt[i] += 1 for l, r in LR: print(qt[r] - qt[l - 1]) def main(): Q = read_int() LR = [read_int_n() for _ in range(Q)] slv(Q, LR) if __name__ == "__main__": main()
false
8.490566
[ "- return p", "+ return p, t", "- p = eratosthenes(N)", "+ p, t = eratosthenes(N)", "- for i in range(2, N):", "+ for i in range(3, N):", "- if i % 2 == 0:", "- continue", "- q = (i + 1) // 2", "- qi = bisect.bisect_left(p, q)", "- ii = bisect.bisect_left(p, i)", "- if qi != len(p) and p[qi] == q and ii != len(p) and p[ii] == i:", "+ if t[i] and t[(i + 1) // 2]:", "- # ans = 0", "- # return ans", "- # print(slv(Q, LR))" ]
false
0.187234
0.153769
1.217629
[ "s866457673", "s930412096" ]
u630511239
p03730
python
s695883202
s096713874
38
35
5,432
5,104
Accepted
Accepted
7.89
A, B, C = list(map(int, input().split())) import fractions c = fractions.gcd(A,B) ans = 'NO' if C % c == 0: ans = 'YES' print(ans)
A, B, C = list(map(int, input().split())) import fractions a = fractions.gcd(A, B) ans = 'NO' if a == 1: ans = 'YES' elif C % a == 0: ans = 'YES' print(ans)
7
9
132
162
A, B, C = list(map(int, input().split())) import fractions c = fractions.gcd(A, B) ans = "NO" if C % c == 0: ans = "YES" print(ans)
A, B, C = list(map(int, input().split())) import fractions a = fractions.gcd(A, B) ans = "NO" if a == 1: ans = "YES" elif C % a == 0: ans = "YES" print(ans)
false
22.222222
[ "-c = fractions.gcd(A, B)", "+a = fractions.gcd(A, B)", "-if C % c == 0:", "+if a == 1:", "+ ans = \"YES\"", "+elif C % a == 0:" ]
false
0.057218
0.057286
0.998823
[ "s695883202", "s096713874" ]
u684241248
p02269
python
s832221545
s376671655
6,690
6,180
138,492
137,140
Accepted
Accepted
7.62
import sys n = int(eval(input())) htable = [0 for _ in range(16777216)] def to_int(s): if s == 'A': return 1 elif s == 'C': return 2 elif s == 'G': return 3 else: return 4 def to_hash(string): h = 0 for i, s in enumerate(string): ints = to_int(s) h += 4**i * ints return h def insert(string): h = to_hash(string) htable[h] = 1 def find(string): h = to_hash(string) if htable[h]: print('yes') else: print('no') for line in sys.stdin: cmd, string = line.strip().split() if cmd == 'insert': insert(string) else: find(string)
import sys htable = [0] * 16777216 def to_int(s): if s == 'A': return 1 elif s == 'C': return 2 elif s == 'G': return 3 else: return 4 def to_hash(string): h = 0 for i, s in enumerate(string): ints = to_int(s) h += 4**i * ints return h def insert(string): h = to_hash(string) htable[h] = 1 def find(string): h = to_hash(string) if htable[h]: print('yes') else: print('no') if __name__ == '__main__': n = int(eval(input())) for line in sys.stdin: cmd, string = line.strip().split() if cmd == 'insert': insert(string) else: find(string)
48
51
718
764
import sys n = int(eval(input())) htable = [0 for _ in range(16777216)] def to_int(s): if s == "A": return 1 elif s == "C": return 2 elif s == "G": return 3 else: return 4 def to_hash(string): h = 0 for i, s in enumerate(string): ints = to_int(s) h += 4**i * ints return h def insert(string): h = to_hash(string) htable[h] = 1 def find(string): h = to_hash(string) if htable[h]: print("yes") else: print("no") for line in sys.stdin: cmd, string = line.strip().split() if cmd == "insert": insert(string) else: find(string)
import sys htable = [0] * 16777216 def to_int(s): if s == "A": return 1 elif s == "C": return 2 elif s == "G": return 3 else: return 4 def to_hash(string): h = 0 for i, s in enumerate(string): ints = to_int(s) h += 4**i * ints return h def insert(string): h = to_hash(string) htable[h] = 1 def find(string): h = to_hash(string) if htable[h]: print("yes") else: print("no") if __name__ == "__main__": n = int(eval(input())) for line in sys.stdin: cmd, string = line.strip().split() if cmd == "insert": insert(string) else: find(string)
false
5.882353
[ "-n = int(eval(input()))", "-htable = [0 for _ in range(16777216)]", "+htable = [0] * 16777216", "-for line in sys.stdin:", "- cmd, string = line.strip().split()", "- if cmd == \"insert\":", "- insert(string)", "- else:", "- find(string)", "+if __name__ == \"__main__\":", "+ n = int(eval(input()))", "+ for line in sys.stdin:", "+ cmd, string = line.strip().split()", "+ if cmd == \"insert\":", "+ insert(string)", "+ else:", "+ find(string)" ]
false
0.916304
0.564943
1.62194
[ "s832221545", "s376671655" ]
u623819879
p03043
python
s342152641
s629100914
167
68
38,768
65,068
Accepted
Accepted
59.28
import sys import math sys.setrecursionlimit(10**6) from collections import defaultdict n,k=list(map(int,input().split())) ans=0 for i in range(1,n+1): if i>=k: ans+=1/n else: ans+=1/(n*2**int(1-1/(10**9)+math.log((k/i),2))) #print(i,2**int(math.log((k/i),2)),ans) print(ans)
n,k=list(map(int,input().split())) a=0 for i in range(n): x=i+1;y=0 while x<k:x*=2;y+=1 a+=1/2**y print((a/n))
14
7
308
111
import sys import math sys.setrecursionlimit(10**6) from collections import defaultdict n, k = list(map(int, input().split())) ans = 0 for i in range(1, n + 1): if i >= k: ans += 1 / n else: ans += 1 / (n * 2 ** int(1 - 1 / (10**9) + math.log((k / i), 2))) # print(i,2**int(math.log((k/i),2)),ans) print(ans)
n, k = list(map(int, input().split())) a = 0 for i in range(n): x = i + 1 y = 0 while x < k: x *= 2 y += 1 a += 1 / 2**y print((a / n))
false
50
[ "-import sys", "-import math", "-", "-sys.setrecursionlimit(10**6)", "-from collections import defaultdict", "-", "-ans = 0", "-for i in range(1, n + 1):", "- if i >= k:", "- ans += 1 / n", "- else:", "- ans += 1 / (n * 2 ** int(1 - 1 / (10**9) + math.log((k / i), 2)))", "-# print(i,2**int(math.log((k/i),2)),ans)", "-print(ans)", "+a = 0", "+for i in range(n):", "+ x = i + 1", "+ y = 0", "+ while x < k:", "+ x *= 2", "+ y += 1", "+ a += 1 / 2**y", "+print((a / n))" ]
false
0.05044
0.079923
0.631107
[ "s342152641", "s629100914" ]
u680851063
p02678
python
s441784726
s243743171
549
456
34,820
34,564
Accepted
Accepted
16.94
# ダミーノード'0'を設定 ※※※ # AtCoder Beginner Contest 168 # https://atcoder.jp/contests/abc168/tasks/abc168_d import sys input = sys.stdin.readline n, m = list(map(int, input().split())) # nは頂点の数、mは辺の数 pic = [[] for _ in range(n+1)] # 隣接リスト_初期化 ※※※ for _ in range(m): # 隣接リスト_取り込み a, b = list(map(int, input().split())) pic[a].append(b) # ※※※ pic[b].append(a) # ※※※ from collections import deque def BFS(u): # 'u'を開始位置として各頂点までの距離を探索する関数_dis → 親ノードを探索して'ans'に記録 queue = deque([u]) # dequeオブジェクトとして初期化、初期値は開始位置の'u'のみ dis = [None] * (n+1) # uからの距離を全ノード分初期化 ※※※ dis[u] = 0 # 開始位置'u'の距離は'0' ans = [-1] * (n+1) # 親ノードを記録する while queue: v = queue.popleft() # 'v'に探索候補のノードを popleft for i in pic[v]: # pic[v]: 探索候補のノードに隣接するノードのリスト if ans[i] == -1: # 親ノードを記録 ans[i] = v if dis[i] is None: dis[i] = dis[v] queue.append(i) return ans tmp = BFS(1) # ここは開始位置'1' print('Yes') for j in tmp[2:]: print(j) # ※※※
# ダミーノード'0'を設定 ※※※ # AtCoder Beginner Contest 168 # https://atcoder.jp/contests/abc168/tasks/abc168_d import sys input = sys.stdin.readline n, m = list(map(int, input().split())) # nは頂点の数、mは辺の数 pic = [[] for _ in range(n+1)] # 隣接リスト_初期化 ※※※ for _ in range(m): # 隣接リスト_取り込み a, b = list(map(int, input().split())) pic[a].append(b) # ※※※ pic[b].append(a) # ※※※ #print(pic) from collections import deque def BFS(u): # 'u'を開始位置として各頂点までの距離を探索する関数_dis → 親ノードを探索して'ans'に記録 queue = deque([u]) # dequeオブジェクトとして初期化、初期値は開始位置の'u'のみ dis = [None] * (n+1) # uからの距離を全ノード分初期化 ※※※ dis[u] = 0 # 開始位置'u'の距離は'0' ans = [-1] * (n+1) # 親ノードを記録する while queue: v = queue.popleft() # 'v'に探索候補のノードを popleft for i in pic[v]: # pic[v]: 探索候補のノードに隣接するノードのリスト if ans[i] == -1: # 親ノードを記録 ans[i] = v if dis[i] is None: dis[i] = dis[v] + 1 # 'u'からの距離を記録 queue.append(i) #print(ans) #print(dis) return ans print('Yes') tmp = BFS(1) # ここは開始位置'1' for j in tmp[2:]: print(j) # ※※※
36
41
1,044
1,113
# ダミーノード'0'を設定 ※※※ # AtCoder Beginner Contest 168 # https://atcoder.jp/contests/abc168/tasks/abc168_d import sys input = sys.stdin.readline n, m = list(map(int, input().split())) # nは頂点の数、mは辺の数 pic = [[] for _ in range(n + 1)] # 隣接リスト_初期化 ※※※ for _ in range(m): # 隣接リスト_取り込み a, b = list(map(int, input().split())) pic[a].append(b) # ※※※ pic[b].append(a) # ※※※ from collections import deque def BFS(u): # 'u'を開始位置として各頂点までの距離を探索する関数_dis → 親ノードを探索して'ans'に記録 queue = deque([u]) # dequeオブジェクトとして初期化、初期値は開始位置の'u'のみ dis = [None] * (n + 1) # uからの距離を全ノード分初期化 ※※※ dis[u] = 0 # 開始位置'u'の距離は'0' ans = [-1] * (n + 1) # 親ノードを記録する while queue: v = queue.popleft() # 'v'に探索候補のノードを popleft for i in pic[v]: # pic[v]: 探索候補のノードに隣接するノードのリスト if ans[i] == -1: # 親ノードを記録 ans[i] = v if dis[i] is None: dis[i] = dis[v] queue.append(i) return ans tmp = BFS(1) # ここは開始位置'1' print("Yes") for j in tmp[2:]: print(j) # ※※※
# ダミーノード'0'を設定 ※※※ # AtCoder Beginner Contest 168 # https://atcoder.jp/contests/abc168/tasks/abc168_d import sys input = sys.stdin.readline n, m = list(map(int, input().split())) # nは頂点の数、mは辺の数 pic = [[] for _ in range(n + 1)] # 隣接リスト_初期化 ※※※ for _ in range(m): # 隣接リスト_取り込み a, b = list(map(int, input().split())) pic[a].append(b) # ※※※ pic[b].append(a) # ※※※ # print(pic) from collections import deque def BFS(u): # 'u'を開始位置として各頂点までの距離を探索する関数_dis → 親ノードを探索して'ans'に記録 queue = deque([u]) # dequeオブジェクトとして初期化、初期値は開始位置の'u'のみ dis = [None] * (n + 1) # uからの距離を全ノード分初期化 ※※※ dis[u] = 0 # 開始位置'u'の距離は'0' ans = [-1] * (n + 1) # 親ノードを記録する while queue: v = queue.popleft() # 'v'に探索候補のノードを popleft for i in pic[v]: # pic[v]: 探索候補のノードに隣接するノードのリスト if ans[i] == -1: # 親ノードを記録 ans[i] = v if dis[i] is None: dis[i] = dis[v] + 1 # 'u'からの距離を記録 queue.append(i) # print(ans) # print(dis) return ans print("Yes") tmp = BFS(1) # ここは開始位置'1' for j in tmp[2:]: print(j) # ※※※
false
12.195122
[ "+# print(pic)", "- dis[i] = dis[v]", "+ dis[i] = dis[v] + 1 # 'u'からの距離を記録", "+ # print(ans)", "+ # print(dis)", "+print(\"Yes\")", "-print(\"Yes\")" ]
false
0.038617
0.044181
0.87407
[ "s441784726", "s243743171" ]
u912237403
p00046
python
s777578886
s742702277
20
10
4,200
4,200
Accepted
Accepted
50
import sys s = list(map(float, sys.stdin)) print(max(s)-min(s))
import sys s = sorted(map(float, sys.stdin)) print(s[-1]-s[0])
4
4
60
65
import sys s = list(map(float, sys.stdin)) print(max(s) - min(s))
import sys s = sorted(map(float, sys.stdin)) print(s[-1] - s[0])
false
0
[ "-s = list(map(float, sys.stdin))", "-print(max(s) - min(s))", "+s = sorted(map(float, sys.stdin))", "+print(s[-1] - s[0])" ]
false
0.054347
0.035687
1.522875
[ "s777578886", "s742702277" ]
u556326323
p02390
python
s678538001
s648711746
30
20
7,660
7,640
Accepted
Accepted
33.33
t, s = divmod(int(eval(input())), 60) h, m = divmod(t, 60) print((str(h) + ':' + str(m) + ':' + str(s)))
t, s = divmod(int(input()), 60) h, m = divmod(t, 60) print(h, m, s, sep=':')
3
3
98
78
t, s = divmod(int(eval(input())), 60) h, m = divmod(t, 60) print((str(h) + ":" + str(m) + ":" + str(s)))
t, s = divmod(int(input()), 60) h, m = divmod(t, 60) print(h, m, s, sep=":")
false
0
[ "-t, s = divmod(int(eval(input())), 60)", "+t, s = divmod(int(input()), 60)", "-print((str(h) + \":\" + str(m) + \":\" + str(s)))", "+print(h, m, s, sep=\":\")" ]
false
0.038236
0.03764
1.015829
[ "s678538001", "s648711746" ]
u002459665
p03578
python
s489670743
s617562011
449
335
35,116
35,556
Accepted
Accepted
25.39
N = int(eval(input())) D = list(map(int, input().split())) M = int(eval(input())) T = list(map(int, input().split())) D.sort() T.sort() flag = True if N < M: flag = False else: d_ind = 0 find = False for i in range(M): for j in range(d_ind, N): if T[i] == D[j]: find = True d_ind = j+1 break if not find: flag = False break find = False if flag: print('YES') else: print('NO')
N = int(eval(input())) D = list(map(int, input().split())) M = int(eval(input())) T = list(map(int, input().split())) D.sort() T.sort() flag = True if N < M: flag = False else: i = 0 for ti in T: find = False while i < N: if ti == D[i]: find = True i += 1 break else: i += 1 if not find: flag = False if flag: print('YES') else: print('NO')
30
29
529
503
N = int(eval(input())) D = list(map(int, input().split())) M = int(eval(input())) T = list(map(int, input().split())) D.sort() T.sort() flag = True if N < M: flag = False else: d_ind = 0 find = False for i in range(M): for j in range(d_ind, N): if T[i] == D[j]: find = True d_ind = j + 1 break if not find: flag = False break find = False if flag: print("YES") else: print("NO")
N = int(eval(input())) D = list(map(int, input().split())) M = int(eval(input())) T = list(map(int, input().split())) D.sort() T.sort() flag = True if N < M: flag = False else: i = 0 for ti in T: find = False while i < N: if ti == D[i]: find = True i += 1 break else: i += 1 if not find: flag = False if flag: print("YES") else: print("NO")
false
3.333333
[ "- d_ind = 0", "- find = False", "- for i in range(M):", "- for j in range(d_ind, N):", "- if T[i] == D[j]:", "+ i = 0", "+ for ti in T:", "+ find = False", "+ while i < N:", "+ if ti == D[i]:", "- d_ind = j + 1", "+ i += 1", "+ else:", "+ i += 1", "- break", "- find = False" ]
false
0.043383
0.037613
1.153386
[ "s489670743", "s617562011" ]
u067227603
p03767
python
s320167267
s816628527
246
215
37,084
39,492
Accepted
Accepted
12.6
n=int(eval(input())) a=list([int(x) for x in input().split()]) a.sort(reverse=True) print((sum(a[1:2*n:2])))
n=int(eval(input())) a=list(map(int, input().split())) a.sort(reverse=True) print((sum(a[1:2*n:2])))
4
4
108
95
n = int(eval(input())) a = list([int(x) for x in input().split()]) a.sort(reverse=True) print((sum(a[1 : 2 * n : 2])))
n = int(eval(input())) a = list(map(int, input().split())) a.sort(reverse=True) print((sum(a[1 : 2 * n : 2])))
false
0
[ "-a = list([int(x) for x in input().split()])", "+a = list(map(int, input().split()))" ]
false
0.035114
0.045564
0.770642
[ "s320167267", "s816628527" ]
u968166680
p02572
python
s575812416
s482548896
140
120
110,556
110,560
Accepted
Accepted
14.29
import sys from itertools import accumulate read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, *A = list(map(int, read().split())) total = sum(A) ans = 0 for a in A: total -= a ans = (ans + a * total % MOD) % MOD print(ans) return if __name__ == '__main__': main()
import sys from itertools import accumulate read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 def main(): N, *A = list(map(int, read().split())) total = sum(A) % MOD ans = total * total % MOD for a in A: ans = (ans - a * a) % MOD ans = ans * pow(2, MOD - 2, MOD) % MOD print(ans) return if __name__ == '__main__': main()
27
28
447
487
import sys from itertools import accumulate read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N, *A = list(map(int, read().split())) total = sum(A) ans = 0 for a in A: total -= a ans = (ans + a * total % MOD) % MOD print(ans) return if __name__ == "__main__": main()
import sys from itertools import accumulate read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines sys.setrecursionlimit(10**9) INF = 1 << 60 MOD = 1000000007 def main(): N, *A = list(map(int, read().split())) total = sum(A) % MOD ans = total * total % MOD for a in A: ans = (ans - a * a) % MOD ans = ans * pow(2, MOD - 2, MOD) % MOD print(ans) return if __name__ == "__main__": main()
false
3.571429
[ "- total = sum(A)", "- ans = 0", "+ total = sum(A) % MOD", "+ ans = total * total % MOD", "- total -= a", "- ans = (ans + a * total % MOD) % MOD", "+ ans = (ans - a * a) % MOD", "+ ans = ans * pow(2, MOD - 2, MOD) % MOD" ]
false
0.047167
0.146969
0.320931
[ "s575812416", "s482548896" ]
u535803878
p02579
python
s713402137
s982640752
1,424
816
124,192
117,740
Accepted
Accepted
42.7
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") import numpy as np from numba import njit, b1, i4, i8, f8 from heapq import heappop as hpp, heappush as hp @njit((b1[:, :],i8,i8,i8,i8)) def main(ss,ch,cw,dh,dw): inf = 1<<30 h,w = ss.shape start = ch*w+cw goal = dh*w+dw n = h*w seen = np.full(n, inf, np.int64) seen[start] = 0 q = [(0, start)] # ワープ回数, 現在位置, 最後の道の位置 while q: pnum,pu = hpp(q) ux,uy = divmod(pu,w) if pu==goal: break for xx in range(-2, 3): for yy in range(-2, 3): if xx==yy==0: continue if abs(xx)+abs(yy)<=1: vv = 0 else: vv = 1 x,y = ux+xx, uy+yy u = x*w + y num = pnum+vv if x<0 or y<0 or x>=h or y>=w or ss[x][y]: continue # print(x,y) if seen[u]>num: seen[u] = num hp(q,(num, u)) val = seen[goal] if val==inf: return -1 else: return val h,w = list(map(int, input().split())) ch,cw = list(map(int, input().split())) dh,dw = list(map(int, input().split())) ch -= 1 cw -= 1 dh -= 1 dw -= 1 rows,cols = h,w OK = "." NG = "#" ss = np.array([[c=="#" for c in eval(input())] for _ in range(h)]) print((main(ss,ch,cw,dh,dw)))
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") import numpy as np from numba import njit, b1, i4, i8, f8 from heapq import heappop as hpp, heappush as hp @njit((b1[:, :],i8,i8,i8,i8), cache=True) def main(ss,ch,cw,dh,dw): inf = 1<<30 h,w = ss.shape start = ch*w+cw goal = dh*w+dw n = h*w seen = np.full(n, inf, np.int64) seen[start] = 0 q = [(0, start)] # ワープ回数, 現在位置, 最後の道の位置 while q: pnum,pu = hpp(q) ux,uy = divmod(pu,w) if pu==goal: break for xx in range(-2, 3): for yy in range(-2, 3): if xx==yy==0: continue if abs(xx)+abs(yy)<=1: vv = 0 else: vv = 1 x,y = ux+xx, uy+yy u = x*w + y num = pnum+vv if x<0 or y<0 or x>=h or y>=w or ss[x][y]: continue # print(x,y) if seen[u]>num: seen[u] = num hp(q,(num, u)) val = seen[goal] if val==inf: return -1 else: return val h,w = list(map(int, input().split())) ch,cw = list(map(int, input().split())) dh,dw = list(map(int, input().split())) ch -= 1 cw -= 1 dh -= 1 dw -= 1 rows,cols = h,w OK = "." NG = "#" ss = np.array([[c=="#" for c in eval(input())] for _ in range(h)]) print((main(ss,ch,cw,dh,dw)))
63
63
1,574
1,586
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x + "\n") import numpy as np from numba import njit, b1, i4, i8, f8 from heapq import heappop as hpp, heappush as hp @njit((b1[:, :], i8, i8, i8, i8)) def main(ss, ch, cw, dh, dw): inf = 1 << 30 h, w = ss.shape start = ch * w + cw goal = dh * w + dw n = h * w seen = np.full(n, inf, np.int64) seen[start] = 0 q = [(0, start)] # ワープ回数, 現在位置, 最後の道の位置 while q: pnum, pu = hpp(q) ux, uy = divmod(pu, w) if pu == goal: break for xx in range(-2, 3): for yy in range(-2, 3): if xx == yy == 0: continue if abs(xx) + abs(yy) <= 1: vv = 0 else: vv = 1 x, y = ux + xx, uy + yy u = x * w + y num = pnum + vv if x < 0 or y < 0 or x >= h or y >= w or ss[x][y]: continue # print(x,y) if seen[u] > num: seen[u] = num hp(q, (num, u)) val = seen[goal] if val == inf: return -1 else: return val h, w = list(map(int, input().split())) ch, cw = list(map(int, input().split())) dh, dw = list(map(int, input().split())) ch -= 1 cw -= 1 dh -= 1 dw -= 1 rows, cols = h, w OK = "." NG = "#" ss = np.array([[c == "#" for c in eval(input())] for _ in range(h)]) print((main(ss, ch, cw, dh, dw)))
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x + "\n") import numpy as np from numba import njit, b1, i4, i8, f8 from heapq import heappop as hpp, heappush as hp @njit((b1[:, :], i8, i8, i8, i8), cache=True) def main(ss, ch, cw, dh, dw): inf = 1 << 30 h, w = ss.shape start = ch * w + cw goal = dh * w + dw n = h * w seen = np.full(n, inf, np.int64) seen[start] = 0 q = [(0, start)] # ワープ回数, 現在位置, 最後の道の位置 while q: pnum, pu = hpp(q) ux, uy = divmod(pu, w) if pu == goal: break for xx in range(-2, 3): for yy in range(-2, 3): if xx == yy == 0: continue if abs(xx) + abs(yy) <= 1: vv = 0 else: vv = 1 x, y = ux + xx, uy + yy u = x * w + y num = pnum + vv if x < 0 or y < 0 or x >= h or y >= w or ss[x][y]: continue # print(x,y) if seen[u] > num: seen[u] = num hp(q, (num, u)) val = seen[goal] if val == inf: return -1 else: return val h, w = list(map(int, input().split())) ch, cw = list(map(int, input().split())) dh, dw = list(map(int, input().split())) ch -= 1 cw -= 1 dh -= 1 dw -= 1 rows, cols = h, w OK = "." NG = "#" ss = np.array([[c == "#" for c in eval(input())] for _ in range(h)]) print((main(ss, ch, cw, dh, dw)))
false
0
[ "-@njit((b1[:, :], i8, i8, i8, i8))", "+@njit((b1[:, :], i8, i8, i8, i8), cache=True)" ]
false
0.179635
0.353526
0.508123
[ "s713402137", "s982640752" ]
u813450984
p03945
python
s377694382
s861705745
50
41
3,956
3,956
Accepted
Accepted
18
l = list(eval(input())) now = l[0] count = 0 for i in range(1, len(l)): if not now == l[i]: count += 1 now = l[i] print(count)
l = list(eval(input())) now = l[0] count = 0 for i in range(1, len(l)): if not l[i] == now: count += 1 now = l[i] print(count)
10
9
141
139
l = list(eval(input())) now = l[0] count = 0 for i in range(1, len(l)): if not now == l[i]: count += 1 now = l[i] print(count)
l = list(eval(input())) now = l[0] count = 0 for i in range(1, len(l)): if not l[i] == now: count += 1 now = l[i] print(count)
false
10
[ "- if not now == l[i]:", "+ if not l[i] == now:" ]
false
0.049105
0.048778
1.006699
[ "s377694382", "s861705745" ]
u340781749
p02579
python
s533110954
s041723048
838
374
30,532
45,432
Accepted
Accepted
55.37
import os import sys import numpy as np from heapq import heappop, heappush def solve(h, w, s, t, field): WARP = (-(w * 2 + 10), -(w * 2 + 9), -(w * 2 + 8), -(w * 2 + 7), -(w * 2 + 6), -(w + 6), -(w + 5), -(w + 3), -(w + 2), -2, 2, w + 2, w + 3, w + 5, w + 6, w * 2 + 6, w * 2 + 7, w * 2 + 8, w * 2 + 9, w * 2 + 10) WALK = (-(w + 4), -1, 1, w + 4) q = [(0, s)] visited = np.zeros((h + 4) * (w + 4), np.int8) queued = np.zeros((h + 4) * (w + 4), np.int8) queued[s] = 1 while q: cost, v = heappop(q) if v == t: return cost if visited[v]: continue visited[v] = 1 for d in WALK: u = v + d if field[u] or visited[u] or queued[u]: continue queued[u] = 1 heappush(q, (cost, u)) for d in WARP: u = v + d if field[u] or visited[u] or queued[u]: continue heappush(q, (cost + 1, u)) return -1 if sys.argv[-1] == 'ONLINE_JUDGE': from numba.pycc import CC cc = CC('my_module') cc.export('solve', '(i8,i8,i8,i8,i1[:],)')(solve) cc.compile() exit() if os.name == 'posix': # noinspection PyUnresolvedReferences from my_module import solve else: from numba import njit solve = njit('(i8,i8,i8,i8,i1[:],)', cache=True)(solve) print('compiled', file=sys.stderr) h, w = map(int, sys.stdin.readline().split()) ch, cw = map(int, sys.stdin.readline().split()) dh, dw = map(int, sys.stdin.readline().split()) field = np.ones((h + 4) * (w + 4), dtype=np.int8) for i in range(h): line = sys.stdin.readline().strip() field[(i + 2) * (w + 4) + 2:(i + 2) * (w + 4) + w + 2] = list(map('.#'.index, line)) s = (ch + 1) * (w + 4) + cw + 1 t = (dh + 1) * (w + 4) + dw + 1 ans = solve(h, w, s, t, field) print(ans)
import os import sys import numpy as np from heapq import heappop, heappush def solve(h, w, s, t, field): WARP = (-(w * 2 + 10), -(w * 2 + 9), -(w * 2 + 8), -(w * 2 + 7), -(w * 2 + 6), -(w + 6), -(w + 5), -(w + 3), -(w + 2), -2, 2, w + 2, w + 3, w + 5, w + 6, w * 2 + 6, w * 2 + 7, w * 2 + 8, w * 2 + 9, w * 2 + 10) WALK = (-(w + 4), -1, 1, w + 4) qc = np.zeros(2000000, dtype=np.int32) qv = np.zeros(2000000, dtype=np.int32) qv[0] = s l, r = 0, 1 visited = np.zeros((h + 4) * (w + 4), np.int8) queued = np.zeros((h + 4) * (w + 4), np.int8) queued[s] = 1 while l < r: cost = qc[l] v = qv[l] l += 1 if v == t: return cost if visited[v]: continue visited[v] = 1 for d in WALK: u = v + d if field[u] or visited[u] or queued[u]: continue queued[u] = 1 l -= 1 qc[l] = cost qv[l] = u for d in WARP: u = v + d if field[u] or visited[u] or queued[u]: continue qc[r] = cost + 1 qv[r] = u r += 1 return -1 if sys.argv[-1] == 'ONLINE_JUDGE': from numba.pycc import CC cc = CC('my_module') cc.export('solve', '(i8,i8,i8,i8,i1[:],)')(solve) cc.compile() exit() if os.name == 'posix': # noinspection PyUnresolvedReferences from my_module import solve else: from numba import njit solve = njit('(i8,i8,i8,i8,i1[:],)', cache=True)(solve) print('compiled', file=sys.stderr) h, w = map(int, sys.stdin.readline().split()) ch, cw = map(int, sys.stdin.readline().split()) dh, dw = map(int, sys.stdin.readline().split()) field = np.ones((h + 4) * (w + 4), dtype=np.int8) for i in range(h): line = sys.stdin.readline().strip() field[(i + 2) * (w + 4) + 2:(i + 2) * (w + 4) + w + 2] = list(map('.#'.index, line)) s = (ch + 1) * (w + 4) + cw + 1 t = (dh + 1) * (w + 4) + dw + 1 ans = solve(h, w, s, t, field) print(ans)
69
78
1,976
2,175
import os import sys import numpy as np from heapq import heappop, heappush def solve(h, w, s, t, field): WARP = ( -(w * 2 + 10), -(w * 2 + 9), -(w * 2 + 8), -(w * 2 + 7), -(w * 2 + 6), -(w + 6), -(w + 5), -(w + 3), -(w + 2), -2, 2, w + 2, w + 3, w + 5, w + 6, w * 2 + 6, w * 2 + 7, w * 2 + 8, w * 2 + 9, w * 2 + 10, ) WALK = (-(w + 4), -1, 1, w + 4) q = [(0, s)] visited = np.zeros((h + 4) * (w + 4), np.int8) queued = np.zeros((h + 4) * (w + 4), np.int8) queued[s] = 1 while q: cost, v = heappop(q) if v == t: return cost if visited[v]: continue visited[v] = 1 for d in WALK: u = v + d if field[u] or visited[u] or queued[u]: continue queued[u] = 1 heappush(q, (cost, u)) for d in WARP: u = v + d if field[u] or visited[u] or queued[u]: continue heappush(q, (cost + 1, u)) return -1 if sys.argv[-1] == "ONLINE_JUDGE": from numba.pycc import CC cc = CC("my_module") cc.export("solve", "(i8,i8,i8,i8,i1[:],)")(solve) cc.compile() exit() if os.name == "posix": # noinspection PyUnresolvedReferences from my_module import solve else: from numba import njit solve = njit("(i8,i8,i8,i8,i1[:],)", cache=True)(solve) print("compiled", file=sys.stderr) h, w = map(int, sys.stdin.readline().split()) ch, cw = map(int, sys.stdin.readline().split()) dh, dw = map(int, sys.stdin.readline().split()) field = np.ones((h + 4) * (w + 4), dtype=np.int8) for i in range(h): line = sys.stdin.readline().strip() field[(i + 2) * (w + 4) + 2 : (i + 2) * (w + 4) + w + 2] = list( map(".#".index, line) ) s = (ch + 1) * (w + 4) + cw + 1 t = (dh + 1) * (w + 4) + dw + 1 ans = solve(h, w, s, t, field) print(ans)
import os import sys import numpy as np from heapq import heappop, heappush def solve(h, w, s, t, field): WARP = ( -(w * 2 + 10), -(w * 2 + 9), -(w * 2 + 8), -(w * 2 + 7), -(w * 2 + 6), -(w + 6), -(w + 5), -(w + 3), -(w + 2), -2, 2, w + 2, w + 3, w + 5, w + 6, w * 2 + 6, w * 2 + 7, w * 2 + 8, w * 2 + 9, w * 2 + 10, ) WALK = (-(w + 4), -1, 1, w + 4) qc = np.zeros(2000000, dtype=np.int32) qv = np.zeros(2000000, dtype=np.int32) qv[0] = s l, r = 0, 1 visited = np.zeros((h + 4) * (w + 4), np.int8) queued = np.zeros((h + 4) * (w + 4), np.int8) queued[s] = 1 while l < r: cost = qc[l] v = qv[l] l += 1 if v == t: return cost if visited[v]: continue visited[v] = 1 for d in WALK: u = v + d if field[u] or visited[u] or queued[u]: continue queued[u] = 1 l -= 1 qc[l] = cost qv[l] = u for d in WARP: u = v + d if field[u] or visited[u] or queued[u]: continue qc[r] = cost + 1 qv[r] = u r += 1 return -1 if sys.argv[-1] == "ONLINE_JUDGE": from numba.pycc import CC cc = CC("my_module") cc.export("solve", "(i8,i8,i8,i8,i1[:],)")(solve) cc.compile() exit() if os.name == "posix": # noinspection PyUnresolvedReferences from my_module import solve else: from numba import njit solve = njit("(i8,i8,i8,i8,i1[:],)", cache=True)(solve) print("compiled", file=sys.stderr) h, w = map(int, sys.stdin.readline().split()) ch, cw = map(int, sys.stdin.readline().split()) dh, dw = map(int, sys.stdin.readline().split()) field = np.ones((h + 4) * (w + 4), dtype=np.int8) for i in range(h): line = sys.stdin.readline().strip() field[(i + 2) * (w + 4) + 2 : (i + 2) * (w + 4) + w + 2] = list( map(".#".index, line) ) s = (ch + 1) * (w + 4) + cw + 1 t = (dh + 1) * (w + 4) + dw + 1 ans = solve(h, w, s, t, field) print(ans)
false
11.538462
[ "- q = [(0, s)]", "+ qc = np.zeros(2000000, dtype=np.int32)", "+ qv = np.zeros(2000000, dtype=np.int32)", "+ qv[0] = s", "+ l, r = 0, 1", "- while q:", "- cost, v = heappop(q)", "+ while l < r:", "+ cost = qc[l]", "+ v = qv[l]", "+ l += 1", "- heappush(q, (cost, u))", "+ l -= 1", "+ qc[l] = cost", "+ qv[l] = u", "- heappush(q, (cost + 1, u))", "+ qc[r] = cost + 1", "+ qv[r] = u", "+ r += 1" ]
false
0.199516
0.327693
0.608851
[ "s533110954", "s041723048" ]
u030879708
p02658
python
s923407499
s298146584
398
78
19,180
19,256
Accepted
Accepted
80.4
eval(input());a=1 for i in input().split():a*=int(i);a=[-1,a][0<=a<=eval('1'+'0'*18)] print(a)
eval(input());a=1 for i in input().split():a*=int(i);a=[-1,a][0<=a<=10**18] print(a)
3
3
90
80
eval(input()) a = 1 for i in input().split(): a *= int(i) a = [-1, a][0 <= a <= eval("1" + "0" * 18)] print(a)
eval(input()) a = 1 for i in input().split(): a *= int(i) a = [-1, a][0 <= a <= 10**18] print(a)
false
0
[ "- a = [-1, a][0 <= a <= eval(\"1\" + \"0\" * 18)]", "+ a = [-1, a][0 <= a <= 10**18]" ]
false
0.094842
0.035838
2.646407
[ "s923407499", "s298146584" ]
u130900604
p03611
python
s503150959
s850925059
323
192
78,776
109,436
Accepted
Accepted
40.56
n=int(eval(input())) a=list(map(int,input().split())) ans=[] for i in a: ans+=(i-1), ans+=(i), ans+=(i+1), from collections import* c=Counter(ans) res=c.most_common()[0][1] print(res)
n,*a=list(map(int,open(0).read().split())) b=[q-1 for q in a] c=[q+1 for q in a] from collections import Counter d=a+b+c e=Counter(d) print((e.most_common()[0][1]))
14
7
201
162
n = int(eval(input())) a = list(map(int, input().split())) ans = [] for i in a: ans += ((i - 1),) ans += ((i),) ans += ((i + 1),) from collections import * c = Counter(ans) res = c.most_common()[0][1] print(res)
n, *a = list(map(int, open(0).read().split())) b = [q - 1 for q in a] c = [q + 1 for q in a] from collections import Counter d = a + b + c e = Counter(d) print((e.most_common()[0][1]))
false
50
[ "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-ans = []", "-for i in a:", "- ans += ((i - 1),)", "- ans += ((i),)", "- ans += ((i + 1),)", "-from collections import *", "+n, *a = list(map(int, open(0).read().split()))", "+b = [q - 1 for q in a]", "+c = [q + 1 for q in a]", "+from collections import Counter", "-c = Counter(ans)", "-res = c.most_common()[0][1]", "-print(res)", "+d = a + b + c", "+e = Counter(d)", "+print((e.most_common()[0][1]))" ]
false
0.045099
0.09062
0.497673
[ "s503150959", "s850925059" ]
u314050667
p02924
python
s049659866
s338291327
20
18
2,940
2,940
Accepted
Accepted
10
N = int(eval(input())) tmp = (1+N) * N // 2 ans = tmp-N print(ans)
N = int(eval(input())) ans = (1+N)*N//2 - N print(ans)
6
3
67
50
N = int(eval(input())) tmp = (1 + N) * N // 2 ans = tmp - N print(ans)
N = int(eval(input())) ans = (1 + N) * N // 2 - N print(ans)
false
50
[ "-tmp = (1 + N) * N // 2", "-ans = tmp - N", "+ans = (1 + N) * N // 2 - N" ]
false
0.044723
0.045542
0.982021
[ "s049659866", "s338291327" ]
u131811591
p02329
python
s844874803
s481401574
1,040
900
179,200
179,068
Accepted
Accepted
13.46
import sys from collections import defaultdict if __name__ == '__main__': n, v = list(map(int, sys.stdin.readline().split())) a = tuple(map(int, sys.stdin.readline().split())) b = tuple(map(int, sys.stdin.readline().split())) c = tuple(map(int, sys.stdin.readline().split())) d = tuple(map(int, sys.stdin.readline().split())) mp = defaultdict(int) for val1 in c: for val2 in d: mp[val1+val2] += 1 print((sum(mp[v-val1-val2] for val1 in a for val2 in b)))
import sys from collections import defaultdict def main(): n, v = list(map(int, sys.stdin.readline().split())) a = tuple(map(int, sys.stdin.readline().split())) b = tuple(map(int, sys.stdin.readline().split())) c = tuple(map(int, sys.stdin.readline().split())) d = tuple(map(int, sys.stdin.readline().split())) mp = defaultdict(int) for val1 in c: for val2 in d: mp[val1 + val2] += 1 print((sum(mp[v - val1 - val2] for val1 in a for val2 in b))) if __name__ == '__main__': main()
15
19
515
550
import sys from collections import defaultdict if __name__ == "__main__": n, v = list(map(int, sys.stdin.readline().split())) a = tuple(map(int, sys.stdin.readline().split())) b = tuple(map(int, sys.stdin.readline().split())) c = tuple(map(int, sys.stdin.readline().split())) d = tuple(map(int, sys.stdin.readline().split())) mp = defaultdict(int) for val1 in c: for val2 in d: mp[val1 + val2] += 1 print((sum(mp[v - val1 - val2] for val1 in a for val2 in b)))
import sys from collections import defaultdict def main(): n, v = list(map(int, sys.stdin.readline().split())) a = tuple(map(int, sys.stdin.readline().split())) b = tuple(map(int, sys.stdin.readline().split())) c = tuple(map(int, sys.stdin.readline().split())) d = tuple(map(int, sys.stdin.readline().split())) mp = defaultdict(int) for val1 in c: for val2 in d: mp[val1 + val2] += 1 print((sum(mp[v - val1 - val2] for val1 in a for val2 in b))) if __name__ == "__main__": main()
false
21.052632
[ "-if __name__ == \"__main__\":", "+", "+def main():", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.037632
0.041718
0.90206
[ "s844874803", "s481401574" ]
u690536347
p02902
python
s101055591
s156379538
419
340
51,404
45,788
Accepted
Accepted
18.85
from collections import deque N, M = list(map(int, input().split())) d = {i:[] for i in range(1, N+1)} l = [] INF = 10**12 v = INF for _ in range(M): A, B = list(map(int, input().split())) d[A].append(B) l.append((A, B)) ans = [] for i, j in l: INF = 10**12 dist = [-1]*(N+1) prev = [-1]*(N+1) dist[j] = 0 prev[j] = 0 q = deque([j]) while q: a = q.popleft() for b in d[a]: if dist[b]==-1: dist[b] = dist[a]+1 prev[b] = a q.append(b) if v>dist[i]+1 and dist[i]!=-1: v = dist[i]+1 buf = i ans = [] while buf!=0: ans.append(buf) buf = prev[buf] if ans: print((len(ans))) for i in ans: print(i) else: print((-1))
from collections import deque import sys input=sys.stdin.readline def solve(): N, M = list(map(int, input().split())) d = {i:[] for i in range(1, N+1)} l = [] INF = 10**12 v = INF for _ in range(M): A, B = list(map(int, input().split())) d[A].append(B) l.append((A, B)) ans = [] for i, j in l: INF = 10**12 dist = [-1]*(N+1) prev = [-1]*(N+1) dist[j] = 0 prev[j] = 0 q = deque([j]) while q: a = q.popleft() for b in d[a]: if dist[b]==-1: dist[b] = dist[a]+1 prev[b] = a q.append(b) if v>dist[i]+1 and dist[i]!=-1: v = dist[i]+1 buf = i ans = [] while buf: ans.append(buf) buf = prev[buf] if ans: print((len(ans))) for i in ans: print(i) else: print((-1)) if __name__ == "__main__": solve()
44
52
838
1,082
from collections import deque N, M = list(map(int, input().split())) d = {i: [] for i in range(1, N + 1)} l = [] INF = 10**12 v = INF for _ in range(M): A, B = list(map(int, input().split())) d[A].append(B) l.append((A, B)) ans = [] for i, j in l: INF = 10**12 dist = [-1] * (N + 1) prev = [-1] * (N + 1) dist[j] = 0 prev[j] = 0 q = deque([j]) while q: a = q.popleft() for b in d[a]: if dist[b] == -1: dist[b] = dist[a] + 1 prev[b] = a q.append(b) if v > dist[i] + 1 and dist[i] != -1: v = dist[i] + 1 buf = i ans = [] while buf != 0: ans.append(buf) buf = prev[buf] if ans: print((len(ans))) for i in ans: print(i) else: print((-1))
from collections import deque import sys input = sys.stdin.readline def solve(): N, M = list(map(int, input().split())) d = {i: [] for i in range(1, N + 1)} l = [] INF = 10**12 v = INF for _ in range(M): A, B = list(map(int, input().split())) d[A].append(B) l.append((A, B)) ans = [] for i, j in l: INF = 10**12 dist = [-1] * (N + 1) prev = [-1] * (N + 1) dist[j] = 0 prev[j] = 0 q = deque([j]) while q: a = q.popleft() for b in d[a]: if dist[b] == -1: dist[b] = dist[a] + 1 prev[b] = a q.append(b) if v > dist[i] + 1 and dist[i] != -1: v = dist[i] + 1 buf = i ans = [] while buf: ans.append(buf) buf = prev[buf] if ans: print((len(ans))) for i in ans: print(i) else: print((-1)) if __name__ == "__main__": solve()
false
15.384615
[ "+import sys", "-N, M = list(map(int, input().split()))", "-d = {i: [] for i in range(1, N + 1)}", "-l = []", "-INF = 10**12", "-v = INF", "-for _ in range(M):", "- A, B = list(map(int, input().split()))", "- d[A].append(B)", "- l.append((A, B))", "-ans = []", "-for i, j in l:", "+input = sys.stdin.readline", "+", "+", "+def solve():", "+ N, M = list(map(int, input().split()))", "+ d = {i: [] for i in range(1, N + 1)}", "+ l = []", "- dist = [-1] * (N + 1)", "- prev = [-1] * (N + 1)", "- dist[j] = 0", "- prev[j] = 0", "- q = deque([j])", "- while q:", "- a = q.popleft()", "- for b in d[a]:", "- if dist[b] == -1:", "- dist[b] = dist[a] + 1", "- prev[b] = a", "- q.append(b)", "- if v > dist[i] + 1 and dist[i] != -1:", "- v = dist[i] + 1", "- buf = i", "- ans = []", "- while buf != 0:", "- ans.append(buf)", "- buf = prev[buf]", "-if ans:", "- print((len(ans)))", "- for i in ans:", "- print(i)", "-else:", "- print((-1))", "+ v = INF", "+ for _ in range(M):", "+ A, B = list(map(int, input().split()))", "+ d[A].append(B)", "+ l.append((A, B))", "+ ans = []", "+ for i, j in l:", "+ INF = 10**12", "+ dist = [-1] * (N + 1)", "+ prev = [-1] * (N + 1)", "+ dist[j] = 0", "+ prev[j] = 0", "+ q = deque([j])", "+ while q:", "+ a = q.popleft()", "+ for b in d[a]:", "+ if dist[b] == -1:", "+ dist[b] = dist[a] + 1", "+ prev[b] = a", "+ q.append(b)", "+ if v > dist[i] + 1 and dist[i] != -1:", "+ v = dist[i] + 1", "+ buf = i", "+ ans = []", "+ while buf:", "+ ans.append(buf)", "+ buf = prev[buf]", "+ if ans:", "+ print((len(ans)))", "+ for i in ans:", "+ print(i)", "+ else:", "+ print((-1))", "+", "+", "+if __name__ == \"__main__\":", "+ solve()" ]
false
0.04512
0.045119
1.000026
[ "s101055591", "s156379538" ]
u170183831
p02971
python
s643364407
s335093262
480
314
15,636
20,140
Accepted
Accepted
34.58
n = int(input()) A = [int(input()) for _ in range(n)] first = 0 second = 1 if A[first] < A[second]: first, second = second, first for i in range(2, n): if A[first] < A[i]: second = first first = i elif A[second] < A[i]: second = i print(*[A[first] if i != first else A[second] for i in range(n)], sep='\n')
import heapq n = int(input()) A = [int(input()) for _ in range(n)] m1, m2 = heapq.nlargest(2, A) print(*[m2 if a == m1 else m1 for a in A], sep='\n')
15
6
359
155
n = int(input()) A = [int(input()) for _ in range(n)] first = 0 second = 1 if A[first] < A[second]: first, second = second, first for i in range(2, n): if A[first] < A[i]: second = first first = i elif A[second] < A[i]: second = i print(*[A[first] if i != first else A[second] for i in range(n)], sep="\n")
import heapq n = int(input()) A = [int(input()) for _ in range(n)] m1, m2 = heapq.nlargest(2, A) print(*[m2 if a == m1 else m1 for a in A], sep="\n")
false
60
[ "+import heapq", "+", "-first = 0", "-second = 1", "-if A[first] < A[second]:", "- first, second = second, first", "-for i in range(2, n):", "- if A[first] < A[i]:", "- second = first", "- first = i", "- elif A[second] < A[i]:", "- second = i", "-print(*[A[first] if i != first else A[second] for i in range(n)], sep=\"\\n\")", "+m1, m2 = heapq.nlargest(2, A)", "+print(*[m2 if a == m1 else m1 for a in A], sep=\"\\n\")" ]
false
0.075689
0.102024
0.741874
[ "s643364407", "s335093262" ]
u883040023
p03011
python
s485240626
s543859115
24
17
2,940
2,940
Accepted
Accepted
29.17
P , Q , R = list(map(int, input().split())) if P >= Q and P >= R: print((Q + R)) elif Q >= P and Q >= R: print((P + R)) else: print((P + Q))
P , Q , R = list(map( int , input().split())) distance = [P+Q , Q+R , R+P] print((min(distance)))
8
5
148
95
P, Q, R = list(map(int, input().split())) if P >= Q and P >= R: print((Q + R)) elif Q >= P and Q >= R: print((P + R)) else: print((P + Q))
P, Q, R = list(map(int, input().split())) distance = [P + Q, Q + R, R + P] print((min(distance)))
false
37.5
[ "-if P >= Q and P >= R:", "- print((Q + R))", "-elif Q >= P and Q >= R:", "- print((P + R))", "-else:", "- print((P + Q))", "+distance = [P + Q, Q + R, R + P]", "+print((min(distance)))" ]
false
0.037601
0.043198
0.870442
[ "s485240626", "s543859115" ]
u312025627
p03229
python
s085632199
s921321968
804
608
61,448
58,840
Accepted
Accepted
24.38
def main(): N = int(eval(input())) A = [int(eval(input())) for i in range(N)] A.sort() from collections import deque def make1(): d = deque(A) ret = deque([d.popleft()]) for i in range((N-1)//2): if i & 1: j = d.popleft() k = d.popleft() else: j = d.pop() k = d.pop() if abs(ret[0] - j) < abs(ret[-1] - j): ret.appendleft(j) ret.append(k) else: ret.append(j) ret.appendleft(k) if len(d) == 1: j = d.pop() if abs(ret[0] - j) < abs(ret[-1] - j): ret.append(j) else: ret.appendleft(j) ans = 0 for i in range(1, N): ans += abs(ret[i-1] - ret[i]) return ans def make2(): d = deque(A) ret = deque([d.pop()]) for i in range((N-1)//2): if i & 1: j = d.pop() k = d.pop() else: j = d.popleft() k = d.popleft() if abs(ret[0] - j) < abs(ret[-1] - j): ret.appendleft(j) ret.append(k) else: ret.append(j) ret.appendleft(k) if len(d) == 1: j = d.pop() if abs(ret[0] - j) < abs(ret[-1] - j): ret.append(j) else: ret.appendleft(j) ans = 0 for i in range(1, N): ans += abs(ret[i-1] - ret[i]) return ans print((max(make1(), make2()))) if __name__ == '__main__': main()
def main(): N = int(eval(input())) A = [int(eval(input())) for i in range(N)] A.sort() le, ri = A[-1], A[-1] # print(le, ri) from collections import deque A = deque(A[:N-1]) ans = 0 for i in range(N-1): cur = [abs(A[0] - le), abs(A[-1] - ri), abs(A[-1] - le), abs(A[0] - ri)] #print(le, ri, cur) if max(cur) == cur[0]: c = A.popleft() ans += abs(c - le) le = c elif max(cur) == cur[1]: c = A.pop() ans += abs(c - ri) ri = c elif max(cur) == cur[2]: c = A.pop() ans += abs(c - le) le = c else: c = A.popleft() ans += abs(c - ri) ri = c print(ans) if __name__ == '__main__': main()
65
34
1,761
854
def main(): N = int(eval(input())) A = [int(eval(input())) for i in range(N)] A.sort() from collections import deque def make1(): d = deque(A) ret = deque([d.popleft()]) for i in range((N - 1) // 2): if i & 1: j = d.popleft() k = d.popleft() else: j = d.pop() k = d.pop() if abs(ret[0] - j) < abs(ret[-1] - j): ret.appendleft(j) ret.append(k) else: ret.append(j) ret.appendleft(k) if len(d) == 1: j = d.pop() if abs(ret[0] - j) < abs(ret[-1] - j): ret.append(j) else: ret.appendleft(j) ans = 0 for i in range(1, N): ans += abs(ret[i - 1] - ret[i]) return ans def make2(): d = deque(A) ret = deque([d.pop()]) for i in range((N - 1) // 2): if i & 1: j = d.pop() k = d.pop() else: j = d.popleft() k = d.popleft() if abs(ret[0] - j) < abs(ret[-1] - j): ret.appendleft(j) ret.append(k) else: ret.append(j) ret.appendleft(k) if len(d) == 1: j = d.pop() if abs(ret[0] - j) < abs(ret[-1] - j): ret.append(j) else: ret.appendleft(j) ans = 0 for i in range(1, N): ans += abs(ret[i - 1] - ret[i]) return ans print((max(make1(), make2()))) if __name__ == "__main__": main()
def main(): N = int(eval(input())) A = [int(eval(input())) for i in range(N)] A.sort() le, ri = A[-1], A[-1] # print(le, ri) from collections import deque A = deque(A[: N - 1]) ans = 0 for i in range(N - 1): cur = [abs(A[0] - le), abs(A[-1] - ri), abs(A[-1] - le), abs(A[0] - ri)] # print(le, ri, cur) if max(cur) == cur[0]: c = A.popleft() ans += abs(c - le) le = c elif max(cur) == cur[1]: c = A.pop() ans += abs(c - ri) ri = c elif max(cur) == cur[2]: c = A.pop() ans += abs(c - le) le = c else: c = A.popleft() ans += abs(c - ri) ri = c print(ans) if __name__ == "__main__": main()
false
47.692308
[ "+ le, ri = A[-1], A[-1]", "+ # print(le, ri)", "- def make1():", "- d = deque(A)", "- ret = deque([d.popleft()])", "- for i in range((N - 1) // 2):", "- if i & 1:", "- j = d.popleft()", "- k = d.popleft()", "- else:", "- j = d.pop()", "- k = d.pop()", "- if abs(ret[0] - j) < abs(ret[-1] - j):", "- ret.appendleft(j)", "- ret.append(k)", "- else:", "- ret.append(j)", "- ret.appendleft(k)", "- if len(d) == 1:", "- j = d.pop()", "- if abs(ret[0] - j) < abs(ret[-1] - j):", "- ret.append(j)", "- else:", "- ret.appendleft(j)", "- ans = 0", "- for i in range(1, N):", "- ans += abs(ret[i - 1] - ret[i])", "- return ans", "-", "- def make2():", "- d = deque(A)", "- ret = deque([d.pop()])", "- for i in range((N - 1) // 2):", "- if i & 1:", "- j = d.pop()", "- k = d.pop()", "- else:", "- j = d.popleft()", "- k = d.popleft()", "- if abs(ret[0] - j) < abs(ret[-1] - j):", "- ret.appendleft(j)", "- ret.append(k)", "- else:", "- ret.append(j)", "- ret.appendleft(k)", "- if len(d) == 1:", "- j = d.pop()", "- if abs(ret[0] - j) < abs(ret[-1] - j):", "- ret.append(j)", "- else:", "- ret.appendleft(j)", "- ans = 0", "- for i in range(1, N):", "- ans += abs(ret[i - 1] - ret[i])", "- return ans", "-", "- print((max(make1(), make2())))", "+ A = deque(A[: N - 1])", "+ ans = 0", "+ for i in range(N - 1):", "+ cur = [abs(A[0] - le), abs(A[-1] - ri), abs(A[-1] - le), abs(A[0] - ri)]", "+ # print(le, ri, cur)", "+ if max(cur) == cur[0]:", "+ c = A.popleft()", "+ ans += abs(c - le)", "+ le = c", "+ elif max(cur) == cur[1]:", "+ c = A.pop()", "+ ans += abs(c - ri)", "+ ri = c", "+ elif max(cur) == cur[2]:", "+ c = A.pop()", "+ ans += abs(c - le)", "+ le = c", "+ else:", "+ c = A.popleft()", "+ ans += abs(c - ri)", "+ ri = c", "+ print(ans)" ]
false
0.041287
0.042031
0.982293
[ "s085632199", "s921321968" ]
u984276646
p04046
python
s150935219
s773831563
1,808
308
15,036
34,712
Accepted
Accepted
82.96
H, W, A, B = list(map(int, input().split())) mod = int(1e+9 + 7) p = mod - 2 X, Y = H-A, W-B L = [] while p != 0: L = [p%2] + L[:] p //= 2 S = 0 fL = [1] invfL = [] for i in range(H+W): fL.append(((i+1)*fL[i])%mod) for i in range(H): invi = 1 for j in range(len(L)): if L[j] == 1: invi *= fL[i] invi %= mod if j != len(L)-1: invi *= invi invi %= mod invfL.append(invi) invB = 1 invW = 1 for i in range(len(L)): if L[i] == 1: invB *= fL[B-1] invB %= mod invW *= fL[W-B-1] invW %= mod if i != len(L)-1: invB *= invB invB %= mod invW *= invW invW %= mod for i in range(X): S += (fL[i+B-1]*fL[H+Y-i-2]*invfL[i]*invfL[H-i-1])%mod S %= mod print(((S*invB*invW)%mod))
H, W, A, B = list(map(int, input().split())) mod = int(1e9) + 7 def inved(a): x, y, u, v, k, l = 1, 0, 0, 1, a, mod while l != 0: x, y, u, v = u, v, x - u * (k // l), y - v * (k // l) k, l = l, k % l return x % mod fact = [1 for _ in range(H+W+A+B+1)] invf = [1 for _ in range(H+W+A+B+1)] for i in range(H+W+A+B): fact[i+1] = (fact[i] * (i + 1)) % mod invf[-1] = inved(fact[-1]) for i in range(H+W+A+B, 0, -1): invf[i-1] = (invf[i] * i) % mod S = 0 for i in range(H-A): S += (fact[i+B-1] * invf[i] * fact[H-i+W-B-2] * invf[H-1-i]) % mod S %= mod S *= (invf[B-1] * invf[W-B-1]) % mod S %= mod print(S)
40
23
775
639
H, W, A, B = list(map(int, input().split())) mod = int(1e9 + 7) p = mod - 2 X, Y = H - A, W - B L = [] while p != 0: L = [p % 2] + L[:] p //= 2 S = 0 fL = [1] invfL = [] for i in range(H + W): fL.append(((i + 1) * fL[i]) % mod) for i in range(H): invi = 1 for j in range(len(L)): if L[j] == 1: invi *= fL[i] invi %= mod if j != len(L) - 1: invi *= invi invi %= mod invfL.append(invi) invB = 1 invW = 1 for i in range(len(L)): if L[i] == 1: invB *= fL[B - 1] invB %= mod invW *= fL[W - B - 1] invW %= mod if i != len(L) - 1: invB *= invB invB %= mod invW *= invW invW %= mod for i in range(X): S += (fL[i + B - 1] * fL[H + Y - i - 2] * invfL[i] * invfL[H - i - 1]) % mod S %= mod print(((S * invB * invW) % mod))
H, W, A, B = list(map(int, input().split())) mod = int(1e9) + 7 def inved(a): x, y, u, v, k, l = 1, 0, 0, 1, a, mod while l != 0: x, y, u, v = u, v, x - u * (k // l), y - v * (k // l) k, l = l, k % l return x % mod fact = [1 for _ in range(H + W + A + B + 1)] invf = [1 for _ in range(H + W + A + B + 1)] for i in range(H + W + A + B): fact[i + 1] = (fact[i] * (i + 1)) % mod invf[-1] = inved(fact[-1]) for i in range(H + W + A + B, 0, -1): invf[i - 1] = (invf[i] * i) % mod S = 0 for i in range(H - A): S += (fact[i + B - 1] * invf[i] * fact[H - i + W - B - 2] * invf[H - 1 - i]) % mod S %= mod S *= (invf[B - 1] * invf[W - B - 1]) % mod S %= mod print(S)
false
42.5
[ "-mod = int(1e9 + 7)", "-p = mod - 2", "-X, Y = H - A, W - B", "-L = []", "-while p != 0:", "- L = [p % 2] + L[:]", "- p //= 2", "+mod = int(1e9) + 7", "+", "+", "+def inved(a):", "+ x, y, u, v, k, l = 1, 0, 0, 1, a, mod", "+ while l != 0:", "+ x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)", "+ k, l = l, k % l", "+ return x % mod", "+", "+", "+fact = [1 for _ in range(H + W + A + B + 1)]", "+invf = [1 for _ in range(H + W + A + B + 1)]", "+for i in range(H + W + A + B):", "+ fact[i + 1] = (fact[i] * (i + 1)) % mod", "+invf[-1] = inved(fact[-1])", "+for i in range(H + W + A + B, 0, -1):", "+ invf[i - 1] = (invf[i] * i) % mod", "-fL = [1]", "-invfL = []", "-for i in range(H + W):", "- fL.append(((i + 1) * fL[i]) % mod)", "-for i in range(H):", "- invi = 1", "- for j in range(len(L)):", "- if L[j] == 1:", "- invi *= fL[i]", "- invi %= mod", "- if j != len(L) - 1:", "- invi *= invi", "- invi %= mod", "- invfL.append(invi)", "-invB = 1", "-invW = 1", "-for i in range(len(L)):", "- if L[i] == 1:", "- invB *= fL[B - 1]", "- invB %= mod", "- invW *= fL[W - B - 1]", "- invW %= mod", "- if i != len(L) - 1:", "- invB *= invB", "- invB %= mod", "- invW *= invW", "- invW %= mod", "-for i in range(X):", "- S += (fL[i + B - 1] * fL[H + Y - i - 2] * invfL[i] * invfL[H - i - 1]) % mod", "+for i in range(H - A):", "+ S += (fact[i + B - 1] * invf[i] * fact[H - i + W - B - 2] * invf[H - 1 - i]) % mod", "-print(((S * invB * invW) % mod))", "+S *= (invf[B - 1] * invf[W - B - 1]) % mod", "+S %= mod", "+print(S)" ]
false
0.073826
0.039814
1.854276
[ "s150935219", "s773831563" ]
u706786134
p02714
python
s682999996
s112306129
1,922
794
9,208
109,644
Accepted
Accepted
58.69
n = int(eval(input())) s = eval(input()) r = g = b = 0 for i in range(n): if s[i] == 'R': r += 1 elif s[i] == 'G': g += 1 else: b += 1 x = 0 for i in range(n): for j in range(i+1, n): k = j + j - i if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]: x += 1 print((r*g*b-x))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np from numba import njit MOD = 10**9 + 7 N = int(readline()) S = np.array(list(read().rstrip()), np.int8) R = np.sum(S == ord('R')) B = np.sum(S == ord('B')) G = np.sum(S == ord('G')) @njit def f(S): N = len(S) ret = 0 for i in range(N): for j in range(i + 1, N): k = j + j - i if k >= N: break if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]: ret += 1 return ret answer = R * B * G - f(S) print(answer)
19
31
357
666
n = int(eval(input())) s = eval(input()) r = g = b = 0 for i in range(n): if s[i] == "R": r += 1 elif s[i] == "G": g += 1 else: b += 1 x = 0 for i in range(n): for j in range(i + 1, n): k = j + j - i if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]: x += 1 print((r * g * b - x))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np from numba import njit MOD = 10**9 + 7 N = int(readline()) S = np.array(list(read().rstrip()), np.int8) R = np.sum(S == ord("R")) B = np.sum(S == ord("B")) G = np.sum(S == ord("G")) @njit def f(S): N = len(S) ret = 0 for i in range(N): for j in range(i + 1, N): k = j + j - i if k >= N: break if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]: ret += 1 return ret answer = R * B * G - f(S) print(answer)
false
38.709677
[ "-n = int(eval(input()))", "-s = eval(input())", "-r = g = b = 0", "-for i in range(n):", "- if s[i] == \"R\":", "- r += 1", "- elif s[i] == \"G\":", "- g += 1", "- else:", "- b += 1", "-x = 0", "-for i in range(n):", "- for j in range(i + 1, n):", "- k = j + j - i", "- if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:", "- x += 1", "-print((r * g * b - x))", "+import sys", "+", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+import numpy as np", "+from numba import njit", "+", "+MOD = 10**9 + 7", "+N = int(readline())", "+S = np.array(list(read().rstrip()), np.int8)", "+R = np.sum(S == ord(\"R\"))", "+B = np.sum(S == ord(\"B\"))", "+G = np.sum(S == ord(\"G\"))", "+", "+", "+@njit", "+def f(S):", "+ N = len(S)", "+ ret = 0", "+ for i in range(N):", "+ for j in range(i + 1, N):", "+ k = j + j - i", "+ if k >= N:", "+ break", "+ if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:", "+ ret += 1", "+ return ret", "+", "+", "+answer = R * B * G - f(S)", "+print(answer)" ]
false
0.062212
0.22401
0.277718
[ "s682999996", "s112306129" ]
u974620347
p03160
python
s561613528
s995541354
132
104
13,928
13,976
Accepted
Accepted
21.21
if __name__ == "__main__": N = int(eval(input())) h = [int(n) for n in input().split()] dp = [0] * int(1e5) # dp[i]はiにたどり着くコストの最小値 # dp[0] = 0 # dp[n] = min(dp[n-1] + abs(h[n] - h[n-1]), dp[n-2] + |h[n] - h[n-2]|) dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, N): dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2])) print((dp[N-1]))
def main(): N = int(eval(input())) A = [int(i) for i in input().split()] dp = [-1]*N dp[0] = 0 dp[1] = abs(A[1] - A[0]) for i in range(2,N): dp[i] = min(dp[i-1] + abs(A[i] - A[i-1]), dp[i-2] + abs(A[i] - A[i-2])) print((dp[N-1])) main()
11
10
402
273
if __name__ == "__main__": N = int(eval(input())) h = [int(n) for n in input().split()] dp = [0] * int(1e5) # dp[i]はiにたどり着くコストの最小値 # dp[0] = 0 # dp[n] = min(dp[n-1] + abs(h[n] - h[n-1]), dp[n-2] + |h[n] - h[n-2]|) dp[0] = 0 dp[1] = abs(h[1] - h[0]) for i in range(2, N): dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2])) print((dp[N - 1]))
def main(): N = int(eval(input())) A = [int(i) for i in input().split()] dp = [-1] * N dp[0] = 0 dp[1] = abs(A[1] - A[0]) for i in range(2, N): dp[i] = min(dp[i - 1] + abs(A[i] - A[i - 1]), dp[i - 2] + abs(A[i] - A[i - 2])) print((dp[N - 1])) main()
false
9.090909
[ "-if __name__ == \"__main__\":", "+def main():", "- h = [int(n) for n in input().split()]", "- dp = [0] * int(1e5) # dp[i]はiにたどり着くコストの最小値", "- # dp[0] = 0", "- # dp[n] = min(dp[n-1] + abs(h[n] - h[n-1]), dp[n-2] + |h[n] - h[n-2]|)", "+ A = [int(i) for i in input().split()]", "+ dp = [-1] * N", "- dp[1] = abs(h[1] - h[0])", "+ dp[1] = abs(A[1] - A[0])", "- dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))", "+ dp[i] = min(dp[i - 1] + abs(A[i] - A[i - 1]), dp[i - 2] + abs(A[i] - A[i - 2]))", "+", "+", "+main()" ]
false
0.036178
0.034106
1.060737
[ "s561613528", "s995541354" ]
u297574184
p02850
python
s751455051
s928387096
649
363
77,292
86,524
Accepted
Accepted
44.07
import sys sys.setrecursionlimit(10**9) N = int(eval(input())) adjL = [[] for _ in range(N)] edges = [] for _ in range(N-1): A, B = list(map(int, input().split())) A, B = A-1, B-1 adjL[A].append(B) adjL[B].append(A) edges.append((A, B)) colors = dict() def dfs(vNow, vPar, color): c = 1 for v2 in adjL[vNow]: if v2 == vPar: continue if c == color: c += 1 A, B = vNow, v2 if A > B: A, B = B, A colors[(A, B)] = c dfs(v2, vNow, c) c += 1 dfs(0, -1, 0) #print(colors) anss = [] for A, B in edges: anss.append(colors[(A, B)]) print((max(colors.values()))) print(('\n'.join(map(str, anss))))
import sys input = sys.stdin.readline sys.setrecursionlimit(10**9) def solve(): N = int(eval(input())) adjL = [[] for _ in range(N)] for i in range(N-1): a, b = list(map(int, input().split())) a, b = a-1, b-1 adjL[a].append((b, i)) adjL[b].append((a, i)) def dfs(vNow, vPar, clrPar): clr = 1 for v2, i in adjL[vNow]: if v2 == vPar: continue if clr == clrPar: clr += 1 anss[i] = clr dfs(v2, vNow, clr) clr += 1 anss = [0] * (N-1) dfs(0, -1, 0) print((max(anss))) print(('\n'.join(map(str, anss)))) solve()
36
31
723
681
import sys sys.setrecursionlimit(10**9) N = int(eval(input())) adjL = [[] for _ in range(N)] edges = [] for _ in range(N - 1): A, B = list(map(int, input().split())) A, B = A - 1, B - 1 adjL[A].append(B) adjL[B].append(A) edges.append((A, B)) colors = dict() def dfs(vNow, vPar, color): c = 1 for v2 in adjL[vNow]: if v2 == vPar: continue if c == color: c += 1 A, B = vNow, v2 if A > B: A, B = B, A colors[(A, B)] = c dfs(v2, vNow, c) c += 1 dfs(0, -1, 0) # print(colors) anss = [] for A, B in edges: anss.append(colors[(A, B)]) print((max(colors.values()))) print(("\n".join(map(str, anss))))
import sys input = sys.stdin.readline sys.setrecursionlimit(10**9) def solve(): N = int(eval(input())) adjL = [[] for _ in range(N)] for i in range(N - 1): a, b = list(map(int, input().split())) a, b = a - 1, b - 1 adjL[a].append((b, i)) adjL[b].append((a, i)) def dfs(vNow, vPar, clrPar): clr = 1 for v2, i in adjL[vNow]: if v2 == vPar: continue if clr == clrPar: clr += 1 anss[i] = clr dfs(v2, vNow, clr) clr += 1 anss = [0] * (N - 1) dfs(0, -1, 0) print((max(anss))) print(("\n".join(map(str, anss)))) solve()
false
13.888889
[ "+input = sys.stdin.readline", "-N = int(eval(input()))", "-adjL = [[] for _ in range(N)]", "-edges = []", "-for _ in range(N - 1):", "- A, B = list(map(int, input().split()))", "- A, B = A - 1, B - 1", "- adjL[A].append(B)", "- adjL[B].append(A)", "- edges.append((A, B))", "-colors = dict()", "-def dfs(vNow, vPar, color):", "- c = 1", "- for v2 in adjL[vNow]:", "- if v2 == vPar:", "- continue", "- if c == color:", "- c += 1", "- A, B = vNow, v2", "- if A > B:", "- A, B = B, A", "- colors[(A, B)] = c", "- dfs(v2, vNow, c)", "- c += 1", "+def solve():", "+ N = int(eval(input()))", "+ adjL = [[] for _ in range(N)]", "+ for i in range(N - 1):", "+ a, b = list(map(int, input().split()))", "+ a, b = a - 1, b - 1", "+ adjL[a].append((b, i))", "+ adjL[b].append((a, i))", "+", "+ def dfs(vNow, vPar, clrPar):", "+ clr = 1", "+ for v2, i in adjL[vNow]:", "+ if v2 == vPar:", "+ continue", "+ if clr == clrPar:", "+ clr += 1", "+ anss[i] = clr", "+ dfs(v2, vNow, clr)", "+ clr += 1", "+", "+ anss = [0] * (N - 1)", "+ dfs(0, -1, 0)", "+ print((max(anss)))", "+ print((\"\\n\".join(map(str, anss))))", "-dfs(0, -1, 0)", "-# print(colors)", "-anss = []", "-for A, B in edges:", "- anss.append(colors[(A, B)])", "-print((max(colors.values())))", "-print((\"\\n\".join(map(str, anss))))", "+solve()" ]
false
0.035701
0.040597
0.879383
[ "s751455051", "s928387096" ]
u380524497
p02788
python
s578414073
s033952155
876
459
45,372
56,024
Accepted
Accepted
47.6
from collections import deque import sys input = sys.stdin.readline n, d, a = list(map(int, input().split())) monsters = [] for _ in range(n): pos, hp = list(map(int, input().split())) monsters.append([pos, hp]) monsters.sort() bomb_area = deque([]) bomb_power = deque([]) total_damage = 0 ans = 0 for pos, hp in monsters: while bomb_area: area = bomb_area[0] if area < pos: bomb_area.popleft() power = bomb_power.popleft() total_damage -= power else: break if hp <= total_damage: continue else: count = (hp-total_damage + a-1) // a ans += count power = a * count total_damage += power bomb_area.append(pos+2*d) bomb_power.append(power) print(ans)
def main(): import sys from operator import itemgetter from collections import deque buf = sys.stdin.buffer n, d, a = list(map(int, buf.readline().split())) m = list(map(int, buf.read().split())) monsters = sorted(zip(m, m), key=itemgetter(0)) bomb_area = deque([]) bomb_power = deque([]) total_damage = 0 ans = 0 for pos, hp in monsters: while bomb_area: area = bomb_area[0] if area < pos: bomb_area.popleft() power = bomb_power.popleft() total_damage -= power else: break if hp <= total_damage: continue else: count = (hp - total_damage + a - 1) // a ans += count power = a * count total_damage += power bomb_area.append(pos + 2 * d) bomb_power.append(power) print(ans) if __name__ == '__main__': main()
37
37
824
1,006
from collections import deque import sys input = sys.stdin.readline n, d, a = list(map(int, input().split())) monsters = [] for _ in range(n): pos, hp = list(map(int, input().split())) monsters.append([pos, hp]) monsters.sort() bomb_area = deque([]) bomb_power = deque([]) total_damage = 0 ans = 0 for pos, hp in monsters: while bomb_area: area = bomb_area[0] if area < pos: bomb_area.popleft() power = bomb_power.popleft() total_damage -= power else: break if hp <= total_damage: continue else: count = (hp - total_damage + a - 1) // a ans += count power = a * count total_damage += power bomb_area.append(pos + 2 * d) bomb_power.append(power) print(ans)
def main(): import sys from operator import itemgetter from collections import deque buf = sys.stdin.buffer n, d, a = list(map(int, buf.readline().split())) m = list(map(int, buf.read().split())) monsters = sorted(zip(m, m), key=itemgetter(0)) bomb_area = deque([]) bomb_power = deque([]) total_damage = 0 ans = 0 for pos, hp in monsters: while bomb_area: area = bomb_area[0] if area < pos: bomb_area.popleft() power = bomb_power.popleft() total_damage -= power else: break if hp <= total_damage: continue else: count = (hp - total_damage + a - 1) // a ans += count power = a * count total_damage += power bomb_area.append(pos + 2 * d) bomb_power.append(power) print(ans) if __name__ == "__main__": main()
false
0
[ "-from collections import deque", "-import sys", "+def main():", "+ import sys", "+ from operator import itemgetter", "+ from collections import deque", "-input = sys.stdin.readline", "-n, d, a = list(map(int, input().split()))", "-monsters = []", "-for _ in range(n):", "- pos, hp = list(map(int, input().split()))", "- monsters.append([pos, hp])", "-monsters.sort()", "-bomb_area = deque([])", "-bomb_power = deque([])", "-total_damage = 0", "-ans = 0", "-for pos, hp in monsters:", "- while bomb_area:", "- area = bomb_area[0]", "- if area < pos:", "- bomb_area.popleft()", "- power = bomb_power.popleft()", "- total_damage -= power", "+ buf = sys.stdin.buffer", "+ n, d, a = list(map(int, buf.readline().split()))", "+ m = list(map(int, buf.read().split()))", "+ monsters = sorted(zip(m, m), key=itemgetter(0))", "+ bomb_area = deque([])", "+ bomb_power = deque([])", "+ total_damage = 0", "+ ans = 0", "+ for pos, hp in monsters:", "+ while bomb_area:", "+ area = bomb_area[0]", "+ if area < pos:", "+ bomb_area.popleft()", "+ power = bomb_power.popleft()", "+ total_damage -= power", "+ else:", "+ break", "+ if hp <= total_damage:", "+ continue", "- break", "- if hp <= total_damage:", "- continue", "- else:", "- count = (hp - total_damage + a - 1) // a", "- ans += count", "- power = a * count", "- total_damage += power", "- bomb_area.append(pos + 2 * d)", "- bomb_power.append(power)", "-print(ans)", "+ count = (hp - total_damage + a - 1) // a", "+ ans += count", "+ power = a * count", "+ total_damage += power", "+ bomb_area.append(pos + 2 * d)", "+ bomb_power.append(power)", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.037875
0.0075
5.050215
[ "s578414073", "s033952155" ]
u546285759
p00062
python
s534455446
s695587548
30
20
7,740
7,688
Accepted
Accepted
33.33
while True: try: nums = eval(input()) except: break a = list(map(int, list(nums))) while len(a) > 1: a = list(map(int, [str(a[i]+a[i+1])[-1] for i in range(len(a)-1)])) print((*a))
while True: try: nums = eval(input()) except: break a = list(map(int, list(nums))) while len(a) > 1: a = [(a[i]+a[i+1])%10 for i in range(len(a)-1)] print((*a))
9
9
224
204
while True: try: nums = eval(input()) except: break a = list(map(int, list(nums))) while len(a) > 1: a = list(map(int, [str(a[i] + a[i + 1])[-1] for i in range(len(a) - 1)])) print((*a))
while True: try: nums = eval(input()) except: break a = list(map(int, list(nums))) while len(a) > 1: a = [(a[i] + a[i + 1]) % 10 for i in range(len(a) - 1)] print((*a))
false
0
[ "- a = list(map(int, [str(a[i] + a[i + 1])[-1] for i in range(len(a) - 1)]))", "+ a = [(a[i] + a[i + 1]) % 10 for i in range(len(a) - 1)]" ]
false
0.035207
0.037865
0.929804
[ "s534455446", "s695587548" ]