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

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

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = [int(i) for i in input().split()]
 
ans = 0
D = [0] * (N + 1)
for i in range(2, N+2):
    if i != 0:
        D[i] = D[i-1] + L[i-1]
    if D[i] <= X:
        ans += 1
    else:
        break
print(ans)

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = [int(i) for i in input().split()]

ans = 0
D = [0] * (N + 2)
for i in range(N+2):
    if i != 1:
        D[i] = D[i-1] + L[i-1]
    if D[i] <= X:
        ans += 1
    else:
        break
print(ans)
Problem p03031 (python)

Fixed submission:
import itertools

N, M = map(int, input().split())
k = []
for i in range(M):
    tmp = [int(j) for j in input().split()]
    k.append(tmp)

p = [int(i) for i in input().split()]

onoff = [0, 1]
kouho = list(itertools.product(onoff, repeat=N))

ans = 0
for li in kouho:
    flag = True
    for i in range(M):
        end = k[i][0]+1
        sum = 0
        for j in range(1, end):
            sum += li[k[i][j]-1]
        if sum % 2 != p[i]:
            flag = False
            break
    if flag == True:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import itertools

N, M = map(int, input().split())
k = []
for i in range(N):
    tmp = map(int, input().split())
    k.append(tmp)

p = input().split()

onoff = [0, 1]
kouho = list(itertools.product(onoff, repeat=N))

ans = 0
for li in kouho:
    for i in range(N):
        if p[i] == 0:
            li[i].count(0) % 2 == 0
            ans += 1
        else:
            li[i].count(0) % 2 == 1
            ans += 1
print(ans)
Problem p03037 (python)

Fixed submission:

N, M = map(int, input().split())

L = []
R = []

for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

maxl = max(L)
minr = min(R)

ans = minr - maxl + 1
if ans > 0:
    print(ans)
else:
    print(0)

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

L = []
R = []
LR = [int(i) for i in range(1, N+1)]
for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)
    LR.append(l)
    LR.append(r)

tmp = []
for gate in range(1, M+1):
    for i in range(L[gate-1], R[gate-1]+1):
        tmp.append(i)
    tmpLR = list(set(tmp) & set(LR))
    LR.clear()
    LR = tmpLR
    tmp.clear()

print(len(LR))

Buggy submission (verdict: Runtime Error):
    N, M = map(int, input().split())
     
    L = []
    R = []
    LR = [int(i) for i in range(1, N+1)]
    for i in range(M):
        l, r = map(int, input().split())
        L.append(l)
        R.append(r)
        LR.append(l)
        LR.append(r)
     
    tmp = []
    for gate in range(1, M+1):
        for i in range(L[gate-1], R[gate-1]+1):
            tmp.append(i)
        tmpLR = list(set(tmp) & set(LR))
        LR.clear()
        LR = tmpLR
        tmp.clear()
     
    print(len(LR))
Problem p03161 (python)

Fixed submission:
N, K = map(int, input().split())
h = [int(i) for i in input().split()]
h.extend([10**9]*1000)
dp = [10**9] * (N+1000)
 
dp[0] = 0
 
for i in range(N):
    for j in range(1, K+1):
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]))
 
print(dp[N-1])

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
h = [int(i) for i in input().split()]
h.extend([10**9]*10)
dp = [10**9] * (N+10)

dp[0] = 0

for i in range(N):
    for j in range(1, K+1):
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]))

print(dp[N-1])
Problem p03163 (python)

Fixed submission:
N, W = map(int, input().split())
wv = [[0 for i in range(2)] for j in range(N)]

for i in range(N):
    w, v = map(int, input().split())
    wv[i] = [w, v]

dp = [[0 for i in range(2*W)] for j in range(2*N)]

for i in range(N):
    for j in range(W+1):
        if (j - wv[i][0] >= 0):
            dp[i+1][j] = max(dp[i+1][j], dp[i][j-wv[i][0]] + wv[i][1])
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

print(dp[N][W])

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
wv = [[0 for i in range(2)] for j in range(N)]

for i in range(N):
    w, v = map(int, input().split())
    wv[i] = [w, v]

dp = [[0 for i in range(2*N)] for j in range(2*W)]

for i in range(N):
    for j in range(W+1):
        if (j - wv[i][0] >= 0):
            dp[i+1][j] = max(dp[i+1][j], dp[i][j-wv[i][0]] + wv[i][1])
        
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

