malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, i, j, A[200005], s = 1;     cin >> n;     for (long long(i) = 0; (i) < (n); (i) = (i + 1)) {       cin >> A[i];       if (A[i] == n) {         k = i;       }     }     for (j = k; j < n - 1; j++) {       if (A[j] < A[j + 1]) {         s = 0;         break;       }     }     if (s != 0) {       for (j = k; j > 0; j--) {         if (A[j] < A[j - 1]) {           s = 0;           break;         }       }       s == 0 ? cout <<  NO  : cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   const int maxN = 2005;   int a[maxN][maxN];   int b[maxN][maxN];   vector<pair<int, int>> by[maxN];   const int dx[3] = {-1, 0, 0};   const int dy[3] = {0, -1, 1};   int his_val[maxN];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     if (n % 2 == 1) {       cout <<  NONE ;       return 0;     }     for (int j = 0; j < n; j++) {       a[0][j] = j / 2;       b[0][j] = 0;     }     for (int i = 0; i + 1 < n; i++) {       for (int j = 0; j < n; j++) {         int xr = 0;         int c = 0;         vector<int> vals;         vals.emplace_back(a[i][j]);         for (int z = 0; z < 3; z++) {           int ni = i + dx[z];           int nj = j + dy[z];           if (ni < 0 || ni >= n) continue;           if (nj < 0 || nj >= n) continue;           vals.emplace_back(a[ni][nj]);         }         int cnt = 0;         int he = -1;         sort(vals.begin(), vals.end());         vals.erase(unique(vals.begin(), vals.end()), vals.end());         for (int& t : vals) {           int pp = 0;           for (int z = 0; z < 3; z++) {             int ni = i + dx[z];             int nj = j + dy[z];             if (ni < 0 || ni >= n) continue;             if (nj < 0 || nj >= n) continue;             if (a[ni][nj] == t) pp ^= 1;             if (a[i][j] == t) pp ^= 1;           }           if (pp && t != a[i][j]) {             cnt++;             he = t;           }         }         assert(cnt == 0 || cnt == 1);         if (cnt == 0)           a[i + 1][j] = a[i][j];         else           a[i + 1][j] = he;         int pp = 0;         for (int z = 0; z < 3; z++) {           int ni = i + dx[z];           int nj = j + dy[z];           if (ni < 0 || ni >= n) continue;           if (nj < 0 || nj >= n) continue;           pp ^= b[ni][nj];           pp ^= b[i][j];           pp ^= 1;         }         b[i + 1][j] = (pp ^ 1) ^ b[i][j];       }     }     memset(his_val, -1, sizeof his_val);     bool ok = true;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         char c;         cin >> c;         if (c ==  . ) continue;         int d = 0;         if (c ==  S )           d = 0;         else           d = 1;         d ^= b[i][j];         if (his_val[a[i][j]] == -1) his_val[a[i][j]] = d;         if (his_val[a[i][j]] != d) ok = false;       }     }     if (!ok) {       cout <<  NONE n ;       return 0;     }     bool hs = false;     for (int z = 0; z < n / 2; z++) {       if (his_val[z] == -1) hs = true;     }     if (hs) {       cout <<  MULTIPLE n ;       return 0;     }     cout <<  UNIQUE n ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         int d = his_val[a[i][j]] ^ b[i][j];         if (d == 0)           cout <<  S ;         else           cout <<  G ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   constexpr int N = 1e6 + 10;   constexpr int M = 30;   long long a1 = 2, a2 = 4, n, ans = 2, t = 4, dis[N], dp[N][M], v, dist1, dist2;   int get_lca(int a, int b) {     if (dis[a] < dis[b]) swap(a, b);     while (dis[a] != dis[b]) a = dp[a][(int)log2(dis[a] - dis[b])];     for (int i = M - 1; i >= 0; i--) {       if (a == b)         return a;       else if (dp[a][i] != dp[b][i]) {         a = dp[a][i];         b = dp[b][i];         return get_lca(a, b);       }     }     return dp[a][0];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     dp[2][0] = 1;     dp[3][0] = 1;     dp[4][0] = 1;     dis[2] = dis[3] = dis[4] = 1;     for (int i = 0; i < n; i++) {       cin >> v;       dp[++t][0] = v;       dp[++t][0] = v;       dis[t - 1] = dis[v] + 1;       dis[t] = dis[v] + 1;       for (int j = 1; j < M; j++) {         dp[t - 1][j] = dp[dp[t - 1][j - 1]][j - 1];         dp[t][j] = dp[dp[t][j - 1]][j - 1];       }       dist1 = dis[t] + dis[a1] - 2 * dis[get_lca(t, a1)];       dist2 = dis[t] + dis[a2] - 2 * dis[get_lca(t, a2)];       if (dist1 >= dist2 && dist1 > ans) {         ans = dist1;         a2 = t;       } else if (dist2 > dist1 && dist2 > ans) {         ans = dist2;         a1 = t;       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<long long> v, z;     long long n, i, j, k;     cin >> n;     while (n != 0) {       v.push_back(n % 10);       n = n / 10;     }     long long p = 1;     for (i = 0; i < v.size(); i++) {       p = p * v[i];     }     z.push_back(p);     for (i = 0; i < v.size() - 1; i++) {       if (v[i] != 9) {         for (j = i + 1; j < v.size(); j++) {           if (v[j] > 0) {             v[j]--;             break;           }         }         if (j != v.size()) {           for (k = i; k < j; k++) {             v[k] = 9;           }         }         p = 1;         for (k = 0; k < v.size() - 1; k++) {           p = p * v[k];         }         if (v[v.size() - 1] != 0) p = p * v[v.size() - 1];         z.push_back(p);       }     }     long long max = 0;     for (i = 0; i < z.size(); i++) {       if (z[i] > max) max = z[i];     }     cout << max;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> road_wt[2 * 100000 + 5];   vector<int> rail_wt[2 * 100000 + 5];   vector<int> road[2 * 100000 + 5];   vector<int> rail[2 * 100000 + 5];   int visited[2 * 100000 + 5];   struct r {     int city;     signed long long int cost;     int type;     r() {}     r(int c, signed long long int co, int t) {       city = c;       cost = co;       type = t;     }   };   signed long long int cost[100000 + 5];   bool way(r a, r b) { return a.cost > b.cost; }   struct OrderBy {     bool operator()(struct r a, struct r b) {       return a.cost > b.cost or a.cost == b.cost and a.type < b.type;     }   };   priority_queue<struct r, std::vector<struct r>, OrderBy> q;   int main() {     int n, k, m, a, b, s;     signed long long int w, y;     cin >> n >> m >> k;     for (int i = 1; i <= m; ++i) {       cin >> a >> b >> w;       road[a].push_back(b);       road[b].push_back(a);       road_wt[a].push_back(w);       road_wt[b].push_back(w);     }     for (int i = 1; i <= k; ++i) {       cin >> s >> y;       rail[1].push_back(s);       rail_wt[1].push_back(y);     }     q.push(r(1, 0, 0));     int ans = 0;     while (!q.empty()) {       r temp = q.top();       int v = temp.city;       q.pop();       if (visited[v]) continue;       visited[v] = 1;       cost[v] = temp.cost;       if (temp.type == 1) ++ans;       for (int i = 0; i < road[v].size(); ++i) {         int u = road[v][i];         if (visited[u]) continue;         q.push(r(u, temp.cost + road_wt[v][i], 2));       }       for (int i = 0; i < rail[v].size(); ++i) {         int u = rail[v][i];         if (visited[u]) continue;         q.push(r(u, temp.cost + rail_wt[v][i], 1));       }     }     cout << k - ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int qtn;     cin >> qtn;     vector<long long int> resp(qtn + 1);     resp[qtn] = 1000000000000000010;     for (int i = 0; i < qtn >> 1; i++) {       long long int n;       cin >> n;       resp[qtn - i - 1] = min(resp[qtn - i], n);       resp[i] = n - resp[qtn - i - 1];       if (i) {         if (resp[i] < resp[i - 1]) {           resp[i] = resp[i - 1];           resp[qtn - i - 1] = n - resp[i];         }       }     }     for (int i = 0; i < qtn; i++) {       cout << resp[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[26], l[26], n, k, x, se, t;   char b;   string s;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> b >> s;       if (x == 1) {         if (i == n - 1) break;         if (b !=  . ) se++;         continue;       }       if (b !=  ? )         for (int j = 0; j < s.size(); j++) l[s[j] -  a ]++;       if (b ==  ! ) {         for (int j = 0; j < s.size(); j++) {           a[s[j] -  a ]++;         }       }       if (b ==  . ) {         for (int j = 0; j < s.size(); j++) {           a[s[j] -  a ]--;         }       }       if (b ==  ?  && i != n - 1) a[s[0] -  a ]--;       if (b !=  ? )         for (int j = 0; j < 26; j++) {           if (l[j] > 1) a[j] = a[j] - l[j] + 1;           l[j] = 0;         }       k = 0;       for (int j = 0; j < 26; j++) k = max(a[j], k);       for (int j = 0; j < 26; j++)         if (a[j] == k) t++;       if (t == 1) x = 1;       t = 0;     }     cout << se;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int xs[8] = {1, 1, 1, 0, 0, -1, -1, -1};   int ys[8] = {-1, 0, 1, -1, 1, -1, 0, 1};   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int x1, y1, x2, y2;     cin >> x1 >> y1;     cin >> x2 >> y2;     int nx, ny;     int mV = INT_MAX;     for (int i = 0; i < 8; i++) {       nx = xs[i] + x2;       ny = ys[i] + y2;       mV = min(abs(nx - x1) + abs(ny - y1), mV);     }     cout << 2 * mV + 8 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long m, h1, a1, x1, y1, h2, a2, x2, y2;     long long p1, p2, q1, q2;     while (cin >> m >> h1 >> a1 >> x1 >> y1 >> h2 >> a2 >> x2 >> y2) {       p1 = p2 = q1 = q2 = 0;       for (long long i = 1; i <= 2 * m; i++) {         h1 = (h1 * x1 + y1) % m;         if (h1 == a1) {           if (p1 == 0)             p1 = i;           else if (q1 == 0) {             q1 = i - p1;             break;           }         }       }       for (long long i = 1; i <= 2 * m; i++) {         h2 = (h2 * x2 + y2) % m;         if (h2 == a2) {           if (p2 == 0)             p2 = i;           else if (q2 == 0) {             q2 = i - p2;             break;           }         }       }       if (p1 == 0 || p2 == 0) {         puts( -1 );         continue;       }       long long ans1 = p1, ans2 = p2;       long long i;       for (i = 1; i <= 2 * m; i++) {         if (ans1 == ans2) {           printf( %I64d n , ans1);           break;         }         if (ans1 > ans2) {           ans2 += q2;         }         if (ans1 < ans2) {           ans1 += q1;         }       }       if (i > 2 * m) {         puts( -1 );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, i, flag;     cin >> t;     while (t--) {       string s1, s2;       cin >> s1 >> s2;       flag = 0;       for (i = 0; i < s1.length(); i++) {         if (find(s2.begin(), s2.end(), s1[i]) == s2.end()) flag++;       }       if (flag == s1.length())         cout <<  NO  << endl;       else         cout <<  YES  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int a[30];   int main() {     int n;     cin >> n;     cin >> s;     for (int i = 0; i < n; i++) {       a[s[i] -  a ]++;     }     for (int i = 0; i < 26; i++) {       int temp = i;       for (int j = 0; j < a[temp]; j++) {         cout << char( a  + temp);       }     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MAXN = 1e3 + 5;   const int INF = 0x3f3f3f3f;   const double eps = 1e-9;   short int mp[MAXN][MAXN];   int d[MAXN][2];   bool vis[MAXN];   int n, m, s, t, u, v;   void dijkstra(int s, int idx) {     memset(vis, false, sizeof(vis));     for (int i = 1; i <= n; i++) d[i][idx] = INF;     d[s][idx] = 0;     for (int i = 0; i < n; i++) {       int x = -1, m = INF;       for (int j = 1; j <= n; j++)         if (!vis[j] && d[j][idx] < m) m = d[x = j][idx];       if (x != -1) {         vis[x] = true;         for (int j = 1; j <= n; j++) {           if (mp[x][j] == 1 && d[j][idx] > d[x][idx] + 1) {             d[j][idx] = d[x][idx] + 1;           }         }       }     }   }   int main() {     scanf( %d %d %d %d , &n, &m, &s, &t);     for (int i = 0; i < m; i++) {       scanf( %d %d , &u, &v);       mp[u][v] = mp[v][u] = 1;     }     dijkstra(s, 0);     dijkstra(t, 1);     int ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         if (mp[i][j] == 0 && d[i][0] + d[j][1] + 1 >= d[t][0] &&             d[i][1] + d[j][0] + 1 >= d[t][0])           ans++;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   void solve() {     int n, ans = 0;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];       ans = max(ans, a[i] - i - 1);     }     cout << ans <<   n ;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( -O3 )   struct vertex {     bool vis = false;     vector<pair<long long int, long long int> > adj;     long long int low = 1000000007;     long long int dp = 0;     long long int parent = -1;   };   long long int tim = 0, n, m;   vector<pair<long long int, long long int> > edges;   bool flag = false;   void dfs(vertex x[], long long int sor) {     x[sor].vis = true;     tim++;     x[sor].dp = tim;     x[sor].low = tim;     for (auto y : x[sor].adj) {       if (!x[y.first].vis) {         x[y.first].parent = sor;         dfs(x, y.first);         x[sor].low = min(x[sor].low, x[y.first].low);         if (x[y.first].low > x[sor].dp)           flag = true;         else           edges[y.second] = {sor, y.first};       } else if (y.first != x[sor].parent) {         x[sor].low = min(x[sor].low, x[y.first].dp);         if (x[y.first].dp < x[sor].dp) {           edges[y.second] = {sor, y.first};         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     vertex x[n];     for (long long int a = 0; a < m; a++) {       long long int u, v;       cin >> u >> v;       u--, v--;       x[u].adj.push_back({v, a});       x[v].adj.push_back({u, a});       edges.push_back({u, v});     }     dfs(x, 0);     if (flag)       cout << 0 << endl;     else       for (auto y : edges) cout << y.first + 1 <<     << y.second + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   int mod = 1000000000 + 7;   long long int inf = 1000000000000000000;   using namespace std;   mt19937 unlucko(chrono::steady_clock::now().time_since_epoch().count());   vector<int> tree[200000], way(200000), dp(200000), ans(200000);   void dfs(int node, int pnode) {     dp[node] = way[node];     for (auto it : tree[node]) {       if (it == pnode) continue;       dfs(it, node);       dp[node] += max(dp[it], 0);     }   }   void jfs(int node, int pnode, int curr) {     ans[node] = dp[node] + curr;     for (auto it : tree[node]) {       if (it == pnode) continue;       jfs(it, node, max(ans[node] - max(0, dp[it]), 0));     }   }   int main() {     iostream::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> way[i];       if (!way[i]) way[i]--;     }     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       --x;       y--;       tree[x].push_back(y);       tree[y].push_back(x);     }     dfs(0, 0);     jfs(0, 0, 0);     for (int i = 0; i < n; i++) cout << ans[i] <<    ;   }
#include <bits/stdc++.h>   constexpr int maxn = 2e5 + 5;   constexpr int inf = 1e9;   constexpr int mod = 1e9 + 7;   using namespace std;   using lint = long long;   using pii = pair<int, int>;   int t, n, a[maxn], b[maxn];   lint ans;   map<int, int> ma, mb;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> t;     while (t--) {       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a[i] >> b[i];         ma[a[i]]++;         mb[b[i]]++;       }       ans = 1ll * n * (n - 1) * (n - 2) / 6;       for (int i = 0; i < n; i++) ans -= 1ll * (ma[a[i]] - 1) * (mb[b[i]] - 1);       cout << ans <<   n ;       ma.clear();       mb.clear();     }   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> ad[200009];   long long vis[200009];   long long cnt, ans;   void dfs(int u) {     vis[u] = 1;     cnt++;     for (auto x : ad[u]) {       if (!vis[x]) dfs(x);     }   }   int main() {     long long i, j, k, l, m, n, u, v;     cin >> n >> k;     for (i = 0; i < k; i++) {       cin >> u >> v;       ad[u].push_back(v);       ad[v].push_back(u);     }     for (i = 1; i <= n; i++) {       if (ad[i].size() == 0) continue;       if (!vis[i]) {         cnt = 0;         dfs(i);         cnt--;         ans += cnt;       }     }     cout << k - ans <<   n ;   }
#include <bits/stdc++.h>   int query(int aa[][150 + 1], int l0, int l1, int r0, int r1) {     return l0 > l1 || r0 > r1 ? 0                               : ((long long)aa[l1][r1] - aa[l0 - 1][r1] -                                  aa[l1][r0 - 1] + aa[l0 - 1][r0 - 1]) %                                     1000000007;   }   void add(int aa[][150 + 1], int l, int r, int a) {     aa[l][r] = (aa[l][r] + a) % 1000000007;   }   int main() {     static int dp00[150 + 1][150 + 1], dp01[150 + 1][150 + 1],         dp10[150 + 1][150 + 1], dp11[150 + 1][150 + 1];     static int dq00[150 + 1][150 + 1], dq01[150 + 1][150 + 1],         dq10[150 + 1][150 + 1], dq11[150 + 1][150 + 1];     int n, m, l, r, ans;     scanf( %d%d , &n, &m);     ans = 0;     while (n--) {       for (l = 1; l <= m; l++)         for (r = 1; r <= m; r++) {           dp00[l][r] = (dp00[l][r] + dp00[l][r - 1]) % 1000000007;           dp01[l][r] = (dp01[l][r] + dp01[l][r - 1]) % 1000000007;           dp10[l][r] = (dp10[l][r] + dp10[l][r - 1]) % 1000000007;           dp11[l][r] = (dp11[l][r] + dp11[l][r - 1]) % 1000000007;         }       for (l = 1; l <= m; l++)         for (r = 1; r <= m; r++) {           dp00[l][r] = (dp00[l][r] + dp00[l - 1][r]) % 1000000007;           dp01[l][r] = (dp01[l][r] + dp01[l - 1][r]) % 1000000007;           dp10[l][r] = (dp10[l][r] + dp10[l - 1][r]) % 1000000007;           dp11[l][r] = (dp11[l][r] + dp11[l - 1][r]) % 1000000007;         }       for (l = 1; l <= m; l++)         for (r = 1; r <= m; r++)           dq00[l][r] = dq01[l][r] = dq10[l][r] = dq11[l][r] = 0;       for (l = 1; l <= m; l++)         for (r = l; r <= m; r++) {           dq00[l][r] = 1;           add(dq00, l, r, query(dp00, l, m, 1, r));           add(dq01, l, r, query(dp01, l, r, r, m));           add(dq01, l, r, query(dp00, l, r, r + 1, m));           add(dq10, l, r, query(dp10, 1, l, l, r));           add(dq10, l, r, query(dp00, 1, l - 1, l, r));           add(dq11, l, r, query(dp11, 1, l, r, m));           add(dq11, l, r, query(dp01, 1, l - 1, r, m));           add(dq11, l, r, query(dp10, 1, l, r + 1, m));           add(dq11, l, r, query(dp00, 1, l - 1, r + 1, m));           ans = (ans + (long long)dq00[l][r] + dq01[l][r] + dq10[l][r] +                  dq11[l][r]) %                 1000000007;         }       for (l = 0; l <= m; l++)         for (r = 0; r <= m; r++) {           dp00[l][r] = dq00[l][r];           dp01[l][r] = dq01[l][r];           dp10[l][r] = dq10[l][r];           dp11[l][r] = dq11[l][r];         }     }     if (ans < 0) ans += 1000000007;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 3e5;   const long long P = 1e9 + 7;   long long n;   long long col[N], f[N], g[N];   vector<long long> a[N];   long long read(void) {     long long s = 0, w = 0;     char c = getchar();     while (!isdigit(c)) w |= c ==  - , c = getchar();     while (isdigit(c)) s = s * 10 + c - 48, c = getchar();     return w ? -s : s;   }   void Dfs(long long x, long long fa) {     col[x] ? f[x] = 1 : g[x] = 1;     for (long long i = 0; i < a[x].size(); ++i) {       long long y = a[x][i];       if (y == fa) continue;       Dfs(y, x);       f[x] = (f[x] * (f[y] + g[y]) + g[x] * f[y]) % P;       g[x] = (g[x] * (f[y] + g[y])) % P;     }     return;   }   signed main(void) {     n = read();     for (long long i = 1; i < n; ++i) a[read()].push_back(i);     for (long long i = 0; i < n; ++i) col[i] = read();     Dfs(0, 0);     cout << f[0] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       int a[n], i, j, k, l, m;       string s, temp;       for (i = 0; i < n; i++) cin >> a[i];       char c =  a , d;       for (i = 0; i <= 50; i++) {         s +=  a ;       }       cout << s << endl;       for (i = 0; i < n; i++) {         k = a[i];         temp =   0 ;         for (j = 0; j < k; j++) {           temp += s[j];           c = s[j];         }         for (j = k; j <= 50; j++) {           if (s[j] !=  z ) {             d = s[j] + 1;           } else {             d =  a ;           }           temp += d;         }         s = temp;         cout << temp << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int k1, k2, k3;     cin >> k1 >> k2 >> k3;     int n = k1 + k2 + k3;     int maps[n];     for (int i = 0; i < n; i++) {       int inp;       cin >> inp;       inp--;       if (i < k1)         maps[inp] = 0;       else if (i < k1 + k2)         maps[inp] = 1;       else         maps[inp] = 2;     }     int costsk1[n];     int costsk2[n];     int costsk3[n];     int profits[n];     int maxprofits[n];     for (int i = 0; i < n; i++) {       costsk1[i] = (i == 0 ? 0 : costsk1[i - 1]) + (maps[i] == 0 ? 0 : 1);       costsk2[i] = (i == 0 ? 0 : costsk2[i - 1]) + (maps[i] == 1 ? 0 : 1);       costsk3[i] = (i == 0 ? 0 : costsk3[i - 1]) + (maps[i] == 2 ? 0 : 1);       profits[i] = costsk2[i] - costsk1[i];       maxprofits[i] = max((i == 0 ? 0 : maxprofits[i - 1]), profits[i]);     }     int minn = costsk3[n - 1];     for (int i = 0; i < n; i++) {       minn = min(minn, costsk2[i] - maxprofits[i] + costsk3[n - 1] - costsk3[i]);     }     cout << minn << endl;   }
#include <bits/stdc++.h>   using namespace std;   void yala_bena() {     cin.tie(0);     std::ios::sync_with_stdio(0);   }   const int m_r = 999999;   int k = -1;   int bestsum, limit;   vector<long long> ans;   int binary(int number) {     while (number) {       k++;       if (number % 2) return k;       number /= 2;     }   }   void sum_it_up(int sum, int index, vector<int> p) {     if (sum + ans[index] <= bestsum) {       sum += ans[index];       p.push_back(index + 1);     }     if (sum == bestsum) {       cout << p.size() << endl;       for (int i = 0; i < p.size(); i++) {         if (i == p.size() - 1)           cout << p[i] << endl;         else           cout << p[i] <<    ;       }       exit(0);     }     for (int i = index + 1; i < ans.size(); i++) {       if (sum + ans[i] <= bestsum) sum_it_up(sum, i, p);     }   }   int main() {     yala_bena();     cin >> bestsum >> limit;     for (int i = limit; i >= 1; i--) {       int a = (int)pow(2, binary(i));       k = -1;       if (a <= bestsum) bestsum -= a, ans.push_back(i);     }     if (bestsum == 0) {       cout << ans.size() << endl;       for (int i = 0; i < ans.size(); i++)         i == ans.size() - 1 ? cout << ans[i] << endl : cout << ans[i] <<    ;       return 0;     }     cout << -1 << endl;   }