Language: C++

#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int n;
	while(scanf("%d",&n),n){
		int p[10000]={0};
		int x = 0;
		int y = 0;
		int ans = 0;
		for(int i = 0; i < n; i++){
			scanf("%d",&p[i]);
			y += p[i];
		}
		sort(p,p+n);
		int j[10000]={0};
		for(int i = 0; i < n-1; i++){
			scanf("%d",&j[i]);
			x += j[i];
		}
		sort(j,j+n-1);
		x += y;
		int cnt = 1;
		ans = x;
		while(1){
			cnt++;
			if(cnt == n)break;
			for(int i = 0; i < n-1; i++){
				if(p[i] != -1){
					p[i] = -1;
					x -= j[i];
					break;
				}
			}
			if(ans > x*cnt){
				break;
			}
			ans = x*cnt;
		}
		ans = max(ans,y*n);
		printf("%d\n",ans);
	}
	return 0;
}
		#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int n;
	while(scanf("%d",&n),n){
		int p[10000]={0};
		int x = 0;
		int y = 0;
		int ans = 0;
		for(int i = 0; i < n; i++){
			scanf("%d",&p[i]);
			y += p[i];
		}
		sort(p,p+n);
		int j[10000]={0};
		for(int i = 0; i < n-1; i++){
			scanf("%d",&j[i]);
			x += j[i];
		}
		sort(j,j+n-1);
		x += y;
		int cnt = 1;
		ans = x;
		while(1){
			cnt++;
			if(cnt == n)break;
			for(int i = 0; i < n-1; i++){
				if(p[i] != -1){
					p[i] = -1;
					x -= j[i];
					break;
				}
			}
			if(ans > x*cnt){
				break;
			}
			ans = x*cnt;
		}
		ans = max(ans,y*n);
		printf("%d\n",ans);
	}
	return 0;
}
		#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int n;
	while(scanf("%d",&n),n){
		int p[10000]={0};
		int x = 0;
		int y = 0;
		int ans = 0;
		for(int i = 0; i < n; i++){
			scanf("%d",&p[i]);
			y += p[i];
		}
		sort(p,p+n);
		int j[10000]={0};
		for(int i = 0; i < n-1; i++){
			scanf("%d",&j[i]);
			x += j[i];
		}
		sort(j,j+n-1);
		x += y;
		int cnt = 1;
		ans = x;
		while(1){
			cnt++;
			if(cnt == n)break;
			for(int i = 0; i < n-1; i++){
				if(p[i] != -1){
					p[i] = -1;
					x -= j[i];
					break;
				}
			}
			if(ans > x*cnt){
				break;
			}
			ans = x*cnt;
		}
		ans = max(ans,y*n);
		printf("%d\n",ans);
	}
	return 0;
}
		#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int n;
	while(scanf("%d",&n),n){
		int p[10000]={0};
		int x = 0;
		int y = 0;
		int ans = 0;
		for(int i = 0; i < n; i++){
			scanf("%d",&p[i]);
			y += p[i];
		}
		sort(p,p+n);
		int j[10000]={0};
		for(int i = 0; i < n-1; i++){
			scanf("%d",&j[i]);
			x += j[i];
		}
		sort(j,j+n-1);
		x += y;
		int cnt = 1;
		ans = x;
		while(1){
			cnt++;
			if(cnt == n)break;
			for(int i = 0; i < n-1; i++){
				if(p[i] != -1){
					p[i] = -1;
					x -= j[i];
					break;
				}
			}
			if(ans > x*cnt){
				break;
			}
			ans = x*cnt;
		}
		ans = max(ans,y*n);
		printf("%d\n",ans);
	}
	return 0;
}
		

Compiler output:
a.cc:48:5: error: redefinition of 'int main()'
   48 | int main(){
      |     ^~~~
a.cc:4:5: note: 'int main()' previously defined here
    4 | int main(){
      |     ^~~~
a.cc:92:5: error: redefinition of 'int main()'
   92 | int main(){
      |     ^~~~
a.cc:4:5: note: 'int main()' previously defined here
    4 | int main(){
      |     ^~~~
a.cc:136:5: error: redefinition of 'int main()'
  136 | int main(){
      |     ^~~~
a.cc:4:5: note: 'int main()' previously defined here
    4 | int main(){
      |     ^~~~