CodeEff/ECCO huggingface dataset:
# Original solution
#!/usr/bin/env python3
import sys
import functools
INF = float("inf")


def solve(p: int, a: "List[int]"):
    N = p
    MOD = p

    fac = [0]*N
    finv = [0]*N
    inv = [0]*N

    def cmb_init():
        fac[0] = 1
        fac[1] = 1
        finv[0] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2, N):
            fac[i] = fac[i-1]*i % MOD
            inv[i] = -inv[MOD % i]*(MOD//i) % MOD
            finv[i] = finv[i-1]*inv[i] % MOD

    def cmb(n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return fac[n] * (finv[k]*finv[n-k] % MOD) % MOD

    cmb_init()

    b = [0]*p
    for ai, av in enumerate(a):
        if av == 1:
            for i in range(p):
                b[i] += -cmb(p-1, i) * pow(-ai, p-i-1)
                b[i] %= p
            b[0] += 1
            b[0] %= p
    print(*b, sep=" ")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    p = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(p-1-0+1)]  # type: "List[int]"
    solve(p, a)


if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys
import functools
INF = float("inf")


def solve(p: int, a: "List[int]"):
    N = p+1
    MOD = p

    inv = [0]*N
    inv[1] = 1
    for i in range(2, N):
        inv[i] = -inv[MOD % i]*(MOD//i) % MOD

    b = [0]*p
    for ai, av in enumerate(a):
        if av == 0:
            continue

        c = 1
        d = 1
        for i in range(p-1, -1, -1):
            b[i] += - c * d
            b[i] %= p
            c = c * i * inv[p-i] % p
            d = -d*ai % p
        b[0] += 1
        b[0] %= p
    print(*b, sep=" ")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    p = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(p-1-0+1)]  # type: "List[int]"
    solve(p, a)


if __name__ == '__main__':
    main()
# Original solution
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return list(map(int,input().split()))
def lmp(): return list(map(int,input().split()))

l,r,d=mp()
ans=0
for i in range(l,r+1):
    if i%d==0:
        ans+=1
print(ans)

# Optimized solution
a,b,c=list(map(int,input().split()))
print((b//c-(a-1)//c))
# Original solution
l, r, d = list(map(int, input().split()))

print((r // d - -(-l // d) + 1))


# Optimized solution

L, R, d = list(map(int, input().split()))

print((R // d - (L - 1) // d))
# Original solution
import sys
read = sys.stdin.read
from itertools import accumulate
def main():
    l, r, d = list(map(int, input().split()))
    res = 0
    for i1 in range(l, r + 1):
        res += i1 % d == 0

    print(res)


if __name__ == '__main__':
    main()

# Optimized solution
def main():
    l, r, d = list(map(int, input().split()))
    res = r // d - (l-1) // d
    print(res)

if __name__ == '__main__':
    main()
# Original solution
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda: int(eval(input()))
mi = lambda: list(map(int, input().split()))
li = lambda: list(map(int, input().split()))

yes = "Yes"
no = "No"


def main():
    l, r, d = mi()
    cnt = 0
    tmp = d
    while tmp <= r:
        if tmp <= r and tmp >= l:
            cnt += 1
        tmp += d
    print(cnt)


main()


# Optimized solution
l, r, d = list(map(int, input().split()))

cnt = 0
tmp = d
while tmp <= r:
    if tmp <= r and tmp >= l:
        cnt += 1
    tmp += d
print(cnt)
# Original solution
l, r, d = list(map(int, input().split()))

cnt = 0

for i in range(l, r+1):
    # print(i)
    if i % d == 0:
        cnt += 1

print(cnt)


# Optimized solution
l, r, d = list(map(int, input().split()))
cnt = 0
for i in range(l, r+1):
    if i % d == 0:
        cnt += 1
print(cnt)
# Original solution
#!/usr/bin/env python3
l, r, d = list(map(int, input().split()))
print((r//d - (l-1)//d))


# Optimized solution
#!/usr/bin/env pypy
l, r, d = list(map(int, input().split()))
print((r//d - (l-1)//d))
# Original solution
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

l,r,d = LI()
ans = 0
for i in range(l, r+1):
    if i % d == 0:
        ans += 1
print(ans)

# Optimized solution
#!/usr/bin/env python3

l, r, d = list(map(int, input().split()))
n = (l-1) // d + 1
m = r // d
print((m-n+1))
# Original solution
L,R,d = list(map(int,input().split()))
print((len([i for i in range(L,R+1) if i % d == 0])))

# Optimized solution
L,R,d=list(map(int,input().split()));print((R//d-(L-1)//d))
# Original solution
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(L, R, D):
    ans = 0
    for i in range(L, R+1):
        if i % D == 0:
            ans += 1
    return ans


def main():
    L, R, D = read_int_n()
    print(slv(L, R, D))


if __name__ == '__main__':
    main()


# Optimized solution
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(L, R, D):
    return R // D - (L-1) // D


def main():
    L, R, D = read_int_n()
    print(slv(L, R, D))


if __name__ == '__main__':
    main()
# Original solution
L, R, d = list(map(int, input().split()))

result = 0
for i in range(L, R + 1):
    if i % d == 0:
        result += 1
print(result)


# Optimized solution
L, R, d = list(map(int, input().split()))

print((R // d - (L - 1) // d))
# Original solution
import sys

input = sys.stdin.readline

def main():
    ans = 0
    l,r,d = list(map(int, input().split()))
    ans = (r//d) - (l//d)
    if l%d == 0:
        ans += 1
    print(ans)

if __name__ == '__main__':
    main()

# Optimized solution
l, r, d = list(map(int, input().split()))
print((r//d-(l-1)//d))
# Original solution
# -*- coding: utf-8 -*-
# 標準入力を取得
L, R, d = list(map(int, input().split()))

# 求解処理
ans = R // d - (L - 1) // d

# 結果出力
print(ans)


# Optimized solution
# -*- coding: utf-8 -*-

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    L, R, d = list(map(int, input().split()))

    return L, R, d


def main(L: int, R: int, d: int) -> None:
    """
    メイン処理.

    Args:\n
        L (int): 整数（1 <= L <= R <= 100）
        R (int): 整数（1 <= L <= R <= 100）
        d (int): 整数（1 <= d <= 100）
    """
    # 求解処理
    ans = R // d - (L - 1) // d

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    L, R, d = get_input()

    # メイン処理
    main(L, R, d)
# Original solution
l,r,d=list(map(int,input().split()))
cnt=0
for i in range(l,r+1):
  for j in range(1,101):
    if d*j==i:
      cnt+=1
      break
print(cnt)
    

# Optimized solution
l, r, d = list(map(int, input().split()))

ans = r // d - (l - 1) // d

print(ans)
# Original solution
l,r,d = list(map(int, input().split()))
ans = 0
while l <= r:
  if l%d == 0:
    ans += 1
  l += 1

print(ans)

# Optimized solution
l,r,d = list(map(int, input().split()))
ans = r//d - (l-1)//d
print(ans)
# Original solution
import sys
input = sys.stdin.readline
l,r,d=list(map(int,input().split()))
ans = 0
for i in range(l,r+1):
    if i%d==0:
        ans+=1
print(ans)


# Optimized solution
import sys
input = sys.stdin.readline

l,r,d=list(map(int,input().split()))
v1 = l//d
if l%d==0:
    v1-=1
v2 = r//d
print((v2-v1))
# Original solution
def main():
    left, right, div = [int(x) for x in input().split()]
    ans = sum(x % div == 0 for x in range(left, right + 1))
    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    left, right, div = [int(x) for x in input().split()]
    ans = right // div - (left - 1) // div
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
l, r, d = list(map(int, input().split()))
print((r//d - l//d + (l%d==0)))


# Optimized solution
l, r, d = list(map(int, input().split()))
print((r//d - (l-1)//d))
# Original solution
L,R,d=list(map(int, input().split()))
cnt=0
 
for i in range(L, R+1):
  if i%d == 0: cnt+=1
  
print(cnt)

# Optimized solution
L,R,d=list(map(int, input().split()))
print((R//d-(L-1)//d))
# Original solution
L, R, d = list(map(int, input().split()))

count = 0

for i in range(101):
  if d * i >= L and d * i <= R:
    count += 1
  if d * i > R:
    break
    
print(count)

# Optimized solution
l, r, d = list(map(int, input().split()))
print((r//d - (l-1)//d))
# Original solution
L,R,d = list(map(int,input().split()))
k = L//d
n = R//d
if L%d==0:
    print((n-k+1))
else:
    print((n-k))

# Optimized solution
L,R,d = list(map(int,input().split()))
print((R//d-(L-1)//d))
# Original solution
L,R,d=list(map(int,input().split()))
ans=0

for i in range(L,R+1):
    if i%d==0:
        ans+=1
print(ans)

# Optimized solution
L,R,d=list(map(int,input().split()))
ans=0

for i in range(R-L+1):
    if (L+i)%d==0:
        ans+=1
print(ans)
# Original solution
l, r, d = list(map(int, input().split()))
print((r//d - (l-1)//d))

# Optimized solution
L, R, d = list(map(int, input().split()))
diff = R - L + 1
ans = 0
l = [None for _ in range(diff)]
for i in range(diff):
   l[i] = L + i
   if l[i] % d == 0:
      ans += 1
print(ans)
# Original solution
l, r, d = list(map(int, input().split()))

print((r//d - (l-1)//d))

# Optimized solution
#!/usr/bin/env python3
l, r, d = list(map(int, input().split()))
 
print((r//d - (l-1)//d))
# Original solution
l,r,d = list(map(int,input().split()))
     
print(( r//d -(l-1)//d ))

# Optimized solution
A = list(map(int, input().split()))
C = 0
for i in range(A[0], A[1]+1):
    if i % A[2] == 0:
        C += 1
 
print(C)
# Original solution
def main():
    L, R, d = list(map(int, input().split(' ')))
    total = 0
    for i in range(L, R + 1):
        if i % d == 0:
            total += 1
    print(total)
main()

# Optimized solution
def main():
    L, R, d = list(map(int, input().split(' ')))
    X = 0
    if L % d == 0:
        X = int(L / d) - 1
    else:
        X = int(L / d)
    print((int(R / d) - X))
main()
# Original solution
L,R,d=list(map(int,input().split()))

ans=0
for i in range(L,R+1):
    if i%d==0:
        ans+=1
print(ans)



# Optimized solution
L,R,d=list(map(int,input().split()))

ans=R//d-(L-1)//d
print(ans)
# Original solution
import sys

s = [x for x in sys.stdin.readline().rstrip()]

black = float("inf")
ans = 0

for i in range(len(s)):
    if s[i] == "B" and black > i:
        black = i
    elif s[i] == "W" and black != float("inf"):
        ans += i - black
        black += 1

print(ans)

# Optimized solution
import sys


def main():
    s = sys.stdin.readline().rstrip()

    black = 0
    ans = 0

    for i in s:
        if i == "B":
            black = black + 1
        else:
            ans = ans + black

    print(ans)

    return


if __name__ == "__main__":
    main()
# Original solution
#AGC029-A Irreversible operation
"""
問題：
一直線上にオセロがある
一回の操作で[黒白]を裏返す時[白黒]、最大何回の操作が行えるか
解法：
まずいちばん最初のBが出てくるところまでは無視できる
そこから、Bの数*Wの数が答え
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
s = readline().rstrip().decode('utf-8')
flag = 0
black = 0
white = 0
ans = 0
for i in s:
    if flag:
        if i == "B":
            black += 1
        else:
            ans += black
    else:
        if i == "B":
            flag = 1
            black += 1
print(ans)

# Optimized solution
#AGC029-A Irreversible operation
"""
問題：
一直線上にオセロがある
一回の操作で[黒白]を裏返す時[白黒]、最大何回の操作が行えるか
解法：
まずいちばん最初のBが出てくるところまでは無視できる
そこから、Wが出てくる度にそこまでに出現したBの数を足した合計が答え
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
s = readline().rstrip().decode('utf-8')
flag = 0
black = 0
white = 0
ans = 0
for i in s:
    if flag:
        if i == "B":
            black += 1
        else:
            ans += black
    else:
        if i == "B":
            flag = 1
            black += 1
print(ans)
# Original solution
from sys import stdin
N=(stdin.readline().rstrip())
def str_del(str,index):
    str = str[:index]+str[index+1:]
    return str
ans=0
for i in range(100000000000):
    index=N.find("W")
    if index==-1:
        break
    ans=ans+index
    N=str_del(N,index)
print(ans)

# Optimized solution
from sys import stdin
N=(stdin.readline().rstrip())
N=list(N)
cnt=0
ans=0
for i in N:
    if i=="B":
        cnt+=1
    else:
        ans+=cnt
print(ans)
# Original solution
S = input().strip()
Sb = [c == "B" for c in S]

def reverse(Sb,i):
    _list = Sb.copy()
    _list[i] = not _list[i]
    return _list

def operate_onestep(Sb):
    _list = Sb.copy()
    cnt = 0
    flg = True
    while flg:
        flg = False
        for i in range(len(_list)-1):
            if _list[i] and not _list[i+1]:
                cnt += 1
                _list = reverse(_list,i)
                _list = reverse(_list,i+1)
                flg = True
    return cnt

print((operate_onestep(Sb)))

# Optimized solution
S = input().strip()

w_total = 0
num_op = 0
for i,c in enumerate(S):
    if c == "W":
        w_total += 1
        num_op += i + 1 - w_total
        
print(num_op)
# Original solution
S = list(input().rstrip())

count = 0
flag = True
while flag:
    for i in range(len(S)-1):
        if S[i] == 'B' and S[i+1] == 'W':
            S[i], S[i+1] = S[i+1], S[i]
            count += 1
            break
        
        if i == len(S)-2:
            flag = False

print(count)

# Optimized solution
S = list(input().rstrip())

ans = 0
countw = 0
for i, c in enumerate(S):
    if c == 'W':
        ans += i - countw
        countw += 1

print(ans)
# Original solution
import sys

def bubble_sort(arr):
    counter = 0
    change = True
    for i in range(len(arr)):
        for j in range(len(arr) - 1, i, -1):
            if arr[j] < arr[j - 1]:
                arr[j], arr[j - 1] = arr[j - 1], arr[j]
                counter += 1
        if change == 0: break
    return arr, counter


def solve():
    input = sys.stdin.readline
    S = list(input().replace("B", "2").replace("W", "1"))[:-1]
    S, counter = bubble_sort(S)

    print(counter)


solve()


# Optimized solution
import sys


def solve():
    input = sys.stdin.readline
    S = list(input().replace("B", "2").replace("W", "1"))[:-1]
    N = len(S)
    ans = N * (N - 1) // 2
    data = [0] * (N + 1)

    def add(k, v):
        while k <= N:
            data[k] += v
            k += k & -k

    def get(k):
        s = 0
        while k:
            s += data[k]
            k -= k & -k
        return s

    for a in map({a: i + 1 for i, a in enumerate(sorted(S))}.__getitem__, S):
        ans -= get(a)
        add(a, 1)

    print(ans)


solve()
# Original solution
import sys
def S(): return sys.stdin.readline().rstrip()

if __name__=='__main__':
    sl = list(S())
    flag = True
    c = 0
    while flag:
        flag = False
        for i in range(0,len(sl)-1):
            if sl[i]=='B' and sl[i+1]=='W':
                sl[i],sl[i+1] = 'W','B'
                c += 1
                flag = True

    print(c)
    exit()

# Optimized solution
import sys
def S(): return sys.stdin.readline().rstrip()

if __name__=='__main__':
    sl = list(S())
    ans = 0
    c = 0
    for i,item in enumerate(sl):
        if item=='W':
            ans += c
        else:
            c += 1

    print(ans)
    exit()
# Original solution
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

s = rs()
counter = collections.Counter(s)
n = len(s)
res = 0
for i, c in enumerate(s):
    if c == 'W':
        counter['W'] -= 1
    else:
        res += counter['W']
print(res)

# Optimized solution
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(eval(input()))
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

s = rs()
counter = collections.Counter(s)
res = 0
for i, c in enumerate(s):
    if c == 'W':
        counter['W'] -= 1
    else:
        res += counter['W']
print(res)
# Original solution
from sys import stdin

def main():
    A=stdin.readline().replace('B', '0').replace('W', '1')
    #A=list(map(int,bw))
    #A = list(map(int,stdin.readline().replace('B', '0').replace('W', '1')))

    wc = A.count('1')
    indices = [i for i, x in enumerate(A) if x == '1']
    if wc > 0:
      print((sum(indices) - 1*wc*(wc-1) //2 ))
    else:
      print((sum(indices)))

input = lambda: stdin.readline()
main()


# Optimized solution
from sys import stdin

def main():
    A=stdin.readline()
    #A = list(map(int,stdin.readline().replace('B', '0').replace('W', '1')))

    wc = A.count('W')
    indices = [i for i, x in enumerate(A) if x == 'W']
    if wc > 0:
      print((sum(indices) - 1*wc*(wc-1) //2 ))
    else:
      print((sum(indices)))

input = lambda: stdin.readline()
main()
# Original solution
#!/usr/bin/env python3

"""
https://atcoder.jp/contests/agc029/tasks/agc029_a
"""

import sys
import re


s = sys.stdin.readline().rstrip()
s2 = ''
cnt = 0

while True:
    s = re.sub('^W+','',s)
    s = re.sub('B+$','',s)
    s2 = s.replace('BW', 'WB', 1)
    if s2 == s:
        break
    cnt += 1
    s = s2


print(cnt)

# Optimized solution
#!/usr/bin/env python3

"""
https://atcoder.jp/contests/agc029/tasks/agc029_a
"""

import sys
import re


s = sys.stdin.readline().rstrip()
e = 0
n = 0

for chr in s:
    if chr == 'W':
        e += n

    if chr == 'B':
        n += 1

print(e)
# Original solution
from sys import stdin

s = stdin.readline().rstrip()
li = []

for i in range(len(s)):
    if s[i] == "B":
        li.append(0)
    else:
        li.append(1)
count = 0

while True:
    flag = 0
    for i in range(len(li)-1):
        if li[i] == 0 and li[i+1] == 1:
            li[i],li[i+1] = 1,0
            flag = 1
            count += 1
    if flag == 0:
        print(count)
        exit()

# Optimized solution
from sys import stdin

s = stdin.readline().rstrip()

now = 0
count = 0

for i in range(len(s)):
    if s[i] == "W":
        count += (i-now)
        now += 1

print(count)
# Original solution
# https://atcoder.jp/contests/arc071/submissions/6325840

from itertools import accumulate

S = tuple(map(lambda x: 1 if x == 'A' else 2, input()))
T = tuple(map(lambda x: 1 if x == 'A' else 2, input()))
# A=1,B=2


acc_s = (0,) + tuple(accumulate(S))
acc_t = (0,) + tuple(accumulate(T))

ans = []
Q = int(input())
for _ in range(Q):
    sl, sr, tl, tr = map(int, input().split())
    diff = (acc_t[tr] - acc_t[tl - 1]) - (acc_s[sr] - acc_s[sl - 1])
    # 添え字-1は変数再代入しない方が20ms速い
    ans.append('YES' if diff % 3 == 0 else 'NO')

print(*ans, sep='\n')
# 逐次printだと1000ms
# 一括だと500ms


# Optimized solution
# https://atcoder.jp/contests/arc071/submissions/6325840

from itertools import accumulate

convert = {'A': 1, 'B': 2}
S = tuple(convert[x] for x in input())
T = tuple(convert[x] for x in input())
# maspyさんのやり方

acc_s = (0,) + tuple(accumulate(S))
acc_t = (0,) + tuple(accumulate(T))

ans = []
Q = int(input())
for _ in range(Q):
    sl, sr, tl, tr = map(int, input().split())
    diff = (acc_t[tr] - acc_t[tl - 1]) - (acc_s[sr] - acc_s[sl - 1])
    # 添え字-1は変数再代入しない方が20ms速い
    ans.append('YES' if diff % 3 == 0 else 'NO')

print(*ans, sep='\n')
# 逐次printだと1000ms
# 一括だと500ms
# Original solution
S = input()
T = input()
Q = int(input())
qs = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(Q)]

smem = [0]
for c in S:
    if c == 'A':
        smem.append(smem[-1] + 1)
    else:
        smem.append(smem[-1] - 1)

tmem = [0]
for c in T:
    if c == 'A':
        tmem.append(tmem[-1] + 1)
    else:
        tmem.append(tmem[-1] - 1)

anss = []
for s1,s2,t1,t2 in qs:
    a = smem[s2+1] - smem[s1]
    b = tmem[t2+1] - tmem[t1]
    if a%3 == b%3:
        anss.append('YES')
    else:
        anss.append('NO')
print(*anss, sep='\n')


# Optimized solution
S = input()
T = input()
Q = int(input())
qs = [tuple(map(int,input().split())) for i in range(Q)]

sas = [0]
sbs = [0]
for c in S:
    a = int(c=='A')
    sas.append(sas[-1] + a)
    sbs.append(sbs[-1] + (a^1))

tas = [0]
tbs = [0]
for c in T:
    a = int(c=='A')
    tas.append(tas[-1] + a)
    tbs.append(tbs[-1] + (a^1))

ans = []
for a,b,c,d in qs:
    sa = sas[b] - sas[a-1]
    sb = sbs[b] - sbs[a-1]
    ta = tas[d] - tas[c-1]
    tb = tbs[d] - tbs[c-1]
    s = (sb-sa)%3
    t = (tb-ta)%3
    ans.append('YES' if s==t else 'NO')
print(*ans, sep='\n')