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

N, A, B, K = map(int, input().split())
if K == 0:
    print(1)
    exit()
c = gcd(A, B)
if K % c != 0:
    print(0)
    exit()
A //= c; B //= c; K //= c
mod = 998244353

fact = [1] * (N+1)
fact_inv = [1] * (N+1)
for i in range(1, N+1):
    fact[i] = i * fact[i-1] % mod
fact_inv[N] = pow(fact[N], mod-2, mod)
for i in range(1, N+1)[::-1]:
    fact_inv[i-1] = i * fact_inv[i] % mod


ans = 0
for x in range(N+1):
    if (K - A * x) % B != 0:
        continue
    y = (K - A * x) // B
    tmp = 0
    for g in range(max(0, x + y - N), min(x, y, N)+1):
        r = x - g
        b = y - g
        if r < 0 or b < 0:
            break
        tmp = (tmp + fact_inv[r] * fact_inv[b] * fact_inv[g] * fact_inv[N - r - g - b]) % mod
    ans = (ans + tmp) % mod
ans = ans * fact[N] % mod
print(ans)

Fixed submission:
from fractions import gcd

N, A, B, K = map(int, input().split())
if K == 0:
    print(1)
    exit()
c = gcd(A, B)
if K % c != 0:
    print(0)
    exit()
A //= c; B //= c; K //= c
mod = 998244353

fact = [1] * (N+1)
fact_inv = [1] * (N+1)
for i in range(1, N+1):
    fact[i] = i * fact[i-1] % mod
fact_inv[N] = pow(fact[N], mod-2, mod)
for i in range(1, N+1)[::-1]:
    fact_inv[i-1] = i * fact_inv[i] % mod
comb = lambda n, k: fact[n] * fact_inv[k] * fact_inv[n-k] % mod

ans = 0
for x in range(N+1):
    y, r = divmod(K - A * x, B)
    if r != 0:
        continue
    if 0 <= y <= N:
        ans = (ans + comb(N, x) * comb(N, y)) % mod
print(ans)

Buggy python submission (verdict: Runtime Error):
from math import gcd

N, A, B, K = map(int, input().split())
if K == 0:
    print(1)
    exit()
c = gcd(A, B)
if K % c != 0:
    print(0)
    exit()
A //= c; B //= c; K //= c
mod = 998244353

fact = [1] * (N+1)
fact_inv = [1] * (N+1)
for i in range(1, N+1):
    fact[i] = i * fact[i-1] % mod
fact_inv[N] = pow(fact[N], mod-2, mod)
for i in range(1, N+1)[::-1]:
    fact_inv[i-1] = i * fact_inv[i] % mod


ans = 0
for x in range(N+1):
    if (K - A * x) % B != 0:
        continue
    y = (K - A * x) // B
    tmp = 0
    for g in range(max(0, x + y - N), min(x, y, N)+1):
        r = x - g
        b = y - g
        if r < 0 or b < 0:
            break
        tmp = (tmp + fact_inv[r] * fact_inv[b] * fact_inv[g] * fact_inv[N - r - g - b]) % mod
    ans = (ans + tmp) % mod
ans = ans * fact[N] % mod
print(ans)

Fixed submission:
from fractions import gcd

N, A, B, K = map(int, input().split())
if K == 0:
    print(1)
    exit()
c = gcd(A, B)
if K % c != 0:
    print(0)
    exit()
A //= c; B //= c; K //= c
mod = 998244353

fact = [1] * (N+1)
fact_inv = [1] * (N+1)
for i in range(1, N+1):
    fact[i] = i * fact[i-1] % mod
fact_inv[N] = pow(fact[N], mod-2, mod)
for i in range(1, N+1)[::-1]:
    fact_inv[i-1] = i * fact_inv[i] % mod
comb = lambda n, k: fact[n] * fact_inv[k] * fact_inv[n-k] % mod

ans = 0
for x in range(N+1):
    y, r = divmod(K - A * x, B)
    if r != 0:
        continue
    if 0 <= y <= N:
        ans = (ans + comb(N, x) * comb(N, y)) % mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
