Code submitted to codingame.com