Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

S = input()
N = len(S)
t = [1 for i in range(N)]
u = [1 for i in range(N)]
for p in range(2 * 10 ** 5):
  u[0] = t[1] * (S[1] == "L")
  for i in range(1, N - 1):
    u[i] = t[i-1] * (S[i-1] == "R") + t[i+1] * (S[i+1] == "L")
  u[N - 1] = t[N-2] * (S[N-2] == "R")
  t = u
  u = [1 for i in range(N)]                                       
print(*t)

### FIXED CODE ###

S = input()
N = len(S)
k = [0]
result = [0] * N

for i in range(N-1):
  if S[i] != S[i+1]:
    k.append(i+1)
l = [k[i+1] - k[i] for i in range(len(k) - 1)] + [N - k[-1]]

for i in range(1, len(k), 2):
  result[k[i]] += (l[i] + 1) // 2 + l[i-1] // 2
  result[k[i]-1] += l[i] // 2 + (l[i-1] + 1) // 2
print(*result)
### BUGGY CODE ###

# from pprint import pprint
# import math
import collections

# n = int(input())
n, m = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = [None] * m
c = [None] * m
for i in range(m):
    _b, _c = map(int, input().split(' '))
    b[i] = _b
    c[i] = _c

for j in range(m):
    l = [c[j]] * b[j]
    a.extend(l)

a2 = list(sorted(a, reverse=True))[:n]

# print(a2)
print(sum(a2))


### FIXED CODE ###

# from pprint import pprint
# import math
import collections

# n = int(input())
n, m = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = [None] * m
c = [None] * m
for i in range(m):
    _b, _c = map(int, input().split(' '))
    b[i] = _b
    c[i] = _c

# # リストに連結していって最後に大きい順に出力
# for j in range(m):
#     l = [c[j]] * b[j]
#     a.extend(l)


cnt = collections.Counter(a)

# カウンターのdictのみ更新
for j in range(m):
    cnt.update({c[j]: b[j]})

a_tup = cnt.items()

# print(a_tup)

# カウンターの結果を逆順にして合計n個になるまで取り出して加算
res = 0
num_cnt = 0
for _ in sorted(a_tup, reverse=True):
    res += _[0] * _[1]
    num_cnt += _[1]

    if num_cnt >= n:
        res -= _[0] * (num_cnt - n)
        break

print(res)
### BUGGY CODE ###

K = int(input())

if(K%2 == 0):
    print("-1")
    exit()

A = 7
ans = 1
while(A < K): #O(6)
    A = A*10 + 7
    ans += 1

while(True):
    #print(A)
    A = A % K #1
    if(ans > K):
        print("-1")
    if(A==0): #1
        print(ans)
        exit()
    A = A * 10 + 7 # 1
    ans += 1# 1


### FIXED CODE ###

K = int(input())

if(K%2 == 0):
    print("-1")
    exit()

A = 7
ans = 1
while(A < K): #O(6)
    A = A*10 + 7
    ans += 1

while(True):
    #print(A)
    A = A % K #1
    if(ans > K):
        print("-1")
        exit()
    if(A==0): #1
        print(ans)
        exit()
    A = A * 10 + 7 # 1
    ans += 1# 1
### BUGGY CODE ###

N = int(input())
As = list(map(int, input().split()))

for i in range(1, N+1):
    print(As.count(i))
    As = [a for a in As if a != i]

### FIXED CODE ###

# coding: utf-8
# Your code here!

N = int(input())
As = list(map(int, input().split()))
ans = [0 for _ in range(N)]
 
for a in As:
    ans[a-1] += 1

print(*ans, sep="\n")
### BUGGY CODE ###

import math
N, K = map(int, input().split())
h = list(map(int, input().split()))

S = [0] * N
S[0] = 0

