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

K,S = map(int,input().split())
num = 0
for i in range(K+1):
  for j in range(K+1) :
    for k in range(K+1):
      total = i +j + k
      if total == S :
        num += 1
print(num)


### FIXED CODE ###

K,S = map(int,input().split())
num = 0
for i in range(K+1):
  for j in range(K+1) :
    k = S - i - j
    if k >= 0 and k <= K :
      num += 1
print(num)
### BUGGY CODE ###

from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]

dx = [1,-1,0,0]

dy = [0,0,1,-1]
B = [[-1 for i in range(W)] for j in range(H)]
qu = deque([])
for i in range(H):
  for j in range(W):
    if A[i][j] == '#':
      B[i][j] = 0
      qu.append((i,j))
      
      
while qu:
  base = qu.popleft()
  for i in range(4):
    if base[0]+dx[i] < 0 or base[0]+dx[i] >=H or base[1]+dy[i] < 0 or base[1]+dy[i] >=W:
      continue
    if B[base[0]+dx[i]][base[1]+dy[i]] == -1:#未訪問
      qu.append((base[0]+dx[i],base[1]+dy[i]))
      B[base[0]+dx[i]][base[1]+dy[i]] = B[base[0]][base[1]] + 1
      
ans = 0
for i in range(H):
  ans = max(ans,max(B[i]))
print(ans)

### FIXED CODE ###

from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]

dx = [1,-1,0,0]

dy = [0,0,1,-1]
B = [[-1 for i in range(W)] for j in range(H)]
qu = deque([])
for i in range(H):
  for j in range(W):
    if A[i][j] == '#':
      B[i][j] = 0
      qu.append((i,j))
      
      
while qu:
  base = qu.popleft()
  for i in range(4):
    if base[0]+dx[i] < 0 or base[0]+dx[i] >=H or base[1]+dy[i] < 0 or base[1]+dy[i] >=W:
      continue
    if B[base[0]+dx[i]][base[1]+dy[i]] == -1:#未訪問
      qu.append((base[0]+dx[i],base[1]+dy[i]))
      B[base[0]+dx[i]][base[1]+dy[i]] = B[base[0]][base[1]] + 1
      
ans = 0
for i in range(H):
  ans = max(ans,max(B[i]))
print(ans)
### BUGGY CODE ###

import bisect
def find_lt(a, x):
    'Find rightmost index less than x'
    i = bisect.bisect_left(a, x)
    if i:
        return i-1
    # raise ValueError
    return -1

N=int(input().strip())
L=list(map(int,input().strip().split()))
L.sort()

count=0
for i,a in enumerate(L):
    for  j,b in enumerate(L[i+1:]):
        minInd=i+1+j+1
        ind=find_lt(L[minInd:], a+b)
        count+=ind+1
print(count)

### FIXED CODE ###

import bisect
 
N = int(input())
L = list(map(int, input().split()))
L.sort()
 
c = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    c += bisect.bisect_right(L, L[i]+L[j]-1) - j - 1
 
 
print(c)
### BUGGY CODE ###

import numpy as np

memo = {}
def dp(v, d, c):
    if memo.get((v, d), False):
        return None

    memo[(v, d)] = True
    if d == 0:
        res[v-1] = c
        return None

    dp(v, d-1, c)
    for e in dic[v-1]:
        dp(e, d-1, c)


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

dic = [[] for _ in range(N)]


for m in range(M):
    a, b = tuple(map(int, input().split(' ')))
    dic[a-1].append(b)
    dic[b-1].append(a)

Q = int(input())

vdc = [None]*Q

for q in range(Q):
    vdc[q] = tuple(map(int, input().split(' ')))

res = np.zeros(N)

for q in range(Q-1, -1, -1):
    v, d, c = vdc[q]
    dp(v, d, c)


for i in range(N):
    print(int(res[i]))


### FIXED CODE ###

import numpy as np

