func_code_string: #include <bits/stdc++.h>   using namespace std;   char buffer[1048576];   int main() {     scanf( %s , buffer);     string dat(buffer);     int n = dat.length();     int Q;     scanf( %d , &Q);     int lgstep = 1;     while ((1 << lgstep) <= n) lgstep++;     while (Q--) {       int k, d;       scanf( %d%d , &k, &d);       vector<int> invpi(k);       {         int lastval = 0;         int grp = 0;         for (int i = 1; i < k; i++) {           lastval += d;           if (lastval >= k) {             grp++;             lastval = grp;           }           invpi[i] = lastval;         }       }       vector<int> from(k);       vector<vector<int>> logfrom(lgstep, vector<int>(k));       for (int i = 0; i < k; i++) {         from[i] = invpi[i] + 1;         logfrom[0][i] = from[i];       }       for (int i = 1; i < lgstep; i++) {         for (int j = 0; j < k; j++) {           int p = logfrom[i - 1][j];           int p2 = (p != k) ? logfrom[i - 1][p] : (k);           logfrom[i][j] = p2;         }       }       string answer(n, 0);       for (int i = 0; i < n; i++) {         int base = min(i, n - k);         int fpos = i - base;         int tracepos = fpos;         int steps = 0;         {           int remain = base + 1;           for (int l = lgstep - 1; l >= 0; l--) {             if (remain >= (1 << l)) {               if (logfrom[l][tracepos] != k) {                 remain -= (1 << l);                 steps += (1 << l);                 tracepos = logfrom[l][tracepos];               }             }           }           if (remain) {             tracepos = logfrom[0][tracepos];             remain--;             steps++;           }         }         answer[i] = dat[base + tracepos - steps];       }       dat = move(answer);       puts(dat.c_str());     }     return 0;   }   