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

#in1 = '4 5 8'
#in2 = ['1 1', '1 4', '1 5', '2 3', '3 1', '3 2', '3 4', '4 4']
#in1 = '10 10 20'
#in2 = ['1 1', '1 4', '1 9', '2 5', '3 10', '4 2', '4 7', '5 9', '6 4', '6 6', '6 7', '7 1', '7 3', '7 7', '8 1', '8 5', '8 10', '9 2', '10 4', '10 9']
#in1 = '1000000000 1000000000 0'
#h, w, n = map(int, in1.split())
h, w, n = map(int, input().split())

"""
10010
00000
00000
00000
"""

idx1 = 0
ab = [[0 for i in range(2)] for j in range(n)]

black_cnt = [0] * 10
black_cnt[0] = (h - 2) * (w - 2)

if n != 0:
    while idx1 < n:
        x = input().split()
        #x = in2[idx1].split()
        ab[idx1] = [int(x[0]), int(x[1])]
        idx1 += 1

    for idx1 in range(len(ab)):
        if ab[idx1][0] < 3:
            sr = 0
        else:
            sr = ab[idx1][0] - 3
        if ab[idx1][0] > h - 2:
            lr = h - 2
        else:
            lr = ab[idx1][0]

        if ab[idx1][1] < 3:
            sc = 0
        else:
            sc = ab[idx1][1] - 3
        if ab[idx1][1] > w - 2:
            lc = w - 2
        else:
            lc = ab[idx1][1]

        #print('s_Row:{} l_Row:{} s_Col:{} l_Col:{}'.format(sr, lr, sc, lc))
        for nowRow in range(sr, lr):
            for nowCol in range(sc, lc):
                #print('nowRow:{} nowCol:{}'.format(nowRow, nowCol))
                w_black = 0
                for idx2 in range(idx1):
                    if nowRow < ab[idx2][0] <= nowRow + 3 and nowCol < ab[idx2][1] <= nowCol + 3:
                        w_black += 1
                black_cnt[w_black]     -= 1
                black_cnt[w_black + 1] += 1
                #print(black_cnt)

for idx1 in range(len(black_cnt)):
    print(black_cnt[idx1])


### FIXED CODE ###

#in1 = '4 5 8'
#in2 = ['1 1', '1 4', '1 5', '2 3', '3 1', '3 2', '3 4', '4 4']
#in1 = '10 10 20'
#in2 = ['1 1', '1 4', '1 9', '2 5', '3 10', '4 2', '4 7', '5 9', '6 4', '6 6', '6 7', '7 1', '7 3', '7 7', '8 1', '8 5', '8 10', '9 2', '10 4', '10 9']
#in1 = '1000000000 1000000000 0'
#h, w, n = map(int, in1.split())
h, w, n = map(int, input().split())

idx1 = 0
ab = [[0 for i in range(2)] for j in range(n)]

black_cnt = [0] * 10
black_cnt[0] = (h - 2) * (w - 2)

if n != 0:
    while idx1 < n:
        x = input().split()
        #x = in2[idx1].split()
        ab[idx1] = [int(x[0]), int(x[1])]
        idx1 += 1

    myDict = {}
    for abitem in ab:
        if abitem[0] < 3:
            sr = 0
        else:
            sr = abitem[0] - 3
        if abitem[0] > h - 3:
            lr = h - 2
        else:
            lr = abitem[0]
        if abitem[1] < 3:
            sc = 0
        else:
            sc = abitem[1] - 3
        if abitem[1] > w - 3:
            lc = w - 2
        else:
            lc = abitem[1]

        for nowRow in range(sr, lr):
            for nowCol in range(sc, lc):
                key = str(nowRow) + ',' + str(nowCol)
                if key in myDict:
                    myDict[key] += 1
                else:
                    myDict[key] = 1

    for bcnt in myDict.values():
        black_cnt[bcnt] += 1
        black_cnt[0]    -= 1

for item in black_cnt:
    print(item)
