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

def gcd(x, y):
    if x < y:
        x, y = y, x
    while x % y != 0:
        r = x % y
        x = y
        y = r
    return y
 
N = int(input())
a_list = list(map(int, input().split()))
MOD = 10 ** 9 + 7
 
if N == 1:
    print(1)
    exit()
div = gcd(a_list[0], a_list[1])
lcm = (a_list[0] * a_list[1]) // div
 
for i in range(2, N):
    div = gcd(lcm, a_list[i])
    lcm = (lcm * a_list[i]) // div
    
ans = 0
for i in range(N):
    ans += lcm//a_list[i] % MOD
 
print(ans%MOD)

### FIXED CODE ###

from functools import reduce

def gcd(x, y):
    if x < y:
        x, y = y, x
    while x % y != 0:
        r = x % y
        x = y
        y = r
    return y

def inv(x):
    return pow(x, MOD-2, MOD)

def lcm(a, b):
    return a * b // gcd(a, b)

def lcm_list(l:list):
    return reduce(lcm, l, 1)
  
N = int(input())
a_list = list(map(int, input().split()))
MOD = 10 ** 9 + 7

num = lcm_list(a_list) % MOD
ans = 0
for a in a_list:
    ans += (num * pow(a, MOD-2, MOD)) % MOD

print(ans%MOD)
### BUGGY CODE ###

a,b,m = map(int, input().split())
for i in range(m):
  if a > 0:
    a -= 1
  elif b > 0:
    b -= 1
  else:
    break
    
print(a,b)

### FIXED CODE ###

a, b, k = map(int, input().split())

if a > k:
    a -= k
    print(a, b)
else:
    k -= a
    a = 0
    
    if b > k:
        b -= k
        print(a, b)
    else:
        b = 0
        print(a, b)
### BUGGY CODE ###

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

b=[0]*(n+1)
for i in range(1,n+1):
    b[i]=a.count(i)

for i in range(1,n+1):
    print(b[i])

### FIXED CODE ###

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

b=[0]*n
for i in a:
    b[i-1]+=1

for i in b:
    print(i)
### BUGGY CODE ###

s = list(input())
s.reverse()
str = ""
for i in s:
    str+=i
str = str.replace("resare","")
str = str.replace("esare","")
str = str.replace("remaerd","")
str = str.replace("maerd","")
if len(str)==0:
    print("YES")
else:
    print("NO")


### FIXED CODE ###

s = list(input())
s.reverse()
str = ""
for i in s:
    str+=i
str = str.replace("resare","")
str = str.replace("esare","")
str = str.replace("remaerd","")
str = str.replace("maerd","")
if len(str)==0:
    print("YES")
else:
    print("NO")
### BUGGY CODE ###

import itertools

