malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const double eps = 1e-9;   const int inf = 2000000000;   const long long infLL = 9000000000000000000;   inline bool checkBit(long long n, int i) { return n & (1LL << i); }   inline long long setBit(long long n, int i) {     return n | (1LL << i);     ;   }   inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }   int dx[] = {0, 0, +1, -1};   int dy[] = {+1, -1, 0, 0};   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   inline bool isLeapYear(long long year) {     return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);   }   inline void normal(long long &a) {     a %= 1000000007;     (a < 0) && (a += 1000000007);   }   inline long long modMul(long long a, long long b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     return (a * b) % 1000000007;   }   inline long long modAdd(long long a, long long b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     return (a + b) % 1000000007;   }   inline long long modSub(long long a, long long b) {     a %= 1000000007, b %= 1000000007;     normal(a), normal(b);     a -= b;     normal(a);     return a;   }   inline long long modPow(long long b, long long p) {     long long r = 1;     while (p) {       if (p & 1) r = modMul(r, b);       b = modMul(b, b);       p >>= 1;     }     return r;   }   inline long long modInverse(long long a) { return modPow(a, 1000000007 - 2); }   inline long long modDiv(long long a, long long b) {     return modMul(a, modInverse(b));   }   const int MX = 10100;   int vis[5][5][5], l[5], r[5], curnum, n;   double dp[5][5][5];   double func(int pos, int eNum, int bNum) {     if (bNum > 1) return 0;     if (pos == n) {       if (eNum > 1 && !bNum) return 1;       if (eNum && bNum) return 1;       return 0;     }     if (vis[pos][eNum][bNum]) return dp[pos][eNum][bNum];     vis[pos][eNum][bNum] = 0;     double &ret = dp[pos][eNum][bNum];     ret = 0;     if (curnum >= l[pos] && curnum <= r[pos]) {       double temp = (1.0 / (r[pos] - l[pos] + 1));       temp *= func(pos + 1, eNum + 1, bNum);       ret += temp;     }     if (r[pos] > curnum) {       double temp = 1;       if (l[pos] <= curnum) {         temp *= (double)(r[pos] - curnum) / (double)(r[pos] - l[pos] + 1);       }       temp *= func(pos + 1, eNum, bNum + 1);       ret += temp;     }     if (l[pos] < curnum) {       double temp = 1;       if (r[pos] >= curnum) {         temp *= (double)(curnum - l[pos]) / (double)(r[pos] - l[pos] + 1);       }       temp *= func(pos + 1, eNum, bNum);       ret += temp;     }     return ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cout.unsetf(ios::floatfield);     cout.precision(10);     cout.setf(ios::fixed, ios::floatfield);     ;     cin >> n;     for (int i = 0; i < n; ++i) cin >> l[i] >> r[i];     double ans = 0;     for (int i = 1; i < MX; ++i) {       curnum = i;       ans += i * func(0, 0, 0);       ;       memset(vis, 0, sizeof(vis));     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   const int N = 5050;   int n, t, v = -1, w, p[N], c[N], d[N], l[N];   void U(int x, int* y) {     for (int u = x + 1; u <= n; u += u & -u) ++y[u];   }   int Q(int x, int* y) {     int s = 0;     while (x > 0) s += y[x], x -= x & -x;     return s;   }   int main() {     scanf( %d , &n);     for (int i = 0, s; i < n && 1 == scanf( %d , &p[i]); ++i)       s = Q(p[i], c), l[i] = s, t += i - s, U(p[i], c);     for (int i = 0; i < n; U(p[i++], d))       for (int j = i + 1, a = 0, b; j < n; ++j)         if (p[j] < p[i]) {           b = l[j] - Q(p[j], d);           if (a - b > v)             v = a - b, w = 1;           else if (a - b == v)             ++w;           ++a;         }     printf( %d %d n , t - v - v - 1, w);   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> ve[100005];   long long vis[100005] = {0}, z = 0, i;   void solve() {     vector<long long> v;     vector<pair<long long, long long> > vp;     map<long long, long long> mp, mpp;     map<long long, long long>::iterator itr;     long long n = 0, m = 0, i = 0, j = 0, k = 0, c = 0, l = 0, r = 0, p = 0,               q = 0, x = 0, y = 0, z = 0, flag = 0, sum = 0;     long long a[300005] = {0}, b[1005] = {0}, ans[25][25];     long long s, t;     cin >> n;     for (i = 0; i < pow(n, 2); i++) cin >> a[i];     for (i = 0; i < pow(n, 2); i++) b[a[i]]++;     for (i = 0; i < 1001; i++)       if (b[i] > 0) vp.push_back(make_pair(b[i], i));     sort(vp.begin(), vp.end());     z = vp.size() - 1;     for (j = 0; j < n / 2; j++) {       for (i = 0; i < n / 2; i++) {         if (vp[z].first >= 4) {           k = vp[z].second;           vp[z].first -= 4;           ans[i][j] = k;           ans[n - i - 1][j] = k;           ans[i][n - j - 1] = k;           ans[n - i - 1][n - j - 1] = k;         } else {           z--;           i--;         }         if (z == -1) {           cout <<  No  << endl;           return;         }       }     }     if (n % 2 == 1) {       s = (n - 1) / 2;       sort(vp.begin(), vp.end());       z = vp.size() - 1;       for (i = 0; i < n / 2; i++) {         if (vp[z].first >= 2) {           k = vp[z].second;           vp[z].first -= 2;           ans[s][i] = k;           ans[s][n - i - 1] = k;         } else {           z--;           i--;         }         if (z == -1) {           cout <<  No  << endl;           return;         }       }       sort(vp.begin(), vp.end());       z = vp.size() - 1;       for (i = 0; i < n / 2; i++) {         if (vp[z].first >= 2) {           k = vp[z].second;           vp[z].first -= 2;           ans[i][s] = k;           ans[n - i - 1][s] = k;         } else {           z--;           i--;         }         if (z == -1) {           cout <<  No  << endl;           return;         }       }       sort(vp.begin(), vp.end());       z = vp.size() - 1;       ans[s][s] = vp[z].second;     }     for (i = 0; i < n; i++)       for (j = 0; j < n; j++)         if (ans[i][j] == 0) {           cout <<  No  << endl;           return;         }     cout <<  Yes  << endl;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) cout << ans[i][j] <<     ;       cout << endl;     }   }   bool imp = false;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     if (imp) cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bitset<300000001> b;   int main() {     int l, r, c = 0, i, j;     cin >> l >> r;     for (i = 3; i * i <= r; i += 2)       for (j = i * i; b[i] == 0 and j <= r; j += i) b[j] = 1;     if (l <= 2 and r >= 2) c = 1;     for (i = 5; i <= r; i += 4) c += !b[i] and i >= l;     cout << c;   }
#include <bits/stdc++.h>   using namespace std;   int b[4], c, n, l = 0, a, i;   int main() {     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &a);       b[a]++;     }     cout << n - max(b[1], max(b[2], b[3])) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000 * 1000 * 1000 + 7;   const double EPS = 1e-9;   int bit_count(int first) {     return first == 0 ? 0 : 1 + bit_count(first & (first - 1));   }   inline int low_bit(int first) { return first & -first; }   inline int sign(double first) {     return first < -EPS ? -1 : first > EPS ? 1 : 0;   }   inline int sign(int first) { return (first > 0) - (first < 0); }   int nextComb(int first) {     if (!first) {       fprintf(stderr,  nextComb(0) called n );       return ((1 << 30) - 1 + (1 << 30));     }     int smallest = first & -first;     int ripple = first + smallest;     int ones = first ^ ripple;     ones = (ones >> 2) / smallest;     return ripple | ones;   }   template <class T>   inline T gcd(T a, T b) {     a = abs(a);     b = abs(b);     while (b) {       int r = a % b;       a = b;       b = r;     }     return a;   }   template <class T>   inline T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   inline int getInt() {     int a;     return scanf( %d , &a) ? a : (fprintf(stderr,  trying to read n ), -1);   }   inline double getDouble() {     double a;     return scanf( %lf , &a) ? a : (fprintf(stderr,  trying to read n ), -1.0);   }   inline double myRand() {     return ((double)rand() / RAND_MAX) + ((double)rand() / RAND_MAX / RAND_MAX);   }   inline string getLine() {     string ret;     getline(cin, ret,  : );     return ret;   }   long long process(string s, int base) {     long long ret = 0;     for (int i = (int)0; i < (int)((int)(s).size()); ++i) {       ret *= base;       if (isdigit(s[i]))         ret += s[i] -  0 ;       else         ret += s[i] -  A  + 10;     }     return ret;   }   bool isValid(string s, int base) {     for (int i = (int)0; i < (int)((int)(s).size()); ++i) {       if (isdigit(s[i]) && s[i] -  0  >= base)         return false;       else if (s[i] -  A  + 10 >= base)         return false;     }     return true;   }   void myCode() {     string hrs, mins;     getline(cin, hrs,  : );     getline(cin, mins);     vector<int> ret;     if (((int)(hrs).size()) < 6 && ((int)(mins).size()) < 7) {       for (int i = (int)2; i < (int)100; ++i) {         if (isValid(hrs, i) == true && isValid(mins, i) == true) {           if (process(hrs, i) < 24 && process(mins, i) < 60) {             ret.push_back(i);           }         }       }     }     if (ret.empty())       printf( 0 n );     else if (ret[((int)(ret).size()) - 1] == 99)       printf( -1 n );     else       for (int i = (int)0; i < (int)((int)(ret).size()); ++i)         printf( %d%c , ret[i], i == ((int)(ret).size()) - 1 ?   n  :    );   }   int main() {     srand(time(NULL));     myCode();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     bool count[26] = {0};     char c;     for (int i = 0; i < n; i++) {       cin >> c;       count[c -  a ] = true;     }     int e = -4;     int res = 0;     for (int i = 0; i < 26; i++) {       if ((!count[i]) || (i - e) < 2) continue;       res += i + 1;       e = i;       k--;       if (k == 0) break;     }     if (k > 0) {       cout <<  -1 n ;     } else       cout << res <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     int n;     cin >> n;     int k;     cin >> k;     string s;     cin >> s;     int ig = -1, it = -1;     for (int i = 0; i < n; i++) {       if (s[i] ==  G ) {         ig = i;       }       if (s[i] ==  T ) {         it = i;       }     }     if (it % k != ig % k) {       cout <<  NO  << endl;     } else {       if (ig < it) {         swap(it, ig);       }       for (int i = it; i <= ig; i++) {         if (s[i] ==  #  && (i % k) == (ig % k)) {           cout <<  NO  << endl;           return 0;         }       }       cout <<  YES  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1005;   const long long mod = 1000000007;   int grid[maxn][maxn];   inline void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);   }   int main() {     fast();     int h, w;     cin >> h >> w;     for (int i = 0; i < h; i++) {       int x;       cin >> x;       for (int j = 0; j < x; j++) grid[i][j] = 1;       grid[i][x] = 2;     }     for (int j = 0; j < w; j++) {       int x;       cin >> x;       for (int i = 0; i < x; i++) {         if (grid[i][j] == 2) {           cout << 0 << endl;           return 0;         }         grid[i][j] = 1;       }       if (grid[x][j] == 1) {         cout << 0 << endl;         return 0;       }       grid[x][j] = 2;     }     int ans = 1;     for (int i = 0; i < h; i++)       for (int j = 0; j < w; j++) {         if (grid[i][j] == 0) {           ans = ans * 2 % mod;         }       }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6;   string b[maxn];   int p[maxn], n[maxn];   void get_id(string);   bool is_legal(string);   int main() {     int N;     scanf( %d , &N);     memset(p, 0, sizeof(p));     memset(n, 0, sizeof(n));     for (int i = 0; i < N; i++) {       cin >> b[i];       get_id(b[i]);     }     int ans = 0;     ans += (p[0] / 2);     for (int i = 1; i < maxn; i++) {       ans += min(p[i], n[i]);     }     printf( %d n , ans);     return 0;   }   void get_id(string c) {     if (is_legal(c)) {       p[0]++;       return;     }     int len = c.size();     int count = 0;     bool find = false;     for (int i = 0; i < len; i++) {       if (c[i] ==  ( )         count++;       else         count--;       if (count < 0) find = true;     }     if (count > 0 && !find) p[count]++;     find = false;     count = 0;     for (int i = len - 1; i >= 0; i--) {       if (c[i] ==  ) )         count++;       else         count--;       if (count < 0) find = true;     }     if (count > 0 && !find) n[count]++;   }   bool is_legal(string c) {     int len = c.size();     int count = 0;     for (int i = 0; i < len; i++) {       if (c[i] ==  ( )         count++;       else         count--;       if (count < 0) return false;     }     if (!count)       return true;     else       return false;   }
#include <bits/stdc++.h>   int n, K;   int ch[60000][26];   int val[60000];   char st[1000];   int f[60000][1000];   int knum;   void add(char *st) {     int m = strlen(st + 1);     int u = 0;     for (int i = 1; i <= m; i++) {       if (!ch[u][st[i] -  a ]) {         knum++;         ch[u][st[i] -  a ] = knum;       }       u = ch[u][st[i] -  a ];     }     val[u]++;   }   void dfs(int u) {     for (int i = 0; i < 26; i++) {       int v = ch[u][i];       if (v) {         dfs(v);       }     }     for (int i = 0; i <= K; i++) {       f[u][i] = -1000000000;     }     f[u][0] = 0;     for (int i = 0; i < 26; i++) {       int v = ch[u][i];       if (v) {         for (int j = K; j >= 0; j--) {           for (int k = 0; k <= j; k++) {             f[u][j] = std::max(f[u][j], f[u][j - k] + f[v][k] + k * (k - 1) / 2);           }         }       }     }     for (int i = K; i >= 0; i--) {       for (int j = 0; j <= std::min(i, val[u]); j++) {         f[u][i] = std::max(f[u][i], f[u][i - j]);       }     }   }   int main() {     knum = 0;     scanf( %d%d , &n, &K);     for (int i = 1; i <= n; i++) {       scanf( %s , st + 1);       add(st);     }     dfs(0);     printf( %d n , f[0][K]);     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000 )   using namespace std;   int n;   string s;   string A[] = { 123456 ,  154236 ,  145326 ,  516324 ,  261453 ,  132546 };   string B[] = { 123456 ,  523164 ,  623541 ,  423615 };   vector<string> P;   vector<string> T;   vector<string> H;   bool BB[1000];   bool F(string a, string b) {     for (long long(i) = (0); (i) < (T.size()); ++(i)) {       string t = a;       for (long long(j) = (0); (j) < (6); ++(j)) t[j] = a[T[i][j] -  0 ];       if (t == b) return true;     }     return false;   }   int main() {     cin >> s;     int Q[6];     for (long long(i) = (0); (i) < (6); ++(i)) Q[i] = i;     do {       string p =   ;       for (long long(i) = (0); (i) < (6); ++(i)) p += char( 0  + Q[i]);       P.push_back(p);     } while (next_permutation(Q, Q + 6));     for (long long(i) = (0); (i) < (6); ++(i))       for (long long(j) = (0); (j) < (4); ++(j)) {         string t = A[i];         string p = t;         for (long long(k) = (0); (k) < (6); ++(k)) {           int x = B[j][k] -  0 ;           x--;           p[k] = t[x];           p[k]--;         }         T.push_back(p);       }     for (long long(i) = (0); (i) < (P.size()); ++(i)) {       string t =   ;       for (long long(j) = (0); (j) < (6); ++(j)) t += s[P[i][j] -  0 ];       H.push_back(t);     }     int res = 0;     for (long long(i) = (0); (i) < (H.size()); ++(i))       if (BB[i] == false) {         res++;         for (long long(j) = (i + 1); (j) < (H.size()); ++(j))           if (F(H[i], H[j])) BB[j] = true;       }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       long long a, b, c, d;       cin >> a >> b >> c >> d;       if (a > b * c)         cout << -1 <<   n ;       else {         long long k = (a / (b * d));         cout << a * (k + 1) - k * (k + 1) / 2 * b * d <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long m, l, r, k, ans;   map<long long, long long> F;   long long f(long long n) {     if (F.count(n)) return F[n];     long long k = n / 2;     if (n % 2 == 0) return F[n] = (f(k) * f(k) + f(k - 1) * f(k - 1)) % m;     return F[n] = (f(k) * f(k + 1) + f(k - 1) * f(k)) % m;   }   vector<long long> poss;   void get(long long x) {     for (long long i = 1, la; i <= x; i = la + 1) {       la = x / (x / i);       poss.push_back(la);     }   }   int32_t main() {     cin >> m >> l >> r >> k;     get(l - 1), get(r);     for (auto i : poss)       if (r / i - (l - 1) / i >= k) ans = max(ans, i);     F[0] = F[1] = 1 % m;     cout << f(ans - 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 3;   long long n, x, a, cnt, ans, sum;   string g;   deque<long long> v;   void DNM() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a;       v.push_back(a);       if (a > 0) cnt = i;     }     for (long long i = 0; i <= cnt; i++) {       if (i == cnt and i == n - 1) {         for (long long j = 1; j <= v[i]; j++) {           if (j == v[i])             g +=  P ;           else             g +=  P , g +=  L , g +=  R ;         }         break;       }       for (long long j = 0; j < v[i]; j++) {         g +=  P ;         g +=  R ;         g +=  L ;       }       g +=  R ;     }     cout << g << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int Qu_l_uQ = 1;     while (Qu_l_uQ--) DNM();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, l, r, p, q, w[100000 + 2], ans = 2100000000, sum = 0, sub = 0;     scanf( %d%d%d%d%d , &n, &l, &r, &p, &q);     for (int i = 0; i < n; i++) {       scanf( %d , &w[i]);       sum += w[i];     }     for (int i = 0; i <= n; i++) {       int ret = sum * r + sub * l;       if (i <= n - i) {         ret += max(0, n - i - i - 1) * q;       } else {         ret += max(0, i - n + i - 1) * p;       }       if (ret < ans) ans = ret;       if (i != n) {         sum -= w[i];         sub += w[i];       }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, i, g = 0, s = 0, b = 0, j;       cin >> n;       long long a[n];       vector<long long> v(n, 1);       for (i = 0; i < n; i++) {         cin >> a[i];       }       if (n < 6)         cout <<  0 0 0 n ;       else {         for (i = 0; i < n - 1; i++) {           if (a[i] == a[i + 1]) v[i + 1] = v[i] + 1;         }         for (i = 0; i < n - 1; i++) {           if (a[i] != a[i + 1]) {             g = g + v[i];             break;           }         }         for (j = i + 1; j < n - 1; j++) {           if (a[j] != a[j + 1] && j < n / 2) {             s = s + v[j];             if (s > g) {               break;             }           }         }         for (long long l = j + 1; l < n - 1; l++) {           if (l < n / 2 && a[l] != a[l + 1]) {             b = b + v[l];           }         }         if (g > 0 && s > 0 && b > 0 && g < s && g < b) {           cout << g <<     << s <<     << b <<   n ;         } else           cout <<  0 0 0 n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     long long int n, k;     cin >> n >> k;     long long int arr1[n], arr2[n];     for (long long int i = 0; i < n; i++) cin >> arr1[i];     for (long long int i = 0; i < n; i++) cin >> arr2[i];     multiset<pair<long long int, pair<long long int, long long int> > > s;     for (long long int i = 0; i < n; i++) {       s.insert(make_pair(arr2[i] / arr1[i], make_pair(arr1[i], arr2[i])));     }     multiset<pair<long long int, pair<long long int, long long int> > >::iterator         it1;     while (true) {       pair<long long int, pair<long long int, long long int> > pp = *s.begin();       long long int num = pp.first, a = pp.second.first, b = pp.second.second;       long long int req = a - (b % a);       if (k >= req) {         k -= req;         s.erase(s.begin());         s.insert(make_pair(num + 1, make_pair(a, b + req)));       } else {         break;       }     }     it1 = s.begin();     cout << it1->first;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100010], w[100010], h[100010];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d%d , &w[i], &h[i]);     ;     a[n] = min(w[n], h[n]);     for (int i = n - 1; i >= 1; i--) {       if (min(w[i], h[i]) >= a[i + 1])         a[i] = min(w[i], h[i]);       else         a[i] = max(w[i], h[i]);       if (a[i] < a[i + 1]) {         printf( NO );         return 0;       }     }     printf( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000 + 10;   const int inf = (-1u) >> 1;   bool v[maxn];   int n, m, k, num;   vector<int> g[maxn];   void dfs(int x) {     v[x] = true;     ++num;     for (vector<int>::iterator it = g[x].begin(); it != g[x].end(); ++it) {       if (!v[*it]) {         dfs(*it);       }     }   }   int main() {     while (scanf( %d%d%d , &n, &m, &k) != EOF) {       for (int i = 0; i < (n); ++i) {         g[i].clear();         v[i] = false;       }       for (int i = 0; i < (m); ++i) {         int a, b;         scanf( %d%d , &a, &b);         --a, --b;         g[a].push_back(b), g[b].push_back(a);       }       int cnt = 0, ecnt = 0, totcnt = 0;       for (int i = 0; i < (n); ++i)         if (!v[i]) {           num = 0;           dfs(i);           ++totcnt;           if (num == 1) {             ++cnt;           } else {             ecnt += min(k, num) - 2;           }         }       if (k >= 2) {         ecnt += 2;         cnt -= ecnt;         if (totcnt > cnt) cnt += 2;         printf( %d n , max(0, (cnt - 1) / 2));       } else {         printf( %d n , max(0, totcnt - 2));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 66;   long long n, k, a[maxn], d[maxn][maxn];   int main(void) {     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       a[i] += a[i - 1];     }     long long rt = 0;     for (int i = 55; i >= 0; --i) {       rt += ((1LL * 1) << i);       memset(d, 0, sizeof(d));       d[0][0] = 1;       for (int j = 1; j <= n; ++j) {         for (int q = 1; q <= j; ++q) {           for (int w = j - 1; w >= q - 1; --w) {             if (((a[j] - a[w]) & rt) < rt) continue;             if (d[w][q - 1] == 1) d[j][q] = 1;           }         }       }       if (d[n][k] == 0) rt -= ((1LL * 1) << i);     }     cout << rt << endl;   }