def dp(v, d, c):
    if memo[v-1][d]:
        return

    memo[v-1][d] = True
    if d == 0:
        res[v-1] = str(c)
        return

    dp(v, d-1, c)
    for e in dic[v-1]:
        dp(e, d-1, c)


N, M = [int(e) for e in input().split(' ')]

dic = [[] for _ in range(N)]
memo = [[False]*11 for _ in range(N)]

for m in range(M):
    a, b = [int(e) for e in input().split(' ')]
    dic[a-1].append(b)
    dic[b-1].append(a)

Q = int(input())


vdc = [[int(e) for e in input().split(' ')] for _ in range(Q)]

res = ['0']*N

[dp(v, d, c) for v, d, c in vdc[::-1]]


print('\n'.join(res))
### BUGGY CODE ###

# coding=utf-8

class Node:
    def __init__(self, idx, degree, children=None):
        self.id = idx
        self.parent = -1 #??????
        self.depth = 0 #??????
        self.type = None #??????
        self.children = children

n = int(input())
data = [list(map(int, input().split())) for x in range(n)]
node_list = []

for data_row in data:
    idx, degree, *children = data_row
    node = Node(idx, degree, children)
    node_list.append(node)

### set parent & type ###
for i, node in enumerate(node_list):
    if node.children:
        node.type = "internal node"
        for child in node.children:
            node_list[child].parent = i
    else:
        node.type = "leaf"

### calc depth ###
for i, node in enumerate(node_list):
    depth = 0
    parent = node.parent
    #?????\???type
    if parent == -1:
        node.type = "root"
    while parent != -1:
        parent = node_list[parent].parent
        depth += 1
    node.depth = depth

for node in node_list:
    print("node {}: parent = {}, depth = {}, {}, {}".format(node.id, node.parent, node.depth, node.type, node.children))

### FIXED CODE ###

# coding=utf-8

class Node:
    def __init__(self, idx, degree, children=None):
        self.id = idx
        self.parent = -1 #??????
        self.depth = 0 #??????
        self.type = None #??????
        self.children = children

n = int(input())
data = [list(map(int, input().split())) for x in range(n)]
node_list = [None for i in range(n)]

for data_row in data:
    idx, degree, *children = data_row
    node = Node(idx, degree, children)
    node_list[idx] = node

### set parent & type ###
for node in node_list:
    i = node.id
    if node.children:
        node.type = "internal node"
        for child in node.children:
            node_list[child].parent = i
    else:
        node.type = "leaf"

### calc depth ###
for i, node in enumerate(node_list):
    depth = 0
    parent = node.parent
    #?????\???type
    if parent == -1:
        node.type = "root"
    while parent != -1:
        parent = node_list[parent].parent
        depth += 1
    node.depth = depth

for node in node_list:
    print("node {}: parent = {}, depth = {}, {}, {}".format(node.id, node.parent, node.depth, node.type, node.children))
### BUGGY CODE ###


N = int(input())

# (締切, 時間)
DeadlineCost = [] * N

for i in range(N):
    c, d = map(int, input().split())
    DeadlineCost.append((d, c))

DeadlineCost.sort()
#print(DeadlineCost)

t = 0
for i in range(N):
    (d, c) = DeadlineCost.pop(0)

    t += c
    if t > d:
        print('No')
        exit()

print('Yes')

### FIXED CODE ###


N = int(input())

# (締切, 時間)
DeadlineCost = [] * N

for i in range(N):
    c, d = map(int, input().split())
    DeadlineCost.append((d, c))

DeadlineCost.sort(reverse=True)
#print(DeadlineCost)

t = 0
for i in range(N):
    (d, c) = DeadlineCost.pop()

    t += c
    if t > d:
        print('No')
        exit()

print('Yes')
### BUGGY CODE ###

# -*- coding: utf-8 -*-
n = int(input())
a = input().split()
b = []

for i in range(n):
    if i%2==0:
        b.append(a[i])
    else:
        b.insert(0, a[i])

if n%2==0:
    print(" ".join(b))
