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
u216015528
p02936
python
s925967666
s474839352
1,722
1,310
255,060
251,956
Accepted
Accepted
23.93
#!/usr/bin/env python3 from sys import setrecursionlimit setrecursionlimit(10 ** 8) def dfs(now): seen[now] = True score[now] += operation[now] for next in branch[now]: if seen[next] is False: score[next] += score[now] dfs(next) N, Q = map(int, input().split()) branch = [set() for _ in range(N)] for _ in range(N - 1): a, b = map(int, input().split()) branch[a - 1].add(b - 1) branch[b - 1].add(a - 1) operation = [0] * N for _ in range(Q): p, x = map(int, input().split()) operation[p - 1] += x seen = [False] * N score = [0] * N for i in range(N): if seen[i] is False: dfs(i) for ans in score: print(ans, end=' ')
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def dfs(now): seen[now] = True for next in branch[now]: if seen[next] is False: score[next] += score[now] dfs(next) N, Q = list(map(int, input().split())) branch = [set() for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) branch[a - 1].add(b - 1) branch[b - 1].add(a - 1) score = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) score[p - 1] += x seen = [False] * N for i in range(N): if seen[i] is False: dfs(i) print((*score))
34
32
737
658
#!/usr/bin/env python3 from sys import setrecursionlimit setrecursionlimit(10**8) def dfs(now): seen[now] = True score[now] += operation[now] for next in branch[now]: if seen[next] is False: score[next] += score[now] dfs(next) N, Q = map(int, input().split()) branch = [set() for _ in range(N)] for _ in range(N - 1): a, b = map(int, input().split()) branch[a - 1].add(b - 1) branch[b - 1].add(a - 1) operation = [0] * N for _ in range(Q): p, x = map(int, input().split()) operation[p - 1] += x seen = [False] * N score = [0] * N for i in range(N): if seen[i] is False: dfs(i) for ans in score: print(ans, end=" ")
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) input = sys.stdin.readline def dfs(now): seen[now] = True for next in branch[now]: if seen[next] is False: score[next] += score[now] dfs(next) N, Q = list(map(int, input().split())) branch = [set() for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) branch[a - 1].add(b - 1) branch[b - 1].add(a - 1) score = [0] * N for _ in range(Q): p, x = list(map(int, input().split())) score[p - 1] += x seen = [False] * N for i in range(N): if seen[i] is False: dfs(i) print((*score))
false
5.882353
[ "-from sys import setrecursionlimit", "+import sys", "-setrecursionlimit(10**8)", "+sys.setrecursionlimit(10**8)", "+input = sys.stdin.readline", "- score[now] += operation[now]", "-N, Q = map(int, input().split())", "+N, Q = list(map(int, input().split()))", "- a, b = map(int, input().split())", "+ a, b = list(map(int, input().split()))", "-operation = [0] * N", "+score = [0] * N", "- p, x = map(int, input().split())", "- operation[p - 1] += x", "+ p, x = list(map(int, input().split()))", "+ score[p - 1] += x", "-score = [0] * N", "-for ans in score:", "- print(ans, end=\" \")", "+print((*score))" ]
false
0.035985
0.04071
0.883953
[ "s925967666", "s474839352" ]
u249447366
p03352
python
s602211697
s579616915
23
17
2,940
3,060
Accepted
Accepted
26.09
x = int(eval(input())) num = 0 if x == 1: num = 1 else: for b in range(2,x): for p in range(2,11): tmp = pow(b, p) if tmp <= x and num < tmp: num = tmp print(num)
x = int(eval(input())) num = 0 if x == 1: num = 1 else: for b in range(2, 33): for p in range(2, 11): tmp = pow(b, p) if tmp <= x and num < tmp: num = tmp print(num)
13
13
226
229
x = int(eval(input())) num = 0 if x == 1: num = 1 else: for b in range(2, x): for p in range(2, 11): tmp = pow(b, p) if tmp <= x and num < tmp: num = tmp print(num)
x = int(eval(input())) num = 0 if x == 1: num = 1 else: for b in range(2, 33): for p in range(2, 11): tmp = pow(b, p) if tmp <= x and num < tmp: num = tmp print(num)
false
0
[ "- for b in range(2, x):", "+ for b in range(2, 33):" ]
false
0.038665
0.035676
1.083783
[ "s602211697", "s579616915" ]
u947883560
p02621
python
s704054313
s181586988
26
23
9,172
9,120
Accepted
Accepted
11.54
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) INF = float("inf") 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)))) def main(): a = INT() print((a+a**2+a**3)) return if __name__ == '__main__': main()
#!/usr/bin/env python3 import sys 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)))) def main(): sys.setrecursionlimit(10**8) INF = float("inf") a = INT() print((a + a**2 + a**3)) return if __name__ == '__main__': main()
34
19
473
440
#!/usr/bin/env python3 import sys sys.setrecursionlimit(10**8) INF = float("inf") 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)))) def main(): a = INT() print((a + a**2 + a**3)) return if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys 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)))) def main(): sys.setrecursionlimit(10**8) INF = float("inf") a = INT() print((a + a**2 + a**3)) return if __name__ == "__main__": main()
false
44.117647
[ "-", "-sys.setrecursionlimit(10**8)", "-INF = float(\"inf\")", "+ sys.setrecursionlimit(10**8)", "+ INF = float(\"inf\")" ]
false
0.036541
0.045527
0.802629
[ "s704054313", "s181586988" ]
u408260374
p02361
python
s221019424
s672125182
4,560
3,590
150,640
143,708
Accepted
Accepted
21.27
import heapq class Edge: def __init__(self, dst, weight): self.dst, self.weight = dst, weight def __lt__(self, e): return self.weight > e.weight class Graph: def __init__(self, V): self.V = V self.E = [[] for _ in range(V)] def add_edge(self, src, dst, weight): self.E[src].append(Edge(dst, weight)) class Node: def __init__(self, v, cost): self.v, self.cost = v, cost def __lt__(self, n): return self.cost < n.cost class ShortestPath: """Dijkstra's algorithm : find the shortest path from a vertex Complexity: O(E + log(V)) used in GRL1A(AOJ) """ def __init__(self, G, INF=10**9): """ V: the number of vertexes E: adjacency list (all edge in E must be 0 or positive) start: start vertex INF: Infinity distance """ self.G, self.INF = G, INF def dijkstra(self, start, goal=None): que = list() self.dist = [self.INF] * self.G.V # distance from start self.prev = [-1] * self.G.V # prev vertex of shortest path self.dist[start] = 0 heapq.heappush(que, Node(start, 0)) while len(que) > 0: n = heapq.heappop(que) if self.dist[n.v] < n.cost: continue if goal is not None and n.v == goal: return for e in self.G.E[n.v]: if self.dist[n.v] + e.weight < self.dist[e.dst]: self.dist[e.dst] = self.dist[n.v] + e.weight heapq.heappush(que, Node(e.dst, self.dist[e.dst])) self.prev[e.dst] = n.v def getPath(self, end): path = [end] while self.prev[end] != -1: end = self.prev[end] return path[::-1] V, E, start = list(map(int, input().split())) G = Graph(V) for _ in range(E): s, t, d = list(map(int, input().split())) G.add_edge(s, t, d) INF = 10**9 sp = ShortestPath(G, INF) sp.dijkstra(start) for i in range(G.V): print(("INF" if sp.dist[i] == INF else sp.dist[i]))
import heapq class Edge: def __init__(self, dst, weight): self.dst, self.weight = dst, weight def __lt__(self, e): return self.weight > e.weight class Graph: def __init__(self, V): self.V = V self.E = [[] for _ in range(V)] def add_edge(self, src, dst, weight): self.E[src].append(Edge(dst, weight)) class ShortestPath: """Dijkstra's algorithm : find the shortest path from a vertex Complexity: O(E + log(V)) used in GRL1A(AOJ) """ def __init__(self, G, INF=10**9): """ V: the number of vertexes E: adjacency list (all edge in E must be 0 or positive) start: start vertex INF: Infinity distance """ self.G, self.INF = G, INF class Node: def __init__(self, v, cost): self.v, self.cost = v, cost def __lt__(self, n): return self.cost < n.cost def dijkstra(self, start, goal=None): que = list() self.dist = [self.INF] * self.G.V # distance from start self.prev = [-1] * self.G.V # prev vertex of shortest path self.dist[start] = 0 heapq.heappush(que, (0, start)) while len(que) > 0: cost, v = heapq.heappop(que) if self.dist[v] < cost: continue if goal is not None and v == goal: return for e in self.G.E[v]: if self.dist[v] + e.weight < self.dist[e.dst]: self.dist[e.dst] = self.dist[v] + e.weight heapq.heappush(que, (self.dist[e.dst], e.dst)) self.prev[e.dst] = v def getPath(self, end): path = [end] while self.prev[end] != -1: end = self.prev[end] return path[::-1] V, E, start = list(map(int, input().split())) G = Graph(V) for _ in range(E): s, t, d = list(map(int, input().split())) G.add_edge(s, t, d) INF = 10**9 sp = ShortestPath(G, INF) sp.dijkstra(start) for i in range(G.V): print(("INF" if sp.dist[i] == INF else sp.dist[i]))
77
76
2,159
2,161
import heapq class Edge: def __init__(self, dst, weight): self.dst, self.weight = dst, weight def __lt__(self, e): return self.weight > e.weight class Graph: def __init__(self, V): self.V = V self.E = [[] for _ in range(V)] def add_edge(self, src, dst, weight): self.E[src].append(Edge(dst, weight)) class Node: def __init__(self, v, cost): self.v, self.cost = v, cost def __lt__(self, n): return self.cost < n.cost class ShortestPath: """Dijkstra's algorithm : find the shortest path from a vertex Complexity: O(E + log(V)) used in GRL1A(AOJ) """ def __init__(self, G, INF=10**9): """V: the number of vertexes E: adjacency list (all edge in E must be 0 or positive) start: start vertex INF: Infinity distance """ self.G, self.INF = G, INF def dijkstra(self, start, goal=None): que = list() self.dist = [self.INF] * self.G.V # distance from start self.prev = [-1] * self.G.V # prev vertex of shortest path self.dist[start] = 0 heapq.heappush(que, Node(start, 0)) while len(que) > 0: n = heapq.heappop(que) if self.dist[n.v] < n.cost: continue if goal is not None and n.v == goal: return for e in self.G.E[n.v]: if self.dist[n.v] + e.weight < self.dist[e.dst]: self.dist[e.dst] = self.dist[n.v] + e.weight heapq.heappush(que, Node(e.dst, self.dist[e.dst])) self.prev[e.dst] = n.v def getPath(self, end): path = [end] while self.prev[end] != -1: end = self.prev[end] return path[::-1] V, E, start = list(map(int, input().split())) G = Graph(V) for _ in range(E): s, t, d = list(map(int, input().split())) G.add_edge(s, t, d) INF = 10**9 sp = ShortestPath(G, INF) sp.dijkstra(start) for i in range(G.V): print(("INF" if sp.dist[i] == INF else sp.dist[i]))
import heapq class Edge: def __init__(self, dst, weight): self.dst, self.weight = dst, weight def __lt__(self, e): return self.weight > e.weight class Graph: def __init__(self, V): self.V = V self.E = [[] for _ in range(V)] def add_edge(self, src, dst, weight): self.E[src].append(Edge(dst, weight)) class ShortestPath: """Dijkstra's algorithm : find the shortest path from a vertex Complexity: O(E + log(V)) used in GRL1A(AOJ) """ def __init__(self, G, INF=10**9): """V: the number of vertexes E: adjacency list (all edge in E must be 0 or positive) start: start vertex INF: Infinity distance """ self.G, self.INF = G, INF class Node: def __init__(self, v, cost): self.v, self.cost = v, cost def __lt__(self, n): return self.cost < n.cost def dijkstra(self, start, goal=None): que = list() self.dist = [self.INF] * self.G.V # distance from start self.prev = [-1] * self.G.V # prev vertex of shortest path self.dist[start] = 0 heapq.heappush(que, (0, start)) while len(que) > 0: cost, v = heapq.heappop(que) if self.dist[v] < cost: continue if goal is not None and v == goal: return for e in self.G.E[v]: if self.dist[v] + e.weight < self.dist[e.dst]: self.dist[e.dst] = self.dist[v] + e.weight heapq.heappush(que, (self.dist[e.dst], e.dst)) self.prev[e.dst] = v def getPath(self, end): path = [end] while self.prev[end] != -1: end = self.prev[end] return path[::-1] V, E, start = list(map(int, input().split())) G = Graph(V) for _ in range(E): s, t, d = list(map(int, input().split())) G.add_edge(s, t, d) INF = 10**9 sp = ShortestPath(G, INF) sp.dijkstra(start) for i in range(G.V): print(("INF" if sp.dist[i] == INF else sp.dist[i]))
false
1.298701
[ "-class Node:", "- def __init__(self, v, cost):", "- self.v, self.cost = v, cost", "-", "- def __lt__(self, n):", "- return self.cost < n.cost", "-", "-", "+ class Node:", "+ def __init__(self, v, cost):", "+ self.v, self.cost = v, cost", "+", "+ def __lt__(self, n):", "+ return self.cost < n.cost", "+", "- heapq.heappush(que, Node(start, 0))", "+ heapq.heappush(que, (0, start))", "- n = heapq.heappop(que)", "- if self.dist[n.v] < n.cost:", "+ cost, v = heapq.heappop(que)", "+ if self.dist[v] < cost:", "- if goal is not None and n.v == goal:", "+ if goal is not None and v == goal:", "- for e in self.G.E[n.v]:", "- if self.dist[n.v] + e.weight < self.dist[e.dst]:", "- self.dist[e.dst] = self.dist[n.v] + e.weight", "- heapq.heappush(que, Node(e.dst, self.dist[e.dst]))", "- self.prev[e.dst] = n.v", "+ for e in self.G.E[v]:", "+ if self.dist[v] + e.weight < self.dist[e.dst]:", "+ self.dist[e.dst] = self.dist[v] + e.weight", "+ heapq.heappush(que, (self.dist[e.dst], e.dst))", "+ self.prev[e.dst] = v" ]
false
0.040316
0.041001
0.983294
[ "s221019424", "s672125182" ]
u043048943
p02803
python
s359716284
s016821982
1,739
654
113,044
92,764
Accepted
Accepted
62.39
#coding:utf-8 import sys sys.setrecursionlimit(10**6) write = sys.stdout.write dbg = lambda *something : print(*something) if DEBUG else 0 DEBUG = False def main(given = sys.stdin.readline): input = lambda : given().rstrip() LMIIS = lambda : list(map(int,input().split())) II = lambda : int(input()) XLMIIS = lambda x : [LMIIS() for _ in range(x)] H,W = LMIIS() MOD = H*W S = [input() for _ in range(H)] def tansaku(S,V,y,x,length): if x >= 1 and S[y][x-1] == '.' and V[y][x-1] > length+1: V[y][x-1] = length+1 tansaku(S,V,y,x-1,length+1) if x < W-1 and S[y][x+1] == '.' and V[y][x+1] > length+1: V[y][x+1] = length+1 tansaku(S,V,y,x+1,length+1) if y >= 1 and S[y-1][x] == '.' and V[y-1][x] > length+1: V[y-1][x] = length+1 tansaku(S,V,y-1,x,length+1) if y < H-1 and S[y+1][x] == '.' and V[y+1][x]> length+1: V[y+1][x] = length+1 tansaku(S,V,y+1,x,length+1) return def getmax(): max_length = 0 for h in range(H): for w in range(W): V = [[MOD] * W for _ in range(H)] if S[h][w] == '.': V[h][w] = 0 tansaku(S,V,h,w,0) for v in V: v = list(map(lambda x:x%MOD,v)) max_length = max(v+[max_length]) # print(V) return max_length print(getmax()) if __name__ == '__main__': main()
#coding:utf-8 import sys sys.setrecursionlimit(10**6) write = sys.stdout.write dbg = lambda *something : print(*something) if DEBUG else 0 DEBUG = False def main(given = sys.stdin.readline): input = lambda : given().rstrip() LMIIS = lambda : list(map(int,input().split())) II = lambda : int(input()) XLMIIS = lambda x : [LMIIS() for _ in range(x)] H,W = LMIIS() MOD = H*W S = [input() for _ in range(H)] from collections import deque def tansaku(S,V,length,q): if len(q) == 0: return length-1 q2 = [] for y,x in q: if x >= 1 and S[y][x-1] == '.' and V[y][x-1]: V[y][x-1] = False q2.append((y,x-1)) if x < W-1 and S[y][x+1] == '.' and V[y][x+1]: V[y][x+1] = False q2.append((y,x+1)) if y >= 1 and S[y-1][x] == '.' and V[y-1][x]: V[y-1][x] = False q2.append((y-1,x)) if y < H-1 and S[y+1][x] == '.' and V[y+1][x]: V[y+1][x] = False q2.append((y+1,x)) return tansaku(S,V,length+1,q2) def getmax(): max_length = 0 for h in range(H): for w in range(W): V = [[True] * W for _ in range(H)] if S[h][w] == '.': V[h][w] = False max_length = max(tansaku(S,V,0,[(h,w)]),max_length) return max_length print(getmax()) if __name__ == '__main__': main()
66
62
1,644
1,607
# coding:utf-8 import sys sys.setrecursionlimit(10**6) write = sys.stdout.write dbg = lambda *something: print(*something) if DEBUG else 0 DEBUG = False def main(given=sys.stdin.readline): input = lambda: given().rstrip() LMIIS = lambda: list(map(int, input().split())) II = lambda: int(input()) XLMIIS = lambda x: [LMIIS() for _ in range(x)] H, W = LMIIS() MOD = H * W S = [input() for _ in range(H)] def tansaku(S, V, y, x, length): if x >= 1 and S[y][x - 1] == "." and V[y][x - 1] > length + 1: V[y][x - 1] = length + 1 tansaku(S, V, y, x - 1, length + 1) if x < W - 1 and S[y][x + 1] == "." and V[y][x + 1] > length + 1: V[y][x + 1] = length + 1 tansaku(S, V, y, x + 1, length + 1) if y >= 1 and S[y - 1][x] == "." and V[y - 1][x] > length + 1: V[y - 1][x] = length + 1 tansaku(S, V, y - 1, x, length + 1) if y < H - 1 and S[y + 1][x] == "." and V[y + 1][x] > length + 1: V[y + 1][x] = length + 1 tansaku(S, V, y + 1, x, length + 1) return def getmax(): max_length = 0 for h in range(H): for w in range(W): V = [[MOD] * W for _ in range(H)] if S[h][w] == ".": V[h][w] = 0 tansaku(S, V, h, w, 0) for v in V: v = list(map(lambda x: x % MOD, v)) max_length = max(v + [max_length]) # print(V) return max_length print(getmax()) if __name__ == "__main__": main()
# coding:utf-8 import sys sys.setrecursionlimit(10**6) write = sys.stdout.write dbg = lambda *something: print(*something) if DEBUG else 0 DEBUG = False def main(given=sys.stdin.readline): input = lambda: given().rstrip() LMIIS = lambda: list(map(int, input().split())) II = lambda: int(input()) XLMIIS = lambda x: [LMIIS() for _ in range(x)] H, W = LMIIS() MOD = H * W S = [input() for _ in range(H)] from collections import deque def tansaku(S, V, length, q): if len(q) == 0: return length - 1 q2 = [] for y, x in q: if x >= 1 and S[y][x - 1] == "." and V[y][x - 1]: V[y][x - 1] = False q2.append((y, x - 1)) if x < W - 1 and S[y][x + 1] == "." and V[y][x + 1]: V[y][x + 1] = False q2.append((y, x + 1)) if y >= 1 and S[y - 1][x] == "." and V[y - 1][x]: V[y - 1][x] = False q2.append((y - 1, x)) if y < H - 1 and S[y + 1][x] == "." and V[y + 1][x]: V[y + 1][x] = False q2.append((y + 1, x)) return tansaku(S, V, length + 1, q2) def getmax(): max_length = 0 for h in range(H): for w in range(W): V = [[True] * W for _ in range(H)] if S[h][w] == ".": V[h][w] = False max_length = max(tansaku(S, V, 0, [(h, w)]), max_length) return max_length print(getmax()) if __name__ == "__main__": main()
false
6.060606
[ "+ from collections import deque", "- def tansaku(S, V, y, x, length):", "- if x >= 1 and S[y][x - 1] == \".\" and V[y][x - 1] > length + 1:", "- V[y][x - 1] = length + 1", "- tansaku(S, V, y, x - 1, length + 1)", "- if x < W - 1 and S[y][x + 1] == \".\" and V[y][x + 1] > length + 1:", "- V[y][x + 1] = length + 1", "- tansaku(S, V, y, x + 1, length + 1)", "- if y >= 1 and S[y - 1][x] == \".\" and V[y - 1][x] > length + 1:", "- V[y - 1][x] = length + 1", "- tansaku(S, V, y - 1, x, length + 1)", "- if y < H - 1 and S[y + 1][x] == \".\" and V[y + 1][x] > length + 1:", "- V[y + 1][x] = length + 1", "- tansaku(S, V, y + 1, x, length + 1)", "- return", "+ def tansaku(S, V, length, q):", "+ if len(q) == 0:", "+ return length - 1", "+ q2 = []", "+ for y, x in q:", "+ if x >= 1 and S[y][x - 1] == \".\" and V[y][x - 1]:", "+ V[y][x - 1] = False", "+ q2.append((y, x - 1))", "+ if x < W - 1 and S[y][x + 1] == \".\" and V[y][x + 1]:", "+ V[y][x + 1] = False", "+ q2.append((y, x + 1))", "+ if y >= 1 and S[y - 1][x] == \".\" and V[y - 1][x]:", "+ V[y - 1][x] = False", "+ q2.append((y - 1, x))", "+ if y < H - 1 and S[y + 1][x] == \".\" and V[y + 1][x]:", "+ V[y + 1][x] = False", "+ q2.append((y + 1, x))", "+ return tansaku(S, V, length + 1, q2)", "- V = [[MOD] * W for _ in range(H)]", "+ V = [[True] * W for _ in range(H)]", "- V[h][w] = 0", "- tansaku(S, V, h, w, 0)", "- for v in V:", "- v = list(map(lambda x: x % MOD, v))", "- max_length = max(v + [max_length])", "- # print(V)", "+ V[h][w] = False", "+ max_length = max(tansaku(S, V, 0, [(h, w)]), max_length)" ]
false
0.077861
0.036374
2.140582
[ "s359716284", "s016821982" ]
u729133443
p03478
python
s724684145
s733084514
197
31
41,708
2,940
Accepted
Accepted
84.26
n,a,b=list(map(int,input().split()));print((sum(i*(a<=sum(map(int,str(i)))<=b)for i in range(n+1))))
n,a,b=list(map(int,input().split()));c=0 while n:c+=n*(a<=sum(map(int,str(n)))<=b);n-=1 print(c)
1
3
92
92
n, a, b = list(map(int, input().split())) print((sum(i * (a <= sum(map(int, str(i))) <= b) for i in range(n + 1))))
n, a, b = list(map(int, input().split())) c = 0 while n: c += n * (a <= sum(map(int, str(n))) <= b) n -= 1 print(c)
false
66.666667
[ "-print((sum(i * (a <= sum(map(int, str(i))) <= b) for i in range(n + 1))))", "+c = 0", "+while n:", "+ c += n * (a <= sum(map(int, str(n))) <= b)", "+ n -= 1", "+print(c)" ]
false
0.042255
0.145098
0.291214
[ "s724684145", "s733084514" ]
u941753895
p03274
python
s499505447
s767250059
129
97
17,120
17,136
Accepted
Accepted
24.81
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def II(): return int(eval(input())) def LS(): return input().split() def S(): return eval(input()) def main(): n,k=LI() l=LI() if l.count(0)>0: k-=1 l.remove(0) if k==0: print((0)) exit() if len(l)==0: print((0)) exit() idx=len(l)-1 for i in range(len(l)): if l[i]>0: idx=i break if max(l)<0: idx=len(l) l1=[abs(x) for x in l[idx:]] l2=[abs(x) for x in l[:idx]] l2.reverse() # print(l1) # print(l2) mn=inf for i in range(len(l1)): if i+1>=k: mn=min(mn,l1[i]) else: if len(l2)>=k-(i+1): # print(l1[i],l2[k-(i+1)-1]) mn=min(mn,l1[i]+2*l2[k-(i+1)-1]) for i in range(len(l2)): if i+1>=k: mn=min(mn,l2[i]) else: if len(l1)>=k-(i+1): # print(l2[i],l1[k-(i+1)-1]) mn=min(mn,l2[i]+2*l1[k-(i+1)-1]) print(mn) main() # print(main())
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def I(): return int(eval(input())) def LS(): return input().split() def S(): return eval(input()) def main(): n,k=LI() l=LI() mn=inf for i in range(n-k+1): a=l[i] b=l[i+k-1] if a<0 and b>0: mn=min([mn,abs(a)+abs(b)*2,abs(a)*2+abs(b)]) else: mn=min(mn,max(abs(a),abs(b))) return mn print((main()))
63
28
1,121
544
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 def LI(): return list(map(int, input().split())) def II(): return int(eval(input())) def LS(): return input().split() def S(): return eval(input()) def main(): n, k = LI() l = LI() if l.count(0) > 0: k -= 1 l.remove(0) if k == 0: print((0)) exit() if len(l) == 0: print((0)) exit() idx = len(l) - 1 for i in range(len(l)): if l[i] > 0: idx = i break if max(l) < 0: idx = len(l) l1 = [abs(x) for x in l[idx:]] l2 = [abs(x) for x in l[:idx]] l2.reverse() # print(l1) # print(l2) mn = inf for i in range(len(l1)): if i + 1 >= k: mn = min(mn, l1[i]) else: if len(l2) >= k - (i + 1): # print(l1[i],l2[k-(i+1)-1]) mn = min(mn, l1[i] + 2 * l2[k - (i + 1) - 1]) for i in range(len(l2)): if i + 1 >= k: mn = min(mn, l2[i]) else: if len(l1) >= k - (i + 1): # print(l2[i],l1[k-(i+1)-1]) mn = min(mn, l2[i] + 2 * l1[k - (i + 1) - 1]) print(mn) main() # print(main())
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 def LI(): return list(map(int, input().split())) def I(): return int(eval(input())) def LS(): return input().split() def S(): return eval(input()) def main(): n, k = LI() l = LI() mn = inf for i in range(n - k + 1): a = l[i] b = l[i + k - 1] if a < 0 and b > 0: mn = min([mn, abs(a) + abs(b) * 2, abs(a) * 2 + abs(b)]) else: mn = min(mn, max(abs(a), abs(b))) return mn print((main()))
false
55.555556
[ "-def II():", "+def I():", "- if l.count(0) > 0:", "- k -= 1", "- l.remove(0)", "- if k == 0:", "- print((0))", "- exit()", "- if len(l) == 0:", "- print((0))", "- exit()", "- idx = len(l) - 1", "- for i in range(len(l)):", "- if l[i] > 0:", "- idx = i", "- break", "- if max(l) < 0:", "- idx = len(l)", "- l1 = [abs(x) for x in l[idx:]]", "- l2 = [abs(x) for x in l[:idx]]", "- l2.reverse()", "- # print(l1)", "- # print(l2)", "- for i in range(len(l1)):", "- if i + 1 >= k:", "- mn = min(mn, l1[i])", "+ for i in range(n - k + 1):", "+ a = l[i]", "+ b = l[i + k - 1]", "+ if a < 0 and b > 0:", "+ mn = min([mn, abs(a) + abs(b) * 2, abs(a) * 2 + abs(b)])", "- if len(l2) >= k - (i + 1):", "- # print(l1[i],l2[k-(i+1)-1])", "- mn = min(mn, l1[i] + 2 * l2[k - (i + 1) - 1])", "- for i in range(len(l2)):", "- if i + 1 >= k:", "- mn = min(mn, l2[i])", "- else:", "- if len(l1) >= k - (i + 1):", "- # print(l2[i],l1[k-(i+1)-1])", "- mn = min(mn, l2[i] + 2 * l1[k - (i + 1) - 1])", "- print(mn)", "+ mn = min(mn, max(abs(a), abs(b)))", "+ return mn", "-main()", "-# print(main())", "+print((main()))" ]
false
0.04679
0.056413
0.829429
[ "s499505447", "s767250059" ]
u864013199
p03326
python
s267654128
s043510204
1,419
152
22,044
12,512
Accepted
Accepted
89.29
import numpy as np N,M = list(map(int,input().split())) L = np.array([list(map(int,input().split())) for _ in range(N)]) l = [[1,1,1],[1,1,-1],[1,-1,1],[-1,1,1],[1,-1,-1],[-1,-1,1],[-1,1,-1],[-1,-1,-1]] ans = 0 for i in range(8): su = L[:,0]*l[i][0]+L[:,1]*l[i][1]+L[:,2]*l[i][2] s = np.sort(su)[::-1] ans = max(ans,sum(s[:M])) print(ans)
import numpy as np N,M = list(map(int,input().split())) L = np.array([list(map(int,input().split())) for _ in range(N)]) l = [[1,1,1],[1,1,-1],[1,-1,1],[-1,1,1],[1,-1,-1],[-1,-1,1],[-1,1,-1],[-1,-1,-1]] ans = 0 for i in range(8): su = L[:,0]*l[i][0]+L[:,1]*l[i][1]+L[:,2]*l[i][2] s = np.sort(su)[::-1] ans = max(ans,np.sum(s[:M])) print(ans)
10
10
353
356
import numpy as np N, M = list(map(int, input().split())) L = np.array([list(map(int, input().split())) for _ in range(N)]) l = [ [1, 1, 1], [1, 1, -1], [1, -1, 1], [-1, 1, 1], [1, -1, -1], [-1, -1, 1], [-1, 1, -1], [-1, -1, -1], ] ans = 0 for i in range(8): su = L[:, 0] * l[i][0] + L[:, 1] * l[i][1] + L[:, 2] * l[i][2] s = np.sort(su)[::-1] ans = max(ans, sum(s[:M])) print(ans)
import numpy as np N, M = list(map(int, input().split())) L = np.array([list(map(int, input().split())) for _ in range(N)]) l = [ [1, 1, 1], [1, 1, -1], [1, -1, 1], [-1, 1, 1], [1, -1, -1], [-1, -1, 1], [-1, 1, -1], [-1, -1, -1], ] ans = 0 for i in range(8): su = L[:, 0] * l[i][0] + L[:, 1] * l[i][1] + L[:, 2] * l[i][2] s = np.sort(su)[::-1] ans = max(ans, np.sum(s[:M])) print(ans)
false
0
[ "- ans = max(ans, sum(s[:M]))", "+ ans = max(ans, np.sum(s[:M]))" ]
false
0.744186
0.360672
2.063332
[ "s267654128", "s043510204" ]
u790710233
p03363
python
s541969435
s620094548
241
195
40,868
45,824
Accepted
Accepted
19.09
from collections import defaultdict n = int(eval(input())) A = list(map(int, input().split())) dd = defaultdict(int) dd[0] += 1 S = [0]*(n+1) for i in range(n): S[i+1] = S[i]+A[i] dd[S[i+1]] += 1 print((sum(v*(v-1)//2 for v in list(dd.values()))))
from collections import defaultdict from itertools import accumulate n = int(eval(input())) A = accumulate(list(map(int, input().split()))) cnt = defaultdict(int) cnt[0] += 1 for a in A: cnt[a] += 1 print((sum(v*(v-1)//2 for v in list(cnt.values()))))
10
9
251
243
from collections import defaultdict n = int(eval(input())) A = list(map(int, input().split())) dd = defaultdict(int) dd[0] += 1 S = [0] * (n + 1) for i in range(n): S[i + 1] = S[i] + A[i] dd[S[i + 1]] += 1 print((sum(v * (v - 1) // 2 for v in list(dd.values()))))
from collections import defaultdict from itertools import accumulate n = int(eval(input())) A = accumulate(list(map(int, input().split()))) cnt = defaultdict(int) cnt[0] += 1 for a in A: cnt[a] += 1 print((sum(v * (v - 1) // 2 for v in list(cnt.values()))))
false
10
[ "+from itertools import accumulate", "-A = list(map(int, input().split()))", "-dd = defaultdict(int)", "-dd[0] += 1", "-S = [0] * (n + 1)", "-for i in range(n):", "- S[i + 1] = S[i] + A[i]", "- dd[S[i + 1]] += 1", "-print((sum(v * (v - 1) // 2 for v in list(dd.values()))))", "+A = accumulate(list(map(int, input().split())))", "+cnt = defaultdict(int)", "+cnt[0] += 1", "+for a in A:", "+ cnt[a] += 1", "+print((sum(v * (v - 1) // 2 for v in list(cnt.values()))))" ]
false
0.036233
0.075687
0.478722
[ "s541969435", "s620094548" ]
u033183216
p02721
python
s825135394
s284920520
376
298
20,584
58,104
Accepted
Accepted
20.74
# https://atcoder.jp/contests/abc161/tasks/abc161_e N, K, C = list(map(int, input().split())) S = eval(input()) i = 0 left = [] while i < N and len(left) < K: if S[i] == 'o': left.append(i) i += (C + 1) continue i += 1 i = N - 1 right = [] while i >= 0 and len(right) < K: if S[i] == 'o': right.append(i) i -= (C + 1) continue i -= 1 n = len(left) for i in range(n): if left[i] == right[n - i - 1]: print((left[i] + 1))
# https://atcoder.jp/contests/abc161/tasks/abc161_e N, K, C = list(map(int, input().split())) S = eval(input()) left = [] i = 0 while K > len(left): while True: if S[i] == 'o': left.append(i) i += C + 1 break i += 1 right = [] i = N - 1 while K > len(right): while True: if S[i] == 'o': right.append(i) i -= (C + 1) break i -= 1 right.reverse() ans = 0 for i in range(K): if left[i] == right[i]: print((left[i] + 1))
26
31
510
562
# https://atcoder.jp/contests/abc161/tasks/abc161_e N, K, C = list(map(int, input().split())) S = eval(input()) i = 0 left = [] while i < N and len(left) < K: if S[i] == "o": left.append(i) i += C + 1 continue i += 1 i = N - 1 right = [] while i >= 0 and len(right) < K: if S[i] == "o": right.append(i) i -= C + 1 continue i -= 1 n = len(left) for i in range(n): if left[i] == right[n - i - 1]: print((left[i] + 1))
# https://atcoder.jp/contests/abc161/tasks/abc161_e N, K, C = list(map(int, input().split())) S = eval(input()) left = [] i = 0 while K > len(left): while True: if S[i] == "o": left.append(i) i += C + 1 break i += 1 right = [] i = N - 1 while K > len(right): while True: if S[i] == "o": right.append(i) i -= C + 1 break i -= 1 right.reverse() ans = 0 for i in range(K): if left[i] == right[i]: print((left[i] + 1))
false
16.129032
[ "+left = []", "-left = []", "-while i < N and len(left) < K:", "- if S[i] == \"o\":", "- left.append(i)", "- i += C + 1", "- continue", "- i += 1", "+while K > len(left):", "+ while True:", "+ if S[i] == \"o\":", "+ left.append(i)", "+ i += C + 1", "+ break", "+ i += 1", "+right = []", "-right = []", "-while i >= 0 and len(right) < K:", "- if S[i] == \"o\":", "- right.append(i)", "- i -= C + 1", "- continue", "- i -= 1", "-n = len(left)", "-for i in range(n):", "- if left[i] == right[n - i - 1]:", "+while K > len(right):", "+ while True:", "+ if S[i] == \"o\":", "+ right.append(i)", "+ i -= C + 1", "+ break", "+ i -= 1", "+right.reverse()", "+ans = 0", "+for i in range(K):", "+ if left[i] == right[i]:" ]
false
0.033466
0.044795
0.747093
[ "s825135394", "s284920520" ]
u186838327
p03403
python
s466326053
s276400800
170
147
86,752
82,460
Accepted
Accepted
13.53
n = int(eval(input())) A = list(map(int, input().split())) A = [0]+A+[0] s = 0 for i in range(1, n+2): s += abs(A[i]-A[i-1]) for i in range(1, n+1): ans = s ans -= abs(A[i]-A[i-1]) ans -= abs(A[i+1]-A[i]) ans += abs(A[i+1]-A[i-1]) print(ans)
n = int(input()) A = list(map(int, input().split())) res = 0 pre = 0 for a in A: res += abs(a-pre) pre = a else: res += abs(0-pre) #print(res) ans = [0]*n A = [0]+A+[0] for i in range(n): j = i+1 temp = res-abs(A[j-1]-A[j])-abs(A[j+1]-A[j])+abs(A[j+1]-A[j-1]) ans[i] = temp print(*ans, sep='\n')
15
18
277
338
n = int(eval(input())) A = list(map(int, input().split())) A = [0] + A + [0] s = 0 for i in range(1, n + 2): s += abs(A[i] - A[i - 1]) for i in range(1, n + 1): ans = s ans -= abs(A[i] - A[i - 1]) ans -= abs(A[i + 1] - A[i]) ans += abs(A[i + 1] - A[i - 1]) print(ans)
n = int(input()) A = list(map(int, input().split())) res = 0 pre = 0 for a in A: res += abs(a - pre) pre = a else: res += abs(0 - pre) # print(res) ans = [0] * n A = [0] + A + [0] for i in range(n): j = i + 1 temp = res - abs(A[j - 1] - A[j]) - abs(A[j + 1] - A[j]) + abs(A[j + 1] - A[j - 1]) ans[i] = temp print(*ans, sep="\n")
false
16.666667
[ "-n = int(eval(input()))", "+n = int(input())", "+res = 0", "+pre = 0", "+for a in A:", "+ res += abs(a - pre)", "+ pre = a", "+else:", "+ res += abs(0 - pre)", "+# print(res)", "+ans = [0] * n", "-s = 0", "-for i in range(1, n + 2):", "- s += abs(A[i] - A[i - 1])", "-for i in range(1, n + 1):", "- ans = s", "- ans -= abs(A[i] - A[i - 1])", "- ans -= abs(A[i + 1] - A[i])", "- ans += abs(A[i + 1] - A[i - 1])", "- print(ans)", "+for i in range(n):", "+ j = i + 1", "+ temp = res - abs(A[j - 1] - A[j]) - abs(A[j + 1] - A[j]) + abs(A[j + 1] - A[j - 1])", "+ ans[i] = temp", "+print(*ans, sep=\"\\n\")" ]
false
0.044468
0.109526
0.406003
[ "s466326053", "s276400800" ]
u790710233
p03546
python
s242091669
s760551271
500
260
26,700
17,364
Accepted
Accepted
48
from scipy.sparse import csr_matrix from scipy.sparse.csgraph import dijkstra from collections import defaultdict h, w = list(map(int, input().split())) table = [list(map(int, input().split())) for _ in range(10)] dd = defaultdict(int) for _ in range(h): for x in map(int, input().split()): if x == -1: continue dd[x] += 1 trans_table = list(zip(*table)) scores = dijkstra(csr_matrix(trans_table), indices=1) ans = 0 for k, v in list(dd.items()): ans += int(scores[k])*v print(ans)
from scipy.sparse.csgraph import dijkstra, csgraph_from_dense from collections import defaultdict h, w = list(map(int, input().split())) table = [list(map(int, input().split())) for _ in range(10)] dd = defaultdict(int) for _ in range(h): for x in map(int, input().split()): if x == -1: continue dd[x] += 1 trans_table = list(zip(*table)) scores = dijkstra(csgraph_from_dense(trans_table), indices=1) ans = 0 for k, v in list(dd.items()): ans += int(scores[k])*v print(ans)
18
18
524
516
from scipy.sparse import csr_matrix from scipy.sparse.csgraph import dijkstra from collections import defaultdict h, w = list(map(int, input().split())) table = [list(map(int, input().split())) for _ in range(10)] dd = defaultdict(int) for _ in range(h): for x in map(int, input().split()): if x == -1: continue dd[x] += 1 trans_table = list(zip(*table)) scores = dijkstra(csr_matrix(trans_table), indices=1) ans = 0 for k, v in list(dd.items()): ans += int(scores[k]) * v print(ans)
from scipy.sparse.csgraph import dijkstra, csgraph_from_dense from collections import defaultdict h, w = list(map(int, input().split())) table = [list(map(int, input().split())) for _ in range(10)] dd = defaultdict(int) for _ in range(h): for x in map(int, input().split()): if x == -1: continue dd[x] += 1 trans_table = list(zip(*table)) scores = dijkstra(csgraph_from_dense(trans_table), indices=1) ans = 0 for k, v in list(dd.items()): ans += int(scores[k]) * v print(ans)
false
0
[ "-from scipy.sparse import csr_matrix", "-from scipy.sparse.csgraph import dijkstra", "+from scipy.sparse.csgraph import dijkstra, csgraph_from_dense", "-scores = dijkstra(csr_matrix(trans_table), indices=1)", "+scores = dijkstra(csgraph_from_dense(trans_table), indices=1)" ]
false
0.526035
0.562601
0.935004
[ "s242091669", "s760551271" ]
u391731808
p03576
python
s115405979
s110682077
778
107
3,064
3,064
Accepted
Accepted
86.25
N,K = list(map(int,input().split())) XY = [list(map(int,input().split())) for _ in [0]*N] iX = sorted(x for x,y in XY) iY = sorted(y for x,y in XY) X = {x:i for i,x in enumerate(iX)} Y = {y:i for i,y in enumerate(iY)} c = [[0]*(N+1) for i in [0]*(N+1)] for x,y in XY: c[Y[y]+1][X[x]+1] = 1 for i in range(N): for j in range(N): c[i+1][j+1] += c[i+1][j] for i in range(N): for j in range(N): c[i+1][j+1] += c[i][j+1] ans = 10**20 for l in range(N): for u in range(N): for r in range(l+1,N): for d in range(u+1,N): if c[d+1][r+1]+c[u][l]-c[u][r+1]-c[d+1][l] >=K: ans = min(ans, (iX[r]-iX[l])*(iY[d]-iY[u])) break print(ans)
N,K = list(map(int,input().split())) XY = [list(map(int,input().split())) for _ in [0]*N] iX = sorted(x for x,y in XY) iY = sorted(y for x,y in XY) X = {x:i for i,x in enumerate(iX)} Y = {y:i for i,y in enumerate(iY)} c = [[0]*(N+1) for i in [0]*(N+1)] for x,y in XY: c[Y[y]+1][X[x]+1] = 1 for i in range(N): for j in range(N): c[i+1][j+1] += c[i+1][j] for i in range(N): for j in range(N): c[i+1][j+1] += c[i][j+1] ans = 10**20 for l in range(N): for r in range(l+1,N): u = 0 d = 1 while d<N: if c[d+1][r+1]+c[u][l]-c[u][r+1]-c[d+1][l] >=K: ans = min(ans, (iX[r]-iX[l])*(iY[d]-iY[u])) u+=1 else:d+=1 print(ans)
30
32
786
778
N, K = list(map(int, input().split())) XY = [list(map(int, input().split())) for _ in [0] * N] iX = sorted(x for x, y in XY) iY = sorted(y for x, y in XY) X = {x: i for i, x in enumerate(iX)} Y = {y: i for i, y in enumerate(iY)} c = [[0] * (N + 1) for i in [0] * (N + 1)] for x, y in XY: c[Y[y] + 1][X[x] + 1] = 1 for i in range(N): for j in range(N): c[i + 1][j + 1] += c[i + 1][j] for i in range(N): for j in range(N): c[i + 1][j + 1] += c[i][j + 1] ans = 10**20 for l in range(N): for u in range(N): for r in range(l + 1, N): for d in range(u + 1, N): if c[d + 1][r + 1] + c[u][l] - c[u][r + 1] - c[d + 1][l] >= K: ans = min(ans, (iX[r] - iX[l]) * (iY[d] - iY[u])) break print(ans)
N, K = list(map(int, input().split())) XY = [list(map(int, input().split())) for _ in [0] * N] iX = sorted(x for x, y in XY) iY = sorted(y for x, y in XY) X = {x: i for i, x in enumerate(iX)} Y = {y: i for i, y in enumerate(iY)} c = [[0] * (N + 1) for i in [0] * (N + 1)] for x, y in XY: c[Y[y] + 1][X[x] + 1] = 1 for i in range(N): for j in range(N): c[i + 1][j + 1] += c[i + 1][j] for i in range(N): for j in range(N): c[i + 1][j + 1] += c[i][j + 1] ans = 10**20 for l in range(N): for r in range(l + 1, N): u = 0 d = 1 while d < N: if c[d + 1][r + 1] + c[u][l] - c[u][r + 1] - c[d + 1][l] >= K: ans = min(ans, (iX[r] - iX[l]) * (iY[d] - iY[u])) u += 1 else: d += 1 print(ans)
false
6.25
[ "- for u in range(N):", "- for r in range(l + 1, N):", "- for d in range(u + 1, N):", "- if c[d + 1][r + 1] + c[u][l] - c[u][r + 1] - c[d + 1][l] >= K:", "- ans = min(ans, (iX[r] - iX[l]) * (iY[d] - iY[u]))", "- break", "+ for r in range(l + 1, N):", "+ u = 0", "+ d = 1", "+ while d < N:", "+ if c[d + 1][r + 1] + c[u][l] - c[u][r + 1] - c[d + 1][l] >= K:", "+ ans = min(ans, (iX[r] - iX[l]) * (iY[d] - iY[u]))", "+ u += 1", "+ else:", "+ d += 1" ]
false
0.157983
0.037734
4.186808
[ "s115405979", "s110682077" ]
u761320129
p03210
python
s054363954
s445162872
19
17
3,316
2,940
Accepted
Accepted
10.53
X = int(eval(input())) print(('YES' if X in (3,5,7) else 'NO'))
X = int(eval(input())) print(('YES' if X in (7,5,3) else 'NO'))
2
2
56
56
X = int(eval(input())) print(("YES" if X in (3, 5, 7) else "NO"))
X = int(eval(input())) print(("YES" if X in (7, 5, 3) else "NO"))
false
0
[ "-print((\"YES\" if X in (3, 5, 7) else \"NO\"))", "+print((\"YES\" if X in (7, 5, 3) else \"NO\"))" ]
false
0.077152
0.078093
0.987957
[ "s054363954", "s445162872" ]
u712429027
p02597
python
s477202080
s418207068
61
49
12,684
10,792
Accepted
Accepted
19.67
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) out = lambda x: print('\n'.join(map(str, x))) n = ini() s = list(ins()) n = s.count("R") t = sorted(s) ans = 0 for i in range(n): if s[i] != t[i]: ans += 1 print(ans)
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) out = lambda x: print('\n'.join(map(str, x))) n = ini() s = list(ins()) n = s.count("R") ans = 0 for i in range(n): if s[i] != "R": ans += 1 print(ans)
17
16
386
370
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) out = lambda x: print("\n".join(map(str, x))) n = ini() s = list(ins()) n = s.count("R") t = sorted(s) ans = 0 for i in range(n): if s[i] != t[i]: ans += 1 print(ans)
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) out = lambda x: print("\n".join(map(str, x))) n = ini() s = list(ins()) n = s.count("R") ans = 0 for i in range(n): if s[i] != "R": ans += 1 print(ans)
false
5.882353
[ "-t = sorted(s)", "- if s[i] != t[i]:", "+ if s[i] != \"R\":" ]
false
0.040589
0.077921
0.5209
[ "s477202080", "s418207068" ]
u498487134
p02887
python
s658436525
s686598811
177
65
39,408
68,316
Accepted
Accepted
63.28
n = int(eval(input())) s = eval(input()) ans = 1 for i in range(1,n): if s[i]!=s[i-1]: ans+=1 print(ans)
def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 cnt=0 N=I() S=eval(input()) now="A" for i in range(N): if S[i]!=now: cnt+=1 now=S[i] print(cnt) main()
8
19
112
328
n = int(eval(input())) s = eval(input()) ans = 1 for i in range(1, n): if s[i] != s[i - 1]: ans += 1 print(ans)
def I(): return int(eval(input())) def MI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) def main(): mod = 10**9 + 7 cnt = 0 N = I() S = eval(input()) now = "A" for i in range(N): if S[i] != now: cnt += 1 now = S[i] print(cnt) main()
false
57.894737
[ "-n = int(eval(input()))", "-s = eval(input())", "-ans = 1", "-for i in range(1, n):", "- if s[i] != s[i - 1]:", "- ans += 1", "-print(ans)", "+def I():", "+ return int(eval(input()))", "+", "+", "+def MI():", "+ return list(map(int, input().split()))", "+", "+", "+def LI():", "+ return list(map(int, input().split()))", "+", "+", "+def main():", "+ mod = 10**9 + 7", "+ cnt = 0", "+ N = I()", "+ S = eval(input())", "+ now = \"A\"", "+ for i in range(N):", "+ if S[i] != now:", "+ cnt += 1", "+ now = S[i]", "+ print(cnt)", "+", "+", "+main()" ]
false
0.0443
0.044775
0.989383
[ "s658436525", "s686598811" ]
u347640436
p02630
python
s885991054
s254405837
271
202
23,572
20,412
Accepted
Accepted
25.46
from sys import stdin readline = stdin.readline N = int(readline()) A = list(map(int, readline().split())) Q = int(readline()) t = sum(A) d = {} for a in A: d.setdefault(a, 0) d[a] += 1 for _ in range(Q): B, C = list(map(int, readline().split())) d.setdefault(B, 0) d.setdefault(C, 0) t -= B * d[B] t += C * d[B] d[C] += d[B] d[B] = 0 print(t)
from sys import stdin readline = stdin.readline N = int(readline()) A = list(map(int, readline().split())) Q = int(readline()) t = [0] * (10 ** 5 + 1) s = sum(A) for a in A: t[a] += 1 for _ in range(Q): B, C = list(map(int, readline().split())) s -= B * t[B] s += C * t[B] t[C] += t[B] t[B] = 0 print(s)
22
19
402
347
from sys import stdin readline = stdin.readline N = int(readline()) A = list(map(int, readline().split())) Q = int(readline()) t = sum(A) d = {} for a in A: d.setdefault(a, 0) d[a] += 1 for _ in range(Q): B, C = list(map(int, readline().split())) d.setdefault(B, 0) d.setdefault(C, 0) t -= B * d[B] t += C * d[B] d[C] += d[B] d[B] = 0 print(t)
from sys import stdin readline = stdin.readline N = int(readline()) A = list(map(int, readline().split())) Q = int(readline()) t = [0] * (10**5 + 1) s = sum(A) for a in A: t[a] += 1 for _ in range(Q): B, C = list(map(int, readline().split())) s -= B * t[B] s += C * t[B] t[C] += t[B] t[B] = 0 print(s)
false
13.636364
[ "-t = sum(A)", "-d = {}", "+t = [0] * (10**5 + 1)", "+s = sum(A)", "- d.setdefault(a, 0)", "- d[a] += 1", "+ t[a] += 1", "- d.setdefault(B, 0)", "- d.setdefault(C, 0)", "- t -= B * d[B]", "- t += C * d[B]", "- d[C] += d[B]", "- d[B] = 0", "- print(t)", "+ s -= B * t[B]", "+ s += C * t[B]", "+ t[C] += t[B]", "+ t[B] = 0", "+ print(s)" ]
false
0.046832
0.047967
0.97632
[ "s885991054", "s254405837" ]
u241159583
p03274
python
s886416693
s540738080
103
95
14,224
14,252
Accepted
Accepted
7.77
n, k = list(map(int, input().split())) X = list(map(int, input().split())) ans = float('inf') for i in range(n-k+1): l, r = X[i], X[i+k-1] if r <= 0: ans = min(abs(l), ans) elif 0 <= l: ans = min(abs(r), ans) else: dist = min(abs(l), abs(r))*2+max(abs(l), abs(r)) ans = min(dist, ans) print(ans)
n, k = list(map(int, input().split())) x = list(map(int, input().split())) ans = float("inf") for i in range(n-k+1): l, r = x[i], x[i+k-1] if r <= 0: a = abs(l) elif l >= 0: a = r else: a = min(abs(l), abs(r)) * 2 + max(abs(l), abs(r)) if ans > a: ans = a print(ans)
14
13
351
316
n, k = list(map(int, input().split())) X = list(map(int, input().split())) ans = float("inf") for i in range(n - k + 1): l, r = X[i], X[i + k - 1] if r <= 0: ans = min(abs(l), ans) elif 0 <= l: ans = min(abs(r), ans) else: dist = min(abs(l), abs(r)) * 2 + max(abs(l), abs(r)) ans = min(dist, ans) print(ans)
n, k = list(map(int, input().split())) x = list(map(int, input().split())) ans = float("inf") for i in range(n - k + 1): l, r = x[i], x[i + k - 1] if r <= 0: a = abs(l) elif l >= 0: a = r else: a = min(abs(l), abs(r)) * 2 + max(abs(l), abs(r)) if ans > a: ans = a print(ans)
false
7.142857
[ "-X = list(map(int, input().split()))", "+x = list(map(int, input().split()))", "- l, r = X[i], X[i + k - 1]", "+ l, r = x[i], x[i + k - 1]", "- ans = min(abs(l), ans)", "- elif 0 <= l:", "- ans = min(abs(r), ans)", "+ a = abs(l)", "+ elif l >= 0:", "+ a = r", "- dist = min(abs(l), abs(r)) * 2 + max(abs(l), abs(r))", "- ans = min(dist, ans)", "+ a = min(abs(l), abs(r)) * 2 + max(abs(l), abs(r))", "+ if ans > a:", "+ ans = a" ]
false
0.111637
0.046264
2.413053
[ "s886416693", "s540738080" ]
u163703551
p03806
python
s836736469
s458388953
592
342
40,228
6,124
Accepted
Accepted
42.23
import sys # sys.stdin = open('d1.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 solve(): M = 10 n, ma, mb = read_int_list() p = [read_int_list() for i in range(n)] min_c = {(0, 0, 0): 0} for i in range(1, n + 1): a, b, c = p[i - 1] for u in range(0, M * (i - 1) + 1): for v in range(0, M * (i - 1) + 1): if (i - 1, u, v) in min_c: cost = min_c[(i - 1, u, v)] cc = cost + c uu = u + a vv = v + b if (i, uu, vv) not in min_c: min_c[(i, uu, vv)] = cc if cc < min_c[(i, uu, vv)]: min_c[(i, uu, vv)] = cc cc = cost uu = u vv = v if (i, uu, vv) not in min_c: min_c[(i, uu, vv)] = cc if cc < min_c[(i, uu, vv)]: min_c[(i, uu, vv)] = cc inf = 10 ** 20 res = inf for u in range(0, M * n + 1): for v in range(0, M * n + 1): if u == 0 and v == 0: continue if u * mb == v * ma: if (n, u, v) in min_c: cost = min_c[(n, u, v)] if cost < res: res = cost if res == inf: res = -1 return res def main(): res = solve() print(res) main()
import sys from collections import defaultdict # sys.stdin = open('d1.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()) M = 10 inf = 10 ** 20 def solve(): n, ma, mb = read_int_list() p = [read_int_list() for i in range(n)] min_c = defaultdict(lambda: inf) min_c[(0, 0)] = 0 for i, (a, b, c) in enumerate(p): for u in range(M * i, -1, -1): for v in range(M * i, -1, -1): if (u, v) in min_c: cost = min_c[(u, v)] if cost + c < min_c[((u + a), (v + b))]: min_c[((u + a), (v + b))] = cost + c res = inf for u in range(0, M * n + 1): for v in range(0, M * n + 1): if u == 0 and v == 0: continue if u * mb == v * ma: if (u, v) in min_c: cost = min_c[(u, v)] if cost < res: res = cost if res == inf: res = -1 return res def main(): res = solve() print(res) main()
71
61
1,724
1,258
import sys # sys.stdin = open('d1.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 solve(): M = 10 n, ma, mb = read_int_list() p = [read_int_list() for i in range(n)] min_c = {(0, 0, 0): 0} for i in range(1, n + 1): a, b, c = p[i - 1] for u in range(0, M * (i - 1) + 1): for v in range(0, M * (i - 1) + 1): if (i - 1, u, v) in min_c: cost = min_c[(i - 1, u, v)] cc = cost + c uu = u + a vv = v + b if (i, uu, vv) not in min_c: min_c[(i, uu, vv)] = cc if cc < min_c[(i, uu, vv)]: min_c[(i, uu, vv)] = cc cc = cost uu = u vv = v if (i, uu, vv) not in min_c: min_c[(i, uu, vv)] = cc if cc < min_c[(i, uu, vv)]: min_c[(i, uu, vv)] = cc inf = 10**20 res = inf for u in range(0, M * n + 1): for v in range(0, M * n + 1): if u == 0 and v == 0: continue if u * mb == v * ma: if (n, u, v) in min_c: cost = min_c[(n, u, v)] if cost < res: res = cost if res == inf: res = -1 return res def main(): res = solve() print(res) main()
import sys from collections import defaultdict # sys.stdin = open('d1.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()) M = 10 inf = 10**20 def solve(): n, ma, mb = read_int_list() p = [read_int_list() for i in range(n)] min_c = defaultdict(lambda: inf) min_c[(0, 0)] = 0 for i, (a, b, c) in enumerate(p): for u in range(M * i, -1, -1): for v in range(M * i, -1, -1): if (u, v) in min_c: cost = min_c[(u, v)] if cost + c < min_c[((u + a), (v + b))]: min_c[((u + a), (v + b))] = cost + c res = inf for u in range(0, M * n + 1): for v in range(0, M * n + 1): if u == 0 and v == 0: continue if u * mb == v * ma: if (u, v) in min_c: cost = min_c[(u, v)] if cost < res: res = cost if res == inf: res = -1 return res def main(): res = solve() print(res) main()
false
14.084507
[ "+from collections import defaultdict", "+M = 10", "+inf = 10**20", "+", "+", "- M = 10", "- min_c = {(0, 0, 0): 0}", "- for i in range(1, n + 1):", "- a, b, c = p[i - 1]", "- for u in range(0, M * (i - 1) + 1):", "- for v in range(0, M * (i - 1) + 1):", "- if (i - 1, u, v) in min_c:", "- cost = min_c[(i - 1, u, v)]", "- cc = cost + c", "- uu = u + a", "- vv = v + b", "- if (i, uu, vv) not in min_c:", "- min_c[(i, uu, vv)] = cc", "- if cc < min_c[(i, uu, vv)]:", "- min_c[(i, uu, vv)] = cc", "- cc = cost", "- uu = u", "- vv = v", "- if (i, uu, vv) not in min_c:", "- min_c[(i, uu, vv)] = cc", "- if cc < min_c[(i, uu, vv)]:", "- min_c[(i, uu, vv)] = cc", "- inf = 10**20", "+ min_c = defaultdict(lambda: inf)", "+ min_c[(0, 0)] = 0", "+ for i, (a, b, c) in enumerate(p):", "+ for u in range(M * i, -1, -1):", "+ for v in range(M * i, -1, -1):", "+ if (u, v) in min_c:", "+ cost = min_c[(u, v)]", "+ if cost + c < min_c[((u + a), (v + b))]:", "+ min_c[((u + a), (v + b))] = cost + c", "- if (n, u, v) in min_c:", "- cost = min_c[(n, u, v)]", "+ if (u, v) in min_c:", "+ cost = min_c[(u, v)]" ]
false
0.043695
0.035276
1.238666
[ "s836736469", "s458388953" ]
u077291787
p03425
python
s663298300
s134687000
165
61
9,772
9,772
Accepted
Accepted
63.03
# ABC089C - March from itertools import combinations def main(): n = int(eval(input())) lst = [input().rstrip() for _ in range(n)] cond = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0} for i in lst: if i[0] in "MARCH": cond[i[0]] += 1 ans = 0 for x, y, z in combinations("MARCH", 3): ans += cond[x] * cond[y] * cond[z] print(ans) if __name__ == "__main__": main()
# ABC089C - March import sys input = sys.stdin.readline from itertools import combinations def main(): n = int(eval(input())) lst = [input().rstrip() for _ in range(n)] cond = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0} for i in lst: if i[0] in "MARCH": cond[i[0]] += 1 ans = 0 for x, y, z in combinations("MARCH", 3): ans += cond[x] * cond[y] * cond[z] print(ans) if __name__ == "__main__": main()
19
22
433
475
# ABC089C - March from itertools import combinations def main(): n = int(eval(input())) lst = [input().rstrip() for _ in range(n)] cond = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0} for i in lst: if i[0] in "MARCH": cond[i[0]] += 1 ans = 0 for x, y, z in combinations("MARCH", 3): ans += cond[x] * cond[y] * cond[z] print(ans) if __name__ == "__main__": main()
# ABC089C - March import sys input = sys.stdin.readline from itertools import combinations def main(): n = int(eval(input())) lst = [input().rstrip() for _ in range(n)] cond = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0} for i in lst: if i[0] in "MARCH": cond[i[0]] += 1 ans = 0 for x, y, z in combinations("MARCH", 3): ans += cond[x] * cond[y] * cond[z] print(ans) if __name__ == "__main__": main()
false
13.636364
[ "+import sys", "+", "+input = sys.stdin.readline" ]
false
0.036017
0.037105
0.970688
[ "s663298300", "s134687000" ]
u281303342
p03315
python
s342243520
s902091656
19
17
2,940
2,940
Accepted
Accepted
10.53
S = eval(input()) print((S.count("+")-S.count("-")))
S = eval(input()) a = S.count("+") b = S.count("-") print((a-b))
2
4
45
60
S = eval(input()) print((S.count("+") - S.count("-")))
S = eval(input()) a = S.count("+") b = S.count("-") print((a - b))
false
50
[ "-print((S.count(\"+\") - S.count(\"-\")))", "+a = S.count(\"+\")", "+b = S.count(\"-\")", "+print((a - b))" ]
false
0.050927
0.049652
1.025678
[ "s342243520", "s902091656" ]
u425351967
p03163
python
s976765080
s431986233
473
414
120,044
118,512
Accepted
Accepted
12.47
N, W = (int(n) for n in input().split()) w, v = [], [] for _ in range(N): w_, v_ = (int(n) for n in input().split()) w.append(w_) v.append(v_) dp = [[0] * (W + 1) for _ in range(N + 1)] for i in range(N): for w_ in range(W + 1): if w_ >= w[i]: dp[i + 1][w_] = max(dp[i][w_], dp[i][w_ - w[i]] + v[i]) else: dp[i + 1][w_] = dp[i][w_] print((dp[N][W]))
N, weight_capacity = (int(n) for n in input().split()) weights, values = [], [] for _ in range(N): w, v = (int(n) for n in input().split()) weights.append(w) values.append(v) def knapsack_dp(weight_capacity, weights, values): """Solve knapsack problem by dynamic programming""" N = len(weights) dp = [[0] * (weight_capacity + 1) for _ in range(len(weights) + 1)] for i in range(N): for w in range(weight_capacity + 1): if w >= weights[i]: dp[i + 1][w] = max(dp[i][w], dp[i][w - weights[i]] + values[i]) else: dp[i + 1][w] = dp[i][w] return dp[N][weight_capacity] print((knapsack_dp(weight_capacity, weights, values)))
17
22
422
737
N, W = (int(n) for n in input().split()) w, v = [], [] for _ in range(N): w_, v_ = (int(n) for n in input().split()) w.append(w_) v.append(v_) dp = [[0] * (W + 1) for _ in range(N + 1)] for i in range(N): for w_ in range(W + 1): if w_ >= w[i]: dp[i + 1][w_] = max(dp[i][w_], dp[i][w_ - w[i]] + v[i]) else: dp[i + 1][w_] = dp[i][w_] print((dp[N][W]))
N, weight_capacity = (int(n) for n in input().split()) weights, values = [], [] for _ in range(N): w, v = (int(n) for n in input().split()) weights.append(w) values.append(v) def knapsack_dp(weight_capacity, weights, values): """Solve knapsack problem by dynamic programming""" N = len(weights) dp = [[0] * (weight_capacity + 1) for _ in range(len(weights) + 1)] for i in range(N): for w in range(weight_capacity + 1): if w >= weights[i]: dp[i + 1][w] = max(dp[i][w], dp[i][w - weights[i]] + values[i]) else: dp[i + 1][w] = dp[i][w] return dp[N][weight_capacity] print((knapsack_dp(weight_capacity, weights, values)))
false
22.727273
[ "-N, W = (int(n) for n in input().split())", "-w, v = [], []", "+N, weight_capacity = (int(n) for n in input().split())", "+weights, values = [], []", "- w_, v_ = (int(n) for n in input().split())", "- w.append(w_)", "- v.append(v_)", "-dp = [[0] * (W + 1) for _ in range(N + 1)]", "-for i in range(N):", "- for w_ in range(W + 1):", "- if w_ >= w[i]:", "- dp[i + 1][w_] = max(dp[i][w_], dp[i][w_ - w[i]] + v[i])", "- else:", "- dp[i + 1][w_] = dp[i][w_]", "-print((dp[N][W]))", "+ w, v = (int(n) for n in input().split())", "+ weights.append(w)", "+ values.append(v)", "+", "+", "+def knapsack_dp(weight_capacity, weights, values):", "+ \"\"\"Solve knapsack problem by dynamic programming\"\"\"", "+ N = len(weights)", "+ dp = [[0] * (weight_capacity + 1) for _ in range(len(weights) + 1)]", "+ for i in range(N):", "+ for w in range(weight_capacity + 1):", "+ if w >= weights[i]:", "+ dp[i + 1][w] = max(dp[i][w], dp[i][w - weights[i]] + values[i])", "+ else:", "+ dp[i + 1][w] = dp[i][w]", "+ return dp[N][weight_capacity]", "+", "+", "+print((knapsack_dp(weight_capacity, weights, values)))" ]
false
0.047261
0.116151
0.406891
[ "s976765080", "s431986233" ]
u906501980
p02713
python
s286005751
s597326422
206
44
75,244
9,372
Accepted
Accepted
78.64
def main(): k = int(eval(input())) gcds = list(sorted([gcd(i, j) for i in range(1, k+1) for j in range(1, k+1)])) j = 0 s = list(sorted(list(set(gcds)))) m = k**2-1 gcdss = [0]*len(s) flag = False for i, l in enumerate(s): while gcds[j] == l: gcdss[i] += 1 if j == m: flag = True break j += 1 if flag: break ans = sum([gcd(i, p)*n for i in range(1, k+1) for p, n in zip(s, gcdss)]) print(ans) def gcd(a, b): if a < b: a, b = b, a if a % b == 0: return b else: return gcd(b, a%b) if __name__ == "__main__": main()
def main(): k = int(eval(input())) gcds = [] for i in range(1, k+1): for j in range(1, k+1): gcds.append(gcd(i, j)) ans = {i:0 for i in set(gcds)} for i in gcds: ans[i] += 1 out = 0 for i, v in list(ans.items()): for j in range(1, k+1): out += gcd(i, j)*v print(out) def gcd(x, y): r = x % y while r: x, y, r = y, r, y%r return y if __name__ == "__main__": main()
32
23
734
479
def main(): k = int(eval(input())) gcds = list(sorted([gcd(i, j) for i in range(1, k + 1) for j in range(1, k + 1)])) j = 0 s = list(sorted(list(set(gcds)))) m = k**2 - 1 gcdss = [0] * len(s) flag = False for i, l in enumerate(s): while gcds[j] == l: gcdss[i] += 1 if j == m: flag = True break j += 1 if flag: break ans = sum([gcd(i, p) * n for i in range(1, k + 1) for p, n in zip(s, gcdss)]) print(ans) def gcd(a, b): if a < b: a, b = b, a if a % b == 0: return b else: return gcd(b, a % b) if __name__ == "__main__": main()
def main(): k = int(eval(input())) gcds = [] for i in range(1, k + 1): for j in range(1, k + 1): gcds.append(gcd(i, j)) ans = {i: 0 for i in set(gcds)} for i in gcds: ans[i] += 1 out = 0 for i, v in list(ans.items()): for j in range(1, k + 1): out += gcd(i, j) * v print(out) def gcd(x, y): r = x % y while r: x, y, r = y, r, y % r return y if __name__ == "__main__": main()
false
28.125
[ "- gcds = list(sorted([gcd(i, j) for i in range(1, k + 1) for j in range(1, k + 1)]))", "- j = 0", "- s = list(sorted(list(set(gcds))))", "- m = k**2 - 1", "- gcdss = [0] * len(s)", "- flag = False", "- for i, l in enumerate(s):", "- while gcds[j] == l:", "- gcdss[i] += 1", "- if j == m:", "- flag = True", "- break", "- j += 1", "- if flag:", "- break", "- ans = sum([gcd(i, p) * n for i in range(1, k + 1) for p, n in zip(s, gcdss)])", "- print(ans)", "+ gcds = []", "+ for i in range(1, k + 1):", "+ for j in range(1, k + 1):", "+ gcds.append(gcd(i, j))", "+ ans = {i: 0 for i in set(gcds)}", "+ for i in gcds:", "+ ans[i] += 1", "+ out = 0", "+ for i, v in list(ans.items()):", "+ for j in range(1, k + 1):", "+ out += gcd(i, j) * v", "+ print(out)", "-def gcd(a, b):", "- if a < b:", "- a, b = b, a", "- if a % b == 0:", "- return b", "- else:", "- return gcd(b, a % b)", "+def gcd(x, y):", "+ r = x % y", "+ while r:", "+ x, y, r = y, r, y % r", "+ return y" ]
false
0.30121
0.048938
6.154955
[ "s286005751", "s597326422" ]
u906501980
p02660
python
s415895864
s867816186
72
66
65,844
65,720
Accepted
Accepted
8.33
from collections import Counter def get_prime_factors(x): out = [] if x < 1: return out while not x%2: out.append(2) x //= 2 i = 3 while i*i <= x: if not x%i: out.append(i) x //= i else: i += 2 if x != 1: out.append(x) return out def main(): n = int(eval(input())) ans = 0 primes = Counter(get_prime_factors(n)) for k, v in list(primes.items()): num = 1 while v >= num: v -= num num += 1 ans += 1 print(ans) if __name__ == "__main__": main()
from collections import Counter def get_prime_factors(x): out = [] if x < 1: return out while not x%2: out.append(2) x //= 2 i = 3 while i*i <= x: if not x%i: out.append(i) x //= i else: i += 2 if x != 1: out.append(x) return out def main(): n = int(eval(input())) primes = Counter(get_prime_factors(n)) ans = 0 for k, v in list(primes.items()): num = 1 while v >= num: v -= num num += 1 ans += 1 print(ans) if __name__ == "__main__": main()
35
34
663
661
from collections import Counter def get_prime_factors(x): out = [] if x < 1: return out while not x % 2: out.append(2) x //= 2 i = 3 while i * i <= x: if not x % i: out.append(i) x //= i else: i += 2 if x != 1: out.append(x) return out def main(): n = int(eval(input())) ans = 0 primes = Counter(get_prime_factors(n)) for k, v in list(primes.items()): num = 1 while v >= num: v -= num num += 1 ans += 1 print(ans) if __name__ == "__main__": main()
from collections import Counter def get_prime_factors(x): out = [] if x < 1: return out while not x % 2: out.append(2) x //= 2 i = 3 while i * i <= x: if not x % i: out.append(i) x //= i else: i += 2 if x != 1: out.append(x) return out def main(): n = int(eval(input())) primes = Counter(get_prime_factors(n)) ans = 0 for k, v in list(primes.items()): num = 1 while v >= num: v -= num num += 1 ans += 1 print(ans) if __name__ == "__main__": main()
false
2.857143
[ "+ primes = Counter(get_prime_factors(n))", "- primes = Counter(get_prime_factors(n))" ]
false
0.038371
0.036699
1.045575
[ "s415895864", "s867816186" ]
u814986259
p03107
python
s857039111
s176891401
49
34
3,188
3,188
Accepted
Accepted
30.61
S = eval(input()) count = [0, 0] for x in S: count[int(x)] += 1 print((min(count)*2))
d = dict() d['0'] = 0 d['1'] = 0 S = eval(input()) for x in S: d[x] += 1 print((min(d['0'], d['1'])*2))
6
9
88
110
S = eval(input()) count = [0, 0] for x in S: count[int(x)] += 1 print((min(count) * 2))
d = dict() d["0"] = 0 d["1"] = 0 S = eval(input()) for x in S: d[x] += 1 print((min(d["0"], d["1"]) * 2))
false
33.333333
[ "+d = dict()", "+d[\"0\"] = 0", "+d[\"1\"] = 0", "-count = [0, 0]", "- count[int(x)] += 1", "-print((min(count) * 2))", "+ d[x] += 1", "+print((min(d[\"0\"], d[\"1\"]) * 2))" ]
false
0.036548
0.167109
0.218705
[ "s857039111", "s176891401" ]
u957198490
p03719
python
s705716815
s405355834
166
17
38,384
2,940
Accepted
Accepted
89.76
A,B,C = list(map(int,input().split())) if A <= C and C <= B: print('Yes') else: print('No')
a,b,c = list(map(int,input().split())) if a <= c and c <= b: print('Yes') else: print('No')
5
5
98
97
A, B, C = list(map(int, input().split())) if A <= C and C <= B: print("Yes") else: print("No")
a, b, c = list(map(int, input().split())) if a <= c and c <= b: print("Yes") else: print("No")
false
0
[ "-A, B, C = list(map(int, input().split()))", "-if A <= C and C <= B:", "+a, b, c = list(map(int, input().split()))", "+if a <= c and c <= b:" ]
false
0.081679
0.079591
1.026225
[ "s705716815", "s405355834" ]
u357751375
p03371
python
s273744491
s343042050
29
24
9,104
9,136
Accepted
Accepted
17.24
a,b,c,x,y = list(map(int,input().split())) l = 0 p = x if x > y: l += (x - y) * a p = y elif x < y: l += (y - x) * b p = x else: pass l += p * 2 * c n = max(x,y) * 2 * c m = x * a + y * b print((min(l,n,m)))
a,b,c,x,y = list(map(int,input().split())) l = 0 flg = x if x > y: l += (x - y) * a flg = y elif x < y: l += (y - x) * b else: pass l += flg * 2 * c n = max(x,y) * 2 * c m = x * a + y * b print((min(l,n,m)))
16
14
235
228
a, b, c, x, y = list(map(int, input().split())) l = 0 p = x if x > y: l += (x - y) * a p = y elif x < y: l += (y - x) * b p = x else: pass l += p * 2 * c n = max(x, y) * 2 * c m = x * a + y * b print((min(l, n, m)))
a, b, c, x, y = list(map(int, input().split())) l = 0 flg = x if x > y: l += (x - y) * a flg = y elif x < y: l += (y - x) * b else: pass l += flg * 2 * c n = max(x, y) * 2 * c m = x * a + y * b print((min(l, n, m)))
false
12.5
[ "-p = x", "+flg = x", "- p = y", "+ flg = y", "- p = x", "-l += p * 2 * c", "+l += flg * 2 * c" ]
false
0.036368
0.046015
0.790338
[ "s273744491", "s343042050" ]
u219494936
p02642
python
s977317747
s709669630
1,275
1,174
51,296
51,296
Accepted
Accepted
7.92
import numpy as np N = int(eval(input())) A = list(map(int, input().split(" "))) Amax = max(A) dp = np.ones(Amax, dtype=bool) appear = np.zeros(Amax, dtype=int) for a in A: appear[a-1] += 1 for i in range(1, len(dp)+1): if not dp[i-1]: continue if appear[i-1] != 0: j = 2 while j * i <= Amax: dp[j * i - 1] = False j += 1 # print(dp) app_set = set([]) dup_set = set([]) count = 0 for a in A: if appear[a-1] > 1: continue else: count += dp[a-1] print((count - len(dup_set)))
import numpy as np N = int(eval(input())) A = [int(x) for x in input().split(" ")] Amax = max(A) dp = np.ones(Amax, dtype=bool) appear = np.zeros(Amax, dtype=int) for a in A: appear[a-1] += 1 for i in range(1, len(dp)+1): if not dp[i-1]: continue if appear[i-1] != 0: j = 2 while j * i <= Amax: dp[j * i - 1] = False j += 1 count = 0 for a in A: if appear[a-1] > 1: continue else: count += dp[a-1] print(count)
30
26
542
475
import numpy as np N = int(eval(input())) A = list(map(int, input().split(" "))) Amax = max(A) dp = np.ones(Amax, dtype=bool) appear = np.zeros(Amax, dtype=int) for a in A: appear[a - 1] += 1 for i in range(1, len(dp) + 1): if not dp[i - 1]: continue if appear[i - 1] != 0: j = 2 while j * i <= Amax: dp[j * i - 1] = False j += 1 # print(dp) app_set = set([]) dup_set = set([]) count = 0 for a in A: if appear[a - 1] > 1: continue else: count += dp[a - 1] print((count - len(dup_set)))
import numpy as np N = int(eval(input())) A = [int(x) for x in input().split(" ")] Amax = max(A) dp = np.ones(Amax, dtype=bool) appear = np.zeros(Amax, dtype=int) for a in A: appear[a - 1] += 1 for i in range(1, len(dp) + 1): if not dp[i - 1]: continue if appear[i - 1] != 0: j = 2 while j * i <= Amax: dp[j * i - 1] = False j += 1 count = 0 for a in A: if appear[a - 1] > 1: continue else: count += dp[a - 1] print(count)
false
13.333333
[ "-A = list(map(int, input().split(\" \")))", "+A = [int(x) for x in input().split(\" \")]", "-# print(dp)", "-app_set = set([])", "-dup_set = set([])", "-print((count - len(dup_set)))", "+print(count)" ]
false
0.271825
0.282171
0.963335
[ "s977317747", "s709669630" ]
u357751375
p02881
python
s969286829
s257071519
158
146
9,164
9,112
Accepted
Accepted
7.59
import math n = int(eval(input())) p = 10 ** 12 m = math.floor(math.sqrt(n)) for i in range(1,m + 1): if n % i == 0: j = n // i p = min(p,i-1+j-1) print(p)
from math import sqrt from math import floor n = int(eval(input())) ans = 10 ** 12 m = floor(sqrt(n)) for i in range(1,m+1): if n % i == 0: j = n // i ans = min(ans,i+j-2) print(ans)
11
10
181
205
import math n = int(eval(input())) p = 10**12 m = math.floor(math.sqrt(n)) for i in range(1, m + 1): if n % i == 0: j = n // i p = min(p, i - 1 + j - 1) print(p)
from math import sqrt from math import floor n = int(eval(input())) ans = 10**12 m = floor(sqrt(n)) for i in range(1, m + 1): if n % i == 0: j = n // i ans = min(ans, i + j - 2) print(ans)
false
9.090909
[ "-import math", "+from math import sqrt", "+from math import floor", "-p = 10**12", "-m = math.floor(math.sqrt(n))", "+ans = 10**12", "+m = floor(sqrt(n))", "- p = min(p, i - 1 + j - 1)", "-print(p)", "+ ans = min(ans, i + j - 2)", "+print(ans)" ]
false
0.094179
0.082855
1.136663
[ "s969286829", "s257071519" ]
u583010173
p03457
python
s905320566
s512558251
403
365
21,108
3,064
Accepted
Accepted
9.43
# -*- coding: utf-8 -*- n = int(eval(input())) t_bef, x_bef, y_bef, flag = 0, 0, 0, 0 travel = [] for i in range(n): travel.append([int(x) for x in input().split()]) for j in travel: t, x, y = j[0], j[1], j[2] check = (t - t_bef) - abs(x_bef - x) - abs(y_bef - y) t_bef, x_bef, y_bef = t, x, y if check < 0: print('No') flag = 1 break if check % 2 != 0: print('No') flag = 1 break if flag == 0: print('Yes')
# -*- coding: utf-8 -*- n = int(eval(input())) t_bef, x_bef, y_bef, flag = 0, 0, 0, 0 travel = [] for i in range(n): t, x, y = [int(x) for x in input().split()] check = (t - t_bef) - abs(x_bef - x) - abs(y_bef - y) t_bef, x_bef, y_bef = t, x, y if check < 0: print('No') flag = 1 break if check % 2 != 0: print('No') flag = 1 break if flag == 0: print('Yes')
22
19
500
443
# -*- coding: utf-8 -*- n = int(eval(input())) t_bef, x_bef, y_bef, flag = 0, 0, 0, 0 travel = [] for i in range(n): travel.append([int(x) for x in input().split()]) for j in travel: t, x, y = j[0], j[1], j[2] check = (t - t_bef) - abs(x_bef - x) - abs(y_bef - y) t_bef, x_bef, y_bef = t, x, y if check < 0: print("No") flag = 1 break if check % 2 != 0: print("No") flag = 1 break if flag == 0: print("Yes")
# -*- coding: utf-8 -*- n = int(eval(input())) t_bef, x_bef, y_bef, flag = 0, 0, 0, 0 travel = [] for i in range(n): t, x, y = [int(x) for x in input().split()] check = (t - t_bef) - abs(x_bef - x) - abs(y_bef - y) t_bef, x_bef, y_bef = t, x, y if check < 0: print("No") flag = 1 break if check % 2 != 0: print("No") flag = 1 break if flag == 0: print("Yes")
false
13.636364
[ "- travel.append([int(x) for x in input().split()])", "-for j in travel:", "- t, x, y = j[0], j[1], j[2]", "+ t, x, y = [int(x) for x in input().split()]" ]
false
0.069513
0.039033
1.780878
[ "s905320566", "s512558251" ]
u044220565
p02845
python
s380114675
s539062311
722
90
143,872
19,728
Accepted
Accepted
87.53
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read from heapq import heappop, heappush from collections import defaultdict sys.setrecursionlimit(10**7) import math #from itertools import product, accumulate, combinations, product #import bisect #import numpy as np #from copy import deepcopy #from collections import deque #from decimal import Decimal #from numba import jit INF = 1 << 50 EPS = 1e-8 mod = 10 ** 9 + 7 def mapline(t = int): return list(map(t, sysread().split())) def mapread(t = int): return list(map(t, read().split())) def run(): N, *A = mapread() dp = [defaultdict(lambda:0) for _ in range(N+1)] dp[0][(0,0,0)] = 1 for i in range(N): a = A[i] k = i + 1 for key in list(dp[k-1].keys()): for ii, v in enumerate(key): if v == a: tmp = list(key) tmp[ii] += 1 dp[k][tuple(tmp)] += dp[k-1][key] % mod ans = 0 for key in list(dp[N].keys()): ans = (ans + dp[N][key]) % mod #print(dp) print(ans) if __name__ == "__main__": run()
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read from heapq import heappop, heappush from collections import defaultdict sys.setrecursionlimit(10**7) import math #from itertools import product, accumulate, combinations, product #import bisect #import numpy as np #from copy import deepcopy #from collections import deque #from decimal import Decimal #from numba import jit INF = 1 << 50 EPS = 1e-8 mod = 10 ** 9 + 7 def mapline(t = int): return list(map(t, sysread().split())) def mapread(t = int): return list(map(t, read().split())) def run(): N, *A = mapread() ans = 1 current = [0,0,0] for a in A: transition = 0 cache = 1 for i, c in enumerate(current): if c == a: transition += 1 cache = i ans *= transition ans %= mod current[cache] += 1 #print(current) print(ans) if __name__ == "__main__": run()
49
45
1,207
1,049
# coding: utf-8 import sys # from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read from heapq import heappop, heappush from collections import defaultdict sys.setrecursionlimit(10**7) import math # from itertools import product, accumulate, combinations, product # import bisect # import numpy as np # from copy import deepcopy # from collections import deque # from decimal import Decimal # from numba import jit INF = 1 << 50 EPS = 1e-8 mod = 10**9 + 7 def mapline(t=int): return list(map(t, sysread().split())) def mapread(t=int): return list(map(t, read().split())) def run(): N, *A = mapread() dp = [defaultdict(lambda: 0) for _ in range(N + 1)] dp[0][(0, 0, 0)] = 1 for i in range(N): a = A[i] k = i + 1 for key in list(dp[k - 1].keys()): for ii, v in enumerate(key): if v == a: tmp = list(key) tmp[ii] += 1 dp[k][tuple(tmp)] += dp[k - 1][key] % mod ans = 0 for key in list(dp[N].keys()): ans = (ans + dp[N][key]) % mod # print(dp) print(ans) if __name__ == "__main__": run()
# coding: utf-8 import sys # from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read from heapq import heappop, heappush from collections import defaultdict sys.setrecursionlimit(10**7) import math # from itertools import product, accumulate, combinations, product # import bisect # import numpy as np # from copy import deepcopy # from collections import deque # from decimal import Decimal # from numba import jit INF = 1 << 50 EPS = 1e-8 mod = 10**9 + 7 def mapline(t=int): return list(map(t, sysread().split())) def mapread(t=int): return list(map(t, read().split())) def run(): N, *A = mapread() ans = 1 current = [0, 0, 0] for a in A: transition = 0 cache = 1 for i, c in enumerate(current): if c == a: transition += 1 cache = i ans *= transition ans %= mod current[cache] += 1 # print(current) print(ans) if __name__ == "__main__": run()
false
8.163265
[ "- dp = [defaultdict(lambda: 0) for _ in range(N + 1)]", "- dp[0][(0, 0, 0)] = 1", "- for i in range(N):", "- a = A[i]", "- k = i + 1", "- for key in list(dp[k - 1].keys()):", "- for ii, v in enumerate(key):", "- if v == a:", "- tmp = list(key)", "- tmp[ii] += 1", "- dp[k][tuple(tmp)] += dp[k - 1][key] % mod", "- ans = 0", "- for key in list(dp[N].keys()):", "- ans = (ans + dp[N][key]) % mod", "- # print(dp)", "+ ans = 1", "+ current = [0, 0, 0]", "+ for a in A:", "+ transition = 0", "+ cache = 1", "+ for i, c in enumerate(current):", "+ if c == a:", "+ transition += 1", "+ cache = i", "+ ans *= transition", "+ ans %= mod", "+ current[cache] += 1", "+ # print(current)" ]
false
0.044246
0.034059
1.299109
[ "s380114675", "s539062311" ]
u803848678
p02839
python
s548821656
s815198222
1,990
243
691,464
55,900
Accepted
Accepted
87.79
def x(): return list(map(int,input().split())) v=list c=abs r=range h,w=x() p=v(r(h)) a=[v(x())for i in p] b=[v(x())for i in p] m=13120 D=[[[0]*m for i in r(w)]for i in p] for i in p: for j in r(w): k=c(a[i][j]-b[i][j]) if i|j: for l in r((i+j+1)*80+1): e=c(l-k) D[i][j][l]=D[i][j-1][e]|D[i][j-1][l+k]|D[i-1][j][e]|D[i-1][j][l+k] else: D[i][j][k]=1 print((D[-1][-1].index(1)))
h,w = list(map(int, input().split())) a = [list(map(int, input().split())) for i in range(h)] b = [list(map(int, input().split())) for i in range(h)] # zeroは真ん中にする ma = 80*2*80 DP = [[0]*w for i in range(h)] for i in range(h): for j in range(w): k = abs(a[i][j]-b[i][j]) if i|j: m = DP[i-1][j]|DP[i][j-1] else: m = 1<<ma DP[i][j] = (m<<k)|(m>>k) k = 1<<ma for i in range(ma): if DP[-1][-1]&(k>>i) or DP[-1][-1]&(k<<i): print(i) exit()
21
21
410
530
def x(): return list(map(int, input().split())) v = list c = abs r = range h, w = x() p = v(r(h)) a = [v(x()) for i in p] b = [v(x()) for i in p] m = 13120 D = [[[0] * m for i in r(w)] for i in p] for i in p: for j in r(w): k = c(a[i][j] - b[i][j]) if i | j: for l in r((i + j + 1) * 80 + 1): e = c(l - k) D[i][j][l] = ( D[i][j - 1][e] | D[i][j - 1][l + k] | D[i - 1][j][e] | D[i - 1][j][l + k] ) else: D[i][j][k] = 1 print((D[-1][-1].index(1)))
h, w = list(map(int, input().split())) a = [list(map(int, input().split())) for i in range(h)] b = [list(map(int, input().split())) for i in range(h)] # zeroは真ん中にする ma = 80 * 2 * 80 DP = [[0] * w for i in range(h)] for i in range(h): for j in range(w): k = abs(a[i][j] - b[i][j]) if i | j: m = DP[i - 1][j] | DP[i][j - 1] else: m = 1 << ma DP[i][j] = (m << k) | (m >> k) k = 1 << ma for i in range(ma): if DP[-1][-1] & (k >> i) or DP[-1][-1] & (k << i): print(i) exit()
false
0
[ "-def x():", "- return list(map(int, input().split()))", "-", "-", "-v = list", "-c = abs", "-r = range", "-h, w = x()", "-p = v(r(h))", "-a = [v(x()) for i in p]", "-b = [v(x()) for i in p]", "-m = 13120", "-D = [[[0] * m for i in r(w)] for i in p]", "-for i in p:", "- for j in r(w):", "- k = c(a[i][j] - b[i][j])", "+h, w = list(map(int, input().split()))", "+a = [list(map(int, input().split())) for i in range(h)]", "+b = [list(map(int, input().split())) for i in range(h)]", "+# zeroは真ん中にする", "+ma = 80 * 2 * 80", "+DP = [[0] * w for i in range(h)]", "+for i in range(h):", "+ for j in range(w):", "+ k = abs(a[i][j] - b[i][j])", "- for l in r((i + j + 1) * 80 + 1):", "- e = c(l - k)", "- D[i][j][l] = (", "- D[i][j - 1][e]", "- | D[i][j - 1][l + k]", "- | D[i - 1][j][e]", "- | D[i - 1][j][l + k]", "- )", "+ m = DP[i - 1][j] | DP[i][j - 1]", "- D[i][j][k] = 1", "-print((D[-1][-1].index(1)))", "+ m = 1 << ma", "+ DP[i][j] = (m << k) | (m >> k)", "+k = 1 << ma", "+for i in range(ma):", "+ if DP[-1][-1] & (k >> i) or DP[-1][-1] & (k << i):", "+ print(i)", "+ exit()" ]
false
0.048294
0.039372
1.226586
[ "s548821656", "s815198222" ]
u952708174
p02889
python
s289652147
s111477097
1,007
910
41,632
41,652
Accepted
Accepted
9.63
def e_travel_by_car(INF=float('inf')): from copy import deepcopy from scipy.sparse.csgraph import floyd_warshall N, M, L = [int(i) for i in input().split()] Roads = [[int(i) for i in input().split()] for j in range(M)] Q = int(eval(input())) Queries = [[int(i) for i in input().split()] for j in range(Q)] graph = [[INF] * N for _ in range(N)] for k in range(N): graph[k][k] = 0 fuel = deepcopy(graph) for a, b, c in Roads: graph[a - 1][b - 1] = graph[b - 1][a - 1] = c dist = floyd_warshall(graph) for i in range(N): for j in range(N): fuel[i][j] = int(dist[i][j] <= L) fuel = floyd_warshall(fuel) ans = [-1 if fuel[s - 1][t - 1] == INF else int(fuel[s - 1][t - 1]) - 1 for s, t in Queries] return '\n'.join(map(str, ans)) print((e_travel_by_car()))
def e_travel_by_car(INF=float('inf')): from copy import deepcopy from scipy.sparse.csgraph import floyd_warshall N, M, L = [int(i) for i in input().split()] Roads = [[int(i) for i in input().split()] for j in range(M)] Q = int(eval(input())) Queries = [[int(i) for i in input().split()] for j in range(Q)] graph = [[INF] * N for _ in range(N)] for k in range(N): graph[k][k] = 0 fuel = deepcopy(graph) for a, b, c in Roads: graph[a - 1][b - 1] = graph[b - 1][a - 1] = c dist = floyd_warshall(graph) for i in range(N): for j in range(i): fuel[i][j] = fuel[j][i] = int(dist[i][j] <= L) fuel = floyd_warshall(fuel) ans = [-1 if fuel[s - 1][t - 1] == INF else int(fuel[s - 1][t - 1]) - 1 for s, t in Queries] return '\n'.join(map(str, ans)) print((e_travel_by_car()))
26
26
868
881
def e_travel_by_car(INF=float("inf")): from copy import deepcopy from scipy.sparse.csgraph import floyd_warshall N, M, L = [int(i) for i in input().split()] Roads = [[int(i) for i in input().split()] for j in range(M)] Q = int(eval(input())) Queries = [[int(i) for i in input().split()] for j in range(Q)] graph = [[INF] * N for _ in range(N)] for k in range(N): graph[k][k] = 0 fuel = deepcopy(graph) for a, b, c in Roads: graph[a - 1][b - 1] = graph[b - 1][a - 1] = c dist = floyd_warshall(graph) for i in range(N): for j in range(N): fuel[i][j] = int(dist[i][j] <= L) fuel = floyd_warshall(fuel) ans = [ -1 if fuel[s - 1][t - 1] == INF else int(fuel[s - 1][t - 1]) - 1 for s, t in Queries ] return "\n".join(map(str, ans)) print((e_travel_by_car()))
def e_travel_by_car(INF=float("inf")): from copy import deepcopy from scipy.sparse.csgraph import floyd_warshall N, M, L = [int(i) for i in input().split()] Roads = [[int(i) for i in input().split()] for j in range(M)] Q = int(eval(input())) Queries = [[int(i) for i in input().split()] for j in range(Q)] graph = [[INF] * N for _ in range(N)] for k in range(N): graph[k][k] = 0 fuel = deepcopy(graph) for a, b, c in Roads: graph[a - 1][b - 1] = graph[b - 1][a - 1] = c dist = floyd_warshall(graph) for i in range(N): for j in range(i): fuel[i][j] = fuel[j][i] = int(dist[i][j] <= L) fuel = floyd_warshall(fuel) ans = [ -1 if fuel[s - 1][t - 1] == INF else int(fuel[s - 1][t - 1]) - 1 for s, t in Queries ] return "\n".join(map(str, ans)) print((e_travel_by_car()))
false
0
[ "- for j in range(N):", "- fuel[i][j] = int(dist[i][j] <= L)", "+ for j in range(i):", "+ fuel[i][j] = fuel[j][i] = int(dist[i][j] <= L)" ]
false
0.255082
0.591247
0.431431
[ "s289652147", "s111477097" ]
u892487306
p02642
python
s351579834
s219646312
1,116
988
44,020
36,752
Accepted
Accepted
11.47
from collections import Counter def main(): N = int(eval(input())) A = list(map(int, input().split(' '))) counter = Counter(A) searched = [0 for _ in range(10 ** 6 + 1)] ans = 0 for i in range(1, 10 ** 6 + 1): if counter[i] == 0: continue if searched[i] == 0 and counter[i] == 1: ans += 1 for j in range(1, ((10 ** 6) // i) + 1): searched[i * j] = 1 print(ans) if __name__ == '__main__': main()
def main(): N = int(eval(input())) A = list(map(int, input().split(' '))) counter = [0 for _ in range(10 ** 6 + 1)] for a in A: counter[a] += 1 searched = [0 for _ in range(10 ** 6 + 1)] ans = 0 for i in range(1, 10 ** 6 + 1): if counter[i] == 0: continue if searched[i] == 0 and counter[i] == 1: ans += 1 for j in range(1, ((10 ** 6) // i) + 1): searched[i * j] = 1 print(ans) if __name__ == '__main__': main()
21
20
504
530
from collections import Counter def main(): N = int(eval(input())) A = list(map(int, input().split(" "))) counter = Counter(A) searched = [0 for _ in range(10**6 + 1)] ans = 0 for i in range(1, 10**6 + 1): if counter[i] == 0: continue if searched[i] == 0 and counter[i] == 1: ans += 1 for j in range(1, ((10**6) // i) + 1): searched[i * j] = 1 print(ans) if __name__ == "__main__": main()
def main(): N = int(eval(input())) A = list(map(int, input().split(" "))) counter = [0 for _ in range(10**6 + 1)] for a in A: counter[a] += 1 searched = [0 for _ in range(10**6 + 1)] ans = 0 for i in range(1, 10**6 + 1): if counter[i] == 0: continue if searched[i] == 0 and counter[i] == 1: ans += 1 for j in range(1, ((10**6) // i) + 1): searched[i * j] = 1 print(ans) if __name__ == "__main__": main()
false
4.761905
[ "-from collections import Counter", "-", "-", "- counter = Counter(A)", "+ counter = [0 for _ in range(10**6 + 1)]", "+ for a in A:", "+ counter[a] += 1" ]
false
0.699581
0.355595
1.967351
[ "s351579834", "s219646312" ]
u489959379
p02881
python
s816242564
s060561753
161
116
3,560
3,268
Accepted
Accepted
27.95
n = int(eval(input())) divisors = [] for i in range(1, int(pow(n, 0.5)) + 1): if n % i == 0: divisors.append([i, n // i]) divisors = sorted(divisors, key= lambda x:x[1]) res = 0 for i in divisors[0]: res += i - 1 print(res)
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 # nの約数を列挙列挙する def make_divisors(n): divisors = [] for i in range(1, int(pow(n, 0.5)) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) divisors.sort() return divisors def resolve(): n = int(eval(input())) div = make_divisors(n) res = f_inf for i in div: cost = i + n // i - 2 res = min(res, cost) print(res) if __name__ == '__main__': resolve()
12
34
246
597
n = int(eval(input())) divisors = [] for i in range(1, int(pow(n, 0.5)) + 1): if n % i == 0: divisors.append([i, n // i]) divisors = sorted(divisors, key=lambda x: x[1]) res = 0 for i in divisors[0]: res += i - 1 print(res)
import sys sys.setrecursionlimit(10**7) f_inf = float("inf") mod = 10**9 + 7 # nの約数を列挙列挙する def make_divisors(n): divisors = [] for i in range(1, int(pow(n, 0.5)) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) divisors.sort() return divisors def resolve(): n = int(eval(input())) div = make_divisors(n) res = f_inf for i in div: cost = i + n // i - 2 res = min(res, cost) print(res) if __name__ == "__main__": resolve()
false
64.705882
[ "-n = int(eval(input()))", "-divisors = []", "-for i in range(1, int(pow(n, 0.5)) + 1):", "- if n % i == 0:", "- divisors.append([i, n // i])", "-divisors = sorted(divisors, key=lambda x: x[1])", "-res = 0", "-for i in divisors[0]:", "- res += i - 1", "-print(res)", "+import sys", "+", "+sys.setrecursionlimit(10**7)", "+f_inf = float(\"inf\")", "+mod = 10**9 + 7", "+# nの約数を列挙列挙する", "+def make_divisors(n):", "+ divisors = []", "+ for i in range(1, int(pow(n, 0.5)) + 1):", "+ if n % i == 0:", "+ divisors.append(i)", "+ if i != n // i:", "+ divisors.append(n // i)", "+ divisors.sort()", "+ return divisors", "+", "+", "+def resolve():", "+ n = int(eval(input()))", "+ div = make_divisors(n)", "+ res = f_inf", "+ for i in div:", "+ cost = i + n // i - 2", "+ res = min(res, cost)", "+ print(res)", "+", "+", "+if __name__ == \"__main__\":", "+ resolve()" ]
false
0.040926
0.049788
0.821997
[ "s816242564", "s060561753" ]
u074220993
p03625
python
s951310898
s553864543
81
73
20,076
20,080
Accepted
Accepted
9.88
N = int(eval(input())) A = [int(x) for x in input().split()] pair = [] unpair = set() for a in A: if a in unpair: pair.append(a) unpair.remove(a) else: unpair.add(a) pair.sort() pair.reverse() if len(pair) <= 1: ans = 0 else: ans = pair[0] * pair[1] print(ans)
with open(0) as f: N, *A = list(map(int, f.read().split())) pair = [] unpair = set() for a in A: if a in unpair: unpair.remove(a) pair.append(a) else: unpair.add(a) pair.sort() print((pair.pop()*pair.pop() if len(pair) > 1 else 0))
19
13
314
272
N = int(eval(input())) A = [int(x) for x in input().split()] pair = [] unpair = set() for a in A: if a in unpair: pair.append(a) unpair.remove(a) else: unpair.add(a) pair.sort() pair.reverse() if len(pair) <= 1: ans = 0 else: ans = pair[0] * pair[1] print(ans)
with open(0) as f: N, *A = list(map(int, f.read().split())) pair = [] unpair = set() for a in A: if a in unpair: unpair.remove(a) pair.append(a) else: unpair.add(a) pair.sort() print((pair.pop() * pair.pop() if len(pair) > 1 else 0))
false
31.578947
[ "-N = int(eval(input()))", "-A = [int(x) for x in input().split()]", "+with open(0) as f:", "+ N, *A = list(map(int, f.read().split()))", "+ unpair.remove(a)", "- unpair.remove(a)", "-pair.reverse()", "-if len(pair) <= 1:", "- ans = 0", "-else:", "- ans = pair[0] * pair[1]", "-print(ans)", "+print((pair.pop() * pair.pop() if len(pair) > 1 else 0))" ]
false
0.061052
0.103829
0.588006
[ "s951310898", "s553864543" ]
u263830634
p02775
python
s166466677
s442466976
1,306
1,060
66,388
19,688
Accepted
Accepted
18.84
N = ['0'] + list(eval(input())) + ['0'] # print (N) n = len(N) ans = 0 flag = False count = 0 for i in range(n - 1, 0, -1): s = int(N[i]) if flag: s += 1 N[i] = str(s) else: pass if s <= 5: next_ = int(N[i - 1]) if s == 5 and next_ >= 5: # ans -= 1 ans += s flag = True else: ans += s flag = False else: ans += 10 - s flag = True if flag: ans += 1 count = 0 for s in N: if s == '5': count += 1 else: ans -= max(count -2, 0) count = 0 print (ans)
S = ['0'] + list(eval(input())) + ['0'] N = len(S) flag = False ans = 0 for i in range(N - 1, 0, -1): j = int(S[i]) if flag: j += 1 S[i] = j if j <= 5: if j == 5 and int(S[i - 1]) >= 5: ans += j flag = True else: ans += j flag = False else: ans += 10 - j flag = True if flag: ans += 1 # print (ans) count = 0 for s in S: if s == 5: count += 1 else: ans -= max(0, count - 2) count = 0 print (ans)
43
43
674
617
N = ["0"] + list(eval(input())) + ["0"] # print (N) n = len(N) ans = 0 flag = False count = 0 for i in range(n - 1, 0, -1): s = int(N[i]) if flag: s += 1 N[i] = str(s) else: pass if s <= 5: next_ = int(N[i - 1]) if s == 5 and next_ >= 5: # ans -= 1 ans += s flag = True else: ans += s flag = False else: ans += 10 - s flag = True if flag: ans += 1 count = 0 for s in N: if s == "5": count += 1 else: ans -= max(count - 2, 0) count = 0 print(ans)
S = ["0"] + list(eval(input())) + ["0"] N = len(S) flag = False ans = 0 for i in range(N - 1, 0, -1): j = int(S[i]) if flag: j += 1 S[i] = j if j <= 5: if j == 5 and int(S[i - 1]) >= 5: ans += j flag = True else: ans += j flag = False else: ans += 10 - j flag = True if flag: ans += 1 # print (ans) count = 0 for s in S: if s == 5: count += 1 else: ans -= max(0, count - 2) count = 0 print(ans)
false
0
[ "-N = [\"0\"] + list(eval(input())) + [\"0\"]", "-# print (N)", "-n = len(N)", "+S = [\"0\"] + list(eval(input())) + [\"0\"]", "+N = len(S)", "+flag = False", "-flag = False", "-count = 0", "-for i in range(n - 1, 0, -1):", "- s = int(N[i])", "+for i in range(N - 1, 0, -1):", "+ j = int(S[i])", "- s += 1", "- N[i] = str(s)", "- else:", "- pass", "- if s <= 5:", "- next_ = int(N[i - 1])", "- if s == 5 and next_ >= 5:", "- # ans -= 1", "- ans += s", "+ j += 1", "+ S[i] = j", "+ if j <= 5:", "+ if j == 5 and int(S[i - 1]) >= 5:", "+ ans += j", "- ans += s", "+ ans += j", "- ans += 10 - s", "+ ans += 10 - j", "+# print (ans)", "-for s in N:", "- if s == \"5\":", "+for s in S:", "+ if s == 5:", "- ans -= max(count - 2, 0)", "+ ans -= max(0, count - 2)" ]
false
0.044866
0.04445
1.009375
[ "s166466677", "s442466976" ]
u764215612
p02708
python
s049837569
s836838081
99
91
9,188
9,192
Accepted
Accepted
8.08
n, k = list(map(int, input().split())) ans = 0 p = 10 ** 9 + 7 a = 0 b = 0 for j in range(k): a += j b += n-j for i in range(k, n+2): ans = (ans+b-a+1)%p a += i b += n-i print(ans)
n, k = list(map(int, input().split())) ans = 0 p = 10 ** 9 + 7 a = 0 b = 0 for j in range(k-1): a += j b += n-j for i in range(k-1, n+1): a += i b += n-i ans = (ans+b-a+1)%p print(ans)
13
13
196
200
n, k = list(map(int, input().split())) ans = 0 p = 10**9 + 7 a = 0 b = 0 for j in range(k): a += j b += n - j for i in range(k, n + 2): ans = (ans + b - a + 1) % p a += i b += n - i print(ans)
n, k = list(map(int, input().split())) ans = 0 p = 10**9 + 7 a = 0 b = 0 for j in range(k - 1): a += j b += n - j for i in range(k - 1, n + 1): a += i b += n - i ans = (ans + b - a + 1) % p print(ans)
false
0
[ "-for j in range(k):", "+for j in range(k - 1):", "-for i in range(k, n + 2):", "- ans = (ans + b - a + 1) % p", "+for i in range(k - 1, n + 1):", "+ ans = (ans + b - a + 1) % p" ]
false
0.187884
0.072659
2.585821
[ "s049837569", "s836838081" ]
u572122511
p02659
python
s095817390
s059329515
24
21
9,156
9,156
Accepted
Accepted
12.5
AB = list(input().split()) A = int(AB[0]) B = int(float(AB[1]) * 100 + 0.5) A *= B print((A // 100))
AB = list(input().split()) A = int(AB[0]) B = int(float(AB[1]) * 100 + 0.5) print((A * B // 100))
5
4
102
98
AB = list(input().split()) A = int(AB[0]) B = int(float(AB[1]) * 100 + 0.5) A *= B print((A // 100))
AB = list(input().split()) A = int(AB[0]) B = int(float(AB[1]) * 100 + 0.5) print((A * B // 100))
false
20
[ "-A *= B", "-print((A // 100))", "+print((A * B // 100))" ]
false
0.040624
0.04432
0.916614
[ "s095817390", "s059329515" ]
u435480265
p02579
python
s817941497
s111115638
637
569
167,676
96,356
Accepted
Accepted
10.68
h,w = list(map(int, input().split())) ch, cw = list(map(int, input().split())) ch -= 1 cw -= 1 dh,dw = list(map(int, input().split())) dh -= 1 dw -= 1 def trans(s): res = [] for i in s: if i == '.': res.append(-1) else: res.append(-2) return res def move(x,y,dq,dq_next): for ix,iy in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]: if ix > h-1 or ix < 0 or iy > w-1 or iy < 0: continue if (m[ix][iy] == -1) or (m[ix][iy] > m[x][y]): m[ix][iy] = m[x][y] dq.append((ix, iy)) for ix, iy in [(x-2, y-2), (x-2, y-1), (x-2, y), (x-2, y+1), (x-2, y+2), (x-1, y-2), (x-1, y-1), (x-1, y+1), (x-1, y+2), (x, y-2), (x, y+2), (x+1, y-2), (x+1, y-1), (x+1, y+1), (x+1, y+2), (x+2, y-2), (x+2, y-1), (x+2, y), (x+2, y+1), (x+2, y+2)]: if ix > h-1 or ix < 0 or iy > w-1 or iy < 0: continue if m[ix][iy] == -1: m[ix][iy] = m[x][y] + 1 dq_next.append((ix, iy)) m = [trans(eval(input())) for _ in range(h)] from collections import deque m[ch][cw] = 0 def main(): dq = deque() dq_next = deque() dq.append((ch,cw)) s_moved = set() while True: while len(dq)>0: xx, yy = dq.popleft() if not (xx, yy) in s_moved: if xx == dh and yy == dw: return m[xx][yy] move(xx, yy, dq, dq_next) s_moved.add((xx, yy)) if len(dq_next) > 0: dq = dq_next.copy() dq_next = deque() else: return -1 print((main()))
h,w = list(map(int, input().split())) ch, cw = list(map(int, input().split())) ch -= 1 cw -= 1 dh,dw = list(map(int, input().split())) dh -= 1 dw -= 1 def trans(s): res = [] for i in s: if i == '.': res.append(-1) else: res.append(-2) return res def move(x,y,dq,dq_next): for ix,iy in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]: if ix > h-1 or ix < 0 or iy > w-1 or iy < 0: continue if (m[ix][iy] == -1) or (m[ix][iy] > m[x][y]): m[ix][iy] = m[x][y] dq.append((ix, iy)) for ix, iy in [(x-2, y-2), (x-2, y-1), (x-2, y), (x-2, y+1), (x-2, y+2), (x-1, y-2), (x-1, y-1), (x-1, y+1), (x-1, y+2), (x, y-2), (x, y+2), (x+1, y-2), (x+1, y-1), (x+1, y+1), (x+1, y+2), (x+2, y-2), (x+2, y-1), (x+2, y), (x+2, y+1), (x+2, y+2)]: if ix > h-1 or ix < 0 or iy > w-1 or iy < 0: continue if m[ix][iy] == -1: m[ix][iy] = m[x][y] + 1 dq_next.append((ix, iy)) m = [trans(eval(input())) for _ in range(h)] from collections import deque m[ch][cw] = 0 def main(): dq = deque() dq_next = deque() dq.append((ch,cw)) while True: while len(dq)>0: xx, yy = dq.popleft() if xx == dh and yy == dw: return m[xx][yy] move(xx, yy, dq, dq_next) if len(dq_next) > 0: dq = dq_next.copy() dq_next = deque() else: return -1 print((main()))
61
58
1,754
1,649
h, w = list(map(int, input().split())) ch, cw = list(map(int, input().split())) ch -= 1 cw -= 1 dh, dw = list(map(int, input().split())) dh -= 1 dw -= 1 def trans(s): res = [] for i in s: if i == ".": res.append(-1) else: res.append(-2) return res def move(x, y, dq, dq_next): for ix, iy in [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]: if ix > h - 1 or ix < 0 or iy > w - 1 or iy < 0: continue if (m[ix][iy] == -1) or (m[ix][iy] > m[x][y]): m[ix][iy] = m[x][y] dq.append((ix, iy)) for ix, iy in [ (x - 2, y - 2), (x - 2, y - 1), (x - 2, y), (x - 2, y + 1), (x - 2, y + 2), (x - 1, y - 2), (x - 1, y - 1), (x - 1, y + 1), (x - 1, y + 2), (x, y - 2), (x, y + 2), (x + 1, y - 2), (x + 1, y - 1), (x + 1, y + 1), (x + 1, y + 2), (x + 2, y - 2), (x + 2, y - 1), (x + 2, y), (x + 2, y + 1), (x + 2, y + 2), ]: if ix > h - 1 or ix < 0 or iy > w - 1 or iy < 0: continue if m[ix][iy] == -1: m[ix][iy] = m[x][y] + 1 dq_next.append((ix, iy)) m = [trans(eval(input())) for _ in range(h)] from collections import deque m[ch][cw] = 0 def main(): dq = deque() dq_next = deque() dq.append((ch, cw)) s_moved = set() while True: while len(dq) > 0: xx, yy = dq.popleft() if not (xx, yy) in s_moved: if xx == dh and yy == dw: return m[xx][yy] move(xx, yy, dq, dq_next) s_moved.add((xx, yy)) if len(dq_next) > 0: dq = dq_next.copy() dq_next = deque() else: return -1 print((main()))
h, w = list(map(int, input().split())) ch, cw = list(map(int, input().split())) ch -= 1 cw -= 1 dh, dw = list(map(int, input().split())) dh -= 1 dw -= 1 def trans(s): res = [] for i in s: if i == ".": res.append(-1) else: res.append(-2) return res def move(x, y, dq, dq_next): for ix, iy in [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]: if ix > h - 1 or ix < 0 or iy > w - 1 or iy < 0: continue if (m[ix][iy] == -1) or (m[ix][iy] > m[x][y]): m[ix][iy] = m[x][y] dq.append((ix, iy)) for ix, iy in [ (x - 2, y - 2), (x - 2, y - 1), (x - 2, y), (x - 2, y + 1), (x - 2, y + 2), (x - 1, y - 2), (x - 1, y - 1), (x - 1, y + 1), (x - 1, y + 2), (x, y - 2), (x, y + 2), (x + 1, y - 2), (x + 1, y - 1), (x + 1, y + 1), (x + 1, y + 2), (x + 2, y - 2), (x + 2, y - 1), (x + 2, y), (x + 2, y + 1), (x + 2, y + 2), ]: if ix > h - 1 or ix < 0 or iy > w - 1 or iy < 0: continue if m[ix][iy] == -1: m[ix][iy] = m[x][y] + 1 dq_next.append((ix, iy)) m = [trans(eval(input())) for _ in range(h)] from collections import deque m[ch][cw] = 0 def main(): dq = deque() dq_next = deque() dq.append((ch, cw)) while True: while len(dq) > 0: xx, yy = dq.popleft() if xx == dh and yy == dw: return m[xx][yy] move(xx, yy, dq, dq_next) if len(dq_next) > 0: dq = dq_next.copy() dq_next = deque() else: return -1 print((main()))
false
4.918033
[ "- s_moved = set()", "- if not (xx, yy) in s_moved:", "- if xx == dh and yy == dw:", "- return m[xx][yy]", "- move(xx, yy, dq, dq_next)", "- s_moved.add((xx, yy))", "+ if xx == dh and yy == dw:", "+ return m[xx][yy]", "+ move(xx, yy, dq, dq_next)" ]
false
0.044177
0.044155
1.000488
[ "s817941497", "s111115638" ]
u751717561
p04033
python
s915230642
s681573567
311
153
20,948
12,256
Accepted
Accepted
50.8
import bisect,collections,copy,heapq,itertools,math,numpy,string import sys def S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) #N = I() #A = [LI() for _ in range(N)] a, b = list(map(int,sys.stdin.readline().rstrip().split())) if a > 0: print('Positive') elif a <= 0 and b >= 0: print('Zero') else: if (a+b)%2 == 0: print('Negative') else: print('Positive')
import bisect,collections,copy,heapq,itertools,math,numpy,string import sys #N = I() #A = [LI() for _ in range(N)] a, b = list(map(int,sys.stdin.readline().rstrip().split())) if a > 0: print('Positive') elif a <= 0 and b >= 0: print('Zero') else: if (a+b)%2 == 0: print('Negative') else: print('Positive')
20
16
586
354
import bisect, collections, copy, heapq, itertools, math, numpy, string import sys def S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) # N = I() # A = [LI() for _ in range(N)] a, b = list(map(int, sys.stdin.readline().rstrip().split())) if a > 0: print("Positive") elif a <= 0 and b >= 0: print("Zero") else: if (a + b) % 2 == 0: print("Negative") else: print("Positive")
import bisect, collections, copy, heapq, itertools, math, numpy, string import sys # N = I() # A = [LI() for _ in range(N)] a, b = list(map(int, sys.stdin.readline().rstrip().split())) if a > 0: print("Positive") elif a <= 0 and b >= 0: print("Zero") else: if (a + b) % 2 == 0: print("Negative") else: print("Positive")
false
20
[ "-", "-", "-def S():", "- return sys.stdin.readline().rstrip()", "-", "-", "-def I():", "- return int(sys.stdin.readline().rstrip())", "-", "-", "-def LI():", "- return list(map(int, sys.stdin.readline().rstrip().split()))", "-", "-", "-def LS():", "- return list(sys.stdin.readline().rstrip().split())", "-" ]
false
0.112027
0.040152
2.790097
[ "s915230642", "s681573567" ]
u197300260
p03495
python
s385923552
s030551009
203
145
39,344
44,184
Accepted
Accepted
28.57
# _*_ coding:utf-8 _*_ # Atcoder_Beginnger_Contest081-C # TODO https://atcoder.jp/contests/abc081/tasks/arc086_a import collections as col def solveProblem(neededBallKind,BallsList): AsListCounter = col.Counter(BallsList) allBallKind = len(AsListCounter) sortCounter = sorted(list(AsListCounter.items()),reverse=False,key=lambda x:x[1]) replaceBallCount = 0 replaceBallKind = allBallKind-neededBallKind if replaceBallKind <= 0: answer = 0 else: for k,v in sortCounter: replaceBallCount = replaceBallCount + v replaceBallKind = replaceBallKind - 1 if replaceBallKind <= 0: break answer = replaceBallCount return answer if __name__ == '__main__': _,K = list(map(int,input().strip().split(' '))) AsList = list(map(int,input().strip().split(' '))) solution = solveProblem(K,AsList) print(("{}".format(solution)))
# Problem: atcoder.jp/contests/abc081/tasks/arc086_a # Python 1st Try import sys # from collections import defaultdict import collections as col # import pprint # import heapq,copy # from collections import deque def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def solver(ALLNUM, KIND, ball_numbers): result = 0 # prp = pprint.pprint counter_result = col.Counter(ball_numbers) ball_num_len = len(counter_result) counter_result_sorted = sorted(list(counter_result.items()), key=lambda x: x[1]) # prp(counter_result_sorted) if ball_num_len <= KIND: return 0 reduce_kind = ball_num_len - KIND # prp(reduce_kind) for _, ballCount in counter_result_sorted: result += ballCount reduce_kind = reduce_kind - 1 # prp(reduce_kind) if reduce_kind <= 0: break return result if __name__ == "__main__": N, K = MI() Ai = list(map(int, sys.stdin.readline().split())) # print(Ai) print(("{}".format(solver(N, K, Ai))))
27
40
856
1,227
# _*_ coding:utf-8 _*_ # Atcoder_Beginnger_Contest081-C # TODO https://atcoder.jp/contests/abc081/tasks/arc086_a import collections as col def solveProblem(neededBallKind, BallsList): AsListCounter = col.Counter(BallsList) allBallKind = len(AsListCounter) sortCounter = sorted(list(AsListCounter.items()), reverse=False, key=lambda x: x[1]) replaceBallCount = 0 replaceBallKind = allBallKind - neededBallKind if replaceBallKind <= 0: answer = 0 else: for k, v in sortCounter: replaceBallCount = replaceBallCount + v replaceBallKind = replaceBallKind - 1 if replaceBallKind <= 0: break answer = replaceBallCount return answer if __name__ == "__main__": _, K = list(map(int, input().strip().split(" "))) AsList = list(map(int, input().strip().split(" "))) solution = solveProblem(K, AsList) print(("{}".format(solution)))
# Problem: atcoder.jp/contests/abc081/tasks/arc086_a # Python 1st Try import sys # from collections import defaultdict import collections as col # import pprint # import heapq,copy # from collections import deque def II(): return int(sys.stdin.readline()) def MI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def solver(ALLNUM, KIND, ball_numbers): result = 0 # prp = pprint.pprint counter_result = col.Counter(ball_numbers) ball_num_len = len(counter_result) counter_result_sorted = sorted(list(counter_result.items()), key=lambda x: x[1]) # prp(counter_result_sorted) if ball_num_len <= KIND: return 0 reduce_kind = ball_num_len - KIND # prp(reduce_kind) for _, ballCount in counter_result_sorted: result += ballCount reduce_kind = reduce_kind - 1 # prp(reduce_kind) if reduce_kind <= 0: break return result if __name__ == "__main__": N, K = MI() Ai = list(map(int, sys.stdin.readline().split())) # print(Ai) print(("{}".format(solver(N, K, Ai))))
false
32.5
[ "-# _*_ coding:utf-8 _*_", "-# Atcoder_Beginnger_Contest081-C", "-# TODO https://atcoder.jp/contests/abc081/tasks/arc086_a", "+# Problem: atcoder.jp/contests/abc081/tasks/arc086_a", "+# Python 1st Try", "+import sys", "+", "+# from collections import defaultdict", "+# import pprint", "+# import heapq,copy", "+# from collections import deque", "+def II():", "+ return int(sys.stdin.readline())", "-def solveProblem(neededBallKind, BallsList):", "- AsListCounter = col.Counter(BallsList)", "- allBallKind = len(AsListCounter)", "- sortCounter = sorted(list(AsListCounter.items()), reverse=False, key=lambda x: x[1])", "- replaceBallCount = 0", "- replaceBallKind = allBallKind - neededBallKind", "- if replaceBallKind <= 0:", "- answer = 0", "- else:", "- for k, v in sortCounter:", "- replaceBallCount = replaceBallCount + v", "- replaceBallKind = replaceBallKind - 1", "- if replaceBallKind <= 0:", "- break", "- answer = replaceBallCount", "- return answer", "+", "+def MI():", "+ return list(map(int, sys.stdin.readline().split()))", "+", "+", "+def LI():", "+ return list(map(int, sys.stdin.readline().split()))", "+", "+", "+def LLI(rows_number):", "+ return [LI() for _ in range(rows_number)]", "+", "+", "+def solver(ALLNUM, KIND, ball_numbers):", "+ result = 0", "+ # prp = pprint.pprint", "+ counter_result = col.Counter(ball_numbers)", "+ ball_num_len = len(counter_result)", "+ counter_result_sorted = sorted(list(counter_result.items()), key=lambda x: x[1])", "+ # prp(counter_result_sorted)", "+ if ball_num_len <= KIND:", "+ return 0", "+ reduce_kind = ball_num_len - KIND", "+ # prp(reduce_kind)", "+ for _, ballCount in counter_result_sorted:", "+ result += ballCount", "+ reduce_kind = reduce_kind - 1", "+ # prp(reduce_kind)", "+ if reduce_kind <= 0:", "+ break", "+ return result", "- _, K = list(map(int, input().strip().split(\" \")))", "- AsList = list(map(int, input().strip().split(\" \")))", "- solution = solveProblem(K, AsList)", "- print((\"{}\".format(solution)))", "+ N, K = MI()", "+ Ai = list(map(int, sys.stdin.readline().split()))", "+ # print(Ai)", "+ print((\"{}\".format(solver(N, K, Ai))))" ]
false
0.056214
0.05348
1.051121
[ "s385923552", "s030551009" ]
u546338822
p02779
python
s855593554
s583216030
90
83
26,808
26,808
Accepted
Accepted
7.78
n = int(eval(input())) a = list(map(int,input().split())) if len(a) == len(set(a)): print('YES') else: print('NO')
n = int(eval(input())) a = list(map(int,input().split())) if n == len(set(a)): print('YES') else: print('NO')
9
7
127
118
n = int(eval(input())) a = list(map(int, input().split())) if len(a) == len(set(a)): print("YES") else: print("NO")
n = int(eval(input())) a = list(map(int, input().split())) if n == len(set(a)): print("YES") else: print("NO")
false
22.222222
[ "-if len(a) == len(set(a)):", "+if n == len(set(a)):" ]
false
0.046635
0.045872
1.016629
[ "s855593554", "s583216030" ]
u677523557
p03452
python
s730710784
s936984716
1,931
1,352
131,224
67,404
Accepted
Accepted
29.98
import sys sys.setrecursionlimit(1000000) N, M = list(map(int, input().split())) class UnionFind(): # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1]*(n+1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0]*(n+1) # ノードxのrootノードを見つける def Find_Root(self, x): if(self.root[x] < 0): return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if(x == y): return # 違う木に属していた場合rnkを見てくっつける方を決める elif(self.rnk[x] > self.rnk[y]): self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if(self.rnk[x] == self.rnk[y]): self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): return -self.root[self.Find_Root(x)] union = UnionFind(N-1) graph = [[] for _ in range(N)] for _ in range(M): a, b, d = list(map(int, input().split())) graph[a-1].append((d, b-1)) graph[b-1].append((-d, a-1)) union.Unite(a-1, b-1) roots = set() for i in range(N): roots.add(union.Find_Root(i)) NUM = [None for _ in range(N)] checked = [False for _ in range(N)] def dfs(p, NUM, ans): x = NUM[p] for d, q in graph[p]: #print(p, q, NUM, d, x) if NUM[q] is None: NUM[q] = x+d elif NUM[q] != x+d: #print("different!!") ans = False return ans if checked[q]: continue checked[q] = True ans = dfs(q, NUM, ans) return ans ans = True for r in roots: NUM[r] = 0 ok = dfs(r, NUM, True) ans = ans and ok if ans: print('Yes') else: print('No')
class UnionFind(): # 作りたい要素数nで初期化 def __init__(self, n): self.n = n self.root = [-1]*(n+1) self.rnk = [0]*(n+1) # ノードxのrootノードを見つける def Find_Root(self, x): if(self.root[x] < 0): return x else: self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): x = self.Find_Root(x) y = self.Find_Root(y) if(x == y): return elif(self.rnk[x] > self.rnk[y]): self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if(self.rnk[x] == self.rnk[y]): self.rnk[y] += 1 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズ def Count(self, x): return -self.root[self.Find_Root(x)] import sys input = sys.stdin.readline N, M = list(map(int, input().split())) graph = [[] for _ in range(N)] uni = UnionFind(N) for _ in range(M): a, b, d = list(map(int, input().split())) uni.Unite(a-1, b-1) graph[a-1].append((d, b-1)) graph[b-1].append((-d, a-1)) INF = 10**14 A = [INF]*N def bfs(start): q = [start] A[start] = 0 while q: qq = [] for p in q: for d, np in graph[p]: if A[np] == INF: A[np] = A[p] + d qq.append(np) elif A[np] != A[p]+d: return False q = qq return True root = set() for i in range(N): root.add(uni.Find_Root(i)) ok = True for r in root: ok = ok and bfs(r) print(("Yes" if ok else "No"))
95
76
2,303
1,814
import sys sys.setrecursionlimit(1000000) N, M = list(map(int, input().split())) class UnionFind: # 作りたい要素数nで初期化 # 使用するインスタンス変数の初期化 def __init__(self, n): self.n = n # root[x]<0ならそのノードが根かつその値が木の要素数 # rootノードでその木の要素数を記録する self.root = [-1] * (n + 1) # 木をくっつける時にアンバランスにならないように調整する self.rnk = [0] * (n + 1) # ノードxのrootノードを見つける def Find_Root(self, x): if self.root[x] < 0: return x else: # ここで代入しておくことで、後の繰り返しを避ける self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): # 入力ノードのrootノードを見つける x = self.Find_Root(x) y = self.Find_Root(y) # すでに同じ木に属していた場合 if x == y: return # 違う木に属していた場合rnkを見てくっつける方を決める elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y # rnkが同じ(深さに差がない場合)は1増やす if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 # xとyが同じグループに属するか判断 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズを返す def Count(self, x): return -self.root[self.Find_Root(x)] union = UnionFind(N - 1) graph = [[] for _ in range(N)] for _ in range(M): a, b, d = list(map(int, input().split())) graph[a - 1].append((d, b - 1)) graph[b - 1].append((-d, a - 1)) union.Unite(a - 1, b - 1) roots = set() for i in range(N): roots.add(union.Find_Root(i)) NUM = [None for _ in range(N)] checked = [False for _ in range(N)] def dfs(p, NUM, ans): x = NUM[p] for d, q in graph[p]: # print(p, q, NUM, d, x) if NUM[q] is None: NUM[q] = x + d elif NUM[q] != x + d: # print("different!!") ans = False return ans if checked[q]: continue checked[q] = True ans = dfs(q, NUM, ans) return ans ans = True for r in roots: NUM[r] = 0 ok = dfs(r, NUM, True) ans = ans and ok if ans: print("Yes") else: print("No")
class UnionFind: # 作りたい要素数nで初期化 def __init__(self, n): self.n = n self.root = [-1] * (n + 1) self.rnk = [0] * (n + 1) # ノードxのrootノードを見つける def Find_Root(self, x): if self.root[x] < 0: return x else: self.root[x] = self.Find_Root(self.root[x]) return self.root[x] # 木の併合、入力は併合したい各ノード def Unite(self, x, y): x = self.Find_Root(x) y = self.Find_Root(y) if x == y: return elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) # ノードxが属する木のサイズ def Count(self, x): return -self.root[self.Find_Root(x)] import sys input = sys.stdin.readline N, M = list(map(int, input().split())) graph = [[] for _ in range(N)] uni = UnionFind(N) for _ in range(M): a, b, d = list(map(int, input().split())) uni.Unite(a - 1, b - 1) graph[a - 1].append((d, b - 1)) graph[b - 1].append((-d, a - 1)) INF = 10**14 A = [INF] * N def bfs(start): q = [start] A[start] = 0 while q: qq = [] for p in q: for d, np in graph[p]: if A[np] == INF: A[np] = A[p] + d qq.append(np) elif A[np] != A[p] + d: return False q = qq return True root = set() for i in range(N): root.add(uni.Find_Root(i)) ok = True for r in root: ok = ok and bfs(r) print(("Yes" if ok else "No"))
false
20
[ "-import sys", "-", "-sys.setrecursionlimit(1000000)", "-N, M = list(map(int, input().split()))", "-", "-", "- # 使用するインスタンス変数の初期化", "- # root[x]<0ならそのノードが根かつその値が木の要素数", "- # rootノードでその木の要素数を記録する", "- # 木をくっつける時にアンバランスにならないように調整する", "- # ここで代入しておくことで、後の繰り返しを避ける", "- # 入力ノードのrootノードを見つける", "- # すでに同じ木に属していた場合", "- # 違う木に属していた場合rnkを見てくっつける方を決める", "- # rnkが同じ(深さに差がない場合)は1増やす", "- # xとyが同じグループに属するか判断", "- # ノードxが属する木のサイズを返す", "+ # ノードxが属する木のサイズ", "-union = UnionFind(N - 1)", "+import sys", "+", "+input = sys.stdin.readline", "+N, M = list(map(int, input().split()))", "+uni = UnionFind(N)", "+ uni.Unite(a - 1, b - 1)", "- union.Unite(a - 1, b - 1)", "-roots = set()", "-for i in range(N):", "- roots.add(union.Find_Root(i))", "-NUM = [None for _ in range(N)]", "-checked = [False for _ in range(N)]", "+INF = 10**14", "+A = [INF] * N", "-def dfs(p, NUM, ans):", "- x = NUM[p]", "- for d, q in graph[p]:", "- # print(p, q, NUM, d, x)", "- if NUM[q] is None:", "- NUM[q] = x + d", "- elif NUM[q] != x + d:", "- # print(\"different!!\")", "- ans = False", "- return ans", "- if checked[q]:", "- continue", "- checked[q] = True", "- ans = dfs(q, NUM, ans)", "- return ans", "+def bfs(start):", "+ q = [start]", "+ A[start] = 0", "+ while q:", "+ qq = []", "+ for p in q:", "+ for d, np in graph[p]:", "+ if A[np] == INF:", "+ A[np] = A[p] + d", "+ qq.append(np)", "+ elif A[np] != A[p] + d:", "+ return False", "+ q = qq", "+ return True", "-ans = True", "-for r in roots:", "- NUM[r] = 0", "- ok = dfs(r, NUM, True)", "- ans = ans and ok", "-if ans:", "- print(\"Yes\")", "-else:", "- print(\"No\")", "+root = set()", "+for i in range(N):", "+ root.add(uni.Find_Root(i))", "+ok = True", "+for r in root:", "+ ok = ok and bfs(r)", "+print((\"Yes\" if ok else \"No\"))" ]
false
0.121897
0.048991
2.488165
[ "s730710784", "s936984716" ]
u064505481
p02685
python
s371407946
s015915357
419
257
84,472
75,776
Accepted
Accepted
38.66
from sys import stdin, stdout rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: list(map(int, stdin.readline().split())) INF, NINF = float('inf'), float('-inf') def binom_tables(n, q): fact = [1 for _ in range(n + 1)] inv = [1 for _ in range(n + 1)] for i in range(1, n+1): fact[i] = (fact[i-1] * i) % q inv[i] = pow(fact[i], q-2, q) return fact, inv def binom(n, k, q, F, I): return (F[n]*((I[k]*I[n-k])%q))%q def main(): MOD = 998244353 n, m, k = rli() F, I = binom_tables(n, MOD) ans = 0 for i in range(n-k, n+1): ans += (binom(n-1, i-1, MOD, F, I)*m*pow(m-1, i-1, MOD))%MOD print((ans % MOD)) if __name__ == "__main__": main()
from sys import stdin, stdout rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: list(map(int, stdin.readline().split())) INF, NINF = float('inf'), float('-inf') def binom_tables(n, q): fact = [1 for _ in range(n + 1)] inv = [1 for _ in range(n + 1)] for i in range(1, n+1): fact[i] = (fact[i-1] * i) % q inv[i] = pow(fact[i], q-2, q) return fact, inv def main(): MOD = 998244353 n, m, k = rli() F, I = binom_tables(n, MOD) def binom(n, k, q): return (F[n]*((I[k]*I[n-k])%q))%q ans = 0 for i in range(n-k, n+1): ans += (binom(n-1, i-1, MOD)*m*pow(m-1, i-1, MOD))%MOD print((ans % MOD)) if __name__ == "__main__": main()
30
31
708
701
from sys import stdin, stdout rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: list(map(int, stdin.readline().split())) INF, NINF = float("inf"), float("-inf") def binom_tables(n, q): fact = [1 for _ in range(n + 1)] inv = [1 for _ in range(n + 1)] for i in range(1, n + 1): fact[i] = (fact[i - 1] * i) % q inv[i] = pow(fact[i], q - 2, q) return fact, inv def binom(n, k, q, F, I): return (F[n] * ((I[k] * I[n - k]) % q)) % q def main(): MOD = 998244353 n, m, k = rli() F, I = binom_tables(n, MOD) ans = 0 for i in range(n - k, n + 1): ans += (binom(n - 1, i - 1, MOD, F, I) * m * pow(m - 1, i - 1, MOD)) % MOD print((ans % MOD)) if __name__ == "__main__": main()
from sys import stdin, stdout rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: list(map(int, stdin.readline().split())) INF, NINF = float("inf"), float("-inf") def binom_tables(n, q): fact = [1 for _ in range(n + 1)] inv = [1 for _ in range(n + 1)] for i in range(1, n + 1): fact[i] = (fact[i - 1] * i) % q inv[i] = pow(fact[i], q - 2, q) return fact, inv def main(): MOD = 998244353 n, m, k = rli() F, I = binom_tables(n, MOD) def binom(n, k, q): return (F[n] * ((I[k] * I[n - k]) % q)) % q ans = 0 for i in range(n - k, n + 1): ans += (binom(n - 1, i - 1, MOD) * m * pow(m - 1, i - 1, MOD)) % MOD print((ans % MOD)) if __name__ == "__main__": main()
false
3.225806
[ "-def binom(n, k, q, F, I):", "- return (F[n] * ((I[k] * I[n - k]) % q)) % q", "-", "-", "+", "+ def binom(n, k, q):", "+ return (F[n] * ((I[k] * I[n - k]) % q)) % q", "+", "- ans += (binom(n - 1, i - 1, MOD, F, I) * m * pow(m - 1, i - 1, MOD)) % MOD", "+ ans += (binom(n - 1, i - 1, MOD) * m * pow(m - 1, i - 1, MOD)) % MOD" ]
false
0.424269
0.127267
3.333679
[ "s371407946", "s015915357" ]
u692746605
p02733
python
s389703333
s531725481
1,533
907
3,444
3,444
Accepted
Accepted
40.83
H,W,K=list(map(int,input().split())) S=[[int(x) for x in list(str(eval(input())))] for _ in range(H)] T=[[0]*(W+1) for x in range(H+1)] for h in range(H): for w in range(W): T[h][w]=T[h][w-1]+S[h][w] for h in range(1,H): for w in range(W): T[h][w]=T[h][w]+T[h-1][w] m=(H-1)*(W-1) for p in range(2**(H-1)): D=[x for x in range(H-1) if p&(2**x)!=0]+[H-1] c,b=0,-1 f=False for w in range(W): u=-1 for d in D: if T[d][w]-T[u][w]-T[d][b]+T[u][b]>K: if b==w-1: f=True c,b=c+1,w-1 break u=d if f==True: break else: m=min(m,c+len(D)-1) print(m)
H,W,K=list(map(int,input().split())) S=[[int(x) for x in list(str(eval(input())))] for _ in range(H)] T=[[0]*(W+1) for x in range(H+1)] def main(): for h in range(H): for w in range(W): T[h][w]=T[h][w-1]+S[h][w] for h in range(1,H): for w in range(W): T[h][w]=T[h][w]+T[h-1][w] m=(H-1)*(W-1) for p in range(2**(H-1)): D=[x for x in range(H-1) if p&(2**x)!=0]+[H-1] c,b=0,-1 f=False for w in range(W): u=-1 for d in D: if T[d][w]-T[u][w]-T[d][b]+T[u][b]>K: if b==w-1: f=True c,b=c+1,w-1 break u=d if f==True: break else: m=min(m,c+len(D)-1) print(m) main()
33
34
652
721
H, W, K = list(map(int, input().split())) S = [[int(x) for x in list(str(eval(input())))] for _ in range(H)] T = [[0] * (W + 1) for x in range(H + 1)] for h in range(H): for w in range(W): T[h][w] = T[h][w - 1] + S[h][w] for h in range(1, H): for w in range(W): T[h][w] = T[h][w] + T[h - 1][w] m = (H - 1) * (W - 1) for p in range(2 ** (H - 1)): D = [x for x in range(H - 1) if p & (2**x) != 0] + [H - 1] c, b = 0, -1 f = False for w in range(W): u = -1 for d in D: if T[d][w] - T[u][w] - T[d][b] + T[u][b] > K: if b == w - 1: f = True c, b = c + 1, w - 1 break u = d if f == True: break else: m = min(m, c + len(D) - 1) print(m)
H, W, K = list(map(int, input().split())) S = [[int(x) for x in list(str(eval(input())))] for _ in range(H)] T = [[0] * (W + 1) for x in range(H + 1)] def main(): for h in range(H): for w in range(W): T[h][w] = T[h][w - 1] + S[h][w] for h in range(1, H): for w in range(W): T[h][w] = T[h][w] + T[h - 1][w] m = (H - 1) * (W - 1) for p in range(2 ** (H - 1)): D = [x for x in range(H - 1) if p & (2**x) != 0] + [H - 1] c, b = 0, -1 f = False for w in range(W): u = -1 for d in D: if T[d][w] - T[u][w] - T[d][b] + T[u][b] > K: if b == w - 1: f = True c, b = c + 1, w - 1 break u = d if f == True: break else: m = min(m, c + len(D) - 1) print(m) main()
false
2.941176
[ "-for h in range(H):", "- for w in range(W):", "- T[h][w] = T[h][w - 1] + S[h][w]", "-for h in range(1, H):", "- for w in range(W):", "- T[h][w] = T[h][w] + T[h - 1][w]", "-m = (H - 1) * (W - 1)", "-for p in range(2 ** (H - 1)):", "- D = [x for x in range(H - 1) if p & (2**x) != 0] + [H - 1]", "- c, b = 0, -1", "- f = False", "- for w in range(W):", "- u = -1", "- for d in D:", "- if T[d][w] - T[u][w] - T[d][b] + T[u][b] > K:", "- if b == w - 1:", "- f = True", "- c, b = c + 1, w - 1", "+", "+", "+def main():", "+ for h in range(H):", "+ for w in range(W):", "+ T[h][w] = T[h][w - 1] + S[h][w]", "+ for h in range(1, H):", "+ for w in range(W):", "+ T[h][w] = T[h][w] + T[h - 1][w]", "+ m = (H - 1) * (W - 1)", "+ for p in range(2 ** (H - 1)):", "+ D = [x for x in range(H - 1) if p & (2**x) != 0] + [H - 1]", "+ c, b = 0, -1", "+ f = False", "+ for w in range(W):", "+ u = -1", "+ for d in D:", "+ if T[d][w] - T[u][w] - T[d][b] + T[u][b] > K:", "+ if b == w - 1:", "+ f = True", "+ c, b = c + 1, w - 1", "+ break", "+ u = d", "+ if f == True:", "- u = d", "- if f == True:", "- break", "- else:", "- m = min(m, c + len(D) - 1)", "-print(m)", "+ else:", "+ m = min(m, c + len(D) - 1)", "+ print(m)", "+", "+", "+main()" ]
false
0.048336
0.048327
1.000177
[ "s389703333", "s531725481" ]
u397953026
p02688
python
s875734547
s925695685
29
26
9,184
9,180
Accepted
Accepted
10.34
n,k = list(map(int,input().split())) count = [0]*n for i in range(k): d = int(eval(input())) a = list(map(int,input().split())) for j in range(len(a)): count[a[j]-1] += 1 print((count.count(0)))
n,k = list(map(int,input().split())) ans = [0]*n for i in range(k): d = int(eval(input())) a = list(map(int,input().split())) for j in range(len(a)): ans[a[j]-1] += 1 print((ans.count(0)))
9
8
209
201
n, k = list(map(int, input().split())) count = [0] * n for i in range(k): d = int(eval(input())) a = list(map(int, input().split())) for j in range(len(a)): count[a[j] - 1] += 1 print((count.count(0)))
n, k = list(map(int, input().split())) ans = [0] * n for i in range(k): d = int(eval(input())) a = list(map(int, input().split())) for j in range(len(a)): ans[a[j] - 1] += 1 print((ans.count(0)))
false
11.111111
[ "-count = [0] * n", "+ans = [0] * n", "- count[a[j] - 1] += 1", "-print((count.count(0)))", "+ ans[a[j] - 1] += 1", "+print((ans.count(0)))" ]
false
0.049535
0.049602
0.998651
[ "s875734547", "s925695685" ]
u072717685
p02695
python
s383977486
s520755674
815
609
21,692
21,780
Accepted
Accepted
25.28
from itertools import combinations_with_replacement def main(): n, m, q = list(map(int, input().split())) qlist = [] for _ in range(q): qlist.append(tuple(map(int, input().split()))) nums = [i for i in range(1, m + 1)] alist = tuple(combinations_with_replacement(nums, n)) r = 0 for al in alist: tr = 0 for eq in qlist: eq0 = eq[0] - 1 eq1 = eq[1] - 1 eq2 = eq[2] eq3 = eq[3] if al[eq1] - al[eq0] == eq2: tr += eq3 r = max(r, tr) print(r) if __name__ == '__main__': main()
import sys read = sys.stdin.read readlines = sys.stdin.readlines from itertools import combinations_with_replacement def main(): n, m, q = list(map(int, input().split())) abcd = [] for _ in range(q): q = tuple(map(int, input().split())) abcd.append(q) c1 = tuple(combinations_with_replacement(list(range(1,m+1)), n)) r = 0 for ce in c1: t = 0 for qe in abcd: a, b, c, d = qe a -= 1 b -= 1 if ce[b] - ce[a] == c: t += d r = max(r, t) print(r) if __name__ == '__main__': main()
26
25
640
624
from itertools import combinations_with_replacement def main(): n, m, q = list(map(int, input().split())) qlist = [] for _ in range(q): qlist.append(tuple(map(int, input().split()))) nums = [i for i in range(1, m + 1)] alist = tuple(combinations_with_replacement(nums, n)) r = 0 for al in alist: tr = 0 for eq in qlist: eq0 = eq[0] - 1 eq1 = eq[1] - 1 eq2 = eq[2] eq3 = eq[3] if al[eq1] - al[eq0] == eq2: tr += eq3 r = max(r, tr) print(r) if __name__ == "__main__": main()
import sys read = sys.stdin.read readlines = sys.stdin.readlines from itertools import combinations_with_replacement def main(): n, m, q = list(map(int, input().split())) abcd = [] for _ in range(q): q = tuple(map(int, input().split())) abcd.append(q) c1 = tuple(combinations_with_replacement(list(range(1, m + 1)), n)) r = 0 for ce in c1: t = 0 for qe in abcd: a, b, c, d = qe a -= 1 b -= 1 if ce[b] - ce[a] == c: t += d r = max(r, t) print(r) if __name__ == "__main__": main()
false
3.846154
[ "+import sys", "+", "+read = sys.stdin.read", "+readlines = sys.stdin.readlines", "- qlist = []", "+ abcd = []", "- qlist.append(tuple(map(int, input().split())))", "- nums = [i for i in range(1, m + 1)]", "- alist = tuple(combinations_with_replacement(nums, n))", "+ q = tuple(map(int, input().split()))", "+ abcd.append(q)", "+ c1 = tuple(combinations_with_replacement(list(range(1, m + 1)), n))", "- for al in alist:", "- tr = 0", "- for eq in qlist:", "- eq0 = eq[0] - 1", "- eq1 = eq[1] - 1", "- eq2 = eq[2]", "- eq3 = eq[3]", "- if al[eq1] - al[eq0] == eq2:", "- tr += eq3", "- r = max(r, tr)", "+ for ce in c1:", "+ t = 0", "+ for qe in abcd:", "+ a, b, c, d = qe", "+ a -= 1", "+ b -= 1", "+ if ce[b] - ce[a] == c:", "+ t += d", "+ r = max(r, t)" ]
false
0.068639
0.06725
1.020649
[ "s383977486", "s520755674" ]
u784022244
p02984
python
s347663416
s562936259
213
145
14,092
14,028
Accepted
Accepted
31.92
N=int(input()) #ダムに溜まった水 A=list(map(int, input().split())) """ + A[0]=B[0]//2+B[1]//2 - A[1]=B[1]//2+B[2]//2 + A[2]=B[2]//2+B[3]//2 ... + A[N-1]=B[N-1]//2+B[0]//2 #奇数番目 A[0]-A[1]+A[2]+....+A[N-1]=B[0] """ b_0=0 for i in range(N): if i%2==0: b_0+=A[i] else: b_0-=A[i] for i in range(N): if i==0: print(b_0, end=" ") b=b_0 else: b_n=(A[i-1]-b//2)*2 print(b_n, end=" ") b=b_n
N=int(eval(input())) A=list(map(int, input().split())) #ダムの水 #山ダム山ダム山ダム。。。。。 B=[0]*N A1=0 for i in range(N): if i%2==0: A1+=A[i] else: A1-=A[i] B[0]=A1 for i in range(1,N): B[i]=2*A[i-1]-B[i-1] print((*B))
31
14
451
238
N = int(input()) # ダムに溜まった水 A = list(map(int, input().split())) """ + A[0]=B[0]//2+B[1]//2 - A[1]=B[1]//2+B[2]//2 + A[2]=B[2]//2+B[3]//2 ... + A[N-1]=B[N-1]//2+B[0]//2 #奇数番目 A[0]-A[1]+A[2]+....+A[N-1]=B[0] """ b_0 = 0 for i in range(N): if i % 2 == 0: b_0 += A[i] else: b_0 -= A[i] for i in range(N): if i == 0: print(b_0, end=" ") b = b_0 else: b_n = (A[i - 1] - b // 2) * 2 print(b_n, end=" ") b = b_n
N = int(eval(input())) A = list(map(int, input().split())) # ダムの水 # 山ダム山ダム山ダム。。。。。 B = [0] * N A1 = 0 for i in range(N): if i % 2 == 0: A1 += A[i] else: A1 -= A[i] B[0] = A1 for i in range(1, N): B[i] = 2 * A[i - 1] - B[i - 1] print((*B))
false
54.83871
[ "-N = int(input())", "-# ダムに溜まった水", "-A = list(map(int, input().split()))", "-\"\"\"", "-+ A[0]=B[0]//2+B[1]//2", "-- A[1]=B[1]//2+B[2]//2", "-+ A[2]=B[2]//2+B[3]//2", "- ...", "-+ A[N-1]=B[N-1]//2+B[0]//2 #奇数番目", "-A[0]-A[1]+A[2]+....+A[N-1]=B[0]", "-\"\"\"", "-b_0 = 0", "+N = int(eval(input()))", "+A = list(map(int, input().split())) # ダムの水", "+# 山ダム山ダム山ダム。。。。。", "+B = [0] * N", "+A1 = 0", "- b_0 += A[i]", "+ A1 += A[i]", "- b_0 -= A[i]", "-for i in range(N):", "- if i == 0:", "- print(b_0, end=\" \")", "- b = b_0", "- else:", "- b_n = (A[i - 1] - b // 2) * 2", "- print(b_n, end=\" \")", "- b = b_n", "+ A1 -= A[i]", "+B[0] = A1", "+for i in range(1, N):", "+ B[i] = 2 * A[i - 1] - B[i - 1]", "+print((*B))" ]
false
0.037378
0.036399
1.026875
[ "s347663416", "s562936259" ]
u476604182
p02863
python
s596031697
s020600144
653
429
116,440
116,440
Accepted
Accepted
34.3
N, T = list(map(int, input().split())) ls = [] for i in range(N): a, b = list(map(int, input().split())) ls += [(a,b)] ls.sort(key=lambda x:x[0]) dp = [[0]*(T) for i in range(N+1)] for i in range(N): a,b = ls[i] for j in range(T-1, a-1, -1): dp[i+1][j] = max(dp[i][j], dp[i][j-a]+b) last = [0]*N last[-1] = ls[-1][1] for i in range(N-2, -1, -1): last[i] = max(last[i+1], ls[i][1]) ans = 0 for i in range(1,N+1): ans = max(ans, max(dp[i-1])+last[i-1]) print(ans)
N, T = list(map(int, input().split())) ls = [] for i in range(N): a, b = list(map(int, input().split())) ls += [(a,b)] ls.sort(key=lambda x:x[0]) t = [[0]*T for i in range(N+1)] for i in range(1,N+1): a, b = ls[i-1] for j in range(T): if j-a>=0: t[i][j] = max(t[i-1][j-a]+b,t[i-1][j]) last = [0] for i in range(N-1,-1,-1): last += [max(last[-1], ls[i][-1])] ans = 0 for i in range(1,N+1): j = N-i ans = max(ans, last[j]+t[i][-1]) print(ans)
25
20
496
471
N, T = list(map(int, input().split())) ls = [] for i in range(N): a, b = list(map(int, input().split())) ls += [(a, b)] ls.sort(key=lambda x: x[0]) dp = [[0] * (T) for i in range(N + 1)] for i in range(N): a, b = ls[i] for j in range(T - 1, a - 1, -1): dp[i + 1][j] = max(dp[i][j], dp[i][j - a] + b) last = [0] * N last[-1] = ls[-1][1] for i in range(N - 2, -1, -1): last[i] = max(last[i + 1], ls[i][1]) ans = 0 for i in range(1, N + 1): ans = max(ans, max(dp[i - 1]) + last[i - 1]) print(ans)
N, T = list(map(int, input().split())) ls = [] for i in range(N): a, b = list(map(int, input().split())) ls += [(a, b)] ls.sort(key=lambda x: x[0]) t = [[0] * T for i in range(N + 1)] for i in range(1, N + 1): a, b = ls[i - 1] for j in range(T): if j - a >= 0: t[i][j] = max(t[i - 1][j - a] + b, t[i - 1][j]) last = [0] for i in range(N - 1, -1, -1): last += [max(last[-1], ls[i][-1])] ans = 0 for i in range(1, N + 1): j = N - i ans = max(ans, last[j] + t[i][-1]) print(ans)
false
20
[ "-dp = [[0] * (T) for i in range(N + 1)]", "-for i in range(N):", "- a, b = ls[i]", "- for j in range(T - 1, a - 1, -1):", "- dp[i + 1][j] = max(dp[i][j], dp[i][j - a] + b)", "-last = [0] * N", "-last[-1] = ls[-1][1]", "-for i in range(N - 2, -1, -1):", "- last[i] = max(last[i + 1], ls[i][1])", "+t = [[0] * T for i in range(N + 1)]", "+for i in range(1, N + 1):", "+ a, b = ls[i - 1]", "+ for j in range(T):", "+ if j - a >= 0:", "+ t[i][j] = max(t[i - 1][j - a] + b, t[i - 1][j])", "+last = [0]", "+for i in range(N - 1, -1, -1):", "+ last += [max(last[-1], ls[i][-1])]", "- ans = max(ans, max(dp[i - 1]) + last[i - 1])", "+ j = N - i", "+ ans = max(ans, last[j] + t[i][-1])" ]
false
0.042923
0.041089
1.044635
[ "s596031697", "s020600144" ]
u737758066
p02684
python
s521954741
s957045097
236
157
32,836
32,384
Accepted
Accepted
33.47
n, k = list(map(int, input().split())) a = list(map(int, input().split())) pos = 0 visit = [0]*n move = [] roop = [] while visit[pos] != 2: if visit[pos] == 0: move.append(pos) else: roop.append(pos) visit[pos] += 1 pos = a[pos] - 1 if len(move) > k: print((move[k]+1)) else: print((roop[(k-(len(move)-len(roop))) % len(roop)]+1))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) num = 1 li = [1] flag = [True]*n flag[0] = False for i in range(k): num = a[num-1] if flag[num-1]: li.append(num) flag[num-1] = False else: break d = li.index(num) ans = (k-d) % (len(li)-d)+d print((li[ans]))
18
19
379
333
n, k = list(map(int, input().split())) a = list(map(int, input().split())) pos = 0 visit = [0] * n move = [] roop = [] while visit[pos] != 2: if visit[pos] == 0: move.append(pos) else: roop.append(pos) visit[pos] += 1 pos = a[pos] - 1 if len(move) > k: print((move[k] + 1)) else: print((roop[(k - (len(move) - len(roop))) % len(roop)] + 1))
n, k = list(map(int, input().split())) a = list(map(int, input().split())) num = 1 li = [1] flag = [True] * n flag[0] = False for i in range(k): num = a[num - 1] if flag[num - 1]: li.append(num) flag[num - 1] = False else: break d = li.index(num) ans = (k - d) % (len(li) - d) + d print((li[ans]))
false
5.263158
[ "-pos = 0", "-visit = [0] * n", "-move = []", "-roop = []", "-while visit[pos] != 2:", "- if visit[pos] == 0:", "- move.append(pos)", "+num = 1", "+li = [1]", "+flag = [True] * n", "+flag[0] = False", "+for i in range(k):", "+ num = a[num - 1]", "+ if flag[num - 1]:", "+ li.append(num)", "+ flag[num - 1] = False", "- roop.append(pos)", "- visit[pos] += 1", "- pos = a[pos] - 1", "-if len(move) > k:", "- print((move[k] + 1))", "-else:", "- print((roop[(k - (len(move) - len(roop))) % len(roop)] + 1))", "+ break", "+d = li.index(num)", "+ans = (k - d) % (len(li) - d) + d", "+print((li[ans]))" ]
false
0.038741
0.084106
0.460626
[ "s521954741", "s957045097" ]
u334712262
p02579
python
s639663326
s382974667
1,676
1,165
270,500
216,040
Accepted
Accepted
30.49
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(H, W, C, D, S): C = (C[0]-1, C[1]-1) D = (D[0]-1, D[1]-1) q = deque() q.append((0, C)) memo = {} while q: c, (x, y) = q.popleft() if (x, y) in memo: continue memo[(x, y)] = c for nx, ny in [(x, y-1), (x, y+1), (x-1, y), (x+1, y)]: if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '.': q.appendleft((c, (nx, ny))) for nx in range(x-2, x+3): for ny in range(y-2, y+3): if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '.': q.append((c+1, (nx, ny))) return -1 if tuple(D) not in memo else memo[D] def main(): H, W = read_int_n() C = read_int_n() D = read_int_n() S = [read_str() for _ in range(H)] print(slv(H, W, C, D, S)) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62-1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, 'sec') return ret return wrap @mt def slv(H, W, C, D, S): C = (C[0]-1, C[1]-1) D = (D[0]-1, D[1]-1) q = deque() q.append((0, C)) memo = {} T = 10**6 while q: c, (x, y) = q.popleft() if (x*T + y) in memo: continue memo[x*T + y] = c for nx, ny in [(x, y-1), (x, y+1), (x-1, y), (x+1, y)]: if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '.': q.appendleft((c, (nx, ny))) for nx in range(x-2, x+3): for ny in range(y-2, y+3): if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '.': q.append((c+1, (nx, ny))) return -1 if (D[0]*T + D[1]) not in memo else memo[D[0]*T + D[1]] def main(): H, W = read_int_n() C = read_int_n() D = read_int_n() S = [read_str() for _ in range(H)] print(slv(H, W, C, D, S)) if __name__ == '__main__': main()
98
98
2,099
2,135
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62 - 1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap @mt def slv(H, W, C, D, S): C = (C[0] - 1, C[1] - 1) D = (D[0] - 1, D[1] - 1) q = deque() q.append((0, C)) memo = {} while q: c, (x, y) = q.popleft() if (x, y) in memo: continue memo[(x, y)] = c for nx, ny in [(x, y - 1), (x, y + 1), (x - 1, y), (x + 1, y)]: if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == ".": q.appendleft((c, (nx, ny))) for nx in range(x - 2, x + 3): for ny in range(y - 2, y + 3): if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == ".": q.append((c + 1, (nx, ny))) return -1 if tuple(D) not in memo else memo[D] def main(): H, W = read_int_n() C = read_int_n() D = read_int_n() S = [read_str() for _ in range(H)] print(slv(H, W, C, D, S)) if __name__ == "__main__": main()
# -*- coding: utf-8 -*- import bisect import heapq import math import random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub import sys # sys.setrecursionlimit(10**6) # buff_readline = sys.stdin.buffer.readline buff_readline = sys.stdin.readline readline = sys.stdin.readline INF = 2**62 - 1 def read_int(): return int(buff_readline()) def read_int_n(): return list(map(int, buff_readline().split())) def read_float(): return float(buff_readline()) def read_float_n(): return list(map(float, buff_readline().split())) def read_str(): return readline().strip() def read_str_n(): return readline().strip().split() def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap @mt def slv(H, W, C, D, S): C = (C[0] - 1, C[1] - 1) D = (D[0] - 1, D[1] - 1) q = deque() q.append((0, C)) memo = {} T = 10**6 while q: c, (x, y) = q.popleft() if (x * T + y) in memo: continue memo[x * T + y] = c for nx, ny in [(x, y - 1), (x, y + 1), (x - 1, y), (x + 1, y)]: if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == ".": q.appendleft((c, (nx, ny))) for nx in range(x - 2, x + 3): for ny in range(y - 2, y + 3): if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == ".": q.append((c + 1, (nx, ny))) return -1 if (D[0] * T + D[1]) not in memo else memo[D[0] * T + D[1]] def main(): H, W = read_int_n() C = read_int_n() D = read_int_n() S = [read_str() for _ in range(H)] print(slv(H, W, C, D, S)) if __name__ == "__main__": main()
false
0
[ "+ T = 10**6", "- if (x, y) in memo:", "+ if (x * T + y) in memo:", "- memo[(x, y)] = c", "+ memo[x * T + y] = c", "- return -1 if tuple(D) not in memo else memo[D]", "+ return -1 if (D[0] * T + D[1]) not in memo else memo[D[0] * T + D[1]]" ]
false
0.03632
0.035369
1.026903
[ "s639663326", "s382974667" ]
u263830634
p03862
python
s902885021
s099522527
147
124
14,252
14,052
Accepted
Accepted
15.65
N, x = list(map(int, input().split())) a = list(map(int, input().split())) count = 0 for i in range(N-1): if a[i] + a[i+1] > x: if a[i+1] >= a[i] + a[i+1] - x: count += a[i] + a[i+1] - x a[i+1] -= a[i] + a[i+1] - x else: count += a[i] + a[i+1] - x a[i+1] = 0 a[i] = x print (count)
N, x = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 for i in range(1, N): a = A[i - 1] b = A[i] if a + b <= x: continue over = (a + b) - x ans += over A[i] = max(0, b - over) print (ans)
15
15
372
261
N, x = list(map(int, input().split())) a = list(map(int, input().split())) count = 0 for i in range(N - 1): if a[i] + a[i + 1] > x: if a[i + 1] >= a[i] + a[i + 1] - x: count += a[i] + a[i + 1] - x a[i + 1] -= a[i] + a[i + 1] - x else: count += a[i] + a[i + 1] - x a[i + 1] = 0 a[i] = x print(count)
N, x = list(map(int, input().split())) A = list(map(int, input().split())) ans = 0 for i in range(1, N): a = A[i - 1] b = A[i] if a + b <= x: continue over = (a + b) - x ans += over A[i] = max(0, b - over) print(ans)
false
0
[ "-a = list(map(int, input().split()))", "-count = 0", "-for i in range(N - 1):", "- if a[i] + a[i + 1] > x:", "- if a[i + 1] >= a[i] + a[i + 1] - x:", "- count += a[i] + a[i + 1] - x", "- a[i + 1] -= a[i] + a[i + 1] - x", "- else:", "- count += a[i] + a[i + 1] - x", "- a[i + 1] = 0", "- a[i] = x", "-print(count)", "+A = list(map(int, input().split()))", "+ans = 0", "+for i in range(1, N):", "+ a = A[i - 1]", "+ b = A[i]", "+ if a + b <= x:", "+ continue", "+ over = (a + b) - x", "+ ans += over", "+ A[i] = max(0, b - over)", "+print(ans)" ]
false
0.183969
0.053779
3.420826
[ "s902885021", "s099522527" ]
u327466606
p03460
python
s946538969
s555762203
1,673
1,451
176,652
78,820
Accepted
Accepted
13.27
N,K = list(map(int,input().split())) import numpy as np blacks = np.zeros((2*K,2*K), dtype=int) offset = 0 for _ in range(N): x,y,c = input().split() x,y = int(x),int(y) x %= 2*K y %= 2*K if c == 'B': blacks[x,y] += 1 else: blacks[x,y] -= 1 offset += 1 m = np.zeros((3*K,2*K),dtype=int) m[:2*K,:] = blacks m[2*K:,:] = blacks[:K,:] np.cumsum(m,axis=0, out=m) m = m[K:,:] - m[:2*K,:] n = np.zeros((2*K,3*K),dtype=int) n[:,:2*K] = m n[:,2*K:] = m[:,:K] np.cumsum(n,axis=1, out=n) n = n[:,K:] - n[:,:2*K] m = np.zeros((3*K,3*K),dtype=int) m[:2*K,:2*K] = n m[2*K:,:2*K] = n[:K,:] m[:2*K,2*K:] = n[:,:K] m[2*K:,2*K:] = n[:K,:K] m = m[:2*K,:2*K] + m[K:,K:] m = m.max() print((m+offset))
N,K = list(map(int,input().split())) import numpy as np m = np.zeros((3*K,3*K), dtype=np.int32) offset = 0 for _ in range(N): x,y,c = input().split() x,y = int(x),int(y) x %= 2*K y %= 2*K if c == 'B': m[x,y] += 1 else: m[x,y] -= 1 offset += 1 K2 = 2*K m[K2:,:K2] = m[:K,:K2] np.cumsum(m[:,:K2],axis=0, out=m[:,:K2]) m[:K2,:K2] = m[K:,:K2] - m[:K2,:K2] m[:K2,K2:] = m[:K2,:K] np.cumsum(m[:K2,:],axis=1, out=m[:K2,:]) m[:K2,:K2] = m[:K2,K:] - m[:K2,:K2] m = m[:K2,:K2] m += np.roll(np.roll(m,K,axis=0),K,axis=1) print((m.max()+offset))
43
31
748
586
N, K = list(map(int, input().split())) import numpy as np blacks = np.zeros((2 * K, 2 * K), dtype=int) offset = 0 for _ in range(N): x, y, c = input().split() x, y = int(x), int(y) x %= 2 * K y %= 2 * K if c == "B": blacks[x, y] += 1 else: blacks[x, y] -= 1 offset += 1 m = np.zeros((3 * K, 2 * K), dtype=int) m[: 2 * K, :] = blacks m[2 * K :, :] = blacks[:K, :] np.cumsum(m, axis=0, out=m) m = m[K:, :] - m[: 2 * K, :] n = np.zeros((2 * K, 3 * K), dtype=int) n[:, : 2 * K] = m n[:, 2 * K :] = m[:, :K] np.cumsum(n, axis=1, out=n) n = n[:, K:] - n[:, : 2 * K] m = np.zeros((3 * K, 3 * K), dtype=int) m[: 2 * K, : 2 * K] = n m[2 * K :, : 2 * K] = n[:K, :] m[: 2 * K, 2 * K :] = n[:, :K] m[2 * K :, 2 * K :] = n[:K, :K] m = m[: 2 * K, : 2 * K] + m[K:, K:] m = m.max() print((m + offset))
N, K = list(map(int, input().split())) import numpy as np m = np.zeros((3 * K, 3 * K), dtype=np.int32) offset = 0 for _ in range(N): x, y, c = input().split() x, y = int(x), int(y) x %= 2 * K y %= 2 * K if c == "B": m[x, y] += 1 else: m[x, y] -= 1 offset += 1 K2 = 2 * K m[K2:, :K2] = m[:K, :K2] np.cumsum(m[:, :K2], axis=0, out=m[:, :K2]) m[:K2, :K2] = m[K:, :K2] - m[:K2, :K2] m[:K2, K2:] = m[:K2, :K] np.cumsum(m[:K2, :], axis=1, out=m[:K2, :]) m[:K2, :K2] = m[:K2, K:] - m[:K2, :K2] m = m[:K2, :K2] m += np.roll(np.roll(m, K, axis=0), K, axis=1) print((m.max() + offset))
false
27.906977
[ "-blacks = np.zeros((2 * K, 2 * K), dtype=int)", "+m = np.zeros((3 * K, 3 * K), dtype=np.int32)", "- blacks[x, y] += 1", "+ m[x, y] += 1", "- blacks[x, y] -= 1", "+ m[x, y] -= 1", "-m = np.zeros((3 * K, 2 * K), dtype=int)", "-m[: 2 * K, :] = blacks", "-m[2 * K :, :] = blacks[:K, :]", "-np.cumsum(m, axis=0, out=m)", "-m = m[K:, :] - m[: 2 * K, :]", "-n = np.zeros((2 * K, 3 * K), dtype=int)", "-n[:, : 2 * K] = m", "-n[:, 2 * K :] = m[:, :K]", "-np.cumsum(n, axis=1, out=n)", "-n = n[:, K:] - n[:, : 2 * K]", "-m = np.zeros((3 * K, 3 * K), dtype=int)", "-m[: 2 * K, : 2 * K] = n", "-m[2 * K :, : 2 * K] = n[:K, :]", "-m[: 2 * K, 2 * K :] = n[:, :K]", "-m[2 * K :, 2 * K :] = n[:K, :K]", "-m = m[: 2 * K, : 2 * K] + m[K:, K:]", "-m = m.max()", "-print((m + offset))", "+K2 = 2 * K", "+m[K2:, :K2] = m[:K, :K2]", "+np.cumsum(m[:, :K2], axis=0, out=m[:, :K2])", "+m[:K2, :K2] = m[K:, :K2] - m[:K2, :K2]", "+m[:K2, K2:] = m[:K2, :K]", "+np.cumsum(m[:K2, :], axis=1, out=m[:K2, :])", "+m[:K2, :K2] = m[:K2, K:] - m[:K2, :K2]", "+m = m[:K2, :K2]", "+m += np.roll(np.roll(m, K, axis=0), K, axis=1)", "+print((m.max() + offset))" ]
false
0.204104
0.201327
1.013796
[ "s946538969", "s555762203" ]
u312025627
p02983
python
s762593477
s872363096
950
193
3,060
38,896
Accepted
Accepted
79.68
l, r = (int(i) for i in input().split()) ans = float('inf') for i in range(l,min(l+2019,r)): for j in range(i+1,min(i+1+2019,r+1)): val = i*j % 2019 if val < ans: ans = val print(ans)
def main(): L, R = (int(i) for i in input().split()) MOD = 2019 R = min(L + 2020, R) ans = 2020 for i in range(L, R): for j in range(i+1, R+1): # print(i, j) ans = min(ans, (i*j) % MOD) print(ans) if __name__ == '__main__': main()
8
14
222
306
l, r = (int(i) for i in input().split()) ans = float("inf") for i in range(l, min(l + 2019, r)): for j in range(i + 1, min(i + 1 + 2019, r + 1)): val = i * j % 2019 if val < ans: ans = val print(ans)
def main(): L, R = (int(i) for i in input().split()) MOD = 2019 R = min(L + 2020, R) ans = 2020 for i in range(L, R): for j in range(i + 1, R + 1): # print(i, j) ans = min(ans, (i * j) % MOD) print(ans) if __name__ == "__main__": main()
false
42.857143
[ "-l, r = (int(i) for i in input().split())", "-ans = float(\"inf\")", "-for i in range(l, min(l + 2019, r)):", "- for j in range(i + 1, min(i + 1 + 2019, r + 1)):", "- val = i * j % 2019", "- if val < ans:", "- ans = val", "-print(ans)", "+def main():", "+ L, R = (int(i) for i in input().split())", "+ MOD = 2019", "+ R = min(L + 2020, R)", "+ ans = 2020", "+ for i in range(L, R):", "+ for j in range(i + 1, R + 1):", "+ # print(i, j)", "+ ans = min(ans, (i * j) % MOD)", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.058419
0.056079
1.041744
[ "s762593477", "s872363096" ]
u201234972
p03044
python
s698416740
s375697253
935
396
98,464
44,924
Accepted
Accepted
57.65
from collections import defaultdict, deque N = int( eval(input())) d = defaultdict( int) E = [ [] for _ in range(N)] for _ in range(N-1): u, v, w = list(map( int, input().split())) u = u-1 v = v-1 E[u].append(v) E[v].append(u) d[(u,v)] = w%2 d[(v,u)] = w%2 V = [-1]*N V[0] = 0 q = deque([0]) while q: v = q.popleft() l = V[v] for t in E[v]: if V[t] == -1: V[t] = (l+d[(v,t)])%2 q.append(t) for i in range(N): print((V[i]))
import sys input = sys.stdin.readline from collections import deque def main(): N = int( eval(input())) E = [[] for _ in range(N)] for _ in range(N-1): u, v, w = list(map( int, input().split())) u -= 1 v -= 1 E[u].append((v,w)) E[v].append((u,w)) V = [-1]*N V[0] = 0 d = deque([(0,0)]) while d: u, l = d.popleft() for v,w in E[u]: if V[v] == -1: V[v] = (l+w)%2 d.append((v, (l+w)%2)) print(("\n".join( map( str, V)))) if __name__ == '__main__': main()
24
26
508
609
from collections import defaultdict, deque N = int(eval(input())) d = defaultdict(int) E = [[] for _ in range(N)] for _ in range(N - 1): u, v, w = list(map(int, input().split())) u = u - 1 v = v - 1 E[u].append(v) E[v].append(u) d[(u, v)] = w % 2 d[(v, u)] = w % 2 V = [-1] * N V[0] = 0 q = deque([0]) while q: v = q.popleft() l = V[v] for t in E[v]: if V[t] == -1: V[t] = (l + d[(v, t)]) % 2 q.append(t) for i in range(N): print((V[i]))
import sys input = sys.stdin.readline from collections import deque def main(): N = int(eval(input())) E = [[] for _ in range(N)] for _ in range(N - 1): u, v, w = list(map(int, input().split())) u -= 1 v -= 1 E[u].append((v, w)) E[v].append((u, w)) V = [-1] * N V[0] = 0 d = deque([(0, 0)]) while d: u, l = d.popleft() for v, w in E[u]: if V[v] == -1: V[v] = (l + w) % 2 d.append((v, (l + w) % 2)) print(("\n".join(map(str, V)))) if __name__ == "__main__": main()
false
7.692308
[ "-from collections import defaultdict, deque", "+import sys", "-N = int(eval(input()))", "-d = defaultdict(int)", "-E = [[] for _ in range(N)]", "-for _ in range(N - 1):", "- u, v, w = list(map(int, input().split()))", "- u = u - 1", "- v = v - 1", "- E[u].append(v)", "- E[v].append(u)", "- d[(u, v)] = w % 2", "- d[(v, u)] = w % 2", "-V = [-1] * N", "-V[0] = 0", "-q = deque([0])", "-while q:", "- v = q.popleft()", "- l = V[v]", "- for t in E[v]:", "- if V[t] == -1:", "- V[t] = (l + d[(v, t)]) % 2", "- q.append(t)", "-for i in range(N):", "- print((V[i]))", "+input = sys.stdin.readline", "+from collections import deque", "+", "+", "+def main():", "+ N = int(eval(input()))", "+ E = [[] for _ in range(N)]", "+ for _ in range(N - 1):", "+ u, v, w = list(map(int, input().split()))", "+ u -= 1", "+ v -= 1", "+ E[u].append((v, w))", "+ E[v].append((u, w))", "+ V = [-1] * N", "+ V[0] = 0", "+ d = deque([(0, 0)])", "+ while d:", "+ u, l = d.popleft()", "+ for v, w in E[u]:", "+ if V[v] == -1:", "+ V[v] = (l + w) % 2", "+ d.append((v, (l + w) % 2))", "+ print((\"\\n\".join(map(str, V))))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.066558
0.069066
0.963681
[ "s698416740", "s375697253" ]
u544587633
p02660
python
s908866268
s070748245
189
73
69,852
68,276
Accepted
Accepted
61.38
#!/usr/bin/env python3 import sys from functools import reduce import math def is_prime(n): if n % 2 == 0 and n > 2: return False for i in range(3, int(math.sqrt(n)) + 1, 2): if n % i == 0: return False return True def sieve(n): n=int(n) # Create a boolean array "prime[0..n]" and initialize # all entries it as true. A value in prime[i] will # finally be false if i is Not a prime, else true. prime = [True for i in range(n + 1)] p = 2 while (p * p <= n): # If prime[p] is not changed, then it is a prime if (prime[p] == True): # Update all multiples of p for i in range(p * 2, n + 1, p): prime[i] = False p += 1 prime[0]= False prime[1]= False return [i for i, p in enumerate(prime) if p] def inthroot(x,n): "calculate floor(x**(1/n))" return math.floor(x**(1/n)) def is_a_power(n): "return (a,b) if n=a**b otherwise throw ValueError" for b in sieve( math.log2(n) +1 ): if b == 0: raise ValueError a = inthroot(n,b) if a**b == n: return a,b raise ValueError def smooth_factorization(n): "return (p,e) where p is prime and n = p**e if such value exists, otherwise throw ValueError" e=1 p=n while True: try: p,n = is_a_power(p) e = e*n except ValueError: break if is_prime(p): return p,e def factors(n): return set( reduce( list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0), ) ) def solve(N: int): count = 0 picked_z = set([]) while True: zs = list(factors(N)) zs.remove(1) for _ in range(len(zs)): z = min(zs) i = zs.index(z) is_prime_power = smooth_factorization(z) if is_prime_power and z not in picked_z: picked_z.add(z) N = N / z count += 1 del zs[i] break del zs[i] if len(zs) == 0: break print(count) return # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int solve(N) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys from functools import reduce import math from collections import defaultdict from math import sqrt def is_prime(n): for i in range(2, int(sqrt(n))): if n % i == 0: return False return True def prime_factors(n): primes = defaultdict(int) i = 2 mx = sqrt(n) while n != 1: if n % i == 0: n = n // i primes[i] += 1 elif i >= mx: if len(primes) == 0: primes[i] += 1 elif is_prime(n): primes[i] += 1 break else: i += 1 return primes def solve_n(x): return (-1 + sqrt(1 + 4 * 2* x)) / 2 def solve(N: int): fs = prime_factors(N) count = 0 for key, value in list(fs.items()): val = solve_n(value) count += math.floor(val) print(count) return # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int solve(N) if __name__ == "__main__": main()
119
64
2,835
1,377
#!/usr/bin/env python3 import sys from functools import reduce import math def is_prime(n): if n % 2 == 0 and n > 2: return False for i in range(3, int(math.sqrt(n)) + 1, 2): if n % i == 0: return False return True def sieve(n): n = int(n) # Create a boolean array "prime[0..n]" and initialize # all entries it as true. A value in prime[i] will # finally be false if i is Not a prime, else true. prime = [True for i in range(n + 1)] p = 2 while p * p <= n: # If prime[p] is not changed, then it is a prime if prime[p] == True: # Update all multiples of p for i in range(p * 2, n + 1, p): prime[i] = False p += 1 prime[0] = False prime[1] = False return [i for i, p in enumerate(prime) if p] def inthroot(x, n): "calculate floor(x**(1/n))" return math.floor(x ** (1 / n)) def is_a_power(n): "return (a,b) if n=a**b otherwise throw ValueError" for b in sieve(math.log2(n) + 1): if b == 0: raise ValueError a = inthroot(n, b) if a**b == n: return a, b raise ValueError def smooth_factorization(n): "return (p,e) where p is prime and n = p**e if such value exists, otherwise throw ValueError" e = 1 p = n while True: try: p, n = is_a_power(p) e = e * n except ValueError: break if is_prime(p): return p, e def factors(n): return set( reduce( list.__add__, ([i, n // i] for i in range(1, int(n**0.5) + 1) if n % i == 0), ) ) def solve(N: int): count = 0 picked_z = set([]) while True: zs = list(factors(N)) zs.remove(1) for _ in range(len(zs)): z = min(zs) i = zs.index(z) is_prime_power = smooth_factorization(z) if is_prime_power and z not in picked_z: picked_z.add(z) N = N / z count += 1 del zs[i] break del zs[i] if len(zs) == 0: break print(count) return # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int solve(N) if __name__ == "__main__": main()
#!/usr/bin/env python3 import sys from functools import reduce import math from collections import defaultdict from math import sqrt def is_prime(n): for i in range(2, int(sqrt(n))): if n % i == 0: return False return True def prime_factors(n): primes = defaultdict(int) i = 2 mx = sqrt(n) while n != 1: if n % i == 0: n = n // i primes[i] += 1 elif i >= mx: if len(primes) == 0: primes[i] += 1 elif is_prime(n): primes[i] += 1 break else: i += 1 return primes def solve_n(x): return (-1 + sqrt(1 + 4 * 2 * x)) / 2 def solve(N: int): fs = prime_factors(N) count = 0 for key, value in list(fs.items()): val = solve_n(value) count += math.floor(val) print(count) return # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int solve(N) if __name__ == "__main__": main()
false
46.218487
[ "+from collections import defaultdict", "+from math import sqrt", "- if n % 2 == 0 and n > 2:", "- return False", "- for i in range(3, int(math.sqrt(n)) + 1, 2):", "+ for i in range(2, int(sqrt(n))):", "-def sieve(n):", "- n = int(n)", "- # Create a boolean array \"prime[0..n]\" and initialize", "- # all entries it as true. A value in prime[i] will", "- # finally be false if i is Not a prime, else true.", "- prime = [True for i in range(n + 1)]", "- p = 2", "- while p * p <= n:", "- # If prime[p] is not changed, then it is a prime", "- if prime[p] == True:", "- # Update all multiples of p", "- for i in range(p * 2, n + 1, p):", "- prime[i] = False", "- p += 1", "- prime[0] = False", "- prime[1] = False", "- return [i for i, p in enumerate(prime) if p]", "+def prime_factors(n):", "+ primes = defaultdict(int)", "+ i = 2", "+ mx = sqrt(n)", "+ while n != 1:", "+ if n % i == 0:", "+ n = n // i", "+ primes[i] += 1", "+ elif i >= mx:", "+ if len(primes) == 0:", "+ primes[i] += 1", "+ elif is_prime(n):", "+ primes[i] += 1", "+ break", "+ else:", "+ i += 1", "+ return primes", "-def inthroot(x, n):", "- \"calculate floor(x**(1/n))\"", "- return math.floor(x ** (1 / n))", "-", "-", "-def is_a_power(n):", "- \"return (a,b) if n=a**b otherwise throw ValueError\"", "- for b in sieve(math.log2(n) + 1):", "- if b == 0:", "- raise ValueError", "- a = inthroot(n, b)", "- if a**b == n:", "- return a, b", "- raise ValueError", "-", "-", "-def smooth_factorization(n):", "- \"return (p,e) where p is prime and n = p**e if such value exists, otherwise throw ValueError\"", "- e = 1", "- p = n", "- while True:", "- try:", "- p, n = is_a_power(p)", "- e = e * n", "- except ValueError:", "- break", "- if is_prime(p):", "- return p, e", "-", "-", "-def factors(n):", "- return set(", "- reduce(", "- list.__add__,", "- ([i, n // i] for i in range(1, int(n**0.5) + 1) if n % i == 0),", "- )", "- )", "+def solve_n(x):", "+ return (-1 + sqrt(1 + 4 * 2 * x)) / 2", "+ fs = prime_factors(N)", "- picked_z = set([])", "- while True:", "- zs = list(factors(N))", "- zs.remove(1)", "- for _ in range(len(zs)):", "- z = min(zs)", "- i = zs.index(z)", "- is_prime_power = smooth_factorization(z)", "- if is_prime_power and z not in picked_z:", "- picked_z.add(z)", "- N = N / z", "- count += 1", "- del zs[i]", "- break", "- del zs[i]", "- if len(zs) == 0:", "- break", "+ for key, value in list(fs.items()):", "+ val = solve_n(value)", "+ count += math.floor(val)" ]
false
0.258486
0.061977
4.170663
[ "s908866268", "s070748245" ]
u577170763
p02862
python
s981688325
s502660577
1,400
875
3,064
92,248
Accepted
Accepted
37.5
class Solution: def solve(self, x: int, y: int) -> int: if (2*x - y) % 3 != 0 or (-x + 2*y) % 3 != 0: return 0 m = (2*x - y) // 3 n = (-x + 2*y) // 3 if m < 0 or n < 0: return 0 # calculate {m+n}C{n} def egcd(a, b): if a == 0: return b, 0, 1 else: g, y, x = egcd(b % a, a) return g, x - (b // a) * y, y def modinv(a, m): g, x, y = egcd(a, m) if g != 1: raise Exception('modular inverse does not exist') else: return x % m def convination(n: int, r: int, mod: int = 10**9+7) -> int: r = min(r, n-r) res = 1 for i in range(r): res = res * (n-i) * modinv(i+1, mod) % mod return res return convination(n+m, m) if __name__ == '__main__': # standard input x, y = list(map(int, input().split())) # solve solution = Solution() print((solution.solve(x, y)))
class MathUtil: # calculate {m+n}C{n} def egcd(self, a: int, b: int): if a == 0: return b, 0, 1 else: g, y, x = self.egcd(b % a, a) return g, x - (b // a) * y, y def modinv(self, a: int, m: int): g, x, y = self.egcd(a, m) if g != 1: raise Exception('modular inverse does not exist') else: return x % m def combination(self, n: int, r: int, mod: int = 10**9+7) -> int: r = min(r, n-r) res = 1 for i in range(r): res = res * (n-i) * self.modinv(i+1, mod) % mod return res x, y = list(map(int, input().split())) m = - x + 2*y n = 2*x - y if m % 3 != 0 or n % 3 != 0 or m < 0 or n < 0: print((0)) else: m //= 3 n //= 3 print((MathUtil().combination(m+n, n)))
45
37
1,120
865
class Solution: def solve(self, x: int, y: int) -> int: if (2 * x - y) % 3 != 0 or (-x + 2 * y) % 3 != 0: return 0 m = (2 * x - y) // 3 n = (-x + 2 * y) // 3 if m < 0 or n < 0: return 0 # calculate {m+n}C{n} def egcd(a, b): if a == 0: return b, 0, 1 else: g, y, x = egcd(b % a, a) return g, x - (b // a) * y, y def modinv(a, m): g, x, y = egcd(a, m) if g != 1: raise Exception("modular inverse does not exist") else: return x % m def convination(n: int, r: int, mod: int = 10**9 + 7) -> int: r = min(r, n - r) res = 1 for i in range(r): res = res * (n - i) * modinv(i + 1, mod) % mod return res return convination(n + m, m) if __name__ == "__main__": # standard input x, y = list(map(int, input().split())) # solve solution = Solution() print((solution.solve(x, y)))
class MathUtil: # calculate {m+n}C{n} def egcd(self, a: int, b: int): if a == 0: return b, 0, 1 else: g, y, x = self.egcd(b % a, a) return g, x - (b // a) * y, y def modinv(self, a: int, m: int): g, x, y = self.egcd(a, m) if g != 1: raise Exception("modular inverse does not exist") else: return x % m def combination(self, n: int, r: int, mod: int = 10**9 + 7) -> int: r = min(r, n - r) res = 1 for i in range(r): res = res * (n - i) * self.modinv(i + 1, mod) % mod return res x, y = list(map(int, input().split())) m = -x + 2 * y n = 2 * x - y if m % 3 != 0 or n % 3 != 0 or m < 0 or n < 0: print((0)) else: m //= 3 n //= 3 print((MathUtil().combination(m + n, n)))
false
17.777778
[ "-class Solution:", "- def solve(self, x: int, y: int) -> int:", "- if (2 * x - y) % 3 != 0 or (-x + 2 * y) % 3 != 0:", "- return 0", "- m = (2 * x - y) // 3", "- n = (-x + 2 * y) // 3", "- if m < 0 or n < 0:", "- return 0", "- # calculate {m+n}C{n}", "- def egcd(a, b):", "- if a == 0:", "- return b, 0, 1", "- else:", "- g, y, x = egcd(b % a, a)", "- return g, x - (b // a) * y, y", "+class MathUtil:", "+ # calculate {m+n}C{n}", "+ def egcd(self, a: int, b: int):", "+ if a == 0:", "+ return b, 0, 1", "+ else:", "+ g, y, x = self.egcd(b % a, a)", "+ return g, x - (b // a) * y, y", "- def modinv(a, m):", "- g, x, y = egcd(a, m)", "- if g != 1:", "- raise Exception(\"modular inverse does not exist\")", "- else:", "- return x % m", "+ def modinv(self, a: int, m: int):", "+ g, x, y = self.egcd(a, m)", "+ if g != 1:", "+ raise Exception(\"modular inverse does not exist\")", "+ else:", "+ return x % m", "- def convination(n: int, r: int, mod: int = 10**9 + 7) -> int:", "- r = min(r, n - r)", "- res = 1", "- for i in range(r):", "- res = res * (n - i) * modinv(i + 1, mod) % mod", "- return res", "-", "- return convination(n + m, m)", "+ def combination(self, n: int, r: int, mod: int = 10**9 + 7) -> int:", "+ r = min(r, n - r)", "+ res = 1", "+ for i in range(r):", "+ res = res * (n - i) * self.modinv(i + 1, mod) % mod", "+ return res", "-if __name__ == \"__main__\":", "- # standard input", "- x, y = list(map(int, input().split()))", "- # solve", "- solution = Solution()", "- print((solution.solve(x, y)))", "+x, y = list(map(int, input().split()))", "+m = -x + 2 * y", "+n = 2 * x - y", "+if m % 3 != 0 or n % 3 != 0 or m < 0 or n < 0:", "+ print((0))", "+else:", "+ m //= 3", "+ n //= 3", "+ print((MathUtil().combination(m + n, n)))" ]
false
0.300615
0.28207
1.065744
[ "s981688325", "s502660577" ]
u077291787
p03330
python
s120577952
s735776901
125
86
5,356
5,356
Accepted
Accepted
31.2
# ABC099D - Good Grid import sys input = sys.stdin.readline from collections import defaultdict from itertools import product def main(): N, C = list(map(int, input().split())) D = [0] + list([0] + list(map(int, input().split())) for _ in range(C)) grid = tuple(tuple(map(int, input().split())) for _ in range(N)) cost = {i: defaultdict(int) for i in range(3)} for i, g in enumerate(grid): for j, x in enumerate(g): cost[(i + j) % 3][x] += 1 dist = [[] for _ in range(3)] for i, tgt in product(list(range(3)), list(range(1, C + 1))): cur = sum(D[src][tgt] * cnt for src, cnt in list(cost[i].items())) dist[i].append(cur) ans = 1 << 60 for i, j in product(list(range(C)), repeat=2): if i == j: continue cur = dist[0][i] + dist[1][j] cur += min(x for k, x in enumerate(dist[2]) if k not in (i, j)) ans = min(ans, cur) print(ans) if __name__ == "__main__": main()
# ABC099D - Good Grid import sys input = sys.stdin.readline from collections import Counter from itertools import product def main(): N, C = list(map(int, input().split())) D = [0] + list([0] + list(map(int, input().split())) for _ in range(C)) grid = tuple(tuple(map(int, input().split())) for _ in range(N)) cost = [Counter() for _ in range(3)] for i, g in enumerate(grid): # classify each cell by mod3 for j in range(3): cost[(i + j) % 3].update(g[j::3]) dist = [[] for _ in range(3)] # compute the actual cost to change color for i, tgt in product(list(range(3)), list(range(1, C + 1))): cur = sum(D[src][tgt] * cnt for src, cnt in list(cost[i].items())) dist[i].append(cur) ans = 1 << 60 # fix two colors and compute the minimum cost for i, j in product(list(range(C)), repeat=2): if i == j: continue cur = dist[0][i] + dist[1][j] cur += min(x for k, x in enumerate(dist[2]) if k not in (i, j)) ans = min(ans, cur) print(ans) if __name__ == "__main__": main()
32
34
990
1,105
# ABC099D - Good Grid import sys input = sys.stdin.readline from collections import defaultdict from itertools import product def main(): N, C = list(map(int, input().split())) D = [0] + list([0] + list(map(int, input().split())) for _ in range(C)) grid = tuple(tuple(map(int, input().split())) for _ in range(N)) cost = {i: defaultdict(int) for i in range(3)} for i, g in enumerate(grid): for j, x in enumerate(g): cost[(i + j) % 3][x] += 1 dist = [[] for _ in range(3)] for i, tgt in product(list(range(3)), list(range(1, C + 1))): cur = sum(D[src][tgt] * cnt for src, cnt in list(cost[i].items())) dist[i].append(cur) ans = 1 << 60 for i, j in product(list(range(C)), repeat=2): if i == j: continue cur = dist[0][i] + dist[1][j] cur += min(x for k, x in enumerate(dist[2]) if k not in (i, j)) ans = min(ans, cur) print(ans) if __name__ == "__main__": main()
# ABC099D - Good Grid import sys input = sys.stdin.readline from collections import Counter from itertools import product def main(): N, C = list(map(int, input().split())) D = [0] + list([0] + list(map(int, input().split())) for _ in range(C)) grid = tuple(tuple(map(int, input().split())) for _ in range(N)) cost = [Counter() for _ in range(3)] for i, g in enumerate(grid): # classify each cell by mod3 for j in range(3): cost[(i + j) % 3].update(g[j::3]) dist = [[] for _ in range(3)] # compute the actual cost to change color for i, tgt in product(list(range(3)), list(range(1, C + 1))): cur = sum(D[src][tgt] * cnt for src, cnt in list(cost[i].items())) dist[i].append(cur) ans = 1 << 60 # fix two colors and compute the minimum cost for i, j in product(list(range(C)), repeat=2): if i == j: continue cur = dist[0][i] + dist[1][j] cur += min(x for k, x in enumerate(dist[2]) if k not in (i, j)) ans = min(ans, cur) print(ans) if __name__ == "__main__": main()
false
5.882353
[ "-from collections import defaultdict", "+from collections import Counter", "- cost = {i: defaultdict(int) for i in range(3)}", "- for i, g in enumerate(grid):", "- for j, x in enumerate(g):", "- cost[(i + j) % 3][x] += 1", "+ cost = [Counter() for _ in range(3)]", "+ for i, g in enumerate(grid): # classify each cell by mod3", "+ for j in range(3):", "+ cost[(i + j) % 3].update(g[j::3])", "+ # compute the actual cost to change color", "+ # fix two colors and compute the minimum cost" ]
false
0.036521
0.066133
0.552234
[ "s120577952", "s735776901" ]
u135389999
p02767
python
s667484972
s100433717
321
18
21,644
3,060
Accepted
Accepted
94.39
import numpy as np import math n = int(eval(input())) x = list(map(int,input().split())) p1_sum = [] p2_sum = [] p1 = math.floor((1/n) * sum(x)) p2 = math.ceil((1/n) * sum(x)) for i in x: p1_sum.append((p1 - i)** 2) p2_sum.append((p2 - i)** 2) print((min(sum(p1_sum),sum(p2_sum))))
n = int(eval(input())) x = list(map(int,input().split())) p = round((1/n) * sum(x)) ans = 0 for i in x: ans += (p -i) ** 2 print(ans)
17
9
302
141
import numpy as np import math n = int(eval(input())) x = list(map(int, input().split())) p1_sum = [] p2_sum = [] p1 = math.floor((1 / n) * sum(x)) p2 = math.ceil((1 / n) * sum(x)) for i in x: p1_sum.append((p1 - i) ** 2) p2_sum.append((p2 - i) ** 2) print((min(sum(p1_sum), sum(p2_sum))))
n = int(eval(input())) x = list(map(int, input().split())) p = round((1 / n) * sum(x)) ans = 0 for i in x: ans += (p - i) ** 2 print(ans)
false
47.058824
[ "-import numpy as np", "-import math", "-", "-p1_sum = []", "-p2_sum = []", "-p1 = math.floor((1 / n) * sum(x))", "-p2 = math.ceil((1 / n) * sum(x))", "+p = round((1 / n) * sum(x))", "+ans = 0", "- p1_sum.append((p1 - i) ** 2)", "- p2_sum.append((p2 - i) ** 2)", "-print((min(sum(p1_sum), sum(p2_sum))))", "+ ans += (p - i) ** 2", "+print(ans)" ]
false
0.035306
0.035357
0.99856
[ "s667484972", "s100433717" ]
u644907318
p02891
python
s520245543
s216629543
183
61
38,512
62,036
Accepted
Accepted
66.67
def f(k): T = S*k N = len(T) cur = T[0] cnt = 1 ans = 0 for i in range(1,N): if T[i]==cur: cnt += 1 else: ans += cnt//2 cur = T[i] cnt = 1 ans += cnt//2 return ans S = input().strip() K = int(eval(input())) ans1 = f(1) ans2 = f(2) ans3 = f(3) d1 = f(2)-f(1) d2 = f(3)-f(2) k = (K-1)//2 if (K-1)%2==0: print((f(1)+(d1+d2)*k)) else: print((f(1)+(d1+d2)*k+d1))
C = {} S = input().strip() N = len(S) K = int(eval(input())) for i in range(N): s = S[i] if s not in C: C[s]=0 C[s] += 1 if len(C)>1: a = 0 cnt = 1 for i in range(1,N): if S[i]==S[i-1]: cnt += 1 else: a += cnt//2 cnt = 1 a += cnt//2 X = S+S b = 0 cnt = 1 for i in range(1,2*N): if X[i]==X[i-1]: cnt += 1 else: b += cnt//2 cnt = 1 b += cnt//2 d = b-a print((a+d*(K-1))) else: A = list(C.items()) k = A[0][1] if k%2==0: print(((k//2)*K)) else: if K%2==0: a = k b = 2*k d = k print((a+d*((K//2)-1))) else: a = k//2 b = (k*3)//2 d = b-a print((a+d*(K//2)))
27
47
477
888
def f(k): T = S * k N = len(T) cur = T[0] cnt = 1 ans = 0 for i in range(1, N): if T[i] == cur: cnt += 1 else: ans += cnt // 2 cur = T[i] cnt = 1 ans += cnt // 2 return ans S = input().strip() K = int(eval(input())) ans1 = f(1) ans2 = f(2) ans3 = f(3) d1 = f(2) - f(1) d2 = f(3) - f(2) k = (K - 1) // 2 if (K - 1) % 2 == 0: print((f(1) + (d1 + d2) * k)) else: print((f(1) + (d1 + d2) * k + d1))
C = {} S = input().strip() N = len(S) K = int(eval(input())) for i in range(N): s = S[i] if s not in C: C[s] = 0 C[s] += 1 if len(C) > 1: a = 0 cnt = 1 for i in range(1, N): if S[i] == S[i - 1]: cnt += 1 else: a += cnt // 2 cnt = 1 a += cnt // 2 X = S + S b = 0 cnt = 1 for i in range(1, 2 * N): if X[i] == X[i - 1]: cnt += 1 else: b += cnt // 2 cnt = 1 b += cnt // 2 d = b - a print((a + d * (K - 1))) else: A = list(C.items()) k = A[0][1] if k % 2 == 0: print(((k // 2) * K)) else: if K % 2 == 0: a = k b = 2 * k d = k print((a + d * ((K // 2) - 1))) else: a = k // 2 b = (k * 3) // 2 d = b - a print((a + d * (K // 2)))
false
42.553191
[ "-def f(k):", "- T = S * k", "- N = len(T)", "- cur = T[0]", "+C = {}", "+S = input().strip()", "+N = len(S)", "+K = int(eval(input()))", "+for i in range(N):", "+ s = S[i]", "+ if s not in C:", "+ C[s] = 0", "+ C[s] += 1", "+if len(C) > 1:", "+ a = 0", "- ans = 0", "- if T[i] == cur:", "+ if S[i] == S[i - 1]:", "- ans += cnt // 2", "- cur = T[i]", "+ a += cnt // 2", "- ans += cnt // 2", "- return ans", "-", "-", "-S = input().strip()", "-K = int(eval(input()))", "-ans1 = f(1)", "-ans2 = f(2)", "-ans3 = f(3)", "-d1 = f(2) - f(1)", "-d2 = f(3) - f(2)", "-k = (K - 1) // 2", "-if (K - 1) % 2 == 0:", "- print((f(1) + (d1 + d2) * k))", "+ a += cnt // 2", "+ X = S + S", "+ b = 0", "+ cnt = 1", "+ for i in range(1, 2 * N):", "+ if X[i] == X[i - 1]:", "+ cnt += 1", "+ else:", "+ b += cnt // 2", "+ cnt = 1", "+ b += cnt // 2", "+ d = b - a", "+ print((a + d * (K - 1)))", "- print((f(1) + (d1 + d2) * k + d1))", "+ A = list(C.items())", "+ k = A[0][1]", "+ if k % 2 == 0:", "+ print(((k // 2) * K))", "+ else:", "+ if K % 2 == 0:", "+ a = k", "+ b = 2 * k", "+ d = k", "+ print((a + d * ((K // 2) - 1)))", "+ else:", "+ a = k // 2", "+ b = (k * 3) // 2", "+ d = b - a", "+ print((a + d * (K // 2)))" ]
false
0.035878
0.035676
1.005653
[ "s520245543", "s216629543" ]
u700805562
p03163
python
s606172725
s276973849
446
234
119,916
149,288
Accepted
Accepted
47.53
n, w = list(map(int, input().split())) wv = [list(map(int, input().split())) for _ in range(n)] dp = [[0]*(w+1) for _ in range(n+1)] for i in range(n): w_, v_ = wv[i] for j in range(w+1): if j < w_: dp[i+1][j] = dp[i][j] else: dp[i+1][j] = max(dp[i][j-w_]+v_, dp[i][j]) print((dp[n][w]))
N, W = list(map(int, input().split())) dp = [[0]*(W+1) for _ in range(N+1)] for i in range(N): w, v = list(map(int, input().split())) for j in range(1, W+1): if j<w: dp[i+1][j] = dp[i][j] if w<=j: dp[i+1][j] = max(dp[i][j], dp[i][j-w]+v) print((dp[-1][-1]))
11
10
337
300
n, w = list(map(int, input().split())) wv = [list(map(int, input().split())) for _ in range(n)] dp = [[0] * (w + 1) for _ in range(n + 1)] for i in range(n): w_, v_ = wv[i] for j in range(w + 1): if j < w_: dp[i + 1][j] = dp[i][j] else: dp[i + 1][j] = max(dp[i][j - w_] + v_, dp[i][j]) print((dp[n][w]))
N, W = list(map(int, input().split())) dp = [[0] * (W + 1) for _ in range(N + 1)] for i in range(N): w, v = list(map(int, input().split())) for j in range(1, W + 1): if j < w: dp[i + 1][j] = dp[i][j] if w <= j: dp[i + 1][j] = max(dp[i][j], dp[i][j - w] + v) print((dp[-1][-1]))
false
9.090909
[ "-n, w = list(map(int, input().split()))", "-wv = [list(map(int, input().split())) for _ in range(n)]", "-dp = [[0] * (w + 1) for _ in range(n + 1)]", "-for i in range(n):", "- w_, v_ = wv[i]", "- for j in range(w + 1):", "- if j < w_:", "+N, W = list(map(int, input().split()))", "+dp = [[0] * (W + 1) for _ in range(N + 1)]", "+for i in range(N):", "+ w, v = list(map(int, input().split()))", "+ for j in range(1, W + 1):", "+ if j < w:", "- else:", "- dp[i + 1][j] = max(dp[i][j - w_] + v_, dp[i][j])", "-print((dp[n][w]))", "+ if w <= j:", "+ dp[i + 1][j] = max(dp[i][j], dp[i][j - w] + v)", "+print((dp[-1][-1]))" ]
false
0.055219
0.059064
0.934902
[ "s606172725", "s276973849" ]
u729133443
p02702
python
s292000350
s035102469
321
134
80,128
9,220
Accepted
Accepted
58.26
M=2019 a=i=0 d=[0]*M p=1 for j in'0'+input()[::-1]:i=(i+int(j)*p)%M;p=p*10%M;a+=d[i];d[i]+=1 print(a)
M=2019 a=i=0 d=[0]*M p=1 for j in input()[::-1]:d[i%M]+=1;i-=int(j)*p;a+=d[i%M];p=p*10%M print(a)
6
6
106
102
M = 2019 a = i = 0 d = [0] * M p = 1 for j in "0" + input()[::-1]: i = (i + int(j) * p) % M p = p * 10 % M a += d[i] d[i] += 1 print(a)
M = 2019 a = i = 0 d = [0] * M p = 1 for j in input()[::-1]: d[i % M] += 1 i -= int(j) * p a += d[i % M] p = p * 10 % M print(a)
false
0
[ "-for j in \"0\" + input()[::-1]:", "- i = (i + int(j) * p) % M", "+for j in input()[::-1]:", "+ d[i % M] += 1", "+ i -= int(j) * p", "+ a += d[i % M]", "- a += d[i]", "- d[i] += 1" ]
false
0.034702
0.034055
1.019001
[ "s292000350", "s035102469" ]
u141610915
p03086
python
s359887568
s460955565
165
63
38,384
62,164
Accepted
Accepted
61.82
S = eval(input()) res = 0 temp = 0 for i in range(len(S)): if S[i] in ["A", "T", "C", "G"]: temp += 1 res = max(temp, res) else: temp = 0 print(res)
import sys input = sys.stdin.readline S = list(eval(input()))[: -1] res = 0 for l in range(len(S)): for r in range(l + 1, len(S) + 1): for i in range(l, r): if not S[i] in ["A", "T", "C", "G"]: break else: res = max(res, r - l) print(res)
10
10
167
257
S = eval(input()) res = 0 temp = 0 for i in range(len(S)): if S[i] in ["A", "T", "C", "G"]: temp += 1 res = max(temp, res) else: temp = 0 print(res)
import sys input = sys.stdin.readline S = list(eval(input()))[:-1] res = 0 for l in range(len(S)): for r in range(l + 1, len(S) + 1): for i in range(l, r): if not S[i] in ["A", "T", "C", "G"]: break else: res = max(res, r - l) print(res)
false
0
[ "-S = eval(input())", "+import sys", "+", "+input = sys.stdin.readline", "+S = list(eval(input()))[:-1]", "-temp = 0", "-for i in range(len(S)):", "- if S[i] in [\"A\", \"T\", \"C\", \"G\"]:", "- temp += 1", "- res = max(temp, res)", "- else:", "- temp = 0", "+for l in range(len(S)):", "+ for r in range(l + 1, len(S) + 1):", "+ for i in range(l, r):", "+ if not S[i] in [\"A\", \"T\", \"C\", \"G\"]:", "+ break", "+ else:", "+ res = max(res, r - l)" ]
false
0.034549
0.044076
0.783861
[ "s359887568", "s460955565" ]
u094999522
p02735
python
s624126908
s111064958
491
39
9,524
9,328
Accepted
Accepted
92.06
#!/usr/bin/env python3 from collections import deque h, w = list(map(int, input().split())) maze = [[i == "#" for i in eval(input())] for _ in range(h)] dx = [1, 0] dy = [0, 1] que = deque([]) que.append((0, 0, maze[0][0], 1 if maze[0][0] else 0)) count = [[h + w] * w for _ in range(h)] while que: x, y, b, c = que.pop() if c >= count[x][y]: continue count[x][y] = c if x == h - 1 and y == w - 1: continue for i in range(2): nx = x + dx[i] ny = y + dy[i] if not (0 <= nx < h and 0 <= ny < w): continue que.append((nx, ny, maze[nx][ny], c + (not b and maze[nx][ny]))) print((count[h - 1][w - 1]))
h, w = list(map(int, input().split())) s = [[i == "#" for i in eval(input())] for _ in range(h)] dp = [[10**9] * w for _ in range(h)] dp[0][0] = int(s[0][0]) for i in range(h): for j in range(w): a = dp[i - 1][j] + (not s[i - 1][j] and s[i][j]) b = dp[i][j - 1] + (not s[i][j -1] and s[i][j]) dp[i][j] = min(a, b,dp[i][j]) print((dp[-1][-1]))
28
10
695
366
#!/usr/bin/env python3 from collections import deque h, w = list(map(int, input().split())) maze = [[i == "#" for i in eval(input())] for _ in range(h)] dx = [1, 0] dy = [0, 1] que = deque([]) que.append((0, 0, maze[0][0], 1 if maze[0][0] else 0)) count = [[h + w] * w for _ in range(h)] while que: x, y, b, c = que.pop() if c >= count[x][y]: continue count[x][y] = c if x == h - 1 and y == w - 1: continue for i in range(2): nx = x + dx[i] ny = y + dy[i] if not (0 <= nx < h and 0 <= ny < w): continue que.append((nx, ny, maze[nx][ny], c + (not b and maze[nx][ny]))) print((count[h - 1][w - 1]))
h, w = list(map(int, input().split())) s = [[i == "#" for i in eval(input())] for _ in range(h)] dp = [[10**9] * w for _ in range(h)] dp[0][0] = int(s[0][0]) for i in range(h): for j in range(w): a = dp[i - 1][j] + (not s[i - 1][j] and s[i][j]) b = dp[i][j - 1] + (not s[i][j - 1] and s[i][j]) dp[i][j] = min(a, b, dp[i][j]) print((dp[-1][-1]))
false
64.285714
[ "-#!/usr/bin/env python3", "-from collections import deque", "-", "-maze = [[i == \"#\" for i in eval(input())] for _ in range(h)]", "-dx = [1, 0]", "-dy = [0, 1]", "-que = deque([])", "-que.append((0, 0, maze[0][0], 1 if maze[0][0] else 0))", "-count = [[h + w] * w for _ in range(h)]", "-while que:", "- x, y, b, c = que.pop()", "- if c >= count[x][y]:", "- continue", "- count[x][y] = c", "- if x == h - 1 and y == w - 1:", "- continue", "- for i in range(2):", "- nx = x + dx[i]", "- ny = y + dy[i]", "- if not (0 <= nx < h and 0 <= ny < w):", "- continue", "- que.append((nx, ny, maze[nx][ny], c + (not b and maze[nx][ny])))", "-print((count[h - 1][w - 1]))", "+s = [[i == \"#\" for i in eval(input())] for _ in range(h)]", "+dp = [[10**9] * w for _ in range(h)]", "+dp[0][0] = int(s[0][0])", "+for i in range(h):", "+ for j in range(w):", "+ a = dp[i - 1][j] + (not s[i - 1][j] and s[i][j])", "+ b = dp[i][j - 1] + (not s[i][j - 1] and s[i][j])", "+ dp[i][j] = min(a, b, dp[i][j])", "+print((dp[-1][-1]))" ]
false
0.081845
0.044066
1.857323
[ "s624126908", "s111064958" ]
u562935282
p03037
python
s240583496
s527492720
536
308
43,608
10,996
Accepted
Accepted
42.54
N, M = list(map(int, input().split())) left = 1 right = N # 1-indexed # [left, right] for _ in range(M): L, R = list(map(int, input().split())) if L > left: left = L if R < right: right = R if right - left + 1 <= 0: break print((max(0, right - left + 1)))
n, m = list(map(int, input().split())) l, r = [], [] for _ in range(m): ll, rr = list(map(int, input().split())) l.append(ll) r.append(rr) print((max(0, min(r) - max(l) + 1)))
16
9
299
184
N, M = list(map(int, input().split())) left = 1 right = N # 1-indexed # [left, right] for _ in range(M): L, R = list(map(int, input().split())) if L > left: left = L if R < right: right = R if right - left + 1 <= 0: break print((max(0, right - left + 1)))
n, m = list(map(int, input().split())) l, r = [], [] for _ in range(m): ll, rr = list(map(int, input().split())) l.append(ll) r.append(rr) print((max(0, min(r) - max(l) + 1)))
false
43.75
[ "-N, M = list(map(int, input().split()))", "-left = 1", "-right = N", "-# 1-indexed", "-# [left, right]", "-for _ in range(M):", "- L, R = list(map(int, input().split()))", "- if L > left:", "- left = L", "- if R < right:", "- right = R", "- if right - left + 1 <= 0:", "- break", "-print((max(0, right - left + 1)))", "+n, m = list(map(int, input().split()))", "+l, r = [], []", "+for _ in range(m):", "+ ll, rr = list(map(int, input().split()))", "+ l.append(ll)", "+ r.append(rr)", "+print((max(0, min(r) - max(l) + 1)))" ]
false
0.083608
0.042413
1.9713
[ "s240583496", "s527492720" ]
u816631826
p02699
python
s955098602
s292633448
64
26
61,792
9,004
Accepted
Accepted
59.38
a, b=[int(yy) for yy in input().split()] if b>=a: print('unsafe') else: print("safe")
S, W = [int(x) for x in input().split()] if W >= S: print('unsafe') else: print('safe')
5
5
92
99
a, b = [int(yy) for yy in input().split()] if b >= a: print("unsafe") else: print("safe")
S, W = [int(x) for x in input().split()] if W >= S: print("unsafe") else: print("safe")
false
0
[ "-a, b = [int(yy) for yy in input().split()]", "-if b >= a:", "+S, W = [int(x) for x in input().split()]", "+if W >= S:" ]
false
0.073506
0.087335
0.841658
[ "s955098602", "s292633448" ]
u937642029
p02683
python
s887343531
s036307963
73
61
10,896
9,240
Accepted
Accepted
16.44
import sys, bisect, math, itertools, string, queue, copy # import numpy as np # import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush from fractions import gcd # input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(eval(input())) def inpm(): return list(map(int,input().split())) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(eval(input())) for _ in range(n)) def inplL(n): return [list(eval(input())) for _ in range(n)] def inplT(n): return [tuple(eval(input())) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) def main(): n,m,x = inpm() c = [list(map(int,input().split())) for _ in range(n)] ans = float('inf') for num in range(1,n+1): for e in combinations(list(range(n)),num): cost = 0 under = [0 for _ in range(m)] for f in e: cost += c[f][0] for i in range(m): under[i] += c[f][i+1] if min(under) >= x: ans = min(ans,cost) if ans == float('inf'): print((-1)) else: print(ans) if __name__ == "__main__": main()
import sys from itertools import combinations input = sys.stdin.readline def main(): n,m,x = list(map(int,input().split())) c = [list(map(int,input().split())) for _ in range(n)] ans = float('inf') for num in range(1,n+1): for e in combinations(list(range(n)),num): cost = 0 under = [0 for _ in range(m)] for f in e: cost += c[f][0] for i in range(m): under[i] += c[f][i+1] if min(under) >= x: ans = min(ans,cost) if ans == float('inf'): print((-1)) else: print(ans) if __name__ == "__main__": main()
42
26
1,429
688
import sys, bisect, math, itertools, string, queue, copy # import numpy as np # import scipy from collections import Counter, defaultdict, deque from itertools import permutations, combinations from heapq import heappop, heappush from fractions import gcd # input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9 + 7 def inp(): return int(eval(input())) def inpm(): return list(map(int, input().split())) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(eval(input())) for _ in range(n)) def inplL(n): return [list(eval(input())) for _ in range(n)] def inplT(n): return [tuple(eval(input())) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) def main(): n, m, x = inpm() c = [list(map(int, input().split())) for _ in range(n)] ans = float("inf") for num in range(1, n + 1): for e in combinations(list(range(n)), num): cost = 0 under = [0 for _ in range(m)] for f in e: cost += c[f][0] for i in range(m): under[i] += c[f][i + 1] if min(under) >= x: ans = min(ans, cost) if ans == float("inf"): print((-1)) else: print(ans) if __name__ == "__main__": main()
import sys from itertools import combinations input = sys.stdin.readline def main(): n, m, x = list(map(int, input().split())) c = [list(map(int, input().split())) for _ in range(n)] ans = float("inf") for num in range(1, n + 1): for e in combinations(list(range(n)), num): cost = 0 under = [0 for _ in range(m)] for f in e: cost += c[f][0] for i in range(m): under[i] += c[f][i + 1] if min(under) >= x: ans = min(ans, cost) if ans == float("inf"): print((-1)) else: print(ans) if __name__ == "__main__": main()
false
38.095238
[ "-import sys, bisect, math, itertools, string, queue, copy", "+import sys", "+from itertools import combinations", "-# import numpy as np", "-# import scipy", "-from collections import Counter, defaultdict, deque", "-from itertools import permutations, combinations", "-from heapq import heappop, heappush", "-from fractions import gcd", "-", "-# input = sys.stdin.readline", "-sys.setrecursionlimit(10**8)", "-mod = 10**9 + 7", "-", "-", "-def inp():", "- return int(eval(input()))", "-", "-", "-def inpm():", "- return list(map(int, input().split()))", "-", "-", "-def inpl():", "- return list(map(int, input().split()))", "-", "-", "-def inpls():", "- return list(input().split())", "-", "-", "-def inplm(n):", "- return list(int(eval(input())) for _ in range(n))", "-", "-", "-def inplL(n):", "- return [list(eval(input())) for _ in range(n)]", "-", "-", "-def inplT(n):", "- return [tuple(eval(input())) for _ in range(n)]", "-", "-", "-def inpll(n):", "- return [list(map(int, input().split())) for _ in range(n)]", "-", "-", "-def inplls(n):", "- return sorted([list(map(int, input().split())) for _ in range(n)])", "+input = sys.stdin.readline", "- n, m, x = inpm()", "+ n, m, x = list(map(int, input().split()))" ]
false
0.035806
0.038887
0.920764
[ "s887343531", "s036307963" ]
u201234972
p03309
python
s567352018
s036016346
787
229
49,520
36,780
Accepted
Accepted
70.9
from statistics import median import math N = int(eval(input())) *A, = list(map(int, input().split())) B = [A[i]-i for i in range(N)] b = median(B) bm = math.floor(b) K = [x - bm for x in B] KZ = [abs(x) for x in K] Z = sum(KZ) for i in range(20): C = [abs(x-i+10) for x in K] Z = min([sum(C),Z]) print((int(Z)))
from statistics import median import math N = int(eval(input())) *A, = list(map(int, input().split())) B = [A[i]-i for i in range(N)] b = median(B) bm = math.floor(b) bM = math.ceil(b) Bm = [abs(x - bm) for x in B] BM = [abs(x - bM) for x in B] m = sum(Bm) M = sum(BM) print((int(min([m,M]))))
14
13
319
291
from statistics import median import math N = int(eval(input())) (*A,) = list(map(int, input().split())) B = [A[i] - i for i in range(N)] b = median(B) bm = math.floor(b) K = [x - bm for x in B] KZ = [abs(x) for x in K] Z = sum(KZ) for i in range(20): C = [abs(x - i + 10) for x in K] Z = min([sum(C), Z]) print((int(Z)))
from statistics import median import math N = int(eval(input())) (*A,) = list(map(int, input().split())) B = [A[i] - i for i in range(N)] b = median(B) bm = math.floor(b) bM = math.ceil(b) Bm = [abs(x - bm) for x in B] BM = [abs(x - bM) for x in B] m = sum(Bm) M = sum(BM) print((int(min([m, M]))))
false
7.142857
[ "-K = [x - bm for x in B]", "-KZ = [abs(x) for x in K]", "-Z = sum(KZ)", "-for i in range(20):", "- C = [abs(x - i + 10) for x in K]", "- Z = min([sum(C), Z])", "-print((int(Z)))", "+bM = math.ceil(b)", "+Bm = [abs(x - bm) for x in B]", "+BM = [abs(x - bM) for x in B]", "+m = sum(Bm)", "+M = sum(BM)", "+print((int(min([m, M]))))" ]
false
0.147121
0.10767
1.366399
[ "s567352018", "s036016346" ]
u546285759
p00047
python
s647334521
s317779781
30
20
7,396
7,376
Accepted
Accepted
33.33
cup= [True, False, False] while True: try: p= list(map(str, input().split(','))) except: break x, y= sorted(p) if x=='A' and y=='B': cup[0], cup[1]= cup[1], cup[0] elif x=='A' and y=='C': cup[0], cup[2]= cup[2], cup[0] elif x=='B' and y=='C': cup[1], cup[2]= cup[2], cup[1] for i in range(3): if cup[i]: print(('A' if i==0 else('B' if i==1 else 'C'))) break
cup = {"A": 1, "B": 0, "C": 0} while True: try: x, y = input().split(",") except: break cup[x], cup[y] = cup[y], cup[x] for k, v in list(cup.items()): if v: print(k)
17
11
455
210
cup = [True, False, False] while True: try: p = list(map(str, input().split(","))) except: break x, y = sorted(p) if x == "A" and y == "B": cup[0], cup[1] = cup[1], cup[0] elif x == "A" and y == "C": cup[0], cup[2] = cup[2], cup[0] elif x == "B" and y == "C": cup[1], cup[2] = cup[2], cup[1] for i in range(3): if cup[i]: print(("A" if i == 0 else ("B" if i == 1 else "C"))) break
cup = {"A": 1, "B": 0, "C": 0} while True: try: x, y = input().split(",") except: break cup[x], cup[y] = cup[y], cup[x] for k, v in list(cup.items()): if v: print(k)
false
35.294118
[ "-cup = [True, False, False]", "+cup = {\"A\": 1, \"B\": 0, \"C\": 0}", "- p = list(map(str, input().split(\",\")))", "+ x, y = input().split(\",\")", "- x, y = sorted(p)", "- if x == \"A\" and y == \"B\":", "- cup[0], cup[1] = cup[1], cup[0]", "- elif x == \"A\" and y == \"C\":", "- cup[0], cup[2] = cup[2], cup[0]", "- elif x == \"B\" and y == \"C\":", "- cup[1], cup[2] = cup[2], cup[1]", "-for i in range(3):", "- if cup[i]:", "- print((\"A\" if i == 0 else (\"B\" if i == 1 else \"C\")))", "- break", "+ cup[x], cup[y] = cup[y], cup[x]", "+for k, v in list(cup.items()):", "+ if v:", "+ print(k)" ]
false
0.008526
0.044542
0.19142
[ "s647334521", "s317779781" ]
u394721319
p03294
python
s249859899
s623417146
171
28
38,896
9,360
Accepted
Accepted
83.63
N = int(eval(input())) A = [int(zz) for zz in input().split()] print((sum(A)-N))
N = int(eval(input())) print((sum([int(i)-1 for i in input().split()])))
4
2
77
66
N = int(eval(input())) A = [int(zz) for zz in input().split()] print((sum(A) - N))
N = int(eval(input())) print((sum([int(i) - 1 for i in input().split()])))
false
50
[ "-A = [int(zz) for zz in input().split()]", "-print((sum(A) - N))", "+print((sum([int(i) - 1 for i in input().split()])))" ]
false
0.03438
0.039421
0.872133
[ "s249859899", "s623417146" ]
u753803401
p02972
python
s042067912
s618552410
606
535
14,060
14,096
Accepted
Accepted
11.72
n = int(eval(input())) a = list(map(int, input().split())) b = [0] * (n + 1) ls = [] for i in range(n, 0, -1): cnt = 0 for j in range(i, n + 1, i): cnt += b[j] if a[i-1] != cnt % 2: b[i] = 1 ls.append(i) print((len(ls))) if len(ls) != 0: print((*ls))
n = int(eval(input())) a = list(map(int, input().split())) ls = [0] * n ans = [] for i in range(n-1, -1, -1): t = 0 for j in range(i, n, (i + 1)): t += ls[j] if a[i] != t % 2: ans.append(i + 1) ls[i] = 1 print((len(ans))) if len(ans) != 0: print((*ans))
14
14
294
297
n = int(eval(input())) a = list(map(int, input().split())) b = [0] * (n + 1) ls = [] for i in range(n, 0, -1): cnt = 0 for j in range(i, n + 1, i): cnt += b[j] if a[i - 1] != cnt % 2: b[i] = 1 ls.append(i) print((len(ls))) if len(ls) != 0: print((*ls))
n = int(eval(input())) a = list(map(int, input().split())) ls = [0] * n ans = [] for i in range(n - 1, -1, -1): t = 0 for j in range(i, n, (i + 1)): t += ls[j] if a[i] != t % 2: ans.append(i + 1) ls[i] = 1 print((len(ans))) if len(ans) != 0: print((*ans))
false
0
[ "-b = [0] * (n + 1)", "-ls = []", "-for i in range(n, 0, -1):", "- cnt = 0", "- for j in range(i, n + 1, i):", "- cnt += b[j]", "- if a[i - 1] != cnt % 2:", "- b[i] = 1", "- ls.append(i)", "-print((len(ls)))", "-if len(ls) != 0:", "- print((*ls))", "+ls = [0] * n", "+ans = []", "+for i in range(n - 1, -1, -1):", "+ t = 0", "+ for j in range(i, n, (i + 1)):", "+ t += ls[j]", "+ if a[i] != t % 2:", "+ ans.append(i + 1)", "+ ls[i] = 1", "+print((len(ans)))", "+if len(ans) != 0:", "+ print((*ans))" ]
false
0.040942
0.044858
0.912704
[ "s042067912", "s618552410" ]
u577170763
p03163
python
s286617195
s969254521
374
276
82,116
117,488
Accepted
Accepted
26.2
# import sys # sys.setrecursionlimit(10**5) # from collections import defaultdict import sys readline = sys.stdin.buffer.readline geta = lambda fn: list(map(fn, readline().split())) gete = lambda fn: fn(readline()) N, W = geta(int) cur = [0] * (W+1) for i in range(N): w, v = geta(int) update = cur[:] for j in range(w,W+1): tmp = cur[j-w] + v if tmp > cur[j]: update[j] = tmp cur = update print((cur[W]))
# import sys # sys.setrecursionlimit(10**5) # from collections import defaultdict import sys readline = sys.stdin.buffer.readline geta = lambda fn: list(map(fn, readline().split())) gete = lambda fn: fn(readline()) def main(): N, W = geta(int) cur = [0] * (W+1) for i in range(N): w, v = geta(int) update = cur[:] for j in range(w,W+1): tmp = cur[j-w] + v if tmp > cur[j]: update[j] = tmp cur = update print((cur[W])) if __name__ == "__main__": main()
22
25
461
557
# import sys # sys.setrecursionlimit(10**5) # from collections import defaultdict import sys readline = sys.stdin.buffer.readline geta = lambda fn: list(map(fn, readline().split())) gete = lambda fn: fn(readline()) N, W = geta(int) cur = [0] * (W + 1) for i in range(N): w, v = geta(int) update = cur[:] for j in range(w, W + 1): tmp = cur[j - w] + v if tmp > cur[j]: update[j] = tmp cur = update print((cur[W]))
# import sys # sys.setrecursionlimit(10**5) # from collections import defaultdict import sys readline = sys.stdin.buffer.readline geta = lambda fn: list(map(fn, readline().split())) gete = lambda fn: fn(readline()) def main(): N, W = geta(int) cur = [0] * (W + 1) for i in range(N): w, v = geta(int) update = cur[:] for j in range(w, W + 1): tmp = cur[j - w] + v if tmp > cur[j]: update[j] = tmp cur = update print((cur[W])) if __name__ == "__main__": main()
false
12
[ "-N, W = geta(int)", "-cur = [0] * (W + 1)", "-for i in range(N):", "- w, v = geta(int)", "- update = cur[:]", "- for j in range(w, W + 1):", "- tmp = cur[j - w] + v", "- if tmp > cur[j]:", "- update[j] = tmp", "- cur = update", "-print((cur[W]))", "+", "+", "+def main():", "+ N, W = geta(int)", "+ cur = [0] * (W + 1)", "+ for i in range(N):", "+ w, v = geta(int)", "+ update = cur[:]", "+ for j in range(w, W + 1):", "+ tmp = cur[j - w] + v", "+ if tmp > cur[j]:", "+ update[j] = tmp", "+ cur = update", "+ print((cur[W]))", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.045072
0.043785
1.029392
[ "s286617195", "s969254521" ]
u600402037
p02949
python
s329659483
s373256405
1,024
746
44,060
42,940
Accepted
Accepted
27.15
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M, P = lr() # 終了時、T*P枚支払う graph = [lr() for _ in range(M)] def bellmanford(start, N): INF = 10 ** 12 dist = [-INF] * (N+1) # 1-indexed dist[start] = 0 for i in range(N+N+5): for pre, ne, weight in graph: if dist[pre] != -INF and dist[pre] + weight - P > dist[ne]: dist[ne] = dist[pre] + weight - P # n回繰り返してもスコアが更新された場合 if i > N-1: dist[ne] = INF if dist[N] == INF: return -1 else: return max(0, dist[N]) answer = bellmanford(1, N) print(answer)
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M, P = lr() # 終了時、T*P枚支払う graph = [tuple(lr()) for _ in range(M)] def bellmanford(start, N): INF = 10 ** 12 dist = [-INF] * (N+1) # 1-indexed dist[start] = 0 for i in range(N+N+5): for pre, ne, weight in graph: if dist[pre] != -INF and dist[pre] + weight - P > dist[ne]: dist[ne] = dist[pre] + weight - P # n回繰り返してもスコアが更新された場合 if i > N-1: dist[ne] = INF if dist[N] == INF: return -1 else: return max(0, dist[N]) answer = bellmanford(1, N) print(answer)
28
28
727
734
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M, P = lr() # 終了時、T*P枚支払う graph = [lr() for _ in range(M)] def bellmanford(start, N): INF = 10**12 dist = [-INF] * (N + 1) # 1-indexed dist[start] = 0 for i in range(N + N + 5): for pre, ne, weight in graph: if dist[pre] != -INF and dist[pre] + weight - P > dist[ne]: dist[ne] = dist[pre] + weight - P # n回繰り返してもスコアが更新された場合 if i > N - 1: dist[ne] = INF if dist[N] == INF: return -1 else: return max(0, dist[N]) answer = bellmanford(1, N) print(answer)
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, M, P = lr() # 終了時、T*P枚支払う graph = [tuple(lr()) for _ in range(M)] def bellmanford(start, N): INF = 10**12 dist = [-INF] * (N + 1) # 1-indexed dist[start] = 0 for i in range(N + N + 5): for pre, ne, weight in graph: if dist[pre] != -INF and dist[pre] + weight - P > dist[ne]: dist[ne] = dist[pre] + weight - P # n回繰り返してもスコアが更新された場合 if i > N - 1: dist[ne] = INF if dist[N] == INF: return -1 else: return max(0, dist[N]) answer = bellmanford(1, N) print(answer)
false
0
[ "-graph = [lr() for _ in range(M)]", "+graph = [tuple(lr()) for _ in range(M)]" ]
false
0.035281
0.035218
1.001768
[ "s329659483", "s373256405" ]
u257050137
p03337
python
s152630822
s269973707
20
17
3,188
2,940
Accepted
Accepted
15
a, b = list(map(int, input().split(' '))) print((max(a+b, a-b, a*b)))
a, b = list(map(int, input().split())) print((max(a + b, a - b, a * b)))
2
2
63
65
a, b = list(map(int, input().split(" "))) print((max(a + b, a - b, a * b)))
a, b = list(map(int, input().split())) print((max(a + b, a - b, a * b)))
false
0
[ "-a, b = list(map(int, input().split(\" \")))", "+a, b = list(map(int, input().split()))" ]
false
0.041799
0.046139
0.905925
[ "s152630822", "s269973707" ]
u875291233
p03108
python
s750628544
s003527810
807
560
27,140
24,784
Accepted
Accepted
30.61
class UnionFind: def __init__(self, size): self.parent = [-1]*size#非負なら親ノード,負ならグループの要素数 def root(self, x): #root(x): xの根ノードを返す. if self.parent[x] < 0: return x else: self.parent[x] = self.root(self.parent[x]) #xをxの根に直接つなぐ return self.parent[x] def merge(self, x, y): #merge(x,y): xのいるグループと$y$のいるグループをまとめる x = self.root(x) y = self.root(y) if x == y: return False if self.parent[x] > self.parent[y]: #xの要素数がyの要素数より「小さい」とき入れ替える x,y=y,x self.parent[x] += self.parent[y] #xの要素数を更新 self.parent[y] = x #yをxにつなぐ return True def issame(self, x, y): #same(x,y): xとyが同じグループにあるならTrue return self.root(x) == self.root(y) def size(self,x): #size(x): xのいるグループの要素数を返す return -self.parent[self.root(x)] n,m=[int(i) for i in input().split()] A=[[int(i)-1 for i in input().split()] for _ in range(m)] ans = [0]*(m+1) a = n*(n-1)//2 ans[0] = a uf = UnionFind(n) for i in range(m): j = m-i-1 v1 = A[j][0] v2 = A[j][1] # print(v1,v2) if not uf.issame(v1,v2): # print(uf.parent) a -= uf.size(v1) * uf.size(v2) uf.merge(v1,v2) ans[i+1]=a for i in range(m): print((ans[m-i-1]))
import sys class UnionFind: def __init__(self, size): self.parent = [-1 for i in range(size)]#非負なら親ノード,負ならグループの要素数 def root(self, x): #root(x): xの根ノードを返す. if self.parent[x] < 0: return x else: self.parent[x] = self.root(self.parent[x]) #xをxの根に直接つなぐ return self.parent[x] def merge(self, x, y): #merge(x,y): xのいるグループと$y$のいるグループをまとめる x = self.root(x) y = self.root(y) if x == y: return False if self.parent[x] > self.parent[y]: #xの要素数がyの要素数より「小さい」とき入れ替える x,y=y,x self.parent[x] += self.parent[y] #xの要素数を更新 self.parent[y] = x #yをxにつなぐ return True def issame(self, x, y): #same(x,y): xとyが同じグループにあるならTrue return self.root(x) == self.root(y) def size(self,x): #size(x): xのいるグループの要素数を返す return -self.parent[self.root(x)] n, m = list(map(int, input().split())) bridges = list(sys.stdin) bridges.reverse() buf = [n * (n - 1) // 2] uft = UnionFind(n) for line in bridges[:-1]: a, b = list(map(int, line.split())) a -= 1 b -= 1 if uft.issame(a, b): buf.append(buf[-1]) continue ra = uft.size(a) rb = uft.size(b) buf.append(buf[-1] - ra * rb) uft.merge(a, b) buf.reverse() print(('\n'.join(map(str, buf))))
61
57
1,390
1,404
class UnionFind: def __init__(self, size): self.parent = [-1] * size # 非負なら親ノード,負ならグループの要素数 def root(self, x): # root(x): xの根ノードを返す. if self.parent[x] < 0: return x else: self.parent[x] = self.root(self.parent[x]) # xをxの根に直接つなぐ return self.parent[x] def merge(self, x, y): # merge(x,y): xのいるグループと$y$のいるグループをまとめる x = self.root(x) y = self.root(y) if x == y: return False if self.parent[x] > self.parent[y]: # xの要素数がyの要素数より「小さい」とき入れ替える x, y = y, x self.parent[x] += self.parent[y] # xの要素数を更新 self.parent[y] = x # yをxにつなぐ return True def issame(self, x, y): # same(x,y): xとyが同じグループにあるならTrue return self.root(x) == self.root(y) def size(self, x): # size(x): xのいるグループの要素数を返す return -self.parent[self.root(x)] n, m = [int(i) for i in input().split()] A = [[int(i) - 1 for i in input().split()] for _ in range(m)] ans = [0] * (m + 1) a = n * (n - 1) // 2 ans[0] = a uf = UnionFind(n) for i in range(m): j = m - i - 1 v1 = A[j][0] v2 = A[j][1] # print(v1,v2) if not uf.issame(v1, v2): # print(uf.parent) a -= uf.size(v1) * uf.size(v2) uf.merge(v1, v2) ans[i + 1] = a for i in range(m): print((ans[m - i - 1]))
import sys class UnionFind: def __init__(self, size): self.parent = [-1 for i in range(size)] # 非負なら親ノード,負ならグループの要素数 def root(self, x): # root(x): xの根ノードを返す. if self.parent[x] < 0: return x else: self.parent[x] = self.root(self.parent[x]) # xをxの根に直接つなぐ return self.parent[x] def merge(self, x, y): # merge(x,y): xのいるグループと$y$のいるグループをまとめる x = self.root(x) y = self.root(y) if x == y: return False if self.parent[x] > self.parent[y]: # xの要素数がyの要素数より「小さい」とき入れ替える x, y = y, x self.parent[x] += self.parent[y] # xの要素数を更新 self.parent[y] = x # yをxにつなぐ return True def issame(self, x, y): # same(x,y): xとyが同じグループにあるならTrue return self.root(x) == self.root(y) def size(self, x): # size(x): xのいるグループの要素数を返す return -self.parent[self.root(x)] n, m = list(map(int, input().split())) bridges = list(sys.stdin) bridges.reverse() buf = [n * (n - 1) // 2] uft = UnionFind(n) for line in bridges[:-1]: a, b = list(map(int, line.split())) a -= 1 b -= 1 if uft.issame(a, b): buf.append(buf[-1]) continue ra = uft.size(a) rb = uft.size(b) buf.append(buf[-1] - ra * rb) uft.merge(a, b) buf.reverse() print(("\n".join(map(str, buf))))
false
6.557377
[ "+import sys", "+", "+", "- self.parent = [-1] * size # 非負なら親ノード,負ならグループの要素数", "+ self.parent = [-1 for i in range(size)] # 非負なら親ノード,負ならグループの要素数", "-n, m = [int(i) for i in input().split()]", "-A = [[int(i) - 1 for i in input().split()] for _ in range(m)]", "-ans = [0] * (m + 1)", "-a = n * (n - 1) // 2", "-ans[0] = a", "-uf = UnionFind(n)", "-for i in range(m):", "- j = m - i - 1", "- v1 = A[j][0]", "- v2 = A[j][1]", "- # print(v1,v2)", "- if not uf.issame(v1, v2):", "- # print(uf.parent)", "- a -= uf.size(v1) * uf.size(v2)", "- uf.merge(v1, v2)", "- ans[i + 1] = a", "-for i in range(m):", "- print((ans[m - i - 1]))", "+n, m = list(map(int, input().split()))", "+bridges = list(sys.stdin)", "+bridges.reverse()", "+buf = [n * (n - 1) // 2]", "+uft = UnionFind(n)", "+for line in bridges[:-1]:", "+ a, b = list(map(int, line.split()))", "+ a -= 1", "+ b -= 1", "+ if uft.issame(a, b):", "+ buf.append(buf[-1])", "+ continue", "+ ra = uft.size(a)", "+ rb = uft.size(b)", "+ buf.append(buf[-1] - ra * rb)", "+ uft.merge(a, b)", "+buf.reverse()", "+print((\"\\n\".join(map(str, buf))))" ]
false
0.077486
0.041035
1.888286
[ "s750628544", "s003527810" ]
u671060652
p03244
python
s311739374
s551706295
653
104
94,312
99,736
Accepted
Accepted
84.07
import itertools import math import fractions import functools import copy n = int(eval(input())) v = list(map(int, input().split())) kisu = [0]*(10**6) gusu = [0]*(10**6) for i in range(n): if i % 2 == 0: gusu[v[i]] += 1 else: kisu[v[i]] += 1 count = 0 gusu_m = gusu.index(max(gusu)) kisu_m = kisu.index(max(kisu)) if gusu_m == kisu_m: gusu[gusu_m] = 0 kisu[kisu_m] = 0 if max(gusu) > max(kisu): gusu_m = gusu.index(max(gusu)) else: kisu_m = kisu.index(max(kisu)) for i in range(n): if i % 2 == 0 and gusu_m != v[i]: count += 1 if i % 2 != 0 and kisu_m != v[i]: count += 1 print(count)
n = int(eval(input())) v = list(map(int, input().split())) kisu = [0]*(10**6) gusu = [0]*(10**6) for i in range(n): if i % 2 == 0: gusu[v[i]] += 1 else: kisu[v[i]] += 1 count = 0 gusu_m = gusu.index(max(gusu)) kisu_m = kisu.index(max(kisu)) if gusu_m == kisu_m: gusu[gusu_m] = 0 kisu[kisu_m] = 0 if max(gusu) > max(kisu): gusu_m = gusu.index(max(gusu)) else: kisu_m = kisu.index(max(kisu)) for i in range(n): if i % 2 == 0 and gusu_m != v[i]: count += 1 if i % 2 != 0 and kisu_m != v[i]: count += 1 print(count)
37
32
704
624
import itertools import math import fractions import functools import copy n = int(eval(input())) v = list(map(int, input().split())) kisu = [0] * (10**6) gusu = [0] * (10**6) for i in range(n): if i % 2 == 0: gusu[v[i]] += 1 else: kisu[v[i]] += 1 count = 0 gusu_m = gusu.index(max(gusu)) kisu_m = kisu.index(max(kisu)) if gusu_m == kisu_m: gusu[gusu_m] = 0 kisu[kisu_m] = 0 if max(gusu) > max(kisu): gusu_m = gusu.index(max(gusu)) else: kisu_m = kisu.index(max(kisu)) for i in range(n): if i % 2 == 0 and gusu_m != v[i]: count += 1 if i % 2 != 0 and kisu_m != v[i]: count += 1 print(count)
n = int(eval(input())) v = list(map(int, input().split())) kisu = [0] * (10**6) gusu = [0] * (10**6) for i in range(n): if i % 2 == 0: gusu[v[i]] += 1 else: kisu[v[i]] += 1 count = 0 gusu_m = gusu.index(max(gusu)) kisu_m = kisu.index(max(kisu)) if gusu_m == kisu_m: gusu[gusu_m] = 0 kisu[kisu_m] = 0 if max(gusu) > max(kisu): gusu_m = gusu.index(max(gusu)) else: kisu_m = kisu.index(max(kisu)) for i in range(n): if i % 2 == 0 and gusu_m != v[i]: count += 1 if i % 2 != 0 and kisu_m != v[i]: count += 1 print(count)
false
13.513514
[ "-import itertools", "-import math", "-import fractions", "-import functools", "-import copy", "-" ]
false
0.143445
0.359382
0.399143
[ "s311739374", "s551706295" ]
u693378622
p02804
python
s060135311
s733429048
461
280
34,972
26,660
Accepted
Accepted
39.26
import numpy as np mod = 10 ** 9 + 7 def f(n,k): ans = 1 for i in range(k): ans = ans * n % mod n -= 1 return ans 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 fact = [1, 1] # fact[n] = (n! mod p) factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p) inv = [0, 1] # factinv 計算用 p = mod for i in range(2, 10**5 + 1): fact.append((fact[-1] * i) % p) inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1] * inv[-1]) % p) # print( cmb(4, 2, mod) ) N, K = list(map(int, input().split())) A = sorted(map(int, input().split())) R = sorted(A, reverse=True) sum = 0 for i in range(N-K+1): t = cmb( N-i-1, K-1, mod) k = A[i] * t % mod # print(A[i], t, k) sum = ( sum + k ) % mod sum = -sum for i in range(N-K+1): t = cmb( N-i-1, K-1, mod) k = R[i] * t % mod # print(R[i], t, k) sum = ( sum + k ) % mod print(sum)
mod = 10 ** 9 + 7 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 fact = [1, 1] # fact[n] = (n! mod p) factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p) inv = [0, 1] # factinv 計算用 p = mod for i in range(2, 10**5 + 1): fact.append((fact[-1] * i) % p) inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1] * inv[-1]) % p) N, K = list(map(int, input().split())) A = sorted(map(int, input().split())) R = sorted(A, reverse=True) ans = 0 for i in range(N-K+1): t = cmb( N-i-1, K-1, mod) mi = A[i] * t % mod ma = A[N-(i+1)] * t % mod ans = ( ans + ma - mi ) % mod print(ans)
52
30
1,050
736
import numpy as np mod = 10**9 + 7 def f(n, k): ans = 1 for i in range(k): ans = ans * n % mod n -= 1 return ans 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 fact = [1, 1] # fact[n] = (n! mod p) factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p) inv = [0, 1] # factinv 計算用 p = mod for i in range(2, 10**5 + 1): fact.append((fact[-1] * i) % p) inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1] * inv[-1]) % p) # print( cmb(4, 2, mod) ) N, K = list(map(int, input().split())) A = sorted(map(int, input().split())) R = sorted(A, reverse=True) sum = 0 for i in range(N - K + 1): t = cmb(N - i - 1, K - 1, mod) k = A[i] * t % mod # print(A[i], t, k) sum = (sum + k) % mod sum = -sum for i in range(N - K + 1): t = cmb(N - i - 1, K - 1, mod) k = R[i] * t % mod # print(R[i], t, k) sum = (sum + k) % mod print(sum)
mod = 10**9 + 7 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 fact = [1, 1] # fact[n] = (n! mod p) factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p) inv = [0, 1] # factinv 計算用 p = mod for i in range(2, 10**5 + 1): fact.append((fact[-1] * i) % p) inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1] * inv[-1]) % p) N, K = list(map(int, input().split())) A = sorted(map(int, input().split())) R = sorted(A, reverse=True) ans = 0 for i in range(N - K + 1): t = cmb(N - i - 1, K - 1, mod) mi = A[i] * t % mod ma = A[N - (i + 1)] * t % mod ans = (ans + ma - mi) % mod print(ans)
false
42.307692
[ "-import numpy as np", "-", "-", "-", "-def f(n, k):", "- ans = 1", "- for i in range(k):", "- ans = ans * n % mod", "- n -= 1", "- return ans", "-# print( cmb(4, 2, mod) )", "-sum = 0", "+ans = 0", "- k = A[i] * t % mod", "- # print(A[i], t, k)", "- sum = (sum + k) % mod", "-sum = -sum", "-for i in range(N - K + 1):", "- t = cmb(N - i - 1, K - 1, mod)", "- k = R[i] * t % mod", "- # print(R[i], t, k)", "- sum = (sum + k) % mod", "-print(sum)", "+ mi = A[i] * t % mod", "+ ma = A[N - (i + 1)] * t % mod", "+ ans = (ans + ma - mi) % mod", "+print(ans)" ]
false
0.259099
0.474725
0.545789
[ "s060135311", "s733429048" ]
u417309772
p04046
python
s169528854
s965975403
1,193
832
16,920
24,808
Accepted
Accepted
30.26
from math import comb h,w,a,b = list(map(int,input().split())) s = 0 nC = b-1 kC = 0 nD = w-b-1+h-1 kD = h-1 p = 1000000007 fac = [1] ff = 1 for i in range(1,200001): ff *= i ff %= p fac.append(ff) def ncr(n, r, p): return (fac[n] * pow(fac[r], p-2, p) % p * pow(fac[n-r], p-2, p) % p); for i in range(h-a): C = ncr(nC, kC, 1000000007) D = ncr(nD, kD, 1000000007) s = (s + C * D) % 1000000007 nC += 1 kC += 1 kD -= 1 nD -= 1 print(s)
P = 10**9+7 fac = [1] ifac = [1] ff = 1 for i in range(1,200001): ff *= i ff %= P fac.append(ff) ifac.append(pow(ff, P-2, P)) def ncr(n, r): return (fac[n] * ifac[r] % P * ifac[n-r] % P); h,w,a,b = list(map(int,input().split())) s = 0 nC = b-1 kC = 0 nD = w-b-1+h-1 kD = h-1 for i in range(h-a): C = ncr(nC, kC) D = ncr(nD, kD) s = (s + C * D) % P nC += 1 kC += 1 kD -= 1 nD -= 1 print(s)
26
27
477
435
from math import comb h, w, a, b = list(map(int, input().split())) s = 0 nC = b - 1 kC = 0 nD = w - b - 1 + h - 1 kD = h - 1 p = 1000000007 fac = [1] ff = 1 for i in range(1, 200001): ff *= i ff %= p fac.append(ff) def ncr(n, r, p): return fac[n] * pow(fac[r], p - 2, p) % p * pow(fac[n - r], p - 2, p) % p for i in range(h - a): C = ncr(nC, kC, 1000000007) D = ncr(nD, kD, 1000000007) s = (s + C * D) % 1000000007 nC += 1 kC += 1 kD -= 1 nD -= 1 print(s)
P = 10**9 + 7 fac = [1] ifac = [1] ff = 1 for i in range(1, 200001): ff *= i ff %= P fac.append(ff) ifac.append(pow(ff, P - 2, P)) def ncr(n, r): return fac[n] * ifac[r] % P * ifac[n - r] % P h, w, a, b = list(map(int, input().split())) s = 0 nC = b - 1 kC = 0 nD = w - b - 1 + h - 1 kD = h - 1 for i in range(h - a): C = ncr(nC, kC) D = ncr(nD, kD) s = (s + C * D) % P nC += 1 kC += 1 kD -= 1 nD -= 1 print(s)
false
3.703704
[ "-from math import comb", "+P = 10**9 + 7", "+fac = [1]", "+ifac = [1]", "+ff = 1", "+for i in range(1, 200001):", "+ ff *= i", "+ ff %= P", "+ fac.append(ff)", "+ ifac.append(pow(ff, P - 2, P))", "+", "+", "+def ncr(n, r):", "+ return fac[n] * ifac[r] % P * ifac[n - r] % P", "+", "-p = 1000000007", "-fac = [1]", "-ff = 1", "-for i in range(1, 200001):", "- ff *= i", "- ff %= p", "- fac.append(ff)", "-", "-", "-def ncr(n, r, p):", "- return fac[n] * pow(fac[r], p - 2, p) % p * pow(fac[n - r], p - 2, p) % p", "-", "-", "- C = ncr(nC, kC, 1000000007)", "- D = ncr(nD, kD, 1000000007)", "- s = (s + C * D) % 1000000007", "+ C = ncr(nC, kC)", "+ D = ncr(nD, kD)", "+ s = (s + C * D) % P" ]
false
0.007911
1.558434
0.005076
[ "s169528854", "s965975403" ]
u729133443
p03035
python
s388332559
s309252970
181
29
38,256
8,972
Accepted
Accepted
83.98
a,b=list(map(int,input().split()));print((b//-~(a<13)*(a>5)))
a,b=list(map(int,input().split())) print(((b>>(a<13))*(a>5)))
1
2
53
54
a, b = list(map(int, input().split())) print((b // -~(a < 13) * (a > 5)))
a, b = list(map(int, input().split())) print(((b >> (a < 13)) * (a > 5)))
false
50
[ "-print((b // -~(a < 13) * (a > 5)))", "+print(((b >> (a < 13)) * (a > 5)))" ]
false
0.05417
0.047208
1.147475
[ "s388332559", "s309252970" ]
u261103969
p02792
python
s235917707
s030970033
301
91
3,064
73,660
Accepted
Accepted
69.77
n = int(eval(input())) dp = [[0] * 10 for _ in range(10)] ans = 0 for i in range(1, n+1): top = int(str(i)[0]) end = int(str(i)[-1]) ans += 2 * dp[end][top] if top == end: ans += 1 dp[top][end] += 1 print(ans)
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): N = int(readline()) dp = [[0] * 10 for _ in range(10)] ans = 0 for i in range(1, N + 1): s = str(i) first = int(s[0]) second = int(s[-1]) ans += 2 * dp[second][first] if first == second: ans += 1 dp[first][second] += 1 print(ans) if __name__ == '__main__': main()
13
30
245
508
n = int(eval(input())) dp = [[0] * 10 for _ in range(10)] ans = 0 for i in range(1, n + 1): top = int(str(i)[0]) end = int(str(i)[-1]) ans += 2 * dp[end][top] if top == end: ans += 1 dp[top][end] += 1 print(ans)
import sys readline = sys.stdin.readline MOD = 10**9 + 7 INF = float("INF") sys.setrecursionlimit(10**5) def main(): N = int(readline()) dp = [[0] * 10 for _ in range(10)] ans = 0 for i in range(1, N + 1): s = str(i) first = int(s[0]) second = int(s[-1]) ans += 2 * dp[second][first] if first == second: ans += 1 dp[first][second] += 1 print(ans) if __name__ == "__main__": main()
false
56.666667
[ "-n = int(eval(input()))", "-dp = [[0] * 10 for _ in range(10)]", "-ans = 0", "-for i in range(1, n + 1):", "- top = int(str(i)[0])", "- end = int(str(i)[-1])", "- ans += 2 * dp[end][top]", "- if top == end:", "- ans += 1", "- dp[top][end] += 1", "-print(ans)", "+import sys", "+", "+readline = sys.stdin.readline", "+MOD = 10**9 + 7", "+INF = float(\"INF\")", "+sys.setrecursionlimit(10**5)", "+", "+", "+def main():", "+ N = int(readline())", "+ dp = [[0] * 10 for _ in range(10)]", "+ ans = 0", "+ for i in range(1, N + 1):", "+ s = str(i)", "+ first = int(s[0])", "+ second = int(s[-1])", "+ ans += 2 * dp[second][first]", "+ if first == second:", "+ ans += 1", "+ dp[first][second] += 1", "+ print(ans)", "+", "+", "+if __name__ == \"__main__\":", "+ main()" ]
false
0.083356
0.130096
0.64073
[ "s235917707", "s030970033" ]
u863442865
p02861
python
s083111871
s706666552
209
161
40,048
38,256
Accepted
Accepted
22.97
''' https://atcoder.jp/contests/abc145/tasks/abc145_c ''' def main(): import sys #input = sys.stdin.readline sys.setrecursionlimit(10000000) from collections import Counter, deque #from collections import defaultdict from itertools import combinations, permutations #from itertools import accumulate, product from math import floor, ceil #from operator import itemgetter #mod = 1000000007 N = int(eval(input())) grid = [list(map(int, input().split())) for _ in range(N)] res = 0 for path in permutations(grid, N): for i in range(N-1): res += ((path[i][0]-path[i+1][0])**2 + (path[i][1]-path[i+1][1])**2)**0.5 a = 1 for i in range(2, N+1): a *= i print((res/a)) if __name__ == '__main__': main()
def main(): import sys #input = sys.stdin.readline sys.setrecursionlimit(10000000) from collections import Counter, deque #from collections import defaultdict from itertools import combinations, permutations #from itertools import accumulate, product from math import floor, ceil #from operator import itemgetter #mod = 1000000007 N=int(eval(input())) xy = [list(map(int, input().split())) for _ in range(N)] res=0 for i in range(N): for j in range(N): res += ((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)**0.5 print((res/N)) if __name__ == '__main__': main()
30
23
819
662
""" https://atcoder.jp/contests/abc145/tasks/abc145_c """ def main(): import sys # input = sys.stdin.readline sys.setrecursionlimit(10000000) from collections import Counter, deque # from collections import defaultdict from itertools import combinations, permutations # from itertools import accumulate, product from math import floor, ceil # from operator import itemgetter # mod = 1000000007 N = int(eval(input())) grid = [list(map(int, input().split())) for _ in range(N)] res = 0 for path in permutations(grid, N): for i in range(N - 1): res += ( (path[i][0] - path[i + 1][0]) ** 2 + (path[i][1] - path[i + 1][1]) ** 2 ) ** 0.5 a = 1 for i in range(2, N + 1): a *= i print((res / a)) if __name__ == "__main__": main()
def main(): import sys # input = sys.stdin.readline sys.setrecursionlimit(10000000) from collections import Counter, deque # from collections import defaultdict from itertools import combinations, permutations # from itertools import accumulate, product from math import floor, ceil # from operator import itemgetter # mod = 1000000007 N = int(eval(input())) xy = [list(map(int, input().split())) for _ in range(N)] res = 0 for i in range(N): for j in range(N): res += ((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2) ** 0.5 print((res / N)) if __name__ == "__main__": main()
false
23.333333
[ "-\"\"\"", "-https://atcoder.jp/contests/abc145/tasks/abc145_c", "-\"\"\"", "-", "-", "- grid = [list(map(int, input().split())) for _ in range(N)]", "+ xy = [list(map(int, input().split())) for _ in range(N)]", "- for path in permutations(grid, N):", "- for i in range(N - 1):", "- res += (", "- (path[i][0] - path[i + 1][0]) ** 2 + (path[i][1] - path[i + 1][1]) ** 2", "- ) ** 0.5", "- a = 1", "- for i in range(2, N + 1):", "- a *= i", "- print((res / a))", "+ for i in range(N):", "+ for j in range(N):", "+ res += ((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2) ** 0.5", "+ print((res / N))" ]
false
0.052031
0.051155
1.017119
[ "s083111871", "s706666552" ]
u790710233
p02685
python
s177567087
s880601178
1,394
639
24,656
24,572
Accepted
Accepted
54.16
MOD = 998244353 n, m, k = list(map(int, input().split())) fact = [0]*(n+1) fact[0] = 1 for i in range(1, n+1): fact[i] = fact[i-1]*i % MOD invfact = [0]*(n+1) for i in range(n+1): invfact[i] = pow(fact[i], MOD-2, MOD) def nCk(n, k): return fact[n]*invfact[k]*invfact[n-k] ans = 0 for i in range(k+1): ans += m*pow(m-1, n-1-i, MOD)*nCk(n-1, i) ans %= MOD print(ans)
MOD = 998244353 n, m, k = list(map(int, input().split())) fact = [0]*(n+1) fact[0] = 1 for i in range(1, n+1): fact[i] = fact[i-1]*i % MOD invfact = [0]*(n+1) invfact[n] = pow(fact[n], MOD-2, MOD) for i in reversed(list(range(n))): invfact[i] = invfact[i+1]*(i+1) % MOD def nCk(n, k): return fact[n]*invfact[k]*invfact[n-k] ans = 0 for i in range(k+1): ans += m*pow(m-1, n-1-i, MOD)*nCk(n-1, i) ans %= MOD print(ans)
22
23
406
452
MOD = 998244353 n, m, k = list(map(int, input().split())) fact = [0] * (n + 1) fact[0] = 1 for i in range(1, n + 1): fact[i] = fact[i - 1] * i % MOD invfact = [0] * (n + 1) for i in range(n + 1): invfact[i] = pow(fact[i], MOD - 2, MOD) def nCk(n, k): return fact[n] * invfact[k] * invfact[n - k] ans = 0 for i in range(k + 1): ans += m * pow(m - 1, n - 1 - i, MOD) * nCk(n - 1, i) ans %= MOD print(ans)
MOD = 998244353 n, m, k = list(map(int, input().split())) fact = [0] * (n + 1) fact[0] = 1 for i in range(1, n + 1): fact[i] = fact[i - 1] * i % MOD invfact = [0] * (n + 1) invfact[n] = pow(fact[n], MOD - 2, MOD) for i in reversed(list(range(n))): invfact[i] = invfact[i + 1] * (i + 1) % MOD def nCk(n, k): return fact[n] * invfact[k] * invfact[n - k] ans = 0 for i in range(k + 1): ans += m * pow(m - 1, n - 1 - i, MOD) * nCk(n - 1, i) ans %= MOD print(ans)
false
4.347826
[ "-for i in range(n + 1):", "- invfact[i] = pow(fact[i], MOD - 2, MOD)", "+invfact[n] = pow(fact[n], MOD - 2, MOD)", "+for i in reversed(list(range(n))):", "+ invfact[i] = invfact[i + 1] * (i + 1) % MOD" ]
false
0.13406
0.107361
1.248683
[ "s177567087", "s880601178" ]
u135331079
p02701
python
s849207051
s798802198
319
286
35,236
30,980
Accepted
Accepted
10.34
N = int(eval(input())) D = dict() for i in range(N): S = eval(input()) if S not in list(D.keys()): D[S] = 1 D[S] += 1 print((len(D)))
n = int(eval(input())) s = set() for i in range(n): s.add(eval(input())) print((len(s)))
9
6
142
84
N = int(eval(input())) D = dict() for i in range(N): S = eval(input()) if S not in list(D.keys()): D[S] = 1 D[S] += 1 print((len(D)))
n = int(eval(input())) s = set() for i in range(n): s.add(eval(input())) print((len(s)))
false
33.333333
[ "-N = int(eval(input()))", "-D = dict()", "-for i in range(N):", "- S = eval(input())", "- if S not in list(D.keys()):", "- D[S] = 1", "- D[S] += 1", "-print((len(D)))", "+n = int(eval(input()))", "+s = set()", "+for i in range(n):", "+ s.add(eval(input()))", "+print((len(s)))" ]
false
0.047162
0.049273
0.957156
[ "s849207051", "s798802198" ]
u504588563
p03545
python
s341950902
s721078085
190
17
38,256
3,064
Accepted
Accepted
91.05
s=eval(input()) for i in range(1 << 3): ans="" for j in range(3): ans+=s[j] if (i>>j)& 1: ans+="+" else: ans+="-" ans+=s[-1] if eval(ans+"==7"): print((ans+"=7")) break
s=eval(input()) ans="" import sys for i in range(2**3): tmp=s[0] tmp_sum=(int(s[0])) for j in range(len(s)-1): if (i >> j) & 1: tmp+="+" tmp_sum+=int(s[j+1]) else: tmp+="-" tmp_sum-=int(s[j+1]) tmp+=s[j+1] # print(tmp,tmp_sum) if tmp_sum==7: print((tmp+"=7")) sys.exit()
13
19
252
397
s = eval(input()) for i in range(1 << 3): ans = "" for j in range(3): ans += s[j] if (i >> j) & 1: ans += "+" else: ans += "-" ans += s[-1] if eval(ans + "==7"): print((ans + "=7")) break
s = eval(input()) ans = "" import sys for i in range(2**3): tmp = s[0] tmp_sum = int(s[0]) for j in range(len(s) - 1): if (i >> j) & 1: tmp += "+" tmp_sum += int(s[j + 1]) else: tmp += "-" tmp_sum -= int(s[j + 1]) tmp += s[j + 1] # print(tmp,tmp_sum) if tmp_sum == 7: print((tmp + "=7")) sys.exit()
false
31.578947
[ "-for i in range(1 << 3):", "- ans = \"\"", "- for j in range(3):", "- ans += s[j]", "+ans = \"\"", "+import sys", "+", "+for i in range(2**3):", "+ tmp = s[0]", "+ tmp_sum = int(s[0])", "+ for j in range(len(s) - 1):", "- ans += \"+\"", "+ tmp += \"+\"", "+ tmp_sum += int(s[j + 1])", "- ans += \"-\"", "- ans += s[-1]", "- if eval(ans + \"==7\"):", "- print((ans + \"=7\"))", "- break", "+ tmp += \"-\"", "+ tmp_sum -= int(s[j + 1])", "+ tmp += s[j + 1]", "+ # print(tmp,tmp_sum)", "+ if tmp_sum == 7:", "+ print((tmp + \"=7\"))", "+ sys.exit()" ]
false
0.059245
0.066328
0.893214
[ "s341950902", "s721078085" ]
u788703383
p03834
python
s766947207
s559952451
165
17
38,384
2,940
Accepted
Accepted
89.7
s = eval(input()) l = s.split(',') print((l[0] + ' '+ l[1] + ' ' + l[2]))
print((input().replace(',',' ')))
3
1
68
31
s = eval(input()) l = s.split(",") print((l[0] + " " + l[1] + " " + l[2]))
print((input().replace(",", " ")))
false
66.666667
[ "-s = eval(input())", "-l = s.split(\",\")", "-print((l[0] + \" \" + l[1] + \" \" + l[2]))", "+print((input().replace(\",\", \" \")))" ]
false
0.090354
0.036957
2.444826
[ "s766947207", "s559952451" ]
u375282392
p02923
python
s653909372
s197396006
98
90
14,252
14,252
Accepted
Accepted
8.16
n = int(eval(input())) h = [int(i) for i in input().split()] c = 0 m = 0 for i in range(n-1): if h[i] >= h[i+1]: if i == n - 1: c += 2 else: c += 1 m = max(c,m) else: c = 0 print(m)
n = int(eval(input())) h = [int(i) for i in input().split()] c = 0 m = 0 for i in range(n-1): if h[i] >= h[i+1]: c += 1 m = max(c,m) else: c = 0 print(m)
14
11
204
165
n = int(eval(input())) h = [int(i) for i in input().split()] c = 0 m = 0 for i in range(n - 1): if h[i] >= h[i + 1]: if i == n - 1: c += 2 else: c += 1 m = max(c, m) else: c = 0 print(m)
n = int(eval(input())) h = [int(i) for i in input().split()] c = 0 m = 0 for i in range(n - 1): if h[i] >= h[i + 1]: c += 1 m = max(c, m) else: c = 0 print(m)
false
21.428571
[ "- if i == n - 1:", "- c += 2", "- else:", "- c += 1", "+ c += 1" ]
false
0.046954
0.094581
0.496448
[ "s653909372", "s197396006" ]
u104171359
p02401
python
s923959398
s501686218
30
10
7,876
7,780
Accepted
Accepted
66.67
#!usr/bin/env python3 import sys import operator from math import floor def string_to_list_spliter(): lst = [int(i) if isinstance(i, int) == True else i for i in sys.stdin.readline().split()] return lst def main(): ops = {'+': operator.add, '-': operator.sub, '*': operator.mul, '/': operator.truediv} while True: lst = string_to_list_spliter() if lst[1] == '?': break elif lst[1] == '+': print((ops[lst[1]](int(lst[0]), int(lst[2])))) elif lst[1] == '-': print((ops[lst[1]](int(lst[0]), int(lst[2])))) elif lst[1] == '*': print((ops[lst[1]](int(lst[0]), int(lst[2])))) elif lst[1] == '/': print((floor(ops[lst[1]](int(lst[0]), int(lst[2]))))) if __name__ == '__main__': main()
#!usr/bin/env python3 import sys import operator from math import floor def string_to_list_spliter(): lst = [i for i in sys.stdin.readline().split()] return lst def main(): ops = {'+': operator.add, '-': operator.sub, '*': operator.mul, '/': operator.truediv} # TODO Refactor the ugly code below into the function above. while True: lst = string_to_list_spliter() if lst[1] == '?': break elif lst[1] == '+': print((ops[lst[1]](int(lst[0]), int(lst[2])))) elif lst[1] == '-': print((ops[lst[1]](int(lst[0]), int(lst[2])))) elif lst[1] == '*': print((ops[lst[1]](int(lst[0]), int(lst[2])))) elif lst[1] == '/': print((floor(ops[lst[1]](int(lst[0]), int(lst[2]))))) if __name__ == '__main__': main()
31
32
835
859
#!usr/bin/env python3 import sys import operator from math import floor def string_to_list_spliter(): lst = [ int(i) if isinstance(i, int) == True else i for i in sys.stdin.readline().split() ] return lst def main(): ops = { "+": operator.add, "-": operator.sub, "*": operator.mul, "/": operator.truediv, } while True: lst = string_to_list_spliter() if lst[1] == "?": break elif lst[1] == "+": print((ops[lst[1]](int(lst[0]), int(lst[2])))) elif lst[1] == "-": print((ops[lst[1]](int(lst[0]), int(lst[2])))) elif lst[1] == "*": print((ops[lst[1]](int(lst[0]), int(lst[2])))) elif lst[1] == "/": print((floor(ops[lst[1]](int(lst[0]), int(lst[2]))))) if __name__ == "__main__": main()
#!usr/bin/env python3 import sys import operator from math import floor def string_to_list_spliter(): lst = [i for i in sys.stdin.readline().split()] return lst def main(): ops = { "+": operator.add, "-": operator.sub, "*": operator.mul, "/": operator.truediv, } # TODO Refactor the ugly code below into the function above. while True: lst = string_to_list_spliter() if lst[1] == "?": break elif lst[1] == "+": print((ops[lst[1]](int(lst[0]), int(lst[2])))) elif lst[1] == "-": print((ops[lst[1]](int(lst[0]), int(lst[2])))) elif lst[1] == "*": print((ops[lst[1]](int(lst[0]), int(lst[2])))) elif lst[1] == "/": print((floor(ops[lst[1]](int(lst[0]), int(lst[2]))))) if __name__ == "__main__": main()
false
3.125
[ "- lst = [", "- int(i) if isinstance(i, int) == True else i", "- for i in sys.stdin.readline().split()", "- ]", "+ lst = [i for i in sys.stdin.readline().split()]", "+ # TODO Refactor the ugly code below into the function above." ]
false
0.037598
0.038094
0.986981
[ "s923959398", "s501686218" ]
u620084012
p02972
python
s961922859
s804003229
1,016
162
71,132
98,948
Accepted
Accepted
84.06
import math N = int(eval(input())) a = list(map(int,input().split())) b = [0]*N ans = [] for k in range(N,0,-1): if a[k-1]%2 != b[k-1]%2: ans.append(k) b[0] += 1 b[k-1] += 1 for l in range(2,math.floor(math.sqrt(k))+1): if k % l == 0: if l*l == k: b[l-1] += 1 else: b[l-1] += 1 b[k//l-1] += 1 print((len(ans))) if len(ans) > 0: print((*ans))
N = int(eval(input())) a = [0] + list(map(int,input().split())) ans = [0]*(N+1) for k in range(N,0,-1): temp = 0 l = k while l <= N: temp += ans[l] l += k if a[k] == 1 and temp%2 == 0: ans[k] = 1 elif a[k] == 0 and temp%2 == 1: ans[k] = 1 b = [] for k in range(1,N+1): if ans[k] == 1: b.append(k) print((len(b))) print((*b))
20
19
495
397
import math N = int(eval(input())) a = list(map(int, input().split())) b = [0] * N ans = [] for k in range(N, 0, -1): if a[k - 1] % 2 != b[k - 1] % 2: ans.append(k) b[0] += 1 b[k - 1] += 1 for l in range(2, math.floor(math.sqrt(k)) + 1): if k % l == 0: if l * l == k: b[l - 1] += 1 else: b[l - 1] += 1 b[k // l - 1] += 1 print((len(ans))) if len(ans) > 0: print((*ans))
N = int(eval(input())) a = [0] + list(map(int, input().split())) ans = [0] * (N + 1) for k in range(N, 0, -1): temp = 0 l = k while l <= N: temp += ans[l] l += k if a[k] == 1 and temp % 2 == 0: ans[k] = 1 elif a[k] == 0 and temp % 2 == 1: ans[k] = 1 b = [] for k in range(1, N + 1): if ans[k] == 1: b.append(k) print((len(b))) print((*b))
false
5
[ "-import math", "-", "-a = list(map(int, input().split()))", "-b = [0] * N", "-ans = []", "+a = [0] + list(map(int, input().split()))", "+ans = [0] * (N + 1)", "- if a[k - 1] % 2 != b[k - 1] % 2:", "- ans.append(k)", "- b[0] += 1", "- b[k - 1] += 1", "- for l in range(2, math.floor(math.sqrt(k)) + 1):", "- if k % l == 0:", "- if l * l == k:", "- b[l - 1] += 1", "- else:", "- b[l - 1] += 1", "- b[k // l - 1] += 1", "-print((len(ans)))", "-if len(ans) > 0:", "- print((*ans))", "+ temp = 0", "+ l = k", "+ while l <= N:", "+ temp += ans[l]", "+ l += k", "+ if a[k] == 1 and temp % 2 == 0:", "+ ans[k] = 1", "+ elif a[k] == 0 and temp % 2 == 1:", "+ ans[k] = 1", "+b = []", "+for k in range(1, N + 1):", "+ if ans[k] == 1:", "+ b.append(k)", "+print((len(b)))", "+print((*b))" ]
false
0.083178
0.076189
1.091737
[ "s961922859", "s804003229" ]
u991567869
p03680
python
s865892160
s984602792
216
75
7,852
7,852
Accepted
Accepted
65.28
n = int(eval(input())) a = [] l = [0]*(n + 1) cnt = 0 now = 1 for i in range(n): a.append(int(eval(input()))) for i in range(n): cnt += 1 now = a[now - 1] if now == 2: print(cnt) exit() print((-1))
import sys input = sys.stdin.readline def main(): n = int(eval(input())) a = [] l = [0]*(n + 1) cnt = 0 now = 1 for i in range(n): a.append(int(eval(input()))) for i in range(n): cnt += 1 now = a[now - 1] if now == 2: print(cnt) exit() print((-1)) main()
17
22
234
353
n = int(eval(input())) a = [] l = [0] * (n + 1) cnt = 0 now = 1 for i in range(n): a.append(int(eval(input()))) for i in range(n): cnt += 1 now = a[now - 1] if now == 2: print(cnt) exit() print((-1))
import sys input = sys.stdin.readline def main(): n = int(eval(input())) a = [] l = [0] * (n + 1) cnt = 0 now = 1 for i in range(n): a.append(int(eval(input()))) for i in range(n): cnt += 1 now = a[now - 1] if now == 2: print(cnt) exit() print((-1)) main()
false
22.727273
[ "-n = int(eval(input()))", "-a = []", "-l = [0] * (n + 1)", "-cnt = 0", "-now = 1", "-for i in range(n):", "- a.append(int(eval(input())))", "-for i in range(n):", "- cnt += 1", "- now = a[now - 1]", "- if now == 2:", "- print(cnt)", "- exit()", "-print((-1))", "+import sys", "+", "+input = sys.stdin.readline", "+", "+", "+def main():", "+ n = int(eval(input()))", "+ a = []", "+ l = [0] * (n + 1)", "+ cnt = 0", "+ now = 1", "+ for i in range(n):", "+ a.append(int(eval(input())))", "+ for i in range(n):", "+ cnt += 1", "+ now = a[now - 1]", "+ if now == 2:", "+ print(cnt)", "+ exit()", "+ print((-1))", "+", "+", "+main()" ]
false
0.03668
0.037578
0.976119
[ "s865892160", "s984602792" ]
u168489836
p03478
python
s473045928
s946260354
36
32
2,940
2,940
Accepted
Accepted
11.11
n, a, b = [int(x) for x in input().split()] count = 0 for i in range(a, n+1): if a <= sum([int(x) for x in list(str(i))]) <= b: count += i print(count)
n, a, b = [int(x) for x in input().split()] idx = 0 for i in range(1, n+1): if a <= sum([int(x) for x in str(i)]) <= b: idx += i print(idx)
6
6
168
156
n, a, b = [int(x) for x in input().split()] count = 0 for i in range(a, n + 1): if a <= sum([int(x) for x in list(str(i))]) <= b: count += i print(count)
n, a, b = [int(x) for x in input().split()] idx = 0 for i in range(1, n + 1): if a <= sum([int(x) for x in str(i)]) <= b: idx += i print(idx)
false
0
[ "-count = 0", "-for i in range(a, n + 1):", "- if a <= sum([int(x) for x in list(str(i))]) <= b:", "- count += i", "-print(count)", "+idx = 0", "+for i in range(1, n + 1):", "+ if a <= sum([int(x) for x in str(i)]) <= b:", "+ idx += i", "+print(idx)" ]
false
0.038416
0.047598
0.807089
[ "s473045928", "s946260354" ]
u072053884
p02244
python
s941843568
s784026074
30
20
7,872
5,616
Accepted
Accepted
33.33
row = [True] * 8 col = [True] * 8 dpos = [True] * 15 dneg = [True] * 15 board = [['.', '.', '.', '.', '.', '.', '.', '.'] for i in range(8)] import sys file_input = sys.stdin k = int(file_input.readline()) for line in file_input: r, c = map(int, line.split()) row[r] = "INIT" col[c] = "INIT" dpos[r + c] = False dneg[r + (7 - c)] = False board[r][c] = 'Q' def dfs(i = 0): if i == 8: for line in board: print(*line, sep='') return if row[i] == "INIT": dfs(i + 1) elif row[i]: for j in range(8): if col[j] == "INIT": pass elif col[j] and dpos[i + j] and dneg[i + (7 - j)]: row[i] = False col[j] = False dpos[i + j] = False dneg[i + (7 - j)] = False board[i][j] = 'Q' dfs(i + 1) row[i] = True col[j] = True dpos[i + j] = True dneg[i + (7 - j)] = True board[i][j] = '.' dfs()
row = [False] * 8 col = [False] * 8 dpos = [False] * 15 dneg = [False] * 15 board = [['.', '.', '.', '.', '.', '.', '.', '.'] for i in range(8)] import sys file_input = sys.stdin k = int(file_input.readline()) for line in file_input: r, c = list(map(int, line.split())) row[r] = True col[c] = True dpos[r + c] = True dneg[r - c + 7] = True board[r][c] = 'Q' def dfs(i = 0): if i == 8: for line in board: print((''.join(line))) elif row[i]: dfs(i + 1) else: for j in range(8): if col[j] or dpos[i + j] or dneg[i - j + 7]: continue row[i] = True col[j] = True dpos[i + j] = True dneg[i - j + 7] = True board[i][j] = 'Q' dfs(i + 1) row[i] = False col[j] = False dpos[i + j] = False dneg[i - j + 7] = False board[i][j] = '.' dfs()
47
45
1,121
1,003
row = [True] * 8 col = [True] * 8 dpos = [True] * 15 dneg = [True] * 15 board = [[".", ".", ".", ".", ".", ".", ".", "."] for i in range(8)] import sys file_input = sys.stdin k = int(file_input.readline()) for line in file_input: r, c = map(int, line.split()) row[r] = "INIT" col[c] = "INIT" dpos[r + c] = False dneg[r + (7 - c)] = False board[r][c] = "Q" def dfs(i=0): if i == 8: for line in board: print(*line, sep="") return if row[i] == "INIT": dfs(i + 1) elif row[i]: for j in range(8): if col[j] == "INIT": pass elif col[j] and dpos[i + j] and dneg[i + (7 - j)]: row[i] = False col[j] = False dpos[i + j] = False dneg[i + (7 - j)] = False board[i][j] = "Q" dfs(i + 1) row[i] = True col[j] = True dpos[i + j] = True dneg[i + (7 - j)] = True board[i][j] = "." dfs()
row = [False] * 8 col = [False] * 8 dpos = [False] * 15 dneg = [False] * 15 board = [[".", ".", ".", ".", ".", ".", ".", "."] for i in range(8)] import sys file_input = sys.stdin k = int(file_input.readline()) for line in file_input: r, c = list(map(int, line.split())) row[r] = True col[c] = True dpos[r + c] = True dneg[r - c + 7] = True board[r][c] = "Q" def dfs(i=0): if i == 8: for line in board: print(("".join(line))) elif row[i]: dfs(i + 1) else: for j in range(8): if col[j] or dpos[i + j] or dneg[i - j + 7]: continue row[i] = True col[j] = True dpos[i + j] = True dneg[i - j + 7] = True board[i][j] = "Q" dfs(i + 1) row[i] = False col[j] = False dpos[i + j] = False dneg[i - j + 7] = False board[i][j] = "." dfs()
false
4.255319
[ "-row = [True] * 8", "-col = [True] * 8", "-dpos = [True] * 15", "-dneg = [True] * 15", "+row = [False] * 8", "+col = [False] * 8", "+dpos = [False] * 15", "+dneg = [False] * 15", "- r, c = map(int, line.split())", "- row[r] = \"INIT\"", "- col[c] = \"INIT\"", "- dpos[r + c] = False", "- dneg[r + (7 - c)] = False", "+ r, c = list(map(int, line.split()))", "+ row[r] = True", "+ col[c] = True", "+ dpos[r + c] = True", "+ dneg[r - c + 7] = True", "- print(*line, sep=\"\")", "- return", "- if row[i] == \"INIT\":", "+ print((\"\".join(line)))", "+ elif row[i]:", "- elif row[i]:", "+ else:", "- if col[j] == \"INIT\":", "- pass", "- elif col[j] and dpos[i + j] and dneg[i + (7 - j)]:", "- row[i] = False", "- col[j] = False", "- dpos[i + j] = False", "- dneg[i + (7 - j)] = False", "- board[i][j] = \"Q\"", "- dfs(i + 1)", "- row[i] = True", "- col[j] = True", "- dpos[i + j] = True", "- dneg[i + (7 - j)] = True", "- board[i][j] = \".\"", "+ if col[j] or dpos[i + j] or dneg[i - j + 7]:", "+ continue", "+ row[i] = True", "+ col[j] = True", "+ dpos[i + j] = True", "+ dneg[i - j + 7] = True", "+ board[i][j] = \"Q\"", "+ dfs(i + 1)", "+ row[i] = False", "+ col[j] = False", "+ dpos[i + j] = False", "+ dneg[i - j + 7] = False", "+ board[i][j] = \".\"" ]
false
0.044388
0.04476
0.991705
[ "s941843568", "s784026074" ]
u852690916
p02824
python
s302608400
s010078255
304
250
119,488
62,704
Accepted
Accepted
17.76
N,M,V,P=list(map(int, input().split())) *A,=list(map(int, input().split())) A.sort() Ax = A[-P] #上位Pの中の最下位 def f(i): mine = A[i] + M #自分に全力で投票 if mine < Ax: return False #逆転不能 votes = M*V votes -= M #自分への票 votes -= min(P-1, V) * M #上位陣のx以外に全力で投票 votes -= sum([min(mine - A[j], M) for j in range(N-P+1) if i!=j]) #逆転されない程度に下位陣に投票 if votes > 0 : return False #再逆転される return True under = -1 r = N-P while r-under>1: m = (r+under)//2 if f(m): r=m else: under=m print((N-r))
N,M,V,P=list(map(int, input().split())) *A,=list(map(int, input().split())) A.sort() #A[x]の問題が採用される可能性があるか? def check(x): r = A[-P] #無投票でギリギリ採用される問題のスコア if A[x] + M < r: return False votes = M*V votes -= M # A[x]に投票 votes -= M*(P-1) #上位の問題に投票 votes -= M*x #下位の問題に投票 #微妙な問題にギリギリ投票 for i in range(x+1, N-P+1): votes -= A[x]+M - A[i] return votes <= 0 l,r=-1,N-1 while r-l>1: m=(l+r)//2 if check(m): r=m else: l=m print((N-r))
24
27
528
519
N, M, V, P = list(map(int, input().split())) (*A,) = list(map(int, input().split())) A.sort() Ax = A[-P] # 上位Pの中の最下位 def f(i): mine = A[i] + M # 自分に全力で投票 if mine < Ax: return False # 逆転不能 votes = M * V votes -= M # 自分への票 votes -= min(P - 1, V) * M # 上位陣のx以外に全力で投票 votes -= sum( [min(mine - A[j], M) for j in range(N - P + 1) if i != j] ) # 逆転されない程度に下位陣に投票 if votes > 0: return False # 再逆転される return True under = -1 r = N - P while r - under > 1: m = (r + under) // 2 if f(m): r = m else: under = m print((N - r))
N, M, V, P = list(map(int, input().split())) (*A,) = list(map(int, input().split())) A.sort() # A[x]の問題が採用される可能性があるか? def check(x): r = A[-P] # 無投票でギリギリ採用される問題のスコア if A[x] + M < r: return False votes = M * V votes -= M # A[x]に投票 votes -= M * (P - 1) # 上位の問題に投票 votes -= M * x # 下位の問題に投票 # 微妙な問題にギリギリ投票 for i in range(x + 1, N - P + 1): votes -= A[x] + M - A[i] return votes <= 0 l, r = -1, N - 1 while r - l > 1: m = (l + r) // 2 if check(m): r = m else: l = m print((N - r))
false
11.111111
[ "-Ax = A[-P] # 上位Pの中の最下位", "+# A[x]の問題が採用される可能性があるか?", "+def check(x):", "+ r = A[-P] # 無投票でギリギリ採用される問題のスコア", "+ if A[x] + M < r:", "+ return False", "+ votes = M * V", "+ votes -= M # A[x]に投票", "+ votes -= M * (P - 1) # 上位の問題に投票", "+ votes -= M * x # 下位の問題に投票", "+ # 微妙な問題にギリギリ投票", "+ for i in range(x + 1, N - P + 1):", "+ votes -= A[x] + M - A[i]", "+ return votes <= 0", "-def f(i):", "- mine = A[i] + M # 自分に全力で投票", "- if mine < Ax:", "- return False # 逆転不能", "- votes = M * V", "- votes -= M # 自分への票", "- votes -= min(P - 1, V) * M # 上位陣のx以外に全力で投票", "- votes -= sum(", "- [min(mine - A[j], M) for j in range(N - P + 1) if i != j]", "- ) # 逆転されない程度に下位陣に投票", "- if votes > 0:", "- return False # 再逆転される", "- return True", "-", "-", "-under = -1", "-r = N - P", "-while r - under > 1:", "- m = (r + under) // 2", "- if f(m):", "+l, r = -1, N - 1", "+while r - l > 1:", "+ m = (l + r) // 2", "+ if check(m):", "- under = m", "+ l = m" ]
false
0.074347
0.040881
1.818592
[ "s302608400", "s010078255" ]
u644907318
p03043
python
s638908020
s753910547
88
65
73,868
65,312
Accepted
Accepted
26.14
def f(n): k = 0 while n*2**k<K: k += 1 return k N,K = list(map(int,input().split())) if K<=N: P = (N-K+1)/N for i in range(1,K): P += 2**(-f(i))/N else: P = 0 for i in range(1,N+1): P += 2**(-f(i))/N print(P)
import math N,K = list(map(int,input().split())) P = max((N-K+1)/N,0) cnt = 0 for k in range(1,min(N,K-1)+1): cnt += 2**(-math.ceil(math.log2(K/k))) cnt = cnt/N P += cnt print(P)
15
9
268
184
def f(n): k = 0 while n * 2**k < K: k += 1 return k N, K = list(map(int, input().split())) if K <= N: P = (N - K + 1) / N for i in range(1, K): P += 2 ** (-f(i)) / N else: P = 0 for i in range(1, N + 1): P += 2 ** (-f(i)) / N print(P)
import math N, K = list(map(int, input().split())) P = max((N - K + 1) / N, 0) cnt = 0 for k in range(1, min(N, K - 1) + 1): cnt += 2 ** (-math.ceil(math.log2(K / k))) cnt = cnt / N P += cnt print(P)
false
40
[ "-def f(n):", "- k = 0", "- while n * 2**k < K:", "- k += 1", "- return k", "-", "+import math", "-if K <= N:", "- P = (N - K + 1) / N", "- for i in range(1, K):", "- P += 2 ** (-f(i)) / N", "-else:", "- P = 0", "- for i in range(1, N + 1):", "- P += 2 ** (-f(i)) / N", "+P = max((N - K + 1) / N, 0)", "+cnt = 0", "+for k in range(1, min(N, K - 1) + 1):", "+ cnt += 2 ** (-math.ceil(math.log2(K / k)))", "+cnt = cnt / N", "+P += cnt" ]
false
0.035245
0.088661
0.397521
[ "s638908020", "s753910547" ]
u520276780
p04020
python
s944432568
s410607840
571
520
52,184
50,776
Accepted
Accepted
8.93
#貪欲の手順がおかしかった #同一ペアを組むのはそれ以下の数を除いた後 #editorial参照、さらに単純に0で区切ってn//2になる n = int(eval(input())) a = [] for _ in range(n): a_ = int(eval(input())) a.append(a_) #print(a) ans = 0 """ for i in range(n-1): if a[i]&1: ans += a[i]//2 a[i] = 1 elif a[i] ==0: pass else: ans += a[i]//2-1 a[i] = 2 print(a) print(ans) """ for i in range(n-1): ans += a[i]//2 a[i] -= (a[i]//2)*2 ad = min(a[i],a[i+1]) ans += ad a[i+1] -= ad ##この時点で最後まだ残っている ans += a[n-1]//2 print(ans)
#旧版のa[n-1]分を訂正してテスト n = int(eval(input())) a = [] for _ in range(n): a_ = int(eval(input())) a.append(a_) ans = 0 for i in range(n-1): if a[i]&1: ans += a[i]//2 a[i] = 1 elif a[i] ==0: pass else: ans += a[i]//2-1 a[i] = 2 for i in range(n-1): if a[i] == 2: ans += 1 a[i] = 0 else: ad = min(a[i],a[i+1]) ans += ad a[i+1] -= ad ans += a[n-1]//2 print(ans)
32
29
553
481
# 貪欲の手順がおかしかった # 同一ペアを組むのはそれ以下の数を除いた後 # editorial参照、さらに単純に0で区切ってn//2になる n = int(eval(input())) a = [] for _ in range(n): a_ = int(eval(input())) a.append(a_) # print(a) ans = 0 """ for i in range(n-1): if a[i]&1: ans += a[i]//2 a[i] = 1 elif a[i] ==0: pass else: ans += a[i]//2-1 a[i] = 2 print(a) print(ans) """ for i in range(n - 1): ans += a[i] // 2 a[i] -= (a[i] // 2) * 2 ad = min(a[i], a[i + 1]) ans += ad a[i + 1] -= ad ##この時点で最後まだ残っている ans += a[n - 1] // 2 print(ans)
# 旧版のa[n-1]分を訂正してテスト n = int(eval(input())) a = [] for _ in range(n): a_ = int(eval(input())) a.append(a_) ans = 0 for i in range(n - 1): if a[i] & 1: ans += a[i] // 2 a[i] = 1 elif a[i] == 0: pass else: ans += a[i] // 2 - 1 a[i] = 2 for i in range(n - 1): if a[i] == 2: ans += 1 a[i] = 0 else: ad = min(a[i], a[i + 1]) ans += ad a[i + 1] -= ad ans += a[n - 1] // 2 print(ans)
false
9.375
[ "-# 貪欲の手順がおかしかった", "-# 同一ペアを組むのはそれ以下の数を除いた後", "-# editorial参照、さらに単純に0で区切ってn//2になる", "+# 旧版のa[n-1]分を訂正してテスト", "-# print(a)", "-\"\"\"", "-for i in range(n-1):", "- if a[i]&1:", "- ans += a[i]//2", "+for i in range(n - 1):", "+ if a[i] & 1:", "+ ans += a[i] // 2", "- elif a[i] ==0:", "+ elif a[i] == 0:", "- ans += a[i]//2-1", "+ ans += a[i] // 2 - 1", "-print(a)", "-print(ans)", "-\"\"\"", "- ans += a[i] // 2", "- a[i] -= (a[i] // 2) * 2", "- ad = min(a[i], a[i + 1])", "- ans += ad", "- a[i + 1] -= ad", "-##この時点で最後まだ残っている", "+ if a[i] == 2:", "+ ans += 1", "+ a[i] = 0", "+ else:", "+ ad = min(a[i], a[i + 1])", "+ ans += ad", "+ a[i + 1] -= ad" ]
false
0.037961
0.039377
0.964018
[ "s944432568", "s410607840" ]
u145950990
p03503
python
s106336528
s908876909
244
221
43,632
42,092
Accepted
Accepted
9.43
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**9 def bfs(x): if len(x) == 10: if 1 in x: global ans a = 0 for i in range(n): f,p = F[i],P[i] c = 0 for j in range(10): if x[j] == f[j] == 1: c+=1 a+=p[c] ans = max(ans,a) else: bfs(x + [0]) bfs(x + [1]) bfs([]) print(ans)
import itertools n = int(eval(input())) f = [list(map(int,input().split())) for _ in range(n)] p = [list(map(int,input().split())) for _ in range(n)] data = list(itertools.product(list(range(2)), repeat = 10))[1:] ans = -10**9 for d in data: a = 0 for i in range(n): c = 0 for j in range(10): if f[i][j] and d[j]: c+=1 a+=p[i][c] ans = max(ans,a) print(ans)
21
15
544
408
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**9) def bfs(x): if len(x) == 10: if 1 in x: global ans a = 0 for i in range(n): f, p = F[i], P[i] c = 0 for j in range(10): if x[j] == f[j] == 1: c += 1 a += p[c] ans = max(ans, a) else: bfs(x + [0]) bfs(x + [1]) bfs([]) print(ans)
import itertools n = int(eval(input())) f = [list(map(int, input().split())) for _ in range(n)] p = [list(map(int, input().split())) for _ in range(n)] data = list(itertools.product(list(range(2)), repeat=10))[1:] ans = -(10**9) for d in data: a = 0 for i in range(n): c = 0 for j in range(10): if f[i][j] and d[j]: c += 1 a += p[i][c] ans = max(ans, a) print(ans)
false
28.571429
[ "+import itertools", "+", "-F = [list(map(int, input().split())) for _ in range(n)]", "-P = [list(map(int, input().split())) for _ in range(n)]", "+f = [list(map(int, input().split())) for _ in range(n)]", "+p = [list(map(int, input().split())) for _ in range(n)]", "+data = list(itertools.product(list(range(2)), repeat=10))[1:]", "-", "-", "-def bfs(x):", "- if len(x) == 10:", "- if 1 in x:", "- global ans", "- a = 0", "- for i in range(n):", "- f, p = F[i], P[i]", "- c = 0", "- for j in range(10):", "- if x[j] == f[j] == 1:", "- c += 1", "- a += p[c]", "- ans = max(ans, a)", "- else:", "- bfs(x + [0])", "- bfs(x + [1])", "-", "-", "-bfs([])", "+for d in data:", "+ a = 0", "+ for i in range(n):", "+ c = 0", "+ for j in range(10):", "+ if f[i][j] and d[j]:", "+ c += 1", "+ a += p[i][c]", "+ ans = max(ans, a)" ]
false
0.04867
0.072096
0.675076
[ "s106336528", "s908876909" ]
u394721319
p03495
python
s832111962
s172035818
420
194
25,732
39,296
Accepted
Accepted
53.81
import bisect N,K = [int(zz) for zz in input().split()] A = [int(zz) for zz in input().split()] B = set(A) A.sort() ans = [] for i in B: p = bisect.bisect_right(A, i) - bisect.bisect_left(A, i) ans.append(p) ans.sort() j = 0 for i in range(len(B)-K): j += ans[i] print(j)
from collections import Counter N,K = [int(zz) for zz in input().split()] A = [int(zz) for zz in input().split()] tmp = Counter(A).most_common()[::-1] ans = 0 for i in range(len(tmp)-K): ans += tmp[i][1] print(ans)
17
11
303
232
import bisect N, K = [int(zz) for zz in input().split()] A = [int(zz) for zz in input().split()] B = set(A) A.sort() ans = [] for i in B: p = bisect.bisect_right(A, i) - bisect.bisect_left(A, i) ans.append(p) ans.sort() j = 0 for i in range(len(B) - K): j += ans[i] print(j)
from collections import Counter N, K = [int(zz) for zz in input().split()] A = [int(zz) for zz in input().split()] tmp = Counter(A).most_common()[::-1] ans = 0 for i in range(len(tmp) - K): ans += tmp[i][1] print(ans)
false
35.294118
[ "-import bisect", "+from collections import Counter", "-B = set(A)", "-A.sort()", "-ans = []", "-for i in B:", "- p = bisect.bisect_right(A, i) - bisect.bisect_left(A, i)", "- ans.append(p)", "-ans.sort()", "-j = 0", "-for i in range(len(B) - K):", "- j += ans[i]", "-print(j)", "+tmp = Counter(A).most_common()[::-1]", "+ans = 0", "+for i in range(len(tmp) - K):", "+ ans += tmp[i][1]", "+print(ans)" ]
false
0.05915
0.079738
0.741802
[ "s832111962", "s172035818" ]
u077291787
p02558
python
s036163160
s535784624
347
315
18,796
58,008
Accepted
Accepted
9.22
class UnionFind: __slots__ = ["_data_size", "_roots"] def __init__(self, data_size: int) -> None: self._data_size = data_size self._roots = [-1] * data_size def __getitem__(self, x: int) -> int: while self._roots[x] >= 0: x = self._roots[x] return x def is_connected(self, x: int, y: int) -> bool: return self[x] == self[y] def unite(self, x: int, y: int) -> None: x, y = self[x], self[y] if x == y: return if self._roots[x] > self._roots[y]: x, y = y, x self._roots[x] += self._roots[y] self._roots[y] = x import sys readline = sys.stdin.buffer.readline N, Q = list(map(int, readline().split())) tree = UnionFind(N) res = [] for _ in range(Q): t, u, v = list(map(int, readline().split())) if t: res.append(int(tree.is_connected(u, v))) else: tree.unite(u, v) print(("\n".join(map(str, res))))
class UnionFind: __slots__ = ["_data_size", "_roots"] def __init__(self, data_size: int) -> None: self._data_size = data_size self._roots = [-1] * data_size def __getitem__(self, x: int) -> int: while self._roots[x] >= 0: x = self._roots[x] return x def is_connected(self, x: int, y: int) -> bool: return self[x] == self[y] def unite(self, x: int, y: int) -> None: x, y = self[x], self[y] if x == y: return if self._roots[x] > self._roots[y]: x, y = y, x self._roots[x] += self._roots[y] self._roots[y] = x N, Q, *TUV = list(map(int, open(0).read().split())) tree = UnionFind(N) res = [] for t, u, v in zip(*[iter(TUV)] * 3): if t: res.append(int(tree.is_connected(u, v))) else: tree.unite(u, v) print(("\n".join(map(str, res))))
39
34
990
921
class UnionFind: __slots__ = ["_data_size", "_roots"] def __init__(self, data_size: int) -> None: self._data_size = data_size self._roots = [-1] * data_size def __getitem__(self, x: int) -> int: while self._roots[x] >= 0: x = self._roots[x] return x def is_connected(self, x: int, y: int) -> bool: return self[x] == self[y] def unite(self, x: int, y: int) -> None: x, y = self[x], self[y] if x == y: return if self._roots[x] > self._roots[y]: x, y = y, x self._roots[x] += self._roots[y] self._roots[y] = x import sys readline = sys.stdin.buffer.readline N, Q = list(map(int, readline().split())) tree = UnionFind(N) res = [] for _ in range(Q): t, u, v = list(map(int, readline().split())) if t: res.append(int(tree.is_connected(u, v))) else: tree.unite(u, v) print(("\n".join(map(str, res))))
class UnionFind: __slots__ = ["_data_size", "_roots"] def __init__(self, data_size: int) -> None: self._data_size = data_size self._roots = [-1] * data_size def __getitem__(self, x: int) -> int: while self._roots[x] >= 0: x = self._roots[x] return x def is_connected(self, x: int, y: int) -> bool: return self[x] == self[y] def unite(self, x: int, y: int) -> None: x, y = self[x], self[y] if x == y: return if self._roots[x] > self._roots[y]: x, y = y, x self._roots[x] += self._roots[y] self._roots[y] = x N, Q, *TUV = list(map(int, open(0).read().split())) tree = UnionFind(N) res = [] for t, u, v in zip(*[iter(TUV)] * 3): if t: res.append(int(tree.is_connected(u, v))) else: tree.unite(u, v) print(("\n".join(map(str, res))))
false
12.820513
[ "-import sys", "-", "-readline = sys.stdin.buffer.readline", "-N, Q = list(map(int, readline().split()))", "+N, Q, *TUV = list(map(int, open(0).read().split()))", "-for _ in range(Q):", "- t, u, v = list(map(int, readline().split()))", "+for t, u, v in zip(*[iter(TUV)] * 3):" ]
false
0.04864
0.039471
1.232293
[ "s036163160", "s535784624" ]
u853185302
p03127
python
s254039793
s482010769
153
78
14,252
16,200
Accepted
Accepted
49.02
N = int(eval(input())) A = list(map(int,input().split())) A.sort() while(len(A) != 1): A_min = A.pop(0) A = [A[i]%A_min for i in range(len(A)) if A[i]%A_min > 0] A.append(A_min) A.sort() print((A[0]))
from functools import reduce from fractions import gcd n = int(eval(input())) a = list(map(int,input().split())) print((reduce(gcd,a)))
11
5
212
132
N = int(eval(input())) A = list(map(int, input().split())) A.sort() while len(A) != 1: A_min = A.pop(0) A = [A[i] % A_min for i in range(len(A)) if A[i] % A_min > 0] A.append(A_min) A.sort() print((A[0]))
from functools import reduce from fractions import gcd n = int(eval(input())) a = list(map(int, input().split())) print((reduce(gcd, a)))
false
54.545455
[ "-N = int(eval(input()))", "-A = list(map(int, input().split()))", "-A.sort()", "-while len(A) != 1:", "- A_min = A.pop(0)", "- A = [A[i] % A_min for i in range(len(A)) if A[i] % A_min > 0]", "- A.append(A_min)", "- A.sort()", "-print((A[0]))", "+from functools import reduce", "+from fractions import gcd", "+", "+n = int(eval(input()))", "+a = list(map(int, input().split()))", "+print((reduce(gcd, a)))" ]
false
0.087379
0.060668
1.44028
[ "s254039793", "s482010769" ]
u699089116
p03951
python
s350032925
s076558455
164
67
38,256
61,828
Accepted
Accepted
59.15
n = int(eval(input())) s = eval(input()) t = eval(input()) ans = len(s + t) for i in range(n): if s[i:] == t[:n-i]: print((n+i)) exit() print((n*2))
n = int(eval(input())) s = eval(input()) t = eval(input()) for i in range(n): if s[i:] == t[:n-i]: print((n + i)) exit() else: print((n*2))
10
10
156
151
n = int(eval(input())) s = eval(input()) t = eval(input()) ans = len(s + t) for i in range(n): if s[i:] == t[: n - i]: print((n + i)) exit() print((n * 2))
n = int(eval(input())) s = eval(input()) t = eval(input()) for i in range(n): if s[i:] == t[: n - i]: print((n + i)) exit() else: print((n * 2))
false
0
[ "-ans = len(s + t)", "-print((n * 2))", "+else:", "+ print((n * 2))" ]
false
0.036002
0.035623
1.010632
[ "s350032925", "s076558455" ]