How to solve the problem Star sky in CodeForces 835C?