malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<long long int> v1, v2;   vector<char> v4;   string s1, s2, s3;   long long int visited[2000005];   set<char> st;   set<long long int>::iterator it;   int main() {     long long int a, b, c, d, e, f, i, j, k,         cnt1 = 0, cnt2 = 0, sum1 = 0, sum2 = 0, first, chk1 = 0, chk2 = 0, T;     cin >> a >> b;     char xx;     long long int indx, chk = 0;     cin >> s1;     s2 = s1;     for (i = 0; i < a; i++) {       if (visited[i] == 0) {         v1.push_back(i);         for (j = i; j < a; j += b) {           visited[j] = 1;           s1[j] = s1[i];         }       }     }     for (i = 0; i < a; i++) {       if (s1[i] > s2[i]) {         chk = 1;         for (j = 0; j < v1.size(); j++) {           if (v1[j] > i) {             for (int k = v1[j]; k < a; k += b) {               s1[k] =  0 ;             }           }         }         break;       } else if (s1[i] == s2[i])         cnt1++;       else {         first = i;         break;       }     }     if (cnt1 == a) chk = 1;     if (chk == 0) {       long long int x = upper_bound(v1.begin(), v1.end(), first) - v1.begin();       x--;       xx = s1[v1[x]];       if (xx ==  9 ) {         for (i = x - 1; i >= 0; i--) {           if (s1[v1[i]] !=  9 ) {             xx = s1[v1[i]] + 1;             for (j = v1[i]; j < a; j += b) {               s1[j] = xx;             }             for (j = i + 1; j < v1.size(); j++) {               if (s1[v1[j]] !=  0 ) {                 for (int k = v1[j]; k < a; k += b) {                   s1[k] =  0 ;                 }               }             }             break;           }         }       } else {         for (i = v1[x]; i < a; i += b) {           s1[i] = xx + 1;         }       }     }     cout << s1.size() << endl;     cout << s1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double dp[200 + 50][200 + 50][200 + 50];   double p[200 + 50];   double res;   int a[200 + 50];   int n, l, x, kol;   int main() {     scanf( %d%d%d , &n, &l, &kol);     for (int i = 1; i <= n; i++) {       scanf( %d , &x);       p[i] = (x + 0.0) / 100;     }     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       a[i]++;     }     memset(dp, 0, sizeof(dp));     dp[0][0][0] = 1;     for (int i = 0; i < n; i++) {       for (int j = 0; j <= i; j++) {         for (int k = 0; k <= n; k++) {           dp[i + 1][j + 1][min(n, k + a[i + 1])] += dp[i][j][k] * p[i + 1];           dp[i + 1][j][k] += dp[i][j][k] * (1 - p[i + 1]);         }       }     }     res = 0;     for (int i = l; i <= n; i++) {       for (int j = max(0, l - kol); j <= n; j++) {         if (i <= j + kol) res += dp[n][i][j];       }     }     printf( %llf , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > out;   vector<pair<int, int> >::iterator iter;   long long int a[3][200005];   int main() {     long long int x[3], y[3], m[3];     int k[3], i, j, bad = 0, prev = 0, n, u = 1, v = 1;     bool A, B;     scanf( %d , &n);     for (i = 1; i <= 2; i++) {       scanf( %d%I64d%I64d%I64d%I64d , &k[i], &a[i][1], &x[i], &y[i], &m[i]);       for (j = 2; j <= k[i]; j++) a[i][j] = (a[i][j - 1] * x[i] + y[i]) % m[i];     }     for (i = 1; i <= k[1] + k[2]; i++) {       A = B = false;       if (((u <= k[1] && a[1][u] < prev) && (v <= k[2] && a[2][v] < prev)) ||           (v > k[2] && a[1][u] < prev) || (u > k[1] && a[2][v] < prev)) {         bad++;         if ((u <= k[1] && a[1][u] < a[2][v]) || v > k[2])           A = true;         else           B = true;       }       if (u <= k[1] && !B &&           (((a[2][v] < prev) || A) ||            ((v > k[2]) || (a[1][u] >= prev && a[1][u] < a[2][v])))) {         if (k[1] + k[2] <= 200000) out.push_back(make_pair(a[1][u], 1));         prev = a[1][u];         u++;       } else {         if (k[1] + k[2] <= 200000) out.push_back(make_pair(a[2][v], 2));         prev = a[2][v];         v++;       }     }     printf( %d n , bad);     if (k[1] + k[2] <= 200000) {       for (iter = out.begin(); iter != out.end(); iter++)         printf( %d %d n , iter->first, iter->second);     }   }
#include <bits/stdc++.h>   using namespace std;   int d[1000000];   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 0; i < (n); ++i) {       int(x);       scanf( %d , &x);       d[i % k] += x;     }     int mi = (int)1e9;     int id = -1;     for (int i = 0; i < (k); ++i) {       if (mi > d[i]) {         mi = d[i];         id = i;       }     }     printf( %d n , id + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1};   const double EPS = 1e-8;   const double PI = acos(-1.0);   int popcount(int n) { return __builtin_popcount(n); }   int popcount(long long n) { return __builtin_popcountll(n); }   template <class T>   int SIZE(T a) {     return a.size();   }   template <class T>   string IntToString(T num) {     string res;     stringstream ss;     ss << num;     return ss.str();   }   template <class T>   T StringToInt(string str) {     T res = 0;     for (int i = 0; i < SIZE(str); i++) res = (res * 10 + str[i] -  0 );     return res;   }   template <class T>   T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class T>   void PrintSeq(T &a, int sz) {     for (int i = 0; i < sz; i++) {       cout << a[i];       if (sz == i + 1)         cout << endl;       else         cout <<    ;     }   }   bool EQ(double a, double b) { return abs(a - b) < EPS; }   void fastStream() {     cin.tie(0);     std::ios_base::sync_with_stdio(0);   }   vector<string> split(string str, char del) {     vector<string> res;     for (int i = 0, s = 0; i < SIZE(str); i++) {       if (str[i] == del) {         if (i - s != 0) res.push_back(str.substr(s, i - s));         s = i + 1;       } else if (i == SIZE(str) - 1) {         res.push_back(str.substr(s));       }     }     return res;   }   int N;   long long as[100001];   long long leftDP[2][100001];   long long rightDP[2][100001];   long long goLeft(int pari, int pos) {     if (leftDP[pari][pos] >= 0) return leftDP[pari][pos];     long long res = 0;     if (pos == 0) {     } else {       if (pari == 0) {         res = max(res,                   goLeft(pari, pos - 1) + as[pos - 1] - (as[pos - 1] % 2 == 0));         if (as[pos - 1] != 1)           res = max(res, goLeft(pari ^ 1, pos - 1) + as[pos - 1] -                              (as[pos - 1] % 2 == 1));       } else {         if (as[pos - 1] != 1)           res = max(res,                     goLeft(pari, pos - 1) + as[pos - 1] - (as[pos - 1] % 2 == 1));       }     }     return leftDP[pari][pos] = res;   }   long long goRight(int pari, int pos) {     if (rightDP[pari][pos] >= 0) return rightDP[pari][pos];     long long res = 0;     if (pos == N - 1) {     } else {       if (pari == 0) {         res = max(res, goRight(pari, pos + 1) + as[pos] - (as[pos] % 2 == 0));         if (as[pos] != 1)           res =               max(res, goRight(pari ^ 1, pos + 1) + as[pos] - (as[pos] % 2 == 1));       } else {         if (as[pos] != 1)           res = max(res, goRight(pari, pos + 1) + as[pos] - (as[pos] % 2));       }     }     return rightDP[pari][pos] = res;   }   int main() {     memset(leftDP, -1, sizeof(leftDP));     memset(rightDP, -1, sizeof(rightDP));     cin >> N;     for (int i = 0; i < N - 1; i++) cin >> as[i];     long long res = 0;     for (int i = 0; i < N; i++) {       res = max(res, goLeft(1, i) + goRight(1, i));       res = max(res, goLeft(1, i) + goRight(0, i));       res = max(res, goLeft(0, i) + goRight(1, i));     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dirty[3009];   int main() {     int n, m;     cin >> n >> m;     for (typeof(0) i = (0); i < (m); i++) cin >> dirty[i];     sort(dirty, dirty + m);     if (!m)       cout <<  YES n ;     else if ((dirty[0] != 1) && (dirty[m - 1] != n)) {       if (m < 3)         cout <<  YES n ;       else {         bool YES = true;         for (typeof(0) i = (0); i < (m - 2); i++)           if ((dirty[i] == (dirty[i + 1] - 1)) &&               (dirty[i + 1] == (dirty[i + 2] - 1)))             YES = false;         if (YES)           cout <<  YES n ;         else           cout <<  NO n ;       }     } else       cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   const double pi = acos(-1.0);   using namespace std;   inline long long MAX2(long long a, long long b) {     return (a) > (b) ? (a) : (b);   }   inline long long MAX3(long long a, long long b, long long c) {     return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c));   }   inline long long MIN2(long long a, long long b) {     return (a) < (b) ? (a) : (b);   }   inline long long MIN3(long long a, long long b, long long c) {     return (a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c));   }   int mod = 1e9 + 7;   int64_t extGcd(int64_t a, int64_t b, int64_t& x, int64_t& y) {     if (!a) {       x = 0;       y = 1;       return b;     }     int64_t x1, y1;     int64_t d = extGcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return d;   }   inline long long addmod(long long a, long long b) {     a = a % mod + b % mod;     if (a > mod) a %= mod;     return a;   }   inline long long submod(long long a, long long b) {     a = a % mod - b % mod;     if (a < 0) a += mod;     return a;   }   inline long long mulmod(long long a, long long b) {     return (a % mod * b % mod) % mod;   }   int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};   int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};   inline long long exp(long long a, long long b) {     if (a == 0) return 0ll;     long long r = 1LL;     while (b > 0) {       if (b & 1) {         r = r * (a % mod);         r = (r + mod) % mod;       }       b /= 2;       a = (a % mod) * (a % mod);       a = (a + mod) % mod;     }     return (r + mod) % mod;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     if (a == 0) return b;     return gcd(b, a % b);   }   unsigned long int setbits(long long n) {     unsigned long int count = 0;     while (n) {       n &= (n - 1);       count++;     }     return count;   }   int main() {     if (fopen( input.txt ,  r ))       freopen( input.txt ,  r , stdin), freopen( output.txt ,  w , stdout);     ;     int t;     cin >> t;     while (t--) {       int n, k, z;       cin >> n >> k >> z;       long long a[n];       long long pre[n + 1];       pre[0] = 0;       for (long long i = (long long)(0); i < (long long)(n); i++) {         cin >> a[i];         pre[i + 1] = pre[i] + a[i];       }       long long ans = 0;       long long curr_sum = a[0];       for (int i = 1; i <= min(k, n - 1); i++) {         curr_sum += a[i];         long long prev = a[i - 1];         long long last = a[i];         int rem = (k - i);         int resz = z;         long long res = curr_sum;         int nxt = i;         while (resz > 0 and rem > 0) {           if (rem <= 0) {             nxt = i;             break;           }           res += prev;           resz--;           rem--;           if (rem <= 0) {             nxt = i - 1;             break;           }           res += last;           rem--;         }         res += pre[nxt + rem + 1] - pre[nxt + 1];         ans = MAX2(ans, res);       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long B[31][31], res = 0;   int main(void) {     for (int i = 0; i <= 30; i++) {       B[i][0] = B[i][i] = 1;       for (int j = 1; j < i; j++) B[i][j] = B[i - 1][j - 1] + B[i - 1][j];     }     int n, m, k;     cin >> n >> m >> k;     for (int b = 4; b < k; b++) {       res += (b <= n && k - b <= m) ? B[n][b] * B[m][k - b] : 0;     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000005;   const int SQRTN = 1003;   const int LOGN = 22;   const double PI = acos(-1);   const int INF = 1e9;   int MOD = 1000000007;   const int FMOD = 998244353;   const double eps = 1e-9;   long long gcd(long long a, long long b) {     if (a == 0) return (b);     return (gcd(b % a, a));   }   long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }   void solve() {     long long n, m1;     cin >> n >> m1;     long long x, k, y;     cin >> x >> k >> y;     long long arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     long long brr[m1];     for (int i = 0; i < m1; i++) cin >> brr[i];     bool flag = false;     long long i = 0, j = 0, m = -1, pos, l = -1, r;     long long result = 0;     while (i < n && j < m1) {       if (flag == true) break;       m = max(m, arr[i]);       if (m == arr[i]) pos = i;       if (arr[i] != brr[j])         i++;       else {         r = i;         i++;         j++;         int len = r - l - 1;         if (pos > l && pos < r && len < k) {           flag = true;           break;         } else {           long long c1, c2;           if (len % k == 0)             c1 = x * (len / k);           else             c1 = x * (len / k) + (len - k * (len / k)) * y;           c2 = y * len;           if (pos > l && pos < r) c2 = y * (len - k) + x;           result += min(c1, c2);         }         l = r;         m = arr[l];       }     }     if (j == m1 && i < n) {       m = arr[i - 1];       pos = i - 1;       l = i - 1;       r = n;       int len = 0;       while (i < n) {         m = max(m, arr[i]);         if (m == arr[i]) pos = i;         i++;         len++;       }       if (pos > l && pos < r && len < k)         flag = true;       else {         long long c1, c2;         if (len % k == 0)           c1 = x * (len / k);         else           c1 = x * (len / k) + (len - k * (len / k)) * y;         c2 = y * len;         if (pos > l && pos < r) c2 = (len - k) * y + x;         result += min(c1, c2);       }     }     if (i == n && j < m1) {       cout << -1 <<   n ;     } else {       if (flag)         cout << -1 <<   n ;       else         cout << result <<   n ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }     return (0);   }
#include <bits/stdc++.h>   using namespace std;   int n, cnt[100015], x[100015], y[100015], z[100015];   vector<int> a[100015];   int getpos(int i, int u) {     if (x[i] == u) return 0;     if (y[i] == u) return 1;     if (z[i] == u) return 2;   }   void dfs(int u, int v) {     cout << u <<    ;     if (cnt[v] == 0) {       cout << v;       return;     }     for (int i : a[u])       if (i) {         --cnt[x[i]];         --cnt[y[i]];         --cnt[z[i]];         int k = 3 - getpos(i, u) - getpos(i, v);         for (int &j : a[x[i]])           if (j == i) j = 0;         for (int &j : a[y[i]])           if (j == i) j = 0;         for (int &j : a[z[i]])           if (j == i) j = 0;         if (k == 0) dfs(v, x[i]);         if (k == 1) dfs(v, y[i]);         if (k == 2) dfs(v, z[i]);       }   }   int main() {     cin >> n;     for (int i = 1; i <= n - 2; ++i)       cin >> x[i] >> y[i] >> z[i], a[x[i]].push_back(i), a[y[i]].push_back(i),           a[z[i]].push_back(i), ++cnt[x[i]], ++cnt[y[i]], ++cnt[z[i]];     for (int i = 1; i <= n; ++i)       if (cnt[i] == 1) {         if (cnt[x[a[i][0]]] == 2) dfs(i, x[a[i][0]]);         if (cnt[y[a[i][0]]] == 2) dfs(i, y[a[i][0]]);         if (cnt[z[a[i][0]]] == 2) dfs(i, z[a[i][0]]);       }   }
#include <bits/stdc++.h>   const int INF = 1e7;   using namespace std;   const int N = 20;   int n, m;   int c[N];   int a[N];   int like[N];   string s[N];   int T_res = 0;   int Lika = 0;   bool Check_Res() {     int Lik;     for (int i = 2; i <= m; i++) {       {         Lik = 0;         for (int j = 0; j <= n - 1; j++)           if (a[j] == (s[i][j] -  0 )) Lik++;         if (Lik != like[i]) return false;       }     }     return true;   }   void attempt(int i, int same) {     if (i == n) {       if (same == like[1] && Check_Res() == true) {         T_res++;       }       return;     }     a[i] = !((s[1][i]) -  0 );     attempt(i + 1, same);     if (same < like[1]) {       a[i] = (s[1][i] -  0 );       attempt(i + 1, same + 1);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       cin >> s[i];       cin >> like[i];     }     attempt(0, 0);     cout << T_res;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     long long out = n * (n + 1) * (n + 2) / 6;     out *= n * (n + 1) * (n + 2) * (n + 3) * (n + 4) / 120;     cout << out <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int m = 320;   struct data {     int n, x, a[2 * m + 10];     data *next;   };   data *head;   int get(int value, int limit) {     int ret = 0;     data *k;     for (k = head; k != NULL; k = k->next) {       if (k->x > value) break;       ret += k->n;     }     if (k != NULL)       for (int i = 1; i <= k->n; i++) {         if (k->a[i] > value) break;         ret++;       }     return (min(ret, limit) + 1);   }   void split(data *k) {     data *t = new (data);     t->x = k->x = 0;     for (int i = 1; i <= m; i++) {       t->a[i] = k->a[i + m];       t->x = max(t->x, t->a[i]);       k->x = max(k->x, k->a[i]);     }     k->n = t->n = m;     t->next = k->next;     k->next = t;   }   void insert(int value, int pos) {     if (head == NULL) {       head = new (data);       head->n = 1;       head->x = head->a[1] = value;       head->next = NULL;       return;     }     data *k;     for (k = head; k != NULL; k = k->next) {       if (pos <= k->n + 1) break;       pos -= k->n;     }     for (int i = k->n; i >= pos; i--) k->a[i + 1] = k->a[i];     k->a[pos] = value;     k->x = max(k->x, value);     k->n++;     if (k->n == 2 * m) split(k);   }   int ans[100010], p[100010];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x, y;       scanf( %d%d , &x, &y);       p[x] = i;       int pos = get(x, y);       insert(x, pos);     }     int t = 0;     for (data *k = head; k != NULL; k = k->next)       for (int i = 1; i <= k->n; i++) ans[++t] = k->a[i];     reverse(ans + 1, ans + n + 1);     for (int i = 1; i <= n; i++) printf( %d%c , p[ans[i]], i == n ?   n  :    );     return (0);   }
#include <bits/stdc++.h>   using namespace std;   int dp[150][150];   int main() {     int n;     cin >> n;     for (char a =  a ; a <=  z ; a++)       for (char b =  a ; b <=  z ; b++) dp[a][b] = -2000000009;     for (char c =  a ; c <=  z ; c++) dp[c][c] = 0;     while (n--) {       string s;       cin >> s;       char a = s[0], b = s[s.length() - 1];       for (char c =  a ; c <=  z ; c++)         dp[c][b] = max(dp[c][b], dp[c][a] + (int)s.length());     }     int ans = 0;     for (char c =  a ; c <=  z ; c++) ans = max(ans, dp[c][c]);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll modinv(ll a, ll m) {     assert(m > 0);     if (m == 1) return 0;     a %= m;     if (a < 0) a += m;     assert(a != 0);     if (a == 1) return 1;     return m - modinv(m, a) * m / a;   }   template <int MOD_>   struct modnum {    private:     int v;       public:     static const int MOD = MOD_;     modnum() : v(0) {}     modnum(ll v_) : v(int(v_ % MOD)) {       if (v < 0) v += MOD;     }     explicit operator int() const { return v; }     friend bool operator==(const modnum& a, const modnum& b) {       return a.v == b.v;     }     friend bool operator!=(const modnum& a, const modnum& b) {       return a.v != b.v;     }     modnum operator~() const {       modnum res;       res.v = modinv(v, MOD);       return res;     }     modnum& operator+=(const modnum& o) {       v += o.v;       if (v >= MOD) v -= MOD;       return *this;     }     modnum& operator-=(const modnum& o) {       v -= o.v;       if (v < 0) v += MOD;       return *this;     }     modnum& operator*=(const modnum& o) {       v = int(ll(v) * ll(o.v) % MOD);       return *this;     }     modnum& operator/=(const modnum& o) { return *this *= (~o); }     friend modnum operator+(const modnum& a, const modnum& b) {       return modnum(a) += b;     }     friend modnum operator-(const modnum& a, const modnum& b) {       return modnum(a) -= b;     }     friend modnum operator*(const modnum& a, const modnum& b) {       return modnum(a) *= b;     }     friend modnum operator/(const modnum& a, const modnum& b) {       return modnum(a) /= b;     }   };   using num = modnum<998244353>;   template <typename T>   T pow(T a, long long b) {     assert(b >= 0);     T r = 1;     while (b) {       if (b & 1) r *= a;       b >>= 1;       a *= a;     }     return r;   }   vector<num> fact;   vector<num> ifact;   void init() {     int N = 1100000;     fact = {1};     for (int i = 1; i < N; i++) fact.push_back(i * fact[i - 1]);     ifact.resize(N);     ifact.back() = 1 / fact.back();     for (int i = N - 1; i > 0; i--) ifact[i - 1] = i * ifact[i];   }   num ncr(int n, int k) {     if (k < 0 || k > n) return 0;     return fact[n] * ifact[k] * ifact[n - k];   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     init();     int n, k;     cin >> n >> k;     vector<int> A(n);     for (int i = 0; i < n; i++) cin >> A[i];     int same = 0;     for (int i = 0; i < n; i++)       if (A[i] == A[(i + 1) % n]) same++;     int diff = n - same;     num ans = 0;     for (int a = 0; a * 2 <= diff; a++) {       ans += ncr(diff, a) * ncr(diff - a, a) * pow(num(k - 2), diff - a - a);     }     ans = (pow(num(k), diff) - ans) / 2;     ans = ans * pow(num(k), same);     cout << (int)ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000 + 50;   const int maxm = 1300000 + 100;   const int maxt = 3000000 + 100;   const int maxk = 10 + 3;   const int M = 2010;   const long long unit = 1LL;   const int INF = 0x3f3f3f3f;   const long long Inf = 0x3f3f3f3f3f3f3f3fLL;   const double eps = 1e-8;   const double inf = 1e15;   const double pi = acos(-1.0);   const long long mod = 998244353LL, gg = 3LL, inv2 = 499122177LL;   inline long long read() {     long long x = 0;     bool t = false;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) t = true, ch = getchar();     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch - 48, ch = getchar();     return t ? -x : x;   }   struct Peo {     int pos, id;     bool operator<(const Peo &a) const {       if (pos == a.pos) return id < a.id;       return pos < a.pos;     }   } peo[maxn];   struct City {     int pos, id;     bool operator<(const City &a) const {       if (pos == a.pos) return id < a.id;       return pos < a.pos;     }   } city[maxn];   int m, n, a[maxn], b[maxn];   long long judge(int x) {     long long ret = 0;     if (x < 0) {       for (int i = 0; i < -x; i++) ret += peo[i].pos + m - city[n + x + i].pos;       for (int i = -x; i < n; i++) ret += abs(peo[i].pos - city[i + x].pos);     } else {       for (int i = 0; i < x; i++) ret += city[i].pos + m - peo[n - x + i].pos;       for (int i = x; i < n; i++) ret += abs(city[i].pos - peo[i - x].pos);     }     return ret;   }   int main() {     m = read(), n = read();     for (int i = 0; i < n; ++i) city[i].pos = read(), city[i].id = i;     sort(city, city + n);     for (int i = 0; i < n; ++i) peo[i].pos = read(), peo[i].id = i;     sort(peo, peo + n);     int l = -n, r = n;     while (l < r) {       int m = (l + r) >> 1;       if (judge(m) < judge(m + 1))         r = m;       else         l = m + 1;     }     long long ans = Inf, anst = 0;     for (int turn = l - 100; turn <= l + 100; ++turn) {       int st = (turn % n + n) % n;       long long res = 0;       for (int i = 0; i < n; ++i) {         res += min(abs(peo[i].pos - city[st].pos),                    m - abs(peo[i].pos - city[st].pos));         ++st;         if (st >= n) st -= n;       }       if (res < ans) {         ans = res;         anst = turn;       }     }     printf( %lld n , ans);     int st = (anst % n + n) % n;     for (int i = 0; i < n; ++i) {       b[city[st].id] = peo[i].id;       ++st;       if (st >= n) st -= n;     }     for (int i = 0; i < n; ++i) printf( %d  , b[i] + 1);     return 0;   }