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

Fixed submission:
from collections import defaultdict, Counter

def main():
  n, *A = map(int, open(0).read().split())
  A.sort()
  n = A[-1]
  isPrime = [True] * (n + 1)
  prep = 0
  for i in A:
    if prep == i:
      isPrime[prep] = False
      continue
    if isPrime[i]:
      for j in range(i * 2, n + 1, i):
        isPrime[j] = False
    prep = i

  prep = res = 0
  for i in A:
    if prep == i:
      continue
    if isPrime[i]:
      res += 1
    prep = i
  print(res)
if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
def main():
    n, *A = map(int, f.read().split())
    A.sort()
    n = A[-1]
    isPrime = [True] * (n + 1)
    prep = 0
    for i in A:
        if prep == i:
            isPrime[prep] = False
            continue
        if isPrime[i]:
            for j in range(i * 2, n + 1, i):
                isPrime[j] = False
        prep = i

    prep = res = 0
    for i in A:
        if prep == i:
            continue
        if isPrime[i]:
            res += 1
        prep = i
    print(res)


if __name__ == '__main__':
    main()
Problem p02727 (python)

Fixed submission:
import sys
from collections import deque
readline = sys.stdin.readline

def main():
  x,y,a,b,c=map(int,readline().split())

  red=[int(i) for i in readline().split()]
  green=[int(i) for i in readline().split()]
  nc=sorted([int(i) for i in readline().split()], reverse=1)
  if a<x:
    red+=nc[:(x-a)]
    nc=nc[(x-a):]
  if b<y:
    green+=nc[:(y-b)]
    nc=nc[(y-b):]
  red=deque(sorted(red)[-x:])
  green=deque(sorted(green)[-y:])
  res=0
  
  def ppl(lst,i,t):
    if i>t:
      lst.popleft()
      return i
    else:
      return 0
    
  for i in nc:
    if (not red) and (not green):
      break
    if not red:
      tg=green[0]
      res+=ppl(green,i,tg)
    elif not green:
      tr=red[0]
      res+=ppl(red,i,tr)
    else:
      tr=red[0]
      tg=green[0]
      if tr<tg:
        res+=ppl(red,i,tr)
      else:
        res+=ppl(green,i,tg)
    
  print(res+sum(red)+sum(green))

main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
readline = sys.stdin.readline

def main():
  x,y,a,b,c=map(int,readline().split())

  red=[int(i) for i in readline().split()]
  green=[int(i) for i in readline().split()]
  nc=sorted([int(i) for i in readline().split()], reverse=1)
  if a<x:
    red+=nc[:(x-a)]
    nc=nc[(x-a):]
  if b<y:
    green+=nc[:(y-b)]
    nc=nc[(y-b):]
  red=deque(sorted(red)[-x:])
  green=deque(sorted(green)[-y:])
  res=0
  for i in nc:
    tr=red[0]
    tg=green[0]
    if tr<tg:
      if i>tr:
        red.popleft()
        res+=i
    else:
      if i>tg:
        green.popleft()
        res+=i
  print(res+sum(red)+sum(green))

main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque

readline = sys.stdin.readline

x,y,a,b,c=map(int,readline().split())
lst=[]
red=deque(sorted(int(i) for i in readline().split())[-x:])
green=deque(sorted(int(i) for i in readline().split())[-y:])
nc=sorted([int(i) for i in readline().split()], reverse=1)

res=0
for i in nc:
  if i>red[0]:
    red.popleft()
    res+=i
  elif i > green[0]:
    green.popleft()
    res+=i
res+=sum(red)+sum(green)
print(res)
Problem p02775 (python)

Fixed submission:
n = list(map(int, input()[::-1])) + [0]
s = 0
res = 0
for i, ni in enumerate(n[:-1]):
    k = ni + s
    if k < 5 or (k == 5 and int(n[i + 1]) < 5):
        res += k
        s = 0
    else:
        res += 10 - k
        s = 1
