Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03525 (python)

Fixed submission:
def main():
    N = int(input())
    D = [int(i) for i in input().split()]
    ans = 0
    cnt = [0]*24
    from collections import Counter
    c = Counter(D)
    cnt[0] = 1
    s = [0]*13
    for k, v in c.items():
        if v >= 3 or k == 0:
            ans = 0
            return print(ans)
        elif v >= 2:
            cnt[k] += 1
            cnt[24 - k] += 1
        elif k == 12:
            cnt[12] += v
        else:
            s[k] += 1
    if any(c >= 2 for c in cnt):
        return print(0)
    for bit in range(1 << 11):
        cur = cnt[:]
        for i in range(11):
            if s[i+1]:
                if bit & (1 << i):
                    cur[24 - (i+1)] += 1
                else:
                    cur[i+1] += 1
        if any(c >= 2 for c in cnt):
            continue
        pre = 0
        mi = 24
        for i, ne in enumerate(cur[1:] + [1], start=1):
            if ne:
                if i - pre < mi:
                    mi = i - pre
                pre = i
        if mi != 24:
            ans = max(ans, mi)
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    _ = int(input())
    D = [int(i) for i in input().split()]
    ans = 0
    cnt = [0]*24
    from collections import Counter
    c = Counter(D)
    cnt[0] = 1
    s = [0]*13
    for k, v in c.items():
        if v >= 3:
            ans = 0
            return print(ans)
        elif v >= 2:
            cnt[k] += 1
            cnt[24 - k] += 1
        elif k == 0 or k == 12:
            cnt[k] += 1
        else:
            s[k] += 1
    if any(c >= 2 for c in cnt):
        return print(0)
    for bit in range(1 << 11):
        cur = cnt[:]
        for i in range(11):
            if s[i+1]:
                if bit & (1 << i):
                    cur[24 - (i+1)] += 1
                else:
                    cur[i+1] += 1
        pre = 0
        mi = 24
        for i, ne in enumerate(cur[1:] + [1], start=1):
            if ne:
                if i - pre < mi:
                    mi = i - pre
                pre = i
        ans = max(ans, mi)
    print(ans)


if __name__ == '__main__':
    main()
Problem p03612 (python)

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


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    P = [int(i) for i in input().split()]
    ans = 0
    for i in range(N):
        if i+1 == P[i]:
            P[i], P[i+1] = P[i+1], P[i]
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()
Problem p03627 (python)

Fixed submission:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    if (c.most_common()[0][1] < 2 or c.most_common()[1][1] < 2) \
            and c.most_common()[0][1] < 4:
        return print(0)
    d = [i[0] for i in c.items() if i[1] >= 2]
    if d:
        d.sort()
    e = [i[0] for i in c.items() if i[1] >= 4]
    if e:
        e.sort()
    if d and e:
        print(max(d[-1] * d[-2], e[-1]*e[-1]))
    elif d:
        print(d[-1] * d[-2])
    else:
        print(e[-1]*e[-1])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    if (c.most_common()[0][1] < 2 or c.most_common()[1][1] < 2) \
            and c.most_common()[0][1] < 4:
        return print(0)
    d = [i[0] for i in c.items() if i[1] >= 2]
    d.sort()
    e = [i[0] for i in c.items() if i[1] >= 4]
    e.sort()
    print(max(d[-1] * d[-2], e[-1]*e[-1]))


if __name__ == '__main__':
    main()
Problem p03695 (python)

Fixed submission:
from bisect import bisect
def grade(rate,breakpoints=[400,800,1200,1600,2000,2400,2800,3200],grades=["gray","brown","green","light blue","blue","yellow","orange","red","anything"]):
    i = bisect(breakpoints,rate)
    return grades[i]

