Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())
count = 0
while True:
    if count % 2 == 0:
        C -= B
    else:
        A -= D
    count += 1
    if A <= 0:
        print("No")
        break
    elif C <= 0:
        print("Yes")
        break


Fixed submission:
a, b = map(int, input().split())
if a <= b:
    print("unsafe")
else:
    print("safe")
Buggy python submission (verdict: Runtime Error):
N = int(input())
l = []
for i in range(N):
    l.append(int(input()))
print(len(set(l)))


Fixed submission:
N = int(input())
l = [input() for i in range(N)]
print(len(set(l)))
Buggy python submission (verdict: Runtime Error):
n=int(input())
p=n%10
if p in [2,4,5,7,9]:
  return "hon"
elif p in [0,1,6,8]:
  return "pon"
return "bon"

Fixed submission:
n=int(input())
p=n%10
if p in [2,4,5,7,9]:
  print("hon")
elif p in [0,1,6,8]:
  print("pon")
else:
  print("bon")
Buggy python submission (verdict: Runtime Error):
k = int(input())
list = input().split()

if int(list[0])//k != int(list[1])//k:
  print("OK")
else if int(list[0])%k == 0:
  print("OK")
else:
  print("NG")


Fixed submission:
k = int(input())
list = input().split()

if int(list[0])//k != int(list[1])//k:
  print("OK")
elif int(list[0])%k == 0:
  print("OK")
else:
  print("NG")
Buggy python submission (verdict: Time Limit Exceeded):
import queue
N, M = map(int, input().split())


path = [[] for i in range(N + 1)]


for i in range(M):
    a,b = map(int,input().split())
    path[a].append(b)
    path[b].append(a)


flag_directions = [-1 for i in range(N + 1)]

q = queue.Queue()
for p in path[1]:
    q.put((1, p))

while not q.empty():
    current, to = q.get()
    if flag_directions[to] == -1:
        flag_directions[to] = current 
        for next_room in path[to]:
            q.put((to, next_room))


print('Yes')
for f in flag_directions[2:]:
    print(f)

Fixed submission:
import queue
N, M = map(int, input().split())


path = [[] for i in range(N + 1)]


for i in range(M):
    a,b = map(int,input().split())
    path[a].append(b)
    path[b].append(a)


flag_directions = [-1 for i in range(N + 1)]

q = queue.Queue()
for p in path[1]:
    q.put((1, p))

while not q.empty():
    current, to = q.get()
    if flag_directions[to] == -1:
        flag_directions[to] = current 
        for next_room in path[to]:
            q.put((to, next_room))


print('Yes')
for f in flag_directions[2:]:
    print(f)
Buggy python submission (verdict: Runtime Error):
a,b=list(int(input().split()))
print(max(a+b,a-b,a*b))

Fixed submission:
a,b=list(map(int,input().split()))
print(max(a+b,a-b,a*b))

