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

Fixed submission:
import heapq
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
Q = []
heapq.heappush(Q, (-A[0]-B[0]-C[0], 0, 0, 0))
for n in range(K):
    ans = heapq.heappop(Q)
    print(-ans[0])
    i, j, k = ans[1], ans[2], ans[3]
    if i < X-1:
        if (- A[i+1] - B[j] - C[k], i+1, j, k) not in Q:
            heapq.heappush(Q, (- A[i+1] - B[j] - C[k], i+1, j, k))
    if j < Y-1:
        if (- A[i] - B[j+1] - C[k], i, j+1, k) not in Q:
            heapq.heappush(Q, (- A[i] - B[j+1] - C[k], i, j+1, k))
    if k < Z-1:
        if (- A[i] - B[j] - C[k+1], i, j, k+1) not in Q:
            heapq.heappush(Q, (- A[i] - B[j] - C[k+1], i, j, k+1))

Buggy submission (verdict: Runtime Error):
# solution 3
import heapq
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
Q = []
s = set()
heapq.heappush(Q, (-A[0]-B[0]-C[0], 0, 0, 0))
for n in range(K):
    q, i, j, k = heapq.heappop(Q)
    print(-q)
    if i < X-1 and [i+1, j, k] not in s:
            heapq.heappush(Q, (- A[i+1] - B[j] - C[k], i+1, j, k))
            s.add((i + 1, j, k))
    if j < Y-1 and [i, j+1, k] not in s:
            heapq.heappush(Q, (- A[i] - B[j+1] - C[k], i, j+1, k))
            s.add((i, j + 1, k))
    if k < Z-1 and [i, j, k+1] not in s:
            heapq.heappush(Q, (- A[i] - B[j] - C[k+1], i, j, k+1))
            s.add((i, j, k + 1))
Problem p03087 (python)

Fixed submission:
N, Q = map(int, input().split())
S = input()
T = [0]*N
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        T[i] = T[i-1] + 1
    else:
        T[i] = T[i-1]
for j in range(Q):
    left, right = map(int, input().split())
    print(T[right-1]-T[left-1])

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
T = [0]*N
for i in range(1, N):
    if S[i-1:i+1] == 'AC':
        T[i] = T[i-1] + 1
    else:
        T[i] = T[i-1]
for j in range(Q):
    left, right = map(int, input().split())
    print(T[right]-T[left-1])
Problem p03149 (python)

Fixed submission:
L = list(map(int, input().split()))
L.sort()
if L == [1, 4, 7, 9]:
	print('YES')
else:
  	print('NO')

Buggy submission (verdict: Runtime Error):
L = list(map(int, input().split()))
L.sort()
if L == [1, 4, 7, 9]:
  print(YES)
else:
  print(NO)

Buggy submission (verdict: Runtime Error):
L = list(map(int, input().split()))
L.sort()
if L == [1, 4, 7, 9]:
	print(YES)
else:
  	print(NO)
Problem p03150 (python)

Fixed submission:
S = list(input())
L = list('keyence')
while len(L)*len(S) > 0 and L[0] == S[0]:
    del L[0]
    del S[0]
while len(L)*len(S) > 0 and L[-1] == S[-1]:
    del L[-1]
    del S[-1]
if L == []:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
S = list(input())
L = list('keyence')
if len(L) > len(S):
	print('NO')
else:
    while L[0] == S[0]:
        L = L[1:]
        S = S[1:]
    while len(L) != 0 and L[-1] == S[-1]:
        L = L[:-1]
        S = S[:-1]
    if L == []:
        print('YES')
    else:
        print('NO')

Buggy submission (verdict: Runtime Error):
S = list(input())
L = list('keyence')
if len(L) > len(S):
	print('NO')
else:
	while L[0] == S[0]:
    	L = L[1:]
    	S = S[1:]
	while len(L) != 0 and L[-1] == S[-1]:
    	L = L[:-1]
    	S = S[:-1]
	if L == []:
    	print('YES')
	else:
    	print('NO')

Buggy submission (verdict: Runtime Error):
S = list(input())
L = list('keyence')
while L[0] == S[0]:
    L = L[1:]
    S = S[1:]
