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

Fixed submission:
import sys
sys.setrecursionlimit(500000)
input = sys.stdin.readline
n,q=map(int,input().split())
l=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)
px=[0]*n
for i in range(q):
  p,x=map(int,input().split())
  px[p-1]+=x
ans=[0]*n
def dsf(index,u):
  ans[index]=ans[u]+px[index]
  for i in l[index]:
    if i==u:continue
    dsf(i,index)
dsf(0,-1)
print(*ans)

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())
l=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)
ans=[0 for i in range(n)]
for i in range(q):
  p,x=map(int,input().split())
  ans[p-1]+=x
def dsf(index,u):
  for i in l[index]:
    if i==u:continue
    ans[i]+=ans[index]
    dsf(i,index)
dsf(0,-1)
print(' '.join(str(j) for j in ans))

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())
l=[[] for i in range(200005)]
for i in range(n-1):
  a,b=map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)
ans=[0 for i in range(n)]
for i in range(q):
  p,x=map(int,input().split())
  ans[p-1]+=x
def dsf(index,u):
  for i in l[index]:
    if i==u:continue
    ans[i]+=ans[index]
    dsf(i,index)
dsf(0,0)
print(' '.join(str(j) for j in ans))

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())
l=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)
ans=[0 for i in range(n)]
for i in range(q):
  p,x=map(int,input().split())
  ans[p-1]+=x
def dsf(index,u):
  for i in l[index]:
    if i==u:continue
    ans[i]+=ans[index]
    dsf(i,index)
dsf(0,0)
print(' '.join(str(j) for j in ans))

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())
l=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  l[a-1].append(b-1)
ans=[0 for i in range(n)]
for i in range(q):
  p,x=map(int,input().split())
  ans[p-1]+=x
def dsf(index,num):
  ans[index]+=num
  if len(l)-1<index:return
  for i in l[index]:
    dsf(i,ans[index])
dsf(0,0)
print(' '.join(str(j) for j in ans))

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())
l=[[] for i in range(n-1)]
for i in range(n-1):
  a,b=map(int,input().split())
  l[a-1].append(b-1)
ans=[0 for i in range(n)]
for i in range(q):
  p,x=map(int,input().split())
  ans[p-1]+=x
def dsf(index,num):
  ans[index]+=num
  if len(l)-1<index:return
  for i in l[index]:
    dsf(i,ans[index])
dsf(0,0)
print(' '.join(str(j) for j in ans))
Problem p02727 (python)

Fixed submission:
import heapq

x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
pq = p[:x]+q[:y]
heapq.heapify(pq)

for e in r :
    heapq.heappushpop(pq, e)

print(sum(pq))

Buggy submission (verdict: Runtime Error):
import heapq

x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(lambda x :-int(x), input().split()))

p.sort(reverse=True)
q.sort(reverse=True)

p = p[:x]
q = q[:y]

pq = p+q
pq.sort(reverse=True)

heapq.heapify(r)
ans = 0

for i in range(x+y) :
    print(i, pq[i], -r[0])
    if len(r) != 0 :
        if  pq[i] < -r[0] :
            ans += -heapq.heappop(r)
        else :
            ans += pq[i]

print(ans)
Problem p02783 (python)

