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

N = int(input())
a = sorted(list(map(int, input().split())))

import numpy as np
from scipy.misc import comb

i = 0
j = N//2

ans = (0, 0)
x = 0
for j in range(1, N):
    n = a[j]
    while j - i > 1:
        if abs(n/2 - a[i]) < abs(n/2 - a[i+1]):
            break
        i+=1
    p = a[i]
    y = comb(n, p)
    if y > x:
        x = y
        ans = (n, p)

print(str(ans[0]), str(ans[1]))


### FIXED CODE ###

N = int(input())
a = sorted(list(map(int, input().split())))

def find_p(n, i):
    lo = 0
    hi = i
    mid = (hi-lo)//2
    xl = a[0]
    xh = a[i]
    while hi - lo > 1:
        mid = (hi+lo)//2
        if a[mid] > n//2:
            hi = mid
        else:
            lo = mid
    if abs(a[lo] - n/2) > abs(a[hi] - n/2):
        return a[hi]
    else:
        return a[lo]



print(str(a[-1]) + ' ' + str(find_p(a[-1], N-1)))
### BUGGY CODE ###

import sys
# from collections import defaultdict
# from collections import Counter
# from queue import Queue

sys.setrecursionlimit(10000)

def solve(n):
    if n == 1:
        return 0

    for i in range(2, n+1):
        if n % i == 0:
            # 素因数を枯らす
            sys.stderr.write('hit: n = {}, i = {}^1\n'.format(n, i))
            sys.stderr.write('hit: {}^1\n'.format(i))
            cnt = 1
            tmp = n // i
            while(tmp % (i ** (cnt+1)) == 0):
                sys.stderr.write('hit: {}^{}\n'.format(i, cnt+1))
                tmp = tmp // (i ** (cnt+1))
                cnt += 1

            while(tmp % i == 0):
                tmp = tmp // i

            return solve(tmp) + cnt

    return 0

def main():
    N = int(input())

    ans = solve(N)
    print(ans)

    # N, M = [int(s) for s in input().split()]

    # As = []
    # for i in range(N):
    #     tmp = int(input())
    #     As.append(tmp)

    return 0

if __name__ == '__main__':
    sys.exit(main())


### FIXED CODE ###

import sys
# from collections import defaultdict
# from collections import Counter
# from queue import Queue
import math

sys.setrecursionlimit(10000)

def solve(n, start):
    if n == 1:
        return 0

    for i in range(start, int(math.sqrt(n+1))):
        sys.stderr.write('i = {}\n'.format(i))

        if n % i == 0:
            # 素因数を枯らす
            sys.stderr.write('hit: n = {}, i = {}^1\n'.format(n, i))
            sys.stderr.write('hit: {}^1\n'.format(i))
            cnt = 1
            tmp = n // i
            while(tmp % (i ** (cnt+1)) == 0):
                sys.stderr.write('hit: {}^{}\n'.format(i, cnt+1))
                tmp = tmp // (i ** (cnt+1))
                cnt += 1

            while(tmp % i == 0):
                tmp = tmp // i

            return solve(tmp, i+1) + cnt

    return 1

def main():
    N = int(input())

    ans = solve(N, 2)
    print(ans)

    # N, M = [int(s) for s in input().split()]

    # As = []
    # for i in range(N):
    #     tmp = int(input())
    #     As.append(tmp)

    return 0

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

#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, maxint

MININT = -1 - maxint


def max_heapify(a, i, heap_size):
    L = 2*i
    R = 2*i + 1
    if L <= heap_size and a[L] > a[i]:
        largest = L
    else:
        largest = i
    if R <= heap_size and a[R] > a[largest]:
        largest = R
    if largest != i:
        a[i], a[largest] = a[largest], a[i]
        max_heapify(a, largest, heap_size)


def max_heap_insert(a, key, heap_size):
    heap_size[0] += 1
    a[heap_size[0]] = MININT
    heap_increase_key(a, key, heap_size[0])


