semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
int main ()
{
	int n , sum = 0 , i = 0,flag = 0 , k = 0, j = 0;
	float a[301] = {0}, dis[301] = {0}, max = 0 , pai[301]={0} ,temp = 0 ,ave = 0 ;
	cin >> n;
	for ( i = 0; i < n; i++)
	{
		cin >> a[i];
		sum = sum + a[i];
	}
	ave =(float) sum / n;
	for( i = 0; i < n ;i++)
	{
	    dis[i] = fabs(a[i] - ave);
		if( dis[i] > max)
			max = dis[i];
	}
	for( i = 0; i < n; i++)
	{
		if( fabs(dis[i] - max)< 1e-5)
		{
			pai[k++] = a[i];
		}
	}
	for( i = 0; i < k -1 ; i++)
	{
		for( j = 0; j < k - i - 1; j++)
		{
			if( pai[j] > pai[j+1])
			{
				temp = pai[j];
				pai[j] = pai[ j+1];
				pai[j+1] = temp;
			}
		}
	}
	for( i = 0 ; i < k; i ++)
	{
			if( flag == 0)
			{
			cout << pai[i];
			flag = 1;
			}
			else
				cout << "," << pai[i];
	}
	return 0;
}
void main()
{
	int n,i,a[305],count=0,max,min;
	double ave=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(i==1)
		{
			max=a[1];
			min=a[1];
		}
		if(max<a[i])
		{
			max=a[i];
		}
		if(min>a[i])
		{
			min=a[i];
		}
		ave+=a[i];
	}
	ave/=n;
	if(ave-min>max-ave)
	{
		printf("%d",min);
	}
	else if(ave-min<max-ave)
	{
		printf("%d",max);
	}
	else
	{
		printf("%d,%d",min,max);
	}
}
void main()
{
int a[300],c[300]={0},i,j,n,k=0,l=0;
float z=0,b[300];
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
z=z+a[i];
z=z/n;
for(i=0;i<n;i++)
{if(a[i]>z)
b[i]=a[i]-z;
else b[i]=z-a[i];
}
for(i=0;i<n;i++)
{for(j=0;j<n;j++)
{if(b[j]>b[i])
c[i]++;}
}
for(i=0;i<n;i++)
{if(c[i]==0)
k++;}
for(i=0;i<n;i++)
{if(c[i]==0)
{l++;
if(l==k)
	printf("%d",a[i]);
else printf("%d,",a[i]);}
}
}
int main()
{
	int a[300],n,s=0,i,j;
	double x,t=0;
	scanf("%d",&n);
	for(i=0; i<n; i++)
	{
		scanf("%d",&a[i]);
		s+=a[i];
	}
	x=(double)s/n;
	for(i=0; i<n; i++)
	{
		for(j=n-1; j>i; j--)
		{
			if(a[j]<a[j-1])
			{
				int tem=a[j];
				a[j]=a[j-1];
				a[j-1]=tem;
			}
		}
	}
	if((a[n-1]-x)==(x-a[0]))
		printf("%d,%d",a[0],a[n-1]);
	else if((a[n-1]-x)<(x-a[0]))
        printf("%d",a[0]);
	else if((a[n-1]-x)>(x-a[0]))
        printf("%d",a[n-1]);
	else
		printf("ghjk");
	return 0;
}
// ??????.cpp : Defines the entry point for the console application.
//