n, m, R = map(int, input().split())
r = list(map(int, input().split()))
dis = [[float("inf") for _ in range(n)] for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    dis[a - 1][b - 1] = c
    dis[b - 1][a - 1] = c

for k in range(n):
    for i in range(n):
        for j in range(n):
            if dis[i][j] > dis[i][k] + dis[k][j]:
                dis[i][j] = dis[i][k] + dis[k][j]


_min = float("inf")
it = itertools.permutations(r)
for iterR in it:
    _dis = 0
    start = iterR[0] - 1
    for end in iterR[1:]:
        _dis += dis[start][end - 1]
        start = end - 1
    _min = min(_min, _dis)
print(_min)


### FIXED CODE ###

import itertools
n, m, R = map(int, input().split())
r = list(map(int, input().split()))
dis = [[float("inf") for _ in range(n)] for _ in range(n)]
for _ in range(m):
    a, b, c = map(int, input().split())
    dis[a - 1][b - 1] = c
    dis[b - 1][a - 1] = c

def war(dis):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if dis[i][j] > dis[i][k] + dis[k][j]:
                    dis[i][j] = dis[i][k] + dis[k][j]
    return dis
dis = war(dis)
_min = float("inf")
it = itertools.permutations(r)
for iterR in it:
    _dis = 0
    start = iterR[0] - 1
    for end in iterR[1:]:
        _dis += dis[start][end - 1]
        start = end - 1
    _min = min(_min, _dis)
print(_min)
### BUGGY CODE ###

import numpy
a = int(input())
b = [list(input()) for _ in range(a)]
cnt = 0
for i in range(a):
    for j in range(i + 1, a):
        c = numpy.sort((b[i]))
        d = numpy.sort(b[j])
        if (c == d).all():
            cnt += 1
print(cnt)


### FIXED CODE ###

import collections
a = int(input())
b = ["".join(sorted(list(input()))) for _ in range(a)]
b = collections.Counter(b)
total = 0
for i in b.values():
    for j in range(1, i):
        total += j
print(total)
### BUGGY CODE ###

# coding: utf-8
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

z = [list(map(int, input().split())) for _ in range(M)]

num1 = {a[i] + b[j] for i in range(A) for j in range(B)}
# print("num1:", num1)        
num1 = min(num1)
# print("num1:", num1)
for i in range(M):
    x, y, c = z[i]
    num = a[x - 1] + b[y - 1] - c
    if num < num1:
        num1 = num
print(num1)

### FIXED CODE ###

# coding: utf-8
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a1 = sorted(a)
b1 = sorted(b)
z = [list(map(int, input().split())) for _ in range(M)]

num1 = a1[0] + b1[0]
# print("num1:", num1)
for i in range(M):
    x, y, c = z[i]
    num = a[x - 1] + b[y - 1] - c
    if num < num1:
        num1 = num
print(num1)
### BUGGY CODE ###

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

while len(a) >= 2:
    min_a = min(a)

    # 最小値が２つある場合に一回はskipする
    flag = False
    for i in range(len(a)):
        if a[i] == min_a and not flag:
            flag = True
            continue
        if flag or a[i] != min_a:
            a[i] = a[i] % min_a
    while True:
        if a.count(0) > 0:
            a.remove(0)
        else:
            break
print(a[0])


### FIXED CODE ###

def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b


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

ans = a[0]
for i in range(1, len(a)):
    ans = gcd(ans, a[i])
print(ans)
### BUGGY CODE ###

N=int(input())
A = [int(i) for i in input().split()]
multiple = 1

for i in range(N):
    multiple = multiple * A[i]

if multiple > 10 ** 18:
    print('-1')
else:
    print(multiple)

### FIXED CODE ###

N=int(input())
A = [int(i) for i in input().split()]

if 0 in A:
    multiple = 0
else:
    multiple = 1
    for i in range(N):
        multiple = multiple * A[i]
        if multiple > 1000000000000000000:
            multiple = -1
            break

print(multiple)
### BUGGY CODE ###

import math

def comb(n):
    if dp[n]!=-1:
        return dp[n]
    if n-2<0:
        dp[n]=0
        return dp[n]
    dp[n]=math.factorial(n)//(math.factorial(2)*math.factorial(n-2))
    return dp[n]

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

dp=[-1 for i in range(N+1)]
nums={}

for i in range(N):
    if not A[i] in nums:
        nums[A[i]]=1
    else:
        nums[A[i]]+=1

ans=[]
for i in range(N):
    number=0
    nums[A[i]]-=1
    for j in nums.keys():
        number+=comb(nums[j])
    ans.append(number)
    nums[A[i]]+=1

for i in range(N):
    print(ans[i])

### FIXED CODE ###

import math

def comb(n):
    if n-2<0:
        return 0
    return math.factorial(n)//(math.factorial(2)*math.factorial(n-2))
    
N=int(input())
A=list(map(int,input().split()))

nums=[0 for i in range(N+1)]
for i in range(N):
    nums[A[i]]+=1

num=0
for i in range(len(nums)):
    num+=comb(nums[i])

for i in range(N):
    ans=num-(nums[A[i]]-1)
    print(ans)
### BUGGY CODE ###

n = int(input())
A = input().split()

b = {}
for a in A:
    if a not in b:
        b[a] = 0
        
    b[a] += 1


for a in A:
    count = 0
    for c in b:
        n = b[c]
        if a == c:
            n -= 1
        
        count += n * (n - 1) // 2
    print(count)

### FIXED CODE ###

n = int(input())
A = input().split()

B = {}
for a in A:
    if a not in B:
        B[a] = 0
    B[a] += 1

sum = 0
for b in B:
    sum += B[b] * (B[b] - 1) // 2

for a in A:
    print(sum - (B[a] - 1))
### BUGGY CODE ###

#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():

    return

#B
def B():

    return

#C
def C():
    n,c = LI()
    a = LI()
    b = LI()
    s = [[0]*(c+1) for i in range(n)]
    for k in range(c+1):
        for i in range(n):
            ai,bi = a[i],b[i]
            for x in range(ai,bi+1):
                s[i][k] += pow(x,k,mod)
                if s[i][k] >= mod:
                    s[i][k] %= mod
    dp = [[0]*(c+1) for i in range(n)]
    for k in range(c+1):
        dp[0][k] = s[0][k]

    for i in range(1,n):
        for k in range(c+1):
            for j in range(k+1):
                dp[i][k] += dp[i-1][j]*s[i][k-j]
                if dp[i][k] >= mod:
                    dp[i][k] %= mod
    print(dp[-1][c])
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    C()


### FIXED CODE ###

#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():

    return

#B
def B():

    return

#C
def C():
    n,c = LI()
    a = LI()
    b = LI()
    s = [[0]*(c+1) for i in range(n)]
    for i in range(n):
        ai,bi = a[i],b[i]
        for x in range(ai,bi+1):
            e = 1
            for k in range(c+1):
                s[i][k] += e
                if s[i][k] >= mod:
                    s[i][k] %= mod
                e *= x
                if e >= mod:
                    e %= mod
    dp = [[0]*(c+1) for i in range(n)]
    for k in range(c+1):
        dp[0][k] = s[0][k]

    for i in range(1,n):
        for k in range(c+1):
            for j in range(k+1):
                dp[i][k] += dp[i-1][j]*s[i][k-j]
                if dp[i][k] >= mod:
                    dp[i][k] %= mod
    print(dp[-1][c])
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    C()
### BUGGY CODE ###

n = int(input())
m = [i for i in range(n)]
print(sum(m))


### FIXED CODE ###

n = int(input())
print((n*(n-1))//2)
### BUGGY CODE ###

import numpy as np

def resolve():
  N, M = map(int, input().split(" "))
  rooms = [None] * N

  def search_and_mark(recent_rooms, AB, depth):
    if None not in rooms:
      return rooms

    tmp_rooms = []
    for r in recent_rooms:
      tmp = AB[np.any(AB == r, axis=1)]
      target = tmp[tmp != r]
      tmp_rooms.extend(target)
      AB = AB[np.any(AB != r, axis=1)]
      
      for t in target:
        if rooms[t] == None:
          rooms[t] = r

    recent_rooms = list(set(tmp_rooms))
    return search_and_mark(recent_rooms, AB, depth+1)

  AB = []
  for m in range(M):
    AB.append([int(x) - 1 for x in input().split(" ")])

  AB = np.array(AB)
  result = search_and_mark([0], AB, 0)

  print("Yes")
  for r in result[1:]:
    print(r + 1)

if __name__ == "__main__":
    resolve()


### FIXED CODE ###

def resolve():
  N, M = map(int, input().split(" "))
  AB_map = [[] for i in range(N)]
  for m in range(M):
    AB = [int(x) - 1 for x in input().split(" ")]
    AB_map[AB[0]].append(AB[1])
    AB_map[AB[1]].append(AB[0])

  not_finished = set(range(1, N+1))
  rooms = [None] * N
  rooms[0] = 0
  room_depths = [0] * N

  recent_rooms = [0]
  depth = 1
  while len(not_finished) != 0 and depth < N:
    temp_recent = set()
    for r in recent_rooms:
      for target in AB_map[r]:
        if target in not_finished:
          temp_recent.add(target)
          not_finished.remove(target)
          rooms[target] = r
          room_depths[target] = depth
    depth += 1
    recent_rooms = list(temp_recent)

  print("Yes")
  for r in rooms[1:]:
    print(r + 1)

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

N = int(input())
S = input()                                                                                                                                                                                                                                                                                                                                                                                                                                            
list_S = list(S)
N1 = 0

ans_list = []
for color in list_S:
    list_S1 = list_S[N1:]
    list_S2 = list_S[:N1]
    ans = list_S2.count('#') + list_S1.count('.')
    ans_list.append(ans)
    N1 += 1
ans_list.append(list_S.count("#"))
     
print(min(ans_list))

### FIXED CODE ###

N = int(input())
S = input()
S = list(map(lambda x: 0 if x=="." else 1, S))
#all_white
# all_white = sum(S)
# all_black = len(S) - all_white

# white, black, white
ans_list = []
for thresh in range(len(S)):        
    if thresh == 0:
        ans = len(S) - sum(S)
        ans_list.append(ans)
    
    else:
        ans = ans_list[-1]
        if S[thresh-1] == 1: 
            ans += 1
        else:
            ans -= 1
        ans_list.append(ans)
ans_list.append(sum(S))
        
print(min(ans_list))
### BUGGY CODE ###

X = int(input())
c = 1
for b in range(1,X):
  for p in range(2,X):
    if b**p <= X: c=max(c,b**p)
print(c)

### FIXED CODE ###

X = int(input())
max_n = 1
for i in range(2,32):
  for j in range(2,10):
    tmp = i**j
    if X >= tmp and max_n < tmp:
      max_n = tmp
print(max_n)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N = int(input())
S = [input() for i in range(N)]
count = 0
while len(S) >0:
  [S for S in S if S != S[0]]
  count += 1

print(count)

### FIXED CODE ###

N = int(input())
S = list()
for i in range(N):
  x = input()
  S.append(x)
  
A = set(S)
print(len(A))
### BUGGY CODE ###

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

ret = 1
for ai in a:
  ret = ret * ai
  if ret == 0:
    ret = 0
    break
    
if ret > 10 ** 18:
  ret = -1

print( ret)

### FIXED CODE ###

n = int( input() )
A = list( map( int,input().split() ) )

if 0 in A:
  print( 0 )
else:
  ret = 1
  for a in A:
    ret = ret * a
    if ret > 10 ** 18:
      ret = -1
      break
  print( ret )
### BUGGY CODE ###

#C
import collections



N,Q =map(int,input().split())
S = input()
List=[[int(j) for j in input().split()] for i in range(1,Q+1)]

for i in range(Q):
    print(S[List[i][0]-1:List[i][1]].count("AC"))

### FIXED CODE ###

#122 C
N,Q= map(int,input().split())
S=input()
ans=[0]*(N+1)

for i in range(2,N+1):
    ans[i]=ans[i-1]
    if S[i-2:i]=='AC':
        ans[i]+=1
    
for i in range(Q):
    l,r=map(int,input().split())
    print(ans[r]-ans[l])
### BUGGY CODE ###

import math
k = int(input())
ans = 0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      ans += math.gcd(a, math.gcd(b, c))
print(ans)

### FIXED CODE ###

import math
k = int(input())
ans = k**3 - (k-1)**3
for a in range(2,k+1):
  for b in range(2,k+1):
    tmp = math.gcd(a,b)
    for c in range(2,k+1):
      ans += math.gcd(tmp, c)
print(ans)
### BUGGY CODE ###

import collections

if __name__ == '__main__':
    N, W = map(int, input().split())

    dp = [collections.defaultdict(int) for _ in range(N + 1)]
    dp[0][0] = 0

    for i in range(N):
        w, v = map(int, input().split())
        for j in range(W + 1):
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
            if j + w <= W: dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v)

    ans = max(dp[N].values())
    print(ans)


### FIXED CODE ###

import collections

if __name__ == '__main__':
    N, W = map(int, input().split())

    dp = [collections.defaultdict(int) for _ in range(N + 1)]
    dp[0][0] = 0

    for i in range(N):
        w, v = map(int, input().split())
        for j in dp[i]:
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
            if j + w <= W: dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v)

    ans = max(dp[N].values())
    print(ans)
