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

Fixed submission:
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
B = list(map(int, input().split()))
B.sort(reverse=True)
C = list(map(int, input().split()))
C.sort(reverse=True)
count = [0]*N
answer = 0
z = 0
for i in range(N):
    if B[N-1] >= C[i]:
        break
    z += 1
count[N-1] = z
for i in range(1, N):
    k=z
    for j in range(k):
        if B[N-1-i] < C[k-1-j]:
            break
        else:
            z -= 1      
    count[N-1-i] = z
sum_matrix = [0]*(N+1)
y = 0
for i in range(N):
    sum_matrix[i+1] = sum_matrix[i] + count[i]
for i in range(N):
    if A[N-1] >= B[i]:
        break
    answer += count[i]
    y += 1
for i in range(1, N):
    x = y
    for j in range(x):
        if A[N-1-i] < B[x-1-j]:
            break        
        y -= 1
    answer += sum_matrix[y]
print(answer)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
B = list(map(int, input().split()))
B.sort(reverse=True)
C = list(map(int, input().split()))
C.sort(reverse=True)
count = [0]*N
answer = 0
z = 0
for i in range(N):
    if B[N-1] >= C[i]:
        break
    z += 1
count[N-1] = z
for i in range(1, N):
    for j in range(z):
        if B[N-1-i] < C[z-1-j]:
            break
        else:

            z -= 1
    count[N-1-i] = z
sum_matrix = [0]*(N+1)
y = 0
for i in range(N):
    sum_matrix[i+1] = sum_matrix[i] + count[i]
for i in range(N):
    if A[N-1] >= B[i]:
        break
    answer += count[i]
    y += 1

for i in range(1, N):
    for j in range(y):
        if A[N-1-i] < B[y-1-j]:
            break        
    y -= j
    answer += sum_matrix[y]
    #print(y)
    #print(answer)
#print(count)
#print(sum_matrix)
print(answer)
Problem p02900 (python)

Fixed submission:
import math
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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

g = gcd(a,b)


