malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int p, numb, hh, i, j, l, n, m, a;   char k;   bool flag;   int h[200000], check[500000], check1[500000], prime[500000], dp[500000];   int main() {     for (i = 2; i <= 100000; i++)       if (check[i] == 0) {         for (j = 2 * i; j <= 100000; j += i) check[j] = 1;       }     for (i = 2; i <= 100000; i++)       if (check[i] == 0) {         l++;         prime[l] = i;       }     cin >> n >> m;     for (i = 1; i <= m; i++) {       cin >> k >> a;       hh = a;       flag = true;       if (k ==  + ) {         if (dp[a] == 1) {           cout <<  Already on  << endl;         } else if (a == 1) {           dp[a] = 1;           cout <<  Success  << endl;         } else {           numb = 0;           hh = a;           for (j = 1; prime[j] * prime[j] <= a; j++)             if (a % prime[j] == 0) {               while (a % prime[j] == 0) a /= prime[j];               if (check1[prime[j]] > 0) {                 cout <<  Conflict with   << check1[prime[j]] << endl;                 flag = false;                 break;               } else {                 numb++;                 h[numb] = prime[j];               }             }           if (flag) {             if (check[a] == 0 && a > 1) {               if (check1[a] > 0) {                 cout <<  Conflict with   << check1[a] << endl;                 flag = false;               } else                 check1[a] = hh;             }             if (flag) {               for (p = 1; p <= numb; p++) check1[h[p]] = hh;               cout <<  Success  << endl;               dp[hh] = 1;             }           }         }       } else {         if (dp[a] == 1) {           hh = a;           cout <<  Success  << endl;           for (j = 1; prime[j] * prime[j] <= a; j++)             if (a % prime[j] == 0) {               while (a % prime[j] == 0) a /= prime[j];               check1[prime[j]] = 0;             }           if (check[a] == 0 && a > 1) check1[a] = 0;           dp[hh] = 0;         } else           cout <<  Already off  << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b, k[100100];   const int du = 0.000001;   bool cmp(int x, int y) { return x > y; }   int main() {     scanf( %d%d%d , &n, &a, &b);     long long sum = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d , &k[i]);       sum += k[i];     }     if (a == b) {       printf( %d , n - 1);       return 0;     }     sort(k + 2, k + 1 + n, cmp);     double cnt = 0;     int xx = sum;     double hah = b;     cnt = a * k[1] / 1.0 / xx;     if (cnt >= b) {       printf( 0 n );       return 0;     }     for (int i = 2; i <= n; ++i) {       xx = xx - k[i];       cnt = a * k[1] / 1.0 / xx;       if (cnt >= b) {         printf( %d n , i - 1);         return 0;       }     }     printf( %d n , n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long int c(long long int n, long long int i) {     if (i == 0)       return 1;     else if (i == 1)       return n;     else if (i == 2)       return (n * (n - 1)) / 2;     else if (i == 3)       return (n * (n - 1) * (n - 2)) / 6;     else if (i == 4)       return (n * (n - 1) * (n - 2) * (n - 3)) / 24;   }   int main() {     long long int d[5];     d[0] = 1;     d[1] = 0;     d[2] = 1;     d[3] = 2;     d[4] = 9;     long long int n, k;     cin >> n >> k;     long long int ans = 0;     for (long long int i = 0; i <= k; i++) ans += d[i] * c(n, i);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int f(int n) {     if (n < 10) {       return n;     }     int ans = 1;     while (n) {       if (n % 10 != 0) {         ans *= n % 10;       }       n /= 10;     }     return ans;   }   int g[1000005];   int cnt[10][1000005];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     for (int i = 1; i <= 1000000; i++) {       if (i < 10) {         g[i] = i;       } else {         g[i] = g[f(i)];       }       if (i <= 60) {       }       for (int j = 1; j <= 9; j++) {         cnt[j][i] = cnt[j][i - 1];       }       cnt[g[i]][i]++;     }     int T;     cin >> T;     while (T--) {       int l, r, k;       cin >> l >> r >> k;       cout << cnt[k][r] - cnt[k][l - 1] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int N = 100200;   struct Node {     int to, cost;   };   vector<Node> g[N];   int dist[105][N] = {}, arr[N] = {}, n, m, type[N] = {}, k, s, vis[N] = {};   void addedge(int u, int v, int cost) {     g[u].push_back((Node){v, cost});     g[v].push_back((Node){u, cost});   }   void bfs(int s, int n, int* d) {     queue<int> que;     memset(vis, 0, sizeof(vis));     int p, to, cost;     que.push(s);     vis[s] = 1;     while (!que.empty()) {       p = que.front();       que.pop();       const int sz = g[p].size();       for (int i = 0; i < sz; i++) {         to = g[p][i].to;         if (to > n - 1 || vis[to]) continue;         d[to] = d[p] + 1;         que.push(to);         vis[to] = 1;       }     }   }   int main(void) {     std::ios::sync_with_stdio(false);     cin >> n >> m >> k >> s;     for (int i = 0; i < n; i++) cin >> type[i];     int u, v;     for (int i = 0; i < m; i++) {       cin >> u >> v;       u--;       v--;       addedge(u, v, 1);     }     for (int i = 0; i < n; i++) {       addedge(n - 1 + type[i], i, 1);     }     for (int i = 1; i <= k; i++) {       bfs(n - 1 + i, n, dist[i]);     }     for (int i = 0; i < n; i++) {       int ans = 0;       for (int j = 1; j <= k; j++) arr[j] = dist[j][i] - 1;       sort(arr + 1, arr + k + 1);       for (int i = 1; i <= s; i++) ans += arr[i];       cout << ans <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long n, l, x, y, a[1 << 20];   set<long> has;   long hx, hy;   long ans;   long thx, thy;   void check(long ps) {     if (ps < 0 || ps > l) return;     hx = thx;     hy = thy;     if (has.find(ps + x) != has.end()) hx = 1;     if (has.find(ps + y) != has.end()) hy = 1;     if (has.find(ps - x) != has.end()) hx = 1;     if (has.find(ps - y) != has.end()) hy = 1;     if (hx && hy) ans = ps;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> l >> x >> y;     for (int i = 0; i < n; i++) {       cin >> a[i];       has.insert(a[i]);     }     hx = hy = 0;     for (int i = 0; i < n; i++) {       if (has.find(a[i] + x) != has.end()) hx = 1;       if (has.find(a[i] + y) != has.end()) hy = 1;       if (has.find(a[i] - x) != has.end()) hx = 1;       if (has.find(a[i] - y) != has.end()) hy = 1;     }     thx = hx;     thy = hy;     if (hx && hy) {       cout << 0 << endl;     } else {       ans = -1;       for (int i = 0; i < n; i++) {         check(a[i] - x);         check(a[i] + x);         check(a[i] - y);         check(a[i] + y);       }       if (ans >= 0)         cout << 1 << endl << ans << endl;       else {         cout << 2 << endl;         cout << x <<     << y << endl;       }     }     cin.get();     cin.get();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int k;   bool debug = false;   int a[105];   int main() {     cin >> n;     for (int i = 0, x; i < n; i++) {       scanf( %d , &x);       a[x]++;     }     for (int i = 0; i < 105; i++) k += a[i] / 2;     printf( %d n , k / 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, n, m, a[1005], b[1005], ans;   bool c[1005], lol;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       lol = false;       fill(c, c + 1005, false);       cin >> n >> m;       for (int i = 0; i < n; ++i) {         cin >> a[i];         c[a[i]] = true;       }       for (int i = 0; i < m; ++i) {         cin >> b[i];         if (c[b[i]] == true) {           ans = b[i];           lol = true;         }       }       if (lol == true)         cout <<  YES n1   << ans <<   n ;       else         cout <<  NO n ;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> adj[200003];   vector<pair<int, pair<int, int>>> edges;   vector<long long> len;   set<int> vertices;   void dijkstra(int start) {     set<int> vis;     priority_queue<pair<long long, int>, vector<pair<long long, int>>,                    greater<pair<long long, int>>>         pq;     pq.push(make_pair(0, start));     while (!pq.empty()) {       while (!pq.empty() && vis.find(pq.top().second) != vis.end()) pq.pop();       if (pq.empty()) break;       long long l = pq.top().first;       int v = pq.top().second;       pq.pop();       vis.insert(v);       if (l != 0) len.push_back(l);       for (int i = 0; i < adj[v].size(); i++) {         if (vis.find(adj[v][i].first) == vis.end()) {           pq.push(make_pair(l + 1ll * adj[v][i].second, adj[v][i].first));         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < m; i++) {       int a, b, w;       cin >> a >> b >> w;       edges.push_back(make_pair(w, make_pair(a, b)));     }     sort(edges.begin(), edges.end());     for (int i = 0; i < k && i < edges.size(); i++) {       vertices.insert(edges[i].second.first);       vertices.insert(edges[i].second.second);       adj[edges[i].second.first].push_back(           make_pair(edges[i].second.second, edges[i].first));       adj[edges[i].second.second].push_back(           make_pair(edges[i].second.first, edges[i].first));     }     for (int x : vertices) {       dijkstra(x);     }     sort(len.begin(), len.end());     cout << len[2 * k - 1] << endl;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     long long int t;     cin >> t;     while (t--) {       long long int n, x, i;       cin >> n >> x;       long long int second = 0;       long long int a[n];       for (long long int i = 0; i < n; i++) {         cin >> a[i];       }       sort(a, a + n);       for (i = n - 1; i >= 0; i--) {         second += a[i];         if (second / (n - i) < x) break;       }       cout << n - (i + 1) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long n, k, l, a[1000010], m, p, q, b[1000010], d, c[1000010], f[1000010],       g[1000010], ans;   struct BIT {     long long a[1000010];     void clear() { memset(a, 0, sizeof(a)); }     void add(int x, long long v) {       for (; x <= 1000010 - 5; x += x & (-x)) a[x] = (a[x] + v + mod) % mod;     }     long long get(int x) {       long long ans = 0;       for (; x; x -= x & (-x)) ans = (ans + a[x]) % mod;       return ans;     }   } tr;   int main() {     scanf( %lld%lld%lld , &n, &l, &k);     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]), b[i] = a[i];     sort(b + 1, b + n + 1);     d = unique(b + 1, b + n + 1) - b - 1;     for (int i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + d + 1, a[i]) - b;     m = l / n;     p = l % n;     if (!p) {       m--;       p += n;     }     q = max(0ll, m - k + 1);     q %= mod;     int cnt = 0;     for (int i = 1; i <= k - 1; i++)       for (int j = 1; j <= n; j++) c[++cnt] = a[j];     for (int i = 1; i <= p; i++) c[++cnt] = a[i];     for (int i = cnt - p + 1; i <= cnt; i++) f[i] = 1, tr.add(c[i], f[i]);     for (int i = k - 1; i; --i) {       for (int j = 1; j <= n; j++) {         int pos = (i - 1) * n + j;         f[pos] = (tr.get(1000010 - 5) - tr.get(c[pos] - 1) + mod) % mod;       }       for (int j = 1; j <= n; j++) {         int pos = (i - 1) * n + j;         if (pos + n <= cnt) tr.add(c[pos + n], -f[pos + n]);         tr.add(c[pos], f[pos]);       }     }     for (int i = max(cnt - p - m * n + 1, 1ll); i <= cnt; i++)       ans = (ans + f[i]) % mod;     memset(c, 0, sizeof(c));     tr.clear();     cnt = 0;     for (int i = 1; i <= k; i++)       for (int j = 1; j <= n; j++) c[++cnt] = a[j];     for (int i = cnt - n + 1; i <= cnt; i++) g[i] = 1, tr.add(c[i], g[i]);     for (int i = k - 1; i; --i) {       for (int j = 1; j <= n; j++) {         int pos = (i - 1) * n + j;         g[pos] = (tr.get(1000010 - 5) - tr.get(c[pos] - 1) + mod) % mod;       }       for (int j = 1; j <= n; j++) {         int pos = (i - 1) * n + j;         tr.add(c[pos + n], -g[pos + n]);         tr.add(c[pos], g[pos]);       }     }     long long tmp = 0;     for (int i = 1; i <= min(m, k - 1); i++) {       for (int j = 1; j <= n; j++) {         int pos = (k - i) * n + j;         tmp = (tmp + g[pos]) % mod;       }       ans = (ans + tmp) % mod;     }     tmp = 0;     for (int i = 1; i <= k; i++)       for (int j = 1; j <= n; j++) {         int pos = (i - 1) * n + j;         tmp = (tmp + g[pos]) % mod;       }     tmp = tmp * q % mod;     ans = (ans + tmp) % mod;     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 1e6 + 5;   int n, q, m;   const int N = 105;   const int L = 1505;   char s[maxn];   int tr[maxn][30], tot = 0;   int fail[maxn], w[maxn];   vector<int> g[maxn];   void add(char *s, int id) {     int u = 0;     int n = strlen(s);     for (int i = 0; i < n; i++) {       int c = s[i] -  a ;       if (!tr[u][c]) tr[u][c] = ++tot;       u = tr[u][c];     }     w[id] = u;   }   struct bit_tree {     long long c[maxn], n;     void init(int x) { n = x; }     inline int lowbit(int x) { return x & (-x); }     inline void update(int x, int v) {       for (int i = x; i <= n; i += lowbit(i)) {         c[i] += v;       }     }     inline long long query(int x) {       long long ans = 0;       for (int i = x; i > 0; i -= lowbit(i)) ans += c[i];       return ans;     }   } T;   void ac() {     queue<int> q;     for (int i = 0; i < 26; i++) {       if (tr[0][i]) q.push(tr[0][i]), fail[tr[0][i]] = 0;     }     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < 26; i++) {         if (tr[u][i]) {           fail[tr[u][i]] = tr[fail[u]][i];           q.push(tr[u][i]);         } else {           tr[u][i] = tr[fail[u]][i];         }       }     }   }   int ins[maxn], out[maxn], cnt = 0;   int vis[maxn];   void dfs(int x) {     ins[x] = ++cnt;     for (int i : g[x]) dfs(i);     out[x] = cnt;   }   int main() {     cin >> q >> n;     for (int i = 1; i <= n; i++) {       cin >> s;       add(s, i);     }     ac();     for (int i = 1; i <= tot; i++) {       g[fail[i]].push_back(i);     }     dfs(0);     T.init(cnt);     for (int i = 1; i <= n; i++) {       vis[i] = 1;       T.update(ins[w[i]], 1);       T.update(out[w[i]] + 1, -1);     }     char c;     int id;     while (q--) {       cin >> c;       if (c ==  + ) {         cin >> id;         if (vis[id]) continue;         vis[id] = 1;         T.update(ins[w[id]], 1);         T.update(out[w[id]] + 1, -1);       } else if (c ==  - ) {         cin >> id;         if (!vis[id]) continue;         vis[id] = 0;         T.update(ins[w[id]], -1);         T.update(out[w[id]] + 1, +1);       } else {         cin >> s;         int m = strlen(s);         long long p = 0, ans = 0;         for (int i = 0; i < m; i++) {           p = tr[p][s[i] -  a ];           ans += T.query(ins[p]);         }         printf( %lld n , ans);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 7;   int n, m;   vector<int> d[MAXN];   int r[MAXN];   vector<pair<int, int> > g[MAXN];   inline void add_edge(int u, int v, int c) {     g[u].push_back(make_pair(c, v));     g[v].push_back(make_pair(c, u));   }   int col[MAXN];   inline bool dfs(int u, int c) {     if (col[u] != -1) return col[u] == c;     col[u] = c;     for (auto e : (g[u])) {       if (!dfs(e.second, c ^ e.first)) return 0;     }     return 1;   }   inline void read(int &x) {     x = 0;     int f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     x *= f;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     read(n);     read(m);     for (int i = (1); i <= (n); ++i) read(r[i]);     for (int i = (1); i <= (m); ++i) {       int x;       read(x);       for (int j = (1); j <= (x); ++j) {         int p;         read(p);         d[p].push_back(i);       }     }     for (int i = (1); i <= (n); ++i) add_edge(d[i][0], d[i][1], r[i] ^ 1);     memset(col, -1, sizeof col);     bool ans = 1;     for (int i = 1; i <= m && ans; ++i)       if (col[i] == -1) ans &= dfs(i, 0);     cout << (ans ?  YES  :  NO ) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1ll << 60;   int n;   long long a[100100][4], f[100100][4], mx[4], sum[100100];   int main() {     scanf( %d , &n);     for (int j = 1; j <= 3; j++) {       for (int i = 1; i <= n; i++) scanf( %I64d , &a[i][j]);     }     for (int i = 1; i <= n; i++)       sum[i] = sum[i - 1] + a[i][1] + a[i][2] + a[i][3];     f[n + 1][1] = -inf;     f[n + 1][2] = -inf;     f[n + 1][3] = 0;     mx[1] = sum[n] + f[n + 1][1];     mx[3] = sum[n] + f[n + 1][3];     for (int i = n; i >= 1; i--) {       f[i][1] = a[i][1] + f[i + 1][1];       f[i][1] = max(f[i][1], a[i][1] + a[i][2] + f[i + 1][2]);       f[i][1] = max(f[i][1], a[i][1] + a[i][2] + a[i][3] + f[i + 1][3]);       f[i][1] = max(f[i][1], mx[3] - sum[i - 1]);       f[i][2] = a[i][2] + f[i + 1][2];       f[i][2] = max(f[i][2], a[i][2] + a[i][1] + f[i + 1][1]);       f[i][2] = max(f[i][2], a[i][2] + a[i][3] + f[i + 1][3]);       f[i][3] = a[i][3] + f[i + 1][3];       f[i][3] = max(f[i][3], a[i][3] + a[i][2] + f[i + 1][2]);       f[i][3] = max(f[i][3], a[i][3] + a[i][2] + a[i][1] + f[i + 1][1]);       f[i][3] = max(f[i][3], mx[1] - sum[i - 1]);       mx[1] = max(mx[1], sum[i - 1] + f[i][1]);       mx[3] = max(mx[3], sum[i - 1] + f[i][3]);     }     printf( %I64d n , f[1][1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int arr[1000000];   int main() {     int n;     cin >> n;     long long int count = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     long long int Min = arr[0];     long long int Max = arr[0];     for (int i = 1; i < n; i++) {       if (arr[i] >= arr[i - 1])         Min = Max = arr[i];       else {         int j = i;         long long int mmin = arr[j - 1];         long long int mmax = arr[j - 1];         int c = 0;         while (arr[j - 1] > arr[j]) {           mmin = min(arr[j], mmin);           mmax = max(arr[j], mmax);           j++;           if (j == n) break;           c++;         }         count += mmax - mmin;         i += c;       }     }     cout << count << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, k = 0, nod;     cin >> a;     for (int i = 2; i < a; i++) {       int b = a;       while (b != 0) {         k += b % i;         b /= i;       }     }     int b = a - 2;     for (int i = k; i > 0; i--)       if (k % i == 0 && b % i == 0) {         nod = i;         k /= nod;         b /= nod;         break;       }     cout << k <<  /  << b;   }
#include <bits/stdc++.h>   using namespace std;   long long a[(20ll + (long long)2e5)], b[(20ll + (long long)2e5)],       c[(20ll + (long long)2e5)], *d[(20ll + (long long)2e5)],       e[(20ll + (long long)2e5)];   int main() {     long long n;     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       a[i] *= i * (n - i + 1);       b[i] = a[i];     }     for (long long i = 1; i <= n; i++) {       scanf( %lld , &c[i]);       d[i] = &b[i];     }     sort(d + 1, d + n + 1, [](long long* l, long long* r) { return *l < *r; });     sort(c + 1, c + 1 + n, greater<long long>());     for (long long i = 1; i <= n; i++) {       *d[i] = c[i];     }     long long s = 0, mod = 998244353ll;     for (long long i = 1; i <= n; i++)       s = (s + (a[i] % mod * (b[i] % mod)) % mod) % mod;     printf(          %lld            n ,         s);     ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const N = 1e3 + 10, K = 10 + 2, E = -(1e8 + 10);   long long dp[N][N][K][2];   int n, m, kk;   string s, t;   void read_input() {     cin >> n >> m >> kk;     cin >> s >> t;   }   void solve() {     s =  *  + s, t =  *  + t;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         for (int k = 1; k <= kk; k++) {           dp[i][j][k][1] = (s[i] == t[j] ? 1 + max(dp[i - 1][j - 1][k][1],                                                    dp[i - 1][j - 1][k - 1][0])                                          : 0);           dp[i][j][k][0] =               max({dp[i - 1][j][k][0], dp[i][j - 1][k][0], dp[i][j][k][1]});         }     cout << dp[n][m][kk][0];   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     read_input(), solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   long long pows(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a;       a = a * a;       b >>= 1;     }     return res;   }   long long powm(long long x, long long y, long long m = 998244353) {     x = x % m;     long long res = 1;     while (y) {       if (y & 1) res = res * x;       res %= m;       y = y >> 1;       x = x * x;       x %= m;     }     return res;   }   long long modInverse(long long a, long long m) { return powm(a, m - 2, m); }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m, i, j, k, x, y, z, t, e, f, p, q, g, l, r, w, h,         count1 = 0, prod = 1, a, b, c, d, index, x1, x2, y1, y2, diff, ans = 0,         sum = 0, sum1 = 0, sum2 = 0, flag = 0, flag1 = 0, flag2 = 0;     string s, s1, s2;     cin >> n >> k;     set<long long> st;     vector<pair<long long, long long>> v(n);     for (i = 0; i < n; i++) {       cin >> v[i].first;       v[i].second = i + 1;     }     sort(v.begin(), v.end(), greater<pair<long long, long long>>());     vector<long long> v1(n + 1);     for (i = k + 1; i <= k + n; i++) {       st.insert(i);     }     for (i = 0; i < n; i++) {       p = *st.lower_bound(v[i].second);       v1[v[i].second] = p;       st.erase(p);       ans += (p - v[i].second) * v[i].first;     }     cout << ans <<   n ;     for (i = 1; i <= n; i++) {       cout << v1[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 5e9;   long long w[20], s[20], m;   bool solve(int bm) {     long long l = 0, r = m;     for (int i = 0; i < 14; ++i) {       if (bm % 3 == 0)         l += w[i];       else if (bm % 3 == 1)         r += w[i];       bm /= 3;     }     return l == r;   }   void special4() {     while (m > 0) {       if (m % 4 == 2) {         cout <<  NO n ;         exit(0);       }       if (m % 4 == 3) {         m += 4;       }       m /= 4;     }     cout <<  YES n ;   }   int main() {     w[0] = 1;     cin >> w[1] >> m;     if (w[1] <= 3) {       cout <<  YES n ;       return 0;     }     for (int i = 2; i < 20; ++i) {       w[i] = w[i - 1] * w[1];       if (w[i] > inf) w[i] = 0;     }     if (w[1] == 4) {       special4();       return 0;     }     for (int bm = 0; bm < (int)5e6; ++bm) {       if (solve(bm)) {         cout <<  YES n ;         return 0;       }     }     cout <<  NO n ;   };
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, b;     cin >> n >> b;     int a[n], maxx = b;     for (int x = 0; x < n; x++) cin >> a[x];     for (int x = 0; x < n; x++) {       for (int y = x + 1; y < n; y++)         maxx = max(maxx, (b / a[x]) * a[y] + (b % a[x]));     }     cout << maxx;   }