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

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [bin(i)[2:] for i in a]
c = [0] * n
for i,v in enumerate(b):
  for j in v[::-1]:
    if j == '0':
      c[i] += 1
    else:
      break
print(min(c))

Buggy submission (verdict: Runtime Error):
N = input()
hoge = map(int,input().split())
fuga = [bin(i) for i in hoge]
count = 10000000
for i in fuga:
  tmp = i[::-1]
    for j in range(len(i)):
      if tmp[j] == '1'  and count > j:
        count = j
        break
print(count)

Buggy submission (verdict: Runtime Error):
N = input()
hoge = map(int,input().split())
fuga = [bin(i) for i in hoge]
count = 10000000
for i in fuga:
   	tmp = i[::-1]
    for j in range(len(i)):
        if tmp[j] == '1'  and count > j:
            count = j
            break
print(count)
Problem p03636 (python)

Fixed submission:
s = input()
print(s[0]+str(len(s)-2)+s[-1])

Buggy submission (verdict: Runtime Error):
s = input()
print(s[0]+len(s)-2+s[-1])
Problem p02713 (python)

Fixed submission:
import math
import numpy
K = int(input())

total = tmp = 0
for a in range(1,K+1) :
  for b in range(1,K+1) :
   tmp=math.gcd(a,b)
   for c in range(1,K+1) :
      total += math.gcd(tmp,c)

print(total)

Buggy submission (verdict: Runtime Error):
import math
import numpy
K = int(input())

total = 0
tmp =0
 for a in range(1,K+1) :
     for b in range(1,K+1) :
        tmp=math.gcd(a,b)
         for c in range(1,K+1) :
             total += math.gcd(tmp,c)

print(total)
Problem p02641 (python)

Fixed submission:
x,n=map(int,input().split())
p=set(map(int,input().split()))

s=set()
for i in range(-100,201):
    s.add(i)

s=list(s-p)

a=[abs(x-i) for i in s]
print(s[a.index(min(a))])

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

s=set()
for i in range(1,101):
    s.add(i)

s=list(s-p)

a=[abs(x-i) for i in s]
print(s[a.index(min(a))])
Problem p02789 (python)

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

if n == m:
    print('Yes')
else:
    print('No')

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

if n == m:
    print('Yes')
else:
    print('No')
Problem p02848 (python)

Fixed submission:
str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 

a = int(input())
s = list(input())

ans = ''
for char in s:
    
    c = str.index(char) + a 

    if c >= 26:
        c = c - 26
    ans = ans + str[c] #文字列は加算できる

print(ans)

Buggy submission (verdict: Runtime Error):
str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 

a = int(input())
s = list(input())

ans = ''
for char in s:
    
    c = str.index(char) + a 

    if c > 27:
        c = c - 26
    ans = ans + str[c] #文字列は加算できる

print(ans)
Problem p02999 (python)

Fixed submission:
x,a=map(int,input().split())
if x<a:
    print(0)
else:
    print(10)

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

wk = 0
for i in range(n):
    wk += l[i]
    #print(i)
    #print(l[i])
    if(wk > x):
        print(i + 1)
        exit()
print(n + 1)
Problem p03000 (python)

Fixed submission:
n,x=map(int,input().split())
l=list(map(int,input().split()))

wk=0
cnt=1
for i in range(n):
    wk+=l[i]
    if wk <= x:
        cnt+=1
print(cnt)

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

wk = 0
for i in range(n):
    wk += l[i]
    #print(i)
    #print(l[i])
    if(wk > x):
        ans = i + 1
        break
print(ans)
Problem p03219 (python)

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

