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

Fixed submission:
import sys
import math
x, y = map(int, input().split())

if (x + y) % 3 != 0 or x > 2 * y or y > 2 * x:
    print(0)
    sys.exit()

# 手数
n = (x + y) // 3
x -= n
y -= n


def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p


MOD = 10**9 + 7
N = 10**6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    factinv.append((factinv[-1] * inv[-1]) % MOD)

print(cmb(x + y, x, MOD))

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
x, y = map(int, input().split())

if (x + y) % 3 != 0 or x > 2 * y or y > 2 * x:
    print(0)
    sys.exit()

# 手数
n = (x + y) // 3
x -= n
y -= n


MOD = 10**9 + 7


def prepare(n, MOD):
    f = 1
    for m in range(1, n + 1):
        f *= m
        f %= MOD
    fn = f

    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv


fact, invs = prepare(n, MOD)

print(fact * invs[x] * invs[y] % MOD)

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
x, y = map(int, input().split())

if (x + y) % 3 != 0 or x > 2 * y or y > 2 * x:
    print(0)
    sys.exit()

# 手数
n = (x + y) // 3
x -= n
y -= n


# モジュラ逆数戦法
def prepare(n, MOD):

    f = 1
    for m in range(1, n + 1):
        f *= m
        f %= MOD
    fn = f

    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return fn, invs


fact, invs = prepare(n, MOD)

print(fact * invs[x] * invs[y] % MOD)

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
x, y = map(int, input().split())

if (x + y) % 3 != 0 or x > 2 * y or y > 2 * x:
    print(0)
    sys.exit()

# 手数
n = (x + y) // 3
x -= n
y -= n


# モジュラ逆数戦法
def prepare(n, MOD):
    nrt = int(n ** 0.5) + 1
    nsq = nrt * nrt
    facts = np.arange(nsq, dtype=np.int64).reshape(nrt, nrt)
    facts[0, 0] = 1
    for i in range(1, nrt):
        facts[:, i] = facts[:, i] * facts[:, i - 1] % MOD
    for i in range(1, nrt):
        facts[i] = facts[i] * facts[i - 1, -1] % MOD
    facts = facts.ravel().tolist()

    invs = np.arange(1, nsq + 1, dtype=np.int64).reshape(nrt, nrt)
    invs[-1, -1] = pow(facts[-1], MOD - 2, MOD)
    for i in range(nrt - 2, -1, -1):
        invs[:, i] = invs[:, i] * invs[:, i + 1] % MOD
    for i in range(nrt - 2, -1, -1):
        invs[i] = invs[i] * invs[i + 1, 0] % MOD
    invs = invs.ravel().tolist()

    return facts, invs


facts, invs = prepare(n, MOD)

print(facts[n] * invs[x] * invs[y] % MOD)
Problem p02880 (python)

Fixed submission:
print("Yes") if int(input()) in [i*j for i in range(1, 10) for j in range(1, 10)] else print("No")

Buggy submission (verdict: Runtime Error):
print("Yes" if sum([int(input()) == x * y for x in range(1, 10) for y in range(1, 10)]) else "No")
Problem p02881 (python)

Fixed submission:
N = int(input())

for i in range(int(N**0.5), 0, -1):
    if (N / i).is_integer():
        a = N // i
        b = N // a
        break

print(a+b-2)

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

for i in range(int(N**0.5), 1, -1):
    if (N / i).is_integer():
        a = N // i
        b = N // a
        break

print(a+b-2)
Problem p02912 (python)

Fixed submission:
from heapq import heapify, heapreplace

n, m = map(int, input().split())
arr = [-x for x in map(int, input().split())]
heapify(arr)

for _ in range(m):
    heapreplace(arr, int(arr[0] / 2))

print(-sum(arr))

Buggy submission (verdict: Runtime Error):
import bisect
from collections import deque

n, m = map(int, input().split())
arr = list(map(int, input().split()))

arr.sort()
arr = deque(arr)