### BUGGY CODE ###

import numpy as np

N=int(input())
A=np.array(list(map(int,input().split())))
'''
以下、方針
・Aから、各要素の出現回数を取得する。
・出現回数から、組み合わせを計算する。
'''
uni,cou=np.unique(A,return_counts=True)
# print(uni)
# print(cou)
com=[]
for i in range(len(cou)):
    nforc=cou[i]
    c=nforc*(nforc-1)//2
    com.append(c)
# print(com)
totalcombination=sum(com)

'''
以下方針
・Aから数字を取得
・その数字に対応する組み合わせを減らす。
・その数字の出現回数を1減らした状態の組み合わせの数を足す。
'''
dic={}
for num in uni:
    dic.setdefault(num)

#print(dic)

for j in range (N):
    n=A[j] #nはAの数列の数字
    if dic[n]==None:
        f=np.where(uni==n)[0][0]
        t=com[f]
        nfore=cou[f]
        e=(nfore-1)*(nfore-2)//2
        a=totalcombination-t+e
        dic[n]=a
        print(a)
    else:
        print(dic[n])

### FIXED CODE ###

import numpy as np

N=int(input())
A=np.array(list(map(int,input().split())))
'''
以下、方針
・Aから、各要素の出現回数を取得する。
・出現回数から、組み合わせを計算する。
'''
uni,cou=np.unique(A,return_counts=True)

# print(uni)
# print(cou)
dic0={}
dic1={}
dic={} #回答用

com=[]
for i in range(len(cou)):
    c=cou[i]*(cou[i]-1)//2
    dic0[uni[i]]=cou[i]
    dic1[uni[i]]=c
    com.append(c)
    dic.setdefault(uni[i])

# print(com)
totalcombination=sum(com)

# print(com)
# print(dic1)

'''
以下方針
・Aから数字を取得
・その数字に対応する組み合わせを減らす。
・その数字の出現回数を1減らした状態の組み合わせの数を足す。
'''

for j in range (N):
    n=A[j] #nはAの数列の数字
    if dic[n]==None:
        e=(dic0[n]-1)*(dic0[n]-2)//2
        t=totalcombination-dic1[n]+e
        dic[n]=t
        print(t)
    else:
        print(dic[n])
### BUGGY CODE ###

N, K = map(int, input().split())
A = [int(s) for s in input().split()]

a = [0] * N
for k in range(K):
    for i in range(N):
        a[max(0, i - A[i])] += 1
        if N - 1 >= (A[i] + i + 1):
            a[A[i] + i + 1] -= 1

    if a[0] == N:
        A = [N] * N
        break
    for j in range(N):
        A[j] = A[j - 1] if j > 0 else 0
        A[j] += a[j]
        a[j] = 0
    # print("k=", k, A)


for i in range(N):
    print(A[i], end="")
    if i < N - 1:
        print(" ", end="")
print()


### FIXED CODE ###

N, K = map(int, input().split())
A = [int(s) for s in input().split()]

a = [0] * N
for k in range(K):
    for i in range(N):
        a[max(0, i - A[i])] += 1
        if N - 1 >= (A[i] + i + 1):
            a[A[i] + i + 1] -= 1

    if a[0] == N:
        A = [N] * N
        break
    for j in range(N):
        A[j] = A[j - 1] if j > 0 else 0
        A[j] += a[j]
        a[j] = 0
    # print("k=", k, A)


for i in range(N):
    print(A[i], end="")
    if i < N - 1:
        print(" ", end="")
print()
### BUGGY CODE ###

res = {}
for i in range(-1000, 1000):
    for j in range(-1000, 1000):
        ans = i ** 5 - j ** 5
        res[ans] = (i, j)
n = int(input())
print(res[n][0], res[n][1])


### FIXED CODE ###

res = {}
for i in range(-500, 500):
    for j in range(-500, 500):
        ans = i ** 5 - j ** 5
        res[ans] = (i, j)
