Language: C++

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b, q;
	cin >> a >> b >> q;
	vll s(a), t(b);
	rep(i, a) cin >> s[i];
	rep(i, b) cin >> t[i];
	s.pb(1e11);
	s.insert(s.begin(), -1e11);
	t.pb(1e11);
	t.insert(t.begin(), -1e11);
	rep(i, q){
		ll ans = LONG_LONG_MAX;
		ll x; cin>>x;
		ll S[2], T[2];
		ll left, right;
		right = upper_bound(s.begin(), s.end());
		left = right-1;
		S[0] = s[left], S[1] = s[right];
		right = upper_bound(t.begin(), t.end());
		left = right-1;
		T[0] = t[left], T[1] = t[right];
		rep(j, 2){
			rep(k, 2){
				ll mini, sum=0;
				mini = min(abs(x-S[j]), abs(x-T[k]));
				sum = mini + abs(S[j]-T[k]);
				ans = min(ans, sum);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:42:36: error: no matching function for call to 'upper_bound(std::vector<long long int>::iterator, std::vector<long long int>::iterator)'
   42 |                 right = upper_bound(s.begin(), s.end());
      |                         ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:2019:5: note: candidate: 'template<class _FIter, class _Tp> _FIter std::upper_bound(_FIter, _FIter, const _Tp&)'
 2019 |     upper_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:2019:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:2050:5: note: candidate: 'template<class _FIter, class _Tp, class _Compare> _FIter std::upper_bound(_FIter, _FIter, const _Tp&, _Compare)'
 2050 |     upper_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:2050:5: note:   candidate expects 4 arguments, 2 provided
a.cc:45:36: error: no matching function for call to 'upper_bound(std::vector<long long int>::iterator, std::vector<long long int>::iterator)'
   45 |                 right = upper_bound(t.begin(), t.end());
      |                         ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:2019:5: note: candidate: 'template<class _FIter, class _Tp> _FIter std::upper_bound(_FIter, _FIter, const _Tp&)'
 2019 |     upper_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:2019:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:2050:5: note: candidate: 'template<class _FIter, class _Tp, class _Compare> _FIter std::upper_bound(_FIter, _FIter, const _Tp&, _Compare)'
 2050 |     upper_bound(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:2050:5: note:   candidate expects 4 arguments, 2 provided