class BinarySearch {
public:
    int getPos(vector<int> A, int n, int val) 
    {
        int i=0;
        int j=n-1;
        while(i<=j)
        {
            int mid=(i+j)/2;
            if(A[mid]==val)
            {
                for(i=mid;i>=0;i--)
                {
                    if(A[i]!=val)
                    {
                        return i+1;
                    }
                }
                return 0;
            }
            else 
            {
                if(A[mid]>val)
                {
                    j=mid-1;
                }
                else 
                {
                    i=mid+1;
                }
            }
        }
        return -1;
    }
};