Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import math
A, B = map(int, input().split())

digits = 0

i = B
mid = A + (B - A) // 2

partSum = B * (B+1) // 2 - A * (A+1) // 2 + A
S = 0
while S != partSum:
	x = i
	while x >= A:
		digits = digits ^ x
		S += x
		if x % 2:
			break
		x //= 2
	i -= 1
	
print(digits)

Fixed submission:
A, B = map(int, input().split())

ones = [0] * 101
def calcones(end, pow):
	start = pow // 2
	if end < pow // 2:
		return 0
	
	n = (end - start + 1) // pow
	n *= pow // 2
	
	if 0 < (end - start + 1) % pow <= pow // 2:
		n += (end - start + 1) % pow
		
	return n

pow = 2
for i in range(1, 101):
	ones[i] = calcones(B, pow) - calcones(A-1, pow)
	pow *= 2
	
# print(ones)
		
ans = 0
pow = 1
for i in range(1, 101):
	ans += (ones[i] % 2) * pow
	pow *= 2
	
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
A, B = map(int, input().split())

digits = [0] * (100)

i = B
mid = A + (B - A) // 2

partSum = B * (B+1) // 2 - A * (A+1) // 2 + A
S = 0
while S != partSum:
	x = i
	while x >= A:
		keta = math.floor(math.log2(x))
		# print(x, bin(x), keta)
		for j in range(keta + 1):
			if x >> j & 1 == 1:
				digits[j] += 1
		S += x
		if x % 2:
			break
		x //= 2
	i -= 1
# print(digits)
for i in range(100):
	digits[i] = digits[i] % 2
# print(digits)
	
pow = 1
ans = 0
for i in range(100):
	ans += digits[i] * pow
	pow *= 2
	
print(ans)
	

Fixed submission:
A, B = map(int, input().split())

ones = [0] * 101
def calcones(end, pow):
	start = pow // 2
	if end < pow // 2:
		return 0
	
	n = (end - start + 1) // pow
	n *= pow // 2
	
	if 0 < (end - start + 1) % pow <= pow // 2:
		n += (end - start + 1) % pow
		
	return n

pow = 2
for i in range(1, 101):
	ones[i] = calcones(B, pow) - calcones(A-1, pow)
	pow *= 2
	
# print(ones)
		
ans = 0
pow = 1
for i in range(1, 101):
	ans += (ones[i] % 2) * pow
	pow *= 2
	
print(ans)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())

layers = [1]
patties = [1]

for i in range(1, N+1):
	layer_i = 2 * layers[i-1] + 3
	patty_i = 2 * patties[i-1] + 1
	layers.append(layer_i)
	patties.append(patty_i)
	
def f(n, x):
	if x == 1:
		return 0
		
	elif 1 < x <= 1 + layers[n-1]:
		return f(n-1, x-1)
		
	elif x == 2 + layers[n-1]:
		return patties[n-1] + 1
		
	elif 2 + layers[n-1] < x <= 2 + 2 * layers[n-1]:
		return patties[n-1] + 1 + f(n-1, x-2-layers[n-1])
	elif x == 3 + 2 * layers[n-1]:
		return 2 * patties[n-1] + 1
		
print(f(N, X))N, X = map(int, input().split())

layers = [1]
patties = [1]

for i in range(1, N+1):
	layer_i = 2 * layers[i-1] + 3
	patty_i = 2 * patties[i-1] + 1
	layers.append(layer_i)
	patties.append(patty_i)
	
def f(n, x):
	if x == 1:
		return 0
		
	elif 1 < x <= 1 + layers[n-1]:
		return f(n-1, x-1)
		
	elif x == 2 + layers[n-1]:
		return patties[n-1] + 1
		
	elif 2 + layers[n-1] < x <= 2 + 2 * layers[n-1]:
		return patties[n-1] + 1 + f(n-1, x-2-layers[n-1])
	elif x == 3 + 2 * layers[n-1]:
		return 2 * patties[n-1] + 1
		
print(f(N, X))


Fixed submission:
import sys
sys.setrecursionlimit(10**5)
N, X = map(int, input().split())