I=input
N=int(I())
X=range(N)
S=[I()for _ in X]
print(sum(all(S[(i+k)%N][j]==S[(j+k)%N][i]for i in X for j in X)for k in X)*N)

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
S = [list(input().rstrip()) for _ in range(N)]
row = [[0] * 26 for _ in range(N)]
col = [[0] * 26 for _ in range(N)]
for i in range(N):
    for j in range(N):
        c = ord(S[i][j]) - ord('a')
        row[i][c] += 1
        col[j][c] += 1
ans = 0
same = [[row[i] == col[j] for j in range(N)] for i in range(N)]
for i in range(N):
    for j in range(N):
        if all(same[(i+k) % N][(j+k) % N] for k in range(N)):
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
if N == 3：
	print(1, 2, 3)
  	exit()
a = []
i = 2
while len(a) < N-N%2-2 and i + 2 <= 30000:
	a.append(i)
    a.append(i+2)
    i += 6
b = []
i = 3
while len(a) + len(b) < N-N%2 and i + 6 <= 30000:
  	b.append(i)
    b.append(i+6)
    i += 12
c = []
i = 6
while len(a) + len(b) + len(c) < N:
  	c.append(i)
    i += 6
print(' '.join(map(str, a+b+c)))


Fixed submission:
N = int(input())
if N == 3:
    print(2, 5, 63)
    exit()
a = []
i = 2
while len(a) < N-N%2-2 and i + 2 <= 30000:
    a.append(i)
    a.append(i+2)
    i += 6
b = []
i = 3
while len(a) + len(b) < N-N%2 and i + 6 <= 30000:
    b.append(i)
    b.append(i+6)
    i += 12
c = []
i = 6
while len(a) + len(b) + len(c) < N:
    c.append(i)
    i += 6
print(' '.join(map(str, a+b+c)))

Buggy python submission (verdict: Runtime Error):
N = int(input())
if N ＝＝ 3：
	print(1, 2, 3)
  	exit()
a = []
i = 2
while len(a) < N-N%2-2 and i + 2 <= 30000:
	a.append(i)
    a.append(i+2)
    i += 6
b = []
i = 3
while len(a) + len(b) < N-N%2 and i + 6 <= 30000:
  	b.append(i)
    b.append(i+6)
    i += 12
c = []
i = 6
while len(a) + len(b) + len(c) < N:
  	c.append(i)
    i += 6
print(' '.join(map(str, a+b+c)))

Fixed submission:
N = int(input())
if N == 3:
    print(2, 5, 63)
    exit()
a = []
i = 2
while len(a) < N-N%2-2 and i + 2 <= 30000:
    a.append(i)
    a.append(i+2)
    i += 6
b = []
i = 3
while len(a) + len(b) < N-N%2 and i + 6 <= 30000:
    b.append(i)
    b.append(i+6)
    i += 12
c = []
i = 6
while len(a) + len(b) + len(c) < N:
    c.append(i)
    i += 6
print(' '.join(map(str, a+b+c)))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


def check(arr, x):
    s = sum(arr)
    if (s+x) % 2 == 1:
        return False
    target = (s+x) // 2
    dp = [False] * (target+1)
    dp[0] = True
    for a in arr:
        for i in range(a, target+1):
            dp[i] = dp[i-a]
    return dp[-1]


s = input().rstrip() + 'T'
x, y = map(int, input().split())
X = []
Y = []
xy = 0
f_count = 0
for c in s:
    if c == 'T':
        if xy == 0:
            X.append(f_count)
        else:
            Y.append(f_count)
        f_count = 0
        xy = 1 - xy
    else:
        f_count += 1
x -= X[0]
X.pop(0)
if check(X, x) and check(Y, y):
    print('Yes')
else:
    print('No')


Fixed submission:
def check(arr, x):
    pos = set([0])
    for dx in arr:
        npos = set()
        for p in pos:
            npos.add(p+dx)
            npos.add(p-dx)
        pos = npos
    return x in pos


s = input().split('T')
x, y = map(int, input().split())
d = [len(ss) for ss in s]
dx = d[2::2]
dy = d[1::2]
x -= d[0]
if check(dx, x) and check(dy, y):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
# 100(aA + bB) + cC + dD <= F
# cC + dD <= (aA + bB)E
# maximize 100(cD + dD) / (100(aA + bB) + cC + dD)

