malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct EDGE {     EDGE(int _v, int _cap, int _edgeidx) : v(_v), cap(_cap), edgeidx(_edgeidx) {}     int v;     int cap;     int edgeidx;   };   int DEBUG = 0;   const int MAXN = 200001;   vector<EDGE> edge[MAXN];   int in[MAXN], total[MAXN], dir[MAXN];   int mark[MAXN];   int main(int argc, char **argv) {     DEBUG = (argc >= 2) ? atoi(argv[1]) : 0;     int n, m;     cin >> n >> m;     memset(total, 0, sizeof(total));     memset(in, 0, sizeof(in));     memset(mark, 0, sizeof(mark));     for (int i = 1; i <= m; i++) {       int a, b, c;       cin >> a >> b >> c;       edge[a].push_back(EDGE(b, c, i));       edge[b].push_back(EDGE(a, c, -i));       total[a] += c;       total[b] += c;     }     if (DEBUG) {       for (int i = 1; i <= m; i++) {         printf( total[%d]= %d  , i, total[i]);       }       printf(  n );     }     queue<int> que;     mark[1] = 1;     que.push(1);     while (!que.empty()) {       int u = que.front();       que.pop();       mark[u] = 1;       if (DEBUG) {         printf(  nu= %d n , u);       }       for (int i = 0; i < edge[u].size(); i++) {         int edgeidx = edge[u][i].edgeidx;         int v = edge[u][i].v;         int cap = edge[u][i].cap;         if (DEBUG) {           printf( u= %d, v= %d, edgeidx= %d, cap= %d, mark[%d]= %d n , u, v,                  edgeidx, cap, v, mark[v]);         }         if (mark[v] == 0) {           in[v] += cap;           if (total[v] == 2 * in[v] && v != n) {             if (DEBUG) {               printf( que.push(%d) n , v);             }             que.push(v);           }           dir[abs(edgeidx)] = ((edgeidx < 0) ? 1 : 0);         }       }       if (DEBUG) {         printf( que.size()= %d n , que.size());       }     }     for (int i = 1; i <= m; i++) {       cout << dir[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1.0e-8;   const int maxn = 1e6 + 10;   const int maxm = 300;   const int turn[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   long long mod = 1e9 + 7;   vector<int> tree[10005];   int ans[10005];   int anser = 0;   void dfs(int x, int pre, int c) {     int cur = c;     if (c != ans[x]) {       anser++, cur = ans[x];     }     int len = tree[x].size();     for (int i = 0; i < len; i++) {       int to = tree[x][i];       if (to == pre) {         continue;       }       dfs(to, x, cur);     }   }   int main() {     int n;     int now;     cin >> n;     for (int i = 2; i <= n; i++) {       cin >> now;       tree[now].push_back(i);       tree[i].push_back(now);     }     for (int i = 1; i <= n; i++) {       cin >> ans[i];     }     dfs(1, 0, 0);     cout << anser << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long int hell = 1000000007;   void solve() {     long long int n, m;     cin >> n >> m;     vector<long long int> used(3 * n + 5, 0);     vector<long long int> mx;     long long int ctr = 1;     for (long long int i = 1; i <= m; i++) {       long long int u, v;       cin >> u >> v;       if (!used[u] and !used[v]) {         mx.push_back(i);         used[u] = used[v] = 1;       }     }     if ((long long int)((mx).size()) >= n) {       cout <<  Matching n ;       for (long long int i = 0; i < n; i++) cout << mx[i] <<    ;       cout <<   n ;     } else {       cout <<  IndSet n ;       long long int ctr = n;       for (long long int i = 1; i <= 3 * n; i++) {         if (!used[i]) {           cout << i <<    ;           ctr--;         }         if (!ctr) break;       }       cout <<   n ;     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t;     cin >> t;     for (long long int i = 0; i < t; i++) solve();     cerr <<  Time elapsed :   << clock() * 1000.0 / CLOCKS_PER_SEC <<  ms           <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<long long> S;   vector<int> N, L, R;   vector<bool> E;   pair<long long, pair<int, int>> merge(int l, int r, int mid,                                         pair<long long, pair<int, int>> L,                                         pair<long long, pair<int, int>> R) {     int ll = L.second.first, lr = L.second.second;     int rl = R.second.first, rr = R.second.second;     long long ls = L.first, rs = R.first;     long long sum = ls + rs;     int lw = ll, rw = rr;     int lLength = mid - l + 1, rLength = r - (mid + 1) + 1;     if (lr && rl && N[mid + 1] >= N[mid]) {       if (ll == lLength) lw += rl;       if (rr == rLength) rw += lr;       if (ll != lLength && rl != rLength)         sum += (long long)(lr + rl) * (lr + rl - 1) / 2;     } else {       if (ll != lLength) sum += (long long)(lr) * (lr - 1) / 2;       if (rr != rLength) sum += (long long)(rl) * (rl - 1) / 2;     }     return {sum, {lw, rw}};   }   pair<long long, pair<int, int>> getVal(int lq, int rq, int l = 0, int r = n - 1,                                          int index = 0) {     if (l == r) return {0, {1, 1}};     if (lq == l && rq == r && E[index]) return {S[index], {L[index], R[index]}};     int mid = (l + r) >> 1;     if (rq <= mid) {       return getVal(lq, rq, l, mid, 2 * index + 1);     } else if (lq > mid) {       return getVal(lq, rq, mid + 1, r, 2 * index + 2);     }     auto lv = getVal(lq, mid, l, mid, 2 * index + 1);     auto rv = getVal(mid + 1, rq, mid + 1, r, 2 * index + 2);     auto ret = merge(lq, rq, mid, lv, rv);     if (l == lq && r == rq) {       E[index] = true;       S[index] = ret.first, L[index] = ret.second.first,       R[index] = ret.second.second;     }     return ret;   }   void update(int lq, int rq, int l = 0, int r = n - 1, int index = 0) {     if (l == r) return;     E[index] = false;     int mid = (l + r) >> 1;     if (rq <= mid) {       return update(lq, rq, l, mid, 2 * index + 1);     } else if (lq > mid) {       return update(lq, rq, mid + 1, r, 2 * index + 2);     }     update(lq, mid, l, mid, 2 * index + 1);     update(mid + 1, rq, mid + 1, r, 2 * index + 2);     return;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int q;     cin >> n >> q;     N = vector<int>(n);     S = vector<long long>(4 * n + 1);     L = R = vector<int>(4 * n + 1);     E = vector<bool>(4 * n + 1, false);     for (auto &it : N) cin >> it;     int cmd, x, y;     for (int qq = 0; qq < q; qq++) {       cin >> cmd >> x >> y;       if (cmd == 1) {         N[x - 1] = y;         update(x - 1, x - 1);       } else {         x--, y--;         auto res = getVal(x, y);         auto sum = res.first;         int l = res.second.first, r = res.second.second;         if (l == (y - x + 1))           sum += (long long)(l) * (l - 1) / 2;         else           sum += ((long long)(l) * (l - 1) + (long long)(r) * (r - 1)) / 2;         sum += (y - x + 1);         cout << sum <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 505;   int n, in[N], out[N], w[N], s[N], v[N];   vector<int> st[N << 1];   int f1[N][N << 1], f2[N][N << 1];   int dfs(int x, int S) {     if (S < 0) return 0;     if (~f1[x][S]) return f1[x][S];     f2[x][out[x] + 1] = 0;     for (int i = out[x]; i >= in[x]; i--) {       f2[x][i] = f2[x][i + 1];       for (int j = 0; j < st[i].size(); j++) {         int p = st[i][j];         if (out[p] > out[x] || p == x) continue;         f2[x][i] = max(f2[x][i], dfs(p, min(S - w[p], s[p])) + f2[x][out[p]]);       }     }     return f1[x][S] = f2[x][in[x]] + v[x];   }   int main() {     int S;     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]);       st[in[i]].push_back(i);     }     memset(f1, -1, sizeof f1);     in[0] = 0;     out[0] = 2 * n + 1;     printf( %d n , dfs(0, S));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fr(int &a, bool f = 0, char ch = getchar()) {     for (a = 0; ch <  0  || ch >  9 ; ch = getchar()) ch ==  -  ? f = 1 : 0;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) a = a * 10 + ch -  0 ;     a = f ? -a : a;   }   int fr() {     int a;     return fr(a), a;   }   const int N = 12;   int arr[(1 << N) + 10], a[(1 << N) + 10], ans[(1 << N) + 10], p[(1 << N) + 10];   int tmp[(1 << N) + 10];   bool visval[(1 << N) + 10], vispos[(1 << N) + 10];   struct OI {     int RP, score;   } CSPS2021, NOIP2021;   int main() {     CSPS2021.RP++, CSPS2021.score++, NOIP2021.RP++, NOIP2021.score++, 392699;     srand(time(0));     int n = fr(), xsum = 0, tot = 1 << n;     for (int i = 0; i < (1 << n); i++) fr(a[i]), xsum ^= a[i], arr[i] = i;     if (xsum) return puts( Fou ), 0;     puts( Shi );     for (int i = 0; i < (1 << n); i++) {       int pos = rand() % tot, arrpos = arr[pos];       if (pos != tot - 1) arr[pos] = arr[tot - 1];       tot--, tmp[0] = 0;       bool flag = 0;       for (int j = 0; j < (1 << n); j++)         if (vispos[j] == 0 && visval[arrpos ^ a[j]] == 0) {           flag = visval[arrpos ^ a[j]] = vispos[j] = 1, ans[j] = arrpos,           p[arrpos ^ a[j]] = j;           break;         } else if (vispos[j] == 0)           tmp[++tmp[0]] = j;       if (flag == 0) {         int j = tmp[rand() % tmp[0] + 1];         vispos[p[arrpos ^ a[j]]] = 0;         arr[tot++] = ans[p[arrpos ^ a[j]]], ans[j] = arrpos;         vispos[j] = 1;         visval[ans[j] ^ a[j]] = 1;         p[ans[j] ^ a[j]] = j;         i--;       }     }     for (int i = 0; i < (1 << n); i++) printf( %d  , ans[i] ^ a[i]);     puts(  );     for (int i = 0; i < (1 << n); i++) printf( %d  , ans[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans[2020], cnt = 0, k;   int main() {     cin >> k;     k++;     ans[++cnt] = -1;     while (k >= 1e6 - 1) {       k -= 1e6 - 1;       ans[++cnt] = 1e6 - 1 + 1;     }     ans[++cnt] = k + 1;     cout << cnt << endl;     for (int i = 1; i <= cnt; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long f = 0, j, q = 1, i, n;     while (q--) {       long long y, k = 1, x, M, s;       cin >> n >> M >> s >> f;       unordered_map<int, pair<int, int> > m;       for (i = 0; i < M; i++) {         long long X, Y, Z;         cin >> X >> Y >> Z;         m.insert(make_pair(X, make_pair(Y, Z)));       }       if (s < f) {         while (s != f) {           if (m.count(k)) {             if ((s >= m[k].first && s <= m[k].second) ||                 (s + 1 >= m[k].first && s + 1 <= m[k].second))               cout <<  X ;             else {               cout <<  R ;               s++;             }           } else {             cout <<  R ;             s++;           }           k++;         }       } else {         while (s != f) {           if (m.count(k)) {             if ((s >= m[k].first && s <= m[k].second) ||                 (s - 1 >= m[k].first && s - 1 <= m[k].second))               cout <<  X ;             else {               cout <<  L ;               s--;             }           } else {             cout <<  L ;             s--;           }           k++;         }       }       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string ch1, ch2, ch3;     getline(cin, ch1);     getline(cin, ch2);     for (int s = 0; s < ch1.size(); s++) {       if (ch1[s] != ch2[s]) {         ch3 +=  1 ;       } else {         ch3 +=  0 ;       }     }     cout << ch3 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long n, k;     cin >> n >> k;     long long l = 0;     long long r = n;     while (l != r) {       long long mid = (l + r) / 2;       if (mid * (mid + 1) / 2 - (n - mid) < k)         l = mid + 1;       else         r = mid;     }     cout << n - l;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Solve {     bool mark[(int)(3e5 + 10)];     vector<pair<int, int>> ed[(int)(3e5 + 10)];     vector<int> mtch;     int n, m, T;     void go() {       T = 0;       input();       find_mx_match();       if (T >= 2 * n)         prnt_match();       else         prnt_ind();     }     void input() {       cin >> n >> m;       for (int i = 0; i < m; i++) {         int u, v;         cin >> u >> v;         u--, v--;         ed[u].push_back({v, i + 1});         ed[v].push_back({u, i + 1});       }     }     void find_mx_match() {       for (int i = 0; i < 3 * n; i++) {         if (mark[i]) continue;         for (auto x : ed[i]) {           if (mark[x.first]) continue;           mark[x.first] = mark[i] = true;           mtch.push_back(x.second);           T += 2;           break;         }       }     }     void prnt_match() {       cout <<  Matching n ;       int I = 0;       for (auto x : mtch) {         if (I == n) break;         cout << x <<    ;         I++;       }       cout << endl;     }     void prnt_ind() {       cout <<  IndSet n ;       for (int I = 0, J = 0; I < 3 * n && J < n; I++) {         if (!mark[I]) {           cout << I + 1 <<    ;           J++;         }       }       cout << endl;     }     void clear() {       T = 0;       for (int i = 0; i < 3 * n; i++) mark[i] = false;       for (int i = 0; i < 3 * n; i++) ed[i].clear();       n = -1, m = -1;       mtch.clear();     }   } S;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     int T;     cin >> T;     while (T--) {       S.go();       S.clear();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       long long n, x, m, i, flag = 0, a, b, l, r, sum = 2, ones = 0, zero = 0,                             output = 0, j;       vector<pair<long long, long long> > v;       cin >> n >> m;       long long arr[n + 1][m + 1];       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           cin >> arr[i][j];         }       }       a = 0;       sum = 2;       flag = 0;       while (flag == 0) {         for (i = 1; i <= n; i++) {           for (j = 1; j <= m; j++) {             if ((i + j == sum) || (i + j == n + m - a))               v.push_back(make_pair(i, j));           }         }         while (v.size() > 0) {           i = v[v.size() - 1].first;           j = v[v.size() - 1].second;           if (arr[i][j] == 0)             zero++;           else             ones++;           v.pop_back();         }         output = output + min(zero, ones);         zero = 0;         ones = 0;         a++;         sum++;         if (sum == n + m - a)           break;         else if (sum > (n + m - a))           break;       }       cout << output <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int c, m, x;       cin >> c >> m >> x;       long long int y = c + m + x;       y = y / 3;       long long int ans = 0;       if (c >= 1 && m >= 1) {         long long int v = min(c, m);         ans = min(v, y);       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   struct Edge {     int t, next;     Edge() {}     Edge(int a, int b) : t(a), next(b) {}   };   Edge e[200005];   int head[100005];   vector<int> g[100005];   queue<int> bel[100005];   int d[100005], scc_cnt;   namespace Graph {   int dfn[100005], low[100005], dfs_cnt;   int st[100005], top;   bool in[100005];   int id[100005];   void dfs(int x) {     dfn[x] = low[x] = ++dfs_cnt;     st[++top] = x;     in[x] = 1;     for (int i = head[x]; i; i = e[i].next) {       int u = e[i].t;       if (!dfn[u]) {         dfs(u);         low[x] = min(low[x], low[u]);       } else if (in[u])         low[x] = min(low[x], dfn[u]);     }     if (low[x] >= dfn[x]) {       scc_cnt++;       int t;       do {         t = st[top--];         in[t] = 0;         id[t] = scc_cnt;         bel[scc_cnt].push(t);       } while (t != x);     }   }   void build(int n) {     for (int i = 1; i <= n; i++)       if (!dfn[i]) dfs(i);     for (int i = 1; i <= n; i++)       for (int j = head[i]; j; j = e[j].next)         if (id[i] != id[e[j].t]) {           int u = id[i], v = id[e[j].t];           g[u].push_back(v);           d[v]++;         }   }   }  // namespace Graph   bool ask(int x, int y) {     printf( ? %d %d n , x, y);     fflush(stdout);     scanf( %d , &x);     return x;   }   queue<int> q;   void erase(int x) {     for (int i = 0; i < g[x].size(); i++) {       int u = g[x][i];       d[u]--;       if (!d[u]) q.push(u);     }   }   int solve(int n) {     int ans = 0;     for (int i = 1; i <= scc_cnt; i++)       if (!d[i]) {         if (!ans)           ans = bel[i].front();         else           q.push(i);       }     while (!q.empty()) {       int t = q.front(), x = bel[t].front();       if (ask(ans, x)) {         bel[t].pop();         if (!bel[t].size()) {           erase(t);           q.pop();         }       } else {         int p = Graph::id[ans];         bel[p].pop();         if (!bel[p].size())           erase(p);         else           q.push(p);         ans = x;         q.pop();       }     }     return ans;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       int x, y;       scanf( %d%d , &x, &y);       e[i] = Edge(y, head[x]);       head[x] = i;     }     Graph::build(n);     printf( ! %d n , solve(n));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int d[66000], s[66000];   int que[66000];   bool f[66000];   int n, m;   vector<pair<int, int> > res;   int biton(int x, int k) { return (x | (1 << k)); }   int Minus(int x, int y) {     int z = 0;     for (int i = 0; i < 17; i++) {       int u = ((x >> i) & 1);       int v = ((y >> i) & 1);       if (u != v) z = biton(z, i);     }     return z;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; i++) cin >> d[i] >> s[i];     for (int i = 0; i < n; i++)       if (d[i] == 1) {         f[i] = true;         m++;         que[m] = i;       }     while (m > 0) {       int u = que[m];       if (d[u] == 0) {         m--;         continue;       }       int v = s[u];       res.push_back(make_pair(u, v));       s[v] = Minus(s[v], u);       d[v]--;       m--;       if (d[v] == 1 && f[v] == false) {         f[v] = true;         m++;         que[m] = v;       }     }     cout << res.size() <<   n ;     for (int i = 0; i < res.size(); i++)       cout << res[i].first <<     << res[i].second <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[200005];   int main() {     int t;     cin >> t;     while (t--) {       memset(a, 0, sizeof(a));       int n;       cin >> n;       for (int i = 0; i < n; i++) {         cin >> a[i];       }       sort(a, a + n);       if (a[0] != a[n - 1]) {         printf( 1 n );       } else {         printf( %d n , n);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void _fill_int(int* p, int val, int rep) {     int i;     for (i = 0; i < rep; i++) p[i] = val;   }   signed long long GETi() {     signed long long i;     scanf( %lld , &i);     return i;   }   int N, M;   int A[10000], B[10000];   int T[4][10000];   void solve() {     int f, i, j, k, l, x, y;     cin >> N >> M;     for (i = 0; i < N; i++) A[i] = 1 << 29;     for (i = 0; i < M; i++) {       cin >> T[0][i] >> T[1][i] >> T[2][i] >> T[3][i];       T[1][i]--;       T[2][i]--;     }     for (i = M - 1; i >= 0; i--) {       if (T[0][i] == 1) {         for (j = T[1][i]; j <= T[2][i]; j++) A[j] -= T[3][i];       } else {         for (j = T[1][i]; j <= T[2][i]; j++) A[j] = min(A[j], T[3][i]);       }     }     int ng = 0;     memmove(B, A, sizeof(A));     for (i = 0; i < M; i++) {       int y = -1 << 29;       if (T[0][i] == 1)         for (j = T[1][i]; j <= T[2][i]; j++) B[j] += T[3][i];       else {         for (j = T[1][i]; j <= T[2][i]; j++) y = max(y, B[j]);         if (y != T[3][i]) ng = 1;       }     }     if (ng)       (void)printf( NO n );     else {       (void)printf( YES n );       for (i = 0; i < N; i++) (void)printf( %d  , A[i]);       (void)printf(  n );     }   }   int main(int argc, char** argv) {     if (argc > 1) freopen(argv[1],  r , stdin);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, t;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> t;     while (t--) {       cin >> n;       if (n == 1) {         cout <<  -1  << endl;         continue;       }       string ans =  2 ;       for (int i = 1; i < n; i++) ans +=  3 ;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int MinDist(int n, int k, const string& s) {     int first_cow_pos = 0;     while (first_cow_pos < n && s[first_cow_pos] ==  1 ) {       ++first_cow_pos;     }     int last_cow_pos = first_cow_pos;     int rooms = 1;     while (rooms < k + 1) {       ++last_cow_pos;       if (s[last_cow_pos] ==  0 ) {         ++rooms;       }     }     int farmer_pos = first_cow_pos;     int delta = last_cow_pos - first_cow_pos;     for (int i = first_cow_pos + 1; i <= last_cow_pos; ++i) {       if (s[i] ==  0  && i - first_cow_pos < delta && last_cow_pos - i < delta) {         delta = max(i - first_cow_pos, last_cow_pos - i);         farmer_pos = i;       }     }     --rooms;     for (++first_cow_pos; first_cow_pos < n; ++first_cow_pos) {       if (s[first_cow_pos] ==  1 ) {         continue;       }       while (rooms < k + 1 && last_cow_pos < n) {         ++last_cow_pos;         if (last_cow_pos == n) {           break;         }         if (s[last_cow_pos] ==  0 ) {           ++rooms;         }       }       if (last_cow_pos == n) {         break;       }       int npos = max(farmer_pos, first_cow_pos);       int cur_delta = max(farmer_pos - first_cow_pos, last_cow_pos - farmer_pos);       while (npos < last_cow_pos) {         ++npos;         if (s[npos] ==  1 ) {           continue;         }         if (npos - first_cow_pos < cur_delta && last_cow_pos - npos < cur_delta) {           cur_delta = max(npos - first_cow_pos, last_cow_pos - npos);           farmer_pos = npos;         } else if (npos - first_cow_pos >= cur_delta) {           break;         }       }       delta = min(delta, cur_delta);       --rooms;     }     return delta;   }   int MinDistSlow(int n, int k, const string& s) {     int result = n;     for (int fcp = 0; fcp < n; ++fcp) {       if (s[fcp] ==  1 ) {         continue;       }       int lcp = fcp;       int rooms = 1;       while (rooms < k + 1 && lcp < n) {         ++lcp;         if (lcp == n) {           break;         }         if (s[lcp] ==  0 ) {           ++rooms;         }       }       if (lcp == n) {         break;       }       for (int fp = fcp; fp <= lcp; ++fp) {         if (s[fp] ==  1 ) {           continue;         }         int delta = max(fp - fcp, lcp - fp);         if (delta < result) {           result = delta;         }       }     }     return result;   }   int main() {     int n, k;     cin >> n >> k;     string s;     char buffer[1000000];     scanf( %s , buffer);     s = buffer;     int delta = MinDist(n, k, s);     cout << delta << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const long long INF = 1e18;   long long n, sum, ans;   long long a[200010];   struct BIT {     long long tree[600010];     BIT() { memset(tree, 0, sizeof(tree)); }     void update(long long i, long long x) {       while (i <= 600000) {         tree[i] += x;         i += i & -i;       }     }     long long sum(long long i) {       long long ret = 0;       while (i) {         ret += tree[i];         i -= i & -i;       }       return ret;     }   } t1, t2;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     ;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       ans += (i - 1) * a[i] - t1.sum(a[i]);       long long x = sum;       for (long long j = a[i]; j <= 300000; j += a[i]) {         t1.update(j, a[i]);         x -= (j / a[i]) * a[i] * (t2.sum(j + a[i] - 1) - t2.sum(j - 1));       }       ans += x;       sum += a[i];       t2.update(a[i], 1);       cout << ans <<    ;     }   }