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

Fixed submission:
inpl = lambda: list(map(int,input().split()))
N = int(input())
S = input()

character_pos = [ set() for _ in range(26) ]
for i in range(N):
    character_pos[ord(S[i])-ord('a')].add(i)

ans = 0
continue_list = dict()
for i in range(N):
    s = S[i]
    new_continue_list = dict()
    for p in character_pos[ord(s)-ord('a')]:
        if p < i:
            new_continue_list[p] = 1
    for k, v in continue_list.items():
        if s == S[k+1]  and v + 1 <= i - k - 1:
            new_continue_list[k+1] = v+1
        elif v > ans:
            ans = v
    continue_list = new_continue_list

if len(continue_list.values()) > 0:
    ans = max(ans, max(continue_list.values()))
print(ans)

Buggy submission (verdict: Runtime Error):
inpl = lambda: list(map(int,input().split()))
N = int(input())
S = input()
character_pos = [set()]
ans = 0
continue_list = dict()
for i in range(N):
    s = S[i]
    new_continue_list = dict()
    cpos = character_pos[ord(s)-ord('a')]
    for p in cpos:
        new_continue_list[p] = 1
    cpos.add(i)
    for k, v in continue_list.items():
        if s == S[k+1]  and v + 1 <= i - k - 1:
            new_continue_list[k+1] = v+1
        elif v > ans:
            ans = v
    continue_list = new_continue_list

if len(continue_list.values()) > 0:
    ans = max(ans, max(continue_list.values()))
print(ans)
Problem p02943 (python)

Fixed submission:
from math import floor, log
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
S = input()
U = S + S[::-1]
Sp = sorted([ U[i:i+N] for i in range(N+1)])[0]
n = 0
while Sp[n] == Sp[0]:
    n += 1

if K > int(floor(log(N/n)/log(2))) + 1:
    print(Sp[0]*N)
else:
    m = n * (2**(K-1))
    if m >= N:
        print(Sp[0]*N)
    else:
        print(Sp[0]*m + Sp[n:n+N-m])

Buggy submission (verdict: Runtime Error):
from math import floor, log2
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
S = input()
U = S + S[::-1]
Sp = sorted([ U[i:i+N] for i in range(N+1)])[0]
n = 0
while Sp[n] == Sp[0]:
    n += 1

if K > int(floor(log2(N/n))):
    print(Sp[0]*N)
else:
    m = n * (2**(K-1))
    if m >= N:
        print(Sp[0]*N)
    else:
        print(Sp[0]*m + Sp[n:n+N-m])
Problem p02985 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
inpl = lambda: list(map(int,input().split()))
MOD = 10**9 + 7

N, K = inpl()
edges = [set() for _ in range(N)]
for _ in range(N-1):
    a, b = inpl()
    a -= 1
    b -= 1
    edges[a].add(b)
    edges[b].add(a)

def dfs(node, colors, root=True):
    if colors == 0:
        return 0
    prod = colors
    if root:
        next_colors = K - 1
    else:
        next_colors = K - 2
    for p in edges[node]:
        if next_colors <= 0:
            return 0
        edges[p].remove(node)
        prod = prod*dfs(p,next_colors,False) % MOD
        if prod == 0:
            return 0
        next_colors -= 1
    return prod

print(dfs(0,K))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))
MOD = 10**9 + 7

N, K = inpl()
edges = [set() for _ in range(N)]
for _ in range(N-1):
    a, b = inpl()
    a -= 1
    b -= 1
    edges[a].add(b)
    edges[b].add(a)

def dfs(node, colors, root=True):
    if colors == 0:
        return 0
    prod = colors
    if root:
        next_colors = K - 1
    else:
        next_colors = K - 2
    for p in edges[node]:
        if next_colors <= 0:
            return 0
        edges[p].remove(node)
        prod = prod*dfs(p,next_colors,False) % MOD
        if prod == 0:
            return 0
        next_colors -= 1
    return prod

print(dfs(0,K))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))
MOD = 10**9 + 7

