malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }   int n, m, c;   int A[1111];   int pref = 0, post = 0;   bool end() {     bool ans = true;     for (int(i) = 0; (i) < (n); (i)++)       if (A[i] == -1 || (i < n - 1 && A[i + 1] < A[i])) ans = false;     return ans;   }   int main() {     memset(A, -1, sizeof(A));     scanf( %d%d%d , &n, &m, &c);     int H = (c + 1) / 2;     for (int(i) = 0; (i) < (m); (i)++) {       int x;       scanf( %d , &x);       if (x <= H) {         int i = 0;         while (i < n && (A[i] <= x && A[i] != -1)) i++;         A[i] = x;         printf( %d n , i + 1);         fflush(stdout);         if (end()) return 0;       } else {         int i = n - 1;         while (i >= 0 && (A[i] >= x && A[i] != -1)) i--;         A[i] = x;         printf( %d n , i + 1);         fflush(stdout);         if (end()) return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int a[N];   int main() {     ios::sync_with_stdio(0);     int tt;     cin >> tt;     while (tt--) {       int n;       cin >> n;       if (n % 2 == 0) {         cout << n / 2 <<     << n / 2 << endl;       } else {         int lim = sqrt(n + 0.5), fg = 0;         for (int i = 3; i <= lim; ++i) {           if (n % i == 0) {             cout << (n / i) <<     << (n / i) * (i - 1) << endl;             fg = 1;             break;           }         }         if (!fg) {           cout << 1 <<     << n - 1 << endl;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     string a;     cin >> a;     int n = 0, m = 0, first = 0, last = 0;     bool b = true;     for (int i = 0; i < a.size(); i++) {       if (a[i] ==  H ) n++;       if (a[i] ==  Q ) m++;     }     int sm = int(sqrt(m));     int i = 0;     i = a.size() - 1;     while ((i >= 0) && (a[i] ==  H )) {       last++;       i--;     };     last /= 2;     i = 0;     while ((i < a.size()) && (a[i] ==  H )) {       first++;       i++;     };     first /= 2;     if (m == 0)       cout <<  Yes ;     else {       if (!((sm * sm == m) && (n % (sm + 1) == 0)))         cout <<  No ;       else {         string middle =   ;         int counter = 0;         while (counter < sm) {           if (a[i] ==  Q ) counter++;           middle += a[i];           i++;         }         string str;         str = middle;         for (int i = 0; i < first; i++) {           str =  H  + str;         }         for (int i = 0; i < last; i++) {           str = str +  H ;         }         string out =   ;         for (int i = 0; i < str.size(); i++) {           if (str[i] ==  H )             out = out +  H ;           else             out += str;         };         if (out == a)           cout <<  Yes ;         else           cout <<  No ;       };     }     return EXIT_SUCCESS;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1000, MAX_M = 1000;   int N, M;   int a[MAX_N][MAX_M], mxx[MAX_N], mxy[MAX_M], cmpx[MAX_N][MAX_M],       cmpy[MAX_N][MAX_M];   vector<int> cmp;   int main() {     scanf( %d %d , &N, &M);     for (int i = (0); i < (N); i++)       for (int j = (0); j < (M); j++) {         scanf( %d , &a[i][j]);       }     for (int i = (0); i < (N); i++) {       cmp.clear();       for (int j = (0); j < (M); j++) {         cmp.push_back(a[i][j]);       }       sort(cmp.begin(), cmp.end());       cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());       mxx[i] = (int)cmp.size();       for (int j = (0); j < (M); j++) {         cmpx[i][j] =             lower_bound(cmp.begin(), cmp.end(), a[i][j]) - cmp.begin() + 1;       }     }     for (int i = (0); i < (M); i++) {       cmp.clear();       for (int j = (0); j < (N); j++) {         cmp.push_back(a[j][i]);       }       sort(cmp.begin(), cmp.end());       cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());       mxy[i] = (int)cmp.size();       for (int j = (0); j < (N); j++) {         cmpy[j][i] =             lower_bound(cmp.begin(), cmp.end(), a[j][i]) - cmp.begin() + 1;       }     }     for (int i = (0); i < (N); i++) {       for (int j = (0); j < (M); j++) {         if (j) printf(   );         int mx = max(cmpx[i][j], cmpy[i][j]);         printf( %d , mx + max(mxx[i] - cmpx[i][j], mxy[j] - cmpy[i][j]));       }       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, howMany[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     vector<pair<int, int> > beacons;     for (int i = 0; i < n; i++) {       int x, p;       cin >> x >> p;       beacons.push_back({x, p});     }     sort(beacons.begin(), beacons.end());     howMany[0] = 0;     auto it = beacons.begin();     for (int i = 1; i < n; i++) {       int now = beacons[i].first, power = beacons[i].second;       auto it =           lower_bound(beacons.begin(), beacons.end(), make_pair(now - power, -1));       int idx = it - beacons.begin();       if (idx == 0) {         howMany[i] = i;       } else {         howMany[i] = howMany[idx - 1] + (i - idx);       }     }     int ans = n;     for (int i = 0; i < n; i++) {       ans = min(ans, howMany[i] + (n - i - 1));     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 6;   int n, k, h[N];   long long p, m, t, a[N], b[N];   struct xd {     int z, i;     bool operator<(const xd &d) const { return z > d.z; }   } tmp, nw;   inline int read() {     int T = 0, F = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) F = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       T = (T << 3) + (T << 1) + (ch - 48), ch = getchar();     return F * T;   }   bool check(long long x) {     priority_queue<xd> q;     memset(b, 0, sizeof(b));     for (int i = 1; i <= n; ++i)       if (x - a[i] * m < h[i]) tmp.z = x / a[i], tmp.i = i, q.push(tmp);     for (int i = 1; i <= m && !q.empty(); ++i)       for (int j = 1; j <= k && !q.empty(); ++j) {         tmp = q.top(), q.pop();         if (tmp.z < i) return 0;         ++b[tmp.i];         if (x + b[tmp.i] * p - a[tmp.i] * m < h[tmp.i])           tmp.z = (x + b[tmp.i] * p) / a[tmp.i], q.push(tmp);       }     return q.empty();   }   long long ef(long long l, long long r) {     if (l == r) return l;     long long mid = l + r >> 1ll;     if (check(mid)) return ef(l, mid);     return ef(mid + 1, r);   }   int main() {     n = read(), m = read(), k = read(), p = read();     for (int i = 1; i <= n; ++i) h[i] = read(), a[i] = read();     printf( %lld n , ef(0, 5e12 + 1e9 + 1));     return 0;   }
#include <bits/stdc++.h>   int t1, t2, t3;   int g[88][88];   int n, k;   int m;   int dp[88][88][88];   int ans = 0x3f3f3f3f;   int main() {     scanf( %d%d , &n, &k);     scanf( %d , &m);     for (int i = 0; i <= n + 1; i++) {       for (int j = 0; j <= n + 1; j++) {         g[i][j] = 0x3f3f3f3f;         for (int kk = 0; kk <= k; kk++) dp[i][j][kk] = 0x3f3f3f3f;       }     }     while (m--) {       scanf( %d%d%d , &t1, &t2, &t3);       g[t1][t2] = (g[t1][t2] <= t3 ? g[t1][t2] : t3);     }     for (int i = 1; i <= n; i++) {       dp[i][0][1] = 0;       dp[i][n + 1][1] = 0;     }     for (int diff = n; diff > 0; diff--) {       for (int i = 1; i <= n; i++) {         if (i + diff > n + 1) continue;         for (int kk = 0; kk < k; kk++) {           if (dp[i][i + diff][kk] == 0x3f3f3f3f) continue;           for (int j = i + 1; j < i + diff; j++) {             if (g[i][j] == 0x3f3f3f3f) continue;             dp[j][i + diff][kk + 1] =                 (dp[j][i + diff][kk + 1] <= dp[i][i + diff][kk] + g[i][j]                      ? dp[j][i + diff][kk + 1]                      : dp[i][i + diff][kk] + g[i][j]);             dp[j][i][kk + 1] = (dp[j][i][kk + 1] <= dp[i][i + diff][kk] + g[i][j]                                     ? dp[j][i][kk + 1]                                     : dp[i][i + diff][kk] + g[i][j]);           }         }       }       for (int i = 1; i <= n; i++) {         if (i - diff < 0) continue;         for (int kk = 0; kk < k; kk++) {           if (dp[i][i - diff][kk] == 0x3f3f3f3f) continue;           for (int j = i - 1; j > i - diff; j--) {             if (g[i][j] == 0x3f3f3f3f) continue;             dp[j][i - diff][kk + 1] =                 (dp[j][i - diff][kk + 1] <= dp[i][i - diff][kk] + g[i][j]                      ? dp[j][i - diff][kk + 1]                      : dp[i][i - diff][kk] + g[i][j]);             dp[j][i][kk + 1] = (dp[j][i][kk + 1] <= dp[i][i - diff][kk] + g[i][j]                                     ? dp[j][i][kk + 1]                                     : dp[i][i - diff][kk] + g[i][j]);           }         }       }     }     for (int i = 0; i <= n + 1; i++) {       for (int j = 0; j <= n + 1; j++) {         ans = (ans <= dp[i][j][k] ? ans : dp[i][j][k]);       }     }     if (ans == 0x3f3f3f3f)       printf( -1 );     else       printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   int n, a[300010], s[300010], x[2];   long long p;   int main() {     int i, j;     long long k;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %lld , &k);       for (j = 0; j <= 60; j++)         if (k & (1ll << j)) a[i]++;       s[i] = s[i - 1] + a[i];     }     x[0] = 1;     for (i = 1; i <= n; i++) {       p += x[s[i] & 1];       x[s[i] & 1]++;       for (j = i, k = 0; j > 0 && i - j <= 80; j--) {         k = max(k, (long long)a[j]);         if (!(s[i] - s[j - 1] & 1) && k * 2 > s[i] - s[j - 1]) p--;       }     }     cout << p <<   n ;     return 0;   }
#include <bits/stdc++.h>   int compare(const void *a, const void *b) { return *(int *)a - *(int *)b; }   int main() {     int n, k;     scanf( %d%d , &n, &k);     int i;     if ((n == 1 && k == 1)) {       printf( -1 n );       return 0;     }     if (n == k) {       printf( -1 n );       return 0;     }     if ((n - k) % 2 != 0) {       printf( 1  );       for (i = 2; i <= ((n - k) - (n - k) % 2); i += 2) {         printf( %d %d  , i + 1, i);       }       for (i = n - k + 1; i <= n; i++) printf( %d  , i);     } else {       for (i = 1; i <= (n - k); i += 2) {         printf( %d %d  , i + 1, i);       }       for (i = n - k + 1; i <= n; i++) printf( %d  , i);     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int print1() {     cout << -1 << endl;     return 0;   }   int main() {     int n, m;     cin >> n >> m;     vector<vector<int> > e(n);     int a, b;     for (int i = 0; i < m; ++i) {       cin >> a >> b;       a--;       b--;       e[a].push_back(b);       e[b].push_back(a);     }     vector<int> c(n, 0);     vector<int> cnt(3, 0);     cnt[0] = n;     for (auto &v : e[0]) {       c[v] = 2;       cnt[0]--;       cnt[2]++;     }     for (a = 0; a < n && c[a] == 0; ++a)       ;     if (a == n) return print1();     for (auto &v : e[a]) {       if (c[v] == 2) {         c[v] = 1;         cnt[1]++;         cnt[2]--;       }     }     for (int j = 0; j < 3; ++j)       if (cnt[j] == 0) return print1();     vector<int> loc(3, 0);     for (int i = 0; i < n; ++i) {       loc[0] = 0;       loc[1] = 0;       loc[2] = 0;       for (auto &v : e[i]) loc[c[v]]++;       if (loc[c[i]] != 0) return print1();       for (int j = 0; j < 3; ++j)         if (c[i] != j && loc[j] != cnt[j]) return print1();     }     for (int i = 0; i < n; ++i) cout << c[i] + 1 <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 55;   char a[maxn][maxn];   int vis[maxn][maxn];   int n, m;   inline void go(int x, int y) {     if (vis[x][y] == 1) return;     if (a[x][y] !=  # ) return;     vis[x][y] = 1;     go(x - 1, y);     go(x + 1, y);     go(x, y - 1);     go(x, y + 1);   }   inline bool check(int x, int y) {     a[x][y] =  . ;     int sum = 0;     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++)         if (a[i][j] ==  #  && vis[i][j] == 0) {           sum++;           go(i, j);         }     }     a[x][y] =  # ;     return sum > 1;   }   int main() {     cin >> n >> m;     int sum = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> a[i][j];         if (a[i][j] ==  # ) sum++;       }     if (sum <= 2) {       cout <<  -1  << endl;       return 0;     }     int ans = 2;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j] ==  # )           if (check(i, j)) ans = 1;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int max_dp = 2e5 + 1;   int dp[101][max_dp];   int n, k;   int a[101], b[101];   int solve(int num, int bal) {     if (dp[num][bal] != -1) {       return dp[num][bal];     }     if (num == 0) {       if (bal == 1e5) {         return 0;       } else {         return -1e9;       }     }     int x = solve(num - 1, bal);     int y = a[num - 1] + solve(num - 1, bal + a[num - 1] - k * b[num - 1]);     dp[num][bal] = max(x, y);     return dp[num][bal];   }   int main() {     cin >> n >> k;     memset(dp, -1, sizeof(dp));     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     int ans = solve(n, 1e5);     if (ans > 0)       cout << ans << endl;     else       cout <<  -1 n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, v[1005], xi, yi;   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) scanf( %d , &v[i]);     int res = 0;     while (m--) {       scanf( %d %d , &xi, &yi);       xi--, yi--;       res += min(v[xi], v[yi]);     }     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A[100][10000];   int d[100][10000];   int main() {     int n, m;     cin >> n >> m;     string str;     getline(cin, str);     for (int i = 0; i < n; i++) {       getline(cin, str);       for (int j = 0; j < str.size(); j++)         if (str[j] ==  1 )           A[i][j] = 1;         else           A[i][j] = 0;     }     for (int i = 0; i < n; i++) {       int prev = 1000001;       int prev2 = 100000;       for (int j = m - 1; j >= 0; j--)         if (A[i][j]) {           prev = -(m - j);           break;         }       if (prev == 1000001) {         cout << -1 << endl;         return 0;       }       bool first = true;       for (int j = 0; j < m; j++) {         if (A[i][j]) {           if (first) {             prev2 = j + 1 + m - 1;             first = false;           }           d[i][j] = 0;           prev = j;         } else           d[i][j] = j - prev;       }       for (int j = m - 1; j >= 0; j--) {         d[i][j] = min(d[i][j], prev2 - j);         if (A[i][j]) prev2 = j;       }     }     int mindall = 1000000;     for (int i = 0; i < m; i++) {       int mind = 0;       for (int j = 0; j < n; j++) {         mind += d[j][i];       }       mindall = min(mindall, mind);     }     cout << mindall << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, tt;     cin >> n >> tt;     vector<int> a(1 << n);     long long sum = 0;     for (int i = 0; i < (1 << n); i++) {       cin >> a[i];       sum += (long long)a[i];     }     cout << fixed << setprecision(17) << (double)sum / (1 << n) <<   n ;     while (tt--) {       int x, y;       cin >> x >> y;       sum += y - a[x];       a[x] = y;       cout << fixed << setprecision(17) << (double)sum / (1 << n) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n >= 1 && n <= 10 || n >= 22 && n <= 25)       cout <<  0 ;     else if (n == 11)       cout <<  4 ;     else if (n == 20)       cout <<  15 ;     else       cout <<  4 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int l = 0, u = 0;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] > 90)         l++;       else         u++;     }     if (l >= u) {       transform(s.begin(), s.end(), s.begin(), ::tolower);       cout << s << endl;     } else {       transform(s.begin(), s.end(), s.begin(), ::toupper);       cout << s << endl;     }     return 0;   }
#include <bits/stdc++.h>   const int MN = 1e5 + 4;   int N, Q, ecnt, ch[MN], depth[MN], len[MN];   long long rt, bit1[MN], *bit2[MN];   std::vector<int> adj[MN];   inline void upd(long long *bit, int ind, int cap, long long val) {     for (; ind < cap; ind += ind & -ind) bit[ind] += val;   }   inline long long qry(long long *bit, int ind) {     long long res = 0;     for (; ind; ind -= ind & -ind) res += bit[ind];     return res;   }   void dfs1(int src, int p, int d, int b) {     ++ecnt;     ch[src] = b;     depth[src] = d++;     for (int i : adj[src]) {       if (i == p) continue;       dfs1(i, src, d, b);     }   }   int main() {     scanf( %d%d , &N, &Q);     for (int i = 1, a, b; i < N; ++i) {       scanf( %d%d , &a, &b);       adj[a].emplace_back(b);       adj[b].emplace_back(a);     }     int cnt = 0;     for (int i : adj[1]) {       dfs1(i, 1, 1, ++cnt);       len[cnt] = ecnt + 1;       bit2[cnt] = (long long *)calloc(ecnt + 1, sizeof(long long));       ecnt = 0;     }     for (int i = 0, a, b, c, d; i < Q; ++i) {       scanf( %d , &a);       if (a) {         scanf( %d , &b);         if (b == 1)           printf( %lld n , rt);         else           printf( %lld n , qry(bit1, depth[b]) + qry(bit2[ch[b]], depth[b]));       } else {         scanf( %d%d%d , &b, &c, &d);         if (b == 1) {           upd(bit1, 1, MN, c);           upd(bit1, d + 1, MN, -c);           rt += c;         } else {           if (d < depth[b]) {             upd(bit2[ch[b]], depth[b] - d, len[ch[b]], c);             upd(bit2[ch[b]], depth[b] + d + 1, len[ch[b]], -c);           } else {             upd(bit2[ch[b]], 1, len[ch[b]], c);             upd(bit2[ch[b]], depth[b] + d + 1, len[ch[b]], -c);             if (depth[b] != d) {               upd(bit1, 1, MN, c);               upd(bit1, d - depth[b] + 1, MN, -c);               upd(bit2[ch[b]], 1, len[ch[b]], -c);               upd(bit2[ch[b]], d - depth[b] + 1, len[ch[b]], c);             }             rt += c;           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int l, r;     cin >> l >> r;     long long int res = 0;     for (long long int i = 1; i <= r; i *= 2) {       for (long long int j = 1; j <= r; j *= 3) {         if (i * j <= r && i * j >= l) {           res++;         }       }     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, pos, l, r;     cin >> n >> pos >> l >> r;     int result;     if (l == 1 && r == n) {       result = 0;     } else if (l == 1) {       result = abs(pos - r) + 1;     } else if (r == n) {       result = abs(pos - l) + 1;     } else {       result = min(abs(pos - l), abs(pos - r)) + r - l + 2;     }     cout << result << endl;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> graph[3123];   vector<vector<int> > vCiclos;   int dist[3123];   int vis[3123];   vector<int> v;   int ciclo[3123];   int tamanhoCiclo[3123];   int cnt = 1;   int n;   bool cycle[3123];   void dfs(int x, int pai) {     vis[x] = 1;     v.push_back(x);     for (int i = 0; i < graph[x].size(); ++i) {       int y = graph[x][i];       if (y == pai) continue;       if (vis[y] == 0) {         dfs(y, x);       } else if (vis[y] == 1) {         vector<int> aux;         for (int j = v.size() - 1;; --j) {           int vert = v[j];           ciclo[vert] = cnt;           aux.push_back(v[j]);           cycle[v[j]] = true;           if (vert == y) break;         }         cnt++;         vCiclos.push_back(aux);       }     }     vis[x] = 2;     v.pop_back();   }   void dfs2(int x, int pai, int k) {     dist[x] = k;     for (int i = 0; i < graph[x].size(); i++) {       int y = graph[x][i];       if (y == pai || cycle[y]) continue;       dfs2(y, x, k + 1);     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d %d , &x, &y);       graph[x].push_back(y);       graph[y].push_back(x);     }     dfs(1, 1);     for (int i = 0; i < vCiclos.size(); i++) {       for (int j = 0; j < vCiclos[i].size(); j++) {         int y = vCiclos[i][j];         dfs2(y, y, 0);       }     }     for (int i = 1; i <= n; i++) printf( %d  , dist[i]);     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string months[] = { January ,    February ,  March ,     April ,                         May ,        June ,      July ,      August ,                         September ,  October ,   November ,  December };     string s;     int n, a;     cin >> s >> n;     for (int i = 0; i < 12; i++) {       if (months[i].compare(s) == 0) {         a = i + n;         break;       }     }     while (a > 11) {       a = a - 12;     }     cout << months[a];   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int INF = 2e9 + 5;   const int MAXN = 100010;   int n;   long long a, r, m, h[MAXN];   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin >> n >> a >> r >> m;     for (int i = 0; i < n; i++) {       cin >> h[i];     }     m = min(m, a + r);     sort(h, h + n, greater<long long>());     long long sum = 0;     for (int i = 0; i < n; i++) {       sum += h[i];     }     long long lbound = (sum + n - 1) / n;     long long cur = (n * h[0] - sum) * a;     long long ans = 1e18;     long long run = 0;     for (int i = 0; i < n; i++) {       if (h[i] < lbound) break;       long long lo = lbound;       if (i + 1 < n) {         lo = max(lo, h[i + 1]);       }       ans = min(ans, cur + run);       long long delta = (i + 1) * m - n * a;       run += delta * (h[i] - lo);     }     ans = min(ans, cur + run);     reverse(h, h + n);     long long ubound = sum / n;     cur = (sum - n * h[0]) * r;     run = 0;     for (int i = 0; i < n; i++) {       if (h[i] > ubound) break;       long long hi = ubound;       if (i + 1 < n) {         hi = min(hi, h[i + 1]);       }       ans = min(ans, cur + run);       long long delta = (i + 1) * m - n * r;       run += delta * (hi - h[i]);       ;     }     ans = min(ans, cur + run);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   const int N = 2e5 + 10;   const int MX = 1e9;   int n, t;   int ar[N], mn[N];   unordered_map<int, int> bit;   void upd(int x, int val) {     x++;     while (x <= t) {       bit[x] += val;       x += (x & (-x));     }   }   int ask(int x) {     x++;     int ret = 0;     while (x) {       ret += bit[x];       x -= (x & (-x));     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> t;     t = min(t, n + MX + 10);     for (int i = 1; i <= n; i++) {       cin >> ar[i];       mn[i] = max(ar[i] - i, 0);     }     int ans = 0;     for (int i = 1; i <= n; i++) {       upd(mn[i], 1);       int mul = t - i - 1;       if (mul >= 0) {         ans = max(ans, ask(mul));       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gets(string s) {     int sum = 0;     while ((s[0] ==  0 ) and (s.size() != 1)) s = s.substr(1, s.size() - 1);     for (int i = 0; i < s.size(); i++) sum += s[i] - 48;     return sum;   }   int main() {     string s, s1, m;     int kol;     cin >> s;     m = s;     kol = gets(s);     for (int i = 0; i < s.size(); i++) {       s1 = s;       int kol1 = 0;       if (s1[i] !=  0 ) s1[i]--;       for (int j = i + 1; j < s.size(); j++) s1[j] =  9 ;       kol1 = gets(s1);       while ((s1[0] ==  0 ) and (s1.size() != 1))         s1 = s1.substr(1, s1.size() - 1);       if ((kol1 > kol) or           ((kol == kol1) and            ((s1.size() > m.size()) or ((s1 > m) and (s1.size() == m.size()))))) {         m = s1;         kol = kol1;       }     }     cout << m;   }