malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <class T>   T gcd(T a, T b) {     T r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class T>   int getbit(T s, int i) {     return (s >> i) & 1;   }   template <class T>   T onbit(T s, int i) {     return s | (T(1) << i);   }   template <class T>   T offbit(T s, int i) {     return s & (~(T(1) << i));   }   const double PI = 2 * acos(0.0);   const double eps = 1e-9;   const int infi = (1 << 31) - 1;   const long long Linfi = (long long)1e18;   const int MOD = 1000000007;   int n, cnt = 0;   int a[110005], p[110005], u[110005], vitri[110005];   vector<pair<int, int> > ans;   void sang(int n) {     memset(p, 0, sizeof(p));     for (int i = 2; i <= sqrt(n); i++) {       if (p[i] == 0) {         for (int j = i * i; j <= n; j += i) p[j] = 1;       }     }     for (int i = 2; i <= n; i++)       if (p[i] == 0) u[++cnt] = i - 1;   }   void solve() {     for (int i = 1; i <= n; i++) {       int pos = vitri[i];       if (pos == i) continue;       int delta = pos - i;       int tmp = lower_bound(u + 1, u + cnt + 1, delta) - u;       if (u[tmp] > delta) tmp--;       int x = u[tmp];       int k = pos - x;       swap(a[k], a[pos]);       ans.push_back(make_pair(k, pos));       swap(vitri[a[k]], vitri[a[pos]]);       while (k > i) {         while (u[tmp] > k - i) tmp--;         x = u[tmp];         if (x == 0) break;         swap(a[k], a[k - x]);         ans.push_back(make_pair(k - x, k));         swap(vitri[a[k]], vitri[a[k - x]]);         k -= x;         if (k == i) break;         if (ans.size() >= 500000) return;       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       printf( %d %d n , ans[i].first, ans[i].second);     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       vitri[a[i]] = i;     }     sang(110001);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[3005];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     int ans = 0;     for (int i = 1; i < n; i++) {       for (int j = 0; j < i; j++) {         if (a[i] < a[j]) {           ans++;         }       }     }     if (ans & 1)       ans = (ans << 1) - 1;     else       ans <<= 1;     printf( %.6f n , (double)ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long n, a, b;       cin >> n >> a >> b;       long long dp[4][n + 1];       string s;       cin >> s;       vector<long long> v(n + 1, 0);       for (long long i = 1; i <= n; i++)         if (s[i - 1] ==  1 ) v[i] = 1;       dp[0][0] = dp[1][0] = dp[2][0] = dp[3][0] = b;       for (long long i = 1; i <= n; i++) {         if (i == 1) {           dp[0][i] = dp[0][0] + a + b;           dp[1][i] = dp[0][0] + 2 * a + 2 * b;           continue;         }         if (v[i] && v[i - 1])           dp[0][i] = dp[1][i] = dp[1][i - 1] + a + 2 * b;         else if (v[i] && !v[i - 1]) {           dp[0][i] = dp[1][i] =               min(dp[1][i - 1], dp[0][i - 2] + 2 * a + 2 * b) + a + 2 * b;         } else if (!v[i] && !v[i - 1]) {           dp[0][i] = min(dp[0][i - 1], dp[1][i - 1] + a) + b + a;           dp[1][i] = min(dp[1][i - 1] + a, dp[0][i - 1] + 2 * a) + 2 * b;         } else if (!v[i] && v[i - 1]) {           dp[0][i] = dp[1][i - 1] + 2 * a + b;           dp[1][i] = dp[1][i - 1] + 2 * b + a;         }       }       cout << dp[0][n] << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   int main() {     int n;     cin >> n;     vector<vector<int> > xy(n, vector<int>(2));     for (int i = 0; i < n; i++) {       cin >> xy[i][0] >> xy[i][1];     }     int k = 0;     for (int i = 0; i < n - 2; i++) {       if (xy[i][0] == xy[i + 1][0]) {         if (xy[i][1] < xy[i + 1][1]) {           if (xy[i + 1][0] > xy[i + 2][0]) k++;         }         if (xy[i][1] > xy[i + 1][1]) {           if (xy[i + 1][0] < xy[i + 2][0]) k++;         }       }       if (xy[i][1] == xy[i + 1][1]) {         if (xy[i][0] < xy[i + 1][0]) {           if (xy[i + 1][1] < xy[i + 2][1]) k++;         }         if (xy[i][0] > xy[i + 1][0]) {           if (xy[i + 1][1] > xy[i + 2][1]) k++;         }       }     }     cout << k;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = int(1e5) + 5;   const int INF = int(1e9) + 7;   const long long MINF = 1e18;   vector<int> g[N];   set<int> x;   int a[N];   int b[N];   vector<int> ans;   void solve() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       int l, r;       cin >> l >> r;       g[l].push_back(r);       g[r].push_back(l);     }     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] == 0) {         x.insert(i);       }     }     int kol = 0;     while (x.size() != 0) {       int num = *x.begin();       x.erase(num);       ans.push_back(num);       kol++;       b[num]++;       int v = num;       for (int i = 0; i < g[v].size(); i++) {         if (b[g[v][i]] == a[g[v][i]]) {           b[g[v][i]]++;           x.erase(g[v][i]);         } else {           b[g[v][i]]++;           if (b[g[v][i]] == a[g[v][i]]) {             x.insert(g[v][i]);           }         }       }       if (kol == n && x.size() != 0) {         cout << -1;         return;       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(0);     int TT = 1;     while (TT--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1 << 24;   int n, f[MAXN], Tohka;   bool p[MAXN];   int lowbit(int first) { return first & -first; }   int main() {     cin >> n;     char str[4];     for (int i = 1; i <= n; ++i) {       scanf( %s , str);       int s = 0;       for (int j = 0; j < 3; ++j) s |= 1 << (str[j] -  a );       ++f[s];     }     for (int i = 0; i < 24; ++i)       for (int j = 1; j < MAXN; ++j)         if (!(j & (1 << i))) f[j] += f[j + (1 << i)];     p[0] = 0;     for (int i = 1; i < MAXN; ++i)       p[i] = p[i - lowbit(i)] ^ 1, f[i] *= (p[i]) ? 1 : -1;     for (int i = 0; i < 24; ++i)       for (int j = MAXN - 1; j >= 0; --j)         if (j & (1 << i)) f[j] += f[j - (1 << i)];     for (int i = 0; i < MAXN; ++i) Tohka ^= f[i] * f[i];     cout << Tohka << endl;     fclose(stdin);     fclose(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     for (int x = 0; x < T; x++) {       vector<long long> arry(7);       for (int i = 0; i < 7; i++) cin >> arry[i];       long long least, all_sum;       all_sum = arry[6];       least = arry[0];       vector<long long> a(3);       a[0] = least;       long long ab = all_sum - least;       a[1] = arry[1];       a[2] = all_sum - a[1] - a[0];       cout << a[0] <<     << a[1] <<     << a[2] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const double PI =       3.14159265358979323846264338327950288419716939937510582097494459230;   struct debugger {     static void call(const char *arg) {}     template <typename T, typename... aT>     static void call(const char *it, T a, aT... rest) {       string b;       for (; *it && (*it) !=  , ; it++) {         b += *it;       }       cerr << b <<   =   << a <<    ;       call(++it, rest...);     }   };   int main() {     int n, b, m;     cin >> n >> b;     int ar[n];     m = b;     for (int i = 0; i < (n); i++) {       cin >> ar[i];     }     for (int i = 0; i < (n); i++) {       int c = b / ar[i], r = b % ar[i];       for (int j = (i + 1); j < (n); j++) {         int w = ar[j] * c;         w = w + r;         m = max(w, m);       }     }     cout << m;   }
#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int x, long long int y) {     if (x < y) swap(x, y);     if (x % y == 0) return y;     return gcd(y, x % y);   }   long long int pwm(long long int a, long long int n) {     long long int ans = 1;     while (n > 0) {       if (n % 2 == 1) {         ans = (ans * a) % 1000000007;       }       a = (a * a) % 1000000007;       n /= 2;     }     return ans % 1000000007;   }   const int pwn = 100010;   long long int pw[pwn];   void pwtwo() {     pw[0] = 1;     for (int i = 1; i < pwn; i++) {       pw[i] = (pw[i - 1] * 2) % 1000000007;     }   }   long long int gcdExtended(long long int a, long long int b, long long int *x,                             long long int *y);   long long int modInverse(long long int a, long long int m) {     if (a == 1) return 1;     long long int x, y;     long long int g = gcdExtended(a, m, &x, &y);     if (g != 1) {       return -1;     } else {       long long int res = (x % m + m) % m;       return res;     }   }   long long int gcdExtended(long long int a, long long int b, long long int *x,                             long long int *y) {     if (a == 0) {       *x = 0, *y = 1;       return b;     }     long long int x1, y1;     long long int gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   long long int fact[1010];   long long int init() {     fact[0] = 1;     for (int i = 1; i < 1010; i++) fact[i] = (fact[i - 1] * i) % 1000000007;   }   long long int ncr(long long int n, long long int r) {     long long int ans = fact[n];     ans = (ans * modInverse(fact[r], 1000000007)) % 1000000007;     ans = (ans * modInverse(fact[n - r], 1000000007)) % 1000000007;     return ans;   }   long long int t[42];   bool check(int x) {     for (int i = 1; i <= 40; i++) {       if (x == t[i] - 1) return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int a, b;     cin >> a >> b;     if (a == 1 || b == 1) {       cout << 0 << endl;       return 0;     }     if (a == b) {       cout << 0 << endl;       return 0;     }     long long int x = abs(b - a);     long long int ans = a * b;     ans = ans / gcd(a, b);     long long int c = 0;     for (int i = 1; i <= sqrt(x); i++) {       if ((x % i) == 0) {         long long int y = a % i;         y = (i - y) % i;         long long int k = (a + y) * (b + y);         k = k / gcd(a + y, b + y);         if (ans > k) {           ans = k;           c = y;         }         int z = x / i;         y = a % z;         y = (z - y) % z;         k = (a + y) * (b + y);         k = k / gcd(a + y, b + y);         if (ans > k) {           ans = k;           c = y;         }       }     }     cout << c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e7 + 9, MAXN = 1e6;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     unsigned long long int k, x;     cin >> n;     while (n--) {       cin >> k >> x;       cout << x + 9 * (k - 1) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int tree[1000000 + 5], a[1000000 + 5], data[1000000 + 5], rear, sum;   int lowbit(int x) { return (x & -x); }   void modify(int x, int value) {     for (int i = x; i <= 1000000; i += lowbit(i)) tree[i] += value;     return;   }   int query(int x) {     int sum = 0;     for (int i = x; i; i -= lowbit(i)) sum += tree[i];     return sum;   }   void del(int rear, int x) {     int l = 1, r = rear, mid;     while (l < r) {       mid = (l + r) / 2;       if (query(mid) < x)         l = mid + 1;       else         r = mid;     }     modify(l, -1);     data[l] = -1;     return;   }   int main() {     int n, m, i, j, ch;     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) scanf( %d , &a[i]);     a[i] = 1000005;     for (i = 1; i <= n; i++) {       scanf( %d , &ch);       if (ch == -1) {         for (j = 1; a[j] <= sum; j++) del(rear, a[j] - j + 1);         sum -= (j - 1);       } else {         modify(++rear, 1);         data[rear] = ch;         sum++;       }     }     if (!sum)       printf( Poor stack! n );     else {       for (i = 1; i <= rear; i++)         if (data[i] != -1) printf( %d , data[i]);       printf(  n );     }     return 0;   }
#include <iostream>   #include <bits/stdc++.h>   using namespace std;      #define int long long       void solve(){      // int n;       //cin>>n;              /*int a[n];       for(int i=0;i<n;i++)       cin>>a[i]; */       string s;       cin>>s;       int n=s.length();              cout << n << endl;         }      int32_t main() {          ios_base::sync_with_stdio(false);       cin.tie(NULL);              int t;       cin>>t;       while(t){           t--;        solve();               }                 }
#include <bits/stdc++.h>   using namespace std;   string st;   int main() {     cin >> st;     char q[11] = { A ,  I ,  O ,  M ,  H ,  U ,  V ,  W ,  X ,  Y ,  T };     set<char> s(q, q + 11);     for (long long i = 0; i < st.size() / 2 + 1; i++) {       if (st[i] != st[st.size() - i - 1] || s.count(st[i]) == 0) {         cout <<  NO ;         return 0;       }     }     if (st.size() == 1) {       if (s.count(st[0]) == 0) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n, sum = 0;       cin >> n;       for (int i = 0; i < 60; i++) {         long long x = 1LL << i;         if (n & x) {           sum += (1LL << (i + 1)) - 1;         }       }       cout << sum << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, q, a, b, x, y, i = 1, j, p[150000], mas[150005];   pair<int, int> m[10];   int main() {     cin >> n >> k >> q;     while (i <= n) {       cin >> p[i];       i++;     }     i = 0;     while (i < q) {       cin >> a >> b;       if (a == 1) {         if (p[b] > m[k - 1].first) {           mas[m[k - 1].second] = 0;           mas[b] = 1;           m[k - 1].first = p[b];           m[k - 1].second = b;           sort(m, m + k);           reverse(m, m + k);         }       }       if (a == 2) {         if (mas[b] == 0) {           cout <<  NO  << endl;         } else {           cout <<  YES  << endl;         }       }       i++;     }   }
#include <bits/stdc++.h>   using namespace std;   void chmax(int& a, int b) { a = max(a, b); }   void chmin(int& a, int b) { a = min(a, b); }   int nth_bit(int64_t num, int n) { return (num >> n) & 1; }   int main() {     string S;     int X;     cin >> S >> X;     int N = S.size();     vector<int> A(N);     for (int i = 0; i < N; i++) A[i] = S[i] -  0 ;     vector<int> ds;     for (int i = 1; i < X; i++)       if (X % i == 0) ds.push_back(i);     if (X == 1) {       cout << count(A.begin(), A.end(), 1) << endl;       return 0;     }     int B = 1 << (X + 1);     vector<int> valid;     for (int b = 0; b < B; b++) {       bool ok = true;       for (int i = 0; i < X; i++)         if (nth_bit(b, i) && nth_bit(b, i + 1)) ok = false;       if (ok) valid.push_back(b);     }     vector<bool> ok(B);     for (int b = 0; b < B; b++) {       if (nth_bit(b, X) == 0) ok[b] = true;       for (int d : ds)         for (int i = 0; i < X; i++)           if (nth_bit(b, i) && nth_bit(b, i + d)) ok[b] = true;     }     vector<int> dp(B), dp2(B);     auto solve = [&](vector<int>& V) -> int {       int N = V.size();       for (int b : valid) dp[b] = 1e9;       dp[1] = 0;       for (int i = 0; i < N; i++) {         for (int b : valid) dp2[b] = dp[b] + 1;         for (int b : valid) {           int b2 = ((b << V[i]) | 1) & (B - 1);           if (ok[b2]) chmin(dp2[b2], dp[b]);         }         for (int b : valid) dp[b] = dp2[b];       }       int ans = 1e9;       for (int b : valid) chmin(ans, dp[b]);       return ans;     };     int ans = 0;     vector<int> V;     for (int i = 0; i < N; i++) {       if (A[i] == 1) {         if (V.size()) ans += solve(V);         V.clear();       } else {         V.push_back(A[i]);       }     }     if (V.size()) ans += solve(V);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long C[4005][4005];   const int mod = 998244853;   long long dp[2005][2005];   void norm(long long& x) {     while (x < 0) x += mod;     while (x >= mod) x -= mod;   }   int main() {     int n, m;     cin >> n >> m;     C[1][0] = 1;     C[1][1] = 1;     for (int i = 2; i <= (n + m); i++) {       C[i][0] = 1;       for (int j = 1; j <= i; j++) {         C[i][j] = C[i - 1][j] + C[i - 1][j - 1];         norm(C[i][j]);       }     }     for (int i = 1; i <= n; i++) {       dp[i][0] = i;       for (int j = 1; j <= m; j++) {         dp[i][j] = dp[i - 1][j] + C[i - 1 + j][j];         norm(dp[i][j]);         dp[i][j] += dp[i][j - 1] - C[i - 1 + j][i];         norm(dp[i][j]);         if (i <= j - 1)           dp[i][j] += C[i + j - 1][j - 1] - C[i + j - 1][j], norm(dp[i][j]);       }     }     cout << dp[n][m];   }
#include <bits/stdc++.h>   using namespace std;   int n, arr[100005], has[100005], t;   vector<int> v[100005];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       int a;       cin >> a;       arr[a]++;       has[i] = arr[a];       v[has[i]].push_back(a);       t = max(t, has[i]);     }     for (int i = 0; i < 100000; i++) {       int p = v[i].size();       if (p != 0) {         int tmp = 0;         for (int j = 0; j < p; j++) {           tmp += v[i][j];         }         if (tmp != ((p * (p + 1)) / 2)) {           cout <<  -1  << endl;           return 0;         }       }     }     cout << t << endl;     for (int i = 1; i <= n; i++) cout << has[i] <<    ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void _R(T &x) {     cin >> x;   }   void _R(int &x) { scanf( %d , &x); }   void _R(long long &x) { scanf( %  PRId64, &x); }   void _R(double &x) { scanf( %lf , &x); }   void _R(char &x) { scanf(  %c , &x); }   void _R(char *x) { scanf( %s , x); }   void R() {}   template <typename T, typename... U>   void R(T &head, U &...tail) {     _R(head);     R(tail...);   }   template <typename T>   void _W(const T &x) {     cout << x;   }   void _W(const int &x) { printf( %d , x); }   template <typename T>   void _W(const vector<T> &x) {     for (auto i = x.cbegin(); i != x.cend(); i++) {       if (i != x.cbegin()) putchar(   );       _W(*i);     }   }   void W() {}   template <typename T, typename... U>   void W(const T &head, const U &...tail) {     _W(head);     putchar(sizeof...(tail) ?     :   n );     W(tail...);   }   int ans;   inline void chkmax(int &a, int b) {     if (b > ans) ans = b;     if (b > a) a = b;   }   const int N = 1010;   const int K = 11;   int n, m, k, dp[K][N][N][2];   char a[N], b[N];   int main() {     memset(dp, -1, sizeof(dp));     dp[0][0][0][0] = 0;     R(n, m, k, a, b);     for (int i = (0); i <= int(k); i++)       for (int x = 0; x < int(n); x++)         for (int y = 0; y < int(m); y++)           for (int j = 0; j < int(2); j++) {             int me = dp[i][x][y][j];             if (me == -1) continue;             chkmax(dp[i][x + 1][y][0], me);             chkmax(dp[i][x][y + 1][0], me);             if (a[x] == b[y]) {               int ni = i + (j == 0);               if (ni <= k) chkmax(dp[i + (j == 0)][x + 1][y + 1][1], me + 1);             }           }     W(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;      //.define   // #define FILE_IN_OUT   #define RET(_x) cout << (_x) <<   n ; return;   #define all(_obj) (_obj).begin(), (_obj).end()   #define loop(_n) for (int i = 0; i < (_n); ++i)   #define sz(_obj) static_cast<int>((_obj).size())   #ifdef SHJ_LOCAL   #define debug(_x) std::cerr << (#_x) <<   =   << (_x) <<   n  << std::flush;   #else   #define debug(_x) {}   #endif   #define endl   n    template <typename P, typename Q>   P CeilDiv(P _dividend, Q _divider) {       return static_cast<P>((_dividend - 1LL + _divider) / _divider);   }   template <typename Tp>   inline void outarr(Tp _begin, Tp _end, const char* _delim =    ) {       for (Tp current = _begin; current != _end; ++current) {           std::cout << *current << _delim;       }       std::cout <<   n ;   }      //.constant   using ll = int64_t;   using pii = std::pair<int, int>;   constexpr int INF = 0x3f3f3f3f;   constexpr int MOD = static_cast<int>(1e9 + 7);      //.data   bool Ask(int l1, int r1, int l2, int r2) {       cout <<  ?   << r1 - l1 + 1 <<     << r2 - l2 + 1 << endl;       for (int i = l1; i <= r1; ++i) {           cout << i <<    ;       }       cout << endl;       for (int i = l2; i <= r2; ++i) {           cout << i <<    ;       }       cout << endl << flush;       int res;       cin >> res;       return res;   }      //.code   void SolveTask() {       int n;       cin >> n;       int j = -1;       for (int i = 2; i <= n; ++i) {           if (Ask(1, i - 1, i, i)) {               j = i;               break;           }       }       vector<int> ans;       for (int i = j + 1; i <= n; ++i) {           if (!Ask(j, j, i, i)) {               ans.push_back(i);           }       }       int l = 1;       int r = j - 1;       while (l <= r) {           int mid = (l + r) >> 1;           if (Ask(1, mid, j, j)) {               r = mid - 1;           } else {               l = mid + 1;           }       }       for (int i = 1; i <= r; ++i) {           ans.push_back(i);       }       for (int i = r + 2; i < j; ++i) {           ans.push_back(i);       }       cout <<  !   << sz(ans) <<    ;       outarr(all(ans));       cout << flush;   }      int main() {   #ifdef FILE_IN_OUT       std::ifstream cin( input.txt , std::ios::in);       std::ofstream cout( output.txt , std::ios::out);   #else       std::ios_base::sync_with_stdio(false);       std::cin.tie(nullptr);   #endif       int test_cases = 1;       cin >> test_cases;       for (int yt = 1; yt <= test_cases; ++yt) {           SolveTask();       }   #ifdef FILE_IN_OUT       cin.close();       cout.close();   #endif       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 5e3 + 10;   int a[M];   int dp[M][M];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , a + i), dp[i][i] = a[i];     for (int d = 1; d < n; d++) {       for (int i = 1; i + d <= n; i++) {         int j = i + d;         dp[i][j] = dp[i][j - 1] ^ dp[i + 1][j];       }     }     for (int d = 1; d < n; d++) {       for (int i = 1; i + d <= n; i++) {         int j = i + d;         dp[i][j] = max({dp[i][j], dp[i + 1][j], dp[i][j - 1]});       }     }     int q, l, r;     scanf( %d , &q);     while (q--) {       scanf( %d%d , &l, &r);       printf( %d n , dp[l][r]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long eps = 1e9 + 7;   const double inf = 1e-12;   bool F(set<pair<int, int> > &a) {     pair<int, int> p = *a.rbegin();     a.erase(p);     --p.first;     if (p.first != 0) {       a.insert(p);     }     if (!a.empty() && a.rbegin()->first == a.begin()->first) {       if (p.first != 0) {         a.erase(p);       }       ++p.first;       a.insert(p);       return true;     }     if (p.first != 0) {       a.erase(p);     }     ++p.first;     a.insert(p);     p = *a.begin();     a.erase(p);     --p.first;     if (p.first != 0) {       a.insert(p);     }     if (!a.empty() && a.rbegin()->first == a.begin()->first) {       if (p.first != 0) {         a.erase(p);       }       ++p.first;       a.insert(p);       return true;     }     if (p.first != 0) {       a.erase(p);     }     ++p.first;     a.insert(p);     return false;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     set<pair<int, int> > a;     vector<int> b(1e5 + 5);     int max1 = 1;     for (int i = 1; i <= n; ++i) {       int first;       cin >> first;       a.erase(pair<int, int>(b[first], first));       ++b[first];       a.insert(pair<int, int>(b[first], first));       if (F(a)) {         max1 = i;       }     }     cout << max1;     return 0;   }