func_code_string: #include <bits/stdc++.h>   using namespace std;   struct __s {     __s() {       if (1) {         ios_base::Init i;         cin.sync_with_stdio(0);         cin.tie(0);       }     }     ~__s() {       if (!1)         fprintf(stderr,  Execution time: %.3lf s. n ,                 (double)clock() / CLOCKS_PER_SEC);       long long n;       cin >> n;     }   } __S;   int main(void) {     long long n, m;     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < (long long)(n); i++) {       cin >> a[i];     }     cin >> m;     long long b = 0;     for (long long i = 0; i < (long long)(m); i++) {       long long x;       cin >> x;       b += x - 1;     }     vector<long long> c;     while (c.size() < 3 * max(m, n)) {       for (long long i = 0; i < (long long)(n - 1); i++) {         c.push_back(i);       }       for (long long i = 0; i < (long long)(n - 1); i++) {         c.push_back(n - 1 - i);       }     }     long long d = 0;     for (long long i = 0; i < (long long)(m); i++) {       b -= c[i];       if (i) d += abs(a[c[i]] - a[c[i - 1]]);     }     set<long long> ans;     for (long long i = m; i < c.size(); i++) {       if (b == 0) {         ans.insert(d);       }       b -= c[i];       b += c[i - m];       d -= abs(a[c[i - m]] - a[c[i - m + 1]]);       d += abs(a[c[i]] - a[c[i - 1]]);     }     if (ans.size() != 1)       cout << -1 <<   n ;     else       cout << *ans.begin() <<   n ;     return 0;   }   