S = gets.chomp puts (0...S.size).map{|i| s = S.dup; s << s[0, i]; s[0, i] = ""; s} .select{|s| s =~ /^\d/ && s =~ /\d$/} .map{|s| s.gsub(/(?