N, K = inpl()
edges = [set() for _ in range(N)]
for _ in range(N-1):
    a, b = inpl()
    a -= 1
    b -= 1
    edges[a].add(b)
    edges[b].add(a)

def dfs(node, colors, root=True):
    prod = colors
    if root:
        next_colors = K - 1
    else:
        next_colors = K - 2
    for p in edges[node]:
        edges[p].remove(node)
        prod = prod*dfs(p,next_colors,False) % MOD
        next_colors -= 1
    return prod

print(dfs(0,K))
Problem p03006 (python)

Fixed submission:
from collections import defaultdict
inpl = lambda: list(map(int,input().split()))

N = int(input())
xy = []
field = defaultdict(int)
for _ in range(N):
    x, y = inpl()
    xy.append((x,y))
    field[(x,y)] = 1
xy.sort()

pq = set()
for i in range(N):
    for j in range(i+1,N):
        x1, y1 = xy[i]
        x2, y2 = xy[j]
        p, q = x2-x1, y2-y1
        pq.add((p,q))

ans = N
for p, q in pq:
    removed = defaultdict(int)
    cost = 0
    for x, y in xy:
        if removed[(x,y)]:
            continue
        else:
            removed[(x,y)] = 1
            cost += 1
            while True:
                x += p
                y += q
                if field[(x,y)]:
                    removed[(x,y)] = 1
                else:
                    break
    if cost < ans:
        ans = cost

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
inpl = lambda: list(map(int,input().split()))
 
N = int(input())
xy = []
for _ in range(N):
    x, y = inpl()
    xy.append((x,y))
xy.sort()
 
edges = defaultdict(int)
for i in range(N):
    for j in range(i+1,N):
        x1, y1 = xy[i]
        x2, y2 = xy[j]
        p, q = x2-x1, y2-y1
        edges[(p,q)] += 1
 
print(N - max(edges.values()))
Problem p03007 (python)

Fixed submission:
inpl = lambda: list(map(int,input().split()))

def output(plus,minus):
    print(sum(plus)-sum(minus))
    p = plus[0]
    for z in minus[1:]:
        print(p,z)
        p -= z
    q = minus[0]
    for w in plus[1:]:
        print(q,w)
        q -= w
    print(p,q)

N = int(input())
A = inpl()
plus = list(filter(lambda x: x>0, A))
minus = list(filter(lambda x: x<0, A))
Np = len(plus)
Nm = len(minus)
Nz = N-Np-Nm

if Np == N:
    plus.sort(reverse=True)
    minus = [plus.pop()]
elif Nm == N:
    minus.sort()
    plus = [minus.pop()]
elif Nz == N:
    plus = [0]*(Nz-1)
    minus = [0]
else:
    if Nm == 0:
        minus = [0]*Nz
    else:
        plus.extend([0]*Nz)

output(plus,minus)

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

def output(plus,minus):
    print(sum(plus)-sum(minus))
    p = plus[0]
    for z in minus[1:]:
        print(p,z)
        p -= z
    q = minus[0]
    for w in plus[1:]:
        print(q,w)
        q -= w
    print(p,q)

N = int(input())
A = inpl()
plus = list(filter(lambda x: x>0, A))
minus = list(filter(lambda x: x<0, A))
Np = len(plus)
Nm = len(minus)
Nz = N-Np-Nm

if Np == N:
    plus.sort(reverse=True)
    minus = [plus.pop()]
elif Nm == N:
    minus.sort()
    plus = [minus.pop()]
else:
    if Nm == 0:
        minus = [0]*Nz
    else:
        plus.extend([0]*Nz)

output(plus,minus)
Problem p03061 (python)

Fixed submission:
from collections import defaultdict
inpl = lambda: list(map(int,input().split()))

P_MAX = 32000
sieve = [1]*P_MAX
sieve[0] = sieve[1] = 0
P = []
for i in range(2,P_MAX):
    sieve = 1
    for p in P:
        if p*p > i:
            break
        elif i % p == 0:
            sieve = 0
            break
    if sieve == 0:
        continue
    else:
        P.append(i)