while len(L)*len(S) != 0 and L[-1] == S[-1]:
    L = L[:-1]
    S = S[:-1]
if L == []:
    print('YES')
else:
    print('NO')
Problem p03219 (python)

Fixed submission:
X, Y = map(int, input().split())
print(X + Y//2)

Buggy submission (verdict: Runtime Error):
import numpy as np
H, W, K = map(int, input().split())
p = 10**9 + 7
r = [1, 1, 2, 3, 5, 8, 13, 21, 34]
dp = np.zeros([H + 1, W], dtype=int)
dp[0, 0] = 1
for h in range(H):
    for w in range(W):
        if w != 0:
            dp[h+1, w] += ((dp[h, w-1] * r[w-1])%p * r[W-1-w])%p
        dp[h+1, w] += ((dp[h, w] * r[w])%p * r[W-1-w])%p
        if w != W-1:
            dp[h+1, w] += ((dp[h, w+1] * r[w])%p * r[W-2-w])%p
        dp[h+1, w] = dp[h+1, w]%p
print(dp[H, K-1])
Problem p03238 (python)

Fixed submission:
N = int(input())
if N == 1:
  print('Hello World')
else:
  A = int(input())
  B = int(input())
  print(A+B)

Buggy submission (verdict: Runtime Error):
N = int(input())
If N == 1:
  print('Hello World')
else:
  A = int(input())
  B = int(input())
  print(A+B)
Problem p03240 (python)

Fixed submission:
import sys
N = int(input())
X = []
Y = []
H = []
for i in range(N):
    x, y, h = map(int, input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
while H[0] == 0:
    X.append(X[0])
    Y.append(Y[0])
    H.append(H[0])
    X = X[1:]
    Y = Y[1:]
    H = H[1:]
x1 = X[0]
y1 = Y[0]
h1 = H[0]
for Cx in range(101):
    for Cy in range(101):
        h = h1 + abs(x1-Cx) + abs(y1-Cy)
        i = 1
        while i < N and H[i] == max(h - abs(X[i]-Cx) - abs(Y[i]-Cy), 0):
            i += 1
        if i == N:
            print(Cx, Cy, h)
            sys.exit()

Buggy submission (verdict: Runtime Error):
import sys
N = int(input())
X = []
Y = []
H = []
for i in range(N):
    x, y, h = map(int, input().split())
    if h != 0:
        X.append(x)
        Y.append(y)
        H.append(h)
x1 = X[0]
y1 = Y[0]
h1 = H[0]
for Cx in range(101):
    for Cy in range(101):
        h = h1 + abs(x1-Cx) + abs(y1-Cy)
        i = 1
        while i < N and h == H[i] + abs(X[i]-Cx) + abs(Y[i]-Cy):
            i += 1
        if i == N:
            print(Cx, Cy, h)
            sys.exit()
Problem p03241 (python)

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

def primefactorize(n):
    fct = []  # return [[p1, power1], [p2, power2], ...]
    p, power = 2, 0
    while p * p <= n:
        while n % p == 0:
            n = n // p
            power += 1
        if power > 0:
            fct.append([p, power])
        if p == 2:
            p += 1
        else:
            p += 2
        power = 0
    if n > 1:
        fct.append([n, 1])
    return fct

def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]

def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

if M != 1:
    fct = primefactorize(M)
    factors = []
    for div in divisorize(fct):
        factors.append(num(div))
else:
    factors = [1]
factors.sort()
k = M//N
L = [x for x in factors if x <= k]
print(max(L))

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

def primefactorize(n):
    fct = []  # return [[p1, power1], [p2, power2], ...]
    p, power = 2, 0
    while p * p <= n:
        while n % p == 0:
            n = n // p
            power += 1
        if power > 0:
            fct.append([p, power])
        if p == 2:
            p += 1
        else:
            p += 2
        power = 0
    if n > 1:
        fct.append([n, 1])
    return fct

def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]

def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

fct = primefactorize(M)
factors = []
for div in divisorize(fct):
    factors.append(num(div))

factors.sort()
k = M//N
L = [x for x in factors if x <= k]
print(max(L))

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

