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

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

from collections import Counter
c = Counter(a)
for k in c.keys():
    if c[k] == 2:
        break
l = []
for i in range(len(a)):
    if a[i] == k:
        l.append(i)
    if len(l) == 2:
        break
d = n - l[1] + l[0]

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y // 2) ** 2 % mod
    else            : return power(x, y // 2) ** 2 * x % mod

mod = (10 ** 9 + 7)

N1 = n + 2
factorial1 = [1]
for i in range(1, N1):
    factorial1.append(factorial1[i - 1] * i % mod)
inverseFactorial1 = [0] * N1
inverseFactorial1[N1 - 1] = power(factorial1[N1 - 1], mod - 2)
for i in range(N1 - 2, -1, -1):
    inverseFactorial1[i] = inverseFactorial1[i + 1] * (i + 1) % mod
def combi1(x, y):
    return factorial1[x] * inverseFactorial1[y] * inverseFactorial1[x - y] % mod

for k in range(1, n + 2):
    if d >= k - 1:
        print((combi1(n+1, k) - combi1(d, k-1)) % mod)
    else:
        print(combi1(n+1, k))

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

from collections import Counter
c = Counter(a)
for k in c.keys():
    if c[k] == 2:
        break
l = []
for i in range(len(a)):
    if a[i] == k:
        l.append(i)
    if len(l) == 2:
        break
d = n - l[1] + l[0]

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y // 2) ** 2 % mod
    else            : return power(x, y // 2) ** 2 * x % mod

mod = 10 ** 9 + 7

factorial = [1]
for i in range(1, N):
    factorial.append(factorial[i - 1] * i % mod)

inverseFactorial = [0] * N
inverseFactorial[N - 1] = power(factorial[N - 1], mod - 2)
for i in range(N - 2, -1, -1):
    inverseFactorial[i] = inverseFactorial[i + 1] * (i + 1) % mod

def comb(x, y):
    return factorial[x] * inverseFactorial[y] * inverseFactorial[x - y] % mod

for k in range(1, n + 2):
    if d >= k - 1:
        print((comb(n+1, k) - comb(d, k-1)) % mod)
    else:
        print(comb(n+1, k))
Problem p03695 (python)

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

l = [0] * 9

for i in range(n):
    s = min(a[i] // 400, 8)
    l[s] += 1

m = 0
for i in range(len(l) - 1):
    if l[i] != 0:
        m += 1

print(max(m, 1), l[-1] + m)

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

l = [0] * 9

for i in range(n):
    s = min(a[i] // 400, 9)
    l[s] += 1

m = 0
for i in range(len(l) - 1):
    if l[i] != 0:
        m += 1

M = min(9, l[-1] + m)
print(m, M)

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

l = [0] * 9

for i in range(n):
    l[a[i] // 400] += 1

m = 0
for i in range(len(l) - 1):
    if l[i] != 0:
        m += 1

M = min(9, l[-1] + m)
print(m, M)
Problem p04000 (python)

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

d = dict()
for i in range(len(ab)):
    a = ab[i][0] - 1
    b = ab[i][0] - 1
    d[a] = set()

dp = [0] * 10
dp[0] = (h - 2) * (w - 2)
for i in range(n):
    a = ab[i][0] - 1
    b = ab[i][1] - 1
    for dx in [-1, 0, 1]:
        for dy in [-1, 0, 1]:
            nx, ny = a + dx, b + dy # center
            if nx >= 1 and nx <= h - 2 and ny >= 1 and ny <= w - 2:
                # print(nx, ny)
                tmp = 0
                for dx2 in [-1, 0, 1]:
                    for dy2 in [-1, 0, 1]:
                        if nx + dx2 in d and ny + dy2 in d[nx + dx2]:
                            tmp += 1

                dp[tmp] -= 1
                dp[tmp + 1] += 1

    d[a].add(b)

for x in dp:
    print(x)

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

d = dict()
for i in range(len(ab)):
    a = ab[i][0] - 1
    b = ab[i][0] - 1
    d[a] = set()

dp = [0] * 10
dp[0] = (h - 2) * (w - 2)
for i in range(n):
    a = ab[i][0] - 1
    b = ab[i][1] - 1
    for dx in [-1, 0, 1]:
        for dy in [-1, 0, 1]:
            nx, ny = a + dx, b + dy # center
            if nx >= 1 and nx <= h - 2 and ny >= 1 and ny <= w - 2:
                # print(nx, ny)
                tmp = 0
                for dx2 in [-1, 0, 1]:
                    for dy2 in [-1, 0, 1]:
                        if ny + dy2 in d[nx + dx2]:
                            tmp += 1

                dp[tmp] -= 1
                dp[tmp + 1] += 1

    d[a].add(b)

for x in dp:
    print(x)
Problem p02618 (python)

Fixed submission:
D = int(input())
cs = list(map(int, input().split()))
ss = [list(map(int, input().split())) for _ in range(D)]

ts = []
for i in range(D):
    t = 1
    ts.append(t)

for t in ts:
    print(t)

Buggy submission (verdict: Runtime Error):
import random

T = 26


def read_input():
    D = int(input())
    cs = list(map(int, input().split()))
    ss = [list(map(int, input().split())) for _ in range(D)]
    return D, cs, ss


def greedy(D, cs, ss):
    ts = []
    last = [0] * T
    for d in range(D):
        d_true = d + 1
        diffs = []
        ssc = ss[d]
        for t in range(T):
            s = ssc[t]
            d = s + cs[t] * (d_true - last[t])
            diffs.append((d, t))
        
        dc, tc = max(diffs)
        last[tc] = d_true
        ts.append(tc)
    
    return ts


def evaluate(out, D, c, s):
    sat = 0
    last = [0] * 26
    for d in range(D):
        assert(1 <= out[d] and out[d] <= 26)
        j = out[d] - 1
        last[j] = d + 1
        for i in range(26):
            sat -= (d + 1 - last[i]) * c[i]
        sat += s[d][j]
        
    return sat, max(0, 1000000 + sat)


def anneal(D, cs, ss, ts_init):
    def calc_cs(tds):
        last = 0
        css = 0
        for d in tds:
            css += (d + 1 - last) * (d - last) // 2
            last = d
        css += D - 1 - last
        return css

    ts = ts_init.copy()
    tds = [set() for t in range(26)]
    for d in range(D):
        t = ts[d]
        tds[t].add(d)

    for i in range(10000):
        r = random.random()
        if r < 1:  # flip
            d1, d2 = random.randint(0, D-1), random.randint(0, D-1)
            if d1 == d2 or ts[d1] == ts[d2]:
                continue
            d1, d2 = min(d1, d2), max(d1, d2)
            t1, t2 = ts[d1], ts[d2]
            diff1 = (ss[d2][t1] - ss[d1][t1]) + (ss[d1][t2] - ss[d2][t2])
            tds1_after = tds[t1].copy()
            tds1_after.add(d2)
            tds1_after.remove(d1)
            tds2_after = tds[t2].copy()
            tds2_after.add(d1)
            tds2_after.remove(d2)
            # print(tds1_after)
            # print(tds[t1])
            # print(calc_cs(sorted(tds1_after)))
            # print(calc_cs(sorted(tds[t1])))
            diff2 = cs[t1] * (calc_cs(sorted(tds1_after)) - calc_cs(sorted(tds[t1]))) \
                + cs[t2] * (calc_cs(sorted(tds2_after)) - calc_cs(sorted(tds[t2])))
            diff = diff1 + diff2
            # print(diff1, diff2)
            if diff > 0:
                # print("yead")
                ts[d1], ts[d2] = ts[d2], ts[d1]
                tds[t1] = tds1_after
                tds[t2] = tds2_after
        else:
            pass

        if i % 100 == 0:
            # print(evaluate(inc(ts), D, cs, ss))
    
    return ts


def inc(ts):
    return [t + 1 for t in ts]


def solve(D, cs, ss):
    ts = greedy(D, cs, ss)
    ts = anneal(D, cs, ss, ts)
    ts = inc(ts)
    return ts


if __name__ == "__main__":
    D, cs, ss = read_input()
    ts = solve(D, cs, ss)

    for t in ts:
        print(t)
Problem p03948 (python)

Fixed submission:
import numpy as np

input()
a = np.array(input().split(), dtype=np.int)

diff = a - np.minimum.accumulate(a)
print((diff == diff.max()).sum())

Buggy submission (verdict: Runtime Error):
from numpy import *
input()
a=array(input().split())
d=a-minimum.accumulate(a)
print((d==d.max()).sum())
Problem p02618 (python)

Fixed submission:
import numpy as np

D = int(input())
c = np.array(list(map(int, input().split())))
s = np.array([list(map(int, input().split())) for x in range(D)])

l_opt = s.argmax(axis=1)
for l in l_opt:
    print(l + 1)

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

D = int(input())
c = np.array(list(map(int, input().split())))
s = np.array([list(map(int, input().split())) for x in range(D)])

l_opt = np.array(list(range(1, 27)) * (D // 26) + list(range(1, D % 26 + 1)))
l_max = s.argmax(axis=1) + 1

for day in range(1, D + 1):
    if day * s[l_opt[day - 1] - 1] < s[l_max[day - 1] - 1]:
        l_opt[day - 1] = l_max[day - 1]

for l in l_opt:
    print(l)

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

D = int(input())
c = np.array(list(map(int, input().split())))
s = np.array([list(map(int, input().split())) for x in range(D)])

l_opt = np.array(list(range(1, 27)) * (D // 26) + list(range(1, D % 26 + 1)))
l_max = s.argmax(axis=1) + 1

for day in range(1, D + 1):
    if 2 * s[l_opt[day - 1] - 1] < s[l_max[day - 1] - 1, day + 1]:
        l_opt[day - 1] = l_max[day - 1]

for l in l_opt:
    print(l)

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

D = int(input())
c = np.array(list(map(int, input().split())))
s = np.array([list(map(int, input().split())) for x in range(D)])

l_opt = np.array(list(range(1, 27)) * (D // 26) + list(range(1, D % 26 + 1)))
l_max = s.argmax(axis=1) + 1

for day in range(1, D + 1):
    if 2 * s[l_opt[day - 1] - 1] < s[l_max[day - 1] - 1]:
        l_opt[day - 1] = l_max[day - 1]

for l in l_opt:
    print(l)
Problem p02730 (python)

Fixed submission:
import sys
s = input()
n = len(s)
l = (n - 1) // 2
s1 = s[:l]
s2 = s[l+1:][::-1]
if s1 != s2:
    print('No')
    sys.exit()
m = l // 2
if l % 2 == 0:
    a1 = s1[:m]
    b1 = s2[:m]
    a2 = s1[m:][::-1]
    b2 = s2[m:][::-1]
else:
    a1 = s1[:m]
    b1 = s2[:m]
    a2 = s1[m+1:][::-1]
    b2 = s2[m+1:][::-1]
if a1 != a2 or b1 != b2:
    print('No')
    sys.exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
l = (n - 1) // 2
m = n // 4
for i in range(m):
  if s[i] != s[l - i - 1] or s[i] != s[l + i + 1] or s[i] != s[n - i - 1]:
Problem p02999 (python)

Fixed submission:
import re
X, A = [int(i) for i in re.split(" ", input())]
if X < A:
  print(0)
else:
  print(10)

Buggy submission (verdict: Runtime Error):
import re
import numpy as np
 
N, K = [int(i) for i in re.split(" ", input())]
A = [int(i) for i in re.split(" ", input())]
count = 0
 
for i in range(N):
  tmp = 0
  for j, a in enumerate(A[i:]):
    tmp += a
    if tmp <= K:
      count += N - j
      break

print(count)

Buggy submission (verdict: Runtime Error):
import re
import numpy as np
 
W, H, x, y = [int(i) for i  in re.split(" ", input())]
 
print(W * H / 2)
 
if x * 2 == W and y * 2 == H:
  print(1)
else:
  print(0)
Problem p03000 (python)

Fixed submission:
import re
import numpy as np
 
N, X = [int(i) for i in re.split(" ", input())]
Ls = [int(i) for i in re.split(" ", input())]
Ds = np.cumsum(Ls)
counts = np.sum(Ds <= X) + 1
print(counts)

Buggy submission (verdict: Runtime Error):
import re
import numpy as np

N, X = [int(i) for i in re.split(" ", input())]
Ls = [int(i) for i in re.split(" ", input())]
Ds = np.cumsum(Ls)
counts = np.sum(Ls <= X) + 1
print(counts)
Problem p03035 (python)

Fixed submission:
A, B = map(int, input().split())
if 13 <= A:
	print(B)
elif 5 < A:
	print(B // 2)
else:
	print(0)

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

N = int(input())
A = np.empty(N, dtype=np.int)
B = np.empty(N, dtype=np.int)
for i in range(N):
	A[i], B[i] = map(int, input().split())

for i in range(N):
	print(A[i] * B[i])
Problem p03101 (python)

Fixed submission:
H, W = map(int, input().split())
h, w = map(int, input().split())
print((H-h)*(W-w))

Buggy submission (verdict: Runtime Error):
from functools import reduce
N, M, C = map(int, input().split())
B = map(int, input().split())
count = 0
for _ in range(N):
    if 0 < C + reduce(lambda p: p[0]*p[1], zip(map(int, input().split()), B)):
        count += 1
print(count)
Problem p03102 (python)

Fixed submission:
from functools import reduce
N, M, C = map(int, input().split())
*B, = map(int, input().split())
count = 0
for _ in range(N):
	if 0 < C + reduce(lambda acc, p: acc + p[0]*p[1], zip(map(int, input().split()), B), 0):
		count += 1
print(count)

Buggy submission (verdict: Runtime Error):
from functools import reduce
N, M, C = map(int, input().split())
B = map(int, input().split())
count = 0
for _ in range(N):
  	if 0 < C + reduce(lambda p: p[0]*p[1], zip(map(int, input().split()), B)):
        count += 1
print(count)

Buggy submission (verdict: Runtime Error):
from functools import reduce
N, M, C = map(int, input().split())
B = map(int, input().split())
count = 0
for _ in range(N):
  	if 0 < C + reduce(lambda p: p[0]*p[1], zip(map(int, input().split()), B)):
    	count += 1
print(count)
Problem p03106 (python)

Fixed submission:
def gcd(a, b):
	while b != 0:
		a, b = b, a % b
	return a
A, B, K = map(int, input().split())
d = gcd(A, B)
print([i for i in range(100, 0, -1) if d % i == 0][K-1])

Buggy submission (verdict: Runtime Error):
from math import gcd
A, B, K = map(int, input().split())
d = gcd(A, B)
print([i for i in range(100, 0, -1) if d % i == 0][K-1])
Problem p03665 (python)

Fixed submission:
def nCk(n, k):
    ans = 1
    i = 0
    while i < k:
        ans *= n - i
        i += 1
    i = 1
    while i <= k:
        ans /= i
        i += 1
    return ans

def main():
    [N, P] = map(int, raw_input().split())
    even = 0
    odd = 0
    A = map(int, raw_input().split())
    i = 0
    while i < N:
        if 0 == A[i] & 1:
            even += 1
        else:
            odd += 1
        i += 1
    i = P
    k = 0
    while i <= odd:
        k += nCk(odd, i)
        i += 2
    print((2 ** even) * k)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def nCk(n, k):
    ans = 1
    i = 0
    while i < k:
        ans *= n - i
        i += 1
    i = 1
    while i <= k:
        ans /= i
        i += 1
    return ans

def main():
    [N, P] = map(int, raw_input().split())
    even = 0
    odd = 0
    A = map(int, raw_input().split())
    i = 0
    while i < N:
        if 0 == A[i] & 1:
            even += 1
        else:
            odd += 1
        i += 1
    i = P
    k = 0
    while i <= odd:
        k += nCk(odd, i)
        i += 2
    print((2 ** even) * k)

main()

Buggy submission (verdict: Runtime Error):
def nCk(n, k):
    ans = 1
    i = 0
    while i < k:
        ans *= n - i
        i += 1
    i = 1
    while i <= k:
        ans /= i
        i += 1
    return ans

def main():
    [N, P] = map(int, raw_input().split())
    even = 0
    odd = 0
    A = map(int, raw_input().split())
    i = 0
    while i < N:
        if 0 == A[i] & 1:
            even += 1
        else:
            odd += 1
        i += 1
    i = P
    k = 0
    while i <= odd:
        k += nCk(odd, i)
        i += 2
    print((2 ** even) * k)

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

Fixed submission:
import bisect,collections,copy,heapq,itertools,math,numpy,string,random
import sys
from decimal import Decimal
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

D = I()
C = LI()
s = [LI() for _ in range(D)]

T = [random.randint(1,26) for _ in range(D)]
#print(D,C)
#print(s)
#print(T)
def last(d,i):
    T_d = T[:d]
    n = [j for j, x in enumerate(T_d,1) if x == i]
    if n:
        #print(T_d,i,"n=",n)
        return max(n)
    else:
        return 0
        
        
score = 0
for d in range(1,D+1):
    sum_c = 0
    for i in range(1,26+1):
        sum_c += C[i-1] * (d -last(d,i))
    score += s[d-1][T[d-1]-1] - sum_c
    #print(score)
    #print(max(10**6 + score,0))
for t in T:
    print(t)

Buggy submission (verdict: Runtime Error):
import bisect,collections,copy,heapq,itertools,math,numpy,string,random
import sys
from decimal import Decimal
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

D = I()
C = LI()
s = [LI() for _ in range(D)]

T = [random.randint(1,26) for _ in range(D)]
#print(D,C)
#print(s)
#print(T)
def last(d,i):
    T_d = T[:d]
    n = [j for j, x in enumerate(T_d,1) if x == i]
    if n:
        #print(T_d,i,"n=",n)
        return max(n)
    else:
        return 0
        
def Score(T):
    score = 0
    for d in range(1,D+1):
        sum_c = 0
        for i in range(1,26+1):
            sum_c += C[i-1] * (d -last(d,i))
        score += s[d-1][T[d-1]-1] - sum_c
        #print(score)
    score_d = max(10**6 + score,0)
    #print(score_d)
    return score_d

while Score(T) == 0:
    T = [random.randint(1,26) for i in range(D) if i%36 == 0]
    

for t in T:
    print(t)
Problem p02684 (python)

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A_dict = {i:a for i,a in enumerate(A,1)}

History = [1]
History_set = {1}
now = 1
for i in range(N):
    now = A_dict[now]
    if now not in History_set:
        History.append(now)
        History_set.add(now)
    else:
        break
#print(History,now)
if K < i:
    print(History[K])
else:
    e = History.index(now)
    #print(e)
    #print(History[e:])
    loop_num = len(History[e:])
    #print(loop_num)
    num = (K-e)%loop_num
    #print(num)
    print(History[e:][num])

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))
A_dict = {i:a for i,a in enumerate(A,1)}

History = [1]
History_set = {1}
now = 1
for _ in range(N):
    now = A_dict[now]
    if now not in History_set:
        History.append(now)
        History_set.add(now)
    else:
        break
#print(History,now)
if K < N:
    print(History[K])
else:
    e = History.index(now)
    #print(e)
    #print(History[e:])
    loop_num = len(History[e:])
    #print(loop_num)
    num = (K-e)%loop_num
    #print(num)
    print(History[e:][num])

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))
A_dict = {i:a for i,a in enumerate(A,1)}

History = [1]
History_set = {1}
now = 1
for _ in range(N):
    now = A_dict[now]
    if now not in History_set:
        History.append(now)
        History_set.add(now)
    else:
        break
#print(History,now)
if K <= N:
    print(History[K])
else:
    e = History.index(now)
    #print(e)
    #print(History[e:])
    loop_num = len(History[e:])
    #print(loop_num)
    num = (K-e)%loop_num
    #print(num)
    print(History[e:][num])
Problem p02917 (python)

Fixed submission:
N = int(input())
B = list(map(int,input().split()))
A = [B[0]] + B
#print(A,B)
for i in range(N-1):
    #print(i,B[i] >= max(A[i],A[i+1]))
    if B[i] < max(A[i],A[i+1]):
        A[i] = A[i+1]
print(sum(A))

Buggy submission (verdict: Runtime Error):
N = int(input())
B = list(map(int,input().split()))
A = [B[0],*B]
#print(A,B)
for i in range(N-1):
    #print(i,B[i] >= max(A[i],A[i+1]))
    if B[i] < max(A[i],A[i+1]):
        A[i] = A[i+1]
print(sum(A))
Problem p02957 (python)

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

Buggy submission (verdict: Runtime Error):
N = int(input())
P = list(map(int,input().split()))
A = []
for i in range(N-1):
    if P[i]>P[i+1]:
        A.append([(P[i],i),(P[i+1],i+1)])
l = len(A)
if l > 2:
    print("NO")
elif l ==1:
    print("NO")
elif l == 0:
    print("YES")
else:
    a = max(A[0])
    b = min(A[1])
    P[a[1]],P[b[1]] = b[0],a[0]
    #print(P)
    for j in range(N-1):
        if P[j] > P[j+1]:
            print("NO")
            break
    if j == N-2:
        print("YES")
Problem p02958 (python)

Fixed submission:
N = int(input())
P = list(map(int,input().split()))
A = []
for i in range(N-1):
    if P[i]>P[i+1]:
        A.append([(P[i],i),(P[i+1],i+1)])
l = len(A)
if l > 2 or l == 1:
    print("NO")
elif l == 0:
    print("YES")
elif l == 2:
    a = max(A[0])
    b = min(A[1])
    P[a[1]],P[b[1]] = b[0],a[0]
    for j in range(N-1):
        if P[j] > P[j+1]:
            print("NO")
            j = "j"
            break
    if j != "j":
        print("YES")

Buggy submission (verdict: Runtime Error):
import collections
N = int(input())
P = list(map(int,input().split()))
A = []
for i in range(N-1):
    if P[i]>P[i+1]:
        A.append([(P[i],i),(P[i+1],i+1)])
l = len(A)
if l > 2:
    print("NO")
elif l == 0:
    print("YES")
else:
    a = max(A[0])
    b = min(A[1])
    P[a[1]],P[b[1]] = b[0],a[0]
    #print(P)
    for j in range(N-1):
        if P[j] > P[j+1]:
            print("NO")
            break
    if j == N-2:
        print("YES")
Problem p03000 (python)

Fixed submission:
N, X = map(int, input().split())
L = list(map(int, input().split()))
D = 0
jump = 1
for i in range(N):
    D += L[i]
    if D > X:
        break
    else:
        jump += 1
print(jump)

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = list(map(int, input().split()))
#print(L)
D = 0
for i in range(N+1):
    if D > X:
        break
    D += L[i]
print(i)
Problem p02618 (python)

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

D = int(input())
cost = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

last_held = [-1 for i in range(26)]
ans = []
for date, line in enumerate(S):
    max_score = line[0] - cost[0]*last_held[0]
    max_index = 0
    for i, score in enumerate(line):
        tmp = score - cost[i]*last_held[i]
        if max_score < tmp:
            max_index = i
            max_score = tmp
    last_held[max_index] = date
    ans.append(max_index+1)
print("\n".join(map(str, ans)))

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

D = int(input())
cost = list(map(int, input().strip().split()))
S = [list(map(int, input().strip().split())) for _ in range(D)]

last_held = [-1 for i in range(26)]
ans = []
for date, daily_scores in enumerate(S):
    minus_score = 0
    for i in range(D):
        minus_score += cost[i] * (date - last_held[i])

    max_score = daily_scores[0] + cost[0] * (date - last_held[0])
    max_index = 0
    for i, daily_score in enumerate(daily_scores):
        tmp = daily_score + cost[i] * (date - last_held[i])
        if max_score < tmp:
            max_index = i
            max_score = tmp
    if max_score <= minus_score:
        tmp = 0
        max_index = 0
        for i in range(D):
           if tmp < cost[i] * (date - last_held[i]):
               tmp = cost[i] * (date - last_held[i])
               max_index = i
    last_held[max_index] = date
    ans.append(max_index+1)
print("\n".join(map(str, ans)))

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

D = int(input())
cost = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

last_held = [-1 for i in range(26)]
ans = []
for date, daily_scores in enumerate(S):
    minus_score = 0
    for i in range(D):
        minus_score += cost[i] * (date - last_held[i])

    max_score = daily_scores[0] + cost[0] * (date - last_held[0])
    max_index = 0
    for i, dayly_score in enumerate(daily_scores):
        tmp = daily_scores[i] + cost[i] * (date - last_held[i])
        if max_score < tmp:
            max_index = i
            max_score = tmp
    last_held[max_index] = date
    ans.append(max_index+1)
print("\n".join(map(str, ans)))