print(x+ y // 2)

Buggy submission (verdict: Runtime Error):
n = int(input())
t,a = map(int,input().split())
l = []
ans = []

l = list(map(int,input().split()))
    
for i in range(n):
    ans.append(a - t - (l[i] * 0.006))

print(ans.index(min(ans,key=abs))+1)
Problem p03289 (python)

Fixed submission:
s = list(input())

ans = 'AC'
if s[0] != 'A':
    ans = 'WA'  

if s[2:-1].count('C') != 1:
    ans = 'WA'

cnt = 0
for i in s:
    
    if 'A' <= i <= 'Z':
        cnt += 1

if cnt != 2:
    ans = 'WA'

print(ans)

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

ans = 'AC'
if s[0] != 'A':
    ans = 'WA'  

if s[2:-1].count('C') != 1:
    ans = 'WA'

s.remove('A')
s.remove('C')
if "".join(s).isupper():
    ans = 'WA'

print(ans)
Problem p03351 (python)

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

if abs(a-c) <= d or max(abs(a-b), abs(b-c)) <= d:
    print('Yes')
else:
    print('No')

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

s = set([1])
for i in range(2,501):
    for j in range(2,10):
        if (i**j) <= x:
            s.add(i**j)

print(max(list(s)))
Problem p03359 (python)

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

if a <= b:
    print(a)
else:
    print(a - 1)

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

m = max(a,b,c)
print(m * 2 * k + a + b + c - max(a,b,c))
Problem p03501 (python)

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

print(min(n*a,b))

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

wrk = 0
for i in n:
    wrk += int(i)

if int(n) % wrk == 0:
    print('Yes')
else:
    print('No')
Problem p03544 (python)

Fixed submission:
n = int(input())
 
l = [2,1]
for i in range(2,n+1):
  l.append(l[i-1] + l[i-2])
 
print(l[n])

Buggy submission (verdict: Runtime Error):
n = int(input())
 
l = [2,1]
for i in range(2,n+1):
  l.append(l[i-1] + l[i-2])
 
print(l[i])
Problem p02582 (python)

Fixed submission:
s = input()
if s == "RSR":
  print(1)
else:
  print(s.count("R"))

Buggy submission (verdict: Runtime Error):
s = input()
if s = "RSR":
  print(1)
else:
  print(s.count("R"))
Problem p02639 (python)

Fixed submission:
x = list(map(int, input().split()))
for i in range(5):
  if x[i] == 0:
    print(i+1)

Buggy submission (verdict: Runtime Error):
x = map(int, input().split())
for i in range(5):
  if x[i] == 0:
    print(i)
Problem p02660 (python)

Fixed submission:
import collections
N = int(input())
  
# 素因数分解
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

num1 = prime_decomposition(N)
num2 = collections.Counter(num1)

ans = 0

for j in set(num1):
  number = 0
  for k in range(50):
    number += k
    if number > num2[j]:
      ans += (k-1)
      break
        
print(ans)

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

# 約数列挙
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

# 素因数分解
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

def div_game(N, ans, LIST):
  if N == 1:
    print(ans)
    return ans
  
  num = make_divisors(N)
  for i in num:
    if i == 1:
      continue
    elif i in LIST:
      continue
    A = prime_decomposition(i)
    if len(set(A)) == 1:
      z = i
      LIST.append(z)
      break
    
  N = int(N/z)
  div_game(N, ans+1, LIST)

LIST = []
last = div_game(N, 0, LIST)
Problem p02718 (python)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
ans = 0

for i in range(n):
  if a[i] >= sum(a)*(1/(4*m)):
    ans += 1
    
if ans >= m:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = map(int, input().split())
ans = 0

for i in range(n):
  if a[i] >= sum(a)*(1/(4*m)):
    ans += 1
    
if ans >= m:
  print("Yes")
else:
  print("No")
Problem p02921 (python)

Fixed submission:
# coding:utf-8
a = list(input())
b = list(input())
count = 0

for i in range(3):
  if a[i] == b[i]:
    count += 1
    
print(count)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
for i in range(30):
  if (a + (a-1) * i) >= b:
    break
print(i+1)
Problem p02924 (python)

Fixed submission:
a = int(input())
ans = a*(a-1)//2
print(int(ans))

Buggy submission (verdict: Runtime Error):
a = int(input())
if a = 1:
  print(1)
  exit(0)
else:
  ans = a*(a+1)/2 - a
  print(int(ans))

Buggy submission (verdict: Runtime Error):
a = list(input())
ans = sum(a) - max(a)
print(ans)
Problem p03037 (python)

Fixed submission:
n, m = map(int, input().split())
num = [list(map(int, input().split())) for _ in range(m)]
num1 = 1
num2 = n

for j in range(m):
  num1 = max(num[j][0], num1)
  num2 = min(num[j][1], num2)

ans = num2 - num1 + 1

if ans > 0:
  print(ans)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
num = [list(map(int, input().split())) for _ in range(m)]
num1 = 1
num2 = n

for j in range(m):
  num1 = max(num[j][0], num1)
  num2 = min(num[j][1], num2)

ans = num2 - num1 + 1

if ans > 0
  print(ans)
else:
  print(0)
Problem p03043 (python)

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

for i in range(1, a+1):
  tmp = 1
  while i*tmp < b:
    tmp *= 2
  ans += (1/a)*(1/tmp)

print(ans)

Buggy submission (verdict: Runtime Error):
fractions import Fraction
a, b = map(int, input().split())
ans = 0

for i in range(1, a+1):
  for j in range(10**6):
    if i*2**j > b:
      ans += Fraction(1, a*2**j)
      break

print(float(ans))
Problem p03238 (python)

Fixed submission:
n = int(input())
if n == 1:
  print('Hello World')
  exit(0)
else:
  a = int(input())
  b = int(input())
  print(a+b)

Buggy submission (verdict: Runtime Error):
n = int(input())
if n == 1:
  print('Hello World')
  exit(0)
else:
  a, b = map(int, input().split())
  print(a)
  print(b)
Problem p03555 (python)

Fixed submission:
A = list(input())
B = list(input())
if A[0] == B[2] and A[1] == B[1] and A[2] == B[0]:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
A = input().split()
B = input().split()
if A[0] == B[2] and A[1] == B[1] and A[2] == B[0]:
    print('YES')
else:
    print('NO')
Problem p02609 (python)

Fixed submission:
N = int(input())
X = list(map(int, input()))
# N = 2*10**5
# X = list(map(int, "10"*(N//2)))

Xp = sum(X)
        
# print(Xp)
a = 0
b = 0
# c = 0
# :N
for i, x in enumerate(X):
    i_reverse = N-i-1
    if Xp > 1:
        a = (a + x * pow(2, i_reverse, Xp-1)) % (Xp-1)
    b = (b + x * pow(2, i_reverse, Xp+1)) % (Xp+1)
    # c = (c + x * (1<<i_reverse))
    # print(bin(c))

# print(a, b)

# :N
for i in range(N):
    i_reverse = N-i-1
    if Xp > 1:
        m = ([a, b][X[i]==0] + [-1, 1][X[i]==0] * pow(2, i_reverse, [Xp-1, Xp+1][X[i]==0])) % [Xp-1, Xp+1][X[i]==0]
    else:
        if X[i]==0:
            m = (b + pow(2, i_reverse, Xp+1)) % (Xp+1)
        else:
            print(0)
            continue
    count = 1
    # print(i, ([a, b][X[i]==0], [-1, 1][X[i]==0]*(1<<i_reverse)), [Xp-1, Xp+1][X[i]==0], X[i]==0)
    # print(m)
    while m > 0:
        p = sum([int(c) for c in str(bin(m)[2:])])
        m = m % p
        count += 1
    print(count)

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

Xp = sum(X)
# print(Xp)
a = 0
b = 0
# c = 0
for i, x in enumerate(X):
    i_reverse = N-i-1
    a = (a + x * (1<<i_reverse)) % (Xp-1)
    b = (b + x * (1<<i_reverse)) % (Xp+1)
    # c = (c + x * (1<<i_reverse))
    # print(bin(c))

# print(a, b)

for i in range(N):
    i_reverse = N-i-1
    m = ([a, b][X[i]==0] + [-1, 1][X[i]==0] * (1<<i_reverse)) % [Xp-1, Xp+1][X[i]==0]
    # print(i, ([a, b][X[i]==0], [-1, 1][X[i]==0]*(1<<i_reverse)), [Xp-1, Xp+1][X[i]==0], X[i]==0)
    # print(m)
    count = 1
    while m > 0:
        p = sum([int(c) for c in str(bin(m)[2:])])
        m = m % p
        count += 1
    print(count)
Problem p02621 (python)

Fixed submission:
A = int(input())

print(A+A**2+A**3)

Buggy submission (verdict: Runtime Error):
A = input()

print(A+A**2+A**3)
Problem p02706 (python)

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

x = N-(sum(A))

print(-1 if x < 0 else x)

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

print(2*R*3.1415926535897)
Problem p02714 (python)

Fixed submission:
from collections import Counter

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

counter = Counter(S)

r = 1
for c in "RGB":
    r *= counter[c]


for i in range(N):
    for j in range(i+1, N):
        k = 2*j-i
        # print(i, j, k)
        if k < N and len({S[i], S[j], S[k]}) == 3:
            r -= 1

print(r)

Buggy submission (verdict: Runtime Error):
from collections import Counter

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

a, b, c = Counter(S).values()
r = a*b*c

for i in range(N):
    for j in range(i+1, N):
        k = 2*j-i
        # print(i, j, k)
        if k < N and len({S[i], S[j], S[k]}) == 3:
            r -= 1

print(r)
Problem p02853 (python)

Fixed submission:
X, Y = map(int, input().split())

points = [-1, 300000, 200000, 100000, 0]
print(400000*(X==Y==1) + points[min(4, X)] + points[min(4, Y)])

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

points = [-1, 100000, 200000, 300000, 0]
print(400000*(X==Y==1) + points[max(4, X)] + points[max(4, Y)])
Problem p02888 (python)

Fixed submission:
from bisect import bisect_left, bisect_right

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

L.sort()

count = 0
for i, l1 in enumerate(L):
    for j, l2 in enumerate(L):
        if i < j:
            s = max(j+1, bisect_right(L, abs(l1-l2)))
            e = max(j+1, bisect_left(L, l1+l2))

            # print((i, j), (l1, l2), (abs(l1-l2), l1+l2), (s, e))
            count += max(0, e-s)
            # abs(l1-l2) <= m <= l1+l2

print(count)

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

L.sort()

count = 0
for i, l1 in enumerate(L):
    for j, l2 in enumerate(L):
        if i < j:
            s = bisect_right(L[j+1:], abs(l1-l2))
            e = bisect_left(L[j+1:], l1+l2)

            # print((i, j), (l1, l2), (abs(l1-l2), l1+l2), (s, e))
            count += max(0, e-s)
            # abs(l1-l2) <= m <= l1+l2

print(count)
Problem p02900 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**8)

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

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a%b)