def heap_increase_key(a, key, i):
    #if key < a[i]:
        #raise ValueError('new key less current key')
    a[i] = key
    half = i // 2
    while i > 1 and a[half] < a[i]:
        a[i], a[half] = a[half], a[i]
        i = i // 2
        half = i // 2


def heap_extract_max(a, heap_size):
    #if heap_size[0] < 1:
        #raise ValueError('heap under flow')
    max = a[1]
    a[1] = a[heap_size[0]]
    heap_size[0] -= 1
    max_heapify(a, 1, heap_size[0])
    return max


heap = [MININT] * 2000001
heap_size = [1]
for cmd in stdin:
    if cmd[0] == 'i':
        key = int(cmd[7:])
        #assert 0 <= key <= 2000000000
        max_heap_insert(heap, key, heap_size)
    elif cmd[1] == 'x':
        print(heap_extract_max(heap, heap_size))
    elif cmd[1] == 'n':
        break

### FIXED CODE ###

#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def max_heapify(a, i):
    heap_size = a[0]

    L = 2*i
    R = 2*i + 1
    if L <= heap_size and a[L] > a[i]:
        largest = L
    else:
        largest = i
    if R <= heap_size and a[R] > a[largest]:
        largest = R
    if largest != i:
        a[i], a[largest] = a[largest], a[i]
        max_heapify(a, largest)


def main():
    heap = [-1] * 2000001
    heap[0] = 1
    for cmd in stdin:
        if cmd[0] == 'i':
            heap[0] += 1
            i = heap[0]
            heap[i] = int(cmd[7:])

            half = i // 2
            while i > 1 and heap[half] < heap[i]:
                heap[i], heap[half] = heap[half], heap[i]
                i //= 2
                half = i // 2
        elif cmd[1] == 'x':
            print(heap[1])
            heap[1] = heap[heap[0]]
            heap[0] -= 1
            max_heapify(heap, 1)
        elif cmd[1] == 'n':
            exit(0)


main()
### BUGGY CODE ###

from collections import deque
H, W = map(int, input().split())
S = [input() + "#" for _ in range(H)]
S.append("#" * (W + 1))
paths = [(h, w) for h in range(H) for w in range(W) if S[h][w] == "."]

ans = 0
todo = deque()
done = [[False] * W for _ in range(H)]
for sh, sw in paths:
    done[sh][sw] = True
    for gh, gw in paths:
        if done[gh][gw]:
            continue
        todo.append((0, sh, sw))
        pathed = [[False] * W for _ in range(H)]
        while todo:
            cnt, h, w = todo.popleft()
            cnt += 1
            for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                nh = h + dh
                nw = w + dw
                if nh == gh and nw == gw:
                    if ans < cnt:
                        ans = cnt
                    todo.clear()
                    break
                elif S[nh][nw] == "." and not pathed[nh][nw]:
                    todo.append((cnt, nh, nw))
            pathed[h][w] = True
print(ans)

### FIXED CODE ###

from collections import deque
H, W = map(int, input().split())
S = [input() + "#" for _ in range(H)]
S.append("#" * (W + 1))

todo = deque()
done = set()
ans = 0
for sh in range(H):
    for sw in range(W):
        if S[sh][sw] == "#":
            continue
        s = (sh, sw)
        done.clear()
        done.add(s)
        todo.append((s, 0))
        while todo:
            p, count = todo.popleft()
            ncount = count + 1
            for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                nh, nw = p[0] + dh, p[1] + dw
                if S[nh][nw] == "#":
                    continue
                np = (nh, nw)
                if np in done:
                    continue
                done.add(np)
                ans = max(ans, ncount)
                todo.append((np, ncount))
print(ans)
### BUGGY CODE ###

from bisect import bisect_left,bisect_right

N,M,Q=list(map(int,input().split()))
t=[list(map(int,input().split())) for _ in range(M)]
query=[list(map(int,input().split())) for _ in range(Q)]