res += s
print(res)

Buggy submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc155/submissions/10175015

def main():
    n = input()[::-1]
    s = 0
    cnt = 0
    for i, ni in enumerate(n):
        k = int(ni) + s
        if k < 5 or k == 5 and int(n[i + 1]) < 5:
            cnt += k
            s = 0
        else:
            cnt += 10 - k
            s = 1
    cnt += s
    print(cnt)
 
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc155/submissions/10175015

n = input()[::-1]
s = 0
res = 0
for i, ni in enumerate(n):
    k = int(ni) + s
    if k < 5 or k == 5 and int(n[i + 1]) < 5:
        res += k
        s = 0
    else:
        res += 10 - k
        s = 1
res += s
print(res)

Buggy submission (verdict: Runtime Error):
import sys
n = list(map(int, sys.stdin.readline().strip()))
s = sum(i if i <= 5 else 10 - i for i in n)
if (n[0] > 5 and n[1] < 6) or (n[0] <= 5 and n[1] >= 6):
    s += 1
print(s)

Buggy submission (verdict: Runtime Error):
import sys
n = list(map(int, sys.stdin.readline()))
s = sum(i if i <= 5 else 10 - i for i in n)

Buggy submission (verdict: Runtime Error):
import sys
n = list(map(int, sys.stdin.readline()))
s = sum(i if i <= 5 else 10 - i for i in n)

print(s)

Buggy submission (verdict: Runtime Error):
import sys
n = list(map(int, sys.stdin.readline()))
s = sum(i if i <= 5 else 10 - i for i in n)
if (n[0] > 5 and n[1] < 6) or (n[0] <= 5 and n[1] >= 6):
  s += 1
print(s)

Buggy submission (verdict: Runtime Error):
import sys
n = list(map(int, sys.stdin.readline()))
s = sum(i if i <= 5 else 10 - i for i in n)
if (n[0] > 5 and n[1] < 6) or (n[0] <= 5 and n[1] >= 6):
  s += 1
print(s)
Problem p02787 (python)

Fixed submission:
import numpy as np
import sys
read=sys.stdin.read

h,n,*ab=map(int,read().split())
a=np.array(ab[::2])
b=np.array(ab[1::2])

magic=np.zeros(h+1,dtype=np.int64)
for i in range(1,1+h):
  magic[i]=np.min(magic[np.maximum(i-a, 0)]+b)
print(magic[h])

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
read=sys.stdin.read

h,n,*ab=map(int,read().split())
a=np.array(ab[::2])
b=np.array(ab[1::2])

magic=np.zeros(h+1)
for i in range(1,1+h):
  magic[i]=np.min(dp[np.maximum(i-a, 0)]+b)
print(magic[h])
Problem p02788 (python)

Fixed submission:
def main():
    import sys
    from collections import deque
    read=sys.stdin.read
    readline=sys.stdin.readline
    
    n, d, a = map(int, readline().split())
    m = map(int, read().split())
    monsters = sorted(zip(m, m), key=lambda x:x[0])
    
    bomb_area = deque([])
    bomb_power = deque([])
    total_damage = 0
    ans = 0
    for pos, hp in monsters:
        while bomb_area:
            area = bomb_area[0]
            if area < pos:
                bomb_area.popleft()
                power = bomb_power.popleft()
                total_damage -= power
            else:
                break
        if hp <= total_damage:
            continue
        else:
            rest = hp - total_damage
            count = rest // a + (rest % a != 0)
            ans += count
            power = a * count
            total_damage += power
            bomb_area.append(pos + 2 * d)
            bomb_power.append(power)
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    from collections import deque
    read=sys.stdin.read
    readline=sys.stdin.readline
    
    n, d, a = map(int, readline().split())
    m = map(int, read().split())
    monsters = sorted(zip(m, m), key=itemgetter(0))
    
    bomb_area = deque([])
    bomb_power = deque([])
    total_damage = 0
    ans = 0
    for pos, hp in monsters:
        while bomb_area:
            area = bomb_area[0]
            if area < pos:
                bomb_area.popleft()
                power = bomb_power.popleft()
                total_damage -= power
            else:
                break
        if hp <= total_damage:
            continue
        else:
            rest = hp - total_damage
            count = rest // a + (rest % a != 0)
            ans += count
            power = a * count
            total_damage += power
            bomb_area.append(pos + 2 * d)
            bomb_power.append(power)
    print(ans)