for i in range(1, N):
    value = S[i - 1] + abs(h[i] - h[i - 1])
    for step in range(1, K + 1):
        # print("i, k:", i, k)
        if i - step < 0:
            break
        value = min(value, S[i - step] + abs(h[i] - h[i - step]))
        #print("value", value)
    S[i] = value
    # print(S)
# print(S)
print(S[N - 1])


### FIXED CODE ###

N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[0]*(N)
dp[1]=abs(h[0]-h[1])
for i in range(2,N):
    dp[i]=min(dp[j]+abs(h[j]-h[i]) for j in range(max(0,i-K),i))
print(dp[N-1])
### BUGGY CODE ###

import copy
from collections import defaultdict

n, k = map(int, input().split())
sushi = [list(map(int, input().split())) for _ in range(n)]
sushi.sort(key=lambda x: x[1])
t = defaultdict(int)
x = list(range(n - 1, n - k - 1, -1))
z = [0]
for i in range(n - k, n):
    t[sushi[i][0]] += 1
    z[0] += sushi[i][1]

y = []
yd = []
for i in range(n - k - 1, -1, -1):
    if sushi[i][0] not in t.keys() and sushi[i][0] not in yd:
        y.append(i)
        yd.append(sushi[i][0])
y = y[::-1]
k = 1

for k in range(1, len(y) + 1):
    for i in range(len(x) - 1, -1, -1):
        xi = x[i]
        if t[sushi[xi][0]] > 1:
            t[sushi[xi][0]] -= 1
            z.append(z[-1] - sushi[xi][1] + sushi[y[-k]][1])
            x.pop(i)
            break

p = len(t.keys())
for i in range(len(z)):
    z[i] += (p + i) ** 2
print(max(z))


### FIXED CODE ###

import heapq

n, k = map(int, input().split())
sushi = [list(map(int, input().split())) for _ in range(n)]
sushi.sort(key=lambda x: x[1])
t = {}
x = []
z = 0
for i in range(n - 1, n - k - 1, -1):
    ti, di = sushi[i]
    if ti in t.keys():
        heapq.heappush(x, di)
        t[ti] += 1
    else:
        t[ti] = 1
    z += di

p = len(t.keys())
ans = z + p ** 2
for i in range(n - k - 1, -1, -1):
    if len(x) == 0:
        break
    ti, di = sushi[i]
    if ti not in t.keys():
        t[ti] = 1
        z += di - heapq.heappop(x)
        p += 1
        ans = max(ans, z + p ** 2)

print(ans)
### BUGGY CODE ###

ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

x,y,z,K=rl()
A=rl()
B=rl()
C=rl()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
X=[]
for a,b,c in zip(A,B,C):
    X.append([a,0])
    X.append([b,1])
    X.append([c,2])
X.sort(reverse=True)

ca=0
cb=0
cc=0
xl = len(X)
if x*y*z>=3000:
    for i in range(len(X)):
        _,a = X[i]
        if a == 0:
            ca += 1
        elif a == 1:
            cb += 1
        else:
            cc += 1 
        if ca*cb*cc>=3000:
            xl=i
            break
else:
    ca=x
    cb=y
    cc=z

ans = []
import itertools
for a,b,c in itertools.product(A[:ca],B,C):
    ans.append(a+b+c)
if ca < x:
    for a,b,c in itertools.product(A[ca:],B[:cb],C):
        ans.append(a+b+c)
    if cb < y:
        for a,b,c in itertools.product(A[ca:],B[cb:],C[:cc]):
            ans.append(a+b+c)
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])

### FIXED CODE ###

ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

X,Y,Z,K=rl()
A=rl()
B=rl()
C=rl()
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
ans = []
for a in range(1,X+1):
    for b in range(1,Y+1):
        for c in range(1,Z+1):
            if a*b*c<=K:
                ans.append(A[a-1]+B[b-1]+C[c-1])
            else:
                break
ans.sort(reverse=True)
for i in range(K):
    print(ans[i])
### BUGGY CODE ###

