Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
x1 -= 1
x2 -= 1
y1 -= 1
y2 -= 1
# C[h][w]
C = [list(input()) for _ in range(h)]

dist = [[10 ** 10] * w for _ in range(h)]

dist[x1][y1] = 0
que = deque([])
que.append((x1, y1))

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

while que:
    a, b = que.popleft()
    d = dist[a][b]
    if a == x2 and b == y2:
        print(dist[x2][y2])
        exit()
    for i in range(4):
        cx = a + dx[i]
        cy = b + dy[i]
        if cx < 0 or cx >= h or cy < 0 or cy >= w:
            continue
        if C[cx][cy] == "@":
            continue
        for j in range(1, k + 1):
            nx = a + dx[i] * j
            ny = b + dy[i] * j
            if nx < 0 or nx >= h or ny < 0 or ny >= w:
                break
            if C[nx][ny] == "@":
                break
            if dist[nx][ny] == 10 ** 10:
                dist[nx][ny] = d + 1
                que.append((nx, ny))
print(-1)


Fixed submission:
from collections import deque

h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
x1 -= 1
x2 -= 1
y1 -= 1
y2 -= 1
# C[h][w]
C = [list(input()) for _ in range(h)]

dist = [[10 ** 10] * w for _ in range(h)]

dist[x1][y1] = 0
que = deque([])
que.append((x1, y1))

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

while que:
    a, b = que.popleft()
    d = dist[a][b]
    if a == x2 and b == y2:
        print(dist[x2][y2])
        exit()
    for i in range(4):
        cx = a + dx[i]
        cy = b + dy[i]
        if cx < 0 or cx >= h or cy < 0 or cy >= w:
            continue
        if C[cx][cy] == "@":
            continue
        for j in range(1, k + 1):
            nx = a + dx[i] * j
            ny = b + dy[i] * j
            if nx < 0 or nx >= h or ny < 0 or ny >= w:
                break
            if C[nx][ny] == "@":
                break
            if dist[nx][ny] < d + 1:
                break
            if dist[nx][ny] == 10 ** 10:
                dist[nx][ny] = d + 1
                que.append((nx, ny))
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
ans = 1
flag = 0
zeroflag = 0
for a in A:
    ans *= a
    if ans > pow(10, 18):
        flag = 1
    if a == 0:
        zeroflag = 1
if flag:
    ans = -1
if zeroflag:
    ans = 0
print(ans if ans <= pow(10, 18) else -1)


Fixed submission:
n = int(input())
A = list(map(int, input().split()))
ans = 1
flag = 0
zeroflag = 0
for a in A:
    if a == 0:
        print(0)
        exit()
for a in A:
    ans *= a
    if ans > pow(10, 18):
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.buffer.readline

n, s = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
dp = [[{} for _ in range(s + 1)] for _ in range(n + 1)]
dp[0][0][0] = 1
kiroku = [0] * (n)

for i in range(n):
    ni = i + 1
    for j in range(s + 1):
        nj = j
        if dp[i][j] == {}:
            continue
        for key, val in dp[i][j].items():
            if key in dp[ni][nj]:
                dp[ni][nj][key] += val
            else:
                dp[ni][nj][key] = val
        nj = j + A[i]
        if nj <= s:
            for key, val in dp[i][j].items():
                if key + 1 in dp[ni][nj]:
                    dp[ni][nj][key + 1] += val
                else:
                    dp[ni][nj][key + 1] = val
ans = 0
for key, val in dp[n][s].items():
    if key == 0:
        continue
    ans += pow(2, n - key) * val
    ans %= mod
print(ans)


Fixed submission:
import sys

input = sys.stdin.buffer.readline

n, s = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
dp = [[0] * (s + 1) for _ in range(n + 1)]
dp[0][0] = 1

for i in range(n):
    ni = i + 1
    for j in range(s + 1):
        nj = j
        dp[ni][nj] += 2 * dp[i][j]
        dp[ni][nj] %= mod
        nj = j + A[i]
        if nj <= s:
            dp[ni][nj] += dp[i][j]
            dp[ni][nj] %= mod
