malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   char str[110];   long long ans = 0;   int main() {     cin >> str;     int ll = strlen(str);     long long k = 1, l = 1;     for (int i = 1; i < ll; i++) {       l = (l % 1000000007 * 2) % 1000000007;     }     k = l;     for (int i = ll - 1; i >= 0; i--) {       if (str[i] ==  1 ) ans = (ans % 1000000007 + k % 1000000007) % 1000000007;       k = (k % 1000000007 * 2) % 1000000007;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long array1[n];     for (int i = 0; i < n; i++) {       cin >> array1[i];     }     long long a, b, c, d, e, sum = 0;     cin >> a >> b >> c >> d >> e;     map<long long, long long> mp;     for (int i = 0; i < n; i++) {       sum += array1[i];       mp[5] += sum / e;       sum %= e;       mp[4] += sum / d;       sum %= d;       mp[3] += sum / c;       sum %= c;       mp[2] += sum / b;       sum %= b;       mp[1] += sum / a;       sum %= a;     }     for (int i = 1; i <= 5; i++) {       cout << mp[i];       if (i != 5) cout <<    ;     }     cout << endl << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, a1, a2, b1, b2, c1, c2, s;     cin >> n;     cin >> a1 >> a2 >> b1 >> b2 >> c1 >> c2;     s = a1 + b1 + c1;     n = n - s;     if (n == 0) {       cout << a1 <<     << b1 <<     << c1 << endl;       return 0;     } else {       a2 = a2 - a1;       b2 = b2 - b1;       c2 = c2 - c1;       if (n <= a2)         a1 += n;       else {         a1 += a2;         n = n - a2;         if (n == 0) {           cout << a1 <<     << b1 <<     << c1 << endl;           return 0;         }         if (n <= b2)           b1 += n;         else {           b1 += b2;           n = n - b2;           if (n == 0) {             cout << a1 <<     << b1 <<     << c1 << endl;             return 0;           }           if (n <= c2) {             c1 += n;           } else {             c1 += c2;           }         }       }     }     cout << a1 <<     << b1 <<     << c1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, m, i, x, p = 0, kk = 100000000000000000, sum = 0;     cin >> n >> k >> m;     string me[n];     map<string, long long> fahim;     for (i = 0; i < n; i++) {       cin >> me[i];     }     for (i = 0; i < n; i++) {       cin >> fahim[me[i]];     }     for (i = 0; i < k; i++) {       cin >> x;       if (x == 1) {         cin >> x;         continue;       }       if (x != 1) {         long long d[x];         for (p = 0; p < x; p++) {           cin >> d[p];           kk = min(kk, fahim[me[d[p] - 1]]);         }         for (p = 0; p < x; p++) {           fahim[me[d[p] - 1]] = kk;         }       }       kk = 100000000000000000;     }     string word;     for (i = 0; i < m; i++) {       cin >> word;       sum += fahim[word];     }     cout << sum;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const int sigma = maxn;   const int HASH_CNT = 2;   int n;   char s[maxn];   unsigned long long Prime_Pool[] = {1998585857ul, 23333333333ul};   unsigned long long Seed_Pool[] = {146527, 19260817};   unsigned long long Mod_Pool[] = {1000000009, 998244353};   unsigned long long has1[26], has2[26];   struct Hash {     unsigned long long Seed, Mod;     unsigned long long bas[maxn];     unsigned long long sum[26][maxn];     int perm[sigma];     void init(int seedIndex, int modIndex) {       Seed = Seed_Pool[seedIndex];       Mod = Mod_Pool[modIndex];       bas[0] = 1;       for (int i = 1; i <= n; i++) {         bas[i] = bas[i - 1] * Seed % Mod;       }       for (int i = 1; i <= n; i++) {         for (int j = 0; j < 26; j++) {           sum[j][i] = (sum[j][i - 1] * Seed % Mod + (s[i] == j +  a )) % Mod;         }       }     }     unsigned long long getHash(int ch, int l, int r) {       return (sum[ch][r] - sum[ch][l - 1] * bas[r - l + 1] % Mod + Mod) % Mod;     }   } hasher[HASH_CNT];   bool check(int l1, int r1, int l2, int r2) {     for (int i = 0; i < HASH_CNT; i++) {       for (int j = 0; j < 26; j++) {         has1[j] = hasher[i].getHash(j, l1, r1);         has2[j] = hasher[i].getHash(j, l2, r2);       }       sort(has1, has1 + 26);       sort(has2, has2 + 26);       for (int j = 0; j < 26; j++)         if (has1[j] != has2[j]) {           return false;         }     }     return true;   }   int main() {     int m, x, y, len;     scanf( %d%d , &n, &m);     scanf( %s , s + 1);     for (int i = 0; i < HASH_CNT; i++) hasher[i].init(i, i);     while (m--) {       scanf( %d%d%d , &x, &y, &len);       if (check(x, x + len - 1, y, y + len - 1))         puts( YES );       else         puts( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   long long f[200009], dp[200009][2];   int main() {     string s, t;     cin >> s >> t;     int m = t.size();     t +=  # ;     t += s;     for (int i = 1; i < t.size(); i++) {       int j = f[i - 1];       while (j > 0 and t[i] != t[j]) j = f[j - 1];       j += (t[i] == t[j]);       f[i] = j;     }     int d = 0, ind;     for (int i = m + 1; i < t.size(); i++) {       if (f[i] == m) d = 1, ind = i - m;       if (d) {         dp[i][0] = ((ind - m + 1) + dp[i - 1][0] + dp[ind][1]) % 1000000007;         dp[i][1] = (dp[i][0] + dp[i - 1][1]) % 1000000007;       }     }     cout << dp[t.size() - 1][0] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 21;   void solve() {     int n, x;     cin >> n;     vector<int> cnt(N, 0);     for (int i = 0; i < n; i++) {       cin >> x;       for (int j = 0; j < N; j++) {         if (x >> j & 1) cnt[j]++;       }     }     long long ans = 0;     for (int i = 0; i < n; i++) {       x = 0;       for (int j = N - 1; j >= 0; j--) {         if (cnt[j]) {           cnt[j]--;           x |= (1 << j);         }       }       ans += (x * 1LL * x);     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     int b[n];     b[0] = 0;     for (int i = 1; i < n; i++) b[i] = abs(a[i] - a[i - 1]);     long long int dp[n], dd[n];     dp[0] = 0;     dd[0] = 0;     for (int i = 1; i < n; i++) {       if (i % 2 == 1) {         dp[i] = dp[i - 1] + b[i];         dd[i] = max(dd[i - 1] - b[i], 0LL);       } else {         dp[i] = max(0LL, dp[i - 1] - b[i]);         dd[i] = dd[i - 1] + b[i];       }     }     long long int ans = 0;     for (int i = 0; i < n; i++) ans = max(ans, dp[i]);     for (int i = 0; i < n; i++) ans = max(ans, dd[i]);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   char str[300005];   vector<int> idx[27];   int main() {     int x;     scanf( %s , str);     int n = strlen(str);     for (int i = 0; i < (int)(n); i++) {       idx[str[i] -  a ].push_back(i);     }     long long int ans[27] = {0};     int ansmax = 0;     for (int i = 0; i < (int)(n); i++) {       set<int> fir;       for (int j = 0; j < (int)(26); j++) {         vector<int>::iterator it = lower_bound(idx[j].begin(), idx[j].end(), i);         if (it != idx[j].end()) fir.insert(*it);       }       int p = i;       int c = 0;       for (__typeof((fir).begin()) it = (fir).begin(); it != (fir).end(); ++it) {         ans[c++] += *it - p;         p = *it;       }       ans[c] += n - p;       ansmax = max(ansmax, c);     }     cout << ansmax << endl;     for (int i = 0; i < (int)(ansmax); i++) cout << ans[i + 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool comp(int a, int b) { return (a > b); }   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int main(void) {     long long int n, m, k;     cin >> n >> m >> k;     if (k > (n + m - 2)) {       cout <<  -1 ;       return 0;     }     long long int ans;     if (m > n) swap(n, m);     if (k <= m - 1)       ans = max(m / (k + 1) * n, n / (k + 1) * m);     else if (k <= n - 1)       ans = n / (k + 1) * m;     else       ans = m / (k - n + 2);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void _R(T &x) {     cin >> x;   }   void _R(int &x) { scanf( %d , &x); }   void _R(long long &x) { scanf( %lld , &x); }   void _R(double &x) { scanf( %lf , &x); }   void _R(char &x) { scanf(  %c , &x); }   void _R(char *x) { scanf( %s , x); }   void R() {}   template <class T, class... U>   void R(T &head, U &...tail) {     _R(head);     R(tail...);   }   template <class T>   void _W(const T &x) {     cout << x;   }   void _W(const int &x) { printf( %d , x); }   void _W(const long long &x) { printf( %lld , x); }   void _W(const double &x) { printf( %.16f , x); }   void _W(const char &x) { putchar(x); }   void _W(const char *x) { printf( %s , x); }   template <class T, class U>   void _W(const pair<T, U> &x) {     _W(x.first);     putchar(   );     _W(x.second);   }   template <class T>   void _W(const vector<T> &x) {     for (auto i = x.begin(); i != x.end(); _W(*i++))       if (i != x.cbegin()) putchar(   );   }   void W() {}   template <class T, class... U>   void W(const T &head, const U &...tail) {     _W(head);     putchar(sizeof...(tail) ?     :   n );     W(tail...);   }   int MOD = 1e9 + 7;   int main() {     long long n, a, b, k;     R(n, a, b, k);     vector<long long> h(n);     for (int i = 0; i < (n); ++i) {       R(h[i]);     }     long long res = 0;     vector<long long> kk;     for (int i = 0; i < (n); ++i) {       if ((h[i] % (a + b)) <= a && (h[i] % (a + b)) > 0) {         ++res;       } else {         long long rest = h[i] - (h[i] / (a + b)) * (a + b);         rest -= a;         if (h[i] % (a + b) == 0) {           rest += a + b;         }         long long r2 = rest;         rest /= a;         if (r2 % a > 0) {           rest += 1;         }         kk.push_back(rest);       }     }     std::sort(kk.begin(), kk.end());     for (int i = 0; i < (kk.size()); ++i) {       if (kk[i] <= k) {         ++res;         k -= kk[i];       } else {         break;       }     }     W(res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[200005], b[200005], s[200005], t[200005], dp[200005];   vector<int> v[200005];   bool flag;   void dfs(int x, int y) {     s[x] = 1;     dp[x] = t[x] = b[x];     int best = 0;     for (int i = (0); i < (v[x].size()); i++) {       int V = v[x][i];       if (V == y) continue;       dfs(V, x);       s[x] += s[V];       t[x] += t[V];       if (s[V] == t[V])         dp[x] += s[V];       else         best = max(best, dp[V]);     }     dp[x] += best;     if (!b[x]) dp[x] = 0;   }   void dfs2(int x, int y) {     int best = 0, ch = -1, sec = 0;     dp[x] = t[x] = b[x];     s[x] = 1;     for (int i = (0); i < (v[x].size()); i++) {       int V = v[x][i];       s[x] += s[V];       t[x] += t[V];       if (s[V] > t[V]) {         if (best <= dp[V]) {           sec = best;           best = dp[V];           ch = V;         } else if (dp[V] > sec)           sec = dp[V];       } else         dp[x] += s[V];     }     dp[x] += best;     if (!b[x]) dp[x] = 0;     if (dp[x] >= m) flag = 1;     for (int i = (0); i < (v[x].size()); i++) {       int V = v[x][i];       if (V == y) continue;       int ori = dp[x], ot = t[x], os = s[x];       if (s[V] == t[V])         dp[x] -= t[V];       else if (ch == V)         dp[x] -= best - sec;       if (!b[x]) dp[x] = 0;       t[x] -= t[V];       s[x] -= s[V];       dfs2(V, x);       dp[x] = ori;       t[x] = ot;       s[x] = os;     }   }   bool ok(int l) {     for (int i = (1); i <= (n); i++) b[i] = a[i] >= l;     dfs(1, 0);     flag = 0;     dfs2(1, 0);     return flag;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = (1); i <= (n); i++) scanf( %d , &a[i]);     for (int i = (1); i < (n); i++) {       int x, y;       scanf( %d %d , &x, &y);       v[x].push_back(y);       v[y].push_back(x);     }     int l = 1, h = 1000000;     while (l < h) {       int m = l + h + 1 >> 1;       if (ok(m))         l = m;       else         h = m - 1;     }     printf( %d n , l);   }
#include <bits/stdc++.h>   const int maxn = 5e5 + 5;   using namespace std;   int a[maxn];   int main() {     int n;     scanf( %d , &n);     long long ans = 0, sum = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       int del = min((long long)a[i] >> 1, sum);       ans += del;       sum -= del;       a[i] -= del << 1;       ans += a[i] / 3;       a[i] %= 3;       sum += a[i];     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000 + 10;   const int maxa = 10000000 + 10;   const int inf = (-1u) >> 1;   struct disjoint_set {     int p[maxn];     void clear(int sz) {       for (int i = (1); i <= (sz); ++i) {         p[i] = i;       }     }     int find(int x) { return x == p[x] ? x : p[x] = find(p[x]); }     bool join(int x, int y) {       x = find(x), y = find(y);       if (x == y) return false;       p[x] = y;       return true;     }   };   int id[maxa], n;   disjoint_set ds;   bool check(int x, int y) { return id[x] && id[y] && ds.join(id[x], id[y]); }   int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }   int main() {     scanf( %d , &n);     for (int i = (1); i <= (n); ++i) {       int t;       scanf( %d , &t);       id[t] = i;     }     ds.clear(n);     int ans = n;     for (int s = 1; s <= 6000; ++s) {       for (int t = (s & 1) + 1; t < s; t += 2) {         if (gcd(s, t) != 1) continue;         int x = 2 * s * t;         int y = s * s - t * t;         int z = s * s + t * t;         if (x >= maxa || y >= maxa) {           continue;         }         ans -= check(x, y);         if (z < maxa) {           ans -= check(x, z);           ans -= check(y, z);         }       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1003;   const int xx[4] = {0, 1, 0, -1};   const int yy[4] = {1, 0, -1, 0};   int x[3], y[3];   void pr(int x, int y, int fx, int fy) {     while (x < fx) {       ++x;       printf( %d %d n , x, y);     }     while (x > fx) {       --x;       printf( %d %d n , x, y);     }     while (y < fy) {       ++y;       printf( %d %d n , x, y);     }     while (y > fy) {       --y;       printf( %d %d n , x, y);     }   }   int main() {     for (int i = 0; i < 3; ++i) scanf( %d%d , &x[i], &y[i]);     int ans = N * N;     int ansx, ansy;     for (int i = 0; i < N; ++i) {       for (int j = 0; j < N; ++j) {         int yans = 0;         for (int k = 0; k < 3; ++k) yans += (abs(i - x[k]) + abs(j - y[k]) + 1);         yans -= 2;         if (yans < ans) {           ans = yans;           ansx = i;           ansy = j;         }       }     }     printf( %d n , ans);     printf( %d %d n , ansx, ansy);     for (int i = 0; i < 3; ++i) pr(ansx, ansy, x[i], y[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int noOfOne(int n) {     int c = 0;     while (n) {       c += (n & 1);       n >>= 1;     }     return c;   }   unsigned long long int f(unsigned long long int n, unsigned long long int r) {     if (n - r > r) {       unsigned long long int temp = n, temp2 = r;       unsigned long long int ans = 1;       while (temp > (n - r)) {         ans *= temp;         --temp;       }       while (temp2) {         ans /= temp2;         --temp2;       }       return ans;     }     unsigned long long int temp = n, temp2 = n - r;     unsigned long long int ans = 1;     while (temp > r) {       ans *= temp;       --temp;     }     while (temp2) {       ans /= temp2;       --temp2;     }     return ans;   }   const unsigned long long int N = 1e6 + 5;   const unsigned long long int MOD = 1e9 + 7;   unsigned long long int n, cnt[N], ans = 0;   int32_t main() {     cin >> n;     unsigned long long int num;     cnt[0] = 1;     for (int i = 1; i <= n; i++) {       cin >> num;       vector<unsigned long long int> cur;       for (unsigned long long int j = 1; j * j <= num; j++) {         if (num % j == 0) {           cur.push_back(j);           if (j != num / j) cur.push_back(num / j);         }       }       sort(cur.begin(), cur.end());       for (int i = cur.size() - 1; i >= 0; i--) {         cnt[cur[i]] += cnt[cur[i] - 1];         cnt[cur[i]] %= MOD;       }     }     for (int i = 1; i <= n && cnt[i] != 0; i++) ans += cnt[i];     ans %= MOD;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e9;   const int mod = inf + 7;   const double eps = 1e-9;   const double pi = acos(-1.0);   long double a, b, c, d;   pair<long double, long double> get(pair<long double, long double> a,                                      pair<long double, long double> b) {     long double x[4] = {a.first * b.first, a.second * b.first, a.first * b.second,                         a.second * b.second};     sort(x, x + 4);     return make_pair(x[0], x[3]);   }   bool ok(pair<long double, long double> a, pair<long double, long double> b) {     long double l = max(a.first, b.first);     long double r = min(a.second, b.second);     return l < r + 1e-21;   }   bool ok(long double ans) {     pair<long double, long double> x = make_pair(a - ans, a + ans);     pair<long double, long double> y = make_pair(b - ans, b + ans);     pair<long double, long double> z = make_pair(c - ans, c + ans);     pair<long double, long double> t = make_pair(d - ans, d + ans);     pair<long double, long double> first = get(x, t);     pair<long double, long double> second = get(y, z);     return ok(first, second);   }   long double mx(long double a, long double b, long double c, long double d) {     return max(abs(a), max(abs(b), max(abs(c), abs(d))));   }   int main() {     cin >> a >> b >> c >> d;     long double l = 0, r = mx(a, b, c, d);     for (int i = 0; i < 20000; i++) {       long double mid = (l + r) / 2.0;       if (ok(mid)) {         r = mid;       } else         l = mid;     }     printf( %.10f n , (double)r);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, p, k, pre[100005], f[100005][128];   struct mem {     long long p[7], a;     bool operator<(const mem &v) const { return a > v.a; }   } c[100005];   int main() {     scanf( %lld%lld%lld , &n, &p, &k);     for (int i = 1; i <= n; i++) scanf( %lld , &c[i].a);     for (int i = 1; i <= n; i++)       for (int j = 0; j < p; j++) scanf( %lld , &c[i].p[j]);     sort(c + 1, c + n + 1);     for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + c[i].a;     for (int i = 1; i <= n; i++)       for (int j = 0; j < 1 << p; j++) {         int sz = 0;         for (int k = 0; k < p; k++) sz += (j >> k) & 1;         f[i][j] = f[i - 1][j];         if (k + sz >= i && sz <= i - 1) f[i][j] += c[i].a;         for (int k = 0; k < p; k++)           if ((j >> k) & 1) {             int q = j ^ (1 << k);             f[i][j] = max(f[i][j], f[i - 1][q] + c[i].p[k]);           }       }     cout << f[n][(1 << p) - 1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct __timestamper {};   vector<string> solve(vector<int> a) {     int n = a.size();     for (int i = 0; i < n - 1; i++) assert(a[i] >= a[i + 1]);     if (n == 0) return vector<string>();     if (a[0] == 1) {       for (int x : a) assert(x == 1);       vector<string> res;       res.push_back(string(n,  1 ));       return res;     }     if (a.back() == n) {       vector<string> res(n + 1);       for (int i = 0; i <= n; i++) {         res[i] = string(n,  1 );         if (i > 0) res[i][i - 1] =  0 ;       }       return res;     }     int x = a.back();     assert(x < n);     a.pop_back();     string cur(n - 1,  0 );     for (int i = 0; i < n - 1; i++) {       if (a[i] == n) {         a[i]--;         cur[i] =  1 ;       }     }     auto res = solve(a);     int left = x - 1;     for (int i = 0; i < (int)res.size(); i++) {       char c =  0 ;       if (left > 0 && res[i] != cur) {         left--;         c =  1 ;       }       res[i] += c;     }     cur +=  1 ;     res.push_back(cur);     return res;   }   vector<string> fast(vector<int> a) {     int n = a.size();     vector<pair<int, int>> b(n);     for (int i = 0; i < n; i++) b[i] = {a[i], i};     sort(b.rbegin(), b.rend());     vector<int> c(n);     for (int i = 0; i < n; i++) c[i] = b[i].first;     auto s = solve(c);     vector<string> res;     for (auto o : s) {       string t(n,  . );       for (int j = 0; j < n; j++) {         t[b[j].second] = o[j];       }       res.push_back(t);     }     sort(res.begin(), res.end());     for (int i = 0; i < (int)res.size() - 1; i++) assert(res[i] != res[i + 1]);     for (int i = 0; i < n; i++) {       int cnt = 0;       for (int j = 0; j < (int)res.size(); j++) {         cnt += res[j][i] ==  1 ;       }       assert(cnt == a[i]);     }     return res;   }   void stress() {     for (int it = 59;; it++) {       mt19937 rnd(it);       cerr <<  it             <<   =   << it << endl;       int n = 1e3;       vector<int> a(n);       for (int i = 0; i < n; i++) a[i] = rnd() % n + 1;       cerr <<  a             <<   =  ;       for (auto xxxx : a) cerr << xxxx <<    ;       cerr << endl;       fast(a);     }   }   int main() {     int n;     while (scanf( %d , &n) == 1) {       vector<int> a(n);       for (int i = 0; i < n; i++) scanf( %d , &a[i]);       auto res = fast(a);       printf( %d n , (int)res.size());       for (auto s : res) printf( %s n , s.c_str());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const K = 12;   int const N = 5e4 + 123;   int n, k;   int s[N][K], maxi[N][K], mini[N][K];   int ans[N];   int cnt[N];   struct Player {     int id, v;     Player(){};     Player(int id, int v) : id(id), v(v){};     bool operator<(const Player &a) const {       if (v != a.v) return v < a.v;       return id < a.id;     };   };   set<Player> t[K];   Player winner = Player(-1, -1);   void pushplayer(int id) {     for (int i = 0; i < k; ++i) {       t[i].insert(Player(id, maxi[id][i]));     }   }   void remove(int id) {     for (int i = 0; i < k; ++i) {       t[i].erase(Player(id, maxi[id][i]));     }   }   void merge(int ida, int idb) {     int idc = min(ida, idb);     winner.id = idc;     cnt[idc] = cnt[ida] + cnt[idb];     for (int i = 0; i < k; ++i) {       mini[idc][i] = min(mini[idb][i], mini[ida][i]);       maxi[idc][i] = max(maxi[idb][i], maxi[ida][i]);     }   }   bool canbeat(int ida, int idb) {     for (int i = 0; i < k; ++i)       if (maxi[ida][i] > mini[idb][i]) return true;     return false;   }   void solve() {     ans[0] = 1;     winner = Player(0, -1);     for (int i = 0; i < n; ++i)       for (int j = 0; j < k; ++j) mini[i][j] = maxi[i][j] = s[i][j];     for (int i = 0; i < n; ++i) cnt[i] = 1;     for (int i = 1; i < n; ++i) {       bool f;       if (canbeat(i, winner.id)) {         if (canbeat(winner.id, i)) {           merge(i, winner.id);           f = true;         } else {           pushplayer(winner.id);           winner = Player(i, -1);           f = false;         }       } else {         pushplayer(i);         f = false;       }       while (f) {         f = false;         Player bf = Player(-1, -1);         for (int j = 0; j < k; ++j) {           if ((int)(t[j].size())) {             set<Player>::iterator it = t[j].end();             --it;             Player b = (*it);             if (canbeat(b.id, winner.id)) {               bf = b;               f = true;               break;             }           }         }         if (!f) break;         remove(bf.id);         merge(winner.id, bf.id);       }       ans[i] = cnt[winner.id];     }   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; ++i)       for (int j = 0; j < k; ++j) scanf( %d , &s[i][j]);     solve();     for (int i = 0; i < n; ++i) printf( %d n , ans[i]);     return 0;   }