semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
void main()
{
	int max,min,x,i,n,s=0;
	scanf("%d",&n);
	scanf("%d",&max);
	min=max;
	s=max;
	for(i=1;i<n;i++)
	{scanf("%d",&x);
	if(x>max)max=x;
	else
		if(x<min)min=x;
	s=s+x;}
	if(abs(min*n-s)==abs(max*n-s))printf("%d,%d",min,max);
	else
		if(abs(min*n-s)<abs(max*n-s))printf("%d",max);
		else printf("%d",min);
}
int main()
{
	double a[320]={0};
	double sum=0;
	int num=0;
	int i,j;
	double average=0;
	double b[320]={0},t;
	double c[400]={0};
	double max=0;
	double n;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		sum=sum+a[i];
	}
	//cout<<sum;
	average=sum/n;
	//cout<<average;
	for(i=0;i<n;i++)
	{
		b[i]=fabs(a[i]-average);
		//cout<<"b"<<i<<b[i]<<" ";
		if(max<b[i])
			max=b[i];
	}
	//cout<<"max "<<max;
	for(i=0;i<n;i++)
	{
		if(b[i]==max)
		{
			c[num]=a[i];
			num++;
		}
	}
	//cout<<"check "<<c[0]<<" "<<c[1]<<endl;
	for(i=0;i<num-1;i++)
		for(j=0;j<num-i-1;j++)
		{
			if(c[j]>c[j+1])
			{
				t=c[j];
				c[j]=c[j+1];
				c[j+1]=t;
			}
		}
	cout<<c[0];
	for(i=1;i<num;i++)
		cout<<","<<c[i];
	return 0;
}
void sort(int a[],int n)
{
     int i,j,mark,b;
     for(i=0;i<n;i++)
     {
          mark=i;
          for(j=i;j<n;j++)
          {
                if(a[j]<a[mark])
                    mark=j;
          }
          if(mark!=i)
          {
                b=a[i];
                a[i]=a[mark];
                a[mark]=b;
          }
     }
}

