criyle/codenet-compile-errors huggingface dataset:
Language: Java

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[][] a = new int[n][m];
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < m; ++j) {
                    a[i][j] = in.nextInt() - 1;
                }
            }
            boolean[] used = new boolean[m];
            Arrays.fill(used, true);
            int ans = n;
            for (int step = 0; step < m; ++step) {
                int[] cnt = new int[m];
                for (int i = 0; i < n; ++i) {
                    int pos = 0;
                    while (pos < m && !used[a[i][pos]]) {
                        pos++;
                    }
                    if (pos == m) {
                        throw new RuntimeException();
                    }
                    cnt[a[i][pos]]++;
                }
                int pos = 0;
                for (int i = 1; i < m; ++i) {
                    if (cnt[i] > cnt[pos]) {
                        pos = i;
                    }
                }
                ans = Math.min(ans, cnt[pos]);
                used[pos] = false;
            }
            out.println(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }


Compiler output:
Main.java:104: error: reached end of file while parsing
        }
         ^
1 error
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <stack>
#include <queue>
using namespace std;
int main()
{
	int N, M;
	cin >> N >> M;
	int** arr = new int*[N];
	for (int i = 0; i < N; i++)
	{
		arr[i] = new int[M];
		for (int j = 0; j < M; j++)
		{
			int tmp;
			cin >> tmp;
			arr[i][j] = tmp;
		}
	}
 
	//init point
	int* point = new int[N];
	bool* deleted = new bool[N];
	for (int i = 0; i < N; i++)
	{
		point[i] = 0;
		deleted[i] = true;
	}
 
	//compute
	int min_people = 0x0fffffff;
 
	for (int i = 0; i < M; i++)
	{
		vector<int> people(M, 0);
		int max_people = -1;
		int max_event = -1;
		for (int j = 0; j < N; j++)
		{
			while (!deleted[arr[j][point[j]]-1])
				point[j]++;
			if (max_people < ++people[arr[j][point[j]] - 1])
			{
				max_people = people[arr[j][point[j]] - 1];
				max_event = arr[j][point[j]] - 1;
			}
		}
		min_people = min(min_people, max_people);
		deleted[max_event] = false;
	}
 
	cout << min_people << endl;
}

Compiler output:
a.cc:27:1: error: extended character   is not valid in an identifier
   27 |  
      | ^
a.cc:36:1: error: extended character   is not valid in an identifier
   36 |  
      | ^
a.cc:39:1: error: extended character   is not valid in an identifier
   39 |  
      | ^
a.cc:58:1: error: extended character   is not valid in an identifier
   58 |  
      | ^
a.cc: In function 'int main()':
a.cc:27:1: error: '\U000000a0' was not declared in this scope
   27 |  
      | ^
a.cc:33:17: error: 'point' was not declared in this scope
   33 |                 point[i] = 0;
      |                 ^~~~~
a.cc:36:2: error: expected ';' before 'int'
   36 |  
      |  ^
      |  ;
   37 |         //compute
   38 |         int min_people = 0x0fffffff;
      |         ~~~
a.cc:39:2: error: expected ';' before 'for'
   39 |  
      |  ^
      |  ;
   40 |         for (int i = 0; i < M; i++)
      |         ~~~
a.cc:40:25: error: 'i' was not declared in this scope
   40 |         for (int i = 0; i < M; i++)
      |                         ^
a.cc:58:2: error: expected ';' before 'cout'
   58 |  
      |  ^
      |  ;
   59 |         cout << min_people << endl;
      |         ~~~~
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <stack>
#include <queue>
using namespace std;
 
int main()
{
	int N, M;
	cin >> N >> M;
	int** arr = new int*[N];
	for (int i = 0; i < N; i++)
	{
		arr[i] = new int[M];
		for (int j = 0; j < M; j++)
		{
			int tmp;
			cin >> tmp;
			arr[i][j] = tmp;
		}
	}
 
	//init point
	int* point = new int[N];
	bool* deleted = new bool[N];
	for (int i = 0; i < N; i++)
	{
		point[i] = 0;
		deleted[i] = true;
	}
 
	//compute
	int min_people = 0x0fffffff;
 
	for (int i = 0; i < M; i++)
	{
		vector<int> people(M, 0);
		int max_people = -1;
		int max_event = -1;
		for (int j = 0; j < N; j++)
		{
			while (!deleted[arr[j][point[j]]-1])
				point[j]++;
			if (max_people < ++people[arr[j][point[j]] - 1])
			{
				max_people = people[arr[j][point[j]] - 1];
				max_event = arr[j][point[j]] - 1;
			}
		}
		min_people = min(min_people, max_people);
		deleted[max_event] = false;
	}
 
	cout << min_people << endl;
}

Compiler output:
a.cc:12:1: error: extended character   is not valid in an identifier
   12 |  
      | ^
a.cc:28:1: error: extended character   is not valid in an identifier
   28 |  
      | ^
a.cc:37:1: error: extended character   is not valid in an identifier
   37 |  
      | ^
a.cc:40:1: error: extended character   is not valid in an identifier
   40 |  
      | ^
a.cc:59:1: error: extended character   is not valid in an identifier
   59 |  
      | ^
a.cc:12:1: error: '\U000000a0' does not name a type
   12 |  
      | ^
Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#define SIZE 305

