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

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()

x, y = 0, 0

i = 0
while i < n - 1:
    if a[i] == a[i + 1]:
        x = a[i]
        i += 2
        break
    i += 1

while i < n - 1:
    if a[i] == a[i + 1]:
        y = a[i]
        i += 2
        break
    i += 1
print(x * y)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()

x, y = 0, 0

i = 0
while i < n - 1:
    if a[i] == a[i + 1]:
        x = a[i]
        i += 2
        break
    i += 1
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.reverse()

x, y = 0, 0

i = 0
while i < n - 1:
    if a[i] == a[i + 1]:
        x = a[i]
        i += 2
        break
    i += 1

while i < n - 1:
    if a[i] == a[i + 1]:
        y = a[i]
        i += 2
        break
    i += 1
print(x * y)
while i < n - 1:
    if a[i] == a[i + 1]:
        y = a[i]
        i += 2
        break
    i += 1
print(x * y)
Problem p03638 (python)

Fixed submission:
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
ans = [[0 for x in range(w)] for y in range(h)]

def getx(i):
    return i // h
def gety(i):
    if (i % (2 * h)) < h:
        return i % h
    else:
        return h - i % h - 1

aa=[]
for i in range(n):
    aa += [i + 1 for _ in range(a[i])]

for i in range(h * w):
    ans[gety(i)][getx(i)] = aa[i]

for y in range(h):
    for x in range(w):
        if x > 0: print(' ', end='')
        print(ans[y][x], end='')
    print()

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
ans = [[0 for x in range(w)] for y in range(h)]

def getx(i):
    return i // h
def gety(i):
    return i % h if i // (2 * h) < h else h - (i % h)

aa=[]
for i in range(n):
    aa += [i + 1 for _ in range(a[i])]

for i in range(h * w):
    ans[gety(i)][getx(i)] = aa[i]

for y in range(h):
    for x in range(w):
        if x > 0: print(' ', end='')
        print(ans[y][x], end='')
    print()
Problem p03644 (python)

Fixed submission:
a = 1
n=int(input())
while a*2 <= n:
    a*=2
print(a)

Buggy submission (verdict: Runtime Error):
a = 1
while a*2 <= int(input()):
    a*=2
print(a)
Problem p03651 (python)

Fixed submission:
def possible(b):
    print('POSSIBLE' if b else 'IMPOSSIBLE')
    exit()

n, k = map(int, input().split())
A = list(set(map(int, input().split())))
n = len(A)

if k in A:
    possible(True)

if k > max(A):
    possible(False)

if n == 1:
    possible(False)

A.sort()
D = [A[i + 1] - A[i] for i in range(n - 1)]
from fractions import *
g = D[0]
for d in D:
    g = gcd(g, d)

possible(k % g == 0)

Buggy submission (verdict: Runtime Error):
def possible(b):
    print('POSSIBLE' if b else 'IMPOSSIIBLE')

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

if k in A:
    possible(True)
    exit()

if n == 1:
    possible(False)
    exit()
A = set(A)
A = list(A)
n = len(A)
A.sort()
D = [A[i + 1] - A[i] for i in range(n - 1)]
from fractions import *
g = D[0]
for d in D:
    g = gcd(g, d)

