RE:2 2147483647 2147483647
#include
int main()
{
long kiss=0,people[200],i,j;
long t,n,count=1;
long mid=1;
while( scanf("%ld",&n)!=EOF )
{
if(n==1) // if n=1
{
printf("Case #%ld: -1\n",count);
count++;
continue;
}
for(i=1;i<=n;i++) //input
scanf("%ld",&people[i]);
for(i=1;ipeople[j])
{
t=people[i];
people[i]=people[j];
people[j]=t;
}
// no need to cal left and right
// for( i=n; people[i]==people[i-1] ; i--) //cal first left
// left++;
// for( i=1; people[i]==people[i+1]; i++ ) //first mid
// mid++;
// for(j=i+mid;people[j]=people[j+1]; j++) //first right
// right++;
people[0]=people[n]; //first left_number
people[n+1]=people[1];
for(i=1;i<=n;i++)
{
while(people[i]==people[i+1])
{
mid++;
i++;
}
if(mid==n || people[1]==people[n])
{
kiss=-1;
break;
}
else if(people[i]+people[i-mid]<0 &&
people[i]-2147483647+people[i-mid]==people[i+1])
kiss+=mid;
else if(people[i]+people[i-mid]>0 &&
people[i]+people[i-mid]==people[i+1]) //over flow
kiss+=mid;
mid=1;
}
printf("Case #%ld: %ld\n",count,kiss);
// for(i=0;i<=n+1;i++) //test
// printf(" %ld ",people[i]);
kiss=0;
count++;
}
return 0;
}