def primefactorize(n):
    fct = []  # return [[p1, power1], [p2, power2], ...]
    p, power = 2, 0
    while p * p <= n:
        while n % p == 0:
            n = n // p
            power += 1
        if power > 0:
            fct.append([p, power])
        if p == 2:
            p += 1
        else:
            p += 2
        power = 0
    if n > 1:
        fct.append([n, 1])
    return fct

def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]

def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

fct = primefactorize(M)
factors = []
for div in divisorize(fct):
    factors.append(num(div))

factors.sort()
cd = 0
k = M/N
for x in factors:
    if x <= k:
        cd = max(cd, x)
print(cd)
Problem p03262 (python)

Fixed submission:
N, X = map(int, input().split())
L = list(map(int, input().split()))
M = [abs(i-X) for i in L if i-X != 0]
n = len(M)
old = M[0]
def gcd(a, b):
    if min(a, b) == 0:
        return max(a, b)
    else:
        m = max(a, b)
        n = min(a, b)
        return gcd(n, m%n)
if n > 1:
    for i in range(n-1):
        new = M[i+1]
        old = gcd(old, new)
print(old)

Buggy submission (verdict: Runtime Error):
import math
N, X = map(int, input().split())
L = list(map(int, input().split()))
M = [abs(i-X) for i in L if i-X != 0]
n = len(M)
old = M[0]
if n > 1:
    for i in range(n-1):
        new = M[i+1]
        old = math.gcd(old, new)
print(old)
Problem p03263 (python)

Fixed submission:
H, W = map(int, input().split())
A = [0]
idx_list = []
for i in range(H):
    L = list(map(int, input().split()))
    M = []
    for j in range(W):
        M.append([i+1, j+1])
    if i%2 != 0:
        L.reverse()
        M.reverse()
    idx_list.extend(M)
    for j in range(W):
        A.append((A[-1]+L[j])%2)
A = A[1:-1]
N = sum(A)
print(N)
if N != 0:
    a = A.index(1)
    iter = 0

    while iter<N:
        if A[a] == 1:
            print(idx_list[a][0], idx_list[a][1], idx_list[a+1][0], idx_list[a+1][1])
            iter += 1
        a += 1

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
A = [0]
idx_list = []
for i in range(H):
    L = list(map(int, input().split()))
    M = []
    for j in range(W):
        M.append([i+1, j+1])
    if i%2 != 0:
        L.reverse()
        M.reverse()
    idx_list.extend(M)
    for j in range(W):
        A.append((A[-1]+L[j])%2)
A = A[1:-1]
a = A.index(1)
N = sum(A)
print(N)
iter = 0

while iter<N:
    if A[a] == 1:
        print(idx_list[a][0], idx_list[a][1], idx_list[a+1][0], idx_list[a+1][1])
        iter += 1
    a += 1

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
A = [0]
idx_list = []
for i in range(H):
    L = list(map(int, input().split()))
    M = []
    for j in range(W):
        M.append([i+1, j+1])
    if i%2 != 0:
        L.reverse()
        M.reverse()
    idx_list.extend(M)
    for j in range(W):
        A.append((A[-1]+L[j])%2)
A = A[1:-2]
a = A.index(1)
N = sum(A)
print(N)
iter = 0

while iter<N:
    if A[a] == 1:
        print(idx_list[a][0], idx_list[a][1], idx_list[a+1][0], idx_list[a+1][1])
        iter += 1
    a += 1

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
A = []
B = []
for i in range(H):
    L = list(map(int, input().split()))
    M = [j%2 for j in L]
    if i%2 != 0:
        M.reverse()
    A.extend(M)

indices = [i for i, x in enumerate(A) if x == 1]

def countiter(indices):
    if len(indices) == 0 or len(indices) == 1:
        return 0
    elif len(indices) == 2:
        return indices[1]-indices[0]
    else:
        return indices[1]-indices[0]+countiter(indices[2:])

