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

Fixed submission:
from collections import deque

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

res = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            continue
        dist = [[-1] * w for _ in range(h)]
        dist[i][j] = 0
        d = deque()
        d.append([i, j])

        while d:
            pos_x, pos_y = d.popleft()
            dist_max = dist[pos_x][pos_y]
            for k in range(4):
                x, y = pos_x + dx[k], pos_y + dy[k]
                if 0 <= x < h and 0 <= y < w and s[x][y] == "." and dist[x][y] == -1:
                    dist[x][y] = dist[pos_x][pos_y] + 1
                    d.append([x, y])

        res = max(res, dist_max)

print(res)

Buggy submission (verdict: Runtime Error):
from collections import deque
import numpy as np

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

res = 0
for i in range(h):
    for j in range(w):
        dist = np.full((h, w), -1)
        dist[i][j] = 0
        d = deque()
        d.append([i, j])

        while len(d) > 0:
            pos_x, pos_y = d.popleft()
            for k in range(4):
                x, y = pos_x + dx[k], pos_y + dy[k]
                if 0 <= x < h and 0 <= y < w and s[x][y] == "." and dist[x][y] == -1:
                    dist[x][y] = dist[pos_x][pos_y] + 1
                    d.append([x, y])

        res = max(res, np.max(dist))

print(res)
Problem p02913 (python)

Fixed submission:
def z_algo(s):
    """Z-algorithm O(|S|)

    Args:
        s (str): 対象文字列
    
    Returns:
        list: lcp配列 (z[i]: sとs[i:]の最長共通接尾辞の長さ)
    """
    n = len(s)
    z = [0] * n
    z[0] = n
    i, j = 1, 0
    while i < n:
        while i + j < n and s[j] == s[i+j]:
            j += 1
        z[i] = j

        if j == 0:
            i += 1
            continue

        k = 1
        while i + k < n and k + z[k] < j:
            z[i+k] = z[k]
            k += 1

        i += k
        j -= k

    return z


n = int(input())
s = input()

res = 0
for i in range(n-1):
    z = z_algo(s[i:])
    for j in range(n-i):
        if z[j] <= j and res < z[j]:
            res = z[j]

print(res)

