malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void ipgraph(long long n, long long m);   vector<vector<long long>> v;   vector<bool> vis;   long long p = pow(10, 9) + 7;   long long power(long long a, long long b, long long p) {     if (b == 0) return 1;     long long c = power(a, b / 2, p);     if (b % 2 == 0)       return ((c * c) % p);     else       return ((((c * c) % p) * a) % p);   }   long long sumod(long long n) {     long long ans = 0;     while (n) {       ans += n % 10;       n /= 10;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t, i, j, n, m, k, l;     t = 1;     while (t--) {       long long a, b, c;       cin >> a >> b >> c;       vector<long long> v;       for (long long i = 1; i < 82; i++) {         if (b * power(i, a, p) + c < pow(10, 9) && b * power(i, a, p) + c > 0 &&             sumod(b * power(i, a, p) + c) == i)           v.push_back(b * power(i, a, p) + c);       }       cout << v.size() <<   n ;       for (auto x : v) {         cout << x <<    ;       }       cout <<   n ;       ;     }     cerr << endl          <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;     return 0;   }   void ipgraph(long long n, long long m) {     v.assign(n, {});     vis.assign(n, 0);     long long x, y;     for (long long i = 0; i < m; i++) {       cin >> x >> y;       x--, y--;       v[x].push_back(y);       v[y].push_back(x);     }   }
#include <bits/stdc++.h>   using namespace std;   inline void in(int &x) {     x = 0;     int f = 1;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = x * 10 + s - 48;       s = getchar();     }     x *= f;   }   inline void out(int x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) out(x / 10);     putchar(x % 10 + 48);   }   int a[200005];   int main() {     int n, i, maxi = 0, p = -1;     in(n);     for (i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > maxi) {         maxi = a[i];         p = i;       }     }     for (i = p - 1; i >= 0; i--) {       if (a[i] >= a[i + 1]) {         cout <<  NO ;         return 0;       }     }     for (i = p + 1; i < n; i++) {       if (a[i] >= a[i - 1]) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   const double pi = acos(-1);   using namespace std;   vector<int> v;   int c[1000000];   int main() {     int n;     double h;     cin >> n >> h;     double s = h / (2 * double(n));     for (int i = 1; i < n; i++) {       printf( %.10f n , sqrt(s * 2 * h * i));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, num[105], ans = 0, i;   int main() {     scanf( %d , &n);     for (int j = 1; j <= n; ++j) scanf( %d , &num[j]);     if (n % 2 == 0 || n < 3) {       printf( -1 n );       return 0;     }     for (int i = n; i >= 3; i -= 2) {       int max_n = max(num[i], num[i - 1]);       if (max_n <= 0) continue;       ans += max_n;       num[i] -= max_n;       num[i - 1] -= max_n;       num[(i - 1) / 2] -= max_n;     }     if (num[1] > 0) ans += num[1];     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   vector<int> adj[100007];   int dis[100007];   void bfs() {     queue<int> q;     bool vis[100007];     memset(vis, false, sizeof(vis));     dis[1] = 1;     vis[1] = true;     q.push(1);     while (!q.empty()) {       int s = q.front();       q.pop();       for (auto u : adj[s]) {         if (vis[u]) continue;         vis[u] = true;         dis[u] = dis[s] + 1;         q.push(u);       }     }   }   void solve() {     int n;     cin >> n;     for (int i = 2; i <= n; ++i) {       int node;       cin >> node;       adj[node].emplace_back(i);     }     bfs();     set<int> st;     unordered_map<int, int> mp;     for (int i = 1; i <= n; ++i) {       st.insert(dis[i]);       mp[dis[i]]++;     }     int cnt = 0;     for (auto s : st) cnt += (mp[s] % 2);     cout << cnt;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[50];   double dp[51][51][51];   bool viz[51][51][51];   long long choose[51][51];   double go(int i, int j, int k) {     if (i == m - 1) return j <= a[i] * k;     double &d = dp[i][j][k];     if (viz[i][j][k]) return d;     double res = 0;     for (int l = 0; l <= min(j, a[i] * k); l++) {       res += choose[j][l] * pow(m - i - 1, j - l) / pow(m - i, j) *              go(i + 1, j - l, k);     }     viz[i][j][k] = 1;     return d = res;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) cin >> a[i];     for (int i = 0; i <= n; i++) choose[i][0] = 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= i; j++)         choose[i][j] = choose[i - 1][j - 1] + choose[i - 1][j];     double r = 0;     for (int i = 1; i <= n; i++) {       double p = go(0, n, i) - go(0, n, i - 1);       r += i * p;     }     printf( %.9lf n , r);   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const bool debugger1 = 0;   const bool debugger2 = 0;   const bool debugger3 = 0;   const bool debugger4 = 0;   const bool debugger5 = 0;   const long long MOD = 1e9 + 7, P = 1e9 + 7;   long long n;   long long sca, scb;   std::vector<pair<long long, long long> > liczby;   int main() {     scanf( %lld , &n);     liczby.resize(2 * n);     for (int i = 0; i < n; i++)       scanf( %lld , &liczby[i].first), liczby[i].second = 1;     for (int i = 0; i < n; i++)       scanf( %lld , &liczby[n + i].first), liczby[n + i].second = 2;     for (int i = 0; i < 2 * n; i++) liczby[i].first *= (-1);     sort(liczby.begin(), liczby.end());     for (int i = 0; i < liczby.size(); i++) {       if (liczby[i].second == 1) {         if (i % 2 == 0) sca -= liczby[i].first;       } else if (i % 2 == 1)         scb -= liczby[i].first;     }     printf( %lld , sca - scb);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const int INF = 2e9;   const long long MOD = 1e9 + 7;   const int MAXN = 1e5 + 2;   const int MN = 1e6 + 3;   int d1, d2;   int p1, p2;   bool usual = 1;   int ans[MN];   int main() {     int n, q;     scanf( %d %d , &n, &q);     p1 = 0, p2 = 1;     int tipo, x;     int pareja;     for (int(i) = (0); (i) < (q); ++(i)) {       scanf( %d , &tipo);       if (tipo == 1) {         scanf( %d , &x);         p1 += x, p2 += x;       } else {         if (p1 % 2 == 0)           p1++;         else           p1--;         if (p2 % 2 == 0)           p2++;         else           p2--;       }       p1 %= n;       if (p1 < 0) p1 += n;       p2 %= n;       if (p2 < 0) p2 += n;     }     int tt;     for (int i = 0; i < n; i += 2) {       tt = (p1 + i) % n;       if (tt < 0) tt += n;       ans[tt] = i;     }     for (int i = 1; i < n; i += 2) {       tt = (p2 + i - 1) % n;       if (tt < 0) tt += n;       ans[tt] = i;     }     for (int(i) = (0); (i) < (n); ++(i)) printf( %d  , ans[i] + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p, q, r, s, t, u;   int a[25];   int b[25];   int dp[25][25];   int n;   int c[25];   int sgn(int x) {     if (x > 0)       return 1;     else if (x < 0)       return -1;     else       return 0;   }   int main() {     int i, j;     int n, k, a, b;     cin >> n >> k >> a >> b;     int p = max(a, b);     int q = min(a, b);     if ((long long int)p > (long long int)(q + 1) * k) {       cout <<  NO  << endl;       return 0;     }     int cont = 0;     char last =  B ;     for (i = 1; i <= n; i++) {       if (a > b) {         if (last ==  B ) cont = 0;         if (cont < k) {           cout <<  G ;           cont++;           last =  G ;           a--;         } else {           cout <<  B ;           cont = 1;           last =  B ;           b--;         }         continue;       } else {         if (last ==  G ) cont = 0;         if (cont < k) {           last =  B ;           cout <<  B ;           cont++;           b--;         } else {           cout <<  G ;           cont = 1;           last =  G ;           a--;         }         continue;       }     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int prime[1000005];   int ans[5];   int idx;   set<int> s, s1;   set<int>::iterator it;   int main() {     int i, j;     for (i = 2; i <= 1000000; i++) {       if (prime[i] == 1) continue;       for (j = i + i; j <= 1000000; j += i) prime[j] = 1;     }     int n;     scanf( %d , &n);     if (n == 1)       printf( 1 n );     else if (n == 2)       printf( 2 n );     else {       long long sum = n;       for (i = 2; i < n; i++) {         if (n % i == 0) s.insert(i);       }       int countt = 0;       for (i = n - 1; i >= 1; i--) {         bool no = 0;         for (it = s.begin(); it != s.end(); it++) {           if (i % (*it) == 0) {             no = 1;             break;           }         }         if (!no) {           sum *= (long long)i;           countt++;         }         if (countt == 2) break;       }       long long sum1 = n - 1;       for (i = 2; i < n - 1; i++) {         if ((n - 1) % i == 0) s1.insert(i);       }       countt = 0;       for (i = n - 2; i >= 1; i--) {         bool no = 0;         for (it = s1.begin(); it != s1.end(); it++) {           if (i % (*it) == 0) {             no = 1;             break;           }         }         if (!no) {           sum1 *= (long long)i;           countt++;         }         if (countt == 2) break;       }       printf( %I64d n , max(sum, sum1));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, i, j;     char e, f;     string s, x, y;     set<string> v;     cin >> x >> y;     x[0] = x[0] -  a  + 1 +  0 ;     a = x[0] -  a  + 1;     b = x[1] -  0  + 1;     e = x[0];     f = x[1];     y[0] = y[0] -  a  + 1 +  0 ;     v.insert(x);     v.insert(y);     for (i = 1; i <= 8; i++) {       s =   ;       s += x[0];       s += (i +  0 );       v.insert(s);       s =   ;       s += (i +  0 );       s += x[1];       v.insert(s);     }     s =   ;     s = x[0] + 1;     s += x[1] + 2;     if (s[1] >=  1  && s[1] <=  8  && s[0] >=  1  && s[0] <=  8 ) {       v.insert(s);     }     s =   ;     s = x[0] - 1;     s += x[1] + 2;     if (s[1] >=  1  && s[1] <=  8  && s[0] >=  1  && s[0] <=  8 ) {       v.insert(s);     }     s =   ;     s = x[0] + 2;     s += x[1] + 1;     if (s[1] >=  1  && s[1] <=  8  && s[0] >=  1  && s[0] <=  8 ) {       v.insert(s);     }     s =   ;     s = x[0] - 2;     s += x[1] + 1;     if (s[1] >=  1  && s[1] <=  8  && s[0] >=  1  && s[0] <=  8 ) {       v.insert(s);     }     s =   ;     s = x[0] + 1;     s += x[1] - 2;     if (s[1] >=  1  && s[1] <=  8  && s[0] >=  1  && s[0] <=  8 ) {       v.insert(s);     }     s =   ;     s = x[0] + 2;     s += x[1] - 1;     if (s[1] >=  1  && s[1] <=  8  && s[0] >=  1  && s[0] <=  8 ) {       v.insert(s);     }     s =   ;     s = x[0] - 1;     s += x[1] - 2;     if (s[1] >=  1  && s[1] <=  8  && s[0] >=  1  && s[0] <=  8 ) {       v.insert(s);     }     s =   ;     s = x[0] - 2;     s += x[1] - 1;     if (s[1] >=  1  && s[1] <=  8  && s[0] >=  1  && s[0] <=  8 ) {       v.insert(s);     }     s =   ;     s = y[0] + 1;     s += y[1] + 2;     if (s[1] >=  1  && s[1] <=  8  && s[0] >=  1  && s[0] <=  8 ) {       v.insert(s);     }     s =   ;     s = y[0] - 1;     s += y[1] + 2;     if (s[1] >=  1  && s[1] <=  8  && s[0] >=  1  && s[0] <=  8 ) {       v.insert(s);     }     s =   ;     s = y[0] + 2;     s += y[1] + 1;     if (s[1] >=  1  && s[1] <=  8  && s[0] >=  1  && s[0] <=  8 ) {       v.insert(s);     }     s =   ;     s = y[0] - 2;     s += y[1] + 1;     if (s[1] >=  1  && s[1] <=  8  && s[0] >=  1  && s[0] <=  8 ) {       v.insert(s);     }     s =   ;     s = y[0] + 1;     s += y[1] - 2;     if (s[1] >=  1  && s[1] <=  8  && s[0] >=  1  && s[0] <=  8 ) {       v.insert(s);     }     s =   ;     s = y[0] + 2;     s += y[1] - 1;     if (s[1] >=  1  && s[1] <=  8  && s[0] >=  1  && s[0] <=  8 ) {       v.insert(s);     }     s =   ;     s = y[0] - 1;     s += y[1] - 2;     if (s[1] >=  1  && s[1] <=  8  && s[0] >=  1  && s[0] <=  8 ) {       v.insert(s);     }     s =   ;     s = y[0] - 2;     s += y[1] - 1;     if (s[1] >=  1  && s[1] <=  8  && s[0] >=  1  && s[0] <=  8 ) {       v.insert(s);     }     cout << 64 - v.size() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, d;     cin >> n >> m >> d;     long long x, y, z, i, j, c = 1;     map<long long, long long> mp, mp2;     set<long long> st;     vector<long long> v;     for (i = 0; i < n; i++) {       cin >> x;       v.push_back(x);       st.insert(x);     }     for (auto i : st) {       if (mp[i] == 0) {         y = i;         mp[y] = 1;         mp2[y] = c;         while (st.upper_bound(y + d) != st.end()) {           auto it = st.upper_bound(y + d);           if (mp[*it] == 0) {             mp[*it] = 1;             mp2[*it] = c;           }           y = *it;           st.erase(it);         }         c++;       }     }     cout << c - 1 << endl;     for (i = 0; i < n; i++) {       cout << mp2[v[i]] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 400;   int dp[N + 1][N + 1];   bool solve(string str, string t1, string t2) {     int n = str.size();     int m = t1.size();     for (int j = 1; j <= m; ++j) dp[0][j] = -1;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j <= m; ++j) {         dp[i][j] = -1;         if (dp[i - 1][j] != -1) {           dp[i][j] = dp[i - 1][j];           if (dp[i][j] < t2.size() && str[i - 1] == t2[dp[i][j]]) ++dp[i][j];         }         if (j > 0 && str[i - 1] == t1[j - 1]) {           dp[i][j] = max(dp[i][j], dp[i - 1][j - 1]);         }       }     }     return dp[n][m] >= (int)t2.size();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int tc;     cin >> tc;     for (int ti = 0; ti < tc; ++ti) {       string src, tar;       cin >> src >> tar;       bool works = false;       for (int a = 1; a <= tar.size(); ++a) {         string le, ri;         for (int i = 0; i < a; ++i) le.push_back(tar[i]);         for (int i = a; i < tar.size(); ++i) ri.push_back(tar[i]);         if (solve(src, le, ri)) works = true;       }       if (works)         cout <<  YES n ;       else         cout <<  NO n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[2010];   char str[1010];   int ans[2010];   int tmp[2010];   int main() {     int n;     cin >> n;     scanf( %s , str);     for (int i = 0; i < n; i++) {       a[i] = str[i] -  0 ;     }     for (int i = n; i < 2 * n; i++) {       a[i] = a[i - n];     }     for (int i = 0; i < n; i++) ans[i] = 9;     for (int i = 0; i < n; i++) {       int d = 10 - a[i];       for (int j = 0; j < n; j++) {         tmp[j] = (a[i + j] + d) % 10;       }       for (int j = 0; j < n; j++) {         if (tmp[j] < ans[j]) {           memcpy(ans, tmp, sizeof(tmp));           break;         } else if (tmp[j] > ans[j])           break;       }     }     for (int i = 0; i < n; i++) {       cout << ans[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int INT_MAX_VAL = (int)1e20;   int INT_MIN_VAL = (int)-1e20;   long long LONG_MAX_VAL = (long long)1e20;   long long LONG_MIN_VAL = (long long)-1e20;   long long C, Hr, Hb, Wr, Wb;   long long func(long long x) {     long long y = (C - Wb * x) / Wr;     return Hb * x + Hr * y;   }   long long solve() {     long long l = 0;     long long r = min(C / Wb, 10000000LL);     long long res = 0;     for (long long i = 0; i <= r; ++i) {       res = max(res, func(i));     }     return res;   }   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     cin >> C >> Hr >> Hb >> Wr >> Wb;     long long res1 = solve();     swap(Hr, Hb);     swap(Wr, Wb);     long long res2 = solve();     cout << max(res1, res2) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   struct node {     int l, r, id;   } a[maxn];   bool cmp(node a, node b) { return a.l < b.l; }   multiset<pair<int, int> > s;   vector<int> ans;   int main() {     multiset<pair<int, int> >::iterator it;     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i].l >> a[i].r;       a[i].id = i;     }     sort(a + 1, a + 1 + n, cmp);     for (int i = 1; i <= n; i++) {       while (s.size() && (*s.begin()).first < a[i].l) s.erase(s.begin());       s.insert(make_pair(a[i].r, a[i].id));       while (s.size() > k) {         multiset<pair<int, int> >::iterator it;         it = s.end();         it--;         ans.push_back((*it).second);         s.erase(it);       }     }     int len = ans.size();     cout << len << endl;     for (int i = 0; i < len; i++) {       cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 1;   const int MOD = 1e9 + 7;   class Problem {    public:     int N, Q, t, k, d;     char ch;     string S;     void solve(std::istream& input, std::ostream& output);   };   void Problem::solve(std::istream& input, std::ostream& output) {     input >> N;     for (int i = sqrt(N); i >= 1; i--) {       if (N % i == 0) {         output << i <<     << N / i;         exit(0);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     std::istream& input(std::cin);     std::ostream& output(std::cout);     input.tie(0);     Problem _A;     _A.solve(input, output);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int visited[505], dp[505];   int d, x, y, flag;   vector<int> vec[505];   vector<pair<int, int> > adj;   int var[505];   void dfs(int u, int dist) {     visited[u] = 1;     d = max(d, dist);     for (int i = 0; i < vec[u].size(); i++) {       if ((u == x && vec[u][i] == y) || (u == y && vec[u][i] == x)) continue;       if (!visited[vec[u][i]]) {         dfs(vec[u][i], dist + 1);       }     }   }   int main() {     int n, ans = 0, fin = 0, temp;     cin >> n;     flag = 1;     for (int i = 0; i < n - 1; i++) {       scanf( %d %d , &x, &y);       vec[x].push_back(y);       vec[y].push_back(x);       adj.push_back(make_pair(x, y));     }     for (int i = 0; i < adj.size(); i++) {       x = adj[i].first, y = adj[i].second;       ans = 0;       memset(var, 0, sizeof(var));       memset(visited, 0, sizeof(visited));       d = 0;       dfs(x, 0);       for (int j = 1; j <= n; j++) {         if (visited[j]) {           var[j] = 1;         }       }       for (int j = 1; j <= n; j++) {         if (var[j]) {           d = 0;           memset(visited, 0, sizeof(visited));           dfs(j, 0);           ans = max(ans, d);         }       }       memset(visited, 0, sizeof(visited));       dfs(y, 0);       memset(var, 0, sizeof(var));       for (int j = 1; j <= n; j++) {         if (visited[j]) {           var[j] = 1;         }       }       temp = 0;       for (int j = 1; j <= n; j++) {         if (var[j]) {           d = 0;           memset(visited, 0, sizeof(visited));           dfs(j, 0);           temp = max(temp, d);         }       }       ans *= temp;       fin = max(fin, ans);     }     cout << fin;   }
#include <bits/stdc++.h>   using namespace std;   struct SegmentTree {     struct Node {       Node *lch, *rch;       long long sum;       Node() {         lch = rch = nullptr;         sum = 0;       }       void up() {         sum = 0;         if (lch != nullptr) sum += lch->sum;         if (rch != nullptr) sum += rch->sum;       }     } * root;     SegmentTree() { root = nullptr; }     void modify(int l, int r, int pos, int v, Node*& node) {       if (node == nullptr) node = new Node();       if (l == r) {         node->sum += v;       } else {         int mid = (l + r) >> 1;         if (pos <= mid)           modify(l, mid, pos, v, node->lch);         else           modify(mid + 1, r, pos, v, node->rch);         node->up();       }     }     long long query(int l, int r, int ql, int qr, Node* node) {       if (node == nullptr) return 0;       if (l == ql && r == qr) return node->sum;       int mid = (l + r) >> 1;       if (qr <= mid)         return query(l, mid, ql, qr, node->lch);       else if (ql > mid)         return query(mid + 1, r, ql, qr, node->rch);       else         return query(l, mid, ql, mid, node->lch) +                query(mid + 1, r, mid + 1, qr, node->rch);     }   } bit[100010];   int n;   inline int lowbit(int x) { return x & -x; }   inline void modify(int x, int y, int v) {     for (int i = x; i <= n; i += lowbit(i))       bit[i].modify(0, n, y, v, bit[i].root);   }   inline long long query(int pos, int ql, int qr) {     long long res = 0;     for (int i = pos; i > 0; i -= lowbit(i))       res += bit[i].query(0, n, ql, qr, bit[i].root);     return res;   }   inline long long Query(int xl, int xr, int yl, int yr) {     return query(xr, yl, yr) - query(xl - 1, yl, yr);   }   set<int> pos[100010];   int a[100010];   int main() {     int m, op, p, x, l, r;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) pos[i].insert(0);     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       auto it = pos[a[i]].end();       it--;       modify(i, *it, i - *it);       pos[a[i]].insert(i);     }     while (m--) {       scanf( %d , &op);       if (op == 1) {         scanf( %d%d , &p, &x);         auto it = pos[a[p]].find(p), it2 = it;         it2--;         it++;         modify(p, *it2, -(p - *it2));         if (it != pos[a[p]].end()) {           modify(*it, p, -(*it - p));           modify(*it, *it2, *it - *it2);         }         pos[a[p]].erase(p);         a[p] = x;         pos[x].insert(p);         it = pos[x].find(p), it2 = it;         it2--;         it++;         modify(p, *it2, p - *it2);         if (it != pos[x].end()) {           modify(*it, *it2, -(*it - *it2));           modify(*it, p, *it - p);         }       } else {         scanf( %d%d , &l, &r);         printf( %lld n , Query(l, r, l, r));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps(1e-8);   int n, m;   vector<long long> seq[100010];   long long a[100010];   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %I64d , &a[i]);     }     long long initial = 0;     a[0] = a[1];     a[m + 1] = a[m];     for (int i = 1; i <= m; i++) {       initial += abs(a[i] - a[i - 1]);     }     for (int i = 1; i <= m; i++) {       if (i - 1 != 0) {         if (a[i] != a[i - 1]) seq[a[i]].push_back(a[i - 1]);       }       if (i != m) {         if (a[i] != a[i + 1]) seq[a[i]].push_back(a[i + 1]);       }     }     long long tmp;     long long less;     long long ini;     long long answer = initial;     for (int i = 1; i <= n; i++) {       if (!seq[i].empty()) {         sort(seq[i].begin(), seq[i].end());         less = 0;         ini = 0;         tmp = seq[i][(seq[i].size() + 1) / 2 - 1];         for (int j = 0; j <= seq[i].size() - 1; j++) {           ini += abs(i - seq[i][j]);           less += abs(tmp - seq[i][j]);         }         less = initial - ini + less;         answer = min(answer, less);       }     }     printf( %I64d n , answer);     return 0;   }