N = countiter(indices)
print(N)
iter = 0
while iter<N:
    a = indices[0]
    b = indices[1]
    h = (a+1)//W + 1
    if h%2 != 0:
        w = a-(h-1)*W+1
        wchange = 1
    else:
        w = h*W-a
        wchange = -1
    while a < b:
        if w == 1 and wchange == -1:
            print(h, w, h+1, w)
            h += 1
            wchange *= -1
            iter += 1
            a += 1
        elif w == W and wchange == 1:
            print(h, w, h+1, w)
            h += 1
            wchange *= -1
            iter += 1
            a += 1
        else:
            print(h, w, h, w + wchange)
            w += wchange
            iter += 1
            a += 1
    indices[0:2] = []
Problem p03274 (python)

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

minp = 0
if X[N-1] <0:
    minp = N-1
else:
    while X[minp] < 0:
        minp += 1

lidx = 0
if minp > K:
    lidx = minp - K
ridx = lidx + K - 1
left = X[lidx]
right = X[ridx]
mind = right - left + min(abs(left), abs(right))

while ridx < N and left <= minp:
    left = X[lidx]
    right = X[ridx]
    mind = min(mind, right - left + min(abs(left), abs(right)))
    lidx += 1
    ridx += 1

print(mind)

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

minp = 0
while X[minp] < 0:
    minp += 1
lidx = 0
if minp > K:
    lidx = minp - K
ridx = lidx + K - 1
left = X[lidx]
right = X[ridx]
mind = right - left + min(abs(left), abs(right))

while ridx < N and left <= minp:
    left = X[lidx]
    right = X[ridx]
    mind = min(mind, right - left + min(abs(left), abs(right)))
    lidx += 1
    ridx += 1

print(mind)
Problem p02684 (python)

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

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

check = [0] * n

start = 0
path = []
for i in range(n):
    if check[start] == 0:
        check[start] = 1
        path.append(start)
        start = A[start] - 1
path.append(start)

before_roop = path[:path.index(path[-1])]
B = before_roop
if before_roop == []:
    before_roop = 0
else:
    before_roop = len(before_roop)

roop = len(path) - before_roop - 1

if k <= before_roop:
    print(path[:before_roop+1][k] + 1)
else:
    k -= before_roop
    k = k % roop
    print(path[before_roop+1:][k-1] + 1)

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

stayed = [0] * (n+1)

A = list(map(int, input().split()))
start = 0
stayed[0] = 1
roops = 0
ANS = []
for i in range(n+1):
    if stayed[A[start] - 1] == 0:
        stayed[A[start] - 1] = 1
        start = A[start] - 1
        ANS.append(start)
        roops += 1
    else:
        break
index_ = ANS.index(start - 1)
before_roop = index_ + 1
if index_ == 0:
    before_roop = 0
true_roop = len(ANS) - index_

if true_roop + before_roop >= k:
    ANS = [0] + ANS + [start -1]
    print(ANS[k] + 1)
else:
    k = k - before_roop
    k = k % true_roop
    ANS = ANS[index_:]
    print(ANS[k] + 1)
Problem p02747 (python)

Fixed submission:
s = list(input())

out = 0

if len(s) % 2 != 0:
    print("No")
else:
    for i in range(0, len(s), 2):
        if s[i] == 'h' and s[i+1] == 'i':
            continue
        else:
            out = 1

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

Buggy submission (verdict: Runtime Error):
s = list(input())

out = 0

for i in range(0, len(s), 2):
    if s[i] == 'h' and s[i+1] == 'i':
        continue
    else:
        out = 1

if out:
    print("No")
else:
    print("Yes")
Problem p02780 (python)

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

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

B = []
t = -1
init_sum = sum(A[0:k])

for i in range(n - k+1):
    if t < init_sum:
        B = A[i:i+k]
        t = init_sum
    if i != n - k:
        init_sum = init_sum - A[i] + A[i+k]


import collections
B = sorted(B)
C = collections.Counter(B)

D = list(C.keys())
E = list(C.values())
F = zip(D, E)
F = sorted(F)
D, E = zip(*F)

G = []
j = 0
total = 0
for i in range(max(D) + 1):
    total += i
    if D[j] == i:
        G.append(total)
        j += 1
ans = 0
k = 0
for i, j in zip(D, G):
    ans += (j/i) * E[k]
    k += 1
print(ans)

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

P = list(map(int, input().split()))


