malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   int main() {     char str[5010];     memset(str, 0, sizeof(str));     scanf( %s , str);     int n;     n = strlen(str);     int res = 0;     for (int i = 0; i < n; i++) {       int l = 0, sum = 0;       for (int j = i; j < n; j++) {         if (str[j] ==  ( )           l++;         else if (str[j] ==  ) )           l--;         else           l--, sum++;         if (!l) res++;         if (l < 0 && sum > 0) {           l += 2;           sum--;         } else if (l < 0 && sum <= 0) {           break;         }       }     }     printf( %d n , res);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int r1, r2, c1, c2;     cin >> r1 >> c1 >> r2 >> c2;     if (r1 == r2 || c1 == c2) {       cout << 1 <<    ;     } else {       cout << 2 <<    ;     }     if ((r1 + c1) % 2 != (r2 + c2) % 2) {       cout << 0 <<    ;     } else {       if (r1 + c1 == r2 + c2 || r1 - c1 == r2 - c2) {         cout << 1 <<    ;       } else {         cout << 2 <<    ;       }     }     cout << max(abs(r1 - r2), abs(c1 - c2)) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     cin >> a >> b >> c >> d;     if (d > 2 * c || 2 * d < c || d >= b) {       printf( -1 n );       return 0;     }     int tmp = max(c, d);     cout << max(d * 2 + 2, a) << endl;     cout << max(d * 2 + 1, b) << endl;     cout << tmp << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 20;   unsigned long long bit[N][20], ans, s;   int main() {     int n, k, a;     cin >> n >> k;     for (int x = 1; x < N; x += x & (-x)) bit[x][0]++;     for (int i = 0; i < n; i++) {       cin >> a;       for (int j = k + 1; j > 0; j--) {         s = 0;         for (int x = a; x > 0; x -= x & (-x)) s += bit[x][j - 1];         for (int x = a; x < N; x += x & (-x)) bit[x][j] += s;       }     }     for (int x = n; x > 0; x -= x & (-x)) ans += bit[x][k + 1];     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dr[] = {-1, 0, 1, 0};   const int dc[] = {0, 1, 0, -1};   string FILE_NAME =  testcase.C ;   string NAME;   string itos(int n) {     stringstream ss;     ss << n;     return ss.str();   }   int main() {     int n, k;     cin >> n >> k;     if (k >= n * (n - 1) / 2) {       cout <<  no solution  << endl;     } else {       for (int i = 0; i < (n); i++) {         cout << 0 <<     << i << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e4;   bitset<maxn * 25> f[50][25];   int n;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     vector<int> a(n * 2);     for (int i = 1; i <= n * 2; i++) cin >> a[i - 1];     sort(a.begin(), a.end());     vector<vector<int>> ans(2);     ans[0].push_back(a[0]), ans[1].push_back(a[1]);     int sum = 0;     for (int i = 2; i <= n * 2 - 1; i++) sum += a[i];     int lim = sum / 2;     f[1][0].set(0);     for (int i = 2; i <= n * 2 - 1; i++)       for (int j = 0; j <= min(i, n - 1); j++) {         f[i][j] |= f[i - 1][j];         if (j) f[i][j] |= f[i - 1][j - 1] << a[i];       }     int s1 = -1, cnt = n - 1, id = 2 * n - 1;     for (int i = lim; i >= 0; i--) {       if (f[id][cnt][i]) {         s1 = i;         break;       }     }     assert(s1 >= 0);     for (int i = id; i >= 2; i--) {       assert(f[i][cnt][s1]);       if (cnt >= 1 && s1 >= a[i] && f[i - 1][cnt - 1][s1 - a[i]]) {         ans[0].push_back(a[i]);         s1 -= a[i], cnt--;       } else         ans[1].push_back(a[i]);     }     sort(ans[0].begin(), ans[0].end());     sort(ans[1].begin(), ans[1].end(), greater<int>());     for (int i = 0; i <= 1; i++) {       for (auto x : ans[i]) cout << x <<    ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[100100], b[100100];   int n, x;   multiset<int> st;   multiset<int>::iterator it;   int main() {     scanf( %d%d , &n, &x);     for (int i = 0; i < n; i++) scanf( %d , a + i);     for (int i = 0; i < n; i++) {       int w;       scanf( %d , &w);       st.insert(w);     }     sort(a, a + n);     reverse(a, a + n);     int res = 1;     for (int i = 0; i < n; i++) {       int w = x - a[i];       it = st.lower_bound(w);       if (it != st.end()) {         st.erase(it);         res = i + 1;       }     }     printf( 1 %d , res);   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 9;   long long n, a, b, val[MAX], incc[MAX], decc[MAX];   vector<int> g[MAX];   void dfs(int v, int p) {     for (auto u : g[v])       if (u != p)         dfs(u, v), decc[v] = max(decc[v], decc[u]),                    incc[v] = max(incc[v], incc[u]);     long long meg = val[v] + incc[v] - decc[v];     if (meg < 0)       incc[v] += -meg;     else       decc[v] += meg;   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; i++)       cin >> a >> b, a--, b--, g[a].push_back(b), g[b].push_back(a);     for (int i = 0; i < n; i++) cin >> val[i];     dfs(0, -1);     cout << incc[0] + decc[0];   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long ans, p;   int main() {     scanf( %d , &n);     p = 2;     for (int i = 1; i <= n; i++) {       cout << (long long)i * (i + 1) * (i + 1) - p / i << endl;       p = (long long)i * (i + 1);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int x1, x2, y1, y2;     cin >> x1 >> y1 >> x2 >> y2;     if (x1 == x2) {       int w = max(y1, y2) - min(y1, y2);       cout << x1 + w <<     << y1 <<     << x2 + w <<     << y2 << endl;     } else if (y1 == y2) {       int w = max(x1, x2) - min(x1, x2);       cout << x1 <<     << y1 + w <<     << x2 <<     << y2 + w << endl;     } else if (abs(x1 - x2) == abs(y1 - y2)) {       cout << x1 <<     << y2 <<     << x2 <<     << y1 << endl;     } else {       cout << -1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t = 0;     string s;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s;       if (s[0] >=  0  && s[0] <=  9 ) {         if (s.size() == 1 || (s.size() == 2 && s <  18 )) t++;       } else if (s ==  ABSINTH  || s ==  CHAMPAGNE  || s ==  TEQUILA  ||                  s ==  WINE  || s ==  WHISKEY  || s ==  VODKA  || s ==  SAKE  ||                  s ==  RUM  || s ==  GIN  || s ==  BRANDY  || s ==  BEER )         t++;     }     cout << t;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3,inline,unroll-loops )   using namespace std;   int f[4020][4020][2][2];   inline int Mod(int x) { return x + ((x >> 31) & 1000000007); }   inline void Modadd(int &x, int y) {     x = Mod(x + y - 1000000007);     return;   }   int Modular(string &a, int b) {     string c;     int i;     long long t;     c = string(a.size(),  0 );     for (i = t = 0; i < (signed)a.size(); i++) {       t = t * 10 + a[i] - 48;       c[i] = t / b + 48;       t %= b;     }     for (i = 0; i < (signed)c.size() && c[i] ==  0 ; i++)       ;     a = c.substr(i);     return (int)t;   }   int main(void) {     int p, k;     string a;     vector<int> b;     int i, j, o;     int w[6];     cin >> p >> k >> a;     while (!a.empty()) b.push_back(Modular(a, p));     reverse(b.begin(), b.end());     f[0][0][1][0] = 1;     for (i = 0; i < (signed)b.size(); i++) {       w[0] = (long long)p * (p + 1) / 2 % 1000000007;       w[1] = (long long)p * (p - 1) / 2 % 1000000007;       w[2] = (long long)b[i] * (b[i] + 1) / 2 % 1000000007;       w[3] = (long long)b[i] * (b[i] - 1) / 2 % 1000000007;       w[4] = (long long)b[i] * (p + p - b[i] - 1) / 2 % 1000000007;       w[5] = (long long)b[i] * (p + p - b[i] + 1) / 2 % 1000000007;       for (j = 0; j <= i + 1; j++) {         Modadd(f[i + 1][j][0][0], (long long)f[i][j][0][0] * w[0] % 1000000007);         Modadd(f[i + 1][j][0][0], (long long)f[i][j][1][0] * w[2] % 1000000007);         Modadd(f[i + 1][j][0][1], (long long)f[i][j][0][0] * w[1] % 1000000007);         Modadd(f[i + 1][j][0][1], (long long)f[i][j][1][0] * w[3] % 1000000007);         Modadd(f[i + 1][j][1][0],                (long long)f[i][j][1][0] * (b[i] + 1) % 1000000007);         Modadd(f[i + 1][j][1][1], (long long)f[i][j][1][0] * b[i] % 1000000007);         Modadd(f[i + 1][j + 1][0][0],                (long long)f[i][j][0][1] * w[1] % 1000000007);         Modadd(f[i + 1][j + 1][0][0],                (long long)f[i][j][1][1] * w[4] % 1000000007);         Modadd(f[i + 1][j + 1][0][1],                (long long)f[i][j][0][1] * w[0] % 1000000007);         Modadd(f[i + 1][j + 1][0][1],                (long long)f[i][j][1][1] * w[5] % 1000000007);         Modadd(f[i + 1][j + 1][1][0],                (long long)f[i][j][1][1] * (p - b[i] - 1) % 1000000007);         Modadd(f[i + 1][j + 1][1][1],                (long long)f[i][j][1][1] * (p - b[i]) % 1000000007);       }     }     for (i = k, o = 0; i <= (signed)b.size(); i++)       Modadd(o, Mod(f[b.size()][i][0][0] + f[b.size()][i][1][0] - 1000000007));     cout << o << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double cooy1, cooy2, cooyw, cooxb, cooyb, r;   double s1, s2;   int main() {     ios_base::sync_with_stdio(false);     cin >> cooy1 >> cooy2 >> cooyw >> cooxb >> cooyb >> r;     cooy1 += r;     cooy2 -= r;     cooyw -= r;     s1 = 2 * cooyw - cooy1;     s2 = 2 * cooyw - cooy2;     double xx1 = cooxb * (cooyw - s1) / (cooyb - s1);     double xx2 = cooxb * (cooyw - s2) / (cooyb - s2);     double dd1 = sqrt(cooxb * cooxb + (s1 - cooyb) * (s1 - cooyb)) * r / cooxb;     double dd2 = sqrt(cooxb * cooxb + (s2 - cooyb) * (s2 - cooyb)) * r / cooxb;     if (s1 - dd1 < s2 - r) {       if (s2 - dd2 < s2 - r) {         cout << -1;         return 0;       }       cout.precision(30);       cout << xx2;       return 0;     } else {       cout.precision(30);       cout << xx1;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long power(long long a, long long b) {     a = a % mod;     long long ans = 1;     while (b > 0) {       if (b % 2 == 1) {         ans = (ans * a) % mod;       }       b = b / 2;       a = (a * a) % mod;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long loc[n + 1];       long long a[n];       for (long long i = 0; i < n; i++) {         cin >> a[i];         loc[a[i]] = i;       }       map<long long, long long> p;       long long m = 0;       for (long long i = 1; i <= n; i++) {         for (long long j = loc[i]; j - 1 >= 0 && p[j - 1] == 0; j--) {           if (m > (n - 1)) {             break;           }           if (a[j - 1] > a[j]) {             swap(loc[a[j]], loc[a[j - 1]]);             swap(a[j], a[j - 1]);             p[j - 1]++;             m++;           } else {             break;           }         }       }       for (long long i = 0; i < n; i++) {         cout << a[i] <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 3e5 + 10;   long long ans;   long long n, k;   long long s[maxn];   long long l[maxn];   long long r[maxn];   long long seg[4 * maxn];   long long lazy[4 * maxn];   vector<long long> bois[maxn];   void in();   void solve();   long long doaz(long long);   long long get(long long, long long, long long, long long, long long);   void upd(long long, long long, long long, long long, long long);   void push(long long, long long, long long);   void out();   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     in();     solve();     out();   }   void in() {     cin >> n >> k;     for (long long i = 0; i < n; i++) cin >> s[i];     for (long long i = 0; i < k; i++) cin >> l[i] >> r[i];   }   void solve() {     sort(s, s + n);     for (long long i = 0; i < k; i++) {       l[i] = lower_bound(s, s + n, l[i]) - s;       r[i] = upper_bound(s, s + n, r[i]) - s;       bois[l[i]].push_back(i);       bois[r[i]].push_back(i);     }     for (long long i = 0; i < n; i++) {       l[k + i] = i;       r[k + i] = i + 1;       bois[i].push_back(k + i);     }     ans = n * (n - 1) * (n - 2) / 6;     for (long long i = 0; i < n; i++) {       for (auto j : bois[i]) upd(1, 0, n, l[j], r[j]);       ans -= doaz(get(1, 0, n, 0, n) - get(1, 0, n, i, i + 1));     }   }   long long get(long long id, long long l, long long r, long long L,                 long long R) {     if (r <= L || R <= l) return 0;     if (L <= l && r <= R) return seg[id];     if (lazy[id]) push(id, l, r);     long long mid = (l + r) >> 1;     return get(id << 1, l, mid, L, R) + get(id << 1 | 1, mid, r, L, R);   }   void upd(long long id, long long l, long long r, long long L, long long R) {     if (r <= L || R <= l) return;     if (L <= l && r <= R) {       seg[id] = r - l - seg[id];       lazy[id] = 1 - lazy[id];       return;     }     if (lazy[id]) push(id, l, r);     long long mid = (l + r) >> 1;     upd(id << 1, l, mid, L, R);     upd(id << 1 | 1, mid, r, L, R);     seg[id] = seg[id << 1] + seg[id << 1 | 1];   }   void push(long long id, long long l, long long r) {     long long mid = (l + r) >> 1;     lazy[id] = 0;     lazy[id << 1] = 1 - lazy[id << 1];     lazy[id << 1 | 1] = 1 - lazy[id << 1 | 1];     seg[id << 1] = mid - l - seg[id << 1];     seg[id << 1 | 1] = r - mid - seg[id << 1 | 1];   }   bool cmp(long long i, long long j) { return s[i] < s[j]; }   long long doaz(long long x) { return x * (x - 1) / 2; }   void out() { cout << ans; }
#include <bits/stdc++.h>   using namespace std;   void dbg() { std::cout <<    # n ; }   template <typename T, typename... Args>   void dbg(T a, Args... args) {     std::cout << a <<    ;     dbg(args...);   }   const long long maxn = 2e5 + 10;   const long long MAX = 1000;   const long long inf = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   long long n, d, m;   long long a[maxn];   long long b[maxn];   multiset<long long> small;   void solve() {     cin >> n >> d >> m;     for (long long i = (1); i <= (n); ++i) {       cin >> a[i];     }     sort(a + 1, a + 1 + n);     long long pos = upper_bound(a + 1, a + 1 + n, m) - a;     long long cans = 0;     long long ans = 0;     for (long long i = (1); i <= (pos - 1); ++i) small.insert(a[i]), cans += a[i];     long long forsmall = n - 1;     ans = max(cans, ans);     for (long long i = (1); i <= (n - pos + 1); ++i) {       if (forsmall < 0) break;       while (small.size() > forsmall) {         cans -= *small.begin();         small.erase(small.begin());       }       cans += a[n - i + 1];       ans = max(ans, cans);       forsmall -= (d + 1);     }     cout << (ans) << endl;   }   signed main() {     long long TestCase = 1;     while (TestCase--) {       solve();     }     char EndFile = getchar();     EndFile = getchar();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[101], n, imin = 0, imax = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> arr[i];       if (arr[i] == 1)         imin = i;       else if (arr[i] == n)         imax = i;     }     int a;     if (imax < imin) swap(imax, imin);     int rsp = abs(imin - imax) + max(n - imax, imin - 1);     cout << rsp;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cout << fixed;     setprecision(15);     double x, y;     cin >> n >> x >> y;     long long p1 = 0, p2 = 0, ans = 0;     set<double> s;     for (long long i = 0; i < n; i++) {       double a, b;       cin >> a >> b;       if (a == x) {         if (s.find((double)1e7) == s.end()) {           s.insert((double)1e7);         }         continue;       }       if (b == y) {         if (s.find((double)1e6) == s.end()) {           s.insert((double)1e6);         }         continue;       }       double slope = (double)(b - y) / (a - x);       if (s.find(slope) == s.end()) {         s.insert(slope);       }     }     cout << (long long)s.size() <<   n ;   }   signed main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     solve();   }
#include <bits/stdc++.h>   using namespace std;   int par[200010];   bool isLeaf[200010];   vector<int> adj[200010];   long long f[200010], dp[200010], s[200010], ans = 0, n;   void duyet(int u) {     s[u] = 1;     f[u] = 0;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (par[u] != v) {         par[v] = u;         duyet(v);         s[u] += s[v];         f[u] += f[v];       }     }     f[u] += s[u];   }   void cal(int u) {     long long tong = 0;     dp[u] = dp[par[u]] - 2 * s[u] + n;     ans = max(ans, dp[u]);     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (par[u] != v) {         cal(v);       }     }   }   void solve() {     cin >> n;     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       par[i] = 0;       adj[x].push_back(y);       adj[y].push_back(x);     }     par[n] = 0;     duyet(1);     dp[1] = f[1];     for (int i = 0; i < adj[1].size(); i++) {       int v = adj[1][i];       cal(v);     }     cout << ans << endl;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr long long maxn = 2e5 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7;   long long n, m, du[maxn], vis[maxn], f[maxn];   long long res, ans = 1;   vector<long long> e[maxn];   map<pair<long long, long long>, long long> mp;   inline long long ksm(long long a, long long b) {     long long k = 1;     while (b) {       if (b & 1) k = k * a % mod;       a = a * a % mod;       b >>= 1;     }     return k;   }   void topo() {     queue<long long> q;     for (long long i = 1; i <= n; i++) {       if (du[i] == 1) {         q.push(i);         vis[i] = i;       }     }     while (!q.empty()) {       long long u = q.front();       q.pop();       for (auto v : e[u]) {         du[v]--;         if (du[v] <= 1 && !vis[v]) {           vis[v] = v;           q.push(v);         }       }     }   }   void dfs(long long u, long long fa) {     vis[u] = fa;     f[fa]++;     for (auto v : e[u]) {       if (!vis[v] && du[v] > 1) {         dfs(v, fa);       }     }   }   signed main() {     cin >> n;     long long flag = 0;     for (long long i = 1; i <= n; i++) {       long long x;       cin >> x;       e[i].emplace_back(x);       e[x].emplace_back(i);       du[i]++;       du[x]++;     }     topo();     for (long long i = 1; i <= n; i++) {       if (!vis[i] && du[i] > 1) {         dfs(i, i);       }     }     for (long long i = 1; i <= n; i++) {       if (vis[i] == i && f[i] == 0) {         res++;       } else if (vis[i] == i && f[i] > 1) {         ans = ans * (ksm(2, f[i]) - 2) % mod;       }     }     cout << ans * ksm(2, res) % mod;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     long long int n, s, p, q;     char d;     map<long long int, long long int> p1, p2;     cin >> n >> s;     for (long long int i = 1; i <= n; i++) {       cin >> d >> p >> q;       if (d ==  B )         p1[p] += q;       else if (d ==  S )         p2[p] += q;     }     map<long long int, long long int>::reverse_iterator rit;     map<long long int, long long int>::iterator it;     vector<pair<long long int, long long int> > p3;     long long int cnt = 0;     for (it = p2.begin(); it != p2.end(); it++) {       if (cnt < s) {         p3.push_back(make_pair(it->first, it->second));         cnt++;       }     }     cnt = 0;     reverse(p3.begin(), p3.end());     vector<pair<long long int, long long int> >::iterator it2;     for (it2 = p3.begin(); it2 != p3.end(); ++it2) {       if (cnt < s) {         cout <<  S               <<     << it2->first <<     << it2->second << endl;         cnt++;       }     }     cnt = 0;     for (rit = p1.rbegin(); rit != p1.rend(); ++rit) {       if (cnt < s) {         cout <<  B               <<     << rit->first <<     << rit->second << endl;         cnt++;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[1005][1005];   int sum[1005][1005];   int mn = 1000000007, area = 0;   int X, Y, n, m;   int extend(int x, int y, int dx, int dy) {     int mx = 0;     if (x + dx <= n && y + dy - 1 <= m &&         sum[x + dx][y + dy - 1] - sum[x + dx][y - 1] - sum[x][y + dy - 1] +                 sum[x][y - 1] ==             dx * dy)       mx = dy + extend(x + 1, y, dx, dy);     else if (y + dy <= m && x + dx - 1 <= n &&              sum[x + dx - 1][y + dy] - sum[x + dx - 1][y] - sum[x - 1][y + dy] +                      sum[x - 1][y] ==                  dx * dy)       mx = dx + extend(x, y + 1, dx, dy);     return mx;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> (s[i] + 1);     int x, y;     for (x = 1; x <= n; x++) {       for (y = 1; y <= m; y++)         if (s[x][y] ==  X ) break;       if (y < m + 1) break;     }     X = x, Y = y;     int extX = 0, extY = 0;     for (int i = x; i <= n; i++)       if (s[i][y] ==  X ) extX++;     for (int i = y; i <= m; i++)       if (s[x][i] ==  X ) extY++;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         sum[i][j] = (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] +                      (s[i][j] ==  X )),         area += (s[i][j] ==  X );       }     for (int dx = 1; dx <= extX; dx++) {       if (dx * extY > mn) break;       if (sum[x + dx - 1][y + extY - 1] - sum[x + dx - 1][y - 1] -               sum[x - 1][y + extY - 1] + sum[x - 1][y - 1] ==           dx * extY) {         int dArea = dx * extY + extend(x, y, dx, extY);         if (dArea == area && dx * extY < mn) mn = dx * extY;       }     }     for (int dy = 1; dy <= extY; dy++) {       if (dy * extX > mn) break;       if (sum[x + extX - 1][y + dy - 1] - sum[x + extX - 1][y - 1] -               sum[x - 1][y + dy - 1] + sum[x - 1][y - 1] ==           extX * dy) {         int dArea = dy * extX + extend(x, y, extX, dy);         if (dArea == area && extX * dy < mn) mn = extX * dy;       }     }     if (mn == 1000000007)       cout <<  -1  << endl;     else       cout << mn << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, q;     cin >> n >> q;     set<int> s;     multiset<int> m;     auto add = [&](int x) {       auto it = s.insert(x).first;       if (next(it) != s.end() && it != s.begin())         m.erase(m.find(*next(it) - *prev(it)));       if (next(it) != s.end()) m.insert(*next(it) - x);       if (it != s.begin()) m.insert(x - *prev(it));     };     auto rm = [&](int x) {       s.erase(x);       auto it = s.lower_bound(x);       if (it != s.end()) m.erase(m.find(*it - x));       if (it != s.begin()) m.erase(m.find(x - *prev(it)));       if (it != s.end() && it != s.begin()) m.insert(*it - *prev(it));     };     for (int i = 0; i < n; i++) {       int x;       cin >> x;       add(x);     }     auto solve = [&]() -> long long {       if (s.size() <= 1)         return 0;       else         return (*s.rbegin() - *s.begin() - *m.rbegin());     };     cout << solve() <<   n ;     while (q--) {       int t, x;       cin >> t >> x;       if (t == 0)         rm(x);       else         add(x);       cout << solve() <<   n ;     }     return 0;   }
// author: sharad12arse   #include<bits/stdc++.h>   using namespace std;      #define ll long long   #define ull unsigned long long   #define gcd __gcd   #define INF LONG_LONG_MAX      void solve(){    int n;    cin>>n;    ll a1=0,a2=0,x=0;    vector<ll> arr(n);    for(int i=0;i<n;i++){     cin>>arr[i];     x^=arr[i];    }    a2=x;    for(int i=0;i<n-1;i++){     a1^=arr[i];     a2^=arr[i];     if(a1==a2){      cout<< YES n ;      return;     }    }    a1=0,a2=0;    for(int i=0;i<n-1;i++){     a1^=arr[i];     a2=0;     for(int j=n-1;j>i;j--){      a2^=arr[j];      if(a1==a2&&((x^a1)^a2)==a1){       cout<< YES n ;       return;      }     }    }    cout<< NO n ;   }      int main(){    ios_base::sync_with_stdio(0);    cin.tie(0);    int t=1;    cin>>t;    while(t--){     solve();    }   }