HACKERRANK: Sherlock and The Beast

https://www.hackerrank.com/challenges/sherlock-and-the-beast