malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 160;   const int mod = 1e9 + 7;   int n, m, f[N][N][2][2], ans;   void inc(int& a, int b) {     if (a += b, a >= mod) a -= mod;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; ++i)       for (int j = i; j <= m; ++j) {         f[i][j][1][1] = 1;       }     for (int h = 1; h <= n; ++h) {       int tot = 0;       for (int i = 1; i <= m; ++i)         for (int j = 1; j <= m; ++j)           for (int kl = 0; kl <= 1; ++kl)             for (int kr = 0; kr <= 1; ++kr) {               inc(tot, f[i][j][kl][kr]);             }       inc(ans, (long long)tot * (n + 1 - h) % mod);       if (h == n) break;       for (int j = 1; j <= m; ++j)         for (int i = 1; i < j; ++i)           for (int kr = 0; kr <= 1; ++kr) {             inc(f[i + 1][j][0][kr], (f[i][j][0][kr] + f[i][j][1][kr]) % mod);           }       for (int i = 1; i <= m; ++i)         for (int j = m; j > i; --j)           for (int kl = 0; kl <= 1; ++kl) {             inc(f[i][j - 1][kl][0], (f[i][j][kl][0] + f[i][j][kl][1]) % mod);           }       for (int j = 2; j <= m; ++j)         for (int i = j; i > 1; --i)           for (int kr = 0; kr <= 1; ++kr) {             inc(f[i - 1][j][1][kr], f[i][j][1][kr]);           }       for (int i = 1; i <= m - 1; ++i)         for (int j = i; j < m; ++j)           for (int kl = 0; kl <= 1; ++kl) {             inc(f[i][j + 1][kl][1], f[i][j][kl][1]);           }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e5 + 5;   char a[MAX_N];   int main() {     int N;     cin >> N;     scanf( %s , a + 1);     int cnt = 0;     for (int i = 1; i <= N; i++) {       if (a[i] ==  S  && a[i] >= 2 && a[i - 1] ==  G ) {         cnt++;       }     }     if (a[N] ==  G ) cnt++;     int len = 0, prelen = (cnt >= 2), ans = 0;     for (int i = 1; i <= N; i++) {       if (a[i] ==  G ) {         len++;         ans = max(ans, len + prelen);       }       if (a[i] ==  S ) {         if (2 <= i && i <= N - 1 && a[i - 1] ==  G  && a[i + 1] ==  G ) {           if (cnt == 2) {             prelen = len;           } else if (cnt >= 3) {             prelen = len + 1;           }         } else {           prelen = (cnt >= 2);         }         len = 0;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, a[4][200010], len;   string s;   bool check(int x) {     for (int i = x; i <= len; i++)       if (a[1][i] - a[1][i - x] && a[2][i] - a[2][i - x] && a[3][i] - a[3][i - x])         return 1;     return 0;   }   int main() {     scanf( %d , &t);     while (t--) {       cin >> s;       len = s.size();       s += s[s.size() - 1];       for (int i = len; i >= 1; i--) {         s[i] = s[i - 1];       }       int l = 1, r = len;       for (int i = 1; i <= len; i++) {         if (s[i] ==  1 ) {           a[1][i] = a[1][i - 1] + 1;           a[2][i] = a[2][i - 1];           a[3][i] = a[3][i - 1];         }         if (s[i] ==  2 ) {           a[1][i] = a[1][i - 1];           a[2][i] = a[2][i - 1] + 1;           a[3][i] = a[3][i - 1];         }         if (s[i] ==  3 ) {           a[1][i] = a[1][i - 1];           a[2][i] = a[2][i - 1];           a[3][i] = a[3][i - 1] + 1;         }       }       if (!a[1][len] || !a[2][len] || !a[3][len]) {         puts( 0 );         continue;       }       while (l + 1 < r) {         int mid = (l + r) >> 1;         if (check(mid))           r = mid;         else           l = mid;       }       cout << r << endl;       memset(a, 0, sizeof(a));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-10;   const long double INF = (int)1e9 + 34;   const int N = (int)1e6 + 34;   void ret(int x) {     cout << x;     exit(0);   }   int n, k;   int a[N];   int b[N], len;   bool u[N];   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , a + i);     srand(3431);     sort(a, a + n);     a[n] = 100000000;     int lst = a[0];     b[len++] = a[0];     for (int i = 1; i < n; i++)       if (a[i + 1] - lst >= k) {         b[len++] = lst = a[i];       }     int mn = a[0];     for (int i = 0; i < n; i++) mn = min(mn, a[i]);     vector<int> v;     for (int i = 0; i < 30; i++) v.push_back(a[abs((rand() << 16) ^ rand()) % n]);     for (int i = 1; i <= 1000000; i++)       for (int j = 0; !u[i] && j < (int)v.size(); j++)         if (v[j] % i > k) u[i] = true;     int l1 = -1;     int pr;     bool fail;     for (int d = mn; d >= 0; d--) {       if (u[d]) continue;       fail = false;       for (int i = 0; !fail && i < len; i++)         if (b[i] % d > k) fail = true;       if (!fail) {         pr = d;         break;       }       l1 = d;     }     for (int d = pr; d >= 0; d--) {       if (u[d]) continue;       fail = false;       for (int i = n - 1; !fail && i >= 0; i--)         if (a[i] % d > k) fail = true;       if (!fail) {         pr = d;         break;       }       l1 = d;     }     cout << pr;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     long long n, cnt1 = 0, cnt2 = 0, l, r;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> l >> r;       cnt1 += l;       cnt2 += r;     }     cout << min(cnt1, n - cnt1) + min(cnt2, n - cnt2);   }
#include <bits/stdc++.h>   using namespace std;   template <ostream& out = cout, class... T>   void prints(T&&...) {}   template <ostream& out = cout, class... T>   void printe(T&&...) {}   template <ostream& out = cout, class... T>   void printw(T&&...) {}   template <ostream& out = cout, class... T>   void printew(T&&...) {}   template <ostream& out = cout, class... T>   void printb(T&&...) {}   template <ostream& out = cout, class... T>   void printd(T&&...) {}   template <ostream& out = cout, class... T>   void printde(T&&...){};   template <class T>   istream& operator>>(istream& in, vector<T>& v) {     for (auto& e : v) {       in >> e;     }     return in;   }   int main() {     int n;     cin >> n;     vector<char> s(n);     cin >> s;     int k = 0;     bool pr;     for (int i = 0; i < n; i++) {       if (s[i] ==  1 ) {         k++;         pr = true;       } else {         break;       }     }     if (k == n) {       cout <<  YES ;       return 0;     }     int l = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  0 ) {         l++;         pr = false;       } else {         break;       }     }     if (l == n) {       cout <<  YES ;       return 0;     }     int m;     m = max(l, k);     for (int i = 0; i < n; i = i + m) {       if (s[i] ==  1  && pr) {         for (int j = 0; j < m; j++) {           if (s[j + i] !=  1 ) {             cout <<  NO ;             return 0;           }         }         pr = false;         continue;       }       if (s[i] ==  0  && !pr) {         for (int j = 0; j < m; j++) {           if (s[j + i] !=  0 ) {             cout <<  NO ;             return 0;           }         }         pr = true;         continue;       }       cout <<  NO ;       return 0;     }     cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   const int nax = 505;   int n;   char grid[nax][nax];   int cc[nax][nax];   int cc_size[nax * nax];   int when_added[nax * nax];   const int dx[4] = {-1, 1, 0, 0};   const int dy[4] = {0, 0, -1, 1};   const char EMPTY =  . ;   bool inside(int x, int y) { return 0 <= min(x, y) && max(x, y) < n; }   void dfs(int x, int y, int which_cc) {     cc[x][y] = which_cc;     ++cc_size[which_cc];     for (int i = 0; i < 4; ++i) {       int x2 = x + dx[i];       int y2 = y + dy[i];       if (inside(x2, y2) && grid[x2][y2] == EMPTY && cc[x2][y2] == 0)         dfs(x2, y2, which_cc);     }   }   void add(int x, int y, int& answer, int current_time) {     if (inside(x, y) && grid[x][y] == EMPTY) {       int id = cc[x][y];       if (when_added[id] != current_time) {         when_added[id] = current_time;         answer += cc_size[id];       }     }   }   int main() {     int k;     scanf( %d%d , &n, &k);     for (int i = 0; i < n; ++i) scanf( %s , grid[i]);     int how_many_cc = 0;     for (int x = 0; x < n; ++x)       for (int y = 0; y < n; ++y)         if (grid[x][y] == EMPTY && cc[x][y] == 0) dfs(x, y, ++how_many_cc);     int cur_time = 1;     int best_answer = 0;     for (int y_low = 0; y_low + k <= n; ++y_low) {       for (int x = 0; x < k; ++x)         for (int y = y_low; y < y_low + k; ++y) --cc_size[cc[x][y]];       for (int x_low = 0; x_low + k <= n; ++x_low) {         int answer = k * k;         for (int x = x_low; x < x_low + k; ++x) {           add(x, y_low - 1, answer, cur_time);           add(x, y_low + k, answer, cur_time);         }         for (int y = y_low; y < y_low + k; ++y) {           add(x_low - 1, y, answer, cur_time);           add(x_low + k, y, answer, cur_time);         }         ++cur_time;         best_answer = max(best_answer, answer);         if (x_low + k != n) {           for (int y = y_low; y < y_low + k; ++y) {             ++cc_size[cc[x_low][y]];             --cc_size[cc[x_low + k][y]];           }         }       }       for (int x = n - k; x < n; ++x)         for (int y = y_low; y < y_low + k; ++y) ++cc_size[cc[x][y]];     }     printf( %d , best_answer);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000000;   const int maxn = 100010;   int a[maxn];   int max(int a, int b) { return a > b ? a : b; }   int min(int a, int b) { return a > b ? b : a; }   int main() {     int n, l, r, i, j;     string s;     while (cin >> n) {       for (i = 0; i < n; i++) cin >> a[i];       cin >> s;       l = -inf, r = inf;       for (i = 4; i < n; i++) {         if (s[i] ==  1 ) {           int maxi = -inf;           for (j = i; j >= i - 4; j--) {             maxi = max(maxi, a[j]);           }           int cnt = 0;           for (j = i; j >= i - 4; j--) {             if (s[j] ==  0 ) cnt++;           }           if (cnt == 4) {             l = max(l, maxi + 1);           }         } else if (s[i] ==  0 ) {           int mina = inf;           for (j = i; j >= i - 4; j--) {             mina = min(mina, a[j]);           }           int cnt = 0;           for (j = i; j >= i - 4; j--) {             if (s[j] ==  1 ) cnt++;           }           if (cnt == 4) {             r = min(r, mina - 1);           }         }       }       cout << l <<     << r << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long i, j, k, n, v[200010], m, a, b, x, y, h, w, l, p, ans, numitor, aux,       mini, sum, poz;   string s1, s2, second;   char c;   map<long long, long long> mip;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> x;     for (long long i = 1; i <= n; i++) {       cin >> v[i];       if (v[i] < x)         v[i] = -1;       else if (v[i] > x)         v[i] = 1;       else {         v[i] = 0;         poz = i;       }     }     mip[0] = 1;     sum = 0;     for (long long i = 1; i <= n; i++) {       sum += v[i];       if (i >= poz) {         if (mip.find(sum) != mip.end()) ans += mip[sum];         if (mip.find(sum - 1) != mip.end()) ans += mip[sum - 1];       } else {         mip[sum] += 1;         v[i] = sum;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, ex, ey, sx[N], sy[N];   char s[N];   inline bool check(int m) {     for (int i = 1; i + m - 1 <= n; i++) {       int decx = sx[n] - sx[i + m - 1] + sx[i - 1];       int decy = sy[n] - sy[i + m - 1] + sy[i - 1];       int nedx = ex - decx;       int nedy = ey - decy;       if (abs(nedx) + abs(nedy) <= m && !(m - abs(nedx) - abs(nedy) & 1))         return 1;     }     return 0;   }   int main() {     scanf( %d%s%d%d , &n, s + 1, &ex, &ey);     for (int i = 1; i <= n; i++) {       sx[i] = sx[i - 1] + (s[i] ==  L  ? -1 : (s[i] ==  R  ? 1 : 0));       sy[i] = sy[i - 1] + (s[i] ==  D  ? -1 : (s[i] ==  U  ? 1 : 0));     }     int l = 0, r = n, mid, ans = -1;     while (l <= r) {       mid = l + r >> 1;       if (check(mid)) {         ans = mid;         r = mid - 1;       } else {         l = mid + 1;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, i, j, x, y = 0, w, z = 0, e;     cin >> a >> b >> c >> d;     if (d % c != 0) {       cout << 0;       return 0;     }     w = d / c;     if (c == d) {       if (c >= a && c <= b)         cout << 1;       else         cout << 0;       return 0;     }     for (i = 1; i <= sqrt(w); i++) {       if (w % i == 0) {         x = w / i;         e = 0;         for (j = 2; j <= i; j++) {           if (i % j == 0 && x % j == 0) {             e = 1;             break;           }         }         if (e == 0) {           if (i * c >= a && i * c <= b && x * c >= a && x * c <= b) y++;         }       }     }     cout << y * 2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 5;   int tree[4 * MAXN], n, m, a[MAXN], size = 0, less1[MAXN];   vector<int> del, nums;   void initialize(int l, int r, int node) {     tree[node] = r - l + 1;     if (r == l) return;     int mid = (l + r) / 2;     initialize(l, mid, 2 * node);     initialize(mid + 1, r, 2 * node + 1);   }   int elim(int node) {     while (node >= 1) {       tree[node]--;       node /= 2;     }   }   void find(int l, int r, int sum, int node) {     if (l == r) {       nums[l] = -2;       elim(node);       return;     }     int mid = (l + r) / 2;     if (tree[2 * node] >= sum)       find(l, mid, sum, 2 * node);     else       find(mid + 1, r, sum - tree[2 * node], 2 * node + 1);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     for (int i = 0; i < m; ++i) {       cin >> a[i];     }     for (int i = 0; i < MAXN; ++i) less1[i] = 0;     for (int i = 0; i < m - 1; ++i)       for (int k = a[i]; k < a[i + 1]; ++k) less1[k] = i + 1;     for (int i = a[m - 1]; i < MAXN; ++i) less1[i] = m;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       if (x == -1) {         del.push_back(less1[size]);         size -= less1[size];       } else {         nums.push_back(x);         size++;       }     }     if (nums.size() == 0) {       cout <<  Poor stack!  << endl;       return 0;     }     initialize(0, nums.size() - 1, 1);     for (int i = 0; i < del.size(); ++i)       for (int j = del[i] - 1; j >= 0; --j) find(0, nums.size() - 1, a[j], 1);     int ct = 0;     for (int i = 0; i < nums.size(); ++i) {       if (nums[i] != -2) {         cout << nums[i];         ++ct;       }     }     if (ct == 0) cout <<  Poor stack! ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long INFF = 0x3f3f3f3f3f3f3f3f;   const double pi = acos(-1.0);   const double eps = 1e-9;   const long long mod = 1e9 + 7;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch< 0  | ch>  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   void Out(int aa) {     if (aa > 9) Out(aa / 10);     putchar(aa % 10 +  0 );   }   int n, t;   int f[55], s[55], p[55];   double dp[55][5005];   bool check(double mid) {     for (int i = n; i >= 1; i--) {       for (int j = t + 1; j <= 5000; j++) dp[i + 1][j] = mid;       for (int j = 0; j <= t; j++) {         double t1 = (dp[i + 1][j + f[i]] + f[i]) * p[i] / 100;         double t2 = (dp[i + 1][j + s[i]] + s[i]) * (100 - p[i]) / 100;         dp[i][j] = min(mid, t1 + t2);       }     }     return dp[1][0] < mid;   }   int main() {     n = read(), t = read();     for (int i = 1; i <= n; i++) f[i] = read(), s[i] = read(), p[i] = read();     double l = 0, r = 1e12;     for (int i = 0; i < 100; i++) {       double mid = (l + r) / 2;       if (check(mid))         r = mid;       else         l = mid;     }     printf( %.10f n , l);     return 0;   }
#include <iostream>   #include <vector>   #include <algorithm>      using namespace std;      #define int long long      void solve() {       int n;       vector<long long> vect;       cin >> n;       for (int i = 0; i < n; i++) {           long long x;           cin >> x;           vect.push_back(x);       }       sort(vect.begin(), vect.end());       long long res = 0;       long long now = 0;       for (int i = n - 2; i >= 0; i--) {           res -= now - (n - i - 2) * vect[i];           now += vect[i + 1];       }       cout << res <<   n ;   }      signed main()   {       ios_base::sync_with_stdio(false);       cin.tie(nullptr);       int t;       cin >> t;       for (int i = 0; i < t; i++)           solve();       return 0;   }
// Problem : B. Tree Array   // Contest : Codeforces - Codeforces Round #728 (Div. 1)   // URL : https://codeforces.com/contest/1540/problem/B   // Memory Limit : 256 MB   // Time Limit : 2000 ms   // Powered by CP Editor (https://github.com/cpeditor/cpeditor)      #include <bits/stdc++.h>      using namespace std;      int N;   long long pas[205][205];   const long long MOD = 1e9+7;   long long cache[205][205];   vector<int> graph[205];   int par[205];   bool vis[205];      long long add(long long a, long long b){    return (a + b) % MOD;   }      long long mult(long long a, long long b){    return a * b % MOD;   }      long long qikpow(long long b, long long e){    if(!e){     return 1;    }    long long ret = qikpow(b, e / 2);    ret = mult(ret, ret);    if(e & 1){     ret = mult(ret, b);    }    return ret;   }      long long sub(long long a, long long b){    return ((a - b) % MOD + MOD ) % MOD;   }      long long divd(long long a, long long b){    return mult(a, qikpow(b, MOD - 2));   }      void dfs1(int n){    for(int e : graph[n]){     if(e != par[n]){      par[e] = n;      dfs1(e);     }    }   }      int dfs2(int n, int p){    int sz = 1;    for(int e : graph[n]){     if(!vis[e] && p != e){      sz += dfs2(e, n);     }    }    return sz;   }      int main(){    ios::sync_with_stdio(0);    cin.tie(0);    cout.tie(0);    cin >> N;    for(int i = 0; i <= N; i++){     pas[i][0] = 1;     for(int j = 1; j <= i; j++){      pas[i][j] = add(pas[i-1][j], pas[i-1][j-1]);     }    }     for(int i = 1; i < N; i++){     int a, b;     cin >> a >> b;     graph[a].emplace_back(b);     graph[b].emplace_back(a);    }    long long ans = 0;    for(int n = 1; n <= N; n++){     fill(par, par+1+N, 0);     dfs1(n);     vis[n] = 1;     for(int k = n+1; k <= N; k++){      int cur = k, len = 0;      while(cur != n){       vis[cur] = 1;       len++;       cur = par[cur];      }      cur = k;      for(int t = len; t; t--){       int s = dfs2(cur, 0);       //cout << s <<   n ;       long long tot = divd(s, N);       if(t == len){        ans = add(ans, tot);       }       else{        /*        long long p = 1;//qikpow(divd(1, 2), len);             cout << p <<     << pas[len - 1][len - t] <<   n ;        p = mult(p, divd(pas[len - 1][len - t], pas[len][len-t]));        cout << n <<     << k <<     << cur <<   n ;        cout << p <<     << tot <<   n ;        ans = add(ans, mult(p, tot));        */        //cout << n <<     << k <<     << cur <<   n ;        //cout << tot <<   n ;        if(!cache[len][t]){         for(int c = 0; c < t; c++){          cache[len][t] = add(cache[len][t], mult(pas[c+len-t-1][len-t-1], qikpow(divd(1, 2), c+len-t)));          //cout << mult(mult(pas[c+len-t-1][len-t-1], qikpow(divd(1, 2), c+len-t)), tot) <<   n ;         }          }        ans = add(mult(tot, cache[len][t]), ans);               }       cur = par[cur];      }      cur = k;      while(cur != n){       vis[cur] = 0;       cur = par[cur];      }     }     vis[n] = 0;    }    cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int64_t ans, n, k, m, r[100005];   char s[100005], t[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int64_t tt;     cin >> tt;     while (tt--) {       cin >> n;       cin >> s;       cin >> t;       vector<int> ans;       m = n - 1;       int i = 0, j = n - 1;       while (i < j) {         r[m--] = i;         i++;         r[m--] = j;         j--;       }       if (i == j) r[m] = i;       m = 0;       for (int i = n - 1; i >= 0; i--) {         if ((s[r[i]] -  0  + m) % 2 == t[i] -  0 ) ans.push_back(1);         ans.push_back(i + 1);         m++;       }       cout << (int)ans.size() <<    ;       for (auto i : ans) cout << i <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> a;   int k, t, n, mx;   string s;   int main() {     cin >> n >> k;     cin >> s;     for (int i = 0; i < s.size(); i++)       if (s[i] ==  . ) a.push_back(i);     for (int i = 0; i < a.size() - 1; i++) mx = max(mx, a[i + 1] - a[i]);     if (mx > k)       cout <<  NO ;     else       cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   int w;   long long n, k;   pair<long long, long long> o = {0, 0};   pair<long long, long long> csop(long long kezd, long long kim) {     long long sum = 0, kov = kezd + k;     if (kezd <= kim && kim <= kov) {       kov++;     }     sum = (kov - kezd) * (kov - kezd - 1) / 2;     if (log(k) + log(kezd) < 42.0) {       sum += kezd * (kov - kezd);     } else {       sum = 2e18;     }     if (kezd <= kim && kim < kov) {       sum -= kim;     }     return {sum, kov};   }   pair<long long, long long> calc(long long ert) {     if (ert <= k * (k + 1) / 2) {       return {1, k * (k + 1) / 2};     }     long long kis = ert / k - k / 2;     auto s = calc(kis);     long long fi = s.first, se = s.second;     long long s2 = kis, kor = 0, ert2 = 0;     s2 -= (fi - 1) * (k + 1), kor += fi - 1, ert2 = (fi - 1) * (k + 1);     long long ss = (s2 + k - 2) / k;     kor += ss, ert2 += ss * k;     ert2++, kor++;     if (ert2 >= se) {       ert2++;     }     auto cs = csop(ert2, se);     if (cs.first < ert) {       ert2 = cs.second, kor++;       cs = csop(ert2, se);     }     return {kor, cs.first};   }   int main() {     ios_base::sync_with_stdio(false);     cin >> w;     while (w--) {       cin >> n >> k;       if (n <= k) {         cout << n <<   n ;         continue;       }       if (k == 2 && n <= 5) {         cout << n <<   n ;         continue;       }       auto s = calc(n);       if (s.second == n) {         cout << s.first * (k + 1) <<   n ;       } else {         long long fi = s.first, ans = fi * (k + 1);         n -= fi * (k + 1) - 1;         ans += (k + 1) * (n / k) + n % k;         if (n % k == 0) {           ans--;         }         cout << ans <<   n ;       }     }     return 0;   }