Fixed submission:
h, a = map(int, input().split())
print(-(-h//a))

Buggy submission (verdict: Runtime Error):
INF = 100100100

h, n = map(int, input().split())
ab = []
maxA = -1
for i in range(n) :
    a, b = map(int, input().split())
    ab.append([a, b])
    maxA = max(maxA, a)

#dp = [[INF for i in range(h+1)] for j in range(n+1)]
dp = [INF for i in range(h+maxA+1)]
dp[0] = 0
for i in range(n) :
    for j in range(h+1) :
        dp[j+ab[i][0]] = min(dp[j+ab[i][0]], dp[j]+ab[i][1])

print(min(dp[h:]))


'''
for i in range(n) :
    for j in range(h+1) :
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        dp[i+1][min(j+ab[i][0], h)] = min(dp[i+1][min(j+ab[i][0], h)], dp[i+1][j]+ab[i][1])
'''
#for i in range(n+1) :
#    print(dp[i])
Problem p02803 (python)

Fixed submission:
import queue

dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]

h, w = map(int, input().split())
s = []
for i in range(h) :
    s.append(input())

ans = 0

for i in range(h) :
    for j in range(w) :
        if s[i][j] == '#' :
            continue
        dist = [[-1 for i in range(w)] for j in range(h)]
        q = queue.Queue()
        q.put([j,i])
        dist[i][j] = 0
        cnt = 0
        while not q.empty() :
            xy = q.get()
            for k in range(4) :
                x = xy[0] + dx[k]
                y = xy[1] + dy[k]
                if y < 0 or y >= h or x < 0 or x >= w :
                    continue
                if s[y][x] == '#' :
                    continue
                if dist[y][x] != -1 :
                    continue
                q.put([x, y])
                dist[y][x] = dist[xy[1]][xy[0]] + 1
        for k in range(h) :
            for l in range(w) :
                ans = max(ans, dist[k][l])


print(ans)

Buggy submission (verdict: Runtime Error):
import queue

dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]

h, w = map(int, input().split())
s = []
for i in range(h) :
    s.append(input())

ans = 0

for i in range(h) :
    for j in range(w) :
        #print(i,j)
        if s[i][j] == '#' :
            continue
        dist = [[-1 for i in range(w)] for j in range(h)]
        q = queue.Queue()
        q.put([i,j])
        dist[i][j] = 0
        cnt = 0
        while not q.empty() :
            xy = q.get()
            for k in range(4) :
                y = xy[0] + dx[k]
                x = xy[1] + dy[k]
                if y < 0 or y >= h or x < 0 or x >= w :
                    continue
                if s[y][x] == '#' :
                    continue
                if dist[y][x] != -1 :
                    continue
                q.put([x, y])
                dist[y][x] = dist[xy[0]][xy[1]] + 1
        for k in range(h) :
            for l in range(w) :
                ans = max(ans, dist[k][l])
        #print(dist)


print(ans)
Problem p02936 (python)

Fixed submission:
n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]

neigh = {}

ans = [0] * n
#print(neigh)
#print(neigh)

for i in range(q) :
    ans[px[i][0] - 1] += px[i][1]

for i in range(n - 1) :
    neigh.setdefault(ab[i][0], []).append(ab[i][1])

sortKey = sorted(neigh.keys())

for k in sortKey :
    for e in neigh[k] :
        ans[e - 1] += ans[k - 1]

print(*ans)

'''
    ans[sortKey]

for i in range(len(sortKey)) :
    for j in range(i + i, len(sortKey)) :
        if sortKey[i] in neigh[sortKey[j]] :
            neigh[sortKey[j]] += neigh[sortKey[i]]
            break

    if px[i][0] in neigh :
        for e in neigh[px[i][0]] :
            ans[e - 1] += px[i][1]


print(*ans)
'''

Buggy submission (verdict: Runtime Error):
def find(a, b, neigh, ans) :
    if a in neigh :
        for v in neigh[a] :
            ans[v - 1] += b
        ans = find(v, b, neigh, ans)
        return ans
    else :
        return ans

n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]

neigh = {}

for i in range(n - 1) :
    neigh.setdefault(ab[i][0], []).append(ab[i][1])

ans = [0] * n
#print(neigh)

for i in range(q) :
    if px[i][0] in neigh :
        for e in neigh[px[i][0]] :
            ans[e - 1] += px[i][1]
            ans = find(e, px[i][1], neigh, ans)
            '''
            if e in neigh :
                for v in neigh[e] :
                    ans[v - 1] += px[i][1]
            '''
    ans[px[i][0] - 1] += px[i][1]

print(*ans)
Problem p02995 (python)

Fixed submission:
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A, B, C, D = map(int, input().split())

