split :: String -> [String] split = go ("", []) where go :: (String, [String]) -> String -> [String] go (a, acc) "" = acc <> [a] go (a, acc) (' ' : xs) = go ("", acc <> [a]) xs go (a, acc) (x : xs) = go (a <> [x], acc) xs prompt :: IO [String] prompt = do split <$> getLine fac :: Integer -> Integer fac 0 = 1 fac n = n * fac (n - 1) solve :: Integer -> Integer -> Integer -> Integer solve n a b = ( if a == b then fac (n - 1) else fac n - (fac (n - 1) * 2) + fac (n - 2) ) `mod` 998244353 main :: IO () main = do vs <- prompt let [n, a, b] = map read [head vs, vs !! 1, vs !! 2] print $ solve n a b