malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5, mod = 1e9 + 7;   int grundy[2000][2000], dr[50], dc[50];   int x, y, n, d;   bool valid(int x, int y) { return x * x + y * y <= d * d; }   int mex(set<int> &st) {     int ret = 0;     while (st.count(ret)) ret++;     return ret;   }   int solve(int x, int y) {     if (grundy[x][y] != -1) return grundy[x][y];     set<int> st;     for (int i = 0; i < n; i++) {       int nx, ny;       nx = x + dr[i];       ny = y + dc[i];       if (valid(nx - 200, ny - 200)) {         st.insert(solve(nx, ny));       }     }     return grundy[x][y] = mex(st);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(grundy, -1, sizeof grundy);     cin >> x >> y >> n >> d;     for (int i = 0; i < n; i++) {       cin >> dr[i] >> dc[i];     }     if (solve(x + 200, y + 200))       cout <<  Anton ;     else       cout <<  Dasha ;     return 0;   }
#include <bits/stdc++.h>   long long int MAX(long long int a, long long int b) {     if (a > b)       return a;     else       return b;   }   using namespace std;   int main() {     string S, SS;     cin >> S >> SS;     int PR = 0, DIF = 0, l = S.length();     for (int x = 0; x < l; x++)       if (S[x] != SS[x]) DIF++;     if (DIF & 1)       printf( impossible n );     else {       DIF /= 2;       bool SEC = false;       for (int i = 0; i < l; i++) {         if (S[i] == SS[i])           printf( 1 );         else {           if (PR == DIF) SEC = true;           if (!SEC) {             if (S[i] ==  1 )               printf( 0 );             else               printf( 1 );           } else {             if (SS[i] ==  1 )               printf( 0 );             else               printf( 1 );           }           PR++;         }       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int b, ans, r;   bool x;   int main() {     cin >> b;     while (!x) {       b++;       ans++;       r = abs(b);       if ((r - 8) % 10 == 0 && r != 0) x = 1;       r /= 10;       if ((r - 8) % 10 == 0 && r != 0) x = 1;       r /= 10;       if ((r - 8) % 10 == 0 && r != 0) x = 1;       r /= 10;       if ((r - 8) % 10 == 0 && r != 0) x = 1;       r /= 10;       if ((r - 8) % 10 == 0 && r != 0) x = 1;       r /= 10;       if ((r - 8) % 10 == 0 && r != 0) x = 1;       r /= 10;       if ((r - 8) % 10 == 0 && r != 0) x = 1;       r /= 10;       if ((r - 8) % 10 == 0 && r != 0) x = 1;       r /= 10;       if ((r - 8) % 10 == 0 && r != 0) x = 1;       r /= 10;       if ((r - 8) % 10 == 0 && r != 0) x = 1;       r /= 10;       if ((r - 8) % 10 == 0 && r != 0) x = 1;       r /= 10;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long oo = (long long)1e4;   long long n, k;   vector<pair<int, int> > l, r;   int length(int x) { return x < 10 ? 1 : length(x / 10) + 1; }   pair<int, int> checkWavy(int x) {     if (x < 10) return make_pair(1, 0);     int digits[8] = {x % 10, x / 10 % 10}, len = 2, sign = digits[1] > digits[0];     if (digits[1] == digits[0]) return make_pair(0, 0);     x /= 100;     while (x) {       digits[len] = x % 10;       x /= 10;       if (digits[len] == digits[len - 1]) return make_pair(0, 0);       int newSign = digits[len] > digits[len - 1];       if (newSign == sign) return make_pair(0, 0);       sign = newSign;       len++;     }     if (len < 6) return make_pair(1, 0);     if (len == 7) return make_pair(1, 1);     return make_pair(1, sign);   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> k;     for (int i = 1; i < int(1e7); i++) {       pair<int, int> u = checkWavy(i);       if (!u.first) continue;       if (i % n == 0)         if (!--k) {           cout << i << endl;           return 0;         }       l.push_back(make_pair(i, i % n));       if (u.second) r.push_back(make_pair(i % n, i));     }     sort(l.begin(), l.end());     sort(r.begin(), r.end());     for (int i = 0; i < int(l.size()); i++) {       if ((n - 1LL * l[i].second * int(1e7) % n) % n > int(1e7)) continue;       int mod = (n - 1LL * l[i].second * int(1e7) % n) % n;       int x = l[i].first, lastDigit = x % 10;       int from = lower_bound(r.begin(), r.end(), make_pair(mod, 0)) - r.begin();       int to = lower_bound(r.begin(), r.end(), make_pair(mod + 1, 0)) - r.begin();       if (from == to) continue;       for (int digit = 0; digit < 10 && from < to; digit++) {         int bound = lower_bound(r.begin() + from, r.begin() + to,                                 make_pair(mod, (digit + 1) * int(1e6))) -                     r.begin();         if (digit < lastDigit) {           if (x < 10 || x / 10 % 10 < lastDigit) {             int low = (digit * 10 + digit + 1) * int(1e5);             int idLow = lower_bound(r.begin() + from, r.begin() + bound,                                     make_pair(mod, low)) -                         r.begin();             if (bound - idLow >= k) {               cout << x;               for (int q = length(r[from + k - 1].second); q < 7; q++) cout << 0;               cout << r[idLow + k - 1].second << endl;               return 0;             } else               k -= bound - idLow;           }         }         if (digit > lastDigit) {           if (x < 10 || x / 10 % 10 > lastDigit) {             int high = (digit * 10 + digit) * int(1e5);             int idHigh = lower_bound(r.begin() + from, r.begin() + bound,                                      make_pair(mod, high)) -                          r.begin();             if (idHigh - from >= k) {               cout << x;               for (int q = length(r[from + k - 1].second); q < 7; q++) cout << 0;               cout << r[from + k - 1].second << endl;               return 0;             } else               k -= idHigh - from;           }         }         from = bound;       }     }     cout << -1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 505;   int a[N];   int b[N];   int dp[N];   int pv[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     int m;     cin >> m;     for (int i = 1; i <= m; i++) {       cin >> b[i];     }     int k;     for (int i = 1; i <= n; i++) {       k = 0;       for (int j = 1; j <= m; j++) {         if (a[i] == b[j]) {           if (dp[j] < dp[k] + 1) {             dp[j] = dp[k] + 1;             pv[j] = k;           }         } else if (b[j] < a[i]) {           if (dp[j] > dp[k]) {             k = j;           }         }       }     }     int d = 0;     for (int i = 1; i <= m; i++) {       if (dp[i] > dp[d]) d = i;     }     vector<int> ans;     while (d != 0) {       ans.push_back(b[d]);       d = pv[d];     }     reverse(ans.begin(), ans.end());     cout << ans.size() <<   n ;     for (auto x : ans) cout << x <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   int main() {     int t;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       int s = abs(a - b);       int ans = s / 5;       s %= 5;       if (s > 2)         ans += 2;       else if (s != 0)         ans++;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int NN = (1 << 15);   int pre[NN], suf[NN];   map<string, int> mp;   int main() {     int n;     cin >> n;     for (int i = 1, x; i <= n; i++) {       cin >> x;       pre[i] = x >> 15;       suf[i] = x & (NN - 1);     }     for (int i = 0; i < NN; i++) {       string tmp;       for (int j = 2; j <= n; j++) {         tmp.push_back(__builtin_popcount(i ^ pre[j]) -                       __builtin_popcount(i ^ pre[1]));       }       if (!mp.count(tmp)) mp[tmp] = i;     }     for (int i = 0; i < NN; i++) {       string tmp;       for (int j = 2; j <= n; j++) {         tmp.push_back(__builtin_popcount(i ^ suf[1]) -                       __builtin_popcount(i ^ suf[j]));       }       if (mp.count(tmp)) {         cout << (mp[tmp] << 15) + i << endl;         return 0;       }     }     puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int m, n;   int mat[105][105];   int main() {     cin >> m >> n;     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         cin >> mat[i][j];       }     }     if (m % 2 != 0) {       cout << m << endl;     } else {       int aux = m;       bool flag = true;       int cont = 0;       bool flag2 = true;       while (flag) {         aux = aux / 2;         if (aux == 1) {           for (int j = 0; j < n; j++) {             if (mat[0][j] != mat[1][j]) {               flag2 = false;             }           }           if (flag2) {             cont++;           }           flag = false;           break;         }         for (int i = 0; i < aux; i++) {           for (int j = 0; j < n; j++) {             if (mat[aux - i - 1][j] != mat[aux + i][j]) {               flag = false;             }           }         }         if (flag) cont++;         if (aux % 2 != 0) break;       }       for (int i = 0; i < cont; i++) {         m = m / 2;       }       cout << m << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m;     cin >> n >> m;     double num;     num = (double)m / n;     if (n == m) {       cout <<  0 ;     } else {       long long int x = num, counter1 = 0, counter2 = 0;       if (ceil(num) == num) {         if (x % 2 == 0 || x % 3 == 0) {           while (x % 2 == 0) {             x = x / 2;             counter1++;           }           while (x % 3 == 0) {             x = x / 3;             counter2++;           }           if (pow(2, counter1) * pow(3, counter2) == num)             cout << counter1 + counter2;           else             cout <<  -1 ;         } else           cout <<  -1 ;       } else         cout <<  -1 ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long calc(int n, int d, long long m, int l) {     for (long long i = 0; i < n; i++) {       long long high = i * m + l;       long long x = high % d;       if (d < (x + m - l)) {         return high + (d - x);       }     }     long long high = (n - 1) * m + l;     long long x = high % d;     return high + (d - x);   }   int main() {     int n, d, m, l;     scanf( %d %d %d %d , &n, &d, &m, &l);     cout << calc(n, d, m, l) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     if (a.second == b.second) return (a.first < b.first);     return (a.second < b.second);   }   int main(void) {     long long a, b;     cin >> a >> b;     string str = to_string(b);     reverse(str.begin(), str.end());     long long d = atoi(str.c_str());     cout << d + a;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   void finish(int x) {     printf( ! %d n , x);     fflush(stdout);     exit(0);   }   int query(int x) {     int a, b, mult = 1;     if (x > n / 2) {       x -= n / 2;       mult = -1;     }     printf( ? %d n , x);     fflush(stdout);     scanf( %d , &a);     printf( ? %d n , x + n / 2);     fflush(stdout);     scanf( %d , &b);     if (a == b) finish(x);     return mult * (b - a);   }   int main() {     scanf( %d , &n);     if (n % 4 != 0) finish(-1);     int offset = 0, l = 1, r = n / 2;     int dif = query(1);     if (dif < 0) offset += n / 2;     while (l < r) {       int m = (l + r) / 2;       if (query(m + offset) > 0)         l = m + 1;       else         r = m - 1;     }     if (query(l) != 0) finish(-1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500005;   int n, k, i, t, j, m;   char c[N];   long long ans, s;   struct str {     int l, r;   } p[N], a[N];   bool cmp(str a, str b) { return a.r - a.l > b.r - b.l; }   bool cmp2(str a, str b) { return a.r < b.r; }   int main() {     scanf( %d , &n);     scanf( %s , c + 1);     for (i = 1; i <= n; ++i)       if (c[i] ==  1 ) {         for (j = i; c[j] ==  1 ; ++j)           ;         p[++k] = (str){i, j - 1};         i = j;       }     sort(p + 1, p + 1 + k, cmp);     for (i = 1; i <= n; ++i) {       int las = 0;       for (j = 1; j <= k; ++j)         if (p[j].r - p[j].l + 1 >= i)           a[j] = p[j];         else           break;       m = j - 1;       sort(a + 1, a + 1 + m, cmp2);       s = las = 0;       for (j = 1; j <= m; ++j) {         if (las != 0)           s += 1ll * (i + a[j].l + i - 1 - las) * (a[j].l - las) / 2;         else           s += 1ll * (a[j].l + i - 2) * (a[j].l + i - 1) / 2;         las = a[j].r - i + 2;         s += 1ll * (a[j].r - a[j].l + 2 - i) * (i - 1);       }       if (m != 0)         s += 1ll * (i + n - las + 1) * (n - a[m].r) / 2;       else         s = 1ll * n * (n + 1) / 2;       ans += 1ll * n * (n + 1) / 2 - s;     }     cout << ans;   }
#include <bits/stdc++.h>   const int MAX_MEM = 1e8;   int mpos = 0;   char mem[MAX_MEM];   inline void *operator new(size_t n) {     assert((mpos += n) <= MAX_MEM);     return (void *)(mem + mpos - n);   }   inline void operator delete(void *) noexcept {}   using namespace std;   struct Ex {     int s, d, c, i;   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     vector<Ex> data(m + 1);     unordered_map<int, int> table(m + 1);     for (int i = 1; i <= m; i++) {       int s, d, c;       cin >> s >> d >> c;       data[i] = {s, d, c, i};       table[d] = i;     }     vector<int> answer(n + 1);     vector<int> cnt(m + 1);     for (int i = 1; i <= n; i++) {       if (table[i]) {         if (cnt[table[i]] == data[table[i]].c) {           answer[i] = m + 1;         } else {           cout << -1;           return 0;         }       } else {         int best_ex = -1;         int day = 1000;         for (int j = 1; j <= m; j++) {           if (data[j].d < day and cnt[data[j].i] < data[j].c and data[j].s <= i) {             best_ex = data[j].i;             day = data[j].d;           }         }         if (best_ex == -1) {           answer[i] = 0;         } else {           answer[i] = best_ex;           cnt[best_ex]++;         }       }     }     for (int i = 1; i <= n; i++) {       cout << answer[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, s1[1000005], r, s2[1000005], dp[1000005], w, mi, mid, ma;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &s1[i]);     }     for (int i = 1; i <= n; i++) {       scanf( %d , &r);       s2[r] = i;     }     for (int i = 1; i <= n; i++) {       s1[i] = s2[s1[i]];     }     w = 0;     dp[0] = 10000000;     for (int i = 1; i <= n; i++) {       if (dp[w] > s1[i]) {         dp[++w] = s1[i];       } else {         mi = 0;         ma = w;         while (mi < ma) {           mid = (mi + ma) >> 1;           if (dp[mid] < s1[i]) {             ma = mid;           } else {             mi = mid + 1;           }         }         dp[mi] = s1[i];       }     }     printf( %d n , w);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> sieve(long long n) {     long long *arr = new long long[n + 1]();     vector<long long> vect;     for (long long i = 2; i <= n; i++)       if (arr[i] == 0) {         vect.push_back(i);         for (long long j = 2 * i; j <= n; j += i) arr[j] = 1;       }     return vect;   }   long long binpow(long long a, long long b, long long m) {     a = a % m;     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   class cmp {    public:     bool operator()(pair<long long, long long> &a,                     pair<long long, long long> &b) {       if (a.second == b.second)         return a.first < b.first;       else         return a.second < b.second;     }   };   signed main() {     long long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       vector<long long> v(n);       for (long long i = 0; i < n; i++) cin >> v[i];       long long x = k;       sort(v.begin(), v.end());       long long ans = 0;       k *= 2;       long long j = n - 1;       vector<long long> vec;       while (k--) {         vec.push_back(v[j]);         j--;       }       sort(vec.begin(), vec.end());       for (long long i = 0; i < vec.size() / 2; i++) {         ans += (vec[i] / vec[i + x]);       }       for (long long i = 0; i <= j; i++) ans += v[i];       cout << ans <<   n ;       ;     }   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000,100000000000 )   const long long INF = 1000000007;   const double cp = 2 * asin(1.0);   const double eps = 1e-9;   const long long mod = 1000000007;   using namespace std;   int main() {     cin.tie(NULL);     ios_base::sync_with_stdio(false);     string s, ans;     bool ok = false;     cin >> s;     for (char q =  a ; q <=  z ; q++) {       string h;       for (int(i) = 0; (i) < (s.size() + 1); i++) {         h =   ;         for (int(j) = 0; (j) < (i); j++) h += s[j];         h += q;         if (i != s.size())           for (int(j) = (i); (j) <= (s.size() - 1); j++) h += s[j];         string t = h;         reverse((t).begin(), (t).end());         if (t == h) {           return cout << t, 0;           ans = t, ok = true;         }       }     }     if (!ok)       cout <<  NA ;     else       cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000000 + 100, logN = 23;   long long read() {     long long x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   int f[N][logN + 1];   int query(int l, int r) {     long long ans = 0;     for (int i = logN - 1; i >= 0; --i) {       if (f[l][i] < r) {         l = f[l][i];         ans += (1 << i);       }     }     l = f[l][0];     ans++;     if (l < r) return -1;     return ans;   }   int main() {     int n = read(), m = read(), mx = 0;     for (int i = 1; i <= n; ++i) {       int l = read() + 1, r = read() + 1;       f[l][0] = max(f[l][0], r);       mx = max(mx, r);     }     for (int i = 1; i <= mx; ++i) f[i][0] = max(f[i][0], max(i, f[i - 1][0]));     for (int j = 1; j < logN; ++j)       for (int i = 1; i <= mx; ++i) f[i][j] = f[f[i][j - 1]][j - 1];     while (m--) {       int l = read() + 1, r = read() + 1;       printf( %d n , query(l, r));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[100001], a[5] =  hard ;   int x[100001];   long long d[5][100001];   const long long inf = 0x3f3f3f3f3f3f3f3f;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf(  %c , &s[i]);     for (int i = 1; i <= n; i++) scanf( %d , &x[i]);     memset(d, 0x3f, sizeof(d));     for (int i = 0; i < 4; i++) d[i][0] = 0;     for (int i = 0; i < 4; i++) {       for (int j = 1; j <= n; j++) {         if (s[j] == a[i]) {           if (i >= 1)             d[i][j] = min(d[i - 1][j - 1], d[i][j - 1] + x[j]);           else             d[i][j] = d[i][j - 1] + x[j];         } else           d[i][j] = d[i][j - 1];       }     }     printf( %lld n , min({d[0][n], d[1][n], d[2][n], d[3][n]}));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long fastModPow(long long a, long long n, long long mod) {     if (mod == 1) return 0;     if (n == 1) return a % mod;     long long res = fastModPow(a, n / 2, mod);     res = res * res % mod;     if (n & 1) res = res * a % mod;     return res;   }   long long fastMaxPow(long long a, long long n, long long mx) {     if (n == 1) return min(a, mx);     long long res = fastMaxPow(a, n / 2, mx);     res = min(res * res, mx);     if (n & 1) res = min(res * a, mx);     return res;   }   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     long long mod = 1000000009;     long long m1 = fastMaxPow(2, m, 100001);     if (n >= m1) {       cout << 0;       return 0;     }     long long mult = fastModPow(2, m, mod);     long long res = 1;     for (int i = 1; i <= n; i++) {       mult--;       if (mult <= 0) mult += mod;       res = res * mult % mod;     }     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 100 * 1000 + 5;   const int lim = 1000 * 1000 * 1000;   const int inf = 1000 * 1000 * 1000 + 5;   int f[3 * maxN];   vector<pair<int, string> > a[maxN];   string t;   int ans;   void dfs(int v, int F) {     for (auto u : a[v]) {       int tmp = F;       string s = u.second;       for (int i = 0; i < s.size(); i++) {         while (tmp && (tmp == t.size() || t[tmp] != s[i])) tmp = f[tmp - 1];         if (t[tmp] == s[i]) tmp++;         if (tmp == t.size()) ans++;       }       dfs(u.first, tmp);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int par;       string s;       cin >> par >> s;       par--;       a[par].push_back(make_pair(i, s));     }     cin >> t;     int tmp = 0;     for (int i = 1; i < t.size(); i++) {       while (tmp && t[tmp] != t[i]) tmp = f[tmp - 1];       if (t[tmp] == t[i]) tmp++;       f[i] = tmp;     }     dfs(0, 0);     cout << ans << endl;     return 0;   }
//#include <bits/stdc++.h>   //using namespace std;   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC target( avx )   #pragma GCC optimize( Ofast )   #include <cstdio>      #define rep(i,_l,_r) for(signed i=(_l),_end=(_r);i<=_end;++i)   #define fep(i,_l,_r) for(signed i=(_l),_end=(_r);i>=_end;--i)   #define print(x,y) write(x),putchar(y)      template <class T> inline T read(const T sample) {       T x=0; int f=1; char s;       while((s=getchar())> 9 ||s< 0 ) if(s== - ) f=-1;       while(s>= 0 &&s<= 9 ) x=(x<<1)+(x<<3)+(s^48),s=getchar();       return x*f;   }   template <class T> inline void write(const T x) {       if(x<0) return (void) (putchar( - ),write(-x));       if(x>9) write(x/10);       putchar(x%10^48);   }   template <class T> inline T Max(const T x,const T y) {if(x>y) return x; return y;}   template <class T> inline T Min(const T x,const T y) {if(x<y) return x; return y;}      const int maxn=2e4+4;      int n,q,lg[maxn],a[maxn],st[32][18][maxn],dp[18][32][maxn],ans[maxn],f[maxn][32],tmp[32];   struct node {    int l,r,k;   } s[maxn];      void init() {    rep(i,2,n) lg[i]=lg[i>>1]+1;   }      int Query(int k,int l,int r) {    int d=lg[r-l+1];    return Max(st[k][d][l],st[k][d][r-(1<<d)+1]);   }      int main() {    n=read(9),q=read(9); init();    int lgn=lg[n]+1;    rep(i,1,n) a[i]=read(9);    rep(k,0,30) rep(i,1,n) dp[0][k][i]=Min(n,i+a[i]+k);    rep(j,1,lgn) {     rep(k,0,30) rep(i,1,n) st[k][0][i]=dp[j-1][k][i];     rep(k,0,30) rep(i,1,lgn) rep(p,1,n)      if(p+(1<<i)-1<=n)       st[k][i][p]=Max(st[k][i-1][p],st[k][i-1][p+(1<<i-1)]);      else break;     rep(k1,0,30) rep(k2,0,30) {      if(k1+k2>30) break;      rep(i,1,n) dp[j][k1+k2][i]=Max(dp[j][k1+k2][i],Query(k1,i,dp[j-1][k2][i]));     }    }    rep(i,1,q) {     s[i].l=read(9),s[i].r=read(9),s[i].k=read(9);     if(s[i].l==s[i].r) ans[i]=-1;     else rep(j,0,s[i].k) f[i][j]=s[i].l;    }    fep(j,lgn,0) {     rep(k,0,30) rep(i,1,n) st[k][0][i]=dp[j][k][i];     rep(k,0,30) rep(i,1,lgn) rep(p,1,n)      if(p+(1<<i)-1<=n)       st[k][i][p]=Max(st[k][i-1][p],st[k][i-1][p+(1<<i-1)]);      else break;     rep(i,1,q) {      if(ans[i]==-1) continue;      rep(k,0,s[i].k) tmp[k]=0;      rep(k1,0,s[i].k) rep(k2,0,s[i].k) {       if(k1+k2>s[i].k) break;       tmp[k1+k2]=Max(tmp[k1+k2],Query(k1,s[i].l,f[i][k2]));      }      if(tmp[s[i].k]<s[i].r) {       ans[i]+=(1<<j);       rep(k,0,s[i].k) f[i][k]=tmp[k];      }     }    }    rep(i,1,q) print(ans[i]+1,  n );    return 0;   }