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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u334712262 | p02868 | python | s938760911 | s595219980 | 933 | 832 | 73,368 | 97,632 | Accepted | Accepted | 10.83 | from collections import defaultdict
from heapq import heappop, heappush
class Graph():
def __init__(self):
self.graph = defaultdict(list)
def __len__(self):
return len(self.graph)
def add_edge(self, src, dst, weight=1):
self.graph[src].append((dst, weight))
def get_nodes(self):
return list(self.graph.keys())
class Dijkstra():
def __init__(self, graph, start):
self.g = graph.graph
self.dist = defaultdict(lambda: float("inf"))
self.dist[start] = 0
self.prev = defaultdict(lambda: None)
self.Q = []
heappush(self.Q, (self.dist[start], start))
while self.Q:
dist_u, u = heappop(self.Q)
if self.dist[u] < dist_u:
continue
for v, weight in self.g[u]:
alt = dist_u + weight
if self.dist[v] > alt:
self.dist[v] = alt
self.prev[v] = u
heappush(self.Q, (alt, v))
def shortest_distance(self, goal):
return self.dist[goal]
def shortest_path(self, goal):
path = []
node = goal
while node is not None:
path.append(node)
node = self.prev[node]
return path[::-1]
import sys
input=sys.stdin.readline
n,m=list(map(int,input().split()))
g=Graph()
for _ in range(m):
l,r,c=list(map(int,input().split()))
g.add_edge(l,r,c)
for i in range(2,n+1):
g.add_edge(i,i-1,0)
d = Dijkstra(g,1)
ans=d.shortest_distance(n)
print((ans if ans!=float("inf") else -1))
| # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
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
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, 'sec')
return ret
return wrap
def Dijkstra(g, s):
prev = {}
q = []
d = defaultdict(lambda: INF)
d[s] = 0
heapq.heappush(q, (d[s], s))
while q:
c, u = heapq.heappop(q)
if d[u] < c:
continue
for v, w in g[u].items():
alt = w + c
if d[v] > alt:
d[v] = alt
prev[v] = u
heapq.heappush(q, (alt, v))
return d
@mt
def slv(N, LRC):
g = defaultdict(dict)
LRC.sort(key=lambda x: x[2], reverse=True )
for l, r, c in LRC:
g[l][r] = c
for i in range(2, N+1):
g[i][i-1] = 0
d = Dijkstra(g, 1)
return -1 if d[N] == INF else d[N]
def main():
N, M = read_int_n()
LRC = [read_int_n() for _ in range(M)]
print(slv(N, LRC))
if __name__ == '__main__':
main()
| 75 | 101 | 1,651 | 1,951 | from collections import defaultdict
from heapq import heappop, heappush
class Graph:
def __init__(self):
self.graph = defaultdict(list)
def __len__(self):
return len(self.graph)
def add_edge(self, src, dst, weight=1):
self.graph[src].append((dst, weight))
def get_nodes(self):
return list(self.graph.keys())
class Dijkstra:
def __init__(self, graph, start):
self.g = graph.graph
self.dist = defaultdict(lambda: float("inf"))
self.dist[start] = 0
self.prev = defaultdict(lambda: None)
self.Q = []
heappush(self.Q, (self.dist[start], start))
while self.Q:
dist_u, u = heappop(self.Q)
if self.dist[u] < dist_u:
continue
for v, weight in self.g[u]:
alt = dist_u + weight
if self.dist[v] > alt:
self.dist[v] = alt
self.prev[v] = u
heappush(self.Q, (alt, v))
def shortest_distance(self, goal):
return self.dist[goal]
def shortest_path(self, goal):
path = []
node = goal
while node is not None:
path.append(node)
node = self.prev[node]
return path[::-1]
import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
g = Graph()
for _ in range(m):
l, r, c = list(map(int, input().split()))
g.add_edge(l, r, c)
for i in range(2, n + 1):
g.add_edge(i, i - 1, 0)
d = Dijkstra(g, 1)
ans = d.shortest_distance(n)
print((ans if ans != float("inf") else -1))
| # -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
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
sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62 - 1
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input().strip()
def read_str_n():
return list(map(str, input().split()))
def error_print(*args):
print(*args, file=sys.stderr)
def mt(f):
import time
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
error_print(e - s, "sec")
return ret
return wrap
def Dijkstra(g, s):
prev = {}
q = []
d = defaultdict(lambda: INF)
d[s] = 0
heapq.heappush(q, (d[s], s))
while q:
c, u = heapq.heappop(q)
if d[u] < c:
continue
for v, w in g[u].items():
alt = w + c
if d[v] > alt:
d[v] = alt
prev[v] = u
heapq.heappush(q, (alt, v))
return d
@mt
def slv(N, LRC):
g = defaultdict(dict)
LRC.sort(key=lambda x: x[2], reverse=True)
for l, r, c in LRC:
g[l][r] = c
for i in range(2, N + 1):
g[i][i - 1] = 0
d = Dijkstra(g, 1)
return -1 if d[N] == INF else d[N]
def main():
N, M = read_int_n()
LRC = [read_int_n() for _ in range(M)]
print(slv(N, LRC))
if __name__ == "__main__":
main()
| false | 25.742574 | [
"-from collections import defaultdict",
"-from heapq import heappop, heappush",
"+# -*- coding: utf-8 -*-",
"+import bisect",
"+import heapq",
"+import math",
"+import random",
"+import sys",
"+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",
"+",
"+sys.setrecursionlimit(100000)",
"+input = sys.stdin.readline",
"+INF = 2**62 - 1",
"-class Graph:",
"- def __init__(self):",
"- self.graph = defaultdict(list)",
"-",
"- def __len__(self):",
"- return len(self.graph)",
"-",
"- def add_edge(self, src, dst, weight=1):",
"- self.graph[src].append((dst, weight))",
"-",
"- def get_nodes(self):",
"- return list(self.graph.keys())",
"+def read_int():",
"+ return int(input())",
"-class Dijkstra:",
"- def __init__(self, graph, start):",
"- self.g = graph.graph",
"- self.dist = defaultdict(lambda: float(\"inf\"))",
"- self.dist[start] = 0",
"- self.prev = defaultdict(lambda: None)",
"- self.Q = []",
"- heappush(self.Q, (self.dist[start], start))",
"- while self.Q:",
"- dist_u, u = heappop(self.Q)",
"- if self.dist[u] < dist_u:",
"- continue",
"- for v, weight in self.g[u]:",
"- alt = dist_u + weight",
"- if self.dist[v] > alt:",
"- self.dist[v] = alt",
"- self.prev[v] = u",
"- heappush(self.Q, (alt, v))",
"-",
"- def shortest_distance(self, goal):",
"- return self.dist[goal]",
"-",
"- def shortest_path(self, goal):",
"- path = []",
"- node = goal",
"- while node is not None:",
"- path.append(node)",
"- node = self.prev[node]",
"- return path[::-1]",
"+def read_int_n():",
"+ return list(map(int, input().split()))",
"-import sys",
"+def read_float():",
"+ return float(input())",
"-input = sys.stdin.readline",
"-n, m = list(map(int, input().split()))",
"-g = Graph()",
"-for _ in range(m):",
"- l, r, c = list(map(int, input().split()))",
"- g.add_edge(l, r, c)",
"-for i in range(2, n + 1):",
"- g.add_edge(i, i - 1, 0)",
"-d = Dijkstra(g, 1)",
"-ans = d.shortest_distance(n)",
"-print((ans if ans != float(\"inf\") else -1))",
"+",
"+def read_float_n():",
"+ return list(map(float, input().split()))",
"+",
"+",
"+def read_str():",
"+ return input().strip()",
"+",
"+",
"+def read_str_n():",
"+ return list(map(str, input().split()))",
"+",
"+",
"+def error_print(*args):",
"+ print(*args, file=sys.stderr)",
"+",
"+",
"+def mt(f):",
"+ import time",
"+",
"+ def wrap(*args, **kwargs):",
"+ s = time.time()",
"+ ret = f(*args, **kwargs)",
"+ e = time.time()",
"+ error_print(e - s, \"sec\")",
"+ return ret",
"+",
"+ return wrap",
"+",
"+",
"+def Dijkstra(g, s):",
"+ prev = {}",
"+ q = []",
"+ d = defaultdict(lambda: INF)",
"+ d[s] = 0",
"+ heapq.heappush(q, (d[s], s))",
"+ while q:",
"+ c, u = heapq.heappop(q)",
"+ if d[u] < c:",
"+ continue",
"+ for v, w in g[u].items():",
"+ alt = w + c",
"+ if d[v] > alt:",
"+ d[v] = alt",
"+ prev[v] = u",
"+ heapq.heappush(q, (alt, v))",
"+ return d",
"+",
"+",
"+@mt",
"+def slv(N, LRC):",
"+ g = defaultdict(dict)",
"+ LRC.sort(key=lambda x: x[2], reverse=True)",
"+ for l, r, c in LRC:",
"+ g[l][r] = c",
"+ for i in range(2, N + 1):",
"+ g[i][i - 1] = 0",
"+ d = Dijkstra(g, 1)",
"+ return -1 if d[N] == INF else d[N]",
"+",
"+",
"+def main():",
"+ N, M = read_int_n()",
"+ LRC = [read_int_n() for _ in range(M)]",
"+ print(slv(N, LRC))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.039431 | 0.057939 | 0.680566 | [
"s938760911",
"s595219980"
] |
u074747865 | p02397 | python | s411552420 | s113048514 | 60 | 50 | 5,608 | 5,604 | Accepted | Accepted | 16.67 | while True:
a=sorted(map(int,input().split()))
if a==[0,0]:
quit()
print((*a))
| while True:
x,y=sorted(map(int,input().split()))
if (x==0) and(y==0):
break
print((x, y))
| 5 | 5 | 101 | 97 | while True:
a = sorted(map(int, input().split()))
if a == [0, 0]:
quit()
print((*a))
| while True:
x, y = sorted(map(int, input().split()))
if (x == 0) and (y == 0):
break
print((x, y))
| false | 0 | [
"- a = sorted(map(int, input().split()))",
"- if a == [0, 0]:",
"- quit()",
"- print((*a))",
"+ x, y = sorted(map(int, input().split()))",
"+ if (x == 0) and (y == 0):",
"+ break",
"+ print((x, y))"
] | false | 0.036088 | 0.036812 | 0.980324 | [
"s411552420",
"s113048514"
] |
u612721349 | p03125 | python | s655421278 | s399763097 | 171 | 17 | 38,384 | 2,940 | Accepted | Accepted | 90.06 | a, b = list(map(int, input().split()))
print(((a + b) if b % a == 0 else (b - a)))
| a,b=list(map(int,input().split()));print(([b+a,b-a][b%a>0])) | 2 | 1 | 76 | 52 | a, b = list(map(int, input().split()))
print(((a + b) if b % a == 0 else (b - a)))
| a, b = list(map(int, input().split()))
print(([b + a, b - a][b % a > 0]))
| false | 50 | [
"-print(((a + b) if b % a == 0 else (b - a)))",
"+print(([b + a, b - a][b % a > 0]))"
] | false | 0.093309 | 0.038406 | 2.429559 | [
"s655421278",
"s399763097"
] |
u370331385 | p03575 | python | s943214918 | s977402496 | 27 | 22 | 3,064 | 3,064 | Accepted | Accepted | 18.52 | N,M = list(map(int,input().split()))
graph = [[0]*N for _ in range(N)]
Edge = []
for i in range(M):
a,b = list(map(int,input().split()))
graph[a-1][b-1] = 1
graph[b-1][a-1] = 1
Edge.append([a-1,b-1])
def dfs(x):
if(vis[x] == 1): return
vis[x] = 1
for i in range(N):
if(graph[x][i] == 1):
dfs(i)
ans = 0
for i in range(M):
graph[Edge[i][0]][Edge[i][1]] = 0
graph[Edge[i][1]][Edge[i][0]] = 0
vis = [0]*60
dfs(0)
for j in range(N):
if(vis[j] == 0):
ans += 1
break
graph[Edge[i][0]][Edge[i][1]] = 1
graph[Edge[i][1]][Edge[i][0]] = 1
print(ans) | 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)]
N,M = list(map(int,input().split()))
Edge = []
for i in range(M):
a,b = list(map(int,input().split()))
Edge.append([a-1,b-1])
ans = 0
for i in range(M):
graph = UnionFind(N)
for j in range(M):
if(i != j):
graph.Unite(Edge[j][0],Edge[j][1])
if(graph.Count(0) != N): ans += 1
print(ans) | 30 | 60 | 619 | 1,631 | N, M = list(map(int, input().split()))
graph = [[0] * N for _ in range(N)]
Edge = []
for i in range(M):
a, b = list(map(int, input().split()))
graph[a - 1][b - 1] = 1
graph[b - 1][a - 1] = 1
Edge.append([a - 1, b - 1])
def dfs(x):
if vis[x] == 1:
return
vis[x] = 1
for i in range(N):
if graph[x][i] == 1:
dfs(i)
ans = 0
for i in range(M):
graph[Edge[i][0]][Edge[i][1]] = 0
graph[Edge[i][1]][Edge[i][0]] = 0
vis = [0] * 60
dfs(0)
for j in range(N):
if vis[j] == 0:
ans += 1
break
graph[Edge[i][0]][Edge[i][1]] = 1
graph[Edge[i][1]][Edge[i][0]] = 1
print(ans)
| 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)]
N, M = list(map(int, input().split()))
Edge = []
for i in range(M):
a, b = list(map(int, input().split()))
Edge.append([a - 1, b - 1])
ans = 0
for i in range(M):
graph = UnionFind(N)
for j in range(M):
if i != j:
graph.Unite(Edge[j][0], Edge[j][1])
if graph.Count(0) != N:
ans += 1
print(ans)
| false | 50 | [
"+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)]",
"+",
"+",
"-graph = [[0] * N for _ in range(N)]",
"- graph[a - 1][b - 1] = 1",
"- graph[b - 1][a - 1] = 1",
"-",
"-",
"-def dfs(x):",
"- if vis[x] == 1:",
"- return",
"- vis[x] = 1",
"- for i in range(N):",
"- if graph[x][i] == 1:",
"- dfs(i)",
"-",
"-",
"- graph[Edge[i][0]][Edge[i][1]] = 0",
"- graph[Edge[i][1]][Edge[i][0]] = 0",
"- vis = [0] * 60",
"- dfs(0)",
"- for j in range(N):",
"- if vis[j] == 0:",
"- ans += 1",
"- break",
"- graph[Edge[i][0]][Edge[i][1]] = 1",
"- graph[Edge[i][1]][Edge[i][0]] = 1",
"+ graph = UnionFind(N)",
"+ for j in range(M):",
"+ if i != j:",
"+ graph.Unite(Edge[j][0], Edge[j][1])",
"+ if graph.Count(0) != N:",
"+ ans += 1"
] | false | 0.037437 | 0.073493 | 0.50939 | [
"s943214918",
"s977402496"
] |
u493520238 | p02684 | python | s468712204 | s620283349 | 128 | 111 | 123,132 | 103,344 | Accepted | Accepted | 13.28 | def main():
n, k = list(map(int, input().split()))
al = list(map(int, input().split()))
city_l = [1]
city_s = set([1])
loop_city_l = []
curr_city = 1
cnt = 0
for i in range(1,k+1):
next_c = al[curr_city-1]
if next_c in city_s:
cnt = i
first_city = city_l.index(next_c)
loop_city_l = city_l[first_city:]
break
else:
city_s.add(next_c)
city_l.append(next_c)
curr_city = next_c
else:
print(curr_city)
return
# print(loop_city_l)
remained = k-cnt
last_pos = remained%len(loop_city_l)
print((loop_city_l[last_pos]))
if __name__ == "__main__":
main() | n,k = list(map(int, input().split()))
al = list(map(int, input().split()))
cnt = 0
cl = [-1]*(n+1)
cll = [1]
curr = 1
for i in range(min(n,k)):
# print(curr)
next_c = al[curr-1]
if cl[next_c] != -1:
# loop_start = (i+1)
loop_start = cl[next_c]
rem = k - (i+1)
break
else:
cl[next_c] = i + 1
cll.append(next_c)
curr = next_c
else:
print(curr)
exit()
# print(rem)
loop_c = cll[loop_start:]
# print(loop_c)
last_ind = rem%len(loop_c)
ans = loop_c[last_ind]
print(ans) | 30 | 30 | 745 | 569 | def main():
n, k = list(map(int, input().split()))
al = list(map(int, input().split()))
city_l = [1]
city_s = set([1])
loop_city_l = []
curr_city = 1
cnt = 0
for i in range(1, k + 1):
next_c = al[curr_city - 1]
if next_c in city_s:
cnt = i
first_city = city_l.index(next_c)
loop_city_l = city_l[first_city:]
break
else:
city_s.add(next_c)
city_l.append(next_c)
curr_city = next_c
else:
print(curr_city)
return
# print(loop_city_l)
remained = k - cnt
last_pos = remained % len(loop_city_l)
print((loop_city_l[last_pos]))
if __name__ == "__main__":
main()
| n, k = list(map(int, input().split()))
al = list(map(int, input().split()))
cnt = 0
cl = [-1] * (n + 1)
cll = [1]
curr = 1
for i in range(min(n, k)):
# print(curr)
next_c = al[curr - 1]
if cl[next_c] != -1:
# loop_start = (i+1)
loop_start = cl[next_c]
rem = k - (i + 1)
break
else:
cl[next_c] = i + 1
cll.append(next_c)
curr = next_c
else:
print(curr)
exit()
# print(rem)
loop_c = cll[loop_start:]
# print(loop_c)
last_ind = rem % len(loop_c)
ans = loop_c[last_ind]
print(ans)
| false | 0 | [
"-def main():",
"- n, k = list(map(int, input().split()))",
"- al = list(map(int, input().split()))",
"- city_l = [1]",
"- city_s = set([1])",
"- loop_city_l = []",
"- curr_city = 1",
"- cnt = 0",
"- for i in range(1, k + 1):",
"- next_c = al[curr_city - 1]",
"- if next_c in city_s:",
"- cnt = i",
"- first_city = city_l.index(next_c)",
"- loop_city_l = city_l[first_city:]",
"- break",
"- else:",
"- city_s.add(next_c)",
"- city_l.append(next_c)",
"- curr_city = next_c",
"+n, k = list(map(int, input().split()))",
"+al = list(map(int, input().split()))",
"+cnt = 0",
"+cl = [-1] * (n + 1)",
"+cll = [1]",
"+curr = 1",
"+for i in range(min(n, k)):",
"+ # print(curr)",
"+ next_c = al[curr - 1]",
"+ if cl[next_c] != -1:",
"+ # loop_start = (i+1)",
"+ loop_start = cl[next_c]",
"+ rem = k - (i + 1)",
"+ break",
"- print(curr_city)",
"- return",
"- # print(loop_city_l)",
"- remained = k - cnt",
"- last_pos = remained % len(loop_city_l)",
"- print((loop_city_l[last_pos]))",
"-",
"-",
"-if __name__ == \"__main__\":",
"- main()",
"+ cl[next_c] = i + 1",
"+ cll.append(next_c)",
"+ curr = next_c",
"+else:",
"+ print(curr)",
"+ exit()",
"+# print(rem)",
"+loop_c = cll[loop_start:]",
"+# print(loop_c)",
"+last_ind = rem % len(loop_c)",
"+ans = loop_c[last_ind]",
"+print(ans)"
] | false | 0.047241 | 0.035942 | 1.314362 | [
"s468712204",
"s620283349"
] |
u707498674 | p03583 | python | s053277985 | s315409546 | 1,405 | 1,054 | 3,064 | 3,060 | Accepted | Accepted | 24.98 | def main():
N = int(eval(input()))
for h in range(1, 3501):
for n in range(1, 3501):
if (4*h*n - N*h - N*n)>0 and N*h*n % (4*h*n - N*h - N*n)==0:
w = N*h*n // (4*h*n - N*h - N*n)
print((h, n, w))
exit()
if __name__ == "__main__":
main() | def main():
N = int(eval(input()))
for h in range(1, 3501):
for n in range(h, 3501):
if (4*h*n - N*h - N*n)>0 and N*h*n % (4*h*n - N*h - N*n)==0:
w = N*h*n // (4*h*n - N*h - N*n)
print((h, n, w))
exit()
if __name__ == "__main__":
main() | 12 | 12 | 321 | 321 | def main():
N = int(eval(input()))
for h in range(1, 3501):
for n in range(1, 3501):
if (4 * h * n - N * h - N * n) > 0 and N * h * n % (
4 * h * n - N * h - N * n
) == 0:
w = N * h * n // (4 * h * n - N * h - N * n)
print((h, n, w))
exit()
if __name__ == "__main__":
main()
| def main():
N = int(eval(input()))
for h in range(1, 3501):
for n in range(h, 3501):
if (4 * h * n - N * h - N * n) > 0 and N * h * n % (
4 * h * n - N * h - N * n
) == 0:
w = N * h * n // (4 * h * n - N * h - N * n)
print((h, n, w))
exit()
if __name__ == "__main__":
main()
| false | 0 | [
"- for n in range(1, 3501):",
"+ for n in range(h, 3501):"
] | false | 0.469574 | 0.007928 | 59.231162 | [
"s053277985",
"s315409546"
] |
u753803401 | p03061 | python | s677815964 | s800572988 | 391 | 360 | 93,844 | 89,580 | Accepted | Accepted | 7.93 | def slove():
import sys
import fractions
input = sys.stdin.readline
n = int(input().rstrip('\n'))
a = list(map(int, input().rstrip('\n').split()))
g_l = [[0, 0] for _ in range(n + 1)]
for i in range(n):
g_l[i+1][0] = fractions.gcd(g_l[i][0], a[i])
g_l[-i-2][1] = fractions.gcd(g_l[-i-1][1], a[-i-1])
m_g = 0
for i in range(n):
m_g = max(m_g, fractions.gcd(g_l[i][0], g_l[i + 1][1]))
print(m_g)
if __name__ == '__main__':
slove()
| def slove():
import sys
import fractions
input = sys.stdin.readline
n = int(input().rstrip('\n'))
a = list(map(int, input().rstrip('\n').split()))
ls = [[0] * (n + 1) for _ in range(2)]
for i in range(n):
ls[0][i+1] = fractions.gcd(ls[0][i], a[i])
ls[1][-i-2] = fractions.gcd(ls[1][-i-1], a[-i-1])
m_gcd = 0
for i in range(n):
gcd = fractions.gcd(ls[0][i], ls[1][i+1])
m_gcd = max(m_gcd, gcd)
print(m_gcd)
if __name__ == '__main__':
slove()
| 19 | 19 | 518 | 537 | def slove():
import sys
import fractions
input = sys.stdin.readline
n = int(input().rstrip("\n"))
a = list(map(int, input().rstrip("\n").split()))
g_l = [[0, 0] for _ in range(n + 1)]
for i in range(n):
g_l[i + 1][0] = fractions.gcd(g_l[i][0], a[i])
g_l[-i - 2][1] = fractions.gcd(g_l[-i - 1][1], a[-i - 1])
m_g = 0
for i in range(n):
m_g = max(m_g, fractions.gcd(g_l[i][0], g_l[i + 1][1]))
print(m_g)
if __name__ == "__main__":
slove()
| def slove():
import sys
import fractions
input = sys.stdin.readline
n = int(input().rstrip("\n"))
a = list(map(int, input().rstrip("\n").split()))
ls = [[0] * (n + 1) for _ in range(2)]
for i in range(n):
ls[0][i + 1] = fractions.gcd(ls[0][i], a[i])
ls[1][-i - 2] = fractions.gcd(ls[1][-i - 1], a[-i - 1])
m_gcd = 0
for i in range(n):
gcd = fractions.gcd(ls[0][i], ls[1][i + 1])
m_gcd = max(m_gcd, gcd)
print(m_gcd)
if __name__ == "__main__":
slove()
| false | 0 | [
"- g_l = [[0, 0] for _ in range(n + 1)]",
"+ ls = [[0] * (n + 1) for _ in range(2)]",
"- g_l[i + 1][0] = fractions.gcd(g_l[i][0], a[i])",
"- g_l[-i - 2][1] = fractions.gcd(g_l[-i - 1][1], a[-i - 1])",
"- m_g = 0",
"+ ls[0][i + 1] = fractions.gcd(ls[0][i], a[i])",
"+ ls[1][-i - 2] = fractions.gcd(ls[1][-i - 1], a[-i - 1])",
"+ m_gcd = 0",
"- m_g = max(m_g, fractions.gcd(g_l[i][0], g_l[i + 1][1]))",
"- print(m_g)",
"+ gcd = fractions.gcd(ls[0][i], ls[1][i + 1])",
"+ m_gcd = max(m_gcd, gcd)",
"+ print(m_gcd)"
] | false | 0.062822 | 0.060641 | 1.035961 | [
"s677815964",
"s800572988"
] |
u001024152 | p03330 | python | s682797882 | s662724158 | 1,146 | 245 | 7,968 | 8,012 | Accepted | Accepted | 78.62 | from collections import Counter
from itertools import permutations
N,C = list(map(int, input().split()))
cost = [list(map(int, input().split())) for _ in range(C)]
color = [list([int(x)-1 for x in input().split()]) for _ in range(N)]
# 3 groups
mod3 = {0:[], 1:[], 2:[]}
for i in range(N):
for j in range(N):
m = (i+j)%3
mod3[m].append(color[i][j])
cnts = [Counter(mod3[i]) for i in range(3)]
ans = float('inf')
for p in permutations(list(range(C)), 3):
cond = 0
for i in range(3):
for col in list(cnts[i].keys()):
cond += cnts[i][col]*cost[col][p[i]]
ans = min(ans, cond)
#print(cond, p)
print(ans)
| from collections import Counter
from itertools import permutations
N,C = list(map(int, input().split()))
cost = [list(map(int, input().split())) for _ in range(C)]
color = [list([int(x)-1 for x in input().split()]) for _ in range(N)]
# 3 groups
mod3 = {0:[], 1:[], 2:[]}
for i in range(N):
for j in range(N):
m = (i+j)%3
mod3[m].append(color[i][j])
cnts = [Counter(mod3[i]) for i in range(3)]
cost_mod = [[-1]*C for _ in range(3)]
for i in range(3):
for to_ in range(C):
cond = 0
for from_ in list(cnts[i].keys()):
cond += cnts[i][from_]*cost[from_][to_]
cost_mod[i][to_] = cond
ans = float('inf')
for p in permutations(list(range(C)), 3):
cond = 0
for i in range(3):
cond += cost_mod[i][p[i]]
ans = min(ans, cond)
#print(cond, p)
print(ans)
| 25 | 31 | 673 | 849 | from collections import Counter
from itertools import permutations
N, C = list(map(int, input().split()))
cost = [list(map(int, input().split())) for _ in range(C)]
color = [list([int(x) - 1 for x in input().split()]) for _ in range(N)]
# 3 groups
mod3 = {0: [], 1: [], 2: []}
for i in range(N):
for j in range(N):
m = (i + j) % 3
mod3[m].append(color[i][j])
cnts = [Counter(mod3[i]) for i in range(3)]
ans = float("inf")
for p in permutations(list(range(C)), 3):
cond = 0
for i in range(3):
for col in list(cnts[i].keys()):
cond += cnts[i][col] * cost[col][p[i]]
ans = min(ans, cond)
# print(cond, p)
print(ans)
| from collections import Counter
from itertools import permutations
N, C = list(map(int, input().split()))
cost = [list(map(int, input().split())) for _ in range(C)]
color = [list([int(x) - 1 for x in input().split()]) for _ in range(N)]
# 3 groups
mod3 = {0: [], 1: [], 2: []}
for i in range(N):
for j in range(N):
m = (i + j) % 3
mod3[m].append(color[i][j])
cnts = [Counter(mod3[i]) for i in range(3)]
cost_mod = [[-1] * C for _ in range(3)]
for i in range(3):
for to_ in range(C):
cond = 0
for from_ in list(cnts[i].keys()):
cond += cnts[i][from_] * cost[from_][to_]
cost_mod[i][to_] = cond
ans = float("inf")
for p in permutations(list(range(C)), 3):
cond = 0
for i in range(3):
cond += cost_mod[i][p[i]]
ans = min(ans, cond)
# print(cond, p)
print(ans)
| false | 19.354839 | [
"+cost_mod = [[-1] * C for _ in range(3)]",
"+for i in range(3):",
"+ for to_ in range(C):",
"+ cond = 0",
"+ for from_ in list(cnts[i].keys()):",
"+ cond += cnts[i][from_] * cost[from_][to_]",
"+ cost_mod[i][to_] = cond",
"- for col in list(cnts[i].keys()):",
"- cond += cnts[i][col] * cost[col][p[i]]",
"+ cond += cost_mod[i][p[i]]"
] | false | 0.006895 | 0.04128 | 0.167028 | [
"s682797882",
"s662724158"
] |
u905203728 | p03274 | python | s080266509 | s572423974 | 220 | 92 | 62,576 | 14,384 | Accepted | Accepted | 58.18 | n,k=list(map(int,input().split()))
candle=list(map(int,input().split()))
ans=float("inf")
for l in range(n-k+1):
r=l+k-1
ans=min(ans,
abs(candle[l])+abs(candle[l]-candle[r]),
abs(candle[r])+abs(candle[r]-candle[l])
)
print(ans) | n,k=list(map(int,input().split()))
line=list(map(int,input().split()))
ans=float("inf")
for i in range(n-k+1):
left,right=i,i+k-1
ans=min(ans,
abs(line[left])+abs(line[left]-line[right]),
abs(line[right])+abs(line[right]-line[left])
)
print(ans) | 10 | 10 | 274 | 292 | n, k = list(map(int, input().split()))
candle = list(map(int, input().split()))
ans = float("inf")
for l in range(n - k + 1):
r = l + k - 1
ans = min(
ans,
abs(candle[l]) + abs(candle[l] - candle[r]),
abs(candle[r]) + abs(candle[r] - candle[l]),
)
print(ans)
| n, k = list(map(int, input().split()))
line = list(map(int, input().split()))
ans = float("inf")
for i in range(n - k + 1):
left, right = i, i + k - 1
ans = min(
ans,
abs(line[left]) + abs(line[left] - line[right]),
abs(line[right]) + abs(line[right] - line[left]),
)
print(ans)
| false | 0 | [
"-candle = list(map(int, input().split()))",
"+line = list(map(int, input().split()))",
"-for l in range(n - k + 1):",
"- r = l + k - 1",
"+for i in range(n - k + 1):",
"+ left, right = i, i + k - 1",
"- abs(candle[l]) + abs(candle[l] - candle[r]),",
"- abs(candle[r]) + abs(candle[r] - candle[l]),",
"+ abs(line[left]) + abs(line[left] - line[right]),",
"+ abs(line[right]) + abs(line[right] - line[left]),"
] | false | 0.04447 | 0.041807 | 1.063718 | [
"s080266509",
"s572423974"
] |
u945181840 | p03112 | python | s475860441 | s388539954 | 585 | 514 | 36,320 | 36,320 | Accepted | Accepted | 12.14 | import sys
from bisect import bisect_left
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
A, B, Q = list(map(int, readline().split()))
stx = list(map(int, read().split()))
s = stx[:A]; t = stx[A:-Q]; x = stx[-Q:]
s = [-10 ** 10] + s + [10 ** 11]
t = [-10 ** 10] + t + [10 ** 11]
for i in x:
ax = bisect_left(s, i)
bx = bisect_left(t, i)
pp = max(s[ax], t[bx]) - i
mm = i - min(s[ax - 1], t[bx - 1])
pm = min(s[ax] * 2 - i - t[bx - 1], t[bx] * 2 - i - s[ax - 1])
mp = min(i - s[ax - 1] * 2 + t[bx], i - t[bx - 1] * 2 + s[ax])
print((min(pp, mm, pm, mp))) | import sys
from bisect import bisect_left
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
A, B, Q = list(map(int, readline().split()))
stx = list(map(int, read().split()))
s = stx[:A]; t = stx[A:-Q]; x = stx[-Q:]
s = [-10 ** 10] + s + [10 ** 11]
t = [-10 ** 10] + t + [10 ** 11]
for i in x:
ax = bisect_left(s, i)
bx = bisect_left(t, i)
pp = max(s[ax], t[bx]) - i
mm = i - min(s[ax - 1], t[bx - 1])
pm = min(s[ax] * 2 - i - t[bx - 1], t[bx] * 2 - i - s[ax - 1])
mp = min(i - s[ax - 1] * 2 + t[bx], i - t[bx - 1] * 2 + s[ax])
print((min(pp, mm, pm, mp)))
if __name__ == '__main__':
main() | 20 | 26 | 630 | 741 | import sys
from bisect import bisect_left
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
A, B, Q = list(map(int, readline().split()))
stx = list(map(int, read().split()))
s = stx[:A]
t = stx[A:-Q]
x = stx[-Q:]
s = [-(10**10)] + s + [10**11]
t = [-(10**10)] + t + [10**11]
for i in x:
ax = bisect_left(s, i)
bx = bisect_left(t, i)
pp = max(s[ax], t[bx]) - i
mm = i - min(s[ax - 1], t[bx - 1])
pm = min(s[ax] * 2 - i - t[bx - 1], t[bx] * 2 - i - s[ax - 1])
mp = min(i - s[ax - 1] * 2 + t[bx], i - t[bx - 1] * 2 + s[ax])
print((min(pp, mm, pm, mp)))
| import sys
from bisect import bisect_left
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
def main():
A, B, Q = list(map(int, readline().split()))
stx = list(map(int, read().split()))
s = stx[:A]
t = stx[A:-Q]
x = stx[-Q:]
s = [-(10**10)] + s + [10**11]
t = [-(10**10)] + t + [10**11]
for i in x:
ax = bisect_left(s, i)
bx = bisect_left(t, i)
pp = max(s[ax], t[bx]) - i
mm = i - min(s[ax - 1], t[bx - 1])
pm = min(s[ax] * 2 - i - t[bx - 1], t[bx] * 2 - i - s[ax - 1])
mp = min(i - s[ax - 1] * 2 + t[bx], i - t[bx - 1] * 2 + s[ax])
print((min(pp, mm, pm, mp)))
if __name__ == "__main__":
main()
| false | 23.076923 | [
"-A, B, Q = list(map(int, readline().split()))",
"-stx = list(map(int, read().split()))",
"-s = stx[:A]",
"-t = stx[A:-Q]",
"-x = stx[-Q:]",
"-s = [-(10**10)] + s + [10**11]",
"-t = [-(10**10)] + t + [10**11]",
"-for i in x:",
"- ax = bisect_left(s, i)",
"- bx = bisect_left(t, i)",
"- pp = max(s[ax], t[bx]) - i",
"- mm = i - min(s[ax - 1], t[bx - 1])",
"- pm = min(s[ax] * 2 - i - t[bx - 1], t[bx] * 2 - i - s[ax - 1])",
"- mp = min(i - s[ax - 1] * 2 + t[bx], i - t[bx - 1] * 2 + s[ax])",
"- print((min(pp, mm, pm, mp)))",
"+",
"+",
"+def main():",
"+ A, B, Q = list(map(int, readline().split()))",
"+ stx = list(map(int, read().split()))",
"+ s = stx[:A]",
"+ t = stx[A:-Q]",
"+ x = stx[-Q:]",
"+ s = [-(10**10)] + s + [10**11]",
"+ t = [-(10**10)] + t + [10**11]",
"+ for i in x:",
"+ ax = bisect_left(s, i)",
"+ bx = bisect_left(t, i)",
"+ pp = max(s[ax], t[bx]) - i",
"+ mm = i - min(s[ax - 1], t[bx - 1])",
"+ pm = min(s[ax] * 2 - i - t[bx - 1], t[bx] * 2 - i - s[ax - 1])",
"+ mp = min(i - s[ax - 1] * 2 + t[bx], i - t[bx - 1] * 2 + s[ax])",
"+ print((min(pp, mm, pm, mp)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.108746 | 0.038603 | 2.817021 | [
"s475860441",
"s388539954"
] |
u871841829 | p02631 | python | s850292506 | s045406362 | 204 | 141 | 43,504 | 114,596 | Accepted | Accepted | 30.88 | N = int(eval(input()))
A = list(map(int, input().split()))
A = A + A
ans = [0] * N
a = 0
for i in range(N-1):
a ^= A[i]
ans[N-1] = a
W = N - 1
for i in range(N-1):
remove = A[i]
addition = A[i+W]
a = remove^a^addition
ans[i] = a
print((" ".join([str(i) for i in ans])))
| N = int(eval(input()))
A = list(map(int, input().split()))
t = 0
for c in A:
t ^= c
ans = []
for b in A:
ans.append(t^b)
print((*ans)) | 16 | 12 | 298 | 148 | N = int(eval(input()))
A = list(map(int, input().split()))
A = A + A
ans = [0] * N
a = 0
for i in range(N - 1):
a ^= A[i]
ans[N - 1] = a
W = N - 1
for i in range(N - 1):
remove = A[i]
addition = A[i + W]
a = remove ^ a ^ addition
ans[i] = a
print((" ".join([str(i) for i in ans])))
| N = int(eval(input()))
A = list(map(int, input().split()))
t = 0
for c in A:
t ^= c
ans = []
for b in A:
ans.append(t ^ b)
print((*ans))
| false | 25 | [
"-A = A + A",
"-ans = [0] * N",
"-a = 0",
"-for i in range(N - 1):",
"- a ^= A[i]",
"-ans[N - 1] = a",
"-W = N - 1",
"-for i in range(N - 1):",
"- remove = A[i]",
"- addition = A[i + W]",
"- a = remove ^ a ^ addition",
"- ans[i] = a",
"-print((\" \".join([str(i) for i in ans])))",
"+t = 0",
"+for c in A:",
"+ t ^= c",
"+ans = []",
"+for b in A:",
"+ ans.append(t ^ b)",
"+print((*ans))"
] | false | 0.038317 | 0.039323 | 0.97442 | [
"s850292506",
"s045406362"
] |
u008229752 | p02861 | python | s965257023 | s290131050 | 700 | 216 | 12,504 | 3,064 | Accepted | Accepted | 69.14 | import numpy as np
from itertools import permutations
from math import hypot
n = int(eval(input()))
cnt = 0
dis = 0
li = []
for _ in range(n):
i, j = list(map(int, input().split()))
li.append(np.array([i, j]))
ptn = list(range(n))
for a in permutations(ptn):
cnt += 1
for i, j in zip(a,a[1:]):
x1, y1 = li[i]
x2, y2 = li[j]
dis += hypot(x1-x2, y1-y2)
print((dis/cnt)) | from itertools import permutations
from math import hypot
n = int(eval(input()))
cnt = 0
dis = 0
li = []
for i in range(n):
x,y = list(map(int,input().split()))
li.append([x, y])
ptn = list(range(n))
for a in permutations(ptn):
cnt += 1
for i, j in zip(a,a[1:]):
x1, y1 = li[i]
x2, y2 = li[j]
dis += hypot(x1-x2, y1-y2)
print((dis/cnt)) | 23 | 22 | 420 | 388 | import numpy as np
from itertools import permutations
from math import hypot
n = int(eval(input()))
cnt = 0
dis = 0
li = []
for _ in range(n):
i, j = list(map(int, input().split()))
li.append(np.array([i, j]))
ptn = list(range(n))
for a in permutations(ptn):
cnt += 1
for i, j in zip(a, a[1:]):
x1, y1 = li[i]
x2, y2 = li[j]
dis += hypot(x1 - x2, y1 - y2)
print((dis / cnt))
| from itertools import permutations
from math import hypot
n = int(eval(input()))
cnt = 0
dis = 0
li = []
for i in range(n):
x, y = list(map(int, input().split()))
li.append([x, y])
ptn = list(range(n))
for a in permutations(ptn):
cnt += 1
for i, j in zip(a, a[1:]):
x1, y1 = li[i]
x2, y2 = li[j]
dis += hypot(x1 - x2, y1 - y2)
print((dis / cnt))
| false | 4.347826 | [
"-import numpy as np",
"-for _ in range(n):",
"- i, j = list(map(int, input().split()))",
"- li.append(np.array([i, j]))",
"+for i in range(n):",
"+ x, y = list(map(int, input().split()))",
"+ li.append([x, y])"
] | false | 0.241269 | 0.05758 | 4.190182 | [
"s965257023",
"s290131050"
] |
u956433805 | p03448 | python | s626467884 | s868723804 | 53 | 49 | 3,060 | 3,060 | Accepted | Accepted | 7.55 | A = int (eval(input()))
B = int (eval(input()))
C = int (eval(input()))
X = int (eval(input()))
ans = 0
for x in range(A+1):
for y in range(B+1):
for z in range(C+1):
if 500 * x + 100 * y + 50 * z == X:
ans +=1
print(ans) | A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
cnt = 0
for a in range(A+1):
for b in range(B+1):
for c in range(C+1):
if 500*a + 100*b + 50*c == X:
cnt+= 1
print(cnt) | 14 | 14 | 253 | 243 | A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
ans = 0
for x in range(A + 1):
for y in range(B + 1):
for z in range(C + 1):
if 500 * x + 100 * y + 50 * z == X:
ans += 1
print(ans)
| A = int(eval(input()))
B = int(eval(input()))
C = int(eval(input()))
X = int(eval(input()))
cnt = 0
for a in range(A + 1):
for b in range(B + 1):
for c in range(C + 1):
if 500 * a + 100 * b + 50 * c == X:
cnt += 1
print(cnt)
| false | 0 | [
"-ans = 0",
"-for x in range(A + 1):",
"- for y in range(B + 1):",
"- for z in range(C + 1):",
"- if 500 * x + 100 * y + 50 * z == X:",
"- ans += 1",
"-print(ans)",
"+cnt = 0",
"+for a in range(A + 1):",
"+ for b in range(B + 1):",
"+ for c in range(C + 1):",
"+ if 500 * a + 100 * b + 50 * c == X:",
"+ cnt += 1",
"+print(cnt)"
] | false | 0.170289 | 0.069285 | 2.457824 | [
"s626467884",
"s868723804"
] |
u286955577 | p03160 | python | s915084541 | s823860383 | 186 | 102 | 13,924 | 13,976 | Accepted | Accepted | 45.16 | N = int(eval(input()))
H = list(map(int, input().split()))
dp = [10 ** 9] * N
dp[0] = 0
for i in range(N):
if i + 1 < N: dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i] - H[i + 1]))
if i + 2 < N: dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i] - H[i + 2]))
print((dp[-1]))
| def solve():
N = int(eval(input()))
H = [int(i) for i in input().split()]
dp = [float('inf')] * N
dp[0] = 0
dp[1] = abs(H[0] - H[1])
for i in range(2, N):
dp[i] = min(dp[i - 2] + abs(H[i - 2] - H[i]), dp[i - 1] + abs(H[i - 1] - H[i]))
return dp[N - 1]
print((solve()))
| 10 | 14 | 272 | 296 | N = int(eval(input()))
H = list(map(int, input().split()))
dp = [10**9] * N
dp[0] = 0
for i in range(N):
if i + 1 < N:
dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i] - H[i + 1]))
if i + 2 < N:
dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i] - H[i + 2]))
print((dp[-1]))
| def solve():
N = int(eval(input()))
H = [int(i) for i in input().split()]
dp = [float("inf")] * N
dp[0] = 0
dp[1] = abs(H[0] - H[1])
for i in range(2, N):
dp[i] = min(dp[i - 2] + abs(H[i - 2] - H[i]), dp[i - 1] + abs(H[i - 1] - H[i]))
return dp[N - 1]
print((solve()))
| false | 28.571429 | [
"-N = int(eval(input()))",
"-H = list(map(int, input().split()))",
"-dp = [10**9] * N",
"-dp[0] = 0",
"-for i in range(N):",
"- if i + 1 < N:",
"- dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i] - H[i + 1]))",
"- if i + 2 < N:",
"- dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i] - H[i + 2]))",
"-print((dp[-1]))",
"+def solve():",
"+ N = int(eval(input()))",
"+ H = [int(i) for i in input().split()]",
"+ dp = [float(\"inf\")] * N",
"+ dp[0] = 0",
"+ dp[1] = abs(H[0] - H[1])",
"+ for i in range(2, N):",
"+ dp[i] = min(dp[i - 2] + abs(H[i - 2] - H[i]), dp[i - 1] + abs(H[i - 1] - H[i]))",
"+ return dp[N - 1]",
"+",
"+",
"+print((solve()))"
] | false | 0.038227 | 0.061175 | 0.624877 | [
"s915084541",
"s823860383"
] |
u623819879 | p03088 | python | s248442716 | s845877329 | 237 | 204 | 42,480 | 42,480 | Accepted | Accepted | 13.92 | #x=int(input())
n=int(eval(input()))
m=102
chars=['A','T','C','G']
mo=10**9+7
d3=set()
d4=set()
for i in chars:
for j in chars:
for k in chars:
d3.add(i+j+k)
for l in chars:
d4.add(i+j+k+l)
kinsoku4=set()
kinsoku3=['AGC','ACG','GAC']
for y in chars:
kinsoku4.add('AG'+y+'C')
kinsoku4.add('A'+y+'GC')
for z in kinsoku3:
kinsoku4.add(y+z)
kinsoku4.add(z+y)
dp=[dict() for i in range(m)]
cnt=[0]*m
for i in d4:
if i not in kinsoku4:
dp[4][i]=1
t=101
for i in range(4,t):
for ch in chars:
for p in list(dp[i-1].keys()):
if p[1:4]+ch not in kinsoku4:
if p[1:4]+ch in dp[i]:
dp[i][p[1:4]+ch]+=dp[i-1][p]%mo
else:
dp[i][p[1:4]+ch]=dp[i-1][p]%mo
for i in range(t):
for x in d4:
if x not in kinsoku4 and x in dp[i]:
cnt[i]+=dp[i][x]%mo
cnt[i]%=mo
#print(len(kinsoku4),kinsoku4)
#print(dp)
#for x in cnt:
#print(x%mo)
if n==3:
ans=61
print(ans)
else:
print((cnt[n]))
| n=int(eval(input()))
m=102
chars=['A','T','C','G']
mo=10**9+7
d4=set()
for i in chars:
for j in chars:
for k in chars:
for l in chars:
d4.add(i+j+k+l)
kinsoku4=set()
kinsoku3=['AGC','ACG','GAC']
for y in chars:
kinsoku4.add('AG'+y+'C')
kinsoku4.add('A'+y+'GC')
for z in kinsoku3:
kinsoku4.add(y+z)
kinsoku4.add(z+y)
dp=[dict() for i in range(m)]
cnt=[0]*m
for i in d4:
if i not in kinsoku4:
dp[4][i]=1
t=1+n
for i in range(4,t):
for ch in chars:
for p in list(dp[i-1].keys()):
if p[1:4]+ch not in kinsoku4:
if p[1:4]+ch in dp[i]:
dp[i][p[1:4]+ch]+=dp[i-1][p]%mo
else:
dp[i][p[1:4]+ch]=dp[i-1][p]%mo
for i in range(t):
for x in d4:
if x not in kinsoku4 and x in dp[i]:
cnt[i]+=dp[i][x]%mo
cnt[i]%=mo
if n==3:
ans=61
print(ans)
else:
print((cnt[n]))
| 60 | 47 | 1,157 | 1,009 | # x=int(input())
n = int(eval(input()))
m = 102
chars = ["A", "T", "C", "G"]
mo = 10**9 + 7
d3 = set()
d4 = set()
for i in chars:
for j in chars:
for k in chars:
d3.add(i + j + k)
for l in chars:
d4.add(i + j + k + l)
kinsoku4 = set()
kinsoku3 = ["AGC", "ACG", "GAC"]
for y in chars:
kinsoku4.add("AG" + y + "C")
kinsoku4.add("A" + y + "GC")
for z in kinsoku3:
kinsoku4.add(y + z)
kinsoku4.add(z + y)
dp = [dict() for i in range(m)]
cnt = [0] * m
for i in d4:
if i not in kinsoku4:
dp[4][i] = 1
t = 101
for i in range(4, t):
for ch in chars:
for p in list(dp[i - 1].keys()):
if p[1:4] + ch not in kinsoku4:
if p[1:4] + ch in dp[i]:
dp[i][p[1:4] + ch] += dp[i - 1][p] % mo
else:
dp[i][p[1:4] + ch] = dp[i - 1][p] % mo
for i in range(t):
for x in d4:
if x not in kinsoku4 and x in dp[i]:
cnt[i] += dp[i][x] % mo
cnt[i] %= mo
# print(len(kinsoku4),kinsoku4)
# print(dp)
# for x in cnt:
# print(x%mo)
if n == 3:
ans = 61
print(ans)
else:
print((cnt[n]))
| n = int(eval(input()))
m = 102
chars = ["A", "T", "C", "G"]
mo = 10**9 + 7
d4 = set()
for i in chars:
for j in chars:
for k in chars:
for l in chars:
d4.add(i + j + k + l)
kinsoku4 = set()
kinsoku3 = ["AGC", "ACG", "GAC"]
for y in chars:
kinsoku4.add("AG" + y + "C")
kinsoku4.add("A" + y + "GC")
for z in kinsoku3:
kinsoku4.add(y + z)
kinsoku4.add(z + y)
dp = [dict() for i in range(m)]
cnt = [0] * m
for i in d4:
if i not in kinsoku4:
dp[4][i] = 1
t = 1 + n
for i in range(4, t):
for ch in chars:
for p in list(dp[i - 1].keys()):
if p[1:4] + ch not in kinsoku4:
if p[1:4] + ch in dp[i]:
dp[i][p[1:4] + ch] += dp[i - 1][p] % mo
else:
dp[i][p[1:4] + ch] = dp[i - 1][p] % mo
for i in range(t):
for x in d4:
if x not in kinsoku4 and x in dp[i]:
cnt[i] += dp[i][x] % mo
cnt[i] %= mo
if n == 3:
ans = 61
print(ans)
else:
print((cnt[n]))
| false | 21.666667 | [
"-# x=int(input())",
"-d3 = set()",
"- d3.add(i + j + k)",
"-t = 101",
"+t = 1 + n",
"-# print(len(kinsoku4),kinsoku4)",
"-# print(dp)",
"-# for x in cnt:",
"-# print(x%mo)"
] | false | 0.233924 | 0.139908 | 1.671979 | [
"s248442716",
"s845877329"
] |
u708255304 | p03162 | python | s474701893 | s986832235 | 718 | 650 | 47,344 | 66,416 | Accepted | Accepted | 9.47 | "C Vacation"
N = int(eval(input()))
summer = []
for i in range(N):
active = list(map(int, input().split()))
summer.append(active)
dp = [[0]*3 for i in range(N+1)]
# dp = [[0, 0, 0]] * (N+1)
# print(dp)
for i in range(N):
dp[i+1][0] = max((max(dp[i][1], dp[i][2])+summer[i][0]), dp[i+1][0])
dp[i+1][1] = max((max(dp[i][0], dp[i][2])+summer[i][1]), dp[i+1][1])
dp[i+1][2] = max((max(dp[i][0], dp[i][1])+summer[i][2]), dp[i+1][2])
print((max(dp[-1])))
| N = int(eval(input()))
S = [list(map(int, input().split())) for _ in range(N)] # N日間の夏休み
dp = [[0]*3 for _ in range(N)] # i日目の状態, (幸福度の合計, 前日の遊んだ内容3種類のテーブル)
# print(S)
# print(dp)
# 初期値
dp[0][0] = (S[0][0], 'a')
dp[0][1] = (S[0][1], 'b')
dp[0][2] = (S[0][2], 'c')
# print(dp)
for i in range(1, N): # N日間の遷移
# aの予定を実行する場合
if dp[i-1][1][0]+S[i][0] > dp[i-1][2][0]+S[i][0]:
dp[i][0] = (dp[i-1][1][0]+S[i][0], 'a')
else:
dp[i][0] = (dp[i-1][2][0]+S[i][0], 'a')
# bの予定を実行する場合
if dp[i-1][0][0]+S[i][1] > dp[i-1][2][0]+S[i][1]:
dp[i][1] = (dp[i-1][0][0]+S[i][1], 'b')
else:
dp[i][1] = (dp[i-1][2][0]+S[i][1], 'b')
# cの予定を実行する場合
if dp[i-1][0][0]+S[i][2] > dp[i-1][1][0]+S[i][2]:
dp[i][2] = (dp[i-1][0][0]+S[i][2], 'c')
else:
dp[i][2] = (dp[i-1][1][0]+S[i][2], 'c')
# print(dp)
print((max(dp[N-1])[0]))
| 17 | 35 | 480 | 914 | "C Vacation"
N = int(eval(input()))
summer = []
for i in range(N):
active = list(map(int, input().split()))
summer.append(active)
dp = [[0] * 3 for i in range(N + 1)]
# dp = [[0, 0, 0]] * (N+1)
# print(dp)
for i in range(N):
dp[i + 1][0] = max((max(dp[i][1], dp[i][2]) + summer[i][0]), dp[i + 1][0])
dp[i + 1][1] = max((max(dp[i][0], dp[i][2]) + summer[i][1]), dp[i + 1][1])
dp[i + 1][2] = max((max(dp[i][0], dp[i][1]) + summer[i][2]), dp[i + 1][2])
print((max(dp[-1])))
| N = int(eval(input()))
S = [list(map(int, input().split())) for _ in range(N)] # N日間の夏休み
dp = [[0] * 3 for _ in range(N)] # i日目の状態, (幸福度の合計, 前日の遊んだ内容3種類のテーブル)
# print(S)
# print(dp)
# 初期値
dp[0][0] = (S[0][0], "a")
dp[0][1] = (S[0][1], "b")
dp[0][2] = (S[0][2], "c")
# print(dp)
for i in range(1, N): # N日間の遷移
# aの予定を実行する場合
if dp[i - 1][1][0] + S[i][0] > dp[i - 1][2][0] + S[i][0]:
dp[i][0] = (dp[i - 1][1][0] + S[i][0], "a")
else:
dp[i][0] = (dp[i - 1][2][0] + S[i][0], "a")
# bの予定を実行する場合
if dp[i - 1][0][0] + S[i][1] > dp[i - 1][2][0] + S[i][1]:
dp[i][1] = (dp[i - 1][0][0] + S[i][1], "b")
else:
dp[i][1] = (dp[i - 1][2][0] + S[i][1], "b")
# cの予定を実行する場合
if dp[i - 1][0][0] + S[i][2] > dp[i - 1][1][0] + S[i][2]:
dp[i][2] = (dp[i - 1][0][0] + S[i][2], "c")
else:
dp[i][2] = (dp[i - 1][1][0] + S[i][2], "c")
# print(dp)
print((max(dp[N - 1])[0]))
| false | 51.428571 | [
"-\"C Vacation\"",
"-summer = []",
"-for i in range(N):",
"- active = list(map(int, input().split()))",
"- summer.append(active)",
"-dp = [[0] * 3 for i in range(N + 1)]",
"-# dp = [[0, 0, 0]] * (N+1)",
"+S = [list(map(int, input().split())) for _ in range(N)] # N日間の夏休み",
"+dp = [[0] * 3 for _ in range(N)] # i日目の状態, (幸福度の合計, 前日の遊んだ内容3種類のテーブル)",
"+# print(S)",
"-for i in range(N):",
"- dp[i + 1][0] = max((max(dp[i][1], dp[i][2]) + summer[i][0]), dp[i + 1][0])",
"- dp[i + 1][1] = max((max(dp[i][0], dp[i][2]) + summer[i][1]), dp[i + 1][1])",
"- dp[i + 1][2] = max((max(dp[i][0], dp[i][1]) + summer[i][2]), dp[i + 1][2])",
"-print((max(dp[-1])))",
"+# 初期値",
"+dp[0][0] = (S[0][0], \"a\")",
"+dp[0][1] = (S[0][1], \"b\")",
"+dp[0][2] = (S[0][2], \"c\")",
"+# print(dp)",
"+for i in range(1, N): # N日間の遷移",
"+ # aの予定を実行する場合",
"+ if dp[i - 1][1][0] + S[i][0] > dp[i - 1][2][0] + S[i][0]:",
"+ dp[i][0] = (dp[i - 1][1][0] + S[i][0], \"a\")",
"+ else:",
"+ dp[i][0] = (dp[i - 1][2][0] + S[i][0], \"a\")",
"+ # bの予定を実行する場合",
"+ if dp[i - 1][0][0] + S[i][1] > dp[i - 1][2][0] + S[i][1]:",
"+ dp[i][1] = (dp[i - 1][0][0] + S[i][1], \"b\")",
"+ else:",
"+ dp[i][1] = (dp[i - 1][2][0] + S[i][1], \"b\")",
"+ # cの予定を実行する場合",
"+ if dp[i - 1][0][0] + S[i][2] > dp[i - 1][1][0] + S[i][2]:",
"+ dp[i][2] = (dp[i - 1][0][0] + S[i][2], \"c\")",
"+ else:",
"+ dp[i][2] = (dp[i - 1][1][0] + S[i][2], \"c\")",
"+# print(dp)",
"+print((max(dp[N - 1])[0]))"
] | false | 0.056249 | 0.040009 | 1.405882 | [
"s474701893",
"s986832235"
] |
u644778646 | p03569 | python | s439686824 | s637483262 | 197 | 181 | 49,520 | 49,392 | Accepted | Accepted | 8.12 | def main():
s = list(eval(input()))
n = len(s)
ans = 0
l, r = 0, n-1
while l < r:
if s[l] == "x" and s[r] == "x":
l += 1
r -= 1
elif s[l] == "x":
l += 1
ans += 1
elif s[r] == "x":
r -= 1
ans += 1
elif s[l] == s[r]:
l += 1
r -= 1
else:
print((-1))
exit()
print(ans)
if __name__ == '__main__':
main()
| def main():
s = list(eval(input()))
n = len(s)
ans = 0
l, r = 0, n-1
while l < r:
if s[l] == s[r]:
l += 1
r -= 1
elif s[l] == "x":
l += 1
ans += 1
elif s[r] == "x":
r -= 1
ans += 1
else:
print((-1))
exit()
print(ans)
if __name__ == '__main__':
main() | 27 | 24 | 508 | 424 | def main():
s = list(eval(input()))
n = len(s)
ans = 0
l, r = 0, n - 1
while l < r:
if s[l] == "x" and s[r] == "x":
l += 1
r -= 1
elif s[l] == "x":
l += 1
ans += 1
elif s[r] == "x":
r -= 1
ans += 1
elif s[l] == s[r]:
l += 1
r -= 1
else:
print((-1))
exit()
print(ans)
if __name__ == "__main__":
main()
| def main():
s = list(eval(input()))
n = len(s)
ans = 0
l, r = 0, n - 1
while l < r:
if s[l] == s[r]:
l += 1
r -= 1
elif s[l] == "x":
l += 1
ans += 1
elif s[r] == "x":
r -= 1
ans += 1
else:
print((-1))
exit()
print(ans)
if __name__ == "__main__":
main()
| false | 11.111111 | [
"- if s[l] == \"x\" and s[r] == \"x\":",
"+ if s[l] == s[r]:",
"- elif s[l] == s[r]:",
"- l += 1",
"- r -= 1"
] | false | 0.036519 | 0.093516 | 0.39051 | [
"s439686824",
"s637483262"
] |
u469953228 | p03251 | python | s566103323 | s294430571 | 20 | 17 | 2,940 | 3,060 | Accepted | Accepted | 15 | n,m,x,y= list(map(int,input().split()))
lix=list(map(int,input().split()))
liy=list(map(int,input().split()))
lix.append(x)
liy.append(y)
if max(lix) < min(liy):
print("No War")
else:
print("War")
| n,m,x,y= list(map(int,input().split()))
lix=list(map(int,input().split()))
liy=list(map(int,input().split()))
lix.append(x)
liy.append(y)
lix.sort()
liy.sort()
if lix[n] < liy[0]:
print("No War")
else:
print("War")
| 9 | 11 | 203 | 223 | n, m, x, y = list(map(int, input().split()))
lix = list(map(int, input().split()))
liy = list(map(int, input().split()))
lix.append(x)
liy.append(y)
if max(lix) < min(liy):
print("No War")
else:
print("War")
| n, m, x, y = list(map(int, input().split()))
lix = list(map(int, input().split()))
liy = list(map(int, input().split()))
lix.append(x)
liy.append(y)
lix.sort()
liy.sort()
if lix[n] < liy[0]:
print("No War")
else:
print("War")
| false | 18.181818 | [
"-if max(lix) < min(liy):",
"+lix.sort()",
"+liy.sort()",
"+if lix[n] < liy[0]:"
] | false | 0.053099 | 0.057278 | 0.92704 | [
"s566103323",
"s294430571"
] |
u642874916 | p03569 | python | s273550161 | s765738299 | 210 | 64 | 47,468 | 4,596 | Accepted | Accepted | 69.52 | from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def show(*inp, end='\n'):
if show_flg:
print(*inp, end=end)
YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True
def main():
s = S()
d = deque(s)
ans = 0
# print(d)
while len(d) > 1:
if d[0] == d[-1]:
d.popleft()
d.pop()
elif d[0] == 'x':
d.append('x')
ans += 1
elif d[-1] == 'x':
d.appendleft('x')
ans += 1
else:
print(-1)
return
print(ans)
if __name__ == '__main__':
main()
| from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def show(*inp, end='\n'):
if show_flg:
print(*inp, end=end)
YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True
def main():
s = S()
d = deque(s)
ans = 0
while len(d) > 1:
l = d.popleft()
r = d.pop()
if l == r:
continue
elif l == 'x':
ans += 1
d.append(r)
elif r == 'x':
ans += 1
d.appendleft(l)
else:
print(-1)
return
print(ans)
if __name__ == '__main__':
main()
| 84 | 84 | 1,531 | 1,519 | from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
def I():
return int(input())
def S():
return input()
def MI():
return map(int, input().split())
def MS():
return map(str, input().split())
def LI():
return [int(i) for i in input().split()]
def LI_():
return [int(i) - 1 for i in input().split()]
def StoI():
return [ord(i) - 97 for i in input()]
def ItoS(nn):
return chr(nn + 97)
def input():
return sys.stdin.readline().rstrip()
def show(*inp, end="\n"):
if show_flg:
print(*inp, end=end)
YNL = {False: "No", True: "Yes"}
YNU = {False: "NO", True: "YES"}
MOD = 10**9 + 7
inf = float("inf")
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
show_flg = False
# show_flg = True
def main():
s = S()
d = deque(s)
ans = 0
# print(d)
while len(d) > 1:
if d[0] == d[-1]:
d.popleft()
d.pop()
elif d[0] == "x":
d.append("x")
ans += 1
elif d[-1] == "x":
d.appendleft("x")
ans += 1
else:
print(-1)
return
print(ans)
if __name__ == "__main__":
main()
| from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
def I():
return int(input())
def S():
return input()
def MI():
return map(int, input().split())
def MS():
return map(str, input().split())
def LI():
return [int(i) for i in input().split()]
def LI_():
return [int(i) - 1 for i in input().split()]
def StoI():
return [ord(i) - 97 for i in input()]
def ItoS(nn):
return chr(nn + 97)
def input():
return sys.stdin.readline().rstrip()
def show(*inp, end="\n"):
if show_flg:
print(*inp, end=end)
YNL = {False: "No", True: "Yes"}
YNU = {False: "NO", True: "YES"}
MOD = 10**9 + 7
inf = float("inf")
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
show_flg = False
# show_flg = True
def main():
s = S()
d = deque(s)
ans = 0
while len(d) > 1:
l = d.popleft()
r = d.pop()
if l == r:
continue
elif l == "x":
ans += 1
d.append(r)
elif r == "x":
ans += 1
d.appendleft(l)
else:
print(-1)
return
print(ans)
if __name__ == "__main__":
main()
| false | 0 | [
"-IINF = 10**10",
"+IINF = 10**19",
"- # print(d)",
"- if d[0] == d[-1]:",
"- d.popleft()",
"- d.pop()",
"- elif d[0] == \"x\":",
"- d.append(\"x\")",
"+ l = d.popleft()",
"+ r = d.pop()",
"+ if l == r:",
"+ continue",
"+ elif l == \"x\":",
"- elif d[-1] == \"x\":",
"- d.appendleft(\"x\")",
"+ d.append(r)",
"+ elif r == \"x\":",
"+ d.appendleft(l)"
] | false | 0.041519 | 0.042746 | 0.9713 | [
"s273550161",
"s765738299"
] |
u048945791 | p03240 | python | s492046296 | s311356535 | 105 | 88 | 3,064 | 3,064 | Accepted | Accepted | 16.19 | n = int(eval(input()))
x = []
y = []
h = []
for i in range(n):
xi, yi, hi = list(map(int, input().split()))
x.append(xi)
y.append(yi)
h.append(hi)
isOk = False
i = 0
j = 0
constant = -1
for i in range(101):
for j in range(101):
constant = -1
for k in range(n):
if h[k] != 0:
temp = h[k] + abs(i - x[k]) + abs(j - y[k])
if constant == -1:
constant = temp
if constant != temp:
break
else:
for p in range(n):
if h[p] == 0 and constant - abs(i - x[p]) - abs(j - y[p]) > 0:
break
else:
isOk = True
break
if isOk:
break
print((i, j, constant))
| n = int(eval(input()))
xyh = []
for i in range(n):
xyh.append(list(map(int, input().split())))
isOk = False
i = 0
j = 0
constant = -1
for i in range(101):
for j in range(101):
constant = -1
for xyhTemp in xyh:
if xyhTemp[2] != 0:
temp = xyhTemp[2] + abs(i - xyhTemp[0]) + abs(j - xyhTemp[1])
if constant == -1:
constant = temp
if constant != temp:
break
else:
for p in xyh:
if p[2] == 0 and constant - abs(i - p[0]) - abs(j - p[1]) > 0:
break
else:
isOk = True
break
if isOk:
break
print((i, j, constant))
| 43 | 39 | 839 | 799 | n = int(eval(input()))
x = []
y = []
h = []
for i in range(n):
xi, yi, hi = list(map(int, input().split()))
x.append(xi)
y.append(yi)
h.append(hi)
isOk = False
i = 0
j = 0
constant = -1
for i in range(101):
for j in range(101):
constant = -1
for k in range(n):
if h[k] != 0:
temp = h[k] + abs(i - x[k]) + abs(j - y[k])
if constant == -1:
constant = temp
if constant != temp:
break
else:
for p in range(n):
if h[p] == 0 and constant - abs(i - x[p]) - abs(j - y[p]) > 0:
break
else:
isOk = True
break
if isOk:
break
print((i, j, constant))
| n = int(eval(input()))
xyh = []
for i in range(n):
xyh.append(list(map(int, input().split())))
isOk = False
i = 0
j = 0
constant = -1
for i in range(101):
for j in range(101):
constant = -1
for xyhTemp in xyh:
if xyhTemp[2] != 0:
temp = xyhTemp[2] + abs(i - xyhTemp[0]) + abs(j - xyhTemp[1])
if constant == -1:
constant = temp
if constant != temp:
break
else:
for p in xyh:
if p[2] == 0 and constant - abs(i - p[0]) - abs(j - p[1]) > 0:
break
else:
isOk = True
break
if isOk:
break
print((i, j, constant))
| false | 9.302326 | [
"-x = []",
"-y = []",
"-h = []",
"+xyh = []",
"- xi, yi, hi = list(map(int, input().split()))",
"- x.append(xi)",
"- y.append(yi)",
"- h.append(hi)",
"+ xyh.append(list(map(int, input().split())))",
"- for k in range(n):",
"- if h[k] != 0:",
"- temp = h[k] + abs(i - x[k]) + abs(j - y[k])",
"+ for xyhTemp in xyh:",
"+ if xyhTemp[2] != 0:",
"+ temp = xyhTemp[2] + abs(i - xyhTemp[0]) + abs(j - xyhTemp[1])",
"- for p in range(n):",
"- if h[p] == 0 and constant - abs(i - x[p]) - abs(j - y[p]) > 0:",
"+ for p in xyh:",
"+ if p[2] == 0 and constant - abs(i - p[0]) - abs(j - p[1]) > 0:"
] | false | 0.039198 | 0.065279 | 0.600476 | [
"s492046296",
"s311356535"
] |
u364363327 | p02642 | python | s023138681 | s310702910 | 592 | 495 | 55,252 | 55,184 | Accepted | Accepted | 16.39 | import numpy as np
N = int(eval(input()))
A = list(map(int,input().split()))
A = np.array(A)
A.sort()
d = {}
for a in A:
d.setdefault(a,0)
d[a] += 1
sieve = [True] * (A[-1] + 1)
for a in A:
if d[a] > 1:
sieve[a] = False
for i in range(a + a, A[-1] + 1, a):
sieve[i] = False
print((sum(1 for a in A if sieve[a]))) | import numpy as np
N = int(eval(input()))
A = list(map(int,input().split()))
A = np.array(A)
A.sort()
d = {}
for a in A:
d.setdefault(a,0)
d[a] += 1
sieve = [True] * (A[-1] + 1)
for a in A:
if sieve[a] == False:
continue
if d[a] > 1:
sieve[a] = False
for i in range(a + a, A[-1] + 1, a):
sieve[i] = False
print((sum(1 for a in A if sieve[a]))) | 26 | 26 | 371 | 412 | import numpy as np
N = int(eval(input()))
A = list(map(int, input().split()))
A = np.array(A)
A.sort()
d = {}
for a in A:
d.setdefault(a, 0)
d[a] += 1
sieve = [True] * (A[-1] + 1)
for a in A:
if d[a] > 1:
sieve[a] = False
for i in range(a + a, A[-1] + 1, a):
sieve[i] = False
print((sum(1 for a in A if sieve[a])))
| import numpy as np
N = int(eval(input()))
A = list(map(int, input().split()))
A = np.array(A)
A.sort()
d = {}
for a in A:
d.setdefault(a, 0)
d[a] += 1
sieve = [True] * (A[-1] + 1)
for a in A:
if sieve[a] == False:
continue
if d[a] > 1:
sieve[a] = False
for i in range(a + a, A[-1] + 1, a):
sieve[i] = False
print((sum(1 for a in A if sieve[a])))
| false | 0 | [
"+ if sieve[a] == False:",
"+ continue"
] | false | 0.580555 | 0.225982 | 2.569029 | [
"s023138681",
"s310702910"
] |
u762955009 | p03012 | python | s038081033 | s099171014 | 174 | 18 | 38,384 | 2,940 | Accepted | Accepted | 89.66 | from itertools import accumulate
N = int(eval(input()))
W = list(accumulate([int(x) for x in input().split()]))
ans = 10**9
for i in range(N - 1):
ans = min(ans, abs(W[N - 1] - W[i]*2))
print(ans) | N = int(eval(input()))
W = [int(x) for x in input().split()]
s1 = 0
s2 = sum(W)
ans = 10**9
for w in W:
s1 += w
s2 -= w
ans = min(ans, abs(s1 -s2))
print(ans)
| 9 | 12 | 204 | 178 | from itertools import accumulate
N = int(eval(input()))
W = list(accumulate([int(x) for x in input().split()]))
ans = 10**9
for i in range(N - 1):
ans = min(ans, abs(W[N - 1] - W[i] * 2))
print(ans)
| N = int(eval(input()))
W = [int(x) for x in input().split()]
s1 = 0
s2 = sum(W)
ans = 10**9
for w in W:
s1 += w
s2 -= w
ans = min(ans, abs(s1 - s2))
print(ans)
| false | 25 | [
"-from itertools import accumulate",
"-",
"-W = list(accumulate([int(x) for x in input().split()]))",
"+W = [int(x) for x in input().split()]",
"+s1 = 0",
"+s2 = sum(W)",
"-for i in range(N - 1):",
"- ans = min(ans, abs(W[N - 1] - W[i] * 2))",
"+for w in W:",
"+ s1 += w",
"+ s2 -= w",
"+ ans = min(ans, abs(s1 - s2))"
] | false | 0.03822 | 0.037353 | 1.023218 | [
"s038081033",
"s099171014"
] |
u977389981 | p03088 | python | s464846112 | s166972737 | 128 | 43 | 3,856 | 3,316 | Accepted | Accepted | 66.41 | N = int(eval(input()))
mod = 10 ** 9 + 7
D = [{} for i in range(N + 1)]
def check(last4):
for i in range(4):
t = list(last4)
if i >= 1:
t[i - 1], t[i] = t[i], t[i - 1]
if ''.join(t).count('AGC') >= 1:
return False
return True
def dfs(cur, last3):
if last3 in D[cur]:
return D[cur][last3]
if cur == N:
return 1
res = 0
for c in 'ACGT':
if check(last3 + c):
res = (res + dfs(cur + 1, last3[1:] + c)) % mod
D[cur][last3] = res
return res
print((dfs(0, '000'))) | N = int(eval(input()))
mod = 10 ** 9 + 7
D = [[[[0] * 4 for i in range(4)] for i in range(4)] for i in range(101)]
D[0][3][3][3] = 1
for i in range(100):
for j in range(4):
for k in range(4):
for l in range(4):
for x in range(4):
if k == 0 and l == 1 and x == 2:
continue
if k == 0 and l == 2 and x == 1:
continue
if k == 1 and l == 0 and x == 2:
continue
if j == 0 and l == 1 and x == 2:
continue
if j == 0 and k == 1 and x == 2:
continue
D[i + 1][k][l][x] += D[i][j][k][l] % mod
D[i + 1][k][l][x] %= mod
ans = 0
for j in range(4):
for k in range(4):
for l in range(4):
ans += D[N][j][k][l]
ans %= mod
print(ans) | 26 | 31 | 601 | 1,016 | N = int(eval(input()))
mod = 10**9 + 7
D = [{} for i in range(N + 1)]
def check(last4):
for i in range(4):
t = list(last4)
if i >= 1:
t[i - 1], t[i] = t[i], t[i - 1]
if "".join(t).count("AGC") >= 1:
return False
return True
def dfs(cur, last3):
if last3 in D[cur]:
return D[cur][last3]
if cur == N:
return 1
res = 0
for c in "ACGT":
if check(last3 + c):
res = (res + dfs(cur + 1, last3[1:] + c)) % mod
D[cur][last3] = res
return res
print((dfs(0, "000")))
| N = int(eval(input()))
mod = 10**9 + 7
D = [[[[0] * 4 for i in range(4)] for i in range(4)] for i in range(101)]
D[0][3][3][3] = 1
for i in range(100):
for j in range(4):
for k in range(4):
for l in range(4):
for x in range(4):
if k == 0 and l == 1 and x == 2:
continue
if k == 0 and l == 2 and x == 1:
continue
if k == 1 and l == 0 and x == 2:
continue
if j == 0 and l == 1 and x == 2:
continue
if j == 0 and k == 1 and x == 2:
continue
D[i + 1][k][l][x] += D[i][j][k][l] % mod
D[i + 1][k][l][x] %= mod
ans = 0
for j in range(4):
for k in range(4):
for l in range(4):
ans += D[N][j][k][l]
ans %= mod
print(ans)
| false | 16.129032 | [
"-D = [{} for i in range(N + 1)]",
"-",
"-",
"-def check(last4):",
"- for i in range(4):",
"- t = list(last4)",
"- if i >= 1:",
"- t[i - 1], t[i] = t[i], t[i - 1]",
"- if \"\".join(t).count(\"AGC\") >= 1:",
"- return False",
"- return True",
"-",
"-",
"-def dfs(cur, last3):",
"- if last3 in D[cur]:",
"- return D[cur][last3]",
"- if cur == N:",
"- return 1",
"- res = 0",
"- for c in \"ACGT\":",
"- if check(last3 + c):",
"- res = (res + dfs(cur + 1, last3[1:] + c)) % mod",
"- D[cur][last3] = res",
"- return res",
"-",
"-",
"-print((dfs(0, \"000\")))",
"+D = [[[[0] * 4 for i in range(4)] for i in range(4)] for i in range(101)]",
"+D[0][3][3][3] = 1",
"+for i in range(100):",
"+ for j in range(4):",
"+ for k in range(4):",
"+ for l in range(4):",
"+ for x in range(4):",
"+ if k == 0 and l == 1 and x == 2:",
"+ continue",
"+ if k == 0 and l == 2 and x == 1:",
"+ continue",
"+ if k == 1 and l == 0 and x == 2:",
"+ continue",
"+ if j == 0 and l == 1 and x == 2:",
"+ continue",
"+ if j == 0 and k == 1 and x == 2:",
"+ continue",
"+ D[i + 1][k][l][x] += D[i][j][k][l] % mod",
"+ D[i + 1][k][l][x] %= mod",
"+ans = 0",
"+for j in range(4):",
"+ for k in range(4):",
"+ for l in range(4):",
"+ ans += D[N][j][k][l]",
"+ ans %= mod",
"+print(ans)"
] | false | 0.103903 | 0.066916 | 1.552739 | [
"s464846112",
"s166972737"
] |
u729133443 | p02708 | python | s746776060 | s983935424 | 55 | 20 | 67,444 | 9,096 | Accepted | Accepted | 63.64 | n,k=list(map(int,input().split()))
print((sum(-~i+i*(n-i)for i in range(k,n+2))%(10**9+7))) | n,k=list(map(int,input().split()))
print(((n-k+2)*((-k-~n)*(n+2*k)+6)//6%(10**9+7))) | 2 | 2 | 84 | 77 | n, k = list(map(int, input().split()))
print((sum(-~i + i * (n - i) for i in range(k, n + 2)) % (10**9 + 7)))
| n, k = list(map(int, input().split()))
print(((n - k + 2) * ((-k - ~n) * (n + 2 * k) + 6) // 6 % (10**9 + 7)))
| false | 0 | [
"-print((sum(-~i + i * (n - i) for i in range(k, n + 2)) % (10**9 + 7)))",
"+print(((n - k + 2) * ((-k - ~n) * (n + 2 * k) + 6) // 6 % (10**9 + 7)))"
] | false | 0.047044 | 0.035355 | 1.330635 | [
"s746776060",
"s983935424"
] |
u547167033 | p03388 | python | s451177323 | s185167188 | 21 | 19 | 3,064 | 3,064 | Accepted | Accepted | 9.52 | q=int(eval(input()))
for _ in range(q):
a,b=list(map(int,input().split()))
if a>b:
a,b=b,a
if a==b:
print((2*a-2))
elif a==b+1:
print((2*a-1))
else:
c=int((a*b)**0.5)
if c*c==a*b:
c-=1
if c*(c+1)>=a*b:
print((2*c-2))
else:
print((2*c-1)) | q=int(eval(input()))
for _ in range(q):
a,b=list(map(int,input().split()))
if a>b:
a,b=b,a
if a==b:
print((2*a-2))
elif b==a+1:
print((2*a-2))
else:
c=int((a*b)**0.5)-1
while (c+1)*(c+1)<a*b:
c+=1
if c*(c+1)>=a*b:
print((2*c-2))
else:
print((2*c-1)) | 17 | 17 | 289 | 301 | q = int(eval(input()))
for _ in range(q):
a, b = list(map(int, input().split()))
if a > b:
a, b = b, a
if a == b:
print((2 * a - 2))
elif a == b + 1:
print((2 * a - 1))
else:
c = int((a * b) ** 0.5)
if c * c == a * b:
c -= 1
if c * (c + 1) >= a * b:
print((2 * c - 2))
else:
print((2 * c - 1))
| q = int(eval(input()))
for _ in range(q):
a, b = list(map(int, input().split()))
if a > b:
a, b = b, a
if a == b:
print((2 * a - 2))
elif b == a + 1:
print((2 * a - 2))
else:
c = int((a * b) ** 0.5) - 1
while (c + 1) * (c + 1) < a * b:
c += 1
if c * (c + 1) >= a * b:
print((2 * c - 2))
else:
print((2 * c - 1))
| false | 0 | [
"- elif a == b + 1:",
"- print((2 * a - 1))",
"+ elif b == a + 1:",
"+ print((2 * a - 2))",
"- c = int((a * b) ** 0.5)",
"- if c * c == a * b:",
"- c -= 1",
"+ c = int((a * b) ** 0.5) - 1",
"+ while (c + 1) * (c + 1) < a * b:",
"+ c += 1"
] | false | 0.097739 | 0.15049 | 0.649476 | [
"s451177323",
"s185167188"
] |
u340781749 | p03283 | python | s709820795 | s593558869 | 937 | 464 | 17,524 | 37,064 | Accepted | Accepted | 50.48 | from itertools import accumulate
n, m, q = list(map(int, input().split()))
rails = [[0] * n for _ in range(n)]
for _ in range(m):
l, r = list(map(int, input().split()))
rails[l - 1][r - 1] += 1
rails = [list(accumulate(s)) for s in rails]
rails = [list(reversed(list(accumulate(reversed(s))))) for s in zip(*rails)]
buf = []
for _ in range(q):
p, q = list(map(int, input().split()))
buf.append(rails[q - 1][p - 1])
print(('\n'.join(map(str, buf))))
| import sys
from itertools import accumulate
n, m, q = list(map(int, input().split()))
ipt = sys.stdin.readlines()
rails = [[0] * n for _ in range(n)]
for l, r in (list(map(int, line.split())) for line in ipt[:m]):
rails[l - 1][r - 1] += 1
rails = [list(reversed(list(accumulate(reversed(s))))) for s in zip(*(accumulate(s) for s in rails))]
print(('\n'.join(str(rails[q - 1][p - 1]) for p, q in (list(map(int, line.split())) for line in ipt[m:]))))
| 14 | 10 | 459 | 443 | from itertools import accumulate
n, m, q = list(map(int, input().split()))
rails = [[0] * n for _ in range(n)]
for _ in range(m):
l, r = list(map(int, input().split()))
rails[l - 1][r - 1] += 1
rails = [list(accumulate(s)) for s in rails]
rails = [list(reversed(list(accumulate(reversed(s))))) for s in zip(*rails)]
buf = []
for _ in range(q):
p, q = list(map(int, input().split()))
buf.append(rails[q - 1][p - 1])
print(("\n".join(map(str, buf))))
| import sys
from itertools import accumulate
n, m, q = list(map(int, input().split()))
ipt = sys.stdin.readlines()
rails = [[0] * n for _ in range(n)]
for l, r in (list(map(int, line.split())) for line in ipt[:m]):
rails[l - 1][r - 1] += 1
rails = [
list(reversed(list(accumulate(reversed(s)))))
for s in zip(*(accumulate(s) for s in rails))
]
print(
(
"\n".join(
str(rails[q - 1][p - 1])
for p, q in (list(map(int, line.split())) for line in ipt[m:])
)
)
)
| false | 28.571429 | [
"+import sys",
"+ipt = sys.stdin.readlines()",
"-for _ in range(m):",
"- l, r = list(map(int, input().split()))",
"+for l, r in (list(map(int, line.split())) for line in ipt[:m]):",
"-rails = [list(accumulate(s)) for s in rails]",
"-rails = [list(reversed(list(accumulate(reversed(s))))) for s in zip(*rails)]",
"-buf = []",
"-for _ in range(q):",
"- p, q = list(map(int, input().split()))",
"- buf.append(rails[q - 1][p - 1])",
"-print((\"\\n\".join(map(str, buf))))",
"+rails = [",
"+ list(reversed(list(accumulate(reversed(s)))))",
"+ for s in zip(*(accumulate(s) for s in rails))",
"+]",
"+print(",
"+ (",
"+ \"\\n\".join(",
"+ str(rails[q - 1][p - 1])",
"+ for p, q in (list(map(int, line.split())) for line in ipt[m:])",
"+ )",
"+ )",
"+)"
] | false | 0.03733 | 0.069206 | 0.539411 | [
"s709820795",
"s593558869"
] |
u296518383 | p02804 | python | s590534868 | s390922709 | 299 | 267 | 84,464 | 77,608 | Accepted | Accepted | 10.7 | def cmb(n, r, mod):
if ( r < 0 or r > n ):
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % mod
MOD = 10 ** 9 + 7 #出力の制限
N = 10 ** 5 * 2 + 1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range(2, N + 1 ):
g1.append((g1[-1] * i) % MOD)
inverse.append((-inverse[MOD % i] * (MOD // i) ) % MOD)
g2.append((g2[-1] * inverse[-1]) % MOD)
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
answer = 0
for i in range(N):
if i > N - K:
break
answer = (answer + (A[N - i - 1] - A[i]) * cmb(N - 1 - i, K - 1, MOD)) % MOD
print(answer) | N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7
### Combination Table ###
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル
def comb(n, r, mod):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % mod
for i in range(2, N + 1):
g1.append((g1[-1] * i) % MOD)
inverse.append((-inverse[MOD % i] * (MOD // i) ) % MOD)
g2.append((g2[-1] * inverse[-1]) % MOD)
#########################
A.sort()
answer = 0
for i in range(N):
if i > N - K:
break
answer = (answer + (A[N - i - 1] - A[i]) * comb(N - 1 - i, K - 1, MOD)) % MOD
print(answer)
| 29 | 30 | 657 | 693 | def cmb(n, r, mod):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % mod
MOD = 10**9 + 7 # 出力の制限
N = 10**5 * 2 + 1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル
for i in range(2, N + 1):
g1.append((g1[-1] * i) % MOD)
inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)
g2.append((g2[-1] * inverse[-1]) % MOD)
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
answer = 0
for i in range(N):
if i > N - K:
break
answer = (answer + (A[N - i - 1] - A[i]) * cmb(N - 1 - i, K - 1, MOD)) % MOD
print(answer)
| N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
MOD = 10**9 + 7
### Combination Table ###
g1 = [1, 1] # 元テーブル
g2 = [1, 1] # 逆元テーブル
inverse = [0, 1] # 逆元テーブル計算用テーブル
def comb(n, r, mod):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return g1[n] * g2[r] * g2[n - r] % mod
for i in range(2, N + 1):
g1.append((g1[-1] * i) % MOD)
inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)
g2.append((g2[-1] * inverse[-1]) % MOD)
#########################
A.sort()
answer = 0
for i in range(N):
if i > N - K:
break
answer = (answer + (A[N - i - 1] - A[i]) * comb(N - 1 - i, K - 1, MOD)) % MOD
print(answer)
| false | 3.333333 | [
"-def cmb(n, r, mod):",
"+N, K = list(map(int, input().split()))",
"+A = list(map(int, input().split()))",
"+MOD = 10**9 + 7",
"+### Combination Table ###",
"+g1 = [1, 1] # 元テーブル",
"+g2 = [1, 1] # 逆元テーブル",
"+inverse = [0, 1] # 逆元テーブル計算用テーブル",
"+",
"+",
"+def comb(n, r, mod):",
"-MOD = 10**9 + 7 # 出力の制限",
"-N = 10**5 * 2 + 1",
"-g1 = [1, 1] # 元テーブル",
"-g2 = [1, 1] # 逆元テーブル",
"-inverse = [0, 1] # 逆元テーブル計算用テーブル",
"-N, K = list(map(int, input().split()))",
"-A = list(map(int, input().split()))",
"+#########################",
"- answer = (answer + (A[N - i - 1] - A[i]) * cmb(N - 1 - i, K - 1, MOD)) % MOD",
"+ answer = (answer + (A[N - i - 1] - A[i]) * comb(N - 1 - i, K - 1, MOD)) % MOD"
] | false | 0.865636 | 0.04766 | 18.162776 | [
"s590534868",
"s390922709"
] |
u499381410 | p02695 | python | s972089015 | s346437192 | 337 | 208 | 82,468 | 77,604 | Accepted | Accepted | 38.28 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from operator import mul
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, m, q = LI()
L = LIR(q)
ans = 0
def f(arr):
global ans
if len(arr) == n:
ret = 0
for a, b, c, d in L:
if arr[b - 1] - arr[a - 1] == c:
ret += d
ans = max(ans, ret)
else:
if arr:
for k in range(arr[-1], m + 1):
f(arr + [k])
else:
for k in range(1, m + 1):
f(arr + [k])
f([])
print(ans) | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from itertools import combinations_with_replacement, combinations
from operator import mul
from functools import reduce
from operator import mul
sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, m, q = LI()
L = LIR(q)
ans = 0
for arr in combinations_with_replacement(list(range(1, m + 1)), n):
ret = 0
for a, b, c, d in L:
if arr[b - 1] - arr[a - 1] == c:
ret += d
ans = max(ans, ret)
print(ans)
| 51 | 47 | 1,493 | 1,368 | from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from operator import mul
sys.setrecursionlimit(2147483647)
INF = 10**20
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def I():
return int(sys.stdin.buffer.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, m, q = LI()
L = LIR(q)
ans = 0
def f(arr):
global ans
if len(arr) == n:
ret = 0
for a, b, c, d in L:
if arr[b - 1] - arr[a - 1] == c:
ret += d
ans = max(ans, ret)
else:
if arr:
for k in range(arr[-1], m + 1):
f(arr + [k])
else:
for k in range(1, m + 1):
f(arr + [k])
f([])
print(ans)
| from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from itertools import combinations_with_replacement, combinations
from operator import mul
from functools import reduce
from operator import mul
sys.setrecursionlimit(2147483647)
INF = 10**20
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def I():
return int(sys.stdin.buffer.readline())
def LS():
return sys.stdin.buffer.readline().rstrip().decode("utf-8").split()
def S():
return sys.stdin.buffer.readline().rstrip().decode("utf-8")
def IR(n):
return [I() for i in range(n)]
def LIR(n):
return [LI() for i in range(n)]
def SR(n):
return [S() for i in range(n)]
def LSR(n):
return [LS() for i in range(n)]
def SRL(n):
return [list(S()) for i in range(n)]
def MSRL(n):
return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007
n, m, q = LI()
L = LIR(q)
ans = 0
for arr in combinations_with_replacement(list(range(1, m + 1)), n):
ret = 0
for a, b, c, d in L:
if arr[b - 1] - arr[a - 1] == c:
ret += d
ans = max(ans, ret)
print(ans)
| false | 7.843137 | [
"+from itertools import combinations_with_replacement, combinations",
"-",
"-",
"-def f(arr):",
"- global ans",
"- if len(arr) == n:",
"- ret = 0",
"- for a, b, c, d in L:",
"- if arr[b - 1] - arr[a - 1] == c:",
"- ret += d",
"- ans = max(ans, ret)",
"- else:",
"- if arr:",
"- for k in range(arr[-1], m + 1):",
"- f(arr + [k])",
"- else:",
"- for k in range(1, m + 1):",
"- f(arr + [k])",
"-",
"-",
"-f([])",
"+for arr in combinations_with_replacement(list(range(1, m + 1)), n):",
"+ ret = 0",
"+ for a, b, c, d in L:",
"+ if arr[b - 1] - arr[a - 1] == c:",
"+ ret += d",
"+ ans = max(ans, ret)"
] | false | 0.148165 | 0.047298 | 3.132591 | [
"s972089015",
"s346437192"
] |
u600402037 | p03673 | python | s806943404 | s586000285 | 210 | 177 | 26,356 | 26,180 | Accepted | Accepted | 15.71 | N = int(eval(input()))
A = list(map(int, input().split()))
right = []
left = []
for i in range(N):
if i % 2 == 0:
right.append(A[i])
else:
left.append(A[i])
answer = left[::-1]
answer += right
if N%2 == 1:
answer = answer[::-1]
print((*answer))
| N=int(input())
A=list(map(int,input().split()))
print(*A[::-2], end=' ')
print(*A[N%2::2])
| 16 | 4 | 295 | 93 | N = int(eval(input()))
A = list(map(int, input().split()))
right = []
left = []
for i in range(N):
if i % 2 == 0:
right.append(A[i])
else:
left.append(A[i])
answer = left[::-1]
answer += right
if N % 2 == 1:
answer = answer[::-1]
print((*answer))
| N = int(input())
A = list(map(int, input().split()))
print(*A[::-2], end=" ")
print(*A[N % 2 :: 2])
| false | 75 | [
"-N = int(eval(input()))",
"+N = int(input())",
"-right = []",
"-left = []",
"-for i in range(N):",
"- if i % 2 == 0:",
"- right.append(A[i])",
"- else:",
"- left.append(A[i])",
"-answer = left[::-1]",
"-answer += right",
"-if N % 2 == 1:",
"- answer = answer[::-1]",
"-print((*answer))",
"+print(*A[::-2], end=\" \")",
"+print(*A[N % 2 :: 2])"
] | false | 0.03743 | 0.038986 | 0.960087 | [
"s806943404",
"s586000285"
] |
u489959379 | p03475 | python | s425247157 | s061619463 | 121 | 55 | 3,064 | 3,188 | Accepted | Accepted | 54.55 | n = int(eval(input()))
C, S, F = [], [], []
for i in range(n - 1):
c, s, f = list(map(int, input().split()))
C.append(c)
S.append(s)
F.append(f)
for i in range(n):
t = 0
for j in range(i, n - 1):
if t <= S[j]:
t = S[j]
elif (t - S[j]) % F[j] == 0:
pass
else:
t += F[j] - (t - S[j]) % F[j]
t += C[j]
print(t) | import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n = int(eval(input()))
CSF = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(n):
if i == n - 1:
print((0))
break
c1, s1, _ = CSF[i]
t = s1 + c1
for j in range(i + 1, n - 1):
c2, s2, f2 = CSF[j]
if t <= s2:
t = s2 + c2
else:
if t % f2 == 0:
wait = 0
else:
wait = f2 - (t - s2) % f2
t += c2 + wait
print(t)
if __name__ == '__main__':
resolve()
| 19 | 33 | 411 | 738 | n = int(eval(input()))
C, S, F = [], [], []
for i in range(n - 1):
c, s, f = list(map(int, input().split()))
C.append(c)
S.append(s)
F.append(f)
for i in range(n):
t = 0
for j in range(i, n - 1):
if t <= S[j]:
t = S[j]
elif (t - S[j]) % F[j] == 0:
pass
else:
t += F[j] - (t - S[j]) % F[j]
t += C[j]
print(t)
| import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7
def resolve():
n = int(eval(input()))
CSF = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(n):
if i == n - 1:
print((0))
break
c1, s1, _ = CSF[i]
t = s1 + c1
for j in range(i + 1, n - 1):
c2, s2, f2 = CSF[j]
if t <= s2:
t = s2 + c2
else:
if t % f2 == 0:
wait = 0
else:
wait = f2 - (t - s2) % f2
t += c2 + wait
print(t)
if __name__ == "__main__":
resolve()
| false | 42.424242 | [
"-n = int(eval(input()))",
"-C, S, F = [], [], []",
"-for i in range(n - 1):",
"- c, s, f = list(map(int, input().split()))",
"- C.append(c)",
"- S.append(s)",
"- F.append(f)",
"-for i in range(n):",
"- t = 0",
"- for j in range(i, n - 1):",
"- if t <= S[j]:",
"- t = S[j]",
"- elif (t - S[j]) % F[j] == 0:",
"- pass",
"- else:",
"- t += F[j] - (t - S[j]) % F[j]",
"- t += C[j]",
"- print(t)",
"+import sys",
"+",
"+sys.setrecursionlimit(10**7)",
"+input = sys.stdin.readline",
"+f_inf = float(\"inf\")",
"+mod = 10**9 + 7",
"+",
"+",
"+def resolve():",
"+ n = int(eval(input()))",
"+ CSF = [list(map(int, input().split())) for _ in range(n - 1)]",
"+ for i in range(n):",
"+ if i == n - 1:",
"+ print((0))",
"+ break",
"+ c1, s1, _ = CSF[i]",
"+ t = s1 + c1",
"+ for j in range(i + 1, n - 1):",
"+ c2, s2, f2 = CSF[j]",
"+ if t <= s2:",
"+ t = s2 + c2",
"+ else:",
"+ if t % f2 == 0:",
"+ wait = 0",
"+ else:",
"+ wait = f2 - (t - s2) % f2",
"+ t += c2 + wait",
"+ print(t)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ resolve()"
] | false | 0.048021 | 0.081708 | 0.587712 | [
"s425247157",
"s061619463"
] |
u866769581 | p03069 | python | s273811552 | s785070380 | 102 | 77 | 19,304 | 3,500 | Accepted | Accepted | 24.51 | n = int(eval(input()))
s = eval(input())
lis = []
ws=s.count('.')
lis.append(ws)
bs = 0
for x in s:
if x == '#':
bs += 1
lis.append(bs+ws)
else:
ws -= 1
lis.append(bs+ws)
print((min(lis)))
| n = int(eval(input()))
s = eval(input())
bs = 0
ws = s.count('.')
ans = ws
for c in s:
if c == '.':
ws -= 1
else:
bs += 1
now = ws + bs
if ans > now:
ans = now
print(ans)
| 14 | 14 | 224 | 212 | n = int(eval(input()))
s = eval(input())
lis = []
ws = s.count(".")
lis.append(ws)
bs = 0
for x in s:
if x == "#":
bs += 1
lis.append(bs + ws)
else:
ws -= 1
lis.append(bs + ws)
print((min(lis)))
| n = int(eval(input()))
s = eval(input())
bs = 0
ws = s.count(".")
ans = ws
for c in s:
if c == ".":
ws -= 1
else:
bs += 1
now = ws + bs
if ans > now:
ans = now
print(ans)
| false | 0 | [
"-lis = []",
"+bs = 0",
"-lis.append(ws)",
"-bs = 0",
"-for x in s:",
"- if x == \"#\":",
"+ans = ws",
"+for c in s:",
"+ if c == \".\":",
"+ ws -= 1",
"+ else:",
"- lis.append(bs + ws)",
"- else:",
"- ws -= 1",
"- lis.append(bs + ws)",
"-print((min(lis)))",
"+ now = ws + bs",
"+ if ans > now:",
"+ ans = now",
"+print(ans)"
] | false | 0.077539 | 0.115731 | 0.669991 | [
"s273811552",
"s785070380"
] |
u046187684 | p02597 | python | s505242071 | s051729062 | 63 | 28 | 10,812 | 9,388 | Accepted | Accepted | 55.56 | def solve(string):
n, c = string.split()
n, c = int(n), list(c)
wi, ri = 0, n - 1
while wi < n and c[wi] == "R":
wi += 1
while ri >= 0 and c[ri] == "W":
ri -= 1
ans = 0
while wi < n and ri >= 0 and wi < ri:
c[wi], c[ri], ans = c[ri], c[wi], ans + 1
wi, ri = wi + 1, ri - 1
while wi < n and c[wi] == "R":
wi += 1
while ri >= 0 and c[ri] == "W":
ri -= 1
return str(ans)
if __name__ == '__main__':
import sys
print((solve(sys.stdin.read().strip())))
| def solve(string):
_, c = string.split()
r = c.count("R")
return str(c[:r].count("W"))
if __name__ == '__main__':
import sys
print((solve(sys.stdin.read().strip())))
| 22 | 9 | 580 | 194 | def solve(string):
n, c = string.split()
n, c = int(n), list(c)
wi, ri = 0, n - 1
while wi < n and c[wi] == "R":
wi += 1
while ri >= 0 and c[ri] == "W":
ri -= 1
ans = 0
while wi < n and ri >= 0 and wi < ri:
c[wi], c[ri], ans = c[ri], c[wi], ans + 1
wi, ri = wi + 1, ri - 1
while wi < n and c[wi] == "R":
wi += 1
while ri >= 0 and c[ri] == "W":
ri -= 1
return str(ans)
if __name__ == "__main__":
import sys
print((solve(sys.stdin.read().strip())))
| def solve(string):
_, c = string.split()
r = c.count("R")
return str(c[:r].count("W"))
if __name__ == "__main__":
import sys
print((solve(sys.stdin.read().strip())))
| false | 59.090909 | [
"- n, c = string.split()",
"- n, c = int(n), list(c)",
"- wi, ri = 0, n - 1",
"- while wi < n and c[wi] == \"R\":",
"- wi += 1",
"- while ri >= 0 and c[ri] == \"W\":",
"- ri -= 1",
"- ans = 0",
"- while wi < n and ri >= 0 and wi < ri:",
"- c[wi], c[ri], ans = c[ri], c[wi], ans + 1",
"- wi, ri = wi + 1, ri - 1",
"- while wi < n and c[wi] == \"R\":",
"- wi += 1",
"- while ri >= 0 and c[ri] == \"W\":",
"- ri -= 1",
"- return str(ans)",
"+ _, c = string.split()",
"+ r = c.count(\"R\")",
"+ return str(c[:r].count(\"W\"))"
] | false | 0.036902 | 0.041782 | 0.883213 | [
"s505242071",
"s051729062"
] |
u254871849 | p03731 | python | s132765927 | s582081599 | 156 | 99 | 25,196 | 25,132 | Accepted | Accepted | 36.54 | N, T = [int(i) for i in input().split()]
t = [int(t) for t in input().split()]
total = T
for i in range(N-1):
if t[i+1] - t[i] < T:
total += t[i+1] - t[i]
else:
total += T
print(total)
| import sys
n, T, *t = list(map(int, sys.stdin.read().split()))
def main():
start = 0
will_stop = T
running_time = 0
for i in range(1, n):
cur = t[i]
if cur < will_stop:
running_time += cur - start
else:
running_time += T
start = cur
will_stop = cur + T
running_time += T
return running_time
if __name__ == '__main__':
ans = main()
print(ans) | 11 | 23 | 221 | 457 | N, T = [int(i) for i in input().split()]
t = [int(t) for t in input().split()]
total = T
for i in range(N - 1):
if t[i + 1] - t[i] < T:
total += t[i + 1] - t[i]
else:
total += T
print(total)
| import sys
n, T, *t = list(map(int, sys.stdin.read().split()))
def main():
start = 0
will_stop = T
running_time = 0
for i in range(1, n):
cur = t[i]
if cur < will_stop:
running_time += cur - start
else:
running_time += T
start = cur
will_stop = cur + T
running_time += T
return running_time
if __name__ == "__main__":
ans = main()
print(ans)
| false | 52.173913 | [
"-N, T = [int(i) for i in input().split()]",
"-t = [int(t) for t in input().split()]",
"-total = T",
"-for i in range(N - 1):",
"- if t[i + 1] - t[i] < T:",
"- total += t[i + 1] - t[i]",
"- else:",
"- total += T",
"-print(total)",
"+import sys",
"+",
"+n, T, *t = list(map(int, sys.stdin.read().split()))",
"+",
"+",
"+def main():",
"+ start = 0",
"+ will_stop = T",
"+ running_time = 0",
"+ for i in range(1, n):",
"+ cur = t[i]",
"+ if cur < will_stop:",
"+ running_time += cur - start",
"+ else:",
"+ running_time += T",
"+ start = cur",
"+ will_stop = cur + T",
"+ running_time += T",
"+ return running_time",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ ans = main()",
"+ print(ans)"
] | false | 0.04214 | 0.042835 | 0.983788 | [
"s132765927",
"s582081599"
] |
u488401358 | p03562 | python | s299818393 | s947434116 | 550 | 254 | 85,416 | 85,184 | Accepted | Accepted | 53.82 | import random
mod=998244353
N,X=input().split()
N=int(N)
A=[]
for i in range(N):
A.append(int(eval(input()),2))
A.sort()
a=A[-1]
M=max(len(X)-1,a.bit_length()-1)
data=[0]*(M+1)
n=a.bit_length()-1
for i in range(M-n,-1,-1):
data[i+n]=a<<i
for i in range(0,N-1):
a=A[i]
flag=True
while flag:
n=a.bit_length()
for j in range(n-1,-1,-1):
a=min(a,a^data[j])
if a!=0:
data[a.bit_length()-1]=a
id=a.bit_length()-1
while data[id+1]==0:
data[id+1]=min((data[id]<<1)^a,(data[id]<<1))
if data[id+1]:
id+=1
else:
flag=False
else:
a=data[id]<<1
else:
break
data2=[0]*(M+1)
for i in range(M+1):
data2[i]=(data[i]!=0)
for i in range(1,M+1):
data2[i]+=data2[i-1]
data2=[0]+data2
#print(data)
#print(data2)
x=0
ans=0
n=len(X)-1
for i in range(len(X)):
if X[i]=="1":
if x>>(n-i)&1==1:
if data[n-i]:
ans+=pow(2,data2[n-i],mod)
ans%=mod
else:
ans+=pow(2,data2[n-i],mod)
ans%=mod
if data[n-i]:
x=x^data[n-i]
else:
break
else:
if x>>(n-i)&1==1:
if data[n-i]:
x=x^data[n-i]
else:
break
else:
continue
else:
ans+=1
ans%=mod
print(ans) | import random
mod=998244353
N,X=input().split()
N=int(N)
A=[]
for i in range(N):
A.append(int(eval(input()),2))
A.sort()
a=A[-1]
M=max(len(X)-1,a.bit_length()-1)
data=[0]*(M+1)
n=a.bit_length()-1
for i in range(M-n,-1,-1):
data[i+n]=a<<i
low=n
for i in range(0,N-1):
a=A[i]
flag=True
while flag:
n=a.bit_length()
for j in range(n-1,low-1,-1):
a=min(a,a^data[j])
if a!=0:
data[a.bit_length()-1]=a
id=a.bit_length()-1
low=id
while data[id+1]==0:
data[id+1]=min((data[id]<<1)^a,(data[id]<<1))
id+=1
else:
a=data[id]<<1
else:
break
data2=[0]*(M+1)
for i in range(M+1):
data2[i]=(data[i]!=0)
for i in range(1,M+1):
data2[i]+=data2[i-1]
data2=[0]+data2
#print(data)
#print(data2)
x=0
ans=0
n=len(X)-1
for i in range(len(X)):
if X[i]=="1":
if x>>(n-i)&1==1:
if data[n-i]:
ans+=pow(2,data2[n-i],mod)
ans%=mod
else:
ans+=pow(2,data2[n-i],mod)
ans%=mod
if data[n-i]:
x=x^data[n-i]
else:
break
else:
if x>>(n-i)&1==1:
if data[n-i]:
x=x^data[n-i]
else:
break
else:
continue
else:
ans+=1
ans%=mod
print(ans)
| 78 | 77 | 1,565 | 1,505 | import random
mod = 998244353
N, X = input().split()
N = int(N)
A = []
for i in range(N):
A.append(int(eval(input()), 2))
A.sort()
a = A[-1]
M = max(len(X) - 1, a.bit_length() - 1)
data = [0] * (M + 1)
n = a.bit_length() - 1
for i in range(M - n, -1, -1):
data[i + n] = a << i
for i in range(0, N - 1):
a = A[i]
flag = True
while flag:
n = a.bit_length()
for j in range(n - 1, -1, -1):
a = min(a, a ^ data[j])
if a != 0:
data[a.bit_length() - 1] = a
id = a.bit_length() - 1
while data[id + 1] == 0:
data[id + 1] = min((data[id] << 1) ^ a, (data[id] << 1))
if data[id + 1]:
id += 1
else:
flag = False
else:
a = data[id] << 1
else:
break
data2 = [0] * (M + 1)
for i in range(M + 1):
data2[i] = data[i] != 0
for i in range(1, M + 1):
data2[i] += data2[i - 1]
data2 = [0] + data2
# print(data)
# print(data2)
x = 0
ans = 0
n = len(X) - 1
for i in range(len(X)):
if X[i] == "1":
if x >> (n - i) & 1 == 1:
if data[n - i]:
ans += pow(2, data2[n - i], mod)
ans %= mod
else:
ans += pow(2, data2[n - i], mod)
ans %= mod
if data[n - i]:
x = x ^ data[n - i]
else:
break
else:
if x >> (n - i) & 1 == 1:
if data[n - i]:
x = x ^ data[n - i]
else:
break
else:
continue
else:
ans += 1
ans %= mod
print(ans)
| import random
mod = 998244353
N, X = input().split()
N = int(N)
A = []
for i in range(N):
A.append(int(eval(input()), 2))
A.sort()
a = A[-1]
M = max(len(X) - 1, a.bit_length() - 1)
data = [0] * (M + 1)
n = a.bit_length() - 1
for i in range(M - n, -1, -1):
data[i + n] = a << i
low = n
for i in range(0, N - 1):
a = A[i]
flag = True
while flag:
n = a.bit_length()
for j in range(n - 1, low - 1, -1):
a = min(a, a ^ data[j])
if a != 0:
data[a.bit_length() - 1] = a
id = a.bit_length() - 1
low = id
while data[id + 1] == 0:
data[id + 1] = min((data[id] << 1) ^ a, (data[id] << 1))
id += 1
else:
a = data[id] << 1
else:
break
data2 = [0] * (M + 1)
for i in range(M + 1):
data2[i] = data[i] != 0
for i in range(1, M + 1):
data2[i] += data2[i - 1]
data2 = [0] + data2
# print(data)
# print(data2)
x = 0
ans = 0
n = len(X) - 1
for i in range(len(X)):
if X[i] == "1":
if x >> (n - i) & 1 == 1:
if data[n - i]:
ans += pow(2, data2[n - i], mod)
ans %= mod
else:
ans += pow(2, data2[n - i], mod)
ans %= mod
if data[n - i]:
x = x ^ data[n - i]
else:
break
else:
if x >> (n - i) & 1 == 1:
if data[n - i]:
x = x ^ data[n - i]
else:
break
else:
continue
else:
ans += 1
ans %= mod
print(ans)
| false | 1.282051 | [
"+low = n",
"- for j in range(n - 1, -1, -1):",
"+ for j in range(n - 1, low - 1, -1):",
"+ low = id",
"- if data[id + 1]:",
"- id += 1",
"- else:",
"- flag = False",
"+ id += 1"
] | false | 0.035169 | 0.076764 | 0.458146 | [
"s299818393",
"s947434116"
] |
u321035578 | p03634 | python | s234656581 | s751444979 | 1,467 | 940 | 52,420 | 51,772 | Accepted | Accepted | 35.92 | import queue
def main():
n = int(eval(input()))
a = []
b = []
c = []
lst = [[] for _ in range(n)]
for i in range(n - 1):
aa, bb, cc = list(map(int,input().split()))
lst[aa - 1].append((bb - 1, cc))
lst[bb - 1].append((aa - 1, cc))
q, k = list(map(int,input().split()))
x = []
y = []
for i in range(q):
xx, yy = list(map(int,input().split()))
x.append(xx - 1)
y.append(yy - 1)
qq = queue.Queue()
qq.put(k - 1)
dist = [0] * n
while not qq.empty():
now = qq.get()
for to, w in lst[now]:
if dist[to] != 0:
continue
dist[to] = dist[now] + w
qq.put(to)
for i in range(q):
print((dist[x[i]] + dist[y[i]]))
if __name__ == '__main__':
main()
| from collections import deque
def main():
n = int(eval(input()))
a = []
b = []
c = []
lst = [[] for _ in range(n)]
for i in range(n - 1):
aa, bb, cc = list(map(int,input().split()))
lst[aa - 1].append((bb - 1, cc))
lst[bb - 1].append((aa - 1, cc))
q, k = list(map(int,input().split()))
x = []
y = []
for i in range(q):
xx, yy = list(map(int,input().split()))
x.append(xx - 1)
y.append(yy - 1)
qq = deque()
qq.append(k - 1)
dist = [0] * n
while len(qq) != 0:
now = qq.popleft()
for to, w in lst[now]:
if dist[to] != 0:
continue
dist[to] = dist[now] + w
qq.append(to)
for i in range(q):
print((dist[x[i]] + dist[y[i]]))
if __name__ == '__main__':
main()
| 40 | 40 | 842 | 861 | import queue
def main():
n = int(eval(input()))
a = []
b = []
c = []
lst = [[] for _ in range(n)]
for i in range(n - 1):
aa, bb, cc = list(map(int, input().split()))
lst[aa - 1].append((bb - 1, cc))
lst[bb - 1].append((aa - 1, cc))
q, k = list(map(int, input().split()))
x = []
y = []
for i in range(q):
xx, yy = list(map(int, input().split()))
x.append(xx - 1)
y.append(yy - 1)
qq = queue.Queue()
qq.put(k - 1)
dist = [0] * n
while not qq.empty():
now = qq.get()
for to, w in lst[now]:
if dist[to] != 0:
continue
dist[to] = dist[now] + w
qq.put(to)
for i in range(q):
print((dist[x[i]] + dist[y[i]]))
if __name__ == "__main__":
main()
| from collections import deque
def main():
n = int(eval(input()))
a = []
b = []
c = []
lst = [[] for _ in range(n)]
for i in range(n - 1):
aa, bb, cc = list(map(int, input().split()))
lst[aa - 1].append((bb - 1, cc))
lst[bb - 1].append((aa - 1, cc))
q, k = list(map(int, input().split()))
x = []
y = []
for i in range(q):
xx, yy = list(map(int, input().split()))
x.append(xx - 1)
y.append(yy - 1)
qq = deque()
qq.append(k - 1)
dist = [0] * n
while len(qq) != 0:
now = qq.popleft()
for to, w in lst[now]:
if dist[to] != 0:
continue
dist[to] = dist[now] + w
qq.append(to)
for i in range(q):
print((dist[x[i]] + dist[y[i]]))
if __name__ == "__main__":
main()
| false | 0 | [
"-import queue",
"+from collections import deque",
"- qq = queue.Queue()",
"- qq.put(k - 1)",
"+ qq = deque()",
"+ qq.append(k - 1)",
"- while not qq.empty():",
"- now = qq.get()",
"+ while len(qq) != 0:",
"+ now = qq.popleft()",
"- qq.put(to)",
"+ qq.append(to)"
] | false | 0.039181 | 0.03764 | 1.040945 | [
"s234656581",
"s751444979"
] |
u764600134 | p03161 | python | s428403427 | s698140173 | 1,947 | 455 | 14,016 | 55,392 | Accepted | Accepted | 76.63 | # -*- coding: utf-8 -*-
"""
B - Frog 2
https://atcoder.jp/contests/dp/tasks/dp_b
"""
import sys
from sys import stdin
def solve(ashiba, N, K):
dp = [float('inf')] * N
dp[0] = 0
for i in range(1, len(ashiba)):
paths = [dp[j]+abs(ashiba[j]-ashiba[i]) for j in range(max(0, i-K), i)]
dp[i] = min(paths)
return dp[-1]
def main(args):
N, K = list(map(int, input().split()))
ashiba = [int(i) for i in input().split()]
ans = solve(ashiba, N, K)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
| # -*- coding: utf-8 -*-
"""
B - Frog 2
https://atcoder.jp/contests/dp/tasks/dp_b
AC
"""
import sys
from sys import stdin
def solve(ashiba, N, K):
dp = [float('inf')] * N
dp[0] = 0
for i in range(1, len(ashiba)):
paths = [dp[j]+abs(ashiba[j]-ashiba[i]) for j in range(max(0, i-K), i)]
dp[i] = min(paths)
return dp[-1]
def main(args):
N, K = list(map(int, input().split()))
ashiba = [int(i) for i in input().split()]
ans = solve(ashiba, N, K)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
| 28 | 28 | 575 | 577 | # -*- coding: utf-8 -*-
"""
B - Frog 2
https://atcoder.jp/contests/dp/tasks/dp_b
"""
import sys
from sys import stdin
def solve(ashiba, N, K):
dp = [float("inf")] * N
dp[0] = 0
for i in range(1, len(ashiba)):
paths = [dp[j] + abs(ashiba[j] - ashiba[i]) for j in range(max(0, i - K), i)]
dp[i] = min(paths)
return dp[-1]
def main(args):
N, K = list(map(int, input().split()))
ashiba = [int(i) for i in input().split()]
ans = solve(ashiba, N, K)
print(ans)
if __name__ == "__main__":
main(sys.argv[1:])
| # -*- coding: utf-8 -*-
"""
B - Frog 2
https://atcoder.jp/contests/dp/tasks/dp_b
AC
"""
import sys
from sys import stdin
def solve(ashiba, N, K):
dp = [float("inf")] * N
dp[0] = 0
for i in range(1, len(ashiba)):
paths = [dp[j] + abs(ashiba[j] - ashiba[i]) for j in range(max(0, i - K), i)]
dp[i] = min(paths)
return dp[-1]
def main(args):
N, K = list(map(int, input().split()))
ashiba = [int(i) for i in input().split()]
ans = solve(ashiba, N, K)
print(ans)
if __name__ == "__main__":
main(sys.argv[1:])
| false | 0 | [
"+AC"
] | false | 0.042241 | 0.041806 | 1.010409 | [
"s428403427",
"s698140173"
] |
u672475305 | p03804 | python | s946173322 | s704440911 | 87 | 26 | 3,064 | 3,060 | Accepted | Accepted | 70.11 | def match(x,y):
ret = True
for i in range(m):
for j in range(m):
if A[y+i][x+j] != B[i][j]:
ret = False
return ret
n,m = list(map(int,input().split()))
A = []
for i in range(n):
A.append(list(eval(input())))
B = []
for i in range(m):
B.append(list(eval(input())))
flg = False
for i in range(n-m+1):
for j in range(n-m+1):
if match(i,j):
flg = True
print(('Yes' if flg else 'No')) | n,m = list(map(int,input().split()))
A = [list(eval(input())) for _ in range(n)]
B = [list(eval(input())) for _ in range(m)]
ans = False
for i in range(n-m+1):
for j in range(n-m+1):
flg = True
for e, k in enumerate(range(m)):
if A[i+e][j:j+m] != B[k]:
flg = False
if flg:
ans = True
break
print(('Yes' if ans else 'No'))
| 23 | 14 | 464 | 395 | def match(x, y):
ret = True
for i in range(m):
for j in range(m):
if A[y + i][x + j] != B[i][j]:
ret = False
return ret
n, m = list(map(int, input().split()))
A = []
for i in range(n):
A.append(list(eval(input())))
B = []
for i in range(m):
B.append(list(eval(input())))
flg = False
for i in range(n - m + 1):
for j in range(n - m + 1):
if match(i, j):
flg = True
print(("Yes" if flg else "No"))
| n, m = list(map(int, input().split()))
A = [list(eval(input())) for _ in range(n)]
B = [list(eval(input())) for _ in range(m)]
ans = False
for i in range(n - m + 1):
for j in range(n - m + 1):
flg = True
for e, k in enumerate(range(m)):
if A[i + e][j : j + m] != B[k]:
flg = False
if flg:
ans = True
break
print(("Yes" if ans else "No"))
| false | 39.130435 | [
"-def match(x, y):",
"- ret = True",
"- for i in range(m):",
"- for j in range(m):",
"- if A[y + i][x + j] != B[i][j]:",
"- ret = False",
"- return ret",
"-",
"-",
"-A = []",
"-for i in range(n):",
"- A.append(list(eval(input())))",
"-B = []",
"-for i in range(m):",
"- B.append(list(eval(input())))",
"-flg = False",
"+A = [list(eval(input())) for _ in range(n)]",
"+B = [list(eval(input())) for _ in range(m)]",
"+ans = False",
"- if match(i, j):",
"- flg = True",
"-print((\"Yes\" if flg else \"No\"))",
"+ flg = True",
"+ for e, k in enumerate(range(m)):",
"+ if A[i + e][j : j + m] != B[k]:",
"+ flg = False",
"+ if flg:",
"+ ans = True",
"+ break",
"+print((\"Yes\" if ans else \"No\"))"
] | false | 0.036426 | 0.075375 | 0.483261 | [
"s946173322",
"s704440911"
] |
u729133443 | p03740 | python | s474116365 | s499312380 | 38 | 17 | 27,884 | 2,940 | Accepted | Accepted | 55.26 | print('ABlriocwen'[eval(input().replace(' ','-'))**2<2::2]) | print(('ABlriocwen'[-2<eval(input().replace(' ','-'))<2::2])) | 1 | 1 | 61 | 59 | print("ABlriocwen"[eval(input().replace(" ", "-")) ** 2 < 2 :: 2])
| print(("ABlriocwen"[-2 < eval(input().replace(" ", "-")) < 2 :: 2]))
| false | 0 | [
"-print(\"ABlriocwen\"[eval(input().replace(\" \", \"-\")) ** 2 < 2 :: 2])",
"+print((\"ABlriocwen\"[-2 < eval(input().replace(\" \", \"-\")) < 2 :: 2]))"
] | false | 0.038562 | 0.041388 | 0.931717 | [
"s474116365",
"s499312380"
] |
u094815239 | p03244 | python | s404739761 | s232421517 | 124 | 74 | 15,588 | 15,588 | Accepted | Accepted | 40.32 | from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))
cnt1 = Counter(a[::2]).most_common(2)
c11, c12 = (cnt1 if len(cnt1) == 2 else cnt1+[('', 0)])
cnt2 = Counter(a[1::2]).most_common(2)
c21, c22 = (cnt2 if len(cnt2) == 2 else cnt2+[('', 0)])
if c11[0] != c21[0]:
print((n - c11[1] - c21[1]))
else:
print((n - max(c11[1]+c22[1], c12[1]+c21[1])))
print() | from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))
cnt1 = Counter(a[::2]).most_common(2)
c11, c12 = (cnt1 if len(cnt1) == 2 else cnt1+[('', 0)])
cnt2 = Counter(a[1::2]).most_common(2)
c21, c22 = (cnt2 if len(cnt2) == 2 else cnt2+[('', 0)])
if c11[0] != c21[0]:
print((n - c11[1] - c21[1]))
else:
print((n - max(c11[1]+c22[1], c12[1]+c21[1]))) | 13 | 12 | 417 | 408 | from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))
cnt1 = Counter(a[::2]).most_common(2)
c11, c12 = cnt1 if len(cnt1) == 2 else cnt1 + [("", 0)]
cnt2 = Counter(a[1::2]).most_common(2)
c21, c22 = cnt2 if len(cnt2) == 2 else cnt2 + [("", 0)]
if c11[0] != c21[0]:
print((n - c11[1] - c21[1]))
else:
print((n - max(c11[1] + c22[1], c12[1] + c21[1])))
print()
| from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))
cnt1 = Counter(a[::2]).most_common(2)
c11, c12 = cnt1 if len(cnt1) == 2 else cnt1 + [("", 0)]
cnt2 = Counter(a[1::2]).most_common(2)
c21, c22 = cnt2 if len(cnt2) == 2 else cnt2 + [("", 0)]
if c11[0] != c21[0]:
print((n - c11[1] - c21[1]))
else:
print((n - max(c11[1] + c22[1], c12[1] + c21[1])))
| false | 7.692308 | [
"-print()"
] | false | 0.089468 | 0.099184 | 0.902038 | [
"s404739761",
"s232421517"
] |
u373047809 | p03356 | python | s813383703 | s935754826 | 462 | 353 | 13,876 | 32,072 | Accepted | Accepted | 23.59 | #!/usr/bin/env python3
import sys
input = sys.stdin.readline
class UnionFind():
def __init__(self, n, m = None, read = 0):
self.n = n
self.parents = [-1] * n
if read:
if m is None:
exit(print("Warning: What is M"))
for i in range(m):
a, b = map(int, input().split())
self.union(a - 1, b - 1)
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
n, m = map(int, input().split())
*p, = map(int, input().split())
UF = UnionFind(n, m, read = 1)
a = 0
for i in range(n):
P = p[i] - 1
if UF.same(P, i):
a += 1
print(a)
| ##### UnionFind #####
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
(n, m), p, *q = [list(map(int, o.split())) for o in open(0)]
UF = UnionFind(-~n)
for a, b in q:UF.union(a, b)
print((sum(UF.same(p[i], -~i) for i in range(n)))) | 61 | 46 | 1,577 | 1,261 | #!/usr/bin/env python3
import sys
input = sys.stdin.readline
class UnionFind:
def __init__(self, n, m=None, read=0):
self.n = n
self.parents = [-1] * n
if read:
if m is None:
exit(print("Warning: What is M"))
for i in range(m):
a, b = map(int, input().split())
self.union(a - 1, b - 1)
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
n, m = map(int, input().split())
(*p,) = map(int, input().split())
UF = UnionFind(n, m, read=1)
a = 0
for i in range(n):
P = p[i] - 1
if UF.same(P, i):
a += 1
print(a)
| ##### UnionFind #####
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
(n, m), p, *q = [list(map(int, o.split())) for o in open(0)]
UF = UnionFind(-~n)
for a, b in q:
UF.union(a, b)
print((sum(UF.same(p[i], -~i) for i in range(n))))
| false | 24.590164 | [
"-#!/usr/bin/env python3",
"-import sys",
"-",
"-input = sys.stdin.readline",
"-",
"-",
"+##### UnionFind #####",
"- def __init__(self, n, m=None, read=0):",
"+ def __init__(self, n):",
"- if read:",
"- if m is None:",
"- exit(print(\"Warning: What is M\"))",
"- for i in range(m):",
"- a, b = map(int, input().split())",
"- self.union(a - 1, b - 1)",
"-n, m = map(int, input().split())",
"-(*p,) = map(int, input().split())",
"-UF = UnionFind(n, m, read=1)",
"-a = 0",
"-for i in range(n):",
"- P = p[i] - 1",
"- if UF.same(P, i):",
"- a += 1",
"-print(a)",
"+(n, m), p, *q = [list(map(int, o.split())) for o in open(0)]",
"+UF = UnionFind(-~n)",
"+for a, b in q:",
"+ UF.union(a, b)",
"+print((sum(UF.same(p[i], -~i) for i in range(n))))"
] | false | 0.042813 | 0.047157 | 0.907902 | [
"s813383703",
"s935754826"
] |
u111365362 | p02863 | python | s297914379 | s454354413 | 466 | 398 | 52,568 | 46,056 | Accepted | Accepted | 14.59 | #16:25
n,t = list(map(int,input().split()))
wv = []
for _ in range(n):
wv.append(list(map(int,input().split())))
wv.sort(key=lambda x:x[0])
now = [0 for _ in range(t+1)]
for i in range(n):
w,v = wv[i]
last = now
now = []
for f in range(t):
if f >= w:
now.append(max(last[f-w]+v,last[f]))
else:
now.append(last[f])
now.append(max(last[-2]+v,last[-1]))
print((now[-1])) | n,t = list(map(int,input().split()))
dish = []
for _ in range(n):
a,b = list(map(int,input().split()))
dish.append([a,b])
dish.sort()
now = [0 for _ in range(t+1)]
for i in range(n):
a,b = dish[i]
for d in range(t)[::-1]:
if d + a < t:
now[d+a] = max(now[d+a],now[d]+b)
else:
now[-1] = max(now[-1],now[d]+b)
#print(now)
print((now[-1])) | 18 | 16 | 408 | 367 | # 16:25
n, t = list(map(int, input().split()))
wv = []
for _ in range(n):
wv.append(list(map(int, input().split())))
wv.sort(key=lambda x: x[0])
now = [0 for _ in range(t + 1)]
for i in range(n):
w, v = wv[i]
last = now
now = []
for f in range(t):
if f >= w:
now.append(max(last[f - w] + v, last[f]))
else:
now.append(last[f])
now.append(max(last[-2] + v, last[-1]))
print((now[-1]))
| n, t = list(map(int, input().split()))
dish = []
for _ in range(n):
a, b = list(map(int, input().split()))
dish.append([a, b])
dish.sort()
now = [0 for _ in range(t + 1)]
for i in range(n):
a, b = dish[i]
for d in range(t)[::-1]:
if d + a < t:
now[d + a] = max(now[d + a], now[d] + b)
else:
now[-1] = max(now[-1], now[d] + b)
# print(now)
print((now[-1]))
| false | 11.111111 | [
"-# 16:25",
"-wv = []",
"+dish = []",
"- wv.append(list(map(int, input().split())))",
"-wv.sort(key=lambda x: x[0])",
"+ a, b = list(map(int, input().split()))",
"+ dish.append([a, b])",
"+dish.sort()",
"- w, v = wv[i]",
"- last = now",
"- now = []",
"- for f in range(t):",
"- if f >= w:",
"- now.append(max(last[f - w] + v, last[f]))",
"+ a, b = dish[i]",
"+ for d in range(t)[::-1]:",
"+ if d + a < t:",
"+ now[d + a] = max(now[d + a], now[d] + b)",
"- now.append(last[f])",
"- now.append(max(last[-2] + v, last[-1]))",
"+ now[-1] = max(now[-1], now[d] + b)",
"+ # print(now)"
] | false | 0.188079 | 0.035665 | 5.273453 | [
"s297914379",
"s454354413"
] |
u046187684 | p02660 | python | s565809652 | s171142448 | 315 | 230 | 20,264 | 20,224 | Accepted | Accepted | 26.98 | def find_primes(n):
ps = []
t = [True] * n
t[0] = t[1] = False
for i in range(2, n):
if not t[i]:
continue
ps.append(i)
for j in range(i, n, i):
t[j] = False
return ps
def solve(string):
n = int(string)
if n == 1:
return "0"
rn = int(n**0.5 + 1)
ps = find_primes(rn)
ans = 0
f = True
for i in ps:
k = 1
while n % (i**k) == 0:
ans += 1
n //= i**k
f = False
k += 1
return str(ans + 1 if f else ans + (n >= rn))
if __name__ == '__main__':
import sys
print((solve(sys.stdin.read().strip())))
| def find_primes(n):
ps = []
t = [True] * n
t[0] = t[1] = False
for i in range(2, n):
if not t[i]:
continue
ps.append(i)
for j in range(i, n, i):
t[j] = False
return ps
def solve(string):
n = int(string)
if n == 1:
return "0"
rn = int(n**0.5 + 1)
ps = find_primes(rn)
ans = 0
for i in ps:
k = 1
while n % (i**k) == 0:
ans += 1
n //= i**k
k += 1
return str(ans + (n >= rn))
if __name__ == '__main__':
import sys
print((solve(sys.stdin.read().strip())))
| 34 | 32 | 703 | 648 | def find_primes(n):
ps = []
t = [True] * n
t[0] = t[1] = False
for i in range(2, n):
if not t[i]:
continue
ps.append(i)
for j in range(i, n, i):
t[j] = False
return ps
def solve(string):
n = int(string)
if n == 1:
return "0"
rn = int(n**0.5 + 1)
ps = find_primes(rn)
ans = 0
f = True
for i in ps:
k = 1
while n % (i**k) == 0:
ans += 1
n //= i**k
f = False
k += 1
return str(ans + 1 if f else ans + (n >= rn))
if __name__ == "__main__":
import sys
print((solve(sys.stdin.read().strip())))
| def find_primes(n):
ps = []
t = [True] * n
t[0] = t[1] = False
for i in range(2, n):
if not t[i]:
continue
ps.append(i)
for j in range(i, n, i):
t[j] = False
return ps
def solve(string):
n = int(string)
if n == 1:
return "0"
rn = int(n**0.5 + 1)
ps = find_primes(rn)
ans = 0
for i in ps:
k = 1
while n % (i**k) == 0:
ans += 1
n //= i**k
k += 1
return str(ans + (n >= rn))
if __name__ == "__main__":
import sys
print((solve(sys.stdin.read().strip())))
| false | 5.882353 | [
"- f = True",
"- f = False",
"- return str(ans + 1 if f else ans + (n >= rn))",
"+ return str(ans + (n >= rn))"
] | false | 0.006416 | 0.085063 | 0.075423 | [
"s565809652",
"s171142448"
] |
u143441425 | p02678 | python | s127860335 | s412802695 | 1,314 | 1,068 | 68,516 | 65,152 | Accepted | Accepted | 18.72 | # ダイクストラ法で部屋1から各部屋への最短経路を出す
import queue
n, m = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(m)]
# 隣接行列の作成
edges_dict = {}
for edge in edges:
a, b = edge
if a not in edges_dict:
edges_dict[a] = [b]
else:
edges_dict[a].append(b)
if b not in edges_dict:
edges_dict[b] = [a]
else:
edges_dict[b].append(a)
# 定数
COST = 1
INF = 1e10
# i=0は未使用, i>0は部屋iへの最短距離
dist_list = [INF] * (n + 1)
# i=0は未使用, i>0は部屋iの最短経路がたどる次の部屋 = 道しるべ
prev_list = [None] * (n + 1)
q = queue.PriorityQueue()
# 初期化
q.put((0, 1)) # (最短経路, 部屋番号)
dist_list[1] = 0
prev_list[1] = 1
while not q.empty():
min_dist, v = q.get()
#print("min_dist={}, v={}".format(min_dist, v))
if dist_list[v] < min_dist:
#print("waste")
continue
#print("check edges: ", edges_dict[v])
for w in edges_dict[v]:
cost = dist_list[v] + COST
if dist_list[w] > cost:
#print("push path {} -> {}; cost {}; path {}".format(v, w, cost, prev_list[v]))
dist_list[w] = cost
prev_list[w] = v#prev_list[v]
q.put((cost, w))
print("Yes")
#print(edges_dict)
#print(dist_list)
#print(prev_list)
for v in prev_list[2:]:
print(v)
| # ダイクストラ法で部屋1から各部屋への最短経路を出す
import queue
n, m = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(m)]
# 隣接行列の作成
edges_dict = {}
for edge in edges:
a, b = edge
if a not in edges_dict:
edges_dict[a] = [b]
else:
edges_dict[a].append(b)
if b not in edges_dict:
edges_dict[b] = [a]
else:
edges_dict[b].append(a)
# i=0は未使用, i>0は部屋iの最短経路がたどる次の部屋 = 道しるべ
prev_list = [None] * (n + 1)
q = queue.Queue()
# 初期化
q.put(1)
prev_list[1] = 1
while not q.empty():
v = q.get()
for w in edges_dict[v]:
if prev_list[w] is None:
prev_list[w] = v
q.put(w)
print("Yes")
for v in prev_list[2:]:
print(v)
| 59 | 39 | 1,318 | 759 | # ダイクストラ法で部屋1から各部屋への最短経路を出す
import queue
n, m = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(m)]
# 隣接行列の作成
edges_dict = {}
for edge in edges:
a, b = edge
if a not in edges_dict:
edges_dict[a] = [b]
else:
edges_dict[a].append(b)
if b not in edges_dict:
edges_dict[b] = [a]
else:
edges_dict[b].append(a)
# 定数
COST = 1
INF = 1e10
# i=0は未使用, i>0は部屋iへの最短距離
dist_list = [INF] * (n + 1)
# i=0は未使用, i>0は部屋iの最短経路がたどる次の部屋 = 道しるべ
prev_list = [None] * (n + 1)
q = queue.PriorityQueue()
# 初期化
q.put((0, 1)) # (最短経路, 部屋番号)
dist_list[1] = 0
prev_list[1] = 1
while not q.empty():
min_dist, v = q.get()
# print("min_dist={}, v={}".format(min_dist, v))
if dist_list[v] < min_dist:
# print("waste")
continue
# print("check edges: ", edges_dict[v])
for w in edges_dict[v]:
cost = dist_list[v] + COST
if dist_list[w] > cost:
# print("push path {} -> {}; cost {}; path {}".format(v, w, cost, prev_list[v]))
dist_list[w] = cost
prev_list[w] = v # prev_list[v]
q.put((cost, w))
print("Yes")
# print(edges_dict)
# print(dist_list)
# print(prev_list)
for v in prev_list[2:]:
print(v)
| # ダイクストラ法で部屋1から各部屋への最短経路を出す
import queue
n, m = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(m)]
# 隣接行列の作成
edges_dict = {}
for edge in edges:
a, b = edge
if a not in edges_dict:
edges_dict[a] = [b]
else:
edges_dict[a].append(b)
if b not in edges_dict:
edges_dict[b] = [a]
else:
edges_dict[b].append(a)
# i=0は未使用, i>0は部屋iの最短経路がたどる次の部屋 = 道しるべ
prev_list = [None] * (n + 1)
q = queue.Queue()
# 初期化
q.put(1)
prev_list[1] = 1
while not q.empty():
v = q.get()
for w in edges_dict[v]:
if prev_list[w] is None:
prev_list[w] = v
q.put(w)
print("Yes")
for v in prev_list[2:]:
print(v)
| false | 33.898305 | [
"-# 定数",
"-COST = 1",
"-INF = 1e10",
"-# i=0は未使用, i>0は部屋iへの最短距離",
"-dist_list = [INF] * (n + 1)",
"-q = queue.PriorityQueue()",
"+q = queue.Queue()",
"-q.put((0, 1)) # (最短経路, 部屋番号)",
"-dist_list[1] = 0",
"+q.put(1)",
"- min_dist, v = q.get()",
"- # print(\"min_dist={}, v={}\".format(min_dist, v))",
"- if dist_list[v] < min_dist:",
"- # print(\"waste\")",
"- continue",
"- # print(\"check edges: \", edges_dict[v])",
"+ v = q.get()",
"- cost = dist_list[v] + COST",
"- if dist_list[w] > cost:",
"- # print(\"push path {} -> {}; cost {}; path {}\".format(v, w, cost, prev_list[v]))",
"- dist_list[w] = cost",
"- prev_list[w] = v # prev_list[v]",
"- q.put((cost, w))",
"+ if prev_list[w] is None:",
"+ prev_list[w] = v",
"+ q.put(w)",
"-# print(edges_dict)",
"-# print(dist_list)",
"-# print(prev_list)"
] | false | 0.036988 | 0.085071 | 0.434784 | [
"s127860335",
"s412802695"
] |
u380524497 | p02901 | python | s943152157 | s401920463 | 1,972 | 769 | 3,188 | 3,188 | Accepted | Accepted | 61 | n, m = list(map(int, input().split()))
DP = [10**9] * (2**n)
DP[0] = 0
for _ in range(m):
cost, types = list(map(int, input().split()))
to_open = list(map(int, input().split()))
openable = 0
for open in to_open:
openable += 1 << (open-1)
for opened in range(2 ** n):
pattern = opened | openable
DP[pattern] = min(DP[pattern], DP[opened] + cost)
full_open = 2**n - 1
ans = DP[full_open]
if ans == 10 ** 9:
ans = -1
print(ans)
| def main():
n, m = list(map(int, input().split()))
all_patterns = 2**n
DP = [10**9] * all_patterns
DP[0] = 0
for _ in range(m):
cost, types = list(map(int, input().split()))
to_open = list(map(int, input().split()))
openable = 0
for open in to_open:
openable += 1 << (open-1)
for opened in range(all_patterns):
pattern = opened | openable
new_cost = DP[opened] + cost
if DP[pattern] > new_cost:
DP[pattern] = new_cost
full_open = 2**n - 1
ans = DP[full_open]
if ans == 10 ** 9:
ans = -1
print(ans)
if __name__ == '__main__':
main()
| 23 | 29 | 489 | 714 | n, m = list(map(int, input().split()))
DP = [10**9] * (2**n)
DP[0] = 0
for _ in range(m):
cost, types = list(map(int, input().split()))
to_open = list(map(int, input().split()))
openable = 0
for open in to_open:
openable += 1 << (open - 1)
for opened in range(2**n):
pattern = opened | openable
DP[pattern] = min(DP[pattern], DP[opened] + cost)
full_open = 2**n - 1
ans = DP[full_open]
if ans == 10**9:
ans = -1
print(ans)
| def main():
n, m = list(map(int, input().split()))
all_patterns = 2**n
DP = [10**9] * all_patterns
DP[0] = 0
for _ in range(m):
cost, types = list(map(int, input().split()))
to_open = list(map(int, input().split()))
openable = 0
for open in to_open:
openable += 1 << (open - 1)
for opened in range(all_patterns):
pattern = opened | openable
new_cost = DP[opened] + cost
if DP[pattern] > new_cost:
DP[pattern] = new_cost
full_open = 2**n - 1
ans = DP[full_open]
if ans == 10**9:
ans = -1
print(ans)
if __name__ == "__main__":
main()
| false | 20.689655 | [
"-n, m = list(map(int, input().split()))",
"-DP = [10**9] * (2**n)",
"-DP[0] = 0",
"-for _ in range(m):",
"- cost, types = list(map(int, input().split()))",
"- to_open = list(map(int, input().split()))",
"- openable = 0",
"- for open in to_open:",
"- openable += 1 << (open - 1)",
"- for opened in range(2**n):",
"- pattern = opened | openable",
"- DP[pattern] = min(DP[pattern], DP[opened] + cost)",
"-full_open = 2**n - 1",
"-ans = DP[full_open]",
"-if ans == 10**9:",
"- ans = -1",
"-print(ans)",
"+def main():",
"+ n, m = list(map(int, input().split()))",
"+ all_patterns = 2**n",
"+ DP = [10**9] * all_patterns",
"+ DP[0] = 0",
"+ for _ in range(m):",
"+ cost, types = list(map(int, input().split()))",
"+ to_open = list(map(int, input().split()))",
"+ openable = 0",
"+ for open in to_open:",
"+ openable += 1 << (open - 1)",
"+ for opened in range(all_patterns):",
"+ pattern = opened | openable",
"+ new_cost = DP[opened] + cost",
"+ if DP[pattern] > new_cost:",
"+ DP[pattern] = new_cost",
"+ full_open = 2**n - 1",
"+ ans = DP[full_open]",
"+ if ans == 10**9:",
"+ ans = -1",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.054537 | 0.035374 | 1.541719 | [
"s943152157",
"s401920463"
] |
u714378447 | p03062 | python | s134457982 | s384267524 | 203 | 57 | 25,512 | 14,412 | Accepted | Accepted | 71.92 | N=int(eval(input()))
A=list(map(int,input().split()))
dp=[[0]*2 for i in range(N)]
dp[0][0]=0
dp[0][1]=-3*10**9
for i in range(N-1):
dp[i+1][0]=max(dp[i][0]+A[i], dp[i][1]-A[i])
dp[i+1][1]=max(dp[i][0]-A[i], dp[i][1]+A[i])
print((max(dp[-1][0]+A[-1], dp[-1][1]-A[-1]))) | N=int(eval(input()))
A=list(map(int,input().split()))
if 0 in A:
print((sum(abs(a) for a in A)))
else:
cnt=sum([1 for a in A if a<0])
if cnt%2==0:
print((sum(abs(a) for a in A)))
else:
A=[abs(a) for a in A]
print((sum(A) -2*min(A))) | 13 | 13 | 280 | 245 | N = int(eval(input()))
A = list(map(int, input().split()))
dp = [[0] * 2 for i in range(N)]
dp[0][0] = 0
dp[0][1] = -3 * 10**9
for i in range(N - 1):
dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i])
dp[i + 1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i])
print((max(dp[-1][0] + A[-1], dp[-1][1] - A[-1])))
| N = int(eval(input()))
A = list(map(int, input().split()))
if 0 in A:
print((sum(abs(a) for a in A)))
else:
cnt = sum([1 for a in A if a < 0])
if cnt % 2 == 0:
print((sum(abs(a) for a in A)))
else:
A = [abs(a) for a in A]
print((sum(A) - 2 * min(A)))
| false | 0 | [
"-dp = [[0] * 2 for i in range(N)]",
"-dp[0][0] = 0",
"-dp[0][1] = -3 * 10**9",
"-for i in range(N - 1):",
"- dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i])",
"- dp[i + 1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i])",
"-print((max(dp[-1][0] + A[-1], dp[-1][1] - A[-1])))",
"+if 0 in A:",
"+ print((sum(abs(a) for a in A)))",
"+else:",
"+ cnt = sum([1 for a in A if a < 0])",
"+ if cnt % 2 == 0:",
"+ print((sum(abs(a) for a in A)))",
"+ else:",
"+ A = [abs(a) for a in A]",
"+ print((sum(A) - 2 * min(A)))"
] | false | 0.04093 | 0.041257 | 0.99209 | [
"s134457982",
"s384267524"
] |
u994521204 | p03045 | python | s979480470 | s938327982 | 1,646 | 610 | 130,648 | 12,780 | Accepted | Accepted | 62.94 | # union-findで行けそう。
n, m = list(map(int, input().split()))
par = [-1] * (n + 1)
def find(a):
if par[a] < 0:
return a
else:
par[a] = find(par[a])
return par[a]
def unite(a, b):
a = find(a)
b = find(b)
if a == b:
return False
else:
if par[a] < par[b]:
a, b = b, a
par[a] += par[b]
par[b] = a
return True
for i in range(m):
x, y, z = list(map(int, input().split()))
unite(x, y)
cnt = 0
for i in range(n):
if par[i + 1] < 0:
cnt += 1
print(cnt)
| n,m=list(map(int,input().split()))
#union-find
par=[-1]*(n+1)
def find(x):
if par[x]<0:
return x
else:
par[x]=find(par[x])
return par[x]
def size(x):
oya=find(x)
return -par[oya]
def unite(x,y):
if find(x)==find(y):
return False
else:
if size(y)>size(x):
y,x=x,y #xを大きい親にしておくか
oya_x=find(x)
oya_y=find(y)
par[oya_x]-=size(oya_y) #xの大きさをyにしておく
par[oya_y]=oya_x #yの親をxに
return True
def is_same(x,y):
return find(x)==find(y)
for _ in range(m):
x,y,z=list(map(int,input().split()))
unite(x,y)
ans_set=set()
for i in range(1,n+1):
ans_set.add(find(i))
print((len(ans_set))) | 35 | 33 | 589 | 722 | # union-findで行けそう。
n, m = list(map(int, input().split()))
par = [-1] * (n + 1)
def find(a):
if par[a] < 0:
return a
else:
par[a] = find(par[a])
return par[a]
def unite(a, b):
a = find(a)
b = find(b)
if a == b:
return False
else:
if par[a] < par[b]:
a, b = b, a
par[a] += par[b]
par[b] = a
return True
for i in range(m):
x, y, z = list(map(int, input().split()))
unite(x, y)
cnt = 0
for i in range(n):
if par[i + 1] < 0:
cnt += 1
print(cnt)
| n, m = list(map(int, input().split()))
# union-find
par = [-1] * (n + 1)
def find(x):
if par[x] < 0:
return x
else:
par[x] = find(par[x])
return par[x]
def size(x):
oya = find(x)
return -par[oya]
def unite(x, y):
if find(x) == find(y):
return False
else:
if size(y) > size(x):
y, x = x, y # xを大きい親にしておくか
oya_x = find(x)
oya_y = find(y)
par[oya_x] -= size(oya_y) # xの大きさをyにしておく
par[oya_y] = oya_x # yの親をxに
return True
def is_same(x, y):
return find(x) == find(y)
for _ in range(m):
x, y, z = list(map(int, input().split()))
unite(x, y)
ans_set = set()
for i in range(1, n + 1):
ans_set.add(find(i))
print((len(ans_set)))
| false | 5.714286 | [
"-# union-findで行けそう。",
"+# union-find",
"-def find(a):",
"- if par[a] < 0:",
"- return a",
"+def find(x):",
"+ if par[x] < 0:",
"+ return x",
"- par[a] = find(par[a])",
"- return par[a]",
"+ par[x] = find(par[x])",
"+ return par[x]",
"-def unite(a, b):",
"- a = find(a)",
"- b = find(b)",
"- if a == b:",
"+def size(x):",
"+ oya = find(x)",
"+ return -par[oya]",
"+",
"+",
"+def unite(x, y):",
"+ if find(x) == find(y):",
"- if par[a] < par[b]:",
"- a, b = b, a",
"- par[a] += par[b]",
"- par[b] = a",
"+ if size(y) > size(x):",
"+ y, x = x, y # xを大きい親にしておくか",
"+ oya_x = find(x)",
"+ oya_y = find(y)",
"+ par[oya_x] -= size(oya_y) # xの大きさをyにしておく",
"+ par[oya_y] = oya_x # yの親をxに",
"-for i in range(m):",
"+def is_same(x, y):",
"+ return find(x) == find(y)",
"+",
"+",
"+for _ in range(m):",
"-cnt = 0",
"-for i in range(n):",
"- if par[i + 1] < 0:",
"- cnt += 1",
"-print(cnt)",
"+ans_set = set()",
"+for i in range(1, n + 1):",
"+ ans_set.add(find(i))",
"+print((len(ans_set)))"
] | false | 0.034904 | 0.038859 | 0.898225 | [
"s979480470",
"s938327982"
] |
u301624971 | p02996 | python | s289345089 | s833232751 | 1,192 | 929 | 60,472 | 60,524 | Accepted | Accepted | 22.06 | '''
ABC 131 D:Megalomania
Accepted :Yes
difficult :
ペナルティ :5分
実際の回答時間 :9分
WAの回数 :0回
合計時間 :9分
'''
def myAnswer(N:int,A:list,B:list) -> str:
dic = {}
# 締め切り時間をkey、作業時間をvalueにした辞書を作成
for a,b in zip(A,B):
if(b in list(dic.keys())):
dic[b].append(a)
else:
dic[b] = [a]
now = 0
dic = sorted(dic.items())
for deadline,time in dic:
time.sort()
# print(deadline,time)
for t in time:
if(deadline < now + t):
return "No"
now += t
return "Yes"
def modelAnswer(N:int,dic:dict) -> str:
now = 0
dic = sorted(dic.items())
for deadline,time in dic:
time.sort()
for t in time:
if(deadline < now + t):
return "No"
now += t
return "Yes"
def main():
N = int(eval(input()))
dic = {}
# A = []
# B = []
for _ in range(N):
a,b = list(map(int,input().split()))
if(b in list(dic.keys())):
dic[b].append(a)
else:
dic[b] = [a]
# A.append(a)
# B.append(b)
print((modelAnswer(N,dic)))
if __name__ == '__main__':
main() | '''
ABC 131 D:Megalomania
Accepted :Yes
difficult :
ペナルティ :5分
実際の回答時間 :9分
WAの回数 :0回
合計時間 :9分
'''
import sys
input = sys.stdin.readline
def myAnswer(N:int,A:list,B:list) -> str:
dic = {}
# 締め切り時間をkey、作業時間をvalueにした辞書を作成
for a,b in zip(A,B):
if(b in list(dic.keys())):
dic[b].append(a)
else:
dic[b] = [a]
now = 0
dic = sorted(dic.items())
for deadline,time in dic:
time.sort()
# print(deadline,time)
for t in time:
if(deadline < now + t):
return "No"
now += t
return "Yes"
def modelAnswer(N:int,dic:dict) -> str:
now = 0
dic = sorted(dic.items())
for deadline,time in dic:
time.sort()
for t in time:
if(deadline < now + t):
return "No"
now += t
return "Yes"
def main():
N = int(eval(input()))
dic = {}
# A = []
# B = []
for _ in range(N):
a,b = list(map(int,input().split()))
if(b in list(dic.keys())):
dic[b].append(a)
else:
dic[b] = [a]
# A.append(a)
# B.append(b)
print((modelAnswer(N,dic)))
if __name__ == '__main__':
main() | 56 | 58 | 1,163 | 1,203 | """
ABC 131 D:Megalomania
Accepted :Yes
difficult :
ペナルティ :5分
実際の回答時間 :9分
WAの回数 :0回
合計時間 :9分
"""
def myAnswer(N: int, A: list, B: list) -> str:
dic = {}
# 締め切り時間をkey、作業時間をvalueにした辞書を作成
for a, b in zip(A, B):
if b in list(dic.keys()):
dic[b].append(a)
else:
dic[b] = [a]
now = 0
dic = sorted(dic.items())
for deadline, time in dic:
time.sort()
# print(deadline,time)
for t in time:
if deadline < now + t:
return "No"
now += t
return "Yes"
def modelAnswer(N: int, dic: dict) -> str:
now = 0
dic = sorted(dic.items())
for deadline, time in dic:
time.sort()
for t in time:
if deadline < now + t:
return "No"
now += t
return "Yes"
def main():
N = int(eval(input()))
dic = {}
# A = []
# B = []
for _ in range(N):
a, b = list(map(int, input().split()))
if b in list(dic.keys()):
dic[b].append(a)
else:
dic[b] = [a]
# A.append(a)
# B.append(b)
print((modelAnswer(N, dic)))
if __name__ == "__main__":
main()
| """
ABC 131 D:Megalomania
Accepted :Yes
difficult :
ペナルティ :5分
実際の回答時間 :9分
WAの回数 :0回
合計時間 :9分
"""
import sys
input = sys.stdin.readline
def myAnswer(N: int, A: list, B: list) -> str:
dic = {}
# 締め切り時間をkey、作業時間をvalueにした辞書を作成
for a, b in zip(A, B):
if b in list(dic.keys()):
dic[b].append(a)
else:
dic[b] = [a]
now = 0
dic = sorted(dic.items())
for deadline, time in dic:
time.sort()
# print(deadline,time)
for t in time:
if deadline < now + t:
return "No"
now += t
return "Yes"
def modelAnswer(N: int, dic: dict) -> str:
now = 0
dic = sorted(dic.items())
for deadline, time in dic:
time.sort()
for t in time:
if deadline < now + t:
return "No"
now += t
return "Yes"
def main():
N = int(eval(input()))
dic = {}
# A = []
# B = []
for _ in range(N):
a, b = list(map(int, input().split()))
if b in list(dic.keys()):
dic[b].append(a)
else:
dic[b] = [a]
# A.append(a)
# B.append(b)
print((modelAnswer(N, dic)))
if __name__ == "__main__":
main()
| false | 3.448276 | [
"+import sys",
"+",
"+input = sys.stdin.readline"
] | false | 0.040137 | 0.044041 | 0.911357 | [
"s289345089",
"s833232751"
] |
u903460784 | p03049 | python | s961364133 | s001532391 | 53 | 42 | 3,828 | 3,828 | Accepted | Accepted | 20.75 | n=int(eval(input()))
s=[eval(input()) for _ in range(n)]
isFinishA=[s[i][-1]=='A' for i in range(n)]
isStartB=[s[i][0]=='B' for i in range(n)]
ans=0
for si in s:
wasA=False
for sij in si:
if sij=='B':
if wasA:
ans+=1
wasA=(sij=='A')
fromBtoA=0
fromB=0
toA=0
for i in range(n):
if isFinishA[i]:
if isStartB[i]:
fromBtoA+=1
else:
toA+=1
else:
if isStartB[i]:
fromB+=1
if fromBtoA==0:
ans+=min(fromB,toA)
else:
if fromB+toA>0:
ans+=fromBtoA+min(fromB,toA)
if fromB+toA==0:
ans+=fromBtoA-1
# print(fromB,toA,fromBtoA)
print(ans)
| n=int(eval(input()))
s=[eval(input()) for _ in range(n)]
isFinishA=[s[i][-1]=='A' for i in range(n)]
isStartB=[s[i][0]=='B' for i in range(n)]
ans=0
for si in s:
wasA=False
for sij in si:
if sij=='B':
if wasA:
ans+=1
wasA=(sij=='A')
cnt=[isFinishA.count(True),isStartB.count(True)]
ans+=min(cnt)
fromBtoA=0
for i in range(n):
if isFinishA[i] and isStartB[i]:
fromBtoA+=1
if cnt[0]==cnt[1]==fromBtoA:
if cnt[0]!=0:
ans-=1
print(ans)
| 35 | 23 | 697 | 519 | n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
isFinishA = [s[i][-1] == "A" for i in range(n)]
isStartB = [s[i][0] == "B" for i in range(n)]
ans = 0
for si in s:
wasA = False
for sij in si:
if sij == "B":
if wasA:
ans += 1
wasA = sij == "A"
fromBtoA = 0
fromB = 0
toA = 0
for i in range(n):
if isFinishA[i]:
if isStartB[i]:
fromBtoA += 1
else:
toA += 1
else:
if isStartB[i]:
fromB += 1
if fromBtoA == 0:
ans += min(fromB, toA)
else:
if fromB + toA > 0:
ans += fromBtoA + min(fromB, toA)
if fromB + toA == 0:
ans += fromBtoA - 1
# print(fromB,toA,fromBtoA)
print(ans)
| n = int(eval(input()))
s = [eval(input()) for _ in range(n)]
isFinishA = [s[i][-1] == "A" for i in range(n)]
isStartB = [s[i][0] == "B" for i in range(n)]
ans = 0
for si in s:
wasA = False
for sij in si:
if sij == "B":
if wasA:
ans += 1
wasA = sij == "A"
cnt = [isFinishA.count(True), isStartB.count(True)]
ans += min(cnt)
fromBtoA = 0
for i in range(n):
if isFinishA[i] and isStartB[i]:
fromBtoA += 1
if cnt[0] == cnt[1] == fromBtoA:
if cnt[0] != 0:
ans -= 1
print(ans)
| false | 34.285714 | [
"+cnt = [isFinishA.count(True), isStartB.count(True)]",
"+ans += min(cnt)",
"-fromB = 0",
"-toA = 0",
"- if isFinishA[i]:",
"- if isStartB[i]:",
"- fromBtoA += 1",
"- else:",
"- toA += 1",
"- else:",
"- if isStartB[i]:",
"- fromB += 1",
"-if fromBtoA == 0:",
"- ans += min(fromB, toA)",
"-else:",
"- if fromB + toA > 0:",
"- ans += fromBtoA + min(fromB, toA)",
"- if fromB + toA == 0:",
"- ans += fromBtoA - 1",
"-# print(fromB,toA,fromBtoA)",
"+ if isFinishA[i] and isStartB[i]:",
"+ fromBtoA += 1",
"+if cnt[0] == cnt[1] == fromBtoA:",
"+ if cnt[0] != 0:",
"+ ans -= 1"
] | false | 0.03618 | 0.036689 | 0.986127 | [
"s961364133",
"s001532391"
] |
u077291787 | p03352 | python | s578605260 | s579099236 | 22 | 18 | 3,316 | 2,940 | Accepted | Accepted | 18.18 | # ABC097B - Exponential
def main():
X = int(eval(input()))
cand = {1}
for i in range(2, int(X ** 0.5) + 1):
p = 2
while i ** p <= X:
cand.add(i ** p)
p += 1
ans = max(cand)
print(ans)
if __name__ == "__main__":
main() | # ABC097B - Exponential
def main():
X = int(eval(input()))
cand = [1]
for i in range(2, int(X ** 0.5) + 1):
p = 2
while i ** p <= X:
cand.append(i ** p)
p += 1
ans = max(cand)
print(ans)
if __name__ == "__main__":
main() | 15 | 15 | 291 | 294 | # ABC097B - Exponential
def main():
X = int(eval(input()))
cand = {1}
for i in range(2, int(X**0.5) + 1):
p = 2
while i**p <= X:
cand.add(i**p)
p += 1
ans = max(cand)
print(ans)
if __name__ == "__main__":
main()
| # ABC097B - Exponential
def main():
X = int(eval(input()))
cand = [1]
for i in range(2, int(X**0.5) + 1):
p = 2
while i**p <= X:
cand.append(i**p)
p += 1
ans = max(cand)
print(ans)
if __name__ == "__main__":
main()
| false | 0 | [
"- cand = {1}",
"+ cand = [1]",
"- cand.add(i**p)",
"+ cand.append(i**p)"
] | false | 0.179408 | 0.042653 | 4.206202 | [
"s578605260",
"s579099236"
] |
u614181788 | p02598 | python | s091219925 | s791199889 | 653 | 578 | 59,200 | 59,344 | Accepted | Accepted | 11.49 | n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
s = sum(a)
x = [0]*n
y = 0
r = 0
for i in range(n):
y = int(a[i]/s*k)
x[i] = [i, y, a[i]/(y+1), a[i]]
r += y
x.sort(key= lambda val : val[2],reverse=True)
for i in range(k-r):
x[i][1] += 1
ans = 0
for i in range(n):
ans = max(ans, x[i][3]/(x[i][1]+1))
print((int(-(-ans//1))))
| n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
s = sum(a)
x = [0]*n
t = 0
for i in range(n):
y = int(a[i]/s * k)
x[i] = [i, a[i], y, a[i]/(y+1)]
t += y
x.sort(key= lambda val : val[3],reverse=True)
for i in range(k-t):
x[i][2] += 1
ans = 0
for i in range(n):
ans = max(ans, x[i][1]/(x[i][2]+1))
print((int(-(-ans//1)))) | 17 | 16 | 377 | 371 | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
s = sum(a)
x = [0] * n
y = 0
r = 0
for i in range(n):
y = int(a[i] / s * k)
x[i] = [i, y, a[i] / (y + 1), a[i]]
r += y
x.sort(key=lambda val: val[2], reverse=True)
for i in range(k - r):
x[i][1] += 1
ans = 0
for i in range(n):
ans = max(ans, x[i][3] / (x[i][1] + 1))
print((int(-(-ans // 1))))
| n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
s = sum(a)
x = [0] * n
t = 0
for i in range(n):
y = int(a[i] / s * k)
x[i] = [i, a[i], y, a[i] / (y + 1)]
t += y
x.sort(key=lambda val: val[3], reverse=True)
for i in range(k - t):
x[i][2] += 1
ans = 0
for i in range(n):
ans = max(ans, x[i][1] / (x[i][2] + 1))
print((int(-(-ans // 1))))
| false | 5.882353 | [
"-y = 0",
"-r = 0",
"+t = 0",
"- x[i] = [i, y, a[i] / (y + 1), a[i]]",
"- r += y",
"-x.sort(key=lambda val: val[2], reverse=True)",
"-for i in range(k - r):",
"- x[i][1] += 1",
"+ x[i] = [i, a[i], y, a[i] / (y + 1)]",
"+ t += y",
"+x.sort(key=lambda val: val[3], reverse=True)",
"+for i in range(k - t):",
"+ x[i][2] += 1",
"- ans = max(ans, x[i][3] / (x[i][1] + 1))",
"+ ans = max(ans, x[i][1] / (x[i][2] + 1))"
] | false | 0.04954 | 0.105224 | 0.470808 | [
"s091219925",
"s791199889"
] |
u729133443 | p02733 | python | s717090225 | s755453915 | 1,038 | 383 | 51,672 | 44,124 | Accepted | Accepted | 63.1 | r=range
h,*s=open(0)
h,w,k,*m=list(map(int,h.split()))
for i in r(512):
t=[j+1for j in r(h)if i>>j&1]+[h];l=len(t);v=1;c=[0]*l
for i in r(w):
b=f=g=0;u=[]
for j in r(l):d,b=sum(s[j][i]>"0"for j in r(b,t[j])),t[j];u+=d,;g|=d>k;c[j]+=d;f|=c[j]>k
v-=f
if f:c=u
if g<1:m+=l-v,
print((min(m))) | x,*s=open(0)
h,w,k,*m=list(map(int,x.split()))
for b in range(512):
r=t=j=0;d=[0]*h
while w-j:
i=c=0
while h-i:
d[c]+=s[i][j]>'0';x=d[c]>k
if(t<j)&x:r+=1;t=j;d=[0]*h;break
r+=h*w*x;c+=b>>i&1;i+=1
else:j+=1
m+=r+bin(b).count('1'),
print((min(m))) | 12 | 13 | 302 | 267 | r = range
h, *s = open(0)
h, w, k, *m = list(map(int, h.split()))
for i in r(512):
t = [j + 1 for j in r(h) if i >> j & 1] + [h]
l = len(t)
v = 1
c = [0] * l
for i in r(w):
b = f = g = 0
u = []
for j in r(l):
d, b = sum(s[j][i] > "0" for j in r(b, t[j])), t[j]
u += (d,)
g |= d > k
c[j] += d
f |= c[j] > k
v -= f
if f:
c = u
if g < 1:
m += (l - v,)
print((min(m)))
| x, *s = open(0)
h, w, k, *m = list(map(int, x.split()))
for b in range(512):
r = t = j = 0
d = [0] * h
while w - j:
i = c = 0
while h - i:
d[c] += s[i][j] > "0"
x = d[c] > k
if (t < j) & x:
r += 1
t = j
d = [0] * h
break
r += h * w * x
c += b >> i & 1
i += 1
else:
j += 1
m += (r + bin(b).count("1"),)
print((min(m)))
| false | 7.692308 | [
"-r = range",
"-h, *s = open(0)",
"-h, w, k, *m = list(map(int, h.split()))",
"-for i in r(512):",
"- t = [j + 1 for j in r(h) if i >> j & 1] + [h]",
"- l = len(t)",
"- v = 1",
"- c = [0] * l",
"- for i in r(w):",
"- b = f = g = 0",
"- u = []",
"- for j in r(l):",
"- d, b = sum(s[j][i] > \"0\" for j in r(b, t[j])), t[j]",
"- u += (d,)",
"- g |= d > k",
"- c[j] += d",
"- f |= c[j] > k",
"- v -= f",
"- if f:",
"- c = u",
"- if g < 1:",
"- m += (l - v,)",
"+x, *s = open(0)",
"+h, w, k, *m = list(map(int, x.split()))",
"+for b in range(512):",
"+ r = t = j = 0",
"+ d = [0] * h",
"+ while w - j:",
"+ i = c = 0",
"+ while h - i:",
"+ d[c] += s[i][j] > \"0\"",
"+ x = d[c] > k",
"+ if (t < j) & x:",
"+ r += 1",
"+ t = j",
"+ d = [0] * h",
"+ break",
"+ r += h * w * x",
"+ c += b >> i & 1",
"+ i += 1",
"+ else:",
"+ j += 1",
"+ m += (r + bin(b).count(\"1\"),)"
] | false | 0.060493 | 0.117842 | 0.513339 | [
"s717090225",
"s755453915"
] |
u952708174 | p02775 | python | s545720449 | s998305038 | 985 | 413 | 5,492 | 26,472 | Accepted | Accepted | 58.07 | def e_payment():
N = eval(input())
dp = (0, 1) # 「最下位桁の 1 つ下の桁」を仮想した場合分けを省くための初期化
for k, ch in enumerate(N[::-1]): # 最下位の桁から見る
n = int(ch)
t1, t2 = dp
a = min(t1 + n, t2 + n + 1)
b = min(t1 + (10 - n), t2 + (10 - (n + 1)))
dp = (a, b)
return min(dp[0], dp[1] + 1)
print((e_payment())) | def e_payment_greedy():
N = [int(i) for i in list(eval(input()))]
s = N[::-1] + [0] # [-d-1]: 最終的に 10**d 円札を何枚受渡ししたかが格納される
for i in range(len(N)):
if s[i] >= 6 or (s[i] == 5 and s[i + 1] >= 5):
s[i] = 10 - s[i]
s[i + 1] += 1
return sum(s)
print((e_payment_greedy())) | 13 | 11 | 348 | 319 | def e_payment():
N = eval(input())
dp = (0, 1) # 「最下位桁の 1 つ下の桁」を仮想した場合分けを省くための初期化
for k, ch in enumerate(N[::-1]): # 最下位の桁から見る
n = int(ch)
t1, t2 = dp
a = min(t1 + n, t2 + n + 1)
b = min(t1 + (10 - n), t2 + (10 - (n + 1)))
dp = (a, b)
return min(dp[0], dp[1] + 1)
print((e_payment()))
| def e_payment_greedy():
N = [int(i) for i in list(eval(input()))]
s = N[::-1] + [0] # [-d-1]: 最終的に 10**d 円札を何枚受渡ししたかが格納される
for i in range(len(N)):
if s[i] >= 6 or (s[i] == 5 and s[i + 1] >= 5):
s[i] = 10 - s[i]
s[i + 1] += 1
return sum(s)
print((e_payment_greedy()))
| false | 15.384615 | [
"-def e_payment():",
"- N = eval(input())",
"- dp = (0, 1) # 「最下位桁の 1 つ下の桁」を仮想した場合分けを省くための初期化",
"- for k, ch in enumerate(N[::-1]): # 最下位の桁から見る",
"- n = int(ch)",
"- t1, t2 = dp",
"- a = min(t1 + n, t2 + n + 1)",
"- b = min(t1 + (10 - n), t2 + (10 - (n + 1)))",
"- dp = (a, b)",
"- return min(dp[0], dp[1] + 1)",
"+def e_payment_greedy():",
"+ N = [int(i) for i in list(eval(input()))]",
"+ s = N[::-1] + [0] # [-d-1]: 最終的に 10**d 円札を何枚受渡ししたかが格納される",
"+ for i in range(len(N)):",
"+ if s[i] >= 6 or (s[i] == 5 and s[i + 1] >= 5):",
"+ s[i] = 10 - s[i]",
"+ s[i + 1] += 1",
"+ return sum(s)",
"-print((e_payment()))",
"+print((e_payment_greedy()))"
] | false | 0.143758 | 0.137017 | 1.049203 | [
"s545720449",
"s998305038"
] |
u562935282 | p03045 | python | s110687641 | s581730991 | 1,537 | 731 | 121,476 | 7,940 | Accepted | Accepted | 52.44 | class UnionFind:
def __init__(self, n):
self.v = [-1 for _ in range(n)] # 根(負): 連結頂点数 * (-1) / 子(正): 根の頂点番号(0-indexed)
def find(self, x): # xを含む木における根の頂点番号を返す
if self.v[x] < 0: # (負)は根
return x
else: # 根の頂点番号
self.v[x] = self.find(self.v[x]) # uniteでは, 旧根に属する頂点の根が旧根のままなので更新
return self.v[x]
def unite(self, x, y): # 違う根に属していたらrankが低くなるように連結
x = self.find(x)
y = self.find(y)
if x == y:
return
if -self.v[x] < -self.v[y]: # size比較, (-1) * (連結頂点数 * (-1)), (正)同士の大小比較
x, y = y, x # 連結頂点数が少ない方をyにすると, findでの更新回数が減る?
self.v[x] += self.v[y] # 連結頂点数の和を取る, 連結頂点数 * (-1)
self.v[y] = x # 連結頂点数が少ないy(引数yの根の頂点番号)の根をx(引数xの根の頂点番号)にする
def root(self, x):
return self.v[x] < 0 # (負)は根
def same(self, x, y):
return self.find(x) == self.find(y) # 同じ根に属するか
def size(self, x):
return -self.v[self.find(x)] # 連結頂点数を返す
N, M = list(map(int, input().split()))
uf = UnionFind(N * 2)
for _ in range(M):
x, y, z = list(map(int, input().split()))
x -= 1
y -= 1
if z % 2 == 0:
uf.unite(x, y)
uf.unite(x + N, y + N)
else:
uf.unite(x, y + N)
uf.unite(x + N, y)
# print(uf.v)
ans = 0
for i in range(N):
if uf.root(i):
ans += 1
print(ans)
| class UnionFind:
def __init__(self, n):
self.v = [-1 for _ in range(n)]
def find(self, x):
if self.v[x] < 0:
return x
else:
self.v[x] = self.find(self.v[x])
return self.v[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if -self.v[x] < -self.v[y]:
x, y = y, x
self.v[x] += self.v[y]
self.v[y] = x
def root(self, x):
return self.v[x] < 0
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.v[self.find(x)]
N, M = list(map(int, input().split()))
uf = UnionFind(N * 2)
for _ in range(M):
x, y, z = list(map(int, input().split()))
x -= 1
y -= 1
if z & 1:
uf.unite(x + N, y)
uf.unite(x, y + N)
else:
uf.unite(x, y)
uf.unite(x + N, y + N)
print((sum(1 for i in range(N) if uf.root(i))))
| 51 | 45 | 1,411 | 1,018 | class UnionFind:
def __init__(self, n):
self.v = [-1 for _ in range(n)] # 根(負): 連結頂点数 * (-1) / 子(正): 根の頂点番号(0-indexed)
def find(self, x): # xを含む木における根の頂点番号を返す
if self.v[x] < 0: # (負)は根
return x
else: # 根の頂点番号
self.v[x] = self.find(self.v[x]) # uniteでは, 旧根に属する頂点の根が旧根のままなので更新
return self.v[x]
def unite(self, x, y): # 違う根に属していたらrankが低くなるように連結
x = self.find(x)
y = self.find(y)
if x == y:
return
if -self.v[x] < -self.v[y]: # size比較, (-1) * (連結頂点数 * (-1)), (正)同士の大小比較
x, y = y, x # 連結頂点数が少ない方をyにすると, findでの更新回数が減る?
self.v[x] += self.v[y] # 連結頂点数の和を取る, 連結頂点数 * (-1)
self.v[y] = x # 連結頂点数が少ないy(引数yの根の頂点番号)の根をx(引数xの根の頂点番号)にする
def root(self, x):
return self.v[x] < 0 # (負)は根
def same(self, x, y):
return self.find(x) == self.find(y) # 同じ根に属するか
def size(self, x):
return -self.v[self.find(x)] # 連結頂点数を返す
N, M = list(map(int, input().split()))
uf = UnionFind(N * 2)
for _ in range(M):
x, y, z = list(map(int, input().split()))
x -= 1
y -= 1
if z % 2 == 0:
uf.unite(x, y)
uf.unite(x + N, y + N)
else:
uf.unite(x, y + N)
uf.unite(x + N, y)
# print(uf.v)
ans = 0
for i in range(N):
if uf.root(i):
ans += 1
print(ans)
| class UnionFind:
def __init__(self, n):
self.v = [-1 for _ in range(n)]
def find(self, x):
if self.v[x] < 0:
return x
else:
self.v[x] = self.find(self.v[x])
return self.v[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if -self.v[x] < -self.v[y]:
x, y = y, x
self.v[x] += self.v[y]
self.v[y] = x
def root(self, x):
return self.v[x] < 0
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.v[self.find(x)]
N, M = list(map(int, input().split()))
uf = UnionFind(N * 2)
for _ in range(M):
x, y, z = list(map(int, input().split()))
x -= 1
y -= 1
if z & 1:
uf.unite(x + N, y)
uf.unite(x, y + N)
else:
uf.unite(x, y)
uf.unite(x + N, y + N)
print((sum(1 for i in range(N) if uf.root(i))))
| false | 11.764706 | [
"- self.v = [-1 for _ in range(n)] # 根(負): 連結頂点数 * (-1) / 子(正): 根の頂点番号(0-indexed)",
"+ self.v = [-1 for _ in range(n)]",
"- def find(self, x): # xを含む木における根の頂点番号を返す",
"- if self.v[x] < 0: # (負)は根",
"+ def find(self, x):",
"+ if self.v[x] < 0:",
"- else: # 根の頂点番号",
"- self.v[x] = self.find(self.v[x]) # uniteでは, 旧根に属する頂点の根が旧根のままなので更新",
"+ else:",
"+ self.v[x] = self.find(self.v[x])",
"- def unite(self, x, y): # 違う根に属していたらrankが低くなるように連結",
"+ def unite(self, x, y):",
"- if -self.v[x] < -self.v[y]: # size比較, (-1) * (連結頂点数 * (-1)), (正)同士の大小比較",
"- x, y = y, x # 連結頂点数が少ない方をyにすると, findでの更新回数が減る?",
"- self.v[x] += self.v[y] # 連結頂点数の和を取る, 連結頂点数 * (-1)",
"- self.v[y] = x # 連結頂点数が少ないy(引数yの根の頂点番号)の根をx(引数xの根の頂点番号)にする",
"+ if -self.v[x] < -self.v[y]:",
"+ x, y = y, x",
"+ self.v[x] += self.v[y]",
"+ self.v[y] = x",
"- return self.v[x] < 0 # (負)は根",
"+ return self.v[x] < 0",
"- return self.find(x) == self.find(y) # 同じ根に属するか",
"+ return self.find(x) == self.find(y)",
"- return -self.v[self.find(x)] # 連結頂点数を返す",
"+ return -self.v[self.find(x)]",
"- if z % 2 == 0:",
"+ if z & 1:",
"+ uf.unite(x + N, y)",
"+ uf.unite(x, y + N)",
"+ else:",
"- else:",
"- uf.unite(x, y + N)",
"- uf.unite(x + N, y)",
"-# print(uf.v)",
"-ans = 0",
"-for i in range(N):",
"- if uf.root(i):",
"- ans += 1",
"-print(ans)",
"+print((sum(1 for i in range(N) if uf.root(i))))"
] | false | 0.049355 | 0.112835 | 0.437408 | [
"s110687641",
"s581730991"
] |
u948524308 | p03379 | python | s809451296 | s573293575 | 575 | 306 | 42,660 | 25,620 | Accepted | Accepted | 46.78 | import collections
N=int(eval(input()))
X=list(map(int,input().split()))
B_dict=collections.Counter(X)
B=sorted(B_dict.items())
cnt=0
for i in range(len(B)):
cnt+=B[i][1]
if cnt==N//2:
ans1=B[i][0]
ans2=B[i+1][0]
break
elif cnt>=N//2+1:
ans1=B[i][0]
ans2=B[i][0]
break
for i in range(N):
if X[i]<=ans1:
print(ans2)
else:
print(ans1)
| N=int(eval(input()))
X=list(map(int,input().split()))
Xsorted=sorted(X)
ans1=Xsorted[(N-1)//2]
ans2=Xsorted[(N-1)//2+1]
for i in range(N):
if X[i]<=ans1:
print(ans2)
else:
print(ans1)
| 28 | 14 | 445 | 219 | import collections
N = int(eval(input()))
X = list(map(int, input().split()))
B_dict = collections.Counter(X)
B = sorted(B_dict.items())
cnt = 0
for i in range(len(B)):
cnt += B[i][1]
if cnt == N // 2:
ans1 = B[i][0]
ans2 = B[i + 1][0]
break
elif cnt >= N // 2 + 1:
ans1 = B[i][0]
ans2 = B[i][0]
break
for i in range(N):
if X[i] <= ans1:
print(ans2)
else:
print(ans1)
| N = int(eval(input()))
X = list(map(int, input().split()))
Xsorted = sorted(X)
ans1 = Xsorted[(N - 1) // 2]
ans2 = Xsorted[(N - 1) // 2 + 1]
for i in range(N):
if X[i] <= ans1:
print(ans2)
else:
print(ans1)
| false | 50 | [
"-import collections",
"-",
"-B_dict = collections.Counter(X)",
"-B = sorted(B_dict.items())",
"-cnt = 0",
"-for i in range(len(B)):",
"- cnt += B[i][1]",
"- if cnt == N // 2:",
"- ans1 = B[i][0]",
"- ans2 = B[i + 1][0]",
"- break",
"- elif cnt >= N // 2 + 1:",
"- ans1 = B[i][0]",
"- ans2 = B[i][0]",
"- break",
"+Xsorted = sorted(X)",
"+ans1 = Xsorted[(N - 1) // 2]",
"+ans2 = Xsorted[(N - 1) // 2 + 1]"
] | false | 0.04114 | 0.038441 | 1.070197 | [
"s809451296",
"s573293575"
] |
u761320129 | p02844 | python | s761078373 | s972211183 | 1,726 | 1,104 | 5,572 | 5,824 | Accepted | Accepted | 36.04 | N = int(eval(input()))
S = eval(input())
lset = [0]
for c in S:
lset.append(lset[-1] | (1<<int(c)))
rset = [0]
for c in S[::-1]:
rset.append(rset[-1] | (1<<int(c)))
rset.reverse()
ptns = [set() for i in range(10)]
for i,c in enumerate(S):
for j in range(10):
if lset[i] & (1<<j) == 0: continue
for k in range(10):
if rset[i+1] & (1<<k) == 0: continue
ptns[int(c)].add(j*10 + k)
print((sum(len(p) for p in ptns))) | N = int(eval(input()))
S = eval(input())
lc = [0]
for c in S:
lc.append(lc[-1] | (1<<int(c)))
rc = [0]
for c in S[::-1]:
rc.append(rc[-1] | (1<<int(c)))
rc.reverse()
mem = [set() for _ in range(10)]
for c,l,r in zip(S,lc,rc[1:]):
c = int(c)
for i in range(10):
if l&(1<<i)==0: continue
for j in range(10):
if r&(1<<j)==0: continue
mem[c].add(10*i+j)
print((sum(len(m) for m in mem))) | 21 | 20 | 474 | 446 | N = int(eval(input()))
S = eval(input())
lset = [0]
for c in S:
lset.append(lset[-1] | (1 << int(c)))
rset = [0]
for c in S[::-1]:
rset.append(rset[-1] | (1 << int(c)))
rset.reverse()
ptns = [set() for i in range(10)]
for i, c in enumerate(S):
for j in range(10):
if lset[i] & (1 << j) == 0:
continue
for k in range(10):
if rset[i + 1] & (1 << k) == 0:
continue
ptns[int(c)].add(j * 10 + k)
print((sum(len(p) for p in ptns)))
| N = int(eval(input()))
S = eval(input())
lc = [0]
for c in S:
lc.append(lc[-1] | (1 << int(c)))
rc = [0]
for c in S[::-1]:
rc.append(rc[-1] | (1 << int(c)))
rc.reverse()
mem = [set() for _ in range(10)]
for c, l, r in zip(S, lc, rc[1:]):
c = int(c)
for i in range(10):
if l & (1 << i) == 0:
continue
for j in range(10):
if r & (1 << j) == 0:
continue
mem[c].add(10 * i + j)
print((sum(len(m) for m in mem)))
| false | 4.761905 | [
"-lset = [0]",
"+lc = [0]",
"- lset.append(lset[-1] | (1 << int(c)))",
"-rset = [0]",
"+ lc.append(lc[-1] | (1 << int(c)))",
"+rc = [0]",
"- rset.append(rset[-1] | (1 << int(c)))",
"-rset.reverse()",
"-ptns = [set() for i in range(10)]",
"-for i, c in enumerate(S):",
"- for j in range(10):",
"- if lset[i] & (1 << j) == 0:",
"+ rc.append(rc[-1] | (1 << int(c)))",
"+rc.reverse()",
"+mem = [set() for _ in range(10)]",
"+for c, l, r in zip(S, lc, rc[1:]):",
"+ c = int(c)",
"+ for i in range(10):",
"+ if l & (1 << i) == 0:",
"- for k in range(10):",
"- if rset[i + 1] & (1 << k) == 0:",
"+ for j in range(10):",
"+ if r & (1 << j) == 0:",
"- ptns[int(c)].add(j * 10 + k)",
"-print((sum(len(p) for p in ptns)))",
"+ mem[c].add(10 * i + j)",
"+print((sum(len(m) for m in mem)))"
] | false | 0.040974 | 0.040864 | 1.002697 | [
"s761078373",
"s972211183"
] |
u763881112 | p03416 | python | s549940321 | s105128598 | 219 | 189 | 12,388 | 12,504 | Accepted | Accepted | 13.7 |
import numpy as np
a,b=list(map(int,input().split()))
ans=0
def check(x):
s=str(x)
for i in range(len(s)):
if(s[i]!=s[len(s)-1-i]):return False
return True
for i in range(a,b+1):
if(check(i)):ans+=1
print(ans) |
import numpy as np
a,b=list(map(int,input().split()))
ans=0
def check(x):
s=str(x)
return s==s[::-1]
for i in range(a,b+1):
if(check(i)):ans+=1
print(ans) | 16 | 14 | 247 | 178 | import numpy as np
a, b = list(map(int, input().split()))
ans = 0
def check(x):
s = str(x)
for i in range(len(s)):
if s[i] != s[len(s) - 1 - i]:
return False
return True
for i in range(a, b + 1):
if check(i):
ans += 1
print(ans)
| import numpy as np
a, b = list(map(int, input().split()))
ans = 0
def check(x):
s = str(x)
return s == s[::-1]
for i in range(a, b + 1):
if check(i):
ans += 1
print(ans)
| false | 12.5 | [
"- for i in range(len(s)):",
"- if s[i] != s[len(s) - 1 - i]:",
"- return False",
"- return True",
"+ return s == s[::-1]"
] | false | 0.106968 | 0.116749 | 0.916221 | [
"s549940321",
"s105128598"
] |
u535171899 | p02959 | python | s929763376 | s026984341 | 241 | 185 | 19,156 | 18,624 | Accepted | Accepted | 23.24 | n = int(eval(input()))
a_li = [int(i) for i in input().split()]
b_li = [int(i) for i in input().split()]
if b_li[0]<b_li[-1]:
a_li = a_li[::-1]
b_li = b_li[::-1]
ans = 0
for i in range(0,n):
attack = min(a_li[i],b_li[i])
attack2 = min(a_li[i+1],b_li[i]-min(a_li[i],b_li[i]))
a_li[i]-=attack
a_li[i+1]-=attack2
b_li[i]-=(attack+attack2)
ans+=(attack+attack2)
print(ans)
| n = int(eval(input()))
a_input = list(map(int,input().split()))
b_input = list(map(int,input().split()))
ans=0
for i in range(n):
first_attack=0
second_attack=0
first_attack = min(b_input[i],a_input[i])
a_input[i]-=first_attack
if first_attack<b_input[i]:
second_attack = min(a_input[i+1],b_input[i]-first_attack)
a_input[i+1]-= second_attack
ans+=first_attack+second_attack
print(ans)
| 19 | 17 | 417 | 439 | n = int(eval(input()))
a_li = [int(i) for i in input().split()]
b_li = [int(i) for i in input().split()]
if b_li[0] < b_li[-1]:
a_li = a_li[::-1]
b_li = b_li[::-1]
ans = 0
for i in range(0, n):
attack = min(a_li[i], b_li[i])
attack2 = min(a_li[i + 1], b_li[i] - min(a_li[i], b_li[i]))
a_li[i] -= attack
a_li[i + 1] -= attack2
b_li[i] -= attack + attack2
ans += attack + attack2
print(ans)
| n = int(eval(input()))
a_input = list(map(int, input().split()))
b_input = list(map(int, input().split()))
ans = 0
for i in range(n):
first_attack = 0
second_attack = 0
first_attack = min(b_input[i], a_input[i])
a_input[i] -= first_attack
if first_attack < b_input[i]:
second_attack = min(a_input[i + 1], b_input[i] - first_attack)
a_input[i + 1] -= second_attack
ans += first_attack + second_attack
print(ans)
| false | 10.526316 | [
"-a_li = [int(i) for i in input().split()]",
"-b_li = [int(i) for i in input().split()]",
"-if b_li[0] < b_li[-1]:",
"- a_li = a_li[::-1]",
"- b_li = b_li[::-1]",
"+a_input = list(map(int, input().split()))",
"+b_input = list(map(int, input().split()))",
"-for i in range(0, n):",
"- attack = min(a_li[i], b_li[i])",
"- attack2 = min(a_li[i + 1], b_li[i] - min(a_li[i], b_li[i]))",
"- a_li[i] -= attack",
"- a_li[i + 1] -= attack2",
"- b_li[i] -= attack + attack2",
"- ans += attack + attack2",
"+for i in range(n):",
"+ first_attack = 0",
"+ second_attack = 0",
"+ first_attack = min(b_input[i], a_input[i])",
"+ a_input[i] -= first_attack",
"+ if first_attack < b_input[i]:",
"+ second_attack = min(a_input[i + 1], b_input[i] - first_attack)",
"+ a_input[i + 1] -= second_attack",
"+ ans += first_attack + second_attack"
] | false | 0.034519 | 0.091271 | 0.378199 | [
"s929763376",
"s026984341"
] |
u905582793 | p03231 | python | s005371668 | s841141506 | 39 | 36 | 5,432 | 5,432 | Accepted | Accepted | 7.69 | from fractions import gcd
n,m = list(map(int,input().split()))
s = eval(input())
t = eval(input())
x = gcd(n,m)
for i in range(x):
if s[i*n//x]!=t[i*m//x]:
print((-1))
break
else:
print((n*m//x)) | from fractions import gcd
n,m = list(map(int,input().split()))
s = eval(input())
t = eval(input())
x = gcd(n,m)
if s[::n//x]==t[::m//x]:
print((n*m//x))
else:
print((-1)) | 11 | 9 | 195 | 160 | from fractions import gcd
n, m = list(map(int, input().split()))
s = eval(input())
t = eval(input())
x = gcd(n, m)
for i in range(x):
if s[i * n // x] != t[i * m // x]:
print((-1))
break
else:
print((n * m // x))
| from fractions import gcd
n, m = list(map(int, input().split()))
s = eval(input())
t = eval(input())
x = gcd(n, m)
if s[:: n // x] == t[:: m // x]:
print((n * m // x))
else:
print((-1))
| false | 18.181818 | [
"-for i in range(x):",
"- if s[i * n // x] != t[i * m // x]:",
"- print((-1))",
"- break",
"+if s[:: n // x] == t[:: m // x]:",
"+ print((n * m // x))",
"- print((n * m // x))",
"+ print((-1))"
] | false | 0.042528 | 0.043443 | 0.97895 | [
"s005371668",
"s841141506"
] |
u609061751 | p03524 | python | s155473217 | s084825790 | 186 | 26 | 39,408 | 3,444 | Accepted | Accepted | 86.02 | import sys
input = sys.stdin.readline
s = input().rstrip()
from collections import Counter
c = Counter(s)
if len(s) == 1:
print("YES")
sys.exit()
if len(list(c.keys())) == 1:
print("NO")
sys.exit()
values = list(c.values())
values.sort()
if len(list(c.keys())) == 2:
if values[0] == 1 and values[1] == 1:
print("YES")
else:
print("NO")
sys.exit()
values[1] -= values[0]
values[2] -= values[0]
if values[1] == 1 and values[2] == 1:
print("YES")
elif values[1] == 0 and values[2] == 1:
print("YES")
elif values[1] == 1 and values[2] == 0:
print("YES")
elif values[1] == 0 and values[2] == 0:
print("YES")
else:
print("NO")
sys.exit()
| import sys
input = lambda : sys.stdin.readline().rstrip()
mod = 10**9 + 7
s = eval(input())
from collections import Counter
c = Counter(s)
A = c["a"]
B = c["b"]
C = c["c"]
if len(list(c.keys())) == 1:
if len(s) > 1:
print("NO")
else:
print("YES")
sys.exit()
if len(list(c.keys())) == 2:
if A + B + C == 2:
print("YES")
else:
print("NO")
sys.exit()
A -= min(c.values())
B -= min(c.values())
C -= min(c.values())
if A >= 2 or B >= 2 or C >= 2:
print("NO")
else:
print("YES") | 42 | 36 | 736 | 561 | import sys
input = sys.stdin.readline
s = input().rstrip()
from collections import Counter
c = Counter(s)
if len(s) == 1:
print("YES")
sys.exit()
if len(list(c.keys())) == 1:
print("NO")
sys.exit()
values = list(c.values())
values.sort()
if len(list(c.keys())) == 2:
if values[0] == 1 and values[1] == 1:
print("YES")
else:
print("NO")
sys.exit()
values[1] -= values[0]
values[2] -= values[0]
if values[1] == 1 and values[2] == 1:
print("YES")
elif values[1] == 0 and values[2] == 1:
print("YES")
elif values[1] == 1 and values[2] == 0:
print("YES")
elif values[1] == 0 and values[2] == 0:
print("YES")
else:
print("NO")
sys.exit()
| import sys
input = lambda: sys.stdin.readline().rstrip()
mod = 10**9 + 7
s = eval(input())
from collections import Counter
c = Counter(s)
A = c["a"]
B = c["b"]
C = c["c"]
if len(list(c.keys())) == 1:
if len(s) > 1:
print("NO")
else:
print("YES")
sys.exit()
if len(list(c.keys())) == 2:
if A + B + C == 2:
print("YES")
else:
print("NO")
sys.exit()
A -= min(c.values())
B -= min(c.values())
C -= min(c.values())
if A >= 2 or B >= 2 or C >= 2:
print("NO")
else:
print("YES")
| false | 14.285714 | [
"-input = sys.stdin.readline",
"-s = input().rstrip()",
"+input = lambda: sys.stdin.readline().rstrip()",
"+mod = 10**9 + 7",
"+s = eval(input())",
"-if len(s) == 1:",
"- print(\"YES\")",
"+A = c[\"a\"]",
"+B = c[\"b\"]",
"+C = c[\"c\"]",
"+if len(list(c.keys())) == 1:",
"+ if len(s) > 1:",
"+ print(\"NO\")",
"+ else:",
"+ print(\"YES\")",
"-if len(list(c.keys())) == 1:",
"- print(\"NO\")",
"- sys.exit()",
"-values = list(c.values())",
"-values.sort()",
"- if values[0] == 1 and values[1] == 1:",
"+ if A + B + C == 2:",
"-values[1] -= values[0]",
"-values[2] -= values[0]",
"-if values[1] == 1 and values[2] == 1:",
"+A -= min(c.values())",
"+B -= min(c.values())",
"+C -= min(c.values())",
"+if A >= 2 or B >= 2 or C >= 2:",
"+ print(\"NO\")",
"+else:",
"-elif values[1] == 0 and values[2] == 1:",
"- print(\"YES\")",
"-elif values[1] == 1 and values[2] == 0:",
"- print(\"YES\")",
"-elif values[1] == 0 and values[2] == 0:",
"- print(\"YES\")",
"-else:",
"- print(\"NO\")",
"-sys.exit()"
] | false | 0.007708 | 0.038586 | 0.199754 | [
"s155473217",
"s084825790"
] |
u546285759 | p00100 | python | s520730711 | s205314062 | 60 | 30 | 7,764 | 7,916 | Accepted | Accepted | 50 | while True:
n = int(eval(input()))
if n == 0: break
d = dict()
order = []
for _ in range(n):
i, p, q = list(map(int, input().split()))
d[i] = d[i]+p*q if i in d else p*q
if i not in order: order.append(i)
b = True
for o in order:
if d[o] > 999999:
print(o)
b = False
if b: print("NA") | while True:
n = int(eval(input()))
if n == 0:
break
d = dict()
sep = []
for _ in range(n):
i, p, q = list(map(int, input().split()))
if i in d:
d[i] += p*q
else:
d[i] = p*q
sep.append(i)
tmp = list([x for x in list(d.items()) if x[1] >= 1000000])
if len(tmp):
tmp = {t[0]: t[1] for t in tmp}
for s in sep:
if s in tmp:
print(s)
else:
print("NA") | 15 | 21 | 374 | 502 | while True:
n = int(eval(input()))
if n == 0:
break
d = dict()
order = []
for _ in range(n):
i, p, q = list(map(int, input().split()))
d[i] = d[i] + p * q if i in d else p * q
if i not in order:
order.append(i)
b = True
for o in order:
if d[o] > 999999:
print(o)
b = False
if b:
print("NA")
| while True:
n = int(eval(input()))
if n == 0:
break
d = dict()
sep = []
for _ in range(n):
i, p, q = list(map(int, input().split()))
if i in d:
d[i] += p * q
else:
d[i] = p * q
sep.append(i)
tmp = list([x for x in list(d.items()) if x[1] >= 1000000])
if len(tmp):
tmp = {t[0]: t[1] for t in tmp}
for s in sep:
if s in tmp:
print(s)
else:
print("NA")
| false | 28.571429 | [
"- order = []",
"+ sep = []",
"- d[i] = d[i] + p * q if i in d else p * q",
"- if i not in order:",
"- order.append(i)",
"- b = True",
"- for o in order:",
"- if d[o] > 999999:",
"- print(o)",
"- b = False",
"- if b:",
"+ if i in d:",
"+ d[i] += p * q",
"+ else:",
"+ d[i] = p * q",
"+ sep.append(i)",
"+ tmp = list([x for x in list(d.items()) if x[1] >= 1000000])",
"+ if len(tmp):",
"+ tmp = {t[0]: t[1] for t in tmp}",
"+ for s in sep:",
"+ if s in tmp:",
"+ print(s)",
"+ else:"
] | false | 0.044871 | 0.045336 | 0.989758 | [
"s520730711",
"s205314062"
] |
u021019433 | p02996 | python | s287658912 | s374132524 | 992 | 796 | 45,980 | 31,972 | Accepted | Accepted | 19.76 | from operator import itemgetter
from itertools import accumulate
n = int(eval(input()))
a = sorted((tuple(map(int, input().split())) for _ in range(n)),
key=itemgetter(1))
c, d = list(zip(*a))
print(('YNeos'[any(x > y for x, y in zip(accumulate(c), d))::2])) | from operator import itemgetter
from itertools import accumulate
n = int(eval(input()))
a = sorted((tuple(map(int, input().split())) for _ in range(n)),
key=itemgetter(1))
c, d = (list(map(itemgetter(i), a)) for i in (0, 1))
print(('YNeos'[any(x > y for x, y in zip(accumulate(c), d))::2]))
| 8 | 8 | 264 | 297 | from operator import itemgetter
from itertools import accumulate
n = int(eval(input()))
a = sorted((tuple(map(int, input().split())) for _ in range(n)), key=itemgetter(1))
c, d = list(zip(*a))
print(("YNeos"[any(x > y for x, y in zip(accumulate(c), d)) :: 2]))
| from operator import itemgetter
from itertools import accumulate
n = int(eval(input()))
a = sorted((tuple(map(int, input().split())) for _ in range(n)), key=itemgetter(1))
c, d = (list(map(itemgetter(i), a)) for i in (0, 1))
print(("YNeos"[any(x > y for x, y in zip(accumulate(c), d)) :: 2]))
| false | 0 | [
"-c, d = list(zip(*a))",
"+c, d = (list(map(itemgetter(i), a)) for i in (0, 1))"
] | false | 0.103989 | 0.039864 | 2.608639 | [
"s287658912",
"s374132524"
] |
u798803522 | p00189 | python | s098899166 | s540601375 | 60 | 30 | 8,044 | 7,684 | Accepted | Accepted | 50 | from collections import defaultdict
road = int(eval(input()))
while road > 0:
connect = defaultdict(list)
# weight = defaultdict(defaultdict(float("inf")))
answer = [[float("inf") if n != m else 0 for n in range(10)] for m in range(10)]
for _ in range(road):
c1, c2, w = (int(n) for n in input().split(" "))
connect[c1].append(c2)
connect[c2].append(c1)
answer[c1][c2] = w
answer[c2][c1] = w
city = max(connect.keys()) + 1
for i in range(city):
for j in range(city):
for k in range(city):
answer[j][k] = min(answer[j][k], answer[j][i] + answer[i][k])
sum_ans = [-1 , float("inf")]
for i in range(city):
if sum(answer[i][:city]) < sum_ans[1]:
sum_ans = [i, sum(answer[i][:city])]
print((*sum_ans))
road = int(eval(input())) | road = int(eval(input()))
while road > 0:
answer = [[float("inf") if n != m else 0 for n in range(10)] for m in range(10)]
city = 0
for _ in range(road):
c1, c2, w = (int(n) for n in input().split(" "))
answer[c1][c2] = w
answer[c2][c1] = w
city = max(city, c1, c2)
city += 1
for i in range(city):
for j in range(city):
for k in range(city):
answer[j][k] = min(answer[j][k], answer[j][i] + answer[i][k])
sum_ans = [-1 , float("inf")]
for i in range(city):
if sum(answer[i][:city]) < sum_ans[1]:
sum_ans = [i, sum(answer[i][:city])]
print((*sum_ans))
road = int(eval(input())) | 23 | 20 | 866 | 704 | from collections import defaultdict
road = int(eval(input()))
while road > 0:
connect = defaultdict(list)
# weight = defaultdict(defaultdict(float("inf")))
answer = [[float("inf") if n != m else 0 for n in range(10)] for m in range(10)]
for _ in range(road):
c1, c2, w = (int(n) for n in input().split(" "))
connect[c1].append(c2)
connect[c2].append(c1)
answer[c1][c2] = w
answer[c2][c1] = w
city = max(connect.keys()) + 1
for i in range(city):
for j in range(city):
for k in range(city):
answer[j][k] = min(answer[j][k], answer[j][i] + answer[i][k])
sum_ans = [-1, float("inf")]
for i in range(city):
if sum(answer[i][:city]) < sum_ans[1]:
sum_ans = [i, sum(answer[i][:city])]
print((*sum_ans))
road = int(eval(input()))
| road = int(eval(input()))
while road > 0:
answer = [[float("inf") if n != m else 0 for n in range(10)] for m in range(10)]
city = 0
for _ in range(road):
c1, c2, w = (int(n) for n in input().split(" "))
answer[c1][c2] = w
answer[c2][c1] = w
city = max(city, c1, c2)
city += 1
for i in range(city):
for j in range(city):
for k in range(city):
answer[j][k] = min(answer[j][k], answer[j][i] + answer[i][k])
sum_ans = [-1, float("inf")]
for i in range(city):
if sum(answer[i][:city]) < sum_ans[1]:
sum_ans = [i, sum(answer[i][:city])]
print((*sum_ans))
road = int(eval(input()))
| false | 13.043478 | [
"-from collections import defaultdict",
"-",
"- connect = defaultdict(list)",
"- # weight = defaultdict(defaultdict(float(\"inf\")))",
"+ city = 0",
"- connect[c1].append(c2)",
"- connect[c2].append(c1)",
"- city = max(connect.keys()) + 1",
"+ city = max(city, c1, c2)",
"+ city += 1"
] | false | 0.122839 | 0.048587 | 2.528246 | [
"s098899166",
"s540601375"
] |
u961683878 | p03752 | python | s368981158 | s195726289 | 213 | 189 | 12,500 | 12,508 | Accepted | Accepted | 11.27 | import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)
N, K = list(map(int, readline().split()))
A = list(map(int, readline().split()))
ans = pow(10, 11)
for bit in range(1 << (N)):
if bin(bit).count('1') < K:
continue
acc = 0
pre = 0
for i in range(N):
if bit & (1 << i):
if A[i] <= pre:
acc += max(0, pre + 1 - A[i])
pre += 1
pre = max(pre, A[i])
ans = min(ans, acc)
print((int(ans))) | import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)
N, K = list(map(int, readline().split()))
A = list(map(int, readline().split()))
ans = pow(10, 11)
for bit in range(1 << (N)):
if bin(bit).count('1') < K:
continue
acc = 0
pre = A[0] - 1
for i, a in enumerate(A[:]):
if bit & (1 << i):
if pre < a:
pre = a
else:
acc += pre + 1 - a
pre = pre + 1
else:
if pre < a:
pre = a
ans = min(ans, acc)
print((int(ans)))
| 26 | 31 | 632 | 721 | import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)
N, K = list(map(int, readline().split()))
A = list(map(int, readline().split()))
ans = pow(10, 11)
for bit in range(1 << (N)):
if bin(bit).count("1") < K:
continue
acc = 0
pre = 0
for i in range(N):
if bit & (1 << i):
if A[i] <= pre:
acc += max(0, pre + 1 - A[i])
pre += 1
pre = max(pre, A[i])
ans = min(ans, acc)
print((int(ans)))
| import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)
N, K = list(map(int, readline().split()))
A = list(map(int, readline().split()))
ans = pow(10, 11)
for bit in range(1 << (N)):
if bin(bit).count("1") < K:
continue
acc = 0
pre = A[0] - 1
for i, a in enumerate(A[:]):
if bit & (1 << i):
if pre < a:
pre = a
else:
acc += pre + 1 - a
pre = pre + 1
else:
if pre < a:
pre = a
ans = min(ans, acc)
print((int(ans)))
| false | 16.129032 | [
"- pre = 0",
"- for i in range(N):",
"+ pre = A[0] - 1",
"+ for i, a in enumerate(A[:]):",
"- if A[i] <= pre:",
"- acc += max(0, pre + 1 - A[i])",
"- pre += 1",
"- pre = max(pre, A[i])",
"+ if pre < a:",
"+ pre = a",
"+ else:",
"+ acc += pre + 1 - a",
"+ pre = pre + 1",
"+ else:",
"+ if pre < a:",
"+ pre = a"
] | false | 0.10093 | 0.047862 | 2.108758 | [
"s368981158",
"s195726289"
] |
u619144316 | p03048 | python | s750422338 | s137199930 | 1,335 | 509 | 2,940 | 9,176 | Accepted | Accepted | 61.87 | R,G,B,N = list(map(int,input().split()))
cnt = 0
for i in range(N//R+1):
M = N-R*i
for j in range(M//G+1):
L = M-G*j
if L % B == 0:
cnt += 1
print(cnt) | def main():
r,g,b,n = list(map(int,input().split()))
c = 0
for i in range(n//r+1):
m = n - r * i
for j in range(m//g+1):
l = m - g * j
if l % b == 0:
c += 1
print(c)
main() | 10 | 13 | 191 | 264 | R, G, B, N = list(map(int, input().split()))
cnt = 0
for i in range(N // R + 1):
M = N - R * i
for j in range(M // G + 1):
L = M - G * j
if L % B == 0:
cnt += 1
print(cnt)
| def main():
r, g, b, n = list(map(int, input().split()))
c = 0
for i in range(n // r + 1):
m = n - r * i
for j in range(m // g + 1):
l = m - g * j
if l % b == 0:
c += 1
print(c)
main()
| false | 23.076923 | [
"-R, G, B, N = list(map(int, input().split()))",
"-cnt = 0",
"-for i in range(N // R + 1):",
"- M = N - R * i",
"- for j in range(M // G + 1):",
"- L = M - G * j",
"- if L % B == 0:",
"- cnt += 1",
"-print(cnt)",
"+def main():",
"+ r, g, b, n = list(map(int, input().split()))",
"+ c = 0",
"+ for i in range(n // r + 1):",
"+ m = n - r * i",
"+ for j in range(m // g + 1):",
"+ l = m - g * j",
"+ if l % b == 0:",
"+ c += 1",
"+ print(c)",
"+",
"+",
"+main()"
] | false | 0.047439 | 0.051359 | 0.923671 | [
"s750422338",
"s137199930"
] |
u377989038 | p02912 | python | s294971490 | s600439522 | 756 | 160 | 14,380 | 14,380 | Accepted | Accepted | 78.84 | import heapq
import sys
input = sys.stdin.readline
def _heappush_max(heap, item):
heap.append(item)
heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappop_max(heap):
"""Maxheap version of a heappop."""
lastelt = heap.pop() # raises appropriate IndexError if heap is empty
if heap:
returnitem = heap[0]
heap[0] = lastelt
heapq._siftup_max(heap, 0)
return returnitem
return lastelt
def main():
n, m = list(map(int, input().split()))
if n == 1:
a = int(eval(input()))
for i in range(m):
a //= 2
print(a)
exit()
a = (list(map(int, input().split())))
heapq._heapify_max(a)
for i in range(m):
tmp = _heappop_max(a) // 2
_heappush_max(a, tmp)
print((sum(a)))
if __name__ == '__main__':
main()
| import heapq
import math
import sys
input = sys.stdin.readline
def main():
n, m = list(map(int, input().split()))
if n == 1:
a = int(eval(input()))
for i in range(m):
a //= 2
print(a)
exit()
a = (list(map(int, input().split())))
a = [-1 * i for i in a]
heapq.heapify(a)
for i in range(m):
tmp = math.ceil(heapq.heappop(a) / 2)
heapq.heappush(a, tmp)
print((sum(a)*-1))
if __name__ == '__main__':
main() | 43 | 28 | 873 | 514 | import heapq
import sys
input = sys.stdin.readline
def _heappush_max(heap, item):
heap.append(item)
heapq._siftdown_max(heap, 0, len(heap) - 1)
def _heappop_max(heap):
"""Maxheap version of a heappop."""
lastelt = heap.pop() # raises appropriate IndexError if heap is empty
if heap:
returnitem = heap[0]
heap[0] = lastelt
heapq._siftup_max(heap, 0)
return returnitem
return lastelt
def main():
n, m = list(map(int, input().split()))
if n == 1:
a = int(eval(input()))
for i in range(m):
a //= 2
print(a)
exit()
a = list(map(int, input().split()))
heapq._heapify_max(a)
for i in range(m):
tmp = _heappop_max(a) // 2
_heappush_max(a, tmp)
print((sum(a)))
if __name__ == "__main__":
main()
| import heapq
import math
import sys
input = sys.stdin.readline
def main():
n, m = list(map(int, input().split()))
if n == 1:
a = int(eval(input()))
for i in range(m):
a //= 2
print(a)
exit()
a = list(map(int, input().split()))
a = [-1 * i for i in a]
heapq.heapify(a)
for i in range(m):
tmp = math.ceil(heapq.heappop(a) / 2)
heapq.heappush(a, tmp)
print((sum(a) * -1))
if __name__ == "__main__":
main()
| false | 34.883721 | [
"+import math",
"-",
"-",
"-def _heappush_max(heap, item):",
"- heap.append(item)",
"- heapq._siftdown_max(heap, 0, len(heap) - 1)",
"-",
"-",
"-def _heappop_max(heap):",
"- \"\"\"Maxheap version of a heappop.\"\"\"",
"- lastelt = heap.pop() # raises appropriate IndexError if heap is empty",
"- if heap:",
"- returnitem = heap[0]",
"- heap[0] = lastelt",
"- heapq._siftup_max(heap, 0)",
"- return returnitem",
"- return lastelt",
"- heapq._heapify_max(a)",
"+ a = [-1 * i for i in a]",
"+ heapq.heapify(a)",
"- tmp = _heappop_max(a) // 2",
"- _heappush_max(a, tmp)",
"- print((sum(a)))",
"+ tmp = math.ceil(heapq.heappop(a) / 2)",
"+ heapq.heappush(a, tmp)",
"+ print((sum(a) * -1))"
] | false | 0.037922 | 0.03897 | 0.97309 | [
"s294971490",
"s600439522"
] |
u785205215 | p03553 | python | s263310654 | s172789501 | 36 | 24 | 4,336 | 3,444 | Accepted | Accepted | 33.33 | class Dinic:
def __init__(self, v, inf=float("inf")):
self.V = v
self.inf = inf
self.G = [[] for _ in range(v)]
self.level = [0 for _ in range(v)]
self.iter = [0 for _ in range(v)]
def addEdge(self, fm, to, cap):
'''
to:行き先
cap:容量
rev:反対側の辺
'''
self.G[fm].append({'to':to, 'cap':cap, 'rev':len(self.G[to])})
self.G[to].append({'to':fm, 'cap':0, 'rev':len(self.G[fm])-1})
# sからの最短距離をbfsで計算
def bfs(self, s):
import queue
self.level = [-1 for _ in range(self.V)]
self.level[s] = 0
que = queue.Queue()
que.put(s)
while not que.empty():
v = que.get()
for i in range(len(self.G[v])):
e = self.G[v][i]
if e['cap'] > 0 and self.level[e['to']] < 0:
self.level[e['to']] = self.level[v] + 1
que.put(e['to'])
def dfs(self, v, t, f):
if v == t: return f
for i in range(self.iter[v], len(self.G[v])):
self.iter[v] = i
e = self.G[v][i]
if e['cap'] > 0 and self.level[v] < self.level[e['to']]:
d = self.dfs(e['to'], t ,min(f,e['cap']))
if d > 0:
e['cap'] -= d
self.G[e['to']][e['rev']]['cap'] += d
return d
return 0
def max_flow(self,s,t):
flow = 0
while True:
self.bfs(s)
if self.level[t] < 0: return flow
self.iter = [0 for _ in range(self.V)]
f = self.dfs(s,t,self.inf)
while f > 0:
flow += f
f = self.dfs(s,t,self.inf)
from sys import stdin, setrecursionlimit
def IL():return list(map(int, stdin.readline().split()))
setrecursionlimit(1000000)
def main():
N = int(eval(input()))
a = IL()
d = Dinic(N+2)
res = 0
for i in range(N):
d.addEdge(N,i, max(0, -a[i]))
d.addEdge(i,N+1, max(0,a[i]))
res+=max(0,a[i])
t = 2*i+2
while t<=N:
d.addEdge(i,t-1,float('inf'))
t+=i+1
print((res-d.max_flow(N,N+1)))
if __name__ == "__main__": main() | class Ford_Fulkerson:
def __init__(self, v, inf=float("inf")):
self.V = v
self.inf = inf
self.G = [[] for _ in range(v)]
self.used = [False for _ in range(v)]
def addEdge(self, fm, to, cap):
'''
to:行き先
cap:容量
rev:反対側の辺
'''
self.G[fm].append({'to':to, 'cap':cap, 'rev':len(self.G[to])})
self.G[to].append({'to':fm, 'cap':0, 'rev':len(self.G[fm])-1})
def dfs(self, v, t, f):
if v == t: return f
self.used[v] = True
for i in range(len(self.G[v])):
e = self.G[v][i]
if self.used[e["to"]] != True and e['cap'] > 0:
d = self.dfs(e['to'], t ,min(f, e['cap']))
if d > 0:
e['cap'] -= d
self.G[e['to']][e['rev']]['cap'] += d
return d
return 0
def max_flow(self,s,t):
flow = 0
while True:
self.used = [False for i in range(self.V)]
f = self.dfs(s,t,self.inf)
if f == 0: return flow
flow += f
from sys import stdin, setrecursionlimit
def IL():return list(map(int, stdin.readline().split()))
setrecursionlimit(1000000)
def main():
N = int(eval(input()))
a = IL()
d = Ford_Fulkerson(N+2)
res = 0
for i in range(N):
d.addEdge(N,i, max(0, -a[i]))
d.addEdge(i,N+1, max(0,a[i]))
res+=max(0,a[i])
t = 2*i+2
while t<=N:
d.addEdge(i,t-1,float('inf'))
t+=i+1
print((res-d.max_flow(N,N+1)))
if __name__ == "__main__": main() | 85 | 64 | 1,894 | 1,400 | class Dinic:
def __init__(self, v, inf=float("inf")):
self.V = v
self.inf = inf
self.G = [[] for _ in range(v)]
self.level = [0 for _ in range(v)]
self.iter = [0 for _ in range(v)]
def addEdge(self, fm, to, cap):
"""
to:行き先
cap:容量
rev:反対側の辺
"""
self.G[fm].append({"to": to, "cap": cap, "rev": len(self.G[to])})
self.G[to].append({"to": fm, "cap": 0, "rev": len(self.G[fm]) - 1})
# sからの最短距離をbfsで計算
def bfs(self, s):
import queue
self.level = [-1 for _ in range(self.V)]
self.level[s] = 0
que = queue.Queue()
que.put(s)
while not que.empty():
v = que.get()
for i in range(len(self.G[v])):
e = self.G[v][i]
if e["cap"] > 0 and self.level[e["to"]] < 0:
self.level[e["to"]] = self.level[v] + 1
que.put(e["to"])
def dfs(self, v, t, f):
if v == t:
return f
for i in range(self.iter[v], len(self.G[v])):
self.iter[v] = i
e = self.G[v][i]
if e["cap"] > 0 and self.level[v] < self.level[e["to"]]:
d = self.dfs(e["to"], t, min(f, e["cap"]))
if d > 0:
e["cap"] -= d
self.G[e["to"]][e["rev"]]["cap"] += d
return d
return 0
def max_flow(self, s, t):
flow = 0
while True:
self.bfs(s)
if self.level[t] < 0:
return flow
self.iter = [0 for _ in range(self.V)]
f = self.dfs(s, t, self.inf)
while f > 0:
flow += f
f = self.dfs(s, t, self.inf)
from sys import stdin, setrecursionlimit
def IL():
return list(map(int, stdin.readline().split()))
setrecursionlimit(1000000)
def main():
N = int(eval(input()))
a = IL()
d = Dinic(N + 2)
res = 0
for i in range(N):
d.addEdge(N, i, max(0, -a[i]))
d.addEdge(i, N + 1, max(0, a[i]))
res += max(0, a[i])
t = 2 * i + 2
while t <= N:
d.addEdge(i, t - 1, float("inf"))
t += i + 1
print((res - d.max_flow(N, N + 1)))
if __name__ == "__main__":
main()
| class Ford_Fulkerson:
def __init__(self, v, inf=float("inf")):
self.V = v
self.inf = inf
self.G = [[] for _ in range(v)]
self.used = [False for _ in range(v)]
def addEdge(self, fm, to, cap):
"""
to:行き先
cap:容量
rev:反対側の辺
"""
self.G[fm].append({"to": to, "cap": cap, "rev": len(self.G[to])})
self.G[to].append({"to": fm, "cap": 0, "rev": len(self.G[fm]) - 1})
def dfs(self, v, t, f):
if v == t:
return f
self.used[v] = True
for i in range(len(self.G[v])):
e = self.G[v][i]
if self.used[e["to"]] != True and e["cap"] > 0:
d = self.dfs(e["to"], t, min(f, e["cap"]))
if d > 0:
e["cap"] -= d
self.G[e["to"]][e["rev"]]["cap"] += d
return d
return 0
def max_flow(self, s, t):
flow = 0
while True:
self.used = [False for i in range(self.V)]
f = self.dfs(s, t, self.inf)
if f == 0:
return flow
flow += f
from sys import stdin, setrecursionlimit
def IL():
return list(map(int, stdin.readline().split()))
setrecursionlimit(1000000)
def main():
N = int(eval(input()))
a = IL()
d = Ford_Fulkerson(N + 2)
res = 0
for i in range(N):
d.addEdge(N, i, max(0, -a[i]))
d.addEdge(i, N + 1, max(0, a[i]))
res += max(0, a[i])
t = 2 * i + 2
while t <= N:
d.addEdge(i, t - 1, float("inf"))
t += i + 1
print((res - d.max_flow(N, N + 1)))
if __name__ == "__main__":
main()
| false | 24.705882 | [
"-class Dinic:",
"+class Ford_Fulkerson:",
"- self.level = [0 for _ in range(v)]",
"- self.iter = [0 for _ in range(v)]",
"+ self.used = [False for _ in range(v)]",
"- # sからの最短距離をbfsで計算",
"- def bfs(self, s):",
"- import queue",
"-",
"- self.level = [-1 for _ in range(self.V)]",
"- self.level[s] = 0",
"- que = queue.Queue()",
"- que.put(s)",
"- while not que.empty():",
"- v = que.get()",
"- for i in range(len(self.G[v])):",
"- e = self.G[v][i]",
"- if e[\"cap\"] > 0 and self.level[e[\"to\"]] < 0:",
"- self.level[e[\"to\"]] = self.level[v] + 1",
"- que.put(e[\"to\"])",
"-",
"- for i in range(self.iter[v], len(self.G[v])):",
"- self.iter[v] = i",
"+ self.used[v] = True",
"+ for i in range(len(self.G[v])):",
"- if e[\"cap\"] > 0 and self.level[v] < self.level[e[\"to\"]]:",
"+ if self.used[e[\"to\"]] != True and e[\"cap\"] > 0:",
"- self.bfs(s)",
"- if self.level[t] < 0:",
"+ self.used = [False for i in range(self.V)]",
"+ f = self.dfs(s, t, self.inf)",
"+ if f == 0:",
"- self.iter = [0 for _ in range(self.V)]",
"- f = self.dfs(s, t, self.inf)",
"- while f > 0:",
"- flow += f",
"- f = self.dfs(s, t, self.inf)",
"+ flow += f",
"- d = Dinic(N + 2)",
"+ d = Ford_Fulkerson(N + 2)"
] | false | 0.075691 | 0.060337 | 1.254486 | [
"s263310654",
"s172789501"
] |
u119148115 | p03835 | python | s248201557 | s817276977 | 254 | 122 | 41,068 | 66,988 | Accepted | Accepted | 51.97 | import sys
def S(): return sys.stdin.readline().rstrip()
K,S = list(map(int,S().split()))
ans = 0
for i in range(K+1):
for j in range(K+1):
if 0 <= S-i-j <= K:
ans += 1
print(ans) | import sys
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip())) #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split()) #空白あり
def LS2(): return list(sys.stdin.readline().rstrip()) #空白なし
K,S = MI()
ans = 0
for i in range(K+1):
for j in range(K+1):
if 0 <= S-(i+j) <= K:
ans += 1
print(ans)
| 13 | 21 | 213 | 629 | import sys
def S():
return sys.stdin.readline().rstrip()
K, S = list(map(int, S().split()))
ans = 0
for i in range(K + 1):
for j in range(K + 1):
if 0 <= S - i - j <= K:
ans += 1
print(ans)
| import sys
sys.setrecursionlimit(10**7)
def I():
return int(sys.stdin.readline().rstrip())
def MI():
return list(map(int, sys.stdin.readline().rstrip().split()))
def LI():
return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり
def LI2():
return list(map(int, sys.stdin.readline().rstrip())) # 空白なし
def S():
return sys.stdin.readline().rstrip()
def LS():
return list(sys.stdin.readline().rstrip().split()) # 空白あり
def LS2():
return list(sys.stdin.readline().rstrip()) # 空白なし
K, S = MI()
ans = 0
for i in range(K + 1):
for j in range(K + 1):
if 0 <= S - (i + j) <= K:
ans += 1
print(ans)
| false | 38.095238 | [
"+",
"+sys.setrecursionlimit(10**7)",
"+",
"+",
"+def I():",
"+ return int(sys.stdin.readline().rstrip())",
"+",
"+",
"+def MI():",
"+ return list(map(int, sys.stdin.readline().rstrip().split()))",
"+",
"+",
"+def LI():",
"+ return list(map(int, sys.stdin.readline().rstrip().split())) # 空白あり",
"+",
"+",
"+def LI2():",
"+ return list(map(int, sys.stdin.readline().rstrip())) # 空白なし",
"-K, S = list(map(int, S().split()))",
"+def LS():",
"+ return list(sys.stdin.readline().rstrip().split()) # 空白あり",
"+",
"+",
"+def LS2():",
"+ return list(sys.stdin.readline().rstrip()) # 空白なし",
"+",
"+",
"+K, S = MI()",
"- if 0 <= S - i - j <= K:",
"+ if 0 <= S - (i + j) <= K:"
] | false | 0.061658 | 0.07355 | 0.838316 | [
"s248201557",
"s817276977"
] |
u476124554 | p03106 | python | s231760647 | s725083388 | 27 | 17 | 3,952 | 3,060 | Accepted | Accepted | 37.04 | import queue
a,b,c = list(map(int,input().split()))
q = queue.LifoQueue()
for i in range(1,101):
if(a%i == 0 and b%i == 0):
q.put(i)
for i in range(c-1):
q.get()
print((q.get())) | a,b,k = list(map(int,input().split()))
ans = []
for i in range(1,101):
if a % i == 0 and b % i == 0:
ans.append(i)
ans = sorted(ans,reverse = True)
print((ans[k-1])) | 9 | 7 | 186 | 175 | import queue
a, b, c = list(map(int, input().split()))
q = queue.LifoQueue()
for i in range(1, 101):
if a % i == 0 and b % i == 0:
q.put(i)
for i in range(c - 1):
q.get()
print((q.get()))
| a, b, k = list(map(int, input().split()))
ans = []
for i in range(1, 101):
if a % i == 0 and b % i == 0:
ans.append(i)
ans = sorted(ans, reverse=True)
print((ans[k - 1]))
| false | 22.222222 | [
"-import queue",
"-",
"-a, b, c = list(map(int, input().split()))",
"-q = queue.LifoQueue()",
"+a, b, k = list(map(int, input().split()))",
"+ans = []",
"- q.put(i)",
"-for i in range(c - 1):",
"- q.get()",
"-print((q.get()))",
"+ ans.append(i)",
"+ans = sorted(ans, reverse=True)",
"+print((ans[k - 1]))"
] | false | 0.038631 | 0.034056 | 1.134347 | [
"s231760647",
"s725083388"
] |
u332906195 | p02783 | python | s671820285 | s269381630 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | H, A = list(map(int, input().split()))
print(((H + A - 1) // A))
| H, A = list(map(int, input().split()))
print(((H - 1) // A + 1))
| 2 | 2 | 58 | 58 | H, A = list(map(int, input().split()))
print(((H + A - 1) // A))
| H, A = list(map(int, input().split()))
print(((H - 1) // A + 1))
| false | 0 | [
"-print(((H + A - 1) // A))",
"+print(((H - 1) // A + 1))"
] | false | 0.147118 | 0.134577 | 1.093188 | [
"s671820285",
"s269381630"
] |
u855710796 | p03045 | python | s765847236 | s504246428 | 609 | 351 | 109,620 | 27,948 | Accepted | Accepted | 42.36 | import sys
sys.setrecursionlimit(10**5+1)
N, M = list(map(int, input().split()))
edge = [[] for i in range(N)]
for i in range(M):
x, y, _ = list(map(int, input().split()))
edge[x-1].append(y-1)
edge[y-1].append(x-1)
visited = [False] * N
ans = 0
def dfs(x):
global ans
if not visited[x]:
ans += 1
visited[x] = True
for x_next in edge[x]:
if visited[x_next]:
continue
visited[x_next] = True
dfs(x_next)
for i in range(N):
dfs(i)
print(ans) | from collections import deque
N, M = list(map(int, input().split()))
edge = [[] for i in range(N)]
for i in range(M):
x, y, _ = list(map(int, input().split()))
edge[x-1].append(y-1)
edge[y-1].append(x-1)
visited = [False] * N
ans = 0
for i in range(N):
if visited[i]:
continue
else:
ans += 1
q = deque([i])
while q:
cur = q.pop()
visited[cur] = True
for next in edge[cur]:
if visited[next]:
continue
visited[next] = True
q.append(next)
print(ans) | 30 | 31 | 538 | 591 | import sys
sys.setrecursionlimit(10**5 + 1)
N, M = list(map(int, input().split()))
edge = [[] for i in range(N)]
for i in range(M):
x, y, _ = list(map(int, input().split()))
edge[x - 1].append(y - 1)
edge[y - 1].append(x - 1)
visited = [False] * N
ans = 0
def dfs(x):
global ans
if not visited[x]:
ans += 1
visited[x] = True
for x_next in edge[x]:
if visited[x_next]:
continue
visited[x_next] = True
dfs(x_next)
for i in range(N):
dfs(i)
print(ans)
| from collections import deque
N, M = list(map(int, input().split()))
edge = [[] for i in range(N)]
for i in range(M):
x, y, _ = list(map(int, input().split()))
edge[x - 1].append(y - 1)
edge[y - 1].append(x - 1)
visited = [False] * N
ans = 0
for i in range(N):
if visited[i]:
continue
else:
ans += 1
q = deque([i])
while q:
cur = q.pop()
visited[cur] = True
for next in edge[cur]:
if visited[next]:
continue
visited[next] = True
q.append(next)
print(ans)
| false | 3.225806 | [
"-import sys",
"+from collections import deque",
"-sys.setrecursionlimit(10**5 + 1)",
"-",
"-",
"-def dfs(x):",
"- global ans",
"- if not visited[x]:",
"+for i in range(N):",
"+ if visited[i]:",
"+ continue",
"+ else:",
"- visited[x] = True",
"- for x_next in edge[x]:",
"- if visited[x_next]:",
"- continue",
"- visited[x_next] = True",
"- dfs(x_next)",
"-",
"-",
"-for i in range(N):",
"- dfs(i)",
"+ q = deque([i])",
"+ while q:",
"+ cur = q.pop()",
"+ visited[cur] = True",
"+ for next in edge[cur]:",
"+ if visited[next]:",
"+ continue",
"+ visited[next] = True",
"+ q.append(next)"
] | false | 0.18045 | 0.049226 | 3.665707 | [
"s765847236",
"s504246428"
] |
u215461917 | p03731 | python | s289569963 | s672147872 | 139 | 85 | 25,200 | 25,200 | Accepted | Accepted | 38.85 | n,t = (int(i) for i in input().split())
ni = [int(i) for i in input().split()]
total = 0
for i in range(1,len(ni)) :
delta = ni[i] - ni[i-1]
if delta < t :
total += delta
else :
total += t
print((total+t)) | def main():
N, T = list(map(int, input().split()))
t = list(map(int, input().split()))
s, e = 0, 0
ans = 0
for i in range(N):
if t[i] <= e:
e = t[i] + T
else:
ans += e - s
s = t[i]
e = t[i] + T
ans += e - s
print(ans)
main()
| 14 | 17 | 238 | 329 | n, t = (int(i) for i in input().split())
ni = [int(i) for i in input().split()]
total = 0
for i in range(1, len(ni)):
delta = ni[i] - ni[i - 1]
if delta < t:
total += delta
else:
total += t
print((total + t))
| def main():
N, T = list(map(int, input().split()))
t = list(map(int, input().split()))
s, e = 0, 0
ans = 0
for i in range(N):
if t[i] <= e:
e = t[i] + T
else:
ans += e - s
s = t[i]
e = t[i] + T
ans += e - s
print(ans)
main()
| false | 17.647059 | [
"-n, t = (int(i) for i in input().split())",
"-ni = [int(i) for i in input().split()]",
"-total = 0",
"-for i in range(1, len(ni)):",
"- delta = ni[i] - ni[i - 1]",
"- if delta < t:",
"- total += delta",
"- else:",
"- total += t",
"-print((total + t))",
"+def main():",
"+ N, T = list(map(int, input().split()))",
"+ t = list(map(int, input().split()))",
"+ s, e = 0, 0",
"+ ans = 0",
"+ for i in range(N):",
"+ if t[i] <= e:",
"+ e = t[i] + T",
"+ else:",
"+ ans += e - s",
"+ s = t[i]",
"+ e = t[i] + T",
"+ ans += e - s",
"+ print(ans)",
"+",
"+",
"+main()"
] | false | 0.039794 | 0.039938 | 0.99639 | [
"s289569963",
"s672147872"
] |
u033606236 | p03274 | python | s607337650 | s875965129 | 158 | 122 | 14,564 | 14,568 | Accepted | Accepted | 22.78 | N, K = list(map(int, input().split()))
ary = [0] + list(map(int, input().split()))
ary.sort()
zero = ary.index(0)
a = [abs(i - zero) for i in range(N + 1)]
ary.pop(zero)
ans = float("Inf")
for i in range(N - K + 1):
b = N - i - 1
d = abs(ary[i])
if a[i] >= K:
ans = min(ans, d)
ans = min(ans, d + abs(ary[i] - ary[i + K - 1]))
d = abs(ary[b])
if a[b] >= K:
ans = min(ans, d)
ans = min(ans, d + abs(ary[b] - ary[b - K + 1]))
print(ans) | N, K = list(map(int, input().split()))
ary = list(map(int, input().split()))
ary2 = sorted(ary+[0])
zero = ary2.index(0)
k = [abs(i - zero) if i < zero else ((i + 1) - zero)for i in range(N)]
ans = float("Inf")
for i in range(N - K + 1):
if k[i] <= K:
if ans > abs(ary[i]) + abs(ary[i] - ary[i + (K - 1)]):
ans = abs(ary[i]) + abs(ary[i] - ary[i + (K - 1)])
for i in range(N-1, K-2, -1):
if k[i] <= K:
if ans > abs(ary[i]) + abs(ary[i] - ary[i - (K-1)]):
ans = abs(ary[i]) + abs(ary[i] - ary[i - (K-1)])
print(ans)
| 18 | 15 | 489 | 571 | N, K = list(map(int, input().split()))
ary = [0] + list(map(int, input().split()))
ary.sort()
zero = ary.index(0)
a = [abs(i - zero) for i in range(N + 1)]
ary.pop(zero)
ans = float("Inf")
for i in range(N - K + 1):
b = N - i - 1
d = abs(ary[i])
if a[i] >= K:
ans = min(ans, d)
ans = min(ans, d + abs(ary[i] - ary[i + K - 1]))
d = abs(ary[b])
if a[b] >= K:
ans = min(ans, d)
ans = min(ans, d + abs(ary[b] - ary[b - K + 1]))
print(ans)
| N, K = list(map(int, input().split()))
ary = list(map(int, input().split()))
ary2 = sorted(ary + [0])
zero = ary2.index(0)
k = [abs(i - zero) if i < zero else ((i + 1) - zero) for i in range(N)]
ans = float("Inf")
for i in range(N - K + 1):
if k[i] <= K:
if ans > abs(ary[i]) + abs(ary[i] - ary[i + (K - 1)]):
ans = abs(ary[i]) + abs(ary[i] - ary[i + (K - 1)])
for i in range(N - 1, K - 2, -1):
if k[i] <= K:
if ans > abs(ary[i]) + abs(ary[i] - ary[i - (K - 1)]):
ans = abs(ary[i]) + abs(ary[i] - ary[i - (K - 1)])
print(ans)
| false | 16.666667 | [
"-ary = [0] + list(map(int, input().split()))",
"-ary.sort()",
"-zero = ary.index(0)",
"-a = [abs(i - zero) for i in range(N + 1)]",
"-ary.pop(zero)",
"+ary = list(map(int, input().split()))",
"+ary2 = sorted(ary + [0])",
"+zero = ary2.index(0)",
"+k = [abs(i - zero) if i < zero else ((i + 1) - zero) for i in range(N)]",
"- b = N - i - 1",
"- d = abs(ary[i])",
"- if a[i] >= K:",
"- ans = min(ans, d)",
"- ans = min(ans, d + abs(ary[i] - ary[i + K - 1]))",
"- d = abs(ary[b])",
"- if a[b] >= K:",
"- ans = min(ans, d)",
"- ans = min(ans, d + abs(ary[b] - ary[b - K + 1]))",
"+ if k[i] <= K:",
"+ if ans > abs(ary[i]) + abs(ary[i] - ary[i + (K - 1)]):",
"+ ans = abs(ary[i]) + abs(ary[i] - ary[i + (K - 1)])",
"+for i in range(N - 1, K - 2, -1):",
"+ if k[i] <= K:",
"+ if ans > abs(ary[i]) + abs(ary[i] - ary[i - (K - 1)]):",
"+ ans = abs(ary[i]) + abs(ary[i] - ary[i - (K - 1)])"
] | false | 0.119707 | 0.047557 | 2.517132 | [
"s607337650",
"s875965129"
] |
u852690916 | p03108 | python | s636935258 | s803690611 | 778 | 514 | 100,444 | 71,388 | Accepted | Accepted | 33.93 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
N,M=list(map(int, input().split()))
B=[tuple(map(int, input().split())) for _ in range(M)]
P=list(range(N+1))
C=[1 for _ in range(N+1)]
C[0] = 0
def root(x):
if P[x]==x: return x
P[x] = root(P[x])
return P[x]
def unite(a,b):
ra = root(a)
rb = root(b)
if count(ra) < count(rb): ra,rb = rb,ra
C[ra] += C[rb]
C[rb] = 0
P[rb] = ra
def same(a,b):
return root(a) == root(b)
def count(x):
return C[root(x)]
ans=[0]*(M+1)
ans[M] = N * (N-1) // 2
for i in range(M-1,-1,-1):
a,b = B[i]
if same(a,b):
ans[i] = ans[i+1]
continue
ans[i] = ans[i+1] - count(a) * count(b)
unite(a,b)
for i in range(1,M+1):
print((ans[i])) | import sys
def main():
input = sys.stdin.readline
N,M=list(map(int, input().split()))
AB=[tuple([int(x)-1 for x in input().split()]) for _ in range(M)]
uf = UnionFindTree(N)
mx = N*(N-1)//2
ans = [mx]*M
for i in range(M-1,0,-1):
a,b = AB[i]
ans[i-1] = ans[i] - (0 if uf.same(a, b) else uf.size(a)*uf.size(b))
uf.union(a, b)
for a in ans: print(a)
class UnionFindTree:
def __init__(self, n):
self.parent = [-1] * n
def find(self, x):
p = self.parent
while p[x] >= 0: x, p[x] = p[x], p[p[x]]
return x
def union(self, x, y):
x, y, p = self.find(x), self.find(y), self.parent
if x == y: return
if p[x] > p[y]: x, y = y, x
p[x], p[y] = p[x] + p[y], x
def same(self, x, y): return self.find(x) == self.find(y)
def size(self, x): return -self.parent[self.find(x)]
if __name__ == '__main__':
main() | 43 | 37 | 796 | 976 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
N, M = list(map(int, input().split()))
B = [tuple(map(int, input().split())) for _ in range(M)]
P = list(range(N + 1))
C = [1 for _ in range(N + 1)]
C[0] = 0
def root(x):
if P[x] == x:
return x
P[x] = root(P[x])
return P[x]
def unite(a, b):
ra = root(a)
rb = root(b)
if count(ra) < count(rb):
ra, rb = rb, ra
C[ra] += C[rb]
C[rb] = 0
P[rb] = ra
def same(a, b):
return root(a) == root(b)
def count(x):
return C[root(x)]
ans = [0] * (M + 1)
ans[M] = N * (N - 1) // 2
for i in range(M - 1, -1, -1):
a, b = B[i]
if same(a, b):
ans[i] = ans[i + 1]
continue
ans[i] = ans[i + 1] - count(a) * count(b)
unite(a, b)
for i in range(1, M + 1):
print((ans[i]))
| import sys
def main():
input = sys.stdin.readline
N, M = list(map(int, input().split()))
AB = [tuple([int(x) - 1 for x in input().split()]) for _ in range(M)]
uf = UnionFindTree(N)
mx = N * (N - 1) // 2
ans = [mx] * M
for i in range(M - 1, 0, -1):
a, b = AB[i]
ans[i - 1] = ans[i] - (0 if uf.same(a, b) else uf.size(a) * uf.size(b))
uf.union(a, b)
for a in ans:
print(a)
class UnionFindTree:
def __init__(self, n):
self.parent = [-1] * n
def find(self, x):
p = self.parent
while p[x] >= 0:
x, p[x] = p[x], p[p[x]]
return x
def union(self, x, y):
x, y, p = self.find(x), self.find(y), self.parent
if x == y:
return
if p[x] > p[y]:
x, y = y, x
p[x], p[y] = p[x] + p[y], x
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.parent[self.find(x)]
if __name__ == "__main__":
main()
| false | 13.953488 | [
"-input = sys.stdin.readline",
"-sys.setrecursionlimit(10**6)",
"-N, M = list(map(int, input().split()))",
"-B = [tuple(map(int, input().split())) for _ in range(M)]",
"-P = list(range(N + 1))",
"-C = [1 for _ in range(N + 1)]",
"-C[0] = 0",
"+",
"+def main():",
"+ input = sys.stdin.readline",
"+ N, M = list(map(int, input().split()))",
"+ AB = [tuple([int(x) - 1 for x in input().split()]) for _ in range(M)]",
"+ uf = UnionFindTree(N)",
"+ mx = N * (N - 1) // 2",
"+ ans = [mx] * M",
"+ for i in range(M - 1, 0, -1):",
"+ a, b = AB[i]",
"+ ans[i - 1] = ans[i] - (0 if uf.same(a, b) else uf.size(a) * uf.size(b))",
"+ uf.union(a, b)",
"+ for a in ans:",
"+ print(a)",
"-def root(x):",
"- if P[x] == x:",
"+class UnionFindTree:",
"+ def __init__(self, n):",
"+ self.parent = [-1] * n",
"+",
"+ def find(self, x):",
"+ p = self.parent",
"+ while p[x] >= 0:",
"+ x, p[x] = p[x], p[p[x]]",
"- P[x] = root(P[x])",
"- return P[x]",
"+",
"+ def union(self, x, y):",
"+ x, y, p = self.find(x), self.find(y), self.parent",
"+ if x == y:",
"+ return",
"+ if p[x] > p[y]:",
"+ x, y = y, x",
"+ p[x], p[y] = p[x] + p[y], x",
"+",
"+ def same(self, x, y):",
"+ return self.find(x) == self.find(y)",
"+",
"+ def size(self, x):",
"+ return -self.parent[self.find(x)]",
"-def unite(a, b):",
"- ra = root(a)",
"- rb = root(b)",
"- if count(ra) < count(rb):",
"- ra, rb = rb, ra",
"- C[ra] += C[rb]",
"- C[rb] = 0",
"- P[rb] = ra",
"-",
"-",
"-def same(a, b):",
"- return root(a) == root(b)",
"-",
"-",
"-def count(x):",
"- return C[root(x)]",
"-",
"-",
"-ans = [0] * (M + 1)",
"-ans[M] = N * (N - 1) // 2",
"-for i in range(M - 1, -1, -1):",
"- a, b = B[i]",
"- if same(a, b):",
"- ans[i] = ans[i + 1]",
"- continue",
"- ans[i] = ans[i + 1] - count(a) * count(b)",
"- unite(a, b)",
"-for i in range(1, M + 1):",
"- print((ans[i]))",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.036956 | 0.06084 | 0.607429 | [
"s636935258",
"s803690611"
] |
u056599756 | p03377 | python | s781347062 | s908700913 | 20 | 17 | 3,060 | 2,940 | Accepted | Accepted | 15 | a,b,x=list(map(int, input().split()))
print(("YES" if a<=x and a+b>=x else "NO")) | a,b,x=list(map(int, input().split()))
print(("YES" if a<=x<=a+b else "NO")) | 3 | 3 | 76 | 70 | a, b, x = list(map(int, input().split()))
print(("YES" if a <= x and a + b >= x else "NO"))
| a, b, x = list(map(int, input().split()))
print(("YES" if a <= x <= a + b else "NO"))
| false | 0 | [
"-print((\"YES\" if a <= x and a + b >= x else \"NO\"))",
"+print((\"YES\" if a <= x <= a + b else \"NO\"))"
] | false | 0.041235 | 0.040565 | 1.016526 | [
"s781347062",
"s908700913"
] |
u562935282 | p02833 | python | s417787155 | s290461819 | 171 | 17 | 38,384 | 2,940 | Accepted | Accepted | 90.06 | def main():
N = int(eval(input()))
if N % 2 == 1:
return 0
ret = 0
for p in range(1, 30 + 1):
ret += N // (2 * pow(5, p))
return ret
if __name__ == '__main__':
print((main()))
| N = int(eval(input()))
if N % 2 == 1:
print((0))
else:
N //= 2
print((sum(N // pow(5, j) for j in range(1, 30))))
| 13 | 6 | 223 | 121 | def main():
N = int(eval(input()))
if N % 2 == 1:
return 0
ret = 0
for p in range(1, 30 + 1):
ret += N // (2 * pow(5, p))
return ret
if __name__ == "__main__":
print((main()))
| N = int(eval(input()))
if N % 2 == 1:
print((0))
else:
N //= 2
print((sum(N // pow(5, j) for j in range(1, 30))))
| false | 53.846154 | [
"-def main():",
"- N = int(eval(input()))",
"- if N % 2 == 1:",
"- return 0",
"- ret = 0",
"- for p in range(1, 30 + 1):",
"- ret += N // (2 * pow(5, p))",
"- return ret",
"-",
"-",
"-if __name__ == \"__main__\":",
"- print((main()))",
"+N = int(eval(input()))",
"+if N % 2 == 1:",
"+ print((0))",
"+else:",
"+ N //= 2",
"+ print((sum(N // pow(5, j) for j in range(1, 30))))"
] | false | 0.042312 | 0.036592 | 1.156324 | [
"s417787155",
"s290461819"
] |
u259053514 | p02743 | python | s703033060 | s513041273 | 53 | 34 | 5,588 | 5,076 | Accepted | Accepted | 35.85 | from decimal import *
import math
getcontext().prec = 28
a, b, c = list(map(int, input().split()))
a = Decimal(a)
b = Decimal(b)
c = Decimal(c)
a = Decimal.sqrt(a)
b = Decimal.sqrt(b)
c = Decimal.sqrt(c)
if a + b < c:
print("Yes")
else:
print("No")
| from decimal import *
import math
getcontext().prec = 50
a, b, c = list(map(int, input().split()))
a = Decimal(a)
b = Decimal(b)
c = Decimal(c)
a = Decimal.sqrt(a)
b = Decimal.sqrt(b)
c = Decimal.sqrt(c)
if a + b < c:
print("Yes")
else:
print("No")
| 18 | 18 | 272 | 272 | from decimal import *
import math
getcontext().prec = 28
a, b, c = list(map(int, input().split()))
a = Decimal(a)
b = Decimal(b)
c = Decimal(c)
a = Decimal.sqrt(a)
b = Decimal.sqrt(b)
c = Decimal.sqrt(c)
if a + b < c:
print("Yes")
else:
print("No")
| from decimal import *
import math
getcontext().prec = 50
a, b, c = list(map(int, input().split()))
a = Decimal(a)
b = Decimal(b)
c = Decimal(c)
a = Decimal.sqrt(a)
b = Decimal.sqrt(b)
c = Decimal.sqrt(c)
if a + b < c:
print("Yes")
else:
print("No")
| false | 0 | [
"-getcontext().prec = 28",
"+getcontext().prec = 50"
] | false | 0.044494 | 0.038408 | 1.158465 | [
"s703033060",
"s513041273"
] |
u347640436 | p02793 | python | s798907016 | s282232199 | 277 | 252 | 49,604 | 49,568 | Accepted | Accepted | 9.03 | # エラトステネスの篩, フェルマーの小定理
def make_prime_table(n):
sieve = list(range(n + 1))
sieve[0] = -1
sieve[1] = -1
for i in range(2, int(n ** 0.5) + 1):
if sieve[i] != i:
continue
for j in range(i * i, n + 1, i):
if sieve[j] == j:
sieve[j] = i
return sieve
def prime_factorize(n):
result = []
while n != 1:
p = prime_table[n]
c = 0
while n % p == 0:
n //= p
c += 1
result.append((p, c))
return result
N = int(eval(input()))
A = list(map(int, input().split()))
m = 1000000007
prime_table = make_prime_table(10 ** 6)
lcm_factors = {}
for a in A:
for p, c in prime_factorize(a):
if p not in lcm_factors or lcm_factors[p] < c:
lcm_factors[p] = c
lcm = 1
for p in lcm_factors:
lcm *= pow(p, lcm_factors[p], m)
lcm %= m
result = 0
for i in range(N):
result += lcm * pow(A[i], -1, m)
result %= m
print(result)
| def make_prime_table(n):
sieve = list(range(n + 1))
sieve[0] = -1
sieve[1] = -1
for i in range(4, n + 1, 2):
sieve[i] = 2
for i in range(3, int(n ** 0.5) + 1, 2):
if sieve[i] != i:
continue
for j in range(i * i, n + 1, i * 2):
if sieve[j] == j:
sieve[j] = i
return sieve
def prime_factorize(n):
result = []
while n != 1:
p = prime_table[n]
e = 0
while n % p == 0:
n //= p
e += 1
result.append((p, e))
return result
N = int(eval(input()))
A = list(map(int, input().split()))
m = 1000000007
prime_table = make_prime_table(10 ** 6)
lcm_factors = {}
for a in A:
for p, e in prime_factorize(a):
if p not in lcm_factors or lcm_factors[p] < e:
lcm_factors[p] = e
lcm = 1
for p in lcm_factors:
lcm *= pow(p, lcm_factors[p], m)
lcm %= m
result = 0
for i in range(N):
result += lcm * pow(A[i], m - 2, m)
result %= m
print(result)
| 49 | 50 | 1,026 | 1,068 | # エラトステネスの篩, フェルマーの小定理
def make_prime_table(n):
sieve = list(range(n + 1))
sieve[0] = -1
sieve[1] = -1
for i in range(2, int(n**0.5) + 1):
if sieve[i] != i:
continue
for j in range(i * i, n + 1, i):
if sieve[j] == j:
sieve[j] = i
return sieve
def prime_factorize(n):
result = []
while n != 1:
p = prime_table[n]
c = 0
while n % p == 0:
n //= p
c += 1
result.append((p, c))
return result
N = int(eval(input()))
A = list(map(int, input().split()))
m = 1000000007
prime_table = make_prime_table(10**6)
lcm_factors = {}
for a in A:
for p, c in prime_factorize(a):
if p not in lcm_factors or lcm_factors[p] < c:
lcm_factors[p] = c
lcm = 1
for p in lcm_factors:
lcm *= pow(p, lcm_factors[p], m)
lcm %= m
result = 0
for i in range(N):
result += lcm * pow(A[i], -1, m)
result %= m
print(result)
| def make_prime_table(n):
sieve = list(range(n + 1))
sieve[0] = -1
sieve[1] = -1
for i in range(4, n + 1, 2):
sieve[i] = 2
for i in range(3, int(n**0.5) + 1, 2):
if sieve[i] != i:
continue
for j in range(i * i, n + 1, i * 2):
if sieve[j] == j:
sieve[j] = i
return sieve
def prime_factorize(n):
result = []
while n != 1:
p = prime_table[n]
e = 0
while n % p == 0:
n //= p
e += 1
result.append((p, e))
return result
N = int(eval(input()))
A = list(map(int, input().split()))
m = 1000000007
prime_table = make_prime_table(10**6)
lcm_factors = {}
for a in A:
for p, e in prime_factorize(a):
if p not in lcm_factors or lcm_factors[p] < e:
lcm_factors[p] = e
lcm = 1
for p in lcm_factors:
lcm *= pow(p, lcm_factors[p], m)
lcm %= m
result = 0
for i in range(N):
result += lcm * pow(A[i], m - 2, m)
result %= m
print(result)
| false | 2 | [
"-# エラトステネスの篩, フェルマーの小定理",
"- for i in range(2, int(n**0.5) + 1):",
"+ for i in range(4, n + 1, 2):",
"+ sieve[i] = 2",
"+ for i in range(3, int(n**0.5) + 1, 2):",
"- for j in range(i * i, n + 1, i):",
"+ for j in range(i * i, n + 1, i * 2):",
"- c = 0",
"+ e = 0",
"- c += 1",
"- result.append((p, c))",
"+ e += 1",
"+ result.append((p, e))",
"- for p, c in prime_factorize(a):",
"- if p not in lcm_factors or lcm_factors[p] < c:",
"- lcm_factors[p] = c",
"+ for p, e in prime_factorize(a):",
"+ if p not in lcm_factors or lcm_factors[p] < e:",
"+ lcm_factors[p] = e",
"- result += lcm * pow(A[i], -1, m)",
"+ result += lcm * pow(A[i], m - 2, m)"
] | false | 0.723389 | 1.192445 | 0.606644 | [
"s798907016",
"s282232199"
] |
u867848444 | p03101 | python | s197729558 | s458947371 | 21 | 18 | 3,188 | 2,940 | Accepted | Accepted | 14.29 | H,W=list(map(int,input().split()))
h,w=list(map(int,input().split()))
lw=H*W-(h*W+H*w-h*w)
print(lw) | H,W=list(map(int,input().split()))
h,w=list(map(int,input().split()))
print(((H-h)*(W-w)))
| 4 | 4 | 91 | 81 | H, W = list(map(int, input().split()))
h, w = list(map(int, input().split()))
lw = H * W - (h * W + H * w - h * w)
print(lw)
| H, W = list(map(int, input().split()))
h, w = list(map(int, input().split()))
print(((H - h) * (W - w)))
| false | 0 | [
"-lw = H * W - (h * W + H * w - h * w)",
"-print(lw)",
"+print(((H - h) * (W - w)))"
] | false | 0.04797 | 0.043544 | 1.101657 | [
"s197729558",
"s458947371"
] |
u644907318 | p04044 | python | s620304410 | s924446334 | 74 | 63 | 62,884 | 62,376 | Accepted | Accepted | 14.86 | N,L = list(map(int,input().split()))
S = sorted([input().strip() for _ in range(N)])
x = ""
for i in range(N):
x += S[i]
print(x) | N,L = list(map(int,input().split()))
print(("".join(sorted([input().strip() for _ in range(N)])))) | 6 | 2 | 132 | 91 | N, L = list(map(int, input().split()))
S = sorted([input().strip() for _ in range(N)])
x = ""
for i in range(N):
x += S[i]
print(x)
| N, L = list(map(int, input().split()))
print(("".join(sorted([input().strip() for _ in range(N)]))))
| false | 66.666667 | [
"-S = sorted([input().strip() for _ in range(N)])",
"-x = \"\"",
"-for i in range(N):",
"- x += S[i]",
"-print(x)",
"+print((\"\".join(sorted([input().strip() for _ in range(N)]))))"
] | false | 0.040403 | 0.040258 | 1.003613 | [
"s620304410",
"s924446334"
] |
u375695365 | p02983 | python | s770517156 | s161315506 | 908 | 528 | 3,064 | 9,172 | Accepted | Accepted | 41.85 | a,b=list(map(int,input().split()))
ans=10000
for i in range(a,b):
for j in range(i+1,b+1):
if i>=2019:
i=i%2019
if j>=2019:
j=j%2019
if i==0 or j==0:
print("0")
exit()
else:
if ans>i*j%2019:
ans=i*j%2019
print(ans) | l, r = list(map(int, input().split()))
n = r-l+1
ans1 = 0
ans2 = 0
min1 = 1000000000
min2 = 10000000000
for i in range(min(n, 2024)):
# print(l+i)
if (l+i) % 2019 == 0:
print((0))
break
else:
ans = 10000000000
for i in range(min(n, 2019)):
for j in range(i+1, min(n, 2020)):
# print(l+i, l+j)
if ((l+i)*(l+j)) % 2019 < ans:
ans = ((l+i)*(l+j)) % 2019
# print(ans, l+i, l+j)
print(ans)
| 15 | 22 | 334 | 499 | a, b = list(map(int, input().split()))
ans = 10000
for i in range(a, b):
for j in range(i + 1, b + 1):
if i >= 2019:
i = i % 2019
if j >= 2019:
j = j % 2019
if i == 0 or j == 0:
print("0")
exit()
else:
if ans > i * j % 2019:
ans = i * j % 2019
print(ans)
| l, r = list(map(int, input().split()))
n = r - l + 1
ans1 = 0
ans2 = 0
min1 = 1000000000
min2 = 10000000000
for i in range(min(n, 2024)):
# print(l+i)
if (l + i) % 2019 == 0:
print((0))
break
else:
ans = 10000000000
for i in range(min(n, 2019)):
for j in range(i + 1, min(n, 2020)):
# print(l+i, l+j)
if ((l + i) * (l + j)) % 2019 < ans:
ans = ((l + i) * (l + j)) % 2019
# print(ans, l+i, l+j)
print(ans)
| false | 31.818182 | [
"-a, b = list(map(int, input().split()))",
"-ans = 10000",
"-for i in range(a, b):",
"- for j in range(i + 1, b + 1):",
"- if i >= 2019:",
"- i = i % 2019",
"- if j >= 2019:",
"- j = j % 2019",
"- if i == 0 or j == 0:",
"- print(\"0\")",
"- exit()",
"- else:",
"- if ans > i * j % 2019:",
"- ans = i * j % 2019",
"-print(ans)",
"+l, r = list(map(int, input().split()))",
"+n = r - l + 1",
"+ans1 = 0",
"+ans2 = 0",
"+min1 = 1000000000",
"+min2 = 10000000000",
"+for i in range(min(n, 2024)):",
"+ # print(l+i)",
"+ if (l + i) % 2019 == 0:",
"+ print((0))",
"+ break",
"+else:",
"+ ans = 10000000000",
"+ for i in range(min(n, 2019)):",
"+ for j in range(i + 1, min(n, 2020)):",
"+ # print(l+i, l+j)",
"+ if ((l + i) * (l + j)) % 2019 < ans:",
"+ ans = ((l + i) * (l + j)) % 2019",
"+ # print(ans, l+i, l+j)",
"+ print(ans)"
] | false | 0.042389 | 0.094869 | 0.446811 | [
"s770517156",
"s161315506"
] |
u156815136 | p02608 | python | s620714642 | s664781036 | 154 | 132 | 80,180 | 87,088 | Accepted | Accepted | 14.29 | #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(eval(input()))
ya = [0] * 100001
for x in range(1,101):
for y in range(1,101):
for z in range(1,101):
n = x**2 + y**2 + z**2 + x*y + y*z + z*x
ya[n] += 1
n = I()
for i in range(1,n+1):
print((ya[i]))
| #from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
return list(map(int,input().split()))
def I():
return int(eval(input()))
n = I()
ya = [0] * 1000001
for x in range(1,101):
for y in range(1,101):
for z in range(1,101):
l = x**2 + y**2 + z**2 + x*y + y*z + z*x
ya[l] += 1
for i in range(1,n+1):
print((ya[i]))
| 38 | 38 | 954 | 964 | # from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations, permutations, accumulate # (string,3) 3回
# from collections import deque
from collections import deque, defaultdict, Counter
import decimal
import re
# import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
# mod = 9982443453
def readInts():
return list(map(int, input().split()))
def I():
return int(eval(input()))
ya = [0] * 100001
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
n = x**2 + y**2 + z**2 + x * y + y * z + z * x
ya[n] += 1
n = I()
for i in range(1, n + 1):
print((ya[i]))
| # from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations, permutations, accumulate, product # (string,3) 3回
# from collections import deque
from collections import deque, defaultdict, Counter
import decimal
import re
# import bisect
#
# d = m - k[i] - k[j]
# if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも!!
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
# mod = 9982443453
def readInts():
return list(map(int, input().split()))
def I():
return int(eval(input()))
n = I()
ya = [0] * 1000001
for x in range(1, 101):
for y in range(1, 101):
for z in range(1, 101):
l = x**2 + y**2 + z**2 + x * y + y * z + z * x
ya[l] += 1
for i in range(1, n + 1):
print((ya[i]))
| false | 0 | [
"-from itertools import combinations, permutations, accumulate # (string,3) 3回",
"+from itertools import combinations, permutations, accumulate, product # (string,3) 3回",
"-ya = [0] * 100001",
"+n = I()",
"+ya = [0] * 1000001",
"- n = x**2 + y**2 + z**2 + x * y + y * z + z * x",
"- ya[n] += 1",
"-n = I()",
"+ l = x**2 + y**2 + z**2 + x * y + y * z + z * x",
"+ ya[l] += 1"
] | false | 1.355008 | 1.333252 | 1.016318 | [
"s620714642",
"s664781036"
] |
u136090046 | p03779 | python | s204577331 | s696211337 | 31 | 24 | 2,940 | 2,940 | Accepted | Accepted | 22.58 | num = int(eval(input()))
for i in range(45000):
res = i * (i + 1) / 2
if res >= num:
print(i)
break
| x = int(eval(input()))
for i in range(1, 10000000):
x -= i
if x <= 0:
break
print(i) | 7 | 7 | 125 | 101 | num = int(eval(input()))
for i in range(45000):
res = i * (i + 1) / 2
if res >= num:
print(i)
break
| x = int(eval(input()))
for i in range(1, 10000000):
x -= i
if x <= 0:
break
print(i)
| false | 0 | [
"-num = int(eval(input()))",
"-for i in range(45000):",
"- res = i * (i + 1) / 2",
"- if res >= num:",
"- print(i)",
"+x = int(eval(input()))",
"+for i in range(1, 10000000):",
"+ x -= i",
"+ if x <= 0:",
"+print(i)"
] | false | 0.048373 | 0.158938 | 0.304352 | [
"s204577331",
"s696211337"
] |
u729133443 | p02537 | python | s937386273 | s112268341 | 1,289 | 1,115 | 276,100 | 275,712 | Accepted | Accepted | 13.5 | d=[0]*6**8
n,k,*a=list(map(int,open(0).read().split()+d))
while n:n-=1;d[n]=max(d[j]for j in range(n,n+99)if abs(a[n]-a[j])<=k)+1
print((max(d))) | d=[0]*6**8
n,k,*a=list(map(int,open(0).read().split()+d))
while n:n-=1;d[n]=max(d[j]for j in range(n,n+99)if-k<=a[n]-a[j]<=k)+1
print((max(d))) | 4 | 4 | 140 | 138 | d = [0] * 6**8
n, k, *a = list(map(int, open(0).read().split() + d))
while n:
n -= 1
d[n] = max(d[j] for j in range(n, n + 99) if abs(a[n] - a[j]) <= k) + 1
print((max(d)))
| d = [0] * 6**8
n, k, *a = list(map(int, open(0).read().split() + d))
while n:
n -= 1
d[n] = max(d[j] for j in range(n, n + 99) if -k <= a[n] - a[j] <= k) + 1
print((max(d)))
| false | 0 | [
"- d[n] = max(d[j] for j in range(n, n + 99) if abs(a[n] - a[j]) <= k) + 1",
"+ d[n] = max(d[j] for j in range(n, n + 99) if -k <= a[n] - a[j] <= k) + 1"
] | false | 0.532409 | 0.582497 | 0.914011 | [
"s937386273",
"s112268341"
] |
u474212171 | p02572 | python | s717022005 | s118936979 | 267 | 172 | 49,832 | 31,664 | Accepted | Accepted | 35.58 | import numpy as np
MOD = 10 ** 9 + 7
n=int(eval(input())) #3
alst=list(map(int,input().split())) #[1,2,3]
# 累積和を求める
# 例
# [1,2,3,4,5,6]の時、累積和は、
# [0,0+1,0+1+2,0+1+2+3,0+1+2+3+4,0+1+2+3+4+5,0+1+2+3+4+5+6]
s=[0]
for i in range(len(alst)):
s.append(s[i]+alst[i])
sum=0
for i in range(len(alst)-1):
sum+=alst[i]*(s[len(s)-1]-s[i+1])
print((sum%MOD)) | MOD = 10 ** 9 + 7
# [1,2,3,4,5,6]の時、累積和は、
# [0,1,3,6,10,15,21]
cumsum=[0]
def my_cumsum(alst):
for i in range(len(alst)):
cumsum.append(cumsum[i]+alst[i])
return cumsum
n=int(eval(input())) #3
alst=list(map(int,input().split()))
# 原因はnp.cumsum関数にある事が判明
# s=np.cumsum(alst)
s=my_cumsum(alst)
sum=0
for i in range(len(alst)-1):
sum+=alst[i]*(s[len(s)-1]-s[i+1])
print((sum%MOD)) | 22 | 24 | 369 | 408 | import numpy as np
MOD = 10**9 + 7
n = int(eval(input())) # 3
alst = list(map(int, input().split())) # [1,2,3]
# 累積和を求める
# 例
# [1,2,3,4,5,6]の時、累積和は、
# [0,0+1,0+1+2,0+1+2+3,0+1+2+3+4,0+1+2+3+4+5,0+1+2+3+4+5+6]
s = [0]
for i in range(len(alst)):
s.append(s[i] + alst[i])
sum = 0
for i in range(len(alst) - 1):
sum += alst[i] * (s[len(s) - 1] - s[i + 1])
print((sum % MOD))
| MOD = 10**9 + 7
# [1,2,3,4,5,6]の時、累積和は、
# [0,1,3,6,10,15,21]
cumsum = [0]
def my_cumsum(alst):
for i in range(len(alst)):
cumsum.append(cumsum[i] + alst[i])
return cumsum
n = int(eval(input())) # 3
alst = list(map(int, input().split()))
# 原因はnp.cumsum関数にある事が判明
# s=np.cumsum(alst)
s = my_cumsum(alst)
sum = 0
for i in range(len(alst) - 1):
sum += alst[i] * (s[len(s) - 1] - s[i + 1])
print((sum % MOD))
| false | 8.333333 | [
"-import numpy as np",
"+MOD = 10**9 + 7",
"+# [1,2,3,4,5,6]の時、累積和は、",
"+# [0,1,3,6,10,15,21]",
"+cumsum = [0]",
"-MOD = 10**9 + 7",
"+",
"+def my_cumsum(alst):",
"+ for i in range(len(alst)):",
"+ cumsum.append(cumsum[i] + alst[i])",
"+ return cumsum",
"+",
"+",
"-alst = list(map(int, input().split())) # [1,2,3]",
"-# 累積和を求める",
"-# 例",
"-# [1,2,3,4,5,6]の時、累積和は、",
"-# [0,0+1,0+1+2,0+1+2+3,0+1+2+3+4,0+1+2+3+4+5,0+1+2+3+4+5+6]",
"-s = [0]",
"-for i in range(len(alst)):",
"- s.append(s[i] + alst[i])",
"+alst = list(map(int, input().split()))",
"+# 原因はnp.cumsum関数にある事が判明",
"+# s=np.cumsum(alst)",
"+s = my_cumsum(alst)"
] | false | 0.097936 | 0.056555 | 1.731711 | [
"s717022005",
"s118936979"
] |
u227082700 | p03040 | python | s806037788 | s490860439 | 1,591 | 1,131 | 19,064 | 67,792 | Accepted | Accepted | 28.91 | from heapq import heappop,heappush
l,r=[],[]
ans=0
for _ in range(int(eval(input()))):
a=list(map(int,input().split()))
if a[0]==1:
_,ia,ib=a
heappush(l,-ia)
heappush(r,ia)
ll=heappop(l)
rr=heappop(r)
heappush(l,-rr)
heappush(r,-ll)
ans+=ib+abs(ll+rr)
else:print((-l[0],ans)) | from heapq import heappop,heappush
q=int(eval(input()))
queries=[list(map(int,input().split()))for _ in range(q)]
l=[]
r=[]
ans=0
queonecount=0
mid=-1
for query in queries:
if query[0]==1:
queonecount+=1
_,a,b=query
ans+=b
heappush(l,-a)
heappush(r,a)
midl=-heappop(l)
midr=heappop(r)
ans+=abs(midl-midr)
heappush(l,-midr)
heappush(r,midl)
if query[0]==2:
minind=-heappop(l)
print((minind,ans))
heappush(l,-minind) | 15 | 24 | 300 | 485 | from heapq import heappop, heappush
l, r = [], []
ans = 0
for _ in range(int(eval(input()))):
a = list(map(int, input().split()))
if a[0] == 1:
_, ia, ib = a
heappush(l, -ia)
heappush(r, ia)
ll = heappop(l)
rr = heappop(r)
heappush(l, -rr)
heappush(r, -ll)
ans += ib + abs(ll + rr)
else:
print((-l[0], ans))
| from heapq import heappop, heappush
q = int(eval(input()))
queries = [list(map(int, input().split())) for _ in range(q)]
l = []
r = []
ans = 0
queonecount = 0
mid = -1
for query in queries:
if query[0] == 1:
queonecount += 1
_, a, b = query
ans += b
heappush(l, -a)
heappush(r, a)
midl = -heappop(l)
midr = heappop(r)
ans += abs(midl - midr)
heappush(l, -midr)
heappush(r, midl)
if query[0] == 2:
minind = -heappop(l)
print((minind, ans))
heappush(l, -minind)
| false | 37.5 | [
"-l, r = [], []",
"+q = int(eval(input()))",
"+queries = [list(map(int, input().split())) for _ in range(q)]",
"+l = []",
"+r = []",
"-for _ in range(int(eval(input()))):",
"- a = list(map(int, input().split()))",
"- if a[0] == 1:",
"- _, ia, ib = a",
"- heappush(l, -ia)",
"- heappush(r, ia)",
"- ll = heappop(l)",
"- rr = heappop(r)",
"- heappush(l, -rr)",
"- heappush(r, -ll)",
"- ans += ib + abs(ll + rr)",
"- else:",
"- print((-l[0], ans))",
"+queonecount = 0",
"+mid = -1",
"+for query in queries:",
"+ if query[0] == 1:",
"+ queonecount += 1",
"+ _, a, b = query",
"+ ans += b",
"+ heappush(l, -a)",
"+ heappush(r, a)",
"+ midl = -heappop(l)",
"+ midr = heappop(r)",
"+ ans += abs(midl - midr)",
"+ heappush(l, -midr)",
"+ heappush(r, midl)",
"+ if query[0] == 2:",
"+ minind = -heappop(l)",
"+ print((minind, ans))",
"+ heappush(l, -minind)"
] | false | 0.037229 | 0.052005 | 0.715879 | [
"s806037788",
"s490860439"
] |
u217627525 | p02888 | python | s661308397 | s354791493 | 1,236 | 906 | 3,188 | 3,188 | Accepted | Accepted | 26.7 | from bisect import bisect_left
n=int(eval(input()))
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(n-2):
for j in range(i+1,n-1):
ans+=bisect_left(l,l[i]+l[j])-j-1
print(ans) | def main():
from bisect import bisect_left
n=int(eval(input()))
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(n-2):
for j in range(i+1,n-1):
ans+=bisect_left(l,l[i]+l[j])-j-1
print(ans)
if __name__=="__main__":
main() | 9 | 12 | 204 | 291 | from bisect import bisect_left
n = int(eval(input()))
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n - 2):
for j in range(i + 1, n - 1):
ans += bisect_left(l, l[i] + l[j]) - j - 1
print(ans)
| def main():
from bisect import bisect_left
n = int(eval(input()))
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n - 2):
for j in range(i + 1, n - 1):
ans += bisect_left(l, l[i] + l[j]) - j - 1
print(ans)
if __name__ == "__main__":
main()
| false | 25 | [
"-from bisect import bisect_left",
"+def main():",
"+ from bisect import bisect_left",
"-n = int(eval(input()))",
"-l = list(map(int, input().split()))",
"-l.sort()",
"-ans = 0",
"-for i in range(n - 2):",
"- for j in range(i + 1, n - 1):",
"- ans += bisect_left(l, l[i] + l[j]) - j - 1",
"-print(ans)",
"+ n = int(eval(input()))",
"+ l = list(map(int, input().split()))",
"+ l.sort()",
"+ ans = 0",
"+ for i in range(n - 2):",
"+ for j in range(i + 1, n - 1):",
"+ ans += bisect_left(l, l[i] + l[j]) - j - 1",
"+ print(ans)",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
] | false | 0.046146 | 0.040005 | 1.15352 | [
"s661308397",
"s354791493"
] |
u162893962 | p02700 | python | s721831736 | s552168583 | 24 | 21 | 9,116 | 9,112 | Accepted | Accepted | 12.5 | import math
a, b, c, d = list(map(int, input().split()))
taka = math.ceil(c/b)
ao = math.ceil(a/d)
if taka <= ao:
print('Yes')
else:
print('No')
| # while文を使うパターン(本番では書けず、あとで修正したもの)
a, b, c, d = list(map(int, input().split()))
turn = 0
while a >= 1 and c >= 1:
if turn % 2 == 0:
c -= b
else:
a -= d
turn += 1
# どちらかが0以下になった時点で止まるので最後のターンがどちらかを判別
if turn % 2 != 0:
print('Yes')
else:
print('No')
| 10 | 18 | 158 | 299 | import math
a, b, c, d = list(map(int, input().split()))
taka = math.ceil(c / b)
ao = math.ceil(a / d)
if taka <= ao:
print("Yes")
else:
print("No")
| # while文を使うパターン(本番では書けず、あとで修正したもの)
a, b, c, d = list(map(int, input().split()))
turn = 0
while a >= 1 and c >= 1:
if turn % 2 == 0:
c -= b
else:
a -= d
turn += 1
# どちらかが0以下になった時点で止まるので最後のターンがどちらかを判別
if turn % 2 != 0:
print("Yes")
else:
print("No")
| false | 44.444444 | [
"-import math",
"-",
"+# while文を使うパターン(本番では書けず、あとで修正したもの)",
"-taka = math.ceil(c / b)",
"-ao = math.ceil(a / d)",
"-if taka <= ao:",
"+turn = 0",
"+while a >= 1 and c >= 1:",
"+ if turn % 2 == 0:",
"+ c -= b",
"+ else:",
"+ a -= d",
"+ turn += 1",
"+# どちらかが0以下になった時点で止まるので最後のターンがどちらかを判別",
"+if turn % 2 != 0:"
] | false | 0.047685 | 0.047535 | 1.003163 | [
"s721831736",
"s552168583"
] |
u227020436 | p03274 | python | s996445528 | s576345182 | 74 | 60 | 14,388 | 15,020 | Accepted | Accepted | 18.92 | N, K = list(map(int, input().split()))
x = list(map(int, input().split()))
assert len(x) == N
m = min(x[i] - x[i-K+1] + min(abs(x[i]), abs(x[i-K+1])) for i in range(K-1, N))
print(m) | N, K = list(map(int, input().split()))
x = list(map(int, input().split()))
assert len(x) == N
m = min(b - a + min(abs(a), abs(b)) for a, b in zip(x, x[K-1:]))
print(m) | 6 | 6 | 184 | 169 | N, K = list(map(int, input().split()))
x = list(map(int, input().split()))
assert len(x) == N
m = min(
x[i] - x[i - K + 1] + min(abs(x[i]), abs(x[i - K + 1])) for i in range(K - 1, N)
)
print(m)
| N, K = list(map(int, input().split()))
x = list(map(int, input().split()))
assert len(x) == N
m = min(b - a + min(abs(a), abs(b)) for a, b in zip(x, x[K - 1 :]))
print(m)
| false | 0 | [
"-m = min(",
"- x[i] - x[i - K + 1] + min(abs(x[i]), abs(x[i - K + 1])) for i in range(K - 1, N)",
"-)",
"+m = min(b - a + min(abs(a), abs(b)) for a, b in zip(x, x[K - 1 :]))"
] | false | 0.042167 | 0.040921 | 1.03045 | [
"s996445528",
"s576345182"
] |
u102461423 | p03808 | python | s169710999 | s679140673 | 179 | 140 | 25,940 | 33,192 | Accepted | Accepted | 21.79 | import sys
input = sys.stdin.readline
import numpy as np
# Aへの加算は、imos法でまとめて行える。
# +[1,2,3,4,5]
# 階差:[-4,1,1,1,1]
# 総回数と最終的な階差から、回数分布がわかる
N = int(eval(input()))
A = np.array(input().split(), dtype=np.int64)
total_op = A.sum() // (N*(N+1)//2)
diff = np.empty_like(A)
diff[1:] = np.diff(A)
diff[0] = A[0] - A[-1]
# 操作の起点となる回数
op = (total_op - diff)//N
bl = True
bl &= (total_op * (N*(N+1)//2) == A.sum())
bl &= (N*op + diff == total_op).all()
bl &= (op >= 0).all()
answer = 'YES' if bl else 'NO'
print(answer) | import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = np.array(read().split(), np.int64)
def main(N, A):
k = N * (N + 1) // 2
t = A.sum() // k
if k * t != A.sum():
return False
B = np.empty_like(A)
B[1:] = A[1:] - A[:-1]
B[0] = A[0] - A[-1]
B -= t
if np.any(B % N != 0):
return False
B //= (-N)
return np.all(B >= 0)
print(('YES' if main(N, A) else 'NO')) | 29 | 25 | 537 | 542 | import sys
input = sys.stdin.readline
import numpy as np
# Aへの加算は、imos法でまとめて行える。
# +[1,2,3,4,5]
# 階差:[-4,1,1,1,1]
# 総回数と最終的な階差から、回数分布がわかる
N = int(eval(input()))
A = np.array(input().split(), dtype=np.int64)
total_op = A.sum() // (N * (N + 1) // 2)
diff = np.empty_like(A)
diff[1:] = np.diff(A)
diff[0] = A[0] - A[-1]
# 操作の起点となる回数
op = (total_op - diff) // N
bl = True
bl &= total_op * (N * (N + 1) // 2) == A.sum()
bl &= (N * op + diff == total_op).all()
bl &= (op >= 0).all()
answer = "YES" if bl else "NO"
print(answer)
| import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = np.array(read().split(), np.int64)
def main(N, A):
k = N * (N + 1) // 2
t = A.sum() // k
if k * t != A.sum():
return False
B = np.empty_like(A)
B[1:] = A[1:] - A[:-1]
B[0] = A[0] - A[-1]
B -= t
if np.any(B % N != 0):
return False
B //= -N
return np.all(B >= 0)
print(("YES" if main(N, A) else "NO"))
| false | 13.793103 | [
"-",
"-input = sys.stdin.readline",
"-# Aへの加算は、imos法でまとめて行える。",
"-# +[1,2,3,4,5]",
"-# 階差:[-4,1,1,1,1]",
"-# 総回数と最終的な階差から、回数分布がわかる",
"-N = int(eval(input()))",
"-A = np.array(input().split(), dtype=np.int64)",
"-total_op = A.sum() // (N * (N + 1) // 2)",
"-diff = np.empty_like(A)",
"-diff[1:] = np.diff(A)",
"-diff[0] = A[0] - A[-1]",
"-# 操作の起点となる回数",
"-op = (total_op - diff) // N",
"-bl = True",
"-bl &= total_op * (N * (N + 1) // 2) == A.sum()",
"-bl &= (N * op + diff == total_op).all()",
"-bl &= (op >= 0).all()",
"-answer = \"YES\" if bl else \"NO\"",
"-print(answer)",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"+N = int(readline())",
"+A = np.array(read().split(), np.int64)",
"+",
"+",
"+def main(N, A):",
"+ k = N * (N + 1) // 2",
"+ t = A.sum() // k",
"+ if k * t != A.sum():",
"+ return False",
"+ B = np.empty_like(A)",
"+ B[1:] = A[1:] - A[:-1]",
"+ B[0] = A[0] - A[-1]",
"+ B -= t",
"+ if np.any(B % N != 0):",
"+ return False",
"+ B //= -N",
"+ return np.all(B >= 0)",
"+",
"+",
"+print((\"YES\" if main(N, A) else \"NO\"))"
] | false | 0.278547 | 0.361383 | 0.77078 | [
"s169710999",
"s679140673"
] |
u873482706 | p00043 | python | s569962490 | s911071232 | 110 | 60 | 4,336 | 4,328 | Accepted | Accepted | 45.45 | import sys
def pokakito(num_line):
if not num_line and flag == 1:
result_lis.append(check_num)
return True
for num in num_line:
if three(num, num_line): return True
if two(num, num_line): return True
if straight(num, num_line): return True
def three(num, num_line):
count = 0
for check in num_line[:3]:
if check == num:
count += 1
else:
if count == 3:
if pokakito(num_line[3:]): return True
def two(num, num_line):
global flag
count = 0
for check in num_line[:2]:
if check == num:
count += 1
else:
if count == 2:
flag += 1
if pokakito(num_line[2:]): return True
flag -= 1
def straight(num, num_line):
num_lis = [num,num+1,num+2]
for i in range(3):
for check in num_lis:
if check < 0 or (not check in num_line):
for i in range(3):
num_lis[i] = num_lis[i]-1
break
else:
for n in num_lis:
index = 0
while num_line:
if num_line[index] == n:
del num_line[index]
break
index += 1
else:
if pokakito(num_line): return True
flag = 0
result_lis = []
check_num = 0
for input_line in sys.stdin:
for i in range(9):
check_num = i+1
input_line = input_line.rstrip()
line = sorted(input_line + str(check_num))
line = ''.join(line)
index = line.find(str(check_num))
if line[index:index+5] == str(check_num)*5:
continue
pokakito([int(char) for char in line])
result = sorted([str(num) for num in result_lis])
flag = 0
else:
if result_lis:
print(' '.join(result))
else:
print(0)
flag = 0
result_lis = []
check_num = 0 | import sys
def pokakito(num_line):
if not num_line and flag == 1:
result_lis.append(check_num)
return True
for num in num_line:
if three(num, num_line): return True
if two(num, num_line): return True
if straight(num, num_line): return True
def three(num, num_line):
count = 0
for check in num_line[:3]:
if check == num:
count += 1
else:
if count == 3:
if pokakito(num_line[3:]): return True
def two(num, num_line):
global flag
count = 0
for check in num_line[:2]:
if check == num:
count += 1
else:
if count == 2:
flag += 1
if pokakito(num_line[2:]): return True
flag -= 1
def straight(num, num_line):
for check in [num,num+1,num+2]:
if not check in num_line:
break
else:
for n in [num,num+1,num+2]:
index = 0
while num_line:
if num_line[index] == n:
del num_line[index]
break
index += 1
else:
if pokakito(num_line): return True
flag = 0
result_lis = []
check_num = 0
for input_line in sys.stdin:
for i in range(9):
check_num = i+1
input_line = input_line.rstrip()
line = sorted(input_line + str(check_num))
line = ''.join(line)
index = line.find(str(check_num))
if line[index:index+5] == str(check_num)*5:
continue
pokakito([int(char) for char in line])
result = sorted([str(num) for num in result_lis])
flag = 0
else:
if result_lis:
print(' '.join(result))
else:
print(0)
flag = 0
result_lis = []
check_num = 0 | 74 | 70 | 2,062 | 1,875 | import sys
def pokakito(num_line):
if not num_line and flag == 1:
result_lis.append(check_num)
return True
for num in num_line:
if three(num, num_line):
return True
if two(num, num_line):
return True
if straight(num, num_line):
return True
def three(num, num_line):
count = 0
for check in num_line[:3]:
if check == num:
count += 1
else:
if count == 3:
if pokakito(num_line[3:]):
return True
def two(num, num_line):
global flag
count = 0
for check in num_line[:2]:
if check == num:
count += 1
else:
if count == 2:
flag += 1
if pokakito(num_line[2:]):
return True
flag -= 1
def straight(num, num_line):
num_lis = [num, num + 1, num + 2]
for i in range(3):
for check in num_lis:
if check < 0 or (not check in num_line):
for i in range(3):
num_lis[i] = num_lis[i] - 1
break
else:
for n in num_lis:
index = 0
while num_line:
if num_line[index] == n:
del num_line[index]
break
index += 1
else:
if pokakito(num_line):
return True
flag = 0
result_lis = []
check_num = 0
for input_line in sys.stdin:
for i in range(9):
check_num = i + 1
input_line = input_line.rstrip()
line = sorted(input_line + str(check_num))
line = "".join(line)
index = line.find(str(check_num))
if line[index : index + 5] == str(check_num) * 5:
continue
pokakito([int(char) for char in line])
result = sorted([str(num) for num in result_lis])
flag = 0
else:
if result_lis:
print(" ".join(result))
else:
print(0)
flag = 0
result_lis = []
check_num = 0
| import sys
def pokakito(num_line):
if not num_line and flag == 1:
result_lis.append(check_num)
return True
for num in num_line:
if three(num, num_line):
return True
if two(num, num_line):
return True
if straight(num, num_line):
return True
def three(num, num_line):
count = 0
for check in num_line[:3]:
if check == num:
count += 1
else:
if count == 3:
if pokakito(num_line[3:]):
return True
def two(num, num_line):
global flag
count = 0
for check in num_line[:2]:
if check == num:
count += 1
else:
if count == 2:
flag += 1
if pokakito(num_line[2:]):
return True
flag -= 1
def straight(num, num_line):
for check in [num, num + 1, num + 2]:
if not check in num_line:
break
else:
for n in [num, num + 1, num + 2]:
index = 0
while num_line:
if num_line[index] == n:
del num_line[index]
break
index += 1
else:
if pokakito(num_line):
return True
flag = 0
result_lis = []
check_num = 0
for input_line in sys.stdin:
for i in range(9):
check_num = i + 1
input_line = input_line.rstrip()
line = sorted(input_line + str(check_num))
line = "".join(line)
index = line.find(str(check_num))
if line[index : index + 5] == str(check_num) * 5:
continue
pokakito([int(char) for char in line])
result = sorted([str(num) for num in result_lis])
flag = 0
else:
if result_lis:
print(" ".join(result))
else:
print(0)
flag = 0
result_lis = []
check_num = 0
| false | 5.405405 | [
"- num_lis = [num, num + 1, num + 2]",
"- for i in range(3):",
"- for check in num_lis:",
"- if check < 0 or (not check in num_line):",
"- for i in range(3):",
"- num_lis[i] = num_lis[i] - 1",
"- break",
"+ for check in [num, num + 1, num + 2]:",
"+ if not check in num_line:",
"+ break",
"+ else:",
"+ for n in [num, num + 1, num + 2]:",
"+ index = 0",
"+ while num_line:",
"+ if num_line[index] == n:",
"+ del num_line[index]",
"+ break",
"+ index += 1",
"- for n in num_lis:",
"- index = 0",
"- while num_line:",
"- if num_line[index] == n:",
"- del num_line[index]",
"- break",
"- index += 1",
"- else:",
"- if pokakito(num_line):",
"- return True",
"+ if pokakito(num_line):",
"+ return True"
] | false | 0.085177 | 0.007563 | 11.262654 | [
"s569962490",
"s911071232"
] |
u252828980 | p03329 | python | s376455109 | s152443916 | 600 | 495 | 3,828 | 12,700 | Accepted | Accepted | 17.5 |
n = int(eval(input()))
dp = [10**9]*(n+1)
L = [6**i for i in range(1,7)]
L += [9**i for i in range(1,6)]
dp[0] = 0
for i in range(1,n+1):
dp[i] = dp[i-1]+1
k = 6
while i-k >=0:
dp[i] = min(dp[i],dp[i-k]+1)
k *=6
k = 9
while i-k >=0:
dp[i] = min(dp[i],dp[i-k]+1)
k *=9
#print(dp)
print((dp[n]))
| n = int(eval(input()))
dp = [0]*(n+10)
for i in range(n+1):
dp[i+1] = dp[i] +1
for i in range(1,n+1):
k = 6
while k <=n:
if i-k>=0:
dp[i] = min(dp[i],dp[i-k]+1)
#print(dp[i-1],dp[i-k])
k *=6
#print(dp)
k = 9
while k <=n:
if i-k>=0:
dp[i] = min(dp[i],dp[i-k]+1)
k *=9
print((dp[n])) | 22 | 25 | 368 | 415 | n = int(eval(input()))
dp = [10**9] * (n + 1)
L = [6**i for i in range(1, 7)]
L += [9**i for i in range(1, 6)]
dp[0] = 0
for i in range(1, n + 1):
dp[i] = dp[i - 1] + 1
k = 6
while i - k >= 0:
dp[i] = min(dp[i], dp[i - k] + 1)
k *= 6
k = 9
while i - k >= 0:
dp[i] = min(dp[i], dp[i - k] + 1)
k *= 9
# print(dp)
print((dp[n]))
| n = int(eval(input()))
dp = [0] * (n + 10)
for i in range(n + 1):
dp[i + 1] = dp[i] + 1
for i in range(1, n + 1):
k = 6
while k <= n:
if i - k >= 0:
dp[i] = min(dp[i], dp[i - k] + 1)
# print(dp[i-1],dp[i-k])
k *= 6
# print(dp)
k = 9
while k <= n:
if i - k >= 0:
dp[i] = min(dp[i], dp[i - k] + 1)
k *= 9
print((dp[n]))
| false | 12 | [
"-dp = [10**9] * (n + 1)",
"-L = [6**i for i in range(1, 7)]",
"-L += [9**i for i in range(1, 6)]",
"-dp[0] = 0",
"+dp = [0] * (n + 10)",
"+for i in range(n + 1):",
"+ dp[i + 1] = dp[i] + 1",
"- dp[i] = dp[i - 1] + 1",
"- while i - k >= 0:",
"- dp[i] = min(dp[i], dp[i - k] + 1)",
"+ while k <= n:",
"+ if i - k >= 0:",
"+ dp[i] = min(dp[i], dp[i - k] + 1)",
"+ # print(dp[i-1],dp[i-k])",
"+ # print(dp)",
"- while i - k >= 0:",
"- dp[i] = min(dp[i], dp[i - k] + 1)",
"+ while k <= n:",
"+ if i - k >= 0:",
"+ dp[i] = min(dp[i], dp[i - k] + 1)",
"- # print(dp)"
] | false | 0.115312 | 0.151844 | 0.759412 | [
"s376455109",
"s152443916"
] |
u754022296 | p03819 | python | s336493654 | s951638556 | 1,919 | 1,762 | 128,336 | 127,784 | Accepted | Accepted | 8.18 | import sys
input = sys.stdin.readline
def main():
n, m = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(n)]
BIT = [0]*(m+2)
def add(i, a):
while i <= m+1:
BIT[i] += a
i += i&(-i)
def bit_sum(i):
res = 0
while i > 0:
res += BIT[i]
i -= i&(-i)
return res
for l, r in LR:
add(l, 1)
add(r+1, -1)
S = sorted([(r-l+1, l, r) for l, r in LR])
cnt = 0
L = []
for i in range(m, 0, -1):
while S and S[-1][0] == i:
c, l, r = S.pop()
cnt += 1
add(l, -1)
add(r+1, 1)
res = cnt
for j in range(0, m+1, i):
res += bit_sum(j)
L.append(res)
print(*L[::-1], sep="\n")
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
n, m = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(n)]
BIT = [0]*(m+2)
def add(i, a):
while i <= m+1:
BIT[i] += a
i += i&(-i)
def bit_sum(i):
res = 0
while i > 0:
res += BIT[i]
i -= i&(-i)
return res
S = sorted([(r-l+1, l, r) for l, r in LR], reverse=True)
cnt = n
L = []
for i in range(1, m+1):
while S and S[-1][0] == i:
c, l, r = S.pop()
cnt -= 1
add(l, 1)
add(r+1, -1)
res = cnt
for j in range(0, m+1, i):
res += bit_sum(j)
L.append(res)
print(*L, sep="\n")
if __name__ == "__main__":
main()
| 40 | 36 | 781 | 731 | import sys
input = sys.stdin.readline
def main():
n, m = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(n)]
BIT = [0] * (m + 2)
def add(i, a):
while i <= m + 1:
BIT[i] += a
i += i & (-i)
def bit_sum(i):
res = 0
while i > 0:
res += BIT[i]
i -= i & (-i)
return res
for l, r in LR:
add(l, 1)
add(r + 1, -1)
S = sorted([(r - l + 1, l, r) for l, r in LR])
cnt = 0
L = []
for i in range(m, 0, -1):
while S and S[-1][0] == i:
c, l, r = S.pop()
cnt += 1
add(l, -1)
add(r + 1, 1)
res = cnt
for j in range(0, m + 1, i):
res += bit_sum(j)
L.append(res)
print(*L[::-1], sep="\n")
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
n, m = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(n)]
BIT = [0] * (m + 2)
def add(i, a):
while i <= m + 1:
BIT[i] += a
i += i & (-i)
def bit_sum(i):
res = 0
while i > 0:
res += BIT[i]
i -= i & (-i)
return res
S = sorted([(r - l + 1, l, r) for l, r in LR], reverse=True)
cnt = n
L = []
for i in range(1, m + 1):
while S and S[-1][0] == i:
c, l, r = S.pop()
cnt -= 1
add(l, 1)
add(r + 1, -1)
res = cnt
for j in range(0, m + 1, i):
res += bit_sum(j)
L.append(res)
print(*L, sep="\n")
if __name__ == "__main__":
main()
| false | 10 | [
"- for l, r in LR:",
"- add(l, 1)",
"- add(r + 1, -1)",
"- S = sorted([(r - l + 1, l, r) for l, r in LR])",
"- cnt = 0",
"+ S = sorted([(r - l + 1, l, r) for l, r in LR], reverse=True)",
"+ cnt = n",
"- for i in range(m, 0, -1):",
"+ for i in range(1, m + 1):",
"- cnt += 1",
"- add(l, -1)",
"- add(r + 1, 1)",
"+ cnt -= 1",
"+ add(l, 1)",
"+ add(r + 1, -1)",
"- print(*L[::-1], sep=\"\\n\")",
"+ print(*L, sep=\"\\n\")"
] | false | 0.033706 | 0.041743 | 0.807469 | [
"s336493654",
"s951638556"
] |
u634079249 | p03400 | python | s981361441 | s435546996 | 36 | 31 | 9,740 | 9,744 | Accepted | Accepted | 13.89 | import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
MOD = 10 ** 9 + 7
INF = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
D, X = il()
ret = X
for n in range(N):
A = ii()
d, m = divmod(D, A)
if m == 0:
ret += D // A
else:
ret += D // A + 1
print(ret)
if __name__ == '__main__':
main()
| import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
MOD = 10 ** 9 + 7
INF = float('inf')
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
D, X = il()
ret = X
for n in range(N):
A = ii()
ret += (D - 1) // A + 1
print(ret)
if __name__ == '__main__':
main()
| 43 | 39 | 1,207 | 1,118 | import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
MOD = 10**9 + 7
INF = float("inf")
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
D, X = il()
ret = X
for n in range(N):
A = ii()
d, m = divmod(D, A)
if m == 0:
ret += D // A
else:
ret += D // A + 1
print(ret)
if __name__ == "__main__":
main()
| import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
MOD = 10**9 + 7
INF = float("inf")
def main():
if os.getenv("LOCAL"):
sys.stdin = open("input.txt", "r")
N = ii()
D, X = il()
ret = X
for n in range(N):
A = ii()
ret += (D - 1) // A + 1
print(ret)
if __name__ == "__main__":
main()
| false | 9.302326 | [
"- d, m = divmod(D, A)",
"- if m == 0:",
"- ret += D // A",
"- else:",
"- ret += D // A + 1",
"+ ret += (D - 1) // A + 1"
] | false | 0.038339 | 0.069123 | 0.554644 | [
"s981361441",
"s435546996"
] |
u922449550 | p02863 | python | s615489060 | s087773996 | 560 | 323 | 123,864 | 22,292 | Accepted | Accepted | 42.32 | N, T = list(map(int, input().split()))
AB = []
for i in range(N):
A, B = list(map(int, input().split()))
AB.append([A, B])
AB.sort()
dp = [[0 for t in range(T)] for i in range(N+1)]
ans = 0
for i, ab in enumerate(AB):
ans = max(ans, dp[i][T-1] + ab[1])
for t in range(T):
if t < ab[0]:
dp[i+1][t] = dp[i][t]
else:
dp[i+1][t] = max(dp[i][t-ab[0]] + ab[1], dp[i][t])
print(ans)
| import numpy as np
N, T = list(map(int, input().split()))
AB = []
for i in range(N):
A, B = list(map(int, input().split()))
AB.append([A, B])
AB.sort()
dp = np.zeros(T, dtype=int)
ans = 0
for a, b in AB:
ans = max(ans, dp[-1] + b)
dp[a:] = np.maximum(dp[a:], dp[:-a] + b)
print(ans) | 20 | 18 | 415 | 300 | N, T = list(map(int, input().split()))
AB = []
for i in range(N):
A, B = list(map(int, input().split()))
AB.append([A, B])
AB.sort()
dp = [[0 for t in range(T)] for i in range(N + 1)]
ans = 0
for i, ab in enumerate(AB):
ans = max(ans, dp[i][T - 1] + ab[1])
for t in range(T):
if t < ab[0]:
dp[i + 1][t] = dp[i][t]
else:
dp[i + 1][t] = max(dp[i][t - ab[0]] + ab[1], dp[i][t])
print(ans)
| import numpy as np
N, T = list(map(int, input().split()))
AB = []
for i in range(N):
A, B = list(map(int, input().split()))
AB.append([A, B])
AB.sort()
dp = np.zeros(T, dtype=int)
ans = 0
for a, b in AB:
ans = max(ans, dp[-1] + b)
dp[a:] = np.maximum(dp[a:], dp[:-a] + b)
print(ans)
| false | 10 | [
"+import numpy as np",
"+",
"-dp = [[0 for t in range(T)] for i in range(N + 1)]",
"+dp = np.zeros(T, dtype=int)",
"-for i, ab in enumerate(AB):",
"- ans = max(ans, dp[i][T - 1] + ab[1])",
"- for t in range(T):",
"- if t < ab[0]:",
"- dp[i + 1][t] = dp[i][t]",
"- else:",
"- dp[i + 1][t] = max(dp[i][t - ab[0]] + ab[1], dp[i][t])",
"+for a, b in AB:",
"+ ans = max(ans, dp[-1] + b)",
"+ dp[a:] = np.maximum(dp[a:], dp[:-a] + b)"
] | false | 0.061614 | 0.21986 | 0.280242 | [
"s615489060",
"s087773996"
] |
u883048396 | p03379 | python | s902011910 | s244971577 | 382 | 241 | 50,452 | 29,808 | Accepted | Accepted | 36.91 | iN = int(eval(input()))
aX = [int(_) for _ in input().split()]
aXs = sorted(enumerate(aX),key=lambda x:x[1])
iMu = iN//2
iMd = iN//2 -1
iMuV = aXs[iMu][1]
iMdV = aXs[iMd][1]
if iMuV == iMdV:
print(("\n".join([str(iMuV)]*iN)))
else:
print(("\n".join(map(str,[iMuV if aX[x] < iMuV else iMdV for x in range(iN)]))))
| iN = int(eval(input()))
aX = [int(_) for _ in input().split()]
aXs = sorted(aX)
iMu = iN//2
iMd = iN//2 -1
iMuV = aXs[iMu]
iMdV = aXs[iMd]
if iMuV == iMdV:
print(("\n".join([str(iMuV)]*iN)))
else:
print(("\n".join(map(str,[iMuV if x < iMuV else iMdV for x in aX]))))
| 15 | 14 | 336 | 288 | iN = int(eval(input()))
aX = [int(_) for _ in input().split()]
aXs = sorted(enumerate(aX), key=lambda x: x[1])
iMu = iN // 2
iMd = iN // 2 - 1
iMuV = aXs[iMu][1]
iMdV = aXs[iMd][1]
if iMuV == iMdV:
print(("\n".join([str(iMuV)] * iN)))
else:
print(("\n".join(map(str, [iMuV if aX[x] < iMuV else iMdV for x in range(iN)]))))
| iN = int(eval(input()))
aX = [int(_) for _ in input().split()]
aXs = sorted(aX)
iMu = iN // 2
iMd = iN // 2 - 1
iMuV = aXs[iMu]
iMdV = aXs[iMd]
if iMuV == iMdV:
print(("\n".join([str(iMuV)] * iN)))
else:
print(("\n".join(map(str, [iMuV if x < iMuV else iMdV for x in aX]))))
| false | 6.666667 | [
"-aXs = sorted(enumerate(aX), key=lambda x: x[1])",
"+aXs = sorted(aX)",
"-iMuV = aXs[iMu][1]",
"-iMdV = aXs[iMd][1]",
"+iMuV = aXs[iMu]",
"+iMdV = aXs[iMd]",
"- print((\"\\n\".join(map(str, [iMuV if aX[x] < iMuV else iMdV for x in range(iN)]))))",
"+ print((\"\\n\".join(map(str, [iMuV if x < iMuV else iMdV for x in aX]))))"
] | false | 0.064918 | 0.118453 | 0.548047 | [
"s902011910",
"s244971577"
] |
u219417113 | p03371 | python | s761030897 | s202926774 | 209 | 183 | 41,692 | 39,280 | Accepted | Accepted | 12.44 | A, B, C, X, Y = list(map(int, input().split()))
"""
ABピザの購入数(0~2 * max(X, Y)で全探索)
"""
min_price = 10 ** 10
for i in range(2 * max(X, Y) + 1):
c_price = C * i
a_price = A * max(0, (X - i//2))
b_price = B * max(0, (Y - i//2))
min_price = min(min_price, a_price+b_price+c_price)
print(min_price)
| a, b, c, x, y = list(map(int, input().split()))
ans = 10 ** 18
for i in range(0, 2 * max(x, y) + 1, 2):
tmp = i * c
if x - i // 2 > 0:
tmp += (x - i // 2) * a
if y - i // 2 > 0:
tmp += (y - i // 2) * b
ans = min(ans, tmp)
print(ans)
| 12 | 11 | 315 | 270 | A, B, C, X, Y = list(map(int, input().split()))
"""
ABピザの購入数(0~2 * max(X, Y)で全探索)
"""
min_price = 10**10
for i in range(2 * max(X, Y) + 1):
c_price = C * i
a_price = A * max(0, (X - i // 2))
b_price = B * max(0, (Y - i // 2))
min_price = min(min_price, a_price + b_price + c_price)
print(min_price)
| a, b, c, x, y = list(map(int, input().split()))
ans = 10**18
for i in range(0, 2 * max(x, y) + 1, 2):
tmp = i * c
if x - i // 2 > 0:
tmp += (x - i // 2) * a
if y - i // 2 > 0:
tmp += (y - i // 2) * b
ans = min(ans, tmp)
print(ans)
| false | 8.333333 | [
"-A, B, C, X, Y = list(map(int, input().split()))",
"-\"\"\"",
"-ABピザの購入数(0~2 * max(X, Y)で全探索)",
"-\"\"\"",
"-min_price = 10**10",
"-for i in range(2 * max(X, Y) + 1):",
"- c_price = C * i",
"- a_price = A * max(0, (X - i // 2))",
"- b_price = B * max(0, (Y - i // 2))",
"- min_price = min(min_price, a_price + b_price + c_price)",
"-print(min_price)",
"+a, b, c, x, y = list(map(int, input().split()))",
"+ans = 10**18",
"+for i in range(0, 2 * max(x, y) + 1, 2):",
"+ tmp = i * c",
"+ if x - i // 2 > 0:",
"+ tmp += (x - i // 2) * a",
"+ if y - i // 2 > 0:",
"+ tmp += (y - i // 2) * b",
"+ ans = min(ans, tmp)",
"+print(ans)"
] | false | 0.114389 | 0.063746 | 1.794455 | [
"s761030897",
"s202926774"
] |
u761320129 | p02807 | python | s536938576 | s786714888 | 233 | 199 | 19,972 | 19,984 | Accepted | Accepted | 14.59 | N = int(eval(input()))
X = list(map(int,input().split()))
MOD = 10**9+7
MAXN = N+5
fac = [1,1] + [0]*MAXN
finv = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
fac[i] = fac[i-1] * i % MOD
inv[i] = -inv[MOD%i] * (MOD // i) % MOD
finv[i] = finv[i-1] * inv[i] % MOD
c = 0
f = fac[N-1]
ans = 0
for i in range(1,N):
c += f * inv[i]
c %= MOD
ans += c * (X[i] - X[i-1])
ans %= MOD
print(ans)
| N = int(eval(input()))
X = list(map(int,input().split()))
Y = [b-a for a,b in zip(X,X[1:])]
MOD = 10**9+7
MAXN = N+5
fac = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
fac[i] = fac[i-1] * i % MOD
inv[i] = -inv[MOD%i] * (MOD // i) % MOD
ans = m = 0
for i,y in enumerate(Y):
m += fac[N-1] * inv[i+1]
ans += y*m
ans %= MOD
print(ans) | 22 | 18 | 449 | 384 | N = int(eval(input()))
X = list(map(int, input().split()))
MOD = 10**9 + 7
MAXN = N + 5
fac = [1, 1] + [0] * MAXN
finv = [1, 1] + [0] * MAXN
inv = [0, 1] + [0] * MAXN
for i in range(2, MAXN + 2):
fac[i] = fac[i - 1] * i % MOD
inv[i] = -inv[MOD % i] * (MOD // i) % MOD
finv[i] = finv[i - 1] * inv[i] % MOD
c = 0
f = fac[N - 1]
ans = 0
for i in range(1, N):
c += f * inv[i]
c %= MOD
ans += c * (X[i] - X[i - 1])
ans %= MOD
print(ans)
| N = int(eval(input()))
X = list(map(int, input().split()))
Y = [b - a for a, b in zip(X, X[1:])]
MOD = 10**9 + 7
MAXN = N + 5
fac = [1, 1] + [0] * MAXN
inv = [0, 1] + [0] * MAXN
for i in range(2, MAXN + 2):
fac[i] = fac[i - 1] * i % MOD
inv[i] = -inv[MOD % i] * (MOD // i) % MOD
ans = m = 0
for i, y in enumerate(Y):
m += fac[N - 1] * inv[i + 1]
ans += y * m
ans %= MOD
print(ans)
| false | 18.181818 | [
"+Y = [b - a for a, b in zip(X, X[1:])]",
"-finv = [1, 1] + [0] * MAXN",
"- finv[i] = finv[i - 1] * inv[i] % MOD",
"-c = 0",
"-f = fac[N - 1]",
"-ans = 0",
"-for i in range(1, N):",
"- c += f * inv[i]",
"- c %= MOD",
"- ans += c * (X[i] - X[i - 1])",
"+ans = m = 0",
"+for i, y in enumerate(Y):",
"+ m += fac[N - 1] * inv[i + 1]",
"+ ans += y * m"
] | false | 0.036796 | 0.035963 | 1.023155 | [
"s536938576",
"s786714888"
] |
u325282913 | p02555 | python | s986233419 | s978785390 | 346 | 300 | 9,216 | 9,292 | Accepted | Accepted | 13.29 | MOD = 10**9 + 7
def comb(n, k):
if n < k or n < 0 or k < 0:
return 0
if k == 0:
return 1
iinv = [1] * (k + 1)
ans = n
for i in range(2, k + 1):
iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
ans *= (n + 1 - i) * iinv[i] % MOD
ans %= MOD
return ans
S = int(eval(input()))
ans = 0
for i in range(1,S+1):
tmp = S
tmp -= i*3
if tmp < 0:
continue
ans += comb(i+tmp-1,tmp)
ans %= MOD
print(ans)
| MOD = 10**9 + 7
S = int(eval(input()))
dp = [0]*(S+4)
dp[0] = 1
dp[3] = 1
for i in range(4,S+1):
for k in range(i-2):
dp[i] += dp[k]
print((dp[S]%MOD)) | 23 | 9 | 499 | 163 | MOD = 10**9 + 7
def comb(n, k):
if n < k or n < 0 or k < 0:
return 0
if k == 0:
return 1
iinv = [1] * (k + 1)
ans = n
for i in range(2, k + 1):
iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
ans *= (n + 1 - i) * iinv[i] % MOD
ans %= MOD
return ans
S = int(eval(input()))
ans = 0
for i in range(1, S + 1):
tmp = S
tmp -= i * 3
if tmp < 0:
continue
ans += comb(i + tmp - 1, tmp)
ans %= MOD
print(ans)
| MOD = 10**9 + 7
S = int(eval(input()))
dp = [0] * (S + 4)
dp[0] = 1
dp[3] = 1
for i in range(4, S + 1):
for k in range(i - 2):
dp[i] += dp[k]
print((dp[S] % MOD))
| false | 60.869565 | [
"-",
"-",
"-def comb(n, k):",
"- if n < k or n < 0 or k < 0:",
"- return 0",
"- if k == 0:",
"- return 1",
"- iinv = [1] * (k + 1)",
"- ans = n",
"- for i in range(2, k + 1):",
"- iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD",
"- ans *= (n + 1 - i) * iinv[i] % MOD",
"- ans %= MOD",
"- return ans",
"-",
"-",
"-ans = 0",
"-for i in range(1, S + 1):",
"- tmp = S",
"- tmp -= i * 3",
"- if tmp < 0:",
"- continue",
"- ans += comb(i + tmp - 1, tmp)",
"- ans %= MOD",
"-print(ans)",
"+dp = [0] * (S + 4)",
"+dp[0] = 1",
"+dp[3] = 1",
"+for i in range(4, S + 1):",
"+ for k in range(i - 2):",
"+ dp[i] += dp[k]",
"+print((dp[S] % MOD))"
] | false | 0.09706 | 0.105572 | 0.919376 | [
"s986233419",
"s978785390"
] |
u513081876 | p03633 | python | s989920121 | s644831189 | 38 | 18 | 5,432 | 3,064 | Accepted | Accepted | 52.63 | import fractions
N = int(eval(input()))
T = [int(eval(input())) for i in range(N)]
ans = T[0]
for i in range(1, N):
ans = (ans * T[i]) // (fractions.gcd(ans, T[i]))
print(ans)
#https://mathtrain.jp/abequalgl | N = int(eval(input()))
T = sorted([int(eval(input())) for i in range(N)])
def gcd(a, b):
while b != 0:
a, b = b,a%b
return a
if N == 1:
print((T[0]))
else:
ans = T[0]
for i in range(1, N):
ans = (ans*T[i])//(gcd(ans, T[i]))
print(ans) | 10 | 16 | 214 | 282 | import fractions
N = int(eval(input()))
T = [int(eval(input())) for i in range(N)]
ans = T[0]
for i in range(1, N):
ans = (ans * T[i]) // (fractions.gcd(ans, T[i]))
print(ans)
# https://mathtrain.jp/abequalgl
| N = int(eval(input()))
T = sorted([int(eval(input())) for i in range(N)])
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
if N == 1:
print((T[0]))
else:
ans = T[0]
for i in range(1, N):
ans = (ans * T[i]) // (gcd(ans, T[i]))
print(ans)
| false | 37.5 | [
"-import fractions",
"+N = int(eval(input()))",
"+T = sorted([int(eval(input())) for i in range(N)])",
"-N = int(eval(input()))",
"-T = [int(eval(input())) for i in range(N)]",
"-ans = T[0]",
"-for i in range(1, N):",
"- ans = (ans * T[i]) // (fractions.gcd(ans, T[i]))",
"-print(ans)",
"-# https://mathtrain.jp/abequalgl",
"+",
"+def gcd(a, b):",
"+ while b != 0:",
"+ a, b = b, a % b",
"+ return a",
"+",
"+",
"+if N == 1:",
"+ print((T[0]))",
"+else:",
"+ ans = T[0]",
"+ for i in range(1, N):",
"+ ans = (ans * T[i]) // (gcd(ans, T[i]))",
"+ print(ans)"
] | false | 0.054723 | 0.04162 | 1.314822 | [
"s989920121",
"s644831189"
] |
u133886644 | p03401 | python | s336752129 | s216785293 | 289 | 247 | 13,540 | 13,540 | Accepted | Accepted | 14.53 | import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline
N, = list(map(int, input().split()))
L = [int(v) for v in input().split()]
# L = [int(input()) for _ in range(Q)]
# S = input().strip()
su = abs(L[0])
a = [0] * N
for i in range(1, N):
t = 0
if L[i - 1] * L[i] < 0:
t = abs(L[i - 1]) + abs(L[i])
else:
t = abs(L[i - 1] - L[i])
su += t
a[i] = t
su += abs(L[-1])
if L[0] * L[1] <= 0:
print((su - abs(L[0]) * 2))
else:
if L[0] < 0:
if L[0] > L[1]:
print(su)
else:
print((su - a[1] * 2))
else:
if L[0] < L[1]:
print(su)
else:
print((su - a[1] * 2))
for i in range(1, N - 1):
c = a[i] + a[i + 1]
t = 0
if L[i - 1] * L[i + 1] < 0:
t = abs(L[i - 1]) + abs(L[i + 1])
else:
t = abs(L[i - 1] - L[i + 1])
print((su - c + t))
if L[-2] * L[-1] <= 0:
print((su - abs(L[-1]) * 2))
else:
if L[-1] < 0:
if L[-1] > L[-2]:
print(su)
else:
print((su - a[-1] * 2))
else:
if L[-1] < L[-2]:
print(su)
else:
print((su - a[-1] * 2)) | import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline
N, = list(map(int, input().split()))
L = [int(v) for v in input().split()]
# L = [int(input()) for _ in range(Q)]
# S = input().strip()
L = [0] + L + [0]
su = 0
for i in range(N + 1):
su += abs(L[i] - L[i + 1])
for i in range(1, N + 1):
print((su + abs(L[i - 1] - L[i + 1]) - abs(L[i - 1] - L[i]) - abs(L[i] - L[i + 1]))) | 61 | 19 | 1,283 | 467 | import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline
(N,) = list(map(int, input().split()))
L = [int(v) for v in input().split()]
# L = [int(input()) for _ in range(Q)]
# S = input().strip()
su = abs(L[0])
a = [0] * N
for i in range(1, N):
t = 0
if L[i - 1] * L[i] < 0:
t = abs(L[i - 1]) + abs(L[i])
else:
t = abs(L[i - 1] - L[i])
su += t
a[i] = t
su += abs(L[-1])
if L[0] * L[1] <= 0:
print((su - abs(L[0]) * 2))
else:
if L[0] < 0:
if L[0] > L[1]:
print(su)
else:
print((su - a[1] * 2))
else:
if L[0] < L[1]:
print(su)
else:
print((su - a[1] * 2))
for i in range(1, N - 1):
c = a[i] + a[i + 1]
t = 0
if L[i - 1] * L[i + 1] < 0:
t = abs(L[i - 1]) + abs(L[i + 1])
else:
t = abs(L[i - 1] - L[i + 1])
print((su - c + t))
if L[-2] * L[-1] <= 0:
print((su - abs(L[-1]) * 2))
else:
if L[-1] < 0:
if L[-1] > L[-2]:
print(su)
else:
print((su - a[-1] * 2))
else:
if L[-1] < L[-2]:
print(su)
else:
print((su - a[-1] * 2))
| import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline
(N,) = list(map(int, input().split()))
L = [int(v) for v in input().split()]
# L = [int(input()) for _ in range(Q)]
# S = input().strip()
L = [0] + L + [0]
su = 0
for i in range(N + 1):
su += abs(L[i] - L[i + 1])
for i in range(1, N + 1):
print((su + abs(L[i - 1] - L[i + 1]) - abs(L[i - 1] - L[i]) - abs(L[i] - L[i + 1])))
| false | 68.852459 | [
"-su = abs(L[0])",
"-a = [0] * N",
"-for i in range(1, N):",
"- t = 0",
"- if L[i - 1] * L[i] < 0:",
"- t = abs(L[i - 1]) + abs(L[i])",
"- else:",
"- t = abs(L[i - 1] - L[i])",
"- su += t",
"- a[i] = t",
"-su += abs(L[-1])",
"-if L[0] * L[1] <= 0:",
"- print((su - abs(L[0]) * 2))",
"-else:",
"- if L[0] < 0:",
"- if L[0] > L[1]:",
"- print(su)",
"- else:",
"- print((su - a[1] * 2))",
"- else:",
"- if L[0] < L[1]:",
"- print(su)",
"- else:",
"- print((su - a[1] * 2))",
"-for i in range(1, N - 1):",
"- c = a[i] + a[i + 1]",
"- t = 0",
"- if L[i - 1] * L[i + 1] < 0:",
"- t = abs(L[i - 1]) + abs(L[i + 1])",
"- else:",
"- t = abs(L[i - 1] - L[i + 1])",
"- print((su - c + t))",
"-if L[-2] * L[-1] <= 0:",
"- print((su - abs(L[-1]) * 2))",
"-else:",
"- if L[-1] < 0:",
"- if L[-1] > L[-2]:",
"- print(su)",
"- else:",
"- print((su - a[-1] * 2))",
"- else:",
"- if L[-1] < L[-2]:",
"- print(su)",
"- else:",
"- print((su - a[-1] * 2))",
"+L = [0] + L + [0]",
"+su = 0",
"+for i in range(N + 1):",
"+ su += abs(L[i] - L[i + 1])",
"+for i in range(1, N + 1):",
"+ print((su + abs(L[i - 1] - L[i + 1]) - abs(L[i - 1] - L[i]) - abs(L[i] - L[i + 1])))"
] | false | 0.04117 | 0.039385 | 1.045329 | [
"s336752129",
"s216785293"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.