g = gcd(A, B)
count = 0
for i in range(2, 10**6+3):
    if g%i == 0:
        count += 1
    while g%i == 0:
        g //= i
if g != 1:
    count += 1

print(count+1)

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

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

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a%b)

g = gcd(A, B)
count = 0
for i in range(2, 10**6+3):
    if g%p == 0:
        count += 1
    while g%p == 0:
        g //= p
if g != 1:
    count += 1

print(count+1)

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

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

primes = []
for i in range(2, 10**3+10):
    if all(i%p for p in primes):
        primes.append(i)
# print(primes)

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a%b)

g = gcd(A, B)
count = 0
for p in primes:
    if g < p:
        break
    if g%p == 0:
        c += 1

print(count+1)

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

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

def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    return gcd(a, b%a)

primes = []
for i in range(2, 10**3+10):
    if all(i%p for p in primes):
        primes.append(i)

g = gcd(A, B)
l = [0]*(g+1)
for p in primes:
    if g < p:
        break
    while g%p == 0:
        l[p] = 1
        g //= p
        if g == 1:
            break
    if g == 1:
        break

print(sum(l)+1)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())

def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    return gcd(a, b%a)

primes = []
for i in range(2, 10**3+10):
    if all(i%p for p in primes):
        primes.append(i)