print(dp[N][W])

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
wv = [[0 for i in range(2)] for j in range(N)]

for i in range(N):
    w, v = map(int, input().split())
    wv[i] = [w, v]

dp = [[0 for i in range(200)] for j in range(200)]

for i in range(N):
    for j in range(W+1):
        if (j - wv[i][0] >= 0):
            dp[i+1][j] = max(dp[i+1][j], dp[i][j-wv[i][0]] + wv[i][1])
        
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

print(dp[N][W])
Problem p03240 (python)

Fixed submission:
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_)

for i in range(0,101):
    for j in range(0,101):
        for n, hn in enumerate(h):
            if hn > 0:
                tmph = hn + abs(i-x[n]) + abs(j-y[n])
                break
        count = 0
        for n in range(N):
            count += 1
            if h[n] != max(tmph - abs(i-x[n]) - abs(j-y[n]), 0):
                break
            if count == N:
                print(str(i) + ' ' + str(j) + ' ' + str(tmph))

Buggy submission (verdict: Runtime Error):
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_)

for i in range(0,101):
    for j in range(0,101):
        for hn in h:
            if hn > 0:
                tmph = hn + abs(i-x[n]) + abs(j-y[n])
                break
        count = 0
        for n in range(N):
            count += 1
            if h[n] != max(tmph - abs(i-x[n]) - abs(j-y[n]), 0):
                break
            if count == N:
                print(str(i) + ' ' + str(j) + ' ' + str(tmph))
Problem p03274 (python)

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

x = [int(i) for i in input().split()]

if N == 1 or K == 1:
    print(x[0])
    exit()

ans = 10**100
for i in range(N):
    if i < N-K+1:
        tmp1 = abs(x[i]) + abs(x[i] - x[i+K-1])
        tmp2 = abs(x[i+K-1]) + abs(x[i] - x[i+K-1])
        ans = min(tmp1, tmp2, ans)

print(ans)

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

x = [int(i) for i in input().split()]

if N == 1 or K == 1:
    print(x[0])
    exit()

suml = []
for left in x:
    if x.index(left) == len(x)-K+1:
        break
    tmp = abs(left) + abs(left - x[x.index(left)+K-1])
    suml.append(tmp)
ansl = min(suml)

sumr = []
for right in reversed(x):
    if x.index(right) == K-1:
        break
    tmp = abs(right) + abs(right - x[x.index(right)-K])
    sumr.append(tmp)
ansr = min(sumr)

print(min(ansl,ansr))

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

xneg = []
xpos = []

for tmp in input().split():
    if int(tmp) < 0:
        xneg.append(int(tmp))
    else:
        xpos.append(int(tmp))

xneg.sort(reverse=True)
xpos.sort()

xp = 0
xn = 0
pre = 0
last1 = 0
last2 = 0
for i in range(K):
    if i == K-1:
        last1 = pre
        if len(xpos) > 0 and len(xneg) > 0:
            if xpos[xp] <= abs(xneg[xn]):
                last2 = xpos[xp]
            else:
                last2 = xneg[xn]
        elif len(xpos) > 0:
            last2 = xpos[xp]
        else:
            last2 = xneg[xn]
    else:
        if len(xpos) > 0 and len(xneg) > 0:
            if xpos[xp] <= abs(xneg[xn]):
                pre = xpos[xp]
                xp += 1
            else:
                pre = xneg[xn]
                xn += 1
        elif len(xpos) > 0:
            ans = xpos[K-1]
            print(ans)
            exit()
        else:
            ans = xneg[K-1]
            print(abs(ans))
            exit()

ans = 2*abs(min(last1,last2)) + abs(max(last1,last2))
print(ans)
Problem p03369 (python)

Fixed submission:
s = input()

print(700+100*s.count('o'))

Buggy submission (verdict: Runtime Error):
a, b, c, x, y = map(int, input().split())
n = min(x,y)
res = 0
if a+b > c*2:
    prod = c*n*2
    x -= n
    y -= n
    res += prod

if x > y:
    if a - c*2 > 0:
        res += c*2*x
        x -= x
else:
    if b - c*2 > 0:
        res += c*2*y
        y -= y

res += a*x + b*y
print(res)
Problem p03377 (python)

Fixed submission:
a, b, x = map(int, input().split())
if a > x or a+b < x:
    print('NO')
else:
    print('YES')

Buggy submission (verdict: Runtime Error):
a, b, x = map(int, input().split())
if a  x or a+b < x:
    print('NO')