def factorize(n):
    primes = []
    powers = []
    for p in P:
        if p * p > n:
            break
        elif n % p == 0:
            k = 0
            while n % p == 0:
                n //= p
                k += 1
            primes.append(p)
            powers.append(k)
    if n > 1:
        primes.append(n)
        powers.append(1)
    return primes, powers

N = int(input())
A = inpl()
infty = 100
lowest_powers = defaultdict(lambda: [infty,infty])
bottle_necks = defaultdict(lambda: -1)
all_factors = set()
for n in range(N):
    primes, powers = factorize(A[n])
    prev_primes = list(bottle_necks.keys())
    done = defaultdict(int)
    for i in range(len(primes)):
        done[primes[i]] = 1
        if not primes[i] in all_factors:
            all_factors.add(primes[i])
            if n == 1:
                lowest_powers[primes[i]] = [0,powers[i]]
                bottle_necks[primes[i]] = 0
            elif n == 0:
                lowest_powers[primes[i]] = [powers[i],infty]
                bottle_necks[primes[i]] = 0
        lowest = lowest_powers[primes[i]]
        if powers[i] == lowest[0]:
            lowest[1] = lowest[0]
            bottle_necks[primes[i]] = -1
        elif powers[i] < lowest[0]:
            lowest[1] = lowest[0]
            lowest[0] = powers[i]
            bottle_necks[primes[i]] = n
        elif powers[i] < lowest[1]:
            lowest[1] = powers[i]
    for p in all_factors:
        if done[p] == 0:
            lowest = lowest_powers[p]
            if lowest[0] == 0:
                lowest[1] = 0
                bottle_necks[p] = -1
            else:
                lowest[1] = lowest[0]
                lowest[0] = 0
                bottle_necks[p] = n

bnl = defaultdict(lambda: [])
for p,n in bottle_necks.items():
    if n >= 0:
        lowest = lowest_powers[p]
        bnl[n].append([p,lowest[1]-lowest[0]])
best_n = -1
largest_f = 1
for n in range(N):
    f = 1
    for pp in bnl[n]:
        f *= pp[0]**pp[1]
    if f > largest_f:
        largest_f = f
        best_n = n

ans = 1
bn = bnl[best_n]
pn = [ s[0] for s in bn]
for p in all_factors:
    if p in pn:
        ans *= p**lowest_powers[p][1]
    else:
        ans *= p**lowest_powers[p][0]
print(ans)

Buggy submission (verdict: Runtime Error):
from fraction import gcd
inpl = lambda: list(map(int,input().split()))

N = int(input())
A = inpl()
L = [A[0]]
R = [A[-1]]
for i in range(1,N-1):
    L.append(gcd(L[i-1],A[i]))
    R.append(gcd(R[i-1],A[-i-1]))

ans = max(L[-1],R[-1])
for i in range(1, N-1):
    g = gcd(L[i-1],R[-i-1])
    if g > ans:
        ans = g
print(ans)
Problem p03068 (python)

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

Slist = list(S) 
e = Slist[K-1]
for i in range(N):
  if Slist[i] != e:
    Slist[i] = '*'
print("".join(Slist))

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

e = S[K-1]
for i in range(N):
  if S[i] != e:
    S[i] = '*'
print(S)
Problem p03078 (python)

Fixed submission:
from collections import defaultdict
inpl = lambda: list(map(int,input().split()))

X, Y, Z, K = inpl()
A = [ sorted(inpl(), key=lambda x: -x) for _ in range(3) ]
N = [X, Y, Z]

mem = defaultdict(int)
ans = sum([A[i][0] for i in range(3)])
mem[(0,0,0)] = 1
cand = [(ans,0,0,0)]

