Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if a + b == 15:
    print('+')
elif a * b == 15:
    print('*')
else:
    print('x')


Fixed submission:
N = input().split(" ")
a = int(N[0])
b = int(N[1])
if a + b== 15:
    print('+')
elif a * b== 15:
    print('*')
else:
    print('x')
Buggy python submission (verdict: Runtime Error):
def main(x):
    if x =1:
        return 0
    else:
        return 1

main(x)


Fixed submission:
x=int(input())

def main(x):
    if x ==1:
        return 0
    else:
        return 1
print(main(x))

Buggy python submission (verdict: Runtime Error):
def main(x):
    if x =1:
        return 0
    else:
        return 1

main(x)


Fixed submission:
x=int(input())

def main(x):
    if x ==1:
        return 0
    else:
        return 1
print(main(x))

Buggy python submission (verdict: Runtime Error):
def main():
    if x =1:
        return 0
    else:
        return 1

main()


Fixed submission:
x=int(input())

def main(x):
    if x ==1:
        return 0
    else:
        return 1
print(main(x))

Buggy python submission (verdict: Runtime Error):
def main():
    if x =1:
        return 0
    elif x !=1:
        return 1

main()

Fixed submission:
x=int(input())

def main(x):
    if x ==1:
        return 0
    else:
        return 1
print(main(x))
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
h=[]
a=0
for i in range(1,N+1):
    i=input()
    h.append(i)
    if int(i)>=int(K):
        a+=1
        
print(a)

Fixed submission:
N,K=map(int,input().split())
h=list(map(int,input().split()))
a=0
for idx in h:
    if idx>=K:
        a+=1
        
print(a)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A={}
for i in range(1,N+1):
    A[i]=int(input())
A=sorted(A.items(),key=lambda x:x[1])
for k in A:
    print(k[0],end=" ")

Fixed submission:
N=int(input())
A=map(int,input().split())
A=list(A)
B={}
for i in range(1,N+1):
    B[i]=A[i-1]

B=sorted(B.items(),key=lambda x:x[1])
for k in B:
    print(k[0],end=" ")
Buggy python submission (verdict: Runtime Error):
A=input()

B=input()


ad=int(A)+int(B)
mi=int(A)-int(B)
de=int(A)*int(B)

math=[ad,mi,de]
m_max=max(math)

print(m_max)


Fixed submission:
A,B=input().split()

ad=int(A)+int(B)
mi=int(A)-int(B)
de=int(A)*int(B)

math=[ad,mi,de]

m_max=max(math)

print(m_max)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_list = [int(x) for x in input().split()]
ans = 1
for a in a_list:
    ans *= a
print(ans if ans <= 10 ** 18 else -1)

Fixed submission:
n = int(input())
a_list = sorted([int(x) for x in input().split()], reverse=True)

if a_list[-1] == 0:
    print(0)
    exit()

ans = 1
s = 10 ** 18
for a in a_list:
    ans *= a
    if ans > s:
        ans = -1
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from operator import mul
n = int(input())
a_list = [int(x) for x in input().split()]
ans = reduce(mul, a_list)
print(ans if ans <= 10 ** 18 else -1)

Fixed submission:
n = int(input())
a_list = sorted([int(x) for x in input().split()], reverse=True)

if a_list[-1] == 0:
    print(0)
    exit()

ans = 1
s = 10 ** 18
for a in a_list:
    ans *= a
    if ans > s:
        ans = -1
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_list = [int(x) for x in input().split()]
s = 10 ** 18
ans = 1
for a in a_list:
    ans *= a
    if ans == 0:
        break
print(ans if ans <= s else -1)

Fixed submission:
n = int(input())
a_list = sorted([int(x) for x in input().split()], reverse=True)

if a_list[-1] == 0:
    print(0)
    exit()

ans = 1
s = 10 ** 18
for a in a_list:
    ans *= a
    if ans > s:
        ans = -1
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
n = 10 ** 9
for b in range(n):
    a = (x + b ** 5) ** 0.2
    if a == int(a.real):
        a = int(a.real)
        break
    b *= -1
    a = (x + b ** 5) ** 0.2
    if a == int(a.real):
        a = int(a.real)
        break
