import java.util.*;

public class BinarySearch {
    public int getPos(int[] A, int n, int val) {
        // write code here
        int left = 0;
        int right = n-1;
        while(left<=right){
            int mid = left + (right-left)/2;
            if(A[mid]==val){
                right = mid-1;
            }else if(A[mid]>val){
                right = mid-1;
            }else{
                left = mid+1;
            }
        }
        return left;
    }
}