malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 110;   int T, mod = 1e9 + 7, n, k, deep[N], timer, sz;   long long ans, fact[N], mem[N][N], vis[N][N];   vector<int> adj[N], v;   map<int, int> mp[N];   void _clear() {     ans = 0;     for (int i = 1; i <= n; i++) adj[i].clear();   }   long long po(long long x, long long os) {     if (os == 0) return 1;     long long z = po(x, os / 2);     if (os & 1) return z * z % mod * x % mod;     return z * z % mod;   }   long long modInv(long long x) { return po(x, mod - 2); }   long long c(long long n, long long r) {     return fact[n] * modInv(fact[r] * fact[n - r] % mod) % mod;   }   void dfs(int u, int v) {     deep[u] = deep[v] + 1;     mp[u][deep[u]]++;     for (auto &x : adj[u])       if (x != v) {         dfs(x, u);         for (auto &p : mp[x]) mp[u][p.first] += p.second;       }   }   long long dp(int i, int k) {     if (k == 0) return 1;     if (i == sz) return 0;     long long &ret = mem[i][k];     if (vis[i][k] == timer) return ret;     vis[i][k] = timer;     return ret = (dp(i + 1, k) + dp(i + 1, k - 1) * v[i] % mod) % mod;   }   long long calc(int p) {     deep[p] = 0;     for (int i = 1; i <= n; i++) mp[i].clear();     dfs(p, p);     long long ret = 0;     for (int i = 2; i <= n; i++) {       int num = 0;       v.clear();       for (auto &x : adj[p])         if (mp[x].find(i) != mp[x].end()) {           num++;           v.push_back(mp[x][i]);         }       if (num < k) continue;       timer++;       sz = (int)(v.size());       ret = (ret + dp(0, k)) % mod;     }     return ret;   }   int main() {     fact[0] = 1;     for (int i = 1; i < N; i++) fact[i] = fact[i - 1] * i % mod;     scanf( %d , &T);     while (T--) {       scanf( %d%d , &n, &k);       _clear();       for (int i = 1; i <= n - 1; i++) {         int a, b;         scanf( %d%d , &a, &b);         adj[a].push_back(b);         adj[b].push_back(a);       }       if (k == 2) {         printf( %lld n , c(n, 2));         continue;       }       for (int i = 1; i <= n; i++) ans = (ans + calc(i)) % mod;       printf( %lld n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   int read() {     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     int x = 0;     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x;   }   const int maxn = (1 << 21) + 3;   const int INF = 0x3f3f3f3f;   struct segtree {     int n;     int tag[maxn], mmin[maxn];     int ul, ur, uv;     void update(int o, int l, int r) {       if (ul <= l && ur >= r) {         tag[o] = max(tag[o], uv);         mmin[o] = max(mmin[o], uv);         return;       }       int mid = (l + r) / 2;       if (ul <= mid) update(o * 2, l, mid);       if (ur > mid) update(o * 2 + 1, mid + 1, r);       mmin[o] = max(min(mmin[o * 2], mmin[o * 2 + 1]), tag[o]);     }     void modify(int l, int r, int v) {       if (l > r) return;       ul = l, ur = r, uv = v;       update(1, 1, n);     }     int p, x;     int query2(int o, int l, int r) {       if (max(tag[o], mmin[o]) >= x) return n + 1;       if (l == r) return l;       int mid = (l + r) / 2;       if (mmin[o * 2] < x)         return query2(o * 2, l, mid);       else         return query2(o * 2 + 1, mid + 1, r);     }     int query(int o, int l, int r) {       if (max(tag[o], mmin[o]) >= x) return n + 1;       if (l == r) return l;       int mid = (l + r) / 2;       if (p > mid)         return query(o * 2 + 1, mid + 1, r);       else {         int ans = query(o * 2, l, mid);         if (ans != n + 1)           return ans;         else           return query2(o * 2 + 1, mid + 1, r);       }     }     int query(int p, int x) {       if (p > n) return n + 1;       this->p = p, this->x = x;       return query(1, 1, n);     }   } t;   struct edge {     int l, r;     bool operator<(const edge& rhs) const { return r < rhs.r; }   } e[maxn];   struct query {     int id, x, y;     bool operator<(const query& rhs) const { return y < rhs.y; }   } q[maxn];   int ans[maxn];   void write(int x) {     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   void writeln(int x) {     write(x);     putchar(  n );   }   int main() {     int n = t.n = read(), k = read();     for (int i = 1; i <= k; i++) e[i].l = read(), e[i].r = read();     sort(e + 1, e + k + 1);     int m = read();     for (int i = 1; i <= m; i++) q[i].id = i, q[i].x = read(), q[i].y = read();     sort(q + 1, q + m + 1);     int now = 1;     for (int i = 1; i <= m; i++) {       while (now <= k && e[now].r <= q[i].y) {         t.modify(e[now].l + 1, e[now].r, e[now].l);         now++;       }       ans[q[i].id] = t.query(q[i].x + 1, q[i].x) - 1;     }     for (int i = 1; i <= m; i++) writeln(ans[i]);   }
#include <bits/stdc++.h>   const int MOD = 1000000007;   const int SIZE_N = 2000 + 10;   int n;   int ary[SIZE_N];   int vis[SIZE_N];   int fac[SIZE_N];   int madd(long long a, long long b) { return (a + b) % MOD; }   int mmul(long long a, long long b) { return (a * b) % MOD; }   int dp[SIZE_N][SIZE_N], v[SIZE_N][SIZE_N];   int f(int a, int b) {     if (v[a][b] == 1) return dp[a][b];     v[a][b] = 1;     if (a == 0) return dp[a][b] = fac[b];     if (a == 1) return dp[a][b] = mmul(b, fac[b]);     return dp[a][b] = madd(mmul(b, f(a - 1, b)), mmul(a - 1, f(a - 2, b + 1)));   }   int main(void) {     fac[0] = 1;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , ary + i);       vis[ary[i]] = 1;       fac[i] = mmul(fac[i - 1], i);     }     int a = 0, b = 0;     for (int i = 1; i <= n; ++i) {       if (vis[i] == 1) continue;       if (ary[i] == -1)         ++a;       else         ++b;     }     int ans = 0;     ans = f(a, b);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   const int M = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int s, x1, x2, t1, t2, p, d;     cin >> s >> x1 >> x2;     cin >> t1 >> t2;     cin >> p >> d;     int ans = t2 * abs(x1 - x2);     if (x1 < x2) {       if (d == -1)         ans = min(ans, (p + x2) * t1);       else if (p <= x1)         ans = min(ans, (x2 - p) * t1);       else         ans = min(ans, (s + s - p + x2) * t1);     } else {       if (d == 1)         ans = min(ans, (s + s - p - x2) * t1);       else if (p >= x1)         ans = min(ans, (p - x2) * t1);       else         ans = min(ans, (s + p + s - x2) * t1);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while ((t--)) {       int n;       cin >> n;       int arr[n];       int diff[n - 1];       for (int i = 0; i < n; i++) {         cin >> arr[i];       }       int ctr = 0;       int min = arr[n - 1];       for (int i = n - 2; i >= 0; i--) {         if (min >= arr[i]) {           min = arr[i];         } else {           ctr++;         }       }       cout << ctr <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX = 1e9;   vector<long long> lucky_nums;   void generate_lucky(long long n) {     if (n > MAX) return;     long long n1 = 10 * n + 4;     lucky_nums.push_back(n1);     generate_lucky(n1);     long long n2 = 10 * n + 7;     lucky_nums.push_back(n2);     generate_lucky(n2);   }   void solve() {     generate_lucky(0);     sort(lucky_nums.begin(), lucky_nums.end());     long long l, r;     cin >> l >> r;     int i =         lower_bound(lucky_nums.begin(), lucky_nums.end(), l) - lucky_nums.begin();     long long prev = l, ans = 0;     while (lucky_nums[i] < r) {       ans += (lucky_nums[i] - prev + 1) * lucky_nums[i];       prev = lucky_nums[i] + 1;       i++;     }     ans += (r - prev + 1) * lucky_nums[i];     cout << ans << endl;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500005;   int n, k;   char a[N], b[N];   int main() {     scanf( %d%d%s%s , &n, &k, a, b);     long long cur = 1, ans = 0;     if (k == 1) {       cout << n << endl;       return 0;     }     for (int i = 0; i < n; i++) {       cur *= 2;       if (a[i] !=  a ) --cur;       if (b[i] !=  b ) --cur;       cur = min(cur, k * 1ll);       ans += cur;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = (1 << 30) - 1;   const long long oo = (1ll << 62) - 1;   const long double PI = 3.1415926535898;   const int N = 1000000 + 5;   int n, m;   vector<int> a[N], e[N];   int num[N], low[N], vt[N], dd[N];   int Time = 0, tpltm = 0;   stack<int> s;   vector<int> res1, res2;   void minimize(int &a, int b) {     if (a > b) a = b;   }   void dfs(int u) {     num[u] = low[u] = ++Time;     s.push(u);     for (int v : a[u]) {       if (num[v] == -2) continue;       if (num[v] > 0) {         minimize(low[u], num[v]);       } else {         dfs(v);         minimize(low[u], low[v]);       }     }     if (low[u] >= num[u]) {       tpltm += 1;       int v;       do {         v = s.top();         s.pop();         vt[v] = tpltm;         num[v] = -2;       } while (v != u);     }   }   void solve() {     cin >> n >> m;     for (int i = 1; i <= n; i++) a[i].clear();     for (int i = 1; i <= m; i++) {       int u, v;       cin >> u >> v;       if (u == v) continue;       a[u].push_back(v);     }     Time = 0;     tpltm = 0;     while (s.size()) s.pop();     for (int i = 1; i <= n; i++) num[i] = 0;     for (int i = 1; i <= n; i++) {       if (num[i]) continue;       dfs(i);     }     if (tpltm <= 1) {       cout <<  No  <<   n ;       return;     }     for (int i = 1; i <= tpltm; i++) e[i].clear();     for (int u = 1; u <= n; u++) {       for (int v : a[u]) {         if (vt[u] == vt[v]) continue;         e[vt[u]].push_back(vt[v]);       }     }     int gt = INF, dinh = 0;     for (int i = 1; i <= tpltm; i++) {       if (e[i].size() < gt) {         gt = e[i].size();         dinh = i;       }     }     res1.clear();     res2.clear();     for (int i = 1; i <= n; i++) {       if (vt[i] == dinh) {         res1.push_back(i);       } else         res2.push_back(i);     }     if (res1.size() == 0 || res2.size() == 0) {       cout <<  No  <<   n ;       return;     }     cout <<  Yes  <<   n ;     cout << res1.size() <<     << res2.size() <<   n ;     for (int i = 0; i < res1.size(); i++) cout << res1[i] <<    ;     cout <<   n ;     for (int i = 0; i < res2.size(); i++) cout << res2[i] <<    ;     cout <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     for (int i = 1; i <= t; i++) solve();   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 505;   long long l1[MAX], l2[MAX], r1[MAX], r2[MAX], a1[MAX], a2[MAX];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int q;     cin >> q;     for (int i = 0; i < q; ++i) {       cin >> l1[i] >> r1[i] >> l2[i] >> r2[i];     }     for (int i = 0; i < q; ++i) {       a1[i] = l1[i], a2[i] = l2[i];       while (a1[i] == a2[i] && a2[i] <= r2[i]) {         a2[i]++;       }       cout << a1[i] <<     << a2[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const int M = 1000000000;   const int INF = 1e18;   int a[N], b[N], s1[N], s2[N];   int n, m, k, d, top1, top2, ansr, ansl, sum[N], pos[N], t[N], mn[N];   map<int, int> mp;   void reset(int x) {     mn[x] = INF;     for (int i = (x - 1) * m + 1; i <= min(n, x * m); i++)       mn[x] = min(mn[x], t[i] + sum[x]);   }   inline void add(int l, int r, int c) {     for (int i = l; i <= min(r, pos[l] * m); i++) t[i] += c;     reset(pos[l]);     if (pos[l] != pos[r]) {       for (int i = (pos[r] - 1) * m + 1; i <= min(n, r); i++) t[i] += c;       reset(pos[r]);     }     for (int i = pos[l] + 1; i <= pos[r] - 1; i++) sum[i] += c, mn[i] += c;   }   inline int query(int l, int r, int c) {     for (int i = r; i >= max((pos[r] - 1) * m + 1, l); i--)       if (t[i] + sum[pos[i]] <= c) {         return i;       }     for (int i = pos[r] - 1; i >= pos[l] + 1; i--)       if (mn[i] <= c)         for (int j = i * m; j >= (i - 1) * m + 1; j--)           if (t[j] + sum[pos[j]] <= c) {             return j;           }     if (pos[l] != pos[r]) {       for (int i = pos[l] * m; i >= l; i--) {         if (t[i] + sum[pos[i]] <= c) return i;       }     }   }   inline void sol(int L, int R) {     if (L == R) return;     mp.clear();     int r = R + 1;     top1 = top2 = 0;     s1[top1] = s2[top2] = R + 1;     for (int i = 0; i <= pos[n]; i++) sum[i] = 0;     for (int i = R; i >= L; i--) {       if (mp.count(a[i])) r = min(r, mp[a[i]]);       while (top1 && a[i] > a[s1[top1]]) {         add(s1[top1], s1[top1 - 1] - 1, -a[s1[top1]]);         top1--;       }       s1[++top1] = i;       add(s1[top1], s1[top1 - 1] - 1, a[s1[top1]]);       while (top2 && a[i] < a[s2[top2]]) {         add(s2[top2], s2[top2 - 1] - 1, a[s2[top2]]);         top2--;       }       s2[++top2] = i;       add(s2[top2], s2[top2 - 1] - 1, -a[s2[top2]]);       int rr = query(i, r - 1, k - i);       if (rr - i > ansr - ansl || (rr - i == ansr - ansl && i < ansl))         ansl = i, ansr = rr;       mp[a[i]] = i;     }     return;   }   int main() {     scanf( %d%d%d , &n, &k, &d);     if (d == 0) {       for (int i = 1; i <= n; i++) scanf( %d , &a[i]);       int ansl = 1;       int ansr = 1;       int lst = 1;       for (int i = 2; i <= n; i++) {         if (a[i] != a[lst]) {           if (i - 1 - lst > ansr - ansl) {             ansl = lst;             ansr = i - 1;           }           lst = i;         }       }       printf( %d %d n , ansl, ansr);       return 0;     }     ansl = n + 1;     ansr = 0;     m = sqrt(n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       b[i] = (a[i] += M) % d;       a[i] = (a[i]) / d + 1;       pos[i] = (i - 1) / m + 1;       t[i] = -i;     }     for (int i = 1, j; i <= n; i = j) {       for (j = i + 1; j <= n; j++) {         if (b[i] != b[j]) break;       }       sol(i, j - 1);     }     printf( %d %d n , ansl, ansr);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, p[200005];   int pn;   int main() {     scanf( %I64d , &n);     n *= 2;     for (int k = 0; k < 60; ++k) {       long long a = (1LL << (k + 1)) - 3;       long long l = 0, r = 2000000000;       if (a > 1) r = min(r, n / a + 1);       while (r - l > 1) {         long long x = (r + l) / 2;         if (x * x + a * x <= n)           l = x;         else           r = x;       }       if (l % 2 == 1 && l * l + a * l == n) p[pn++] = (l << k);     }     if (pn == 0) {       puts( -1 );       exit(0);     }     sort(p, p + pn);     for (int i = 0; i < pn; ++i) printf( %I64d n , p[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[200010], t[200010];   string ans;   void solve() {     int n = strlen(s), x = 0;     for (int i = 0; i < n; i++) {       if (i) ans +=  + ;       if (i < n - 1 && rand() % 2 == 0) {         ans += (s[i]), ans += s[++i];         x += 10 * (s[i - 1] -  0 ) + s[i] -  0 ;       } else {         ans += (s[i]);         x += s[i] -  0 ;       }     }     ans +=   n ;     sprintf(s,  %d , x);   }   int main() {     srand(time(0));     scanf( %s%s , s, t);     while (1) {       strcpy(s, t);       ans =   ;       solve();       solve();       solve();       if (strlen(s) == 1) return cout << ans, 0;     }   }
#include <bits/stdc++.h>   using namespace std;   int p[1001][1001], row[1001], col[1001];   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (int r = 1; r <= n; ++r) row[r] = r;     for (int c = 1; c <= m; ++c) col[c] = c;     for (int r = 1; r <= n; ++r)       for (int c = 1; c <= m; ++c) scanf( %d , &p[r][c]);     while (k--) {       char s[2];       int x, y;       scanf( %s%d%d , s, &x, &y);       switch (s[0]) {         case  r :           swap(row[x], row[y]);           break;         case  c :           swap(col[x], col[y]);           break;         case  g :           printf( %d n , p[row[x]][col[y]]);           break;         default:           break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool ok = false, a[5][5];   int u[5];   string p, maxs;   int pol(char s) {     if (s ==  A ) return 1;     if (s ==  B ) return 2;     if (s ==  C ) return 3;   }   string pol2(int s) {     if (s == 1) return  A ;     if (s == 2) return  B ;     if (s == 3) return  C ;   }   void dfs(int v) {     if (ok) return;     u[v] = 1;     for (int i = 1; i <= 3; i++)       if (a[v][i] && u[i] == 0)         dfs(i);       else if (a[v][i] && u[i] == 1)         ok = true;     u[v] = 2;     p = p + pol2(v);   }   int main() {     string s;     for (int i = 1; i <= 3; i++) {       cin >> s;       if (s[1] ==  > )         a[pol(s[0])][pol(s[2])] = 1;       else         a[pol(s[2])][pol(s[0])] = 1;     }     for (int i = 1; i <= 3; i++) {       for (int j = 1; j <= 3; j++) u[j] = 0;       p =   ;       dfs(i);       if (p.size() > maxs.size()) maxs = p;     }     if (ok)       cout <<  Impossible ;     else       cout << maxs;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 69;   const int MAXP = 2e6 + 69;   int n, q;   int val[MAXN];   vector<int> a[MAXN];   int check[MAXP];   vector<int> p;   void build() {     for (long long i = 2; i < MAXP; i++) {       if (check[i] == 0) {         p.push_back(i);         check[i] = i;         for (long long j = i * i; j < MAXP; j += i) {           if (check[j] == 0) check[j] = i;         }       }     }   }   int ans[MAXN];   int h[MAXN];   vector<int> prim[MAXP];   void ptich(int i) {     int x = val[i];     while (check[x] != 0) {       int t = check[x];       if (!prim[t].empty()) {         int u = prim[t].back();         if (h[u] > h[ans[i]]) {           ans[i] = u;         }       }       prim[t].push_back(i);       while (x % t == 0) x /= t;     }   }   void xoa(int i) {     int x = val[i];     while (check[x] != 0) {       int t = check[x];       prim[t].pop_back();       while (x % t == 0) x /= t;     }   }   void dfs(int x, int p) {     h[x] = h[p] + 1;     ptich(x);     for (int u : a[x]) {       if (u == p) continue;       dfs(u, x);     }     xoa(x);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     build();     cin >> n >> q;     for (int i = 1; i <= n; i++) cin >> val[i];     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       a[x].push_back(y);       a[y].push_back(x);     }     dfs(1, 1);     while (q--) {       int type;       cin >> type;       if (type == 2) {         for (int i = 1; i <= n; i++) ans[i] = 0, h[i] = 0;         for (int i = 1; i < MAXP; i++) prim[i].clear();         int x, y;         cin >> x >> y;         val[x] = y;         dfs(1, 1);       } else {         int x;         cin >> x;         if (ans[x] != 0)           cout << ans[x] <<   n ;         else           cout << -1 <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int v_1, v_2, v_3, v_m, m_1, m_2, m_3;     cin >> v_1 >> v_2 >> v_3 >> v_m;     if (v_m >= v_2 || v_m < v_2 && v_m > v_3 && 2 * v_3 < v_m ||         v_m <= v_3 && 2 * v_m < v_3) {       cout << -1;       return 0;     }     cout << 2 * v_1 <<   n  << 2 * v_2 <<   n ;     if (v_m > v_3) {       cout << v_m;     } else       cout << v_3;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int MN = 1000010;   int exp(int x, int n) {     int ret = 1;     while (n) {       if (n & 1) ret = 1LL * ret * x % mod;       x = 1LL * x * x % mod;       n >>= 1;     }     return ret;   }   int inv(int x) { return exp(x, mod - 2); }   int fact[MN], invf[MN];   int K, W, ans;   int main() {     fact[0] = 1;     for (int i = 1; i < MN; i++) {       fact[i] = 1LL * fact[i - 1] * i % mod;     }     for (int i = 0; i < MN; i++) {       invf[i] = inv(fact[i]);     }     cin >> K >> W;     for (int i = 1; i <= min(K, W - 1); i++) {       ans += 1LL * i * fact[K] % mod * fact[K] % mod * exp(K, W - 1 - i) % mod *              invf[K - i] % mod * invf[K - i] % mod;       ans %= mod;     }     for (int i = W; i <= K; i++) {       ans += 1LL * W * fact[K] % mod * fact[K - i + W - 1] % mod * invf[K - i] %              mod * invf[K - i] % mod;       ans %= mod;     }     for (int i = 1; i <= min(K - 1, W - 2); i++) {       ans += 1LL * i * fact[K] % mod * fact[K] % mod * exp(K, W - 2 - i) % mod *              invf[K - i] % mod * invf[K - i - 1] % mod;       ans %= mod;     }     for (int i = W - 1; i <= K - 1; i++) {       ans += 1LL * (W - 1) * fact[K] % mod * fact[K - i + W - 2] % mod *              invf[K - i] % mod * invf[K - i - 1] % mod;       ans %= mod;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const long long int inf = 9e18;   const long double pi = 2 * acos(0.0);   long long int arr[100005];   void solve() {     long long int n, k;     cin >> n >> k;     ;     for (int i = 0; i < n; i++) cin >> arr[i];     ;     long long int mn = inf, pos = 0;     for (long long int i = 0; i < n; ++i) {       if (arr[i] < mn) {         mn = arr[i];         pos = i;       }     }     long long int ans = 0;     for (long long int i = 0; i < n; ++i) {       if (i == pos) continue;       long long int t = abs(k - arr[i]);       ans += (t / mn);     }     cout << ans <<   n ;     return;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long int tc = 1;     cin >> tc;     while (tc--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   string s;   vector<vector<int> > a[28];   vector<int> t, v1, v2;   int ans = 1e9;   void gen(int ind) {     if (ind == 3) {       a[t[0] + t[1] + t[2]].push_back(t);       return;     }     for (int i = 0; i <= 9; i++) {       t.push_back(i);       gen(ind + 1);       t.pop_back();     }   }   int dif(vector<int> aa, vector<int> bb) {     int ret = 0;     for (int i = 0; i < aa.size(); i++) ret += (aa[i] != bb[i]);     return ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> s;     v1.push_back(s[0] -  0 );     v1.push_back(s[1] -  0 );     v1.push_back(s[2] -  0 );     v2.push_back(s[3] -  0 );     v2.push_back(s[4] -  0 );     v2.push_back(s[5] -  0 );     gen(0);     for (int i = 0; i <= 27; i++)       for (int j = 0; j < a[i].size(); j++)         for (int k = 0; k < a[i].size(); k++)           ans = min(ans, dif(v1, a[i][j]) + dif(v2, a[i][k]));     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct trie {     trie* child[2];     int cnt;     trie() {       child[0] = child[1] = NULL;       cnt = 0;     }   } * root;   int n, k, sum;   long long res;   void add(int val) {     trie* node = root;     for (int i = 29; i >= 0; i--) {       int j = (val >> i) & 1;       if (!node->child[j]) node->child[j] = new trie;       node = node->child[j];       node->cnt++;     }   }   void get(trie* node, int i, int val, int remain) {     if (i == -1) return;     if (remain > (1 << (i + 1)) - 1) return;     int j = (val >> i) & 1;     if (node->child[j ^ 1]) {       if ((1 << i) >= remain)         res += node->child[j ^ 1]->cnt;       else         get(node->child[j ^ 1], i - 1, val, remain - (1 << i));     }     if (node->child[j]) get(node->child[j], i - 1, val, remain);   }   int main(int argc, char const* argv[]) {     ios ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     root = new trie;     add(0);     for (int i = 1; i <= n; i++) {       int a;       cin >> a;       sum ^= a;       get(root, 29, sum, k);       add(sum);     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, A[1000100], A2[1000010], N;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> A[i];     }     N = n;     long long cumsum = 0;     for (int i = 2, rank = 2; i <= n; i++) {       long long cumsum2 = cumsum + (rank - 2) * A2[rank - 1];       long long d = cumsum2 - (rank - 1) * (N - rank) * A[i];       if (d < k) {         cout << i << endl;         N--;       } else {         A2[rank] = A[i];         rank++;         cumsum = cumsum2;       }     }     return 0;   }