Solution http://www.codingame.com