malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int INF = 1e9;   const long long INF64 = 9e18;   const long double EPS = 1e-9;   const long double PI = 3.14159265358979310000;   const long long MD = 1248742437;   const long long T = 378531;   const int N = 1200001;   const int M = 501;   int n, k, a[N];   int main() {     cin >> n >> k;     if (n / k < 3) {       cout << -1;       return 0;     }     int j = 1;     for (int i = 1; i <= k * 2; i++) {       a[i] = j;       j++;       if (j > k) j = 1;     }     j = k;     for (int i = k * 2 + 1; i <= n; i++) {       a[i] = j;       j--;       if (j == 0) j = k;     }     swap(a[k / 2], a[k / 2 + 1]);     for (int i = 1; i <= n; i++) printf( %d  , a[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int tab[205];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> V;       for (int i = 0; i < n; i++) {         int x;         cin >> x;         tab[x] = 1;         V.push_back(x);       }       vector<int> V2;       bool b = 1;       for (int i : V) {         b = 0;         for (int j = i + 1; j <= 2 * n; j++) {           if (tab[j] == 0) {             tab[j] = 1;             b = 1;             V2.push_back(j);             break;           }         }         if (!b) {           break;         }       }       if (!b) {         cout <<  -1 n ;       } else {         for (int i = 0; i < n; i++) {           cout << min(V[i], V2[i]) <<     << max(V[i], V2[i]) <<    ;         }         cout <<   n ;       }       for (int i = 0; i <= 2 * n; i++) {         tab[i] = 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     t = 1;     while (t--) {       long long int n, m;       cin >> n >> m;       long long int arr[n];       string arr2[m];       for (long long int i = 0; i < n; i++) {         cin >> arr[i];       }       map<string, int> mp;       for (long long int i = 0; i < m; i++) {         cin >> arr2[i];         if (mp.find(arr2[i]) != mp.end()) {           std::map<string, int>::iterator it = mp.find(arr2[i]);           it->second++;         } else {           mp.insert({arr2[i], 1});         }       }       sort(arr, arr + n);       vector<long long int> freq;       for (auto &it : mp) {         freq.push_back(it.second);       }       sort(freq.begin(), freq.end(), greater<long long int>());       long long int ans = 0;       long long int ans2 = 0;       for (long long int i = 0; i < freq.size(); i++) {         ans += freq[i] * arr[i];         ans2 += freq[i] * arr[n - i - 1];       }       cout << ans <<     << ans2 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 10;   const int maxn = 5e5 + 10;   int N, M;   struct edge {     int v, u, l, r;     edge() {}     edge(int v_, int u_, int l_, int r_) : v(v_), u(u_), l(l_), r(r_) {}     bool operator>(const edge& rhs) const { return l > rhs.l; }   };   priority_queue<edge, vector<edge>, greater<edge>> q;   vector<edge> adj[maxn][2];   int last[maxn][2];   void relax(int v, int start, int end) {     last[v][start & 1] = max(last[v][start & 1], end);     for (auto& e : adj[v][start & 1]) {       edge t = e;       t.l = start;       q.push(t);     }     adj[v][start & 1].clear();   }   int main() {     scanf( %d %d , &N, &M);     for (int i = 1; i <= M; ++i) {       int v, u, l, r;       scanf( %d %d %d %d , &v, &u, &l, &r);       --r;       q.push(edge(v, u, l, ((l & 1) == (r & 1) ? r : r - 1)));       q.push(edge(u, v, l, ((l & 1) == (r & 1) ? r : r - 1)));       q.push(edge(v, u, l + 1, (((l + 1) & 1) == (r & 1) ? r : r - 1)));       q.push(edge(u, v, l + 1, (((l + 1) & 1) == (r & 1) ? r : r - 1)));     }     if (N == 1) {       printf( 0 n );       return 0;     }     for (int i = 1; i <= N; ++i)       for (int j = 0; j < 2; ++j) last[i][j] = -1;     last[1][0] = 0;     while (!q.empty()) {       edge e = q.top();       q.pop();       if (e.l <= e.r) {         if (last[e.v][e.l & 1] >= e.l) {           if (e.u == N) {             printf( %d n , e.l + 1);             return 0;           }           relax(e.u, e.l + 1, e.r + 1);         } else {           adj[e.v][e.l & 1].push_back(e);         }       }     }     printf( -1 n );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, A, B, x, y;     while (cin >> x >> y >> A >> B) {       int Count = 0;       for (i = A; i <= x; i++) {         for (j = B; j <= y; j++) {           if (i > j) {             Count++;           }         }       }       cout << Count << endl;       for (i = A; i <= x; i++) {         for (j = B; j <= y; j++) {           if (i > j) {             cout << i <<     << j << endl;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000000];   pair<int, int> b[1000000];   int ord[1000000];   int main() {     int n, k;     cin >> n >> k;     long long m;     cin >> m;     for (int i = 1; i <= n; i++) {       cin >> a[i];       b[i] = make_pair(a[i], i);     }     sort(b + 1, b + n, greater<pair<int, int> >());     b[n].first = 0;     long long sum = 0;     for (int i = 1; i < n; i++) {       if (i < k) sum += b[i].first;       ord[b[i].second] = i;     }     int num = k - 1;     for (int i = 1; i < n; i++) {       long long s = sum;       if (ord[i] <= num) {         s -= b[ord[i]].first;         s += b[k].first;       }       if (m - s < a[i]) {         cout << i << endl;         return 0;       }     }     cout << n << endl;   }
#include <bits/stdc++.h>   using namespace std;   void rom(long long W) {     long long pot = 1LL;     char val[20] =  IVXLCDM ;     long long w = 0LL, z, i;     while (pot <= W) {       pot *= 10LL;       w++;     }     pot /= 10LL;     w--;     while (pot) {       z = W / pot;       if (z == 4)         printf( %c%c , val[w * 2], val[w * 2 + 1]);       else if (z == 9)         printf( %c%c , val[w * 2], val[w * 2 + 2]);       else {         if (z >= 5) {           printf( %c , val[w * 2 + 1]);           z -= 5;         }         for (i = 0; i < z; i++) printf( %c , val[w * 2]);       }       W -= W / pot * pot;       pot /= 10LL;       w--;     }     printf(  n );   }   void nice(long long W, long long B) {     if (W == 0LL) cout << 0;     long long pot = 1LL;     char val[300];     int i, j;     for (i = 0, j =  0 ; j <=  9 ; i++, j++) val[i] = j;     for (j =  A ; j <=  Z ; i++, j++) val[i] = j;     while (pot <= W) {       pot *= B;     }     pot /= B;     while (pot) {       printf( %c , val[W / pot]);       W -= (W / pot) * pot;       pot /= B;     }     printf(  n );   }   int main() {     long long a;     char b[10000], c[10000];     long long w, pot, i, j;     long long val[300];     memset(val, 0, sizeof(val));     for (i =  0 , j = 0; i <=  9 ; i++, j++) {       val[i] = j;     }     for (i =  A ; i <=  Z ; i++, j++) {       val[i] = j;     }     cin >> a;     scanf( %s%s , b, c);     w = 0LL;     pot = 1LL;     for (i = strlen(c) - 1; i >= 0; i--, pot *= a) {       w += (val[c[i]]) * pot;     }     if (b[0] ==  R )       rom(w);     else {       int q;       sscanf(b,  %d , &q);       nice(w, 0LL + q);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a = 0;     cin >> a;     int z = 0, e = 0;     char b;     for (int i = 0; i < a; i++) {       cin >> b;       if (b ==  D ) z++;       if (b ==  A ) e++;     }     if (e == z)       cout <<  Friendship ;     else if (e < z)       cout <<  Danik ;     else if (e > z)       cout <<  Anton ;   }
#include <bits/stdc++.h>   using namespace std;   bool good(long long int a, long long int b) {     while (a and b) {       if (a % 2 == 0 and b % 2 == 1) return false;       a /= 2;       b /= 2;     }     return true;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<pair<long long int, long long int>> s(n);     for (int i = 0; i < n; i++) cin >> s[i].first;     for (int i = 0; i < n; i++) cin >> s[i].second;     sort(s.rbegin(), s.rend());     vector<bool> used(n, false);     int nb = 0;     long long int knw = 0;     long long int ans = 0;     for (int i = 1; i < n; i++) {       if (s[i].first == s[i - 1].first) {         knw |= s[i].first;         if (!used[i]) {           nb++;           ans += s[i].second;           used[i] = true;         }         if (!used[i - 1]) {           nb++;           ans += s[i - 1].second;           used[i - 1] = true;         }       }     }     for (int i = 0; i < n; i++) {       if (used[i]) continue;       for (int j = 0; j < n; j++) {         if (used[j] and (s[i].first | s[j].first) == s[j].first) {           ans += s[i].second;           nb++;           used[i] = true;           break;         }       }     }     if (nb < 2) ans = 0;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   deque<int> q;   int main() {     int n;     while (~scanf( %d , &n)) {       q.clear();       for (int i = 1; i <= n; i++) q.push_back(i);       for (int i = 2; i <= n; i++) {         int k = ((n - 1) / i) * i;         int tmp = q[k];         for (int j = k; j >= i; j -= i) q[j] = q[j - i];         q[0] = tmp;         q.push_back(q.front());         q.pop_front();       }       int sz = q.size();       for (int i = 0; i < sz; i++)         if (i == 0)           printf( %d , q[i]);         else           printf(  %d , q[i]);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void setIO(string str, bool dbg) {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     cout.tie(nullptr);     if (!dbg) {       freopen((str +  .in ).c_str(),  r , stdin);       freopen((str +  .out ).c_str(),  w , stdout);     }   }   const int MAX = 5e3 + 5;   const int LEN = 2e3 + 5;   const int LVL = 2e1 + 0;   const long long int MOD = 1e9 + 7;   const long long int INF = 2e9;   int xyz = 1;   int n, q;   int pld[MAX][MAX];   int dps[MAX][MAX];   void fnc() {     string str;     cin >> str;     n = str.length();     for (int i = 0; i < n; i++) pld[i][i] = 1;     for (int i = 1; i < n; i++) {       for (int j = 0; j + i < n; j++) {         int l = j;         int r = i + j;         pld[l][r] = str[l] == str[r] ? pld[l + 1][r - 1] || r - l == 1 : 0;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j + i < n; j++) {         int l = j;         int r = i + j;         dps[l][r] = pld[l][r] + dps[l + 1][r] + dps[l][r - 1] - dps[l + 1][r - 1];       }     }     cin >> q;     for (int i = 0; i < q; i++) {       int l;       int r;       cin >> l >> r;       cout << dps[l - 1][r - 1] <<   n ;     }   }   int main() {     setIO(  , 1);     while (xyz--) fnc();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 998244353;   long long gcd(long long a, long long b) {     long long c;     while (a != 0) {       c = a;       a = b % a;       b = c;     }     return b;   }   signed main() {     cin.tie(0);     ios::sync_with_stdio(false);     long long N;     cin >> N;     vector<long long> A(N);     long long res = 1;     for (long long i = 0; i < N; i++) {       cin >> A[i];     }     map<long long, long long> mp;     map<long long, long long> num;     vector<long long> C;     set<long long> st;     for (long long i = 0; i < N; i++) {       long long X = pow(A[i], 0.25);       X = max((long long)0, X - 3);       while (X * X * X * X < A[i]) X++;       if (X * X * X * X == A[i]) {         mp[X] += 4;         st.insert(X);         continue;       }       X = pow(A[i], 1.0 / 3);       X = max((long long)0, X - 3);       while (X * X * X < A[i]) X++;       if (X * X * X == A[i]) {         mp[X] += 3;         st.insert(X);         continue;       }       X = sqrt(A[i]);       X = max((long long)0, X - 3);       while (X * X < A[i]) X++;       if (X * X == A[i]) {         mp[X] += 2;         st.insert(X);         continue;       }       num[A[i]]++;       if (num[A[i]] == 1) {         C.push_back(A[i]);       }     }     vector<long long> V(C.size(), 0);     for (long long i = 0; i < C.size(); i++) {       for (long long j = i + 1; j < C.size(); j++) {         long long a = gcd(C[i], C[j]);         if (a != 1) {           st.insert(a);           st.insert(C[i] / a);           st.insert(C[j] / a);         }       }     }     vector<long long> sv;     for (auto s : st) {       sv.push_back(s);     }     for (long long i = 0; i < C.size(); i++) {       bool ok = true;       for (long long j = 0; j < sv.size(); j++) {         if (C[i] % sv[j] == 0) {           mp[sv[j]] += num[C[i]];           mp[C[i] / sv[j]] += num[C[i]];           ok = false;           break;         }       }       if (ok) {         long long t = num[C[i]] + 1;         res = (res * t * t) % MOD;       }     }     for (auto m : mp) {       res = (res * (m.second + 1)) % MOD;     }     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long q, n;   string h;   int main() {     ios::sync_with_stdio(NULL);     cin.tie(0);     cout.tie(0);     cin >> q;     while (q--) {       cin >> n;       if (n == 1) {         cout <<  a n ;         continue;       }       for (long long i = 1; i <= n / 2; i++) cout <<  a ;       cout << ((n % 2 == 0) ?  b  :  bc );       for (long long i = 1; i <= n / 2 - 1; i++) cout <<  a ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long double mem[50 + 5][50 + 5][50 + 5];   long double fact[55];   vector<int> num;   int n, p, L;   long double dp(int sum, int idx, int cnt, int last) {     if (sum > p || cnt > L) {       return 0;     }     if (idx == n) {       return (sum + num[last] > p && cnt + 1 == L);     }     long double &ret = mem[sum][idx][cnt];     if (ret == ret) {       return ret;     }     ret = 0;     if (idx != last) ret += dp(sum + num[idx], idx + 1, cnt + 1, last);     ret += dp(sum, idx + 1, cnt, last);     return ret;   }   void solve() {     long double ans = 0;     fact[0] = 1;     for (int i = 1; i <= 50; i++) {       fact[i] = fact[i - 1] * i;     }     for (int i = 2; i <= n; i++) {       for (int j = 0; j < n; j++) {         memset(mem, -1, sizeof(mem));         L = i;         long double ret = dp(0, 0, 0, j);         if (ret) ans += (fact[i - 1] * fact[n - i] / fact[n] * ret * (i - 1));       }     }     int sum = 0;     for (int i = 0; i < n; i++) {       sum += num[i];     }     if (ans == 0 && sum <= p) ans = n;     cout << ans << endl;   }   int main() {     int a;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       num.push_back(a);     }     cin >> p;     solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[4];     cin >> arr[0] >> arr[1] >> arr[2] >> arr[3];     sort(arr, arr + 4);     if ((arr[0] + arr[3]) == (arr[1] + arr[2]) ||         (arr[0] + arr[1] + arr[2]) == arr[3]) {       cout <<  YES  <<   n ;     } else {       cout <<  NO  <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool check(string& a, string& b) {     if (a.size() != b.size()) return false;     int ind1 = -1, ind2 = -1;     bool check = false;     bool buck[26] = {0};     int count = 0;     for (int i = 0; i < a.size(); i++) {       if (a[i] != b[i]) {         count++;         if (count > 2) return false;         if (ind1 == -1)           ind1 = i;         else           ind2 = i;       } else {         if (buck[a[i] -  a ])           check = true;         else           buck[a[i] -  a ] = true;       }     }     if (count == 1) return false;     if (count == 0) {       return check;     }     return (a[ind1] == b[ind2]) && (a[ind2] == b[ind1]);   }   int main() {     string a, b;     cin >> a;     cin >> b;     if (check(a, b))       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   int ct, n, m, tct, cnt[540010], mp[540010], t[540010], a[50010][4],       lmax = 27 * 27 * 27 * 27, B, pool[200010], *pt(pool),       *v[540010], ans[70010][402];   char s[50010], x[10], y[10];   int nd(const char* st, const char* ed) {     int res = 0;     while (st != ed) res = res * 27 + (*st++ -  a  + 1);     return res;   }   int leng(int i) {     if (i < 27) return 1;     if (i < 27 * 27) return 2;     if (i < 27 * 27 * 27) return 3;     return 4;   }   int main() {     scanf( %s%d , s, &m);     n = strlen(s);     B = 500;     for (int i = 0; i < n; i++) {       if (i <= n - 4) ++cnt[a[i][3] = nd(s + i, s + i + 4)];       if (i <= n - 3) ++cnt[a[i][2] = nd(s + i, s + i + 3)];       if (i <= n - 2) ++cnt[a[i][1] = nd(s + i, s + i + 2)];       ++cnt[a[i][0] = nd(s + i, s + i + 1)];     }     for (int i = 1; i < lmax; i++)       if (cnt[i]) {         mp[i] = ++ct;         v[mp[i]] = pt, pt += cnt[i];         cnt[i] = 0;       }     for (int k = 0; k <= 3; k++)       for (int j = 0; j < n - k; j++) {         int p = mp[a[j][k]];         v[p][cnt[p]++] = j;       }     for (int i = 1; i <= lmax; i++)       if (cnt[mp[i]] >= B) {         t[mp[i]] = ++tct;         int q = t[mp[i]], d = leng(i);         for (int j = 1; j <= ct; j++) ans[j][q] = 0x3f3f3f3f;         int rl = -5, ll = -5;         for (int k = 0; k <= 3; k++) {           rl = -5;           for (int j = 0; j < n - k; j++) {             int p = mp[a[j][k]];             if (a[j][d - 1] == i) ll = j - 1, rl = j + d - 1;             if (rl != -5)               ans[p][q] = std::min(ans[p][q], std::max(j + k, rl) - ll);           }         }         for (int k = 0; k <= 3; k++) {           rl = -5;           for (int j = n - k - 1; ~j; j--) {             int p = mp[a[j][k]];             if (a[j][d - 1] == i) ll = j, rl = j + d;             if (rl != -5)               ans[p][q] =                   std::min(ans[p][q], std::max(rl, j + k + 1) - std::min(ll, j));           }         }         ans[mp[i]][q] = d;       }     while (m--) {       scanf( %s%s , x, y);       int xw = strlen(x), yw = strlen(y);       int x1 = nd(x, x + xw), y1 = nd(y, y + yw);       if (!mp[x1] || !mp[y1]) {         puts( -1 );       } else {         x1 = mp[x1], y1 = mp[y1];         if (cnt[x1] > cnt[y1]) x1 ^= y1 ^= x1 ^= y1, xw ^= yw ^= xw ^= yw;         if (cnt[y1] >= B) {           printf( %d n , ans[x1][t[y1]]);         } else {           int i = 0, j = 0, ans = 0x3f3f3f3f;           while (i < cnt[x1] && j < cnt[y1]) {             if (v[x1][i] < v[y1][j])               ans = std::min(ans,                              std::max(v[x1][i] + xw, v[y1][j] + yw) - v[x1][i]),               ++i;             else               ans = std::min(ans,                              std::max(v[x1][i] + xw, v[y1][j] + yw) - v[y1][j]),               ++j;           }           printf( %d n , ans);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t = 1;     while (t--) {       string s;       cin >> s;       sort(s.begin(), s.end());       long long n = s.size(), ans = 0;       long long l = 0, r = n - 1;       while (l <= r) {         long long m = l + (r - l) / 2;         if (s[m] == s[n - 1]) {           if (s[m - 1] != s[n - 1] || m == 0) {             ans = m;             break;           } else             r = m - 1;         } else {           l = m + 1;         }       }       cout << s.substr(ans) << endl;     }   }
#include <bits/stdc++.h>   const int maxn = 1011;   const int mod = 256;   char str[maxn];   int main() {     gets(str);     int len = strlen(str);     int sad = 0;     for (int i = 0; i < len; i++) {       int a[11] = {0}, j = 0, temp = 0;       int c = str[i];       while (c) {         a[j++] = c % 2;         c /= 2;       }       for (int j = 7, k = 1; j >= 0; j--, k *= 2) {         temp += a[j] * k;       }       int res = (sad - temp + mod) % mod;       printf( %d n , res);       sad = temp;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     register long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = getchar();     }     return (f == 1) ? x : -x;   }   int cnt[10101010], X[10101010];   bool vis[10101010];   long long F[10101010], pw2[1101010];   int tot, p[1010101], a[1010101], lim, mu[10101010];   inline void seive(int n) {     for (int i = 2; i <= n; i++) {       if (!vis[i]) p[++tot] = i, X[i] = i, mu[i] = -1;       for (int j = 1; j <= tot; j++) {         if (1ll * p[j] * i > n) break;         vis[p[j] * i] = 1, mu[p[j] * i] = -mu[i];         if (i % p[j] == 0) {           mu[i * p[j]] = 0;           X[i * p[j]] = X[i];           break;         } else           X[i * p[j]] = X[i] * p[j];       }     }   }   inline void FMTand(long long *F, int lim) {     for (int i = 1; i <= tot; i++) {       for (int j = lim / p[i]; j; j--) {         F[j] = (F[j] + F[j * p[i]]) % 1000000007;       }     }   }   inline void FMTor(long long *F, int lim) {     for (int i = 1; i <= tot; i++) {       for (int j = 1; j * p[i] <= lim; j++) {         F[j * p[i]] = (F[j * p[i]] + F[j]) % 1000000007;       }     }   }   signed main() {     long long n = read();     pw2[0] = 1;     for (int i = 1; i <= n; i++) pw2[i] = 1ll * pw2[i - 1] * 2 % 1000000007;     for (int i = 1; i <= n; i++) {       a[i] = read();       cnt[a[i]]++;       lim = max(lim, a[i]);       F[a[i]] = cnt[a[i]];     }     seive(lim);     FMTand(F, lim);     long long ONE = pw2[F[1]] - 1, _ = 0;     for (int i = 2; i <= lim; i++) {       ONE =           (1000000007 + ONE + mu[i] * (pw2[F[i]] - 1) % 1000000007) % 1000000007;     }     for (int i = 1; i <= lim; i++) {       F[i] = (1000000007 + (pw2[F[i]] - 1) * (1000000007 - mu[i]) % 1000000007) %              1000000007;     }     FMTor(F, lim);     for (int i = 1; i <= lim; i++) {       _ = (_ + 1ll * cnt[i] * (pw2[n] - 1 - ONE - F[X[i]]) % 1000000007) %           1000000007;     }     cout << (_ % 1000000007 + 1000000007) % 1000000007;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[101][3] = {};   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 1, a; i <= n; ++i) {       cin >> a;       dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2]));       if (a & 1) dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + 1;       if (a & 2) dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + 1;     }     cout << n - max(dp[n][0], max(dp[n][1], dp[n][2])) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int a[maxn], m, n, ans, dp[maxn];   inline bool check(int x) {     memset(dp, 0, sizeof(dp));     for (int sta = 0; sta <= 1 && sta < n; sta++) {       dp[sta] = sta ? max(a[0] + x, a[1]) : a[0];       for (int i = sta + 1; i < n; i++) {         dp[i] = dp[i - 1];         if (dp[i - 1] >= a[i] - 1) dp[i] = max(dp[i], a[i] + x);         if (dp[i - 1] >= a[i] - x - 1) dp[i] = max(dp[i], a[i]);         if (dp[i - 2] >= a[i] - x - 1 && i >= 2) dp[i] = max(dp[i], a[i - 1] + x);       }       if (dp[n - 1] >= min(m - 1, m + a[sta] - x - 1)) return 1;     }     return 0;   }   int main() {     scanf( %d%d , &m, &n);     for (int i = 0; i < n; i++) scanf( %d , a + i);     sort(a, a + n);     pair<int, int> pos(a[0] + m - a[n - 1], 0);     for (int i = 1; i < n; i++) {       pos = max(pos, make_pair(a[i] - a[i - 1], i));     }     rotate(a, a + pos.second, a + n);     for (int i = n - 1; i >= 0; i--) {       a[i] -= a[0];       if (a[i] < 0) {         a[i] += m;       }     }     int l = 0, r = a[0] - a[n - 1] + m - 1, ans = r;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid)) {         ans = mid, r = mid - 1;       } else         l = mid + 1;     }     printf( %d n , ans);     return 0;   }