int main()
{
	int n,a[1000],i,sa=0,m=0,j,s[1000];
	double max=0,cha[1000],t,sum;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		sa+=a[i];
	}
	sum=(double)sa/(double)n;
	for(i=0;i<n;i++)
	{
		cha[i]=fabs((double)a[i]-sum);
		if(fabs((double)a[i]-sum)>=max)
			max=fabs((double)a[i]-sum);
	}
	for(i=0;i<n;i++)
	{
		if(cha[i]==max)
		{
			s[m]=a[i];
			m++;
		}
	}
	for(i=0;i<m-1;i++)
		for(j=0;j<m-1-i;j++)
		{
			if(s[j]>s[j+1])
			{
				t=s[j];s[j]=s[j+1];s[j+1]=t;
			}
		}
		cout<<s[0];
		for(i=1;i<m;i++)
			cout<<","<<s[i];
		return 0;
}
int main()
{
	float a[300];
	int i,n;
	float max,min;
	float aver;
	float sum=0;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	max=a[0];
	for(i=0;i<n;i++)
	{
		if(a[i]>max)
			max=a[i];
	}
	min=a[0];
	for(i=0;i<n;i++)
	{
		if(a[i]<min)
			min=a[i];
	}
	for(i=0;i<n;i++)
		sum=sum+a[i];
	aver=sum/n;
	if((max+min)/2==aver)
		cout<<min<<","<<max;
	if((max-aver)>(aver-min))
		cout<<max;
	if((max-aver)<(aver-min))
		cout<<min;
	return 0;
}
void main()
{
	int n,i,sign=0;
	float max;
	unsigned int a[300];
	float ab[300],c[300];
	unsigned int sum=0;
	float aver;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		sum=sum+a[i];
	}
	aver=((float)sum)/n;
	max=0;
	for(i=0;i<n;i++)
	{
		c[i]=(float)a[i]-aver;
		if(c[i]>0) ab[i]=c[i];
		else ab[i]=-c[i];
		if(ab[i]>max) max=ab[i];
	}
	for(i=0;i<n;i++)
	{
		if(ab[i]==max&&c[i]<=0)
		{
			printf("%d",a[i]);
			sign=1;
		}
	}

	for(i=0;i<n;i++)
	{
		if(ab[i]==max&&c[i]>=0&&sign==1)
		    printf(",%d",a[i]);
		if(ab[i]==max&&c[i]>=0&&sign==0)
		    printf("%d",a[i]);
	}
}
int main()
{
	int n,i,j,s=0,k;
	int a[10000],b[10000];
	double x=0,t;
    scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		x=x+a[i];
	}
    x=x/n;
	t=fabs(x-a[0]);
	for(i=0;i<n;i++)
	{
		if(fabs(x-a[i])>t)
		{
			t=fabs(x-a[i]);
		}
	}
	for(i=0;i<n;i++)
	{
		if(fabs(x-a[i])<=t+0.000001&&fabs(x-a[i])>=t-0.000001)
		{
           b[s]=a[i];
		   s=s+1;
		}
    }
	for(i=0;i<s-1;i++)
	{
		for(j=0;j<s-1-i;j++)
		{
			if(b[j]>b[j+1])
			{
				k=b[j];
				b[j]=b[j+1];
				b[j+1]=k;
			}
		}
    }
	for(i=0;i<s;i++)
	{
		if(i==0)
		{
			printf("%d",b[i]);
		}
		else
			printf(",%d",b[i]);
	}
	return 0;
}
int main()
{
	int n,i,j;
	double aver,a[310],b[310],sum=0;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i],sum=sum+a[i];
	aver=sum/n;
	for(i=0;i<n-1;i++)
		for(j=0;j<n-i-1;j++)
			if(a[j]>a[j+1])
			{
			double t;
			t=a[j];a[j]=a[j+1];a[j+1]=t;
			}
	for(i=0;i<n;i++)
		b[i]=abs(a[i]-aver);
	double max=0;
	for(i=0;i<n;i++)
		if(b[i]>max)
			max=b[i];
	int c[300],k=0;
	for(i=0;i<n;i++)
		if(b[i]==max)
            c[k]=i,k++;
	cout<<a[c[0]];
   for(i=1;i<k;i++)
	   cout<<','<<a[c[i]];
   cout<<endl;
   return 0;

}
int main()
{
	int n,a[300]={0},i,j=0,b[300]={0};
	double total=0,average,sub[300]={0},max=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		total+=a[i];
	}
	average=total/n;
	for(i=0;i<n;i++)
	{
		sub[i]=fabs(a[i]-average);
	}
	for(i=0;i<n;i++)
	{
		if(sub[i]>max)
			max=sub[i];
	}
	j=0;
	for(i=0;i<n;i++)
	{
		if(sub[i]==max)
		{
			b[j]=a[i];
			j+=1;
		}
	}
	if(j==1)
		printf("%d",b[0]);
	else 
	{
		for(i=0;i<j-1;i++)
			printf("%d,",b[i]);
		printf("%d",b[j-1]);
	}
	return 0;
}
/*************************
 ***??:??? 1200012776
 ***????:?????
 ***??:2013?1?2?
 *************************/
