Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heapify, heappush, heappop
def main():
    N, M = map(int, input().split())
    lst = list(map(int, input().split()))
    lst = [-l for l in lst]
    heapify(lst)
    
    for _ in range(M):
        b, c = map(int, input().split())
        for _ in range(b):
            heappush(lst, -c)
    
    ans = 0
    for _ in range(N):
        ans += heappop(lst)
    print(-ans)
main()

Fixed submission:
from heapq import heapify, heappush, heappop
def main():
    N, M = map(int, input().split())
    lst = list(map(int, input().split()))
    lst = [(-l, 1) for l in lst]
    heapify(lst)
    
    for _ in range(M):
        b, c = map(int, input().split())
        heappush(lst, (-c, b))
    
    ans = 0
    cnt = 0
    while True:
        tmp = heappop(lst)
        flag = False
        for _ in range(tmp[1]):
            ans -= tmp[0]
            cnt += 1
            if cnt==N:
                flag = True
                break
        
        if flag:
            break
    
    print(ans)
main()
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
S = list(map(int, S))

cnt = 0
renew=True
while S and renew:
    nextS = []
    renew = False
    lS = len(S)
    i = 0
    while (i <= lS-1):
        if i == lS-1:
            nextS.append(S[i])
            break
        a = S[i]
        b = S[i+1]
        if a != b:
            cnt += 1
            i+=2
            renew = True
        else:
            nextS.append(a)
            i+=1
    S = nextS
print(cnt*2)

Fixed submission:
from collections import Counter
S = list(input())
S = list(map(int, S))

cnt = Counter(S)
setS = set(S)
if len(setS) == 1:
    print(0)
else:
    print(2*min(cnt[0], cnt[1]))