print('POSSIBLE' if k % g == 0 and k <= A[-1] else 'IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
def possible(b):
    print('POSSIBLE' if b else 'IMPOSSIIBLE')

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

if k in A:
    possible(True)
    exit()

if n == 1:
    possible(False)
    exit()
A = set(A)
A = list(A)

A.sort()
D = [A[i + 1] - A[i] for i in range(n - 1)]
from fractions import *
g = D[0]
for d in D:
    g = gcd(g, d)

print('POSSIBLE' if k % g == 0 and k <= A[-1] else 'IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
def possible(b):
    print('POSSIBLE' if b else 'IMPOSSIIBLE')

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

if k in A:
    possible(True)
    exit()

if n == 1:
    possible(False)
    exit()

A.sort()
D = [A[i + 1] - A[i] for i in range(n - 1)]
from fractions import *
g = D[0]
for d in D:
    g = gcd(g, d)

print('POSSIBLE' if k % g == 0 and k <= A[-1] else 'IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
A = list(map(int, input().split()))
if n == 1:
    print('IMPOSSIBLE')
    exit()
A.sort()
D = [A[i + 1] - A[i] for i in range(n - 1)]
from math import *
g = D[0]
for d in D:
    g = gcd(g, d)
print('POSSIBLE'if g == 1 else 'IMPOSSIBLE')
Problem p03737 (python)

Fixed submission:
s = input().split()
print(''.join(i[0] for i in s).upper())

Buggy submission (verdict: Runtime Error):
 print(''.join(i[0] for i in input().split()).upper())
Problem p03816 (python)

Fixed submission:
#1,1,1 -> (1,1) 1

#1,2,3 -> (1,3) 2

#1,1,3 -> (1,3) 1  <=> 1,1,3,3 -> (1,3) 1,3

#1,2,1,3,7 == [1:2, 2:1, 3:1, 7:1]
#[1:4, 2:3, 3:2, 5:1, 6:2, 8:2, 11:1]

#それぞれ1または2と等しい
#[1:2, 2:1, 3:2, 5:1, 6:2, 8:2, 11:1]
#[1,1,3,3,6,6,8,8]
#[1,1,3,6,6,8,8]
#[1,3,6,8]

N = int(input())
A = list(map(int, input().split()))
B = [-1 for i in range(100005)]

for i in range(N):
    if B[A[i]] == -1:
        B[A[i]] = 1
    elif B[A[i]] == 1:
        B[A[i]] = 2
    elif B[A[i]] == 2:
        B[A[i]] = 1

n = len(B) - B.count(-1)

if B.count(2) % 2 == 0:
    print(n)
else:
    print(n-1)

Buggy submission (verdict: Runtime Error):
#1,1,1 -> (1,1) 1

#1,2,3 -> (1,3) 2

#1,1,3 -> (1,3) 1  <=> 1,1,3,3 -> (1,3) 1,3

#1,2,1,3,7 == [1:2, 2:1, 3:1, 7:1]
#[1:4, 2:3, 3:2, 5:1, 6:2, 8:2, 11:1]

#それぞれ1または2と等しい
#[1:2, 2:1, 3:2, 5:1, 6:2, 8:2, 11:1]
#[1,1,3,3,6,6,8,8]
#[1,1,3,6,6,8,8]
#[1,3,6,8]

N = int(input())
A = list(map(int, input().split()))
B = [-1 for i in range(100005)]

for i in range(N):
    if B[A[i]] == -1:
        B[A[i]] = 1
    elif B[A[i]] == 1:
        B[A[i]] = 2:
    elif B[A[i]] == 2:
        B[A[i]] = 1

n = N - B.count(-1)

if B.count(2) % 2 == 0:
    print(n)
else:
    print(n-1)
Problem p02684 (python)

Fixed submission:
n, k = [int(i) for i in input().split()]
al = [int(i) for i in input().split()]

index = 0
keiro = []
s_keiro = set()
loop_f = False

for i in range(k):
  index = al[index] - 1
  if index in s_keiro:
    start = keiro.index(index)
    mod = i - start
    loop_f = True
    break
  s_keiro.add(index)
  keiro.append(index)

if loop_f:
  pos = (k-start-1) % mod
  if mod == 1:
    print(keiro[start]+1)
  else:
    print(keiro[start + pos]+1)
else:
  print(keiro[-1] + 1)

Buggy submission (verdict: Runtime Error):
n, k = [int(i) for i in input().split()]
al = [int(i) for i in input().split()]

index = 0
keiro = []
s_keiro = set()

for i in range(k):
  index = al[index] - 1
  if index in s_keiro:
    start = keiro.index(index)
    mod = i - start
    break
  s_keiro.add(index)
  keiro.append(index)

pos = (k-start) % mod
print(keiro[start + pos - 1]+1)

Buggy submission (verdict: Runtime Error):
n, k = [int(i) for i in input().split()]
al = [int(i) for i in input().split()]

index = 0
keiro = []
s_keiro = set()

for i in range(k):
  index = al[index] - 1
  if index in s_keiro:
    start = keiro.index(index)
    mod = i - start
    break
  s_keiro.add(index)
  keiro.append(index)

print(keiro[start + (k-start)%mod - 1]+1)

Buggy submission (verdict: Runtime Error):
n, k = [int(i) for i in input().split()]
al = [int(i) for i in input().split()]

index = 0
keiro = []

for i in range(k):
  index = al[index] - 1
  keiro.append(index)
  if keiro.count(index) == 2:
    start = keiro.index(index)
    mod = i - start
    break

print(keiro[k%mod-1]+1)
Problem p02727 (python)

Fixed submission:
from collections import deque
x, y, a, b, c = [int(i) for i in input().split()]
lp = sorted([int(i) for i in input().split()])
if len(lp) != x:
  del lp[:len(lp)-x]
lp = deque(lp)
lq = sorted([int(i) for i in input().split()])
if len(lq) != y:
  del lq[:len(lq)-y]
lq = deque(lq)
lr = sorted([int(i) for i in input().split()])
lr = deque(lr)


while True:
  if len(lr) == 0:
    break
  r_max = lr[len(lr)-1]
  p_min = lp[0]
  q_min = lq[0]
  if r_max <= p_min and r_max <= q_min:
    break
  elif r_max > q_min and p_min >= q_min:
    del lq[0]
    lq.append(lr.pop())
  elif r_max > p_min and q_min >= p_min:
    del lp[0]
    lp.append(lr.pop())


print(sum(lp) + sum(lq))

Buggy submission (verdict: Runtime Error):
from collections import deque
x, y, a, b, c = [int(i) for i in input().split()]
lp = sorted([int(i) for i in input().split()])
if len(lp) != x:
  del lp[:len(lp)-x]
lp = deque(lp)
lq = sorted([int(i) for i in input().split()])
if len(lq) != y:
  del lq[:len(lq)-y]
lq = deque(lq)
lr = sorted([int(i) for i in input().split()])
lr = deque(lr)


while True:
  if len(lr) == 0:
    break
  r_max = lr[len(lr)-1]
  p_min = lp[0]
  q_min = lq[0]
  if r_max <= p_min and r_max <= q_min:
    break
  elif r_max > q_min and p_min >= q_min:
    del lq[0]
    lq.append(lr.pop(-1))
  elif r_max > p_min and q_min >= p_min:
    del lp[0]
    lp.append(lr.pop(-1))


print(sum(lp) + sum(lq))
Problem p02865 (python)

Fixed submission:
print((int(input())-1)//2)

Buggy submission (verdict: Runtime Error):
print((int(input())-1//2)
Problem p03623 (python)

Fixed submission:
x,a,b=list(map(int,input().split()))
if abs(x-a) < abs(x-b):
    print("A")
else:
    print("B")

Buggy submission (verdict: Runtime Error):
x,a,b=map(int,input().split())
if abs(x-a) < abs(x-b):
    print("A")
else:
    pring("B")
Problem p03632 (python)

Fixed submission:
a,b,c,d=map(int,input().split())
start=max(a,c)
end=min(b,d)
print(end-start if end-start > 0 else 0)

Buggy submission (verdict: Runtime Error):
a,b,c,d=map((int,input().split()))
start=min(a,b)
end=min(c,d)
print(end-start if end-start > 0 else 0)
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] + str(len(s-2))+ s[-1])
Problem p03644 (python)

Fixed submission:
N = int(input())
t = 1;
while(t * 2 <= N):
    t *= 2
print(t)

Buggy submission (verdict: Runtime Error):
N = input()
t = 1;
while(t <= N):
    t *= 2
print(t)
Problem p03729 (python)

Fixed submission:
a,b,c=input().split()
print("YES" if a[-1] == b[0] and b[-1] == c[0] else "NO")

Buggy submission (verdict: Runtime Error):
a,b,c=input().split()
print "YES" if a[-1] == b[0] and b[-1] == c[0] else "NO"

Buggy submission (verdict: Runtime Error):
a,b,c=input().split()
print "YES" if a[-1] == b[0] && b[-1] == c[0] else "NO"

Buggy submission (verdict: Runtime Error):
a,b,c=input().split()
print "YES" if a.last() == b.first() && b.last() == c.first() else "NO"

Buggy submission (verdict: Runtime Error):
a,b,c=map(int(),split())
print "YES" if a.last() == b.first() && b.last() == c.first() else "NO"
Problem p03778 (python)

Fixed submission:
w,a,b=map(int,input().split())
print(b-(a+w) if b>a+w else a-(b+w) if b+w<a else 0)

Buggy submission (verdict: Runtime Error):
w,a,b=map(int,input())
print(b-(a+w) if b>a else a-(b+w) if b<a else 0)
Problem p03826 (python)

Fixed submission:
import math;
a,b,c,d=map(int,input().split())
print(max(a*b,c*d))

Buggy submission (verdict: Runtime Error):
import math;
a,b,c,d=map(int,input().split())
print(math.max(a*b,c*d))
Problem p03853 (python)

Fixed submission:
h,w=map(int,input().split())
c=[input() for i in range(h)]
  
for i in range(h):
  print(c[i])
  print(c[i])

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
c=list(h)
for i in range(h):
  c[i]=input()
  
for i in range(h):
  print(c[i])
  print(c[i])
Problem p02618 (python)

Fixed submission:
D=int(input())
c = list(map(int,input().split()))
s=[[0 for e in range(26)] for f in range(D)]
for i in range(D):
 s[i]=list(map(int,input().split()))
last=[0]*26
ans=0
point=[0]*D
for i in range(D):
 saidai=-(10**10)
 kouho=0
 for j in range(26):
  if s[i][j]+c[j]*((i+1)-last[j])>=saidai:
   kouho=j+1
   saidai=s[i][j]+c[j]*((i+1)-last[j])
 print(kouho)

Buggy submission (verdict: Runtime Error):
for k in range(50):
 D=int(input())
 c = list(map(int,input().split()))
 s=[[0 for e in range(26)] for f in range(D)]
 for i in range(D):
  s[i]=list(map(int,input().split()))
 last=[0]*26
 ans=0
 point=[0]*D
 for i in range(D):
  saidai=-(10**10)
  kouho=1
  for j in range(26):
   if s[i][j]+c[j]*((i+1)-last[j])>=saidai:
    kouho=j+1
    saidai=s[i][j]+c[j]*((i+1)-last[j])
  print(kouho)
Problem p02675 (python)

Fixed submission:
N=int(input())
if N%10==3:
 print("bon")
elif N%10==0 or N%10==1 or N%10==6 or N%10==8:
 print("pon")
else:
 print("hon")

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from fractions import Fraction
import sys
input = sys.stdin.readline
N=int(input())
mod=10**9+7
dic=defaultdict(int)
c=0
d=0
e=0
for i in range(N):
 A,B = map(int,input().split())
 if A==0 or B==0:
  e+=1
 else:
  dic[Fraction(A,B)]+=1
ans=1
for k in dic:
 if -1/k in dic:
  ans*=(pow(2,dic[k],mod)+pow(2,dic[-1/k],mod) -1)
  ans%=mod
  dic[k]=0
  dic[-1/k]=0
 else:
  ans*=pow(2,dic[k],mod)
  ans%=mod
ans*=(pow(2,c,mod)+pow(2,d,mod)-1)
print((ans-1+e)%mod)
Problem p02684 (python)

Fixed submission:
N,K=map(int,input().split())
T=str(bin(K))
S=len(T)-2
A = list(map(int,input().split()))
lst=[[0 for e in range(N+1)] for f in range(S)]
for i in range(1,N+1):
 lst[0][i]=A[i-1]
for j in range(1,S):
 for i in range(1,N+1):
  lst[j][i]=lst[j-1][lst[j-1][i]]
ans=[[e for e in range(N+1)] for f in range(S+1)]
for k in range(S):
 if int(T[k+2])==1:
  for l in range(1,N+1):
   ans[k+1][l]=lst[S-1-k][ans[k][l]]
 else:
  for l in range(1,N+1):
   ans[k+1][l]=ans[k][l]
print(ans[S][1])

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=[0]*(N+1)
B[0]=1
kaisuu=1
C=[-1]*(N+1)
C[0]=0
roo=0
rooa=0
while kaisuu>=0:
 B[kaisuu]=A[B[kaisuu-1]-1]
 if C[B[kaisuu]-1]>=0:
  roo=kaisuu-C[B[kaisuu]-1]
  rooa=C[B[kaisuu]-1]
  break
 else:
  C[B[kaisuu]-1]=kaisuu
  kaisuu+=1
if K<=rooa:
 print(lst[K])
else:
 d= (K-rooa)%roo
 print(B[rooa+d])
Problem p02690 (python)

Fixed submission:
X=int(input())
for a in range(201):
 for b in range(401):
  if a**5-(b-200)**5==X:
   x=str(a)
   y=str(b-200)
L=[x,y]
L=' '.join(L)
print(L)

Buggy submission (verdict: Runtime Error):
X=int(input())
for a in range(101):
 for b in range(201):
  if a**5-(b-100)**5==X:
   x=str(a)
   y=str(b-100)
L=[x,y]
L=' '.join(L)
print(L)
Problem p02702 (python)

Fixed submission:
S=input()
T=len(S)
a=0
d=1
mod=[0]*2019
mod[0]+=1
for i in range(T):
 a+=(int(S[T-i-1])*(d))%2019
 b=a%2019
 mod[b]+=1
 d*=10
 d%=2019
c=0
for i in range(2019):
 if mod[i]>=2:
  c+= mod[i]*(mod[i]-1)/2
print(int(c))

Buggy submission (verdict: Runtime Error):
S=input()
a=0
mod=[0]*2019
mod[0]+=1
for s in S:
 a+=(int(s)*(10**i))%2019
 b=a%2019
 mod[b]+=1
c=0
for i in range(2019):
 if mod[i]>=2:
  c+= mod[b]*(mod[b]-1)/2
print(int(c))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
S=int(input())
K=len(str(S))
lst= [x for x in list(str(S))]
A=[[0 for v in range(2019)] for j in range(2019)]
A[int(lst[0])][0]+=1
for i in range(1,K):
 c=int(lst[i])
 A[c][i]+=1
 for k in range(2019):
  d=(k*10+c)%2019
  A[d][i]+=A[k][i-1]
print(sum(A[0]))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
S=int(input())
K=len(str(S))
lst= [x for x in list(str(S))]
A=[[0 for v in range(2016)] for j in range(2019)]
A[int(lst[0])][0]+=1
for i in range(1,K):
 c=int(lst[i])
 A[c][i]+=1
 for k in range(2019):
  d=(k*10+c)%2019
  A[d][i]+=A[k][i-1]
print(sum(A[0]))
Problem p02727 (python)

Fixed submission:
def merge_sort(arr):
 if len(arr) <= 1:
  return arr
 mid = len(arr) // 2
# ここで分割を行う
 left = arr[:mid]
 right = arr[mid:]
# 再帰的に分割を行う
 left = merge_sort(left)
 right = merge_sort(right)
# returnが返ってきたら、結合を行い、結合したものを次に渡す
 return merge(left, right)
def merge(left, right):
 merged = []
 l_i, r_i = 0, 0
# ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
 while l_i < len(left) and r_i < len(right):
    # ここで=をつけることで安定性を保っている
  if left[l_i] <= right[r_i]:
   merged.append(left[l_i])
   l_i += 1
  else:
   merged.append(right[r_i])
   r_i += 1

# 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
 if l_i < len(left):
  merged.extend(left[l_i:])
 if r_i < len(right):
  merged.extend(right[r_i:])
 return merged

X,Y,A,B,C = map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
R = list(map(int,input().split()))
PP=merge_sort(P)
QQ=merge_sort(Q)
S=PP[A-X:A]+QQ[B-Y:B]+R
SS=merge_sort(S)
D=0
for r in range(X+Y):
 D+=SS[C+r]
print(D)

Buggy submission (verdict: Runtime Error):
import statistics

def quickSort(arr):
  left = []
  right = []
  if len(arr) <= 1:
   return arr
  median = int(statistics.median(arr))
  medianFlg = 0

  for element in arr:
   if element < median:
    left.append(element)
   elif element > median:
    right.append(element)
   else:
    medianFlg += 1
  left = quickSort(left)
  right = quickSort(right)
  return left + [median] * medianFlg + right

X,Y,A,B,C = map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
R = list(map(int,input().split()))
t1 = time.time()
PP=quickSort(P)
QQ=quickSort(Q)
S=PP[A-X:A]+QQ[B-Y:B]+R
SS=quickSort(S)
D=0
for r in range(X+Y):
 D+=SS[C+r]
print(D)
t2 = time.time()
elapsed_time = t2-t1
print(f"経過時間：{elapsed_time}")import time
import statistics

def quickSort(arr):
  left = []
  right = []
  if len(arr) <= 1:
   return arr
  median = int(statistics.median(arr))
  medianFlg = 0

  for element in arr:
   if element < median:
    left.append(element)
   elif element > median:
    right.append(element)
   else:
    medianFlg += 1
  left = quickSort(left)
  right = quickSort(right)
  return left + [median] * medianFlg + right

X,Y,A,B,C = map(int,input().split())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
R = list(map(int,input().split()))
PP=quickSort(P)
QQ=quickSort(Q)
S=PP[A-X:A]+QQ[B-Y:B]+R
SS=quickSort(S)
D=0
for r in range(X+Y):
 D+=SS[C+r]
print(D)
Problem p02775 (python)

Fixed submission:
N=input()
L=len(N)
ans=[[0 for e in range(2)] for f in range(L)]
k=int(N[L-1])
ans[0][0]=k
ans[0][1]=10-k
if L>1:
 for i in range(1,L):
  k=int(N[L-1-i])
  ans[i][0]=min(ans[i-1][0]+k,ans[i-1][1]+k+1)
  ans[i][1]=min(ans[i-1][0]+10-k,ans[i-1][1]+10-k-1)
print(min(ans[L-1][0],ans[L-1][1]+1))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N,Q=map(int,input().split())
ans=[0]*N
ki=[[] for _ in range(N)]
for i in range(N-1):
 a,b=map(int,input().split())
 ki[a-1].append(b-1)
 ki[b-1].append(a-1)
for i in range(Q):
 p,q=map(int,input().split())
 ans[p-1]+=q
# dfs
from collections import deque
stack =deque([0])
visited = ["False"] * N
while stack:
 ne = stack.popleft()
 if visited[ne] == "False":
  visited[ne] = "True"
  for j in ki[ne]:
   if visited[j] == "False":
    ans[j]+=ans[ne]
    stack.append(j)
print(*ans)

Buggy submission (verdict: Runtime Error):
def digit(i):
 if i > 0:
  return digit(i//10) + [i%10]
 else:
  return []
N=int(input())
lst=digit(N)
L=len(lst)
ans=[[0 for e in range(2)] for f in range(L)]
ans[0][0]=lst[L-1]
ans[0][1]=10-lst[L-1]
for i in range(1,L):
 ans[i][0]=min(ans[i-1][0]+lst[L-1-i],ans[i-1][1]+lst[L-1-i]+1)
 ans[i][1]=min(ans[i-1][0]+10-lst[L-1-i],ans[i-1][1]+10-lst[L-1-i]-1)
print(min(ans[L-1][0],ans[L-1][1]+1))
Problem p02783 (python)

Fixed submission:
h,a=map(int,input().split())
b=int((h-1)/a)+1
print(b)

Buggy submission (verdict: Runtime Error):
def nibun_right(a, x):
 lo, hi = 0, len(a)
 while lo < hi:
  mid = (lo+hi)//2
  if x < a[mid][0]: hi = mid
  else: lo = mid+1
 return lo
N,D,A=map(int,input().split())
lst=[0]*N
for i in range(N):
 lst[i]=list(map(int,input().split()))
lst.sort()
ans=0
print(ans)
Problem p02788 (python)

Fixed submission:
def nibun_right(a, x, lo=0, hi=None):
 if lo < 0:
  raise ValueError('lo must be non-negative')
 if hi is None:
  hi = len(a)
 while lo < hi:
  mid = (lo+hi)//2
  if x < a[mid][0]: hi = mid
  else: lo = mid+1
 return lo
N,D,A=map(int,input().split())
lst=[0]*N
for i in range(N):
 lst[i]=list(map(int,input().split()))
lst.sort()
DMG=[0]*N
ans=0
for i in range(N):
 if i!=0:
  DMG[i]+=DMG[i-1]
 renji=nibun_right(lst,lst[i][0]+2*D)
 Z=max(int((lst[i][1]-1)/A)+1-DMG[i],0)
 DMG[i]+=Z
 if renji!=N:
  DMG[renji]-=Z
 ans+=Z
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
def nibun_right(a, x):
 lo, hi = 0, len(a)
 while lo < hi:
  mid = (lo+hi)//2
  if x < a[mid][0]: hi = mid
  else: lo = mid+1
 return lo
N,D,A=map(int,input().split())
lst=[0]*N
for i in range(N):
 lst[i]=list(map(int,input().split()))
 lst[i][1]=int((lst[i][1]-1)/A))+1
lst.sort(key=itemgetter(0))
DMG=[0]*(N+1)
ans=0
for i in range(N):
 renji=nibun_right(lst,lst[i][0]+2*D)
 Z=max(lst[i][1]-DMG[i],0)
 DMG[i]+=Z
 DMG[renji]-=Z
 ans+=Z
 DMG[i+1]+=DMG[i]
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
def nibun_right(a, x):
 lo, hi = 0, len(a)
 while lo < hi:
  mid = (lo+hi)//2
  if x < a[mid][0]: hi = mid
  else: lo = mid+1
 return lo
N,D,A=map(int,input().split())
lst=[0]*N
for i in range(N):
 lst[i]=list(map(int,input().split()))
 lst[i][1]=int((lst[i][1]-1)/A))+1
lst.sort()
DMG=[0]*(N+1)
ans=0
for i in range(N):
 renji=nibun_right(lst,lst[i][0]+2*D)
 Z=max(lst[i][1]-DMG[i],0)
 DMG[i]+=Z
 DMG[renji]-=Z
 ans+=Z
 DMG[i+1]+=DMG[i]
print(ans)

Buggy submission (verdict: Runtime Error):
def nibun_right(a, x):
 lo, hi = 0, len(a)
 while lo < hi:
  mid = (lo+hi)//2
  if x < a[mid][0]: hi = mid
  else: lo = mid+1
 return lo
N,D,A=map(int,input().split())
lst=[0]*N
for i in range(N):
 lst[i]=list(map(int,input().split()))
 lst[i][1]=int((lst[i][1]-1)/A))+1
lst.sort()
ans=0
print(ans)

Buggy submission (verdict: Runtime Error):
def nibun_right(a, x):
 lo, hi = 0, len(a)
 while lo < hi:
  mid = (lo+hi)//2
  if x < a[mid][0]: hi = mid
  else: lo = mid+1
 return lo
N,D,A=map(int,input().split())
lst=[0]*N
for i in range(N):
 lst[i]=list(map(int,input().split()))
 lst[i][1]=int((lst[i][1]-1)/A))+1
lst.sort()

Buggy submission (verdict: Runtime Error):
def nibun_right(a, x):
 lo, hi = 0, len(a)
 while lo < hi:
  mid = (lo+hi)//2
  if x < a[mid][0]: hi = mid
  else: lo = mid+1
 return lo
N,D,A=map(int,input().split())
lst=[0]*N
for i in range(N):
 lst[i]=list(map(int,input().split()))
 lst[i][1]=int((lst[i][1]-1)/A))+1
lst.sort()
DMG=[0]*(N+1)
ans=0
for i in range(N):
 renji=nibun_right(lst,lst[i][0]+2*D)
 Z=max(lst[i][1]-DMG[i],0)
 DMG[i]+=Z
 DMG[renji]-=Z
 ans+=Z
 DMG[i+1]+=DMG[i]
print(ans)