user_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
1 value
submission_id_v0
stringlengths
10
10
submission_id_v1
stringlengths
10
10
cpu_time_v0
int64
10
38.3k
cpu_time_v1
int64
0
24.7k
memory_v0
int64
2.57k
1.02M
memory_v1
int64
2.57k
869k
status_v0
stringclasses
1 value
status_v1
stringclasses
1 value
improvement_frac
float64
7.51
100
input
stringlengths
20
4.55k
target
stringlengths
17
3.34k
code_v0_loc
int64
1
148
code_v1_loc
int64
1
184
code_v0_num_chars
int64
13
4.55k
code_v1_num_chars
int64
14
3.34k
code_v0_no_empty_lines
stringlengths
21
6.88k
code_v1_no_empty_lines
stringlengths
20
4.93k
code_same
bool
1 class
relative_loc_diff_percent
float64
0
79.8
diff
list
diff_only_import_comment
bool
1 class
measured_runtime_v0
float64
0.01
4.45
measured_runtime_v1
float64
0.01
4.31
runtime_lift
float64
0
359
key
list
u987164499
p03456
python
s457780077
s960854121
149
17
12,456
2,940
Accepted
Accepted
88.59
from sys import stdin from itertools import combinations from math import factorial import numpy as np import math a,b = [int(x) for x in stdin.readline().rstrip().split()] c = int(str(a)+str(b)) if int(math.sqrt(c))**2 == c: print("Yes") else: print("No")
a,b = list(map(int,input().split())) n = int(str(a)+str(b)) for i in range(1,350): if i**2 == n: print("Yes") exit() print("No")
14
10
280
154
from sys import stdin from itertools import combinations from math import factorial import numpy as np import math a, b = [int(x) for x in stdin.readline().rstrip().split()] c = int(str(a) + str(b)) if int(math.sqrt(c)) ** 2 == c: print("Yes") else: print("No")
a, b = list(map(int, input().split())) n = int(str(a) + str(b)) for i in range(1, 350): if i**2 == n: print("Yes") exit() print("No")
false
28.571429
[ "-from sys import stdin", "-from itertools import combinations", "-from math import factorial", "-import numpy as np", "-import math", "-", "-a, b = [int(x) for x in stdin.readline().rstrip().split()]", "-c = int(str(a) + str(b))", "-if int(math.sqrt(c)) ** 2 == c:", "- print(\"Yes\")", "-els...
false
0.041311
0.033241
1.242745
[ "s457780077", "s960854121" ]
u690037900
p03221
python
s223348421
s054765063
683
484
41,024
36,400
Accepted
Accepted
29.14
import bisect import collections N,M=list(map(int,input().split())) L=collections.defaultdict(list) p=[[int(j) for j in input().split()] for i in range(M)] for x,y in sorted(p): L[x]+=[y] for x,y in p: z=bisect.bisect(L[x],y) print(("%06d%06d"%(x,z)))
import sys import collections import bisect as bs input=sys.stdin.readline n,m=list(map(int,input().split())) d=collections.defaultdict(list) L=[] for i in range(m): a,b=list(map(int,input().split())) L.append((a,b)) for x,y in sorted(L): d[x].append(y) for x,y in L: z=bs.bisect(d[x],y) print(("%06d%06d"%(x,z)))
10
15
265
333
import bisect import collections N, M = list(map(int, input().split())) L = collections.defaultdict(list) p = [[int(j) for j in input().split()] for i in range(M)] for x, y in sorted(p): L[x] += [y] for x, y in p: z = bisect.bisect(L[x], y) print(("%06d%06d" % (x, z)))
import sys import collections import bisect as bs input = sys.stdin.readline n, m = list(map(int, input().split())) d = collections.defaultdict(list) L = [] for i in range(m): a, b = list(map(int, input().split())) L.append((a, b)) for x, y in sorted(L): d[x].append(y) for x, y in L: z = bs.bisect(d[x], y) print(("%06d%06d" % (x, z)))
false
33.333333
[ "-import bisect", "+import sys", "+import bisect as bs", "-N, M = list(map(int, input().split()))", "-L = collections.defaultdict(list)", "-p = [[int(j) for j in input().split()] for i in range(M)]", "-for x, y in sorted(p):", "- L[x] += [y]", "-for x, y in p:", "- z = bisect.bisect(L[x], y)...
false
0.040694
0.00722
5.63612
[ "s223348421", "s054765063" ]
u902380746
p03386
python
s665204426
s279320816
183
164
38,704
38,256
Accepted
Accepted
10.38
import sys import math import bisect def solve(a, b, k): ans = [] for i in range(k): if a + i <= b: ans.append(a + i) if b - i >= a: ans.append(b - i) ans = list(sorted(set(ans))) return ans def main(): a, b, k = list(map(int, input().split())) for a in solve(a, b, k): print(a) if __name__ == "__main__": main()
import sys import math import bisect def solve(a, b, k): ans = [] for i in range(k): if a + i <= b: ans.append(a + i) if b - i >= a: ans.append(b - i) ans = sorted(set(ans)) return ans def main(): a, b, k = list(map(int, input().split())) for a in solve(a, b, k): print(a) if __name__ == "__main__": main()
21
21
406
400
import sys import math import bisect def solve(a, b, k): ans = [] for i in range(k): if a + i <= b: ans.append(a + i) if b - i >= a: ans.append(b - i) ans = list(sorted(set(ans))) return ans def main(): a, b, k = list(map(int, input().split())) for a in solve(a, b, k): print(a) if __name__ == "__main__": main()
import sys import math import bisect def solve(a, b, k): ans = [] for i in range(k): if a + i <= b: ans.append(a + i) if b - i >= a: ans.append(b - i) ans = sorted(set(ans)) return ans def main(): a, b, k = list(map(int, input().split())) for a in solve(a, b, k): print(a) if __name__ == "__main__": main()
false
0
[ "- ans = list(sorted(set(ans)))", "+ ans = sorted(set(ans))" ]
false
0.070008
0.049556
1.412699
[ "s665204426", "s279320816" ]
u562935282
p03027
python
s168469585
s728584295
614
551
94,028
93,804
Accepted
Accepted
10.26
# https://atcoder.jp/contests/m-solutions2019/submissions/5741430 import sys input = sys.stdin.readline MOD = 10 ** 6 + 3 fact = [1] for n in range(1, MOD): fact.append((fact[-1] * n) % MOD) # d>1 の数列を d=1 となる数列に変換する # MODの倍数を含む数列の積は0になるので, # MODの倍数を含まない区間の積が計算できればよい # そのような区間の右端はMOD-1であり,fact[MOD-1]が計算できればよい inv_fact = [-1] * MOD inv_fact[MOD - 1] = pow(fact[-1], MOD - 2, MOD) for n in range(MOD - 2, -1, -1): inv_fact[n] = ((inv_fact[n + 1] * (n + 1)) % MOD) # inv_factは,inv(n!)にn,n-1,...を掛けるイメージ Q = int(eval(input())) for _ in range(Q): x, d, n = list(map(int, input().split())) if x == 0: print((0)) continue if d == 0: print((pow(x, n, MOD))) continue xd = (x * pow(d, MOD - 2, MOD)) % MOD if xd == 0: print((0)) continue if MOD - xd < n: print((0)) continue dn = pow(d, n, MOD) print(((((fact[xd + n - 1] * inv_fact[xd - 1]) % MOD) * dn) % MOD))
# https://atcoder.jp/contests/m-solutions2019/submissions/5741430 import sys input = sys.stdin.readline MOD = 10 ** 6 + 3 fact = [1] for n in range(1, MOD): fact.append((fact[-1] * n) % MOD) # d>1 の数列を d=1 となる数列に変換する # MODの倍数を含む数列の積は0になるので, # MODの倍数を含まない区間の積が計算できればよい # そのような区間の右端はMOD-1であり,fact[MOD-1]が計算できればよい inv_fact = [-1] * MOD inv_fact[MOD - 1] = pow(fact[-1], MOD - 2, MOD) for n in range(MOD - 2, -1, -1): inv_fact[n] = ((inv_fact[n + 1] * (n + 1)) % MOD) # inv_factは,inv(n!)にn,n-1,...を掛けるイメージ Q = int(input()) ans = [] for _ in range(Q): x, d, n = map(int, input().split()) if x == 0: ans.append(0) continue if d == 0: ans.append(pow(x, n, MOD)) continue xd = (x * pow(d, MOD - 2, MOD)) % MOD if xd == 0: ans.append(0) continue if MOD - xd < n: ans.append(0) continue dn = pow(d, n, MOD) ans.append((((fact[xd + n - 1] * inv_fact[xd - 1]) % MOD) * dn) % MOD) print(*ans, sep='\n')
44
46
1,011
1,069
# https://atcoder.jp/contests/m-solutions2019/submissions/5741430 import sys input = sys.stdin.readline MOD = 10**6 + 3 fact = [1] for n in range(1, MOD): fact.append((fact[-1] * n) % MOD) # d>1 の数列を d=1 となる数列に変換する # MODの倍数を含む数列の積は0になるので, # MODの倍数を含まない区間の積が計算できればよい # そのような区間の右端はMOD-1であり,fact[MOD-1]が計算できればよい inv_fact = [-1] * MOD inv_fact[MOD - 1] = pow(fact[-1], MOD - 2, MOD) for n in range(MOD - 2, -1, -1): inv_fact[n] = (inv_fact[n + 1] * (n + 1)) % MOD # inv_factは,inv(n!)にn,n-1,...を掛けるイメージ Q = int(eval(input())) for _ in range(Q): x, d, n = list(map(int, input().split())) if x == 0: print((0)) continue if d == 0: print((pow(x, n, MOD))) continue xd = (x * pow(d, MOD - 2, MOD)) % MOD if xd == 0: print((0)) continue if MOD - xd < n: print((0)) continue dn = pow(d, n, MOD) print(((((fact[xd + n - 1] * inv_fact[xd - 1]) % MOD) * dn) % MOD))
# https://atcoder.jp/contests/m-solutions2019/submissions/5741430 import sys input = sys.stdin.readline MOD = 10**6 + 3 fact = [1] for n in range(1, MOD): fact.append((fact[-1] * n) % MOD) # d>1 の数列を d=1 となる数列に変換する # MODの倍数を含む数列の積は0になるので, # MODの倍数を含まない区間の積が計算できればよい # そのような区間の右端はMOD-1であり,fact[MOD-1]が計算できればよい inv_fact = [-1] * MOD inv_fact[MOD - 1] = pow(fact[-1], MOD - 2, MOD) for n in range(MOD - 2, -1, -1): inv_fact[n] = (inv_fact[n + 1] * (n + 1)) % MOD # inv_factは,inv(n!)にn,n-1,...を掛けるイメージ Q = int(input()) ans = [] for _ in range(Q): x, d, n = map(int, input().split()) if x == 0: ans.append(0) continue if d == 0: ans.append(pow(x, n, MOD)) continue xd = (x * pow(d, MOD - 2, MOD)) % MOD if xd == 0: ans.append(0) continue if MOD - xd < n: ans.append(0) continue dn = pow(d, n, MOD) ans.append((((fact[xd + n - 1] * inv_fact[xd - 1]) % MOD) * dn) % MOD) print(*ans, sep="\n")
false
4.347826
[ "-Q = int(eval(input()))", "+Q = int(input())", "+ans = []", "- x, d, n = list(map(int, input().split()))", "+ x, d, n = map(int, input().split())", "- print((0))", "+ ans.append(0)", "- print((pow(x, n, MOD)))", "+ ans.append(pow(x, n, MOD))", "- print((0)...
false
1.079693
1.167482
0.924805
[ "s168469585", "s728584295" ]
u203669169
p03607
python
s528960421
s475675441
231
177
18,364
21,728
Accepted
Accepted
23.38
#! /usr/bin/env python3 from fractions import gcd from collections import Counter, deque, defaultdict from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from itertools import accumulate, product, permutations, combinations, combinations_with_replacement N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] c = Counter(A) ct = 0 for i in list(c.values()): if i % 2 != 0: ct += 1 print(ct)
#! /usr/bin/env python3 from fractions import gcd # from math import gcd from collections import Counter, deque, defaultdict from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from itertools import accumulate, product, permutations, combinations, combinations_with_replacement N = int(eval(input())) A = [int(eval(input())) for i in range(N)] c = Counter(A) ret = 0 for key, item in list(c.items()): if item % 2 == 1: ret += 1 print(ret)
19
20
533
570
#! /usr/bin/env python3 from fractions import gcd from collections import Counter, deque, defaultdict from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from itertools import ( accumulate, product, permutations, combinations, combinations_with_replacement, ) N = int(eval(input())) A = [int(eval(input())) for _ in range(N)] c = Counter(A) ct = 0 for i in list(c.values()): if i % 2 != 0: ct += 1 print(ct)
#! /usr/bin/env python3 from fractions import gcd # from math import gcd from collections import Counter, deque, defaultdict from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort from itertools import ( accumulate, product, permutations, combinations, combinations_with_replacement, ) N = int(eval(input())) A = [int(eval(input())) for i in range(N)] c = Counter(A) ret = 0 for key, item in list(c.items()): if item % 2 == 1: ret += 1 print(ret)
false
5
[ "+", "+# from math import gcd", "-A = [int(eval(input())) for _ in range(N)]", "+A = [int(eval(input())) for i in range(N)]", "-ct = 0", "-for i in list(c.values()):", "- if i % 2 != 0:", "- ct += 1", "-print(ct)", "+ret = 0", "+for key, item in list(c.items()):", "+ if item % 2 =...
false
0.102274
0.04381
2.334492
[ "s528960421", "s475675441" ]
u864013199
p03287
python
s805796678
s294538295
90
75
16,548
16,556
Accepted
Accepted
16.67
from collections import Counter N,M = list(map(int,input().split())) A = list(map(int,input().split())) B = [0] for a in A: B.append((B[-1]+a)%M) c = Counter(B) ans = 0 for v in list(c.values()): ans += v*(v-1)//2 print(ans)
from collections import Counter def main(): N,M = list(map(int,input().split())) A = list(map(int,input().split())) B = [0] for a in A: B.append((B[-1]+a)%M) c = Counter(B) ans = 0 for v in list(c.values()): ans += v*(v-1)//2 print(ans) if __name__ == '__main__': main()
11
15
231
325
from collections import Counter N, M = list(map(int, input().split())) A = list(map(int, input().split())) B = [0] for a in A: B.append((B[-1] + a) % M) c = Counter(B) ans = 0 for v in list(c.values()): ans += v * (v - 1) // 2 print(ans)
from collections import Counter def main(): N, M = list(map(int, input().split())) A = list(map(int, input().split())) B = [0] for a in A: B.append((B[-1] + a) % M) c = Counter(B) ans = 0 for v in list(c.values()): ans += v * (v - 1) // 2 print(ans) if __name__ == "__main__": main()
false
26.666667
[ "-N, M = list(map(int, input().split()))", "-A = list(map(int, input().split()))", "-B = [0]", "-for a in A:", "- B.append((B[-1] + a) % M)", "-c = Counter(B)", "-ans = 0", "-for v in list(c.values()):", "- ans += v * (v - 1) // 2", "-print(ans)", "+", "+def main():", "+ N, M = list...
false
0.035083
0.036678
0.95651
[ "s805796678", "s294538295" ]
u654470292
p03608
python
s678384800
s180628878
572
264
88,152
84,248
Accepted
Accepted
53.85
import sys from collections import * import heapq import math import bisect from itertools import permutations,accumulate,combinations,product from fractions import gcd def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0]+list(accumulate(lst)) mod=pow(10,9)+7 al=[chr(ord('a') + i) for i in range(26)] n,m,r=list(map(int,input().split())) r=list(map(int,input().split())) abc=[list(map(int,input().split())) for i in range(m)] def warshall_floyd(d): #d[i][j]: iからjへの最短距離 for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j],d[i][k] + d[k][j]) return d d = [[float("inf") for i in range(n)] for i in range(n)] #d[u][v] : 辺uvのコスト(存在しないときはinf) for i in range(m): x,y,z = abc[i] x-=1 y-=1 d[x][y] = z d[y][x] = z for i in range(n): d[i][i] = 0 #自身のところに行くコストは0 warshall_floyd(d) lst=list(permutations(r)) # print(lst) ans=float('inf') for i in range(len(lst)): tmp=0 for j in range(len(lst[i])-1): tmp+=d[lst[i][j+1]-1][lst[i][j]-1] ans=min(ans,tmp) print(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]] n,m,r=list(map(int,input().split())) r=list(map(int,input().split())) abc=[list(map(int,input().split())) for i in range(m)] def warshall_floyd(d): #d[i][j]: iからjへの最短距離 for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j],d[i][k] + d[k][j]) return d n,w = n,m d = [[float("inf") for i in range(n)] for i in range(n)] #d[u][v] : 辺uvのコスト(存在しないときはinf) for i in range(w): x,y,z = abc[i] x,y=x-1,y-1 d[x][y] = z d[y][x] = z for i in range(n): d[i][i] = 0 #自身のところに行くコストは0 d=warshall_floyd(d) # print(range(r)) lst=list(permutations(r)) # print(lst) ans=float('inf') for i in lst: tmp=0 for j in range(len(i)-1): tmp+=d[i[j]-1][i[j+1]-1] ans=min(ans,tmp) print(ans)
49
50
1,152
1,254
import sys from collections import * import heapq import math import bisect from itertools import permutations, accumulate, combinations, product from fractions import gcd def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return [0] + list(accumulate(lst)) mod = pow(10, 9) + 7 al = [chr(ord("a") + i) for i in range(26)] n, m, r = list(map(int, input().split())) r = list(map(int, input().split())) abc = [list(map(int, input().split())) for i in range(m)] def warshall_floyd(d): # d[i][j]: iからjへの最短距離 for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j], d[i][k] + d[k][j]) return d d = [[float("inf") for i in range(n)] for i in range(n)] # d[u][v] : 辺uvのコスト(存在しないときはinf) for i in range(m): x, y, z = abc[i] x -= 1 y -= 1 d[x][y] = z d[y][x] = z for i in range(n): d[i][i] = 0 # 自身のところに行くコストは0 warshall_floyd(d) lst = list(permutations(r)) # print(lst) ans = float("inf") for i in range(len(lst)): tmp = 0 for j in range(len(lst[i]) - 1): tmp += d[lst[i][j + 1] - 1][lst[i][j] - 1] ans = min(ans, tmp) print(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]] n, m, r = list(map(int, input().split())) r = list(map(int, input().split())) abc = [list(map(int, input().split())) for i in range(m)] def warshall_floyd(d): # d[i][j]: iからjへの最短距離 for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j], d[i][k] + d[k][j]) return d n, w = n, m d = [[float("inf") for i in range(n)] for i in range(n)] # d[u][v] : 辺uvのコスト(存在しないときはinf) for i in range(w): x, y, z = abc[i] x, y = x - 1, y - 1 d[x][y] = z d[y][x] = z for i in range(n): d[i][i] = 0 # 自身のところに行くコストは0 d = warshall_floyd(d) # print(range(r)) lst = list(permutations(r)) # print(lst) ans = float("inf") for i in lst: tmp = 0 for j in range(len(i) - 1): tmp += d[i[j] - 1][i[j + 1] - 1] ans = min(ans, tmp) print(ans)
false
2
[ "-import sys", "+import bisect, copy, heapq, math, sys", "-import heapq", "-import math", "-import bisect", "-from itertools import permutations, accumulate, combinations, product", "-from fractions import gcd", "+from functools import lru_cache", "+from itertools import accumulate, combinations, pe...
false
0.035703
0.033113
1.078241
[ "s678384800", "s180628878" ]
u759412327
p03796
python
s969647353
s382409708
230
152
3,972
9,956
Accepted
Accepted
33.91
from math import factorial print((factorial(int(eval(input())))%(10**9+7)))
from math import * print((factorial(int(eval(input())))%(10**9+7)))
2
2
68
60
from math import factorial print((factorial(int(eval(input()))) % (10**9 + 7)))
from math import * print((factorial(int(eval(input()))) % (10**9 + 7)))
false
0
[ "-from math import factorial", "+from math import *" ]
false
0.547273
0.105736
5.17583
[ "s969647353", "s382409708" ]
u239342230
p02873
python
s485580409
s435100599
597
450
48,500
48,404
Accepted
Accepted
24.62
S=eval(input()) S_rev=S[::-1] import numpy as np arr_rev=[] cnt=0 for s_rev in S_rev: if s_rev==">": cnt+=1 else: cnt=0 arr_rev.append(cnt) A=np.array(arr_rev[::-1]+[0]) arr=[] cnt=0 for s in S: if s=="<": cnt+=1 else: cnt=0 arr.append(cnt) B=np.array([0]+arr) print((sum(np.maximum(A,B))))
import numpy as np S=eval(input());T=S[::-1];a=[];c=0 for t in T: if t==">": c+=1 else: c=0 a.append(c) A=np.array(a[::-1]+[0]) b=[];c=0 for s in S: if s=="<": c+=1 else: c=0 b.append(c) B=np.array([0]+b) print((np.maximum(A,B).sum()))
28
18
371
300
S = eval(input()) S_rev = S[::-1] import numpy as np arr_rev = [] cnt = 0 for s_rev in S_rev: if s_rev == ">": cnt += 1 else: cnt = 0 arr_rev.append(cnt) A = np.array(arr_rev[::-1] + [0]) arr = [] cnt = 0 for s in S: if s == "<": cnt += 1 else: cnt = 0 arr.append(cnt) B = np.array([0] + arr) print((sum(np.maximum(A, B))))
import numpy as np S = eval(input()) T = S[::-1] a = [] c = 0 for t in T: if t == ">": c += 1 else: c = 0 a.append(c) A = np.array(a[::-1] + [0]) b = [] c = 0 for s in S: if s == "<": c += 1 else: c = 0 b.append(c) B = np.array([0] + b) print((np.maximum(A, B).sum()))
false
35.714286
[ "-S = eval(input())", "-S_rev = S[::-1]", "-arr_rev = []", "-cnt = 0", "-for s_rev in S_rev:", "- if s_rev == \">\":", "- cnt += 1", "+S = eval(input())", "+T = S[::-1]", "+a = []", "+c = 0", "+for t in T:", "+ if t == \">\":", "+ c += 1", "- cnt = 0", "- ...
false
0.046106
0.21581
0.213643
[ "s485580409", "s435100599" ]
u934442292
p02623
python
s537945821
s521205637
707
602
42,208
42,392
Accepted
Accepted
14.85
import sys from itertools import accumulate input = sys.stdin.readline def binary_search(a, key): """Meguru type binary search""" ok = -1 ng = len(a) while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if a[mid] <= key: ok = mid else: ng = mid return ok def main(): N, M, K = list(map(int, input().split())) A = tuple(map(int, input().split())) B = tuple(map(int, input().split())) B_cumsum = tuple(accumulate(B)) ans = 0 time = 0 for i in range(N + 1): if time > K: break j = binary_search(B_cumsum, K - time) + 1 ans = max(ans, i + j) if i < N: time += A[i] print(ans) if __name__ == "__main__": main()
import sys from itertools import accumulate input = sys.stdin.readline def binary_search(a, key): """Meguru type binary search""" ok = -1 ng = len(a) while (ng - ok > 1): mid = (ok + ng) // 2 if a[mid] <= key: ok = mid else: ng = mid return ok def main(): N, M, K = list(map(int, input().split())) A = tuple(map(int, input().split())) B = tuple(map(int, input().split())) B_cumsum = tuple(accumulate(B)) ans = 0 time = 0 for i in range(N + 1): if time > K: break j = binary_search(B_cumsum, K - time) + 1 ans = max(ans, i + j) if i < N: time += A[i] print(ans) if __name__ == "__main__": main()
43
43
808
803
import sys from itertools import accumulate input = sys.stdin.readline def binary_search(a, key): """Meguru type binary search""" ok = -1 ng = len(a) while abs(ok - ng) > 1: mid = (ok + ng) // 2 if a[mid] <= key: ok = mid else: ng = mid return ok def main(): N, M, K = list(map(int, input().split())) A = tuple(map(int, input().split())) B = tuple(map(int, input().split())) B_cumsum = tuple(accumulate(B)) ans = 0 time = 0 for i in range(N + 1): if time > K: break j = binary_search(B_cumsum, K - time) + 1 ans = max(ans, i + j) if i < N: time += A[i] print(ans) if __name__ == "__main__": main()
import sys from itertools import accumulate input = sys.stdin.readline def binary_search(a, key): """Meguru type binary search""" ok = -1 ng = len(a) while ng - ok > 1: mid = (ok + ng) // 2 if a[mid] <= key: ok = mid else: ng = mid return ok def main(): N, M, K = list(map(int, input().split())) A = tuple(map(int, input().split())) B = tuple(map(int, input().split())) B_cumsum = tuple(accumulate(B)) ans = 0 time = 0 for i in range(N + 1): if time > K: break j = binary_search(B_cumsum, K - time) + 1 ans = max(ans, i + j) if i < N: time += A[i] print(ans) if __name__ == "__main__": main()
false
0
[ "- while abs(ok - ng) > 1:", "+ while ng - ok > 1:" ]
false
0.043719
0.052318
0.835641
[ "s537945821", "s521205637" ]
u794145298
p02710
python
s385540926
s265259366
1,119
743
253,168
209,780
Accepted
Accepted
33.6
N = int(eval(input())) Cs = list(map(int, input().split())) adj = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) adj[a - 1].append(b - 1) adj[b - 1].append(a - 1) degs = [0] * N clusters = [[] for _ in range(N)] def go(curr, fro): col = Cs[curr] - 1 deg = 1 clust = {} for n in adj[curr]: if n == fro: continue ch_deg, ch_clust = yield go(n, curr) clusters[col].append(ch_deg - ch_clust.get(col, 0)) if len(ch_clust) > len(clust): clust, ch_clust = ch_clust, clust for k, v in list(ch_clust.items()): clust[k] = clust.get(k, 0) + v deg += ch_deg clust[col] = deg return deg, clust def tramp(gen): stack = [gen] val = None while stack: try: stack.append(stack[-1].send(val)) val = None except StopIteration as e: stack.pop() val = e.value return val _, root_clust = tramp(go(0, -1)) for i in range(N): clusters[i].append(N - root_clust.get(i, 0)) for clust in clusters: tot = (N * N + N) // 2 for cnt in clust: tot -= (cnt * cnt + cnt) // 2 print(tot)
N = int(eval(input())) Cs = list(map(int, input().split())) adj = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) adj[a - 1].append(b - 1) adj[b - 1].append(a - 1) under_col = [0] * N ans = [0] * N def tri(n): return n * (n + 1) // 2 def go(curr, fro): col = Cs[curr] - 1 prev_under = under_col[col] deg = 1 for n in adj[curr]: if n == fro: continue curr_under = under_col[col] ch_deg = yield go(n, curr) diff_under = under_col[col] - curr_under ans[col] += tri(ch_deg - diff_under) deg += ch_deg under_col[col] = prev_under + deg return deg def tramp(gen): stack = [gen] val = None while stack: try: stack.append(stack[-1].send(val)) val = None except StopIteration as e: stack.pop() val = e.value return val tramp(go(0, -1)) for i in range(N): ans[i] += tri(N - under_col[i]) print((tri(N) - ans[i]))
53
49
1,256
1,071
N = int(eval(input())) Cs = list(map(int, input().split())) adj = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) adj[a - 1].append(b - 1) adj[b - 1].append(a - 1) degs = [0] * N clusters = [[] for _ in range(N)] def go(curr, fro): col = Cs[curr] - 1 deg = 1 clust = {} for n in adj[curr]: if n == fro: continue ch_deg, ch_clust = yield go(n, curr) clusters[col].append(ch_deg - ch_clust.get(col, 0)) if len(ch_clust) > len(clust): clust, ch_clust = ch_clust, clust for k, v in list(ch_clust.items()): clust[k] = clust.get(k, 0) + v deg += ch_deg clust[col] = deg return deg, clust def tramp(gen): stack = [gen] val = None while stack: try: stack.append(stack[-1].send(val)) val = None except StopIteration as e: stack.pop() val = e.value return val _, root_clust = tramp(go(0, -1)) for i in range(N): clusters[i].append(N - root_clust.get(i, 0)) for clust in clusters: tot = (N * N + N) // 2 for cnt in clust: tot -= (cnt * cnt + cnt) // 2 print(tot)
N = int(eval(input())) Cs = list(map(int, input().split())) adj = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) adj[a - 1].append(b - 1) adj[b - 1].append(a - 1) under_col = [0] * N ans = [0] * N def tri(n): return n * (n + 1) // 2 def go(curr, fro): col = Cs[curr] - 1 prev_under = under_col[col] deg = 1 for n in adj[curr]: if n == fro: continue curr_under = under_col[col] ch_deg = yield go(n, curr) diff_under = under_col[col] - curr_under ans[col] += tri(ch_deg - diff_under) deg += ch_deg under_col[col] = prev_under + deg return deg def tramp(gen): stack = [gen] val = None while stack: try: stack.append(stack[-1].send(val)) val = None except StopIteration as e: stack.pop() val = e.value return val tramp(go(0, -1)) for i in range(N): ans[i] += tri(N - under_col[i]) print((tri(N) - ans[i]))
false
7.54717
[ "-degs = [0] * N", "-clusters = [[] for _ in range(N)]", "+under_col = [0] * N", "+ans = [0] * N", "+", "+", "+def tri(n):", "+ return n * (n + 1) // 2", "+ prev_under = under_col[col]", "- clust = {}", "- ch_deg, ch_clust = yield go(n, curr)", "- clusters[col].append(ch...
false
0.040088
0.007435
5.391629
[ "s385540926", "s265259366" ]
u133936772
p02861
python
s668752534
s406313198
436
17
3,188
2,940
Accepted
Accepted
96.1
n = int(eval(input())) ll = [list(map(int,input().split())) for _ in range(n)] import itertools as it c,d = 0,0 for t in it.permutations(list(range(n))): c += 1 for i in range(len(t)-1): d += ((ll[t[i+1]][1]-ll[t[i]][1])**2+(ll[t[i+1]][0]-ll[t[i]][0])**2)**.5 print((d/c))
n=int(eval(input())) l=[list(map(int,input().split())) for _ in range(n)] print((sum(((x-z)**2+(y-w)**2)**.5 for x,y in l for z,w in l)/n))
9
3
274
133
n = int(eval(input())) ll = [list(map(int, input().split())) for _ in range(n)] import itertools as it c, d = 0, 0 for t in it.permutations(list(range(n))): c += 1 for i in range(len(t) - 1): d += ( (ll[t[i + 1]][1] - ll[t[i]][1]) ** 2 + (ll[t[i + 1]][0] - ll[t[i]][0]) ** 2 ) ** 0.5 print((d / c))
n = int(eval(input())) l = [list(map(int, input().split())) for _ in range(n)] print((sum(((x - z) ** 2 + (y - w) ** 2) ** 0.5 for x, y in l for z, w in l) / n))
false
66.666667
[ "-ll = [list(map(int, input().split())) for _ in range(n)]", "-import itertools as it", "-", "-c, d = 0, 0", "-for t in it.permutations(list(range(n))):", "- c += 1", "- for i in range(len(t) - 1):", "- d += (", "- (ll[t[i + 1]][1] - ll[t[i]][1]) ** 2 + (ll[t[i + 1]][0] - ll[...
false
0.076018
0.039181
1.940193
[ "s668752534", "s406313198" ]
u580697892
p03486
python
s768033363
s497383989
20
17
3,060
3,060
Accepted
Accepted
15
# coding: utf-8 s = eval(input()) t = eval(input()) re_s = sorted(s) re_t = sorted(t, reverse=True) print(("Yes" if re_s < re_t else "No"))
# coding: utf-8 s = list(eval(input())) t = list(eval(input())) s.sort() t.sort(reverse=True) sd = "".join(s) td = "".join(t) print(("Yes" if sd < td else "No"))
6
8
130
154
# coding: utf-8 s = eval(input()) t = eval(input()) re_s = sorted(s) re_t = sorted(t, reverse=True) print(("Yes" if re_s < re_t else "No"))
# coding: utf-8 s = list(eval(input())) t = list(eval(input())) s.sort() t.sort(reverse=True) sd = "".join(s) td = "".join(t) print(("Yes" if sd < td else "No"))
false
25
[ "-s = eval(input())", "-t = eval(input())", "-re_s = sorted(s)", "-re_t = sorted(t, reverse=True)", "-print((\"Yes\" if re_s < re_t else \"No\"))", "+s = list(eval(input()))", "+t = list(eval(input()))", "+s.sort()", "+t.sort(reverse=True)", "+sd = \"\".join(s)", "+td = \"\".join(t)", "+print(...
false
0.048719
0.054811
0.888849
[ "s768033363", "s497383989" ]
u662396511
p02699
python
s882570625
s552335578
23
20
9,088
9,020
Accepted
Accepted
13.04
S, W = list(map(int, input().split())) if S>W: print("safe") else: print("unsafe")
s, w = list(map(int, input().split())) if s>w: print("safe") else: print("unsafe")
5
5
84
84
S, W = list(map(int, input().split())) if S > W: print("safe") else: print("unsafe")
s, w = list(map(int, input().split())) if s > w: print("safe") else: print("unsafe")
false
0
[ "-S, W = list(map(int, input().split()))", "-if S > W:", "+s, w = list(map(int, input().split()))", "+if s > w:" ]
false
0.06074
0.061234
0.991935
[ "s882570625", "s552335578" ]
u782850731
p00005
python
s941121630
s070497435
30
20
5,900
5,896
Accepted
Accepted
33.33
from __future__ import (division, absolute_import, print_function, unicode_literals) import sys from fractions import gcd from itertools import count for line in sys.stdin: small, large = sorted(int(n) for n in line .split()) for i in count(large, large): if not i % small: lcm = i break print(gcd(large, small), lcm)
from __future__ import (division, absolute_import, print_function, unicode_literals) import sys from fractions import gcd for line in sys.stdin: small, large = sorted(int(n) for n in line .split()) G = gcd(large, small) print(G, large // G * small)
13
9
398
293
from __future__ import division, absolute_import, print_function, unicode_literals import sys from fractions import gcd from itertools import count for line in sys.stdin: small, large = sorted(int(n) for n in line.split()) for i in count(large, large): if not i % small: lcm = i break print(gcd(large, small), lcm)
from __future__ import division, absolute_import, print_function, unicode_literals import sys from fractions import gcd for line in sys.stdin: small, large = sorted(int(n) for n in line.split()) G = gcd(large, small) print(G, large // G * small)
false
30.769231
[ "-from itertools import count", "- for i in count(large, large):", "- if not i % small:", "- lcm = i", "- break", "- print(gcd(large, small), lcm)", "+ G = gcd(large, small)", "+ print(G, large // G * small)" ]
false
0.064373
0.061489
1.046905
[ "s941121630", "s070497435" ]
u724687935
p03448
python
s442996045
s321932609
169
51
38,896
3,060
Accepted
Accepted
69.82
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) cnt = 0 for num_A in [num_A for num_A in range(A + 1) if (num_A * 500 <= X)]: rest_XA = X - num_A * 500 for num_B in [num_B for num_B in range(B + 1) if num_B * 100 <= rest_XA]: rest_XAB = rest_XA - num_B * 100 if rest_XAB % 50 == 0 and rest_XAB <= C * 50: cnt += 1 print(cnt)
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) cnt = 0 for a in range(A + 1): for b in range(B + 1): for c in range(C + 1): if 500 * a + 100 * b + 50 * c == X: cnt += 1 print(cnt)
14
14
396
257
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) cnt = 0 for num_A in [num_A for num_A in range(A + 1) if (num_A * 500 <= X)]: rest_XA = X - num_A * 500 for num_B in [num_B for num_B in range(B + 1) if num_B * 100 <= rest_XA]: rest_XAB = rest_XA - num_B * 100 if rest_XAB % 50 == 0 and rest_XAB <= C * 50: cnt += 1 print(cnt)
A = int(eval(input())) B = int(eval(input())) C = int(eval(input())) X = int(eval(input())) cnt = 0 for a in range(A + 1): for b in range(B + 1): for c in range(C + 1): if 500 * a + 100 * b + 50 * c == X: cnt += 1 print(cnt)
false
0
[ "-for num_A in [num_A for num_A in range(A + 1) if (num_A * 500 <= X)]:", "- rest_XA = X - num_A * 500", "- for num_B in [num_B for num_B in range(B + 1) if num_B * 100 <= rest_XA]:", "- rest_XAB = rest_XA - num_B * 100", "- if rest_XAB % 50 == 0 and rest_XAB <= C * 50:", "- ...
false
0.088999
0.117232
0.759169
[ "s442996045", "s321932609" ]
u151503168
p02996
python
s405831422
s217806208
1,012
794
55,264
31,828
Accepted
Accepted
21.54
N = int(eval(input())) X = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[1]) t = 0 for a, b in X: t += a if (t > b): print("No") exit() print("Yes")
N = int(eval(input())) X = [tuple(map(int, input().split())) for _ in range(N)] X.sort(key=lambda x:x[1]) t = 0 for a, b in X: t += a if (t > b): print("No") break else: print("Yes")
9
11
201
214
N = int(eval(input())) X = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[1]) t = 0 for a, b in X: t += a if t > b: print("No") exit() print("Yes")
N = int(eval(input())) X = [tuple(map(int, input().split())) for _ in range(N)] X.sort(key=lambda x: x[1]) t = 0 for a, b in X: t += a if t > b: print("No") break else: print("Yes")
false
18.181818
[ "-X = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[1])", "+X = [tuple(map(int, input().split())) for _ in range(N)]", "+X.sort(key=lambda x: x[1])", "- exit()", "-print(\"Yes\")", "+ break", "+else:", "+ print(\"Yes\")" ]
false
0.094725
0.045759
2.070088
[ "s405831422", "s217806208" ]
u189023301
p02819
python
s444925514
s497941926
51
28
20,640
9,400
Accepted
Accepted
45.1
def solve(): from bisect import bisect_right, bisect, bisect_left x = int(eval(input())) n = 100100 primes = set(range(2, n + 1)) for i in range(2, int(n ** 0.5 + 1)): if i not in primes: i += 1 else: ran = list(range(i * 2, n + 1, i)) primes.difference_update(ran) primes = list(primes) y = bisect_left(primes, x) print((primes[y])) solve()
def solve(): x = int(eval(input())) def is_prime(n): for i in range(2, int(x ** 0.5) + 1): if n % i == 0: return False return True while not is_prime(x): x += 1 print(x) solve()
17
14
438
256
def solve(): from bisect import bisect_right, bisect, bisect_left x = int(eval(input())) n = 100100 primes = set(range(2, n + 1)) for i in range(2, int(n**0.5 + 1)): if i not in primes: i += 1 else: ran = list(range(i * 2, n + 1, i)) primes.difference_update(ran) primes = list(primes) y = bisect_left(primes, x) print((primes[y])) solve()
def solve(): x = int(eval(input())) def is_prime(n): for i in range(2, int(x**0.5) + 1): if n % i == 0: return False return True while not is_prime(x): x += 1 print(x) solve()
false
17.647059
[ "- from bisect import bisect_right, bisect, bisect_left", "+ x = int(eval(input()))", "- x = int(eval(input()))", "- n = 100100", "- primes = set(range(2, n + 1))", "- for i in range(2, int(n**0.5 + 1)):", "- if i not in primes:", "- i += 1", "- else:", "...
false
0.221937
0.036189
6.132767
[ "s444925514", "s497941926" ]
u734548018
p03681
python
s914607693
s207257569
495
168
54,640
38,384
Accepted
Accepted
66.06
# /usr/bin/python # -*- coding: utf-8 -*- import math D = 10**9+7 def main(): NM = sorted(list(map(int, input().split()))) if NM[1]-NM[0] > 1: return 0 elif NM[0]==NM[1]: ret = 2*(math.factorial(NM[0])**2) % D return ret else: ret = math.factorial(NM[0])*math.factorial(NM[1]) % D return ret if __name__ == "__main__": print((main()))
# /usr/bin/python # -*- coding: utf-8 -*- import math D = 10**9+7 def fact(n): ret = 1 for i in range(1,n+1): ret = (ret*i) % D return ret def main(): NM = sorted(list(map(int, input().split()))) n,m = [fact(NM[0]), fact(NM[1])] if NM[0]==NM[1]: return (n*m*2) % D elif NM[0]+1==NM[1]: return (n*m) % D else: return 0 if __name__ == "__main__": print((main()))
21
26
387
423
# /usr/bin/python # -*- coding: utf-8 -*- import math D = 10**9 + 7 def main(): NM = sorted(list(map(int, input().split()))) if NM[1] - NM[0] > 1: return 0 elif NM[0] == NM[1]: ret = 2 * (math.factorial(NM[0]) ** 2) % D return ret else: ret = math.factorial(NM[0]) * math.factorial(NM[1]) % D return ret if __name__ == "__main__": print((main()))
# /usr/bin/python # -*- coding: utf-8 -*- import math D = 10**9 + 7 def fact(n): ret = 1 for i in range(1, n + 1): ret = (ret * i) % D return ret def main(): NM = sorted(list(map(int, input().split()))) n, m = [fact(NM[0]), fact(NM[1])] if NM[0] == NM[1]: return (n * m * 2) % D elif NM[0] + 1 == NM[1]: return (n * m) % D else: return 0 if __name__ == "__main__": print((main()))
false
19.230769
[ "+def fact(n):", "+ ret = 1", "+ for i in range(1, n + 1):", "+ ret = (ret * i) % D", "+ return ret", "+", "+", "- if NM[1] - NM[0] > 1:", "+ n, m = [fact(NM[0]), fact(NM[1])]", "+ if NM[0] == NM[1]:", "+ return (n * m * 2) % D", "+ elif NM[0] + 1 == NM[1]:",...
false
0.057894
0.038349
1.509679
[ "s914607693", "s207257569" ]
u707124227
p03040
python
s854728196
s555388888
984
695
117,732
109,456
Accepted
Accepted
29.37
q=int(eval(input())) query=[eval(input()) for _ in range(q)] from bisect import bisect_left ary=[-float('inf')] for qq in query: if qq[0]=='1': _,a,_=list(map(int,qq.split())) ary.append(a) ary.sort() ary.append(float('inf')) class SegmentTree(): def __init__(self,size,f=lambda x,y:x+y,default=0): self.size=pow(2,(size-1).bit_length()) self.f=f self.default=default self.data=[default]*(self.size*2) def update(self,i,x): i+=self.size self.data[i]=x while i: i>>=1 self.data[i]=self.f(self.data[i*2],self.data[i*2+1]) # 区間[l,r)へのクエリ def query(self,l,r): l,r=l+self.size,r+self.size lret,rret=self.default,self.default while l<r: if l&1: lret=self.f(self.data[l],lret) l+=1 if r&1: r-=1 rret=self.f(self.data[r],rret) l>>=1 r>>=1 return self.f(lret,rret) def get(self,i): return self.data[self.size+i] def add(self,i,x): self.update(i,self.get(i)+x) ml,mr=0,len(ary)+1 mv=0 st=SegmentTree(len(ary)) for qq in query: if qq[0]=='2': print((ary[ml],mv)) else: _,a,b=list(map(int,qq.split())) a=bisect_left(ary,a) st.add(0,-1) st.add(a,2) if ml<=a<mr: mv+=b ml,mr=a,a+1 else: l,r=0,len(ary)+1 # はじめて0以上になる場所を二分探索→ここがml while r-l>1: x=(r+l)//2 if st.query(0,x)>=0: l,r=l,x else: l,r=x,r # はじめて1以上になる場所を二分探索→ここがmr mv+=b mv+=min(abs(ary[l]-ary[ml]),abs(ary[l]-ary[mr]))+abs(ary[l]-ary[a]) ml=l l,r=0,len(ary)+1 while r-l>1: x=(r+l)//2 if st.query(0,x)>0: l,r=l,x else: l,r=x,r mr=l
q=int(eval(input())) query=[eval(input()) for _ in range(q)] from bisect import bisect_left ary=[-float('inf')] for qq in query: if qq[0]=='1': _,a,_=list(map(int,qq.split())) ary.append(a) ary.sort() ary.append(float('inf')) class BIT: def __init__(self, n): self.n = n self.data = [0]*(n+1) self.el = [0]*(n+1) def sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i & -i return s def add(self, i, x): # assert i > 0 self.el[i] += x while i <= self.n: self.data[i] += x i += i & -i def get(self, i, j=None): if j is None: return self.el[i] return self.sum(j) - self.sum(i) ml,mr=0,len(ary)+1 mv=0 bit=BIT(len(ary)+1) for qq in query: if qq[0]=='2': print((ary[ml],mv)) else: _,a,b=list(map(int,qq.split())) a=bisect_left(ary,a) bit.add(1,-1) bit.add(a+1,2) if ml<=a<mr: mv+=b ml,mr=a,a+1 else: l,r=1,len(ary)+2 # はじめて0以上になる場所を二分探索→ここがml while r-l>1: x=(r+l)//2 if bit.sum(x)>=0: l,r=l,x else: l,r=x,r # はじめて1以上になる場所を二分探索→ここがmr mv+=b mv+=min(abs(ary[l]-ary[ml]),abs(ary[l]-ary[mr]))+abs(ary[l]-ary[a]) ml=l l,r=1,len(ary)+2 while r-l>1: x=(r+l)//2 if bit.sum(x)>0: l,r=l,x else: l,r=x,r mr=l
77
68
1,762
1,428
q = int(eval(input())) query = [eval(input()) for _ in range(q)] from bisect import bisect_left ary = [-float("inf")] for qq in query: if qq[0] == "1": _, a, _ = list(map(int, qq.split())) ary.append(a) ary.sort() ary.append(float("inf")) class SegmentTree: def __init__(self, size, f=lambda x, y: x + y, default=0): self.size = pow(2, (size - 1).bit_length()) self.f = f self.default = default self.data = [default] * (self.size * 2) def update(self, i, x): i += self.size self.data[i] = x while i: i >>= 1 self.data[i] = self.f(self.data[i * 2], self.data[i * 2 + 1]) # 区間[l,r)へのクエリ def query(self, l, r): l, r = l + self.size, r + self.size lret, rret = self.default, self.default while l < r: if l & 1: lret = self.f(self.data[l], lret) l += 1 if r & 1: r -= 1 rret = self.f(self.data[r], rret) l >>= 1 r >>= 1 return self.f(lret, rret) def get(self, i): return self.data[self.size + i] def add(self, i, x): self.update(i, self.get(i) + x) ml, mr = 0, len(ary) + 1 mv = 0 st = SegmentTree(len(ary)) for qq in query: if qq[0] == "2": print((ary[ml], mv)) else: _, a, b = list(map(int, qq.split())) a = bisect_left(ary, a) st.add(0, -1) st.add(a, 2) if ml <= a < mr: mv += b ml, mr = a, a + 1 else: l, r = 0, len(ary) + 1 # はじめて0以上になる場所を二分探索→ここがml while r - l > 1: x = (r + l) // 2 if st.query(0, x) >= 0: l, r = l, x else: l, r = x, r # はじめて1以上になる場所を二分探索→ここがmr mv += b mv += min(abs(ary[l] - ary[ml]), abs(ary[l] - ary[mr])) + abs( ary[l] - ary[a] ) ml = l l, r = 0, len(ary) + 1 while r - l > 1: x = (r + l) // 2 if st.query(0, x) > 0: l, r = l, x else: l, r = x, r mr = l
q = int(eval(input())) query = [eval(input()) for _ in range(q)] from bisect import bisect_left ary = [-float("inf")] for qq in query: if qq[0] == "1": _, a, _ = list(map(int, qq.split())) ary.append(a) ary.sort() ary.append(float("inf")) class BIT: def __init__(self, n): self.n = n self.data = [0] * (n + 1) self.el = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.data[i] i -= i & -i return s def add(self, i, x): # assert i > 0 self.el[i] += x while i <= self.n: self.data[i] += x i += i & -i def get(self, i, j=None): if j is None: return self.el[i] return self.sum(j) - self.sum(i) ml, mr = 0, len(ary) + 1 mv = 0 bit = BIT(len(ary) + 1) for qq in query: if qq[0] == "2": print((ary[ml], mv)) else: _, a, b = list(map(int, qq.split())) a = bisect_left(ary, a) bit.add(1, -1) bit.add(a + 1, 2) if ml <= a < mr: mv += b ml, mr = a, a + 1 else: l, r = 1, len(ary) + 2 # はじめて0以上になる場所を二分探索→ここがml while r - l > 1: x = (r + l) // 2 if bit.sum(x) >= 0: l, r = l, x else: l, r = x, r # はじめて1以上になる場所を二分探索→ここがmr mv += b mv += min(abs(ary[l] - ary[ml]), abs(ary[l] - ary[mr])) + abs( ary[l] - ary[a] ) ml = l l, r = 1, len(ary) + 2 while r - l > 1: x = (r + l) // 2 if bit.sum(x) > 0: l, r = l, x else: l, r = x, r mr = l
false
11.688312
[ "-class SegmentTree:", "- def __init__(self, size, f=lambda x, y: x + y, default=0):", "- self.size = pow(2, (size - 1).bit_length())", "- self.f = f", "- self.default = default", "- self.data = [default] * (self.size * 2)", "+class BIT:", "+ def __init__(self, n):", ...
false
0.079598
0.043776
1.818306
[ "s854728196", "s555388888" ]
u074220993
p03436
python
s102479235
s307409656
262
134
29,380
26,588
Accepted
Accepted
48.85
H, W = list(map(int, input().split())) import numpy as np Grid = np.array([[0 if x == '.' else -1 for x in eval(input())] for _ in range(H)],dtype='int64') def solveMase(Grid, start, goal): seen = {start} V = [start] while len(V) != 0: v = V.pop(0) if v == goal: return Grid[goal] y,x = v nV = [] if x > 0: nV.append((y,x-1)) if y > 0: nV.append((y-1,x)) if x < W-1: nV.append((y,x+1)) if y < H-1: nV.append((y+1,x)) for nv in nV: if Grid[nv] == -1 or nv in seen: continue Grid[nv] = Grid[v] + 1 V.append(nv) seen.add(nv) return 0 white = len(Grid[Grid == 0])-1 nes_white = solveMase(Grid, (0,0), (H-1,W-1)) if nes_white > 0: ans = white - nes_white else: ans = -1 print(ans)
H, W = list(map(int, input().split())) import numpy as np Grid = np.array([[0 if x == '.' else -1 for x in eval(input())] for _ in range(H)],dtype='int64') def solveMase(Grid, start, goal): #bfsで迷路を解き、スタート-ゴール間の最低必要白マス数を返す seen = {start} V = [start] while len(V) != 0: #bfs v = V.pop(0) if v == goal: return Grid[goal] #移動先nvをリストにまとめる y,x = v nV = [] if x > 0: nV.append((y,x-1)) if y > 0: nV.append((y-1,x)) if x < W-1: nV.append((y,x+1)) if y < H-1: nV.append((y+1,x)) #bfs for nv in nV: if Grid[nv] == -1 or nv in seen: continue Grid[nv] = Grid[v] + 1 V.append(nv) seen.add(nv) return 0 white = len(Grid[Grid == 0])-1 nes_white = solveMase(Grid, (0,0), (H-1,W-1)) print((white-nes_white if nes_white > 0 else -1))
34
30
872
913
H, W = list(map(int, input().split())) import numpy as np Grid = np.array( [[0 if x == "." else -1 for x in eval(input())] for _ in range(H)], dtype="int64" ) def solveMase(Grid, start, goal): seen = {start} V = [start] while len(V) != 0: v = V.pop(0) if v == goal: return Grid[goal] y, x = v nV = [] if x > 0: nV.append((y, x - 1)) if y > 0: nV.append((y - 1, x)) if x < W - 1: nV.append((y, x + 1)) if y < H - 1: nV.append((y + 1, x)) for nv in nV: if Grid[nv] == -1 or nv in seen: continue Grid[nv] = Grid[v] + 1 V.append(nv) seen.add(nv) return 0 white = len(Grid[Grid == 0]) - 1 nes_white = solveMase(Grid, (0, 0), (H - 1, W - 1)) if nes_white > 0: ans = white - nes_white else: ans = -1 print(ans)
H, W = list(map(int, input().split())) import numpy as np Grid = np.array( [[0 if x == "." else -1 for x in eval(input())] for _ in range(H)], dtype="int64" ) def solveMase(Grid, start, goal): # bfsで迷路を解き、スタート-ゴール間の最低必要白マス数を返す seen = {start} V = [start] while len(V) != 0: # bfs v = V.pop(0) if v == goal: return Grid[goal] # 移動先nvをリストにまとめる y, x = v nV = [] if x > 0: nV.append((y, x - 1)) if y > 0: nV.append((y - 1, x)) if x < W - 1: nV.append((y, x + 1)) if y < H - 1: nV.append((y + 1, x)) # bfs for nv in nV: if Grid[nv] == -1 or nv in seen: continue Grid[nv] = Grid[v] + 1 V.append(nv) seen.add(nv) return 0 white = len(Grid[Grid == 0]) - 1 nes_white = solveMase(Grid, (0, 0), (H - 1, W - 1)) print((white - nes_white if nes_white > 0 else -1))
false
11.764706
[ "-def solveMase(Grid, start, goal):", "+def solveMase(Grid, start, goal): # bfsで迷路を解き、スタート-ゴール間の最低必要白マス数を返す", "- while len(V) != 0:", "+ while len(V) != 0: # bfs", "+ # 移動先nvをリストにまとめる", "+ # bfs", "-if nes_white > 0:", "- ans = white - nes_white", "-else:", "- ans = -1"...
false
0.181782
0.656326
0.276969
[ "s102479235", "s307409656" ]
u842401785
p02775
python
s613794434
s866399913
760
508
133,496
133,496
Accepted
Accepted
33.16
n = eval(input()) s = [] for c in n: s.append(int(c)) s.reverse() l = len(s) INF = 1000000000 def get_next(c): ret = [ [INF, INF], [INF, INF], ] # for a in range(10): # for b in range(10): # if a - b == c: # ret[0][0] = min(ret[0][0], a + b) # if 10 + a - b == c: # ret[0][1] = min(ret[0][1], a + b) # if a - 1 - b == c: # ret[1][0] = min(ret[1][0], a + b) # if 10 + a - 1 - b == c: # ret[1][1] = min(ret[1][1], a + b) for b in range(10): a = c + b if 0 <= a < 10: ret[0][0] = min(ret[0][0], a+b) a = c + b - 10 if 0 <= a < 10: ret[0][1] = min(ret[0][1], a+b) a = c + b + 1 if 0 <= a < 10: ret[1][0] = min(ret[1][0], a + b) a = c + b - 10 + 1 if 0 <= a < 10: ret[1][1] = min(ret[1][1], a + b) return ret dp = [[0 for _ in range(l+1)] for _ in range(2)] dp[1][0] = INF for i, c in enumerate(s): next_step = get_next(c) dp[0][i+1] = min(dp[0][i]+next_step[0][0], dp[1][i]+next_step[1][0]) dp[1][i+1] = min(dp[0][i]+next_step[0][1], dp[1][i]+next_step[1][1]) print((min(dp[0][l], dp[1][l]+1))) # print(dp)
n = eval(input()) s = [] for c in n: s.append(int(c)) s.reverse() l = len(s) INF = 1000000000 def get_next(c): ret = [ [INF, INF], [INF, INF], ] # for a in range(10): # for b in range(10): # if a - b == c: # ret[0][0] = min(ret[0][0], a + b) # if 10 + a - b == c: # ret[0][1] = min(ret[0][1], a + b) # if a - 1 - b == c: # ret[1][0] = min(ret[1][0], a + b) # if 10 + a - 1 - b == c: # ret[1][1] = min(ret[1][1], a + b) # for b in range(10): # a = c + b # if 0 <= a < 10: # ret[0][0] = min(ret[0][0], a+b) # a = c + b - 10 # if 0 <= a < 10: # ret[0][1] = min(ret[0][1], a+b) # a = c + b + 1 # if 0 <= a < 10: # ret[1][0] = min(ret[1][0], a + b) # a = c + b - 10 + 1 # if 0 <= a < 10: # ret[1][1] = min(ret[1][1], a + b) a = c ret[0][0] = min(ret[0][0], a) b = 10 - c if b < 10: ret[0][1] = min(ret[0][1], b) a = c + 1 if a < 10: ret[1][0] = min(ret[1][0], a) b = 9-c ret[1][1] = min(ret[1][1], b) return ret dp = [[0 for _ in range(l+1)] for _ in range(2)] dp[1][0] = INF for i, c in enumerate(s): next_step = get_next(c) dp[0][i+1] = min(dp[0][i]+next_step[0][0], dp[1][i]+next_step[1][0]) dp[1][i+1] = min(dp[0][i]+next_step[0][1], dp[1][i]+next_step[1][1]) print((min(dp[0][l], dp[1][l]+1))) # print(dp)
51
62
1,335
1,598
n = eval(input()) s = [] for c in n: s.append(int(c)) s.reverse() l = len(s) INF = 1000000000 def get_next(c): ret = [ [INF, INF], [INF, INF], ] # for a in range(10): # for b in range(10): # if a - b == c: # ret[0][0] = min(ret[0][0], a + b) # if 10 + a - b == c: # ret[0][1] = min(ret[0][1], a + b) # if a - 1 - b == c: # ret[1][0] = min(ret[1][0], a + b) # if 10 + a - 1 - b == c: # ret[1][1] = min(ret[1][1], a + b) for b in range(10): a = c + b if 0 <= a < 10: ret[0][0] = min(ret[0][0], a + b) a = c + b - 10 if 0 <= a < 10: ret[0][1] = min(ret[0][1], a + b) a = c + b + 1 if 0 <= a < 10: ret[1][0] = min(ret[1][0], a + b) a = c + b - 10 + 1 if 0 <= a < 10: ret[1][1] = min(ret[1][1], a + b) return ret dp = [[0 for _ in range(l + 1)] for _ in range(2)] dp[1][0] = INF for i, c in enumerate(s): next_step = get_next(c) dp[0][i + 1] = min(dp[0][i] + next_step[0][0], dp[1][i] + next_step[1][0]) dp[1][i + 1] = min(dp[0][i] + next_step[0][1], dp[1][i] + next_step[1][1]) print((min(dp[0][l], dp[1][l] + 1))) # print(dp)
n = eval(input()) s = [] for c in n: s.append(int(c)) s.reverse() l = len(s) INF = 1000000000 def get_next(c): ret = [ [INF, INF], [INF, INF], ] # for a in range(10): # for b in range(10): # if a - b == c: # ret[0][0] = min(ret[0][0], a + b) # if 10 + a - b == c: # ret[0][1] = min(ret[0][1], a + b) # if a - 1 - b == c: # ret[1][0] = min(ret[1][0], a + b) # if 10 + a - 1 - b == c: # ret[1][1] = min(ret[1][1], a + b) # for b in range(10): # a = c + b # if 0 <= a < 10: # ret[0][0] = min(ret[0][0], a+b) # a = c + b - 10 # if 0 <= a < 10: # ret[0][1] = min(ret[0][1], a+b) # a = c + b + 1 # if 0 <= a < 10: # ret[1][0] = min(ret[1][0], a + b) # a = c + b - 10 + 1 # if 0 <= a < 10: # ret[1][1] = min(ret[1][1], a + b) a = c ret[0][0] = min(ret[0][0], a) b = 10 - c if b < 10: ret[0][1] = min(ret[0][1], b) a = c + 1 if a < 10: ret[1][0] = min(ret[1][0], a) b = 9 - c ret[1][1] = min(ret[1][1], b) return ret dp = [[0 for _ in range(l + 1)] for _ in range(2)] dp[1][0] = INF for i, c in enumerate(s): next_step = get_next(c) dp[0][i + 1] = min(dp[0][i] + next_step[0][0], dp[1][i] + next_step[1][0]) dp[1][i + 1] = min(dp[0][i] + next_step[0][1], dp[1][i] + next_step[1][1]) print((min(dp[0][l], dp[1][l] + 1))) # print(dp)
false
17.741935
[ "- for b in range(10):", "- a = c + b", "- if 0 <= a < 10:", "- ret[0][0] = min(ret[0][0], a + b)", "- a = c + b - 10", "- if 0 <= a < 10:", "- ret[0][1] = min(ret[0][1], a + b)", "- a = c + b + 1", "- if 0 <= a < 10:", "- ...
false
0.048311
0.047356
1.020173
[ "s613794434", "s866399913" ]
u453968283
p03386
python
s663177959
s748010262
19
17
3,060
3,064
Accepted
Accepted
10.53
ip=[int(x) for x in input().split()] a=ip[0] b=ip[1] k=ip[2] if k>=(b-a+1): for i in range(a,b+1): print(i) else: lw=list(range(a,a+k)) hg=list(range(b-k+1,b+1)) res=list(set(lw+hg)) res.sort() for i in res: print(i)
ip=[int(x) for x in input().split()] a=ip[0];b=ip[1];k=ip[2] ans=list() for i in range(0,k): ans.append(a) ans.append(b) a=a+1 b=b-1 if((a>ip[1])|(b<ip[0])): break res=list(set(ans)) res.sort() for i in res: print(i)
14
14
245
261
ip = [int(x) for x in input().split()] a = ip[0] b = ip[1] k = ip[2] if k >= (b - a + 1): for i in range(a, b + 1): print(i) else: lw = list(range(a, a + k)) hg = list(range(b - k + 1, b + 1)) res = list(set(lw + hg)) res.sort() for i in res: print(i)
ip = [int(x) for x in input().split()] a = ip[0] b = ip[1] k = ip[2] ans = list() for i in range(0, k): ans.append(a) ans.append(b) a = a + 1 b = b - 1 if (a > ip[1]) | (b < ip[0]): break res = list(set(ans)) res.sort() for i in res: print(i)
false
0
[ "-if k >= (b - a + 1):", "- for i in range(a, b + 1):", "- print(i)", "-else:", "- lw = list(range(a, a + k))", "- hg = list(range(b - k + 1, b + 1))", "- res = list(set(lw + hg))", "- res.sort()", "- for i in res:", "- print(i)", "+ans = list()", "+for i in ran...
false
0.038218
0.061841
0.617996
[ "s663177959", "s748010262" ]
u347640436
p03087
python
s532819802
s655288030
902
269
6,164
6,332
Accepted
Accepted
70.18
n, q = list(map(int, input().split())) s = eval(input()) c = [0] * (n + 1) for i in range(2, n + 1): if s[i - 1] == 'C' and s[i - 2] == 'A': c[i] = c[i - 1] + 1 else: c[i] = c[i - 1] for _ in range(q): l, r = list(map(int, input().split())) t = c[r] - c[l - 1] if l > 1 and s[l - 2: l] == 'AC': t -= 1 print(t)
from sys import stdin def main(): readline = stdin.readline n, q = list(map(int, readline().split())) s = eval(input()) c = [0] * (n + 1) for i in range(2, n + 1): if s[i - 1] == 'C' and s[i - 2] == 'A': c[i] = c[i - 1] + 1 else: c[i] = c[i - 1] for _ in range(q): l, r = list(map(int, readline().split())) t = c[r] - c[l - 1] if l >= 2 and s[l - 2: l] == 'AC': t -= 1 print(t) main()
14
18
330
437
n, q = list(map(int, input().split())) s = eval(input()) c = [0] * (n + 1) for i in range(2, n + 1): if s[i - 1] == "C" and s[i - 2] == "A": c[i] = c[i - 1] + 1 else: c[i] = c[i - 1] for _ in range(q): l, r = list(map(int, input().split())) t = c[r] - c[l - 1] if l > 1 and s[l - 2 : l] == "AC": t -= 1 print(t)
from sys import stdin def main(): readline = stdin.readline n, q = list(map(int, readline().split())) s = eval(input()) c = [0] * (n + 1) for i in range(2, n + 1): if s[i - 1] == "C" and s[i - 2] == "A": c[i] = c[i - 1] + 1 else: c[i] = c[i - 1] for _ in range(q): l, r = list(map(int, readline().split())) t = c[r] - c[l - 1] if l >= 2 and s[l - 2 : l] == "AC": t -= 1 print(t) main()
false
22.222222
[ "-n, q = list(map(int, input().split()))", "-s = eval(input())", "-c = [0] * (n + 1)", "-for i in range(2, n + 1):", "- if s[i - 1] == \"C\" and s[i - 2] == \"A\":", "- c[i] = c[i - 1] + 1", "- else:", "- c[i] = c[i - 1]", "-for _ in range(q):", "- l, r = list(map(int, input...
false
0.041249
0.047831
0.862387
[ "s532819802", "s655288030" ]
u479835943
p02832
python
s582640227
s736833746
158
104
25,724
18,332
Accepted
Accepted
34.18
n = int(eval(input())) a = list(map(int, input().split())) ans_lst = [] for ai in a: if len(ans_lst) == 0 and ai == 1: ans_lst.append(1) elif len(ans_lst) > 0 and ans_lst[-1] == ai - 1: ans_lst.append(ai) if len(ans_lst) == 0: print((-1)) else: print((n - len(ans_lst)))
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 for ai in a: if ans == ai - 1: ans += 1 if ans == 0: print((-1)) else: print((n-ans))
12
10
297
165
n = int(eval(input())) a = list(map(int, input().split())) ans_lst = [] for ai in a: if len(ans_lst) == 0 and ai == 1: ans_lst.append(1) elif len(ans_lst) > 0 and ans_lst[-1] == ai - 1: ans_lst.append(ai) if len(ans_lst) == 0: print((-1)) else: print((n - len(ans_lst)))
n = int(eval(input())) a = list(map(int, input().split())) ans = 0 for ai in a: if ans == ai - 1: ans += 1 if ans == 0: print((-1)) else: print((n - ans))
false
16.666667
[ "-ans_lst = []", "+ans = 0", "- if len(ans_lst) == 0 and ai == 1:", "- ans_lst.append(1)", "- elif len(ans_lst) > 0 and ans_lst[-1] == ai - 1:", "- ans_lst.append(ai)", "-if len(ans_lst) == 0:", "+ if ans == ai - 1:", "+ ans += 1", "+if ans == 0:", "- print((n - ...
false
0.038173
0.036355
1.050024
[ "s582640227", "s736833746" ]
u498487134
p02984
python
s771369056
s880534711
252
102
84,452
96,432
Accepted
Accepted
59.52
N=int(eval(input())) A=list(map(int,input().split())) s=sum(A)//2 ans=[0]*N rem=0 for i in range(1,N,2): rem+=A[i] ans[0]=(s-rem)*2 for i in range(1,N): ans[i]=(A[i-1]-ans[i-1]//2)*2 ans[-1]=(A[-1]-ans[0]//2)*2 print((' '.join(map(str, ans))))
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N=I() A=LI() S=sum(A) S2=0 for i in range(1,N,2): S2+=A[i] B=[0]*N B[0]=S-S2*2 for i in range(1,N): B[i]=A[i-1]*2-B[i-1] print((' '.join(map(str, B)))) main()
19
24
268
436
N = int(eval(input())) A = list(map(int, input().split())) s = sum(A) // 2 ans = [0] * N rem = 0 for i in range(1, N, 2): rem += A[i] ans[0] = (s - rem) * 2 for i in range(1, N): ans[i] = (A[i - 1] - ans[i - 1] // 2) * 2 ans[-1] = (A[-1] - ans[0] // 2) * 2 print((" ".join(map(str, ans))))
import sys input = sys.stdin.readline def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod = 10**9 + 7 N = I() A = LI() S = sum(A) S2 = 0 for i in range(1, N, 2): S2 += A[i] B = [0] * N B[0] = S - S2 * 2 for i in range(1, N): B[i] = A[i - 1] * 2 - B[i - 1] print((" ".join(map(str, B)))) main()
false
20.833333
[ "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-s = sum(A) // 2", "-ans = [0] * N", "-rem = 0", "-for i in range(1, N, 2):", "- rem += A[i]", "-ans[0] = (s - rem) * 2", "-for i in range(1, N):", "- ans[i] = (A[i - 1] - ans[i - 1] // 2) * 2", "-ans[-1] = (A[-1] - ans[0]...
false
0.036659
0.085958
0.426479
[ "s771369056", "s880534711" ]
u844005364
p03161
python
s873861812
s197687408
519
408
56,416
55,008
Accepted
Accepted
21.39
n, k = [int(i) for i in input().split()] h = [int(i) for i in input().split()] def frog(n, k, h): d = [float('inf')] * n d[0] = 0 for i in range(1, n): d[i] = min( d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i) ) return d[n - 1] print((frog(n, k, h)))
n, k = [int(i) for i in input().split()] h = [int(i) for i in input().split()] dp = [float('inf')] * n dp[0] = 0 for i in range(1, n): for j in range(max(i - k, 0), i): dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j])) print((dp[n - 1]))
15
10
325
254
n, k = [int(i) for i in input().split()] h = [int(i) for i in input().split()] def frog(n, k, h): d = [float("inf")] * n d[0] = 0 for i in range(1, n): d[i] = min(d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i)) return d[n - 1] print((frog(n, k, h)))
n, k = [int(i) for i in input().split()] h = [int(i) for i in input().split()] dp = [float("inf")] * n dp[0] = 0 for i in range(1, n): for j in range(max(i - k, 0), i): dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j])) print((dp[n - 1]))
false
33.333333
[ "-", "-", "-def frog(n, k, h):", "- d = [float(\"inf\")] * n", "- d[0] = 0", "- for i in range(1, n):", "- d[i] = min(d[j] + abs(h[i] - h[j]) for j in range(max(i - k, 0), i))", "- return d[n - 1]", "-", "-", "-print((frog(n, k, h)))", "+dp = [float(\"inf\")] * n", "+dp[0]...
false
0.035283
0.038257
0.922256
[ "s873861812", "s197687408" ]
u864197622
p03040
python
s596881065
s570253753
1,454
631
11,108
11,100
Accepted
Accepted
56.6
from heapq import * Q = int(eval(input())) L, R = [], [] ans = 0 for _ in range(Q): a = [int(a) for a in input().split()] if a[0] == 1: ans += a[2] if len(L) == 0 or a[1] <= -L[0]: heappush(L, -a[1]) ans += -L[0] - a[1] else: heappush(R, a[1]) ans += a[1] + L[0] if len(R) > len(L): ans -= R[0] + L[0] heappush(L, -heappop(R)) elif len(L) - len(R) >= 2: heappush(R, -heappop(L)) else: print((-L[0], ans))
import sys input = sys.stdin.readline from heapq import * Q = int(eval(input())) L, R = [], [] ans = 0 for _ in range(Q): a = [int(a) for a in input().split()] if a[0] == 1: ans += a[2] if len(L) == 0 or a[1] <= -L[0]: heappush(L, -a[1]) ans += -L[0] - a[1] else: heappush(R, a[1]) ans += a[1] + L[0] if len(R) > len(L): ans -= R[0] + L[0] heappush(L, -heappop(R)) elif len(L) - len(R) >= 2: heappush(R, -heappop(L)) else: print((-L[0], ans))
21
23
560
601
from heapq import * Q = int(eval(input())) L, R = [], [] ans = 0 for _ in range(Q): a = [int(a) for a in input().split()] if a[0] == 1: ans += a[2] if len(L) == 0 or a[1] <= -L[0]: heappush(L, -a[1]) ans += -L[0] - a[1] else: heappush(R, a[1]) ans += a[1] + L[0] if len(R) > len(L): ans -= R[0] + L[0] heappush(L, -heappop(R)) elif len(L) - len(R) >= 2: heappush(R, -heappop(L)) else: print((-L[0], ans))
import sys input = sys.stdin.readline from heapq import * Q = int(eval(input())) L, R = [], [] ans = 0 for _ in range(Q): a = [int(a) for a in input().split()] if a[0] == 1: ans += a[2] if len(L) == 0 or a[1] <= -L[0]: heappush(L, -a[1]) ans += -L[0] - a[1] else: heappush(R, a[1]) ans += a[1] + L[0] if len(R) > len(L): ans -= R[0] + L[0] heappush(L, -heappop(R)) elif len(L) - len(R) >= 2: heappush(R, -heappop(L)) else: print((-L[0], ans))
false
8.695652
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.053251
0.035609
1.495417
[ "s596881065", "s570253753" ]
u600402037
p03033
python
s387132618
s388143618
1,880
1,663
134,524
134,300
Accepted
Accepted
11.54
# coding: utf-8 import sys from heapq import heapify, heappop, heappush sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, Q = lr() STX = [tuple(lr()) for _ in range(N)] STX.sort(key=lambda x: x[2], reverse=True) event = [] for s, t, x in STX: event.append((s-x, 0, x)) event.append((t-x, -1, x)) for i in range(Q): d = ir() event.append((d, 1, i)) event.sort() answer = [-1] * Q cur = set() flag = False INF = 10 ** 10 min_x = INF for a, b, c in event: if b == 0: cur.add(c) if c < min_x: min_x = c flag = True elif b == -1: cur.remove(c) if min_x == c: flag = False elif b == 1: if cur: if not flag: min_x = min(cur) flag = True answer[c] = min_x print(('\n'.join(map(str, answer)))) # 19
# coding: utf-8 import sys from heapq import heapify, heappop, heappush sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, Q = lr() STX = [tuple(lr()) for _ in range(N)] event = [] append = event.append for s, t, x in STX: append((s-x, 0, x)) append((t-x, -1, x)) for i in range(Q): d = ir() append((d, 1, i)) event.sort() answer = [-1] * Q cur = set() flag = False INF = 10 ** 10 min_x = INF add = cur.add remove = cur.remove for a, b, c in event: if b == 0: add(c) if c < min_x: min_x = c flag = True elif b == -1: remove(c) if min_x == c: flag = False elif b == 1: if cur: if not flag: min_x = min(cur) flag = True answer[c] = min_x print(('\n'.join(map(str, answer))))
45
46
958
941
# coding: utf-8 import sys from heapq import heapify, heappop, heappush sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, Q = lr() STX = [tuple(lr()) for _ in range(N)] STX.sort(key=lambda x: x[2], reverse=True) event = [] for s, t, x in STX: event.append((s - x, 0, x)) event.append((t - x, -1, x)) for i in range(Q): d = ir() event.append((d, 1, i)) event.sort() answer = [-1] * Q cur = set() flag = False INF = 10**10 min_x = INF for a, b, c in event: if b == 0: cur.add(c) if c < min_x: min_x = c flag = True elif b == -1: cur.remove(c) if min_x == c: flag = False elif b == 1: if cur: if not flag: min_x = min(cur) flag = True answer[c] = min_x print(("\n".join(map(str, answer)))) # 19
# coding: utf-8 import sys from heapq import heapify, heappop, heappush sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, Q = lr() STX = [tuple(lr()) for _ in range(N)] event = [] append = event.append for s, t, x in STX: append((s - x, 0, x)) append((t - x, -1, x)) for i in range(Q): d = ir() append((d, 1, i)) event.sort() answer = [-1] * Q cur = set() flag = False INF = 10**10 min_x = INF add = cur.add remove = cur.remove for a, b, c in event: if b == 0: add(c) if c < min_x: min_x = c flag = True elif b == -1: remove(c) if min_x == c: flag = False elif b == 1: if cur: if not flag: min_x = min(cur) flag = True answer[c] = min_x print(("\n".join(map(str, answer))))
false
2.173913
[ "-STX.sort(key=lambda x: x[2], reverse=True)", "+append = event.append", "- event.append((s - x, 0, x))", "- event.append((t - x, -1, x))", "+ append((s - x, 0, x))", "+ append((t - x, -1, x))", "- event.append((d, 1, i))", "+ append((d, 1, i))", "+add = cur.add", "+remove = cur....
false
0.03715
0.03812
0.974534
[ "s387132618", "s388143618" ]
u497625442
p03287
python
s462986883
s261394752
124
85
14,956
16,832
Accepted
Accepted
31.45
from collections import Counter c = Counter() N, M = list(map(int,input().split())) a = list(map(int,input().split())) s = 0 c[s] += 1 for i in range(N): s = (s + a[i]) % M c[s] += 1 # print(c) S=0 # t=0 for (i,k) in list(c.items()): if k > 1: S += (k-1)*k//2 # t += k print(S) # print(t)
from collections import Counter from itertools import accumulate from functools import reduce N, M = list(map(int, input().split())) A = [int(x) for x in input().split()] c = Counter([0] + [x % M for x in accumulate(A)]) ans = reduce(lambda x,y:x+y, [v*(v-1)//2 for v in list(c.values())]) print(ans)
19
10
308
300
from collections import Counter c = Counter() N, M = list(map(int, input().split())) a = list(map(int, input().split())) s = 0 c[s] += 1 for i in range(N): s = (s + a[i]) % M c[s] += 1 # print(c) S = 0 # t=0 for (i, k) in list(c.items()): if k > 1: S += (k - 1) * k // 2 # t += k print(S) # print(t)
from collections import Counter from itertools import accumulate from functools import reduce N, M = list(map(int, input().split())) A = [int(x) for x in input().split()] c = Counter([0] + [x % M for x in accumulate(A)]) ans = reduce(lambda x, y: x + y, [v * (v - 1) // 2 for v in list(c.values())]) print(ans)
false
47.368421
[ "+from itertools import accumulate", "+from functools import reduce", "-c = Counter()", "-a = list(map(int, input().split()))", "-s = 0", "-c[s] += 1", "-for i in range(N):", "- s = (s + a[i]) % M", "- c[s] += 1", "-# print(c)", "-S = 0", "-# t=0", "-for (i, k) in list(c.items()):", ...
false
0.058934
0.057762
1.020278
[ "s462986883", "s261394752" ]
u750838232
p02888
python
s773511862
s644724906
1,510
1,317
3,316
3,188
Accepted
Accepted
12.78
import bisect n = int(eval(input())) l = sorted(list(map(int, input().split()))) ans = 0 for i in range(n): for j in range(i+1, n): k = bisect.bisect_left(l, l[i]+l[j]) if k > j: ans += k - j - 1 print(ans)
import bisect n = int(eval(input())) l = sorted(list(map(int, input().split()))) ans = 0 for i in range(n): for j in range(i+1, n): k = bisect.bisect_left(l, l[i]+l[j]) #if k > j: ans += k - j - 1 print(ans)
14
14
234
233
import bisect n = int(eval(input())) l = sorted(list(map(int, input().split()))) ans = 0 for i in range(n): for j in range(i + 1, n): k = bisect.bisect_left(l, l[i] + l[j]) if k > j: ans += k - j - 1 print(ans)
import bisect n = int(eval(input())) l = sorted(list(map(int, input().split()))) ans = 0 for i in range(n): for j in range(i + 1, n): k = bisect.bisect_left(l, l[i] + l[j]) # if k > j: ans += k - j - 1 print(ans)
false
0
[ "- if k > j:", "- ans += k - j - 1", "+ # if k > j:", "+ ans += k - j - 1" ]
false
0.048159
0.083993
0.573372
[ "s773511862", "s644724906" ]
u183422236
p02684
python
s010227653
s088203851
1,685
105
103,404
95,120
Accepted
Accepted
93.77
import bisect n, k = list(map(int, input().split())) a = list(map(int, input().split())) seen = [] seen_sort = [1] start = 1 while True: tmp = a[start - 1] seen.append(start) index = bisect.bisect_left(seen_sort, tmp) if index >= len(seen_sort) or seen_sort[index] != tmp: seen_sort.insert(index, tmp) else: repeat_index = seen.index(tmp) repeat_len = len(seen) - repeat_index break start = tmp if k <= repeat_index: print((seen[k])) else: print((seen[repeat_index + ((k - repeat_index) % repeat_len)]))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) visited = [] visited_index = [-1] * n pre = 0 while visited_index[pre] == -1: now = a[pre] visited.append(pre) visited_index[pre] = len(visited) pre = now - 1 loop = len(visited) - visited_index[pre] + 1 head = visited_index[pre] - 1 if k < head: print((visited[k] + 1)) else: k -= head k %= loop print((visited[head + k] + 1))
23
21
581
447
import bisect n, k = list(map(int, input().split())) a = list(map(int, input().split())) seen = [] seen_sort = [1] start = 1 while True: tmp = a[start - 1] seen.append(start) index = bisect.bisect_left(seen_sort, tmp) if index >= len(seen_sort) or seen_sort[index] != tmp: seen_sort.insert(index, tmp) else: repeat_index = seen.index(tmp) repeat_len = len(seen) - repeat_index break start = tmp if k <= repeat_index: print((seen[k])) else: print((seen[repeat_index + ((k - repeat_index) % repeat_len)]))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) visited = [] visited_index = [-1] * n pre = 0 while visited_index[pre] == -1: now = a[pre] visited.append(pre) visited_index[pre] = len(visited) pre = now - 1 loop = len(visited) - visited_index[pre] + 1 head = visited_index[pre] - 1 if k < head: print((visited[k] + 1)) else: k -= head k %= loop print((visited[head + k] + 1))
false
8.695652
[ "-import bisect", "-", "-seen = []", "-seen_sort = [1]", "-start = 1", "-while True:", "- tmp = a[start - 1]", "- seen.append(start)", "- index = bisect.bisect_left(seen_sort, tmp)", "- if index >= len(seen_sort) or seen_sort[index] != tmp:", "- seen_sort.insert(index, tmp)", ...
false
0.078262
0.035905
2.179721
[ "s010227653", "s088203851" ]
u583507988
p03165
python
s691773766
s623955548
313
281
144,128
144,604
Accepted
Accepted
10.22
S=eval(input()) T=eval(input()) n=len(S) m=len(T) dp=[[0]*(m+1) for i in range(n+1)] for i in range(n): for j in range(m): dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j],dp[i][j]+(S[i]==T[j])) ans='' while n>0 and m>0: if dp[n][m]==dp[n-1][m]: n-=1 elif dp[n][m]==dp[n][m-1]: m-=1 else: n-=1 m-=1 ans=S[n]+ans print(ans)
S=eval(input()) T=eval(input()) n=len(S) m=len(T) dp=[[0]*(m+1) for i in range(n+1)] for i in range(n): for j in range(m): if S[i]==T[j]: dp[i+1][j+1]=dp[i][j]+1 else: dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]) ans='' while n>0 and m>0: if dp[n][m]==dp[n-1][m]: n-=1 elif dp[n][m]==dp[n][m-1]: m-=1 else: n-=1 m-=1 ans=S[n]+ans print(ans)
19
22
350
392
S = eval(input()) T = eval(input()) n = len(S) m = len(T) dp = [[0] * (m + 1) for i in range(n + 1)] for i in range(n): for j in range(m): dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j], dp[i][j] + (S[i] == T[j])) ans = "" while n > 0 and m > 0: if dp[n][m] == dp[n - 1][m]: n -= 1 elif dp[n][m] == dp[n][m - 1]: m -= 1 else: n -= 1 m -= 1 ans = S[n] + ans print(ans)
S = eval(input()) T = eval(input()) n = len(S) m = len(T) dp = [[0] * (m + 1) for i in range(n + 1)] for i in range(n): for j in range(m): if S[i] == T[j]: dp[i + 1][j + 1] = dp[i][j] + 1 else: dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]) ans = "" while n > 0 and m > 0: if dp[n][m] == dp[n - 1][m]: n -= 1 elif dp[n][m] == dp[n][m - 1]: m -= 1 else: n -= 1 m -= 1 ans = S[n] + ans print(ans)
false
13.636364
[ "- dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j], dp[i][j] + (S[i] == T[j]))", "+ if S[i] == T[j]:", "+ dp[i + 1][j + 1] = dp[i][j] + 1", "+ else:", "+ dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])" ]
false
0.088803
0.042817
2.073991
[ "s691773766", "s623955548" ]
u312025627
p03437
python
s002648851
s603140062
179
165
38,256
38,384
Accepted
Accepted
7.82
x, y = (int(i) for i in input().split()) if x%y == 0: print((-1)) else: print(x)
def main(): X, Y = (int(i) for i in input().split()) if X % Y == 0: print((-1)) else: print(X) if __name__ == '__main__': main()
5
10
86
170
x, y = (int(i) for i in input().split()) if x % y == 0: print((-1)) else: print(x)
def main(): X, Y = (int(i) for i in input().split()) if X % Y == 0: print((-1)) else: print(X) if __name__ == "__main__": main()
false
50
[ "-x, y = (int(i) for i in input().split())", "-if x % y == 0:", "- print((-1))", "-else:", "- print(x)", "+def main():", "+ X, Y = (int(i) for i in input().split())", "+ if X % Y == 0:", "+ print((-1))", "+ else:", "+ print(X)", "+", "+", "+if __name__ == \"__m...
false
0.045037
0.045128
0.997988
[ "s002648851", "s603140062" ]
u418826171
p03470
python
s172972650
s242910643
31
27
9,144
9,168
Accepted
Accepted
12.9
N = int(eval(input())) d = sorted([int(eval(input())) for i in range(N)]) ans = 1 for i in range(N-1): if d[i] < d[i+1]: ans += 1 print(ans)
N = int(eval(input())) d = [int(eval(input())) for i in range(N)] print((len(set(d))))
7
3
146
74
N = int(eval(input())) d = sorted([int(eval(input())) for i in range(N)]) ans = 1 for i in range(N - 1): if d[i] < d[i + 1]: ans += 1 print(ans)
N = int(eval(input())) d = [int(eval(input())) for i in range(N)] print((len(set(d))))
false
57.142857
[ "-d = sorted([int(eval(input())) for i in range(N)])", "-ans = 1", "-for i in range(N - 1):", "- if d[i] < d[i + 1]:", "- ans += 1", "-print(ans)", "+d = [int(eval(input())) for i in range(N)]", "+print((len(set(d))))" ]
false
0.048242
0.048726
0.990064
[ "s172972650", "s242910643" ]
u440566786
p02912
python
s766435097
s171389027
401
367
68,224
63,856
Accepted
Accepted
8.48
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda:sys.stdin.readline().rstrip() from heapq import heappush,heappop,heapify def resolve(): n,m=list(map(int,input().split())) A=list([-int(x) for x in input().split()]) heapify(A) for _ in range(m): x=-heappop(A) x//=2 heappush(A,-x) print((-sum(A))) resolve()
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 # 998244353 input=lambda:sys.stdin.readline().rstrip() class Heap(object): def __init__(self, A): self._heap = [] # heapify は O(n) でできるらしいが、O(nlogn) で妥協 # cf. https://github.com/python/cpython/blob/3.8/Lib/heapq.py for a in A: self.append(a) def __len__(self): return len(self._heap) def __bool__(self): return bool(self._heap) def front(self): assert self return self._heap[0] def append(self, x): self._heap.append(x) now = len(self)-1 heap = self._heap # n の親は (n-1)//2 while now!=0 and heap[now] < heap[(now-1)//2]: heap[now], heap[(now-1)//2] = heap[(now-1)//2], heap[now] now = (now-1)//2 def pop(self): assert self if len(self)==1: return self._heap.pop() heap = self._heap res, heap[0] = heap[0], heap.pop() # n の子は 2*n+1, 2*n+2 now = 0 while(1): if now*2+1 >= len(self): break # 子が存在しない # 子がひとつだけのとき、必要なら入れ替えて終わり if now*2+1 == len(self)-1: if heap[now] > heap[now*2+1]: heap[now], heap[now*2+1] = heap[now*2+1], heap[now] break # 子が複数のとき else: # 親、子1、子2のうち、親が最小であれば終わり if min(heap[now], heap[2*now+1], heap[2*now+2]) == heap[now]: break # そうでないとき、子のうち小さい方を親と入れ替える next = min((heap[2*now+1],2*now+1), (heap[2*now+2],2*now+2))[1] heap[now], heap[next] = heap[next], heap[now] now = next return res def sort(self): return [self.pop() for _ in range(len(self))] def resolve(): n, m = list(map(int,input().split())) A = list([-int(x) for x in input().split()]) heap = Heap(A) for _ in range(m): x = -heap.pop() x //= 2 heap.append(-x) print((-sum(heap._heap))) resolve()
17
74
400
2,131
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() from heapq import heappush, heappop, heapify def resolve(): n, m = list(map(int, input().split())) A = list([-int(x) for x in input().split()]) heapify(A) for _ in range(m): x = -heappop(A) x //= 2 heappush(A, -x) print((-sum(A))) resolve()
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 # 998244353 input = lambda: sys.stdin.readline().rstrip() class Heap(object): def __init__(self, A): self._heap = [] # heapify は O(n) でできるらしいが、O(nlogn) で妥協 # cf. https://github.com/python/cpython/blob/3.8/Lib/heapq.py for a in A: self.append(a) def __len__(self): return len(self._heap) def __bool__(self): return bool(self._heap) def front(self): assert self return self._heap[0] def append(self, x): self._heap.append(x) now = len(self) - 1 heap = self._heap # n の親は (n-1)//2 while now != 0 and heap[now] < heap[(now - 1) // 2]: heap[now], heap[(now - 1) // 2] = heap[(now - 1) // 2], heap[now] now = (now - 1) // 2 def pop(self): assert self if len(self) == 1: return self._heap.pop() heap = self._heap res, heap[0] = heap[0], heap.pop() # n の子は 2*n+1, 2*n+2 now = 0 while 1: if now * 2 + 1 >= len(self): break # 子が存在しない # 子がひとつだけのとき、必要なら入れ替えて終わり if now * 2 + 1 == len(self) - 1: if heap[now] > heap[now * 2 + 1]: heap[now], heap[now * 2 + 1] = heap[now * 2 + 1], heap[now] break # 子が複数のとき else: # 親、子1、子2のうち、親が最小であれば終わり if min(heap[now], heap[2 * now + 1], heap[2 * now + 2]) == heap[now]: break # そうでないとき、子のうち小さい方を親と入れ替える next = min( (heap[2 * now + 1], 2 * now + 1), (heap[2 * now + 2], 2 * now + 2) )[1] heap[now], heap[next] = heap[next], heap[now] now = next return res def sort(self): return [self.pop() for _ in range(len(self))] def resolve(): n, m = list(map(int, input().split())) A = list([-int(x) for x in input().split()]) heap = Heap(A) for _ in range(m): x = -heap.pop() x //= 2 heap.append(-x) print((-sum(heap._heap))) resolve()
false
77.027027
[ "-MOD = 10**9 + 7", "+MOD = 10**9 + 7 # 998244353", "-from heapq import heappush, heappop, heapify", "+", "+", "+class Heap(object):", "+ def __init__(self, A):", "+ self._heap = []", "+ # heapify は O(n) でできるらしいが、O(nlogn) で妥協", "+ # cf. https://github.com/python/cpython/bl...
false
0.113534
0.136637
0.830919
[ "s766435097", "s171389027" ]
u867848444
p02887
python
s189891475
s807829149
196
42
45,424
3,316
Accepted
Accepted
78.57
n=int(eval(input())) s=eval(input()) ss=set(s) l=s[0] count=1 for j in range(n): if l!=s[j]: count+=1 l=s[j] print(count)
n=int(eval(input())) s=eval(input()) cnt=1 temp=s[0] for i in range(n): if temp!=s[i]: cnt+=1 temp=s[i] print(cnt)
10
9
138
130
n = int(eval(input())) s = eval(input()) ss = set(s) l = s[0] count = 1 for j in range(n): if l != s[j]: count += 1 l = s[j] print(count)
n = int(eval(input())) s = eval(input()) cnt = 1 temp = s[0] for i in range(n): if temp != s[i]: cnt += 1 temp = s[i] print(cnt)
false
10
[ "-ss = set(s)", "-l = s[0]", "-count = 1", "-for j in range(n):", "- if l != s[j]:", "- count += 1", "- l = s[j]", "-print(count)", "+cnt = 1", "+temp = s[0]", "+for i in range(n):", "+ if temp != s[i]:", "+ cnt += 1", "+ temp = s[i]", "+print(cnt)" ]
false
0.044942
0.044852
1.002
[ "s189891475", "s807829149" ]
u670180528
p02889
python
s413638726
s945574737
642
568
40,792
40,760
Accepted
Accepted
11.53
from scipy.sparse.csgraph import floyd_warshall import numpy as np n,m,l,*L=list(map(int,open(0).read().split())) abc=L[:3*m];st=L[3*m+1:] town=[[float("inf")]*n for _ in range(n)] for a,b,c in zip(*[iter(abc)]*3): if c<=l: town[a-1][b-1]=c fw=floyd_warshall(town,0) ti=floyd_warshall(np.where(fw<=l,1,fw),0) for s,t in zip(*[iter(st)]*2): if ti[s-1,t-1]==float("inf"): print((-1)) else: print((int(ti[s-1,t-1]-1)))
def main(): from scipy.sparse.csgraph import floyd_warshall import numpy as np n, m, l, *L = list(map(int, open(0).read().split())) abc = L[:3 * m]; st = L[3 * m + 1:] r = [[float("inf")] * n for _ in range(n)] for a, b, c in zip(*[iter(abc)] * 3): if c <= l: r[a - 1][b - 1] = c fw = floyd_warshall(r, 0) ans = floyd_warshall(np.where(fw <= l, 1, fw), 0) - 1 for s, t in zip(*[iter(st)] * 2): x = ans[s - 1, t - 1] if x == float("inf"): print((-1)) else: print((int(x))) if __name__ == "__main__": main()
15
21
428
542
from scipy.sparse.csgraph import floyd_warshall import numpy as np n, m, l, *L = list(map(int, open(0).read().split())) abc = L[: 3 * m] st = L[3 * m + 1 :] town = [[float("inf")] * n for _ in range(n)] for a, b, c in zip(*[iter(abc)] * 3): if c <= l: town[a - 1][b - 1] = c fw = floyd_warshall(town, 0) ti = floyd_warshall(np.where(fw <= l, 1, fw), 0) for s, t in zip(*[iter(st)] * 2): if ti[s - 1, t - 1] == float("inf"): print((-1)) else: print((int(ti[s - 1, t - 1] - 1)))
def main(): from scipy.sparse.csgraph import floyd_warshall import numpy as np n, m, l, *L = list(map(int, open(0).read().split())) abc = L[: 3 * m] st = L[3 * m + 1 :] r = [[float("inf")] * n for _ in range(n)] for a, b, c in zip(*[iter(abc)] * 3): if c <= l: r[a - 1][b - 1] = c fw = floyd_warshall(r, 0) ans = floyd_warshall(np.where(fw <= l, 1, fw), 0) - 1 for s, t in zip(*[iter(st)] * 2): x = ans[s - 1, t - 1] if x == float("inf"): print((-1)) else: print((int(x))) if __name__ == "__main__": main()
false
28.571429
[ "-from scipy.sparse.csgraph import floyd_warshall", "-import numpy as np", "+def main():", "+ from scipy.sparse.csgraph import floyd_warshall", "+ import numpy as np", "-n, m, l, *L = list(map(int, open(0).read().split()))", "-abc = L[: 3 * m]", "-st = L[3 * m + 1 :]", "-town = [[float(\"inf\"...
false
0.298478
0.284051
1.050793
[ "s413638726", "s945574737" ]
u057916330
p03221
python
s711746000
s615152256
753
691
38,420
39,152
Accepted
Accepted
8.23
# https://abc113.contest.atcoder.jp/tasks/abc113_c def pad(n): return '{:0>6}'.format(n) N, M = list(map(int, input().split())) data = [None for _ in range(M)] for i in range(M): Pi, Yi = list(map(int, input().split())) data[i] = [Pi, Yi, 1, i] data.sort(key=lambda x: x[1]) # sort by year data.sort(key=lambda x: x[0]) # sort by prefectures for i in range(1, M): if data[i][0] == data[i - 1][0]: data[i][2] = data[i - 1][2] + 1 data.sort(key=lambda x: x[-1]) # original order ans = [] for di in data: ans.append(pad(di[0]) + pad(di[2])) print(('\n'.join(ans)))
# https://abc113.contest.atcoder.jp/tasks/abc113_c def pad(n): return '{:0>6}'.format(n) N, M = list(map(int, input().split())) work = [None for _ in range(M)] orig = [None for _ in range(M)] # retains original order for i in range(M): Pi, Yi = list(map(int, input().split())) data = [Pi, Yi, 1, i] work[i] = data orig[i] = data work.sort(key=lambda x: x[1]) # sort by year work.sort(key=lambda x: x[0]) # sort by prefectures for i in range(1, M): if work[i][0] == work[i - 1][0]: work[i][2] = work[i - 1][2] + 1 ans = [] for di in orig: ans.append(pad(di[0]) + pad(di[2])) print(('\n'.join(ans)))
23
25
606
652
# https://abc113.contest.atcoder.jp/tasks/abc113_c def pad(n): return "{:0>6}".format(n) N, M = list(map(int, input().split())) data = [None for _ in range(M)] for i in range(M): Pi, Yi = list(map(int, input().split())) data[i] = [Pi, Yi, 1, i] data.sort(key=lambda x: x[1]) # sort by year data.sort(key=lambda x: x[0]) # sort by prefectures for i in range(1, M): if data[i][0] == data[i - 1][0]: data[i][2] = data[i - 1][2] + 1 data.sort(key=lambda x: x[-1]) # original order ans = [] for di in data: ans.append(pad(di[0]) + pad(di[2])) print(("\n".join(ans)))
# https://abc113.contest.atcoder.jp/tasks/abc113_c def pad(n): return "{:0>6}".format(n) N, M = list(map(int, input().split())) work = [None for _ in range(M)] orig = [None for _ in range(M)] # retains original order for i in range(M): Pi, Yi = list(map(int, input().split())) data = [Pi, Yi, 1, i] work[i] = data orig[i] = data work.sort(key=lambda x: x[1]) # sort by year work.sort(key=lambda x: x[0]) # sort by prefectures for i in range(1, M): if work[i][0] == work[i - 1][0]: work[i][2] = work[i - 1][2] + 1 ans = [] for di in orig: ans.append(pad(di[0]) + pad(di[2])) print(("\n".join(ans)))
false
8
[ "-data = [None for _ in range(M)]", "+work = [None for _ in range(M)]", "+orig = [None for _ in range(M)] # retains original order", "- data[i] = [Pi, Yi, 1, i]", "-data.sort(key=lambda x: x[1]) # sort by year", "-data.sort(key=lambda x: x[0]) # sort by prefectures", "+ data = [Pi, Yi, 1, i]", ...
false
0.043457
0.043251
1.004761
[ "s711746000", "s615152256" ]
u905203728
p03401
python
s184757604
s357904229
410
372
64,876
63,980
Accepted
Accepted
9.27
n=int(eval(input())) box=[0]+list(map(int,input().split()))+[0] count=0 for i in range(n+1):count +=abs(box[i]-box[i+1]) for j in range(1,n+1): print((count-(abs(box[j-1]-box[j])+abs(box[j]-box[j+1]))+abs(box[j-1]-box[j+1])))
n=int(eval(input())) add=list(map(int,input().split())) add.insert(0,0) add.append(0) count=0 for i in range(n+1): count +=abs(add[i]-add[i+1]) for i in range(1,n+1): print((count-(abs(add[i-1]-add[i])+abs(add[i]-add[i+1]))+(abs(add[i-1]-add[i+1]))))
6
9
226
258
n = int(eval(input())) box = [0] + list(map(int, input().split())) + [0] count = 0 for i in range(n + 1): count += abs(box[i] - box[i + 1]) for j in range(1, n + 1): print( ( count - (abs(box[j - 1] - box[j]) + abs(box[j] - box[j + 1])) + abs(box[j - 1] - box[j + 1]) ) )
n = int(eval(input())) add = list(map(int, input().split())) add.insert(0, 0) add.append(0) count = 0 for i in range(n + 1): count += abs(add[i] - add[i + 1]) for i in range(1, n + 1): print( ( count - (abs(add[i - 1] - add[i]) + abs(add[i] - add[i + 1])) + (abs(add[i - 1] - add[i + 1])) ) )
false
33.333333
[ "-box = [0] + list(map(int, input().split())) + [0]", "+add = list(map(int, input().split()))", "+add.insert(0, 0)", "+add.append(0)", "- count += abs(box[i] - box[i + 1])", "-for j in range(1, n + 1):", "+ count += abs(add[i] - add[i + 1])", "+for i in range(1, n + 1):", "- - (abs(...
false
0.044011
0.043352
1.015184
[ "s184757604", "s357904229" ]
u596276291
p03700
python
s643907390
s562780636
1,276
1,048
8,624
9,064
Accepted
Accepted
17.87
from collections import defaultdict from math import ceil def can_kill(total, A, B, h_list): add = A - B num = 0 for h in h_list: h -= B * total num += ceil(h / add) if num > total: return False return True def main(): N, A, B = list(map(int, input().split())) h_list = list(sorted([int(eval(input())) for _ in range(N)], reverse=True)) left, right = -1, 10 ** 10 ans = 0 while right - left > 1: m = (left + right) // 2 if can_kill(m, A, B, h_list): ans = m right = m else: left = m print(ans) if __name__ == '__main__': main()
from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def ok(n, A, B, H): num = 0 for h in H: r = h - n * B if r > 0: num += ceil(r, (A - B)) return num <= n def main(): N, A, B = list(map(int, input().split())) H = sorted([int(eval(input())) for _ in range(N)]) low, high = 0, 10 ** 10 ans = 0 while high - low > 1: middle = (low + high) // 2 if ok(middle, A, B, H): ans = middle high = middle else: low = middle print(ans) if __name__ == '__main__': main()
33
51
695
1,216
from collections import defaultdict from math import ceil def can_kill(total, A, B, h_list): add = A - B num = 0 for h in h_list: h -= B * total num += ceil(h / add) if num > total: return False return True def main(): N, A, B = list(map(int, input().split())) h_list = list(sorted([int(eval(input())) for _ in range(N)], reverse=True)) left, right = -1, 10**10 ans = 0 while right - left > 1: m = (left + right) // 2 if can_kill(m, A, B, h_list): ans = m right = m else: left = m print(ans) if __name__ == "__main__": main()
from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def ok(n, A, B, H): num = 0 for h in H: r = h - n * B if r > 0: num += ceil(r, (A - B)) return num <= n def main(): N, A, B = list(map(int, input().split())) H = sorted([int(eval(input())) for _ in range(N)]) low, high = 0, 10**10 ans = 0 while high - low > 1: middle = (low + high) // 2 if ok(middle, A, B, H): ans = middle high = middle else: low = middle print(ans) if __name__ == "__main__": main()
false
35.294118
[ "-from collections import defaultdict", "-from math import ceil", "+from collections import defaultdict, Counter", "+from itertools import product, groupby, count, permutations, combinations", "+from math import pi, sqrt", "+from collections import deque", "+from bisect import bisect, bisect_left, bisec...
false
0.053105
0.048512
1.094669
[ "s643907390", "s562780636" ]
u651235280
p02761
python
s004917927
s713301273
30
26
9,192
9,192
Accepted
Accepted
13.33
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline n,m = list(map(int, input().split())) sc = [list(map(int, input().split())) for _ in range(m)] for i in range(1000): flag = True for s in sc: num = str(i) if len(num) >= s[0] and str(s[1]) == num[s[0] - 1]: continue else: flag = False break if flag and len(str(i)) == n: print(i) exit() print((-1))
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline n,m = list(map(int, input().split())) v = [list(map(int, input().split())) for _ in range(m)] for i in range(1000): flag = True num = str(i) for sc in v: if len(num) >= sc[0] and str(sc[1]) == num[sc[0] - 1]: continue else: flag = False break if flag and len(num) == n: print(i) exit() print((-1))
21
20
469
462
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline n, m = list(map(int, input().split())) sc = [list(map(int, input().split())) for _ in range(m)] for i in range(1000): flag = True for s in sc: num = str(i) if len(num) >= s[0] and str(s[1]) == num[s[0] - 1]: continue else: flag = False break if flag and len(str(i)) == n: print(i) exit() print((-1))
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline n, m = list(map(int, input().split())) v = [list(map(int, input().split())) for _ in range(m)] for i in range(1000): flag = True num = str(i) for sc in v: if len(num) >= sc[0] and str(sc[1]) == num[sc[0] - 1]: continue else: flag = False break if flag and len(num) == n: print(i) exit() print((-1))
false
4.761905
[ "-sc = [list(map(int, input().split())) for _ in range(m)]", "+v = [list(map(int, input().split())) for _ in range(m)]", "- for s in sc:", "- num = str(i)", "- if len(num) >= s[0] and str(s[1]) == num[s[0] - 1]:", "+ num = str(i)", "+ for sc in v:", "+ if len(num) >= sc[0...
false
0.042567
0.073252
0.581096
[ "s004917927", "s713301273" ]
u955248595
p03231
python
s892569461
s383215560
48
39
13,308
9,384
Accepted
Accepted
18.75
import math N,M = (int(T) for T in input().split()) S = eval(input()) T = eval(input()) NMG = math.gcd(N,M) Length = N*M//NMG Flag = True SIndex = [Nk*(M//NMG) for Nk in range(0,N)] SList = list(S) Count = 0 for Mk in range(0,M): if Mk%(M//NMG)==0: if SList[Count*(N//NMG)]!=T[Mk]: Flag = False break else: Count += 1 if Flag: print(Length) else: print((-1))
import math N,M = (int(T) for T in input().split()) S = eval(input()) T = eval(input()) NMgcd = math.gcd(N,M) Leng = N*M//NMgcd Flag = True SList = [S[Nk] for Nk in range(0,N) if Nk%(N//NMgcd)==0] for Mk in range(0,len(SList)): if SList[Mk]!=T[Mk*(M//NMgcd)]: Flag = False break if Flag: print(Leng) else: print((-1))
23
18
435
352
import math N, M = (int(T) for T in input().split()) S = eval(input()) T = eval(input()) NMG = math.gcd(N, M) Length = N * M // NMG Flag = True SIndex = [Nk * (M // NMG) for Nk in range(0, N)] SList = list(S) Count = 0 for Mk in range(0, M): if Mk % (M // NMG) == 0: if SList[Count * (N // NMG)] != T[Mk]: Flag = False break else: Count += 1 if Flag: print(Length) else: print((-1))
import math N, M = (int(T) for T in input().split()) S = eval(input()) T = eval(input()) NMgcd = math.gcd(N, M) Leng = N * M // NMgcd Flag = True SList = [S[Nk] for Nk in range(0, N) if Nk % (N // NMgcd) == 0] for Mk in range(0, len(SList)): if SList[Mk] != T[Mk * (M // NMgcd)]: Flag = False break if Flag: print(Leng) else: print((-1))
false
21.73913
[ "-NMG = math.gcd(N, M)", "-Length = N * M // NMG", "+NMgcd = math.gcd(N, M)", "+Leng = N * M // NMgcd", "-SIndex = [Nk * (M // NMG) for Nk in range(0, N)]", "-SList = list(S)", "-Count = 0", "-for Mk in range(0, M):", "- if Mk % (M // NMG) == 0:", "- if SList[Count * (N // NMG)] != T[Mk]...
false
0.037924
0.040761
0.930411
[ "s892569461", "s383215560" ]
u386819480
p03449
python
s293331859
s073292765
20
18
3,064
3,064
Accepted
Accepted
10
#!/usr/bin/env python3 import sys def dfs(x:int, y:int): if(y == 1 and x == (N-1)): return A[y][x] elif(y > 1 or x > N-1): return 0 else: return max(dfs(x+1, y), dfs(x, y+1)) + A[y][x] def solve(N: int, A: "List[List[int]]"): print((dfs(0,0))) return # Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() global N, A N = int(next(tokens)) # type: int A = [[int(next(tokens)) for _ in range(N)] for _ in range(2)] # type: "List[List[int]]" solve(N, A) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys def solve(N: int, A: "List[List[int]]"): ans = 0 for i in range(0,N): ans = max(sum(A[0][:i+1])+sum(A[1][i:]), ans) print(ans) return # Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = [[int(next(tokens)) for _ in range(N)] for _ in range(2)] # type: "List[List[int]]" solve(N, A) if __name__ == '__main__': main()
34
27
879
741
#!/usr/bin/env python3 import sys def dfs(x: int, y: int): if y == 1 and x == (N - 1): return A[y][x] elif y > 1 or x > N - 1: return 0 else: return max(dfs(x + 1, y), dfs(x, y + 1)) + A[y][x] def solve(N: int, A: "List[List[int]]"): print((dfs(0, 0))) return # Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() global N, A N = int(next(tokens)) # type: int A = [ [int(next(tokens)) for _ in range(N)] for _ in range(2) ] # type: "List[List[int]]" solve(N, A) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys def solve(N: int, A: "List[List[int]]"): ans = 0 for i in range(0, N): ans = max(sum(A[0][: i + 1]) + sum(A[1][i:]), ans) print(ans) return # Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int A = [ [int(next(tokens)) for _ in range(N)] for _ in range(2) ] # type: "List[List[int]]" solve(N, A) if __name__ == "__main__": main()
false
20.588235
[ "-def dfs(x: int, y: int):", "- if y == 1 and x == (N - 1):", "- return A[y][x]", "- elif y > 1 or x > N - 1:", "- return 0", "- else:", "- return max(dfs(x + 1, y), dfs(x, y + 1)) + A[y][x]", "-", "-", "- print((dfs(0, 0)))", "+ ans = 0", "+ for i in ran...
false
0.047775
0.037948
1.258964
[ "s293331859", "s073292765" ]
u241159583
p03610
python
s092410024
s264370556
19
17
3,188
3,188
Accepted
Accepted
10.53
s = eval(input()) print((s[::2]))
s = eval(input()) print((s[0::2]))
2
2
26
27
s = eval(input()) print((s[::2]))
s = eval(input()) print((s[0::2]))
false
0
[ "-print((s[::2]))", "+print((s[0::2]))" ]
false
0.042973
0.046982
0.914652
[ "s092410024", "s264370556" ]
u811841526
p02408
python
s712966202
s203379100
40
20
7,984
5,604
Accepted
Accepted
50
from collections import OrderedDict cards = OrderedDict() cards['S'] = set() cards['H'] = set() cards['C'] = set() cards['D'] = set() n = int(eval(input())) for _ in range(n): suit, num = input().split() num = int(num) cards[suit].add(num) for suit, nums in list(cards.items()): for num in range(1,14): if num not in nums: print((suit, num))
n = int(eval(input())) deck = [] for i in range(n): deck.append(eval(input())) for suit in 'SHCD': for i in range(1, 14): card = f'{suit} {i}' if card not in deck: print(card)
18
11
383
212
from collections import OrderedDict cards = OrderedDict() cards["S"] = set() cards["H"] = set() cards["C"] = set() cards["D"] = set() n = int(eval(input())) for _ in range(n): suit, num = input().split() num = int(num) cards[suit].add(num) for suit, nums in list(cards.items()): for num in range(1, 14): if num not in nums: print((suit, num))
n = int(eval(input())) deck = [] for i in range(n): deck.append(eval(input())) for suit in "SHCD": for i in range(1, 14): card = f"{suit} {i}" if card not in deck: print(card)
false
38.888889
[ "-from collections import OrderedDict", "-", "-cards = OrderedDict()", "-cards[\"S\"] = set()", "-cards[\"H\"] = set()", "-cards[\"C\"] = set()", "-cards[\"D\"] = set()", "-for _ in range(n):", "- suit, num = input().split()", "- num = int(num)", "- cards[suit].add(num)", "-for suit, ...
false
0.048022
0.040009
1.200263
[ "s712966202", "s203379100" ]
u298633786
p03994
python
s223748319
s074259413
1,903
206
52,400
52,912
Accepted
Accepted
89.17
import sys import math # noqa import bisect # noqa import queue # noqa def input(): return sys.stdin.readline().rstrip() def main(): S = eval(input()) K = int(eval(input())) S = [s for s in S] D = [ord('z') - ord(s) + 1 if s != 'a' else 0 for s in S] T = [] for s, d in zip(S, D): if d <= K: T.append('a') K -= d else: T.append(s) c = ord(T[-1]) for _ in range(K): if c == ord('z'): c = ord('a') else: c += 1 T[-1] = chr(c) print((''.join(T))) if __name__ == '__main__': main()
import sys import math # noqa import bisect # noqa import queue # noqa def input(): return sys.stdin.readline().rstrip() def main(): S = eval(input()) K = int(eval(input())) S = [s for s in S] D = [ord('z') - ord(s) + 1 if s != 'a' else 0 for s in S] T = [] for s, d in zip(S, D): if d <= K: T.append('a') K -= d else: T.append(s) c = ord(T[-1]) K %= 26 for _ in range(K): if c == ord('z'): c = ord('a') else: c += 1 T[-1] = chr(c) print((''.join(T))) if __name__ == '__main__': main()
37
38
652
665
import sys import math # noqa import bisect # noqa import queue # noqa def input(): return sys.stdin.readline().rstrip() def main(): S = eval(input()) K = int(eval(input())) S = [s for s in S] D = [ord("z") - ord(s) + 1 if s != "a" else 0 for s in S] T = [] for s, d in zip(S, D): if d <= K: T.append("a") K -= d else: T.append(s) c = ord(T[-1]) for _ in range(K): if c == ord("z"): c = ord("a") else: c += 1 T[-1] = chr(c) print(("".join(T))) if __name__ == "__main__": main()
import sys import math # noqa import bisect # noqa import queue # noqa def input(): return sys.stdin.readline().rstrip() def main(): S = eval(input()) K = int(eval(input())) S = [s for s in S] D = [ord("z") - ord(s) + 1 if s != "a" else 0 for s in S] T = [] for s, d in zip(S, D): if d <= K: T.append("a") K -= d else: T.append(s) c = ord(T[-1]) K %= 26 for _ in range(K): if c == ord("z"): c = ord("a") else: c += 1 T[-1] = chr(c) print(("".join(T))) if __name__ == "__main__": main()
false
2.631579
[ "+ K %= 26" ]
false
0.196189
0.046096
4.256058
[ "s223748319", "s074259413" ]
u755801379
p02713
python
s579755966
s899961481
1,370
451
9,176
68,900
Accepted
Accepted
67.08
k=int(eval(input())) import math ans=0 for i in range(1,k+1): for j in range(1,k+1): a=math.gcd(i,j) for l in range(1,k+1): ans+=math.gcd(a,l) print(ans)
k=int(eval(input())) import math ans=0 for i in range(1,k+1): for j in range(1,k+1): for l in range(1,k+1): a=math.gcd(i,j) ans+=math.gcd(a,l) print(ans)
9
9
187
185
k = int(eval(input())) import math ans = 0 for i in range(1, k + 1): for j in range(1, k + 1): a = math.gcd(i, j) for l in range(1, k + 1): ans += math.gcd(a, l) print(ans)
k = int(eval(input())) import math ans = 0 for i in range(1, k + 1): for j in range(1, k + 1): for l in range(1, k + 1): a = math.gcd(i, j) ans += math.gcd(a, l) print(ans)
false
0
[ "- a = math.gcd(i, j)", "+ a = math.gcd(i, j)" ]
false
0.110131
0.206157
0.534208
[ "s579755966", "s899961481" ]
u922449550
p03165
python
s345956361
s723403040
574
528
112,476
112,476
Accepted
Accepted
8.01
S = eval(input()) T = eval(input()) dp = [[0] * (len(T)+1) for i in range(len(S)+1)] for i, s in enumerate(S, 1): for j, t in enumerate(T, 1): if s == t: dp[i][j] = dp[i-1][j-1] + 1 else: dp[i][j] = max(dp[i-1][j], dp[i][j-1]) ans = [] while i > 0 and j > 0: if dp[i][j] == dp[i][j-1]: j -= 1 elif dp[i][j] == dp[i-1][j]: i -= 1 else: ans.append(S[i-1]) i -= 1 j -= 1 print((''.join(ans[::-1])))
S = eval(input()) T = eval(input()) dp = [[0] * (len(T)+1) for i in range(len(S)+1)] for i, s in enumerate(S, 1): for j, t in enumerate(T, 1): if s == t: dp[i][j] = dp[i-1][j-1] + 1 else: dp[i][j] = max(dp[i-1][j], dp[i][j-1]) ans = '' while i > 0 and j > 0: if dp[i][j] == dp[i][j-1]: j -= 1 elif dp[i][j] == dp[i-1][j]: i -= 1 else: ans += S[i-1] i -= 1 j -= 1 print((ans[::-1]))
23
23
454
440
S = eval(input()) T = eval(input()) dp = [[0] * (len(T) + 1) for i in range(len(S) + 1)] for i, s in enumerate(S, 1): for j, t in enumerate(T, 1): if s == t: dp[i][j] = dp[i - 1][j - 1] + 1 else: dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) ans = [] while i > 0 and j > 0: if dp[i][j] == dp[i][j - 1]: j -= 1 elif dp[i][j] == dp[i - 1][j]: i -= 1 else: ans.append(S[i - 1]) i -= 1 j -= 1 print(("".join(ans[::-1])))
S = eval(input()) T = eval(input()) dp = [[0] * (len(T) + 1) for i in range(len(S) + 1)] for i, s in enumerate(S, 1): for j, t in enumerate(T, 1): if s == t: dp[i][j] = dp[i - 1][j - 1] + 1 else: dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) ans = "" while i > 0 and j > 0: if dp[i][j] == dp[i][j - 1]: j -= 1 elif dp[i][j] == dp[i - 1][j]: i -= 1 else: ans += S[i - 1] i -= 1 j -= 1 print((ans[::-1]))
false
0
[ "-ans = []", "+ans = \"\"", "- ans.append(S[i - 1])", "+ ans += S[i - 1]", "-print((\"\".join(ans[::-1])))", "+print((ans[::-1]))" ]
false
0.112951
0.039762
2.840672
[ "s345956361", "s723403040" ]
u873482706
p00134
python
s636005241
s748328493
30
20
4,964
4,692
Accepted
Accepted
33.33
import math N = eval(input()) S = sum([int(input()) for i in range(N)]) / float(N) print(int(math.floor(S)))
N = eval(input()) print(sum([int(input()) for i in range(N)]) / N)
4
2
108
64
import math N = eval(input()) S = sum([int(input()) for i in range(N)]) / float(N) print(int(math.floor(S)))
N = eval(input()) print(sum([int(input()) for i in range(N)]) / N)
false
50
[ "-import math", "-", "-S = sum([int(input()) for i in range(N)]) / float(N)", "-print(int(math.floor(S)))", "+print(sum([int(input()) for i in range(N)]) / N)" ]
false
0.164647
0.037304
4.413668
[ "s636005241", "s748328493" ]
u844646164
p03253
python
s581495226
s571398449
198
131
58,096
15,380
Accepted
Accepted
33.84
import math import collections Mod = 1000000007 fac = [1, 1] finv = [1, 1] inv = [0, 1] def COMinit(): for i in range(2, N+111): fac.append(fac[-1]*i%Mod) inv.append((-inv[Mod%i] * (Mod//i)) % Mod) finv.append(finv[-1] * inv[-1] % Mod) def COM(n, k): if n < 0 or k < 0 or n < k: return 0 return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod N, M = list(map(int, input().split())) prime_count = collections.Counter() for i in range(2, math.ceil(math.sqrt(M))+1): while M % i == 0: M /= i prime_count[i] += 1 if M > 1: prime_count[M] += 1 ans = 1 COMinit() for i, b in list(prime_count.items()): tmp = COM(b+N-1, N-1) ans = (ans * tmp) % Mod print(ans)
import math import collections #Max = 210000 Mod = 1000000007 """ fac = [0] * Max finv = [0] * Max inv = [0] * Max def COMinit(): fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 inv[1] = 1 for i in range(2, Max): fac[i] = fac[i-1] * i % Mod inv[i] = Mod - inv[Mod%i] * (Mod//i) % Mod finv[i] = finv[i-1] * inv[i] % Mod """ fac = [1, 1] finv = [1, 1] inv = [0, 1] def COMinit(): for i in range(2, N+111): fac.append(fac[-1]*i%Mod) inv.append((-inv[Mod%i] * (Mod//i)) % Mod) finv.append(finv[-1] * inv[-1] % Mod) def COM(n, k): if n < 0 or k < 0 or n < k: return 0 return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod N, M = list(map(int, input().split())) prime_count = collections.Counter() for i in range(2, math.ceil(math.sqrt(M))+1): while M % i == 0: M /= i prime_count[i] += 1 if M > 1: prime_count[M] += 1 ans = 1 COMinit() for i, b in list(prime_count.items()): tmp = COM(b+N-1, N-1) ans = (ans * tmp) % Mod print(ans)
34
47
755
1,078
import math import collections Mod = 1000000007 fac = [1, 1] finv = [1, 1] inv = [0, 1] def COMinit(): for i in range(2, N + 111): fac.append(fac[-1] * i % Mod) inv.append((-inv[Mod % i] * (Mod // i)) % Mod) finv.append(finv[-1] * inv[-1] % Mod) def COM(n, k): if n < 0 or k < 0 or n < k: return 0 return fac[n] * (finv[k] * finv[n - k] % Mod) % Mod N, M = list(map(int, input().split())) prime_count = collections.Counter() for i in range(2, math.ceil(math.sqrt(M)) + 1): while M % i == 0: M /= i prime_count[i] += 1 if M > 1: prime_count[M] += 1 ans = 1 COMinit() for i, b in list(prime_count.items()): tmp = COM(b + N - 1, N - 1) ans = (ans * tmp) % Mod print(ans)
import math import collections # Max = 210000 Mod = 1000000007 """ fac = [0] * Max finv = [0] * Max inv = [0] * Max def COMinit(): fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 inv[1] = 1 for i in range(2, Max): fac[i] = fac[i-1] * i % Mod inv[i] = Mod - inv[Mod%i] * (Mod//i) % Mod finv[i] = finv[i-1] * inv[i] % Mod """ fac = [1, 1] finv = [1, 1] inv = [0, 1] def COMinit(): for i in range(2, N + 111): fac.append(fac[-1] * i % Mod) inv.append((-inv[Mod % i] * (Mod // i)) % Mod) finv.append(finv[-1] * inv[-1] % Mod) def COM(n, k): if n < 0 or k < 0 or n < k: return 0 return fac[n] * (finv[k] * finv[n - k] % Mod) % Mod N, M = list(map(int, input().split())) prime_count = collections.Counter() for i in range(2, math.ceil(math.sqrt(M)) + 1): while M % i == 0: M /= i prime_count[i] += 1 if M > 1: prime_count[M] += 1 ans = 1 COMinit() for i, b in list(prime_count.items()): tmp = COM(b + N - 1, N - 1) ans = (ans * tmp) % Mod print(ans)
false
27.659574
[ "+# Max = 210000", "+\"\"\"", "+fac = [0] * Max", "+finv = [0] * Max", "+inv = [0] * Max", "+def COMinit():", "+ fac[0] = fac[1] = 1", "+ finv[0] = finv[1] = 1", "+ inv[1] = 1", "+ for i in range(2, Max):", "+ fac[i] = fac[i-1] * i % Mod", "+ inv[i] = Mod - inv[Mod%i]...
false
0.131151
0.08667
1.513218
[ "s581495226", "s571398449" ]
u699089116
p02803
python
s455236315
s523257897
354
319
9,436
9,476
Accepted
Accepted
9.89
from collections import deque H, W = list(map(int, input().split())) maze = [list(eval(input())) for _ in range(H)] direction = [[0, 1], [1, 0], [0, -1], [-1, 0]] ans = 0 for sh in range(H): for sw in range(W): if maze[sh][sw] == "#": continue dist = [[-1] * W for _ in range(H)] dist[sh][sw] = 0 que = deque([[sh, sw]]) while que: nh, nw = que.pop() for dh, dw in direction: if not ((0 <= nh + dh < H) and (0 <= nw + dw < W)): continue if maze[nh + dh][nw + dw] == "#": continue if dist[nh + dh][nw + dw] != -1: continue dist[nh + dh][nw + dw] = dist[nh][nw] + 1 que.appendleft([nh + dh, nw + dw]) ans = max(ans, max([max(d) for d in dist])) print(ans)
from collections import deque H, W = list(map(int, input().split())) maze = [list(eval(input())) for _ in range(H)] directions = [[0, 1], [1, 0], [0, -1], [-1, 0]] ans = 0 for sh in range(H): for sw in range(W): if maze[sh][sw] == "#": continue dist = [[-1] * W for _ in range(H)] dist[sh][sw] = 0 que = deque([[sh, sw]]) while que: nh, nw = que.pop() for dh, dw in directions: tmp_h, tmp_w = nh + dh, nw + dw if not ((0 <= tmp_h < H) and (0 <= tmp_w < W)): continue if maze[tmp_h][tmp_w] == "#": continue if dist[tmp_h][tmp_w] != -1: continue dist[tmp_h][tmp_w] = dist[nh][nw] + 1 que.appendleft([tmp_h, tmp_w]) ans = max(ans, max([max(d) for d in dist])) print(ans)
31
31
905
934
from collections import deque H, W = list(map(int, input().split())) maze = [list(eval(input())) for _ in range(H)] direction = [[0, 1], [1, 0], [0, -1], [-1, 0]] ans = 0 for sh in range(H): for sw in range(W): if maze[sh][sw] == "#": continue dist = [[-1] * W for _ in range(H)] dist[sh][sw] = 0 que = deque([[sh, sw]]) while que: nh, nw = que.pop() for dh, dw in direction: if not ((0 <= nh + dh < H) and (0 <= nw + dw < W)): continue if maze[nh + dh][nw + dw] == "#": continue if dist[nh + dh][nw + dw] != -1: continue dist[nh + dh][nw + dw] = dist[nh][nw] + 1 que.appendleft([nh + dh, nw + dw]) ans = max(ans, max([max(d) for d in dist])) print(ans)
from collections import deque H, W = list(map(int, input().split())) maze = [list(eval(input())) for _ in range(H)] directions = [[0, 1], [1, 0], [0, -1], [-1, 0]] ans = 0 for sh in range(H): for sw in range(W): if maze[sh][sw] == "#": continue dist = [[-1] * W for _ in range(H)] dist[sh][sw] = 0 que = deque([[sh, sw]]) while que: nh, nw = que.pop() for dh, dw in directions: tmp_h, tmp_w = nh + dh, nw + dw if not ((0 <= tmp_h < H) and (0 <= tmp_w < W)): continue if maze[tmp_h][tmp_w] == "#": continue if dist[tmp_h][tmp_w] != -1: continue dist[tmp_h][tmp_w] = dist[nh][nw] + 1 que.appendleft([tmp_h, tmp_w]) ans = max(ans, max([max(d) for d in dist])) print(ans)
false
0
[ "-direction = [[0, 1], [1, 0], [0, -1], [-1, 0]]", "+directions = [[0, 1], [1, 0], [0, -1], [-1, 0]]", "- for dh, dw in direction:", "- if not ((0 <= nh + dh < H) and (0 <= nw + dw < W)):", "+ for dh, dw in directions:", "+ tmp_h, tmp_w = nh + dh, nw + d...
false
0.045744
0.044927
1.018175
[ "s455236315", "s523257897" ]
u969850098
p03029
python
s815709146
s056700136
19
17
2,940
2,940
Accepted
Accepted
10.53
A, P = list(map(int, input().split())) print(((A * 3 + P) // 2))
a, p = list(map(int, input().split())) print(((a*3 + p) // 2))
2
2
57
55
A, P = list(map(int, input().split())) print(((A * 3 + P) // 2))
a, p = list(map(int, input().split())) print(((a * 3 + p) // 2))
false
0
[ "-A, P = list(map(int, input().split()))", "-print(((A * 3 + P) // 2))", "+a, p = list(map(int, input().split()))", "+print(((a * 3 + p) // 2))" ]
false
0.043144
0.042218
1.021942
[ "s815709146", "s056700136" ]
u057109575
p03946
python
s923304691
s552518468
296
240
69,916
69,920
Accepted
Accepted
18.92
from bisect import bisect_left from collections import defaultdict N, T, *A = list(map(int, open(0).read().split())) inf = 10 ** 9 + 7 dp = [inf] * (N + 1) ctr = defaultdict(int) for i in range(N): idx = bisect_left(dp, A[i]) dp[idx] = A[i] if idx != 0: ctr[A[i] - dp[0]] += 1 print((ctr[max(ctr)]))
from collections import defaultdict N, T, *A = list(map(int, open(0).read().split())) ctr = defaultdict(int) m = 10 ** 9 + 7 for i in range(N): m = min(m, A[i]) ctr[A[i] - m] += 1 print((ctr[max(ctr)]))
15
11
329
216
from bisect import bisect_left from collections import defaultdict N, T, *A = list(map(int, open(0).read().split())) inf = 10**9 + 7 dp = [inf] * (N + 1) ctr = defaultdict(int) for i in range(N): idx = bisect_left(dp, A[i]) dp[idx] = A[i] if idx != 0: ctr[A[i] - dp[0]] += 1 print((ctr[max(ctr)]))
from collections import defaultdict N, T, *A = list(map(int, open(0).read().split())) ctr = defaultdict(int) m = 10**9 + 7 for i in range(N): m = min(m, A[i]) ctr[A[i] - m] += 1 print((ctr[max(ctr)]))
false
26.666667
[ "-from bisect import bisect_left", "-inf = 10**9 + 7", "-dp = [inf] * (N + 1)", "+m = 10**9 + 7", "- idx = bisect_left(dp, A[i])", "- dp[idx] = A[i]", "- if idx != 0:", "- ctr[A[i] - dp[0]] += 1", "+ m = min(m, A[i])", "+ ctr[A[i] - m] += 1" ]
false
0.04255
0.041906
1.01537
[ "s923304691", "s552518468" ]
u038408819
p03013
python
s569914035
s045138015
595
213
463,476
7,764
Accepted
Accepted
64.2
N, M = list(map(int, input().split())) #a = [int(input()) for _ in range(M)] issafe = [True] * (N + 1) for i in range(M): issafe[int(eval(input()))] = False dp = [0] * (N + 1) dp[0] = 1 if issafe[1]: dp[1] = 1 for i in range(2, N + 1): if issafe[i - 1]: dp[i] += dp[i - 1] if issafe[i - 2]: dp[i] += dp[i - 2] mod = 1000000007 print((dp[N] % mod))
N, M = list(map(int, input().split())) #a = [int(input()) for _ in range(M)] issafe = [True] * (N + 1) for i in range(M): issafe[int(eval(input()))] = False dp = [0] * (N + 1) dp[0] = 1 if issafe[1]: dp[1] = 1 mod = 1000000007 for i in range(2, N + 1): if issafe[i - 1]: dp[i] += dp[i - 1] if issafe[i - 2]: dp[i] += dp[i - 2] dp[i] = dp[i] %mod print((dp[N]))
19
20
386
404
N, M = list(map(int, input().split())) # a = [int(input()) for _ in range(M)] issafe = [True] * (N + 1) for i in range(M): issafe[int(eval(input()))] = False dp = [0] * (N + 1) dp[0] = 1 if issafe[1]: dp[1] = 1 for i in range(2, N + 1): if issafe[i - 1]: dp[i] += dp[i - 1] if issafe[i - 2]: dp[i] += dp[i - 2] mod = 1000000007 print((dp[N] % mod))
N, M = list(map(int, input().split())) # a = [int(input()) for _ in range(M)] issafe = [True] * (N + 1) for i in range(M): issafe[int(eval(input()))] = False dp = [0] * (N + 1) dp[0] = 1 if issafe[1]: dp[1] = 1 mod = 1000000007 for i in range(2, N + 1): if issafe[i - 1]: dp[i] += dp[i - 1] if issafe[i - 2]: dp[i] += dp[i - 2] dp[i] = dp[i] % mod print((dp[N]))
false
5
[ "+mod = 1000000007", "-mod = 1000000007", "-print((dp[N] % mod))", "+ dp[i] = dp[i] % mod", "+print((dp[N]))" ]
false
0.084417
0.032467
2.600128
[ "s569914035", "s045138015" ]
u426534722
p02243
python
s311651007
s565286375
750
390
70,900
42,520
Accepted
Accepted
48
from sys import stdin import heapq INF = 1<<21 n = int(stdin.readline()) adj = [[]] * n for u in range(0, n): U = list(map(int, stdin.readline().split()[2:])) adj[u] = [e for e in zip(U[0::2], U[1::2])] def dijkstra(): d = [0] + [INF] * (n - 1) hq = [(0, 0)] while hq: u = heapq.heappop(hq)[1] for v, c in adj[u]: alt = d[u] + c if d[v] > alt: d[v] = alt heapq.heappush(hq, (alt, v)) for i, c in enumerate(d): print((i, c)) dijkstra()
from sys import stdin import heapq INF = 1<<21 n = int(stdin.readline()) adj = [[]] * n for u in range(0, n): U = list(map(int, stdin.readline().split()[2:])) adj[u] = (e for e in zip(U[0::2], U[1::2])) def dijkstra(): d = [0] + [INF] * (n - 1) hq = [(0, 0)] while hq: u = heapq.heappop(hq)[1] for v, c in adj[u]: alt = d[u] + c if d[v] > alt: d[v] = alt heapq.heappush(hq, (alt, v)) for i, c in enumerate(d): print((i, c)) dijkstra()
21
21
556
556
from sys import stdin import heapq INF = 1 << 21 n = int(stdin.readline()) adj = [[]] * n for u in range(0, n): U = list(map(int, stdin.readline().split()[2:])) adj[u] = [e for e in zip(U[0::2], U[1::2])] def dijkstra(): d = [0] + [INF] * (n - 1) hq = [(0, 0)] while hq: u = heapq.heappop(hq)[1] for v, c in adj[u]: alt = d[u] + c if d[v] > alt: d[v] = alt heapq.heappush(hq, (alt, v)) for i, c in enumerate(d): print((i, c)) dijkstra()
from sys import stdin import heapq INF = 1 << 21 n = int(stdin.readline()) adj = [[]] * n for u in range(0, n): U = list(map(int, stdin.readline().split()[2:])) adj[u] = (e for e in zip(U[0::2], U[1::2])) def dijkstra(): d = [0] + [INF] * (n - 1) hq = [(0, 0)] while hq: u = heapq.heappop(hq)[1] for v, c in adj[u]: alt = d[u] + c if d[v] > alt: d[v] = alt heapq.heappush(hq, (alt, v)) for i, c in enumerate(d): print((i, c)) dijkstra()
false
0
[ "- adj[u] = [e for e in zip(U[0::2], U[1::2])]", "+ adj[u] = (e for e in zip(U[0::2], U[1::2]))" ]
false
0.057101
0.054986
1.038457
[ "s311651007", "s565286375" ]
u724687935
p03377
python
s967620171
s311034332
167
25
38,256
9,048
Accepted
Accepted
85.03
A, B, X = list(map(int, input().split())) ans = 'YES' if A <= X and X <= A + B else 'NO' print(ans)
A, B, X = list(map(int, input().split())) ans = 'YES' if A <= X <= A + B else 'NO' print(ans)
4
3
98
90
A, B, X = list(map(int, input().split())) ans = "YES" if A <= X and X <= A + B else "NO" print(ans)
A, B, X = list(map(int, input().split())) ans = "YES" if A <= X <= A + B else "NO" print(ans)
false
25
[ "-ans = \"YES\" if A <= X and X <= A + B else \"NO\"", "+ans = \"YES\" if A <= X <= A + B else \"NO\"" ]
false
0.087707
0.038215
2.295094
[ "s967620171", "s311034332" ]
u606045429
p02889
python
s361341864
s094236507
1,894
644
133,600
40,784
Accepted
Accepted
66
def WarshallFloyd(M): N = len(M) for k in range(N): for j in range(N): for i in range(N): M[i][j] = min(M[i][j], M[i][k] + M[k][j]) return M INF = float("inf") N, M, L, *I = list(map(int, open(0).read().split())) ABC, ST = I[:3 * M], I[3 * M + 1:] E = [[INF] * N for _ in range(N)] for a, b, c in zip(*[iter(ABC)] * 3): E[a - 1][b - 1] = E[b - 1][a - 1] = c E = WarshallFloyd(E) for i in range(N): for j in range(N): if E[i][j] <= L: E[i][j] = 1 else: E[i][j] = INF E = WarshallFloyd(E) for s, t in zip(*[iter(ST)] * 2): a = E[s - 1][t - 1] - 1 print((-1 if a == INF else a))
from scipy.sparse.csgraph import floyd_warshall N, M, L, *I = list(map(int, open(0).read().split())) ABC, ST = I[:3 * M], I[3 * M + 1:] E = [[0] * N for _ in range(N)] for a, b, c in zip(*[iter(ABC)] * 3): E[a - 1][b - 1] = E[b - 1][a - 1] = c E = floyd_warshall(E) E = [[(eij <= L) for j, eij in enumerate(ei)] for i, ei in enumerate(E)] E = floyd_warshall(E) INF = float("inf") A = [] for s, t in zip(*[iter(ST)] * 2): a = E[s - 1][t - 1] - 1 A.append("-1" if a == INF else str(int(a))) print(("\n".join(A)))
32
21
711
541
def WarshallFloyd(M): N = len(M) for k in range(N): for j in range(N): for i in range(N): M[i][j] = min(M[i][j], M[i][k] + M[k][j]) return M INF = float("inf") N, M, L, *I = list(map(int, open(0).read().split())) ABC, ST = I[: 3 * M], I[3 * M + 1 :] E = [[INF] * N for _ in range(N)] for a, b, c in zip(*[iter(ABC)] * 3): E[a - 1][b - 1] = E[b - 1][a - 1] = c E = WarshallFloyd(E) for i in range(N): for j in range(N): if E[i][j] <= L: E[i][j] = 1 else: E[i][j] = INF E = WarshallFloyd(E) for s, t in zip(*[iter(ST)] * 2): a = E[s - 1][t - 1] - 1 print((-1 if a == INF else a))
from scipy.sparse.csgraph import floyd_warshall N, M, L, *I = list(map(int, open(0).read().split())) ABC, ST = I[: 3 * M], I[3 * M + 1 :] E = [[0] * N for _ in range(N)] for a, b, c in zip(*[iter(ABC)] * 3): E[a - 1][b - 1] = E[b - 1][a - 1] = c E = floyd_warshall(E) E = [[(eij <= L) for j, eij in enumerate(ei)] for i, ei in enumerate(E)] E = floyd_warshall(E) INF = float("inf") A = [] for s, t in zip(*[iter(ST)] * 2): a = E[s - 1][t - 1] - 1 A.append("-1" if a == INF else str(int(a))) print(("\n".join(A)))
false
34.375
[ "-def WarshallFloyd(M):", "- N = len(M)", "- for k in range(N):", "- for j in range(N):", "- for i in range(N):", "- M[i][j] = min(M[i][j], M[i][k] + M[k][j])", "- return M", "+from scipy.sparse.csgraph import floyd_warshall", "-", "-INF = float(\"inf\")",...
false
0.087831
0.611362
0.143664
[ "s361341864", "s094236507" ]
u558242240
p02792
python
s649410548
s654104793
314
246
3,064
3,316
Accepted
Accepted
21.66
n = int(eval(input())) ab = {} for i in range(1, n+1): t = str(i) if (t[0], t[-1]) in ab: ab[(t[0], t[-1])] += 1 else: ab[(t[0], t[-1])] = 1 #print(ab) ans = 0 for i in range(1, n+1): t = str(i) if (t[-1], t[0]) in ab: ans += ab[(t[-1], t[0])] print(ans)
from collections import defaultdict n = int(eval(input())) counter = defaultdict(int) for i in range(1, n+1): t = str(i) counter[(t[0], t[-1])] += 1 ans = 0 for i in range(1, n+1): t = str(i) ans += counter[(t[-1], t[0])] print(ans)
16
15
309
261
n = int(eval(input())) ab = {} for i in range(1, n + 1): t = str(i) if (t[0], t[-1]) in ab: ab[(t[0], t[-1])] += 1 else: ab[(t[0], t[-1])] = 1 # print(ab) ans = 0 for i in range(1, n + 1): t = str(i) if (t[-1], t[0]) in ab: ans += ab[(t[-1], t[0])] print(ans)
from collections import defaultdict n = int(eval(input())) counter = defaultdict(int) for i in range(1, n + 1): t = str(i) counter[(t[0], t[-1])] += 1 ans = 0 for i in range(1, n + 1): t = str(i) ans += counter[(t[-1], t[0])] print(ans)
false
6.25
[ "+from collections import defaultdict", "+", "-ab = {}", "+counter = defaultdict(int)", "- if (t[0], t[-1]) in ab:", "- ab[(t[0], t[-1])] += 1", "- else:", "- ab[(t[0], t[-1])] = 1", "-# print(ab)", "+ counter[(t[0], t[-1])] += 1", "- if (t[-1], t[0]) in ab:", "- ...
false
0.058239
0.050706
1.148568
[ "s649410548", "s654104793" ]
u606045429
p02574
python
s305987060
s748437492
644
534
121,888
121,944
Accepted
Accepted
17.08
from functools import reduce from math import gcd N, *A = list(map(int, open(0).read().split())) C = [0] * (10 ** 6 + 10) for a in A: C[a] += 1 if reduce(gcd, A) != 1: print("not coprime") elif all(sum(C[i::i]) <= 1 for i in range(2, len(C))): print("pairwise coprime") else: print("setwise coprime")
from functools import reduce from math import gcd N, *A = list(map(int, open(0).read().split())) C = [0] * (max(A) + 1) for a in A: C[a] += 1 if reduce(gcd, A) != 1: print("not coprime") elif all(sum(C[i::i]) <= 1 for i in range(2, len(C))): print("pairwise coprime") else: print("setwise coprime")
17
17
331
329
from functools import reduce from math import gcd N, *A = list(map(int, open(0).read().split())) C = [0] * (10**6 + 10) for a in A: C[a] += 1 if reduce(gcd, A) != 1: print("not coprime") elif all(sum(C[i::i]) <= 1 for i in range(2, len(C))): print("pairwise coprime") else: print("setwise coprime")
from functools import reduce from math import gcd N, *A = list(map(int, open(0).read().split())) C = [0] * (max(A) + 1) for a in A: C[a] += 1 if reduce(gcd, A) != 1: print("not coprime") elif all(sum(C[i::i]) <= 1 for i in range(2, len(C))): print("pairwise coprime") else: print("setwise coprime")
false
0
[ "-C = [0] * (10**6 + 10)", "+C = [0] * (max(A) + 1)" ]
false
0.481772
0.03718
12.957925
[ "s305987060", "s748437492" ]
u125090409
p02595
python
s391000523
s732715227
912
566
66,508
66,588
Accepted
Accepted
37.94
import numpy as np n, d = list(map(int, input().split())) x, y = np.array([list(map(int, input().split())) for _ in range(n)]).T print((sum(x**2+y**2<=d**2)))
import numpy as np n, d = list(map(int, input().split())) x, y = np.array([list(map(int, input().split())) for _ in range(n)]).T print(((x**2+y**2<=d**2).sum()))
6
6
157
160
import numpy as np n, d = list(map(int, input().split())) x, y = np.array([list(map(int, input().split())) for _ in range(n)]).T print((sum(x**2 + y**2 <= d**2)))
import numpy as np n, d = list(map(int, input().split())) x, y = np.array([list(map(int, input().split())) for _ in range(n)]).T print(((x**2 + y**2 <= d**2).sum()))
false
0
[ "-print((sum(x**2 + y**2 <= d**2)))", "+print(((x**2 + y**2 <= d**2).sum()))" ]
false
0.24293
0.24745
0.981733
[ "s391000523", "s732715227" ]
u533039576
p03164
python
s863967311
s666676384
239
186
147,240
149,336
Accepted
Accepted
22.18
import sys input = sys.stdin.readline n, w = list(map(int, input().split())) items = [tuple(map(int, input().split())) for _ in range(n)] V_MAX = 10**5 dp = [[w + 1] * (V_MAX + 1) for _ in range(n + 1)] dp[0][0] = 0 for i, (wi, vi) in enumerate(items): for j in range(V_MAX + 1): if j >= vi: dp[i + 1][j] = min(dp[i][j], dp[i][j - vi] + wi) else: dp[i + 1][j] = dp[i][j] ans = 0 for i in range(n + 1): for j in range(V_MAX + 1): if dp[i][j] <= w: ans = max(ans, j) print(ans)
import sys input = sys.stdin.readline n, w = list(map(int, input().split())) items = [tuple(map(int, input().split())) for _ in range(n)] V_MAX = 10**5 dp = [[w + 1] * (V_MAX + 1) for _ in range(n + 1)] dp[0][0] = 0 for i, (wi, vi) in enumerate(items): for j in range(V_MAX + 1): if j >= vi: dp[i + 1][j] = min(dp[i][j], dp[i][j - vi] + wi) else: dp[i + 1][j] = dp[i][j] ans = 0 for j in range(V_MAX + 1): if dp[n][j] <= w: ans = max(ans, j) print(ans)
24
23
566
530
import sys input = sys.stdin.readline n, w = list(map(int, input().split())) items = [tuple(map(int, input().split())) for _ in range(n)] V_MAX = 10**5 dp = [[w + 1] * (V_MAX + 1) for _ in range(n + 1)] dp[0][0] = 0 for i, (wi, vi) in enumerate(items): for j in range(V_MAX + 1): if j >= vi: dp[i + 1][j] = min(dp[i][j], dp[i][j - vi] + wi) else: dp[i + 1][j] = dp[i][j] ans = 0 for i in range(n + 1): for j in range(V_MAX + 1): if dp[i][j] <= w: ans = max(ans, j) print(ans)
import sys input = sys.stdin.readline n, w = list(map(int, input().split())) items = [tuple(map(int, input().split())) for _ in range(n)] V_MAX = 10**5 dp = [[w + 1] * (V_MAX + 1) for _ in range(n + 1)] dp[0][0] = 0 for i, (wi, vi) in enumerate(items): for j in range(V_MAX + 1): if j >= vi: dp[i + 1][j] = min(dp[i][j], dp[i][j - vi] + wi) else: dp[i + 1][j] = dp[i][j] ans = 0 for j in range(V_MAX + 1): if dp[n][j] <= w: ans = max(ans, j) print(ans)
false
4.166667
[ "-for i in range(n + 1):", "- for j in range(V_MAX + 1):", "- if dp[i][j] <= w:", "- ans = max(ans, j)", "+for j in range(V_MAX + 1):", "+ if dp[n][j] <= w:", "+ ans = max(ans, j)" ]
false
0.338748
0.266267
1.272216
[ "s863967311", "s666676384" ]
u325492232
p02844
python
s879042642
s974830919
1,859
1,210
9,200
9,212
Accepted
Accepted
34.91
n = int(eval(input())) s = eval(input()) ans = 0 for i in range(1000): # 確認するpinの数字の組み合わせと桁の初期化 current_digit = 0 pin = f'{i:0>3}' # pin = list(str(i).zfill(3)) k = pin[current_digit] for num in s: # 見つけると桁を右に一つずらす if num == k: current_digit += 1 # indexが3(桁が3→2→1→0)になったときはそのPINは作れる if current_digit <= 2: k = pin[current_digit] elif current_digit == 3: ans += 1 break print(ans)
def sumitrust2019_d(): n = int(eval(input())) s = eval(input()) ans = 0 for i in range(1000): # 確認するpinの数字の組み合わせと桁の初期化 # pin = list(str(i).zfill(3)) current_digit = 0 pin = f'{i:0>3}' search_num = pin[current_digit] for num in s: # 見つけると桁を右に一つずらす # 毎回リストにアクセスするより変数に取り出しておくほうがいいかも。 # if num == pin[current_digit]: if num == pin[current_digit]: current_digit += 1 # indexが3(桁が3→2→1→0)になったときはそのPINは作れる if current_digit == 3: ans += 1 break # 見つけ終わるまではチェックする数字を置き換え。 elif current_digit < 3: search_num = pin[current_digit] print(ans) if __name__ == '__main__': sumitrust2019_d()
25
32
533
860
n = int(eval(input())) s = eval(input()) ans = 0 for i in range(1000): # 確認するpinの数字の組み合わせと桁の初期化 current_digit = 0 pin = f"{i:0>3}" # pin = list(str(i).zfill(3)) k = pin[current_digit] for num in s: # 見つけると桁を右に一つずらす if num == k: current_digit += 1 # indexが3(桁が3→2→1→0)になったときはそのPINは作れる if current_digit <= 2: k = pin[current_digit] elif current_digit == 3: ans += 1 break print(ans)
def sumitrust2019_d(): n = int(eval(input())) s = eval(input()) ans = 0 for i in range(1000): # 確認するpinの数字の組み合わせと桁の初期化 # pin = list(str(i).zfill(3)) current_digit = 0 pin = f"{i:0>3}" search_num = pin[current_digit] for num in s: # 見つけると桁を右に一つずらす # 毎回リストにアクセスするより変数に取り出しておくほうがいいかも。 # if num == pin[current_digit]: if num == pin[current_digit]: current_digit += 1 # indexが3(桁が3→2→1→0)になったときはそのPINは作れる if current_digit == 3: ans += 1 break # 見つけ終わるまではチェックする数字を置き換え。 elif current_digit < 3: search_num = pin[current_digit] print(ans) if __name__ == "__main__": sumitrust2019_d()
false
21.875
[ "-n = int(eval(input()))", "-s = eval(input())", "-ans = 0", "-for i in range(1000):", "- # 確認するpinの数字の組み合わせと桁の初期化", "- current_digit = 0", "- pin = f\"{i:0>3}\"", "- # pin = list(str(i).zfill(3))", "- k = pin[current_digit]", "- for num in s:", "- # 見つけると桁を右に一つずらす", "...
false
0.093061
0.097701
0.952505
[ "s879042642", "s974830919" ]
u270681687
p03326
python
s497701258
s174674988
240
28
41,328
3,572
Accepted
Accepted
88.33
n, m = list(map(int, input().split())) x = [] y = [] z = [] for i in range(n): X, Y, Z = list(map(int, input().split())) x.append(X) y.append(Y) z.append(Z) sign = [1, -1] ans = [] for j in sign: for k in sign: for l in sign: a = [] for i in range(n): a.append(x[i] * j + y[i] * k + z[i] * l) a.sort(reverse=True) ans.append(sum(a[:m])) print((max(ans)))
n, m = list(map(int, input().split())) cake = [list(map(int, input().split())) for i in range(n)] box = [[[[] for i in range(2)] for j in range(2)] for k in range(2)] ans = 0 for i in range(2): for j in range(2): for k in range(2): worth = 0 for x, y, z in cake: if i == 1: x = -x if j == 1: y = -y if k == 1: z = -z box[i][j][k].append(x+y+z) box[i][j][k].sort(reverse=True) ans = max(ans, sum(box[i][j][k][:m])) print(ans)
25
22
462
626
n, m = list(map(int, input().split())) x = [] y = [] z = [] for i in range(n): X, Y, Z = list(map(int, input().split())) x.append(X) y.append(Y) z.append(Z) sign = [1, -1] ans = [] for j in sign: for k in sign: for l in sign: a = [] for i in range(n): a.append(x[i] * j + y[i] * k + z[i] * l) a.sort(reverse=True) ans.append(sum(a[:m])) print((max(ans)))
n, m = list(map(int, input().split())) cake = [list(map(int, input().split())) for i in range(n)] box = [[[[] for i in range(2)] for j in range(2)] for k in range(2)] ans = 0 for i in range(2): for j in range(2): for k in range(2): worth = 0 for x, y, z in cake: if i == 1: x = -x if j == 1: y = -y if k == 1: z = -z box[i][j][k].append(x + y + z) box[i][j][k].sort(reverse=True) ans = max(ans, sum(box[i][j][k][:m])) print(ans)
false
12
[ "-x = []", "-y = []", "-z = []", "-for i in range(n):", "- X, Y, Z = list(map(int, input().split()))", "- x.append(X)", "- y.append(Y)", "- z.append(Z)", "-sign = [1, -1]", "-ans = []", "-for j in sign:", "- for k in sign:", "- for l in sign:", "- a = []", ...
false
0.03534
0.089531
0.394718
[ "s497701258", "s174674988" ]
u644907318
p03139
python
s701328755
s591274570
68
27
61,480
9,064
Accepted
Accepted
60.29
N,A,B = list(map(int,input().split())) print((min(A,B),max(0,A+B-N)))
N,A,B = list(map(int,input().split())) print((min(A,B),max(A+B-N,0)))
2
2
62
62
N, A, B = list(map(int, input().split())) print((min(A, B), max(0, A + B - N)))
N, A, B = list(map(int, input().split())) print((min(A, B), max(A + B - N, 0)))
false
0
[ "-print((min(A, B), max(0, A + B - N)))", "+print((min(A, B), max(A + B - N, 0)))" ]
false
0.037619
0.067014
0.561355
[ "s701328755", "s591274570" ]
u597374218
p02860
python
s112776801
s580952304
21
17
3,316
2,940
Accepted
Accepted
19.05
N=int(eval(input())) S=eval(input()) print(("Yes" if N%2==0 and S[:N//2]==S[N//2:] else "No"))
N=int(eval(input())) S=eval(input()) print(("Yes" if S[:N//2]==S[N//2:] else "No"))
3
3
82
71
N = int(eval(input())) S = eval(input()) print(("Yes" if N % 2 == 0 and S[: N // 2] == S[N // 2 :] else "No"))
N = int(eval(input())) S = eval(input()) print(("Yes" if S[: N // 2] == S[N // 2 :] else "No"))
false
0
[ "-print((\"Yes\" if N % 2 == 0 and S[: N // 2] == S[N // 2 :] else \"No\"))", "+print((\"Yes\" if S[: N // 2] == S[N // 2 :] else \"No\"))" ]
false
0.04387
0.038831
1.12977
[ "s112776801", "s580952304" ]
u880128069
p02712
python
s632716543
s864004420
227
201
33,616
9,128
Accepted
Accepted
11.45
N = int(eval(input())) a = [0] * N for i in range(1,N+1): if i%3 == 0 and i%5 == 0: pass elif i%3 == 0: pass elif i%5 == 0: pass else: a[i-1] = i print((sum(a)))
N = int(eval(input())) ans = 0 for i in range(1,N+1): if i%3==0 and i%5==0: pass elif i%3==0: pass elif i%5==0: pass else: ans += i print(ans)
15
15
218
179
N = int(eval(input())) a = [0] * N for i in range(1, N + 1): if i % 3 == 0 and i % 5 == 0: pass elif i % 3 == 0: pass elif i % 5 == 0: pass else: a[i - 1] = i print((sum(a)))
N = int(eval(input())) ans = 0 for i in range(1, N + 1): if i % 3 == 0 and i % 5 == 0: pass elif i % 3 == 0: pass elif i % 5 == 0: pass else: ans += i print(ans)
false
0
[ "-a = [0] * N", "+ans = 0", "- a[i - 1] = i", "-print((sum(a)))", "+ ans += i", "+print(ans)" ]
false
0.352745
0.174504
2.021411
[ "s632716543", "s864004420" ]
u285891772
p03031
python
s002169644
s902580530
66
50
5,204
5,204
Accepted
Accepted
24.24
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N, M = MAP() ks = [LIST() for _ in range(M)] p = LIST() ans = 0 for i in range(1<<N): flg = True i = list("{:b}".format(i).zfill(N)) #print(i) for j in range(M): cnt_sk = 0 for k in range(ks[j][0]): #print(k, ks[j][k+1]) #print(i[ks[j][k+1]-1] == "1") if i[ks[j][k+1]-1] == "1": cnt_sk += 1 #print(cnt_sk) if cnt_sk%2 != p[j]: flg = False if flg: ans += 1 print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2 from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N, M = MAP() ks = [LIST() for _ in range(M)] p = LIST() ans = 0 for i in range(1<<N): flg = True i = list("{:b}".format(i).zfill(N)) #print(i) for j ,lis in enumerate(ks): lis = lis[1:] tmp = 0 for l in lis: if i[l-1] == "1": tmp += 1 if tmp%2 != p[j]: flg = False break if flg: ans += 1 print(ans)
45
43
1,278
1,207
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, ) from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N, M = MAP() ks = [LIST() for _ in range(M)] p = LIST() ans = 0 for i in range(1 << N): flg = True i = list("{:b}".format(i).zfill(N)) # print(i) for j in range(M): cnt_sk = 0 for k in range(ks[j][0]): # print(k, ks[j][k+1]) # print(i[ks[j][k+1]-1] == "1") if i[ks[j][k + 1] - 1] == "1": cnt_sk += 1 # print(cnt_sk) if cnt_sk % 2 != p[j]: flg = False if flg: ans += 1 print(ans)
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, ) from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) def ZIP(n): return list(zip(*(MAP() for _ in range(n)))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N, M = MAP() ks = [LIST() for _ in range(M)] p = LIST() ans = 0 for i in range(1 << N): flg = True i = list("{:b}".format(i).zfill(N)) # print(i) for j, lis in enumerate(ks): lis = lis[1:] tmp = 0 for l in lis: if i[l - 1] == "1": tmp += 1 if tmp % 2 != p[j]: flg = False break if flg: ans += 1 print(ans)
false
4.444444
[ "- for j in range(M):", "- cnt_sk = 0", "- for k in range(ks[j][0]):", "- # print(k, ks[j][k+1])", "- # print(i[ks[j][k+1]-1] == \"1\")", "- if i[ks[j][k + 1] - 1] == \"1\":", "- cnt_sk += 1", "- # print(cnt_sk)", "- if c...
false
0.036851
0.037776
0.975502
[ "s002169644", "s902580530" ]
u029000441
p02802
python
s527903323
s195999790
373
264
15,700
31,884
Accepted
Accepted
29.22
import sys nm=input().rstrip().split(" ") n=int(nm[0]) m=int(nm[1]) answers=[[] for i in range(n)] for i in range(m): line=input().rstrip().split(" ") if line[1]=="AC": answers[int(line[0])-1].append(1) if line[1]=="WA": answers[int(line[0])-1].append(0) #print(answers) ac=0 i=0 was=[] while i<n: sums=0 j=0 while j<len(answers[i]): sums=sums+answers[i][j] if sums>0: ac+=1 was.append(j) break j=j+1 i=i+1 print(ac,end=" ") #print(was) wacount=0 for j in was: wacount=wacount+j print(wacount)
N,M=list(map(int,input().split())) L=[list(input().split()) for i in range(M)] W=[0]*N A=[0]*N a=0 w=0 for i in range(M): if L[i][1]=="AC": A[int(L[i][0])-1]=1 elif L[i][1]=="WA" and A[int(L[i][0])-1]==0: W[int(L[i][0])-1]+=1 #for i in A: #a+=i #for i in W: #w+=i for i in range(N): if A[i]>0: a+=1 w+=W[i] print((a,w))
32
22
634
366
import sys nm = input().rstrip().split(" ") n = int(nm[0]) m = int(nm[1]) answers = [[] for i in range(n)] for i in range(m): line = input().rstrip().split(" ") if line[1] == "AC": answers[int(line[0]) - 1].append(1) if line[1] == "WA": answers[int(line[0]) - 1].append(0) # print(answers) ac = 0 i = 0 was = [] while i < n: sums = 0 j = 0 while j < len(answers[i]): sums = sums + answers[i][j] if sums > 0: ac += 1 was.append(j) break j = j + 1 i = i + 1 print(ac, end=" ") # print(was) wacount = 0 for j in was: wacount = wacount + j print(wacount)
N, M = list(map(int, input().split())) L = [list(input().split()) for i in range(M)] W = [0] * N A = [0] * N a = 0 w = 0 for i in range(M): if L[i][1] == "AC": A[int(L[i][0]) - 1] = 1 elif L[i][1] == "WA" and A[int(L[i][0]) - 1] == 0: W[int(L[i][0]) - 1] += 1 # for i in A: # a+=i # for i in W: # w+=i for i in range(N): if A[i] > 0: a += 1 w += W[i] print((a, w))
false
31.25
[ "-import sys", "-", "-nm = input().rstrip().split(\" \")", "-n = int(nm[0])", "-m = int(nm[1])", "-answers = [[] for i in range(n)]", "-for i in range(m):", "- line = input().rstrip().split(\" \")", "- if line[1] == \"AC\":", "- answers[int(line[0]) - 1].append(1)", "- if line[1]...
false
0.04234
0.037475
1.129831
[ "s527903323", "s195999790" ]
u489959379
p03673
python
s989945202
s023761498
229
161
25,536
27,588
Accepted
Accepted
29.69
from collections import deque n = int(eval(input())) A = list(map(int, input().split())) B = deque() for i in range(n): if i % 2 == 0: B.append(A[i]) else: B.appendleft(A[i]) if n % 2 == 0: print((*B)) else: B = list(B) print((*(B[::-1])))
import sys # import numpy as np from collections import Counter, deque sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n = int(eval(input())) A = deque(list(map(int, input().split()))) B = deque([]) if n % 2 == 0: for i in range(n): a = deque.popleft(A) if i % 2 == 0: B.append(a) else: B.appendleft(a) else: for i in range(n): a = deque.popleft(A) if i % 2 != 0: B.append(a) else: B.appendleft(a) print((" ".join(map(str, B)))) if __name__ == '__main__': resolve()
16
33
282
713
from collections import deque n = int(eval(input())) A = list(map(int, input().split())) B = deque() for i in range(n): if i % 2 == 0: B.append(A[i]) else: B.appendleft(A[i]) if n % 2 == 0: print((*B)) else: B = list(B) print((*(B[::-1])))
import sys # import numpy as np from collections import Counter, deque sys.setrecursionlimit(10**7) f_inf = float("inf") mod = 10**9 + 7 def resolve(): n = int(eval(input())) A = deque(list(map(int, input().split()))) B = deque([]) if n % 2 == 0: for i in range(n): a = deque.popleft(A) if i % 2 == 0: B.append(a) else: B.appendleft(a) else: for i in range(n): a = deque.popleft(A) if i % 2 != 0: B.append(a) else: B.appendleft(a) print((" ".join(map(str, B)))) if __name__ == "__main__": resolve()
false
51.515152
[ "-from collections import deque", "+import sys", "-n = int(eval(input()))", "-A = list(map(int, input().split()))", "-B = deque()", "-for i in range(n):", "- if i % 2 == 0:", "- B.append(A[i])", "+# import numpy as np", "+from collections import Counter, deque", "+", "+sys.setrecursi...
false
0.080122
0.042868
1.869016
[ "s989945202", "s023761498" ]
u130900604
p03107
python
s234788999
s721654913
26
20
3,956
3,956
Accepted
Accepted
23.08
def main(): msg=list(eval(input())) a,b=0,0 for _ in msg: if _ == "0": a+=1 else: b+=1 ans=2*min(a,b) print(ans) main()
def main(): msg=list(eval(input())) a=msg.count("1") b=len(msg)-a print((2*min(a,b))) main()
11
6
157
97
def main(): msg = list(eval(input())) a, b = 0, 0 for _ in msg: if _ == "0": a += 1 else: b += 1 ans = 2 * min(a, b) print(ans) main()
def main(): msg = list(eval(input())) a = msg.count("1") b = len(msg) - a print((2 * min(a, b))) main()
false
45.454545
[ "- a, b = 0, 0", "- for _ in msg:", "- if _ == \"0\":", "- a += 1", "- else:", "- b += 1", "- ans = 2 * min(a, b)", "- print(ans)", "+ a = msg.count(\"1\")", "+ b = len(msg) - a", "+ print((2 * min(a, b)))" ]
false
0.037917
0.043003
0.881712
[ "s234788999", "s721654913" ]
u146816547
p01102
python
s206477205
s736370247
10
0
4,648
4,652
Accepted
Accepted
100
while True: s1 = input() if s1 == '.': break s2 = input() s1 = s1.split('"') s2 = s2.split('"') if s1 == s2: print("IDENTICAL") elif len(s1) != len(s2): print("DIFFERENT") else: cnt = 0 for i in range(len(s1)): if s1[i] != s2[i] and i % 2 == 1: cnt += 1 elif s1[i] != s2[i]: cnt += 2 print("CLOSE" if cnt == 1 else "DIFFERENT")
def solve(s, t): s = s.split('"') t = t.split('"') if s == t: return "IDENTICAL" if len(s) == len(t): cnt = 0 for i in range(len(s)): if s[i] != t[i] and i % 2 == 1: cnt += 1 elif s[i] != t[i]: cnt += 2 if cnt == 1: return 'CLOSE' return 'DIFFERENT' while True: s1 = input() if s1 == '.': break s2 = input() print(solve(s1, s2))
26
28
504
507
while True: s1 = input() if s1 == ".": break s2 = input() s1 = s1.split('"') s2 = s2.split('"') if s1 == s2: print("IDENTICAL") elif len(s1) != len(s2): print("DIFFERENT") else: cnt = 0 for i in range(len(s1)): if s1[i] != s2[i] and i % 2 == 1: cnt += 1 elif s1[i] != s2[i]: cnt += 2 print("CLOSE" if cnt == 1 else "DIFFERENT")
def solve(s, t): s = s.split('"') t = t.split('"') if s == t: return "IDENTICAL" if len(s) == len(t): cnt = 0 for i in range(len(s)): if s[i] != t[i] and i % 2 == 1: cnt += 1 elif s[i] != t[i]: cnt += 2 if cnt == 1: return "CLOSE" return "DIFFERENT" while True: s1 = input() if s1 == ".": break s2 = input() print(solve(s1, s2))
false
7.142857
[ "+def solve(s, t):", "+ s = s.split('\"')", "+ t = t.split('\"')", "+ if s == t:", "+ return \"IDENTICAL\"", "+ if len(s) == len(t):", "+ cnt = 0", "+ for i in range(len(s)):", "+ if s[i] != t[i] and i % 2 == 1:", "+ cnt += 1", "+ ...
false
0.061851
0.061316
1.008714
[ "s206477205", "s736370247" ]
u146803137
p03030
python
s218954433
s182934804
26
24
9,180
9,032
Accepted
Accepted
7.69
n = int(eval(input())) d = {} for i in range(n): s ,p = input().split() p = int(p) if not(s in d): d[s] = {} d[s][p*-1] = i+1 for i in sorted(d.keys()): for j in sorted(d[i].keys()): print((d[i][j]))
n = int(eval(input())) s = [] p = [0] * 101 d = {} for i in range(n): a,b = input().split() b = int(b) s.append(a) p[b] = i+1 if a in list(d.keys()): d[a].append(b) continue d[a] = [b] s = sorted(set(s)) for i in s: c = sorted(d[i],reverse=True) for j in c: print((p[j]))
11
18
238
337
n = int(eval(input())) d = {} for i in range(n): s, p = input().split() p = int(p) if not (s in d): d[s] = {} d[s][p * -1] = i + 1 for i in sorted(d.keys()): for j in sorted(d[i].keys()): print((d[i][j]))
n = int(eval(input())) s = [] p = [0] * 101 d = {} for i in range(n): a, b = input().split() b = int(b) s.append(a) p[b] = i + 1 if a in list(d.keys()): d[a].append(b) continue d[a] = [b] s = sorted(set(s)) for i in s: c = sorted(d[i], reverse=True) for j in c: print((p[j]))
false
38.888889
[ "+s = []", "+p = [0] * 101", "- s, p = input().split()", "- p = int(p)", "- if not (s in d):", "- d[s] = {}", "- d[s][p * -1] = i + 1", "-for i in sorted(d.keys()):", "- for j in sorted(d[i].keys()):", "- print((d[i][j]))", "+ a, b = input().split()", "+ b = ...
false
0.038479
0.03971
0.969023
[ "s218954433", "s182934804" ]
u550835660
p02756
python
s458416643
s525122655
1,439
1,302
40,656
41,712
Accepted
Accepted
9.52
s = eval(input()) q = int(eval(input())) qs = [input().split() for i in range(q)] n = False left= right = "" for operation in qs: if operation[0] == '1': n = not n if operation[0] == '2': t , f, c = operation f = int(f) if n: f = 1 if f != 1 else 2 if f == 1: left=c+left elif f == 2: right+=c s = left+s+right print((s[::-1] if n else s))
s = eval(input()) q = int(eval(input())) qs = [input().split() for i in range(q)] n = False left= right = "" for operation in qs: if operation[0] == '1': n = not n if operation[0] == '2': t , f, c = operation if n: f = '1' if f != '1' else '2' if f == '1': left=c+left elif f == '2': right+=c s = left+s+right print((s[::-1] if n else s))
19
18
435
425
s = eval(input()) q = int(eval(input())) qs = [input().split() for i in range(q)] n = False left = right = "" for operation in qs: if operation[0] == "1": n = not n if operation[0] == "2": t, f, c = operation f = int(f) if n: f = 1 if f != 1 else 2 if f == 1: left = c + left elif f == 2: right += c s = left + s + right print((s[::-1] if n else s))
s = eval(input()) q = int(eval(input())) qs = [input().split() for i in range(q)] n = False left = right = "" for operation in qs: if operation[0] == "1": n = not n if operation[0] == "2": t, f, c = operation if n: f = "1" if f != "1" else "2" if f == "1": left = c + left elif f == "2": right += c s = left + s + right print((s[::-1] if n else s))
false
5.263158
[ "- f = int(f)", "- f = 1 if f != 1 else 2", "- if f == 1:", "+ f = \"1\" if f != \"1\" else \"2\"", "+ if f == \"1\":", "- elif f == 2:", "+ elif f == \"2\":" ]
false
0.038687
0.038951
0.993247
[ "s458416643", "s525122655" ]
u506127000
p03912
python
s753098004
s310353490
323
283
54,380
54,252
Accepted
Accepted
12.38
MAX_X = 10 ** 5 + 100 def main(): N, M = [int(i) for i in input().split()] X = [0] * (MAX_X + 1) for i in map(int, input().split()): X[i] += 1 Y = [sum(X[i::M]) for i in range(min(M, MAX_X))] # Mの倍数 ans = Y[0] // 2 Y[0] = 0 # M%2==0のM/2 if M % 2 == 0: ans += Y[M//2] // 2 Y[M//2] = 0 for i in range(1, M//2+1): j = M - i tmp = min(Y[i], Y[j]) ans += tmp Y[i] -= tmp Y[j] -= tmp try: for i, n in enumerate(X): j = i % M if Y[j] < 2 or n < 2: continue tmp = min(Y[j]-Y[j]%2, n-n%2) ans += tmp // 2 Y[j] -= tmp except IndexError: print((-1)) print(ans) if __name__ == "__main__": main()
MAX_X = 10 ** 5 + 100 def main(): N, M = [int(i) for i in input().split()] X = [0] * (MAX_X + 1) for i in map(int, input().split()): X[i] += 1 Y = [sum(X[i::M]) for i in range(min(M, MAX_X))] # Mの倍数 ans = Y[0] // 2 Y[0] = 0 # M%2==0のM/2 try: if M % 2 == 0: ans += Y[M//2] // 2 Y[M//2] = 0 for i in range(1, M//2+1): j = M - i tmp = min(Y[i], Y[j]) ans += tmp Y[i] -= tmp Y[j] -= tmp except IndexError: print((-1)) for i, n in enumerate(X): j = i % M if Y[j] < 2 or n < 2: continue tmp = min(Y[j]-Y[j]%2, n-n%2) ans += tmp // 2 Y[j] -= tmp print(ans) if __name__ == "__main__": main()
35
35
838
846
MAX_X = 10**5 + 100 def main(): N, M = [int(i) for i in input().split()] X = [0] * (MAX_X + 1) for i in map(int, input().split()): X[i] += 1 Y = [sum(X[i::M]) for i in range(min(M, MAX_X))] # Mの倍数 ans = Y[0] // 2 Y[0] = 0 # M%2==0のM/2 if M % 2 == 0: ans += Y[M // 2] // 2 Y[M // 2] = 0 for i in range(1, M // 2 + 1): j = M - i tmp = min(Y[i], Y[j]) ans += tmp Y[i] -= tmp Y[j] -= tmp try: for i, n in enumerate(X): j = i % M if Y[j] < 2 or n < 2: continue tmp = min(Y[j] - Y[j] % 2, n - n % 2) ans += tmp // 2 Y[j] -= tmp except IndexError: print((-1)) print(ans) if __name__ == "__main__": main()
MAX_X = 10**5 + 100 def main(): N, M = [int(i) for i in input().split()] X = [0] * (MAX_X + 1) for i in map(int, input().split()): X[i] += 1 Y = [sum(X[i::M]) for i in range(min(M, MAX_X))] # Mの倍数 ans = Y[0] // 2 Y[0] = 0 # M%2==0のM/2 try: if M % 2 == 0: ans += Y[M // 2] // 2 Y[M // 2] = 0 for i in range(1, M // 2 + 1): j = M - i tmp = min(Y[i], Y[j]) ans += tmp Y[i] -= tmp Y[j] -= tmp except IndexError: print((-1)) for i, n in enumerate(X): j = i % M if Y[j] < 2 or n < 2: continue tmp = min(Y[j] - Y[j] % 2, n - n % 2) ans += tmp // 2 Y[j] -= tmp print(ans) if __name__ == "__main__": main()
false
0
[ "- if M % 2 == 0:", "- ans += Y[M // 2] // 2", "- Y[M // 2] = 0", "- for i in range(1, M // 2 + 1):", "- j = M - i", "- tmp = min(Y[i], Y[j])", "- ans += tmp", "- Y[i] -= tmp", "- Y[j] -= tmp", "- for i, n in enumerate(X):", "- ...
false
0.052115
0.060482
0.861665
[ "s753098004", "s310353490" ]
u747602774
p02662
python
s778272470
s685696304
273
168
147,108
132,284
Accepted
Accepted
38.46
N,S = list(map(int,input().split())) A = list(map(int,input().split())) dp = [[0 for j in range(S+2)] for i in range(N+1)] dp[0][0] = 1 mod = 998244353 for i,a in enumerate(A): for j in range(S+1): if j-a >= 0: dp[i+1][j] = (dp[i][j]*2+dp[i][j-a])%mod else: dp[i+1][j] = dp[i][j]*2%mod print((dp[N][S]))
N,S = list(map(int,input().split())) A = list(map(int,input().split())) dp = [[0]*(S+2) for i in range(N+1)] dp[0][0] = 1 mod = 998244353 for i,a in enumerate(A): for j in range(S+1): if j-a >= 0: dp[i+1][j] = (dp[i][j]*2+dp[i][j-a])%mod else: dp[i+1][j] = dp[i][j]*2%mod print((dp[N][S]))
13
12
353
337
N, S = list(map(int, input().split())) A = list(map(int, input().split())) dp = [[0 for j in range(S + 2)] for i in range(N + 1)] dp[0][0] = 1 mod = 998244353 for i, a in enumerate(A): for j in range(S + 1): if j - a >= 0: dp[i + 1][j] = (dp[i][j] * 2 + dp[i][j - a]) % mod else: dp[i + 1][j] = dp[i][j] * 2 % mod print((dp[N][S]))
N, S = list(map(int, input().split())) A = list(map(int, input().split())) dp = [[0] * (S + 2) for i in range(N + 1)] dp[0][0] = 1 mod = 998244353 for i, a in enumerate(A): for j in range(S + 1): if j - a >= 0: dp[i + 1][j] = (dp[i][j] * 2 + dp[i][j - a]) % mod else: dp[i + 1][j] = dp[i][j] * 2 % mod print((dp[N][S]))
false
7.692308
[ "-dp = [[0 for j in range(S + 2)] for i in range(N + 1)]", "+dp = [[0] * (S + 2) for i in range(N + 1)]" ]
false
0.088669
0.038468
2.305015
[ "s778272470", "s685696304" ]
u764860452
p02837
python
s971866943
s640707950
153
91
3,188
3,064
Accepted
Accepted
40.52
def main(): N = int(eval(input())) testimony = [[] for _ in range(N)] for i in range(N): num = int(eval(input())) for j in range(num): person, state = list(map(int, input().split())) testimony[i].append([person-1, state]) honest = 0 for i in range(1, 2**N): flag = 0 for j in range(N): if (i>>j)&1 == 1: # j番目は正直と仮定 for x,y in testimony[j]: if (i>>x)&1 != y: # j番目は正直だが矛盾を発見 flag = 1 break if flag == 0: # 矛盾がある場合はflag == 1になる honest = max(honest, bin(i)[2:].count('1')) # 1の数をカウントし最大となるものを選択 print(honest) if __name__=="__main__": main()
from itertools import product N=int(eval(input())) data=[] for i in range(N): for j in range(int(eval(input()))): x,y=list(map(int,input().split())) data.append((i,x-1,y)) #print(data) ans=0 for i in product([1,0],repeat=N): #print(i) s=True for k in data: if i[k[0]]==1 and i[k[1]]!=k[2]: s=False break if s: ans=max(ans,sum(i)) print(ans)
25
20
771
419
def main(): N = int(eval(input())) testimony = [[] for _ in range(N)] for i in range(N): num = int(eval(input())) for j in range(num): person, state = list(map(int, input().split())) testimony[i].append([person - 1, state]) honest = 0 for i in range(1, 2**N): flag = 0 for j in range(N): if (i >> j) & 1 == 1: # j番目は正直と仮定 for x, y in testimony[j]: if (i >> x) & 1 != y: # j番目は正直だが矛盾を発見 flag = 1 break if flag == 0: # 矛盾がある場合はflag == 1になる honest = max(honest, bin(i)[2:].count("1")) # 1の数をカウントし最大となるものを選択 print(honest) if __name__ == "__main__": main()
from itertools import product N = int(eval(input())) data = [] for i in range(N): for j in range(int(eval(input()))): x, y = list(map(int, input().split())) data.append((i, x - 1, y)) # print(data) ans = 0 for i in product([1, 0], repeat=N): # print(i) s = True for k in data: if i[k[0]] == 1 and i[k[1]] != k[2]: s = False break if s: ans = max(ans, sum(i)) print(ans)
false
20
[ "-def main():", "- N = int(eval(input()))", "- testimony = [[] for _ in range(N)]", "- for i in range(N):", "- num = int(eval(input()))", "- for j in range(num):", "- person, state = list(map(int, input().split()))", "- testimony[i].append([person - 1, stat...
false
0.037458
0.046175
0.811212
[ "s971866943", "s640707950" ]
u190405389
p03450
python
s373437895
s690625579
1,393
400
106,144
84,736
Accepted
Accepted
71.28
n,m = list(map(int, input().split())) dist = [[] for i in range(n)] for i in range(m): l,r,d = list(map(int,input().split())) l-=1 r-=1 dist[l].append([r,d]) dist[r].append([l,-d]) position = [10**10]*n for i in range(n): if position[i]==10**10: stack = [i] position[i] = 0 while stack: p = stack.pop() for to,d in dist[p]: if position[to]==10**10: position[to]=position[p]+d stack.append(to) for i in range(n): for to,d in dist[i]: if position[to]-position[i]!=d: print('No') exit() print('Yes')
import sys sys.setrecursionlimit(10**7) readline = sys.stdin.buffer.readline def readstr():return readline().rstrip().decode() def readstrs():return list(readline().decode().split()) def readint():return int(readline()) def readints():return list(map(int,readline().split())) def printrows(x):print(('\n'.join(map(str,x)))) def printline(x):print((' '.join(map(str,x)))) class UnionFind_weight: # 初期化 def __init__(self, n): # 根なら-size, 子なら親の頂点 self.par = [-1] * n # 木の高さ self.rank = [0] * n # 親との差分 self.weight = [0] * n # 検索 def find(self, x): if self.par[x] < 0: return x else: p = self.par[x] # 根につなぎ直す前の親をメモ self.par[x] = self.find(self.par[x]) self.weight[x] += self.weight[p] return self.par[x] # 併合 # x → y の重みを w とする。 def unite(self, x, y, w): w += self.weight[x] - self.weight[y] x = self.find(x) y = self.find(y) if x != y: # 異なる集合に属する場合のみ併合 if self.rank[x] < self.rank[y]: # 高い方をxとする。 x,y = y,x w = -w if self.rank[x] == self.rank[y]: # 同じ高さの時は高さ+1 self.rank[x] += 1 # yの親をxとし、xのサイズにyのサイズを加える。重みも更新。 self.par[x] += self.par[y] self.par[y] = x self.weight[y] = w # 同集合判定 def same(self, x, y): return self.find(x) == self.find(y) # 集合の大きさ def size(self, x): return -self.par[self.find(x)] # x → y の重み def diff(self, x, y): return self.weight[y] - self.weight[x] n,m = readints() u = UnionFind_weight(n) ans = 1 for i in range(m): l,r,d = readints() l-=1;r-=1 if u.same(l,r): if u.diff(l,r) != d: ans = 0 break else: u.unite(l,r,d) print(('Yes' if ans else 'No'))
32
80
687
1,976
n, m = list(map(int, input().split())) dist = [[] for i in range(n)] for i in range(m): l, r, d = list(map(int, input().split())) l -= 1 r -= 1 dist[l].append([r, d]) dist[r].append([l, -d]) position = [10**10] * n for i in range(n): if position[i] == 10**10: stack = [i] position[i] = 0 while stack: p = stack.pop() for to, d in dist[p]: if position[to] == 10**10: position[to] = position[p] + d stack.append(to) for i in range(n): for to, d in dist[i]: if position[to] - position[i] != d: print("No") exit() print("Yes")
import sys sys.setrecursionlimit(10**7) readline = sys.stdin.buffer.readline def readstr(): return readline().rstrip().decode() def readstrs(): return list(readline().decode().split()) def readint(): return int(readline()) def readints(): return list(map(int, readline().split())) def printrows(x): print(("\n".join(map(str, x)))) def printline(x): print((" ".join(map(str, x)))) class UnionFind_weight: # 初期化 def __init__(self, n): # 根なら-size, 子なら親の頂点 self.par = [-1] * n # 木の高さ self.rank = [0] * n # 親との差分 self.weight = [0] * n # 検索 def find(self, x): if self.par[x] < 0: return x else: p = self.par[x] # 根につなぎ直す前の親をメモ self.par[x] = self.find(self.par[x]) self.weight[x] += self.weight[p] return self.par[x] # 併合 # x → y の重みを w とする。 def unite(self, x, y, w): w += self.weight[x] - self.weight[y] x = self.find(x) y = self.find(y) if x != y: # 異なる集合に属する場合のみ併合 if self.rank[x] < self.rank[y]: # 高い方をxとする。 x, y = y, x w = -w if self.rank[x] == self.rank[y]: # 同じ高さの時は高さ+1 self.rank[x] += 1 # yの親をxとし、xのサイズにyのサイズを加える。重みも更新。 self.par[x] += self.par[y] self.par[y] = x self.weight[y] = w # 同集合判定 def same(self, x, y): return self.find(x) == self.find(y) # 集合の大きさ def size(self, x): return -self.par[self.find(x)] # x → y の重み def diff(self, x, y): return self.weight[y] - self.weight[x] n, m = readints() u = UnionFind_weight(n) ans = 1 for i in range(m): l, r, d = readints() l -= 1 r -= 1 if u.same(l, r): if u.diff(l, r) != d: ans = 0 break else: u.unite(l, r, d) print(("Yes" if ans else "No"))
false
60
[ "-n, m = list(map(int, input().split()))", "-dist = [[] for i in range(n)]", "+import sys", "+", "+sys.setrecursionlimit(10**7)", "+readline = sys.stdin.buffer.readline", "+", "+", "+def readstr():", "+ return readline().rstrip().decode()", "+", "+", "+def readstrs():", "+ return lis...
false
0.054321
0.042785
1.269632
[ "s373437895", "s690625579" ]
u906501980
p02762
python
s697887373
s491247023
1,526
920
140,596
25,136
Accepted
Accepted
39.71
import sys input = sys.stdin.buffer.readline class UnionFind: __slots__ = ["data"] def __init__(self, n=0): self.data = [-1]*(n+1) def root(self, x): if self.data[x] < 0: return x self.data[x] = self.root(self.data[x]) return self.data[x] def unite(self, x, y): x = self.root(x) y = self.root(y) if x != y: if self.data[x] < self.data[y]: self.data[x] += self.data[y] self.data[y] = x else: self.data[y] += self.data[x] self.data[x] = y def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.data[self.root(x)] def main(): n, m, k = list(map(int, input().split())) friends = [[] for _ in range(n+1)] blocks = [[] for _ in range(n+1)] uf = UnionFind(n) for _ in range(m): a, b = list(map(int, input().split())) friends[a].append(b) friends[b].append(a) uf.unite(a, b) for _ in range(k): c, d = list(map(int, input().split())) blocks[c].append(d) blocks[d].append(c) for i in range(1, n+1): nf = len(friends[i]) nb = sum([uf.same(i, b) for b in blocks[i]]) ans = uf.size(i) - 1 - nf - nb print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.buffer.readline class UnionFind: __slots__ = ["data"] def __init__(self, n=0): self.data = [-1]*(n+1) def root(self, x): if self.data[x] < 0: return x self.data[x] = self.root(self.data[x]) return self.data[x] def unite(self, x, y): x = self.root(x) y = self.root(y) if x != y: if self.data[x] < self.data[y]: self.data[x] += self.data[y] self.data[y] = x else: self.data[y] += self.data[x] self.data[x] = y def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.data[self.root(x)] def main(): n, m, k = list(map(int, input().split())) friends = [0]*(n+1) blocks = [[] for _ in range(n+1)] uf = UnionFind(n) for _ in range(m): a, b = list(map(int, input().split())) friends[a] += 1 friends[b] += 1 uf.unite(a, b) for _ in range(k): c, d = list(map(int, input().split())) blocks[c].append(d) blocks[d].append(c) for i in range(1, n+1): nf = friends[i] nb = sum([uf.same(i, b) for b in blocks[i]]) ans = uf.size(i) - 1 - nf - nb print(ans) if __name__ == "__main__": main()
57
57
1,466
1,436
import sys input = sys.stdin.buffer.readline class UnionFind: __slots__ = ["data"] def __init__(self, n=0): self.data = [-1] * (n + 1) def root(self, x): if self.data[x] < 0: return x self.data[x] = self.root(self.data[x]) return self.data[x] def unite(self, x, y): x = self.root(x) y = self.root(y) if x != y: if self.data[x] < self.data[y]: self.data[x] += self.data[y] self.data[y] = x else: self.data[y] += self.data[x] self.data[x] = y def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.data[self.root(x)] def main(): n, m, k = list(map(int, input().split())) friends = [[] for _ in range(n + 1)] blocks = [[] for _ in range(n + 1)] uf = UnionFind(n) for _ in range(m): a, b = list(map(int, input().split())) friends[a].append(b) friends[b].append(a) uf.unite(a, b) for _ in range(k): c, d = list(map(int, input().split())) blocks[c].append(d) blocks[d].append(c) for i in range(1, n + 1): nf = len(friends[i]) nb = sum([uf.same(i, b) for b in blocks[i]]) ans = uf.size(i) - 1 - nf - nb print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.buffer.readline class UnionFind: __slots__ = ["data"] def __init__(self, n=0): self.data = [-1] * (n + 1) def root(self, x): if self.data[x] < 0: return x self.data[x] = self.root(self.data[x]) return self.data[x] def unite(self, x, y): x = self.root(x) y = self.root(y) if x != y: if self.data[x] < self.data[y]: self.data[x] += self.data[y] self.data[y] = x else: self.data[y] += self.data[x] self.data[x] = y def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.data[self.root(x)] def main(): n, m, k = list(map(int, input().split())) friends = [0] * (n + 1) blocks = [[] for _ in range(n + 1)] uf = UnionFind(n) for _ in range(m): a, b = list(map(int, input().split())) friends[a] += 1 friends[b] += 1 uf.unite(a, b) for _ in range(k): c, d = list(map(int, input().split())) blocks[c].append(d) blocks[d].append(c) for i in range(1, n + 1): nf = friends[i] nb = sum([uf.same(i, b) for b in blocks[i]]) ans = uf.size(i) - 1 - nf - nb print(ans) if __name__ == "__main__": main()
false
0
[ "- friends = [[] for _ in range(n + 1)]", "+ friends = [0] * (n + 1)", "- friends[a].append(b)", "- friends[b].append(a)", "+ friends[a] += 1", "+ friends[b] += 1", "- nf = len(friends[i])", "+ nf = friends[i]" ]
false
0.177213
0.042954
4.125693
[ "s697887373", "s491247023" ]
u875291233
p02684
python
s314374961
s600803163
452
133
183,328
93,600
Accepted
Accepted
70.58
# coding: utf-8 # Your code here! import sys read = sys.stdin.read readline = sys.stdin.readline n,k,*a = list(map(int,read().split())) for i in range(n): a[i] -= 1 def pow2(a,n): if n==0: return list(range(n)) if n==1: return a if n%2: return mul(a,pow2(a,n-1)) else: x = pow2(a,n//2) return mul(x,x) def mul(a,b): return [a[bi] for bi in b] x = pow2(a,k) print((x[0]+1))
# coding: utf-8 # Your code here! import sys read = sys.stdin.read readline = sys.stdin.readline n,k,*a = list(map(int,read().split())) for i in range(n): a[i] -= 1 na = [0]*n v = 0 while k: if k&1: v = a[v] for j, aj in enumerate(a): na[j] = a[aj] a,na = na,a i += 1 k >>= 1 print((v+1))
23
20
441
341
# coding: utf-8 # Your code here! import sys read = sys.stdin.read readline = sys.stdin.readline n, k, *a = list(map(int, read().split())) for i in range(n): a[i] -= 1 def pow2(a, n): if n == 0: return list(range(n)) if n == 1: return a if n % 2: return mul(a, pow2(a, n - 1)) else: x = pow2(a, n // 2) return mul(x, x) def mul(a, b): return [a[bi] for bi in b] x = pow2(a, k) print((x[0] + 1))
# coding: utf-8 # Your code here! import sys read = sys.stdin.read readline = sys.stdin.readline n, k, *a = list(map(int, read().split())) for i in range(n): a[i] -= 1 na = [0] * n v = 0 while k: if k & 1: v = a[v] for j, aj in enumerate(a): na[j] = a[aj] a, na = na, a i += 1 k >>= 1 print((v + 1))
false
13.043478
[ "-", "-", "-def pow2(a, n):", "- if n == 0:", "- return list(range(n))", "- if n == 1:", "- return a", "- if n % 2:", "- return mul(a, pow2(a, n - 1))", "- else:", "- x = pow2(a, n // 2)", "- return mul(x, x)", "-", "-", "-def mul(a, b):", ...
false
0.077411
0.036932
2.096062
[ "s314374961", "s600803163" ]
u703950586
p03044
python
s658355498
s931935774
930
556
160,428
80,392
Accepted
Accepted
40.22
import sys,queue,math,copy,itertools,bisect,collections sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 LI = lambda : [int(x) for x in sys.stdin.readline().split()] _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) N = NI() edge = [[] for _ in range(N+1)] color = [-1] * (N+1) for _ in range(N-1): u,v,w = LI() edge[u].append((v,w)) edge[v].append((u,w)) def set_color(u,c): color[u] = c for v,w in edge[u]: if color[v] >= 0 : continue set_color(v,(w % 2) ^ c) set_color(1,0) print(*color[1:],sep='\n')
import sys,queue,math,copy,itertools,bisect,collections sys.setrecursionlimit(10**7) LI = lambda : [int(x) for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) N = NI() edge = [[] for _ in range(N+1)] color = [-1] * (N+1) for _ in range(N-1): u,v,w = LI() edge[u].append((v,w)) edge[v].append((u,w)) def set_color(u,c): color[u] = c for v,w in edge[u]: if color[v] >= 0 : continue set_color(v,(w % 2) ^ c) set_color(1,0) print(*color[1:],sep='\n')
23
20
627
531
import sys, queue, math, copy, itertools, bisect, collections sys.setrecursionlimit(10**7) INF = 10**18 MOD = 10**9 + 7 LI = lambda: [int(x) for x in sys.stdin.readline().split()] _LI = lambda: [int(x) - 1 for x in sys.stdin.readline().split()] NI = lambda: int(sys.stdin.readline()) N = NI() edge = [[] for _ in range(N + 1)] color = [-1] * (N + 1) for _ in range(N - 1): u, v, w = LI() edge[u].append((v, w)) edge[v].append((u, w)) def set_color(u, c): color[u] = c for v, w in edge[u]: if color[v] >= 0: continue set_color(v, (w % 2) ^ c) set_color(1, 0) print(*color[1:], sep="\n")
import sys, queue, math, copy, itertools, bisect, collections sys.setrecursionlimit(10**7) LI = lambda: [int(x) for x in sys.stdin.readline().split()] NI = lambda: int(sys.stdin.readline()) N = NI() edge = [[] for _ in range(N + 1)] color = [-1] * (N + 1) for _ in range(N - 1): u, v, w = LI() edge[u].append((v, w)) edge[v].append((u, w)) def set_color(u, c): color[u] = c for v, w in edge[u]: if color[v] >= 0: continue set_color(v, (w % 2) ^ c) set_color(1, 0) print(*color[1:], sep="\n")
false
13.043478
[ "-INF = 10**18", "-MOD = 10**9 + 7", "-_LI = lambda: [int(x) - 1 for x in sys.stdin.readline().split()]" ]
false
0.096767
0.038229
2.53123
[ "s658355498", "s931935774" ]
u868701750
p03835
python
s437737161
s590094664
1,985
1,225
2,940
2,940
Accepted
Accepted
38.29
# -*- coding: utf-8 -*- K, S = list(map(int, input().split())) count = 0 for x in range(0, K+1): for y in range(0, K+1): z = S - x - y if z < 0 or z > K: continue if x + y + z == S: count += 1 print(count)
K, S = list(map(int, input().split())) c = 0 for x in range(K+1): for y in range(K+1): if 0 <= (S-x-y) <= K: c += 1 print(c)
14
7
268
149
# -*- coding: utf-8 -*- K, S = list(map(int, input().split())) count = 0 for x in range(0, K + 1): for y in range(0, K + 1): z = S - x - y if z < 0 or z > K: continue if x + y + z == S: count += 1 print(count)
K, S = list(map(int, input().split())) c = 0 for x in range(K + 1): for y in range(K + 1): if 0 <= (S - x - y) <= K: c += 1 print(c)
false
50
[ "-# -*- coding: utf-8 -*-", "-count = 0", "-for x in range(0, K + 1):", "- for y in range(0, K + 1):", "- z = S - x - y", "- if z < 0 or z > K:", "- continue", "- if x + y + z == S:", "- count += 1", "-print(count)", "+c = 0", "+for x in range(K + ...
false
0.044543
0.037473
1.188648
[ "s437737161", "s590094664" ]
u530606147
p02640
python
s208226797
s502942850
23
21
9,156
9,128
Accepted
Accepted
8.7
x, y = list(map(int, input().split())) for i in range(x + 1): if 2 * i + 4 * (x - i) == y: print('Yes') exit() print('No')
x, y = list(map(int, input().split())) a2 = 4 * x - y if a2 % 2 == 0 and 0 <= a2 // 2 <= x: print('Yes') else: print('No')
8
7
142
134
x, y = list(map(int, input().split())) for i in range(x + 1): if 2 * i + 4 * (x - i) == y: print("Yes") exit() print("No")
x, y = list(map(int, input().split())) a2 = 4 * x - y if a2 % 2 == 0 and 0 <= a2 // 2 <= x: print("Yes") else: print("No")
false
12.5
[ "-for i in range(x + 1):", "- if 2 * i + 4 * (x - i) == y:", "- print(\"Yes\")", "- exit()", "-print(\"No\")", "+a2 = 4 * x - y", "+if a2 % 2 == 0 and 0 <= a2 // 2 <= x:", "+ print(\"Yes\")", "+else:", "+ print(\"No\")" ]
false
0.116044
0.116052
0.999932
[ "s208226797", "s502942850" ]
u826929627
p03361
python
s583418279
s980131392
20
18
3,064
3,064
Accepted
Accepted
10
"""考え方 上下左右のいずれか隣接するマスが黒である必要がある。 つまり黒マスが1つだけポツンと存在した場合はNGとなる。 横チェック、縦チェック、の2つに分断して確認を行う。 """ H,W = list(map(int,input().split())) list_matu = [] for h in range(H): list_matu.append(list(eval(input()))) ## 横チェック ng_matu=[] for h in range(H): ## 全レコードが対象 for w in range(1,W-1): ## 列ごとに実施 target = list_matu[h][w] target_left = list_matu[h][w-1] target_right = list_matu[h][w+1] if target=='#': if (target_left != '#') and (target_right != '#'): ng_matu.append([h,w]) ## 縦チェック for w in range(W): for h in range(1,H-1): target = list_matu[h][w] target_over = list_matu[h+1][w] target_under = list_matu[h-1][w] if target=='#': if (target_over != '#') and (target_under != '#'): if [h,w] in ng_matu: print('No') exit() print('Yes')
H,W = list(map(int , input().split() )) """考え方 普通に全探索して問題あるか無いかを確認して行く。 1行目、H行目、1列目、W列目だけは少し注意!!! →0行目、H+1行目、0列目、W+1列目を追加する """ list_ = [] list_.append(['.' for i in range(W+2)]) for h in range(H): list_.append(list('.'+eval(input())+'.')) list_.append(['.' for i in range(W+2)]) ans = 'Yes' for h in range(H): for w in range(W): ## 黒にする箇所があった時に、上下左右のいずれかに黒色の箇所があればOK!!! if list_[h][w] == '#': if list_[h-1][w] == '.': if list_[h+1][w] == '.': if list_[h][w-1] == '.': if list_[h][w+1] == '.': ans = 'No' break print(ans)
43
27
863
620
"""考え方 上下左右のいずれか隣接するマスが黒である必要がある。 つまり黒マスが1つだけポツンと存在した場合はNGとなる。 横チェック、縦チェック、の2つに分断して確認を行う。 """ H, W = list(map(int, input().split())) list_matu = [] for h in range(H): list_matu.append(list(eval(input()))) ## 横チェック ng_matu = [] for h in range(H): ## 全レコードが対象 for w in range(1, W - 1): ## 列ごとに実施 target = list_matu[h][w] target_left = list_matu[h][w - 1] target_right = list_matu[h][w + 1] if target == "#": if (target_left != "#") and (target_right != "#"): ng_matu.append([h, w]) ## 縦チェック for w in range(W): for h in range(1, H - 1): target = list_matu[h][w] target_over = list_matu[h + 1][w] target_under = list_matu[h - 1][w] if target == "#": if (target_over != "#") and (target_under != "#"): if [h, w] in ng_matu: print("No") exit() print("Yes")
H, W = list(map(int, input().split())) """考え方 普通に全探索して問題あるか無いかを確認して行く。 1行目、H行目、1列目、W列目だけは少し注意!!! →0行目、H+1行目、0列目、W+1列目を追加する """ list_ = [] list_.append(["." for i in range(W + 2)]) for h in range(H): list_.append(list("." + eval(input()) + ".")) list_.append(["." for i in range(W + 2)]) ans = "Yes" for h in range(H): for w in range(W): ## 黒にする箇所があった時に、上下左右のいずれかに黒色の箇所があればOK!!! if list_[h][w] == "#": if list_[h - 1][w] == ".": if list_[h + 1][w] == ".": if list_[h][w - 1] == ".": if list_[h][w + 1] == ".": ans = "No" break print(ans)
false
37.209302
[ "+H, W = list(map(int, input().split()))", "-上下左右のいずれか隣接するマスが黒である必要がある。", "-つまり黒マスが1つだけポツンと存在した場合はNGとなる。", "-横チェック、縦チェック、の2つに分断して確認を行う。", "+普通に全探索して問題あるか無いかを確認して行く。", "+1行目、H行目、1列目、W列目だけは少し注意!!!", "+→0行目、H+1行目、0列目、W+1列目を追加する", "-H, W = list(map(int, input().split()))", "-list_matu = []", "+list_ =...
false
0.036165
0.036807
0.982551
[ "s583418279", "s980131392" ]
u408260374
p01545
python
s811511311
s226587317
4,020
1,440
27,952
27,748
Accepted
Accepted
64.18
import math class SegmentTree: """ Segment Tree query: 1. update(i, val): update i-th value to val 2. query(low, high): find f(value) in [low, high) time complexity: O(log n) space complexity: O(2n) """ def __init__(self, N, f, default): self.N = 1 << math.ceil(math.log(N, 2)) self.default = default self.f = f self.segtree = [self.default] * (self.N * 2 - 1) def update(self, i, val): i += self.N - 1 self.segtree[i] = val while i > 0: i = (i - 1) // 2 self.segtree[i] = self.f(self.segtree[2*i+1], self.segtree[2*i+2]) def query(self, low, high, k=0, left=0, right=-1): if right == -1: right = self.N if right <= low or high <= left: return self.default if low <= left and right <= high: return self.segtree[k] else: mid = (left + right) // 2 return self.f(self.query(low, high, 2*k+1, left, mid), self.query(low, high, 2*k+2, mid, right)) N = int(eval(input())) X = [int(x) for x in input().split()] dp = SegmentTree(N, lambda x, y: max(x, y), 0) for x, i in sorted((x, i) for i, x in enumerate(X)): dp.update(i, dp.query(0, i) + x) print((N * (N + 1) // 2 - dp.query(0, N)))
import math class FenwickTree: def __init__(self, a_list, f, default): # 0-indexed self.N = len(a_list) self.bit = a_list[:] self.f = f self.default = default for _ in range(self.N, 1 << (math.ceil(math.log(self.N, 2)))): self.bit.append(self.default) for i in range(self.N - 1): self.bit[i | (i + 1)] = self.f(self.bit[i | (i + 1)], self.bit[i]) def update(self, i, val): while i < self.N: self.bit[i] = self.f(self.bit[i], val) i |= i + 1 def query(self, n): # [0, n] ret = 0 while n >= 0: ret = self.f(ret, self.bit[n]) n = (n & (n + 1)) - 1 return ret N = int(eval(input())) X = [int(x) for x in input().split()] dp = FenwickTree([0] * N, lambda x, y: max(x, y), 0) for x, i in sorted((x, i) for i, x in enumerate(X)): dp.update(i, dp.query(i) + x) print((N * (N + 1) // 2 - dp.query(N - 1)))
45
35
1,368
1,012
import math class SegmentTree: """ Segment Tree query: 1. update(i, val): update i-th value to val 2. query(low, high): find f(value) in [low, high) time complexity: O(log n) space complexity: O(2n) """ def __init__(self, N, f, default): self.N = 1 << math.ceil(math.log(N, 2)) self.default = default self.f = f self.segtree = [self.default] * (self.N * 2 - 1) def update(self, i, val): i += self.N - 1 self.segtree[i] = val while i > 0: i = (i - 1) // 2 self.segtree[i] = self.f(self.segtree[2 * i + 1], self.segtree[2 * i + 2]) def query(self, low, high, k=0, left=0, right=-1): if right == -1: right = self.N if right <= low or high <= left: return self.default if low <= left and right <= high: return self.segtree[k] else: mid = (left + right) // 2 return self.f( self.query(low, high, 2 * k + 1, left, mid), self.query(low, high, 2 * k + 2, mid, right), ) N = int(eval(input())) X = [int(x) for x in input().split()] dp = SegmentTree(N, lambda x, y: max(x, y), 0) for x, i in sorted((x, i) for i, x in enumerate(X)): dp.update(i, dp.query(0, i) + x) print((N * (N + 1) // 2 - dp.query(0, N)))
import math class FenwickTree: def __init__(self, a_list, f, default): # 0-indexed self.N = len(a_list) self.bit = a_list[:] self.f = f self.default = default for _ in range(self.N, 1 << (math.ceil(math.log(self.N, 2)))): self.bit.append(self.default) for i in range(self.N - 1): self.bit[i | (i + 1)] = self.f(self.bit[i | (i + 1)], self.bit[i]) def update(self, i, val): while i < self.N: self.bit[i] = self.f(self.bit[i], val) i |= i + 1 def query(self, n): # [0, n] ret = 0 while n >= 0: ret = self.f(ret, self.bit[n]) n = (n & (n + 1)) - 1 return ret N = int(eval(input())) X = [int(x) for x in input().split()] dp = FenwickTree([0] * N, lambda x, y: max(x, y), 0) for x, i in sorted((x, i) for i, x in enumerate(X)): dp.update(i, dp.query(i) + x) print((N * (N + 1) // 2 - dp.query(N - 1)))
false
22.222222
[ "-class SegmentTree:", "- \"\"\"", "- Segment Tree", "- query:", "- 1. update(i, val): update i-th value to val", "- 2. query(low, high): find f(value) in [low, high)", "- time complexity: O(log n)", "- space complexity: O(2n)", "- \"\"\"", "-", "- def __init__(self, N...
false
0.100297
0.157751
0.635794
[ "s811511311", "s226587317" ]
u014333473
p04030
python
s422006828
s839314832
30
25
9,032
9,000
Accepted
Accepted
16.67
s=eval(input()) result = [] for i in s: if i=='0': result.append('0') elif i=='1': result.append('1') elif i=='B': if not result: continue result.pop() print((''.join(result)))
n=[] for i in input(): if i=='B': if n: n.pop() else: n.append(i) print(*n,sep='')
12
7
207
100
s = eval(input()) result = [] for i in s: if i == "0": result.append("0") elif i == "1": result.append("1") elif i == "B": if not result: continue result.pop() print(("".join(result)))
n = [] for i in input(): if i == "B": if n: n.pop() else: n.append(i) print(*n, sep="")
false
41.666667
[ "-s = eval(input())", "-result = []", "-for i in s:", "- if i == \"0\":", "- result.append(\"0\")", "- elif i == \"1\":", "- result.append(\"1\")", "- elif i == \"B\":", "- if not result:", "- continue", "- result.pop()", "-print((\"\".join(resul...
false
0.188795
0.043726
4.317708
[ "s422006828", "s839314832" ]
u811434779
p00430
python
s318076323
s800821733
130
100
6,468
6,272
Accepted
Accepted
23.08
l = [0 for i in range(31)] pos = goal = 0 def solve(cur,sum): global pos, goal if cur == goal: print(" ".join(map(str,l[:pos]))) return for i in range(sum,0,-1): if cur + i <= goal: l[pos] = i pos += 1 solve(cur+i,i) pos -= 1 while True: goal = int(input()) if goal==0: break solve(0,goal)
l = [0]*31 pos = goal = 0 def solve(cur,sum): global pos, goal if cur == goal: print(" ".join(map(str,l[:pos]))) return for i in range(sum,0,-1): if cur + i <= goal: l[pos] = i pos += 1 solve(cur+i,i) pos -= 1 while True: goal = int(input()) if goal == 0: break solve(0,goal)
17
17
404
390
l = [0 for i in range(31)] pos = goal = 0 def solve(cur, sum): global pos, goal if cur == goal: print(" ".join(map(str, l[:pos]))) return for i in range(sum, 0, -1): if cur + i <= goal: l[pos] = i pos += 1 solve(cur + i, i) pos -= 1 while True: goal = int(input()) if goal == 0: break solve(0, goal)
l = [0] * 31 pos = goal = 0 def solve(cur, sum): global pos, goal if cur == goal: print(" ".join(map(str, l[:pos]))) return for i in range(sum, 0, -1): if cur + i <= goal: l[pos] = i pos += 1 solve(cur + i, i) pos -= 1 while True: goal = int(input()) if goal == 0: break solve(0, goal)
false
0
[ "-l = [0 for i in range(31)]", "+l = [0] * 31" ]
false
0.043477
0.101092
0.430072
[ "s318076323", "s800821733" ]
u141610915
p03666
python
s935006466
s352766522
189
71
40,428
67,932
Accepted
Accepted
62.43
import sys input = sys.stdin.readline N, A, B, C, D = list(map(int, input().split())) for i in range(N - 1): r = D * (N - i - 1) + A l = C * (N - i - 1) + A r -= C * i l -= D * i #print(l, r, i) if B in range(l, r + 1): print("YES") exit(0) print("NO")
import sys input = sys.stdin.readline N, A, B, C, D = list(map(int, input().split())) for i in range(N - 1): l = C * i + A - D * (N - i - 1) r = D * i + A - C * (N - i - 1) + 1 if B in range(l, r): print("YES") break else: print("NO")
14
10
280
251
import sys input = sys.stdin.readline N, A, B, C, D = list(map(int, input().split())) for i in range(N - 1): r = D * (N - i - 1) + A l = C * (N - i - 1) + A r -= C * i l -= D * i # print(l, r, i) if B in range(l, r + 1): print("YES") exit(0) print("NO")
import sys input = sys.stdin.readline N, A, B, C, D = list(map(int, input().split())) for i in range(N - 1): l = C * i + A - D * (N - i - 1) r = D * i + A - C * (N - i - 1) + 1 if B in range(l, r): print("YES") break else: print("NO")
false
28.571429
[ "- r = D * (N - i - 1) + A", "- l = C * (N - i - 1) + A", "- r -= C * i", "- l -= D * i", "- # print(l, r, i)", "- if B in range(l, r + 1):", "+ l = C * i + A - D * (N - i - 1)", "+ r = D * i + A - C * (N - i - 1) + 1", "+ if B in range(l, r):", "- exit(0)", "-p...
false
0.159013
0.152277
1.044235
[ "s935006466", "s352766522" ]
u867848444
p03545
python
s110200065
s365485318
20
18
3,064
3,064
Accepted
Accepted
10
l=list(map(int,eval(input()))) n=3 for i in range(2**n): s = str(l[0]) sum_s = l[0] for j in range(n): #j桁目が1の時 if (i>>j)&1: s+='+'+str(l[j+1]) sum_s+=l[j+1] #j桁目が0の時 else: s+='-'+str(l[j+1]) sum_s-=l[j+1] if sum_s==7: print((s+'=7')) exit()
l=list(map(int,eval(input()))) def dfs(i,s,sum): if i==3: if sum==7: print((s+'=7')) exit() else: dfs(i+1,s+'-'+str(l[i+1]),sum-l[i+1]) dfs(i+1,s+'+'+str(l[i+1]),sum+l[i+1]) return -1 dfs(0,str(l[0]),l[0])
19
13
365
271
l = list(map(int, eval(input()))) n = 3 for i in range(2**n): s = str(l[0]) sum_s = l[0] for j in range(n): # j桁目が1の時 if (i >> j) & 1: s += "+" + str(l[j + 1]) sum_s += l[j + 1] # j桁目が0の時 else: s += "-" + str(l[j + 1]) sum_s -= l[j + 1] if sum_s == 7: print((s + "=7")) exit()
l = list(map(int, eval(input()))) def dfs(i, s, sum): if i == 3: if sum == 7: print((s + "=7")) exit() else: dfs(i + 1, s + "-" + str(l[i + 1]), sum - l[i + 1]) dfs(i + 1, s + "+" + str(l[i + 1]), sum + l[i + 1]) return -1 dfs(0, str(l[0]), l[0])
false
31.578947
[ "-n = 3", "-for i in range(2**n):", "- s = str(l[0])", "- sum_s = l[0]", "- for j in range(n):", "- # j桁目が1の時", "- if (i >> j) & 1:", "- s += \"+\" + str(l[j + 1])", "- sum_s += l[j + 1]", "- # j桁目が0の時", "- else:", "- s += \...
false
0.039196
0.038378
1.021327
[ "s110200065", "s365485318" ]
u620084012
p03807
python
s359250855
s241531882
226
55
62,448
14,108
Accepted
Accepted
75.66
N = int(eval(input())) A = list(map(int,input().split())) c = 0 for e in A: if e%2 == 1: c += 1 if c%2 == 1: print("NO") else: print("YES")
N = int(eval(input())) A = list(map(int,input().split())) t = 0 for e in A: t += e%2 print(("YES" if t%2 == 0 else "NO"))
10
6
163
123
N = int(eval(input())) A = list(map(int, input().split())) c = 0 for e in A: if e % 2 == 1: c += 1 if c % 2 == 1: print("NO") else: print("YES")
N = int(eval(input())) A = list(map(int, input().split())) t = 0 for e in A: t += e % 2 print(("YES" if t % 2 == 0 else "NO"))
false
40
[ "-c = 0", "+t = 0", "- if e % 2 == 1:", "- c += 1", "-if c % 2 == 1:", "- print(\"NO\")", "-else:", "- print(\"YES\")", "+ t += e % 2", "+print((\"YES\" if t % 2 == 0 else \"NO\"))" ]
false
0.038469
0.06787
0.566805
[ "s359250855", "s241531882" ]
u780475861
p03246
python
s323517549
s454148251
103
89
20,396
20,572
Accepted
Accepted
13.59
from collections import Counter def main(): n = int(eval(input())) m = list(map(int, input().split())) lst1, lst2 = list(zip(*list(zip(m, m)))) c1, c2 = sorted(list(Counter(lst1).items()), key=lambda x: x[1], reverse=1), sorted(list(Counter(lst2).items()), key=lambda x: x[1], reverse=1) c1.append((0, 0)), c2.append((0, 0)) if c1[0][0] != c2[0][0]: print((n - c1[0][1] - c2[0][1])) else: print((n - max(c1[1][1] + c2[0][1], c1[0][1] + c2[1][1]))) if __name__ == '__main__': main()
from collections import Counter def main(): n, *lst = list(map(int, open(0).read().split())) c1, c2 = sorted(list(Counter(lst[::2]).items()), key=lambda x: x[1], reverse=1), sorted(list(Counter(lst[1::2]).items()), key=lambda x: x[1], reverse=1) c1.append((0, 0)), c2.append((0, 0)) if c1[0][0] != c2[0][0]: print((n - c1[0][1] - c2[0][1])) else: print((n - max(c1[1][1] + c2[0][1], c1[0][1] + c2[1][1]))) if __name__ == '__main__': main()
17
15
485
455
from collections import Counter def main(): n = int(eval(input())) m = list(map(int, input().split())) lst1, lst2 = list(zip(*list(zip(m, m)))) c1, c2 = sorted(list(Counter(lst1).items()), key=lambda x: x[1], reverse=1), sorted( list(Counter(lst2).items()), key=lambda x: x[1], reverse=1 ) c1.append((0, 0)), c2.append((0, 0)) if c1[0][0] != c2[0][0]: print((n - c1[0][1] - c2[0][1])) else: print((n - max(c1[1][1] + c2[0][1], c1[0][1] + c2[1][1]))) if __name__ == "__main__": main()
from collections import Counter def main(): n, *lst = list(map(int, open(0).read().split())) c1, c2 = sorted( list(Counter(lst[::2]).items()), key=lambda x: x[1], reverse=1 ), sorted(list(Counter(lst[1::2]).items()), key=lambda x: x[1], reverse=1) c1.append((0, 0)), c2.append((0, 0)) if c1[0][0] != c2[0][0]: print((n - c1[0][1] - c2[0][1])) else: print((n - max(c1[1][1] + c2[0][1], c1[0][1] + c2[1][1]))) if __name__ == "__main__": main()
false
11.764706
[ "- n = int(eval(input()))", "- m = list(map(int, input().split()))", "- lst1, lst2 = list(zip(*list(zip(m, m))))", "- c1, c2 = sorted(list(Counter(lst1).items()), key=lambda x: x[1], reverse=1), sorted(", "- list(Counter(lst2).items()), key=lambda x: x[1], reverse=1", "- )", "+ ...
false
0.04159
0.045414
0.915791
[ "s323517549", "s454148251" ]
u775681539
p03162
python
s887354696
s343569114
1,692
301
148,168
70,236
Accepted
Accepted
82.21
#python3 def main(): n = int(eval(input())) a = [] for _ in range(n): x, y, z = list(map(int, input().split())) a.append((x, y, z)) dp = [[0 for _ in range(3)] for _ in range(10*n)] for i in range(n): for j in range(3): for k in range(3): if j == k: continue dp[i+1][j] = max(dp[i+1][j], dp[i][k] + a[i][j]) ans = max(dp[n]) print(ans) main()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): n = int(readline()) act = [] for _ in range(n): a, b, c = list(map(int, readline().split())) act.append((a, b, c)) #dp[i][j]:= 太郎くんがi日目に活動jを行って得る幸福度の総和の最大値 dp = [[0, 0, 0] for _ in range(n)] for j in range(3): dp[0][j] = act[0][j] for i in range(n-1): dp[i+1][0] = max(dp[i][1]+act[i+1][0], dp[i][2]+act[i+1][0]) dp[i+1][1] = max(dp[i][0]+act[i+1][1], dp[i][2]+act[i+1][1]) dp[i+1][2] = max(dp[i][0]+act[i+1][2], dp[i][1]+act[i+1][2]) print((max(dp[n-1]))) if __name__ == '__main__': main()
21
26
470
727
# python3 def main(): n = int(eval(input())) a = [] for _ in range(n): x, y, z = list(map(int, input().split())) a.append((x, y, z)) dp = [[0 for _ in range(3)] for _ in range(10 * n)] for i in range(n): for j in range(3): for k in range(3): if j == k: continue dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + a[i][j]) ans = max(dp[n]) print(ans) main()
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): n = int(readline()) act = [] for _ in range(n): a, b, c = list(map(int, readline().split())) act.append((a, b, c)) # dp[i][j]:= 太郎くんがi日目に活動jを行って得る幸福度の総和の最大値 dp = [[0, 0, 0] for _ in range(n)] for j in range(3): dp[0][j] = act[0][j] for i in range(n - 1): dp[i + 1][0] = max(dp[i][1] + act[i + 1][0], dp[i][2] + act[i + 1][0]) dp[i + 1][1] = max(dp[i][0] + act[i + 1][1], dp[i][2] + act[i + 1][1]) dp[i + 1][2] = max(dp[i][0] + act[i + 1][2], dp[i][1] + act[i + 1][2]) print((max(dp[n - 1]))) if __name__ == "__main__": main()
false
19.230769
[ "-# python3", "-def main():", "- n = int(eval(input()))", "- a = []", "- for _ in range(n):", "- x, y, z = list(map(int, input().split()))", "- a.append((x, y, z))", "- dp = [[0 for _ in range(3)] for _ in range(10 * n)]", "- for i in range(n):", "- for j in ran...
false
0.074415
0.102698
0.724596
[ "s887354696", "s343569114" ]
u346812984
p03069
python
s530229419
s602511243
140
96
11,144
11,368
Accepted
Accepted
31.43
N = int(eval(input())) S = eval(input()) white = [0] * (N + 1) for i in range(N): if S[i] == ".": white[i + 1] = white[i] + 1 else: white[i + 1] = white[i] ans = N for i in range(N + 1): tmp = (i - white[i]) + (white[-1] - white[i]) if tmp < ans: ans = tmp print(ans)
import sys sys.setrecursionlimit(10 ** 6) INF = float("inf") MOD = 10 ** 9 + 7 def input(): return sys.stdin.readline().strip() def main(): N = int(eval(input())) S = eval(input()) B = S.count("#") W = S.count(".") # 左からi文字目までの白の数 n_white = [] if S[0] == ".": n_white.append(1) else: n_white.append(0) for i in range(1, N): if S[i] == ".": n_white.append(n_white[-1] + 1) else: n_white.append(n_white[-1]) # ....##### の並びにする.境目に関して全探索 ans = min(B, W) for i in range(N): # 白に変える数 cnt = i + 1 - n_white[i] # 黒に変える数 cnt += n_white[-1] - n_white[i] if cnt < ans: ans = cnt print(ans) if __name__ == "__main__": main()
17
46
315
827
N = int(eval(input())) S = eval(input()) white = [0] * (N + 1) for i in range(N): if S[i] == ".": white[i + 1] = white[i] + 1 else: white[i + 1] = white[i] ans = N for i in range(N + 1): tmp = (i - white[i]) + (white[-1] - white[i]) if tmp < ans: ans = tmp print(ans)
import sys sys.setrecursionlimit(10**6) INF = float("inf") MOD = 10**9 + 7 def input(): return sys.stdin.readline().strip() def main(): N = int(eval(input())) S = eval(input()) B = S.count("#") W = S.count(".") # 左からi文字目までの白の数 n_white = [] if S[0] == ".": n_white.append(1) else: n_white.append(0) for i in range(1, N): if S[i] == ".": n_white.append(n_white[-1] + 1) else: n_white.append(n_white[-1]) # ....##### の並びにする.境目に関して全探索 ans = min(B, W) for i in range(N): # 白に変える数 cnt = i + 1 - n_white[i] # 黒に変える数 cnt += n_white[-1] - n_white[i] if cnt < ans: ans = cnt print(ans) if __name__ == "__main__": main()
false
63.043478
[ "-N = int(eval(input()))", "-S = eval(input())", "-white = [0] * (N + 1)", "-for i in range(N):", "- if S[i] == \".\":", "- white[i + 1] = white[i] + 1", "+import sys", "+", "+sys.setrecursionlimit(10**6)", "+INF = float(\"inf\")", "+MOD = 10**9 + 7", "+", "+", "+def input():", ...
false
0.092346
0.03808
2.425092
[ "s530229419", "s602511243" ]
u352394527
p00519
python
s937236210
s667052584
190
170
7,936
7,788
Accepted
Accepted
10.53
from heapq import heappop as pop from heapq import heappush as push INF = 10 ** 20 def main(): n, k = list(map(int, input().split())) clst = [] rlst = [] for i in range(n): c, r = list(map(int, input().split())) clst.append(c) rlst.append(r) edges = [[] * n for i in range(n)] for i in range(k): a, b = list(map(int, input().split())) a -= 1 b -= 1 edges[a].append(b) edges[b].append(a) costs = [INF for i in range(n)] costs[0] = 0 used = [False for i in range(n)] def make_to_lst(s_num): loop = rlst[s_num] temp = set(edges[s_num]) ret = set() while loop: new = set() for p in temp: pto = set(edges[p]) new = new | pto ret = ret | temp temp = new - ret if not temp: break loop -= 1 return ret used[0] = True costs[0] = 0 break_flag = 0 que = [(clst[0], 0)] while que and not break_flag: next_cost, s_num = pop(que) to_lst = make_to_lst(s_num) for num in to_lst: costs[num] = next_cost if num == n - 1: break_flag = 1 break if not used[num]: push(que, (costs[num] + clst[num], num)) used[num] = True print((costs[n - 1])) main()
from heapq import heappop as pop from heapq import heappush as push def main(): n, k = list(map(int, input().split())) clst = [] rlst = [] for i in range(n): c, r = list(map(int, input().split())) clst.append(c) rlst.append(r) edges = [[] * n for i in range(n)] for i in range(k): a, b = list(map(int, input().split())) a -= 1 b -= 1 edges[a].append(b) edges[b].append(a) costs = [None] * n used = [False] * n def make_to_lst(s_num): loop = rlst[s_num] temp = set(edges[s_num]) ret = set() while loop and temp: new = set() for p in temp: pto = set(edges[p]) new = new | pto ret = ret | temp temp = new - ret loop -= 1 return ret used[0] = True costs[0] = 0 que = [(clst[0], 0)] while que: next_cost, s_num = pop(que) to_lst = make_to_lst(s_num) for num in to_lst: if num == n - 1: print(next_cost) return costs[num] = next_cost if not used[num]: push(que, (next_cost + clst[num], num)) used[num] = True main()
65
61
1,309
1,170
from heapq import heappop as pop from heapq import heappush as push INF = 10**20 def main(): n, k = list(map(int, input().split())) clst = [] rlst = [] for i in range(n): c, r = list(map(int, input().split())) clst.append(c) rlst.append(r) edges = [[] * n for i in range(n)] for i in range(k): a, b = list(map(int, input().split())) a -= 1 b -= 1 edges[a].append(b) edges[b].append(a) costs = [INF for i in range(n)] costs[0] = 0 used = [False for i in range(n)] def make_to_lst(s_num): loop = rlst[s_num] temp = set(edges[s_num]) ret = set() while loop: new = set() for p in temp: pto = set(edges[p]) new = new | pto ret = ret | temp temp = new - ret if not temp: break loop -= 1 return ret used[0] = True costs[0] = 0 break_flag = 0 que = [(clst[0], 0)] while que and not break_flag: next_cost, s_num = pop(que) to_lst = make_to_lst(s_num) for num in to_lst: costs[num] = next_cost if num == n - 1: break_flag = 1 break if not used[num]: push(que, (costs[num] + clst[num], num)) used[num] = True print((costs[n - 1])) main()
from heapq import heappop as pop from heapq import heappush as push def main(): n, k = list(map(int, input().split())) clst = [] rlst = [] for i in range(n): c, r = list(map(int, input().split())) clst.append(c) rlst.append(r) edges = [[] * n for i in range(n)] for i in range(k): a, b = list(map(int, input().split())) a -= 1 b -= 1 edges[a].append(b) edges[b].append(a) costs = [None] * n used = [False] * n def make_to_lst(s_num): loop = rlst[s_num] temp = set(edges[s_num]) ret = set() while loop and temp: new = set() for p in temp: pto = set(edges[p]) new = new | pto ret = ret | temp temp = new - ret loop -= 1 return ret used[0] = True costs[0] = 0 que = [(clst[0], 0)] while que: next_cost, s_num = pop(que) to_lst = make_to_lst(s_num) for num in to_lst: if num == n - 1: print(next_cost) return costs[num] = next_cost if not used[num]: push(que, (next_cost + clst[num], num)) used[num] = True main()
false
6.153846
[ "-", "-INF = 10**20", "- costs = [INF for i in range(n)]", "- costs[0] = 0", "- used = [False for i in range(n)]", "+ costs = [None] * n", "+ used = [False] * n", "- while loop:", "+ while loop and temp:", "- if not temp:", "- break", "- ...
false
0.048396
0.049123
0.985196
[ "s937236210", "s667052584" ]
u581187895
p02629
python
s199740211
s347999497
33
27
9,180
9,136
Accepted
Accepted
18.18
def resolve(): lower = "abcdefghijklmnopqrstuvwxyz" N = int(eval(input())) ans = "" while N > 26: idx = N % 26 ans += lower[idx-1] N = -(-N//26)-1 idx = N % 26 ans += lower[idx - 1] print((ans[::-1])) if __name__ == "__main__": resolve()
def resolve(): lower = "abcdefghijklmnopqrstuvwxyz" N = int(eval(input())) ans = "" while N: N -= 1 idx = N%26 ans += lower[idx] N //= 26 print((ans[::-1])) if __name__ == "__main__": resolve()
16
15
308
259
def resolve(): lower = "abcdefghijklmnopqrstuvwxyz" N = int(eval(input())) ans = "" while N > 26: idx = N % 26 ans += lower[idx - 1] N = -(-N // 26) - 1 idx = N % 26 ans += lower[idx - 1] print((ans[::-1])) if __name__ == "__main__": resolve()
def resolve(): lower = "abcdefghijklmnopqrstuvwxyz" N = int(eval(input())) ans = "" while N: N -= 1 idx = N % 26 ans += lower[idx] N //= 26 print((ans[::-1])) if __name__ == "__main__": resolve()
false
6.25
[ "- while N > 26:", "+ while N:", "+ N -= 1", "- ans += lower[idx - 1]", "- N = -(-N // 26) - 1", "- idx = N % 26", "- ans += lower[idx - 1]", "+ ans += lower[idx]", "+ N //= 26" ]
false
0.04389
0.04503
0.974681
[ "s199740211", "s347999497" ]
u072717685
p03583
python
s370034767
s338037409
1,130
731
9,264
109,688
Accepted
Accepted
35.31
import sys read = sys.stdin.read readlines = sys.stdin.readlines def main(): N = int(eval(input())) for h in range(1, 3501): for n in range(1, 3501): shisu = h * N * n bosu = n * (h * 4 - N) - h * N if bosu >= 1: if not (shisu / bosu) % 1: print((h, n , int((h * N * n) / (n * (h * 4 - N) - h * N)))) sys.exit() if __name__ == '__main__': main()
import sys read = sys.stdin.read readlines = sys.stdin.readlines from numba import njit def main(): N = int(input()) @njit def solve(N): for h in range(1, 3501): for n in range(1, 3501): shisu = h * N * n bosu = n * (h * 4 - N) - h * N if bosu >= 1: if not (shisu / bosu) % 1: return h, n , int((h * N * n) / (n * (h * 4 - N) - h * N)) r = solve(N) print(*r , sep=' ') if __name__ == '__main__': main()
17
21
467
561
import sys read = sys.stdin.read readlines = sys.stdin.readlines def main(): N = int(eval(input())) for h in range(1, 3501): for n in range(1, 3501): shisu = h * N * n bosu = n * (h * 4 - N) - h * N if bosu >= 1: if not (shisu / bosu) % 1: print((h, n, int((h * N * n) / (n * (h * 4 - N) - h * N)))) sys.exit() if __name__ == "__main__": main()
import sys read = sys.stdin.read readlines = sys.stdin.readlines from numba import njit def main(): N = int(input()) @njit def solve(N): for h in range(1, 3501): for n in range(1, 3501): shisu = h * N * n bosu = n * (h * 4 - N) - h * N if bosu >= 1: if not (shisu / bosu) % 1: return h, n, int((h * N * n) / (n * (h * 4 - N) - h * N)) r = solve(N) print(*r, sep=" ") if __name__ == "__main__": main()
false
19.047619
[ "+from numba import njit", "- N = int(eval(input()))", "- for h in range(1, 3501):", "- for n in range(1, 3501):", "- shisu = h * N * n", "- bosu = n * (h * 4 - N) - h * N", "- if bosu >= 1:", "- if not (shisu / bosu) % 1:", "- ...
false
0.47914
0.044094
10.866372
[ "s370034767", "s338037409" ]
u017723605
p03545
python
s108642115
s960547368
24
18
3,188
3,064
Accepted
Accepted
25
#!/usr/bin/env python3 import sys def solve(ABCD: str): num_str = ABCD N = len(num_str) - 1 for bit in range(2 ** N): tmp = num_str[0] for i in range(N): if bit & 1 << i: tmp += "+" else: tmp += "-" tmp += num_str[i + 1] res = eval(tmp) if res == 7: print((tmp + "=7")) return return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() ABCD = next(tokens) solve(ABCD) if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys def solve(num_str: str): N = len(num_str) - 1 for bit in range(2 ** N): ans = num_str[0] for i in range(N): if bit & 1 << i: ans += "+" else: ans += "-" ans += num_str[i + 1] if eval(ans) == 7: print((ans + "=7")) return return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() ABCD = next(tokens) solve(ABCD) if __name__ == '__main__': main()
37
35
874
838
#!/usr/bin/env python3 import sys def solve(ABCD: str): num_str = ABCD N = len(num_str) - 1 for bit in range(2**N): tmp = num_str[0] for i in range(N): if bit & 1 << i: tmp += "+" else: tmp += "-" tmp += num_str[i + 1] res = eval(tmp) if res == 7: print((tmp + "=7")) return return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() ABCD = next(tokens) solve(ABCD) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys def solve(num_str: str): N = len(num_str) - 1 for bit in range(2**N): ans = num_str[0] for i in range(N): if bit & 1 << i: ans += "+" else: ans += "-" ans += num_str[i + 1] if eval(ans) == 7: print((ans + "=7")) return return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() ABCD = next(tokens) solve(ABCD) if __name__ == "__main__": main()
false
5.405405
[ "-def solve(ABCD: str):", "- num_str = ABCD", "+def solve(num_str: str):", "- tmp = num_str[0]", "+ ans = num_str[0]", "- tmp += \"+\"", "+ ans += \"+\"", "- tmp += \"-\"", "- tmp += num_str[i + 1]", "- res = eval(tmp)...
false
0.041195
0.041863
0.984022
[ "s108642115", "s960547368" ]
u358254559
p03069
python
s781834017
s958802554
186
101
12,820
3,500
Accepted
Accepted
45.7
n = int(eval(input())) s = eval(input()) b_lst=[] w_lst=[] b_cnt=0 w_cnt=0 for i in range(len(s)): b_lst.append(b_cnt) w_lst.append(w_cnt) if s[i]=="#": b_cnt+=1 if s[len(s)-i-1]==".": w_cnt+=1 b_lst.append(b_cnt) w_lst.append(w_cnt) w_lst.reverse() ans=10**9 for b,w in zip(b_lst,w_lst): if ans > b+w: ans=b+w print(ans)
n = int(eval(input())) s = eval(input()) ans=0 for stone in s: if stone==".": ans+=1 ans_mn=ans for i in range(len(s)): if s[i]=="#": ans+=1 if s[i]==".": ans-=1 if ans < ans_mn: ans_mn=ans print(ans_mn)
22
15
375
253
n = int(eval(input())) s = eval(input()) b_lst = [] w_lst = [] b_cnt = 0 w_cnt = 0 for i in range(len(s)): b_lst.append(b_cnt) w_lst.append(w_cnt) if s[i] == "#": b_cnt += 1 if s[len(s) - i - 1] == ".": w_cnt += 1 b_lst.append(b_cnt) w_lst.append(w_cnt) w_lst.reverse() ans = 10**9 for b, w in zip(b_lst, w_lst): if ans > b + w: ans = b + w print(ans)
n = int(eval(input())) s = eval(input()) ans = 0 for stone in s: if stone == ".": ans += 1 ans_mn = ans for i in range(len(s)): if s[i] == "#": ans += 1 if s[i] == ".": ans -= 1 if ans < ans_mn: ans_mn = ans print(ans_mn)
false
31.818182
[ "-b_lst = []", "-w_lst = []", "-b_cnt = 0", "-w_cnt = 0", "+ans = 0", "+for stone in s:", "+ if stone == \".\":", "+ ans += 1", "+ans_mn = ans", "- b_lst.append(b_cnt)", "- w_lst.append(w_cnt)", "- b_cnt += 1", "- if s[len(s) - i - 1] == \".\":", "- w_cnt +...
false
0.032573
0.041316
0.788387
[ "s781834017", "s958802554" ]
u254871849
p03111
python
s213299691
s996353979
363
63
26,556
3,064
Accepted
Accepted
82.64
import sys from functools import lru_cache inf = float('inf') n, A, B, C, *l = list(map(int, sys.stdin.read().split())) @lru_cache(None) def cost(a, b, c, cnt, i): if i == n: if not (a and b and c): return inf return abs(A - a) + abs(B - b) + abs(C - c) + 10 * (cnt - 3) return min(cost(a, b, c, cnt, i+1), cost(a+l[i], b, c, cnt+1, i+1), cost(a, b+l[i], c, cnt+1, i+1), cost(a, b, c+l[i], cnt+1, i+1)) def main(): print((cost(0, 0, 0, 0, 0))) if __name__ == '__main__': main()
import sys inf = float('inf') n, A, B, C, *l = list(map(int, sys.stdin.read().split())) def cost(a, b, c, cnt, i): if i == n: if not (a and b and c): return inf return abs(A - a) + abs(B - b) + abs(C - c) + 10 * (cnt - 3) return min(cost(a, b, c, cnt, i+1), cost(a+l[i], b, c, cnt+1, i+1), cost(a, b+l[i], c, cnt+1, i+1), cost(a, b, c+l[i], cnt+1, i+1)) def main(): print((cost(0, 0, 0, 0, 0))) if __name__ == '__main__': main()
21
19
572
521
import sys from functools import lru_cache inf = float("inf") n, A, B, C, *l = list(map(int, sys.stdin.read().split())) @lru_cache(None) def cost(a, b, c, cnt, i): if i == n: if not (a and b and c): return inf return abs(A - a) + abs(B - b) + abs(C - c) + 10 * (cnt - 3) return min( cost(a, b, c, cnt, i + 1), cost(a + l[i], b, c, cnt + 1, i + 1), cost(a, b + l[i], c, cnt + 1, i + 1), cost(a, b, c + l[i], cnt + 1, i + 1), ) def main(): print((cost(0, 0, 0, 0, 0))) if __name__ == "__main__": main()
import sys inf = float("inf") n, A, B, C, *l = list(map(int, sys.stdin.read().split())) def cost(a, b, c, cnt, i): if i == n: if not (a and b and c): return inf return abs(A - a) + abs(B - b) + abs(C - c) + 10 * (cnt - 3) return min( cost(a, b, c, cnt, i + 1), cost(a + l[i], b, c, cnt + 1, i + 1), cost(a, b + l[i], c, cnt + 1, i + 1), cost(a, b, c + l[i], cnt + 1, i + 1), ) def main(): print((cost(0, 0, 0, 0, 0))) if __name__ == "__main__": main()
false
9.52381
[ "-from functools import lru_cache", "-@lru_cache(None)" ]
false
0.25194
0.11675
2.157941
[ "s213299691", "s996353979" ]
u480200603
p02971
python
s508133796
s719237190
871
320
68,952
12,512
Accepted
Accepted
63.26
n = int(eval(input())) l = [] m1 = 0 m2 = 0 for i in range(n): num = int(eval(input())) l.append(num) if num > m1: m1 = num elif num > m2: m2 = num for i in range(n): if l[i] != m1: print(m1) else: print(m2)
import sys input = sys.stdin.readline n = int(eval(input())) l = [] m1 = 0 m2 = 0 for i in range(n): num = int(eval(input())) l.append(num) if num > m1: m1 = num elif num > m2: m2 = num for i in range(n): if l[i] != m1: print(m1) else: print(m2)
17
20
269
311
n = int(eval(input())) l = [] m1 = 0 m2 = 0 for i in range(n): num = int(eval(input())) l.append(num) if num > m1: m1 = num elif num > m2: m2 = num for i in range(n): if l[i] != m1: print(m1) else: print(m2)
import sys input = sys.stdin.readline n = int(eval(input())) l = [] m1 = 0 m2 = 0 for i in range(n): num = int(eval(input())) l.append(num) if num > m1: m1 = num elif num > m2: m2 = num for i in range(n): if l[i] != m1: print(m1) else: print(m2)
false
15
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.075843
0.125429
0.60467
[ "s508133796", "s719237190" ]