public static int turningPoint(int[]A, int x) {
	   int n=A.length;
	   int[]B=new int[n], C=new int[n];
	   for (int i=0;i<n;++i)
		   if (i==0) {
			   if (A[i]==x)
				   B[i]=1;
		   } else if (A[i]==x) {
			   B[i]=B[i-1]+1;
		   } else {
			   B[i]=B[i-1];
		   }
	   for (int j=n-1;j>=0;--j)
		   	if (j==n-1) {
		   		if (A[j]!=x)
		   			C[j]=1;
		   	} else if (A[j]!=x) {
		   		C[j]=C[j+1]+1;
		   	} else {
		   		C[j]=C[j+1];
		   	}
	   for (int i=0;i<n;++i) {
		   if (B[i]==C[i])
			   return i;
	   }
	   return -1;
   }