malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int sy, a, b, n, l[200010], r[200010], sum[200010], m, x, y;   double xl, xr, ans;   int getmid(double xi) {     int L = 1, R = n + 1, ret, mid;     while (L < R) {       mid = (L + R) >> 1;       if (l[mid] <= xi)         ret = mid, L = mid + 1;       else         R = mid;     }     return ret;   }   double getlenth(double xi) {     if (xi <= l[1]) return 0;     int pos = getmid(xi);     return min(xi, (double)r[pos]) - l[pos] + sum[pos - 1];   }   int main() {     scanf( %d%d%d , &sy, &a, &b);     scanf( %d , &n);     sum[0] = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &l[i], &r[i]);       sum[i] = sum[i - 1] + r[i] - l[i];     }     scanf( %d , &m);     while (m--) {       scanf( %d%d , &x, &y);       xl = -1.0 * (x - a) / (y - sy) * y + x;       xr = -1.0 * (x - b) / (y - sy) * y + x;       ans = (getlenth(xr) - getlenth(xl)) / (xr - xl) * (b - a);       printf( %.10lf n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   bool flag[maxn];   int phi[maxn];   vector<int> prime;   vector<int> fin[6][maxn];   int a[10][10], num;   void get_prime_phi() {     phi[1] = 1;     for (int i = 2; i < 1e5; i++) {       if (!flag[i]) {         prime.push_back(i);         phi[i] = i - 1;       }       int top = prime.size();       for (int j = 0; j < top && i * prime[j] < 1e5; j++) {         flag[i * prime[j]] = 1;         if (i % prime[j])           phi[i * prime[j]] = phi[i] * (prime[j] - 1);         else {           phi[i * prime[j]] = phi[i] * prime[j];           break;         }       }     }   }   void init() {     int si = prime.size();     for (int i = 0; i < si; i++) {       int x = prime[i];       for (int j = 1; j <= 5; j++) {         fin[j][x / 10].push_back(prime[i]);         x /= 10;       }     }   }   int dfs(int x) {     int ans = 0;     int tem = 0, tt = num - x;     for (int i = 0; i < x; i++) tem = tem * 10 + a[x][i];     int si = fin[tt][tem].size();     if (x == num - 1) return si;     for (int i = 0; i < si; i++) {       int xx = fin[tt][tem][i];       for (int j = num - 1; j >= x; j--) {         a[x][j] = xx % 10;         xx /= 10;       }       for (int j = x + 1; j < num; j++) a[j][x] = a[x][j];       ans += dfs(x + 1);     }     return ans;   }   int main() {     get_prime_phi();     init();     int cas, n;     cin >> cas;     while (cas--) {       memset(a, 0, sizeof(a));       scanf( %d , &n);       int x = n;       num = 0;       while (x) {         num++;         x /= 10;       }       x = n;       for (int i = 0; i < num; i++) {         a[0][num - 1 - i] = a[num - 1 - i][0] = x % 10;         x /= 10;       }       printf( %d n , dfs(1));     }   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   constexpr int N = 1e5 + 5;   int n;   int in[N];   void solve(int x, int y) {     int res = 0;     while (x <= y) {       res++;       for (int i = 1; i <= n; i++) {         if (in[i] == x) x++;       }     }     cout << res <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     for (int i = 1; i <= n; i++) cin >> in[i];     int q;     cin >> q;     while (q--) {       int p, x, y;       cin >> p >> x >> y;       if (p == 1) {         solve(x, y);       } else {         swap(in[x], in[y]);       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2 * 1e5 + 100;   long long t, n;   struct node {     long long m, p;   } sh[N];   bool cmp(node a, node b) { return a.m > b.m; }   signed main() {     scanf( %lld , &t);     while (t--) {       scanf( %lld , &n);       for (long long i = 1; i <= n; i++) scanf( %lld%lld , &sh[i].m, &sh[i].p);       sort(sh + 1, sh + 1 + n, cmp);       long long ans = 0;       priority_queue<long long, vector<long long>, greater<long long> > q;       for (long long i = 1; i <= n;) {         long long j = i;         while (j <= n && sh[j].m == sh[i].m) {           q.push(sh[j].p);           j++;         }         while (n - (long long)q.size() < sh[i].m) {           ans += q.top();           q.pop();         }         i = j;       }       printf( %lld n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const int inf = INT_MAX;   const int N = 100004;   const int modn = 1000000007;   complex<long long> v[N];   int p[N];   long long x(complex<long long> a) { return a.real(); }   long long y(complex<long long> a) { return a.imag(); }   long long cross(complex<long long> a, complex<long long> b) {     return y(conj(a) * b);   }   int n;   bool comp(int i, int j) {     if (x(v[i]) == x(v[j])) return y(v[i]) < y(v[j]);     return x(v[i]) < x(v[j]);   }   int sig(long long x) { return (x > 0) - (x < 0); }   int ok(complex<long long> a, complex<long long> b, complex<long long> c) {     return sig(cross(b - a, c - a));   }   int main() {     scanf( %d , &n);     long long a, b;     for (int i = 0; i < n; i++) {       p[i] = i;       cin >> a >> b;       v[i] = complex<long long>(a, b);     }     int cont = 0;     sort(p, p + n, comp);     for (int i = 0; i < n - 2; i++) {       if (ok(v[p[i]], v[p[i + 1]], v[p[i + 2]])) {         printf( %d %d %d n , p[i] + 1, p[i + 1] + 1, p[i + 2] + 1);         return 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2100;   int n, al;   double P;   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> P;     al = n * (n - 1) * (n - 2) / 6;     int ans = n;     for (int i = 0; i <= n; i++) {       double temp = 0;       if (i >= 1 && n - i - 1 >= 0)         temp += (double)(i * (n - i) * (n - i - 1) / 2) / al / 2;       if (i >= 2) temp += (double)(i * (i - 1) * (n - i) / 2) / al;       if (i >= 3) temp += (double)(i * (i - 1) * (i - 2) / 6) / al;       if (temp >= P) {         ans = i;         break;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, normg, bekg, uykg, beksur, uyksur;     int i, j, x, y, t = 0, A[1000][2], fark;     cin >> n >> normg >> bekg >> uykg >> beksur >> uyksur;     for (i = 1; i <= n; i++) cin >> A[i][0] >> A[i][1];     for (i = 1; i <= n; i++) {       t += abs(A[i][1] - A[i][0]) * normg;       if (i != n) {         fark = abs(A[i + 1][0] - A[i][1]);         if (fark >= beksur) {           t += beksur * normg;           fark -= beksur;         } else           t += fark * normg, fark = 0;         if (fark >= uyksur) {           t += uyksur * bekg;           fark -= uyksur;         } else           t += fark * bekg, fark = 0;         if (fark > 0) t += fark * uykg;       }     }     cout << t;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int ans[n];     int a, b, c;     cout <<  ? 1 2  << endl;     cin >> a;     cout <<  ? 1 3  << endl;     cin >> b;     cout <<  ? 2 3  << endl;     cin >> c;     ans[0] = ((a + b + c) / 2) - c;     ans[1] = ((a + b + c) / 2) - b;     ans[2] = ((a + b + c) / 2) - a;     for (int i = 4; i < n + 1; i++) {       cout <<  ? 1   << i << endl;       int x;       cin >> x;       ans[i - 1] = x - ans[0];     }     cout <<  !  ;     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, w = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) w = -1;       c = getchar();     }     while (c <=  9  && c >=  0 ) {       x = (x << 1) + (x << 3) + c -  0 ;       c = getchar();     }     return w == 1 ? x : -x;   }   int n, ans[200005];   struct node {     int x, y, id;   } a[200005];   int main() {     n = read();     for (int i = 1; i <= n; i++) a[i].x = read(), a[i].y = read(), a[i].id = i;     while (1) {       long long x = 0, y = 0;       for (int i = 0; i <= n; i++) {         if ((x + a[i].x) * (x + a[i].x) + (y + a[i].y) * (y + a[i].y) <=             (x - a[i].x) * (x - a[i].x) + (y - a[i].y) * (y - a[i].y)) {           ans[a[i].id] = 1;           x += a[i].x;           y += a[i].y;         } else           ans[a[i].id] = -1, x -= a[i].x, y -= a[i].y;       }       if (x * x + y * y <= 1.5e6 * 1.5e6) break;       random_shuffle(a + 1, a + n + 1);     }     for (int i = 1; i <= n; i++) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long GI(long long &a) { return scanf( %I64d , &a); }   long long n, i, j, k, tmp, m;   long long arr[100100];   string s, s1;   int32_t main() {     getline(cin, s1);     getline(std::cin, s);     k = 0;     for (long long i = 0; i < s1.length(); i++) k = k * 10 + s1[i] -  0 ;     n = s.length();     long long cur = 0;     vector<long long> l;     long long mm = 0;     for ((i) = 0; (i) < (long long)(n); ++i) {       cur++;       if (s[i] ==  -  || s[i] ==    ) {         l.push_back(cur);         mm = (mm > cur ? mm : cur);         cur = 0;       }     }     if (cur > 0) {       l.push_back(cur);       mm = max(mm, cur);     }     long long le = mm, r = 1000000, mid;     while (le < r) {       mid = (le + r) / 2;       long long cnt = 0;       long long last = 1000000;       for (long long i = 0; i < l.size(); i++) {         if (last + l[i] > mid) {           cnt++;           last = l[i];         } else           last = last + l[i];       }       if (cnt <= k)         r = mid;       else         le = mid + 1;     }     cout << le;   }
#include <bits/stdc++.h>   using namespace std;   int a[360360 + 1], k;   int func(int from, int to) {     int i, j;     for (i = 0; i <= 360360; i++) a[i] = 100000000;     if (from == 0) from = 360360;     a[from] = 0;     for (i = 360360; i > 0; i--) {       if (a[i] == 100000000) continue;       if (a[i - 1] > 1 + a[i]) a[i - 1] = a[i] + 1;       for (j = 2; j <= k; j++) {         int l = i - (i % j);         if (a[l] > a[i] + 1) a[l] = a[i] + 1;       }     }     return a[to];   }   int main() {     long long a, b, i, j, ans = 0;     scanf( %I64d , &a);     scanf( %I64d , &b);     scanf( %d , &k);     if (a / 360360 == b / 360360)       ans = func(a % 360360, b % 360360);     else {       ans = func(a % 360360, 0);       ans += func(360360, b % 360360);       ans += (long long)func(360360, 0) * (a / 360360 - b / 360360 - 1);     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       if (n == 5) {         cout <<  2               <<                  <<  4               <<   n ;       } else         cout << 2 <<     << n / 2 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, m;   long long ans, c[N], a[N];   vector<pair<int, int> > v[N], store;   int main() {     scanf( %d%d , &n, &m);     long long k = n / m, x = 0, res = 0;     for (int i = 0; i < n; ++i) {       scanf( %lld , a + i);       v[a[i] % m].push_back({a[i], i});     }     for (int i = 0; i < m; ++i) c[i] = (int)v[i].size() - k;     for (int i = 1; i < m; ++i) c[i] += c[i - 1];     for (int i = 0; i < n; ++i) x = min(x, c[i]);     for (int i = 0; i < m; ++i) c[i] -= x, res += c[i];     printf( %lld n , res);     int st = 0;     for (int i = 0; i < m; ++i)       if (c[i] == 0) {         st = i;         break;       }     st = (st + 1) % m;     for (int time = 0; time < m; ++time) {       while (store.size() < c[st]) {         pair<int, int> t = v[st].back();         v[st].pop_back();         store.push_back({t.first - time, t.second});       }       while (store.size() > c[st]) {         pair<int, int> t = store.back();         store.pop_back();         v[st].push_back({t.first + time, t.second});       }       st = (st + 1) % m;     }     for (int i = 0; i < m; ++i)       for (auto &t : v[i]) a[t.second] = t.first;     for (int i = 0; i < n; ++i) printf( %d  , a[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n;     cin >> n;     string s =  <3 ;     for (int i = 0; i < n; i++) {       string a;       cin >> a;       s += a;       s +=  <3 ;     }     string b;     cin >> b;     long long int j = 0;     for (int i = 0; i < b.size(); i++) {       if (b[i] == s[j]) j++;     }     if (j >= s.size()) {       cout <<  yes ;     } else {       cout <<  no ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<long long> a(n);     vector<long long> v;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n - 1; i++) {       v.push_back(abs(a[i] - a[i + 1]));     }     long long ans = a[n - 1] - a[0];     sort(v.begin(), v.end());     int y = v.size() - 1;     k--;     while (k--) {       ans = ans - v[y--];     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   int a[51][51];   int p[51];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %d , &a[i][j]);     for (int k = 1; k <= n; k++) {       for (int i = 1; i <= n; i++) {         if (p[i] != 0) continue;         int sum = 0;         for (int j = 1; j <= n; j++) {           if (p[j] != 0) continue;           sum += a[i][j];         }         if (sum == k * (n - k)) {           p[i] = k;           break;         }       }     }     for (int i = 1; i <= n; i++) printf( %d  , p[i]);     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, i, sum = 0, last = -1e8, c, k;     scanf( %d%d , &n, &c);     for (i = 1; i <= n; i++) {       scanf( %d , &k);       if (k - last > c) {         sum = 1;         last = k;       } else {         sum++;         last = k;       }     }     printf( %d , sum);   }
#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265359;   int main() {     int n;     long long p;     cin >> n >> p;     p /= 2;     vector<int> a;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       if (s ==  half )         a.push_back(0);       else         a.push_back(1);     }     long long tek = 0;     for (int i = n - 1; i >= 0; i--) {       if (a[i] == 1)         tek = (tek + 1) * 2LL;       else         tek = tek * 2LL;     }     long long ans = 0;     for (int i = 0; i < n; i++) {       if (tek % 2 == 0 && tek % 4 != 0) {         ans += (tek / 2) * p;         tek = tek / 2 - 1;       } else {         ans += (tek / 2) * p;         tek = tek / 2;       }     }     assert(tek == 0);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 30, Mod = 1e9 + 7;   const long long SQ = 330;   const long long INF = 1e17;   long long a[N], n, q;   long long sum[N << 2], mx[N << 2];   void Change(int x, int val, int id = 1, int b = 0, int e = n) {     if (e - b == 1) {       mx[id] = a[x] = val;       sum[id] = val;       return;     }     if (x < ((b + e) >> 1))       Change(x, val, id << 1, b, ((b + e) >> 1));     else       Change(x, val, id << 1 | 1, ((b + e) >> 1), e);     sum[id] = sum[id << 1] + sum[id << 1 | 1];     mx[id] = max(mx[id << 1], mx[id << 1 | 1]);   }   long long Get(int l, int r, int id = 1, int b = 0, int e = n) {     if (r <= b || e <= l) return 0;     if (l <= b && e <= r) return sum[id];     return Get(l, r, id << 1, b, ((b + e) >> 1)) +            Get(l, r, id << 1 | 1, ((b + e) >> 1), e);   }   void Set(int l, int r, int m, int id = 1, int b = 0, int e = n) {     if (mx[id] < m) return;     if (r <= b || e <= l) return;     if (e - b == 1) {       sum[id] = mx[id] = mx[id] % m;       return;     }     Set(l, r, m, id << 1, b, ((b + e) >> 1));     Set(l, r, m, id << 1 | 1, ((b + e) >> 1), e);     sum[id] = sum[id << 1] + sum[id << 1 | 1];     mx[id] = max(mx[id << 1], mx[id << 1 | 1]);   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n >> q;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) Change(i, a[i]);     while (q--) {       long long t;       cin >> t;       switch (t) {         case 1:           int l, r;           cin >> l >> r;           l--;           cout << Get(l, r) <<   n ;           break;         case 2:           int x;           cin >> l >> r >> x;           l--;           Set(l, r, x);           break;         case 3:           int k;           cin >> k >> x;           Change(k - 1, x);       }     }     return (0);   }
#include <bits/stdc++.h>   using namespace std;   int Fac[1000010], IFac[1000010];   void gcd2(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1, y = 0;       return;     }     gcd2(b, a % b, x, y);     long long t = x;     x = y, y = t - a / b * y;   }   int Inv(int n) {     long long x, y;     gcd2(n, 1000000007, x, y);     if (x < 0)       return x + 1000000007;     else       return x;   }   const int Inv2 = Inv(2);   int n, m;   int main() {     Fac[0] = IFac[0] = 1;     for (int i = 1; i < 1000010; i++)       Fac[i] = (long long)Fac[i - 1] * i % 1000000007;     IFac[1000010 - 1] = Inv(Fac[1000010 - 1]);     for (int i = 1000010 - 2; i >= 0; i--)       IFac[i] = (long long)IFac[i + 1] * (i + 1) % 1000000007;     int _;     scanf( %d , &_);     while (_--) {       int x;       scanf( %d , &x);       if (x == 1)         n++;       else         m++;     }     int n1 = n;     int S = 1;     for (int i = 1, s = 1; i <= n / 2; i++) {       s = ((long long)s * ((long long)n1 * (n1 - 1) / 2 % 1000000007)) %           1000000007;       S = (S + (long long)s * IFac[i] % 1000000007) % 1000000007;       n1 -= 2;     }     for (int i = 0; i < m; i++) S = (long long)S * (n + i + 1) % 1000000007;     printf( %d n , S);     return 0;   }
#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::endl;   using std::pair;   using std::string;   using std::vector;   using vi = vector<int>;   using pii = pair<int, int>;   using vii = vector<pii>;   using ll = long long;   int solve();   int main(int argc, char* argv[]) {     ::std::ios::sync_with_stdio(false);     ::std::cin.tie(0);     ::std::cout.tie(0);     int t = 1;     for (int i = 1; i <= t; ++i) {       solve();     }   }   constexpr int MAX_N = 505050;   constexpr int MOD = 998244353;   int t[4 * MAX_N][2][2];   int n, m;   char s[MAX_N];   void pushup(int k) {     memset(t[k], 0, sizeof(t[k]));     for (int i = 0; i < 2; ++i) {       for (int j = 0; j < 2; ++j) {         t[k][i][j] = (t[k * 2][i][0] * 1LL * t[k * 2 + 1][0][j] +                       t[k * 2][i][1] * 1LL * t[k * 2 + 1][1][j]) %                      MOD;       }     }   }   void build(int k, int L, int R) {     if (L == R) {       memset(t[k], 0, sizeof(t[k]));       t[k][1][0] = 1;       t[k][0][0] = s[L] + 1;       if (s[L] == 1) t[k][0][1] = 9 - s[L + 1];       return;     }     int mid = (L + R) / 2;     build(k * 2, L, mid);     build(k * 2 + 1, mid + 1, R);     pushup(k);   }   void change(int k, int L, int R, int P) {     if (L == R) {       memset(t[k], 0, sizeof(t[k]));       t[k][1][0] = 1;       t[k][0][0] = s[L] + 1;       if (s[L] == 1) t[k][0][1] = 9 - s[L + 1];       return;     }     int mid = (L + R) / 2;     if (P <= mid)       change(k * 2, L, mid, P);     else       change(k * 2 + 1, mid + 1, R, P);     pushup(k);   }   int solve() {     string str;     cin >> n >> m;     cin >> str;     for (int i = 1; i <= n; ++i) s[i] = str[i - 1] -  0 ;     build(1, 1, n);     while (m--) {       int x, y;       cin >> x >> y;       s[x] = y;       if (x != 1) change(1, 1, n, x - 1);       change(1, 1, n, x);       cout << t[1][0][0] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e5 + 5;   map<long long int, long long int> m;   long long int n, ans;   void init() {     m[-1] = -1;     m[2e9] = 2e9;     m[1] = n;     ans = n;   }   void add(long long int l, long long int r) {     m[l] = r;     ans += r - l + 1;   }   void remove(long long int l, long long int r) {     long long int rem = 0;     auto it = m.lower_bound(l);     it--;     if (it->second >= l) {       m[l] = it->second;       it->second = l - 1;     }     it++;     while (it->first <= r) {       if (it->second > r) {         rem += r + 1 - it->first;         m[r + 1] = it->second;       } else         rem += it->second - it->first + 1;       auto it2 = it;       it++;       m.erase(it2);     }     ans -= rem;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int q;     cin >> n >> q;     init();     while (q--) {       long long int l, r, k;       cin >> l >> r >> k;       remove(l, r);       if (k == 2) add(l, r);       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 201110, M = 501110;   int n, m, numeven, numodd;   int a[N];   stack<int> odd, even;   map<int, int> mp;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       mp[a[i]]++;       if (a[i] % 2 == 0)         numeven++;       else         numodd++;     }     for (int i = 1; i <= min(M, m); i++) {       if (i % 2 == 0 && mp[i] == 0) even.push(i);       if (i % 2 == 1 && mp[i] == 0) odd.push(i);     }     int ans = 0;     for (int i = 1; i <= n; i++)       if (mp[a[i]] > 1) {         if (a[i] % 2 == 0)           numeven--;         else           numodd--;         mp[a[i]]--;         if (numeven > numodd) {           ans++;           if (odd.size() == 0) {             cout << -1 << endl;             return 0;           }           a[i] = odd.top();           odd.pop();           numodd++;         } else {           ans++;           if (even.size() == 0) {             cout << -1 << endl;             return 0;           }           a[i] = even.top();           even.pop();           numeven++;         }       }     for (int i = 1; i <= n; i++) {       if (numeven > numodd && a[i] % 2 == 0) {         ans++;         if (odd.size() == 0) {           cout << -1 << endl;           return 0;         }         a[i] = odd.top();         odd.pop();         numeven--;         numodd++;       }       if (numeven < numodd && a[i] % 2 == 1) {         ans++;         if (even.size() == 0) {           cout << -1 << endl;           return 0;         }         a[i] = even.top();         even.pop();         numeven++;         numodd--;       }     }     printf( %d n , ans);     for (int i = 1; i <= n; i++) printf( %d  , a[i]);   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     int v, c, i, d;     edge(int v, int c, int i, int d) : v(v), c(c), i(i), d(d) {}   };   vector<vector<edge> > g(200005);   int n, m, d[200005], f[200005];   int main() {     cin >> n >> m;     for (int _n = m, i = 0; i < _n; ++i) {       int a, b, c;       cin >> a >> b >> c;       a--;       b--;       g[a].push_back(edge(b, c, i, 0));       g[b].push_back(edge(a, c, i, 1));       f[a] += c;       f[b] += c;     }     for (int _n = n, i = 0; i < _n; ++i) f[i] /= 2;     queue<int> Q;     Q.push(0);     memset(d, -1, sizeof(d));     while (!Q.empty()) {       int u = Q.front();       Q.pop();       for (int _n = int((g[u]).size()), i = 0; i < _n; ++i) {         int id = g[u][i].i;         if (d[id] == -1) {           d[id] = g[u][i].d;           int v = g[u][i].v;           f[v] -= g[u][i].c;           if (f[v] == 0 && v != n - 1) Q.push(v);         }       }     }     for (int _n = m, i = 0; i < _n; ++i) cout << d[i] << endl;     return 0;   }