malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   int n, a[N], s1[N], s2[N], ans = 0;   void judge(int x, int y, int mid) {     int tmp = 0;     if (x == y)       tmp = s1[mid] + s2[n] - s2[mid];     else       tmp = s1[x - 1] + s2[n] - s2[y] + s2[mid] - s2[x - 1] + s1[y] - s1[mid];     ans = max(ans, tmp);   }   int main() {     scanf( %d , &n);     int i, j, x, y;     for (i = 1; i <= n; i++) scanf( %d , &a[i]);     for (i = 1; i <= n; i++) {       s1[i] = s1[i - 1];       s2[i] = s2[i - 1];       if (a[i] == 1)         s1[i]++;       else         s2[i]++;     }     int mx, val, mid;     for (x = 1; x <= n; x++) {       if (a[x] == 1)         val = -1;       else         val = 1;       mid = x;       mx = val;       judge(x, x, x);       judge(x, x, x - 1);       for (y = x + 1; y <= n; y++) {         if (a[y] == 1)           val--;         else           val++;         if (val > mx) mx = val, mid = y;         judge(x, y, mid);       }     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(3,  Ofast ,  inline )   using namespace std;   long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch = getchar();     }     return x * f;   }   long long n, m, ans, a[10], G[4005][4005];   long long gcd(long long x, long long y) {     if (!y) return x;     if (G[x][y]) return G[x][y];     return G[x][y] = gcd(y, x % y);   }   long long Get(long long x, long long opt) {     if (opt == 1) {       if (n % 2 == 0) {         if (x)           return n / 2;         else           return n / 2 + 1;       } else         return n / 2 + 1;     } else {       if (m % 2 == 0) {         if (x)           return m / 2;         else           return m / 2 + 1;       } else         return m / 2 + 1;     }   }   void calc() {     if ((a[3] - a[1]) * (a[6] - a[2]) - (a[5] - a[1]) * (a[4] - a[2]) % 2 != 0)       return;     long long x = Get(a[1], 1) * Get(a[2], 2), y = Get(a[3], 1) * Get(a[4], 2),               z = Get(a[5], 1) * Get(a[6], 2);     if (a[1] == a[3] && a[2] == a[4]) y--;     if (a[1] == a[5] && a[2] == a[6]) z--;     if (a[3] == a[5] && a[4] == a[6]) z--;     ans += x * y % 1000000007 * z % 1000000007;     ans %= 1000000007;   }   void dfs(long long x) {     if (x == 7) {       calc();       return;     }     a[x] = 0;     dfs(x + 1);     a[x] = 1;     dfs(x + 1);   }   signed main() {     n = read();     m = read();     for (long long i = 0; i <= 4000; i++) {       for (long long j = 0; j <= 4000; j++) {         G[i][j] = gcd(i, j);       }     }     dfs(1);     for (long long i = 2; i <= n; i++) {       for (long long j = 2; j <= m; j++) {         long long GCD = G[i][j];         ans -= (n - i + 1) % 1000000007 * (m - j + 1) % 1000000007 * (GCD - 1) %                1000000007 * 12ll % 1000000007 % 1000000007;         ans %= 1000000007;         ans += 1000000007;         ans %= 1000000007;       }     }     for (long long i = 0; i <= n; i++) {       if (i >= 2)         ans -= (m + 1) * (i * (i - 1) / 2) % 1000000007 * 6 % 1000000007;       ans += 1000000007;       ans %= 1000000007;     }     for (long long i = 0; i <= m; i++) {       if (i >= 2)         ans -= (n + 1) * (i * (i - 1) / 2) % 1000000007 * 6 % 1000000007;       ans += 1000000007;       ans %= 1000000007;     }     ans %= 1000000007;     ans += 1000000007;     ans += 1000000007;     ans %= 1000000007;     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > q[500005];   int n, m, tot, nms, ans[500005], dep[500005], ms[500005], sz[500005],       t[500005][30], a[500005], hd[500005], to[500005], nxt[500005];   char ch[500005];   int read() {     int x = 0, fl = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fl = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * fl;   }   void add(int x, int y) {     tot++;     to[tot] = y;     nxt[tot] = hd[x];     hd[x] = tot;     return;   }   void dfs(int x, int f) {     sz[x] = 1;     int mx = 0;     for (int i = hd[x]; i; i = nxt[i]) {       int y = to[i];       if (y == f) continue;       dep[y] = dep[x] + 1, dfs(y, x);       sz[x] += sz[y];       if (sz[y] > mx) mx = sz[y], ms[x] = y;     }     return;   }   void calc(int x, int f, int o) {     t[dep[x]][a[x]] += o;     for (int i = hd[x]; i; i = nxt[i]) {       int y = to[i];       if (y == f || y == nms) continue;       calc(y, x, o);     }     return;   }   void dsu(int x, int f, int o) {     for (int i = hd[x]; i; i = nxt[i]) {       int y = to[i];       if (y == f || y == ms[x]) continue;       dsu(y, x, -1);     }     if (ms[x]) dsu(ms[x], x, 1), nms = ms[x];     calc(x, f, 1), nms = 0;     for (int p = 0; p < (int)q[x].size(); p++) {       int d = q[x][p].first, id = q[x][p].second, cnt = 0;       for (int i = 1; i <= 26; i++) cnt += (t[d][i] & 1);       ans[id] = (cnt <= 1);     }     if (o == -1) calc(x, f, -1);     return;   }   int main() {     n = read(), m = read();     for (int i = 2; i <= n; i++) {       int x = read();       add(x, i);     }     scanf( %s , ch + 1);     for (int i = 1; i <= n; i++) a[i] = ch[i] -  a  + 1;     for (int i = 1; i <= m; i++) {       int x = read(), y = read();       q[x].push_back(make_pair(y, i));     }     dep[1] = 1, dfs(1, 0), dsu(1, 0, -1);     for (int i = 1; i <= m; i++) printf( %s n , ans[i] ?  Yes  :  No );     return 0;   }
#include <bits/stdc++.h>   const int SIZE = 5e5 + 5;   using namespace std;   vector<pair<int, int> > v;   set<pair<int, int> > H;   bool used[SIZE];   int b[SIZE];   int main() {     int(n);     scanf( %d , &n);     for (int i = 0; i < (n); ++i) {       int(x);       scanf( %d , &x);       v.push_back(make_pair(x, i));       H.insert(make_pair(i, x));     }     long long an = 0;     sort((v).begin(), (v).end());     for (int i = 0; i < (((int)(v).size())); ++i) {       if (v[i].second == 0 || v[i].second == n - 1) continue;       set<pair<int, int> >::iterator it =           H.lower_bound(make_pair(v[i].second, 0));       set<pair<int, int> >::iterator it2 = it;       int now = it->second;       it2--;       int tmp = it2->second;       it2++;       it2++;       tmp = min(it2->second, tmp);       if (now <= tmp) {         used[i] = 1;         an += tmp;         H.erase(it);       }     }     int bn = 0;     for (set<pair<int, int> >::iterator it = H.begin(); it != H.end(); it++) {       b[bn++] = it->second;     }     if (bn > 2) {       sort(b, b + bn);       for (int i = 0; i + 2 < bn; i++) an += b[i];     }     cout << an << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef long long lint;   typedef pair<int, int> pi;   const int MAXN = 250005;      const int mod = 998244353; //1e9 + 7;//998244353;      template<typename T>   T gcd(const T &a, const T &b) {       return b == T(0) ? a : gcd(b, a % b);   }      struct mint {       int val;       mint() { val = 0; }       mint(const lint& v) {           val = (-mod <= v && v < mod) ? v : v % mod;           if (val < 0) val += mod;       }          friend ostream& operator<<(ostream& os, const mint& a) { return os << a.val; }       friend bool operator==(const mint& a, const mint& b) { return a.val == b.val; }       friend bool operator!=(const mint& a, const mint& b) { return !(a == b); }       friend bool operator<(const mint& a, const mint& b) { return a.val < b.val; }          mint operator-() const { return mint(-val); }       mint& operator+=(const mint& m) { if ((val += m.val) >= mod) val -= mod; return *this; }       mint& operator-=(const mint& m) { if ((val -= m.val) < 0) val += mod; return *this; }       mint& operator*=(const mint& m) { val = (lint)val*m.val%mod; return *this; }       friend mint ipow(mint a, lint p) {           mint ans = 1; for (; p; p /= 2, a *= a) if (p&1) ans *= a;           return ans;       }       friend mint inv(const mint& a) { assert(a.val); return ipow(a, mod - 2); }       mint& operator/=(const mint& m) { return (*this) *= inv(m); }          friend mint operator+(mint a, const mint& b) { return a += b; }       friend mint operator-(mint a, const mint& b) { return a -= b; }       friend mint operator*(mint a, const mint& b) { return a *= b; }       friend mint operator/(mint a, const mint& b) { return a /= b; }       operator int64_t() const {return val; }   };   char str[MAXN];      int main(){    int t;    scanf( %d ,&t);    while(t--){     int n;     scanf( %d ,&n);     scanf( %s , str);     int empt = n;     int ret = 0;     for(int i = 0; i < n; i++){      if(str[i] ==  0 ) continue;      int e = i;      while(e < n && str[e] ==  1 ) e++;      empt -= e - i;    //  if((e - i) % 2) empt--;      ret += (e - i) / 2;      i = e;     }     mint dap = 1, divi = 1;     for(int i = 0; i < empt + ret; i++) dap *= mint(i + 1);     for(int i = 0; i < empt; i++) divi *= mint(i + 1);     for(int i = 0; i < ret; i++) divi *= mint(i + 1);     cout << dap / divi << endl;    }   }
#include <bits/stdc++.h>   using namespace std;   string s;   long long k, n;   int index_1[(int)(1e6 + 5)], num = 0;   void solve() {     cin >> k >> s;     n = s.size();     if (k == 0) {       long long last = 0, ans = 0;       for (int i = 0; i < n; i++) {         if (s[i] ==  0 )           last++;         else {           ans += last * (last + 1) / 2;           last = 0;         }       }       ans += last * (last + 1) / 2;       cout << ans;       return;     }     for (int i = 0; i < n; i++) {       if (s[i] ==  1 ) index_1[num++] = i;     }     long long ans = 0;     for (int i = k - 1; i < num; i++) {       long long t1 = n - 1 - index_1[i] + 1;       if (i < num - 1) t1 = index_1[i + 1] - index_1[i];       long long t2 = index_1[i - (k - 1)] - 0 + 1;       if (i - (k - 1) > 0) t2 = index_1[i - (k - 1)] - index_1[i - (k - 1) - 1];       ans += t1 * t2;     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int in() {     int n;     scanf( %d , &n);     return n;   }   long long Lin() {     long long n;     scanf( %lld , &n);     return n;   }   double Din() {     double n;     scanf( %lf , &n);     return n;   }   const long long inf = (long long)1e17;   const long long mod = (long long)1e9 + 7;   const int N = 1e5 + 5;   vector<int> g[N];   bool vis[N];   int par[18][N], dep[N], sz[N];   void lca_build(int u, int d = 0) {     vis[u] = true, dep[u] = d, sz[u] = 1;     for (int i = 1; i <= 17; i++) {       par[i][u] = par[i - 1][par[i - 1][u]];     }     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (!vis[v]) {         par[0][v] = u;         lca_build(v, dep[u] + 1);         sz[u] += sz[v];       }     }   }   int lca_query(int u, int v) {     if (dep[u] < dep[v]) swap(u, v);     for (int i = 17; i >= 0 && u != v; i--) {       if (dep[par[i][u]] >= dep[v]) u = par[i][u];     }     if (u == v) return u;     for (int i = 17; i >= 0; i--) {       if (par[i][u] != par[i][v]) u = par[i][u], v = par[i][v];     }     return par[0][u];   }   int lifting(int u, int p) {     for (int i = 17; i >= 0; i--) {       if ((1 << i) <= p) u = par[i][u], p -= (1 << i);     }     return u;   }   int dis(int u, int v, int l) { return dep[u] + dep[v] - 2 * dep[l]; }   int solve() {     int n = in();     for (int i = 1; i < n; i++) {       int u = in(), v = in();       g[u].push_back(v);       g[v].push_back(u);     }     par[0][1] = 1;     lca_build(1);     int q = in();     while (q--) {       int u = in(), v = in();       int l = lca_query(u, v);       int d = dis(u, v, l);       int ans = 0;       if (u == v) {         ans = n;       } else if (d & 1) {         ans = 0;       } else if (dep[u] == dep[v]) {         int x = lifting(u, d / 2 - 1);         int y = lifting(v, d / 2 - 1);         ans = n - sz[x] - sz[y];       } else if (dep[u] > dep[v]) {         int x = lifting(u, d / 2);         int y = lifting(u, d / 2 - 1);         ans = sz[x] - sz[y];       } else {         int x = lifting(v, d / 2);         int y = lifting(v, d / 2 - 1);         ans = sz[x] - sz[y];       }       printf( %d n , ans);     }     return 0;   }   int main() {     int test = 1, tc = 0;     while (test--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[200005];   long long cum[200005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tc;     cin >> tc;     while (tc--) {       long long n, p, k;       cin >> n >> p >> k;       for (int i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       long long ans = 0;       long long cnt = 0;       long long temp = p;       for (int i = k - 1; i < n; i += k) {         if (a[i] <= temp) {           temp -= a[i];           cnt += k;         } else           break;       }       long long sum = 0;       for (int i = 0; i < n; i++) {         sum += a[i];         cum[i] = sum;       }       ans = max(ans, cnt);       int in = 0;       while (in < k && (temp - a[in]) >= 0) {         cnt = 0;         temp = p;         temp -= cum[in];         if (temp < 0) break;         for (int i = in + k; i < n; i += k) {           if (a[i] <= temp) {             temp -= a[i];             cnt += k;           } else             break;         }         ans = max(ans, cnt + in + 1);         in++;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using lint = long long;   const lint linf = 1e18 + 7;   const lint inf = 1e9 + 7;   const int MOD = 1000000007;   void press(vector<long long>& x) {     map<int, int> memo;     int n = x.size();     for (int i = 0; i < n; ++i) {       memo[x[i]] += 1;     }     int cur = 1;     for (auto& val : memo) {       val.second = cur;       ++cur;     }     for (int i = 0; i < n; ++i) {       x[i] = memo[x[i]];     }   }   void solve() {     int n;     cin >> n;     vector<lint> a(n, 0);     for (int i = 0; i < n; ++i) cin >> a[i];     auto b = a;     press(b);     vector<vector<int>> dp(n + 5, vector<int>(3, 0));     vector<int> cnt(n + 5, 0);     for (int i = 0; i < n; ++i) cnt[b[i]] += 1;     int res = n - 1;     for (int i = 0; i < n; ++i) {       if (dp[b[i]][0] == 0) {         dp[b[i]][0] = max(dp[b[i] - 1][1], dp[b[i] - 1][2]) + 1;       }       if (dp[b[i]][1] + 1 < cnt[b[i]])         ++dp[b[i]][1];       else {         dp[b[i]][2] = dp[b[i]][0] + dp[b[i]][1];         res = min(res, n - dp[b[i]][2]);         dp[b[i]][1] += 1;       }       int hoge = dp[b[i]][1] + cnt[b[i] + 1] - dp[b[i] + 1][1];       res = min(res, n - hoge);       hoge = cnt[b[i]] - dp[b[i]][1] + dp[b[i] - 1][2] + 1;       res = min(res, n - hoge);     }     cout << res <<   n ;   }   signed main() {     cin.tie(0);     ios::sync_with_stdio(false);     int t;     cin >> t;     for (int i = 0; i < t; ++i) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int mod = 10007;   const long long INF = 1e18 + 1234;   int setbit(int n, int pos) { return n = n | (1 << pos); }   int resetbit(int n, int pos) { return n = n & ~(1 << pos); }   bool checkbit(int n, int pos) { return (bool)(n & (1 << pos)); }   template <typename T>   T mul(T x, T y) {     x %= mod;     y %= mod;     return (x * y) % mod;   }   template <typename T>   T add(T x, T y) {     x %= mod;     y %= mod;     return (x + y) % mod;   }   template <typename T>   T modPow(T x, T k, T mod) {     if (k == 0) return 1;     if (k & 1) {       return ((x % mod) * modPow(x, k - 1, mod) % mod) % mod;     } else {       T ret = modPow(x, k / 2, mod);       ret %= mod;       return (ret * ret) % mod;     }   }   template <typename T>   T ext_gcd(T num1, T num2, T& X, T& Y) {     T r2, r1, q2, q1, x2, x1, y2, y1, x, y, r;     x2 = 1;     y2 = 0;     x1 = 0;     y1 = 1;     for (r2 = num1, r1 = num2; r1 != 0;          y2 = y1, y1 = y, x2 = x1, x1 = x, r2 = r1, r1 = r) {       q1 = r2 / r1;       x = x2 - q1 * x1;       y = y2 - q1 * y1;       r = r2 % r1;     }     X = x2;     Y = y2;     return r2;   }   template <typename T>   void print(const T& v) {     cerr << v <<    ;   }   template <typename T1, typename... T2>   void print(const T1& first, const T2&... rest) {     print(first);     print(rest...);   }   template <class T>   string to_str(T t) {     stringstream second;     second << t;     return second.str();   }   template <typename T>   T modInv(T x, T m) {     return modPow(x, m - 2, m);   }   template <typename T>   void dbg_a(T a[], int n = 10) {     cerr <<  [  ;     for (int i = 0; i < n; i++) cerr << a[i] <<    ;     cerr <<   ]           <<   n ;   }   template <typename F, typename S>   ostream& operator<<(ostream& os, const pair<F, S>& p) {     return os <<  [   << p.first <<  ,   << p.second <<   ] ;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     os <<  [  ;     for (int i = 0; i < v.size(); i++) os << v[i] <<    ;     return os <<   ] n ;   }   const int M = (int)1e6 + 123;   const int maxn = (int)1e6;   bool check(int x, int c, int m) {     int k = min(m, c);     c -= x;     m -= x;     if (c + m >= x)       return 1;     else       return 0;   }   void solve() {     int x = 2048, y, z, k, ans = 0, c, m;     cin >> c >> m >> x;     k = min(c, min(m, x));     ans = k;     c -= k;     m -= k;     x -= k;     if (c == 0 or m == 0) {       cout << ans <<   n ;       return;     }     int s = 0, e = min(c, m), mid;     int ret = 0;     while (s <= e) {       mid = s + (e - s) / 2;       if (check(mid, c, m)) {         ret = mid;         s = mid + 1;       } else {         e = mid - 1;       }     }     cout << ans + ret <<   n ;   }   int main() {     ios ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1, c = 0;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2020;   int prv[N], nxt[N], n;   long long h, x[N];   int px[N], nx[N], pxa[N], nxa[N];   bool mark[N][N][4];   double p, dp[N][N][4];   void prep() {     for (int i = n - 1; i >= 0; i--) {       if (i + 1 == n || x[i + 1] - x[i] >= h) {         nxa[i] = h;         nxt[i] = i;       } else {         nxt[i] = nxt[i + 1];         nxa[i] = min(h, x[i + 1] - x[i]);       }       if (i + 1 == n)         nx[i] = h;       else if (x[i + 1] - x[i] >= 2 * h)         nx[i] = h;       else         nx[i] = max(0LL, x[i + 1] - x[i] - h);     }     for (int i = 0; i < n; i++) {       if (i == 0 || x[i] - x[i - 1] >= h) {         pxa[i] = h;         prv[i] = i;       } else {         pxa[i] = min(h, x[i] - x[i - 1]);         prv[i] = prv[i - 1];       }       if (i == 0)         px[i] = h;       else if (x[i] - x[i - 1] >= 2 * h)         px[i] = h;       else         px[i] = max(0LL, x[i] - x[i - 1] - h);     }   }   double f(int l, int r, int mask) {     if (l > r) return 0;     if (l == r) {       int h1 = pxa[l], h2 = nxa[l];       if (mask & 1) h1 = px[l];       if (mask & 2) h2 = nx[l];       return p * h2 + (1.0 - p) * h1;     }     double &ret = dp[l][r][mask];     if (mark[l][r][mask]) return ret;     int nxtr = min(r, nxt[l]);     int h1 = nxa[nxtr];     if (mask & 2 && nxtr == r) h1 = nx[nxtr];     ret += p * ((x[nxtr] - x[l] + h1) + f(nxtr + 1, r, mask | 1));     h1 = pxa[l];     if (mask & 1) h1 = px[l];     ret += (1.0 - p) * (h1 + f(l + 1, r, mask & 2));     ret /= 2.0;     int prvl = max(l, prv[r]);     h1 = pxa[prvl];     if (mask & 1 && prvl == l) h1 = px[prvl];     double ret2 = (1.0 - p) * ((x[r] - x[prvl] + h1) + f(l, prvl - 1, mask | 2));     int hh = nxa[r];     if (mask & 2) hh = nx[r];     ret2 += p * (hh + f(l, r - 1, mask & 1));     ret2 *= 0.5;     ret += ret2;     mark[l][r][mask] = true;     return ret;   }   int main(void) {     ios::sync_with_stdio(false);     cin >> n >> h >> p;     p = 1.0 - p;     for (int i = 0; i < n; i++) cin >> x[i];     sort(x, x + n);     prep();     printf( %.11lf n , f(0, n - 1, 0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 3 * 100000 + 1;     vector<int> v(n);     v[0] = 0;     for (int i = 1; i < n; i++) {       v[i] = i ^ v[i - 1];     }     int a, b, t, ans;     cin >> t;     while (t--) {       cin >> a >> b;       if (v[a - 1] == b) {         ans = a;       } else if ((v[a - 1] ^ b) == a)         ans = a + 2;       else         ans = a + 1;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b, i, p = 2e9;   int main() {     for (cin >> n; i < n; i++) {       cin >> a >> b;       if (max(a, b) <= p)         p = max(a, b);       else if (a <= p)         p = a;       else if (b <= p)         p = b;       else         return cout <<  NO , 0;     }     cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   inline int re_ad() {     int x = 0, f = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + (ch ^ 48), ch = getchar();     return x * f;   }   int a, b, m;   int rd[2010], ans;   int col[2010][2010];   struct node {     int u, v;   } e[100010];   int main() {     register int i, j, x, y;     register int co[2], now;     a = re_ad();     b = re_ad();     m = re_ad();     for (i = 1; i <= m; ++i) {       e[i].u = x = re_ad();       e[i].v = y = re_ad() + a;       ++rd[x];       ++rd[y];     }     for (i = 1; i <= a + b; ++i) ans = max(ans, rd[i]);     for (i = 1; i <= m; ++i) {       for (j = 1; j <= ans; ++j)         if (!col[e[i].u][j]) {           co[0] = j;           break;         }       for (j = 1; j <= ans; ++j)         if (!col[e[i].v][j]) {           co[1] = j;           break;         }       col[e[i].u][co[0]] = e[i].v;       col[e[i].v][co[1]] = e[i].u;       if (co[0] == co[1]) continue;       now = 1;       x = e[i].v;       while (x) {         swap(col[x][co[1]], col[x][co[0]]);         x = col[x][co[now]];         now ^= 1;       }     }     printf( %d n , ans);     for (i = 1; i <= m; ++i) {       for (j = 1; j <= ans; ++j) {         if (col[e[i].u][j] == e[i].v) {           printf( %d  , j);           break;         }       }     }   }