for _ in range(m):
    q = arr.pop()
    bisect.insort_right(arr, q // 2)

print(sum(arr))

Buggy submission (verdict: Runtime Error):
import bisect
from collections import deque

n, m = map(int, input().split())
arr = list(map(int, input().split()))

arr.sort()
arr = deque(arr)

for _ in range(m):
    q = arr.pop()
    bisect.insort_right(arr, q // 2)

print(sum(arr))

Buggy submission (verdict: Runtime Error):
import bisect
from collections import deque

n, m = map(int, input().split())
arr = deque(map(int, input().split()))

arr.sort()

for _ in range(m):
    q = arr.pop()
    bisect.insort_right(arr, q // 2)

print(sum(arr))
Problem p02959 (python)

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

sa = sum(A)

for i, b in enumerate(B):
    tmp = min(A[i], b)  # 削り取れる分
    A[i] -= tmp  # 削り取る
    A[i + 1] -= min(A[i + 1], b - tmp)  # i+1から削れる分はここで削っておく。b-tmpがi時点でのA[i+1]への攻撃力

print(sa - sum(A))  # 全量から削れなかった分を引く

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

sa = sum(A)

for i, b in enumerate(B):
    tmp = min(A[i], b)  # 削り取れる分
    A[i] -= tmp　　# 削り取る
    A[i + 1] -= min(A[i + 1], b - tmp)　　# i+1から削れる分はここで削っておく。b-tmpがi時点でのA[i+1]への攻撃力

print(sa - sum(A))　　# 全量から削れなかった分を引く
Problem p02984 (python)

Fixed submission:
import numpy as np
n = int(input())
arr = np.array(list(map(int, input().split())))

ans = np.zeros(n + 1, dtype=int)
for i, x in enumerate(arr):
    tmp = x * 2 - ans[i]
    ans[i + 1] += tmp

x = ans[-1] // 2
ans = ans[:-1]
ans[0::2] += x
ans[1::2] -= x

print(*ans)

Buggy submission (verdict: Runtime Error):
import sympy

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

x = sympy.Symbol("x")

ex = [0] * n
ex[0] = x

for i in range(n - 1):
    ex[i + 1] = 2 * arr[i] - ex[i]

ans = sympy.solve(ex[0] + ex[-1] - 2 * arr[-1])[0]
ans = [y.subs(x, ans) for y in ex]

print(*ans)
Problem p02987 (python)

Fixed submission:
from collections import Counter
S = list(input().rstrip())
ans = Counter(S)
print("Yes") if len(ans)==2 & list(ans.values())[0]==2 & list(ans.values())[1]==2 else print("No")

Buggy submission (verdict: Runtime Error):
S = list(input().rstrip())
ans = Counter(S)
print("Yes") if len(ans)==2 & list(ans.values())[0]==2 & list(ans.values())[1]==2 else print("No")
Problem p02989 (python)

Fixed submission:
N = int(input())
d = [int(x) for x in input().split()]

d.sort()
length = len(d)
left = d[length//2-1]
right = d[length//2]

if left==right:
    print(0)
else:
    print(right - left)

Buggy submission (verdict: Runtime Error):
N = int(input())
d = [int(x) for x in input().split()]

d.sort()
length = len(d)
left = d[length//2-1]
right = d[length//2]

if left==right:
    print(0)
else:
    print(ans)
Problem p02990 (python)

Fixed submission:
def factorial_mod(n, mod):
    a = 1
    for i in range(1, n + 1):
        a *= i
        a %= mod
    return a


def cmb(n, k, mod):
    if k > n or k < 0:
        return 0
    fact_n = factorial_mod(n, mod)
    fact_k = factorial_mod(k, mod)
    fact_n_k = factorial_mod(n - k, mod)
    return (fact_n * pow(fact_k, mod - 2, mod) * pow(fact_n_k, mod - 2, mod)) % mod


n, k = map(int, input().split())
MOD = 10**9 + 7

for i in range(k):
    print(int(cmb(n - k + 1, i + 1, MOD) * cmb(k - 1, i, MOD) % MOD))

Buggy submission (verdict: Runtime Error):
from scipy.misc import comb

n, k = map(int, input().split())

for i in range(k):
    print(int(comb(n - k + 1, i + 1) * comb(k - 1, i) % MOD))

Buggy submission (verdict: Runtime Error):
from scipy.special import comb

n, k = map(int, input().split())

for i in range(k):
    print(int(comb(n - k + 1, i + 1) * comb(k - 1, i) % MOD))

Buggy submission (verdict: Runtime Error):
def prepare(n):

    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs


def f(i, facts, invs):
    a = n - k - i + 1
    if a < 0:
        return 0
    b = k - i
    ans = facts[i + a] * invs[i] * invs[a] % MOD
    ans *= facts[i + b - 1] * invs[i - 1] * invs[b] % MOD
    return ans


n, k = list(map(int, input().split()))
facts, invs = prepare(n)

ans = []
for i in range(1, k + 1):
    ans.append(f(i, facts, invs))

print(*ans, sep="\n")
Problem p03013 (python)

Fixed submission:
N, M = map(int, input().split())
A = [None]*M

is_broken = [False] * (N+1)

for i in range(M):
    A[i] = int(input())
    is_broken[A[i]] = True

dp = [0] * (N+1)
dp[0] = 1

for i in range(1, N+1):
    if is_broken[i]:
        continue
    dp[i]  = (dp[i-1] + dp[i-2]) % (10**9 + 7)

print(dp[-1])

Buggy submission (verdict: Runtime Error):
import numpy as np
from math import factorial
import math, sys

N, M = map(int, input().split())
A = [None]*M

for i in range(M):
    A[i] = int(input())

tmp = 0
x = []

for i, a in enumerate(A):
    x.append(a-tmp-1)
    tmp = a + 1

x.append(N - tmp)
    
x = np.array(x)
if x[1:].min()<1:
    print(0)
    sys.exit()

def calc_combi(a):
    ans = 0
    for i in range(int(a/2)+1):
        tmp_n = math.ceil(a/2)+i
        tmp_r = a - tmp_n
        ans += factorial(tmp_n) // factorial(max(tmp_r, tmp_n - tmp_r))                        
    return ans

memo =  list(map(lambda x: calc_combi(x), x))

ans = 1
for m in memo:
    ans = ans * m % 1000000007

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
from math import factorial
import math, sys

N, M = map(int, input().split())
A = [None]*M

for i in range(M):
    A[i] = int(input())

tmp = 0
x = []

for i, a in enumerate(A):
    x.append(a-tmp-1)
    tmp = a + 1

x.append(N - tmp)
    
x = np.array(x)
if x[1:].min()<1:
    print(0)
    sys.exit()

def calc_combi(a):
    ans = 0
    for i in range(int(a/2)+1):
        tmp_n = math.ceil(a/2)+i
        tmp_r = a - tmp_n
        ans += factorial(tmp_n) // factorial(max(tmp_r, tmp_n - tmp_r))                        
    return ans

memo =  list(map(lambda x: calc_combi(x), x))

ans = 1
for m in memo:
    ans = ans * m % 1000000007
Problem p03104 (python)

Fixed submission:
# 0123の周期でXORはリセットされるため剰余だけ考える
def solve(x):
    if x % 4 == 3:
        return 0
    elif x % 4 == 0:
        return x
    elif x % 4 == 1:
        return x ^ (x - 1)
    elif x % 4 == 2:
        return x ^ (x - 1) ^ (x - 2)


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


print(solve(a - 1) ^ solve(b))

Buggy submission (verdict: Runtime Error):
def solve(x):
    # 0123の周期でXORはリセットされるため剰余だけ考える
    if x % 4 == 3:
        return 0
    elif x % 4 == 0:
        return x
    elif x % 4 == 1:
        return x ^ (x　-　1)
    elif x % 4 == 2:
        return x ^ (x　-　1) ^ (x　-　2)


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


print(solve(a - 1) ^ solve(b))
Problem p03345 (python)

Fixed submission:
A, B, C, K = map(int, input().split())
print(A-B) if K%2==0 else print(B-A)

Buggy submission (verdict: Runtime Error):
A, B, C, K = map(int, input().split())
print(A-B) if k%2==0 else print(B-A)
Problem p03634 (python)

Fixed submission:
from heapq import heappush, heappop
from collections import defaultdict

n = int(input())
graph = defaultdict(list)

# グラフにコストを格納
for _ in range(n - 1):
    a, b, c = map(int, input().split())
    graph[a].append((b, c))
    graph[b].append((a, c))

q, k = map(int, input().split())


# コストの初期化
INF = 1 << 60
dist = [INF] * (n + 1)
dist[k] = 0

#　スタート地点
que = [(0, k)]

# ３からの距離
while que:
    cost, curr = heappop(que)
    if cost > dist[curr]:
        continue
    for after, nc in graph[curr]:
        if cost + nc < dist[after]:
            dist[after] = cost + nc
            heappush(que, (cost + nc, after))
            
print(*([dist[x] + dist[y] for x, y in (map(int, input().split()) for _ in range(q))]), sep="\n")

Buggy submission (verdict: Runtime Error):
from heapq import heappush, heappop
from collections import defaultdict

n = int(input())
graph = defaultdict(list)

# グラフにコストを格納
for _ in range(n - 1):
    a, b, c = map(int, input().split())
    graph[a].append((b, c))
    graph[b].append((a, c))

q, k = map(int, input().split())


# コストの初期化
INF = 1 << 60
dist = [INF] * (n + 1)
dist[k] = 0

#　スタート地点
q = [(0, k)]

# ３からの距離
while q:
    cost, curr = heappop(q)
    if cost > dist[curr]:
        continue
    for after, nc in graph[curr]:
        if cost + nc < dist[after]:
            dist[after] = cost + nc
            heappush(q, (cost + nc, after))

print("\n".join(map(str, (dist[x] + dist[y]
                          for x, y in (map(int, input().split()) for _ in range(q))))))
Problem p03745 (python)

Fixed submission:
import sys
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

if N <= 2:
    print(1)
    sys.exit()

A = [A[0]] + [y for x,y in zip(A,A[1:]) if x != y]
sq = np.diff(A)

ans = 1
flg = 0
prev = sq[0]
for i in range(1, len(sq)):
    if flg==1:
        prev = sq[i]
        flg = 0
        continue
    current = sq[i]
    if (prev * current) > 0:
        continue
    else:
        ans += 1
        prev = current
        flg = 1

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

if len(A)==0:
    print(1)
    sys.exit()

A = [A[0]] + [y for x,y in zip(A,A[1:]) if x != y]
sq = np.diff(A)

ans = 1
flg = 0
prev = sq[0]
for i in range(1, len(sq)):
    if flg==1:
        prev = sq[i]
        flg = 0
        continue
    current = sq[i]
    if (prev * current) > 0:
        continue
    else:
        ans += 1
        prev = current
        flg = 1

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

A = [A[0]] + [y for x,y in zip(A,A[1:]) if x != y]
sq = np.diff(A)

ans = 1
flg = 0
prev = sq[0]
for i in range(1, len(sq)):
    if flg==1:
        prev = sq[i]
        flg = 0
        continue
    current = sq[i]
    if (prev * current) > 0:
        continue
    else:
        ans += 1
        prev = current
        flg = 1

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

sq = np.diff(A)

ans = 1
flg = 0
prev = sq[0]
for i in range(1, len(sq)):
    if flg==1:
        prev = sq[i]
        flg = 0
        continue
    current = sq[i]
    if (prev * current) >= 0:
        continue
    else:
        ans += 1
        prev = current
        flg = 1

print(ans)
Problem p02933 (python)

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

if a < 3200:
    print('red')
else:
    print(s)

Buggy submission (verdict: Runtime Error):
import collections
n, q = map(int, input().split())

tree = collections.defaultdict(list)
counter = {}
for _ in range(n-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    counter[a] = 0
    counter[b] = 0

for _ in range(q):
    p, x = map(int, input().split())

    def add(p_, x_):
        counter[p_] += x_
        for v in tree[p_]:
            add(v, x_)

    add(p, x)

print(' '.join(str(v) for _, v in sorted(counter.items(), key=lambda x: x[0])))
Problem p02623 (python)

Fixed submission:
import itertools

n, m, k = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

A = list(itertools.accumulate(A))
B = list(itertools.accumulate(B))

count = 0
j = m
for i in range(n+1):
    if A[i] > k:
        break
    
    while A[i]+B[j] > k:
        j -= 1
        
    count = max(count, i+j)
    
print(count)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))

a_idx = b_idx = 0
count = 0
time = 0

while time < k:
    if a_idx == n or A[a_idx] >= B[b_idx]:
        time += B[b_idx]
        b_idx += 1
    elif b_idx == m or A[a_idx] < B[b_idx]:
        time += A[a_idx]
        a_idx += 1
        
    if time > k:
        break
    count += 1
    
    if a_idx+b_idx == n+m or time==k:
        break
    
print(count)
Problem p02633 (python)

Fixed submission:
x = int(input())
ans = 0
for i in range(1,361):
    num = 360*i
    if num%x==0:
        print(num//x)
        exit()

Buggy submission (verdict: Runtime Error):
x = int(input())
x = i
if x>90:
    x = x-90
ans = 0
a = 360
while True:
    if a%x==0:
        ans+=a//x
        break
    else:
        rem = a%x
        ans+=a//x
        a-=rem
print(ans)
Problem p02623 (python)

Fixed submission:
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


n, m, k = inpl()
a = inpl()
b = inpl()
tmp = 0
for i in range(len(a)):
    tmp += a[i]
    a[i] = tmp
tmp = 0
for i in range(len(b)):
    tmp += b[i]
    b[i] = tmp
ans = 0
a_start = bisect.bisect_right(a, k)
ans = bisect.bisect_right(b, k)
for a_amount in range(a_start, 0, -1):
    new_k = k - a[a_amount - 1]
    b_amount = bisect.bisect_right(b, new_k)
    ans = max(ans, a_amount + b_amount)
print(ans)

Buggy submission (verdict: Runtime Error):
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


n, m, k = inpl()
a = inpl()
b = inpl()
tmp = 0
for i in range(len(a)):
    tmp += a[i]
    a[i] = tmp
tmp = 0
for i in range(len(b)):
    tmp += b[i]
    b[i] = tmp
ans = 0
a_start = bisect.bisect_right(a, k)
if a_amount==0:
    print(bisect.bisect_right(b, k))
for a_amount in range(a_start, 0, -1):
    new_k = k - a[a_amount - 1]
    b_amount = bisect.bisect_right(b, new_k)
    ans = max(ans, a_amount + b_amount)
print(ans)
Problem p02762 (python)

Fixed submission:
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))

class UnionFind():
    def __init__(self, n):
        """
        Parameters
        ----------
        n:int
            the number of node
        """
        self.par = [-1] * n # -self.par[i] means the tree size

    def find(self, x):
        """
        Parameters
        ----------
        x:int
            target node

        Return
        ----------
        res:int
            root node
        """
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.par[x] > self.par[y]: # lesser has many nodes
                x, y = y, x
            self.par[x] += self.par[y]
            self.par[y] = x

    def is_same(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        '''
        Parameters
        ----------
        x:int
            target node
        
        Return
        ----------
        x:int
            size of  group  to which belongs
        '''
        return - self.par[self.find(x)]
        

n, m, k = inpl()
dame = collections.defaultdict(set)
uf = UnionFind(n)
ans=[0]*n
for i in range(m):
    a, b = inpl()
    a, b = a - 1, b - 1
    dame[a].add(b)
    dame[b].add(a)
    uf.union(a,b)
for i in range(k):
    c, d = inpl()
    c, d = c - 1, d - 1
    if uf.is_same(c,d):
        dame[c].add(d)
        dame[d].add(c)
for i in range(n):
    ans[i] = uf.size(i) - len(dame[i]) - 1
    # 同じグループに所属 - (友達+ブロック) - 自分
print(*ans)

'''

'''

Buggy submission (verdict: Runtime Error):
n,m,k=map(int,input().split())
f={i:set([]) for i in range(n)}
for _ in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  f[a].add(b)
  f[b].add(a)
b={i:set([]) for i in range(n)}
for _ in range(k):
  c,d=map(int,input().split())
  c-=1
  d-=1
  b[c].add(d)
  b[d].add(c)
joined=set([])
def append_friends(j):
  if j in friends:
    return
  friends.add(j)
  s=f[j]
  for a in s:
    append_friends(a)
  return 
dp=[]
result=[]
for i in range(n):
  if i in joined:
    for j in dp:
      if i in j:
        result.append(j)
        break
    continue
  friends=set([])
  append_friends(i)
  dp.append(friends)
  result.append(friends)
  joined=joined|friends
ans=[0]*n
for i in range(n):
  ans[i]=str(len(result[i]-b[i]-f[i]-{i}))
print(" ".join(ans))
Problem p02984 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
ans[0]=sum(a[::2])-sum(a[1::2])
for i in range(1,n):
  ans[i]=2*a[i-1]-ans[i-1]
ans=list(map(str,ans))
print(" ".join(ans))

Buggy submission (verdict: Runtime Error):
import numpy as np
n=int(input())
a=np.array(list(map(int,input().split())))
x=np.zeros((n,n))
for i in range(n):
  x[i][i]=0.5
  if i!=n-1:
    x[i][i+1]=0.5
  else:
    x[i][0]=0.5
#inv_x=np.linalg.inv(x)
#ans=np.dot(inv_x,a)
ans=np.linalg.solve(x,a)
ans=ans.tolist()
ans=list(map(str,map(int,ans)))
print(" ".join(ans))

Buggy submission (verdict: Runtime Error):
import numpy as np
n=int(input())
a=np.array(list(map(int,input().split())))
x=np.zeros((n,n))
for i in range(n):
  x[i][i]=0.5
  if i!=n-1:
    x[i][i+1]=0.5
  else:
    x[i][0]=0.5
inv_x=np.linalg.inv(x)
ans=np.dot(inv_x,a)
ans=ans.tolist()
ans=list(map(str,map(int,ans)))
print(" ".join(ans))

Buggy submission (verdict: Runtime Error):
import numpy as np
n=int(input())
a=np.array(list(map(int,input().split())))
x=np.zeros((n,n))
for i in range(n):
  x[i][i]=0.5
  if i!=n-1:
    x[i][i+1]=0.5
  else:
    x[i][0]=0.5
inv_x=np.linalg.inv(x)
ans=np.dot(a.T,inv_x)
ans=np.insert(ans,0,ans[-1])
ans=np.delete(ans,n)
ans=ans.tolist()
ans=list(map(str,map(int,ans)))
print(" ".join(ans))
Problem p02990 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**5)
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    r=min(r,n-r)
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
n,k=map(int,input().split())
ans=[0]*k

for i in range(k):
  if n-k<i:
    print(0)
    continue
  ans = cmb(n-k+1,i+1)*cmb(k-1,i)
  print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
n,k=map(int,input().split())
ans=[0]*k
for i in range(k):
  ans = cmb(n-k+1,i+1)*cmb(k-1,i)
  print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(3000)
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
n,k=map(int,input().split())
ans=[0]*k
for i in range(k):
  ans = cmb(n-k+1,i+1)*cmb(k-1,i)
  print(ans%(10**9+7))