malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void debug_out() { cerr << endl; }   template <class T>   ostream& prnt(ostream& out, T v) {     out << v.size() <<   n ;     for (auto e : v) out << e <<    ;     return out;   }   template <class T>   ostream& operator<<(ostream& out, vector<T> v) {     return prnt(out, v);   }   template <class T>   ostream& operator<<(ostream& out, set<T> v) {     return prnt(out, v);   }   template <class T1, class T2>   ostream& operator<<(ostream& out, map<T1, T2> v) {     return prnt(out, v);   }   template <class T1, class T2>   ostream& operator<<(ostream& out, pair<T1, T2> p) {     return out <<  (  << p.first <<     << p.second <<  ) ;   }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << H;     debug_out(T...);   }   const long double PI = acos(-1);   int n, m, c, st[2 * 20005], dr[2 * 20005], a, b;   bool uz[20005];   vector<int> v[2 * 20005];   bool cup(int nod) {     uz[nod] = 1;     for (auto it : v[nod]) {       if (!dr[it]) {         dr[it] = nod;         st[nod] = it;         return 1;       }     }     for (auto it : v[nod]) {       if (!uz[dr[it]] && cup(dr[it])) {         dr[it] = nod;         st[nod] = it;         return 1;       }     }     return 0;   }   struct edge {     int a, b, c;   };   vector<edge> E2;   int _try(int x) {     for (int i = 0; i <= 2 * n + 1; i++) {       v[i].clear();     }     memset(st, 0, sizeof(st));     memset(dr, 0, sizeof(dr));     for (auto it : E2) {       if (it.c > x) continue;       v[it.a].push_back(it.b);       v[it.b].push_back(it.a);     }     int ok = 1;     while (ok) {       ok = 0;       memset(uz, 0, sizeof(uz));       for (int i = 1; i <= n; i++)         if (!st[i] && !uz[i]) ok |= cup(i);     }     int nr = 0;     for (int i = 1; i <= n; i++)       if (st[i]) nr++;     return nr == n;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (long long i = 1; i <= m; i++) {       int p, q, c;       cin >> p >> q >> c;       q += n;       E2.push_back({p, q, c});     }     int p = 1, st = 0;     for (; p <= 1e9; p <<= 1)       ;     for (; p >= 1; p >>= 1) {       if (st + p < 1e9 && !_try(st + p)) {         st += p;       }     }     st++;     if (!_try(st)) {       cout <<  -1 n ;     } else       cout << st <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[10][5];   int ulx, uly, drx, dry;   bool isd(int x, int y) { return x <= drx && x >= ulx && y <= dry && y >= uly; }   bool vis[210];   int numtot;   int pos;   int len;   int abs(int x) { return x < 0 ? -x : x; }   bool isd2(int x, int y) {     return abs(x - a[pos][2]) + abs(y - a[pos + 1][2] + len) <= len;   }   bool crss(int a, int b, int c, int d, int e, int f, int g, int h) {     if (a > c) swap(a, c);     if (b > d) swap(b, d);     if (e > g) swap(e, g), swap(f, h);     if (b == d) {       if (h > f) return b >= f && b <= h && e + b - f >= a && e + b - f <= c;       return b >= h && b <= f && e + f - b >= a && e + f - b <= c;     }     if (h > f) return a >= e && a <= g && f + a - e >= b && f + a - e <= d;     return a >= e && a <= g && f + e - a >= b && f + e - a <= d;   }   int main() {     int tmp = -0x7fffffff;     for (int k = 1; k <= 2; k++)       for (int i = 1; i <= 8; i++) scanf( %d , &a[i][k]);     for (int i = 1; i <= 8; i += 2)       if (!vis[a[i][1] + 101]) numtot++, vis[a[i][1] + 101] = true;     if (numtot > 2)       for (int i = 1; i <= 8; i++) swap(a[i][1], a[i][2]);     ulx = min(a[1][1], a[5][1]);     uly = min(a[2][1], a[6][1]);     drx = max(a[1][1], a[5][1]);     dry = max(a[2][1], a[6][1]);     if (isd(a[1][2], a[2][2]) && isd(a[3][2], a[4][2]) && isd(a[5][2], a[6][2]) &&         isd(a[7][2], a[8][2]))       return puts( yes ), 0;     for (int i = 2; i <= 8; i += 2)       if (a[i][2] > tmp) tmp = a[i][2], pos = i - 1;     len = abs(a[pos - 2 < 1 ? pos - 2 + 8 : pos - 2][2] -               a[pos + 2 > 8 ? pos + 2 - 8 : pos + 2][2]) /           2;     if (isd2(a[1][1], a[2][1]) && isd2(a[3][1], a[4][1]) &&         isd2(a[5][1], a[6][1]) && isd2(a[7][1], a[8][1]))       return puts( yes ), 0;     for (int i = 1; i <= 4; i++)       for (int j = 1; j <= 4; j++)         if (crss(a[i * 2 - 1][1], a[i * 2][1],                  a[(i + 1 == 5 ? 1 : i + 1) * 2 - 1][1],                  a[(i + 1 == 5 ? 1 : i + 1) * 2][1], a[j * 2 - 1][2], a[j * 2][2],                  a[(j + 1 == 5 ? 1 : j + 1) * 2 - 1][2],                  a[(j + 1 == 5 ? 1 : j + 1) * 2][2]))           return puts( yes ), 0;     return puts( no ), 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, S, T, du[10010];   struct edge {     int u, v, cap, flow;     edge() {}     edge(int u, int v, int c, int f) : u(u), v(v), cap(c), flow(f) {}   };   vector<edge> edges;   vector<int> e[10010];   inline void add_edge(int u, int v, int c) {     edges.push_back(edge(u, v, c, 0));     edges.push_back(edge(v, u, 0, 0));     int m = edges.size();     e[u].push_back(m - 2);     e[v].push_back(m - 1);   }   int vis[10010], dis[10010], cur[10010];   bool bfs(int s, int t) {     memset(vis, 0, sizeof(vis));     queue<int> que;     que.push(s);     vis[s] = 1;     dis[s] = 0;     while (!que.empty()) {       int now = que.front();       que.pop();       for (int i = 0; i < (e[now].size()); i++) {         edge& nxt = edges[e[now][i]];         if (!vis[nxt.v] && nxt.cap > nxt.flow) {           vis[nxt.v] = 1;           dis[nxt.v] = dis[now] + 1;           que.push(nxt.v);         }       }     }     return vis[t];   }   int dfs(int st, int t, int low) {     if (st == t || low == 0) return low;     int flow = 0, f;     for (int& i = cur[st]; i < e[st].size(); i++) {       edge& nxt = edges[e[st][i]];       if (dis[nxt.v] == dis[st] + 1 &&           (f = dfs(nxt.v, t, min(low, nxt.cap - nxt.flow))) > 0) {         nxt.flow += f;         edges[e[st][i] ^ 1].flow -= f;         flow += f;         low -= f;         if (low == 0) break;       }     }     return flow;   }   int Dinic(int s, int t) {     int ans = 0;     while (bfs(s, t)) {       memset(cur, 0, sizeof(cur));       ans += dfs(s, t, 0x3f3f3f3f);     }     return ans;   }   pair<int, int> pp[10010];   bool check(int mid) {     edges.clear();     for (int i = 0; i <= n + m + 1; i++) e[i].clear();     for (int i = 1; i <= m; i++) {       add_edge(S, i, 1);       add_edge(i, m + pp[i].first, 1);       add_edge(i, m + pp[i].second, 1);     }     for (int i = 1; i <= n; i++) add_edge(m + i, T, min(du[i], mid));     int ans = Dinic(S, T);     if (ans < m) return false;     return true;   }   int main() {     scanf( %d %d , &n, &m);     S = 0, T = n + m + 1;     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d %d , &u, &v);       pp[i] = make_pair(u, v);       du[u]++;       du[v]++;     }     int L = 1, R = min(m, n - 1), ans = min(m, n - 1);     while (L <= R) {       int mid = (L + R) >> 1;       if (check(mid)) {         ans = mid;         R = mid - 1;       } else         L = mid + 1;     }     printf( %d n , ans);     check(ans);     int tmp = 0;     for (int i = 0; i < edges.size(); i += 2) {       if (edges[i].u <= m && edges[i].u >= 1 && edges[i].v >= m + 1 &&           edges[i].v <= n + m && edges[i].cap == edges[i].flow) {         int nxt = pp[edges[i].u].first;         if (nxt == edges[i].v - m) nxt = pp[edges[i].u].second;         printf( %d %d n , edges[i].v - m, nxt);       }     }   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int N = 1005;   int n, m;   int a[N], ans[N], pre[N];   int main() {     int i, j, k, t, nc = 0;     while (scanf( %d%d , &n, &m) != EOF) {       int tmin = -1, tpre = -1;       for (i = 1; i <= m; i++) {         scanf( %d , &a[i]);         if (tmin < a[i]) {           k = i;           tmin = a[i];         }       }       bool work = true;       ans[1] = k;       a[k]--;       for (i = 1; i <= m; i++) pre[i] = N;       pre[k] = 1;       for (i = 2; i < n; i++) {         tmin = -1;         for (j = 1; j <= m; j++) {           if (a[j] == 0 || j == ans[i - 1]) continue;           if (tmin < a[j] || tmin == a[j] && pre[j] < tpre) {             k = j;             tmin = a[j];             tpre = pre[j];           }         }         if (tmin == N) break;         ans[i] = k;         a[k]--;         pre[k] = i;       }       if (i < n)         work = false;       else {         for (i = 1; i <= m; i++) {           if (a[i] > 0 && i != ans[1] && i != ans[n - 1]) {             ans[n] = i;             break;           }         }         if (i > m) work = false;       }       if (!work)         printf( -1 n );       else {         for (i = 1; i <= n; i++) {           printf( %d , ans[i]);           if (i < n)             printf(   );           else             printf(  n );         }       }     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   class FKuroniAndThePunishment {    public:     vector<long long> primes;     void pre(int n) {       vector<bool> isPrime(n + 1, true);       isPrime[1] = false;       isPrime[0] = false;       for (int i = 2; i <= n; i++) {         if (isPrime[i])           for (int j = 2 * i; j <= n; j += i) isPrime[j] = false;         if (isPrime[i]) primes.push_back(i);       }     }     void solve(std::istream &in, std::ostream &out) {       int n;       in >> n;       vector<long long> ar(n);       for (long long &i : ar) in >> i;       long long mn = LLONG_MIN;       for (long long i : ar) mn = max(mn, i);       pre(1000000);       int idx = primes.size();       for (long long i = max(1ll, mn - n); i <= mn + n; i++) primes.push_back(i);       long long first = primes[idx];       for (int i = 0; i < idx; i++) {         long long index =             idx + (first % primes[i] == 0 ? 0 : primes[i] - (first % primes[i]));         for (long long j = index; j < primes.size(); j += primes[i])           while (primes[j] % primes[i] == 0) primes[j] /= primes[i];       }       long long ans = n;       for (long long &i : primes) {         if (i == 1) continue;         long long res = 0;         for (long long &j : ar) {           if (j < i)             res += (i - j);           else             res += min(j % i, (i - (j % i)));           if (res >= ans) break;         }         ans = min(ans, res);       }       out << ans <<   n ;     }   };   int main() {     FKuroniAndThePunishment solver;     std::ios_base::sync_with_stdio(false);     cin.tie(NULL);     std::istream &in(std::cin);     std::ostream &out(std::cout);     solver.solve(in, out);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   int n, k, now, last;   long long dp[2][505][505], sum[505], ans = 0, s;   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> k;     memset(dp[1], 0, sizeof dp[1]);     dp[1][1][1] = 1;     for (int i = 2; i <= n; i++) {       now = i & 1;       last = now ^ 1;       memset(dp[now], 0, sizeof dp[now]);       for (int j = 1; j < i; j++) {         for (int k = 1; k < i; k++) {           if (j != k)             dp[now][j][k + 1] = (dp[now][j][k + 1] + dp[last][j][k]) % mod;           else             dp[now][j + 1][k + 1] =                 (dp[now][j + 1][k + 1] + dp[last][j][k]) % mod;           dp[now][j][1] = (dp[now][j][1] + dp[last][j][k]) % mod;         }       }     }     memset(sum, 0, sizeof sum);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= i; j++) sum[i] = (sum[i] + dp[now][i][j]) % mod;     s = 0;     for (int i = 1; i <= n; i++) s = (s + sum[i]) % mod;     int t = n;     for (int i = 1; i <= n; i++) {       while (t * i >= k) {         s = (s - sum[t] + mod) % mod;         t--;       }       ans = (ans + sum[i] * s % mod) % mod;     }     ans = ans * 2 % mod;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool poss = true;   int n, rt = 0;   vector<int> v, res;   vector<vector<int>> adj;   vector<pair<int, int>> dfs(int second, int p) {     vector<pair<int, int>> cur;     for (auto i : adj[second]) {       if (i != p) {         vector<pair<int, int>> ch = dfs(i, second);         for (auto i : ch) {           cur.push_back(i);         }       }     }     sort(cur.begin(), cur.end());     for (int i = 0; i < cur.size(); ++i) {       if (i < v[second])         cur[i].first = i;       else         cur[i].first = i + 1;     }     if (v[second] > cur.size()) poss = false;     cur.push_back({v[second], second});     return cur;   }   int main() {     cin >> n;     adj.assign(n, vector<int>());     v.assign(n, 0);     res.assign(n, 0);     for (int i = 0; i < n; ++i) {       int x;       cin >> x >> v[i];       x--;       if (x != -1) {         adj[x].push_back(i);         adj[i].push_back(x);       } else         rt = i;     }     vector<pair<int, int>> cur = dfs(rt, rt);     for (auto i : cur) {       res[i.second] = i.first + 1;     }     if (!poss) {       cout <<  NO ;       return 0;     }     cout <<  YES n ;     for (auto i : res) {       cout << i <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q;   struct matrix {     int val;   } matr[109][109];   matrix* mat[109][109];   int main() {     scanf( %d %d %d , &n, &m, &q);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         matr[i][j].val = 0;         mat[i][j] = &matr[i][j];       }     int t1, t2, t3, t4, t5;     matrix* tmp;     for (int i = 0; i < q; i++) {       scanf( %d , &t1);       if (t1 == 1) {         scanf( %d , &t2);         tmp = mat[t2][1];         for (int j = 1; j < m; j++) {           mat[t2][j] = mat[t2][j + 1];         }         mat[t2][m] = tmp;       } else if (t1 == 2) {         scanf( %d , &t2);         tmp = mat[1][t2];         for (int i = 1; i < n; i++) {           mat[i][t2] = mat[i + 1][t2];         }         mat[n][t2] = tmp;       } else if (t1 == 3) {         scanf( %d %d %d , &t3, &t4, &t5);         mat[t3][t4]->val = t5;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         printf( %d  , matr[i][j].val);       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   const int maxpow = 1 << 17;   const int inf = 1e9 + 7;   long long h[maxn];   int par[maxn];   struct node {     pair<int, int> a;     node(pair<int, int> _a) : a(_a) {}     node() : a(0, -1) {}     void merge(node x, node y) { a = max(x.a, y.a); }   };   node tree[maxpow * 2];   node query(int i, int ns, int ne, int qs, int qe) {     if (qe <= ns || qs >= ne) {       return node();     }     if (ns >= qs && ne <= qe) {       return tree[i];     }     int mid = (ns + ne) / 2;     node res1 = query(2 * i, ns, mid, qs, qe);     node res2 = query(2 * i + 1, mid, ne, qs, qe);     node res;     res.merge(res1, res2);     return res;   }   void update(int i, int ns, int ne, int qs, pair<int, int> v) {     if (qs + 1 <= ns || qs >= ne) {       return;     }     if (ns + 1 == ne) {       tree[i] = node(v);       return;     }     int mid = (ns + ne) / 2;     update(2 * i, ns, mid, qs, v);     update(2 * i + 1, mid, ne, qs, v);     tree[i].merge(tree[2 * i], tree[2 * i + 1]);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, d;     cin >> n >> d;     vector<long long> a;     for (long long i = 0; i < n; i++) {       cin >> h[i];       a.push_back(h[i]);     }     sort(a.begin(), a.end());     a.erase(unique(a.begin(), a.end()), a.end());     pair<int, int> mx(-1, -1);     for (int i = 0; i < n; i++) {       int left = lower_bound(a.begin(), a.end(), h[i] - d + 1) - a.begin();       int right = lower_bound(a.begin(), a.end(), h[i] + d) - a.begin();       int cur = lower_bound(a.begin(), a.end(), h[i]) - a.begin();       node ans1 = query(1, 0, maxpow, 0, left);       node ans2 = query(1, 0, maxpow, right, n);       pair<int, int> ans = max(ans1.a, ans2.a);       ans.first += 1;       par[i] = ans.second;       ans.second = i;       mx = max(mx, ans);       update(1, 0, maxpow, cur, ans);     }     cout << mx.first << endl;     int ind = mx.second;     vector<int> res;     while (ind != -1) {       res.push_back(ind);       ind = par[ind];     }     reverse(res.begin(), res.end());     for (int i = 0; i < res.size(); i++) {       cout << res[i] + 1 <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, r = 0, l = 0;     vector<int> d;     cin >> n;     d.resize(n);     for (int i = 0; i < n; ++i) {       int x, y;       cin >> x >> y;       l += x;       r += y;       d[i] = x - y;     }     int maxx = abs(r - l), n_max = -1;     for (int i = 0; i < n; ++i) {       int dl = l - d[i], dr = r + d[i];       if (abs(dr - dl) > maxx) {         maxx = abs(dr - dl);         n_max = i + 1;       }     }     if (n_max == -1)       cout << 0 << endl;     else       cout << n_max;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int TC;     cin >> TC;     while (TC--) {       int p, f, cnts, cntw, s, w;       cin >> p >> f >> cnts >> cntw >> s >> w;       if (s < w) {         swap(s, w);         swap(cnts, cntw);       }       int maxi = 0;       for (int i = 0; i <= min(p / w, cntw); i++) {         int pw = i;         int ps = min((p - i * w) / s, cnts);         int fw, fs;         int cntW = cntw - i;         int cntS = cnts - ps;         fw = min(cntW, f / w);         if (f / w > cntW) {           fs = min(cntS, (f - cntW * w) / s);         } else {           fs = 0;         }         int total = ps + pw + fs + fw;         maxi = max(maxi, total);       }       cout << maxi <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<bool> vis;   vector<vector<long long>> adj;   void dfs(long long node) {     vis[node] = true;     for (long long child : adj[node]) {       if (vis[child]) continue;       dfs(child);     }   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long> arr(n - 1);     vector<long long> deg(n + 1, 1);     for (long long i = 0; i < n - 1; ++i) {       cin >> arr[i];       ++deg[arr[i]];     }     set<pair<long long, long long>> st;     for (long long i = 1; i <= n; ++i) {       if (deg[i] == 1) {         st.insert({i, i});       }     }     cout << arr[0] <<   n ;     for (long long i = n - 2; i >= 0; --i) {       const long long node = arr[i];       auto it = st.begin();       long long currMx = it->first;       long long currRoot = it->second;       st.erase(it);       cout << currRoot <<     << node <<   n ;       --deg[node];       if (deg[node] == 1) {         st.insert({max(currMx, node), node});       }     }   }
#include <bits/stdc++.h>   using namespace std;   static const double EPS = 1e-10;   template <typename T, typename S>   vector<T>& operator<<(vector<T>& a, S b) {     a.push_back(b);     return a;   }   template <typename T>   void operator>>(vector<T>& a, int b) {     while (b--)       if (!a.empty()) a.pop_back();   }   bool isprime(int n) {     if (n < 2) return false;     for (int i = 2; i * i <= n; i++)       if (n % i == 0) return false;     return true;   }   long long b_pow(long long x, long long n) {     return n ? b_pow(x * x, n / 2) * (n % 2 ? x : 1) : 1ll;   }   string itos(int n) {     stringstream ss;     ss << n;     return ss.str();   }   string read() {     string s;     char c;     while (cin >> c && c !=  > ) s += c;     if (s.size() == 0) exit(0);     return s.substr(1);   }   int f(string s) { return s[0] ==  / ; }   string get(string s) {     if (s[0] ==  / ) return s.substr(1);     return s;   }   int main() {     ios_base::sync_with_stdio(false);     int n, m, ret = 0;     stack<string> s;     while (1) {       string t = read();       if (t ==   ) return 0;       if (s.size() == 0 || (!f(t) || get(s.top()) != get(t))) {         cout << string(s.size() * 2,    ) <<  <  << t <<  >  << endl;         s.push(t);       } else {         s.pop();         cout << string(s.size() * 2,    ) <<  <  << t <<  >  << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long ti;     cin >> ti;     for (long long io = 0; io < ti; io++) {       long long n, m;       cin >> n >> m;       vector<long long> a, ao, b;       for (long long i = 0; i < m; i++) {         long long x, y;         cin >> x >> y;         a.push_back(x);         ao.push_back(x);         b.push_back(y);       }       sort(a.begin(), a.end());       long long sf[m + 1];       long long sm = 0;       for (long long i = m - 1; i >= 0; i--) {         sm += a[i];         sf[m - i] = sm;       }       long long ans = 0;       if (n <= m) ans = sf[n];       for (long long i = 0; i < m; i++) {         long long v = b[i];         long long idx = upper_bound(a.begin(), a.end(), v) - a.begin() + 1;         long long avl = m - idx + 1;         if (idx > m) {           ans = max(ans, ao[i] + (n - 1) * b[i]);         } else if (avl < n) {           long long as = 0;           as = as + sf[avl];           long long rm = n - avl;           if (ao[i] <= b[i]) {             as += ao[i];             rm--;           }           as += rm * b[i];           ans = max(ans, as);         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct ed {     int a, b, w;   } p[600010];   int n, m, fa[600010], d[600010], ans;   bool cmp(ed a, ed b) { return (a.w > b.w); }   int gf(int x) { return (fa[x] != x) ? fa[x] = gf(fa[x]) : x; }   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) cin >> p[i].a >> p[i].b >> p[i].w;     sort(p + 1, p + m + 1, cmp);     for (int i = 1; i <= n; i++) fa[i] = i, d[i] = 1;     for (int i = 1; i <= m; i++) {       int x = gf(p[i].a), y = gf(p[i].b);       if (x != y && d[x] + d[y] > 0)         fa[y] = x, ans += p[i].w, d[x] = d[x] & d[y];       else if (x == y && d[x]) {         d[x] = 0, ans += p[i].w;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   int arr[100005];   int k;   void unsort(int left, int right) {     if (k <= 0 || left >= right - 1) return;     int mid = (left + right) / 2;     std::swap(arr[mid - 1], arr[mid]);     --k;     unsort(left, mid);     unsort(mid, right);   }   int main() {     int n;     scanf( %d%d , &n, &k);     if (k % 2 == 0 || k > 2 * n) {       printf( -1 n );       return 0;     }     for (int i = 0; i < n; ++i) {       arr[i] = i + 1;     }     k /= 2;     unsort(0, n);     for (int i = 0; i < n; ++i) {       printf( %d  , arr[i]);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, i, j, res = 0, k, v1, v2;     cin >> n;     vector<long long> v;     for (i = 0; i < n; i++) {       cin >> j;       v.emplace_back(j);     }     if (n == 1) {       cout << v[0] <<   n ;       return 0;     } else if (n == 2) {       cout << (v[0] | v[1]) <<   n ;       return 0;     }     for (i = 0; i < n; i++) {       for (j = i + 1; j < n; j++) {         v2 = v[i] | v[j];         for (k = j + 1; k < n; k++) {           v1 = v2 | v[k];           res = max(res, v1);         }       }     }     cout << res <<   n ;     return 0;   }