func_code_string: #include <bits/stdc++.h>   using namespace std;   inline long long mod(long long n) { return (n % 1000000007); }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n;     vector<long long> v(n);     map<long long, long long> has, cnt;     for (long long i = 0; i < n; i++) {       cin >> v[i];     }     cin >> m;     for (long long i = 0; i < m; i++) {       long long x;       cin >> x;       has[v[x - 1]]++;     }     long long sz = has.size();     while (v.size() < n + 5 * m) {       for (long long i = n - 2; i >= 0; i--) v.push_back(v[i]);       for (long long i = 1; i < n; i++) v.push_back(v[i]);     }     set<long long> possible;     long long cur = 0;     long long match = 0;     for (long long i = 0; i < m; i++) {       if (cnt[v[i]] == has[v[i]] && cnt[v[i]] > 0) match--;       cnt[v[i]]++;       if (cnt[v[i]] == has[v[i]] && cnt[v[i]] > 0) match++;       cur += abs(v[i] - (i - 1 >= 0 ? v[i - 1] : 0));       if (i == 0) cur -= v[i];       if (match == sz) possible.insert(cur);     }     for (long long i = m; i < n + 5 * m; i++) {       if (cnt[v[i - m]] == has[v[i - m]] && cnt[v[i - m]] > 0) match--;       cnt[v[i - m]]--;       if (cnt[v[i - m]] == has[v[i - m]] && cnt[v[i - m]] > 0) match++;       if (cnt[v[i]] == has[v[i]] && cnt[v[i]] > 0) match--;       cnt[v[i]]++;       if (cnt[v[i]] == has[v[i]] && cnt[v[i]] > 0) match++;       cur += abs(v[i] - (i - 1 >= 0 ? v[i - 1] : 0));       cur -= abs(v[i - m + 1] - (i - m >= 0 ? v[i - m] : 0));       if (match == sz) possible.insert(cur);     }     if (possible.size() > 1)       cout << -1 <<   n ;     else if (possible.size() == 0)       cout << -1 <<   n ;     else       cout << *possible.begin() <<   n ;   }   