if __name__ == '__main__':
    main()
Problem p02805 (python)

Fixed submission:
from itertools import combinations
import math
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n = int(readline())
m = map(float,read().split())
points = [[x, y] for x, y in zip(m, m)]


def center(a, b, c):
    M = pow(a[0], 2) - pow(b[0], 2) + pow(a[1], 2) - pow(b[1], 2)
    N = pow(a[0], 2) - pow(c[0], 2) + pow(a[1], 2) - pow(c[1], 2)
    Yab = a[1] - b[1]
    Xab = a[0] - b[0]
    Yac = a[1] - c[1]
    Xac = a[0] - c[0]
    d1 = Yac * Xab - Yab * Xac
    d2 = Xac * Yab - Xab * Yac
    if d1 == 0 or d2 == 0:
        return None
    x = (M * Yac - N * Yab) / (2 * d1)
    y = (M * Xac - N * Xab) / (2 * d2)
    return (x, y)


centers = []
for a, b, c in combinations(points, 3):
    cen = center(a, b, c)
    if cen is None:
      continue
    centers.append(cen)

for a, b in combinations(points, 2):
    cen = ((a[0]+b[0])/2,(a[1]+b[1])/2)
    centers.append(cen)

res = 1000
for cx, cy in centers:
    r = 0
    for x, y in points:
        tr = math.hypot(x - cx, y - cy)
        if tr > r:
            r = tr
    if r < res:
        res = r
print(res)

Buggy submission (verdict: Runtime Error):
from itertools import combinations
import math
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n = int(readline())
m = map(float,read().split())
points = [[x, y] for x, y in zip(m, m)]


def center(a, b, c):
    M = pow(a[0], 2) - pow(b[0], 2) + pow(a[1], 2) - pow(b[1], 2)
    N = pow(a[0], 2) - pow(c[0], 2) + pow(a[1], 2) - pow(c[1], 2)
    Yab = a[1] - b[1]
    Xab = a[0] - b[0]
    Yac = a[1] - c[1]
    Xac = a[0] - c[0]
    d1 = Yac * Xab - Yab * Xac
    d2 = Xac * Yab - Xab * Yac
    if d1 == 0 or d2 == 0:
        return None
    x = (M * Yac - N * Yab) / (2 * d1)
    y = (M * Xac - N * Xab) / (2 * d2)
    return (x, y)


centers = []
for a, b, c in combinations(points, 3):
    cen = center(a, b, c)
    centers.append(cen)

for a, b in combinations(points, 2):
    cen = ((a[0]+b[0])/2,(a[1]+b[1])/2)
    centers.append(cen)

res = 1000
for cx, cy in centers:
    r = 0
    for x, y in points:
        tr = math.hypot(x - cx, y - cy)
        if tr > r:
            r = tr
    if r < res:
        res = r
print(res)
Problem p02814 (python)

Fixed submission:
import sys
readline = sys.stdin.buffer.readline
from fractions import gcd
from functools import reduce

n,m = map(int,readline().split())
alst = list(map(int,readline().split()))

def lcm(x,y):
  g=gcd(x,y)
  if x//g %2==0 or y//g%2==0:
    return 0
  return x*y//g
g=reduce(lcm,alst)
if g==0:
  print(0)
  quit()
