import Data.List (sort, group) factorial :: Int -> Int factorial 0 = 1 factorial n = product [1 .. n] countPermutations :: String -> Int countPermutations s = subtract 1 $ div l $ product $ map factorial $ map length $ group $ sort s where l = factorial $ length s main :: IO () main = print . countPermutations =<< getLine