n = int(input())
print(res[n][0], res[n][1])
### BUGGY CODE ###

N = int(input())
L = []
for i in range(N):
    L.append(str(input()))

list_val = list(set(L))
list_val.sort()
list_size = []
for i in list_val:
    list_size.append(L.count(i))

max_size = max(list_size)

while max(list_size) == max_size:
    max_idx = list_size.index(max_size)
    print(list_val[max_idx])
    list_size[max_idx] = 0


### FIXED CODE ###

import collections

N = int(input())

s = [input() for i in range(N)]

c = collections.Counter(s)
max_n = max(c.values())

ans = []
for key, val in c.items():
  if val == max_n:
    ans.append(key)
print("\n".join(sorted(list(set(ans)))))
### BUGGY CODE ###

S=input()
l = len(S)
S_list = [S[i] for i in range(l)]
ans =0
while True:
    l = len(S_list)
    if l<2:
        break
    check_dif = False
    for i in range(l-1):
        if S_list[i] != S_list[i+1]:
            S_list.pop(i)
            S_list.pop(i)
            check_dif = True
            break
    if check_dif:
        ans+=2
print(ans)

### FIXED CODE ###

S=input()
num_one=S.count('1')
num_zero=S.count('0')
ans = 2*min(num_one,num_zero)
print(ans)
### BUGGY CODE ###

from collections import deque
H,W = map(int, input().split())
A = 0
dp = [None] * H
mat = deque()
for h in range(H):
    s = list(input())
    for w, x in zip(range(W), s):
        if x == "#":
            mat.append((h, w, 0))
            s[w] = 1
        else:
            s[w] = 0
    dp[h] = s

while len(mat):
    h, w, cnt = mat.popleft()

    for t, h, w, cnt in ((h > 0, h - 1, w, cnt),(h < H-1, h + 1, w, cnt),(w > 0, h , w - 1, cnt),(w < W-1, h , w + 1, cnt)):
        if t and dp[h][w] == 0:
            mat.append((h, w, cnt+1))
            dp[h][w] = 1

print(cnt)


### FIXED CODE ###

from collections import deque
H,W = map(int, input().split())
A = 0
dp = [None] * H
mat = [None] * (H*W)
matS = matE = 0
for h in range(H):
    s = list(input())
    for w, x in zip(range(W), s):
        if x == "#":
            mat[matE] = (h, w, 0)
            matE+=1
    dp[h] = s

def search(dp, mat, nH, nW, cnt):
    global matE
    if dp[nH][nW] == ".":
        mat[matE] = (nH, nW, cnt+1)
        matE+=1
        dp[nH][nW] = "#"

while matS < matE:
    h, w, cnt = mat[matS]
    matS += 1

    if h > 0:
        search(dp, mat, h - 1, w, cnt)
    if h < H-1:
        search(dp, mat, h + 1, w, cnt)
    if w > 0:
        search(dp, mat, h , w - 1, cnt)
    if w < W-1:
        search(dp, mat, h , w + 1, cnt)

print(cnt)
### BUGGY CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(100000000)
def main():
    #入力
    N, Q = (int(_) for _ in input().split())
    edge = [[int(_) for _ in input().split()] for __ in range(N-1)]
    query = [[int(_) for _ in input().split()] for __ in range(Q)]

    tree = defaultdict(list)
    for a, b in edge:
        tree[a].append(b)
        tree[b].append(a)

    cc = [0] * (N+1)
    seen = [False] * (N+1)

    for p, x in query:
        cc[p] += x

    def dfs(x):
        for p in tree[x]:
            if seen[p] == False:
                seen[p] = True
                cc[p] += cc[x]
                dfs(p)
        return

    seen[1] = True
    dfs(1)

    print(*cc[1:])
    return

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline #for input speed
sys.setrecursionlimit(10**6) #for deep recursion
n, q = map(int, input().split())

tree_index = [[] for _ in range(n)]
for i in range(n-1):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  tree_index[a].append(b) # a<bとは限らないため、双方向にする
  tree_index[b].append(a)
