malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename Tp>   inline void outarr(Tp _begin, Tp _end, const char* _delim =    ) {     for (Tp current = _begin; current != _end; ++current) {       std::cout << *current << _delim;     }     std::cout <<   n ;   }   using ll = long long;   using pii = std::pair<int, int>;   constexpr int INF = 0x3f3f3f3f;   constexpr int MOD = static_cast<const int>(1e9 + 7);   constexpr int MAXN = 20005;   int dp[2][MAXN];   int cnt[MAXN];   int sum[MAXN];   int Add(int x, int y) {     x += y;     return x < MOD ? x : x - MOD;   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     int n;     cin >> n;     vector<int> arr(n);     for (int i = 0; i < (n); ++i) {       cin >> arr[i];     }     int off = 10000;     int cur = 0;     int ans = 0;     dp[0][off] = 1;     cnt[off] = 1;     for (int i = 0; i < (n); ++i) {       int pre = cur;       cur ^= 1;       memset(dp[cur], 0, sizeof(dp[cur]));       for (int j = -10000; j <= 10000; ++j) {         if (j - arr[i] >= -10000) {           dp[cur][j - arr[i] + off] =               Add(dp[cur][j - arr[i] + off], dp[pre][j + off]);         }         if (j + arr[i] <= 10000) {           dp[cur][j + arr[i] + off] =               Add(dp[cur][j + arr[i] + off], dp[pre][j + off]);         }       }       ans = Add(ans, dp[cur][off]);       dp[cur][off] = Add(dp[cur][off], 1);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans(0);     cin >> n;     int h[n], a[n];     for (int i = 0; i < n; i++) {       cin >> h[i] >> a[i];     }     for (int b = 0; b < n; b++) {       for (int c = 0; c < n; c++) {         if (c != b) {           if (h[b] == a[c]) ans++;         }       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long md = 1e9 + 7;   long long inv(long long a) {     long long p = md - 2;     long long ret = 1;     while (p) {       if (p & 1) ret = (ret * a) % md;       a = a * a % md;       p >>= 1;     }     return ret;   }   int mp[1010][1010];   int xn[2100], yyyn[2100], dn[2100];   void range(int &x0, int &y0, int &x1, int &y1) {     x0 = max(x0, 1);     y0 = max(y0, 1);     x1 = min(x1, 1000);     y1 = min(y1, 1000);   }   int cnt(int x0, int y0, int x1, int y1) {     range(x0, y0, x1, y1);     return mp[x1][y1] - mp[x0 - 1][y1] - mp[x1][y0 - 1] + mp[x0 - 1][y0 - 1];   }   long long cn[2100];   void init(int m) {     memset(cn, 0, sizeof(cn));     cn[m] = 1;     for (int i = m + 1; i < 2100; i++) {       cn[i] = cn[i - 1] * i % md * inv(i - m) % md;     }   }   long long c(int n, int m) { return cn[n]; }   int main() {     int z;     int n, m, r;     int i, j, k;     memset(mp, 0, sizeof(mp));     cin >> n >> m >> r;     for (i = 0; i < n; i++) {       cin >> xn[i] >> yyyn[i] >> dn[i];       mp[xn[i]][yyyn[i]] = 1;     }     for (i = 1; i <= 1000; i++) {       for (j = 1; j <= 1000; j++) {         mp[i][j] = mp[i - 1][j] + mp[i][j - 1] - mp[i - 1][j - 1] + mp[i][j];       }     }     long long ans = 0;     init(m);     for (i = 0; i < n; i++) {       for (j = i + 1; j < n; j++) {         int xi = xn[i], yi = yyyn[i];         int xj = xn[j], yj = yyyn[j];         int dx = abs(xi - xj), dy = abs(yi - yj);         int u, v, w;         u = cnt(xi - r, yi - r, xi + r, yi + r);         v = cnt(xj - r, yj - r, xj + r, yj + r);         if (dx <= 2 * r && dy <= 2 * r) {           int x0, y0, x1, y1;           if (xi > xj) swap(xi, xj);           x0 = xj - r, x1 = xi + r;           if (yi > yj) swap(yi, yj);           y0 = yj - r, y1 = yi + r;           w = cnt(x0, y0, x1, y1);         } else {           w = 0;         }         u -= w;         v -= w;         long long sum = ((c(n, m) - c(n - w, m) + md) +                          (c(n - w, m) - c(n - w - u, m) - c(n - w - v, m) +                           c(n - w - u - v, m) + 2 * md)) %                         md;         ans = (ans + 2 * sum % md * dn[i] % md * dn[j] % md) % md;       }       int ni = cnt(xn[i] - r, yyyn[i] - r, xn[i] + r, yyyn[i] + r);       ans = (ans + (c(n, m) - c(n - ni, m) + md) % md * dn[i] % md * dn[i] % md) %             md;     }     cout << ans % md << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x[7];   int y[7];   bool inside1(float x1, float y1) {     if (x1 + .5 >= x[3] && x1 + .5 <= x[4] && y1 + .5 >= y[3] && y1 + .5 <= y[4])       return 1;     return 0;   }   bool inside2(float x1, float y1) {     if (x1 + .5 >= x[5] && x1 + .5 <= x[6] && y1 + .5 >= y[5] && y1 + .5 <= y[6])       return 1;     return 0;   }   int main() {     for (int i = 0; i < (int)(6); ++i) cin >> x[i + 1] >> y[i + 1];     for (int i = (y[1]); i < (int)(y[2]); ++i) {       for (int j = (x[1]); j < (int)(x[2]); ++j) {         if (inside1(j, i) && inside2(j, i)) {           j = max(x[4], x[6]);           if (j < x[2]) {             cout <<  YES  << endl;             return 0;           }         } else if (inside1(j, i)) {           j = x[4];           if (!inside2(j, i) && j < x[2]) {             cout <<  YES  << endl;             return 0;           }         } else if (inside2(j, i)) {           j = x[6];           if (!inside1(j, i) && j < x[2]) {             cout <<  YES  << endl;             return 0;           }         } else {           cout <<  YES  << endl;           return 0;         }       }     }     cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int limB = 1 << 20;   const int limN = 20;   bool usdA[limB][limN], usdB[limB][limN];   int ansA[limB][limN], ansB[limB][limN];   int ja(int n, int k);   int jb(int n, int k);   int ja(int n, int k) {     if (k == 2) return n;     if (usdA[n][k]) return ansA[n][k];     usdA[n][k] = true;     int &ans = ansA[n][k];     ans = jb(n >> 1, k - 1);     for (int i = 1; i < k; i++) {       ans = min(ans, jb(((n >> (i + 1)) << i) + n % (1 << i), k - 1));     }     return ans;   }   int jb(int n, int k) {     if (k == 2) return n;     if (usdB[n][k]) return ansB[n][k];     usdB[n][k] = true;     int &ans = ansB[n][k];     ans = ja(n >> 1, k - 1);     for (int i = 1; i < k; i++) {       ans = max(ans, ja(((n >> (i + 1)) << i) + n % (1 << i), k - 1));     }     return ans;   }   void pint(int n, int k) {     int w = 0;     for (int i = k - 1; i >= 0; i--) {       printf( %d , (1 << i) & n ? 1 : 0);       if ((1 << i) & n) w++;     }     printf(  => %d n , w);   }   char str[limB];   int main() {     scanf( %s , str);     int mino = 0, maxo = 0, n = 0;     char ut =  ? ;     for (char *c = str; *c; c++) {       mino += *c ==  1  ? 1 : 0;       maxo += *c !=  0  ? 1 : 0;       ut = *c;       n++;     }     n = (n + 1) / 2;     if (mino <= n - 1) printf( 00 n );     if (mino <= n && n <= maxo) {       if (ut ==  1  || (ut ==  ?  && mino + 1 <= n)) printf( 01 n );       if (ut ==  0  || (ut ==  ?  && n <= maxo - 1)) printf( 10 n );     }     if (n + 1 <= maxo) printf( 11 n );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int ttt;     cin >> ttt;     for (long long int iq = 0; iq < ttt; ++iq) {       long long int n, e = 0;       cin >> n;       long long int s = n % 10;       while (n >= 10) {         n = n / 10;         n = n * 10;         e += n;         n = n / 10;         n += s;         s = n % 10;       }       cout << e + s << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     long long int n, k;     cin >> t;     while (t--) {       cin >> n >> k;       if (n < k * k) {         cout <<  NO  << endl;         continue;       } else {         if ((n % 2 == 1 && k % 2 == 1) || (n % 2 == 0 && k % 2 == 0))           cout <<  YES  << endl;         else           cout <<  NO  << endl;       }     }     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;   int n, m;   vector<int> a;   bool chk(int c) {     int lst = a[0];     if (a[0] + c >= m) lst = 0;     for (int i = 1; i <= (n - 1); ++i) {       if (a[i] + c >= m + lst) continue;       if (a[i] < lst && a[i] + c >= lst) continue;       if (a[i] + c < lst) return false;       lst = a[i];     }     return true;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin.exceptions(cin.failbit);     cin >> n >> m;     a.resize(n);     for (int i = 0; i < (n); ++i) cin >> a[i];     bool sorted = true;     for (int i = 0; i < (n); ++i) {       if (i != 0 && a[i - 1] > a[i]) sorted = false;     }     if (sorted) {       cout << 0 << endl;       return 0;     }     int lo = 0, hi = m, mid = (hi + lo) / 2;     while (hi - lo > 1) {       if (chk(mid))         hi = mid;       else         lo = mid;       mid = (hi + lo) / 2;     }     cout << hi << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Node {     Node() : vis(0), comp(-1) {}     int vis;     int comp;     vector<int> adj;   };   vector<int> vis;   bool dfs(vector<vector<int> >& a, int u, string& res) {     vis[u] = true;     for (int i = 0; i < a.size(); i++) {       if (i == u) continue;       if (vis[i] == false) {         if (a[u][i] == 0) {           if (res[u] ==  b ) res[u] =  a ;           res[i] = (res[u] ==  a ) ?  c  :  a ;           if (!dfs(a, i, res)) return false;         }       } else {         if (a[u][i] == 0) {           if (res[u] == res[i]) return false;         }       }     }     return true;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     vector<vector<int> > a(n, vector<int>(n));     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       a[u][v] = 1;       a[v][u] = 1;     }     string res(n,  b );     vis.assign(n, false);     for (int i = 0; i < n; i++) {       if (vis[i] == false) {         if (!dfs(a, i, res)) {           cout <<  No  << endl;           return 0;         }       }     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (abs(res[i] - res[j]) == 2 && a[i][j] == 1) {           cout <<  No  << endl;           return 0;         }         if (abs(res[i] - res[j]) <= 1 && a[i][j] == 0) {           cout <<  No  << endl;           return 0;         }       }     }     cout <<  Yes  << endl;     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 9;   const int N = 333333;   int fib[N][2], fibSum[N][2];   void PreSolve() {     fib[1][0] = fib[2][1] = 1;     for (int i = 3; i < N; ++i) {       for (int j = 0; j < 2; ++j) {         fib[i][j] = fib[i - 1][j] + fib[i - 2][j];         if (fib[i][j] >= MOD) {           fib[i][j] -= MOD;         }       }     }     for (int i = 1; i < N; ++i) {       for (int j = 0; j < 2; ++j) {         fibSum[i][j] = fibSum[i - 1][j] + fib[i][j];         if (fibSum[i][j] >= MOD) {           fibSum[i][j] -= MOD;         }       }     }   }   void Add(int &a, const int b) {     a += b;     if (a >= MOD) {       a -= MOD;     }   }   int sum[N << 2], add[N << 2][2];   void Up(const int rt) {     sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];     if (sum[rt] >= MOD) {       sum[rt] -= MOD;     }   }   void Down(const int len, const int rt) {     if (add[rt][0] || add[rt][1]) {       int ls = rt << 1, rs = rt << 1 | 1;       int rl = len >> 1, ll = len - rl;       int temp[2];       for (int i = 0; i < 2; ++i) {         Add(add[ls][i], add[rt][i]);         Add(add[rs][i], temp[i] = ((long long)add[rt][0] * fib[ll + i + 1][0] +                                    (long long)add[rt][1] * fib[ll + i + 1][1]) %                                   MOD);       }       Add(sum[ls], ((long long)add[rt][0] * fibSum[ll][0] +                     (long long)add[rt][1] * fibSum[ll][1]) %                        MOD);       Add(sum[rs], ((long long)temp[0] * fibSum[rl][0] +                     (long long)temp[1] * fibSum[rl][1]) %                        MOD);       add[rt][0] = add[rt][1] = 0;     }   }   void Build(int l, int r, int rt) {     add[rt][0] = add[rt][1] = 0;     if (l == r) {       cin >> sum[rt];       return;     }     int m = l + r >> 1;     Build(l, m, rt << 1);     Build(m + 1, r, rt << 1 | 1);     Up(rt);   }   void Update(int L, int R, int l, int r, int rt) {     if (L <= l && r <= R) {       int temp[2];       for (int i = 0; i < 2; ++i) {         Add(add[rt][i],             temp[i] = (fib[l - L + i + 1][0] + fib[l - L + i + 1][1]) % MOD);       }       Add(sum[rt], ((long long)fibSum[r - l + 1][0] * temp[0] +                     (long long)fibSum[r - l + 1][1] * temp[1]) %                        MOD);       return;     }     int m = l + r >> 1;     Down(r - l + 1, rt);     if (L <= m) {       Update(L, R, l, m, rt << 1);     }     if (m < R) {       Update(L, R, m + 1, r, rt << 1 | 1);     }     Up(rt);   }   int Query(int L, int R, int l, int r, int rt) {     if (L <= l && r <= R) {       return sum[rt];     }     int m = l + r >> 1, result = 0;     Down(r - l + 1, rt);     if (L <= m) {       Add(result, Query(L, R, l, m, rt << 1));     }     if (m < R) {       Add(result, Query(L, R, m + 1, r, rt << 1 | 1));     }     Up(rt);     return result;   }   int main() {     int n, m;     PreSolve();     while (cin >> n >> m) {       Build(1, n, 1);       int op, x, y;       for (int i = 0; i < m; ++i) {         cin >> op >> x >> y;         if (op == 1) {           Update(x, y, 1, n, 1);         } else {           cout << Query(x, y, 1, n, 1) << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch -  0  < 0 || ch -  0  > 9) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch -  0  >= 0 && ch -  0  <= 9) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, m, A, B;   int a[200010], w[200010];   int quick_pow(int x, int p) {     int an = 1;     int po = x;     while (p) {       if (p & 1) an = 1ll * an * po % 998244353;       po = 1ll * po * po % 998244353;       p >>= 1;     }     return an;   }   int f[3010][3010], g[3010][3010];   int inv[3010 * 2];   int main() {     n = read();     m = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= n; i++) w[i] = read();     for (int i = 1; i <= n; i++) {       A += (a[i] == 1) * w[i];       A %= 998244353;       B += (a[i] == 0) * w[i];       B %= 998244353;     }     for (int i = 1; i <= 2 * m; i++)       inv[i] = quick_pow(A + B + i - m, 998244353 - 2);     for (int i = m; i >= 0; i--) {       f[i][m - i] = g[i][m - i] = 1;       for (int j = min(m - i - 1, B); j >= 0; j--) {         f[i][j] = (1ll * f[i + 1][j] * (A + i + 1) % 998244353 * inv[i - j + m] %                        998244353 +                    1ll * f[i][j + 1] * (B - j) % 998244353 * inv[i - j + m] %                        998244353) %                   998244353;         g[i][j] = (1ll * g[i + 1][j] * (A + i) % 998244353 * inv[i - j + m] %                        998244353 +                    1ll * g[i][j + 1] * (B - j - 1) % 998244353 * inv[i - j + m] %                        998244353) %                   998244353;       }     }     for (int i = 1; i <= n; i++) {       if (a[i] == 1)         printf( %d n , 1ll * w[i] * f[0][0] % 998244353);       else         printf( %d n , 1ll * w[i] * g[0][0] % 998244353);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, h;     cin >> n >> m >> h;     int a[105][105] = {0};     int x[105] = {0}, y[105] = {0};     for (int i = 1; i <= m; i++) cin >> x[i];     for (int i = 1; i <= n; i++) cin >> y[i];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];         if (a[i][j] != 0) {           a[i][j] = min(x[j], y[i]);         }       }     }     int i, j;     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         cout << a[i][j] <<    ;       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     cout << 6 - n <<   n ;     vector<bool> chk(6, false);     for (int i = 0; i < n; i++) {       string s;       cin >> s;       if (s[0] ==  p )         chk[0] = true;       else if (s[0] ==  g )         chk[1] = true;       else if (s[0] ==  b )         chk[2] = true;       else if (s[0] ==  o )         chk[3] = true;       else if (s[0] ==  r )         chk[4] = true;       else if (s[0] ==  y )         chk[5] = true;     }     if (chk[0] == false) cout <<  Power  <<   n ;     if (chk[1] == false) cout <<  Time  <<   n ;     if (chk[2] == false) cout <<  Space  <<   n ;     if (chk[3] == false) cout <<  Soul  <<   n ;     if (chk[4] == false) cout <<  Reality  <<   n ;     if (chk[5] == false) cout <<  Mind  <<   n ;   }
#include <bits/stdc++.h>   int dx[] = {0, -1, 0, 1, -1, 1, -1, 1};   int dy[] = {-1, 0, 1, 0, 1, -1, -1, 1};   const int MOD = 1e9 + 7, N = 2e5 + 5, oo = 2e9;   const double pi = acos(-1);   using namespace std;   long long day[N], h[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     long long ans = -1;     for (int i = 0; i < m; i++) {       cin >> day[i] >> h[i];       ans = max(ans, h[i]);       if (i and day[i] - day[i - 1] < abs(h[i] - h[i - 1]))         return cout <<  IMPOSSIBLE , 0;     }     ans = max(ans, h[0] + day[0] - 1);     ans = max(ans, h[m - 1] + (n - day[m - 1]));     for (int i = 1; i < m; i++) {       long long dif = day[i] - day[i - 1], cur = h[i - 1];       if (h[i] > h[i - 1])         ans = max(ans, h[i] + (day[i] - day[i - 1] - abs(h[i] - h[i - 1])) / 2);       else         ans =             max(ans, h[i - 1] + (day[i] - day[i - 1] - abs(h[i] - h[i - 1])) / 2);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool debug = false;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   map<string, int> lesha;   vector<int> v;   int nxt[500035][16], sz, w[1 << 15][16];   const int maxk = 110;   int dp[1 << 15][maxk];   void ii() {     for (int s = 0; s < (1 << n); s++) {       for (int j = 1; j <= n; j++) {         int x = (1 << n) - 1 - ((1 << j) - 1);         w[s][j] = __builtin_popcount(x & s);       }     }   }   void init() {     sz = (int)v.size();     for (int(i) = 0; (i) < (int)(sz + 1); (i)++)       for (int(j) = 0; (j) < (int)(n + 1); (j)++) nxt[i][j] = 1 << 30;     for (int i = sz - 1; i >= 0; i--) {       for (int j = 1; j <= n; j++) nxt[i][j] = nxt[i + 1][j];       nxt[i][v[i]] = i + 1;     }   }   int cal() {     init();     for (int(i) = 0; (i) < (int)(1 << n); (i)++)       for (int(k) = 0; (k) < (int)(maxk); (k)++) dp[i][k] = 1 << 30;     dp[0][0] = 0;     dp[1 << (v[0] - 1)][0] = 1;     for (int s = 0; s < (1 << n); s++) {       for (int k = 0; k < maxk; k++)         for (int x = 1; x <= n; x++)           if (dp[s][k] < 1 << 30 && k + w[s][x] < maxk) {             int tmp = dp[s | (1 << (x - 1))][k + w[s][x]];             dp[s | (1 << (x - 1))][k + w[s][x]] = min(tmp, nxt[dp[s][k]][x]);           }     }     for (int k = 0; k < maxk; k++)       if (dp[(1 << n) - 1][k] != 1 << 30) {         return k;       }     return 1 << 30;   }   int main() {     scanf( %d , &n);     string tmp;     for (int(i) = 0; (i) < (int)(n); (i)++) {       cin >> tmp;       lesha[tmp] = i + 1;     }     scanf( %d , &m);     ii();     int ans = 1 << 30;     int aa = 0;     for (int(i) = 0; (i) < (int)(m); (i)++) {       scanf( %d , &k);       v.clear();       for (int(j) = 0; (j) < (int)(k); (j)++) {         cin >> tmp;         if (lesha.find(tmp) != lesha.end()) {           v.push_back(lesha[tmp]);         }       }       if (v.empty()) continue;       int tt = cal();       if (tt < ans) {         ans = tt;         aa = i + 1;       }     }     if (!aa)       puts( Brand new problem! );     else {       int count = (n - 1) * n / 2 - ans + 1;       printf( %d n , aa);       printf( [: );       for (int(i) = 0; (i) < (int)(count); (i)++) printf( | );       puts( :] );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   long long INF = 1LL << 60;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     vector<long long> l(n), r(n), m(n);     for (long long i = (long long)(0); i < (n); i++) {       cin >> m[i];     }     stack<pair<long long, long long>> stk;     stk.push(make_pair(0, -1));     stk.push(make_pair(m[0], 0));     l[0] = m[0];     for (long long i = (long long)(1); i < (n); i++) {       if (m[i] > stk.top().first) {         l[i] = l[i - 1] + m[i];       } else {         while (!stk.empty() && m[i] < stk.top().first) {           stk.pop();         }         int ind = stk.top().second;         long long prv;         if (ind == -1) {           prv = 0;         } else {           prv = l[ind];         }         l[i] = prv + (i - ind) * m[i];       }       stk.push(make_pair(m[i], i));     }     while (!stk.empty()) {       stk.pop();     };     reverse(m.begin(), m.end());     ;     stk.push(make_pair(0, -1));     stk.push(make_pair(m[0], 0));     r[0] = m[0];     for (long long i = (long long)(1); i < (n); i++) {       if (m[i] > stk.top().first) {         r[i] = r[i - 1] + m[i];       } else {         while (!stk.empty() && m[i] < stk.top().first) {           stk.pop();         }         int ind = stk.top().second;         long long prv;         if (ind == -1) {           prv = 0;         } else {           prv = r[ind];         }         r[i] = prv + (i - ind) * m[i];       }       stk.push(make_pair(m[i], i));     };     reverse(m.begin(), m.end());     ;     ;     reverse(r.begin(), r.end());     ;     int ind = 0;     long long out = 0;     long long temp;     for (long long i = (long long)(0); i < (n); i++) {       temp = l[i] + r[i] - m[i];       if (temp > out) {         ind = i;         out = temp;       }     }     vector<long long> outt(n);     outt[ind] = m[ind];     long long big = m[ind];     for (int i = ind - 1; i >= 0; i--) {       if (m[i] < big) {         big = m[i];       }       outt[i] = big;     }     big = m[ind];     for (int i = ind + 1; i < n; i++) {       if (m[i] < big) {         big = m[i];       }       outt[i] = big;     }     for (long long i = (long long)(0); i < (n); i++) {       cout << outt[i] <<    ;     }   }
#include <bits/stdc++.h>   const int N = 2e3 + 9;   using namespace std;   int n, dp[5][N], a[N], b[5] = {0, 1, 2, 1, 2};   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= 4; i++) {       for (int j = 1; j <= n; j++) {         dp[i][j] = max(dp[i - 1][j], dp[i][j - 1] + (a[j] == b[i]));       }     }     printf( %d n , dp[4][n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, k;     cin >> n >> k;     int hash[201] = {0};     vector<pair<int, int>> v;     for (int i = 0; i < n; i++) {       int l, r;       cin >> l >> r;       v.push_back(make_pair(l, r));       for (int j = l; j < r + 1; j++) hash[j]++;     }     vector<int> ans(n);     for (int j = 0; j < 250; j++) {       while (hash[j] > k) {         int m = -1;         for (int i = 0; i < n; i++) {           if (!ans[i] && (j >= v[i].first && j <= v[i].second)) {             if (m == -1 || v[i].second > v[m].second) m = i;           }         }         if (m == -1) break;         for (int i = v[m].first; i < v[m].second + 1; i++) hash[i]--;         ans[m] = 1;       }     }     cout << accumulate(ans.begin(), ans.end(), 0) << endl;     for (int i = 0; i < n; i++)       if (ans[i]) cout << i + 1 <<    ;   }