Language: C++

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))


int bisect_left(long long x,long long  a[],int left,int right){
   int mid;
   right++;
   while (left < right) {
      mid = (left + right) / 2;
      if (a[mid] < x) {
         left = mid + 1;
      } else {
         right = mid;
      }
   }
   return left;
}

int main(void) {
   int A,B,Q;
   scanf("%d%d%d", &A,&B,&Q);
   long long *shrine = (long long *)calloc((A+3) * sizeof(long long));
   long long *temple = (long long *)calloc((B+3) * sizeof(long long));
   shrine[0] = -1000000000000LL;
   temple[0] = -1000000000000LL;
   shrine[A+1] = 1000000000000LL;
   temple[A+1] = 1000000000000LL;
   for (int i = 1; i <= A; i++) {
      scanf("%lld", &shrine[i]);
   }
   for (int i = 1; i <= B; i++) {
      scanf("%lld", &temple[i]);
   }
   for (int i = 0; i < Q; i++) {
      long long now;
      scanf("%lld", &now);
      int s1 = bisect_left(now,shrine,0,A+1)-1;
      int s2 = bisect_left(now,shrine,0,A+1);
      int t1 = bisect_left(now,temple,0,A+1)-1;
      int t2 = bisect_left(now,temple,0,A+1);
      long long ans = 100000000000000LL;
      ans = MIN(ans,ABS(shrine[s1]-now) + ABS(shrine[s1]-temple[t1]));
      ans = MIN(ans,ABS(shrine[s1]-now) + ABS(shrine[s1]-temple[t2]));
      ans = MIN(ans,ABS(shrine[s2]-now) + ABS(shrine[s2]-temple[t1]));
      ans = MIN(ans,ABS(shrine[s2]-now) + ABS(shrine[s2]-temple[t2]));
      ans = MIN(ans,ABS(temple[t1]-now) + ABS(shrine[s1]-temple[t1]));
      ans = MIN(ans,ABS(temple[t1]-now) + ABS(shrine[s2]-temple[t1]));
      ans = MIN(ans,ABS(temple[t2]-now) + ABS(shrine[s1]-temple[t2]));
      ans = MIN(ans,ABS(temple[t2]-now) + ABS(shrine[s2]-temple[t2]));
      printf("%lld\n",ans);
   }
   return 0;
}
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))


int bisect_left(long long x,long long  a[],int left,int right){
   int mid;
   right++;
   while (left < right) {
      mid = (left + right) / 2;
      if (a[mid] < x) {
         left = mid + 1;
      } else {
         right = mid;
      }
   }
   return left;
}

int main(void) {
   int A,B,Q;
   scanf("%d%d%d", &A,&B,&Q);
   long long *shrine = (long long *)malloc((A+2) * sizeof(long long));
   long long *temple = (long long *)malloc((B+2) * sizeof(long long));
   shrine[0] = -1000000000000LL;
   temple[0] = -1000000000000LL;
   shrine[A+1] = 1000000000000LL;
   temple[A+1] = 1000000000000LL;
   for (int i = 1; i <= A; i++) {
      scanf("%lld", &shrine[i]);
   }
   for (int i = 1; i <= B; i++) {
      scanf("%lld", &temple[i]);
   }
   for (int i = 0; i < Q; i++) {
      long long now;
      scanf("%lld", &now);
      int s1 = bisect_left(now,shrine,0,A+1)-1;
      int s2 = bisect_left(now,shrine,0,A+1);
      int t1 = bisect_left(now,temple,0,A+1)-1;
      int t2 = bisect_left(now,temple,0,A+1);
      long long ans = 10000000000000LL;
      ans = MIN(ans,ABS(shrine[s1]-now) + ABS(shrine[s1]-temple[t1]));
      ans = MIN(ans,ABS(shrine[s1]-now) + ABS(shrine[s1]-temple[t2]));
      ans = MIN(ans,ABS(shrine[s2]-now) + ABS(shrine[s2]-temple[t1]));
      ans = MIN(ans,ABS(shrine[s2]-now) + ABS(shrine[s2]-temple[t2]));
      ans = MIN(ans,ABS(temple[t1]-now) + ABS(shrine[s1]-temple[t1]));
      ans = MIN(ans,ABS(temple[t1]-now) + ABS(shrine[s2]-temple[t1]));
      ans = MIN(ans,ABS(temple[t2]-now) + ABS(shrine[s1]-temple[t2]));
      ans = MIN(ans,ABS(temple[t2]-now) + ABS(shrine[s2]-temple[t2]));
      printf("%lld\n",ans);
   }
   


}


Compiler output:
a.cc: In function 'int main()':
a.cc:26:43: error: too few arguments to function 'void* calloc(size_t, size_t)'
   26 |    long long *shrine = (long long *)calloc((A+3) * sizeof(long long));
      |                                     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/std_abs.h:38,
                 from /usr/include/c++/14/cmath:49,
                 from /usr/include/c++/14/math.h:36,
                 from a.cc:3:
/usr/include/stdlib.h:675:14: note: declared here
  675 | extern void *calloc (size_t __nmemb, size_t __size)
      |              ^~~~~~
a.cc:27:43: error: too few arguments to function 'void* calloc(size_t, size_t)'
   27 |    long long *temple = (long long *)calloc((B+3) * sizeof(long long));
      |                                     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/stdlib.h:675:14: note: declared here
  675 | extern void *calloc (size_t __nmemb, size_t __size)
      |              ^~~~~~
a.cc: At global scope:
a.cc:67:5: error: redefinition of 'int bisect_left(long long int, long long int*, int, int)'
   67 | int bisect_left(long long x,long long  a[],int left,int right){
      |     ^~~~~~~~~~~
a.cc:9:5: note: 'int bisect_left(long long int, long long int*, int, int)' previously defined here
    9 | int bisect_left(long long x,long long  a[],int left,int right){
      |     ^~~~~~~~~~~
a.cc:81:5: error: redefinition of 'int main()'
   81 | int main(void) {
      |     ^~~~
a.cc:23:5: note: 'int main()' previously defined here
   23 | int main(void) {
      |     ^~~~