# can't find why this code giving "wrong answer".... for http://www.codechef.com/problems/BESTBATS

#include<stdio.h>

int fact(int n)
{
int k=1,i;
if(n==0||n==1)
return 1;
for(i=2;i<=n;i++)
{
k=k*i;
}
return k;
}
int main()
{
int t,k,key,count=1,xtra=0,out,swap,c,d,i,j,up,low,arr[11];
scanf("%d",&t); //t=no. of test cases
for(i=0;i<t;i++)
{
scanf("%d %d %d %d %d %d %d %d %d %d %d",&arr[0],&arr[1],&arr[2],&arr[3],&arr[4],&arr[5],&arr[6],&arr[7],&arr[8],&arr[9],&arr[10]);
scanf("%d",&k);//no. of batsmen
if(k<=0)
{

``````		 printf("0\n");
continue;
}
for (c = 0 ; c < 10; c++)
{
for (d = 0 ; d < 11 - c - 1; d++)
{
if (arr[d] < arr[d+1])
{
swap=arr[d];
arr[d]=arr[d+1];
arr[d+1] = swap;
}
}
}

key=arr[k-1];
for(j=k-2;j>=0;j--)
{
if(arr[j]==key)
count++;//counts no. of copies on left + 1(for key itself)
else
break;
}

for(j=k;j<=10;j++)
{
if(arr[j]==key)
xtra++; //counts no. of copies on right
else
break;
}
/*	printf("identicas=%d\n",count+xtra);
printf("left=%d\n",count);
printf("Rgt=%d\n",xtra);*/
up=fact(count+xtra);
low=(fact(count) * fact(xtra));
up=up/low;
printf("%d\n",up);

}
return 0;
``````

}