train=[[0]*(N+1) for _ in range(N+1)]
c=[[0]*(N+1) for _ in range(N+1)]

for l,r in t:
    train[l][r]+=1

for l in range(1,N+1):
    for r in range(1,N+1):
        c[l][r]=c[l][r-1]+train[l][r]

for p,q in query:
    tmp=0
    for l in range(p,q+1):
        tmp+=c[l][q]-c[l][p-1]
    
    print(tmp)

### FIXED CODE ###

N,M,Q=list(map(int,input().split()))
t=[list(map(int,input().split())) for _ in range(M)]
query=[list(map(int,input().split())) for _ in range(Q)]

train=[[0]*(N+1) for _ in range(N+1)]
c=[[0]*(N+1) for _ in range(N+1)]

for l,r in t:
    train[l][r]+=1

for l in range(1,N+1):
    for r in range(1,N+1):
        c[l][r]=c[l][r-1]+train[l][r]

for p,q in query:
    tmp=0
    for l in range(p,q+1):
        tmp+=c[l][q]-c[l][p-1]
    
    print(tmp)
### BUGGY CODE ###

n = int(input())
s = []
for i in range(n):
    sin = input()
    sin = list(sin)
    sin.sort()
    sin = ''.join(sin)
    s.append(sin)

c = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        if s[i] == s[j]:
            c += 1
            continue
print(c)


### FIXED CODE ###

import itertools

def comb(n, r):
    return len(list(itertools.combinations(range(n), r)))

def get_runlength(s): # ex) s = 'RRLLLLRLRLRLRR'
    ret = []
    count = 1
    for i in range(len(s)):
        if i == len(s) - 1:
            ret.append((s[i], count))
            continue
        if s[i] == s[i + 1]:
            count += 1
        else:
            ret.append((s[i], count))
            count = 1
    return ret

n = int(input())
dic = {}
for i in range(n):
    sin = input()
    sin = list(sin)
    sin.sort()
    sin = ''.join(sin)
    try:
        dic[sin] += 1
    except:
        dic[sin] = 1

count = 0
for v in dic.values():
    count += v * (v - 1) / 2
count = int(count)
print(count)
### BUGGY CODE ###

n = int(input())
size = list(map(int, input().split()))
price = list(map(int, input().split()))

ans = 0

for i in range(2**n-1) :
    tmp_sumS = 0
    tmp_sumP = 0
    tmp_comb = []

    for j in range(n) :
        # シフトして１ビットずつ判断
        is_put = i>>(n-j-1)&1
        tmp_comb.append(is_put)
        tmp_sumS += is_put * size[j]
        tmp_sumP += is_put * price[j]
            
        if tmp_sumS-tmp_sumP > ans:
            ans = tmp_sumS-tmp_sumP

print(ans)

### FIXED CODE ###

n = int(input())
size = list(map(int, input().split()))
price = list(map(int, input().split()))

ans = 0

for i in range(n):
    if size[i]-price[i] > 0:
        ans+=size[i]-price[i]

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

n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
cnt = 0

for i in range(n):
  for j in range(n):
    b1 = b[j]
    c1 = c[i]
    if c1 <= b1:
      break
    for k in range(n):
      a1 = a[k]
      if b1 <= a1:
        break
      else:
        cnt += 1

print(cnt)

### FIXED CODE ###

import bisect
n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
ans = 0

for b in B:
  num_a = bisect.bisect_left(A, b)
  num_c = n - bisect.bisect_right(C, b)
  ans += num_a * num_c
print(ans)
### BUGGY CODE ###


def do():
    S = input()
    l = len(S)
    S = S[::-1]
    dp =[[0 for _ in range(13) ] for _ in range(l + 1)]
    kurai = 1
    MOD = (10 ** 9) + 7
    dp[0][0] = 1

    for keta,c in  enumerate(S):

        if c == "?":
            for j in range(0,10):
                temp = (j * kurai) % 13
                for i in range(13):
                    dp[keta + 1][(temp + i) % 13] += (dp[keta][i] %MOD)
                    dp[keta + 1][(temp + i) % 13] %= MOD
        else:
            temp = (int(c) * kurai) % 13
            for i in range(13):
                dp[keta + 1][(temp + i) % 13]  += (dp[keta][i] % MOD)
                dp[keta + 1][(temp + i) % 13] %= MOD
        kurai *= 10
        keta %= MOD
    print(dp[-1][5] % MOD)