print(a, b)

Fixed submission:
x = int(input())
for a in range(-118, 120):
    for b in range(-119, 119):
        if a ** 5 - b ** 5 == x:
            print(a, b)
            exit()

Buggy python submission (verdict: Runtime Error):
x = int(input())
n = 10 ** 9
for b in range(n):
    a = (x + b ** 5) ** 0.2
    if a == int(a):
        a = int(a)
        break
    b *= -1
    a = (x + b ** 5) ** 0.2
    if a == int(a):
        a = int(a)
        break
print(a, b)

Fixed submission:
x = int(input())
for a in range(-118, 120):
    for b in range(-119, 119):
        if a ** 5 - b ** 5 == x:
            print(a, b)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_list = [int(x) for x in input().split()]

temp_list = sorted([(a, i) for i, a in enumerate(a_list)])

ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        if temp_list[i][0] + temp_list[j][0] >= n:
            break
        if temp_list[i][0] + temp_list[j][0] == abs(temp_list[i][1] - temp_list[j][1]):
            ans += 1
print(ans)

Fixed submission:
from collections import defaultdict

n = int(input())

a_list = [int(x) for x in input().split()]

l = defaultdict(int)
r = defaultdict(int)
for i in range(n):
    l[i + a_list[i]] += 1
    r[i - a_list[i]] += 1

ans = 0
for x in l.keys():
    ans += l[x] * r[x]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd

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):
            temp = gcd(gcd(a, b), c)
            ans += temp
print(ans)

Fixed submission:
from math import gcd

k = int(input())

r = range(1, k + 1)
ans = sum([gcd(gcd(a, b), c) for a in r for b in r for c in r])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())

result_dict = {}
def gcd(x, y):
    if x > y:
        x, y = y, x
    if x == 0:
        return y
        
    global result_dict
    if x not in result_dict:
        result_dict[x] = {}
    if y in result_dict[x]:
        return result_dict[x][y]

    temp = gcd(y % x, x)
    result_dict[x][y] = temp
    return temp

ans = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            temp = gcd(gcd(a, b), c)
            ans += temp
print(ans)

Fixed submission:
from math import gcd

k = int(input())

r = range(1, k + 1)
ans = sum([gcd(gcd(a, b), c) for a in r for b in r for c in r])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product

k = int(input())
s = input()

temp_dict = {
    "R": [],
    "G": [],
    "B": [],
}
for i, c in enumerate(s):
    temp_dict[c].append(i)

ans = 0
temp_list = list(product(temp_dict["R"], temp_dict["G"], temp_dict["B"]))
for temp in temp_list:
    temp = sorted(list(temp))
    if temp[0] - temp[1] != temp[1] - temp[2]:
        ans += 1

print(ans)


Fixed submission:
n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")

ans = r * g * b
for i in range(n - 2):
    for j in range(i + 2, n, 2):
        if s[i] != s[(i + j) >> 1] != s[j] != s[i]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Runtime Error):
from itertools import product

k = int(input())
s = input()

temp_dict = {
    "R": [],
    "G": [],
    "B": [],
}
for i, c in enumerate(s):
    temp_dict[c].append(i)

ans = 0
temp_list = list(product(temp_dict["R"], temp_dict["G"], temp_dict["B"]))
for temp in temp_list:
    temp.sort()
    if temp[0] - temp[1] != temp[1] - temp[2]:
        ans += 1

print(ans)


Fixed submission:
n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")

ans = r * g * b
for i in range(n - 2):
    for j in range(i + 2, n, 2):
        if s[i] != s[(i + j) >> 1] != s[j] != s[i]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Runtime Error):
temp_dict = {
    "R": [],
    "G": [],
    "B": [],
}
for i, c in enumerate(s):
    temp_dict[c].append(i)

