binary search with key counter