### BUGGY CODE ###

n = int(input())
s = input()
print(min(sum(s[j] == '#' if j < i else s[j] == '.' for j in range(n)) for i in range(n+1)))

### FIXED CODE ###

n = int(input())
s = input()
m = s.count('.')
c = (0, m)
for i in range(n):
    if s[i] == '#':
        c = (c[0]+1, c[1])
    else:
        c = (c[0], max(c[1]-1, 0))
    m = min(c[0] + c[1], m)
print(m)
### BUGGY CODE ###

def main():
    num = 0
    _ = input()
    A = sorted(list(map(int, input().split())))
    for i in range(len(A)-1):
        for j in range(i+1, len(A)):
            a = A[i]
            b = A[j]
            thresh = a + b
            ok = j
            ng = len(A)
            idx = binary_search(A, ok, ng, thresh)
            num += idx - j

    print(num)


def binary_search(li, ok, ng, value):
    while abs(ok-ng) > 1:
        mid = (ok + ng) // 2
        if li[mid] < value:
            ok = mid
        else:
            ng = mid

    return ok


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline
 
 
def main():
    num = 0
    _ = input()
    A = sorted(list(map(int, input().split())))
    for i in range(len(A)-1):
        for j in range(i+1, len(A)):
            a = A[i]
            b = A[j]
            thresh = a + b
            ok = j
            ng = len(A)
            idx = binary_search(A, ok, ng, thresh)
            num += idx - j
 
    print(num)
 
 
