criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <cstdio>
#include <string>
#include <utility>
#include <queue>
using namespace std;

typedef pair<int, string> P;

int main()
{
    char worm[32];

    while (scanf("%s", worm), *worm != '0'){
        queue<P> que;
        set<string> exist;

        for (que.push(P(0, string(worm))); que.size(); que.pop()){
            P tmp = que.front();
            string s = tmp.second;
            bool flag = true;

            for (int i = 0; i < s.length() - 1; i++){
                string t = s;

                if (t[i] != t[i + 1]){
                    flag = false;
                    if (t[i] != 'r' && t[i + 1] != 'r'){
                        t[i] = t[i + 1] = 'r';
                    }
                    else if (t[i] != 'g' && t[i + 1] != 'g'){
                        t[i] = t[i + 1] = 'g';
                    }
                    else {
                        t[i] = t[i + 1] = 'b';
                    }
                    que.push(P(tmp.first + 1, t));
                }
            }
            if (flag){
                printf("%d\n", tmp.first);
                break;
            }
        }
        if (que.empty()){
            puts("NA");
        }
    }

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:15:9: error: 'set' was not declared in this scope
   15 |         set<string> exist;
      |         ^~~
a.cc:5:1: note: 'std::set' is defined in header '<set>'; this is probably fixable by adding '#include <set>'
    4 | #include <queue>
  +++ |+#include <set>
    5 | using namespace std;
a.cc:15:19: error: expected primary-expression before '>' token
   15 |         set<string> exist;
      |                   ^
a.cc:15:21: error: 'exist' was not declared in this scope; did you mean 'exit'?
   15 |         set<string> exist;
      |                     ^~~~~
      |                     exit
Language: C++

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
#include <queue>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}
typedef pair<string ,int> P;

int bfs(string s){
  queue<P> que;
  que.push(P(s,0));
  
  map<string,int> d;
  while(!que.empty()){
    P p=que.front();
    que.pop();
    
    if(d[p.first])continue;
    string st = p.first;
    
    bool f = false;
    rep(i,st.size()-1){
      if(st[i]!=st[i+1]){ // find different words
	f = true;
	break;
      }
    }

    if(!f)return p.second;
    
    d[p.first] = second;
    rep(i,st.size()-1){
      if(st[i] != st[i+1]){
	char t;
	string nx;
      }
    }
    
  }
  
}

int main(void){
  string s;
  while(cin>>s,s!="0"){
    int ret = bfs(s);
    if(ret>=0)cout<<ret<<endl;
    else cout<<"NA"<<endl;
  }
}

Compiler output:
a.cc: In function 'int bfs(std::string)':
a.cc:50:18: error: 'second' was not declared in this scope
   50 |     d[p.first] = second;
      |                  ^~~~~~
a.cc:60:1: warning: control reaches end of non-void function [-Wreturn-type]
   60 | }
      | ^
Language: C++

#include <bits/stdc++.h>

using namespace std;

typedef pair<string, int> P;

//????????????????????????????????????
bool judge(string str) {
	for (int i = 0; i < str.size(); ++i) {
		if (str[0] != str[i]) return false;
	}
	return true;
}

//??£?????????2?????????????????§?????????????????????
char color(char a, char b){
	if((a == 'g' && b == 'r') || (a == 'r' && b == 'g'))return 'b';
	else if((a == 'b' && b == 'r') || (a == 'r' && b == 'b')) return 'g';
	else if((a == 'g' && b == 'b') || (a == 'b' && b == 'g')) return 'r';
}

int solve(string s ){

	queue<P> q;
	map<string, int> m;
	q.push(P(s, 0));	//?????\??????????????¶????????\??????
	if(m[p.first]) continue;	//??????????????????

	while (!q.empty()) {	//?????\??????????????¶?????????????????§
		P p = q.front();
		q.pop();
		string now = p.first;
		if (judge(now)) return p.second;
		for (int i = 0; i < now.size() - 1; ++i) {
			if (now[i] != now[i+1]){	//??£?????????2????????°????????¨???
				char tmp = color(now[i], now[i + 1]);
				string D = now;
				D[i] = tmp;
				D[i + 1] = tmp;
				q.push(P(D, p.second + 1));
			}
		}
	}
	return -1;
}

