malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   int sz[maxn], N, M;   int main() {     scanf( %d%d , &N, &M);     memset(sz, 0, sizeof(sz));     vector<int> cnt;     cnt.resize(N);     int a, b;     for (int i = 1; i <= M; i++) {       scanf( %d%d , &a, &b);       a--, b--;       cnt[a]++, cnt[b]++;     }     sort(cnt.begin(), cnt.end());     for (int i = 0; i < N; i++) sz[cnt[i]]++;     if (sz[2] == N)       printf( ring topology n );     else if (sz[1] == 2 && sz[2] == N - 2)       printf( bus topology n );     else if (sz[1] == N - 1 && sz[N - 1] == 1)       printf( star topology n );     else       printf( unknown topology n );   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int h, s, preh, pres, vis, water, sec;   } n[400010][4];   int m, k, p, hh;   char c;   queue<node> q;   int main() {     scanf( %d%d , &m, &k);     getchar();     for (int i = 1; i <= m; i++) {       scanf( %c , &c);       n[i][1].vis = n[i][2].vis = 0;       n[i][1].h = n[i][2].h = i;       n[i][1].s = 1;       if (c ==  - )         n[i][1].sec = 1;       else         n[i][1].sec = 0;     }     getchar();     for (int i = 1; i <= m; i++) {       scanf( %c , &c);       n[i][2].s = 2;       if (c ==  - )         n[i][2].sec = 1;       else         n[i][2].sec = 0;     }     int side = 1, flag = 0;     n[1][1].water = 0;     n[1][1].vis = 1;     n[1][1].preh = n[1][1].pres = -1;     q.push(n[1][1]);     while (!q.empty()) {       node height = q.front();       hh = height.h;       side = height.s;       q.pop();       if (height.h <= height.water) {         continue;       }       if (height.h > m) {         printf( YES n );         flag = 1;         break;       }       if (side == 1) {         if (hh + 1 > m || (!n[hh + 1][1].vis && n[hh + 1][1].sec)) {           n[hh + 1][1].h = hh + 1;           n[hh + 1][1].vis = 1;           n[hh + 1][1].preh = hh;           n[hh + 1][1].pres = 1;           n[hh + 1][1].water = height.water + 1;           q.push(n[hh + 1][1]);         }         if (!n[hh - 1][1].vis && n[hh - 1][1].sec) {           n[hh - 1][1].vis = 1;           n[hh - 1][1].preh = hh;           n[hh - 1][1].pres = 1;           n[hh - 1][1].water = height.water + 1;           q.push(n[hh - 1][1]);         }         if (hh + k > m || (!n[hh + k][2].vis && n[hh + k][2].sec)) {           n[hh + k][2].h = hh + k;           n[hh + k][2].vis = 1;           n[hh + k][2].preh = hh;           n[hh + k][2].pres = 1;           n[hh + k][2].water = height.water + 1;           q.push(n[hh + k][2]);         }       } else {         if (hh + 1 > m || (!n[hh + 1][2].vis && n[hh + 1][2].sec)) {           n[hh + 1][2].h = hh + 1;           n[hh + 1][2].vis = 1;           n[hh + 1][2].preh = hh;           n[hh + 1][2].pres = 2;           n[hh + 1][2].water = height.water + 1;           q.push(n[hh + 1][2]);         }         if (!n[hh - 1][2].vis && n[hh - 1][2].sec) {           n[hh - 1][2].vis = 1;           n[hh - 1][2].preh = hh;           n[hh - 1][2].pres = 2;           n[hh - 1][2].water = height.water + 1;           q.push(n[hh - 1][2]);         }         if (hh + k > m || (!n[hh + k][1].vis && n[hh + k][1].sec)) {           n[hh + k][1].h = hh + k;           n[hh + k][1].vis = 1;           n[hh + k][1].preh = hh;           n[hh + k][1].pres = 2;           n[hh + k][1].water = height.water + 1;           q.push(n[hh + k][1]);         }       }     }     if (!flag) printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[110000], ans[110000];   int rs[70], G[110000][64], E[110000];   inline int read() {     int n = 0;     char a;     bool z = false;     while (a = getchar()) {       if (a >  9  || a <  0 )         if (z)           break;         else           continue;       if (!z) z = true;       n = (n << 1) + (n << 3) + (a ^ 48);     }     return n;   }   int main() {     scanf( %s , s + 1);     int m = strlen(s + 1), n = read(), len, x;     for (int i = 1; i <= m; ++i) ++rs[1 << s[i] -  a ];     for (int S = 0; S < 64; ++S)       if (S & S - 1) rs[S] = rs[S & S - 1] + rs[S & -S];     for (int i = 1; i <= n; ++i) {       x = read();       scanf( %s , s + 1);       len = strlen(s + 1);       for (int j = 1; j <= len; ++j) E[x] |= 1 << s[j] -  a ;     }     for (int i = 1; i <= m; ++i)       if (!E[i]) E[i] = 63;     for (int i = m; i; --i)       for (int S = 0; S < 64; ++S) G[i][S] = G[i + 1][S] + (S & E[i] ? 1 : 0);     for (int i = 1; i <= m; ++i) {       bool zz = false;       for (int j = 1; j <= 6; ++j) {         if (!rs[1 << j - 1] || !(E[i] & 1 << j - 1)) continue;         bool Z = true;         for (int S = 0; S < 64; ++S)           if (G[i + 1][S] < rs[S] - (S & 1 << j - 1 ? 1 : 0)) {             Z = false;             break;           }         if (Z) {           ans[i] = j +  a  - 1;           zz = true;           for (int S = 0; S < 64; ++S) rs[S] -= S & 1 << j - 1 ? 1 : 0;           break;         }       }       if (!zz) return !printf( Impossible );     }     printf( %s , ans + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 102;   int R, P, S;   bool visited[3][MAXN][MAXN][MAXN];   double dp[3][MAXN][MAXN][MAXN];   double f(int t, int r, int p, int s) {     if (!r && !p && !s) {       return 0;     } else if (r && !p && !s) {       return t == 0;     } else if (!r && p && !s) {       return t == 1;     } else if (!r && !p && s) {       return t == 2;     }     double &result = dp[t][r][p][s];     if (visited[t][r][p][s]) {       return result;     }     visited[t][r][p][s] = true;     double sum = r * p + r * s + p * s;     if (r && p) {       result += f(t, r - 1, p, s) * ((r * p) / sum);     }     if (r && s) {       result += f(t, r, p, s - 1) * ((r * s) / sum);     }     if (p && s) {       result += f(t, r, p - 1, s) * ((p * s) / sum);     }     return result;   }   int main() {     cin >> R >> S >> P;     printf( %.10lf %.10lf %.10lf n , f(0, R, P, S), f(2, R, P, S), f(1, R, P, S));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int main() {     ios_base::sync_with_stdio(true);     int c1, c2, a, b;     cin >> c1 >> c2 >> a >> b;     long long lo, hi, mid, numdiva, numdivb, numdivl, lcm, gc, na, nb, nl;     lo = 0;     hi = 3 * (1e9);     gc = gcd(a, b);     lcm = a;     lcm = (lcm * b) / gc;     while (hi > lo) {       mid = (lo + hi) >> 1;       numdiva = mid / a;       na = mid - numdiva;       if (na < c1) {         lo = mid + 1;         continue;       }       numdivb = mid / b;       nb = mid - numdivb;       if (nb < c2) {         lo = mid + 1;         continue;       }       numdivl = mid / lcm;       nl = mid - (numdiva + numdivb - numdivl);       if (na + nb - nl >= (c1 + c2))         hi = mid;       else         lo = mid + 1;     }     cout << lo <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     long long arr[n], dp[550][550] = {};     for (long long i = 0; i < n; i++) cin >> arr[i];     for (long long size = 1; size <= n; size++) {       for (long long r = size - 1; r < n; r++) {         long long l = r - size + 1;         if (r == l)           dp[l][r] = 1;         else if (r == l + 1) {           if (arr[l] == arr[r])             dp[l][r] = 1;           else             dp[l][r] = 2;         } else {           dp[l][r] = 1 + dp[l + 1][r];           if (arr[l] == arr[l + 1]) dp[l][r] = min(dp[l][r], 1 + dp[l + 2][r]);           for (long long k = l + 2; k <= r; k++) {             if (arr[l] == arr[k])               dp[l][r] = min(dp[l][r], dp[l + 1][k - 1] + dp[k + 1][r]);           }         }       }     }     cout << dp[0][n - 1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     unordered_map<string, string> dict;     string lecture[n], s1, s2;     for (int i = 0; i < m; i++) {       cin >> s1 >> s2;       dict[s1] = s2;     }     for (int i = 0; i < n; i++) {       cin >> lecture[i];       if (dict.find(lecture[i]) != dict.end()) {         if (dict[lecture[i]].size() < lecture[i].size()) {           lecture[i] = dict[lecture[i]];         }       }       cout << lecture[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int find_47(const string& s, int from) {     for (int i = from; i < (s.size() - 1); i++) {       if ((s[i] ==  4 ) && (s[i + 1] ==  7 )) return i;     }     return -1;   }   int main() {     int n, k;     cin >> n >> k;     cin >> s;     int from = 0;     while (true) {       if (k == 0) break;       int ind = find_47(s, from);       if (ind == -1) break;       if (ind % 2 == 0) {         if (ind + 2 >= n) {           s[ind + 1] =  4 ;           break;         }         if (s[ind + 2] ==  7 ) {           if (k % 2 == 1) s[ind + 1] =  4 ;           break;         } else {           s[ind + 1] =  4 ;           k--;           from = ind + 2;         }       } else {         if (s[ind - 1] ==  4 ) {           if (k % 2 == 1) s[ind] =  7 ;           break;         } else {           s[ind] =  7 ;           k--;           from = ind + 1;         }       }     }     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, k, m[100005], n[100005];   int main() {     while (scanf( %d , &k) != EOF) {       for (i = 1; i <= k; i++) scanf( %d , &n[i]);       j = 0;       for (i = k; i >= 2; i--) {         if (n[i] > n[i - 1])           continue;         else {           j = i - 1;           break;         }       }       printf( %d n , j);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     const int MAX_N = 200000;     int n;     char s[MAX_N][20];     set<string> chat;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %s , s[i]);     }     for (int i = n - 1; i >= 0; i--) {       if (chat.find(s[i]) == chat.end()) {         printf( %s n , s[i]);       }       chat.insert(s[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2 * 1e5 + 1;   int l[N], r[N], pos[30];   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     string s, t;     cin >> s >> t;     int n = s.size(), m = t.size();     memset(pos, -1, sizeof pos);     for (int i = 0, j = 0; i < n; i++) {       if (j < m && s[i] == t[j])         l[i] = pos[s[i] -  a ] = j++;       else         l[i] = pos[s[i] -  a ];     }     memset(pos, 0x3f, sizeof pos);     for (int i = n - 1, j = m - 1; i >= 0; i--) {       if (j >= 0 && s[i] == t[j])         r[i] = pos[s[i] -  a ] = j--;       else         r[i] = pos[s[i] -  a ];     }     bool ok = 1;     for (int i = 0; i < n; i++) ok &= (l[i] >= r[i]);     cout << (ok ?  Yes  :  No ) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int arr[105][105];   int main() {     long long int n, m;     cin >> n >> m;     long long int r[n], c[m], tr1 = 0, tr2 = 0;     for (long long int i = 0; i < n; i++) {       cin >> r[i];       tr1 ^= r[i];     }     for (long long int i = 0; i < m; i++) {       cin >> c[i];       tr2 ^= c[i];     }     if (tr1 != tr2) {       cout <<  NO ;       exit(0);     }     for (long long int i = 1; i < n - 1; i++) arr[i][0] = r[i];     for (long long int i = 1; i < m - 1; i++) arr[0][i] = c[i];     arr[0][m - 1] = r[0] ^ c[0] ^ c[m - 1] ^ tr1;     arr[n - 1][0] = r[0] ^ r[n - 1] ^ c[0] ^ tr1;     arr[n - 1][m - 1] = arr[0][m - 1] ^ c[m - 1];     cout <<  YES  << endl;     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < m; j++) cout << arr[i][j] <<    ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     string s;     cin >> s;     int c = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  || s[i] ==  u )         c++;       else if ((s[i] <  a  || s[i] >  z ) && (s[i] -  0 ) % 2 != 0) {         c++;       }     }     cout << c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2 * 1e5 + 10;   char str[maxn];   int ans[maxn];   int main() {     int n, a, b, k;     while (scanf( %d%d%d%d , &n, &a, &b, &k) != EOF) {       scanf( %s , str + 1);       int m = 0, cnt = 0;       for (int i = 1; i <= n; ++i) {         if (str[i] ==  0 ) {           cnt++;           if (cnt == b) {             ans[m++] = i;             cnt = 0;           }         }         if (str[i] ==  1 ) cnt = 0;       }       printf( %d n , m + 1 - a);       printf( %d , ans[0]);       for (int i = 1; i <= m - a; ++i) printf(  %d , ans[i]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   bool sortinrev(const pair<int, int>& a, const pair<int, int>& b) {     if (a.first == b.first) return b.second > a.second;     return a.first > b.first;   }   void run(vector<int> v) {     for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;     cout << endl;   }   int modInverse(long long int a, long long int m) {     long long int m0 = m;     long long int y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long int q = a / m;       long long int t = m;       m = a % m, a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   void numberOfNodes(int n, vector<long long int> adj[],                      vector<long long int>& count1, int s, int e) {     vector<long long int>::iterator u;     count1[s] = 1;     for (u = adj[s].begin(); u != adj[s].end(); u++) {       if (*u == e) continue;       numberOfNodes(n, adj, count1, *u, s);       count1[s] += count1[*u];     }   }   void solve() {     int n;     cin >> n;     long long int a[n], b[n];     int vis[n];     long long int ans = 0;     vector<vector<int>> v, total;     memset(vis, 0, sizeof(vis));     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 0; i < n; i++) {       int count = 0;       if (!vis[i]) {         for (int j = 0; j < n; j++) {           if (j != i) {             if (a[i] == a[j]) {               if (count == 0) ans += b[i];               vis[j] = 1;               vis[i] = 1;               ans += b[j];               count++;             }           }         }       }     }     for (int i = 0; i < n; i++) {       vector<int> vi(61);       long long int m = a[i];       int count = 0;       vector<int> ind;       while (m > 0) {         if (m % 2 == 1) {           ind.push_back(count);         }         m = m / 2;         count++;       }       for (int j = 0; j < ind.size(); j++) vi[ind[j]] = 1;       total.push_back(vi);       if (vis[i]) v.push_back(vi);     }     int count1, k;     for (int i = 0; i < n; i++) {       if (!vis[i]) {         for (int j = 0; j < v.size(); j++) {           for (k = 0; k < 60; k++) {             if (total[i][k] == 1) {               if (v[j][k] == 0) break;             }           }           if (k == 60) {             ans += b[i];             vis[i] = 1;             v.push_back(total[i]);             break;           }         }       }     }     cout << ans << endl;   }   int main() {     int t;     t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int a;     int count = 0;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       if (a == 1) count += 1;     }     if (n != 1) {       if (count == (n - 1))         cout <<  YES  << endl;       else         cout <<  NO  << endl;     } else {       if (count == 1)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int binExp(long long int a, long long int power,                        long long int m = 1000000007) {     long long int res = 1;     while (power) {       if (power & 1) res = (res * a) % m;       a = (a * a) % m;       power >>= 1;     }     return res;   }   int n, k;   int arr[100][100];   int cost[100][100];   void solve() {     int q;     cin >> n >> k;     int c = (k + 1) / 2;     for (int i = 1; i <= k; i++) {       for (int j = 1; j <= k; j++) {         arr[i][j] = arr[i][j - 1] + 1;         cost[i][j] = abs(i - c) + abs(j - c) + cost[i][j - 1];       }     }     while (n--) {       int ele;       cin >> ele;       int x = -1, l = -1, r = -1;       int mn = 1000000000;       for (int row = 1; row <= k; row++) {         for (int _l = 1, _r = ele; _r <= k; _l++, _r++) {           if (arr[row][_r] - arr[row][_l - 1] == ele) {             if (mn > cost[row][_r] - cost[row][_l - 1]) {               mn = cost[row][_r] - cost[row][_l - 1];               l = _l;               r = _r;               x = row;             }           }         }       }       if (mn == 1000000000) {         cout << -1 <<   n ;       } else {         cout << x <<     << l <<     << r <<   n ;         for (int i = l; i <= r; i++) arr[x][i] -= i - l + 1;         for (int i = r + 1; i <= k; i++) arr[x][i] -= ele;       }     }   }   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ucln(int k, int l) {     int t;     while (l > 0) {       t = l;       l = k % l;       k = t;     }     return (k);   }   int main() {     int x, y, m, n, a, b;     cin >> n >> m >> x >> y >> a >> b;     int u = ucln(a, b);     a /= u;     b /= u;     int na, nb;     if ((n / a) < (m / b)) {       na = a * (n / a);       nb = b * (n / a);     } else {       na = a * (m / b);       nb = b * (m / b);     }     int x1, x2, y1, y2;     x2 = x + na / 2;     x1 = x2 - na;     if (x1 < 0) {       x2 -= x1;       x1 = 0;     }     if (x2 > n) {       x1 -= (x2 - n);       x2 = n;     }     y2 = y + nb / 2;     y1 = y2 - nb;     if (y1 < 0) {       y2 -= y1;       y1 = 0;     }     if (y2 > m) {       y1 -= (y2 - m);       y2 = m;     }     cout << x1 <<     << y1 <<     << x2 <<     << y2;     return 0;   }
#include <bits/stdc++.h>   const int MOD = 1e9 + 7;   inline int addmod(int a, int b) { return (a + b) % MOD; }   const int MAXN = 105;   const int MAXM = 10005;   int cnt[MAXN];   int n, a[MAXN];   int f[MAXN][MAXM];   int com[MAXN][MAXN];   int main() {     for (int i = 0; i < MAXN; i++) {       com[i][0] = 1;       for (int j = 1; j <= i; j++) {         com[i][j] = addmod(com[i - 1][j], com[i - 1][j - 1]);       }     }     scanf( %d , &n);     f[0][0] = 1;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       cnt[a[i]]++;       for (int x = 100; x >= 1; x--) {         for (int y = a[i]; y <= 10000; y++)           f[x][y] = addmod(f[x][y], f[x - 1][y - a[i]]);       }     }     int tot = 0;     for (int i = 0; i < MAXN; i++)       if (cnt[i] > 0) tot++;     int ans = 0;     for (int i = 0; i <= 100; i++) {       int sum = 0;       for (int j = 1; j <= cnt[i]; j++) {         sum += i;         if (f[j][sum] == com[cnt[i]][j]) {           ans = std::max(ans, j);           if (j == cnt[i] && tot == 2) ans = n;         }       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       string temp = s;       sort(s.begin(), s.end());       int count = 0;       for (int i = 0; i < s.size(); i++)         if (s[i] != temp[i]) count++;       cout << count <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[5000];   int b[5000];   int main() {     int n, m;     cin >> n >> m;     int x;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     sort(a, a + n);     sort(b, b + m);     int cura = 0;     for (int i = 0; i < m && cura < n; i++)       if (b[i] >= a[cura]) cura++;     cout << n - cura << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[92];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> arr[i];     if (n == 1) {       if (arr[0] == 15)         cout <<  DOWN ;       else if (arr[0] == 0)         cout <<  UP ;       else         cout << -1;     } else {       if (arr[n - 1] > arr[n - 2]) {         if (arr[n - 1] == 15)           cout <<  DOWN ;         else           cout <<  UP ;       } else if (arr[n - 1] < arr[n - 2]) {         if (arr[n - 1] == 0)           cout <<  UP ;         else           cout <<  DOWN ;       } else         cout << -1;     }   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 3000;   int r, c, n;   int k;   struct Node {     int x, y;     friend bool operator<(Node a, Node b) {       if (a.y == b.y) {         return a.x < b.x;       }       return a.y < b.y;     }   } a[Maxn + 5], b[Maxn + 5];   int len;   vector<int> g[Maxn + 5];   int lst[Maxn + 5], nxt[Maxn + 5];   long long tmp;   int cnt[Maxn + 5];   void calc(int x, int k) {     tmp -= b[x].y * cnt[x];     tmp += b[lst[x]].y * cnt[x];     if (lst[x] && k > 1) {       calc(lst[x], k - 1);     }     if (lst[x]) {       cnt[lst[x]] += cnt[x];     }     cnt[x] = 0;   }   int main() {     scanf( %d%d%d%d , &r, &c, &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &a[i].x, &a[i].y);     }     sort(a + 1, a + 1 + n);     long long ans = 0;     for (int left = 1, right; left <= r; left++) {       right = r;       for (int i = 1; i <= r; i++) {         g[i].clear();       }       len = 0;       for (int i = 1; i <= n; i++) {         if (a[i].x >= left) {           b[++len] = a[i];           lst[len] = len - 1;           nxt[len] = len + 1;           cnt[len] = 0;           g[b[len].x].push_back(len);         }       }       tmp = 0;       for (int i = 1, j = 0; i <= c; i++) {         while (j + 1 <= len && b[j + 1].y <= i) {           j++;         }         if (j - k + 1 > 0) {           cnt[j - k + 1]++;           tmp += b[j - k + 1].y;         }       }       ans += tmp;       while (right > left) {         for (int i = 0; i < (int)g[right].size(); i++) {           int u = g[right][i];           calc(u, k);           nxt[lst[u]] = nxt[u];           lst[nxt[u]] = lst[u];         }         ans += tmp;         right--;       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, m;   long long int arr[200005];   map<long long int, long long int> x;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> arr[i];     long long int l = 0, sum = 0, rem = 0, ksum = 0;     vector<long long int> ans;     while (l < n) {       int cnt = 0;       rem = 0;       sum = ksum;       if (sum + arr[l] > m) {         auto it = x.rbegin();         while (sum + arr[l] > m && it != x.rend()) {           pair<long long int, long long int> curr = *(it);           if ((long long int)ceil((sum + arr[l] - m) * 1.0 / curr.first) >               curr.second) {             rem += curr.second;             sum -= (curr.first * curr.second);             it++;           } else {             rem += (long long int)ceil((sum + arr[l] - m) * 1.0 / curr.first);             sum -= (curr.first) *                    ((long long int)ceil((sum + arr[l] - m) * 1.0 / curr.first));           }         }       }       ksum += arr[l];       if (x.find(arr[l]) != x.end()) {         pair<long long int, long long int> curr = *(x.find(arr[l]));         x.erase(arr[l]);         x.insert(make_pair(curr.first, curr.second + 1));       } else         x.insert(make_pair(arr[l], 1));       ans.push_back(rem);       l++;     }     for (auto it : ans) cout << it <<    ;     cout << endl;     return 0;   }