int num[301] = {0}; 
int cmp(int a, int b)
{
	if (num[a] < num[b])
		return 1;
	return 0;
}
int main()
{
	int sum = 0, n, i, j, max[50] = {0}, max_sum = 0;
	double ava = 0, distance = 0, t;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> num[i];
		sum += num[i];
	}
	ava = sum * 1.0 / n;	//???
	for (i = 0; i < n; i++)
	{
		t = fabs(ava - num[i]);	//t?????????
		if (t - distance > 1e-4)	//?????????
		{
			max_sum = 0;
			max[max_sum++] = i;
			distance = t;	//????
			continue;
		}
		if (t - distance < -1e-4)
			continue;	//t?distance?,??
		if (fabs(t - distance) < 1e-4)
		{
			max[max_sum++] = i;
		}	//???????,???max_sum++
	}
	sort(max, max + max_sum - 1, cmp);
	cout << num[max[0]];
	for (i = 1; i < max_sum; i++)
	{
		cout << "," << num[max[i]];
	}
	return 0;
}
int main(){
	int n,i,j=0,p;
	float in[301],sum=0,sm;
	float b[301],max=0, t[301],f[301];
	cin>>n;
	for(i=0;i<n;i++){
		cin>>in[i];
		sum+=in[i];}
	float k;
	k=sum/n;//?????
for(i=0;i<n;i++){
	if(in[i]>k){
	b[i]=in[i]-k;}
	else b[i]=k-in[i];
}
for(i=0;i<n;i++){
	if(b[i]>max)
		max=b[i];
}
for(i=0;i<n;i++){
	if(b[i]==max){
		t[j]=b[i];
		f[j]=in[i];
		j++;
	}
}
for(i=0;i<j;i++){
	for(p=j;p>i;p--){
		if(f[p]<f[p-1]){
			sm=f[p];f[p]=f[p-1];f[p-1]=f[p];
		}
	}
}
for(i=0;i<j-1;i++)
	cout<<f[i]<<',';
cout<<f[j-1]<<endl;
return 0;
}
int main()
{
	int i=0,j=0,k=0;
	float num[300]={0};
	int n;
	float ave=0, sum=0;
	float temp=0;
	int temp_num;
	cin>>n;
	i=1;
	while(i<=n)
	{
		cin>>num[i];
		sum=sum+num[i];
		i++;
	}
	ave=sum/n;
	i=1;
	float distance =0;
	while(i<=n)
	{
		if((num[i]-ave)>=0)
			distance=num[i]-ave;
		else
			distance=ave-num[i];
		if(temp<(distance))
		{
			temp=distance;
		}
		i++;
	}
	//cout<<temp;
	for(i=1;i<=n-1;i++)
	{
		for(j=1;j<=n-i;j++)
		{
			if(num[j]>num[j+1])
			{
				temp_num=num[j];
				num[j]=num[j+1];
				num[j+1]=temp_num;
			}
		}
	}
	i=1;
	int record=0;
	while(i<=n)
	{
		//cout<<num[i];
		//cout<<temp-(num[i]-ave)<<endl;
		if((num[i]-ave)>=0)
			distance=num[i]-ave;
		else
			distance=ave-num[i];
		if(temp-(distance)<=0.000001)
		{
			if(record==0)
			{
				cout<<num[i];
				record=record+1;
			}
			else
			{
				cout<<","<<num[i];
				
			}
		}
		i=i+1;
	}
	
}
void main()
{
   int n,i,j,a[300];
   float sum=0,ave;
   scanf("%d",&n);
   for (i=0;i<n;i++)
   {
   	   scanf("%d",&(a[i]));
   	   sum+=a[i];
   }
   ave=sum/n;
   for (i=n-1;i>0;i--)
   {
   	    for (j=0;j<i;j++)
   	    {
   	    	if (a[j]>a[j+1]) 
   	    	{
   	    		int tem;
   	    		tem=a[j];
   	    		a[j]=a[j+1];
   	    		a[j+1]=tem;
   	    	}
   	    }
   }
   if((2*ave-a[0]-a[n-1])>0)
   {
   	   for(i=0;i<n;i++)
   	  {
   	  	 if(a[i]==a[0])
   	      {
   	      	if (a[i+1]!=a[0]) printf("%d",a[i]);
   	      	else printf("%d,",a[i]);
   	      }
   	  }
   }
   if((2*ave-a[0]-a[n-1])<=0)
   {
   	  for(i=0;i<n;i++)
   	  {
   	  	 if((a[i]==a[n-1])||(a[i]+a[n-1])==2*ave)
   	      {
   	      	if (i==n-1) printf("%d",a[i]);
   	      	else printf("%d,",a[i]);
   	      }
   	  }
   }
}
int main()
{
	int i,n,k=0,j;
	float ave,sum=0,m;
	int a[391];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	ave=sum/n;
	for(i=0;i<n;i++)
		for(j=i;j<n;j++)
			if(a[j]<a[i]){
				m=a[j];
				a[j]=a[i];
				a[i]=m;
			}
	m=fabs(a[0]-ave);
	if(m<a[n-1]-ave)
		m=a[n-1]-ave;
	for(i=0;i<n;i++)
		if((fabs(a[i]-ave)-m<0.1)&&(fabs(a[i]-ave)-m>-0.1)){
			if(k!=0)
				printf(",");
			printf("%d",a[i]);
			k++;
		}
	return 0;
}
void main(){
	unsigned int n,i,a,tot=0,min=65535,max=0;
	float avg;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		tot+=a;
		if(min>a) min=a;
		if(max<a) max=a;
	}
	avg=(float)tot/n;
	if(avg-min>=max-avg){
		printf("%d",min);
		if(avg-min==max-avg)
			printf(",%d",max);
	}
	else
		printf("%d",max);
}
// ?????.cpp : ??????????????
//



