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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    ll a,b,q, x, ans; cin >> a >> b >> q;
    vll jinja(a), tera(b);
    rep(i,a) cin >> jinja[i];
    rep(i,b) cin >> tera[i];
    jinja.push_back(infll);
    jinja.push_back(-infll);
    tera.push_back(infll);
    tera.push_back(-infll);
    sort(all(jinja));
    sort(all(tera));

    rep(i,q) {
        ans = infll;
        cin >> x;
        ll near_west_jinja, near_west_tera, near_east_jinja, near_east_tera;
        near_west_jinja = *--lower_bound(all(jinja), x);
        near_west_tera = *--lower_bound(all(tera), x);
        near_east_jinja = *upper_bound(all(jinja), x);
        near_east_tera = *upper_bound(all(tera), x);

        ll dist_west;
        if(near_west_tera == -infll && near_west_jinja == -infll) dist_west = infll;
        else if(near_west_tera == -infll) dist_west = near_east_tera-near_west_jinja + x-near_west_jinja;
        else if(near_west_jinja == -infll) dist_west = near_east_jinja-near_west_tera + x-near_west_tera;
        else dist_west = max(x-near_west_jinja, x-near_west_tera);
        ll dist_east;
        if(near_east_jinja == infll && near_east_tera == infll) dist_east = infll;
        else if(near_east_tera == infll) dist_east = near_east_jinja-x + near_east_jinja-near_west_tera;
        else if(near_east_jinja == infll) dist_east = near_east_tera-x + near_east_tera-near_west_jinja;
        else dist_east = max(near_east_jinja-x, near_east_tera-x);
        chmin(ans, dist_east);
        chmin(ans, dist_west);
//        debug(dist_east);
//        debug(dist_west);
//        debug(near_west_jinja);debug(near_west_tera);debug(near_east_jinja);debug(near_east_tera);
        cout << ans << '\n';
    }

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}