naive chef problem

my code is working fine in dev c++ but not in codechef compiler.please show me the error.
my code is:
#include"iostream"
#include"math.h"

using namespace std;

int main(){
double ans;
long long int n,x[10000],n1,a,b;
long long int a1=0,b1=0;
cin>>n;
for(int i=0;i<n;i++){
cin>>n1>>a>>b;

	for(int j=0;j<n1;j++){
		cin>>x[j];
		}
	
	for(int k=0;k<n1;k++){
		if(x[k]==a){
			a1++;
		}
		
		
		if(x[k]==b){
			b1++;
		}
		
	}
	ans=(a1*b1)/pow(n1,2);
	cout<<ans<<endl;
	return 0;
	
	
	
}

}

Bro
You’ve to set a1=b1=0 for each test case;

Also, you have not set the precision while printing the answer.
cout<<setprecision(10)<<ans<<endl;