A, B, C, D, E, F = map(int, input().split())
concentration = 0
ans = None
for a in range(31):
    for b in range(31):
        water = 100*(a*A + b*B)
        if water > F:
            break
        for c in range(3001):
            for d in range(3001):
                sugar = c*C + d*D
                if water + sugar == 0:
                    continue
                if water + sugar > F:
                    break
                if sugar > water // 100 * E:
                    break
                conc = 100*sugar / (water + sugar)
                if concentration < conc:
                    concentration = conc
                    ans = (water + sugar, sugar)
print(ans[0], ans[1])


Fixed submission:
# 100(aA + bB) + cC + dD <= F
# cC + dD <= (aA + bB)E
# maximize 100(cD + dD) / (100(aA + bB) + cC + dD)

A, B, C, D, E, F = map(int, input().split())
concentration = -1
ans = (0, 0)
for a in range(31):
    for b in range(31):
        water = 100*(a*A + b*B)
        if water > F:
            break
        for c in range(3001):
            for d in range(3001):
                sugar = c*C + d*D
                if water + sugar == 0:
                    continue
                if water + sugar > F:
                    break
                if sugar > water // 100 * E:
                    break
                conc = 100*sugar / (water + sugar)
                if concentration < conc:
                    concentration = conc
                    ans = (water + sugar, sugar)