B = []
init_ = sum(P[0:k])
max_ = 0
for i in range(0, n - k+1):
    if i != 0:
        init_ = init_ - P[i] + P[i+k-1]
    if max_ < init_:
        B = P[i:i+k]
        max_ = init_
B = sorted(B)
i = 0
t = 0
C = []
for j in range(B[-1]+1):
    t += j
    if j == B[i]:
        C.append(t)
        i += 1

ans = 0
for i in range(k):
    ans += C[i] / B[i]
print(ans)
Problem p02923 (python)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))[::-1]
B = []
t = 0
before = A[0] - 1
max_t = 0
for i in A:
    if before <= i:
        t += 1
        before = i
    else:
        B.append(t)
        t = 1
        before = i
B.append(t)
if n == 1:
    print(0)
else:
    print(max(B)-1)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))[::-1]
B = []
t = 0
before = A[0] - 1
max_t = 0
for i in A:
    if before <= i:
        t += 1
        before = i
    else:
        B.append(t)
        t = 1
        before = i

print(max(B)-1)
Problem p02993 (python)

Fixed submission:
s = input()
a = 0
for i in range(3):
    if s[i]==s[i+1]:
        print("Bad")
        a = 1
        break
if a == 0:
    print("Good")

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())

total = b - a + 1

c_1 = b//c - a//c if a%c!=0 else b//c - a//c + 1
d_1 = b//d - a//d if a%d!=0 else b//d - a//d + 1

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z

div = int(c * d / gcd(c, d))

cd = b//div - a//div if a%div!=0 else b//div - a//div + 1

print(total - c_1 - d_1 + cd)
Problem p03001 (python)

Fixed submission:
w, h, x, y = map(int, input().split())


if x in [0, w] or y in [0, h]:
    print(w * h/2, 0)
else:
    if x * 2 == w and y * 2 == h:
        print(w * h / 2, 1)
    else:
        print(w * h/2, 0)

Buggy submission (verdict: Runtime Error):
w, h, x, y = map(int, input().split())

min_wh = w*h/2
a = 0

if x == 0 or y == 0:
    print(min_wh, 0)

if w%x==0 and h%y==0:
    a = 1
print(min_wh, a)

Buggy submission (verdict: Runtime Error):
w, h, x, y = map(int, input().split())

min_wh = w*h/2
a = 0
if w%x==0 and h%y==0:
    a = 1
print(min_wh, a)
Problem p03273 (python)

Fixed submission:
import numpy as np
h, w = map(int, input().split())

A = []
for i in range(h):
    s = list(input())
    if len(set(s)) == 1 and s[0] == ".":
        continue
    else:
        A.append(s)
B = A
c = 0
for i in range(w):
    s = []
    for j in range(len(A)):
        s.append(A[j][i])
    if len(set(s)) == 1 and s[0] == '.':
        B = np.delete(B, i-c, 1)
        c += 1


for i in B:
    a = ""
    for j in i:
        a += j
    print(a)

Buggy submission (verdict: Runtime Error):
import numpy as np
h, w = map(int, input().split())

A = []
for i in range(h):
    s = list(input())
    if len(set(s)) == 1 and s[0] == ".":
        continue
    else:
        A.append(s)
B = A
c = 0
for i in range(w):
    s = []
    for j in range(len(A)):
        s.append(A[j][i])
    if len(set(s)) == 1 and s[0] == '.':
        B = np.delete(B, i-c, 1)
        c += 1


for i in B:
    a = ""
    for j in i:
        a += j
    print(a)
Problem p03556 (python)

Fixed submission:
n = int(input())

for i in range(n):
    if i**2 > n:
        break

if n == 1 or n == 2:
    print(1)
else:
    print((i-1)**2)

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

