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
u781262926
p03713
python
s514086411
s513234730
466
20
3,064
3,064
Accepted
Accepted
95.71
h, w = list(map(int, input().split())) if h % 3 == 0 or w % 3 == 0: print((0)) else: if h > w: h, w = w, h ans = h for w1 in range(w//3-2, w//3+3): s1 = w1 * h w2 = w-w1 for h1 in range(h//2 + 1): s2 = w2 * h1 s3 = w2 * (h-h1) ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3)) h, w = w, h for w1 in range(w//3-2, w//3+3): s1 = w1 * h w2 = w-w1 for h1 in range(h//2 + 1): s2 = w2 * h1 s3 = w2 * (h-h1) ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3)) print(ans)
h, w = list(map(int, input().split())) if h % 3 == 0 or w % 3 == 0: print((0)) else: ans = min(w, h) for w1 in range(w//3, w//3+3): s1 = w1 * h w2 = w-w1 for h1 in range(h//2, h//2+2): s2 = w2 * h1 s3 = w2 * (h-h1) ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3)) h, w = w, h for w1 in range(w//3, w//3+3): s1 = w1 * h w2 = w-w1 for h1 in range(h//2, h//2+2): s2 = w2 * h1 s3 = w2 * (h-h1) ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3)) print(ans)
23
21
631
607
h, w = list(map(int, input().split())) if h % 3 == 0 or w % 3 == 0: print((0)) else: if h > w: h, w = w, h ans = h for w1 in range(w // 3 - 2, w // 3 + 3): s1 = w1 * h w2 = w - w1 for h1 in range(h // 2 + 1): s2 = w2 * h1 s3 = w2 * (h - h1) ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3)) h, w = w, h for w1 in range(w // 3 - 2, w // 3 + 3): s1 = w1 * h w2 = w - w1 for h1 in range(h // 2 + 1): s2 = w2 * h1 s3 = w2 * (h - h1) ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3)) print(ans)
h, w = list(map(int, input().split())) if h % 3 == 0 or w % 3 == 0: print((0)) else: ans = min(w, h) for w1 in range(w // 3, w // 3 + 3): s1 = w1 * h w2 = w - w1 for h1 in range(h // 2, h // 2 + 2): s2 = w2 * h1 s3 = w2 * (h - h1) ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3)) h, w = w, h for w1 in range(w // 3, w // 3 + 3): s1 = w1 * h w2 = w - w1 for h1 in range(h // 2, h // 2 + 2): s2 = w2 * h1 s3 = w2 * (h - h1) ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3)) print(ans)
false
8.695652
[ "- if h > w:", "- h, w = w, h", "- ans = h", "- for w1 in range(w // 3 - 2, w // 3 + 3):", "+ ans = min(w, h)", "+ for w1 in range(w // 3, w // 3 + 3):", "- for h1 in range(h // 2 + 1):", "+ for h1 in range(h // 2, h // 2 + 2):", "- for w1 in range(w // 3 - 2, w // 3 + 3):", "+ for w1 in range(w // 3, w // 3 + 3):", "- for h1 in range(h // 2 + 1):", "+ for h1 in range(h // 2, h // 2 + 2):" ]
false
0.593747
0.036567
16.237228
[ "s514086411", "s513234730" ]
u062147869
p03721
python
s078520478
s522512732
499
442
24,320
20,104
Accepted
Accepted
11.42
from bisect import bisect_left,bisect_right N,K=list(map(int,input().split())) table=[] for i in range(N): a,b=list(map(int,input().split())) table.append([a,b]) table.sort() cou=[0]*N cou[0]=table[0][1] for i in range(1,N): cou[i]=cou[i-1]+table[i][1] s = bisect_left(cou,K) print((table[s][0]))
N,K=list(map(int,input().split())) table=[] for i in range(N): a,b=list(map(int,input().split())) table.append([a,b]) table.sort() ans = 0 for x,y in table: ans += y if ans >=K: print(x) break
13
12
306
223
from bisect import bisect_left, bisect_right N, K = list(map(int, input().split())) table = [] for i in range(N): a, b = list(map(int, input().split())) table.append([a, b]) table.sort() cou = [0] * N cou[0] = table[0][1] for i in range(1, N): cou[i] = cou[i - 1] + table[i][1] s = bisect_left(cou, K) print((table[s][0]))
N, K = list(map(int, input().split())) table = [] for i in range(N): a, b = list(map(int, input().split())) table.append([a, b]) table.sort() ans = 0 for x, y in table: ans += y if ans >= K: print(x) break
false
7.692308
[ "-from bisect import bisect_left, bisect_right", "-", "-cou = [0] * N", "-cou[0] = table[0][1]", "-for i in range(1, N):", "- cou[i] = cou[i - 1] + table[i][1]", "-s = bisect_left(cou, K)", "-print((table[s][0]))", "+ans = 0", "+for x, y in table:", "+ ans += y", "+ if ans >= K:", "+ print(x)", "+ break" ]
false
0.037223
0.038742
0.960786
[ "s078520478", "s522512732" ]
u145410317
p03457
python
s658619013
s662891634
438
362
27,380
3,064
Accepted
Accepted
17.35
num = int(eval(input())) travels = [] for _ in range(num): travels.append(list(map(int, input().split()))) beforTime = 0 beforX = 0 beforY = 0 resultFrag = True for travel in travels: move = abs(beforX - travel[1]) + abs(beforY - travel[2]) canMoveTime = travel[0] - beforTime if move <= canMoveTime and (move + canMoveTime) % 2 == 0: beforTime = travel[0] beforX = travel[1] beforY = travel[2] continue resultFrag = False break print(("Yes" if resultFrag else "No"))
num = int(eval(input())) beforTime = 0 beforX = 0 beforY = 0 resultFrag = True for travel in range(num): time, x, y = list(map(int, input().split())) move = abs(beforX - x) + abs(beforY - y) canMoveTime = time - beforTime if move <= canMoveTime and (move + canMoveTime) % 2 == 0: beforTime = time beforX = x beforY = y continue resultFrag = False break print(("Yes" if resultFrag else "No"))
23
20
542
456
num = int(eval(input())) travels = [] for _ in range(num): travels.append(list(map(int, input().split()))) beforTime = 0 beforX = 0 beforY = 0 resultFrag = True for travel in travels: move = abs(beforX - travel[1]) + abs(beforY - travel[2]) canMoveTime = travel[0] - beforTime if move <= canMoveTime and (move + canMoveTime) % 2 == 0: beforTime = travel[0] beforX = travel[1] beforY = travel[2] continue resultFrag = False break print(("Yes" if resultFrag else "No"))
num = int(eval(input())) beforTime = 0 beforX = 0 beforY = 0 resultFrag = True for travel in range(num): time, x, y = list(map(int, input().split())) move = abs(beforX - x) + abs(beforY - y) canMoveTime = time - beforTime if move <= canMoveTime and (move + canMoveTime) % 2 == 0: beforTime = time beforX = x beforY = y continue resultFrag = False break print(("Yes" if resultFrag else "No"))
false
13.043478
[ "-travels = []", "-for _ in range(num):", "- travels.append(list(map(int, input().split())))", "-for travel in travels:", "- move = abs(beforX - travel[1]) + abs(beforY - travel[2])", "- canMoveTime = travel[0] - beforTime", "+for travel in range(num):", "+ time, x, y = list(map(int, input().split()))", "+ move = abs(beforX - x) + abs(beforY - y)", "+ canMoveTime = time - beforTime", "- beforTime = travel[0]", "- beforX = travel[1]", "- beforY = travel[2]", "+ beforTime = time", "+ beforX = x", "+ beforY = y" ]
false
0.041022
0.043123
0.951282
[ "s658619013", "s662891634" ]
u836311327
p02536
python
s375613383
s485120147
843
211
87,140
13,268
Accepted
Accepted
74.97
#!/usr/bin/env python3 from networkx.utils import UnionFind import sys def input(): return sys.stdin.readline().rstrip() def main(): n,m=list(map(int, input().split())) uf = UnionFind() for i in range(1,n+1): _=uf[i] for _ in range(m): a,b=list(map(int, input().split())) uf.union(a, b) # aとbをマージ print((len(list(uf.to_sets()))-1)) #for group in uf.to_sets(): # すべてのグループのリストを返す #print(group) if __name__ == '__main__': main()
import sys def input(): return sys.stdin.readline().rstrip() from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): self.all_group_member=defaultdict(list) for i in range(self.n): self.all_group_member[self.find(i)].append(i) return self.all_group_member def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) def main(): n,m=list(map(int, input().split())) uf = UnionFind(n+1) for _ in range(m): a,b=list(map(int, input().split())) uf.union(a, b) # aとbをマージ print((uf.group_count()-2)) #for group in uf.to_sets(): # すべてのグループのリストを返す #print(group) if __name__ == '__main__': main()
21
66
498
1,736
#!/usr/bin/env python3 from networkx.utils import UnionFind import sys def input(): return sys.stdin.readline().rstrip() def main(): n, m = list(map(int, input().split())) uf = UnionFind() for i in range(1, n + 1): _ = uf[i] for _ in range(m): a, b = list(map(int, input().split())) uf.union(a, b) # aとbをマージ print((len(list(uf.to_sets())) - 1)) # for group in uf.to_sets(): # すべてのグループのリストを返す # print(group) if __name__ == "__main__": main()
import sys def input(): return sys.stdin.readline().rstrip() from collections import defaultdict class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): self.all_group_member = defaultdict(list) for i in range(self.n): self.all_group_member[self.find(i)].append(i) return self.all_group_member def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) def main(): n, m = list(map(int, input().split())) uf = UnionFind(n + 1) for _ in range(m): a, b = list(map(int, input().split())) uf.union(a, b) # aとbをマージ print((uf.group_count() - 2)) # for group in uf.to_sets(): # すべてのグループのリストを返す # print(group) if __name__ == "__main__": main()
false
68.181818
[ "-#!/usr/bin/env python3", "-from networkx.utils import UnionFind", "+from collections import defaultdict", "+", "+", "+class UnionFind:", "+ def __init__(self, n):", "+ self.n = n", "+ self.parents = [-1] * n", "+", "+ def find(self, x):", "+ if self.parents[x] < 0:", "+ return x", "+ else:", "+ self.parents[x] = self.find(self.parents[x])", "+ return self.parents[x]", "+", "+ def union(self, x, y):", "+ x = self.find(x)", "+ y = self.find(y)", "+ if x == y:", "+ return", "+ if self.parents[x] > self.parents[y]:", "+ x, y = y, x", "+ self.parents[x] += self.parents[y]", "+ self.parents[y] = x", "+", "+ def size(self, x):", "+ return -self.parents[self.find(x)]", "+", "+ def same(self, x, y):", "+ return self.find(x) == self.find(y)", "+", "+ def members(self, x):", "+ root = self.find(x)", "+ return [i for i in range(self.n) if self.find(i) == root]", "+", "+ def roots(self):", "+ return [i for i, x in enumerate(self.parents) if x < 0]", "+", "+ def group_count(self):", "+ return len(self.roots())", "+", "+ def all_group_members(self):", "+ self.all_group_member = defaultdict(list)", "+ for i in range(self.n):", "+ self.all_group_member[self.find(i)].append(i)", "+ return self.all_group_member", "+", "+ def __str__(self):", "+ return \"\\n\".join(\"{}: {}\".format(r, self.members(r)) for r in self.roots())", "+", "+", "- uf = UnionFind()", "- for i in range(1, n + 1):", "- _ = uf[i]", "+ uf = UnionFind(n + 1)", "- print((len(list(uf.to_sets())) - 1))", "+ print((uf.group_count() - 2))" ]
false
0.06731
0.040293
1.670504
[ "s375613383", "s485120147" ]
u595952233
p02579
python
s827148705
s519781181
1,966
880
164,476
132,520
Accepted
Accepted
55.24
from collections import deque """ ダイクストラ ギリギリ """ h, w = list(map(int, input().split())) ch, cw = list(map(int, input().split())) dh, dw = list(map(int, input().split())) ch-=1; cw-=1; dh-=1; dw-=1 area = [list(eval(input())) for _ in range(h)] inf = 10**100 dist = [[inf]*w for i in range(h)] dwalk = [(0, 1), (0, -1), (1, 0), (-1, 0)] def Dijkstra(ch, cw): import heapq edgelist = [(0, ch, cw)] heapq.heapify(edgelist) dist[ch][cw] = 0 while len(edgelist): cost, y, x = heapq.heappop(edgelist) if y==dh and x==dw: return dist # この枝刈がないと通らない if dist[y][x] < cost: continue for next_y, next_x in dwalk: if 0<=y+next_y<h and 0<=x+next_x<w: if area[y+next_y][x+next_x]=='#': continue if dist[y+next_y][x+next_x]>cost: dist[y+next_y][x+next_x] = cost heapq.heappush(edgelist, (cost, y+next_y, x+next_x)) for next_y in range(-2, 3): for next_x in range(-2, 3): if 0<=y+next_y<h and 0<=x+next_x<w: if area[y+next_y][x+next_x]=='#': continue if dist[y+next_y][x+next_x]>cost+1: dist[y+next_y][x+next_x] = cost+1 heapq.heappush(edgelist, (cost+1, y+next_y, x+next_x)) return dist dist = Dijkstra(ch, cw) if dist[dh][dw] == inf: print((-1)) else: print((dist[dh][dw]))
from collections import deque h, w = list(map(int, input().split())) ch, cw = list(map(int, input().split())) dh, dw = list(map(int, input().split())) ch-=1; cw-=1; dh-=1; dw-=1 area = [list(eval(input())) for _ in range(h)] inf = 10**100 dist = [[inf]*w for i in range(h)] dwalk = [(0, 1), (0, -1), (1, 0), (-1, 0)] q = deque([(ch, cw)]) dist[ch][cw] = 0 while q: y, x = q.popleft() for dy, dx in dwalk: py = y+dy; px = x+dx if not 0<=py<h: continue if not 0<=px<w: continue if area[py][px]=='#': continue if dist[py][px]>dist[y][x]: dist[py][px] = dist[y][x] q.appendleft((py, px)) for dy in range(-2, 3): for dx in range(-2, 3): py = y+dy; px = x+dx if not 0<=py<h: continue if not 0<=px<w: continue if area[py][px]=='#': continue if dist[py][px]>dist[y][x]+1: dist[py][px] = dist[y][x]+1 q.append((py, px)) if dist[dh][dw] == inf: print((-1)) else: print((dist[dh][dw]))
46
37
1,493
1,069
from collections import deque """ ダイクストラ ギリギリ """ h, w = list(map(int, input().split())) ch, cw = list(map(int, input().split())) dh, dw = list(map(int, input().split())) ch -= 1 cw -= 1 dh -= 1 dw -= 1 area = [list(eval(input())) for _ in range(h)] inf = 10**100 dist = [[inf] * w for i in range(h)] dwalk = [(0, 1), (0, -1), (1, 0), (-1, 0)] def Dijkstra(ch, cw): import heapq edgelist = [(0, ch, cw)] heapq.heapify(edgelist) dist[ch][cw] = 0 while len(edgelist): cost, y, x = heapq.heappop(edgelist) if y == dh and x == dw: return dist # この枝刈がないと通らない if dist[y][x] < cost: continue for next_y, next_x in dwalk: if 0 <= y + next_y < h and 0 <= x + next_x < w: if area[y + next_y][x + next_x] == "#": continue if dist[y + next_y][x + next_x] > cost: dist[y + next_y][x + next_x] = cost heapq.heappush(edgelist, (cost, y + next_y, x + next_x)) for next_y in range(-2, 3): for next_x in range(-2, 3): if 0 <= y + next_y < h and 0 <= x + next_x < w: if area[y + next_y][x + next_x] == "#": continue if dist[y + next_y][x + next_x] > cost + 1: dist[y + next_y][x + next_x] = cost + 1 heapq.heappush(edgelist, (cost + 1, y + next_y, x + next_x)) return dist dist = Dijkstra(ch, cw) if dist[dh][dw] == inf: print((-1)) else: print((dist[dh][dw]))
from collections import deque h, w = list(map(int, input().split())) ch, cw = list(map(int, input().split())) dh, dw = list(map(int, input().split())) ch -= 1 cw -= 1 dh -= 1 dw -= 1 area = [list(eval(input())) for _ in range(h)] inf = 10**100 dist = [[inf] * w for i in range(h)] dwalk = [(0, 1), (0, -1), (1, 0), (-1, 0)] q = deque([(ch, cw)]) dist[ch][cw] = 0 while q: y, x = q.popleft() for dy, dx in dwalk: py = y + dy px = x + dx if not 0 <= py < h: continue if not 0 <= px < w: continue if area[py][px] == "#": continue if dist[py][px] > dist[y][x]: dist[py][px] = dist[y][x] q.appendleft((py, px)) for dy in range(-2, 3): for dx in range(-2, 3): py = y + dy px = x + dx if not 0 <= py < h: continue if not 0 <= px < w: continue if area[py][px] == "#": continue if dist[py][px] > dist[y][x] + 1: dist[py][px] = dist[y][x] + 1 q.append((py, px)) if dist[dh][dw] == inf: print((-1)) else: print((dist[dh][dw]))
false
19.565217
[ "-\"\"\"", "-ダイクストラ ギリギリ", "-\"\"\"", "-", "-", "-def Dijkstra(ch, cw):", "- import heapq", "-", "- edgelist = [(0, ch, cw)]", "- heapq.heapify(edgelist)", "- dist[ch][cw] = 0", "- while len(edgelist):", "- cost, y, x = heapq.heappop(edgelist)", "- if y == dh and x == dw:", "- return dist", "- # この枝刈がないと通らない", "- if dist[y][x] < cost:", "+q = deque([(ch, cw)])", "+dist[ch][cw] = 0", "+while q:", "+ y, x = q.popleft()", "+ for dy, dx in dwalk:", "+ py = y + dy", "+ px = x + dx", "+ if not 0 <= py < h:", "- for next_y, next_x in dwalk:", "- if 0 <= y + next_y < h and 0 <= x + next_x < w:", "- if area[y + next_y][x + next_x] == \"#\":", "- continue", "- if dist[y + next_y][x + next_x] > cost:", "- dist[y + next_y][x + next_x] = cost", "- heapq.heappush(edgelist, (cost, y + next_y, x + next_x))", "- for next_y in range(-2, 3):", "- for next_x in range(-2, 3):", "- if 0 <= y + next_y < h and 0 <= x + next_x < w:", "- if area[y + next_y][x + next_x] == \"#\":", "- continue", "- if dist[y + next_y][x + next_x] > cost + 1:", "- dist[y + next_y][x + next_x] = cost + 1", "- heapq.heappush(edgelist, (cost + 1, y + next_y, x + next_x))", "- return dist", "-", "-", "-dist = Dijkstra(ch, cw)", "+ if not 0 <= px < w:", "+ continue", "+ if area[py][px] == \"#\":", "+ continue", "+ if dist[py][px] > dist[y][x]:", "+ dist[py][px] = dist[y][x]", "+ q.appendleft((py, px))", "+ for dy in range(-2, 3):", "+ for dx in range(-2, 3):", "+ py = y + dy", "+ px = x + dx", "+ if not 0 <= py < h:", "+ continue", "+ if not 0 <= px < w:", "+ continue", "+ if area[py][px] == \"#\":", "+ continue", "+ if dist[py][px] > dist[y][x] + 1:", "+ dist[py][px] = dist[y][x] + 1", "+ q.append((py, px))" ]
false
0.043031
0.043136
0.99757
[ "s827148705", "s519781181" ]
u285891772
p02900
python
s858688470
s651293025
267
132
5,204
5,320
Accepted
Accepted
50.56
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 def is_prime(num): if num < 2: return False if num in [2, 3, 5]: return True if any(num%x == 0 for x in [2, 3, 5]): return False prime = 7 step = 4 while prime <= sqrt(num): if num%prime == 0: return False prime += step step = 6-step return True A, B = MAP() C = gcd(A, B) ans = 1 for i in range(1, int(sqrt(C))+1): if C%i == 0: ans += is_prime(i) + is_prime(C//i) 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 def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i == 0: cnt = 0 while temp%i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr A, B = MAP() N = gcd(A, B) print((len(factorization(N))+1 if N != 1 else 1))
49
40
1,289
1,221
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 def is_prime(num): if num < 2: return False if num in [2, 3, 5]: return True if any(num % x == 0 for x in [2, 3, 5]): return False prime = 7 step = 4 while prime <= sqrt(num): if num % prime == 0: return False prime += step step = 6 - step return True A, B = MAP() C = gcd(A, B) ans = 1 for i in range(1, int(sqrt(C)) + 1): if C % i == 0: ans += is_prime(i) + is_prime(C // i) 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 def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr A, B = MAP() N = gcd(A, B) print((len(factorization(N)) + 1 if N != 1 else 1))
false
18.367347
[ "-def is_prime(num):", "- if num < 2:", "- return False", "- if num in [2, 3, 5]:", "- return True", "- if any(num % x == 0 for x in [2, 3, 5]):", "- return False", "- prime = 7", "- step = 4", "- while prime <= sqrt(num):", "- if num % prime == 0:", "- return False", "- prime += step", "- step = 6 - step", "- return True", "+def factorization(n):", "+ arr = []", "+ temp = n", "+ for i in range(2, int(-(-(n**0.5) // 1)) + 1):", "+ if temp % i == 0:", "+ cnt = 0", "+ while temp % i == 0:", "+ cnt += 1", "+ temp //= i", "+ arr.append([i, cnt])", "+ if temp != 1:", "+ arr.append([temp, 1])", "+ if arr == []:", "+ arr.append([n, 1])", "+ return arr", "-C = gcd(A, B)", "-ans = 1", "-for i in range(1, int(sqrt(C)) + 1):", "- if C % i == 0:", "- ans += is_prime(i) + is_prime(C // i)", "-print(ans)", "+N = gcd(A, B)", "+print((len(factorization(N)) + 1 if N != 1 else 1))" ]
false
0.062061
0.060283
1.029491
[ "s858688470", "s651293025" ]
u083960235
p03805
python
s922031207
s299711745
52
45
6,376
4,980
Accepted
Accepted
13.46
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N, M = MAP() L = [LIST() for i in range(M)] graph = defaultdict(list) # E = defaultdict(list) rinsetsu = [[0] * N for i in range(N)] for a, b in L: graph[a-1].append(b-1) graph[b-1].append(a-1) rinsetsu[a-1][b-1] = 1 rinsetsu[b-1][a-1] = 1 per = list(permutations([n for n in range(1, N)])) # print(permu) permu = [] for p_list in per: p_list = [0] + list(p_list) permu.append(p_list) ans = 0 for p in permu: for i in range(N-1): # print(p[i], p[i+1]) if rinsetsu[p[i]][p[i+1]] != 1: break else: ans += 1 print(ans)
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from heapq import heapify, heappop, heappush def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 N, M = MAP() L = [LIST() for i in range(M)] graph = defaultdict(list) rinsetsu = [[0] * N for i in range(N)] for a, b in L: graph[a-1].append(b-1) graph[b-1].append(a-1) rinsetsu[a-1][b-1] = 1 rinsetsu[b-1][a-1] = 1 per = list(permutations([n for n in range(1, N)])) permu = [] for p in per: p = [0] + list(p) permu.append(p) ans = 0 for p in permu: cnt = 0 for i in range(N-1): a, b = p[i], p[i+1] if rinsetsu[a][b] == 1: cnt += 1 if cnt == N - 1: ans += 1 print(ans)
51
49
1,350
1,326
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N, M = MAP() L = [LIST() for i in range(M)] graph = defaultdict(list) # E = defaultdict(list) rinsetsu = [[0] * N for i in range(N)] for a, b in L: graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) rinsetsu[a - 1][b - 1] = 1 rinsetsu[b - 1][a - 1] = 1 per = list(permutations([n for n in range(1, N)])) # print(permu) permu = [] for p_list in per: p_list = [0] + list(p_list) permu.append(p_list) ans = 0 for p in permu: for i in range(N - 1): # print(p[i], p[i+1]) if rinsetsu[p[i]][p[i + 1]] != 1: break else: ans += 1 print(ans)
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from heapq import heapify, heappop, heappush def input(): return sys.stdin.readline().strip() def INT(): return int(eval(input())) def MAP(): return list(map(int, input().split())) def S_MAP(): return list(map(str, input().split())) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 N, M = MAP() L = [LIST() for i in range(M)] graph = defaultdict(list) rinsetsu = [[0] * N for i in range(N)] for a, b in L: graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) rinsetsu[a - 1][b - 1] = 1 rinsetsu[b - 1][a - 1] = 1 per = list(permutations([n for n in range(1, N)])) permu = [] for p in per: p = [0] + list(p) permu.append(p) ans = 0 for p in permu: cnt = 0 for i in range(N - 1): a, b = p[i], p[i + 1] if rinsetsu[a][b] == 1: cnt += 1 if cnt == N - 1: ans += 1 print(ans)
false
3.921569
[ "-from fractions import gcd", "+from heapq import heapify, heappop, heappush", "-# E = defaultdict(list)", "-# print(permu)", "-for p_list in per:", "- p_list = [0] + list(p_list)", "- permu.append(p_list)", "+for p in per:", "+ p = [0] + list(p)", "+ permu.append(p)", "+ cnt = 0", "- # print(p[i], p[i+1])", "- if rinsetsu[p[i]][p[i + 1]] != 1:", "- break", "- else:", "+ a, b = p[i], p[i + 1]", "+ if rinsetsu[a][b] == 1:", "+ cnt += 1", "+ if cnt == N - 1:" ]
false
0.045495
0.052904
0.859951
[ "s922031207", "s299711745" ]
u596536048
p03378
python
s794270614
s946479086
28
25
9,172
9,096
Accepted
Accepted
10.71
total_square, total_toll_gate, current_square = list(map(int, input().split())) toll_gate_square = list(map(int, input().split())) route1 = 0 route2 = 0 for i in range(total_toll_gate): if toll_gate_square[i] < current_square: route1 += 1 else: route2 += 1 print((min(route1, route2)))
N, M, X = list(map(int, input().split())) A = sum(int(i) < X for i in input().split()) print((min(A, M - A)))
10
3
310
103
total_square, total_toll_gate, current_square = list(map(int, input().split())) toll_gate_square = list(map(int, input().split())) route1 = 0 route2 = 0 for i in range(total_toll_gate): if toll_gate_square[i] < current_square: route1 += 1 else: route2 += 1 print((min(route1, route2)))
N, M, X = list(map(int, input().split())) A = sum(int(i) < X for i in input().split()) print((min(A, M - A)))
false
70
[ "-total_square, total_toll_gate, current_square = list(map(int, input().split()))", "-toll_gate_square = list(map(int, input().split()))", "-route1 = 0", "-route2 = 0", "-for i in range(total_toll_gate):", "- if toll_gate_square[i] < current_square:", "- route1 += 1", "- else:", "- route2 += 1", "-print((min(route1, route2)))", "+N, M, X = list(map(int, input().split()))", "+A = sum(int(i) < X for i in input().split())", "+print((min(A, M - A)))" ]
false
0.043363
0.038333
1.131217
[ "s794270614", "s946479086" ]
u979667682
p03014
python
s919480132
s990353049
1,893
1,089
311,664
187,632
Accepted
Accepted
42.47
from sys import stdin import math import fractions from collections import deque import itertools INF = 10 ** 10 # H <= 2000, W <= 2000 # H*W -> O(4*10^6) H, W = [int(x) for x in stdin.readline().rstrip().split()] S = [[x for x in stdin.readline().rstrip()] for _ in range(H)] # L[i][j]: i行目j列目に明かりを置いたときにそこから左方向に照らされるマスの個数 # (i行目j列目のマスを含む) L = [[0] * W for _ in range(H)] R = [[0] * W for _ in range(H)] D = [[0] * W for _ in range(H)] U = [[0] * W for _ in range(H)] # L for i in range(H): for j in range(W): if S[i][j] == "#": L[i][j] = 0 continue if j == 0: L[i][j] = 1 # j >= 1 else: L[i][j] = L[i][j-1] + 1 # R for i in range(H-1, -1, -1): for j in range(W-1, -1, -1): if S[i][j] == "#": R[i][j] = 0 continue if j == W-1: R[i][j] = 1 else: R[i][j] = R[i][j+1] + 1 # U for j in range(W): for i in range(H): if S[i][j] == "#": U[i][j] = 0 continue if i == 0: U[i][j] = 1 else: U[i][j] = U[i-1][j] + 1 # D for j in range(W-1, -1, -1): for i in range(H-1, -1, -1): if S[i][j] == "#": D[i][j] = 0 continue if i == H-1: D[i][j] = 1 else: D[i][j] = D[i+1][j] + 1 ans = -INF for i in range(H): for j in range(W): ans = max(ans, L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3) # for DEBUG #print(*S, sep="\n") #print(L) #print(R) #print(D) #print(U) print(ans)
from sys import stdin import math import fractions from collections import deque import itertools INF = 10 ** 10 # H <= 2000, W <= 2000 # H*W -> O(4*10^6) H, W = [int(x) for x in stdin.readline().rstrip().split()] S = [stdin.readline().rstrip() for _ in range(H)] # L[i][j]: i行目j列目に明かりを置いたときにそこから左方向に照らされるマスの個数 # (i行目j列目のマスを含む) L = [[0] * W for _ in range(H)] R = [[0] * W for _ in range(H)] D = [[0] * W for _ in range(H)] U = [[0] * W for _ in range(H)] # L for i in range(H): for j in range(W): if S[i][j] == "#": L[i][j] = 0 continue if j == 0: L[i][j] = 1 # j >= 1 else: L[i][j] = L[i][j-1] + 1 # R for i in range(H-1, -1, -1): for j in range(W-1, -1, -1): if S[i][j] == "#": R[i][j] = 0 continue if j == W-1: R[i][j] = 1 else: R[i][j] = R[i][j+1] + 1 # U for j in range(W): for i in range(H): if S[i][j] == "#": U[i][j] = 0 continue if i == 0: U[i][j] = 1 else: U[i][j] = U[i-1][j] + 1 # D for j in range(W-1, -1, -1): for i in range(H-1, -1, -1): if S[i][j] == "#": D[i][j] = 0 continue if i == H-1: D[i][j] = 1 else: D[i][j] = D[i+1][j] + 1 ans = -INF for i in range(H): for j in range(W): ans = max(ans, L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3) # for DEBUG #print(*S, sep="\n") #print(L) #print(R) #print(D) #print(U) print(ans)
84
84
1,684
1,671
from sys import stdin import math import fractions from collections import deque import itertools INF = 10**10 # H <= 2000, W <= 2000 # H*W -> O(4*10^6) H, W = [int(x) for x in stdin.readline().rstrip().split()] S = [[x for x in stdin.readline().rstrip()] for _ in range(H)] # L[i][j]: i行目j列目に明かりを置いたときにそこから左方向に照らされるマスの個数 # (i行目j列目のマスを含む) L = [[0] * W for _ in range(H)] R = [[0] * W for _ in range(H)] D = [[0] * W for _ in range(H)] U = [[0] * W for _ in range(H)] # L for i in range(H): for j in range(W): if S[i][j] == "#": L[i][j] = 0 continue if j == 0: L[i][j] = 1 # j >= 1 else: L[i][j] = L[i][j - 1] + 1 # R for i in range(H - 1, -1, -1): for j in range(W - 1, -1, -1): if S[i][j] == "#": R[i][j] = 0 continue if j == W - 1: R[i][j] = 1 else: R[i][j] = R[i][j + 1] + 1 # U for j in range(W): for i in range(H): if S[i][j] == "#": U[i][j] = 0 continue if i == 0: U[i][j] = 1 else: U[i][j] = U[i - 1][j] + 1 # D for j in range(W - 1, -1, -1): for i in range(H - 1, -1, -1): if S[i][j] == "#": D[i][j] = 0 continue if i == H - 1: D[i][j] = 1 else: D[i][j] = D[i + 1][j] + 1 ans = -INF for i in range(H): for j in range(W): ans = max(ans, L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3) # for DEBUG # print(*S, sep="\n") # print(L) # print(R) # print(D) # print(U) print(ans)
from sys import stdin import math import fractions from collections import deque import itertools INF = 10**10 # H <= 2000, W <= 2000 # H*W -> O(4*10^6) H, W = [int(x) for x in stdin.readline().rstrip().split()] S = [stdin.readline().rstrip() for _ in range(H)] # L[i][j]: i行目j列目に明かりを置いたときにそこから左方向に照らされるマスの個数 # (i行目j列目のマスを含む) L = [[0] * W for _ in range(H)] R = [[0] * W for _ in range(H)] D = [[0] * W for _ in range(H)] U = [[0] * W for _ in range(H)] # L for i in range(H): for j in range(W): if S[i][j] == "#": L[i][j] = 0 continue if j == 0: L[i][j] = 1 # j >= 1 else: L[i][j] = L[i][j - 1] + 1 # R for i in range(H - 1, -1, -1): for j in range(W - 1, -1, -1): if S[i][j] == "#": R[i][j] = 0 continue if j == W - 1: R[i][j] = 1 else: R[i][j] = R[i][j + 1] + 1 # U for j in range(W): for i in range(H): if S[i][j] == "#": U[i][j] = 0 continue if i == 0: U[i][j] = 1 else: U[i][j] = U[i - 1][j] + 1 # D for j in range(W - 1, -1, -1): for i in range(H - 1, -1, -1): if S[i][j] == "#": D[i][j] = 0 continue if i == H - 1: D[i][j] = 1 else: D[i][j] = D[i + 1][j] + 1 ans = -INF for i in range(H): for j in range(W): ans = max(ans, L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3) # for DEBUG # print(*S, sep="\n") # print(L) # print(R) # print(D) # print(U) print(ans)
false
0
[ "-S = [[x for x in stdin.readline().rstrip()] for _ in range(H)]", "+S = [stdin.readline().rstrip() for _ in range(H)]" ]
false
0.058725
0.059505
0.986884
[ "s919480132", "s990353049" ]
u893063840
p03503
python
s761255259
s039285480
481
118
3,064
9,228
Accepted
Accepted
75.47
n = int(eval(input())) f = [list(map(int, input().split())) for _ in range(n)] p = [list(map(int, input().split())) for _ in range(n)] ans = -float("inf") for i in range(1, 2 ** 10): i_bin = "{:010b}".format(i) sm = 0 for shop_i in range(n): cnt = 0 for j, dig in enumerate(i_bin): if f[shop_i][j] * int(dig):# == 1 cnt += 1 sm += p[shop_i][cnt] ans = max(ans, sm) print(ans)
from itertools import combinations n = int(eval(input())) f = [list(map(int, input().split())) for _ in range(n)] p = [list(map(int, input().split())) for _ in range(n)] ans = - 10 ** 18 for i in range(1, 11): for pat in combinations(list(range(10)), i): cnt = [0] * n for e in pat: for j in range(n): cnt[j] += f[j][e] score = 0 for i, e in enumerate(cnt): score += p[i][e] ans = max(ans, score) print(ans)
17
21
464
505
n = int(eval(input())) f = [list(map(int, input().split())) for _ in range(n)] p = [list(map(int, input().split())) for _ in range(n)] ans = -float("inf") for i in range(1, 2**10): i_bin = "{:010b}".format(i) sm = 0 for shop_i in range(n): cnt = 0 for j, dig in enumerate(i_bin): if f[shop_i][j] * int(dig): # == 1 cnt += 1 sm += p[shop_i][cnt] ans = max(ans, sm) print(ans)
from itertools import combinations n = int(eval(input())) f = [list(map(int, input().split())) for _ in range(n)] p = [list(map(int, input().split())) for _ in range(n)] ans = -(10**18) for i in range(1, 11): for pat in combinations(list(range(10)), i): cnt = [0] * n for e in pat: for j in range(n): cnt[j] += f[j][e] score = 0 for i, e in enumerate(cnt): score += p[i][e] ans = max(ans, score) print(ans)
false
19.047619
[ "+from itertools import combinations", "+", "-ans = -float(\"inf\")", "-for i in range(1, 2**10):", "- i_bin = \"{:010b}\".format(i)", "- sm = 0", "- for shop_i in range(n):", "- cnt = 0", "- for j, dig in enumerate(i_bin):", "- if f[shop_i][j] * int(dig): # == 1", "- cnt += 1", "- sm += p[shop_i][cnt]", "- ans = max(ans, sm)", "+ans = -(10**18)", "+for i in range(1, 11):", "+ for pat in combinations(list(range(10)), i):", "+ cnt = [0] * n", "+ for e in pat:", "+ for j in range(n):", "+ cnt[j] += f[j][e]", "+ score = 0", "+ for i, e in enumerate(cnt):", "+ score += p[i][e]", "+ ans = max(ans, score)" ]
false
0.043648
0.042619
1.024147
[ "s761255259", "s039285480" ]
u768559443
p03107
python
s147498660
s918945223
180
46
39,408
3,956
Accepted
Accepted
74.44
s=eval(input()) a=0 b=0 for i in s: if i=="0": a+=1 else: b+=1 print((min(a,b)*2))
S=eval(input()) stack=[] cnt=0 for s in S: if not stack: stack.append(s) elif stack[-1]!=s: stack.pop() cnt+=2 else: stack.append(s) print(cnt)
11
13
100
176
s = eval(input()) a = 0 b = 0 for i in s: if i == "0": a += 1 else: b += 1 print((min(a, b) * 2))
S = eval(input()) stack = [] cnt = 0 for s in S: if not stack: stack.append(s) elif stack[-1] != s: stack.pop() cnt += 2 else: stack.append(s) print(cnt)
false
15.384615
[ "-s = eval(input())", "-a = 0", "-b = 0", "-for i in s:", "- if i == \"0\":", "- a += 1", "+S = eval(input())", "+stack = []", "+cnt = 0", "+for s in S:", "+ if not stack:", "+ stack.append(s)", "+ elif stack[-1] != s:", "+ stack.pop()", "+ cnt += 2", "- b += 1", "-print((min(a, b) * 2))", "+ stack.append(s)", "+print(cnt)" ]
false
0.085641
0.044429
1.927578
[ "s147498660", "s918945223" ]
u678167152
p03137
python
s779732881
s722427616
110
86
13,968
20,300
Accepted
Accepted
21.82
N, M = list(map(int, input().split())) X = list(map(int, input().split())) X.sort() diff = [0]*(M-1) for i in range(M-1): diff[i] = X[i+1]-X[i] diff.sort() if N>=M: ans = 0 else: ans = sum(diff[:M-N]) print(ans)
def solve(): N, M = list(map(int, input().split())) X = list(map(int, input().split())) X.sort() lis = [] for i in range(M-1): lis.append(X[i+1]-X[i]) lis.sort(reverse=True) ans = X[-1]-X[0]-sum(lis[:N-1]) return ans print((solve()))
14
11
232
255
N, M = list(map(int, input().split())) X = list(map(int, input().split())) X.sort() diff = [0] * (M - 1) for i in range(M - 1): diff[i] = X[i + 1] - X[i] diff.sort() if N >= M: ans = 0 else: ans = sum(diff[: M - N]) print(ans)
def solve(): N, M = list(map(int, input().split())) X = list(map(int, input().split())) X.sort() lis = [] for i in range(M - 1): lis.append(X[i + 1] - X[i]) lis.sort(reverse=True) ans = X[-1] - X[0] - sum(lis[: N - 1]) return ans print((solve()))
false
21.428571
[ "-N, M = list(map(int, input().split()))", "-X = list(map(int, input().split()))", "-X.sort()", "-diff = [0] * (M - 1)", "-for i in range(M - 1):", "- diff[i] = X[i + 1] - X[i]", "-diff.sort()", "-if N >= M:", "- ans = 0", "-else:", "- ans = sum(diff[: M - N])", "-print(ans)", "+def solve():", "+ N, M = list(map(int, input().split()))", "+ X = list(map(int, input().split()))", "+ X.sort()", "+ lis = []", "+ for i in range(M - 1):", "+ lis.append(X[i + 1] - X[i])", "+ lis.sort(reverse=True)", "+ ans = X[-1] - X[0] - sum(lis[: N - 1])", "+ return ans", "+", "+", "+print((solve()))" ]
false
0.047485
0.04637
1.02405
[ "s779732881", "s722427616" ]
u596536048
p03563
python
s554444013
s121077065
29
25
9,092
8,996
Accepted
Accepted
13.79
R, G = (int(eval(input())) for i in range(2)) print((G * 2 - R))
print((-int(eval(input())) + int(eval(input())) * 2))
2
1
57
40
R, G = (int(eval(input())) for i in range(2)) print((G * 2 - R))
print((-int(eval(input())) + int(eval(input())) * 2))
false
50
[ "-R, G = (int(eval(input())) for i in range(2))", "-print((G * 2 - R))", "+print((-int(eval(input())) + int(eval(input())) * 2))" ]
false
0.113185
0.032472
3.485571
[ "s554444013", "s121077065" ]
u098012509
p03476
python
s143250259
s673615436
750
286
34,108
23,044
Accepted
Accepted
61.87
import sys import bisect from functools import lru_cache input = sys.stdin.readline @lru_cache(maxsize=None) def is_prime(n): if n == 1: return False for i in range(2, int(n ** 0.5) + 1): if n % i == 0: return False return True def main(): Q = int(eval(input())) lr = [[int(x) for x in input().split()] for _ in range(Q)] sosu = [] for i in range(1, 10 ** 5 + 1): if is_prime(i) and is_prime((i + 1) // 2): sosu.append(i) for l, r in lr: li = bisect.bisect_left(sosu, l) ri = bisect.bisect_right(sosu, r) print((ri - li)) if __name__ == '__main__': main()
import sys import bisect input = sys.stdin.readline def get_primes(n): sieve = [1] * n for i in range(3, int(n ** 0.5) + 1, 2): if sieve[i]: sieve[i * i:: 2 * i] = [0] * ((n - i * i - 1) // (2 * i) + 1) return [2] + [i for i in range(3, n, 2) if sieve[i]] def main(): Q = int(eval(input())) lr = [[int(x) for x in input().split()] for _ in range(Q)] P = get_primes(10 ** 5 + 1) setP = set(P) like = [] for p in P: if (p + 1) // 2 in setP: like.append(p) for l, r in lr: li = bisect.bisect_left(like, l) ri = bisect.bisect_right(like, r) print((ri - li)) if __name__ == '__main__': main()
41
34
712
731
import sys import bisect from functools import lru_cache input = sys.stdin.readline @lru_cache(maxsize=None) def is_prime(n): if n == 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def main(): Q = int(eval(input())) lr = [[int(x) for x in input().split()] for _ in range(Q)] sosu = [] for i in range(1, 10**5 + 1): if is_prime(i) and is_prime((i + 1) // 2): sosu.append(i) for l, r in lr: li = bisect.bisect_left(sosu, l) ri = bisect.bisect_right(sosu, r) print((ri - li)) if __name__ == "__main__": main()
import sys import bisect input = sys.stdin.readline def get_primes(n): sieve = [1] * n for i in range(3, int(n**0.5) + 1, 2): if sieve[i]: sieve[i * i :: 2 * i] = [0] * ((n - i * i - 1) // (2 * i) + 1) return [2] + [i for i in range(3, n, 2) if sieve[i]] def main(): Q = int(eval(input())) lr = [[int(x) for x in input().split()] for _ in range(Q)] P = get_primes(10**5 + 1) setP = set(P) like = [] for p in P: if (p + 1) // 2 in setP: like.append(p) for l, r in lr: li = bisect.bisect_left(like, l) ri = bisect.bisect_right(like, r) print((ri - li)) if __name__ == "__main__": main()
false
17.073171
[ "-from functools import lru_cache", "-@lru_cache(maxsize=None)", "-def is_prime(n):", "- if n == 1:", "- return False", "- for i in range(2, int(n**0.5) + 1):", "- if n % i == 0:", "- return False", "- return True", "+def get_primes(n):", "+ sieve = [1] * n", "+ for i in range(3, int(n**0.5) + 1, 2):", "+ if sieve[i]:", "+ sieve[i * i :: 2 * i] = [0] * ((n - i * i - 1) // (2 * i) + 1)", "+ return [2] + [i for i in range(3, n, 2) if sieve[i]]", "- sosu = []", "- for i in range(1, 10**5 + 1):", "- if is_prime(i) and is_prime((i + 1) // 2):", "- sosu.append(i)", "+ P = get_primes(10**5 + 1)", "+ setP = set(P)", "+ like = []", "+ for p in P:", "+ if (p + 1) // 2 in setP:", "+ like.append(p)", "- li = bisect.bisect_left(sosu, l)", "- ri = bisect.bisect_right(sosu, r)", "+ li = bisect.bisect_left(like, l)", "+ ri = bisect.bisect_right(like, r)" ]
false
0.56793
0.147295
3.85573
[ "s143250259", "s673615436" ]
u351892848
p02773
python
s718173478
s528930233
659
434
35,572
38,812
Accepted
Accepted
34.14
from collections import Counter N = int(eval(input())) S = [] for _ in range(N): S.append(eval(input())) counter = Counter(S) max_val = max(counter.values()) ans = [] for key, value in list(counter.items()): if value == max_val: ans.append(key) ans = sorted(ans) for s in ans: print(s)
from collections import Counter N = int(eval(input())) S = [eval(input()) for _ in range(N)] counter = Counter(S) maxv = max(counter.values()) ans = [] for k, v in list(counter.items()): if v == maxv: ans.append(k) ans.sort() for s in ans: print(s)
19
16
311
266
from collections import Counter N = int(eval(input())) S = [] for _ in range(N): S.append(eval(input())) counter = Counter(S) max_val = max(counter.values()) ans = [] for key, value in list(counter.items()): if value == max_val: ans.append(key) ans = sorted(ans) for s in ans: print(s)
from collections import Counter N = int(eval(input())) S = [eval(input()) for _ in range(N)] counter = Counter(S) maxv = max(counter.values()) ans = [] for k, v in list(counter.items()): if v == maxv: ans.append(k) ans.sort() for s in ans: print(s)
false
15.789474
[ "-S = []", "-for _ in range(N):", "- S.append(eval(input()))", "+S = [eval(input()) for _ in range(N)]", "-max_val = max(counter.values())", "+maxv = max(counter.values())", "-for key, value in list(counter.items()):", "- if value == max_val:", "- ans.append(key)", "-ans = sorted(ans)", "+for k, v in list(counter.items()):", "+ if v == maxv:", "+ ans.append(k)", "+ans.sort()" ]
false
0.085081
0.034991
2.43149
[ "s718173478", "s528930233" ]
u134302690
p03137
python
s881424846
s343474916
126
109
13,968
13,968
Accepted
Accepted
13.49
N, M = list(map(int, input().split())) X = list(map(int, input().split())) if N >= M: print((0)) else: X.sort() X_div = [0] * (M-1) for i in range(1,M): X_div[i-1] = X[i] - X[i-1] X_div.sort(reverse=True) m = 0 for i in range(N-1): m += X_div[i] print((X[-1]-X[0]-m))
N,M = list(map(int,input().split())) x = list(map(int,input().split())) x.sort() l = [0]*(M) for i in range(1,M): l[i] = x[i]-x[i-1] l.sort(reverse=True) print((sum(l[(N-1):])))
14
8
319
180
N, M = list(map(int, input().split())) X = list(map(int, input().split())) if N >= M: print((0)) else: X.sort() X_div = [0] * (M - 1) for i in range(1, M): X_div[i - 1] = X[i] - X[i - 1] X_div.sort(reverse=True) m = 0 for i in range(N - 1): m += X_div[i] print((X[-1] - X[0] - m))
N, M = list(map(int, input().split())) x = list(map(int, input().split())) x.sort() l = [0] * (M) for i in range(1, M): l[i] = x[i] - x[i - 1] l.sort(reverse=True) print((sum(l[(N - 1) :])))
false
42.857143
[ "-X = list(map(int, input().split()))", "-if N >= M:", "- print((0))", "-else:", "- X.sort()", "- X_div = [0] * (M - 1)", "- for i in range(1, M):", "- X_div[i - 1] = X[i] - X[i - 1]", "- X_div.sort(reverse=True)", "- m = 0", "- for i in range(N - 1):", "- m += X_div[i]", "- print((X[-1] - X[0] - m))", "+x = list(map(int, input().split()))", "+x.sort()", "+l = [0] * (M)", "+for i in range(1, M):", "+ l[i] = x[i] - x[i - 1]", "+l.sort(reverse=True)", "+print((sum(l[(N - 1) :])))" ]
false
0.044834
0.042161
1.063395
[ "s881424846", "s343474916" ]
u312025627
p02792
python
s430115856
s146769717
212
79
40,428
67,932
Accepted
Accepted
62.74
def main(): N = int(eval(input())) c = [[0]*10 for _ in range(10)] for n in range(1, N+1): s = str(n) c[int(s[0])][int(s[-1])] += 1 ans = 0 for i in range(1, 10): for j in range(1, 10): # if c[i][j]*c[j][i]: # print(i, j, c[i][j]*c[j][i]) ans += c[i][j] * c[j][i] print(ans) # print(*c, sep="\n") if __name__ == '__main__': main()
def main(): N = int(eval(input())) C = [[0]*10 for _ in range(10)] for num in range(1, N+1): s = str(num) px = int(s[0]) sf = int(s[-1]) C[px][sf] += 1 ans = 0 for i in range(1, 10): for j in range(1, 10): ans += C[i][j] * C[j][i] print(ans) if __name__ == '__main__': main()
18
17
440
368
def main(): N = int(eval(input())) c = [[0] * 10 for _ in range(10)] for n in range(1, N + 1): s = str(n) c[int(s[0])][int(s[-1])] += 1 ans = 0 for i in range(1, 10): for j in range(1, 10): # if c[i][j]*c[j][i]: # print(i, j, c[i][j]*c[j][i]) ans += c[i][j] * c[j][i] print(ans) # print(*c, sep="\n") if __name__ == "__main__": main()
def main(): N = int(eval(input())) C = [[0] * 10 for _ in range(10)] for num in range(1, N + 1): s = str(num) px = int(s[0]) sf = int(s[-1]) C[px][sf] += 1 ans = 0 for i in range(1, 10): for j in range(1, 10): ans += C[i][j] * C[j][i] print(ans) if __name__ == "__main__": main()
false
5.555556
[ "- c = [[0] * 10 for _ in range(10)]", "- for n in range(1, N + 1):", "- s = str(n)", "- c[int(s[0])][int(s[-1])] += 1", "+ C = [[0] * 10 for _ in range(10)]", "+ for num in range(1, N + 1):", "+ s = str(num)", "+ px = int(s[0])", "+ sf = int(s[-1])", "+ C[px][sf] += 1", "- # if c[i][j]*c[j][i]:", "- # print(i, j, c[i][j]*c[j][i])", "- ans += c[i][j] * c[j][i]", "+ ans += C[i][j] * C[j][i]", "- # print(*c, sep=\"\\n\")" ]
false
0.060852
0.058585
1.038684
[ "s430115856", "s146769717" ]
u241159583
p03107
python
s367663165
s845272267
20
18
3,956
3,188
Accepted
Accepted
10
S = list(eval(input())) n = len(S) red = S.count("0") blue = n - red print((n if red == blue else n - abs(red - blue)))
S = eval(input()) n = len(S) red = S.count("0") blue = n - red print((n if red == blue else min(red, blue) * 2))
5
5
115
108
S = list(eval(input())) n = len(S) red = S.count("0") blue = n - red print((n if red == blue else n - abs(red - blue)))
S = eval(input()) n = len(S) red = S.count("0") blue = n - red print((n if red == blue else min(red, blue) * 2))
false
0
[ "-S = list(eval(input()))", "+S = eval(input())", "-print((n if red == blue else n - abs(red - blue)))", "+print((n if red == blue else min(red, blue) * 2))" ]
false
0.044165
0.040716
1.084726
[ "s367663165", "s845272267" ]
u746419473
p03637
python
s085230202
s992797693
71
64
14,224
14,252
Accepted
Accepted
9.86
n = int(eval(input())) *a, = list(map(int, input().split())) *b, = [x for x in a if x%4 != 0] mul_4 = n-len(b) *c, = [x for x in b if x%2 != 0] mul_2 = (len(b)-len(c)) k = n-(mul_4+mul_2) if mul_2 == 0 and k <= mul_4+1: print("Yes") elif k <= mul_4: print("Yes") else: print("No")
n = int(eval(input())) *a, = list(map(int, input().split())) b1 = 0 b2 = 0 b4 = 0 for _a in a: if _a%4 == 0: b4 += 1 elif _a%2 == 0: b2 += 1 else: b1 += 1 if b2 == 0: print(("Yes" if b1 <= b4+1 else "No")) else: print(("Yes" if b1 <= b4 else "No"))
17
18
307
296
n = int(eval(input())) (*a,) = list(map(int, input().split())) (*b,) = [x for x in a if x % 4 != 0] mul_4 = n - len(b) (*c,) = [x for x in b if x % 2 != 0] mul_2 = len(b) - len(c) k = n - (mul_4 + mul_2) if mul_2 == 0 and k <= mul_4 + 1: print("Yes") elif k <= mul_4: print("Yes") else: print("No")
n = int(eval(input())) (*a,) = list(map(int, input().split())) b1 = 0 b2 = 0 b4 = 0 for _a in a: if _a % 4 == 0: b4 += 1 elif _a % 2 == 0: b2 += 1 else: b1 += 1 if b2 == 0: print(("Yes" if b1 <= b4 + 1 else "No")) else: print(("Yes" if b1 <= b4 else "No"))
false
5.555556
[ "-(*b,) = [x for x in a if x % 4 != 0]", "-mul_4 = n - len(b)", "-(*c,) = [x for x in b if x % 2 != 0]", "-mul_2 = len(b) - len(c)", "-k = n - (mul_4 + mul_2)", "-if mul_2 == 0 and k <= mul_4 + 1:", "- print(\"Yes\")", "-elif k <= mul_4:", "- print(\"Yes\")", "+b1 = 0", "+b2 = 0", "+b4 = 0", "+for _a in a:", "+ if _a % 4 == 0:", "+ b4 += 1", "+ elif _a % 2 == 0:", "+ b2 += 1", "+ else:", "+ b1 += 1", "+if b2 == 0:", "+ print((\"Yes\" if b1 <= b4 + 1 else \"No\"))", "- print(\"No\")", "+ print((\"Yes\" if b1 <= b4 else \"No\"))" ]
false
0.046196
0.043003
1.074253
[ "s085230202", "s992797693" ]
u201234972
p02996
python
s133971799
s457559748
814
544
29,392
29,400
Accepted
Accepted
33.17
#import sys #input = sys.stdin.readline def main(): N = int( eval(input())) T = [ (0,0)]*N for i in range(N): a, b = list(map( int, input().split())) T[i] = (b,a) T.sort() time = 0 ans = "Yes" for i in range(N): time += T[i][1] if time > T[i][0]: ans = "No" break print(ans) if __name__ == '__main__': main()
import sys input = sys.stdin.readline def main(): N = int( eval(input())) T = [ (0,0)]*N for i in range(N): a, b = list(map( int, input().split())) T[i] = (b,a) T.sort() time = 0 ans = "Yes" for i in range(N): time += T[i][1] if time > T[i][0]: ans = "No" break print(ans) if __name__ == '__main__': main()
19
19
407
405
# import sys # input = sys.stdin.readline def main(): N = int(eval(input())) T = [(0, 0)] * N for i in range(N): a, b = list(map(int, input().split())) T[i] = (b, a) T.sort() time = 0 ans = "Yes" for i in range(N): time += T[i][1] if time > T[i][0]: ans = "No" break print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): N = int(eval(input())) T = [(0, 0)] * N for i in range(N): a, b = list(map(int, input().split())) T[i] = (b, a) T.sort() time = 0 ans = "Yes" for i in range(N): time += T[i][1] if time > T[i][0]: ans = "No" break print(ans) if __name__ == "__main__": main()
false
0
[ "-# import sys", "-# input = sys.stdin.readline", "+import sys", "+", "+input = sys.stdin.readline", "+", "+" ]
false
0.047181
0.046546
1.013642
[ "s133971799", "s457559748" ]
u112364985
p02924
python
s973024685
s458557205
31
27
9,092
8,980
Accepted
Accepted
12.9
n=int(eval(input())) print((n*(n+1)//2-n))
n=int(eval(input())) print((n*(n-1)//2))
2
2
35
33
n = int(eval(input())) print((n * (n + 1) // 2 - n))
n = int(eval(input())) print((n * (n - 1) // 2))
false
0
[ "-print((n * (n + 1) // 2 - n))", "+print((n * (n - 1) // 2))" ]
false
0.039073
0.04465
0.87509
[ "s973024685", "s458557205" ]
u254871849
p03637
python
s558420205
s747541465
71
64
14,052
14,052
Accepted
Accepted
9.86
from sys import stdin n, *a = list(map(int, stdin.read().split())) c2, c4 = 0, 0 for i in a: if i % 2 == 0: c2 += 1 if i % 4 == 0: c4 += 1 if c4 >= len(a) // 2: ans = "Yes" elif (len(a) - c4 * 2) == (c2 - c4): ans = "Yes" else: ans = "No" print(ans)
from sys import stdin n, *a = list(map(int, stdin.read().split())) c2, c4 = 0, 0 for i in a: if i % 2 == 0: if i % 4 == 0: c4 += 1 else: c2 += 1 if c4 >= len(a) // 2: ans = "Yes" elif (len(a) - c4 * 2) == c2: ans = "Yes" else: ans = "No" print(ans)
12
15
264
303
from sys import stdin n, *a = list(map(int, stdin.read().split())) c2, c4 = 0, 0 for i in a: if i % 2 == 0: c2 += 1 if i % 4 == 0: c4 += 1 if c4 >= len(a) // 2: ans = "Yes" elif (len(a) - c4 * 2) == (c2 - c4): ans = "Yes" else: ans = "No" print(ans)
from sys import stdin n, *a = list(map(int, stdin.read().split())) c2, c4 = 0, 0 for i in a: if i % 2 == 0: if i % 4 == 0: c4 += 1 else: c2 += 1 if c4 >= len(a) // 2: ans = "Yes" elif (len(a) - c4 * 2) == c2: ans = "Yes" else: ans = "No" print(ans)
false
20
[ "- c2 += 1", "- if i % 4 == 0:", "- c4 += 1", "+ if i % 4 == 0:", "+ c4 += 1", "+ else:", "+ c2 += 1", "-elif (len(a) - c4 * 2) == (c2 - c4):", "+elif (len(a) - c4 * 2) == c2:" ]
false
0.044
0.037363
1.177643
[ "s558420205", "s747541465" ]
u075012704
p02948
python
s368499691
s600102118
944
588
84,536
31,964
Accepted
Accepted
37.71
import heapq N, M = list(map(int, input().split())) Work = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: x[0]) ans = 0 can_work = [] i = 0 for m in range(M + 1): while (i < N) and (Work[i][0]) <= m: heapq.heappush(can_work, -Work[i][1]) i += 1 if can_work: ans += -heapq.heappop(can_work) print(ans)
import heapq N, M = list(map(int, input().split())) works = sorted([list(map(int, input().split())) for i in range(N)]) ans = 0 hq = [] i = 0 for limit in range(1, M + 1): while (i < N) and (works[i][0] <= limit): cost, value = works[i] heapq.heappush(hq, -value) i += 1 if hq: ans += -heapq.heappop(hq) print(ans)
15
17
370
368
import heapq N, M = list(map(int, input().split())) Work = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: x[0]) ans = 0 can_work = [] i = 0 for m in range(M + 1): while (i < N) and (Work[i][0]) <= m: heapq.heappush(can_work, -Work[i][1]) i += 1 if can_work: ans += -heapq.heappop(can_work) print(ans)
import heapq N, M = list(map(int, input().split())) works = sorted([list(map(int, input().split())) for i in range(N)]) ans = 0 hq = [] i = 0 for limit in range(1, M + 1): while (i < N) and (works[i][0] <= limit): cost, value = works[i] heapq.heappush(hq, -value) i += 1 if hq: ans += -heapq.heappop(hq) print(ans)
false
11.764706
[ "-Work = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: x[0])", "+works = sorted([list(map(int, input().split())) for i in range(N)])", "-can_work = []", "+hq = []", "-for m in range(M + 1):", "- while (i < N) and (Work[i][0]) <= m:", "- heapq.heappush(can_work, -Work[i][1])", "+for limit in range(1, M + 1):", "+ while (i < N) and (works[i][0] <= limit):", "+ cost, value = works[i]", "+ heapq.heappush(hq, -value)", "- if can_work:", "- ans += -heapq.heappop(can_work)", "+ if hq:", "+ ans += -heapq.heappop(hq)" ]
false
0.040729
0.042156
0.966155
[ "s368499691", "s600102118" ]
u715107458
p03160
python
s446959799
s780255115
788
137
268,484
14,976
Accepted
Accepted
82.61
from functools import lru_cache import sys sys.setrecursionlimit(20000000) N = int(eval(input())) heights = [int(h) for h in input().split()] # heights = [10, 30, 40, 20] # heights = [10, 10] # heights = [30, 10, 60, 10, 60, 50] # 记忆化 @lru_cache(None) def dfs(i): if i == len(heights) - 1: return 0 return min(abs(heights[i] - heights[i + 1]) + dfs(i + 1) if i + 1 < len(heights) else float("inf"), abs(heights[i] - heights[i + 2]) + dfs(i + 2) if i + 2 < len(heights) else float("inf")) print((dfs(0)))
import sys from functools import lru_cache sys.setrecursionlimit(20000000) N = int(eval(input())) heights = [int(h) for h in input().split()] # heights = [10, 30, 40, 20] # heights = [10, 10] # heights = [30, 10, 60, 10, 60, 50] # 记忆化 @lru_cache(None) def dfs(i): if i == len(heights) - 1: return 0 return min(abs(heights[i] - heights[i + 1]) + dfs(i + 1) if i + 1 < len(heights) else float("inf"), abs(heights[i] - heights[i + 2]) + dfs(i + 2) if i + 2 < len(heights) else float("inf")) def helper(): dp = [float("inf")] * len(heights) dp[0] = 0 for i in range(1, len(heights)): dp[i] = min(dp[i], dp[i - 1] + abs(heights[i] - heights[i - 1])) if i > 1: dp[i] = min(dp[i], dp[i - 2] + abs(heights[i] - heights[i - 2])) return dp[-1] # print(dfs(0)) print((helper()))
22
34
554
876
from functools import lru_cache import sys sys.setrecursionlimit(20000000) N = int(eval(input())) heights = [int(h) for h in input().split()] # heights = [10, 30, 40, 20] # heights = [10, 10] # heights = [30, 10, 60, 10, 60, 50] # 记忆化 @lru_cache(None) def dfs(i): if i == len(heights) - 1: return 0 return min( abs(heights[i] - heights[i + 1]) + dfs(i + 1) if i + 1 < len(heights) else float("inf"), abs(heights[i] - heights[i + 2]) + dfs(i + 2) if i + 2 < len(heights) else float("inf"), ) print((dfs(0)))
import sys from functools import lru_cache sys.setrecursionlimit(20000000) N = int(eval(input())) heights = [int(h) for h in input().split()] # heights = [10, 30, 40, 20] # heights = [10, 10] # heights = [30, 10, 60, 10, 60, 50] # 记忆化 @lru_cache(None) def dfs(i): if i == len(heights) - 1: return 0 return min( abs(heights[i] - heights[i + 1]) + dfs(i + 1) if i + 1 < len(heights) else float("inf"), abs(heights[i] - heights[i + 2]) + dfs(i + 2) if i + 2 < len(heights) else float("inf"), ) def helper(): dp = [float("inf")] * len(heights) dp[0] = 0 for i in range(1, len(heights)): dp[i] = min(dp[i], dp[i - 1] + abs(heights[i] - heights[i - 1])) if i > 1: dp[i] = min(dp[i], dp[i - 2] + abs(heights[i] - heights[i - 2])) return dp[-1] # print(dfs(0)) print((helper()))
false
35.294118
[ "+import sys", "-import sys", "-print((dfs(0)))", "+def helper():", "+ dp = [float(\"inf\")] * len(heights)", "+ dp[0] = 0", "+ for i in range(1, len(heights)):", "+ dp[i] = min(dp[i], dp[i - 1] + abs(heights[i] - heights[i - 1]))", "+ if i > 1:", "+ dp[i] = min(dp[i], dp[i - 2] + abs(heights[i] - heights[i - 2]))", "+ return dp[-1]", "+", "+", "+# print(dfs(0))", "+print((helper()))" ]
false
0.040575
0.037093
1.093865
[ "s446959799", "s780255115" ]
u327465093
p02608
python
s551452560
s223531373
282
89
71,144
9,224
Accepted
Accepted
68.44
from collections import Counter N = int(eval(input())) counter = [0] * 10001 for x in range(1, N+1): n1 = x * x if n1 >= N: continue for y in range(x, N+1): n2 = n1 + y * y + x * y if n2 >= N: continue for z in range(y, N+1): n = n2 + z * z + y * z + z * x if 1 <= n <= 10000: s = len(Counter([x, y, z])) if s == 1: counter[n] += 1 elif s == 2: counter[n] += 3 elif s == 3: counter[n] += 6 for i in range(1, N+1): print((counter[i]))
N = int(eval(input())) counter = [0] * 10001 for x in range(1, 100+1): n1 = x * x if n1 >= N: continue for y in range(x, 100+1): n2 = n1 + y * y + x * y if n2 >= N: continue for z in range(y, 100+1): n = n2 + z * z + y * z + z * x if 1 <= n <= 10000: if x == y and y == z: counter[n] += 1 elif x == y or y == z: counter[n] += 3 else: counter[n] += 6 for i in range(1, N+1): print((counter[i]))
25
22
660
600
from collections import Counter N = int(eval(input())) counter = [0] * 10001 for x in range(1, N + 1): n1 = x * x if n1 >= N: continue for y in range(x, N + 1): n2 = n1 + y * y + x * y if n2 >= N: continue for z in range(y, N + 1): n = n2 + z * z + y * z + z * x if 1 <= n <= 10000: s = len(Counter([x, y, z])) if s == 1: counter[n] += 1 elif s == 2: counter[n] += 3 elif s == 3: counter[n] += 6 for i in range(1, N + 1): print((counter[i]))
N = int(eval(input())) counter = [0] * 10001 for x in range(1, 100 + 1): n1 = x * x if n1 >= N: continue for y in range(x, 100 + 1): n2 = n1 + y * y + x * y if n2 >= N: continue for z in range(y, 100 + 1): n = n2 + z * z + y * z + z * x if 1 <= n <= 10000: if x == y and y == z: counter[n] += 1 elif x == y or y == z: counter[n] += 3 else: counter[n] += 6 for i in range(1, N + 1): print((counter[i]))
false
12
[ "-from collections import Counter", "-", "-for x in range(1, N + 1):", "+for x in range(1, 100 + 1):", "- for y in range(x, N + 1):", "+ for y in range(x, 100 + 1):", "- for z in range(y, N + 1):", "+ for z in range(y, 100 + 1):", "- s = len(Counter([x, y, z]))", "- if s == 1:", "+ if x == y and y == z:", "- elif s == 2:", "+ elif x == y or y == z:", "- elif s == 3:", "+ else:" ]
false
0.041932
0.078517
0.534044
[ "s551452560", "s223531373" ]
u070201429
p03409
python
s587110442
s559787992
72
66
63,908
63,100
Accepted
Accepted
8.33
def main(): from sys import stdin def input(): return stdin.readline().strip() n = int(eval(input())) red = [tuple(map(int, input().split())) for _ in range(n)] blue = [tuple(map(int, input().split())) for _ in range(n)] red.sort() blue.sort() now = 0 for i in blue: while now < len(red) and red[now] < i: now += 1 l = red[:now] if l == []: continue l = sorted(l, key=lambda x: x[1]) for j in range(len(l)-1, -1, -1): if l[j][1] < i[1]: red.remove(l[j]) now -= 1 break print((n - len(red))) main()
def main(): from sys import stdin def input(): return stdin.readline().strip() n = int(eval(input())) red = [tuple(map(int, input().split())) for _ in range(n)] blue = [tuple(map(int, input().split())) for _ in range(n)] red.sort() blue.sort() now = 0 for i in blue: while now < len(red) and red[now] < i: now += 1 l = red[:now] if l == []: continue l = sorted(l, key=lambda x: x[1]) if l[0][1] > i[1]: continue # binary search left = 0 right = len(l) - 1 while left < right: center = (left + right + 1) // 2 if l[center][1] < i[1]: left = center else: right = center - 1 red.remove(l[left]) now -= 1 print((n - len(red))) main()
31
41
710
930
def main(): from sys import stdin def input(): return stdin.readline().strip() n = int(eval(input())) red = [tuple(map(int, input().split())) for _ in range(n)] blue = [tuple(map(int, input().split())) for _ in range(n)] red.sort() blue.sort() now = 0 for i in blue: while now < len(red) and red[now] < i: now += 1 l = red[:now] if l == []: continue l = sorted(l, key=lambda x: x[1]) for j in range(len(l) - 1, -1, -1): if l[j][1] < i[1]: red.remove(l[j]) now -= 1 break print((n - len(red))) main()
def main(): from sys import stdin def input(): return stdin.readline().strip() n = int(eval(input())) red = [tuple(map(int, input().split())) for _ in range(n)] blue = [tuple(map(int, input().split())) for _ in range(n)] red.sort() blue.sort() now = 0 for i in blue: while now < len(red) and red[now] < i: now += 1 l = red[:now] if l == []: continue l = sorted(l, key=lambda x: x[1]) if l[0][1] > i[1]: continue # binary search left = 0 right = len(l) - 1 while left < right: center = (left + right + 1) // 2 if l[center][1] < i[1]: left = center else: right = center - 1 red.remove(l[left]) now -= 1 print((n - len(red))) main()
false
24.390244
[ "- for j in range(len(l) - 1, -1, -1):", "- if l[j][1] < i[1]:", "- red.remove(l[j])", "- now -= 1", "- break", "+ if l[0][1] > i[1]:", "+ continue", "+ # binary search", "+ left = 0", "+ right = len(l) - 1", "+ while left < right:", "+ center = (left + right + 1) // 2", "+ if l[center][1] < i[1]:", "+ left = center", "+ else:", "+ right = center - 1", "+ red.remove(l[left])", "+ now -= 1" ]
false
0.034292
0.034216
1.002207
[ "s587110442", "s559787992" ]
u495903598
p03061
python
s210412298
s761735546
210
189
14,072
14,076
Accepted
Accepted
10
# coding: utf-8 # In[1]: import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) # In[2]: #import copy #import numpy as np try: from fractions import gcd except: from math import gcd # In[ ]: # 左からn個の最大公約数を求める O(n) # 右からn個の最大公約数を求める O(n) # n個目を抜いた最大公約数は n-1個目までの公約数とn+1個目からの公約数との公約数 # In[3]: lg = [1]*(N) rg = [1]*(N) ans = 0 # In[4]: #print(lg) #print(rg) #print(A) # In[5]: lg[0] = A[1] rg[0] = A[N-2] lg[1] = A[0] rg[1] = A[N-1] #print(lg, rg) for i in range(1, N-1): #print(i) lg[i+1] = gcd(lg[i], A[i]) #print(lg[i], A[i]) rg[i+1] = gcd(rg[i], A[N-1-i]) #print(rg[N-1-i], A[N-1-i]) #print(lg, rg) for i in range(N): #print(i, lg[i], rg[N-i-1]) tmp = gcd(lg[i], rg[N-i-1]) #print(tmp) if ans < tmp: ans = tmp #print(ans) # In[6]: print(ans) # In[ ]: """ [42 54 69 92 12 23]のとき 1 [54 69 92 12 23]の最大公約数 2 [42 69 92 12 23] 3 [42 54 92 12 23] 4 [42 54 69 12 23] """
# coding: utf-8 # In[1]: import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) # In[2]: #import copy #import numpy as np try: from fractions import gcd except: from math import gcd # In[ ]: # 左からn個の最大公約数を求める O(n) # 右からn個の最大公約数を求める O(n) # n個目を抜いた最大公約数は n-1個目までの公約数とn+1個目からの公約数との公約数 # In[3]: lg = [1]*(N) rg = [1]*(N) ans = 0 # In[4]: #print(lg) #print(rg) #print(A) # In[ ]: lg[0] = A[1] rg[0] = A[N-2] lg[1] = A[0] rg[1] = A[N-1] #print(lg, rg) for i in range(1, N-1): #print(i) lg[i+1] = gcd(lg[i], A[i]) #print(lg[i], A[i]) rg[i+1] = gcd(rg[i], A[N-1-i]) #print(rg[N-1-i], A[N-1-i]) #print(lg, rg) #ans = [0]*N ans = [gcd(lg[i], rg[N-1-i]) for i in range(N)] #for i in range(N): #print(i, lg[i], rg[N-i-1]) #ans = gcd(lg[i], rg[N-i-1]) print((max(ans))) # In[6]: #print(ans)
82
69
1,070
939
# coding: utf-8 # In[1]: import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) # In[2]: # import copy # import numpy as np try: from fractions import gcd except: from math import gcd # In[ ]: # 左からn個の最大公約数を求める O(n) # 右からn個の最大公約数を求める O(n) # n個目を抜いた最大公約数は n-1個目までの公約数とn+1個目からの公約数との公約数 # In[3]: lg = [1] * (N) rg = [1] * (N) ans = 0 # In[4]: # print(lg) # print(rg) # print(A) # In[5]: lg[0] = A[1] rg[0] = A[N - 2] lg[1] = A[0] rg[1] = A[N - 1] # print(lg, rg) for i in range(1, N - 1): # print(i) lg[i + 1] = gcd(lg[i], A[i]) # print(lg[i], A[i]) rg[i + 1] = gcd(rg[i], A[N - 1 - i]) # print(rg[N-1-i], A[N-1-i]) # print(lg, rg) for i in range(N): # print(i, lg[i], rg[N-i-1]) tmp = gcd(lg[i], rg[N - i - 1]) # print(tmp) if ans < tmp: ans = tmp # print(ans) # In[6]: print(ans) # In[ ]: """ [42 54 69 92 12 23]のとき 1 [54 69 92 12 23]の最大公約数 2 [42 69 92 12 23] 3 [42 54 92 12 23] 4 [42 54 69 12 23] """
# coding: utf-8 # In[1]: import sys input = sys.stdin.readline N = int(eval(input())) A = list(map(int, input().split())) # In[2]: # import copy # import numpy as np try: from fractions import gcd except: from math import gcd # In[ ]: # 左からn個の最大公約数を求める O(n) # 右からn個の最大公約数を求める O(n) # n個目を抜いた最大公約数は n-1個目までの公約数とn+1個目からの公約数との公約数 # In[3]: lg = [1] * (N) rg = [1] * (N) ans = 0 # In[4]: # print(lg) # print(rg) # print(A) # In[ ]: lg[0] = A[1] rg[0] = A[N - 2] lg[1] = A[0] rg[1] = A[N - 1] # print(lg, rg) for i in range(1, N - 1): # print(i) lg[i + 1] = gcd(lg[i], A[i]) # print(lg[i], A[i]) rg[i + 1] = gcd(rg[i], A[N - 1 - i]) # print(rg[N-1-i], A[N-1-i]) # print(lg, rg) # ans = [0]*N ans = [gcd(lg[i], rg[N - 1 - i]) for i in range(N)] # for i in range(N): # print(i, lg[i], rg[N-i-1]) # ans = gcd(lg[i], rg[N-i-1]) print((max(ans))) # In[6]: # print(ans)
false
15.853659
[ "-# In[5]:", "+# In[ ]:", "-for i in range(N):", "- # print(i, lg[i], rg[N-i-1])", "- tmp = gcd(lg[i], rg[N - i - 1])", "- # print(tmp)", "- if ans < tmp:", "- ans = tmp", "- # print(ans)", "+# ans = [0]*N", "+ans = [gcd(lg[i], rg[N - 1 - i]) for i in range(N)]", "+# for i in range(N):", "+# print(i, lg[i], rg[N-i-1])", "+# ans = gcd(lg[i], rg[N-i-1])", "+print((max(ans)))", "-print(ans)", "-# In[ ]:", "-\"\"\"", "-[42 54 69 92 12 23]のとき", "- 1 [54 69 92 12 23]の最大公約数", "- 2 [42 69 92 12 23]", "- 3 [42 54 92 12 23]", "- 4 [42 54 69 12 23]", "-\"\"\"", "+# print(ans)" ]
false
0.044087
0.046635
0.945361
[ "s210412298", "s761735546" ]
u227082700
p02913
python
s461819450
s989714186
422
354
270,408
270,404
Accepted
Accepted
16.11
n=int(eval(input())) s=eval(input()) dp=[(n+1)*[0]for _ in range(n+1)] for i in range(1,n): for j in range(i+1,n+1): if s[i-1]==s[j-1]: dp[i][j]=dp[i-1][j-1]+1 dp[i][j]=min(dp[i][j],i,j-i) print((max(max(i)for i in dp)))
n=int(eval(input())) s=eval(input()) dp=[(n+1)*[0]for _ in range(n+1)] ans=0 for i in range(1,n): for j in range(i+1,n+1): if s[i-1]==s[j-1]: dp[i][j]=min(dp[i-1][j-1]+1,j-i) ans=max(ans,dp[i][j]) print(ans)
9
10
246
240
n = int(eval(input())) s = eval(input()) dp = [(n + 1) * [0] for _ in range(n + 1)] for i in range(1, n): for j in range(i + 1, n + 1): if s[i - 1] == s[j - 1]: dp[i][j] = dp[i - 1][j - 1] + 1 dp[i][j] = min(dp[i][j], i, j - i) print((max(max(i) for i in dp)))
n = int(eval(input())) s = eval(input()) dp = [(n + 1) * [0] for _ in range(n + 1)] ans = 0 for i in range(1, n): for j in range(i + 1, n + 1): if s[i - 1] == s[j - 1]: dp[i][j] = min(dp[i - 1][j - 1] + 1, j - i) ans = max(ans, dp[i][j]) print(ans)
false
10
[ "+ans = 0", "- dp[i][j] = dp[i - 1][j - 1] + 1", "- dp[i][j] = min(dp[i][j], i, j - i)", "-print((max(max(i) for i in dp)))", "+ dp[i][j] = min(dp[i - 1][j - 1] + 1, j - i)", "+ ans = max(ans, dp[i][j])", "+print(ans)" ]
false
0.042901
0.043944
0.976282
[ "s461819450", "s989714186" ]
u472696272
p02831
python
s829233671
s581351521
26
17
3,060
2,940
Accepted
Accepted
34.62
num1, num2 = list(map(int, input().split())) import math def gcd(num1, num2): for i in range(min(num1, num2),0,-1): if num1%i==0 and num2%i==0: return i print((int(num1*num2/gcd(num1,num2))))
a,b = list(map(int,input().split())) def euclid(num1,num2): if num1<num2: num1,num2 = num2,num1 while num2>0: r = num1%num2 num1 = num2 num2 = r return num1 gcd = euclid(a,b) lcm = int(a*b/gcd) print(lcm)
9
13
209
231
num1, num2 = list(map(int, input().split())) import math def gcd(num1, num2): for i in range(min(num1, num2), 0, -1): if num1 % i == 0 and num2 % i == 0: return i print((int(num1 * num2 / gcd(num1, num2))))
a, b = list(map(int, input().split())) def euclid(num1, num2): if num1 < num2: num1, num2 = num2, num1 while num2 > 0: r = num1 % num2 num1 = num2 num2 = r return num1 gcd = euclid(a, b) lcm = int(a * b / gcd) print(lcm)
false
30.769231
[ "-num1, num2 = list(map(int, input().split()))", "-import math", "+a, b = list(map(int, input().split()))", "-def gcd(num1, num2):", "- for i in range(min(num1, num2), 0, -1):", "- if num1 % i == 0 and num2 % i == 0:", "- return i", "+def euclid(num1, num2):", "+ if num1 < num2:", "+ num1, num2 = num2, num1", "+ while num2 > 0:", "+ r = num1 % num2", "+ num1 = num2", "+ num2 = r", "+ return num1", "-print((int(num1 * num2 / gcd(num1, num2))))", "+gcd = euclid(a, b)", "+lcm = int(a * b / gcd)", "+print(lcm)" ]
false
0.03981
0.073505
0.541592
[ "s829233671", "s581351521" ]
u261103969
p02819
python
s466511787
s833770889
383
20
8,600
3,060
Accepted
Accepted
94.78
n = int(eval(input())) const = 10**5+100 a = [i for i in range(2,const+1)] prime = [] for i in a: prime.append(i) if i > int(n**0.5): break a = [j for j in a if j % i != 0] prime += a ans = [i for i in a if i >= n][0] print(ans)
import sys n = int(eval(input())) while True: for i in range(2, int(n**0.5+1)): if n % i == 0: break else: print(n) sys.exit() n = n + 1
19
13
267
193
n = int(eval(input())) const = 10**5 + 100 a = [i for i in range(2, const + 1)] prime = [] for i in a: prime.append(i) if i > int(n**0.5): break a = [j for j in a if j % i != 0] prime += a ans = [i for i in a if i >= n][0] print(ans)
import sys n = int(eval(input())) while True: for i in range(2, int(n**0.5 + 1)): if n % i == 0: break else: print(n) sys.exit() n = n + 1
false
31.578947
[ "+import sys", "+", "-const = 10**5 + 100", "-a = [i for i in range(2, const + 1)]", "-prime = []", "-for i in a:", "- prime.append(i)", "- if i > int(n**0.5):", "- break", "- a = [j for j in a if j % i != 0]", "-prime += a", "-ans = [i for i in a if i >= n][0]", "-print(ans)", "+while True:", "+ for i in range(2, int(n**0.5 + 1)):", "+ if n % i == 0:", "+ break", "+ else:", "+ print(n)", "+ sys.exit()", "+ n = n + 1" ]
false
0.116401
0.036375
3.200003
[ "s466511787", "s833770889" ]
u260216890
p02713
python
s347049059
s519179079
80
59
67,728
61,812
Accepted
Accepted
26.25
k = int(eval(input())) from math import gcd ans=0 for i in range(k): ans+=i+1 for j in range(i+1, k): x=gcd(i+1,j+1) ans+=6*gcd(i+1,j+1) for l in range(j+1, k): ans+=6*gcd(x,l+1) print(ans)
n=3 k=int(eval(input())) INF=10**9+7 l=[0]*k ans=0 for i in range(k-1,-1,-1): x=i+1 temp=pow(k//x,n,INF) for j in range(2,k//x+1): temp=(temp-l[j*x-1])%INF l[i]=temp ans=(ans+x*temp)%INF print(ans)
12
14
240
234
k = int(eval(input())) from math import gcd ans = 0 for i in range(k): ans += i + 1 for j in range(i + 1, k): x = gcd(i + 1, j + 1) ans += 6 * gcd(i + 1, j + 1) for l in range(j + 1, k): ans += 6 * gcd(x, l + 1) print(ans)
n = 3 k = int(eval(input())) INF = 10**9 + 7 l = [0] * k ans = 0 for i in range(k - 1, -1, -1): x = i + 1 temp = pow(k // x, n, INF) for j in range(2, k // x + 1): temp = (temp - l[j * x - 1]) % INF l[i] = temp ans = (ans + x * temp) % INF print(ans)
false
14.285714
[ "+n = 3", "-from math import gcd", "-", "+INF = 10**9 + 7", "+l = [0] * k", "-for i in range(k):", "- ans += i + 1", "- for j in range(i + 1, k):", "- x = gcd(i + 1, j + 1)", "- ans += 6 * gcd(i + 1, j + 1)", "- for l in range(j + 1, k):", "- ans += 6 * gcd(x, l + 1)", "+for i in range(k - 1, -1, -1):", "+ x = i + 1", "+ temp = pow(k // x, n, INF)", "+ for j in range(2, k // x + 1):", "+ temp = (temp - l[j * x - 1]) % INF", "+ l[i] = temp", "+ ans = (ans + x * temp) % INF" ]
false
0.102523
0.085638
1.197175
[ "s347049059", "s519179079" ]
u054825571
p02572
python
s459899825
s773938065
136
121
94,332
94,248
Accepted
Accepted
11.03
MOD=10**9+7 N=int(eval(input())) A=list(map(int,input().split())) a_sum=sum(A)%MOD ans=0 for a in A: a_sum-=a%MOD ans+=a_sum*a ans%=MOD print(ans)
MOD=10**9+7 N=int(eval(input())) A=list(map(int,input().split())) ans=sum(A)**2 ans-=sum([x**2 for x in A]) ans//=2 print((ans%MOD))
10
7
161
135
MOD = 10**9 + 7 N = int(eval(input())) A = list(map(int, input().split())) a_sum = sum(A) % MOD ans = 0 for a in A: a_sum -= a % MOD ans += a_sum * a ans %= MOD print(ans)
MOD = 10**9 + 7 N = int(eval(input())) A = list(map(int, input().split())) ans = sum(A) ** 2 ans -= sum([x**2 for x in A]) ans //= 2 print((ans % MOD))
false
30
[ "-a_sum = sum(A) % MOD", "-ans = 0", "-for a in A:", "- a_sum -= a % MOD", "- ans += a_sum * a", "- ans %= MOD", "-print(ans)", "+ans = sum(A) ** 2", "+ans -= sum([x**2 for x in A])", "+ans //= 2", "+print((ans % MOD))" ]
false
0.046599
0.113737
0.409711
[ "s459899825", "s773938065" ]
u766684188
p02834
python
s619800600
s996244420
817
597
104,352
85,844
Accepted
Accepted
26.93
import sys input=sys.stdin.readline from collections import deque class LCA: def __init__(self,v,Edges,root=0): self.v=v self.Edges=Edges self.maxLog=18 self.Parent=[[-1]*v for _ in range(self.maxLog+1)] self.Depth=[0]*v self.__bfs(root) for i in range(self.maxLog): for j in range(v): if self.Parent[i][j]!=-1: self.Parent[i+1][j]=self.Parent[i][self.Parent[i][j]] def __bfs(self,root): Visited=[False]*self.v Visited[root]=True q=deque([root]) while q: fr=q.pop() for to in self.Edges[fr]: if Visited[to]: continue self.Parent[0][to]=fr self.Depth[to]=self.Depth[fr]+1 Visited[to]=True q.append(to) def lca(self,a,b): if self.Depth[a]>self.Depth[b]: a,b=b,a for i in range(self.maxLog): if (self.Depth[b]-self.Depth[a])&(1<<i): b=self.Parent[i][b] if a==b: return b for i in reversed(list(range(self.maxLog-1))): if self.Parent[i][a]!=self.Parent[i][b]: a=self.Parent[i][a] b=self.Parent[i][b] return self.Parent[0][a] def dist(self,a,b): lca=self.lca(a,b) return self.Depth[a]+self.Depth[b]-2*self.Depth[lca] def main(): n,u,v=list(map(int,input().split())) u-=1; v-=1 Edges=[[] for _ in range(n)] for _ in range(n-1): x,y=[int(i)-1 for i in input().split()] Edges[x].append(y) Edges[y].append(x) L=[] for i in range(n): if len(Edges[i])==1: L.append(i) lca=LCA(n,Edges,v) dist=lca.dist(u,v) ans=dist//2 for l in L: m=lca.lca(u,l) if lca.dist(u,m)>=lca.dist(v,m): continue d_u=lca.dist(u,l) d_v=lca.dist(v,l) d=d_v-d_u cnt=d-1 ans=max(ans,d_u+cnt) print(ans) if __name__=='__main__': main()
import sys input=sys.stdin.readline from collections import deque class LCA: def __init__(self,v,Edges,root=0): self.v=v self.Edges=Edges self.maxLog=18 self.Parent=[[-1]*v for _ in range(self.maxLog+1)] self.Depth=[0]*v self.__bfs(root) for i in range(self.maxLog): for j in range(v): if self.Parent[i][j]!=-1: self.Parent[i+1][j]=self.Parent[i][self.Parent[i][j]] def __bfs(self,root): Visited=[False]*self.v Visited[root]=True q=deque([root]) while q: fr=q.pop() for to in self.Edges[fr]: if Visited[to]: continue self.Parent[0][to]=fr self.Depth[to]=self.Depth[fr]+1 Visited[to]=True q.append(to) def lca(self,a,b): if self.Depth[a]>self.Depth[b]: a,b=b,a for i in range(self.maxLog): if (self.Depth[b]-self.Depth[a])&(1<<i): b=self.Parent[i][b] if a==b: return b for i in reversed(list(range(self.maxLog-1))): if self.Parent[i][a]!=self.Parent[i][b]: a=self.Parent[i][a] b=self.Parent[i][b] return self.Parent[0][a] def dist(self,a,b): lca=self.lca(a,b) return self.Depth[a]+self.Depth[b]-2*self.Depth[lca] def main(): n,u,v=list(map(int,input().split())) u-=1; v-=1 Edges=[[] for _ in range(n)] for _ in range(n-1): x,y=[int(i)-1 for i in input().split()] Edges[x].append(y) Edges[y].append(x) L=[] for i in range(n): if len(Edges[i])==1: L.append(i) lca=LCA(n,Edges,v) ans=0 for l in L: if lca.dist(u,l)>=lca.dist(v,l): continue ans=max(ans,lca.dist(v,l)-1) print(ans) if __name__=='__main__': main()
74
68
2,153
2,017
import sys input = sys.stdin.readline from collections import deque class LCA: def __init__(self, v, Edges, root=0): self.v = v self.Edges = Edges self.maxLog = 18 self.Parent = [[-1] * v for _ in range(self.maxLog + 1)] self.Depth = [0] * v self.__bfs(root) for i in range(self.maxLog): for j in range(v): if self.Parent[i][j] != -1: self.Parent[i + 1][j] = self.Parent[i][self.Parent[i][j]] def __bfs(self, root): Visited = [False] * self.v Visited[root] = True q = deque([root]) while q: fr = q.pop() for to in self.Edges[fr]: if Visited[to]: continue self.Parent[0][to] = fr self.Depth[to] = self.Depth[fr] + 1 Visited[to] = True q.append(to) def lca(self, a, b): if self.Depth[a] > self.Depth[b]: a, b = b, a for i in range(self.maxLog): if (self.Depth[b] - self.Depth[a]) & (1 << i): b = self.Parent[i][b] if a == b: return b for i in reversed(list(range(self.maxLog - 1))): if self.Parent[i][a] != self.Parent[i][b]: a = self.Parent[i][a] b = self.Parent[i][b] return self.Parent[0][a] def dist(self, a, b): lca = self.lca(a, b) return self.Depth[a] + self.Depth[b] - 2 * self.Depth[lca] def main(): n, u, v = list(map(int, input().split())) u -= 1 v -= 1 Edges = [[] for _ in range(n)] for _ in range(n - 1): x, y = [int(i) - 1 for i in input().split()] Edges[x].append(y) Edges[y].append(x) L = [] for i in range(n): if len(Edges[i]) == 1: L.append(i) lca = LCA(n, Edges, v) dist = lca.dist(u, v) ans = dist // 2 for l in L: m = lca.lca(u, l) if lca.dist(u, m) >= lca.dist(v, m): continue d_u = lca.dist(u, l) d_v = lca.dist(v, l) d = d_v - d_u cnt = d - 1 ans = max(ans, d_u + cnt) print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline from collections import deque class LCA: def __init__(self, v, Edges, root=0): self.v = v self.Edges = Edges self.maxLog = 18 self.Parent = [[-1] * v for _ in range(self.maxLog + 1)] self.Depth = [0] * v self.__bfs(root) for i in range(self.maxLog): for j in range(v): if self.Parent[i][j] != -1: self.Parent[i + 1][j] = self.Parent[i][self.Parent[i][j]] def __bfs(self, root): Visited = [False] * self.v Visited[root] = True q = deque([root]) while q: fr = q.pop() for to in self.Edges[fr]: if Visited[to]: continue self.Parent[0][to] = fr self.Depth[to] = self.Depth[fr] + 1 Visited[to] = True q.append(to) def lca(self, a, b): if self.Depth[a] > self.Depth[b]: a, b = b, a for i in range(self.maxLog): if (self.Depth[b] - self.Depth[a]) & (1 << i): b = self.Parent[i][b] if a == b: return b for i in reversed(list(range(self.maxLog - 1))): if self.Parent[i][a] != self.Parent[i][b]: a = self.Parent[i][a] b = self.Parent[i][b] return self.Parent[0][a] def dist(self, a, b): lca = self.lca(a, b) return self.Depth[a] + self.Depth[b] - 2 * self.Depth[lca] def main(): n, u, v = list(map(int, input().split())) u -= 1 v -= 1 Edges = [[] for _ in range(n)] for _ in range(n - 1): x, y = [int(i) - 1 for i in input().split()] Edges[x].append(y) Edges[y].append(x) L = [] for i in range(n): if len(Edges[i]) == 1: L.append(i) lca = LCA(n, Edges, v) ans = 0 for l in L: if lca.dist(u, l) >= lca.dist(v, l): continue ans = max(ans, lca.dist(v, l) - 1) print(ans) if __name__ == "__main__": main()
false
8.108108
[ "- dist = lca.dist(u, v)", "- ans = dist // 2", "+ ans = 0", "- m = lca.lca(u, l)", "- if lca.dist(u, m) >= lca.dist(v, m):", "+ if lca.dist(u, l) >= lca.dist(v, l):", "- d_u = lca.dist(u, l)", "- d_v = lca.dist(v, l)", "- d = d_v - d_u", "- cnt = d - 1", "- ans = max(ans, d_u + cnt)", "+ ans = max(ans, lca.dist(v, l) - 1)" ]
false
0.044575
0.157473
0.283062
[ "s619800600", "s996244420" ]
u086566114
p02412
python
s898141968
s748955745
100
40
6,332
6,376
Accepted
Accepted
60
def get_num(n, x): ans = 0 for n3 in range(min(n, x), (x + 2) / 3, -1): for n2 in range(n3 - 1, (x - n3 + 1) / 2 - 1, -1): for n1 in range(n2 - 1, 0, -1): if n1 + n2 + n3 == x: ans += 1 break return ans data = [] while True: [n, x] = [int(m) for m in input().split()] if [n, x] == [0, 0]: break if x < 3: data.append(0) # print(0) else: data.append(get_num(n, x)) # print(get_num(n, x)) for n in data: print(n)
def get_num(n, x): ans = 0 for n3 in range(min(n, x), (x + 2) / 3, -1): for n2 in range(min(n3 - 1, x - n3), (x - n3 + 1) / 2 - 1, -1): for n1 in range(n2 - 1, 0, -1): if n1 + n2 + n3 == x: ans += 1 break return ans data = [] while True: [n, x] = [int(m) for m in input().split()] if [n, x] == [0, 0]: break if x < 3: data.append(0) # print(0) else: data.append(get_num(n, x)) # print(get_num(n, x)) for n in data: print(n)
25
25
589
602
def get_num(n, x): ans = 0 for n3 in range(min(n, x), (x + 2) / 3, -1): for n2 in range(n3 - 1, (x - n3 + 1) / 2 - 1, -1): for n1 in range(n2 - 1, 0, -1): if n1 + n2 + n3 == x: ans += 1 break return ans data = [] while True: [n, x] = [int(m) for m in input().split()] if [n, x] == [0, 0]: break if x < 3: data.append(0) # print(0) else: data.append(get_num(n, x)) # print(get_num(n, x)) for n in data: print(n)
def get_num(n, x): ans = 0 for n3 in range(min(n, x), (x + 2) / 3, -1): for n2 in range(min(n3 - 1, x - n3), (x - n3 + 1) / 2 - 1, -1): for n1 in range(n2 - 1, 0, -1): if n1 + n2 + n3 == x: ans += 1 break return ans data = [] while True: [n, x] = [int(m) for m in input().split()] if [n, x] == [0, 0]: break if x < 3: data.append(0) # print(0) else: data.append(get_num(n, x)) # print(get_num(n, x)) for n in data: print(n)
false
0
[ "- for n2 in range(n3 - 1, (x - n3 + 1) / 2 - 1, -1):", "+ for n2 in range(min(n3 - 1, x - n3), (x - n3 + 1) / 2 - 1, -1):" ]
false
0.046697
0.043545
1.07239
[ "s898141968", "s748955745" ]
u952708174
p02691
python
s228980844
s361168121
336
172
35,296
50,892
Accepted
Accepted
48.81
def e_this_message_will_self_destruct_in_5s(): from bisect import bisect_left N = int(eval(input())) A = [int(i) for i in input().split()] add = [j + a for j, a in enumerate(A, 1)] diff = sorted([k - a for k, a in enumerate(A, 1)]) ans = 0 for p in add: ans += bisect_left(diff, p + 1) - bisect_left(diff, p) return ans print((e_this_message_will_self_destruct_in_5s()))
def e_this_message_will_self_destruct_in_5s(): from collections import Counter N = int(eval(input())) A = [int(i) for i in input().split()] add = [j + a for j, a in enumerate(A, 1)] diff = [k - a for k, a in enumerate(A, 1)] count = Counter(diff) return sum([count[p] for p in add]) print((e_this_message_will_self_destruct_in_5s()))
13
11
416
365
def e_this_message_will_self_destruct_in_5s(): from bisect import bisect_left N = int(eval(input())) A = [int(i) for i in input().split()] add = [j + a for j, a in enumerate(A, 1)] diff = sorted([k - a for k, a in enumerate(A, 1)]) ans = 0 for p in add: ans += bisect_left(diff, p + 1) - bisect_left(diff, p) return ans print((e_this_message_will_self_destruct_in_5s()))
def e_this_message_will_self_destruct_in_5s(): from collections import Counter N = int(eval(input())) A = [int(i) for i in input().split()] add = [j + a for j, a in enumerate(A, 1)] diff = [k - a for k, a in enumerate(A, 1)] count = Counter(diff) return sum([count[p] for p in add]) print((e_this_message_will_self_destruct_in_5s()))
false
15.384615
[ "- from bisect import bisect_left", "+ from collections import Counter", "- diff = sorted([k - a for k, a in enumerate(A, 1)])", "- ans = 0", "- for p in add:", "- ans += bisect_left(diff, p + 1) - bisect_left(diff, p)", "- return ans", "+ diff = [k - a for k, a in enumerate(A, 1)]", "+ count = Counter(diff)", "+ return sum([count[p] for p in add])" ]
false
0.052115
0.035529
1.466842
[ "s228980844", "s361168121" ]
u593567568
p02769
python
s762057362
s991159864
1,996
1,660
51,516
28,044
Accepted
Accepted
16.83
import sys import numpy as np sys.setrecursionlimit(10 ** 7) # Wrong Answer # WA N, K = list(map(int, input().split())) MOD = 10 ** 9 + 7 # 階乗、Combinationコンビネーション(numpyを使う) def cumprod(arr, MOD): L = len(arr) Lsq = int(L**.5+1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n-1] arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n-1, -1] arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD-2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10**6 fact, fact_inv = make_fact(U, MOD) def mod_comb_k(n, k, mod): return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod ans = 0 for i in range(N): if K < i: continue if N - 1 <= K: ans = mod_comb_k(N + N - 1, N - 1, MOD) break if i == 0: ans += 1 continue ''' a = mod_comb_k(N - 1, i, MOD) b = mod_comb_k(N, i, MOD) c = a * b c %= MOD ''' a = mod_comb_k(N - 1, i, MOD) b = mod_comb_k(N, i, MOD) c = a * b % MOD ans += c ans %= MOD print(ans)
import sys import numpy as np sys.setrecursionlimit(10 ** 7) # Wrong Answer # WA N, K = list(map(int, input().split())) MOD = 10 ** 9 + 7 # 階乗、Combinationコンビネーション(numpyを使う) def cumprod(arr, MOD): L = len(arr) Lsq = int(L**.5+1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n-1] arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n-1, -1] arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD-2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10**6 fact, fact_inv = make_fact(N*2+10, MOD) def mod_comb_k(n, k, mod): return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod ans = 0 for i in range(N): if K < i: continue if N - 1 <= K: ans = mod_comb_k(N + N - 1, N - 1, MOD) break if i == 0: ans += 1 continue a = int(mod_comb_k(N - 1, i, MOD)) * int(mod_comb_k(N, i, MOD)) a %= MOD ans += a ans %= MOD ''' a = int(fact[N]) * int(fact_inv[i]) % MOD * int(fact_inv[N - 1]) a = a * int(fact[N-1]) % MOD * int(fact_inv[i]) % MOD * \ int(fact_inv[N-i-1]) % MOD ans = (a + ans) % MOD ''' print(ans)
71
71
1,365
1,469
import sys import numpy as np sys.setrecursionlimit(10**7) # Wrong Answer # WA N, K = list(map(int, input().split())) MOD = 10**9 + 7 # 階乗、Combinationコンビネーション(numpyを使う) def cumprod(arr, MOD): L = len(arr) Lsq = int(L**0.5 + 1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n - 1] arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n - 1, -1] arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10**6 fact, fact_inv = make_fact(U, MOD) def mod_comb_k(n, k, mod): return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod ans = 0 for i in range(N): if K < i: continue if N - 1 <= K: ans = mod_comb_k(N + N - 1, N - 1, MOD) break if i == 0: ans += 1 continue """ a = mod_comb_k(N - 1, i, MOD) b = mod_comb_k(N, i, MOD) c = a * b c %= MOD """ a = mod_comb_k(N - 1, i, MOD) b = mod_comb_k(N, i, MOD) c = a * b % MOD ans += c ans %= MOD print(ans)
import sys import numpy as np sys.setrecursionlimit(10**7) # Wrong Answer # WA N, K = list(map(int, input().split())) MOD = 10**9 + 7 # 階乗、Combinationコンビネーション(numpyを使う) def cumprod(arr, MOD): L = len(arr) Lsq = int(L**0.5 + 1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n - 1] arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n - 1, -1] arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10**6 fact, fact_inv = make_fact(N * 2 + 10, MOD) def mod_comb_k(n, k, mod): return fact[n] * fact_inv[k] % mod * fact_inv[n - k] % mod ans = 0 for i in range(N): if K < i: continue if N - 1 <= K: ans = mod_comb_k(N + N - 1, N - 1, MOD) break if i == 0: ans += 1 continue a = int(mod_comb_k(N - 1, i, MOD)) * int(mod_comb_k(N, i, MOD)) a %= MOD ans += a ans %= MOD """ a = int(fact[N]) * int(fact_inv[i]) % MOD * int(fact_inv[N - 1]) a = a * int(fact[N-1]) % MOD * int(fact_inv[i]) % MOD * \ int(fact_inv[N-i-1]) % MOD ans = (a + ans) % MOD """ print(ans)
false
0
[ "-fact, fact_inv = make_fact(U, MOD)", "+fact, fact_inv = make_fact(N * 2 + 10, MOD)", "+ a = int(mod_comb_k(N - 1, i, MOD)) * int(mod_comb_k(N, i, MOD))", "+ a %= MOD", "+ ans += a", "+ ans %= MOD", "- a = mod_comb_k(N - 1, i, MOD)", "- b = mod_comb_k(N, i, MOD)", "- c = a * b", "- c %= MOD", "+ a = int(fact[N]) * int(fact_inv[i]) % MOD * int(fact_inv[N - 1])", "+ a = a * int(fact[N-1]) % MOD * int(fact_inv[i]) % MOD * \\", "+ int(fact_inv[N-i-1]) % MOD", "+ ans = (a + ans) % MOD", "- a = mod_comb_k(N - 1, i, MOD)", "- b = mod_comb_k(N, i, MOD)", "- c = a * b % MOD", "- ans += c", "- ans %= MOD" ]
false
0.397916
0.452686
0.87901
[ "s762057362", "s991159864" ]
u879870653
p02901
python
s969502292
s027587176
356
292
45,528
42,348
Accepted
Accepted
17.98
import sys #input = sys.stdin.readline INF = 10**12 N,M = list(map(int,input().split())) K = [] for i in range(M) : a,b = list(map(int,input().split())) s = 0 #setをbitで管理. cx = list(map(int,input().split())) for c in cx : s = s | (1 << (c-1)) #setの和集合 K.append([s, a]) #dp[bit]: 集合=bit のときのコストの最小値 dp = [INF]*(1 << N) dp[0] = 0 for bit in range(1 << N) : for i in range(M) : s,a = K[i] t = bit | s cost = dp[bit] + a dp[t] = min(dp[t], cost) ans = -1 if dp[-1] == INF else dp[-1] print(ans)
import sys input = sys.stdin.readline INF = 10**12 N,M = list(map(int,input().split())) K = [] for i in range(M) : a,b = list(map(int,input().split())) s = 0 #setをbitで管理. cx = list(map(int,input().split())) for c in cx : s = s | (1 << (c-1)) #setの和集合 K.append([s, a]) #dp[bit]: 集合=bit のときのコストの最小値 dp = [INF]*(1 << N) dp[0] = 0 for bit in range(1 << N) : for i in range(M) : s,a = K[i] t = bit | s cost = dp[bit] + a dp[t] = min(dp[t], cost) ans = -1 if dp[-1] == INF else dp[-1] print(ans)
27
27
573
572
import sys # input = sys.stdin.readline INF = 10**12 N, M = list(map(int, input().split())) K = [] for i in range(M): a, b = list(map(int, input().split())) s = 0 # setをbitで管理. cx = list(map(int, input().split())) for c in cx: s = s | (1 << (c - 1)) # setの和集合 K.append([s, a]) # dp[bit]: 集合=bit のときのコストの最小値 dp = [INF] * (1 << N) dp[0] = 0 for bit in range(1 << N): for i in range(M): s, a = K[i] t = bit | s cost = dp[bit] + a dp[t] = min(dp[t], cost) ans = -1 if dp[-1] == INF else dp[-1] print(ans)
import sys input = sys.stdin.readline INF = 10**12 N, M = list(map(int, input().split())) K = [] for i in range(M): a, b = list(map(int, input().split())) s = 0 # setをbitで管理. cx = list(map(int, input().split())) for c in cx: s = s | (1 << (c - 1)) # setの和集合 K.append([s, a]) # dp[bit]: 集合=bit のときのコストの最小値 dp = [INF] * (1 << N) dp[0] = 0 for bit in range(1 << N): for i in range(M): s, a = K[i] t = bit | s cost = dp[bit] + a dp[t] = min(dp[t], cost) ans = -1 if dp[-1] == INF else dp[-1] print(ans)
false
0
[ "-# input = sys.stdin.readline", "+input = sys.stdin.readline" ]
false
0.036336
0.038336
0.947818
[ "s969502292", "s027587176" ]
u921168761
p03659
python
s112852880
s993161393
232
207
24,812
28,652
Accepted
Accepted
10.78
n = int(eval(input())) a = list(map(int, input().split())) s = [0] * (n + 1) for i in range(n): s[i + 1] = s[i] + a[i] ans = 3e9 for i in range(n - 1): ans = min(ans, abs((s[n] - s[i + 1]) - s[i + 1])) print(ans)
N=int(eval(input())) A=list(map(int,input().split())) s=[0]*(N+1) for i in range(N): s[i + 1]=s[i]+A[i] C=[0]*(N) C[0]=-s[N] x=10**10 p=0 for i in range(1, N): C[i]=C[i-1]+2*A[i-1] if x>abs(C[i]): x=abs(C[i]) p=i print(x) #print(C)
11
15
226
264
n = int(eval(input())) a = list(map(int, input().split())) s = [0] * (n + 1) for i in range(n): s[i + 1] = s[i] + a[i] ans = 3e9 for i in range(n - 1): ans = min(ans, abs((s[n] - s[i + 1]) - s[i + 1])) print(ans)
N = int(eval(input())) A = list(map(int, input().split())) s = [0] * (N + 1) for i in range(N): s[i + 1] = s[i] + A[i] C = [0] * (N) C[0] = -s[N] x = 10**10 p = 0 for i in range(1, N): C[i] = C[i - 1] + 2 * A[i - 1] if x > abs(C[i]): x = abs(C[i]) p = i print(x) # print(C)
false
26.666667
[ "-n = int(eval(input()))", "-a = list(map(int, input().split()))", "-s = [0] * (n + 1)", "-for i in range(n):", "- s[i + 1] = s[i] + a[i]", "-ans = 3e9", "-for i in range(n - 1):", "- ans = min(ans, abs((s[n] - s[i + 1]) - s[i + 1]))", "-print(ans)", "+N = int(eval(input()))", "+A = list(map(int, input().split()))", "+s = [0] * (N + 1)", "+for i in range(N):", "+ s[i + 1] = s[i] + A[i]", "+C = [0] * (N)", "+C[0] = -s[N]", "+x = 10**10", "+p = 0", "+for i in range(1, N):", "+ C[i] = C[i - 1] + 2 * A[i - 1]", "+ if x > abs(C[i]):", "+ x = abs(C[i])", "+ p = i", "+print(x)", "+# print(C)" ]
false
0.077796
0.152558
0.509943
[ "s112852880", "s993161393" ]
u341533698
p02272
python
s158303542
s541253719
4,310
3,600
54,768
54,688
Accepted
Accepted
16.47
n = int(input()) S = list(map(int, input().split())) cnt = 0 def merge(A, left, mid, right): global cnt n1 = mid - left n2 = right - mid L = [0] * (n1+1) R = [0] * (n2+1) #L[:n1] = A[left:mid] #R[:n2] = A[mid:right] for i in range(n1): L[i] = A[left + i] for i in range(n2): R[i] = A[mid + i] L[n1] = float('inf') R[n2] = float('inf') i = 0 j = 0 for k in range(left,right): if L[i] <= R[j]: A[k] = L[i] i += 1 cnt += 1 else: A[k] = R[j] j += 1 cnt += 1 return 0 def mergeSort(A, left, right): if right - left > 1: mid = int((left + right) / 2) mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) return 0 def main(): mergeSort(S, 0, len(S)) print(' '.join(map(str, S))) print(cnt) return 0 main()
n = int(input()) S = list(map(int, input().split())) cnt = 0 def merge(A, left, mid, right): global cnt n1 = mid - left n2 = right - mid L = [0] * (n1+1) R = [0] * (n2+1) L[:n1] = A[left:mid] R[:n2] = A[mid:right] #for i in xrange(n1): # L[i] = A[left + i] #for i in xrange(n2): # R[i] = A[mid + i] L[n1] = float('inf') R[n2] = float('inf') i = 0 j = 0 for k in range(left,right): if L[i] <= R[j]: A[k] = L[i] i += 1 cnt += 1 else: A[k] = R[j] j += 1 cnt += 1 return 0 def mergeSort(A, left, right): if right - left > 1: mid = int((left + right) / 2) mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) return 0 def main(): mergeSort(S, 0, len(S)) print(' '.join(map(str, S))) print(cnt) return 0 main()
46
46
994
996
n = int(input()) S = list(map(int, input().split())) cnt = 0 def merge(A, left, mid, right): global cnt n1 = mid - left n2 = right - mid L = [0] * (n1 + 1) R = [0] * (n2 + 1) # L[:n1] = A[left:mid] # R[:n2] = A[mid:right] for i in range(n1): L[i] = A[left + i] for i in range(n2): R[i] = A[mid + i] L[n1] = float("inf") R[n2] = float("inf") i = 0 j = 0 for k in range(left, right): if L[i] <= R[j]: A[k] = L[i] i += 1 cnt += 1 else: A[k] = R[j] j += 1 cnt += 1 return 0 def mergeSort(A, left, right): if right - left > 1: mid = int((left + right) / 2) mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) return 0 def main(): mergeSort(S, 0, len(S)) print(" ".join(map(str, S))) print(cnt) return 0 main()
n = int(input()) S = list(map(int, input().split())) cnt = 0 def merge(A, left, mid, right): global cnt n1 = mid - left n2 = right - mid L = [0] * (n1 + 1) R = [0] * (n2 + 1) L[:n1] = A[left:mid] R[:n2] = A[mid:right] # for i in xrange(n1): # L[i] = A[left + i] # for i in xrange(n2): # R[i] = A[mid + i] L[n1] = float("inf") R[n2] = float("inf") i = 0 j = 0 for k in range(left, right): if L[i] <= R[j]: A[k] = L[i] i += 1 cnt += 1 else: A[k] = R[j] j += 1 cnt += 1 return 0 def mergeSort(A, left, right): if right - left > 1: mid = int((left + right) / 2) mergeSort(A, left, mid) mergeSort(A, mid, right) merge(A, left, mid, right) return 0 def main(): mergeSort(S, 0, len(S)) print(" ".join(map(str, S))) print(cnt) return 0 main()
false
0
[ "- # L[:n1] = A[left:mid]", "- # R[:n2] = A[mid:right]", "- for i in range(n1):", "- L[i] = A[left + i]", "- for i in range(n2):", "- R[i] = A[mid + i]", "+ L[:n1] = A[left:mid]", "+ R[:n2] = A[mid:right]", "+ # for i in xrange(n1):", "+ # L[i] = A[left + i]", "+ # for i in xrange(n2):", "+ # R[i] = A[mid + i]" ]
false
0.043414
0.042561
1.020041
[ "s158303542", "s541253719" ]
u753803401
p03634
python
s520230446
s857744622
863
686
118,616
115,928
Accepted
Accepted
20.51
import sys import collections def solve(): input = sys.stdin.readline mod = 10 ** 9 + 7 n = int(input().rstrip('\n')) tmd = collections.defaultdict(list) tmdc = collections.defaultdict(int) for i in range(n-1): tma, tmb, tmc = list(map(int, input().rstrip('\n').split())) tmd[tma-1] += [tmb-1] tmd[tmb-1] += [tma-1] tmdc[tma-1, tmb-1] = tmc tmdc[tmb-1, tma-1] = tmc q, k = list(map(int, input().rstrip('\n').split())) ql = [[0, k-1]] ql = collections.deque(ql) fq = collections.defaultdict(int) fq[k-1] while True: if len(ql) != 0: cost, tmp = ql.popleft() for tmv in tmd[tmp]: if tmv not in fq or cost + tmdc[tmp, tmv] < fq[tmv]: ql.append([cost + tmdc[tmp, tmv], tmv]) fq[tmv] = cost + tmdc[tmp, tmv] else: break for i in range(q): x, y = list(map(int, input().rstrip('\n').split())) print((fq[x-1] + fq[y-1])) if __name__ == '__main__': solve()
import sys import collections def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 n = int(readline()) tmd = collections.defaultdict(list) cl = collections.defaultdict(int) for i in range(n-1): tma, tmb, tmc = list(map(int, readline().split())) tmd[tma-1] += [tmb-1] tmd[tmb-1] += [tma-1] cl[tma-1, tmb-1] = tmc cl[tmb-1, tma-1] = tmc q, k = list(map(int, readline().split())) ql = [[0, k-1]] ql = collections.deque(ql) fq = collections.defaultdict(int) fq[k-1] while True: if len(ql) != 0: cost, tmp = ql.popleft() for tmv in tmd[tmp]: if tmv not in fq: ql.append([cost + cl[tmv, tmp], tmv]) fq[tmv] = cost + cl[tmv, tmp] elif cost + cl[tmv, tmp] < fq[tmv]: fq[tmv] = cost + cl[tmv, tmp] else: break for i in range(q): x, y = list(map(int, readline().split())) print((fq[x-1] + fq[y-1])) if __name__ == '__main__': solve()
38
40
1,108
1,137
import sys import collections def solve(): input = sys.stdin.readline mod = 10**9 + 7 n = int(input().rstrip("\n")) tmd = collections.defaultdict(list) tmdc = collections.defaultdict(int) for i in range(n - 1): tma, tmb, tmc = list(map(int, input().rstrip("\n").split())) tmd[tma - 1] += [tmb - 1] tmd[tmb - 1] += [tma - 1] tmdc[tma - 1, tmb - 1] = tmc tmdc[tmb - 1, tma - 1] = tmc q, k = list(map(int, input().rstrip("\n").split())) ql = [[0, k - 1]] ql = collections.deque(ql) fq = collections.defaultdict(int) fq[k - 1] while True: if len(ql) != 0: cost, tmp = ql.popleft() for tmv in tmd[tmp]: if tmv not in fq or cost + tmdc[tmp, tmv] < fq[tmv]: ql.append([cost + tmdc[tmp, tmv], tmv]) fq[tmv] = cost + tmdc[tmp, tmv] else: break for i in range(q): x, y = list(map(int, input().rstrip("\n").split())) print((fq[x - 1] + fq[y - 1])) if __name__ == "__main__": solve()
import sys import collections def solve(): readline = sys.stdin.buffer.readline mod = 10**9 + 7 n = int(readline()) tmd = collections.defaultdict(list) cl = collections.defaultdict(int) for i in range(n - 1): tma, tmb, tmc = list(map(int, readline().split())) tmd[tma - 1] += [tmb - 1] tmd[tmb - 1] += [tma - 1] cl[tma - 1, tmb - 1] = tmc cl[tmb - 1, tma - 1] = tmc q, k = list(map(int, readline().split())) ql = [[0, k - 1]] ql = collections.deque(ql) fq = collections.defaultdict(int) fq[k - 1] while True: if len(ql) != 0: cost, tmp = ql.popleft() for tmv in tmd[tmp]: if tmv not in fq: ql.append([cost + cl[tmv, tmp], tmv]) fq[tmv] = cost + cl[tmv, tmp] elif cost + cl[tmv, tmp] < fq[tmv]: fq[tmv] = cost + cl[tmv, tmp] else: break for i in range(q): x, y = list(map(int, readline().split())) print((fq[x - 1] + fq[y - 1])) if __name__ == "__main__": solve()
false
5
[ "- input = sys.stdin.readline", "+ readline = sys.stdin.buffer.readline", "- n = int(input().rstrip(\"\\n\"))", "+ n = int(readline())", "- tmdc = collections.defaultdict(int)", "+ cl = collections.defaultdict(int)", "- tma, tmb, tmc = list(map(int, input().rstrip(\"\\n\").split()))", "+ tma, tmb, tmc = list(map(int, readline().split()))", "- tmdc[tma - 1, tmb - 1] = tmc", "- tmdc[tmb - 1, tma - 1] = tmc", "- q, k = list(map(int, input().rstrip(\"\\n\").split()))", "+ cl[tma - 1, tmb - 1] = tmc", "+ cl[tmb - 1, tma - 1] = tmc", "+ q, k = list(map(int, readline().split()))", "- if tmv not in fq or cost + tmdc[tmp, tmv] < fq[tmv]:", "- ql.append([cost + tmdc[tmp, tmv], tmv])", "- fq[tmv] = cost + tmdc[tmp, tmv]", "+ if tmv not in fq:", "+ ql.append([cost + cl[tmv, tmp], tmv])", "+ fq[tmv] = cost + cl[tmv, tmp]", "+ elif cost + cl[tmv, tmp] < fq[tmv]:", "+ fq[tmv] = cost + cl[tmv, tmp]", "- x, y = list(map(int, input().rstrip(\"\\n\").split()))", "+ x, y = list(map(int, readline().split()))" ]
false
0.040779
0.037128
1.098334
[ "s520230446", "s857744622" ]
u188827677
p02996
python
s067306293
s018177603
919
633
53,600
48,656
Accepted
Accepted
31.12
n = int(eval(input())) ab = [list(map(int, input().split())) for _ in range(n)] ab.sort(key=lambda i: i[1]) t = 0 for i in ab: t += i[0] if t > i[1]: print("No") exit() print("Yes")
n = int(eval(input())) ab = sorted([list(map(int, input().split())) for _ in range(n)], key = lambda i: i[1]) t = 0 for i in ab: t += i[0] if t > i[1]: print("No") exit() print("Yes")
11
10
198
199
n = int(eval(input())) ab = [list(map(int, input().split())) for _ in range(n)] ab.sort(key=lambda i: i[1]) t = 0 for i in ab: t += i[0] if t > i[1]: print("No") exit() print("Yes")
n = int(eval(input())) ab = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda i: i[1]) t = 0 for i in ab: t += i[0] if t > i[1]: print("No") exit() print("Yes")
false
9.090909
[ "-ab = [list(map(int, input().split())) for _ in range(n)]", "-ab.sort(key=lambda i: i[1])", "+ab = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda i: i[1])" ]
false
0.037196
0.036774
1.011456
[ "s067306293", "s018177603" ]
u191874006
p02793
python
s522397683
s908852533
1,062
397
71,784
52,828
Accepted
Accepted
62.62
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def gcd(a,b): if b == 0: return a else: return gcd(b,a%b) def lcm(a,b): return a*b//gcd(a,b) n = I() a = LI() l = 1 for i in range(n): l = lcm(l,a[i]) ans = 0 l %= mod for i in range(n): ans += l *pow(a[i],mod-2,mod) ans %= mod print(ans)
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append((i, cnt)) if temp!=1: arr.append((temp, 1)) if arr==[]: arr.append((n, 1)) return arr n = I() a = LI() lst = [0]*(10**6+1) for i in a: l = factorization(i) for (j,k) in l: lst[j] = max(lst[j],k) t = 1 for i in range(1,10**6+1): if lst[i] != 0: t = t*(i**lst[i]) % mod ans = 0 for i in a: ans += t*pow(i,mod-2,mod) % mod ans %= mod print(ans)
40
55
862
1,240
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) def lcm(a, b): return a * b // gcd(a, b) n = I() a = LI() l = 1 for i in range(n): l = lcm(l, a[i]) ans = 0 l %= mod for i in range(n): ans += l * pow(a[i], mod - 2, mod) ans %= mod print(ans)
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop, heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 10**9 + 7 inf = float("inf") def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append((i, cnt)) if temp != 1: arr.append((temp, 1)) if arr == []: arr.append((n, 1)) return arr n = I() a = LI() lst = [0] * (10**6 + 1) for i in a: l = factorization(i) for (j, k) in l: lst[j] = max(lst[j], k) t = 1 for i in range(1, 10**6 + 1): if lst[i] != 0: t = t * (i ** lst[i]) % mod ans = 0 for i in a: ans += t * pow(i, mod - 2, mod) % mod ans %= mod print(ans)
false
27.272727
[ "-def gcd(a, b):", "- if b == 0:", "- return a", "- else:", "- return gcd(b, a % b)", "-", "-", "-def lcm(a, b):", "- return a * b // gcd(a, b)", "+def factorization(n):", "+ arr = []", "+ temp = n", "+ for i in range(2, int(-(-(n**0.5) // 1)) + 1):", "+ if temp % i == 0:", "+ cnt = 0", "+ while temp % i == 0:", "+ cnt += 1", "+ temp //= i", "+ arr.append((i, cnt))", "+ if temp != 1:", "+ arr.append((temp, 1))", "+ if arr == []:", "+ arr.append((n, 1))", "+ return arr", "-l = 1", "-for i in range(n):", "- l = lcm(l, a[i])", "+lst = [0] * (10**6 + 1)", "+for i in a:", "+ l = factorization(i)", "+ for (j, k) in l:", "+ lst[j] = max(lst[j], k)", "+t = 1", "+for i in range(1, 10**6 + 1):", "+ if lst[i] != 0:", "+ t = t * (i ** lst[i]) % mod", "-l %= mod", "-for i in range(n):", "- ans += l * pow(a[i], mod - 2, mod)", "+for i in a:", "+ ans += t * pow(i, mod - 2, mod) % mod" ]
false
0.036504
0.442979
0.082406
[ "s522397683", "s908852533" ]
u638795007
p03111
python
s983351555
s289280984
298
192
50,416
10,588
Accepted
Accepted
35.57
def examC(): N, A, B, C = LI() L = [I() for _ in range(N)] loop = 4**N; ans = 10**9 for i in range(loop): cur = 0 curA = 0; curB = 0; curC = 0 for j in range(N): judge = (i//(4**j))%4 if judge==1: if curA>0: cur +=10 curA += L[j] elif judge==2: if curB>0: cur +=10 curB += L[j] elif judge==3: if curC>0: cur +=10 curC += L[j] if curA==0 or curB==0 or curC==0: continue cur += abs(curA-A) cur += abs(curB-B) cur += abs(curC-C) ans = min(cur,ans) print(ans) import sys,copy,bisect,itertools,heapq,math from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() mod = 10**9 + 7 inf = float('inf') if __name__ == '__main__': examC()
def examA(): N = DI()/dec(7) ans = N print(N) return def examB(): ans = 0 print(ans) return def examC(): N, A, B, C = LI() L = [I()for _ in range(N)] loop = (1<<(2*N)) ans = inf for l in range(loop): cost = 0 bamboo_A = 0 bamboo_B = 0 bamboo_C = 0 for j in range(N): if l&(1<<(2*j))>0: if l&(1<<(2*j+1))>0: cost += 10 bamboo_A += L[j] else: cost += 10 bamboo_B += L[j] else: if l&(1<<(2*j+1))>0: cost += 10 bamboo_C += L[j] if bamboo_A==0 or bamboo_B==0 or bamboo_C==0: continue cost += abs(A-bamboo_A) + abs(B-bamboo_B) + abs(C-bamboo_C) - 30 ans = min(ans,cost) print(ans) return def examD(): N = I() P = LI() O_ = [-1]*N start = P[0]-1 for i in range(N): O_[P[i]-1] = i #print(O_,start) A = [1]*N B = [1]*N for i in range(start+1,N): cur = O_[i]-O_[i-1] if cur>0: A[i] = A[i-1] + (cur+1) B[i] = B[i-1] - 1 else: A[i] = A[i-1] + 1 B[i] = B[i-1] - (-cur+1) for i in range(start)[::-1]: cur = O_[i]-O_[i+1] if cur>0: B[i] = B[i+1] + (cur+1) A[i] = A[i+1] - 1 else: B[i] = B[i+1] + 1 A[i] = A[i+1] - (-cur+1) if A[0]<1: add = (1-A[0]) for i in range(N): A[i] += add if B[-1]<1: add = (1-B[-1]) for i in range(N): B[i] += add print((" ".join(map(str,A)))) print((" ".join(map(str,B)))) return def examE(): return def examF(): ans = 0 print(ans) return from decimal import getcontext,Decimal as dec import sys,bisect,itertools,heapq,math,random from copy import deepcopy from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(eval(input())) def LI(): return list(map(int,sys.stdin.readline().split())) def DI(): return dec(eval(input())) def LDI(): return list(map(dec,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet,_ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = dec("0.000000000001") alphabet = [chr(ord('a') + i) for i in range(26)] alphabet_convert = {chr(ord('a') + i): i for i in range(26)} getcontext().prec = 28 sys.setrecursionlimit(10**7) if __name__ == '__main__': examC() """ 9 7 3 9 1 8 4 5 6 2 """
42
123
1,267
2,977
def examC(): N, A, B, C = LI() L = [I() for _ in range(N)] loop = 4**N ans = 10**9 for i in range(loop): cur = 0 curA = 0 curB = 0 curC = 0 for j in range(N): judge = (i // (4**j)) % 4 if judge == 1: if curA > 0: cur += 10 curA += L[j] elif judge == 2: if curB > 0: cur += 10 curB += L[j] elif judge == 3: if curC > 0: cur += 10 curC += L[j] if curA == 0 or curB == 0 or curC == 0: continue cur += abs(curA - A) cur += abs(curB - B) cur += abs(curC - C) ans = min(cur, ans) print(ans) import sys, copy, bisect, itertools, heapq, math from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() mod = 10**9 + 7 inf = float("inf") if __name__ == "__main__": examC()
def examA(): N = DI() / dec(7) ans = N print(N) return def examB(): ans = 0 print(ans) return def examC(): N, A, B, C = LI() L = [I() for _ in range(N)] loop = 1 << (2 * N) ans = inf for l in range(loop): cost = 0 bamboo_A = 0 bamboo_B = 0 bamboo_C = 0 for j in range(N): if l & (1 << (2 * j)) > 0: if l & (1 << (2 * j + 1)) > 0: cost += 10 bamboo_A += L[j] else: cost += 10 bamboo_B += L[j] else: if l & (1 << (2 * j + 1)) > 0: cost += 10 bamboo_C += L[j] if bamboo_A == 0 or bamboo_B == 0 or bamboo_C == 0: continue cost += abs(A - bamboo_A) + abs(B - bamboo_B) + abs(C - bamboo_C) - 30 ans = min(ans, cost) print(ans) return def examD(): N = I() P = LI() O_ = [-1] * N start = P[0] - 1 for i in range(N): O_[P[i] - 1] = i # print(O_,start) A = [1] * N B = [1] * N for i in range(start + 1, N): cur = O_[i] - O_[i - 1] if cur > 0: A[i] = A[i - 1] + (cur + 1) B[i] = B[i - 1] - 1 else: A[i] = A[i - 1] + 1 B[i] = B[i - 1] - (-cur + 1) for i in range(start)[::-1]: cur = O_[i] - O_[i + 1] if cur > 0: B[i] = B[i + 1] + (cur + 1) A[i] = A[i + 1] - 1 else: B[i] = B[i + 1] + 1 A[i] = A[i + 1] - (-cur + 1) if A[0] < 1: add = 1 - A[0] for i in range(N): A[i] += add if B[-1] < 1: add = 1 - B[-1] for i in range(N): B[i] += add print((" ".join(map(str, A)))) print((" ".join(map(str, B)))) return def examE(): return def examF(): ans = 0 print(ans) return from decimal import getcontext, Decimal as dec import sys, bisect, itertools, heapq, math, random from copy import deepcopy from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(eval(input())) def LI(): return list(map(int, sys.stdin.readline().split())) def DI(): return dec(eval(input())) def LDI(): return list(map(dec, sys.stdin.readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod, mod2, inf, alphabet, _ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = dec("0.000000000001") alphabet = [chr(ord("a") + i) for i in range(26)] alphabet_convert = {chr(ord("a") + i): i for i in range(26)} getcontext().prec = 28 sys.setrecursionlimit(10**7) if __name__ == "__main__": examC() """ 9 7 3 9 1 8 4 5 6 2 """
false
65.853659
[ "+def examA():", "+ N = DI() / dec(7)", "+ ans = N", "+ print(N)", "+ return", "+", "+", "+def examB():", "+ ans = 0", "+ print(ans)", "+ return", "+", "+", "- loop = 4**N", "- ans = 10**9", "- for i in range(loop):", "- cur = 0", "- curA = 0", "- curB = 0", "- curC = 0", "+ loop = 1 << (2 * N)", "+ ans = inf", "+ for l in range(loop):", "+ cost = 0", "+ bamboo_A = 0", "+ bamboo_B = 0", "+ bamboo_C = 0", "- judge = (i // (4**j)) % 4", "- if judge == 1:", "- if curA > 0:", "- cur += 10", "- curA += L[j]", "- elif judge == 2:", "- if curB > 0:", "- cur += 10", "- curB += L[j]", "- elif judge == 3:", "- if curC > 0:", "- cur += 10", "- curC += L[j]", "- if curA == 0 or curB == 0 or curC == 0:", "+ if l & (1 << (2 * j)) > 0:", "+ if l & (1 << (2 * j + 1)) > 0:", "+ cost += 10", "+ bamboo_A += L[j]", "+ else:", "+ cost += 10", "+ bamboo_B += L[j]", "+ else:", "+ if l & (1 << (2 * j + 1)) > 0:", "+ cost += 10", "+ bamboo_C += L[j]", "+ if bamboo_A == 0 or bamboo_B == 0 or bamboo_C == 0:", "- cur += abs(curA - A)", "- cur += abs(curB - B)", "- cur += abs(curC - C)", "- ans = min(cur, ans)", "+ cost += abs(A - bamboo_A) + abs(B - bamboo_B) + abs(C - bamboo_C) - 30", "+ ans = min(ans, cost)", "+ return", "-import sys, copy, bisect, itertools, heapq, math", "+def examD():", "+ N = I()", "+ P = LI()", "+ O_ = [-1] * N", "+ start = P[0] - 1", "+ for i in range(N):", "+ O_[P[i] - 1] = i", "+ # print(O_,start)", "+ A = [1] * N", "+ B = [1] * N", "+ for i in range(start + 1, N):", "+ cur = O_[i] - O_[i - 1]", "+ if cur > 0:", "+ A[i] = A[i - 1] + (cur + 1)", "+ B[i] = B[i - 1] - 1", "+ else:", "+ A[i] = A[i - 1] + 1", "+ B[i] = B[i - 1] - (-cur + 1)", "+ for i in range(start)[::-1]:", "+ cur = O_[i] - O_[i + 1]", "+ if cur > 0:", "+ B[i] = B[i + 1] + (cur + 1)", "+ A[i] = A[i + 1] - 1", "+ else:", "+ B[i] = B[i + 1] + 1", "+ A[i] = A[i + 1] - (-cur + 1)", "+ if A[0] < 1:", "+ add = 1 - A[0]", "+ for i in range(N):", "+ A[i] += add", "+ if B[-1] < 1:", "+ add = 1 - B[-1]", "+ for i in range(N):", "+ B[i] += add", "+ print((\" \".join(map(str, A))))", "+ print((\" \".join(map(str, B))))", "+ return", "+", "+", "+def examE():", "+ return", "+", "+", "+def examF():", "+ ans = 0", "+ print(ans)", "+ return", "+", "+", "+from decimal import getcontext, Decimal as dec", "+import sys, bisect, itertools, heapq, math, random", "+from copy import deepcopy", "+read = sys.stdin.buffer.read", "+readline = sys.stdin.buffer.readline", "+readlines = sys.stdin.buffer.readlines", "+", "- return int(sys.stdin.readline())", "+ return int(eval(input()))", "+", "+", "+def DI():", "+ return dec(eval(input()))", "+", "+", "+def LDI():", "+ return list(map(dec, sys.stdin.readline().split()))", "+global mod, mod2, inf, alphabet, _ep", "-inf = float(\"inf\")", "+mod2 = 998244353", "+inf = 10**18", "+_ep = dec(\"0.000000000001\")", "+alphabet = [chr(ord(\"a\") + i) for i in range(26)]", "+alphabet_convert = {chr(ord(\"a\") + i): i for i in range(26)}", "+getcontext().prec = 28", "+sys.setrecursionlimit(10**7)", "+\"\"\"", "+9", "+7 3 9 1 8 4 5 6 2", "+\"\"\"" ]
false
0.202483
0.16927
1.196212
[ "s983351555", "s289280984" ]
u442877951
p03568
python
s933004077
s039806615
32
29
9,100
9,128
Accepted
Accepted
9.38
N = int(eval(input())) A = list(map(int,input().split())) odd_count = 1 for a in A: if a%2 != 0: odd_count *= 1 else: odd_count *= 2 print((3**N - odd_count))
N = int(eval(input())) A = list(map(int,input().split())) odd_count = 1 for a in A: if a%2 == 0: odd_count *= 2 print((3**N - odd_count))
12
10
176
147
N = int(eval(input())) A = list(map(int, input().split())) odd_count = 1 for a in A: if a % 2 != 0: odd_count *= 1 else: odd_count *= 2 print((3**N - odd_count))
N = int(eval(input())) A = list(map(int, input().split())) odd_count = 1 for a in A: if a % 2 == 0: odd_count *= 2 print((3**N - odd_count))
false
16.666667
[ "- if a % 2 != 0:", "- odd_count *= 1", "- else:", "+ if a % 2 == 0:" ]
false
0.049039
0.049175
0.997217
[ "s933004077", "s039806615" ]
u332385682
p03818
python
s011965612
s874832079
76
63
22,636
19,316
Accepted
Accepted
17.11
import sys from collections import Counter def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG: {} -> {}'.format(name, val), file=sys.stderr) return None N = int(input()) cnt_A = Counter(map(int, input().split())) # debug(cnt_A, locals()) # debug(cnt_A.values(), locals()) dabuli = sum(cnt_A.values()) - len(cnt_A.values()) if dabuli % 2 == 0: ans = N - dabuli else: ans = N - (dabuli + 1) print(ans)
import sys def debug(x, table): for name, val in table.items(): if x is val: print('DEBUG: {} -> {}'.format(name, val), file=sys.stderr) return None N = int(input()) A = set(map(int, input().split())) # debug(A, locals()) m = len(A) if m % 2 == 0: ans = m - 1 else: ans = m print(ans)
23
20
499
352
import sys from collections import Counter def debug(x, table): for name, val in table.items(): if x is val: print("DEBUG: {} -> {}".format(name, val), file=sys.stderr) return None N = int(input()) cnt_A = Counter(map(int, input().split())) # debug(cnt_A, locals()) # debug(cnt_A.values(), locals()) dabuli = sum(cnt_A.values()) - len(cnt_A.values()) if dabuli % 2 == 0: ans = N - dabuli else: ans = N - (dabuli + 1) print(ans)
import sys def debug(x, table): for name, val in table.items(): if x is val: print("DEBUG: {} -> {}".format(name, val), file=sys.stderr) return None N = int(input()) A = set(map(int, input().split())) # debug(A, locals()) m = len(A) if m % 2 == 0: ans = m - 1 else: ans = m print(ans)
false
13.043478
[ "-from collections import Counter", "-cnt_A = Counter(map(int, input().split()))", "-# debug(cnt_A, locals())", "-# debug(cnt_A.values(), locals())", "-dabuli = sum(cnt_A.values()) - len(cnt_A.values())", "-if dabuli % 2 == 0:", "- ans = N - dabuli", "+A = set(map(int, input().split()))", "+# debug(A, locals())", "+m = len(A)", "+if m % 2 == 0:", "+ ans = m - 1", "- ans = N - (dabuli + 1)", "+ ans = m" ]
false
0.036371
0.039563
0.919309
[ "s011965612", "s874832079" ]
u077291787
p02993
python
s783861352
s460458777
19
17
2,940
2,940
Accepted
Accepted
10.53
# ABC131A - Security def main(): s = eval(input()) flg = all(s[i] != s[i + 1] for i in range(len(s) - 1)) print(("Good" if flg else "Bad")) if __name__ == "__main__": main()
# ABC131A - Security def main(): s = eval(input()) if all(i != j for i, j in zip(s, s[1:])): print("Good") else: print("Bad") if __name__ == "__main__": main()
9
11
191
198
# ABC131A - Security def main(): s = eval(input()) flg = all(s[i] != s[i + 1] for i in range(len(s) - 1)) print(("Good" if flg else "Bad")) if __name__ == "__main__": main()
# ABC131A - Security def main(): s = eval(input()) if all(i != j for i, j in zip(s, s[1:])): print("Good") else: print("Bad") if __name__ == "__main__": main()
false
18.181818
[ "- flg = all(s[i] != s[i + 1] for i in range(len(s) - 1))", "- print((\"Good\" if flg else \"Bad\"))", "+ if all(i != j for i, j in zip(s, s[1:])):", "+ print(\"Good\")", "+ else:", "+ print(\"Bad\")" ]
false
0.037616
0.070174
0.536038
[ "s783861352", "s460458777" ]
u332906195
p03476
python
s956321727
s091259306
1,167
1,019
5,732
53,196
Accepted
Accepted
12.68
def primes(N): '''Sieve of Eratosthenes''' p = [False, False] + [True] * (N - 1) for i in range(2, int(N ** 0.5) + 1): if p[i]: for j in range(i * 2, N + 1, i): p[j] = False return p p, c = primes(10 ** 5), [0] for i in range(1, 10 ** 5 + 1): c.append(c[-1] + 1 if p[i] and p[(i + 1) // 2] else c[-1]) Q = int(eval(input())) for _ in range(Q): l, r = list(map(int, input().split())) print((c[r] - c[l - 1]))
def primes(N): p = [False, False] + [True] * (N - 1) for i in range(2, int(N ** 0.5) + 1): if p[i]: for j in range(i * 2, N + 1, i): p[j] = False return p p, c = primes(10 ** 5), [0] for i in range(1, 10 ** 5 + 1): c.append(c[-1] + 1 if p[i] and p[(i + 1) // 2] else c[-1]) Q = int(eval(input())) for _ in range(Q): l, r = list(map(int, input().split())) print((c[r] - c[l - 1]))
18
17
478
445
def primes(N): """Sieve of Eratosthenes""" p = [False, False] + [True] * (N - 1) for i in range(2, int(N**0.5) + 1): if p[i]: for j in range(i * 2, N + 1, i): p[j] = False return p p, c = primes(10**5), [0] for i in range(1, 10**5 + 1): c.append(c[-1] + 1 if p[i] and p[(i + 1) // 2] else c[-1]) Q = int(eval(input())) for _ in range(Q): l, r = list(map(int, input().split())) print((c[r] - c[l - 1]))
def primes(N): p = [False, False] + [True] * (N - 1) for i in range(2, int(N**0.5) + 1): if p[i]: for j in range(i * 2, N + 1, i): p[j] = False return p p, c = primes(10**5), [0] for i in range(1, 10**5 + 1): c.append(c[-1] + 1 if p[i] and p[(i + 1) // 2] else c[-1]) Q = int(eval(input())) for _ in range(Q): l, r = list(map(int, input().split())) print((c[r] - c[l - 1]))
false
5.555556
[ "- \"\"\"Sieve of Eratosthenes\"\"\"" ]
false
0.117571
0.083516
1.407761
[ "s956321727", "s091259306" ]
u380524497
p03645
python
s454895579
s224709557
416
157
65,908
44,752
Accepted
Accepted
62.26
import sys input = sys.stdin.readline n, m = list(map(int, input().split())) edges = [set() for _ in range(n)] for _ in range(m): _from, to = list(map(int, input().split())) edges[_from-1].add(to-1) first = list(edges[0]) possible = False while first: island = first.pop() if n-1 in edges[island]: possible = True break if possible: print("POSSIBLE") else: print("IMPOSSIBLE ")
import sys buf = sys.stdin.buffer n, m = list(map(int, buf.readline().split())) AB = list(map(int, buf.read().split())) reachable_from_start = set() reachable_to_goal = set() for a, b in zip(AB,AB): if a == 1: reachable_from_start.add(b) if b == n: reachable_to_goal.add(a) possible = reachable_from_start & reachable_to_goal if possible or n in reachable_from_start: print("POSSIBLE") else: print("IMPOSSIBLE")
24
19
435
453
import sys input = sys.stdin.readline n, m = list(map(int, input().split())) edges = [set() for _ in range(n)] for _ in range(m): _from, to = list(map(int, input().split())) edges[_from - 1].add(to - 1) first = list(edges[0]) possible = False while first: island = first.pop() if n - 1 in edges[island]: possible = True break if possible: print("POSSIBLE") else: print("IMPOSSIBLE ")
import sys buf = sys.stdin.buffer n, m = list(map(int, buf.readline().split())) AB = list(map(int, buf.read().split())) reachable_from_start = set() reachable_to_goal = set() for a, b in zip(AB, AB): if a == 1: reachable_from_start.add(b) if b == n: reachable_to_goal.add(a) possible = reachable_from_start & reachable_to_goal if possible or n in reachable_from_start: print("POSSIBLE") else: print("IMPOSSIBLE")
false
20.833333
[ "-input = sys.stdin.readline", "-n, m = list(map(int, input().split()))", "-edges = [set() for _ in range(n)]", "-for _ in range(m):", "- _from, to = list(map(int, input().split()))", "- edges[_from - 1].add(to - 1)", "-first = list(edges[0])", "-possible = False", "-while first:", "- island = first.pop()", "- if n - 1 in edges[island]:", "- possible = True", "- break", "-if possible:", "+buf = sys.stdin.buffer", "+n, m = list(map(int, buf.readline().split()))", "+AB = list(map(int, buf.read().split()))", "+reachable_from_start = set()", "+reachable_to_goal = set()", "+for a, b in zip(AB, AB):", "+ if a == 1:", "+ reachable_from_start.add(b)", "+ if b == n:", "+ reachable_to_goal.add(a)", "+possible = reachable_from_start & reachable_to_goal", "+if possible or n in reachable_from_start:", "- print(\"IMPOSSIBLE \")", "+ print(\"IMPOSSIBLE\")" ]
false
0.039167
0.041825
0.93644
[ "s454895579", "s224709557" ]
u926046014
p02773
python
s058010622
s485233659
628
506
51,792
38,584
Accepted
Accepted
19.43
from collections import Counter n = int(eval(input())) s = [] for i in range(n): s.append(eval(input())) c = Counter(s) d = c.most_common() t = [] t.append(d[0]) cnt = 1 if len(d)>1: for i in range(len(d)-1): if d[i+1][1]==t[0][1]: t.append(d[i+1]) cnt+=1 else: break t= sorted(t) for i in range(cnt): print((t[i][0])) else: print((d[0][0]))
n=int(eval(input())) ar = [] for i in range(n): a = eval(input()) ar.append(a) dic = {} for i in range(n): if ar[i] not in dic: dic[ar[i]]=1 else: dic[ar[i]]+=1 highest = max(dic.values()) ans = [] for keys in list(dic.keys()): if dic[keys] == highest: ans.append(keys) ans = sorted(ans) for i in ans: print(i)
28
23
438
366
from collections import Counter n = int(eval(input())) s = [] for i in range(n): s.append(eval(input())) c = Counter(s) d = c.most_common() t = [] t.append(d[0]) cnt = 1 if len(d) > 1: for i in range(len(d) - 1): if d[i + 1][1] == t[0][1]: t.append(d[i + 1]) cnt += 1 else: break t = sorted(t) for i in range(cnt): print((t[i][0])) else: print((d[0][0]))
n = int(eval(input())) ar = [] for i in range(n): a = eval(input()) ar.append(a) dic = {} for i in range(n): if ar[i] not in dic: dic[ar[i]] = 1 else: dic[ar[i]] += 1 highest = max(dic.values()) ans = [] for keys in list(dic.keys()): if dic[keys] == highest: ans.append(keys) ans = sorted(ans) for i in ans: print(i)
false
17.857143
[ "-from collections import Counter", "-", "-s = []", "+ar = []", "- s.append(eval(input()))", "-c = Counter(s)", "-d = c.most_common()", "-t = []", "-t.append(d[0])", "-cnt = 1", "-if len(d) > 1:", "- for i in range(len(d) - 1):", "- if d[i + 1][1] == t[0][1]:", "- t.append(d[i + 1])", "- cnt += 1", "- else:", "- break", "- t = sorted(t)", "- for i in range(cnt):", "- print((t[i][0]))", "-else:", "- print((d[0][0]))", "+ a = eval(input())", "+ ar.append(a)", "+dic = {}", "+for i in range(n):", "+ if ar[i] not in dic:", "+ dic[ar[i]] = 1", "+ else:", "+ dic[ar[i]] += 1", "+highest = max(dic.values())", "+ans = []", "+for keys in list(dic.keys()):", "+ if dic[keys] == highest:", "+ ans.append(keys)", "+ans = sorted(ans)", "+for i in ans:", "+ print(i)" ]
false
0.038079
0.036804
1.034649
[ "s058010622", "s485233659" ]
u633068244
p00040
python
s406183810
s086786660
230
170
4,260
4,268
Accepted
Accepted
26.09
dict = ["a","b","c","d","e","f","g","h","i","j","k","l","m",\ "n","o","p","q","r","s","t","u","v","w","x","y","z"] lsalpha = [1,3,5,7,9,11,15,17,19,21,23,25] n = int(input()) for roop in range(n): code = input() for alpha in lsalpha: flag = 0 for beta in range(26): decode = "" for chara in code: if chara != " ": f = dict.index(chara) for i in range(26): if (alpha*i + beta)%26 == f: dechara = dict[i] break decode += dechara else: decode += " " if decode.count("that") > 0 or decode.count("this") > 0: flag = 1 break if flag == 1: break print(decode)
dict = ["a","b","c","d","e","f","g","h","i","j","k","l","m",\ "n","o","p","q","r","s","t","u","v","w","x","y","z"] lsalpha = [1,3,5,7,9,11,15,17,19,21,23,25] def decode(alpha, beta, code): msg = "" for chara in code: if chara != " ": f = dict.index(chara) for i in range(26): if (alpha*i + beta)%26 == f: dechara = dict[i] break msg += dechara else: msg += " " return msg n = int(input()) for roop in range(n): code = input() for alpha in lsalpha: flag = 0 for beta in range(26): msg = decode(alpha, beta, code) if msg.count("that") > 0 or msg.count("this") > 0: flag = 1 break if flag == 1: break print(msg)
27
31
902
895
dict = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ] lsalpha = [1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25] n = int(input()) for roop in range(n): code = input() for alpha in lsalpha: flag = 0 for beta in range(26): decode = "" for chara in code: if chara != " ": f = dict.index(chara) for i in range(26): if (alpha * i + beta) % 26 == f: dechara = dict[i] break decode += dechara else: decode += " " if decode.count("that") > 0 or decode.count("this") > 0: flag = 1 break if flag == 1: break print(decode)
dict = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ] lsalpha = [1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25] def decode(alpha, beta, code): msg = "" for chara in code: if chara != " ": f = dict.index(chara) for i in range(26): if (alpha * i + beta) % 26 == f: dechara = dict[i] break msg += dechara else: msg += " " return msg n = int(input()) for roop in range(n): code = input() for alpha in lsalpha: flag = 0 for beta in range(26): msg = decode(alpha, beta, code) if msg.count("that") > 0 or msg.count("this") > 0: flag = 1 break if flag == 1: break print(msg)
false
12.903226
[ "+", "+", "+def decode(alpha, beta, code):", "+ msg = \"\"", "+ for chara in code:", "+ if chara != \" \":", "+ f = dict.index(chara)", "+ for i in range(26):", "+ if (alpha * i + beta) % 26 == f:", "+ dechara = dict[i]", "+ break", "+ msg += dechara", "+ else:", "+ msg += \" \"", "+ return msg", "+", "+", "- decode = \"\"", "- for chara in code:", "- if chara != \" \":", "- f = dict.index(chara)", "- for i in range(26):", "- if (alpha * i + beta) % 26 == f:", "- dechara = dict[i]", "- break", "- decode += dechara", "- else:", "- decode += \" \"", "- if decode.count(\"that\") > 0 or decode.count(\"this\") > 0:", "+ msg = decode(alpha, beta, code)", "+ if msg.count(\"that\") > 0 or msg.count(\"this\") > 0:", "- print(decode)", "+ print(msg)" ]
false
0.120148
0.051162
2.348393
[ "s406183810", "s086786660" ]
u299730702
p03738
python
s040985965
s832159433
19
17
3,060
2,940
Accepted
Accepted
10.53
import math A = int(eval(input())) B = int(eval(input())) A = math.log10(A) B = math.log10(B) if A > B: print('GREATER') elif A < B: print('LESS') else: print('EQUAL')
import math A = int(eval(input())) B = int(eval(input())) #A = math.log10(A) #B = math.log10(B) if A > B: print('GREATER') elif A < B: print('LESS') else: print('EQUAL')
13
13
182
184
import math A = int(eval(input())) B = int(eval(input())) A = math.log10(A) B = math.log10(B) if A > B: print("GREATER") elif A < B: print("LESS") else: print("EQUAL")
import math A = int(eval(input())) B = int(eval(input())) # A = math.log10(A) # B = math.log10(B) if A > B: print("GREATER") elif A < B: print("LESS") else: print("EQUAL")
false
0
[ "-A = math.log10(A)", "-B = math.log10(B)", "+# A = math.log10(A)", "+# B = math.log10(B)" ]
false
0.045619
0.046961
0.971413
[ "s040985965", "s832159433" ]
u906501980
p02727
python
s368776582
s987819279
359
250
105,444
22,524
Accepted
Accepted
30.36
def main(): x, y, a, b, c = list(map(int, input().split())) al = sorted(list(map(int, input().split())), reverse=True)[:x] bl = sorted(list(map(int, input().split())), reverse=True)[:y] cl = sorted(list(map(int, input().split())), reverse=True) ans = 0 xi, yi = 0, 0 for i in cl: if al: ai = al[-1] else: ai = 10000000000 if bl: bi = bl[-1] else: bi = 10000000000 if ai < bi: if al: m = al.pop() else: m = 0 else: if bl: m = bl.pop() else: m = 0 if m < i: ans += i else: ans += m break ans += sum(al)+sum(bl) print(ans) if __name__ == "__main__": main()
def main(): x, y, a, b, c = list(map(int, input().split())) p = list(sorted(list(map(int, input().split())), reverse=True))[:x] q = list(sorted(list(map(int, input().split())), reverse=True))[:y] r = list(map(int, input().split())) print((sum(list(sorted(p+q+r, reverse=True))[:(x+y)]))) if __name__ == "__main__": main()
37
8
901
344
def main(): x, y, a, b, c = list(map(int, input().split())) al = sorted(list(map(int, input().split())), reverse=True)[:x] bl = sorted(list(map(int, input().split())), reverse=True)[:y] cl = sorted(list(map(int, input().split())), reverse=True) ans = 0 xi, yi = 0, 0 for i in cl: if al: ai = al[-1] else: ai = 10000000000 if bl: bi = bl[-1] else: bi = 10000000000 if ai < bi: if al: m = al.pop() else: m = 0 else: if bl: m = bl.pop() else: m = 0 if m < i: ans += i else: ans += m break ans += sum(al) + sum(bl) print(ans) if __name__ == "__main__": main()
def main(): x, y, a, b, c = list(map(int, input().split())) p = list(sorted(list(map(int, input().split())), reverse=True))[:x] q = list(sorted(list(map(int, input().split())), reverse=True))[:y] r = list(map(int, input().split())) print((sum(list(sorted(p + q + r, reverse=True))[: (x + y)]))) if __name__ == "__main__": main()
false
78.378378
[ "- al = sorted(list(map(int, input().split())), reverse=True)[:x]", "- bl = sorted(list(map(int, input().split())), reverse=True)[:y]", "- cl = sorted(list(map(int, input().split())), reverse=True)", "- ans = 0", "- xi, yi = 0, 0", "- for i in cl:", "- if al:", "- ai = al[-1]", "- else:", "- ai = 10000000000", "- if bl:", "- bi = bl[-1]", "- else:", "- bi = 10000000000", "- if ai < bi:", "- if al:", "- m = al.pop()", "- else:", "- m = 0", "- else:", "- if bl:", "- m = bl.pop()", "- else:", "- m = 0", "- if m < i:", "- ans += i", "- else:", "- ans += m", "- break", "- ans += sum(al) + sum(bl)", "- print(ans)", "+ p = list(sorted(list(map(int, input().split())), reverse=True))[:x]", "+ q = list(sorted(list(map(int, input().split())), reverse=True))[:y]", "+ r = list(map(int, input().split()))", "+ print((sum(list(sorted(p + q + r, reverse=True))[: (x + y)])))" ]
false
0.038083
0.037701
1.010137
[ "s368776582", "s987819279" ]
u347640436
p03160
python
s681126063
s128166114
166
131
13,908
13,928
Accepted
Accepted
21.08
n = int(eval(input())) h = list(map(int, input().split())) cost = [float('inf')] * n cost[0] = 0 for i in range(n - 2): cost[i + 1] = min(cost[i + 1], cost[i] + abs(h[i + 1] - h[i])) cost[i + 2] = min(cost[i + 2], cost[i] + abs(h[i + 2] - h[i])) cost[n - 1] = min(cost[n - 1], cost[n - 2] + abs(h[n - 1] - h[n - 2])) print((cost[n - 1]))
n = int(eval(input())) h = list(map(int, input().split())) cost = [0] * n cost[1] = abs(h[1] - h[0]) for i in range(2, n): cost[i] = min(abs(h[i] - h[i - 1]) + cost[i - 1], abs(h[i] - h[i - 2]) + cost[i - 2]) print((cost[n - 1]))
9
7
342
230
n = int(eval(input())) h = list(map(int, input().split())) cost = [float("inf")] * n cost[0] = 0 for i in range(n - 2): cost[i + 1] = min(cost[i + 1], cost[i] + abs(h[i + 1] - h[i])) cost[i + 2] = min(cost[i + 2], cost[i] + abs(h[i + 2] - h[i])) cost[n - 1] = min(cost[n - 1], cost[n - 2] + abs(h[n - 1] - h[n - 2])) print((cost[n - 1]))
n = int(eval(input())) h = list(map(int, input().split())) cost = [0] * n cost[1] = abs(h[1] - h[0]) for i in range(2, n): cost[i] = min( abs(h[i] - h[i - 1]) + cost[i - 1], abs(h[i] - h[i - 2]) + cost[i - 2] ) print((cost[n - 1]))
false
22.222222
[ "-cost = [float(\"inf\")] * n", "-cost[0] = 0", "-for i in range(n - 2):", "- cost[i + 1] = min(cost[i + 1], cost[i] + abs(h[i + 1] - h[i]))", "- cost[i + 2] = min(cost[i + 2], cost[i] + abs(h[i + 2] - h[i]))", "-cost[n - 1] = min(cost[n - 1], cost[n - 2] + abs(h[n - 1] - h[n - 2]))", "+cost = [0] * n", "+cost[1] = abs(h[1] - h[0])", "+for i in range(2, n):", "+ cost[i] = min(", "+ abs(h[i] - h[i - 1]) + cost[i - 1], abs(h[i] - h[i - 2]) + cost[i - 2]", "+ )" ]
false
0.110957
0.042552
2.607556
[ "s681126063", "s128166114" ]
u631914718
p03163
python
s401689997
s405568523
324
174
21,372
14,568
Accepted
Accepted
46.3
import numpy as np N, W = list(map(int, input().split())) ndp = np.zeros(W+1, dtype= np.int64) for _ in range(N): w, v = list(map(int,input().split())) # 離散より連続で扱った方が簡単になる。 np.maximum(ndp[:-w] + v, ndp[w:], out = ndp[w:]) print((ndp[-1])) """ https://atcoder.jp/contests/dp/submissions/6657472 より失敬。 めっちゃスマートな解法。 """
import numpy as np N,W = list(map(int,input().split())) ndp = np.zeros(W+1,dtype= np.int64) for _ in range(N): w,v = list(map(int,input().split())) np.maximum(ndp[:-w] + v, ndp[w:], out = ndp[w:]) print((ndp[-1]))
17
7
335
214
import numpy as np N, W = list(map(int, input().split())) ndp = np.zeros(W + 1, dtype=np.int64) for _ in range(N): w, v = list(map(int, input().split())) # 離散より連続で扱った方が簡単になる。 np.maximum(ndp[:-w] + v, ndp[w:], out=ndp[w:]) print((ndp[-1])) """ https://atcoder.jp/contests/dp/submissions/6657472 より失敬。 めっちゃスマートな解法。 """
import numpy as np N, W = list(map(int, input().split())) ndp = np.zeros(W + 1, dtype=np.int64) for _ in range(N): w, v = list(map(int, input().split())) np.maximum(ndp[:-w] + v, ndp[w:], out=ndp[w:]) print((ndp[-1]))
false
58.823529
[ "- # 離散より連続で扱った方が簡単になる。", "-\"\"\"", "-https://atcoder.jp/contests/dp/submissions/6657472", "-より失敬。", "-めっちゃスマートな解法。", "-\"\"\"" ]
false
0.160603
0.171184
0.93819
[ "s401689997", "s405568523" ]
u993622994
p03126
python
s126339027
s513299658
20
17
3,060
3,060
Accepted
Accepted
15
n, m = list(map(int, input().split())) ka = [list(map(int, input().split())) for i in range(n)] ans = [0] * m for i in range(n): for j in range(1, len(ka[i])): for k in range(1, m+1): if ka[i][j] == k: ans[k-1] += 1 break print((ans.count(n)))
n, m = list(map(int, input().split())) ka = [list(map(int, input().split())) for i in range(n)] ans = [0] * m for i in range(n): for j in ka[i][1:]: ans[j-1] += 1 print((ans.count(n)))
12
9
304
198
n, m = list(map(int, input().split())) ka = [list(map(int, input().split())) for i in range(n)] ans = [0] * m for i in range(n): for j in range(1, len(ka[i])): for k in range(1, m + 1): if ka[i][j] == k: ans[k - 1] += 1 break print((ans.count(n)))
n, m = list(map(int, input().split())) ka = [list(map(int, input().split())) for i in range(n)] ans = [0] * m for i in range(n): for j in ka[i][1:]: ans[j - 1] += 1 print((ans.count(n)))
false
25
[ "- for j in range(1, len(ka[i])):", "- for k in range(1, m + 1):", "- if ka[i][j] == k:", "- ans[k - 1] += 1", "- break", "+ for j in ka[i][1:]:", "+ ans[j - 1] += 1" ]
false
0.069365
0.053961
1.28547
[ "s126339027", "s513299658" ]
u301624971
p03814
python
s180653916
s365046971
31
18
3,516
3,516
Accepted
Accepted
41.94
def myAnswer(s:str) -> int: start = 0 end = 0 for n,string in enumerate(s): if(string =="A"): start = n break for n,string in enumerate(s[::-1]): if(string == "Z"): end = len(s) - n break return end - start def modelAnswer(): tmp=1 def main(): s = (eval(input())) print((myAnswer(s))) if __name__ == '__main__': main()
def myAnswer2(s:str) -> int: return len(s)-s[::-1].index("Z") - s.index("A") def main(): s = (eval(input())) print((myAnswer2(s))) if __name__ == '__main__': main()
25
9
415
178
def myAnswer(s: str) -> int: start = 0 end = 0 for n, string in enumerate(s): if string == "A": start = n break for n, string in enumerate(s[::-1]): if string == "Z": end = len(s) - n break return end - start def modelAnswer(): tmp = 1 def main(): s = eval(input()) print((myAnswer(s))) if __name__ == "__main__": main()
def myAnswer2(s: str) -> int: return len(s) - s[::-1].index("Z") - s.index("A") def main(): s = eval(input()) print((myAnswer2(s))) if __name__ == "__main__": main()
false
64
[ "-def myAnswer(s: str) -> int:", "- start = 0", "- end = 0", "- for n, string in enumerate(s):", "- if string == \"A\":", "- start = n", "- break", "- for n, string in enumerate(s[::-1]):", "- if string == \"Z\":", "- end = len(s) - n", "- break", "- return end - start", "-", "-", "-def modelAnswer():", "- tmp = 1", "+def myAnswer2(s: str) -> int:", "+ return len(s) - s[::-1].index(\"Z\") - s.index(\"A\")", "- print((myAnswer(s)))", "+ print((myAnswer2(s)))" ]
false
0.035561
0.038796
0.916605
[ "s180653916", "s365046971" ]
u680851063
p02947
python
s951248496
s715076297
551
439
20,860
11,408
Accepted
Accepted
20.33
# n = int(eval(input())) s = [] for _ in range(n): #s.append(list(input())) # !!! #s.append(sorted(list(input()))) # !!! #s.append(sorted(input())) # !!! s.append([''.join(sorted(eval(input())))]) #s += [''.join(sorted(input()))] #''.join(sorted((sorted(input())) s = sorted(s) #print(s) a = [] x = 1 for i in range(1,n): if s[i] == s[i-1]: x += 1 else: a.append(x) x = 1 else: a.append(x) #print(a) y = 0 for j in a: y += j*(j-1)/2 print((int(y)))
# 2回目のソートに気づけずTLE、納得のアルゴリズム n = int(eval(input())) s = [] for _ in range(n): #文字列の各要素をソートしリストに格納 #s.append(list(input())) # !!! #s.append(sorted(list(input()))) # !!! #s.append(sorted(input())) # !!! #s.append([''.join(sorted(input()))]) s += [''.join(sorted(eval(input())))] # appendよりも'+='の方が高速! s = sorted(s) #さらにソートして全検索を避ける #print(s) a = [] x = 1 for i in range(1,n): #隣り合う要素が重複する数をリストに格納 if s[i] == s[i-1]: x += 1 else: a.append(x) x = 1 else: a.append(x) #print(a) y = 0 for j in a: #各重複する数から各組み合わせ数を返し合算 y += j*(j-1)/2 print((int(y)))
30
29
531
620
# n = int(eval(input())) s = [] for _ in range(n): # s.append(list(input())) # !!! # s.append(sorted(list(input()))) # !!! # s.append(sorted(input())) # !!! s.append(["".join(sorted(eval(input())))]) # s += [''.join(sorted(input()))] #''.join(sorted((sorted(input())) s = sorted(s) # print(s) a = [] x = 1 for i in range(1, n): if s[i] == s[i - 1]: x += 1 else: a.append(x) x = 1 else: a.append(x) # print(a) y = 0 for j in a: y += j * (j - 1) / 2 print((int(y)))
# 2回目のソートに気づけずTLE、納得のアルゴリズム n = int(eval(input())) s = [] for _ in range(n): # 文字列の各要素をソートしリストに格納 # s.append(list(input())) # !!! # s.append(sorted(list(input()))) # !!! # s.append(sorted(input())) # !!! # s.append([''.join(sorted(input()))]) s += ["".join(sorted(eval(input())))] # appendよりも'+='の方が高速! s = sorted(s) # さらにソートして全検索を避ける # print(s) a = [] x = 1 for i in range(1, n): # 隣り合う要素が重複する数をリストに格納 if s[i] == s[i - 1]: x += 1 else: a.append(x) x = 1 else: a.append(x) # print(a) y = 0 for j in a: # 各重複する数から各組み合わせ数を返し合算 y += j * (j - 1) / 2 print((int(y)))
false
3.333333
[ "-#", "+# 2回目のソートに気づけずTLE、納得のアルゴリズム", "-for _ in range(n):", "+for _ in range(n): # 文字列の各要素をソートしリストに格納", "- s.append([\"\".join(sorted(eval(input())))])", "- # s += [''.join(sorted(input()))]", "- #''.join(sorted((sorted(input()))", "-s = sorted(s)", "+ # s.append([''.join(sorted(input()))])", "+ s += [\"\".join(sorted(eval(input())))] # appendよりも'+='の方が高速!", "+s = sorted(s) # さらにソートして全検索を避ける", "-for i in range(1, n):", "+for i in range(1, n): # 隣り合う要素が重複する数をリストに格納", "-for j in a:", "+for j in a: # 各重複する数から各組み合わせ数を返し合算" ]
false
0.03669
0.038748
0.946894
[ "s951248496", "s715076297" ]
u905895868
p03272
python
s221574635
s735672700
29
24
9,040
9,148
Accepted
Accepted
17.24
train_len, target_vehicle = list(map(int, input().split())) target_from_backside = train_len - (target_vehicle - 1) print(target_from_backside)
n, i = list(map(int, input().split())) print((n - i + 1))
4
3
142
53
train_len, target_vehicle = list(map(int, input().split())) target_from_backside = train_len - (target_vehicle - 1) print(target_from_backside)
n, i = list(map(int, input().split())) print((n - i + 1))
false
25
[ "-train_len, target_vehicle = list(map(int, input().split()))", "-target_from_backside = train_len - (target_vehicle - 1)", "-print(target_from_backside)", "+n, i = list(map(int, input().split()))", "+print((n - i + 1))" ]
false
0.037733
0.037888
0.995901
[ "s221574635", "s735672700" ]
u943057856
p03557
python
s801009350
s589827840
336
244
23,092
29,316
Accepted
Accepted
27.38
import bisect n=int(eval(input())) a=sorted(list(map(int,input().split()))) b=sorted(list(map(int,input().split()))) c=sorted(list(map(int,input().split()))) ans=0 for i in b: x=bisect.bisect_left(a,i) y=n-bisect.bisect_right(c,i) ans+=x*y print(ans)
import bisect n=int(eval(input())) a=sorted(list(map(int,input().split()))) b=sorted(list(map(int,input().split()))) c=sorted(list(map(int,input().split()))) ans=0 for i in b: A=bisect.bisect_left(a,i) B=len(b)-bisect.bisect_right(c,i) ans+=A*B print(ans)
11
11
266
271
import bisect n = int(eval(input())) a = sorted(list(map(int, input().split()))) b = sorted(list(map(int, input().split()))) c = sorted(list(map(int, input().split()))) ans = 0 for i in b: x = bisect.bisect_left(a, i) y = n - bisect.bisect_right(c, i) ans += x * y print(ans)
import bisect n = int(eval(input())) a = sorted(list(map(int, input().split()))) b = sorted(list(map(int, input().split()))) c = sorted(list(map(int, input().split()))) ans = 0 for i in b: A = bisect.bisect_left(a, i) B = len(b) - bisect.bisect_right(c, i) ans += A * B print(ans)
false
0
[ "- x = bisect.bisect_left(a, i)", "- y = n - bisect.bisect_right(c, i)", "- ans += x * y", "+ A = bisect.bisect_left(a, i)", "+ B = len(b) - bisect.bisect_right(c, i)", "+ ans += A * B" ]
false
0.087001
0.04076
2.134449
[ "s801009350", "s589827840" ]
u113971909
p02727
python
s861539227
s659076059
303
234
23,328
23,472
Accepted
Accepted
22.77
from heapq import heapify, heappop, heappush, heappushpop import sys input = sys.stdin.readline x,y,a,b,c=list(map(int, input().split())) p=list(map(int, input().split())) q=list(map(int, input().split())) r=list(map(int, input().split())) p.sort(reverse=True) q.sort(reverse=True) r.sort() p=p[:x] q=q[:y] heapify(p) heapify(q) mp = heappop(p) mq = heappop(q) for ri in r: if mp<mq: if mp<ri: heappush(p, ri) mp=heappop(p) else: if mq<ri: heappush(q, ri) mq=heappop(q) print((sum(p)+sum(q)+mp+mq))
import sys input = sys.stdin.readline x,y,a,b,c=list(map(int, input().split())) p=list(map(int, input().split())) q=list(map(int, input().split())) r=list(map(int, input().split())) p.sort(reverse=True) q.sort(reverse=True) p=p[:x] q=q[:y] r=r+p+q r.sort(reverse=True) print((sum(r[:x+y])))
27
13
553
294
from heapq import heapify, heappop, heappush, heappushpop import sys input = sys.stdin.readline x, y, a, b, c = list(map(int, input().split())) p = list(map(int, input().split())) q = list(map(int, input().split())) r = list(map(int, input().split())) p.sort(reverse=True) q.sort(reverse=True) r.sort() p = p[:x] q = q[:y] heapify(p) heapify(q) mp = heappop(p) mq = heappop(q) for ri in r: if mp < mq: if mp < ri: heappush(p, ri) mp = heappop(p) else: if mq < ri: heappush(q, ri) mq = heappop(q) print((sum(p) + sum(q) + mp + mq))
import sys input = sys.stdin.readline x, y, a, b, c = list(map(int, input().split())) p = list(map(int, input().split())) q = list(map(int, input().split())) r = list(map(int, input().split())) p.sort(reverse=True) q.sort(reverse=True) p = p[:x] q = q[:y] r = r + p + q r.sort(reverse=True) print((sum(r[: x + y])))
false
51.851852
[ "-from heapq import heapify, heappop, heappush, heappushpop", "-r.sort()", "-heapify(p)", "-heapify(q)", "-mp = heappop(p)", "-mq = heappop(q)", "-for ri in r:", "- if mp < mq:", "- if mp < ri:", "- heappush(p, ri)", "- mp = heappop(p)", "- else:", "- if mq < ri:", "- heappush(q, ri)", "- mq = heappop(q)", "-print((sum(p) + sum(q) + mp + mq))", "+r = r + p + q", "+r.sort(reverse=True)", "+print((sum(r[: x + y])))" ]
false
0.037178
0.036562
1.016843
[ "s861539227", "s659076059" ]
u173148629
p02803
python
s436559619
s509664956
552
350
74,732
3,316
Accepted
Accepted
36.59
H,W=list(map(int,input().split())) S=[] for _ in range(H): S.append(list(eval(input()))) from collections import deque que=deque() maxx=0 for i in range(H): for j in range(W): if S[i][j]=="#": continue ans=[[500]*W for _ in range(H)] ans[i][j]=0 que.append((i,j)) while que: h,w=que.popleft() if h!=0 and S[h-1][w]==".": if ans[h-1][w]==500: ans[h-1][w]=ans[h][w]+1 que.append((h-1,w)) if h!=H-1 and S[h+1][w]==".": if ans[h+1][w]==500: ans[h+1][w]=ans[h][w]+1 que.append((h+1,w)) if w!=0 and S[h][w-1]==".": if ans[h][w-1]==500: ans[h][w-1]=ans[h][w]+1 que.append((h,w-1)) if w!=W-1 and S[h][w+1]==".": if ans[h][w+1]==500: ans[h][w+1]=ans[h][w]+1 que.append((h,w+1)) maxx=max(maxx,ans[h][w]) print(maxx)
H,W=list(map(int,input().split())) S=[] for _ in range(H): S.append(list(eval(input()))) from collections import deque que=deque() maxx=0 for i in range(H): for j in range(W): if S[i][j]=="#": continue ans=[[-1]*W for _ in range(H)] ans[i][j]=0 que.append((i,j)) while que: h,w=que.popleft() if h!=0 and S[h-1][w]==".": if ans[h-1][w]==-1: ans[h-1][w]=ans[h][w]+1 que.append((h-1,w)) if h!=H-1 and S[h+1][w]==".": if ans[h+1][w]==-1: ans[h+1][w]=ans[h][w]+1 que.append((h+1,w)) if w!=0 and S[h][w-1]==".": if ans[h][w-1]==-1: ans[h][w-1]=ans[h][w]+1 que.append((h,w-1)) if w!=W-1 and S[h][w+1]==".": if ans[h][w+1]==-1: ans[h][w+1]=ans[h][w]+1 que.append((h,w+1)) maxx=max(maxx,ans[h][w]) print(maxx)
37
37
1,091
1,086
H, W = list(map(int, input().split())) S = [] for _ in range(H): S.append(list(eval(input()))) from collections import deque que = deque() maxx = 0 for i in range(H): for j in range(W): if S[i][j] == "#": continue ans = [[500] * W for _ in range(H)] ans[i][j] = 0 que.append((i, j)) while que: h, w = que.popleft() if h != 0 and S[h - 1][w] == ".": if ans[h - 1][w] == 500: ans[h - 1][w] = ans[h][w] + 1 que.append((h - 1, w)) if h != H - 1 and S[h + 1][w] == ".": if ans[h + 1][w] == 500: ans[h + 1][w] = ans[h][w] + 1 que.append((h + 1, w)) if w != 0 and S[h][w - 1] == ".": if ans[h][w - 1] == 500: ans[h][w - 1] = ans[h][w] + 1 que.append((h, w - 1)) if w != W - 1 and S[h][w + 1] == ".": if ans[h][w + 1] == 500: ans[h][w + 1] = ans[h][w] + 1 que.append((h, w + 1)) maxx = max(maxx, ans[h][w]) print(maxx)
H, W = list(map(int, input().split())) S = [] for _ in range(H): S.append(list(eval(input()))) from collections import deque que = deque() maxx = 0 for i in range(H): for j in range(W): if S[i][j] == "#": continue ans = [[-1] * W for _ in range(H)] ans[i][j] = 0 que.append((i, j)) while que: h, w = que.popleft() if h != 0 and S[h - 1][w] == ".": if ans[h - 1][w] == -1: ans[h - 1][w] = ans[h][w] + 1 que.append((h - 1, w)) if h != H - 1 and S[h + 1][w] == ".": if ans[h + 1][w] == -1: ans[h + 1][w] = ans[h][w] + 1 que.append((h + 1, w)) if w != 0 and S[h][w - 1] == ".": if ans[h][w - 1] == -1: ans[h][w - 1] = ans[h][w] + 1 que.append((h, w - 1)) if w != W - 1 and S[h][w + 1] == ".": if ans[h][w + 1] == -1: ans[h][w + 1] = ans[h][w] + 1 que.append((h, w + 1)) maxx = max(maxx, ans[h][w]) print(maxx)
false
0
[ "- ans = [[500] * W for _ in range(H)]", "+ ans = [[-1] * W for _ in range(H)]", "- if ans[h - 1][w] == 500:", "+ if ans[h - 1][w] == -1:", "- if ans[h + 1][w] == 500:", "+ if ans[h + 1][w] == -1:", "- if ans[h][w - 1] == 500:", "+ if ans[h][w - 1] == -1:", "- if ans[h][w + 1] == 500:", "+ if ans[h][w + 1] == -1:" ]
false
0.038074
0.037803
1.007146
[ "s436559619", "s509664956" ]
u614314290
p03086
python
s695511712
s525212518
35
19
3,316
3,188
Accepted
Accepted
45.71
import re S = eval(input()) H = re.findall("[ACGT]+", S) max_length = 0 for h in H: if max_length < len(h): max_length = len(h) print(max_length)
import re H = re.findall("[ACGT]+", eval(input())) print((len(max(H, key=lambda x: len(x))) if H else 0))
8
3
150
100
import re S = eval(input()) H = re.findall("[ACGT]+", S) max_length = 0 for h in H: if max_length < len(h): max_length = len(h) print(max_length)
import re H = re.findall("[ACGT]+", eval(input())) print((len(max(H, key=lambda x: len(x))) if H else 0))
false
62.5
[ "-S = eval(input())", "-H = re.findall(\"[ACGT]+\", S)", "-max_length = 0", "-for h in H:", "- if max_length < len(h):", "- max_length = len(h)", "-print(max_length)", "+H = re.findall(\"[ACGT]+\", eval(input()))", "+print((len(max(H, key=lambda x: len(x))) if H else 0))" ]
false
0.060952
0.066195
0.920798
[ "s695511712", "s525212518" ]
u729939940
p02595
python
s574852592
s346696987
475
389
9,124
9,192
Accepted
Accepted
18.11
from math import sqrt N,D=list(map(int,input().split())) ans=0 for i in range(N): x,y=list(map(int,input().split())) if x**2+y**2<=D**2: ans+=1 print(ans)
N,D=list(map(int,input().split())) ans=0 for i in range(N): x,y=list(map(int,input().split())) if x*x+y*y<=D*D: ans+=1 print(ans)
8
7
157
131
from math import sqrt N, D = list(map(int, input().split())) ans = 0 for i in range(N): x, y = list(map(int, input().split())) if x**2 + y**2 <= D**2: ans += 1 print(ans)
N, D = list(map(int, input().split())) ans = 0 for i in range(N): x, y = list(map(int, input().split())) if x * x + y * y <= D * D: ans += 1 print(ans)
false
12.5
[ "-from math import sqrt", "-", "- if x**2 + y**2 <= D**2:", "+ if x * x + y * y <= D * D:" ]
false
0.048328
0.049026
0.985756
[ "s574852592", "s346696987" ]
u729133443
p02819
python
s028726335
s417079325
92
30
4,668
2,940
Accepted
Accepted
67.39
from subprocess import* x=int(eval(input())) while len(Popen(['factor',str(x)],stdout=PIPE).communicate()[0].split())>2:x+=1 print(x)
x=int(eval(input())) while any(x%i<1for i in range(2,x)):x+=1 print(x)
4
3
130
66
from subprocess import * x = int(eval(input())) while len(Popen(["factor", str(x)], stdout=PIPE).communicate()[0].split()) > 2: x += 1 print(x)
x = int(eval(input())) while any(x % i < 1 for i in range(2, x)): x += 1 print(x)
false
25
[ "-from subprocess import *", "-", "-while len(Popen([\"factor\", str(x)], stdout=PIPE).communicate()[0].split()) > 2:", "+while any(x % i < 1 for i in range(2, x)):" ]
false
0.053899
0.038048
1.416606
[ "s028726335", "s417079325" ]
u814986259
p03062
python
s253788210
s598837398
140
92
14,412
14,412
Accepted
Accepted
34.29
N = int(eval(input())) A = list(map(int, input().split())) count = 0 A.sort(key=lambda x: abs(x)) for x in A: if x < 0: count += 1 A = [abs(x) for x in A] ans = 0 if count % 2 == 0: ans = sum(A) else: ans = sum(A[1:]) - A[0] print(ans)
N = int(eval(input())) A = list(map(int, input().split())) if abs(A[0]) < abs(A[-1]): A = A[::-1] B = list(map(abs, A)) B.sort() C = [x for x in A if x < 0] n = len(C) if n % 2 == 0: print((sum(B))) else: print((sum(B[1:]) - B[0]))
15
13
265
247
N = int(eval(input())) A = list(map(int, input().split())) count = 0 A.sort(key=lambda x: abs(x)) for x in A: if x < 0: count += 1 A = [abs(x) for x in A] ans = 0 if count % 2 == 0: ans = sum(A) else: ans = sum(A[1:]) - A[0] print(ans)
N = int(eval(input())) A = list(map(int, input().split())) if abs(A[0]) < abs(A[-1]): A = A[::-1] B = list(map(abs, A)) B.sort() C = [x for x in A if x < 0] n = len(C) if n % 2 == 0: print((sum(B))) else: print((sum(B[1:]) - B[0]))
false
13.333333
[ "-count = 0", "-A.sort(key=lambda x: abs(x))", "-for x in A:", "- if x < 0:", "- count += 1", "-A = [abs(x) for x in A]", "-ans = 0", "-if count % 2 == 0:", "- ans = sum(A)", "+if abs(A[0]) < abs(A[-1]):", "+ A = A[::-1]", "+B = list(map(abs, A))", "+B.sort()", "+C = [x for x in A if x < 0]", "+n = len(C)", "+if n % 2 == 0:", "+ print((sum(B)))", "- ans = sum(A[1:]) - A[0]", "-print(ans)", "+ print((sum(B[1:]) - B[0]))" ]
false
0.113947
0.079962
1.425018
[ "s253788210", "s598837398" ]
u966695411
p03805
python
s657659404
s636334878
53
48
3,064
3,064
Accepted
Accepted
9.43
import itertools N, M = list(map(int, input().split())) E = set([tuple(sorted(map(int, input().split()))) for x in range(M)]) cnt = 0 for i in itertools.permutations(list(range(2,N+1)), N-1): l = [1]+list(i) if sum(1 for x in range(N-1) if tuple(sorted(l[x:x+2])) in E) == N-1: cnt += 1 print(cnt)
import itertools N, M = list(map(int, input().split())) D = {tuple(sorted(map(int, input().split()))) for x in range(M)} cnt = 0 for i in itertools.permutations(list(range(2, N+1)), N-1): l = [1]+list(i) cnt += sum(1 for x in zip(l,l[1:]) if tuple(sorted(x)) in D) == N-1 print(cnt)
9
8
309
285
import itertools N, M = list(map(int, input().split())) E = set([tuple(sorted(map(int, input().split()))) for x in range(M)]) cnt = 0 for i in itertools.permutations(list(range(2, N + 1)), N - 1): l = [1] + list(i) if sum(1 for x in range(N - 1) if tuple(sorted(l[x : x + 2])) in E) == N - 1: cnt += 1 print(cnt)
import itertools N, M = list(map(int, input().split())) D = {tuple(sorted(map(int, input().split()))) for x in range(M)} cnt = 0 for i in itertools.permutations(list(range(2, N + 1)), N - 1): l = [1] + list(i) cnt += sum(1 for x in zip(l, l[1:]) if tuple(sorted(x)) in D) == N - 1 print(cnt)
false
11.111111
[ "-E = set([tuple(sorted(map(int, input().split()))) for x in range(M)])", "+D = {tuple(sorted(map(int, input().split()))) for x in range(M)}", "- if sum(1 for x in range(N - 1) if tuple(sorted(l[x : x + 2])) in E) == N - 1:", "- cnt += 1", "+ cnt += sum(1 for x in zip(l, l[1:]) if tuple(sorted(x)) in D) == N - 1" ]
false
0.063324
0.05644
1.121955
[ "s657659404", "s636334878" ]
u732061897
p03111
python
s863136134
s255064448
236
67
9,200
9,152
Accepted
Accepted
71.61
N, A, B, C = list(map(int, input().split())) L_list = [int(eval(input())) for i in range(N)] import itertools Target = itertools.product([0, 1, 2, 3], repeat=N) INF = 10 ** 9 #Target = [(1,2,2,2,3)] ans = INF for T in Target: A_sum = 0 B_sum = 0 C_sum = 0 A_cost = 0 B_cost = 0 C_cost = 0 for i in range(N): if T[i] == 0: continue if T[i] == 1: if A_sum == 0: A_sum += L_list[i] else: A_sum += L_list[i] A_cost += 10 if T[i] == 2: if B_sum == 0: B_sum += L_list[i] else: B_sum += L_list[i] B_cost += 10 if T[i] == 3: if C_sum == 0: C_sum += L_list[i] else: C_sum += L_list[i] C_cost += 10 if min(A_sum, B_sum, C_sum) == 0: continue ans = min(ans, abs(A - A_sum)+A_cost + abs(B - B_sum)+B_cost + abs(C - C_sum)+C_cost) print(ans)
N, A, B, C = list(map(int, input().split())) L_list = [int(eval(input())) for i in range(N)] INF = 10 ** 9 def dfs(a, b, c, n): if n == N: return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else INF ret1 = dfs(a, b, c, n + 1) ret2 = dfs(a + L_list[n], b, c, n + 1) + 10 ret3 = dfs(a, b + L_list[n], c, n + 1) + 10 ret4 = dfs(a, b, c + L_list[n], n + 1) + 10 return min(ret1, ret2, ret3, ret4) ans = dfs(0, 0, 0, 0) print(ans) ''' 8 100 90 80 100 100 90 90 90 80 80 80 0 8 1000 800 100 300 333 400 444 500 555 600 666 243 '''
42
45
1,047
616
N, A, B, C = list(map(int, input().split())) L_list = [int(eval(input())) for i in range(N)] import itertools Target = itertools.product([0, 1, 2, 3], repeat=N) INF = 10**9 # Target = [(1,2,2,2,3)] ans = INF for T in Target: A_sum = 0 B_sum = 0 C_sum = 0 A_cost = 0 B_cost = 0 C_cost = 0 for i in range(N): if T[i] == 0: continue if T[i] == 1: if A_sum == 0: A_sum += L_list[i] else: A_sum += L_list[i] A_cost += 10 if T[i] == 2: if B_sum == 0: B_sum += L_list[i] else: B_sum += L_list[i] B_cost += 10 if T[i] == 3: if C_sum == 0: C_sum += L_list[i] else: C_sum += L_list[i] C_cost += 10 if min(A_sum, B_sum, C_sum) == 0: continue ans = min( ans, abs(A - A_sum) + A_cost + abs(B - B_sum) + B_cost + abs(C - C_sum) + C_cost ) print(ans)
N, A, B, C = list(map(int, input().split())) L_list = [int(eval(input())) for i in range(N)] INF = 10**9 def dfs(a, b, c, n): if n == N: return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else INF ret1 = dfs(a, b, c, n + 1) ret2 = dfs(a + L_list[n], b, c, n + 1) + 10 ret3 = dfs(a, b + L_list[n], c, n + 1) + 10 ret4 = dfs(a, b, c + L_list[n], n + 1) + 10 return min(ret1, ret2, ret3, ret4) ans = dfs(0, 0, 0, 0) print(ans) """ 8 100 90 80 100 100 90 90 90 80 80 80 0 8 1000 800 100 300 333 400 444 500 555 600 666 243 """
false
6.666667
[ "-import itertools", "+INF = 10**9", "-Target = itertools.product([0, 1, 2, 3], repeat=N)", "-INF = 10**9", "-# Target = [(1,2,2,2,3)]", "-ans = INF", "-for T in Target:", "- A_sum = 0", "- B_sum = 0", "- C_sum = 0", "- A_cost = 0", "- B_cost = 0", "- C_cost = 0", "- for i in range(N):", "- if T[i] == 0:", "- continue", "- if T[i] == 1:", "- if A_sum == 0:", "- A_sum += L_list[i]", "- else:", "- A_sum += L_list[i]", "- A_cost += 10", "- if T[i] == 2:", "- if B_sum == 0:", "- B_sum += L_list[i]", "- else:", "- B_sum += L_list[i]", "- B_cost += 10", "- if T[i] == 3:", "- if C_sum == 0:", "- C_sum += L_list[i]", "- else:", "- C_sum += L_list[i]", "- C_cost += 10", "- if min(A_sum, B_sum, C_sum) == 0:", "- continue", "- ans = min(", "- ans, abs(A - A_sum) + A_cost + abs(B - B_sum) + B_cost + abs(C - C_sum) + C_cost", "- )", "+", "+def dfs(a, b, c, n):", "+ if n == N:", "+ return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a, b, c) > 0 else INF", "+ ret1 = dfs(a, b, c, n + 1)", "+ ret2 = dfs(a + L_list[n], b, c, n + 1) + 10", "+ ret3 = dfs(a, b + L_list[n], c, n + 1) + 10", "+ ret4 = dfs(a, b, c + L_list[n], n + 1) + 10", "+ return min(ret1, ret2, ret3, ret4)", "+", "+", "+ans = dfs(0, 0, 0, 0)", "+\"\"\"", "+8 100 90 80", "+100", "+100", "+90", "+90", "+90", "+80", "+80", "+80", "+0", "+8 1000 800 100", "+300", "+333", "+400", "+444", "+500", "+555", "+600", "+666", "+243", "+\"\"\"" ]
false
0.768371
0.114961
6.68376
[ "s863136134", "s255064448" ]
u756388720
p03111
python
s082621879
s461961747
90
68
3,064
9,236
Accepted
Accepted
24.44
N, A, B, C = list(map(int, input().split())) l = [int(eval(input())) for i in range(N)] def dfs(d, a, b, c): if d == N: res = abs(a - A) + abs(b - B) + abs(c - C) - 30 return 1e9 if min(a, b, c) == 0 else res ret = [0] * 4 ret[0] = dfs(d + 1, a, b, c) ret[1] = dfs(d + 1, a + l[d], b, c) + 10 ret[2] = dfs(d + 1, a, b + l[d], c) + 10 ret[3] = dfs(d + 1, a, b, c + l[d]) + 10 return min(ret) print((dfs(0, 0, 0, 0)))
N, A, B, C = list(map(int, input().split())) L = [int(eval(input())) for _ in range(N)] def rec(itr, a, b, c, mp): if itr == N: if a == 0 or b == 0 or c == 0: return 10 ** 9 return abs(a - A) + abs(b - B) + abs(c - C) + mp - 30 res = rec(itr + 1, a, b, c, mp) res = min(res, rec(itr + 1, a + L[itr], b, c, mp) + 10) res = min(res, rec(itr + 1, a, b + L[itr], c, mp) + 10) res = min(res, rec(itr + 1, a, b, c + L[itr], mp) + 10) return res print((rec(0, 0, 0, 0, 0)))
13
13
436
517
N, A, B, C = list(map(int, input().split())) l = [int(eval(input())) for i in range(N)] def dfs(d, a, b, c): if d == N: res = abs(a - A) + abs(b - B) + abs(c - C) - 30 return 1e9 if min(a, b, c) == 0 else res ret = [0] * 4 ret[0] = dfs(d + 1, a, b, c) ret[1] = dfs(d + 1, a + l[d], b, c) + 10 ret[2] = dfs(d + 1, a, b + l[d], c) + 10 ret[3] = dfs(d + 1, a, b, c + l[d]) + 10 return min(ret) print((dfs(0, 0, 0, 0)))
N, A, B, C = list(map(int, input().split())) L = [int(eval(input())) for _ in range(N)] def rec(itr, a, b, c, mp): if itr == N: if a == 0 or b == 0 or c == 0: return 10**9 return abs(a - A) + abs(b - B) + abs(c - C) + mp - 30 res = rec(itr + 1, a, b, c, mp) res = min(res, rec(itr + 1, a + L[itr], b, c, mp) + 10) res = min(res, rec(itr + 1, a, b + L[itr], c, mp) + 10) res = min(res, rec(itr + 1, a, b, c + L[itr], mp) + 10) return res print((rec(0, 0, 0, 0, 0)))
false
0
[ "-l = [int(eval(input())) for i in range(N)]", "+L = [int(eval(input())) for _ in range(N)]", "-def dfs(d, a, b, c):", "- if d == N:", "- res = abs(a - A) + abs(b - B) + abs(c - C) - 30", "- return 1e9 if min(a, b, c) == 0 else res", "- ret = [0] * 4", "- ret[0] = dfs(d + 1, a, b, c)", "- ret[1] = dfs(d + 1, a + l[d], b, c) + 10", "- ret[2] = dfs(d + 1, a, b + l[d], c) + 10", "- ret[3] = dfs(d + 1, a, b, c + l[d]) + 10", "- return min(ret)", "+def rec(itr, a, b, c, mp):", "+ if itr == N:", "+ if a == 0 or b == 0 or c == 0:", "+ return 10**9", "+ return abs(a - A) + abs(b - B) + abs(c - C) + mp - 30", "+ res = rec(itr + 1, a, b, c, mp)", "+ res = min(res, rec(itr + 1, a + L[itr], b, c, mp) + 10)", "+ res = min(res, rec(itr + 1, a, b + L[itr], c, mp) + 10)", "+ res = min(res, rec(itr + 1, a, b, c + L[itr], mp) + 10)", "+ return res", "-print((dfs(0, 0, 0, 0)))", "+print((rec(0, 0, 0, 0, 0)))" ]
false
0.288771
0.07189
4.016871
[ "s082621879", "s461961747" ]
u287132915
p02838
python
s616226365
s329784561
586
310
122,936
48,808
Accepted
Accepted
47.1
n = int(eval(input())) a = list(map(int, input().split())) wa = 0 kazu = 10**9 + 7 for i in range(60): b = 0 for j in a: b += j & 1 wa = (wa + b*(n-b)*(1<<i)) % kazu for j in range(n): a[j] = a[j] >> 1 print(wa)
import numpy as np n = int(eval(input())) a = np.array(list(map(int, input().split()))) wa = 0 kazu = 10**9 + 7 for i in range(60): b = int((a & 1).sum()) wa = (wa + b*(n-b)*(1<<i)) % kazu a = a >> 1 print(wa)
14
13
252
230
n = int(eval(input())) a = list(map(int, input().split())) wa = 0 kazu = 10**9 + 7 for i in range(60): b = 0 for j in a: b += j & 1 wa = (wa + b * (n - b) * (1 << i)) % kazu for j in range(n): a[j] = a[j] >> 1 print(wa)
import numpy as np n = int(eval(input())) a = np.array(list(map(int, input().split()))) wa = 0 kazu = 10**9 + 7 for i in range(60): b = int((a & 1).sum()) wa = (wa + b * (n - b) * (1 << i)) % kazu a = a >> 1 print(wa)
false
7.142857
[ "+import numpy as np", "+", "-a = list(map(int, input().split()))", "+a = np.array(list(map(int, input().split())))", "- b = 0", "- for j in a:", "- b += j & 1", "+ b = int((a & 1).sum())", "- for j in range(n):", "- a[j] = a[j] >> 1", "+ a = a >> 1" ]
false
0.127184
0.891212
0.142709
[ "s616226365", "s329784561" ]
u268470352
p02923
python
s608788630
s359694548
60
47
11,128
11,132
Accepted
Accepted
21.67
N = int(eval(input())) H = list(map(int, input().split())) counter = -1 last_h = float('inf') _max = 0 for h in H: if h <= last_h: counter += 1 else: if _max < counter: _max = counter counter = 0 last_h = h if _max < counter: _max = counter print(_max)
def solve(N, H): last_h = float('inf') _count = -1 _max = 0 for h in H: if h <= last_h: _count += 1 else: if _max < _count: _max = _count _count = 0 last_h = h if _max < _count: _max = _count return _max if __name__ == '__main__': N = int(eval(input())) H = list(map(int, input().split())) ans = solve(N, H) print(ans)
17
24
309
465
N = int(eval(input())) H = list(map(int, input().split())) counter = -1 last_h = float("inf") _max = 0 for h in H: if h <= last_h: counter += 1 else: if _max < counter: _max = counter counter = 0 last_h = h if _max < counter: _max = counter print(_max)
def solve(N, H): last_h = float("inf") _count = -1 _max = 0 for h in H: if h <= last_h: _count += 1 else: if _max < _count: _max = _count _count = 0 last_h = h if _max < _count: _max = _count return _max if __name__ == "__main__": N = int(eval(input())) H = list(map(int, input().split())) ans = solve(N, H) print(ans)
false
29.166667
[ "-N = int(eval(input()))", "-H = list(map(int, input().split()))", "-counter = -1", "-last_h = float(\"inf\")", "-_max = 0", "-for h in H:", "- if h <= last_h:", "- counter += 1", "- else:", "- if _max < counter:", "- _max = counter", "- counter = 0", "- last_h = h", "-if _max < counter:", "- _max = counter", "-print(_max)", "+def solve(N, H):", "+ last_h = float(\"inf\")", "+ _count = -1", "+ _max = 0", "+ for h in H:", "+ if h <= last_h:", "+ _count += 1", "+ else:", "+ if _max < _count:", "+ _max = _count", "+ _count = 0", "+ last_h = h", "+ if _max < _count:", "+ _max = _count", "+ return _max", "+", "+", "+if __name__ == \"__main__\":", "+ N = int(eval(input()))", "+ H = list(map(int, input().split()))", "+ ans = solve(N, H)", "+ print(ans)" ]
false
0.101668
0.073626
1.380866
[ "s608788630", "s359694548" ]
u566428756
p02802
python
s879263646
s478196101
338
289
33,584
4,596
Accepted
Accepted
14.5
N,M=list(map(int,input().split())) PS=[list(input().split()) for _ in range(M)] wa=[0]*(N+1) ac=[0]*(N+1) ac_cnt=set() for ps in PS: if ps[1]=='AC': ac_cnt.add(ps[0]) ac[int(ps[0])]=1 if ps[1]=='WA' and ac[int(ps[0])]==0: wa[int(ps[0])]+=1 for i in range(1,N+1): if str(i) not in ac_cnt: wa[i]=0 print((sum(ac),sum(wa)))
N,M=list(map(int,input().split())) ac=[0]*(N+1) wa=[0]*(N+1) for i in range(M): p,s=input().split() if ac[int(p)]==1: continue if s=='AC': ac[int(p)]=1 elif s=='WA': wa[int(p)]+=1 ac_ans,wa_ans=0,0 for a,w in zip(ac,wa): if a==0: continue ac_ans+=a wa_ans+=w print((ac_ans,wa_ans))
15
20
371
354
N, M = list(map(int, input().split())) PS = [list(input().split()) for _ in range(M)] wa = [0] * (N + 1) ac = [0] * (N + 1) ac_cnt = set() for ps in PS: if ps[1] == "AC": ac_cnt.add(ps[0]) ac[int(ps[0])] = 1 if ps[1] == "WA" and ac[int(ps[0])] == 0: wa[int(ps[0])] += 1 for i in range(1, N + 1): if str(i) not in ac_cnt: wa[i] = 0 print((sum(ac), sum(wa)))
N, M = list(map(int, input().split())) ac = [0] * (N + 1) wa = [0] * (N + 1) for i in range(M): p, s = input().split() if ac[int(p)] == 1: continue if s == "AC": ac[int(p)] = 1 elif s == "WA": wa[int(p)] += 1 ac_ans, wa_ans = 0, 0 for a, w in zip(ac, wa): if a == 0: continue ac_ans += a wa_ans += w print((ac_ans, wa_ans))
false
25
[ "-PS = [list(input().split()) for _ in range(M)]", "+ac = [0] * (N + 1)", "-ac = [0] * (N + 1)", "-ac_cnt = set()", "-for ps in PS:", "- if ps[1] == \"AC\":", "- ac_cnt.add(ps[0])", "- ac[int(ps[0])] = 1", "- if ps[1] == \"WA\" and ac[int(ps[0])] == 0:", "- wa[int(ps[0])] += 1", "-for i in range(1, N + 1):", "- if str(i) not in ac_cnt:", "- wa[i] = 0", "-print((sum(ac), sum(wa)))", "+for i in range(M):", "+ p, s = input().split()", "+ if ac[int(p)] == 1:", "+ continue", "+ if s == \"AC\":", "+ ac[int(p)] = 1", "+ elif s == \"WA\":", "+ wa[int(p)] += 1", "+ac_ans, wa_ans = 0, 0", "+for a, w in zip(ac, wa):", "+ if a == 0:", "+ continue", "+ ac_ans += a", "+ wa_ans += w", "+print((ac_ans, wa_ans))" ]
false
0.109034
0.092889
1.173809
[ "s879263646", "s478196101" ]
u952708174
p03151
python
s888156276
s149373152
138
113
18,356
18,356
Accepted
Accepted
18.12
def c_exam_and_wizard(N, A, B): ans = 0 short_val = 0 # 合格に不足する準備度 can_give = [] for a, b in zip(A, B): if a < b: ans += 1 short_val += b - a elif a > b: can_give.append(a - b) if short_val == 0: return 0 can_give.sort() idx = len(can_give) - 1 while True: if not can_give: ans = -1 break if can_give[idx] >= short_val: ans += 1 break short_val -= can_give[idx] can_give.pop() ans += 1 idx -= 1 return ans N = int(eval(input())) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] print((c_exam_and_wizard(N, A, B)))
def c_exam_and_wizard(N, A, B): ans = 0 sum_of_shortage_for_passing_mark = 0 campensation_for_shortage = [] for a, b in zip(A, B): if a < b: ans += 1 sum_of_shortage_for_passing_mark += b - a elif a > b: campensation_for_shortage.append(a - b) if sum_of_shortage_for_passing_mark == 0: return 0 # 準備度を変更するまでもない campensation_for_shortage.sort(reverse=True) # A_i-B_iが大きなiから分けていく for pts in campensation_for_shortage: if pts >= sum_of_shortage_for_passing_mark: ans += 1 break sum_of_shortage_for_passing_mark -= pts ans += 1 else: ans = -1 return ans N = int(eval(input())) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] print((c_exam_and_wizard(N, A, B)))
35
30
764
863
def c_exam_and_wizard(N, A, B): ans = 0 short_val = 0 # 合格に不足する準備度 can_give = [] for a, b in zip(A, B): if a < b: ans += 1 short_val += b - a elif a > b: can_give.append(a - b) if short_val == 0: return 0 can_give.sort() idx = len(can_give) - 1 while True: if not can_give: ans = -1 break if can_give[idx] >= short_val: ans += 1 break short_val -= can_give[idx] can_give.pop() ans += 1 idx -= 1 return ans N = int(eval(input())) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] print((c_exam_and_wizard(N, A, B)))
def c_exam_and_wizard(N, A, B): ans = 0 sum_of_shortage_for_passing_mark = 0 campensation_for_shortage = [] for a, b in zip(A, B): if a < b: ans += 1 sum_of_shortage_for_passing_mark += b - a elif a > b: campensation_for_shortage.append(a - b) if sum_of_shortage_for_passing_mark == 0: return 0 # 準備度を変更するまでもない campensation_for_shortage.sort(reverse=True) # A_i-B_iが大きなiから分けていく for pts in campensation_for_shortage: if pts >= sum_of_shortage_for_passing_mark: ans += 1 break sum_of_shortage_for_passing_mark -= pts ans += 1 else: ans = -1 return ans N = int(eval(input())) A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] print((c_exam_and_wizard(N, A, B)))
false
14.285714
[ "- short_val = 0 # 合格に不足する準備度", "- can_give = []", "+ sum_of_shortage_for_passing_mark = 0", "+ campensation_for_shortage = []", "- short_val += b - a", "+ sum_of_shortage_for_passing_mark += b - a", "- can_give.append(a - b)", "- if short_val == 0:", "- return 0", "- can_give.sort()", "- idx = len(can_give) - 1", "- while True:", "- if not can_give:", "- ans = -1", "- break", "- if can_give[idx] >= short_val:", "+ campensation_for_shortage.append(a - b)", "+ if sum_of_shortage_for_passing_mark == 0:", "+ return 0 # 準備度を変更するまでもない", "+ campensation_for_shortage.sort(reverse=True) # A_i-B_iが大きなiから分けていく", "+ for pts in campensation_for_shortage:", "+ if pts >= sum_of_shortage_for_passing_mark:", "- short_val -= can_give[idx]", "- can_give.pop()", "+ sum_of_shortage_for_passing_mark -= pts", "- idx -= 1", "+ else:", "+ ans = -1" ]
false
0.035124
0.036728
0.956345
[ "s888156276", "s149373152" ]
u747873993
p03501
python
s950521779
s922772163
19
17
2,940
2,940
Accepted
Accepted
10.53
N,A,B=(int(i) for i in input().split()) if A*N<B: print((A*N)) else: print(B)
N,A,B=(int(i) for i in input().split()) value=A*N if value<B: print(value) else: print(B)
5
6
87
102
N, A, B = (int(i) for i in input().split()) if A * N < B: print((A * N)) else: print(B)
N, A, B = (int(i) for i in input().split()) value = A * N if value < B: print(value) else: print(B)
false
16.666667
[ "-if A * N < B:", "- print((A * N))", "+value = A * N", "+if value < B:", "+ print(value)" ]
false
0.045341
0.044103
1.028072
[ "s950521779", "s922772163" ]
u452512115
p02996
python
s895823990
s407160579
1,017
855
38,224
39,756
Accepted
Accepted
15.93
N = int(eval(input())) lst = [] for i in range(N): N, K = list(map(int, input().split())) lst.append((K-N, N, K)) lst.sort() lst.sort(key=lambda tup: tup[2]) count = 0 for ind, x in enumerate(lst): if count > x[0]: print("No") exit() count += x[1] print("Yes")
N = int(eval(input())) lst = [] for i in range(N): N, K = list(map(int, input().split())) lst.append((K-N, N, K)) lst.sort(key=lambda tup: tup[2]) count = 0 for ind, x in enumerate(lst): if count > x[0]: print("No") exit() count += x[1] print("Yes")
17
16
284
272
N = int(eval(input())) lst = [] for i in range(N): N, K = list(map(int, input().split())) lst.append((K - N, N, K)) lst.sort() lst.sort(key=lambda tup: tup[2]) count = 0 for ind, x in enumerate(lst): if count > x[0]: print("No") exit() count += x[1] print("Yes")
N = int(eval(input())) lst = [] for i in range(N): N, K = list(map(int, input().split())) lst.append((K - N, N, K)) lst.sort(key=lambda tup: tup[2]) count = 0 for ind, x in enumerate(lst): if count > x[0]: print("No") exit() count += x[1] print("Yes")
false
5.882353
[ "-lst.sort()" ]
false
0.035927
0.037025
0.970343
[ "s895823990", "s407160579" ]
u227082700
p03779
python
s087827019
s612049538
40
28
2,940
2,940
Accepted
Accepted
30
x,t=int(eval(input())),0 while round(t*(t+1)/2)<x:t+=1 print(t)
x=int(eval(input())) for t in range(1,10**10): if t*(t+1)//2>=x:print(t);exit()
3
3
59
77
x, t = int(eval(input())), 0 while round(t * (t + 1) / 2) < x: t += 1 print(t)
x = int(eval(input())) for t in range(1, 10**10): if t * (t + 1) // 2 >= x: print(t) exit()
false
0
[ "-x, t = int(eval(input())), 0", "-while round(t * (t + 1) / 2) < x:", "- t += 1", "-print(t)", "+x = int(eval(input()))", "+for t in range(1, 10**10):", "+ if t * (t + 1) // 2 >= x:", "+ print(t)", "+ exit()" ]
false
0.041243
0.056719
0.727153
[ "s087827019", "s612049538" ]
u251515715
p02913
python
s462521465
s954656898
1,799
1,126
3,064
3,060
Accepted
Accepted
37.41
n=int(eval(input())) s=eval(input()) ans=0 tmp=0 for i in range(n-1): for j in range(i+2,n+1): if j-i>ans: if s[i:j] in s[j:]: tmp=j-i else: ans=max(tmp,ans) break ans=max(tmp,ans) print(ans)
n=int(eval(input())) s=eval(input()) ans=0 i=0 j=1 while i<n and j<=n: if s[i:j] in s[j:n]: ans=max(j-i,ans) j+=1 else: i+=1 print(ans)
14
12
234
150
n = int(eval(input())) s = eval(input()) ans = 0 tmp = 0 for i in range(n - 1): for j in range(i + 2, n + 1): if j - i > ans: if s[i:j] in s[j:]: tmp = j - i else: ans = max(tmp, ans) break ans = max(tmp, ans) print(ans)
n = int(eval(input())) s = eval(input()) ans = 0 i = 0 j = 1 while i < n and j <= n: if s[i:j] in s[j:n]: ans = max(j - i, ans) j += 1 else: i += 1 print(ans)
false
14.285714
[ "-tmp = 0", "-for i in range(n - 1):", "- for j in range(i + 2, n + 1):", "- if j - i > ans:", "- if s[i:j] in s[j:]:", "- tmp = j - i", "- else:", "- ans = max(tmp, ans)", "- break", "-ans = max(tmp, ans)", "+i = 0", "+j = 1", "+while i < n and j <= n:", "+ if s[i:j] in s[j:n]:", "+ ans = max(j - i, ans)", "+ j += 1", "+ else:", "+ i += 1" ]
false
0.041193
0.035382
1.164242
[ "s462521465", "s954656898" ]
u944886577
p02627
python
s294139659
s689287902
35
28
9,864
8,864
Accepted
Accepted
20
import re a=eval(input()) if re.sub(r'[A-Z]',"",a)=="": print('A') else: print('a')
a=eval(input()) if a.isupper(): print('A') else: print('a')
6
5
87
61
import re a = eval(input()) if re.sub(r"[A-Z]", "", a) == "": print("A") else: print("a")
a = eval(input()) if a.isupper(): print("A") else: print("a")
false
16.666667
[ "-import re", "-", "-if re.sub(r\"[A-Z]\", \"\", a) == \"\":", "+if a.isupper():" ]
false
0.042234
0.039969
1.056657
[ "s294139659", "s689287902" ]
u460245024
p03078
python
s644576569
s350468089
1,200
253
140,004
48,988
Accepted
Accepted
78.92
import itertools X, Y, Z, K = map(int, input().split()) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) comb_ab = [] for a, b in itertools.product(A, B): comb_ab.append(sum([a, b])) comb_ab_top = sorted(comb_ab, reverse=True)[:K] comb_abc = [] for ab, c in itertools.product(comb_ab_top, C): comb_abc.append(sum([ab, c])) ans = sorted(comb_abc, reverse=True)[:K] print(*ans, sep='\n')
X, Y, Z, K = map(int, input().split()) A = sorted(list(map(int, input().split())), reverse=True) B = sorted(list(map(int, input().split())), reverse=True) C = sorted(list(map(int, input().split())), reverse=True) comb = [] for a in range(X): b_max = K // (a+1) for b in range(min(Y, b_max)): c_max = K // ((a+1)*(b+1)) for c in range(min(Z, c_max)): comb.append(sum([A[a], B[b], C[c]])) comb.sort(reverse=True) print(*comb[:K], sep='\n')
19
16
500
492
import itertools X, Y, Z, K = map(int, input().split()) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) comb_ab = [] for a, b in itertools.product(A, B): comb_ab.append(sum([a, b])) comb_ab_top = sorted(comb_ab, reverse=True)[:K] comb_abc = [] for ab, c in itertools.product(comb_ab_top, C): comb_abc.append(sum([ab, c])) ans = sorted(comb_abc, reverse=True)[:K] print(*ans, sep="\n")
X, Y, Z, K = map(int, input().split()) A = sorted(list(map(int, input().split())), reverse=True) B = sorted(list(map(int, input().split())), reverse=True) C = sorted(list(map(int, input().split())), reverse=True) comb = [] for a in range(X): b_max = K // (a + 1) for b in range(min(Y, b_max)): c_max = K // ((a + 1) * (b + 1)) for c in range(min(Z, c_max)): comb.append(sum([A[a], B[b], C[c]])) comb.sort(reverse=True) print(*comb[:K], sep="\n")
false
15.789474
[ "-import itertools", "-", "-A = sorted(list(map(int, input().split())))", "-B = sorted(list(map(int, input().split())))", "-C = sorted(list(map(int, input().split())))", "-comb_ab = []", "-for a, b in itertools.product(A, B):", "- comb_ab.append(sum([a, b]))", "-comb_ab_top = sorted(comb_ab, reverse=True)[:K]", "-comb_abc = []", "-for ab, c in itertools.product(comb_ab_top, C):", "- comb_abc.append(sum([ab, c]))", "-ans = sorted(comb_abc, reverse=True)[:K]", "-print(*ans, sep=\"\\n\")", "+A = sorted(list(map(int, input().split())), reverse=True)", "+B = sorted(list(map(int, input().split())), reverse=True)", "+C = sorted(list(map(int, input().split())), reverse=True)", "+comb = []", "+for a in range(X):", "+ b_max = K // (a + 1)", "+ for b in range(min(Y, b_max)):", "+ c_max = K // ((a + 1) * (b + 1))", "+ for c in range(min(Z, c_max)):", "+ comb.append(sum([A[a], B[b], C[c]]))", "+comb.sort(reverse=True)", "+print(*comb[:K], sep=\"\\n\")" ]
false
0.12424
0.046622
2.664809
[ "s644576569", "s350468089" ]
u249218427
p02586
python
s915231954
s836384583
1,130
656
169,244
149,656
Accepted
Accepted
41.95
# -*- coding: utf-8 -*- R,C,K = list(map(int, input().split())) items = [[0 for _ in range(C+1)] for _ in range(R+1)] for i in range(K): r,c,v = list(map(int, input().split())) items[r][c] = v DP_prev = [0 for _ in range(C+1)] for r in range(1,R+1): DP1 = [0 for _ in range(C+1)] DP2 = [0 for _ in range(C+1)] DP3 = [0 for _ in range(C+1)] for c in range(1,C+1): item = items[r][c] DP1[c] = max(DP_prev[c]+item,DP1[c-1]) DP2[c] = max(DP1[c],DP2[c-1],DP1[c-1]+item) DP3[c] = max(DP2[c],DP3[c-1],DP2[c-1]+item) DP_prev = DP3 print((DP_prev[C]))
# -*- coding: utf-8 -*- R,C,K = list(map(int, input().split())) items = [[0 for _ in range(C+1)] for _ in range(R+1)] for i in range(K): r,c,v = list(map(int, input().split())) items[r][c] = v DP_prev = [0 for _ in range(C+1)] DP1 = [0 for _ in range(C+1)] DP2 = [0 for _ in range(C+1)] DP3 = [0 for _ in range(C+1)] for r in range(1,R+1): for c in range(1,C+1): item = items[r][c] DP1[c] = max(DP_prev[c]+item,DP1[c-1]) DP2[c] = max(DP1[c],DP2[c-1],DP1[c-1]+item) DP3[c] = max(DP2[c],DP3[c-1],DP2[c-1]+item) DP_prev = DP3 print((DP_prev[C]))
22
22
591
585
# -*- coding: utf-8 -*- R, C, K = list(map(int, input().split())) items = [[0 for _ in range(C + 1)] for _ in range(R + 1)] for i in range(K): r, c, v = list(map(int, input().split())) items[r][c] = v DP_prev = [0 for _ in range(C + 1)] for r in range(1, R + 1): DP1 = [0 for _ in range(C + 1)] DP2 = [0 for _ in range(C + 1)] DP3 = [0 for _ in range(C + 1)] for c in range(1, C + 1): item = items[r][c] DP1[c] = max(DP_prev[c] + item, DP1[c - 1]) DP2[c] = max(DP1[c], DP2[c - 1], DP1[c - 1] + item) DP3[c] = max(DP2[c], DP3[c - 1], DP2[c - 1] + item) DP_prev = DP3 print((DP_prev[C]))
# -*- coding: utf-8 -*- R, C, K = list(map(int, input().split())) items = [[0 for _ in range(C + 1)] for _ in range(R + 1)] for i in range(K): r, c, v = list(map(int, input().split())) items[r][c] = v DP_prev = [0 for _ in range(C + 1)] DP1 = [0 for _ in range(C + 1)] DP2 = [0 for _ in range(C + 1)] DP3 = [0 for _ in range(C + 1)] for r in range(1, R + 1): for c in range(1, C + 1): item = items[r][c] DP1[c] = max(DP_prev[c] + item, DP1[c - 1]) DP2[c] = max(DP1[c], DP2[c - 1], DP1[c - 1] + item) DP3[c] = max(DP2[c], DP3[c - 1], DP2[c - 1] + item) DP_prev = DP3 print((DP_prev[C]))
false
0
[ "+DP1 = [0 for _ in range(C + 1)]", "+DP2 = [0 for _ in range(C + 1)]", "+DP3 = [0 for _ in range(C + 1)]", "- DP1 = [0 for _ in range(C + 1)]", "- DP2 = [0 for _ in range(C + 1)]", "- DP3 = [0 for _ in range(C + 1)]" ]
false
0.043673
0.04352
1.003521
[ "s915231954", "s836384583" ]
u486209657
p02639
python
s462741780
s309080107
25
23
9,116
9,168
Accepted
Accepted
8
x1, x2, x3, x4, x5 = list(map(int, input().split())) if x1 == 0: print((1)) elif x2 == 0: print((2)) elif x3 == 0: print((3)) elif x4 == 0: print((4)) else: print((5))
x = list(map(int, input().replace(' ',''))) x = list(x) for idx in range(len(x)): if x[idx] == 0: print((idx + 1)) break
12
7
173
129
x1, x2, x3, x4, x5 = list(map(int, input().split())) if x1 == 0: print((1)) elif x2 == 0: print((2)) elif x3 == 0: print((3)) elif x4 == 0: print((4)) else: print((5))
x = list(map(int, input().replace(" ", ""))) x = list(x) for idx in range(len(x)): if x[idx] == 0: print((idx + 1)) break
false
41.666667
[ "-x1, x2, x3, x4, x5 = list(map(int, input().split()))", "-if x1 == 0:", "- print((1))", "-elif x2 == 0:", "- print((2))", "-elif x3 == 0:", "- print((3))", "-elif x4 == 0:", "- print((4))", "-else:", "- print((5))", "+x = list(map(int, input().replace(\" \", \"\")))", "+x = list(x)", "+for idx in range(len(x)):", "+ if x[idx] == 0:", "+ print((idx + 1))", "+ break" ]
false
0.046553
0.045103
1.032147
[ "s462741780", "s309080107" ]
u075012704
p03557
python
s887134160
s760518272
902
476
25,596
107,108
Accepted
Accepted
47.23
import numpy as np N = int(eval(input())) A = np.array(list(map(int, input().split()))) B = np.array(list(map(int, input().split()))) C = np.array(list(map(int, input().split()))) A.sort() B.sort() C.sort() ans = 0 for b in B: AB = A.searchsorted(b, side='left') CB = len(B) - C.searchsorted(b, side='right') ans += AB * CB print(ans)
from bisect import bisect_left, bisect_right N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) ans = 0 for b in B: ans += bisect_left(A, b) * (N - bisect_right(C, b)) print(ans)
18
11
362
294
import numpy as np N = int(eval(input())) A = np.array(list(map(int, input().split()))) B = np.array(list(map(int, input().split()))) C = np.array(list(map(int, input().split()))) A.sort() B.sort() C.sort() ans = 0 for b in B: AB = A.searchsorted(b, side="left") CB = len(B) - C.searchsorted(b, side="right") ans += AB * CB print(ans)
from bisect import bisect_left, bisect_right N = int(eval(input())) A = sorted(list(map(int, input().split()))) B = sorted(list(map(int, input().split()))) C = sorted(list(map(int, input().split()))) ans = 0 for b in B: ans += bisect_left(A, b) * (N - bisect_right(C, b)) print(ans)
false
38.888889
[ "-import numpy as np", "+from bisect import bisect_left, bisect_right", "-A = np.array(list(map(int, input().split())))", "-B = np.array(list(map(int, input().split())))", "-C = np.array(list(map(int, input().split())))", "-A.sort()", "-B.sort()", "-C.sort()", "+A = sorted(list(map(int, input().split())))", "+B = sorted(list(map(int, input().split())))", "+C = sorted(list(map(int, input().split())))", "- AB = A.searchsorted(b, side=\"left\")", "- CB = len(B) - C.searchsorted(b, side=\"right\")", "- ans += AB * CB", "+ ans += bisect_left(A, b) * (N - bisect_right(C, b))" ]
false
0.456169
0.143505
3.178765
[ "s887134160", "s760518272" ]
u225388820
p02913
python
s568088420
s127069338
421
84
77,704
10,848
Accepted
Accepted
80.05
def Z_algorithm(s): n = len(s) Z = [0] * n # z[i] = sum(s[0::n - i], s[i::n]) Z[0] = n i, j = 1, 0 while i < n: # 共通部分を見つけるパート while i + j < n and s[j] == s[i + j]: j += 1 Z[i] = j if j == 0: i += 1 continue # 計算の再利用パート # k + Z[k] < j なら再利用できる k = 1 while k < j and k + Z[k] < j: Z[i + k] = Z[k] k += 1 # k個先まで見たのでk個先にバトンを渡す i += k j -= k return Z def solve(k): a = Z_algorithm(s[k:]) ans = 0 for i in range(n - k): ans = max(ans, min(i, a[i])) return ans n, s = int(eval(input())), eval(input()) print((max(solve(i) for i in range(n))))
from random import randint class RollingHash: def __init__(self, s): self.base = [7073, 7577, 5445, 2742, 6972, 7547, 2267, 286, 6396, 7147, 3307, 188, 266, 8253, 2818, 9527, 5110, 1207, 4633, 6196, 309, 2646, 7533, 85, 9870, 4730, 6862, 9213, 7456, 7098, 6805, 674, 5821, 4864, 8061, 1826, 2219, 459, 5937, 5667, 9033, 5552, 7263, 2402, 9809, 3701, 7048, 2874, 8350, 6006, 973, 3317, 2522, 5546, 1669, 1545, 7972, 4979, 9905, 173, 6812, 7715, 5006, 6068, 6340, 4989, 5510, 6380, 1200, 6739, 5527, 4000, 6519, 3448, 2933, 6048, 3133, 1667, 9086, 8368, 4914, 7142, 2770, 7752, 391, 7052, 5476, 3105, 8322, 3501, 7454, 3167, 8730, 9002, 4564, 138, 2197, 7238, 3411, 7433][randint(0, 100)] self.mod = 4611686018427387903 self.size = len(s) self.string = s self.hash = self.make_hashtable(s) self.pow = self.make_powtable() def make_hashtable(self, _s): hashtable = [0] * (self.size + 1) for i in range(self.size): hashtable[i + 1] = (hashtable[i] * self.base + ord(_s[i])) % self.mod return hashtable def make_powtable(self): power = [1] * (self.size + 1) for i in range(self.size): power[i + 1] = (self.base * power[i]) % self.mod return power def get_hash(self, left, right): """get hash of s[left:right]""" return (self.hash[right] - self.hash[left] * self.pow[right - left]) % self.mod def contain(self, a): """return a in s""" m = len(a) if m > self.size: return False hashs = self.get_hash(0, m) hasha = 0 for i in range(m): hasha = (hasha * self.base + ord(a[i])) % self.mod for i in range(self.size - m + 1): if hasha == hashs: return True hashs = self.get_hash(i, m + i) return hasha == hashs from collections import defaultdict # d = defaultdict(int)で0で初期化 # d = defaultdict(lambda: 100)で100で初期化 n, s = int(eval(input())), eval(input()) rh = RollingHash(s) def check(m): d = defaultdict(lambda: 10000000) for i in range(n - m + 1): h = rh.get_hash(i, i + m) d[h] = min(d[h], i) # m以上離れていて2回目 if i - d[h] >= m: return True return False l, r = 0, n // 2 + 1 while l + 1 < r: mid = (l + r) // 2 if check(mid): l = mid else: r = mid print(l)
36
80
761
2,682
def Z_algorithm(s): n = len(s) Z = [0] * n # z[i] = sum(s[0::n - i], s[i::n]) Z[0] = n i, j = 1, 0 while i < n: # 共通部分を見つけるパート while i + j < n and s[j] == s[i + j]: j += 1 Z[i] = j if j == 0: i += 1 continue # 計算の再利用パート # k + Z[k] < j なら再利用できる k = 1 while k < j and k + Z[k] < j: Z[i + k] = Z[k] k += 1 # k個先まで見たのでk個先にバトンを渡す i += k j -= k return Z def solve(k): a = Z_algorithm(s[k:]) ans = 0 for i in range(n - k): ans = max(ans, min(i, a[i])) return ans n, s = int(eval(input())), eval(input()) print((max(solve(i) for i in range(n))))
from random import randint class RollingHash: def __init__(self, s): self.base = [ 7073, 7577, 5445, 2742, 6972, 7547, 2267, 286, 6396, 7147, 3307, 188, 266, 8253, 2818, 9527, 5110, 1207, 4633, 6196, 309, 2646, 7533, 85, 9870, 4730, 6862, 9213, 7456, 7098, 6805, 674, 5821, 4864, 8061, 1826, 2219, 459, 5937, 5667, 9033, 5552, 7263, 2402, 9809, 3701, 7048, 2874, 8350, 6006, 973, 3317, 2522, 5546, 1669, 1545, 7972, 4979, 9905, 173, 6812, 7715, 5006, 6068, 6340, 4989, 5510, 6380, 1200, 6739, 5527, 4000, 6519, 3448, 2933, 6048, 3133, 1667, 9086, 8368, 4914, 7142, 2770, 7752, 391, 7052, 5476, 3105, 8322, 3501, 7454, 3167, 8730, 9002, 4564, 138, 2197, 7238, 3411, 7433, ][randint(0, 100)] self.mod = 4611686018427387903 self.size = len(s) self.string = s self.hash = self.make_hashtable(s) self.pow = self.make_powtable() def make_hashtable(self, _s): hashtable = [0] * (self.size + 1) for i in range(self.size): hashtable[i + 1] = (hashtable[i] * self.base + ord(_s[i])) % self.mod return hashtable def make_powtable(self): power = [1] * (self.size + 1) for i in range(self.size): power[i + 1] = (self.base * power[i]) % self.mod return power def get_hash(self, left, right): """get hash of s[left:right]""" return (self.hash[right] - self.hash[left] * self.pow[right - left]) % self.mod def contain(self, a): """return a in s""" m = len(a) if m > self.size: return False hashs = self.get_hash(0, m) hasha = 0 for i in range(m): hasha = (hasha * self.base + ord(a[i])) % self.mod for i in range(self.size - m + 1): if hasha == hashs: return True hashs = self.get_hash(i, m + i) return hasha == hashs from collections import defaultdict # d = defaultdict(int)で0で初期化 # d = defaultdict(lambda: 100)で100で初期化 n, s = int(eval(input())), eval(input()) rh = RollingHash(s) def check(m): d = defaultdict(lambda: 10000000) for i in range(n - m + 1): h = rh.get_hash(i, i + m) d[h] = min(d[h], i) # m以上離れていて2回目 if i - d[h] >= m: return True return False l, r = 0, n // 2 + 1 while l + 1 < r: mid = (l + r) // 2 if check(mid): l = mid else: r = mid print(l)
false
55
[ "-def Z_algorithm(s):", "- n = len(s)", "- Z = [0] * n # z[i] = sum(s[0::n - i], s[i::n])", "- Z[0] = n", "- i, j = 1, 0", "- while i < n:", "- # 共通部分を見つけるパート", "- while i + j < n and s[j] == s[i + j]:", "- j += 1", "- Z[i] = j", "- if j == 0:", "- i += 1", "- continue", "- # 計算の再利用パート", "- # k + Z[k] < j なら再利用できる", "- k = 1", "- while k < j and k + Z[k] < j:", "- Z[i + k] = Z[k]", "- k += 1", "- # k個先まで見たのでk個先にバトンを渡す", "- i += k", "- j -= k", "- return Z", "+from random import randint", "-def solve(k):", "- a = Z_algorithm(s[k:])", "- ans = 0", "- for i in range(n - k):", "- ans = max(ans, min(i, a[i]))", "- return ans", "+class RollingHash:", "+ def __init__(self, s):", "+ self.base = [", "+ 7073,", "+ 7577,", "+ 5445,", "+ 2742,", "+ 6972,", "+ 7547,", "+ 2267,", "+ 286,", "+ 6396,", "+ 7147,", "+ 3307,", "+ 188,", "+ 266,", "+ 8253,", "+ 2818,", "+ 9527,", "+ 5110,", "+ 1207,", "+ 4633,", "+ 6196,", "+ 309,", "+ 2646,", "+ 7533,", "+ 85,", "+ 9870,", "+ 4730,", "+ 6862,", "+ 9213,", "+ 7456,", "+ 7098,", "+ 6805,", "+ 674,", "+ 5821,", "+ 4864,", "+ 8061,", "+ 1826,", "+ 2219,", "+ 459,", "+ 5937,", "+ 5667,", "+ 9033,", "+ 5552,", "+ 7263,", "+ 2402,", "+ 9809,", "+ 3701,", "+ 7048,", "+ 2874,", "+ 8350,", "+ 6006,", "+ 973,", "+ 3317,", "+ 2522,", "+ 5546,", "+ 1669,", "+ 1545,", "+ 7972,", "+ 4979,", "+ 9905,", "+ 173,", "+ 6812,", "+ 7715,", "+ 5006,", "+ 6068,", "+ 6340,", "+ 4989,", "+ 5510,", "+ 6380,", "+ 1200,", "+ 6739,", "+ 5527,", "+ 4000,", "+ 6519,", "+ 3448,", "+ 2933,", "+ 6048,", "+ 3133,", "+ 1667,", "+ 9086,", "+ 8368,", "+ 4914,", "+ 7142,", "+ 2770,", "+ 7752,", "+ 391,", "+ 7052,", "+ 5476,", "+ 3105,", "+ 8322,", "+ 3501,", "+ 7454,", "+ 3167,", "+ 8730,", "+ 9002,", "+ 4564,", "+ 138,", "+ 2197,", "+ 7238,", "+ 3411,", "+ 7433,", "+ ][randint(0, 100)]", "+ self.mod = 4611686018427387903", "+ self.size = len(s)", "+ self.string = s", "+ self.hash = self.make_hashtable(s)", "+ self.pow = self.make_powtable()", "+", "+ def make_hashtable(self, _s):", "+ hashtable = [0] * (self.size + 1)", "+ for i in range(self.size):", "+ hashtable[i + 1] = (hashtable[i] * self.base + ord(_s[i])) % self.mod", "+ return hashtable", "+", "+ def make_powtable(self):", "+ power = [1] * (self.size + 1)", "+ for i in range(self.size):", "+ power[i + 1] = (self.base * power[i]) % self.mod", "+ return power", "+", "+ def get_hash(self, left, right):", "+ \"\"\"get hash of s[left:right]\"\"\"", "+ return (self.hash[right] - self.hash[left] * self.pow[right - left]) % self.mod", "+", "+ def contain(self, a):", "+ \"\"\"return a in s\"\"\"", "+ m = len(a)", "+ if m > self.size:", "+ return False", "+ hashs = self.get_hash(0, m)", "+ hasha = 0", "+ for i in range(m):", "+ hasha = (hasha * self.base + ord(a[i])) % self.mod", "+ for i in range(self.size - m + 1):", "+ if hasha == hashs:", "+ return True", "+ hashs = self.get_hash(i, m + i)", "+ return hasha == hashs", "+from collections import defaultdict", "+", "+# d = defaultdict(int)で0で初期化", "+# d = defaultdict(lambda: 100)で100で初期化", "-print((max(solve(i) for i in range(n))))", "+rh = RollingHash(s)", "+", "+", "+def check(m):", "+ d = defaultdict(lambda: 10000000)", "+ for i in range(n - m + 1):", "+ h = rh.get_hash(i, i + m)", "+ d[h] = min(d[h], i)", "+ # m以上離れていて2回目", "+ if i - d[h] >= m:", "+ return True", "+ return False", "+", "+", "+l, r = 0, n // 2 + 1", "+while l + 1 < r:", "+ mid = (l + r) // 2", "+ if check(mid):", "+ l = mid", "+ else:", "+ r = mid", "+print(l)" ]
false
0.045711
0.042714
1.070147
[ "s568088420", "s127069338" ]
u142415823
p03625
python
s327947356
s536599783
135
89
18,600
14,252
Accepted
Accepted
34.07
import collections N = int(eval(input())) A = [int(i) for i in input().split()] stick_num = collections.Counter(A) flag = True ans = 0 for i in sorted(stick_num, reverse=True): if stick_num[i] >= 4: ans = i * i if flag else a * i break elif stick_num[i] >= 2: if flag: a = i flag = False else: ans = a * i break print(ans)
N = int(eval(input())) A = [int(i) for i in input().split()] A.sort(reverse=True) flag_h = True flag_v = True h, v = 0, 0 for i in A: if flag_h: if h == i: flag_h = False else: h = i elif flag_v: if v == i: flag_v = False else: v = i if not (flag_v and flag_h): print((h * v)) else: print((0))
21
24
427
405
import collections N = int(eval(input())) A = [int(i) for i in input().split()] stick_num = collections.Counter(A) flag = True ans = 0 for i in sorted(stick_num, reverse=True): if stick_num[i] >= 4: ans = i * i if flag else a * i break elif stick_num[i] >= 2: if flag: a = i flag = False else: ans = a * i break print(ans)
N = int(eval(input())) A = [int(i) for i in input().split()] A.sort(reverse=True) flag_h = True flag_v = True h, v = 0, 0 for i in A: if flag_h: if h == i: flag_h = False else: h = i elif flag_v: if v == i: flag_v = False else: v = i if not (flag_v and flag_h): print((h * v)) else: print((0))
false
12.5
[ "-import collections", "-", "-stick_num = collections.Counter(A)", "-flag = True", "-ans = 0", "-for i in sorted(stick_num, reverse=True):", "- if stick_num[i] >= 4:", "- ans = i * i if flag else a * i", "- break", "- elif stick_num[i] >= 2:", "- if flag:", "- a = i", "- flag = False", "+A.sort(reverse=True)", "+flag_h = True", "+flag_v = True", "+h, v = 0, 0", "+for i in A:", "+ if flag_h:", "+ if h == i:", "+ flag_h = False", "- ans = a * i", "- break", "-print(ans)", "+ h = i", "+ elif flag_v:", "+ if v == i:", "+ flag_v = False", "+ else:", "+ v = i", "+if not (flag_v and flag_h):", "+ print((h * v))", "+else:", "+ print((0))" ]
false
0.070103
0.03862
1.81519
[ "s327947356", "s536599783" ]
u518711553
p00002
python
s174599418
s010149725
30
20
7,704
7,472
Accepted
Accepted
33.33
import sys from operator import add from math import log10 for i in sys.stdin: print((int(log10(add(*list(map(int, i.split()))))) + 1))
import sys from operator import add for i in sys.stdin: print((len(str(add(*list(map(int, i.split())))))))
6
5
143
113
import sys from operator import add from math import log10 for i in sys.stdin: print((int(log10(add(*list(map(int, i.split()))))) + 1))
import sys from operator import add for i in sys.stdin: print((len(str(add(*list(map(int, i.split())))))))
false
16.666667
[ "-from math import log10", "- print((int(log10(add(*list(map(int, i.split()))))) + 1))", "+ print((len(str(add(*list(map(int, i.split())))))))" ]
false
0.038841
0.038066
1.020355
[ "s174599418", "s010149725" ]
u561083515
p03053
python
s658637199
s867199294
994
692
105,976
105,976
Accepted
Accepted
30.38
import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline H,W = list(map(int,input().split())) INF = 10**18 q = [] visited = [[True]*(W+2)] visited += [[True] + [x == '#' for x in input().rstrip()] + [True] for _ in range(H)] visited.append([True]*(W+2)) for i in range(1,H+1): for j in range(1,W+1): if visited[i][j]: q.append((i,j)) moves = [(0,1),(0,-1),(1,0),(-1,0)] ans = -1 while q: qq = [] ans += 1 for x,y in q: if not visited[x-1][y]: visited[x-1][y] = True qq.append((x-1,y)) if not visited[x+1][y]: visited[x+1][y] = True qq.append((x+1,y)) if not visited[x][y-1]: visited[x][y-1] = True qq.append((x,y-1)) if not visited[x][y+1]: visited[x][y+1] = True qq.append((x,y+1)) q = qq print(ans)
import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline def main(): H,W = list(map(int,input().split())) # 番兵法 (#を外周に設置する) visited = [[True]*(W+2)] visited += [[True] + [x == '#' for x in input().rstrip()] + [True] for _ in range(H)] visited.append([True]*(W+2)) # #の位置をqに格納 q = [] for i in range(1,H+1): for j in range(1,W+1): if visited[i][j]: q.append((i,j)) # dx,dyを使用せずにBFS # 定数倍改善 ans = -1 while q: qq = [] # 新たに#となった地点をqqに格納 for x,y in q: if not visited[x-1][y]: visited[x-1][y] = True qq.append((x-1,y)) if not visited[x+1][y]: visited[x+1][y] = True qq.append((x+1,y)) if not visited[x][y-1]: visited[x][y-1] = True qq.append((x,y-1)) if not visited[x][y+1]: visited[x][y+1] = True qq.append((x,y+1)) q = qq ans += 1 print(ans) if __name__ == '__main__': main()
39
45
836
1,138
import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline H, W = list(map(int, input().split())) INF = 10**18 q = [] visited = [[True] * (W + 2)] visited += [[True] + [x == "#" for x in input().rstrip()] + [True] for _ in range(H)] visited.append([True] * (W + 2)) for i in range(1, H + 1): for j in range(1, W + 1): if visited[i][j]: q.append((i, j)) moves = [(0, 1), (0, -1), (1, 0), (-1, 0)] ans = -1 while q: qq = [] ans += 1 for x, y in q: if not visited[x - 1][y]: visited[x - 1][y] = True qq.append((x - 1, y)) if not visited[x + 1][y]: visited[x + 1][y] = True qq.append((x + 1, y)) if not visited[x][y - 1]: visited[x][y - 1] = True qq.append((x, y - 1)) if not visited[x][y + 1]: visited[x][y + 1] = True qq.append((x, y + 1)) q = qq print(ans)
import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline def main(): H, W = list(map(int, input().split())) # 番兵法 (#を外周に設置する) visited = [[True] * (W + 2)] visited += [ [True] + [x == "#" for x in input().rstrip()] + [True] for _ in range(H) ] visited.append([True] * (W + 2)) # #の位置をqに格納 q = [] for i in range(1, H + 1): for j in range(1, W + 1): if visited[i][j]: q.append((i, j)) # dx,dyを使用せずにBFS # 定数倍改善 ans = -1 while q: qq = [] # 新たに#となった地点をqqに格納 for x, y in q: if not visited[x - 1][y]: visited[x - 1][y] = True qq.append((x - 1, y)) if not visited[x + 1][y]: visited[x + 1][y] = True qq.append((x + 1, y)) if not visited[x][y - 1]: visited[x][y - 1] = True qq.append((x, y - 1)) if not visited[x][y + 1]: visited[x][y + 1] = True qq.append((x, y + 1)) q = qq ans += 1 print(ans) if __name__ == "__main__": main()
false
13.333333
[ "-H, W = list(map(int, input().split()))", "-INF = 10**18", "-q = []", "-visited = [[True] * (W + 2)]", "-visited += [[True] + [x == \"#\" for x in input().rstrip()] + [True] for _ in range(H)]", "-visited.append([True] * (W + 2))", "-for i in range(1, H + 1):", "- for j in range(1, W + 1):", "- if visited[i][j]:", "- q.append((i, j))", "-moves = [(0, 1), (0, -1), (1, 0), (-1, 0)]", "-ans = -1", "-while q:", "- qq = []", "- ans += 1", "- for x, y in q:", "- if not visited[x - 1][y]:", "- visited[x - 1][y] = True", "- qq.append((x - 1, y))", "- if not visited[x + 1][y]:", "- visited[x + 1][y] = True", "- qq.append((x + 1, y))", "- if not visited[x][y - 1]:", "- visited[x][y - 1] = True", "- qq.append((x, y - 1))", "- if not visited[x][y + 1]:", "- visited[x][y + 1] = True", "- qq.append((x, y + 1))", "- q = qq", "-print(ans)", "+", "+", "+def main():", "+ H, W = list(map(int, input().split()))", "+ # 番兵法 (#を外周に設置する)", "+ visited = [[True] * (W + 2)]", "+ visited += [", "+ [True] + [x == \"#\" for x in input().rstrip()] + [True] for _ in range(H)", "+ ]", "+ visited.append([True] * (W + 2))", "+ # #の位置をqに格納", "+ q = []", "+ for i in range(1, H + 1):", "+ for j in range(1, W + 1):", "+ if visited[i][j]:", "+ q.append((i, j))", "+ # dx,dyを使用せずにBFS", "+ # 定数倍改善", "+ ans = -1", "+ while q:", "+ qq = []", "+ # 新たに#となった地点をqqに格納", "+ for x, y in q:", "+ if not visited[x - 1][y]:", "+ visited[x - 1][y] = True", "+ qq.append((x - 1, y))", "+ if not visited[x + 1][y]:", "+ visited[x + 1][y] = True", "+ qq.append((x + 1, y))", "+ if not visited[x][y - 1]:", "+ visited[x][y - 1] = True", "+ qq.append((x, y - 1))", "+ if not visited[x][y + 1]:", "+ visited[x][y + 1] = True", "+ qq.append((x, y + 1))", "+ q = qq", "+ ans += 1", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.036807
0.037626
0.978231
[ "s658637199", "s867199294" ]
u535171899
p03575
python
s086189622
s362854166
25
19
3,436
3,064
Accepted
Accepted
24
from collections import deque def dfs(n, start, graph): visited = [False] * n stack = deque() stack.append(start) visited[start] = True while stack: q = stack.popleft() nxts = graph[q] for nxt in nxts: if not visited[nxt]: visited[nxt] = True stack.append(nxt) return visited n, m = list(map(int, input().split())) edge = [list(map(int, input().split())) for _ in range(m)] ans = 0 for i in range(m): graph = [[] for _ in range(n)] for itr, (a, b) in enumerate(edge): if itr != i: graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) if not all(dfs(n, 0, graph)): ans += 1 print(ans)
n,m=list(map(int,input().split())) edge=[[] for _ in range(n+1)] eab=[] for i in range(m): a,b=list(map(int,input().split())) edge[a-1].append(b-1) edge[b-1].append(a-1) eab.append([a-1,b-1]) def dfs(visited,count,node): visited[node]=True count+=1 ev=edge[node] for node in ev: if visited[node]: continue else: count=dfs(visited,count,node) return count ans=0 for i in range(m): a,b=eab[i] edge[a].remove(b) edge[b].remove(a) ci=dfs([False for _ in range(n)],0,0) if ci!=n: ans+=1 edge[a].append(b) edge[b].append(a) print(ans)
30
31
687
661
from collections import deque def dfs(n, start, graph): visited = [False] * n stack = deque() stack.append(start) visited[start] = True while stack: q = stack.popleft() nxts = graph[q] for nxt in nxts: if not visited[nxt]: visited[nxt] = True stack.append(nxt) return visited n, m = list(map(int, input().split())) edge = [list(map(int, input().split())) for _ in range(m)] ans = 0 for i in range(m): graph = [[] for _ in range(n)] for itr, (a, b) in enumerate(edge): if itr != i: graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) if not all(dfs(n, 0, graph)): ans += 1 print(ans)
n, m = list(map(int, input().split())) edge = [[] for _ in range(n + 1)] eab = [] for i in range(m): a, b = list(map(int, input().split())) edge[a - 1].append(b - 1) edge[b - 1].append(a - 1) eab.append([a - 1, b - 1]) def dfs(visited, count, node): visited[node] = True count += 1 ev = edge[node] for node in ev: if visited[node]: continue else: count = dfs(visited, count, node) return count ans = 0 for i in range(m): a, b = eab[i] edge[a].remove(b) edge[b].remove(a) ci = dfs([False for _ in range(n)], 0, 0) if ci != n: ans += 1 edge[a].append(b) edge[b].append(a) print(ans)
false
3.225806
[ "-from collections import deque", "+n, m = list(map(int, input().split()))", "+edge = [[] for _ in range(n + 1)]", "+eab = []", "+for i in range(m):", "+ a, b = list(map(int, input().split()))", "+ edge[a - 1].append(b - 1)", "+ edge[b - 1].append(a - 1)", "+ eab.append([a - 1, b - 1])", "-def dfs(n, start, graph):", "- visited = [False] * n", "- stack = deque()", "- stack.append(start)", "- visited[start] = True", "- while stack:", "- q = stack.popleft()", "- nxts = graph[q]", "- for nxt in nxts:", "- if not visited[nxt]:", "- visited[nxt] = True", "- stack.append(nxt)", "- return visited", "+def dfs(visited, count, node):", "+ visited[node] = True", "+ count += 1", "+ ev = edge[node]", "+ for node in ev:", "+ if visited[node]:", "+ continue", "+ else:", "+ count = dfs(visited, count, node)", "+ return count", "-n, m = list(map(int, input().split()))", "-edge = [list(map(int, input().split())) for _ in range(m)]", "- graph = [[] for _ in range(n)]", "- for itr, (a, b) in enumerate(edge):", "- if itr != i:", "- graph[a - 1].append(b - 1)", "- graph[b - 1].append(a - 1)", "- if not all(dfs(n, 0, graph)):", "+ a, b = eab[i]", "+ edge[a].remove(b)", "+ edge[b].remove(a)", "+ ci = dfs([False for _ in range(n)], 0, 0)", "+ if ci != n:", "+ edge[a].append(b)", "+ edge[b].append(a)" ]
false
0.130989
0.066719
1.963293
[ "s086189622", "s362854166" ]
u110656379
p03043
python
s997166375
s050315204
63
48
2,940
2,940
Accepted
Accepted
23.81
n,k=list(map(int,input().split())) answer=0 for i in range(n): j=1 while (i+1)*j<k: j*=2 answer+=1/j*1/n print(answer)
n,k=list(map(int,input().split())) m=0 for i in range(1,n+1): l=k j=0 while l>i: l/=2 j+=1 m+=1/n*((1/2)**j) print(m)
8
10
129
136
n, k = list(map(int, input().split())) answer = 0 for i in range(n): j = 1 while (i + 1) * j < k: j *= 2 answer += 1 / j * 1 / n print(answer)
n, k = list(map(int, input().split())) m = 0 for i in range(1, n + 1): l = k j = 0 while l > i: l /= 2 j += 1 m += 1 / n * ((1 / 2) ** j) print(m)
false
20
[ "-answer = 0", "-for i in range(n):", "- j = 1", "- while (i + 1) * j < k:", "- j *= 2", "- answer += 1 / j * 1 / n", "-print(answer)", "+m = 0", "+for i in range(1, n + 1):", "+ l = k", "+ j = 0", "+ while l > i:", "+ l /= 2", "+ j += 1", "+ m += 1 / n * ((1 / 2) ** j)", "+print(m)" ]
false
0.007739
0.052126
0.14847
[ "s997166375", "s050315204" ]
u896741788
p03911
python
s454626361
s080211979
753
684
62,936
62,808
Accepted
Accepted
9.16
n,m=map(int,input().split()) class UnionFind: #def -> foo=UnionFind(n,1) <- 1-based index, default is 0 #method -> foo.hoge(huga) __slots__ = ["_size", "_first_idx", "_parents"] def __init__(self, size: int, first_index: int = 0) -> None: self._size = size self._first_idx = first_index self._parents = [-1] * (size + first_index) def find(self, x: int) -> int: if self._parents[x] < 0: return x self._parents[x] = self.find(self._parents[x]) return self._parents[x] def same(self, x: int, y: int) -> bool: return self.find(x) == self.find(y) def unite(self, x: int, y: int) -> bool: x, y = self.find(x), self.find(y) if x == y: return False if self._parents[x] > self._parents[y]: x, y = y, x self._parents[x] += self._parents[y] self._parents[y] = x return True def size(self, x: int) -> int: return -self._parents[self.find(x)] def group_count(self) ->int: return sum(1 for i in self._parents if i<0) lanper=[-1]*m uf=UnionFind(n) for i in range(n): for j in list(map(int,input().split()))[1:]: if lanper[j-1]==-1:lanper[j-1]=i else:uf.unite(lanper[j-1],i) print("YES") if uf.group_count()==1 else print("NO")
n,m=map(int,input().split()) class UnionFind: #def -> foo=UnionFind(n,1) <- 1-based index, default is 0 #method -> foo.hoge(huga) __slots__ = ["_size", "_first_idx", "_parents"] def __init__(self, size: int, first_index: int = 0) -> None: self._size = size self._first_idx = first_index self._parents = [-1] * (size + first_index) def find(self, x: int) -> int: if self._parents[x] < 0: return x self._parents[x] = self.find(self._parents[x]) return self._parents[x] def same(self, x: int, y: int) -> bool: return self.find(x) == self.find(y) def unite(self, x: int, y: int) -> bool: x, y = self.find(x), self.find(y) if x == y: return False if self._parents[x] > self._parents[y]: x, y = y, x self._parents[x] += self._parents[y] self._parents[y] = x return True def size(self, x: int) -> int: return -self._parents[self.find(x)] def group_count(self) ->int: return sum(1 for i in self._parents if i<0) lanper=[-1]*m uf=UnionFind(n) for i in range(n): for j in list(map(int,input().split()))[1:]: if lanper[j-1]==-1:lanper[j-1]=i else:uf.unite(lanper[j-1],i) print("YES") if uf.size(0)==n else print("NO")
36
36
1,364
1,358
n, m = map(int, input().split()) class UnionFind: # def -> foo=UnionFind(n,1) <- 1-based index, default is 0 # method -> foo.hoge(huga) __slots__ = ["_size", "_first_idx", "_parents"] def __init__(self, size: int, first_index: int = 0) -> None: self._size = size self._first_idx = first_index self._parents = [-1] * (size + first_index) def find(self, x: int) -> int: if self._parents[x] < 0: return x self._parents[x] = self.find(self._parents[x]) return self._parents[x] def same(self, x: int, y: int) -> bool: return self.find(x) == self.find(y) def unite(self, x: int, y: int) -> bool: x, y = self.find(x), self.find(y) if x == y: return False if self._parents[x] > self._parents[y]: x, y = y, x self._parents[x] += self._parents[y] self._parents[y] = x return True def size(self, x: int) -> int: return -self._parents[self.find(x)] def group_count(self) -> int: return sum(1 for i in self._parents if i < 0) lanper = [-1] * m uf = UnionFind(n) for i in range(n): for j in list(map(int, input().split()))[1:]: if lanper[j - 1] == -1: lanper[j - 1] = i else: uf.unite(lanper[j - 1], i) print("YES") if uf.group_count() == 1 else print("NO")
n, m = map(int, input().split()) class UnionFind: # def -> foo=UnionFind(n,1) <- 1-based index, default is 0 # method -> foo.hoge(huga) __slots__ = ["_size", "_first_idx", "_parents"] def __init__(self, size: int, first_index: int = 0) -> None: self._size = size self._first_idx = first_index self._parents = [-1] * (size + first_index) def find(self, x: int) -> int: if self._parents[x] < 0: return x self._parents[x] = self.find(self._parents[x]) return self._parents[x] def same(self, x: int, y: int) -> bool: return self.find(x) == self.find(y) def unite(self, x: int, y: int) -> bool: x, y = self.find(x), self.find(y) if x == y: return False if self._parents[x] > self._parents[y]: x, y = y, x self._parents[x] += self._parents[y] self._parents[y] = x return True def size(self, x: int) -> int: return -self._parents[self.find(x)] def group_count(self) -> int: return sum(1 for i in self._parents if i < 0) lanper = [-1] * m uf = UnionFind(n) for i in range(n): for j in list(map(int, input().split()))[1:]: if lanper[j - 1] == -1: lanper[j - 1] = i else: uf.unite(lanper[j - 1], i) print("YES") if uf.size(0) == n else print("NO")
false
0
[ "-print(\"YES\") if uf.group_count() == 1 else print(\"NO\")", "+print(\"YES\") if uf.size(0) == n else print(\"NO\")" ]
false
0.126879
0.084037
1.509804
[ "s454626361", "s080211979" ]
u784022244
p02990
python
s641436625
s888385112
608
24
3,944
3,572
Accepted
Accepted
96.05
N, K=list(map(int, input().split())) mod=10**9+7 #青K個 赤NーK個 #青をi個に分ける K-1Ci-1 #赤1個以上を仕切りに振り分ける (両端含むが、両端は0でもOK) #N-KCi-2+N-KCi-1+N-KCi #1997C1+ from operator import mul from functools import reduce def cmb(n,r): r = min(n-r,r) if r == 0: return 1 over = reduce(mul, list(range(n, n - r, -1))) under = reduce(mul, list(range(1,r + 1))) return over // under for i in range(1,K+1): if i==1: print(((N-K+1)%mod)) else: try: a=cmb(N-K-1, i-2)%mod except: a=0 try: b=cmb(N-K-1, i-1)%mod except: b=0 try: c=cmb(N-K-1, i)%mod except: c=0 try: d=cmb(K-1, i-1)%mod except: d=0 ans=(a+2*b+c)*d print((ans%mod))
n,k=list(map(int, input().split())) def cmb(n, r, p): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n-r] % p p = 10 ** 9 + 7 N = 2000 # N は必要分だけ用意する fact = [1, 1] # fact[n] = (n! mod p) 階乗のmod factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p) inv = [0, 1] # factinv 計算用 for i in range(2, N + 1): fact.append((fact[-1] * i) % p) inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1] * inv[-1]) % p) for i in range(k): ans=(cmb(k-1,i,p)*cmb(n-k+1,i+1,p))%p print(ans)
41
21
735
568
N, K = list(map(int, input().split())) mod = 10**9 + 7 # 青K個 赤NーK個 # 青をi個に分ける K-1Ci-1 # 赤1個以上を仕切りに振り分ける (両端含むが、両端は0でもOK) # N-KCi-2+N-KCi-1+N-KCi # 1997C1+ from operator import mul from functools import reduce def cmb(n, r): r = min(n - r, r) if r == 0: return 1 over = reduce(mul, list(range(n, n - r, -1))) under = reduce(mul, list(range(1, r + 1))) return over // under for i in range(1, K + 1): if i == 1: print(((N - K + 1) % mod)) else: try: a = cmb(N - K - 1, i - 2) % mod except: a = 0 try: b = cmb(N - K - 1, i - 1) % mod except: b = 0 try: c = cmb(N - K - 1, i) % mod except: c = 0 try: d = cmb(K - 1, i - 1) % mod except: d = 0 ans = (a + 2 * b + c) * d print((ans % mod))
n, k = list(map(int, input().split())) def cmb(n, r, p): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n - r] % p p = 10**9 + 7 N = 2000 # N は必要分だけ用意する fact = [1, 1] # fact[n] = (n! mod p) 階乗のmod factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p) inv = [0, 1] # factinv 計算用 for i in range(2, N + 1): fact.append((fact[-1] * i) % p) inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1] * inv[-1]) % p) for i in range(k): ans = (cmb(k - 1, i, p) * cmb(n - k + 1, i + 1, p)) % p print(ans)
false
48.780488
[ "-N, K = list(map(int, input().split()))", "-mod = 10**9 + 7", "-# 青K個 赤NーK個", "-# 青をi個に分ける K-1Ci-1", "-# 赤1個以上を仕切りに振り分ける (両端含むが、両端は0でもOK)", "-# N-KCi-2+N-KCi-1+N-KCi", "-# 1997C1+", "-from operator import mul", "-from functools import reduce", "+n, k = list(map(int, input().split()))", "-def cmb(n, r):", "- r = min(n - r, r)", "- if r == 0:", "- return 1", "- over = reduce(mul, list(range(n, n - r, -1)))", "- under = reduce(mul, list(range(1, r + 1)))", "- return over // under", "+def cmb(n, r, p):", "+ if (r < 0) or (n < r):", "+ return 0", "+ r = min(r, n - r)", "+ return fact[n] * factinv[r] * factinv[n - r] % p", "-for i in range(1, K + 1):", "- if i == 1:", "- print(((N - K + 1) % mod))", "- else:", "- try:", "- a = cmb(N - K - 1, i - 2) % mod", "- except:", "- a = 0", "- try:", "- b = cmb(N - K - 1, i - 1) % mod", "- except:", "- b = 0", "- try:", "- c = cmb(N - K - 1, i) % mod", "- except:", "- c = 0", "- try:", "- d = cmb(K - 1, i - 1) % mod", "- except:", "- d = 0", "- ans = (a + 2 * b + c) * d", "- print((ans % mod))", "+p = 10**9 + 7", "+N = 2000 # N は必要分だけ用意する", "+fact = [1, 1] # fact[n] = (n! mod p) 階乗のmod", "+factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)", "+inv = [0, 1] # factinv 計算用", "+for i in range(2, N + 1):", "+ fact.append((fact[-1] * i) % p)", "+ inv.append((-inv[p % i] * (p // i)) % p)", "+ factinv.append((factinv[-1] * inv[-1]) % p)", "+for i in range(k):", "+ ans = (cmb(k - 1, i, p) * cmb(n - k + 1, i + 1, p)) % p", "+ print(ans)" ]
false
0.039116
0.039724
0.984709
[ "s641436625", "s888385112" ]
u530606147
p02708
python
s864934010
s653566170
136
22
9,184
9,168
Accepted
Accepted
83.82
n, k = list(map(int, input().split())) MOD = 10**9 + 7 ans = 0 for c in range(k, n + 2): m = c * (c - 1) // 2 M = c * (2 * (n + 1) - c - 1) // 2 ans += M - m + 1 ans %= MOD print(ans)
n, k = list(map(int, input().split())) MOD = 10**9 + 7 print(((-2 + k - n) * (-6 - 2 * k + 2 * k**2 - n - k * n - n**2) // 6 % MOD))
12
3
206
132
n, k = list(map(int, input().split())) MOD = 10**9 + 7 ans = 0 for c in range(k, n + 2): m = c * (c - 1) // 2 M = c * (2 * (n + 1) - c - 1) // 2 ans += M - m + 1 ans %= MOD print(ans)
n, k = list(map(int, input().split())) MOD = 10**9 + 7 print(((-2 + k - n) * (-6 - 2 * k + 2 * k**2 - n - k * n - n**2) // 6 % MOD))
false
75
[ "-ans = 0", "-for c in range(k, n + 2):", "- m = c * (c - 1) // 2", "- M = c * (2 * (n + 1) - c - 1) // 2", "- ans += M - m + 1", "- ans %= MOD", "-print(ans)", "+print(((-2 + k - n) * (-6 - 2 * k + 2 * k**2 - n - k * n - n**2) // 6 % MOD))" ]
false
0.080956
0.034277
2.361825
[ "s864934010", "s653566170" ]
u203962828
p02711
python
s804946265
s457252801
31
28
9,048
9,020
Accepted
Accepted
9.68
n = str(eval(input())) if n[0] == '7' or n[1] == '7' or n[2] == '7': print('Yes') else: print('No')
n = list(eval(input())) for i in n: if '7' in n: print('Yes') break else: print('No') break
6
9
107
134
n = str(eval(input())) if n[0] == "7" or n[1] == "7" or n[2] == "7": print("Yes") else: print("No")
n = list(eval(input())) for i in n: if "7" in n: print("Yes") break else: print("No") break
false
33.333333
[ "-n = str(eval(input()))", "-if n[0] == \"7\" or n[1] == \"7\" or n[2] == \"7\":", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+n = list(eval(input()))", "+for i in n:", "+ if \"7\" in n:", "+ print(\"Yes\")", "+ break", "+ else:", "+ print(\"No\")", "+ break" ]
false
0.035313
0.03489
1.012117
[ "s804946265", "s457252801" ]
u057109575
p02837
python
s258322913
s832912401
303
100
50,672
74,104
Accepted
Accepted
67
N = int(eval(input())) A = [0] * N XY = [] for i in range(N): tmp = [] a = int(eval(input())) A[i] = a for j in range(a): tmp.append(list(map(int, input().split()))) XY.append(tmp) def counter(x): if x == 0: return 0 else: return counter(x >> 1) + (x & 1) ans = 0 for bits in range(1, 1 << N): ok = True for i in range(N): if not (bits & (1 << i)): continue for x, y in XY[i]: if ((bits >> (x - 1)) & 1) ^ y: ok = False if ok: ans = max(ans, counter(bits)) print(ans)
N = int(eval(input())) X = {} for i in range(N): A = int(eval(input())) tmp = [list(map(int, input().split())) for _ in range(A)] X[i] = tmp ans = 0 for bit in range(2 ** N): tmp = bit flag = True for i in range(N): if not (bit >> i & 1): continue for x, y in X[i]: if (bit >> (x - 1) & 1) != y: flag = False break if flag: ans = max(ans, bin(bit).count("1")) print(ans)
33
25
662
512
N = int(eval(input())) A = [0] * N XY = [] for i in range(N): tmp = [] a = int(eval(input())) A[i] = a for j in range(a): tmp.append(list(map(int, input().split()))) XY.append(tmp) def counter(x): if x == 0: return 0 else: return counter(x >> 1) + (x & 1) ans = 0 for bits in range(1, 1 << N): ok = True for i in range(N): if not (bits & (1 << i)): continue for x, y in XY[i]: if ((bits >> (x - 1)) & 1) ^ y: ok = False if ok: ans = max(ans, counter(bits)) print(ans)
N = int(eval(input())) X = {} for i in range(N): A = int(eval(input())) tmp = [list(map(int, input().split())) for _ in range(A)] X[i] = tmp ans = 0 for bit in range(2**N): tmp = bit flag = True for i in range(N): if not (bit >> i & 1): continue for x, y in X[i]: if (bit >> (x - 1) & 1) != y: flag = False break if flag: ans = max(ans, bin(bit).count("1")) print(ans)
false
24.242424
[ "-A = [0] * N", "-XY = []", "+X = {}", "- tmp = []", "- a = int(eval(input()))", "- A[i] = a", "- for j in range(a):", "- tmp.append(list(map(int, input().split())))", "- XY.append(tmp)", "-", "-", "-def counter(x):", "- if x == 0:", "- return 0", "- else:", "- return counter(x >> 1) + (x & 1)", "-", "-", "+ A = int(eval(input()))", "+ tmp = [list(map(int, input().split())) for _ in range(A)]", "+ X[i] = tmp", "-for bits in range(1, 1 << N):", "- ok = True", "+for bit in range(2**N):", "+ tmp = bit", "+ flag = True", "- if not (bits & (1 << i)):", "+ if not (bit >> i & 1):", "- for x, y in XY[i]:", "- if ((bits >> (x - 1)) & 1) ^ y:", "- ok = False", "- if ok:", "- ans = max(ans, counter(bits))", "+ for x, y in X[i]:", "+ if (bit >> (x - 1) & 1) != y:", "+ flag = False", "+ break", "+ if flag:", "+ ans = max(ans, bin(bit).count(\"1\"))" ]
false
0.085676
0.04902
1.747765
[ "s258322913", "s832912401" ]
u896741788
p03546
python
s911766056
s612239062
353
236
3,064
96,348
Accepted
Accepted
33.14
h,w=list(map(int,input().split())) tra=[list(map(int,input().split())) for i in range(10)] ll=[[tra[i][j] for j in range(10)] for i in range(10)] for i in range(10**3-1): for i in range(10): for j in range(10): if i!=j: ll[i][j]=min(ll[i][j],min(ll[i][o]+tra[o][j] for o in range(10) if o!=i and o!=j)) ans=0 for i in range(h): for j in map(int,input().split()): if j==-1 or j==1:continue ans+=ll[j][1] print(ans)
class WarshallFloyd: #O(V^3)で任意2頂点の最短距離 def __init__(self,n,_first_index=0): self.v = n self._first_idx=_first_index self.d = [[float("INF")]*(n) for _ in range(n)] for i in range(n): self.d[i][i] = 0 def path(self,x,y,c): if x == y: return False f=self._first_idx self.d[x-f][y-f] = c return True def build(self): for k in range(self.v): for i in range(self.v): for j in range(self.v): self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j]) return self.d h,w=list(map(int,input().split())) war=WarshallFloyd(10) for i in range(10): s=list(map(int,input().split())) for j in range(10): war.path(i,j,s[j]) dis=war.build() from collections import Counter as co l=[list(map(int,input().split())) for i in range(h)] l=sum(l,[]) var=list(co(l).items()) print((sum([0]+[v*dis[k][1] for k,v in var if k!=-1])))
14
35
480
1,017
h, w = list(map(int, input().split())) tra = [list(map(int, input().split())) for i in range(10)] ll = [[tra[i][j] for j in range(10)] for i in range(10)] for i in range(10**3 - 1): for i in range(10): for j in range(10): if i != j: ll[i][j] = min( ll[i][j], min(ll[i][o] + tra[o][j] for o in range(10) if o != i and o != j), ) ans = 0 for i in range(h): for j in map(int, input().split()): if j == -1 or j == 1: continue ans += ll[j][1] print(ans)
class WarshallFloyd: # O(V^3)で任意2頂点の最短距離 def __init__(self, n, _first_index=0): self.v = n self._first_idx = _first_index self.d = [[float("INF")] * (n) for _ in range(n)] for i in range(n): self.d[i][i] = 0 def path(self, x, y, c): if x == y: return False f = self._first_idx self.d[x - f][y - f] = c return True def build(self): for k in range(self.v): for i in range(self.v): for j in range(self.v): self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j]) return self.d h, w = list(map(int, input().split())) war = WarshallFloyd(10) for i in range(10): s = list(map(int, input().split())) for j in range(10): war.path(i, j, s[j]) dis = war.build() from collections import Counter as co l = [list(map(int, input().split())) for i in range(h)] l = sum(l, []) var = list(co(l).items()) print((sum([0] + [v * dis[k][1] for k, v in var if k != -1])))
false
60
[ "+class WarshallFloyd:", "+ # O(V^3)で任意2頂点の最短距離", "+ def __init__(self, n, _first_index=0):", "+ self.v = n", "+ self._first_idx = _first_index", "+ self.d = [[float(\"INF\")] * (n) for _ in range(n)]", "+ for i in range(n):", "+ self.d[i][i] = 0", "+", "+ def path(self, x, y, c):", "+ if x == y:", "+ return False", "+ f = self._first_idx", "+ self.d[x - f][y - f] = c", "+ return True", "+", "+ def build(self):", "+ for k in range(self.v):", "+ for i in range(self.v):", "+ for j in range(self.v):", "+ self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j])", "+ return self.d", "+", "+", "-tra = [list(map(int, input().split())) for i in range(10)]", "-ll = [[tra[i][j] for j in range(10)] for i in range(10)]", "-for i in range(10**3 - 1):", "- for i in range(10):", "- for j in range(10):", "- if i != j:", "- ll[i][j] = min(", "- ll[i][j],", "- min(ll[i][o] + tra[o][j] for o in range(10) if o != i and o != j),", "- )", "-ans = 0", "-for i in range(h):", "- for j in map(int, input().split()):", "- if j == -1 or j == 1:", "- continue", "- ans += ll[j][1]", "-print(ans)", "+war = WarshallFloyd(10)", "+for i in range(10):", "+ s = list(map(int, input().split()))", "+ for j in range(10):", "+ war.path(i, j, s[j])", "+dis = war.build()", "+from collections import Counter as co", "+", "+l = [list(map(int, input().split())) for i in range(h)]", "+l = sum(l, [])", "+var = list(co(l).items())", "+print((sum([0] + [v * dis[k][1] for k, v in var if k != -1])))" ]
false
0.007946
0.04392
0.18093
[ "s911766056", "s612239062" ]
u002459665
p02813
python
s600602252
s939776638
45
27
15,092
8,052
Accepted
Accepted
40
N = int(eval(input())) P = list(map(int, input().split())) Q = list(map(int, input().split())) import itertools A = [i for i in range(1, N+1)] T = [list(i) for i in list(itertools.permutations(A, N))] # print(T) n1 = T.index(P) n2 = T.index(Q) print((abs(n1-n2)))
N = int(eval(input())) P = tuple(map(int, input().split())) Q = tuple(map(int, input().split())) from itertools import permutations t = [i for i in range(1, N+1)] r = list(permutations(t)) # print(P) # print(Q) i1 = r.index(P) i2 = r.index(Q) print((abs(i1-i2)))
13
15
270
272
N = int(eval(input())) P = list(map(int, input().split())) Q = list(map(int, input().split())) import itertools A = [i for i in range(1, N + 1)] T = [list(i) for i in list(itertools.permutations(A, N))] # print(T) n1 = T.index(P) n2 = T.index(Q) print((abs(n1 - n2)))
N = int(eval(input())) P = tuple(map(int, input().split())) Q = tuple(map(int, input().split())) from itertools import permutations t = [i for i in range(1, N + 1)] r = list(permutations(t)) # print(P) # print(Q) i1 = r.index(P) i2 = r.index(Q) print((abs(i1 - i2)))
false
13.333333
[ "-P = list(map(int, input().split()))", "-Q = list(map(int, input().split()))", "-import itertools", "+P = tuple(map(int, input().split()))", "+Q = tuple(map(int, input().split()))", "+from itertools import permutations", "-A = [i for i in range(1, N + 1)]", "-T = [list(i) for i in list(itertools.permutations(A, N))]", "-# print(T)", "-n1 = T.index(P)", "-n2 = T.index(Q)", "-print((abs(n1 - n2)))", "+t = [i for i in range(1, N + 1)]", "+r = list(permutations(t))", "+# print(P)", "+# print(Q)", "+i1 = r.index(P)", "+i2 = r.index(Q)", "+print((abs(i1 - i2)))" ]
false
0.107709
0.054405
1.979763
[ "s600602252", "s939776638" ]
u759412327
p04030
python
s063038469
s738715323
19
17
2,940
2,940
Accepted
Accepted
10.53
S = input() a = [] for s in S: if s=="B": if a: a.pop() else: a.append(s) print(*a,sep="")
a = "" for s in eval(input()): if s=="B": a=a[:-1] else: a+=s print(a)
11
9
120
86
S = input() a = [] for s in S: if s == "B": if a: a.pop() else: a.append(s) print(*a, sep="")
a = "" for s in eval(input()): if s == "B": a = a[:-1] else: a += s print(a)
false
18.181818
[ "-S = input()", "-a = []", "-for s in S:", "+a = \"\"", "+for s in eval(input()):", "- if a:", "- a.pop()", "+ a = a[:-1]", "- a.append(s)", "-print(*a, sep=\"\")", "+ a += s", "+print(a)" ]
false
0.070651
0.070788
0.998061
[ "s063038469", "s738715323" ]
u409064224
p03037
python
s280783340
s291294291
347
282
16,616
3,060
Accepted
Accepted
18.73
n,m = list(map(int,input().split())) src = [tuple(map(int,input().split())) for i in range(m)] l_max,r_min = 0,10**5 for l,r in src: l_max = max(l_max,l) for l,r in src: r_min = min(r_min,r) else: if r_min-l_max < 0: print((0)) else: print((r_min-l_max+1))
n,m = list(map(int,input().split())) ll = 0 rr = 10**5+1 for i in range(m): l,r = list(map(int,input().split())) if l > ll: ll = l if r < rr: rr = r else: #print(rr-ll+1) if rr-ll+1>n: print(n) elif rr-ll+1<0: print((0)) else: print((rr-ll+1))
14
17
301
312
n, m = list(map(int, input().split())) src = [tuple(map(int, input().split())) for i in range(m)] l_max, r_min = 0, 10**5 for l, r in src: l_max = max(l_max, l) for l, r in src: r_min = min(r_min, r) else: if r_min - l_max < 0: print((0)) else: print((r_min - l_max + 1))
n, m = list(map(int, input().split())) ll = 0 rr = 10**5 + 1 for i in range(m): l, r = list(map(int, input().split())) if l > ll: ll = l if r < rr: rr = r else: # print(rr-ll+1) if rr - ll + 1 > n: print(n) elif rr - ll + 1 < 0: print((0)) else: print((rr - ll + 1))
false
17.647059
[ "-src = [tuple(map(int, input().split())) for i in range(m)]", "-l_max, r_min = 0, 10**5", "-for l, r in src:", "- l_max = max(l_max, l)", "-for l, r in src:", "- r_min = min(r_min, r)", "+ll = 0", "+rr = 10**5 + 1", "+for i in range(m):", "+ l, r = list(map(int, input().split()))", "+ if l > ll:", "+ ll = l", "+ if r < rr:", "+ rr = r", "- if r_min - l_max < 0:", "+ # print(rr-ll+1)", "+ if rr - ll + 1 > n:", "+ print(n)", "+ elif rr - ll + 1 < 0:", "- print((r_min - l_max + 1))", "+ print((rr - ll + 1))" ]
false
0.039764
0.038392
1.035736
[ "s280783340", "s291294291" ]
u693953100
p02829
python
s822169432
s718869984
22
17
3,316
2,940
Accepted
Accepted
22.73
a = int(eval(input())) b = int(eval(input())) print((6-a-b))
def solve(): a=int(eval(input())) b=int(eval(input())) print((6-a-b)) if __name__ == "__main__": solve()
3
6
48
111
a = int(eval(input())) b = int(eval(input())) print((6 - a - b))
def solve(): a = int(eval(input())) b = int(eval(input())) print((6 - a - b)) if __name__ == "__main__": solve()
false
50
[ "-a = int(eval(input()))", "-b = int(eval(input()))", "-print((6 - a - b))", "+def solve():", "+ a = int(eval(input()))", "+ b = int(eval(input()))", "+ print((6 - a - b))", "+", "+", "+if __name__ == \"__main__\":", "+ solve()" ]
false
0.037723
0.039214
0.961995
[ "s822169432", "s718869984" ]
u784022244
p02678
python
s381587957
s951323999
1,320
695
33,640
33,928
Accepted
Accepted
47.35
N,M=list(map(int, input().split())) G=[[] for _ in range(N)] for i in range(M): a,b=list(map(int, input().split())) G[a-1].append(b-1) G[b-1].append(a-1) siru=[-1]*(N-1)#2~~N que=[0] while len(que)>0: #print(que) now=que.pop(0) nexlist=G[now] for nex in nexlist: if nex==0: continue if siru[nex-1]==-1: siru[nex-1]=now que.append(nex) X=siru.count(-1) if X>=1: print("No") else: print("Yes") for num in siru: print((num+1))
from collections import deque N,M=list(map(int, input().split())) G=[[] for _ in range(N)] for i in range(M): a,b=list(map(int, input().split())) G[a-1].append(b-1) G[b-1].append(a-1) siru=[-1]*(N-1)#2~~N que=deque([0]) while que: #print(que) now=que.popleft() nexlist=G[now] for nex in nexlist: if nex==0: continue if siru[nex-1]==-1: siru[nex-1]=now que.append(nex) X=siru.count(-1) if X>=1: print("No") else: print("Yes") for num in siru: print((num+1))
27
28
538
572
N, M = list(map(int, input().split())) G = [[] for _ in range(N)] for i in range(M): a, b = list(map(int, input().split())) G[a - 1].append(b - 1) G[b - 1].append(a - 1) siru = [-1] * (N - 1) # 2~~N que = [0] while len(que) > 0: # print(que) now = que.pop(0) nexlist = G[now] for nex in nexlist: if nex == 0: continue if siru[nex - 1] == -1: siru[nex - 1] = now que.append(nex) X = siru.count(-1) if X >= 1: print("No") else: print("Yes") for num in siru: print((num + 1))
from collections import deque N, M = list(map(int, input().split())) G = [[] for _ in range(N)] for i in range(M): a, b = list(map(int, input().split())) G[a - 1].append(b - 1) G[b - 1].append(a - 1) siru = [-1] * (N - 1) # 2~~N que = deque([0]) while que: # print(que) now = que.popleft() nexlist = G[now] for nex in nexlist: if nex == 0: continue if siru[nex - 1] == -1: siru[nex - 1] = now que.append(nex) X = siru.count(-1) if X >= 1: print("No") else: print("Yes") for num in siru: print((num + 1))
false
3.571429
[ "+from collections import deque", "+", "-que = [0]", "-while len(que) > 0:", "+que = deque([0])", "+while que:", "- now = que.pop(0)", "+ now = que.popleft()" ]
false
0.04046
0.044501
0.909205
[ "s381587957", "s951323999" ]
u163703551
p02783
python
s285232796
s886702444
28
25
3,696
3,572
Accepted
Accepted
10.71
import sys import socket hostname = socket.gethostname() if hostname == 'F451C': sys.stdin = open('a1.in') def read_int_list(): return list(map(int, input().split())) def read_str_list(): return input().split() def read_int(): return int(eval(input())) def read_str(): return eval(input()) def main(): H, A = read_int_list() res = 0 for i in range(10001): H = H - A res += 1 if H <= 0: break print(res) main()
import sys import socket hostname = socket.gethostname() if hostname == 'F451C': sys.stdin = open('a1.in') def read_int_list(): return list(map(int, input().split())) def read_str_list(): return input().split() def read_int(): return int(eval(input())) def read_str(): return eval(input()) def main_0(): H, A = read_int_list() res = 0 for i in range(10001): H = H - A res += 1 if H <= 0: break print(res) def main_1(): H, A = read_int_list() res = H // A if H % A != 0: res += 1 print(res) def main(): H, A = read_int_list() res = 0 while H > 0: H -= A res += 1 print(res) main()
37
53
510
749
import sys import socket hostname = socket.gethostname() if hostname == "F451C": sys.stdin = open("a1.in") def read_int_list(): return list(map(int, input().split())) def read_str_list(): return input().split() def read_int(): return int(eval(input())) def read_str(): return eval(input()) def main(): H, A = read_int_list() res = 0 for i in range(10001): H = H - A res += 1 if H <= 0: break print(res) main()
import sys import socket hostname = socket.gethostname() if hostname == "F451C": sys.stdin = open("a1.in") def read_int_list(): return list(map(int, input().split())) def read_str_list(): return input().split() def read_int(): return int(eval(input())) def read_str(): return eval(input()) def main_0(): H, A = read_int_list() res = 0 for i in range(10001): H = H - A res += 1 if H <= 0: break print(res) def main_1(): H, A = read_int_list() res = H // A if H % A != 0: res += 1 print(res) def main(): H, A = read_int_list() res = 0 while H > 0: H -= A res += 1 print(res) main()
false
30.188679
[ "-def main():", "+def main_0():", "+def main_1():", "+ H, A = read_int_list()", "+ res = H // A", "+ if H % A != 0:", "+ res += 1", "+ print(res)", "+", "+", "+def main():", "+ H, A = read_int_list()", "+ res = 0", "+ while H > 0:", "+ H -= A", "+ res += 1", "+ print(res)", "+", "+" ]
false
0.045186
0.045294
0.997615
[ "s285232796", "s886702444" ]
u512266180
p02621
python
s290774233
s277366701
29
26
9,124
9,148
Accepted
Accepted
10.34
a = int(eval(input())) ans = a + a**2 + a**3 print(ans)
a = int(eval(input())) print((a+a**2+a**3))
3
2
51
36
a = int(eval(input())) ans = a + a**2 + a**3 print(ans)
a = int(eval(input())) print((a + a**2 + a**3))
false
33.333333
[ "-ans = a + a**2 + a**3", "-print(ans)", "+print((a + a**2 + a**3))" ]
false
0.046874
0.048941
0.95777
[ "s290774233", "s277366701" ]