arr = []
temp = g
for i in range(2, int(-(-g**0.5//1))+1):
    if temp%i==0:
        cnt=0
        while temp%i==0:
            cnt+=1
            temp //= i
        arr.append([i, cnt])

if temp!=1:
    arr.append([temp, 1])

print(len(arr)+1)

Buggy submission (verdict: Runtime Error):
import math
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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

g = gcd(a,b)


ans = 1
for i in range(2,int(math.sqrt(g))):
    while g%i == 0:
        g=g//i
        isdevided = True
    if isdevided:
        ans += 1
        isdevided = False
    if g == 1:
        break

print(ans)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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

g = gcd(a,b)


ans = 1
for i in range(2,g):
    while g%i == 0:
        g=g//i
        isdevided = True
    if isdevided:
        ans += 1
        isdevided = False

print(ans)

Buggy submission (verdict: Runtime Error):
import math

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

g = math.gcd(a,b)


ans = 1
for i in range(2,g):
    while g%i == 0:
        g=g//i
        isdevided = True
    if isdevided:
        ans += 1
        isdevided = False

print(ans)
Problem p02957 (python)

Fixed submission:
a,b = (int(x) for x in input().split())


if (a-b)%2 == 1:
  print("IMPOSSIBLE")

else:
  print(int((a+b)/2))

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

if (a-b)%2 == 1:
  print("IMPOSSIBLE")
  
else:
  print((a+b)/2)
Problem p02658 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
U = 10 ** 18
p = 1
for x in A:
    p *= x
    if p > U:
        p = U + 1
 
if p > U:
    print(-1)
else:
    print(p)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
ans = 1
for i in range(N):
    ans = ans*A[i]
if ans > 10**18:
    print(-1)
else:
    print(int(ans[N-1]))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
ans = 1
for i in range(N):
    ans = ans*A[i]
if ans > 10**18:
    print(-1)
else:
    print(int(ans[N-1]))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
import numpy as np
B = np.array(A,dtype='float64')
ans = np.cumprod(B)
if ans[N-1] > 10**18:
    print(-1)
else:
    print(int(ans[N-1]))
Problem p02718 (python)

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

sum = 0
for i in range(n):
    sum = sum + a[i]
sum_divided = sum/(4*m)
cnt = 0
for i in range(n):
    if a[i] >= sum_divided:
        cnt = cnt + 1
if cnt >= m:
    print('Yes')
else:
    print('No')

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

sum = 0
for i in range(a):
    sum = sum + a[i]
sum_divided = sum/(4*m)
cnt = 0
for i in range(a):
    if a[i] >= sum_divided:
        cnt = cnt + 1
if cnt >= m:
    print('Yes')
else:
    print('No')

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

sum = 0
for i in range(a):
    sum = sum + a[i]
sum_divided = sum/(4*m)
cnt = 0
for i in range(a):
    if a[i] >= sum_divided:
        cnt = cnt + 1
if cnt >= m:
    print('Yes')
else:
    print('No')
Problem p02783 (python)

Fixed submission:
h,a = map(int,input().split())
if h%a == 0:
    result = int(h/a)
else:
    result = int(h/a) + 1
print(result)

Buggy submission (verdict: Runtime Error):
h,a = map(int,input().split())
print(int(h/a+1)
Problem p03164 (python)

Fixed submission:
N,W = map(int,input().split())
import numpy as np
dp = np.full(N*1000 +1,W+1,dtype=np.int64)
dp[0]=0
for _ in range(N):
    w,v = map(int,input().split())
    dp[v:] = np.minimum(dp[:-v] + w, dp[v:])
print(np.max(np.where(dp <= W)))

Buggy submission (verdict: Runtime Error):
N,W = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(N)]
import numpy as np
dp = np.full(10**5,10**18,dtype=np.int64)
dp[0]=0
for w,v in wv:
    np.minimum(dp[v:],dp[:-v]+w,out=dp[v:])
print(np.where(dp<=W).max())

Buggy submission (verdict: Runtime Error):
N,W = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(N)]
import numpy as np
dp = np.zeros(W+1)
for w,v in wv:
    np.maximum(dp[w:],dp[:-w]+v,out=dp[w:])
print(int(dp.max()))

Buggy submission (verdict: Runtime Error):
N,W = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(N)]
import numpy as np
dp = np.zeros(W+1,dtype=np.int64)
for w,v in wv:
    np.maximum(dp[w:],dp[:-w]+v,out=dp[w:])
print(dp.max())
Problem p03448 (python)

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if (500*i+100*j+50*k) == X:
                cnt = cnt + 1
print(cnt)

Buggy submission (verdict: Runtime Error):
X = int(input())
A = int(input())
B = int(input())
C = int(input())
cnt = 0
for i in range(A):
    for j in range(B):
        for k in range(C):
            if (i+j+h) == X:
                cnt = cnt + 1
print(cnt)

Buggy submission (verdict: Runtime Error):
X = int(input())
A = int(input())
B = int(input())
C = int(input())
cnt = 0
for(i in range(A)):
    for(j in range(B)):
        for(k in range(C)):
            if(i+j+h == X):
                cnt = cnt + 1
print(cnt)
Problem p03471 (python)

Fixed submission:
N, Y = map(int,input().split())
y = Y/1000
ans_a = -1
ans_b = -1
for i in range(N+1):
    for j in range(N-i+1):
        if i*9 + j*4 + N == y:
            ans_a = i
            ans_b = j
if ans_a == -1:
    N = -3
print(str(ans_a)+' '+str(ans_b)+' '+str(N-ans_a-ans_b))

Buggy submission (verdict: Runtime Error):
N, Y = map(int,input().split())
y = Y/1000
ans_a = -1
ans_b = -1
for i in range(1,2001):
    for j in range(1,2001):
        if i*9 + j*4 + N == y:
            ans_a = i
            ans_b = j
if ans_a == -1:
    N = -1
print(str(ans_a)+' '+str(ans_b)+' '+str(N-ans_a-ans_b)
Problem p02600 (python)

Fixed submission:
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

X = int(readline())

if X <= 599:
    print(8)
elif X <= 799:
    print(7)
elif X <= 999:
    print(6)
elif X <= 1199:
    print(5)
elif X <= 1399:
    print(4)
elif X <= 1599:
    print(3)
elif X <= 1799:
    print(2)
elif X <= 1999:
    print(1)

Buggy submission (verdict: Runtime Error):
#! /usr/bin/env python3

import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
XYP = [list(map(int, readline().split())) for _ in range(N)]

x_cost = [0] * ((1 << N) * N)
y_cost = [0] * ((1 << N) * N)

for bit in range(1 << N):
    for i, (xi, yi, _) in enumerate(XYP):
        x_cost[bit * N + i] = abs(xi)
        y_cost[bit * N + i] = abs(yi)

        for k, (xk, yk, _) in enumerate(XYP):
            if bit & (1 << k):
                x_cost[bit * N + i] = min(x_cost[bit * N + i], abs(xi - xk))
                y_cost[bit * N + i] = min(y_cost[bit * N + i], abs(yi - yk))

ans = [sys.maxsize for _ in range(N + 1)]

for bit in range(1 << N):
    cnt = bin(bit).count('1')
    bit_ = bit
    while bit_ >= 0:
        bit_ &= bit
        cost = 0
        for k in range(N):
            cost += 1 * XYP[k][2] * min(x_cost[bit_ * N + k],
                                        y_cost[(bit - bit_) * N + k])
        ans[cnt] = min(ans[cnt], cost)

        bit_ -= 1
for i in range(N + 1):
    print(ans[i])
Problem p02609 (python)

Fixed submission:
#! /usr/bin/env python3

import sys
import numpy as np
from functools import lru_cache
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)


@lru_cache(maxsize=None)
def f(x):
    if x == 0:
        return 0
    return f(x % bin(x).count('1')) + 1


N = int(readline())
X = readline().decode().rstrip()
X_ = int(X, 2)
X_cnt = X.count('1')
p1 = X_ % (X_cnt + 1)
m1 = X_ % (X_cnt - 1) if X_cnt > 1 else 0

for i in range(N):
    if X[i] == '0':
        cnt = X_cnt + 1
        acc = (p1 + pow(2, N - i - 1, cnt)) % cnt

    else:
        cnt = X_cnt - 1
        if cnt == 0:
            print(0)
            continue
        acc = (m1 - pow(2, N - i - 1, cnt)) % cnt
    print(f(acc) + 1)

Buggy submission (verdict: Runtime Error):
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
X = readline().decode().rstrip()

hoge = [pow(2, i) for i in range(N + 5)]
counts = [1 if i in hoge else -1 for i in range(N + 5)]

for i in range(N):
    cnt = X.count('1')

    tmp = 0
    X_ = list(X)
    m = 0
    if X[i] == "0":
        cnt += 1
        X_[i] = "1"
    else:
        X_[i] = "0"
        cnt -= 1

    X_ = "".join(X_)
    acc = 0
    for j, c in enumerate(X_[::-1]):
        if c == '1':
            acc += hoge[j]
    if acc > 2 * pow(10, 5):
        if acc % cnt == 0:
            print(1)
            continue
        else:
            acc %= cnt
            cnt = bin(acc).count('1')
            tmp += 1

    if counts[acc] != -1:
        print(counts[acc] + tmp)
    else:
        while True:
            if acc % cnt == 0:
                counts[acc] = 1
                print(counts[acc] + tmp)
                break
            elif counts[acc % cnt] != 0:
                counts[acc] = counts[acc % cnt] + 1
                print(counts[acc] + tmp)
                break

            acc %= cnt
            cnt = bin(acc).count('1')
            #print(acc, cnt)
Problem p02647 (python)

Fixed submission:
#! /usr/bin/env python3

import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K, *A = map(int, read().split())

for _ in range(min(K, 42)):
    acc = [0] * (N + 1)
    for i, a in enumerate(A):
        l = max(0, i - a)
        r = min(N, i + a + 1)
        acc[l] += 1
        acc[r] -= 1
    acc[0] = min(N, acc[0])
    for i in range(N):
        acc[i + 1] = min(N, acc[i] + acc[i + 1])
    A = acc[:-1]
    if all(a == N for a in A):
        break
print(*A)

Buggy submission (verdict: Runtime Error):
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K, *A = map(int, read().split())

for _ in range(min(K, 42)):
    acc = [0] * (N + 1)
    for i, a in enumerate(A):
        l = max(0, i - a)
        r = min(N, i + a + 1)
        acc[l] += 1
        acc[r] -= 1
    acc[0] = min(N, acc[0])
    for i in range(N):
        acc[i + 1] = min(N, acc[i] + acc[i + 1])
    A = acc[:-1]
    if all(a == N for a in A):
        break
print(*A)
Problem p02678 (python)

Fixed submission:
import sys
from collections import deque
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, M = map(int, readline().split())
graph = [[] for _ in range(N)]
for i in range(M):
    A, B = map(int1, readline().split())
    graph[A].append(B)
    graph[B].append(A)
ans = [None] * (N)

visited = [False] * N
visited[0] = True

que = deque([0])

while len(que) > 0:
    acc = que.popleft()
    for connected in graph[acc]:
        if visited[connected]:
            continue

        ans[connected] = acc + 1
        visited[connected] = True
        que.append(connected)

if sum(visited) == len(visited):
    print("Yes")
    for sign in ans[1:]:
        print(sign)
else:
    print("No")

Buggy submission (verdict: Runtime Error):
#! /usr/bin/env python3

import sys
from collections import defaultdict
from math import gcd
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)