print(dp[n][s] % mod)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = len(s)
ans = ""
for i in range(n):
  if s[i] == "?":
    ans += "D"
  else:
    ans += s[i]
print(ans)


Fixed submission:
s = input()
temp = list(s)
for i in range(len(list(s))):
    if s[i] == "?":
        temp[i] = "D"
print(*temp, sep="")
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
max_k = k.bit_length()
A = [0] + list(map(int, input().split()))

DB = [[0] * (n + 1) for _ in range(max_k + 1)]
# DB[i][j] 2**i乗回考えた時にjが移動する数
for j in range(1, n + 1):
    DB[0][j] = A[j]
for i in range(max_k):
    for j in range(1, n + 1):
        num = DB[i][j]
        DB[i + 1][j] += DB[i][num]
bit = bin(k)
num = 1
for i in range(max_k):
    if bit[-(i + 1)] == "1":
        num = DB[i][num]
print(num)


Fixed submission:
n, k = map(int, input().split())
A = [0] + list(map(int, input().split()))
cnt = 0
pre = 1
memo = []
kumi = set([])
if k < n:
    for i in range(2 * (10 ** 5) + 5):
        cur = A[pre]
        cnt += 1
        pre = cur
        if cnt == k:
            print(cur)
            exit()

else:
    for i in range(2 * (10 ** 5) + 5):
        cur = A[pre]
        cnt += 1
        memo.append(cur)
        if cur in kumi:
            break
        kumi.add(cur)
        pre = cur
    # 今までに見た物の数を減らしておく、kは残り回数
    k -= cnt

    for j in range(cnt):
        if memo[j] == cur:
            start = j
            break
    loop = memo[start:-1]

    loop_num = i - start
    print(loop[k % loop_num])
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

x = int(input())
kouho = [pow(i, 5) for i in range(10 ** 7)]

for left in range(10 ** 7):
    L = pow(left, 5)
    kouho1 = abs(L + x)
    pos1 = bisect_left(kouho, kouho1)
    if pos1 < 10 ** 7:
        if kouho[pos1] == kouho1:
            right = pos1
            break
    kouho2 = abs(L - x)
    pos2 = bisect_left(kouho, kouho2)
    if kouho[pos2] < 10 ** 7:
        if kouho[pos2] == kouho2:
            right = pos2
            break

bigger = max(abs(left), abs(right))
smaller = min(abs(right), abs(left))
if smaller == 0:
    print(bigger, smaller)
    exit()
if bigger ** 5 - smaller ** 5 == x:
    print(bigger, smaller)
if bigger ** 5 + smaller ** 5 == x:
    print(bigger, -smaller)


Fixed submission:
x = int(input())
for a in range(1000 + 1):
    for b in range(1000 + 1):
        A = pow(a, 5)
        B = pow(b, 5)
        if A - B == x:
            print(a, b)
            exit()
        if A + B == x:
            print(a, -b)
            exit()
print("wrong")
Buggy python submission (verdict: Runtime Error):
import sys
input = readline
from itertools import product

n, m, q = map(int, input().split())

ABCD = [list(map(int, input().split())) for _ in range(q)]

kumiawase = list(product(range(1, m + 1), repeat=n))

ans = 0
for kumi in kumiawase:
    A = [0] + list(kumi)
    temp = 0
    for abcd in ABCD:
        a, b, c, d = abcd
        if A[b] - A[a] == c:
            temp += d
    ans = max(ans, temp)

print(ans)



Fixed submission:
import sys

input = sys.stdin.buffer.readline

from itertools import combinations_with_replacement

n, m, q = map(int, input().split())

ABCD = [list(map(int, input().split())) for _ in range(q)]

kumiawase = list(combinations_with_replacement(range(1, m + 1), n))

ans = 0
for kumi in kumiawase:
    A = [0] + list(kumi)
    temp = 0
    for abcd in ABCD:
        a, b, c, d = abcd
        if A[b] - A[a] == c:
            temp += d
    ans = max(ans, temp)

print(ans)
Buggy python submission (verdict: Runtime Error):
# 解説AC
from math import gcd
from collections import defaultdict
import sys

input = sys.stdin.buffer.readline

