Problem:
Score : 400 points

Problem Statement

Along a road running in an east-west direction, there are A shrines and B temples.
The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meters from the west end of the road.

Answer the following Q queries:

Query i (1 \leq i \leq Q): If we start from a point at a distance of x_i meters from the west end of the road and freely travel along the road, what is the minimum distance that needs to be traveled in order to visit one shrine and one temple? (It is allowed to pass by more shrines and temples than required.)

Constraints

1 \leq A, B \leq 10^5

1 \leq Q \leq 10^5

1 \leq s_1 < s_2 < ... < s_A \leq 10^{10}

1 \leq t_1 < t_2 < ... < t_B \leq 10^{10}

1 \leq x_i \leq 10^{10}

s_1, ..., s_A, t_1, ..., t_B, x_1, ..., x_Q are all different.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B Q
s_1
:
s_A
t_1
:
t_B
x_1
:
x_Q

Output

Print Q lines. The i-th line should contain the answer to the i-th query.

Sample Input 1

2 3 4
100
600
400
900
1000
150
2000
899
799

Sample Output 1

350
1400
301
399

There are two shrines and three temples. The shrines are located at distances of 100, 600 meters from the west end of the road, and the temples are located at distances of 400, 900, 1000 meters from the west end of the road.

Query 1: If we start from a point at a distance of 150 meters from the west end of the road, the optimal move is first to walk 50 meters west to visit a shrine, then to walk 300 meters east to visit a temple.

Query 2: If we start from a point at a distance of 2000 meters from the west end of the road, the optimal move is first to walk 1000 meters west to visit a temple, then to walk 400 meters west to visit a shrine. We will pass by another temple on the way, but it is fine.

Query 3: If we start from a point at a distance of 899 meters from the west end of the road, the optimal move is first to walk 1 meter east to visit a temple, then to walk 300 meters west to visit a shrine.

Query 4: If we start from a point at a distance of 799 meters from the west end of the road, the optimal move is first to walk 199 meters west to visit a shrine, then to walk 200 meters west to visit a temple.

Sample Input 2

1 1 3
1
10000000000
2
9999999999
5000000000

Sample Output 2

10000000000
10000000000
14999999998

The road is quite long, and we may need to travel a distance that does not fit into a 32-bit integer.

Solution in Ruby (2.7.1) (judge verdict: Runtime Error)

a, b, q = gets.chomp.split.map(&:to_i)
# sarr = Array.new(a + 4); sarr[0] = -114514; sarr[1] = -114514; sarr[-1] = 114514; sarr[-2] = 114514
# tarr = Array.new(b + 4); tarr[0] = -114514; tarr[1] = -114514; tarr[-1] = 114514; tarr[-2] = 114514

# 2.upto(a + 1) do |i|
# 	sarr[i] = gets.chomp.to_i
# end
# 2.upto(b + 1) do |i|
# 	tarr[i] = gets.chomp.to_i
# end
sarr = Array.new(a)
tarr = Array.new(b)
a.times do |i|
	sarr[i] = gets.chomp.to_i
end
b.times do |i|
	tarr[i] = gets.chomp.to_i
end

sarr = sarr.sort
tarr = tarr.sort

starr = Array.new(a + b + 8);
starr[0] = [-114514810810, true]; starr[1] = [-114514810810, true]; starr[2] = [-114514810810, false]; starr[3] = [-114514810810, false]
starr[-4] = [114514818100, true]; starr[-3] = [114514810810, true]; starr[-2] = [114514810810, false]; starr[-1] = [114514810810, false]


si = 0
ti = 0
while si < sarr.length || ti < tarr.length
	if ti > tarr.length || (si < sarr.length && sarr[si] < tarr[ti])
		starr[si + ti + 4] = [sarr[si], true]
		si += 1
	else
		starr[si + ti + 4] = [tarr[ti], false]
		ti += 1
	end
end


def binarys(x, arr)
	l = 0
	r = arr.length - 1
	prev = -114514
	while l < r
		mid = (l + r) / 2
		return mid if arr[mid][0] == x || prev == mid
		if arr[mid][0] < x 
			l = mid
		else
			r = mid
		end
		prev = mid
	end
	return prev
end

#p starr
q.times do
	x = gets.chomp.to_i
	ind = binarys(x, starr)

	#現在地
	if starr[ind][0] == x
		l = 114514
		(ind-1).downto(0) do |i|
			if starr[i][1] != starr[ind][1]
				l = starr[i][0]
				break
			end
		end
		r = 114514
		(ind+1).upto(starr.length-1) do |i|
			if starr[i][1] != starr[ind][1]
				r = starr[i][0]
				break
			end
		end
		puts ([l, r].min - x).abs
		exit
	end

	
	# 左側の神社と寺を2つ列挙
	ls = nil
	lt = nil
	ind.downto(0) do |i|
		if starr[i][1]
			ls = (starr[i][0] - x).abs if ls == nil
		else
			lt = (starr[i][0] - x).abs if lt == nil
		end
		break if ls != nil && lt != nil
	end

	#右側
	rs = nil
	rt = nil
	(ind+1).upto(starr.length-1) do |i|
		if starr[i][1]
			rs = (starr[i][0] - x).abs if rs == nil
		else
			rt = (starr[i][0] - x).abs if rt == nil
		end
		break if rs != nil && rt != nil
	end


	#左左
	ll = [ls, lt].max
	rr = [rs, rt].max

	lr = ls < lt ? ls * 2 + rt : lt * 2 + rs
	rl = rs < rt ? rs * 2 + lt : rt * 2 + ls

	# lr = ls[0] < lt[0] ? ls[0] * 2 + rt[0] : lt[0] * 2 + rs[0]
	# rl = rs[0] < rt[0] ? rs[0] * 2 + lt[0] : rt[0] * 2 + ls[0]

	
	# puts "ind:#{ind}"
	# puts "lt:#{lt} ls:#{ls} rt:#{rt} rs:#{rs}"
	# puts "ll:#{ll} rr:#{rr} lr:#{lr} rl:#{rl}"
	puts [ll, rr, lr, rl].min
	#puts
end