Buggy python submission (verdict: Runtime Error):
lst = list(map(int, input().split('/'))
if lst[1] >= 5:
    print('TBD')
else:
    print('Heisei')

Fixed submission:
lst = list(map(int, input().split('/')))
if lst[1] >= 5:
    print('TBD')
else:
    print('Heisei')
Buggy python submission (verdict: Runtime Error):
def main():
    N = int(input())
    rate = 380000
    jpy = 0
    bit = 0
    for _ in range(N):
        x, u = input().split()
        if u=='JPY':
            jpy += x
        else:
            bit += x
    print(jpy + bit*rate)
main()

Fixed submission:
def main():
    N = int(input())
    rate = 380000
    jpy = 0
    bit = 0
    for _ in range(N):
        x, u = input().split()
        if u=='JPY':
            jpy += float(x)
        else:
            bit += float(x)
    print(jpy + bit*rate)
main()
Buggy python submission (verdict: Runtime Error):
def main():
    N, M = map(int, input().split())
    lst = list(map(int, input().split()))
    mapk = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
    
    dp = [0 for _ in range(N+1)] # ちょうどi本使ったときの最大桁数
    for i in range(1, N+1):
        tmp = []
        for k in lst:
            if (i-mapk[k])>=0:
                tmp.append(dp[i-mapk[k]] + 1)
            else:
                tmp.append(-float('inf'))
        dp[i] = max(tmp)
    #print(dp)
    
    ans = ''
    X = N
    lst = sorted(lst, reverse=True)
    for _ in range(dp[N]):
        for k in lst:
            if dp[X - mapk[k]] == dp[X] - 1:
                ans += str(k)
                X -= mapk[k]
                break
    print(ans)
main()

Fixed submission:
def main():
    N, M = map(int, input().split())
    lst = list(map(int, input().split()))
    mapk = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
    
    dp = [0 for _ in range(N+1)] # ちょうどi本使ったときの最大桁数
    for i in range(1, N+1):
        tmp = []
        for k in lst:
            if (i-mapk[k])>=0:
                tmp.append(dp[i-mapk[k]] + 1)
            else:
                tmp.append(-float('inf'))
        dp[i] = max(tmp)
    #print(dp)
    
    ans = ''
    X = N
    lst = sorted(lst, reverse=True)
    for _ in range(dp[N]):
        for k in lst:
            if (X-mapk[k]>=0) and (dp[X - mapk[k]] == dp[X] - 1):
                ans += str(k)
                X -= mapk[k]
                break
    print(ans)
main()
Buggy python submission (verdict: Runtime Error):
N, K =map(int, input().split())
lst = []
for _ in range(N):
    lst.append(int(input()))
sor = sorted(lst)

mindiff = float('inf')
for i in range(N-K+1):
    diff = selected[i] - selected[i+K-1]
    if diff <= mindiff:
        mindiff = diff
print(mindiff)

Fixed submission:
N, K =map(int, input().split())
lst = []
for _ in range(N):
    lst.append(int(input()))
sor = sorted(lst)

mindiff = float('inf')
for i in range(N-K+1):
    diff = sor[i+K-1] - sor[i] 
    if diff <= mindiff:
        mindiff = diff
print(mindiff)

Buggy python submission (verdict: Time Limit Exceeded):
N, K =map(int, input().split())
lst = []
for _ in range(N):
    lst.append(int(input()))
sor = sorted(lst)

mindiff = float('inf')
for i in range(N-K+1):
    selected = sor[i:i+K] 
    diff = selected[-1] - selected[0]
    if diff <= mindiff:
        mindiff = diff
print(mindiff) 

Fixed submission:
N, K =map(int, input().split())
lst = []
for _ in range(N):
    lst.append(int(input()))
sor = sorted(lst)

mindiff = float('inf')
for i in range(N-K+1):
    diff = sor[i+K-1] - sor[i] 
    if diff <= mindiff:
        mindiff = diff
print(mindiff)

Buggy python submission (verdict: Time Limit Exceeded):
N, K =map(int, input().split())
lst = []
for _ in range(N):
    lst.append(int(input()))
sor = sorted(lst)

mindiff = float('inf')
for i in range(N-K+1):
    selected = sor[i:i+K]
    diff = selected[-1] - selected[0]
    if diff <= mindiff:
        mindiff = diff
print(mindiff)

Fixed submission:
N, K =map(int, input().split())
lst = []
for _ in range(N):
    lst.append(int(input()))
sor = sorted(lst)

mindiff = float('inf')
for i in range(N-K+1):
    diff = sor[i+K-1] - sor[i] 
    if diff <= mindiff:
        mindiff = diff
print(mindiff)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
lis = []
for index in range(M):
	p, y = map(int, input().split())
	lis.append((p, y, index))

n_lis = []
for unique_p in range(1, N+1):
	tmp = [(p, y, index) for p, y, index in lis if p == unique_p]
	tmp = sorted(tmp, key=lambda x: x[1])
	for born, val in enumerate(tmp, start=1):
		p, y, index = val
		n_lis.append((p, y, index, born))

n_lis = sorted(n_lis, key=lambda x: x[2])

for p, _, _, born in n_lis:
	print('{}{}'.format(str(p).zfill(6), str(born).zfill(6)))

Fixed submission:
def main():
    N, M = map(int, input().split())
    citys = []
    for _ in range(M):
        p, y = map(int, input().split())
        citys.append((p, y))
    
    ### citysdict作成
    temp= [[] for _ in range(N)]
    for city in citys:
        p, y = city
        temp[p-1].append((p, y))
    sortedcitys = []
    for pre in temp:
        sortedcitys.append(sorted(pre, key=lambda x:x[1]))
    citysdict = {}
    for pre in sortedcitys:
        ban = 1
        for city in pre:
            citysdict[city] = ban
            ban += 1
    
    ## 出力
    for city in citys:
        up = city[0]
        down = citysdict[city]
        print('{:0>6}'.format(up) + '{:0>6}'.format(down))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
{ % if prediction_success % }
{ % endif % }
{ % if mod or yes_str or no_str % }

{ % endif % }
{ % if mod % }
MOD = None  # type: int
{ % endif % }
{ % if yes_str % }
YES = "None"  # type: str
{ % endif % }
{ % if no_str % }
NO = "None"  # type: str
{ % endif % }
{ % if prediction_success % }


def main():
    N = int(input())
    points = []
    for _ in range(N):
        x, y, h = map(int, input().split())
        points.append((x, y, h))
        if h >= 1:
            hint = (x, y, h)

    for px in range(1, 101):
        for py in range(1, 101):
            H = hint[2] + abs(px-hint[0]) + abs(py-hint[1])
            clearflag = True
            for point in points:
                x, y, h = point
                val = max([H - abs(px-x) - abs(py-y), 0])
                if val != h:
                    clearflag = False

            if clearflag:
                print(px, py, H)
                return
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    N = int(input())
    points = []
    for _ in range(N):
        x, y, h = map(int, input().split())
        points.append((x, y, h))
        if h >= 1:
            hint = (x, y, h)

    for px in range(101):
        for py in range(101):
            H = hint[2] + abs(px-hint[0]) + abs(py-hint[1])
            clearflag = True
            for point in points:
                x, y, h = point
                val = max([H - abs(px-x) - abs(py-y), 0])
                if val != h:
                    clearflag = False

            if clearflag:
                print(px, py, H)
                return
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

n, x = map(int, input().split())
city = list(map(int, input().split()))
city.append(x)
city = sorted(city)
diff = [city[i+1] - city[i] for i in range(len(city)-1)]

if len(diff)==1:
    print(diff[0])
else:
    print(gcd_list(diff))

Fixed submission:
from functools import reduce
from fractions import gcd

def gcd_list(numbers):
    return reduce(gcd, numbers)

n, x = map(int, input().split())
city = list(map(int, input().split()))
city.append(x)
city = sorted(city)
diff = [city[i+1] - city[i] for i in range(len(city)-1)]

if len(diff)==1:
    print(diff[0])
else:
    print(gcd_list(diff))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
H, W = map(int, input().split())

path = []
for i in range(H):
    y = i+1
    row = list(map(int, input().split()))
    if i%2==0:
        for j, coin in enumerate(row):
               x = j+1
               path.append([y, x, coin])
    else:
        for j, coin in enumerate(row[::-1]):
               x = W-j
               path.append([y, x, coin])
path = np.array(path)

ans = []
for k in range(len(path)-1):
    c = path[k,2]
    if c%2==0:
        continue
    else:
        y, x = path[k, :2]
        ny, nx = path[k+1, :2]
        ans.append((y, x, ny, nx))
        path[k+1, 2] += 1

print(len(ans))
for a in ans:
    print(a[0], a[1], a[2], a[3])

Fixed submission:
H, W = map(int, input().split())

path = []
for i in range(H):
    y = i+1
    row = list(map(int, input().split()))
    if i%2==0:
        for j, coin in enumerate(row):
               x = j+1
               path.append([y, x, coin])
    else:
        for j, coin in enumerate(row[::-1]):
               x = W-j
               path.append([y, x, coin])

ans = []
cnt = 0
for k in range(len(path)-1):
    c = path[k][2]
    if c%2==0:
        continue
    else:
        cnt += 1
        y, x = path[k][:2]
        ny, nx = path[k+1][:2]
        ans.append((y, x, ny, nx))
        path[k+1][2] += 1

print(cnt)
for a in ans:
    print(a[0], a[1], a[2], a[3])
Buggy python submission (verdict: Runtime Error):
s = input()
n = len(s)
k = int(input())
for i in range(k):
    if i == n:
        break

    if s[i] != '1':
        ans = int(s[i])
        break
    else:
        continue
if ans:
    print(ans)
else:
    print(1)

Fixed submission:
s = input()
n = len(s)
k = int(input())
ans = None
for i in range(k):
    if i == n:
        break

    if s[i] != '1':
        ans = int(s[i])
        break
    else:
        continue
if ans:
    print(ans)
else:
    print(1)

Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
for i in range(k):
    if s[i] != '1':
        ans = int(s[i])
        break
    else:
        continue
if ans:
    print(ans)
else:
    print(1)

Fixed submission:
s = input()
n = len(s)
k = int(input())
ans = None
for i in range(k):
    if i == n:
        break

    if s[i] != '1':
        ans = int(s[i])
        break
    else:
        continue
if ans:
    print(ans)
else:
    print(1)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
lst = list(map(int, input().split()))
ans = 0

for i in range(n):
    total = 0
    for j in range(i, n):
        total += lst[j]
        if total%m==0:
            ans += 1
print(ans)

Fixed submission:
from collections import Counter
import numpy as np
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
n, m = map(int, input().split())
lst = list(map(int, input().split()))
blst = [0]
total = 0
for i in range(n):
    total += lst[i]
    blst.append(total)
modblst = np.array(blst)%m
count = Counter(modblst)

ans = 0
for val in count.values():
    if val == 1:
        continue
    ans += cmb(val, 2)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
lst = list(map(int, input().split()))
ans = 0

for i in range(n):
    total = 0
    for j in range(i, n):
        total += lst[j]
        if total%m==0:
            ans += 1
print(ans)

Fixed submission:
from collections import Counter
import numpy as np
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
n, m = map(int, input().split())
lst = list(map(int, input().split()))
blst = [0]
total = 0
for i in range(n):
    total += lst[i]
    blst.append(total)
modblst = np.array(blst)%m
count = Counter(modblst)

ans = 0
for val in count.values():
    if val == 1:
        continue
    ans += cmb(val, 2)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
print(lcm(2, n))

Fixed submission:
n = int(input())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(a, b):
	return a * b // gcd (a, b)
print(lcm(2, n))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
i = 1
while True:
    if (i%2==0)and(i%n==0):
        print(i)
        break
    i += 1

Fixed submission:
n = int(input())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(a, b):
	return a * b // gcd (a, b)
print(lcm(2, n))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def twonum(n):
    count = Counter(prime_factorize(n))
    return count[2]

n = int(input())
ali = list(map(int, input().split()))
twos = []
for a in ali:
    twos.append(twonum(a))
print(sum(twos))

Fixed submission:
n = int(input())
ali = list(map(int, input().split()))
total = 0
for a in ali:
    while a%2==0:
        a = (a//2)
        total += 1
print(total)
Buggy python submission (verdict: Runtime Error):
tmp = [row[i] for i, row in enumerate(input())]
print(''.join(tmp))

Fixed submission:
tmp = [input()[i] for i in range(3)]
print(''.join(tmp))
Buggy python submission (verdict: Runtime Error):
# B
n = int(input())
sli = list(map(int, input().spllit()))
for s in sli:
    if s == 'Y':
        print('Four')
        exit()

print('Three')

Fixed submission:
# B
n = int(input())
sli = list(input().split())
for s in sli:
    if s == 'Y':
        print('Four')
        exit()

print('Three')
Buggy python submission (verdict: Runtime Error):
print(sum(list(map(int, list(input())))))

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

if (a*b) % 2 == 0:
	print('Even')
else:
	print('Odd')
Buggy python submission (verdict: Runtime Error):
N = int(input())

plist = [(0,0,0)]
for _ in range(N):
	plist.append(tuple(map(int, input().split())))

judge = True
for i in range(N):
	mae = plist[i]
	usi = plist[i+1]

	time_diff = usi[0] - mae[0]
	road = abs(usi[1] - mae[1]) + abs(usi[2] - mae[2])

	amari = time_diff % road

	if amari % 2 != 0:
		judge =False

print(judge)

Fixed submission:
N = int(input())

plist = [(0,0,0)]
for _ in range(N):
	plist.append(tuple(map(int, input().split())))

judge = 'Yes'
for i in range(N):
	mae = plist[i]
	usi = plist[i+1]

	time_diff = usi[0] - mae[0]
	road = abs(usi[1] - mae[1]) + abs(usi[2] - mae[2])

	if time_diff < road:
		judge = 'No'
	elif time_diff >= road:
		yozyo = time_diff - road
		if yozyo % 2 != 0:
			judge = 'No'

print(judge)

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

plist = [(0,0,0)]
for _ in range(N):
	plist.append(tuple(map(int, input().suplit())))

judge = True
for i in range(N):
	mae = plist[i]
	usi = plist[i+1]

	time_diff = usi[0] - mae[0]
	road = abs(usi[1] - mae[1]) + abs(usi[2] - mae[2])

	amari = time_diff % road

	if amari % 2 != 0:
		judge =False

print(judge)

Fixed submission:
N = int(input())

plist = [(0,0,0)]
for _ in range(N):
	plist.append(tuple(map(int, input().split())))

judge = 'Yes'
for i in range(N):
	mae = plist[i]
	usi = plist[i+1]

	time_diff = usi[0] - mae[0]
	road = abs(usi[1] - mae[1]) + abs(usi[2] - mae[2])

	if time_diff < road:
		judge = 'No'
	elif time_diff >= road:
		yozyo = time_diff - road
		if yozyo % 2 != 0:
			judge = 'No'

print(judge)
Buggy python submission (verdict: Runtime Error):
N = int(input())
mochis = []
for _ in range(N):
	mochis.append(int(input()))

mochis = sorted(mochis, reverse=True)
dan = 0
for i in range(N):
	dan += 1
	if mochis[i] == mochis[i+1]:
		break

print(dan)


Fixed submission:
N = int(input())
mochis = []
for _ in range(N):
	mochis.append(int(input()))

dan = len(list(set(mochis)))
print(dan)

Buggy python submission (verdict: Runtime Error):
N = int(input())
mochis = []
for _ in range(N):
	mochis.append(int(input())

mochis = sorted(mochis, reverse=True)
dan = 0
for i in range(N):
	dan += 1
	if mochis[i] == mochis[i+1]:
		break

print(dan)


Fixed submission:
N = int(input())
mochis = []
for _ in range(N):
	mochis.append(int(input()))

dan = len(list(set(mochis)))
print(dan)
Buggy python submission (verdict: Runtime Error):
# B
a, b = map(int, input().split())
s = input()
n = len(s)
nums = list(range(10))
point = 0
flag = 'Yes'

if n != a+b+1:
    flag = 'No'
    print(flag)
    exit()

while point<=n-1:
    if point == a:
        if s[point] != '-':
            flag = 'No'
    else:
        if int(s[point]) not in nums:
            flag = 'No'
    point += 1
print(flag)

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

if (s[a]=='-' and s.count('-')==1):
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
# B
a, b = map(int, input().split())
s = input()
n = len(s)
nums = list(range(10))
point = 0
flag = 'Yes'

while (0<=point<=n-1):
    if point == a:
        if s[point] != '-':
            flag = 'No'
    else:
        if int(s[point]) not in nums:
            flag = 'No'
    point += 1
print(flag)

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

if (s[a]=='-' and s.count('-')==1):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
cond = []
for _ in range(n-1):
    c = list(map(int, input().split()))
    cond.append(c)

for i in range(n):
    if i == n-1:
        print(0)
    else:
        ela = 0

        for j in range(i, n-1):
            if j == i:
                # noru
                ela += cond[j][1]
            elif j != i:
                # noru
                if ela <= cond[j][1]:
                    ela = cond[j][1]
                elif ela > cond[j][1]:
                    k = 0
                    while True:
                        k += 1
                        product = k*cond[j][2]   
                        if product >= ela:
                            break
                    ela = product                     
            # susumu
            ela += cond[j][0]
        print(ela)

Fixed submission:
# C
n = int(input())
cond = []
for _ in range(n-1):
    c = list(map(int, input().split()))
    cond.append(c)

for i in range(n):
    if i == n-1:
        print(0)
    else:
        ela = 0

        for j in range(i, n-1):
            if j == i:
                # noru
                ela += cond[j][1]
            elif j != i:
                # noru
                if ela <= cond[j][1]:
                    ela = cond[j][1]
                elif ela > cond[j][1]:
                    k = cond[j][2]
                    if ela%k == 0:
                        pass
                    else:
                        ela = ela + (k-(ela%k))               
            # susumu
            ela += cond[j][0]
        print(ela)
Buggy python submission (verdict: Runtime Error):
# D submit
from math import sqrt
def sieve(n):
    if n<2:
        return [False]*(n+1)
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(sqrt(n))+1):
        if is_prime[i]:
            for j in range(i*2, n+1, i):
                is_prime[j] = False
    return is_prime

n = int(1e5)
is_prime = sieve(n)

cnt = [0]*(n+1)
for i in range(1, N+1):
    cnt[i] += cnt[i-1]
    if is_prime[i] and is_prime[(i+1)//2]:
        cnt[i] += 1
q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(cnt[r] - cnt[l-1])

Fixed submission:
# D submit
from math import sqrt
def sieve(n):
    if n<2:
        return [False]*(n+1)
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(sqrt(n))+1):
        if is_prime[i]:
            for j in range(i*2, n+1, i):
                is_prime[j] = False
    return is_prime

n = int(1e5)
is_prime = sieve(n)

cnt = [0]*(n+1)
for i in range(1, n+1):
    cnt[i] += cnt[i-1]
    if is_prime[i] and is_prime[(i+1)//2]:
        cnt[i] += 1
q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(cnt[r] - cnt[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

def islike(num):
    num1 = num
    num2 = (num+1)//2
    if (is_prime(num1) and is_prime(num2)):
        return True
    else:
        return False

q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    total = 0
    for m in range(l, r+1):
        if islike(m):
            total += 1
    print(total)

Fixed submission:
# D submit
from math import sqrt
def sieve(n):
    if n<2:
        return [False]*(n+1)
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(sqrt(n))+1):
        if is_prime[i]:
            for j in range(i*2, n+1, i):
                is_prime[j] = False
    return is_prime

n = int(1e5)
is_prime = sieve(n)

cnt = [0]*(n+1)
for i in range(1, n+1):
    cnt[i] += cnt[i-1]
    if is_prime[i] and is_prime[(i+1)//2]:
        cnt[i] += 1
q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(cnt[r] - cnt[l-1])