ans = [0] * n
for i in range(q):
  p, x = map(int, input().split())
  ans[p-1] += x
def dfs(cur, par):
    for chl in tree_index[cur]:
      if chl == par: #parentとchildが等しい時はスキップ
        continue
      ans[chl] += ans[cur] 
      dfs(chl, cur)
dfs(0, -1)
print(*ans)
### BUGGY CODE ###

from copy import deepcopy

def getval():
    r,c,k = map(int,input().split())
    item = [[0 for i in range(c)] for i in range(r)]
    for i in range(k):
        ri,ci,vi = map(int,input().split())
        item[ri-1][ci-1] = vi
    return r,c,k,item

def main(r,c,k,item):
    #DP containing the information of max value given k items picked in i,j
    prev = [[0 for i in range(4)]]
    inititem = item[0][0]
    prev[0] = [0,inititem,inititem,inititem]
    for i in range(1,r):
        initval = prev[i-1][3]
        temp = []
        cur = item[i][0]
        for j in range(4):
            temp.append(initval)
        for j in range(1,4):
            temp[j] += cur
        prev.append(temp)

    for j in range(1,c):
        init = deepcopy(prev[0])
        for i in range(1,4):
            init[i] = prev[0][i]
            if prev[0][i-1]+item[0][j]>init[i]:
                init[i] = prev[0][i-1]+item[0][j]
        curcol = [init]
        for i in range(1,r):
            cur = item[i][j]
            left = curcol[-1][3]
            down = prev[i]
            temp = [left]
            if down[0]>temp[0]:
                temp[0] = down[0]
            for k in range(1,4):
                c = down[k]
                if left+cur>c:
                    c = left+cur 
                if down[k-1]+cur>c:
                    c = down[k-1]+cur
                temp.append(c)
            curcol.append(temp)
        prev = deepcopy(curcol)
            
    print(max(prev[-1]))
    #print(prev)
           
if __name__=="__main__":
    r,c,k,item = getval()
    main(r,c,k,item) 

### FIXED CODE ###

from copy import deepcopy

def getval():
    r,c,k = map(int,input().split())
    item = [[0 for i in range(c)] for i in range(r)]
    for i in range(k):
        ri,ci,vi = map(int,input().split())
        item[ri-1][ci-1] = vi
    return r,c,k,item

def main(r,c,k,item):
    #DP containing the information of max value given k items picked in i,j
    prev = [[0 for i in range(4)]]
    inititem = item[0][0]
    prev[0] = [0,inititem,inititem,inititem]
    for i in range(1,r):
        initval = prev[i-1][3]
        temp = []
        cur = item[i][0]
        for j in range(4):
            temp.append(initval)
        for j in range(1,4):
            temp[j] += cur
        prev.append(temp)

    for j in range(1,c):
        init = deepcopy(prev[0])
        for i in range(1,4):
            init[i] = max(prev[0][i],prev[0][i-1]+item[0][j])
        curcol = [init]
        for i in range(1,r):
            cur = item[i][j]
            left = curcol[-1]
            down = prev[i]
            temp = [max(left[3],down[0])]
            for k in range(1,4):
                temp.append(max(max(left[3],down[k-1])+cur,down[k]))
            curcol.append(temp)
        prev = curcol
            
    print(max(prev[-1]))
           
if __name__=="__main__":
    r,c,k,item = getval()
    main(r,c,k,item)
### BUGGY CODE ###

from functools import lru_cache
import sys
sys.setrecursionlimit(1000000)

@lru_cache(maxsize=None)
def f(a, b):
    if a < A or b < B: return 0
    if a == A and b == B: return 1
    return (f(a-1, b) * b + f(a, b-1) * a - f(a-1, b-1) * (a - 1) * (b - 1)) % P

P = 998244353
A, B, C, D = map(int, input().split())
print(f(C, D))

### FIXED CODE ###