def binary_search(li, ok, ng, value):
    while abs(ok-ng) > 1:
        mid = (ok + ng) // 2
        if li[mid] < value:
            ok = mid
        else:
            ng = mid
 
    return ok
 
 
if __name__ == "__main__":
    main()
### BUGGY CODE ###

import math
def choose(n,k):
    return math.factorial(n)//(math.factorial(n-k)*math.factorial(k))
mod = 10**9 +7
N,M,K = map(int,input().split())
ans = 0
memo = choose(N*M-2,K-2)
#まずはX軸について、総和を考える
d = 1
while d < M:
    ans += d*memo*(M-d)*N*N
    d += 1
    ans %= mod

#Y軸について、総和を考える
d = 1
while d < N:
    ans += d*memo*(N-d)*M*M
    d += 1
    ans %= mod

print(ans)


### FIXED CODE ###

import math
def choose(n,k):
    return math.factorial(n)//(math.factorial(n-k)*math.factorial(k))
mod = 10**9 +7
N,M,K = map(int,input().split())
ans = 0
memo = choose(N*M-2,K-2)
memo %= mod
#まずはX軸について、総和を考える
d = 1
while d < M:
    ans += d*memo*(M-d)*N*N
    d += 1
    ans %= mod

#Y軸について、総和を考える
d = 1
while d < N:
    ans += d*memo*(N-d)*M*M
    d += 1
    ans %= mod

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