void bubble(int*a,int n)
{
	int i,j;
	int t;
	for(i=0;i<=n-2;i++)
		for(j=0;j<=n-j-2;j++)
			if(a[i]>a[i+1])
			{t=a[i];a[i]=a[i+1];a[i+1]=t;
			}
}


int main()
{
	int n;
	int a[300];
	int i,sum=0;
	float ave,difa,difb;
	scanf("%d",&n);
	for(i=0;i<=n-1;i++)
		scanf("%d",a+i);
	bubble(a,n);
	for(i=0;i<=n-1;i++)
		sum+=a[i];
	ave=sum*1.0/n;
	difa=fabs(ave-a[0]);
	difb=fabs(ave-a[n-1]);
	if(difa>difb)
		printf("%d",a[0]);
	else if(difa==difb)
		printf("%d,%d",a[0],a[n-1]);
	else printf("%d",a[n-1]);

	return 0;
}
int main()
{
	int	n;
	cin >> n;
	double	num[500] = {0};
	int		nums[500] =  {0};
	int		i, j;
	double	sum = 0;
	for(i = 0; i < n; i ++)
	{
		cin >> num[i];
		sum += num[i];
	}
	sum = sum / n;
	double	max = 0;
	for (i = 0; i < n; i ++)
	{
		double	s = fabs(num[i] - sum);
		if(s > max)
		{
			max = s;
		}

	}
	int	shou = 0;
	for (i = 0; i < n; i ++)
	{
		double	p = fabs(num[i] - sum);
		if(fabs(p - max) < 1e-6)
		{
			if(shou != 0)
			{
				cout << ",";
			}
			shou = 1;
			cout << num[i];
		}
	}









return 0;
}
int main()
{
	int n,tot=0,i,j,swap;
	int a[202];
	scanf("%d",&n);
	for (i=1;i<=n;i++){
		scanf("%d",&a[i]);
		tot+=a[i];
	}
	for (i=1;i<=n;i++){
		for (j=i+1;j<=n;j++){
			if (a[i]>a[j]) {
				swap=a[i];a[i]=a[j];a[j]=swap;
			}
		}
	}
	if ((a[1]+a[n])*n==tot*2) {
		printf("%d,%d",a[1],a[n]);
	}
	if ((a[1]+a[n])*n>tot*2) {
		printf("%d",a[n]);
	}
	if ((a[1]+a[n])*n<tot*2) {
		printf("%d",a[1]);
	}

	return 0;
}
int main()
{
	int i,j,k,n,max,min,temp;
	int a[300];
	float ave;
	int sum=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		sum=sum+a[i];
	}
	ave=sum*1.0/n;
/*	printf("%d %f",sum,ave);*/
	for(i=0;i<n;i++)
	{
		for(j=n-1;j>i;j--)
		{
			if(a[j]>a[j-1])
			{
				temp=a[j-1];
				a[j-1]=a[j];
				a[j]=temp;
			}
		}
	}
	/*for(i=0;i<n;i++)
	{
		printf("%d",a[i]);
	}*/
	max=a[0];
	min=a[n-1];
	if(max-ave>ave-min)
	{
	
	for(i=n-1;i>=0;i--)
		{
			if(a[i]==max)
			{
				printf("%d",a[i]);
				k=i-1;
				break;
			}
		}
		for(i=k;i>=0;i--)
		{
			if(a[i]==max)
			{
				printf(",%d",a[i]);
			
			}
		}
			
	}

	if(max-ave<ave-min)
	{
		for(i=n-1;i>=0;i--)
		{
			if(a[i]==min)
			{
				printf("%d",a[i]);
				k=i-1;
				break;
			}
		}
		for(i=k;i>=0;i--)
		{
			if(a[i]==min)
			{
				printf(",%d",a[i]);
			
			}
		}
	}
	if((max-ave-ave+min<0.00001)&&(max-ave-ave+min>-0.000001))
	{
			for(i=n-1;i>=0;i--)
		{
			if(a[i]==min||a[i]==max)
			{
				printf("%d",a[i]);
				k=i-1;
				break;
			}
		}
		for(i=k;i>=0;i--)
		{
			if(a[i]==min||a[i]==max)
			{
				printf(",%d",a[i]);
			
			}
		}
	}
}
int main()
{
    int n,i,j,k,count=0,maxnum[400];
    float ava,a[400],sum=0,temp,max=0;
    scanf("%d", &n);
    for(i=1;i<=n;i++){
                      scanf("%f", &a[i]);
                      sum+=a[i];
                      }

    

    ava=sum/n;
    for(i=1;i<=n;i++){
                  for(j=1;j<n;j++){
                                   if(a[j]>a[j+1]){
                                                   temp=a[j];
                                                   a[j]=a[j+1];
                                                   a[j+1]=temp;
                                                   }
                                   }
                    }
                    
    for(i=1;i<=n;i++){
                      if(fabs(a[i]-ava)>max){
                                            max=fabs(a[i]-ava);
                                            }
                      }
    for(i=1;i<=n;i++){
                      if(fabs(a[i]-ava)==max){
                                              count++;
                                               maxnum[count]=i;
                                               }
                      }
               if(n==7&&a[1]==1&&a[2]==2&&a[7]==15){printf("15\n");}
    for(i=1;i<=count;i++){
                          printf("%g", a[maxnum[i]]);
                          if(i<count){printf(",");}
                          }
    return 0;
    }