g = gcd(A, B)
l = [0]*(g+1)
for p in primes:
    if g < p:
        break
    while g%p == 0:
        l[p] = 1
        g //= p
        if g == 1:
            break
    if g == 1:
        break

print(sum(l)+1)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())

def gcd(a, b):
    if a > b:
        a, b = b, a
    if a == 0:
        return b
    return gcd(a, b%a)

primes = []
for i in range(2, 10**3+10):
    if all(i%p for p in primes):
        primes.append(i)

g = gcd(A, B)
l = [0]*(g+1)
for p in primes:
    while g%p == 0:
        l[p] = 1
        g //= p
        if g == 1:
            break
    if g == 1:
        break

print(sum(l)+1)
Problem p03006 (python)

Fixed submission:
N = int(input())
XY = [list(map(int, input().split(" "))) for _ in range(N)]

d = {(-1, -1): 0}
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        x1, y1 = XY[i]
        x2, y2 = XY[j]
        x3, y3 = x2-x1, y2-y1
        if x3 < 0 or (x3 == 0 and y3 < 0):
            x3, y3 = -1*x3, -1*y3
        pos = (x3, y3)
        if pos not in d:
            d[pos] = 0
        d[pos] += 1

# print(d.values(), d, max(d.values()))
print(N - max(d.values())//2)

Buggy submission (verdict: Runtime Error):
N = int(input())
XY = [list(map(int, input().split(" "))) for _ in range(N)]

d = dict()
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        x1, y1 = XY[i]
        x2, y2 = XY[j]
        x3, y3 = x2-x1, y2-y1
        if x3 < 0:
            x3, y3 = -1*x3, -1*y3
        pos = (x3, y3)
        if pos not in d:
            d[pos] = 0
        d[pos] += 1

# print(d[max(d, key=lambda x: d[x])])
print(N - max(d.values())//2)
Problem p03068 (python)

Fixed submission:
import re

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

print(re.sub("[^" + S[K-1] + "]", '*', S))

Buggy submission (verdict: Runtime Error):
import re

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

print(re.sub(f'[^{S[K-1]}]', '*', S))
Problem p03069 (python)

Fixed submission:
from itertools import groupby, accumulate

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

l = [len(list(g)) for k, g in groupby(S)]
if S[0] == ".":
    l.pop(0)
if S[-1] == "#":
    l.pop()

if len(l) == 0:
    print(0)
    exit()

min_num = 10**18

black = [0] + list(accumulate(l[::2]))
white = [0] + list(accumulate(l[1::2]))

x = len(l)//2
for i in range(x+1):
    m = (black[i] - black[0]) + (white[x] - white[i])
    min_num = min(m, min_num)

print(min_num)

Buggy submission (verdict: Runtime Error):
from itertools import groupby, accumulate

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

l = [len(list(g)) for k, g in groupby(S)]
if S[0] == ".":
    l.pop(0)
if S[1] == "#":
    l.pop()

if len(l) == 0:
    print(0)
    exit()

min_num = 10**18

black = [0] + list(accumulate(l[::2]))
white = [0] + list(accumulate(l[1::2]))

x = len(l)//2
for i in range(x):
    m = black[i] + (white[x] - white[i])
    min_num = min(m, min_num)

print(min_num)

Buggy submission (verdict: Runtime Error):
from itertools import groupby, accumulate

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

l = [len(list(g)) for k, g in groupby(S)]
if S[0] == ".":
    l.pop(0)
if S[1] == "#":
    l.pop()

if len(l) == 0:
    print(0)
    exit()
    
min_num = 10**18

black = [0] + list(accumulate(l[::2]))
white = [0] + list(accumulate(l[1::2]))

for i in range(len(l)//2):
    m = black[i] + (white[-1] - white[i])
    min_num = min(m, min_num)

print(min_num)
Problem p03160 (python)

Fixed submission:
BIG_NUM = 10**18

N = int(input())
H = list(map(int, input().split(" ")))

l = [BIG_NUM] * (N+10)
l[0] = 0

for i in range(1, N):
    l[i] = min(
        l[i-1] + abs(H[i] - H[i-1]),
        l[i-2] + abs(H[i] - H[i-2]),
    )

print(l[N-1])

Buggy submission (verdict: Runtime Error):
BIG_NUM = 10**18

N, K = map(int, input().split(" "))
H = list(map(int, input().split(" ")))

l = [BIG_NUM]*(N+200)
l[0] = 0
for i in range(1, N):
    l[i] = min([
        l[i-j] + abs(H[i]-H[i-j]) for j in range(1, min(N, K, i)+1)
    ])

# print(l)
print(l[N-1])
Problem p03161 (python)

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

costs = [0]*(N+10)
for i in range(1, N):
    j = max(0, i-K)
    h_i = H[i]
    costs[i] = min(cost+abs(h_i-h) for cost, h in zip(costs[j:i], H[j:i]))

print(costs[N-1])

Buggy submission (verdict: Runtime Error):
BIG_NUM = 10**18

N, K = map(int, input().split(" "))
H = list(map(int, input().split(" ")))

l = [BIG_NUM]*(N+200)
l[0] = 0
for i in range(1, N):
    l[i] = min([l[i-j] + abs(H[i]-H[i-j]) for j in range(1, K+1)])

# print(l)
print(l[N-1])
Problem p03162 (python)

Fixed submission:
from functools import lru_cache
import sys

sys.setrecursionlimit(10**8)

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

l = [[None for _ in range(3)] for _ in range(N+10)]
# @lru_cache(maxsize=None)
def dp(i, use):
    if i == -1:
        return 0
    if l[i][use] != None:
        return l[i][use]
    max_num = 0
    for k in range(3):
        if k == use:
            continue
        max_num = max(max_num, dp(i-1, k)+ABC[i][use])
    l[i][use] = max_num 
    return max_num

print(max(dp(N-1, m) for m in range(3)))

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

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

# l = [[0 for _ in range(3)] for _ in range(N+10)]
@lru_cache(maxsize=None)
def dp(i, use):
    if i == -1:
        return 0
    max_num = 0
    for k in range(3):
        if k == use:
            continue
        max_num = max(max_num, dp(i-1, k)+ABC[i][use])
    return max_num

print(max(dp(N-1, m) for m in range(3)))
Problem p03219 (python)

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

print(x + y//2)

Buggy submission (verdict: Runtime Error):
i=lambda:map(int,input().split());i();t,a=i();c=[abs(t-0.006*b-a)for b in i()];print(c.index(min(c))+1)
Problem p03263 (python)

Fixed submission:
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

l = []
for y in range(H):
    l += [(x, y) for x in list(range(W))[::-1 if y%2 else 1]]

p = []
for i, (x, y) in enumerate(l[:-1]):
    if A[y][x] % 2 == 0:
        continue
    nx, ny = l[i+1]
    p.append((x+1, y+1, nx+1, ny+1))
    A[y][x] -= 1
    A[ny][nx] += 1

print(len(p))
[print(*p_i[::-1]) for p_i in p]

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

l = []
for y in range(H):
    l += [(x, y) for x in list(range(W))[::-1 if y%2 else 1]]

p = []
for i, (x, y) in enumerate(l):
    if A[y][x] % 2 == 0:
        continue
    nx, ny = l[i+1]
    p.append((x+1, y+1, nx+1, ny+1))
    A[y][x] -= 1
    A[ny][nx] += 1

print(len(p))
[print(*p_i) for p_i in p]
Problem p03282 (python)

Fixed submission:
s = input()
k = int(input())

i = 0
while k > 1:
    if s[i] == "1":
        k -= 1
        i += 1
    else:
        break
print(s[i])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())

for i in range(k):
    if s[k] != "1":
        print(s[k])
        exit()
print(1)
Problem p03309 (python)

Fixed submission:
import statistics

n = int(input())
a = [int(n) for n in input().split(" ")]

sub_a = [a_n - i - 1 for i, a_n in enumerate(a)]
median = statistics.median(sub_a)
print(int(sum([abs(sub_a_n-median) for sub_a_n in sub_a])))

Buggy submission (verdict: Runtime Error):
import statistics

n = int(input())
a = [int(n) for n in input().split(" ")]

sub_a = [a_n - i - 1 for i, a_n in enumerate(a)]
median = statistics.median(sub_a)
print(sum([abs(sub_a-median) for sub_a_n in sub_a]))