problem_id stringlengths 6 6 | buggy_code stringlengths 8 526k | fixed_code stringlengths 12 526k | labels listlengths 0 15 ⌀ | buggy_submission_id int64 1 1.54M | fixed_submission_id int64 2 1.54M | user_id stringlengths 10 10 | language stringclasses 8
values |
|---|---|---|---|---|---|---|---|
p02840 | n, x, d = map(int, input().split())
if d == 0:
if x == 0:
print(1)
exit
else:
print(n + 1)
exit
if d < 0:
y = x
x = x + d * (n - 1)
d = -d
else:
y = x + d * (n - 1)
U = {}
ans = 0
has0 = 0
for k in range(1, n + 1):
r = (x * k) % d
s = k * d * (k - 1) // 2
v1 = k * x + s
v2 = k * y - s
if r in U:
u = U[r]
if v1 > u[1] or v2 < u[0]:
ans += (u[1] - u[0]) // d + 1
else:
v1 = min(v1, U[r][0])
v2 = max(v2, U[r][1])
U[r] = (v1, v2)
if r == 0 and v1 <= 0 and v2 >= 0:
has0 = 1
# print(ans, k, v1, v2, U)
for r, u in U.items():
ans += (u[1] - u[0]) // d + 1
if not has0: ans += 1
print(ans) | n, x, d = map(int, input().split())
if d == 0:
if x == 0:
print(1)
exit()
else:
print(n + 1)
exit()
if d < 0:
y = x
x = x + d * (n - 1)
d = -d
else:
y = x + d * (n - 1)
U = {}
ans = 0
has0 = 0
for k in range(1, n + 1):
r = (x * k) % d
s = k * d * (k - 1) // 2
v1 = k * x + s
v2 = k * y - s
if r in U:
u = U[r]
if v1 > u[1] or v2 < u[0]:
ans += (u[1] - u[0]) // d + 1
else:
v1 = min(v1, U[r][0])
v2 = max(v2, U[r][1])
U[r] = (v1, v2)
if r == 0 and v1 <= 0 and v2 >= 0:
has0 = 1
# print(ans, k, v1, v2, U)
for r, u in U.items():
ans += (u[1] - u[0]) // d + 1
if not has0: ans += 1
print(ans) | [
"call.add"
] | 646,420 | 646,421 | u956530786 | python |
p02840 | import sys
readline = sys.stdin.readline
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
def solve():
n, x, d = nm()
ans = 0
if d == 0:
print(0 if x == 0 else n)
return
if d < 0:
d = -d
x = -x
g = dict()
g[0] = [(0, 0)]
for i in range(1, n+1):
c, y = divmod(x * i, d)
# print((c, y))
f = (c + i*(i-1)//2, c + n*i - i*(i+1)//2)
if y not in g:
g[y] = list()
g[y].append(f)
for y in g:
f = sorted(g[y])
# print(f)
cx, cy = f[0]
for nx, ny in f:
if nx <= cy:
cx = min(nx, cx)
cy = max(ny, cy)
else:
ans += cy - cx + 1
cx, cy = nx, ny
ans += cy - cx + 1
print(ans)
return
solve() | import sys
readline = sys.stdin.readline
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
def solve():
n, x, d = nm()
ans = 0
if d == 0:
print(1 if x == 0 else n+1)
return
if d < 0:
d = -d
x = -x
g = dict()
g[0] = [(0, 0)]
for i in range(1, n+1):
c, y = divmod(x * i, d)
# print((c, y))
f = (c + i*(i-1)//2, c + n*i - i*(i+1)//2)
if y not in g:
g[y] = list()
g[y].append(f)
for y in g:
f = sorted(g[y])
# print(f)
cx, cy = f[0]
for nx, ny in f:
if nx <= cy:
cx = min(nx, cx)
cy = max(ny, cy)
else:
ans += cy - cx + 1
cx, cy = nx, ny
ans += cy - cx + 1
print(ans)
return
solve()
| [
"literal.number.integer.change",
"call.arguments.change",
"io.output.change"
] | 646,458 | 646,457 | u543954314 | python |
p02840 | import sys
readline = sys.stdin.readline
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
def solve():
n, x, d = nm()
ans = 0
if d == 0:
print(0 if x == 0 else n)
if d < 0:
d = -d
x = -x
g = dict()
g[0] = [(0, 0)]
for i in range(1, n+1):
c, y = divmod(x * i, d)
# print((c, y))
f = (c + i*(i-1)//2, c + n*i - i*(i+1)//2)
if y not in g:
g[y] = list()
g[y].append(f)
for y in g:
f = sorted(g[y])
# print(f)
cx, cy = f[0]
for nx, ny in f:
if nx <= cy:
cx = min(nx, cx)
cy = max(ny, cy)
else:
ans += cy - cx + 1
cx, cy = nx, ny
ans += cy - cx + 1
print(ans)
return
solve() | import sys
readline = sys.stdin.readline
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
def solve():
n, x, d = nm()
ans = 0
if d == 0:
print(1 if x == 0 else n+1)
return
if d < 0:
d = -d
x = -x
g = dict()
g[0] = [(0, 0)]
for i in range(1, n+1):
c, y = divmod(x * i, d)
# print((c, y))
f = (c + i*(i-1)//2, c + n*i - i*(i+1)//2)
if y not in g:
g[y] = list()
g[y].append(f)
for y in g:
f = sorted(g[y])
# print(f)
cx, cy = f[0]
for nx, ny in f:
if nx <= cy:
cx = min(nx, cx)
cy = max(ny, cy)
else:
ans += cy - cx + 1
cx, cy = nx, ny
ans += cy - cx + 1
print(ans)
return
solve()
| [
"literal.number.integer.change",
"call.arguments.change",
"io.output.change",
"control_flow.return.add"
] | 646,459 | 646,457 | u543954314 | python |
p02842 | n=int(input())
flag = False
for i in range(100*n,100*(n+1)):
if i%108 == 0:
x == int(i//108)
print(x)
flag == True
break
if flag == False:
print(':(') | n=int(input())
flag = False
for i in range(100*n,100*(n+1)):
if i%108 == 0:
x = int(i//108)
print(x)
flag = True
break
if flag == False:
print(':(') | [
"expression.operation.compare.replace.remove",
"assignment.replace.add",
"misc.typo"
] | 646,610 | 646,611 | u530071782 | python |
p02842 | n=int(input())
flag == False
for i in range(100*n,100*(n+1)):
if i%108 == 0:
x == int(i//108)
print(x)
flag == True
break
if flag == False:
print(':(')
| n=int(input())
flag = False
for i in range(100*n,100*(n+1)):
if i%108 == 0:
x = int(i//108)
print(x)
flag = True
break
if flag == False:
print(':(') | [
"expression.operation.compare.replace.remove",
"assignment.replace.add",
"misc.typo"
] | 646,612 | 646,611 | u530071782 | python |
p02842 | import math
n = int(input())
for i in range(1,n):
if math.floor(i * 1.08) == n:
print(i)
exit(0)
print(":(") | import math
n = int(input())
for i in range(n+1):
if math.floor(i * 1.08) == n:
print(i)
exit(0)
print(":(") | [
"call.arguments.change"
] | 646,617 | 646,616 | u598684283 | python |
p02842 | import math
n=int(input())
if int(math.ceil(n/1.08)*1.08)==n:
print(math.ceil(n/1.08))
else:
print(":()") | import math
n=int(input())
if int(math.ceil(n/1.08)*1.08)==n:
print(math.ceil(n/1.08))
else:
print(":(") | [
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 646,629 | 646,630 | u629540524 | python |
p02842 | # -*- coding: utf-8 -*-
import math
N = int(input())
for x in range(N,1,-1):
val = int(x * 1.08)
if val == N:
print(x)
exit()
print(':(') | # -*- coding: utf-8 -*-
import math
N = int(input())
for x in range(N,0,-1):
val = int(x * 1.08)
if val == N:
print(x)
exit()
print(':(') | [
"literal.number.integer.change",
"call.arguments.change",
"control_flow.loop.range.bounds.upper.change"
] | 646,635 | 646,636 | u540762794 | python |
p02842 | n=int(input())
for i in range(n):
if (i *108)//100 == n:
print(i)
exit()
print(':(') | n=int(input())
for i in range(1,n+1):
if (i *108)//100 == n:
print(i)
exit()
print(':(') | [
"call.arguments.add"
] | 646,639 | 646,640 | u244434589 | python |
p02842 | import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7
import math
n = I()
# N円払った
# 8パーセントの消費税がかかる
# 税抜き価格xを忘れたので、求めたい。
# xは整数とする。
# あり得る価格のうち一つを出力せよ。ただし考えられるものが存在しない場合はその旨を報告せよ。
# 普通に考えたら、n / 1.08が原価
# ただし、消費税は切り捨てとなる点に注意が必要。
x = n / 1.08
c_x = math.ceil(x)
f_n = math.floor(c_x * 1.08)
if f_n == n:
print(f_n)
else:
print(":(") | import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7
import math
n = I()
# N円払った
# 8パーセントの消費税がかかる
# 税抜き価格xを忘れたので、求めたい。
# xは整数とする。
# あり得る価格のうち一つを出力せよ。ただし考えられるものが存在しない場合はその旨を報告せよ。
# 普通に考えたら、n / 1.08が原価
# ただし、消費税は切り捨てとなる点に注意が必要。
x = n / 1.08
c_x = math.ceil(x)
f_n = math.floor(c_x * 1.08)
if f_n == n:
print(c_x)
else:
print(":(") | [
"identifier.change",
"call.arguments.change",
"io.output.change"
] | 646,645 | 646,646 | u190850294 | python |
p02842 | from decimal import Decimal
N = int(input())
a = Decimal('1.08')
for x in range(N):
if int(x*a) == N:
print(x)
exit()
print(':(') | from decimal import Decimal
N = int(input())
a = Decimal('1.08')
for x in range(N+1):
if int(x*a) == N:
print(x)
exit()
print(':(') | [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add"
] | 646,647 | 646,648 | u267718666 | python |
p02842 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(input())
def binary_search(ok, ng, cond):
while abs(ok - ng) > 1:
mid = (ok + ng) / 2
if cond(mid):
ok = mid
else:
ng = mid
return ok
candidate = binary_search(n, 0, lambda x: x * 1.08 >= n)
if n == int(candidate * 1.08):
print(candidate)
else:
print(':(')
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(input())
def binary_search(ok, ng, cond):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if cond(mid):
ok = mid
else:
ng = mid
return ok
candidate = binary_search(n, 0, lambda x: x * 1.08 >= n)
if n == int(candidate * 1.08):
print(candidate)
else:
print(':(')
| [
"expression.operator.arithmetic.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 646,663 | 646,664 | u883621917 | python |
p02842 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(input())
def binary_search(ok, ng, cond):
while abs(ok - ng) > 1:
mid = (ok + ng) / 2
if cond(mid):
ok = mid
else:
ng = mid
return ok
candidate = int(binary_search(n, 0, lambda x: x * 1.08 >= n))
if n == int(candidate * 1.08):
print(candidate)
else:
print(':(')
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(input())
def binary_search(ok, ng, cond):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if cond(mid):
ok = mid
else:
ng = mid
return ok
candidate = binary_search(n, 0, lambda x: x * 1.08 >= n)
if n == int(candidate * 1.08):
print(candidate)
else:
print(':(')
| [
"expression.operator.arithmetic.change",
"assignment.value.change",
"expression.operation.binary.change",
"call.remove",
"call.arguments.change"
] | 646,665 | 646,664 | u883621917 | python |
p02842 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(input())
def bs(ok, ng, solve):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if solve(mid):
ok = mid
else:
ng = mid
return ok
ans = bs(n, 0, lambda x: x * 1.08 >= n)
if ans * 1.08 == n:
print(ans)
else:
print(':(')
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(input())
def bs(ok, ng, solve):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if solve(mid):
ok = mid
else:
ng = mid
return ok
ans = bs(n, 0, lambda x: x * 1.08 >= n)
if int(ans * 1.08) == n:
print(ans)
else:
print(':(')
| [
"control_flow.branch.if.condition.change",
"call.add"
] | 646,666 | 646,667 | u883621917 | python |
p02842 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(input())
def bs(ok, ng, cond):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if cond(mid):
ok = mid
else:
ng = mid
return mid
ans = bs(n, 0, lambda x: (x * 1.08) >= n)
if int(ans * 1.08) == n:
print(ans)
else:
print(':(')
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(input())
def bs(ok, ng, solve):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if solve(mid):
ok = mid
else:
ng = mid
return ok
ans = bs(n, 0, lambda x: x * 1.08 >= n)
if int(ans * 1.08) == n:
print(ans)
else:
print(':(')
| [
"identifier.change",
"call.function.change",
"control_flow.branch.if.condition.change",
"function.return_value.change",
"call.arguments.change"
] | 646,668 | 646,667 | u883621917 | python |
p02842 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(input())
def bs(ok, ng, cond):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if cond(mid):
ok = mid
else:
ng = mid
return mid
ans = bs(n, 0, lambda x: (x * 1.08) >= n)
if int(ans * 1.08) == n:
print(ans)
else:
print(':(')
| import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(input())
def bs(ok, ng, cond):
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if cond(mid):
ok = mid
else:
ng = mid
return ok
ans = bs(n, 0, lambda x: (x * 1.08) >= n)
if int(ans * 1.08) == n:
print(ans)
else:
print(':(')
| [
"identifier.change",
"function.return_value.change"
] | 646,668 | 646,670 | u883621917 | python |
p02842 | #
# smbc2019 b
#
import sys
from io import StringIO
import unittest
import math
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """432"""
output = """400"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """1079"""
output = """:("""
self.assertIO(input, output)
def test_入力例_3(self):
input = """1001"""
output = """927"""
self.assertIO(input, output)
def resolve():
N = int(input())
for x in range(1, N):
if math.floor(x*1.08) == N:
print(x)
break
else:
print(":(")
if __name__ == "__main__":
# unittest.main()
resolve()
| #
# smbc2019 b
#
import sys
from io import StringIO
import unittest
import math
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """432"""
output = """400"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """1079"""
output = """:("""
self.assertIO(input, output)
def test_入力例_3(self):
input = """1001"""
output = """927"""
self.assertIO(input, output)
def resolve():
N = int(input())
for x in range(1, N+1):
if math.floor(x*1.08) == N:
print(x)
break
else:
print(":(")
if __name__ == "__main__":
# unittest.main()
resolve()
| [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add"
] | 646,679 | 646,680 | u481250941 | python |
p02842 | n = int(input())
r = n % 27
if r == 13 or r == 26:
print(':)')
elif r ==0:
x = int(100*n/108)
print(x)
else:
for i in range(1, 25):
if 1.08*(i-1) < r <= 1.08*i:
break
x = int(100*(n - i)/108) + i
print(x) | n = int(input())
r = n % 27
if r == 13 or r == 26:
print(':(')
elif r ==0:
x = int(100*n/108)
print(x)
else:
for i in range(1, 25):
if 1.08*(i-1) < r <= 1.08*i:
break
x = int(100*(n - i)/108) + i
print(x) | [
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 646,689 | 646,690 | u148981246 | python |
p02842 | N=int(input())
for i in range(N+1):
if int(i*1.08)==N:
print(i)
break
if all(int(i*1.08)!=N for i in range(N))==True:
print(":(") | N=int(input())
for i in range(N+1):
if int(i*1.08)==N:
print(i)
break
if all(int(i*1.08)!=N for i in range(N+1))==True:
print(":(") | [
"control_flow.branch.if.condition.change"
] | 646,693 | 646,694 | u591919975 | python |
p02842 | N=int(input())
for i in range(N):
if int(i*1.08)==N:
print(i)
break
if all(int(i*1.08)!=N for i in range(N))==True:
print(":(") | N=int(input())
for i in range(N+1):
if int(i*1.08)==N:
print(i)
break
if all(int(i*1.08)!=N for i in range(N+1))==True:
print(":(") | [
"control_flow.branch.if.condition.change"
] | 646,695 | 646,694 | u591919975 | python |
p02842 | N=int(input())
for i in range(N):
if int(i*1.08)==N:
print(i)
break
if all(int(i*1.08)!=N for i in range(N))==True:
print("No") | N=int(input())
for i in range(N+1):
if int(i*1.08)==N:
print(i)
break
if all(int(i*1.08)!=N for i in range(N+1))==True:
print(":(") | [
"control_flow.branch.if.condition.change",
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 646,696 | 646,694 | u591919975 | python |
p02842 | N = int(input())
ans = ":("
for X in range(N-1):
if int(X * 1.08) == N:
ans = X
break
print(ans)
| N = int(input())
ans = ":("
for X in range(N+1):
if int(X * 1.08) == N:
ans = X
break
print(ans)
| [
"misc.opposites",
"expression.operator.arithmetic.change",
"call.arguments.change",
"expression.operation.binary.change",
"control_flow.loop.range.bounds.upper.change"
] | 646,715 | 646,716 | u909224749 | python |
p02842 | n = int(input())
for i in range(n):
ans = int(i*1.08)
if ans == n:
print(i)
break
else:
print(":(") | n = int(input())
for i in range(1,n+1):
ans = int(i*1.08)
if ans == n:
print(i)
break
else:
print(":(") | [
"call.arguments.add"
] | 646,718 | 646,719 | u397953026 | python |
p02842 | n = int(input())
ans = int(n*100/108)
if int(ans*1.08)==n:
print(ans)
elif int((ans-1)*1.08)==n:
print(ans-1)
elif int((ans-1)*1.08)==n:
print(ans+1)
else:
print(":(")
| n = int(input())
ans = int(n*100/108)
if int(ans*1.08)==n:
print(ans)
elif int((ans-1)*1.08)==n:
print(ans-1)
elif int((ans+1)*1.08)==n:
print(ans+1)
else:
print(":(")
| [
"misc.opposites",
"expression.operator.arithmetic.change",
"control_flow.branch.if.condition.change"
] | 646,720 | 646,721 | u035453792 | python |
p02842 | import math
N = int(input())
ans = -1
for i in range(N):
if math.floor(i*1.08) == N:
ans = i
if ans == -1:
print(':(')
else:
print(ans) | import math
N = int(input())
ans = -1
for i in range(N+1):
if math.floor(i*1.08) == N:
ans = i
if ans == -1:
print(':(')
else:
print(ans) | [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add"
] | 646,727 | 646,728 | u456579619 | python |
p02842 | N = int(input())
n = int(N // 1.08)
while n < N:
if int(n * 1.08) == N:
print(n)
exit()
n += 1
print(':(')
| N = int(input())
n = int(N // 1.08)
while n <= N:
if int(n * 1.08) == N:
print(n)
exit()
n += 1
print(':(')
| [
"expression.operator.compare.change",
"control_flow.loop.condition.change"
] | 646,737 | 646,738 | u891516200 | python |
p02842 | a=int(input())
b=0
for i in range(a):
c=i
c+=(i*8)//100
if c==a:
b=i
print(":("if b==0 else b) | a=int(input())
b=0
for i in range(a+1):
c=i
c+=(i*8)//100
if c==a:
b=i
print(":("if b==0 else b) | [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add"
] | 646,739 | 646,740 | u158290747 | python |
p02842 | import math
f = True
N = int(input())
for i in range(N):
if math.floor(i*1.08) == N:
print(i)
f = False
break
if f:
print(":(")
| import math
f = True
N = int(input())
for i in range(N+1):
if math.floor(i*1.08) == N:
print(i)
f = False
break
if f:
print(":(")
| [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add"
] | 646,745 | 646,746 | u950174376 | python |
p02842 | import math
f = True
N = int(input())
for i in range(N):
if math.floor(i*1.08) == N:
print(i)
f = False
if f:
print(":(")
| import math
f = True
N = int(input())
for i in range(N+1):
if math.floor(i*1.08) == N:
print(i)
f = False
break
if f:
print(":(")
| [
"control_flow.break.add"
] | 646,747 | 646,746 | u950174376 | python |
p02842 | N = int(input())
import math
X = math.floor(N/1.08)
if N == math.ceil(X*1.08):
print(X)
else:
print(':(') | N = int(input())
import math
X = math.ceil(N/1.08)
if N == math.floor(X*1.08):
print(X)
else:
print(':(') | [
"misc.opposites",
"assignment.value.change",
"identifier.change",
"control_flow.branch.if.condition.change"
] | 646,748 | 646,749 | u837546225 | python |
p02842 | import math
N = int(input())
X = math.floor(N/1.08)
if N == math.ceil(X*1.08):
print(X)
else:
print(':(') | N = int(input())
import math
X = math.ceil(N/1.08)
if N == math.floor(X*1.08):
print(X)
else:
print(':(') | [
"misc.opposites",
"assignment.value.change",
"identifier.change",
"control_flow.branch.if.condition.change"
] | 646,750 | 646,749 | u837546225 | python |
p02842 | N = int(input())
for i in range(N):
X = i * 1.08
if int(X) == N:
print(i)
exit()
print(':(') | N = int(input())
for i in range(N+1):
X = i * 1.08
if int(X) == N:
print(i)
exit()
print(':(') | [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add"
] | 646,755 | 646,756 | u776311944 | python |
p02842 | N = int(input())
for i in range(N-1):
X = i * 1.08
if int(X) == N:
print(i)
exit()
print(':(') | N = int(input())
for i in range(N+1):
X = i * 1.08
if int(X) == N:
print(i)
exit()
print(':(') | [
"misc.opposites",
"expression.operator.arithmetic.change",
"call.arguments.change",
"expression.operation.binary.change",
"control_flow.loop.range.bounds.upper.change"
] | 646,757 | 646,756 | u776311944 | python |
p02842 | N = int(input())
for i in range(N):
if int(i * 1.08) == N:
print(i)
exit(0)
else:
print(":(") | N = int(input())
for i in range(N+1):
if int(i * 1.08) == N:
print(i)
exit(0)
else:
print(":(") | [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add"
] | 646,758 | 646,759 | u848535504 | python |
p02839 | def inpl(): return list(map(int, input().split()))
H, W = inpl()
A = [inpl() for _ in range(H)]
B = [inpl() for _ in range(W)]
DP = [[0 for _ in range(W+1)] for _ in range(H+1)]
DP[0][0] = 1 << 12800
for h in range(H):
for w in range(W):
d = abs(A[h][w] - B[h][w])
DP[h+1][w] |= DP[h][w] >> d
DP[h+1][w] |= DP[h][w] << d
DP[h][w+1] |= DP[h][w] >> d
DP[h][w+1] |= DP[h][w] << d
l = 1 << 12800
r = 1 << 12800
for i in range(12800):
if (DP[-1][-2]& l) | (DP[-1][-2] & r):
print(i)
break
l = l << 1
r = r >> 1 | def inpl(): return list(map(int, input().split()))
H, W = inpl()
A = [inpl() for _ in range(H)]
B = [inpl() for _ in range(H)]
DP = [[0 for _ in range(W+1)] for _ in range(H+1)]
DP[0][0] = 1 << 12800
for h in range(H):
for w in range(W):
d = abs(A[h][w] - B[h][w])
DP[h+1][w] |= DP[h][w] >> d
DP[h+1][w] |= DP[h][w] << d
DP[h][w+1] |= DP[h][w] >> d
DP[h][w+1] |= DP[h][w] << d
l = 1 << 12800
r = 1 << 12800
for i in range(12801):
if (DP[-1][-2]& l) | (DP[-1][-2] & r):
print(i)
break
l = l << 1
r = r >> 1 | [
"assignment.value.change",
"identifier.change",
"call.arguments.change",
"control_flow.loop.range.bounds.upper.change",
"literal.number.integer.change"
] | 646,763 | 646,764 | u777923818 | python |
p02839 | #https://atcoder.jp/contests/abc147/submissions/8874645
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
ofs=6400
h,w=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(h)]
B=[list(map(int,input().split())) for _ in range(h)]
dp=[[0]*w for _ in range(h)]
x=abs(A[0][0]-B[0][0])
dp[0][0]|=((1<<(ofs+x))|(1<<(ofs-x)))
from itertools import product
for i,j in product(range(h),range(w)):
x=abs(A[i][j]-B[i][j])
t=0
if(i-1>=0):
t|=dp[i-1][j]
if(j-1>=0):
t|=dp[i][j-1]
dp[i][j]=((t<<x)|(t>>x))
for i,s in enumerate(bin(dp[-1][-1])[-ofs-1:]):
if(s=='1'):
print(i)
return
resolve()
| #https://atcoder.jp/contests/abc147/submissions/8874645
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
ofs=6400
h,w=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(h)]
B=[list(map(int,input().split())) for _ in range(h)]
dp=[[0]*w for _ in range(h)]
x=abs(A[0][0]-B[0][0])
dp[0][0]|=((1<<(ofs+x))|(1<<(ofs-x)))
from itertools import product
for i,j in product(range(h),range(w)):
x=abs(A[i][j]-B[i][j])
t=0
if(i-1>=0):
t|=dp[i-1][j]
if(j-1>=0):
t|=dp[i][j-1]
dp[i][j]|=((t<<x)|(t>>x))
for i,s in enumerate(bin(dp[-1][-1])[-ofs-1:]):
if(s=='1'):
print(i)
return
resolve()
| [
"assignment.value.change"
] | 646,801 | 646,802 | u708618797 | python |
p02839 | #https://atcoder.jp/contests/abc147/submissions/8874645
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
ofs=6400
h,w=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(h)]
B=[list(map(int,input().split())) for _ in range(h)]
dp=[[0]*w for _ in range(h)]
x=abs(A[0][0]-B[0][0])
dp[0][0]|=(1<<(ofs+x))|(1<<(ofs-x))
from itertools import product
for i,j in product(range(h),range(w)):
x=abs(A[i][j]-B[i][j])
t=0
if(i-1>=0):
t|=dp[i-1][j]
if(j-1>=0):
t|=dp[i][j-1]
dp[i][j]=(t<<x)|(t>>x)
for i,s in enumerate(bin(dp[-1][-1])[-ofs-1:]):
if(s=='1'):
print(i)
return
resolve()
| #https://atcoder.jp/contests/abc147/submissions/8874645
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
ofs=6400
h,w=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(h)]
B=[list(map(int,input().split())) for _ in range(h)]
dp=[[0]*w for _ in range(h)]
x=abs(A[0][0]-B[0][0])
dp[0][0]|=((1<<(ofs+x))|(1<<(ofs-x)))
from itertools import product
for i,j in product(range(h),range(w)):
x=abs(A[i][j]-B[i][j])
t=0
if(i-1>=0):
t|=dp[i-1][j]
if(j-1>=0):
t|=dp[i][j-1]
dp[i][j]|=((t<<x)|(t>>x))
for i,s in enumerate(bin(dp[-1][-1])[-ofs-1:]):
if(s=='1'):
print(i)
return
resolve()
| [
"assignment.value.change"
] | 646,803 | 646,802 | u708618797 | python |
p02839 | H,W = map(int,input().split())
A = [list(map(int,input().split()))for _ in range(H)]
for i in range(H):
b = list(map(int,input().split()))
for j in range(W):
A[i][j] = abs(A[i][j]-b[j])
NUM = 100
DP = [[[0]*NUM for i in range(W)]for j in range(H)]
DP[0][0][A[0][0]] = 1
i = 0
for j in range(W-1):
a = A[i][j+1]
for k in range(NUM):
if DP[i][j][k] == 1:
if 0 <= a-k < NUM:
DP[i][j+1][a-k] = 1
if 0 <= k-a < NUM:
DP[i][j+1][k-a] = 1
if 0 <= k+a < NUM:
DP[i][j+1][k+a] = 1
j = 0
for i in range(H-1):
a = A[i+1][j]
for k in range(NUM):
if DP[i][j][k] == 1:
if 0 <= a-k < NUM:
DP[i+1][j][a-k] = 1
if 0 <= k-a < NUM:
DP[i+1][j][k-a] = 1
if 0 <= k+a < NUM:
DP[i+1][j][k+a] = 1
for i in range(H-1):
for j in range(W-1):
a = A[i+1][j+1]
for k in range(NUM):
if DP[i+1][j][k] == 1:
if 0 <= a-k < NUM:
DP[i+1][j+1][a-k] = 1
if 0 <= k-a < NUM:
DP[i+1][j+1][k-a] = 1
if 0 <= k+a < NUM:
DP[i+1][j+1][k+a] = 1
if DP[i][j+1][k] == 1:
if 0 <= a-k < NUM:
DP[i+1][j+1][a-k] = 1
if 0 <= k-a < NUM:
DP[i+1][j+1][k-a] = 1
if 0 <= k+a < NUM:
DP[i+1][j+1][k+a] = 1
print(DP[-1][-1].index(1)) | H,W = map(int,input().split())
A = [list(map(int,input().split()))for _ in range(H)]
for i in range(H):
b = list(map(int,input().split()))
for j in range(W):
A[i][j] = abs(A[i][j]-b[j])
NUM = 6400
DP = [[[0]*NUM for i in range(W)]for j in range(H)]
DP[0][0][A[0][0]] = 1
i = 0
for j in range(W-1):
a = A[i][j+1]
for k in range(NUM):
if DP[i][j][k] == 1:
if 0 <= a-k < NUM:
DP[i][j+1][a-k] = 1
if 0 <= k-a < NUM:
DP[i][j+1][k-a] = 1
if 0 <= k+a < NUM:
DP[i][j+1][k+a] = 1
j = 0
for i in range(H-1):
a = A[i+1][j]
for k in range(NUM):
if DP[i][j][k] == 1:
if 0 <= a-k < NUM:
DP[i+1][j][a-k] = 1
if 0 <= k-a < NUM:
DP[i+1][j][k-a] = 1
if 0 <= k+a < NUM:
DP[i+1][j][k+a] = 1
for i in range(H-1):
for j in range(W-1):
a = A[i+1][j+1]
for k in range(NUM):
if DP[i+1][j][k] == 1:
if 0 <= a-k < NUM:
DP[i+1][j+1][a-k] = 1
if 0 <= k-a < NUM:
DP[i+1][j+1][k-a] = 1
if 0 <= k+a < NUM:
DP[i+1][j+1][k+a] = 1
if DP[i][j+1][k] == 1:
if 0 <= a-k < NUM:
DP[i+1][j+1][a-k] = 1
if 0 <= k-a < NUM:
DP[i+1][j+1][k-a] = 1
if 0 <= k+a < NUM:
DP[i+1][j+1][k+a] = 1
print(DP[-1][-1].index(1)) | [
"literal.number.integer.change",
"assignment.value.change"
] | 646,815 | 646,811 | u211160392 | python |
p02839 | H,W = map(int,input().split())
A = [list(map(int,input().split()))for _ in range(H)]
for i in range(H):
b = list(map(int,input().split()))
for j in range(W):
A[i][j] = abs(A[i][j]-b[j])
NUM = 10
DP = [[[0]*NUM for i in range(W)]for j in range(H)]
DP[0][0][A[0][0]] = 1
i = 0
for j in range(W-1):
a = A[i][j+1]
for k in range(NUM):
if DP[i][j][k] == 1:
if 0 <= a-k < NUM:
DP[i][j+1][a-k] = 1
if 0 <= k-a < NUM:
DP[i][j+1][k-a] = 1
if 0 <= k+a < NUM:
DP[i][j+1][k+a] = 1
j = 0
for i in range(H-1):
a = A[i+1][j]
for k in range(NUM):
if DP[i][j][k] == 1:
if 0 <= a-k < NUM:
DP[i+1][j][a-k] = 1
if 0 <= k-a < NUM:
DP[i+1][j][k-a] = 1
if 0 <= k+a < NUM:
DP[i+1][j][k+a] = 1
for i in range(H-1):
for j in range(W-1):
a = A[i+1][j+1]
for k in range(NUM):
if DP[i+1][j][k] == 1:
if 0 <= a-k < NUM:
DP[i+1][j+1][a-k] = 1
if 0 <= k-a < NUM:
DP[i+1][j+1][k-a] = 1
if 0 <= k+a < NUM:
DP[i+1][j+1][k+a] = 1
if DP[i][j+1][k] == 1:
if 0 <= a-k < NUM:
DP[i+1][j+1][a-k] = 1
if 0 <= k-a < NUM:
DP[i+1][j+1][k-a] = 1
if 0 <= k+a < NUM:
DP[i+1][j+1][k+a] = 1
print(DP[-1][-1].index(1)) | H,W = map(int,input().split())
A = [list(map(int,input().split()))for _ in range(H)]
for i in range(H):
b = list(map(int,input().split()))
for j in range(W):
A[i][j] = abs(A[i][j]-b[j])
NUM = 6400
DP = [[[0]*NUM for i in range(W)]for j in range(H)]
DP[0][0][A[0][0]] = 1
i = 0
for j in range(W-1):
a = A[i][j+1]
for k in range(NUM):
if DP[i][j][k] == 1:
if 0 <= a-k < NUM:
DP[i][j+1][a-k] = 1
if 0 <= k-a < NUM:
DP[i][j+1][k-a] = 1
if 0 <= k+a < NUM:
DP[i][j+1][k+a] = 1
j = 0
for i in range(H-1):
a = A[i+1][j]
for k in range(NUM):
if DP[i][j][k] == 1:
if 0 <= a-k < NUM:
DP[i+1][j][a-k] = 1
if 0 <= k-a < NUM:
DP[i+1][j][k-a] = 1
if 0 <= k+a < NUM:
DP[i+1][j][k+a] = 1
for i in range(H-1):
for j in range(W-1):
a = A[i+1][j+1]
for k in range(NUM):
if DP[i+1][j][k] == 1:
if 0 <= a-k < NUM:
DP[i+1][j+1][a-k] = 1
if 0 <= k-a < NUM:
DP[i+1][j+1][k-a] = 1
if 0 <= k+a < NUM:
DP[i+1][j+1][k+a] = 1
if DP[i][j+1][k] == 1:
if 0 <= a-k < NUM:
DP[i+1][j+1][a-k] = 1
if 0 <= k-a < NUM:
DP[i+1][j+1][k-a] = 1
if 0 <= k+a < NUM:
DP[i+1][j+1][k+a] = 1
print(DP[-1][-1].index(1)) | [
"literal.number.integer.change",
"assignment.value.change"
] | 646,816 | 646,811 | u211160392 | python |
p02839 | def main(sample_file = ''):
""" convenient functions
# for i, a in enumerate(iterable)
# q, mod = divmod(a, b)
# divmod(x, y) returns the tuple (x//y, x%y)
# Higher-order function: reduce(operator.mul, xyz_count, 1)
# manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
"""
"""convenient decorator
# @functools.lru_cache():
# to facilitate use of recursive function
# ex:
# from functools import lru_cache
# import sys
# sys.setrecursionlimit(10**9)
# @lru_cache(maxsize=None)
# def fib(n):
# if n < 2:
# return n
# return fib(n-1) + fib(n-2)
# print(fib(1000))
"""
# import numpy as np
import sys
sys.setrecursionlimit(10**7)
from itertools import accumulate, combinations, permutations, product # https://docs.python.org/ja/3/library/itertools.html
# accumulate() returns iterator! to get list: list(accumulate())
from math import factorial, ceil, floor, sqrt
def factorize(n):
"""return the factors of the Arg and count of each factor
Args:
n (long): number to be resolved into factors
Returns:
list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
"""
fct = [] # prime factor
b, e = 2, 0 # base, exponent
while b * b <= n:
while n % b == 0:
n = n // b
e = e + 1
if e > 0:
fct.append((b, e))
b, e = b + 1, 0
if n > 1:
fct.append((n, 1))
return fct
def combinations_count(n, r):
"""Return the number of selecting r pieces of items from n kinds of items.
Args:
n (long): number
r (long): number
Raises:
Exception: not defined when n or r is negative
Returns:
long: number
"""
# TODO: How should I do when n - r is negative?
if n < 0 or r < 0:
raise Exception('combinations_count(n, r) not defined when n or r is negative')
if n - r < r: r = n - r
if r < 0: return 0
if r == 0: return 1
if r == 1: return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2,r+1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p-1,r,p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
def combinations_with_replacement_count(n, r):
"""Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
Args:
n (long): number
r (long): number
Raises:
Exception: not defined when n or r is negative
Returns:
long: number
"""
if n < 0 or r < 0:
raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
elif n == 0:
return 1
else:
return combinations_count(n + r - 1, r)
from bisect import bisect_left, bisect_right
from collections import deque, Counter, defaultdict # https://docs.python.org/ja/3/library/collections.html#collections.deque
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
import operator
from operator import itemgetter #sort
# ex1: List.sort(key=itemgetter(1))
# ex2: sorted(tuples, key=itemgetter(1,2))
from functools import reduce, lru_cache
def chmin(x, y):
"""change minimum
if x > y, x = y and return (x, True).
convenient when solving problems of dp[i]
Args:
x (long): current minimum value
y (long): potential minimum value
Returns:
(x, bool): (x, True) when updated, else (x, False)
"""
if x > y:
x = y
return (x, True)
else:
return (x, False)
def chmax(x, y):
"""change maximum
if x < y, x = y and return (x, True).
convenient when solving problems of dp[i]
Args:
x (long): current maximum value
y (long): potential maximum value
Returns:
(x, bool): (x, True) when updated, else (x, False)
"""
if x < y:
x = y
return (x, True)
else:
return (x, False)
from math import gcd # Deprecated since version 3.5: Use math.gcd() instead.
def gcds(numbers):
return reduce(gcd, numbers)
def lcm(x, y):
return (x * y) // gcd(x, y)
def lcms(numbers):
return reduce(lcm, numbers, 1)
def make_divisors(n, reversed=False):
"""create list of divisors
Args:
number (int): number from which list of divisors is created
reversed (bool, optional): ascending order if False. Defaults to False.
Returns:
list: list of divisors
"""
divisors = set()
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.add(i)
divisors.add(n//i)
return sorted(list(divisors),reverse=reversed)
# first create factorial_list
# fac_list = mod_factorial_list(n)
INF = 10 ** 18
MOD = 10 ** 9 + 7
modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow!
def modinv(a, p = MOD):
# evaluate reciprocal using Fermat's little theorem:
# a**(p-1) is identical to 1 (mod p) when a and p is coprime
return modpow(a, p-2, p)
def modinv_list(n, p = MOD):
if n <= 1:
return [0,1][:n+1]
else:
inv_t = [0,1]
for i in range(2, n+1):
inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
return inv_t
def modfactorial_list(n, p = MOD):
if n == 0:
return [1]
else:
l = [0] * (n+1)
tmp = 1
for i in range(1, n+1):
tmp = tmp * i % p
l[i] = tmp
return l
def modcomb(n, k, fac_list = [], p = MOD):
# fac_list = modfactorial_list(100)
# print(modcomb(100, 5, modfactorial_list(100)))
from math import factorial
if n < 0 or k < 0 or n < k: return 0
if n == 0 or k == 0: return 1
if len(fac_list) <= n:
a = factorial(n) % p
b = factorial(k) % p
c = factorial(n-k) % p
else:
a = fac_list[n]
b = fac_list[k]
c = fac_list[n-k]
return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
def modadd(a, b, p = MOD):
return (a + b) % MOD
def modsub(a, b, p = MOD):
return (a - b) % p
def modmul(a, b, p = MOD):
return ((a % p) * (b % p)) % p
def moddiv(a, b, p = MOD):
return modmul(a, modpow(b, p-2, p))
class UnionFindTree:
"""union find tree class
TODO: fix this description...
how to use (example):
>> uf = UnionFindTree(N)
>> if uf.find_root(a) == uf.find_root(b):
>> do something
>> else:
>> do something
>> uf.unite(a, b)
"""
def __init__(self, N):
self.root = [-1] * (N+1)
self.rank = [0] * (N+1)
self.connected_num = [1] * (N+1)
def find_root(self,x):
root = self.root
while root[x] != -1:
x = root[x]
return x
def unite(self,x,y):
root = self.root
rank = self.rank
connected_num = self.connected_num
find_root = self.find_root
rx = find_root(x)
ry = find_root(y)
if rx != ry:
if rank[rx] < rank[ry]:
root[rx] = ry
rx,ry = ry,rx
else:
if rank[rx] == rank[ry]:
rank[rx] += 1
root[ry] = rx
connected_num[rx] += connected_num[ry]
# Graph: https://en.wikipedia.org/wiki/Directed_graph
# Bellman-Ford: O(|V||E|). Use this if there exists an edge with negative length in the graph
# After N steps, the shortest path has converded if there doesn't exist an cycle of edges with negative
# Watch out: d[N] == d[2*N] doesn't necessarily mean the graph doesn't have negative cycle
# ref: https://www.youtube.com/watch?v=1Z6ofKN03_Y
def BellmanFord(N, M, ABC, vertex_start, vertex_end, value_if_inf = -1, find_shortest = False):
"""to calculate furthest or shortest length between vertex_start and vertex_end using BellmanFord algorithm
Args:
N (int): number of vertices
M (int): number of edges
ABC (list): [(ai, bi, ci) for _ in range(N)] where i-th edge is directed from vertex ai to vertex bi and the length is ci
vertex_start (int): start vertex. usually use 0.
vertex_end (int): end vertex. usually use N-1.
value_if_inf (int or string as you like, optional): value you want when the furthest (or shortest) distance is infinite (or -infinite). Defaults to -1.
find_shortest (bool, optional): choose False to find furthest path. Defaults to False.
Returns:
int or string: normally int (but can be str if you set value_if_inf to str)
Example:
N, M, P = R()
ABC = [R() for _ in range(M)]
ABC = [(a-1, b-1, c-P) for a, b, c in ABC]
print(BellmanFord(N, M, ABC, 0, N-1, value_if_inf = 'inf'))
"""
def make_reachable_list(N, M, ABC, vertex_start, vertex_end):
reachable_to_direct = defaultdict(list)
reachable_from_direct = defaultdict(list)
reachable_from_start = [False] * N
reachable_to_end = [False] * N
reachable_from_start[vertex_start] = True
reachable_to_end[vertex_end] = True
reachable_from_both_sides = [False] * N
dfs_from_start = []
dfs_to_end = []
for a, b, c in ABC:
reachable_to_direct[a].append(b)
reachable_from_direct[b].append(a)
if a == vertex_start:
dfs_from_start.append(b)
reachable_from_start[b] = True
if b == vertex_end:
dfs_to_end.append(a)
reachable_to_end[a] = True
while dfs_from_start:
v = dfs_from_start.pop()
for i in reachable_to_direct[v]:
if not reachable_from_start[i]:
reachable_from_start[i] = True
dfs_from_start.append(i)
while dfs_to_end:
v = dfs_to_end.pop()
for i in reachable_from_direct[v]:
if not reachable_to_end[i]:
reachable_to_end[i] = True
dfs_to_end.append(i)
for i in range(N):
reachable_from_both_sides[i] = reachable_from_start[i] and reachable_to_end[i]
return reachable_from_both_sides
reachable_from_both_sides = make_reachable_list(N, M, ABC, vertex_start, vertex_end)
if find_shortest:
dist = [INF for i in range(N)]
else:
dist = [-INF for i in range(N)]
dist[vertex_start] = 0
for i in range(N):
updated = False
for a, b, c in ABC:
if not reachable_from_both_sides[a]:
continue
elif find_shortest:
update_condition = dist[a] + c < dist[b]
else:
update_condition = dist[a] + c > dist[b]
if dist[a] != INF and update_condition:
dist[b] = dist[a] + c
updated = True
if i == N-1:
return value_if_inf
if not updated:
break
return dist[vertex_end]
""" initialize variables and set inputs
# initialize variables
# to initialize list, use [0] * n
# to initialize two dimentional array:
# ex) [[0] * N for _ in range(N)]
# ex2) dp = [[0] * (N+1) for _ in range(W*2)]
# set inputs
# put inputs between specific values (almost as quickly)
# ex) S = [-INF] + [int(r()) for _ in range(A)] + [INF]
# open(0).read() is sometimes useful:
# ex) n, m, *x = map(int, open(0).read().split())
# min(x[::2]) - max(x[1::2])
# ex2) *x, = map(int, open(0).read().split())
# don't forget to add comma after *x if only one variable is used
# preprocessing
# transpose = [x for x in zip(*data)]
# ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
# flat = [flatten for inner in data for flatten in inner]
# ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [1, 2, 3, 4, 5, 6, 7, 8, 9]
# calculate and output
# output pattern
# ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6
"""
# functions to read input
r = lambda: sys.stdin.readline().strip()
r_int = lambda: int(r())
r_float = lambda: float(r())
R = lambda: list(map(int, r().split()))
R_map = lambda: map(int, r().split())
R_float = lambda: list(map(float, r().split()))
R_tuple = lambda: tuple(map(int, r().split()))
""" how to treat input
# single int: int(r())
# single string: r()
# single float: float(r())
# line int: R()
# line string: r().split()
# line (str, int, int): [j if i == 0 else int(j) for i, j in enumerate(r().split())]
# lines int: [R() for _ in range(n)]
"""
# for test
if sample_file:
sys.stdin = open(sample_file)
# ----------------------------------
# main
from operator import sub
H, W = R()
A = [R() for _ in range(H)]
B = [R() for _ in range(H)]
AB = [list(map(lambda m, n: abs(m-n), a, b)) for (a, b) in zip(A, B)]
dp = [[[0]*6402 for w in range(W+1)] for h in range(H+1)]
dp[0][0][0] = 1
for h in range(H):
for w in range(W):
ab = AB[h][w]
for i in range(6401):
# 6400?
if dp[h][w][i] == 1:
dp[h+1][w][i+ab] = 1
dp[h+1][w][abs(i-ab)] = 1
dp[h][w+1][i+ab] = 1
dp[h][w+1][abs(i-ab)] = 1
for i in range(100):
if dp[H-1][W][i] == 1:
print(i)
return
# to finish code, use return instead of exit()
# end of main
# ----------------------------------
"""memo: how to use defaultdict of list
# initialize
Dic = defaultdict(list)
# append / extend
Dic[x].append(y)
# three methods for loop: keys(), values(), items()
for k, v in Dic.items():
"""
"""memo: how to solve binary problems
# to make binary digits text
>>> a = 5
>>> bin_str_a = format(a, '#06b')
>>> print(bin_str_a)
0b0101 # first 2 strings (='0b') indicates it is binary
"""
"""memo: how to solve the problem
creating simple test/answer
greed
simple dp
graph
"""
if __name__ == '__main__':
main()
| def main(sample_file = ''):
""" convenient functions
# for i, a in enumerate(iterable)
# q, mod = divmod(a, b)
# divmod(x, y) returns the tuple (x//y, x%y)
# Higher-order function: reduce(operator.mul, xyz_count, 1)
# manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
"""
"""convenient decorator
# @functools.lru_cache():
# to facilitate use of recursive function
# ex:
# from functools import lru_cache
# import sys
# sys.setrecursionlimit(10**9)
# @lru_cache(maxsize=None)
# def fib(n):
# if n < 2:
# return n
# return fib(n-1) + fib(n-2)
# print(fib(1000))
"""
# import numpy as np
import sys
sys.setrecursionlimit(10**7)
from itertools import accumulate, combinations, permutations, product # https://docs.python.org/ja/3/library/itertools.html
# accumulate() returns iterator! to get list: list(accumulate())
from math import factorial, ceil, floor, sqrt
def factorize(n):
"""return the factors of the Arg and count of each factor
Args:
n (long): number to be resolved into factors
Returns:
list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
"""
fct = [] # prime factor
b, e = 2, 0 # base, exponent
while b * b <= n:
while n % b == 0:
n = n // b
e = e + 1
if e > 0:
fct.append((b, e))
b, e = b + 1, 0
if n > 1:
fct.append((n, 1))
return fct
def combinations_count(n, r):
"""Return the number of selecting r pieces of items from n kinds of items.
Args:
n (long): number
r (long): number
Raises:
Exception: not defined when n or r is negative
Returns:
long: number
"""
# TODO: How should I do when n - r is negative?
if n < 0 or r < 0:
raise Exception('combinations_count(n, r) not defined when n or r is negative')
if n - r < r: r = n - r
if r < 0: return 0
if r == 0: return 1
if r == 1: return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2,r+1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p-1,r,p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
def combinations_with_replacement_count(n, r):
"""Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
Args:
n (long): number
r (long): number
Raises:
Exception: not defined when n or r is negative
Returns:
long: number
"""
if n < 0 or r < 0:
raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
elif n == 0:
return 1
else:
return combinations_count(n + r - 1, r)
from bisect import bisect_left, bisect_right
from collections import deque, Counter, defaultdict # https://docs.python.org/ja/3/library/collections.html#collections.deque
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
import operator
from operator import itemgetter #sort
# ex1: List.sort(key=itemgetter(1))
# ex2: sorted(tuples, key=itemgetter(1,2))
from functools import reduce, lru_cache
def chmin(x, y):
"""change minimum
if x > y, x = y and return (x, True).
convenient when solving problems of dp[i]
Args:
x (long): current minimum value
y (long): potential minimum value
Returns:
(x, bool): (x, True) when updated, else (x, False)
"""
if x > y:
x = y
return (x, True)
else:
return (x, False)
def chmax(x, y):
"""change maximum
if x < y, x = y and return (x, True).
convenient when solving problems of dp[i]
Args:
x (long): current maximum value
y (long): potential maximum value
Returns:
(x, bool): (x, True) when updated, else (x, False)
"""
if x < y:
x = y
return (x, True)
else:
return (x, False)
from math import gcd # Deprecated since version 3.5: Use math.gcd() instead.
def gcds(numbers):
return reduce(gcd, numbers)
def lcm(x, y):
return (x * y) // gcd(x, y)
def lcms(numbers):
return reduce(lcm, numbers, 1)
def make_divisors(n, reversed=False):
"""create list of divisors
Args:
number (int): number from which list of divisors is created
reversed (bool, optional): ascending order if False. Defaults to False.
Returns:
list: list of divisors
"""
divisors = set()
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.add(i)
divisors.add(n//i)
return sorted(list(divisors),reverse=reversed)
# first create factorial_list
# fac_list = mod_factorial_list(n)
INF = 10 ** 18
MOD = 10 ** 9 + 7
modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow!
def modinv(a, p = MOD):
# evaluate reciprocal using Fermat's little theorem:
# a**(p-1) is identical to 1 (mod p) when a and p is coprime
return modpow(a, p-2, p)
def modinv_list(n, p = MOD):
if n <= 1:
return [0,1][:n+1]
else:
inv_t = [0,1]
for i in range(2, n+1):
inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
return inv_t
def modfactorial_list(n, p = MOD):
if n == 0:
return [1]
else:
l = [0] * (n+1)
tmp = 1
for i in range(1, n+1):
tmp = tmp * i % p
l[i] = tmp
return l
def modcomb(n, k, fac_list = [], p = MOD):
# fac_list = modfactorial_list(100)
# print(modcomb(100, 5, modfactorial_list(100)))
from math import factorial
if n < 0 or k < 0 or n < k: return 0
if n == 0 or k == 0: return 1
if len(fac_list) <= n:
a = factorial(n) % p
b = factorial(k) % p
c = factorial(n-k) % p
else:
a = fac_list[n]
b = fac_list[k]
c = fac_list[n-k]
return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
def modadd(a, b, p = MOD):
return (a + b) % MOD
def modsub(a, b, p = MOD):
return (a - b) % p
def modmul(a, b, p = MOD):
return ((a % p) * (b % p)) % p
def moddiv(a, b, p = MOD):
return modmul(a, modpow(b, p-2, p))
class UnionFindTree:
"""union find tree class
TODO: fix this description...
how to use (example):
>> uf = UnionFindTree(N)
>> if uf.find_root(a) == uf.find_root(b):
>> do something
>> else:
>> do something
>> uf.unite(a, b)
"""
def __init__(self, N):
self.root = [-1] * (N+1)
self.rank = [0] * (N+1)
self.connected_num = [1] * (N+1)
def find_root(self,x):
root = self.root
while root[x] != -1:
x = root[x]
return x
def unite(self,x,y):
root = self.root
rank = self.rank
connected_num = self.connected_num
find_root = self.find_root
rx = find_root(x)
ry = find_root(y)
if rx != ry:
if rank[rx] < rank[ry]:
root[rx] = ry
rx,ry = ry,rx
else:
if rank[rx] == rank[ry]:
rank[rx] += 1
root[ry] = rx
connected_num[rx] += connected_num[ry]
# Graph: https://en.wikipedia.org/wiki/Directed_graph
# Bellman-Ford: O(|V||E|). Use this if there exists an edge with negative length in the graph
# After N steps, the shortest path has converded if there doesn't exist an cycle of edges with negative
# Watch out: d[N] == d[2*N] doesn't necessarily mean the graph doesn't have negative cycle
# ref: https://www.youtube.com/watch?v=1Z6ofKN03_Y
def BellmanFord(N, M, ABC, vertex_start, vertex_end, value_if_inf = -1, find_shortest = False):
"""to calculate furthest or shortest length between vertex_start and vertex_end using BellmanFord algorithm
Args:
N (int): number of vertices
M (int): number of edges
ABC (list): [(ai, bi, ci) for _ in range(N)] where i-th edge is directed from vertex ai to vertex bi and the length is ci
vertex_start (int): start vertex. usually use 0.
vertex_end (int): end vertex. usually use N-1.
value_if_inf (int or string as you like, optional): value you want when the furthest (or shortest) distance is infinite (or -infinite). Defaults to -1.
find_shortest (bool, optional): choose False to find furthest path. Defaults to False.
Returns:
int or string: normally int (but can be str if you set value_if_inf to str)
Example:
N, M, P = R()
ABC = [R() for _ in range(M)]
ABC = [(a-1, b-1, c-P) for a, b, c in ABC]
print(BellmanFord(N, M, ABC, 0, N-1, value_if_inf = 'inf'))
"""
def make_reachable_list(N, M, ABC, vertex_start, vertex_end):
reachable_to_direct = defaultdict(list)
reachable_from_direct = defaultdict(list)
reachable_from_start = [False] * N
reachable_to_end = [False] * N
reachable_from_start[vertex_start] = True
reachable_to_end[vertex_end] = True
reachable_from_both_sides = [False] * N
dfs_from_start = []
dfs_to_end = []
for a, b, c in ABC:
reachable_to_direct[a].append(b)
reachable_from_direct[b].append(a)
if a == vertex_start:
dfs_from_start.append(b)
reachable_from_start[b] = True
if b == vertex_end:
dfs_to_end.append(a)
reachable_to_end[a] = True
while dfs_from_start:
v = dfs_from_start.pop()
for i in reachable_to_direct[v]:
if not reachable_from_start[i]:
reachable_from_start[i] = True
dfs_from_start.append(i)
while dfs_to_end:
v = dfs_to_end.pop()
for i in reachable_from_direct[v]:
if not reachable_to_end[i]:
reachable_to_end[i] = True
dfs_to_end.append(i)
for i in range(N):
reachable_from_both_sides[i] = reachable_from_start[i] and reachable_to_end[i]
return reachable_from_both_sides
reachable_from_both_sides = make_reachable_list(N, M, ABC, vertex_start, vertex_end)
if find_shortest:
dist = [INF for i in range(N)]
else:
dist = [-INF for i in range(N)]
dist[vertex_start] = 0
for i in range(N):
updated = False
for a, b, c in ABC:
if not reachable_from_both_sides[a]:
continue
elif find_shortest:
update_condition = dist[a] + c < dist[b]
else:
update_condition = dist[a] + c > dist[b]
if dist[a] != INF and update_condition:
dist[b] = dist[a] + c
updated = True
if i == N-1:
return value_if_inf
if not updated:
break
return dist[vertex_end]
""" initialize variables and set inputs
# initialize variables
# to initialize list, use [0] * n
# to initialize two dimentional array:
# ex) [[0] * N for _ in range(N)]
# ex2) dp = [[0] * (N+1) for _ in range(W*2)]
# set inputs
# put inputs between specific values (almost as quickly)
# ex) S = [-INF] + [int(r()) for _ in range(A)] + [INF]
# open(0).read() is sometimes useful:
# ex) n, m, *x = map(int, open(0).read().split())
# min(x[::2]) - max(x[1::2])
# ex2) *x, = map(int, open(0).read().split())
# don't forget to add comma after *x if only one variable is used
# preprocessing
# transpose = [x for x in zip(*data)]
# ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
# flat = [flatten for inner in data for flatten in inner]
# ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [1, 2, 3, 4, 5, 6, 7, 8, 9]
# calculate and output
# output pattern
# ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6
"""
# functions to read input
r = lambda: sys.stdin.readline().strip()
r_int = lambda: int(r())
r_float = lambda: float(r())
R = lambda: list(map(int, r().split()))
R_map = lambda: map(int, r().split())
R_float = lambda: list(map(float, r().split()))
R_tuple = lambda: tuple(map(int, r().split()))
""" how to treat input
# single int: int(r())
# single string: r()
# single float: float(r())
# line int: R()
# line string: r().split()
# line (str, int, int): [j if i == 0 else int(j) for i, j in enumerate(r().split())]
# lines int: [R() for _ in range(n)]
"""
# for test
if sample_file:
sys.stdin = open(sample_file)
# ----------------------------------
# main
from operator import sub
H, W = R()
A = [R() for _ in range(H)]
B = [R() for _ in range(H)]
AB = [list(map(lambda m, n: abs(m-n), a, b)) for (a, b) in zip(A, B)]
dp = [[[0]*12403 for w in range(W+1)] for h in range(H+1)]
dp[0][0][0] = 1
for h in range(H):
for w in range(W):
ab = AB[h][w]
for i in range(6401):
# 6400?
if dp[h][w][i] == 1:
dp[h+1][w][i+ab] = 1
dp[h+1][w][abs(i-ab)] = 1
dp[h][w+1][i+ab] = 1
dp[h][w+1][abs(i-ab)] = 1
for i in range(1000):
if dp[H-1][W][i] == 1:
print(i)
return
# to finish code, use return instead of exit()
# end of main
# ----------------------------------
"""memo: how to use defaultdict of list
# initialize
Dic = defaultdict(list)
# append / extend
Dic[x].append(y)
# three methods for loop: keys(), values(), items()
for k, v in Dic.items():
"""
"""memo: how to solve binary problems
# to make binary digits text
>>> a = 5
>>> bin_str_a = format(a, '#06b')
>>> print(bin_str_a)
0b0101 # first 2 strings (='0b') indicates it is binary
"""
"""memo: how to solve the problem
creating simple test/answer
greed
simple dp
graph
"""
if __name__ == '__main__':
main()
| [
"literal.number.integer.change",
"assignment.value.change",
"expression.operation.binary.change",
"call.arguments.change",
"control_flow.loop.range.bounds.upper.change"
] | 646,832 | 646,829 | u988402778 | python |
p02839 | def main(sample_file = ''):
""" convenient functions
# for i, a in enumerate(iterable)
# q, mod = divmod(a, b)
# divmod(x, y) returns the tuple (x//y, x%y)
# Higher-order function: reduce(operator.mul, xyz_count, 1)
# manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
"""
"""convenient decorator
# @functools.lru_cache():
# to facilitate use of recursive function
# ex:
# from functools import lru_cache
# import sys
# sys.setrecursionlimit(10**9)
# @lru_cache(maxsize=None)
# def fib(n):
# if n < 2:
# return n
# return fib(n-1) + fib(n-2)
# print(fib(1000))
"""
# import numpy as np
import sys
sys.setrecursionlimit(10**7)
from itertools import accumulate, combinations, permutations, product # https://docs.python.org/ja/3/library/itertools.html
# accumulate() returns iterator! to get list: list(accumulate())
from math import factorial, ceil, floor, sqrt
def factorize(n):
"""return the factors of the Arg and count of each factor
Args:
n (long): number to be resolved into factors
Returns:
list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
"""
fct = [] # prime factor
b, e = 2, 0 # base, exponent
while b * b <= n:
while n % b == 0:
n = n // b
e = e + 1
if e > 0:
fct.append((b, e))
b, e = b + 1, 0
if n > 1:
fct.append((n, 1))
return fct
def combinations_count(n, r):
"""Return the number of selecting r pieces of items from n kinds of items.
Args:
n (long): number
r (long): number
Raises:
Exception: not defined when n or r is negative
Returns:
long: number
"""
# TODO: How should I do when n - r is negative?
if n < 0 or r < 0:
raise Exception('combinations_count(n, r) not defined when n or r is negative')
if n - r < r: r = n - r
if r < 0: return 0
if r == 0: return 1
if r == 1: return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2,r+1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p-1,r,p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
def combinations_with_replacement_count(n, r):
"""Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
Args:
n (long): number
r (long): number
Raises:
Exception: not defined when n or r is negative
Returns:
long: number
"""
if n < 0 or r < 0:
raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
elif n == 0:
return 1
else:
return combinations_count(n + r - 1, r)
from bisect import bisect_left, bisect_right
from collections import deque, Counter, defaultdict # https://docs.python.org/ja/3/library/collections.html#collections.deque
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
import operator
from operator import itemgetter #sort
# ex1: List.sort(key=itemgetter(1))
# ex2: sorted(tuples, key=itemgetter(1,2))
from functools import reduce, lru_cache
def chmin(x, y):
"""change minimum
if x > y, x = y and return (x, True).
convenient when solving problems of dp[i]
Args:
x (long): current minimum value
y (long): potential minimum value
Returns:
(x, bool): (x, True) when updated, else (x, False)
"""
if x > y:
x = y
return (x, True)
else:
return (x, False)
def chmax(x, y):
"""change maximum
if x < y, x = y and return (x, True).
convenient when solving problems of dp[i]
Args:
x (long): current maximum value
y (long): potential maximum value
Returns:
(x, bool): (x, True) when updated, else (x, False)
"""
if x < y:
x = y
return (x, True)
else:
return (x, False)
from math import gcd # Deprecated since version 3.5: Use math.gcd() instead.
def gcds(numbers):
return reduce(gcd, numbers)
def lcm(x, y):
return (x * y) // gcd(x, y)
def lcms(numbers):
return reduce(lcm, numbers, 1)
def make_divisors(n, reversed=False):
"""create list of divisors
Args:
number (int): number from which list of divisors is created
reversed (bool, optional): ascending order if False. Defaults to False.
Returns:
list: list of divisors
"""
divisors = set()
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.add(i)
divisors.add(n//i)
return sorted(list(divisors),reverse=reversed)
# first create factorial_list
# fac_list = mod_factorial_list(n)
INF = 10 ** 18
MOD = 10 ** 9 + 7
modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow!
def modinv(a, p = MOD):
# evaluate reciprocal using Fermat's little theorem:
# a**(p-1) is identical to 1 (mod p) when a and p is coprime
return modpow(a, p-2, p)
def modinv_list(n, p = MOD):
if n <= 1:
return [0,1][:n+1]
else:
inv_t = [0,1]
for i in range(2, n+1):
inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
return inv_t
def modfactorial_list(n, p = MOD):
if n == 0:
return [1]
else:
l = [0] * (n+1)
tmp = 1
for i in range(1, n+1):
tmp = tmp * i % p
l[i] = tmp
return l
def modcomb(n, k, fac_list = [], p = MOD):
# fac_list = modfactorial_list(100)
# print(modcomb(100, 5, modfactorial_list(100)))
from math import factorial
if n < 0 or k < 0 or n < k: return 0
if n == 0 or k == 0: return 1
if len(fac_list) <= n:
a = factorial(n) % p
b = factorial(k) % p
c = factorial(n-k) % p
else:
a = fac_list[n]
b = fac_list[k]
c = fac_list[n-k]
return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
def modadd(a, b, p = MOD):
return (a + b) % MOD
def modsub(a, b, p = MOD):
return (a - b) % p
def modmul(a, b, p = MOD):
return ((a % p) * (b % p)) % p
def moddiv(a, b, p = MOD):
return modmul(a, modpow(b, p-2, p))
class UnionFindTree:
"""union find tree class
TODO: fix this description...
how to use (example):
>> uf = UnionFindTree(N)
>> if uf.find_root(a) == uf.find_root(b):
>> do something
>> else:
>> do something
>> uf.unite(a, b)
"""
def __init__(self, N):
self.root = [-1] * (N+1)
self.rank = [0] * (N+1)
self.connected_num = [1] * (N+1)
def find_root(self,x):
root = self.root
while root[x] != -1:
x = root[x]
return x
def unite(self,x,y):
root = self.root
rank = self.rank
connected_num = self.connected_num
find_root = self.find_root
rx = find_root(x)
ry = find_root(y)
if rx != ry:
if rank[rx] < rank[ry]:
root[rx] = ry
rx,ry = ry,rx
else:
if rank[rx] == rank[ry]:
rank[rx] += 1
root[ry] = rx
connected_num[rx] += connected_num[ry]
# Graph: https://en.wikipedia.org/wiki/Directed_graph
# Bellman-Ford: O(|V||E|). Use this if there exists an edge with negative length in the graph
# After N steps, the shortest path has converded if there doesn't exist an cycle of edges with negative
# Watch out: d[N] == d[2*N] doesn't necessarily mean the graph doesn't have negative cycle
# ref: https://www.youtube.com/watch?v=1Z6ofKN03_Y
def BellmanFord(N, M, ABC, vertex_start, vertex_end, value_if_inf = -1, find_shortest = False):
"""to calculate furthest or shortest length between vertex_start and vertex_end using BellmanFord algorithm
Args:
N (int): number of vertices
M (int): number of edges
ABC (list): [(ai, bi, ci) for _ in range(N)] where i-th edge is directed from vertex ai to vertex bi and the length is ci
vertex_start (int): start vertex. usually use 0.
vertex_end (int): end vertex. usually use N-1.
value_if_inf (int or string as you like, optional): value you want when the furthest (or shortest) distance is infinite (or -infinite). Defaults to -1.
find_shortest (bool, optional): choose False to find furthest path. Defaults to False.
Returns:
int or string: normally int (but can be str if you set value_if_inf to str)
Example:
N, M, P = R()
ABC = [R() for _ in range(M)]
ABC = [(a-1, b-1, c-P) for a, b, c in ABC]
print(BellmanFord(N, M, ABC, 0, N-1, value_if_inf = 'inf'))
"""
def make_reachable_list(N, M, ABC, vertex_start, vertex_end):
reachable_to_direct = defaultdict(list)
reachable_from_direct = defaultdict(list)
reachable_from_start = [False] * N
reachable_to_end = [False] * N
reachable_from_start[vertex_start] = True
reachable_to_end[vertex_end] = True
reachable_from_both_sides = [False] * N
dfs_from_start = []
dfs_to_end = []
for a, b, c in ABC:
reachable_to_direct[a].append(b)
reachable_from_direct[b].append(a)
if a == vertex_start:
dfs_from_start.append(b)
reachable_from_start[b] = True
if b == vertex_end:
dfs_to_end.append(a)
reachable_to_end[a] = True
while dfs_from_start:
v = dfs_from_start.pop()
for i in reachable_to_direct[v]:
if not reachable_from_start[i]:
reachable_from_start[i] = True
dfs_from_start.append(i)
while dfs_to_end:
v = dfs_to_end.pop()
for i in reachable_from_direct[v]:
if not reachable_to_end[i]:
reachable_to_end[i] = True
dfs_to_end.append(i)
for i in range(N):
reachable_from_both_sides[i] = reachable_from_start[i] and reachable_to_end[i]
return reachable_from_both_sides
reachable_from_both_sides = make_reachable_list(N, M, ABC, vertex_start, vertex_end)
if find_shortest:
dist = [INF for i in range(N)]
else:
dist = [-INF for i in range(N)]
dist[vertex_start] = 0
for i in range(N):
updated = False
for a, b, c in ABC:
if not reachable_from_both_sides[a]:
continue
elif find_shortest:
update_condition = dist[a] + c < dist[b]
else:
update_condition = dist[a] + c > dist[b]
if dist[a] != INF and update_condition:
dist[b] = dist[a] + c
updated = True
if i == N-1:
return value_if_inf
if not updated:
break
return dist[vertex_end]
""" initialize variables and set inputs
# initialize variables
# to initialize list, use [0] * n
# to initialize two dimentional array:
# ex) [[0] * N for _ in range(N)]
# ex2) dp = [[0] * (N+1) for _ in range(W*2)]
# set inputs
# put inputs between specific values (almost as quickly)
# ex) S = [-INF] + [int(r()) for _ in range(A)] + [INF]
# open(0).read() is sometimes useful:
# ex) n, m, *x = map(int, open(0).read().split())
# min(x[::2]) - max(x[1::2])
# ex2) *x, = map(int, open(0).read().split())
# don't forget to add comma after *x if only one variable is used
# preprocessing
# transpose = [x for x in zip(*data)]
# ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
# flat = [flatten for inner in data for flatten in inner]
# ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [1, 2, 3, 4, 5, 6, 7, 8, 9]
# calculate and output
# output pattern
# ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6
"""
# functions to read input
r = lambda: sys.stdin.readline().strip()
r_int = lambda: int(r())
r_float = lambda: float(r())
R = lambda: list(map(int, r().split()))
R_map = lambda: map(int, r().split())
R_float = lambda: list(map(float, r().split()))
R_tuple = lambda: tuple(map(int, r().split()))
""" how to treat input
# single int: int(r())
# single string: r()
# single float: float(r())
# line int: R()
# line string: r().split()
# line (str, int, int): [j if i == 0 else int(j) for i, j in enumerate(r().split())]
# lines int: [R() for _ in range(n)]
"""
# for test
if sample_file:
sys.stdin = open(sample_file)
# ----------------------------------
# main
from operator import sub
H, W = R()
A = [R() for _ in range(H)]
B = [R() for _ in range(H)]
AB = [list(map(lambda m, n: abs(m-n), a, b)) for (a, b) in zip(A, B)]
dp = [[[0]*6401 for w in range(W+1)] for h in range(H+1)]
dp[0][0][0] = 1
for h in range(H):
for w in range(W):
ab = AB[h][w]
for i in range(3201):
# 6400?
if dp[h][w][i] == 1:
dp[h+1][w][i+ab] = 1
dp[h+1][w][abs(i-ab)] = 1
dp[h][w+1][i+ab] = 1
dp[h][w+1][abs(i-ab)] = 1
for i in range(100):
if dp[H-1][W][i] == 1:
print(i)
return
# to finish code, use return instead of exit()
# end of main
# ----------------------------------
"""memo: how to use defaultdict of list
# initialize
Dic = defaultdict(list)
# append / extend
Dic[x].append(y)
# three methods for loop: keys(), values(), items()
for k, v in Dic.items():
"""
"""memo: how to solve binary problems
# to make binary digits text
>>> a = 5
>>> bin_str_a = format(a, '#06b')
>>> print(bin_str_a)
0b0101 # first 2 strings (='0b') indicates it is binary
"""
"""memo: how to solve the problem
creating simple test/answer
greed
simple dp
graph
"""
if __name__ == '__main__':
main() | def main(sample_file = ''):
""" convenient functions
# for i, a in enumerate(iterable)
# q, mod = divmod(a, b)
# divmod(x, y) returns the tuple (x//y, x%y)
# Higher-order function: reduce(operator.mul, xyz_count, 1)
# manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
"""
"""convenient decorator
# @functools.lru_cache():
# to facilitate use of recursive function
# ex:
# from functools import lru_cache
# import sys
# sys.setrecursionlimit(10**9)
# @lru_cache(maxsize=None)
# def fib(n):
# if n < 2:
# return n
# return fib(n-1) + fib(n-2)
# print(fib(1000))
"""
# import numpy as np
import sys
sys.setrecursionlimit(10**7)
from itertools import accumulate, combinations, permutations, product # https://docs.python.org/ja/3/library/itertools.html
# accumulate() returns iterator! to get list: list(accumulate())
from math import factorial, ceil, floor, sqrt
def factorize(n):
"""return the factors of the Arg and count of each factor
Args:
n (long): number to be resolved into factors
Returns:
list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
"""
fct = [] # prime factor
b, e = 2, 0 # base, exponent
while b * b <= n:
while n % b == 0:
n = n // b
e = e + 1
if e > 0:
fct.append((b, e))
b, e = b + 1, 0
if n > 1:
fct.append((n, 1))
return fct
def combinations_count(n, r):
"""Return the number of selecting r pieces of items from n kinds of items.
Args:
n (long): number
r (long): number
Raises:
Exception: not defined when n or r is negative
Returns:
long: number
"""
# TODO: How should I do when n - r is negative?
if n < 0 or r < 0:
raise Exception('combinations_count(n, r) not defined when n or r is negative')
if n - r < r: r = n - r
if r < 0: return 0
if r == 0: return 1
if r == 1: return n
numerator = [n - r + k + 1 for k in range(r)]
denominator = [k + 1 for k in range(r)]
for p in range(2,r+1):
pivot = denominator[p - 1]
if pivot > 1:
offset = (n - r) % p
for k in range(p-1,r,p):
numerator[k - offset] /= pivot
denominator[k] /= pivot
result = 1
for k in range(r):
if numerator[k] > 1:
result *= int(numerator[k])
return result
def combinations_with_replacement_count(n, r):
"""Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
Args:
n (long): number
r (long): number
Raises:
Exception: not defined when n or r is negative
Returns:
long: number
"""
if n < 0 or r < 0:
raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
elif n == 0:
return 1
else:
return combinations_count(n + r - 1, r)
from bisect import bisect_left, bisect_right
from collections import deque, Counter, defaultdict # https://docs.python.org/ja/3/library/collections.html#collections.deque
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
import operator
from operator import itemgetter #sort
# ex1: List.sort(key=itemgetter(1))
# ex2: sorted(tuples, key=itemgetter(1,2))
from functools import reduce, lru_cache
def chmin(x, y):
"""change minimum
if x > y, x = y and return (x, True).
convenient when solving problems of dp[i]
Args:
x (long): current minimum value
y (long): potential minimum value
Returns:
(x, bool): (x, True) when updated, else (x, False)
"""
if x > y:
x = y
return (x, True)
else:
return (x, False)
def chmax(x, y):
"""change maximum
if x < y, x = y and return (x, True).
convenient when solving problems of dp[i]
Args:
x (long): current maximum value
y (long): potential maximum value
Returns:
(x, bool): (x, True) when updated, else (x, False)
"""
if x < y:
x = y
return (x, True)
else:
return (x, False)
from math import gcd # Deprecated since version 3.5: Use math.gcd() instead.
def gcds(numbers):
return reduce(gcd, numbers)
def lcm(x, y):
return (x * y) // gcd(x, y)
def lcms(numbers):
return reduce(lcm, numbers, 1)
def make_divisors(n, reversed=False):
"""create list of divisors
Args:
number (int): number from which list of divisors is created
reversed (bool, optional): ascending order if False. Defaults to False.
Returns:
list: list of divisors
"""
divisors = set()
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.add(i)
divisors.add(n//i)
return sorted(list(divisors),reverse=reversed)
# first create factorial_list
# fac_list = mod_factorial_list(n)
INF = 10 ** 18
MOD = 10 ** 9 + 7
modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow!
def modinv(a, p = MOD):
# evaluate reciprocal using Fermat's little theorem:
# a**(p-1) is identical to 1 (mod p) when a and p is coprime
return modpow(a, p-2, p)
def modinv_list(n, p = MOD):
if n <= 1:
return [0,1][:n+1]
else:
inv_t = [0,1]
for i in range(2, n+1):
inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
return inv_t
def modfactorial_list(n, p = MOD):
if n == 0:
return [1]
else:
l = [0] * (n+1)
tmp = 1
for i in range(1, n+1):
tmp = tmp * i % p
l[i] = tmp
return l
def modcomb(n, k, fac_list = [], p = MOD):
# fac_list = modfactorial_list(100)
# print(modcomb(100, 5, modfactorial_list(100)))
from math import factorial
if n < 0 or k < 0 or n < k: return 0
if n == 0 or k == 0: return 1
if len(fac_list) <= n:
a = factorial(n) % p
b = factorial(k) % p
c = factorial(n-k) % p
else:
a = fac_list[n]
b = fac_list[k]
c = fac_list[n-k]
return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
def modadd(a, b, p = MOD):
return (a + b) % MOD
def modsub(a, b, p = MOD):
return (a - b) % p
def modmul(a, b, p = MOD):
return ((a % p) * (b % p)) % p
def moddiv(a, b, p = MOD):
return modmul(a, modpow(b, p-2, p))
class UnionFindTree:
"""union find tree class
TODO: fix this description...
how to use (example):
>> uf = UnionFindTree(N)
>> if uf.find_root(a) == uf.find_root(b):
>> do something
>> else:
>> do something
>> uf.unite(a, b)
"""
def __init__(self, N):
self.root = [-1] * (N+1)
self.rank = [0] * (N+1)
self.connected_num = [1] * (N+1)
def find_root(self,x):
root = self.root
while root[x] != -1:
x = root[x]
return x
def unite(self,x,y):
root = self.root
rank = self.rank
connected_num = self.connected_num
find_root = self.find_root
rx = find_root(x)
ry = find_root(y)
if rx != ry:
if rank[rx] < rank[ry]:
root[rx] = ry
rx,ry = ry,rx
else:
if rank[rx] == rank[ry]:
rank[rx] += 1
root[ry] = rx
connected_num[rx] += connected_num[ry]
# Graph: https://en.wikipedia.org/wiki/Directed_graph
# Bellman-Ford: O(|V||E|). Use this if there exists an edge with negative length in the graph
# After N steps, the shortest path has converded if there doesn't exist an cycle of edges with negative
# Watch out: d[N] == d[2*N] doesn't necessarily mean the graph doesn't have negative cycle
# ref: https://www.youtube.com/watch?v=1Z6ofKN03_Y
def BellmanFord(N, M, ABC, vertex_start, vertex_end, value_if_inf = -1, find_shortest = False):
"""to calculate furthest or shortest length between vertex_start and vertex_end using BellmanFord algorithm
Args:
N (int): number of vertices
M (int): number of edges
ABC (list): [(ai, bi, ci) for _ in range(N)] where i-th edge is directed from vertex ai to vertex bi and the length is ci
vertex_start (int): start vertex. usually use 0.
vertex_end (int): end vertex. usually use N-1.
value_if_inf (int or string as you like, optional): value you want when the furthest (or shortest) distance is infinite (or -infinite). Defaults to -1.
find_shortest (bool, optional): choose False to find furthest path. Defaults to False.
Returns:
int or string: normally int (but can be str if you set value_if_inf to str)
Example:
N, M, P = R()
ABC = [R() for _ in range(M)]
ABC = [(a-1, b-1, c-P) for a, b, c in ABC]
print(BellmanFord(N, M, ABC, 0, N-1, value_if_inf = 'inf'))
"""
def make_reachable_list(N, M, ABC, vertex_start, vertex_end):
reachable_to_direct = defaultdict(list)
reachable_from_direct = defaultdict(list)
reachable_from_start = [False] * N
reachable_to_end = [False] * N
reachable_from_start[vertex_start] = True
reachable_to_end[vertex_end] = True
reachable_from_both_sides = [False] * N
dfs_from_start = []
dfs_to_end = []
for a, b, c in ABC:
reachable_to_direct[a].append(b)
reachable_from_direct[b].append(a)
if a == vertex_start:
dfs_from_start.append(b)
reachable_from_start[b] = True
if b == vertex_end:
dfs_to_end.append(a)
reachable_to_end[a] = True
while dfs_from_start:
v = dfs_from_start.pop()
for i in reachable_to_direct[v]:
if not reachable_from_start[i]:
reachable_from_start[i] = True
dfs_from_start.append(i)
while dfs_to_end:
v = dfs_to_end.pop()
for i in reachable_from_direct[v]:
if not reachable_to_end[i]:
reachable_to_end[i] = True
dfs_to_end.append(i)
for i in range(N):
reachable_from_both_sides[i] = reachable_from_start[i] and reachable_to_end[i]
return reachable_from_both_sides
reachable_from_both_sides = make_reachable_list(N, M, ABC, vertex_start, vertex_end)
if find_shortest:
dist = [INF for i in range(N)]
else:
dist = [-INF for i in range(N)]
dist[vertex_start] = 0
for i in range(N):
updated = False
for a, b, c in ABC:
if not reachable_from_both_sides[a]:
continue
elif find_shortest:
update_condition = dist[a] + c < dist[b]
else:
update_condition = dist[a] + c > dist[b]
if dist[a] != INF and update_condition:
dist[b] = dist[a] + c
updated = True
if i == N-1:
return value_if_inf
if not updated:
break
return dist[vertex_end]
""" initialize variables and set inputs
# initialize variables
# to initialize list, use [0] * n
# to initialize two dimentional array:
# ex) [[0] * N for _ in range(N)]
# ex2) dp = [[0] * (N+1) for _ in range(W*2)]
# set inputs
# put inputs between specific values (almost as quickly)
# ex) S = [-INF] + [int(r()) for _ in range(A)] + [INF]
# open(0).read() is sometimes useful:
# ex) n, m, *x = map(int, open(0).read().split())
# min(x[::2]) - max(x[1::2])
# ex2) *x, = map(int, open(0).read().split())
# don't forget to add comma after *x if only one variable is used
# preprocessing
# transpose = [x for x in zip(*data)]
# ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
# flat = [flatten for inner in data for flatten in inner]
# ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [1, 2, 3, 4, 5, 6, 7, 8, 9]
# calculate and output
# output pattern
# ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6
"""
# functions to read input
r = lambda: sys.stdin.readline().strip()
r_int = lambda: int(r())
r_float = lambda: float(r())
R = lambda: list(map(int, r().split()))
R_map = lambda: map(int, r().split())
R_float = lambda: list(map(float, r().split()))
R_tuple = lambda: tuple(map(int, r().split()))
""" how to treat input
# single int: int(r())
# single string: r()
# single float: float(r())
# line int: R()
# line string: r().split()
# line (str, int, int): [j if i == 0 else int(j) for i, j in enumerate(r().split())]
# lines int: [R() for _ in range(n)]
"""
# for test
if sample_file:
sys.stdin = open(sample_file)
# ----------------------------------
# main
from operator import sub
H, W = R()
A = [R() for _ in range(H)]
B = [R() for _ in range(H)]
AB = [list(map(lambda m, n: abs(m-n), a, b)) for (a, b) in zip(A, B)]
dp = [[[0]*12403 for w in range(W+1)] for h in range(H+1)]
dp[0][0][0] = 1
for h in range(H):
for w in range(W):
ab = AB[h][w]
for i in range(6401):
# 6400?
if dp[h][w][i] == 1:
dp[h+1][w][i+ab] = 1
dp[h+1][w][abs(i-ab)] = 1
dp[h][w+1][i+ab] = 1
dp[h][w+1][abs(i-ab)] = 1
for i in range(1000):
if dp[H-1][W][i] == 1:
print(i)
return
# to finish code, use return instead of exit()
# end of main
# ----------------------------------
"""memo: how to use defaultdict of list
# initialize
Dic = defaultdict(list)
# append / extend
Dic[x].append(y)
# three methods for loop: keys(), values(), items()
for k, v in Dic.items():
"""
"""memo: how to solve binary problems
# to make binary digits text
>>> a = 5
>>> bin_str_a = format(a, '#06b')
>>> print(bin_str_a)
0b0101 # first 2 strings (='0b') indicates it is binary
"""
"""memo: how to solve the problem
creating simple test/answer
greed
simple dp
graph
"""
if __name__ == '__main__':
main()
| [
"literal.number.integer.change",
"assignment.value.change",
"expression.operation.binary.change",
"call.arguments.change",
"control_flow.loop.range.bounds.upper.change"
] | 646,836 | 646,829 | u988402778 | python |
p02842 | n = int(input())
import math
for i in range(50000):
if math.floor(i*1.08) == n:
print(i)
exit()
ptiny(":(") | n = int(input())
import math
for i in range(50000):
if math.floor(i*1.08) == n:
print(i)
exit()
print(":(") | [
"identifier.change",
"call.function.change"
] | 646,955 | 646,956 | u289547799 | python |
p02842 | import math
n=int(input())
num=round(n/1.08)
if math.floor(num*1.08)==n:
print(num)
else:
print(":(")
| import math
n=int(input())
num=math.ceil(n/1.08)
if math.floor(num*1.08)==n:
print(num)
else:
print(":(")
| [
"assignment.value.change"
] | 646,961 | 646,962 | u999503965 | python |
p02842 | import math
price = int(input())
tax = 8
price_1 = math.ceil(price / (1 + tax / 100))
price_2 = math.floor(price * tax / 100)
print(price_1 if price == price_1 + price2 else ':(') | import math
price = int(input())
tax = 8
price_1 = math.ceil(price / (1 + tax / 100))
price_2 = math.floor(price_1 * tax / 100)
print(price_1 if price == price_1 + price_2 else ':(') | [
"assignment.value.change",
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 646,977 | 646,978 | u706659319 | python |
p02842 | n=int(input())
ans=0
for i in range(1,50000+1):
z=i*1.08
if n<=z<(n+1):
ans=z
break
if ans==0:
print(":(")
else:
print(ans)
| n=int(input())
ans=0
for i in range(1,50000+1):
z=i*1.08
if n<=z<(n+1):
ans=i
break
if ans==0:
print(":(")
else:
print(ans)
| [
"assignment.value.change",
"identifier.change"
] | 646,995 | 646,996 | u723583932 | python |
p02842 | import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def solve():
f = math.ceil(m/1.08)
if math.floor(f*1.08)==n:
print(f)
else:
print(':(')
return
if __name__=='__main__':
n = I()
solve() | import sys
from collections import deque
import numpy as np
import math
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def solve():
f = math.ceil(n/1.08)
if math.floor(f*1.08)==n:
print(f)
else:
print(':(')
return
if __name__=='__main__':
n = I()
solve() | [
"assignment.value.change",
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 647,004 | 647,005 | u844895214 | python |
p02842 | import math
a = int(input())
for i in range(a):
if math.floor(i*1.08) == a:
print(i)
exit()
print(":(") | import math
a = int(input())
for i in range(50001):
if math.floor(i*1.08) == a:
print(i)
exit()
print(":(") | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"control_flow.loop.range.bounds.upper.change"
] | 647,006 | 647,007 | u717762991 | python |
p02842 | import math
N=int(input())
X=N/1.08
X=math.ceil(X)
if X*1.08==N:
print(X)
else:
print(":(") | import math
N=int(input())
X=N/1.08
X=math.ceil(X)
if math.floor(X*1.08)==N:
print(X)
else:
print(":(") | [
"control_flow.branch.if.condition.change",
"call.add"
] | 647,015 | 647,016 | u536017058 | python |
p02842 | import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N = int(input())
for x in range(N):
val = x * 108
val -= val % 100
if val == N * 100:
print(x)
exit()
print(":(")
| import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
N = int(input())
for x in range(1, N + 1):
val = x * 108
val -= val % 100
if val == N * 100:
print(x)
exit()
print(":(")
| [
"call.arguments.add"
] | 647,026 | 647,027 | u036104576 | python |
p02842 | import math
def solve():
N = int(input())
if round(math.ceil(N / 1.08) * 1.08) == N:
print(math.ceil(N / 1.08))
else:
print(':(')
if __name__ == "__main__":
solve() | import math
def solve():
N = int(input())
if math.floor(math.ceil(N / 1.08) * 1.08) == N:
print(math.ceil(N / 1.08))
else:
print(':(')
if __name__ == "__main__":
solve() | [
"control_flow.branch.if.condition.change"
] | 647,032 | 647,033 | u373442126 | python |
p02842 | import math
def solve():
N = int(input())
if math.floor(round(N / 1.08) * 1.08) == N:
print(round(N / 1.08))
else:
print(':(')
if __name__ == "__main__":
solve() | import math
def solve():
N = int(input())
if math.floor(math.ceil(N / 1.08) * 1.08) == N:
print(math.ceil(N / 1.08))
else:
print(':(')
if __name__ == "__main__":
solve() | [
"control_flow.branch.if.condition.change",
"call.arguments.change",
"io.output.change"
] | 647,034 | 647,033 | u373442126 | python |
p02842 | import math
n=int(input())
x=math.ceil(n/1.08)
nn=n*1.08
if math.floor(nn)==n:
print(x)
else:
print(":(")
| import math
n=int(input())
xc=math.ceil(n/1.08)
nn=xc*1.08
if math.floor(nn)==n:
print(xc)
else:
print(":(")
| [
"assignment.variable.change",
"identifier.change",
"assignment.value.change",
"expression.operation.binary.change",
"call.arguments.change",
"io.output.change"
] | 647,042 | 647,043 | u368270116 | python |
p02842 | def main2():
n = int(input())
x = int(math.ceil(n / 1.08))
if int(x*1.08) == n:
print(x)
else:
print(":(")
if __name__ == "__main__":
main2() | import math
def main2():
n = int(input())
x = int(math.ceil(n / 1.08))
if int(x*1.08) == n:
print(x)
else:
print(":(")
if __name__ == "__main__":
main2() | [] | 647,047 | 647,048 | u835283937 | python |
p02842 | N = int(input())
flag = True
for i in range(N):
if int(i * 1.08) == N:
print(i)
flag = False
break
if flag:
print(":(")
| N = int(input())
flag = True
for i in range(100000):
if int(i * 1.08) == N:
print(i)
flag = False
break
if flag:
print(":(")
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"control_flow.loop.range.bounds.upper.change"
] | 647,051 | 647,050 | u720558413 | python |
p02842 | n = int(input())
found = False
for i in range(n):
x = int ( i * 1.08 )
if x == n :
print(i)
found = True
break
if not found:
print(":(") | n = int(input())
found = False
for i in range(1, n + 1):
x = int ( i * 1.08 )
if x == n :
print(i)
found = True
break
if not found:
print(":(") | [
"call.arguments.add"
] | 647,052 | 647,053 | u035742291 | python |
p02842 | n=int(input())
for m in range(1,n):
if int(m*1.08)==n:
print(m)
break
else:print(":(") | n=int(input())
for m in range(1,n+1):
if int(m*1.08)==n:
print(m)
break
else:print(":(")
| [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add"
] | 647,060 | 647,061 | u123745130 | python |
p02842 | import numpy
N = int(input())
X0 = N / 1.08
X1 = (N + 1) / 1.08
if numpy.floor(X1) - numpy.floor(X0) == 0:
print(':(')
else:
print(int(numpy.floor(X0) + 1)) | import numpy
N = int(input())
X0 = N / 1.08
X1 = (N + 1) / 1.08
if numpy.ceil(X1) - numpy.ceil(X0) == 0:
print(':(')
else:
print(int(numpy.ceil(X0))) | [
"misc.opposites",
"identifier.change",
"control_flow.branch.if.condition.change",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 647,077 | 647,078 | u169165784 | python |
p02842 | ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
from math import floor
n=ni()
for i in range(n):
if floor(i*1.08)==n:
print(i)
exit()
print(':(')
| ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
from math import floor
n=ni()
for i in range(n+1):
if floor(i*1.08)==n:
print(i)
exit()
print(':(')
| [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add"
] | 647,087 | 647,088 | u963915126 | python |
p02842 | import math
N = int(input())
flag = True
for i in range(N):
if math.floor(i * 1.08) == N:
print(i)
flag = False
break
if flag:
print(':(') | import math
N = int(input())
flag = True
for i in range(N+1):
if math.floor(i * 1.08) == N:
print(i)
flag = False
break
if flag:
print(':(') | [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add"
] | 647,089 | 647,090 | u789290859 | python |
p02842 | N = int(input())
a = int(N / 2)
x = 0
for i in range(a - 1, N):
if N == int(i * 1.08):
print(i)
x += 1
if x == 0:
print(':(') | N = int(input())
a = int(N / 10)
x = 0
for i in range(a,N + 1):
if N == int(i * 1.08):
print(i)
x += 1
if x == 0:
print(':(') | [
"literal.number.integer.change",
"assignment.value.change",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 647,091 | 647,092 | u569776981 | python |
p02842 | import math
n=int(input())
for i in range(n):
if math.floor(i*1.08)==n:
print(i)
break
elif i*1.08>n:
print(":(")
break
| import math
n=int(input())
for i in range(1,n+1):
if math.floor(i*1.08)==n:
print(i)
break
elif i*1.08>n:
print(":(")
break
| [
"call.arguments.add"
] | 647,097 | 647,098 | u206541745 | python |
p02842 | n = int(input())
for x in range(1, 50005):
if x * 1.08 == n:
print(x)
exit()
else:
print(':(') | n = int(input())
for x in range(1, 50005):
if x * 108//100 == n:
print(x)
exit()
else:
print(':(') | [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change"
] | 647,114 | 647,115 | u960080897 | python |
p02842 | import math
N = int(input())
for i in range(1,N):
if math.floor(i*1.08) == N:
print(i)
break
else:
print(":(") | import math
N = int(input())
for i in range(1,N+1):
if math.floor(i*1.08) == N:
print(i)
break
else:
print(":(") | [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add"
] | 647,116 | 647,117 | u397384480 | python |
p02842 | n=int(input())
ans=':('
for i in range(1,n):
if int((i*1.08)//1)==n:
ans=i
break
print(ans)
| n=int(input())
ans=':('
for i in range(1,n+1):
if int((i*1.08)//1)==n:
ans=i
break
print(ans)
| [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add"
] | 647,130 | 647,131 | u350093546 | python |
p02842 | import math
N = int(input())
X = 0
a = 0
for i in range(N):
X = math.floor(1.08*i)
if(X==N):
print(i)
a+=1
break
if(a ==0):
print(":(") | import math
N = int(input())
X = 0
a = 0
for i in range(50000):
X = math.floor(1.08*i)
if(X==N):
print(i)
a+=1
break
if(a ==0):
print(":(") | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"control_flow.loop.range.bounds.upper.change"
] | 647,135 | 647,136 | u696684809 | python |
p02842 | N = int(input())
X = 0
a = 0
for i in range(N):
X = int(1.08*i)
if(X==N):
print(i)
a+=1
break
if(a ==0):
print(":(") | import math
N = int(input())
X = 0
a = 0
for i in range(50000):
X = math.floor(1.08*i)
if(X==N):
print(i)
a+=1
break
if(a ==0):
print(":(") | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"control_flow.loop.range.bounds.upper.change",
"assignment.value.change"
] | 647,137 | 647,136 | u696684809 | python |
p02842 | N = int(input())
for i in range(1, N):
if i + (i * 8) // 100 == N:
print(i)
break
else:
print(":(") | N = int(input())
for i in range(1, N + 1):
if i + (i * 8) // 100 == N:
print(i)
break
else:
print(":(") | [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add"
] | 647,159 | 647,160 | u422242927 | python |
p02842 | N = int(input())
for i in range(1, N):
if i + (i * 8) // 100 == N:
print(i)
else:
print(":(")
| N = int(input())
for i in range(1, N + 1):
if i + (i * 8) // 100 == N:
print(i)
break
else:
print(":(") | [
"control_flow.break.add"
] | 647,161 | 647,160 | u422242927 | python |
p02842 | N = int(input())
for i in range(1, N):
if i + i * 8 // 100 == N:
print(i)
else:
print(":(")
| N = int(input())
for i in range(1, N + 1):
if i + (i * 8) // 100 == N:
print(i)
break
else:
print(":(") | [
"control_flow.branch.if.condition.change",
"control_flow.break.add"
] | 647,162 | 647,160 | u422242927 | python |
p02842 | n = int(input())
dic = {}
for i in range(1,50000):
dic[int(i * 1.08)] = i
print(dic)
if n in dic:
print(dic[n])
else:
print(':(') | n = int(input())
dic = {}
for i in range(1,50000):
dic[int(i * 1.08)] = i
if n in dic:
print(dic[n])
else:
print(':(') | [
"call.remove"
] | 647,163 | 647,164 | u212328220 | python |
p02842 | n=int(input())
num=round(n/1.08)
check=round(num*1.08)
if check==n:
print(num)
else:
print(':(') | import math
n=int(input())
num=math.ceil(n/1.08)
check=int(num*1.08)
if check==n:
print(num)
else:
print(':(') | [
"assignment.value.change",
"identifier.change",
"call.function.change"
] | 647,188 | 647,189 | u113107956 | python |
p02842 | n=int(input())
num=round(n/1.08)
check=int(num*1.08)
if check==n:
print(num)
else:
print(':(') | import math
n=int(input())
num=math.ceil(n/1.08)
check=int(num*1.08)
if check==n:
print(num)
else:
print(':(') | [
"assignment.value.change"
] | 647,190 | 647,189 | u113107956 | python |
p02842 | n = int(input())
for i in range(n):
if int(i * 1.08) == n:
print(i)
exit()
print(":(") | n = int(input())
for i in range(50001):
if int(i * 1.08) == n:
print(i)
exit()
print(":(") | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"control_flow.loop.range.bounds.upper.change"
] | 647,191 | 647,192 | u624613992 | python |
p02842 | n = int(input())
for i in range(n):
if i * 1.08 == n:
print(i)
exit()
print(":(") | n = int(input())
for i in range(50001):
if int(i * 1.08) == n:
print(i)
exit()
print(":(") | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"control_flow.loop.range.bounds.upper.change",
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"call.add"
] | 647,193 | 647,192 | u624613992 | python |
p02842 | n = int(input())
import math
a = n*100/108
b = (n*100+100)/108
ans = math.ceil(a) if math.ceil(a) != b else ":("
print(ans) | n = int(input())
import math
a = n*100/108
b = (n*100+100)/108
ans = math.ceil(a) if math.ceil(a) < b else ":("
print(ans) | [
"expression.operator.compare.change",
"assignment.value.change"
] | 647,198 | 647,199 | u555458045 | python |
p02842 | def readinput():
n=int(input())
return n
def main(n):
x7=int(n/1.07)
x8=int(n/1.08)
x9=int(n/1.09)
n100=n*100
for x in range(max(1,x9-1),x7+1):
xx=x*108//100
if xx==n:
print(x)
break
else:
print(':(')
if __name__=='__main__':
n=readinput()
main(n)
| def readinput():
n=int(input())
return n
def main(n):
x7=int(n/1.07)
x8=int(n/1.08)
x9=int(n/1.09)
n100=n*100
for x in range(max(1,x9-1),x7+1+1):
xx=x*108//100
#print(x,xx)
if xx==n:
print(x)
break
else:
print(':(')
if __name__=='__main__':
n=readinput()
main(n)
| [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add"
] | 647,208 | 647,209 | u592547545 | python |
p02842 | def readinput():
n=int(input())
return n
def main(n):
x7=int(n/1.07)
x8=int(n/1.08)
x9=int(n/1.09)
n100=n*100
for x in range(max(1,x9-1),x7+1):
xx=x*108
if xx==n100:
print(x)
break
else:
print(':(')
if __name__=='__main__':
n=readinput()
main(n)
| def readinput():
n=int(input())
return n
def main(n):
x7=int(n/1.07)
x8=int(n/1.08)
x9=int(n/1.09)
n100=n*100
for x in range(max(1,x9-1),x7+1+1):
xx=x*108//100
#print(x,xx)
if xx==n:
print(x)
break
else:
print(':(')
if __name__=='__main__':
n=readinput()
main(n)
| [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 647,210 | 647,209 | u592547545 | python |
p02842 | N = int(input())
for x in range(N):
if int(x*1.08) == N:
print(x)
break
else:
print(':(') | N = int(input())
for x in range(N+1):
if int(x*1.08) == N:
print(x)
break
else:
print(':(') | [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add"
] | 647,211 | 647,212 | u555767343 | python |
p02842 | def main():
N = int(input())
for i in range(N):
ans = i * 108 // 100
if ans == N:
print(i)
return
print(':(')
main() | def main():
N = int(input())
for i in range(N + 1):
ans = i * 108
ans = ans // 100
if ans == N:
print(i)
return
print(':(')
main() | [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add",
"assignment.add"
] | 647,215 | 647,216 | u033642300 | python |
p02842 | def resolve():
import math
N = int(input())
for i in range(N):
if math.floor(i*1.08) == N:
print(i)
exit()
print(":(")
resolve() | def resolve():
import math
N = int(input())
for i in range(N+1):
if math.floor(i*1.08) == N:
print(i)
exit()
print(":(")
resolve() | [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add"
] | 647,219 | 647,220 | u600261652 | python |
p02842 | import numpy as np
N = int(input())
X = int(np.round(N/1.08))
if np.floor(X*1.08)!=N:
X = ':('
print(X) | import numpy as np
N = int(input())
X = int(np.ceil(N/1.08))
if np.floor(X*1.08)!=N:
X = ':('
print(X) | [
"assignment.value.change",
"identifier.change",
"call.arguments.change"
] | 647,229 | 647,230 | u232873434 | python |
p02842 | from math import floor
def main(N, rate=1.08):
ans = -1
for x in range(1, N+1):
if floor(x * 1.08) == N:
ans = x
return ans
if __name__ == "__main__":
N = int(input())
ans = main(N)
print(ans if ans > 0 else ':)')
| from math import floor
def main(N, rate=1.08):
ans = -1
for x in range(1, N+1):
if floor(x * 1.08) == N:
ans = x
return ans
if __name__ == "__main__":
N = int(input())
ans = main(N)
print(ans if ans > 0 else ':(')
| [
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 647,235 | 647,236 | u142415823 | python |
p02842 | # template by 3xC and starkizard.
# contributors:
#####################################################################################
from __future__ import division, print_function
import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io
"""Uncomment modules according to your need"""
# from bisect import bisect_left, bisect_right, insort
# from heapq import heappop, heapify, heappush
# from random import randint as rn
# from Queue import Queue as Q
# from copy import deepcopy
# from decimal import *
# import re
# import operator
#####################################################################################
# this enables you to write python3 code with PyPy2 (Python 2)
if sys.version_info[0] < 3:
input = raw_input
range = xrange
filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip
#####################################################################################
"""value of mod"""
MOD = 998244353
mod = 10**9 + 7
"""Uncomment next 4 lines if doing huge recursion"""
# import threading
# threading.stack_size(1<<27)
# sys.setrecursionlimit(10000
def prepare_factorial(mod=mod):
""" returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
# Comment code out when you don't need inverse factorial or vice versa
fact = [1]
for i in range(1, 200005):
fact.append((fact[-1] * i) % mod)
ifact = [0] * 200005
ifact[200004] = pow(fact[200004], mod - 2, mod)
for i in range(200004, 0, -1):
ifact[i - 1] = (i * ifact[i]) % mod
return fact, ifact
def modinv(n, p):
""" returns N inverse modulo p """
return pow(n, p - 2, p)
def ncr(n, r, fact, ifact):
""" takes 4 arguments: n , r and factorial and inverse factorial lists"""
t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
return t
def get_n(Sum):
"""this function returns the maximum n for which Summation(n) <= Sum"""
ans = (-1 + sqrt(1 + 8*Sum))//2
return ans
def sieve(n):
""" returns a list of prime numbers till n """
if n < 2: return list()
prime = [True for _ in range(n + 1)]
p = 3
while p * p <= n:
if prime[p]:
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 2
r = [2]
for p in range(3, n + 1, 2):
if prime[p]:
r.append(p)
return r
def divs(n, start=1):
""" returns a list of all divisors till n """
divisors = []
for i in range(start, int(math.sqrt(n) + 1)):
if n % i == 0:
if n / i == i:
divisors.append(i)
else:
divisors.extend([i, n // i])
return divisors
def divn(n, primes):
""" returns the number of divisors, two arguments n and the sieve till n """
divs_number = 1
for i in primes:
if n == 1:
return divs_number
t = 1
while n % i == 0:
t += 1
n //= i
divs_number *= t
def lrfind(d, x, default=-1):
""" Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
left = right = -1
for i in range(len(d)):
if d[i] == x:
if left == -1: left = i
right = i
if left == -1:
return default, default
else:
return left, right
def gcd(x, y): # math.gcd is slower
""" returns greatest common divisor of x and y """
while y:
x, y = y, x % y
return x
def ceil(n, k=1): return n // k + (n % k != 0) #returns math.ceil but protecting against floating inconsistencies
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) #inputs integer
def mi(): return map(int, input().split()) # inputting space seperated variables for example x,y,z
def li(): return list(map(int, input().split())) #inputting a space seperated list of integers
def lw(): return input().split() #inputting a space seperated list of strings
def lcm(a, b): return abs(a * b) // gcd(a, b) #returns LCM of two arguments
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) #For printing an iterable with seperator sep as optional second argument (default : " "), ending character (default: "\n") as optional third
def dd(): return defaultdict(int) #returns a dictionary with values defaulted to 0
def ddl(): return defaultdict(list) #returns a dictionary with values defaulted to []
def write(s): return sys.stdout.write(s)
###################################################################
def main():
#CODE GOES HERE:
n=ii()
c=n/1.08
if int(int(c)*1.08)==n:
print(c)
elif int((int(c)+1 )*1.08)==n:
print(c+1)
else:
print(":(")
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""
py2 = round(0.5)
if py2:
from future_builtins import ascii, filter, hex, map, oct, zip
range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192
class FastIO(BytesIO):
newlines = 0
def __init__(self, file):
self._file = file
self._fd = file.fileno()
self.writable = "x" in file.mode or "w" in file.mode
self.write = super(FastIO, self).write if self.writable else None
def _fill(self):
s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
return s
def read(self):
while self._fill(): pass
return super(FastIO, self).read()
def readline(self):
while self.newlines == 0:
s = self._fill();
self.newlines = s.count(b"\n") + (not s)
self.newlines -= 1
return super(FastIO, self).readline()
def flush(self):
if self.writable:
os.write(self._fd, self.getvalue())
self.truncate(0), self.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
if py2:
self.write = self.buffer.write
self.read = self.buffer.read
self.readline = self.buffer.readline
else:
self.write = lambda s: self.buffer.write(s.encode('ascii'))
self.read = lambda: self.buffer.read().decode('ascii')
self.readline = lambda: self.buffer.readline().decode('ascii')
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
""" main function"""
if __name__ == '__main__':
main()
# threading.Thread(target=main).start()
| # template by 3xC and starkizard.
# contributors:
#####################################################################################
from __future__ import division, print_function
import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io
"""Uncomment modules according to your need"""
# from bisect import bisect_left, bisect_right, insort
# from heapq import heappop, heapify, heappush
# from random import randint as rn
# from Queue import Queue as Q
# from copy import deepcopy
# from decimal import *
# import re
# import operator
#####################################################################################
# this enables you to write python3 code with PyPy2 (Python 2)
if sys.version_info[0] < 3:
input = raw_input
range = xrange
filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip
#####################################################################################
"""value of mod"""
MOD = 998244353
mod = 10**9 + 7
"""Uncomment next 4 lines if doing huge recursion"""
# import threading
# threading.stack_size(1<<27)
# sys.setrecursionlimit(10000
def prepare_factorial(mod=mod):
""" returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
# Comment code out when you don't need inverse factorial or vice versa
fact = [1]
for i in range(1, 200005):
fact.append((fact[-1] * i) % mod)
ifact = [0] * 200005
ifact[200004] = pow(fact[200004], mod - 2, mod)
for i in range(200004, 0, -1):
ifact[i - 1] = (i * ifact[i]) % mod
return fact, ifact
def modinv(n, p):
""" returns N inverse modulo p """
return pow(n, p - 2, p)
def ncr(n, r, fact, ifact):
""" takes 4 arguments: n , r and factorial and inverse factorial lists"""
t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
return t
def get_n(Sum):
"""this function returns the maximum n for which Summation(n) <= Sum"""
ans = (-1 + sqrt(1 + 8*Sum))//2
return ans
def sieve(n):
""" returns a list of prime numbers till n """
if n < 2: return list()
prime = [True for _ in range(n + 1)]
p = 3
while p * p <= n:
if prime[p]:
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 2
r = [2]
for p in range(3, n + 1, 2):
if prime[p]:
r.append(p)
return r
def divs(n, start=1):
""" returns a list of all divisors till n """
divisors = []
for i in range(start, int(math.sqrt(n) + 1)):
if n % i == 0:
if n / i == i:
divisors.append(i)
else:
divisors.extend([i, n // i])
return divisors
def divn(n, primes):
""" returns the number of divisors, two arguments n and the sieve till n """
divs_number = 1
for i in primes:
if n == 1:
return divs_number
t = 1
while n % i == 0:
t += 1
n //= i
divs_number *= t
def lrfind(d, x, default=-1):
""" Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
left = right = -1
for i in range(len(d)):
if d[i] == x:
if left == -1: left = i
right = i
if left == -1:
return default, default
else:
return left, right
def gcd(x, y): # math.gcd is slower
""" returns greatest common divisor of x and y """
while y:
x, y = y, x % y
return x
def ceil(n, k=1): return n // k + (n % k != 0) #returns math.ceil but protecting against floating inconsistencies
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) #inputs integer
def mi(): return map(int, input().split()) # inputting space seperated variables for example x,y,z
def li(): return list(map(int, input().split())) #inputting a space seperated list of integers
def lw(): return input().split() #inputting a space seperated list of strings
def lcm(a, b): return abs(a * b) // gcd(a, b) #returns LCM of two arguments
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) #For printing an iterable with seperator sep as optional second argument (default : " "), ending character (default: "\n") as optional third
def dd(): return defaultdict(int) #returns a dictionary with values defaulted to 0
def ddl(): return defaultdict(list) #returns a dictionary with values defaulted to []
def write(s): return sys.stdout.write(s)
###################################################################
def main():
#CODE GOES HERE:
n=ii()
c=n/1.08
if int(int(c)*1.08)==n:
print(int(c))
elif int((int(c)+1 )*1.08)==n:
print(int(c+1))
else:
print(":(")
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""
py2 = round(0.5)
if py2:
from future_builtins import ascii, filter, hex, map, oct, zip
range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192
class FastIO(BytesIO):
newlines = 0
def __init__(self, file):
self._file = file
self._fd = file.fileno()
self.writable = "x" in file.mode or "w" in file.mode
self.write = super(FastIO, self).write if self.writable else None
def _fill(self):
s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
return s
def read(self):
while self._fill(): pass
return super(FastIO, self).read()
def readline(self):
while self.newlines == 0:
s = self._fill();
self.newlines = s.count(b"\n") + (not s)
self.newlines -= 1
return super(FastIO, self).readline()
def flush(self):
if self.writable:
os.write(self._fd, self.getvalue())
self.truncate(0), self.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
if py2:
self.write = self.buffer.write
self.read = self.buffer.read
self.readline = self.buffer.readline
else:
self.write = lambda s: self.buffer.write(s.encode('ascii'))
self.read = lambda: self.buffer.read().decode('ascii')
self.readline = lambda: self.buffer.readline().decode('ascii')
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
""" main function"""
if __name__ == '__main__':
main()
# threading.Thread(target=main).start()
| [
"call.add",
"call.arguments.change"
] | 647,237 | 647,238 | u436697953 | python |
p02842 | n = int(input())
for i in range(n):
if int(i*1.08) == n:
print(i)
break
else:
print(":(") | n = int(input())
for i in range(1,n+1):
if int(i*1.08) == n:
print(i)
break
else:
print(":(") | [
"call.arguments.add"
] | 647,241 | 647,242 | u496821919 | python |
p02842 | n = int(input())
xmin = int(n/1.08)
xmax = int((n+1)/1.08)
if n%27 == 0:
print(xmax)
elif (n+1)%27 == 0:
print(xmin)
elif xmin == xmax:
print(":(")
else:
print(xmax)
| n = int(input())
xmin = int(n/1.08)
xmax = int((n+1)/1.08)
if n%27 == 0:
print(xmax)
elif (n+1)%27 == 0:
print(":(")
elif xmin == xmax:
print(":(")
else:
print(xmax) | [
"call.arguments.change",
"io.output.change"
] | 647,243 | 647,244 | u492910842 | python |
p02842 | n = int(input())
ans = 0
for i in range(1, N+1):
if int(i * 1.08) == n:
ans = i
if ans == 0:
print(":(")
else:
print(x) | n = int(input())
ans = 0
for i in range(1, n+1):
if int(i * 1.08) == n:
ans = i
if ans == 0:
print(":(")
else:
print(ans) | [
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change",
"control_flow.loop.range.bounds.upper.change",
"io.output.change"
] | 647,250 | 647,251 | u039860745 | python |
p02842 | # sumitb2019_b_bacha.py
N = int(input())
for i in range(N):
if int(i*1.08) == N:
print(i)
exit()
print(":(")
| # sumitb2019_b_bacha.py
N = int(input())
for i in range(50000):
if int(i*1.08) == N:
print(i)
exit()
print(":(")
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"control_flow.loop.range.bounds.upper.change"
] | 647,258 | 647,257 | u371132735 | python |
p02842 | # sumitb2019_b.py
import math
N = int(input())
for i in range(N):
if math.floor(i*1.08) == N:
print(i)
exit()
print(":(") | # sumitb2019_b_bacha.py
N = int(input())
for i in range(50000):
if int(i*1.08) == N:
print(i)
exit()
print(":(")
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"control_flow.loop.range.bounds.upper.change",
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change"
] | 647,259 | 647,257 | u371132735 | python |
p02842 | # sumitb2019_b.py
import math
N = int(input())
for i in range(N):
if math.floor(i*1.08) == N:
print(i)
exit()
print(":(") | # sumitb2019_b.py
import math
N = int(input())
for i in range(50000):
if math.floor(i*1.08) == N:
print(i)
exit()
print(":(") | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"control_flow.loop.range.bounds.upper.change"
] | 647,259 | 647,260 | u371132735 | python |
p02842 | n = int(input())
for i in range(n):
if int((i * 1.08) // 1) == n:
print(i)
exit()
print(":(")
| n = int(input())
for i in range(n+1):
if int((i * 1.08) // 1) == n:
print(i)
exit()
print(":(")
| [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add"
] | 647,261 | 647,262 | u432853936 | python |
p02842 | n = int(input())
for x in range(n):
if x * 1.08 // 1 == n:
print(x)
break
else:
print(':(') | n = int(input())
for x in range(n+1):
if x * 108 // 100 == n:
print(x)
break
else:
print(':(') | [
"control_flow.branch.if.condition.change",
"literal.number.integer.change"
] | 647,263 | 647,264 | u382423941 | python |
p02842 | N = int(input())
X = int(-(-N//1.08))
print(X)
if N == int(X * 1.08):
print(X)
else:
print(':(') | N = int(input())
X = int(-(-N//1.08))
if N == int(X * 1.08):
print(X)
else:
print(':(') | [
"call.remove"
] | 647,271 | 647,272 | u996564551 | python |
p02842 | from decimal import Decimal
N = int(input())
M = round(N/Decimal(1.08))
if N == int(M*Decimal(1.08)) :
print( int(M))
else :
print(':(') | from decimal import Decimal
N = int(input())
M = int(N/Decimal(1.08)) + 1
if N == int(M*Decimal(1.08)) :
print( int(M))
else :
print(':(') | [
"assignment.value.change",
"identifier.change",
"call.function.change"
] | 647,275 | 647,276 | u441246928 | python |
p02842 | from decimal import Decimal
N = int(input())
M = N/Decimal(1.08)
if N == int(M*Decimal(1.08)) :
print( int(M))
else :
print(':(') | from decimal import Decimal
N = int(input())
M = int(N/Decimal(1.08)) + 1
if N == int(M*Decimal(1.08)) :
print( int(M))
else :
print(':(') | [
"call.add"
] | 647,277 | 647,276 | u441246928 | python |
p02842 | # N=1079
N=int(input())
a=int(N*100/110)-1
flg=False
for i in range (N-a+1):
if ((a+i)*1.08)//1==N:
print(a+i)
exit
else:
pass
print(':(') | # N=1079
N=int(input())
a=int(N*100/110)-1
flg=False
for i in range (N-a+1):
if ((a+i)*1.08)//1==N:
print(a+i)
exit()
else:
pass
print(':(') | [
"call.add"
] | 647,280 | 647,281 | u674588203 | python |
p02842 | import math
x = int(input())
ans = math.ceil(x/1.08)
if x == round(ans * 1.08):
print(ans)
else:
print(":(") | import math
x = int(input())
ans = math.ceil(x/1.08)
if x == math.floor(ans * 1.08):
print(ans)
else:
print(":(") | [
"control_flow.branch.if.condition.change"
] | 647,298 | 647,299 | u098982053 | python |
p02842 | import math
x = int(input())
ans = math.ceil(x/1.08)
if x == (ans * 1.08):
print(ans)
else:
print(":(") | import math
x = int(input())
ans = math.ceil(x/1.08)
if x == math.floor(ans * 1.08):
print(ans)
else:
print(":(") | [
"control_flow.branch.if.condition.change"
] | 647,300 | 647,299 | u098982053 | python |
p02842 | import math
x = int(input())
ans = round(x/1.08)
if x == math.floor(ans * 1.08):
print(ans)
else:
print(":(") | import math
x = int(input())
ans = math.ceil(x/1.08)
if x == math.floor(ans * 1.08):
print(ans)
else:
print(":(") | [
"assignment.value.change"
] | 647,301 | 647,299 | u098982053 | python |
p02842 | n=int(input())
for i in range(n):
if i*1.08>=n and i*1.08<n+1:
print(i)
break
else:
print(":(") | n=int(input())
for i in range(1,n+1):
if i*1.08>=n and i*1.08<n+1:
print(i)
break
else:
print(":(") | [
"call.arguments.add"
] | 647,308 | 647,309 | u629350026 | python |
p02842 | N = int(input())
for i in range(N):
if int(i * 1.08) == N:
print(i)
exit()
print(':(') | N = int(input())
for i in range(N+100):
if int(i * 1.08) == N:
print(i)
exit()
print(':(') | [
"control_flow.loop.range.bounds.upper.change",
"expression.operation.binary.add"
] | 647,320 | 647,321 | u225845681 | python |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.