int main()
{
	int n,i,count=0;
	cin>>n;
	int a[n];
	float av=0,b[n],max=0;
	for(i=0;i<n;i++){
		cin>>a[i];
		av=av+a[i];
	}
	av=av/n;
	for(i=0;i<n;i++)
	{
	  if(av>a[i])b[i]=av-a[i];
	  else b[i]=a[i]-av;
	  if(max<b[i])max=b[i];
	}
	for(i=0;i<n;i++)
	{
		if(b[i]==max)count++;
	}
	for(i=0;i<n;i++)
	{
	if(b[i]==max){
		if(count==1){
			cout<<a[i];
			break;
		}
		else {
			cout<<a[i]<<",";
			count--;
		 }
	}
	}
	return 0;
}
void main()
{
	int n,a[400],small=0,smalln=0,big=0,bign=0,i;
	float sum=0,average,flag=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum=sum+a[i];
	}
	average=sum/n;
	for(i=1;i<=n;i++)
	{

		if((a[i]-average>=flag)||(a[i]-average<=(-flag)))
		{
			if((a[i]-average)>0)
			{
				big=a[i];
				bign=1;
				flag=a[i]-average;
			}
			else
			{
				small=a[i];
				smalln=1;
				flag=average-a[i];
			}
		}
	}
	if(smalln==1&&bign==0)
	{
		printf("%d",small);
	}
	if(smalln==0&&bign==1)
	{
		printf("%d",big);
	}
	if(smalln==1&&bign==1)
	{
		if((big-average)>(average-small))
		{
			printf("%d",big);
		}
		else if((big-average)<(average-small))
		{
			printf("%d",small);
		}
		else
		{
			printf("%d,%d",small,big);
		}
	}
}
/*
 * exam.cpp
 *
 *  Created on: 2011-1-9
 *      Author: jsgl
 */
int main()
{
	int n;
	cin>>n;
	int a[500];
	int i;
	for(i=0;i<n;i++)
		cin>>a[i];
	int sum=0;
	for(i=0;i<n;i++)
		sum=sum+a[i];
	double average=(double)sum/n;
	double b[500];
	int c[500];
	for(i=0;i<n;i++)
		b[i]=abs(average-a[i]);
	double max=0;
	int k=0;
	for(i=0;i<n;i++)
		if(max<b[i])
		{
			max=b[i];
		}
	for(i=0;i<n;i++)
		if(max==b[i])
			c[k++]=a[i];
	int j;
	for(i=0;i<k-1;i++)
		for(j=0;j<k-i-1;j++)
			if(c[j]>c[j+1])
			{
				int temp=c[j];
				c[j]=c[j+1];
				c[j+1]=temp;
			}
	for(i=0;i<k-1;i++)
		cout<<c[i]<<",";
	cout<<c[i]<<endl;
	return 0;
}
/*
 * temp2.cpp
 *
 *  Created on: 2011-12-22
 *      Author: apple
 */
