cf 271 div2 - B and C - binary search and implementation