https://videosashka.com/watch/W1aOXD8LPXM/zadacha-639-topcoder-acmp-ru-c