malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long N = 105;   long long max(long long a, long long b) {     if (a > b)       return a;     else       return b;   }   long long min(long long a, long long b) {     if (a < b)       return a;     else       return b;   }   void vecdisp(vector<long long> v) {     for (long long i = 0; i < v.size(); i++) cout << v[i] <<    ;   }   void arrdisp(long long a[], long long n) {     for (long long i = 0; i < n; i++) cout << a[i] <<    ;   }   void sarrdisp(string s[], long long n) {     for (long long i = 0; i < n; i++) cout << s[i] <<   n ;   }   void twodarrdisp(long long *a, long long r, long long c) {     for (long long i = 0; i < r; i++) {       for (long long j = 0; j < c; j++) cout << (*((a + i * c) + j)) <<    ;       cout <<   n ;     }   }   void setdisp(set<long long> s) {     for (auto it = s.begin(); it != s.end(); ++it) cout <<     << *it;   }   long long nod(long long a) {     long long c = 0;     set<long long> s;     while (a > 0) {       ++c;       s.insert(a % 10);       a /= 10;     }     if (s.size() == c)       return 1;     else       return 0;   }   long long sod(long long a) {     long long c = 0;     while (a > 0) {       c += a % 10;       a /= 10;     }     return c;   }   bool isComposite(long long n) {     if (n <= 1) return false;     if (n <= 3) return false;     if (n % 2 == 0 || n % 3 == 0) return true;     for (long long i = 5; i * i <= n; i += 6) {       if (n % i == 0 || n % (i + 2) == 0) return true;     }     return false;   }   long long countDivisors(long long n) {     long long cnt = 0;     for (long long i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i)           cnt++;         else           cnt += 2;       }     }     return cnt;   }   long long isPalindrome(string s) {     long long l = s.size();     long long flag = 0;     for (long long i = 0; i < l; i++) {       if (s[i] != s[l - i - 1]) {         flag = 1;         break;       }     }     if (flag)       return 0;     else       return 1;   }   void solve() {     long long stops[N] = {0};     long long n, r, x;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> r;       for (long long i = 0; i < r; i++) {         cin >> x;         ++stops[x];       }     }     for (long long i = 1; i <= 100; i++) {       if (stops[i] == n) cout << i <<    ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t = 1;     if (!t) cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 1;   vector<pair<long long, long long> > g[N];   set<pair<long long, long long> > q;   long long dist[N];   int main() {     cin.tie(0);     cout.tie(0);     long long n, m, u, v, w;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> u >> v >> w;       u--;       v--;       w = w * 2;       g[u].push_back({v, w});       g[v].push_back({u, w});     }     for (int i = 0; i < n; i++) {       cin >> dist[i];       q.insert({dist[i], i});     }     while (!q.empty()) {       auto now = *q.begin();       auto u = now.second;       q.erase(q.begin());       for (auto v : g[u]) {         if (dist[v.first] > dist[u] + v.second) {           q.erase({dist[v.first], v.first});           dist[v.first] = dist[u] + v.second;           q.insert({dist[v.first], v.first});         }       }     }     for (int i = 0; i < n; i++) cout << dist[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     string s, res =   ;     cin >> s;     int len = s.length();     if (len <= 3) {       cout << s[0] << endl;       return 0;     }     int l = 0, r = len - 1;     while (l + 1 < r - 1) {       if (s[l] == s[r] || s[l] == s[r - 1])         res += s[l];       else if (s[l + 1] == s[r] || s[l + 1] == s[r - 1])         res += s[l + 1];       l += 2, r -= 2;     }     string ch =   ;     if (l <= r) ch += s[l];     string re_res = res;     reverse(re_res.begin(), re_res.end());     cout << res << ch << re_res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, col[100010], out[100010], sum[3], cn, id[100010];   vector<int> g[100010];   void dfs(int x) {     for (int i = 0, v; i < g[x].size(); i++) {       v = g[x][i];       if (col[v]) continue;       col[v] = 3 ^ col[x];       dfs(v);     }   }   void get() {     for (int i = 1, st = 3; i <= n; i++)       if (col[i] == 1 && !id[i]) {         if (st == 3) cn++, st = 0;         st++, id[i] = cn;       }     for (int i = 1, st = 3; i <= n; i++)       if (col[i] == 2 && !id[i]) {         if (st == 3) cn++, st = 0;         st++, id[i] = cn;       }     puts( YES );     for (int i = 1; i <= n; i++) printf( %d  , id[i]);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0, u, v; i < m; i++) {       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 1; i <= n; i++)       if (!col[i]) col[i] = 1, dfs(i);     for (int i = 1; i <= n; i++)       for (int j = 0; j < g[i].size(); j++)         if (col[i] ^ col[g[i][j]]) out[i]++;     for (int i = 1; i <= n; i++) sum[col[i]]++;     if (!(sum[1] % 3) && !(sum[2] % 3)) return get(), 0;     if (sum[1] % 3 > sum[2] % 3) {       swap(sum[1], sum[2]);       for (int i = 1; i <= n; i++) col[i] = 3 ^ col[i];     }     for (int i = 1; i <= n; i++)       if (col[i] == 1 && sum[2] - out[i] >= 2) {         id[i] = cn = 1;         for (int p = 0; p < g[i].size(); p++) col[g[i][p]] = 0;         for (int p = 1, st = 2; st && p <= n; p++)           if (col[p] == 2) st--, id[p] = 1;         for (int p = 0; p < g[i].size(); p++) col[g[i][p]] = 2;         return get(), 0;       }     if (sum[1] > 1) {       int xp = 0, yp = 0;       for (int i = 1; i <= n; i++)         if (col[i] == 2 && sum[1] - out[i] >= 2) {           if (!xp)             xp = i;           else             yp = i;         }       if (yp) {         id[xp] = cn = 1;         for (int p = 0; p < g[xp].size(); p++) col[g[xp][p]] = 0;         for (int p = 1, st = 2; st && p <= n; p++)           if (col[p] == 1) st--, id[p] = 1;         for (int p = 0; p < g[xp].size(); p++) col[g[xp][p]] = 1;         id[yp] = cn = 2;         for (int p = 0; p < g[yp].size(); p++) col[g[yp][p]] = 0;         for (int p = 1, st = 2; st && p <= n; p++)           if (col[p] == 1) st--, id[p] = 2;         for (int p = 0; p < g[yp].size(); p++) col[g[yp][p]] = 1;         return get(), 0;       }     }     return printf( NO ), 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     vector<bool> possible(1010);     possible[0] = true;     for (int i = 0; i < 1000; ++i) {       if (!possible[i])         continue;       else {         possible[i + 3] = true;         possible[i + 5] = true;         possible[i + 7] = true;       }     }     int t;     cin >> t;     for (int tt = 0; tt < t; ++tt) {       int n;       cin >> n;       if (!possible[n]) {         cout <<  -1 n ;         continue;       } else {         vector<int64_t> ans(3);         while (n != 0) {           if (possible[n - 3]) {             n -= 3;             ans[0]++;           } else if (possible[n - 5]) {             n -= 5;             ans[1]++;           } else {             n -= 7;             ans[2]++;           }         }         cout << ans[0] <<     << ans[1] <<     << ans[2] <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   long long v[4000 + 1], c[4000 + 1], d[4000 + 1], done[4000 + 1], sol[4000 + 1],       stiva[4000 + 1];   int main() {     int n, i, j, vf;     long long sum, sc;     fscanf(stdin,  %d , &n);     for (i = 1; i <= n; i++) {       fscanf(stdin,  %I64d%I64d%I64d , &v[i], &d[i], &c[i]);     }     i = 1;     while (i <= n) {       if (done[i] == 0) {         sol[++sol[0]] = i;         sum = 0;         j = i + 1;         vf = 0;         while ((v[i] > 0) && (j <= n)) {           if (done[j] == 0) {             c[j] -= v[i];             if (c[j] < 0) {               done[j] = 1;               stiva[++vf] = j;             }             v[i]--;           }           j++;         }         while (vf > 0) {           sum = d[stiva[vf]];           vf--;           for (j = stiva[vf + 1] + 1; j <= n; j++) {             if (done[j] == 0) {               c[j] -= sum;               if (c[j] < 0) {                 done[j] = 1;                 stiva[++vf] = j;               }             }           }         }       }       i++;     }     fprintf(stdout,  %I64d n , sol[0]);     for (i = 1; i <= sol[0]; i++) {       fprintf(stdout,  %I64d  , sol[i]);     }     fclose(stdin);     fclose(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 55;   int a[maxn][maxn], b[maxn][maxn];   int vis[maxn][maxn];   vector<pair<int, int> > ans;   int main(int argc, char const *argv[]) {     ios::sync_with_stdio(false);     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         scanf( %d , &a[i][j]);       }     }     for (int i = 1; i < n; i++) {       for (int j = 1; j < m; j++) {         if (a[i + 1][j + 1] == 1 && a[i][j] == 1 && a[i + 1][j] == 1 &&             a[i][j + 1] == 1) {           ans.push_back(make_pair(i, j));         }       }     }     for (int i = 0; i < ans.size(); i++) {       int x = ans[i].first;       int y = ans[i].second;       b[x][y] = 1;       b[x + 1][y + 1] = 1;       b[x + 1][y] = 1;       b[x][y + 1] = 1;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (b[i][j] != a[i][j]) {           printf( -1 n );           return 0;         }       }     }     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) {       printf( %d %d n , ans[i].first, ans[i].second);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     cin >> n >> m >> k;     int a[m], b[k], c[105] = {0};     for (int i = 0; i < m; i++) {       cin >> a[i];     }     for (int i = 0; i < k; i++) {       cin >> b[i];     }     for (int i = 0; i < m; i++) {       c[a[i]] = 1;     }     for (int i = 0; i < k; i++) {       if (c[b[i]] == 0) c[b[i]] = 2;     }     for (int i = 1; i <= n; i++) {       cout << c[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<pair<int, bool> > list(n);     for (int i = 0; i < n; i++) cin >> list[i].first;     int tmp;     for (int i = 0; i < m; i++) {       cin >> tmp;       list[tmp - 1].second = 1;     }     vector<int> v1(n - m), v2(m);     int c1 = 0, c2 = 0;     for (int i = 0; i < n; i++) {       if (list[i].second == 1)         v2[c1++] = list[i].first;       else         v1[c2++] = list[i].first;     }     sort(v1.begin(), v1.end());     sort(v2.begin(), v2.end());     c1 = c2 = 0;     long long cnt = 0;     for (int i = 0; i < v1.size(); i++) cnt += v1[i];     if (cnt < v2.back()) {       cnt += v2.back();       v2.back() = -1;     }     for (int i = 0; i < v2.size(); i++) {       if (v2[i] != -1) cnt *= 2;     }     cout << cnt;     return 0;   }
#include <bits/stdc++.h>   const int inf = (1ll << 30) - 1;   const int maxn = (int)1e5 + 10;   using namespace std;   int dp[150][(1 << 16) + 100];   int c[111];   int r[111];   int b[111];   char temp[111];   int cntR[(1 << 16) + 10];   int cntB[(1 << 16) + 10];   int n;   void solve() {     memset(dp, -1, sizeof dp);     queue<pair<pair<int, int>, int> > pq;     scanf( %d , &n);     int xx = 0;     for (int i = 0; i < n; i++) {       scanf( %s%d%d , temp, &r[i], &b[i]);       c[i] = temp[0] ==  R  ? 1 : 0;       xx += c[i];     }     if (xx * 2 > n) {       for (int i = 0; i < n; i++) {         c[i] ^= 1;         swap(r[i], b[i]);       }     }     for (int i = 0; i < (1 << n); i++) {       for (int j = 0; j < n; j++) {         if (i & (1 << j)) {           if (c[j])             cntR[i]++;           else             cntB[i]++;         }       }     }     dp[0][0] = 0;     pq.push(make_pair(make_pair(0, 0), 0));     while (pq.size() > 0) {       int x = pq.front().first.first;       int y = pq.front().first.second;       int mask = pq.front().second;       pq.pop();       if (dp[x][mask] < y) continue;       for (int i = 0; i < n; i++) {         if (mask & (1 << i)) continue;         int nmask = mask | (1 << i);         int X = x, Y = y;         if (r[i] >= cntR[mask]) {           X += cntR[mask];         } else           X += r[i];         if (b[i] >= cntB[mask]) {           Y += cntB[mask];         } else           Y += b[i];         if (dp[X][nmask] == -1 || dp[X][nmask] < Y) {           dp[X][nmask] = Y;           pq.push(make_pair(make_pair(X, Y), nmask));         }       }     }     int sumA = 0, sumB = 0;     for (int i = 0; i < n; i++) {       sumA += r[i];       sumB += b[i];     }     int ans = inf;     for (int i = 0; i < 144; i++) {       if (dp[i][(1 << n) - 1] == -1) continue;       ans = min(ans, max(sumA - i, sumB - dp[i][(1 << n) - 1]));     }     printf( %d n , ans + n);   }   int main() {     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long a, b, c, count = 0;     scanf( %lld %lld , &a, &b);     while (a--) {       scanf( %lld , &c);       if (c <= b)         count++;       else         count += 2;     }     printf( %lld , count);   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 300100, MOD = 1e9 + 7;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int main() {     ios::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     int n;     cin >> n;     vector<int> arr(n);     int odd = 0, even = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] % 2 == 0)         even++;       else         odd++;     }     if (odd > 0 && even > 0) sort(arr.begin(), arr.end());     for (auto& a : arr) {       cout << a <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, k, l, ans = 0, sign = 1, count = 0;     string s;     getline(cin, s);     l = s.size();     vector<int> v;     for (i = 0; i < l; i++) {       if (s[i] ==  ? ) {         v.push_back(sign);         sign == 1 ? count++ : count--;       } else if (s[i] ==  + )         sign = 1;       else if (s[i] ==  - )         sign = -1;       else if (s[i] !=     && s[i] !=  = ) {         ans = 10 * ans + s[i] -  0 ;       }     }     int remain = ans - count;     vector<int> v1(v.size(), 1);     for (i = 0; i < v.size(); i++) {       if (v[i] == 1 && remain > 0) {         int old = v1[i];         v1[i] = min(ans, v1[i] + remain);         remain -= (v1[i] - old);       } else if (v[i] == -1 && remain < 0) {         int old = v1[i];         v1[i] = min(ans, v1[i] - remain);         remain += (v1[i] - old);       }     }     if (remain != 0) {       printf( Impossible n );       return 0;     }     printf( Possible n );     for (i = 0; i < v.size(); i++) {       if (i == 0) {         printf( %d  , v1[i]);       } else {         printf( %c %d  , v[i] == 1 ?  +  :  - , v1[i]);       }     }     printf( = %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, ans(0);   int main() {     cin >> n >> m;     while ((n + m) >= 3 && n > 0 && m > 0) {       if (n >= m) {         ans++;         n -= 2;         m--;       } else {         ans++;         m -= 2;         n--;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, A, ni, ai;   string si;   vector<int> hero;   vector<string> moves;   vector<int> player;   bool used[22][(int)(1 << 20)];   int dp[22][(int)(1 << 20)];   int BAD = 99999999;   int memo(int a, int b) {     if (used[a][b]) return dp[a][b];     if (a == A) return 0;     int res = -BAD;     for (int i = 0; i < A; ++i) {       if ((b & (1 << i)) > 0) continue;       int add = hero[i];       if (moves[a] ==  p ) {         if (player[a] % 2 == 0) {           add *= -1;           if (res == -BAD)             res = add + memo(a + 1, b + (1 << i));           else             res = min(res, add + memo(a + 1, b + (1 << i)));         } else {           if (res == -BAD)             res = add + memo(a + 1, b + (1 << i));           else             res = max(res, add + memo(a + 1, b + (1 << i)));         }       } else {         if (player[a] % 2 == 0) {           if (res == -BAD)             res = memo(a + 1, b + (1 << i));           else             res = min(res, memo(a + 1, b + (1 << i)));         } else {           if (res == -BAD)             res = memo(a + 1, b + (1 << i));           else             res = max(res, memo(a + 1, b + (1 << i)));         }       }     }     used[a][b] = true;     dp[a][b] = res;     return dp[a][b];   }   void solve() { cout << memo(0, 0) << endl; }   int main() {     cin >> N;     for (int i = 0; i < N; ++i) {       cin >> ni;       hero.push_back(ni);     }     sort(hero.begin(), hero.end());     reverse(hero.begin(), hero.end());     cin >> A;     for (int i = 0; i < A; ++i) {       cin >> si;       cin >> ai;       moves.push_back(si);       player.push_back(ai);     }     solve();   }
#include <bits/stdc++.h>   using namespace std;   string s;   int isPalin(int start, int end) {     if (start == end) return 1;     int i = (start + end - 1) / 2;     while (start <= i) {       if (s[start++] != s[end--]) return 0;     }     return 1;   }   int main() {     cin >> s;     int start = 0, end = s.length() - 1, flag = 1;     if (isPalin(start, end)) {       flag = ((end - start + 1) % 2 == 1) ? 2 : flag;       end = (start + end - 1) / 2;     }     while (start < end) {       if (isPalin(start, end)) {         flag = ((end - start + 1) % 2 == 1) ? 2 : flag;         end = (start + end - 1) / 2;       } else {         cout << flag << endl;         return 0;       }     }     end = ((int)s.length() - 2) / 2;     while (start < end) {       if (isPalin(start, end))         end--;       else {         cout << flag << endl;         return 0;       }     }     cout <<  Impossible n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[4];     cin >> a[0] >> a[1] >> a[2] >> a[3];     int sum, i;     sum = 0;     string s;     cin >> s;     for (i = 0; i < s.length(); i++) {       sum += a[((s[i]) -  0 ) - 1];     }     cout << sum;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int N = 2e6 + 1;   const long long mod = 998244353;   long long fact[N];   long long power(long long x, long long n) {     long long res = 1;     x %= mod;     while (n) {       if (n & 1) res = (res * x) % mod;       x = (x * x) % mod;       n >>= 1;     }     return res;   }   long long modInv(long long n) { return power(n, mod - 2); }   long long ncr(long long n, long long r) {     if (n < 0 || r < 0 || r > n) return 0;     long long num = fact[n];     long long denom = (fact[n - r] * fact[r]) % mod;     return (num * modInv(denom)) % mod;   }   void pre() {     fact[0] = 1;     for (int i = 1; i < N; i++) {       fact[i] = (fact[i - 1] * i) % mod;     }   }   void solve() {     long long n, k;     cin >> n >> k;     long long y = n - k;     if (y < 0) {       cout << 0 <<   n ;       return;     }     long long ans = ncr(n, y);     long long sum = 0;     for (int i = 0; i <= y; i++) {       long long temp = (ncr(y, y - i) * power(y - i, n)) % mod;       if (i % 2) {         sum = (sum + mod - temp) % mod;       } else {         sum = (sum + temp) % mod;       }     }     ans = (ans * sum) % mod;     if (y != n) {       ans = (ans * 2) % mod;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     std::cout << std::fixed << std::setprecision(20);     ;     int t = 1;     pre();     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   const int MAXN = 5000 + 10;   char s[MAXN];   int f[MAXN][MAXN];   bool isP[MAXN][MAXN];   int main() {     scanf( %s , s + 1);     int len = strlen(s + 1);     for (int i = 1; i <= len + 1; i++) {       f[i][i + 1] = 1;       isP[i][i + 1] = isP[i][i] = true;     }     for (int l = 2; l <= len; l++) {       for (int i = 1; i + l <= len + 1; i++) {         int j = i + l;         isP[i][j] = (isP[i + 1][j - 1] && s[i] == s[j - 1]);       }     }     for (int l = 2; l <= len; l++) {       for (int i = 1; i + l <= len + 1; i++) {         int j = i + l;         f[i][j] = f[i][j - 1] + f[i + 1][j] - f[i + 1][j - 1] + isP[i][j];       }     }     int q;     scanf( %d , &q);     while (q--) {       int l, r;       scanf( %d%d , &l, &r);       printf( %d n , f[l][r + 1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   stack<int> ST, SI;   vector<int> P;   char OR[10000], TEMP[10000];   int L, S, C;   int main() {     while (scanf( %s , TEMP) == 1) strcat(OR, TEMP);     L = strlen(OR);     for (S = 0; S < L;) {       if (OR[S + 2] ==  a )         ST.push(0), SI.push(C), C = 0, S += 7;       else if (OR[S + 2] ==  r )         ST.push(1), S += 4;       else if (OR[S + 2] ==  d )         ST.push(2), C++, S += 4;       else if (OR[S + 3] ==  a )         P.push_back(C), C = SI.top(), SI.pop(), S += 8;       else if (OR[S + 3] ==  r )         ST.pop(), S += 5;       else if (OR[S + 3] ==  d )         ST.pop(), S += 5;     }     sort(P.begin(), P.end());     int i;     for (i = 0; i < P.size(); i++) printf( %d  , P[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b;     cin >> a >> b;     while (1) {       if (a >= (2 * b)) {         a = a % (2 * b);       } else if (b >= (2 * a))         b = b % (2 * a);       else         break;       if ((a == 0 || b == 0)) break;     }     cout << a <<     << b << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1100;   int N, K, L;   string S;   int nc[26];   vector<char> res[MAXN];   int main() {     ios_base::sync_with_stdio(0);     for (int i = 0; i < 26; i++) nc[i] = 0;     cin >> N >> L >> K >> S;     for (int i = 0; i < S.length(); i++) nc[S[i] -  a ]++;     int nlo = 0, tlen = 0;     for (int i = 0; i < 26; i++) {       if (tlen == L) break;       int ncnt = (K - nlo);       int nb = nc[i] / ncnt;       nb = min(nb, L - tlen);       for (int j = nlo; j < K; j++) {         for (int k = 0; k < nb; k++) {           res[j].push_back((char) a  + i);           nc[i]--;         }       }       tlen += nb;       if (tlen == L) break;       int nleft = nc[i] % ncnt;       for (int j = 0; j < nleft; j++) {         res[nlo++].push_back((char) a  + i);         nc[i]--;       }     }     for (int i = 0; i < N; i++) {       for (int j = 0; j < 26; j++) {         while (nc[j] > 0 && res[i].size() < L) {           res[i].push_back((char) a  + j);           nc[j]--;         }       }     }     for (int i = 0; i < N; i++) {       for (char c : res[i]) cout << c;       cout <<   n ;     }   }