else:
    print('YES')
Problem p03379 (python)

Fixed submission:
import copy

N = int(input())
X = [int(i) for i in input().split()]
tmp = copy.deepcopy(X)

X = sorted(X)
for i in range(N):
    ans1 = X[int(len(X)/2)]
    ans2 = X[int(len(X)/2)-1]
    if tmp[i] < ans1:
        print(ans1)
    else:
        print(ans2)

Buggy submission (verdict: Runtime Error):
N = int(input())
X = [int(i) for i in input().split()]

for i in range(N):
    tmp = []
    once = True
    delnum = X[i]
    for j in range(len(X)):
        if X[j] == delnum and once:
            continue  
        else:
            tmp.append(X[j])
            once = False
    tmp = sorted(tmp)
    print(tmp[int((len(tmp)+1)/2)])
Problem p03423 (python)

Fixed submission:
import math

n = int(input())
d = n / 3

if d == 0:
    print('0')
else:
    print(math.floor(d))

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

if 'Y' in s:
    print('Four')
else:
    print('Three')
Problem p02995 (python)

Fixed submission:
A,B,C,D = map(int, input().split())
from fractions import gcd

cd = C*D//gcd(D,C)
f = lambda x: B//x - ((A-1)//x)
print(B - A + 1 - (f(C) + f(D) - f(cd)))

Buggy submission (verdict: Runtime Error):
A,B,C,D = map(int, input().split())
from math import gcd
cd = C*D//gcd(D,C)
f = lambda x: B//x - ((A-1)//x)
print(B - A + 1 - (f(C) + f(D) - f(cd)))

Buggy submission (verdict: Runtime Error):
a,b,c,d = input()
count = 0
for i in range(a,b+1):
  if i % c == 0 or i % d == 0:
    continue
  count += 1

print(count)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
N = int(input())
edg = [list(map(int,input().split())) for _ in range(N-1)]
vtx = [[] for _ in range(N)]
for e in edg:
    v1,v2,w = e
    vtx[v1-1].append([v2-1,w])
    vtx[v2-1].append([v1-1,w])

colors = [1 for _ in range(N)]

def dfs(vtx,i=0,p=-1,c=1): # vertex and its parent
    colors[i] = c
    for v,w in vtx[i]:
        if v == p:
            continue
        dfs(vtx,v,i,1-c if w%2 != 0 else c)
dfs(vtx)

for v in colors:
    print(v)

Buggy submission (verdict: Runtime Error):
N = int(input())
edg = [list(map(int,input().split())) for _ in range(N-1)]
vtx = [[] for _ in range(N)]
for e in edg:
    v1,v2,w = e
    vtx[v1-1].append([v2-1,w])
    vtx[v2-1].append([v1-1,w])

colors = [1 for _ in range(N)]

def dfs(vtx,i=0,p=-1,c=1): # vertex and its parent
    colors[i] = c
    for v,w in vtx[i]:
        if v == p:
            continue
        dfs(vtx,v,i,1-c if w%2 != 0 else c)
dfs(vtx)

for v in colors:
    print(v)

Buggy submission (verdict: Runtime Error):
N = int(input())
edg = [list(map(int,input().split())) for _ in range(N-1)]
vtx = [[] for _ in range(N)]
for e in edg:
    v1,v2,w = e
    vtx[v1-1].append([v2-1,w])
    vtx[v2-1].append([v1-1,w])

colors = [1 for _ in range(N)]
def dfs(vtx,i=0,p=-1): # vertex and its parent
    for c,w in vtx[i]:
        if c == p:
            continue
        colors[c] = 1 - colors[i] if w%2 != 0 else colors[i]
        dfs(vtx,c,i)
dfs(vtx)

for v in colors:
    print(v)
Problem p03636 (python)

Fixed submission:
s = input()
print("{}{}{}".format(s[0],len(s)-2,s[-1]))

Buggy submission (verdict: Runtime Error):
print("{}{}{}".format(s[0],len(s)-2,s[-1]))

