Language: C++

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

const ll INF = 1e18;

int main() {
    int a, b, q;
    cin >> a >> b >> q;
    ll s[a+2], t[b+2], u[2][2];
    s[0] = t[0] = -INF;
    for(int i = 1; i <= a; i++) {
        cin >> s[i];
    }
    for(int i = 1; i <= b; i++) {
        cin >> t[i];
    }
    s[a+1] = t[b+1] = INF;

    rep(roop, q) {
        ll x;
        cin >> x;

        int* sepos = lower_bound(s, s+a+2, x);
        int n1 = distance(s, sepos);
        u[0][1] = s[n1];
        u[0][0] = s[n1-1];
        int* tepos = lower_bound(t, t+b+2, x);
        int n2 = distance(t, tepos);
        u[1][1] = t[n2];
        u[1][0] = t[n2-1];

        ll dist = 0;
        ll ans = INF;
        rep(i, 2) {
            rep(j, 2) {
                rep(k, 2) {
                   dist += abs(u[i][j] - x) + abs(u[i][j] - u[i^1][k]);
                   ans = min(ans, dist);
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:33: error: cannot convert 'long long int*' to 'int*' in initialization
   30 |         int* sepos = lower_bound(s, s+a+2, x);
      |                      ~~~~~~~~~~~^~~~~~~~~~~~~
      |                                 |
      |                                 long long int*
a.cc:31:26: error: no matching function for call to 'distance(ll [(a + 2)], int*&)'
   31 |         int n1 = distance(s, sepos);
      |                  ~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note: candidate: 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator)'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note:   template argument deduction/substitution failed:
a.cc:31:26: note:   deduced conflicting types for parameter '_InputIterator' ('long long int*' and 'int*')
   31 |         int n1 = distance(s, sepos);
      |                  ~~~~~~~~^~~~~~~~~~
a.cc:34:33: error: cannot convert 'long long int*' to 'int*' in initialization
   34 |         int* tepos = lower_bound(t, t+b+2, x);
      |                      ~~~~~~~~~~~^~~~~~~~~~~~~
      |                                 |
      |                                 long long int*
a.cc:35:26: error: no matching function for call to 'distance(ll [(b + 2)], int*&)'
   35 |         int n2 = distance(t, tepos);
      |                  ~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note: candidate: 'template<class _InputIterator> constexpr typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::distance(_InputIterator, _InputIterator)'
  148 |     distance(_InputIterator __first, _InputIterator __last)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:148:5: note:   template argument deduction/substitution failed:
a.cc:35:26: note:   deduced conflicting types for parameter '_InputIterator' ('long long int*' and 'int*')
   35 |         int n2 = distance(t, tepos);
      |                  ~~~~~~~~^~~~~~~~~~