Language: C++

#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
//const double EPS = 1e(-12);
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

ll s[100010];
ll t[100010];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);

    int A, B, Q;
    cin >> A >> B >> Q;

    for (int i = 0; i < A; ++i)
    {
        cin >> s[i];
    }
    s[A] = 10000000000;
    for (int i = 0; i < B; ++i)
    {
        cin >> t[i];
    }
    t[B] = 10000000000;

    for (int i = 0; i < Q; ++i)
    {
        ll x;
        cin >> x;

        ll t1 = lower_bound(s, s + A, x) - s;

        ll t2 = lower_bound(t, t + B, x) - t;

        if (t1 == A && t2 == B)
        {
            cout << x - min(s[t1 - 1], t[t2 - 1]) << endl;
        }
        else if (t1 == A)
        {
            //まず神社を訪れる場合
            ll minV = 10000000000;

            ll sum = 0;
            sum += abs(x - s[t1 - 1]);

            sum += min(abs(s[t1 - 1] - t[t2]), abs(s[t1 - 1] - t[t2 - 1]));

            minV = min({minV, abs(x - t[t2]) + abs(t[t2] - s[t1 - 1]), abs(x - t[t2 - 1] + abs(t[t2 - 1] - s[t1 - 1]))});

            cout << minV << endl;

            //寺を訪れる
        }
        else if (t2 == B)
        {
            ll minV = 10000000000;

            ll sum = 0;
            sum += abs(x - t[t2 - 1]);

            sum += min(abs(t[t2 - 1] - s[t1]), abs(t[t2 - 1] - s[t1 - 1]));

            minV = min({minV, abs(x - s[t1]) + abs(s[t1] - t[t2 - 1]), abs(x - s[t1 - 1] + abs(s[t1 - 1] - t[t2 - 1]))});

            cout << minV << endl;
        }
        else
        {
            ll minV = 10000000000;

            ll sum = 0;
            if (t1 > 0 && t2 > 0)
            {
                sum += abs(x - s[t1 - 1]);

                sum += min(abs(s[t1 - 1] - t[t2]), abs(s[t1 - 1] - t[t2 - 1]));

                minV = min({minV, abs(x - t[t2]) + abs(t[t2] - s[t1 - 1]), abs(x - t[t2 - 1] + abs(t[t2 - 1] - s[t1 - 1]))});

                sum = 0;
                sum += abs(x - t[t2 - 1]);

                sum += min(abs(t[t2 - 1] - s[t1]), abs(t[t2 - 1] - s[t1 - 1]));

                minV = min({minV, abs(x - s[t1]) + abs(s[t1] - t[t2 - 1]), abs(x - s[t1 - 1] + abs(s[t1 - 1] - t[t2 - 1]))});

                cout << minV << endl;
            }
        }
        return 0;
    }

Compiler output:
a.cc: In function 'int main()':
a.cc:129:6: error: expected '}' at end of input
  129 |     }
      |      ^
a.cc:44:1: note: to match this '{'
   44 | {
      | ^