layers = [1]
patties = [1]

for i in range(1, N+1):
	layer_i = 2 * layers[i-1] + 3
	patty_i = 2 * patties[i-1] + 1
	layers.append(layer_i)
	patties.append(patty_i)
	
def f(n, x):
	if x == 1:
		return 1 if n == 0 else 0
		
	elif 1 < x <= 1 + layers[n-1]:
		return f(n-1, x-1)
		
	elif x == 2 + layers[n-1]:
		return patties[n-1] + 1
		
	elif 2 + layers[n-1] < x <= 2 + 2 * layers[n-1]:
		return patties[n-1] + 1 + f(n-1, x-2-layers[n-1])
		
	else:
		return 2 * patties[n-1] + 1
		
print(f(N, X))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**5)
N, X = map(int, input().split())

def f(burger, counter):
    if counter == 0:
        return "P"

    L = f(burger, counter - 1)
    newBurger = "B" + L + "P" + L + "B"

    return newBurger

burger = f("", N)

ans = burger[0:X].count("P")
print(ans)


Fixed submission:
import sys
sys.setrecursionlimit(10**5)
N, X = map(int, input().split())

layers = [1]
patties = [1]

for i in range(1, N+1):
	layer_i = 2 * layers[i-1] + 3
	patty_i = 2 * patties[i-1] + 1
	layers.append(layer_i)
	patties.append(patty_i)
	
def f(n, x):
	if x == 1:
		return 1 if n == 0 else 0
		
	elif 1 < x <= 1 + layers[n-1]:
		return f(n-1, x-1)
		
	elif x == 2 + layers[n-1]:
		return patties[n-1] + 1
		
	elif 2 + layers[n-1] < x <= 2 + 2 * layers[n-1]:
		return patties[n-1] + 1 + f(n-1, x-2-layers[n-1])
		
	else:
		return 2 * patties[n-1] + 1
		
print(f(N, X))
Buggy python submission (verdict: Runtime Error):
from collections import deque
import sys
H, W = list(map(int, input().split()))

city = []

for _ in range(H):
    city.append(list(input()))

dist = [[float("inf") for _ in range(W)] for _ in range(H)]

dist_count = [0 for _ in range(H*W)]

queue = deque()
queue.append((0, 0))

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

while len(queue) > 0:
    now_x, now_y = queue.popleft()

    for dx_, dy_ in zip(dx, dy):

        adj_x = now_x + dx_
        adj_y = now_y + dy_

        if (not 0 <= adj_x < W) or (not 0 <= adj_y < H):
            continue

        if city[adj_y][adj_x] == "#":
            continue

        if dist[adj_y][adj_x] > H*W:
            dist[adj_y][adj_x] = dist[now_x][now_y] + 1
            queue.append((adj_x, adj_y))
            dist_count[dist[adj_y][adj_x]] += 1

#すぬけ君がどうやってもたどり着けない場合
if dist[H-1][W-1] > H*W:
    print(-1)
    sys.exit()

#すぬけ君がたどり着ける場合
max_dist = dist[H-1][W-1]

ans = 0
for i in range(1, max_dist+1):
    ans += dist[i] - 1
print(ans)


Fixed submission:
from collections import deque
import sys
H, W = list(map(int, input().split()))

city = []

for _ in range(H):
    city.append(list(input()))

dist = [[float("inf") for _ in range(W)] for _ in range(H)]

dist_count = [0 for _ in range(H*W)]

queue = deque()
queue.append((0, 0))
dist[0][0] = 0

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

while len(queue) > 0:
    now_x, now_y = queue.popleft()

    for dx_, dy_ in zip(dx, dy):

        adj_x = now_x + dx_
        adj_y = now_y + dy_

        if (not 0 <= adj_x < W) or (not 0 <= adj_y < H):
            continue

        if city[adj_y][adj_x] == "#":
            continue

        if dist[adj_y][adj_x] > H*W:
            dist[adj_y][adj_x] = dist[now_y][now_x] + 1
            queue.append((adj_x, adj_y))
            dist_count[dist[adj_y][adj_x]] += 1