if __name__ == "__main__":
    do()

### FIXED CODE ###


import sys

S =  sys.stdin.readline()[:-1]
l = len(S)
# S = S[::-1]
S = list(reversed(S))

dp =[[0 ] * 13 for _ in range(l + 1)]
kurai = 1
MOD = (10 ** 9) + 7
dp[0][0] = 1

for keta in range(len(S)):
    c =S[keta]

    if c == "?":
        for j in range(0,10):
            kurai %= 13
            temp = (j * kurai) % 13
            for i in range(13):
                dp[keta + 1][(temp + i) % 13] += (dp[keta][i] )
                dp[keta + 1][(temp + i) % 13] %= MOD
    else:
        kurai %= 13

        temp = (int(c) * kurai) % 13
        for i in range(13):
            dp[keta + 1][(temp + i) % 13]  += (dp[keta][i] )
            dp[keta + 1][(temp + i) % 13] %= MOD
    kurai *= 10
    keta %= MOD
print(dp[-1][5] )
### BUGGY CODE ###

n,k = map(int,input().split())
h = [int(input()) for _ in range(n)]
h = sorted(h)
ans = float('inf')
for i in range(n-k+1):
    hs = h[i:i+k]
    ans = min(ans,(hs[-1] - hs[0]))
print(ans)

### FIXED CODE ###

n,k = map(int,input().split())
h = [int(input()) for _ in range(n)]
h.sort()
ans = float('inf')
for i in range(n-k+1):
    ans = min(ans,(h[i+k-1] - h[i]))
print(ans)
### BUGGY CODE ###

import numpy as np

N = int(input())
res = 0
p = list(map(int, input().split()))
p_a = np.array(p, dtype = np.int64)
for i in range(N):
    mini = np.min(p_a[:(i+1)])
    if mini >= p[i]:
        res += 1    
print(res)

### FIXED CODE ###

N = int(input())
res = 0
p = list(map(int, input().split()))
mini = p[0]
for i in range(N):
    mini = min(mini, p[i])
    if mini >= p[i]:
        res += 1    
print(res)
### BUGGY CODE ###

import sys

n = int(input())

a = []
for i in range(n):
  v = list(map(int, input().split(' ')))
  a.append(v)

f = True
day = 1
while(f):
  done = []
  nokori = False
  for m in range(n):
    if m in done:
      if not nokori and len(a[m]):
        nokori = True
      pass
    elif len(a[m]):
      teki = a[m][0]
      jibun = m + 1
      if not len(a[teki - 1]):
        print(-1)
        sys.exit()
      elif a[teki - 1][0] == jibun and teki - 1 not in done:
        a[m].pop(0)
        a[teki - 1].pop(0)
        done.append(m)
        done.append(teki - 1)
        if not nokori and len(a[m]):
          nokori = True
  if not nokori:
    for m in range(n):
      if len(a[m]):
        print(-1)
        sys.exit()
    print(day)
    sys.exit()
  day += 1

### FIXED CODE ###

import sys
import time
from collections import deque

start = time.time()

input = sys.stdin.readline

