--- /dev/null
+import Data.List (sort, inits, tails, nub)
+
+main :: IO ()
+main = do
+ line1 <- getLine
+ let base = sort line1
+ let perms = permutations base
+ print $ length perms
+ putStrLn $ unlines perms
+
+permutations :: String -> [String]
+
+permutations [] = []
+permutations (x:[]) = [[x]]
+permutations xs = concatMap (\(y, ys) -> map (y:) (permutations ys)) (selects xs)
+
+selects :: String -> [(Char, String)]
+selects [] = []
+selects xs = nub [(head t, h ++ (tail t))
+ | (h, t) <- zip (inits xs) (tails xs)
+ , not (null t)]
+