malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 5010;   int n, k;   int a[N];   int dp[N][N / 2][2];   int solve(int r, int num, int sub) {     if (num == 0) return 0;     int& res = dp[r][num][sub];     if (res != 1000000000) return res;     if (sub == 1) {       res = solve(r - 2, num - 1, (a[r - 1] < a[r] ? 0 : 1)) +             (a[r - 1] < a[r] ? 0 : (a[r - 1] - a[r] + 1)) +             (a[r + 2] - 1 < a[r] ? 0 : (a[r + 2] - 1 - a[r] + 1));       if (num * 2 <= r) {         res = min(res, solve(r - 1, num, 0));       }     } else {       res = solve(r - 2, num - 1, (a[r - 1] < a[r] ? 0 : 1)) +             (a[r - 1] < a[r] ? 0 : (a[r - 1] - a[r] + 1)) +             (a[r + 1] < a[r] ? 0 : (a[r + 1] - a[r] + 1));       if (num * 2 <= r) {         res = min(solve(r - 1, num, 0), res);       }     }     return res;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     k = (n + 1) / 2;     for (int i = 0; i < n; i++) {       cin >> a[i + 1];     }     a[0] = -100;     a[n + 1] = -100;     for (int i = 0; i < N; i++) {       for (int j = 0; j < N / 2; j++) {         for (int k = 0; k < 2; k++) {           dp[i][j][k] = 1000000000;         }       }     }     cout << solve(n, 1, 0);     for (int i = 2; i < k + 1; i++) {       cout <<     << solve(n, i, 0);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, p, q1, q2, t, a[300010], y[300010], w, u;   long long x[300010];   map<long long, int> f, g;   vector<int> r[300010];   inline bool cmp(int a, int b) { return x[a] < x[b]; }   inline int power(int a, int b, int q) {     if (!b) return 1;     int c = power(a, b >> 1, q);     c = (long long)c * c % q;     if (b & 1) c = (long long)c * a % q;     return c;   }   inline long long ran() {     return ((long long)rand() << 45) + ((long long)rand() << 30) +            (rand() << 15) + rand();   }   inline void dfs(int i) {     int j;     u--;     g[x[i]] = ++w;     for (j = 0; j < r[i].size(); j++)       if (!g[x[r[i][j]]]) dfs(r[i][j]);   }   inline bool check(int p) {     int i;     for (i = 2; i * i <= p; i++)       if (p % i == 0) return 0;     return 1;   }   int main() {     int i, j, k;     srand(time(0));     ran();     ran();     ran();     for (q1 = ran() % 1000000000 + 100000000; !check(q1); q1++)       ;     for (q2 = ran() % 1000000000 + 100000000; !check(q2); q2++)       ;     for (p = ran() % 1000000 + 100000; !check(p); p++)       ;     for (t = ran() % 1000000 + 100000; !check(t); t++)       ;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) {       x[i] = power(p, i ^ t, q1);       y[i] = power(p, i ^ t, q2);     }     for (i = 1; i <= m; i++) {       scanf( %d%d , &j, &k);       x[j] = (x[j] + power(p, k ^ t, q1)) % q1;       y[j] = (y[j] + power(p, k ^ t, q2)) % q2;       x[k] = (x[k] + power(p, j ^ t, q1)) % q1;       y[k] = (y[k] + power(p, j ^ t, q2)) % q2;       r[j].push_back(k);       r[k].push_back(j);     }     for (i = 1; i <= n; i++) {       x[i] = x[i] * 2000000000 + y[i];       a[i] = i;     }     sort(a + 1, a + n + 1, cmp);     for (i = 1; i <= n; i++)       if (i == 1 || x[a[i]] != x[a[i - 1]]) {         for (j = 0, k = 0; j < r[a[i]].size(); j++)           if (x[r[a[i]][j]] != x[a[i]] && !g[x[r[a[i]][j]]]) {             g[x[r[a[i]][j]]] = 1;             k++;           }         g.clear();         f[x[a[i]]] = k;         u++;       }     for (i = 1; i <= n; i++)       if (f[x[i]] > 2) {         u = 1;         break;       } else if (f[x[i]] <= 1 && !g[x[i]])         dfs(i);     if (u)       printf( NO n );     else {       printf( YES n );       for (i = 1; i <= n; i++) printf( %d  , g[x[i]]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n, m;     cin >> n >> m;     int a[n];     for (__typeof((n)) i = (0); i < (n); i++) cin >> a[i];     int fq[m];     for (__typeof((m)) i = (0); i < (m); i++) fq[i] = 0;     for (__typeof((n)) i = (0); i < (n); i++) {       fq[a[i] % m]++;     }     int flg = 0;     for (__typeof((m)) i = (0); i < (m); i++) {       if (fq[i] >= 2) {         flg = 1;         break;       }     }     if (flg == 1)       cout << 0 << endl;     else {       int prd = 1;       for (__typeof((n)) i = (0); i < (n); i++) {         for (int j = i + 1; j < n; j++)           prd = ((prd % m) * (abs(a[i] - a[j]) % m)) % m;       }       cout << prd << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n1, n2;     cin >> n1 >> n2;     int k, m;     cin >> k >> m;     long long a[n1], b[n2];     for (int i = 0; i < n1; i++) cin >> a[i];     for (int i = 0; i < n2; i++) cin >> b[i];     int count = 0;     for (int i = 0; i < n1; i++) {       if (a[i] >= b[n2 - m]) break;       count++;       if (count >= k) break;     }     if (count >= k && n2 >= m)       cout <<  YES n ;     else       cout <<  NO n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int color[400100];   int w[400100];   struct segment_tree {     long long a[1600100];     bool put[1600100];     void push(int x) {       if (put[x]) {         a[x * 2] = a[x * 2 + 1] = a[x];         put[x] = false;         put[x * 2] = put[x * 2 + 1] = true;       }     }     void calc(int x) { a[x] = a[x * 2] | a[x * 2 + 1]; }     void build(int x, int l, int r) {       if (l < r) {         int y = (l + r) >> 1;         build(x * 2, l, y);         build(x * 2 + 1, y + 1, r);         a[x] = a[x * 2] | a[x * 2 + 1];         put[x] = false;       } else {         a[x] = (1LL << color[w[l]]);         put[x] = true;       }     }     void modify(int x, int l, int r, int ll, int rr, long long v) {       if (r < ll || l > rr) return;       if (ll <= l && rr >= r) {         a[x] = v;         put[x] = true;         return;       }       push(x);       int y = (l + r) >> 1;       modify(x * 2, l, y, ll, rr, v);       modify(x * 2 + 1, y + 1, r, ll, rr, v);       calc(x);     }     long long get(int x, int l, int r, int ll, int rr) {       if (r < ll || l > rr) return 0LL;       if (ll <= l && rr >= r) {         return a[x];       }       push(x);       int y = (l + r) >> 1;       long long ret = get(x * 2, l, y, ll, rr);       ret |= get(x * 2 + 1, y + 1, r, ll, rr);       calc(x);       return ret;     }   } seg;   vector<int> ga[400100];   int u, v;   int din[400100], dout[400100];   int timer;   void dfs(int u, int p) {     timer++;     din[u] = timer;     w[timer] = u;     for (int i = 0; i < ga[u].size(); i++) {       int v = ga[u][i];       if (v != p) dfs(v, u);     }     dout[u] = timer;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> color[i];     for (int i = 1; i < n; i++) {       cin >> u >> v;       ga[u].push_back(v);       ga[v].push_back(u);     }     dfs(1, -1);     seg.build(1, 1, n);     int tp, aa, bb;     for (int i = 1; i <= m; i++) {       cin >> tp;       if (tp == 1) {         cin >> aa >> bb;         seg.modify(1, 1, n, din[aa], dout[aa], (1LL << bb));       } else {         cin >> aa;         cout << __builtin_popcountll(seg.get(1, 1, n, din[aa], dout[aa])) << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string name[7];   int a, b, c, n, max_p, dexp, was[7];   bool p[7][7];   void perebor(int point, int num);   int main() {     name[0] =  Anka ;     name[1] =  Chapay ;     name[2] =  Cleo ;     name[3] =  Troll ;     name[4] =  Dracul ;     name[5] =  Snowy ;     name[6] =  Hexadecimal ;     cin >> n;     for (int i = 0; i < n; i++) {       int a, b;       string name1, name2, s;       cin >> name1 >> s >> name2;       for (int j = 0; j < 7; j++) {         if (name[j] == name1) a = j;         if (name[j] == name2) b = j;       }       p[a][b] = true;     }     cin >> a >> b >> c;     dexp = (int)1e9 * 2 + 1;     max_p = -1;     perebor(1, 0);     cout << dexp <<     << max_p;     return 0;   }   void perebor(int point, int num) {     if (point == 4 && num != 7) return;     if (num == 7) {       int c_p = 0, t[4], ans;       for (int i = 0; i < 4; i++) t[i] = 0;       for (int i = 0; i < 7; i++) {         t[was[i]]++;         for (int j = 0; j < 7; j++)           if (was[i] == was[j] && p[i][j] == true && i != j) c_p++;       }       if (!(t[1] && t[2] && t[3]))         return;       else {         ans = max(ceil(a / t[1]), max(ceil(b / t[2]), ceil(c / t[3]))) -               min(ceil(a / t[1]), min(ceil(b / t[2]), ceil(c / t[3])));         if (ans <= dexp) {           if (ans < dexp) max_p = 0;           dexp = ans;           if (max_p < c_p) max_p = c_p;         }       }       return;     }     for (int i = 0; i < 7; i++)       if (was[i] == 0) {         was[i] = point;         perebor(point, num + 1);         perebor(point + 1, num + 1);         was[i] = 0;       }     return;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 2e5 + 10;   const int mod = 1e9 + 7;   struct pairNode {     char ch;     long long times;     pairNode(char ch = 0, long long times = 0) : ch(ch), times(times) {}     ~pairNode() = default;     bool operator==(const pairNode &rhs) const {       return ch == rhs.ch && times == rhs.times;     }     bool operator!=(const pairNode &rhs) const {       return ch != rhs.ch || times != rhs.times;     }     bool operator>=(const pairNode &rhs) const {       return ch == rhs.ch && times >= rhs.times;     }   };   int tS, tT;   vector<pairNode> S, T, newT;   int nxt[M];   inline void getInput(vector<pairNode> &S, int len) {     char cur = 0, ch[3];     long long curtimes = 0, times;     for (int i = 0; i < len; ++i) {       scanf( %I64d-%s , &times, ch);       if (ch[0] == cur) {         curtimes += times;       } else {         if (i) S.push_back(pairNode(cur, curtimes));         cur = ch[0];         curtimes = times;       }     }     S.push_back(pairNode(cur, curtimes));   }   int main() {     S.clear();     T.clear();     cin >> tS >> tT;     getInput(S, tS);     getInput(T, tT);     if (T.size() == 1) {       long long ans = 0;       for (int i = 0; i < S.size(); ++i)         if (S[i] >= T[0]) ans += S[i].times - T[0].times + 1;       cout << ans << endl;       return 0;     }     if (T.size() == 2) {       long long ans = 0;       for (int i = 0; i < S.size() - 1; ++i)         if (S[i] >= T[0] && S[i + 1] >= T[1]) ++ans;       cout << ans << endl;       return 0;     }     for (int i = 1; i < T.size() - 1; ++i) newT.push_back(T[i]);     nxt[0] = -1;     int k = -1;     for (int i = 1; i < newT.size(); ++i) {       while (k != -1 && newT[k + 1] != newT[i]) k = nxt[k];       if (newT[k + 1] == newT[i]) ++k;       nxt[i] = k;     }     long long ans = 0;     k = -1;     for (int i = 0; i < S.size(); ++i) {       while (k != -1 && newT[k + 1] != S[i]) k = nxt[k];       if (newT[k + 1] == S[i]) ++k;       if (k == newT.size() - 1) {         if (i >= newT.size() && i + 1 <= S.size() && S[i - newT.size()] >= T[0] &&             S[i + 1] >= T[T.size() - 1])           ++ans;         k = nxt[k];       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>       #define ll long long int   #define ii pair<int,int>   #define int long long int       using namespace std;       const int inf = 0x3f3f3f3f;      int32_t main() {       int t; scanf( %lld ,&t);       while(t--) {           int n, m, x; scanf( %lld%lld%lld ,&n,&m,&x);           --x;              int c = (x/n);           int r = (x%n);                      int ans = r*m+c;           printf( %lld n ,ans+1);       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, sum, k, ans, c;   long long arr[1000000 + 5];   long long tmp[1000000 + 5];   vector<long long> frac;   signed main() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> arr[i], sum += arr[i];     }     ans = 1e18;     for (long long i = 2; i <= sqrt(sum); i++) {       if (sum % i == 0) frac.push_back(i), frac.push_back(sum / i);     }     frac.push_back(1);     for (long long i : frac) {       k = sum / i, c = 0;       for (long long j = 0; j < n; j++) tmp[j] = 0;       for (long long j = 0; j < n; j++) {         tmp[j] += arr[j];         if (tmp[j] < 0) {           c += -tmp[j];           tmp[j + 1] += tmp[j];           tmp[j] = 0;         }         if (tmp[j] % k != 0) {           if (tmp[j] % k < k - tmp[j] % k) {             c += tmp[j] % k;             tmp[j + 1] += tmp[j] % k;           } else {             c += k - tmp[j] % k;             tmp[j + 1] -= k - tmp[j] % k;           }         }       }       ans = min(ans, c);     }     if (sum > 1)       cout << ans <<   n ;     else       cout << -1 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long m[10000005], x = 0, n, k, i, j, a;   int main() {     cin >> a >> n;     for (i = 1; i < a + n; i++) {       m[i] = i;     }     for (i = 2; i < 3400; i++) {       k = 0;       for (j = i * i; j <= a + n; j = j + i * i) {         k++;         m[j] = k;       }     }     for (i = a; i < a + n; i++) x = x + m[i];     cout << x;   }
#include <bits/stdc++.h>   using namespace std;   long long big = 1000000007;   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long a, b;     cin >> a >> b;     int g = gcd(a, b);     a /= g;     b /= g;     int ctr = 0;     while (a % 2 == 0) {       ctr += 1;       a /= 2;     }     while (a % 3 == 0) {       ctr += 1;       a /= 3;     }     while (a % 5 == 0) {       ctr += 1;       a /= 5;     }     if (a != 1) {       cout << -1 <<   n ;       return 0;     }     while (b % 2 == 0) {       ctr += 1;       b /= 2;     }     while (b % 3 == 0) {       ctr += 1;       b /= 3;     }     while (b % 5 == 0) {       ctr += 1;       b /= 5;     }     if (b != 1) {       cout << -1 <<   n ;       return 0;     }     cout << ctr <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAXN = (long long)((1e5) + 100);   long long cuberoot(long long x) {     long long lo = 1, hi = min(2000000ll, x);     while (hi - lo > 1) {       long long mid = (lo + hi) / 2;       if (mid * mid * mid < x) {         lo = mid;       } else         hi = mid;     }     if (hi * hi * hi <= x)       return hi;     else       return lo;   }   const long long dx[4] = {-1, 1, 0, 0};   const long long dy[4] = {0, 0, -1, 1};   long long XX[] = {-1, -1, -1, 0, 0, 1, 1, 1};   long long YY[] = {-1, 0, 1, -1, 1, -1, 0, 1};   const long long N = (long long)(1 * 1e6 + 10);   bool comp(pair<long long, pair<long long, long long>> p1,             pair<long long, pair<long long, long long>> p2) {     if (p1.first > p2.first)       return true;     else if (p1.second == p2.second) {       if (p1.second.first < p2.second.first) return true;     }     return false;   }   long long fact(long long n);   long long ncr(long long n, long long r) {     return fact(n) / (fact(r) * fact(n - r));   }   long long fact(long long n) {     long long res = 1;     for (long long i = 2; i <= n; i++) res = res * i;     return res % 1000000007;   }   const long long a = 1000000000;   long long nCr(long long n, long long r) {     long long fac1 = 1, fac2 = 1, fac;     for (long long i = r; i >= 1; i--, n--) {       fac1 = fac1 * n;       if (fac1 % i == 0)         fac1 = fac1 / i;       else         fac2 = fac2 * i;     }     fac = fac1 / fac2;     return fac % a;   }   const long long m = 1000000007;   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   signed main() {     long long n;     cin >> n;     long long arr[n + 1];     for (long long i = 0; i < n; i++) {       cin >> arr[i];     }     long long mx = 0;     vector<long long> v;     for (long long i = n - 1; i >= 0; i--) {       if (i == n - 1) {         v.push_back(0);         mx = arr[i];       } else {         long long ans = 0;         if (mx >= arr[i])           ans = max(mx, arr[i]) - arr[i] + 1;         else           ans = max(mx, arr[i]) - arr[i];         v.push_back(ans);         mx = max(mx, arr[i]);       }     }     for (long long i = n - 1; i >= 0; i--) cout << v[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int MN = 100000 + 1;   int N;   char buf[2000];   int main() {     scanf( %d , &N);     for (int i = 0; i < N; i++) {       int a, b;       scanf( %s%d%d , buf, &a, &b);       if (a >= 2400 && b > a) {         puts( YES );         return 0;       }     }     puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1005], b[1005], c[1005], d[1005], posa[1005], posb[1005];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int q = 1; q <= n; q++) {       int x;       cin >> x;       a[x] = q;     }     for (int q = 1; q <= n; q++) {       int x;       cin >> x;       b[x] = q;     }     for (int q = 1; q <= n; q++) {       c[q] = d[q] = posa[q] = posb[q] = q;     }     vector<array<int, 4>> v;     for (int q = 1; q <= n; q++) {       if (c[q] == a[q] && d[q] == b[q]) continue;       v.push_back({q, posb[b[q]], posa[a[q]], q});       posb[d[q]] = posb[b[q]];       posa[c[q]] = posa[a[q]];       d[posb[d[q]]] = d[q];       c[posa[c[q]]] = c[q];     }     cout << ((int)((v).size())) <<   n ;     for (int q = 0; q < ((int)((v).size())); q++) {       for (int w = 0; w < 4; w++) cout << v[q][w] <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int tree[4 * 200005];   void update(int n, int st, int en, int index, int val) {     if (st == en) {       tree[n] = val;       return;     }     int mid = (st + en) / 2, lc = 2 * n, rc = lc + 1;     if (index <= mid)       update(lc, st, mid, index, val);     else       update(rc, mid + 1, en, index, val);     tree[n] = max(tree[lc], tree[rc]);   }   int query(int n, int st, int en, int l, int r) {     if (r < st || en < l) return 0;     if (l <= st && en <= r) return tree[n];     int mid = (st + en) / 2, lc = 2 * n, rc = lc + 1;     return max(query(lc, st, mid, l, r), query(rc, mid + 1, en, l, r));   }   vector<int> pos[200005 + 5];   int main() {     int n, inp;     scanf( %d , &n);     int mx = 0;     for (int i = 1; i < n + 1; i++) {       scanf( %d , &inp);       pos[inp].push_back(i);     }     for (int num = 1; num < 200005; num++) {       reverse(pos[num].begin(), pos[num].end());       for (auto position : pos[num]) {         if (position < num) continue;         int highestDeletePossible = position - num;         int maxAns = query(1, 0, 200005, 0, highestDeletePossible) + 1;         update(1, 0, 200005, highestDeletePossible, maxAns);       }     }     cout << query(1, 0, 200005, 0, 200005) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXM = 111111;   vector<int> v[MAXM];   int n, m, lim, x, lower, upper;   inline bool check(int score) {     for (int i = 1; i <= m; ++i)       for (int j = score - 1; j < (int)v[i].size(); ++j) {         int k = j - score + 1;         if (v[i][j] - v[i][k] - lim <= score - 1) return true;       }     return false;   }   int main() {     scanf( %d %d %d , &n, &m, &lim);     for (int i = 0; i < n; ++i) {       scanf( %d , &x);       v[x].push_back(i);     }     lower = 0, upper = n;     while (lower < upper) {       int mid = (lower + upper + 1) / 2;       if (check(mid))         lower = mid;       else         upper = mid - 1;     }     printf( %d n , lower);   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 + 10, MAXL = 500 + 10;   int n, S, in[MAXN], out[MAXN], w[MAXN], s[MAXN], v[MAXN];   int id[MAXN], h[MAXN][MAXN], g[MAXN][MAXN], f[MAXL][MAXN], Tohka;   vector<int> l[MAXN];   bool cmp(int first, int second) {     if ((out[first] - in[first]) != (out[second] - in[second]))       return (out[first] - in[first]) < (out[second] - in[second]);     return (s[first] + w[first]) < (s[second] + w[second]);   }   int main() {     scanf( %d%d , &n, &S);     for (int i = 1; i <= n; ++i)       scanf( %d%d%d%d%d , &in[i], &out[i], &w[i], &s[i], &v[i]), ++in[i],           id[i] = i;     ++n;     in[n] = 1, out[n] = n * 2 + 1, w[n] = 0, s[n] = S;     id[n] = n;     sort(id + 1, id + n + 1, cmp);     for (int i = 1; i <= n; ++i) l[out[id[i]]].push_back(id[i]);     for (int t = 1; t <= n; ++t) {       int i = id[t], R = min(S - w[i], s[i]);       for (int k = 0; k <= R; ++k) g[in[i] - 1][k] = 0;       for (int j = in[i]; j <= out[i]; ++j) {         for (int k = 0; k <= R; ++k) g[j][k] = g[j - 1][k];         vector<int> &L = l[j];         for (int p = 0; p < (int)L.size() && L[p] != i && in[L[p]] >= in[i]; ++p)           for (int k = w[L[p]]; k <= R; ++k)             g[j][k] = max(g[j][k], g[in[L[p]] - 1][k] + f[L[p]][k]);       }       for (int k = R; k >= 0; --k)         f[i][k + w[i]] = g[out[i]][k] + v[i], Tohka = max(Tohka, f[i][k + w[i]]);       for (int k = 0; k < w[i]; ++k) f[i][k] = 0;       for (int k = 1; k <= S; ++k) f[i][k] = max(f[i][k], f[i][k - 1]);     }     cout << Tohka << endl;     fclose(stdin);     fclose(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct flight {     int d, f, t, c;     flight() {}     flight(int d, int f, int t, int c) : d(d), f(f), t(t), c(c) {}     bool operator<(const flight& a) const { return d > a.d; }   };   int n, m, k;   priority_queue<flight> arr, dep;   priority_queue<pair<int, int> > cheap[100010];   long long minarr[100010], arrcost, depcost;   int main() {     cin >> n >> m >> k;     for (int i = 0; i < m; i++) {       int d, f, t, c;       cin >> d >> f >> t >> c;       if (t == 0) {         arr.push(flight(d, f, t, c));       } else {         dep.push(flight(d, f, t, c));         cheap[t].push(make_pair(-c, d));       }     }     for (int i = 1; i <= n; i++) {       if (cheap[i].empty()) {         cout << -1 <<   n ;         return 0;       }       depcost += -cheap[i].top().first;     }     memset(minarr, -1, sizeof(minarr));     int num = 0;     long long ans = -1;     while (!arr.empty()) {       flight f = arr.top();       arr.pop();       int u = f.f;       if (minarr[u] == -1) {         num++;         minarr[u] = f.c;         arrcost += f.c;       } else if (f.c < minarr[u]) {         arrcost += f.c - minarr[u];         minarr[u] = f.c;       }       if (num < n) continue;       bool done = 0;       while (!dep.empty() && dep.top().d <= f.d + k) {         flight df = dep.top();         dep.pop();         depcost -= -cheap[df.t].top().first;         while (!cheap[df.t].empty() && cheap[df.t].top().second <= df.d)           cheap[df.t].pop();         if (cheap[df.t].empty()) {           done = 1;           break;         }         depcost += -cheap[df.t].top().first;       }       if (done) break;       if (ans == -1 || arrcost + depcost < ans) {         ans = arrcost + depcost;       }     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   const int INF = (int)(1e9);   const long long INFLL = (long long)(1e18);   const double EPS = 1e-13;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, k;     cin >> n >> k;     vector<int> b(n);     for (int i = 0; i < n; i++) cin >> b[i];     vector<int> a;     for (int i = 0; i < n; i++)       if (b[i] == 0) a.push_back(i);     for (int i = n - 1; i >= 0; i--)       if (b[i] > 0) {         int cnt = 0;         int index = -1;         for (int j = 0; j < a.size(); j++) {           if (a[j] >= i + k) cnt++;           if (cnt == b[i]) {             index = j + 1;             break;           }         }         a.insert(a.begin() + index, i);       }     for (int i = 0; i < n; i++) cout << a[i] + 1 <<    ;     cout << endl;     return 0;   }