ans = 0
temp_list = list(product(temp_dict["R"], temp_dict["G"], temp_dict["B"]))
for temp in temp_list:
    temp = sorted(list(temp))
    if temp[0] - temp[1] != temp[1] - temp[2]:
        ans += 1

print(ans)

Fixed submission:
n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")

ans = r * g * b
for i in range(n - 2):
    for j in range(i + 2, n, 2):
        if s[i] != s[(i + j) >> 1] != s[j] != s[i]:
            ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product

n = int(input())
s = input()

temp_dict = {
    "R": [],
    "G": [],
    "B": [],
}
for i, c in enumerate(s):
    temp_dict[c].append(i)
# print(temp_dict)

ans = 0
for temp in list(product(temp_dict["R"], temp_dict["G"], temp_dict["B"])):
    temp = sorted(list(temp))
    if temp[1] - temp[0] != temp[2] - temp[1]:
        ans += 1
print(ans)

Fixed submission:
n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")

ans = r * g * b
for i in range(n - 2):
    for j in range(i + 2, n, 2):
        if s[i] != s[(i + j) >> 1] != s[j] != s[i]:
            ans -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

query_list = [input().split() for _ in range(q)]

for query in query_list:
    if query[0] == "1":
        s = s[::-1]
    elif query[0] == "2":
        if query[1] == "1":
            s = query[2] + s
        elif query[1] == "2":
            s = s + query[2]

print(s)

Fixed submission:
from collections import deque
s = input()
n = int(input())
q_list = [input().split() for _ in range(n)]
d = deque(list(s))
r_flag = False
for q in q_list:
    if q[0] == "1":
        r_flag = not r_flag
    elif q[0] == "2":
        if q[1] == "1":
            if r_flag:
                d.append(q[2])
            else:
                d.appendleft(q[2])
        elif q[1] == "2":
            if r_flag:
                d.appendleft(q[2])
            else:
                d.append(q[2])
if r_flag:
    d.reverse()
print("".join(d))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(s) for s in input().split()]

e_list = [(int(s) + 1) / 2 for s in input().split()]
e_sum_list = e_list[:]

for _ in range(k - 1):
    e_list.pop(0)
    e_sum_list = [a + b for a, b in zip(e_sum_list, e_list)]

ans = max(e_sum_list)
print(ans)

Fixed submission:
n, k = [int(s) for s in input().split()]

e_list = [(int(s) + 1) / 2 for s in input().split()]

temp = sum(e_list[:k])
ans = temp

for i in range(k, n):
    temp = temp - e_list[i - k] + e_list[i]
    if temp > ans:
        ans = temp

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd

from functools import reduce


def lcm(x, y):
    return (x * y) // gcd(x, y)

n = int(input())
a_list = [int(x) for x in input().split()]

temp = reduce(lcm, a_list)

