malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int sN = 1 << 19;   long long v[sN], d[sN], l[sN], r[sN], s[sN], w[sN];   int n, m;   int t, Left, Right;   long long x;   void down(int a, int c1, int c2) {     d[c1] += d[a];     d[c2] += d[a];     s[c1] += d[a] * w[c1];     s[c2] += d[a] * w[c2];     d[a] = 0;     if (v[a] > 0) v[c1] = v[c2] = v[a];   }   long long get(int a) {     if (Right < l[a] or r[a] < Left) return 0ll;     if (Left <= l[a] and r[a] <= Right) return s[a];     int c1 = a << 1, c2 = c1 + 1;     down(a, c1, c2);     return get(c1) + get(c2);   }   void update(int a) {     if (Right < l[a] or r[a] < Left) return;     if (Left <= l[a] and r[a] <= Right and v[a] > 0) {       long long inc = x - v[a];       if (inc < 0) inc = -inc;       d[a] += inc;       s[a] += inc * w[a];       v[a] = x;       return;     }     int c1 = a << 1, c2 = c1 + 1;     down(a, c1, c2);     update(c1);     update(c2);     s[a] = s[c1] + s[c2];     if (v[c1] == v[c2])       v[a] = v[c1];     else       v[a] = 0;   }   int main() {     scanf( %d %d , &n, &m);     int nn = 1;     for (; nn < n; nn <<= 1)       ;     n = nn--;     for (int i = 1; i <= n; i++)       v[nn + i] = l[nn + i] = r[nn + i] = i, w[nn + i] = 1;     for (int i = nn, j = i << 1; i > 0; i--, j = i << 1)       l[i] = l[j], r[i] = r[j + 1], w[i] = w[j] << 1;     for (; m--;) {       scanf( %d , &t);       if (t == 1) {         scanf( %d %d , &Left, &Right);         scanf( %I64d , &x);         update(1);       } else {         scanf( %d %d , &Left, &Right);         printf( %I64d n , get(1));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   const int inf = 0x3f3f3f3f;   const int mod = 998244353;   int a[N], n, L;   bool check(double x, int id) {     double s1 = 0, s2 = 0;     double t = x;     int s = 1;     for (int i = 1; i <= n + 1; i++) {       double cur = 1.0 * (a[i] - a[i - 1]) / s;       if (cur <= t) {         s1 = a[i];         t -= cur;       } else {         s1 += t * s;         break;       }       s++;     }     s = 1;     t = x;     for (int i = n; i >= 0; i--) {       double cur = 1.0 * (a[i + 1] - a[i]) / s;       if (cur <= t) {         s2 = L - a[i];         t -= cur;       } else {         s2 += t * s;         break;       }       s++;     }     return s1 + s2 >= 1.0 * L;   }   void solve() {     scanf( %d%d , &n, &L);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     a[n + 1] = L;     double l = 0, r = L;     double res = 1e9;     for (int i = 1; i <= 100; i++) {       double mid = 1.0 * (l + r) / 2;       if (check(mid, i)) {         res = mid;         r = mid;       } else         l = mid;     }     printf( %.6f n , res);   }   int main() {     int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, i, j, v[1005];   char s[1005];   int main() {     scanf( %d n , &n);     scanf( %s , s + 1);     s[0] =  L ;     s[n] =  R ;     for (i = 1; i <= n; ++i) {       j = i - 1;       while (s[j] !=  L ) {         if (s[j] ==  R ) ++v[i];         --j;       }       int aux = 0;       j = i;       while (s[j] !=  R ) {         if (s[j] ==  L ) ++aux;         ++j;       }       v[i] = max(v[i], aux);       ++v[i];     }     for (i = 1; i <= n; ++i) printf( %d  , v[i]);   }
#include <bits/stdc++.h>   using namespace std;   long long int max(long long int a, long long int b) {     if (a < b) swap(a, b);     return a;   }   long long int min(long long int a, long long int b) {     if (a >= b) swap(a, b);     return a;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string st, c;     long long int len, k, y[29] = {0}, i;     cin >> len >> k;     cin >> st;     c = st;     sort(c.begin(), c.end());     for (i = 0; i < k; i++) {       y[c[i] - 96] += 1;     }     for (i = 0; i < len; i++) {       if (y[st[i] - 96])         y[st[i] - 96] -= 1;       else         cout << st[i];     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( -O3 )   using namespace std;   void solve() {     long long int n, k;     cin >> n >> k;     vector<long long int> a(n);     for (long long int i = 0; i < n; i++) cin >> a[i];     sort(a.begin(), a.end());     long long int ones = 0;     vector<long long int> b;     for (long long int i = 0; i < k; i++) {       long long int temp;       cin >> temp;       if (temp == 1)         ones++;       else         b.push_back(temp);     }     sort(b.begin(), b.end(), greater<long long int>());     k = b.size();     long long int ans = accumulate(a.end() - 1 - ones + 1, a.end(), 0ll) * 2;     long long int end = n - 1 - ones, beg = 0;     for (long long int i = 0; i < k; i++) {       long long int cur = b[i];       ans += (a[end]);       cur--;       end--;       if (cur == 0)         ans += (a[end + 1]);       else {         ans += a[beg];         beg += cur;       }     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int __t;     cin >> __t;     while (__t--) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream& operator<<(ostream& os, vector<T> V) {     os <<  [  ;     for (auto v : V) os << v <<    ;     os <<  ] ;     return os;   }   template <class T>   ostream& operator<<(ostream& os, set<T> second) {     os <<  {  ;     for (auto s : second) os << s <<    ;     return os <<  } ;   }   template <class T>   ostream& operator<<(ostream& os, multiset<T> second) {     os <<  {  ;     for (auto s : second) os << s <<    ;     return os <<  } ;   }   template <class L, class R>   ostream& operator<<(ostream& os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }   template <class L, class R>   ostream& operator<<(ostream& os, map<L, R> M) {     os <<  {  ;     for (auto m : M) os <<  (  << m.first <<  :  << m.second <<  )  ;     return os <<  } ;   }   template <class L, class R>   ostream& operator<<(ostream& os, unordered_map<L, R> M) {     os <<  {  ;     for (auto m : M) os <<  (  << m.first <<  :  << m.second <<  )  ;     return os <<  } ;   }   const long long N = 2010, M = 1e9 + 7;   long long n, a[N][N], dp1[N][N], dp2[N][N], dp3[N][N];   void solve() {     cin >> n;     for (long long i = (0); i <= n - 1; i++)       for (long long j = (0); j <= n - 1; j++) cin >> a[i][j];     for (long long i = (0); i <= n - 1; i++)       dp1[i][0] = a[i][0], dp1[0][i] = a[0][i], dp2[i][n - 1] = a[i][n - 1],       dp2[0][n - i - 1] = a[0][n - i - 1];     for (long long i = (1); i <= n - 1; i++)       for (long long j = (1); j <= n - 1; j++)         dp1[i][j] = a[i][j] + dp1[i - 1][j - 1];     for (long long i = (1); i <= n - 1; i++)       for (long long j = (0); j <= n - 2; j++)         dp2[i][j] = a[i][j] + dp2[i - 1][j + 1];     for (long long i = (0); i <= n - 1; i++)       for (long long j = (0); j <= n - 1; j++) {         long long i1 = i + min(n - i - 1, n - j - 1);         long long j1 = j + min(n - i - 1, n - j - 1);         long long i2 = i + min(n - i - 1, j);         long long j2 = j - min(n - i - 1, j);         dp3[i][j] = dp1[i1][j1] + dp2[i2][j2] - a[i][j];       }     long long ans1 = LLONG_MIN, ans2 = LLONG_MIN, posx1, posy1, posx2, posy2;     for (long long i = (0); i <= n - 1; i++)       for (long long j = (0); j <= n - 1; j++) {         if ((i + j) % 2 == 0 && dp3[i][j] > ans1) {           ans1 = max(ans1, dp3[i][j]);           posx1 = i + 1;           posy1 = j + 1;         } else if ((i + j) % 2 == 1 && dp3[i][j] > ans2) {           ans2 = max(ans2, dp3[i][j]);           posx2 = i + 1;           posy2 = j + 1;         }       }     cout << ans1 + ans2 <<   n ;     cout << posx1 <<     << posy1 <<     << posx2 <<     << posy2 <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int a[2][2];     node() { a[0][0] = a[0][1] = a[1][0] = a[1][1] = 0; }     int *operator[](const size_t &s) { return a[s]; }   };   node segTree[400008], L[400008];   node id, M, zero;   int a[100002];   int lazy[400008];   inline node operator+(node &a, node &b) {     node res;     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) res[i][j] = (a[i][j] + b[i][j]) % 1000000007;     return res;   }   inline node operator*(node &a, node &b) {     node res;     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++)         for (int k = 0; k < 2; k++)           res[i][j] =               (res[i][j] + (1ll * a[i][k] * b[k][j]) % 1000000007) % 1000000007;     return res;   }   inline node matPower(int n) {     node res = id;     node m = M;     while (n > 0) {       if (n & 1) res = res * m;       m = m * m;       n >>= 1;     }     return res;   }   inline void buildTree(int v, int s, int e) {     L[v] = id;     lazy[v] = 0;     if (s == e) {       segTree[v] = matPower(a[s]);       return;     }     int m = (s + e) / 2;     buildTree(2 * v, s, m);     buildTree(2 * v + 1, m + 1, e);     segTree[v] = segTree[2 * v] + segTree[2 * v + 1];   }   inline void propogate(int v, int l, int r) {     if (lazy[v] > 0) {       segTree[v] = segTree[v] * L[v];       if (l != r) {         lazy[2 * v] = lazy[2 * v + 1] = 1;         L[2 * v] = L[2 * v] * L[v];         L[2 * v + 1] = L[2 * v + 1] * L[v];       }       lazy[v] = 0;       L[v] = id;     }     return;   }   inline void update(int v, int tl, int tr, int l, int r, node x) {     propogate(v, tl, tr);     if (l > r) return;     if (tl == l && tr == r) {       lazy[v] = 1;       L[v] = x;       propogate(v, tl, tr);       return;     }     int tm = (tl + tr) / 2;     update(2 * v, tl, tm, l, min(tm, r), x);     update(2 * v + 1, tm + 1, tr, max(l, tm + 1), r, x);     segTree[v] = segTree[2 * v] + segTree[2 * v + 1];   }   inline node query(int v, int tl, int tr, int l, int r) {     propogate(v, tl, tr);     if (l > r) return zero;     if (tl == l && tr == r) return segTree[v];     int tm = (tl + tr) / 2;     node left = query(2 * v, tl, tm, l, min(tm, r));     node right = query(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);     return (left + right);   }   int main() {     id[0][0] = id[1][1] = 1;     M[0][0] = M[0][1] = M[1][0] = 1;     ios::sync_with_stdio(false);     int n, m, q, l, r, x;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     buildTree(1, 0, n - 1);     while (m--) {       cin >> q;       if (q == 1) {         cin >> l >> r >> x;         node val = matPower(x);         update(1, 0, n - 1, l - 1, r - 1, val);       } else {         cin >> l >> r;         cout << query(1, 0, n - 1, l - 1, r - 1)[0][1] << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int a[N];   int main() {     ios_base::sync_with_stdio(false);     int n, U;     cin >> n >> U;     for (int i = 1; i <= n; ++i) cin >> a[i];     double ans = -1;     for (int i = 1, j = 1; i + 1 <= n; ++i) {       while (j + 1 <= n and a[j + 1] - a[i] <= U) ++j;       if (j - i + 1 < 3) continue;       ans = max(ans, (double)(a[j] - a[i + 1]) / (a[j] - a[i]));     }     cout << fixed << setprecision(9) << ans <<   n ;   }
#include <bits/stdc++.h>   int main() {     int q;     std::cin >> q;     while (q--) {       int n, ans(0);       std::cin >> n;       std::set<std::string> check, p;       std::string s;       std::vector<std::string> res, a(n);       for (int i = 0; i < n; i++) {         std::cin >> a[i];         check.insert(a[i]);       }       for (int i = 0; i < n; i++) {         if (p.find(a[i]) != p.end()) {           std::string t = a[i];           for (int x = 0; x < 10; x++) {             if (check.find(t) == check.end()) {               check.insert(t);               p.insert(t);               break;             }             t[0] = char( 0  + x);           }           ++ans;           res.push_back(t);         } else {           res.push_back(a[i]);           p.insert(a[i]);         }       }       std::cout << ans << std::endl;       for (int i = 0; i < res.size(); i++) {         std::cout << res[i] << std::endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef long long int ll;   typedef unsigned long long int ull;   inline void smax(int &x, int y) { x = max(x, y); }   inline void smin(int &x, int y) { x = min(x, y); }   ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); }   ll n, m, a, b;   vector<vector<int> > gr;   vector<int> vis;   ll con = 0;   int dfs(int s, int prt) {     vis[s] = 1;     con++;     int f = 0;     if (prt == s) f = 1;     for (__typeof(gr[s].size()) i = (0) - ((0) > (gr[s].size()));          i != (gr[s].size()) - ((0) > (gr[s].size()));          i += 1 - 2 * ((0) > (gr[s].size()))) {       int x = gr[s][i];       if (!vis[x]) {         if (dfs(x, prt) == 1) f = 1;       }     }     return f;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     int tcase;     cin >> tcase;     for (__typeof(tcase + 1) tc = (1) - ((1) > (tcase + 1));          tc != (tcase + 1) - ((1) > (tcase + 1));          tc += 1 - 2 * ((1) > (tcase + 1))) {       cin >> n >> m >> a >> b;       gr.resize(0);       vis.resize(0);       gr.resize(n + 1);       vis.resize(n + 1);       for (__typeof(m) i = (0) - ((0) > (m)); i != (m) - ((0) > (m));            i += 1 - 2 * ((0) > (m))) {         int x, y;         cin >> x >> y;         gr[x].push_back(y);         gr[y].push_back(x);       }       ll con1 = 0;       vis[a] = 1;       for (__typeof(gr[a].size()) i = (0) - ((0) > (gr[a].size()));            i != (gr[a].size()) - ((0) > (gr[a].size()));            i += 1 - 2 * ((0) > (gr[a].size()))) {         if (vis[gr[a][i]]) continue;         con = 0;         int tch = dfs(gr[a][i], b);         if (tch == 0) {           con1 += con;         }       }       vis.resize(0);       vis.resize(n + 1);       vis[b] = 1;       ll con2 = 0;       for (__typeof(gr[b].size()) i = (0) - ((0) > (gr[b].size()));            i != (gr[b].size()) - ((0) > (gr[b].size()));            i += 1 - 2 * ((0) > (gr[b].size()))) {         con = 0;         if (vis[gr[b][i]]) continue;         int tch = dfs(gr[b][i], a);         if (tch == 0) {           con2 += con;         }       }       cout << con2 * con1 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<int> SEC;   int main() {     long long n, x, y;     cin >> n >> x >> y;     long long tedX = 0, tedY = 0;     while (tedX + tedY < x + y) {       if ((tedX + 1) * y > (tedY + 1) * x) {         SEC.push_back(2);         tedY++;       } else if ((tedX + 1) * y < (tedY + 1) * x) {         SEC.push_back(1);         tedX++;       } else {         SEC.push_back(-1);         SEC.push_back(-1);         tedX++;         tedY++;       }     }     for (int i = 0; i < n; i++) {       long long tmp;       cin >> tmp;       long long ans = SEC[(tmp - 1) % (x + y)];       if (ans == 1) {         cout <<  Vanya  << endl;       } else if (ans == 2) {         cout <<  Vova  << endl;       } else         cout <<  Both  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 400010;   struct Event {     int x, type, ind;     Event() {}     Event(int x, int type, int ind) : x(x), type(type), ind(ind) {}     bool operator<(const Event &other) const {       return make_pair(x, type) < make_pair(other.x, other.type);     }   };   int n, k;   int l[N], r[N];   Event a[N];   bool del[N];   set<pair<int, int> > q;   vector<int> res;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &l[i], &r[i]);       a[2 * i - 1] = Event(l[i], 0, i);       a[2 * i] = Event(r[i], 1, i);     }     sort(a + 1, a + 2 * n + 1);     int cov = 0;     int ans = 0;     for (int i = 1; i <= n; i++) del[i] = false;     for (int i = 1; i <= 2 * n; i++) {       int j = a[i].ind;       if (a[i].type == 0) {         q.insert(make_pair(-r[j], j));         cov++;         if (cov > k) {           cov--;           ans++;           int ind = (*q.begin()).second;           del[ind] = true;           res.push_back(ind);           q.erase(q.begin());         }       } else if (!del[j]) {         cov--;         q.erase(make_pair(-r[j], j));       }     }     printf( %d n , ans);     for (int x : res) printf( %d  , x);     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   const int MAXN = -1;   const int MOD = 1;   const int INF = (int)(1e9);   int sign(long long x) {     if (x > 0) return 1;     if (x < 0) return -1;     return 0;   }   vector<int> getB(vector<int> a, int n, int &s) {     vector<int> b(a.size() + 40);     for (int i = 0; i < (int)a.size(); i++) {       int x = a[i];       int j = i;       while (x) {         b[j] += x % 2;         x /= 2;         j++;       }     }     for (int j = 0; j < (int)b.size(); j++) {       if (b[j]) {         b[j + 1] += b[j] / 2;         b[j] %= 2;       }     }     int mx = -1;     for (int j = 0; j < (int)b.size(); j++)       if (b[j] != 0) mx = j;     if (mx == -1) {       s = 0;       return vector<int>(a.size(), 0);     }     s = 1;     if (b[mx] == -1) {       s = -1;       for (int i = 0; i < (int)b.size(); i++) b[i] *= -1;     }     for (int i = 0; i < (int)b.size(); i++) {       b[i + 1] += b[i] / 2;       b[i] %= 2;       if (b[i] == -1) {         b[i] = 1;         b[i + 1] += -1;       }     }     return b;   }   int fastsolve(vector<int> a, int n, int k) {     for (int i = 0; i < 40; i++) a.push_back(0);     long long cur = 0;     int mn = INF, mx = -INF;     int s;     vector<int> b = getB(a, n, s);     for (int i = 0; i < (int)b.size(); i++) {       if (b[i] == 1) {         mn = min(mn, i);         mx = max(mx, i);       }     }     if (mx - mn > 35) {       return 0;     }     cur = 0;     for (int i = mx; i >= mn; i--) {       cur *= 2;       if (i != mn) cur += b[i];     }     cur *= s;     int ans = 0;     for (int i = mn; i >= 0; i--) {       cur += b[i] * s;       if (abs(cur) > 2LL * k) {         break;       }       ans += i <= n && abs(cur - a[i]) <= k && (i != n || abs(cur - a[i]) != 0);       cur *= 2;     }     return ans;   }   int slowsolve(vector<int> a, int n, int k) {     for (int i = 0; i < 40; i++) a.push_back(0);     int ans = 0;     for (int i = 0; i <= n; i++) {       vector<int> na = a;       for (int j = -k; j <= k; j++) {         na[i] = j;         if (i == n && j == 0) continue;         int s;         getB(na, n, s);         if (s == 0) {           ans++;           getB(na, n, s);         }       }     }     return ans;   }   int main() {     int n, k;     while (scanf( %d%d , &n, &k) == 2) {       vector<int> a(n + 1);       for (int i = 0; i <= n; i++) scanf( %d , &a[i]);       printf( %d n , fastsolve(a, n, k));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long T = 0;     int f = 0;     char c = getchar();     for (; c <  0  || c >  9 ; c = getchar()) f |= c ==  - ;     for (; c >=  0  && c <=  9 ; c = getchar()) T = T * 10 + c -  0 ;     return f ? -T : T;   }   const double eps = 1e-7;   const int maxn = 1e5 + 233;   const double pi = acos(-1.0);   struct Vector {     double x, y, r;   } A[maxn];   int n, a;   double ans;   struct WZP_AK_SZB {     double l, r;     bool operator<(const WZP_AK_SZB &n) const {       if (l == n.l) return r > n.r;       return l < n.l;     }   } B[maxn];   int numB;   set<double> S;   set<double>::iterator it;   bool check(double x) {     numB = 0;     for (register int i = (1); i <= (n); ++i) {       double dis = sqrt(((A[i].x - a) * (A[i].x - a)) + ((A[i].y) * (A[i].y)));       if (dis > A[i].r + x || A[i].r > dis + x || x > dis + A[i].r) continue;       double u = atan2(A[i].y, A[i].x - a);       double t = acos((((dis) * (dis)) + ((x) * (x)) - ((A[i].r) * (A[i].r))) /                       2.0 / dis / x);       double l = u - t, r = u + t;       if (l < -pi) l += 2 * pi;       if (l > pi) l -= 2 * pi;       if (r < -pi) r += 2 * pi;       if (r > pi) r -= 2 * pi;       if (l > r) swap(l, r);       B[++numB].l = l;       B[numB].r = r;     }     sort(B + 1, B + 1 + numB);     S.clear();     for (register int i = (1); i <= (numB); ++i) {       it = S.upper_bound(B[i].l);       if (it != S.end() && *it < B[i].r) return true;       S.insert(B[i].r);     }     return false;   }   int main() {     n = read(), a = read();     for (register int i = (1); i <= (n); ++i) {       A[i].x = read(), A[i].y = read();       A[i].r = sqrt(((A[i].x + a) * (A[i].x + a)) + ((A[i].y) * (A[i].y)));     }     double l = 0.0;     double r = 2.0 * a;     while (r - l > 1e-7) {       double mid = (l + r) / 2;       if (check(mid)) {         r = mid;       } else {         l = mid;       }     }     printf( %.10lf n , l);   }
#include <bits/stdc++.h>   using namespace std;   struct child {     long long v, p, d;   };   child c[4123];   bool gone[4123];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < (int)(n); i++) {       scanf( %lld%lld%lld , &c[i].v, &c[i].d, &c[i].p);     }     int ans = 0;     vector<int> all;     for (int i = 0; i < (int)(n); i++) {       if (gone[i]) continue;       ans++;       all.push_back(i + 1);       for (int j = i + 1; j < n && c[i].v; j++) {         if (gone[j]) continue;         c[j].p -= c[i].v;         c[i].v--;       }       long long dec = 0;       for (int j = i + 1; j < n; j++) {         if (gone[j]) continue;         c[j].p -= dec;         if (c[j].p < 0) {           gone[j] = 1;           dec += c[j].d;         }       }     }     printf( %d n , ans);     for (int i = 0; i < (int)(all.size()); i++) {       printf( %d%c , all[i], (i == all.size() - 1 ?   n  :    ));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, q, i;     cin >> q;     for (i = 0; i < q; i++) {       cin >> n;       if (n == 2) {         cout <<  2  << endl;       } else if (n % 2 == 1) {         cout <<  1  << endl;       } else if (n != 2 && n % 2 == 0) {         cout <<  0  << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, mnPre[(100005)], mxPre[(100005)], mnSuf[(100005)], mxSuf[(100005)];   pair<int, int> a[2][(100005)];   long long solve(int ax) {     sort(a[ax] + 1, a[ax] + 1 + n);     for (int i = 1; i <= n; ++i) {       mnPre[i] = min(mnPre[i - 1], a[ax][i].second);       mxPre[i] = max(mxPre[i - 1], a[ax][i].second);     }     for (int i = n; i >= 1; --i) {       mnSuf[i] = min(mnSuf[i + 1], a[ax][i].second);       mxSuf[i] = max(mxSuf[i + 1], a[ax][i].second);     }     long long r = (1LL << 60) - 1;     long long m = 0;     int mn, mx;     for (int i = 59; i >= 0; --i) {       bool allowed = 0;       m = r - (1LL << i);       allowed = (1LL * (a[ax][n].first - a[ax][1].first) *                  (a[ax][n].first - a[ax][1].first)) <= m;       for (int en = 1, st = 1; en <= n && !allowed; ++en) {         while ((1LL * (a[ax][en].first - a[ax][st].first) *                 (a[ax][en].first - a[ax][st].first)) > m)           ++st;         mn = min(mnPre[st - 1], mnSuf[en + 1]);         mx = max(mxPre[st - 1], mxSuf[en + 1]);         allowed = (1LL * (mx - mn) * (mx - mn)) <= m &&                   max((1LL * (mn) * (mn)), (1LL * (mx) * (mx))) +                           max((1LL * (a[ax][en].first) * (a[ax][en].first)),                               (1LL * (a[ax][st].first) * (a[ax][st].first))) <=                       m;       }       if (allowed) r -= (1LL << i);     }     return r;   }   int main() {     scanf( %d , &n);     for (int i = 1, x, y; i <= n; ++i) {       scanf( %d%d , &x, &y);       a[0][i] = {x, y}, a[1][i] = {y, x};     }     printf( %I64d , min(solve(0), solve(1)));   }