Buggy python submission (verdict: Runtime Error):
a,b=list(int(input().split()))
print(max(a+b,a-b,a*b)

Fixed submission:
a,b=list(map(int,input().split()))
print(max(a+b,a-b,a*b))
Buggy python submission (verdict: Runtime Error):
l=[int(input())for _ in range(4)]
print(min((l[0],l[1]),(l[2],l[3]))

Fixed submission:
a=int(input())
b=int(input())
c=int(input())
d=int(input())
print(min(a,b)+min(c,d))

Buggy python submission (verdict: Runtime Error):
l=[int(input())for _ in range(4)]
print(min(l[0],l[1])+min(l[3],l[4]))


Fixed submission:
a=int(input())
b=int(input())
c=int(input())
d=int(input())
print(min(a,b)+min(c,d))
Buggy python submission (verdict: Runtime Error):
N = int(input())
print(0)
now = input()
old = now
che = N//2+1
nowi = 0
print(nowi+che)
nowi = N//2+1
first = True
ische = (che%2==0)
for i in range(18):
    now = input()
    if now==old:
        if che%2==0:
            pass
        elif che%2==1:
            first = not first
    elif now!=old:
        if che%2==0:
            first = not first
        elif che%2==1:
            pass
        che-=che//2+1
        nowi = nowi+che
    if first:
        print(nowi+che)
        nowi+=che
    else:
        print(nowi-che)
        nowi-=che
    old = now


Fixed submission:
x,y=map(int,input().split())
if x%y==0:
    print(-1)
    exit()
print(x)
Buggy python submission (verdict: Runtime Error):
N,Y = map(int,input().split())
Y = Y/1000
torf = False
for numoft in range(N+1):
    for numof5t in range(N-numoft+1):
        numof10t = (N)-(numoft+numof5t)
        if Y == numoft + 5*numof5t + 10*numof10t:
            print(numof10t,numof5t,numoft)
            exit()
print("-1 -1 -1")

Fixed submission:
s = list(input())
s[3]="8"
st=""
for c in s:
    st +=c
print(st)
Buggy python submission (verdict: Runtime Error):
n,y=map(int,input().split())
for i in range(n-1):
  a10000=i+1
  for i2 in range(n-1-a10000):
    a5000=i2+1
    for i3 in range(n-1-a10000-a5000):
      a1000=i3+1
      if a10000*10000+a5000*5000+a1000*1000==y
        print(a10000,a5000,a1000)
        exit()
print("-1 -1 -1")

Fixed submission:
N,Y = map(int,input().split())
Y = Y/1000
torf = False
for numoft in range(N+1):
    for numof5t in range(N-numoft+1):
        numof10t = (N)-(numoft+numof5t)
        if Y == numoft + 5*numof5t + 10*numof10t:
            print(numof10t,numof5t,numoft)
            exit()
print("-1 -1 -1")

Buggy python submission (verdict: Runtime Error):
n,y=map(int,input().split())
for i in range(n-1):
  a10000=i+1
  for i2 in range(n-1-a10000):
    a5000=i2+1
      for i3 in range(n-1-a10000-a5000):
        a1000=i3+1
        if a10000*10000+a5000*5000+a1000*1000==y:
          print(a10000,a5000,a1000)
          exit()
print("-1 -1 -1")

Fixed submission:
N,Y = map(int,input().split())
Y = Y/1000
torf = False
for numoft in range(N+1):
    for numof5t in range(N-numoft+1):
        numof10t = (N)-(numoft+numof5t)
        if Y == numoft + 5*numof5t + 10*numof10t:
            print(numof10t,numof5t,numoft)
            exit()
print("-1 -1 -1")
Buggy python submission (verdict: Runtime Error):
N = int(input())
clis = [];slis =[];flis = []
for i in range(N-1):
    c,s,f = map(int,input().split())
    clis.append(c);slis.append(s);flis.append(f)
for i in range(N):
    count=0
    for i2 in range(N-i-1):
        c=clis[i+i2];s=slis[i+i2];f=flis[i+i2]
        if count <= s:
            count=s+c
        elif (count-s)%f ==0:
            count = count+c
        else:
            count = count + c f-count%f
    print(count)


Fixed submission:
N = int(input())
clis = [];slis =[];flis = []
for i in range(N-1):
    c,s,f = map(int,input().split())
    clis.append(c);slis.append(s);flis.append(f)
for i in range(N):
    count=0
    for i2 in range(N-i-1):
        c=clis[i+i2];s=slis[i+i2];f=flis[i+i2]
        if count <= s:
            count=s+c
        elif (count-s)%f ==0:
            count = count+c
        else:
            count = count + c+f-count%f
    print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
clis = [];slis =[];flis = []
for i in range(N-1):
    c,s,f = map(int,input().split())
    clis.append(c);slis.append(s);flis.append(f)
for i in range(N):
    count =0
    for i2 in range(N-i-1):
        s = slis[i+i2]
        f = flis[i+i2]
        i3 = 0
        while True:
            if s+f*i3 >= count:
                count = s+f*i3+clis[i+i2]
                break
            i3 += 1
    print(count)


Fixed submission:
N = int(input())
clis = [];slis =[];flis = []
for i in range(N-1):
    c,s,f = map(int,input().split())
    clis.append(c);slis.append(s);flis.append(f)
for i in range(N):
    count=0
    for i2 in range(N-i-1):
        c=clis[i+i2];s=slis[i+i2];f=flis[i+i2]
        if count <= s:
            count=s+c
        elif (count-s)%f ==0:
            count = count+c
        else:
            count = count + c+f-count%f
    print(count)
Buggy python submission (verdict: Time Limit Exceeded):
sosu  =[i+2 for i in range(99999)]
for i in range(len(sosu)):
    if sosu[i] != 0:
        i2 = (i+2)*2-2
        while i2 < len(sosu):
            sosu[i2] =0
            i2 += i+2
Q = int(input())
sosu.remove(0)
lis = []
for i in range(Q):
    lis.append(list(map(int,input().split())))
for i in lis:
    c,r = i
    count = 0
    while c <= r:
        if c in sosu:
            if int((c+1)/2) in sosu:
                count +=1
        c+=1
    print(count)


Fixed submission:
# -*- coding: utf-8 -*-       
import math
def is_prime(x):
    if(x%2==0):return 0
    else:
        a = 3
        while(a<=math.sqrt(x)):
            if(x%a==0):return 0
            a += 2
    return 1
 
q = int(input())
MAX = 10**5+2
prime = [0 for i in range(MAX)]
alike = [0 for i in range(MAX)]
num = [0 for i in range(MAX)]
prime[2],prime[3] = 1,1
for i in range(4,MAX):
    prime[i] = is_prime(i)
for i in range(1,MAX-1,2):
    if(prime[i]==1 and prime[(i+1)//2]==1):
        alike[i] = 1
    num[i] = num[i-2]+alike[i]
    num[i+1] = num[i]
for i in range(q):
    l, r = list(map(int,input().split()))
    print(num[r]-num[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
sosu  =[i+2 for i in range(99999)]
for i in range(len(sosu)):
    if sosu[i] != 0:
        i2 = (i+2)*2-2
        while i2 < len(sosu):
            sosu[i2] =0
            i2 += i+2
Q = int(input())

lis = []
for i in range(Q):
    lis.append(list(map(int,input().split())))
for i in lis:
    c,r = i
    count = 0
    while c <= r:
        if c in sosu:
            if int((c+1)/2) in sosu:
                count +=1
        c+=1
    print(count)


Fixed submission:
# -*- coding: utf-8 -*-       
import math
def is_prime(x):
    if(x%2==0):return 0
    else:
        a = 3
        while(a<=math.sqrt(x)):
            if(x%a==0):return 0
            a += 2
    return 1
 
q = int(input())
MAX = 10**5+2
prime = [0 for i in range(MAX)]
alike = [0 for i in range(MAX)]
num = [0 for i in range(MAX)]
prime[2],prime[3] = 1,1
for i in range(4,MAX):
    prime[i] = is_prime(i)
for i in range(1,MAX-1,2):
    if(prime[i]==1 and prime[(i+1)//2]==1):
        alike[i] = 1
    num[i] = num[i-2]+alike[i]
    num[i+1] = num[i]
for i in range(q):
    l, r = list(map(int,input().split()))
    print(num[r]-num[l-1])
Buggy python submission (verdict: Runtime Error):
s = input()
x,y=map(int,input().split())
fst = True;xory=1;xc=0;yc=0;xlis=[];ylis=[0];
for c in s:
    if c == "F":
        if xory == 1:
            xc +=1
        else:
            yc +=1
    else:
        if fst and xory ==1:
            xlis.append(xc)
            fst = False
            xory -=1
            xc = 0
        elif xory == 1:
            kari = xlis
            xlis =[i+xc for i in kari]
            xlis.extend([i-xc for i in kari])
            xc = 0
            xory -=1
        else:
            kari = ylis
            ylis = [i+yc for i in kari]
            ylis.extend([i-yc for i in kari])
            yc = 0
            xory +=1
if xory == 1:
    kari = xlis
    xlis =[i+xc for i in kari]
    xlis.extend([i-xc for i in kari])
    xc = 0
else:
    kari = ylis
    ylis = [i+yc for i in kari]
    ylis.extend([i-yc for i in kari])
    yc = 0

if x in xlis and y in ylis:
    print("Yes")
else:
    print("No")


Fixed submission:
import math
a , b = map(float,input().split())
print(math.ceil((a+b)/2))
Buggy python submission (verdict: Time Limit Exceeded):
N , K = list(map(int,input().split()))
li = list(map(int,input().split()))
typ = []
for i in range(N):
    if li[i] == -1: 
        pass
    else:
        count = 0 
        num = li[i]
        for i2 in range(N - i): 
            if li[i + i2] == num:
                count += 1
                li[i + i2] = -1
        typ.append(count)
typ.sort()
count = 0 
if len(typ) > K:
    for i in range(len(typ) - K): 
        count += typ[i]
print(count)

Fixed submission:
N , K = list(map(int,input().split()))
li = list(map(int,input().split()))
typ = []
li.sort()
count = 0 
for i in range(N - 1): 
    count += 1
    if li[i] != li[i + 1]: 
        typ.append(count)
        count = 0 
if li[N - 1] != li[N - 2]: 
    typ.append(1)
else:
    typ.append(count + 1)
typ.sort()
count = 0 
if len(typ) > K:
    for i in range(len(typ) - K): 
        count += typ[i]
print(count)
Buggy python submission (verdict: Runtime Error):
N ,M=map(float,input().split())
print(int((1900*M+100*(N-M)*2**M))


Fixed submission:
N ,M=map(float,input().split())
print(int((1900*M+100*(N-M))*2**M))
Buggy python submission (verdict: Runtime Error):
import numpy as np

H, W = map(int, input().split())
arr=np.array([])
s=0
while s != H:
  li=list(input())
  li=np.array(li)
  arr=np.hstack((arr,li))

  s+=1
arr=arr.reshape((H,W))
count=0
def check(x,y):
    global count
    if arr[x,y] == "#":
        count+=1

for x in range(H):
    stri=""
    for y in range(W):
        if arr[x,y] == ".":
            count=0
            top= None
            right =None
            left=None
            if y != 0:
                top=True
                check(x,(y-1))
            if x != 0:
                if top:
                    check((x-1),(y-1))
                check((x-1),y)
                left=True
            if x != (W-1):
                if top:
                    check((x+1),(y-1))
                right=True
                check((x+1),y)
            if y != (H-1):
                if left:
                    check(x-1,y+1)
                if right:
                    check(x+1,y+1)
                check(x,(y+1))
            print(str(count),end="")
        else:
            print("#",end="")
    print("")


Fixed submission:
a ,b ,c=map(int,raw_input().split())
if a==b:
  print(c)
elif a==c:
  print(b)
else:
  print(a)

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

H, W = map(int, raw_input().split())
arr=np.array([])
s=0
while s != H:
  li=list(raw_input())
  li=np.array(li)
  arr=np.hstack((arr,li))

  s+=1
arr=arr.reshape((H,W))
count=0

def check(x,y):
    import __main__
    if arr[x,y] == "#":
        __main__.count+=1

for x in range(H):
    stri=""
    for y in range(W):
        if arr[x,y] == ".":
            count=0
            top= None
            right =None
            left=None
            if y != 0:
                top=True
                check(x,(y-1))
            if x != 0:
                if top:
                    check((x-1),(y-1))
                check((x-1),y)
                left=True
            if x != (W-1):
                if top:
                    check((x+1),(y-1))
                right=True
                check((x+1),y)
            if y != (H-1):
                if left:
                    check(x-1,y+1)
                if right:
                    check(x+1,y+1)
                check(x,(y+1))
            stri=stri+str(count)
        else:
            stri=stri+"#"
    print(stri)


Fixed submission:
a ,b ,c=map(int,raw_input().split())
if a==b:
  print(c)
elif a==c:
  print(b)
else:
  print(a)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))
for i in T:
    if i in D:
        D.pop(D.index(i))
    else:
        print("NO")
        exit()
print("YES")


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

D.sort();T.sort()
di = 0
ti = 0
while True:
     d = D[di];t=T[ti]
     if d==t:
         di+=1;ti+=1
     elif d>t:
         print("NO")
         exit()
     elif t>d:
         di+=1
     if ti >= len(T):
         print("YES")
         exit()
     if di >= len(D):
         print(di)
         print("NO")
         exit()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(raw_input())
li=[]
while n !=0:
    a = int(raw_input())
    if a not in li:
        li.append(a)
    else:
        li.remove(a)
    n-=1
print(len(li))


Fixed submission:
n=int(raw_input())
li={}
while n !=0:
    a = raw_input()
    if a in li:
        del li[a]
    else:
        li[a]=a
    n-=1
print(len(li))
Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
inlis = list(map(int,input().split()))
donelis =[]
numlis=[]

for i in inlis:
    donelis.append(i+1)
    donelis.append(i)
    donelis.append(i-1)
    if not i in numlis:
        numlis.append(i)
    if not i+1 in numlis:
        numlis.append(i+1)
    if not i-1 in numlis:
        numlis.append(i-1)
estc =0
for i in numlis:
    a =donelis.count(i)
    if estc < a:
        estc = a
print(estc)

Fixed submission:
n = int(input())
inlis = list(map(int,input().split()))
donelis =[]
numlis=[]

for i in inlis:
    donelis.append(i+1)
    donelis.append(i)
    donelis.append(i-1)

estc =0
donelis.sort()
a = -2
count=0
for i in donelis:
    if a != i:
        if count > estc:
            estc = count
        count = 1
        a = i
    else:
        count +=1
if count >estc:
    estc =count
print(estc)

Buggy python submission (verdict: Time Limit Exceeded):
N= int(input())
inlis = list(map(int,input().split()))
donelis =[]
for i in inlis:
    donelis.append(i+1)
    donelis.append(i)
    donelis.append(i-1)
estc =0
for i in donelis:
    a =donelis.count(i)
    if estc < a:
        estc = a
print(estc)

Fixed submission:
n = int(input())
inlis = list(map(int,input().split()))
donelis =[]
numlis=[]

for i in inlis:
    donelis.append(i+1)
    donelis.append(i)
    donelis.append(i-1)

estc =0
donelis.sort()
a = -2
count=0
for i in donelis:
    if a != i:
        if count > estc:
            estc = count
        count = 1
        a = i
    else:
        count +=1
if count >estc:
    estc =count
print(estc)
Buggy python submission (verdict: Runtime Error):
(t if t < 24 else t-24)

Fixed submission:
a,b=map(int,input().split())
t=a+b
print(t if t < 24 else t-24)
Buggy python submission (verdict: Runtime Error):
a,b=input().split()
if a=="H":
  f=True
else:
  f=False
if f:
  print("H" if b=="H" else "D")
else:
  print("H" if b=="D" else "D"

Fixed submission:
a,b=input().split()
if a=="H":
  f=True
else:
  f=False
if f:
  print("H" if b=="H" else "D")
else:
  print("H" if b=="D" else "D")
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())

if a==b
  print("Draw")
elif a==1:
  print("Alice")
elif b==1:
  print("Bob")
elif a>b:
  print("Alice")
else:
  print("Bob")

Fixed submission:
a,b=map(int,input().split())
     
if a==b:
  print("Draw")
elif a==1:
  print("Alice")
elif b==1:
  print("Bob")
elif a>b:
  print("Alice")
else:
  print("Bob")
Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
c=0
for i in range(k+1):
  for i2 in range(k+1):
    for i3 in range(k+1):
      if i+i2+i3==s:
        c+=1
print(c)

Fixed submission:
k,s=map(int,input().split())
c=0
for i in range(k+1):
  for i2 in range(k+1):
      if i+i2>s:
        break
      elif s-(i+i2) <=k: 
        c+=1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
c=0
for i in range(k+1):
  for i2 in range(k+1):
    for i3 in range(k+1):
      if i+i2+i3==s:
        c+=1
print(c)

Fixed submission:
k,s=map(int,input().split())
c=0
for i in range(k+1):
  for i2 in range(k+1):
      if i+i2>s:
        break
      elif s-(i+i2) <=k: 
        c+=1
print(c)

Buggy python submission (verdict: Runtime Error):
k,s=map(int,input().split())
c=0
for i in range(k+1):
  for i2 in range(k+1):
    for i3 in range(k+1):
      if i+i2+i3i==s:
        c+=1
print(c)

Fixed submission:
k,s=map(int,input().split())
c=0
for i in range(k+1):
  for i2 in range(k+1):
      if i+i2>s:
        break
      elif s-(i+i2) <=k: 
        c+=1
print(c)
Buggy python submission (verdict: Runtime Error):
A,op,B=input.split() 
if op=="+": 
    print(int(A)+int(B)) 
else: 
    print(int(A)-int(B))

Fixed submission:
A,op,B=input().split() 
if op=="+": 
    print(int(A)+int(B)) 
else: 
    print(int(A)-int(B))
Buggy python submission (verdict: Runtime Error):
K = int(input())
S = input()
if len(S) > K:
    new_S = S[:K]
    new_S += '...'
    print(new_S)
else:
    print(S)

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 python submission (verdict: Runtime Error):
K = int(input())
S = input()
if len(S) > K:
	new_S = S[:K]
	new_S += '...'
    print(new_S)
else:
  print(S)


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 python submission (verdict: Runtime Error):
N = int(input())

if N % 10 == 3:
	print('bon')
else if N%10 == 0 or N%10 == 1 or N%10 == 6 or N%10 == 8:
	print('pon')
else: print('hon')
  

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 python submission (verdict: Runtime Error):
num = [x for x in input().split() ]
count5 = num.count5("5")
count7 = num.count7("7")
if count5 == 2 and count7 == 1:
  print("YES")
else:
  print("NO")

Fixed submission:
num = list(map(int,input().split()))
if num.count(5) == 2 and num.count(7) == 1:
  print("YES")
else:
  print("NO")

Buggy python submission (verdict: Runtime Error):
num = list.input()
count1 = num.count(5)
count2 = num.count(7)
if count1 == 2 and count2 == 7:
  print("YES")
else:
  print("NO")

Fixed submission:
num = list(map(int,input().split()))
if num.count(5) == 2 and num.count(7) == 1:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


const int N_MAX = 100001;
VI prime;
void generate_prime() {
    prime.push_back(2); 
    FOR(i, 3, N_MAX) {
        for(auto p : prime) {
            if(i % p == 0) break;
            if(p > sqrt(i)) {
                prime.push_back(i);
                break;
            }
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    generate_prime();
    set<int> prime1(ALL(prime));
    set<int> prime2;
    for(auto& p : prime1) {
        if(p == 2) continue;
        if(prime1.count((p + 1) / 2) == 1) prime2.insert(p);
    }
    VI ans(N_MAX);
    ans[0] = 0;
    FOR(i, 1, N_MAX - 1) {
        if(prime2.count(i) == 1) ans[i] = ans[i - 1] + 1;
        else ans[i] = ans[i - 1];
    }
    
    int q;
    cin >> q;
    REP(i, q) {
        int l, r;
        cin >> l >> r;
        cout << ans[r] - ans[l - 1] << '\n';
    }
    return 0;
}


Fixed submission:
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import math


def generate_prime(p_max):
    prime = [2]
    for i in range(3, p_max + 1):
        for p in prime:
            if i % p == 0:
                break
            if p > math.sqrt(i):
                prime.append(i)
                break
    return prime


def main():
    prime = generate_prime(10**5)
    prime = set(prime)
    prime2 = set()
    for p in prime:
        if p == 2:
            continue
        if (p + 1) / 2 in prime:
            prime2.add(p)
    ans = [0] * (10**5 + 1)
    for i in range(1, 10**5 + 1):
        if i in prime2:
            ans[i] = ans[i - 1] + 1
        else:
            ans[i] = ans[i - 1]

    q = int(input())
    queries = [[int(i) for i in input().split()] for _ in range(q)]
    for query in queries:
        print(ans[query[1]] - ans[query[0] - 1])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())
M = [tuple(map(int, input().split())) for i in range(N)]

dp = [float("inf")] * (H+1)
dp[H] = 0

for i in range(H, 0, -1):
  for j in range(N):
    a, b = M[j]
    dp[i-a if i-a >= 0 else 0] = min(dp[i-a if i-a >= 0 else 0], dp[i] + b)
print(dp[0])

Fixed submission:
H, N = map(int, input().split())
M = [tuple(map(int, input().split())) for i in range(N)]

dp = [float("inf")] * (H+1)
dp[H] = 0

for i in range(H, 0, -1):
  for j in range(N):
    a, b = M[j]
    dp[i-a if i-a >= 0 else 0] = min(dp[i-a if i-a >= 0 else 0], dp[i] + b)
print(dp[0])