import Data.Ratio import Data.List data Probably a = Prob{getProb :: [(a, Rational)]} deriving Show instance Functor Probably where fmap f (Prob xs) = Prob $ map (\(x,p) -> (f x, p)) xs instance Monad Probably where return x = Prob [(x, 1)] m >>= f = flatten (fmap f m) flatten :: Probably (Probably a) -> Probably a flatten (Prob xs) = Prob $ concat $ map multAll xs where multAll (Prob xs', p) = map (\(x, r) -> (x, r * p)) xs' normalDice :: Probably Int normalDice = Prob [(i, 1%6) | i <- [1..6]] cheatingDice :: Probably Int cheatingDice = Prob [(i, 1%6) | i <- concat(replicate 2 [4..6])] integrate :: Probably Int -> Probably Int -> Probably Int integrate a b = Prob $ fmap head $ group $ sort $ map (\(x, p) -> (x, sum $ fmap snd (filter (\(x', _) -> x == x') ps))) ps where Prob ps = do a' <- a b' <- b return (a' + b') throwDice :: [Probably Int] -> Probably Int throwDice ps = foldl1 integrate ps main :: IO() main = do [n, k] <- return . map (read::String->Int) . lines =<< getContents let jiro = throwDice (replicate n normalDice) let taro = throwDice $ (replicate (n-k) normalDice) ++ (replicate k cheatingDice) print $ fromRational $ sum $ fmap (\(x, p) -> (* p) $ sum $ fmap snd $ filter (\(y, p') -> x > y) (getProb jiro)) (getProb taro)