X, Y, Z, K = map(int, input().split())

A = sorted(list(map(int, input().split())))[::-1]
B = sorted(list(map(int, input().split())))[::-1]
C = sorted(list(map(int, input().split())))[::-1]

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

A_B = sorted(A_B)

def bin_search(mid):
    res = 0
    idx = 0
    ans = []
    for c in C:
        while idx < len(A_B):
            if c + A_B[idx] >= mid:
                res += len(A_B) - idx
                ans += [i + c for i in A_B[idx:]]
                break
            else:
                idx += 1
    
    return res, ans

ok = 0
ng = pow(10, 10) * 3 + 1

while ok + 1 < ng:
    mid = (ok + ng) // 2
    res, ans = bin_search(mid)
    if res >= K:
        ok = mid
    else:
        ng = mid

res, ans = bin_search(ok)
for a in sorted(ans)[::-1][:K]:
    print(a)

### FIXED CODE ###

X, Y, Z, K = map(int, input().split())

A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))[::-1]

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

A_B = sorted(A_B)

def bin_search(mid):
    res = 0
    idx = 0
    ans = [] 
    for c in C:
        while idx < len(A_B):
            if c + A_B[idx] >= mid:
                res += len(A_B) - idx
                ans.append((c, idx))
                break
            else:
                idx += 1

    return res, ans

ok = 0
ng = pow(10, 10) * 3 + 1

while ok + 1 < ng:
    mid = (ok + ng) // 2
    res, ans = bin_search(mid)
    if res >= K:
        ok = mid
    else:
        ng = mid

res, ans = bin_search(ok)

tmp_ans = []
for c, idx in ans:
    for i in range(idx, len(A_B)):
        tmp_ans.append(A_B[i] + c)