P = 998244353
A, B, C, D = map(int, input().split())
X = [[0] * 3001 for _ in range(3001)]
for a in range(3001):
    for b in range(3001):
        if a < A or b < B: continue
        if a == A and b == B:
            X[a][b] = 1
        elif a == A:
            X[a][b] = X[a][b-1] * a % P
        elif b == B:
            X[a][b] = X[a-1][b] * b % P
        else:
            X[a][b] = (X[a-1][b] * b + X[a][b-1] * a - X[a-1][b-1] * (a-1) * (b-1)) % P

print(X[C][D])
### BUGGY CODE ###

s = input()
table = [0 for i in range(len(s)+1)]
i = 1
for c in s[::-1]:
    table[i] = ((10 ** (i-1)) * int(c) + table[i-1]) % 2019
    i += 1

ans =  len(s) + 1 - len(set(table))
print(ans)

### FIXED CODE ###

s = input()
table = [0 for i in range(2019)]
table[0] = 1
num = 0
d = 1
for c in s[::-1]:
    num += (int(c) * d)
    num %= 2019
    d *= 10
    d %= 2019
    table[num] += 1

ans = 0
for cnt in table:
    ans += cnt * (cnt - 1) // 2

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

import numpy as np

N, M = map(int, input().split())

a = np.ones(N, dtype=int)
for m in range(M):
  L, R = map(int, input().split())
  b = np.zeros(N, dtype=int)
  b[L-1:R] = 1
  a = a * b

print(np.sum(a))


### FIXED CODE ###

N, M = map(int, input().split())

gates = [[1, N]]

for m in range(M):
  L, R = map(int, input().split())
  updated = []
  for gate in gates:
    if L <= gate[0]:
      if gate[0] <= R:
        updated.append([gate[0], min(gate[1], R)])
    else:
      if L <= gate[1]:
        updated.append([L, min(gate[1], R)])
  gates = updated


print(sum([g[1] - g[0] + 1 for g in gates]))
### BUGGY CODE ###

H, W = map(int, input().split())
S_list = [None] * H

for h in range(H):
    S_list[h] = list(input())


l_list = [[0] * W for _ in range(H)]
r_list = [[0] * W for _ in range(H)]
d_list = [[0] * W for _ in range(H)]
u_list = [[0] * W for _ in range(H)]
for h in range(H):
    #left
    for w in range(W):
        if S_list[h][w] == '#':
            continue
        elif w == 0:
            l_list[h][w] = 1
        else:
            l_list[h][w] = l_list[h][w - 1] + 1
    #right
    for w in reversed(range(W)):
        if S_list[h][w] == '#':
            continue
        elif w == W - 1:
            r_list[h][w] = 1
        else:
            r_list[h][w] = r_list[h][w + 1] + 1

for w in range(W):
    #up
    for h in range(H):
        if S_list[h][w] == '#':
            continue
        elif h == 0:
            u_list[h][w] = 1
        else:
            u_list[h][w] = u_list[h - 1][w] + 1
    #down
    for h in reversed(range(H)):
        if S_list[h][w] == '#':
            continue
        elif h == H - 1:
            d_list[h][w] = 1
        else:
            d_list[h][w] = d_list[h + 1][w] + 1


max_right = 0
for h in range(H):
    for w in range(W):
        rights = l_list[h][w] + r_list[h][w] + u_list[h][w] + d_list[h][w] - 3
        max_right = max(max_right, rights)

print(max_right)


### FIXED CODE ###

#ref. https://atcoder.jp/contests/abc129/submissions/5906191
import numpy as np
import sys