n = int(input())
a = [int(i) for i in input().split()]
colors = [grade(r) for r in a]
anything_count = colors.count("anything")
ans = len(set(colors))
print(*(ans,ans) if anything_count == 0 else (ans-1+(1 if ans == 1 else 0),ans-1+anything_count))

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    cnt = [0]*9
    for a in A:
        cnt[a//400] += 1
    ans = sum(int(a > 0) for a in cnt[:-1])
    print(ans, ans+cnt[-1])


if __name__ == '__main__':
    main()
Problem p03703 (python)

Fixed submission:
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


def main():
    import sys
    read = sys.stdin.read
    N, K = (int(i) for i in input().split())
    A = [int(s) for s in read().rstrip().split('\n')]
    from itertools import accumulate
    S = list(accumulate([0] + A))
    B = [s - K*i for i, s in enumerate(S)]
    c = {b: i+1 for i, b in enumerate(sorted(set(B)))}
    f = Bit(N+1)
    ans = 0
    for j in range(N+1):
        ans += f.sum(c[B[j]])
        f.add(c[B[j]], 1)
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


def main():
    import sys
    read = sys.stdin.read
    N, K = (int(i) for i in input().split())
    A = [int(s) for s in read().rstrip().split('\n')]
    from itertools import accumulate
    S = list(accumulate([0] + A))
    B = [s - K*i for i, s in enumerate(S)]
    c = {b: i+1 for i, b in enumerate(sorted(set(B)))}
    f = Bit(N)
    ans = 0
    for j in range(N+1):
        ans += f.sum(c[B[j]])
        f.add(c[B[j]], 1)
    print(ans)


if __name__ == '__main__':
    main()
Problem p04020 (python)

Fixed submission:
def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    ans = 0
    for i in range(n):
        if a[i] == 0:
            continue
        ans += a[i]//2
        if i != n-1 and a[i]&1 and a[i+1] != 0:
            ans += 1
            a[i+1] -= 1
    print(ans)
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    ans = 0
    changing = [a[0]]
    direct_flag = False #False > True <
    for i in range(1,n):
        if len(changing) == 1:
            changing.append(a[i])
            if changing[0] < changing[1]:
                direct_flag = True
        else:
            if direct_flag and changing[-1] < a[i]:
                changing.append(a[i])
            elif not direct_flag and changing[-1] > a[i]:
                changing.append(a[i])
            else:
                m = len(changing)
                iterange = (range(m) if direct_flag else range(m)[::-1])
                for j in iterange:
                    if j != 0:
                        makable = min(changing[j-1],changing[j])
                        ans += makable
                        changing[j-1] -= makable
                        changing[j] -= makable
                    if j != m-1:
                        makable = min(changing[j],changing[j+1])
                        ans += makable
                        changing[j] -= makable
                        changing[j+1] -= makable
                    if changing[j] >= 2:
                        makable = changing[j] // 2
                        ans += makable
                        changing[j] -= makable * 2
                changing = [a[i]]
                direct_flag = False
        if i == n-1:
            if len(changing) == 1:
                ans += changing[0] // 2
            else:
                iterange = (range(m) if direct_flag else range(m)[::-1])
                for j in iterange:
                    if j != 0:
                        makable = min(changing[j-1],changing[j])
                        ans += makable
                        changing[j-1] -= makable
                        changing[j] -= makable
                    if j != m-1:
                        makable = min(changing[j],changing[j+1])
                        ans += makable
                        changing[j] -= makable
                        changing[j+1] -= makable
                    if changing[j] >= 2:
                        makable = changing[j] // 2
                        ans += makable
                        changing[j] -= makable * 2
    print(ans)
if __name__ == "__main__":
    main()
Problem p02789 (python)

Fixed submission:
N, M = map(int, input().split())
if N == M:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
print("Yes" if A==B else "No)
Problem p03206 (python)

Fixed submission:
print(["Christmas Eve Eve Eve", "Christmas Eve Eve", "Christmas Eve", "Christmas"][int(input())-22])

Buggy submission (verdict: Runtime Error):
print(["Christmas Eve Eve Eve", "Christmas Eve Eve", "Christmas Eve", "Christmas"][int(input())+22])
Problem p03477 (python)

Fixed submission:
a, b, c, d = map(int, input().split())
if a + b > c + d:
  print('Left')
elif a + b == c + d:
  print('Balanced')
else:
  print('Right')

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
if a + b > c + d: print('Left')
elif a + b == c + d: print('Balanced')
else print('Right')

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
if (a + b > c + d) print('Left')
elif (a + b == c + d) print('Balanced')
else print('Right')
Problem p03501 (python)

Fixed submission:
n,a,b=map(int,input().split())
print(min(n*a,b))

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
print(min(n*A,B))
Problem p03563 (python)

Fixed submission:
print(-int(input())+2*int(input()))

Buggy submission (verdict: Runtime Error):
print(-int(input()+2*int(input()))
Problem p03738 (python)

Fixed submission:
A, B = int(input()), int(input())
if A > B:
    print('GREATER')
elif A < B:
    print('LESS')
else:
    print('EQUAL')

Buggy submission (verdict: Runtime Error):
A, B = int(input())
if A > B:
    print('GREATER')
elif A < B:
    print('LESS')
else:
    print('EQUAL')
Problem p02609 (python)

Fixed submission:
import collections
memo = collections.defaultdict(int)
memo[0] = 0
memo[1] = 1


def f(x):
    if x in memo:
        return memo[x]
    else:
        y = x % bin(x).count('1')
        ret = 1 + f(y)
        memo[x] = ret
        return ret


N = int(input())
sX = input()
modX = sX.count('1')
if modX == 0:
    for _ in range(N):
        print(1)
elif modX == 1:
    sX = sX[::-1]
    for i, b in enumerate(sX):
        if b == '1':
            break
    #print(i)
    if i == 0:
        ans = [0] + [2] * (N - 1)
        ans = ans[::-1]
    else:
        ans = [1] * N
        ans[-1] = 2
        ans[-i - 1] = 0
    print('\n'.join(map(str, ans)))
else:
    modp = modX + 1
    modm = modX - 1
    sX = sX[::-1]
    Xmodp = 0
    Xmodm = 0
    for i, b in enumerate(sX):
        if b == '1':
            Xmodp += pow(2, i, modp)
            Xmodp %= modp
            Xmodm += pow(2, i, modm)
            Xmodm %= modm
    s = []
    for i, b in enumerate(sX):
        if b == '1':
            s += [(Xmodm - pow(2, i, modm)) % modm]
        else:
            s += [(Xmodp + pow(2, i, modp)) % modp]
    ans = []
    for k in s[::-1]:
        ans += [1 + f(k)]
    print('\n'.join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
import collections
N = int(input())
sX = input()
modX = sX.count('1')
modp = modX + 1
modm = modX - 1
sX = sX[::-1]
Xmodp = 0
Xmodm = 0
for i, b in enumerate(sX):
    if b == '1':
        Xmodp += pow(2, i, modp)
        Xmodp %= modp
        Xmodm += pow(2, i, modm)
        Xmodm %= modm
s = []
for i, b in enumerate(sX):
    if b == '1':
        s += [(Xmodm - pow(2, i, modm)) % modm]
    else:
        s += [(Xmodp + pow(2, i, modp)) % modp]
t = s[::-1]

memo = collections.defaultdict(int)
memo[0] = 0


def f(x):
    if x in memo:
        return memo[x]
    else:
        y = x % bin(x).count('1')
        ret = 1 + f(y)
        memo[x] = ret
        return ret


ans = []
for k in t:
    ans += [1 + f(k)]
print('\n'.join(map(str, ans)))
Problem p02616 (python)

Fixed submission:
import itertools


def out(X):
    return list(itertools.accumulate(X, func=lambda x, y: x * y % mod))[-1]


N, K = [int(_) for _ in input().split()]
A = sorted([int(_) for _ in input().split()], key=lambda x: -abs(x))
mod = 10**9 + 7
cnt = 0
ipos = ineg = -1
for i, a in enumerate(A[:K]):
    if a < 0:
        cnt += 1
        ineg = i
    else:
        ipos = i
if cnt % 2 == 0:
    print(out(A[:K]))
else:
    oneg = opos = -10**10
    for i, a in enumerate(A[K:]):
        if a < 0 and ipos != -1:
            X = A[:ipos] + A[ipos + 1:K] + [A[K + i]]
            oneg = out(X)
            beforeneg = A[ipos]
            afterneg = A[K + i]
            ipos = -1
        elif a > 0 and ineg != -1:
            Y = A[:ineg] + A[ineg + 1:K] + [A[K + i]]
            opos = out(Y)
            beforepos = A[ineg]
            afterpos = A[K + i]
            ineg = -1
    if oneg != -10**10 and opos != -10**10:
        #afterneg/beforeneg > afterpos>beforepos
        if afterneg * beforepos > afterpos * beforeneg:
            print(oneg)
        else:
            print(opos)
    elif oneg != -10**10 or opos != -10**10:
        print(max(opos, oneg))
    else:
        C = A[::-1]
        print(out(C[:K]))

Buggy submission (verdict: Runtime Error):
import itertools


def out(X):
    return list(itertools.accumulate(X, func=lambda x, y: x * y % mod))[-1]


N, K = [int(_) for _ in input().split()]
A = sorted([int(_) for _ in input().split()], key=lambda x: -abs(x))
mod = 10**9 + 7
cnt = 0
ipos = ineg = -1
for i, a in enumerate(A[:K]):
    if a < 0:
        cnt += 1
        ineg = i
    else:
        ipos = i
if cnt % 2 == 0:
    print(out(A[:K]))
else:
    oneg = opos = -10**10
    for i, a in enumerate(A[K:]):
        if a < 0 and ipos != -1:
            X = A[:ipos] + A[ipos + 1:K] + A[K + i]
            oneg = out(X)
            ipos = -1
        elif a > 0 and ineg != -1:
            X = A[:ineg] + A[ineg + 1:K] + A[K + i]
            opos = out(X)
            ineg = -1
    if oneg != -10**10 or opos != -10**10:
        print(max(opos, oneg))
    else:
        C = A[::-1]
        print(out(C[:K]))

Buggy submission (verdict: Runtime Error):
import itertools, operator


def out(X):
    print(list(itertools.accumulate(X, func=lambda x, y: x * y % mod))[-1])
    exit()


N, K = [int(_) for _ in input().split()]
A = sorted([int(_) for _ in input().split()], key=lambda x: -abs(x))
mod = 10**9 + 7
cnt = 0
ipos = ineg = -1
for i, a in enumerate(A[:K]):
    if a < 0:
        cnt += 1
        ineg = i
    else:
        ipos = i
if cnt % 2 == 0:
    out(A[:K])
else:
    for i, a in enumerate(A[K:]):
        if a < 0 and ipos != -1:
            X = A[:ipos] + A[ipos + 1:K] + A[K + i]
            out(X)
        elif a > 0 and ineg != -1:
            X = A[:ineg] + A[ineg + 1:K] + A[K + i]
            out(X)
    else:
        C = A[::-1]
        cnt = 0
        out(C[:K])
Problem p02632 (python)

Fixed submission:
def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10**9 + 7  #出力の制限
N = 2000005
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  #逆元テーブル
inverse = [0, 1]  #逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

K = int(input())
S = len(input())
ans = 0
for i in range(S, S + K + 1):
    ans += cmb(S + K, i, mod) * pow(25, K + S - i, mod)
    ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


mod = 10**9 + 7  #出力の制限
N = 300000
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  #逆元テーブル
inverse = [0, 1]  #逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

K = int(input())
S = len(input())
ans = 0
for i in range(S, S + K + 1):
    ans += cmb(S + K, i, mod) * pow(25, K + S - i, mod)
    ans %= mod
print(ans)
Problem p02663 (python)

Fixed submission:
a, b, c, d, e = [int(_) for _ in input().split()]
print(c * 60 + d - a * 60 - b - e)

Buggy submission (verdict: Runtime Error):
import itertools
N = int(input())
A = [int(_) for _ in input().split()]
if A[0] != 0:
    if N == 0 and A[0] == 1:
        print(1)
    else:
        print(-1)
    exit()
ans = 1
n = 1
if A[0] > 1:
    print(-1)
    exit()
cumr = list(itertools.accumulate(A[::-1]))[::-1]
for i in range(1, N):
    minn = n - A[i - 1]
    n = min(2 * (n - A[i - 1]), cumr[i])
    ans += n
    if 0 <= minn <= n:
        continue
    print(-1)
    exit()
if n <= A[-1] <= 2 * n:
    ans += A[-1]
    print(ans)
else:
    print(-1)
    exit()
Problem p02686 (python)

Fixed submission:
def Yes():
    print('Yes')
    exit()


def No():
    print('No')
    exit()


def parse(s):
    ret = [0, 0]
    for c in s:
        if c == ')':
            if ret[0]:
                ret[0] -= 1
            else:
                ret[1] -= 1
        else:
            ret[0] += 1
    return ret


N = int(input())
S = [parse(input()) for _ in range(N)]
S.sort(key=lambda a: -a[0] - a[1])
S1 = sorted([s for s in S if s[0] + s[1] >= 0], key=lambda a: -a[1])
S2 = sorted([s for s in S if s[0] + s[1] < 0], key=lambda a: -a[0])
cnt = 0
for s in S1:
    cnt += s[1]
    if cnt < 0:
        No()
    cnt += s[0]
for s in S2:
    cnt += s[1]
    if cnt < 0:
        No()
    cnt += s[0]
if cnt:
    No()
Yes()

Buggy submission (verdict: Runtime Error):
def Yes():
    print('Yes')
    exit()


def No():
    print('No')
    exit()


def parse(s):
    ret = [0, 0]
    for c in s:
        if c == ')':
            if ret[0]:
                ret[0] -= 1
            else:
                ret[1] -= 1
        else:
            ret[0] += 1
    return ret


import numpy as np
N = int(input())
S = [parse(input()) for _ in range(N)]
#a[0]+a[1]が大きい順に並べる
S.sort(key=lambda a: -a[0] - a[1])
#この中でa[1]が耐えられるものを貪欲にかき集める
#集められなくなったら終了


class SegmentTree():
    def __init__(self, array, f, ti):
        """
        Parameters
        ----------
        array : list
            to construct segment tree from
        f : func
            binary operation of the monoid
        ti : 
            identity element of the monoid
        """
        self.f = f
        self.ti = ti
        self.n = n = 2**(len(array).bit_length())
        self.dat = dat = [ti] * n + array + [ti] * (n - len(array))
        for i in range(n - 1, 0, -1):  # build
            dat[i] = f(dat[i << 1], dat[i << 1 | 1])

    def update(self, p, v):  # set value at position p (0-indexed)
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = v
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])

    def query(self, l, r):  # result on interval [l, r) (0-indexed)
        f, ti, n, dat = self.f, self.ti, self.n, self.dat
        res = ti
        l += n
        r += n
        while l < r:
            if l & 1:
                res = f(res, dat[l])
                l += 1
            if r & 1:
                r -= 1
                res = f(dat[r], res)
            l >>= 1
            r >>= 1
        return res


def f(x, y):
    return y if y[2] + cnt >= 0 else x


cnt = 0
ti = (10**10, 0, -10**10)
st = SegmentTree([(i, a[0], a[1]) for i, a in enumerate(S)], f=f, ti=ti)
for _ in range(N):
    x = st.query(0, N)
    if x[2] + cnt < 0:
        No()
    cnt += x[1] + x[2]
    st.update(x[0], ti)
if cnt == 0:
    Yes()
else:
    No()
Problem p02716 (python)

Fixed submission:
import collections, sys
sys.setrecursionlimit(100005)
N = int(input())
A = [int(_) for _ in input().split()]
INF = float('inf')
memo = collections.defaultdict(lambda: INF)


def c(start, res):
    if memo[start, res] != INF:
        return memo[start, res]
    elif 2 * res - 1 > N - start:
        memo[start, res] = -INF
    elif start >= N:
        memo[start, res] = -INF
    elif res > 1:
        memo[start, res] = max(A[start] + c(start + 2, res - 1),
                               c(start + 1, res), c(start + 2, res))
    else:
        memo[start, res] = max(A[start], c(start + 1, res))
    return memo[start, res]


print(c(0, N // 2))

Buggy submission (verdict: Runtime Error):
import collections
N = int(input())
A = [int(_) for _ in input().split()]
INF = float('inf')
memo = collections.defaultdict(lambda: INF)


def c(start, res):
    if memo[start, res] != INF:
        return memo[start, res]
    elif start >= N:
        memo[start, res] = -INF
    elif res > 1:
        memo[start, res] = max(A[start] + c(start + 2, res - 1),
                               c(start + 1, res), c(start + 2, res))
    else:
        memo[start, res] = A[start]
    return memo[start, res]


print(c(0, N // 2))
Problem p02782 (python)

Fixed submission:
r, c, R, C = [int(_) for _ in input().split()]
mod = 10**9 + 7

f = [1] * (3 * 10**6 + 10)
for i in range(1, 3 * 10**6 + 10):
    f[i] = i * f[i - 1] % mod
fi = {}


def comb(n, r):
    if r not in fi:
        fi[r] = pow(f[r], mod - 2, mod)
    if n - r not in fi:
        fi[n - r] = pow(f[n - r], mod - 2, mod)
    return (f[n] * fi[r] * fi[n - r]) % mod


a1 = (C + 2) * f[c + 1] * f[C + R + 2] - (c + 1) * f[C + 2] * f[c + R + 1]
a1 *= pow(R + 1, mod - 2, mod) * pow(f[c + 1], mod - 2, mod) * pow(
    f[C + 2], mod - 2, mod) * pow(f[R], mod - 2, mod)
a2 = (C + 2) * f[c + 1] * f[C + r + 1] - (c + 1) * f[C + 2] * f[c + r]
a2 *= pow(r, mod - 2, mod) * pow(f[c + 1], mod - 2, mod) * pow(
    f[C + 2], mod - 2, mod) * pow(f[r - 1], mod - 2, mod)
ans = a1 - a2
ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
r1, c1, r2, c2 = [int(_) for _ in input().split()]
mod = 10**9 + 7

f = [1] * (10**6 + 1)
for i in range(1, 10**6 + 1):
    f[i] = i * f[i - 1] % mod
fi = {}


def comb(n, r):
    if r not in fi:
        fi[r] = pow(f[r], mod - 2, mod)
    if n - r not in fi:
        fi[n - r] = pow(f[n - r], mod - 2, mod)
    return (f[n] * fi[r] * fi[n - r]) % mod


ans = 0
for x in range(c1, c2 + 1):
    ans += comb(r2 + x + 1, x + 1) - comb(r1 + x, x + 1)
    ans %= mod
print(ans)
Problem p02787 (python)

Fixed submission:
H, N = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for _ in range(N)]
dp = [float('inf')] * 10001
dp[0] = 0
for a, b in AB:
    for i in range(10001 - a):
        dp[i + a] = min(dp[i + a], dp[i] + b)
print(min(dp[H:]))

Buggy submission (verdict: Runtime Error):
H, N = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for _ in range(N)]
dp = [float('inf')] * 10**4
dp[0] = 0
for a, b in AB:
    for i in range(10**4 - a):
        dp[i + a] = min(dp[i + a], dp[i] + b)
print(min(dp[H:]))