malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int dp[2][1005][55][55], a[1005], b[1005];   int mx(int x) { return max(0, x); };   int main() {     int n, p, k;     scanf( %d %d %d , &n, &p, &k);     if (p > 2 * (n + k - 1) / k) {       p = 2 * (n + k - 1) / k;     }     int z1;     scanf( %d , &z1);     for (int i = 1; i <= z1; i++) {       int x;       scanf( %d , &x);       a[x] = 1;     }     int z2;     scanf( %d , &z2);     for (int i = 1; i <= z2; i++) {       int x;       scanf( %d , &x);       b[x] = 1;     }     memset(dp, -0x3f, sizeof(dp));     dp[0][0][0][0] = 0;     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= p; j++) {         for (int x = 0; x < k; x++) {           for (int y = 0; y < k; y++) {             dp[i % 2][j + 1][k - 1][mx(y - 1)] =                 max(dp[i % 2][j + 1][k - 1][mx(y - 1)],                     dp[(i + 1) % 2][j][x][y] + (a[i] || (y && b[i])));             dp[i % 2][j + 1][mx(x - 1)][k - 1] =                 max(dp[i % 2][j + 1][mx(x - 1)][k - 1],                     dp[(i + 1) % 2][j][x][y] + (b[i] || (x && a[i])));             dp[i % 2][j][mx(x - 1)][mx(y - 1)] =                 max(dp[i % 2][j][mx(x - 1)][mx(y - 1)],                     dp[(i + 1) % 2][j][x][y] + ((a[i] && x) || (b[i] && y)));           }         }       }       memset(dp[(i + 1) % 2], -0x3f, sizeof(dp[(i + 1) % 2]));     }     int res = 0;     for (int j = 0; j <= p; j++) {       for (int x = 0; x < k; x++) {         for (int y = 0; y < k; y++) {           res = max(res, dp[n % 2][j][x][y]);         }       }     }     printf( %d n , res);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     long long q;     cin >> q;     while (q--) {       long long l1, r1, l2, r2;       cin >> l1 >> r1 >> l2 >> r2;       if (l1 == l2) {         cout << l1 <<     << r2 <<   n ;         continue;       }       if (l1 == r2) {         cout << l1 <<     << l2 <<   n ;         continue;       }       if (r1 == l2) {         cout << r1 <<     << r2 <<   n ;         continue;       }       if (r2 == r1) {         cout << r1 <<     << l2 <<   n ;         continue;       }       cout << l1 <<     << l2 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 9;   int n, m, a, b, k;   char s[100005];   long long ans, q;   inline long long f(char a) { return a ==  -  ? -1 : 1; }   inline long long fpow(long long a, long long b) {     long long r = 1;     for (; b; b >>= 1, a = (a * a) % M)       if (b & 1) r = (r * a) % M;     return r;   }   inline long long sum(long long a1, long long q, long long n) {     if (q == 1) return a1 * n % M;     long long p = (fpow(q, n) - 1 + M) % M;     long long qq = (q - 1 + M) % M;     qq = fpow(qq, M - 2);     return a1 * p % M * qq % M;   }   int main() {     scanf( %d %d %d %d , &n, &a, &b, &k);     q = b * fpow(a, M - 2) % M;     q = fpow(q, k);     m = (n + 1) / k;     scanf( %s , s);     if (n < k) {       for (int i = 0; i <= n; i++) {         long long t = fpow(a, n - i) * fpow(b, i) % M;         if (s[i] ==  - ) t = M - t;         (ans += t) %= M;       }       return printf( %lld n , ans), 0;     }     for (int i = 0; i < k; i++) {       long long x = sum(fpow(a, n - i) * fpow(b, i) % M, q, m);       if (s[i] ==  - ) x = M - x;       (ans += x) %= M;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   int n, a[105], ans;   int comp(const void* elem1, const void* elem2) {     int f = *((int*)elem1);     int s = *((int*)elem2);     if (f > s) return 1;     if (f < s) return -1;     return 0;   }   int main(int argc, char* argv[]) {     scanf( %d , &n);     int i;     for (i = 0; i < n; ++i) {       int HH, MM;       scanf( %d:%d , &HH, &MM);       a[i] = HH * 60 + MM;     }     qsort(a, n, sizeof(a[0]), comp);     ans = 0;     for (i = 0; i < n - 1; ++i) {       if (a[i + 1] - a[i] > ans) {         ans = a[i + 1] - a[i];       }     }     if (a[0] + 24 * 60 - a[n - 1] > ans) {       ans = a[0] + 24 * 60 - a[n - 1];     }     ans--;     int d1, d2;     d1 = ans / 60;     d2 = ans % 60;     if (d1 < 10) {       if (d2 < 10) {         printf( 0%d:0%d n , d1, d2);       } else {         printf( 0%d:%d n , d1, d2);       }     } else {       if (d2 < 10) {         printf( %d:0%d n , d1, d2);       } else {         printf( %d:%d n , d1, d2);       }     }     return 0;   }
#include <bits/stdc++.h>   const int maxn = 100100;   const int bl = 512;   static const int N = 600;   int n, k, q;   int s[maxn];   struct block {     int pop[N], c0;     int push[N], c1;     int ok;   } o[maxn / bl + 10];   inline int eql(const int *a, const int *b, const int len) {     for (int i = 0; i < len; ++i) {       if (a[i] != b[i]) return 0;     }     return 1;   }   inline bool ask(int l, int r) {     static int st[maxn];     int top = 0;     for (; l % bl && l <= r; ++l)       if (s[l] > 0) {         st[++top] = s[l];       } else {         if (!top || st[top] != -s[l]) return 0;         --top;       };     for (; l + bl - 1 <= r; l += bl) {       block &o = ::o[l / bl];       if (!o.ok) return 0;       if (top < o.c0) return 0;       if (!eql(st + top - o.c0 + 1, o.pop + N - o.c0, o.c0)) return 0;       top -= o.c0;       memcpy(st + top + 1, o.push + 1, o.c1 << 2);       top += o.c1;     }     for (; l <= r; ++l)       if (s[l] > 0) {         st[++top] = s[l];       } else {         if (!top || st[top] != -s[l]) return 0;         --top;       };     return top == 0;   }   inline void init(int id) {     block &o = ::o[id];     o.c0 = o.c1 = 0;     o.ok = 1;     int top = 0;     const int L = id * bl, R = std::min(n - 1, id * bl + bl - 1);     for (int i = L; i <= R; ++i) {       if (s[i] > 0) {         o.push[++top] = s[i];       } else {         if (top && o.push[top] != -s[i]) {           o.ok = 0;           return;         } else {           if (top) {             --top;           } else {             o.pop[N - ++o.c0] = -s[i];           }         }       }     }     o.c1 = top;   }   int main() {     std::ios::sync_with_stdio(false), std::cin.tie(0);     std::cin >> n >> k;     for (int i = 0; i < n; ++i) {       std::cin >> s[i];     }     for (int i = 0; i <= (n - 1) / bl; ++i) init(i);     std::cin >> q;     for (int i = 0; i < q; ++i) {       int opt, pos, v, l, r;       std::cin >> opt;       if (opt == 1) {         std::cin >> pos;         --pos;         std::cin >> s[pos];         init(pos / bl);       } else {         std::cin >> l >> r;         std::cout << (ask(l - 1, r - 1) ?  Yes  :  No ) <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   int main() {     int n, k;     cin >> n >> k;     set<char> st;     string s;     cin >> s;     for (int i = 0; i < n; ++i) st.insert(s[i]);     int res = 0;     char lastc = 0;     int i;     for (i = 0; i < k && !st.empty(); ++i) {       auto it = st.begin();       char c = *it;       st.erase(it);       if (*it - lastc < 2)         --i;       else {         res += int(c -  a  + 1);         lastc = c;       }     }     if (i == k)       cout << res <<   n ;     else       cout << -1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   const int N = 1000001;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     vector<pair<int, int>> a[n + 1];     int ans = 0;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       a[u].push_back(make_pair(v, i + 1));       a[v].push_back(make_pair(u, i + 1));       ans = max({ans, (int)a[u].size(), (int)a[v].size()});     }     cout << ans <<   n ;     int final[n], vis[n + 1];     memset(final, -1, sizeof final);     memset(vis, 0, sizeof vis);     queue<int> q;     q.push(1);     vis[1] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       map<int, int> d;       for (auto [v, ind] : a[u]) {         d[final[ind]] = 1;       }       int day = 1;       for (auto [v, ind] : a[u]) {         if (final[ind] == -1) {           while (d[day]) {             ++day;           }           final[ind] = day++;         }         if (vis[v] == 0) {           vis[v] = 1;           q.push(v);         }       }     }     vector<int> f1[ans + 1];     for (int i = 1; i < n; i++) {       f1[final[i]].push_back(i);     }     for (int i = 1; i < ans + 1; i++) {       cout << f1[i].size() <<    ;       for (int e : f1[i]) {         cout << e <<    ;       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   struct column {     int a[13];     int x;   };   column c[2001];   bool cmp(column p, column q) { return p.x > q.x; }   int s[13][4096], f[13][4096];   int mian() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) scanf( %d , &c[j].a[i]);     for (int j = 1; j <= m; j++) {       c[j].x = 0;       for (int i = 1; i <= n; i++) c[j].x = max(c[j].x, c[j].a[i]);     }     sort(c + 1, c + 1 + m, cmp);     m = min(m, n);     for (int i = 1; i <= m; i++)       for (int j = 0; j < (1 << n); j++) {         s[i][j] = 0;         for (int p = 0; p < n; p++) {           int sum = 0;           for (int l = 1, k = p + 1; l <= n; l++, k = (k == n) ? 1 : (k + 1))             if (j & (1 << l - 1)) sum += c[i].a[k];           s[i][j] = max(s[i][j], sum);         }       }     for (int i = 1; i <= m; i++)       for (int j = 0; j < (1 << n); j++) {         f[i][j] = f[i - 1][j];         for (int k = j; k; k = (k - 1) & j)           f[i][j] = max(f[i][j], f[i - 1][j ^ k] + s[i][k]);       }     printf( %d n , f[m][(1 << n) - 1]);     return 0;   }   int t;   int main() {     for (scanf( %d , &t); t; t--) mian();     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   template <class T1, class T2>   ostream &operator<<(ostream &os, const pair<T1, T2> &p) {     os <<  {  << p.first <<  ,  << p.second <<  } ;     return os;   }   const int N = 1e6 + 5;   const long long oo = 998244353;   long long fact[N];   long long fact_inv[N];   long long extended_euclidean(long long a, long long b, long long &x,                                long long &y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long d = extended_euclidean(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return d;   }   long long mod_inverse(long long a, long long m) {     long long x, y;     long long g = extended_euclidean(a, m, x, y);     if (g != 1) {       cout <<  No solution! ;       return -1;     } else {       x = (x % m + m) % m;       return x;     }   }   long long ncr(int n, int r) {     return n < r ? 0                  : ((1LL * fact[n] % oo * fact_inv[r] % oo) % oo *                     fact_inv[n - r]) %                        oo;   }   void pre(int N) {     fact[0] = 1;     for (long long i = 1; i < N; i++) {       fact[i] = (i * fact[i - 1]) % oo;     }     fact_inv[N - 1] = mod_inverse(fact[N - 1], oo);     for (long long i = N - 2; i >= 0; i--) {       fact_inv[i] = (i + 1LL) * fact_inv[i + 1] % oo;     }   }   long long bigmod(long long a, long long p, long long m) {     long long res = 1;     long long x = a;     while (p) {       if (p & 1) {         res = (res * x) % m;       }       x = (x * x) % m;       p = p >> 1;     }     return res;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     pre(N);     int n;     cin >> n;     int a = 0, b = 0;     int totww = 0, totwb = 0;     int totbb = 0, totbw = 0;     int tot__ = 0;     while (n--) {       string s;       cin >> s;       if (s ==  WW )         a++;       else if (s ==  W?  or s ==  ?W )         b++;       else if (s ==  B?  or s ==  ?B )         a--, b++;       else if (s ==  BB )         a--;       else if (s ==  ?? )         b += 2, a--;       totww += s ==  WW ;       totwb += s ==  W? ;       totwb += s ==  WB ;       totwb += s ==  ?B ;       totbb += s ==  BB ;       totbw += s ==  B? ;       totbw += s ==  BW ;       totbw += s ==  ?W ;       tot__ += s ==  ?? ;     }     a = -a;     long long ans = 0;     if (a <= b and a >= 0) {       ans = ncr(b, a);       if (totww == 0 and totbb == 0) {         long long x = bigmod(2, tot__, oo);         ans = (ans - x + oo) % oo;         ans += totbw == 0;         ans += totwb == 0;       }     }     ans = (ans + oo) % oo;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const int INF = 1 << 30;   const long long LINF = 1ll << 60;   const int BUFFER_SZ = 1 << 15;   const int MOD = 1000 * 1000 * 1000 + 7;   char BUFFER[BUFFER_SZ];   int gi() {     int x;     scanf( %d , &x);     return x;   }   double gd() {     double x;     scanf( %lf , &x);     return x;   }   long long gll() {     long long x;     cin >> x;     return x;   }   vector<int> gvi(int n) {     vector<int> a;     while (n-- > 0) a.push_back(gi());     return a;   }   string gs() {     scanf( %s , BUFFER);     return string(BUFFER);   }   template <class T>   void print(vector<T> &x, string format) {     format +=  %c ;     for (int i = 0; i < x.size(); ++i)       printf(format.c_str(), x[i], i + 1 == x.size() ?   n  :    );   }   int c_ins, c_del, c_rep, c_swp;   int dp[4444][4444];   int main() {     int c_ins = gi();     int c_del = gi();     int c_rep = gi();     int c_swp = gi();     string a = gs();     string b = gs();     int prev[256];     memset((prev), (0), sizeof(prev));     for (int i = 0; i <= a.size(); ++i) {       int last = 0;       for (int j = 0; j <= b.size(); ++j) {         if (!i)           dp[i][j] = j * c_ins;         else if (!j)           dp[i][j] = i * c_del;         else {           dp[i][j] = 1 << 30;           int ii = j > 0 ? prev[b[j - 1]] : 0;           int jj = last;           if (a[i - 1] == b[j - 1]) {             dp[i][j] = dp[i - 1][j - 1];             last = j;           }           int v = min(min(dp[i - 1][j] + c_del, dp[i][j - 1] + c_ins),                       dp[i - 1][j - 1] + c_rep);           if (i && j && ii && jj) {             v = min(v, dp[ii - 1][jj - 1] + c_swp + c_del * (i - ii - 1) +                            c_ins * (j - jj - 1));           }           dp[i][j] = min(dp[i][j], v);         }       }       if (i > 0) {         prev[a[i - 1]] = i;       }     }     printf( %d n , dp[a.size()][b.size()]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using P = pair<ll, ll>;   const int INF = 1001001001;   const ll mod = 998244353;   const ll INFL = 1000000001000000000;   int M = 100005;   int main() {     int n, q;     cin >> n >> q;     vector<ll> v(n);     for (int i = 0; i < (n); i++) cin >> v[i];     vector<int> c(n);     for (int i = 0; i < (n); i++) cin >> c[i];     for (int i = 0; i < (n); i++) c[i]--;     while (q--) {       ll a, b;       cin >> a >> b;       vector<ll> dp(M, -INFL);       ll bigM1 = 0, bigM2 = 0;       int bigC1 = -1, bigC2 = -1;       for (int i = 0; i < (n); i++) {         if (c[i] == bigC1) {           ll nM = max(dp[c[i]] + v[i] * a, bigM2 + v[i] * b);           dp[c[i]] = max(dp[c[i]], nM);           if (bigM1 < nM) {             bigM1 = nM;             bigC1 = c[i];           }         } else {           ll nM = max(dp[c[i]] + v[i] * a, bigM1 + v[i] * b);           dp[c[i]] = max(dp[c[i]], nM);           if (bigM2 < nM) {             bigM2 = nM;             bigC2 = c[i];           }           if (bigM1 < bigM2) {             swap(bigM1, bigM2);             swap(bigC1, bigC2);           }         }       }       ll ans = 0;       for (int i = 0; i < (M); i++) ans = max(ans, dp[i]);       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a == 0)       return b;     else if (b == 0)       return a;     else {       a = a % b;       return gcd(b, a);     }   }   int main() {     int n;     int sum = 0, odd = 0;     scanf( %d , &n);     int t;     for (int i = 0; i < n; i++) {       scanf( %d , &t);       sum += t;       if (t % 2) odd++;     }     if (sum % 2)       cout << odd;     else       cout << n - odd;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     char arr1[n][m];     char arr2[m][n];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         char a;         cin >> a;         arr1[i][j] = a;         arr2[j][i] = a;       }     }     string ans =   ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (count(arr1[i], arr1[i] + m, arr1[i][j]) == 1 &&             count(arr2[j], arr2[j] + n, arr1[i][j]) == 1) {           ans += string(1, arr1[i][j]);         }       }     }     cout << ans;   }
#include <bits/stdc++.h>   static const int INF = std::numeric_limits<int>::max();   int main() {     int n;     std::cin >> n;     std::vector<int> a(n + 1), b(n + 1);     for (int i = 1; i <= n; ++i) {       std::cin >> a[i];     }     for (int i = 1; i <= n; ++i) {       std::cin >> b[i];     }     std::vector<int> res(n + 1);     for (int i = 1; i <= n; ++i) {       res[a[i]] = b[i];     }     for (int i = 1; i <= n; ++i) {       std::cout << res[i] <<    ;     }     std::cout << std::endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   char c[109][109];   bool ja = 1;   bool useless = 1;   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> c[i][j];         if (c[i][j] ==  . ) {           if (i % 2 == 0 && j % 2 == 0 || i % 2 == 1 && j % 2 == 1) {             c[i][j] =  B ;           } else {             c[i][j] =  W ;           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << c[i][j];       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e2 + 10;   int main() {     mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, i, in, last, ans = 0, prelast = -1;     cin >> n;     cin >> last;     for (i = 1; i < n; i++) {       cin >> in;       if (last == 1 && in == 2) {         ans += 3;         if (prelast == 3) ans--;       } else if (last == 1 && in == 3)         ans += 4;       else if (last == 2 && in == 1)         ans += 3;       else if (last == 2 && in == 3) {         cout <<  Infinite n ;         return 0;       } else if (last == 3 && in == 2) {         cout <<  Infinite n ;         return 0;       } else if (last == 3 && in == 1)         ans += 4;       prelast = last;       last = in;     }     cout <<  Finite n ;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const long long e = 1e5 + 110;   bool zs[e];   long long num[e];   void sai() {     for (long long i = 2; i <= e - 99; i++) {       if (zs[i]) continue;       for (long long j = i + i; j <= e - 99; j += i) {         zs[j] = true;       }     }     for (long long tot = 0, i = 2; i <= e - 99; i++) {       if (!zs[i]) tot++, num[tot] = i;     }   }   struct fengjie {     long long v, t;   } f[e];   long long cnf = 0;   void fj(long long x) {     long long tmp = x;     for (long long i = 2; i <= x; i++) {       long long cnt = 0;       while (tmp % i == 0) {         tmp /= i;         cnt++;       }       if (cnt == 0) continue;       cnf++;       f[cnf].v = i, f[cnf].t = cnt;     }     return;   }   long long ksm(long long a, long long z) {     long long ret = 1;     if (z == 0) return 1;     while (z != 1) {       if (z % 2 == 1) {         ret *= a;         a *= a;       } else {         a *= a;       }       z /= 2;     }     return a * ret;   }   fengjie an[e];   signed main() {     long long n;     cin >> n;     sai();     fj(n);     long long ans = 1, g = 0, cna = 0, minn;     for (long long i = cnf; i > 0; i--) {       for (long long j = 1; j <= f[i].t; j++) {         if (cna == 0) {           g++;           ans *= ksm(num[g], f[i].v - 1);           an[++cna].v = num[g];           an[cna].t = f[i].v - 1;           continue;         }         long long pl = -1;         minn = ans * ksm(num[g + 1], f[i].v - 1);         for (long long l = 1; l <= cna; l++) {           long long ct = f[i].v * (an[l].t + 1) - 1;           long long tmp = ans / ksm(an[l].v, an[l].t);           tmp *= ksm(an[l].v, ct);           if (tmp < ans or ksm(an[l].v, ct) < an[l].v) continue;           if (tmp < minn) {             pl = l;             minn = tmp;           }         }         if (pl == -1) {           g++;           ans *= ksm(num[g], f[i].v - 1);           an[++cna].v = num[g];           an[cna].t = f[i].v - 1;         }         if (pl != -1) {           long long tmp = ans / ksm(an[pl].v, an[pl].t);           long long ct = f[i].v * (an[pl].t + 1) - 1;           ans = tmp * ksm(an[pl].v, ct);         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   stack<int> s;   priority_queue<int> pq;   long long maxm = numeric_limits<long long>::max();   const int maxn = 10005;   struct node {     int l, r;   } q[1001];   bool cmp(node a, node b) { return a.l < b.l; }   int main() {     int n, sum = 0;     scanf( %d , &n);     int a[maxn], l[maxn], r[maxn];     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       sum += a[i];     }     int m, tmp;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &q[i].l, &q[i].r);     }     sort(q + 1, q + 1 + m, cmp);     if (sum > q[m].r)       printf( -1 n );     else if (sum < q[1].l)       printf( %d n , q[1].l);     else {       for (int i = 1; i <= m; i++) {         if (sum > q[i].r && sum < q[i + 1].l) {           printf( %d n , q[i + 1].l);           break;         } else if (sum >= q[i].l && sum <= q[i].r) {           printf( %d n , sum);           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     bool b[4][n][n];     for (int i = 0; i < 4; i++) {       for (int j = 0; j < n; j++) {         char c[n + 1];         scanf( %s , &c);         for (int k = 0; k < n; k++) b[i][j][k] = c[k] ==  1  ? 1 : 0;       }     }     int s[] = {0, 1, 2, 3}, mi = 1e9, co = 0;     bool o = 0;     do {       for (int k = 0; k < 4; k += 2) {         for (int j = 0; j < n; j++) {           for (int i = 0; i < n; i++) {             if (b[s[k]][j][i] != o) co++;             o ^= 1;           }           for (int i = 0; i < n; i++) {             if (b[s[k + 1]][j][i] != o) co++;             o ^= 1;           }           o ^= 1;         }       }       mi = min(mi, co);       co = 0;     } while (next_permutation(s, s + 4));     cout << mi <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, M;   int A[50050], X[50500];   int L[50050], R[50500];   int XX[1010101];   int ma[50505];   int ret[50505];   signed long long xorxor(signed long long val) {     int i;     signed long long ret = ((val + 1) / 2) % 2;     for (i = 0; i <= 29; i++)       if ((val >> i) % 2) ret |= (1 ^ (val % 2)) << i;     return ret;   }   void solve() {     int i, j, k, l, r, x, y;     string s;     for (i = 1; i <= 1000000; i++) XX[i] = XX[i - 1] ^ i;     cin >> N >> M;     for (i = 0; i < (N); i++) cin >> A[i], X[i] = XX[A[i]];     for (i = 0; i < (M); i++) cin >> L[i] >> R[i], L[i]--, R[i]--;     for (x = 0; x < (N); x++) {       ma[x - 1] = 0;       for (y = x; y < N; y++)         ma[y] = max(ma[y - 1], X[x] ^ X[y] ^ ((A[x] > A[y]) ? A[y] : A[x]));       for (i = 0; i < (M); i++)         if (L[i] <= x) ret[i] = max(ret[i], ma[R[i]]);     }     for (i = 0; i < (M); i++) cout << ret[i] << endl;   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false);     for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);     solve();     return 0;   }