print(ans[0], ans[1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
    x, y = map(lambda x: int(x) - 1, input().split())
    G[x].append(y)
    G[y].append(x)

nim = [0] * N

def dfs(v, p):
    for c in G[v]:
        if c != p:
            dfs(c, v)
            nim[v] ^= nim[c]
    nim[v] += 1

dfs(0, -1)
print('Alice' if nim[0] > 1 else 'Bob')

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N-1):
    x, y = map(lambda x: int(x) - 1, input().split())
    G[x].append(y)
    G[y].append(x)

nim = [0] * N

def dfs(v, p):
    for c in G[v]:
        if c != p:
            dfs(c, v)
            nim[v] ^= nim[c]
    nim[v] += 1

dfs(0, -1)
print('Alice' if nim[0] > 1 else 'Bob')
Buggy python submission (verdict: Runtime Error):
H, W, h, w = map(int, input().split())
if H % h == 0 and W % h == 0:
    print('No')
    exit()
rem = H * W - (H - H % h) * (W - W % w)
x = (H // h * W // w) // rem + 1
a = [[x] * W for _ in range(H)]
for i in range(h-1, H, h):
    for j in range(w-1, W, w):
        a[i][j] = -(h * w - 1) * x - 1
print('Yes')
for row in a:
    print(*row)


Fixed submission:
H, W, h, w = map(int, input().split())
rem = H * W - (H - H % h) * (W - W % w)
if rem == 0:
    print('No')
    exit()
x = (H // h * W // w + rem) // rem
if abs(x) > 10**9 or abs(-(h * w - 1) * x - 1) > 10**9:
    print('No')
    exit()
print('Yes')
a = [[x] * W for _ in range(H)]
for i in range(h-1, H, h):
    for j in range(w-1, W, w):
        a[i][j] = -(h * w - 1) * x - 1
for row in a:
    print(*row)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = input()

for bit in range(4):
    animal = [-1] * N
    animal[0] = bit % 2
    animal[1] = bit // 2
    for i in range(1, N-1):
        if (animal[i] == 0) ^ (s[i] == 'o'):
            animal[i+1] = 1 - animal[i-1]
        else:
            animal[i+1] = animal[i-1]
    ok = True
    if animal[-1] == 0:
        if (s[-1] == 'o') ^ (animal[-2] == animal[0]):
            ok = False
    if animal[-1] == 1:
        if (s[-1] == 'o') ^ (animal[-2] != animal[0]):
            ok = False
    if animal[0] == 0:
        if (s[0] == 'o') ^ (animal[-1] == animal[1]):
            ok = False
    if animal[0] == 1:
        if (s[0] == 'o') ^ (animal[-1] != animal[1]):
            ok = False
    if ok:
        ans = ''
        for i in range(N):
            ans += 'S' if animal[i] == 0 else 'W'
        print(ans)
        exit()
print(-1)


Fixed submission:
N = int(input())
s = input()

for bit in range(4):
    animal = [-1] * N
    animal[0] = bit % 2
    animal[1] = bit // 2
    for i in range(1, N-1):
        if (animal[i] == 0) ^ (s[i] == 'o'):
            animal[i+1] = 1 - animal[i-1]
        else:
            animal[i+1] = animal[i-1]
    ok = True
    if animal[-1] == 0:
        if (s[-1] == 'o') ^ (animal[-2] == animal[0]):
            ok = False
    if animal[-1] == 1:
        if (s[-1] == 'o') ^ (animal[-2] != animal[0]):
            ok = False
    if animal[0] == 0:
        if (s[0] == 'o') ^ (animal[-1] == animal[1]):
            ok = False
    if animal[0] == 1:
        if (s[0] == 'o') ^ (animal[-1] != animal[1]):
            ok = False
    if ok:
        ans = ''
        for i in range(N):
            ans += 'S' if animal[i] == 0 else 'W'
        print(ans)
        exit()
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N = int(input())
s = input().rstrip()
for t in ['SS', 'SW', 'WS', 'WW']:
    for i in range(1, N-1):
        if (t[-1] == 'W') ^ (s[i] == 'o') ^ (t[-2] == 'S'):
            t += 'W'
        else:
            t += 'S'
    if (t[-1] == 'W') ^ (s[-1] == 'o') ^ (t[-2] == t[0]):
        continue
    if (t[0] == 'W') ^ (s[0] == 'o') ^ (t[-1] == t[1]):
        continue
    print(t)
    exit()
print(-1)


Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
s = input().rstrip()
for t in ['SS', 'SW', 'WS', 'WW']:
    for i in range(1, N-1):
        if (t[-1] == 'W') ^ (s[i] == 'o') ^ (t[-2] == 'S'):
            t += 'W'
        else:
            t += 'S'
    if (t[-1] == 'W') ^ (s[-1] == 'o') ^ (t[-2] == t[0]):
        continue
    if (t[0] == 'W') ^ (s[0] == 'o') ^ (t[-1] == t[1]):
        continue
    print(t)
    exit()
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N = int(input())
G = [[] for _ in range(N+1)]
for i in range(2, N+1):
    a = int(input())
    G[a].append(i)

def dfs(v):
    if len(G[v]) == 0:
        return 1
    depth = set()
    for u in G[v]:
        d = dfs(u) + 1
        while d in depth:
            d += 1
        depth.add(d)
    return max(depth)

print(dfs(1) - 1)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N = int(input())
G = [[] for _ in range(N+1)]
for i in range(2, N+1):
    a = int(input())
    G[a].append(i)

def dfs(v):
    if len(G[v]) == 0:
        return 1
    depth = []
    for u in G[v]:
        d = dfs(u) + 1
        depth.append(d)
    depth.sort()
    ret = 0
    for d in depth:
        if ret < d:
            ret = d
        else:
            ret += 1
    return ret

print(dfs(1) - 1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N = int(input())
G = [[] for _ in range(N+1)]
for i in range(2, N+1):
    a = int(input())
    G[a].append(i)

def dfs(v):
    if len(G[v]) == 0:
        return 1
    depth = set()
    for u in G[v]:
        d = dfs(u) + 1
        while d in depth:
            d += 1
        depth.add(d)
    return max(depth)

print(dfs(1) - 1)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N = int(input())
G = [[] for _ in range(N+1)]
for i in range(2, N+1):
    a = int(input())
    G[a].append(i)

def dfs(v):
    if len(G[v]) == 0:
        return 1
    depth = []
    for u in G[v]:
        d = dfs(u) + 1
        depth.append(d)
    depth.sort()
    ret = 0
    for d in depth:
        if ret < d:
            ret = d
        else:
            ret += 1
    return ret

print(dfs(1) - 1)
Buggy python submission (verdict: Time Limit Exceeded):
N, A, B, C, D = map(int, input().split())
mod = 10**9 + 7

fact = [1] * (N+1)
fact_inv = [1] * (N+1)
for i in range(1, N+1):
    fact[i] = i * fact[i-1] % mod
fact_inv[N] = pow(fact[N], mod-2, mod)
for i in range(1, N+1)[::-1]:
    fact_inv[i-1] = i * fact_inv[i] % mod
comb = lambda n, k: fact[n] * fact_inv[k] * fact_inv[n-k] % mod

dp = [0] * (N+1)
dp[0] = 1
for i in range(A, B+1):
    for j in range(N+1)[::-1]:
        for F in range(C, D+1):
            if j + F * i > N:
                break
            dp[j + F * i] += dp[j] * comb(N - j, F * i) * fact[F * i] * pow(pow(fact[i], F, mod) * fact[F], mod - 2, mod) % mod
            dp[j + F * i] %= mod
print(dp[N])

Fixed submission:
N, A, B, C, D = map(int, input().split())
mod = 10**9 + 7

fact = [1] * (N+1)
fact_inv = [1] * (N+1)
for i in range(1, N+1):
    fact[i] = i * fact[i-1] % mod
fact_inv[N] = pow(fact[N], mod-2, mod)
for i in range(1, N+1)[::-1]:
    fact_inv[i-1] = i * fact_inv[i] % mod
comb = lambda n, k: fact[n] * fact_inv[k] * fact_inv[n-k] % mod

dp = [0] * (N+1)
dp[0] = 1
for i in range(A, B+1):
    for j in range(N+1)[::-1]:
        for F in range(C, D+1):
            if j + F * i > N:
                break
            dp[j + F * i] += dp[j] * comb(N - j, F * i) * fact[F * i] * pow(fact_inv[i], F, mod) * fact_inv[F] % mod
            dp[j + F * i] %= mod
print(dp[N])
Buggy python submission (verdict: Runtime Error):
N, x = map(int, input().split())
if x == 1 or x == 2*N-1:
    print('No')
    exit()
print('Yes')
ans = None
if x+2 <= 2*N-1:
    ans = list(range(1, x-1)) + list(range(x+3, 2*N))
    ans = ans[:N-3] + [x+2, x-1, x, x+1] + ans[N-3:]
elif x-2 >= 1:
    ans = list(range(1, x-2)) + list(range(x+2, 2*N))
    ans = ans[:N-3] + [x-2, x+1, x, x-1] + ans[N-3:]
for i in ans:
    print(i)



Fixed submission:
N, x = map(int, input().split())
if x == 1 or x == 2*N-1:
    print('No')
    exit()
print('Yes')
ans = None
if N == 2:
    ans = [1, 2, 3]
elif x+2 <= 2*N-1:
    ans = list(range(1, x-1)) + list(range(x+3, 2*N))
    ans = ans[:N-3] + [x+2, x-1, x, x+1] + ans[N-3:]
else:
    ans = list(range(1, x-2)) + list(range(x+2, 2*N))
    ans = ans[:N-3] + [x-2, x+1, x, x-1] + ans[N-3:]
for i in ans:
    print(i)
Buggy python submission (verdict: Runtime Error):
N, A = map(int, input().split())
x = list(map(int, input().split()))
MAX_J = sum(x)
dp = [[0] * (MAX_J+1) for i in range(N+1)]
dp[0][0] = 1
for n in range(N):
    for i in range(N)[::-1]:
        for j in range(MAX_J-x[n]+1)[::-1]:
            dp[i+1][j+x[n]] += dp[i][j]
ans = 0
for i in range(1, N+1):
    ans += dp[i][A * i]
print(ans)


Fixed submission:
N, A = map(int, input().split())
x = list(map(int, input().split()))
MAX_J = sum(x)
dp = [[0] * (MAX_J+1) for i in range(N+1)]
dp[0][0] = 1
for n in range(N):
    for i in range(N)[::-1]:
        for j in range(MAX_J-x[n]+1)[::-1]:
            dp[i+1][j+x[n]] += dp[i][j]
ans = 0
for i in range(1, N+1):
    if A * i <= MAX_J:
        ans += dp[i][A * i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import log

n = int(input())
s = int(input())
lb, ub = 1, n + 2
while ub - lb > 1:
    b = (lb + ub) // 2
    if s <= (b - 1) * (int(log(n) / log(b)) + 1):
        ub = b
    else:
        lb = b
for b in range(ub, n + 2):
    m = n
    a = 0
    while m:
        a += m % b
        m //= b
    if a == s:
        print(b)
        exit()
print(-1)

Fixed submission:
def divisor(n):
    divisors = []
    i = 1
    while i * i < n:
        if n % i == 0:
            divisors.append(i)
            divisors.append(n // i)
        i += 1
    if i * i == n:
        divisors.append(i)
    divisors.sort()
    return divisors

n = int(input())
s = int(input())
if n == s:
    print(n + 1)
    exit()
if n < s:
    print(-1)
    exit()
sr = int(n ** 0.5)
for b in range(2, sr + 1):
    m = n
    a = 0
    while m:
        a += m % b
        m //= b
    if a == s:
        print(b)
        exit()
for d in divisor(n - s):
    b = d + 1
    if b <= sr:
        continue
    q = (n - s) // d
    r = n % b
    if q + r == s:
        print(b)
        exit()
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N = int(input())
x = list(map(int, input().split()))
L = int(input())
Q = int(input())
for _ in range(Q):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if a > b:
        a, b = b, a
    ans = 1
    i = a
    d = 0
    while i < b:
        if d + x[i+1] - x[i] <= L:
            d += x[i+1] - x[i]
        else:
            ans += 1
            d = x[i+1] - x[i]
        i += 1
    print(ans)


Fixed submission:
from bisect import bisect_right
import sys
input = sys.stdin.readline

N = int(input())
x = list(map(int, input().split()))
L = int(input())
log = 1
while 1 << log < N:
    log += 1
doubling = [[0] * (log + 1) for _ in range(N)]
for i in range(N):
    j = bisect_right(x, x[i] + L) - 1
    doubling[i][0] = j
for l in range(1, log + 1):
    for i in range(N):
        doubling[i][l] = doubling[doubling[i][l-1]][l-1]
Q = int(input())
for _ in range(Q):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if a > b:
        a, b = b, a
    ans = 0
    for l in range(log, -1, -1):
        if doubling[a][l] < b:
            ans += 1 << l
            a = doubling[a][l]
    print(ans + 1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

mod = 10**9 + 7
N, C = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
dp = [0] * (C + 1)
dp[0] = 1
for i in range(N):
    X = [0] * (C + 1)
    for j in range(C+1):
        for k in range(A[i], B[i] + 1):
            X[j] = (X[j] + pow(k, j, mod)) % mod
    ndp = [0] * (C + 1)
    for j in range(C+1):
        for k in range(C+1-j):
            ndp[j + k] = (ndp[j + k] + dp[j] * X[k]) % mod
    dp = ndp
print(dp[C])

Fixed submission:
import sys
input = sys.stdin.readline

mod = 10**9 + 7
N, C = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
dp = [0] * (C + 1)
dp[0] = 1
for i in range(N):
    X = [0] * (C + 1)
    for j in range(A[i], B[i] + 1):
        x = 1
        for k in range(C+1):
            X[k] = (X[k] + x) % mod
            x = x * j % mod
    ndp = [0] * (C + 1)
    for j in range(C+1):
        for k in range(C+1-j):
            ndp[j + k] = (ndp[j + k] + dp[j] * X[k]) % mod
    dp = ndp
print(dp[C])
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input()))
s = a[0]
ans = 0
for i in range(1,n):
  ans += max(0,a[i]-s)
  s = max(s,a[i])
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
s = a[0]
ans = 0
for i in range(1,n):
  ans += max(0,s-a[i])
  s = max(s,a[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,K=map(int,input().split())
p=list(map(lambda x:int(x)-1,input().split()))
c=list(map(int,input().split()))
if K == 1:
    print(max(c));exit()
ans = -10**10
def cycle(k):
    mo=k
    clen=0
    cscore=0
    flg = True
    cmax=[-10**10]
    while (mo != k or flg):
        clen+=1
        cscore+=c[mo]
        mo = p[mo]
        cmax.append(max(cmax[-1],cscore))
        if mo == k:
            flg = False
    if cscore<0:
        return cmax[min(K-1,clen-1)]
    return cscore*((K-1)//clen)+cmax[(K-1)%clen+1]
for i in range(n):
    a=cycle(i)
    if a>ans:
        ans = a
print(ans)


Fixed submission:
s = input()
if "RRR" in s:
  print(3)
elif "RR" in s:
  print(2)
elif "R" in s:
  print(1)
else:
  print(0)