malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   using namespace std;   const int N = 101010, mod = 1e9 + 7;   namespace {   inline int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }   inline int sub(int x, int y) { return (x -= y) < 0 ? x + mod : x; }   inline int mul(int x, int y) { return 1LL * x * y % mod; }   }  // namespace   struct edge {     int u, v, w;   } e[N];   int n, K, fac[N];   map<long long, int> f[55][55];   vector<pair<int, int> > adj[N];   vector<int> allu, allv;   long long least[N];   inline void U(int &x, int y) { (x += y) >= mod ? x -= mod : x; }   int main(void) {     scanf( %d%d , &n, &K);     fac[0] = 1;     for (int i = 1; i <= n; i++) {       fac[i] = mul(fac[i - 1], i);     }     for (int i = 1, u, v, w; i <= K; i++) {       scanf( %d%d%d , &u, &v, &w);       e[i] = (edge){u, v, sub(w, 1)};       allu.push_back(u);       allv.push_back(v);     }     sort(allu.begin(), allu.end());     sort(allv.begin(), allv.end());     allu.erase(unique(allu.begin(), allu.end()), allu.end());     allv.erase(unique(allv.begin(), allv.end()), allv.end());     int m = allu.size();     for (int i = 1; i <= K; i++) {       int u = lower_bound(allu.begin(), allu.end(), e[i].u) - allu.begin();       int v = lower_bound(allv.begin(), allv.end(), e[i].v) - allv.begin();       adj[u].push_back((pair<int, int>){v, e[i].w});     }     for (int i = m - 1; ~i; i--) {       least[i] = least[i + 1];       for (auto p : adj[i]) {         least[i] |= 1LL << p.first;       }     }     f[0][0][0] = 1;     for (int i = 0; i < m; i++) {       for (int j = 0; j <= i; j++) {         for (auto p : f[i][j]) {           U(f[i + 1][j][p.first & least[i + 1]], p.second);           for (auto t : adj[i]) {             if (~p.first >> t.first & 1) {               U(f[i + 1][j + 1][(p.first | (1LL << t.first)) & least[i + 1]],                 mul(p.second, t.second));             }           }         }       }     }     int ans = 0;     for (int i = 0; i <= m; i++) {       for (auto p : f[m][i]) {         U(ans, mul(p.second, fac[n - i]));       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     long long k = 0;     cin >> k;     if (k == 1) {       cout <<  4 ;       return 0;     }     string s =   ;     unsigned long long a = 1000000000000000000;     unsigned long long num = 0;     long long f = 0;     while (k > 0) {       if (k >= 2) {         k -= 2;         s += to_string(8);         num = (num * 10) + 8;       } else {         k -= 1;         s += to_string(0);         num = (num * 10) + 0;       }       if (num > a) {         f = 1;         break;       }     }     if (f == 0)       cout << s;     else       cout <<  -1 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   vector<int> Q[100010];   long long F[100010][2];   bool vis[100010];   void dfs(int u) {     if (vis[u]) return;     vis[u] = true, F[u][1] = 1LL, F[u][0] = 0LL;     if (!Q[u].size()) return;     long long d0, d1;     for (int i = 0; i < Q[u].size(); i++) {       int v = Q[u][i];       dfs(v);       d0 = (F[u][1] * F[v][1] + F[u][0] * F[v][0]) % 1000000007;       d1 = (F[u][1] * F[v][0] + F[u][0] * F[v][1]) % 1000000007;       F[u][0] = (F[u][0] + d0) % 1000000007;       F[u][1] = (F[u][1] + d1) % 1000000007;     }     long long p0 = 1LL, p1 = 1LL, p2 = 0LL;     for (int i = 0; i < Q[u].size(); i++) {       int v = Q[u][i];       p0 = (p0 + p0 * F[v][0]) % 1000000007;       long long tmp = p1;       p1 = (p1 + p2 * F[v][1]) % 1000000007;       p2 = (p2 + tmp * F[v][1]) % 1000000007;     }     F[u][0] = (F[u][0] * 2 - p2 + 1000000007) % 1000000007;     F[u][1] = (F[u][1] * 2 - p0 + 1000000007) % 1000000007;     return;   }   int main() {     scanf( %d , &N);     for (int i = 2; i <= N; i++) {       int x;       scanf( %d , &x);       Q[x].push_back(i);     }     memset(vis, false, sizeof(vis));     memset(F, 0, sizeof(F));     dfs(1);     cout << (F[1][0] + F[1][1]) % 1000000007 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int h[36020];   int main() {     char sir[4005];     int a, n, i, j, suma, v[4005];     cin >> a;     cin.get();     cin.get(sir + 1, 4005);     n = strlen(sir + 1);     v[0] = 0;     for (i = 1; i <= n; i++) v[i] = v[i - 1] + (sir[i] -  0 );     for (i = 1; i <= n; i++)       for (j = i; j <= n; j++) {         suma = v[j] - v[i - 1];         h[suma]++;       }     long long int rasp = 0;     for (i = 1; i <= n; i++)       for (j = i; j <= n; j++) {         suma = v[j] - v[i - 1];         if (a == 0) {           if (suma == 0)             rasp += ((n * (n + 1)) / 2);           else             rasp += h[0];         } else if (suma != 0)           if (a % suma == 0) rasp += (((a / suma) < 36020) ? h[a / suma] : 0);       }     cout << rasp <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   unordered_map<int, vector<int> > g;   map<pair<int, int>, int> weights;   map<pair<int, int>, int> idx;   unordered_map<int, bool> used;   struct elem {     int prev;     int u;     long long dist;     elem(int prev, int u, long long dist) : prev(prev), u(u), dist(dist) {}     friend bool operator<(const elem& lh, const elem& rh) {       return lh.dist > rh.dist;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m >> k;     for (int i = 1; i <= m; ++i) {       int u, v, w;       cin >> u >> v >> w;       g[u].push_back(v);       g[v].push_back(u);       weights[make_pair(u, v)] = w;       weights[make_pair(v, u)] = w;       idx[make_pair(u, v)] = i;       idx[make_pair(v, u)] = i;     }     vector<int> res;     priority_queue<elem> q;     q.push(elem(0, 1, 0));     int taken = 0;     int mx = min(n, k);     while (!q.empty() && mx != taken) {       int prev = q.top().prev;       int u = q.top().u;       long long dist = q.top().dist;       q.pop();       if (used[u]) continue;       used[u] = true;       if (prev) {         res.push_back(idx[make_pair(prev, u)]);         ++taken;       }       for (int v : g[u])         if (!used[v]) {           q.push(elem(u, v, dist + weights[make_pair(u, v)]));         }     }     cout << res.size() << endl;     for (int i : res) cout << i <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[100005];   long long ans = 0;   int main() {     int n;     cin >> n;     vector<int> a;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] % 2)         a.push_back(arr[i]);       else         ans += arr[i];     }     int i;     if ((int)a.size() % 2)       i = 1;     else       i = 0;     sort(a.begin(), a.end());     int sz = a.size();     for (; i < sz; i++) ans += a[i];     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 2e9;   const long long INFL = 1e18;   const int N = 3e5;   int n, m, R;   vector<int> adj[N + 5];   pair<int, int> E[2 * N + 5];   long long d[N + 5];   struct cmp {     bool operator()(pair<int, long long> x, pair<int, long long> y) {       return (x.second > y.second);     }   };   priority_queue<pair<int, long long>, vector<pair<int, long long> >, cmp> H;   int tr[N + 5];   void Dijkstra() {     for (int i = (1), _b = (n); i <= _b; ++i) d[i] = INFL;     d[R] = 0;     H.push(make_pair(R, d[R]));     while (!H.empty()) {       int u = H.top().first;       long long oldDist = H.top().second;       H.pop();       if (oldDist != d[u]) continue;       for (int i = (0), _b = (((int)(adj[u]).size())); i < _b; ++i) {         int v = E[adj[u][i]].first, w = E[adj[u][i]].second;         if (d[u] + w < d[v] ||             d[u] + w == d[v] && E[adj[u][i]].second < E[tr[v]].second) {           d[v] = d[u] + w;           H.push(make_pair(v, d[v]));           tr[v] = adj[u][i];         }       }     }   }   vector<int> pth;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     int cntE = 0;     while (m--) {       int u, v, w;       cin >> u >> v >> w;       E[++cntE] = make_pair(v, w);       adj[u].push_back(cntE);       E[++cntE] = make_pair(u, w);       adj[v].push_back(cntE);     }     cin >> R;     Dijkstra();     long long res = 0;     for (int i = (1), _b = (n); i <= _b; ++i)       if (i != R) {         res += E[tr[i]].second;         pth.push_back(tr[i]);       }     cout << res <<   n ;     for (int i = (0), _b = (((int)(pth).size())); i < _b; ++i)       cout << (pth[i] + 1) / 2 <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 2e5 + 10, MOD = 1e9 + 7;   long long n, T, ni[MAXN], jie[MAXN], jie_ni[MAXN], A[MAXN], ans, sum;   long long sum_N, sum_K;   void Init() {     ni[1] = 1;     for (long long i = 2; i <= MAXN - 10; i++) {       ni[i] = ((MOD - (MOD / i)) * ni[MOD % i] % MOD) % MOD;     }     jie_ni[0] = 1;     for (long long i = 1; i <= MAXN - 10; i++) {       jie_ni[i] = jie_ni[i - 1] * ni[i] % MOD;     }     jie[0] = 1;     for (long long i = 1; i <= MAXN - 10; i++) {       jie[i] = jie[i - 1] * i % MOD;     }   }   long long Quick(long long x, long long y) {     long long res = 1, a = x;     while (y) {       if (y & 1) res *= a, res %= MOD;       a = a * a, a %= MOD;       y /= 2;     }     return res;   }   long long C(long long x, long long y) {     if (y == 0) return 1;     if (x == y) return 1;     return (jie[x] * jie_ni[y]) % MOD * jie_ni[x - y] % MOD;   }   long long work(long long N, long long K) {     if (sum_N == 0) {       sum_N = 1;       for (long long i = 1; i <= K; i++) sum_N += C(N, i), sum_N %= MOD;       sum_K = K;       return sum_N;     } else {       sum_N = (sum_N * 2 - C(N - 1, sum_K) + MOD) % MOD;       for (long long i = sum_K; i >= K + 1; i--) {         sum_N -= C(N, i), sum_N = (sum_N + MOD) % MOD;       }       sum_K = K;       return sum_N;     }   }   signed main() {     cin >> n >> T;     Init();     for (long long i = 1; i <= n; i++) cin >> A[i];     long long BASE = 1;     for (long long i = 1; i <= n; i++) {       sum += A[i];       BASE = BASE * 2;       BASE %= MOD;       if (T - sum >= i) {         ans++;         ans %= MOD;       } else if (T - sum < 0) {         break;       } else {         ans += (work(i, T - sum) * Quick(BASE, MOD - 2)) % MOD;         ans %= MOD;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char a[2000][2000];   const int dx[4] = {-1, 0, 1, 0};   const int dy[4] = {0, -1, 0, 1};   queue<pair<int, int> > que;   int main() {     int n, m;     while (~scanf( %d %d , &n, &m)) {       for (int i = 0; i < n; i++) {         getchar();         for (int j = 0; j < m; j++) {           a[i][j] = getchar();         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           int cnt = 0;           for (int k = 0; k < 4; k++) {             int ni = i + dx[k];             int nj = j + dy[k];             if (ni >= 0 && ni < n && nj >= 0 && nj < m && a[ni][nj] ==  . ) {               cnt++;             }           }           if (cnt == 1) {             que.push({i, j});           }         }       }       while (!que.empty()) {         pair<int, int> p = que.front();         que.pop();         int i = p.first, j = p.second, k, ni, nj;         if (a[i][j] !=  . ) {           continue;         }         for (k = 0; k < 4; k++) {           ni = i + dx[k];           nj = j + dy[k];           if (ni >= 0 && ni < n && nj >= 0 && nj < m && a[ni][nj] ==  . ) {             break;           }         }         if (k == 0) {           a[i][j] =  v ;           a[i - 1][j] =  ^ ;         } else if (k == 1) {           a[i][j] =  > ;           a[i][j - 1] =  < ;         } else if (k == 2) {           a[i][j] =  ^ ;           a[i + 1][j] =  v ;         } else if (k == 3) {           a[i][j] =  < ;           a[i][j + 1] =  > ;         } else {           continue;         }         for (int k = 0; k < 4; k++) {           int mi = ni + dx[k];           int mj = nj + dy[k];           if (mi >= 0 && mi < n && mj >= 0 && mj < m && a[mi][mj] ==  . ) {             int cnt = 0;             for (int k = 0; k < 4; k++) {               int pi = mi + dx[k];               int pj = mj + dy[k];               if (pi >= 0 && pi < n && pj >= 0 && pj < m && a[pi][pj] ==  . ) {                 cnt++;               }             }             if (cnt == 1) {               que.push({mi, mj});             }           }         }       }       bool flag = false;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (a[i][j] ==  . ) {             flag = true;             break;           }         }         if (flag) {           printf( Not unique n );           break;         }       }       if (!flag) {         for (int i = 0; i < n; i++) {           for (int j = 0; j < m; j++) {             putchar(a[i][j]);           }           putchar(10);         }       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize  trapv    const int inf1 = 1e9;   const long long int inf2 = 1e18;   const int N = 100000;   using namespace std;   int dirs[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   vector<int> z_function(string s) {     int n = s.length();     vector<int> z(n);     for (int i = 1, l = 0, r = 0; i < n; ++i) {       if (i <= r) z[i] = min(r - i + 1, z[i - l]);       while (i + z[i] < n && s[z[i]] == s[i + z[i]]) z[i]++;       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;     }     return z;   }   bool ispalindrome(string s) {     string t = s;     reverse(s.begin(), s.end());     return t == s;   }   string LPP(string s) {     if (s.length() == 1) return s;     int l = s.length();     string t = s +  # ;     string t2 = s;     reverse(t2.begin(), t2.end());     t += t2;     vector<int> z = z_function(t);     int l2 = 2 * l + 1;     for (int i = l + 1; i < l2; i++) {       if (z[i] == (l2 - i)) {         string ans = t.substr(i, l2 - i);         return ans;       }     }   }   int solve() {     string s;     cin >> s;     int n = s.length();     if (ispalindrome(s)) {       cout << s <<   n ;       return 0;     }     int i = 0;     while (s[i] == s[n - 1 - i]) i++;     string ans = s.substr(0, i);     string ans4 = ans;     reverse(ans4.begin(), ans4.end());     string s2 = s.substr(i, n - 2 * i);     string s3 = s2;     reverse(s3.begin(), s3.end());     string ans1 = LPP(s2);     string ans2 = LPP(s3);     if (ans1.size() >= ans2.size()) {       cout << ans + ans1 + ans4 <<   n ;     } else {       cout << ans + ans2 + ans4 <<   n ;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int N, M, Dx, Dy;     cin >> N >> M >> Dx >> Dy;     vector<pair<int, int>> way(N);     way[0].first = way[0].second = 0;     for (int i = 1; i < N; ++i) {       way[i].first = (way[i - 1].first + Dx) % N;       way[i].second = (way[i - 1].second + Dy) % N;     }     sort(way.begin(), way.end());     vector<pair<int, int>> trees(M);     for (auto& p : trees) {       cin >> p.first >> p.second;     }     sort(trees.begin(), trees.end());     map<int, int> lower, upper;     for (const auto& tree : trees) {       int x = tree.first;       int y = tree.second;       if (y == way[x].second) {         lower[0]++;         upper[0]++;       } else if (y < way[x].second) {         upper[way[x].second - y]++;         lower[y + N - way[x].second]++;       } else {         lower[y - way[x].second]++;         upper[N - y + way[x].second]++;       }     }     auto it1 =         max_element(lower.begin(), lower.end(),                     [](const pair<int, int>& lhs, const pair<int, int>& rhs) {                       return lhs.second < rhs.second;                     });     auto it2 =         max_element(upper.begin(), upper.end(),                     [](const pair<int, int>& lhs, const pair<int, int>& rhs) {                       return lhs.second < rhs.second;                     });     if (it2->second >= it1->second) {       cout << 0 <<     << (2 * N - it2->first) % N <<   n ;     } else {       cout << 0 <<     << it1->first % N <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, c = 0;     cin >> n;     int a, f[7];     for (int j = 0; j < 7; j++) f[j] = 0;     for (int i = 0; i < n; i++) {       cin >> a;       for (int j = 0; j < 7; j++) {         if (a % (int)pow(10, 1) == 1) f[j]++;         a = a / 10;       }     }     for (int i = 0; i < 7; i++) c = max(c, f[i]);     cout << c;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int o, O, f, z, i, d;   string t, s[6] = { lios ,  liala ,  etr ,  etra ,  initis ,  inites };   int V[ zz ];   int main() {     while (cin >> t) {       for (i = O = 0; i < 6; i++)         if ((d = t.size() - s[i].size()) < 0 ? 0 : t.substr(d) == s[i]) {           if (z && V[z - 1] > i) break;           O = 1;           V[z++] = i;           f += i / 2 == 1;           o += i % 2;         }       if (!O) {         cout <<  NO n ;         return 0;       }     }     cout << (z != 1 && (o % z || f != 1) ?  NO n  :  YES n );   }
#include <bits/stdc++.h>   using namespace std;   int n, x, y, son[100005], q;   int fir[100005], nxt[200005], to[200005], cnt;   long long wi[200005], z, dp[100005][2], f[100005];   struct node {     int id;     long long val;   } c[100005];   int size[100005], fa[100005], Fa[100005];   long long read() {     long long x = 0;     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();     return x;   }   void dfs(int x, int fa) {     for (int i = fir[x]; i; i = nxt[i]) {       if (to[i] == fa) continue;       dfs(to[i], x);       if (dp[x][0] < dp[to[i]][0] + wi[i])         dp[x][1] = dp[x][0], dp[x][0] = dp[to[i]][0] + wi[i], son[x] = to[i];       else if (dp[x][1] < dp[to[i]][0] + wi[i])         dp[x][1] = dp[to[i]][0] + wi[i];     }   }   void Dfs(int x, int fa, long long W) {     f[x] = max(dp[x][0], W);     for (int i = fir[x]; i; i = nxt[i]) {       if (to[i] == fa) continue;       if (to[i] == son[x])         Dfs(to[i], x, max(W, dp[x][1]) + wi[i]);       else         Dfs(to[i], x, max(W, dp[x][0]) + wi[i]);     }   }   int cmp(node u, node v) { return u.val < v.val; }   void DFS(int x, int f) {     Fa[x] = f;     for (int i = fir[x]; i; i = nxt[i]) {       if (to[i] == f) continue;       DFS(to[i], x);     }   }   int find(int x) {     if (x == fa[x]) return x;     return fa[x] = find(fa[x]);   }   int main() {     n = read();     for (int i = 1; i < n; i++) {       x = read(), y = read(), z = read();       to[++cnt] = y, nxt[cnt] = fir[x], fir[x] = cnt, wi[cnt] = z;       to[++cnt] = x, nxt[cnt] = fir[y], fir[y] = cnt, wi[cnt] = z;     }     dfs(1, 0);     Dfs(1, 0, 0);     for (int i = 1; i <= n; i++) c[i] = (node){i, f[i]};     sort(c + 1, c + n + 1, cmp);     DFS(c[1].id, 0);     q = read();     for (int i = 1; i <= q; i++) {       z = read();       for (int i = 1; i <= n; i++) fa[i] = i;       for (int i = 1; i <= n; i++) size[i] = 1;       int r = n, ans = 0;       for (int j = n; j >= 1; j--) {         while (r && c[r].val - c[j].val > z) size[find(c[r].id)]--, r--;         ans = max(ans, size[find(c[j].id)]);         int u = find(c[j].id), v = find(Fa[c[j].id]);         if (u != v) fa[u] = v, size[v] += size[u];       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char buf[1 << 20], *p1 = buf, *p2 = buf;   template <typename T>   void read(T &x) {     x = 0;     bool f = 1;     char c =         (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)              ? EOF              : *p1++);     for (; !isdigit(c);          c = (p1 == p2 &&                       (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)                   ? EOF                   : *p1++))       if (c ==  - ) f = 0;     if (f)       for (; isdigit(c);            c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin),                             p1 == p2)                     ? EOF                     : *p1++))         x = x * 10 - 48 + c;     else       for (; isdigit(c);            c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin),                             p1 == p2)                     ? EOF                     : *p1++))         x = x * 10 + 48 - c;   }   template <typename T, typename... Args>   void read(T &t, Args &...args) {     read(t), read(args...);   }   const int N = 5e3 + 5;   int n, a[N];   int raw, mn, cnt, f[N][N], g[N][N];   int qf(int i, int l, int r) { return f[i][r] - f[i][l - 1]; }   int qg(int i, int l, int r) { return g[i][l] - g[i][r + 1]; }   int main() {     read(n);     for (int i = 1; i <= n; ++i) read(a[i]);     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j) raw += a[i] > a[j];     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) f[i][j] = a[j] > a[i], g[i][j] = a[j] < a[i];       for (int j = 1; j <= n; ++j) f[i][j] += f[i][j - 1];       for (int j = n; j >= 1; --j) g[i][j] += g[i][j + 1];     }     for (int i = 1; i <= n; ++i)       for (int j = i + 1; j <= n; ++j) {         int cur = qf(i, i + 1, j - 1) - qg(i, i + 1, j - 1) -                   qf(j, i + 1, j - 1) + qg(j, i + 1, j - 1) +                   (a[i] < a[j] ? 1 : -1);         if (cur < mn)           mn = cur, cnt = 1;         else if (cur == mn)           ++cnt;       }     printf( %d %d , raw + mn, cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 150, M = 65;   int n;   int dist[N][N], g[N][N];   vector<long long> v[M];   map<long long, int> mp;   int main() {     memset(g, 0x3f, sizeof g);     memset(dist, 0x3f, sizeof dist);     cin >> n;     for (int i = 0; i < n; i++) {       long long t, x;       cin >> x;       t = x;       int cnt = 0;       while (t) {         if (t & 1) v[cnt].push_back(x);         t >>= 1;         cnt++;       }     }     int cnt = 0;     bool flag = false;     for (int i = 0; i <= 64; i++) {       int m = v[i].size();       if (!m)         continue;       else if (m > 2) {         flag = true;         break;       } else if (m == 2) {         long long x = v[i][0], y = v[i][1];         if (!mp[x]) mp[x] = ++cnt;         if (!mp[y]) mp[y] = ++cnt;         x = mp[x], y = mp[y];         g[x][y] = g[y][x] = 1;         dist[x][y] = dist[y][x] = 1;       }     }     if (flag)       cout << 3 << endl;     else {       int res = 0x3f3f3f3f;       for (int k = 1; k <= cnt; k++) {         for (int i = 1; i < k; i++)           if (g[k][i] == 1)             for (int j = i + 1; j < k; j++)               if (g[k][j] == 1)                 if (dist[i][j] != 0x3f3f3f3f)                   res = min(res, dist[i][j] + g[i][k] + g[j][k]);         for (int i = 1; i <= cnt; i++)           if (dist[i][k] != 0x3f3f3f3f)             for (int j = 1; j <= cnt; j++)               if (dist[k][j] != 0x3f3f3f3f)                 dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);       }       if (res != 0x3f3f3f3f)         cout << res << endl;       else         cout << -1 << endl;     }   }