B_C = B // C
B_D = B // D
B_C_D = B // lcm(C, D)

A_C = (A - 1) // C
A_D = (A - 1) // D
A_C_D = (A - 1) // lcm(C, D)

B_div = B_C + B_D - B_C_D
A_div = A_C + A_D - A_C_D



print(B - A + 1 - (B_div - A_div))

Buggy submission (verdict: Runtime Error):
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A, B, C, D = map(int, input().split())

B_C = B // C
B_D = B // D
B_C_D = B // lcm(C, D)

A_C = (A - 1) // C
A_D = (A - 1) // D
A_C_D = (A - 1) // lcm(C, D)

B_div = B_C + B_D - B_C_D
A_div = A_C + A_D - A_C_D



print(B - A + 1 - (B_div - A_div))
Problem p03005 (python)

Fixed submission:
N, K = map(int, input().split())
if K == 1 :
    print(0)
else :
    print(N-K)

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

l = []
for _ in range(N) :
    ll = list(map(int, input().split()))
    l.append(ll)

#print(l)

dic = {}

for i in range(1, N) :
    #subl.append([l[i][0] - l[i-1][0], l[i][1] - l[i-1][1]])
    #k = 1000000001*(l[i][0] - l[i-1][0]) + l[i][1] - l[i-1][1]
    k = str(l[i][0] - l[i-1][0]) + '+' + str(l[i][1] - l[i-1][1])

    if l[i][0] - l[i-1][0] == 0 and l[i][1] - l[i-1][1] == 0:
        continue

    if k not in dic :
        dic[k] = 1
    else :
        dic[k] += 1

print(dic)

if len(dic) == 0 :
    print(N)
else :
    print(N - max(dic.values()))
Problem p03068 (python)

Fixed submission:
N = int(input())
S = input()
K = int(input())

a = S[K - 1]

for i in range(len(S)) :
    if S[i] != a :
        print('*', end="")
    else :
        print(S[i], end="")
print()

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

a = S[K + 1]

for i in range(len(S)) :
    if S[i] != a :
        print('*', end="")
    else :
        print(S[i], end="")
print()
Problem p03105 (python)

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

if (B / A < C) :
    print(B // A)
else :
    print(C)

Buggy submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
print(min(-(-B//A), C)
Problem p03110 (python)

Fixed submission:
sum = 0

num = int(input())

for i in range(num) :
    money, currency = input().split()
    money = float(money)
    if currency == 'JPY' :
        sum += money
    else :
        sum += money * 380000

print(sum)

Buggy submission (verdict: Runtime Error):
sum = 0

num = int(input())

if num < 1 or num > 10 :
    return
    
for i in range(num) :
    money, currency = input().split()
    money = double(money)
    if currency == 'JPY' :
        sum += money
    else :
        sum += money * 380000

print(sum)

Buggy submission (verdict: Runtime Error):
sum = 0

num = int(input())

for i in range(num) :
    money, currency = input().split()
    money = int(money)
    if currency == 'JPY' :
        sum += money
    else :
        sum += money * 380000

print(sum)

Buggy submission (verdict: Runtime Error):
sum = 0

num = int(input())

for i in range(num) :
    money = int(input())
    currency = input()
    if currency == 'JPY' :
        sum += money
    else :
        sum += money * 380000

print(sum)
Problem p03361 (python)

Fixed submission:
H, W = map(int, input().split())

l = [['P' for _ in range(W + 2)] for _ in range(H + 2)]

for i in range(H) :
    s = list(input())
    for j in range(W) :
        l[i+1][j+1] = s[j]

dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]

ans = True

for i in range(1, H + 1) :
    for j in range(1, W + 1) :
        if l[i][j] != "#" :
            continue
        flag = False
        for k in range(len(dx)) :
            if l[i + dx[k]][j + dy[k]] == "#" :
                flag = True
                break
        if flag == False :
            ans = False

if ans :
    print('Yes')
else :
    print('No')

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())

l = [['P' for _ in range(H + 2)] for _ in range(W + 2)]

for i in range(H) :
    s = list(input())
    for j in range(W) :
        l[i+1][j+1] = s[j]

dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]

ans = True

for i in range(1, H + 1) :
    for j in range(1, W + 1) :
        if l[i][j] != "#" :
            continue
        flag = False
        for k in range(len(dx)) :
            if l[i + dx[k]][j + dy[k]] == "#" :
                flag = True
                break
        if flag == False :
            ans = False

if ans :
    print('Yes')
else :
    print('No')

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())