else:
    print(" ".join(b[::-1]))


### FIXED CODE ###

# -*- coding: utf-8 -*-
n = int(input())
a = input().split()
b = [a[0], []]
last = b[1]

for i in range(1,n):
    if i%2==0:
        last.append(a[i])
        last.append([])
        last = last[1]
    else:
        b = [a[i],b]

ret = []
for _ in range(n):
    ret.append(b[0])
    b = b[1]

if n%2==0:
    print(" ".join(ret))
else:

    print(" ".join(ret[::-1]))
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
A = list(map(int, readline().split()))
mod = 10 ** 9 + 7


def lcm(X, Y):
    x = X
    y = Y
    if y > x:
        x, y = y, x
    while x % y != 0:
        x, y = y, x % y
    return X * Y // y


cnt = 0
ans = 0
LCM = 1
for i in range(n):
    Q = lcm(LCM, A[i])
    cnt *= Q // LCM
    LCM = Q
    cnt += Q // A[i]
print(cnt % mod)


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
A = list(map(int, readline().split()))
mod = 10 ** 9 + 7


def lcm(X, Y):
    x = X
    y = Y
    if y > x:
        x, y = y, x
    while x % y != 0:
        x, y = y, x % y
    return X * Y // y


cnt = 0
ans = 0
LCM = 1
for i in range(n):
    Q = lcm(LCM, A[i])
    cnt *= Q // LCM
    LCM = Q
    cnt += Q // A[i]
print(cnt % mod)
### BUGGY CODE ###

import copy
R, C, K = map(int,input().split())
i = [list(map(int,input().split())) for k in range(K)]
dp0 = [[0] * (C+1) for r in range(R+1)]
dp1 = copy.deepcopy(dp0)
dp2 = copy.deepcopy(dp0)
dp3 = copy.deepcopy(dp0)
item = copy.deepcopy(dp0)
for k in range(K):
   item[i[k][0]-1][i[k][1]-1] = i[k][2]
for r in range(R):
   for c in range(C):
      dp3[r][c] = max(dp3[r][c], dp2[r][c] + item[r][c])
      dp2[r][c] = max(dp2[r][c], dp1[r][c] + item[r][c])
      dp1[r][c] = max(dp1[r][c], dp0[r][c] + item[r][c])
      dp1[r][c+1] = max(dp1[r][c], dp1[r][c+1])
      dp2[r][c+1] = max(dp2[r][c], dp2[r][c+1])
      dp3[r][c+1] = max(dp3[r][c], dp3[r][c+1])
      dp0[r+1][c] = max(dp0[r+1][c], dp1[r][c])
      dp0[r+1][c] = max(dp0[r+1][c], dp2[r][c])
      dp0[r+1][c] = max(dp0[r+1][c], dp3[r][c])
ans = max(dp0[R-1][C-1], dp1[R-1][C-1])
ans = max(ans, dp3[R-1][C-1])
ans = max(ans, dp2[R-1][C-1])
print(ans)



### FIXED CODE ###

import sys
import copy
R, C, K = map(int, input().split())
item = [[0] * (C + 1) for _ in range(R + 1)]  # dp配列と合わせるために, 0行目, 0列目を追加している.
for s in sys.stdin.readlines():
    r, c, v = map(int, s.split())
    r -= 1
    c -= 1
    item[r][c] = v
    
dp0 = [[0] * (C+1) for r in range(R+1)]
dp1 = [[0] * (C+1) for r in range(R+1)]
dp2 = [[0] * (C+1) for r in range(R+1)]
dp3 = [[0] * (C+1) for r in range(R+1)]

