func_code_string: #include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   int N, M;   int dist[200000];   int interval[200000];   int cnt[200000];   int main(void) {     cin >> N;     for (int i = 0; i < (int)(N); ++i) scanf( %d , dist + i);     for (int i = 0; i < (int)(N - 1); ++i) interval[i] = dist[i + 1] - dist[i];     cin >> M;     map<int, int> _ma;     for (int i = 0; i < (int)(M); ++i) {       int b;       scanf( %d , &b);       cnt[b - 1]++;       _ma[b - 1]++;     }     vector<int> candid;     for (int i = 1; i < (int)(N - 1); ++i)       if (cnt[i - 1] != cnt[i] or cnt[i] != cnt[i + 1])         if (cnt[i]) candid.push_back(i);     candid.push_back(0);     candid.push_back(N - 1);     long long res = -1;     for (int s : candid) {       for (int sd = -1; sd <= 1; sd += 2) {         map<int, int> ma = _ma;         int now = s, d = sd;         long long sum = 0;         ma[now]--;         if (ma[now] == 0) ma.erase(now);         while (true) {           if (ma.find(now) == ma.end() and ma.size() == 0) {             if (res == -1 or res == sum) {               res = sum;               break;             } else {               cout << -1 << endl;               return 0;             }           }           now = now + d;           if (!(0 <= (now) && (now) < (N))) {             d *= -1;             now += 2 * d;           }           sum += interval[min(now, now - d)];           if (ma[now] == 0) break;           ma[now]--;           if (ma[now] == 0) ma.erase(now);         }       }     }     cout << res << endl;     return 0;   }   