l = [['P' for _ in range(H + 2)] for _ in range(W + 2)]

for i in range(H) :
    s = list(input())
    for j in range(W) :
        l[i+1][j+1] = s[j]

dx = [0, 0, -1, 1]
dy = [-1, 1, 0, 0]

ans = True

for i in range(1, H + 1) :
    for j in range(1, W + 1) :
        if l[i][j] != "#" :
            continue
        flag = False
        for k in range(len(dx)) :
            if l[i + dx[k]][j + dy[k]] == "#" :
                flag = True
                break
        if flag == False :
            ans = False

if ans :
    print('Yes')
else :
    print('No')
Problem p03435 (python)

Fixed submission:
c = [list(map(int, input().split())) for i in range(3) ]

ans = False

for i in range(101) :
    for j in range(101) :
        for k in range(101) :
            b1 = c[0][0] - i
            b2 = c[1][0] - i
            b3 = c[2][0] - i
            if j + b1 != c[0][1] :
                continue
            elif j + b2 != c[1][1] :
                continue
            elif j + b3 != c[2][1] :
                continue
            elif k + b1 != c[0][2] :
                continue
            elif k + b2 != c[1][2] :
                continue
            elif k + b3 != c[2][2] :
                continue
            ans = True

if ans :
    print('Yes')
else :
    print('No')

Buggy submission (verdict: Runtime Error):
c = [list(map(int, input().split())) for i in range(3) ]

ans = False

for i in range(max(101)) :
    a1 = 0
    b1 = c[0][0]
    b2 = c[0][1]
    b3 = c[0][2]
    a2 = c[1][0] - b1
    a3 = c[2][0] - b1
    a = []
    a.append(a1)
    a.append(a2)
    a.append(a3)
    if a2 + b2 != c[1][1] :
        continue
    elif a3 + b2 != c[2][1] :
        continue
    elif a2 + b3 != c[1][2] :
        continue
    elif a3 + b3 != c[2][2] :
        continue
    ans = True
    break

if ans :
    print('Yes')
else :
    print('No')

Buggy submission (verdict: Runtime Error):
c = [list(map(int, input().split())) for i in range(3) ]

ans = False

for i in range(max(c)) :
    a1 = 0
    b1 = c[0][0]
    b2 = c[0][1]
    b3 = c[0][2]
    a2 = c[1][0] - b1
    a3 = c[2][0] - b1
    a = []
    a.append(a1)
    a.append(a2)
    a.append(a3)
    if a2 + b2 != c[1][1] :
        continue
    elif a3 + b2 != c[2][1] :
        continue
    elif a2 + b3 != c[1][2] :
        continue
    elif a3 + b3 != c[2][2] :
        continue
    ans = True
    break

if ans :
    print('Yes')
else :
    print('No')
Problem p03493 (python)

Fixed submission:
print(input().count('1'))

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

count = 0
while sum(list(map(lambda x: x % 2, A))) == 0 :
    count += 1
    A = list(map(lambda x: x / 2, A))

print(count)
Problem p03644 (python)

Fixed submission:
N = int(input())

nList = [i + 1 for i in range(N)]
res = -1
counter = -1
for n in nList :
    count = 0
    buf = n
    while buf % 2 == 0 :
        count += 1
        buf = buf / 2
    if counter < count :
        counter  = count
        res = n
print(res)

Buggy submission (verdict: Runtime Error):
n = int(input())
for i in range(7) :
    if (2**i) < n :
        ans = 2**i
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
for i in range(1, 7) :
    if (2**i) < n :
        ans = 2**i