using namespace std;
bool vi[SIZE];
int cnt[SIZE];
int a[SIZE][SIZE];

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j];
	int ans = n;
	for (int i = 1; i <= m; i++) {
		memset(cnt, 0, sizeof(cnt));
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= m; k++) {
				if (!vi[a[j][k]]) {
					cnt[a[j][k]]++;
					break;
				}
			}
		}
		int index = -1;
		int n_max = -1;
		for (int j = 1; j <= m; j++) {
			if (cnt[j] > n_max) {
				n_max = cnt[j];
				index = j;
			}
		}
		ans = min(ans, n_max);
		vi[index] = true;
	}
	
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:18:17: error: 'memset' was not declared in this scope
   18 |                 memset(cnt, 0, sizeof(cnt));
      |                 ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <vector>
  +++ |+#include <cstring>
    4 | #define SIZE 305
Language: C++

#include <iostream>
#include <limits>

void solve(int a[310][310], int n, int m)
{
	int values[310] = { 0 }, maxRating, maxValues = 0, maxIndex = 0, ans = INT_MAX;
	bool visited[310] = { 0 };
	
	maxRating = m;
	while (maxRating--)
	{
//		std::cout << "\n";
		int values[310] = { 0 }, popularSport = 0, indexOfPopularSport = 0;
		for (int i = 0; i < n; ++i)
		{
			int chosenSport = INT_MAX, minOfChosenSport = INT_MAX;
			for (int j = 0; j < m; ++j)
			{
				if (!visited[a[i][j]])
				{
					if (j < chosenSport)
					{
						chosenSport = j;
						++values[a[i][j]];
						
						if (values[a[i][j]] > popularSport)
						{
							popularSport = values[a[i][j]];
							indexOfPopularSport = a[i][j];
						}
					}
				}
			}
		}
		
		if (popularSport < ans)
			ans = popularSport;
		
		visited[indexOfPopularSport] = true;
	}
	
	std::cout << ans;
}

int main()
{
	int n, m, a[310][310], values[310] = { 0 }, maxRating = INT_MAX, maxValues = 0, maxIndex = 0;
	bool visited[310] = { 0 };
	std::cin >> n >> m;
	
	maxRating = m;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			std::cin >> a[i][j];
			if (a[i][j] == maxRating)
				++values[i];
			if (values[i] > maxValues)
			{
				maxValues = values[i];
				maxIndex = maxValues;
			}
		}
	}
	
	solve(a, n, m);
}

Compiler output:
a.cc: In function 'void solve(int (*)[310], int, int)':
a.cc:6:80: error: 'INT_MAX' was not declared in this scope
    6 |         int values[310] = { 0 }, maxRating, maxValues = 0, maxIndex = 0, ans = INT_MAX;
      |                                                                                ^~~~~~~
a.cc:3:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    2 | #include <limits>
  +++ |+#include <climits>
    3 | 
a.cc: In function 'int main()':
a.cc:47:65: error: 'INT_MAX' was not declared in this scope
   47 |         int n, m, a[310][310], values[310] = { 0 }, maxRating = INT_MAX, maxValues = 0, maxIndex = 0;
      |                                                                 ^~~~~~~
a.cc:47:65: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc:59:41: error: 'maxValues' was not declared in this scope; did you mean 'values'?
   59 |                         if (values[i] > maxValues)
      |                                         ^~~~~~~~~
      |                                         values
a.cc:62:33: error: 'maxIndex' was not declared in this scope
   62 |                                 maxIndex = maxValues;
      |                                 ^~~~~~~~
Language: C++

//let's do it
 #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1000000000000
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define boost1 ios::sync_with_stdio(false);
#define boost2 cin.tie(0);
#define mem(a,val) memset(a,val,sizeof a)
#define endl "\n"
#define maxn 100001

int n,m,a[305][305],cnt[305],ban[305],ptr[305];

int ok(int limit)
{
	for(int i=1;i<=n;i++)
	ptr[i]=1;
	for(i=1;i<=m;i++)
	{
		cnt[i]=0;
		ban[i]=0;
	}
	while(1)
	{
		for(int i=1;i<=m;i++)
		cnt[i]=0;
		int f=1;
		for(int i=1;i<=n;i++)
		{
			if(ban[a[i][ptr[i]]])
			{
				f=0;
				break;
			}
			cnt[a[i][ptr[i]]]++;
		}
		for(int i=1;i<=m;i++)
		{
			if(cnt[i]>limit)
			{
				f=0;
				break;
			}
		}
		if(f)
		return 1;
		for(int i=1;i<=n;i++)
		{
			if(cnt[a[i][ptr[i]]]>limit)
			{
				ban[a[i][ptr[i]]]=1;
				ptr[i]++;
			}
			else if(ban[a[i][ptr[i]]])
			ptr[i]++;
		}
		for(int i=1;i<=n;i++)
		{
			if(ptr[i]>m)
			return 0;
		}
	}
}
int main()
{
	boost1;boost2;
	int i,j,lo,mid,hi;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=m;j++)
		cin>>a[i][j];
	}
	lo=0;
	hi=n;
	while(hi-lo>1)
	{
		mid=(lo+hi)/2;
		if(ok(mid))
		hi=mid;
		else
		lo=mid;
	}
	cout<<hi;
	return 0;
}


Compiler output:
a.cc: In function 'int ok(int)':
a.cc:25:13: error: 'i' was not declared in this scope
   25 |         for(i=1;i<=m;i++)
      |             ^
Language: C++

#include <iostream>
#include <limits>

void solve(int a[310][310], int n, int m)
{
	int values[310] = { 0 }, maxRating, maxValues = 0, maxIndex = 0, ans = INT_MAX;
	bool visited[310] = { 0 };
	
	maxRating = m;
	while (maxRating--)
	{
//		std::cout << "\n";
		int values[310] = { 0 }, popularSport = 0, indexOfPopularSport = 0;
		for (int i = 0; i < n; ++i)
		{
			int chosenSport = 0, maxOfChosenSport = 0;
			for (int j = 0; j < m; ++j)
			{
				if (a[i][j] > maxOfChosenSport && visited[j] == 0)
				{
					chosenSport = j;
					maxOfChosenSport = a[i][j];
				}
			}
			
//			std::cout << chosenSport << "\n";
			++values[chosenSport];
			if (values[chosenSport] > popularSport)
			{
				popularSport = values[chosenSport];
				indexOfPopularSport = chosenSport;
			}
		}
		
		if (popularSport < ans)
			ans = popularSport;
		
		visited[indexOfPopularSport] = true;
	}
	
	std::cout << ans;
}

