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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
u923668099 | p02343 | python | s623871998 | s811147112 | 500 | 380 | 14,132 | 10,400 | Accepted | Accepted | 24 | import sys
sys.setrecursionlimit(10**5)
def solve():
n, q = map(int, sys.stdin.readline().split())
uf = UnionFind(n)
ans = []
for lp in range(q):
c, x, y = map(int, sys.stdin.readline().split())
if c == 0:
uf.unite(x, y)
else:
ans.append(1 if uf.is_same(x, y) else 0)
print(*ans, sep='\n')
class UnionFind:
def __init__(self, n):
self.ds = [i for i in range(n)]
self.root = [i for i in range(n)]
# self.rank = [0] * n
def find_root(self, x):
if x != self.root[x]:
self.root[x] = self.find_root(self.root[x])
return self.root[x]
def is_same(self, x, y):
return self.find_root(x) == self.find_root(y)
def unite(self, x, y):
p = self.find_root(x)
q = self.find_root(y)
self.root[p] = q
def debug(x, table):
for name, val in table.items():
if x is val:
print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
return None
if __name__ == '__main__':
solve()
| import sys
def solve():
n, q = map(int, sys.stdin.readline().split())
uf = UnionFind(n)
ans = []
for lp in range(q):
c, x, y = map(int, sys.stdin.readline().split())
if c == 0:
uf.unite(x, y)
else:
ans.append(1 if uf.same(x, y) else 0)
print(*ans, sep='\n')
class UnionFind:
def __init__(self, n):
self.ds = [i for i in range(n)]
self.root = [i for i in range(n)]
self.rank = [0] * n
def find_root(self, x):
if self.root[x] == x:
return x
res = self.root[x]
while res != self.root[res]:
res = self.root[res]
return res
def same(self, x, y):
return self.find_root(x) == self.find_root(y)
def unite(self, x, y):
p = self.find_root(x)
q = self.find_root(y)
if p == q:
return None
if self.rank[p] < self.rank[q]:
self.root[p] = q
elif self.rank[q] < self.rank[p]:
self.root[q] = p
else:
self.root[q] = p
self.rank[p] += 1
def debug(x, table):
for name, val in table.items():
if x is val:
print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
return None
if __name__ == '__main__':
solve()
| 49 | 62 | 1,124 | 1,391 | import sys
sys.setrecursionlimit(10**5)
def solve():
n, q = map(int, sys.stdin.readline().split())
uf = UnionFind(n)
ans = []
for lp in range(q):
c, x, y = map(int, sys.stdin.readline().split())
if c == 0:
uf.unite(x, y)
else:
ans.append(1 if uf.is_same(x, y) else 0)
print(*ans, sep="\n")
class UnionFind:
def __init__(self, n):
self.ds = [i for i in range(n)]
self.root = [i for i in range(n)]
# self.rank = [0] * n
def find_root(self, x):
if x != self.root[x]:
self.root[x] = self.find_root(self.root[x])
return self.root[x]
def is_same(self, x, y):
return self.find_root(x) == self.find_root(y)
def unite(self, x, y):
p = self.find_root(x)
q = self.find_root(y)
self.root[p] = q
def debug(x, table):
for name, val in table.items():
if x is val:
print("DEBUG:{} -> {}".format(name, val), file=sys.stderr)
return None
if __name__ == "__main__":
solve()
| import sys
def solve():
n, q = map(int, sys.stdin.readline().split())
uf = UnionFind(n)
ans = []
for lp in range(q):
c, x, y = map(int, sys.stdin.readline().split())
if c == 0:
uf.unite(x, y)
else:
ans.append(1 if uf.same(x, y) else 0)
print(*ans, sep="\n")
class UnionFind:
def __init__(self, n):
self.ds = [i for i in range(n)]
self.root = [i for i in range(n)]
self.rank = [0] * n
def find_root(self, x):
if self.root[x] == x:
return x
res = self.root[x]
while res != self.root[res]:
res = self.root[res]
return res
def same(self, x, y):
return self.find_root(x) == self.find_root(y)
def unite(self, x, y):
p = self.find_root(x)
q = self.find_root(y)
if p == q:
return None
if self.rank[p] < self.rank[q]:
self.root[p] = q
elif self.rank[q] < self.rank[p]:
self.root[q] = p
else:
self.root[q] = p
self.rank[p] += 1
def debug(x, table):
for name, val in table.items():
if x is val:
print("DEBUG:{} -> {}".format(name, val), file=sys.stderr)
return None
if __name__ == "__main__":
solve()
| false | 20.967742 | [
"-",
"-sys.setrecursionlimit(10**5)",
"- ans.append(1 if uf.is_same(x, y) else 0)",
"+ ans.append(1 if uf.same(x, y) else 0)",
"- # self.rank = [0] * n",
"+ self.rank = [0] * n",
"- if x != self.root[x]:",
"- self.root[x] = self.find_root(self.root[x])",
"- return self.root[x]",
"+ if self.root[x] == x:",
"+ return x",
"+ res = self.root[x]",
"+ while res != self.root[res]:",
"+ res = self.root[res]",
"+ return res",
"- def is_same(self, x, y):",
"+ def same(self, x, y):",
"- self.root[p] = q",
"+ if p == q:",
"+ return None",
"+ if self.rank[p] < self.rank[q]:",
"+ self.root[p] = q",
"+ elif self.rank[q] < self.rank[p]:",
"+ self.root[q] = p",
"+ else:",
"+ self.root[q] = p",
"+ self.rank[p] += 1"
]
| false | 0.035939 | 0.042338 | 0.848861 | [
"s623871998",
"s811147112"
]
|
u037754315 | p02658 | python | s879068609 | s873324681 | 89 | 48 | 21,640 | 21,496 | Accepted | Accepted | 46.07 | N = int(eval(input()))
A = list(map(int, input().split()))
limit = 10 ** 18
A.sort()
result = A[0]
for a in A[1:]:
result *= a
if result > limit:
print((-1))
exit()
print(result) | N = int(eval(input()))
A = list(map(int,input().split()))
ans = 1
if 0 in A:
ans = 0
N = 0
for i in range(N):
ans *= A[i]
if ans > 10**18:
ans = -1
break
print(ans) | 12 | 15 | 206 | 191 | N = int(eval(input()))
A = list(map(int, input().split()))
limit = 10**18
A.sort()
result = A[0]
for a in A[1:]:
result *= a
if result > limit:
print((-1))
exit()
print(result)
| N = int(eval(input()))
A = list(map(int, input().split()))
ans = 1
if 0 in A:
ans = 0
N = 0
for i in range(N):
ans *= A[i]
if ans > 10**18:
ans = -1
break
print(ans)
| false | 20 | [
"-limit = 10**18",
"-A.sort()",
"-result = A[0]",
"-for a in A[1:]:",
"- result *= a",
"- if result > limit:",
"- print((-1))",
"- exit()",
"-print(result)",
"+ans = 1",
"+if 0 in A:",
"+ ans = 0",
"+ N = 0",
"+for i in range(N):",
"+ ans *= A[i]",
"+ if ans > 10**18:",
"+ ans = -1",
"+ break",
"+print(ans)"
]
| false | 0.03821 | 0.076687 | 0.498262 | [
"s879068609",
"s873324681"
]
|
u627600101 | p02579 | python | s022191123 | s102481261 | 673 | 317 | 99,548 | 94,696 | Accepted | Accepted | 52.9 | from collections import deque
H, W = list(map(int, input().split()))
Ch, Cw = list(map(int, input().split()))
Dh, Dw = list(map(int, input().split()))
Ch += 1
Cw += 1
Dh += 1
Dw += 1
lim = 10**6
S = ['#'*(W+4)]
S.append('#'*(W+4))
for k in range(H):
S.append('##' + eval(input()) + '##')
S.append('#'*(W+4))
S.append('#'*(W+4))
foo = [[-1 for _ in range(W+4)] for _ in range(H+4)]
for k in range(2, H+2):
for j in range(2, W+2):
if S[k][j] == '.':
foo[k][j] = lim
foo[Ch][Cw] = 0
now = deque([])
new = deque([(Ch, Cw)])
while len(new) > 0:
item = new.pop()
now.append(item)
x = item[0]
y = item[1]
if foo[x+1][y] == lim:
foo[x+1][y] = 0
new.append((x+1, y))
if foo[x][y+1] == lim:
foo[x][y+1] = 0
new.append((x, y+1))
if foo[x-1][y] == lim:
foo[x-1][y] = 0
new.append((x-1, y))
if foo[x][y-1] == lim:
foo[x][y-1] = 0
new.append((x, y-1))
ans = 0
while foo[Dh][Dw] == lim:
if len(now) == 0:
print((-1))
exit()
ans += 1
while len(now) > 0:
item = now.pop()
x = item[0]
y = item[1]
if foo[x+2][y+2] > ans:
foo[x+2][y+2] = ans
new.append((x+2, y+2))
if foo[x+2][y+1] > ans:
foo[x+2][y+1] = ans
new.append((x+2, y+1))
if foo[x+2][y] > ans:
foo[x+2][y] = ans
new.append((x+2, y))
if foo[x+2][y-1] > ans:
foo[x+2][y-1] = ans
new.append((x+2, y-1))
if foo[x+2][y-2] > ans:
foo[x+2][y-2] = ans
new.append((x+2, y-2))
if foo[x+1][y+2] > ans:
foo[x+1][y+2] = ans
new.append((x+1, y+2))
if foo[x+1][y-2] > ans:
foo[x+1][y-2] = ans
new.append((x+1, y-2))
if foo[x][y+2] > ans:
foo[x][y+2] = ans
new.append((x, y+2))
if foo[x][y-2] > ans:
foo[x][y-2] = ans
new.append((x, y-2))
if foo[x-2][y+2] > ans:
foo[x-2][y+2] = ans
new.append((x-2, y+2))
if foo[x-2][y+1] > ans:
foo[x-2][y+1] = ans
new.append((x-2, y+1))
if foo[x-2][y] > ans:
foo[x-2][y] = ans
new.append((x-2, y))
if foo[x-2][y-1] > ans:
foo[x-2][y-1] = ans
new.append((x-2, y-1))
if foo[x-2][y-2] > ans:
foo[x-2][y-2] = ans
new.append((x-2, y-2))
if foo[x-1][y+2] > ans:
foo[x-1][y+2] = ans
new.append((x-1, y+2))
if foo[x-1][y-2] > ans:
foo[x-1][y-2] = ans
new.append((x-1, y-2))
if foo[x-1][y-1] > ans:
foo[x-1][y-1] = ans
new.append((x-1, y-1))
if foo[x-1][y+1] > ans:
foo[x-1][y+1] = ans
new.append((x-1, y+1))
if foo[x+1][y+1] > ans:
foo[x+1][y+1] = ans
new.append((x+1, y+1))
if foo[x+1][y-1] > ans:
foo[x+1][y-1] = ans
new.append((x+1, y-1))
while len(new) > 0:
item = new.pop()
now.append(item)
x = item[0]
y = item[1]
if foo[x+1][y] == lim:
foo[x+1][y] = 0
new.append((x+1, y))
if foo[x][y+1] == lim:
foo[x][y+1] = 0
new.append((x, y+1))
if foo[x-1][y] == lim:
foo[x-1][y] = 0
new.append((x-1, y))
if foo[x][y-1] == lim:
foo[x][y-1] = 0
new.append((x, y-1))
print(ans) | from collections import deque
H, W = list(map(int, input().split()))
Ch, Cw = list(map(int, input().split()))
Dh, Dw = list(map(int, input().split()))
Ch += 1
Cw += 1
Dh += 1
Dw += 1
lim = 10**6
S = ['#'*(W+4)]
S.append('#'*(W+4))
for k in range(H):
S.append('##' + eval(input()) + '##')
S.append('#'*(W+4))
S.append('#'*(W+4))
foo = [[-1 for _ in range(W+4)] for _ in range(H+4)]
rev = [[-1 for _ in range(W+4)] for _ in range(H+4)]
for k in range(2, H+2):
for j in range(2, W+2):
if S[k][j] == '.':
foo[k][j] = lim
rev[k][j] = lim
foo[Ch][Cw] = 0
rev[Dh][Dw] = 0
jump = [(2,2),(2,1),(2,0),(2,-1),(2,-2),(1,2),(1,1),(1,-1),(1,-2),(0,2),(0,-2),(-1,2),(-1,1),(-1,-1),(-1,-2),(-2,2),(-2,1),(-2,0),(-2,-1),(-2,-2)]
mv = [(1,0),(-1,0),(0,1),(0,-1)]
now = deque([])
new = deque([(Ch, Cw)])
while len(new) > 0:
item = new.pop()
now.append(item)
x = item[0]
y = item[1]
for m in mv:
mx = x + m[0]
my = y + m[1]
if rev[mx][my] == 0:
print((0))
exit()
else:
if foo[mx][my] == lim:
foo[mx][my] = 0
new.append((mx, my))
now_rev = deque([])
new_rev = deque([(Dh,Dw)])
while len(new_rev) > 0:
item = new_rev.pop()
now_rev.append(item)
x = item[0]
y = item[1]
for m in mv:
mx = x + m[0]
my = y + m[1]
if rev[mx][my] == lim:
rev[mx][my] = 0
new_rev.append((mx, my))
start = 0
while True:
if len(now) == 0:
print((-1))
exit()
start += 1
while len(now) > 0:
item = now.pop()
x = item[0]
y = item[1]
for j in jump:
jx = x + j[0]
jy = y + j[1]
if 0 <= rev[jx][jy] < lim:
print((foo[x][y]+rev[jx][jy]+1))
exit()
else:
if foo[jx][jy] > start:
foo[jx][jy] = start
new.append((jx,jy))
while len(new) > 0:
item = new.pop()
now.append(item)
x = item[0]
y = item[1]
for m in mv:
mx = x + m[0]
my = y + m[1]
if 0 <= rev[mx][my] < lim:
print((foo[x][y] + rev[mx][my]))
exit()
else:
if foo[mx][my] == lim:
foo[mx][my] = start
new.append((mx, my))
if len(now_rev) == 0:
print((-1))
exit()
while len(now_rev) > 0:
item = now_rev.pop()
x = item[0]
y = item[1]
for j in jump:
jx = x + j[0]
jy = y + j[1]
if 0 <= foo[jx][jy] < lim:
print((rev[x][y]+foo[jx][jy]+1))
exit()
else:
if rev[jx][jy] > start:
rev[jx][jy] = start
new_rev.append((jx,jy))
while len(new_rev) > 0:
item = new_rev.pop()
now_rev.append(item)
x = item[0]
y = item[1]
for m in mv:
mx = x + m[0]
my = y + m[1]
if 0 <= foo[mx][my] < lim:
print((rev[x][y] + foo[mx][my]))
exit()
else:
if rev[mx][my] == lim:
rev[mx][my] = start
new_rev.append((mx, my))
| 138 | 136 | 3,245 | 2,987 | from collections import deque
H, W = list(map(int, input().split()))
Ch, Cw = list(map(int, input().split()))
Dh, Dw = list(map(int, input().split()))
Ch += 1
Cw += 1
Dh += 1
Dw += 1
lim = 10**6
S = ["#" * (W + 4)]
S.append("#" * (W + 4))
for k in range(H):
S.append("##" + eval(input()) + "##")
S.append("#" * (W + 4))
S.append("#" * (W + 4))
foo = [[-1 for _ in range(W + 4)] for _ in range(H + 4)]
for k in range(2, H + 2):
for j in range(2, W + 2):
if S[k][j] == ".":
foo[k][j] = lim
foo[Ch][Cw] = 0
now = deque([])
new = deque([(Ch, Cw)])
while len(new) > 0:
item = new.pop()
now.append(item)
x = item[0]
y = item[1]
if foo[x + 1][y] == lim:
foo[x + 1][y] = 0
new.append((x + 1, y))
if foo[x][y + 1] == lim:
foo[x][y + 1] = 0
new.append((x, y + 1))
if foo[x - 1][y] == lim:
foo[x - 1][y] = 0
new.append((x - 1, y))
if foo[x][y - 1] == lim:
foo[x][y - 1] = 0
new.append((x, y - 1))
ans = 0
while foo[Dh][Dw] == lim:
if len(now) == 0:
print((-1))
exit()
ans += 1
while len(now) > 0:
item = now.pop()
x = item[0]
y = item[1]
if foo[x + 2][y + 2] > ans:
foo[x + 2][y + 2] = ans
new.append((x + 2, y + 2))
if foo[x + 2][y + 1] > ans:
foo[x + 2][y + 1] = ans
new.append((x + 2, y + 1))
if foo[x + 2][y] > ans:
foo[x + 2][y] = ans
new.append((x + 2, y))
if foo[x + 2][y - 1] > ans:
foo[x + 2][y - 1] = ans
new.append((x + 2, y - 1))
if foo[x + 2][y - 2] > ans:
foo[x + 2][y - 2] = ans
new.append((x + 2, y - 2))
if foo[x + 1][y + 2] > ans:
foo[x + 1][y + 2] = ans
new.append((x + 1, y + 2))
if foo[x + 1][y - 2] > ans:
foo[x + 1][y - 2] = ans
new.append((x + 1, y - 2))
if foo[x][y + 2] > ans:
foo[x][y + 2] = ans
new.append((x, y + 2))
if foo[x][y - 2] > ans:
foo[x][y - 2] = ans
new.append((x, y - 2))
if foo[x - 2][y + 2] > ans:
foo[x - 2][y + 2] = ans
new.append((x - 2, y + 2))
if foo[x - 2][y + 1] > ans:
foo[x - 2][y + 1] = ans
new.append((x - 2, y + 1))
if foo[x - 2][y] > ans:
foo[x - 2][y] = ans
new.append((x - 2, y))
if foo[x - 2][y - 1] > ans:
foo[x - 2][y - 1] = ans
new.append((x - 2, y - 1))
if foo[x - 2][y - 2] > ans:
foo[x - 2][y - 2] = ans
new.append((x - 2, y - 2))
if foo[x - 1][y + 2] > ans:
foo[x - 1][y + 2] = ans
new.append((x - 1, y + 2))
if foo[x - 1][y - 2] > ans:
foo[x - 1][y - 2] = ans
new.append((x - 1, y - 2))
if foo[x - 1][y - 1] > ans:
foo[x - 1][y - 1] = ans
new.append((x - 1, y - 1))
if foo[x - 1][y + 1] > ans:
foo[x - 1][y + 1] = ans
new.append((x - 1, y + 1))
if foo[x + 1][y + 1] > ans:
foo[x + 1][y + 1] = ans
new.append((x + 1, y + 1))
if foo[x + 1][y - 1] > ans:
foo[x + 1][y - 1] = ans
new.append((x + 1, y - 1))
while len(new) > 0:
item = new.pop()
now.append(item)
x = item[0]
y = item[1]
if foo[x + 1][y] == lim:
foo[x + 1][y] = 0
new.append((x + 1, y))
if foo[x][y + 1] == lim:
foo[x][y + 1] = 0
new.append((x, y + 1))
if foo[x - 1][y] == lim:
foo[x - 1][y] = 0
new.append((x - 1, y))
if foo[x][y - 1] == lim:
foo[x][y - 1] = 0
new.append((x, y - 1))
print(ans)
| from collections import deque
H, W = list(map(int, input().split()))
Ch, Cw = list(map(int, input().split()))
Dh, Dw = list(map(int, input().split()))
Ch += 1
Cw += 1
Dh += 1
Dw += 1
lim = 10**6
S = ["#" * (W + 4)]
S.append("#" * (W + 4))
for k in range(H):
S.append("##" + eval(input()) + "##")
S.append("#" * (W + 4))
S.append("#" * (W + 4))
foo = [[-1 for _ in range(W + 4)] for _ in range(H + 4)]
rev = [[-1 for _ in range(W + 4)] for _ in range(H + 4)]
for k in range(2, H + 2):
for j in range(2, W + 2):
if S[k][j] == ".":
foo[k][j] = lim
rev[k][j] = lim
foo[Ch][Cw] = 0
rev[Dh][Dw] = 0
jump = [
(2, 2),
(2, 1),
(2, 0),
(2, -1),
(2, -2),
(1, 2),
(1, 1),
(1, -1),
(1, -2),
(0, 2),
(0, -2),
(-1, 2),
(-1, 1),
(-1, -1),
(-1, -2),
(-2, 2),
(-2, 1),
(-2, 0),
(-2, -1),
(-2, -2),
]
mv = [(1, 0), (-1, 0), (0, 1), (0, -1)]
now = deque([])
new = deque([(Ch, Cw)])
while len(new) > 0:
item = new.pop()
now.append(item)
x = item[0]
y = item[1]
for m in mv:
mx = x + m[0]
my = y + m[1]
if rev[mx][my] == 0:
print((0))
exit()
else:
if foo[mx][my] == lim:
foo[mx][my] = 0
new.append((mx, my))
now_rev = deque([])
new_rev = deque([(Dh, Dw)])
while len(new_rev) > 0:
item = new_rev.pop()
now_rev.append(item)
x = item[0]
y = item[1]
for m in mv:
mx = x + m[0]
my = y + m[1]
if rev[mx][my] == lim:
rev[mx][my] = 0
new_rev.append((mx, my))
start = 0
while True:
if len(now) == 0:
print((-1))
exit()
start += 1
while len(now) > 0:
item = now.pop()
x = item[0]
y = item[1]
for j in jump:
jx = x + j[0]
jy = y + j[1]
if 0 <= rev[jx][jy] < lim:
print((foo[x][y] + rev[jx][jy] + 1))
exit()
else:
if foo[jx][jy] > start:
foo[jx][jy] = start
new.append((jx, jy))
while len(new) > 0:
item = new.pop()
now.append(item)
x = item[0]
y = item[1]
for m in mv:
mx = x + m[0]
my = y + m[1]
if 0 <= rev[mx][my] < lim:
print((foo[x][y] + rev[mx][my]))
exit()
else:
if foo[mx][my] == lim:
foo[mx][my] = start
new.append((mx, my))
if len(now_rev) == 0:
print((-1))
exit()
while len(now_rev) > 0:
item = now_rev.pop()
x = item[0]
y = item[1]
for j in jump:
jx = x + j[0]
jy = y + j[1]
if 0 <= foo[jx][jy] < lim:
print((rev[x][y] + foo[jx][jy] + 1))
exit()
else:
if rev[jx][jy] > start:
rev[jx][jy] = start
new_rev.append((jx, jy))
while len(new_rev) > 0:
item = new_rev.pop()
now_rev.append(item)
x = item[0]
y = item[1]
for m in mv:
mx = x + m[0]
my = y + m[1]
if 0 <= foo[mx][my] < lim:
print((rev[x][y] + foo[mx][my]))
exit()
else:
if rev[mx][my] == lim:
rev[mx][my] = start
new_rev.append((mx, my))
| false | 1.449275 | [
"+rev = [[-1 for _ in range(W + 4)] for _ in range(H + 4)]",
"+ rev[k][j] = lim",
"+rev[Dh][Dw] = 0",
"+jump = [",
"+ (2, 2),",
"+ (2, 1),",
"+ (2, 0),",
"+ (2, -1),",
"+ (2, -2),",
"+ (1, 2),",
"+ (1, 1),",
"+ (1, -1),",
"+ (1, -2),",
"+ (0, 2),",
"+ (0, -2),",
"+ (-1, 2),",
"+ (-1, 1),",
"+ (-1, -1),",
"+ (-1, -2),",
"+ (-2, 2),",
"+ (-2, 1),",
"+ (-2, 0),",
"+ (-2, -1),",
"+ (-2, -2),",
"+]",
"+mv = [(1, 0), (-1, 0), (0, 1), (0, -1)]",
"- if foo[x + 1][y] == lim:",
"- foo[x + 1][y] = 0",
"- new.append((x + 1, y))",
"- if foo[x][y + 1] == lim:",
"- foo[x][y + 1] = 0",
"- new.append((x, y + 1))",
"- if foo[x - 1][y] == lim:",
"- foo[x - 1][y] = 0",
"- new.append((x - 1, y))",
"- if foo[x][y - 1] == lim:",
"- foo[x][y - 1] = 0",
"- new.append((x, y - 1))",
"-ans = 0",
"-while foo[Dh][Dw] == lim:",
"+ for m in mv:",
"+ mx = x + m[0]",
"+ my = y + m[1]",
"+ if rev[mx][my] == 0:",
"+ print((0))",
"+ exit()",
"+ else:",
"+ if foo[mx][my] == lim:",
"+ foo[mx][my] = 0",
"+ new.append((mx, my))",
"+now_rev = deque([])",
"+new_rev = deque([(Dh, Dw)])",
"+while len(new_rev) > 0:",
"+ item = new_rev.pop()",
"+ now_rev.append(item)",
"+ x = item[0]",
"+ y = item[1]",
"+ for m in mv:",
"+ mx = x + m[0]",
"+ my = y + m[1]",
"+ if rev[mx][my] == lim:",
"+ rev[mx][my] = 0",
"+ new_rev.append((mx, my))",
"+start = 0",
"+while True:",
"- ans += 1",
"+ start += 1",
"- if foo[x + 2][y + 2] > ans:",
"- foo[x + 2][y + 2] = ans",
"- new.append((x + 2, y + 2))",
"- if foo[x + 2][y + 1] > ans:",
"- foo[x + 2][y + 1] = ans",
"- new.append((x + 2, y + 1))",
"- if foo[x + 2][y] > ans:",
"- foo[x + 2][y] = ans",
"- new.append((x + 2, y))",
"- if foo[x + 2][y - 1] > ans:",
"- foo[x + 2][y - 1] = ans",
"- new.append((x + 2, y - 1))",
"- if foo[x + 2][y - 2] > ans:",
"- foo[x + 2][y - 2] = ans",
"- new.append((x + 2, y - 2))",
"- if foo[x + 1][y + 2] > ans:",
"- foo[x + 1][y + 2] = ans",
"- new.append((x + 1, y + 2))",
"- if foo[x + 1][y - 2] > ans:",
"- foo[x + 1][y - 2] = ans",
"- new.append((x + 1, y - 2))",
"- if foo[x][y + 2] > ans:",
"- foo[x][y + 2] = ans",
"- new.append((x, y + 2))",
"- if foo[x][y - 2] > ans:",
"- foo[x][y - 2] = ans",
"- new.append((x, y - 2))",
"- if foo[x - 2][y + 2] > ans:",
"- foo[x - 2][y + 2] = ans",
"- new.append((x - 2, y + 2))",
"- if foo[x - 2][y + 1] > ans:",
"- foo[x - 2][y + 1] = ans",
"- new.append((x - 2, y + 1))",
"- if foo[x - 2][y] > ans:",
"- foo[x - 2][y] = ans",
"- new.append((x - 2, y))",
"- if foo[x - 2][y - 1] > ans:",
"- foo[x - 2][y - 1] = ans",
"- new.append((x - 2, y - 1))",
"- if foo[x - 2][y - 2] > ans:",
"- foo[x - 2][y - 2] = ans",
"- new.append((x - 2, y - 2))",
"- if foo[x - 1][y + 2] > ans:",
"- foo[x - 1][y + 2] = ans",
"- new.append((x - 1, y + 2))",
"- if foo[x - 1][y - 2] > ans:",
"- foo[x - 1][y - 2] = ans",
"- new.append((x - 1, y - 2))",
"- if foo[x - 1][y - 1] > ans:",
"- foo[x - 1][y - 1] = ans",
"- new.append((x - 1, y - 1))",
"- if foo[x - 1][y + 1] > ans:",
"- foo[x - 1][y + 1] = ans",
"- new.append((x - 1, y + 1))",
"- if foo[x + 1][y + 1] > ans:",
"- foo[x + 1][y + 1] = ans",
"- new.append((x + 1, y + 1))",
"- if foo[x + 1][y - 1] > ans:",
"- foo[x + 1][y - 1] = ans",
"- new.append((x + 1, y - 1))",
"+ for j in jump:",
"+ jx = x + j[0]",
"+ jy = y + j[1]",
"+ if 0 <= rev[jx][jy] < lim:",
"+ print((foo[x][y] + rev[jx][jy] + 1))",
"+ exit()",
"+ else:",
"+ if foo[jx][jy] > start:",
"+ foo[jx][jy] = start",
"+ new.append((jx, jy))",
"- if foo[x + 1][y] == lim:",
"- foo[x + 1][y] = 0",
"- new.append((x + 1, y))",
"- if foo[x][y + 1] == lim:",
"- foo[x][y + 1] = 0",
"- new.append((x, y + 1))",
"- if foo[x - 1][y] == lim:",
"- foo[x - 1][y] = 0",
"- new.append((x - 1, y))",
"- if foo[x][y - 1] == lim:",
"- foo[x][y - 1] = 0",
"- new.append((x, y - 1))",
"-print(ans)",
"+ for m in mv:",
"+ mx = x + m[0]",
"+ my = y + m[1]",
"+ if 0 <= rev[mx][my] < lim:",
"+ print((foo[x][y] + rev[mx][my]))",
"+ exit()",
"+ else:",
"+ if foo[mx][my] == lim:",
"+ foo[mx][my] = start",
"+ new.append((mx, my))",
"+ if len(now_rev) == 0:",
"+ print((-1))",
"+ exit()",
"+ while len(now_rev) > 0:",
"+ item = now_rev.pop()",
"+ x = item[0]",
"+ y = item[1]",
"+ for j in jump:",
"+ jx = x + j[0]",
"+ jy = y + j[1]",
"+ if 0 <= foo[jx][jy] < lim:",
"+ print((rev[x][y] + foo[jx][jy] + 1))",
"+ exit()",
"+ else:",
"+ if rev[jx][jy] > start:",
"+ rev[jx][jy] = start",
"+ new_rev.append((jx, jy))",
"+ while len(new_rev) > 0:",
"+ item = new_rev.pop()",
"+ now_rev.append(item)",
"+ x = item[0]",
"+ y = item[1]",
"+ for m in mv:",
"+ mx = x + m[0]",
"+ my = y + m[1]",
"+ if 0 <= foo[mx][my] < lim:",
"+ print((rev[x][y] + foo[mx][my]))",
"+ exit()",
"+ else:",
"+ if rev[mx][my] == lim:",
"+ rev[mx][my] = start",
"+ new_rev.append((mx, my))"
]
| false | 0.057387 | 0.063805 | 0.899415 | [
"s022191123",
"s102481261"
]
|
u606045429 | p03132 | python | s443440453 | s473631075 | 368 | 265 | 11,036 | 11,036 | Accepted | Accepted | 27.99 | L, *A = list(map(int, open(0)))
D = [(2, 1), (1, 0), (0, 1)]
s0 = s1 = s2 = s3 = s4 = 0
for a in A:
e, o = D[(a - 1) % 2 + 1 if a else 0]
s0 += a
s1 = min(s0, s1 + e)
s2 = min(s1, s2 + o)
s3 = min(s2, s3 + e)
s4 = min(s3, s4 + a)
print((min(s0, s1, s2, s3, s4)))
| L, *A = list(map(int, open(0)))
D = [(2, 1), (1, 0), (0, 1)]
s0 = s1 = s2 = s3 = s4 = 0
for a in A:
e, o = D[(a - 1) % 2 + 1 if a else 0]
s0 += a
s1 = s0 if s0 < s1 + e else s1 + e
s2 = s1 if s1 < s2 + o else s2 + o
s3 = s2 if s2 < s3 + e else s3 + e
s4 = s3 if s3 < s4 + a else s4 + a
print((min(s0, s1, s2, s3, s4)))
| 16 | 16 | 299 | 355 | L, *A = list(map(int, open(0)))
D = [(2, 1), (1, 0), (0, 1)]
s0 = s1 = s2 = s3 = s4 = 0
for a in A:
e, o = D[(a - 1) % 2 + 1 if a else 0]
s0 += a
s1 = min(s0, s1 + e)
s2 = min(s1, s2 + o)
s3 = min(s2, s3 + e)
s4 = min(s3, s4 + a)
print((min(s0, s1, s2, s3, s4)))
| L, *A = list(map(int, open(0)))
D = [(2, 1), (1, 0), (0, 1)]
s0 = s1 = s2 = s3 = s4 = 0
for a in A:
e, o = D[(a - 1) % 2 + 1 if a else 0]
s0 += a
s1 = s0 if s0 < s1 + e else s1 + e
s2 = s1 if s1 < s2 + o else s2 + o
s3 = s2 if s2 < s3 + e else s3 + e
s4 = s3 if s3 < s4 + a else s4 + a
print((min(s0, s1, s2, s3, s4)))
| false | 0 | [
"- s1 = min(s0, s1 + e)",
"- s2 = min(s1, s2 + o)",
"- s3 = min(s2, s3 + e)",
"- s4 = min(s3, s4 + a)",
"+ s1 = s0 if s0 < s1 + e else s1 + e",
"+ s2 = s1 if s1 < s2 + o else s2 + o",
"+ s3 = s2 if s2 < s3 + e else s3 + e",
"+ s4 = s3 if s3 < s4 + a else s4 + a"
]
| false | 0.053905 | 0.035171 | 1.532634 | [
"s443440453",
"s473631075"
]
|
u460172144 | p02288 | python | s138159973 | s429941624 | 1,050 | 790 | 74,128 | 72,888 | Accepted | Accepted | 24.76 |
def maxHeapify(i):
l =2*i
r = 2*i+1
# print(A[i])
largest =0
if l <=H and A[l]> A[i]:
largest = l
else:
largest = i
if r <= H and A[r] > A[largest]:
largest = r
if largest != i :
A[i],A[largest] = A[largest],A[i]
maxHeapify(largest)
# print(A)
H = int(input())
A = list(map(int,input().split()))
A = [-1]+A
for i in range(int(H/2),0,-1):
maxHeapify(i)
Astr = list(map(str,A))
print(" ",end="")
print(*A[1:])
|
def maxHeapify(i):
l =2*i
r = 2*i+1
# print(A[i])
largest =0
if l <=H and A[l]> A[i]:
largest = l
else:
largest = i
if r <= H and A[r] > A[largest]:
largest = r
if largest != i :
A[i],A[largest] = A[largest],A[i]
maxHeapify(largest)
# print(A)
H = int(input())
A = list(map(int,input().split()))
A = [-1]+A
for i in range(int(H/2),0,-1):
maxHeapify(i)
Astr = list(map(str,A))
print(" ",end="")
print(" ".join(Astr[1:]))
| 36 | 36 | 536 | 548 | def maxHeapify(i):
l = 2 * i
r = 2 * i + 1
# print(A[i])
largest = 0
if l <= H and A[l] > A[i]:
largest = l
else:
largest = i
if r <= H and A[r] > A[largest]:
largest = r
if largest != i:
A[i], A[largest] = A[largest], A[i]
maxHeapify(largest)
# print(A)
H = int(input())
A = list(map(int, input().split()))
A = [-1] + A
for i in range(int(H / 2), 0, -1):
maxHeapify(i)
Astr = list(map(str, A))
print(" ", end="")
print(*A[1:])
| def maxHeapify(i):
l = 2 * i
r = 2 * i + 1
# print(A[i])
largest = 0
if l <= H and A[l] > A[i]:
largest = l
else:
largest = i
if r <= H and A[r] > A[largest]:
largest = r
if largest != i:
A[i], A[largest] = A[largest], A[i]
maxHeapify(largest)
# print(A)
H = int(input())
A = list(map(int, input().split()))
A = [-1] + A
for i in range(int(H / 2), 0, -1):
maxHeapify(i)
Astr = list(map(str, A))
print(" ", end="")
print(" ".join(Astr[1:]))
| false | 0 | [
"-print(*A[1:])",
"+print(\" \".join(Astr[1:]))"
]
| false | 0.043362 | 0.040124 | 1.080692 | [
"s138159973",
"s429941624"
]
|
u939702463 | p03434 | python | s450863986 | s111949389 | 20 | 17 | 2,940 | 3,060 | Accepted | Accepted | 15 | n = int(eval(input()))
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = sum(a[0::2]) - sum(a[1::2])
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
a.reverse()
print((sum(a[::2]) - sum(a[1::2])))
| 8 | 6 | 129 | 114 | n = int(eval(input()))
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = sum(a[0::2]) - sum(a[1::2])
print(ans)
| n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
a.reverse()
print((sum(a[::2]) - sum(a[1::2])))
| false | 25 | [
"-a.sort(reverse=True)",
"-ans = sum(a[0::2]) - sum(a[1::2])",
"-print(ans)",
"+a.sort()",
"+a.reverse()",
"+print((sum(a[::2]) - sum(a[1::2])))"
]
| false | 0.038636 | 0.092157 | 0.419239 | [
"s450863986",
"s111949389"
]
|
u113835532 | p03207 | python | s893847348 | s770378587 | 30 | 26 | 9,140 | 9,180 | Accepted | Accepted | 13.33 | n = int(eval(input()))
p = list(int(eval(input())) for _ in range(n))
p.append(p.pop(p.index(max(p))) // 2)
print((sum(p))) | def answer(n: int, p: []) -> int:
p.append(p.pop(p.index(max(p))) // 2)
return sum(p)
def main():
n = int(eval(input()))
p = list(int(eval(input())) for _ in range(n))
print((answer(n, p)))
if __name__ == '__main__':
main() | 4 | 13 | 112 | 249 | n = int(eval(input()))
p = list(int(eval(input())) for _ in range(n))
p.append(p.pop(p.index(max(p))) // 2)
print((sum(p)))
| def answer(n: int, p: []) -> int:
p.append(p.pop(p.index(max(p))) // 2)
return sum(p)
def main():
n = int(eval(input()))
p = list(int(eval(input())) for _ in range(n))
print((answer(n, p)))
if __name__ == "__main__":
main()
| false | 69.230769 | [
"-n = int(eval(input()))",
"-p = list(int(eval(input())) for _ in range(n))",
"-p.append(p.pop(p.index(max(p))) // 2)",
"-print((sum(p)))",
"+def answer(n: int, p: []) -> int:",
"+ p.append(p.pop(p.index(max(p))) // 2)",
"+ return sum(p)",
"+",
"+",
"+def main():",
"+ n = int(eval(input()))",
"+ p = list(int(eval(input())) for _ in range(n))",
"+ print((answer(n, p)))",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.035994 | 0.035092 | 1.025684 | [
"s893847348",
"s770378587"
]
|
u814171899 | p03310 | python | s777265120 | s053998282 | 946 | 847 | 25,536 | 24,180 | Accepted | Accepted | 10.47 | from itertools import accumulate
n=int(eval(input()))
a=list(map(int, input().split()))
acc=list(accumulate(a))
sumA=acc[-1]
cut=[0, 1, 2, len(a)-1]
score=[acc[cut[0]], acc[cut[1]]-acc[cut[0]], acc[cut[2]]-acc[cut[1]], acc[cut[3]]-acc[cut[2]]]
ans=max(score)-min(score)
for i in range(1,len(a)-1):
cut[1]=i
while abs(acc[cut[1]]-acc[cut[0]]-acc[cut[0]]) > abs(acc[cut[1]]-acc[cut[0]+1]-acc[cut[0]+1]):
cut[0]+=1
while abs(acc[cut[3]]-acc[cut[2]]-(acc[cut[2]]-acc[cut[1]])) > abs(acc[cut[3]]-acc[cut[2]+1]-(acc[cut[2]+1]-acc[cut[1]])):
cut[2]+=1
score=[acc[cut[0]], acc[cut[1]]-acc[cut[0]], acc[cut[2]]-acc[cut[1]], acc[cut[3]]-acc[cut[2]]]
ans=min(ans, max(score)-min(score))
print(ans)
| from itertools import accumulate
n=int(eval(input()))
a=list(map(int, input().split()))
acc=list(accumulate(a))
left=0; right=2
ans=float('inf')
for center in range(1,n-1):
while abs(acc[center]-acc[left]-acc[left]) > abs(acc[center]-acc[left+1]-acc[left+1]):
left+=1
while abs(acc[n-1]-acc[right]-(acc[right]-acc[center])) > abs(acc[n-1]-acc[right+1]-(acc[right+1]-acc[center])):
right+=1
score=acc[left], acc[center]-acc[left], acc[right]-acc[center], acc[n-1]-acc[right]
ans=min(ans, max(score)-min(score))
print(ans)
| 18 | 15 | 740 | 563 | from itertools import accumulate
n = int(eval(input()))
a = list(map(int, input().split()))
acc = list(accumulate(a))
sumA = acc[-1]
cut = [0, 1, 2, len(a) - 1]
score = [
acc[cut[0]],
acc[cut[1]] - acc[cut[0]],
acc[cut[2]] - acc[cut[1]],
acc[cut[3]] - acc[cut[2]],
]
ans = max(score) - min(score)
for i in range(1, len(a) - 1):
cut[1] = i
while abs(acc[cut[1]] - acc[cut[0]] - acc[cut[0]]) > abs(
acc[cut[1]] - acc[cut[0] + 1] - acc[cut[0] + 1]
):
cut[0] += 1
while abs(acc[cut[3]] - acc[cut[2]] - (acc[cut[2]] - acc[cut[1]])) > abs(
acc[cut[3]] - acc[cut[2] + 1] - (acc[cut[2] + 1] - acc[cut[1]])
):
cut[2] += 1
score = [
acc[cut[0]],
acc[cut[1]] - acc[cut[0]],
acc[cut[2]] - acc[cut[1]],
acc[cut[3]] - acc[cut[2]],
]
ans = min(ans, max(score) - min(score))
print(ans)
| from itertools import accumulate
n = int(eval(input()))
a = list(map(int, input().split()))
acc = list(accumulate(a))
left = 0
right = 2
ans = float("inf")
for center in range(1, n - 1):
while abs(acc[center] - acc[left] - acc[left]) > abs(
acc[center] - acc[left + 1] - acc[left + 1]
):
left += 1
while abs(acc[n - 1] - acc[right] - (acc[right] - acc[center])) > abs(
acc[n - 1] - acc[right + 1] - (acc[right + 1] - acc[center])
):
right += 1
score = (
acc[left],
acc[center] - acc[left],
acc[right] - acc[center],
acc[n - 1] - acc[right],
)
ans = min(ans, max(score) - min(score))
print(ans)
| false | 16.666667 | [
"-sumA = acc[-1]",
"-cut = [0, 1, 2, len(a) - 1]",
"-score = [",
"- acc[cut[0]],",
"- acc[cut[1]] - acc[cut[0]],",
"- acc[cut[2]] - acc[cut[1]],",
"- acc[cut[3]] - acc[cut[2]],",
"-]",
"-ans = max(score) - min(score)",
"-for i in range(1, len(a) - 1):",
"- cut[1] = i",
"- while abs(acc[cut[1]] - acc[cut[0]] - acc[cut[0]]) > abs(",
"- acc[cut[1]] - acc[cut[0] + 1] - acc[cut[0] + 1]",
"+left = 0",
"+right = 2",
"+ans = float(\"inf\")",
"+for center in range(1, n - 1):",
"+ while abs(acc[center] - acc[left] - acc[left]) > abs(",
"+ acc[center] - acc[left + 1] - acc[left + 1]",
"- cut[0] += 1",
"- while abs(acc[cut[3]] - acc[cut[2]] - (acc[cut[2]] - acc[cut[1]])) > abs(",
"- acc[cut[3]] - acc[cut[2] + 1] - (acc[cut[2] + 1] - acc[cut[1]])",
"+ left += 1",
"+ while abs(acc[n - 1] - acc[right] - (acc[right] - acc[center])) > abs(",
"+ acc[n - 1] - acc[right + 1] - (acc[right + 1] - acc[center])",
"- cut[2] += 1",
"- score = [",
"- acc[cut[0]],",
"- acc[cut[1]] - acc[cut[0]],",
"- acc[cut[2]] - acc[cut[1]],",
"- acc[cut[3]] - acc[cut[2]],",
"- ]",
"+ right += 1",
"+ score = (",
"+ acc[left],",
"+ acc[center] - acc[left],",
"+ acc[right] - acc[center],",
"+ acc[n - 1] - acc[right],",
"+ )"
]
| false | 0.050774 | 0.087914 | 0.577549 | [
"s777265120",
"s053998282"
]
|
u102461423 | p02649 | python | s122055425 | s924769178 | 575 | 193 | 110,580 | 30,448 | Accepted | Accepted | 66.43 | import sys
import numpy as np
from numba import njit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit('(i4[::1],i4,i8[::1])', cache=True)
def main(A, B, C):
counts = np.zeros(1 << 18, np.int32)
popcount = np.zeros(1 << B, np.int32)
for i in range(B):
popcount[1 << i:1 << i + 1] = popcount[:1 << i] + 1
answer = 0
for i in range(1 << B):
k = popcount[i]
t = 0
for x in A & i:
n = counts[x]
counts[x] += 1
t -= C[n]
t += C[n + 1]
for x in A & i:
counts[x] = 0
if k & 1:
t = -t
answer += t
return answer
if sys.argv[-1] == 'ONLINE_JUDGE':
from numba.pycc import CC
cc = CC('my_module')
cc.export('main', '(i4[::1],i4,i8[::1])')(main)
cc.compile()
exit()
from my_module import main
N, K, S, T = list(map(int, readline().split()))
A = np.array(readline().split(), np.int32)
def convert_problem(S, T, A):
ng = np.zeros(len(A), np.bool)
B = np.zeros_like(A)
n = 0
for i in range(18):
s, t = (S >> i) & 1, (T >> i) & 1
if (s, t) == (0, 0):
ng |= ((A >> i) & 1) == 1
elif (s, t) == (1, 1):
ng |= ((A >> i) & 1) == 0
elif (s, t) == (1, 0):
print((0))
exit()
else:
B += ((A >> i) & 1) << n
n += 1
return B[~ng], n
A, B = convert_problem(S, T, A)
C = np.zeros((100, 100), np.int64)
C[0, 0] = 1
for n in range(1, 100):
C[n, :-1] += C[n - 1, :-1]
C[n, 1:] += C[n - 1, :-1]
C = C[:, 1:K + 1].sum(axis=1)
print((main(A, B, C))) | import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main(A, B, C):
counts = np.zeros(1 << 18, np.int32)
popcount = np.zeros(1 << B, np.int32)
for i in range(B):
popcount[1 << i:1 << i + 1] = popcount[:1 << i] + 1
answer = 0
for i in range(1 << B):
k = popcount[i]
t = 0
for x in A & i:
n = counts[x]
counts[x] += 1
t -= C[n]
t += C[n + 1]
for x in A & i:
counts[x] = 0
if k & 1:
t = -t
answer += t
return answer
if sys.argv[-1] == 'ONLINE_JUDGE':
from numba.pycc import CC
cc = CC('my_module')
cc.export('main', '(i4[::1],i4,i8[::1])')(main)
cc.compile()
exit()
from my_module import main
N, K, S, T = list(map(int, readline().split()))
A = np.array(readline().split(), np.int32)
def convert_problem(S, T, A):
ng = np.zeros(len(A), np.bool)
B = np.zeros_like(A)
n = 0
for i in range(18):
s, t = (S >> i) & 1, (T >> i) & 1
if (s, t) == (0, 0):
ng |= ((A >> i) & 1) == 1
elif (s, t) == (1, 1):
ng |= ((A >> i) & 1) == 0
elif (s, t) == (1, 0):
print((0))
exit()
else:
B += ((A >> i) & 1) << n
n += 1
return B[~ng], n
A, B = convert_problem(S, T, A)
C = np.zeros((100, 100), np.int64)
C[0, 0] = 1
for n in range(1, 100):
C[n, :-1] += C[n - 1, :-1]
C[n, 1:] += C[n - 1, :-1]
C = C[:, 1:K + 1].sum(axis=1)
print((main(A, B, C)))
| 70 | 68 | 1,756 | 1,690 | import sys
import numpy as np
from numba import njit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
@njit("(i4[::1],i4,i8[::1])", cache=True)
def main(A, B, C):
counts = np.zeros(1 << 18, np.int32)
popcount = np.zeros(1 << B, np.int32)
for i in range(B):
popcount[1 << i : 1 << i + 1] = popcount[: 1 << i] + 1
answer = 0
for i in range(1 << B):
k = popcount[i]
t = 0
for x in A & i:
n = counts[x]
counts[x] += 1
t -= C[n]
t += C[n + 1]
for x in A & i:
counts[x] = 0
if k & 1:
t = -t
answer += t
return answer
if sys.argv[-1] == "ONLINE_JUDGE":
from numba.pycc import CC
cc = CC("my_module")
cc.export("main", "(i4[::1],i4,i8[::1])")(main)
cc.compile()
exit()
from my_module import main
N, K, S, T = list(map(int, readline().split()))
A = np.array(readline().split(), np.int32)
def convert_problem(S, T, A):
ng = np.zeros(len(A), np.bool)
B = np.zeros_like(A)
n = 0
for i in range(18):
s, t = (S >> i) & 1, (T >> i) & 1
if (s, t) == (0, 0):
ng |= ((A >> i) & 1) == 1
elif (s, t) == (1, 1):
ng |= ((A >> i) & 1) == 0
elif (s, t) == (1, 0):
print((0))
exit()
else:
B += ((A >> i) & 1) << n
n += 1
return B[~ng], n
A, B = convert_problem(S, T, A)
C = np.zeros((100, 100), np.int64)
C[0, 0] = 1
for n in range(1, 100):
C[n, :-1] += C[n - 1, :-1]
C[n, 1:] += C[n - 1, :-1]
C = C[:, 1 : K + 1].sum(axis=1)
print((main(A, B, C)))
| import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main(A, B, C):
counts = np.zeros(1 << 18, np.int32)
popcount = np.zeros(1 << B, np.int32)
for i in range(B):
popcount[1 << i : 1 << i + 1] = popcount[: 1 << i] + 1
answer = 0
for i in range(1 << B):
k = popcount[i]
t = 0
for x in A & i:
n = counts[x]
counts[x] += 1
t -= C[n]
t += C[n + 1]
for x in A & i:
counts[x] = 0
if k & 1:
t = -t
answer += t
return answer
if sys.argv[-1] == "ONLINE_JUDGE":
from numba.pycc import CC
cc = CC("my_module")
cc.export("main", "(i4[::1],i4,i8[::1])")(main)
cc.compile()
exit()
from my_module import main
N, K, S, T = list(map(int, readline().split()))
A = np.array(readline().split(), np.int32)
def convert_problem(S, T, A):
ng = np.zeros(len(A), np.bool)
B = np.zeros_like(A)
n = 0
for i in range(18):
s, t = (S >> i) & 1, (T >> i) & 1
if (s, t) == (0, 0):
ng |= ((A >> i) & 1) == 1
elif (s, t) == (1, 1):
ng |= ((A >> i) & 1) == 0
elif (s, t) == (1, 0):
print((0))
exit()
else:
B += ((A >> i) & 1) << n
n += 1
return B[~ng], n
A, B = convert_problem(S, T, A)
C = np.zeros((100, 100), np.int64)
C[0, 0] = 1
for n in range(1, 100):
C[n, :-1] += C[n - 1, :-1]
C[n, 1:] += C[n - 1, :-1]
C = C[:, 1 : K + 1].sum(axis=1)
print((main(A, B, C)))
| false | 2.857143 | [
"-from numba import njit",
"-@njit(\"(i4[::1],i4,i8[::1])\", cache=True)"
]
| false | 0.217477 | 0.281103 | 0.773656 | [
"s122055425",
"s924769178"
]
|
u611090896 | p03292 | python | s927777772 | s799764096 | 19 | 17 | 3,060 | 2,940 | Accepted | Accepted | 10.53 | a,b,c = sorted(map(int,input().split()))
print((c-b + b-a)) | *a, = list(map(int,input().split()))
print((max(a)-min(a)))
| 2 | 2 | 58 | 53 | a, b, c = sorted(map(int, input().split()))
print((c - b + b - a))
| (*a,) = list(map(int, input().split()))
print((max(a) - min(a)))
| false | 0 | [
"-a, b, c = sorted(map(int, input().split()))",
"-print((c - b + b - a))",
"+(*a,) = list(map(int, input().split()))",
"+print((max(a) - min(a)))"
]
| false | 0.045701 | 0.117712 | 0.388245 | [
"s927777772",
"s799764096"
]
|
u608088992 | p03295 | python | s525917130 | s585108558 | 506 | 236 | 21,648 | 22,852 | Accepted | Accepted | 53.36 | N, M = list(map(int, input().split()))
AB = []
for i in range(M):
AB.append([int(i) for i in input().split()])
AB.sort()
MinBar = 1
abar = AB[0][0]
bbar = AB[0][1]
for i in range(1, M):
if AB[i][0] < bbar:
bbar = min(bbar, AB[i][1])
else:
MinBar += 1
abar = AB[i][0]
bbar = AB[i][1]
print(MinBar) | import sys
from operator import itemgetter
def solve():
input = sys.stdin.readline
N, M = list(map(int, input().split()))
Cut = [[int(i) - 1 for i in input().split()] for _ in range(M)]
Cut.sort(key = itemgetter(1))
count = 1
cindex = 1
cutPlace = Cut[0][1]
while cindex < M:
if Cut[cindex][0] < cutPlace: cindex += 1
else:
count += 1
cutPlace = Cut[cindex][1]
cindex += 1
print(count)
return 0
if __name__ == "__main__":
solve() | 17 | 23 | 351 | 544 | N, M = list(map(int, input().split()))
AB = []
for i in range(M):
AB.append([int(i) for i in input().split()])
AB.sort()
MinBar = 1
abar = AB[0][0]
bbar = AB[0][1]
for i in range(1, M):
if AB[i][0] < bbar:
bbar = min(bbar, AB[i][1])
else:
MinBar += 1
abar = AB[i][0]
bbar = AB[i][1]
print(MinBar)
| import sys
from operator import itemgetter
def solve():
input = sys.stdin.readline
N, M = list(map(int, input().split()))
Cut = [[int(i) - 1 for i in input().split()] for _ in range(M)]
Cut.sort(key=itemgetter(1))
count = 1
cindex = 1
cutPlace = Cut[0][1]
while cindex < M:
if Cut[cindex][0] < cutPlace:
cindex += 1
else:
count += 1
cutPlace = Cut[cindex][1]
cindex += 1
print(count)
return 0
if __name__ == "__main__":
solve()
| false | 26.086957 | [
"-N, M = list(map(int, input().split()))",
"-AB = []",
"-for i in range(M):",
"- AB.append([int(i) for i in input().split()])",
"-AB.sort()",
"-MinBar = 1",
"-abar = AB[0][0]",
"-bbar = AB[0][1]",
"-for i in range(1, M):",
"- if AB[i][0] < bbar:",
"- bbar = min(bbar, AB[i][1])",
"- else:",
"- MinBar += 1",
"- abar = AB[i][0]",
"- bbar = AB[i][1]",
"-print(MinBar)",
"+import sys",
"+from operator import itemgetter",
"+",
"+",
"+def solve():",
"+ input = sys.stdin.readline",
"+ N, M = list(map(int, input().split()))",
"+ Cut = [[int(i) - 1 for i in input().split()] for _ in range(M)]",
"+ Cut.sort(key=itemgetter(1))",
"+ count = 1",
"+ cindex = 1",
"+ cutPlace = Cut[0][1]",
"+ while cindex < M:",
"+ if Cut[cindex][0] < cutPlace:",
"+ cindex += 1",
"+ else:",
"+ count += 1",
"+ cutPlace = Cut[cindex][1]",
"+ cindex += 1",
"+ print(count)",
"+ return 0",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ solve()"
]
| false | 0.037657 | 0.036898 | 1.020552 | [
"s525917130",
"s585108558"
]
|
u057109575 | p03045 | python | s257087407 | s261972208 | 858 | 392 | 94,040 | 107,524 | Accepted | Accepted | 54.31 | N, M = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(M)]
class UnionFind:
def __init__(self, n):
self.par = list(range(n))
self.rank = [0] * n
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
elif self.rank[x] < self.rank[y]:
x, y = y, x
self.par[y] = x
def get_par(self):
return self.par
t = UnionFind(N)
for u, v, _ in edges:
t.unite(u - 1, v - 1)
print((len(set(t.find(x) for x in range(N)))))
|
class UnionFind:
def __init__(self, n):
self.par = list(range(n))
self.rank = [0] * n
self.size = [1] * n
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
elif self.rank[x] < self.rank[y]:
x, y = y, x
self.par[y] = x
self.size[x] += self.size[y]
def is_same(self, x, y):
return self.find(x) == self.find(y)
def get_size(self, x):
return self.size[self.find(x)]
N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(M)]
tree = UnionFind(N)
for x, y, z in X:
tree.unite(x - 1, y - 1)
# Update
for x in range(N):
tree.find(x)
print((len(set(tree.par))))
| 36 | 48 | 882 | 1,040 | N, M = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(M)]
class UnionFind:
def __init__(self, n):
self.par = list(range(n))
self.rank = [0] * n
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
elif self.rank[x] < self.rank[y]:
x, y = y, x
self.par[y] = x
def get_par(self):
return self.par
t = UnionFind(N)
for u, v, _ in edges:
t.unite(u - 1, v - 1)
print((len(set(t.find(x) for x in range(N)))))
| class UnionFind:
def __init__(self, n):
self.par = list(range(n))
self.rank = [0] * n
self.size = [1] * n
def find(self, x):
if self.par[x] == x:
return x
else:
self.par[x] = self.find(self.par[x])
return self.par[x]
def unite(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.rank[x] == self.rank[y]:
self.rank[x] += 1
elif self.rank[x] < self.rank[y]:
x, y = y, x
self.par[y] = x
self.size[x] += self.size[y]
def is_same(self, x, y):
return self.find(x) == self.find(y)
def get_size(self, x):
return self.size[self.find(x)]
N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(M)]
tree = UnionFind(N)
for x, y, z in X:
tree.unite(x - 1, y - 1)
# Update
for x in range(N):
tree.find(x)
print((len(set(tree.par))))
| false | 25 | [
"-N, M = list(map(int, input().split()))",
"-edges = [list(map(int, input().split())) for _ in range(M)]",
"-",
"-",
"+ self.size = [1] * n",
"+ self.size[x] += self.size[y]",
"- def get_par(self):",
"- return self.par",
"+ def is_same(self, x, y):",
"+ return self.find(x) == self.find(y)",
"+",
"+ def get_size(self, x):",
"+ return self.size[self.find(x)]",
"-t = UnionFind(N)",
"-for u, v, _ in edges:",
"- t.unite(u - 1, v - 1)",
"-print((len(set(t.find(x) for x in range(N)))))",
"+N, M = list(map(int, input().split()))",
"+X = [list(map(int, input().split())) for _ in range(M)]",
"+tree = UnionFind(N)",
"+for x, y, z in X:",
"+ tree.unite(x - 1, y - 1)",
"+# Update",
"+for x in range(N):",
"+ tree.find(x)",
"+print((len(set(tree.par))))"
]
| false | 0.043965 | 0.043212 | 1.017434 | [
"s257087407",
"s261972208"
]
|
u317710033 | p03493 | python | s849698042 | s313095233 | 19 | 17 | 2,940 | 2,940 | Accepted | Accepted | 10.53 | a = eval(input())
one_number = a.count('1')
print(( 1 * one_number)) | a = eval(input())
if a == '111':
print((3))
elif a == '110' or a== '101' or a == '011':
print((2))
elif a == '100' or a == '010' or a == '001':
print((1))
else:
print((0)) | 3 | 9 | 62 | 173 | a = eval(input())
one_number = a.count("1")
print((1 * one_number))
| a = eval(input())
if a == "111":
print((3))
elif a == "110" or a == "101" or a == "011":
print((2))
elif a == "100" or a == "010" or a == "001":
print((1))
else:
print((0))
| false | 66.666667 | [
"-one_number = a.count(\"1\")",
"-print((1 * one_number))",
"+if a == \"111\":",
"+ print((3))",
"+elif a == \"110\" or a == \"101\" or a == \"011\":",
"+ print((2))",
"+elif a == \"100\" or a == \"010\" or a == \"001\":",
"+ print((1))",
"+else:",
"+ print((0))"
]
| false | 0.047276 | 0.047558 | 0.99408 | [
"s849698042",
"s313095233"
]
|
u869790980 | p03238 | python | s328156511 | s296358773 | 422 | 56 | 85,060 | 64,264 | Accepted | Accepted | 86.73 | n = int(input())
if n == 1: print('Hello World')
elif n == 2: print(int(input())+int(input())) | print('Hello World' if int(input()) == 1 else (int(input())+int(input()))) | 3 | 1 | 106 | 85 | n = int(input())
if n == 1:
print("Hello World")
elif n == 2:
print(int(input()) + int(input()))
| print("Hello World" if int(input()) == 1 else (int(input()) + int(input())))
| false | 66.666667 | [
"-n = int(input())",
"-if n == 1:",
"- print(\"Hello World\")",
"-elif n == 2:",
"- print(int(input()) + int(input()))",
"+print(\"Hello World\" if int(input()) == 1 else (int(input()) + int(input())))"
]
| false | 0.055729 | 0.037448 | 1.4882 | [
"s328156511",
"s296358773"
]
|
u512212329 | p02691 | python | s991719566 | s888533797 | 206 | 189 | 67,032 | 67,200 | Accepted | Accepted | 8.25 | # class Map(dict):
# def __missing__(self, key):
# # この割当てなしのほうが速い。
# # self[key] = 0
# return 0
def main():
int(eval(input()))
d = {}
ans = 0
for i, height in enumerate(input().split()):
height = int(height)
# 引き算のほうの i は足し算のよりも大きい。
# 従って,このように順番に見ていく必要がある。
d.setdefault(i + height, 0)
d[i + height] += 1
ans += d.setdefault(i - height, 0)
return ans
if __name__ == '__main__':
print((main()))
# 大いに参考にした。
# https://kmjp.hatenablog.jp/entry/2020/05/03/1030
| # class Map(dict):
# def __missing__(self, key):
# # この割当てなしのほうが速い。
# # self[key] = 0
# return 0
def main():
int(eval(input()))
d = {}
ans = 0
d_setdefault = d.setdefault
for i, height in enumerate(input().split()):
height = int(height)
# 引き算のほうの i は足し算のよりも大きい。
# 従って,このように順番に見ていく必要がある。
d_setdefault(i + height, 0)
d[i + height] += 1
ans += d_setdefault(i - height, 0)
return ans
if __name__ == '__main__':
print((main()))
# 大いに参考にした。
# https://kmjp.hatenablog.jp/entry/2020/05/03/1030
| 28 | 29 | 584 | 617 | # class Map(dict):
# def __missing__(self, key):
# # この割当てなしのほうが速い。
# # self[key] = 0
# return 0
def main():
int(eval(input()))
d = {}
ans = 0
for i, height in enumerate(input().split()):
height = int(height)
# 引き算のほうの i は足し算のよりも大きい。
# 従って,このように順番に見ていく必要がある。
d.setdefault(i + height, 0)
d[i + height] += 1
ans += d.setdefault(i - height, 0)
return ans
if __name__ == "__main__":
print((main()))
# 大いに参考にした。
# https://kmjp.hatenablog.jp/entry/2020/05/03/1030
| # class Map(dict):
# def __missing__(self, key):
# # この割当てなしのほうが速い。
# # self[key] = 0
# return 0
def main():
int(eval(input()))
d = {}
ans = 0
d_setdefault = d.setdefault
for i, height in enumerate(input().split()):
height = int(height)
# 引き算のほうの i は足し算のよりも大きい。
# 従って,このように順番に見ていく必要がある。
d_setdefault(i + height, 0)
d[i + height] += 1
ans += d_setdefault(i - height, 0)
return ans
if __name__ == "__main__":
print((main()))
# 大いに参考にした。
# https://kmjp.hatenablog.jp/entry/2020/05/03/1030
| false | 3.448276 | [
"+ d_setdefault = d.setdefault",
"- d.setdefault(i + height, 0)",
"+ d_setdefault(i + height, 0)",
"- ans += d.setdefault(i - height, 0)",
"+ ans += d_setdefault(i - height, 0)"
]
| false | 0.046453 | 0.047804 | 0.971754 | [
"s991719566",
"s888533797"
]
|
u814271993 | p02983 | python | s016638589 | s575549252 | 80 | 73 | 9,168 | 9,076 | Accepted | Accepted | 8.75 | import sys
l, r = list(map(int, input().split()))
ans = 10 ** 10
for i in range(l, r):
for j in range(i+1, r+1):
if (i * j) % 2019 == 0:
print((0))
sys.exit()
ans = min(ans, (i*j) % 2019)
print(ans) | l, r = list(map(int, input().split()))
ans = 10 ** 10
for i in range(l, r):
for j in range(i+1, r+1):
if (i * j) % 2019 == 0:
print((0))
exit()
ans = min(ans, (i*j) % 2019)
print(ans) | 11 | 9 | 224 | 205 | import sys
l, r = list(map(int, input().split()))
ans = 10**10
for i in range(l, r):
for j in range(i + 1, r + 1):
if (i * j) % 2019 == 0:
print((0))
sys.exit()
ans = min(ans, (i * j) % 2019)
print(ans)
| l, r = list(map(int, input().split()))
ans = 10**10
for i in range(l, r):
for j in range(i + 1, r + 1):
if (i * j) % 2019 == 0:
print((0))
exit()
ans = min(ans, (i * j) % 2019)
print(ans)
| false | 18.181818 | [
"-import sys",
"-",
"- sys.exit()",
"+ exit()"
]
| false | 0.038476 | 0.032771 | 1.174063 | [
"s016638589",
"s575549252"
]
|
u843175622 | p04034 | python | s995948804 | s259642135 | 358 | 230 | 5,552 | 11,408 | Accepted | Accepted | 35.75 | n, m = list(map(int, input().split()))
B = [1] * n
R = [0] * n
R[0] = 1
for _ in range(m):
x, y = list(map(int, input().split()))
x -= 1; y -= 1
if B[x] == 1 and R[x] == 1:
R[x] = 0; R[y] = 1
elif B[x] > 1 and R[x] == 1:
R[y] = 1
B[x] -= 1; B[y] += 1
print((len([i for i in R if i==1]))) | n, m = list(map(int, input().split()))
red = [False] * n
ball = [1] * n
red[0] = True
for _ in range(m):
x, y = [int(x) - 1 for x in input().split()]
if red[x]:
red[y] = True
if ball[x] == 1:
red[x] = False
ball[y] += 1
ball[x] -= 1
print((len(list([x for x in red if x]))))
| 16 | 15 | 330 | 335 | n, m = list(map(int, input().split()))
B = [1] * n
R = [0] * n
R[0] = 1
for _ in range(m):
x, y = list(map(int, input().split()))
x -= 1
y -= 1
if B[x] == 1 and R[x] == 1:
R[x] = 0
R[y] = 1
elif B[x] > 1 and R[x] == 1:
R[y] = 1
B[x] -= 1
B[y] += 1
print((len([i for i in R if i == 1])))
| n, m = list(map(int, input().split()))
red = [False] * n
ball = [1] * n
red[0] = True
for _ in range(m):
x, y = [int(x) - 1 for x in input().split()]
if red[x]:
red[y] = True
if ball[x] == 1:
red[x] = False
ball[y] += 1
ball[x] -= 1
print((len(list([x for x in red if x]))))
| false | 6.25 | [
"-B = [1] * n",
"-R = [0] * n",
"-R[0] = 1",
"+red = [False] * n",
"+ball = [1] * n",
"+red[0] = True",
"- x, y = list(map(int, input().split()))",
"- x -= 1",
"- y -= 1",
"- if B[x] == 1 and R[x] == 1:",
"- R[x] = 0",
"- R[y] = 1",
"- elif B[x] > 1 and R[x] == 1:",
"- R[y] = 1",
"- B[x] -= 1",
"- B[y] += 1",
"-print((len([i for i in R if i == 1])))",
"+ x, y = [int(x) - 1 for x in input().split()]",
"+ if red[x]:",
"+ red[y] = True",
"+ if ball[x] == 1:",
"+ red[x] = False",
"+ ball[y] += 1",
"+ ball[x] -= 1",
"+print((len(list([x for x in red if x]))))"
]
| false | 0.075239 | 0.034531 | 2.178862 | [
"s995948804",
"s259642135"
]
|
u949338836 | p02272 | python | s287066787 | s519674111 | 4,580 | 3,620 | 63,720 | 63,780 | Accepted | Accepted | 20.96 | #coding:utf-8
#1_5_B
def merge_sort(array):
if len(array) > 1:
L, countL = merge_sort(array[0:len(array)//2])
R, countR = merge_sort(array[len(array)//2:])
return merge(L, R, countL+countR)
if len(array) == 1:
return [array, 0]
def merge(L, R, count=0):
L.append(10**9+1)
R.append(10**9+1)
response = []
i = 0
j = 0
for k in range(len(L)-1 + len(R)-1):
if L[i] <= R[j]:
response.append(L[i])
i += 1
count += 1
else:
response.append(R[j])
j += 1
count += 1
return [response, count]
n = int(eval(input()))
S = list(map(int, input().split()))
numbers, count = merge_sort(S)
print((*numbers))
print(count) | #coding:utf-8
#1_5_B
def merge(array, left, mid, right):
global cnt
n1 = mid - left
n2 = right - mid
L = array[left:mid] + [sentinel]
R = array[mid:right] + [sentinel]
i = j = 0
for k in range(left, right):
if L[i] <= R[j]:
array[k] = L[i]
i += 1
else:
array[k] = R[j]
j += 1
cnt += right - left
def merge_sort(array, left, right):
if left + 1 < right:
mid = (left + right) // 2
merge_sort(array, left, mid)
merge_sort(array, mid, right)
merge(array, left, mid, right)
n = int(eval(input()))
S = list(map(int, input().split()))
cnt = 0
sentinel = 10 ** 9 + 1
merge_sort(S, 0, len(S))
print((*S))
print(cnt) | 33 | 33 | 784 | 766 | # coding:utf-8
# 1_5_B
def merge_sort(array):
if len(array) > 1:
L, countL = merge_sort(array[0 : len(array) // 2])
R, countR = merge_sort(array[len(array) // 2 :])
return merge(L, R, countL + countR)
if len(array) == 1:
return [array, 0]
def merge(L, R, count=0):
L.append(10**9 + 1)
R.append(10**9 + 1)
response = []
i = 0
j = 0
for k in range(len(L) - 1 + len(R) - 1):
if L[i] <= R[j]:
response.append(L[i])
i += 1
count += 1
else:
response.append(R[j])
j += 1
count += 1
return [response, count]
n = int(eval(input()))
S = list(map(int, input().split()))
numbers, count = merge_sort(S)
print((*numbers))
print(count)
| # coding:utf-8
# 1_5_B
def merge(array, left, mid, right):
global cnt
n1 = mid - left
n2 = right - mid
L = array[left:mid] + [sentinel]
R = array[mid:right] + [sentinel]
i = j = 0
for k in range(left, right):
if L[i] <= R[j]:
array[k] = L[i]
i += 1
else:
array[k] = R[j]
j += 1
cnt += right - left
def merge_sort(array, left, right):
if left + 1 < right:
mid = (left + right) // 2
merge_sort(array, left, mid)
merge_sort(array, mid, right)
merge(array, left, mid, right)
n = int(eval(input()))
S = list(map(int, input().split()))
cnt = 0
sentinel = 10**9 + 1
merge_sort(S, 0, len(S))
print((*S))
print(cnt)
| false | 0 | [
"-def merge_sort(array):",
"- if len(array) > 1:",
"- L, countL = merge_sort(array[0 : len(array) // 2])",
"- R, countR = merge_sort(array[len(array) // 2 :])",
"- return merge(L, R, countL + countR)",
"- if len(array) == 1:",
"- return [array, 0]",
"+def merge(array, left, mid, right):",
"+ global cnt",
"+ n1 = mid - left",
"+ n2 = right - mid",
"+ L = array[left:mid] + [sentinel]",
"+ R = array[mid:right] + [sentinel]",
"+ i = j = 0",
"+ for k in range(left, right):",
"+ if L[i] <= R[j]:",
"+ array[k] = L[i]",
"+ i += 1",
"+ else:",
"+ array[k] = R[j]",
"+ j += 1",
"+ cnt += right - left",
"-def merge(L, R, count=0):",
"- L.append(10**9 + 1)",
"- R.append(10**9 + 1)",
"- response = []",
"- i = 0",
"- j = 0",
"- for k in range(len(L) - 1 + len(R) - 1):",
"- if L[i] <= R[j]:",
"- response.append(L[i])",
"- i += 1",
"- count += 1",
"- else:",
"- response.append(R[j])",
"- j += 1",
"- count += 1",
"- return [response, count]",
"+def merge_sort(array, left, right):",
"+ if left + 1 < right:",
"+ mid = (left + right) // 2",
"+ merge_sort(array, left, mid)",
"+ merge_sort(array, mid, right)",
"+ merge(array, left, mid, right)",
"-numbers, count = merge_sort(S)",
"-print((*numbers))",
"-print(count)",
"+cnt = 0",
"+sentinel = 10**9 + 1",
"+merge_sort(S, 0, len(S))",
"+print((*S))",
"+print(cnt)"
]
| false | 0.041749 | 0.04232 | 0.986514 | [
"s287066787",
"s519674111"
]
|
u794910686 | p02848 | python | s839042251 | s280459734 | 30 | 20 | 3,060 | 3,060 | Accepted | Accepted | 33.33 | E=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
N=int(eval(input()))
S=list(eval(input()))
while(N>=26):
N-=26
for i in range(len(S)):
if N+E.index(S[i])<=25:
S[i]=E[N+E.index(S[i])]
elif N+E.index(S[i])>=26:
S[i]=E[N+E.index(S[i])-26]
print(("".join(S)))
| z="ABCDEFGHIJKLMNOPQRSTUVWXYZ"*2
n=int(eval(input()))%26
s=eval(input())
out=[]
for a in s:
out.append(z[z.find(a)+n])
print(("".join(out)))
| 17 | 7 | 281 | 137 | E = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
N = int(eval(input()))
S = list(eval(input()))
while N >= 26:
N -= 26
for i in range(len(S)):
if N + E.index(S[i]) <= 25:
S[i] = E[N + E.index(S[i])]
elif N + E.index(S[i]) >= 26:
S[i] = E[N + E.index(S[i]) - 26]
print(("".join(S)))
| z = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" * 2
n = int(eval(input())) % 26
s = eval(input())
out = []
for a in s:
out.append(z[z.find(a) + n])
print(("".join(out)))
| false | 58.823529 | [
"-E = list(\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\")",
"-N = int(eval(input()))",
"-S = list(eval(input()))",
"-while N >= 26:",
"- N -= 26",
"-for i in range(len(S)):",
"- if N + E.index(S[i]) <= 25:",
"- S[i] = E[N + E.index(S[i])]",
"- elif N + E.index(S[i]) >= 26:",
"- S[i] = E[N + E.index(S[i]) - 26]",
"-print((\"\".join(S)))",
"+z = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\" * 2",
"+n = int(eval(input())) % 26",
"+s = eval(input())",
"+out = []",
"+for a in s:",
"+ out.append(z[z.find(a) + n])",
"+print((\"\".join(out)))"
]
| false | 0.034737 | 0.036553 | 0.950316 | [
"s839042251",
"s280459734"
]
|
u076917070 | p02834 | python | s367910940 | s812739765 | 758 | 428 | 41,964 | 33,424 | Accepted | Accepted | 43.54 | import sys
input = sys.stdin.readline
import heapq
def dijkstra(s, E):
inf = float("inf")
d = [inf for i in range(len(E))]
d[s] = 0
q = [(0, s)]
while q:
c, p = heapq.heappop(q)
if d[p] < c:
continue
for cost, to in E[p]:
if d[to] > d[p] + cost:
d[to] = d[p] + cost
heapq.heappush(q, (d[to], to))
return d
def main():
N, u, v = list(map(int, input().split()))
E = [[] for i in range(N)]
for _ in range(N-1):
a, b = list(map(int, input().split()))
E[a-1].append((1, b-1))
E[b-1].append((1, a-1))
du = dijkstra(u-1, E)
dv = dijkstra(v-1, E)
ans = 0
for i, j in zip(du, dv):
if i < j:
ans = max(ans, j)
print((ans - 1))
if __name__ == '__main__':
main()
| import sys
input = sys.stdin.readline
def treeDist(u, E):
D = [-1]*len(E)
q = [(u, 0)]
while q:
i, d = q.pop()
if D[i] != -1:
continue
D[i] = d
for j in E[i]:
q.append((j, d+1))
return D
def main():
N, u, v = list(map(int, input().split()))
E = [[] for i in range(N)]
for _ in range(N-1):
a, b = list(map(int, input().split()))
E[a-1].append(b-1)
E[b-1].append(a-1)
D1 = treeDist(u-1, E)
D2 = treeDist(v-1, E)
ans = 0
for d1, d2 in zip(D1, D2):
if d1 < d2:
ans = max(ans, d2)
print((ans-1))
if __name__ == '__main__':
main()
| 39 | 36 | 865 | 705 | import sys
input = sys.stdin.readline
import heapq
def dijkstra(s, E):
inf = float("inf")
d = [inf for i in range(len(E))]
d[s] = 0
q = [(0, s)]
while q:
c, p = heapq.heappop(q)
if d[p] < c:
continue
for cost, to in E[p]:
if d[to] > d[p] + cost:
d[to] = d[p] + cost
heapq.heappush(q, (d[to], to))
return d
def main():
N, u, v = list(map(int, input().split()))
E = [[] for i in range(N)]
for _ in range(N - 1):
a, b = list(map(int, input().split()))
E[a - 1].append((1, b - 1))
E[b - 1].append((1, a - 1))
du = dijkstra(u - 1, E)
dv = dijkstra(v - 1, E)
ans = 0
for i, j in zip(du, dv):
if i < j:
ans = max(ans, j)
print((ans - 1))
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def treeDist(u, E):
D = [-1] * len(E)
q = [(u, 0)]
while q:
i, d = q.pop()
if D[i] != -1:
continue
D[i] = d
for j in E[i]:
q.append((j, d + 1))
return D
def main():
N, u, v = list(map(int, input().split()))
E = [[] for i in range(N)]
for _ in range(N - 1):
a, b = list(map(int, input().split()))
E[a - 1].append(b - 1)
E[b - 1].append(a - 1)
D1 = treeDist(u - 1, E)
D2 = treeDist(v - 1, E)
ans = 0
for d1, d2 in zip(D1, D2):
if d1 < d2:
ans = max(ans, d2)
print((ans - 1))
if __name__ == "__main__":
main()
| false | 7.692308 | [
"-import heapq",
"-def dijkstra(s, E):",
"- inf = float(\"inf\")",
"- d = [inf for i in range(len(E))]",
"- d[s] = 0",
"- q = [(0, s)]",
"+def treeDist(u, E):",
"+ D = [-1] * len(E)",
"+ q = [(u, 0)]",
"- c, p = heapq.heappop(q)",
"- if d[p] < c:",
"+ i, d = q.pop()",
"+ if D[i] != -1:",
"- for cost, to in E[p]:",
"- if d[to] > d[p] + cost:",
"- d[to] = d[p] + cost",
"- heapq.heappush(q, (d[to], to))",
"- return d",
"+ D[i] = d",
"+ for j in E[i]:",
"+ q.append((j, d + 1))",
"+ return D",
"- E[a - 1].append((1, b - 1))",
"- E[b - 1].append((1, a - 1))",
"- du = dijkstra(u - 1, E)",
"- dv = dijkstra(v - 1, E)",
"+ E[a - 1].append(b - 1)",
"+ E[b - 1].append(a - 1)",
"+ D1 = treeDist(u - 1, E)",
"+ D2 = treeDist(v - 1, E)",
"- for i, j in zip(du, dv):",
"- if i < j:",
"- ans = max(ans, j)",
"+ for d1, d2 in zip(D1, D2):",
"+ if d1 < d2:",
"+ ans = max(ans, d2)"
]
| false | 0.062998 | 0.114215 | 0.55157 | [
"s367910940",
"s812739765"
]
|
u143509139 | p03203 | python | s964885676 | s966864625 | 1,459 | 1,118 | 67,672 | 67,924 | Accepted | Accepted | 23.37 | h, w, n = list(map(int, input().split()))
li = []
l = [w] * h
for _ in range(n):
x, y = list(map(int, input().split()))
li.append((x - 1, y - 1))
li.sort()
cnt = 0
ans = h
for x, y in li:
if x - cnt == y:
cnt += 1
elif x - cnt > y:
ans = min(ans, x)
print(ans)
| h, w, n = list(map(int, input().split()))
l = [list(map(int, input().split())) for _ in range(n)]
l.sort(key=lambda x: (x[1], x[0]))
t = 0
a = [h + 1]
for x, y in l:
if x > y + t:
a.append(x)
elif x == y + t:
t += 1
print((min(a) - 1))
| 16 | 11 | 297 | 262 | h, w, n = list(map(int, input().split()))
li = []
l = [w] * h
for _ in range(n):
x, y = list(map(int, input().split()))
li.append((x - 1, y - 1))
li.sort()
cnt = 0
ans = h
for x, y in li:
if x - cnt == y:
cnt += 1
elif x - cnt > y:
ans = min(ans, x)
print(ans)
| h, w, n = list(map(int, input().split()))
l = [list(map(int, input().split())) for _ in range(n)]
l.sort(key=lambda x: (x[1], x[0]))
t = 0
a = [h + 1]
for x, y in l:
if x > y + t:
a.append(x)
elif x == y + t:
t += 1
print((min(a) - 1))
| false | 31.25 | [
"-li = []",
"-l = [w] * h",
"-for _ in range(n):",
"- x, y = list(map(int, input().split()))",
"- li.append((x - 1, y - 1))",
"-li.sort()",
"-cnt = 0",
"-ans = h",
"-for x, y in li:",
"- if x - cnt == y:",
"- cnt += 1",
"- elif x - cnt > y:",
"- ans = min(ans, x)",
"-print(ans)",
"+l = [list(map(int, input().split())) for _ in range(n)]",
"+l.sort(key=lambda x: (x[1], x[0]))",
"+t = 0",
"+a = [h + 1]",
"+for x, y in l:",
"+ if x > y + t:",
"+ a.append(x)",
"+ elif x == y + t:",
"+ t += 1",
"+print((min(a) - 1))"
]
| false | 0.040778 | 0.035667 | 1.143296 | [
"s964885676",
"s966864625"
]
|
u163907160 | p02695 | python | s958271581 | s024299160 | 197 | 169 | 77,092 | 72,260 | Accepted | Accepted | 14.21 | import math
#X=int(input())
N,M,Q=list(map(int,input().split()))
S=[[]for i in range(Q)]
for i in range(Q):
a=list(map(int,input().split()))
S[i]=a
ans=0
T=0
for a in range(1,M+1):
for b in range(a, M+1):
for c in range(b, M+1):
for d in range(c, M+1):
for e in range(d, M+1):
for f in range(e, M+1):
for g in range(f, M+1):
for h in range(g, M+1):
for i in range(h, M+1):
for j in range(i, M+1):
D=[a,b,c,d,e,f,g,h,i,j]
for k in range(Q):
if D[S[k][1]-1]-D[S[k][0]-1]==S[k][2]:
ans+=S[k][3]
if ans>=T:
T=ans
ans = 0
print(T)
| import math
import sys
sys.setrecursionlimit(10**7)
#X=int(input())
N,M,Q=list(map(int,input().split()))
S=[[]for i in range(Q)]
for i in range(Q):
a=list(map(int,input().split()))
S[i]=a
ans=0
T=0
def solve(l):
global ans
if len(l)>=N:
tmp=0
for k in range(Q):
if l[S[k][1]-1]-l[S[k][0]-1]==S[k][2]:
tmp+=S[k][3]
ans=max(ans,tmp)
return
for i in range(l[-1],M+1):
solve(l+[i])
solve([1])
print(ans) | 27 | 24 | 1,030 | 504 | import math
# X=int(input())
N, M, Q = list(map(int, input().split()))
S = [[] for i in range(Q)]
for i in range(Q):
a = list(map(int, input().split()))
S[i] = a
ans = 0
T = 0
for a in range(1, M + 1):
for b in range(a, M + 1):
for c in range(b, M + 1):
for d in range(c, M + 1):
for e in range(d, M + 1):
for f in range(e, M + 1):
for g in range(f, M + 1):
for h in range(g, M + 1):
for i in range(h, M + 1):
for j in range(i, M + 1):
D = [a, b, c, d, e, f, g, h, i, j]
for k in range(Q):
if (
D[S[k][1] - 1] - D[S[k][0] - 1]
== S[k][2]
):
ans += S[k][3]
if ans >= T:
T = ans
ans = 0
print(T)
| import math
import sys
sys.setrecursionlimit(10**7)
# X=int(input())
N, M, Q = list(map(int, input().split()))
S = [[] for i in range(Q)]
for i in range(Q):
a = list(map(int, input().split()))
S[i] = a
ans = 0
T = 0
def solve(l):
global ans
if len(l) >= N:
tmp = 0
for k in range(Q):
if l[S[k][1] - 1] - l[S[k][0] - 1] == S[k][2]:
tmp += S[k][3]
ans = max(ans, tmp)
return
for i in range(l[-1], M + 1):
solve(l + [i])
solve([1])
print(ans)
| false | 11.111111 | [
"+import sys",
"+sys.setrecursionlimit(10**7)",
"-for a in range(1, M + 1):",
"- for b in range(a, M + 1):",
"- for c in range(b, M + 1):",
"- for d in range(c, M + 1):",
"- for e in range(d, M + 1):",
"- for f in range(e, M + 1):",
"- for g in range(f, M + 1):",
"- for h in range(g, M + 1):",
"- for i in range(h, M + 1):",
"- for j in range(i, M + 1):",
"- D = [a, b, c, d, e, f, g, h, i, j]",
"- for k in range(Q):",
"- if (",
"- D[S[k][1] - 1] - D[S[k][0] - 1]",
"- == S[k][2]",
"- ):",
"- ans += S[k][3]",
"- if ans >= T:",
"- T = ans",
"- ans = 0",
"-print(T)",
"+",
"+",
"+def solve(l):",
"+ global ans",
"+ if len(l) >= N:",
"+ tmp = 0",
"+ for k in range(Q):",
"+ if l[S[k][1] - 1] - l[S[k][0] - 1] == S[k][2]:",
"+ tmp += S[k][3]",
"+ ans = max(ans, tmp)",
"+ return",
"+ for i in range(l[-1], M + 1):",
"+ solve(l + [i])",
"+",
"+",
"+solve([1])",
"+print(ans)"
]
| false | 0.084121 | 0.056025 | 1.501509 | [
"s958271581",
"s024299160"
]
|
u875291233 | p02937 | python | s080085398 | s815255115 | 823 | 245 | 103,904 | 103,772 | Accepted | Accepted | 70.23 | # coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意
ss = eval(input())
t = eval(input())
s = ss+ss
l = len(s)
d = [[-1]*26 for _ in range(l)]
#now = [-1]*27
prev = [-1]*27
ans = -1
for i,c in enumerate(s):
# if now[j] == -1: continue
# if d[now[j]][ord(c)-97] == -1:
# d[now[j]][ord(c)-97] = i
for k in range(max(0,prev[ord(c)-97]),i):
d[k][ord(c)-97] = i
# now[ord(c)-97] = i
prev[ord(c)-97] = i
#print(now)
#print(d)
ans = ss.find(t[0])
if ans == -1:
print((-1))
exit()
ls = len(ss)
#print(ans)
lt = len(t)-1
res = ans
for i in range(lt):
# print(res, d[res])
if d[res][ord(t[i+1])-97] == -1:
print((-1))
exit()
diff = d[res][ord(t[i+1])-97] - res
ans += diff
res = (res+diff)%ls
print((ans+1))
| # coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意
s = eval(input())
t = eval(input())
ls = len(s)
ss = s+s
#table[ord(t)-97][i] = 文字tがi番目orそれ以降で登場する最初のindex
table = [[-1]*(ls*2) for _ in range(26)]
prev = [-1]*26
for i,c in enumerate(ss):
cind = ord(c)-97
table[cind][prev[cind]+1:i+1] = [i]*(i-prev[cind])
prev[cind] = i
#print(table)
ans = 0
now = 0
for i in t:
pos = table[ord(i)-97][now]
if pos == -1:
print((-1))
exit()
diff = pos +1 - now
ans += diff
now = (now+diff)%ls
print(ans)
| 69 | 37 | 941 | 639 | # coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline # 文字列入力のときは注意
ss = eval(input())
t = eval(input())
s = ss + ss
l = len(s)
d = [[-1] * 26 for _ in range(l)]
# now = [-1]*27
prev = [-1] * 27
ans = -1
for i, c in enumerate(s):
# if now[j] == -1: continue
# if d[now[j]][ord(c)-97] == -1:
# d[now[j]][ord(c)-97] = i
for k in range(max(0, prev[ord(c) - 97]), i):
d[k][ord(c) - 97] = i
# now[ord(c)-97] = i
prev[ord(c) - 97] = i
# print(now)
# print(d)
ans = ss.find(t[0])
if ans == -1:
print((-1))
exit()
ls = len(ss)
# print(ans)
lt = len(t) - 1
res = ans
for i in range(lt):
# print(res, d[res])
if d[res][ord(t[i + 1]) - 97] == -1:
print((-1))
exit()
diff = d[res][ord(t[i + 1]) - 97] - res
ans += diff
res = (res + diff) % ls
print((ans + 1))
| # coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline # 文字列入力のときは注意
s = eval(input())
t = eval(input())
ls = len(s)
ss = s + s
# table[ord(t)-97][i] = 文字tがi番目orそれ以降で登場する最初のindex
table = [[-1] * (ls * 2) for _ in range(26)]
prev = [-1] * 26
for i, c in enumerate(ss):
cind = ord(c) - 97
table[cind][prev[cind] + 1 : i + 1] = [i] * (i - prev[cind])
prev[cind] = i
# print(table)
ans = 0
now = 0
for i in t:
pos = table[ord(i) - 97][now]
if pos == -1:
print((-1))
exit()
diff = pos + 1 - now
ans += diff
now = (now + diff) % ls
print(ans)
| false | 46.376812 | [
"-ss = eval(input())",
"+s = eval(input())",
"-s = ss + ss",
"-l = len(s)",
"-d = [[-1] * 26 for _ in range(l)]",
"-# now = [-1]*27",
"-prev = [-1] * 27",
"-ans = -1",
"-for i, c in enumerate(s):",
"- # if now[j] == -1: continue",
"- # if d[now[j]][ord(c)-97] == -1:",
"- # d[now[j]][ord(c)-97] = i",
"- for k in range(max(0, prev[ord(c) - 97]), i):",
"- d[k][ord(c) - 97] = i",
"- # now[ord(c)-97] = i",
"- prev[ord(c) - 97] = i",
"-# print(now)",
"-# print(d)",
"-ans = ss.find(t[0])",
"-if ans == -1:",
"- print((-1))",
"- exit()",
"-ls = len(ss)",
"-# print(ans)",
"-lt = len(t) - 1",
"-res = ans",
"-for i in range(lt):",
"- # print(res, d[res])",
"- if d[res][ord(t[i + 1]) - 97] == -1:",
"+ls = len(s)",
"+ss = s + s",
"+# table[ord(t)-97][i] = 文字tがi番目orそれ以降で登場する最初のindex",
"+table = [[-1] * (ls * 2) for _ in range(26)]",
"+prev = [-1] * 26",
"+for i, c in enumerate(ss):",
"+ cind = ord(c) - 97",
"+ table[cind][prev[cind] + 1 : i + 1] = [i] * (i - prev[cind])",
"+ prev[cind] = i",
"+# print(table)",
"+ans = 0",
"+now = 0",
"+for i in t:",
"+ pos = table[ord(i) - 97][now]",
"+ if pos == -1:",
"- diff = d[res][ord(t[i + 1]) - 97] - res",
"+ diff = pos + 1 - now",
"- res = (res + diff) % ls",
"-print((ans + 1))",
"+ now = (now + diff) % ls",
"+print(ans)"
]
| false | 0.042268 | 0.036729 | 1.150812 | [
"s080085398",
"s815255115"
]
|
u952708174 | p03476 | python | s746394731 | s373594048 | 409 | 372 | 24,944 | 33,260 | Accepted | Accepted | 9.05 | def d_2017LikeNumber(Q, I): # Q:クエリの数、I:探索区間の左端と右端
def prime_list(M):
# 0以上M以下の素数のリスト
s = [True] * (M + 1) # i番目の要素はiが素数ならTrue、非素数ならFalse
s[0] = s[1] = False
for x in range(2, int(M**0.5) + 1):
if s[x]:
for i in range(x + x, len(s), x):
# 素数xの倍数は素数ではない
s[i] = False
return s
def calc_like2017(M, p):
# i番目の要素が、1以上i以下の"2017に似た数"の個数となるようなリスト
# 0番目は0と定義する
# M以下の素数のリストpを予め作っておく必要がある
c = [0] * (M + 1)
for i in range(3, M + 1, 2): # 0,1,2は定義上2017に似た数にならない
if p[i] and p[(i + 1) // 2]:
c[i] += 1
for i in range(3, M + 1):
c[i] += c[i - 1]
return c
c = calc_like2017(10**5, prime_list(10**5))
ans = ''
for query in I:
l, r = query[0], query[1]
ans += '{}\n'.format(c[r] - c[l - 1])
return ans[:-1]
Q = int(eval(input()))
I = [[int(i) for i in input().split()] for j in range(Q)]
print((d_2017LikeNumber(Q, I))) | def d_2017_like_number():
Q = int(eval(input()))
I = [[int(i) for i in input().split()] for j in range(Q)]
def prime_table(n):
"""n 以下の整数がそれぞれ素数かどうかのリスト (エラトステネスの篩)"""
is_prime = [True] * (n + 1)
is_prime[0] = is_prime[1] = False # 0と1は素数でない
for j in range(2, int(n**0.5) + 1):
if not is_prime[j]:
continue
for k in range(j * 2, n + 1, j):
is_prime[k] = False # jの倍数は素数でない
return is_prime
def calc_like2017(m, p):
# i 番目の要素が、1 以上 i 以下の "2017に似た数" の個数となるリストを返す
# m 以下の素数のリスト p を予め作っておく必要がある
c = [0] * (m + 1) # 0番目は0と定義する
for i in range(3, m + 1, 2): # 0, 1, 2 は定義上2017に似た数にならない
if p[i] and p[(i + 1) // 2]:
c[i] += 1
for i in range(3, m + 1):
c[i] += c[i - 1]
return c
like2017 = calc_like2017(10**5, prime_table(10**5))
ans = [like2017[r] - like2017[l - 1] for l, r in I]
return '\n'.join(map(str, ans))
print((d_2017_like_number())) | 34 | 31 | 1,079 | 1,076 | def d_2017LikeNumber(Q, I): # Q:クエリの数、I:探索区間の左端と右端
def prime_list(M):
# 0以上M以下の素数のリスト
s = [True] * (M + 1) # i番目の要素はiが素数ならTrue、非素数ならFalse
s[0] = s[1] = False
for x in range(2, int(M**0.5) + 1):
if s[x]:
for i in range(x + x, len(s), x):
# 素数xの倍数は素数ではない
s[i] = False
return s
def calc_like2017(M, p):
# i番目の要素が、1以上i以下の"2017に似た数"の個数となるようなリスト
# 0番目は0と定義する
# M以下の素数のリストpを予め作っておく必要がある
c = [0] * (M + 1)
for i in range(3, M + 1, 2): # 0,1,2は定義上2017に似た数にならない
if p[i] and p[(i + 1) // 2]:
c[i] += 1
for i in range(3, M + 1):
c[i] += c[i - 1]
return c
c = calc_like2017(10**5, prime_list(10**5))
ans = ""
for query in I:
l, r = query[0], query[1]
ans += "{}\n".format(c[r] - c[l - 1])
return ans[:-1]
Q = int(eval(input()))
I = [[int(i) for i in input().split()] for j in range(Q)]
print((d_2017LikeNumber(Q, I)))
| def d_2017_like_number():
Q = int(eval(input()))
I = [[int(i) for i in input().split()] for j in range(Q)]
def prime_table(n):
"""n 以下の整数がそれぞれ素数かどうかのリスト (エラトステネスの篩)"""
is_prime = [True] * (n + 1)
is_prime[0] = is_prime[1] = False # 0と1は素数でない
for j in range(2, int(n**0.5) + 1):
if not is_prime[j]:
continue
for k in range(j * 2, n + 1, j):
is_prime[k] = False # jの倍数は素数でない
return is_prime
def calc_like2017(m, p):
# i 番目の要素が、1 以上 i 以下の "2017に似た数" の個数となるリストを返す
# m 以下の素数のリスト p を予め作っておく必要がある
c = [0] * (m + 1) # 0番目は0と定義する
for i in range(3, m + 1, 2): # 0, 1, 2 は定義上2017に似た数にならない
if p[i] and p[(i + 1) // 2]:
c[i] += 1
for i in range(3, m + 1):
c[i] += c[i - 1]
return c
like2017 = calc_like2017(10**5, prime_table(10**5))
ans = [like2017[r] - like2017[l - 1] for l, r in I]
return "\n".join(map(str, ans))
print((d_2017_like_number()))
| false | 8.823529 | [
"-def d_2017LikeNumber(Q, I): # Q:クエリの数、I:探索区間の左端と右端",
"- def prime_list(M):",
"- # 0以上M以下の素数のリスト",
"- s = [True] * (M + 1) # i番目の要素はiが素数ならTrue、非素数ならFalse",
"- s[0] = s[1] = False",
"- for x in range(2, int(M**0.5) + 1):",
"- if s[x]:",
"- for i in range(x + x, len(s), x):",
"- # 素数xの倍数は素数ではない",
"- s[i] = False",
"- return s",
"+def d_2017_like_number():",
"+ Q = int(eval(input()))",
"+ I = [[int(i) for i in input().split()] for j in range(Q)]",
"- def calc_like2017(M, p):",
"- # i番目の要素が、1以上i以下の\"2017に似た数\"の個数となるようなリスト",
"- # 0番目は0と定義する",
"- # M以下の素数のリストpを予め作っておく必要がある",
"- c = [0] * (M + 1)",
"- for i in range(3, M + 1, 2): # 0,1,2は定義上2017に似た数にならない",
"+ def prime_table(n):",
"+ \"\"\"n 以下の整数がそれぞれ素数かどうかのリスト (エラトステネスの篩)\"\"\"",
"+ is_prime = [True] * (n + 1)",
"+ is_prime[0] = is_prime[1] = False # 0と1は素数でない",
"+ for j in range(2, int(n**0.5) + 1):",
"+ if not is_prime[j]:",
"+ continue",
"+ for k in range(j * 2, n + 1, j):",
"+ is_prime[k] = False # jの倍数は素数でない",
"+ return is_prime",
"+",
"+ def calc_like2017(m, p):",
"+ # i 番目の要素が、1 以上 i 以下の \"2017に似た数\" の個数となるリストを返す",
"+ # m 以下の素数のリスト p を予め作っておく必要がある",
"+ c = [0] * (m + 1) # 0番目は0と定義する",
"+ for i in range(3, m + 1, 2): # 0, 1, 2 は定義上2017に似た数にならない",
"- for i in range(3, M + 1):",
"+ for i in range(3, m + 1):",
"- c = calc_like2017(10**5, prime_list(10**5))",
"- ans = \"\"",
"- for query in I:",
"- l, r = query[0], query[1]",
"- ans += \"{}\\n\".format(c[r] - c[l - 1])",
"- return ans[:-1]",
"+ like2017 = calc_like2017(10**5, prime_table(10**5))",
"+ ans = [like2017[r] - like2017[l - 1] for l, r in I]",
"+ return \"\\n\".join(map(str, ans))",
"-Q = int(eval(input()))",
"-I = [[int(i) for i in input().split()] for j in range(Q)]",
"-print((d_2017LikeNumber(Q, I)))",
"+print((d_2017_like_number()))"
]
| false | 0.007836 | 0.075851 | 0.103307 | [
"s746394731",
"s373594048"
]
|
u581980068 | p03059 | python | s025961675 | s967765030 | 11 | 10 | 2,568 | 2,568 | Accepted | Accepted | 9.09 | [A, B, T] = list(map(int, input().split()))
biscuits = 0
time = 0
while time < (T + 0.5 - A):
biscuits = biscuits + B
time = time + A
print(biscuits) | [A, B, T] = list(map(int, input().split()))
biscuits = B * (T / A)
print(biscuits) | 7 | 3 | 156 | 81 | [A, B, T] = list(map(int, input().split()))
biscuits = 0
time = 0
while time < (T + 0.5 - A):
biscuits = biscuits + B
time = time + A
print(biscuits)
| [A, B, T] = list(map(int, input().split()))
biscuits = B * (T / A)
print(biscuits)
| false | 57.142857 | [
"-biscuits = 0",
"-time = 0",
"-while time < (T + 0.5 - A):",
"- biscuits = biscuits + B",
"- time = time + A",
"+biscuits = B * (T / A)"
]
| false | 0.055889 | 0.035361 | 1.580538 | [
"s025961675",
"s967765030"
]
|
u751549333 | p02595 | python | s233229012 | s209170176 | 555 | 497 | 24,932 | 9,540 | Accepted | Accepted | 10.45 | n , d = list(map(int, input().split()))
x = []
y = []
for i in range(n):
a = list(map(int, (input().split())))
x.append(a[0])
y.append(a[1])
ans = 0
for i in range(n):
if (x[i] ** 2 + y[i] ** 2) ** (0.5) <= d:
ans += 1
print(ans) | n , d = list(map(int, input().split()))
ans = 0
for _ in range(n):
p, q = list(map(int, input().split()))
if (p ** 2 + q ** 2) ** 0.5 <= d:
ans += 1
print(ans) | 14 | 9 | 289 | 206 | n, d = list(map(int, input().split()))
x = []
y = []
for i in range(n):
a = list(map(int, (input().split())))
x.append(a[0])
y.append(a[1])
ans = 0
for i in range(n):
if (x[i] ** 2 + y[i] ** 2) ** (0.5) <= d:
ans += 1
print(ans)
| n, d = list(map(int, input().split()))
ans = 0
for _ in range(n):
p, q = list(map(int, input().split()))
if (p**2 + q**2) ** 0.5 <= d:
ans += 1
print(ans)
| false | 35.714286 | [
"-x = []",
"-y = []",
"-for i in range(n):",
"- a = list(map(int, (input().split())))",
"- x.append(a[0])",
"- y.append(a[1])",
"-for i in range(n):",
"- if (x[i] ** 2 + y[i] ** 2) ** (0.5) <= d:",
"+for _ in range(n):",
"+ p, q = list(map(int, input().split()))",
"+ if (p**2 + q**2) ** 0.5 <= d:"
]
| false | 0.071146 | 0.056632 | 1.256282 | [
"s233229012",
"s209170176"
]
|
u729133443 | p03087 | python | s677514387 | s060060277 | 1,025 | 894 | 53,964 | 7,768 | Accepted | Accepted | 12.78 | I=lambda:list(map(int,input().split()))
n,q=I()
s=eval(input())
a=[0]
for i in range(n):a+=[a[i]+(s[i-1:i+1]=='AC')]
for _ in[0]*q:l,r=I();print((a[r]-a[l])) | I=lambda:list(map(int,input().split()));n,q=I();s=eval(input());a=[0]
for i in range(n):a+=[a[i]+(s[i-1:i+1]=='AC')]
while q:l,r=I();print((a[r]-a[l]));q-=1 | 6 | 3 | 148 | 144 | I = lambda: list(map(int, input().split()))
n, q = I()
s = eval(input())
a = [0]
for i in range(n):
a += [a[i] + (s[i - 1 : i + 1] == "AC")]
for _ in [0] * q:
l, r = I()
print((a[r] - a[l]))
| I = lambda: list(map(int, input().split()))
n, q = I()
s = eval(input())
a = [0]
for i in range(n):
a += [a[i] + (s[i - 1 : i + 1] == "AC")]
while q:
l, r = I()
print((a[r] - a[l]))
q -= 1
| false | 50 | [
"-for _ in [0] * q:",
"+while q:",
"+ q -= 1"
]
| false | 0.047119 | 0.047116 | 1.000077 | [
"s677514387",
"s060060277"
]
|
u041932988 | p02596 | python | s918440104 | s528419778 | 1,665 | 181 | 8,900 | 9,068 | Accepted | Accepted | 89.13 | def f(K):
sum = 0
for i in range(K+1):
sum += (pow(10, i, K)*7)
sum %= K
if sum == 0:
return i+1
return -1
K = int(eval(input()))
print((f(K)))
| def f(K):
sum = 0
p10 = 1
for i in range(K+1):
sum += p10*7
p10 *= 10
p10 %= K
sum %= K
if sum == 0:
return i+1
return -1
K = int(eval(input()))
print((f(K)))
| 14 | 17 | 201 | 239 | def f(K):
sum = 0
for i in range(K + 1):
sum += pow(10, i, K) * 7
sum %= K
if sum == 0:
return i + 1
return -1
K = int(eval(input()))
print((f(K)))
| def f(K):
sum = 0
p10 = 1
for i in range(K + 1):
sum += p10 * 7
p10 *= 10
p10 %= K
sum %= K
if sum == 0:
return i + 1
return -1
K = int(eval(input()))
print((f(K)))
| false | 17.647059 | [
"+ p10 = 1",
"- sum += pow(10, i, K) * 7",
"+ sum += p10 * 7",
"+ p10 *= 10",
"+ p10 %= K"
]
| false | 1.00686 | 0.06896 | 14.600623 | [
"s918440104",
"s528419778"
]
|
u057415180 | p03456 | python | s773702594 | s981740880 | 50 | 18 | 2,940 | 2,940 | Accepted | Accepted | 64 | a, b = list(map(str, input().split()))
c = int(a + b)
for i in range(c):
if i**2 == c:
ans = 'Yes'
break
else:
ans = 'No'
print(ans) | a, b = list(map(str, input().split()))
c = int(a + b)
for i in range(4, 317):
if i**2 == c:
ans = 'Yes'
break
else:
ans = 'No'
print(ans) | 11 | 11 | 170 | 175 | a, b = list(map(str, input().split()))
c = int(a + b)
for i in range(c):
if i**2 == c:
ans = "Yes"
break
else:
ans = "No"
print(ans)
| a, b = list(map(str, input().split()))
c = int(a + b)
for i in range(4, 317):
if i**2 == c:
ans = "Yes"
break
else:
ans = "No"
print(ans)
| false | 0 | [
"-for i in range(c):",
"+for i in range(4, 317):"
]
| false | 0.057242 | 0.036911 | 1.550818 | [
"s773702594",
"s981740880"
]
|
u171276253 | p03448 | python | s535423356 | s631146251 | 49 | 45 | 3,064 | 2,940 | Accepted | Accepted | 8.16 | a, b, c, x = list(map(int, [eval(input()) for i in range(4)]))
ans = 0
for a in range(a + 1):
for b in range(b + 1):
for c in range(c + 1):
if a*500 + b*100 + c*50 == x:
ans += 1
print(ans) | a, b, c, x = list(map(int, [eval(input()) for i in range(4)]))
ans = [ a for a1 in range(a+1) for b1 in range(b+1) for c1 in range(c+1) if a1*500 + b1*100+ c1*50 == x ]
print((len(ans))) | 8 | 3 | 224 | 174 | a, b, c, x = list(map(int, [eval(input()) for i in range(4)]))
ans = 0
for a in range(a + 1):
for b in range(b + 1):
for c in range(c + 1):
if a * 500 + b * 100 + c * 50 == x:
ans += 1
print(ans)
| a, b, c, x = list(map(int, [eval(input()) for i in range(4)]))
ans = [
a
for a1 in range(a + 1)
for b1 in range(b + 1)
for c1 in range(c + 1)
if a1 * 500 + b1 * 100 + c1 * 50 == x
]
print((len(ans)))
| false | 62.5 | [
"-ans = 0",
"-for a in range(a + 1):",
"- for b in range(b + 1):",
"- for c in range(c + 1):",
"- if a * 500 + b * 100 + c * 50 == x:",
"- ans += 1",
"-print(ans)",
"+ans = [",
"+ a",
"+ for a1 in range(a + 1)",
"+ for b1 in range(b + 1)",
"+ for c1 in range(c + 1)",
"+ if a1 * 500 + b1 * 100 + c1 * 50 == x",
"+]",
"+print((len(ans)))"
]
| false | 0.148164 | 0.117462 | 1.261373 | [
"s535423356",
"s631146251"
]
|
u585482323 | p02788 | python | s156613977 | s684217240 | 1,907 | 1,700 | 134,948 | 106,920 | Accepted | Accepted | 10.85 | #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
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)]
sys.setrecursionlimit(1000000)
mod = 1000000007
import operator
class SegmentTree:
def __init__(self, size, default, op = operator.add):
self.size = 2**size.bit_length()
self.dat = [default]*(self.size*2)
self.op = op
def update(self, i, x):
i += self.size
self.dat[i] = x
while i > 0:
i >>= 1
self.dat[i] = self.op(self.dat[i*2], self.dat[i*2+1])
def add(self, i, x):
i += self.size
self.dat[i] = self.op(self.dat[i], x)
while i > 0:
i >>= 1
self.dat[i] = self.op(self.dat[i], x)
def get(self, a, b = None):
if b is None:
b = a + 1
l, r = a + self.size, b + self.size
res = None
while l < r:
if l & 1:
if res is None:
res = self.dat[l]
else:
res = self.op(res, self.dat[l])
l += 1
if r & 1:
r -= 1
if res is None:
res = self.dat[r]
else:
res = self.op(res, self.dat[r])
l >>= 1
r >>= 1
return res
def solve():
n,d,a = LI()
p = LIR(n)
ans = 0
p.sort()
X = [p[i][0] for i in range(n)]
s = SegmentTree(n,0)
for i in range(n):
x,h = p[i]
j = bisect.bisect_left(X,x-2*d)
if i != j:
su = s.get(j,i)
h -= s.get(j,i)
if h > 0:
l = x
k = math.ceil(h/a)
ans += k
s.update(i,k*a)
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
| #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
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)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
def add(i,s):
while i <= n:
bit[i] += s
i += i&-i
def sum(i):
res = 0
while i > 0:
res += bit[i]
i -= i&-i
return res
n,d,a = LI()
p = LIR(n)
bit = [0]*(n+1)
p.sort()
ans = 0
X = [p[i][0] for i in range(n)]
for i in range(n):
x,h = p[i]
j = bisect.bisect_left(X,x-2*d)
if i != j:
su = sum(i+1)
if j > 0:
su -= sum(j)
h -= su
if h > 0:
l = x
k = math.ceil(h/a)
ans += k
add(i+1,k*a)
print(ans)
return
#Solve
if __name__ == "__main__":
solve()
| 96 | 65 | 2,430 | 1,472 | #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
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)]
sys.setrecursionlimit(1000000)
mod = 1000000007
import operator
class SegmentTree:
def __init__(self, size, default, op=operator.add):
self.size = 2 ** size.bit_length()
self.dat = [default] * (self.size * 2)
self.op = op
def update(self, i, x):
i += self.size
self.dat[i] = x
while i > 0:
i >>= 1
self.dat[i] = self.op(self.dat[i * 2], self.dat[i * 2 + 1])
def add(self, i, x):
i += self.size
self.dat[i] = self.op(self.dat[i], x)
while i > 0:
i >>= 1
self.dat[i] = self.op(self.dat[i], x)
def get(self, a, b=None):
if b is None:
b = a + 1
l, r = a + self.size, b + self.size
res = None
while l < r:
if l & 1:
if res is None:
res = self.dat[l]
else:
res = self.op(res, self.dat[l])
l += 1
if r & 1:
r -= 1
if res is None:
res = self.dat[r]
else:
res = self.op(res, self.dat[r])
l >>= 1
r >>= 1
return res
def solve():
n, d, a = LI()
p = LIR(n)
ans = 0
p.sort()
X = [p[i][0] for i in range(n)]
s = SegmentTree(n, 0)
for i in range(n):
x, h = p[i]
j = bisect.bisect_left(X, x - 2 * d)
if i != j:
su = s.get(j, i)
h -= s.get(j, i)
if h > 0:
l = x
k = math.ceil(h / a)
ans += k
s.update(i, k * a)
print(ans)
return
# Solve
if __name__ == "__main__":
solve()
| #!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def I():
return int(sys.stdin.readline())
def LS():
return [list(x) for x in sys.stdin.readline().split()]
def S():
res = list(sys.stdin.readline())
if res[-1] == "\n":
return res[:-1]
return res
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)]
sys.setrecursionlimit(1000000)
mod = 1000000007
def solve():
def add(i, s):
while i <= n:
bit[i] += s
i += i & -i
def sum(i):
res = 0
while i > 0:
res += bit[i]
i -= i & -i
return res
n, d, a = LI()
p = LIR(n)
bit = [0] * (n + 1)
p.sort()
ans = 0
X = [p[i][0] for i in range(n)]
for i in range(n):
x, h = p[i]
j = bisect.bisect_left(X, x - 2 * d)
if i != j:
su = sum(i + 1)
if j > 0:
su -= sum(j)
h -= su
if h > 0:
l = x
k = math.ceil(h / a)
ans += k
add(i + 1, k * a)
print(ans)
return
# Solve
if __name__ == "__main__":
solve()
| false | 32.291667 | [
"-import operator",
"-",
"-",
"-class SegmentTree:",
"- def __init__(self, size, default, op=operator.add):",
"- self.size = 2 ** size.bit_length()",
"- self.dat = [default] * (self.size * 2)",
"- self.op = op",
"-",
"- def update(self, i, x):",
"- i += self.size",
"- self.dat[i] = x",
"- while i > 0:",
"- i >>= 1",
"- self.dat[i] = self.op(self.dat[i * 2], self.dat[i * 2 + 1])",
"-",
"- def add(self, i, x):",
"- i += self.size",
"- self.dat[i] = self.op(self.dat[i], x)",
"- while i > 0:",
"- i >>= 1",
"- self.dat[i] = self.op(self.dat[i], x)",
"-",
"- def get(self, a, b=None):",
"- if b is None:",
"- b = a + 1",
"- l, r = a + self.size, b + self.size",
"- res = None",
"- while l < r:",
"- if l & 1:",
"- if res is None:",
"- res = self.dat[l]",
"- else:",
"- res = self.op(res, self.dat[l])",
"- l += 1",
"- if r & 1:",
"- r -= 1",
"- if res is None:",
"- res = self.dat[r]",
"- else:",
"- res = self.op(res, self.dat[r])",
"- l >>= 1",
"- r >>= 1",
"- return res",
"+ def add(i, s):",
"+ while i <= n:",
"+ bit[i] += s",
"+ i += i & -i",
"+",
"+ def sum(i):",
"+ res = 0",
"+ while i > 0:",
"+ res += bit[i]",
"+ i -= i & -i",
"+ return res",
"+",
"+ bit = [0] * (n + 1)",
"+ p.sort()",
"- p.sort()",
"- s = SegmentTree(n, 0)",
"- su = s.get(j, i)",
"- h -= s.get(j, i)",
"+ su = sum(i + 1)",
"+ if j > 0:",
"+ su -= sum(j)",
"+ h -= su",
"- s.update(i, k * a)",
"+ add(i + 1, k * a)"
]
| false | 0.090695 | 0.034914 | 2.597685 | [
"s156613977",
"s684217240"
]
|
u844646164 | p03449 | python | s140117813 | s149918906 | 165 | 75 | 13,428 | 62,064 | Accepted | Accepted | 54.55 | import numpy as np
N = int(eval(input()))
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
A_sum = np.cumsum(A)
B_sum = np.cumsum(B[::-1])[::-1]
li = []
for i in range(N):
li.append(A_sum[i]+B_sum[i])
print((max(li))) | N = int(eval(input()))
A = [list(map(int, input().split())) for _ in range(2)]
b = [0] + A[0]
c = [0] + A[1]
if N == 1:
print((A[0][0] + A[1][0]))
exit()
for i in range(1, N):
b[i+1] += b[i]
c[i+1] += c[i]
ans = 0
for i in range(1, N):
tmp = (b[i]-b[0]) + (c[-1]-c[i-1])
ans = max(ans, tmp)
print(ans) | 10 | 20 | 265 | 341 | import numpy as np
N = int(eval(input()))
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
A_sum = np.cumsum(A)
B_sum = np.cumsum(B[::-1])[::-1]
li = []
for i in range(N):
li.append(A_sum[i] + B_sum[i])
print((max(li)))
| N = int(eval(input()))
A = [list(map(int, input().split())) for _ in range(2)]
b = [0] + A[0]
c = [0] + A[1]
if N == 1:
print((A[0][0] + A[1][0]))
exit()
for i in range(1, N):
b[i + 1] += b[i]
c[i + 1] += c[i]
ans = 0
for i in range(1, N):
tmp = (b[i] - b[0]) + (c[-1] - c[i - 1])
ans = max(ans, tmp)
print(ans)
| false | 50 | [
"-import numpy as np",
"-",
"-A = np.array(list(map(int, input().split())))",
"-B = np.array(list(map(int, input().split())))",
"-A_sum = np.cumsum(A)",
"-B_sum = np.cumsum(B[::-1])[::-1]",
"-li = []",
"-for i in range(N):",
"- li.append(A_sum[i] + B_sum[i])",
"-print((max(li)))",
"+A = [list(map(int, input().split())) for _ in range(2)]",
"+b = [0] + A[0]",
"+c = [0] + A[1]",
"+if N == 1:",
"+ print((A[0][0] + A[1][0]))",
"+ exit()",
"+for i in range(1, N):",
"+ b[i + 1] += b[i]",
"+ c[i + 1] += c[i]",
"+ans = 0",
"+for i in range(1, N):",
"+ tmp = (b[i] - b[0]) + (c[-1] - c[i - 1])",
"+ ans = max(ans, tmp)",
"+print(ans)"
]
| false | 0.22304 | 0.041452 | 5.380692 | [
"s140117813",
"s149918906"
]
|
u952708174 | p03013 | python | s529960776 | s287779434 | 589 | 174 | 462,708 | 13,216 | Accepted | Accepted | 70.46 | def c_typical_stairs(N, M, A, MOD=10**9 + 7):
a = set(A)
stairs = [0] * (N + 100)
stairs[0] = 1
for i in range(N):
if i + 1 <= N and (i + 1) not in a:
stairs[i + 1] += stairs[i]
if i + 2 <= N and (i + 2) not in a:
stairs[i + 2] += stairs[i]
return stairs[N] % MOD
N, M = [int(i) for i in input().split()]
A = [int(eval(input())) for _ in range(M)]
print((c_typical_stairs(N, M, A))) | def c_typical_stairs(N, M, A, MOD=(10**9 + 7)):
a = set(A)
stairs = [0] * (N + 1)
stairs[0] = 1
for i in range(1, N + 1):
if i in a:
continue
if i - 1 >= 0:
stairs[i] += stairs[i - 1]
stairs[i] %= MOD
if i - 2 >= 0:
stairs[i] += stairs[i - 2]
stairs[i] %= MOD
return stairs[N] % MOD
N, M = [int(i) for i in input().split()]
A = [int(eval(input())) for _ in range(M)]
print((c_typical_stairs(N, M, A))) | 14 | 18 | 448 | 515 | def c_typical_stairs(N, M, A, MOD=10**9 + 7):
a = set(A)
stairs = [0] * (N + 100)
stairs[0] = 1
for i in range(N):
if i + 1 <= N and (i + 1) not in a:
stairs[i + 1] += stairs[i]
if i + 2 <= N and (i + 2) not in a:
stairs[i + 2] += stairs[i]
return stairs[N] % MOD
N, M = [int(i) for i in input().split()]
A = [int(eval(input())) for _ in range(M)]
print((c_typical_stairs(N, M, A)))
| def c_typical_stairs(N, M, A, MOD=(10**9 + 7)):
a = set(A)
stairs = [0] * (N + 1)
stairs[0] = 1
for i in range(1, N + 1):
if i in a:
continue
if i - 1 >= 0:
stairs[i] += stairs[i - 1]
stairs[i] %= MOD
if i - 2 >= 0:
stairs[i] += stairs[i - 2]
stairs[i] %= MOD
return stairs[N] % MOD
N, M = [int(i) for i in input().split()]
A = [int(eval(input())) for _ in range(M)]
print((c_typical_stairs(N, M, A)))
| false | 22.222222 | [
"-def c_typical_stairs(N, M, A, MOD=10**9 + 7):",
"+def c_typical_stairs(N, M, A, MOD=(10**9 + 7)):",
"- stairs = [0] * (N + 100)",
"+ stairs = [0] * (N + 1)",
"- for i in range(N):",
"- if i + 1 <= N and (i + 1) not in a:",
"- stairs[i + 1] += stairs[i]",
"- if i + 2 <= N and (i + 2) not in a:",
"- stairs[i + 2] += stairs[i]",
"+ for i in range(1, N + 1):",
"+ if i in a:",
"+ continue",
"+ if i - 1 >= 0:",
"+ stairs[i] += stairs[i - 1]",
"+ stairs[i] %= MOD",
"+ if i - 2 >= 0:",
"+ stairs[i] += stairs[i - 2]",
"+ stairs[i] %= MOD"
]
| false | 0.042371 | 0.128305 | 0.330237 | [
"s529960776",
"s287779434"
]
|
u525065967 | p02597 | python | s631850174 | s195106831 | 50 | 29 | 10,624 | 9,368 | Accepted | Accepted | 42 | n = int(eval(input()))
C = list(eval(input()))
r = C.count('R')
c = 0
for i in range(r, n):
if C[i] == 'R': c += 1
print(c)
| _ = int(eval(input()))
C = eval(input())
print((C[C.count('R'):].count('R')))
| 7 | 3 | 122 | 66 | n = int(eval(input()))
C = list(eval(input()))
r = C.count("R")
c = 0
for i in range(r, n):
if C[i] == "R":
c += 1
print(c)
| _ = int(eval(input()))
C = eval(input())
print((C[C.count("R") :].count("R")))
| false | 57.142857 | [
"-n = int(eval(input()))",
"-C = list(eval(input()))",
"-r = C.count(\"R\")",
"-c = 0",
"-for i in range(r, n):",
"- if C[i] == \"R\":",
"- c += 1",
"-print(c)",
"+_ = int(eval(input()))",
"+C = eval(input())",
"+print((C[C.count(\"R\") :].count(\"R\")))"
]
| false | 0.039964 | 0.037204 | 1.074195 | [
"s631850174",
"s195106831"
]
|
u746419473 | p02879 | python | s644828600 | s856828721 | 19 | 17 | 3,060 | 3,064 | Accepted | Accepted | 10.53 | a, b = list(map(int, input().split()))
print((a*b if len(str(a)) == len(str(b)) == 1 else -1))
| a, b = list(map(int, input().split()))
print((a*b if a <= 9 and b <= 9 else -1))
| 3 | 2 | 90 | 74 | a, b = list(map(int, input().split()))
print((a * b if len(str(a)) == len(str(b)) == 1 else -1))
| a, b = list(map(int, input().split()))
print((a * b if a <= 9 and b <= 9 else -1))
| false | 33.333333 | [
"-print((a * b if len(str(a)) == len(str(b)) == 1 else -1))",
"+print((a * b if a <= 9 and b <= 9 else -1))"
]
| false | 0.039492 | 0.03943 | 1.001566 | [
"s644828600",
"s856828721"
]
|
u934442292 | p03355 | python | s159359609 | s289756480 | 38 | 33 | 4,984 | 4,980 | Accepted | Accepted | 13.16 | import sys
from string import ascii_lowercase as AL
input = sys.stdin.readline
def main():
s = input().rstrip()
K = int(eval(input()))
N = len(s)
total = 0
for al in AL:
induces = []
for i in range(N):
if al == s[i]:
induces.append(i)
if not induces:
continue
match = [al]
for i in range(1, 5):
for idx in induces:
if idx + i < N:
match.append(s[idx:idx + i + 1])
match = set(match)
match = sorted(match)
if total + len(match) >= K:
ans = match[K - 1 - total]
break
else:
total += len(match)
print(ans)
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
s = input().rstrip()
K = int(eval(input()))
N = len(s)
sub = []
for i in range(N):
for j in range(K):
sub.append(s[i:i+j+1])
sub = set(sub)
sub = sorted(sub)
ans = sub[K-1]
print(ans)
if __name__ == "__main__":
main()
| 36 | 22 | 796 | 349 | import sys
from string import ascii_lowercase as AL
input = sys.stdin.readline
def main():
s = input().rstrip()
K = int(eval(input()))
N = len(s)
total = 0
for al in AL:
induces = []
for i in range(N):
if al == s[i]:
induces.append(i)
if not induces:
continue
match = [al]
for i in range(1, 5):
for idx in induces:
if idx + i < N:
match.append(s[idx : idx + i + 1])
match = set(match)
match = sorted(match)
if total + len(match) >= K:
ans = match[K - 1 - total]
break
else:
total += len(match)
print(ans)
if __name__ == "__main__":
main()
| import sys
input = sys.stdin.readline
def main():
s = input().rstrip()
K = int(eval(input()))
N = len(s)
sub = []
for i in range(N):
for j in range(K):
sub.append(s[i : i + j + 1])
sub = set(sub)
sub = sorted(sub)
ans = sub[K - 1]
print(ans)
if __name__ == "__main__":
main()
| false | 38.888889 | [
"-from string import ascii_lowercase as AL",
"- total = 0",
"- for al in AL:",
"- induces = []",
"- for i in range(N):",
"- if al == s[i]:",
"- induces.append(i)",
"- if not induces:",
"- continue",
"- match = [al]",
"- for i in range(1, 5):",
"- for idx in induces:",
"- if idx + i < N:",
"- match.append(s[idx : idx + i + 1])",
"- match = set(match)",
"- match = sorted(match)",
"- if total + len(match) >= K:",
"- ans = match[K - 1 - total]",
"- break",
"- else:",
"- total += len(match)",
"+ sub = []",
"+ for i in range(N):",
"+ for j in range(K):",
"+ sub.append(s[i : i + j + 1])",
"+ sub = set(sub)",
"+ sub = sorted(sub)",
"+ ans = sub[K - 1]"
]
| false | 0.042129 | 0.03708 | 1.136188 | [
"s159359609",
"s289756480"
]
|
u729133443 | p02760 | python | s076839438 | s810166060 | 19 | 17 | 3,060 | 3,064 | Accepted | Accepted | 10.53 | a=open(0).read().split();print(('YNeos'[all(t-set(map(a.index,a[10:]))for t in({0,3,6},{0,4,8},{1,4,7},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2])) | a=open(0).read().split();print(('YNeos'[all(t-set(map(a.index,a[10:]))for t in({0,3,6},{0,4,8},{2,4,6},{2,5,8},{3,4,5},{6,7,8}))::2])) | 1 | 1 | 140 | 132 | a = open(0).read().split()
print(
(
"YNeos"[
all(
t - set(map(a.index, a[10:]))
for t in (
{0, 3, 6},
{0, 4, 8},
{1, 4, 7},
{2, 4, 6},
{2, 5, 8},
{3, 4, 5},
{6, 7, 8},
)
) :: 2
]
)
)
| a = open(0).read().split()
print(
(
"YNeos"[
all(
t - set(map(a.index, a[10:]))
for t in (
{0, 3, 6},
{0, 4, 8},
{2, 4, 6},
{2, 5, 8},
{3, 4, 5},
{6, 7, 8},
)
) :: 2
]
)
)
| false | 0 | [
"- {1, 4, 7},"
]
| false | 0.031973 | 0.062704 | 0.509898 | [
"s076839438",
"s810166060"
]
|
u747602774 | p02781 | python | s621463451 | s534303348 | 46 | 42 | 3,192 | 3,316 | Accepted | Accepted | 8.7 | import itertools
N = eval(input())
K = int(eval(input()))
lN = len(N)
if K == 1:
ans = int(N[0])+9*(lN-1)
print(ans)
elif K == 2:
not0 = 1000
for i in range(1,lN):
if int(N[i]) != 0:
not0 = i
break
ans = 0
n = [i for i in range(lN)]
for v in itertools.combinations(n,2):
#print(v)
if v[0] != 0:
ans += 9*9
else:
if not0 >= v[1]:
ans += max(0,int(N[0])-1)*9 + int(N[v[1]])
else:
ans += int(N[0])*9
print(ans)
else:
not0f = 1000
not0s = 1000
for i in range(1,lN):
if int(N[i]) != 0:
not0f = i
break
for i in range(not0f+1,lN):
if int(N[i]) != 0:
not0s = i
break
ans = 0
n = [i for i in range(lN)]
for v in itertools.combinations(n,3):
if v[0] != 0:
ans += 9*9*9
else:
if not0f == v[1]:
if not0s == v[2]:
ans += max(0,int(N[0])-1)*9*9
ans += max(0,int(N[v[1]])-1)*9
ans += int(N[v[2]])
elif not0s < v[2]:
ans += max(0,int(N[0])-1)*9*9
ans += int(N[v[1]])*9
#ans += int(N[0])*int(N[v[1]])*9
else:
ans += max(0,int(N[0])-1)*9*9
ans += max(0,int(N[v[1]])-1)*9
elif not0f < v[1]:
ans += int(N[0])*9*9
else:
ans += max(0,int(N[0])-1)*9*9
print(ans)
| import itertools
N = eval(input())
K = int(eval(input()))
lN = len(N)
if K == 1:
ans = int(N[0])+9*(lN-1)
print(ans)
elif K == 2:
not0 = 1000
for i in range(1,lN):
if int(N[i]) != 0:
not0 = i
break
ans = 0
n = [i for i in range(lN)]
for v in itertools.combinations(n,2):
#print(v)
if v[0] != 0:
ans += 9*9
else:
if not0 >= v[1]:
ans += max(0,int(N[0])-1)*9 + int(N[v[1]])
else:
ans += int(N[0])*9
print(ans)
else:
not0f = 1000
not0s = 1000
for i in range(1,lN):
if int(N[i]) != 0:
not0f = i
break
for i in range(not0f+1,lN):
if int(N[i]) != 0:
not0s = i
break
ans = 0
n = [i for i in range(lN)]
for v in itertools.combinations(n,3):
if v[0] != 0:
ans += 9*9*9
else:
if not0f == v[1]:
if not0s >= v[2]:
ans += max(0,int(N[0])-1)*9*9
ans += max(0,int(N[v[1]])-1)*9
ans += int(N[v[2]])
else:
ans += max(0,int(N[0])-1)*9*9
ans += int(N[v[1]])*9
elif not0f < v[1]:
ans += int(N[0])*9*9
else:
ans += max(0,int(N[0])-1)*9*9
print(ans)
| 67 | 62 | 1,659 | 1,464 | import itertools
N = eval(input())
K = int(eval(input()))
lN = len(N)
if K == 1:
ans = int(N[0]) + 9 * (lN - 1)
print(ans)
elif K == 2:
not0 = 1000
for i in range(1, lN):
if int(N[i]) != 0:
not0 = i
break
ans = 0
n = [i for i in range(lN)]
for v in itertools.combinations(n, 2):
# print(v)
if v[0] != 0:
ans += 9 * 9
else:
if not0 >= v[1]:
ans += max(0, int(N[0]) - 1) * 9 + int(N[v[1]])
else:
ans += int(N[0]) * 9
print(ans)
else:
not0f = 1000
not0s = 1000
for i in range(1, lN):
if int(N[i]) != 0:
not0f = i
break
for i in range(not0f + 1, lN):
if int(N[i]) != 0:
not0s = i
break
ans = 0
n = [i for i in range(lN)]
for v in itertools.combinations(n, 3):
if v[0] != 0:
ans += 9 * 9 * 9
else:
if not0f == v[1]:
if not0s == v[2]:
ans += max(0, int(N[0]) - 1) * 9 * 9
ans += max(0, int(N[v[1]]) - 1) * 9
ans += int(N[v[2]])
elif not0s < v[2]:
ans += max(0, int(N[0]) - 1) * 9 * 9
ans += int(N[v[1]]) * 9
# ans += int(N[0])*int(N[v[1]])*9
else:
ans += max(0, int(N[0]) - 1) * 9 * 9
ans += max(0, int(N[v[1]]) - 1) * 9
elif not0f < v[1]:
ans += int(N[0]) * 9 * 9
else:
ans += max(0, int(N[0]) - 1) * 9 * 9
print(ans)
| import itertools
N = eval(input())
K = int(eval(input()))
lN = len(N)
if K == 1:
ans = int(N[0]) + 9 * (lN - 1)
print(ans)
elif K == 2:
not0 = 1000
for i in range(1, lN):
if int(N[i]) != 0:
not0 = i
break
ans = 0
n = [i for i in range(lN)]
for v in itertools.combinations(n, 2):
# print(v)
if v[0] != 0:
ans += 9 * 9
else:
if not0 >= v[1]:
ans += max(0, int(N[0]) - 1) * 9 + int(N[v[1]])
else:
ans += int(N[0]) * 9
print(ans)
else:
not0f = 1000
not0s = 1000
for i in range(1, lN):
if int(N[i]) != 0:
not0f = i
break
for i in range(not0f + 1, lN):
if int(N[i]) != 0:
not0s = i
break
ans = 0
n = [i for i in range(lN)]
for v in itertools.combinations(n, 3):
if v[0] != 0:
ans += 9 * 9 * 9
else:
if not0f == v[1]:
if not0s >= v[2]:
ans += max(0, int(N[0]) - 1) * 9 * 9
ans += max(0, int(N[v[1]]) - 1) * 9
ans += int(N[v[2]])
else:
ans += max(0, int(N[0]) - 1) * 9 * 9
ans += int(N[v[1]]) * 9
elif not0f < v[1]:
ans += int(N[0]) * 9 * 9
else:
ans += max(0, int(N[0]) - 1) * 9 * 9
print(ans)
| false | 7.462687 | [
"- if not0s == v[2]:",
"+ if not0s >= v[2]:",
"- elif not0s < v[2]:",
"+ else:",
"- # ans += int(N[0])*int(N[v[1]])*9",
"- else:",
"- ans += max(0, int(N[0]) - 1) * 9 * 9",
"- ans += max(0, int(N[v[1]]) - 1) * 9"
]
| false | 0.088823 | 0.083043 | 1.069597 | [
"s621463451",
"s534303348"
]
|
u709304134 | p03031 | python | s040016518 | s998875152 | 255 | 28 | 12,536 | 3,064 | Accepted | Accepted | 89.02 | #coding:utf-8
import itertools
import numpy as np
ls_S = []
N,M = list(map(int,input().split()))
for m in range(M):
S = list(map(int,input().split()))
S = [s-1 for s in S]
ls_S.append(S[1:])
ptns = list(itertools.product(list(range(0,2)), repeat=N))
ptns = np.array(ptns)
#print (ptns)
#print (ls_S)
P = list(map(int,input().split()))
def check(P,ls):
for i in range(len(P)):
if P[i] == ls[i]:
pass
else:
return 0
return 1
sm = 0
for ptn in ptns:
ans = []
for S in ls_S:
#print ("a",sum(ptn[S]))
ans.append(sum(ptn[S])%2)
#print (ans)
sm += check(P,ans)
print (sm)
| from itertools import product
N, M = list(map(int,input().split()))
S = []
for m in range(M):
s = list(map(int,input().split()))
S.append(s[1:])
P = list(map(int,input().split()))
ans = 0
for c in product([0,1],repeat=N):
ok = True
for m in range(M):
sm = 0
for s in S[m]:
sm += c[s-1]
if sm % 2 != P[m]:
ok = False
break
if ok:
ans += 1
print (ans)
| 30 | 22 | 682 | 463 | # coding:utf-8
import itertools
import numpy as np
ls_S = []
N, M = list(map(int, input().split()))
for m in range(M):
S = list(map(int, input().split()))
S = [s - 1 for s in S]
ls_S.append(S[1:])
ptns = list(itertools.product(list(range(0, 2)), repeat=N))
ptns = np.array(ptns)
# print (ptns)
# print (ls_S)
P = list(map(int, input().split()))
def check(P, ls):
for i in range(len(P)):
if P[i] == ls[i]:
pass
else:
return 0
return 1
sm = 0
for ptn in ptns:
ans = []
for S in ls_S:
# print ("a",sum(ptn[S]))
ans.append(sum(ptn[S]) % 2)
# print (ans)
sm += check(P, ans)
print(sm)
| from itertools import product
N, M = list(map(int, input().split()))
S = []
for m in range(M):
s = list(map(int, input().split()))
S.append(s[1:])
P = list(map(int, input().split()))
ans = 0
for c in product([0, 1], repeat=N):
ok = True
for m in range(M):
sm = 0
for s in S[m]:
sm += c[s - 1]
if sm % 2 != P[m]:
ok = False
break
if ok:
ans += 1
print(ans)
| false | 26.666667 | [
"-# coding:utf-8",
"-import itertools",
"-import numpy as np",
"+from itertools import product",
"-ls_S = []",
"+S = []",
"- S = list(map(int, input().split()))",
"- S = [s - 1 for s in S]",
"- ls_S.append(S[1:])",
"-ptns = list(itertools.product(list(range(0, 2)), repeat=N))",
"-ptns = np.array(ptns)",
"-# print (ptns)",
"-# print (ls_S)",
"+ s = list(map(int, input().split()))",
"+ S.append(s[1:])",
"-",
"-",
"-def check(P, ls):",
"- for i in range(len(P)):",
"- if P[i] == ls[i]:",
"- pass",
"- else:",
"- return 0",
"- return 1",
"-",
"-",
"-sm = 0",
"-for ptn in ptns:",
"- ans = []",
"- for S in ls_S:",
"- # print (\"a\",sum(ptn[S]))",
"- ans.append(sum(ptn[S]) % 2)",
"- # print (ans)",
"- sm += check(P, ans)",
"-print(sm)",
"+ans = 0",
"+for c in product([0, 1], repeat=N):",
"+ ok = True",
"+ for m in range(M):",
"+ sm = 0",
"+ for s in S[m]:",
"+ sm += c[s - 1]",
"+ if sm % 2 != P[m]:",
"+ ok = False",
"+ break",
"+ if ok:",
"+ ans += 1",
"+print(ans)"
]
| false | 0.160085 | 0.035969 | 4.450621 | [
"s040016518",
"s998875152"
]
|
u474202990 | p02678 | python | s209773504 | s510598521 | 620 | 566 | 104,784 | 105,056 | Accepted | Accepted | 8.71 | import queue
import sys
imput = sys.stdin.readline
n,m = list(map(int,input().split()))
conne = [[] for _ in range(n)]
dist = [99999]*(n)
par = [0] * (n)
for i in range(m):
a,b = list(map(int,input().split()))
conne[a-1].append(b-1)
conne[b-1].append(a-1)
q=queue.Queue()
dist[0] = 0
q.put((0,0))
while not q.empty():
x,d = q.get()
for i in conne[x]:
if dist[i]==99999:
q.put((i,d+1))
par[i] = x
dist[i] = d+1
print("Yes")
for i in par[1:]:
print((i+1))
| import queue
import sys
imput = sys.stdin.readline
n,m = list(map(int,input().split()))
conne = [[] for _ in range(n+1)]
dist = [99999]*(n+1)
par = [0] * (n+1)
for i in range(m):
a,b = list(map(int,input().split()))
conne[a].append(b)
conne[b].append(a)
q=queue.Queue()
dist[1] = 0
q.put((1,0))
while not q.empty():
x,d = q.get()
for i in conne[x]:
if dist[i]==99999:
q.put((i,d+1))
par[i] = x
dist[i] = d+1
print("Yes")
for i in par[2:]:
print(i)
| 34 | 35 | 569 | 567 | import queue
import sys
imput = sys.stdin.readline
n, m = list(map(int, input().split()))
conne = [[] for _ in range(n)]
dist = [99999] * (n)
par = [0] * (n)
for i in range(m):
a, b = list(map(int, input().split()))
conne[a - 1].append(b - 1)
conne[b - 1].append(a - 1)
q = queue.Queue()
dist[0] = 0
q.put((0, 0))
while not q.empty():
x, d = q.get()
for i in conne[x]:
if dist[i] == 99999:
q.put((i, d + 1))
par[i] = x
dist[i] = d + 1
print("Yes")
for i in par[1:]:
print((i + 1))
| import queue
import sys
imput = sys.stdin.readline
n, m = list(map(int, input().split()))
conne = [[] for _ in range(n + 1)]
dist = [99999] * (n + 1)
par = [0] * (n + 1)
for i in range(m):
a, b = list(map(int, input().split()))
conne[a].append(b)
conne[b].append(a)
q = queue.Queue()
dist[1] = 0
q.put((1, 0))
while not q.empty():
x, d = q.get()
for i in conne[x]:
if dist[i] == 99999:
q.put((i, d + 1))
par[i] = x
dist[i] = d + 1
print("Yes")
for i in par[2:]:
print(i)
| false | 2.857143 | [
"-conne = [[] for _ in range(n)]",
"-dist = [99999] * (n)",
"-par = [0] * (n)",
"+conne = [[] for _ in range(n + 1)]",
"+dist = [99999] * (n + 1)",
"+par = [0] * (n + 1)",
"- conne[a - 1].append(b - 1)",
"- conne[b - 1].append(a - 1)",
"+ conne[a].append(b)",
"+ conne[b].append(a)",
"-dist[0] = 0",
"-q.put((0, 0))",
"+dist[1] = 0",
"+q.put((1, 0))",
"-for i in par[1:]:",
"- print((i + 1))",
"+for i in par[2:]:",
"+ print(i)"
]
| false | 0.08647 | 0.105892 | 0.816585 | [
"s209773504",
"s510598521"
]
|
u645250356 | p03038 | python | s797826633 | s729522175 | 431 | 243 | 34,916 | 34,336 | Accepted | Accepted | 43.62 | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n,m = inpl()
a = inpl()
a.sort()
bc = [inpl() for _ in range(m)]
bc.sort(key = lambda x:x[1], reverse = True)
lm = sum(x[1] for x in bc)
now = 0
alt = 0
while now < n and alt < m:
c,b = bc[alt]
if a[now] > b:
break
else:
a[now] = b
bc[alt][0] -= 1
if bc[alt][0] == 0:
alt += 1
now += 1
print((sum(a)))
| from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n,m = inpl()
a = inpl()
a.sort()
bc = [inpl() for _ in range(m)]
bc.sort(key=lambda x:x[1], reverse = True)
ind = -1
now = -1
cnt = 0
for i in range(n):
if cnt == 0:
ind += 1
if ind >= m: break
cnt, now = bc[ind]
if a[i] >= now:
break
a[i] = now
cnt -= 1
print((sum(a))) | 29 | 28 | 728 | 687 | from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions, pprint
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n, m = inpl()
a = inpl()
a.sort()
bc = [inpl() for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True)
lm = sum(x[1] for x in bc)
now = 0
alt = 0
while now < n and alt < m:
c, b = bc[alt]
if a[now] > b:
break
else:
a[now] = b
bc[alt][0] -= 1
if bc[alt][0] == 0:
alt += 1
now += 1
print((sum(a)))
| from collections import Counter, defaultdict, deque
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions, pprint
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n, m = inpl()
a = inpl()
a.sort()
bc = [inpl() for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True)
ind = -1
now = -1
cnt = 0
for i in range(n):
if cnt == 0:
ind += 1
if ind >= m:
break
cnt, now = bc[ind]
if a[i] >= now:
break
a[i] = now
cnt -= 1
print((sum(a)))
| false | 3.448276 | [
"-from heapq import heappop, heappush, heapify",
"+from heapq import heappop, heappush",
"-lm = sum(x[1] for x in bc)",
"-now = 0",
"-alt = 0",
"-while now < n and alt < m:",
"- c, b = bc[alt]",
"- if a[now] > b:",
"+ind = -1",
"+now = -1",
"+cnt = 0",
"+for i in range(n):",
"+ if cnt == 0:",
"+ ind += 1",
"+ if ind >= m:",
"+ break",
"+ cnt, now = bc[ind]",
"+ if a[i] >= now:",
"- else:",
"- a[now] = b",
"- bc[alt][0] -= 1",
"- if bc[alt][0] == 0:",
"- alt += 1",
"- now += 1",
"+ a[i] = now",
"+ cnt -= 1"
]
| false | 0.042392 | 0.07197 | 0.589025 | [
"s797826633",
"s729522175"
]
|
u016302627 | p02684 | python | s792127780 | s617451695 | 152 | 104 | 32,280 | 94,196 | Accepted | Accepted | 31.58 | n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
visit = [-1] * n #到達しているかどうかを管理
D = [1] # 循環するもののindexを格納
tmp = A[0] #初期位置
ct = 1
while visit[tmp - 1] == -1:
D.append(tmp)
visit[tmp - 1] = ct #到達済に変更
if k == ct:
print(tmp)
exit()
ct += 1
tmp = A[tmp - 1]
#循環している場合の残りの処理
k -= visit[tmp - 1]
k %= (ct - visit[tmp - 1])
print((D[visit[tmp - 1] + k])) | import sys
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
visit = [-1] * n #到達しているかどうかを管理
D = [1] # 循環するもののindexを格納
tmp = A[0] #初期位置
ct = 1
while visit[tmp - 1] == -1:
D.append(tmp)
visit[tmp - 1] = ct #到達済に変更
if k == ct:
print(tmp)
sys.exit()
ct += 1
tmp = A[tmp - 1]
#循環している場合の残りの処理
k -= visit[tmp - 1]
k %= (ct - visit[tmp - 1])
print((D[visit[tmp - 1] + k])) | 23 | 25 | 435 | 453 | n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
visit = [-1] * n # 到達しているかどうかを管理
D = [1] # 循環するもののindexを格納
tmp = A[0] # 初期位置
ct = 1
while visit[tmp - 1] == -1:
D.append(tmp)
visit[tmp - 1] = ct # 到達済に変更
if k == ct:
print(tmp)
exit()
ct += 1
tmp = A[tmp - 1]
# 循環している場合の残りの処理
k -= visit[tmp - 1]
k %= ct - visit[tmp - 1]
print((D[visit[tmp - 1] + k]))
| import sys
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
visit = [-1] * n # 到達しているかどうかを管理
D = [1] # 循環するもののindexを格納
tmp = A[0] # 初期位置
ct = 1
while visit[tmp - 1] == -1:
D.append(tmp)
visit[tmp - 1] = ct # 到達済に変更
if k == ct:
print(tmp)
sys.exit()
ct += 1
tmp = A[tmp - 1]
# 循環している場合の残りの処理
k -= visit[tmp - 1]
k %= ct - visit[tmp - 1]
print((D[visit[tmp - 1] + k]))
| false | 8 | [
"+import sys",
"+",
"- exit()",
"+ sys.exit()"
]
| false | 0.042486 | 0.041556 | 1.022376 | [
"s792127780",
"s617451695"
]
|
u279460955 | p02904 | python | s110964169 | s124048511 | 247 | 222 | 103,560 | 103,684 | Accepted | Accepted | 10.12 | class SegTree: # 0-index !!!
"""
fx: モノイドXでの二項演算
ex: モノイドXでの単位元
init(seq, fx, ex): 配列seqで初期化 O(N)
update(i, x): i番目の値をxに更新 O(logN)
query(l, r): 区間[l,r)をfxしたものを返す O(logN)
get(i): i番目の値を返す
show(): 配列を返す
"""
def __init__(self, seq, fx, ex):
self.n = len(seq)
self.fx = fx
self.ex = ex
self.size = 1<<(self.n - 1).bit_length()
self.tree = [ex] * (self.size * 2)
# build
for i, x in enumerate(seq, start=self.size):
self.tree[i] = x
for i in reversed(list(range(1, self.size))):
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def set(self, i, x): # O(log(n))
i += self.size
self.tree[i] = x
while i:
i >>= 1
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def update(self, i, x):
i += self.size
self.tree[i] = x
while i > 1:
i >>= 1
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def query(self, l, r): # l = r の場合はたぶんバグるので注意
tmp_l = self.ex
tmp_r = self.ex
l += self.size
r += self.size
while l < r:
if l & 1:
tmp_l = self.fx(tmp_l, self.tree[l])
l += 1
if r & 1:
tmp_r = self.fx(self.tree[r - 1], tmp_r) # 交換法則を仮定しない(順序大事に)
l >>= 1
r >>= 1
return self.fx(tmp_l, tmp_r)
def get(self, i):
return self.tree[self.size + i]
def show(self):
return self.tree[self.size: self.size + self.n]
# ---------------------- #
n, k = (int(x) for x in input().split())
P = list(int(x) for x in input().split())
min_seg = SegTree(P, fx=min, ex=10**18)
max_seg = SegTree(P, fx=max, ex=0)
asc_count = [1] * n
for i in range(1, n):
if P[i] > P[i - 1]:
asc_count[i] = asc_count[i - 1] + 1
ans = 0
no_count = 0
min_out_flag = False
for i in range(n - k + 1):
if not min_out_flag or P[i + k - 1] != max_seg.query(i, i + k):
ans += 1
if asc_count[i + k - 1] >= k:
no_count += 1
if P[i] == min_seg.query(i, i + k):
min_out_flag = True
else:
min_out_flag = False
print((ans - max(no_count - 1, 0)))
| class SegTree: # 0-index !!!
def __init__(self, seq, fx, ex):
self.n = len(seq)
self.fx = fx
self.ex = ex
self.size = 1<<(self.n - 1).bit_length()
self.tree = [ex] * (self.size * 2)
# build
for i, x in enumerate(seq, start=self.size):
self.tree[i] = x
for i in reversed(list(range(1, self.size))):
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def update(self, i, x):
i += self.size
self.tree[i] = x
while i > 1:
i >>= 1
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def query(self, l, r):
tmp_l = self.ex
tmp_r = self.ex
l += self.size
r += self.size
while l < r:
if l & 1:
tmp_l = self.fx(tmp_l, self.tree[l])
l += 1
if r & 1:
tmp_r = self.fx(self.tree[r - 1], tmp_r) # 交換法則を仮定しない(順序大事に)
l >>= 1
r >>= 1
return self.fx(tmp_l, tmp_r)
# ---------------------- #
n, k = (int(x) for x in input().split())
P = list(int(x) for x in input().split())
min_seg = SegTree(P, fx=min, ex=10**18)
max_seg = SegTree(P, fx=max, ex=0)
asc_count = [1] * n
for i in range(1, n):
if P[i] > P[i - 1]:
asc_count[i] = asc_count[i - 1] + 1
ans = 1
no_count = 0
if asc_count[k - 1] >= k:
no_count += 1
for i in range(1, n - k + 1):
if P[i - 1] != min_seg.query(i - 1, i + k - 1) or P[i + k - 1] != max_seg.query(i, i + k):
ans += 1
if asc_count[i + k - 1] >= k:
no_count += 1
print((ans - max(no_count - 1, 0)))
| 84 | 59 | 2,377 | 1,723 | class SegTree: # 0-index !!!
"""
fx: モノイドXでの二項演算
ex: モノイドXでの単位元
init(seq, fx, ex): 配列seqで初期化 O(N)
update(i, x): i番目の値をxに更新 O(logN)
query(l, r): 区間[l,r)をfxしたものを返す O(logN)
get(i): i番目の値を返す
show(): 配列を返す
"""
def __init__(self, seq, fx, ex):
self.n = len(seq)
self.fx = fx
self.ex = ex
self.size = 1 << (self.n - 1).bit_length()
self.tree = [ex] * (self.size * 2)
# build
for i, x in enumerate(seq, start=self.size):
self.tree[i] = x
for i in reversed(list(range(1, self.size))):
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def set(self, i, x): # O(log(n))
i += self.size
self.tree[i] = x
while i:
i >>= 1
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def update(self, i, x):
i += self.size
self.tree[i] = x
while i > 1:
i >>= 1
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def query(self, l, r): # l = r の場合はたぶんバグるので注意
tmp_l = self.ex
tmp_r = self.ex
l += self.size
r += self.size
while l < r:
if l & 1:
tmp_l = self.fx(tmp_l, self.tree[l])
l += 1
if r & 1:
tmp_r = self.fx(self.tree[r - 1], tmp_r) # 交換法則を仮定しない(順序大事に)
l >>= 1
r >>= 1
return self.fx(tmp_l, tmp_r)
def get(self, i):
return self.tree[self.size + i]
def show(self):
return self.tree[self.size : self.size + self.n]
# ---------------------- #
n, k = (int(x) for x in input().split())
P = list(int(x) for x in input().split())
min_seg = SegTree(P, fx=min, ex=10**18)
max_seg = SegTree(P, fx=max, ex=0)
asc_count = [1] * n
for i in range(1, n):
if P[i] > P[i - 1]:
asc_count[i] = asc_count[i - 1] + 1
ans = 0
no_count = 0
min_out_flag = False
for i in range(n - k + 1):
if not min_out_flag or P[i + k - 1] != max_seg.query(i, i + k):
ans += 1
if asc_count[i + k - 1] >= k:
no_count += 1
if P[i] == min_seg.query(i, i + k):
min_out_flag = True
else:
min_out_flag = False
print((ans - max(no_count - 1, 0)))
| class SegTree: # 0-index !!!
def __init__(self, seq, fx, ex):
self.n = len(seq)
self.fx = fx
self.ex = ex
self.size = 1 << (self.n - 1).bit_length()
self.tree = [ex] * (self.size * 2)
# build
for i, x in enumerate(seq, start=self.size):
self.tree[i] = x
for i in reversed(list(range(1, self.size))):
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def update(self, i, x):
i += self.size
self.tree[i] = x
while i > 1:
i >>= 1
self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])
def query(self, l, r):
tmp_l = self.ex
tmp_r = self.ex
l += self.size
r += self.size
while l < r:
if l & 1:
tmp_l = self.fx(tmp_l, self.tree[l])
l += 1
if r & 1:
tmp_r = self.fx(self.tree[r - 1], tmp_r) # 交換法則を仮定しない(順序大事に)
l >>= 1
r >>= 1
return self.fx(tmp_l, tmp_r)
# ---------------------- #
n, k = (int(x) for x in input().split())
P = list(int(x) for x in input().split())
min_seg = SegTree(P, fx=min, ex=10**18)
max_seg = SegTree(P, fx=max, ex=0)
asc_count = [1] * n
for i in range(1, n):
if P[i] > P[i - 1]:
asc_count[i] = asc_count[i - 1] + 1
ans = 1
no_count = 0
if asc_count[k - 1] >= k:
no_count += 1
for i in range(1, n - k + 1):
if P[i - 1] != min_seg.query(i - 1, i + k - 1) or P[i + k - 1] != max_seg.query(
i, i + k
):
ans += 1
if asc_count[i + k - 1] >= k:
no_count += 1
print((ans - max(no_count - 1, 0)))
| false | 29.761905 | [
"- \"\"\"",
"- fx: モノイドXでの二項演算",
"- ex: モノイドXでの単位元",
"- init(seq, fx, ex): 配列seqで初期化 O(N)",
"- update(i, x): i番目の値をxに更新 O(logN)",
"- query(l, r): 区間[l,r)をfxしたものを返す O(logN)",
"- get(i): i番目の値を返す",
"- show(): 配列を返す",
"- \"\"\"",
"-",
"- def set(self, i, x): # O(log(n))",
"- i += self.size",
"- self.tree[i] = x",
"- while i:",
"- i >>= 1",
"- self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])",
"-",
"- def query(self, l, r): # l = r の場合はたぶんバグるので注意",
"+ def query(self, l, r):",
"- def get(self, i):",
"- return self.tree[self.size + i]",
"-",
"- def show(self):",
"- return self.tree[self.size : self.size + self.n]",
"-",
"-ans = 0",
"+ans = 1",
"-min_out_flag = False",
"-for i in range(n - k + 1):",
"- if not min_out_flag or P[i + k - 1] != max_seg.query(i, i + k):",
"+if asc_count[k - 1] >= k:",
"+ no_count += 1",
"+for i in range(1, n - k + 1):",
"+ if P[i - 1] != min_seg.query(i - 1, i + k - 1) or P[i + k - 1] != max_seg.query(",
"+ i, i + k",
"+ ):",
"- if P[i] == min_seg.query(i, i + k):",
"- min_out_flag = True",
"- else:",
"- min_out_flag = False"
]
| false | 0.05937 | 0.037493 | 1.583499 | [
"s110964169",
"s124048511"
]
|
u102461423 | p02956 | python | s186881598 | s654842799 | 1,840 | 979 | 74,684 | 178,216 | Accepted | Accepted | 46.79 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 998244353
N = int(readline())
m = list(map(int,read().split()))
Y = [y for x,y in sorted(zip(m,m))] # Y座標昇順
# 座圧
Y_rank = {y:i for i,y in enumerate(sorted(Y),1)}
Y = [Y_rank[y] for y in Y]
class BIT():
def __init__(self, max_n):
self.size = max_n + 1
self.tree = [0] * self.size
def get_sum(self,i):
s = 0
while i:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i < self.size:
self.tree[i] += x
i += i & -i
LD = [0] * N
bit = BIT(N)
for i,y in enumerate(Y):
LD[i] = bit.get_sum(y)
bit.add(y,1)
def cumprod(arr,MOD):
L = len(arr); Lsq = int(L**.5+1)
arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
for n in range(1,Lsq):
arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
for n in range(1,Lsq):
arr[n] *= arr[n-1,-1]; arr[n] %= MOD
return arr.ravel()[:L]
x = np.full(N+10,2,np.int64); x[0] = 1
pow2 = cumprod(x,MOD)
LD = np.array(LD,dtype=np.int32)
D = np.array(Y)-1
L = np.arange(N)
R = N-1-L
U = N-1-D
LU = L-LD
RU = U-LU
RD = D-LD
x = pow2[N] - 1 + pow2[LD] + pow2[RD] + pow2[RU] + pow2[LU]
x -= pow2[U] + pow2[D] + pow2[R] + pow2[L]
answer = x.sum() % MOD
print(answer) | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 998244353
N = int(eval(input()))
XY = [[int(x) for x in input().split()] for _ in range(N)]
XY.sort() # X ascending
X,Y = list(zip(*XY))
Y_rank = {x:i for i,x in enumerate(sorted(Y),1)}
def BIT_update(tree,x):
while x <= N:
tree[x] += 1
x += x & (-x)
def BIT_sum(tree,x):
ret = 0
while x:
ret += tree[x]
x -= x & (-x)
return ret
pow2 = [1]
for _ in range(N):
pow2.append(pow2[-1] * 2 % MOD)
answer = 0
tree = [0] * (N+1)
for L,(x,y) in enumerate(XY):
y = Y_rank[y]
R = N - 1 - L
D = y - 1
U = N - 1 - D
LD = BIT_sum(tree,y)
BIT_update(tree,y)
LU = L - LD
RD = D - LD
RU = R - RD
# bounding box が自分自身を含むような集合を数える
# 全体から引く
cnt = pow2[N]
cnt -= pow2[L]
cnt -= pow2[R]
cnt -= pow2[D]
cnt -= pow2[U]
cnt += pow2[LD]
cnt += pow2[LU]
cnt += pow2[RD]
cnt += pow2[RU]
cnt -= 1
answer += cnt
answer %= MOD
print(answer)
| 66 | 57 | 1,451 | 1,077 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 998244353
N = int(readline())
m = list(map(int, read().split()))
Y = [y for x, y in sorted(zip(m, m))] # Y座標昇順
# 座圧
Y_rank = {y: i for i, y in enumerate(sorted(Y), 1)}
Y = [Y_rank[y] for y in Y]
class BIT:
def __init__(self, max_n):
self.size = max_n + 1
self.tree = [0] * self.size
def get_sum(self, i):
s = 0
while i:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i < self.size:
self.tree[i] += x
i += i & -i
LD = [0] * N
bit = BIT(N)
for i, y in enumerate(Y):
LD[i] = bit.get_sum(y)
bit.add(y, 1)
def cumprod(arr, MOD):
L = len(arr)
Lsq = int(L**0.5 + 1)
arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
for n in range(1, Lsq):
arr[:, n] *= arr[:, n - 1]
arr[:, n] %= MOD
for n in range(1, Lsq):
arr[n] *= arr[n - 1, -1]
arr[n] %= MOD
return arr.ravel()[:L]
x = np.full(N + 10, 2, np.int64)
x[0] = 1
pow2 = cumprod(x, MOD)
LD = np.array(LD, dtype=np.int32)
D = np.array(Y) - 1
L = np.arange(N)
R = N - 1 - L
U = N - 1 - D
LU = L - LD
RU = U - LU
RD = D - LD
x = pow2[N] - 1 + pow2[LD] + pow2[RD] + pow2[RU] + pow2[LU]
x -= pow2[U] + pow2[D] + pow2[R] + pow2[L]
answer = x.sum() % MOD
print(answer)
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
MOD = 998244353
N = int(eval(input()))
XY = [[int(x) for x in input().split()] for _ in range(N)]
XY.sort() # X ascending
X, Y = list(zip(*XY))
Y_rank = {x: i for i, x in enumerate(sorted(Y), 1)}
def BIT_update(tree, x):
while x <= N:
tree[x] += 1
x += x & (-x)
def BIT_sum(tree, x):
ret = 0
while x:
ret += tree[x]
x -= x & (-x)
return ret
pow2 = [1]
for _ in range(N):
pow2.append(pow2[-1] * 2 % MOD)
answer = 0
tree = [0] * (N + 1)
for L, (x, y) in enumerate(XY):
y = Y_rank[y]
R = N - 1 - L
D = y - 1
U = N - 1 - D
LD = BIT_sum(tree, y)
BIT_update(tree, y)
LU = L - LD
RD = D - LD
RU = R - RD
# bounding box が自分自身を含むような集合を数える
# 全体から引く
cnt = pow2[N]
cnt -= pow2[L]
cnt -= pow2[R]
cnt -= pow2[D]
cnt -= pow2[U]
cnt += pow2[LD]
cnt += pow2[LU]
cnt += pow2[RD]
cnt += pow2[RU]
cnt -= 1
answer += cnt
answer %= MOD
print(answer)
| false | 13.636364 | [
"-read = sys.stdin.buffer.read",
"-readline = sys.stdin.buffer.readline",
"-readlines = sys.stdin.buffer.readlines",
"-import numpy as np",
"-",
"+input = sys.stdin.readline",
"+sys.setrecursionlimit(10**7)",
"-N = int(readline())",
"-m = list(map(int, read().split()))",
"-Y = [y for x, y in sorted(zip(m, m))] # Y座標昇順",
"-# 座圧",
"-Y_rank = {y: i for i, y in enumerate(sorted(Y), 1)}",
"-Y = [Y_rank[y] for y in Y]",
"+N = int(eval(input()))",
"+XY = [[int(x) for x in input().split()] for _ in range(N)]",
"+XY.sort() # X ascending",
"+X, Y = list(zip(*XY))",
"+Y_rank = {x: i for i, x in enumerate(sorted(Y), 1)}",
"-class BIT:",
"- def __init__(self, max_n):",
"- self.size = max_n + 1",
"- self.tree = [0] * self.size",
"-",
"- def get_sum(self, i):",
"- s = 0",
"- while i:",
"- s += self.tree[i]",
"- i -= i & -i",
"- return s",
"-",
"- def add(self, i, x):",
"- while i < self.size:",
"- self.tree[i] += x",
"- i += i & -i",
"+def BIT_update(tree, x):",
"+ while x <= N:",
"+ tree[x] += 1",
"+ x += x & (-x)",
"-LD = [0] * N",
"-bit = BIT(N)",
"-for i, y in enumerate(Y):",
"- LD[i] = bit.get_sum(y)",
"- bit.add(y, 1)",
"+def BIT_sum(tree, x):",
"+ ret = 0",
"+ while x:",
"+ ret += tree[x]",
"+ x -= x & (-x)",
"+ return ret",
"-def cumprod(arr, MOD):",
"- L = len(arr)",
"- Lsq = int(L**0.5 + 1)",
"- arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)",
"- for n in range(1, Lsq):",
"- arr[:, n] *= arr[:, n - 1]",
"- arr[:, n] %= MOD",
"- for n in range(1, Lsq):",
"- arr[n] *= arr[n - 1, -1]",
"- arr[n] %= MOD",
"- return arr.ravel()[:L]",
"-",
"-",
"-x = np.full(N + 10, 2, np.int64)",
"-x[0] = 1",
"-pow2 = cumprod(x, MOD)",
"-LD = np.array(LD, dtype=np.int32)",
"-D = np.array(Y) - 1",
"-L = np.arange(N)",
"-R = N - 1 - L",
"-U = N - 1 - D",
"-LU = L - LD",
"-RU = U - LU",
"-RD = D - LD",
"-x = pow2[N] - 1 + pow2[LD] + pow2[RD] + pow2[RU] + pow2[LU]",
"-x -= pow2[U] + pow2[D] + pow2[R] + pow2[L]",
"-answer = x.sum() % MOD",
"+pow2 = [1]",
"+for _ in range(N):",
"+ pow2.append(pow2[-1] * 2 % MOD)",
"+answer = 0",
"+tree = [0] * (N + 1)",
"+for L, (x, y) in enumerate(XY):",
"+ y = Y_rank[y]",
"+ R = N - 1 - L",
"+ D = y - 1",
"+ U = N - 1 - D",
"+ LD = BIT_sum(tree, y)",
"+ BIT_update(tree, y)",
"+ LU = L - LD",
"+ RD = D - LD",
"+ RU = R - RD",
"+ # bounding box が自分自身を含むような集合を数える",
"+ # 全体から引く",
"+ cnt = pow2[N]",
"+ cnt -= pow2[L]",
"+ cnt -= pow2[R]",
"+ cnt -= pow2[D]",
"+ cnt -= pow2[U]",
"+ cnt += pow2[LD]",
"+ cnt += pow2[LU]",
"+ cnt += pow2[RD]",
"+ cnt += pow2[RU]",
"+ cnt -= 1",
"+ answer += cnt",
"+answer %= MOD"
]
| false | 0.365962 | 0.037911 | 9.653302 | [
"s186881598",
"s654842799"
]
|
u476590491 | p02579 | python | s715939809 | s564473313 | 1,365 | 1,062 | 202,092 | 182,884 | Accepted | Accepted | 22.2 | # -*- coding: utf-8 -*-
from collections import deque
q = deque()
h, w = list(map(int, input().split()))
ch, cw = list(map(int, input().split()))
dh, dw = list(map(int, input().split()))
ch -= 1
cw -= 1
dh -= 1
dw -= 1
# mylist = [[]]
ban_list = [[-1 for j in range(w)] for i in range(h)]
cost_list = [[-1 for j in range(w)] for i in range(h)]
# print(mylist)
for i in range(h):
# 文字列の入力
s = eval(input())
for j in range(len(s)):
ban_list[i][j] = s[j]
ban_list[ch][cw] = 0
# cost_list[ch][cw] = 0
cost = 0
ph = ch
pw = cw
q.append([ph, pw])
# # 最後デバッグ
# for li in ban_list:
# print(li)
loop = True
while loop:
# print(len(q))
ph, pw = q.popleft()
cost = ban_list[ph][pw]
# print(ph, pw)
# print(cost)
# 上
if ph == 0:
pass
else:
if ban_list[ph-1][pw] != "#" and ban_list[ph-1][pw] != cost:
if ban_list[ph-1][pw] == "." or cost < ban_list[ph-1][pw]:
ban_list[ph-1][pw] = cost
# appendだとrandom_02.txtがWAになる
q.appendleft([ph-1, pw])
else:
pass
# 右
if pw == w -1:
pass
else:
if ban_list[ph][pw + 1] != "#" and ban_list[ph][pw + 1] != cost:
if ban_list[ph][pw + 1] == "." or cost < ban_list[ph][pw + 1]:
ban_list[ph][pw + 1] = cost
q.appendleft([ph, pw+1])
else:
pass
# 下
if ph == h -1:
pass
else:
if ban_list[ph+1][pw] != "#" and ban_list[ph+1][pw] != cost:
if ban_list[ph+1][pw] == "." or cost < ban_list[ph+1][pw]:
ban_list[ph+1][pw] = cost
q.appendleft([ph+1, pw])
else:
pass
# 左
if pw == 0:
pass
else:
if ban_list[ph][pw - 1] != "#" and ban_list[ph][pw - 1] != cost:
if ban_list[ph][pw - 1] == "." or cost < ban_list[ph][pw - 1]:
ban_list[ph][pw - 1] = cost
q.appendleft([ph, pw-1])
else:
pass
# ジャンプ--------------
for i in range(-2, 3):
if (ph + i < 0) or (h - 1 < ph + i):
continue
for j in range(-2, 3):
if (pw + j < 0) or (w - 1 < pw + j) or (i==0 and j == 0) or (i==0 and j == -1) or (i==0 and j == 1) or (i==-1 and j == 0) or (i==1 and j == 0):
continue
if ban_list[ph + i][pw + j] == ".":
# print(ph, pw)
# print(i, j)
# print(cost)
ban_list[ph + i][pw + j] = cost + 1
q.append([ph + i, pw + j])
if len(q) == 0:
loop = False
result = ban_list[dh][dw]
if result == ".":
result = -1
# # 最後デバッグ
# for li in ban_list:
# print(li)
print(result)
| # -*- coding: utf-8 -*-
from collections import deque
q = deque()
h, w = list(map(int, input().split()))
ch, cw = list(map(int, input().split()))
dh, dw = list(map(int, input().split()))
ch -= 1
cw -= 1
dh -= 1
dw -= 1
ban_list = [[-999 for j in range(w)] for i in range(h)]
for i in range(h):
# 文字列の入力
s = eval(input())
for j in range(len(s)):
ban_list[i][j] = s[j]
ban_list[ch][cw] = 0
cost = 0
ph = ch
pw = cw
q.append([ph, pw])
# 上右下左
ido_h = [-1, 0, 1, 0]
ido_w = [0, 1, 0, -1]
while q:
ph, pw = q.popleft()
cost = ban_list[ph][pw]
for i in range(4):
nh = ph + ido_h[i]
nw = pw + ido_w[i]
if nh < 0 or h -1 < nh or nw < 0 or w -1 < nw:
continue
val = ban_list[nh][nw]
if val == "#" or val == cost:
continue
if val == "." or cost < val:
ban_list[nh][nw] = cost
q.appendleft([nh, nw])
# # 上
# if ph == 0:
# pass
# else:
# if ban_list[ph-1][pw] != "#" and ban_list[ph-1][pw] != cost:
# if ban_list[ph-1][pw] == "." or cost < ban_list[ph-1][pw]:
# ban_list[ph-1][pw] = cost
# # appendだとrandom_02.txtがWAになる
# q.appendleft([ph-1, pw])
# else:
# pass
# # 右
# if pw == w -1:
# pass
# else:
# if ban_list[ph][pw + 1] != "#" and ban_list[ph][pw + 1] != cost:
# if ban_list[ph][pw + 1] == "." or cost < ban_list[ph][pw + 1]:
# ban_list[ph][pw + 1] = cost
# q.appendleft([ph, pw+1])
# else:
# pass
# # 下
# if ph == h -1:
# pass
# else:
# if ban_list[ph+1][pw] != "#" and ban_list[ph+1][pw] != cost:
# if ban_list[ph+1][pw] == "." or cost < ban_list[ph+1][pw]:
# ban_list[ph+1][pw] = cost
# q.appendleft([ph+1, pw])
# else:
# pass
# # 左
# if pw == 0:
# pass
# else:
# if ban_list[ph][pw - 1] != "#" and ban_list[ph][pw - 1] != cost:
# if ban_list[ph][pw - 1] == "." or cost < ban_list[ph][pw - 1]:
# ban_list[ph][pw - 1] = cost
# q.appendleft([ph, pw-1])
# else:
# pass
# ジャンプ--------------
for i in range(-2, 3):
if (ph + i < 0) or (h - 1 < ph + i):
continue
for j in range(-2, 3):
if (pw + j < 0) or (w - 1 < pw + j) or (i==0 and j == 0) or (i==0 and j == -1) or (i==0 and j == 1) or (i==-1 and j == 0) or (i==1 and j == 0):
continue
if ban_list[ph + i][pw + j] == ".":
ban_list[ph + i][pw + j] = cost + 1
q.append([ph + i, pw + j])
result = ban_list[dh][dw]
if result == ".":
result = -1
print(result)
| 125 | 121 | 2,575 | 2,633 | # -*- coding: utf-8 -*-
from collections import deque
q = deque()
h, w = list(map(int, input().split()))
ch, cw = list(map(int, input().split()))
dh, dw = list(map(int, input().split()))
ch -= 1
cw -= 1
dh -= 1
dw -= 1
# mylist = [[]]
ban_list = [[-1 for j in range(w)] for i in range(h)]
cost_list = [[-1 for j in range(w)] for i in range(h)]
# print(mylist)
for i in range(h):
# 文字列の入力
s = eval(input())
for j in range(len(s)):
ban_list[i][j] = s[j]
ban_list[ch][cw] = 0
# cost_list[ch][cw] = 0
cost = 0
ph = ch
pw = cw
q.append([ph, pw])
# # 最後デバッグ
# for li in ban_list:
# print(li)
loop = True
while loop:
# print(len(q))
ph, pw = q.popleft()
cost = ban_list[ph][pw]
# print(ph, pw)
# print(cost)
# 上
if ph == 0:
pass
else:
if ban_list[ph - 1][pw] != "#" and ban_list[ph - 1][pw] != cost:
if ban_list[ph - 1][pw] == "." or cost < ban_list[ph - 1][pw]:
ban_list[ph - 1][pw] = cost
# appendだとrandom_02.txtがWAになる
q.appendleft([ph - 1, pw])
else:
pass
# 右
if pw == w - 1:
pass
else:
if ban_list[ph][pw + 1] != "#" and ban_list[ph][pw + 1] != cost:
if ban_list[ph][pw + 1] == "." or cost < ban_list[ph][pw + 1]:
ban_list[ph][pw + 1] = cost
q.appendleft([ph, pw + 1])
else:
pass
# 下
if ph == h - 1:
pass
else:
if ban_list[ph + 1][pw] != "#" and ban_list[ph + 1][pw] != cost:
if ban_list[ph + 1][pw] == "." or cost < ban_list[ph + 1][pw]:
ban_list[ph + 1][pw] = cost
q.appendleft([ph + 1, pw])
else:
pass
# 左
if pw == 0:
pass
else:
if ban_list[ph][pw - 1] != "#" and ban_list[ph][pw - 1] != cost:
if ban_list[ph][pw - 1] == "." or cost < ban_list[ph][pw - 1]:
ban_list[ph][pw - 1] = cost
q.appendleft([ph, pw - 1])
else:
pass
# ジャンプ--------------
for i in range(-2, 3):
if (ph + i < 0) or (h - 1 < ph + i):
continue
for j in range(-2, 3):
if (
(pw + j < 0)
or (w - 1 < pw + j)
or (i == 0 and j == 0)
or (i == 0 and j == -1)
or (i == 0 and j == 1)
or (i == -1 and j == 0)
or (i == 1 and j == 0)
):
continue
if ban_list[ph + i][pw + j] == ".":
# print(ph, pw)
# print(i, j)
# print(cost)
ban_list[ph + i][pw + j] = cost + 1
q.append([ph + i, pw + j])
if len(q) == 0:
loop = False
result = ban_list[dh][dw]
if result == ".":
result = -1
# # 最後デバッグ
# for li in ban_list:
# print(li)
print(result)
| # -*- coding: utf-8 -*-
from collections import deque
q = deque()
h, w = list(map(int, input().split()))
ch, cw = list(map(int, input().split()))
dh, dw = list(map(int, input().split()))
ch -= 1
cw -= 1
dh -= 1
dw -= 1
ban_list = [[-999 for j in range(w)] for i in range(h)]
for i in range(h):
# 文字列の入力
s = eval(input())
for j in range(len(s)):
ban_list[i][j] = s[j]
ban_list[ch][cw] = 0
cost = 0
ph = ch
pw = cw
q.append([ph, pw])
# 上右下左
ido_h = [-1, 0, 1, 0]
ido_w = [0, 1, 0, -1]
while q:
ph, pw = q.popleft()
cost = ban_list[ph][pw]
for i in range(4):
nh = ph + ido_h[i]
nw = pw + ido_w[i]
if nh < 0 or h - 1 < nh or nw < 0 or w - 1 < nw:
continue
val = ban_list[nh][nw]
if val == "#" or val == cost:
continue
if val == "." or cost < val:
ban_list[nh][nw] = cost
q.appendleft([nh, nw])
# # 上
# if ph == 0:
# pass
# else:
# if ban_list[ph-1][pw] != "#" and ban_list[ph-1][pw] != cost:
# if ban_list[ph-1][pw] == "." or cost < ban_list[ph-1][pw]:
# ban_list[ph-1][pw] = cost
# # appendだとrandom_02.txtがWAになる
# q.appendleft([ph-1, pw])
# else:
# pass
# # 右
# if pw == w -1:
# pass
# else:
# if ban_list[ph][pw + 1] != "#" and ban_list[ph][pw + 1] != cost:
# if ban_list[ph][pw + 1] == "." or cost < ban_list[ph][pw + 1]:
# ban_list[ph][pw + 1] = cost
# q.appendleft([ph, pw+1])
# else:
# pass
# # 下
# if ph == h -1:
# pass
# else:
# if ban_list[ph+1][pw] != "#" and ban_list[ph+1][pw] != cost:
# if ban_list[ph+1][pw] == "." or cost < ban_list[ph+1][pw]:
# ban_list[ph+1][pw] = cost
# q.appendleft([ph+1, pw])
# else:
# pass
# # 左
# if pw == 0:
# pass
# else:
# if ban_list[ph][pw - 1] != "#" and ban_list[ph][pw - 1] != cost:
# if ban_list[ph][pw - 1] == "." or cost < ban_list[ph][pw - 1]:
# ban_list[ph][pw - 1] = cost
# q.appendleft([ph, pw-1])
# else:
# pass
# ジャンプ--------------
for i in range(-2, 3):
if (ph + i < 0) or (h - 1 < ph + i):
continue
for j in range(-2, 3):
if (
(pw + j < 0)
or (w - 1 < pw + j)
or (i == 0 and j == 0)
or (i == 0 and j == -1)
or (i == 0 and j == 1)
or (i == -1 and j == 0)
or (i == 1 and j == 0)
):
continue
if ban_list[ph + i][pw + j] == ".":
ban_list[ph + i][pw + j] = cost + 1
q.append([ph + i, pw + j])
result = ban_list[dh][dw]
if result == ".":
result = -1
print(result)
| false | 3.2 | [
"-# mylist = [[]]",
"-ban_list = [[-1 for j in range(w)] for i in range(h)]",
"-cost_list = [[-1 for j in range(w)] for i in range(h)]",
"-# print(mylist)",
"+ban_list = [[-999 for j in range(w)] for i in range(h)]",
"-# cost_list[ch][cw] = 0",
"-# # 最後デバッグ",
"-# for li in ban_list:",
"-# print(li)",
"-loop = True",
"-while loop:",
"- # print(len(q))",
"+# 上右下左",
"+ido_h = [-1, 0, 1, 0]",
"+ido_w = [0, 1, 0, -1]",
"+while q:",
"- # print(ph, pw)",
"- # print(cost)",
"- # 上",
"- if ph == 0:",
"- pass",
"- else:",
"- if ban_list[ph - 1][pw] != \"#\" and ban_list[ph - 1][pw] != cost:",
"- if ban_list[ph - 1][pw] == \".\" or cost < ban_list[ph - 1][pw]:",
"- ban_list[ph - 1][pw] = cost",
"- # appendだとrandom_02.txtがWAになる",
"- q.appendleft([ph - 1, pw])",
"- else:",
"- pass",
"- # 右",
"- if pw == w - 1:",
"- pass",
"- else:",
"- if ban_list[ph][pw + 1] != \"#\" and ban_list[ph][pw + 1] != cost:",
"- if ban_list[ph][pw + 1] == \".\" or cost < ban_list[ph][pw + 1]:",
"- ban_list[ph][pw + 1] = cost",
"- q.appendleft([ph, pw + 1])",
"- else:",
"- pass",
"- # 下",
"- if ph == h - 1:",
"- pass",
"- else:",
"- if ban_list[ph + 1][pw] != \"#\" and ban_list[ph + 1][pw] != cost:",
"- if ban_list[ph + 1][pw] == \".\" or cost < ban_list[ph + 1][pw]:",
"- ban_list[ph + 1][pw] = cost",
"- q.appendleft([ph + 1, pw])",
"- else:",
"- pass",
"- # 左",
"- if pw == 0:",
"- pass",
"- else:",
"- if ban_list[ph][pw - 1] != \"#\" and ban_list[ph][pw - 1] != cost:",
"- if ban_list[ph][pw - 1] == \".\" or cost < ban_list[ph][pw - 1]:",
"- ban_list[ph][pw - 1] = cost",
"- q.appendleft([ph, pw - 1])",
"- else:",
"- pass",
"+ for i in range(4):",
"+ nh = ph + ido_h[i]",
"+ nw = pw + ido_w[i]",
"+ if nh < 0 or h - 1 < nh or nw < 0 or w - 1 < nw:",
"+ continue",
"+ val = ban_list[nh][nw]",
"+ if val == \"#\" or val == cost:",
"+ continue",
"+ if val == \".\" or cost < val:",
"+ ban_list[nh][nw] = cost",
"+ q.appendleft([nh, nw])",
"+ # # 上",
"+ # if ph == 0:",
"+ # pass",
"+ # else:",
"+ # if ban_list[ph-1][pw] != \"#\" and ban_list[ph-1][pw] != cost:",
"+ # if ban_list[ph-1][pw] == \".\" or cost < ban_list[ph-1][pw]:",
"+ # ban_list[ph-1][pw] = cost",
"+ # # appendだとrandom_02.txtがWAになる",
"+ # q.appendleft([ph-1, pw])",
"+ # else:",
"+ # pass",
"+ # # 右",
"+ # if pw == w -1:",
"+ # pass",
"+ # else:",
"+ # if ban_list[ph][pw + 1] != \"#\" and ban_list[ph][pw + 1] != cost:",
"+ # if ban_list[ph][pw + 1] == \".\" or cost < ban_list[ph][pw + 1]:",
"+ # ban_list[ph][pw + 1] = cost",
"+ # q.appendleft([ph, pw+1])",
"+ # else:",
"+ # pass",
"+ # # 下",
"+ # if ph == h -1:",
"+ # pass",
"+ # else:",
"+ # if ban_list[ph+1][pw] != \"#\" and ban_list[ph+1][pw] != cost:",
"+ # if ban_list[ph+1][pw] == \".\" or cost < ban_list[ph+1][pw]:",
"+ # ban_list[ph+1][pw] = cost",
"+ # q.appendleft([ph+1, pw])",
"+ # else:",
"+ # pass",
"+ # # 左",
"+ # if pw == 0:",
"+ # pass",
"+ # else:",
"+ # if ban_list[ph][pw - 1] != \"#\" and ban_list[ph][pw - 1] != cost:",
"+ # if ban_list[ph][pw - 1] == \".\" or cost < ban_list[ph][pw - 1]:",
"+ # ban_list[ph][pw - 1] = cost",
"+ # q.appendleft([ph, pw-1])",
"+ # else:",
"+ # pass",
"- # print(ph, pw)",
"- # print(i, j)",
"- # print(cost)",
"- if len(q) == 0:",
"- loop = False",
"-# # 最後デバッグ",
"-# for li in ban_list:",
"-# print(li)"
]
| false | 0.072879 | 0.082036 | 0.888375 | [
"s715939809",
"s564473313"
]
|
u203843959 | p02689 | python | s408905960 | s059299090 | 496 | 371 | 46,008 | 45,228 | Accepted | Accepted | 25.2 | N,M=list(map(int,input().split()))
hlist=list(map(int,input().split()))
graph=[set() for _ in range(N+1)]
for _ in range(M):
a,b=list(map(int,input().split()))
graph[a].add(b)
graph[b].add(a)
#print(graph)
high_list=[0]*(N+1)
for i in range(1,N+1):
if high_list[i]==-1:
continue
h=hlist[i-1]
for s in graph[i]:
if h<=hlist[s-1]:
high_list[i]=-1
if h>=hlist[s-1]:
high_list[s]=-1
if high_list[i]==0:
high_list[i]=1
answer=0
for i in range(1,N+1):
if high_list[i]==1:
#print(i)
answer+=1
print(answer) | N,M=list(map(int,input().split()))
hlist=list(map(int,input().split()))
graph=[set() for _ in range(N+1)]
for _ in range(M):
a,b=list(map(int,input().split()))
graph[a].add(b)
graph[b].add(a)
#print(graph)
answer=0
for i in range(1,N+1):
h=hlist[i-1]
for s in graph[i]:
if h<=hlist[s-1]:
break
else:
answer+=1
print(answer) | 32 | 20 | 585 | 359 | N, M = list(map(int, input().split()))
hlist = list(map(int, input().split()))
graph = [set() for _ in range(N + 1)]
for _ in range(M):
a, b = list(map(int, input().split()))
graph[a].add(b)
graph[b].add(a)
# print(graph)
high_list = [0] * (N + 1)
for i in range(1, N + 1):
if high_list[i] == -1:
continue
h = hlist[i - 1]
for s in graph[i]:
if h <= hlist[s - 1]:
high_list[i] = -1
if h >= hlist[s - 1]:
high_list[s] = -1
if high_list[i] == 0:
high_list[i] = 1
answer = 0
for i in range(1, N + 1):
if high_list[i] == 1:
# print(i)
answer += 1
print(answer)
| N, M = list(map(int, input().split()))
hlist = list(map(int, input().split()))
graph = [set() for _ in range(N + 1)]
for _ in range(M):
a, b = list(map(int, input().split()))
graph[a].add(b)
graph[b].add(a)
# print(graph)
answer = 0
for i in range(1, N + 1):
h = hlist[i - 1]
for s in graph[i]:
if h <= hlist[s - 1]:
break
else:
answer += 1
print(answer)
| false | 37.5 | [
"-high_list = [0] * (N + 1)",
"+answer = 0",
"- if high_list[i] == -1:",
"- continue",
"- high_list[i] = -1",
"- if h >= hlist[s - 1]:",
"- high_list[s] = -1",
"- if high_list[i] == 0:",
"- high_list[i] = 1",
"-answer = 0",
"-for i in range(1, N + 1):",
"- if high_list[i] == 1:",
"- # print(i)",
"+ break",
"+ else:"
]
| false | 0.037811 | 0.03729 | 1.013966 | [
"s408905960",
"s059299090"
]
|
u312025627 | p03036 | python | s838217011 | s921992348 | 163 | 85 | 38,384 | 61,892 | Accepted | Accepted | 47.85 | r, d, x = list(map(int,input().split()))
after = r * x - d
for i in range(1,11):
print(after)
after = r * after - d | def main():
r, D, x = (int(i) for i in input().split())
for i in range(10):
nx = r*x - D
print(nx)
x = nx
if __name__ == '__main__':
main()
| 5 | 11 | 121 | 189 | r, d, x = list(map(int, input().split()))
after = r * x - d
for i in range(1, 11):
print(after)
after = r * after - d
| def main():
r, D, x = (int(i) for i in input().split())
for i in range(10):
nx = r * x - D
print(nx)
x = nx
if __name__ == "__main__":
main()
| false | 54.545455 | [
"-r, d, x = list(map(int, input().split()))",
"-after = r * x - d",
"-for i in range(1, 11):",
"- print(after)",
"- after = r * after - d",
"+def main():",
"+ r, D, x = (int(i) for i in input().split())",
"+ for i in range(10):",
"+ nx = r * x - D",
"+ print(nx)",
"+ x = nx",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.034626 | 0.034312 | 1.009159 | [
"s838217011",
"s921992348"
]
|
u086056891 | p03212 | python | s775616571 | s744630649 | 57 | 52 | 3,060 | 2,940 | Accepted | Accepted | 8.77 | n = int(eval(input()))
def solve(s):
if int(s) > n:
return 0
if '7' in s and '5' in s and '3' in s:
count = 1
else:
count = 0
count += solve(s + '7')
count += solve(s + '5')
count += solve(s + '3')
return count
print((solve('0'))) | def dfs(s):
if int(s) > n:
return 0
return ('7' in s and '5' in s and '3' in s) + dfs(s + '7') + dfs(s + '5') + dfs(s + '3')
n = int(eval(input()))
print((dfs('0'))) | 15 | 8 | 290 | 182 | n = int(eval(input()))
def solve(s):
if int(s) > n:
return 0
if "7" in s and "5" in s and "3" in s:
count = 1
else:
count = 0
count += solve(s + "7")
count += solve(s + "5")
count += solve(s + "3")
return count
print((solve("0")))
| def dfs(s):
if int(s) > n:
return 0
return (
("7" in s and "5" in s and "3" in s)
+ dfs(s + "7")
+ dfs(s + "5")
+ dfs(s + "3")
)
n = int(eval(input()))
print((dfs("0")))
| false | 46.666667 | [
"-n = int(eval(input()))",
"+def dfs(s):",
"+ if int(s) > n:",
"+ return 0",
"+ return (",
"+ (\"7\" in s and \"5\" in s and \"3\" in s)",
"+ + dfs(s + \"7\")",
"+ + dfs(s + \"5\")",
"+ + dfs(s + \"3\")",
"+ )",
"-def solve(s):",
"- if int(s) > n:",
"- return 0",
"- if \"7\" in s and \"5\" in s and \"3\" in s:",
"- count = 1",
"- else:",
"- count = 0",
"- count += solve(s + \"7\")",
"- count += solve(s + \"5\")",
"- count += solve(s + \"3\")",
"- return count",
"-",
"-",
"-print((solve(\"0\")))",
"+n = int(eval(input()))",
"+print((dfs(\"0\")))"
]
| false | 0.045025 | 0.043051 | 1.045849 | [
"s775616571",
"s744630649"
]
|
u192154323 | p02720 | python | s596606434 | s637594839 | 357 | 219 | 10,904 | 13,368 | Accepted | Accepted | 38.66 | from collections import deque
k = int(eval(input()))
d = deque([i for i in range(1,10)])
count = 0
while True:
num = d.popleft()
count += 1
if count == k:
break
str_num = str(num)
next_digit_ls = [int(str_num[-1]) - 1, int(str_num[-1]), int(str_num[-1]) + 1]
for digit in next_digit_ls:
if 0<= digit <= 9:
d.append(int(str_num + str(digit)))
print(num) | k = int(eval(input()))
lun_ls = []
def change_to_num(ls):
ls = list(map(str, ls))
strnum = ''.join(ls)
return int(strnum)
def lun(num):
'''
渡された数が上限行ってなければlun_lsに追加して、次の数で再帰呼出
'''
if num > 3234566667:
return
lun_ls.append(num)
last = num % 10
for nex in range(last-1, last+2):
if 0<= nex < 10:
new_str = str(num) + str(nex)
new = int(new_str)
lun(new)
for start in range(1,10):
lun(start)
lun_ls.sort()
print((lun_ls[k-1])) | 16 | 26 | 414 | 551 | from collections import deque
k = int(eval(input()))
d = deque([i for i in range(1, 10)])
count = 0
while True:
num = d.popleft()
count += 1
if count == k:
break
str_num = str(num)
next_digit_ls = [int(str_num[-1]) - 1, int(str_num[-1]), int(str_num[-1]) + 1]
for digit in next_digit_ls:
if 0 <= digit <= 9:
d.append(int(str_num + str(digit)))
print(num)
| k = int(eval(input()))
lun_ls = []
def change_to_num(ls):
ls = list(map(str, ls))
strnum = "".join(ls)
return int(strnum)
def lun(num):
"""
渡された数が上限行ってなければlun_lsに追加して、次の数で再帰呼出
"""
if num > 3234566667:
return
lun_ls.append(num)
last = num % 10
for nex in range(last - 1, last + 2):
if 0 <= nex < 10:
new_str = str(num) + str(nex)
new = int(new_str)
lun(new)
for start in range(1, 10):
lun(start)
lun_ls.sort()
print((lun_ls[k - 1]))
| false | 38.461538 | [
"-from collections import deque",
"+k = int(eval(input()))",
"+lun_ls = []",
"-k = int(eval(input()))",
"-d = deque([i for i in range(1, 10)])",
"-count = 0",
"-while True:",
"- num = d.popleft()",
"- count += 1",
"- if count == k:",
"- break",
"- str_num = str(num)",
"- next_digit_ls = [int(str_num[-1]) - 1, int(str_num[-1]), int(str_num[-1]) + 1]",
"- for digit in next_digit_ls:",
"- if 0 <= digit <= 9:",
"- d.append(int(str_num + str(digit)))",
"-print(num)",
"+",
"+def change_to_num(ls):",
"+ ls = list(map(str, ls))",
"+ strnum = \"\".join(ls)",
"+ return int(strnum)",
"+",
"+",
"+def lun(num):",
"+ \"\"\"",
"+ 渡された数が上限行ってなければlun_lsに追加して、次の数で再帰呼出",
"+ \"\"\"",
"+ if num > 3234566667:",
"+ return",
"+ lun_ls.append(num)",
"+ last = num % 10",
"+ for nex in range(last - 1, last + 2):",
"+ if 0 <= nex < 10:",
"+ new_str = str(num) + str(nex)",
"+ new = int(new_str)",
"+ lun(new)",
"+",
"+",
"+for start in range(1, 10):",
"+ lun(start)",
"+lun_ls.sort()",
"+print((lun_ls[k - 1]))"
]
| false | 0.113239 | 0.352551 | 0.321199 | [
"s596606434",
"s637594839"
]
|
u397638621 | p02712 | python | s116341535 | s422289655 | 159 | 121 | 9,148 | 29,896 | Accepted | Accepted | 23.9 | N = int(eval(input()))
a = 0
for i in range(1, N + 1):
if i % 5 != 0 and i % 3 != 0:
a += i
print(a)
| N = int(eval(input()))
print((sum([i for i in range(1, N+1) if i%5!=0 and i%3!=0]))) | 6 | 2 | 112 | 77 | N = int(eval(input()))
a = 0
for i in range(1, N + 1):
if i % 5 != 0 and i % 3 != 0:
a += i
print(a)
| N = int(eval(input()))
print((sum([i for i in range(1, N + 1) if i % 5 != 0 and i % 3 != 0])))
| false | 66.666667 | [
"-a = 0",
"-for i in range(1, N + 1):",
"- if i % 5 != 0 and i % 3 != 0:",
"- a += i",
"-print(a)",
"+print((sum([i for i in range(1, N + 1) if i % 5 != 0 and i % 3 != 0])))"
]
| false | 0.224432 | 0.099278 | 2.260657 | [
"s116341535",
"s422289655"
]
|
u390901183 | p02699 | python | s958864127 | s040171356 | 23 | 19 | 9,148 | 9,100 | Accepted | Accepted | 17.39 | s, w = list(map(int, input().split()))
if w >= s:
print('unsafe')
else:
print('safe')
| s, w = list(map(int, input().split()))
print(('un' * (w >= s) + 'safe')) | 6 | 2 | 94 | 65 | s, w = list(map(int, input().split()))
if w >= s:
print("unsafe")
else:
print("safe")
| s, w = list(map(int, input().split()))
print(("un" * (w >= s) + "safe"))
| false | 66.666667 | [
"-if w >= s:",
"- print(\"unsafe\")",
"-else:",
"- print(\"safe\")",
"+print((\"un\" * (w >= s) + \"safe\"))"
]
| false | 0.043053 | 0.099394 | 0.433149 | [
"s958864127",
"s040171356"
]
|
u691018832 | p03503 | python | s698028512 | s250648623 | 321 | 282 | 3,188 | 3,188 | Accepted | Accepted | 12.15 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
import itertools
n = int(readline())
f = [list(map(int, readline().split())) for _ in range(n)]
p = [list(map(int, readline().split())) for _ in range(n)]
bit = list(itertools.product([0, 1], repeat=10))
ans = -float('inf')
bit.pop(0)
for i in range(2 ** 10 - 1):
memo = 0
flag = False
for j in range(n):
cnt = 0
for k in range(10):
if bit[i][k] == f[j][k] == 1:
cnt += 1
if cnt != 0:
flag = True
memo += p[j][cnt]
if flag:
ans = max(ans, memo)
print(ans)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from itertools import product
n = int(readline())
f = [list(map(int, readline().split())) for _ in range(n)]
p = [list(map(int, readline().split())) for _ in range(n)]
ans = -float('inf')
for bit in list(product([0, 1], repeat=10))[1:]:
v = 0
for ff, pp in zip(f, p):
cnt = 0
for i, check in enumerate(ff):
if bit[i] == check == 1:
cnt += 1
v += pp[cnt]
if ans < v:
ans = v
print(ans)
| 28 | 23 | 728 | 628 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
import itertools
n = int(readline())
f = [list(map(int, readline().split())) for _ in range(n)]
p = [list(map(int, readline().split())) for _ in range(n)]
bit = list(itertools.product([0, 1], repeat=10))
ans = -float("inf")
bit.pop(0)
for i in range(2**10 - 1):
memo = 0
flag = False
for j in range(n):
cnt = 0
for k in range(10):
if bit[i][k] == f[j][k] == 1:
cnt += 1
if cnt != 0:
flag = True
memo += p[j][cnt]
if flag:
ans = max(ans, memo)
print(ans)
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
from itertools import product
n = int(readline())
f = [list(map(int, readline().split())) for _ in range(n)]
p = [list(map(int, readline().split())) for _ in range(n)]
ans = -float("inf")
for bit in list(product([0, 1], repeat=10))[1:]:
v = 0
for ff, pp in zip(f, p):
cnt = 0
for i, check in enumerate(ff):
if bit[i] == check == 1:
cnt += 1
v += pp[cnt]
if ans < v:
ans = v
print(ans)
| false | 17.857143 | [
"-import itertools",
"+from itertools import product",
"-bit = list(itertools.product([0, 1], repeat=10))",
"-bit.pop(0)",
"-for i in range(2**10 - 1):",
"- memo = 0",
"- flag = False",
"- for j in range(n):",
"+for bit in list(product([0, 1], repeat=10))[1:]:",
"+ v = 0",
"+ for ff, pp in zip(f, p):",
"- for k in range(10):",
"- if bit[i][k] == f[j][k] == 1:",
"+ for i, check in enumerate(ff):",
"+ if bit[i] == check == 1:",
"- if cnt != 0:",
"- flag = True",
"- memo += p[j][cnt]",
"- if flag:",
"- ans = max(ans, memo)",
"+ v += pp[cnt]",
"+ if ans < v:",
"+ ans = v"
]
| false | 0.137934 | 0.100756 | 1.368988 | [
"s698028512",
"s250648623"
]
|
u411203878 | p03352 | python | s067273596 | s290145978 | 164 | 65 | 38,384 | 61,876 | Accepted | Accepted | 60.37 | n=int(eval(input()))
ans = 1
i = 2
while i**2 <= n:
u = 2
while i**u <= n:
ans = max(i**u, ans)
u += 1
i += 1
print(ans) | N = int(eval(input()))
ans = 1
for i in range(2,N+1):
tmp = 2
while i**tmp<=N:
ans = max(ans,i**tmp)
tmp += 1
print(ans) | 13 | 9 | 157 | 147 | n = int(eval(input()))
ans = 1
i = 2
while i**2 <= n:
u = 2
while i**u <= n:
ans = max(i**u, ans)
u += 1
i += 1
print(ans)
| N = int(eval(input()))
ans = 1
for i in range(2, N + 1):
tmp = 2
while i**tmp <= N:
ans = max(ans, i**tmp)
tmp += 1
print(ans)
| false | 30.769231 | [
"-n = int(eval(input()))",
"+N = int(eval(input()))",
"-i = 2",
"-while i**2 <= n:",
"- u = 2",
"- while i**u <= n:",
"- ans = max(i**u, ans)",
"- u += 1",
"- i += 1",
"+for i in range(2, N + 1):",
"+ tmp = 2",
"+ while i**tmp <= N:",
"+ ans = max(ans, i**tmp)",
"+ tmp += 1"
]
| false | 0.036098 | 0.036214 | 0.996799 | [
"s067273596",
"s290145978"
]
|
u535659144 | p03212 | python | s663129226 | s906921945 | 420 | 305 | 50,392 | 48,104 | Accepted | Accepted | 27.38 | def cnct(lint,lim):
global list753
global list357
global list333
lint1=str(lint)+"3"
lint1int=int(lint1)
if lint1int<=lim and not lint1int in list357:
list357.add(lint1int)
cnct(lint1int,lim)
lint2=str(lint)+"5"
lint2int=int(lint2)
if lint2int<=lim and not lint2int in list357:
list357.add(lint2int)
cnct(lint2int,lim)
lint3=str(lint)+"7"
lint3int=int(lint3)
if lint3int<=lim and not lint3int in list357:
list357.add(lint3int)
cnct(lint3int,lim)
lint4="3"+str(lint)
lint4int=int(lint4)
if lint4int<=lim and not lint4int in list357:
list357.add(lint4int)
cnct(lint4int,lim)
lint5="5"+str(lint)
lint5int=int(lint5)
if lint5int<=lim and not lint5int in list357:
list357.add(lint5int)
cnct(lint5int,lim)
lint6="7"+str(lint)
lint6int=int(lint6)
if lint6int<=lim and not lint6int in list357:
list357.add(lint6int)
cnct(lint6int,lim)
def D(lint):
lista=list(str(lint))
if lista.count("3") and lista.count("5") and lista.count("7"):
return True
else:
return False
list753=[3,5,7]
list357=set()
k=int(eval(input()))
count=0
for b in list753:
cnct(b,k)
list333=list(list357)
list333.sort()
for c in [x for x in list333]:
if not D(c):
list333.remove(c)
print((len(list333)))
| def cnct(lint,lim):
global list753
global list357
global list333
lint1int=lint*10+3
if lint1int<=lim and not lint1int in list357:
list357.add(lint1int)
cnct(lint1int,lim)
lint2int=lint*10+5
if lint2int<=lim and not lint2int in list357:
list357.add(lint2int)
cnct(lint2int,lim)
lint3int=lint*10+7
if lint3int<=lim and not lint3int in list357:
list357.add(lint3int)
cnct(lint3int,lim)
def D(lint):
lista=list(str(lint))
if lista.count("3") and lista.count("5") and lista.count("7"):
return True
else:
return False
list753=[3,5,7]
list357=set()
k=int(eval(input()))
for b in list753:
cnct(b,k)
for c in [x for x in list357]:
if not D(c):
list357.remove(c)
print((len(list357))) | 53 | 33 | 1,434 | 829 | def cnct(lint, lim):
global list753
global list357
global list333
lint1 = str(lint) + "3"
lint1int = int(lint1)
if lint1int <= lim and not lint1int in list357:
list357.add(lint1int)
cnct(lint1int, lim)
lint2 = str(lint) + "5"
lint2int = int(lint2)
if lint2int <= lim and not lint2int in list357:
list357.add(lint2int)
cnct(lint2int, lim)
lint3 = str(lint) + "7"
lint3int = int(lint3)
if lint3int <= lim and not lint3int in list357:
list357.add(lint3int)
cnct(lint3int, lim)
lint4 = "3" + str(lint)
lint4int = int(lint4)
if lint4int <= lim and not lint4int in list357:
list357.add(lint4int)
cnct(lint4int, lim)
lint5 = "5" + str(lint)
lint5int = int(lint5)
if lint5int <= lim and not lint5int in list357:
list357.add(lint5int)
cnct(lint5int, lim)
lint6 = "7" + str(lint)
lint6int = int(lint6)
if lint6int <= lim and not lint6int in list357:
list357.add(lint6int)
cnct(lint6int, lim)
def D(lint):
lista = list(str(lint))
if lista.count("3") and lista.count("5") and lista.count("7"):
return True
else:
return False
list753 = [3, 5, 7]
list357 = set()
k = int(eval(input()))
count = 0
for b in list753:
cnct(b, k)
list333 = list(list357)
list333.sort()
for c in [x for x in list333]:
if not D(c):
list333.remove(c)
print((len(list333)))
| def cnct(lint, lim):
global list753
global list357
global list333
lint1int = lint * 10 + 3
if lint1int <= lim and not lint1int in list357:
list357.add(lint1int)
cnct(lint1int, lim)
lint2int = lint * 10 + 5
if lint2int <= lim and not lint2int in list357:
list357.add(lint2int)
cnct(lint2int, lim)
lint3int = lint * 10 + 7
if lint3int <= lim and not lint3int in list357:
list357.add(lint3int)
cnct(lint3int, lim)
def D(lint):
lista = list(str(lint))
if lista.count("3") and lista.count("5") and lista.count("7"):
return True
else:
return False
list753 = [3, 5, 7]
list357 = set()
k = int(eval(input()))
for b in list753:
cnct(b, k)
for c in [x for x in list357]:
if not D(c):
list357.remove(c)
print((len(list357)))
| false | 37.735849 | [
"- lint1 = str(lint) + \"3\"",
"- lint1int = int(lint1)",
"+ lint1int = lint * 10 + 3",
"- lint2 = str(lint) + \"5\"",
"- lint2int = int(lint2)",
"+ lint2int = lint * 10 + 5",
"- lint3 = str(lint) + \"7\"",
"- lint3int = int(lint3)",
"+ lint3int = lint * 10 + 7",
"- lint4 = \"3\" + str(lint)",
"- lint4int = int(lint4)",
"- if lint4int <= lim and not lint4int in list357:",
"- list357.add(lint4int)",
"- cnct(lint4int, lim)",
"- lint5 = \"5\" + str(lint)",
"- lint5int = int(lint5)",
"- if lint5int <= lim and not lint5int in list357:",
"- list357.add(lint5int)",
"- cnct(lint5int, lim)",
"- lint6 = \"7\" + str(lint)",
"- lint6int = int(lint6)",
"- if lint6int <= lim and not lint6int in list357:",
"- list357.add(lint6int)",
"- cnct(lint6int, lim)",
"-count = 0",
"-list333 = list(list357)",
"-list333.sort()",
"-for c in [x for x in list333]:",
"+for c in [x for x in list357]:",
"- list333.remove(c)",
"-print((len(list333)))",
"+ list357.remove(c)",
"+print((len(list357)))"
]
| false | 0.953141 | 0.045101 | 21.133274 | [
"s663129226",
"s906921945"
]
|
u327125861 | p02397 | python | s602226851 | s642007298 | 70 | 60 | 7,640 | 7,472 | Accepted | Accepted | 14.29 | while 1:
n = input().split()
a = int(n[0])
b = int(n[1])
if a == 0 and b == 0:
break
if a > b:
bf = a
a = b
b = bf
print((str(a) + " " + str(b))) | while True:
s = input().rstrip().split(' ')
x = int(s[0])
y = int(s[1])
if x == 0 and y == 0: break
if x > y:
x,y = y,x
print((str(x) + " " + str(y))) | 11 | 8 | 167 | 163 | while 1:
n = input().split()
a = int(n[0])
b = int(n[1])
if a == 0 and b == 0:
break
if a > b:
bf = a
a = b
b = bf
print((str(a) + " " + str(b)))
| while True:
s = input().rstrip().split(" ")
x = int(s[0])
y = int(s[1])
if x == 0 and y == 0:
break
if x > y:
x, y = y, x
print((str(x) + " " + str(y)))
| false | 27.272727 | [
"-while 1:",
"- n = input().split()",
"- a = int(n[0])",
"- b = int(n[1])",
"- if a == 0 and b == 0:",
"+while True:",
"+ s = input().rstrip().split(\" \")",
"+ x = int(s[0])",
"+ y = int(s[1])",
"+ if x == 0 and y == 0:",
"- if a > b:",
"- bf = a",
"- a = b",
"- b = bf",
"- print((str(a) + \" \" + str(b)))",
"+ if x > y:",
"+ x, y = y, x",
"+ print((str(x) + \" \" + str(y)))"
]
| false | 0.083705 | 0.106423 | 0.78653 | [
"s602226851",
"s642007298"
]
|
u145145077 | p02995 | python | s350161885 | s015644529 | 234 | 32 | 27,204 | 9,216 | Accepted | Accepted | 86.32 | a,b,c,d=list(map(int,input().split()))
def calc_div_num(a,b,x):
return b//x - (a-1)//x
num_c = calc_div_num(a, b, c)
num_d = calc_div_num(a, b, d)
import numpy as np
import math
#lcd = np.lcm(c, d)
lcd = c*d/math.gcd(c,d)
num_lcd = calc_div_num(a, b, int(lcd))
result = b-a+1 - (num_c+num_d-num_lcd)
print(result) | a,b,c,d=list(map(int,input().split()))
def calc_div_num(a,b,x):
return b//x - (a-1)//x
num_c = b//c - (a-1)//c
num_d = b//d - (a-1)//d
import math
lcd = int(c * d / math.gcd(c,d))
num_lcd = b//lcd - (a-1)//lcd
result = b-a+1 - (num_c+num_d-num_lcd)
print(result) | 16 | 14 | 328 | 275 | a, b, c, d = list(map(int, input().split()))
def calc_div_num(a, b, x):
return b // x - (a - 1) // x
num_c = calc_div_num(a, b, c)
num_d = calc_div_num(a, b, d)
import numpy as np
import math
# lcd = np.lcm(c, d)
lcd = c * d / math.gcd(c, d)
num_lcd = calc_div_num(a, b, int(lcd))
result = b - a + 1 - (num_c + num_d - num_lcd)
print(result)
| a, b, c, d = list(map(int, input().split()))
def calc_div_num(a, b, x):
return b // x - (a - 1) // x
num_c = b // c - (a - 1) // c
num_d = b // d - (a - 1) // d
import math
lcd = int(c * d / math.gcd(c, d))
num_lcd = b // lcd - (a - 1) // lcd
result = b - a + 1 - (num_c + num_d - num_lcd)
print(result)
| false | 12.5 | [
"-num_c = calc_div_num(a, b, c)",
"-num_d = calc_div_num(a, b, d)",
"-import numpy as np",
"+num_c = b // c - (a - 1) // c",
"+num_d = b // d - (a - 1) // d",
"-# lcd = np.lcm(c, d)",
"-lcd = c * d / math.gcd(c, d)",
"-num_lcd = calc_div_num(a, b, int(lcd))",
"+lcd = int(c * d / math.gcd(c, d))",
"+num_lcd = b // lcd - (a - 1) // lcd"
]
| false | 0.036371 | 0.035596 | 1.021773 | [
"s350161885",
"s015644529"
]
|
u775681539 | p02850 | python | s267355888 | s091465882 | 1,085 | 475 | 60,420 | 83,488 | Accepted | Accepted | 56.22 | #python3
from collections import deque
class Edge:
def __init__(self, to, d):
self.to = to
self.d = d
def main():
n = int(eval(input()))
g = [[] for _ in range(n)]
for i in range(n-1):
a, b = [int(x)-1 for x in input().split()]
g[a].append(Edge(b, i))
g[b].append(Edge(a, i))
dq = deque()
dq.append(0)
done = [0 for _ in range(n)]
done[0] = 1
ans = [0 for _ in range(n-1)]
while len(dq):
v = dq.pop()
c = -1
for i in range(len(g[v])):
u = g[v][i].to
ei = g[v][i].d
if done[u]:
c = ans[ei]
k = 1
for i in range(len(g[v])):
u = g[v][i].to
ei = g[v][i].d
if done[u]:
continue
if k == c:
k += 1
ans[ei] = k
k += 1
dq.append(u)
done[u] = 1
mx = 0
for i in range(len(g)):
mx = max(mx, len(g[i]))
print(mx)
for i in ans:
print(i)
main() | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
class Edge:
def __init__(self, to, id):
self.to = to
self.id = id
def main():
n = int(readline())
g = [[] for _ in range(n)]
for i in range(n-1):
a, b = list(map(int, readline().split()))
g[a-1].append(Edge(b-1, i))
g[b-1].append(Edge(a-1, i))
dq = deque()
done = [0 for _ in range(n)]
dq.append(0)
done[0] = 1
edgecolor = [0 for _ in range(n-1)]
while len(dq) > 0:
v = dq.pop()
c = -1
for i in range(len(g[v])):
nx = g[v][i].to
edge_id = g[v][i].id
if done[nx]:
c = edgecolor[edge_id]
k = 1
for i in range(len(g[v])):
nx = g[v][i].to
edge_id = g[v][i].id
if done[nx]:
continue
if k == c:
k += 1
edgecolor[edge_id] = k
k += 1
done[nx] = 1
dq.append(nx)
mx = max(edgecolor)
print(mx)
for ec in edgecolor:
print(ec)
if __name__ == '__main__':
main()
| 53 | 55 | 1,137 | 1,287 | # python3
from collections import deque
class Edge:
def __init__(self, to, d):
self.to = to
self.d = d
def main():
n = int(eval(input()))
g = [[] for _ in range(n)]
for i in range(n - 1):
a, b = [int(x) - 1 for x in input().split()]
g[a].append(Edge(b, i))
g[b].append(Edge(a, i))
dq = deque()
dq.append(0)
done = [0 for _ in range(n)]
done[0] = 1
ans = [0 for _ in range(n - 1)]
while len(dq):
v = dq.pop()
c = -1
for i in range(len(g[v])):
u = g[v][i].to
ei = g[v][i].d
if done[u]:
c = ans[ei]
k = 1
for i in range(len(g[v])):
u = g[v][i].to
ei = g[v][i].d
if done[u]:
continue
if k == c:
k += 1
ans[ei] = k
k += 1
dq.append(u)
done[u] = 1
mx = 0
for i in range(len(g)):
mx = max(mx, len(g[i]))
print(mx)
for i in ans:
print(i)
main()
| import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque
class Edge:
def __init__(self, to, id):
self.to = to
self.id = id
def main():
n = int(readline())
g = [[] for _ in range(n)]
for i in range(n - 1):
a, b = list(map(int, readline().split()))
g[a - 1].append(Edge(b - 1, i))
g[b - 1].append(Edge(a - 1, i))
dq = deque()
done = [0 for _ in range(n)]
dq.append(0)
done[0] = 1
edgecolor = [0 for _ in range(n - 1)]
while len(dq) > 0:
v = dq.pop()
c = -1
for i in range(len(g[v])):
nx = g[v][i].to
edge_id = g[v][i].id
if done[nx]:
c = edgecolor[edge_id]
k = 1
for i in range(len(g[v])):
nx = g[v][i].to
edge_id = g[v][i].id
if done[nx]:
continue
if k == c:
k += 1
edgecolor[edge_id] = k
k += 1
done[nx] = 1
dq.append(nx)
mx = max(edgecolor)
print(mx)
for ec in edgecolor:
print(ec)
if __name__ == "__main__":
main()
| false | 3.636364 | [
"-# python3",
"+import sys",
"+",
"+read = sys.stdin.buffer.read",
"+readline = sys.stdin.buffer.readline",
"+readlines = sys.stdin.buffer.readlines",
"- def __init__(self, to, d):",
"+ def __init__(self, to, id):",
"- self.d = d",
"+ self.id = id",
"- n = int(eval(input()))",
"+ n = int(readline())",
"- a, b = [int(x) - 1 for x in input().split()]",
"- g[a].append(Edge(b, i))",
"- g[b].append(Edge(a, i))",
"+ a, b = list(map(int, readline().split()))",
"+ g[a - 1].append(Edge(b - 1, i))",
"+ g[b - 1].append(Edge(a - 1, i))",
"+ done = [0 for _ in range(n)]",
"- done = [0 for _ in range(n)]",
"- ans = [0 for _ in range(n - 1)]",
"- while len(dq):",
"+ edgecolor = [0 for _ in range(n - 1)]",
"+ while len(dq) > 0:",
"- u = g[v][i].to",
"- ei = g[v][i].d",
"- if done[u]:",
"- c = ans[ei]",
"+ nx = g[v][i].to",
"+ edge_id = g[v][i].id",
"+ if done[nx]:",
"+ c = edgecolor[edge_id]",
"- u = g[v][i].to",
"- ei = g[v][i].d",
"- if done[u]:",
"+ nx = g[v][i].to",
"+ edge_id = g[v][i].id",
"+ if done[nx]:",
"- ans[ei] = k",
"+ edgecolor[edge_id] = k",
"- dq.append(u)",
"- done[u] = 1",
"- mx = 0",
"- for i in range(len(g)):",
"- mx = max(mx, len(g[i]))",
"+ done[nx] = 1",
"+ dq.append(nx)",
"+ mx = max(edgecolor)",
"- for i in ans:",
"- print(i)",
"+ for ec in edgecolor:",
"+ print(ec)",
"-main()",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.063494 | 0.078142 | 0.812544 | [
"s267355888",
"s091465882"
]
|
u554781254 | p02760 | python | s397170186 | s466452559 | 183 | 148 | 38,384 | 12,444 | Accepted | Accepted | 19.13 | table_1 = input().split()
table_2 = input().split()
table_3 = input().split()
bingo_card = table_1 + table_2 + table_3
N = int(eval(input()))
for _ in range(N):
b = str(int(eval(input())))
if b in bingo_card:
bingo_card[bingo_card.index(b)] = True
if bingo_card[0] == bingo_card[1] == bingo_card[2]:
print('Yes')
elif bingo_card[3] == bingo_card[4] == bingo_card[5]:
print('Yes')
elif bingo_card[6] == bingo_card[7] == bingo_card[8]:
print('Yes')
elif bingo_card[0] == bingo_card[3] == bingo_card[6]:
print('Yes')
elif bingo_card[1] == bingo_card[4] == bingo_card[7]:
print('Yes')
elif bingo_card[2] == bingo_card[5] == bingo_card[8]:
print('Yes')
elif bingo_card[0] == bingo_card[4] == bingo_card[8]:
print('Yes')
elif bingo_card[2] == bingo_card[4] == bingo_card[6]:
print('Yes')
else:
print('No') | import numpy as np
def main():
bingo_card = np.array([list(map(int, input().split())) for _ in range(3)])
counter = int(eval(input()))
for _ in range(counter):
bingo_card = np.where(bingo_card == int(eval(input())), 0, bingo_card)
vertical_bingo = min(np.sum(bingo_card, axis=0)) == 0
horizontal_bingo = min(np.sum(bingo_card, axis=1)) == 0
diag_normal_bingo = bingo_card[0][0] == 0 and bingo_card[1][1] == 0 and bingo_card[2][2] == 0
diag_reverse_bingo = bingo_card[0][2] == 0 and bingo_card[1][1] == 0 and bingo_card[2][0] == 0
if vertical_bingo or horizontal_bingo or diag_normal_bingo or diag_reverse_bingo:
print('Yes')
exit()
else:
print('No')
if __name__ == '__main__':
main() | 30 | 25 | 879 | 775 | table_1 = input().split()
table_2 = input().split()
table_3 = input().split()
bingo_card = table_1 + table_2 + table_3
N = int(eval(input()))
for _ in range(N):
b = str(int(eval(input())))
if b in bingo_card:
bingo_card[bingo_card.index(b)] = True
if bingo_card[0] == bingo_card[1] == bingo_card[2]:
print("Yes")
elif bingo_card[3] == bingo_card[4] == bingo_card[5]:
print("Yes")
elif bingo_card[6] == bingo_card[7] == bingo_card[8]:
print("Yes")
elif bingo_card[0] == bingo_card[3] == bingo_card[6]:
print("Yes")
elif bingo_card[1] == bingo_card[4] == bingo_card[7]:
print("Yes")
elif bingo_card[2] == bingo_card[5] == bingo_card[8]:
print("Yes")
elif bingo_card[0] == bingo_card[4] == bingo_card[8]:
print("Yes")
elif bingo_card[2] == bingo_card[4] == bingo_card[6]:
print("Yes")
else:
print("No")
| import numpy as np
def main():
bingo_card = np.array([list(map(int, input().split())) for _ in range(3)])
counter = int(eval(input()))
for _ in range(counter):
bingo_card = np.where(bingo_card == int(eval(input())), 0, bingo_card)
vertical_bingo = min(np.sum(bingo_card, axis=0)) == 0
horizontal_bingo = min(np.sum(bingo_card, axis=1)) == 0
diag_normal_bingo = (
bingo_card[0][0] == 0 and bingo_card[1][1] == 0 and bingo_card[2][2] == 0
)
diag_reverse_bingo = (
bingo_card[0][2] == 0 and bingo_card[1][1] == 0 and bingo_card[2][0] == 0
)
if vertical_bingo or horizontal_bingo or diag_normal_bingo or diag_reverse_bingo:
print("Yes")
exit()
else:
print("No")
if __name__ == "__main__":
main()
| false | 16.666667 | [
"-table_1 = input().split()",
"-table_2 = input().split()",
"-table_3 = input().split()",
"-bingo_card = table_1 + table_2 + table_3",
"-N = int(eval(input()))",
"-for _ in range(N):",
"- b = str(int(eval(input())))",
"- if b in bingo_card:",
"- bingo_card[bingo_card.index(b)] = True",
"-if bingo_card[0] == bingo_card[1] == bingo_card[2]:",
"- print(\"Yes\")",
"-elif bingo_card[3] == bingo_card[4] == bingo_card[5]:",
"- print(\"Yes\")",
"-elif bingo_card[6] == bingo_card[7] == bingo_card[8]:",
"- print(\"Yes\")",
"-elif bingo_card[0] == bingo_card[3] == bingo_card[6]:",
"- print(\"Yes\")",
"-elif bingo_card[1] == bingo_card[4] == bingo_card[7]:",
"- print(\"Yes\")",
"-elif bingo_card[2] == bingo_card[5] == bingo_card[8]:",
"- print(\"Yes\")",
"-elif bingo_card[0] == bingo_card[4] == bingo_card[8]:",
"- print(\"Yes\")",
"-elif bingo_card[2] == bingo_card[4] == bingo_card[6]:",
"- print(\"Yes\")",
"-else:",
"- print(\"No\")",
"+import numpy as np",
"+",
"+",
"+def main():",
"+ bingo_card = np.array([list(map(int, input().split())) for _ in range(3)])",
"+ counter = int(eval(input()))",
"+ for _ in range(counter):",
"+ bingo_card = np.where(bingo_card == int(eval(input())), 0, bingo_card)",
"+ vertical_bingo = min(np.sum(bingo_card, axis=0)) == 0",
"+ horizontal_bingo = min(np.sum(bingo_card, axis=1)) == 0",
"+ diag_normal_bingo = (",
"+ bingo_card[0][0] == 0 and bingo_card[1][1] == 0 and bingo_card[2][2] == 0",
"+ )",
"+ diag_reverse_bingo = (",
"+ bingo_card[0][2] == 0 and bingo_card[1][1] == 0 and bingo_card[2][0] == 0",
"+ )",
"+ if vertical_bingo or horizontal_bingo or diag_normal_bingo or diag_reverse_bingo:",
"+ print(\"Yes\")",
"+ exit()",
"+ else:",
"+ print(\"No\")",
"+",
"+",
"+if __name__ == \"__main__\":",
"+ main()"
]
| false | 0.039543 | 0.347043 | 0.113944 | [
"s397170186",
"s466452559"
]
|
u326609687 | p03141 | python | s206671957 | s065990200 | 510 | 382 | 27,904 | 44,084 | Accepted | Accepted | 25.1 | import numpy as np
N = int(eval(input()))
x = []
y = []
for i in range(N):
a, b = [int(_) for _ in input().split()]
x.append(a)
y.append(b)
nx = np.array(x)
ny = np.array(y)
ns = nx + ny
arr = np.array([nx, ny, ns]).T
arr = arr[np.argsort(arr[:, 2])][::-1, :]
n = np.sum(arr[0::2, 0]) - np.sum(arr[1::2, 1])
print(n) | import numpy as np
N = int(eval(input()))
x = []
for i in range(N):
x.extend(input().split())
a = np.array(x, dtype='int').reshape((N, 2))
s = a[:,0:1] + a[:,1:2]
a = np.hstack((a, s))
a = a[np.argsort(a[:, 2])][::-1, :]
n = np.sum(a[0::2, 0]) - np.sum(a[1::2, 1])
print(n) | 17 | 13 | 340 | 285 | import numpy as np
N = int(eval(input()))
x = []
y = []
for i in range(N):
a, b = [int(_) for _ in input().split()]
x.append(a)
y.append(b)
nx = np.array(x)
ny = np.array(y)
ns = nx + ny
arr = np.array([nx, ny, ns]).T
arr = arr[np.argsort(arr[:, 2])][::-1, :]
n = np.sum(arr[0::2, 0]) - np.sum(arr[1::2, 1])
print(n)
| import numpy as np
N = int(eval(input()))
x = []
for i in range(N):
x.extend(input().split())
a = np.array(x, dtype="int").reshape((N, 2))
s = a[:, 0:1] + a[:, 1:2]
a = np.hstack((a, s))
a = a[np.argsort(a[:, 2])][::-1, :]
n = np.sum(a[0::2, 0]) - np.sum(a[1::2, 1])
print(n)
| false | 23.529412 | [
"-y = []",
"- a, b = [int(_) for _ in input().split()]",
"- x.append(a)",
"- y.append(b)",
"-nx = np.array(x)",
"-ny = np.array(y)",
"-ns = nx + ny",
"-arr = np.array([nx, ny, ns]).T",
"-arr = arr[np.argsort(arr[:, 2])][::-1, :]",
"-n = np.sum(arr[0::2, 0]) - np.sum(arr[1::2, 1])",
"+ x.extend(input().split())",
"+a = np.array(x, dtype=\"int\").reshape((N, 2))",
"+s = a[:, 0:1] + a[:, 1:2]",
"+a = np.hstack((a, s))",
"+a = a[np.argsort(a[:, 2])][::-1, :]",
"+n = np.sum(a[0::2, 0]) - np.sum(a[1::2, 1])"
]
| false | 0.182283 | 0.273801 | 0.66575 | [
"s206671957",
"s065990200"
]
|
u372550522 | p03111 | python | s977553879 | s185881075 | 1,226 | 72 | 3,064 | 3,064 | Accepted | Accepted | 94.13 | n, A, B, C = (int(i) for i in input().split())
l = [int(eval(input())) for i in range(n)]
a = []
b = []
c = []
def furiwake(x):
global a
global b
global c
a = []
b = []
c = []
for i in range(1, n+1):
if dig4(x, i) == 0:
a.append(l[i-1])
if dig4(x, i) == 1:
b.append(l[i-1])
if dig4(x, i) == 2:
c.append(l[i-1])
def dig4(n, k):
return (n%(4**k))//(4**(k-1))
def cost():
costa = 10 * (len(a)-1) + abs(sum(a)-A)
costb = 10 * (len(b)-1) + abs(sum(b)-B)
costc = 10 * (len(c)-1) + abs(sum(c)-C)
return costa+costb+costc
ans = 1000000000
for i in range(1, 4**8):
furiwake(i)
if(len(a)*len(b)*len(c)):
ans = min(ans, cost())
print(ans) | N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for i in range(N)]
INF = 10 ** 9
def dfs(cur, a, b, c):
if cur == N:
return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
ret0 = dfs(cur + 1, a, b, c)
ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
return min(ret0, ret1, ret2, ret3)
print((dfs(0, 0, 0, 0))) | 36 | 14 | 784 | 442 | n, A, B, C = (int(i) for i in input().split())
l = [int(eval(input())) for i in range(n)]
a = []
b = []
c = []
def furiwake(x):
global a
global b
global c
a = []
b = []
c = []
for i in range(1, n + 1):
if dig4(x, i) == 0:
a.append(l[i - 1])
if dig4(x, i) == 1:
b.append(l[i - 1])
if dig4(x, i) == 2:
c.append(l[i - 1])
def dig4(n, k):
return (n % (4**k)) // (4 ** (k - 1))
def cost():
costa = 10 * (len(a) - 1) + abs(sum(a) - A)
costb = 10 * (len(b) - 1) + abs(sum(b) - B)
costc = 10 * (len(c) - 1) + abs(sum(c) - C)
return costa + costb + costc
ans = 1000000000
for i in range(1, 4**8):
furiwake(i)
if len(a) * len(b) * len(c):
ans = min(ans, cost())
print(ans)
| N, A, B, C = list(map(int, input().split()))
l = [int(eval(input())) for i in range(N)]
INF = 10**9
def dfs(cur, a, b, c):
if cur == N:
return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
ret0 = dfs(cur + 1, a, b, c)
ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
return min(ret0, ret1, ret2, ret3)
print((dfs(0, 0, 0, 0)))
| false | 61.111111 | [
"-n, A, B, C = (int(i) for i in input().split())",
"-l = [int(eval(input())) for i in range(n)]",
"-a = []",
"-b = []",
"-c = []",
"+N, A, B, C = list(map(int, input().split()))",
"+l = [int(eval(input())) for i in range(N)]",
"+INF = 10**9",
"-def furiwake(x):",
"- global a",
"- global b",
"- global c",
"- a = []",
"- b = []",
"- c = []",
"- for i in range(1, n + 1):",
"- if dig4(x, i) == 0:",
"- a.append(l[i - 1])",
"- if dig4(x, i) == 1:",
"- b.append(l[i - 1])",
"- if dig4(x, i) == 2:",
"- c.append(l[i - 1])",
"+def dfs(cur, a, b, c):",
"+ if cur == N:",
"+ return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF",
"+ ret0 = dfs(cur + 1, a, b, c)",
"+ ret1 = dfs(cur + 1, a + l[cur], b, c) + 10",
"+ ret2 = dfs(cur + 1, a, b + l[cur], c) + 10",
"+ ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10",
"+ return min(ret0, ret1, ret2, ret3)",
"-def dig4(n, k):",
"- return (n % (4**k)) // (4 ** (k - 1))",
"-",
"-",
"-def cost():",
"- costa = 10 * (len(a) - 1) + abs(sum(a) - A)",
"- costb = 10 * (len(b) - 1) + abs(sum(b) - B)",
"- costc = 10 * (len(c) - 1) + abs(sum(c) - C)",
"- return costa + costb + costc",
"-",
"-",
"-ans = 1000000000",
"-for i in range(1, 4**8):",
"- furiwake(i)",
"- if len(a) * len(b) * len(c):",
"- ans = min(ans, cost())",
"-print(ans)",
"+print((dfs(0, 0, 0, 0)))"
]
| false | 2.029042 | 0.060822 | 33.360389 | [
"s977553879",
"s185881075"
]
|
u887080340 | p02975 | python | s280531302 | s583727885 | 87 | 52 | 14,468 | 14,468 | Accepted | Accepted | 40.23 | import collections
N = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
C = collections.Counter(a)
L = len(C)
e = list(C.keys())
if (L == 1) and (C[0] > 0):
print("Yes")
elif (L == 2) and (C[e[0]] * 2 == C[e[1]]):
print((((e[0] ^ e[0] == e[1]) or (e[1] ^ e[1] == e[0])) and "Yes" or "No"))
elif (L == 3) and (C[e[0]] == C[e[1]]) and (C[e[1]] == C[e[2]]):
print((((e[0] ^ e[1]) == e[2]) and "Yes" or "No"))
else:
print("No")
| import collections
N = int(eval(input()))
a = list(map(int, input().split()))
C = collections.Counter(a)
L = len(C)
e = list(C.keys())
if (L == 1) and (C[0] > 0):
print("Yes")
elif (L == 2) and (C[e[0]] * 2 == C[e[1]]):
print((((e[0] ^ e[0] == e[1]) or (e[1] ^ e[1] == e[0])) and "Yes" or "No"))
elif (L == 3) and (C[e[0]] == C[e[1]]) and (C[e[1]] == C[e[2]]):
print((((e[0] ^ e[1]) == e[2]) and "Yes" or "No"))
else:
print("No")
| 17 | 15 | 463 | 451 | import collections
N = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
C = collections.Counter(a)
L = len(C)
e = list(C.keys())
if (L == 1) and (C[0] > 0):
print("Yes")
elif (L == 2) and (C[e[0]] * 2 == C[e[1]]):
print((((e[0] ^ e[0] == e[1]) or (e[1] ^ e[1] == e[0])) and "Yes" or "No"))
elif (L == 3) and (C[e[0]] == C[e[1]]) and (C[e[1]] == C[e[2]]):
print((((e[0] ^ e[1]) == e[2]) and "Yes" or "No"))
else:
print("No")
| import collections
N = int(eval(input()))
a = list(map(int, input().split()))
C = collections.Counter(a)
L = len(C)
e = list(C.keys())
if (L == 1) and (C[0] > 0):
print("Yes")
elif (L == 2) and (C[e[0]] * 2 == C[e[1]]):
print((((e[0] ^ e[0] == e[1]) or (e[1] ^ e[1] == e[0])) and "Yes" or "No"))
elif (L == 3) and (C[e[0]] == C[e[1]]) and (C[e[1]] == C[e[2]]):
print((((e[0] ^ e[1]) == e[2]) and "Yes" or "No"))
else:
print("No")
| false | 11.764706 | [
"-a.sort()"
]
| false | 0.120954 | 0.108671 | 1.113026 | [
"s280531302",
"s583727885"
]
|
u811733736 | p02316 | python | s943470300 | s629090496 | 890 | 690 | 44,248 | 17,872 | Accepted | Accepted | 22.47 | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_C&lang=jp
"""
import sys
input = sys.stdin.readline
def solve_knapsack(weight, items):
dp = [[0]*(weight+1) for _ in range(len(items))]
for i, item in enumerate(items[1:]):
for w in range(1, weight+1):
if item[1] <= w:
dp[i+1][w] = max((item[0] + dp[i][w-item[1]]), dp[i][w], (item[0] + dp[i+1][w-item[1]]))
else:
dp[i+1][w] = dp[i][w]
return dp[-1][-1]
def main(args):
N, W = list(map(int, input().split()))
items = [[]]
for _ in range(N):
items.append([int(x) for x in input().strip().split()])
result = solve_knapsack(W, items)
print(result)
if __name__ == '__main__':
main(sys.argv[1:]) | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_C&lang=jp
AC
"""
import sys
input = sys.stdin.readline
def solve_knapsack(weight, items):
dp = [[0]*(weight+1) for _ in range(len(items))]
for i, item in enumerate(items[1:]):
for w in range(1, weight+1):
if item[1] <= w:
# dp[i+1][w] = max((item[0] + dp[i][w-item[1]]), dp[i][w], (item[0] + dp[i+1][w-item[1]]))
dp[i+1][w] = max(dp[i][w], (item[0] + dp[i+1][w-item[1]]))
else:
dp[i+1][w] = dp[i][w]
return dp[-1][-1]
def main(args):
N, W = list(map(int, input().split()))
items = [[]]
for _ in range(N):
items.append([int(x) for x in input().strip().split()])
result = solve_knapsack(W, items)
print(result)
if __name__ == '__main__':
main(sys.argv[1:]) | 30 | 32 | 819 | 901 | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_C&lang=jp
"""
import sys
input = sys.stdin.readline
def solve_knapsack(weight, items):
dp = [[0] * (weight + 1) for _ in range(len(items))]
for i, item in enumerate(items[1:]):
for w in range(1, weight + 1):
if item[1] <= w:
dp[i + 1][w] = max(
(item[0] + dp[i][w - item[1]]),
dp[i][w],
(item[0] + dp[i + 1][w - item[1]]),
)
else:
dp[i + 1][w] = dp[i][w]
return dp[-1][-1]
def main(args):
N, W = list(map(int, input().split()))
items = [[]]
for _ in range(N):
items.append([int(x) for x in input().strip().split()])
result = solve_knapsack(W, items)
print(result)
if __name__ == "__main__":
main(sys.argv[1:])
| # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_C&lang=jp
AC
"""
import sys
input = sys.stdin.readline
def solve_knapsack(weight, items):
dp = [[0] * (weight + 1) for _ in range(len(items))]
for i, item in enumerate(items[1:]):
for w in range(1, weight + 1):
if item[1] <= w:
# dp[i+1][w] = max((item[0] + dp[i][w-item[1]]), dp[i][w], (item[0] + dp[i+1][w-item[1]]))
dp[i + 1][w] = max(dp[i][w], (item[0] + dp[i + 1][w - item[1]]))
else:
dp[i + 1][w] = dp[i][w]
return dp[-1][-1]
def main(args):
N, W = list(map(int, input().split()))
items = [[]]
for _ in range(N):
items.append([int(x) for x in input().strip().split()])
result = solve_knapsack(W, items)
print(result)
if __name__ == "__main__":
main(sys.argv[1:])
| false | 6.25 | [
"+AC",
"- dp[i + 1][w] = max(",
"- (item[0] + dp[i][w - item[1]]),",
"- dp[i][w],",
"- (item[0] + dp[i + 1][w - item[1]]),",
"- )",
"+ # dp[i+1][w] = max((item[0] + dp[i][w-item[1]]), dp[i][w], (item[0] + dp[i+1][w-item[1]]))",
"+ dp[i + 1][w] = max(dp[i][w], (item[0] + dp[i + 1][w - item[1]]))"
]
| false | 0.125867 | 0.091886 | 1.369818 | [
"s943470300",
"s629090496"
]
|
u077291787 | p02913 | python | s121730485 | s543312275 | 409 | 226 | 20,172 | 11,576 | Accepted | Accepted | 44.74 | # ABC141E - Who Says a Pun?
class RollingHash:
def __init__(self, source: str, base=1000000007, mod=9007199254740997):
self.source = source
self.length = len(source)
self.base = base
self.mod = mod
self.hash = self._get_hash_from_zero()
self.power = self._get_base_pow()
def _get_hash_from_zero(self): # compute hash of interval [0, right)
cur, hash_from_zero = 0, [0]
for e in self.source:
cur = (cur * self.base + ord(e)) % self.mod
hash_from_zero.append(cur)
return hash_from_zero
def _get_base_pow(self): # computer mod of power of base
cur, power = 1, [1]
for i in range(self.length):
cur *= self.base % self.mod
power.append(cur)
return power
def get_hash(self, l: int, r: int): # compute hash of interval [left, right)
return (self.hash[r] - self.hash[l] * self.power[r - l]) % self.mod
def main():
N = int(eval(input()))
S = input().rstrip()
rh, ok, ng = RollingHash(S, 1007, 10 ** 9 + 7), 0, N // 2 + 1
while ng - ok > 1:
mid = (ok + ng) // 2
flg, memo = 0, set()
for i in range(N - 2 * mid + 1):
memo.add(rh.get_hash(i, i + mid))
if rh.get_hash(i + mid, i + 2 * mid) in memo:
flg = 1
break
if flg:
ok = mid # next mid will be longer
else:
ng = mid # next mid will be shorter
print(ok) # max length of substrings appeared twice or more
if __name__ == "__main__":
main() | # ABC141E - Who Says a Pun?
class RollingHash:
def __init__(self, source: str, base=1000000007, mod=9007199254740997):
self.source = source
self.length = len(source)
self.base = base
self.mod = mod
self.hash = self._get_hash_from_zero()
self.power = self._get_base_pow()
def _get_hash_from_zero(self): # compute hash of interval [0, right)
cur, hash_from_zero = 0, [0]
for e in self.source:
cur = (cur * self.base + ord(e)) % self.mod
hash_from_zero.append(cur)
return hash_from_zero
def _get_base_pow(self): # computer mod of power of base
cur, power = 1, [1]
for i in range(self.length):
cur *= self.base % self.mod
power.append(cur)
return power
def get_hash(self, l: int, r: int): # compute hash of interval [left, right)
return (self.hash[r] - self.hash[l] * self.power[r - l]) % self.mod
def main():
N = int(eval(input()))
S = input().rstrip()
rh, ok, ng = RollingHash(S, 27, 10 ** 9 + 7), 0, N // 2 + 1
while ng - ok > 1:
mid = (ok + ng) // 2
flg, memo = 0, set()
for i in range(N - 2 * mid + 1):
memo.add(rh.get_hash(i, i + mid))
if rh.get_hash(i + mid, i + 2 * mid) in memo:
flg = 1
break
if flg:
ok = mid # next mid will be longer
else:
ng = mid # next mid will be shorter
print(ok) # max length of substrings appeared twice or more
if __name__ == "__main__":
main() | 49 | 49 | 1,645 | 1,643 | # ABC141E - Who Says a Pun?
class RollingHash:
def __init__(self, source: str, base=1000000007, mod=9007199254740997):
self.source = source
self.length = len(source)
self.base = base
self.mod = mod
self.hash = self._get_hash_from_zero()
self.power = self._get_base_pow()
def _get_hash_from_zero(self): # compute hash of interval [0, right)
cur, hash_from_zero = 0, [0]
for e in self.source:
cur = (cur * self.base + ord(e)) % self.mod
hash_from_zero.append(cur)
return hash_from_zero
def _get_base_pow(self): # computer mod of power of base
cur, power = 1, [1]
for i in range(self.length):
cur *= self.base % self.mod
power.append(cur)
return power
def get_hash(self, l: int, r: int): # compute hash of interval [left, right)
return (self.hash[r] - self.hash[l] * self.power[r - l]) % self.mod
def main():
N = int(eval(input()))
S = input().rstrip()
rh, ok, ng = RollingHash(S, 1007, 10**9 + 7), 0, N // 2 + 1
while ng - ok > 1:
mid = (ok + ng) // 2
flg, memo = 0, set()
for i in range(N - 2 * mid + 1):
memo.add(rh.get_hash(i, i + mid))
if rh.get_hash(i + mid, i + 2 * mid) in memo:
flg = 1
break
if flg:
ok = mid # next mid will be longer
else:
ng = mid # next mid will be shorter
print(ok) # max length of substrings appeared twice or more
if __name__ == "__main__":
main()
| # ABC141E - Who Says a Pun?
class RollingHash:
def __init__(self, source: str, base=1000000007, mod=9007199254740997):
self.source = source
self.length = len(source)
self.base = base
self.mod = mod
self.hash = self._get_hash_from_zero()
self.power = self._get_base_pow()
def _get_hash_from_zero(self): # compute hash of interval [0, right)
cur, hash_from_zero = 0, [0]
for e in self.source:
cur = (cur * self.base + ord(e)) % self.mod
hash_from_zero.append(cur)
return hash_from_zero
def _get_base_pow(self): # computer mod of power of base
cur, power = 1, [1]
for i in range(self.length):
cur *= self.base % self.mod
power.append(cur)
return power
def get_hash(self, l: int, r: int): # compute hash of interval [left, right)
return (self.hash[r] - self.hash[l] * self.power[r - l]) % self.mod
def main():
N = int(eval(input()))
S = input().rstrip()
rh, ok, ng = RollingHash(S, 27, 10**9 + 7), 0, N // 2 + 1
while ng - ok > 1:
mid = (ok + ng) // 2
flg, memo = 0, set()
for i in range(N - 2 * mid + 1):
memo.add(rh.get_hash(i, i + mid))
if rh.get_hash(i + mid, i + 2 * mid) in memo:
flg = 1
break
if flg:
ok = mid # next mid will be longer
else:
ng = mid # next mid will be shorter
print(ok) # max length of substrings appeared twice or more
if __name__ == "__main__":
main()
| false | 0 | [
"- rh, ok, ng = RollingHash(S, 1007, 10**9 + 7), 0, N // 2 + 1",
"+ rh, ok, ng = RollingHash(S, 27, 10**9 + 7), 0, N // 2 + 1"
]
| false | 0.046483 | 0.072482 | 0.641305 | [
"s121730485",
"s543312275"
]
|
u677440371 | p03290 | python | s037442357 | s089881905 | 786 | 709 | 3,064 | 3,188 | Accepted | Accepted | 9.8 | d,g = list(map(int, input().split()))
p = []
c = []
for i in range(d):
a,b = list(map(int, input().split()))
p.append(a)
c.append(b)
dp = [0 for i in range(sum(p) + 2)]
for i in range(1,d+1):
count_max = p[i-1]
bonus = c[i-1]
for j in range(sum(p)+1,0,-1):
for k in range(1,count_max+1):
if k < count_max:
cc = 100 * i * k
if k == count_max:
cc = 100 * i * k + bonus
if j - k >= 0:
dp[j] = max(dp[j],dp[j-k] + cc)
for i,j in enumerate(dp):
if g <= j:
print(i)
break | d,g = list(map(int, input().split()))
P = []
C = []
PC = []
for i in range(d):
p,c = list(map(int, input().split()))
P.append(p)
C.append(c)
PC.append((p,c))
P_sum = sum(P)
dp = [0 for i in range(P_sum + 1)]
for i,j in enumerate(PC):
for k in range(P_sum, -1, -1):
for l in range(1,j[0]+1):
if l + k <= P_sum:
if l == j[0]:
cc = 100 * (i + 1)* l + j[1]
else:
cc = 100 * (i + 1) * l
dp[l + k] = max(dp[l + k ], dp[k] + cc)
for i,j in enumerate(dp):
if j >= g:
print(i)
break | 26 | 26 | 654 | 657 | d, g = list(map(int, input().split()))
p = []
c = []
for i in range(d):
a, b = list(map(int, input().split()))
p.append(a)
c.append(b)
dp = [0 for i in range(sum(p) + 2)]
for i in range(1, d + 1):
count_max = p[i - 1]
bonus = c[i - 1]
for j in range(sum(p) + 1, 0, -1):
for k in range(1, count_max + 1):
if k < count_max:
cc = 100 * i * k
if k == count_max:
cc = 100 * i * k + bonus
if j - k >= 0:
dp[j] = max(dp[j], dp[j - k] + cc)
for i, j in enumerate(dp):
if g <= j:
print(i)
break
| d, g = list(map(int, input().split()))
P = []
C = []
PC = []
for i in range(d):
p, c = list(map(int, input().split()))
P.append(p)
C.append(c)
PC.append((p, c))
P_sum = sum(P)
dp = [0 for i in range(P_sum + 1)]
for i, j in enumerate(PC):
for k in range(P_sum, -1, -1):
for l in range(1, j[0] + 1):
if l + k <= P_sum:
if l == j[0]:
cc = 100 * (i + 1) * l + j[1]
else:
cc = 100 * (i + 1) * l
dp[l + k] = max(dp[l + k], dp[k] + cc)
for i, j in enumerate(dp):
if j >= g:
print(i)
break
| false | 0 | [
"-p = []",
"-c = []",
"+P = []",
"+C = []",
"+PC = []",
"- a, b = list(map(int, input().split()))",
"- p.append(a)",
"- c.append(b)",
"-dp = [0 for i in range(sum(p) + 2)]",
"-for i in range(1, d + 1):",
"- count_max = p[i - 1]",
"- bonus = c[i - 1]",
"- for j in range(sum(p) + 1, 0, -1):",
"- for k in range(1, count_max + 1):",
"- if k < count_max:",
"- cc = 100 * i * k",
"- if k == count_max:",
"- cc = 100 * i * k + bonus",
"- if j - k >= 0:",
"- dp[j] = max(dp[j], dp[j - k] + cc)",
"+ p, c = list(map(int, input().split()))",
"+ P.append(p)",
"+ C.append(c)",
"+ PC.append((p, c))",
"+P_sum = sum(P)",
"+dp = [0 for i in range(P_sum + 1)]",
"+for i, j in enumerate(PC):",
"+ for k in range(P_sum, -1, -1):",
"+ for l in range(1, j[0] + 1):",
"+ if l + k <= P_sum:",
"+ if l == j[0]:",
"+ cc = 100 * (i + 1) * l + j[1]",
"+ else:",
"+ cc = 100 * (i + 1) * l",
"+ dp[l + k] = max(dp[l + k], dp[k] + cc)",
"- if g <= j:",
"+ if j >= g:"
]
| false | 0.007571 | 0.052944 | 0.143005 | [
"s037442357",
"s089881905"
]
|
u842170774 | p03547 | python | s744283370 | s490219842 | 32 | 28 | 9,016 | 8,864 | Accepted | Accepted | 12.5 | a,b=input().split();print((['=','<','>'][(a!=b)+(a>b)])) | a,b=input().split();print(("=<>"[(a!=b)+(a>b)])) | 1 | 1 | 54 | 46 | a, b = input().split()
print((["=", "<", ">"][(a != b) + (a > b)]))
| a, b = input().split()
print(("=<>"[(a != b) + (a > b)]))
| false | 0 | [
"-print(([\"=\", \"<\", \">\"][(a != b) + (a > b)]))",
"+print((\"=<>\"[(a != b) + (a > b)]))"
]
| false | 0.054854 | 0.03486 | 1.573549 | [
"s744283370",
"s490219842"
]
|
u580873239 | p03037 | python | s329962661 | s146068094 | 372 | 313 | 27,340 | 12,408 | Accepted | Accepted | 15.86 | n,m=list(map(int,input().split()))
li=[]
for i in range(m):
a=list(map(int,input().split()))
li.append(a)
l=0
r=n
for i in range(m):
if li[i][0]>l:
l=li[i][0]
if li[i][1]<r:
r=li[i][1]
print((max(0,r-l+1)))
| n,m=list(map(int,input().split()))
L=[]
R=[]
for i in range(m):
l,r=list(map(int,input().split()))
L.append(l)
R.append(r)
a=max(L)
b=min(R)
li=[i for i in range(a,b+1)]
print((len(li)))
| 14 | 12 | 248 | 197 | n, m = list(map(int, input().split()))
li = []
for i in range(m):
a = list(map(int, input().split()))
li.append(a)
l = 0
r = n
for i in range(m):
if li[i][0] > l:
l = li[i][0]
if li[i][1] < r:
r = li[i][1]
print((max(0, r - l + 1)))
| n, m = list(map(int, input().split()))
L = []
R = []
for i in range(m):
l, r = list(map(int, input().split()))
L.append(l)
R.append(r)
a = max(L)
b = min(R)
li = [i for i in range(a, b + 1)]
print((len(li)))
| false | 14.285714 | [
"-li = []",
"+L = []",
"+R = []",
"- a = list(map(int, input().split()))",
"- li.append(a)",
"-l = 0",
"-r = n",
"-for i in range(m):",
"- if li[i][0] > l:",
"- l = li[i][0]",
"- if li[i][1] < r:",
"- r = li[i][1]",
"-print((max(0, r - l + 1)))",
"+ l, r = list(map(int, input().split()))",
"+ L.append(l)",
"+ R.append(r)",
"+a = max(L)",
"+b = min(R)",
"+li = [i for i in range(a, b + 1)]",
"+print((len(li)))"
]
| false | 0.006447 | 0.037077 | 0.17389 | [
"s329962661",
"s146068094"
]
|
u645250356 | p02773 | python | s759324187 | s201915961 | 1,950 | 670 | 131,908 | 197,044 | Accepted | Accepted | 65.64 | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
s = [eval(input()) for i in range(n)]
l = []
d = defaultdict(int)
ss = set()
for i,j in enumerate(s):
d[j] += 1
for jj in list(d):
l.append([jj,d[jj]])
l.sort()
l.sort(key=lambda x:x[1],reverse = True)
max = l[0][1]
# print(l,max)
for i,j in enumerate(l):
if j[1] == max:
print((j[0]))
else:
break
| from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n = inp()
d = []
s = set()
dd = {}
ind = 0
for i in range(n):
x = eval(input())
if x in s:
d[dd[x]][1] += 1
else:
dd[x] = ind
d.append([x,1])
ind += 1
s.add(x)
d.sort(key = lambda x:x[1], reverse = True)
# print(d)
res = []
for key,va in d:
if va < d[0][1]:
break
res.append(key)
res.sort()
for x in res:
print(x) | 27 | 34 | 672 | 756 | from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heapify
import sys, bisect, math, itertools, fractions, pprint
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n = inp()
s = [eval(input()) for i in range(n)]
l = []
d = defaultdict(int)
ss = set()
for i, j in enumerate(s):
d[j] += 1
for jj in list(d):
l.append([jj, d[jj]])
l.sort()
l.sort(key=lambda x: x[1], reverse=True)
max = l[0][1]
# print(l,max)
for i, j in enumerate(l):
if j[1] == max:
print((j[0]))
else:
break
| from collections import Counter, defaultdict, deque
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
import sys, math, itertools, fractions, pprint
sys.setrecursionlimit(10**8)
mod = 10**9 + 7
INF = float("inf")
def inp():
return int(sys.stdin.readline())
def inpl():
return list(map(int, sys.stdin.readline().split()))
n = inp()
d = []
s = set()
dd = {}
ind = 0
for i in range(n):
x = eval(input())
if x in s:
d[dd[x]][1] += 1
else:
dd[x] = ind
d.append([x, 1])
ind += 1
s.add(x)
d.sort(key=lambda x: x[1], reverse=True)
# print(d)
res = []
for key, va in d:
if va < d[0][1]:
break
res.append(key)
res.sort()
for x in res:
print(x)
| false | 20.588235 | [
"-from heapq import heappop, heappush, heapify",
"-import sys, bisect, math, itertools, fractions, pprint",
"+from heapq import heappop, heappush",
"+from bisect import bisect_left, bisect_right",
"+import sys, math, itertools, fractions, pprint",
"-s = [eval(input()) for i in range(n)]",
"-l = []",
"-d = defaultdict(int)",
"-ss = set()",
"-for i, j in enumerate(s):",
"- d[j] += 1",
"-for jj in list(d):",
"- l.append([jj, d[jj]])",
"-l.sort()",
"-l.sort(key=lambda x: x[1], reverse=True)",
"-max = l[0][1]",
"-# print(l,max)",
"-for i, j in enumerate(l):",
"- if j[1] == max:",
"- print((j[0]))",
"+d = []",
"+s = set()",
"+dd = {}",
"+ind = 0",
"+for i in range(n):",
"+ x = eval(input())",
"+ if x in s:",
"+ d[dd[x]][1] += 1",
"+ dd[x] = ind",
"+ d.append([x, 1])",
"+ ind += 1",
"+ s.add(x)",
"+d.sort(key=lambda x: x[1], reverse=True)",
"+# print(d)",
"+res = []",
"+for key, va in d:",
"+ if va < d[0][1]:",
"+ res.append(key)",
"+res.sort()",
"+for x in res:",
"+ print(x)"
]
| false | 0.039431 | 0.046456 | 0.848779 | [
"s759324187",
"s201915961"
]
|
u761320129 | p03687 | python | s941651854 | s404845301 | 48 | 44 | 3,064 | 3,064 | Accepted | Accepted | 8.33 | S = eval(input())
ans = len(S)
for i in range(26):
c = chr(ord('a') + i)
if not c in S: continue
s = S
ope = 0
while any(a!=c for a in s):
t = ''
for a,b in zip(s,s[1:]):
if a==c or b==c:
t += c
else:
t += '-'
s = t
ope += 1
ans = min(ans, ope)
print(ans) | S = eval(input())
ans = len(S)
for i in range(26):
c = chr(ord('a') + i)
if c not in S: continue
cnt = 0
s = S
while any(a!=c for a in s):
t = ''
for a,b in zip(s,s[1:]):
if c==a or c==b:
t += c
else:
t += a
s = t
cnt += 1
ans = min(ans, cnt)
print(ans) | 19 | 19 | 380 | 378 | S = eval(input())
ans = len(S)
for i in range(26):
c = chr(ord("a") + i)
if not c in S:
continue
s = S
ope = 0
while any(a != c for a in s):
t = ""
for a, b in zip(s, s[1:]):
if a == c or b == c:
t += c
else:
t += "-"
s = t
ope += 1
ans = min(ans, ope)
print(ans)
| S = eval(input())
ans = len(S)
for i in range(26):
c = chr(ord("a") + i)
if c not in S:
continue
cnt = 0
s = S
while any(a != c for a in s):
t = ""
for a, b in zip(s, s[1:]):
if c == a or c == b:
t += c
else:
t += a
s = t
cnt += 1
ans = min(ans, cnt)
print(ans)
| false | 0 | [
"- if not c in S:",
"+ if c not in S:",
"+ cnt = 0",
"- ope = 0",
"- if a == c or b == c:",
"+ if c == a or c == b:",
"- t += \"-\"",
"+ t += a",
"- ope += 1",
"- ans = min(ans, ope)",
"+ cnt += 1",
"+ ans = min(ans, cnt)"
]
| false | 0.033239 | 0.06677 | 0.497814 | [
"s941651854",
"s404845301"
]
|
u050428930 | p04001 | python | s950940259 | s536571007 | 27 | 20 | 3,060 | 3,064 | Accepted | Accepted | 25.93 | a=list(eval(input()))
ans=0
for i in range(1<<(len(a)-1)):
s=a[0]
for j in range(len(a)-1):
if i & (1<<j):
s+="+"
s+=a[j+1]
ans+=eval(s)
print(ans) | N=int(eval(input()))
m=list(map(int,str(N)))[::-1]
p=0
n=len(str(N))
if n==1:
print(N)
exit()
for i in range(2**(n-1)):
s=(["0"]*8+list(bin(i)[2:]))[::-1]
s=s[:n-1]
p+=m[0]
q=0
for i in range(n-1):
if s[i]=="0":
q+=1
p+=(10**q)*(m[i+1])
else:
q=0
p+=m[i+1]
print(p)
| 10 | 22 | 194 | 402 | a = list(eval(input()))
ans = 0
for i in range(1 << (len(a) - 1)):
s = a[0]
for j in range(len(a) - 1):
if i & (1 << j):
s += "+"
s += a[j + 1]
ans += eval(s)
print(ans)
| N = int(eval(input()))
m = list(map(int, str(N)))[::-1]
p = 0
n = len(str(N))
if n == 1:
print(N)
exit()
for i in range(2 ** (n - 1)):
s = (["0"] * 8 + list(bin(i)[2:]))[::-1]
s = s[: n - 1]
p += m[0]
q = 0
for i in range(n - 1):
if s[i] == "0":
q += 1
p += (10**q) * (m[i + 1])
else:
q = 0
p += m[i + 1]
print(p)
| false | 54.545455 | [
"-a = list(eval(input()))",
"-ans = 0",
"-for i in range(1 << (len(a) - 1)):",
"- s = a[0]",
"- for j in range(len(a) - 1):",
"- if i & (1 << j):",
"- s += \"+\"",
"- s += a[j + 1]",
"- ans += eval(s)",
"-print(ans)",
"+N = int(eval(input()))",
"+m = list(map(int, str(N)))[::-1]",
"+p = 0",
"+n = len(str(N))",
"+if n == 1:",
"+ print(N)",
"+ exit()",
"+for i in range(2 ** (n - 1)):",
"+ s = ([\"0\"] * 8 + list(bin(i)[2:]))[::-1]",
"+ s = s[: n - 1]",
"+ p += m[0]",
"+ q = 0",
"+ for i in range(n - 1):",
"+ if s[i] == \"0\":",
"+ q += 1",
"+ p += (10**q) * (m[i + 1])",
"+ else:",
"+ q = 0",
"+ p += m[i + 1]",
"+print(p)"
]
| false | 0.046505 | 0.045978 | 1.011456 | [
"s950940259",
"s536571007"
]
|
u802963389 | p03436 | python | s006430867 | s640911266 | 29 | 26 | 3,572 | 3,316 | Accepted | Accepted | 10.34 | from collections import deque
"""
-1 -> not visited
else -> step count
"""
def bfs(maze, visited, sh, sw):
stack = deque([[sh, sw]])
visited[sh][sw] = 1
while stack:
h, w = stack.popleft()
# ゴールの条件
if h == H - 1 and w == W - 1:
break
for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
new_h, new_w = h+j, w+k
if new_h < 0 or new_h >= H or \
new_w < 0 or new_w >= W:
continue
elif maze[new_h][new_w] != "#" and \
visited[new_h][new_w] == -1:
visited[new_h][new_w] = visited[h][w] + 1
stack.append([new_h, new_w])
return visited[H-1][W-1]
if __name__ == "__main__":
H, W = map(int, input().split())
maze = [input() for _ in range(H)]
sh, sw = 0, 0
visited = [[-1] * W for _ in range(H)]
step_cnt = bfs(maze, visited, sh, sw)
white_cnt = sum([i.count(".") for i in maze])
if step_cnt > 0:
print(white_cnt - step_cnt)
else:
print(-1)
| from collections import deque
def dfs(sx, sy):
stack = deque()
stack.append([sx, sy])
visited[sy][sx] = 1
while stack:
x, y = stack.popleft()
if x == w - 1 and y == h - 1:
break
for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
if 0 <= x + dx < w and 0 <= y + dy < h:
if S[y + dy][x + dx] != "#" and visited[y + dy][x + dx] == -1:
visited[y + dy][x + dx] = visited[y][x] + 1
stack.append([x + dx, y + dy])
h, w = list(map(int, input().split()))
S = [eval(input()) for _ in range(h)]
visited = [[-1] * w for _ in range(h)]
dfs(0, 0)
whites = sum([s.count(".") for s in S])
if visited[h - 1][w - 1] != -1:
ans = whites - visited[h - 1][w - 1]
else:
ans = -1
print(ans) | 41 | 31 | 1,105 | 757 | from collections import deque
"""
-1 -> not visited
else -> step count
"""
def bfs(maze, visited, sh, sw):
stack = deque([[sh, sw]])
visited[sh][sw] = 1
while stack:
h, w = stack.popleft()
# ゴールの条件
if h == H - 1 and w == W - 1:
break
for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
new_h, new_w = h + j, w + k
if new_h < 0 or new_h >= H or new_w < 0 or new_w >= W:
continue
elif maze[new_h][new_w] != "#" and visited[new_h][new_w] == -1:
visited[new_h][new_w] = visited[h][w] + 1
stack.append([new_h, new_w])
return visited[H - 1][W - 1]
if __name__ == "__main__":
H, W = map(int, input().split())
maze = [input() for _ in range(H)]
sh, sw = 0, 0
visited = [[-1] * W for _ in range(H)]
step_cnt = bfs(maze, visited, sh, sw)
white_cnt = sum([i.count(".") for i in maze])
if step_cnt > 0:
print(white_cnt - step_cnt)
else:
print(-1)
| from collections import deque
def dfs(sx, sy):
stack = deque()
stack.append([sx, sy])
visited[sy][sx] = 1
while stack:
x, y = stack.popleft()
if x == w - 1 and y == h - 1:
break
for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
if 0 <= x + dx < w and 0 <= y + dy < h:
if S[y + dy][x + dx] != "#" and visited[y + dy][x + dx] == -1:
visited[y + dy][x + dx] = visited[y][x] + 1
stack.append([x + dx, y + dy])
h, w = list(map(int, input().split()))
S = [eval(input()) for _ in range(h)]
visited = [[-1] * w for _ in range(h)]
dfs(0, 0)
whites = sum([s.count(".") for s in S])
if visited[h - 1][w - 1] != -1:
ans = whites - visited[h - 1][w - 1]
else:
ans = -1
print(ans)
| false | 24.390244 | [
"-\"\"\"",
"--1 -> not visited",
"-else -> step count",
"-\"\"\"",
"+",
"+def dfs(sx, sy):",
"+ stack = deque()",
"+ stack.append([sx, sy])",
"+ visited[sy][sx] = 1",
"+ while stack:",
"+ x, y = stack.popleft()",
"+ if x == w - 1 and y == h - 1:",
"+ break",
"+ for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:",
"+ if 0 <= x + dx < w and 0 <= y + dy < h:",
"+ if S[y + dy][x + dx] != \"#\" and visited[y + dy][x + dx] == -1:",
"+ visited[y + dy][x + dx] = visited[y][x] + 1",
"+ stack.append([x + dx, y + dy])",
"-def bfs(maze, visited, sh, sw):",
"- stack = deque([[sh, sw]])",
"- visited[sh][sw] = 1",
"- while stack:",
"- h, w = stack.popleft()",
"- # ゴールの条件",
"- if h == H - 1 and w == W - 1:",
"- break",
"- for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):",
"- new_h, new_w = h + j, w + k",
"- if new_h < 0 or new_h >= H or new_w < 0 or new_w >= W:",
"- continue",
"- elif maze[new_h][new_w] != \"#\" and visited[new_h][new_w] == -1:",
"- visited[new_h][new_w] = visited[h][w] + 1",
"- stack.append([new_h, new_w])",
"- return visited[H - 1][W - 1]",
"-",
"-",
"-if __name__ == \"__main__\":",
"- H, W = map(int, input().split())",
"- maze = [input() for _ in range(H)]",
"- sh, sw = 0, 0",
"- visited = [[-1] * W for _ in range(H)]",
"- step_cnt = bfs(maze, visited, sh, sw)",
"- white_cnt = sum([i.count(\".\") for i in maze])",
"- if step_cnt > 0:",
"- print(white_cnt - step_cnt)",
"- else:",
"- print(-1)",
"+h, w = list(map(int, input().split()))",
"+S = [eval(input()) for _ in range(h)]",
"+visited = [[-1] * w for _ in range(h)]",
"+dfs(0, 0)",
"+whites = sum([s.count(\".\") for s in S])",
"+if visited[h - 1][w - 1] != -1:",
"+ ans = whites - visited[h - 1][w - 1]",
"+else:",
"+ ans = -1",
"+print(ans)"
]
| false | 0.048974 | 0.04878 | 1.00399 | [
"s006430867",
"s640911266"
]
|
u916242112 | p02628 | python | s248568129 | s676811106 | 33 | 26 | 9,256 | 8,888 | Accepted | Accepted | 21.21 | N, K = list(map(int,input().split()))
p = list(map(int,input().split()))
list.sort(p)
total = 0
for i in range(K):
total += p[i]
print(total) | N,K = list(map(int,input().split()))
list = list(map(int,input().split()))
list.sort()
total=0
for i in range(K):
total+=list[i]
print(total) | 8 | 9 | 144 | 146 | N, K = list(map(int, input().split()))
p = list(map(int, input().split()))
list.sort(p)
total = 0
for i in range(K):
total += p[i]
print(total)
| N, K = list(map(int, input().split()))
list = list(map(int, input().split()))
list.sort()
total = 0
for i in range(K):
total += list[i]
print(total)
| false | 11.111111 | [
"-p = list(map(int, input().split()))",
"-list.sort(p)",
"+list = list(map(int, input().split()))",
"+list.sort()",
"- total += p[i]",
"+ total += list[i]"
]
| false | 0.10476 | 0.043071 | 2.43223 | [
"s248568129",
"s676811106"
]
|
u037430802 | p03353 | python | s086977786 | s326530497 | 38 | 33 | 5,068 | 4,464 | Accepted | Accepted | 13.16 | s = eval(input())
k = int(eval(input()))
ans = []
for i in range(1,k+1):
for j in range(len(s)):
if j+i > len(s): break
ans.append(s[j:j+i])
ans = list(sorted(set(ans))) #setはsortedではソートできる。リストでソートしてsetにすると順序は保証されない
if k != 1:
print((ans[k-1]))
else:
print((min(list(s)))) | s = eval(input())
K = int(eval(input()))
substrings = set()
for k in range(1,K+1):
for i in range(len(s)):
substrings.add(s[i:i+k])
ans = sorted(substrings)
print((ans[K-1])) | 16 | 11 | 291 | 185 | s = eval(input())
k = int(eval(input()))
ans = []
for i in range(1, k + 1):
for j in range(len(s)):
if j + i > len(s):
break
ans.append(s[j : j + i])
ans = list(sorted(set(ans))) # setはsortedではソートできる。リストでソートしてsetにすると順序は保証されない
if k != 1:
print((ans[k - 1]))
else:
print((min(list(s))))
| s = eval(input())
K = int(eval(input()))
substrings = set()
for k in range(1, K + 1):
for i in range(len(s)):
substrings.add(s[i : i + k])
ans = sorted(substrings)
print((ans[K - 1]))
| false | 31.25 | [
"-k = int(eval(input()))",
"-ans = []",
"-for i in range(1, k + 1):",
"- for j in range(len(s)):",
"- if j + i > len(s):",
"- break",
"- ans.append(s[j : j + i])",
"-ans = list(sorted(set(ans))) # setはsortedではソートできる。リストでソートしてsetにすると順序は保証されない",
"-if k != 1:",
"- print((ans[k - 1]))",
"-else:",
"- print((min(list(s))))",
"+K = int(eval(input()))",
"+substrings = set()",
"+for k in range(1, K + 1):",
"+ for i in range(len(s)):",
"+ substrings.add(s[i : i + k])",
"+ans = sorted(substrings)",
"+print((ans[K - 1]))"
]
| false | 0.113749 | 0.040912 | 2.780342 | [
"s086977786",
"s326530497"
]
|
u416011173 | p02726 | python | s219922962 | s381037724 | 1,996 | 1,626 | 3,444 | 3,444 | Accepted | Accepted | 18.54 | # -*- coding: utf-8 -*-
# D - Line++
# 標準入力の取得
N,X,Y = list(map(int, input().split()))
# 求解
# (i, j)間の最短距離はmin{|j-i|, |X-i|+1+|j-Y|, |Y-i|+1+|j-X|}であるため、
# (i, j)が決まれば、最短距離はO(1)で決まる。したがって、全(i, j)について、最短距離を求める。
k_list = [0 for i in range(1,N)]
for i in range(1, N):
diff_X_i = abs(X - i)
diff_Y_i = abs(Y - i)
for j in range(i+1, N+1):
diff_j_i = abs(j - i)
diff_j_X = abs(j - X)
diff_j_Y = abs(j - Y)
min_path = min([diff_j_i, diff_X_i+1+diff_j_Y, diff_Y_i+1+diff_j_X])
k_list[min_path-1] += 1
# 結果出力
for k in k_list:
print(k) | # -*- coding: utf-8 -*-
# D - Line++
# 標準入力の取得
N,X,Y = list(map(int, input().split()))
# 求解
# (i, j)間の最短距離はmin{|j-i|, |X-i|+1+|j-Y|}であるため、
# (i, j)が決まれば、最短距離はO(1)で決まる。したがって、全(i, j)について、最短距離を求める。
k_list = [0 for i in range(1,N)]
for i in range(1, N):
for j in range(i+1, N+1):
min_path = min([abs(j-i), abs(X-i)+1+abs(j-Y)])
k_list[min_path-1] += 1
# 結果出力
for k in k_list:
print(k) | 22 | 17 | 605 | 422 | # -*- coding: utf-8 -*-
# D - Line++
# 標準入力の取得
N, X, Y = list(map(int, input().split()))
# 求解
# (i, j)間の最短距離はmin{|j-i|, |X-i|+1+|j-Y|, |Y-i|+1+|j-X|}であるため、
# (i, j)が決まれば、最短距離はO(1)で決まる。したがって、全(i, j)について、最短距離を求める。
k_list = [0 for i in range(1, N)]
for i in range(1, N):
diff_X_i = abs(X - i)
diff_Y_i = abs(Y - i)
for j in range(i + 1, N + 1):
diff_j_i = abs(j - i)
diff_j_X = abs(j - X)
diff_j_Y = abs(j - Y)
min_path = min([diff_j_i, diff_X_i + 1 + diff_j_Y, diff_Y_i + 1 + diff_j_X])
k_list[min_path - 1] += 1
# 結果出力
for k in k_list:
print(k)
| # -*- coding: utf-8 -*-
# D - Line++
# 標準入力の取得
N, X, Y = list(map(int, input().split()))
# 求解
# (i, j)間の最短距離はmin{|j-i|, |X-i|+1+|j-Y|}であるため、
# (i, j)が決まれば、最短距離はO(1)で決まる。したがって、全(i, j)について、最短距離を求める。
k_list = [0 for i in range(1, N)]
for i in range(1, N):
for j in range(i + 1, N + 1):
min_path = min([abs(j - i), abs(X - i) + 1 + abs(j - Y)])
k_list[min_path - 1] += 1
# 結果出力
for k in k_list:
print(k)
| false | 22.727273 | [
"-# (i, j)間の最短距離はmin{|j-i|, |X-i|+1+|j-Y|, |Y-i|+1+|j-X|}であるため、",
"+# (i, j)間の最短距離はmin{|j-i|, |X-i|+1+|j-Y|}であるため、",
"- diff_X_i = abs(X - i)",
"- diff_Y_i = abs(Y - i)",
"- diff_j_i = abs(j - i)",
"- diff_j_X = abs(j - X)",
"- diff_j_Y = abs(j - Y)",
"- min_path = min([diff_j_i, diff_X_i + 1 + diff_j_Y, diff_Y_i + 1 + diff_j_X])",
"+ min_path = min([abs(j - i), abs(X - i) + 1 + abs(j - Y)])"
]
| false | 0.0414 | 0.041609 | 0.994997 | [
"s219922962",
"s381037724"
]
|
u608088992 | p03449 | python | s661030647 | s110294272 | 25 | 22 | 3,316 | 3,316 | Accepted | Accepted | 12 | import sys
from collections import deque
def solve():
input = sys.stdin.readline
N = int(eval(input()))
A = [[int(a) for a in input().split()] for _ in range(2)]
move = ((1, 0), (0, 1))
maxN = [[0 for _ in range(N)] for i in range(2)]
q = deque()
q.append((0, 0, A[0][0]))
while q:
nx, ny, np = q.popleft()
maxN[nx][ny] = max(maxN[nx][ny], np)
for dx, dy in move:
if 0 <= nx + dx < 2 and 0 <= ny + dy < N:
q.append((nx + dx, ny + dy, maxN[nx][ny] + A[nx + dx][ny + dy]))
print((maxN[1][N - 1]))
return 0
if __name__ == "__main__":
solve() | import sys
from collections import deque
def solve():
input = sys.stdin.readline
N = int(eval(input()))
A = [[int(a) for a in input().split()] for _ in range(2)]
M = ((1, 0), (0, 1))
q = deque()
q.append((0, 0, 0))
C = [[0] * N for _ in range(2)]
while q:
i, j, n = q.popleft()
if n + A[i][j] > C[i][j]:
C[i][j] = n + A[i][j]
for di, dj in M:
if 0 <= i + di < 2 and 0 <= j + dj < N:
q.append((i + di, j + dj, C[i][j]))
print((C[1][N-1]))
return 0
if __name__ == "__main__":
solve() | 24 | 25 | 653 | 621 | import sys
from collections import deque
def solve():
input = sys.stdin.readline
N = int(eval(input()))
A = [[int(a) for a in input().split()] for _ in range(2)]
move = ((1, 0), (0, 1))
maxN = [[0 for _ in range(N)] for i in range(2)]
q = deque()
q.append((0, 0, A[0][0]))
while q:
nx, ny, np = q.popleft()
maxN[nx][ny] = max(maxN[nx][ny], np)
for dx, dy in move:
if 0 <= nx + dx < 2 and 0 <= ny + dy < N:
q.append((nx + dx, ny + dy, maxN[nx][ny] + A[nx + dx][ny + dy]))
print((maxN[1][N - 1]))
return 0
if __name__ == "__main__":
solve()
| import sys
from collections import deque
def solve():
input = sys.stdin.readline
N = int(eval(input()))
A = [[int(a) for a in input().split()] for _ in range(2)]
M = ((1, 0), (0, 1))
q = deque()
q.append((0, 0, 0))
C = [[0] * N for _ in range(2)]
while q:
i, j, n = q.popleft()
if n + A[i][j] > C[i][j]:
C[i][j] = n + A[i][j]
for di, dj in M:
if 0 <= i + di < 2 and 0 <= j + dj < N:
q.append((i + di, j + dj, C[i][j]))
print((C[1][N - 1]))
return 0
if __name__ == "__main__":
solve()
| false | 4 | [
"- move = ((1, 0), (0, 1))",
"- maxN = [[0 for _ in range(N)] for i in range(2)]",
"+ M = ((1, 0), (0, 1))",
"- q.append((0, 0, A[0][0]))",
"+ q.append((0, 0, 0))",
"+ C = [[0] * N for _ in range(2)]",
"- nx, ny, np = q.popleft()",
"- maxN[nx][ny] = max(maxN[nx][ny], np)",
"- for dx, dy in move:",
"- if 0 <= nx + dx < 2 and 0 <= ny + dy < N:",
"- q.append((nx + dx, ny + dy, maxN[nx][ny] + A[nx + dx][ny + dy]))",
"- print((maxN[1][N - 1]))",
"+ i, j, n = q.popleft()",
"+ if n + A[i][j] > C[i][j]:",
"+ C[i][j] = n + A[i][j]",
"+ for di, dj in M:",
"+ if 0 <= i + di < 2 and 0 <= j + dj < N:",
"+ q.append((i + di, j + dj, C[i][j]))",
"+ print((C[1][N - 1]))"
]
| false | 0.035907 | 0.036991 | 0.970715 | [
"s661030647",
"s110294272"
]
|
u573754721 | p02952 | python | s405302728 | s983728385 | 172 | 57 | 38,896 | 2,940 | Accepted | Accepted | 66.86 | N = int(eval(input()))
c = 0
for i in range(1,N + 1):
if len(str(i))%2 == 1:
c += 1
print(c)
| n=int(eval(input()))
c=0
for i in range(1,n+1):
if len(str(i))%2!=0:
c+=1
print(c)
| 8 | 6 | 115 | 100 | N = int(eval(input()))
c = 0
for i in range(1, N + 1):
if len(str(i)) % 2 == 1:
c += 1
print(c)
| n = int(eval(input()))
c = 0
for i in range(1, n + 1):
if len(str(i)) % 2 != 0:
c += 1
print(c)
| false | 25 | [
"-N = int(eval(input()))",
"+n = int(eval(input()))",
"-for i in range(1, N + 1):",
"- if len(str(i)) % 2 == 1:",
"+for i in range(1, n + 1):",
"+ if len(str(i)) % 2 != 0:"
]
| false | 0.054625 | 0.112358 | 0.486166 | [
"s405302728",
"s983728385"
]
|
u175111751 | p02420 | python | s148740790 | s044153794 | 50 | 30 | 7,976 | 7,640 | Accepted | Accepted | 40 | from collections import deque
while True:
s = eval(input())
if s == '-': break
else: ds = deque(s)
ds.rotate(sum([int(eval(input())) for _ in range(int(eval(input())))])*-1)
print((''.join(ds))) | while True:
s = eval(input())
if s == '-': break
l = sum([int(eval(input())) for _ in range(int(eval(input())))]) % len(s)
print((s[l:]+s[:l])) | 7 | 5 | 200 | 143 | from collections import deque
while True:
s = eval(input())
if s == "-":
break
else:
ds = deque(s)
ds.rotate(sum([int(eval(input())) for _ in range(int(eval(input())))]) * -1)
print(("".join(ds)))
| while True:
s = eval(input())
if s == "-":
break
l = sum([int(eval(input())) for _ in range(int(eval(input())))]) % len(s)
print((s[l:] + s[:l]))
| false | 28.571429 | [
"-from collections import deque",
"-",
"- else:",
"- ds = deque(s)",
"- ds.rotate(sum([int(eval(input())) for _ in range(int(eval(input())))]) * -1)",
"- print((\"\".join(ds)))",
"+ l = sum([int(eval(input())) for _ in range(int(eval(input())))]) % len(s)",
"+ print((s[l:] + s[:l]))"
]
| false | 0.037187 | 0.036868 | 1.008672 | [
"s148740790",
"s044153794"
]
|
u296150111 | p03031 | python | s716920386 | s828359867 | 56 | 33 | 3,064 | 3,064 | Accepted | Accepted | 41.07 | ks=[]
n,m=list(map(int,input().split()))
for i in range(m):
ks.append(list(map(int,input().split())))
p=list(map(int,input().split()))
ans_ans=0
for i in range(2**n):
num="0"*10+bin(i)
ans=0
for j in range(m):
cnt=0
for k in range(n):
if num[-k-1]=="1" and k+1 in ks[j][1:]:
cnt+=1
if cnt%2==p[j]:
ans+=1
if ans==m:
ans_ans+=1
print(ans_ans)
| n,m=list(map(int,input().split()))
ks=[]
for _ in range(m):
rr=list(map(int,input().split()))
ks.append(rr)
p=list(map(int,input().split()))
def two(x):
return "0"*(n-len(bin(x)[2:]))+bin(x)[2:]
ans=0
for i in range(2**n):
r=two(i)
f=1
for j in range(m):
cnt=0
for k in range(ks[j][0]):
if r[ks[j][k+1]-1]=="1":
cnt+=1
if cnt%2!=p[j]:
f=0
break
ans+=f
print(ans)
| 22 | 22 | 385 | 404 | ks = []
n, m = list(map(int, input().split()))
for i in range(m):
ks.append(list(map(int, input().split())))
p = list(map(int, input().split()))
ans_ans = 0
for i in range(2**n):
num = "0" * 10 + bin(i)
ans = 0
for j in range(m):
cnt = 0
for k in range(n):
if num[-k - 1] == "1" and k + 1 in ks[j][1:]:
cnt += 1
if cnt % 2 == p[j]:
ans += 1
if ans == m:
ans_ans += 1
print(ans_ans)
| n, m = list(map(int, input().split()))
ks = []
for _ in range(m):
rr = list(map(int, input().split()))
ks.append(rr)
p = list(map(int, input().split()))
def two(x):
return "0" * (n - len(bin(x)[2:])) + bin(x)[2:]
ans = 0
for i in range(2**n):
r = two(i)
f = 1
for j in range(m):
cnt = 0
for k in range(ks[j][0]):
if r[ks[j][k + 1] - 1] == "1":
cnt += 1
if cnt % 2 != p[j]:
f = 0
break
ans += f
print(ans)
| false | 0 | [
"+n, m = list(map(int, input().split()))",
"-n, m = list(map(int, input().split()))",
"-for i in range(m):",
"- ks.append(list(map(int, input().split())))",
"+for _ in range(m):",
"+ rr = list(map(int, input().split()))",
"+ ks.append(rr)",
"-ans_ans = 0",
"+",
"+",
"+def two(x):",
"+ return \"0\" * (n - len(bin(x)[2:])) + bin(x)[2:]",
"+",
"+",
"+ans = 0",
"- num = \"0\" * 10 + bin(i)",
"- ans = 0",
"+ r = two(i)",
"+ f = 1",
"- for k in range(n):",
"- if num[-k - 1] == \"1\" and k + 1 in ks[j][1:]:",
"+ for k in range(ks[j][0]):",
"+ if r[ks[j][k + 1] - 1] == \"1\":",
"- if cnt % 2 == p[j]:",
"- ans += 1",
"- if ans == m:",
"- ans_ans += 1",
"-print(ans_ans)",
"+ if cnt % 2 != p[j]:",
"+ f = 0",
"+ break",
"+ ans += f",
"+print(ans)"
]
| false | 0.066273 | 0.112023 | 0.591601 | [
"s716920386",
"s828359867"
]
|
u771007149 | p02678 | python | s018909000 | s691665218 | 781 | 665 | 34,312 | 34,208 | Accepted | Accepted | 14.85 | #D
from collections import deque
n,m = list(map(int,input().split()))
#インデックス→各部屋番号(-1),つながってる部屋の番号を格納
graph = [[] for _ in range(n)]
for _ in range(m):
a,b = list(map(int,input().split()))
graph[a-1].append(b-1)
graph[b-1].append(a-1)
#各部屋から1までの距離(初期値999)
bango = [-999 for _ in range(n)]
bango[0] = 0
#p->今いる部屋
p = deque()
p.append(0)
while not len(p)==0:
x = p.pop()
for i in graph[x]:
if bango[i] != -999:
pass
else:
p.appendleft(i)
#i番目の部屋はxからいける
bango[i] = x
print('Yes')
for i in range(1,n):
print((bango[i]+1)) | from collections import deque
n,m = list(map(int,input().split()))
graph = [[] for _ in range(n)]
for _ in range(m):
a,b = list(map(int,input().split()))
graph[a-1].append(b-1)
graph[b-1].append(a-1)
#部屋から1までの距離(深さ)
dist = [-100 for _ in range(n)]
dist[0] = 0
#幅優先探索でdistを更新
#pに今いる位置を格納
p = deque()
p.append(0)
while len(p) > 0:
now = p.pop()
for i in graph[now]:
if dist[i] != -100:
continue
p.appendleft(i)
dist[i] = now
print('Yes')
for i in range(1,n):
print((dist[i]+1)) | 31 | 30 | 630 | 568 | # D
from collections import deque
n, m = list(map(int, input().split()))
# インデックス→各部屋番号(-1),つながってる部屋の番号を格納
graph = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
graph[a - 1].append(b - 1)
graph[b - 1].append(a - 1)
# 各部屋から1までの距離(初期値999)
bango = [-999 for _ in range(n)]
bango[0] = 0
# p->今いる部屋
p = deque()
p.append(0)
while not len(p) == 0:
x = p.pop()
for i in graph[x]:
if bango[i] != -999:
pass
else:
p.appendleft(i)
# i番目の部屋はxからいける
bango[i] = x
print("Yes")
for i in range(1, n):
print((bango[i] + 1))
| from collections import deque
n, m = list(map(int, input().split()))
graph = [[] for _ in range(n)]
for _ in range(m):
a, b = list(map(int, input().split()))
graph[a - 1].append(b - 1)
graph[b - 1].append(a - 1)
# 部屋から1までの距離(深さ)
dist = [-100 for _ in range(n)]
dist[0] = 0
# 幅優先探索でdistを更新
# pに今いる位置を格納
p = deque()
p.append(0)
while len(p) > 0:
now = p.pop()
for i in graph[now]:
if dist[i] != -100:
continue
p.appendleft(i)
dist[i] = now
print("Yes")
for i in range(1, n):
print((dist[i] + 1))
| false | 3.225806 | [
"-# D",
"-# インデックス→各部屋番号(-1),つながってる部屋の番号を格納",
"-# 各部屋から1までの距離(初期値999)",
"-bango = [-999 for _ in range(n)]",
"-bango[0] = 0",
"-# p->今いる部屋",
"+# 部屋から1までの距離(深さ)",
"+dist = [-100 for _ in range(n)]",
"+dist[0] = 0",
"+# 幅優先探索でdistを更新",
"+# pに今いる位置を格納",
"-while not len(p) == 0:",
"- x = p.pop()",
"- for i in graph[x]:",
"- if bango[i] != -999:",
"- pass",
"- else:",
"- p.appendleft(i)",
"- # i番目の部屋はxからいける",
"- bango[i] = x",
"+while len(p) > 0:",
"+ now = p.pop()",
"+ for i in graph[now]:",
"+ if dist[i] != -100:",
"+ continue",
"+ p.appendleft(i)",
"+ dist[i] = now",
"- print((bango[i] + 1))",
"+ print((dist[i] + 1))"
]
| false | 0.068928 | 0.063616 | 1.083497 | [
"s018909000",
"s691665218"
]
|
u296518383 | p03503 | python | s732000208 | s307907955 | 272 | 212 | 3,956 | 42,092 | Accepted | Accepted | 22.06 | N=int(eval(input()))
M=[[0 for i in range(2**10)] for j in range(N)]
K=[0]*(2**10)
F=[list(map(int,input().split())) for _ in range(N)]
P=[list(map(int,input().split())) for _ in range(N)]
for i in range(2**10):
for j in range(10):
for k in range(N):
if (i>>9-j)&1 and F[k][j]:
#print(i,j)
M[k][i]+=1
for i in range(2**10):
for k in range(N):
K[i]+=P[k][M[k][i]]
print((max(K[1:]))) | N = int(eval(input()))
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
answer = []
for i in range(1, 2 ** 10):
tmp = 0
for j in range(N):
cnt = 0
for k in range(10):
if (i >> k) & 1 and F[j][k]:
cnt += 1
tmp += P[j][cnt]
answer.append(tmp)
print((max(answer))) | 17 | 16 | 426 | 367 | N = int(eval(input()))
M = [[0 for i in range(2**10)] for j in range(N)]
K = [0] * (2**10)
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
for i in range(2**10):
for j in range(10):
for k in range(N):
if (i >> 9 - j) & 1 and F[k][j]:
# print(i,j)
M[k][i] += 1
for i in range(2**10):
for k in range(N):
K[i] += P[k][M[k][i]]
print((max(K[1:])))
| N = int(eval(input()))
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
answer = []
for i in range(1, 2**10):
tmp = 0
for j in range(N):
cnt = 0
for k in range(10):
if (i >> k) & 1 and F[j][k]:
cnt += 1
tmp += P[j][cnt]
answer.append(tmp)
print((max(answer)))
| false | 5.882353 | [
"-M = [[0 for i in range(2**10)] for j in range(N)]",
"-K = [0] * (2**10)",
"-for i in range(2**10):",
"- for j in range(10):",
"- for k in range(N):",
"- if (i >> 9 - j) & 1 and F[k][j]:",
"- # print(i,j)",
"- M[k][i] += 1",
"-for i in range(2**10):",
"- for k in range(N):",
"- K[i] += P[k][M[k][i]]",
"-print((max(K[1:])))",
"+answer = []",
"+for i in range(1, 2**10):",
"+ tmp = 0",
"+ for j in range(N):",
"+ cnt = 0",
"+ for k in range(10):",
"+ if (i >> k) & 1 and F[j][k]:",
"+ cnt += 1",
"+ tmp += P[j][cnt]",
"+ answer.append(tmp)",
"+print((max(answer)))"
]
| false | 0.064485 | 0.107066 | 0.602298 | [
"s732000208",
"s307907955"
]
|
u535803878 | p02579 | python | s805655677 | s621658690 | 1,611 | 821 | 123,920 | 117,872 | Accepted | Accepted | 49.04 | import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
import numpy as np
from numba import njit, b1, i4, i8, f8
from heapq import heappop as hpp, heappush as hp
h,w = list(map(int, input().split()))
ch,cw = list(map(int, input().split()))
dh,dw = list(map(int, input().split()))
ch -= 1
cw -= 1
dh -= 1
dw -= 1
rows,cols = h,w
OK = "."
NG = "#"
@njit((b1[:, :],i8,i8,i8,i8), cache=True)
def main(ss,ch,cw,dh,dw):
inf = 1<<30
h,w = ss.shape
start = ch*w+cw
goal = dh*w+dw
n = h*w
seen = np.full(n, inf, np.int64)
seen[start] = 0
q = [(0, start)] # ワープ回数, 現在位置, 最後の道の位置
while q:
pnum,pu = hpp(q)
ux,uy = divmod(pu,w)
if pu==goal:
break
for xx in range(-2, 3):
for yy in range(-2, 3):
if xx==yy==0:
continue
if abs(xx)+abs(yy)<=1:
vv = 0
else:
vv = 1
x,y = ux+xx, uy+yy
u = x*w + y
num = pnum+vv
if x<0 or y<0 or x>=h or y>=w or ss[x][y]:
continue
# print(x,y)
if seen[u]>num:
seen[u] = num
hp(q,(num, u))
val = seen[goal]
if val==inf:
return -1
else:
return val
ss = np.array([[c=="#" for c in eval(input())] for _ in range(h)])
print((main(ss,ch,cw,dh,dw))) | import numpy as np
from numba import njit, b1, i4, i8, f8
from heapq import heappop as hpp, heappush as hp
@njit((b1[:, :],i8,i8,i8,i8), cache=True)
def main(ss,ch,cw,dh,dw):
inf = 1<<30
h,w = ss.shape
start = ch*w+cw
goal = dh*w+dw
n = h*w
seen = np.full(n, inf, np.int64)
seen[start] = 0
q = [(0, start)] # ワープ回数, 現在位置, 最後の道の位置
while q:
pnum,pu = hpp(q)
ux,uy = divmod(pu,w)
if pu==goal:
break
for xx in range(-2, 3):
for yy in range(-2, 3):
if xx==yy==0:
continue
if abs(xx)+abs(yy)<=1:
vv = 0
else:
vv = 1
x,y = ux+xx, uy+yy
u = x*w + y
num = pnum+vv
if x<0 or y<0 or x>=h or y>=w or ss[x][y]:
continue
# print(x,y)
if seen[u]>num:
seen[u] = num
hp(q,(num, u))
val = seen[goal]
if val==inf:
return -1
else:
return val
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")
h,w = list(map(int, input().split()))
ch,cw = list(map(int, input().split()))
dh,dw = list(map(int, input().split()))
ch -= 1
cw -= 1
dh -= 1
dw -= 1
rows,cols = h,w
OK = "."
NG = "#"
ss = np.array([[c=="#" for c in eval(input())] for _ in range(h)])
print((main(ss,ch,cw,dh,dw))) | 63 | 63 | 1,586 | 1,592 | import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
import numpy as np
from numba import njit, b1, i4, i8, f8
from heapq import heappop as hpp, heappush as hp
h, w = list(map(int, input().split()))
ch, cw = list(map(int, input().split()))
dh, dw = list(map(int, input().split()))
ch -= 1
cw -= 1
dh -= 1
dw -= 1
rows, cols = h, w
OK = "."
NG = "#"
@njit((b1[:, :], i8, i8, i8, i8), cache=True)
def main(ss, ch, cw, dh, dw):
inf = 1 << 30
h, w = ss.shape
start = ch * w + cw
goal = dh * w + dw
n = h * w
seen = np.full(n, inf, np.int64)
seen[start] = 0
q = [(0, start)] # ワープ回数, 現在位置, 最後の道の位置
while q:
pnum, pu = hpp(q)
ux, uy = divmod(pu, w)
if pu == goal:
break
for xx in range(-2, 3):
for yy in range(-2, 3):
if xx == yy == 0:
continue
if abs(xx) + abs(yy) <= 1:
vv = 0
else:
vv = 1
x, y = ux + xx, uy + yy
u = x * w + y
num = pnum + vv
if x < 0 or y < 0 or x >= h or y >= w or ss[x][y]:
continue
# print(x,y)
if seen[u] > num:
seen[u] = num
hp(q, (num, u))
val = seen[goal]
if val == inf:
return -1
else:
return val
ss = np.array([[c == "#" for c in eval(input())] for _ in range(h)])
print((main(ss, ch, cw, dh, dw)))
| import numpy as np
from numba import njit, b1, i4, i8, f8
from heapq import heappop as hpp, heappush as hp
@njit((b1[:, :], i8, i8, i8, i8), cache=True)
def main(ss, ch, cw, dh, dw):
inf = 1 << 30
h, w = ss.shape
start = ch * w + cw
goal = dh * w + dw
n = h * w
seen = np.full(n, inf, np.int64)
seen[start] = 0
q = [(0, start)] # ワープ回数, 現在位置, 最後の道の位置
while q:
pnum, pu = hpp(q)
ux, uy = divmod(pu, w)
if pu == goal:
break
for xx in range(-2, 3):
for yy in range(-2, 3):
if xx == yy == 0:
continue
if abs(xx) + abs(yy) <= 1:
vv = 0
else:
vv = 1
x, y = ux + xx, uy + yy
u = x * w + y
num = pnum + vv
if x < 0 or y < 0 or x >= h or y >= w or ss[x][y]:
continue
# print(x,y)
if seen[u] > num:
seen[u] = num
hp(q, (num, u))
val = seen[goal]
if val == inf:
return -1
else:
return val
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
h, w = list(map(int, input().split()))
ch, cw = list(map(int, input().split()))
dh, dw = list(map(int, input().split()))
ch -= 1
cw -= 1
dh -= 1
dw -= 1
rows, cols = h, w
OK = "."
NG = "#"
ss = np.array([[c == "#" for c in eval(input())] for _ in range(h)])
print((main(ss, ch, cw, dh, dw)))
| false | 0 | [
"-import sys",
"-",
"-input = lambda: sys.stdin.readline().rstrip()",
"-sys.setrecursionlimit(max(1000, 10**9))",
"-write = lambda x: sys.stdout.write(x + \"\\n\")",
"-",
"-h, w = list(map(int, input().split()))",
"-ch, cw = list(map(int, input().split()))",
"-dh, dw = list(map(int, input().split()))",
"-ch -= 1",
"-cw -= 1",
"-dh -= 1",
"-dw -= 1",
"-rows, cols = h, w",
"-OK = \".\"",
"-NG = \"#\"",
"+import sys",
"+",
"+input = lambda: sys.stdin.readline().rstrip()",
"+sys.setrecursionlimit(max(1000, 10**9))",
"+write = lambda x: sys.stdout.write(x + \"\\n\")",
"+h, w = list(map(int, input().split()))",
"+ch, cw = list(map(int, input().split()))",
"+dh, dw = list(map(int, input().split()))",
"+ch -= 1",
"+cw -= 1",
"+dh -= 1",
"+dw -= 1",
"+rows, cols = h, w",
"+OK = \".\"",
"+NG = \"#\""
]
| false | 0.174209 | 0.17406 | 1.000853 | [
"s805655677",
"s621658690"
]
|
u201234972 | p03855 | python | s206542960 | s065129841 | 1,473 | 1,290 | 61,952 | 62,012 | Accepted | Accepted | 12.42 | from collections import defaultdict
def find(x, A):
p = A[x]
if p == x:
return x
a = find(p, A)
A[x] = a
find(a,A)
return a
N, K, L = list(map( int, input().split()))
V = [ i for i in range(N)]
W = [ i for i in range(N)]
for _ in range(K):
p, q = list(map( int, input().split()))
p, q = p-1, q-1
bp, bq = find(p,V), find(q,V)
V[q] = bp
V[bq] = bp
for _ in range(L):
r, s = list(map( int, input().split()))
r, s = r-1, s-1
br, bs = find(r,W), find(s,W)
W[s] = br
W[bs] = br
d = defaultdict(int)
for i in range(N):
d[(find(i,V), find(i, W))] += 1
ANS = [0]*N
for i in range(N):
ANS[i] = d[(find(i,V), find(i, W))]
print((' '.join( map( str, ANS)))) | from collections import defaultdict
def find(x, A): #unionfind
p = A[x]
if p == x:
return x
a = find(p, A)
A[x] = a
return a
N, K, L = list(map( int, input().split()))
V = [ i for i in range(N)]
W = [ i for i in range(N)]
for _ in range(K):
p, q = list(map( int, input().split()))
p, q = p-1, q-1
bp, bq = find(p,V), find(q,V)
V[q] = bp
V[bq] = bp
for _ in range(L):
r, s = list(map( int, input().split()))
r, s = r-1, s-1
br, bs = find(r,W), find(s,W)
W[s] = br
W[bs] = br
d = defaultdict(int) #デフォルトで0を返す。
for i in range(N):
d[(find(i,V), find(i, W))] += 1
ANS = [0]*N
for i in range(N):
ANS[i] = d[(find(i,V), find(i, W))]
print((' '.join( map( str, ANS)))) | 35 | 34 | 744 | 753 | from collections import defaultdict
def find(x, A):
p = A[x]
if p == x:
return x
a = find(p, A)
A[x] = a
find(a, A)
return a
N, K, L = list(map(int, input().split()))
V = [i for i in range(N)]
W = [i for i in range(N)]
for _ in range(K):
p, q = list(map(int, input().split()))
p, q = p - 1, q - 1
bp, bq = find(p, V), find(q, V)
V[q] = bp
V[bq] = bp
for _ in range(L):
r, s = list(map(int, input().split()))
r, s = r - 1, s - 1
br, bs = find(r, W), find(s, W)
W[s] = br
W[bs] = br
d = defaultdict(int)
for i in range(N):
d[(find(i, V), find(i, W))] += 1
ANS = [0] * N
for i in range(N):
ANS[i] = d[(find(i, V), find(i, W))]
print((" ".join(map(str, ANS))))
| from collections import defaultdict
def find(x, A): # unionfind
p = A[x]
if p == x:
return x
a = find(p, A)
A[x] = a
return a
N, K, L = list(map(int, input().split()))
V = [i for i in range(N)]
W = [i for i in range(N)]
for _ in range(K):
p, q = list(map(int, input().split()))
p, q = p - 1, q - 1
bp, bq = find(p, V), find(q, V)
V[q] = bp
V[bq] = bp
for _ in range(L):
r, s = list(map(int, input().split()))
r, s = r - 1, s - 1
br, bs = find(r, W), find(s, W)
W[s] = br
W[bs] = br
d = defaultdict(int) # デフォルトで0を返す。
for i in range(N):
d[(find(i, V), find(i, W))] += 1
ANS = [0] * N
for i in range(N):
ANS[i] = d[(find(i, V), find(i, W))]
print((" ".join(map(str, ANS))))
| false | 2.857143 | [
"-def find(x, A):",
"+def find(x, A): # unionfind",
"- find(a, A)",
"-d = defaultdict(int)",
"+d = defaultdict(int) # デフォルトで0を返す。"
]
| false | 0.040269 | 0.043916 | 0.916947 | [
"s206542960",
"s065129841"
]
|
u186838327 | p02983 | python | s024629244 | s922457367 | 300 | 234 | 40,812 | 41,196 | Accepted | Accepted | 22 | import itertools
l, r = list(map(int, input().split()))
if r-l >= 2018:
print((0))
else:
l_mod = l%2019
r_mod = r%2019
min_mod = float('inf')
if l_mod <= r_mod:
for c in itertools.combinations(list(range(l_mod, r_mod+1)), 2):
min_mod = min(min_mod, (c[0]*c[1])%2019)
print(min_mod)
else:
print((0))
| l, r = list(map(int, input().split()))
if r-l+1 >= 2019:
print((0))
else:
l %= 2019
r %= 2019
if l <= r:
ans = float('inf')
for i in range(l, r):
for j in range(i+1, r+1):
ans = min(ans, (i*j)%2019)
else:
ans = 0
print(ans) | 19 | 14 | 340 | 304 | import itertools
l, r = list(map(int, input().split()))
if r - l >= 2018:
print((0))
else:
l_mod = l % 2019
r_mod = r % 2019
min_mod = float("inf")
if l_mod <= r_mod:
for c in itertools.combinations(list(range(l_mod, r_mod + 1)), 2):
min_mod = min(min_mod, (c[0] * c[1]) % 2019)
print(min_mod)
else:
print((0))
| l, r = list(map(int, input().split()))
if r - l + 1 >= 2019:
print((0))
else:
l %= 2019
r %= 2019
if l <= r:
ans = float("inf")
for i in range(l, r):
for j in range(i + 1, r + 1):
ans = min(ans, (i * j) % 2019)
else:
ans = 0
print(ans)
| false | 26.315789 | [
"-import itertools",
"-",
"-if r - l >= 2018:",
"+if r - l + 1 >= 2019:",
"- l_mod = l % 2019",
"- r_mod = r % 2019",
"- min_mod = float(\"inf\")",
"- if l_mod <= r_mod:",
"- for c in itertools.combinations(list(range(l_mod, r_mod + 1)), 2):",
"- min_mod = min(min_mod, (c[0] * c[1]) % 2019)",
"- print(min_mod)",
"+ l %= 2019",
"+ r %= 2019",
"+ if l <= r:",
"+ ans = float(\"inf\")",
"+ for i in range(l, r):",
"+ for j in range(i + 1, r + 1):",
"+ ans = min(ans, (i * j) % 2019)",
"- print((0))",
"+ ans = 0",
"+ print(ans)"
]
| false | 0.037463 | 0.070883 | 0.528519 | [
"s024629244",
"s922457367"
]
|
u911449886 | p02901 | python | s463128377 | s756832665 | 1,985 | 329 | 96,292 | 76,512 | Accepted | Accepted | 83.43 | from sys import stdin
def getval():
n,m = list(map(int,input().split()))
ab = []
c = []
def tobit(arr):
idx = len(arr)-1
s = ""
for i in range(n-1,-1,-1):
if arr[idx]-1==i and idx!=-1:
s = "".join([s,"1"])
idx -= 1
else:
s = "".join([s,"0"])
return s
for i in range(m):
ab.append(list(map(int,stdin.readline().split())))
c.append(tobit(list(map(int,stdin.readline().split()))))
return n,m,ab,c
def main(n,m,ab,c):
dp = [-1 for i in range(2**n)]
dp[0] = 0
def intersect(bit1,bit2):
s = ""
for i in range(n):
if bit1[i]=="1" or bit2[i]=="1":
s = "".join([s,"1"])
else:
s = "".join([s,"0"])
return int(s,2)
for i in range(m):
curc = ab[i][0]
curk = c[i]
temp = [-1 for i in range(2**n)]
for j in range(2**n):
if dp[j]==-1:
continue
new = dp[j]
s = bin(j)[2:]
if len(s)!=n:
while len(s)<n:
s = "".join(["0",s])
update = intersect(curk,s)
#print(i,j,update,new,curc,curk,s)
target = temp[update]
if target==-1:
temp[update] = new+curc
elif target>new+curc:
temp[update] = new+curc
if new<temp[j] or temp[j]==-1:
temp[j] = dp[j]
dp = temp
#print(dp)
print((dp[-1]))
if __name__=="__main__":
n,m,ab,c = getval()
main(n,m,ab,c) | from sys import stdin
def getval():
n,m = list(map(int,input().split()))
ab = []
c = []
def tobit(arr):
idx = len(arr)-1
s = ""
for i in range(n-1,-1,-1):
if arr[idx]-1==i and idx!=-1:
s = "".join([s,"1"])
idx -= 1
else:
s = "".join([s,"0"])
return s
for i in range(m):
ab.append(list(map(int,stdin.readline().split())))
c.append(tobit(list(map(int,stdin.readline().split()))))
return n,m,ab,c
def main(n,m,ab,c):
dp = [-1 for i in range(2**n)]
dp[0] = 0
for i in range(m):
curc = ab[i][0]
curk = c[i]
temp = [-1 for i in range(2**n)]
for j in range(2**n):
if dp[j]==-1:
continue
new = dp[j]
update = int(curk,2)|j
#print(i,j,update,new,curc,curk,s)
target = temp[update]
if target==-1:
temp[update] = new+curc
elif target>new+curc:
temp[update] = new+curc
if new<temp[j] or temp[j]==-1:
temp[j] = dp[j]
dp = temp
#print(dp)
print((dp[-1]))
if __name__=="__main__":
n,m,ab,c = getval()
main(n,m,ab,c) | 66 | 52 | 1,778 | 1,391 | from sys import stdin
def getval():
n, m = list(map(int, input().split()))
ab = []
c = []
def tobit(arr):
idx = len(arr) - 1
s = ""
for i in range(n - 1, -1, -1):
if arr[idx] - 1 == i and idx != -1:
s = "".join([s, "1"])
idx -= 1
else:
s = "".join([s, "0"])
return s
for i in range(m):
ab.append(list(map(int, stdin.readline().split())))
c.append(tobit(list(map(int, stdin.readline().split()))))
return n, m, ab, c
def main(n, m, ab, c):
dp = [-1 for i in range(2**n)]
dp[0] = 0
def intersect(bit1, bit2):
s = ""
for i in range(n):
if bit1[i] == "1" or bit2[i] == "1":
s = "".join([s, "1"])
else:
s = "".join([s, "0"])
return int(s, 2)
for i in range(m):
curc = ab[i][0]
curk = c[i]
temp = [-1 for i in range(2**n)]
for j in range(2**n):
if dp[j] == -1:
continue
new = dp[j]
s = bin(j)[2:]
if len(s) != n:
while len(s) < n:
s = "".join(["0", s])
update = intersect(curk, s)
# print(i,j,update,new,curc,curk,s)
target = temp[update]
if target == -1:
temp[update] = new + curc
elif target > new + curc:
temp[update] = new + curc
if new < temp[j] or temp[j] == -1:
temp[j] = dp[j]
dp = temp
# print(dp)
print((dp[-1]))
if __name__ == "__main__":
n, m, ab, c = getval()
main(n, m, ab, c)
| from sys import stdin
def getval():
n, m = list(map(int, input().split()))
ab = []
c = []
def tobit(arr):
idx = len(arr) - 1
s = ""
for i in range(n - 1, -1, -1):
if arr[idx] - 1 == i and idx != -1:
s = "".join([s, "1"])
idx -= 1
else:
s = "".join([s, "0"])
return s
for i in range(m):
ab.append(list(map(int, stdin.readline().split())))
c.append(tobit(list(map(int, stdin.readline().split()))))
return n, m, ab, c
def main(n, m, ab, c):
dp = [-1 for i in range(2**n)]
dp[0] = 0
for i in range(m):
curc = ab[i][0]
curk = c[i]
temp = [-1 for i in range(2**n)]
for j in range(2**n):
if dp[j] == -1:
continue
new = dp[j]
update = int(curk, 2) | j
# print(i,j,update,new,curc,curk,s)
target = temp[update]
if target == -1:
temp[update] = new + curc
elif target > new + curc:
temp[update] = new + curc
if new < temp[j] or temp[j] == -1:
temp[j] = dp[j]
dp = temp
# print(dp)
print((dp[-1]))
if __name__ == "__main__":
n, m, ab, c = getval()
main(n, m, ab, c)
| false | 21.212121 | [
"-",
"- def intersect(bit1, bit2):",
"- s = \"\"",
"- for i in range(n):",
"- if bit1[i] == \"1\" or bit2[i] == \"1\":",
"- s = \"\".join([s, \"1\"])",
"- else:",
"- s = \"\".join([s, \"0\"])",
"- return int(s, 2)",
"-",
"- s = bin(j)[2:]",
"- if len(s) != n:",
"- while len(s) < n:",
"- s = \"\".join([\"0\", s])",
"- update = intersect(curk, s)",
"+ update = int(curk, 2) | j"
]
| false | 0.045701 | 0.217982 | 0.209656 | [
"s463128377",
"s756832665"
]
|
u596276291 | p03795 | python | s353238210 | s742115141 | 33 | 27 | 3,444 | 3,944 | Accepted | Accepted | 18.18 | from collections import defaultdict
def main():
N = int(eval(input()))
print((800 * N - (N // 15) * 200))
if __name__ == '__main__':
main()
| from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def main():
N = int(eval(input()))
print((800 * N - 200 * (N // 15)))
if __name__ == '__main__':
main()
| 10 | 30 | 157 | 778 | from collections import defaultdict
def main():
N = int(eval(input()))
print((800 * N - (N // 15) * 200))
if __name__ == "__main__":
main()
| from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def main():
N = int(eval(input()))
print((800 * N - 200 * (N // 15)))
if __name__ == "__main__":
main()
| false | 66.666667 | [
"-from collections import defaultdict",
"+from collections import defaultdict, Counter",
"+from itertools import product, groupby, count, permutations, combinations",
"+from math import pi, sqrt",
"+from collections import deque",
"+from bisect import bisect, bisect_left, bisect_right",
"+from string import ascii_lowercase",
"+from functools import lru_cache",
"+import sys",
"+",
"+sys.setrecursionlimit(10000)",
"+INF = float(\"inf\")",
"+YES, Yes, yes, NO, No, no = \"YES\", \"Yes\", \"yes\", \"NO\", \"No\", \"no\"",
"+dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]",
"+dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]",
"+",
"+",
"+def inside(y, x, H, W):",
"+ return 0 <= y < H and 0 <= x < W",
"+",
"+",
"+def ceil(a, b):",
"+ return (a + b - 1) // b",
"- print((800 * N - (N // 15) * 200))",
"+ print((800 * N - 200 * (N // 15)))"
]
| false | 0.045981 | 0.037633 | 1.221819 | [
"s353238210",
"s742115141"
]
|
u057109575 | p02949 | python | s221975053 | s405160049 | 969 | 507 | 65,368 | 87,988 | Accepted | Accepted | 47.68 | import sys
sys.setrecursionlimit(10 ** 9)
N, M, P = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(M)]
edges = [[] for _ in range(N)]
to = [[] for _ in range(N)]
ot = [[] for _ in range(N)]
for a, b, c in X:
a -= 1
b -= 1
c = -(c - P)
edges[a].append((b, c))
to[a].append(b)
ot[b].append(a)
ok_1 = [False] * N
ok_n = [False] * N
# Reachable
def dfs(u):
if ok_1[u]:
return
ok_1[u] = True
for v in to[u]:
dfs(v)
def rdfs(u):
if ok_n[u]:
return
ok_n[u] = True
for v in ot[u]:
rdfs(v)
dfs(0)
rdfs(N - 1)
flag = [ok_1[i] & ok_n[i] for i in range(N)]
# Bellman ford
INF = 10 ** 9 + 7
d = [INF] * N
d[0] = 0
cnt = 0
updated = True
while updated and cnt <= N:
updated = False
cnt += 1
for u in range(N):
if not flag[u]:
continue
for v, c in edges[u]:
if not flag[v]:
continue
value = d[u] + c
if d[v] > d[u] + c:
d[v] = value
updated = True
if cnt > N:
print((-1))
else:
print((max(0, -d[-1])))
| from collections import deque
import sys
sys.setrecursionlimit(10 ** 9)
N, M, P = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(M)]
to = [[] for _ in range(N + 1)]
ot = [[] for _ in range(N + 1)]
edges = [[] for _ in range(N + 1)]
for a, b, c in X:
edges[a].append((b, c - P))
to[a].append(b)
ot[b].append(a)
ok_1 = [False] * (N + 1)
ok_n = [False] * (N + 1)
def dfs_1(u):
if ok_1[u]:
return
ok_1[u] = True
for v in to[u]:
dfs_1(v)
def dfs_n(u):
if ok_n[u]:
return
ok_n[u] = True
for v in ot[u]:
dfs_n(v)
dfs_1(1)
dfs_n(N)
INF = 10 ** 9 + 7
d = [INF] * (N + 1)
d[1] = 0
updated = True
cnt = 0
while updated and cnt <= N:
updated = False
cnt += 1
for u in range(1, N + 1):
if not ok_1[u] or not ok_n[u]:
continue
for v, c in edges[u]:
if not ok_1[v] or not ok_n[v]:
continue
if d[v] > d[u] - c:
d[v] = d[u] - c
updated = True
if cnt > N:
print((-1))
else:
print((max(0, -d[-1])))
| 67 | 62 | 1,228 | 1,213 | import sys
sys.setrecursionlimit(10**9)
N, M, P = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(M)]
edges = [[] for _ in range(N)]
to = [[] for _ in range(N)]
ot = [[] for _ in range(N)]
for a, b, c in X:
a -= 1
b -= 1
c = -(c - P)
edges[a].append((b, c))
to[a].append(b)
ot[b].append(a)
ok_1 = [False] * N
ok_n = [False] * N
# Reachable
def dfs(u):
if ok_1[u]:
return
ok_1[u] = True
for v in to[u]:
dfs(v)
def rdfs(u):
if ok_n[u]:
return
ok_n[u] = True
for v in ot[u]:
rdfs(v)
dfs(0)
rdfs(N - 1)
flag = [ok_1[i] & ok_n[i] for i in range(N)]
# Bellman ford
INF = 10**9 + 7
d = [INF] * N
d[0] = 0
cnt = 0
updated = True
while updated and cnt <= N:
updated = False
cnt += 1
for u in range(N):
if not flag[u]:
continue
for v, c in edges[u]:
if not flag[v]:
continue
value = d[u] + c
if d[v] > d[u] + c:
d[v] = value
updated = True
if cnt > N:
print((-1))
else:
print((max(0, -d[-1])))
| from collections import deque
import sys
sys.setrecursionlimit(10**9)
N, M, P = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(M)]
to = [[] for _ in range(N + 1)]
ot = [[] for _ in range(N + 1)]
edges = [[] for _ in range(N + 1)]
for a, b, c in X:
edges[a].append((b, c - P))
to[a].append(b)
ot[b].append(a)
ok_1 = [False] * (N + 1)
ok_n = [False] * (N + 1)
def dfs_1(u):
if ok_1[u]:
return
ok_1[u] = True
for v in to[u]:
dfs_1(v)
def dfs_n(u):
if ok_n[u]:
return
ok_n[u] = True
for v in ot[u]:
dfs_n(v)
dfs_1(1)
dfs_n(N)
INF = 10**9 + 7
d = [INF] * (N + 1)
d[1] = 0
updated = True
cnt = 0
while updated and cnt <= N:
updated = False
cnt += 1
for u in range(1, N + 1):
if not ok_1[u] or not ok_n[u]:
continue
for v, c in edges[u]:
if not ok_1[v] or not ok_n[v]:
continue
if d[v] > d[u] - c:
d[v] = d[u] - c
updated = True
if cnt > N:
print((-1))
else:
print((max(0, -d[-1])))
| false | 7.462687 | [
"+from collections import deque",
"-edges = [[] for _ in range(N)]",
"-to = [[] for _ in range(N)]",
"-ot = [[] for _ in range(N)]",
"+to = [[] for _ in range(N + 1)]",
"+ot = [[] for _ in range(N + 1)]",
"+edges = [[] for _ in range(N + 1)]",
"- a -= 1",
"- b -= 1",
"- c = -(c - P)",
"- edges[a].append((b, c))",
"+ edges[a].append((b, c - P))",
"-ok_1 = [False] * N",
"-ok_n = [False] * N",
"-# Reachable",
"-def dfs(u):",
"+ok_1 = [False] * (N + 1)",
"+ok_n = [False] * (N + 1)",
"+",
"+",
"+def dfs_1(u):",
"- dfs(v)",
"+ dfs_1(v)",
"-def rdfs(u):",
"+def dfs_n(u):",
"- rdfs(v)",
"+ dfs_n(v)",
"-dfs(0)",
"-rdfs(N - 1)",
"-flag = [ok_1[i] & ok_n[i] for i in range(N)]",
"-# Bellman ford",
"+dfs_1(1)",
"+dfs_n(N)",
"-d = [INF] * N",
"-d[0] = 0",
"+d = [INF] * (N + 1)",
"+d[1] = 0",
"+updated = True",
"-updated = True",
"- for u in range(N):",
"- if not flag[u]:",
"+ for u in range(1, N + 1):",
"+ if not ok_1[u] or not ok_n[u]:",
"- if not flag[v]:",
"+ if not ok_1[v] or not ok_n[v]:",
"- value = d[u] + c",
"- if d[v] > d[u] + c:",
"- d[v] = value",
"+ if d[v] > d[u] - c:",
"+ d[v] = d[u] - c"
]
| false | 0.06444 | 0.064443 | 0.999963 | [
"s221975053",
"s405160049"
]
|
u343977188 | p02708 | python | s911084455 | s249046595 | 171 | 146 | 9,168 | 9,124 | Accepted | Accepted | 14.62 | N,K=list(map(int,input().split()))
p=10**9 + 7
ans=0
for i in range(K-1,N+1):
L_min=i*(i+1)//2
L_max=(N*(N+1)//2)-((N-i-1)*(N-i)//2)
ans += (L_max-L_min+1)%p
print((ans%p)) | N,K=list(map(int,input().split()))
p=10**9 + 7
L_min,L_max=0,0
for i in range(K-1,N+1):
L_min+=i*(i+1)//2 - 1
L_max+=(N*(N+1)//2)-((N-i-1)*(N-i)//2)
ans = (L_max-L_min)%p
print(ans)
| 8 | 8 | 177 | 187 | N, K = list(map(int, input().split()))
p = 10**9 + 7
ans = 0
for i in range(K - 1, N + 1):
L_min = i * (i + 1) // 2
L_max = (N * (N + 1) // 2) - ((N - i - 1) * (N - i) // 2)
ans += (L_max - L_min + 1) % p
print((ans % p))
| N, K = list(map(int, input().split()))
p = 10**9 + 7
L_min, L_max = 0, 0
for i in range(K - 1, N + 1):
L_min += i * (i + 1) // 2 - 1
L_max += (N * (N + 1) // 2) - ((N - i - 1) * (N - i) // 2)
ans = (L_max - L_min) % p
print(ans)
| false | 0 | [
"-ans = 0",
"+L_min, L_max = 0, 0",
"- L_min = i * (i + 1) // 2",
"- L_max = (N * (N + 1) // 2) - ((N - i - 1) * (N - i) // 2)",
"- ans += (L_max - L_min + 1) % p",
"-print((ans % p))",
"+ L_min += i * (i + 1) // 2 - 1",
"+ L_max += (N * (N + 1) // 2) - ((N - i - 1) * (N - i) // 2)",
"+ans = (L_max - L_min) % p",
"+print(ans)"
]
| false | 0.061995 | 0.0608 | 1.019651 | [
"s911084455",
"s249046595"
]
|
u440180827 | p00008 | python | s099222929 | s930449618 | 200 | 60 | 7,476 | 7,688 | Accepted | Accepted | 70 | import sys
for line in sys.stdin:
n = int(line)
count = 0
for i in range(10):
for j in range(10):
for k in range(10):
for l in range(10):
if i + j + k + l == n:
count += 1
print(count) | import sys
t = [0 for i in range(10000)]
c = 0
for i in range(10):
for j in range(10):
for k in range(10):
for l in range(10):
t[c] = i + j + k + l
c += 1
for line in sys.stdin:
print((t.count(int(line)))) | 11 | 11 | 290 | 273 | import sys
for line in sys.stdin:
n = int(line)
count = 0
for i in range(10):
for j in range(10):
for k in range(10):
for l in range(10):
if i + j + k + l == n:
count += 1
print(count)
| import sys
t = [0 for i in range(10000)]
c = 0
for i in range(10):
for j in range(10):
for k in range(10):
for l in range(10):
t[c] = i + j + k + l
c += 1
for line in sys.stdin:
print((t.count(int(line))))
| false | 0 | [
"+t = [0 for i in range(10000)]",
"+c = 0",
"+for i in range(10):",
"+ for j in range(10):",
"+ for k in range(10):",
"+ for l in range(10):",
"+ t[c] = i + j + k + l",
"+ c += 1",
"- n = int(line)",
"- count = 0",
"- for i in range(10):",
"- for j in range(10):",
"- for k in range(10):",
"- for l in range(10):",
"- if i + j + k + l == n:",
"- count += 1",
"- print(count)",
"+ print((t.count(int(line))))"
]
| false | 0.040095 | 0.039528 | 1.014324 | [
"s099222929",
"s930449618"
]
|
u349449706 | p02536 | python | s106024220 | s892217958 | 325 | 291 | 82,228 | 86,840 | Accepted | Accepted | 10.46 | N, M = list(map(int, input().split()))
F = [[] for _ in range(N)]
P = [0] * N
for i in range(M):
A, B = list(map(int, input().split()))
F[A-1].append(B-1)
F[B-1].append(A-1)
c=0
l = []
for i in range(N):
if P[i] == 0:
c+=1
l.append(i)
while len(l)>0:
p=l.pop()
P[p] = c
for j in F[p]:
if P[j] == 0:
l.append(j)
print((c-1))
| N, M = list(map(int, input().split()))
Ne = [[] for _ in range(N)]
C = [0] * N
for i in range(M):
A, B = list(map(int, input().split()))
Ne[A-1].append(B-1)
Ne[B-1].append(A-1)
c=0
l = []
for i in range(N):
if C[i] == 0:
c+=1
l.append(i)
while len(l)>0:
v=l.pop()
C[v] = c
for j in Ne[v]:
if C[j] == 0:
l.append(j)
print((c-1))
| 20 | 20 | 441 | 445 | N, M = list(map(int, input().split()))
F = [[] for _ in range(N)]
P = [0] * N
for i in range(M):
A, B = list(map(int, input().split()))
F[A - 1].append(B - 1)
F[B - 1].append(A - 1)
c = 0
l = []
for i in range(N):
if P[i] == 0:
c += 1
l.append(i)
while len(l) > 0:
p = l.pop()
P[p] = c
for j in F[p]:
if P[j] == 0:
l.append(j)
print((c - 1))
| N, M = list(map(int, input().split()))
Ne = [[] for _ in range(N)]
C = [0] * N
for i in range(M):
A, B = list(map(int, input().split()))
Ne[A - 1].append(B - 1)
Ne[B - 1].append(A - 1)
c = 0
l = []
for i in range(N):
if C[i] == 0:
c += 1
l.append(i)
while len(l) > 0:
v = l.pop()
C[v] = c
for j in Ne[v]:
if C[j] == 0:
l.append(j)
print((c - 1))
| false | 0 | [
"-F = [[] for _ in range(N)]",
"-P = [0] * N",
"+Ne = [[] for _ in range(N)]",
"+C = [0] * N",
"- F[A - 1].append(B - 1)",
"- F[B - 1].append(A - 1)",
"+ Ne[A - 1].append(B - 1)",
"+ Ne[B - 1].append(A - 1)",
"- if P[i] == 0:",
"+ if C[i] == 0:",
"- p = l.pop()",
"- P[p] = c",
"- for j in F[p]:",
"- if P[j] == 0:",
"+ v = l.pop()",
"+ C[v] = c",
"+ for j in Ne[v]:",
"+ if C[j] == 0:"
]
| false | 0.067303 | 0.048069 | 1.400117 | [
"s106024220",
"s892217958"
]
|
u186838327 | p03045 | python | s267354940 | s249413003 | 896 | 375 | 73,560 | 64,304 | Accepted | Accepted | 58.15 | class UnionFind():
def __init__(self, n):
self.n = n
# n+1なのはノード番号とリストのインデックスを一致させるため
# root[x]<0ならそのノードが根かつその絶対値が木の要素数
self.root = [-1]*(n+1)
self.rnk = [0]*(n+1)
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
def Unite(self, x, y):
x = self.Find_Root(x)
y = self.Find_Root(y)
if x == y:
return
elif(self.rnk[x] > self.rnk[y]):
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
def Count(self, x):
return -self.root[self.Find_Root(x)]
n, m = list(map(int, input().split()))
UF = UnionFind(n)
for i in range(m):
x, y, z = list(map(int, input().split()))
UF.Unite(x,y)
print((sum(x<0 for x in UF.root[1:]))) | import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
g = [[] for _ in range(n)]
for i in range(m):
x, y, z = list(map(int, input().split()))
x, y = x-1, y-1
g[x].append(y)
g[y].append(x)
s = []
visit = [-1]*n
cnt = 0
for i in range(n):
if visit[i] == -1:
s.append(i)
cnt += 1
visit[i] = cnt
while s:
v = s.pop()
for u in g[v]:
if visit[u] == -1:
visit[u] = visit[v]
s.append(u)
print((max(visit))) | 42 | 26 | 1,028 | 566 | class UnionFind:
def __init__(self, n):
self.n = n
# n+1なのはノード番号とリストのインデックスを一致させるため
# root[x]<0ならそのノードが根かつその絶対値が木の要素数
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
def Unite(self, x, y):
x = self.Find_Root(x)
y = self.Find_Root(y)
if x == y:
return
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
def Count(self, x):
return -self.root[self.Find_Root(x)]
n, m = list(map(int, input().split()))
UF = UnionFind(n)
for i in range(m):
x, y, z = list(map(int, input().split()))
UF.Unite(x, y)
print((sum(x < 0 for x in UF.root[1:])))
| import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
g = [[] for _ in range(n)]
for i in range(m):
x, y, z = list(map(int, input().split()))
x, y = x - 1, y - 1
g[x].append(y)
g[y].append(x)
s = []
visit = [-1] * n
cnt = 0
for i in range(n):
if visit[i] == -1:
s.append(i)
cnt += 1
visit[i] = cnt
while s:
v = s.pop()
for u in g[v]:
if visit[u] == -1:
visit[u] = visit[v]
s.append(u)
print((max(visit)))
| false | 38.095238 | [
"-class UnionFind:",
"- def __init__(self, n):",
"- self.n = n",
"- # n+1なのはノード番号とリストのインデックスを一致させるため",
"- # root[x]<0ならそのノードが根かつその絶対値が木の要素数",
"- self.root = [-1] * (n + 1)",
"- self.rnk = [0] * (n + 1)",
"+import sys",
"- def Find_Root(self, x):",
"- if self.root[x] < 0:",
"- return x",
"- else:",
"- self.root[x] = self.Find_Root(self.root[x])",
"- return self.root[x]",
"-",
"- def Unite(self, x, y):",
"- x = self.Find_Root(x)",
"- y = self.Find_Root(y)",
"- if x == y:",
"- return",
"- elif self.rnk[x] > self.rnk[y]:",
"- self.root[x] += self.root[y]",
"- self.root[y] = x",
"- else:",
"- self.root[y] += self.root[x]",
"- self.root[x] = y",
"- if self.rnk[x] == self.rnk[y]:",
"- self.rnk[y] += 1",
"-",
"- def isSameGroup(self, x, y):",
"- return self.Find_Root(x) == self.Find_Root(y)",
"-",
"- def Count(self, x):",
"- return -self.root[self.Find_Root(x)]",
"-",
"-",
"+input = sys.stdin.readline",
"-UF = UnionFind(n)",
"+g = [[] for _ in range(n)]",
"- UF.Unite(x, y)",
"-print((sum(x < 0 for x in UF.root[1:])))",
"+ x, y = x - 1, y - 1",
"+ g[x].append(y)",
"+ g[y].append(x)",
"+s = []",
"+visit = [-1] * n",
"+cnt = 0",
"+for i in range(n):",
"+ if visit[i] == -1:",
"+ s.append(i)",
"+ cnt += 1",
"+ visit[i] = cnt",
"+ while s:",
"+ v = s.pop()",
"+ for u in g[v]:",
"+ if visit[u] == -1:",
"+ visit[u] = visit[v]",
"+ s.append(u)",
"+print((max(visit)))"
]
| false | 0.056021 | 0.048153 | 1.163398 | [
"s267354940",
"s249413003"
]
|
u699296734 | p03606 | python | s932150591 | s214209319 | 129 | 58 | 16,772 | 9,500 | Accepted | Accepted | 55.04 | n = int(eval(input()))
seat = [0] * 10 ** 6
for i in range(n):
l, r = list(map(int, input().split()))
for j in range(l, r + 1):
seat[j - 1] = 1
res = 0
for i in range(10 ** 6):
if seat[i] == 1:
res += 1
print(res)
| n = int(eval(input()))
seat = [0] * (10 ** 5 + 1)
for i in range(n):
l, r = list(map(int, input().split()))
seat[l - 1] += 1
seat[r] -= 1
for i in range(1, 10 ** 5):
seat[i] += seat[i - 1]
res = 0
for i in range(10 ** 5):
if seat[i] == 1:
res += 1
print(res)
| 12 | 15 | 242 | 291 | n = int(eval(input()))
seat = [0] * 10**6
for i in range(n):
l, r = list(map(int, input().split()))
for j in range(l, r + 1):
seat[j - 1] = 1
res = 0
for i in range(10**6):
if seat[i] == 1:
res += 1
print(res)
| n = int(eval(input()))
seat = [0] * (10**5 + 1)
for i in range(n):
l, r = list(map(int, input().split()))
seat[l - 1] += 1
seat[r] -= 1
for i in range(1, 10**5):
seat[i] += seat[i - 1]
res = 0
for i in range(10**5):
if seat[i] == 1:
res += 1
print(res)
| false | 20 | [
"-seat = [0] * 10**6",
"+seat = [0] * (10**5 + 1)",
"- for j in range(l, r + 1):",
"- seat[j - 1] = 1",
"+ seat[l - 1] += 1",
"+ seat[r] -= 1",
"+for i in range(1, 10**5):",
"+ seat[i] += seat[i - 1]",
"-for i in range(10**6):",
"+for i in range(10**5):"
]
| false | 0.203606 | 0.110124 | 1.84888 | [
"s932150591",
"s214209319"
]
|
u870178975 | p02861 | python | s959599192 | s838518559 | 412 | 169 | 3,064 | 38,384 | Accepted | Accepted | 58.98 | import math
import itertools
a=[]
ans=0
n=int(eval(input()))
m=1
for i in range(1,n+1):
m*=i
for i in range(n):
x,y=list(map(int,input().split()))
a.append([x,y])
for t in itertools.permutations(list(range(n)),n):
for i in range(n-1):
ans+=math.sqrt((a[t[i]][0]-a[t[i+1]][0])**2+(a[t[i]][1]-a[t[i+1]][1])**2)
ans=ans/m
print(ans) | def resolve():
n=int(eval(input()))
x = [0] * n
y = [0] * n
ans=0
t=1
for i in range(1,n):
t*=i
for i in range(n):
x[i], y[i] = list(map(int, input().split()))
for i in range(n):
for j in range(i+1,n):
ans+=((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5
print((2*ans/n))
resolve() | 16 | 15 | 342 | 342 | import math
import itertools
a = []
ans = 0
n = int(eval(input()))
m = 1
for i in range(1, n + 1):
m *= i
for i in range(n):
x, y = list(map(int, input().split()))
a.append([x, y])
for t in itertools.permutations(list(range(n)), n):
for i in range(n - 1):
ans += math.sqrt(
(a[t[i]][0] - a[t[i + 1]][0]) ** 2 + (a[t[i]][1] - a[t[i + 1]][1]) ** 2
)
ans = ans / m
print(ans)
| def resolve():
n = int(eval(input()))
x = [0] * n
y = [0] * n
ans = 0
t = 1
for i in range(1, n):
t *= i
for i in range(n):
x[i], y[i] = list(map(int, input().split()))
for i in range(n):
for j in range(i + 1, n):
ans += ((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2) ** 0.5
print((2 * ans / n))
resolve()
| false | 6.25 | [
"-import math",
"-import itertools",
"+def resolve():",
"+ n = int(eval(input()))",
"+ x = [0] * n",
"+ y = [0] * n",
"+ ans = 0",
"+ t = 1",
"+ for i in range(1, n):",
"+ t *= i",
"+ for i in range(n):",
"+ x[i], y[i] = list(map(int, input().split()))",
"+ for i in range(n):",
"+ for j in range(i + 1, n):",
"+ ans += ((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2) ** 0.5",
"+ print((2 * ans / n))",
"-a = []",
"-ans = 0",
"-n = int(eval(input()))",
"-m = 1",
"-for i in range(1, n + 1):",
"- m *= i",
"-for i in range(n):",
"- x, y = list(map(int, input().split()))",
"- a.append([x, y])",
"-for t in itertools.permutations(list(range(n)), n):",
"- for i in range(n - 1):",
"- ans += math.sqrt(",
"- (a[t[i]][0] - a[t[i + 1]][0]) ** 2 + (a[t[i]][1] - a[t[i + 1]][1]) ** 2",
"- )",
"-ans = ans / m",
"-print(ans)",
"+",
"+resolve()"
]
| false | 0.083213 | 0.046776 | 1.778975 | [
"s959599192",
"s838518559"
]
|
u300645821 | p01314 | python | s444379156 | s702001484 | 30 | 10 | 7,520 | 6,264 | Accepted | Accepted | 66.67 | #!/usr/bin/python
import sys
if sys.version_info[0]>=3: raw_input=input
try:
while True:
n=int(input())
if n==0: break
r=0
i=1
while 1:
n-=i
if n<i: break
i+=1
if n%i==0: r+=1
print(r)
except EOFError:
pass | #!/usr/bin/python
import sys
if sys.version_info[0]>=3: raw_input=input
try:
while True:
n=int(input())
if n==0: break
r=0
i=1
while 1:
n-=i
i+=1
if n<i: break
if n%i==0: r+=1
print(r)
except EOFError:
pass | 18 | 18 | 254 | 254 | #!/usr/bin/python
import sys
if sys.version_info[0] >= 3:
raw_input = input
try:
while True:
n = int(input())
if n == 0:
break
r = 0
i = 1
while 1:
n -= i
if n < i:
break
i += 1
if n % i == 0:
r += 1
print(r)
except EOFError:
pass
| #!/usr/bin/python
import sys
if sys.version_info[0] >= 3:
raw_input = input
try:
while True:
n = int(input())
if n == 0:
break
r = 0
i = 1
while 1:
n -= i
i += 1
if n < i:
break
if n % i == 0:
r += 1
print(r)
except EOFError:
pass
| false | 0 | [
"+ i += 1",
"- i += 1"
]
| false | 0.107456 | 0.077249 | 1.391025 | [
"s444379156",
"s702001484"
]
|
u119148115 | p03564 | python | s461390826 | s736450645 | 87 | 66 | 61,940 | 61,860 | Accepted | Accepted | 24.14 | 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()) #空白なし
N,K = I(),I()
ans = 10**6
for i in range(N+1):
a = 2**i
a += K*(N-i)
ans = min(ans,a)
print(ans)
| import sys
def I(): return int(sys.stdin.readline().rstrip())
N,K = I(),I()
print((min(2**i+K*(N-i) for i in range(N+1))))
| 20 | 6 | 609 | 128 | 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()) # 空白なし
N, K = I(), I()
ans = 10**6
for i in range(N + 1):
a = 2**i
a += K * (N - i)
ans = min(ans, a)
print(ans)
| import sys
def I():
return int(sys.stdin.readline().rstrip())
N, K = I(), I()
print((min(2**i + K * (N - i) for i in range(N + 1))))
| false | 70 | [
"-",
"-sys.setrecursionlimit(10**7)",
"-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()) # 空白なし",
"-",
"-",
"-ans = 10**6",
"-for i in range(N + 1):",
"- a = 2**i",
"- a += K * (N - i)",
"- ans = min(ans, a)",
"-print(ans)",
"+print((min(2**i + K * (N - i) for i in range(N + 1))))"
]
| false | 0.007809 | 0.04075 | 0.19162 | [
"s461390826",
"s736450645"
]
|
u698762975 | p02264 | python | s103147270 | s611630885 | 410 | 350 | 14,464 | 13,300 | Accepted | Accepted | 14.63 | from collections import deque
def solve(n,t):
q=deque([])
for i in range(n):
l=list(input().split())
q.append(l)
time=0
while not len(q)==0:
x=q.popleft()
if int(x[1])-t>0:
x[1]=str(int(x[1])-t)
time+=t
q.append(x)
else:
print((x[0]+" "+str(time+int(x[1]))))
time+=int(x[1])
n,t=list(map(int,input().split()))
solve(n,t)
| import collections
q=collections.deque()
n,m=list(map(int,input().split()))
for i in range(n):
a,b=input().split()
b=int(b)
q.append([a,b])
t=0
while len(q)!=0:
n=q.popleft()
if n[1]<=m:
t+=n[1]
print((n[0],str(t)))
else:
t+=m
n[1]-=m
q.append(n)
| 18 | 17 | 388 | 287 | from collections import deque
def solve(n, t):
q = deque([])
for i in range(n):
l = list(input().split())
q.append(l)
time = 0
while not len(q) == 0:
x = q.popleft()
if int(x[1]) - t > 0:
x[1] = str(int(x[1]) - t)
time += t
q.append(x)
else:
print((x[0] + " " + str(time + int(x[1]))))
time += int(x[1])
n, t = list(map(int, input().split()))
solve(n, t)
| import collections
q = collections.deque()
n, m = list(map(int, input().split()))
for i in range(n):
a, b = input().split()
b = int(b)
q.append([a, b])
t = 0
while len(q) != 0:
n = q.popleft()
if n[1] <= m:
t += n[1]
print((n[0], str(t)))
else:
t += m
n[1] -= m
q.append(n)
| false | 5.555556 | [
"-from collections import deque",
"+import collections",
"-",
"-def solve(n, t):",
"- q = deque([])",
"- for i in range(n):",
"- l = list(input().split())",
"- q.append(l)",
"- time = 0",
"- while not len(q) == 0:",
"- x = q.popleft()",
"- if int(x[1]) - t > 0:",
"- x[1] = str(int(x[1]) - t)",
"- time += t",
"- q.append(x)",
"- else:",
"- print((x[0] + \" \" + str(time + int(x[1]))))",
"- time += int(x[1])",
"-",
"-",
"-n, t = list(map(int, input().split()))",
"-solve(n, t)",
"+q = collections.deque()",
"+n, m = list(map(int, input().split()))",
"+for i in range(n):",
"+ a, b = input().split()",
"+ b = int(b)",
"+ q.append([a, b])",
"+t = 0",
"+while len(q) != 0:",
"+ n = q.popleft()",
"+ if n[1] <= m:",
"+ t += n[1]",
"+ print((n[0], str(t)))",
"+ else:",
"+ t += m",
"+ n[1] -= m",
"+ q.append(n)"
]
| false | 0.047115 | 0.04653 | 1.01257 | [
"s103147270",
"s611630885"
]
|
u729133443 | p02782 | python | s099356940 | s087073780 | 424 | 348 | 82,164 | 82,164 | Accepted | Accepted | 17.92 | def main():
M=10**9+7
r1,c1,r2,c2=list(map(int,input().split()))
n=r2+c2+2
fac=[0]*(n+1)
fac[0]=1
for i in range(1,n+1):fac[i]=fac[i-1]*i%M
f=lambda r,c:fac[r+c+2]*pow(fac[c+1],M-2,M)*pow(fac[r+1],M-2,M)-c-r-2
print(((f(r2,c2)-f(r2,c1-1)-f(r1-1,c2)+f(r1-1,c1-1))%M))
main() | def main():
M=10**9+7
r1,c1,r2,c2=list(map(int,input().split()))
n=r2+c2+2
fac=[0]*(n+1)
fac[0]=before=1
for i in range(1,n+1):fac[i]=before=before*i%M
f=lambda r,c:fac[r+c+2]*pow(fac[c+1],M-2,M)*pow(fac[r+1],M-2,M)-c-r-2
print(((f(r2,c2)-f(r2,c1-1)-f(r1-1,c2)+f(r1-1,c1-1))%M))
main() | 10 | 10 | 290 | 302 | def main():
M = 10**9 + 7
r1, c1, r2, c2 = list(map(int, input().split()))
n = r2 + c2 + 2
fac = [0] * (n + 1)
fac[0] = 1
for i in range(1, n + 1):
fac[i] = fac[i - 1] * i % M
f = (
lambda r, c: fac[r + c + 2]
* pow(fac[c + 1], M - 2, M)
* pow(fac[r + 1], M - 2, M)
- c
- r
- 2
)
print(((f(r2, c2) - f(r2, c1 - 1) - f(r1 - 1, c2) + f(r1 - 1, c1 - 1)) % M))
main()
| def main():
M = 10**9 + 7
r1, c1, r2, c2 = list(map(int, input().split()))
n = r2 + c2 + 2
fac = [0] * (n + 1)
fac[0] = before = 1
for i in range(1, n + 1):
fac[i] = before = before * i % M
f = (
lambda r, c: fac[r + c + 2]
* pow(fac[c + 1], M - 2, M)
* pow(fac[r + 1], M - 2, M)
- c
- r
- 2
)
print(((f(r2, c2) - f(r2, c1 - 1) - f(r1 - 1, c2) + f(r1 - 1, c1 - 1)) % M))
main()
| false | 0 | [
"- fac[0] = 1",
"+ fac[0] = before = 1",
"- fac[i] = fac[i - 1] * i % M",
"+ fac[i] = before = before * i % M"
]
| false | 0.050143 | 0.050329 | 0.996299 | [
"s099356940",
"s087073780"
]
|
u519939795 | p03408 | python | s986683172 | s719212421 | 21 | 17 | 3,316 | 3,060 | Accepted | Accepted | 19.05 | from collections import Counter
N=int(eval(input()))
S=Counter([eval(input()) for i in range(N)])
M=int(eval(input()))
T=Counter([eval(input()) for i in range(M)])
ans=0
for key in list(S.keys()):
ans = max(S.get(key)-T.get(key,0),ans)
print(ans) | n=int(eval(input()))
s=[eval(input()) for i in range(n)]
m=int(eval(input()))
t=[eval(input()) for i in range(m)]
li=list(set(s))
print((max(0,max(s.count(li[i])-t.count(li[i]) for i in range(len(li)))))) | 9 | 6 | 228 | 183 | from collections import Counter
N = int(eval(input()))
S = Counter([eval(input()) for i in range(N)])
M = int(eval(input()))
T = Counter([eval(input()) for i in range(M)])
ans = 0
for key in list(S.keys()):
ans = max(S.get(key) - T.get(key, 0), ans)
print(ans)
| n = int(eval(input()))
s = [eval(input()) for i in range(n)]
m = int(eval(input()))
t = [eval(input()) for i in range(m)]
li = list(set(s))
print((max(0, max(s.count(li[i]) - t.count(li[i]) for i in range(len(li))))))
| false | 33.333333 | [
"-from collections import Counter",
"-",
"-N = int(eval(input()))",
"-S = Counter([eval(input()) for i in range(N)])",
"-M = int(eval(input()))",
"-T = Counter([eval(input()) for i in range(M)])",
"-ans = 0",
"-for key in list(S.keys()):",
"- ans = max(S.get(key) - T.get(key, 0), ans)",
"-print(ans)",
"+n = int(eval(input()))",
"+s = [eval(input()) for i in range(n)]",
"+m = int(eval(input()))",
"+t = [eval(input()) for i in range(m)]",
"+li = list(set(s))",
"+print((max(0, max(s.count(li[i]) - t.count(li[i]) for i in range(len(li))))))"
]
| false | 0.0412 | 0.041434 | 0.994374 | [
"s986683172",
"s719212421"
]
|
u977389981 | p03273 | python | s570904508 | s773904180 | 25 | 19 | 3,316 | 3,064 | Accepted | Accepted | 24 | h, w = list(map(int, input().split()))
A = []
for i in range(h):
s = list(eval(input()))
if '#' in s:
A.append(s)
B = [[0] * w for i in range(len(A))]
for i in range(len(A)):
for j in range(w):
if A[i][j] == '#':
B[i][j] += 1
C = [0] * w
for i in range(len(A)):
for j in range(w):
C[j] += B[i][j]
D = [[] for i in range(len(A))]
for i in range(len(A)):
for j in range(w):
if C[j] != 0:
D[i].append(A[i][j])
for i in range(len(A)):
print((''.join(D[i]))) | h, w = list(map(int, input().split()))
A = []
for i in range(h):
s = list(eval(input()))
if '#' in s:
A.append(s)
h2 = len(A)
for j in range(w - 1, -1, -1):
for i in range(h2):
if A[i][j] == '#':
break
elif i == h2 - 1:
for k in range(h2):
del A[k][j]
for a in A:
print((''.join(a))) | 27 | 19 | 598 | 382 | h, w = list(map(int, input().split()))
A = []
for i in range(h):
s = list(eval(input()))
if "#" in s:
A.append(s)
B = [[0] * w for i in range(len(A))]
for i in range(len(A)):
for j in range(w):
if A[i][j] == "#":
B[i][j] += 1
C = [0] * w
for i in range(len(A)):
for j in range(w):
C[j] += B[i][j]
D = [[] for i in range(len(A))]
for i in range(len(A)):
for j in range(w):
if C[j] != 0:
D[i].append(A[i][j])
for i in range(len(A)):
print(("".join(D[i])))
| h, w = list(map(int, input().split()))
A = []
for i in range(h):
s = list(eval(input()))
if "#" in s:
A.append(s)
h2 = len(A)
for j in range(w - 1, -1, -1):
for i in range(h2):
if A[i][j] == "#":
break
elif i == h2 - 1:
for k in range(h2):
del A[k][j]
for a in A:
print(("".join(a)))
| false | 29.62963 | [
"-B = [[0] * w for i in range(len(A))]",
"-for i in range(len(A)):",
"- for j in range(w):",
"+h2 = len(A)",
"+for j in range(w - 1, -1, -1):",
"+ for i in range(h2):",
"- B[i][j] += 1",
"-C = [0] * w",
"-for i in range(len(A)):",
"- for j in range(w):",
"- C[j] += B[i][j]",
"-D = [[] for i in range(len(A))]",
"-for i in range(len(A)):",
"- for j in range(w):",
"- if C[j] != 0:",
"- D[i].append(A[i][j])",
"-for i in range(len(A)):",
"- print((\"\".join(D[i])))",
"+ break",
"+ elif i == h2 - 1:",
"+ for k in range(h2):",
"+ del A[k][j]",
"+for a in A:",
"+ print((\"\".join(a)))"
]
| false | 0.046948 | 0.072305 | 0.649308 | [
"s570904508",
"s773904180"
]
|
u588341295 | p03478 | python | s217180264 | s230165776 | 38 | 28 | 3,060 | 3,060 | Accepted | Accepted | 26.32 | # -*- coding: utf-8 -*-
N, A, B = list(map(int, input().split()))
ans = 0
# 1~Nのループ
for i in range(1, N+1):
sum1 = 0
num = i
# 各桁の値を合計していく
for j in range(len(str(i))):
sum1 += num % 10
num = int(num / 10)
# 条件に合っていれば答えに足す
if sum1 >= A and sum1 <= B:
ans += i
print(ans) | # -*- coding: utf-8 -*-
N, A, B = list(map(int, input().split()))
ans = 0
# 1~Nのループ
for i in range(1, N+1):
sum1 = 0
num = i
# 各桁の値を合計していく
while num > 0:
sum1 += num % 10
num //= 10
# 条件に合っていれば答えに足す
if sum1 >= A and sum1 <= B:
ans += i
print(ans) | 19 | 19 | 333 | 310 | # -*- coding: utf-8 -*-
N, A, B = list(map(int, input().split()))
ans = 0
# 1~Nのループ
for i in range(1, N + 1):
sum1 = 0
num = i
# 各桁の値を合計していく
for j in range(len(str(i))):
sum1 += num % 10
num = int(num / 10)
# 条件に合っていれば答えに足す
if sum1 >= A and sum1 <= B:
ans += i
print(ans)
| # -*- coding: utf-8 -*-
N, A, B = list(map(int, input().split()))
ans = 0
# 1~Nのループ
for i in range(1, N + 1):
sum1 = 0
num = i
# 各桁の値を合計していく
while num > 0:
sum1 += num % 10
num //= 10
# 条件に合っていれば答えに足す
if sum1 >= A and sum1 <= B:
ans += i
print(ans)
| false | 0 | [
"- for j in range(len(str(i))):",
"+ while num > 0:",
"- num = int(num / 10)",
"+ num //= 10"
]
| false | 0.03831 | 0.045165 | 0.848222 | [
"s217180264",
"s230165776"
]
|
u690536347 | p02843 | python | s219436709 | s692247578 | 186 | 35 | 3,828 | 3,828 | Accepted | Accepted | 81.18 | X = int(eval(input()))
dp = [0]*(X+1)
dp[0] = 1
for i in range(X+1):
for j in [100, 101, 102, 103, 104, 105]:
if i-j>=0 and dp[i-j]:
dp[i] = 1
print((dp[X])) | X = int(eval(input()))
dp = [0]*(X+1)
dp[0] = 1
for i in range(100, X+1):
dp[i] = dp[i-100] or dp[i-101] or dp[i-102] or dp[i-103] or dp[i-104] or dp[i-105]
print((dp[X])) | 10 | 8 | 184 | 176 | X = int(eval(input()))
dp = [0] * (X + 1)
dp[0] = 1
for i in range(X + 1):
for j in [100, 101, 102, 103, 104, 105]:
if i - j >= 0 and dp[i - j]:
dp[i] = 1
print((dp[X]))
| X = int(eval(input()))
dp = [0] * (X + 1)
dp[0] = 1
for i in range(100, X + 1):
dp[i] = (
dp[i - 100]
or dp[i - 101]
or dp[i - 102]
or dp[i - 103]
or dp[i - 104]
or dp[i - 105]
)
print((dp[X]))
| false | 20 | [
"-for i in range(X + 1):",
"- for j in [100, 101, 102, 103, 104, 105]:",
"- if i - j >= 0 and dp[i - j]:",
"- dp[i] = 1",
"+for i in range(100, X + 1):",
"+ dp[i] = (",
"+ dp[i - 100]",
"+ or dp[i - 101]",
"+ or dp[i - 102]",
"+ or dp[i - 103]",
"+ or dp[i - 104]",
"+ or dp[i - 105]",
"+ )"
]
| false | 0.040891 | 0.03695 | 1.106646 | [
"s219436709",
"s692247578"
]
|
u086503932 | p03785 | python | s124510697 | s359129073 | 273 | 184 | 7,384 | 81,068 | Accepted | Accepted | 32.6 | N,C,K = list(map(int,input().split()))
T = [int(eval(input())) for _ in range(N)]
T.sort()
i = 0
ans = 0
while i < N:
tmp = i+1
while tmp < N:
if tmp < i+C and T[tmp] <= T[i]+K:
tmp += 1
else:
break
ans += 1
i = tmp
print(ans) | N, C, K = list(map(int, input().split()))
T = [int(eval(input())) for _ in range(N)]
T.sort()
T.append(10**12)
ans = 0
now = T[0]
i = 0
while i < N:
ans += 1
num = 0
while i < N and T[i] <= now+K and num < C:
num += 1
i += 1
now = T[i]
print(ans)
| 16 | 18 | 258 | 290 | N, C, K = list(map(int, input().split()))
T = [int(eval(input())) for _ in range(N)]
T.sort()
i = 0
ans = 0
while i < N:
tmp = i + 1
while tmp < N:
if tmp < i + C and T[tmp] <= T[i] + K:
tmp += 1
else:
break
ans += 1
i = tmp
print(ans)
| N, C, K = list(map(int, input().split()))
T = [int(eval(input())) for _ in range(N)]
T.sort()
T.append(10**12)
ans = 0
now = T[0]
i = 0
while i < N:
ans += 1
num = 0
while i < N and T[i] <= now + K and num < C:
num += 1
i += 1
now = T[i]
print(ans)
| false | 11.111111 | [
"+T.append(10**12)",
"+ans = 0",
"+now = T[0]",
"-ans = 0",
"- tmp = i + 1",
"- while tmp < N:",
"- if tmp < i + C and T[tmp] <= T[i] + K:",
"- tmp += 1",
"- else:",
"- break",
"- i = tmp",
"+ num = 0",
"+ while i < N and T[i] <= now + K and num < C:",
"+ num += 1",
"+ i += 1",
"+ now = T[i]"
]
| false | 0.096876 | 0.056925 | 1.701833 | [
"s124510697",
"s359129073"
]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.