def formatting(a, b):
    if a == 0:
        return (0, 1)
    g = gcd(a, b)
    a //= g
    b //= g

    if a < 0:
        return (-a, -b)

    return a, b


MOD = pow(10, 9) + 7

N = int(readline())
m = map(int, read().split())
A, B = zip(*zip(m, m))

zz = 0
odd = defaultdict(int)
even = defaultdict(int)

for a, b in zip(A, B):
    if a == b == 0:
        zz += 1
        continue
    a, b = formatting(a, b)
    if b <= 0:
        odd[(a, b)] += 1
    else:
        even[(b, -a)] += 1
        odd[(b, -a)] += 0

ans = zz
k = 1

for key, cnt0 in odd.items():
    cnt1 = even[key]
    acc = pow(2, cnt0, MOD) + pow(2, cnt1, MOD)
    k = k * (acc - 1) % MOD

ans += k - 1
print(ans % MOD)
Problem p02743 (python)

Fixed submission:
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

a, b, c = map(int, read().split())
if ((c - a - b) > 0) & (4 * a * b < pow(c - a - b, 2)):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import sys
from  decimal import *
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

a, b, c = map(int, read().split())
if pow(Decimal(a), .5) + pow(Decimal(b, .5)) < pow(Decimal(c, .5)):


        print("Yes")
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
import sys
from  decimal import *
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

