func_code_string: #include <bits/stdc++.h>   using namespace std;   int di[] = {0, 0, 1, -1, 1, 1, -1, -1};   int dj[] = {1, -1, 0, 0, 1, -1, 1, -1};   inline int calcMedian(vector<int> &vec) {     if (((int)vec.size()) % 2 == 1) {       return vec[((int)vec.size()) / 2];     }     return (vec[((int)vec.size()) / 2 - 1] + vec[((int)vec.size()) / 2]) / 2;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long init = 0, ans = 0;     int n, m;     cin >> n >> m;     vector<int> vec(m);     vector<vector<int> > adj(n);     for (int i = 0; i < m; ++i) {       cin >> vec[i];       --vec[i];       if (i && vec[i] != vec[i - 1]) {         ans = init += abs(vec[i] - vec[i - 1]);         adj[vec[i]].push_back(vec[i - 1]);         adj[vec[i - 1]].push_back(vec[i]);       }     }     for (int i = 0; i < n; ++i)       if (((int)adj[i].size())) {         sort(adj[i].begin(), adj[i].end());         int median = calcMedian(adj[i]);         long long tmp = 0;         for (int j = 0; j < ((int)adj[i].size()); ++j) {           tmp -= 0LL + abs(adj[i][j] - i);           tmp += 0LL + abs(adj[i][j] - median);         }         if (init + tmp < ans) ans = init + tmp;       }     cout << ans <<   n ;     return 0;   }   