for i in range(K):
    cand.sort()
    c = cand[-1]
    print(c[0])
    n = [c[1],c[2],c[3]]
    cand.pop(-1)
    
    for p in range(3):
        if n[p] < N[p]-1:
            n[p] += 1
            if mem[(n[0],n[1],n[2])] == 0:
                mem[(n[0],n[1],n[2])] = 1
                cand.append((sum([A[j][n[j]] for j in range(3)]),n[0],n[1],n[2]))
            n[p] -= 1

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import heapq
inpl = lambda: list(map(int,input().split()))

X, Y, Z, K = inpl()
A = [ sorted(inpl(), reverse=True) for _ in range(3) ]
N = [X, Y, Z]

mem = defaultdict(int)
score = sum([A[i][0] for i in range(3)])
mem[(0,0,0)] = 1
candidates = []
heapq._heappush_max(candidates, (score,(0,0,0)))

for i in range(K):
    c = heapq._heappop_max(candidates)
    print(c[0])
    n = list(c[1])
    
    for p in range(3):
        if n[p] < N[p]-1:
            n[p] += 1
            if mem[tuple(n)] == 0:
                mem[tuple(n)] = 1
                score = sum([A[j][n[j]] for j in range(3)])
                heapq._heappush_max(candidates, (score,tuple(n)))
            n[p] -= 1
Problem p03126 (python)

Fixed submission:
import numpy as np

(N,M) = map(int,input().split())
B = np.ones(M,dtype=np.int)

for _ in range(N):
    A = np.array(list(map(int,input().split())))[1:]
    for i in range(M):
        if not i+1 in A:
            B[i] = 0
print(B.sum())

Buggy submission (verdict: Runtime Error):
(N,M) = map(int,input().split())
r = int32(-1)
for i in range(M):
  A = list(map(int,input().split()))
  A.pop(0)
  c = 0
  for a in A:
    c |= (1 << (a-1))
  d &= c

ans = sum([(d>>n)&1 for n in range(n)])
print(ans)
Problem p03148 (python)

Fixed submission:
import numpy as np
N, K = map(int,input().split())
td = np.empty((N,2),dtype=np.int64)
for i in range(N):
    td[i] = list(map(int,input().split()))

t = td[:,0]-1
d = td[:,1]
order1=np.argsort(d)[::-1]
mins = len(set(t[order1[:K]]))

best = -np.ones(N,dtype=np.int64)
for i in range(N):
    if best[t[i]] < 0 or d[i] > d[best[t[i]]]:
        best[t[i]]=i

bestmenu = np.array(list(set(best) - set([-1])),dtype=np.int64)
othermenu = np.array(list(set(range(N)) - set(bestmenu)),dtype=np.int64)

maxs = min(len(bestmenu),K)
ans = 0
bests=0
sorted_d_best=np.sort(d[bestmenu])[::-1]
sorted_d_other=np.sort(d[othermenu])[::-1]
for s in range(mins,maxs+1):
    score = s*s + sorted_d_best[:s].sum() + sorted_d_other[:(K-s)].sum()
    if score > ans:
        bests=s
        ans = score

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N, K = map(int,input().split())
td = np.empty((N,2),dtype=np.int64)
for i in range(N):
    td[i] = list(map(int,input().split()))

t = td[:,0]-1
d = td[:,1]
order1=np.argsort(d)[::-1]
mins = len(set(t[order1[:K]]))

best = -np.ones(N,dtype=np.int64)
for i in range(N):
    if best[t[i]] < 0 or d[i] > d[best[t[i]]]:
        best[t[i]]=i

bestmenu = np.array(list(set(best) - set([-1])),dtype=np.int64)
othermenu = np.array(list(set(range(N)) - set(bestmenu)),dtype=np.int64)

maxs = min(len(bestmenu),K)
ans = 0
bests=0
sorted_d_best=np.sort(d[bestmenu])
sorted_d_other=np.sort(d[othermenu])
bo
for s in range(mins,maxs+1):
    score = s*s + sorted_d_best[-s:].sum() + sorted_d_other[-(K-s):].sum()
    if score > ans:
        bests=s
        ans = score

print(ans)
Problem p03163 (python)

