countChar :: Char -> [Char] -> Integer countChar c l = fromIntegral (length (filter (== c) l)) countChars' :: [Char] -> Char -> [Integer] -> [Integer] countChars' l1 'Z' l2 = (countChar 'Z' l1) : l2 countChars' l1 c l2 = (countChar c l1) : countChars' l1 (succ c) l2 ++ l2 countChars :: [Char] -> [Integer] countChars l = countChars' l 'A' [] fact :: Integer -> Integer fact 0 = 1 fact 1 = 1 fact n = n * fact (n - 1) solve :: [Char] -> Integer solve s = (fact (sum l) `div` product (map fact l) - 1) `mod` 573 where l = countChars s main :: IO () main = do s <- getLine putStrLn $ show (solve s)