n = int(input())
a = [deque([x for x in list(map(int, input().split()))]) for _ in range(n)]
nokori_games = n * (n - 1) / 2 
day = 1
r5000 = range(5000)
player_in_this_game = set()
rn = range(n)
for _ in r5000:
  for m in rn: #選手ごとに判定
    #整合性のある対戦組み合わせがあれば配列から消す
    #全員の判定が終わって試合が残っていたら1日増やす
    if m in player_in_this_game:
      #自分が既に試合が組まれている
      continue

    la = len(a[m])      
    if la: #選手に試合予定が残っている
      teki = a[m][0] #対戦相手
      jibun = m + 1 #自分
      teki_idx = teki - 1
      if teki_idx in player_in_this_game:
        #相手が既に試合に組まれている
        continue

      if a[teki_idx][0] == jibun: #対戦相手の予定も自分でかつ相手がこのターンで試合中ではない
        a[m].popleft() #自分の予定を消す
        a[teki_idx].popleft() #相手の予定を消す
        player_in_this_game.add(m) #自分を試合中にする
        player_in_this_game.add(teki_idx) #相手を試合中にする
        nokori_games -= 1 #残り試合予定を1つ減らす

  if nokori_games: #残り試合があるのに
    if not len(player_in_this_game): #今回対戦が組まれなければ残りの予定が不整合なのでエラー
      print(-1)
      sys.exit()
  else: #誰も残り試合予定がなければ終了
    print(day)
    sys.exit()
  day += 1
  player_in_this_game.clear()
  elapsed_time = time.time() - start
  if elapsed_time > 1:
    print(n*(n-1)//2)
    exit()
### BUGGY CODE ###

X,Y,Z,K=[int(i) for i in input().split(" ")]
A=[int(i) for i in input().split(" ")]
B=[int(i) for i in input().split(" ")]
C=[int(i) for i in input().split(" ")]

delicious=[]

for a in A:
    for b in B:
        for c in C:
            delicious.append(a+b+c)

delicious=sorted(delicious,reverse=True)
for i in range(K):
    print(delicious[i])


### FIXED CODE ###

import heapq
X,Y,Z,K=[int(i) for i in input().split(" ")]
A=[int(i) for i in input().split(" ")]
B=[int(i) for i in input().split(" ")]
C=[int(i) for i in input().split(" ")]

AB=[]
for a in A:
    for b in B:
        AB.append(a+b)

AB=heapq.nlargest(K,AB)
ABC=[]
for ab in AB:
    for c in C:
        ABC.append(ab+c)

for cake in heapq.nlargest(K,ABC):
    print(cake)
### BUGGY CODE ###

N, M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(M)]
mid = []
AB.sort()
for ab in AB:
    if ab[0] == 1:
        for  cd in AB:
            if ab[1] == cd[0] and cd[1] == N:
                print("POSSIBLE")
                exit()
    else:
        break
print("IMPOSSIBLE")

### FIXED CODE ###

N, M = map(int,input().split())
AB = []
for _ in range(M):
    a,b = map(int,input().split())
    if  a == 1 or b== N:
        AB.append((a,b))
set1 = set()
set2 = set()
for ab in AB:
    if ab[0] == 1:
        set1.add(ab[1])
    if ab[1] == N:
        set2.add(ab[0])
if set1 & set2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
### BUGGY CODE ###

l=input().split()
l = [int(s) for s in l]
for i in range(1,l[0]+1):
    if l[0] % i == 0 and l[1] % i == 0:
        c = i
print(c)



### FIXED CODE ###

l=input().split()
l = [int(s) for s in l]
a = l[0]
b = l[1]
while (b != 0 and a != 0):
    if(a < b):
        b = b % a
    else:
        a = a % b
if(a == 0):
    print(b)
else:
    print(a)
### BUGGY CODE ###

N = int(input())

cnt = 0
n = 1

while N // 2*(5**n) > 0:
  a = N // 2*(5**n)
  cnt = cnt + a
  n = n + 1
  
print(cnt)

### FIXED CODE ###

import math
N = int(input())

a1  = N // 10
a2  = N // 100
a3  = N // 1000
a4  = N // 10000
a5  = N // 100000
a6  = N // 1000000
a7  = N // 10000000
a8  = N // 100000000
a9  = N // 1000000000
a10 = N // 10000000000
a11 = N // 100000000000
a12 = N // 1000000000000
a13 = N // 10000000000000
a14 = N // 100000000000000
a15 = N // 1000000000000000
a16 = N // 10000000000000000
a17 = N // 100000000000000000
a18 = N // 1000000000000000000
a19 = N // 10000000000000000000

