malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int res = -1;     for (int i = 1; i < s.size(); i++) {       for (int j = 1; i + j < s.size(); j++) {         int p1;         string P1 = s.substr(0, i);         if (P1.size() > 1 && P1[0] ==  0 )           p1 = -1;         else if (P1.size() >= 7 && P1 !=  1000000 )           p1 = -1;         else           istringstream(P1) >> p1;         int p2;         string P2 = s.substr(i, j);         if (P2.size() > 1 && P2[0] ==  0 )           p2 = -1;         else if (P2.size() >= 7 && P2 !=  1000000 )           p2 = -1;         else           istringstream(P2) >> p2;         int p3;         string P3 = s.substr(i + j, s.size());         if (P3.size() > 1 && P3[0] ==  0 )           p3 = -1;         else if (P3.size() >= 7 && P3 !=  1000000 )           p3 = -1;         else           istringstream(P3) >> p3;         if (p1 == -1 || p2 == -1 || p3 == -1) continue;         res = max(res, p1 + p2 + p3);       }     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   using PII = pair<int, int>;   int main() {     auto get_factors = [](int n) {       vector<int> ret;       for (int i = 1; i * i <= n; i++) {         if (n % i == 0) {           ret.push_back(i);           if (i * i != n) ret.push_back(n / i);         }       }       sort(ret.begin(), ret.end());       return ret;     };     vector<vector<int>> factors(1e5 + 1);     for (int i = (1); i <= (1e5); ++i) factors[i] = get_factors(i);     ios::sync_with_stdio(false);     int tc;     cin >> tc;     while (tc--) {       int x[3], cnt[8] = {0};       cin >> x[0] >> x[1] >> x[2];       vector<int> v;       for (int i = 0; i < 3; i++) {         for (auto val : factors[x[i]]) v.push_back(val);       }       sort(v.begin(), v.end());       v.erase(unique(v.begin(), v.end()), v.end());       for (auto val : v) {         int mask = 0;         for (int i = 0; i < 3; i++) {           if (x[i] % val == 0) mask |= 1 << i;         }         cnt[mask]++;       }       int ans = 0;       for (int a = 1; a < 8; a++) {         for (int b = a; b < 8; b++) {           int t1 = a | b;           if (t1 == (t1 & -t1)) continue;           for (int c = b; c < 8; c++) {             int t2 = a | c, t3 = b | c;             if (t2 == (t2 & -t2)) continue;             if (t3 == (t3 & -t3)) continue;             if ((a | b | c) != 7) continue;             if (a != b && a != c && b != c) {               ans += cnt[a] * cnt[b] * cnt[c];             } else if (a == b && b == c) {               int n = cnt[a] + 2;               ans += n * (n - 1) * (n - 2) / 6;             } else if (a == b) {               ans += cnt[a] * (cnt[a] + 1) / 2 * cnt[c];             } else if (a == c) {               ans += cnt[a] * (cnt[a] + 1) / 2 * cnt[b];             } else if (b == c) {               ans += cnt[b] * (cnt[b] + 1) / 2 * cnt[a];             }           }         }       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i, name[100], cnt;     string str;     char ch;     cin >> n >> k;     cnt = 0;     for (i = 1; i <= k - 1; i++) {       name[i] = ++cnt;     }     for (i = k; i <= n; i++) {       cin >> str;       if (str[0] ==  N ) {         name[i] = name[i - k + 1];       } else {         name[i] = ++cnt;       }     }     for (i = 1; i <= n; i++) {       if (name[i] <= 26) {         ch = ( A  - 1) + name[i];         str = ch;       } else {         ch = ( a ) + name[i] - 26;         str =  A ;         str = str + ch;       }       cout << str <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   char c[100];   int main() {     int n;     cin >> n;     int i;     cin.getline(c, 100);     int open = 0;     string tt =   ;     for (i = 0; i < n; i++) {       cin.getline(c, 100);       string s =   ;       int k = strlen(c);       int j = 0, z;       while (j < k && (c[j] ==     || c[j] ==   t )) j++;       z = k - 1;       while (z >= j && (c[z] ==     || c[z] ==   t )) z--;       for (; j <= z; j++) {         s += c[j];       }       if (s ==  try ) {         open++;       }       if (s.substr(0, 5) ==  throw ) {         open = 0;         k = s.length();         j = 5;         while (j < k && (s[j] ==  (  || s[j] ==     || s[j] ==   t )) j++;         z = k - 1;         while (z >= j && (s[z] ==  )  || s[z] ==     || s[z] ==   t )) z--;         for (; j <= z; j++) {           tt += s[j];         }       }       if (s.substr(0, 5) ==  catch ) {         if (open == 0 && tt !=   ) {           j = 5;           k = s.length();           while (j < k && (s[j] ==  (  || s[j] ==    )) j++;           string ss =   ;           string out =   ;           for (;; j++) {             if (s[j] ==     || s[j] ==  , ) break;             ss += s[j];           }           while (j < k && s[j] !=    ) j++;           for (j++; s[j] !=    ; j++) {             out += s[j];           }           if (ss == tt) {             printf( %s n , out.c_str());             tt =   ;           }         }         open--;         if (open < 0) open = 0;       }     }     if (tt !=   ) {       printf( Unhandled Exception n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void debugv(std::vector<long long> v);   void printv(std::vector<long long> v);   void inputv(std::vector<long long> &v);   void solve() {     long long n;     cin >> n;     string s;     cin >> s;     unordered_map<string, long long> mp;     for (long long i = 0; i < n - 1; i++) {       string k = s.substr(i, 2);       mp[k]++;     }     long long maxi = INT_MIN;     string ans =   ;     for (auto i : mp) {       if (i.second > maxi) {         ans = i.first;         maxi = i.second;       }     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     t = 1;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }   void debugv(std::vector<long long> v) {     long long size = v.size();     for (long long i = 0; i < size; i++) {       cerr << v[i] <<    ;     }     cout <<   n ;   }   void printv(std::vector<long long> v) {     long long size = v.size();     for (long long i = 0; i < size; i++) {       cout << v[i] <<    ;     }     cout <<   n ;   }   void inputv(std::vector<long long> &v) {     for (auto &i : v) {       cin >> i;     }   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, s[30][105], cnt[105];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     string t;     cin >> t;     s[t[0] -  a ][1] = 1;     for (int i = 1; i < t.size(); i++) {       int u = t[i] -  a ;       for (int j = i + 1; j >= 2; j--) {         s[u][j] = 0;         for (int k = 0; k < 26; k++) {           s[u][j] += s[k][j - 1];         }       }       s[u][1] = 1;     }     for (int i = 0; i < 26; i++) {       for (int j = 1; j <= t.size(); j++) {         cnt[j] += s[i][j];       }     }     cnt[0] = 1;     long long res = 0, id = t.size();     while (k > 0) {       long long u = min(k, cnt[id]);       k -= u;       res += (n - id) * u;       id--;       if (id < 0) break;     }     if (k > 0) return cout << -1, 0;     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mod = 1e9 + 7;   int power(int p, int k) {     int a = 1;     while (k) {       if (k & 1) a = (a * p) % mod;       p = (p * p) % mod;       k >>= 1;     }     return a;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int tc = 1;     int i, j;     cin >> tc;     while (tc--) {       int n;       cin >> n;       if (n == 1 || n == 2)         cout << 1;       else if (n == 3)         cout << 2;       else if (n % 2 == 0)         cout << n / 2;       else if (n % 2 == 1)         cout << n / 2 + 1;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   struct time {     int s;     int e;   };   int main() {     int n;     cin >> n;     int s, e;     int minc = INT_MAX, maxc = -1;     for (int i = 0; i < n; i++) {       cin >> s >> e;       if (minc > e) {         minc = e;       }       if (maxc < s) {         maxc = s;       }     }     int m;     cin >> m;     int maxp = -1, minp = INT_MAX;     for (int i = 0; i < m; i++) {       cin >> s >> e;       if (minp > e) {         minp = e;       }       if (maxp < s) {         maxp = s;       }     }     int p = maxp - minc;     int q = maxc - minp;     if (p < 0 && q < 0) {       cout << 0;     } else {       cout << max(p, q);     }   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   const long double PI = 3.141592653589793;   const long long int INF = 9223372036854775807ll;   void solve() {     string p, h;     cin >> p >> h;     if (h.size() < p.size()) {       cout <<  NO n ;       return;     }     vector<int> x(26, 0);     for (int i = 0; i < p.size(); i++) x[p[i] -  a ]++;     for (int i = 0; i < h.size() - p.size() + 1; i++) {       vector<int> v(26, 0);       for (int j = i; j < i + p.size(); j++) v[h[j] -  a ]++;       int cnt = 0;       for (int i = 0; i < 26; i++)         if (x[i] == v[i]) cnt++;       if (cnt == 26) {         cout <<  YES n ;         return;       }     }     cout <<  NO n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t = 1;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int flag1;     flag1 = 0;     int flag2 = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  I ) {         flag1++;       }       if (s[i] ==  A ) {         flag2++;       }     }     if (flag1 == 0) {       cout << flag2 << endl;     } else if (flag1 == 1) {       cout << 1 << endl;     } else {       cout << 0 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0)->sync_with_stdio(0);     string s;     cin >> s;     string t = s;     int n = s.size();     auto check = [&]() {       for (int i = 0; i <= 0; i++) {         int mx0 = 0, mx1 = 0, mmx0 = 0, mmx1 = 0;         for (int j = i; j < n; j++) {           if (s[j] ==  1 ) {             mx1 = max(mx1 + 1, mx0 + 1);           } else {             mx0++;           }           if (t[j] ==  1 ) {             mmx1 = max(mmx1 + 1, mmx0 + 1);           } else {             mmx0++;           }           if (max(mx0, mx1) != max(mmx0, mmx1)) {             return 0;           }         }       }       return 1;     };     for (int i = 0; i < n; i++) {       if (s[i] ==  0 ) continue;       s[i] =  0 ;       if (!check()) {         s[i] =  1 ;       }     }     cout << s <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX1 = 1e6 + 10;   long long T, a, b, c, d, e, f, x, y, z, l, r, mid, num[MAX1], cnt, flag,       p1[55][55], p2[55][55];   string s, t;   stack<char> st;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> s;     a = s.size();     for (int i = 0; i < a; ++i) {       if (st.empty())         st.push(s[i]);       else if (st.top() == s[i]) {         st.pop();       } else         st.push(s[i]);     }     if (st.empty())       cout <<  Yes ;     else       cout <<  No ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int l;     cin >> l;     string s;     cin >> s;     if (s.length() % l != 0) {       string pattern(l,  0 );       pattern[0] =  1 ;       int times = s.length() / l + 1;       while (times-- > 0) {         cout << pattern;       }     } else {       string pattern = s.substr(0, l);       int times = s.length() / l;       string presumablyAnswer;       for (int i = 0; i < times; ++i) {         presumablyAnswer += pattern;       }       if (presumablyAnswer > s) {         cout << presumablyAnswer << endl;       } else {         if (count(pattern.begin(), pattern.end(),  9 ) < l) {           int i = (int)pattern.size() - 1;           while (pattern[i] ==  9 ) {             pattern[i] =  0 ;             --i;           }           ++pattern[i];           for (int i = 0; i < times; ++i) {             cout << pattern;           }         } else {           fill(pattern.begin(), pattern.end(),  0 );           pattern[0] =  1 ;           for (int i = 0; i <= times; ++i) {             cout << pattern;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cnt[5005];   int nearest[5005];   int main(void) {     int n, m;     cin >> n >> m;     memset(cnt, 0, sizeof(cnt));     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       b = b > a ? b : b + n;       if (!cnt[a] || b < nearest[a]) nearest[a] = b;       cnt[a]++;     }     for (int i = 1; i <= n; ++i) {       int time = 0;       for (int j = 1; j <= n; ++j) {         int x = (cnt[j] - 1) * n + (nearest[j] + (i > j ? n : 0));         time = max(x, time);       }       cout << time - i <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f, mod = 1e9 + 7;   const int maxn = 2e5 + 100, mxn = 5e5 + 100;   const long double PI = acos(-1.0);   long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }   void exgcd(long long a, long long b, long long& d, long long& x, long long& y) {     if (!b) {       d = a;       x = 1;       y = 0;     } else {       exgcd(b, a % b, d, y, x);       y -= x * (a / b);     }   }   long long power(long long a, long long n) {     long long p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;       }       n >>= 1;       a *= a;     }     return p;   }   long long power(long long a, long long n, long long mod) {     long long p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;         p %= mod;       }       n >>= 1;       a *= a;       a %= mod;     }     return p % mod;   }   int n, m;   double a[maxn], b[maxn], p, q;   double f(double x) {     double minn = 100000.0;     for (int i = 1; i <= n; i++) minn = min(minn, (1 - b[i] * x) / a[i]);     return p * minn + q * x;   }   int main() {     while (cin >> n >> p >> q) {       double maxx = 0;       for (int i = 1; i <= n; i++) {         cin >> a[i] >> b[i];         maxx = max(b[i], maxx);       }       double l = 0, r = 1 / maxx;       for (int i = 1; i <= 400; i++) {         double mid = (l + r) / 2.0;         double midmid = (mid + r) / 2.0;         if (f(mid) >= f(midmid))           r = midmid;         else           l = mid;       }       printf( %.10f n , f((l + r) / 2.0));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> final;   void seive(int n) {     vector<bool> prime(n + 1, true);     prime[0] = false;     prime[1] = false;     for (long long int i = 2; i <= (long long int)sqrt(n); ++i) {       if (prime[i]) {         for (int j = i * i; j <= n; j += i) prime[j] = false;       }     }     for (long long int i = 2; i <= n; ++i) {       if (prime[i]) final.push_back(i);     }   }   const int mod = 998244353;   const int mx = 2e5 + 1;   vector<int> fact(mx);   vector<int> inv_fact(mx);   long long int expo_pow(long long int a, long long int b) {     a %= mod;     long long int res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return res;   }   void precompute() {     fact[0] = 1;     for (long long int i = 1; i <= mx; ++i) fact[i] = (fact[i - 1] * i) % mod;     for (long long int i = 0; i <= mx; ++i)       inv_fact[i] = expo_pow(fact[i], mod - 2) % mod;   }   long long int compute(long long int n, long long int r) {     return fact[n] * 1ll * inv_fact[r] % mod * inv_fact[n - r] % mod;   }   struct cmp {     bool operator()(long long int const& a, long long int const& b) {       return a > b;     }   };   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t--) {       long long int n, k, gain, sum = 0;       cin >> n >> k;       vector<long long int> cost(n), a(n);       for (long long int i = 0; i < n; ++i) cin >> a[i];       cin >> gain;       for (long long int i = 0; i < n; ++i) cin >> cost[i];       priority_queue<long long int, vector<long long int>, cmp> pq;       bool cond = true;       for (long long int i = 0; i < n; ++i) {         pq.push(cost[i]);         if (k < a[i]) {           while (!pq.empty() && k < a[i]) {             k += gain;             sum += pq.top();             pq.pop();           }           if (k >= a[i])             continue;           else {             cond = false;             break;           }           cout <<   n ;         }       }       if (cond)         cout << sum <<   n ;       else         cout << -1 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, w, l;     cin >> n >> l >> w;     long double p[n + 1];     long long int b[n + 1];     for (long long int i = 1; i <= n; i++) {       cin >> p[i];       p[i] /= 100;     }     for (long long int i = 1; i <= n; i++) {       cin >> b[i];       b[i]++;     }     long double a[n + 1][n + 1][n + 1];     for (long long int i = 0; i <= n; i++) {       for (long long int j = 0; j <= n; j++) {         for (long long int k = 0; k <= n; k++) {           a[i][j][k] = 0;         }       }     }     long double x, y;     long long int z = 0;     if (w > n) w = n;     a[0][0][w] = 1;     for (long long int i = 1; i <= n; i++) {       for (long long int j = 0; j <= i; j++) {         for (long long int k = 0; k <= n; k++) {           z = b[i];           z += k;           if (z > n) z = n;           if (j > 0) a[j][i - j][z] += ((a[j - 1][i - j][k]) * (p[i]));           if ((i - j) > 0)             a[j][i - j][k] += ((a[j][i - j - 1][k]) * (1.0 - p[i]));         }       }     }     long double ans = 0.0;     for (long long int i = 0; i <= n; i++) {       for (long long int j = 0; j <= n; j++) {         for (long long int k = 0; k <= n; k++) {           if ((k >= i) && (i >= l) && ((i + j) == n)) {             ans += a[i][j][k];           }         }       }     }     cout << fixed << setprecision(6) << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     multiset<long long> A, B;     for (long long i = 0; i < n; i++) {       long long num;       cin >> num;       A.insert(-num);     }     for (long long i = 0; i < n; i++) {       long long num;       cin >> num;       B.insert(-num);     }     long long ansa = 0, ansb = 0;     while (!A.empty() || !B.empty()) {       long long v1 = 0, v2 = 0;       if (A.size() > 0) {         v1 = -(*A.begin());         if (B.size() > 0) {           v2 = -(*B.begin());           if (v2 >= v1) {             auto it = B.begin();             B.erase(it);           } else {             auto it = A.begin();             A.erase(it);             ansa += v1;           }         } else {           auto it = A.begin();           A.erase(it);           ansa += v1;         }       } else {         if (B.size() > 0) {           auto it = B.begin();           B.erase(it);         }       }       v1 = 0, v2 = 0;       if (B.size() > 0) {         long long v1 = -(*B.begin());         if (A.size() > 0) {           v2 = -(*A.begin());           if (v2 >= v1) {             auto it = A.begin();             A.erase(it);           } else {             auto it = B.begin();             B.erase(it);             ansb += v1;           }         } else {           auto it = B.begin();           B.erase(it);           ansb += v1;         }       } else {         if (A.size() > 0) {           auto it = A.begin();           A.erase(it);         }       }     }     cout << ansa - ansb;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int adj[5000005], can[5000005], fuck[5000005];   inline int read() {     int x = 0, f = 1;     char ch = getchar();     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) f = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     return x * f;   }   int main() {     n = read(), m = read();     if (n == 1) {       puts( 0 );       return 0;     }     for (int i = 0; i < n; i++) adj[i] = 1 << i;     while (m--) {       int x = read() - 1, y = read() - 1;       adj[x] |= 1 << y, adj[y] |= 1 << x;     }     int all = (1 << n) - 1;     bool flag = 1;     for (int i = 0; i < n; i++)       if (adj[i] != all) flag = 0;     if (flag) {       puts( 0 );       return 0;     }     for (int i = 0; i < n; i++) can[1 << i] = 1, fuck[1 << i] = adj[i];     for (int i = 1; i < (1 << n); i++)       if (can[i]) {         for (int j = 0; j < n; j++)           if ((~i >> j & 1) && (fuck[i] >> j & 1))             can[1 << j | i] = 1, fuck[1 << j | i] = fuck[i] | adj[j];       }     int ans = n, mask = 0;     for (int i = 1; i < (1 << n); i++)       if (can[i] && (fuck[i] == all)) {         int res = __builtin_popcount(i);         if (ans > res) ans = res, mask = i;       }     printf( %d n , ans);     for (int i = 0; i < n; i++)       if (mask >> i & 1) printf( %d  , i + 1);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   int n;   int dig[N];   vector<int> ans[N];   bool vis[N];   int main() {     cin >> n;     vector<int> x;     for (int i = (0); i < (n); i++) scanf( %d , &dig[i]), x.push_back(dig[i]);     sort((x).begin(), (x).end());     for (int i = (0); i < (n); i++)       dig[i] = lower_bound((x).begin(), (x).end(), dig[i]) - x.begin();     memset(vis, false, sizeof(vis));     int ned = 0;     for (int i = (0); i < (n); i++)       if (!vis[i]) {         for (int u = i; !vis[u]; u = dig[u]) vis[u] = true, ans[ned].push_back(u);         ned++;       }     printf( %d n , ned);     for (int i = (0); i < (ned); i++) {       printf( %d , ((int)(ans[i]).size()));       for (int j = (0); j < (((int)(ans[i]).size())); j++)         printf(  %d , ans[i][j] + 1);       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2;     cin >> s1 >> s2;     for (int i = 0; i < s1.size(); i++) {       if (s1[i] <= 90) s1[i] += 32;       if (s2[i] <= 90) s2[i] += 32;       if (s1[i] > s2[i]) {         cout << 1 << endl;         return 0;       } else if (s1[i] < s2[i]) {         cout << -1 << endl;         return 0;       }     }     cout << 0 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       char a[n][m];       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cin >> a[i][j];         }       }       int ans = 0;       for (int j = 0; j < m - 1; j++) {         if (a[n - 1][j] ==  D ) {           ans++;         }       }       for (int i = 0; i < n - 1; i++) {         if (a[i][m - 1] ==  R ) {           ans++;         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1000 + 20, MAX_K = 5 + 2;   int a[MAX_K][MAX_N];   int dp[MAX_N];   map<int, int> D, ke;   int ans;   int n, k;   int main() {     ios::sync_with_stdio(false);     cin >> n >> k;     for (int i(0); i < int(k); ++i)       for (int j(0); j < int(n); ++j) {         cin >> a[i][j];         --a[i][j];       }     for (int i(0); i < int(n); ++i) D[a[0][i]] = i;     for (int i(0); i < int(k); ++i)       for (int j(0); j < int(n); ++j) a[i][j] = D[a[i][j]];     for (int i(0); i < int(n); ++i) {       ke.clear();       dp[i] = 1;       for (int j(0); j < int(k); ++j)         for (int l = 0; l < n && a[j][l] != i; ++l) ke[a[j][l]]++;       for (int j(0); j < int(i); ++j)         if (ke[j] == k) dp[i] = max(dp[i], dp[j] + 1);     }     for (int i(0); i < int(n); ++i) ans = max(ans, dp[i]);     cout << ans << endl;     return 0;   }