Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# abc169_b.py
N = int(input())
A = list(map(int,input().split()))
ans =1
for i in A:
    ans *= i 
if ans >10**18:
    print(-1)
    exit()
print(ans)


Fixed submission:
# abc169_b.py
N = int(input())
A = list(map(int,input().split()))
ans =1
A.sort()
for i in A:
    if i == 0 :
        ans = 0
        break
    ans *= i 
    if ans >10**18:
        print(-1)
        exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, N = map(int,input().split())
ans = -100000000000
pre = 10**9
ans = 0
for i in range(N+1):
    t = (A*i) // B - A * (i//B)
    if pre < ans :
        break
    if ans < t:
        ans = t
    pre = t
print(ans)

Fixed submission:
import math
def f(x):
    return math.floor(A*x/B)

A, B, N = map(int, input().split())
print(f(min(B-1,N)))

Buggy python submission (verdict: Runtime Error):
# abc165_d.py
from math import floor
A, B,N = map(int,input().split())
ans = 0
for i in range(1,A):
    t = floor(A*i/B)-A*floor(i/B)
#    print(i, t,floor(A*i/B),A*floor(i/B))
    if ans<=t:
        ans = t
print(ans)# abc165_d.py
from math import floor
A, B,N = map(int,input().split())
ans = -100000000
for i in range(1,A):
    t = floor(A*i/B)-A*floor(i/B)
#    print(i, t,floor(A*i/B),A*floor(i/B))
    if ans<=t:
        ans = t
print(ans)

Fixed submission:
import math
def f(x):
    return math.floor(A*x/B)

A, B, N = map(int, input().split())
print(f(min(B-1,N)))
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)


K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += gcd(i,j,k)

print(ans)


Fixed submission:
#test.py
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)


K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            if i==1 or j==1 or k ==1:
                ans += 1
            else:
                ans += gcd(i,j,k)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)


K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            if i==1 or j==1 or k ==1:
                ans += 1
            else:
                ans += gcd(i,j,k)

print(ans)


Fixed submission:
#test.py
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)


K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            if i==1 or j==1 or k ==1:
                ans += 1
            else:
                ans += gcd(i,j,k)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#test.py
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)


K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
                ans += gcd(i,j,k)

print(ans)
#メモ化再帰で高速化できないか考える
# Kまでの数の組み合わせを考える





Fixed submission:
#test.py
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)


K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            if i==1 or j==1 or k ==1:
                ans += 1
            else:
                ans += gcd(i,j,k)

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
cnt= 0
for i in range(n):
    for j in range(i,n):
        if s[i] != s[j] and s[i] != s[2*j-i] and s[j] != s[2*j-i] and 2*j-i<n:
            cnt += 1
print(r*g*b-cnt)

Fixed submission:
# abc162_d.py
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
cnt= 0
for i in range(n):
    for j in range(i,n):
        if 2*j-i<n:
            if s[i] != s[j] and s[i] != s[2*j-i] and s[j] != s[2*j-i]:
                cnt += 1
print(r*g*b-cnt)

Buggy python submission (verdict: Time Limit Exceeded):
# e.py
N = int(input())
S = input()
ans = 0
for i in range(N):
    for j in range(i,N):
        if S[i]!=S[j]:
#            print(S[i],S[j])
            for k in range(j,N):
                if j-i != k-j:
                    if S[i]!=S[k] and S[k]!=S[j]:
                        ans += 1
print(ans)


Fixed submission:
# abc162_d.py
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
cnt= 0
for i in range(n):
    for j in range(i,n):
        if 2*j-i<n:
            if s[i] != s[j] and s[i] != s[2*j-i] and s[j] != s[2*j-i]:
                cnt += 1
print(r*g*b-cnt)

Buggy python submission (verdict: Time Limit Exceeded):
# e.py
N = int(input())
S = input()
ans = 0
for i in range(N):
    for j in range(i,N):
        for k in range(j,N):
            if j-i != k-j:
                if S[i]!=S[j] and S[i]!=S[k] and S[k]!=S[j]:
                    ans += 1
print(ans)


Fixed submission:
# abc162_d.py
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
cnt= 0
for i in range(n):
    for j in range(i,n):
        if 2*j-i<n:
            if s[i] != s[j] and s[i] != s[2*j-i] and s[j] != s[2*j-i]:
                cnt += 1
