malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 50010, K = 11;   int n, k;   int s[N][K];   struct Data {     int mn[K], mx[K];     int cnt;     Data() {       for (int i = 0; i < K; i++) {         mn[i] = 1e9;         mx[i] = -1e9;       }       cnt = 0;     }   };   bool operator<(const Data &u, const Data &v) {     return u.mx[1] < v.mx[1];     return 1;   }   bool check(const Data &u, const Data &v) {     int l = 0, r = 0;     for (int i = 1; i <= k; i++) {       if (u.mx[i] > v.mn[i]) {         r = 1;       }       if (u.mn[i] < v.mx[i]) {         l = 1;       }     }     return l && r;   }   void update(Data &u, const Data &v) {     for (int i = 1; i <= k; i++) {       u.mx[i] = max(u.mx[i], v.mx[i]);       u.mn[i] = min(u.mn[i], v.mn[i]);     }     u.cnt += v.cnt;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= k; j++) {         cin >> s[i][j];       }     }     set<Data> a;     for (int i = 1; i <= n; i++) {       Data foo;       for (int j = 1; j <= k; j++) {         foo.mx[j] = foo.mn[j] = s[i][j];         foo.cnt = 1;       }       if (a.empty()) {         a.insert(foo);         cout << 1 << endl;         continue;       }       while (!a.empty()) {         auto it = a.lower_bound(foo);         if (it == a.end()) {           break;         }         Data bar = *it;         if (check(foo, bar)) {           update(foo, bar);           a.erase(it);         } else {           break;         }       }       while (!a.empty()) {         auto it = a.lower_bound(foo);         if (it == a.begin()) {           break;         }         it--;         Data bar = *it;         if (check(bar, foo)) {           update(foo, bar);           a.erase(it);         } else {           break;         }       }       a.insert(foo);       cout << a.rbegin()->cnt << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, m;     cin >> n >> m;     int a[n][m], b[n][m];     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) cin >> a[i][j];     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) cin >> b[i][j];     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         if (a[i][j] > b[i][j]) swap(a[i][j], b[i][j]);     bool pass = true;     for (int i = 0; i < n - 1; ++i)       for (int j = 0; j < m - 1; ++j) {         if (a[i][j] >= a[i + 1][j] || a[i][j] >= a[i][j + 1] ||             b[i][j] >= b[i + 1][j] || b[i][j] >= b[i][j + 1])           pass = false;       }     for (int i = 0; i < m - 1; ++i)       if (a[n - 1][i] >= a[n - 1][i + 1] || b[n - 1][i] >= b[n - 1][i + 1])         pass = false;     for (int i = 0; i < n - 1; ++i)       if (a[i][m - 1] >= a[i + 1][m - 1] || b[i][m - 1] >= b[i + 1][m - 1])         pass = false;     pass ? puts( Possible ) : puts( Impossible );   }
#include <bits/stdc++.h>   using namespace std;   int c[120][120], ct[120], n;   int ccc[120], Ciel, Jiro, cnt;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , ct + i);       int p1 = ct[i] / 2 - 1, p2 = ct[i] - ct[i] / 2;       for (int j = 0; j < ct[i]; j++) {         scanf( %d , &c[i][j]);         if (j <= p1)           Ciel += c[i][j];         else if (j >= p2)           Jiro += c[i][j];         else           ccc[cnt++] = c[i][j];       }     }     sort(ccc, ccc + cnt);     for (int i = cnt - 1; i >= 0; i--) {       if ((cnt - i) % 2)         Ciel += ccc[i];       else         Jiro += ccc[i];     }     printf( %d %d n , Ciel, Jiro);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 998244353;   long long modpow(long long base, long long exp, long long modulus = M) {     base %= modulus;     long long result = 1;     while (exp > 0) {       if (exp & 1) result = (result * base) % modulus;       base = (base * base) % modulus;       exp >>= 1;     }     return result;   }   long long modinv(long long a, long long mod = M) { return modpow(a, mod - 2); }   string s;   int n;   long long f[1000010], invf[1000010];   long long C(long long a, long long b) {     if (b > a || b < 0 || a < 0) return 0;     return (((f[a] * invf[b]) % M) * invf[a - b]) % M;   }   int main() {     ios::sync_with_stdio(false);     cin >> s;     n = s.length();     f[0] = invf[0] = 1;     for (int i = 1; i <= n; ++i) {       f[i] = (f[i - 1] * i) % M;       invf[i] = modinv(f[i]);     }     int lb = 0, rb = 0, lq = 0, rq = 0;     for (int i = 0; i < n; ++i) {       if (s[i] ==  ) )         ++rb;       else if (s[i] ==  ? )         ++rq;     }     long long ans = 0;     for (int i = 0; i < n; ++i) {       if (s[i] ==  ) ) --rb;       if (s[i] ==  ( ) ++lb;       if (s[i] ==  ? ) --rq, ++lq;       ans += (1ll * lb * C(lq + rq, rq - lb + rb) +               1ll * lq * C(lq + rq - 1, rq - lb + rb - 1)) %              M;       ans %= M;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using PII = pair<int, int>;   PII a[300005];   int idx[300005];   map<int, int> mp;   int main() {     int n;     ;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d %d , &a[i].first, &a[i].second);       idx[i] = i;     }     sort(idx, idx + n, [&](int l, int r) {       if (a[l].first != a[r].first)         return a[l].first > a[r].first;       else         return a[l].second < a[r].second;     });     bool f = false;     for (int i = 0; i < n; ++i) {       auto it = mp.upper_bound(a[idx[i]].second);       if (it != mp.begin()) {         f = true;         --it;         printf( %d %d n , it->second + 1, idx[i] + 1);         break;       } else {         mp[a[idx[i]].second] = idx[i];       }     }     if (!f) puts( -1 -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 5;   long long n;   long long a[N];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     if (n == 0) {       cout <<  1 1 ;       return 0;     }     long long l = 1, r = n;     for (long long cur = 1; cur <= n; cur += 2) {       a[l++] = cur;       a[r--] = cur;     }     l = n + 1;     r = 2 * n - 1;     for (long long cur = 2; cur <= n; cur += 2) {       a[l++] = cur;       a[r--] = cur;     }     for (long long i = 1; i <= 2 * n; i++) {       if (a[i] == 0) a[i] = n;       cout << a[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   const double Pi = 3.14159265;   const int N = 2e5 + 10;   const unsigned long long base = 163;   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const double eps = 1e-10;   const double pi = acos(-1);   using namespace std;   long long inv[N];   long long dp[N];   int main() {     long long p = mod;     long long n;     cin >> n;     inv[1] = 1;     for (int i = 2; i <= n; i++) inv[i] = (p - p / i) * inv[p % i] % p;     long long ans = 1;     for (int i = n; i >= 2; --i) {       dp[i] = n / i * inv[n - n / i];       for (int j = i + i; j <= n; j += i) {         dp[i] -= dp[j];         dp[i] %= mod;       }       dp[i] += mod;       dp[i] %= mod;       ans += dp[i];       ans %= mod;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   const int N = 2e5 + 5;   using namespace std;   int n, k, m, ans[N], x[N], y[N], mx;   map<pair<int, int>, int> Mp;   template <typename T>   inline T read() {     T x = 0, w = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) w = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return x * w;   }   struct PQ {     priority_queue<int> q1, q2;     int cnt;     PQ() { cnt = 0; }     void ins(int x) { cnt++, q1.push(x); }     void del(int x) { cnt--, q2.push(x); }     int top() {       while (!q1.empty() && !q2.empty() && q1.top() == q2.top())         q1.pop(), q2.pop();       return q1.top();     }     bool empty() { return !cnt; }   } q;   struct BIT {     int t[N << 2];     int lowbit(int x) { return x & (-x); }     void modify(int x, int y) {       for (int i = x; i <= mx; i += lowbit(i)) t[i] += y;     }     int query(int x) {       int res = 0;       for (int i = x; i; i -= lowbit(i)) res += t[i];       return res;     }     int kth(int x) {       int sum = 0, pos = 0;       for (int i = 20; i >= 0; i--)         if (pos + (1 << i) <= mx && sum + t[pos + (1 << i)] < x)           pos += (1 << i), sum += t[pos];       return pos + 1;     }   } BIT;   struct SegTree {     vector<int> vec[N << 2], op[N << 2];     void modify(int p, int l, int r, int ql, int qr, int x) {       if (ql <= l && r <= qr) return (void)(vec[p].push_back(x));       int mid = (l + r) >> 1;       if (ql <= mid) modify(p << 1, l, mid, ql, qr, x);       if (mid < qr) modify(p << 1 | 1, mid + 1, r, ql, qr, x);     }     void dfs(int p, int l, int r) {       for (int x, y, i = 0; i < vec[p].size(); i++) {         x = vec[p][i], x = BIT.query(x - 1), x = BIT.kth(x + 1);         BIT.modify(x, -1), op[p].push_back(x), q.ins(x);       }       if (l == r) {         ans[l] = q.top() - n;         for (int i = 0; i < op[p].size(); i++)           BIT.modify(op[p][i], 1), q.del(op[p][i]);         return;       }       int mid = (l + r) >> 1;       dfs(p << 1, l, mid), dfs(p << 1 | 1, mid + 1, r);       for (int i = 0; i < op[p].size(); i++)         BIT.modify(op[p][i], 1), q.del(op[p][i]);     }   } T;   int mabs(int x) { return x > 0 ? x : -x; }   int main() {     n = read<int>(), k = read<int>(), m = read<int>();     for (int i = 1; i <= m; i++) {       x[i] = read<int>(), y[i] = read<int>();       if (!Mp[make_pair(x[i], y[i])])         Mp[make_pair(x[i], y[i])] = i;       else {         T.modify(1, 1, m, Mp[make_pair(x[i], y[i])], i - 1,                  y[i] + mabs(x[i] - k));         mx = max(mx, y[i] + mabs(x[i] - k)), Mp[make_pair(x[i], y[i])] = 0;       }     }     for (int i = 1; i <= m; i++)       if (Mp[make_pair(x[i], y[i])]) {         T.modify(1, 1, m, Mp[make_pair(x[i], y[i])], m, y[i] + mabs(x[i] - k));         mx = max(mx, y[i] + mabs(x[i] - k)), Mp[make_pair(x[i], y[i])] = 0;       }     mx += m;     for (int i = 1; i <= mx; i++) BIT.modify(i, 1);     q.ins(n), T.dfs(1, 1, m);     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long sum[2000005];   int main() {     long long n;     double k;     cin >> n >> k;     vector<long long> v;     for (int i = 0; i < n; i++) {       long long a;       cin >> a;       v.push_back(a);     }     for (int i = 1; i <= n; i++) {       sum[i] = sum[i - 1] + v[i - 1];     }     double total = 0;     int go = n - k + 1;     for (int i = 0; i < v.size(); i++) {       if (go + i - 1 == v.size()) {         break;       }       total += (sum[go + i] - sum[i]) / (double)go;     }     printf( %.10llf n , total);   }
#include <bits/stdc++.h>   using namespace std;   long long n, i, m[6222000], k, a, b, x, y, sum, z, m1[5000];   string s;   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> m[i];     }     sort(m, m + n);     for (i = 1; i < n; i++) {       if (m[i] == m[i - 1])         z++;       else         z = 0;       if (z == 2) {         cout <<  NO ;         return 0;       }     }     for (i = 1; i < n; i++) {       if (m[i] == m[i - 1]) k++;     }     cout <<  YES n  << n - k << endl;     cout << m[0] <<    ;     for (i = 1; i < n; i++) {       if (m[i] != m[i - 1]) cout << m[i] <<    ;     }     cout << endl << k << endl;     reverse(m, m + n);     for (i = 0; i < n - 1; i++) {       if (m[i] == m[i + 1]) cout << m[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > vec;   int grid1[2050], grid2[2050];   int main() {     int n;     cin >> n;     int r = 0, c = 0;     long long ans = 0;     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       ans += grid1[x + y];       grid1[x + y]++;       ans += grid2[x - y + 1000];       grid2[x - y + 1000]++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize  Ofast    using namespace std;   const long long BIG_INF = 1e18;   const int N = 1e6 + 7;   const int T = 1 << 20;   template <class T, class G>   ostream &operator<<(ostream &os, const pair<T, G> &para) {     os << para.first <<     << para.second;     return os;   }   template <class T>   ostream &operator<<(ostream &os, const vector<T> &vec) {     for (const T &el : vec) os << el <<    ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, const set<T> &vec) {     for (const T &el : vec) os << el <<    ;     return os;   }   template <class T>   istream &operator>>(istream &is, vector<T> &vec) {     for (T &el : vec) is >> el;     return is;   }   template <class T, class G>   istream &operator>>(istream &os, pair<T, G> &para) {     os >> para.first >> para.second;     return os;   }   template <class T>   void setmax(T &a, T b) {     a = (a >= b ? a : b);   }   template <class T>   void setmin(T &a, T b) {     a = (a <= b ? a : b);   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   std::vector<int> zet(const std::string &w) {     int n = (int)w.size();     std::vector<int> p(n);     int j = 0;     for (int i = 1; i < n; ++i) {       p[i] = std::max(std::min(p[j] + j - i, p[i - j]), 0);       while (p[i] + i < n && w[p[i]] == w[p[i] + i]) p[j = i]++;     }     return p;   }   void solve() {     int n;     cin >> n;     string second;     cin >> second;     vector<vector<int> > zzz;     vector<int> dp(n);     for (int i = 0; i < n; i++) {       string temp = second.substr(i);       zzz.push_back(zet(temp));       int dl_suf = n - i;       dp[i] = dl_suf;       for (int j = 0; j < i; j++) {         int dl_wsp = zzz[j][i - j];         if (dl_wsp < dl_suf and second[j + dl_wsp] < second[i + dl_wsp])           setmax(dp[i], dp[j] + dl_suf - dl_wsp);       }     }     int ans = 0;     for (auto &u : dp) setmax(ans, u);     cout << ans <<   n ;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     int test = 1;     cin >> test;     for (int i = 1; i <= test; i++) solve();   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   set<int> adj[maxn * 2 + 20];   int ans[maxn], n;   vector<int> ans_eu;   map<pair<int, int>, int> mp;   void find_eu(int v) {     while (adj[v].size()) {       int tmp = *adj[v].begin();       adj[v].erase(tmp);       adj[tmp].erase(v);       find_eu(tmp);     }     ans_eu.push_back(v);   }   void solve() {     for (int i = 1, tmp = maxn * 2 + 9; i < maxn * 2 + 10; i++)       if (adj[i].size() % 2 == 1) adj[tmp].insert(i), adj[i].insert(tmp);     for (int i = maxn * 2 + 9; i > 0; i--) {       if (adj[i].size()) {         ans_eu.clear();         find_eu(i);         for (int j = 1; j < ans_eu.size(); j++)           if (max(ans_eu[j], ans_eu[j - 1]) != maxn * 2 + 9)             ans[mp[{ans_eu[j], ans_eu[j - 1]}]] = j % 2;       }     }     for (int i = 1; i <= n; i++) cout << (ans[i] ?  r  :  b );     cout << endl;   }   int main() {     cin >> n;     for (int i = 1, x, y; i <= n; i++) {       cin >> x >> y;       adj[x].insert(y + maxn);       adj[y + maxn].insert(x);       mp[{x, y + maxn}] = mp[{y + maxn, x}] = i;     }     solve();     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--) {       long long p, q;       cin >> p >> q;       long long ans = -1;       for (long long i = 1; i * i <= q; ++i) {         long long pp = p;         if (q % i == 0) {           while (i != 1 and pp % q == 0 and pp % i == 0) {             pp /= i;           }           long long ppp = p;           while (ppp % q == 0 and ppp % (q / i) == 0) {             ppp /= (q / i);           }           if (ppp % q != 0) ans = max(ans, ppp);         }         if (pp % q != 0) ans = max(ans, pp);       }       assert(ans != -1);       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   const int N = 100001;   int Pri[200005];   int NN, Cnt[100005], Mac[100005];   bool Use[200005];   void GetPrimeList() {     int TmpN = sqrt(N);     for (int i = 2; i <= N; ++i) Use[i] = true;     for (int i = 2; i <= N; ++i) {       if (Use[i]) Pri[++Pri[0]] = i;       for (int j = 1; j <= Pri[0] && i * Pri[j] <= N; ++j) {         Use[i * Pri[j]] = false;         if (i % Pri[j] == 0) break;       }       if (i <= TmpN) NN = Pri[0];     }     ++NN;     for (int i = 1; i <= N; ++i) Use[i] = false;   }   int Add(int x) {     int t = x;     for (int i = 1; i <= NN; ++i)       if (t % Pri[i] == 0) {         if (Cnt[Pri[i]] != 0) return Mac[Pri[i]];         for (; t % Pri[i] == 0; t /= Pri[i])           ;       }     if (t != 1 && Cnt[t] != 0) return Mac[t];     t = x;     for (int i = 1; i <= NN; ++i)       if (t % Pri[i] == 0) {         ++Cnt[Pri[i]];         Mac[Pri[i]] = x;         for (; t % Pri[i] == 0; t /= Pri[i])           ;       }     if (t != 1) {       ++Cnt[t];       Mac[t] = x;     }     Use[x] = true;     return -1;   }   void Del(int x) {     int t = x;     for (int i = 1, j, k; i <= NN; ++i)       if (t % Pri[i] == 0) {         --Cnt[Pri[i]];         Mac[Pri[i]] = 0;         for (; t % Pri[i] == 0; t /= Pri[i])           ;       }     if (t != 1) {       --Cnt[t];       Mac[t] = 0;     }     Use[x] = false;   }   int main() {     GetPrimeList();     int n, m, num;     char op;     scanf( %d %d n , &n, &m);     for (int i = 1, ret; i <= m; ++i) {       scanf( %c %d n , &op, &num);       if (op ==  + ) {         if (Use[num])           puts( Already on );         else {           ret = Add(num);           if (ret == -1)             puts( Success );           else             printf( Conflict with %d n , ret);         }       } else {         if (!Use[num])           puts( Already off );         else {           Del(num);           puts( Success );         }       }     }     return 0;   }
#include <bits/stdc++.h>   const int MAXN = 2e5 + 7;   struct Edge {     int t, next;   } edge[MAXN << 1];   int head[MAXN], cnt;   std::pair<int, int> p[MAXN];   int color[MAXN];   int n;   void add(int u, int v) {     edge[++cnt] = (Edge){v, head[u]};     head[u] = cnt;   }   void dfs(int u, int col) {     if (color[u] != -1) return;     color[u] = col;     for (int e = head[u]; e; e = edge[e].next) {       int v = edge[e].t;       dfs(v, col ^ 1);     }   }   int main(int argc, char *argv[]) {     memset(color, -1, sizeof color);     scanf( %d , &n);     int l, r;     for (int i = 0; i < n; i++) {       scanf( %d %d , &l, &r);       add(i << 1, i << 1 | 1);       add(i << 1 | 1, i << 1);       p[i << 1] = std::make_pair(l, i << 1);       p[i << 1 | 1] = std::make_pair(r + 1, i << 1 | 1);     }     std::sort(p, p + 2 * n);     for (int i = 0; i < n; i++) {       int u = p[i << 1].second, v = p[i << 1 | 1].second;       add(u, v), add(v, u);     }     for (int i = 0; i < n; i++) {       if (color[i << 1] == -1) dfs(i << 1, 0);       printf( %d  , color[i << 1]);     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v, w;   int m;   long long int f(int d, int target) {     long long int timeSpent = 0;     long long int totDone = 0;     long long int koytaDone = 0;     long long int lastSpent = 0;     for (int i = 0; i < v.size(); i++) {       if (v[i] <= d) {         timeSpent += v[i];         lastSpent += v[i];         koytaDone++;         totDone++;         if (totDone == target) return timeSpent;       }       if (koytaDone == m) {         koytaDone = 0;         timeSpent += lastSpent;         lastSpent = 0;       }     }     return LLONG_MAX / 3;   }   int main() {     int t, n, inp;     long long int tot;     scanf( %d , &t);     while (t--) {       v.clear();       w.clear();       scanf( %d %d , &n, &m);       cin >> tot;       while (n--) {         scanf( %d , &inp);         v.push_back(inp);         w.push_back(inp);       }       sort(w.begin(), w.end());       int lo = 1, hi = w.size(), ans = 0, ans_d = 1;       while (lo <= hi) {         int mid = (lo + hi) / 2;         int tem_d = w[mid - 1];         if (f(tem_d, mid) <= tot) {           ans = mid;           ans_d = tem_d;           lo = mid + 1;         } else           hi = mid - 1;       }       cout << ans <<     << ans_d <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[1123456], p[1123456];   int main() {     int n, i, j;     scanf( %d , &n);     for (i = 0; i < n; ++i) {       scanf( %d , &j);       p[j] = i;     }     dp[1] = 1;     int ans = 1;     for (i = 2; i <= n; ++i) {       if (p[i] > p[i - 1]) {         dp[i] = 1 + dp[i - 1];       } else {         dp[i] = 1;       }       ans = max(ans, dp[i]);     }     cout << n - ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans[1005];   void calc() {     int i, j;     for (i = 2; i < 1000; i++) {       if (ans[i] == 0) {         ans[i] = 1;         int k = i;         for (j = 2; j <= 10; j++) {           if (k * i < 1000) {             ans[k * i] = 1;             k = k * i;           } else             break;         }         for (j = i + i; j <= 1002; j += i) {           if (!ans[j]) ans[j] = -1;         }       }     }   }   int main() {     calc();     int n, i;     cin >> n;     if (n == 1) {       cout << 0;       return 0;     }     vector<int> v;     for (i = 2; i <= n; i++) {       if (ans[i] == 1) v.push_back(i);     }     cout << v.size() << endl;     for (i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1e9 + 9;   const long long N = 500500;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long T;     cin >> T;     while (T--) {       long long n, ans = 0, mx;       cin >> n;       for (long long b = 0; b <= 6; b++) {         vector<long long> x, y;         for (long long i = 1; i <= n; i++) {           if (i & (1 << b)) {             x.push_back(i);           } else             y.push_back(i);         }         if (x.size() == 0 || y.size() == 0) continue;         cout << x.size() <<     << y.size() <<    ;         for (auto z : x) cout << z <<    ;         for (auto z : y) cout << z <<    ;         cout << endl;         cin >> mx;         ans = max(ans, mx);       }       cout <<  -1   << ans << endl;       cout.flush();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     int v, w;     edge() {}     edge(int V, int W) { v = V, w = W; }   };   struct node {     long long x, y, z;     node() {}     node(long long X, long long Y, long long Z) { x = X, y = Y, z = Z; }   } p[100005];   vector<edge> G[100005];   int n;   long long f1[100005], f2[100005], Size[100005];   bool cmp(node u, node v) { return v.x * u.y < u.x * v.y; }   void dfs(int u, int fa) {     Size[u]++;     for (int i = 0; i < G[u].size(); i++) {       int v = G[u][i].v;       if (v == fa) continue;       dfs(v, u);       Size[u] += Size[v], f1[u] += f1[v];     }     int len = 0;     for (int i = 0; i < G[u].size(); i++) {       int v = G[u][i].v, w = G[u][i].w;       if (v == fa) continue;       p[++len] = node(Size[v], f2[v] + (w << 1), w);     }     sort(p + 1, p + len + 1, cmp);     for (int i = 1; i <= len; i++)       f1[u] += (p[i].z + f2[u]) * p[i].x, f2[u] += p[i].y;   }   int main() {     scanf( %d , &n);     for (int i = 1, u, v, w; i < n; i++) {       scanf( %d %d %d , &u, &v, &w);       G[u].push_back(edge(v, w));       G[v].push_back(edge(u, w));     }     dfs(1, 0);     printf( %.8f , f1[1] * 1.0 / (n - 1));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e6 + 5;   const int mod = (int)1e9 + 7;   string a;   int x, n;   int u[N];   int main() {     ios_base::sync_with_stdio(false);     cin >> a;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x;       u[x]++;     }     for (int i = 1; i <= a.size() / 2; i++) u[i] += u[i - 1];     for (int i = 0; i < a.size(); i++) {       if (u[i + 1] & 1) swap(a[i], a[a.size() - i - 1]);     }     cout << a << endl;     return 0;   }