Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys
X, Y = map(int, input().split())

mod = 10 ** 9 + 7

a = (2 * Y - X) / 3
b = (2 * X - Y) / 3
if a < 0 or b < 0 or (X + Y) % 3 != 0:
    print(0)
    sys.exit()

a = int(a)
b = int(b)
N = a + b
f = [1]
invf = [1]
for i in range(1,a+b+1):
    f.append((f[-1] * i) % mod)
    invf.append(pow(f[i], mod-2, mod))
ans = f[a+b] * (invf[a] * invf[b] % mod) % mod
print(ans)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
X, Y = map(int, input().split())

mod = 10 ** 9 + 7

a = (2 * Y - X) / 3
b = (2 * X - Y) / 3
if a < 0 or b < 0 or (X + Y) % 3 != 0:
    print(0)
    sys.exit()

a = int(a)
b = int(b)
N = a + b
f = [1]
for i in range(1,a+b+1):
    f.append((f[-1] * i) % mod)
ans = f[a+b] * (pow(f[a], mod-2, mod) * pow(f[b], mod-2, mod) % mod) % mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N = int(input())
L = list(map(int,input().split()))
count = 0

L.sort()
for i in range(0,N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if L[k] >= L[i] +L[j]:
                break
            if L[i] < L[j] +L[k] and L[j] < L[k] + L[i]:
                count += 1
            else: 
                break
                
print(count)

Fixed submission:
# -*- coding: utf-8 -*-
import bisect

N = int(input())
L = list(map(int,input().split()))

count = 0
L.sort()
for i in range(N-2):
    for j in range(i+1,N-1):
        k = bisect.bisect_left(L,L[i]+L[j])
        count += k - j - 1 
        
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N = int(input())
L = list(map(int,input().split()))
count = 0

L.sort(reverse = True)
for i in range(0,N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if L[k] >= L[i] +L[j]:
                break
            if L[i] < L[j] +L[k] and L[j] < L[k] + L[i]:
                count += 1
            else: 
                break
                
print(count)

Fixed submission:
# -*- coding: utf-8 -*-
import bisect

N = int(input())
L = list(map(int,input().split()))

count = 0
L.sort()
for i in range(N-2):
    for j in range(i+1,N-1):
        k = bisect.bisect_left(L,L[i]+L[j])
        count += k - j - 1 
        
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N = int(input())
L = list(map(int,input().split()))
count =0

L.sort(reverse = True)
for i in range(0,N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if L[i] < L[j] +L[k] and L[j] < L[k] + L[i] and L[k] < L[i] +L[j]:
                count += 1
            else: 
                break
                
print(count)

Fixed submission:
# -*- coding: utf-8 -*-
import bisect

N = int(input())
L = list(map(int,input().split()))

count = 0
L.sort()
for i in range(N-2):
    for j in range(i+1,N-1):
        k = bisect.bisect_left(L,L[i]+L[j])
        count += k - j - 1 
        
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
N = int(input())
L = list(map(int,input().split()))
count =0
for i in range(0,N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if L[i] < L[j] +L[k] and L[j] < L[k] + L[i] and L[k] < L[i] +L[j]:
                count += 1
                
print(count)

Fixed submission:
# -*- coding: utf-8 -*-
import bisect

N = int(input())
L = list(map(int,input().split()))

count = 0
L.sort()
for i in range(N-2):
    for j in range(i+1,N-1):
        k = bisect.bisect_left(L,L[i]+L[j])
        count += k - j - 1 
        
print(count)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math

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

ans = 0

CD = (C * D) // math.gcd(C, D) 

def l(a, x):
    if a // x == 0:
        return 1
    if a % x != 0:
        t = a // x + 1
        return t
    t = a // x
    return t

cl = l(A, C)
dl = l(A, D)
cdl = l(A, CD)
cr = B // C
dr = B // D
cdr = B // (CD)

ans = B - A + 1 - (cr - cl + 1) - (dr - dl + 1) + (cdr - cdl + 1)
        
print(ans)

Fixed submission:
# -*- coding: utf-8 -*-
A, B, C, D = map(int, input().split())

ans = 0
def gcd(a, b):
    while b :
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

CD = (C * D) // gcd(C, D) 

def l(a, x):
    if a // x == 0:
        return 1
    if a % x != 0:
        t = a // x + 1
        return t
    t = a // x
    return t

cl = l(A, C)
dl = l(A, D)
cdl = l(A, CD)
cr = B // C
dr = B // D
cdr = B // (CD)

ans = B - A + 1 - (cr - cl + 1) - (dr - dl + 1) + (cdr - cdl + 1)
        
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import Counter

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

pq = []

for x, y in A:
    for i, j in A:
        if x == i and y == j:
            continue
        pq.append(str(i-x)+str(j-y))

ans = Counter(pq).most_common()

print(N - ans[0][1])

Fixed submission:
from collections import Counter

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

pq = []

for x, y in A:
    for i, j in A:
        if x == i and y == j:
            continue
        pq.append(str(i-x)+str(j-y))

ans = Counter(pq).most_common()

if ans == []:
    print(1)
else:
    print(N - ans[0][1])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(M):
    B, C = map(int, input().split())
    A += [C] * B
A.sort()
A = A[-N:]
print(sum(A))

Fixed submission:
import numpy as np
from collections import Counter

N, M = map(int, input().split())
A = list(map(int, input().split()))
B = []
C = []
for _ in range(M):
    b1, c1 = map(int, input().split())
    B.append(b1)
    C.append(c1)

A = list(Counter(A).items())

for i in range(len(A)):
    C.append(A[i][0])
    B.append(A[i][1])
 
d = np.argsort(C)[::-1]
B = [B[i] for i in d]
C = [C[i] for i in d]

i = 0
c = 0
ans = 0
while True:
    if c + B[i] < N:
        ans += C[i] * B[i]
        c += B[i]
        i += 1
    else:
        ans += C[i] * (N - c)
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(M):
    B, C = map(int, input().split())
    A = A + [C] * B
    A.sort()
    A = A[-N:]
print(sum(A))

Fixed submission:
import numpy as np
from collections import Counter

N, M = map(int, input().split())
A = list(map(int, input().split()))
B = []
C = []
for _ in range(M):
    b1, c1 = map(int, input().split())
    B.append(b1)
    C.append(c1)

A = list(Counter(A).items())

for i in range(len(A)):
    C.append(A[i][0])
    B.append(A[i][1])
 
d = np.argsort(C)[::-1]
B = [B[i] for i in d]
C = [C[i] for i in d]

i = 0
c = 0
ans = 0
while True:
    if c + B[i] < N:
        ans += C[i] * B[i]
        c += B[i]
        i += 1
    else:
        ans += C[i] * (N - c)
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(M):
    B, C = map(int, input().split())
    A = A + [C] * B
    A.sort()
    A = A[-N:]
print(sum(A))

Fixed submission:
import numpy as np
from collections import Counter

N, M = map(int, input().split())
A = list(map(int, input().split()))
B = []
C = []
for _ in range(M):
    b1, c1 = map(int, input().split())
    B.append(b1)
    C.append(c1)

A = list(Counter(A).items())

for i in range(len(A)):
    C.append(A[i][0])
    B.append(A[i][1])
 
d = np.argsort(C)[::-1]
B = [B[i] for i in d]
C = [C[i] for i in d]

i = 0
c = 0
ans = 0
while True:
    if c + B[i] < N:
        ans += C[i] * B[i]
        c += B[i]
        i += 1
    else:
        ans += C[i] * (N - c)
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ans = [-1] * N

def find(x):
    global ans
    if ans[x] == -1:
        return x
    else:
        return find(ans[x])
    
for _ in range(M):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    xx = find(x)
    yy = find(y)
    if ans[x] == ans[y] == -1:
        ans[y] = x
    elif xx == yy:
        continue
    else:
        ans[yy] = xx

n = 0
for i in ans:
    if i == -1:
        n += 1

print(n)

Fixed submission:
N, M = map(int, input().split())
ans = [-1] * N

def find(x):
    global ans
    if ans[x] == -1:
        return x
    else:
        ans[x] = find(ans[x])
        return ans[x]
    
for _ in range(M):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    xx = find(x)
    yy = find(y)
    if ans[x] == ans[y] == -1:
        ans[y] = x
    elif xx == yy:
        continue
    else:
        ans[yy] = xx

n = 0
for i in ans:
    if i == -1:
        n += 1

print(n)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
ans = [-1] * N

def find(x):
    global ans
    if ans[x] == -1:
        return x
    else:
        return find(ans[x])
    
for _ in range(M):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    xx = find(x)
    yy = find(y)
    if ans[x] == ans[y] == -1:
        ans[y] = x
    elif xx == yy:
        continue
    else:
        ans[yy] = xx

n = 0
for i in ans:
    if i == -1:
        n += 1

print(n)

Fixed submission:
N, M = map(int, input().split())
ans = [-1] * N

def find(x):
    global ans
    if ans[x] == -1:
        return x
    else:
        ans[x] = find(ans[x])
        return ans[x]
    
for _ in range(M):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    xx = find(x)
    yy = find(y)
    if ans[x] == ans[y] == -1:
        ans[y] = x
    elif xx == yy:
        continue
    else:
        ans[yy] = xx

n = 0
for i in ans:
    if i == -1:
        n += 1

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

N = int(input())
A = list(map(int, input().split()))

L = [0] * (N+1)
R = [0] * (N+2)

for i in range(N):
    L[i+1] = gcd(L[i],A[i])
for i in range(N)[::-1]:
    R[i+1] = gcd(R[i+2],A[i])
    
ans = 0

for i in range(1,N+1):
    ans = max(ans, gcd(L[i-1], R[i+1]))

print(ans)

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

def gcd(a, b):
    while b :
        a, b = b, a % b
    return a

L = [0] * (N+1)
R = [0] * (N+2)

for i in range(N):
    L[i+1] = gcd(L[i],A[i])
for i in range(N)[::-1]:
    R[i+1] = gcd(R[i+2],A[i])
    
ans = 0

for i in range(1,N+1):
    ans = max(ans, gcd(L[i-1], R[i+1]))

print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import groupby
import sys

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

S = [[i, len(list(j))] for i, j in groupby(S)]

if len(S) // 2 <= K:
    if len(S) % 2 == 1 and S[-1][0] == "0":
        pass
    else:
        print(sum([j for i, j in S]))
        sys.exit()

ans = 0
cnt = 0
lidx = -1
for i, j in S:
    lidx += 1
    if cnt == K and i == "0":
        break
    ans += j
    if i == "0":
        cnt += 1
sidx = 0
mans = ans
for i in range(lidx,len(S)):
    ans += S[i][1]
    if i == len(S)-1 or S[i][0] == "1":
        while True:
            ans -= S[sidx][1]
            sidx += 1
            if S[sidx][0] == "1":
                break
        mans = max(mans, ans)

print(mans)


        
        

Fixed submission:
from itertools import groupby
import sys

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

S = [[i, len(list(j))] for i, j in groupby(S)]

if len(S) // 2 <= K:
    if len(S) % 2 == 1 and S[-1][0] == "0":
        if len(S) == 1:
            print(sum([j for i, j in S]))
            sys.exit()
            
    else:
        print(sum([j for i, j in S]))
        sys.exit()

ans = 0
cnt = 0
lidx = -1
for i, j in S:
    lidx += 1
    if cnt == K and i == "0":
        break
    ans += j
    if i == "0":
        cnt += 1
sidx = 0
mans = ans
for i in range(lidx,len(S)):
    ans += S[i][1]
    if i == len(S)-1 or S[i][0] == "1":
        while True:
            ans -= S[sidx][1]
            sidx += 1
            if S[sidx][0] == "1":
                break
        mans = max(mans, ans)

print(mans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
S = input()

mod = 10 ** 9 + 7
s = list(Counter(S).values())

ans = 0 
for i in range(1, 1 << len(s)):
    k = 1
    for j in range(len(s)):
        if (i >> j) & 1 == 1:
            k *= s[j]
            k %= mod
    ans += k
    ans %= mod
    
print(ans)

Fixed submission:
from collections import Counter

N = int(input())
S = input()

mod = 10 ** 9 + 7
s = list(Counter(S).values())

ans = 1 
for i in s:
    ans *= (i+1)
    ans %= mod
print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
S = input()

mod = 10 ** 9 + 7
s = list(Counter(S).values())

ans = 0 
for i in range(1, 1 << len(s)):
    k = 1
    for j in range(len(s)):
        if (i >> j) & 1 == 1:
            k *= s[j]
            k %= mod
    ans += k
    ans %= mod
    
print(ans)

Fixed submission:
from collections import Counter

N = int(input())
S = input()

mod = 10 ** 9 + 7
s = list(Counter(S).values())

ans = 1 
for i in s:
    ans *= (i+1)
    ans %= mod
print(ans-1)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

cost = [0] + [float("inf") for _ in range(N-1)]
    
for i in range(1,N):
    t = max(0, i - K)
    for j in range(t,i):
        cost[i] = min(cost[i], cost[j] + abs(h[i] - h[j])) 
    
print(cost[-1])

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

cost = [0 for _ in range(N)]
K = min(N, K)
for i in range(1,K):
    cost[i] = abs(h[0] - h[i])
    
for i in range(1,N):
    t = max(0, i - K)
    for j in range(t,i):
        if j == t:
            cost[i] = cost[j] + abs(h[i] - h[j])
        else:
            cost[i] = min(cost[i], cost[j] + abs(h[i] - h[j])) 
    
print(cost[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))

cost = [0 for _ in range(N)]
K = min(N, K)
for i in range(1,K):
    cost[i] = abs(h[0] - h[i])
    
for i in range(1,N):
    t = max(0, i - K)
    for j in range(t,i):
        if j == t:
            cost[i] = cost[j] + abs(h[i] - h[j])
        else:
            cost[i] = min(cost[i], cost[j] + abs(h[i] - h[j])) 
    
print(cost[-1])

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

cost = [0 for _ in range(N)]
K = min(N, K)
for i in range(1,K):
    cost[i] = abs(h[0] - h[i])
    
for i in range(1,N):
    t = max(0, i - K)
    for j in range(t,i):
        if j == t:
            cost[i] = cost[j] + abs(h[i] - h[j])
        else:
            cost[i] = min(cost[i], cost[j] + abs(h[i] - h[j])) 
    
print(cost[-1])
Buggy python submission (verdict: Runtime Error):
from collections import Counter

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

a = Counter(v[::2])
b = Counter(v[1::2])
a = a.most_common()
b = b.most_common()

if n % 2 == 0:
    al = n // 2
    bl = al
else:
    al = n // 2 + 1
    bl = n // 2

if len(a) == 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print(min(a[0][1], b[0][1]))
    else:
        print(0)
elif len(a) == 1 or len(bl) == 1:
    if len(a) == 1:
        if a[0][0] == b[0][0]:
            print(bl - b[1][1])
        else:
            print(bl - b[0][1])
    if len(b) == 1:
        if a[0][0] == b[0][0]:
            print(al - a[1][1])
        else:
            print(al - a[0][1])
else:
     if a[0][0] == b[0][0]:
         print(min(n - a[0][1] - b[1][1], n - a[1][1] - b[0][1])) 
     else:
         print(n - a[0][1] - b[0][1])


Fixed submission:
from collections import Counter

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

a = Counter(v[::2])
b = Counter(v[1::2])
a = a.most_common()
b = b.most_common()

if n % 2 == 0:
    al = n // 2
    bl = al
else:
    al = n // 2 + 1
    bl = n // 2

if len(a) == 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print(min(a[0][1], b[0][1]))
    else:
        print(0)
elif len(a) == 1 or len(b) == 1:
    if len(a) == 1:
        if a[0][0] == b[0][0]:
            print(bl - b[1][1])
        else:
            print(bl - b[0][1])
    if len(b) == 1:
        if a[0][0] == b[0][0]:
            print(al - a[1][1])
        else:
            print(al - a[0][1])
else:
     if a[0][0] == b[0][0]:
         print(min(n - a[0][1] - b[1][1], n - a[1][1] - b[0][1])) 
     else:
         print(n - a[0][1] - b[0][1])
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))

a.sort()
m = a[-1] // 2 + a[-1] % 2

i = bisect_left(a, m)

if i == 0:
    ans = str(a[-1]) + " " + str(a[0])
elif i == len(a)-1:
    ans = str(a[-1]) + " " + str(a[-2])
else:
    k = [a[i] - m, m - a[-1] % 2 - a[i-1]]
    s = min(m - a[-1] % 2 - a[i-1], a[i] - m)
    k.index(s)
    ans = str(a[-1]) + " " + str(a[i-s])     

print(ans)

Fixed submission:
from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))

a.sort()
m = a[-1] // 2 + a[-1] % 2

i = bisect_left(a, m)

if i == 0:
    ans = str(a[-1]) + " " + str(a[0])
elif i == len(a)-1:
    ans = str(a[-1]) + " " + str(a[-2])
else:
    k = [a[i] - m, m - a[-1] % 2 - a[i-1]]
    s = min(k)
    s = k.index(s)
    ans = str(a[-1]) + " " + str(a[i-s])     

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse.csgraph import dijkstra

H, W = map(int, input().split())
s = [input() for _ in range(H)]

graph = [[0 for _ in range(H*W)] for _ in range(H*W)]

for i in range(H):
    for j in range(W-1):
        if s[i][j] == s[i][j+1] == ".":
            graph[j+(W*i)][j+(W*i)+1] = 1
            graph[j+(W*i)+1][j+(W*i)] = 1

for i in range(H-1):        
    for j in range(W):
        if s[i][j] == s[i+1][j] == ".":
            graph[j+(W*i)][j+(W*(i+1))] = 1
            graph[j+(W*(i+1))][j+(W*i)] = 1
            
d = dijkstra(graph)

cnt = 0
for i in s:
    for j in range(W):
        if i[j] == ".":
            cnt += 1
      
if d[0][H*W-1] == float("inf"):
    print(-1)
else:
    print(int(cnt-d[0][H*W-1]-1))

Fixed submission:
from collections import deque

H, W = map(int, input().split())
S = [input() for i in range(H)]
C = sum(i.count('.') for i in S)

dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
que = deque([(0, 0, 0)])
used = {(0, 0)}

res = []
while que:
    s, t, cost = que.popleft()
    if s == H-1 and t == W-1:
        res = cost
        break
    for di, dj in dd:
        xi = s + di; yj = t + dj
        if (not 0 <= xi < H) or (not 0 <= yj < W) or S[xi][yj] == '#' or (xi, yj) in used:
            continue
        used.add((xi, yj))
        que.append((xi, yj, cost + 1))
if res:
    print(C - 1 - res)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
Q = int(input())
n = 10 ** 5
L = [0] * 2 + [1] * (n-1)

for i in range(int(n ** 0.5)+1):
    if L[i] == 1:
        j = 2
        while i * j <= n:
            L[i*j] = 0
            j += 1
            
T = [0] * (n+1)
for i in range(3,n):
    if L[i] == 1 and L[(i+1) // 2] == 1:
        T[i] = 1    
    
for i in range(Q):
    l, r = map(int, input().split())
    print(sum(T[l:r+1]))

Fixed submission:
from itertools import accumulate

Q = int(input())
n = 10 ** 5
L = [0] * 2 + [1] * (n-1)

for i in range(int(n ** 0.5)+1):
    if L[i] == 1:
        j = 2
        while i * j <= n:
            L[i*j] = 0
            j += 1
            
T = [0] * (n+1)
for i in range(3,n):
    if L[i] == 1 and L[(i+1) // 2] == 1:
        T[i] = 1    
s = list(accumulate(T))
    
for i in range(Q):
    l, r = map(int, input().split())
    print(s[r]-s[l-1])
Buggy python submission (verdict: Runtime Error):
import numpy as np
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

m = np.argsort(a)[::-1]
n = [str(i+1) for i in m]
c = [a[i] for i in m]

ans = ["" for _ in range(H)]
j = 0
for i in range(H):
    count = 0
    while count != W:
        if count + c[i] <= W:
            ans[i] += n[j] * c[j]
            count += c[j]
            j += 1
        else:
            count = W - count
            ans[i] += n[j] * count
            c[j] -= count 
            count = W

for i in range(H):
    if i % 2 == 0:
        print(" ".join(ans[i][::-1]))
    else:
        print(" ".join(ans[i]))

Fixed submission:
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(N):
  ans.extend([i+1 for _ in range(a[i])])
ans = [ans[i:i+W] for i in range(0, H*W, W)]
for i in range(1, H, 2):
  ans[i] = ans[i][::-1]
for r in ans:
  print(' '.join(map(str,r)))

Buggy python submission (verdict: Runtime Error):
import numpy as np
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))

m = np.argsort(a)[::-1]
n = [str(i+1) for i in m]
c = [a[i] for i in m]

ans = ["" for _ in range(H)]
j = 0
for i in range(H):
    count = 0
    while count != W:
        if count + c[i] <= W:
            ans[i] += n[j] * c[j]
            count += c[j]
            j += 1
        else:
            count = W - count
            ans[i] += n[j] * count
            count = W

for i in range(H):
    if i % 2 == 0:
        print(" ".join(ans[i][::-1]))
    else:
        print(" ".join(ans[i]))

Fixed submission:
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(N):
  ans.extend([i+1 for _ in range(a[i])])
ans = [ans[i:i+W] for i in range(0, H*W, W)]
for i in range(1, H, 2):
  ans[i] = ans[i][::-1]
for r in ans:
  print(' '.join(map(str,r)))
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())

