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.3.3) (judge verdict: Runtime Error)

#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

ll A,B,Q;
vl s,t,x;

signed main(){
	cin >> A >> B >> Q;
	s.resize(A);t.resize(B);x.resize(Q);
	FOR(i,0,A)cin >> s[i];
	FOR(i,0,B)cin >> t[i];
	FOR(i,0,Q)cin >> x[i];
	vl S(A);
	vl T(B);
	FOR(i,0,A){
		if(s[i] < t[0]){
			S[i] = t[0] - s[i];
			continue;
		}
		if(t[t.size()-1] < s[i]){
			S[i] = s[i] - t[t.size()-1];
		}
		ll tmp1 = *upper_bound(ALL(t),s[i]);
		ll tmp2 = *(upper_bound(ALL(t),s[i])-1);
		S[i] = min(abs(tmp1-s[i]),abs(tmp2-s[i]));
	}
	FOR(i,0,B){
		if(t[i] < s[0]){
			T[i] = s[0] - t[i];
			continue;
		}
		if(s[s.size()-1] < t[i]){
			T[i] = t[i] - s[t.size()-1];
		}
		ll tmp1 = *upper_bound(ALL(s),t[i]);
		ll tmp2 = *(upper_bound(ALL(s),t[i])-1);
		T[i] = min(abs(tmp1-t[i]),abs(tmp2-t[i]));
	}
	FOR(i,0,Q){
		ll idx1 = upper_bound(ALL(s),x[i]) - s.begin();
		ll idx2 = upper_bound(ALL(t),x[i]) - t.begin();
		vl tmp1,tmp2;
		if(idx1 < s.size())tmp1.pb(idx1);
		if(idx2 < t.size())tmp2.pb(idx2);
		if(idx1 != 0)tmp1.pb(idx1-1);
		if(idx2 != 0)tmp2.pb(idx2-1);
		ll ans = LINF;
		FOR(j,0,tmp1.size()){
			ll tmp = abs(x[i] - s[tmp1[j]]) + S[tmp1[j]];
			chmin(ans,tmp);
		}
		FOR(j,0,tmp2.size()){
			ll tmp = abs(x[i] - t[tmp2[j]]) + T[tmp2[j]];
			chmin(ans,tmp);
		}
		cout << ans << endl;
	}
}