SPOJ BEADS Lexicographically minimal string rotation