ans = K * ((K-1) ** (N-1))

Fixed submission:
N, K = map(int,input().split())
print(K * ((K-1) ** (N-1)))
Buggy python submission (verdict: Runtime Error):
from itertools import groupby
x = [[i,len(list(j))] for i,j in groupby(input())]

ans = []
if x[0][0] == "T":
    ans.append(x[0][1])
if x[-1][0] == "S":
    ans.append(x[-1][1])
    
print(max(ans)*2)

Fixed submission:
X = input()

ans = 0
cnt = 0
for i in range(len(X)):
    if cnt == 0 and X[i] == "T":
        ans += 1
    else:
        if X[i] == "T":
            cnt += 1
        else:
            cnt -= 1

print(ans*2)
Buggy python submission (verdict: Time Limit Exceeded):
M = 1000000007

def nCr(n, k): 
    C = [[0 for x in range(k+1)] for x in range(n+1)] 
  
    for i in range(n+1): 
        for j in range(min(i, k)+1): 
            if j == 0 or j == i: 
                C[i][j] = 1
  
            else: 
                C[i][j] = C[i-1][j-1] + C[i-1][j] 
  
    return C[n][k] 

x, y , z = map(int,input().split()) 
ans = pow(2,x)-1
ans = ans - nCr(x,y)
ans = ans - nCr(x,z)
ans = ans%M

print(int(ans))


Fixed submission:
def nrc_mod(n, r, mod=10**9+7):
    r = min(n - r, r)
    if r == 0:
        return 1
 
    over = 1
    for i in range(n, n - r, -1):
        over = over * i % mod
 
    under = 1
    for i in range(1, r + 1):
        under = under * i % mod
 
    inv = pow(under, mod - 2, mod)
    return over * inv % mod
 
 
n, a, b = map(int, input().split())
MOD = 10**9 + 7

ans = pow(2, n, MOD) - 1
ans -= nrc_mod(n, a, MOD)
ans -= nrc_mod(n, b, MOD)
while ans < 0:
    ans += MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int, input().split()))

ans = a[0]
for x in a:
  ans = math.gcd(ans, x)
print(ans)

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

ans = a[0]
for x in a:
  ans = fractions.gcd(ans, x)
print(ans)