stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

//#define ull unsigned long long

#define ull uint

#define ul unsigned long

#define ll long long



int main(){

  int N;

  cin>>N;

  int inc,myno;

  ull SYO=1000000007,sameflg;

  vector<int> C(N,0);

  cin>>C[0];

  int newN=1,jid;//newN

  

  for(int i=1;i<N;i++){

    cin>>inc;

    if (C[newN-1]!=inc){

      C[newN]=inc;

      newN++;

    }

  }

  //Cの数値が何個出現するかを記憶する変数

  vector<int> Cnum(200000,0);

  for(int i=0;i<newN;i++){

    Cnum[C[i]]++;

  }

  vector<int> Cnumsum(200000,0);//参照する最初のindexがこれでわかる

  for(int i=1;i<200000;i++){

    Cnumsum[i]=Cnumsum[i-1]+Cnum[i-1];

  }

  vector<int> Cnumsum_dmy(200000,0);//参照する最初のindexがこれでわかる

  for(int i=0;i<200000;i++){

    Cnumsum_dmy[i]=Cnumsum[i];

  }

  

  //Cの数値が出現したindexを記憶する変数

  vector<int> Cnumid(newN,0);

  for(int i=0;i<newN;i++){

    Cnumid[Cnumsum_dmy[C[i]]]=i;

    Cnumsum_dmy[C[i]]++;

  }

  

  vector<int> sumdp(200000,0);

  

  

  vector<vector<ull>> dp = vector<vector<ull>>(newN, vector<ull>(2, 0));

  ull ans=0;

  dp[0][0]=1;

  sumdp[C[0]]=1;

  for(int i=1;i<newN;i++){

    myno=C[i];

    sameflg=0;

    

    for(int j=0;j<Cnum[myno];j++){

      jid=Cnumid[Cnumsum[myno]+j];

      if (jid>=i){break;}

      //sameflg++;

    }

    

      sameflg+=sumdp[myno];

      sameflg%=SYO;

      dp[i][0]=(dp[i-1][0]+sameflg)%SYO;

      sumdp[myno]=(sumdp[myno]+dp[i-1][0])%SYO;

    

    

  }

    

  ans=dp[newN-1][0];

  cout<<ans%SYO<<endl;

  return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



int main(){

  uint N;

  cin>>N;

  uint inc,myno,SYO=1000000007,sameflg;

  vector<uint> C(N,0);

  cin>>C[0];

  uint newN=1,jid;//newN

  for(uint i=1;i<N;i++){

    cin>>inc;

    if (C[newN-1]!=inc){

      C[newN]=inc;

      newN++;

    }

  }

  

  vector<uint> sumdp(200000,0);

  vector<uint> dp(newN,0);



  dp[0]=1;

  sumdp[C[0]]=1;

  for(uint i=1;i<newN;i++){

    myno=C[i];

    sameflg=sumdp[myno];

    dp[i]=(dp[i-1]+sameflg)%SYO;

    sumdp[myno]=(sumdp[myno]+dp[i-1])%SYO;

  }



  cout<<dp[newN-1]<<endl;

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>



using namespace std;

#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)

#define REP(i,a,b) REPP(i,a,b,1)

#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)

#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) REP(i,0,(int)a-1)

#define FORD(i,a) REV(i,(int)a-1,0)

#define PB push_back

#define POB pop_back

#define MP make_pair

#define FI first

#define SE second

typedef long long ll;

typedef unsigned long long ull;

typedef pair < int , int > pii;

typedef vector < int > vi;

typedef vector < pii > vii;

typedef vector < ll > vl;



const double EPS = 1e-9;

const double PI = acos(-1);

const int INF = 1e9;

const ll MOD = 1e9 + 7;



ll addMod(ll a, ll b){

	return (a+b) % MOD;

}



ll mulMod(ll a, ll b){

	return (a*b) % MOD;

}



ll fast(ll a, ll b){

	if(b == 0) return 1;

	ll tmp = fast(a,b/2);

	tmp = mulMod(tmp, tmp);

	if(b & 1) tmp = mulMod(tmp, a);

	return tmp;

}



/////////////////////////////////////////////////////////



const int N = 2e5;



int n;

int m;

int arr[N + 5];

vi lst[N + 5];

ll dp[N + 5];

int nxt[N + 5];



ll solve(int idx){

	if(idx == m+1){

		return 1;

	}

	ll& ret = dp[idx];

	if(ret != -1) return ret;

	ret = solve(idx+1);

	if(nxt[idx] != -1) ret = addMod(ret, solve(nxt[idx]));

	return ret;

}





int main(){

	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

	memset(nxt,-1,sizeof nxt);

	m = 0;

	cin >> n;

	int bef = -1;

	int x;

	REP(i,1,n){

		cin >> x;

		if(x != bef){

			arr[++m] = x;

			bef = x;

			lst[x].PB(m);

		}

	}

	REP(i,1,N){

		if(lst[i].size() > 1){

			FOR(j,lst[i].size()-1){

				nxt[lst[i][j]] = lst[i][j+1];

			}

		}

	}

	memset(dp,-1,sizeof dp);

	cout << solve(1) << endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

using namespace std;

int n,x,las,ans,c[200013];

int main(){

    scanf("%d",&n);

    ans=1;las=-1;

    for(register int i=0;i<n;++i){

        scanf("%d",&x);

        if(x==las)continue;

        las=x;

        ans=(1LL*ans+c[x])%1000000007;

        c[x]=ans;

    }

    printf("%d",ans);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

#define pb push_back

using ll = long long;

const ll N = 200500;

const ll m = (ll)1e9 + 7;

ll n,c[N],dp[N];

vector <ll> pos[N];



ll add(ll a , ll b) {

   return ((a % m) + (b % m)) % m;

}



ll f(ll curr) {

   if (curr > n) return 1;

   ll &sol = dp[curr];

   if (sol != -1) return sol;

   auto it = upper_bound(pos[c[curr]].begin() , pos[c[curr]].end() , curr);

   if (it == pos[c[curr]].end()) {

      sol = f(curr + 1);

   } else {

      if (abs((*it) - curr) == 1) {

         sol = f(curr + 1);

      } else {

         sol = add(f(curr + 1) , f(*it));

      }

   }

   return sol;

}



int main() {

   scanf("%lld" , &n);

   for (ll i = 1 ; i <= n ; i++) {

      scanf("%lld" , &c[i]);

      pos[c[i]].push_back(i);

   }

   memset (dp , -1 , sizeof dp);

   printf("%lld\n" , f(1));

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define rep(i, l, r) for (register int i = l; i <= r; i++)

#define per(i, r, l) for (register int i = r; i >= l; i--)

#define srep(i, l, r) for (register int i = l; i < r; i++)

#define sper(i, r, l) for (register int i = r; i > l; i--)

#define erep(i, x) for (register int i = h[x]; i; i = e[i].next)

#define erep2(i, x) for (register int& i = cur[x]; i; i = e[i].next)

#define pii pair<int, int>

#define pll pair<ll, ll>

#define pdd pair<double, double>

#define fi first

#define se second

#define ui unsigned int

#define ld long double

#define ll long long int 

#define pb push_back

#define pc putchar

#define lowbit(x) (x & -x)

#define maxr 2000020

#define maxn 400020

#define maxm

#define maxs

#define maxb

#define M 1000000007

#define mo(x) (x = (x >= M) ? (x - M) : x)

#define gc() ((p1 == p2 && (p2 = (p1 = buffer) + fread(buffer, 1, maxr, stdin), p1 == p2)) ? EOF : *p1++)

using namespace std;



char buffer[maxr], *p1, *p2;

template <class T> void read(T& x){

	char ch = gc(); x = 0; bool f = 1;

	while (!('0' <= ch && ch <= '9') && ch != '-') ch = gc();

	if (ch == '-') f = 0, ch = gc();

	while ('0' <= ch && ch <= '9') x = (x << 1) + (x << 3) + ch - '0', ch = gc();

	x = (f) ? x : -x;

}

int _num[20];

template <class T> void write(T x){	

	if (!x) {putchar('0'), putchar('\n'); return;}

	if (x < 0) putchar('-'), x = -x;

	int c = 0;

	while (x) _num[++c] = x % 10, x /= 10;

	while (c) putchar('0' + _num[c--]); 

	putchar('\n');

}



int n, a[maxn], _n, _a[maxn], dp[maxn], c[maxn], pre[maxn];



int main(){

	scanf("%d", &_n); rep(i, 1, _n) scanf("%d", _a + i); 

	rep(i, 1, _n) {

		int now = _a[i]; a[++n] = now;

		while (i <= _n && _a[i] == now) i++; i--;

	}

	

	rep(i, 1, n){

		dp[i] = c[a[i]], pre[i] = pre[i - 1] + dp[i], mo(pre[i]);

		//c[a[i + 1]] += pre[i] + 1, mo(c[a[i + 1]]);

		c[a[i]] += pre[i - 1] + 1, mo(c[a[i]]);

	} 

	printf("%d\n", pre[n] + 1);

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

//#include <iomanip>

//#include <string>

#include <vector>

#include <algorithm>

//#include <utility>

//#include <set>

//#include <map>

//#include <queue>

//#include <deque>

//#include <bitset>

//#include <math.h>

using namespace std ;

using ll = long long ;

//using ld = long double ;

using vll = vector<ll> ;

using vvll = vector<vll> ;

//using vc = vector<char> ;

//using vvc = vector<vc> ;

//using vb = vector<bool> ;

//using vvb = vector<vb> ;

//using pll = pair<ll,ll> ;

#define all(v) v.begin(),v.end()

ll mod = 1e9+7 ;

//long double pie = acos(-1) ;

//ll INF = 1000000000000 ;



//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}

//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}

//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}

//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}

//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}

//void fix_cout(){cout << fixed << setprecision(20) ;}



int main(){

	ll n ; cin >> n ;

	vvll b(200000,vll(0)) ;

	vll dp(n+1,0) ;

	dp.at(0) = 1 ;

	for(int i=1;i<=n;i++){

		ll c ; cin >> c ;

		c-- ;

		dp.at(i) += dp.at(i-1) ;

		b.at(c).push_back(i) ;

		if(b.at(c).size()>=2&&i-1>b.at(c).at(b.at(c).size()-2)){

			dp.at(i) += dp.at(b.at(c).at(b.at(c).size()-2)) ;

		}

		dp.at(i) %= mod ;

	}

//	for(auto i:dp) cout << i << " " ; cout << endl ;

	cout << dp.at(n) << endl ;

//	cout << mod << endl ;

}


// Optimized solution to the same problem (faster):
#include <iostream>

//#include <iomanip>

#include <string>

#include <vector>

#include <algorithm>

//#include <utility>

#include <set>

//#include <map>

//#include <queue>

//#include <deque>

//#include <bitset>

//#include <math.h>

using namespace std ;

using ll = long long ;

//using ld = long double ;

using vll = vector<ll> ;

//using vvll = vector<vll> ;

//using vc = vector<char> ;

//using vvc = vector<vc> ;

//using vb = vector<bool> ;

//using vvb = vector<vb> ;

//using pll = pair<ll,ll> ;

#define all(v) v.begin(),v.end()

ll mod = 1000000007 ;

//long double pie = acos(-1) ;

//ll INF = 1000000000000 ;



//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}

void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}

//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}

//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}

//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}

//void fix_cout(){cout << fixed << setprecision(20) ;}



int main(){

	ll n ; cin >> n ;

	vll last(200001,-1) ;

	vll dp(n+1,0) ;

	dp.at(0) = 1 ;

	for(int i=0;i<n;i++){

		ll a ; cin >> a ;

		dp.at(i+1) = dp.at(i) ;

		if(last.at(a)!=-1&&last.at(a)+1!=i) dp.at(i+1) += dp.at(last.at(a)+1) ;

		dp.at(i+1) %= mod ;

		last.at(a) = i ;

	}

	cout << dp.at(n) << endl ;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int maxn = 2e5+5;

const ll mod=1e9+7;

ll qp(ll t1,ll t2) { ll s=1;for (;t2;t1=t1*t1%mod,t2>>=1) if (t2&1) s=s*t1%mod; return s;}

inline int read() {

    char c = getchar(); int x = 0, f = 1;

    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}

    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();

    return x * f;

}

vector<int> p[maxn];

int a[maxn];

int b[maxn];

ll dp[maxn];

ll temp[maxn];

int main()

{

    int n;



    n=read();



    for (int q=1;q<=n;q++)

    a[q]=read();



    int tot=1;

    for (int q=1;q<=n;q++)

    {

        if( a[q]!=a[q-1])

        {

            b[tot++]=a[q];

        }

    }



    dp[0]=1;

    int z,x,sz;

    memset(temp,0,sizeof temp);

    for (int q=1;q<tot;q++)

    {



        dp[q]=dp[q-1];

        z=b[q],x;

        if (temp[z]==0)

        temp[z]=dp[q-1];

        else 

        {

            dp[q]+=temp[z];

            temp[z]+=dp[q-1];

            dp[q]%=mod;

            temp[z]%=mod;

        }

    }



    printf("%lld\n",dp[tot-1]);





    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int maxn = 2e5+5;

const ll mod=1e9+7;

ll qp(ll t1,ll t2) { ll s=1;for (;t2;t1=t1*t1%mod,t2>>=1) if (t2&1) s=s*t1%mod; return s;}

inline int read() {

    char c = getchar(); int x = 0, f = 1;

    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}

    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();

    return x * f;

}

ll p[maxn];

int a[maxn];

int b[maxn];

ll dp[maxn];

int main()

{

    int n;



    n=read();



    for (int q=1;q<=n;q++)

    a[q]=read();



    int tot=1;

    for (int q=1;q<=n;q++)

    {

        if( a[q]!=a[q-1])

        {

            b[tot++]=a[q];

        }

    }



    dp[0]=1;

    int x;

    memset(p,0,sizeof p);

    for (int q=1;q<tot;q++)

    {

        dp[q]=dp[q-1];

        x=b[q];

        if (p[x]==0)

        p[x]=dp[q-1];

        else 

        {

            dp[q]+=p[x];

            p[x]+=dp[q-1];

            dp[q]%=mod;

            p[x]%=mod;

        }

    }



    printf("%lld\n",dp[tot-1]);

  



    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<algorithm>

using namespace std;

#define MAX 1000000

int n;



pair<int, int> T[MAX];



main(){

    int id, m, s;

    while( cin >> n && n ){

	for ( int i = 0; i < n; i++ ){

	    cin >> id;

	    int sum = 0;

	    for ( int j = 0; j < 4; j++ ){

		cin >> m >> s;

		sum += m*60 + s;

	    }

	    T[i] = make_pair(sum, id);

	}

	sort( T, T + n );



	cout << T[0].second << endl;

	cout << T[1].second << endl;

	cout << T[n-2].second << endl;

    }

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#define MAX 100000

#define INF (1<<21)



int id[MAX], total[MAX];

int n;



int searchMin(){

    int minv = INF;

    int target;

    for ( int i = 0; i < n; i++ ){

	if ( total[i] < 0 ) continue;

	if ( total[i] < minv ){

	    minv = total[i];

	    target = i;

	}

    }

    total[target] = -1;

    return id[target];

}



int searchMax(){

    int maxv = 0;

    int target;

    for ( int i = 0; i < n; i++ ){

	if ( total[i] < 0 ) continue;

	if ( total[i] > maxv ){

	    maxv = total[i];

	    target = i;

	}

    }

    total[target] = -1;

    return id[target];

}



main(){

    int m, s;

    while(1){

	scanf("%d", &n);

	if ( n == 0 ) break;

	for ( int i = 0; i < n; i++ ){

	    scanf("%d", &id[i]);

	    total[i] = 0;

	    for ( int j = 0; j < 4; j++ ){

		scanf("%d %d", &m, &s);

		total[i] += m*60+s;

	    }

	}



	printf("%d\n", searchMin());

	printf("%d\n", searchMin());

	searchMax();

	printf("%d\n", searchMax());

    }

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
// 基本テンプレート



#include <iostream>

#include <iomanip>

#include <cstdio>

#include <string>

#include <cstring>

#include <deque>

#include <list>

#include <queue>

#include <stack>

#include <vector>

#include <utility>

#include <algorithm>

#include <map>

#include <set>

#include <complex>

#include <cmath>

#include <limits>

#include <cfloat>

#include <climits>

#include <ctime>

#include <cassert>

#include <numeric>

#include <fstream>

#include <functional>

using namespace std;



#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)

#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)

#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)

#define int long long int



template<typename T> void chmax(T &a, T b) {a = max(a, b);}

template<typename T> void chmin(T &a, T b) {a = min(a, b);}

template<typename T> void chadd(T &a, T b) {a = a + b;}



typedef pair<int, int> pii;

typedef long long ll;



int dx[] = {0, 0, 1, -1};

int dy[] = {1, -1, 0, 0};

constexpr ll INF = 1001001001001001LL;

constexpr ll MOD = 1000000007LL;



signed main() {

    int N, M; cin >> N >> M;

    cout << ((M*1900 + (N-M)*100) << M) << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

using namespace std;

int main() {

    int N, M; scanf("%d%d", &N, &M);

    int submit_time = 100*N + 1800*M;

    printf("%d\n", submit_time * (1 << M));

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



typedef long long LL;



int N, M;

double t1 = 1900, t2 = 100;



void Solve()

{

  t1 *= M;

  double ans = 0;

  int a = (N - M) * t2;

  int p = 1 << M;

  double pp = 1;

  for (int i = 1; i <= 1000000; ++i) {

    ans += (a + t1) * i / p * pp;

    pp = pp * (p - 1) / p;

  }

  int ians = ans + 0.5;

  printf("%d\n", ians);

}



int main()

{

#ifdef linjian

freopen("in", "r", stdin);

#endif

  scanf("%d%d", &N, &M);

  Solve();

  return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;



typedef long long LL;



int N, M;



void Solve()

{

  int tot = 1900 * M + 100 * (N - M);

  int p = 1 << M;

  int ans = tot * p;

  printf("%d\n", ans);

}



int main()

{

#ifdef linjian

freopen("in", "r", stdin);

#endif

  scanf("%d%d", &N, &M);

  Solve();

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#define _USE_MATH_DEFINES

#include <algorithm>

#include <cstdio>

#include <functional>

#include <iostream>

#include <cfloat>

#include <climits>

#include <cstring>

#include <cmath>

#include <map>

#include <queue>

#include <set>

#include <sstream>

#include <stack>

#include <string>

#include <time.h>

#include <vector>

using namespace std;



typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> i_i;

typedef pair<ll, int> ll_i;

typedef pair<double, int> d_i;

typedef pair<ll, ll> ll_ll;

typedef pair<double, double> d_d;

struct edge { int u, v; ll w; };



ll MOD = 1000000007;

ll _MOD = 1000000009;

double EPS = 1e-10;



struct bit {

	vector<ll> v;

	bit(int n) : v(n + 1) {}

	ll sum(int i) {

		ll res = 0;

		for (; i > 0; i -= i & -i) res += v[i];

		return res;

	}

	void add(int i, ll x) {

		for (i++; i < v.size(); i += i & -i) v[i] += x;

	}

	int lower_bound(ll x) {

		if (x <= 0) return 0;

		int res = 0;

		for (int i = 1 << 24; i > 0; i >>= 1)

			if (res + i < v.size() && v[res + i] < x) {

				res += i; x -= v[res];

			}

		return res + 1;

	}

};



int main() {

	for (;;) {

		int n, k, m; cin >> n >> k >> m;

		if (n == 0) break;

		bit b(n);

		for (int i = 0; i < n; i++) b.add(i, 1);

		for (n--; n > 0; n--) {

			b.add(m - 1, -1);

			int x = (b.sum(m) + k) % n;

			if (x == 0) x = n;

			m = b.lower_bound(x);

		}

		cout << m << endl;

	}

}

// Optimized solution to the same problem (faster):
#define _USE_MATH_DEFINES

#include <algorithm>

#include <cstdio>

#include <functional>

#include <iostream>

#include <cfloat>

#include <climits>

#include <cstring>

#include <cmath>

#include <map>

#include <queue>

#include <set>

#include <sstream>

#include <stack>

#include <string>

#include <time.h>

#include <vector>

using namespace std;



typedef long long ll;

typedef unsigned long long ull;

typedef pair<int, int> i_i;

typedef pair<ll, int> ll_i;

typedef pair<double, int> d_i;

typedef pair<ll, ll> ll_ll;

typedef pair<double, double> d_d;

struct edge { int u, v; ll w; };



ll MOD = 1000000007;

ll _MOD = 1000000009;

double EPS = 1e-10;



int f(int n, int k) {

	return n == 1 ? 0 : 1 + (k - 1 + f(n - 1, k)) % (n - 1);

}



int main() {

	for (;;) {

		int n, k, m; cin >> n >> k >> m;

		if (n == 0) break;

		cout << 1 + (m - 1 + f(n, k)) % n << endl;

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define N 320

#define ll long long

using namespace std;

inline int read(){

	int x=0,f=1;char ch=getchar();

	while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());

	while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();

	return f?x:-x;

}

int cnt[N], a[N][N], ans = 1 << 30, at[N], del[N];

int main(int argc, char const *argv[]) {

	int n = read(), m = read();

	for (int i = 1; i <= n; i++)

		for (int j = 1; j <= m; j++)

			a[i][j] = read();

	for (int i = 1; i <= n; i++)

		cnt[a[i][at[i] = 1]] ++;

	for (int i = 1; i <= m; i++) {

		int * mx = max_element(cnt + 1, cnt + m + 1);

		ans = min(ans, * mx);

		// printf("%d %d %d %d %d\n", cnt[1], cnt[2], cnt[3], cnt[4], cnt[5]);

		// printf("it %d => del %d, %d\n", i, mx - cnt, *mx);

		if (i == m) break;

		del[mx - cnt] = 1;

		for (int j = 1; j <= n; j++) {

			cnt[a[j][at[j]]] --;

			while (del[a[j][at[j]]])

				++ at[j];

			cnt[a[j][at[j]]] ++;

		}

	}

	printf("%d\n", ans);

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;



template<typename T>

void input(T &x) {

	x=0; T a=1;

	register char c=getchar();

	for(;c<48||c>57;c=getchar())

		if(c==45) a=-1;

	for(;c>=48&&c<=57;c=getchar())

		x=x*10+c-48;

	x*=a;

	return;

}



#define MAXN 1010

#define MAXM 1010



int n,m;

int a[MAXN][MAXM];

int sum[MAXM];



namespace solve30 { //O(n*m*2^m)

	

	bool chose[15];



	void main() {

		for(int i=1;i<=n;i++)

			for(int j=1;j<=m;j++)

				input(a[i][j]),a[i][j]--;

		int ans=2147483647;

		for(int s=1;s<1<<m;s++) {

			for(int i=0;i<m;i++)

				if(s&(1<<i)) chose[i]=true;

			for(int i=1;i<=n;i++)

				for(int j=1;j<=m;j++)

					if(chose[a[i][j]]) {

						sum[a[i][j]]++;

						break;

					}

			int Max=0;

			for(int i=0;i<m;i++) {

				Max=max(Max,sum[i]),

				sum[i]=0,chose[i]=false;

			}

			ans=min(ans,Max);

		}

		printf("%d\n",ans);

		return;

	}



}



namespace solve70 { // O(n*m*log n)

	

	int cnt[MAXN];

	bool not_chose[MAXM];



	bool Judge(int mid) {

		memset(not_chose,0,sizeof(not_chose));

		for(int i=1;i<=n;i++) cnt[i]=1;

		while(true) {

			memset(sum,0,sizeof(sum));

			bool flag=true;

			for(int i=1;i<=n;i++) {

				for(;cnt[i]<=m&&not_chose[a[i][cnt[i]]];cnt[i]++);

				if(cnt[i]>m) return false;

				if(++sum[a[i][cnt[i]]]>mid)

					not_chose[a[i][cnt[i]]]=true,flag=false;

			}

			if(flag) return true;

		}

		return false;

	}



	void main() {

		for(int i=1;i<=n;i++)

			for(int j=1;j<=m;j++)

				input(a[i][j]);

		int l=1,r=n,ans;

		while(l<=r) {

			int mid=l+r>>1;

			if(Judge(mid)) ans=mid,r=mid-1;

			else l=mid+1;

		}

		printf("%d\n",ans);

		return;

	}



}



int main() {

//	freopen("sports.in","r",stdin),

//	freopen("sports.out","w",stdout),

	input(n),input(m);

	if(n<=10&&m<=10) solve30::main();

	else solve70::main();

//	fclose(stdin),fclose(stdout);

	return 0;

}


// Fastest known solution for this problem: