func_code_string: #include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   const int mxN = 2e5 + 5;   const long long inf = 1e18;   template <class T>   T gcd(T a, T b) {     return ((b == 0) ? a : gcd(b, a % b));   }   pair<int, long long> dp[2][4];   long long mn[mxN], mx[mxN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m, k, q;     cin >> n >> m >> k >> q;     vector<pair<long long, long long>> p(k);     for (int i = 0; i < (int)(mxN); i++) mn[i] = inf, mx[i] = -inf;     long long h = 0;     for (int i = 0; i < (int)(k); i++) {       cin >> p[i].first >> p[i].second;       mn[p[i].first] = min(mn[p[i].first], p[i].second);       mx[p[i].first] = max(mx[p[i].first], p[i].second);       h = max(h, p[i].first);     }     vector<int> b(q);     for (int i = 0; i < (int)(q); i++) cin >> b[i];     sort(b.begin(), b.end());     for (int i = 0; i < (int)(2); i++)       for (int j = 0; j < (int)(4); j++) dp[i][j] = make_pair(0, inf);     long long ans = 1e18;     if (mn[1] == inf) {       int pos = 1;       auto it = lower_bound(b.begin(), b.end(), pos);       if (it != b.end()) dp[0][1] = make_pair(*it, (*it - pos));       if (it != b.begin()) {         it--;         dp[0][0] = make_pair(*it, (pos - *it));       }       ans = 0;     } else {       int pos = mx[1];       auto it = lower_bound(b.begin(), b.end(), pos);       if (it != b.end()) dp[0][3] = make_pair(*it, (*it - pos) + (pos - 1));       if (it != b.begin()) {         it--;         dp[0][2] = make_pair(*it, (pos - *it) + (pos - 1));       }       ans = pos - 1;     }     int cnt = 1;     for (int i = (int)(2); i < (int)(mxN); i++)       if (mn[i] != inf) {         int cr = cnt & 1, pr = 1 - cr;         long long A = 1e18, B = 1e18;         for (int j = 0; j < (int)(4); j++)           if (dp[pr][j].second != inf) {             A = min(A, dp[pr][j].second + abs(mx[i] - dp[pr][j].first) +                            (mx[i] - mn[i]));           }         for (int j = 0; j < (int)(4); j++)           if (dp[pr][j].second != inf) {             B = min(B, dp[pr][j].second + abs(mn[i] - dp[pr][j].first) +                            (mx[i] - mn[i]));           }         int pos = mn[i];         auto it = lower_bound(b.begin(), b.end(), pos);         if (it != b.end()) dp[cr][1] = make_pair(*it, A + (*it - pos));         if (it != b.begin()) {           it--;           dp[cr][0] = make_pair(*it, A + (pos - *it));         }         pos = mx[i];         it = lower_bound(b.begin(), b.end(), pos);         if (it != b.end()) dp[cr][3] = make_pair(*it, B + (*it - pos));         if (it != b.begin()) {           it--;           dp[cr][2] = make_pair(*it, B + (pos - *it));         }         ans = min(A, B);         for (int j = 0; j < (int)(4); j++) dp[pr][j] = make_pair(0, inf);         cnt++;       }     cout << ans + h - 1 <<   n ;     return 0;   }   