n, m = map(int, input().split())
friend = [[0]*n for i in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    friend[a-1][b-1] = 1
    friend[b-1][a-1] = 1
s = 0
for i in range(n):
    s = max(s, sum(friend[i]))
print(s+1)

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    uf.union(a-1,b-1)
maxn = 0
for i in range(n):
    maxn = max(maxn, uf.size(i))
print(maxn)
### BUGGY CODE ###

import heapq

n, m = map(int, input().split())
al = map(int, input().split())
h = []

for a in al:
    heapq.heappush(h, a)

for i in range(m):
    b, c = map(int, input().split())
    if len(h) >= n and c <= heapq.nlargest(n, h)[-1]:
        continue

    if b > n:
        b = n
    for j in range(b):
        heapq.heappush(h, c)




ans = sum(heapq.nlargest(n,h))
print(ans)

### FIXED CODE ###

import heapq


n, m = map(int, input().split())
al = map(int, input().split())
h = []
ad = {}
for a in al:
    if a not in ad:
        ad[a] = 1
    else:
        ad[a] += 1
    

for i in range(m):
    b, c = map(int, input().split())
    
    if c not in ad:
        ad[c] = b
    else:
        ad[c] += b


keys = list( ad.keys() )
keys.sort(reverse=True)



for k in keys:
    for i in range(ad[k]):
        heapq.heappush(h, k)

        if len(h) >= n:
            break


ans = sum( heapq.nlargest(n, h) )
print(ans)
### BUGGY CODE ###

from math import sqrt, floor
from functools import reduce


def divisors(a):
    return {i for i in range(1, floor(sqrt(a)) + 1) if a % i == 0}\
        .union({a // i for i in range(1, floor(sqrt(a)) + 1) if a % i == 0})


def greatest_common_divisor(a, b):
    return max(divisors(a).intersection(divisors(b)))


def greatest_common_divisor_of(lst):
    return reduce(greatest_common_divisor, lst)


X = int(input().split()[1])
xi = list(map(int, input().split()))
x = [abs(x - X) for x in xi]
print(greatest_common_divisor_of(x))


### FIXED CODE ###

from functools import reduce
from fractions import gcd

X = int(input().split()[1])
x = [abs(int(x) - X) for x in input().split()]

print(reduce(gcd, x))
### BUGGY CODE ###

N,A,B=map(int,input().split())
x=[]
for i in range(1,N+A+B):
  for j in range(A):
    x.append("a")
  for k in range(B):
    x.append("b")
   
x=x[:N]
print(x.count("a"))

### FIXED CODE ###

N,A,B=map(int,input().split())
num=N//(A+B)
res=N-num*(A+B)
count=0
if res<=A:
  count=num*A+res
else:
  count=num*A+A
print(count)
### BUGGY CODE ###

def solve(A, ms, flags):
	for i,m in enumerate(ms):
		if m==0:
			flags[i]=True
	if len(A)==0:
		return flags
	else:
		use = solve(A[1:], list(map(lambda x:x-A[0], ms)), flags)
		no_use = solve(A[1:], ms, flags)
		return list(map(lambda x,y:x or y, use, no_use))

def main():
	n = int(input())
	A = input()
	A = list(map(int, A.split()))
	q = int(input())
	m = input()
	m = list(map(int, m.split()))
	flags = [False for i in range(q)]
	for flag in solve(A, m, flags):
		if flag:
			print('yes')
		else:
			print('no')

if __name__ == '__main__':
	main()

### FIXED CODE ###

def power_set(A, s):
	if len(A) == 0:
		return {s}
	else:
		return power_set(A[1:], s) | power_set(A[1:], s+A[0])

def main():
	n = int(input())
	A = input()
	#print(n)
	A = list(map(int, A.split()))
	q = int(input())
	m = input()
	ms = list(map(int, m.split()))
	powerset = power_set(A, 0)
	
	for m in ms:
		if m in powerset:
			print('yes')
		else:
			print('no')

if __name__ == '__main__':
	main()
### BUGGY CODE ###

N = int(input())
S = input()

ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        if S[i] == S[j]:
            continue
        elif set([S[i], S[j]]) == {"R", "G"}:
            if 2*j - i < N and S[2*j - i] == "B":
                ans += S[j+1:].count("B") - 1
            else:
                ans += S[j+1:].count("B")
        elif set([S[i], S[j]]) == {"B", "G"}:
            if 2*j - i < N and S[2*j - i] == "R":
                ans += S[j+1:].count("R") - 1
            else:
                ans += S[j+1:].count("R")
        else:
            if 2*j - i < N and S[2*j - i] == "G":
                ans += S[j+1:].count("G") - 1
            else:
                ans += S[j+1:].count("G")

print(ans)


### FIXED CODE ###

N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")

for i in range(N-2):
    for d in range(1, (N-i-1)//2+1):
        if {S[i], S[i+d], S[i+2*d]} == {"R", "G", "B"}:
            ans -= 1

print(ans)
### BUGGY CODE ###

n = int(input())
bra = []
ket = []
for _ in range(n):
  s = input()
  mini = 0
  now = 0
  l = len(s)
  for i in range(l):
    if s[i] == '(':
      now += 1
    else:
      now -= 1
      mini = min(mini,now)
  bra.append([-mini,now])
  s = s[::-1]
  mini = 0
  now = 0
  for i in range(l):
    if s[i] == ')':
      now += 1
    else:
      now -= 1
      mini = min(mini,now)
  ket.append([-mini,now])  
check = 0
for x in bra:
  #print(x)
  check += x[1]
if check != 0:
  print('No')
  exit()
bra.sort()
now = 0
here = -1
#print(bra)
import heapq
pool = []
for i in range(n):
  while here != n-1:
    if bra[here+1][0] <= now:
      here += 1
      heapq.heappush(pool,-bra[here][1])
    else:
      break
  #print(i,'#',pool)
  if not pool:
    print('No')
    exit()
  else:
    now -= heapq.heappop(pool)

ket.sort()
now = 0
here = -1
#print(bra)
pool = []
for i in range(n):
  while here != n-1:
    if ket[here+1][0] <= now:
      here += 1
      heapq.heappush(pool,-ket[here][1])
    else:
      break
  #print(i,'#',pool)
  if not pool:
    print('No')
    exit()
  else:
    now -= heapq.heappop(pool)
print('Yes')

### FIXED CODE ###

n = int(input())
bra = []
ket = []
c = []
for _ in range(n):
  s = input()
  mini = 0
  now = 0
  l = len(s)
  for i in range(l):
    if s[i] == '(':
      now += 1
    else:
      now -= 1
      mini = min(mini,now)
  if now >= 0:
    bra.append([-mini,now])
  c.append(now)
  s = s[::-1]
  mini = 0
  now = 0
  for i in range(l):
    if s[i] == ')':
      now += 1
    else:
      now -= 1
      mini = min(mini,now)
  if now >= 0:
    ket.append([-mini,now])  
check = 0
for x in c:
  #print(x)
  check += x
if check != 0:
  print('No')
  exit()
bra.sort()
now = 0
here = -1
n = len(bra)
#print(bra)
import heapq
pool = []
for i in range(n):
  while here != n-1:
    if bra[here+1][0] <= now:
      here += 1
      heapq.heappush(pool,-bra[here][1])
    else:
      break
  #print(i,'#',pool)
  if not pool:
    print('No')
    exit()
  else:
    now -= heapq.heappop(pool)

ket.sort()
now = 0
here = -1
n = len(ket)
#print(bra)
pool = []
for i in range(n):
  while here != n-1:
    if ket[here+1][0] <= now:
      here += 1
      heapq.heappush(pool,-ket[here][1])
    else:
      break
  #print(i,'#',pool)
  if not pool:
    print('No')
    exit()
  else:
    now -= heapq.heappop(pool)
print('Yes')
### BUGGY CODE ###

from collections import *
H,W = map(int,input().split())
ch,cw = map(int,input().split())
dh,dw = map(int,input().split())
S = 2*[(W+4)*"#"]+["##"+input()+"##" for h in range(H)]+2*[(W+4)*"#"]
ans = [(W+4)*[-1] for h in range(H+4)]
ans[ch+1][cw+1] = 0
move = [[-1,0],[1,0],[0,-1],[0,1]]
magic = [[-2,-2],[-2,-1],[-2,0],[-2,1],[-2,2],[-1,-2],[-1,-1],[-1,0],[-1,1],[-1,2],[0,-2],[0,-1],[0,0],[0,1],[0,2],[1,-2],[1,-1],[1,0],[1,1],[1,2],[2,-2],[2,-1],[2,0],[2,1],[2,2]]

for h in range(H+4):
  for w in range(W+4):
    if S[h][w]=="#":
      ans[h][w]=-2

P = deque([[ch+1,cw+1]])
Q = deque([])

while P:
  x,y = P.popleft()
  Q.append([x,y])
  for dx,dy in move:
    if ans[x+dx][y+dy]==-1:
      ans[x+dx][y+dy] = ans[x][y]
      P.append([x+dx,y+dy])
  
  if len(P)==0:
    while Q:
      x,y = Q.popleft()
      for dx,dy in magic:
        if ans[x+dx][y+dy]==-1:
          ans[x+dx][y+dy] = ans[x][y]+1
          P.append([x+dx,y+dy])

print(ans[dh+1][dw+1])

### FIXED CODE ###

from collections import *

def main():
    H,W = map(int, input().split())
    ch,cw = map(int, input().split())
    dh,dw = map(int, input().split())
    s = ["#"*(W+4)]
    s.append("#"*(W+4))
    for i in range(H):
        s.append("##"+input()+"##")
    s.append("#"*(W+4))
    s.append("#"*(W+4))
    
    ans = [[-1]*(W+4) for _ in range(H+4)]
    for i in range(H+4):
        for j in range(W+4):
            if s[i][j] == "#":
                ans[i][j] = -2
    ch += 1; cw += 1
    dh += 1; dw += 1
    ans[ch][cw] = 0
    
    move = [[-1,0],[1,0],[0,-1],[0,1]]
    magic = [
        [-2,-2],[-2,-1],[-2,0],[-2,1],[-2,2],\
        [-1,-2],[-1,-1],[-1,0],[-1,1],[-1,2],\
        [0,-2],[0,-1],[0,0],[0,1],[0,2],\
        [1,-2],[1,-1],[1,0],[1,1],[1,2],\
        [2,-2],[2,-1],[2,0],[2,1],[2,2]
        ]
    
    mylist = deque([[ch,cw]])
    mylist2 = deque([])
    while len(mylist) > 0:
        x,y = mylist.popleft()
        mylist2.append([x,y])
        for p,q in move:
            v1,v2 = x+p,y+q
            if ans[v1][v2] == -1:
                mylist.append([v1,v2])
                ans[v1][v2] = ans[x][y]
        if len(mylist) == 0:
            while len(mylist2) > 0:
                x2,y2 = mylist2.popleft()
                for v1,v2 in magic:
                    i,j = x2+v1,y2+v2
                    if ans[i][j] == -1:
                        ans[i][j] = ans[x2][y2]+1
                        mylist.append([i,j])
    print(ans[dh][dw])
 
if __name__ == "__main__":
    main()
### BUGGY CODE ###

import fractions
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2] != 1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,mod):
    x = extgcd(a,mod)[0]
    return (mod + x % mod)% mod
def comb(n,k,mod):
    c = 1
    for i in range(k):
        c = c*(n-i)%mod
        c = c*mod_inv(i+1,mod)%mod
    return c
n = int(input())
a = list(map(int,input().split()))
g = 1
mod = 10**9 + 7
for i in range(n):
    g = g*a[i]//fractions.gcd(g,a[i])
ans = 0
for i in range(n):
    ans += g//a[i]
    ans %= mod
print(ans)

### FIXED CODE ###

import fractions
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2] != 1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,mod):
    x = extgcd(a,mod)[0]
    return (mod + x % mod)% mod