b1  = (N // 50) - a2
b2  = (N // 250  ) - a3
b3  = (N // 1250 ) - a4
b4  = (N // ((5**4)*10) ) - a5
b5  = math.ceil(N // ((5**5)*10 )) - a6
b6  = math.ceil(N // ((5**6)*10 )) - a7
b7  = math.ceil(N // ((5**7)*10 )) - a8
b8  = math.ceil(N // ((5**8)*10 )) - a9
b9  = math.ceil(N // ((5**9)*10 )) - a10
b10 = math.ceil(N // ((5**10)*10) ) - a11
b11 = math.ceil(N // ((5**11)*10) ) - a12
b12 = math.ceil(N // ((5**12)*10) ) - a13
b13 = math.ceil(N // ((5**13)*10) ) - a14
b14 = math.ceil(N // ((5**14)*10) ) - a15
b15 = math.ceil(N // ((5**15)*10) ) - a16
b16 = math.ceil(N // ((5**16)*10)) - a17
b17 = math.ceil(N // ((5**17)*10) ) - a18
b18 = math.ceil(N // ((5**18)*10) ) - a19
b19 = math.ceil(N // ((5**19)*10) )
b20 = math.ceil(N // ((5**20)*10) )
b21 = math.ceil(N // ((5**21)*10) )
b22 = math.ceil(N // ((5**22)*10) )
b23 = math.ceil(N // ((5**23)*10) )
b24 = math.ceil(N // ((5**24)*10) )
b25 = math.ceil(N // ((5**25)*10) )
b26 = math.ceil(N // ((5**26)*10) )


ans = a1*1 + a2*1+ a3*1+ a4*1 + a5*1+ a6*1+ a7*1+ a8*1+ a9*1+ a10*1+ a11*1+ a12*1+ a13*1+ a14*1+ a15*1+ a16*1+ a17*1+ a18*1+ a19*1
ans = ans + b1*1 + b2*1+ b3*1+ b4*1 + b5*1+ b6*1+ b7*1+ b8*1+ b9*1+ b10*1+ b11*1+ b12*1+ b13*1+ b14*1+ b15*1+ b16*1+ b17*1+ b18*1 + b19+b20+b21+b22+b23+b24+b25

if N % 2 == 1:
  print(0)
else:
  print(ans)
### BUGGY CODE ###

N=int(input())
item = [int(input()) for i in range(N)]
ans=0
for i in range(2 ** N):
    out = 0
    for j in range(N):  # このループが一番のポイント
        if (i >> j) & 1:  # 順に右にシフトさせ最下位bitのチェックを行う
            out+=item[j]  # フラグが立っていたら 加算する
    if str(out)[-1]=='0':
        out = 0
    ans=max(ans,out)
print(ans)

### FIXED CODE ###

N=int(input())
items = [int(input()) for i in range(N)]
tot=sum(items)
ans=0
if tot%10!=0:
  ans=tot
else:
  items.sort()
  for i in range(N):
    if items[i]%10!=0:
      ans=tot-items[i]
      break
print(ans)
### BUGGY CODE ###

#!/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()))

n = I()
V = []
W = []
for _ in range(n):
    v, w = LI()
    V.append(v)
    W.append(w)

q = I()
for _ in range(q):
    v, L = LI()
    m = int(math.log2(v)) + 1
    dp = [[0]*(L+1) for _ in range(m+1)]
    idx = v
    for i in range(m):
        for j in range(L+1):
            if j < W[idx-1]:
                dp[i+1][j] = dp[i][j]
            else:
                dp[i+1][j] = max(dp[i][j],dp[i][j-W[idx-1]] + V[idx-1])
        idx //= 2
    print(dp[-1][L])

    

### FIXED CODE ###

#!/usr/bin/env python3

def main():
    import sys
    def I(): return int(sys.stdin.readline())
    def LI(): return list(map(int,sys.stdin.readline().split()))

    n = I()
    V = []
    W = []

    maxL = 10**5
    m = min(n, 1 << 10)
    dp = [[0]*(maxL + 1)]
    
    for i in range(n):
        v, w = LI()
        if i <= m:
            d_ = dp[(i+1)>>1][:]
            for j in range(w, maxL+1)[::-1]:
                d_[j] = max(d_[j], d_[j - w] + v)
            dp.append(d_)
        V.append(v)
        W.append(w)
    
    q = I()
    for i in range(q):
        v, L = LI()
        if v <= m:
            print(dp[v][L])
            continue
        cnt = 0
        v_ = []
        w_ = []
        while v > m:
            v_.append(V[v-1])
            w_.append(W[v-1])
            v >>= 1
            cnt += 1
        ret = dp[v][L]
        v_tmp = [0] * (1 << cnt)
        w_tmp = [0] * (1 << cnt)
        for b in range(1, 1 << cnt):
            lsb = b & -b
            l = lsb.bit_length()
            w_t = w_tmp[b - lsb] + w_[l-1]
            w_tmp[b] = w_t
            if w_t <= L:
                v_t = v_tmp[b - lsb] + v_[l-1]
                v_tmp[b] = v_t
                ret = max(ret, v_t + dp[v][L - w_t])
        print(ret)
    return

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

import collections

NONE_RES,A_RES,B_RES = 0,1,2
buf = [[NONE_RES,B_RES,A_RES],[A_RES,NONE_RES,B_RES],[B_RES,A_RES,NONE_RES]]

def check(s1,s2):
    s1,s2 = collections.Counter(s1),collections.Counter(s2)
    A1 = s1['A'] if 'A' in s1 else 0
    A2 = s2['A'] if 'A' in s2 else 0
    B1 = s1['B'] if 'B' in s1 else 0
    B2 = s2['B'] if 'B' in s2 else 0
    type1 = buf[A1%3][B1%3]
    type2 = buf[A2%3][B2%3]
    return type1==type2

S = input()
T = input()
n = int(input())
for _ in range(n):
    a,b,c,d = map(int,input().split(' '))
    if check(S[a-1:b],T[c-1:d]):
        print('YES')
    else:
        print('NO')

### FIXED CODE ###

NONE_RES,A_RES,B_RES = 0,1,2
buf = [[NONE_RES,B_RES,A_RES],[A_RES,NONE_RES,B_RES],[B_RES,A_RES,NONE_RES]]

S = input()
s = [1 if c == 'A' else 0 for c in S]
T = input()
t = [1 if c == 'A' else 0 for c in T]
n = int(input())

sum_s = [0]
for s_ in s:
    sum_s.append(sum_s[-1]+s_)

sum_t = [0]
for t_ in t:
    sum_t.append(sum_t[-1]+t_)

for _ in range(n):
    a,b,c,d = map(int,input().split(' '))
    A1 = sum_s[b] - sum_s[a-1]
    B1 = (b-(a-1))-A1
    A2 = sum_t[d] - sum_t[c-1]
    B2 = (d-(c-1))-A2
    type1 = buf[A1%3][B1%3]
    type2 = buf[A2%3][B2%3]
    if type1==type2:
        print('YES')
    else:
        print('NO')
### BUGGY CODE ###

S=input()
S_list=list(S)
num_B = S.count('W')
count = 0
for nb in range(num_B):
  i = nb
  while S_list[i] != 'W': i+=1
  count += i - nb
  S_list[nb],S_list[i]=S_list[i],S_list[nb]
print(count)

### FIXED CODE ###

S=input()
S_list=list(S)
num_B = S.count('W')
count = 0
i = 0
for nb in range(num_B):
  while S_list[i] != 'W': i+=1
  count += i - nb
  S_list[nb],S_list[i]=S_list[i],S_list[nb]
  i+=1
print(count)