Buggy submission (verdict: Runtime Error):
def main(str):
  print("{}{}{}".format(str[0],str(len(str)-2),str[len(str)-1])
Problem p03062 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
mi = 0
for i in range(n):
  if a[i] < 0:
    mi+=1
  a[i]= abs(a[i])
if mi %2 == 1:
  print(sum(a)-2*min(a))
else:
  print(sum(a))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
mi = 0
for i in range(a):
  if a[i] < 0:
    mi+=1
  a[i]= abs(a[i])
if mi %2 == 1:
  print(sum(a)-min(a))
else:
  print(sum(a))
Problem p03064 (python)

Fixed submission:
import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
mod = 998244353
n = int(input())
a = [int(input()) for i in range(n)]
d = max(a)
go = sum(a)
dp = [[0]*(go+d+1) for j in range(n+1)]
dp[0][0] = 1
dp2 = [[0]*(go+d+1) for j in range(n+1)]
dp2[0][0] = 1
for i in range(n):
    for j in range(go):
            dp[i+1][j+a[i]] += dp[i][j]
            dp[i+1][j] += dp[i][j]*2
            dp[i+1][j+a[i]] %= mod
            dp[i+1][j] %= mod

            dp2[i+1][j+a[i]] += dp2[i][j]
            dp2[i+1][j] += dp2[i][j]
            dp2[i+1][j+a[i]] %= mod
            dp2[i+1][j] %= mod

zen = 3**n
zen %= mod
if go %2 == 1:
    print((zen - sum(dp[n][go//2+1:])*3)%mod)
else:
    print((zen - sum(dp[n][go//2:])*3 + dp2[n][go//2]*3)%mod)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
mod = 998244353
n = int(input())
a = [int(input()) for i in range(n)]
d = max(a)
dp = [[[0]*(d*n+1) for i in range(d*n+1)] for j in range(n+1)]
dp[0][0][0] = 1
for i in range(n):
    for j in range(d*n+1-d):
        for k in range(d*n+1-d):
            dp[i+1][j+a[i]][k] += dp[i][j][k]
            dp[i+1][j][k+a[i]] += dp[i][j][k]
            dp[i+1][j][k] += dp[i][j][k]
            dp[i+1][j+a[i]][k] %= mod
            dp[i+1][j][k+a[i]] %= mod
            dp[i+1][j][k] %= mod
go = sum(a)
ans = 0
for j in range(1,d*n+1):
    for k in range(1,d*n+1):
        if dp[n][j][k]:
            side1 = j
            side2 = k
            side3 = go-j-k
            if side3 == 0:
                continue
            if(side1+side2>side3)and(side2+side3>side1)and(side3+side1>side2):
                ans += dp[n][j][k]
                ans %= mod
print(ans)
Problem p03078 (python)

Fixed submission:
import sys
import math
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
x,y,z,p = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
"""
if x*y*z <= 3*10**6:
    abc = []
    for i in range(x):
        for j in range(y):
            for k in range(z):
                abc.append(a[i]+b[j]+c[k])
    abc.sort()
    abc = abc[::-1]
    for i in range(p):
        print(abc[i])  
    exit()
"""
ab = []
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])
ab.sort()
c = c[::-1]
ab = ab[::-1]
ab.append(-2**62)
ans = []
miru = [0]*z
for i in range(z):
    if i + 1 == z:
        d = -2**60
    else:
        d = c[i+1]+ab[0]
    for j in range(i+1):
        flag = 0
        while ab[miru[j]] + c[j] >= d and (len(ans)<= p or ab[miru[j]] + c[j] >= ans[0]):
             ans.append(ab[miru[j]] + c[j])
             miru[j]+=1
             flag = 1
        if flag and len(ans) <=p+1:
            ans.sort()
ans.sort()
ans = ans[::-1]
for i in range(p):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
import sys
import math
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
x,y,z,p = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
if x*y*z <= 3*10**6:
    abc = []
    for i in range(x):
        for j in range(y):
            for k in range(z):
                abc.append(a[i]+b[j]+c[k])
    abc.sort()
    abc = abc[::-1]
    for i in range(p):
        print(abc[i])  
    exit()
ab = []
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])
ab.sort()
c = c[::-1]
ab = ab[::-1]
ab.append(-2**62)
ans = []
miru = [0]*z
for i in range(z):
    if i + 1 == z:
        d = -2**60
    else:
        d = c[i+1]+ab[0]
    for j in range(i+1):
        ans.sort()
        while ab[miru[j]] + c[j] >= d and (len(ans)<= k or ab[miru[j]] + c[j] >= ans[-1]):
             ans.append(ab[miru[j]] + c[j])
             miru[j]+=1
    if len(ans) >= k:
        break
ans.sort()
ans = ans[::-1]
for i in range(p):
    print(ans[i])
Problem p03081 (python)

Fixed submission:
import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n,q = map(int,input().split())
s = input().strip()
a = [list(input().split()) for i in range(q)]
def cheak(x):
  for i in range(q):
      if s[x] == a[i][0]:
          if a[i][1] == "L":
              x-=1
          else:
              x+=1
      if x >= n :
          return 0
      elif x < 0:
          return 1
  return 0
def cheak2(x):
  for i in range(q):
      if s[x] == a[i][0]:
          if a[i][1] == "L":
              x-=1
          else:
              x+=1
      if x >= n :
          return 1
      elif x < 0:
          return 0
  return 0
dai = n-1
syo = 0
hi = cheak(syo)
mi = cheak2(dai)
if hi== 0 and mi==0:
    print(n)
elif hi and mi:
  while True:
    if dai-syo <= 1:
        if cheak(dai) != 1:
            dai = syo
        break
    kon = (dai+syo)//2
    c = cheak(kon)
    if c == 0:
        dai = kon
    else:
        syo = kon
  ab = dai
  dai = n-1
  syo = 0
  while True:
    if dai-syo <= 1:
        if cheak2(syo) == 1:
            dai = syo
        break
    kon = (dai+syo)//2
    c = cheak2(kon)
    if c == 1:
        dai = kon
    else:
        syo = kon
  if dai <= ab:
      print(0)
      exit()
  print(n-(ab+1+n-dai))
elif hi==1 and mi == 0:
  while True:
    if dai-syo <= 1:
        if cheak(dai) != 1:
            dai = syo
        break
    kon = (dai+syo)//2
    c = cheak(kon)
    if c == 0:
        dai = kon
    else:
        syo = kon
  print(n-1-dai)
else:
  while True:
    if dai-syo <= 1:
        if cheak2(syo) == 1:
            dai = syo
        break
    kon = (dai+syo)//2
    c = cheak2(kon)
    if c == 1:
        dai = kon
    else:
        syo = kon
  print(dai)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n,x = map(int,input().split())
s = list(map(int,input().split()))
mod = 10**9 + 7
s.sort()
s = s[::-1]
c = max(max(s),x)
dp = [[0]*(c+1) for i in range(n+1)]
dp[0][x] = 1
for i in range(n):
    for j in range(c+1):
        dp[i+1][j%s[i]] += dp[i][j]
        dp[i+1][j%s[i]] %= mod
        dp[i+1][j] += dp[i][j]*(n-i-1)
        dp[i+1][j] %= mod
ans = 0
for i in range(c+1):
        ans += dp[n][i]*i
        ans %= mod
print(ans)
if n <= 10000:
  print(9)
Problem p03112 (python)

Fixed submission:
import bisect
import sys
input = sys.stdin.readline
a,b,q = map(int,input().split())
x = [int(input()) for i in range(a)]
y = [int(input()) for i in range(b)]
osoi = [int(input()) for i in range(q)]
x.sort()
y.sort()
xx = [0]*a
yy = [0]*b
n = 0
for i in range(a):
    while n < b-1 and abs(x[i]-y[n]) > abs(x[i]-y[n+1]):
        n+=1
    xx[i] = abs(x[i]-y[n])
n = 0
for i in range(b):
    while n < a-1 and abs(y[i]-x[n]) > abs(y[i]-x[n+1]):
        n+=1

    yy[i] = abs(y[i]-x[n])

for i in range(q):
    z = osoi[i]
    ans = 1<<61
    n = bisect.bisect_left(x, z)
    if n<a:
        tmp = abs(x[n]-z)+xx[n]
        ans = min(ans,tmp)
    if n>0:
        tmp = abs(x[n-1]-z)+xx[n-1]
        ans = min(ans,tmp)

    n = bisect.bisect_left(y, z)
    if n<b:
        tmp = abs(y[n]-z)+yy[n]
        ans = min(ans,tmp)
    if n>0:
        tmp = abs(y[n-1]-z)+yy[n-1]
        ans = min(ans,tmp)
    print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
a,b,q = map(int,input().split())
x = [int(input()) for i in range(a)]
y = [int(input()) for i in range(b)]
x.sort()
y.sort()
for i in range(q):
    z = int(input())
    ans = 1<<61
    n = bisect.bisect_left(x, z)
    if n<a:
        tmp = abs(x[n]-z)
        m = bisect.bisect_left(y, x[n])
        try:
            ans = min(ans,abs(y[m]-x[n])+tmp)
        except:
            pass
        try:
            ans = min(ans,abs(y[m-1]-x[n])+tmp)
        except:
            pass
    if n>0:
        tmp = abs(x[n-1]-z)
        m = bisect.bisect_left(y, x[n-1])
        try:
            ans = min(ans,abs(y[m]-x[n-1])+tmp)
        except:
            pass
        try:
            ans = min(ans,abs(y[m-1]-x[n-1])+tmp)
        except:
            pass

    n = bisect.bisect_left(y, z)
    if n<a:
        tmp = abs(y[n]-z)
        m = bisect.bisect_left(x, y[n])
        try:
            ans = min(ans,abs(y[n]-x[m])+tmp)
        except:
            pass
        try:
            ans = min(ans,abs(x[m-1]-y[n])+tmp)
        except:
            pass
    if n>0:
        tmp = abs(y[n-1]-z)
        m = bisect.bisect_left(x, y[n-1])
        try:
            ans = min(ans,abs(x[m]-y[n-1])+tmp)
        except:
            pass
        try:
            ans = min(ans,abs(x[m-1]-y[n-1])+tmp)
        except:
            pass
    print(ans)
Problem p03125 (python)

Fixed submission:
import numpy as np
a,b = map(int,input().split())
if b%a == 0:
    print(b+a)
else:
    print(b-a)

Buggy submission (verdict: Runtime Error):
import numpy as np
n,m = map(int,input().split())
if b%a == 0:
    print(b+a)
else:
    print(b-a)
Problem p03157 (python)

Fixed submission:
from collections import deque
import sys
sys.setrecursionlimit(200000)
#input = sys.stdin.readline
h,w = map(int,input().split())
a = [[j for j in input()] for i in range(h)]
used = [[0]*w for i in range(h)]
def dfs(x,y):
    if used[x][y]:
        return 0
    global go
    used[x][y] = 1
    if x-1 >=0 and a[x-1][y] != a[x][y]:
            go.add((x-1,y))
            dfs(x-1,y)
    if y-1 >=0 and a[x][y-1] != a[x][y]:
            go.add((x,y-1))
            dfs(x,y-1)
    if x+1 <h and a[x+1][y] != a[x][y]:
            go.add((x+1,y))      
            dfs(x+1,y)
    if y+1 <w and a[x][y+1] != a[x][y]:
            go.add((x,y+1))
            dfs(x,y+1)
ans = 0
for i in range(h):
    for j in range(w):
        go = set()
        if used[i][j]:
            continue
        dfs(i,j)
        kuro = 0
        siro = 0
        for k,l in go:
            if a[k][l] == "#":
                kuro += 1
            else:
                siro += 1
        ans += kuro*siro

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
import sys
sys.setrecursionlimit(20000)
#input = sys.stdin.readline
h,w = map(int,input().split())
a = [[j for j in input()] for i in range(h)]
used = [[0]*w for i in range(h)]
def dfs(x,y):
    if used[x][y]:
        return 0
    global go
    used[x][y] = 1
    if x-1 >=0 and a[x-1][y] != a[x][y]:
            go.add((x-1,y))
            dfs(x-1,y)
    if y-1 >=0 and a[x][y-1] != a[x][y]:
            go.add((x,y-1))
            dfs(x,y-1)
    if x+1 <h and a[x+1][y] != a[x][y]:
            go.add((x+1,y))      
            dfs(x+1,y)
    if y+1 <w and a[x][y+1] != a[x][y]:
            go.add((x,y+1))
            dfs(x,y+1)
ans = 0
for i in range(h):
    for j in range(w):
        go = set()
        if used[i][j]:
            continue
        dfs(i,j)
        kuro = 0
        siro = 0
        for k,l in go:
            if a[k][l] == "#":
                kuro += 1
            else:
                siro += 1
        ans += kuro*siro

print(ans)
Problem p03160 (python)

Fixed submission:
n = int(input())
h = list(map(int,input().split()))
dp = [float("inf")]*n
dp[0] = 0
for i in range(n):
  if i+1 < n:
    dp[i+1] = min(dp[i]+abs(h[i+1]-h[i]),dp[i+1])
  if i+2 < n:
    dp[i+2] = min(dp[i]+abs(h[i+2]-h[i]),dp[i+2])
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [float("inf")]*n
dp[0] = 0
for i in range(n):
  for j in range(1,k+1):
    if i+j < n:
      dp[i+j] = min(dp[i]+abs(h[i+j]-h[i]),dp[i+j])
print(dp[-1])