Solution by Sergey Gogolev

Yandex.School.2013: 1-introduction