#すぬけ君がどうやってもたどり着けない場合
if dist[H-1][W-1] > H**W:
    print(-1)
    sys.exit()

#すぬけ君がたどり着ける場合
route_grids = dist[H-1][W-1] + 1

white_all = 0
for i in range(H):
    for j in range(W):
        if city[i][j] == ".":
            white_all += 1
ans = white_all - route_grids
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque, defaultdict
N, M = map(int, input().split())
graph = [[] for _ in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    a -= 1; b -= 1;
    graph[a].append(b)
    graph[b].append(a)


visited = [False for _ in range(N)]
color = [0 for _ in range(N)]

def dfs(now, c):

    color[now] = c

    for adj in graph[now]:
        if color[adj] == c:
            return False

        if color[adj] == 0 and not dfs(adj, -c):
            return False

    return True

ans = dfs(0, 1)
white = color.count(-1)
black = N - white
if ans:
    print(black * white - M)
else:
    print(N * (N+1)//2 - M)


Fixed submission:
from collections import deque, defaultdict
import sys

sys.setrecursionlimit(10**8)
N, M = map(int, input().split())
graph = [[] for _ in range(N)]

for i in range(M):
    a, b = map(int, input().split())
    a -= 1; b -= 1;
    graph[a].append(b)
    graph[b].append(a)


visited = [False for _ in range(N)]
color = [0 for _ in range(N)]

def dfs(now, c):

    color[now] = c

    for adj in graph[now]:
        if color[adj] == c:
            return False

        if color[adj] == 0 and not dfs(adj, -c):
            return False

    return True

ans = dfs(0, 1)
white = color.count(-1)
black = N - white
if ans:
    print(black * white - M)
else:
    print(N * (N-1)//2 - M)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 998244353


def main():
    from bisect import bisect_left
    N, K = (int(i) for i in input().split())
    S = set()
    for _ in range(K):
        le, ri = (int(i) for i in input().split())
        for i in range(le, ri+1):
            S.add(i)

    A = sorted(S)
    memo = [0] * (N+1)
    memo[0] = 1

    def dfs(N):
        if N < 0:
            return 0
        if memo[N] != 0:
            return memo[N]
        ret = 0
        idx = bisect_left(A, N)
        for i in A[idx::-1]:
            ret += dfs(N - i)
            ret %= MOD
        memo[N] = ret
        return ret

    print(dfs(N-1))
    # print(memo, A)


if __name__ == '__main__':
    main()


Fixed submission:
MOD = 998244353


def main():
    N, K = (int(i) for i in input().split())
    LR = [[int(i) for i in input().split()] for j in range(K)]

    dp = [0] * (N+2)
    dp[1] = 1
    dp[2] = -1
    for i in range(1, N+1):
        for le, ri in LR:
            if i+le <= N:
                dp[i+le] += dp[i]
                dp[i+le] %= MOD
            if i+ri+1 <= N:
                dp[i+ri+1] -= dp[i]
                dp[i+ri+1] %= MOD
        dp[i+1] += dp[i]
        dp[i+1] %= MOD
    print(dp[N])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    H, W, M = (int(i) for i in input().split())
    hc = [0]*(H+1)
    wc = [0]*(W+1)
    maps = set()
    for _ in range(M):
        h, w = (int(i) for i in input().split())
        hc[h] += 1
        wc[w] += 1
        maps.add((h, w))
    mah = -1
    maw = -1
    hmaps = set()
    wmaps = set()
    for i, h in enumerate(hc):
        if mah < h:
            mah = h
            hmaps = {i}
        elif mah == h:
            hmaps.add(i)
    for i, w in enumerate(wc):
        if maw < w:
            maw = w
            wmaps = {i}
        elif maw == w:
            wmaps.add(i)
    ans = mah+maw
    aru = True

    for h in list(hmaps):
        for w in list(wmaps):
            if (h, w) not in maps:
                aru = False
                break
    if aru:
        print(ans - 1)
    else:
        print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    H, W, M = (int(i) for i in input().split())
    hc = [0]*(H+1)
    wc = [0]*(W+1)
    maps = set()
    for _ in range(M):
        h, w = (int(i) for i in input().split())
        hc[h] += 1
        wc[w] += 1
        maps.add((h, w))
    mah = -1
    maw = -1
    hmaps = set()
    wmaps = set()
    for i, h in enumerate(hc):
        if mah < h:
            mah = h
            hmaps = {i}
        elif mah == h:
            hmaps.add(i)
    for i, w in enumerate(wc):
        if maw < w:
            maw = w
            wmaps = {i}
        elif maw == w:
            wmaps.add(i)
    ans = mah+maw
    aru = True
    if len(hmaps) * len(wmaps) <= 5*10**6:
        for h in list(hmaps):
            for w in list(wmaps):
                if (h, w) not in maps:
                    aru = False
                    break
    else:
        aru = False
    if aru:
        print(ans - 1)
    else:
        print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    for n in range(1, N+1):
        cur = 0
        for x in range(1, N+1):
            if n < x**2:
                break
            for y in range(1, N+1):
                if n < x**2 + y**2 + x*y:
                    break
                for z in range(1, N+1):
                    if n < x**2 + y**2 + z**2 + x*y + y*z + z*x:
                        break
                    if n == x**2 + y**2 + z**2 + x*y + y*z + z*x:
                        cur += 1
        print(cur)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N = int(input())
    ans = [0]*(N+1)
    for x in range(1, N+1):
        if N < x**2:
            break
        for y in range(1, N+1):
            if N < x**2 + y**2 + x*y:
                break
            for z in range(1, N+1):
                if N < x**2 + y**2 + z**2 + x*y + y*z + z*x:
                    break
                ans[x**2 + y**2 + z**2 + x*y + y*z + z*x] += 1

    print(*ans[1:], sep="\n")


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main(N):
    ans = 0

    for i in range(1, N+1):
        for j in range(i, N+1, i):
            ans += j
    print(ans)


if __name__ == '__main__':
    N = int(input())
    main(N)


Fixed submission:
def main():
    N = int(input())
    A = [1]*(N+1)
    A[0] = 0

    for i in range(2, N+1):
        j = i
        while j <= N:
            A[j] += 1
            j += i
    print(sum(i*a for i, a in enumerate(A)))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
https://kkt89.hatenablog.com/entry/2020/06/21/ABC171_F-Strivore

Fixed submission:
MOD = 10**9 + 7


def main():
    K = int(input())
    S = input()
    N = len(S)
    m = N+K + 5
    fac = [0] * m
    finv = [0] * m
    inv = [0] * m

    def COMBinitialize(m):
        fac[0] = 1
        finv[0] = 1
        if m > 1:
            fac[1] = 1
            finv[1] = 1
            inv[1] = 1
            for i in range(2, m):
                fac[i] = fac[i-1] * i % MOD
                inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
                finv[i] = finv[i - 1] * inv[i] % MOD

    def COMB(n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

    COMBinitialize(m)
    ans = 0
    for i in range(K+1):
        v = COMB(N-1+K-i, N-1)
        v %= MOD
        v *= pow(25, (K-i), MOD)
        v %= MOD
        v *= pow(26, i, MOD)
        v %= MOD
        ans += v
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
MOD = 10**9 + 7
m = 10**6 + 5
fac = [0] * m
finv = [0] * m
inv = [0] * m


def COMBinitialize(m):
    fac[0] = 1
    finv[0] = 1
    if m > 1:
        fac[1] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2, m):
            fac[i] = fac[i-1] * i % MOD
            inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
            finv[i] = finv[i - 1] * inv[i] % MOD


def COMB(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


def main():
    K = int(input())
    S = input()
    N = len(S)
    ans = 0
    COMBinitialize(m)
    for i in range(K+1):
        ans += COMB(N-1+K-i, N-1) * pow(25, (K-i), MOD) * pow(26, i, MOD)
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
MOD = 10**9 + 7


def main():
    K = int(input())
    S = input()
    N = len(S)
    m = N+K + 5
    fac = [0] * m
    finv = [0] * m
    inv = [0] * m

    def COMBinitialize(m):
        fac[0] = 1
        finv[0] = 1
        if m > 1:
            fac[1] = 1
            finv[1] = 1
            inv[1] = 1
            for i in range(2, m):
                fac[i] = fac[i-1] * i % MOD
                inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
                finv[i] = finv[i - 1] * inv[i] % MOD

    def COMB(n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

    COMBinitialize(m)
    ans = 0
    for i in range(K+1):
        v = COMB(N-1+K-i, N-1)
        v %= MOD
        v *= pow(25, (K-i), MOD)
        v %= MOD
        v *= pow(26, i, MOD)
        v %= MOD
        ans += v
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from numba import njit


@njit
def main(X):
    for a in range(-2000, 2001):
        for b in range(-2000, 2001):
            if pow(a, 5) - pow(b, 5) == X:
                print(a, b)
                return


if __name__ == '__main__':
    X = int(input())
    main(X)


Fixed submission:
def main():
    X = int(input())
    for a in range(-200, 201):
        for b in range(-200, 201):
            if a**5 - b**5 == X:
                return print(a, b)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    from itertools import combinations_with_replacement
    import sys
    input = sys.stdin.buffer.readline
    N, M, Q = (int(i) for i in input().split())
    T = [[int(i) for i in input().split()] for j in range(Q)]
    ans = 0
    for A in combinations_with_replacement(range(1, M+1), N):
        A.sort()
        cur = 0
        for a, b, c, d in T:
            if A[b-1] - A[a-1] == c:
                cur += d
        ans = max(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M, Q = (int(i) for i in input().split())
    T = [[int(i) for i in input().split()] for j in range(Q)]

    def dfs(A):
        cur = 0
        if len(A) == N:
            for a, b, c, d in T:
                if A[b-1] - A[a-1] == c:
                    cur += d
        elif len(A) == 0:
            for i in range(1, M+1):
                v = dfs(A + [i])
                cur = max(cur, v)
        else:
            for i in range(A[-1], M+1):
                v = dfs(A + [i])
                cur = max(cur, v)
        return cur

    print(dfs([]))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    S = input()
    N = len(S)
    K = int(input())
    dp = [[[0]*(N+1) for j in range(2)] for i in range(N+1)]
    dp[0][0][0] = 1
    for i in range(N):
        for j in range(2):
            for k in range(N):
                lim = (9 if j else int(S[i]))
                for d in range(lim + 1):
                    dp[i+1][j or d < lim][k + (d != 0)] += dp[i][j][k]
    ans = 0
    for j in range(2):
        ans += dp[N][j][K]
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    S = input()
    N = len(S)
    K = int(input())
    dp = [[[0]*(4) for j in range(2)] for i in range(N+1)]
    dp[0][0][0] = 1
    for i in range(N):
        for j in range(2):
            for k in range(4):
                lim = (9 if j else int(S[i]))
                for d in range(lim + 1):
                    if k + (d != 0) > 3:
                        continue
                    dp[i+1][j or d < lim][k + (d != 0)] += dp[i][j][k]
    ans = 0
    for j in range(2):
        ans += dp[N][j][K]
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    MOD = 10**9 + 7
    r1, c1, r2, c2 = (int(i) for i in input().split())
    m = r2 + c2 + 1
    fac = [0] * m
    finv = [0] * m
    inv = [0] * m

    def COMBinitialize(m):
        fac[0] = 1
        finv[0] = 1
        if m > 1:
            fac[1] = 1
            finv[1] = 1
            inv[1] = 1
            for i in range(2, m):
                fac[i] = fac[i-1] * i % MOD
                inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
                finv[i] = finv[i - 1] * inv[i] % MOD

    def COMB(n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

    COMBinitialize(m)
    ans = 0
    # TLE
    for r in range(r1, r2+1):
        for c in range(c1, c2+1):
            ans += (fac[r+c]*finv[r]*finv[c]) % MOD
    """
    for i, v in enumerate(range(r1+c1, r2+c2+1)):
        print(i, v)
        for r in range(r1, min(r2+2, r1+(i+1))):
            c = v - r
            if c < c1 or c2 < c:
                break
            ans += (fac[v]*finv[r]*finv[c]) % MOD
            print("   ", r, c, (fac[v]*finv[r]*finv[c]) % MOD)
    """
    print(ans % MOD)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    MOD = 10**9 + 7
    r1, c1, r2, c2 = (int(i) for i in input().split())
    m = r2 + c2 + 3
    fac = [0] * m
    finv = [0] * m
    inv = [0] * m

    def COMBinitialize(m):
        fac[0] = 1
        finv[0] = 1
        if m > 1:
            fac[1] = 1
            finv[1] = 1
            inv[1] = 1
            for i in range(2, m):
                fac[i] = fac[i-1] * i % MOD
                inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
                finv[i] = finv[i - 1] * inv[i] % MOD

    def COMB(n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

    COMBinitialize(m)
    ans = 0
    ans += (fac[r2+1+c2+1]*finv[r2+1]*finv[c2+1] - 1) % MOD
    ans -= (fac[r2+1+c1]*finv[r2+1]*finv[c1] - 1) % MOD
    ans -= (fac[r1+c2+1]*finv[r1]*finv[c2+1] - 1) % MOD
    ans += (fac[r1+c1]*finv[r1]*finv[c1] - 1) % MOD
    print(ans % MOD)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    H = int(input())
    div = {2**i for i in range(40)}
    ans = 0
    from math import log2, ceil
    if not(H in div):
        for h in range(int(log2(H)) + 1):
            ans += 2**h
        print(ans)
    else:
        for h in range(int(log2(H)) + 1):
            ans += 2**h
        print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    H = int(input())
    div = {2**i for i in range(40)}
    ans = 0
    from math import log2, ceil
    if not(H in div):
        for h in range(int(log2(H)) + 1):
            ans += 2**h
        print(ans)
    else:
        for h in range(int(log2(H)) + 1):
            ans += 2**h
        print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    H, N = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    dp = [10**12 for i in range(H+1)]  # dp[i] := 体力をi減らすときの魔力の最小値
    dp[0] = 0
    for h in range(H):
        for damage, cost in AB:
            next_index = min(h + damage, H)
            dp[next_index] = min(dp[next_index], dp[h] + cost)
    print(dp[H])


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    H, N = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    dp = [[(10**8) for i in range(H + 1)] for j in range(N+1)]
    for i in range(N+1):
        dp[i][0] = 0

    for i in range(1, N + 1):
        for h in range(H + 1):
            dp[i][h] = min(dp[i][max(h - AB[i - 1][0], 0)] +
                           AB[i - 1][1], dp[i - 1][h])
    print(dp[N][H])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    H, N = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    dp = [[(10**8) for i in range(H + 1)] for j in range(N+1)]
    for i in range(N+1):
        dp[i][0] = 0

    for i in range(1, N + 1):
        for h in range(H + 1):
            dp[i][h] = min(dp[i][max(h - AB[i - 1][0], 0)] +
                           AB[i - 1][1], dp[i - 1][h])
    print(dp[N][H])


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    H, N = (int(i) for i in input().split())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    dp = [[(10**8) for i in range(H + 1)] for j in range(N+1)]
    for i in range(N+1):
        dp[i][0] = 0

    for i in range(1, N + 1):
        for h in range(H + 1):
            dp[i][h] = min(dp[i][max(h - AB[i - 1][0], 0)] +
                           AB[i - 1][1], dp[i - 1][h])
    print(dp[N][H])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = [input() for i in range(N)]
    S = input()
    print(sum(A[S.index():]))


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    N = int(input())
    A = [input().split() for i in range(N)]
    S = input()
    flag = False
    ans = 0
    for i, a in enumerate(A):
        if a[0] == S:
            flag = True
        elif flag:
            ans += int(a[1])
    print(ans)


if __name__ == '__main__':
    main()