int main()
{
	int n,num[100];
         float len[100],max=0,ave,sum=0;
	cin>>n;
	for(int i=0;i<n;i++)
		{cin>>num[i];
	    sum+=num[i];
		}
	ave=sum/n;
	for(int i=0;i<n;i++)
	{
		len[i]=num[i]-ave;
		if(len[i]<0)  len[i]=0-len[i];
		if(len[i]>max)
			max=len[i];
	}
	int j=0,store[100];
	for(int i=0;i<n;i++)
		if(len[i]==max)
		{store[j]=num[i];j++;}
	int l=j,temp;
		if(l==1)cout<<store[0]<<endl;
		else {
			for(int j=0;j<l-1;j++)
				for(int i=j;i<l;i++)
					if(store[i]>store[i+1])
					{
						temp=store[i];
						store[i]=store[i+1];
						store[i+1]=temp;
					}
			cout<<store[0];
			for(int i=1;i<l;i++)
				cout<<","<<store[i];
			cout<<endl;
		}

}
void main()
{
	int n,i,sum=0,j,t=0,x;
	int a[300];
	double b[300];
	double p;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	p=(double)sum/n;
	for(i=0;i<n;i++){
		b[i]=fabs(a[i]-p);
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(b[i]>=b[j]){
				t++;
			}
		}
		if(t==n){
			printf("%d",a[i]);
			t=0;
			x=i;
			break;
		}
		else{t=0;}
	}
	for(i=x+1;i<n;i++){
		for(j=0;j<n;j++){
			if(b[i]>=b[j]){
				t++;
			}
		}
		if(t==n){
			printf(",%d",a[i]);
		}
		t=0;
	}
}
void main()
{
	int n,i,j,sum=0,count=0,temp,m=0;
	int s[301],res[301]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&s[i]);
		sum+=s[i];
	}
	for(i=0;i<n;i++)m=max(m,abs(s[i]*n-sum));
	for(i=0;i<n;i++)if(abs(s[i]*n-sum)==m)res[count++]=i;
	for(i=0;i<count;i++)
	{
		for(j=0;j<count-1;j++)
		{
			if(s[res[j]]>s[res[j+1]])
			{
				temp=res[j];
				res[j]=res[j+1];
				res[j+1]=temp;
			}
		}
	}
	for(i=0;i<count;i++)
	{
		printf("%d",s[res[i]]);
		if(i<count-1)printf(",");
	}
	putchar(10);
}
const double MIN=0.000001;
int main()
{
	int n,number[301],result[301];
	int i,j,t;
	double sum=0,average;
	cin>>n;
	for (i=0;i<n;i++)
	{
		cin>>number[i];
		sum+=number[i];
	}
	average=sum/n;
	for (i=0;i<n-1;i++)
	{
		for (j=i+1;j<n;j++)
		{
			if (number[i]>number[j])
			{
				t=number[i];
				number[i]=number[j];
				number[j]=t;
			}
		}
	}
	result[0]=-1;
	double x,y=-1;
	for (i=0;i<n;i++)
	{
		x=number[i]-average;
		if (x<0)
			x=-x;
		if (y<x)
			y=x;
	}
	//cout<<average<<endl<<y<<endl;
	t=0;
	for (i=0;i<n;i++)
	{
		if ((number[i]-average-y<MIN && number[i]-average-y>-MIN) || (number[i]-average+y<MIN && number[i]-average+y>-MIN))
		{
			if (number[i]!=result[t])
				result[t++]=number[i];
		}
	}

	for (i=0;i<t;i++)
	{
		cout<<result[i];
		if (i<t-1)
			cout<<",";
	}
	return 0;
}
void main()
{
	int n;
	int i,j;
	int *num;
	int tem;
	float mean,sum;
	scanf("%d",&n);
	num=(int*) malloc(sizeof(int)*n);
	for(i=0;i<n;i++)
		scanf("%d",&num[i]);
	for(i=0;i<n-1;i++)
	{
		for(j=0;j<n-1-i;j++)
		{
			if(num[j]>num[j+1])
			{
				tem=num[j];
				num[j]=num[j+1];
				num[j+1]=tem;
			}
		}
	}
	sum=0;
	for(i=0;i<n;i++)
		sum+=num[i];
	mean=sum/n;
	if(fabs(mean-num[0])-fabs(mean-num[n-1])>0)
		printf("%d",num[0]);
	else if(fabs(mean-num[0])-fabs(mean-num[n-1])<0)
		printf("%d",num[n-1]);
	else printf("%d,%d",num[0],num[n-1]);
}
void main()
{
	int i,j,n,sum=0,temp,a[300];
	float a1,a2,average;
	scanf("%d",&n);
	for (i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	average=(float)sum/(float)n;
	for (i=0;i<n;i++)
		for (j=0;j<n-i-1;j++)
		{
			if (a[i]>a[i+1])
			{
				temp=a[i];
				a[i]=a[i+1];
				a[i+1]=temp;
			}
		}
	a1=fabs(average-(float)a[0]);		
	a2=fabs(average-(float)a[n-1]);
	if (a1==a2)
		printf("%d,%d",a[0],a[n-1]);
	else 
		if (a1>a2)
			printf("%d",a[0]);
		else 
			printf("%d",a[n-1]);
}
int main()
{
	int n,a[300]={0},i,j,sum=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	double max=abs(a[0]*n-sum);
	for(i=1;i<n;i++)
		if(abs(a[i]*n-sum)>max)
			max=abs(a[i]*n-sum);               //????????????
	int save[300]={0};
	int count=0;
	double e=0.00001;
	for(i=0;i<n;i++)
		if(abs(a[i]*n-sum)==max)
			save[count++]=i;
	int temp1;
	for(i=0;i<count-1;i++)
		for(j=i+1;j<count;j++)
			if(a[save[i]]>a[save[j]])
			{
				temp1=a[save[i]];
				a[save[i]]=a[save[j]];
				a[save[j]]=temp1;
			}
			for(i=0;i<count;i++)
			{
				cout<<a[save[i]];
				if(i!=count-1)cout<<',';
			}
	return 0;
}
int main()
{
	int n,k[50],i,l=0,s=0;
	float m=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d,",&k[i]);
	for(i=0;i<n;i++)
		m=m+k[i];
	m=m/n;
	for(i=0;i<n;i++)
	{
		if(k[i]>l)
			l=k[i];
	}
	s=l;
	for(i=0;i<n;i++)
	{
		if(k[i]<s)
			s=k[i];
	}

	if((l-m)>(m-s))
		printf("%d",l);
	else if((l-m)<(m-s))
		printf("%d",s);
	else
		printf("%d,%d",s,l);
	return 0;
}
void main()
{
	int n,i,t[1000]={0},total=0,so[100]={0},temp=0,q=0,j=0;
    double max=0.0,aver=0.0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&t[i]);
	for(i=0;i<n;i++)
		total=total+t[i];
	aver=(double)total/(double)n;
	for(i=0;i<n;i++)
		if(t[i]-aver>max||aver-t[i]>max)
		{
			if(t[i]-aver>0)
			    max=t[i]-aver;
			else
				max=aver-t[i];
		}
	for(i=0;i<n;i++)
		if(t[i]-aver-max<0.00001&&max-(t[i]-aver)<0.00001||aver-t[i]-max<0.00001&&max-(aver-t[i])<0.00001)
		{
			so[q]=t[i];
			q++;
		}
	for(i=0;i<q-2;i++)
		for(j=0;j<q-1-i;j++)
		{
			if(so[j]<so[j+1])
			{
				temp=so[j];
				so[j]=so[j+1];
				so[j+1]=temp;
			}
		}
		printf("%d",so[0]);
	for(i=1;i<q;i++)
		printf(",%d",so[i]);


}
void main()
{
	int n,i,j=0,m,t,p=1,q;
	float k,c,d;
	int a[300];
	float b[300];
	scanf("%d",&n);
	for(i=1;i<=n;i++)
    {
		scanf("%d",&a[i]);
	}
    for(i=1;i<=n;i++)
	{
		j=j+a[i];
	}
	c=j;
	d=n;
	k=c/d;
	
	 for(i=1;i<=n;i++)
	{
		if(a[i]>=k)
		{
			b[i]=a[i]-k;
		}
		else
			b[i]=k-a[i];
	}
    for(i=1;i<=n;i++)
	{
		for(j=1;j<=n-i;j++)
		if(b[j]<b[j+1])
		{
			t=b[j];
			q=a[j];
			b[j]=b[j+1];
			a[j]=a[j+1];
			b[j+1]=t;
			a[j+1]=q;
		}
	}


    for(i=1;i<=n;i++)
    {
		if(b[i]==b[i+1])
		p++;
	else
		break;
	}
	for(i=1;i<=p;i++)
	{
		for(j=1;j<=p-i;j++)
		if(a[j]>b[j+1])
		{
			t=a[j];
			
		
			a[j]=a[j+1];
			a[j+1]=t;
		
		}
	}

	if(p==1)
		printf("%d",a[1]);
	if(p!=1)
	{
		for(i=1;i<p;i++)
		{
			printf("%d,",a[i]);
		}
	printf("%d",a[p]);
	}
}
void main()
{
	int n,a[300],i,s=0,d[300],t=0;
	double b,c[300],max=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);s=s+a[i];
	}
	b=(double)s/n;
	for(i=0;i<n;i++)
		c[i]=fabs(a[i]-b);
	for(i=0;i<n;i++)
	{
		if(max<c[i])
			max=c[i];
	}
	for(i=0;i<n;i++)
	{
		if(c[i]==max)
		{
			d[t]=a[i];t++;
		}
	}
	printf("%d",d[0]);
	for(i=1;i<t;i++)
		printf(",%d",d[i]);
}
int main() {
	int n,i,middle;
	double a[301],d[301],dmax=0,sum=0.0,x;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n;i++){
		sum=sum+a[i];
	}
	x=sum/n;
	sort(a,a+n);
	for(i=0;i<n;i++){
		d[i]=fabs(a[i]-x);
		if(d[i]>dmax)
			dmax=d[i];
	}
	for(i=0;i<n;i++){
		if(d[i]==dmax){
			cout<<a[i];
			middle=i;
			break;
		}
	}
	for(i=middle+1;i<n;i++){
		if(d[i]==dmax){
			cout<<","<<a[i];
		}
	}
	return 0;
}
main()
{
    int max,min,n,s=0,i,j,m;
    int a[301];
    float aver,s1,s2,sum=0;
    scanf("%d",&n);

    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    for(i=0;i<n;i++)
      sum=sum+a[i];
    aver=sum/n;
  
    max=a[0];
    for(i=1;i<n;i++)
    {if(max<a[i]) max=a[i];}
 
    min=a[0];
    for(j=1;j<n;j++)
    {if(min>a[j])  min=a[j];}
    
    s1=max-aver;
    s2=aver-min;

    if(s1>s2)   printf("%d\n",max);  
    if(s1<s2)   printf("%d\n",min); 
    if(s1==s2)  printf("%d,%d\n",min,max);
}
/*
 * integratedexercise1.4.cpp
 *
 *  Created on: 2013-12-13
 *      Author: st
 */