int main()
{
	int n, m, a[310][310], values[310] = { 0 }, maxRating = INT_MAX, maxValues = 0, maxIndex = 0;
	bool visited[310] = { 0 };
	std::cin >> n >> m;
	
	maxRating = m;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			std::cin >> a[i][j];
			if (a[i][j] == maxRating)
				++values[i];
			if (values[i] > maxValues)
			{
				maxValues = values[i];
				maxIndex = maxValues;
			}
		}
	}
	
	solve(a, n, m);
}

Compiler output:
a.cc: In function 'void solve(int (*)[310], int, int)':
a.cc:6:80: error: 'INT_MAX' was not declared in this scope
    6 |         int values[310] = { 0 }, maxRating, maxValues = 0, maxIndex = 0, ans = INT_MAX;
      |                                                                                ^~~~~~~
a.cc:3:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    2 | #include <limits>
  +++ |+#include <climits>
    3 | 
a.cc: In function 'int main()':
a.cc:46:65: error: 'INT_MAX' was not declared in this scope
   46 |         int n, m, a[310][310], values[310] = { 0 }, maxRating = INT_MAX, maxValues = 0, maxIndex = 0;
      |                                                                 ^~~~~~~
a.cc:46:65: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc:58:41: error: 'maxValues' was not declared in this scope; did you mean 'values'?
   58 |                         if (values[i] > maxValues)
      |                                         ^~~~~~~~~
      |                                         values
a.cc:61:33: error: 'maxIndex' was not declared in this scope
   61 |                                 maxIndex = maxValues;
      |                                 ^~~~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;

const int N = 305;
int N,M;
int p[333][333];
int pnt[333];
bool invalid[333];
int c[333];
bool ok(int x){
	memset(invalid,0,sizeof(invalid));
	for(int i=1; i<=N; i++)pnt[i] = 1;

	while(1){
		bool flag = false;
		memset(c,0,sizeof(c));
		for(int i=1; i<=N; i++){
			while(pnt[i] <= M && invalid[p[i][pnt[i]]])pnt[i] ++;
			if(pnt[i] > M)return false;
			c[p[i][pnt[i]]] ++;
		}
		for(int i=1; i<=M; i++)
			if(c[i] > x){
				invalid[i] = true;
				flag = true;
			}
		if(!flag)return true;
	}
}
int main(){
	scanf("%d%d",&N,&M);
	for(int i=1; i<=N; i++)
		for(int j=1; j<=M; j++)
			scanf("%d",&p[i][j]);
	int lo = 1, hi = N;
	while(lo != hi){
		int mi = (lo + hi)/2;
		if(ok(mi))
			hi = mi;
		else
			lo = mi+1;
	}
	printf("%d\n",lo);
	return 0;
}


Compiler output:
a.cc:5:5: error: conflicting declaration 'int N'
    5 | int N,M;
      |     ^
a.cc:4:11: note: previous declaration as 'const int N'
    4 | const int N = 305;
      |           ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
