Pergunta de entrevista da empresa Yandex

Very hard algorithm contest at yandex