Pregunta de entrevista de Yandex

Very hard algorithm contest at yandex