Buggy submission (verdict: Runtime Error):
def z_algorithm(s):
	"""Z-algorithm O(|S|)
    """
    l = len(s)
    z = [0] * l
    z[0] = l
    i, j = 1, 0
    while i < l:
        while i + j < l and S[j] == S[i+j]:
            j += 1
        z[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while k + z[k] < j:
            z[i+k] = z[k]
            k += 1
        i += k
        j -= k
 
    return z
Problem p02995 (python)

Fixed submission:
import fractions

a, b, c, d = map(int, input().split())

a_c = (a - 1) // c
a_d = (a - 1) // d
a_cd = (a - 1) // (c * d // fractions.gcd(c, d))

b_c = b // c
b_d = b // d
b_cd = b // (c * d // fractions.gcd(c, d))

print((b - b_c - b_d + b_cd) - ((a - 1) - a_c - a_d + a_cd))

Buggy submission (verdict: Runtime Error):
import fractions

a, b, c, d = map(int, input().split())

a_c = (a - 1)//c
a_d = (a - 1) // d
a_cd = (a - 1) // (c * d // math.gcd(c, d))

b_c = b // c
b_d = b // d
b_cd = b // (c * d // math.gcd(c, d))

print((b - b_c - b_d + b_cd) - ((a - 1) - a_c - a_d + a_cd))

Buggy submission (verdict: Runtime Error):
from fractions import gcd

a, b, c, d = map(int, input().split())

a_c = (a - 1) // c
a_d = (a - 1) // d
a_cd = (a - 1) // (c * d // math.gcd(c, d))

b_c = b // c
b_d = b // d
b_cd = b // (c * d // math.gcd(c, d))

print((b - b_c - b_d + b_cd) - ((a - 1) - a_c - a_d + a_cd))

Buggy submission (verdict: Runtime Error):
from fractions import gcd

a, b, c, d = map(int, input().split())

a_c = (a - 1) // c
a_d = (a - 1) // d
a_cd = (a - 1) // (c * d // math.gcd(c, d))

b_c = b // c
b_d = b // d
b_cd = b // (c * d // math.gcd(c, d))

print((b - b_c - b_d + b_cd) - ((a - 1) - a_c - a_d + a_cd))

Buggy submission (verdict: Runtime Error):
import math

a, b, c, d = map(int, input().split())

a_c = (a - 1) // c
a_d = (a - 1) // d
a_cd = (a - 1) // (c * d // math.gcd(c, d))

b_c = b // c
b_d = b // d
b_cd = b // (c * d // math.gcd(c, d))

print((b - b_c - b_d + b_cd) - ((a - 1) - a_c - a_d + a_cd))
Problem p03044 (python)

Fixed submission:
from sys import setrecursionlimit

setrecursionlimit(10 ** 6)

def dfs(now, prev):
    for nxt, w in edge[now]:
        if nxt == prev:
            continue
        
        dist[nxt] = dist[now] + w
        dfs(nxt, now)


n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
    u, v, w = map(int, input().split())
    edge[u-1].append([v-1, w])
    edge[v-1].append([u-1, w])

dist = [0] * n
dfs(0, -1)

for d in dist:
    if d % 2 == 0:
        print(0)
    else:
        print(1)

Buggy submission (verdict: Runtime Error):
def dfs(now, prev):
    for nxt, w in edge[now]:
        if nxt == prev:
            continue
        
        dist[nxt] = dist[now] + w
        dfs(nxt, now)


n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
    u, v, w = map(int, input().split())
    edge[u-1].append([v-1, w])
    edge[v-1].append([u-1, w])

dist = [0] * n
dfs(0, -1)

for d in dist:
    if d % 2 == 0:
        print(0)
    else:
        print(1)
Problem p03061 (python)

Fixed submission:
from fractions import gcd

# 配列aで初期化
def init(a):
    for i in range(n):
        seg[i+num-1] = a[i]    
    for i in range(num-2, -1, -1) :
        seg[i] = gcd(seg[2*i+1], seg[2*i+2]) 


# a[k]の値をxに更新
def update(k, x):
    k += num - 1
    seg[k] = x
    while k:
        k = (k - 1) // 2
        seg[k] = gcd(seg[k*2+1], seg[k*2+2])


# [p, q)についてsegfuncを適用したものを返す
def query(p,q):
    if q <= p:
        return ide_ele
    
    p += num - 1
    q += num - 2
    res = ide_ele

    while q - p > 1:
        if p & 1 == 0:
            res = gcd(res, seg[p])
        if q & 1 == 1:
            res = gcd(res, seg[q])
            q -= 1
        p = p // 2
        q = (q - 1) // 2
    if p == q:
        res = gcd(res, seg[p])
    else:
        res = gcd(gcd(res, seg[p]), seg[q])
    
    return res


n = int(input())
a = list(map(int, input().split()))

ide_ele = 0
num = 2 ** (len(bin(n - 1)) - 2)
seg = [ide_ele] * 2 * num
init(a)

res = 0
for i in range(n):
    res = max(res, gcd(query(0, i), query(i+1, n)))

print(res)

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

# 配列aで初期化
def init(a):
    for i in range(n):
        seg[i+num-1] = a[i]    
    for i in range(num-2, -1, -1) :
        seg[i] = gcd(seg[2*i+1], seg[2*i+2]) 


# a[k]の値をxに更新
def update(k, x):
    k += num - 1
    seg[k] = x
    while k:
        k = (k - 1) // 2
        seg[k] = gcd(seg[k*2+1], seg[k*2+2])


# [p, q)についてsegfuncを適用したものを返す
def query(p,q):
    if q <= p:
        return ide_ele
    
    p += num - 1
    q += num - 2
    res = ide_ele

    while q - p > 1:
        if p & 1 == 0:
            res = gcd(res, seg[p])
        if q & 1 == 1:
            res = gcd(res, seg[q])
            q -= 1
        p = p // 2
        q = (q - 1) // 2
    if p == q:
        res = gcd(res, seg[p])
    else:
        res = gcd(gcd(res, seg[p]), seg[q])
    
    return res


n = int(input())
a = list(map(int, input().split()))

ide_ele = 0
num = 2 ** (len(bin(n - 1)) - 2)
seg = [ide_ele] * 2 * num
init(a)

res = 0
for i in range(n):
    res = max(res, gcd(query(0, i), query(i+1, n)))

print(res)
Problem p03126 (python)

Fixed submission:
n, m = map(int, input().split())
b = [0] * m
count = 0

for _ in range(n):
    a = list(map(int, input().split()))
    for i in range(1, a[0] + 1):
        b[a[i] - 1] += 1

for i in range(m):
    if b[i] == n:
        count += 1

print(count)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
b = [0] * m
count = 0

for _ in range(n):
    a = list(map(int, input().split()))
    for i in range(1, a[0] + 1):
        b[a[i]] += 1

for i in range(m):
    if b[i] == n:
        count += 1

print(count)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
b = [0] * m
count = 0

for _ in range(n):
    a = list(map(int, input().split()))
    for i in range(1, a[0] + 1):
        b[a[i]] += 1

for i in range(m):
    if b[i] == n:
        count += 1

print(count)
Problem p03146 (python)

Fixed submission:
s = int(input())

i = 0
a = []
a.append(s)
b = [0] * 10000

while True:
    if a[i] % 2 == 0:
        a.append(a[i] // 2)
    else:
        a.append(a[i] * 3 + 1)
    b[a[i]] += 1
    if b[a[i]] == 2:
        break
    i += 1

print(i + 1)

Buggy submission (verdict: Runtime Error):
s = int(input())

i = 0
a = []
a.append(s)
b = [0] * 1000

while True:
    if a[i] % 2 == 0:
        a.append(a[i] // 2)
    else:
        a.append(a[i] * 3 + 1)
    b[a[i]] += 1
    if b[a[i]] == 2:
        break
    i += 1

print(i + 1)

Buggy submission (verdict: Runtime Error):
s = int(input())

i = 0
a = []
a.append(s)
b = [0] * 300

while True:
    if a[i] % 2 == 0:
        a.append(a[i] // 2)
    else:
        a.append(a[i] * 3 + 1)
    b[a[i]] += 1
    if b[a[i]] == 2:
        break
    i += 1

print(i + 1)

Buggy submission (verdict: Runtime Error):
import sys

s = int(input())

i = 0
a = []
a.append(s)
b = [0] * 300

while True:
    if a[i] % 2 == 0:
        a.append(a[i] // 2)
    else:
        a.append(a[i] * 3 + 1)
    b[a[i]] += 1
    i += 1
    for j in range(300):
        if b[j] == 2:
            print(i)
            sys.exit()
Problem p03238 (python)

Fixed submission:
n = int(input())

if n == 1:
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a + b)

Buggy submission (verdict: Runtime Error):
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
ans = 10000

for i in range(n):
    if abs(a - (t - h[i] * 0.006)) < ans:
           ans = abs(a - (t - h[i] * 0.006))
           b = i
print(b + 1)
Problem p03244 (python)

Fixed submission:
n = int(input())
v = list(map(int, input().split()))

if len(set(v)) == 1:
    print(n // 2)
else:
    cnt_even = [[0, i] for i in range(10 ** 5 + 1)]
    cnt_odd = [[0, i] for i in range(10 ** 5 + 1)]
    for i in range(n):
        if i % 2 == 0:
            cnt_even[v[i]][0] += 1
        else:
            cnt_odd[v[i]][0] += 1

    cnt_even.sort()
    cnt_odd.sort()

    if cnt_even[-1][1] == cnt_odd[-1][1]:
        print(n - max(cnt_even[-1][0] + cnt_odd[-2][0], cnt_even[-2][0] + cnt_odd[-1][0]))
    else:
        print(n - cnt_even[-1][0] - cnt_odd[-1][0])

Buggy submission (verdict: Runtime Error):
n = int(input())
v = list(map(int, input().split()))

if len(set(v)) == 1:
    print(n // 2)
else:
    cnt_even = [0] * 10 ** 5
    cnt_odd = [0] * 10 ** 5
    max_even = 0
    max_odd = 0
    for i in range(n):
        if i % 2 == 0:
            cnt_even[v[i]] += 1
            if cnt_even[v[i]] > cnt_even[max_even]:
                max_even = v[i]
        else:
            cnt_odd[v[i]] += 1
            if cnt_odd[v[i]] > cnt_even[max_odd]:
                max_odd = v[i]
    print(n - cnt_even[max_even] - cnt_odd[max_odd])
Problem p03260 (python)

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

if (a * b) % 2 != 0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a. b = map(int, input().split())

if (a * b) % 2 != 0:
    print("Yes")
else:
    print("No")
Problem p03262 (python)

Fixed submission:
from fractions import gcd

N, X = map(int, input().split())
x = list(map(int, input().split()))

res = abs(X - x[0])
for v in x[1:]:
    res = gcd(res, abs(X - v))

print(res)

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

N, X = map(int, input().split())
x = list(map(int, input().split()))

res = abs(X - x[0])
for v in x[1:]:
    res = gcd(res, abs(X - v))

print(res)
Problem p03263 (python)

Fixed submission:
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]

cnt = 0
for i in range(h):
    for j in range(w):
        if a[i][j] % 2 == 1:
            cnt += 1

res = []
c = 0
move_flag = False
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            if a[i][j] % 2 == 1:
                c += 1
                if move_flag:
                    move_flag = False
                else:
                    if cnt % 2 == 0 or c != cnt:
                        move_flag = True
            if move_flag:
                if j < w - 1:
                    res.append([i+1, j+1, i+1, j+2])
                else:
                    res.append([i+1, j+1, i+2, j+1])
    else:
        for j in range(w-1, -1, -1):
            if a[i][j] % 2 == 1:
                c += 1
                if move_flag:
                    move_flag = False
                else:
                    if cnt % 2 == 0 or c != cnt:
                        move_flag = True
            if move_flag:
                if j > 0:
                    res.append([i+1, j+1, i+1, j])
                else:
                    res.append([i+1, j+1, i+2, j+1])

print(len(res))
for y1, x1, y2, x2 in res:
    print(y1, x1, y2, x2)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]

res = []
for i in range(h):
    if i % 2 == 0:
        for j in range(w):
            if a[i][j] % 2 == 1:
                if j < w - 1:
                    a[i][j+1] += 1
                    res.append([i+1, j+1, i+1, j+2])
                else:
                    a[i+1][j] += 1
                    res.append([i+1, j+1, i+2, j+1])
    else:
        for j in range(w-1, -1, -1):
            if a[i][j] % 2 == 1:
                if j > 0:
                    a[i][j-1] += 1
                    res.append([i+1, j+1, i+1, j])
                else:
                    a[i+1][j] += 1
                    res.append([i+1, j+1, i+2, j+1])

print(len(res))
for y1, x1, y2, x2 in res:
    print(y1, x1, y2, x2)
Problem p03473 (python)

Fixed submission:
print(48 - int(input()))

Buggy submission (verdict: Runtime Error):
print(48 - int(input())
Problem p03579 (python)

Fixed submission:
from sys import setrecursionlimit

setrecursionlimit(10**6)

def dfs(v):
    flag = True

    for nxt in edge[v]:
        if l[v] == l[nxt]:
            return False
        elif l[v] + l[nxt] == 1:
            continue
        else:
            l[nxt] = 1 - l[v]
            cnt[1-l[v]] += 1
            flag &= dfs(nxt)
    
    return flag
        

n, m = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

l = [-1] * n
l[0] = 0
cnt = [1, 0]

if dfs(0):
    print(cnt[0] * cnt[1] - m)
else:
    print(n * (n - 1) // 2 - m)

Buggy submission (verdict: Runtime Error):
from sys import setrecursionlimit

setrecursionlimit(10**10)

def dfs(v):
    flag = True

    for nxt in edge[v]:
        if l[v] == l[nxt]:
            return False
        elif l[v] + l[nxt] == 1:
            continue
        else:
            l[nxt] = 1 - l[v]
            cnt[1-l[v]] += 1
            flag &= dfs(nxt)
    
    return flag
        

n, m = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

l = [-1] * n
l[0] = 0
cnt = [1, 0]

if dfs(0):
    print(cnt[0] * cnt[1] - m)
else:
    print(n * (n - 1) // 2 - m)
Problem p03625 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

l = []
d = dict()
for v in a:
    if v not in d:
        d[v] = 1
    else:
        d[v] += 1
        
    if d[v] == 2 or d[v] == 4:
        l.append(v)

if len(l) < 2:
    print(0)
else:
    l.sort()
    print(l[-1] * l[-2])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

l = []
d = dict()
for v in a:
    if v not in d:
        d[v] = 1
    else:
        d[v] += 1
        
    if d[v] == 2:
        l.append(v)

l.sort()
print(l[-1] * l[-2])
Problem p02630 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))

q = int(input())

m = {}

for i in range(1000000):
  m[i] = 0

for e in a:
  m[e] += 1
  
ans = sum(a)

for i in range(q):
  b,q = map(int,input().split())
  diff = (q-b) * m[b]
  
  m[q] += m[b]
  m[b] = 0
  
  ans += diff
  print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))

q = int(input())

m = {}

for i in range(100000):
  m[i] = 0

for e in a:
  m[e] += 1
  
ans = sum(a)

for i in range(q):
  b,q = map(int,input().split())
  diff = (q-b) * m[b]
  
  m[q] += m[b]
  m[b] = 0
  
  ans += diff
  print(ans)
Problem p02899 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))

b = []
for i,e in enumerate(a):
  b.append((e,i+1))
  
b.sort()

for i,t in enumerate(b):
  if i == n-1:
    print(t[1])
  else:
    print(t[1],end=' ')

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))

