Shortest Repetition

Solution for CodeEval problem.