a, b, c = map(int, read().split())
if pow(Decimal(a), .5) + pow(Decimal(b, .5) < pow(Decimal(c, .5)):


        print("Yes")
    else:
        print("No")
Problem p02774 (python)

Fixed submission:
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)


def count(x):
    cnt = 0
    if x >= 0:
        cnt += N * len(zero)
    cnt += np.searchsorted(A, x // pos, side='right').sum()
    cnt += N * len(neg) - np.searchsorted(A, -(-x // neg), side='left').sum()
    cnt -= np.count_nonzero(A * A <= x)

    return cnt // 2


N, K, *A = map(int, read().split())
A = np.array(A)
A.sort()

neg = A[A < 0]
zero = A[A == 0]
pos = A[A > 0]

r = 10**18
l = -r

while r - l > 1:
    m = (r + l) // 2
    if count(m) >= K:
        r = m
    else:
        l = m

print(r)

Buggy submission (verdict: Runtime Error):
import sys
from itertools import permutations, combinations, combinations_with_replacement, product

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K, *A = map(int, read().split())

ans = [0] * (N * (N - 1) // 2)
for i, p in enumerate(combinations(A, 2)):
    ans[i] = p[0] * p[1]

print(sorted(ans)[K - 1])
Problem p02787 (python)

Fixed submission:
import sys
from bisect import bisect_left
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

H, N = map(int, readline().split())
m = map(int, read().split())
AB = zip(m, m)

INF = 10**18

dp = [INF] * (H + (10**4))
dp[0] = 0
for a, b in AB:
    for n in range(H):
        if dp[n + a] > dp[n] + b:
            dp[n + a] = dp[n] + b

print(min(dp[H:]))

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

H, N = map(int, readline().split())
m = map(int, read().split())
AB = np.array(zip(m, m))

INF = 10**18

dp = [INF] * (H + 1)
dp[0] = 0
for a, b in AB:
    for n in range(H + 1):
        k = max(0, n - a)
        acc = dp[k] + b
        if acc < dp[n]:
            dp[n] = acc

print(dp[H])
Problem p02796 (python)

Fixed submission:
import sys
from operator import itemgetter
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n = int(readline())
xl = [list(map(int, readline().decode('utf-8').split())) for _ in range(n)]
LR = [(x - l, x + l) for x, l in xl]
LR.sort(key=itemgetter(1))

acc = -10**18

cnt = 0

for l, r in LR:
    if acc > l:
        continue
    cnt += 1
    acc = r

print(cnt)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n = int(readline())
xl = [list(map(int, readline().decode('utf-8').split())) for _ in range(n)]
xl = np.array(xl)
xl_ = np.c_[xl[:, 0] - xl[:, 1], xl[:, 0] + xl[:, 1]]
xl_ += abs(xl_.min()) + 1

cnt_array = np.zeros(xl_.max())
cnt = 0
for l, r in xl_:
    if (cnt_array[l:r] > 0).sum() > 0:
        continue
    else:
        cnt_array[l:r] += 1
        cnt += 1

cnt_ = 0
for l, r in xl_[::-1]:
    if (cnt_array[l:r] > 0).sum() > 0:
        continue
    else:
        cnt_array[l:r] += 1
        cnt_ += 1

print(max(cnt, cnt_))

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n = int(readline())
xl = [list(map(int, readline().decode('utf-8').split())) for _ in range(n)]
xl = np.array(xl)
xl_ = np.c_[xl[:, 0] - xl[:, 1], xl[:, 0] + xl[:, 1]]
xl_ += abs(xl_.min())

cnt_array = np.zeros(xl_.max())
cnt = 0
for l, r in xl_:
    if (cnt_array[l:r] > 0).sum() > 0:
        continue
    else:
        cnt_array[l:r] += 1
        cnt += 1

cnt_ = 0
for l, r in xl_[::-1]:
    if (cnt_array[l:r] > 0).sum() > 0:
        continue
    else:
        cnt_array[l:r] += 1
        cnt_ += 1

print(max(cnt, cnt_))
Problem p02797 (python)

Fixed submission:
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K, S = map(int, read().split())

if S != 1:
    ans = [S - 1] * N
else:
    ans = [S + 1] * N
for i in range(K):
    ans[i] = S

print(*ans)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K, S = map(int, read().split())

S_half = [S // 2, S - S // 2]

ans = []
for _ in range(N // 2 + 1):
    ans += S_half
ans = np.array(ans[:N])
i = 0
cnt = 0
for i in range(N):
    if cnt == K:
        ans[i:N] = S - 1
        idx = i
        break
    if sum(ans[i:i + 2]) == S:
        cnt += 1
        continue

if ans[idx - 1:idx + 1].sum() != S:
    for s_ in S_half:
        if ans[idx - 1] + s_ == S:
            ans[idx] = s_

print(*ans)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K, S = map(int, read().split())

S_half = [S // 2, S - S // 2]

ans = []
for _ in range(N // 2 + 1):
    ans += S_half
ans = np.array(ans[:N])
i = 0
cnt = 0
for i in range(N):
    if cnt == K:
        ans[i:N] = 0
        idx = i
        break
    if sum(ans[i:i + 2]) == S:
        cnt += 1
        continue

if ans[idx - 1:idx + 1].sum() != S:
    for s_ in S_half:
        if ans[idx - 1] + s_ == S:
            ans[idx] = s_

print(*ans)
Problem p02807 (python)

Fixed submission:
import sys
import numpy as np
from itertools import permutations
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

MOD = int(1e+9 + 7)


class Comb(object):
    def __init__(self, n, MOD=1e9+7):
        self.n = n
        self.MOD = MOD

        fac = [0] * self.n
        finv = [0] * self.n
        inv = [0] * self.n

        fac[0] = 1
        fac[1] = 1
        finv[0] = 1
        finv[1] = 1
        inv[1] = 1

        for i in range(2, n):
            fac[i] = fac[i-1] * i % MOD
            inv[i] = MOD - inv[(MOD % i)] * (MOD // i) % MOD
            finv[i] = finv[i-1] * inv[i] % MOD
        self.fac = fac
        self.finv = finv
        self.inv = inv

    def calv(self, k):
        if self.n < k:
            return 0

        return self.fac[n] * (self.finv[k] * self.finv[n-k] % self.MOD) % self.MOD


N, *X = map(int, read().split())
X = np.array(X)
X_diff = np.diff(X)

comb = Comb(N+5, MOD)

acc = 0
ans = 0
for i in range(1, N):
    acc += comb.fac[N-1] * comb.inv[i]
    acc %= MOD

    ans += acc * (X_diff[i-1])
    ans %= MOD


print(ans % MOD)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
from itertools import permutations
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

MOD = 1000000000 + 7

N, *X = map(int, read().split())
cnt = 1
for i in range(1, N):
    cnt *= i
ans = 0

"""
l = list(permutations(range(1, N)))
for per in l:
    ans += np.abs(np.diff(np.array(list(per) + [N]))).sum()
    ans %= MOD
    print(ans, per)
"""

for i in range(1, N):
    for j in range(1, i+1):
        ans += j * (cnt / i)

print(int(ans % MOD))