b = []
for i,e in enumerate(a):
  b.append(e,i+1)
  
sort(b)

for i,t in enumerate(b):
  if i == n-1:
    print(t[0])
  else:
    print(t[0],end=' ')

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))

b = []
for i,e in enumerate(a):
  b.append(e,i+1)
  
sort(b)

print(' '.join(b))
Problem p02909 (python)

Fixed submission:
s = input()
li = ["Sunny","Cloudy","Rainy"]
id = 0

if s == "Sunny":
  id = 1
elif s == "Cloudy":
  id = 2
else:
  id = 0
  
print(li[id])

Buggy submission (verdict: Runtime Error):
s = input()
li = ["Sunny","Cloudy","Rainy"]
id = 0

if s == "Sunny":
  id = 1
elif s == "Cloudy:
  id = 2
else:
  id = 0
  
print(li[id])
Problem p02936 (python)

Fixed submission:
n,q = map(int,input().split())
graph = [[] for i in range(n)]
for i in range(n-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  graph[a].append(b)
  graph[b].append(a)

weight = [0 for i in range(n)]
for i in range(q):
  p,x = map(int,input().split())
  weight[p-1] += x

st = [0]
visit = [False for i in range(n)]
while not len(st) == 0:
  now = st.pop()
  visit[now] = True
  for e in graph[now]:
    if visit[e]:
      continue
    weight[e] += weight[now]
    st.append(e)
    
print(' '.join(map(str,weight)))

Buggy submission (verdict: Runtime Error):
n,q = map(int,input().split())
graph = [[] for i in range(n)]
for i in range(n-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  graph[a].append(b)
  graph[b].append(a)

weight = [0 for i in range(n)]
for i in range(q):
  p,x = map(int,input().split())
  weight[p-1] = x

st = [0]
visit = [false for i in range(n)]
while not len(st) == 0:
  now = st.pop()
  visit[now] = true
  for e in graph[now]:
    if visit[e]:
      continue
    weight[e] += weight[e]
    st.push(e)
    
print(' '.join(map(str,weight)))
Problem p03109 (python)

Fixed submission:
s = input()
m = int(s[5:7])

if m >= 5:
    print("TBD")
else:
    print("Heisei")

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
print(a+b if b%a == 0 else b-a)
Problem p03965 (python)

Fixed submission:
s = input()
n = len(s)
p = 0
for e in s:
  if e == 'p':
    p += 1
print(n//2 - p)

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
p = 0
for e in s:
  if e == 'p':
    p += 1
print(s//2 - p)
Problem p03997 (python)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())

print((a+b)*c//2)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())

print((a+b)*h//2)
Problem p04013 (python)

Fixed submission:
class Combination:
    def __init__(self, n, mod):
        self.n = n
        self.mod = mod
        self.fac = [1 for i in range(self.n + 1)]
        self.finv = [1 for i in range(self.n + 1)]
        for i in range(2, self.n+1):
            self.fac[i] = (self.fac[i - 1] * i) % self.mod
            self.finv[i] = (self.finv[i-1] * pow(i, -1, self.mod)) % self.mod

    def comb(self, n, m):
        return self.fac[n] * (self.finv[n-m] * self.finv[m] % self.mod) % self.mod
def iparse():
    return list(map(int, input().split()))

if __name__ == "__main__":
    n, a = iparse()
    x = iparse()

    dp = [[[0 for i in range(sum(x) + 10)] for j in range(n + 10)] \
        for k in range(n + 10)]
    dp[0][0][0] = 1
    for i in range(n):
        for j in range(n + 1):
            for k in range(sum(x) + 1):
                if j >= 1 and k - x[i] >= 0:
                    dp[i + 1][j][k] = dp[i][j][k] + dp[i][j - 1][k - x[i]]
                else:
                    dp[i+1][j][k] = dp[i][j][k]
    ans = 0
    for i in range(n):
        if (i + 1) * a >= sum(x) + 10:
            break
        ans += dp[n][i + 1][(i+1)*a]
    print(ans)

Buggy submission (verdict: Runtime Error):
class Combination:
    def __init__(self, n, mod):
        self.n = n
        self.mod = mod
        self.fac = [1 for i in range(self.n + 1)]
        self.finv = [1 for i in range(self.n + 1)]
        for i in range(2, self.n+1):
            self.fac[i] = (self.fac[i - 1] * i) % self.mod
            self.finv[i] = (self.finv[i-1] * pow(i, -1, self.mod)) % self.mod

    def comb(self, n, m):
        return self.fac[n] * (self.finv[n-m] * self.finv[m] % self.mod) % self.mod
def iparse():
    return list(map(int, input().split()))

if __name__ == "__main__":
    n, a = iparse()
    x = iparse()

    dp = [[[0 for i in range(sum(x) + 10)] for j in range(n + 10)] \
        for k in range(n + 10)]
    dp[0][0][0] = 1
    for i in range(n):
        for j in range(n + 1):
            for k in range(sum(x) + 1):
                if j >= 1 and k - x[i] >= 0:
                    dp[i + 1][j][k] = dp[i][j][k] + dp[i][j - 1][k - x[i]]
                else:
                    dp[i+1][j][k] = dp[i][j][k]
    ans = 0
    for i in range(n):
        ans += dp[n][i + 1][(i+1)*a]
    print(ans)
Problem p04030 (python)

Fixed submission:
s = input()
st = []
for e in s:
  if e == 'B':
    if len(st) != 0:
      st.pop()
  else:
    st.append(int(e))
print(''.join(map(str,st)))

Buggy submission (verdict: Runtime Error):
s = input()
st = []
for e in s:
  if e == 'B' and len(st) != 0:
    st.pop()
  else:
    st.append(int(e))
print(''.join(map(str,st)))

Buggy submission (verdict: Runtime Error):
s = input()
st = []
for e in s:
  if e == B and len(st) != 0:
    st.pop()
  else:
    st.append(int(e))
print(''.join(map(str,st)))
Problem p02555 (python)

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

S = int(input())

A = [-1] * (2001)
mod = 10 ** 9 + 7

for i in range(3):
    A[i] = 0

for i in range(3, 6):
    A[i] = 1


def dfs(n):
    if A[n] != -1:
        return A[n]
    else:
        A[n] = (dfs(n - 3) + dfs(n - 1)) % mod
        return A[n]


print(dfs(S))

Buggy submission (verdict: Runtime Error):
from sys import stdin, setrecursionlimit
input = stdin.readline

setrecursionlimit(10 ** 8)

S = int(input())

A = [-1] * (S + 1)
mod = 10 ** 9 + 7

for i in range(3):
    A[i] = 0

for i in range(3, 6):
    A[i] = 1


def dfs(n):
    if A[n] != -1:
        return A[n]
    else:
        A[n] = (dfs(n - 3) + dfs(n - 1)) % mod
        return A[n]


print(dfs(S))

Buggy submission (verdict: Runtime Error):
from sys import stdin
input = stdin.readline

S = int(input())

A = [-1] * (S + 1)
mod = 10 ** 9 + 7

for i in range(3):
    A[i] = 0

for i in range(3, 6):
    A[i] = 1


def dfs(n):
    if A[n] != -1:
        return A[n]
    else:
        A[n] = (dfs(n - 3) + dfs(n - 1)) % mod
        return A[n]


print(dfs(S))
Problem p02584 (python)

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

X, K, D = map(int, input().split())

X = abs(X)

m = X % D
l = X // D

if l > K:
    print(abs(X) - D * K)
else:
    if (K - l) % 2 == 0:
        print(m)
    else:
        print(D - m)

Buggy submission (verdict: Runtime Error):
from sys import stdin
input = stdin.readline

X, K, D = map(int, input().split())

m = X % D
l = X // D

if l > K:
    print(abs(abs(X) - D * K))
else:
    if (K - l) % 2 == 0:
        print(m)
        exit(1)
    else:
        print(D - m)

Buggy submission (verdict: Runtime Error):
from sys import stdin
input = stdin.readline

X, K, D = map(int, input().split())

m = X % D
l = X // D

if l > K:
    print(abs(abs(X) - D * K))
    exit(1)
else:
    if (K - l) % 2 == 0:
        print(m)
    else:
        print(D - m)