Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
def isprime(x):
  if x==1:
    return False
  if x==2:
    return True
  for i in range(2,int(x**0.5)+1):
    if x%i==0:
      return False
  return True

def like2017(x):
  return (isprime(x) and isprime((x+1)//2))

a=[like2017(i) for i in range(10**5+1)]

a_cum=np.cumsum(a)

q=int(input())
for i in range(q):
  l,r=map(int,input().split())
  print(a_cum[r]-a_cum[l-1])

Fixed submission:
from functools import lru_cache
@lru_cache(maxsize=None)
def is_prime(x):
    if x==1:
        return False
    for i in range(2,int(x**0.5)+1):
        if x%i==0:
            return False
    return True

# @lru_cache(maxsize=None)
def like2017(x):
    return is_prime(i) and is_prime((i+1)//2)
    
table=[0,0]
for i in range(2,10**5):
    table+=table[i-1]+like2017(i),
        
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    print(table[b]-table[a-1])
# print(table)

Buggy python submission (verdict: Runtime Error):
import numpy as np
def isprime(x):
  if x==1:
    return False
  if x==2:
    return True
  for i in range(2,int(x**0.5)+1):
    if x%i==0:
      return False
  return True

def like2017(x):
  return (isprime(x) and isprime((x+1)//2))


a=[like2017(i) for i in range(10**5+1)]

a_cum=np.cumsum(a)

q=int(input())
for i in range(q):
  l,r=map(int,input().split())
  print(a_cum[r]-a_cum[l-1])


Fixed submission:
from functools import lru_cache
@lru_cache(maxsize=None)
def is_prime(x):
    if x==1:
        return False
    for i in range(2,int(x**0.5)+1):
        if x%i==0:
            return False
    return True

# @lru_cache(maxsize=None)
def like2017(x):
    return is_prime(i) and is_prime((i+1)//2)
    
table=[0,0]
for i in range(2,10**5):
    table+=table[i-1]+like2017(i),
        
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    print(table[b]-table[a-1])
# print(table)

Buggy python submission (verdict: Runtime Error):
import numpy as np
def isprime(x):
  if x==1:
    return False
  if x==2:
    return True
  for i in range(2,int(x**0.5)+1):
    if x%i==0:
      return False
  return True

def like2017(x):
  return (isprime(x) and isprime((x+1)//2))


a=[like2017(i) for i in range(10**5+1)]

a_cum=np.cumsum(a)

q=int(input())
for i in range(q):
  l,r=map(int,input().split())
  print(a_cum[r]-a_cum[l-1])


Fixed submission:
from functools import lru_cache
@lru_cache(maxsize=None)
def is_prime(x):
    if x==1:
        return False
    for i in range(2,int(x**0.5)+1):
        if x%i==0:
            return False
    return True

# @lru_cache(maxsize=None)
def like2017(x):
    return is_prime(i) and is_prime((i+1)//2)
    
table=[0,0]
for i in range(2,10**5):
    table+=table[i-1]+like2017(i),
        
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    print(table[b]-table[a-1])
# print(table)

Buggy python submission (verdict: Time Limit Exceeded):
def is_prime(x):
    if x==1:
        return False
    for i in range(2,int(x**0.5)+1):
        if x%i==0:
            return False
    return True
    
def like2017_1tox(x):
    cnt=0
    for i in range(1,x+1,+2):
        if is_prime(i):
            if is_prime((i+1)//2):
                cnt+=1
        
    return cnt
    
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    print(like2017_1tox(b)-like2017_1tox(a-1))


Fixed submission:
from functools import lru_cache
@lru_cache(maxsize=None)
def is_prime(x):
    if x==1:
        return False
    for i in range(2,int(x**0.5)+1):
        if x%i==0:
            return False
    return True

# @lru_cache(maxsize=None)
def like2017(x):
    return is_prime(i) and is_prime((i+1)//2)
    
table=[0,0]
for i in range(2,10**5):
    table+=table[i-1]+like2017(i),
        
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    print(table[b]-table[a-1])
# print(table)

Buggy python submission (verdict: Time Limit Exceeded):
def is_prime(x):
    if x==1:
        return False
    for i in range(2,int(x**0.5)+1):
        if x%i==0:
            return False
    return True
    
def like2017_1tox(x):
    cnt=0
    for i in range(1,x+1,+2):
        # print(i)
        if is_prime(i):
            if is_prime((i+1)//2):
                cnt+=1   
    return cnt
    
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    print(like2017_1tox(b)-like2017_1tox(a-1))


Fixed submission:
from functools import lru_cache
@lru_cache(maxsize=None)
def is_prime(x):
    if x==1:
        return False
    for i in range(2,int(x**0.5)+1):
        if x%i==0:
            return False
    return True

# @lru_cache(maxsize=None)
def like2017(x):
    return is_prime(i) and is_prime((i+1)//2)
    
table=[0,0]
for i in range(2,10**5):
    table+=table[i-1]+like2017(i),
        
n=int(input())
for _ in range(n):
    a,b=map(int,input().split())
    print(table[b]-table[a-1])
# print(table)