Fixed submission:
def inpl(): return list(map(int,input().split()))
 
N, W = inpl()
dp = [[0]*(W+1) for _ in range(N+1)]
for n in range(1,N+1):
  w, v = inpl()
  for x in range(W+1):
    if x < w:
      dp[n][x] = dp[n-1][x]
    else:
      dp[n][x] = max(dp[n-1][x], dp[n-1][x-w] + v)
print(dp[-1][-1])

Buggy submission (verdict: Runtime Error):
def inpl(): return list(map(int,input().split()))
 
N, W = inpl()
dp = [[0]*W for _ in range(N+1)]
for n in range(1,N+1):
  w, v = inpl()
  for x in range(W+1):
    if x < w:
      dp[n][x] = dp[n-1][x]
    else:
      dp[n][x] = max(dp[n-1][x], dp[n-1][x-w] + v)
print(dp[-1][-1])

Buggy submission (verdict: Runtime Error):
def inpl(): return list(map(int,input().split()))
 
N, W = inpl()
dp = [[0]*W for _ in range(N)]
for n in range(1,N+1):
  w, v = inpl()
  for x in range(W):
    if x < w:
      dp[n][x] = dp[n-1][x]
    else:
      dp[n][x] = max(dp[n-1][x], dp[n-1][x-w] + v)
print(dp[-1][-1])

Buggy submission (verdict: Runtime Error):
def inpl(): return map(int,input().split())

N, W = inpl()
dp = [[0]*W for _ in range(N)]
for n in range(1,N+1):
  w, v = inpl()
  for x in range(W):
    if x < w:
      dp[n][x] = dp[n-1][x]
    else:
      dp[n][x] = max(dp[n-1][x], dp[n-1][x-w] + v)
print(dp[-1][-1])
Problem p03212 (python)

Fixed submission:
import numpy as np

def count(n,s):
    if s == 0:
        return 3**n - 3*(2**n) + 3
    elif s == 1:
        return 3**n - 2**(n+1) + 1
    elif s == 2:
        return 3**n - 2**n
    else:
        return 3**n

def num753(Nlist, appeared):
    n = len(Nlist)
    if n == 0:
        if appeared == 7:
            return 1
        else:
            return 0
    
    top = Nlist[-1]
    
    ap3 = appeared|1
    s3 = ap3 % 2 + (ap3 % 4)//2 + ap3 // 4
    ap5 = appeared|2
    s5 = ap5 % 2 + (ap5 % 4)//2 + ap5 // 4
    ap7 = appeared|4
    s7 = ap7 % 2 + (ap7 % 4)//2 + ap7 // 4

    if appeared == 0:
        ans = sum([count(i,0) for i in range(3,n)])
    else:
        ans = 0

    if top < 3:
        pass
    elif top == 3:
        ans = ans + num753(Nlist[:-1],ap3)
    elif top == 4:
        ans = ans + count(n-1,s3)
    elif top == 5:
        ans = ans + count(n-1,s3) + num753(Nlist[:-1],ap5)
    elif top == 6:
        ans = ans + count(n-1,s3) + count(n-1,s5)
    elif top == 7:
        ans = ans + count(n-1,s3) + count(n-1,s5) + num753(Nlist[:-1],ap7)
    else: # top == 8,9
        ans = ans + count(n-1,s3) + count(n-1,s5) + count(n-1,s7)
    
    return ans

N = int(input())
Nlist=[]
while N > 0:
    Nlist.append(N % 10)
    N = N // 10
Nlist = np.array(Nlist,dtype=np.int)

print(num753(Nlist,0))

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

def list753(n):
    if n == 1:
        return np.array([3,5,7],dtype=np.int)
    else:
        prev = list753(n-1)
        return np.concatenate((10*prev+3,10*prev+5,10*prev+7))

def all_list753(n):
    return np.concatenate(tuple([list753(i) for i in range(3,n+1)]))

Nstr = input()
N = int(Nstr)
Nlen = len(Nstr)

candidates = all_list753(Nlen)
ans = 0