for ans in sorted(tmp_ans)[::-1][:K]:
    print(ans)
### BUGGY CODE ###

t,*grid = open(0)
h,w = map(int,t.split())
L,R,U,D = eval("[0]*((w+2)*(h+2)),"*4)
for y in range(h):
	for x in range(w):
		if grid[y][x]==".":
			L[(y+1)*(w+2)+x+1] = L[(y+1)*(w+2)+x]+1
		if grid[y][w-x-1]==".":
			R[(y+1)*(w+2)+w-x] = R[(y+1)*(w+2)+w-x+1]+1
for x in range(w):
	for y in range(h):
		if grid[y][x]==".":
			U[(y+1)*(w+2)+x+1] = U[y*(w+2)+x+1]+1
		if grid[h-y-1][x]==".":
			D[(h-y)*(w+2)+x+1] = D[(h-y+1)*(w+2)+x+1]+1
print(max(l+r+u+d-3 for l,r,u,d in zip(L,R,U,D)))

### FIXED CODE ###

t,*grid = open(0)
h,w = map(int,t.split())
L,R,U,D = eval("[[0]*(w+2) for _ in range(h+2)],"*4)
for y in range(h):
	for x in range(w):
		if grid[y][x]==".":
			L[y+1][x+1] = L[y+1][x]+1
		if grid[y][w-x-1]==".":
			R[y+1][w-x] = R[y+1][w-x+1]+1
for x in range(w):
	for y in range(h):
		if grid[y][x]==".":
			U[y+1][x+1] = U[y][x+1]+1
		if grid[h-y-1][x]==".":
			D[h-y][x+1] = D[h-y+1][x+1]+1
a = 0
for y in range(1,h+1):
	for x in range(1,w+1):
		a = max(a, L[y][x] + R[y][x] + U[y][x] + D[y][x] -3)
print(a)
### BUGGY CODE ###

from bisect import bisect_left, bisect_right
a, b, q = map(int, input().split())
shrine = [int(input()) for _ in range(a)]
temple = [int(input()) for _ in range(b)]

inf = 10**18
for _ in range(q):
    ans = inf
    x = int(input())
    index_s = bisect_left(shrine, x)
    index_t = bisect_right(temple, x)
    for i in range(index_s-1, index_s+1):
        if i == a or i < 0:
            continue
        s = shrine[i]
        i_t = bisect_left(temple, s)

        if i_t == 0:
            t0 = inf
        else:
            t0 = temple[i_t - 1]
            
        if i_t <= b-1:
            t1 = temple[i_t]
        else:
            t1 = inf

        ans = min(
            ans,
            abs(x - s) + abs(s - t0),
            abs(x - s) + abs(s - t1),
        )
    for i in range(index_t-1, index_t+1):
        if i == b or i < 0:
            continue
        t = temple[i]
        i_s = bisect_left(shrine, t)
        if i_s == 0:
            s0 = inf
        else:
            s0 = shrine[i_s - 1]

        if i_s <= a-1:
            s1 = shrine[i_s]
        else:
            s1 = inf
        ans = min(
            ans,
            abs(x - t) + abs(t - s0),
            abs(x - t) + abs(t - s1),
        )

    print(ans)





### FIXED CODE ###

from bisect import bisect_left, bisect_right
a, b, q = map(int, input().split())
inf = 10**18
shrine = [-inf] + [int(input()) for _ in range(a)] + [inf]
temple = [-inf] + [int(input()) for _ in range(b)] + [inf]

for _ in range(q):
    ans = inf
    x = int(input())
    index_s = bisect_left(shrine, x)
    index_t = bisect_right(temple, x)
    for i in range(index_s-1, index_s+1):
        s = shrine[i]
        i_t = index_t
        t0, t1 = temple[i_t-1], temple[i_t]
        ans = min(
            ans,
            abs(x - s) + abs(s - t0),
            abs(x - s) + abs(s - t1),
        )

    for i in range(index_t-1, index_t+1):
        t = temple[i]
        i_s = index_s
        s0 = shrine[i_s - 1]
        s1 = shrine[i_s]
        ans = min(
            ans,
            abs(x - t) + abs(t - s0),
            abs(x - t) + abs(t - s1),
        )

    print(ans)