print(ans)
Problem p03658 (python)

Fixed submission:
N, K = map(int, input().split())
l= list(map(int, input().split()))

l.sort(reverse = True)
sum = 0
for i in range(K) :
    sum += l[i]
print(sum)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, k;
  cin >> n >> k;
  int l[k];
  rep(i, n) cin >> l[i];

  sort(l, l+n, greater<int>());
  int sum = 0;
  rep(i, k) sum += l[i];

  cout << sum << endl;

}
Problem p03759 (python)

Fixed submission:
a, b, c = map(int, input().split())
print('YES' if a - 2*b + c == 0 else 'NO')

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
print('YES' if a - 2b + c == 0 else 'NO')
Problem p02584 (python)

Fixed submission:
x, k, d = map(int, input().split())

def sgn(x):
    if x > 0:return 1
    if x < 0:return -1
    return 0

if x > 0:
    x_greedy = x - k * d
else:
    x_greedy = x + k * d

if sgn(x) == sgn(x_greedy):
    print(abs(x_greedy))
    exit()
x_r = x % d
x_l = x_r - d

r_parity = (abs(x - x_r) // d) % 2

if k%2 == r_parity:
    print(abs(x_r))
else:
    print(abs(x_l))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
p = [0] + list(map(int, input().split()))
c = [0] + list(map(int, input().split()))

maximum = max(c[1:])
if maximum < 0:
    print(maximum)
    exit()

used = [False] * (n+1)

ans = 0

for i in range(1, n+1):
    if used[i]:continue
    loop = [i]
    now = i
    while p[now] != i:
        now = p[now]
        loop.append(now)

    L = len(loop)
    S = sum(c[v] for v in loop)
    for a_ind in range(L):
        a = loop[a_ind]
        used[a] = True
        dist_ab = 0
        cost_ab = -c[a]
        for b_ind in range(a_ind, a_ind+L):
            b = loop[b_ind % L]
            cost_ab += c[b]
            max_cost = cost_ab + max(0, S) * ((k - dist_ab) // L)
            ans = max(ans, max_cost)
            dist_ab += 1
            if dist_ab > k:
                break

print(ans)
Problem p02603 (python)

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

money = 1000
kabu = 0

a = []

for kabuka in given_a:
    if len(a) > 0 and a[-1] == kabuka:
        continue
    else:
        a.append(kabuka)

n = len(a)

if n == 1:
    print(money)
    exit()
    
for i in range(n):
   if i == 0:
       if a[i+1] < a[i]:
           continue
       else:
           kabu += money // a[i]
           money %= a[i]
   elif i == n-1:
       money += kabu * a[i]
       kabu = 0
   else:
       if a[i-1] < a[i] and a[i] > a[i+1]:
           money += kabu * a[i]
           kabu = 0
       if a[i-1] > a[i] and a[i] < a[i+1]:
           kabu += money // a[i]
           money %= a[i]

print(money)

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

money = 1000
kabu = 0

a = []

for kabuka in given_a:
    if len(a) > 0 and a[-1] == kabuka:
        continue
    else:
        a.append(kabuka)

n = len(a)
for i in range(n):
   if i == 0:
       if a[i+1] < a[i]:
           continue
       else:
           kabu += money // a[i]
           money %= a[i]
   elif i == n-1:
       money += kabu * a[i]
       kabu = 0
   else:
       if a[i-1] < a[i] and a[i] > a[i+1]:
           money += kabu * a[i]
           kabu = 0
       if a[i-1] > a[i] and a[i] < a[i+1]:
           kabu += money // a[i]
           money %= a[i]

print(money)
Problem p02609 (python)

Fixed submission:
n = int(input())
x = input()

original_pop_count = x.count('1')
one_pop_count = original_pop_count - 1
zero_pop_count = original_pop_count + 1

one_mod = 0
zero_mod = 0
for b in x:
    if one_pop_count != 0:
        one_mod = (one_mod * 2 + int(b)) % one_pop_count
    zero_mod = (zero_mod * 2 + int(b)) % zero_pop_count


#f の前計算

f = [0] * 220000
pop_count = [0] * 220000
for i in range(1, 220000):
    pop_count[i] = pop_count[i//2] + i % 2
    f[i] = f[i % pop_count[i]] + 1

#pow2 の前計算
one_pow2 = [1] * 220000
zero_pow2 = [1] * 220000
for i in range(1, 220000):
    if one_pop_count != 0:
        one_pow2[i] = one_pow2[i-1] * 2 % one_pop_count
    zero_pow2[i] = zero_pow2[i-1] * 2 % zero_pop_count
    
# n-1, n-2, ,, 0
for i in range(n-1, -1, -1):
    if x[n-1-i] == '1':
        if one_pop_count != 0:
            nxt = one_mod
            nxt -= one_pow2[i]
            nxt %= one_pop_count
            print(f[nxt] + 1)
        else:
            print(0)
    if x[n-1-i] == '0':
        nxt = zero_mod
        nxt += zero_pow2[i]
        nxt %= zero_pop_count
        print(f[nxt] + 1)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()

original_pop_count = x.count('1')
one_pop_count = original_pop_count - 1
zero_pop_count = original_pop_count + 1

one_mod = 0
zero_mod = 0
for b in x:
    one_mod = (one_mod * 2 + int(b)) % one_pop_count
    zero_mod = (zero_mod * 2 + int(b)) % zero_pop_count


#f の前計算

f = [0] * 220000
pop_count = [0] * 220000
for i in range(1, 220000):
    pop_count[i] = pop_count[i//2] + i % 2
    f[i] = f[i % pop_count[i]] + 1

#pow2 の前計算
one_pow2 = [1] * 220000
zero_pow2 = [1] * 220000
for i in range(1, 220000):
    one_pow2[i] = one_pow2[i-1] * 2 % one_pop_count
    zero_pow2[i] = zero_pow2[i-1] * 2 % zero_pop_count
    
# n-1, n-2, ,, 0
for i in range(n-1, -1, -1):
    if x[n-1-i] == '1':
        nxt = one_mod
        #todo
        nxt -= one_pow2[i]
        nxt %= one_pop_count
        print(f[nxt] + 1)
    if x[n-1-i] == '0':
        nxt = zero_mod
        #todo
        nxt += zero_pow2[i]
        nxt %= zero_pop_count
        print(f[nxt] + 1)
Problem p02632 (python)

Fixed submission:
MOD = 10**9 + 7

fact = [1] * 2200000
invfact = [1] * 2200000

for i in range(1, 2200000):
    fact[i] = fact[i-1] * i % MOD

invfact[2200000 - 1] = pow(fact[2200000 - 1], MOD-2, MOD)

for i in range(2200000-1, 0, -1):
    invfact[i-1] = invfact[i] * i % MOD


def nCk(n, k):
    return fact[n] * invfact[k] * invfact[n-k] % MOD


k = int(input())
n = len(input())

ans = 0

for l in range(n, n+k+1):
    ans += pow(25, l - n, MOD) * nCk(l-1, n-1) * pow(26, n+k-l, MOD) % MOD
    ans %= MOD

print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 10**9 + 7

fact = [1] * 1100000
invfact = [1] * 1100000

for i in range(1, 1100000):
    fact[i] = fact[i-1] * i % MOD

invfact[1100000 - 1] = pow(fact[1100000 - 1], MOD-2, MOD)

for i in range(1100000-1, 0, -1):
    invfact[i-1] = invfact[i] * i % MOD


def nCk(n, k):
    return fact[n] * invfact[k] * invfact[n-k] % MOD


k = int(input())
n = len(input())

ans = 0

for l in range(n, n+k+1):
    ans += pow(25, l - n, MOD) * nCk(l-1, n-1) * pow(26, n+k-l, MOD) % MOD
    ans %= MOD

print(ans)