for r in range(R):
   for c in range(C):
      dp3[r][c] = max(dp3[r][c], dp2[r][c] + item[r][c])
      dp2[r][c] = max(dp2[r][c], dp1[r][c] + item[r][c])
      dp1[r][c] = max(dp1[r][c], dp0[r][c] + item[r][c])
      dp1[r][c+1] = max(dp1[r][c], dp1[r][c+1])
      dp2[r][c+1] = max(dp2[r][c], dp2[r][c+1])
      dp3[r][c+1] = max(dp3[r][c], dp3[r][c+1])
      dp0[r+1][c] = max(dp0[r+1][c], dp1[r][c])
      dp0[r+1][c] = max(dp0[r+1][c], dp2[r][c])
      dp0[r+1][c] = max(dp0[r+1][c], dp3[r][c])
ans = max(dp0[R-1][C-1], dp1[R-1][C-1])
ans = max(ans, dp3[R-1][C-1])
ans = max(ans, dp2[R-1][C-1])
print(ans)
### BUGGY CODE ###

h, w, m = map(int, input().split())
target_points = {tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(m)}

row_points = [0] * h
col_points = [0] * w
for row, col in target_points:
    row_points[row] += 1
    col_points[col] += 1

row_max = max(row_points)
col_max = max(col_points)

row_max_indexes = [i for i in range(h) if row_points[i] == row_max]
col_max_indexes = [i for i in range(w) if col_points[i] == col_max]

crossing_points = {(row, col) for row in row_max_indexes for col in col_max_indexes}

print(row_max + col_max - (not (crossing_points - target_points)))


### FIXED CODE ###

h, w, m = map(int, input().split())
target_points = {tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(m)}

row_points = [0] * h
col_points = [0] * w
for row, col in target_points:
    row_points[row] += 1
    col_points[col] += 1

row_max = max(row_points)
col_max = max(col_points)

row_max_indexes = [i for i in range(h) if row_points[i] == row_max]
col_max_indexes = [i for i in range(w) if col_points[i] == col_max]

empty_crossing_exist = False
for row in row_max_indexes:
    for col in col_max_indexes:
        if (row, col) not in target_points:
            empty_crossing_exist = True
            break
    if empty_crossing_exist:
        break

print(row_max + col_max - (not empty_crossing_exist))
### BUGGY CODE ###

import collections
n = int(input())
li = list(map(int,input().split()))
c = collections.Counter(li)
for i in range(n):
  d = c.copy()
  num = li[i]
  d[num] -= 1
  ans = 0
  for v in d.values():
    v = int(v)
    ans += v*(v-1)//2
  print(ans)

### FIXED CODE ###

import collections
n = int(input())
li = list(map(int,input().split()))
c = collections.Counter(li)
d = c.copy()
ans_1 = 0
for v in d.values():
  v = int(v)
  ans_1 += v*(v-1)//2
for k in li:
  print(ans_1 - (c[k]-1))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