mod = 10 ** 9 + 7
ans = sum([temp // a for a in a_list]) % mod
print(ans)

Fixed submission:
from fractions import gcd

from functools import reduce


n = int(input())
a_list = [int(x) for x in input().split()]

temp = reduce(lambda x, y: (x * y) // gcd(x, y), a_list)

mod = 10 ** 9 + 7
ans = sum([temp // a for a in a_list]) % mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(x) for x in input().split()]

a_list = [int(x) for x in input().split()]
a_list.sort()

mod = 10 ** 9 + 7

temp_list = [1] * (n + 1)
for i in range(1, n + 1):
    temp_list[i] = i * temp_list[i - 1] % mod

i_temp_list = [1] * (n + 1)
i_temp_list[-1] = pow(temp_list[-1], mod - 2, mod)
for i in range(n, 0, -1):
    i_temp_list[i - 1] = i_temp_list[i] * i % mod

y = k - 2

ans = 0
for i in range(n - k + 1):
    for j in range(i + k - 1, n):
        f = a_list[j] - a_list[i]

        x = j - i - 1
        num = temp_list[x] * i_temp_list[y] * i_temp_list[x - y] % mod

        ans += f * num % mod

ans %= mod
print(ans)

Fixed submission:
n, k = [int(x) for x in input().split()]

a_list = [int(x) for x in input().split()]
a_list.sort()

mod = 10 ** 9 + 7

temp_list = [1] * (n + 1)
for i in range(1, n + 1):
    temp_list[i] = i * temp_list[i - 1] % mod

i_temp_list = [1] * (n + 1)
i_temp_list[-1] = pow(temp_list[-1], mod - 2, mod)
for i in range(n, 0, -1):
    i_temp_list[i - 1] = i_temp_list[i] * i % mod

y = k - 1

ans = 0
for i in range(k - 1, n):
        x = i
        num = temp_list[x] * i_temp_list[y] * i_temp_list[x - y] % mod
        ans += a_list[i] * num % mod
for i in range(n - k + 1):
        x = n - 1 - i
        num = temp_list[x] * i_temp_list[y] * i_temp_list[x - y] % mod
        ans -= a_list[i] * num % mod

ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = [int(x) for x in input().split()]

a_list = [int(x) for x in input().split()]
a_list.sort()

temp_list = [1] * (n + 1)
for i in range(1, n + 1):
    temp_list[i] = i * temp_list[i - 1]

mod = 10 ** 9 + 7
y = k - 2

ans = 0
for i in range(n - k + 1):
    for j in range(i + k - 1, n):
        f = a_list[j] - a_list[i]

        x = j - i - 1
        num = temp_list[x] // temp_list[y] // temp_list[x - y]

        ans += (f * num) % mod

ans %= mod
print(ans)

Fixed submission:
n, k = [int(x) for x in input().split()]

a_list = [int(x) for x in input().split()]
a_list.sort()

mod = 10 ** 9 + 7

temp_list = [1] * (n + 1)
for i in range(1, n + 1):
    temp_list[i] = i * temp_list[i - 1] % mod

i_temp_list = [1] * (n + 1)
i_temp_list[-1] = pow(temp_list[-1], mod - 2, mod)
for i in range(n, 0, -1):
    i_temp_list[i - 1] = i_temp_list[i] * i % mod

y = k - 1

ans = 0
for i in range(k - 1, n):
        x = i
        num = temp_list[x] * i_temp_list[y] * i_temp_list[x - y] % mod
        ans += a_list[i] * num % mod
for i in range(n - k + 1):
        x = n - 1 - i
        num = temp_list[x] * i_temp_list[y] * i_temp_list[x - y] % mod
        ans -= a_list[i] * num % mod

ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
x, y = [int(s) for s in input().split()]

a, a_mod = divmod(2 * y - x, 3)
b, b_mod = divmod(2 * x - y, 3)
if a_mod != 0 or b_mod != 0:
    print(0)
    exit()

mod = 10 ** 9 + 7

n = a + b
temp_list = [1] * (n + 1)
for i in range(1, n + 1):
    temp_list[i] = i * temp_list[i - 1] % mod

stop = a if a < b else b
i_temp_list = [1] * (n + 1)
i_temp_list[-1] = pow(temp_list[-1], mod - 2, mod)
for i in range(n, stop, -1):
    i_temp_list[i - 1] = i_temp_list[i] * i % mod

ans = temp_list[n] * i_temp_list[a] * i_temp_list[b] % mod
print(ans)

Fixed submission:
x, y = [int(s) for s in input().split()]

a, a_mod = divmod(2 * y - x, 3)
b, b_mod = divmod(2 * x - y, 3)
if a < 0 or a_mod != 0 or b < 0 or b_mod != 0:
    print(0)
    exit()

mod = 10 ** 9 + 7

n = a + b
temp_list = [1] * (n + 1)
for i in range(1, n + 1):
    temp_list[i] = i * temp_list[i - 1] % mod

stop = a if a < b else b
i_temp_list = [1] * (n + 1)
i_temp_list[-1] = pow(temp_list[-1], mod - 2, mod)
for i in range(n, stop, -1):
    i_temp_list[i - 1] = i_temp_list[i] * i % mod

ans = temp_list[n] * i_temp_list[a] * i_temp_list[b] % mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, bisect_right

n = int(input())

l_list = [int(x) for x in input().split()]
l_list.sort()

ans = 0
for i in range(n - 2):
    continue_flag = False
    for j in range(i + 1, n - 1):
        l = bisect_right(l_list, l_list[j] - l_list[i])
        l = l if l > j else j + 1
        if l == n:
            continue_flag = True
            break

        r = bisect_left(l_list, l_list[j] + l_list[i])

        ans += r - l

    if continue_flag:
        continue
print(ans)

Fixed submission:
from bisect import bisect_left

n = int(input())

l_list = [int(x) for x in input().split()]
l_list.sort()
# print(l_list)

ans = 0
for i in range(n - 2):
    continue_flag = False
    for j in range(i + 1, n - 1):
        ans += bisect_left(l_list, l_list[j] + l_list[i]) - (j + 1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import insort_left

n, m = [int(x) for x in input().split()]

a_list = [int(x) for x in input().split()]
a_list.sort()

for _ in range(m):
    a_list[-1] //= 2
    insort_left(a_list, a_list.pop())
print(sum(a_list))

Fixed submission:
import heapq
from math import ceil

n, m = [int(x) for x in input().split()]

a_list = [-int(x) for x in input().split()]
heapq.heapify(a_list)

for _ in range(m):
    temp = ceil(heapq.heappop(a_list) / 2)
    heapq.heappush(a_list, temp)
print(-sum(a_list))
Buggy python submission (verdict: Runtime Error):
n, m = [int(x) for x in input().split()]
a_list = [0] * m
for i in range(m):
    a_list[i] = int(input())

mod = 1000000007

temp_list = [0] * (n + 1)
temp_list[0] = 1
if a_list[0] != 1:
    temp_list[1] = 1
    j = 0
else:
    j = 1

for i in range(2, n + 1):
    if j < m and i == a_list[j]:
        j += 1
        continue
    temp_list[i] = (temp_list[i - 2] + temp_list[i - 1]) % mod
print(temp_list[n])

Fixed submission:
n, m = [int(x) for x in input().split()]
a_list = [0] * m
for i in range(m):
    a_list[i] = int(input())

mod = 1000000007

temp_list = [0] * (n + 1)
temp_list[0] = 1
temp_list[1] = 1
j = 0
if j < m and a_list[0] == 1:
    temp_list[1] = 0
    j = 1

for i in range(2, n + 1):
    if j < m and i == a_list[j]:
        j += 1
        continue
    temp_list[i] = (temp_list[i - 2] + temp_list[i - 1]) % mod
print(temp_list[n])
Buggy python submission (verdict: Time Limit Exceeded):
n, m = [int(x) for x in input().split()]

key_set = None
for _ in range(m):
    l, r = [int(x) for x in input().split()]
    if not key_set:
        key_set = set(range(l, r + 1))
    else:
        key_set &= set(range(l, r + 1))
print(len(key_set))

Fixed submission:
n, m = [int(x) for x in input().split()]

l_list = [0] * m
r_list = [0] * m
for i in range(m):
    l_list[i], r_list[i] = [int(x) for x in input().split()]

print(max(min(r_list) - max(l_list) + 1, 0))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = [int(x) for x in input().split()]
g_list = [[int(x) for x in input().split()] for _ in range(m)]

ans = 0
for i in range(1, n + 1):
    for l, r in g_list:
        if i < l or i > r:
            break
    else:
        ans += 1
print(ans)

Fixed submission:
n, m = [int(x) for x in input().split()]

l_list = [0] * m
r_list = [0] * m
for i in range(m):
    l_list[i], r_list[i] = [int(x) for x in input().split()]

print(max(min(r_list) - max(l_list) + 1, 0))
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd

n = int(input())
a_list = [int(x) for x in input().split()]

ans = 0
for i in range(n):
    temp = None
    for j in range(n):
        if j == i:
            continue
        
        if temp is None:
            temp = a_list[j]
        else:
            temp = gcd(temp, a_list[j])
        
        if temp == 1:
            break
    
    if temp > ans:
        ans = temp
print(ans)

Fixed submission:
from fractions import gcd

n = int(input())
a_list = [int(x) for x in input().split()]

l_list = [0] * n
temp = a_list[0]
for i in range(n - 1):
    if temp == 1:
        l_list[i] = 1
        continue
    temp = gcd(temp, a_list[i])
    l_list[i] = temp

r_list = [0] * n
temp = a_list[n - 1]
for i in range(n - 1, 0, -1):
    if temp == 1:
        r_list[i] = 1
        continue
    temp = gcd(temp, a_list[i])
    r_list[i] = temp

ans = 0
for i in range(n):
    if i == 0:
        temp = r_list[1]
    elif i == n - 1:
        temp = l_list[n - 2]
    else:
        temp = gcd(l_list[i - 1], r_list[i + 1])
    if temp > ans:
        ans = temp
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(x) for x in input().split()]
s = input()
for _ in range(q):
    l, r = [int(x) for x in input().split()]
    print(s[l-1:r].count("AC"))

Fixed submission:
from bisect import bisect_left

n, q = [int(x) for x in input().split()]
s = input()

index_list = []
i = 0
while i < n - 1:
    if s[i] == "A" and s[i + 1] == "C":
        index_list.append(i + 1)
        i += 2
    else:
        i += 1

for _ in range(q):
    l, r = [int(x) for x in input().split()]
    print(bisect_left(index_list, r) - bisect_left(index_list, l))
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
from itertools import product

a, b, q = [int(i) for i in input().split()]

s_list = [int(input()) for _ in range(a)]
t_list = [int(input()) for _ in range(b)]

n_list = [a, b]
s_t_list = [s_list, t_list]

for _ in range(q):
    x = int(input())

    temp_s_t_list = [[10 ** 11] * 2, [10 ** 11] * 2]
    for i in range(2):
        xi = bisect_left(s_t_list[i], x)

        if xi < n_list[i]:
            temp_s_t_list[i][0] = s_t_list[i][xi] - x
        if xi > 0:
            temp_s_t_list[i][1] = s_t_list[i][xi - 1] - x
    
    temp_list = []
    for s_x, t_x in list(product(temp_s_t_list[0], temp_s_t_list[1])):
        temp_s_x = s_x
        s_x = abs(s_x)
        temp_t_x = t_x
        t_x = abs(t_x)
        if temp_s_x // s_x == temp_t_x // t_x:
            temp_list.append(max(s_x, t_x))
        else:
            temp_list.append(s_x + t_x + min(s_x, t_x))
    print(min(temp_list))

Fixed submission:
from bisect import bisect_left

a, b, q = [int(i) for i in input().split()]

s_list = [int(input()) for _ in range(a)]
t_list = [int(input()) for _ in range(b)]

for _ in range(q):
    x = int(input())

    temp_s_t_list = [10 ** 11] * 4
    
    si = bisect_left(s_list, x)
    if si < a:
        temp_s_t_list[0] = s_list[si] - x
    if si > 0:
        temp_s_t_list[1] = s_list[si - 1] - x
    
    ti = bisect_left(t_list, x)
    if ti < b:
        temp_s_t_list[2] = t_list[ti] - x
    if ti > 0:
        temp_s_t_list[3] = t_list[ti - 1] - x

    ans = 10 ** 11 * 3
    for s_x, t_x in [(temp_s_t_list[0], temp_s_t_list[2]), (temp_s_t_list[0], temp_s_t_list[3]), (temp_s_t_list[1], temp_s_t_list[2]), (temp_s_t_list[1], temp_s_t_list[3])]:
        temp_s_x = s_x
        s_x = abs(s_x)
        temp_t_x = t_x
        t_x = abs(t_x)
        if temp_s_x // s_x == temp_t_x // t_x:
            temp = max(s_x, t_x)
        else:
            temp = s_x + t_x + min(s_x, t_x)

        if ans > temp:
            ans = temp
    print(ans)