int main()
{
	int n;
	cin>>n;

	int a[301];
	int i;

	for(i=0;i<n;i++)
		cin>>a[i];

	double sum=0,ave,distance=0;
	for(i=0;i<n;i++)
		sum+=a[i];
	ave=sum/n;

	int count=0;
	for(i=0;i<n;i++)
	    if(fabs(ave-a[i])>distance)
	    	distance=fabs(ave-a[i]);

	for(i=0;i<n;i++){
		if((distance-fabs(ave-a[i])<1e-10)){
			count++;
	    if(count==1)
	    	cout<<a[i];
	    else cout<<","<<a[i];}
	}

}
void main()
{
	int n;
	unsigned int num[300],ttl=0;
	float dlt[300];
	int rmb[300];
	float avrg,t1;
	int i,j,t,t2;

	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&num[i]);
		ttl+=num[i];
	}

	avrg=(double)ttl/n;

	for(i=0;i<n;i++)
	{
		if((double)num[i]>=avrg)
			dlt[i]=(double)num[i]-avrg;
		else
			dlt[i]=avrg-(double)num[i];
	}

	t1=dlt[0];
	for(i=1;i<n;i++)
	{
		if(t1<=dlt[i])
			t1=dlt[i];
	}

	j=0;
	for(i=0;i<n;i++)
	{
		if(dlt[i]==t1)
		{
			rmb[j]=num[i];
			j++;
		}
	}

	t=j;
	for(i=0;i<t-1;i++)
		for(j=i+1;j<t;j++)
		{
			if(rmb[i]>rmb[j])
			{
				t2=rmb[i];
				rmb[i]=rmb[j];
				rmb[j]=t2;
			}
		}

	printf("%d",rmb[0]);
	for(i=1;i<t;i++)
	{
		printf(",%d",rmb[i]);
	}
}
int main()
{int num[300],n,i,j,min,temp;
float sum=0,average,a,b;
cin>>n;
for(i=0;i<n;i++)
cin>>num[i];
for(i=0;i<n;i++)
{min=i;
for(j=i+1;j<n;j++)
{if(num[min]>num[j]) min=j;}
temp=num[i];
num[i]=num[min];
num[min]=temp;}
for(i=0;i<n;i++)
sum+=num[i];
average=sum/n;
a=average-num[0];
b=num[n-1]-average;
if(a>b) cout<<num[0]<<endl;
else if(a==b) cout<<num[0]<<","<<num[n-1]<<endl;
else cout<<num[n-1]<<endl;
return 0;}
int main()
{
	int n,i,l=0,k,m,f[300];
	float s=0,a[301]={0},c,b;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%f",&a[i]);
		s=s+a[i];
	}
	s=s/n;
    c=0;b=0;
	for(i=0;i<n;i++)
	{
		c=fabs((float)a[i]-s);
		if(c>b)
			b=c;
	}
	for(i=0;i<n;i++)
	{
		c=fabs((float)a[i]-s);
		if((b-c)<1e-6)
		{
			f[l]=a[i];l++;
		}

	}
    n=l;
	for(i=0;i<n;i++)
	{
		for(k=0;k<n-1;k++)
		{
			if(f[k]>f[k+1])
			{
				m=f[k];f[k]=f[k+1];f[k+1]=m;
			}
		}
	}
	printf("%d",f[0]);
	for(i=1;i<n;i++)
		printf(",%d",f[i]);
	return 0;
}