for c in candidates:
    if c > N:
        continue
    cstr = str(c)
    if '3' in cstr and '5' in cstr and '7' in cstr:
        ans += 1

print(ans)
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)

Buggy submission (verdict: Runtime Error):
inpl = lambda: map(int,input().split())
N = int(input())
if N == 1:
  print('Hello World')
else:
  A, B = inpl()
  print(A+B)
Problem p03240 (python)

Fixed submission:
import numpy as np
N = int(input())
x = np.empty(N,dtype=np.int)
y = np.empty(N,dtype=np.int)
h = np.empty(N,dtype=np.int)
for n in range(N):
    (x[n],y[n],h[n]) = map(int,input().split())

M = 100

grads = np.array([[1,1],[-1,1],[-1,-1],[1,-1]],dtype=np.int)
def height(x,y,h,i,j,d):
    # d=0-3
    return (h + grads[d,0]*(i-x) + grads[d,1]*(j-y))

def quadrant(x,y):
    if x > 0 and y >= 0:
        return 0
    elif y > 0:
        return 1
    elif x < 0:
        return 2
    else:
        return 3

Clist = [(Cx,Cy) for Cy in range(M+1) for Cx in range(M+1)]
k = h.argmax()
for (Cx,Cy) in Clist:
    H = height(x[k],y[k],h[k],Cx,Cy,quadrant(Cx-x[k],Cy-y[k]))
    for n in range(N):
        Hn = height(x[n],y[n],h[n],Cx,Cy,quadrant(Cx-x[n],Cy-y[n]))
        if h[n] == 0:
            if Hn < H:
                break
        else:
            if Hn != H:
                break
    else:
        break

print(Cx,Cy,H)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
x = np.empty(N,dtype=np.int)
y = np.empty(N,dtype=np.int)
h = np.empty(N,dtype=np.int)
for n in range(N):
    (x[n],y[n],h[n]) = map(int,input().split())

M = 100

grads = np.array([[1,1],[-1,1],[-1,-1],[1,-1]],dtype=np.int)
def height(x,y,h,i,j,d):
    # d=0-3
    return (h + grads[d,0]*(i-x) + grads[d,1]*(j-y))

def quadrant(x,y):
    if x > 0 and y >= 0:
        return 0
    elif y > 0:
        return 1
    elif x < 0:
        return 2
    else:
        return 3

Clist = [(Cx,Cy) for Cy in range(M+1) for Cx in range(M+1)]
k = h.argmax()
for (Cx,Cy) in Clist:
    H = height(x[k],y[k],h[k],Cx,Cy,quadrant(Cx-x[k],Cy-y[k]))
    for n in range(N):
        Hn = height(x[n],y[n],h[n],Cx,Cy,quadrant(Cx-x[n],Cy-y[n]))
        if h[n] == 0:
            if Hn < H:
                break
        else:
            if Hn != H:
                break
    else:
        break

print(i,j,H)
Problem p03251 (python)

Fixed submission:
inpl = lambda: list(map(int,input().split()))
N, M, X, Y = inpl()
x = inpl()
y = inpl()
 
x.append(X)
y.append(Y)
xmax = max(x)
ymin = min(y)
if xmax < ymin:
  print('No War')
else:
  print('War')

Buggy submission (verdict: Runtime Error):
inpl = lambda: list(map(int,input().split()))
N, M, X, Y = inpl()
x = inpl()
y = inpl()

x.append(X)
y.append(Y)
xmax = max(X)
ymin = min(Y)
if xmax < ymin:
  print('No War')
else:
  print('War')
Problem p03263 (python)

Fixed submission:
inpl = lambda: list(map(int,input().split()))

H, W = inpl()
A = []
for _ in range(H):
    A.append(inpl())

def pos(n):
    q, m = divmod(n, W)
    if q % 2:
        m = (W-1) - m
    return q, m