def main():
    sin = sys.stdin.buffer
    H, W = map(int, sin.readline().split())
    grid = np.frombuffer(sin.read(H * (W + 1)), dtype="B") == ord(".")
    grid = grid.reshape((H, W + 1))[:, :-1]

    L = np.empty((H, W), dtype="i4")
    R = np.empty((H, W), dtype="i4")
    T = np.empty((H, W), dtype="i4")
    B = np.empty((H, W), dtype="i4")

    T[0] = grid[0]
    for i in range(1, H):
        T[i] = (T[i - 1] + 1) * grid[i]

    B[-1] = grid[-1]
    for i in range(H - 2, -1, -1):
        B[i] = (B[i + 1] + 1) * grid[i]

    L[:, 0] = grid[:, 0]
    for i in range(1, W):
        L[:, i] = (L[:, i - 1] + 1) * grid[:, i]

    R[:, -1] = grid[:, -1]
    for i in range(W - 2, -1, -1):
        R[:, i] = (R[:, i + 1] + 1) * grid[:, i]

    ans = (T + B + L + R - 3).max()
    print(ans)

main()
### BUGGY CODE ###

S=input().strip()
N=len(S)
q = [S]
while q:
    s = q.pop()
    p = ''
    v = 0
    for i,c in enumerate(s):
        if (p == '0' and c == '1') or (p == '1' and c == '0'):
            q.append(s[:i-1]+s[i+1:])
            v += 1
        p = c
    if v == 0:
        print(N-len(s))
        break

### FIXED CODE ###

from collections import deque
S=input().strip()
N=len(S)

a=[0 if x == '0' else 1 for x in S]

q = deque()
for i in a:
    if q:
        if q[-1] != i:
            q.pop()
        else:
            q.append(i)
    else:
        q.append(i)

print(N-len(q))
### BUGGY CODE ###

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

total = 0
from itertools import combinations as cm
for pair in cm(L, 3):
  a, b, c = pair
  if a < b+c and b < c+a and c < a+b:
    total += 1
print(total)

### FIXED CODE ###

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

counter = 0
for a_pointer in range(len(L)):
    for b_pointer in range(a_pointer+1, len(L)):
        a = L[a_pointer]
        b = L[b_pointer]
        c_left_pointer = max(bisect.bisect_left(L, b - a + 1), b_pointer + 1)
        c_right_pointer = bisect.bisect_right(L, b + a - 1)
        #print(a, b, c_left_pointer, c_right_pointer)
        counter += max(c_right_pointer - c_left_pointer, 0)
        #if c_right_pointer == len(L) and c_right_pointer == len(L):
            #break
print(counter)
### BUGGY CODE ###

x = int(input())
item_num = x // 100

def brute(t):
    for i in range(t+1):
        for j in range(t+1-i):
            for k in range(t+1-i-j):
                for l in range(t+1-i-j-k):
                    for m in range(t+1-i-j-k-l):
                        for n in range(t+1-i-j-k-l-m):
                            total = i + j + k + l + m + n
                            if total == t and (100 * i + 101 * j + 102 * k +  103 * l + 104 * m + 105 * n ) == x:
                                return 1
    return 0

print(brute(item_num))

### FIXED CODE ###

x = int(input())

num = x // 100



dp = ["?"] * (x+1)
dp[0] = "1"

for i in range(1,x+1):
    if i <= 99:
        dp[i] = "0"
    elif i in (100,101,102,103,104,105):
        dp[i] = "1"
    else:
        if "1" in(dp[i-100],dp[i-101],dp[i-102],dp[i-103],dp[i-104],dp[i-105]):
            dp[i] = "1"
        else:
            dp[i] = "0"

            
print(dp[x])
### BUGGY CODE ###

md = 10 ** 9 + 7
s = input()
n = len(s)
dp = [[0, 0, 0, 0] for _ in range(n + 1)]
pre = dp[0]
for i, c in enumerate(s):
    cur = dp[i + 1]
    if c == "A":
        cur[0] = (pre[0] + 3 ** pre[3]) % md
        cur[1:] = pre[1:]
    elif c == "B":
        cur[0] = pre[0]
        cur[1] = (pre[0] + pre[1]) % md
        cur[2:] = pre[2:]
    elif c == "C":
        cur[:2] = pre[:2]
        cur[2] = (pre[1] + pre[2]) % md
        cur[3] = pre[3]
    else:
        cur[0] = (pre[0] * 3 + 3 ** pre[3]) % md
        cur[1] = (pre[1] * 3 + pre[0]) % md
        cur[2] = (pre[2] * 3 + pre[1]) % md
        cur[3] = (pre[3] + 1) % md
    pre = cur
