malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> g[50005];   vector<int> t[50005];   int T;   int col[1000005];   int team[50005];   mt19937 mt(1235577);   int x[100005], y[100005];   int ans[50005];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < (int)(m); ++i) {       int from, to;       scanf( %d%d , &from, &to), --from, --to;       x[i] = from;       y[i] = to;       g[from].push_back(to);       g[to].push_back(from);     }     for (int i = 0; i < (int)(n); ++i) {       int cnt;       scanf( %d , &cnt);       for (int j = 0; j < (int)(cnt); ++j) {         int x;         scanf( %d , &x), --x;         T = max(T, x + 1);         t[i].push_back(x);       }     }     int times = 0;     while (true) {       assert(times++ < 100);       for (int i = 0; i < (int)(T); ++i) {         col[i] = mt() & 1;       }       bool ok = true;       bool was[2];       for (int i = 0; i < (int)(n); ++i) {         was[0] = was[1] = false;         for (int x : t[i]) {           was[col[x]] = true;         }         if (!was[0] || !was[1]) {           ok = false;           break;         }       }       if (ok) {         break;       }     }     while (true) {       for (int i = 0; i < (int)(n); ++i) team[i] = mt() & 1;       int cnt = 0;       for (int i = 0; i < (int)(m); ++i)         if (team[x[i]] != team[y[i]]) {           ++cnt;         }       if (2 * cnt < m) {         continue;       }       for (int i = 0; i < (int)(n); ++i) {         for (int x : t[i])           if (col[x] == team[i]) {             ans[i] = x;             break;           }       }       bool firstTime = true;       for (int i = 0; i < (int)(n); ++i) {         if (!firstTime) {           printf(   );         }         firstTime = false;         printf( %d , ans[i] + 1);       }       printf(  n );       firstTime = true;       for (int i = 0; i < (int)(T); ++i) {         if (!firstTime) {           printf(   );         }         firstTime = false;         printf( %d , col[i] + 1);       }       printf(  n );       break;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> num;   void solve() {     int n;     cin >> n;     char arr[2][n];     for (int i = 0; i < 2; i++) {       for (int j = 0; j < n; j++) {         cin >> arr[i][j];       }     }     int row = 0, col = 0;     int visited[2][n];     memset(visited, false, sizeof(visited));     while (col < n - 1) {       visited[row][col] = true;       if (!visited[row][col + 1] && arr[row][col + 1] !=  1 )         col++;       else if (!visited[1 - row][col] && arr[1 - row][col] !=  1 ) {         row = 1 - row;       } else if (!visited[1 - row][col + 1] && arr[1 - row][col + 1] !=  1 ) {         row = 1 - row;         col++;       } else {         break;       }     }     if (col == n - 1)       cout <<  Yes  << endl;     else       cout <<  No  << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, x0, y, y0;     cin >> x >> y >> x0 >> y0;     char s[100013];     cin >> s;     int a[513][513] = {};     int num = 0;     for (int i = 0; s[i] !=   0 ; i++) {       if (a[x0][y0] != 1) {         cout <<  1  ;         num++;       } else {         cout <<  0  ;       }       a[x0][y0] = 1;       if (s[i] ==  U  && x0 > 1) {         x0--;       }       if (s[i] ==  D  && x0 < x) {         x0++;       }       if (s[i] ==  L  && y0 > 1) {         y0--;       }       if (s[i] ==  R  && y0 < y) {         y0++;       }     }     cout << (x * y) - num;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[40000005];   void oku() {     int n;     cin >> n;     for (int i = 0; i < n; i++) a[i] = i;     int l, k;     for (k = 2, l = 0; k <= n; k++, l++) {       int r = (n - 1) / k;       a[n + l] = a[r * k + l];       for (; r > 0; r--) {         a[r * k + l] = a[(r - 1) * k + l];       }     }     for (int i = l; i < l + n; i++) printf( %d  , a[i] + 1);     cout << endl;   }   void oku2() {     int n;     cin >> n;     for (int i = 0; i < n; i++) a[i] = i;     for (int i = 2; i <= n; i++) {       for (int k = 0; i * k < n; k++)         for (int j = i * k; j + 1 < min(n, i * (k + 1)); j++)           swap(a[j], a[j + 1]);     }     for (int i = 0; i < n; i++) cout << a[i] <<    ;     cout << endl;   }   int main() {     oku();     return 0;   }
#include <bits/stdc++.h>   const int maxN = 1000000;   char in[maxN + 1];   int occ[10], instanceOfRest[7] = {8169, 8961, 8619, 6891, 8691, 9168, 8196};   int main() {     scanf( %s , in);     int s = std::strlen(in);     for (int i = 0; i < s; i++) occ[in[i] -  0 ]++;     occ[1]--, occ[6]--, occ[8]--, occ[9]--;     int powerOf10 = 1, res = 0, occOfZero = occ[0];     occ[0] = 4;     for (int i = 0; i < 10; i++) {       for (int j = 0; j < occ[i]; j++) {         res = (res + (i % 7) * powerOf10) % 7;         powerOf10 = (powerOf10 * 3) % 7;       }     }     for (int i = 9; i > 0; i--)       for (int j = 0; j < occ[i]; j++) printf( %d , i);     printf( %d , instanceOfRest[(7 - res) % 7]);     while (occOfZero--) printf( 0 );     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;      int b[200100];      int l[200100], r[200100];      int main(){       int T; scanf( %d , &T);       int tot = T;       int num = 0;       while (T--){           num++;           int N, K, M; scanf( %d%d%d , &N, &K, &M);           for (int i = 1; i <= M; i++) scanf( %d , &b[i]);           int ind = 1;           int cnt = 0;           for (int i = 1; i <= N; i++){               l[i] = 0;               if (ind == M+1 || b[ind] != i){                   cnt++;               } else {                   ind++;                   l[i] = cnt;               }           }           if (cnt%(K-1) != 0){               printf( NO n );               continue;           }           bool work = false;           for (int i = 1; i <= N; i++){               if (l[i] >= K/2 && cnt-l[i] >= K/2){                   work = true;                   break;               }           }           if (work) printf( YES n );           else printf( NO n );       }   }
#include <bits/stdc++.h>   using namespace std;   enum faces {     Tetrahedron = 4,     Cube = 6,     Octahedron = 8,     Dodecahedron = 12,     Icosahedron = 20   };   int main() {     int n;     cin >> n;     long long total = 0;     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       if (s ==  Tetrahedron )         total += Tetrahedron;       else if (s ==  Cube )         total += Cube;       else if (s ==  Octahedron )         total += Octahedron;       else if (s ==  Dodecahedron )         total += Dodecahedron;       else if (s ==  Icosahedron )         total += Icosahedron;     }     cout << total;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long even[222222] = {0}, a[222222], odd[222222] = {0}, backEven[222222],             cur, best = numeric_limits<int>::min(), besteven = 0;   int main() {     int n;     scanf( %d , &n);     for (int i = 2; i <= n; i++) cin >> a[i];     even[1] = 0;     odd[1] = 0;     for (int i = 2; i <= n; i++) {       even[i] = even[i - 1] + (a[i] / 2) * 2;       if (a[i] < 2) even[i] = 0;       odd[i] = odd[i - 1] + a[i];       if (a[i] % 2 == 0) odd[i]--;     }     backEven[n] = 0;     for (int i = n - 1; i >= 1; i--) {       backEven[i] = backEven[i + 1] + (a[i + 1] / 2) * 2;       if (a[i + 1] < 2) backEven[i] = 0;     }     for (int j = 1; j <= n; j++) {       cur = besteven + backEven[j] + odd[j];       best = max(cur, best);       besteven = max(besteven, even[j + 1] - odd[j + 1]);     }     cout << best;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   void solve() {     int n, m;     cin >> n >> m;     int mex = INT_MAX, curr = 0;     for (int i = 0; i < m; i++) {       int l, r;       cin >> l >> r;       mex = min(mex, r - l + 1);     }     cout << mex <<   n ;     for (int i = 0; i < n; i++) {       cout << curr <<    ;       curr++;       if (curr == mex) curr = 0;     }   }   int main() {     ios_base::sync_with_stdio(false);     cout.tie(NULL);     cin.tie(NULL);     ;     long long int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unsigned int dp[100010];   int n, m, maxx;   char str[100010];   int main() {     cin >> n;     if (n & 1) {       cout << 0 << endl;       return 0;     }     scanf( %s , str + 1);     dp[0] = 1;     for (int i = 1; i <= n; i++)       if (str[i] ==  ? ) {         m++;         maxx = min(i / 2, m);         for (int j = maxx; j; j--) dp[j] += dp[j - 1];       }     if (m < n / 2) {       cout << 0 << endl;       return 0;     }     m -= n / 2;     while (m--) dp[n >> 1] *= 25;     cout << dp[n >> 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string a, b;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> a >> b;     int p1 = -1, p2 = -1;     for (int i = 0; i < n; i++) {       if (a[i] != b[i]) {         p1 = i;         break;       }     }     for (int i = n - 1; i >= 0; i--) {       if (a[i] != b[i]) {         p2 = i;         break;       }     }     string x =   , y =   ;     for (int i = p1; i <= p2; i++) {       x += a[i];       y += b[i];     }     int sol = 0;     if (x + y.back() == x[0] + y) sol++;     if (y[0] + x == y + x.back()) sol++;     cout << sol <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300005;   pair<int, int> pa[maxn];   int main() {     int n, a, b;     scanf( %d%d%d , &n, &a, &b);     for (int i = 0; i < n; ++i) {       scanf( %d , &pa[i].first);       pa[i].second = i + 1;     }     sort(pa, pa + n);     for (int i = 0; i < n; ++i) {       int c = (a + pa[i].first - 1) / pa[i].first + i;       if (c < n && (b + pa[c].first - 1) / pa[c].first <= n - c) {         int d = (b + pa[c].first - 1) / pa[c].first;         puts( Yes );         printf( %d %d n , c - i, d);         printf( %d , pa[i].second);         for (int j = i + 1; j < c; ++j) printf(  %d , pa[j].second);         printf(  n );         printf( %d , pa[c].second);         for (int j = 1; j < d; ++j) printf(  %d , pa[c + j].second);         printf(  n );         return 0;       }     }     swap(a, b);     for (int i = 0; i < n; ++i) {       int c = (a + pa[i].first - 1) / pa[i].first + i;       if (c < n && (b + pa[c].first - 1) / pa[c].first <= n - c) {         int d = (b + pa[c].first - 1) / pa[c].first;         puts( Yes );         printf( %d %d n , d, c - i);         printf( %d , pa[c].second);         for (int j = 1; j < d; ++j) printf(  %d , pa[c + j].second);         printf(  n );         printf( %d , pa[i].second);         for (int j = i + 1; j < c; ++j) printf(  %d , pa[j].second);         printf(  n );         return 0;       }     }     puts( No );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 100005;   vector<pair<long long, char>> adj[maxn];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long u, v;       char c;       cin >> u >> v >> c;       adj[u].push_back({v, c});       adj[v].push_back({u, c});     }     vector<long long> res(2e5, 0);     for (long long c : { R ,  B }) {       vector<long long> vec;       bool vis[maxn], color[maxn];       for (long long i = 0; i <= n; i++) vis[i] = color[i] = false;       for (long long i = 1; i <= n; i++) {         if (vis[i]) continue;         vector<long long> s, t;         queue<long long> q;         q.push(i);         vis[i] = true;         while (!q.empty()) {           long long u = q.front();           q.pop();           if (color[u])             s.push_back(u);           else             t.push_back(u);           for (pair<long long, char> e : adj[u]) {             if (vis[e.first]) continue;             if (e.second == c)               color[e.first] = !color[u];             else               color[e.first] = color[u];             vis[e.first] = true;             q.push(e.first);           }         }         if (s.size() < t.size())           for (long long u : s) vec.push_back(u);         else           for (long long u : t) vec.push_back(u);       }       bool ok = true;       for (long long u = 1; u <= n; u++) {         for (pair<long long, char> e : adj[u]) {           if (e.second == c)             ok &= color[e.first] != color[u];           else             ok &= color[e.first] == color[u];         }       }       if (!ok) continue;       if (vec.size() < res.size()) res = vec;     }     if (res.size() == 2e5)       cout <<  -1 n ;     else {       cout << res.size() <<   n ;       for (long long i : res) cout << i <<    ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k, l, c, d, p, nl, np;   int main() {     cin >> n >> k >> l >> c >> d >> p >> nl >> np;     int a, b, e;     a = (k * l) / nl;     b = c * d;     e = p / np;     cout << min(min(a, b), e) / n << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> ch(26);     for (int i = 0; i < n; i++) {       char c;       cin >> c;       ch[c -  a ]++;     }     if (k >= *max_element(ch.begin(), ch.end()))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
/*   #pragma GCC optimize( O2 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( avx,avx2,sse,sse2,fma )   */   #include <bits/stdc++.h>      using namespace std;      typedef long long ll;   typedef long double ld;   typedef pair<int , int> pii;      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());      const int maxn = 3e6;   const ll mod = 1e9+7;   const ld PI = acos((ld)-1);      #define pb push_back   #define endl   n    #define dokme(x) cout << x , exit(0)   #define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)   #define ms(x , y) memset(x , y , sizeof x)   ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}      ll n , q , k;         int32_t main(){    migmig;    cin >> q;    while(q --){     cin >> n >> k;     if(n - (k - 1) <= n/2){      for(int i = 1 ; i < k ; i ++)       cout << 1 <<    ;      cout << n - (k - 1) << endl;      continue;     }     if(n%k == 0){      for(int i = 1 ; i <= k ; i ++)       cout << n / k <<    ;      cout << endl;      continue;     }     for(int i = 1 ; i <= k - 3 ; i ++){      n--;      cout << 1 <<    ;     }     if(n % 3 == 0){      cout << n/3 <<     << n/3 <<     << n/3 << endl;      continue;     }     if(n % 2){      cout << 1 <<     << (n - 1)/2 <<     << (n - 1)/2 << endl;      continue;     }     if((n - 2)%4 == 0){      cout << 2 <<     << (n - 2) / 2 <<     << (n - 2) / 2 << endl;      continue;     }       cout << n / 2 <<     << n/4 <<      << n/4 << endl;    }    return(0);   }
#include <bits/stdc++.h>   using namespace std;   int dx[4] = {1, 0, -1, 0};   int dy[4] = {0, 1, 0, -1};   int ddx[8] = {-1, -1, 0, 1, 1, 1, 0, -1};   int ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};   bool debug = false;   int main() {     int n, L, a;     cin >> n >> L >> a;     int ans = 0, now = 0;     for (int i = 0; i < n; i++) {       int t, l;       cin >> t >> l;       ans += (t - now) / a;       now = t + l;     }     ans += (L - now) / a;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 7;   bool pri(int a) {     if (a == 1) return 0;     for (int i = 2; i * i <= a; i++) {       if (a % i == 0) {         return 0;       }     }     return 1;   }   long long n, m, t, a[200000];   string s;   int main() {     cin >> t;     while (t--) {       long long x, y;       cin >> x >> y;       if (x > y) {         cout << x + y <<   n ;         continue;       }       if (x == y) {         cout << x <<   n ;         continue;       }       if (2 * x >= y) {         cout << (x + y) / 2 <<   n ;         continue;       }       x = x * int(y / x);       cout << (x + y) / 2 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unsigned short log2(unsigned short x) {     unsigned short log = 0;     while (x > 1) {       log++;       x /= 2;     }     return log;   }   int main() {     unsigned short a, b, n, r;     cin >> n >> a >> b;     a -= 1;     b -= 1;     n /= 2;     if (a / n != b / n)       cout <<  Final!  << endl;     else {       r = log2(n);       n /= 2;       while (a / n == b / n) {         n /= 2;         r -= 1;       }       cout << r << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class flow_t, const flow_t inf>   struct Dinic {     struct edge_t {       long long to;       flow_t cap, flow;       edge_t(long long to = 0, flow_t cap = 0, flow_t flow = 0)           : to(to), cap(cap), flow(flow) {}     };     long long n, s, t;     vector<vector<long long>> g;     vector<long long> d, ptr;     vector<edge_t> ed;     Dinic(long long n = 0, long long s = 0, long long t = 0) : n(n), s(s), t(t) {       g.assign(n + 5, vector<long long>());       ed.clear();     }     void add(long long u, long long v, long long cap) {       g[u].push_back(ed.size());       ed.push_back(edge_t(v, cap, 0));       g[v].push_back(ed.size());       ed.push_back(edge_t(u, 0, 0));     }     bool bfs() {       d.assign(n + 5, -1);       ptr.assign(n + 5, 0);       queue<long long> q;       d[s] = 0;       q.push(s);       while (!q.empty()) {         long long u = q.front();         q.pop();         for (long long id : g[u]) {           long long v = ed[id].to;           if (d[v] == -1 && ed[id].cap > ed[id].flow) {             d[v] = d[u] + 1;             q.push(v);           }         }       }       return d[t] != -1;     }     flow_t dfs(long long u, flow_t flow) {       if (u == t || !flow) return flow;       for (long long& i = ptr[u]; i < (long long)g[u].size(); ++i) {         long long id = g[u][i];         long long v = ed[id].to;         if (d[v] != d[u] + 1 || ed[id].cap <= ed[id].flow) continue;         flow_t nxt = dfs(v, min(flow, ed[id].cap - ed[id].flow));         if (nxt) {           ed[id].flow += nxt;           ed[id ^ 1].flow -= nxt;           return nxt;         }       }       return 0;     }     flow_t max_flow() {       while (bfs())         while (dfs(s, inf))           ;       flow_t ret = 0;       for (long long id : g[s]) ret += ed[id].flow;       return ret;     }     vector<long long> path;     flow_t trace(long long u) {       path.push_back(u);       if (u == t) return 1;       for (long long id : g[u]) {         long long v = ed[id].to;         if (ed[id].flow > 0) {           ed[id].flow--;           trace(v);           return 1;         }       }       return 0;     }     vector<vector<long long>> solve() {       vector<vector<long long>> ret;       while (true) {         path.clear();         if (trace(s))           ret.push_back(path);         else           break;       }       return ret;     }   };   signed main() {     ios_base::sync_with_stdio(false);     long long n, m;     cin >> n >> m;     long long s = 0, t = n + m + 1;     Dinic<long long, (long long)1e18> dn(n + m, s, t);     for (long long i = 1; i <= n; ++i) {       long long x;       cin >> x;       dn.add(i, t, x);     }     long long sum = 0;     for (long long i = 1; i <= m; ++i) {       long long u, v;       long long w;       cin >> u >> v >> w;       dn.add(n + i, u, 1e18);       dn.add(n + i, v, 1e18);       dn.add(s, n + i, w);       sum += w;     }     cout << sum - dn.max_flow() <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   template <class _Tp>   _Tp gcd(_Tp a, _Tp b) {     return (b == 0) ? (a) : (gcd(b, a % b));   }   const long long Inf = 1000000000000000000ll;   const int inf = 1000000000;   char buf[1 << 25], *p1 = buf, *p2 = buf;   inline int getc() {     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 25, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline int read() {     int x = 0, f = 0;     char c = getc();     while (!isdigit(c)) (c ==  - ) && (f = 1), c = getc();     while (isdigit(c)) x = x * 10 + (c & 15), c = getc();     return f ? -x : x;   }   const int N = 200005;   const int Lg = 19;   int dfn[N], fa[N][Lg], dep[N], siz[N];   int sum[N * 4], t[N * 4], cnt;   vector<int> e[N];   map<int, int> added[N];   void dfs(int u, int f) {     dfn[u] = ++cnt;     fa[u][0] = f;     dep[u] = dep[f] + 1;     siz[u] = 1;     for (int i = 0; i < e[u].size(); ++i) {       int to = e[u][i];       if (to == f) continue;       dfs(to, u);       siz[u] += siz[to];     }   }   void pushup(int o, int len) {     if (t[o])       sum[o] = len;     else if (len == 1)       sum[o] = 0;     else       sum[o] = sum[o << 1] + sum[o << 1 | 1];   }   void update(int o, int l, int r, int L, int R, int val) {     if (L <= l && r <= R) {       t[o] += val;       pushup(o, r - l + 1);       return;     }     int mid = l + r >> 1;     if (L <= mid) update(o << 1, l, mid, L, R, val);     if (R > mid) update(o << 1 | 1, mid + 1, r, L, R, val);     pushup(o, r - l + 1);   }   int n, q;   int main() {     n = read();     q = read();     for (int i = 1; i < n; ++i) {       int x = read(), y = read();       e[x].push_back(y);       e[y].push_back(x);     }     dfs(1, 0);     for (int w = 1; w < Lg; ++w)       for (int i = 1; i <= n; ++i) fa[i][w] = fa[fa[i][w - 1]][w - 1];     while (q--) {       int u = read(), v = read(), k;       if (dfn[u] > dfn[v]) swap(u, v);       if (added[u][v])         added[u][v] = 0, k = -1;       else         added[u][v] = 1, k = 1;       if (dfn[u] + siz[u] - 1 >= dfn[v] + siz[v] - 1) {         int x = v;         for (int w = Lg - 1; ~w; --w)           if (dep[fa[x][w]] > dep[u]) x = fa[x][w];         update(1, 1, n, dfn[x], dfn[v] - 1, k);         update(1, 1, n, dfn[v] + siz[v], dfn[x] + siz[x] - 1, k);       } else {         update(1, 1, n, 1, dfn[u] - 1, k);         update(1, 1, n, dfn[u] + siz[u], dfn[v] - 1, k);         update(1, 1, n, dfn[v] + siz[v], n, k);       }       printf( %d n , n - sum[1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-13;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     int k = n / m;     vector<int> v(n);     vector<vector<int>> d(m);     for (int i = 0; i < (int)(n); ++i) {       cin >> v[i];       d[v[i] % m].push_back(i);     }     long long ans = 0;     vector<pair<int, int>> free;     for (int i = 0; i < (int)(2 * m); ++i) {       int cur = i % m;       while (d[cur].size() > k) {         free.push_back(make_pair(d[cur].back(), i));         d[cur].pop_back();       }       while (d[cur].size() < k && !free.empty()) {         d[cur].push_back(free.back().first);         v[free.back().first] += i - free.back().second;         ans += i - free.back().second;         free.pop_back();       }     }     cout << ans <<   n ;     for (auto x : v) cout << x <<    ;     return 0;   }