ans = []
f = 0
hn, wn = 0, 0
for n in range(H*W-1):
    h, w = hn, wn
    hn, wn = pos(n+1)
    if (f+A[h][w]) % 2:
        ans.append([h+1,w+1,hn+1,wn+1])
        f = 1
    else:
        f = 0

print(len(ans))
for rec in ans:
    print(rec[0],rec[1],rec[2],rec[3])

Buggy submission (verdict: Runtime Error):
inpl = lambda: list(map(int, input().split()))
H, W = inpl()
def next_sq(sq):
  h, w = sq
  if h % 2 == 0:
    if w == h-1:
      return h+1, w
    else:
      return h, w+1
  else:
    if w == 0:
      return h+1, w
    else:
      return h, w-1
a = [inpl() for _ in range(H)]
n = sum(sum(a[h][w] % 2 for w in range(W)) for h in range(H))
if n < 2:
  print(0)
  exit()
sq = (0, 0)
prev = None
for _ in range(H*W):
  h, w = sq
  if prev is not None:
    print(prev[0], prev[1], h, w)
    if a[h][w] % 2:
      n -= 1
      if n < 2:
        break
      prev = None
    else:
      prev = sq
  elif a[h][w] % 2:
	n -= 1
    prev = sq
  sq = next_sq(sq)
Problem p03274 (python)

Fixed submission:
import bisect
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
x = inpl()

infty = 10**9
c = bisect.bisect_left(x,0)
if c == N:
    print(-x[-K])
    exit()
elif x[c] > 0:
    K += 1
    N += 1
    x.insert(c,0)

if c >= K-1:
    turn = c-(K-1)
else:
    turn = 0

ans = infty
while turn <= c and turn + K <= N:
    L = -x[turn]
    R = x[turn + K - 1]
    cur = L + R + min(L,R)
    if cur < ans:
        ans = cur
    turn += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
x = inpl()

infty = 10**9
c = bisect.bisect_left(x,0)
if x[c] > 0:
    K += 1
    N += 1
    x.insert(c,0)

if c >= K-1:
    turn = c-(K-1)
    ans = -x[turn]
    turn += 1
else:
    turn = 0
    ans = infty

while turn <= c and turn + K <= N:
    L = -x[turn]
    R = x[turn + K - 1]
    cur = L + R + min(L,R)
    if cur < ans:
        ans = cur
    turn += 1

print(ans)
Problem p02554 (python)

Fixed submission:
import math
MOD = 10**9 + 7

def mod_pow(x, mod):
    xx = [1, x]
    def _pow(y, x=x):
        nonlocal xx
        if y == 0:
            return 1
        while len(xx) <= math.log(y, 2)+1:
            v = xx[-1] * xx[-1]
            v %= mod
            xx.append(v)
        i = 1
        result = 1
        while y > 0:
            if y % 2 == 1:
                result *= xx[i]
                result %= mod
            y = y >> 1
            i += 1
        return result
    return _pow

pow10 = mod_pow(10, MOD)
pow9 = mod_pow(9, MOD)
pow8 = mod_pow(8, MOD)

def f(n):
    ans = pow10(n) - (2 * pow9(n) - pow8(n))
    ans %= MOD
    return ans


def main():
    N = int(input())
    ans = f(N)
    print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import math
sys.setrecursionlimit(10**6)

MOD = 10**9 + 7
def mod_pow(x, mod):
    xx = [1, x]
    def _pow(y, x=x):
        nonlocal xx
        if y == 0:
            return 1
        while len(xx) <= math.log(y, 2)+1:
            v = xx[-1] * xx[-1]
            v %= mod
            xx.append(v)
        i = 1
        result = 1
        while y > 0:
            if y % 2 == 1:
                result *= xx[i]
                result %= mod
            y = y >> 1
            i += 1
        return result
    return _pow

pow9 = mod_pow(9, MOD)

def f(n):
    if n == 1:
        return 0
    else:
        return 10 * f(n-1) + 2 * pow9(n-2)
def main():
    N = int(input())
    ans = f(N)
    print(ans)

if __name__ == '__main__':
    main()