int main() {
	string worm;
	while (cin >> worm) {
		if (worm == "0") break;
		int count = solve(worm);
		if (count == -1) cout << "NA" << endl;
		else cout << count << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int solve(std::string)':
a.cc:27:14: error: 'p' was not declared in this scope
   27 |         if(m[p.first]) continue;        //??????????????????
      |              ^
a.cc:27:24: error: continue statement not within a loop
   27 |         if(m[p.first]) continue;        //??????????????????
      |                        ^~~~~~~~
a.cc: In function 'char color(char, char)':
a.cc:20:1: warning: control reaches end of non-void function [-Wreturn-type]
   20 | }
      | ^
Language: C++

#include <bits/stdc++.h>

using namespace std;

typedef pair<string, int> P;

//????????????????????????????????????
bool judge(string str) {
	for (int i = 0; i < str.size(); ++i) {
		if (str[0] != str[i]) return false;
	}
	return true;
}

//??£?????????2?????????????????§?????????????????????
char color(char a, char b){
	if((a == 'g' && b == 'r') || (a == 'r' && b == 'g'))return 'b';
	else if((a == 'b' && b == 'r') || (a == 'r' && b == 'b')) return 'g';
	else if((a == 'g' && b == 'b') || (a == 'b' && b == 'g')) return 'r';
}

int solve(string s ){

	queue<P> q;
	map<string, int> m;
	q.push(P(s, 0));	//?????\??????????????¶????????\??????
	if(m[p.first]) continue;

	while (!q.empty()) {	//?????\??????????????¶?????????????????§
		P p = q.front();
		q.pop();
		string now = p.first;
		if (judge(now)) return p.second;
		for (int i = 0; i < now.size() - 1; ++i) {
			if (now[i] != now[i+1]){	//??£?????????2????????°????????¨???
				char tmp = color(now[i], now[i + 1]);
				string D = now;
				D[i] = tmp;
				D[i + 1] = tmp;
				q.push(P(D, p.second + 1));
			}
		}
	}
	return -1;
}

int main() {
	string worm;
	while (cin >> worm) {
		if (worm == "0") break;
		int count = solve(worm);
		if (count == -1) cout << "NA" << endl;
		else cout << count << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int solve(std::string)':
a.cc:27:14: error: 'p' was not declared in this scope
   27 |         if(m[p.first]) continue;
      |              ^
a.cc:27:24: error: continue statement not within a loop
   27 |         if(m[p.first]) continue;
      |                        ^~~~~~~~
a.cc: In function 'char color(char, char)':
a.cc:20:1: warning: control reaches end of non-void function [-Wreturn-type]
   20 | }
      | ^
Language: C++

#include <list>
#include <stdio.h>
#include <algorithm>

using namespace std;


typedef struct {
	char nood[11];
	int time;
} WORM;

unsigned int makeHash(char nood[])
{
	int i = 0;
	unsigned int ret = 0;
	while (nood[i] != -1){
		ret += nood[i];
		ret *= 3;
		i++;
	}
	
	return (ret);
}

int add_worm(list<WORM>* lstWorm, list<unsigned>& lstHash)
{
	WORM add;
	
	add.time = lstWorm->front().time + 1;
	
	int i = 0;
	while (lstWorm->front().nood[i + 1] != -1){
		if (lstWorm->front().nood[i] != lstWorm->front().nood[i + 1]){
			memcpy(add.nood, lstWorm->front().nood, 11);
			add.nood[i] = add.nood[i + 1] = 3 - (lstWorm->front().nood[i] + lstWorm->front().nood[i + 1]);
			if (find(lstHash.begin(), lstHash.end(), makeHash(add.nood)) == lstHash.end()){
				lstWorm->push_back(add);
				lstHash.push_back(makeHash(add.nood));
			}
		}
		i++;
	}
	
	return (0);
}

bool checkNood(char nood[])
{
	int i = 1;
	int d = nood[0];
	bool ret = true;
	
	while (nood[i] != -1){
		if (d != nood[i]){
			ret = false;
			break;
		}
		i++;
	}
	
	return (ret);
}

int main(void)
{
	list<unsigned int> lstHash;
	list<WORM> lstWorm;
	WORM add;
	
	while (1){
		lstHash.clear();
		lstWorm.clear();
		scanf("%s", add.nood);
		if (add.nood[0] == '0'){
			break;
		}
		int i = 0;
		while (add.nood[i] != '\0'){
			switch(add.nood[i]){
			  case 'r': add.nood[i] = 0; break;
			  case 'g': add.nood[i] = 1; break;
			  case 'b': add.nood[i] = 2; break;
			}
			i++;
		}
		add.nood[i] = -1;
		add.time = 0;
		
		lstWorm.push_back(add);
		lstHash.push_back(makeHash(add.nood));
		
		while (lstWorm.empty() == false && checkNood(lstWorm.front().nood) == false){
			add_worm(&lstWorm, lstHash);
			lstWorm.pop_front();
		}
		
		if (lstWorm.empty() == true){
			puts("NA");
		}
		else {
			printf("%d\n", lstWorm.front().time);
		}
	}
	
	return (0);
}

Compiler output:
a.cc: In function 'int add_worm(std::__cxx11::list<WORM>*, std::__cxx11::list<unsigned int>&)':
a.cc:35:25: error: 'memcpy' was not declared in this scope
   35 |                         memcpy(add.nood, lstWorm->front().nood, 11);
      |                         ^~~~~~
a.cc:4:1: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <algorithm>
  +++ |+#include <cstring>
    4 |
Language: C++

#include <iostream>
#include <queue>
#include <map>
using namespace std;

int f(char a,char b){
	if( a == 'r' && b == 'g' ) return 'b';
	if( a == 'b' && b == 'r' ) return 'g';
	if( a == 'b' && b == 'g' ) return 'r';
	swap(a,b);
	if( a == 'r' && b == 'g' ) return 'b';
	if( a == 'b' && b == 'r' ) return 'g';
	if( a == 'b' && b == 'g' ) return 'r';
	return 0;
}

int main(){
	string s;
	while(cin >> s && s != "0" ){
		map<string,int> done;
		queue< pair<string,int> > Q;
		Q.push(make_pair(s,0));
		while(Q.size()){
			pair<string,int> q = Q.front(); Q.pop();
			if( done[q.first]++) continue;
			if( count(q.first.begin(),q.first.end(),q.first[0]) == q.first.size() ) {
				cout << q.second << endl;
				goto exit;
			}
			for(int i = 0 ; i < q.first.size() - 1 ; i++){
				if( f(q.first[i],q.first[i+1]) ){
					char c = f(q.first[i],q.first[i+1]);
					string next = q.first;
					next[i] = next[i+1] = c;
					Q.push(make_pair(next,q.second+1));
				}
			}
		}
		cout << "NA" << endl;
		exit:;
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:26:29: error: 'count' was not declared in this scope
   26 |                         if( count(q.first.begin(),q.first.end(),q.first[0]) == q.first.size() ) {
      |                             ^~~~~
Language: C

#include<stdio.h>
#include<stdlib.h>
#define INF 10000000

int cost[100][500];
int mincost[500];
int used[500];

int main(void)
{
	int n, m,a,b,c;
	int i,j;
	while (1) {
		scanf("%d %d", &n, &m);
		if (n == 0 && m == 0)break;
		for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++) {
				if (i == j)cost[i][j] = 0;
				else
					cost[i][j] = INF;
			}
		}
		for (i = 0; i < m; i++) {
			scanf("%d %d %d", &a, &b, &c);
			cost[a][b] = c;
			cost[b][a] = c;
		}

		for (int i = 0; i < n; i++) {
			mincost[i] = INF;
			used[i] = 0;
		}
		mincost[0] = 0;
		int res = 0;

		while (1) {
			int v = -1;
			int u;
			for (u = 0; u < n; u++) {
				if (!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u;
			}
			if (v == -1)break;
			used[v] = 1;
			res += mincost[v];

			for (u = 0; u < n; u++)
				mincost[u] = min(mincost[u], cost[v][u]);
		}
		printf("%d\n",res);
	}
	return 0;
}

Compiler output:
main.c: In function 'main':
main.c:47:46: error: implicit declaration of function 'min'; did you mean 'main'? [-Wimplicit-function-declaration]
   47 |                                 mincost[u] = min(mincost[u], cost[v][u]);
      |                                              ^~~
      |                                              main
Language: C++

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

int n,m,sum;
int P[110],a[10010],b[10010],cost[10010];
pair<int,int> bridge[10010];
void init(int N) {
	for(int i=0; i<N; ++i) P[i] = i;
}
int root(int a) {
	if(P[a] == a) return a;
	return (P[a] = root(P[a]));
}

int main() {
	cin >> n >> m;
	while(n!=0 && m!=0) {
		for(int i=0; i<m; ++i) {
			cin >> a[i] >> b[i] >> cost[i];
			bridge[i].first = cost[i];
			bridge[i].second = i;
		}
		sort(bridge,bridge+m);
		init(n);
		for(int i=0; i<m; ++i) {
			if(P[b[bridge[i].second]] == b[bridge[i].second]) {
				if(P[a[bridge[i].second]] != b[bridge[i].second]) {
					P[b[bridge[i].second]] = a[bridge[i].second];
					root(b[bridge[i].second]);
					sum += bridge[i].first;
				}
			}
		}
		cout << sum << endl;
		cin >> n >> m;
		sum =0;
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:17: error: 'sort' was not declared in this scope; did you mean 'short'?
   24 |                 sort(bridge,bridge+m);
      |                 ^~~~
      |                 short
Language: C++

# include <iostream>
# include <algorithm>

const int MAX_N = 100;
const int INF = 100000;

int n, m;
int cost[MAX_N][MAX_N], mincost[MAX_N];
bool used[MAX_N];

int prim(){
	for (int i = 0; i < n; ++i)
		mincost[i] = INF;
	mincost[0] = 0;
	int res = 0;
	while (1){
		int v = -1;
		for (int i = 0; i < n; ++i){
			if (!used[i] && (v == -1 || mincost[i] < mincost[v]))
				v = i;
		}
		if (v == -1)
			break;
		used[v] = true;
		res += mincost[v];

		for (int i = 0;  i < n; ++i)
			mincost[i] = std::min(mincost[i], cost[v][i]);
	
	}
	return res;
}

int main(){
	while (1){
		std::cin >> n >> m;
		if (n == 0 && m == 0)
			break;
		std::memset(used, 0, n);
		for (int i = 0; i < n; ++i){
			for (int j = 0; j < n; ++j)
				cost[i][j] = INF;
		}
		int a, b, c;

		for (int i = 0; i < m; ++i){
			std::cin >> a >> b >> c;
			cost[a][b] = c;
			cost[b][a] = c;
		}
		std::cout << prim() << std::endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:39:22: error: 'memset' is not a member of 'std'; did you mean 'wmemset'?
   39 |                 std::memset(used, 0, n);
      |                      ^~~~~~
      |                      wmemset
Language: C++

#include <iostream>
#include <set>
#include <algorithm>

using namespace std;

int n, m;
vector< set< pair<int, int> > > cost(100,set< pair<int,int> >());

int prim()
{
	int res=0;
	set<int> v;
	v.insert(0);
	while(v.size()<n)
	{
		pair<int, int> mini(100000007, -1);
		for(set<int>::iterator it=v.begin();it!=v.end();it++)
		{
			for(set<  pair<int, int> >::iterator it2=cost[*it].begin();it2!=cost[*it].end();it2++)
				if(v.find((*it2).second)==v.end())
				{
					if(mini.first>(*it2).first)
						mini=(*it2);
					break;
				}
		}
		v.insert(mini.second);
		res+=mini.first;
	}
	return res;
}

int main()
{
	while(1)
	{
		cin >> n >> m;
		if(n==0&&m==0) break;
		for(int i=0;i<m;i++)
		{
			int a, b, c;
			cin >> a >> b >> c;
			cost[a].insert(pair<int, int>(c, b));
			cost[b].insert(pair<int, int>(c, a));
		}
		cout << prim() << endl;
		for(int i=0;i<m;i++)
			cost[i].clear();
	}
	return 0;
}

Compiler output:
a.cc:8:1: error: 'vector' does not name a type
    8 | vector< set< pair<int, int> > > cost(100,set< pair<int,int> >());
      | ^~~~~~
a.cc: In function 'int prim()':
a.cc:20:66: error: 'cost' was not declared in this scope; did you mean 'const'?
   20 |                         for(set<  pair<int, int> >::iterator it2=cost[*it].begin();it2!=cost[*it].end();it2++)
      |                                                                  ^~~~
      |                                                                  const
a.cc: In function 'int main()':
a.cc:44:25: error: 'cost' was not declared in this scope; did you mean 'const'?
   44 |                         cost[a].insert(pair<int, int>(c, b));
      |                         ^~~~
      |                         const
a.cc:49:25: error: 'cost' was not declared in this scope; did you mean 'const'?
   49 |                         cost[i].clear();
      |                         ^~~~
      |                         const
Language: C++

#include <list>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
long long prim(int V, vector<pair<int, long long> > X[]) {
	priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > Q;
	for (int i = 0; i < V; i++) dist[i] = INF, used[i] = false;
	dist[0] = 0; Q.push(make_pair(0, 0));
	while (!Q.empty()) {
		pair<int, long long> pa = Q.top(); Q.pop();
		long long a1 = pa.first, a2 = pa.second; used[a2] = true;
		for (int i = 0; i < X[a2].size(); i++) {
			int to = X[a2][i].first; long long leng = X[a2][i].second;
			if (dist[to] > leng && !used[to]) {
				dist[to] = leng; Q.push(make_pair(dist[to], to));
			}
		}
	}
	long long sum = 0;
	for (int i = 0; i < V; i++) sum += dist[i];
	return sum;
}
int n, m, u, v, w; vector<pair<int, long long> > G[100];
int main() {
	while(cin >> n >> m, n) {
		for(int i = 0; i < n; i++) G[i].clear();
		for(int i = 0; i < m; i++) {
			cin >> u >> v >> w;
			G[u].push_back(make_pair(v, w));
			G[v].push_back(make_pair(u, w));
		}
		cout << prim(n, G) << endl;
	}
}

Compiler output:
a.cc: In function 'long long int prim(int, std::vector<std::pair<int, long long int> >*)':
a.cc:10:37: error: 'dist' was not declared in this scope
   10 |         for (int i = 0; i < V; i++) dist[i] = INF, used[i] = false;
      |                                     ^~~~
a.cc:10:47: error: 'INF' was not declared in this scope
   10 |         for (int i = 0; i < V; i++) dist[i] = INF, used[i] = false;
      |                                               ^~~
a.cc:10:52: error: 'used' was not declared in this scope
   10 |         for (int i = 0; i < V; i++) dist[i] = INF, used[i] = false;
      |                                                    ^~~~
a.cc:11:9: error: 'dist' was not declared in this scope
   11 |         dist[0] = 0; Q.push(make_pair(0, 0));
      |         ^~~~
a.cc:14:58: error: 'used' was not declared in this scope
   14 |                 long long a1 = pa.first, a2 = pa.second; used[a2] = true;
      |                                                          ^~~~
Language: C++

#include <list>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
bool used[100]; long long dist[100];
long long prim(int V, vector<pair<int, long long> > X[]) {
	priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > Q;
	for (int i = 0; i < V; i++) dist[i] = INF, used[i] = false;
	dist[0] = 0; Q.push(make_pair(0, 0));
	while (!Q.empty()) {
		pair<int, long long> pa = Q.top(); Q.pop();
		long long a1 = pa.first, a2 = pa.second; used[a2] = true;
		for (int i = 0; i < X[a2].size(); i++) {
			int to = X[a2][i].first; long long leng = X[a2][i].second;
			if (dist[to] > leng && !used[to]) {
				dist[to] = leng; Q.push(make_pair(dist[to], to));
			}
		}
	}
	long long sum = 0;
	for (int i = 0; i < V; i++) sum += dist[i];
	return sum;
}
int n, m, u, v, w; vector<pair<int, long long> > G[100];
int main() {
	while(cin >> n >> m, n) {
		for(int i = 0; i < n; i++) G[i].clear();
		for(int i = 0; i < m; i++) {
			cin >> u >> v >> w;
			G[u].push_back(make_pair(v, w));
			G[v].push_back(make_pair(u, w));
		}
		cout << prim(n, G) << endl;
	}
}

Compiler output:
a.cc: In function 'long long int prim(int, std::vector<std::pair<int, long long int> >*)':
a.cc:11:47: error: 'INF' was not declared in this scope
   11 |         for (int i = 0; i < V; i++) dist[i] = INF, used[i] = false;
      |                                               ^~~
Language: C++

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<set>
#include<stack>

using namespace std;
typedef unsigned long long ll;

int main(){
    int n,m;
    while(cin>>n>>m,n){
        int city[102][102];
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                city[i][j]=INT_MAX;
            }
            city[i][i]=0;
        }
        for(int i=0;i<m;i++){
            int a,b,c;
            cin>>a>>b>>c;
            city[a][b]=c;
            city[b][a]=c;
        }
        vector<int>que;
        vector<int>vec;
        vec.push_back(0);
        for(int i=1;i<n;i++){
            que.push_back(i);
        }
        int ret=0;
        while(!que.empty()){
            int mi=INT_MAX;
            int cur=-1,in;
            for(int j=0;j<que.size();j++){
                for(int i=0;i<vec.size();i++){
                    if(city[vec[i]][que[j]]<mi){
                        mi=city[vec[i]][que[j]];
                        cur=que[j];
                        in=j;
                    }
                }
            }
            ret+=mi;
            que.erase(que.begin()+in);
            vec.push_back(cur);
        }
        cout<<ret<<endl;
    }
    
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:28: error: 'INT_MAX' was not declared in this scope
   23 |                 city[i][j]=INT_MAX;
      |                            ^~~~~~~
a.cc:13:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   12 | #include<stack>
  +++ |+#include <climits>
   13 | 
a.cc:41:20: error: 'INT_MAX' was not declared in this scope
   41 |             int mi=INT_MAX;
      |                    ^~~~~~~
a.cc:41:20: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
Language: C++

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

struct Edge {
  int from, to, cost;
  Edge() : from(0), to(0), cost(0) { }
  Edge(int from, int to, int cost) : from(from), to(to), cost(cost) { }
};

struct UnionFind {
  vector<int> data;

  UnionFind(int n) : data(n, -1) { }

  bool same(int i, int j) {
    return root(i) == root(j);
  }

  int root(int i) {
    return data[i] < 0 ? i : data[i] = root(data[i]);
  }

  void join(int i, int j) {
    data[root(i)] += data[root(j)];
    data[root(j)] = root(i);
  }
};

int main() {
  for(int n, m; cin >> n >> m && n; ) {
    vector<Edge> edges(m);

    for(int i = 0; i < m; i++) {
      cin >> edges[i].from >> edges[i].to >> edges[i].cost;
    }

    sort(edges.begin(), edges.end(), [](const Edge& a, const Edge& b) {
      return a.cost < b.cost;
    });

    int cost = 0;
    UnionFind uf(n);

    for(auto it = edges.begin(); it != edges.end(); it++) {
      if(!uf.same(it->from, it->to)) {
        uf.join(it->from, it->to);
        cost += it->cost;
      }
    }

    cout << cost << endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   38 |     sort(edges.begin(), edges.end(), [](const Edge& a, const Edge& b) {
      |     ^~~~
      |     short
Language: C++

#include <iostream>
#incldue <cstdio>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;

#define INF 999999

int n, m;
int a, b, c;

int cost[100][100];
int mincost[100];
bool used[100];

void init()
{
	rep(i,100) rep(j,100)
	{
		cost[i][j] = INF;
	}
}

int prim()
{
	rep(i,n)
	{
		mincost[i] = INF;
		used[i] = false;
	}

	mincost[0] = 0;
	int res = 0;

	while (true)
	{
		int v = -1;
		rep(u,n)
		{
			if (!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u;
		}

		if (v == -1) break;
		used[v] = true;
		res += mincost[v];

		rep(u,n)
		{
			mincost[u] = min(mincost[u], cost[v][u]);
		}
	}

	return res;
}

int main()
{
	while (true)
	{
		cin >> n >> m;
		if (n == 0 && m == 0) break;

		init();

		rep(i,m)
		{
			cin >> a >> b >> c;
			cost[a][b] = c;
			cost[b][a] = c;
		}

		printf("%d\n", prim());
	}
}

Compiler output:
a.cc:2:2: error: invalid preprocessing directive #incldue; did you mean #include?
    2 | #incldue <cstdio>
      |  ^~~~~~~
      |  include
Language: C++

#include "Graph.hpp"
#include<iostream>
#include<vector>
#include<queue>
using namespace std;

Graph creat_graph(int n, int m);
int search_prim(Graph prim, int n);

vector<int> ans;
vector<vector<int>> cost(100,vector<int>(100,0));

int main(){
  int n,m;
 
  
  while(cin >> n >> m, n){     
    Graph prim = creat_graph(n,m);   /*creat graph*/
    ans.push_back(search_prim(prim,n));   /*make answer*/
  }
  
  for(int i: ans){
    cout << i << endl;
  }
  return 0;
}


 Graph creat_graph(int n,int m){
    Graph prim(n);
    int a,b,cost_t;

    for(int i=0; i<m; i++){
      cin >> a >> b >> cost_t;
      prim.connect(a,b);
      cost[a][b] = cost_t;
      cost[a][b] = cost_t;
    }
    return prim;
  }
    
int search_prim(Graph prim, int n){
  int current,cost_sum;
  typedef pair<int, int> PII;
  vector<bool> frag(n,false);
  priority_queue < PII, vector < pair <int, int> >, greater < pair <int, int> > > que;
  /*cost,next_node*/
  
  cost_sum = 0;
  current = 0;
  frag[0] = true;
  for(int k=0; k<n-1; ++k){
     vector<int> near = prim.neighbours(current);

     for(int j:near){
       que.push(PII(cost[current][j],j));
     }

     while(1){
       if(frag[que.top().second] == false){
	 cost_sum += que.top().first;
	 frag[que.top().second] = true;
	 current = que.top().second;
	 break;
	 }
     }
     que.pop();
  }
  return cost_sum;
}
       

Compiler output:
a.cc:1:10: fatal error: Graph.hpp: No such file or directory
    1 | #include "Graph.hpp"
      |          ^~~~~~~~~~~
compilation terminated.
Language: C++

#include<iostream>
#include<queue>
#include<vector>

using namespace std;

class Load{
	public:
	int n,m,o,p;
	load(){p=0;}
	load(int a,int b){n=a;m=b;p=0;}
};

int n,m;
Load load[100];

int prim(){
	vector<int> visit;
	visit.push_back(0);
	int cont=0;
	
	while(1){
		if(visit.size()==n){
			break;
		}
		int maxi=1000000000;
		int maxo=0;
		int maxa=0;
		for(int i=0;i<m;i++){
			for(int j=0;j<visit.size();j++){
				if(load[i].n==visit[j]&&load[i].p==0){
					if(maxi>load[i].o){
						load[i].p=1;
						maxi=load[i].o;
						maxo=load[i].m;
						maxa=i;
					}
				}
				if(load[i].m==visit[j]&&load[i].p==0){
					if(maxi>load[i].o){
						load[i].p=1;
						maxi=load[i].o;
						maxo=load[i].n;
						maxa=i;
					}
				}
			}
		}
		//printf("%d %d %d\n",maxa,maxo,maxi);
		cont+=maxi;
		visit.push_back(maxo);
	}
	return cont;
}

int main(){
	while(1){
	cin>>n>>m;
		if(!n){
			break;
		}
		for(int i=0;i<m;i++){
			int a,b,c;
			cin>>a>>b>>c;
			load[i].n=a;
			load[i].m=b;
			load[i].o=c;
			load[i].p=0;
		}
		printf("%d\n",prim());
	}
	
}

Compiler output:
a.cc:10:9: error: ISO C++ forbids declaration of 'load' with no type [-fpermissive]
   10 |         load(){p=0;}
      |         ^~~~
a.cc:11:9: error: ISO C++ forbids declaration of 'load' with no type [-fpermissive]
   11 |         load(int a,int b){n=a;m=b;p=0;}
      |         ^~~~
a.cc: In member function 'int Load::load()':
a.cc:10:20: warning: no return statement in function returning non-void [-Wreturn-type]
   10 |         load(){p=0;}
      |                    ^
a.cc: In member function 'int Load::load(int, int)':
a.cc:11:39: warning: no return statement in function returning non-void [-Wreturn-type]
   11 |         load(int a,int b){n=a;m=b;p=0;}
      |                                       ^
Language: C++

#include<iostream>
#include<vector>
#include<cstdio>
#include<cmath>

#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

typedef unsigned long long ull;

int main(){
  int n,m;
  while(scanf("%d%d",&n,&m),n+m){
    int  cost[n][n];
    bool f[n];
    memset(cost, 0, sizeof(cost));
    memset(f, 0, sizeof(f));
    REP(i,m){
      int a,b,c;
      scanf("%d%d%d",&a,&b,&c);
      cost[a][b] = cost[b][a] = c;
    }
    f[0] = true;
    int ans = 0;
    REP(i,n-1){
      int m = INT_MAX;
      int ii,jj;
      for(int i=0; i<n; i++){
	for(int j=i+1; j<n; j++){
	  if(f[i] ^ f[j] && cost[i][j] != 0){
	    if(m > cost[i][j]){
	      ii = i; jj = j;
	      m = cost[i][j];
	    }
	  }
	}
      }
      f[ii] = f[jj] = true;
      ans += m;
    }

    printf("%d\n",ans);
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:17:5: error: 'memset' was not declared in this scope
   17 |     memset(cost, 0, sizeof(cost));
      |     ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    4 | #include<cmath>
  +++ |+#include <cstring>
    5 | 
a.cc:27:15: error: 'INT_MAX' was not declared in this scope
   27 |       int m = INT_MAX;
      |               ^~~~~~~
a.cc:5:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    4 | #include<cmath>
  +++ |+#include <climits>
    5 |
Language: C++

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

#define NONE 0

int prim(int n, vector< vector<int> >v)
{
  set<int>selected;
  set<int>::iterator it;
  int mincost,mini;
  int i;
  int ans=0;

  selected.insert(0);

  while(selected.size()!=n){
    mincost=INT_MAX;
    mini=NONE;

    for(it=selected.begin();it!=selected.end();it++){
      for(i=0;i<n;i++){
	if(selected.find(i)!=selected.end())continue;
	if(v[*it][i]==NONE)continue;
	if(v[*it][i]>=mincost)continue;
	mincost=v[*it][i];
	mini=i;
      }
    }

    if(mini==NONE)break;
    selected.insert(mini);
    ans+=mincost;
  }

  return ans;
}

int main()
{
  int n,m,a,b,cost;
  int i;
  while(cin>>n>>m,n|m){
    vector< vector<int> >v(n,vector<int>(n,NONE));
    for(i=0;i<m;i++){
      cin>>a>>b>>cost;
      v[a][b]=v[b][a]=cost;
    }
    cout<<prim(n,v)<<endl;
  }
}

Compiler output:
a.cc: In function 'int prim(int, std::vector<std::vector<int> >)':
a.cc:19:13: error: 'INT_MAX' was not declared in this scope
   19 |     mincost=INT_MAX;
      |             ^~~~~~~
a.cc:4:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    3 | #include<set>
  +++ |+#include <climits>
    4 | using namespace std;
Language: C++

#include <stdio.h>
#define  MAX 101


struct Dis
{
    int pa[MAX];
    int used[MAX];
    int n;
    Dis(int n):n(n)
    {
        for(int i=0;i<n;i++)
        {
            pa[i]=i;
            used[i]=0;
        }
    }
    void use(int i)
    {
        used[i]=1;
    }
    int root(int a)
    {
        if(pa[a]==a)
            return a;
        return pa[a]=root(pa[a]);
    }
    bool is_same_set(int a,int b)
    {
        return root(a)==root(b);
    }
    void unite(int n,int m)
    {
        use(n);
        use(m);
        pa[root(n)]=root(m);
    }
    bool is_connected()
    {
        int rt=-1;
        for(int i=0;i<n;i++)
        {
            if(rt>=0 &&used[i] && rt!=root(i))
                return false;
            if(used[i])
                rt=root(i);
        }
        return rt!=-1;
    }
};

int br[6000][3];

int getMin(int m)
{
    int tmp=-1;
    for(int i=0;i<m;i++)
    {
        if(br[i][2]!=-1)
        {
            if(tmp==-1 || br[tmp][2]>=br[i][2])
            {
                tmp=i;
            }
        }
    }
    if(tmp!=-1)
    {
        return tmp;
    }
}

int main(void)
{
    int n,m;
    while(scanf("%d%d",&n,&m)==2 && n && m)
    {
        Dis dis(n);
        for(int i=0;i<m;i++)
        {
            scanf("%d%d%d",br[i],br[i]+1,br[i]+2);
        }
        int nc=0;
        int cost=0;
        while(nc<n)
        {
            int min=getMin();
            int a=br[min][0];
            int b=br[min][1];
            if(!dis.is_same_set(a,b))
            {
                dis.unite(a,b);
                nc++;
                cost+=br[min][2];
                br[min][2]=-1;
            }
        }
        printf("%d\n",cost);
    }
    return 0;
    
}

Compiler output:
a.cc: In function 'int main()':
a.cc:87:27: error: too few arguments to function 'int getMin(int)'
   87 |             int min=getMin();
      |                     ~~~~~~^~
a.cc:54:5: note: declared here
   54 | int getMin(int m)
      |     ^~~~~~
a.cc: In function 'int getMin(int)':
a.cc:71:1: warning: control reaches end of non-void function [-Wreturn-type]
   71 | }
      | ^
Language: Java

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

typedef long long ll;

    ll m, n;
    ll w[110];
    
    bool check(ll mid){
        ll sum=0, count=1;
        for(ll i=1; i<=n; i++){
            if(w[i]>mid)    return false;
            sum+=w[i];
            if(sum>mid){
                count++;
                sum=w[i];
            }
        }
        return count<=m;
    }
    
int main(void){
    while(cin >> m >> n){
        if(m+n==0) break;
        for(int i=1; i<=n; i++){
            cin >> w[i];
        }
        ll under=0, upper=1500000;
        while(upper-under>1LL){
            ll mid=(under+upper)/2;
            
            if(! check(mid)){
                under=mid;
            }
            else{
                upper=mid;
            }
        }
    
        cout << upper << "\n";
    }
    
    return 0;
}


Compiler output:
Main.java:1: error: illegal character: '#'
#include<bits/stdc++.h>
^
Main.java:1: error: class, interface, enum, or record expected
#include<bits/stdc++.h>
        ^
Main.java:4: error: class, interface, enum, or record expected
typedef long long ll;
^
Main.java:6: error: class, interface, enum, or record expected
    ll m, n;
    ^
Main.java:7: error: class, interface, enum, or record expected
    ll w[110];
    ^
Main.java:9: error: unnamed classes are a preview feature and are disabled by default.
    bool check(ll mid){
    ^
  (use --enable-preview to enable unnamed classes)
Main.java:26: error: not a statement
            cin >> w[i];
                ^
Main.java:29: error: not a statement
        while(upper-under>1LL){
                            ^
Main.java:40: error: not a statement
        cout << upper << "\n";
                      ^
Main.java:22: error: <identifier> expected
int main(void){
             ^
Main.java:29: error: ';' expected
        while(upper-under>1LL){
                             ^
11 errors
Language: Java


import java.util.Scanner;

//Persistence
public class AOJ0181 {

	static int[] w;
	static int n, m;
	
	static boolean f(int W){
		int need = 1;
		int s = 0;
		for(int i=0;i<n;i++){
			if(w[i]>W)return false;
			if(s+w[i]>W){
				need++;
				s = 0;
			}
			s+=w[i];
		}
		return need <= m;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			m = sc.nextInt();
			n = sc.nextInt();
			if((m|n)==0)break;
			w = new int[n];
			for(int i=0;i<n;i++)w[i]=sc.nextInt();
			int l = 1;
			int r = 1500000;
			while(r-l>1){
				int mid = (l+r)/2;
				if(f(mid))r = mid;
				else l = mid;
			}
			System.out.println(f(l)?l:r);
		}
	}
}

Compiler output:
Main.java:5: error: class AOJ0181 is public, should be declared in a file named AOJ0181.java
public class AOJ0181 {
       ^
1 error
Language: C

#include <cstdio>
using namespace std;
int bookin(int* books,int m,int w,int n);

int main(void)
{
  int n,m;
  for(;;){
    scanf("%d %d",&m,&n);
    if(n==0)return 0;
    int books[n];
    for(int i=0;i<n;i++){
      scanf("%d",&books[i]);
    }

    int low = 1,high=1500000;
    for(int i=0;i<100;i++){
      int mid = (low+high)/2;
      int midval = bookin(books,m,mid,n);

      if(midval==0)low = mid;
      else high = mid;
    }
    printf("%d\n",high); 
  }
}

int bookin(int* books,int m,int w,int n)
{
  int haba=w;
  for(int i=0;i<n;i++){
    haba-=books[i];
    if(haba<0){i--;m--;haba=w;}
    if(m<=0)return 0;
  }
  return 1;
}
  

Compiler output:
main.c:1:10: fatal error: cstdio: No such file or directory
    1 | #include <cstdio>
      |          ^~~~~~~~
compilation terminated.
Language: C

#include<stdio.h>
#include<math.h>

int w[100];
int m, n;

int func(int h) {
	int i=0, sum = 0,count=0;
	while(i<n && count < m){
		if (h >= sum + w[i]) 
			sum += w[i++];
		else {
			sum = 0;
			count++;
        }
	}
	return i == n && count < m;
}

int binsearch_func(int low, int hight) {
	int i;
	for (i = 0; i < 100; i++) {
		int mid = (low + hight) / 2;
		int midval = func(mid);

		if (midval)hight = mid;
		else low = mid;
	}
	return max(low,hight);
}

int main(void)
{
	int sum;
	int i;
	while (1) {
		scanf("%d %d", &m, &n);
		if (m == 0 && n == 0)break;
		sum = 0;
		for (i = 0; i < n; i++) {
			scanf("%d",&w[i]);
			sum += w[i];
		}

		printf("%d\n", binsearch_func(0, 10000000));
	}
	return 0;
}

Compiler output:
main.c: In function 'binsearch_func':
main.c:29:16: error: implicit declaration of function 'max'; did you mean 'fmax'? [-Wimplicit-function-declaration]
   29 |         return max(low,hight);
      |                ^~~
      |                fmax
Language: C

//suhan lee, saitama university;
#include <iostream>
using namespace std;
int putbook(int *list,int bookwi,int stair,int width){

  int dara[20];
  int j=0;
  for(int i=0;i<20;i++)
    dara[i]=0;
  for(int i=0;i<bookwi;i++)
    if(dara[j]+list[i]<=width)
      dara[j]+=list[i];
    else  if(list[i]>width){
      //cout <<"too big book"<<endl;
      return 0;
    }
    else  dara[++j]+=list[i];     
  //  cout <<"hondara";
  for(int i=0;i<stair;i++)
    // cout <<dara[i]<<endl;
    // cout <<"kugiri";
  if(j<stair) return 1;// no problem
  else return 0;
}


int main(){

  int list[100];

  int bookwi,stair,temp;
  int max,min;
  while(1){
    cin >>stair>>bookwi;
    if(bookwi==0&&stair==0)
      return 0;
    for(int i=0;i<bookwi;i++)
      cin>>list[i];
    max=1000000;
    min=1;
    //cout << putbook( list,bookwi,stair,1800 )<<endl;
    while(1){
      if(min==max) break;
      if(putbook( list,bookwi,stair, ( max+min)/2  ) )
	max=(max+min)/2;
      else min= (max+min)/2+1;
      //   cout <<endl<<max<<" max&min   "<<min<<endl;   
    }
    cout <<max<<endl;
  }

}

Compiler output:
main.c:2:10: fatal error: iostream: No such file or directory
    2 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	while (1) {
		int M, N; cin >> M >> N;
		if (!M)break;
		vector<int>as;
		for (int i = 0; i < N; ++i) {
			int a; cin >> a;
			as.emplace_back(a);
		}

		int amin = *max_element(as.begin(),as.end())-1; int amax = 1500001;
		while (amin + 1 != amax) {
			int amid = (amin + amax) / 2;
			{
				int h = 0;
				int num = 0;
				for (int b = 0; b < N; ++b) {
					if (as[b] + num > amid) {
						h++;
						num = as[b];
					}
					else {
						num += asa[b];
					}
				}
				if (h >= M) {
					amin = amid;
				}
				else {
					amax = amid;
				}
			}
		}
		cout << amax << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:34:56: error: 'asa' was not declared in this scope; did you mean 'as'?
   34 |                                                 num += asa[b];
      |                                                        ^~~
      |                                                        as
Language: C++

import Control.Monad
import Control.Applicative

main :: IO ()
main = do
  [m, n] <- getInts
  if (m == 0 && n == 0) then return ()
  else do
    ss <- getIntLines n
    print $ rolve m ss
    main

rolve m ss = bin_search (kuwa ss m) 0 1000000

kuwa xs m n = func xs m n n
  where
    func (x:xs) m n l
      | m <= 0 = False
      | m > 0 && xs == [] && n - x >= 0 = True
      | n - x >= 0 = func xs m (n - x) l
      | n - x < 0 = func (x:xs) (m - 1) l l

bin_search func min max
  | (max - min == 1) && (func min) = min
  | (max - min == 1) && (func max) = max
  | func center = bin_search func min center
  | not (func center) = bin_search func center max
  where
    center = div (min + max) 2
---

getInt :: IO Integer
getInt = read <$> getLine

getInts :: IO [Integer]
getInts = map read . words <$> getLine

getIntLines :: Integral a => a -> IO [Integer]
getIntLines n = replicateM (fromIntegral n :: Int) getInt

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import Control.Monad
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
Language: C++

import Control.Applicative

main :: IO ()
main = do
  [m, n] <- getInts
  if (m == 0 && n == 0) then return ()
  else do
    ss <- getIntLines n
    print $ rolve m ss
    main

rolve m ss = bin_search (kuwa ss m) 0 1000000

kuwa xs m n = func xs m n n
  where
    func (x:xs) m n l
      | m <= 0 = False
      | m > 0 && xs == [] && n - x >= 0 = True
      | n - x >= 0 = func xs m (n - x) l
      | n - x < 0 = func (x:xs) (m - 1) l l

bin_search func min max
  | (max - min == 1) && (func min) = min
  | (max - min == 1) && (func max) = max
  | func center = bin_search func min center
  | not (func center) = bin_search func center max
  where
    center = div (min + max) 2
---

getInt :: IO Integer
getInt = read <$> getLine

getInts :: IO [Integer]
getInts = map read . words <$> getLine

getIntLines :: Integral a => a -> IO [Integer]
getIntLines n = replicateM (fromIntegral n :: Int) getInt

Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import Control.Applicative
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
Language: C++


main :: IO ()
main = do
  [m, n] <- getInts
  if (m == 0 && n == 0) then return ()
  else do
    ss <- getIntLines n
    print $ rolve m ss
    main

rolve m ss = bin_search (kuwa ss m) 0 1000000

kuwa xs m n = func xs m n n
  where
    func (x:xs) m n l
      | m <= 0 = False
      | m > 0 && xs == [] && n - x >= 0 = True
      | n - x >= 0 = func xs m (n - x) l
      | n - x < 0 = func (x:xs) (m - 1) l l

bin_search func min max
  | (max - min == 1) && (func min) = min
  | (max - min == 1) && (func max) = max
  | func center = bin_search func min center
  | not (func center) = bin_search func center max
  where
    center = div (min + max) 2
---

getInt :: IO Integer
getInt = read <$> getLine

getInts :: IO [Integer]
getInts = map read . words <$> getLine

getIntLines :: Integral a => a -> IO [Integer]
getIntLines n = replicateM (fromIntegral n :: Int) getInt

Compiler output:
a.cc:2:1: error: 'main' does not name a type
    2 | main :: IO ()
      | ^~~~
Language: C++

#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,m,a[101];
bool nibun(int x){
	int s=0,q=0,t=0;
	r(i,n){
		if(s+a[i]<=x)s+=a[i];
		else s=0,q++,i--,t++;
		if(t>1000)return 0;
	}
	return m>=q+1;
}
main(){
	while(cin>>m>>n,m){
	  y=1e9;
	  r(i,n)cin>>a[i];
	  int l=0,r=1500001;
	  while(l<r){
    	int mid=(l+r)/2;
		if(nibun(mid))r=mid;
		else l=mid+1;
	  }
	  cout<<l<<endl;
    }
}

Compiler output:
a.cc:14:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   14 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:16:11: error: 'y' was not declared in this scope; did you mean 'yn'?
   16 |           y=1e9;
      |           ^
      |           yn
Language: C++

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

int m,n,*b,*l,mp;
map<int,int> hk;

int max(){
	int tmp = l[0];
	for(int i=1; i<m; i++)
		if(tmp < l[i])
			tmp = l[i];
	return tmp;
}

void solve(){
	mp = 0;
	int k;
	l[0] = 0;
	for(int i=0; i<n; i++){
		k = i+1;
		l[0] += b[i];
		for(int j=1; j<m-1; j++){
			l[j] = 0;
			for(; k<n; k++){
				l[j] += b[k];
				if(k == n-1){
					k++;
					break;
				}
				if((l[0] - l[j] >= 0 && l[0] - l[j] < l[j] + b[k+1] - l[0];)||(l[j] >= l[0])){
					k++;
					break;
				}
			}
		}
		l[m-1] = 0;
		for(; k<n; k++)
			l[m-1] += b[k];
		hk[mp++] = max();
	}
}

int min(){
	int tmp = hk[0];
	map<int, int>::iterator it = hk.begin();
	while(it!=hk.end()){
		if(tmp > (*it).second)
			tmp = (*it).second;
		it++;
	}
	return tmp;
}

int main(){
	while(true){
		cin >> m >> n;
		if(!m && !n)
			return 0;
		b = new int[n];
		l = new int[m];
		for(int i=0; i< n; i++)
			cin >> b[i];
		solve();
		cout << min() << endl;
		delete[] b;
		delete[] l;
		hk.clear();
	}
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:31:91: error: expected ')' before ';' token
   31 |                                 if((l[0] - l[j] >= 0 && l[0] - l[j] < l[j] + b[k+1] - l[0];)||(l[j] >= l[0])){
      |                                    ~                                                      ^
      |                                                                                           )
a.cc:31:91: error: expected ')' before ';' token
   31 |                                 if((l[0] - l[j] >= 0 && l[0] - l[j] < l[j] + b[k+1] - l[0];)||(l[j] >= l[0])){
      |                                   ~                                                       ^
      |                                                                                           )
a.cc:31:92: error: expected primary-expression before ')' token
   31 |                                 if((l[0] - l[j] >= 0 && l[0] - l[j] < l[j] + b[k+1] - l[0];)||(l[j] >= l[0])){
      |                                                                                            ^
Language: C++

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

int m,n,*b,*l,mp;
map<int,int> hk;

int max(){
	int tmp = l[0];
	for(int i=1; i<m; i++)
		if(tmp < l[i])
			tmp = l[i];
	return tmp;
}

void erase(){
	for(int i=1; i<m; i++)
		l[i] = 0;
}

void solve(int x, int y){
	l[x] = 0;
	for(int i=y; i<n; i++){
		l[x] += b[i];
		if(x != m-1)
			solve(x+1, i+1);
	}
	if(x == m-1){
//		for(int i=0; i<m; i++)
//			cout << l[i] << ' ';
//		cout << endl;
		hk[mp++] = max();
		if(hl[mp-1] < hk[mp])
			goto FIN;
		return;
	}
}

int min(){
	int tmp = hk[0];
	map<int, int>::iterator it = hk.begin();
	while(it!=hk.end()){
		if(tmp > (*it).second)
			tmp = (*it).second;
		it++;
	}
	return tmp;
}

int main(){
	while(true){
		cin >> m >> n;
		if(!m && !n)
			return 0;
		b = new int[n];
		l = new int[m];
		for(int i=0; i< n; i++)
			cin >> b[i];
		mp = 0;
		solve(0, 0);
FIN:;
		cout << min() << endl;
		delete[] b;
		delete[] l;
		hk.clear();
	}
}

Compiler output:
a.cc: In function 'void solve(int, int)':
a.cc:33:20: error: 'hl' was not declared in this scope; did you mean 'l'?
   33 |                 if(hl[mp-1] < hk[mp])
      |                    ^~
      |                    l
a.cc:34:30: error: label 'FIN' used but not defined
   34 |                         goto FIN;
      |                              ^~~
Language: C++

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int height(const vint& v, int w)
{
	int res = 0, pl = 0;
	
	rep(i, v.size())
	{
		if(w < pl + v[i])
		{
			res++;
			
			if(w < v[i]) return INT_MAX;
			
			pl = 0;
		}
		
		pl += v[i];
	}
	
	return res + (pl != 0);
}

int main()
{
	int m, n;
	while(cin >> m >> n && n)
	{		
		vint v(n);
		rep(i, n) cin >> v[i];
		
		double lb = 1, ub = 1500000;
		
		rep(i, 10000)
		{
			double mid = (ub + lb) / 2;
			
			if(height(v, ceil(mid)) <= m) ub = mid;
			else lb = mid;
		}
		
		cout << ceil(ub) << endl;
	}
}

Compiler output:
a.cc: In function 'int height(const vint&, int)':
a.cc:48:45: error: 'INT_MAX' was not declared in this scope
   48 |                         if(w < v[i]) return INT_MAX;
      |                                             ^~~~~~~
a.cc:24:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   23 | #include <fstream>
  +++ |+#include <climits>
   24 | using namespace std;