public int removeElement(int[] A, int elem) {
    	Arrays.sort(A);
    	int length = A.length;
    	if (length == 0) return 0;
    	else if (length == 1)
    	{
    		if (A[0] == elem) return 0;
    		else return 1;
    	}
    	
    	int start = binarySearch(A,0,length,elem);
    	if (start == -1) return length;
    	int j = start;
    	
    	while (j < length && A[j] == A[start])
    	{
    		j++;
    	}
    
    	int deta = j - start;
    	length -= deta;
    	j = start;
    	while (j < length)
    	{
    		A[j] = A[j + deta];
    		j++;
    	}
        return length;
    }