print(r*g*b-cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
N = int(input())
A = list(map(int,input().split()))

C = collections.Counter(A)
#print(C)
calc = {}
for i,cnt in C.items():
    calc[i] = cnt*(cnt-1)//2
#print("calc:",calc)
for i in range(N):
    ans = 0
    for j,k in calc.items():
#        print(j,k,A[i])
        if j != A[i]:
            ans += k
#    print("ans",ans)
#    print("A[i]",A[i],"calc[A[i]]",calc[A[i]])
    if calc[A[i]] != 0:
        ans += (C[A[i]]-1)*(C[A[i]]-2)//2
#        print((calc[A[i]]-2)*(calc[A[i]]-1)//2)
#        ans += (calc[A[i]]-2)*(calc[A[i]]-1)//2
    print(ans)


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

C = collections.Counter(A)
#print(C)
calc = {}
for i,cnt in C.items():
    calc[i] = cnt*(cnt-1)//2
#print("calc:",calc)
calc_sum = sum(calc.values())
for i in range(N):
    ans = calc_sum - calc[A[i]]
#    print("ans",ans)
#    print("A[i]",A[i],"calc[A[i]]",calc[A[i]])
    if calc[A[i]] != 0:
        ans += (C[A[i]]-1)*(C[A[i]]-2)//2
#        print((calc[A[i]]-2)*(calc[A[i]]-1)//2)
#        ans += (calc[A[i]]-2)*(calc[A[i]]-1)//2
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = int(input())
flg=False
for i in range(N):
	Q = input().split()
	if Q[0] == "1":
		if not flg:
			flg = True
		else:
			flg = False
	elif Q[0] == "2":
		if Q[1] == "1":
			if not flg:
				S = Q[2]+S
			else:
				S = S+Q[2]
		if Q[1] == "2":
			if flg:
				S = Q[2]+S
			else:
				S = S+Q[2]
if flg:
	S =S[::-1]
print(S)

Fixed submission:
S = input()
N = int(input())
rev_flg=False
head = []
tail = []
for i in range(N):
	Q = input().split()
	if Q[0] == "1":
		if not rev_flg:
			rev_flg = True
		else:
			rev_flg = False
	elif Q[0] == "2":
		if Q[1] == "1":
			if not rev_flg:
				head.append(Q[2])
			else:
				tail.append(Q[2])
		if Q[1] == "2":
			if not rev_flg:
				tail.append(Q[2])
			else:
				head.append(Q[2])
S = "".join(head[::-1])+S+"".join(tail)
#print(head,tail)
#print(S)
if rev_flg:
	S =S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = int(input())
for i in range(N):
    Q = input().split()
    if Q[0] == "1":
        S = S[::-1]
    elif Q[0] == "2":
        if Q[1] == "1":
            S = Q[2]+S
        if Q[1] == "2":
            S = S+Q[2]
print(S)

Fixed submission:
S = input()
N = int(input())
rev_flg=False
head = []
tail = []
for i in range(N):
	Q = input().split()
	if Q[0] == "1":
		if not rev_flg:
			rev_flg = True
		else:
			rev_flg = False
	elif Q[0] == "2":
		if Q[1] == "1":
			if not rev_flg:
				head.append(Q[2])
			else:
				tail.append(Q[2])
		if Q[1] == "2":
			if not rev_flg:
				tail.append(Q[2])
			else:
				head.append(Q[2])
S = "".join(head[::-1])+S+"".join(tail)
#print(head,tail)
#print(S)
if rev_flg:
	S =S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = int(input())
for i in range(N):
    Q = input().split()
    if Q[0] == "1":
        S = S[::-1]
    elif Q[0] == "2":
        if Q[1] == "1":
            S = Q[2]+S
        if Q[1] == "2":
            S = S+Q[2]
print(S)

Fixed submission:
S = input()
N = int(input())
rev_flg=False
head = []
tail = []
for i in range(N):
	Q = input().split()
	if Q[0] == "1":
		if not rev_flg:
			rev_flg = True
		else:
			rev_flg = False
	elif Q[0] == "2":
		if Q[1] == "1":
			if not rev_flg:
				head.append(Q[2])
			else:
				tail.append(Q[2])
		if Q[1] == "2":
			if not rev_flg:
				tail.append(Q[2])
			else:
				head.append(Q[2])
S = "".join(head[::-1])+S+"".join(tail)
#print(head,tail)
#print(S)
if rev_flg:
	S =S[::-1]
print(S)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
s = []
c = []
ans = -1
ans_flg = True
for i in range(M):
  si, ci = map(int,input().split())
  s.append(si)
  c.append(ci)
for i in range(1000):
    #print("i : ",i)
    ans_str = str(i)
    if i < 10**(N-1)-1 or i > 10**(N+1):
        continue
    for j in range(len(s)):
        #print("ans_str : ",ans_str,", ans_str[s[j]-1] : ",ans_str[s[j]-1],", s[j] : ",s[j],", c[j] : ",c[j])
        if ans_str[s[j]-1] != str(c[j]):
            #print("hoge",ans_flg)
            ans_flg = False
            break
        else:
            #print("fuga")
            ans_flg = True
    #print(i)
    if ans_flg:
        ans = i
        break
print(ans)


Fixed submission:
N,M = map(int,input().split())
s = []
c = []
ans = -1
ans_flg = True
for i in range(M):
  si, ci = map(int,input().split())
  s.append(si)
  c.append(ci)
for i in range(1000):
    #print("i : ",i)
    ans_str = str(i)
    if len(str(i)) != N:
        continue
    for j in range(len(s)):
        #print("ans_str : ",ans_str,", ans_str[s[j]-1] : ",ans_str[s[j]-1],", s[j] : ",s[j],", c[j] : ",c[j])
        if ans_str[s[j]-1] != str(c[j]):
            #print("hoge",ans_flg)
            ans_flg = False
            break
        else:
            #print("fuga")
            ans_flg = True
    #print(i)
    if ans_flg:
        ans = i
        break
print(ans)

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
s = []
c = []
flg = [0]*N
ok_flg = True
ans = [0]*N
answer = "-1"
for i in range(M):
  si, ci = map(int,input().split())
  s.append(si)
  c.append(ci)
#print("s:",s,",c:",c)
for i in range(len(s)):
#  print(ans)
#  print(10**s[i] , 10**(N))
  if 10**s[i] > 10**(N):
    ok_flg = False
    break
  if flg[s[i]-1]  == 0:
#    print("for :",s[i],c[i])
    ans[s[i]-1] = c[i]
    flg[s[i]-1] = 1
  else:
    if ans[s[i]-1] != c[i]:
      answer = -1
      ok_flg = False
      break
is_zero = 0
if ok_flg :
  answer = ""
  for i in ans:
    answer += str(i)
    is_zero += i
  if is_zero == 0:
    answer = "-1"
  if M = 0:
    answer = 0
print(int(answer))

Fixed submission:
N,M = map(int,input().split())
s = []
c = []
ans = -1
ans_flg = True
for i in range(M):
  si, ci = map(int,input().split())
  s.append(si)
  c.append(ci)
for i in range(1000):
    #print("i : ",i)
    ans_str = str(i)
    if len(str(i)) != N:
        continue
    for j in range(len(s)):
        #print("ans_str : ",ans_str,", ans_str[s[j]-1] : ",ans_str[s[j]-1],", s[j] : ",s[j],", c[j] : ",c[j])
        if ans_str[s[j]-1] != str(c[j]):
            #print("hoge",ans_flg)
            ans_flg = False
            break
        else:
            #print("fuga")
            ans_flg = True
    #print(i)
    if ans_flg:
        ans = i
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
al = "abcdefghijklmnopqrstuvwxyz"
i = input()
for a in ramge(al):
  if al[a] == i:
    print(al[a+1])

al = "abcdefghijklmnopqrstuvwxyz"
i = input()
for a in range(len(al)):
  if al[a] == i:
    print(al[a+1])



Fixed submission:
al = "abcdefghijklmnopqrstuvwxyz"
i = input()
for a in range(len(al)):
  if al[a] == i:
    print(al[a+1])
Buggy python submission (verdict: Time Limit Exceeded):
# sumitb2019_b_bacha.py
N = int(input())
for i in range(10000000):
    if int(i*1.08) == N:
        print(i)
        exit()
print(":(")




Fixed submission:
# sumitb2019_b.py
import math 
N = int(input())
for i in range(50000):
    if math.floor(i*1.08) == N:
        print(i)
        exit()
print(":(")

Buggy python submission (verdict: Runtime Error):
# sumitb2019_b.py
import math
N = int(input())
for i in range(N):
    if math.floor(i*1.08) == N:
#        print(i)
#        exit()
print(":(")

Fixed submission:
# sumitb2019_b.py
import math 
N = int(input())
for i in range(50000):
    if math.floor(i*1.08) == N:
        print(i)
        exit()
print(":(")
Buggy python submission (verdict: Runtime Error):
N = input()
print(N**2)


Fixed submission:
N = int(input())
print(N**2)

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

Fixed submission:
N = int(input())
print(N**2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = "No"
if N <=81:
	for i in range(1,9):
       if N%i == 0:
           ans = "Yes"
print(ans)

Fixed submission:
N = int(input())
ans = "No"
if N <=81:
  for i in range(1,10):
    for j in range(1,10):
      if i*j == N:
        ans = "Yes"
print(ans)

Buggy python submission (verdict: Runtime Error):
	N = int(input())
ans = "No"
for i in range(1,9):
    if N%i == 0:
        ans = "Yes"
print(ans)

Fixed submission:
N = int(input())
ans = "No"
if N <=81:
  for i in range(1,10):
    for j in range(1,10):
      if i*j == N:
        ans = "Yes"
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# abc143_d.py
N = int(input())
L = list(map(int,input().split()))
cnt =0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if L[i]<L[j]+L[k] and L[j]<L[i]+L[k] and L[k]<L[j]+L[i]:
                # print(i,j,k)
                cnt+=1
print(cnt)


Fixed submission:
# abc143_d.py
def can_make(i, j, k):
    if L[i] < L[j] + L[k] and L[j] < L[k] + L[i] and L[k] < L[j] + L[i]:
        return True
    return False


def find(i, j, L):
    left = j
    right = N
    mid = (right + left)//2
    flg = False
    while right - left > 1:
        mid = (right + left)//2
        # print("left,mid,right", left, mid, right)
        if can_make(i, j, mid):
            # print("can make")
            left = mid
            flg = True
        else:
            right = mid
    # print("j,mid", j, mid)
    # print(flg)
    if flg:
        return left-j
    else:
        return 0


N = int(input())
L = list(map(int, input().split()))
cnt = 0
L = sorted(L, reverse=True)
for i in range(N):
    for j in range(i+1, N):
        # print(L)
        # print("i,j", i, j, L[i], L[j])
        cnt += find(i, j, L)
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
# abc139_d.py
N = int(input())
A = [N-i for i in range(N)]
print(sum(A)-N)

Fixed submission:
N = int(input())
print(N*(N-1)//2)
Buggy python submission (verdict: Runtime Error):
# abc131_c.py
'''
M を C,D でそれぞれ割り切れるもの
N を CD の最小公倍数で割り切れるもの
とすると
(B - A + 1) - (M - N)
で求められるはず
'''
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

def lcm(a,b):
    return (a*b)//gcd(a,b)

A,B,C,D = map(int,input().split())
r = (B - A + 1)
M = math.ceil(r/C) + math.ceil(r/D)
N = math.ceil(r/lcm(C,D))
print(r-M+N)

Fixed submission:

import math
from  fractions import gcd

def lcm(a,b):
    return (a*b)//gcd(a,b)

A,B,C,D = map(int,input().split())
d_cnt = B//D-(A-1)//D
c_cnt = B//C-(A-1)//C
cd = lcm(C,D)
cd_cnt = B//cd-(A-1)//cd
print(B-A+1-(c_cnt+d_cnt-cd_cnt))

Buggy python submission (verdict: Runtime Error):

import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
import math

def lcm(a,b):
    return (a*b)//gcd(a,b)

A,B,C,D = map(int,input().split())
r = (B - A + 1)
M = math.ceil(r/C) + math.ceil(r/D)
N = math.ceil(r/lcm(C,D))
print(r-M+N)

Fixed submission:

import math
from  fractions import gcd

def lcm(a,b):
    return (a*b)//gcd(a,b)

A,B,C,D = map(int,input().split())
d_cnt = B//D-(A-1)//D
c_cnt = B//C-(A-1)//C
cd = lcm(C,D)
cd_cnt = B//cd-(A-1)//cd
print(B-A+1-(c_cnt+d_cnt-cd_cnt))
Buggy python submission (verdict: Runtime Error):
W, H, x, y = map(int,input().split())
duplicate = 1 if W/x==2 and H/y==2 else 0
x_min = min((W-x)*H, x*H)
y_min = min(W*(H-y), W*y)
area = max(x_min, y_min)
print(area, duplicate)


Fixed submission:
W,H,x,y = map(int,input().split())
scale = W*H/2
div = 0
if x==W/2 and y==H/2:
  div = 1
print(scale,div)
Buggy python submission (verdict: Runtime Error):
# abc120_b.py
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

A, B, K = map(int,input().split())
cnt = 0
_max = gcd(A,B)
while _max>=0:
    if A%_max==0 and B%_max==0:
        cnt += 1
        if cnt == K:
            print(_max)
            exit()
    _max -=1


Fixed submission:
# abc120_b.py
import fractions 
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

A, B, K = map(int,input().split())
cnt = 0
_max = gcd(A,B)
while _max>=0:
    if A%_max==0 and B%_max==0:
        cnt += 1
        if cnt == K:
            print(_max)
            exit()
    _max -=1
Buggy python submission (verdict: Time Limit Exceeded):
# dp_b.py
def chmin(h, k, i):
    if i == 0:
        return 0
    ans = 10**9
    for j in range(min(i, k)):
        _min = dp[i-j-1] + abs(h[i]-h[i-j-1])
        if ans > _min:
            ans = _min
    return ans


N, K = map(int, input().split())
H = list(map(int, input().split()))
dp = [0]*N
for i in range(N):
    dp[i] = chmin(H, K, i)
    # print(dp)
print(dp[N-1])


Fixed submission:
# dp_b.py
def chmin(h, k, i):
    if i == 0:
        return 0
    ans = 10**9
    for j in range(min(i, k)):
        _min = dp[i-j-1] + abs(h[i]-h[i-j-1])
        if ans > _min:
            ans = _min
    return ans


N, K = map(int, input().split())
H = list(map(int, input().split()))
dp = [0]*N
for i in range(N):
    dp[i] = chmin(H, K, i)
    # print(dp)
print(dp[N-1])
Buggy python submission (verdict: Runtime Error):
N ,K = map(int,inpuit())
if N%K == 0:
  print(0)
else:
  print(1)


Fixed submission:
N ,K = map(int,input().split())
if N%K == 0:
  print(0)
else:
  print(1)

Buggy python submission (verdict: Runtime Error):
N ,K = map(int,inpuit())
print(N%K)

Fixed submission:
N ,K = map(int,input().split())
if N%K == 0:
  print(0)
else:
  print(1)
Buggy python submission (verdict: Time Limit Exceeded):
# abc093_b.py
A, B,K = map(int,input().split())
for i,v in enumerate(range(A,B+1)):
    if i<=K-1 or B+1-A-K<=i:
        print(v)


Fixed submission:
# abc093_b.py
A, B,K = map(int,input().split())
ans = []
for i in range(K):
#    print(i)
    ans.append(i+A)
    if i >(B-A-1):
        break
for i in range(K):
#    print(A-i)
#    print(i)
    ans.append(B-i)
    if i >(B-A-1):
        break
ans = list(set(ans))
ans.sort()
for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
# abc093_b.py
A, B,K = map(int,input().split())
for i,v in enumerate(range(A,B+1)):
    if i<=K-1 or B+1-A-K<=i:
        print(v)


Fixed submission:
# abc093_b.py
A, B,K = map(int,input().split())
ans = []
for i in range(K):
#    print(i)
    ans.append(i+A)
    if i >(B-A-1):
        break
for i in range(K):
#    print(A-i)
#    print(i)
    ans.append(B-i)
    if i >(B-A-1):
        break
ans = list(set(ans))
ans.sort()
for i in ans:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
# abc084_d.py
'''
通常の素数判定（√N まで割り続ける方法）ではTLEするので
エラトステネスの篩をリストで用意しておく。
'''
def is_prime(n):
    if n == 1:
        return False
    if n == 2:
        return True
    if n%2 == 0:
        return False
    for i in range(2,int(n**0.5)+1):
        if n%i == 0:
            return False
    return True

def is_like_num(n):
    return is_prime(n) and is_prime((n+1)//2)

erast_list = [is_like_num(i) for i in range(100001)]
# print(erast_list[:6].count(True))
# print(erast_list[:6])
Q = int(input())
for i in range(Q):
    L,R = map(int,input().split())
    print(erast_list[:R+1].count(True)-erast_list[:L].count(True))

Fixed submission:
def is_prime(n):
    if n == 1:
        return False
    if n == 2:
        return True
    if n%2 == 0:
        return False
    for i in range(2,int(n**0.5)+1):
        if n%i == 0:
            return False
    return True

def is_like_num(n):
    return is_prime(n) and is_prime((n+1)//2)

erast_list =[0]*100001
cnt = 0
for i in range(100001):
    if is_like_num(i):
        cnt+=1
    erast_list[i] = cnt
# print(erast_list[:5])
Q = int(input())
for i in range(Q):
    L,R = map(int,input().split())
#    print(erast_list[R+1],erast_list[L-1])
    print(erast_list[R+1]-erast_list[L-1])

Buggy python submission (verdict: Time Limit Exceeded):

def is_prime(n):
    if n == 1:
        return False
    if n == 2:
        return True
    if n%2 == 0:
        return False
    for i in range(2,int(n**0.5)+1):
        if n%i == 0:
            return False
    return True

Q = int(input())
for i in range(Q):
    cnt = 0
    l,r = map(int,input().split())
    for j in range(l,r+1):
        if j == 2 :
            continue
        if is_prime(j) :
            if is_prime((j+1)/2):
#                print(j,(j+1)/2,"is like number.")
                cnt += 1
    print(cnt)

Fixed submission:
def is_prime(n):
    if n == 1:
        return False
    if n == 2:
        return True
    if n%2 == 0:
        return False
    for i in range(2,int(n**0.5)+1):
        if n%i == 0:
            return False
    return True

def is_like_num(n):
    return is_prime(n) and is_prime((n+1)//2)

erast_list =[0]*100001
cnt = 0
for i in range(100001):
    if is_like_num(i):
        cnt+=1
    erast_list[i] = cnt
# print(erast_list[:5])
Q = int(input())
for i in range(Q):
    L,R = map(int,input().split())
#    print(erast_list[R+1],erast_list[L-1])
    print(erast_list[R+1]-erast_list[L-1])
Buggy python submission (verdict: Runtime Error):
X,Y = map(int,unput().split())
ans = 0
while Y<=X:
  ans += 1
  X*=2
print(ans)

Fixed submission:
X,Y = map(int,input().split())
ans = 0
while Y>=X:
  ans += 1
  X*=2
print(ans)
Buggy python submission (verdict: Runtime Error):
def round_up_mean(a,b):
  ans = -(-(a+b)//2)
  print(ans)


a,b = int(input().split(" "))
round_up_mean(a, b)

Fixed submission:
#import math
def round_up_mean(a,b):
#  ans = math.ceil((a+b)/2)
#  print(ans)
  ans = -(-(a+b)//2)
  print(ans)

a, b = map(int, input().split(" "))
round_up_mean(a, b)

Buggy python submission (verdict: Runtime Error):
def round_up_mean(a,b):
  ans = -(-(a+b)//2)
  print(ans)


a,b = int(input().split(""))
round_up_mean(a, b)

Fixed submission:
#import math
def round_up_mean(a,b):
#  ans = math.ceil((a+b)/2)
#  print(ans)
  ans = -(-(a+b)//2)
  print(ans)

a, b = map(int, input().split(" "))
round_up_mean(a, b)

Buggy python submission (verdict: Runtime Error):
#import math
def round_up_mean(a,b):
#  ans = math.ceil((a+b)/2)
#  print(ans)
  ans = -(-(a+b)//2)
  print(ans)


a = int(input())
b = int(input())
round_up_mean(a, b)

Fixed submission:
#import math
def round_up_mean(a,b):
#  ans = math.ceil((a+b)/2)
#  print(ans)
  ans = -(-(a+b)//2)
  print(ans)

a, b = map(int, input().split(" "))
round_up_mean(a, b)