print(dp[-1][-2])


### FIXED CODE ###

md=10**9+7
s=input()
dp=[[0]*4 for _ in range(3)]
for c in s:
    if c=="A":dp[0][0]=(dp[0][0]+1)%md
    if c=="B":
        for j in range(2):dp[1][j]=(dp[1][j]+dp[0][j])%md
    if c=="C":
        for j in range(3):dp[2][j]=(dp[2][j]+dp[1][j])%md
    if c=="?":
        for j in range(3):dp[2][j+1]=(dp[2][j+1]+dp[1][j])%md
        for j in range(2):dp[1][j+1]=(dp[1][j+1]+dp[0][j])%md
        dp[0][1] = (dp[0][1] + 1) % md
ans=0
q=s.count("?")
for j in range(4):
    if q-j<0:break
    ans+=dp[2][j]*pow(3,q-j,md)
    ans%=md
print(ans)
### BUGGY CODE ###

# coding: utf-8
# Your code here!
A,B,Q=map(int,input().split())

def bisearch(target,lis):
    low=0
    high=len(lis)-1
    if lis[0]>target:
        return low-1
    elif lis[-1]<target:
        return high
    
    while lis[low]>target or lis[low+1]<target:
        mid=(low+high)//2
        if lis[mid]<target:
            high=mid
        else:
            low=mid
    return low

def cand(num,lis):
    N=len(lis)-1
    a=max(num,0)
    b=min(num+1,N)
    return [lis[a],lis[b]]

god=[]
for _ in range(A):
    god.append(int(input()))

buddha=[]
for _ in range(B):
    buddha.append(int(input()))

for _ in range(Q):
    q=int(input())
    g_i=(bisearch(q,god))
    b_i=(bisearch(q,buddha))
    G=cand(g_i,god)
    B=cand(b_i,buddha)
    ans=10**18
    ans=min(abs(q-G[0])+abs(G[0]-B[0]),abs(q-B[0])+abs(B[0]-G[0]),abs(q-G[1])+abs(G[1]-B[0]),abs(q-B[0])+abs(B[0]-G[1]),abs(q-G[0])+abs(G[0]-B[1]),abs(q-B[1])+abs(B[1]-G[0]),abs(q-G[1])+abs(G[1]-B[1]),abs(q-B[1])+abs(B[1]-G[1]))
    for g in G:
        for b in B:
            ans=min(ans,abs(q-g)+abs(g-b),abs(q-b)+abs(b-g))
    print(ans)


### FIXED CODE ###

# coding: utf-8
# Your code here!
import bisect

A,B,Q=map(int,input().split())

god=[-10**18]
for _ in range(A):
    god.append(int(input()))
god.append(10**18)

buddha=[-10**18]
for _ in range(B):
    buddha.append(int(input()))
buddha.append(10**18)

#print(god,buddha)
for _ in range(Q):
    q=int(input())
    g_i=bisect.bisect_left(god, q)
    b_i=bisect.bisect_left(buddha, q)
    #print(g_i,b_i)
    
    ans=10**18
    G=[god[g_i-1],god[g_i]]
    B=[buddha[b_i-1],buddha[b_i]]
    for g in G:
        for b in B:
            ans=min(ans,abs(q-g)+abs(g-b),abs(q-b)+abs(b-g))
    print(ans)
### BUGGY CODE ###

import heapq
def SME(start,end):
    A = []
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] == 0:
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * 0.995 + 200 : break
    for i in range(L):
        if ANS[i] == 0 : ANS[i] = min(Whole[:i+1])
    for i in range(L,N):
        if ANS[i] == 0 : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
ANS = [0]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])