mod = 10 ** 9 + 7
n = int(input())
cnt = 0
cnt += n
zerocnt = 0
kumi = defaultdict(int)
for i in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zerocnt += 1
        continue
    elif b == 0:
        kumi[(1, 0)] += 1
        kumi[(0, -1)] += 0
        continue
    elif a == 0:
        kumi[(0, -1)] += 1
        kumi[(1, 0)] += 0
        continue
    g = gcd(a, b)
    a //= g
    b //= g
    if a < 0:
        a *= -1
        b *= -1
    kumi[(a, b)] += 1
    kumi[(b, -a)] += 0
ans = 1
cnt -= zerocnt
for a, b in kumi.keys():
    if b <= 0:
        continue
    s = kumi[(a, b)]
    t = kumi[(b, -a)]
    ans *= pow(2, (s + t), mod) - (pow(2, s, mod) - 1) * (pow(2, t, mod) - 1)
    ans %= mod
    cnt -= s + t
if cnt > 0:
    ans *= pow(2, cnt, mod)
    ans %= mod
print((ans - 1 + zerocnt) % mod)


Fixed submission:
n, m = map(int, input().split())
if m % 2 == 1:

    cnt = 0

    for i in range(m // 2):
        num1 = 1 + i
        num2 = m - i
        print(num1, num2, sep=" ")
        cnt += 1
        if cnt == m:
            exit()
    for i in range(m // 2 + 1):
        num1 = m + 1 + i
        num2 = 2 * m + 1 - i
        print(num1, num2, sep=" ")
        cnt += 1
        if cnt == m:
            exit()
else:
    cnt = 0

    for i in range(m // 2):
        num1 = 1 + i
        num2 = m + 1 - i
        print(num1, num2, sep=" ")
        cnt += 1
        if cnt == m:
            exit()
    for i in range(m // 2):
        num1 = m + 2 + i
        num2 = 2 * m + 1 - i
        print(num1, num2, sep=" ")
        cnt += 1
        if cnt == m:
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
# 解説AC
import sys
input = sys.stdin.buffer.readline

n = int(input())
A = list(map(int, input().split()))
B = []
for i, e in enumerate(A):
    B.append((e, i + 1))
B.sort(reverse=True)
# dp[i][j]: Aiまで入れた時、左にj個決めた時の最大値
dp = [[-1] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 0

for i in range(n):
    for j in range(i + 1):  # 左の個数
        k = i - j  # 右の個数
        ni = i + 1
        val, idx = B[i]
        dp[ni][j] = max(dp[ni][j], dp[i][j] + abs(n - k - idx) * val)
        dp[ni][j + 1] = max(dp[ni][j + 1], dp[i][j] + abs(idx - (j + 1)) * val)
ans = 0
for i in range(n + 1):
    ans = max(ans, dp[n][i])
print(ans)


Fixed submission:
# 解説AC
import sys
input = sys.stdin.buffer.readline

n = int(input())
A = list(map(int, input().split()))
B = []
for i, e in enumerate(A):
    B.append((e, i + 1))
B.sort(reverse=True)
# dp[i][j]: Aiまで入れた時、左にj個決めた時の最大値
dp = [[-1] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 0

for i in range(n):
    for j in range(i + 1):  # 左の個数
        k = i - j  # 右の個数
        ni = i + 1
        val, idx = B[i]
        dp[ni][j] = max(dp[ni][j], dp[i][j] + abs(n - k - idx) * val)
        dp[ni][j + 1] = max(dp[ni][j + 1], dp[i][j] + abs(idx - (j + 1)) * val)
ans = 0
for i in range(n + 1):
    ans = max(ans, dp[n][i])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# 解説AC
n = int(input())
A = list(map(int, input().split()))
B = []
for i, e in enumerate(A):
    B.append((e, i + 1))
B.sort(reverse=True)
# dp[i][j]: Aiまで入れた時、左にj個決めた時の最大値
dp = [[-1] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 0

for i in range(n):
    for j in range(i + 1):  # 左の個数
        k = i - j  # 右の個数
        ni = i + 1
        val, idx = B[i]
        dp[ni][j] = max(dp[ni][j], dp[i][j] + abs(n - k - idx) * val)
        dp[ni][j + 1] = max(dp[ni][j + 1], dp[i][j] + abs(idx - (j + 1)) * val)
ans = 0
for i in range(n + 1):
    ans = max(ans, dp[n][i])
print(ans)


Fixed submission:
# 解説AC
import sys
input = sys.stdin.buffer.readline

n = int(input())
A = list(map(int, input().split()))
B = []
for i, e in enumerate(A):
    B.append((e, i + 1))
B.sort(reverse=True)
# dp[i][j]: Aiまで入れた時、左にj個決めた時の最大値
dp = [[-1] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 0

for i in range(n):
    for j in range(i + 1):  # 左の個数
        k = i - j  # 右の個数
        ni = i + 1
        val, idx = B[i]
        dp[ni][j] = max(dp[ni][j], dp[i][j] + abs(n - k - idx) * val)
        dp[ni][j + 1] = max(dp[ni][j + 1], dp[i][j] + abs(idx - (j + 1)) * val)
ans = 0
for i in range(n + 1):
    ans = max(ans, dp[n][i])
print(ans)
Buggy python submission (verdict: Runtime Error):
from heapq import heappop, heapify, heappush
import sys

input = sys.stdin.buffer.readline()

x, y, a, b, c = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
AB = A[:x] + (B[:y])

heapify(AB)
heapify(C)
ans = 0
for _ in range(len(C)):
    c = heappop(C)
    ab = heappop(AB)
    if ab > c:
        heappush(AB, ab)
        break
    heappush(AB, c)
ans = sum(AB)
print(ans)

Fixed submission:
from heapq import heappop, heapify, heappush


x, y, a, b, c = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = [-i for i in C]
A.sort(reverse=True)
B.sort(reverse=True)
AB = A[:x] + (B[:y])

heapify(AB)
heapify(D)
ans = 0
for _ in range(c):
    d = -heappop(D)
    ab = heappop(AB)
    if ab > d:
        heappush(AB, ab)
        break
    heappush(AB, d)
ans = sum(AB)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
h, w, k = map(int, input().split())
C = [list(input()) for _ in range(h)]
# C[hCX][w]
ans = 10 ** 20
for s in range(2 ** (h - 1)):
    yoko = bin(s).count("1")
    white = [0] * (yoko + 2)
    cnt = 0
    # 横分割を足しておく
    cnt += yoko
    outflag = 0
    for j in range(w):
        now = 0
        for i in range(h):
            if outflag:
                break
            white[now] += int(C[i][j])
            if white[now] > k:
                # 縦分割をする時はkを超えた時。
                # kを超えたら1つ前で割ったことにするので、
                # その列をもう1回やり直す必要あり
                cnt += 1
                # 同じjのところをi=[0,i]までやり直す
                # 初期化
                white = [0] * (yoko + 2)
                now = 0
                # 0からiまでやり直す
                for t in range(i + 1):
                    white[now] += int(C[t][j])
                    if white[now] > k:
                        outflag = 1
                        break
                    if (s >> t) & 1 == 1:
                        now += 1
                continue
            if (s >> i) & 1 == 1:
                now += 1
        if outflag:
            break
    if outflag:
        outflag = 0
        continue
    ans = min(cnt, ans)
print(ans)


Fixed submission:
h, w, k = map(int, input().split())
C = [list(input()) for _ in range(h)]
# C[hCX][w]
ans = 10 ** 20
for s in range(2 ** (h - 1)):
    yoko = bin(s).count("1")
    white = [0] * (yoko + 2)
    cnt = 0
    # 横分割を足しておく
    cnt += yoko
    outflag = 0
    for j in range(w):
        now = 0
        for i in range(h):
            if outflag:
                break
            white[now] += int(C[i][j])
            if white[now] > k:
                # 縦分割をする時はkを超えた時。
                # kを超えたら1つ前で割ったことにするので、
                # その列をもう1回やり直す必要あり
                cnt += 1
                # 同じjのところをi=[0,i]までやり直す
                # 初期化
                white = [0] * (yoko + 2)
                now = 0
                # 0からiまでやり直す
                for t in range(i + 1):
                    white[now] += int(C[t][j])
                    if white[now] > k:
                        outflag = 1
                        break
                    if (s >> t) & 1 == 1:
                        now += 1
                continue
            if (s >> i) & 1 == 1:
                now += 1
        if outflag:
            break
    if outflag:
        outflag = 0
        continue
    ans = min(cnt, ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.buffer.readline
n, s = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0] * (s + 1) for _ in range(n + 1)]

mod = 998244353
# dp[i][s] A[i]まで見た時、合計sになる数。
# 各々の地点で新しく開始されるものも有るので毎回dp[i][0]は＋1
dp[0][0] = 1
ans = 0
for i in range(n):
    ni = i + 1
    for j in range(s + 1):
        nj = j
        dp[ni][nj] += dp[i][j]
        dp[ni][nj] %= mod
        nj = j + A[i]
        if nj <= s:
            dp[ni][nj] += dp[i][j]
            dp[ni][nj] %= mod
    dp[ni][0] += 1
    ans += dp[ni][s]
    ans %= mod
print(ans)


Fixed submission:
n, s = map(int, input().split())
A = list(map(int, input().split()))
dp = [[0] * (s + 1) for _ in range(n + 1)]

mod = 998244353
# dp[i][s] A[i]まで見た時、合計sになる数。
# 各々の地点で新しく開始されるものも有るので毎回dp[i][0]は＋1
dp[0][0] = 1
ans = 0
for i in range(n):
    ni = i + 1
    for j in range(s + 1):
        nj = j
        dp[ni][nj] += dp[i][j]
        dp[ni][nj] %= mod
        nj = j + A[i]
        if nj <= s:
            dp[ni][nj] += dp[i][j]
            dp[ni][nj] %= mod
    dp[ni][0] += 1
    ans += dp[ni][s]
    ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
D=[list(input()) for i in range(h)]
# D[i][j]はD[h-1][w-1]まで
#dfs
stack=[]
stack.append((0,0,0))
da=[0,1]
db=[1,0]
infi=10**10
ans=infi
while stack:
    a,b, cnt=stack.pop()
    if D[a][b]=='#':
        cnt+=1
    if a+b==(h+w-2):
        ans=min(ans,cnt)
    for i in range(2):
        p=a+da[i]
        q=b+db[i]
        if 0<=p and p<=h-1 and 0<=q and q<=w-1:
            stack.append((p,q,cnt))
print(ans)

Fixed submission:
# import sys
# input = sys.stdin.readline
h,w=map(int,input().split())
infi=10**10
D=[list(input()) for i in range(h)]
kotae=[[infi]*(w) for _ in range(h)]
# D[i][j]はD[h-1][w-1]まで

cnt=0
if D[0][0]=='.':
    kotae[0][0]=0
else:
    kotae[0][0]=1
    cnt+=1
for i in range(1,h):
    if D[i][0]=='#' and D[i-1][0]=='.':
        cnt+=1
    kotae[i][0]=cnt

cnt=0
if D[0][0]=='.':
    kotae[0][0]=0
else:
    kotae[0][0]=1
    cnt+=1
for j in range(1,w):
    if D[0][j]=='#' and D[0][j-1]=='.':
        cnt+=1
    kotae[0][j]=cnt
for i in range(h-1):
    for j in range(w-1):
        kouho1 = kotae[i][j+1]
        if D[i][j+1]=='.' and D[i+1][j+1]=='#':
            kouho1+=1
        kouho2=kotae[i+1][j]
        if D[i+1][j]=='.' and D[i+1][j+1]=='#':
            kouho2+=1
        kotae[i+1][j+1]=min(kouho1,kouho2)
print(kotae[h-1][w-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,a,b=map(int,input().split())
mod=10**9+7
bunbo=1
bunshi=1
for i in range(1,max(a+1, b+1)):
    bunbo*=i
    bunshi*=n-i+1
    bunshi%=mod
    bunbo%=mod
    if i==a:
        comba=bunshi*(pow(bunbo,mod-2,mod))
    if i==b:
        combb=bunshi*(pow(bunbo,mod-2,mod))
print((2**n-1-comba-combb)%mod)

Fixed submission:
n,a,b=map(int,input().split())
mod=10**9+7
bunbo=1
bunshi=1
for i in range(1,max(a+1, b+1)):
    bunbo*=i
    bunshi*=n-i+1
    bunshi%=mod
    bunbo%=mod
    if i==a:
        comba=bunshi*(pow(bunbo,mod-2,mod))
    if i==b:
        combb=bunshi*(pow(bunbo,mod-2,mod))
print((2**n-1-comba-combb)%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n,a,b=map(int,input().split())
mod=10**9+7
bikkuri=[0 for i in range(n+5)]
bikkuri[0]=1
gyaku=[0 for i in range(n+5)]
gyaku[0]=1
for i in range(1,n+5):
    bikkuri[i] = (i * bikkuri[i-1])%mod
    gyaku[i]=pow(bikkuri[i], mod-2, mod)
def comb(a,b):
    return bikkuri[a]*gyaku[b]*gyaku[a-b]
ans=(2**n)-1-comb(n,a)-comb(n,b)
print(ans%mod)

Fixed submission:
n,a,b=map(int,input().split())
mod=10**9+7
bunbo=1
bunshi=1
for i in range(1,max(a+1, b+1)):
    bunbo*=i
    bunshi*=n-i+1
    bunshi%=mod
    bunbo%=mod
    if i==a:
        comba=bunshi*(pow(bunbo,mod-2,mod))
    if i==b:
        combb=bunshi*(pow(bunbo,mod-2,mod))
print((2**n-1-comba-combb)%mod)

Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
mod=10**9+7
bikkuri=[0 for i in range(n+5)]
bikkuri[0]=1
gyaku=[0 for i in range(n+5)]
gyaku[0]=1
for i in range(1,n+5):
    bikkuri[i] = (i * bikkuri[i-1])%mod
for i in range(n+4, -1, -1)
    gyaku[i]=pow(bikkuri[i], mod-2, mod)
def comb(a,b):
    return bikkuri[a]*gyaku[b]*gyaku[a-b]
ans=(2**n)-1-comb(n,a)-comb(n,b)
print(ans%mod)

Fixed submission:
n,a,b=map(int,input().split())
mod=10**9+7
bunbo=1
bunshi=1
for i in range(1,max(a+1, b+1)):
    bunbo*=i
    bunshi*=n-i+1
    bunshi%=mod
    bunbo%=mod
    if i==a:
        comba=bunshi*(pow(bunbo,mod-2,mod))
    if i==b:
        combb=bunshi*(pow(bunbo,mod-2,mod))
print((2**n-1-comba-combb)%mod)

Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
mod=10**9+7
bikkuri=[0 for i in range(n+5)]
bikkuri[0]=1
gyaku=[0 for i in range(n+5)]
gyaku[0]=1
for i in range(1,n+5):
    bikkuri[i] = (i * bikkuri[i-1])%mod
gyaku[n+3]=
for i in range(n+4, -1, -1)
    gyaku[i]=pow(bikkuri[i], mod-2, mod)
def comb(a,b):
    return bikkuri[a]*gyaku[b]*gyaku[a-b]
ans=(2**n)-1-comb(n,a)-comb(n,b)
print(ans%mod)

Fixed submission:
n,a,b=map(int,input().split())
mod=10**9+7
bunbo=1
bunshi=1
for i in range(1,max(a+1, b+1)):
    bunbo*=i
    bunshi*=n-i+1
    bunshi%=mod
    bunbo%=mod
    if i==a:
        comba=bunshi*(pow(bunbo,mod-2,mod))
    if i==b:
        combb=bunshi*(pow(bunbo,mod-2,mod))
print((2**n-1-comba-combb)%mod)
Buggy python submission (verdict: Runtime Error):
a,p,b,q=map(int,input().split())

n=2*(10**6)+1
mod=10**9+7
kaidan=[1]*(n+1)
gyaku=[1]*(n+1)
for i in range(1,n+1):
    kaidan[i]=i*kaidan[i-1]%mod
    gyaku[i]=pow(kaidan[i],mod-2,mod)
def comb(n,r):
    if n-r>=0 and n>=0 and r>=0:
        return (kaidan[n]*gyaku[n-r]*gyaku[r])%mod
    else:
        return 0

def ans(a,b):
    return comb(a+b+2,a+1) -(a+b+2) 

print((ans(b,q)-ans(b,p-1)-ans(a-1,q)+ans(a-1,p-1))%mod)

Fixed submission:
a,p,b,q=map(int,input().split())

n=2*(10**6)+3
mod=10**9+7
kaidan=[1]*(n+1)
gyaku=[1]*(n+1)
for i in range(1,n+1):
    kaidan[i]=i*kaidan[i-1]%mod
    gyaku[i]=pow(kaidan[i],mod-2,mod)
def comb(n,r):
    if n-r>=0 and n>=0 and r>=0:
        return (kaidan[n]*gyaku[n-r]*gyaku[r])%mod
    else:
        return 0

def ans(a,b):
    return comb(a+b+2,a+1) -(a+b+2) 

print((ans(b,q)-ans(b,p-1)-ans(a-1,q)+ans(a-1,p-1))%mod)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
h,n=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(n)]
#i-1番目までの魔法で、j以上のだめを得与えるのに最低限必要な魔力
infi=10**12
dp=[[infi]*(h+1) for i in range(n+1)]
#shoki化
for i in range(n+1):
    dp[i][0]=0
for i in range(n):
    if AB[i][0]+1<h+1:
        for j in range(AB[i][0]+1):
            dp[i+1][j]=min(dp[i][j], AB[i][1])
        for j in range(AB[i][0]+1, h+1):
            dp[i+1][j]=min(dp[i][j], dp[i+1][j-AB[i][0]]+AB[i][1])
    else:
        for j in range(AB[i][0]+1):
            dp[i+1][j]=min(dp[i][j], AB[i][1])
print(dp[n][h])

Fixed submission:
import sys
input = sys.stdin.readline
h,n=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(n)]
#i-1番目までの魔法で、j以上のだめを得与えるのに最低限必要な魔力
infi=10**12
dp=[[infi]*(h+1) for i in range(n+1)]
#shoki化
for i in range(n+1):
    dp[i][0]=0
for i in range(n):
    if AB[i][0]+1<h+1:
        for j in range(AB[i][0]+1):
            dp[i+1][j]=min(dp[i][j], AB[i][1])
        for j in range(AB[i][0]+1, h+1):
            dp[i+1][j]=min(dp[i][j], dp[i+1][j-AB[i][0]]+AB[i][1])
    else:
        for j in range(h+1):
            dp[i+1][j]=min(dp[i][j], AB[i][1])
print(dp[n][h])
Buggy python submission (verdict: Runtime Error):
#sになるのがちょうどk個
n,k,s=map(int,input().split())
ans=0
n_max=10**5
ans=[0]*n
moto=[]
detarame=10**5-1
if s<n:
    ans = [n]*k +[n+1]*(n-k)
    print(ans)
else:
    flag=0
    remain=s
    for i in range(n):
        moto.append(min(n_max,remain))
        if moto[-1]<n_max:
            flag=1
            break
        remain-=moto[-1]
    nagasa=len(moto)
    for i in range(nagasa+k-1):
        ans[i]=moto[i%nagasa]
    for i in range(nagasa+k-1,n):
        ans[i]=detarame
    print(ans)

Fixed submission:
#sになるのがちょうどk個
n,k,s=map(int,input().split())
ans=[0]*n
if s==10**9:
    ans = [s]*k +[10**9-1]*(n-k)
else:
    ans = [s]*k + [10**9]*(n-k)
print(*ans, sep=' ')
Buggy python submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
if k>=0 and k <=a:
  print(a-k,b)
elif k>a, k<=a+b:
  print(0, b-(k-a))
else:
  print(0,0)

Fixed submission:
a,b,k=map(int,input().split())
if k>=0 and k <=a:
  print(a-k,b)
elif k>a and k<=a+b:
  print(0, b-(k-a))
else:
  print(0,0)