class Unionfind:

    __slots__ = ['nodes','size']

    def __init__(self, n):
        self.nodes = list(range(n))
        self.size = [1]*n

    def root(self, x):
        if self.nodes[x] == x:
            return x
        else:
            root_x = self.root(self.nodes[x])
            self.nodes[x] = root_x
            return root_x

    def unite(self, x, y):
        x = self.root(x); y = self.root(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.size[x] += self.size[y]
        self.nodes[y] = x

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

N,K,L = map(int,input().split())

uf1 = Unionfind(N)
uf2 = Unionfind(N)

for _ in range(K):
    p,q = map(int,input().split())
    p -= 1; q -= 1
    uf1.unite(p,q)

for _ in range(L):
    r,s = map(int,input().split())
    r -= 1; s -= 1
    uf2.unite(r,s)

set1 = [set() for _ in range(N)]
set2 = [set() for _ in range(N)]

for node in range(N):
    set1[node] = set1[uf1.root(node)]
    set1[node].add(node)
    set2[node] = set2[uf2.root(node)]
    set2[node].add(node)

for node,s1,s2 in zip(range(N),set1,set2):
    out = len(s1 & s2)
    if node == N-1:
        print(out)
    else:
        print(out,end = " ")

### FIXED CODE ###

import sys
input = sys.stdin.readline

class Unionfind:

    __slots__ = ['nodes','size']

    def __init__(self, n):
        self.nodes = list(range(n))
        self.size = [1]*n

    def root(self, x):
        if self.nodes[x] == x:
            return x
        else:
            root_x = self.root(self.nodes[x])
            self.nodes[x] = root_x
            return root_x

    def unite(self, x, y):
        x = self.root(x); y = self.root(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.size[x] += self.size[y]
        self.nodes[y] = x

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

N,K,L = map(int,input().split())

uf1 = Unionfind(N)
uf2 = Unionfind(N)

for _ in range(K):
    p,q = map(int,input().split())
    p -= 1; q -= 1
    uf1.unite(p,q)

for _ in range(L):
    r,s = map(int,input().split())
    r -= 1; s -= 1
    uf2.unite(r,s)

keys = []
dic = {}

for node in range(N):
    key = (uf1.root(node),uf2.root(node))
    keys.append(key)
    if key in dic:
        dic[key] += 1
    else:
        dic[key] = 1

ans = [str(dic[key]) for key in keys]
print(" ".join(ans))
### BUGGY CODE ###

n = int(input())
a = [] * n

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 = [] * n
ans = 1

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

if a.count(0) > 0:
  ans = 0
else:
  for i in range(n):
    if ans > 10**18:
      break
    else:
      ans *= a[i]

if ans == 0:
  print(ans)
elif ans > 10**18:
  print(-1)
else:
  print(ans)
### BUGGY CODE ###

import sys
from bisect import bisect_left
inpurt = sys.stdin.readline
a, b, q = map(int, input().split())
INF = 10 ** 11
s = [-INF]
s_append = s.append
for i in range(a):
    si = int(input())
    s_append(si)
s_append(INF)
t = [-INF]
t_append = t.append
for i in range(b):
    ti = int(input())
    t_append(ti)
t_append(INF)
x = []
x_append = x.append
for i in range(q):
    xi = int(input())
    x_append(xi)

for xi in x:
    index_s = bisect_left(s, xi)
    s1 = abs(xi - s[index_s - 1])
    s2 = abs(xi - s[index_s])
    index_t = bisect_left(t, xi)
    t1 = abs(xi - t[index_t - 1])
    t2 = abs(xi - t[index_t])
    print(min(max(s1, t1), max(s2, t2), min(s1, t2) * 2 + max(s1, t2), min(s2, t1) * 2 + max(s2, t1)))


### FIXED CODE ###

import sys
from bisect import bisect_left
inpurt = sys.stdin.readline
a, b, q = map(int, input().split())
INF = 10 ** 11
s = [-INF]
s_append = s.append
for i in range(a):
    si = int(input())
    s_append(si)
s_append(INF)
t = [-INF]
t_append = t.append
for i in range(b):
    ti = int(input())
    t_append(ti)
t_append(INF)
x = []
x_append = x.append
for i in range(q):
    xi = int(input())
    x_append(xi)

for xi in x:
    index_s = bisect_left(s, xi)
    s1 = xi - s[index_s - 1]
    s2 = s[index_s] - xi
    index_t = bisect_left(t, xi)
    t1 = xi - t[index_t - 1]
    t2 = t[index_t] -xi
    print(min(max(s1, t1), max(s2, t2), min(s1, t2) * 2 + max(s1, t2), min(s2, t1) * 2 + max(s2, t1)))
### BUGGY CODE ###

def 解():
    sS = input().rstrip()
    iK = int(input())
    iL = len(sS)
    iC = 0
    sAbc = "abcdefghijklmnopqrstuvwxyz"
    for s in sAbc:
        sDic = set()
        indexes = []
        for i in range(iL):
            if sS[i] == s:
                indexes.append(i)
        for i in indexes:
            for j in range(1,iL -i+1):
                sDic.add(sS[i:i+j])
        aS = sorted(list(sDic))
        iLS = len(aS)
        if iC + iLS < iK:
            iC += iLS
            continue
        else:
            print(aS[iK -iC-1])
            exit()
解()


### FIXED CODE ###

def 解():
    sS = input().rstrip()
    dsS = set()
    for s in sS:
        if s not in dsS:
            dsS.add(s)
    iK = int(input())
    iL = len(sS)
    iC = 0
    for s in sorted(list(dsS)):
        sDic = set()
        indexes = []
        for i in range(iL):
            if sS[i] == s :
                if i != 0 and i != iL-1:
                    if sS[i-1] != s or sS[i+1] != s:
                        indexes.append(i)
                else:
                    indexes.append(i)
        if iK < iL :
            for i in indexes:
                for j in range(1,iK+1):
                    if i+j <= iL:
                        sDic.add(sS[i:i+j])
            aS = sorted(list(sDic))
            if iK <= len(aS) :
                print(aS[iK - iC -1])
                exit()
            else:
                iC += len(aS)
        else:
            for i in indexes:
                for j in range(1,iL -i+1):
                    sDic.add(sS[i:i+j])
            aS = sorted(list(sDic))
            iLS = len(aS)
            if iC + iLS < iK:
                iC += iLS
                continue
            else:
                print(aS[iK -iC-1])
                exit()
解()
### BUGGY CODE ###

N = int(input())
P = [int(input()) for _ in range(N)]

POINT = [False] * (10 ** 4 + 101)
POINT[0] = True
LP = len(POINT)

for p in POINT:
  for i in range(10**4):
    POINT[i+p] = POINT[i] | POINT[i+p]
  
ans = 0
for i in range(LP):
  if POINT[i]:
    ans = max(i,ans)
    
print(ans)


### FIXED CODE ###

N = int(input())
P = [int(input()) for _ in range(N)]

POINT = [False] * (10 ** 4 + 101)
POINT[0] = True
LP = len(POINT)

for p in P:
  for i in range(10**4,-1,-1):
    POINT[i+p] = POINT[i] | POINT[i+p]
  
ans = 0
for i in range(LP):
  if POINT[i] and i % 10 != 0:
    ans = max(i,ans)
    
print(ans)
### BUGGY CODE ###

#import itertools

x,y,z,k=(int(i) for i in input().split())
#print(x,y,z,k)
a=list(int(i) for i in input().split())
a.sort(reverse=True)
b=list(int(i) for i in input().split())
b.sort(reverse=True)
c=list(int(i) for i in input().split())
c.sort(reverse=True)
#print(a,b,c)

#k=3000
#a=[int(i) for i in range(1000)]
#b=[int(i) for i in range(1000)]
#c=[int(i) for i in range(1000)]
x=[]
for h in range(len(a)):
    for i in range(len(b)):
            for j in range(len(c)):
                if (h+1)*(i+1)*(j+1) <=k:
                    x.append(a[h]+b[i]+c[j])

x.sort(reverse=True)
for i in range(k):
  print(x[i])
  


### FIXED CODE ###

#import itertools

x,y,z,k=(int(i) for i in input().split())
#print(x,y,z,k)
a=list(int(i) for i in input().split())
a.sort(reverse=True)
b=list(int(i) for i in input().split())
b.sort(reverse=True)
c=list(int(i) for i in input().split())
c.sort(reverse=True)
#print(a,b,c)

#k=3000
#a=[int(i) for i in range(1000)]
#b=[int(i) for i in range(1000)]
#c=[int(i) for i in range(1000)]
x=[]
for h in range(len(a)):
    for i in range(len(b)):
        if (h+1)*(i+1) <=k:
            for j in range(len(c)):
                if (h+1)*(i+1)*(j+1) <=k:
                    x.append(a[h]+b[i]+c[j])

x.sort(reverse=True)
for i in range(k):
  print(x[i])
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N = int(input())
S = input()
Q = int(input())
k = [int(i) for i in input().split()]

for ki in k :
    ret = 0
    d, m, dm = 0, 0, 0
    for i in range(N) :
        if i >= ki :
            j = i - ki
            if S[j] == 'D' :
                d -= 1
                dm -= m
            elif S[j] == 'M' :
                m -= 1

        if S[i] == 'D' :
            d += 1
        elif S[i] == 'M' :
            m += 1
            dm += d
        elif S[i] == 'C' :
            ret += dm
            
    print(ret)

### FIXED CODE ###

import sys
input = sys.stdin.readline

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

for ki in k :
    ret = 0
    dp = [0] * 3
    for i in range(N) :
        if i >= ki :
            j = i - ki
            if S[j] == 'D' :
                dp[0] -= 1
                dp[2] -= dp[1]
            elif S[j] == 'M' :
                dp[1] -= 1

        if S[i] == 'D' :
            dp[0] += 1
        elif S[i] == 'M' :
            dp[1] += 1
            dp[2] += dp[0]
        elif S[i] == 'C' :
            ret += dp[2]
            
    print(ret)
### BUGGY CODE ###

import bisect

A, B, Q = (int(i) for i in input().split())
s = [0]*A
t = [0]*B
for i in range(A):
    s[i] = int(input())
for i in range(B):
    t[i] = int(input())

s_diff = [0]*A
t_diff = [0]*B
for i in range(A):
    ind = bisect.bisect_left(t, s[i])
    if ind == 0:
        sm = float("inf")
    else:
        sm = s[i] - t[ind-1]
    if ind == B:
        bi = float("inf")
    else:
        bi = t[ind] - s[i]
    s_diff[i] = min(sm, bi)
for i in range(B):
    ind = bisect.bisect_left(s, t[i])
    if ind == 0:
        sm = float("inf")
    else:
        sm = t[i] - s[ind-1]
    if ind == A:
        bi = float("inf")
    else:
        bi = s[ind] - t[i]
    t_diff[i] = min(sm, bi)

for i in range(Q):
    x = int(input())
    ind = bisect.bisect_left(t, x)
    if ind == 0:
        sm = float("inf")
    else:
        sm = x - t[ind-1] + t_diff[ind-1]
    if ind == B:
        bi = float("inf")
    else:
        bi = t[ind] - x + t_diff[ind]
    ans = min(sm, bi)
    ind = bisect.bisect_left(s, x)
    if ind == 0:
        sm = float("inf")
    else:
        sm = x - s[ind-1] + s_diff[ind-1]
    if ind == A:
        bi = float("inf")
    else:
        bi = s[ind] - x + s_diff[ind]
    ans = min(ans, sm, bi)
    print(ans)

### FIXED CODE ###

import numpy as np
import bisect
import sys
input = sys.stdin.readline

(A,B,Q) = map(int,input().split())
inf = 10**12
s = [0] * (A+2)
t = [0] * (B+2)
s[0] = -inf
t[0] = -inf
s[A+1] = inf
t[B+1] = inf

for i in range(A):
    s[i+1] = int(input())
for i in range(B):
    t[i+1] = int(input())

for _ in range(Q):
    x = int(input())
    p = bisect.bisect_left(s,x)
    q = bisect.bisect_left(t,x)
    spx = s[p] - x
    tqx = t[q] - x
    xtq1 = x - t[q-1]
    xsp1 = x - s[p-1]
    ans = min(max(spx, tqx),
              max(xsp1, xtq1),
                  spx*2 + xtq1,
                  spx + xtq1*2,
                  tqx*2 + xsp1,
                  t[q]-x + xsp1*2)
    print(ans)
### BUGGY CODE ###

A, B, K = map(int, input().split(' '))

lst = [i for i in range(A, B + 1)]

if len(lst) < 2 * K:
    for item in lst:
        print(item)
else:
    for item in lst[:K]:
        print(item)
    for item in lst[-K:]:
        print(item)


### FIXED CODE ###

A, B, K = map(int, input().split(' '))

if (B - A + 1) < 2 * K:
    for i in range(A, B + 1):
        print(i)
else:
    for i in range(A, A + K):
        print(i)
    for i in range(B - K + 1, B + 1):
        print(i)