int a[400][400];
int vis[400][400];
int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i = 0; i< n; i++)
    {
        int pos = 0, maxx = -1;
        for(int j = 0; j < m; j++)
        {
            scanf("%d", &a[i][j]);
            if(a[i][j] > maxx)
            {
                maxx = a[i][j];
                pos = j;
            }
        }
        vis[i][j] = 1;
    }

    int ans = 1;
    for(int j= 0; j < m; j++)
    {
        int cnt = 0;
        for(int i = 0; i < n; i++)
        {
            cnt += vis[i][j];
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:21:16: error: 'j' was not declared in this scope
   21 |         vis[i][j] = 1;
      |                ^
Language: C++

#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstdint>
using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> A(N, vector<int>(M, 0));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            cin >> A[i][j];
            // A[i][j] --;
        }
    }

    vector<bool> used(M, false);

    int ans = INT_MAX;
    for (int i = 0; i < M; ++i) {
        vector<int> num(M, 0);
        for (int j = 0; j < N; ++j) {
            int max_v = -1;
            int max_id = 0;
            for (int k = 0; k < M; ++k) {
                if (!used[k] && max_v < A[j][k]) {
                    max_v = A[j][k];
                    max_id = k;
                }
            }
            num[max_id]++;
        }
        auto it = max_element(num.begin(), num.end());
        int id = std::distance(num.begin(), it);
        int k = *it;
        // cout << id << ", " << k << endl;
        used[id] = true;
        ans = min(ans, k);
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:15: error: 'INT_MAX' was not declared in this scope
   22 |     int ans = INT_MAX;
      |               ^~~~~~~
a.cc:6:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    5 | #include <cstdint>
  +++ |+#include <climits>
    6 | using namespace std;
Language: C++

#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> A(N, vector<int>(M, 0));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            cin >> A[i][j];
            // A[i][j] --;
        }
    }

    vector<bool> used(M, false);

    int ans = INT_MAX;
    for (int i = 0; i < M; ++i) {
        vector<int> num(M, 0);
        for (int j = 0; j < N; ++j) {
            int max_v = -1;
            int max_id = 0;
            for (int k = 0; k < M; ++k) {
                if (!used[k] && max_v < A[j][k]) {
                    max_v = A[j][k];
                    max_id = k;
                }
            }
            num[max_id]++;
        }
        auto it = max_element(num.begin(), num.end());
        int id = std::distance(num.begin(), it);
        int k = *it;
        // cout << id << ", " << k << endl;
        used[id] = true;
        ans = min(ans, k);
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:15: error: 'INT_MAX' was not declared in this scope
   21 |     int ans = INT_MAX;
      |               ^~~~~~~
a.cc:5:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    4 | #include <algorithm>
  +++ |+#include <climits>
    5 | using namespace std;
Language: C++

#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> A(n, vector<int>(m, 0));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> A[i][j];
            A[i][j] --;
        }
    }

    vector<bool> used(m, false);

    int ans = n;
    for (int i = 0; i < m; ++i)
    {
        vector<int> num(m, 0);
        for (int j = 0; j < n; ++j) {
            int max_v = -1;
            int max_id = 0;
            for (int k = 0; k < m; ++k) {
                if (!used[k] && max_v < A[j][k]) {
                    max_v = A[j][k];
                    max_id = k;
                }
            }
            num[max_id]++;
        }
        auto it = max_element(num.begin(), num.end());
        int id = std::distance(num.begin(), it);
        int k = *it;
        // cout << id << ", " << k << endl;
        used[id] = true;
        ans = min(ans, k);
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:35:19: error: 'max_element' was not declared in this scope
   35 |         auto it = max_element(num.begin(), num.end());
      |                   ^~~~~~~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
 
int n,m,ans = 1e9,cnt[303];
vector<priority_queue<pair<int,int> > > v(303);
set<int> del;
 
int main(){
    cin >> n >> m;
    for(int i = 0;i < n;++i){
        for(int j = 0, x;j < m;++j){
            scanf("%d",&x);
            v[i].push({m-j,x});
        }
    }
    for(int k = 0;k < m;++k){
        memset(cnt,0,sizeof cnt);
        int mx = 0, nxt;
        for(int i = 0;i < n;++i){
            auto t = v[i].top();
            while(del.count(t.second)){
                v[i].pop();
                t = v[i].top();
            }
            cnt[t.second]++;
            if(cnt[t.second] > mx){
                mx = cnt[t.second];
                nxt = t.second;
            }
        }
        ans = min(ans,mx);
        del.insert(nxt);
    }
    cout << ans << endl;
 
    return 0;
}

Compiler output:
a.cc:3:1: error: extended character   is not valid in an identifier
    3 |  
      | ^
a.cc:7:1: error: extended character   is not valid in an identifier
    7 |  
      | ^
a.cc:35:1: error: extended character   is not valid in an identifier
   35 |  
      | ^
a.cc:3:1: error: '\U000000a0' does not name a type
    3 |  
      | ^
a.cc:7:1: error: '\U000000a0' does not name a type
    7 |  
      | ^
Language: C++

#include<stdio.h>
#include <iostream>
#include <vector>
#define MAX_N 200
#define MAX_M 300


using namespace std;
int N, M;
int A[MAX_N+1][MAX_M+1] = {};

int c[MAX_M+1][MAX_M+1] = {};

int calc(int dim, int aray[dim]){
	int result[dim];
	for(int i=0; i <dim; i++){
		result[i] = 0;
	}

	for(int n_ind=0; n_ind < N; n_ind++){
		for(int m_ind=0; m_ind < M; m_ind++){
			bool isFound = false;
			for(int aray_ind=0; aray_ind < dim; aray_ind++){
				if(A[n_ind][m_ind] == aray[aray_ind]){
					result[aray_ind] ++;
					isFound = true;
					break;
				}
			}

			if(isFound)break;
		}
	}

	int max = 0;
	for(int i=0; i < dim; i++){
		//printf("res:%d\n", result[i]);
		if(max < result[i]) max = result[i];
	}

	return max;
}

void solve() {
	cin >> N ;
	cin >> M;

	vector<int> sports(M+1);
	for(int i=0; i<M; i++){
		sports[i] = i+1;
	}

	for(int n_ind=0; n_ind < N; n_ind++){
		for(int m_ind=0; m_ind < M; m_ind++){
			int tmp;
			cin >>tmp;
			 A[n_ind][m_ind] = tmp;
			(c[m_ind][ tmp ] )++;	//m番目に好きなものを種類別にカウント
		}
	}

	vector<int> erased(M+1, 0);
	int min_max = calc(sports.size(),&sports.front());
	for(int m_ind=0; m_ind < M; m_ind++){
		int sports_ind = -1;
		int max_count =0 ;
		//最大のスポーツを探し外す
		for(int i=1; i<M+1; i++){
			if(max_count < c[m_ind][i]){
				sports_ind = i -1;
				max_count = c[m_ind][i];
			}
		}

		bool isFound1=false;
		//printf("tag:%d :", sports_ind +1);
		for(int erase_ind=0; erase_ind<sports.size(); erase_ind++){
			//printf("%d ", sports[erase_ind]);
			if(sports[erase_ind] == sports_ind+1) {
				sports_ind = erase_ind;
				isFound1 = true;
			}
		}
		//printf("\n ");

		if(isFound1)sports[sports_ind] = 0;//削除
		int temp =  calc(sports.size(),&sports.front());
		if(min_max > temp && temp != 0) min_max= temp;	//最小値更新
	}
	printf("%d\n", min_max);
}


int main(void) {
	solve();
	return 0;
}


Compiler output:
a.cc:14:31: error: use of parameter outside function body before ']' token
   14 | int calc(int dim, int aray[dim]){
      |                               ^
a.cc: In function 'int calc(...)':
a.cc:15:20: error: 'dim' was not declared in this scope; did you mean 'div'?
   15 |         int result[dim];
      |                    ^~~
      |                    div
a.cc:17:17: error: 'result' was not declared in this scope
   17 |                 result[i] = 0;
      |                 ^~~~~~
a.cc:24:55: error: 'aray' was not declared in this scope
   24 |                                 if(A[n_ind][m_ind] == aray[aray_ind]){
      |                                                       ^~~~
a.cc:25:41: error: 'result' was not declared in this scope
   25 |                                         result[aray_ind] ++;
      |                                         ^~~~~~
a.cc:38:26: error: 'result' was not declared in this scope
   38 |                 if(max < result[i]) max = result[i];
      |                          ^~~~~~
Language: C++

#include<stdio.h>
#include <iostream>
#include <vector>
#define MAX_N 200
#define MAX_M 300


using namespace std;
int N, M;
int A[MAX_N+1][MAX_M+1] = {};

int c[MAX_M+1][MAX_M+1] = {};
int calc(int dim, int aray[dim]);

void solve() {
	cin >> N ;
	cin >> M;

	vector<int> sports(M+1);
	for(int i=0; i<M; i++){
		sports[i] = i+1;
	}

	for(int n_ind=0; n_ind < N; n_ind++){
		for(int m_ind=0; m_ind < M; m_ind++){
			int tmp;
			cin >>tmp;
			 A[n_ind][m_ind] = tmp;
			(c[m_ind][ tmp ] )++;	//m番目に好きなものを種類別にカウント
		}
	}

	vector<int> erased(M+1, 0);
	int min_max = calc(sports.size(),&sports.front());
	for(int m_ind=0; m_ind < M; m_ind++){
		int sports_ind = -1;
		int max_count =0 ;
		//最大のスポーツを探し外す
		for(int i=1; i<M+1; i++){
			if(max_count < c[m_ind][i]){
				sports_ind = i -1;
				max_count = c[m_ind][i];
			}
		}

		bool isFound1=false;
		//printf("tag:%d :", sports_ind +1);
		for(int erase_ind=0; erase_ind<sports.size(); erase_ind++){
			//printf("%d ", sports[erase_ind]);
			if(sports[erase_ind] == sports_ind+1) {
				sports_ind = erase_ind;
				isFound1 = true;
			}
		}
		//printf("\n ");

		if(isFound1)sports[sports_ind] = 0;//削除
		int temp =  calc(sports.size(),&sports.front());
		if(min_max > temp && temp != 0) min_max= temp;	//最小値更新
	}
	printf("%d\n", min_max);
}

int calc(int dim, int aray[dim]){
	int result[dim];
	for(int i=0; i <dim; i++){
		result[i] = 0;
	}

	for(int n_ind=0; n_ind < N; n_ind++){
		for(int m_ind=0; m_ind < M; m_ind++){
			bool isFound = false;
			for(int aray_ind=0; aray_ind < dim; aray_ind++){
				if(A[n_ind][m_ind] == aray[aray_ind]){
					result[aray_ind] ++;
					isFound = true;
					break;
				}
			}

			if(isFound)break;
		}
	}

	int max = 0;
	for(int i=0; i < dim; i++){
		//printf("res:%d\n", result[i]);
		if(max < result[i]) max = result[i];
	}

	return max;
}

int main(void) {
	solve();
	return 0;
}


Compiler output:
a.cc:13:31: error: use of parameter outside function body before ']' token
   13 | int calc(int dim, int aray[dim]);
      |                               ^
a.cc:64:31: error: use of parameter outside function body before ']' token
   64 | int calc(int dim, int aray[dim]){
      |                               ^
a.cc: In function 'int calc(...)':
a.cc:65:20: error: 'dim' was not declared in this scope; did you mean 'div'?
   65 |         int result[dim];
      |                    ^~~
      |                    div
a.cc:67:17: error: 'result' was not declared in this scope
   67 |                 result[i] = 0;
      |                 ^~~~~~
a.cc:74:55: error: 'aray' was not declared in this scope
   74 |                                 if(A[n_ind][m_ind] == aray[aray_ind]){
      |                                                       ^~~~
a.cc:75:41: error: 'result' was not declared in this scope
   75 |                                         result[aray_ind] ++;
      |                                         ^~~~~~
a.cc:88:26: error: 'result' was not declared in this scope
   88 |                 if(max < result[i]) max = result[i];
      |                          ^~~~~~
Language: C++

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define For(i,a,b) for(int i=(int)a;i<=(int)b;++i)
#define Fordown(i,a,b) for(int i=(int)a;i>=(int)b;--i)
#define re read()
#define maxn 300+10
#define inf 2100000000
#define mem(a,b)memset(a,b,sizeof(a))
#define ll long long
int n,m;
int a[maxn][maxn];
int b[maxn],bb[maxn];
inline int read()
{
    int flag=1,ans=0;
    char ch=getchar();
    while(!isdigit(ch)&&ch!='-')ch=getchar();
    if(ch=='-'){flag=-1;ch=getchar();}
    while(isdigit(ch)){ans=(ans<<3)+(ans<<1)+(ch-'0');ch=getchar();}
    return ans*flag;
}
struct node
{
	int id,sum;
	node(){sum=0;}
}e[maxn];
void init()
{
	n=re;m=re;
	For(i,1,m)e[i].id=i;
	For(i,1,n)
	{
		For(j,1,m)
		{
			a[i][j]=re;
			e[a[i][j]].sum+=j;
		}
	}
}
bool cmp(node a,node b){return a.sum>=b.sum;}
int cal()
{
	int ans=0;
	mem(bb,0);
	For(i,1,n)
	{
		For(j,1,m)
		{
			if(b[a[i][j]])
			{
				bb[a[i][j]]++;
				ans=max(bb[a[i][j]],ans);
				break;
			}
		}
	}
	return ans;
}
void work()
{4 5
5 1 3 4 2
2 5 3 1 4
2 3 1 4 5
2 5 4 3 1
	int ans=n+1;
	sort(e+1,e+m+1,cmp);
	For(i,1,m)
	{
		b[e[i].id]=1;
		ans=min(ans,cal());
	}
	printf("%d\n",ans);
}
int main()
{
	init();
	work();
	return 0;
}


Compiler output:
a.cc: In function 'void work()':
a.cc:70:3: error: expected ';' before numeric constant
   70 | {4 5
      |   ^~
      |   ;
a.cc:80:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   80 |                 ans=min(ans,cal());
      |                 ^~~
      |                 abs
a.cc:82:23: error: 'ans' was not declared in this scope; did you mean 'abs'?
   82 |         printf("%d\n",ans);
      |                       ^~~
      |                       abs
Language: C++

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
#include <random>
using namespace std;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;
 
int N,M;
int A[310][310];
int cnt[310];
bool sports[310];
 
int main() {
 
    cin >> N >> M;
    REP(i,N) REP(j,M) cin >> A[i][j];
    REP(i,N) REP(j,M) A[i][j]--;
    REP(i,310) sports[i] = true;
 
    //---
    int ans = 0;
 
    REP(i,310) cnt[i] = 0;
    REP(i,N) cnt[A[i][0]]++;
 
    REP(i,M) ans = max(ans,cnt[i]);
    //---
 
    while (true && limit > 1) {
        REP(i,310) cnt[i] = 0;
        REP(i,N) {
            int pri = 1e9;
            int idx = -1;
            REP(j,M) {
                if(!sports[j]) continue;
                if(pri > A[i][j]) {
                    idx = j;
                    pri = A[i][j];
                }
            }
            cnt[idx]++;
        }
 
        int maxs = -1;
        int spo = -1;
        REP(i,M) {
            if(maxs < cnt[i]) {
                spo = i;
                maxs = cnt[i];
            }
        }
 
       // cout << maxs << " " << spo << endl;
 
        sports[spo] = false;
 
        // -----
        REP(i,310) cnt[i] = 0;
        REP(i,N) {
            int pri = 1e9;
            int idx = -1;
            REP(j,M) {
                if(!sports[j]) continue;
                if(pri > A[i][j]) {
                    idx = j;
                    pri = A[i][j];
                }
            }
            cnt[idx]++;
        }
 
        int sum = 0;
        REP(i,M) sum += cnt[i];
        if(sum != N) break;
 
        // ----
 
        int anst = 0;
        REP(i,M) anst = max(anst,cnt[i]);
        ans = min(ans,anst);
 
    }
 
    cout << ans << endl;
 
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:44:20: error: 'limit' was not declared in this scope
   44 |     while (true && limit > 1) {
      |                    ^~~~~
Language: C++

#include <vector>
#include <string>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <queue>
#include <deque>
#include <iostream>
#include <cstdio>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1 ; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define FILL(a,b) memset(a , b , sizeof(a))
#define SZ(a) (int)a.size()
#define PB push_back
#define MP make_pair

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAX = 307;
const int INF = 1000000000;

int A[MAX][MAX];
int cnt[MAX];
int d[MAX];

int main()
{
	//freopen("in.txt" , "r" , stdin);


	int n , m;
	cin >> n >> m;
	FOR(i,0,n)
	{
		FOR(j,0,m)
		{
			cin >> A[i][j];
			-- A[i][j];
		}
	}

	int res = INF;

	FOR(it,0,m)
	{
		FILL(cnt , 0);
		FOR(i,0,n)
		{
			FOR(j,0,m)
			{
				if (!d[A[i][j]])
				{
					cnt[A[i][j]] ++ ;
					break;
				}
			}
		}
		int mx = -1;
		int id;
		FOR(i,0,m)
		{
			if (cnt[i] > mx)
			{
				mx = cnt[i];
				id = i;
			}
		}

		res = min(res , mx);
		d[id] = 1;
	}

	cout << res << endl;



}


Compiler output:
a.cc: In function 'int main()':
a.cc:17:19: error: 'memset' was not declared in this scope
   17 | #define FILL(a,b) memset(a , b , sizeof(a))
      |                   ^~~~~~
a.cc:53:17: note: in expansion of macro 'FILL'
   53 |                 FILL(cnt , 0);
      |                 ^~~~
a.cc:11:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   10 | #include <cstdio>
  +++ |+#include <cstring>
   11 |
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int val[310][310];
int main(){
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cin >> r;
			val[i][r] = j+1;
		}
	}
	int ans = 100000;
	int used[310];
	for(int z = 0; z < m; z++){
		used[z] = 1;
	}
	for(int z = 0; z < m; z++){
		int freq[310];
		for(int j = 0; j < m; j++){
			freq[j] = 0;
		}
		for(int i = 0; i < n; i++){
			int best = -1;
			for(int j = 0; j < m; j++){
				if(used[j] && (best == -1 || val[i][j] > val[i][best])){
					best = j;
				}
			}
			freq[best]++;
		}
		int sbest = -1;
		for(int j = 0; j < m; j++){
			if(used[j] && (sbest == -1 || freq[j] > freq[sbest])){
				sbest = j;
			}
		}

		ans = min(ans, freq[sbest]);

		used[sbest] = 0;
	}
	cout << ans << endl;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:10:32: error: 'r' was not declared in this scope
   10 |                         cin >> r;
      |                                ^
Language: C++

            if (t && t <= m) {
                m = t;
                best = g;
            }
        }
        if (best < 0) {
            cout << m << endl;
            break;
        }
        // cout << "remove " << best  << " because " << m << endl;
        games.erase(best);
    }
}


Compiler output:
a.cc:1:13: error: expected unqualified-id before 'if'
    1 |             if (t && t <= m) {
      |             ^~
a.cc:5:9: error: expected declaration before '}' token
    5 |         }
      |         ^
a.cc:6:9: error: expected unqualified-id before 'if'
    6 |         if (best < 0) {
      |         ^~
a.cc:11:9: error: 'games' does not name a type
   11 |         games.erase(best);
      |         ^~~~~
a.cc:12:5: error: expected declaration before '}' token
   12 |     }
      |     ^
a.cc:13:1: error: expected declaration before '}' token
   13 | }
      | ^
Language: C++

#include<cstdio>
#include<iostream>
using namespace std;
int n,m,maxn,minn=400,k;
int a[305][305];
int t[305];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	scanf("%d",&a[i][j]);
	for(int i=1;i<=m;i++)
	{
		memset(t,0,sizeof(t));
		maxn=0;
		for(int j=1;j<=n;j++)
		{
			//p=i;
			//while(a[j][p]==0)p++;
			t[a[j][i]]++;
			if(t[a[j][i]]>maxn)maxn=t[a[j][i]],k=a[j][i];
		}
		for(int ii=1;ii<=n;ii++)
		for(int jj=1;jj<=m;jj++)
		{
			if(a[ii][jj]==k)
			a[ii][jj]=a[ii][jj+1];
		}
		//del++;
		minn=min(minn,maxn);
	}
	cout<<minn<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:17: error: 'memset' was not declared in this scope
   15 |                 memset(t,0,sizeof(t));
      |                 ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include<iostream>
  +++ |+#include <cstring>
    3 | using namespace std;
Language: C++

#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>

#define P 1000000007

using namespace std;

class Node {
public:
  int id, sum;
  Node(int i, int s) {
    id = i;
    sum = s;
  }
  bool operator<(const Node &rhs) const {
    return this->sum > rhs.sum;
  }
  bool operator>(const Node &rhs) const {
    return this->sum < rhs.sum;
  }
};

vector<bool> b;
int n, m;
vector<vector<int>> a;
vector<int> cnt;

int f(int id) {
  vector<Node> nd;
  for(int j = 0; j < m; j++) {
    Node nds(j, 0);
    nd.push_back(nds);
  }
  for(int j = 0; j < n; j++) {
    if(a[j][cnt[j]] == id) {
      nd[a[j][cnt[j] + 1]].sum++;
    } else {
      nd[a[j][cnt[j]]].sum++;
    }
  }
  sort(nd.begin(), nd.end());
  return nd[0].sum;
}

int main() {
  cin >> n >> m;
  a.resize(n);
  cnt.resize(n);
  b.resize(n);
  for(int i = 0; i < n; i++) {
    a[i].resize(m);
    b[i] = true;
    for(int j = 0; j < m; j++){
      cin >> a[i][j];
      a[i][j]--;
    }
  }

  int ans = n;

  for(int i = 0; i < m - 1; i++) {
    vector<Node> nd;
    for(int j = 0; j < m; j++) {
      Node nds(j, 0);
      nd.push_back(nds);
    }
    for(int j = 0; j < n; j++) {
      nd[a[j][cnt[j]]].sum++;
    }
    sort(nd.begin(), nd.end());
    ans = min(ans, nd[0].sum);

    int c == nd[0].sum, id = nd[0].id, mm = f(nd[0].id);

    for(int j = 1; j < m && nd[j].sum == c; j++) {
      int d = f(nd[j].id);
      if(d < mm) {
        mm = d;
        id = nd[j].id;
      }
    }
    if(mm > ans) {
      break;
    }
    b[id] = false;
    for(int j = 0; j < n; j++) {
      if(a[j][cnt[j]] == id) {
        cnt[j]++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:81:11: error: expected initializer before '==' token
   81 |     int c == nd[0].sum, id = nd[0].id, mm = f(nd[0].id);
      |           ^~
a.cc:83:42: error: 'c' was not declared in this scope
   83 |     for(int j = 1; j < m && nd[j].sum == c; j++) {
      |                                          ^
a.cc:85:14: error: 'mm' was not declared in this scope; did you mean 'tm'?
   85 |       if(d < mm) {
      |              ^~
      |              tm
a.cc:87:9: error: 'id' was not declared in this scope; did you mean 'd'?
   87 |         id = nd[j].id;
      |         ^~
      |         d
a.cc:90:8: error: 'mm' was not declared in this scope; did you mean 'tm'?
   90 |     if(mm > ans) {
      |        ^~
      |        tm
a.cc:93:7: error: 'id' was not declared in this scope; did you mean 'nd'?
   93 |     b[id] = false;
      |       ^~
      |       nd
Language: C++

#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>

#define P 1000000007

using namespace std;

class Node {
public:
  int id, sum;
  Node(int i, int s) {
    id = i;
    sum = s;
  }
  bool operator<(const Node &rhs) const {
    return this->sum > rhs.sum;
  }
  bool operator>(const Node &rhs) const {
    return this->sum < rhs.sum;
  }
};

vector<bool> b;
int n, m;
vector<vector<int>> a;
vector<int> cnt;

int f(int id) {
  vector<Node> nd;
  for(int j = 0; j < m; j++) {
    Node nds(j, 0);
    nd.push_back(nds);
  }
  for(int j = 0; j < n; j++) {
    if(a[j][cnt[j]] == id) {
      nd[a[j][cnt[j] + 1]].sum++;
    } else {
      nd[a[j][cnt[j]]].sum++;
    }
  }
  sort(nd.begin(), nd.end());
  return nd[0].sum;
}

int main() {
  cin >> n >> m;
  a.resize(n);
  cnt.resize(n);
  b.resize(n);
  for(int i = 0; i < n; i++) {
    a[i].resize(m);
    b[i] = true;
    for(int j = 0; j < m; j++){
      cin >> a[i][j];
      a[i][j]--;
    }
  }

  int ans = n;

  for(int i = 0; i < m - 1; i++) {
    vector<Node> nd;
    for(int j = 0; j < m; j++) {
      Node nds(j, 0);
      nd.push_back(nds);
    }
    for(int j = 0; j < n; j++) {
      nd[a[j][cnt[j]]].sum++;
    }
    sort(nd.begin(), nd.end());
    ans = min(ans, nd[0].sum);

    int id = nd[0].id, mm = f(nd[0].id);

    for(int j = 1; j < m && nd[j].sum == c; j++) {
      int d = f(nd[j].id);
      if(d < mm) {
        mm = d;
        id = nd[j].id;
      }
    }
    if(mm > ans) {
      break;
    }
    b[id] = false;
    for(int j = 0; j < n; j++) {
      if(a[j][cnt[j]] == id) {
        cnt[j]++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:83:42: error: 'c' was not declared in this scope
   83 |     for(int j = 1; j < m && nd[j].sum == c; j++) {
      |                                          ^
Language: C++

#include <iostream>
#include <algorithm>
using namespace std;

int N, M;
int A[305][305];
int B[305];
bool removed[305];

int main()
{
    cin >> N >> M;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            cin >> A[i][j];
            A[i][j] --;
        }
    }

    // int ans = *max_element(B+1, B+1+M);
    int ans = INT_MAX;
    for (int m = 0; m < M; ++m)
    {
        for (int j = 0; j < M; ++j) {
            B[j] = 0;
        }
        for (int n = 0; n < N; ++n)
        {
            int max_idx = 0;
            int max_v = -1;
            for (int j = 0; j < M; ++j)
            {
                if (!removed[j] && max_v < A[n][j])
                {
                    max_v = A[n][j];
                    max_idx = j;
                }
            }
            B[max_idx] ++;
        }
        auto it = max_element(B, B+M);
        int idx = std::distance(B, it);
        int k = *it;
        // cout << idx << ", " << k << endl;
        removed[idx] = true;
        ans = min(ans, k);
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:21:15: error: 'INT_MAX' was not declared in this scope
   21 |     int ans = INT_MAX;
      |               ^~~~~~~
a.cc:3:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    2 | #include <algorithm>
  +++ |+#include <climits>
    3 | using namespace std;
Language: C++

#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

bool test(int N, int M, const vector<vector<int>>& A, int k)
{
    vector<bool> used(M, false);

    vector<vector<int>::const_iterator> ps(N);
    vector<vector<int>::const_iterator> ends(N);
    for (int i = 0; i < N; ++i) {
        ps[i] = A[i].begin();
        ends[i] = A[i].end();
    }

    while (true) {
        vector<int> cnt(M);
        for (int i = 0; i < N; ++i) {
            if (ps[i] != ends[i])
                ++cnt[*ps[i]];
        }

        vector<pair<int, int>> rank;
        for (int i = 0; i < M; ++i) {
            rank.push_back(make_pair(cnt[i], i));
        }
        sort(rank.begin(), rank.end(), greater<pair<int, int>>());

        if (rank[0].first > k) {
            for (auto pr : rank) {
                int c = pr.first;
                int i = pr.second;
                if (c <= k)
                    break;
                used[i] = true;
            }

            for (int i = 0; i < N; ++i) {
                if (ps[i] == ends[i])
                    continue;

                while (ps[i] != ends[i] && used[*ps[i]])
                    ++ps[i];
                if (ps[i] == ends[i])
                    return false;
            }
        } else {
            break;
        }
    }

    return true;
}

int main()
{
    int N, M;
    cin >> N >> M;

    vector<vector<int>> A(N, vector<int>(M));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            cin >> A[i][j];
            --A[i][j];
        }
    }

    int mn = 0;
    int mx = 300;
    while (mx - mn > 1) {
        int mid = (mn + mx) / 2;
        if (test(N, M, A, mid))
            mx = mid;
        else
            mn = mid;
    }

    cout << mx << '\n';

    return 0;
}


Compiler output:
a.cc: In function 'bool test(int, int, const std::vector<std::vector<int> >&, int)':
a.cc:35:9: error: 'sort' was not declared in this scope; did you mean 'short'?
   35 |         sort(rank.begin(), rank.end(), greater<pair<int, int>>());
      |         ^~~~
      |         short
Language: C++

#include <iostream>
using namespace std;

int N, M;
int A[301][301];
int B[301];
bool removed[301];

int main()
{
    cin >> N >> M;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            cin >> A[i][j];
            if (A[i][j] == M)
                B[j]++;
        }
    }

    int ans = *max_element(B+1, B+1+M);
    for (int m = 0; m < M-1; ++m)
    {
        auto it = max_element(B+1, B+1+M);
        int idx = std::distance(B, it);
        int k = *it;
        // cout << k << endl;
        removed[idx] = true;
        ans = min(ans, k);
        for (int j = 1; j <= M; ++j) {
            B[j] = 0;
        }
        for (int n = 0; n < N; ++n)
        {
            int max_idx = 0;
            int max_v = 0;
            for (int j = 1; j <= M; ++j)
            {
                if (!removed[j] && max_v < A[n][j])
                {
                    max_v = A[n][j];
                    max_idx = j;
                }
            }
            B[max_idx] ++;
        }
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:20:16: error: 'max_element' was not declared in this scope
   20 |     int ans = *max_element(B+1, B+1+M);
      |                ^~~~~~~~~~~