int main()
{
	int n,i,j=0,a[305];
	float aver=0,x,y;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
         scanf("%d",&a[i]);
         aver+=a[i];
    }
    aver/=n;
    sort(a,n);
    x=aver-a[0];
    y=a[n-1]-aver;
    if(x-y>0.01)
    {
        printf("%d",a[0]);
        for(i=1;i<n;i++)
        {
             if(a[i]==a[0]) printf(",%d",a[i]);
             else break;
        }
    }
    if(y-x>0.01)
    {
        for(i=1;i<n;i++)
        {
             if(a[i]==a[n-1])
             {
                  printf("%d",a[i]);
                  break;
             }
        }
        if(i!=n-1)
        {
        for(i=i+1;i<n;i++)
             if(a[i]==a[n-1]) printf(",%d",a[i]);
        }
    }
    if(fabs(x-y)<1e-6)
    {
        printf("%d",a[0]);
        for(i=1;i<n;i++)
            if(a[i]==a[0]||a[i]==a[n-1]) printf(",%d",a[i]);
    }
}
int main ()
{
	int n;
	int a[310]={0};
	cin>>n;
	int sum = 0;
	for (int i=0;i<n;i++){
		cin>>a[i];
		sum += a[i];
	}
	double average = (double)sum/(double)n;
	for (int i=0;i<n-1;i++)
		for (int j=0;j<n-1-i;j++)
			if (a[j]>a[j+1]){
				int t;
				t = a[j]; a[j] = a[j+1]; a[j+1] = t;
			}
	int maxp[310]={0},num = 0;
	double dmax = 0;
	for (int i=0;i<n;i++){
		double d = fabs((double)a[i]-average);
		if (d > dmax)
			dmax = d;
	}
	for (int i=0;i<n;i++){
		double d = fabs((double)a[i]-average);
		if (fabs(d-dmax)<1e-8)
			maxp[num++] = i;
	}
	for (int i=0;i<num-1;i++)
		cout<<a[maxp[i]]<<",";
	cout<<a[maxp[num-1]];
	return 0;
}
int n;
int num[100];
int i;
int min=10000,max=-1,total=0;
int main(void)
{
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&num[i]);
		if(num[i]<min)
			min=num[i];
		if(num[i]>max)
			max=num[i];
		total+=num[i];
	}
	if(total-min*n==max*n-total)
		printf("%d,%d\n",min,max);
	else
		if(total-min*n<max*n-total)
		{
			printf("%d\n",max);
		}
		else if(total-min*n>max*n-total)
			printf("%d\n",min);
}
void main()
{
	int n,i,max,min,p;
	float av,sum=0,a[100];
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%f",&a[i]);
	for(i=0;i<n;i++)
		sum=sum+a[i];
	av=sum/n;
	max=min=a[0];
	for(i=1;i<n;i++)
	{
		max=a[i]>max?a[i]:max;
		min=a[i]>min?min:a[i];
	}
	p=max+min;
	if(2*av==p)
		printf("%d,%d\n",min,max);
	else if(2*av>p)
		printf("%d\n",min);
	else if(2*av<p)
		printf("%d\n",max);
}
void main()
{
	int n,i,j,k,t=0;
	float ave=0.0,a[300],b[300],max=0.0,p=0.0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%f",&a[i]);
		ave=ave+a[i];
		
		
	}
	ave=ave/n;
	for(i=0;i<n;i++)
	{
		b[i]=a[i]-ave;
		if(b[i]<0)
			b[i]=-b[i];
	//	printf("%f\n",b[i]);
	}
	max=b[0];
	for(i=0;i<n;i++)
	{
		if(b[i]>max)
			max=b[i];
	}
	k=0;
	for(i=0;i<n;i++)
	{
		if(b[i]==max)
			k=k+1;
	}
	if(k==1)
	{
		for(i=0;i<n;i++)
		{
			if(b[i]==max)
				printf("%d",(int)a[i]);
		}
	}
	else
	{
		for(i=0;i<n;i++)
		{
			for(j=0;j<n-1-i;j++)
			{
				if(a[i]>a[i+1])
				{
					p=a[i];
					a[i]=a[i+1];
					a[i+1]=p;
				}
			}
		}
		t=0;
    	for(i=0;i<n;i++)
		{
			if(b[i]==max)
			{
				t=t+1;
				if(t==1)
					printf("%d",(int)a[i]);
				else
					printf(",%d",(int)a[i]);
			}
		}
	}
}
const double MIN=0.000001;
int main()
{
	int n,number[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;
			}
		}
	}
	if (average-number[0]==number[n-1]-average)
		cout<<number[0]<<","<<number[n-1]<<endl;
	else if (average-number[0]>number[n-1]-average)
		cout<<number[0]<<endl;
	else if (average-number[0]<number[n-1]-average)
		cout<<number[n-1]<<endl;
	return 0;
}
int main()
{
	int n,i,s,max;
	int a[10000];
	scanf("%d",&n);
	s=0;
	for (i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		s=s+a[i];
	}
	max=0;
	for (i=1;i<=n;i++)
		if (abs(a[i]*n-s)>max) max=abs(a[i]*n-s);
	for (i=1;i<=n;i++)
		if (abs(a[i]*n-s)==max)
		{
			printf("%d",a[i]);
			break;
		}
	i++;
	for (;i<=n;i++)
		if (abs(a[i]*n-s)==max) printf(",%d",a[i]);

	return(0);
}
int main()
{
	int i, j, n;
	int sum[300], t1;
	double ave = 0.0, t, a[300];
	cin >> n;
	for(i = 1; i <= n; i++)
	{
		cin >> sum[i];
		ave = ave + sum[i];
	}
	ave = ave / n;
	for(i = 1; i <= n; i++)
	{
		a[i] = fabs(sum[i] - ave);
	}
	for(i = 1; i < n; i++)
	{
		for(j = 1; j <= n - i; j++)
		{
			if(a[j] - a[j + 1] < 0)
			{
				t = a[j];
				a[j] = a[j + 1];
				a[j + 1] = t;
				t1 = sum[j];
				sum[j] = sum[j + 1];
				sum[j+ 1] = t;
			}
		}
	}
	if(a[1] - a[2] < 0.000001)
	{
		if(sum[1] < sum[2])
			cout << sum[1] << "," << sum[2] << endl;
		else
			cout << sum[2] << "," << sum[1] << endl;
	}
	else
		cout << sum[1] << endl;
	return 0;
}
int main ()
{  int i,m,n,sum=0,max,min;
   int num[300];
   scanf("%d",&n);
   for(i=0;i<n;i++)
	  { scanf("%d",&num[i]);
         sum+=num[i];
	  }
   max=num[0];
   min=num[0];
   for(i=0;i<n;i++)
   {  if(num[i]>max) max=num[i];
      if(num[i]<min) min=num[i];
   }
   m=2*sum-n*(max+min);
   if(n==1) printf("%d",num[0]);
   if(m>0) printf("%d",min);
   if(m==0&&n!=1) printf("%d,%d",min,max);
   if(m<0) printf("%d",max);
   return 0;
}
/*
 * 1.cpp
 *
 *  Created on: 2011-1-9
 *      Author: jsgl
 */
