Language: C++

var lines = [];
var a,b,q,s,t,x;

var readline=require("readline");

var rl = readline.createInterface({
    input: process.stdin,
    output:process.stdout,
});

rl.on('line',function(x){
    lines.push(x);
});

rl.on('close',function(){
    var tmp = lines.shift();
    a = Number(tmp.split(" ")[0]);
    b = Number(tmp.split(" ")[1]);
    q = Number(tmp.split(" ")[2]);

    s = Array(a);
    t = Array(b);
    x = Array(q);

    for(var i=0;i<a;i++){
        s[i] = lines.shift();
        s[i] = Number(s[i]);
    }
    s.sort(function(a,b){return(a-b);});
    
    for(var i=0;i<b;i++){
        t[i] = lines.shift();
        t[i] = Number(t[i]);
    }
    t.sort(function(a,b){return(a-b);});

    for(var i=0;i<q;i++){
        x[i] = lines.shift();
        x[i] = {
           start_location: Number(x[i]),
           minimum:Infinity,
        }
    }

    dfs(0,[]);
    for(var i=0;i<q;i++){console.log(x[i].minimum);}
});

function dfs(n,comb){
    if(2 === n){calc(comb);return(0);}
    
    var finish = a>b?finish=a:finish=b;
    for(var i=0;i<finish;i++){
        comb[n]=i;
        dfs(n+1,comb);
    }
}

function calc(comb){
    if(s[comb[0]] !== undefined && t[comb[1]] !== undefined){
        for(var i=0;i<q;i++){
            
            if((s[comb[0]] < x[i].start_location && x[i].start_location < t[comb[1]]) || t[comb[1]] < x[i] && x[i] < s[comb[0]]){
                if(Math.abs(x[i].start_location - s[comb[0]]) < Math.abs(x[i].start_location - t[comb[1]])){
                    result = Math.abs(x[i].start_location - s[comb[0]])*2 + Math.abs(x[i].start_location - t[comb[1]]);
                }
                else{
                    result = Math.abs(x[i].start_location - s[comb[0]]) + Math.abs(x[i].start_location - t[comb[1]])*2;
                }
            }
            else{
                Math.abs(x[i].start_location - s[comb[0]]) > Math.abs(x[i].start_location - t[comb[1]]) ? result = Math.abs(x[i].start_location - s[comb[0]]) : result = Math.abs(x[i].start_location - t[comb[1]]);
            }
            if(result < x[i].minimum){x[i].minimum = result;}
        }
    }
}


Compiler output:
a.cc:11:7: warning: multi-character character constant [-Wmultichar]
   11 | rl.on('line',function(x){
      |       ^~~~~~
a.cc:15:7: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   15 | rl.on('close',function(){
      |       ^~~~~~~
a.cc:1:1: error: 'var' does not name a type
    1 | var lines = [];
      | ^~~
a.cc:2:1: error: 'var' does not name a type
    2 | var a,b,q,s,t,x;
      | ^~~
a.cc:4:1: error: 'var' does not name a type
    4 | var readline=require("readline");
      | ^~~
a.cc:6:1: error: 'var' does not name a type
    6 | var rl = readline.createInterface({
      | ^~~
a.cc:9:2: error: expected unqualified-id before ')' token
    9 | });
      |  ^
a.cc:11:1: error: 'rl' does not name a type
   11 | rl.on('line',function(x){
      | ^~
a.cc:13:2: error: expected unqualified-id before ')' token
   13 | });
      |  ^
a.cc:15:1: error: 'rl' does not name a type
   15 | rl.on('close',function(){
      | ^~
a.cc:47:2: error: expected unqualified-id before ')' token
   47 | });
      |  ^
a.cc:49:1: error: 'function' does not name a type; did you mean 'union'?
   49 | function dfs(n,comb){
      | ^~~~~~~~
      | union
a.cc:59:1: error: 'function' does not name a type; did you mean 'union'?
   59 | function calc(comb){
      | ^~~~~~~~
      | union