def comb(n,k,mod):
    c = 1
    for i in range(k):
        c = c*(n-i)%mod
        c = c*mod_inv(i+1,mod)%mod
    return c
n = int(input())
a = list(map(int,input().split()))
g = a[0]
ans = 1
mod = 10**9 + 7
for i in range(1,n):
    p = fractions.gcd(g,a[i])
    g1 = (a[i]//p)*g
    ans *= (g1//g)
    ans %= mod
    ans += g1//a[i]
    ans %= mod
    g = g1
print(ans)
### BUGGY CODE ###

import fractions
import itertools
A,B=map(int,input().split())

C=[1]
for i in range(2,min(A,B)+1):
    if A % i == 0 and B % i == 0:
        C.append(i)
#print(C)

#for i in itertools.combinations(C, 2):
#    print(i)

NG=[]
ans=0

for i in itertools.combinations(C, 2):
    a,b=i
    if a in NG:
        continue
    if b in NG:
        continue

    z=fractions.gcd(a,b)
    #print(a,b)
    #print(z)
    
    if z != 1:
        NG.append(max(a,b))

print(len(C)-len(NG))

    



### FIXED CODE ###

import fractions
import collections
   
A,B = map(int,input().split())
gcd = fractions.gcd(A,B)

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

c = collections.Counter(prime_factorize(gcd))
print(len(list(c.keys()))+1)
### BUGGY CODE ###

N=input()
list=[]
a=[]
b=[]
c=[]
s=[]
t=0
for i in range(int(N)):
    list.append(input())
    for l in range(len(a)):
        if(a[l]==list[i]):
            b[l]+=1
            t=1
            break
    if t==0:
        a.append(list[i])
        b.append(1)
    else:
        t=0
m=max(b)
for i in range(len(a)):
    if b[i]==m:
        c.append(a[i])
s=sorted(c)
for i in range(len(s)):
    print(s[i])


### FIXED CODE ###

import collections
import sys
N=int(input())
S=[input() for i in range(N)]
c = collections.Counter(S).most_common()
c.sort()
c.sort(key=lambda c:c[1],reverse=True)
max_count=c[0][1]
for _ in c:
  if _[1]==max_count:
    print(_[0])
  else:
    sys.exit()
### BUGGY CODE ###

def trial_division(n):
    prime_factors = list()
    while n % 2 == 0:
        prime_factors.append(2)
        n //= 2
    p = 3
    while p * p <= n:
        if n % p == 0:
            prime_factors.append(p)
            n //= p
        else:
            p += 2
    if n != 1:
        prime_factors.append(n)
    return prime_factors

Q = int(input())
for _ in range(Q):
    l,r = map(int,input().split())
    ans = 0
    for i in range(l,r+1,2):
        if len(trial_division(i)) == 1 and len(trial_division((i+1)//2)) == 1:
            ans += 1
    print(ans)

### FIXED CODE ###

import sys

def input():
    return sys.stdin.readline().strip()

def main():

    Q = int(input())
    ma = 10 ** 5 + 1
    dp = [0] * ma
    dp[2] = 1

    for i in range(3,ma,2):
        if dp[i] == 0:
            dp[i] = 1
            if dp[(i + 1) // 2] == 1 or dp[(i + 1) // 2] == 2:
                dp[i] = 2
            for j in range(i * 2,ma,i):
                dp[j] = 3

    ruiseki = [0] * ma

    for i in range(1,ma):
        if dp[i] == 2:
            ruiseki[i] = ruiseki[i-1] + 1
        else:
            ruiseki[i] = ruiseki[i-1]

    for _ in range(Q):
        l,r = map(int,input().split())
        print(ruiseki[r] - ruiseki[l-1])

if __name__ == "__main__":
    main()
### BUGGY CODE ###

import itertools
k,s = map(int,input().split())
ans = 0
x = [i for i in range(k + 1)]
y = [i for i in range(k + 1)]
z = [i for i in range(k + 1)]
arr = list(itertools.product(x,y,z))
for i in arr:
    if sum(i) == s:
        ans += 1
print(ans)

### FIXED CODE ###

k,s = map(int,input().split())
ans = 0
for i in range(k + 1):
    for j in range(k + 1):
        if 0 <= s - i - j <= k:
            ans += 1
print(ans)
### BUGGY CODE ###

n = int(input())
b = list(map(int, input().split()))

a = [0 for k in range(n)]
a[0] = b[0]
a[n-1] = b[n-2]

for i in range(1, n-1):
  j=0
  while not j == min(b[i], b[i-1]):
    j += 1
  a[i]=j
  
ans = 0
for x in range(n):
  ans += a[x]

print(ans)

### FIXED CODE ###

n = int(input())
b = list(map(int, input().split()))

a = [0 for k in range(n)]
a[0] = b[0]
a[n-1] = b[n-2]

for i in range(1, n-1):
  a[i]=min(b[i], b[i-1])
  
ans = 0
for x in range(n):
  ans += a[x]

print(ans)
### BUGGY CODE ###

param_x, param_k, param_d = map(int, input().split())

param_x_tmp = param_x

if param_x > 0:
  int_times_nega_posi = -1
else:
  int_times_nega_posi =  1
  
if (param_x*int_times_nega_posi*-1) - (param_k*param_d) > 0:
  print((param_x*int_times_nega_posi*-1) - (param_k*param_d))
  
else:
  count = 0
  while param_x_tmp*param_x > 0:
    
    param_x_tmp = param_x_tmp + param_d*int_times_nega_posi
    
    count = count + 1
    
    if param_k - count == 0:
      print(abs(param_x_tmp))
  
  if count < param_k:
    int_move = param_k - count #move left
    int_move_devide_2_no_amari = int_move % 2
    print(abs(param_x_tmp + param_d*int_move_devide_2_no_amari*int_times_nega_posi*-1))

### FIXED CODE ###

param_x, param_k, param_d = map(int, input().split())

param_x_tmp = param_x

if param_x > 0:
  int_times_nega_posi = -1
else:
  int_times_nega_posi =  1
  
if (param_x*int_times_nega_posi*-1) - (param_k*param_d) > 0:
  print((param_x*int_times_nega_posi*-1) - (param_k*param_d))
  
else:
  int_time_before_cross_0 = int((param_x*int_times_nega_posi*-1) / param_d)
  # print(int_time_before_cross_0)
  
  param_x_tmp = param_x + int_time_before_cross_0*param_d*int_times_nega_posi
  # print(param_x_tmp)
  
  int_move = param_k - int_time_before_cross_0 #move left
  int_move_devide_2_no_amari = int_move % 2
  print(abs(param_x_tmp + param_d*int_move_devide_2_no_amari*int_times_nega_posi))
  
  #count = 0
  #while param_x_tmp*param_x > 0:
  #  
  #  param_x_tmp = param_x_tmp + param_d*int_times_nega_posi
  #  
  #  count = count + 1
  #  
  #  if param_k - count == 0:
  #    print(abs(param_x_tmp))
  #
  #if count < param_k:
  #  int_move = param_k - count #move left
  #  int_move_devide_2_no_amari = int_move % 2
  #  print(abs(param_x_tmp + param_d*int_move_devide_2_no_amari*int_times_nega_posi*-1))