for i in range(n//2):
    if i**2 > n:
        break
print((i-1)**2)
Problem p03651 (python)

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

A = list(map(int, input().split()))
import fractions
def list_gcd(X):
    t = max(X)
    for i in X:
        t = fractions.gcd(t, i)
    return t

if k in A or (k % list_gcd(A) == 0 and max(A) >= k):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

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

A = list(map(int, input().split()))
import math
def list_gcd(X):
    t = max(X)
    for i in X:
        t = math.gcd(t, i)
    return t

if k in A or (k % list_gcd(A) == 0 and max(A) >= k):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Problem p03106 (python)

Fixed submission:
a, b, k = map(int, input().split())

m = min(a, b)
l = []

for i in range(1, m+1):
    if a % i == 0 and b % i == 0:
        l.append(i)
print(l[-k])

Buggy submission (verdict: Runtime Error):
m = min(a, b)

for i in reversed(range(m+1)):
    if a % i == 0 and b % i == 0:
        k -= 1
        if k == 0:
            print(i)
            exit()
Problem p03273 (python)

Fixed submission:
h, w = map(int, input().split())
a = [''] * h

for i in range(h):
    a[i] = input()
    
row = [False] * h
cal = [False] * w

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            row[i] = True
            cal[j] = True
            
for i in range(h):
    if row[i]:
        for j in range(w):
            if cal[j]:
                print(a[i][j], end='')
        print()

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
a = [''] * h

for i in range(w):
    a[i] = input()
    
row = [False] * h
cal = [False] * w

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            row[i] = True
            cal[j] = True
            
for i in range(h):
    if row[i]:
        for j in range(w):
            if cal[j]:
                print(a[i][j], end='')
        print()
Problem p03088 (python)

Fixed submission:
N, MOD = int(input()), 10 ** 9 + 7
memo = [{} for i in range(N+1)]
def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True
def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in 'ACGT':
        if ok(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
    memo[cur][last3] = ret
    return ret
print(dfs(0, 'TTT'))

Buggy submission (verdict: Runtime Error):
#include<iostream>
#include<vector>
using namespace std;
const long long INF = 1000000007ll;
int k[4];
void ku(int a) {
  for (int i = 3; i >= 0; i --) {
    k[i] = a % 4;
    a /= 4;
  }
}
bool ok(int a) {
  for (int i = 0; i < 4; i ++) {
    ku(a);
    if (i >= 1) swap(k[i - 1], k[i]);
    if (k[0] == 0 && k[1] == 1 && k[2] == 2) return false;
    if (k[1] == 0 && k[2] == 1 && k[3] == 2) return false;
  }
  return true;
}
int N;
vector<vector<long long>>memo(101, vector<long long>(64, -1));
long long dfs(int cur, int last3) {
  if (memo[cur][last3] != -1) return memo[cur][last3];
  if (cur == N) return 1;
  long long ret = 0;
  for (int i = 0; i < 4; i ++) {
    if (ok(last3 * 4 + i)) {
      int jun = last3 % 16;
      jun *= 4;
      jun += i;
      ret = (ret + dfs(cur + 1, jun)) % INF;
    }
  }
  memo[cur][last3] = ret;
  return ret;
}
int main () {
  cin >> N;
  cout << dfs(0, 63) << endl;
}

Buggy submission (verdict: Runtime Error):
#include<iostream>
#include<vector>
using namespace std;
const long long INF = 1000000007ll;
int k[4];
void ku(int a) {
  for (int i = 3; i >= 0; i --) {
    k[i] = a % 4;
    a /= 4;
  }
}
bool ok(int a) {
  for (int i = 0; i < 4; i ++) {
    ku(a)
    if (i >= 1) swap(k[i - 1], k[i]);
    if (k[0] == 0 && k[1] == 1 && k[2] == 2) return false;
    if (k[1] == 0 && k[2] == 1 && k[3] == 2) return false;
  }
  return true;
}
int N;
vector<vector<long long>>memo(101, vector<long long>(64, -1));
long long dfs(int cur, int last3) {
  if (memo[cur][last3] != -1) return memo[cur][last3];
  if (cur == N) return 1;
  long long ret = 0;
  for (int i = 0; i < 4; i ++) {
    if (ok(last3 * 4 + i)) {
      int jun = last3 % 16;
      jun *= 4;
      jun += i;
      ret = (ret + dfs(cur + 1, jun)) % INF;
    }
  }
  memo[cur][last3] = ret;
  return ret;
}
int main () {
  cin >> N;
  cout << dfs(0, 63) << endl;
}
Problem p02534 (python)

Fixed submission:
print("ACL"*int(input()))

Buggy submission (verdict: Runtime Error):
print("ACL"*K=int(input()))