Solving 10385 - Duathlon (Ternary search)