int main()
{
	int n, i, max, min;
	double sum, k;
	int a[305];
	cin>>n;
	cin>>a[0];
	max=min=a[0];
	sum=a[0];
	for(i=1; i<n; i++)
	{
		cin>>a[i];
		sum=sum+a[i];
		if(a[i]>max) max=a[i];
		if(a[i]<min) min=a[i];
	}
	k=(double)sum/n;
    if((max-k)>(k-min)) cout<<max;
    else if((max-k)<(k-min)) cout<<min;
    else cout<<min<<","<<max;
	return 0;
}
int main()
{
  unsigned int n;
  int j,a[N],c[N],i,temp,k=0;
  float ave,sum=0,b[N],d=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
  scanf("%d",&a[i]);
  sum=sum+a[i];
  }
  for(i=0;i<n-1;i++)
  for(j=0;j<n-i-1;j++)
  if(a[j]>a[j+1])
  {
       temp=a[j];
       a[j]=a[j+1];
       a[j+1]=temp ;
  }
  ave=sum/n;
  for(i=0;i<n;i++)
  {
   b[i]=fabs(a[i]-ave);
   if(b[i]>d)
    d=b[i];
  }
  for(i=0;i<n;i++)
  if(b[i]==d)
  {
  c[k]=a[i];
  k++;
  }
    printf("%d",c[0]);
    if(k>1)
    {
    for(i=1;i<k;i++)
    printf(",%d",c[i]);
    }
    return 0;
}
void main()
{
	int n,i,t=0;
	float pj=0.0,max,a[300],b[300];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{	scanf("%f",&a[i]);pj=pj+a[i];}
	pj=pj/n;							//	printf("pj%f\n",pj);
	for(i=0;i<n;i++)
	{if(a[i]>pj)b[i]=a[i]-pj;else b[i]=pj-a[i];}
	max=b[0];
	for(i=1;i<n;i++)
		if(max<b[i])max=b[i];			//printf("max%f\n",max);
		for(i=0;i<n;i++)
			{	if(b[i]==max&&t==0){printf("%d",(int)a[i]);t++;}
				else if(b[i]==max)printf(",%d",(int)a[i]);}
}
void main()
{
	int n;
	int i,j;
	int tem;
	int ori[301];
	float sum=0,E=0;

	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&ori[i]);
	}
	for(i=0;i<n-1;i++)
		for(j=1;j<n-i;j++)
		{
			if(ori[j]<ori[j-1])
			{
				tem=ori[j-1];ori[j-1]=ori[j];ori[j]=tem;
			}
		}
	for(i=0;i<n;i++)
	{
		sum+=ori[i];
	}
	E=sum/n;
	if(0.001>fabs((float)(ori[0]+ori[n-1])/2-E))
	     printf("%d,%d\n",ori[0],ori[n-1]);
	else if(E<(ori[0]+ori[n-1])/2.0)
		printf("%d\n",ori[n-1]);
	     else
			 printf("%d\n",ori[0]);
}
void main()
{
   int a[400],i,j,n,l,s=0,t=0,r;
   float x,z;
   scanf("%d",&n);
   for(i=0;i<n;i++)
   {
        scanf("%d",&a[i]);
        s=s+a[i];
   }
   for(i=0;i<n;i++)
   { 
      for(j=i+1;j<n;j++)
      {
          if(a[j]<a[i])
          {
              l=a[i];
              a[i]=a[j];
              a[j]=l;
           }
       }
   }
   x=(float)s/(float)n;
   z=(float)a[0]+(float)a[n-1]-2*x;
   if(z<0.001&&z>-0.001)
   {
      for(i=0;i<n;i++)
      {
          if(a[i]==a[0]||a[i]==a[n-1])
          { 
               if(t==1)
               printf(",");
               printf("%d",a[i]);
               t=1;
           }
       }
   }
    else
    {
       t=0;
       r=z>0?a[n-1]:a[0];
       for(i=0;i<n;i++)
      {
          if(a[i]==r)
          { 
               if(t==1)
               printf(",");
               printf("%d",a[i]);
               t=1;
           }
       }
     }
}
void main()
{
	int n,i,a[400],j=0,l=0,b[400],g,c;
	float s=0,m,k=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		s=s+a[i];
	}
	s=s/n;
	for(i=0;i<n;i++)
	{
		m=a[i]-s;
		if((k>=0)&&(m>=k||m<=-k))
		{
			k=m;
		}
		else if((k<0)&&(m<=k||m>=-k))
		{	k=m;
		}
	}
	for(i=0;i<n;i++)
	{
		m=a[i]-s;
		if(m==k||m==-k)
		{
			b[j]=a[i];j++;
		}
	}
	for(i=0;i<j;i++)
	{
		for(g=0;g<i;g++)
		{
			if(b[g]>=b[i])
			{
                c=b[g];b[g]=b[i];b[i]=c;
			}
		}
	}
	for(i=0;i<j;i++)
	{
		if(i!=j-1)
			printf("%d,",b[i]);
		else printf("%d",b[i]);
		
	}
}
int main()
{
	int n,a[300],i,sum=0,m=0,c[2],j=0;
	float aver,cha[300],max;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		sum=sum+a[i];
	}
	aver=(float)sum/n;
	for(i=0;i<n;i++)
	{
		if(a[i]>aver)
			cha[i]=(float)(a[i]-aver);
		else
			cha[i]=(float)(aver-a[i]);
	}
	for(i=0;i<n;i++)
	{
		if(cha[i]>max)
			max=cha[i];
	}
	for(i=0;i<n;i++)
	{
		if(cha[i]==max)
		{
			c[j]=a[i];
			j++;
			m++;

		}
	}
	if(m==1)
		printf("%d\n",c[0]);
	else
		printf("%d,%d\n",c[0],c[1]);
}
void main()
{
	int n,a[300],i,j=0,v[2];
	double p,u,w;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		j=j+a[i];
	}
	p=(float)j/(float)n;
	for(i=0;i<n;i++)
	{
		if(i==0)
		{
			v[0]=i;
			v[1]=i;
			if((float)a[i]>=p)
				u=(float)a[i]-p;
			else
				u=p-(float)a[i];
		}
		else
		{
			if((float)a[i]>=p)
				w=(float)a[i]-p;
			else
				w=p-(float)a[i];
			if(w>u)
			{
				v[0]=i;
				v[1]=i;
				u=w;
			}
			else if(w==u)
			{
				v[1]=i;
			}
		}
	}
	if(a[v[0]]==a[v[1]])
		printf("%d",a[v[0]]);
	else
		printf("%d,%d",a[v[0]],a[v[1]]);
}
void main()
{
	int n,i=0,j=1,k=0,t=0;
	int a[500]={0},b[300]={0};
	double sum=0,ave=0,c=0,d=0;

	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		sum=sum+a[i];
	}
	ave=sum/n;
	b[0]=a[0];
	c=ave-b[0];
	if(c<0) c=-c;
	for(i=1;i<n;i++)
	{
		d=ave-a[i];
		if(d<0) d=-d;
		if(d>c) 
		{
			b[0]=a[i];
			c=d;
		}
		else if(d==c) 
		{
			b[j]=a[i];
			j++;
		}
	}

	if(j==1) printf("%d",b[0]);
	else 
	{
		for(i=0;i<j-1;i++)
			for(k=0;k<j-1-i;k++)
			{
				if(b[k]>b[k+1])
				{
					t=b[k];
					b[k]=b[k+1];
					b[k+1]=t;
				}
			}
	for(i=0;i<j;i++)
		if(i==0) printf("%d",b[i]);
		else
		printf(",%d",b[i]);
	}
}
int main() {
	int s = 0, a[310] = { 0 }, b[310] = { 0 }, t = 0;
	int n, k = 0, max = -10000;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s = s + a[i];
	}
	for (int i = 0; i < n; i++) {
		if (abs(s - n * a[i]) > max) {
			max = abs(s - n * a[i]);
		}
	}
	for (int i = 0; i < n; i++) {
		if (abs(s - n * a[i]) == max)
			b[k++] = a[i];
	}
	for (int i = 0; i < k; i++) {
		for (int j = i + 1; j < k; j++) {
			if (b[i] > b[j]) {
				t = b[i];
				b[i] = b[j];
				b[j] = t;
			}
		}
	}
	for (int i = 0; i < k; i++) {
		cout << b[i];
		if (i != k - 1)
			cout << ',';
	}
	return 0;
}
int main()
{
	double a[302], b[302] = {0};
	double num = 0, average = 0, k;
	int n, p = 0, i, j;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> a[i];
		num = num + a[i];
	}
	average = num / n;
	k = fabs(a[0] - average);
	for (i = 0; i < n; i++)
	{
		if (fabs(a[i] - average) > k)
		{
			p = 1;
			k = fabs(a[i] - average);
			b[p] = a[i];
		}
		else
			if (fabs(a[i] - average) == k)
			{
				p++;
				b[p] = a[i];
			}
	}
	for (i = 1; i <= p; i++)
	{
		for (j = 1; j <= p - i; j++)
		{
			if (b[j] > b[j + 1])
			{
				k = b[j];
				b[j] = b[j + 1];
				b[j+ 1] = b[j];
			}
		}
	}
	for (i = 1; i <= p; i++)
	{
		if (i == 1)
			cout << b[i];
		else
			cout << "," << b[i];
	}
	cout << endl;
	return 0;
}
void main()
{
	int n;
	int a[301]={0};
	int i,j;
	double aver=0;
	double t=0;
	int u=0;
	int b[301]={0};
	int tem=0;

	scanf("%d",&n);

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

	aver=aver/n;

	for(i=0;i<n;i++)
	{
		if(aver-a[i]>t||a[i]-aver>t)
		{
			t=aver-a[i];
			j=i;
			if(t<0)
				t=0-t;
		}
	}
	for(i=0;i<n;i++)
	{
		if(aver-a[i]-t<0.001&&a[i]+t-aver<0.001)
		{
			b[u]=a[i];
			u++;
		}
		if(a[i]-aver-t<0.001&&aver+t-a[i]<0.001)
		{
			b[u]=a[i];
			u++;
		}

	}
	for(i=u;i>0;i--)
		for(j=0;j<i-1;j++)
		{
			if(b[j]>b[j+1])
			{
				int t=b[j];
				b[j]=b[j+1];
				b[j+1]=t;
			}
		}

	for(i=0;i<u;i++)
	{
		if(tem==0)
		{
			printf("%d",b[i]);
			tem=1;
		}
		else
		{
			printf(",%d",b[i]);
		}
	}

}
void main()
{
	int num,n[300],max,min,x,y,i;
	float av=0;
          scanf("%d",&num);
	for(i=0;i<num;i++)
	{
		scanf("%d",&n[i]);av+=n[i];
	}
	max=n[0];
	x=1;
	av/=num;
	for(i=1;i<num;i++)
	{
	if(n[i]>max)
	{max=n[i];x=1;}
	else
	{
	if(n[i]==max)x++;
	}
	}
	
    min=n[0];
	y=1;
	for(i=1;i<num;i++)
	{
		if(n[i]<min)
		{
			min=n[i];y=1;
		}
		else
		{
			if(min==n[i])y++;
		}
	}
	if(min==max)
	{
		printf("%d",max);
		for(i=1;i<x;i++)
			printf(",%d",max);
	}
	else
	{
		if((max+min)==(2*av))
		{
			printf("%d",min);
			for(i=1;i<y;i++)
				printf(",%d",min);

			for(i=0;i<x;i++)
				printf(",%d",max);
		}
		else
		{
			if((max+min)>(av*2))
			{
				printf("%d",max);
				for(i=1;i<x;i++)
					printf(",%d",max);
			}
			else
			{
				printf("%d",min);
				for(i=1;i<y;i++)
					printf(",%d",min);
			}
		}
	}
}
void main()
{
	float a[300],b[300];int c[300];float sum=0,max;int i,j,n,m=0;int k;
    scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%f",&a[i]);
		sum=sum+a[i];
	}sum=sum/n;
	for(i=0;i<n;i++)
	{
		b[i]=a[i]-sum;
		if(b[i]<0)b[i]=0-b[i];
	}max=b[0];
	for(i=0;i<n;i++)
	{
		if(b[i]>max)max=b[i];
	}
	for(i=0;i<n;i++)
	{
		if(b[i]==max)
		{c[m]=(int)a[i];m++;}
	}
	for(i=0;i<m;i++)
		for(j=i+1;j<m;j++)
		{
			if(c[i]>c[j])
			{k=c[j];c[j]=c[i];c[i]=k;}
		}
		for(i=0;i<m-1;i++)printf("%d,",c[i]);
		printf("%d",c[m-1]);
}
int main()
{
	int n, i, t[300], j, k;
	double v, a[300], sum = 0.0, max = 0.0;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	v = (double)sum / n;
	for (i = 0; i < n; i++)
	{
		if (max < fabs(a[i] - v))
		{
			max = fabs(a[i] - v);
			j = 0;
			t[j++] = a[i];
		}
		else if (max == fabs(a[i] - v))
			t[j++] = a[i];
	}
	for (i = 0; i < j - 1; i++)
	{
		for (k = i + 1; k < j; k++)
		{
			if (a[i] > a[k])
			{
				int temp = t[i];
				t[i] = t[k];
				t[k] = temp;
			}
		}
	}
	cout << t[0];
	for (i = 1; i < j; i++)
		cout << "," << t[i];
	cout << endl;
	return 0;
}
int main()
{
	int i,n;
	float num=0,per;
	cin>>n;
	float a[300], p[300];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		num=num+a[i];
	}
	per=num/n;
	for(i=0;i<n;i++)
	{
		if(a[i]-per>0.000001)
		{
			p[i]=a[i]-per;
		}
		else 
		{
			p[i]=per-a[i];
		}
	}
	float max=0.0;
	for(i=0;i<n;i++)
	{
		if(p[i]-max>0.000001)
		{max=p[i];}
	}
	float p1[300];
	int flag=0;
	for(i=0;i<n;i++)
	{
		if(p[i] == max)
		{flag=flag+1;}
	}
	if(flag<=1)
	{
		for(i=0;i<n;i++)
		{
			if(p[i]==max)
			{cout<<a[i];
			}
		}
	}
	int k=0;
	if(flag>1)
	{
		for(i=0;i<n;i++)
		{
			if(p[i]==max)
			{p1[k]=a[i];
			k++;}
		}
	}
	int temp;
	for(i=0;i<k-1;i++)
	{
		for(int j=i;j<k-1;j++)
		{
			if(p1[i]>p1[j])
			{temp=p1[i];
			p1[i]=p1[j];
			p1[j]=temp;
			}
		}
	}
	if(flag>1)
	{
	for(i=0;i<k-1;i++)
	{
		cout<<p1[i]<<",";
	}
	cout<<p1[k-1];
	}
	return 0;
}
void main()
{
	int n,i,a[400],k,c[400],l;
	float m,j=0,b[400];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		j=j+a[i];
	}
	j=j/(float)n;
	//printf("%.2f",j);
	for(i=0;i<n;i++)
		if((a[i]-j)>=0)
			b[i]=(a[i]-j);
		else
			b[i]=(j-a[i]);
	for(i=1,m=b[0];i<n;i++)
		if(m<b[i])
			m=b[i];
	for(i=0,k=0;i<n;i++)
		if(b[i]==m)
			c[k++]=a[i];
	for(i=0;i<k;i++)
		for(l=0;l<k-i-1;l++)
			if(c[l]>c[l+1])
			{
				n=c[l];
				c[l]=c[l+1];
				c[l+1]=n;
			}
	for(i=0;i<k;i++)
		if(i==0)
			printf("%d",c[i]);
		else
			printf(",%d",c[i]);
}
void main()
{
	int n,i,j,k,a[100]={0};
	float sum=0;
	scanf("%d",&n);
	for(i=0;i<=n-1;i++)
	{
		scanf("%d",&a[i]);
		sum=sum+a[i];
	}
	sum=sum/n;
	for(i=0;i<=n-2;i++)
	{
		for(j=0;j<=i;j++)
		{
			if(a[j+1]<a[j])
			{
				k=a[j+1];
				a[j+1]=a[j];
				a[j]=k;
			}
		}
	}
	if(sum-a[0]==a[n-1]-sum)
		printf("%d,%d\n",a[0],a[n-1]);
	else
		printf("%d\n",(sum-a[0]>a[n-1]-sum)?a[0]:a[n-1]);
}
int main()
{
	int count = 0, flag = 0;
	int i, j ;
	double x = 0.0, max = 0.0, num[301], n, temp, b[301] = {0};
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> num[i];
		x = x + num[i];
	}
	x = x / n;
	for (i = 0; i < n - 1; i++)
	{
		for (j = 0; j < n - i - 1; j++)
		{
			if (num[j] > num[j + 1])
			{
				temp = num[j];
				num[j] = num[j + 1];
				num[j + 1] = temp;
			}
		}
	}
	for (i = 0; i < n; i++)
	{
		if (num[i] >= x)
			b[i] = num[i] - x;
		else
			b[i] = x - num[i];
	}
	for (i = 0; i < n; i++)
	{
		if (max < b[i])
			max = b[i];
	}
	for (i = 0; i < n; i++)
	{
		if (b[i] == max)
		{
			if (flag == 0)
			{
				cout << num[i];
				flag = 1;
			}
			else
				cout << ',' << num[i];
		}
	}
	return 0;
}
int m=0;
void main()
{
	int n,a[300],i,j,k,d[100]={-1};
	float f,sum=0;
	double b[300],c;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n;i++)
		sum=sum+a[i];
	f=sum/n;
	for(i=0;i<n;i++)
		b[i]=fabs(a[i]-f);
	c=b[0];
	for(i=0;i<n;i++)
		if(b[i]>c)
			c=b[i];
	for(i=0;i<n;i++)
		if(c==b[i])
		{
			d[m]=a[i];m++;
		}
	if(d[1]==-1)
		printf("%d\n",d[0]);
	else
	{
		for(i=0;i<m-1;i++)
			printf("%d,",d[i]);
		printf("%d\n",d[m-1]);
	}
}
int main()
{
	int a[300],i,n,max,min;
	double aver,cha1,cha2,sum=0.0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		sum=sum+a[i];
	}
	aver=sum/n;
	max=a[0];
	min=a[0];
	for(i=0;i<n;i++)
	{
		if(a[i]>max)
			max=a[i];
		if(a[i]<min)
			min=a[i];
	}
	cha1=fabs(max-aver);
	cha2=fabs(min-aver);
	if(cha1==cha2)
		printf("%d,%d",min,max);
	else
	{
		if(cha1>cha2)
			printf("%d",max);
		else
			printf("%d",min);
	}
	return 0;
}
void main()
{
	float b[300],p=0,t;int i,j=0,n,max=0,a[300];
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
 
 for(j=0;j<n-1;j++)
				for(i=0;i<n-j-1;i++)
					if(a[i]>a[i+1])
					{
						t=a[i];
						a[i]=a[i+1];
						a[i+1]=t;
					}
	for(i=0;i<n;i++)
		p=p+a[i];
	p=p/n;
	for(i=0;i<n;i++)
	{
		if(a[i]-p>=0)
			b[i]=a[i]-p;
		else b[i]=p-a[i];
	}
	for(i=1;i<n;i++)
		if(b[i]>b[max])
		{
			t=max;
			max=i;
			i=t;
		}
		for(i=0;i<n;i++)
			if(b[i]<b[max])
				a[i]=-1;
		for(i=0;i<n;i++)
		if(a[i]>=0)
		{
			printf("%d",a[i]);
			for(j=i+1;j<n;j++)
				if(a[j]>=0)
					printf(",%d",a[j]);break;
		}
}
struct smn{
	int a;
	float b;
};
void main()
{
	int n,i,j;
	float sum=0,c;
	struct smn s[300];
	struct smn p;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&s[i].a);
		sum+=s[i].a;
	}
	c=sum/n;
	for(i=0;i<n;i++)
	{
		s[i].b=fabs(s[i].a-c);
	}
	for(j=1;j<n;j++)
		for(i=0;i<n-j;i++)
		{
			if(s[i].b<s[i+1].b)
			{
				p=s[i];
				s[i]=s[i+1];
				s[i+1]=p;
			}
		}
		for(j=1;j<n;j++)
		for(i=0;i<n-j;i++)
		{
			if(s[i].a>s[i+1].a&&s[i].b==s[i+1].b)
			{		p=s[i];
			s[i]=s[i+1];
			s[i+1]=p;
			}
		}
		printf("%d",s[0].a);
		for(i=1;i<n;i++)
		{
			if(s[i].b==s[0].b)
				printf(",%d",s[i].a);
			else break;
		}
}
main()
{
	int i,j;
	int s=0,b[300],temp,n,a[300],tem;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++)
	{
		s=s+a[i];
	}
	for(i=0;i<n;i++)
	{
		b[i]=abs(n*a[i]-s);
	}
	for(i=0;i<n-1;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(b[j]>b[i])
			{
				temp=b[j];
				b[j]=b[i];
				b[i]=temp;
				tem=a[j];
				a[j]=a[i];
				a[i]=tem;
			}
		}
	}
	j=1;
	for(i=1;i<n;i++)
	{
		if(b[i]>=b[0])
		j++;
	}
	for(i=0;i<j-1;i++)
	{
		printf("%d,",a[i]);
	}
	printf("%d",a[j-1]);
}
/*
 * 1234.cpp
 *
 *  Created on: 2011-1-9
 *      Author: c130
 */
