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

n=int(input())
s=input()
c=[[0,0,0] for _ in range(n+1)]
R=G=B=0
for j,i in enumerate(s):
    if i=="R":
        R+=1
    elif i=="G":
        G+=1
    else:B+=1
    c[j+1]=[R,G,B]
a=0
for i,m in enumerate(s):
    for j in range(i):
        k=3-"RGB".index(m)-"RGB".index(s[j])
        if m!=s[j]:
            a+=c[-1][k]-c[i][k]
            if 2*i-j<=n-1:
                if s[2*i-j]=="RGB"[k]:
                    a-=1
print(a)

### FIXED CODE ###

n=int(input())
s=input()
c=s.count
a=c("R")*c("G")*c("B")
for i in range(n-2):
    for j in range((n-i+1)//2):
        if s[i]!=s[i+j] and s[i+j]!=s[i+2*j] and s[i+2*j]!=s[i]:
            a-=1
print(a)
### BUGGY CODE ###

N = int(input())
x = list(map(int, input().split()))
y = []
for a in x:
    y.append(a)
    y.reverse()
print(*y)

### FIXED CODE ###

import math
N = int(input())
x = list(map(int, input().split()))
y = []
if N%2 == 0:
    for i in range(N//2):
        y.append(x[N-1-2*i])
    for i in range(N//2):
        y.append(x[2*i])
if N%2 == 1:
    for i in range(math.ceil(N/2)):
        y.append(x[N-1-2*i])
    for i in range(math.floor(N/2)):
        y.append(x[2*i+1])
print(*y)
### BUGGY CODE ###

import bisect

n = int(input())
L =list(map(int, input().split()))
L=sorted(L)

ans=0
for i in range(0, n-2,1):
  for j in range(i+1,n-1,1):
    min_sum = L[i]+L[j]
    more_than = bisect.bisect_left(L[j+1:], min_sum)
    ans += more_than
print(ans)

### FIXED CODE ###

from bisect import bisect_left
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += bisect_left(L, L[i]+L[j])-j-1
print(ans)
### BUGGY CODE ###

n, m, r = list(map(int, input().split()))
rs = list(map(int, input().split()))
# construct map
import numpy as np
dists = np.ones((n + 1, n + 1)) * float('inf')
for _ in range(m):
    a, b, c = list(map(int, input().split()))
    dists[a, b] = dists[b, a] = c
for i in range(1, n + 1):
    dists[i, i] = 0

from itertools import product, permutations
for i, j in product(range(1, 1 + n), repeat=2):
    for k in range(j + 1, n + 1):
        if dists[j, k] > dists[j, i] + dists[i, k]:
            dists[j, k] = dists[k, j] = dists[j, i] + dists[i, k]

ans = float('inf')
for path in permutations(rs):
    val = sum(dists[i, j] for i, j in zip(path, path[1:]))
    val = int(val)
    if val < ans:
        ans = val

print(ans)

### FIXED CODE ###

n, m, r = list(map(int, input().split()))
rs = list(map(int, input().split()))
# construct map
import numpy as np
dists = np.ones((n + 1, n + 1)) * float('inf')
for _ in range(m):
    a, b, c = list(map(int, input().split()))
    dists[a, b] = dists[b, a] = c
for i in range(1, n + 1):
    dists[i, i] = 0

from itertools import product, permutations
for i, k in product(range(1, 1 + n), repeat=2):
    dists[:, k] = np.minimum(dists[:, k], dists[:, i] + dists[i, k])

ans = float('inf')
for path in permutations(rs):
    val = sum(dists[i, j] for i, j in zip(path, path[1:]))
    val = int(val)
    if val < ans:
        ans = val

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

n = int(input())
a = list(map(int,input().split()))
ans = 1
for i in range(n):
    ans *= a[i]
if ans > 10 ** 18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1
cnt_0 = a.count(0)
if cnt_0 >= 1:
    ans = 0
else:
    for i in range(n):
        ans *= a[i]
        if ans > 10 ** 18:
            ans = -1
            break
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import numpy as np
def print_ans(L, R):
    """Test Case
    >>> print_ans(2020, 2040)
    2
    >>> print_ans(4, 5)
    20
    """
    ans = 2019
    for i in range(L, R):
        for k in range(i + 1, R + 1):
            ans = min(ans, (i * k) % 2019)
    print(ans)



if __name__ == '__main__':
    L, R = map(int, input().rstrip().split())
    print_ans(L, R)


### FIXED CODE ###

import sys
input = sys.stdin.readline
def print_ans(L, R):
    """Test Case
    >>> print_ans(2020, 2040)
    2
    >>> print_ans(4, 5)
    20
    """
    tmp = R - L
    if tmp > 2019:
        print("0")
    else:
        L = L % 2019
        R = L + tmp
        ans = 2019
        flg = False
        for i in range(L, R):
            for k in range(i + 1, R + 1):
                ans = min(ans, (i * k) % 2019)
                if ans == 0:
                    flg = True
                    break
            if flg :
                break
        print(ans)



if __name__ == '__main__':
    L, R = map(int, input().rstrip().split())
    print_ans(L, R)
### BUGGY CODE ###

S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]
flag=0
#print(query)
s=S
s2=""
for i in range(Q):
    if len(query[i])==1:
        flag=(flag+1)%2 #反転フラグをひっくり返す
    else:
        if flag==0:
            if query[i][1]=="1":
                s="".join((query[i][2],s))
            else:
                s = "".join((s,query[i][2]))
        else:
            if query[i][1]=="2":
                s="".join((query[i][2],s))
            else:
                s = "".join((s,query[i][2]))
if flag==0:
    print(s)
else:
    for i in range(len(s)):
        s2="".join(())
    print(s[::-1])

### FIXED CODE ###

from collections import deque
d=deque()
S=list(input())
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]
flag=0  #反転なし
#print(query)
s=S
s2=""
d.extend(S)
#print(d)
for i in range(Q):
    #print(i,len(d))
    if (len(query[i])==1):
        if len(d)>1:
            flag=(flag+1)%2 #反転フラグをひっくり返す
    else:
        if flag==0:
            if query[i][1]=="1":
                d.appendleft(query[i][2])
            else:
                d.append(query[i][2])
        else:
            if query[i][1]=="2":
                d.appendleft(query[i][2])
            else:
                d.append(query[i][2])
    #print(d)
if flag==0:
    print("".join(list(d)))
else:
    d.reverse()
    print("".join(list(d)))
### BUGGY CODE ###

N,Q = map(int,input().split())
S = list(input())

def counter(S):
  count1 = 0
  for i in range(len(S)-1):
    if((S[i] == 'A')and(S[i+1] == 'C')):
      count1 += 1
  return count1


for i in range(Q):
  count = 0
  l,r = map(int,input().split())
  l,r = l-1,r-1
  tmp_S = S[l:r+1]
  count += counter(tmp_S)
  print(count)


### FIXED CODE ###

N,Q = map(int,input().split())
S = list(input())

AC = []
count1 = 0
for i in range(N):
  
  if(i != 0):
   if((S[i-1] == 'A')and(S[i] == 'C')):
    count1 += 1
  AC.append(count1)

for i in range(Q):
  l,r = map(int,input().split())
  l,r = l-1,r-1
  count = AC[r]-AC[l]
  print(count)
### BUGGY CODE ###

N,K = map(int,input().split())
A = list(map(int, input().split()))
sum = 1
last = 1
sw = 0
for num in range(K):
  last *= A[num]
for i in range(1,N-K+1):
  for j in range(K):
    sum *= A[i+j]
    if last < sum:
      print("Yes")
      sw = 1
      break
  if sw ==0:
    print("No")
  last = sum
  sum = 1
  sw = 0

### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int, input().split()))

for i in range(0,N-K):
  if A[i] < A[i+K]:
    print("Yes")
  else:
    print("No")
### BUGGY CODE ###

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

import math


class SegmentTree(object):
    # セグメント木

    def __init__(self, N):
        """サイズNの配列を元にしたセグメント木
        """
        # 単位元
        self.idelem = -INF
        # 比較関数
        self.func = max

        self.N0 = 2**(math.ceil(math.log2(N)))
        self.tree = [self.idelem]*(2*self.N0)

    def update(self, k, x):
        """k番目の値をxに更新
        """
        k += self.N0-1
        self.tree[k] = x
        while k > 1:
            k = (k-1)//2
            self.tree[k] = self.func(self.tree[2*k+1], self.tree[2*k+2])

    def query(self, l, r):
        """区間[l, r)の最大
        """
        l += self.N0-1
        r += self.N0-1
        s = self.idelem
        while l < r:
            if r % 2 == 0:
                r -= 1
                s = self.func(s, self.tree[r])

            if l % 2 == 0:
                s = self.func(s, self.tree[l])
                l += 1
            l //= 2
            r //= 2
        return s

    def __str__(self):
        return str(self.tree[self.N0-1:-1])


def solve(N: int, A: "List[int]"):
    st = SegmentTree(N)
    for i, a in enumerate(A):
        st.update(i, a)
    print(st.query(1, N))
    for i in range(1, N-1):
        print(max(st.query(0, i), st.query(i+1, N)))
    print(st.query(0, N-1))

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


### FIXED CODE ###

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


def argmax(a):
    m, n = -(1 << 31), -1
    for i, v in enumerate(a):
        if m < v:
            m, n = v, i
    return m, n


def solve(N: int, A: "List[int]"):
    m, mi = argmax(A)
    m2, mi2 = argmax(A[:mi]+A[mi+1:])
    for i in range(N):
        if i == mi:
            print(m2)
        else:
            print(m)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


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

def main():
  n, k = map(int, input().split())
  a = list(map(int, input().split()))
  l = []
  for i in range(0, n):
    for j in range(i+1, n):
      l.append(a[i]*a[j])
  l.sort()
  print(l[k-1])

if __name__ == '__main__':
  main()

### FIXED CODE ###

from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from functools import reduce
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm(a, b):
  return a*b//gcd(a, b)


def main():
  n, k = map(int, input().split())
  A = np.array(input().split(), np.int64)
  
  A = np.sort(A)
  
  zero = A[A == 0]
  pos = A[A>0]
  neg = A[A<0]
  
  def F(x):
    cnt_tpl = 0
    #zero multipy ...
    if x>= 0:
      cnt_tpl += len(zero)*n
    #positive multipy ...
    cnt_tpl += np.searchsorted(A, x//pos, side='right').sum()
    cnt_tpl += (n - np.searchsorted(A, (-x-1)//(-neg), side='right')).sum()
    cnt_tpl -= np.count_nonzero(A*A<=x)
    assert cnt_tpl %2 ==0
    return cnt_tpl//2
  
  left = -10**18
  right = 10**18
  while left + 1 < right:
    mid = (left+right)//2
    if F(mid) >= k:
      right = mid
    else:
      left = mid
  print(right)
  
if __name__ == '__main__':
  main()
### BUGGY CODE ###

# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n,k = readInt()
    a = readInt()
    ans = []
    res = 1
    for i in range(n):
        x = res
        if i<k:
            res *= a[i]
        else:
            res //= a[i-k]
            res *= a[i]
            if res>x:
                ans.append("Yes\n")
            else:
                ans.append("No\n")
    print(''.join(ans))
    return

if __name__=='__main__':
    main()


### FIXED CODE ###

# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
import time
# from itertools import product,permutations,\
    # combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n,k = readInt()
    a = readInt()
    ans = ["Yes\n" for i in range(n-k)]
    for i in range(n):
        if i<k:
            continue
        if a[i]>a[i-k]:
            print("Yes")
        else:
            print("No")
    return

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

#coding:utf-8
import math
K=int(input())
result=0
for i in range(K):
	for j in range(K):
		for k in range(K):
			result+=math.gcd(math.gcd(i+1,j+1),k+1)

print(result)

### FIXED CODE ###

#coding:utf-8
from math import*
K=int(input())
result=0
for i in range(1,K+1):
	for j in range(1,K+1):
		for k in range(1,K+1):
			result+=gcd(gcd(i,j),k)

print(result)
### BUGGY CODE ###

n = int(input())
for i in range(1, n*2+1):
  if i%2==0 and i%n==0:
    print(i)
    exit()

### FIXED CODE ###

n=int(input())
if n % 2 == 0:print(n)
else: print(n*2)
### BUGGY CODE ###

n=int(input())
s=[input() for _ in range(n)]
alp=[chr(ord('a')+i) for i in range(26)]
sc=[[0] for _ in range(n)]
for i in range(n):
  for j in alp:
    sc[i].append(s[i].count(j))
cnt=0

for i in range(n):
  cnt+=sc.count(sc[0])-1
  sc.pop(0)
print(cnt)

### FIXED CODE ###

from collections import Counter
n=int(input())
s=[]
for _ in range(n):
  s.append(''.join(sorted([i for i in input()])))
s=Counter(s)
ans=0
for i in Counter(s).values():
  ans+=i*(i-1)//2
print(ans)
### BUGGY CODE ###

from itertools import combinations_with_replacement
# n個の数列、1~mの中で数列を作る
n, m, q = map(int, input().split())

comb = combinations_with_replacement(range(1, m + 1), n)
abcd = [list(map(int, input().split())) for _ in [0] * q]

ans = 0
for A in comb:
    cnt = 0
    for i in range(q):
        a, b, c, d = abcd[i][0], abcd[i][1], abcd[i][2], abcd[i][3]
        if A[b - 1] - A[a - 1] == c:
            cnt += d
    ans = max(ans, cnt)

print(ans)


### FIXED CODE ###

from itertools import combinations_with_replacement
# n個の数列、1~mの中で数列を作る
# 2<=n<=10
# 1<=m<=10
n, m, q = map(int, input().split())

comb = combinations_with_replacement(range(1, m + 1), n)
abcd = [list(map(int, input().split())) for _ in [0] * q]

ans = 0
for A in comb:
    cnt = 0
    for a,b,c,d in abcd:
        if A[b - 1] - A[a - 1] == c:
            cnt += d
    ans = max(ans, cnt)

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

N = int(input())
s = [list(input()) for _ in range(N)]
s_sort = [sorted(n) for n in s]
cnt = 0
cnt_list = []
for i in range(N):
  if cnt_list.count(s_sort[i]) == 1:
    pass
  else:
    count = s_sort.count(s_sort[i])
    cnt_list.append(s_sort[i])
    if count == 1:
      pass
    elif count > 1:
      cnt += int(count*(count-1)/2)
print(cnt)

### FIXED CODE ###

N = int(input())
s_sort = [''.join(sorted(input())) for _ in range(N)]
dic = {}
ans = 0
for i in s_sort:
  if i not in dic:
    dic[i] = 0
  else:
    dic[i] += 1
    ans += dic[i]
print(ans)
### BUGGY CODE ###

class LinkedList(object):
    def __init__(self):
        self.first = None
        self.last = None

    def insert(self, key):
        node = {'key':key, 'next':None, 'prev':None}
        if not self.first:
            self.first = self.last = node
        else:
            node['next'] = self.first
            self.first['prev'] = node
            self.first = node

    def delete(self, key):
        node = self.first
        if self.first['key'] == key:
            self.deleteFirst()
            return
        while node['next']:
            if node['key'] == key:
                node['prev']['next'] = node['next']
                node['next']['prev'] = node['prev']
                return
            node = node['next']
        if self.last['key'] == key:
            self.deleteLast()

    def deleteFirst(self):
        if self.first == self.last:
            self.first = self.last = None
        else:
            self.first['next']['prev'] = None
            self.first = self.first['next']

    def deleteLast(self):
        if self.first == self.last:
            self.first = self.last = None
        else:
            self.last['prev']['next'] = None
            self.last = self.last['prev']

    def show(self):
        if not self.first:
            print('')
            return
        node = self.first
        res = [node['key']]
        while node['next']:
            node = node['next']
            res.append(node['key'])
        print(' '.join(res))

def run():
    n = int(input())
    linked_list = LinkedList()
    for _ in range(n):
        order = [o.strip() for o in input().split()]
        if order[0] == 'insert':
            linked_list.insert(order[1])
        elif order[0] == 'delete':
            linked_list.delete(order[1])
        elif order[0] == 'deleteFirst':
            linked_list.deleteFirst()
        elif order[0] == 'deleteLast':
            linked_list.deleteLast()
    linked_list.show()

if __name__ == '__main__':
    run()




### FIXED CODE ###

from collections import deque

def run():
    n = int(input())
    dq = deque()
    for _ in range(n):
        order = input()
        if order[0] == 'i':
            dq.appendleft(order[7:])
        elif order[6] == ' ':
            key = order.split()[1]
            if not key in dq:
                continue
            for i in range(len(dq)):
                if dq[i] == key:
                    dq.remove(key)
                    break
        elif order[6] == 'F':
            dq.popleft()
        elif order[6] == 'L':
            dq.pop()

    print(' '.join(dq))

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

N,M = map(int,input().split())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
modulo = 10**9+7

x,y = 0,0
for i in range(N):
    for j in range(i+1,N):
        x += X[j]-X[i]
for i in range(M):
    for j in range(i+1,M):
        y += Y[j]-Y[i]

print(x*y%modulo)

### FIXED CODE ###

N,M = map(int,input().split())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
modulo = 10**9+7

x,y = 0,0
for i in range(N):
    x += X[i]*i - X[i]*(N-i-1)
for i in range(M):
    y += Y[i]*i - Y[i]*(M-i-1)

print(x*y%modulo)
### BUGGY CODE ###

from math import gcd
from functools import reduce
n = int(input())
a = list(map(int, input().split()))

tmp = [set() for _ in range(10**6+1)]
for i in range(2, int(10**6//(0.5))+1):
    for j in range(i, 10**6+1, i):
        tmp[j].add(i)


flag = False
for i in range(n-1):
    if len(tmp[a[i]] & tmp[max(a)]) > 0:
        flag = True
        break

if flag == False:
    print("pairwise coprime")
else:
    if reduce(gcd, a) == 1:
        print("setwise coprime")
    else:
        print("not coprime")

### FIXED CODE ###

from math import gcd
from functools import reduce
n = int(input())
a = list(map(int, input().split()))

# sieve[n]は、その数を最初にふるいに落とした数を格納
def prime_factor_table(n):
    # sieveとはふるいの意味
    sieve = [i for i in range(n+1)]
    # n以下の整数を最初にふるい落とす数(√n以下に必ず存在)を求める.
    for i in range(2, int(n**0.5)+1):
        if sieve[i] == i:
            for j in range(2*i, n+1, i):
                if sieve[j] == j:
                    sieve[j] = i
    return sieve

sieve = prime_factor_table(10**6+1)

def prime_factor(n):
    # 素数は英語でprime number
    prime = set()
    while n > 1:
        prime.add(sieve[n])
        n //= sieve[n]
    return prime

for i, v in enumerate(a):
    if i == 0:
        tmp = prime_factor(v)
    else:
        prime = prime_factor(v)
        for j in prime:
            if j in tmp:
                if reduce(gcd, a) == 1:
                    print("setwise coprime")
                    exit()
                else:
                    print("not coprime")
                    exit()
            tmp.add(j)
print("pairwise coprime")
### BUGGY CODE ###

n,a,b=(int(x) for x in input().split())
mod=1000000007
n1=int(n/2)
list=[1]
for i in range(n1):
	k=list[i]*(n-i)/(i+1)
	k%=mod
	list.append(k)
su=sum(list)%mod
su*=2
if n%2==0:
	su-=list[n1]
if 2*a>n:
	a=n-a
if 2*b>n:
	b=n-b
su-=list[a]
su-=list[b]
su-=1
print(int(su%mod))

### FIXED CODE ###

n,a,b = map(int, input().split())
mod = 10**9+7

def minus(n,k):
    x,y =1,1
    for i in range(k):
        x=x*(n-i)%mod
        y=y*(k-i)%mod
    return x*pow(y, mod-2, mod)%mod

ans = pow(2,n,mod)-1-minus(n,a)-minus(n,b)
while ans<0:
    ans+=mod
print(ans)
### BUGGY CODE ###

s = list(map(int,list(input())))
n = len(s)

t = [0]*(n + 1)
mod = [0]*2019
mod[0] = 1
cnt = 0
for i in reversed(range(n)):
    t[i] = t[i+1] + s[i]*10**(n-i-1)
    mod[t[i]%2019] += 1
for m in mod:
    cnt += m*(m-1)//2
print(cnt)

### FIXED CODE ###

s = input()[::-1]
n = len(s)

mod = [0]*2019
pre = 0
mod[pre] = 1
x = 1
for i in range(n):
    pre += int(s[i])*x
    pre %= 2019
    mod[pre] += 1
    x *= 10
    x %=2019
print(sum([m*(m-1)//2 for m in mod]))
### BUGGY CODE ###

D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

def solve():
    ans = []
    N = 26
    for _ in S:
        nx = 0
        res = -10**18
        for i in range(N):
            ans.append(i)
            r = calc(ans)
            ans.pop()
            if res < r:
                nx = i
                res = r
        ans.append(nx)

    return ans

def calc(ans):
    N = 26
    L = [0] * N
    res = 0

    for d, t in enumerate(map(lambda a: a - 1, ans), start=1):
        L[t] = d
        res += S[d - 1][t]
        for c, l in zip(C, L):
            res -= c * (d - l)

    return res

print(*solve(), sep='\n')


### FIXED CODE ###

D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

for A in S:
    print(A.index(max(A)) + 1)
### BUGGY CODE ###

A, B, Q = map(int, input().split())
shrine = []
temple = []
for i in range(A):
    shrine.append(int(input()))
for i in range(B):
    temple.append(int(input()))

for i in range(Q):
    pos = int(input())
    sh = [[shrine[i], abs(pos - shrine[i])] for i in range(A)]
    tem = [[temple[i], abs(pos - temple[i])] for i in range(B)]
    sh.sort(key = lambda x: x[1])
    tem.sort(key = lambda x: x[1])
    l1 = sh[0][1]
    npos = sh[0][0]
    ntem = [abs(npos - temple[i]) for i in range(B)]
    ntem.sort()
    l1 += ntem[0]

    l2 = tem[0][1]
    npos = tem[0][0]
    nsh = [abs(npos - shrine[i]) for i in range(A)]
    nsh.sort()
    l2 += nsh[0]
    print(min([l1, l2]))

### FIXED CODE ###

import bisect
A, B, Q = map(int, input().split())
INF = 10**18
shrine = [-INF] + [int(input()) for i in range(A)] + [INF]
temple = [-INF] + [int(input()) for i in range(B)] + [INF]

for i in range(Q):
    pos = int(input())
    b,d = bisect.bisect_right(shrine, pos), bisect.bisect_right(temple, pos)
    res = INF
    for S in [shrine[b-1], shrine[b]]:
        for T in [temple[d-1], temple[d]]:
            d1, d2 = abs(S-pos)+abs(T-S), abs(T-pos)+abs(S-T)
            res = min(res, d1, d2)
    print(res)