else:
  res=(2*m//g)
  print(res//2+res%2)

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.read


n, m, *alst = list(map(int, read().split()))
mm = 2 * m


def min_factor(n):
    sieve = list(range(n + 1))
    sieve[2::2] = [2] * (n // 2)
    for i in range(3, int(n ** 0.5) + 2, 2):
        if sieve[i] == i:
            sieve[i * i::2 * i] = [i] * ((n - i * i) // (2 * i) + 1)
    return sieve


# 素因数分解
def prime_factorize(n):
    a = {}
    while n != 1:
        b = table[n]
        if b in a:
            a[b] += 1
        else:
            a[b] = 1
        n //= b
    return a

table = min_factor(max(alst))

dic = {}
prep = -1
for i in alst:
    for key, value in prime_factorize(i).items():
        if key == 2:
            if prep == -1:
                prep = value
            elif value != prep:
                print(0)
                quit()
        if key in dic:
            dic[key] = max(dic[key], value)
        else:
            dic[key] = value

lcm = 1
for i, j in dic.items():
    lcm *= pow(i, j)
    if lcm > mm:
        print(0)
        quit()
res = mm // lcm
print(res // 2 + res % 2)
Problem p02817 (python)

Fixed submission:
s,t = input().split()
print(t+s)

Buggy submission (verdict: Runtime Error):
s,t=input(),input()
print(t+s)
Problem p02821 (python)

Fixed submission:
# https://atcoder.jp/contests/abc149/submissions/9219994
  
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# 価値 x 以上の握手を全て行うとする
# 握手回数が決まる。左手ごとに集計できる。

import numpy as np

N,M = map(int,readline().split())
A = np.array(read().split(),np.int64)

A.sort()

def shake_cnt(x):
    # x 以上の握手を全て行うとして、握手の回数を数える
    # 行わない握手を数える
    X = np.searchsorted(A,x-A)
    return N * N - X.sum()

left = 0 # 握手の回数がM以上
right = 10 ** 6 # 握手の回数がM未満
while left + 1 < right:
    x = (left + right) // 2
    if shake_cnt(x) >= M:
        left = x
    else:
        right = x

left,right

# right 以上の握手を全て行ったとして、回数と総和を計算

X = np.searchsorted(A,right-A) # 行わない人数
Acum = np.zeros(N+1,np.int64) # 人数 -> 累積和
Acum[1:] = np.cumsum(A)

shake = N * N - X.sum()
happy = (Acum[-1] - Acum[X]).sum() + (A * (N - X)).sum()

happy += (M - shake) *left
print(happy)

Buggy submission (verdict: Runtime Error):
import sys
import heapq
readline = sys.stdin.buffer.readline
import itertools
n,m=map(int,readline().split())
alst=[int(i) for i in readline().split()]
alst.sort(reverse=True)
a=0
c=[0]*m
heapq.heapify(c)

for x,y in itertools.product(alst, repeat = 2):
  ta = x+y
  if ta > c[0]:
    heapq.heappushpop(c, ta)
print(sum(c))
Problem p02837 (python)

Fixed submission:
n = int(input())
lst = []
for _ in range(n):
    a = int(input())
    lst.append([[int(i) for i in input().split()] for _ in range(a)])
m = 0
for i in range(2 ** n):
    a = True
    for j in range(n):
        if i >> j & 1:
            for x, y in lst[j]:
                if (i >> (x - 1) & 1) != y:
                    a = False
                    break
    if a:
        m = max(m, sum(map(int, bin(i)[2:])))
print(m)

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
lst = []
for _ in range(n):
    a = int(sys.stdin.readline())
    lst.append([[i for i in sys.stdin.readline().split()] for _ in range(a)])
m = 0
for i in range(2 ** n):
    a = True
    d = 0
    for j in range(n):
        if i >> j & 1:
            d += 1
            for x, y in lst[j]:
                if bin(i)[- int(x)] != y:
                    a = False
                    break
    if a:
        m = max(m, d)
print(m)
Problem p02838 (python)

Fixed submission:
import sys
import numpy as np
 
n = int(input())
lst = [int(i) for i in sys.stdin.readline().split()]
arr = np.array(lst, np.int64)

mod = 10 ** 9 + 7
x_sum = 0

for i in range(60):
    c1 = np.count_nonzero(arr & 1)
    x_sum += (c1 * (n - c1) * 2 ** i)
    x_sum %= mod
    arr >>= 1
print(x_sum)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
 
n = int(input())
lst = [int(i) for i in sys.stdin.readline().split()]
arr = np.array(lst, np.int64)

mod = 10 ** 9 + 7
x_sum = 0

for i in range(60):
    c1 = sum(lst & 1)
    x_sum += (c1 * (n - c1) * 2 ** i)
    x_sum %= mod
    lst >>= 1
print(x_sum)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
 
n = int(input())
lst = [int(i) for i in sys.stdin.readline().split()]
mod = 10 ** 9 + 7
c = []

for i in range(60):
    c1 = sum(lst & 1)
    c.append(c1 * (n - c1))
    lst >>= 1
print(sum([v * 2 ** i for i, v in enumerate(c)]) % mod)
Problem p02843 (python)

Fixed submission:
X =int(input())
if X > 10100:
    print(1)
    quit()
lst = []
for i in range(20):
    lst.append([i*105+1, i*100+99])
for item in lst:
    if X >= item[0] and X<=item[1]:
        print(0)
        quit()
print(1)

Buggy submission (verdict: Runtime Error):
if X > 10100:
    print(1)
    quit()
lst = []
for i in range(20):
    lst.append([i*105+1, i*100+99])
for item in lst:
    if X >= item[0] and X<=item[1]:
        print(0)
        quit()
print(1)
Problem p02844 (python)

Fixed submission:
N = int(input())
S = input()
lst = []
count = 0
for i in range(1000):
    num = str(i).zfill(3)
    if num[0] in S:
        a1 = S.index(num[0])
        if num[1] in S[a1+1:]:
            a2 = S[a1+1:].index(num[1]) + a1+1
            if num[2] in S[a2+1:]:
                count += 1
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
lst = []
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if S[i]+S[j]+S[k] in lst:
                continue
            else:
                lst.append(S[i]+S[j]+S[k])
            if len(lst) = 999:
                print(len(lst))
                quit()
print(len(lst))
Problem p02845 (python)

Fixed submission:
N = int(input())
lst = [int(i) for i in input().split()]
mod = 1000000007
count = [0] * (N + 1)
count[0] = 3

ret = 1
for i in lst:
    count[i + 1] += 1
    ret = (ret * count[i]) % mod
    count[i] -= 1

print(ret)

Buggy submission (verdict: Runtime Error):
N = int(input())
lst = [int(i) for i in input().split()]
mod = 1000000007
count = [0] * N
count[0] = 3

ret = 1
for i in lst:
    count[i + 1] += 1
    ret = (ret * count[i]) % mod
    count[i] -= 1

print(ret)
Problem p02852 (python)

Fixed submission:
N, M = [int(item) for item in input().split()]
S = input()
a=[]
s = S
n = N
while n > 0:
    for i in range(M, 0, -1):
        can = False
        if n>=i and s[n-i] == '0':
            a.append(i)
            s = s[:n-i+1]
            n -= i
            can = True
            break
    if (not can) and len(s)>1:
        print(-1)
        a=[]
        break
a=a[-1::-1]
if len(a):
    print(*a)

Buggy submission (verdict: Runtime Error):
N, M = [int(item) for item in input().split()]
S = input()
a=[]
s = S
n = N
while n > 0:
    for i in range(M, 0, -1):
        can = False
        if n>=i and s[n-i] == '0':
            a.append(i)
            s = s[:n-i+1]
            print(s)
            n -= -i
            can = True
            break
    if not can and len(s)>1:
        print(-1)
        a=[]
        break
a=a[-1::-1]
if len(a):
    print(*a)
Problem p03037 (python)

Fixed submission:
n, m = map(int, input().split())
left, right = 1, n
for _ in range(m):
  l, r = map(int, input().split())
  if l > left:
    left = l
  if r < right:
    right = r
  if left > right:
    print(0)
    quit()
print(right - left + 1)

Buggy submission (verdict: Runtime Error):
n, m, *lst = map(int, input().split())
l = max(lst[::2])
r = min(lst[1::2])
if l > r:
  print(0)
else:
  print(r - l + 1)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
left, right = 1, n
for _ in range(m):
  l, r = map(int, input().split())
  if l > left:
    left = l
  if r < right:
    right = r
  if l > r:
    print(0)
    quit()
if right > n:
  
print(right - left + 1)
Problem p03126 (python)

Fixed submission:
n, m = map(int, input().split())
lst = []
for i in range(n):
  tmplst = [int(i) for i in input().split()]
  tmp = 0
  for item in tmplst[1:]:
    tmp |= 1 << item
  lst.append(tmp)
ret = lst[0]
for item in lst[1:]:
  ret &= item
if ret:
  s = sum(map(int, bin(ret)[2:]))
  print(s)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
from functools import reduce
from math import log
n, m = map(int, input().split())
f1 = lambda x, y: 1 << x | 1 << y
f2 = lambda x, y: x & y
lst = []
for i in range(n):
  tmplst = [int(i) for i in input().split()]
  tmp = reduce(f1, tmplst[1:])
  lst.append(tmp)
ret = reduce(f2, lst)
if ret:
  print(int(log(ret, 2)))
else:
  print(0)
Problem p03147 (python)

Fixed submission:
n = int(input())
lst = [int(i) for i in input().split()]
c = lst[0]
for i in range(1, n):
  if lst[i] > lst[i - 1]:
      c += lst[i] - lst[i - 1]
print(c)

Buggy submission (verdict: Runtime Error):
n = int(input())
c, *lst = [int(i) for i in input().split()]
for i in range(1, n):
  if lst[i] > lst[i - 1]:
      c += lst[i] - lst[i - 1]
print(c)
Problem p03212 (python)

Fixed submission:
N = int(input())

def dfs(s): # 文字列 s で始まる七五三数の個数
  if int(s) > N:
  	return 0
  ret = 1 if all(s.count(c) > 0 for c in '753') else 0 # s 自体が七五三数なら +1
  for c in '753':
  	ret += dfs(s + c)
  return ret

print(dfs('0')) # 本当は dfs('') と書きたいが 4 行目でのエラーを防ぐため仕方なく

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

def dfs(s): # 文字列 s で始まる七五三数の個数
  if int(s) > N:
  	return 0
  ret = 1 if all(s.count(c) > 0 for c in '753') else 0 # s 自体が七五三数なら +1
  for c in '753':
  	ret += dfs(s + c)
	return ret

print(dfs('0')) # 本当は dfs('') と書きたいが 4 行目でのエラーを防ぐため仕方なく
Problem p03240 (python)

Fixed submission:
n = int(input())
lst = []
for _ in range(n):
  x, y, h = map(int, input().split())
  if h != 0:
    lst.append([x, y, h])
if len(lst) == 1:
  print(*lst[0])
  quit()
for cx in range(101):
  for cy in range(101):
    a = True
    preh = abs(lst[0][0] - cx) + abs(lst[0][1] - cy) +lst[0][2]
    for x, y, h in lst[1:]:
      H = abs(x - cx) + abs(y - cy) + h
      if H != preh:
        a = False
        break
    if a:
      print(cx, cy, H)
      quit()

Buggy submission (verdict: Runtime Error):
n = int(input())
lst = []
for _ in range(n):
  x, y, h = map(int, input().split())
  if h:
  lst.append(x, y, h)
if len(lst) == 1:
  print(*lst)
  quit()
for cx in range(101):
  for cy in range(101):
    a = True
    preh = abs(lst[0][0] - cx) + abs(lst[0][1] - cy) +lst[0][2]
    for x, y, h in lst[1:]:
      H = abs(x - cx) + abs(y - cy) + h
      if H != preh:
        a = False
        break
    if a:
      print(cx, cy, H)
      quit()
Problem p03243 (python)

Fixed submission:
print(((int(input()) - 1) // 111 + 1) * 111)

Buggy submission (verdict: Runtime Error):
print((int(input() - 1) // 111 + 1) * 111)
Problem p03276 (python)

Fixed submission:
import bisect

n, k, *lst = map(int, open(0).read().split())
z = bisect.bisect_left(lst, 0)
if not z:
  print(lst[k - 1])
  quit()
if z >= n - 1:
  print(-lst[-k])
  quit()
res = float('inf')
for i in range(max(z - k + 1, 0), min(z, n - k) + 1):
  tmp = lst[i + k - 1] - lst[i] + min(abs(lst[i]), lst[i + k - 1])
  if tmp < res:
    res = tmp
print(res)

Buggy submission (verdict: Runtime Error):
import bisect

def main():
  n, k, *lst = map(int, open(0).read().split())
  z = bisect.bisect_left(lst, 0)
  idx = max(z - k + 1, 0)
  print(min(min(abs(i), j) + j - i for i, j in zip(lst[idx:], lst[idx + k - 1:])))

if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
import bisect

n, k, *lst = map(int, open(0).read().split())
z = bisect.bisect_left(lst, 0)
if not z:
  print(lst[z + k - 1])
  quit()
assert lst[z] > 0
res = float('inf')
for i in range(max(z - k + 1, 0), min(z, n - k) + 1):
  tmp = lst[i + k - 1] - lst[i] + min(abs(lst[i]), lst[i + k - 1])
  if tmp < res:
    res = tmp
print(res)
Problem p03294 (python)

Fixed submission:
import sys
readline = sys.stdin.readline
n = int(readline())
print(sum([int(i) for i in readline().split()]) - n)

Buggy submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline
n = int(readline())
print(sum([int(i) for i in readline().split()] - n)
Problem p03308 (python)

Fixed submission:
_ = input()
lst = [int(i) for i in input().split()]

print(max(lst) - min(lst))

Buggy submission (verdict: Runtime Error):
_ = input()
lst = map(int, input().split())

print(max(lst) - min(lst))
Problem p03316 (python)

Fixed submission:
n = int(input())
h = sum(map(int, list(str(n))))

print('Yes' if n % h == 0 else 'No')

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

h = sum(list(str(n)))

print('Yes' if n % h == 0 else 'No')
Problem p03393 (python)

Fixed submission:
s = input()
if len(s) < 26:
  for i in range(97, 124):
    if chr(i) not in s:
      break
  print(s + chr(i))
else:
  prep = [s[-1]]
  for i in s[-2::-1]:
    if i > prep[-1]:
      prep.append(i)
    else:
      break
  if len(prep) == 26:
    print(-1)
  else:
    print(s[:-len(prep)-1] + min(i for i in prep if i > s[-len(prep)-1]))

Buggy submission (verdict: Runtime Error):
s = input()
if len(s) < 26:
  for i in range(97, 124):
    if chr(i) not in s:
      break
  print(s + chr(i))
else:
  prep = [s[-1]]
  for i in s[-2::-1]:
    if i > prep[-1]:
      prep.append(i)
    else:
      break
  if len(prep) == 26:
    print(-1)
  else:
    print(s[:-len(prep)-1] + min(i for i in prep if i > s[-len(prep)-2]))