int main()
{
	int n,i;
	float a[300],max,min,s=0;
	float v,w,e;
	cin >> n;
	for(i=0;i<n;i++)
		cin >> a[i];
	max=a[0];
	min=a[0];
	for(i=0;i<n;i++)
		if(a[i]>max)
			max=a[i];
	for(i=0;i<n;i++)
			if(a[i]<min)
				min=a[i];
	for(i=0;i<n;i++)
			s=s+a[i];
	v=s/n;
	w=v-min;
	e=max-v;
	if(w>e)
		cout << min << endl;
	else
		if(w==e)
			cout << min << "," << max << endl;
			else
				cout << max << endl;
	return 0;
}
int main(){
	int n,i,j;
	double num[300],e,c=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lf",&num[i]);
		c+=num[i];
	}
	for(i=1;i<=n;i++){
		for(j=0;j<n-i;j++){
			if(num[j]>num[j+1]){
				e=num[j];
				num[j]=num[j+1];
				num[j+1]=e;
			}
		}
	}
	if((c/n-num[0])==(num[n-1]-c/n))
		printf("%.0lf,%.0lf\n",num[0],num[n-1]);
	else if((c/n-num[0])>(num[n-1]-c/n))
		printf("%.0lf\n",num[0]);
	else if((c/n-num[0])<(num[n-1]-c/n))
		printf("%.0lf\n",num[n-1]);
	return 0;
}
int main()
{
	int n, i;
	double num[300], sum = 0, min = 10000, max = 0, temp = 0;
	double aver;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> num[i];
		sum += num[i];
	}
	aver = 1.0 * sum / n;
	for (i = 0; i < n; i++)
	{
		if (fabs(num[i] - aver) >= temp)
		{
			temp = num[i] - aver;
			if (num[i] >= max)
				max = num[i];
			if (num[i] <= min)
				min = num[i];
		}
	}
	if (min == max)
		cout << min << endl;
	else if ((max - aver) - (aver - min) > 0)
		cout << max << endl;
	else if ((max - aver) - (aver - min) < 0)
		cout << min << endl;
	else
		cout << min << "," << max << endl;
	return 0;
}
void f1(float a[],int x);
void main()
{
	int n;
	float shuzu[1000],ping;
	float max,min,sum=0;
	int s;
	scanf("%d",&n);
	for (s=0;s<n;s++)
	{
		scanf("%f",&shuzu[s]);
	}
	f1(shuzu,n);
	for (s=0;s<n;s++)
	{
		sum=sum+shuzu[s];
	}
	ping=sum/n;
	max=shuzu[0]-ping;
	min=ping-shuzu[n-1];
	if(max==min) printf("%.0f,%.0f",shuzu[n-1],shuzu[0]);
	else if(max>min) printf("%.0f",shuzu[0]);
	else printf("%.0f",shuzu[n-1]);
}
void f1(float a[],int x)
{
	int i,j;
	float t;
	for (i=0;i<x-1;i++)
	{
		for (j=0;j<x-1;j++)
		{
			if(a[j]<a[j+1])
			{
				t=a[j];
				a[j]=a[j+1];
				a[j+1]=t;
			}
		}
	}
}
int main()
{
	int a[300]={0},b[300]={0},i,j,n,s;
	float sum=0,aver,demin,demax;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++)
	{
		sum=sum+a[i];
		s=0;
		for(j=0;j<n;j++)
		{
			if(a[i]>a[j])
				s++;
		}
		b[s]=a[i];
	}
	aver=sum/n;
	demin=aver-b[0];
	demax=b[n-1]-aver;
	if(demin==demax)
		printf("%d,%d",b[0],b[n-1]);
	if(demin>demax)
		printf("%d",b[0]);
	if(demin<demax)
		printf("%d",b[n-1]);
	return 0;
}
int main()
{
	unsigned int *p,*k;
	int n,i,j=0,t,m=0,tmp;
	double a=0,sum=0,*c,lar=0;
	scanf("%d",&n);
	p=(unsigned int*)malloc(sizeof(unsigned int)*n);
	c=(double*)malloc(sizeof(double)*n);
	k=(unsigned int*)malloc(sizeof(unsigned int)*n);
	for(i=0;i<n;i++)
	{
		scanf("%u",&p[i]);
		sum=sum+(double)p[i];
	}
	a=sum/(double)n;
	for(i=0;i<n;i++)
	{
		if(a-(double)p[i]>=0)
			c[i]=a-(double)p[i];
		else
			c[i]=(double)p[i]-a;
	}
	for(i=0;i<n;i++)
	{
		if(lar<c[i])
		{
			lar=c[i];
		}
	}
	for(i=0;i<n;i++)
	{
		if(c[i]==lar)
		{
			k[j]=p[i];
			j++;
		}
	}
	m=j;
	for(i=0;i<m;i++)
	{
		t=i;
		for(j=m-1;j>i;j--)
		{
			if(k[j]>k[j-1])
				t=j-1;
		}
		tmp=k[i];
		k[i]=k[t];
		k[t]=tmp;
	}
	printf("%u",k[0]);
	for(i=1;i<t+1;i++)
		printf(",%u",k[i]);
	free(p);
	free(k);
	free(c);
	return 0;
}