#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int sum[10010],flag[10010];
int a[10010],from[10010];
int ans,n,tag,t,i,j;
while(scanf("%d",&n)!=EOF)
{
memset(sum,0,sizeof(sum));
memset(flag,0,sizeof(flag));
memset(from,0,sizeof(from));
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<=n;i++)
{
sum[i]=sum[i-1]+a[i];
t=sum[i]%n;
if(t==0)
{
printf("%d\n",i);
for(j=1;j<=i;j++)
{
printf("%d\n",a[j]);
}
break;
}
else
{
if(flag[t]==0)
{
flag[t]=1;from[t]=i;
}
else
{
printf("%d\n",i-from[sum[i]%n]);
for(j=from[sum[i]%n]+1;j<=i;j++)
{
printf("%d\n",a[j]);
}
break;
}
}
}
}
return 0;
}
抽屉原理题目