func_code_string: #include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int inf = 1e9 + 7;   const ll longinf = 1LL << 60;   const ll mod = 1e9 + 7;   int main() {     int h, w, n, q;     cin >> h >> w >> n >> q;     vector<int> v[h];     for (int i = (int)(0); i < (int)(n); ++i) {       int x, y;       cin >> x >> y;       --x;       --y;       v[x].push_back(y);     }     for (int i = (int)(0); i < (int)(h); ++i) sort(v[i].begin(), v[i].end());     vector<ll> ok;     ok.push_back(-longinf);     ok.push_back(longinf);     for (int i = (int)(0); i < (int)(q); ++i) {       int x;       cin >> x;       --x;       ok.push_back(x);     }     sort(ok.begin(), ok.end());     ll pl = 0, pr = 0;     ll dp[2][202020];     for (int i = (int)(0); i < (int)(2); ++i)       for (int j = (int)(0); j < (int)(202020); ++j) dp[i][j] = longinf;     dp[0][1] = dp[1][1] = 0;     if (v[0].size()) {       pl = v[0][0];       pr = v[0].back();       dp[0][1] = 2 * pr - pl;       dp[1][1] = pr;     }     int maxh = 1;     for (int i = (int)(1); i < (int)(h); ++i) {       if (v[i].empty()) {         dp[0][i + 1] = dp[0][i] + 1;         dp[1][i + 1] = dp[1][i] + 1;         continue;       }       int nl = v[i][0], nr = v[i].back();       auto itr = lower_bound(ok.begin(), ok.end(), pl);       dp[0][i + 1] = min(dp[0][i + 1], dp[0][i] + abs(*itr - pl) +                                            abs(nr - *itr) + abs(nr - nl) + 1);       dp[1][i + 1] = min(dp[1][i + 1], dp[0][i] + abs(*itr - pl) +                                            abs(nl - *itr) + abs(nr - nl) + 1);       --itr;       dp[0][i + 1] = min(dp[0][i + 1], dp[0][i] + abs(*itr - pl) +                                            abs(nr - *itr) + abs(nr - nl) + 1);       dp[1][i + 1] = min(dp[1][i + 1], dp[0][i] + abs(*itr - pl) +                                            abs(nl - *itr) + abs(nr - nl) + 1);       itr = lower_bound(ok.begin(), ok.end(), pr);       dp[0][i + 1] = min(dp[0][i + 1], dp[1][i] + abs(*itr - pr) +                                            abs(nr - *itr) + abs(nr - nl) + 1);       dp[1][i + 1] = min(dp[1][i + 1], dp[1][i] + abs(*itr - pr) +                                            abs(nl - *itr) + abs(nr - nl) + 1);       --itr;       dp[0][i + 1] = min(dp[0][i + 1], dp[1][i] + abs(*itr - pr) +                                            abs(nr - *itr) + abs(nr - nl) + 1);       dp[1][i + 1] = min(dp[1][i + 1], dp[1][i] + abs(*itr - pr) +                                            abs(nl - *itr) + abs(nr - nl) + 1);       pl = nl;       pr = nr;       maxh = max(i + 1, maxh);     }     cout << min(dp[0][maxh], dp[1][maxh]) << endl;     return 0;   }   