{"source_code": "main = do\n [n,m] <- fmap (map read . words) getLine :: IO [Int]\n print $ length [ () | a <- [0 .. floor (sqrt $ fromIntegral n)]\n , b <- [0 .. floor (sqrt $ fromIntegral m)]\n , a^2 + b == n\n , a + b^2 == m ]\n", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd"} {"source_code": "s(t:_:p:q:_:r:s:_)|q==t&&s/=t||q==s&&r`elem`dropWhile(/=p)\"AKQJT9876\"=\"YES\"|1>0=\"NO\"\nmain=interact$s", "src_uid": "da13bd5a335c7f81c5a963b030655c26"} {"source_code": "main = interact $ show . solve . read\n\nsolve n | n <= 10 = 0 \nsolve n | n < 20 = 4\nsolve 20 = 15\nsolve 21 = 4\nsolve n = 0\n\n\n", "src_uid": "5802f52caff6015f21b80872274ab16c"} {"source_code": "import Control.Applicative ((<$>))\n\ndata Offer = Offer { offerCost :: Integer\n , offerVolume :: Integer\n } deriving (Show, Eq, Ord)\n\ndoubleOffer :: Offer -> Offer\ndoubleOffer (Offer c v) = Offer (2 * c) (2 * v)\n\n-- reverses the offer list\noptimizeOffers :: Integer -> [Offer] -> [Offer]\noptimizeOffers v = fillExtra v . optBwd . reverse . optFwd\n where\n optFwd (a:b:xs) = a : optFwd (min (doubleOffer a) b:xs)\n optFwd xs = xs\n \n optBwd (a@(Offer ca va):(Offer cb vb):xs) =\n a : optFwd (Offer (min cb ca) vb:xs)\n optBwd xs = xs\n\n fillExtra v (x:xs)\n | offerVolume x > v = (x:xs)\n | otherwise = fillExtra v (doubleOffer x : x : xs)\n\noptimizeCost :: Integer -> [Offer] -> Integer\noptimizeCost left (Offer c v:xs)\n | left <= 0 = 0\n | null xs = c\n | v <= left = c + optimizeCost (left - v) xs\n | otherwise = min c (optimizeCost left xs)\n\nsolve :: Integer -> [Offer] -> Integer\nsolve v xs = optimizeCost v (optimizeOffers v xs)\n\nreadIntegers :: IO [Integer]\nreadIntegers = fmap read . words <$> getLine\n\nreadOffers :: IO [Offer]\nreadOffers = build 1 <$> readIntegers\n where\n build _ [] = []\n build v (c:cs) = Offer c v : build (v * 2) cs\n\nmain = do\n [_, v] <- readIntegers\n offers <- readOffers\n print (solve v offers)\n", "src_uid": "04ca137d0383c03944e3ce1c502c635b"} {"source_code": "import Data.Int (Int64)\nimport Data.Maybe (fromJust)\nimport Control.Applicative ((<$>))\nimport Data.ByteString (ByteString)\nimport qualified Data.ByteString as B\nimport qualified Data.ByteString.Char8 as C\n\nprimes :: Integral a => [a]\nprimes = 2:3:rest\n where\n rest = filter isPrime $ chain [5,11..] [7,13..]\n chain (x:xs) (y:ys) = x:y:chain xs ys\n isPrime a = all (0 /=) . map (a `mod`) . takeWhile pred $ primes\n where pred x = x * x < a + 1\n\nsolve :: Int64 -> Int64 -> Int64\nsolve p q = loop (head a) n a m b\n where\n ispal a = d == reverse d\n where d = map (`mod` 10) . takeWhile (0 <) . iterate (`div` 10) $ a\n\n k = 1200000\n a = reverse . takeWhile (< k) $ primes\n b = reverse . filter ispal $ [1..k]\n n = fromIntegral . length $ a\n m = fromIntegral . length $ b\n\n loop 2 _ [] _ _ = 1\n loop prime i xs@(x:xs') j ys@(y:ys')\n | q * i < p * j + 1 = prime - 1\n | x < y = loop prime i xs (j - 1) ys'\n | y < x = loop x (i - 1) xs' j ys\n | otherwise = loop x (i - 1) xs' (j - 1) ys'\n\n\nparse :: ByteString -> [Int]\nparse line = fst . fromJust . C.readInt <$> C.words line\n\nmain = do\n [p, q] <- fmap fromIntegral . parse <$> B.getLine\n print $ solve p q\n", "src_uid": "e6e760164882b9e194a17663625be27d"} {"source_code": "import Data.List\n\nmain :: IO()\nmain = do\n s <- getLine\n let n = length s\n print $ maximum $ (0:[ j - i + 1 | i <- [0..n - 2], j <- [i..n - 1], gao i j s ])\n where gao i j s = let sub = take (j - i + 1) $ drop i s in sub `isInfixOf` drop (i + 1) s\n", "src_uid": "13b5cf94f2fabd053375a5ccf3fd44c7"} {"source_code": "module Main where\nmain = interact $ solve . read\n\nsolve :: (Integral a) => a -> String\nsolve w\n | even w && w >= 4 = \"YES\"\n | otherwise = \"NO\" ", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2"} {"source_code": "import Data.List\nimport Data.Array\nimport Data.Ord\n\nisProg t = [a1,a2..alast]==t where\n\t(a1:a2:_)=t\n\talast=last t\n\t\nprogr t = (last t)+d where\n\t(a1:a2:_)=t\n\td=a2-a1\n\nsolve t\n\t|length t==2 = progr t\n\t|isProg t = progr t\n\t|otherwise = last t\n\nmain=do\n\tn<-fmap (\\x->read x::Int) getLine\n\tt<-fmap (map (\\x->read x::Int).take n.words) $ getLine\n\tprint $ solve t\n\n{-\n\tfmap (map (\\x->read x::Int).words) $ getLine\n-}", "src_uid": "d04fa4322a1b300bdf4a56f09681b17f"} {"source_code": "import qualified Data.Set as S\nimport Data.Array.IArray\nimport Data.List\ndata Color = R | O | Y | G | B | I | V deriving (Show, Eq, Ord, Enum)\nf n = do\n let l' = [(0, S.singleton R)] ++ \n [(i, S.fromList $ enumFrom O) | i <- [1..3] ++ [n-3..n-1]] ++\n [(i, S.fromList $ enumFrom R) | i <- [4..n-4]]\n f1 n (array (0, n-1) l':: Array Int (S.Set Color)) [R] 1\n \nf1 n arr r i | i == n = if length (nub r) == 7 then return $ reverse r else fail \"\"\n | otherwise = do\n c <- S.toList $ arr ! i\n let arr' = (accum (flip S.delete) arr \n [((i+i') `mod` n, c) | i' <- ([-3..(-1)]++[1..3])]) // [(i, (S.singleton c))]\n f1 n arr' (c:r) (i+1)\nmain = do\n n <- read `fmap` getLine\n mapM (putStr.show) $ head $ f n\n", "src_uid": "dc3817c71b1fa5606f316e5e94732296"} {"source_code": "import Data.IntSet(IntSet)\nimport qualified Data.IntSet as IS\n\nmain = readLn >>= putStrLn.solve\n\nsolve :: Int -> String\nsolve n = if any (\\x -> IS.member (n-x) tnumSet) tnumList\n then \"YES\" else \"NO\"\n where tnumList = takeWhile(<=n).map(\\x->x*(x+1)`div`2)$[1..]\n tnumSet = IS.fromList tnumList\n", "src_uid": "245ec0831cd817714a4e5c531bffd099"} {"source_code": "import Data.List\nmain :: IO ()\nmain = do\n n <- getLine\n input <- getLine\n let xs = map read (words input)\n putStrLn $ show $ solve xs\n return ()\n\n{-solve :: [Int]->Int\nsolve xs \n |(length n ) == 1 =0\n |(length n ) == 2 =abs(n!!0 - n!!1)\n |(length n ) == 3 = let s = sort n in\n if s!!0-s!!1==s!!1-s!!2 then s!!2-s!!1 else -1\n |otherwise =-1\n where n = nub xs-}\nsolve :: [Int]->Int\nsolve xs \n |(length n) == 1 =0\n |(length n) == 2 =if odd (abs(n!!0 - n!!1)) then abs(n!!0 - n!!1) else div (abs(n!!0 - (n!!1))) 2 \n |(length n) == 3 = let s = sort n in\n if s!!0-s!!1==s!!1-s!!2 then s!!2-s!!1 else -1\n | otherwise = -1\n where n = nub xs", "src_uid": "d486a88939c132848a7efdf257b9b066"} {"source_code": "digitCount s = digitCount' s 0 where digitCount' s a = if s == 0 then a else digitCount' (s`div`10) (a+1)\n\naddDigits a b = addDigits' a b 0\n where \n addDigits' 0 0 c = c\n addDigits' a b c = addDigits' (a`div`10) (b`div`10) (c+(a`mod`10)+(b`mod`10))\n\nmain = do\n n <- getLine >>= return . (\\x -> read x :: Integer)\n let tens = 10 ^ (digitCount n - 1) \n a = pred $ (*tens) $ (`div` tens) $ n \n print $ addDigits a (n-a)\n", "src_uid": "5c61b4a4728070b9de49d72831cd2329"} {"source_code": "import Control.Applicative\nimport Control.Monad\nimport Control.Monad.ST\nimport Data.Array\nimport Data.Array.ST\nimport qualified Data.ByteString.Char8 as B\nimport Data.Maybe\nimport Data.Tuple\n\ndata Action = Ignore | Assign | Use deriving (Enum, Eq)\n\ntype Vertex = Int\n\ntype Graph = Array Vertex [Vertex]\n\nreachable g vs = runST $ do\n\t\tbs <- newArray (bounds g) False :: ST s (STArray s Vertex Bool)\n\t\tmapM_ (search bs) vs\n\t\tgetElems bs\n\twhere\n\t\tsearch bs v = do\n\t\t\tb <- readArray bs v\n\t\t\tif b\n\t\t\t\tthen return ()\n\t\t\t\telse do\n\t\t\t\t\twriteArray bs v True\n\t\t\t\t\tmapM_ (search bs) (g ! v)\n\ngetWords = map (fst . fromJust . B.readInt) . B.words <$> B.getLine\n\nbuild range edges = accumArray (flip (:)) [] range edges\n\nsolve actions edges =\n\t\tzipWith (&&) (reachable' g1 Assign) (reachable' g2 Use)\n\twhere\n\t\tn = length actions\n\t\tactions' = listArray (1, n) actions\n\n\t\treachable' g action = reachable g $ filter ((== action) . (actions' !)) [1..n]\n\n\t\tedges' = filter (\\(i,j) -> actions' ! i /= Assign) $ map swap edges\n\n\t\tg1 = build (1, n) edges\n\t\tg2 = build (1, n) edges'\n\nmain = do\n\t[n, m] <- getWords\n\tactions <- map toEnum <$> getWords\n\tedges <- replicateM m $ (\\[x, y] -> (x, y)) <$> getWords\n\n\tlet r = solve actions edges\n\tmapM_ print $ map fromEnum r\n", "src_uid": "87d869a0fd4a510c5e7e310886b86a57"} {"source_code": "sq x = p * p\n\twhere p = x - 2\nmain = interact $ show . sq . read", "src_uid": "efa8e7901a3084d34cfb1a6b18067f2b"} {"source_code": "{-# LANGUAGE TupleSections, MultiParamTypeClasses, ExistentialQuantification, \n RankNTypes, FlexibleContexts, DeriveFunctor #-}\n\nimport Control.Monad\nimport Control.Applicative \n--import Control.Lens\n--import Control.Zipper\nimport Control.Arrow\nimport qualified Data.Map as M\n--import qualified Data.Vector as V\nimport qualified Data.Set as S\nimport Data.List\n--import Debug.Trace\n--import Control.Comonad\nimport Data.Monoid\n--import Data.Functor.Foldable\n--import Test.QuickCheck\nimport Data.Tree\n--import Data.Machine\n--import Data.Traversable\n--import Data.Distributive\n--import Linear\nimport Control.Monad.Cont\n\n\nmain = do\n [a,b,c] <- fmap (map read . words) getLine\n putStrLn $ if solve a b c then \"YES\" else \"NO\"\n\nsolve a b c\n | b == a = True\n | c == 0 = False\n | b >= a && c >= 0 = mod (b - a) c == 0\n | b >= a && c < 0 = False\n | b < a && c >= 0 = False\n | b < a && c < 0 = mod (a - b) (-c) == 0\n | otherwise = error \"ASD\"\n\n", "src_uid": "9edf42c20ddf22a251b84553d7305a7d"} {"source_code": "isPrime 2 = True\nisPrime x = and $ map (\\i -> (x `rem` i) /= 0) (2:(takeWhile (\\i -> (i*i) <= x) [3,5..]))\nprimes = 2:f [3] [3,5..]\n where f (x:xs) ys = let (ps,qs) = span (>= return . take 4 . map int . words\n print $ solution as\n", "src_uid": "907ac56260e84dbb6d98a271bcb2d62d"} {"source_code": "import Control.Monad\nimport qualified Data.Set as Set\n\ntoTuples xs = map (\\[a,b] -> (a,b)) xs\n\nbuildSet :: [Int] -> [Int] -> Set.Set (Int,Int)\nbuildSet xs ys = let mp = (mx,my) \n where mx = xs !! 1\n my = ys !! 1\n fset = [(a,b) | a <- xs, b <- ys, (a,b) /= mp]\n in Set.fromList fset\n \n\ncheck pts = let pset = Set.fromList pts\n xset = Set.toList $ Set.fromList $ map (\\(a,b) -> a) pts\n yset = Set.toList $ Set.fromList $ map (\\(a,b) -> b) pts\n in if (length xset /= 3) || (length yset /= 3)\n then False\n else pset == buildSet xset yset\n \nmain = do \n points <- forM [1..8] (\\a -> do\n st <- getLine\n return (map (\\w -> (read w :: Int)) $ words st))\n if check $ toTuples points then putStrLn \"respectable\"\n else putStrLn \"ugly\"\n ", "src_uid": "f3c96123334534056f26b96f90886807"} {"source_code": "\nmain = do\n\td<-getLine\n\tlet [a,b]= map read $ words d\n\tputStrLn $ show $ solve a b 0\n\nsolve::Integer->Integer->Integer->Integer\nsolve a b acc \n | a==b || b<=0 = acc \n | otherwise = solve (ma) (mi) (acc+div a b)\n where ma = max b (a-d*b)\n mi = min (a-d*b) b\n d = div a b", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83"} {"source_code": "main = interact $ show . solve . read\nsolve n | odd n = 0\n | otherwise = 2 ^ (n `div` 2)\n", "src_uid": "4b7ff467ed5907e32fd529fb39b708db"} {"source_code": "main =do\n e<-getLine\n e2<-getLine\n let n=read e::Integer\n (x:y:[])=map read (words e2)::[Integer]\n a=max (y-1) (x-1)\n b=max (n-y) (n-x)\n putStrLn $ if a<=b then \"White\" else \"Black\"", "src_uid": "b8ece086b35a36ca873e2edecc674557"} {"source_code": "import List\n\nmain = do\n\tn <- fmap read getLine\n\tputStrLn $ show' $ null $ ([0 .. n - 1]\\\\) $ take (n+n) $ map (`mod` n) $ scanl1 (+) [0 ..]\n\nshow' True = \"YES\"\nshow' False = \"NO\"\n", "src_uid": "4bd174a997707ed3a368bd0f2424590f"} {"source_code": "main=interact$unwords.map show.f.map read.words\nf(n:m:bs)=foldl step (replicate n 0) bs\n where\n step xs x = ys ++ (zeros>>[x]) ++ ws\n where\n (ys,zs) = splitAt(x-1)xs\n (zeros,ws) = span (0==) zs\n", "src_uid": "2e44c8aabab7ef7b06bbab8719a8d863"} {"source_code": "module Main where\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.List\nimport qualified Data.Map as M\n\ntype Airport = String\ntype Ticket = (Airport, Airport)\ndata Result = Home | Contest deriving (Show)\n\nsolve :: String -> [Ticket] -> Result\nsolve home tickets = if location == home then Home else Contest\n where update balance (from, to) = addTo to . addFrom from $ balance\n addFrom from balance = M.insertWith (+) from (-1) balance\n addTo to balance = M.insertWith (+) to 1 balance\n\n cities = zip (concatMap (\\(f, t) -> [f, t]) tickets) (repeat 0)\n base = M.fromList $ cities ++ [(home, 1)]\n balance = foldl' update base tickets\n\n location = fst . head . filter ((== 1) . snd) $ M.toList balance\n\nmain :: IO ()\nmain = do\n n <- read <$> getLine\n home <- getLine\n tickets <- replicateM n $ do\n ticket <- getLine\n return (take 3 ticket, drop 5 ticket)\n case (solve home tickets) of\n Home -> putStrLn \"home\"\n Contest -> putStrLn \"contest\"\n", "src_uid": "51d1c79a52d3d4f80c98052b6ec77222"} {"source_code": "main = fmap (map read . words) getLine >>= print . solve\nsolve [k,n,w] = max 0 $ k*w*(w+1) `div` 2 - n\n", "src_uid": "e87d9798107734a885fd8263e1431347"} {"source_code": "import Data.List\nimport Data.Char\n\nmain :: IO ()\nmain = do\n cubes <- getContents >>= return . map (map read) . map words . drop 1 . lines\n let Just ans = findIndex (==False) $ map (makeNum cubes) $ map show [1, 2..]\n print ans\n\nmakeNum :: [[Int]] -> String -> Bool\nmakeNum _ \"\" = True\nmakeNum [] _ = False\nmakeNum cubes (d:ds) = any tryEachCube [0, 1..length cubes - 1]\n where\n tryEachCube :: Int -> Bool\n tryEachCube i = (ord d - ord '0') `elem` (cubes !! i) && makeNum (deleteAt i cubes) ds\n\ndeleteAt :: Int -> [a] -> [a]\ndeleteAt pos xs = let (ms, ns) = splitAt pos xs in ms ++ tail ns", "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b"} {"source_code": "module Main where\n import Data.List\n import Control.Monad\n import Data.Array\n import qualified Data.Set as S\n\n toArray :: [a] -> Array Int a\n toArray xs =\n let ls = length xs - 1\n in array (0, ls) $ zip [0..ls] xs\n\n readInt :: String -> Int\n readInt s = read s :: Int\n\n readInteger :: String -> Integer\n readInteger s = read s :: Integer\n\n readMultilineInput :: Int -> (String -> IO a) -> IO [a]\n readMultilineInput n transformer = replicateM n (getLine >>= transformer)\n\n elemSet :: (Ord a) => a -> S.Set a -> Bool\n elemSet elem sets =\n let found = elem `S.lookupIndex` sets\n in toBool found\n where\n toBool :: Maybe Int -> Bool\n toBool (Just _) = True\n toBool Nothing = False\n\n -- data Point = Point { x :: Int, y :: Int } deriving (Ord, Eq)\n couldWin :: Char -> String -> Bool\n couldWin x (a:b:'.':_) = x == a && x == b\n couldWin x (a:'.':b:_) = x == a && x == b\n couldWin x ('.':a:b:_) = x == a && x == b\n couldWin x _ = False\n\n lineCouldWin :: Char -> String -> Bool\n lineCouldWin a (x:xs) = couldWin a (x:xs) || couldWin a xs\n\n diagonalCouldWin :: Char -> [String] -> Bool\n diagonalCouldWin c [(x1:x2:x3:_), (y1:y2:y3:_), (z1:z2:z3:_)]\n | x1 == '.' && y2 == z3 && c == y2 = True\n | x3 == '.' && y2 == z1 && c == y2 = True\n | z1 == '.' && y2 == x3 && c == y2 = True\n | z3 == '.' && y2 == x1 && c == y2 = True\n | y2 == '.' && x1 == z3 && c == x1 = True\n | y2 == '.' && x3 == z1 && c == x3 = True\n | otherwise = False\n\n yesNo :: Bool -> String\n yesNo True = \"YES\"\n yesNo _ = \"NO\"\n\n to3x3 :: [String] -> [[String]]\n to3x3 (a:b:c:d:_) = [\n map (take 3) (a:b:c:[]),\n map (take 3) (b:c:d:[]),\n map (drop 1) (a:b:c:[]),\n map (drop 1) (b:c:d:[])\n ]\n\n main :: IO()\n main = do\n tics <- readMultilineInput 4 return\n let alltics = intercalate [] tics\n ticsAlter = transpose tics\n playCount = length $ filter (=='.') alltics\n diagonals = to3x3 tics\n c = case playCount `mod` 2 of\n 0 -> 'x'\n 1 -> 'o'\n result1 = any (lineCouldWin c) tics\n result2 = any (lineCouldWin c) ticsAlter\n result3 = any (diagonalCouldWin c) diagonals\n -- print $ c\n -- print $ map (lineCouldWin c) tics\n -- forM_ ticsAlter print\n -- print $ map (lineCouldWin c) ticsAlter\n putStrLn $ yesNo $ result1 || result2 || result3\n", "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917"} {"source_code": "module Main where\n\nimport Control.Monad\n\ntype A2D = [(Int, Int)]\n\ncnt :: Int -> Int -> Int -> Int -> A2D -> Int\ncnt i1 j1 i2 j2 a = length $ do \n\tx <- [i1..i2]\n\ty <- [j1..j2]\n\tguard $ (x, y) `elem` a\n\treturn (x, y)\n\nsolve :: Int -> Int -> Int -> Int -> A2D -> Int\nsolve r c n k a = length $ do\n\ti1 <- [1..r]\n\tj1 <- [1..c]\n\ti2 <- [i1..r]\n\tj2 <- [j1..c]\n\tguard $ (cnt i1 j1 i2 j2 a >= k)\n\treturn ()\n\ntuplify2 :: [a] -> (a, a)\ntuplify2 [x, y] = (x, y)\n\ntuplify4 :: [a] -> (a, a, a, a)\ntuplify4 [x, y, z, w] = (x, y, z, w)\n\nreadInts :: [String] -> [Int]\nreadInts = map read\n\nreadMusicians :: [String] -> A2D\nreadMusicians = map (\\x -> tuplify2 . readInts $ words x)\n\nparse :: String -> String\nparse x = do\n\tlet (l:ls) = lines x\n\tlet (r, c, n, k) = tuplify4 . readInts . words $ l\n\tlet music = readMusicians ls\n\tshow $ solve r c n k music\n\nmain = interact $ parse\n\t", "src_uid": "9c766881f6415e2f53fb43b61f8f40b4"} {"source_code": "main = do\n [n,k] <- (map read).words <$> getLine\n print $ n + (n + 1) + (n - 1) + (min (k-1) (n-k))", "src_uid": "24b02afe8d86314ec5f75a00c72af514"} {"source_code": "calcRes :: [Integer] -> [Integer] -> Integer\ncalcRes (m:n:_) (x:y:z:_) = (max 0 (2 * x + y - m)) + (max 0 (3 * z + y - n))\ncalcRes _ _ = 0\n\nreadInts :: IO [Integer]\nreadInts = fmap (map read.words) getLine\n\nmain = do\n a <- readInts\n b <- readInts\n putStrLn . show $ calcRes a b\n", "src_uid": "35202a4601a03d25e18dda1539c5beba"} {"source_code": "digs :: Integer -> [Integer]\ndigs 0\t= []\ndigs n\t= digs (n `quot` 10 ) ++ [n `rem` 10]\n\nisLucky :: Integer -> Bool\nisLucky n = (length . filter (\\x -> x == 4 || x == 7) . digs $ n) == (length . digs $ n) && (length . digs $ n) /= 0\n\nanswer :: Integer -> String\nanswer n \n\t| isLucky $ foldl (\\acc x -> if x == 4 || x == 7 then acc + 1 else acc) 0 (digs n) = \"YES\"\n\t| otherwise = \"NO\"\n\nmain :: IO()\nmain = do\n [n] <- (map read . words) `fmap` getLine\n putStrLn $ answer n\n", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1"} {"source_code": "-- -*- compile-command: \"ghc -o main -O specialolympics.hs\" -*-\nimport System.IO\nimport Data.List\nimport Data.Char\nimport qualified Data.ByteString.Char8 as SS\n\nreadDouble :: String -> Double\nreadDouble = read\n\nvalidCircle :: (Double, Double, Double) -> Double -> Bool\nvalidCircle (a,r,rr) d \n | r >= d+a = True\n | rr+d <= a = True\n | d >= a+rr = True\n | otherwise = False\n\nvalidCircles :: Double -> [(Double,Double,Double)] -> Int\nvalidCircles d ls = foldl helper 0 ls\n where helper c x = case validCircle x d of\n True -> c+1\n False -> c\n\nmain = do\n (x1:y1:r1:rr1:_) <- (map readDouble . words) `fmap` getLine\n (x2:y2:r2:rr2:_) <- (map readDouble . words) `fmap` getLine\n let d = sqrt $ (x1-x2)^2+(y1-y2)^2\n print $ validCircles d [(r1,r2,rr2),(rr1,r2,rr2),(r2,r1,rr1),(rr2,r1,rr1)]", "src_uid": "4c2865e4742a29460ca64860740b84f4"} {"source_code": "readInts :: IO [Int]\nreadInts = map read . words <$> getLine\n\nmain :: IO ()\nmain = do\n n <- read <$> getLine\n [a1, a2, a3] <- readInts\n [b1, b2, b3] <- readInts\n let\n s1 = min a1 b2\n s2 = min a2 b3\n s3 = min a3 b1\n maxScore = s1 + s2 + s3\n t1 = max 0 $ a1 + b2 - n\n t2 = max 0 $ a2 + b3 - n\n t3 = max 0 $ a3 + b1 - n\n minScore = t1 + t2 + t3\n putStrLn . unwords $ map show [minScore, maxScore]\n", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402"} {"source_code": "import Data.Functor\nimport Data.List\n\nmain :: IO ()\nmain = do\n [n, a, b] <- map read . words <$> getLine\n putStrLn . show $ (n * 100 + a + b - 1) `mod` n + 1\n", "src_uid": "cd0e90042a6aca647465f1d51e6dffc4"} {"source_code": "nextSimple :: Int -> Int\nnextSimple n0 = head (filter (\\n -> length (filter (\\m -> mod n m == 0) [1..n]) == 2) [(n0+1)..])\n\nsolve :: Int -> Int -> String\nsolve n m = if m == nextSimple n then \"YES\" else \"NO\"\n\nmain = do\n s <- getLine\n let [n, m] = map (read::(String -> Int)) (words s)\n putStr (solve n m)\n", "src_uid": "9d52ff51d747bb59aa463b6358258865"} {"source_code": "import Control.Monad\nimport Control.Monad.ST\nimport Data.Array\nimport Data.Array.ST\n\nmain = interact $ output . solve . map read . words\n\noutput :: Bool -> String\noutput True = \"YES\"\noutput _ = \"NO\"\n\nsolve :: [Int] -> Bool\nsolve [n,k] = let pr = primes n in (>=k) . length . filter (==True) . map (flip elem pr . (+1)) $ zipWith (+) pr (tail pr)\n\nprimes :: Int -> [Int]\nprimes = fst . unzip . filter ((==0) . snd) . assocs . sieve\n\nsieve :: Int -> Array Int Int\nsieve n = runSTArray build\n\t\twhere build :: ST s (STArray s Int Int)\n\t\t build = newArray (2,n) 0 >>=\n\t\t\t\t\t \\arr -> forM_ (takeWhile (\\x -> x*x <= n) [2..n]) (\\i -> readArray arr i >>=\n\t\t\t\t\t \\p -> if p == 0\n\t\t\t\t\t\t then forM_ [i*i,(i+1)*i..n] (\\j -> writeArray arr j 1)\n\t\t\t\t\t\t\telse return ()) >> return arr", "src_uid": "afd2b818ed3e2a931da9d682f6ad660d"} {"source_code": "main = do\n x <- read `fmap` getLine :: IO Integer\n putStrLn $ show $ solve x\n\nsolve :: Integer -> Integer\nsolve x \n | x `mod` 5 /= 0 = x `div` 5 + 1\n | otherwise = x `div` 5\n\n\n", "src_uid": "4b3d65b1b593829e92c852be213922b6"} {"source_code": "main = do\n\tn <- getLine\n\tstones <- getLine\n\tlet res = foldl (\\prev i -> if stones !! i == stones !! (i - 1)\n\t\t\t\t\t\t\t\tthen prev + 1\n\t\t\t\t\t\t\t\telse prev) 0 [1..length stones - 1]\n\t\n\tputStrLn $ show res", "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8"} {"source_code": "import Control.Applicative\nimport Control.Monad\nimport Data.List\nimport Data.Maybe\n\n\nmain = do\n\t\t[x,y,z,t1,t2,t3]<- map read <$> words <$> getLine::IO [Int]\n\t\tlet w = abs(x-y) * t1\n\t\tlet e = abs(z-x) *t2 + t3+t3 + t2 * abs (x-y) +t3\n\t\tputStrLn $ if e>w then \"NO\" else \"YES\"\n", "src_uid": "05cffd59b28b9e026ca3203718b2e6ca"} {"source_code": "main = interact $ solve . read\nsolve n = case n `mod` 4 of 0 -> \"1 A\"\n 1 -> \"0 A\"\n 2 -> \"1 B\"\n 3 -> \"2 A\"\n", "src_uid": "488e809bd0c55531b0b47f577996627e"} {"source_code": "import Data.List\nmain = interact $ format . solve . map read . tail . words\nformat True = \"YES\"\nformat False = \"NO\"\nsolve xs = any (uncurry (>)) $ zip xs' $ tail $ scanr1 min $ zipWith (-) (tail xs') xs'\n where xs' = sort xs\n\ntests = [\n solve [1,5,3,2,4] == True\n , solve [4,1,2] == False\n , solve [197,75,517,39724,7906061,1153471,3,15166,168284,3019844,272293,316,16,24548,42,118,5792,5,9373,1866366,4886214,24,2206,712886,104005,1363,836,64273,440585,3576] == False\n , solve [229017064,335281886,247217656,670601882,743442492,615491486,544941439,911270108,474843964,803323771,177115397,62179276,390270885,754889875,881720571,902691435,154083299,328505383,761264351,182674686,94104683,357622370,573909964,320060691,33548810,247029007,812823597,946798893,813659359,710111761] == True\n , solve [740553458,532562042,138583675,75471987,487348843,476240280,972115023,103690894,546736371,915774563,35356828,819948191,138721993,24257926,761587264,767176616,608310208,78275645,386063134,227581756,672567198,177797611,87579917,941781518,274774331,843623616,981221615,630282032,118843963,749160513,354134861,132333165,405839062,522698334,29698277,541005920,856214146,167344951,398332403,68622974] == True\n , solve [155,1470176,7384,765965701,1075,4,561554,6227772,93,16304522,1744,662,3,292572860,19335,908613,42685804,347058,20,132560,3848974,69067081,58,2819,111752888,408,81925,30,11951,4564,251,26381275,473392832,50628,180819969,2378797,10076746,9,214492,31291] == False\n , solve [1,1000000000,1000000000] == True\n , solve [1,1000000000,1000000000,1000000000] == True\n , solve [1,1000000000,1] == False\n , solve [1,2,3,5,2] == True\n ]\n", "src_uid": "897bd80b79df7b1143b652655b9a6790"} {"source_code": "import Data.List\nimport Data.Array\nimport Data.Ord\nimport Data.Char\n\nrd x = read x::Integer\ngetNumbers=map rd.words\nextract (x:xs)=map rd $ take (read x::Int) xs\n\nsolve x\n\t|length num==2 && half x= unlines [\"YES\",unwords [show (num!!0),show (num!!1)]]\n\t|otherwise = \"NO\"\n\twhere \n\t\tnum = nub x\n\t\thalf x = length (filter (==num!!0) x) == length (filter (==num!!1) x)\n\t\nmain=interact$solve.extract.lines", "src_uid": "2860b4fb22402ea9574c2f9e403d63d8"} {"source_code": "\nimport Prelude hiding (sqrt)\n\nsqrt :: Int -> Int\nsqrt n = head $ [x | x <- [0..], x*x == n]\n\nsolve :: [Int] -> Int\nsolve [ab, ac, bc] = 4 * (a + b + c)\n where\n a = sqrt (div (ab*ac) bc)\n b = div ab a\n c = div ac a\n\nmain :: IO ()\nmain = fmap (map read . words) getLine >>= print . solve\n", "src_uid": "c0a3290be3b87f3a232ec19d4639fefc"} {"source_code": "main :: IO ()\nmain = interact $ show . solve . map read . words\n\nsolve :: [Int] -> Int\nsolve (w1:h1:w2:h2:_) = 4+2*(h1+h2)+2*w1", "src_uid": "b5d44e0041053c996938aadd1b3865f6"} {"source_code": "import Data.List\nmain = interact $ show . solve . map read . words\nsolve (n:as) = max b (n-a-1) where\n [a,b] = findIndices (`elem` [1,n]) as\n", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4"} {"source_code": "import Data.Array\n\nmaxn = 1000 :: Integer\n\nprimes' :: Integer -> Array Integer Bool -> [Integer]\nprimes' n outside\n | n-1 >= maxn = []\n | outside ! n = primes' (n+1) outside\n | otherwise = n : primes' (n+1) outside'\n where\n outside' = outside // (map (\\i->(i,True)) [n,2*n..maxn])\nprimes :: [Integer]\nprimes = primes' 2 $ listArray (2,maxn) (repeat False)\n\n\nprimefacs' :: [Integer] -> Integer -> [Integer]\nprimefacs' [] _ = []\nprimefacs' pps@(p:ps) i\n | mod i p == 0 = p : primefacs' pps (div i p)\n | otherwise = primefacs' ps i\nprimefacs :: Integer -> [Integer]\nprimefacs i = primefacs' primes i\n\n\nsolve' :: Integer -> [Integer] -> [Integer]\nsolve' mult factormult\n | null factormult || (mult-1)*nextprime < nmult = factormult ++ [mult]\n | otherwise = nfactormult\n where\n nextprime = primes !! length factormult\n nmults = map (\\(expo,pri) -> pri^(expo*mult - expo)) (zip factormult primes)\n (nmult,primeindx) = minimum (zip nmults [0..])\n (prevs,curr:nxts) = splitAt primeindx factormult\n nfactormult = prevs ++ (curr*mult):nxts\n\n\nsolve :: Integer -> Integer\nsolve i = let\n expos = foldr solve' [] (primefacs i)\n in product $ zipWith (\\a b -> a^(b-1)) primes expos\n\n\nmain :: IO ()\nmain = do\n i <- readLn :: IO Integer\n print $ solve i\n\n\n{-\nLa cantidad de divisores de un número es la cantidad de formas que se tienen de tomar un multiconjunto diferente de sus factores primos, para cada factor primo, si se repite k veces, se pueden tomar k+1 veces de maneras diferentes, así, por ejemplo:\n\n40 = 2^3 * 5^1 tiene (3+1)*(1+1) divisores.\n\nSi se quiere un número con n divisores, n se descompone en sus factores primos de menor a mayor, luego, se debe encontrar un conjunto de exponentes de factores primos de manera que los sucesores de estos exponentes, multiplicados, den n.\n\nDe forma voraz, se va construyendo el menor número m con dicha cantidad de factores primos, operando con el siguiente factor primo r de n. Lo que hace es ver qué aumenta menos el número m, si modificar uno de los exponentes de su descomposición en factores primos, de manera que la cantidad de veces que se pueda tomar sea r veces más o agregar el siguiente factor primo con un exponente r - 1.\n\nLuego se calcula el número m.\n\n-}\n", "src_uid": "62db589bad3b7023418107de05b7a8ee"} {"source_code": "import Data.List\n\nf::[Int] -> String\nf [x,y] | x >= 2 && y >= 2 = g [x-2,y-2]\n\t| x >= 1 && y >= 12 = g [x-1,y-12]\n\t| x >= 0 && y >= 22 = g [x-0,y-22]\n\t| otherwise = \"Hanako\"\n\ng::[Int] -> String\ng [x,y] | x >= 0 && y >= 22 = f [x-0,y-22]\n\t| x >= 1 && y >= 12 = f [x-1,y-12]\n\t| x >= 2 && y >= 2 = f [x-2,y-2]\n\t| otherwise = \"Ciel\"\n\nmain = interact $ f.map read.words\n\n", "src_uid": "8ffee18bbc4bb281027f91193002b7f5"} {"source_code": "import List\nmyhead ::[[Int]] -> [Int]\nmyhead [] = []\nmyhead a = head a\nhasNotSame ::[Int] -> Bool\nhasNotSame a = length(nub a)==(length a)\ngetAns ::[Int] -> [Int]\ngetAns [r1,r2,c1,c2,d1,d2] = myhead [[x,y,w,z]|x<-[1..9],y<-[1..9],w<-[1..9],z<-[1..9],hasNotSame[x,y,w,z],r1 == (x+y),r2 == (w+z),c1 == (x+w),c2 ==(y+z),d1==(x+z),d2==(y+w)]\ntoS ::[Int]->String\ntoS [] = \"-1\"\ntoS [x,y,w,z] = concat [(show x),\" \",(show y),\"\\n\",(show w),\" \",(show z) ]\nmain=interact$toS.getAns.map read.words", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3"} {"source_code": "import Control.Monad\nimport Data.Array\nimport Data.Char\nimport Data.Functor\nimport Data.Int\nimport Data.List\nimport Data.List.Split\nimport Data.Maybe\n-- import qualified Data.Text as T\nimport qualified Data.ByteString.Char8 as B\ngetList :: Read a => IO [a]\ngetList = map (read . B.unpack) . B.words <$> B.getLine\ngetIntList :: IO [Int]\ngetIntList = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine\n\nsolve :: [[Int]] -> Int\nsolve a = length [() | i <- a, j <- a, head i == j !! 1]\n\nmain :: IO ()\nmain = do\n n <- read <$> getLine\n a <- replicateM n getIntList\n print $ solve a\n", "src_uid": "745f81dcb4f23254bf6602f9f389771b"} {"source_code": "-- import Debug.Trace\n\n-- cubes n i cnt \n-- | n < cnt = trace (show cnt) i\n-- | otherwise = trace (\"cnt \" ++ (show cnt) ++ \" i \" ++ (show i)) cubes n (i+1) (cnt + sq i 0 0)\n\n\n-- sq n ind ret\n-- | n == ind = ret\n-- | otherwise = trace (\"\\n\" ++ (show ret)) sq n (ind + 1) (ret + ind)\n\ncubes n i cnt \n | n < cnt = i\n | otherwise = cubes n (i+1) (cnt + sq i 0 0)\n\n\nsq n ind ret\n | n == ind = ret\n | otherwise = sq n (ind + 1) (ret + ind)\n\nmain = do\n ff <- getLine\n let ss = (read ff)::Int\n ans = cubes ss 0 0 \n putStrLn (show (ans-3))\n\n\n\n\n\n", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0"} {"source_code": "n (y:x:_) = [((y + ((x + 1) `div` 60)) `mod` 24), ((x + 1) `mod` 60)]\nc :: Int -> Int\nc x = ((x `mod` 10) * 10) + (x `div` 10)\nok :: [Int] -> Bool\nok (y:x:_) = y == (c x)\ns x = (show (x `div` 10)) ++ (show (x `mod` 10))\np (x:y:_) = (s x) ++ \":\" ++ (s y)\nmain = do\n s <- getLine\n let s3 = read (take 2 s) :: Int\n let s4 = read (reverse . (take 2) . reverse $ s) :: Int\n putStrLn $ p $ head $ filter ok $ tail $ iterate n [s3, s4] ", "src_uid": "158eae916daa3e0162d4eac0426fa87f"} {"source_code": "module Main where\n\nimport Control.Applicative\nimport Data.List\n\nrest = [31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\nleaps = 31 : 29 : rest\nordinary = 31 : 28 : rest\n\nmonths = ordinary ++ ordinary ++ leaps ++ ordinary ++ ordinary\n\nsubstrings :: [a] -> Int -> [[a]]\nsubstrings as n = filter ((== n) . length) . map (take n) $ tails as\n\nsolve :: [Int] -> Bool\nsolve ds = case find (== ds) (substrings months n) of\n Just _ -> True\n _ -> False\n where n = length ds\n\ntest0 = [31, 31, 30, 31] :: [Int]\ntest1 = [30, 30] :: [Int]\n\nmain :: IO ()\nmain = do\n _ <- getLine\n ds <- map read . words <$> getLine\n putStrLn $ if solve ds then \"Yes\" else \"No\"\n", "src_uid": "d60c8895cebcc5d0c6459238edbdb945"} {"source_code": "-- hm i'm not sure how to rigorously prove this solution. basically you expand the fraction to continued fraction and take all the pluses (and the last denominator).\n-- like 43/30 = 1 + 1 / (2 + 1 / (3 + 1 / 4)) -> 1+2+3+4 = 10. indeed \"43 30\" gives output \"10\".\ncomputeResult :: (Integer, Integer) -> Integer\ncomputeResult (_, 0) = 0\ncomputeResult (a, b) = (+) (div a b) (computeResult (b, mod a b))\n\n-- ok i lied a bit. this function also swaps the arguments if the first is smaller. but it's still handle input blargh whatever\nhandleInput :: [String] -> (Integer, Integer)\nhandleInput (x:y:[]) = let a = read x; b = read y in if (a < b) then (b, a) else (a, b)\n\n-- the main function just so i can test it without resorting to cygwin and compiling the function\nmainFunction :: String -> String\nmainFunction = show . computeResult . handleInput . words\n\n-- the \"actual\" main function which handles all the IO stuff\nmain = do\n s <- getLine\n putStrLn $ mainFunction s", "src_uid": "792efb147f3668a84c866048361970f8"} {"source_code": "{-# LANGUAGE TypeSynonymInstances #-}\n{-# OPTIONS_GHC -O2 #-}\n{-# LANGUAGE ForeignFunctionInterface, ScopedTypeVariables #-}\n{-# LANGUAGE OverloadedStrings #-}\nimport Foreign hiding (newArray)\nimport Foreign.C.Types\nimport Foreign.C.String\nimport Foreign.Marshal.Alloc\nimport Debug.Trace\nimport Data.List\nimport Control.Monad\nimport Control.Monad.ST\nimport qualified Data.Array.Unboxed as UB\nimport Data.Array.ST\nimport Data.Array.Base hiding ((!))\nimport Data.Array\nimport Data.Char\nclass IOtyp a where scan' :: String -> a; show' :: a -> String\ninstance IOtyp Int64 where scan' = read; show' = show\ninstance IOtyp Char where scan' (x:_) = x;show' = (:[])\ninstance IOtyp Float where scan' = read;show' = show\ninstance IOtyp Double where scan' = read;show' = show\ninstance IOtyp Integer where scan' = read;show' = show\ninstance IOtyp String where scan' = id;show' = id\ninstance (IOtyp a,IOtyp b) => IOtyp (a,b) where scan' = (\\(x:y:_) -> (scan' x,scan' y)).words;show' (x,y) = show' x++' ':show' y\ninstance (IOtyp a,IOtyp b,IOtyp c) => IOtyp (a,b,c) where scan' = (\\(x:y:z:_) -> (scan' x,scan' y,scan' z)).words;show' (x,y,z) = show' x++' ':show' y++' ':show' z\nforeign import ccall \"stdio.h puts\" c_puts :: CString -> IO ()\nscan :: (IOtyp a) => IO a; scan = getLine>>=return.scan'\nscans :: (IOtyp a) => Int -> IO [a]; scans = (flip replicateM) scan\nscanlist :: (IOtyp a) => IO [a]; scanlist = getLine>>=return.map scan'.words\nscanlists :: (IOtyp a) => Int -> IO [[a]]; scanlists = (flip replicateM) scanlist\nputs :: (IOtyp a) => a -> IO (); puts ans = do {str<-newCString $ show' ans;c_puts str;free str}\n\nsieve :: Int64 -> UArray Int64 Bool\nsieve n = runSTUArray $ do\n t <- newArray (0,n) True\n unsafeWrite t 0 False\n unsafeWrite t 1 False\n mapM_ (\\i -> unsafeWrite t i False) [4,6..fromIntegral n]\n let sqn = (floor.sqrt.fromIntegral) (n::Int64)\n mapM_ (\\i -> (mapM_ (\\j -> unsafeRead t i>>=(flip when) (unsafeWrite t j False)) [i*i,i*(i+2)..fromIntegral n])) [3,5..sqn]\n return t\n\nisPrime n = if n==2 then True else let sqn = ceiling.sqrt.fromIntegral $ n in all (\\x -> mod n x /= 0) (2:[3,5..sqn])\n\nsolve :: Int64 -> String\nsolve n | trace (show n) True = if n==1 || isPrime n then \"1\\n0\" else if null l then \"2\" else \"1\\n\"++(show.(\\(a:b:_) -> a*b) $ l)\n where\n sqn = ceiling.sqrt.fromIntegral $ n\n sve = sieve sqn\n l = rec 0 n 2 []\n rec counter m i l = if counter == 2 then l\n else\n if i>=sqn then []\n else\n if sve UB.! i then\n if mod m i == 0 then\n rec (counter+1) (div m i) i (i:l)\n else\n rec counter m (i+1) l\n else\n rec counter m (i+1) l\n\nmain = (scan :: IO Int64) >>= putStrLn.solve", "src_uid": "f0a138b9f6ad979c5ca32437e05d6f43"} {"source_code": "module Main where\n\nimport Data.Maybe\nimport Data.Array\nimport Data.List\nimport Data.Char\n\nimport Data.Time.Calendar\n\nmain = interact (show . solve . map read . words)\n\nsolve :: [Int] -> Int\nsolve (a : x : y : _) = if got then aim else -1 where\n got = if y `mod` a == 0\n then False\n else if y < a\n then hitOne a x\n else let y' = (y - a) `mod` (2 * a) in\n (y' < a && hitOne a x) || (a < y' && hitTwo a x)\n\n aim = number a x y\n\nhitOne :: Int -> Int -> Bool\nhitOne a x = -a < 2 * x && 2 * x < a\n\nhitTwo :: Int -> Int -> Bool\nhitTwo a x = (-a < x && x < 0) || (0 < x && x < a)\n\nnumber :: Int -> Int -> Int -> Int\nnumber a x y = if y < a\n then 1\n else 1 + number' a x (y - a)\nnumber' a x y = 3 * (y `div` (2 * a)) + amongThree a x (y `mod` (2 * a))\n\namongThree a x y = if y < a\n then 1\n else if x < 0\n then 2\n else 3\n", "src_uid": "cf48ff6ba3e77ba5d4afccb8f775fb02"} {"source_code": "p x=x`div`4*2+min(x`mod`4)2\ns[n,m]=maximum[p n*p m,m,n,(n*m+1)`div`2]\nmain=interact$show.s.map read.words", "src_uid": "e858e7f22d91aaadd7a48a174d7b2dc9"} {"source_code": "main = do\n n <- readLn :: IO Int\n putStrLn \"+------------------------+\"\n putStrLn $ f n # \"|#.#.#.#.#.#.#.#.#.#.#.|D|)\"\n putStrLn $ g n # \"|#.#.#.#.#.#.#.#.#.#.#.|.|\"\n if n >= 3 then putStrLn \"|O.......................|\"\n else putStrLn \"|#.......................|\"\n putStrLn $ h n # \"|#.#.#.#.#.#.#.#.#.#.#.|.|)\" \n putStrLn \"+------------------------+\"\n\n(#) :: Int -> String -> String\n0#cs = cs\nn#('#':cs) = 'O' : (n-1)#cs\nn#(c:cs) = c : n#cs\n_#[] = []\n\nf n\n | n <= 4 = if n >= 1 then 1 else 0\n | (q,r)<-divMod(n-4)3 = if r >= 1 then 2 + q else 1 + q\n\ng n\n | n <= 4 = if n >= 2 then 1 else 0\n | (q,r)<-divMod(n-4)3 = if r == 2 then 2 + q else 1 + q\n\nh n\n | n < 4 = 0\n | n == 4 = 1\n | (q,r)<-divMod(n-4)3 = 1 + q\n", "src_uid": "075f83248f6d4d012e0ca1547fc67993"} {"source_code": "main=interact$show.f.map read.words\nf(n:x)=sum[1|i<-[1..5],(i+sum x)`mod`(n+1)/=1]", "src_uid": "ff6b3fd358c758324c19a26283ab96a4"} {"source_code": "import Data.List\nmain = interact $ show . solve . map read . tail . words\nsolve as = sum ps - sum ns\n where (ps,ns) = partition (>= 0) as\n", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5"} {"source_code": "check s =\n go 'a' s\n where go c \"\" = \"YES\"\n go c (x:xs) = if c == x\n then go (succ c) (filter (/= c) xs)\n else \"NO\"\n\nmain = do\n s <- getLine\n putStrLn $ check s\n\n", "src_uid": "c4551f66a781b174f95865fa254ca972"} {"source_code": "-- Codeforces 865A\n\nimport Control.Applicative\n\nmain :: IO ()\nmain = do\n x <- read <$> getLine :: IO Int\n putStrLn $ show (2 * x - 1) ++ \" \" ++ \"2\"\n putStrLn \"1 2\"\n", "src_uid": "5c000b4c82a8ecef764f53fda8cee541"} {"source_code": "import List\nimport Maybe\nmain = interact solve\nsolve input = output where\n inputs = sort $ zip ( lines input ) \"FMS\"\n i0 = map fst inputs\n output\n | i0 == [\"paper\",\"rock\",\"rock\"] = [fromJust $ lookup \"paper\" inputs]\n | i0 == [\"paper\",\"paper\",\"scissors\"] = [fromJust $ lookup \"scissors\" inputs]\n | i0 == [\"rock\",\"scissors\",\"scissors\"] = [fromJust $ lookup \"rock\" inputs]\n | otherwise = \"?\"\n", "src_uid": "072c7d29a1b338609a72ab6b73988282"} {"source_code": "main = print . solve . map read . words =<< getLine\nsolve [n,a,b] = min (n-a) (b+1)\n", "src_uid": "51a072916bff600922a77da0c4582180"} {"source_code": "{-# LANGAGE BangPatterns #-}\n\nimport Data.Int\nimport Data.List\n\npowers2 = 1 : (map (*2) powers2)\n\nsolve :: String -> Int64\nsolve xs = foldl' go 0 (zip xs powers2)\n where\n go a ('B',p) = a+p\n go a ('R',p) = a\n\nmain = do\n n <- read `fmap` getLine\n line <- (take n) `fmap` getLine\n print $ solve line\n\n", "src_uid": "d86a1b5bf9fe9a985f7b030fedd29d58"} {"source_code": "import System.IO\nimport Data.Char\nimport Data.Int (Int64)\nimport Data.List\nimport qualified Data.Set as S\n\ndivisores :: Int64 -> [Int64]\ndivisores b = loop 2 b\n where\n loop n b | n*n > b = [b]\n | n*n == b = [n, b]\n | b `mod` n == 0 = (n:(b `div` n):result)\n | otherwise = result\n where result = loop (n+1) b\n\nmain= do\n line <- getLine \n let b = (read line :: Int64)\n print $ length (S.fromList(1:divisores b))\n", "src_uid": "7fc9e7d7e25ab97d8ebc10ed8ae38fd1"} {"source_code": "main = do\n [h1, h2] <- fmap (map read . words) getLine :: IO [Int]\n [a, b] <- fmap (map read . words) getLine\n\n let\n find d h\n | h <= h2 && h2 <= h + (22-14)*a = d\n | h' <= h2 && h2 <= h' + (14-10)*a = d+1\n | h'' <= h = -1\n | otherwise = find (d+1) h''\n where\n h' = h + (22-14)*a - 12*b\n h'' = h' + (14-10)*a\n\n print $ find 0 h1\n", "src_uid": "2c39638f07c3d789ba4c323a205487d7"} {"source_code": "main=do n<-readLn;print.head$[x::Integer|x<-[max(r n-99)1..r n],x*(x+sum[read[c]|c<-show x])==n]++[-1]\nr=floor.sqrt.fromIntegral\n", "src_uid": "e1070ad4383f27399d31b8d0e87def59"} {"source_code": "\n\nmain = do\n lines <- sequence [getLine,getLine]\n let a = read (lines !! 0) :: Int\n b = read (lines !! 1) :: Int\n if a < 31\n then\n putStrLn $ show $ b `mod` (2^a)\n else\n putStrLn $ show b\n", "src_uid": "c649052b549126e600691931b512022f"} {"source_code": "main = interact $ show . solve . read\nsolve n = (n+1) `div` 2 - 1\n", "src_uid": "dfe9446431325c73e88b58ba204d0e47"} {"source_code": "main :: IO ()\nmain = \n do cs <- getContents\n (putStr.show.solve.parseIn) cs\n\nparseIn::String->Int\nparseIn = read.head.lines\n\nsolve::Int->Int\nsolve i = divlistCps i 2 i\n where\n divlistCps n k ret = \n if (n==1) \n then \n ret\n else\n if ((mod n k) == 0)\n then\n divlistCps (div n k) k ((div n k)+ret)\n else\n divlistCps n (if (k==2) then 3 else k+2) ret\n", "src_uid": "821c0e3b5fad197a47878bba5e520b6e"} {"source_code": "\nimport Array\nimport Data.List (nub, permutations, sort)\nimport Prelude hiding (print)\n\n{-\nimport HUnit\n\ntest :: FilePath -> IO ()\ntest programName = do\n systemTest programName (map makeTest tests) checker\n\nmakeTest (n, as) = (unlines [show n, concatMap (\\a -> show a ++ \" \") as], \"\")\n\nchecker :: String -> String -> Maybe String\nchecker accepted answer = Nothing\n\ntests =\n [\n (3, [1..9]),\n (3, [1, 0, -1, 0, 2, -1, -2, 0, 1]),\n (2, [5, 5, 5, 5]),\n (2, [-1, -1, -1, -1]),\n (3, [58, -83, 72, 65, -90, -2, -9, -16, -76]),\n (3, [399, -1025, -129, -497, 927, -577, 479, 31, -49]),\n (3, [2, 4, 6, 8, 10, 12, 14, 16, 18]),\n (3, [36, 31, -25, 3, -20, -30, 8, -2, 26]),\n (3, map read $ words \"175 -1047 -731 -141 38 -594 -415 -278 491\"),\n (3, map read $ words \"-1256 74 -770 -284 -105 381 -591 1046 560\"),\n (1, map read $ words \"-98765432\"),\n (3, map read $ words \"99981234 99981234 99981234 99981234 99981234 99981234 99981234 99981234 99981234\"),\n (3, map read $ words \"-67774718 52574834 -7599942 52574834 52574834 -67774718 -67774718 -7599942 -7599942\"),\n (3, map read $ words \"12458317 12458317 -27658201 -7599942 -27658201 32516576 -67774719 -47716460 52574835\"),\n (3, map read $ words \"-33389130 52574830 -16196338 -41985526 996454 26785642 -7599942 18189246 -67774714\"),\n (4, map read $ words \"4815960 32237520 2073804 -668352 -22605600 -668352 15784584 4815960 10300272 -6152664 10300272 15784584 -6152664 7558116 2073804 7558116\"),\n (4, map read $ words \"1936924 6264932 1936924 -4555088 -8883096 -19703116 -8883096 1936924 12756944 -8883096 -8883096 -8883096 6264932 1936924 6264932 -8883096\"),\n (4, map read $ words \"-27386716 27186128 27186128 -13743505 -100294 -100294 13542917 -100294 13542917 68115761 27186128 -100294 -13743505 -27386716 -81959560 -13743505\"),\n (4, map read $ words \"-25056193 -6486895 -6486895 -25056193 -6486895 -6486895 12082403 -6486895 -25056193 12082403 -6486895 12082403 -6486895 -6486895 -6486895 -6486895\"),\n (4, map read $ words \"24978426 4704454 -5432532 -364039 -10501025 30046919 19909933 -15569518 -30774997 -5432532 19909933 4704454 -364039 19909933 19909933 -364039\"),\n (4, map read $ words \"-71868244 -24941524 -24941524 -24941524 -24941524 -24941524 -24941524 -6170836 21985196 21985196 21985196 21985196 40755884 40755884 40755884 68911916\"),\n (4, map read $ words \"11368 -623328 -1892720 -623328 -1892720 -4431504 -1258024 -1892720 1280760 646064 646064 2550152 4454240 646064 1280760 1280760\"),\n (4, map read $ words \"2413742 -1336682 -8837530 28666710 2413742 -16338378 2413742 6164166 -8837530 13665014 9914590 6164166 -12587954 6164166 -1336682 9914590\"),\n (4, map read $ words \"-14473327 44823703 17455843 -23595947 -9912017 17455843 -789397 -14473327 -5350707 -28157257 -5350707 -9912017 -9912017 -789397 17455843 12894533\"),\n (4, map read $ words \"3284309 -2011475 3284309 -23194611 -12603043 -7307259 -2011475 -12603043 8580093 -12603043 -12603043 -17898827 3284309 -23194611 -39081963 29763229\"),\n (4, map read $ words \"13371337 13371337 13371337 13371337 13371337 13371337 13371337 13371337 13371337 13371337 13371337 13371337 13371337 13371337 13371337 13371337\"),\n (4, map read $ words \"3773926 -6772298 2016222 2016222 -1499186 -6772298 -1499186 2016222 -1499186 -1499186 2016222 10804742 -1499186 -1499186 2016222 2016222\"),\n (4, map read $ words \"-4287644 29340128 -4287644 -46322359 -37915416 -4287644 29340128 -4287644 -4287644 20933185 -29508473 37747071 29340128 20933185 -29508473 62967900\"),\n (4, map read $ words \"-5 -4 3 -4 4 -2 4 -3 -2 4 -2 5 2 4 2 -6\"),\n (4, map read $ words \"8 -7 8 3 -5 -5 2 3 -5 7 -13 -1 2 4 4 -5\"),\n (4, map read $ words \"-1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16\"),\n (4, map read $ words \"18 2 24 9 -4 5 7 -9 -1 3 5 -3 10 -1 -23 -2\"),\n (4, map read $ words \"-11107327 -16312908 -21518489 -26724070 -31929651 -37135232 -52751975 -78779880 -696165 4509416 9714997 14920578 20126159 25331740 40948483 66976388\"),\n (4, map read $ words \"-12529096 -16064890 -19600684 -23136478 -26672272 -33743860 -44351242 -58494418 -5457508 -1921714 1614080 5149874 8685668 15757256 26364638 40507814\"),\n (4, map read $ words \"-80196146 -51775286 -34722770 -29038598 -17670254 -11986082 -6301910 -617738 10750606 16434778 22118950 27803122 39171466 44855638 61908154 90329014\"),\n (4, map read $ words \"-53765840 41030320 -11107568 -1627952 -20587184 7851664 -82204688 69469168 3111856 12591472 31550704 22071088 -15847376 -25326992 -44286224 -34806608\"),\n (4, map read $ words \"-3881001 -6742541 -9604081 -12465621 -18188701 -21050241 -26773321 -49665641 1842079 4703619 7565159 10426699 13288239 24734399 33319019 36180559\"),\n (4, map read $ words \"-1362991 -4200802 -7038613 -9876424 -15552046 -18389857 -24065479 -32578912 4312631 7150442 9988253 12826064 15663875 21339497 24177308 41204174\"),\n (4, map read $ words \"18047153 23317234 28587315 33857396 39127477 44397558 49667639 60207801 -3033171 -8303252 -13573333 -18843414 -24113495 -29383576 -55733981 -45193819\"),\n (4, map read $ words \"-4396182 740352 5876886 11013420 16149954 21286488 26423022 41832624 -14669250 -19805784 -24942318 -30078852 -35215386 -40351920 -45488454 -60898056\"),\n (4, map read $ words \"-36858210 -25967360 -4185660 -19432850 -82599780 -60818080 -39036380 -17254680 26308720 48090420 69872120 91653820 28486890 13239700 35021400 45912250\"),\n (4, map read $ words \"32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2\"),\n (4, map read $ words \"3918060 12506682 8825844 6371952 10052790 2691114 11279736 5145006 17414466 13733628 1464168 -23688225 40112967 38886021 -2216670 -24915171\"),\n (4, map read $ words \"-6080284 20608576 -60792447 75320739 -63461333 77989625 -14086942 28615234 9933032 12601918 17939690 15270804 4595260 1926374 -3411398 -742512\"),\n (4, map read $ words \"-62314327 -58329965 -50361241 -38408155 -30439431 -22470707 -14501983 -6533259 9404189 17372913 25341637 33310361 41279085 53232171 61200895 65185257\")\n ]\n-}\n\nmagic :: Array (Int, Int) Int -> Bool\nmagic a = 1 == length (nub as)\n where\n n = snd $ snd $ bounds a\n as = [sum [a ! (i,i) | i <- [1..n]]]\n ++ [sum [a ! (i,n+1-i) | i <- [1..n]]]\n ++ [sum [a ! (i,j) | j <- [1..n]] | i <- [1..n]]\n ++ [sum [a ! (i,j) | i <- [1..n]] | j <- [1..n]]\n\nsolve :: Int -> [Int] -> Array (Int, Int) Int\nsolve 1 [a] = listArray ((1,1), (1,1)) [a]\nsolve 2 [a, _, _, _] = listArray ((1,1), (2,2)) [a,a,a,a]\nsolve 3 as = ans\n where\n as' = listArray (1, 9) $ sort as\n ans = head $ concatMap solve' as\n solve' :: Int -> [Array (Int, Int) Int]\n solve' a = filter magic $ do\n [i, j, k] <- map (take 3) $ permutations [2, 3, 4, 6, 7, 8]\n let is = [i, j, k, 1, 5, 9, 10 - k, 10 - j, 10 - i]\n return $ listArray ((1,1), (3,3)) [as' ! i | i <- is]\nsolve 4 as = ans\n where\n s4 = div (sum as) 4\n asSort = sort as\n as' = listArray (1,16) asSort\n ans = head $ concatMap solve' asSort\n solve' a = do\n ai <- [3,2,1,4,5,6,7,8]\n bi <- [ix | ix <- [ai+1 .. 16]]\n ci <- [ix | ix <- [ai+1 .. 16], ix /= bi]\n di <- [ix | ix <- [ai+1 .. 16], ix /= bi, ix /= ci]\n hi <- [ix | ix <- [ai+1 .. 16], ix /= bi, ix /= ci, ix /= di]\n let a = as' ! ai\n let b = as' ! bi\n let c = as' ! ci\n let d = as' ! di\n let h = as' ! hi\n let g = s4 - a - b - h\n e <- [e | e <- [a + h - d], d <= e]\n let f' = s4 - a - c - h\n f <- if c <= f' then [f'] else []\n a' <- asSort \\\\ (a : sort [b,c,d,e,f,g,h])\n o <- a'\n let p = s4 - a - b - o\n let u = s4 - o - c - e\n let v = s4 - p - d - f\n if (g + u + v + h /= s4)\n then fail \"\"\n else do\n a'' <- a' \\\\ sort [o, p, u, v] \n q <- a''\n let s = s4 - a - q - g\n let r = s4 - q - c - d\n let t = s4 - b - r - h\n if (s + e + f + t /= s4)\n then fail \"\"\n else if (sort [a,b,c,d,e,f,g,h,o,p,q,r,s,t,u,v] == asSort)\n then return $ listArray ((1,1), (4,4)) [a,o,p,b,q,c,d,r,s,e,f,t,g,u,v,h]\n else fail \"\"\n where\n (\\\\) :: [Int] -> [Int] ->[[Int]]\n (\\\\) full del = f full (sort del)\n where \n f xs [] = [full]\n f [] _ = []\n f (x:xs) (y:ys)\n | x < y = f xs (y:ys)\n | x > y = f (x:xs) ys\n | otherwise = f xs ys\n\nprint :: Array (Int, Int) Int -> IO ()\nprint a = do\n let n = snd $ snd $ bounds a\n putStrLn $ show $ sum [a ! (i,i) | i <- [1..n]]\n mapM_ (\\i -> putStrLn (concatMap (\\j -> show (a ! (i,j)) ++ \" \") [1..n])) [1..n]\n\nmain :: IO ()\nmain = do\n n <- readLn\n as <- fmap (map read . words) getLine\n print $ solve n as\n", "src_uid": "7c806fb163aaf23e1eef3e6570aea436"} {"source_code": "import Data.Char \n\ngetInt :: IO Int\ngetInt = do \n line <- getLine\n return (read line :: Int)\n\nmain = do \n n <- getInt\n let x = div n 3\n let y = mod n 3\n let z = if y == 2 then x + 1 else x\n let w = div z 12\n let v = mod z 12\n print w\n print v\n", "src_uid": "5d4f38ffd1849862623325fdbe06cd00"} {"source_code": "{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances #-}\n{-# OPTIONS_GHC -O2 #-}\n\nimport Data.List\nimport Data.Maybe\nimport Data.Char\nimport Data.Array.IArray\nimport Data.Array.Unboxed (UArray)\nimport Data.Int\nimport Data.Ratio\nimport Data.Bits\nimport Data.Function\nimport Data.Ord\n--import Control.Monad.State\nimport Control.Monad\nimport Control.Applicative\nimport Data.ByteString.Char8 (ByteString)\nimport qualified Data.ByteString.Char8 as BS\nimport Data.Set (Set)\nimport qualified Data.Set as Set\nimport Data.Map (Map)\nimport qualified Data.Map as Map\nimport Data.IntMap (IntMap)\nimport qualified Data.IntMap as IntMap\nimport Data.Sequence (Seq, (<|), (|>), (><), ViewL(..), ViewR(..))\nimport qualified Data.Sequence as Seq\nimport qualified Data.Foldable as F\nimport Data.Graph\n\nimport Debug.Trace\n\nparseInput = do \n limit <- (,) <$> readInteger <*> readInteger\n k <- readInt\n from <- (,) <$> readInteger <*> readInteger\n to <- (,) <$> readInteger <*> readInteger\n return (limit, k, from, to)\n where\n readInt = state $ fromJust . BS.readInt . BS.dropWhile isSpace\n readInteger = state $ fromJust . BS.readInteger . BS.dropWhile isSpace\n readString = state $ BS.span (not . isSpace) . BS.dropWhile isSpace\n readLine = state $ BS.span (not . isEoln) . BS.dropWhile isEoln\n isEoln ch = ch == '\\r' || ch == '\\n'\n\nmain = print =<< solve . evalState parseInput <$> BS.getContents\n\nadd0 len str | length str > len = replicate len 'F'\nadd0 len str | length str < len = replicate (len - length str) '0' ++ str\nadd0 len str = str\n\nmaxn = 16 :: Int\n\nsolveCase (h, m) k (h', m') = searchH (0, False, False, 0, 0)\n where\n hUpper = listArray (0, hLen - 1) $ map digitToInt $ show (h - 1) :: UArray Int Int\n mUpper = listArray (0, mLen - 1) $ map digitToInt $ show (m - 1) :: UArray Int Int\n\n hUpper' = listArray (0, hLen - 1) $ map digitToInt $ add0 hLen $ show h' :: UArray Int Int\n mUpper' = listArray (0, mLen - 1) $ map digitToInt $ add0 mLen $ show m' :: UArray Int Int\n\n hLen = length $ show (h - 1)\n mLen = length $ show (m - 1)\n\n searchH :: (Int, Bool, Bool, Int, Int) -> Integer\n searchH = (cache!)\n where\n bnds = ((0, False, False, 0, 0), (maxn, True, True, maxn, maxn))\n cache = listArray bnds $ map go $ range bnds :: Array (Int, Bool, Bool, Int, Int) Integer\n\n go (pos, ltH, ltH', consec9, count0) | pos < hLen = sum lst\n where\n lst = [ searchH ( pos + 1\n , ltH || digit < (hUpper ! pos)\n , ltH' || digit < (hUpper' ! pos)\n , if digit == 9 then consec9 + 1 else 0\n , count0 + if digit == 0 then 1 else 0\n )\n | digit <- [0..9]\n , ltH || digit <= (hUpper ! pos)\n , ltH' || digit <= (hUpper' ! pos)\n ]\n\n go (pos, ltH, ltH', consec9, count0)\n | not ltH = searchM (0, (False, ltH'), 0, 0, hLen - count0)\n | otherwise = searchM (0, (False, ltH'), 0, 0, consec9 + 1)\n\n searchM :: (Int, (Bool, Bool), Int, Int, Int) -> Integer\n searchM = (cache!)\n where\n bnds = ((0, (False, False), 0, 0, 0), (maxn, (True, True), maxn, maxn, maxn))\n cache = listArray bnds $ map go $ range bnds :: Array (Int, (Bool, Bool), Int, Int, Int) Integer\n\n go (pos, (ltM, ltM'), consec9, count0, changeH) | pos < mLen = sum lst\n where\n lst = [ searchM ( pos + 1\n , (ltM || digit < (mUpper ! pos) , ltM' || digit < (mUpper' ! pos))\n , if digit == 9 then consec9 + 1 else 0\n , count0 + if digit == 0 then 1 else 0\n , changeH\n )\n | digit <- [0..9]\n , ltM || digit <= (mUpper ! pos)\n , ltM' || digit <= (mUpper' ! pos)\n ]\n\n go (pos, (ltM, ltM'), consec9, count0, changeH)\n | not ltM' = 0\n | not ltM = if mLen - count0 + changeH >= k then 1 else 0\n | otherwise = if consec9 + 1 >= k then 1 else 0\n\nsolve (limit, k, from, to)\n | from <= to = count to - count from\n | otherwise = (count limit - count from) + count to\n where\n count = solveCase limit k\n\n----------------------------------------------------------------------\n----------------------------------------------------------------------\n----------------------------------------------------------------------\n\nclass (Monad m) => MonadState s m | m -> s where\n\tget :: m s\n\tput :: s -> m ()\n\nmodify :: (MonadState s m) => (s -> s) -> m ()\nmodify f = do\n\ts <- get\n\tput (f s)\n\ngets :: (MonadState s m) => (s -> a) -> m a\ngets f = do\n\ts <- get\n\treturn (f s)\n\nnewtype State s a = State { runState :: s -> (a, s) }\n\ninstance Functor (State s) where\n\tfmap f m = State $ \\s -> let\n\t\t(a, s') = runState m s\n\t\tin (f a, s')\n\ninstance Applicative (State s) where\n pure = return\n (<*>) = ap\n\ninstance Monad (State s) where\n\treturn a = State $ \\s -> (a, s)\n\tm >>= k = State $ \\s -> let\n\t\t(a, s') = runState m s\n\t\tin runState (k a) s'\n\ninstance MonadState s (State s) where\n\tget = State $ \\s -> (s, s)\n\tput s = State $ \\_ -> ((), s)\n\nevalState :: State s a -> s -> a\nevalState m s = fst (runState m s)\n\nexecState :: State s a -> s -> s\nexecState m s = snd (runState m s)\n\nmapState :: ((a, s) -> (b, s)) -> State s a -> State s b\nmapState f m = State $ f . runState m\n\nwithState :: (s -> s) -> State s a -> State s a\nwithState f m = State $ runState m . f\n\nstate = State\n", "src_uid": "e2782743229645ad3a0f8e815d86dc5f"} {"source_code": "answer = [1, 3, 15, 133, 2025, 37851, 1030367, 36362925]\n\nsolve :: Int -> Integer\nsolve n = if n `mod` 2 == 0\n then 0\n else answer !! (n `div` 2) * product [1..fromIntegral n] `mod` (1000000000 + 7)\n\nmain = interact work where\n work = show . solve . (\\x -> read x :: Int)\n", "src_uid": "a6a804ce23bc48ec825c17d64ac0bb69"} {"source_code": "main=putStrLn.slv.map read.words=< words <$> getLine::IO [Int] \n putStrLn $ process a b\n\n", "src_uid": "3041b1240e59341ad9ec9ac823e57dd7"} {"source_code": "import Data.List\n\nmain = getLine >> getLine >>= putStrLn . solve\n\nsolve [x] = [x]\nsolve (x:y:xs)\n | isvowel x && isvowel y = solve (x:xs)\n | otherwise = x : solve (y:xs)\n where isvowel = (`elem` \"aeiouy\")\n", "src_uid": "63a4a5795d94f698b0912bb8d4cdf690"} {"source_code": "module Main (main) where\n\nlooser :: [(a, Int)] -> Int -> a \nlooser participans s = fst $ head $ filter ((< 0). snd) $ history $ concat $ repeat participans\n where history x = zip (fmap fst x) $ tail $ scanl step s $ fmap snd x\n step a x = a - gcd x a\n \nmain :: IO ()\nmain = do cont <- getContents\n let [a, b, n] = fmap read $ words cont\n print $ looser [(1, a), (0, b)] n\n ", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2"} {"source_code": "main = getContents >>= print . solve 0 1 . map read . words\n\nsolve ans c (a:b:_)\n | b < a = solve ans c (b:a:[])\n | a == b = ans\n | b - a == 1 = ans + c\n | otherwise = solve (ans + 2 * c) (c + 1) (a + 1 : b - 1 :[])\n", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da"} {"source_code": "main = getLine >>= putStrLn . solve . map read . words\n\nsolve [n,a,b]\n | b < a = answer (solve' [0,n,b,a]) $ log2 n\n | otherwise = answer (solve' [0,n,a,b]) $ log2 n\n where log2 1 = 0\n log2 n = 1 + (log2 $ n `div` 2)\n solve' [m,n,a,b]\n | middle < a = solve' [middle,n,a,b]\n | middle >= b = solve' [m,middle,a,b]\n | otherwise = log2 $ n - m\n where middle = (m + n) `div` 2\n answer a b\n | a == b = \"Final!\"\n | otherwise = show a\n", "src_uid": "a753bfa7bde157e108f34a28240f441f"} {"source_code": "import Control.Applicative\nimport Data.List\n\n\n \n \n\nmain= do\n\ts<-getLine\n\tlet sh = read $ take 2 s ::Int\n\tlet sm = read $ drop 3 s ::Int\n\tt<-getLine\n\tlet th = read $ take 2 t ::Int\n\tlet tm = read $ drop 3 t ::Int\n\tlet qm = mod (sm-tm) 60\n\tlet qh = mod ((sh-th) - (if tm>sm then 1 else 0)) 24\n\tlet ans1 = if qh <10 then '0':(show qh) else show qh\n\tlet ans2= if qm <10 then '0':(show qm) else show qm\n\tputStrLn $ ans1++\":\" ++ ans2\n\n", "src_uid": "595c4a628c261104c8eedad767e85775"} {"source_code": "import Data.List\n\n\nsolve n = head [x | x<-[n+1..], length (nub (show x))==4]\n\nmain = do\n\tn<-getLine\n\tputStrLn $ show $ solve (read n)", "src_uid": "d62dabfbec52675b7ed7b582ad133acd"} {"source_code": "{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -cpp #-}\n{-# OPTIONS_GHC -funbox-strict-fields -fexcess-precision -monly-3-regs #-}\n{-# LANGUAGE BangPatterns, OverloadedStrings, ScopedTypeVariables #-}\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.List\nimport Data.Ord\nimport Text.Printf\n\nmain :: IO ()\nmain = do\n let readData :: IO [Integer]\n readData = map read . words <$> getLine\n n : m : s : _ <- readData\n let a = (n - 1) `rem` s + 1\n b = (m - 1) `rem` s + 1\n c = (n - 1) `quot` s + 1\n d = (m - 1) `quot` s + 1\n answer = a * b * c * d\n printf \"%d\\n\" answer\n\n\n\n", "src_uid": "e853733fb2ed87c56623ff9a5ac09c36"} {"source_code": "--import Control.Monad.ST\n--import Data.Array.ST\nimport Control.Monad(liftM)\n\n\nswaps :: Int -> String -> String\nswaps _ [] = []\nswaps 0 a = a\nswaps k a = minc: swaps (k - kmin) after\n where\n kmin = negate $ snd $ maximum $ take (k + 1) $ zip a [0,-1..]\n after = take kmin a ++ drop (kmin + 1) a\n minc = a !! kmin\n\nmain :: IO ()\nmain = do\n [as, ks] <- words `liftM` getLine\n let k = read ks :: Int\n putStr $ swaps k as\n", "src_uid": "e56f6c343167745821f0b18dcf0d0cde"} {"source_code": "main = getLine >> getLine >>= print . minimum . map solve . rotations . map read . words\n where\n solve = minimum . map (\\s -> abs $ (360 :: Int) - 2 * s) . scanl1 (+)\n rotations xs = take (length xs) $ iterate (\\(x:xs) -> xs ++ [x]) xs", "src_uid": "1b6a6aff81911865356ec7cbf6883e82"} {"source_code": "import Data.List\nz n m k\n |km+n-2= -1\n |1>0=m`div`(1+(k-(n-1)))\ns[n,m,k]=max(z n m k)(z m n k)\nmain=interact$show.s.map read.words\n", "src_uid": "bb453bbe60769bcaea6a824c72120f73"} {"source_code": "import Data.List\n\nreadInts :: IO [Int]\nreadInts = fmap (map read.words) getLine\n\ng :: Bool -> Int -> Int -> Int\ng True a _ = a\ng False _ a = a\n\nf :: Int -> Int -> [Int] -> Int\nf n curr xs \n | n==1 = 0\n | curr==0 = min (xs!!0) (xs!!1) + f (n - 1) (g (min (xs!!0) (xs!!1) == (xs!!0)) 1 2) xs\n | curr==1 = min (xs!!0) (xs!!2) + f (n - 1) (g (min (xs!!0) (xs!!2) == (xs!!0)) 0 2) xs\n | otherwise = min (xs!!1) (xs!!2) + f (n - 1) (g (min (xs!!1) (xs!!2) == (xs!!1)) 0 1) xs\n\nmain = do\n (n:_) <- readInts\n (a:_) <- readInts\n (b:_) <- readInts\n (c:_) <- readInts\n print( f n 0 [a,b,c])", "src_uid": "6058529f0144c853e9e17ed7c661fc50"} {"source_code": "module Main (main) where\n\nimport Control.Monad\nimport Control.Applicative\n\n\ntype GroupCount = (Int, Int, Int, Int, Int)\n\n\ncountGroups :: [Int] -> GroupCount\ncountGroups = foldl f (0, 0, 0, 0, 0)\n where\n f (a, b, c, d, e) 1 = (a+1, b, c, d, e)\n f (a, b, c, d, e) 2 = (a, b+1, c, d, e)\n f (a, b, c, d, e) 3 = (a, b, c+1, d, e)\n f (a, b, c, d, e) 4 = (a, b, c, d+1, e)\n f (a, b, c, d, e) 5 = (a, b, c, d, e+1)\n\n\nsolve :: [Int] -> [Int] -> Int\nsolve as bs = if canSolve then answer else -1\n where\n (a, b, c, d, e) = countGroups as\n (p, q, r, s, t) = countGroups bs\n\n diffs = [ a - p\n , b - q\n , c - r\n , d - s\n , e - t\n ]\n \n canSolve = all even diffs\n answer = sum (map abs diffs) `quot` 4\n\n\nmain :: IO ()\nmain = do\n n <- readLn\n as <- readInts n\n bs <- readInts n\n print (solve as bs)\n\n\nreadInts :: Int -> IO [Int]\nreadInts n = map read . words <$> getLine\n", "src_uid": "47da1dd95cd015acb8c7fd6ae5ec22a3"} {"source_code": "{-# LANGUAGE FlexibleContexts, ScopedTypeVariables, BangPatterns #-}\n{-# OPTIONS_GHC -O2 #-}\n\nimport Control.Applicative\nimport Control.Monad\nimport Control.Monad.ST.Safe\nimport Control.Monad.State\nimport Data.Array\n-- import Data.Array.IArray\nimport Data.Array.IO.Safe\nimport Data.Array.MArray.Safe\nimport Data.Array.ST.Safe\n-- import Data.Array.Unboxed\nimport qualified Data.ByteString.Char8 as B\nimport qualified Data.ByteString.Lazy.Builder as BB\nimport Data.Char\nimport qualified Data.Foldable as F\nimport Data.Function\n-- import Data.Graph\nimport Data.Int\nimport Data.List\nimport Data.List.Split\nimport Data.Maybe\nimport Data.Monoid\nimport Data.Ratio\nimport qualified Data.Sequence as Seq\nimport Data.Sequence (Seq)\nimport Data.Set (Set)\nimport qualified Data.Set as Set\n-- import Data.Tree\nimport Data.Tuple\nimport Data.Map (Map)\nimport qualified Data.Map as Map\nimport Data.IntMap (IntMap)\nimport qualified Data.IntMap as IntMap\nimport System.IO\n-- import Debug.Trace\n\ngetInts = fmap (map read . words) getLine\n-- getInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine\n\nmain = do\n [v1, v2] <- getInts\n [t, d] <- getInts\n\n print $ sum [min (v1 + d*i) (v2 + d*(t-i-1)) | i <- [0..t-1]]\n", "src_uid": "9246aa2f506fcbcb47ad24793d09f2cf"} {"source_code": "\nimport Control.Monad (liftM)\n\n--------------------------------------------------------------------------------\n{-\nimport HUnit\n\ntestInput :: Test\ntestInput = TestList \"TestInput\"\n [\n Test \"#1\" $ assertEq 2 $ solve 2 6 12 11,\n Test \"#2\" $ assertEq 4 $ solve 2 3 5 1,\n Test \"#3\" $ assertEq 1 $ solve 3 6 81 9\n ]\n\ntest :: IO ()\ntest = mapM_ run\n [\n testInput\n ]\n-}\n--------------------------------------------------------------------------------\n\nnext :: Int -> Int -> Int -> Int -> Int\nnext a b m r = (a * r + b) `mod` m\n\nnexts :: Int -> Int -> Int -> Int -> [Int]\nnexts a b m r = iterate (next a b m) r\n\nsolve :: Int -> Int -> Int -> Int -> Int\nsolve a b m r0 = solve' 1 (head ns) (tail ns)\n where\n ns = drop m $ nexts a b m r0\n solve' n x0 (x:xs)\n | x == x0 = n\n | otherwise = solve' (n+1) x0 xs\n\nmain :: IO ()\nmain = do\n [a, b, m, r0] <- liftM (map read . words) getLine\n print $ solve a b m r0\n", "src_uid": "9137197ee1b781cd5cc77c46f50b9012"} {"source_code": "import Data.List\nimport System.IO\n\nmain = do\n _ <- fmap read getLine :: IO Int\n xs <- fmap (fmap read . words) getLine :: IO [Int]\n print $ solve xs\n \n\nsolve :: [Int] -> Int\nsolve xs = length xs * foldr1 gcd xs\n", "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4"} {"source_code": "{-# OPTIONS_GHC -O2 #-}\n{-# LANGUAGE BangPatterns, TupleSections #-}\n\nimport Data.List\nimport qualified Data.IntSet as IS\nimport Data.Array.Base\n\nmain=interact$show.f.map read.words\nf :: [Int] -> Int\nf[a,b,n]=foldl'(+%)0.map(comb n)$filter isGood[0..n]\n where\n goods :: IS.IntSet\n !goods = IS.fromList.map read$concat[mapM(const[ca,cb])[1..i]|i<-[1..9]]\n isGood k = IS.member ((a-b)*k+b*n) goods\n !ca = show a !! 0\n !cb = show b !! 0\n\n\nbigPrime :: Int\nbigPrime = 1000000007\n\ninfixl 7 *%, /%\ninfixl 6 +%, -%\n\n(+%) :: Int -> Int -> Int\nx +% y = case x+y of\n xy | xy < bigPrime -> xy\n | otherwise -> xy-bigPrime\n\n(-%) :: Int -> Int -> Int\nx -% y = case x-y of\n xy | xy >= 0 -> xy\n | otherwise -> xy+bigPrime\n\n(*%) :: Int -> Int -> Int\nx *% y = fromInteger $ toInteger x * toInteger y `rem` toInteger bigPrime\n\n(/%) :: Int -> Int -> Int\nx /% y = x *% (fst (extGcd y bigPrime) `mod` bigPrime)\n\n{-# INLINE (+%) #-}\n{-# INLINE (-%) #-}\n{-# INLINE (*%) #-}\n{-# INLINE (/%) #-}\n\nextGcd :: Int -> Int -> (Int,Int)\nextGcd !a !b\n | b == 0 = (1, 0)\n | otherwise = (t, s - a `div` b * t)\n where\n (!s, !t) = extGcd b $ a `mod` b\n\npermmemo :: UArray Int Int\npermmemo = listArray(0,1000000)$scanl(*%)1[1..1000000]\n\nperm :: Int -> Int -> Int\nperm n k = foldl' (*%) 1 [n -% k +% 1..n]\n\nfact :: Int -> Int\nfact n = perm n n\n\ncomb :: Int -> Int -> Int\ncomb n 0 = 1\ncomb n k = (unsafeAt permmemo n) /% ((unsafeAt permmemo (n-k)) *% (unsafeAt permmemo k))", "src_uid": "d3e3da5b6ba37c8ac5f22b18c140ce81"} {"source_code": "pocet n = poc n 3\npoc n d\n | d > n = 1\n | n `mod` d == 0 = poc n (d*3)\n | otherwise = n `div` d + 1\n\n\nmain = do\n n <- readLn\n print (pocet n)\n", "src_uid": "7e7b59f2112fd200ee03255c0c230ebd"} {"source_code": "import Data.List.Split\nimport Data.List\n\nmakeIntArray :: [Char] -> [Int]\nmakeIntArray y = map (\\x -> read x :: Int) $ (splitOn \" \") y\n\ngetSum :: [[Int]] -> Int\ngetSum arr = div (arr!!0!!1 + 2* arr!!0!!2 + 2*arr!!1!!2 + arr!!1!!0) 2\n\nreplaceZero :: [Int] -> Int -> [Int]\nreplaceZero (x:xs) y\n | x == 0 = (y:xs)\n | otherwise = (x: replaceZero xs y) \n\nmain::IO()\nmain = do \n input1 <- getLine\n input2 <- getLine\n input3 <- getLine\n let arr = map makeIntArray [input1, input2, input3]\n let sum = getSum arr\n let ans = [(replaceZero (arr!!0) (sum - (arr!!0!!1 + arr!!0!!2))), (replaceZero (arr!!1) ( sum - (arr!!1!!0 + arr!!1!!2))), (replaceZero (arr!!2) ( sum - (arr!!2!!0 + arr!!2!!1)))]\n mapM_ putStrLn $ map (intercalate \" \") $ map (map show) ans\n", "src_uid": "0c42eafb73d1e30f168958a06a0f9bca"} {"source_code": "-- Codeforces 1040A\nimport Data.List\n\nzipWithPrice :: [Int] -> Int -> Int -> [Int]\nzipWithPrice dancers priceA priceB = zipWith func dancers (reverse dancers)\n where func 0 1 = -1\n func 2 1 = priceB\n func 2 0 = priceA\n func 2 2 = min priceA priceB\n func _ _ = 0\n\ncomputePrice :: [Int] -> Int -> Int -> Int\ncomputePrice dancers priceA priceB = if (-1) `elem` priceList then -1\n else sum priceList\n where priceList = zipWithPrice dancers priceA priceB\n\nmain :: IO ()\nmain = do\n [n, a, b] <- getLine >>= return . (map read) . words :: IO [Int]\n dancers <- getLine >>= return . (map read) . words :: IO [Int]\n putStrLn $ show $ computePrice dancers a b\n", "src_uid": "af07223819aeb5bd6ded4340c472b2b6"} {"source_code": "import Data.List\n\nreadNumbers :: String -> [Int]\nreadNumbers = map read . words\n\n\ndiff k = last(k) - head(k)\n\nsolve n f result | length (f) <= n = min result (last (f) - head(f))\n | otherwise = solve n (tail f) (min result (diff (take n f)))\n\nparse x y = putStrLn $ show $ solve (head (readNumbers x)) (sort (readNumbers y)) 1008\nmain = getLine >>= (\\x -> getLine >>= parse x)\n", "src_uid": "7830aabb0663e645d54004063746e47f"} {"source_code": "import Data.List\nimport Data.Ord\ng x = head $ maximumBy (comparing length) (group . sort $ fn x) \nfn [x,y] = [[x,y]] \nfn (x:y:xs) = [x,y] : (fn $ y:xs) \nmain = do\n _ <- getLine\n a <- getLine\n putStrLn $ g a", "src_uid": "e78005d4be93dbaa518f3b40cca84ab1"} {"source_code": "main :: IO()\nmain = print . solve . map read . words =<< getLine\n\nsolve :: [Integer] -> Integer\nsolve [n, k] = let m = max (n - 2 * k) 0\n in n * (n - 1) `div` 2 - m * (m - 1) `div` 2\n", "src_uid": "ea36ca0a3c336424d5b7e1b4c56947b0"} {"source_code": "{-# LANGUAGE Safe #-}\n{-# LANGUAGE FlexibleContexts #-}\n{-# LANGUAGE LambdaCase #-}\n{-# LANGUAGE ViewPatterns #-}\n{-# LANGUAGE TupleSections #-}\n{-# LANGUAGE MultiWayIf #-}\n\nimport Control.Monad\nimport Control.Monad.ST.Safe\nimport Control.Monad.State\nimport Control.Applicative\nimport Control.Arrow\nimport Data.List\nimport Data.Array\nimport Data.Array.IO.Safe\nimport Data.Array.ST.Safe\nimport Data.IORef\nimport Data.STRef\nimport Data.Maybe\nimport Data.Bits\nimport Data.Ord\nimport Data.Ratio\nimport Data.Int\nimport Data.Char\nimport qualified Data.IntMap as IM\nimport qualified Data.ByteString.Char8 as BS\nimport qualified Data.Set as Set\nimport qualified Data.Sequence as Sq\nimport Data.Tuple\nimport Data.Function\nimport Text.Printf\nimport Numeric\n\nreadIntBS = fst . fromJust . BS.readInt\n\nmain = do\n [n,m] <- map read . words <$> getLine :: IO [Integer]\n let x = minimum [i | i<-[0..n], i*(i-1)`div`2 >= m]\n printf \"%d %d\\n\" (max 0 (n-2*m)) (n-x)\n", "src_uid": "daf0dd781bf403f7c1bb668925caa64d"} {"source_code": "main = do\n a <- fmap (map read . words) getLine :: IO [Int]\n b <- fmap (map read . words) getLine :: IO [Int]\n putStrLn $ if null $ filter (\\x->fst x==snd x) $ zip a b then \"NO\" else \"YES\"\n", "src_uid": "91c9dbbceb467d5fd420e92c2919ecb6"} {"source_code": "\nmain :: IO ()\nmain = do\n [a, b, r] <- fmap (map (read :: String -> Int) . words) getLine\n if 2*r > a || 2*r > b\n then putStrLn \"Second\"\n else putStrLn \"First\"\n", "src_uid": "90b9ef939a13cf29715bc5bce26c9896"} {"source_code": "import Data.List\nimport qualified Data.Map as Map\nimport qualified Data.Set as Set\nimport Data.Char\n\nmain :: IO ()\nmain = do\n\ta <- getLine\n\tb <- getLine\n\tc <- getLine\n\tlet\n\t\t[xa, ya] = map (\\x -> read x :: Integer). words $ a\n\t\t[xb, yb] = map (\\x -> read x :: Integer). words$ b\n\t\t[xc, yc] = map (\\x -> read x :: Integer). words$ c\n\t\tx1 = xb - xa\n\t\ty1 = yb - ya\n\t\tx2 = xb - xc\n\t\ty2 = yb - yc\n\tif x1*y2 == y1*x2 then\n\t\tputStrLn \"TOWARDS\"\n\t\telse if x1*y2 - y1*x2 < 0 then\n\t\t\tputStrLn \"LEFT\"\n\t\t\telse\n\t\t\t\tputStrLn \"RIGHT\"\n", "src_uid": "f6e132d1969863e9f28c87e5a44c2b69"} {"source_code": "import Data.Int\ng a b m\n | b >= m - 1 = \"2\"\n | length list == 0 = \"2\"\n | otherwise = \"1 \" ++ (p . show . head) list\n where p s = if (length s) == 9 then s else p ('0':s)\n mul = mod 1000000000 m\n list = filter (\\x -> (m - (mul * x)) `mod` m > b) [0..(min m a)]\nmain = do [a, b, mod] <- fmap ((map (read::String->Int64)) . words) getLine\n putStrLn $ g a b mod", "src_uid": "8b6f633802293202531264446d33fee5"} {"source_code": "import Control.Monad\nimport Data.List\nimport Data.Maybe\nimport Data.Char \n\nimport qualified Data.ByteString.Char8 as B\nreadInt = readLn :: IO Int\nreadInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine\n\nsolve :: String -> Bool \nsolve s = (not (any (\\(a, b) -> c a && d b) (zip s (tail s)))) && (not (c (last s)))\n where c = not . (flip elem) \"aeioun\"\n d = not . (flip elem) \"aeiou\"\n\n\nmain :: IO ()\nmain = do\n s <- getLine\n -- print $ solve \"auuaoonntanonnuewannnnpuuinniwoonennyolonnnvienonpoujinndinunnenannmuveoiuuhikucuziuhunnnmunzancenen\"\n -- print $ solve \"ninja\"\n -- print $ solve \"codeforces\"\n -- print $ solve \"sumimasen\"\n -- print $ solve \"necnei\"\n -- print $ solve \"a\"\n -- print $ solve \"ab\"\n putStrLn $ if solve s then \"YES\" else \"NO\"\n\n", "src_uid": "a83144ba7d4906b7692456f27b0ef7d4"} {"source_code": "module Main where\nimport Data.Bool\nimport Data.List\nmain = getLine >> getLine >>= putStr . bool \"No\" \"Yes\" . solve\nsolve xs = xs /= \"0\" && (\\g -> notElem \"00\" [head g, last g] && all (`elem` [\"0\", \"1\", \"00\"]) g) (group xs)", "src_uid": "c14d255785b1f668d04b0bf6dcadf32d"} {"source_code": "main=interact$show.f.map read.words\nf[n,m,z]=sum[1|c<-[n,n+n..z],rem c m<1]", "src_uid": "e7ad55ce26fc8610639323af1de36c2d"} {"source_code": "--http://rextester.com ghc 7.10\nmain=interact(unwords.a.map read.words)\na[0,0]=[\"0 0\"]\na[0,_]=[\"Impossible\"]\na[b,c]=map show[max b c,if c/=0 then c+b-1 else b]", "src_uid": "1e865eda33afe09302bda9077d613763"} {"source_code": "-- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] - Problem A: Raising Bacteria (https://codeforces.com/problemset/problem/579/A) \nsolve 1 = 1\nsolve n | n `mod` 2 == 0 = solve (n `div` 2)\n | otherwise = 1 + solve (n `div` 2)\n\nmain = do\n n <- readLn :: IO Int\n print $ solve n\n", "src_uid": "03e4482d53a059134676f431be4c16d2"} {"source_code": "import Control.Applicative\nimport Data.List\n \n \n \nmain=do\t \n\t[n,x]<-map read.words <$> getLine:: IO [Int] \n\tprint $ length [1|i<-[1..n], mod x i ==0, div x i <=n]\n\t \n", "src_uid": "c4b139eadca94201596f1305b2f76496"} {"source_code": "main :: IO ()\nmain = interact $ show . solve . map read . words\n\nsolve :: [Integer] -> Integer\nsolve [m, n, k]\n | n >= (k - 1) * c = (2 * k * (exp2 d - 1) + e) `rem` p\n | otherwise = n\n where\n c = (m - n + 1)\n (q, r) = (n - (k - 1) * c) `quotRem` k\n d = q + min 1 r\n e = n - d * k\n\nexp2 :: Integer -> Integer\nexp2 0 = 1\nexp2 x\n | even x = y * y `rem` p\n | otherwise = y * y * 2 `rem` p\n where\n (q, r) = x `quotRem` 2\n y = exp2 q\n\np :: Integer\np = 1000000009\n", "src_uid": "9cc1aecd70ed54400821c290e2c8018e"} {"source_code": "\nanswer 0 = 1\nanswer x = (3 ^ (x - 1)) `mod` 1000003\nmain = do v <- getLine\n putStrLn $ show $ answer (read v::Integer)", "src_uid": "1a335a9638523ca0315282a67e18eec7"} {"source_code": "import Data.List\n\nmain = interact $ show . phi . (+(-1)) . read\n\nfact n = map (\\l -> (head l, length l)) . group $ divf n 2\n where divf 1 _ = []\n divf n' p | p^2 <= n = if n'`mod`p == 0\n then p:(divf (n'`div`p) p)\n else divf n' (p+1)\n | otherwise = [n']\n\nphi n = foldl' (\\r (p,k) -> r * phiPrime p k) 1 (fact n)\n where phiPrime p k = p^(k-1) * (p-1)\n", "src_uid": "3bed682b6813f1ddb54410218c233cff"} {"source_code": "import Control.Applicative\nimport Control.Monad\nimport Control.Arrow\nimport Data.List\nimport Data.Ord\nimport Data.Char\nimport Data.Array.IO\nimport Data.Array\nimport Text.Printf\n\nmain :: IO ()\nmain = do\n n <- readLn\n s <- reverse . take (2 * n) <$> getLine\n let a = listArray (1, 2 * n) $ map (toInteger . digitToInt) s :: Array Int Integer\n table <- newArray ((0, 0), (n, n)) 0 :: IO (IOArray (Int, Int) Integer)\n route <- newArray_ ((0, 0), (n, n)) :: IO (IOArray (Int, Int) Char)\n let initValue i = read . reverse $ take i s\n forM_ [0 .. n] $ \\i -> do\n forM_ [0 .. n] $ \\j -> do\n unless (i == 0 && j == 0) $ do\n let sumPrize idx x = (a ! idx) * 10 ^ (x - 1) \n h <- do\n if i > 0\n then (+ sumPrize (i + j) i) <$> readArray table (i - 1, j)\n else return 0\n m <- do\n if j > 0\n then (+ sumPrize (i + j) j) <$> readArray table (i, j - 1)\n else return 0\n writeArray table (i, j) $ max h m\n writeArray route (i, j) $ case () of\n _ | i == 0 -> 'M'\n | j == 0 -> 'H'\n | otherwise -> if h >= m then 'H' else 'M'\n let getOrder = f (n, n) where\n f (0, 0) = return \"\"\n f idx@(i, j) = do\n c <- readArray route idx\n if c == 'H'\n then (c :) <$> f (i - 1, j)\n else (c :) <$> f (i, j - 1)\n-- printArray table\n getOrder >>= putStrLn\n\nprintArrayWith :: (Show a) => Int -> IOArray (Int, Int) a -> IO ()\nprintArrayWith width table = do\n ((l1, c1), (l2, c2)) <- getBounds table\n forM_ [l1 .. l2] $ \\l -> do\n forM_ [c1 .. c2] $ \\c -> do\n v <- readArray table (l, c)\n printf \"%-*s \" width (show v)\n putChar '\\n'\n putChar '\\n'\n\nprintArray :: (Show a) => IOArray (Int, Int) a -> IO ()\nprintArray = printArrayWith 10\n", "src_uid": "98489fe54488dcfb45f8ae7b5c473d88"} {"source_code": "-- import Debug.Trace\n-- import System.IO.Unsafe\n-- import Text.Printf\nimport System.IO\nimport Control.Monad\nimport Data.List\n\nglwr = fmap (map read . words) getLine\n\nmain = do\n hSetBuffering stdout NoBuffering\n solve\n\nsolve :: IO ()\nsolve = do\n m:n:_ <- glwr\n\n print $ domino m n\n\ndomino :: Int -> Int -> Int\ndomino m n = (m * n) `div` 2\n", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd"} {"source_code": "{-# OPTIONS_GHC -funbox-strict-fields #-}\n\nimport Control.Applicative\nimport Control.Monad\nimport Control.Arrow\nimport Data.List\nimport Data.Ord\nimport Text.Printf\n\nmain :: IO ()\nmain = do\n let readDoubles = map read . words\n l : d : v : g : r : _ <- readDoubles <$> getLine\n let epsilon = 1e-9\n t = last . takeWhile (negate epsilon <=)\n $ zipWith (-) (repeat $ d / v) [0, g + r ..]\n waitTime = if t < g - epsilon\n then 0\n else g + r - t\n answer = l / v + waitTime :: Double\n printf \"%.7f\\n\" answer\n\n\n", "src_uid": "e4a4affb439365c843c9f9828d81b42c"} {"source_code": "import Data.Char\nimport Control.Monad\n\nreadIntImpl :: Int -> Bool -> IO Int\nreadIntImpl x flag = do\n c <- getChar\n if c `elem` ['0'..'9']\n then do\n let d = digitToInt c\n y <- readIntImpl (x*10+d) True\n return y\n else if flag\n then \n return x\n else do\n y <- readIntImpl x False\n return y\n\nreadInt = readIntImpl 0 False\nreadArr n readFunc = replicateM n readFunc\n\nf [] [] = []\nf (x:xs) (y:ys) = do\n if x < y then\n []\n else\n y:(f xs ys)\n\nmain = do\n x <- getLine\n y <- getLine\n let z = f x y\n let ans = if length z < length x then \"-1\" else z\n putStrLn ans", "src_uid": "ce0cb995e18501f73e34c76713aec182"} {"source_code": "import Data.List (sort)\nimport Control.Monad (filterM)\npowerset = filterM (const [True, False])\nsolve (l:r:x:c) = length $ filter acc (powerset $ sort c)\n where acc ps = let s = sum ps in length ps >= 2 && (maximum ps - minimum ps) >= x && s <= r && s >= l\nmain = putStrLn.show.solve.map read.tail.words =<< getContents\n", "src_uid": "0d43104a0de924cdcf8e4aced5aa825d"} {"source_code": "import Control.Applicative\nimport Control.Monad\nimport Data.List\nimport Data.Maybe\nimport Data.Array\n\n\n\n\nmain = do\n\t\tgetLine\n\t\ta<-map read <$> words <$> getLine ::IO [Int]\n\t \tprint $ max 0 ((maximum a) - 25) \n\n\n", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd"} {"source_code": "main = do\n n_ <- readLn\n as_ <- return . map read . words =<< getLine\n let lrs = map (`splitAt` as_) [1..n_]\n\tcheck (l,r) = sum l /= 0 && sum r /= 0\n\ttwoSplits = filter check lrs\n\ttotal = sum as_\n if total /= 0\n then do\n\tputStrLn \"YES\"\n\tprint 1\n\tputStr $ (show 1) ++ \" \" ++ (show n_)\n else case twoSplits of\n\t[] -> putStr \"NO\"\n\t(l,r):_ -> do\n\t putStrLn \"YES\"\n\t print 2\n\t let szL = length l\n\t putStrLn $ (show 1) ++ \" \" ++ (show szL)\n\t putStr $ (show$szL+1) ++ \" \" ++ (show n_)\n", "src_uid": "3a9258070ff179daf33a4515def9897a"} {"source_code": "run c m ans n | n == m = c:ans\n | n < m = run (succ c) 1 (succ c:ans) n\n | n > m = run c (m + 1) (c:ans) (n - m)\nmain = getLine >>= putStrLn . run 'a' 0 [] . read\n", "src_uid": "b991c064562704b6106a6ff2a297e64a"} {"source_code": "check p1 p2 p3 p4 x = if ((((x `mod` p1) `mod` p2) `mod` p3) `mod` p4) == x\n then 1\n else 0\n \ncount p1 p2 p3 p4 x b | x == b = check p1 p2 p3 p4 x\n | otherwise = (check p1 p2 p3 p4 x) + (count p1 p2 p3 p4 (x+1) b)\n\n\nbrute (f:fs) ts a b = (brute (fs) (ts ++ [f]) a b) -- + (brute (fs ++ [f]) ts a b)\n\nbrute [] (p1:p2:p3:p4:[]) a b = count p1 p2 p3 p4 a b\n\nsolve l a b = brute l [] a b\n \n \n\nmain = do\n line <- getLine\n let (p1:p2:p3:p4:a:b:[]) = map read (words line) :: [Int]\n putStrLn $ show $ solve [p1, p2, p3, p4] a b\n return ()\n", "src_uid": "63b9dc70e6ad83d89a487ffebe007b0a"} {"source_code": "-- Codeforces Round 380 (Div. 2)\n-- ID: Problem A. Interview with Oleg\n-- URL: http://codeforces.com/contest/738/problem/A\n\ngetInt = read `fmap` getLine :: IO Int\n\nmain = do\n n <- getInt\n s <- getLine\n putStrLn (ogoFilter s)\n\nogoFilter s = case split s of\n ([], []) -> []\n ([], r:rest) -> r : ogoFilter rest\n (ogo, rest) -> \"***\" ++ ogoFilter rest\n\nsplit [] = ([], [])\nsplit (c:cs)\n | c == 'o' && length go /= 0 = ('o' : go, drop (length go) cs)\n | otherwise = ([], c:cs)\n where\n go = f cs []\n f ('g':'o':s) acc = f s ('g':'o':acc)\n f s acc = acc\n", "src_uid": "619665bed79ecf77b083251fe6fe7eb3"} {"source_code": "modulus = 1000000007 :: Integer\n\nfactorial :: Integer -> Integer\nfactorial n = product [1..n]\n\nnCr :: Integer -> Integer -> Integer\nnCr n r = div (factorial n) $ (factorial r) * (factorial (n - r))\n\n\nmain :: IO ()\nmain = do \n [n, x, p] <- map read . words <$> getLine\n print $ solve n x p `mod` modulus\n\n\nsolve :: Integer -> Integer -> Integer -> Integer\nsolve n x p \n | (smallCount < smallPositions) || (bigCount < bigPositions) = 0\n | otherwise = product [nCr bigCount bigPositions, nCr smallCount smallPositions, factorial smallPositions, factorial bigPositions, factorial (n - bigPositions - smallPositions - 1)]\n where (smallPositions, bigPositions) = getBigSmallPos 0 n p\n (smallCount, bigCount) = (x - 1, n - x)\n\n\ngetBigSmallPos :: Integer -> Integer -> Integer -> (Integer, Integer)\ngetBigSmallPos s e p \n | s >= e = (-1, 0)\n | m <= p = let (a, b) = getBigSmallPos (m + 1) e p in (a + 1, b)\n | otherwise = let (a, b) = getBigSmallPos s m p in (a, b + 1)\n where m = (s + e) `div` 2\n\n", "src_uid": "24e2f10463f440affccc2755f4462d8a"} {"source_code": "import Control.Applicative\n\ncanBeBad :: Char -> Int\ncanBeBad '0' = 2 -- 0, 8\ncanBeBad '1' = 7 -- 0, 1, 3, 4, 7, 8, 9\ncanBeBad '2' = 2 -- 2, 8\ncanBeBad '3' = 3 -- 3, 8, 9\ncanBeBad '4' = 3 -- 4, 8, 9\ncanBeBad '5' = 4 -- 5, 6, 8, 9\ncanBeBad '6' = 2 -- 6, 8\ncanBeBad '7' = 5 -- 0, 3, 7, 8, 9\ncanBeBad '8' = 1 -- 8\ncanBeBad '9' = 2 -- 8, 9\n\nmain = do x <- getLine\n print $ foldl (*) 1 $ map canBeBad x\n", "src_uid": "76c8bfa6789db8364a8ece0574cd31f5"} {"source_code": "import Control.Monad\nimport Data.List\n\nnextmeet vp vd f x =\n let t = x / vd + f\n x' = x + t * vp\n in x' + x' / (vd - vp) * vp :: Double\n\nsolve vp vd t f c | vd <= vp = 0\nsolve vp vd t f c =\n let firstmeet = t * vp + t * vp / (vd - vp) * vp\n meets = iterate (nextmeet vp vd f) firstmeet\n in length $ takeWhile (< c - 1e-10) meets\n\nmain = do\n [vp, vd, t, f, c] <- replicateM 5 $ liftM read getLine\n print $ solve vp vd t f c\n", "src_uid": "c9c03666278acec35f0e273691fe0fff"} {"source_code": "import Control.Applicative\n\npillowsTo :: Integral t => t -> t -> t\npillowsTo i k = let a = max (i - k + 1) 0 in (a + i) * (i - a + 1) `quot` 2\n\ntotalPillows :: Integral a => a -> a -> a -> a\ntotalPillows i k n = pillowsTo i k + pillowsTo i (n - k + 1) - i\n\ndiho::Integer->Integer->Integer->Integer\ndiho n m k = go start end where\n start = 0\n end = m - n + 1\n go s e = let mid = (s + e) `quot` 2\n total = totalPillows mid k n\n good = total <= m - n\n found = e - s <= 1\n in if found then s + 1 else if good then go mid e else go s mid\n\nmain :: IO ()\nmain = do\n [n, m, k] <- fmap read . words <$> getLine\n print $ diho n m k\n", "src_uid": "da9ddd00f46021e8ee9db4a8deed017c"} {"source_code": "main = do\n s <- getLine\n putStrLn (normalize s)\n\nnormalize :: String -> String\nnormalize = normalize'' . normalize'\n\nnormalize' :: String -> String\nnormalize' (x:o@(y:_)) = if and [x == '/', y == '/'] then normalize' o else x:normalize o\nnormalize' x = x\n\nnormalize'' :: String -> String\nnormalize'' [] = []\nnormalize'' [x] = [x]\nnormalize'' x = if last x == '/' then init x else x\n", "src_uid": "6c2e658ac3c3d6b0569dd373806fa031"} {"source_code": "{-# LANGUAGE TypeApplications #-}\n\nimport Data.List\n\nmain :: IO ()\nmain = do\n _ <- getLine\n a <- fmap (map (read @ Int) . words) getLine\n print $ run $ sort a\n\nrun :: [Int] -> Int\nrun [] = 0\nrun (x:xs) = 1 + run (filter (\\e -> e `mod` x /= 0) xs)\n", "src_uid": "63d9b7416aa96129c57d20ec6145e0cd"} {"source_code": "import Control.Applicative\nimport Control.Monad\nimport Data.List\nimport Data.Maybe\nimport Data.Array\nimport qualified Data.Map as M\n\n\t\t\n\nmain = do\n\t\t[a,b,c]<-map read <$> words <$> getLine ::IO [Integer]\n\t\tprint $ (c+ (min a b))*2 + if a==b then 0 else 1\n\n", "src_uid": "609f131325c13213aedcf8d55fc3ed77"} {"source_code": "import Data.Array\n\ndp = array ((2,0,0), (20,20,3)) [((i,j,k), f i j k) | i <- [2 .. 20], j <- [0 .. 20], k <- [0 .. 3]] where\n\tf 2 0 k = k\n\tf 2 _ _ = 0\n\tf i j k = sum [dp!(i-1,j',k') | j' <- [max 0 (j - 1) .. j], k' <- if odd j then [k + 1 .. 3] else [0 .. k - 1]]\n\nmain = fmap (map read . words) getLine >>= putStrLn . show . gao where\n\tgao [n, t] = sum [dp!(n,t+t-1,k) | k <- [0 .. 3]]\n\n\n", "src_uid": "6d67559744583229455c5eafe68f7952"} {"source_code": "{-# LANGUAGE BangPatterns #-}\nmodule Main where\n\nimport Data.Maybe\nimport Control.Applicative\n\nimport qualified Data.ByteString as BS\nimport qualified Data.ByteString.Char8 as BS8\n\nreadInts = map (fst . fromJust . BS8.readInt) . BS8.words\n\ngetInts = readInts <$> BS.getLine\n\nsolve k2 k3 k5 k6 =\n max (256 * n256 + 32 * n32After256) (32 * n32 + 256 * n256After32)\n where\n n32 = minimum [k2, k3]\n n256 = minimum [k2, k5, k6]\n\n n32After256 = min n32 $ max 0 (k2 - n256)\n n256After32 = min n256 $ max 0 (k2 - n32)\n\nmain = do\n [!k2, !k3, !k5, !k6] <- getInts\n print $ solve k2 k3 k5 k6\n", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e"} {"source_code": "main = do\n s <- getLine\n let [n,k,l,c,d,p,nl,np] = map read $ words s\n print $ solve n k l c d p nl np\nsolve n k l c d p nl np = minimum [water k l nl, lime c d, salt p np] `div` n\nwater k l nl = k*l `div` nl\nlime c d = c*d\nsalt p np = p `div` np", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1"} {"source_code": "import Control.Applicative\nimport Data.List\n \t\n\t\t\t\n\n \n\n\nmain= do\n\tn<- read <$> getLine ::IO Integer\n\tk<- read <$> getLine ::IO Integer\n\tlet s= takeWhile (<=k) $ iterate (*n) n \n\tputStrLn $ if s/= [] && last s ==k then \"YES\\n\" ++ show (length s -1) else \"NO\"", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46"} {"source_code": "main=interact (++\" 0 0\")", "src_uid": "db46a6b0380df047aa34ea6a8f0f93c1"} {"source_code": "fi=fromIntegral\nf n=n*(n+1) `div` 2\nx n = (sqrt (1+8*(fi n))-1)/2\n\nfind a n\n\t|f a>n && ((odd (f a) && odd n) || ( even (f a) && even n ))= a\n\t|otherwise = find (a+1) n\n\nsolve n\n\t|nn == f a = a\n\t|otherwise = find a nn\n\twhere\n\t\tnn = abs n\n\t\ta = floor $ (x nn)\n\t\tb = f a\n\t\n\n \nmain=do\n\ta<-getLine\n\tputStrLn (show $ solve (read a::Int))", "src_uid": "18644c9df41b9960594fdca27f1d2fec"} {"source_code": "import Control.Applicative\nimport Data.List\n\nrepl 'q' = -9\nrepl 'r' = -5\nrepl 'b' = -3\nrepl 'n' = -3\nrepl 'p' = -1\nrepl 'Q' = 9\nrepl 'R' = 5\nrepl 'B' = 3\nrepl 'N' = 3\nrepl 'P' = 1\nrepl x = 0\n \n\nmain=do\t \n\ta<- getContents \n\tlet b = sum $ map repl a\n\tputStrLn $ if b>0 then \"White\" else if b==0 then \"Draw\" else \"Black\" ", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442"} {"source_code": "import Data.List\nimport Data.Char\n\nmain :: IO ()\nmain = getContents >>= solve\n\nsolve :: String -> IO ()\nsolve input = do\n let temp = dropWhile (/= '1') input \n if temp == [] \n then putStrLn \"no\"\n else if (length $ filter (== '0') temp ) >= 6 then putStrLn \"yes\"\n else putStrLn \"no\"\n", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca"} {"source_code": "solve :: Integer -> [Integer] -> Integer -> Integer\nsolve n [] t\n | n == 0 = t\n | otherwise = 10000000\nsolve n (x:xs) t =\n min a b \n where\n ps = toInteger (length (x:xs) :: Int)\n l = n `div` x\n h = (n + x - 1) `div` x\n a = solve (n - l * x) xs (t + ps * l)\n b = solve (h * x - n) xs (t + ps * h)\n\ngo :: Integer -> Integer\ngo n =\n let\n vals = reverse . take 16 $ iterate (\\x -> 10 * x + 1) 1\n in\n solve n vals 0\n\nmain = do\n n <- fmap read getLine\n putStrLn $ show $ go n\n", "src_uid": "1b17a7b3b41077843ee1d6e0607720d6"} {"source_code": "import Data.List\nmain = interact $ f . map read . words\nf [0,0] = \"infinity\"\nf [0,_] = \"0\"\nf [a,b]\n | a == b = \"infinity\"\n | a < b = \"0\"\n | otherwise = show . length . filter (>b) . foldl (\\xs ys -> [x*y | x <- xs, y <- ys]) [1] . map (scanl (*) 1) . group $ h 2 (a-b)\nh a b\n | mod b a == 0 = a:h a (div b a)\n | a*a <= b = h (a+1) b\n | b > 1 = [b]\n | otherwise = []", "src_uid": "6e0715f9239787e085b294139abb2475"} {"source_code": "f::String->String\nf \"\"=\"\"\nf ('.':xs)='0':f xs\nf ('-':'.':xs)='1':f xs\nf ('-':'-':xs)='2':f xs\n\nmain = do\n e<-getLine\n putStrLn $ f e", "src_uid": "46b5a1cd1bd2985f2752662b7dbb1869"} {"source_code": "fu n b| sum [1..n] < b = b - sum[1..n] | sum [1..n] == b = 0 | sum [1..n] > b = fu (n-1) b\nsolve [n,b] | sum [1..n] < b = solve [n,x] | sum [1..n] == b = 0 | sum [1..n] > b = fu n x\n where x = b `mod` sum [1..n]\nmain = interact $ show . solve . map read . words\n", "src_uid": "5dd5ee90606d37cae5926eb8b8d250bb"} {"source_code": "import Data.List\nmain = interact $ show.helper.(map read).words\n\nhelper (a:b:c:d:[]) = (f y x) + (f z y)\n where s = [a,b,c]\n [x,y,z] = sort s\n f k l = max (d - (k -l)) 0\n", "src_uid": "47c07e46517dbc937e2e779ec0d74eb3"} {"source_code": "import Control.Monad.State\nimport Data.Map as Map\nimport qualified Data.ByteString.Char8 as C\n\ntype S = Map (Int, Int, Int) Integer\n\n\nsmall :: [[Int]] -> Int -> Int -> Int -> State S Integer\nsmall _ 0 _ _ = return 0\nsmall cost n a c = do\n map <- get\n case Map.lookup (n,a,c) map of\n Just ret -> return ret\n Nothing -> do\n let b = 3-a-c\n mab <- small cost (n-1) a b \n mac <- small cost (n-1) a c\n mbc <- small cost (n-1) b c\n mca <- small cost (n-1) c a\n let costac = fromIntegral $ cost!!a!!c\n let costab = fromIntegral $ cost!!a!!b\n let costbc = fromIntegral $ cost!!b!!c\n \n let ret = min (mab+costac+mbc) (mac+costab+ mca+costbc+mac)\n modify (insert (n,a,c) ret)\n return ret\n\n \ngetInts :: IO [Int]\ngetInts = do\n line <- C.getLine\n return $ fmap read $ words $ C.unpack line\n\nmain = do \n cost <- sequence [getInts, getInts, getInts]\n n <- fmap read getLine :: IO Int\n let (ret, _) = runState (small cost n 0 2) Map.empty\n print ret\n\n\n", "src_uid": "c4c20228624365e39299d0a6e8fe7095"} {"source_code": "{- This code was written by\nRussell Emerine - linguist,\nmathematician, coder,\nmusician, and metalhead. -}\n\ndigsum 0 = 0\ndigsum n = (mod n 10) + (digsum $ div n 10)\n\ninteresting n = mod (digsum n) 4 == 0\n\ninspect n = if interesting n\n then print n\n else inspect $ n + 1\n\nmain = do\n line <- getLine\n inspect $ read $ line\n", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7"} {"source_code": "{-# LANGUAGE FlexibleContexts, ScopedTypeVariables, BangPatterns #-}\n{-# OPTIONS_GHC -O2 #-}\n\nimport Control.Applicative\nimport Control.Monad\nimport Control.Monad.ST.Safe\nimport Control.Monad.State\n-- import Data.Array\nimport Data.Array.IArray\nimport Data.Array.IO.Safe\nimport Data.Array.MArray.Safe\nimport Data.Array.ST.Safe\nimport Data.Array.Unboxed\nimport qualified Data.ByteString.Char8 as B\nimport qualified Data.ByteString.Lazy.Builder as BB\nimport Data.Char\nimport qualified Data.Foldable as F\nimport Data.Function\n-- import Data.Graph\nimport Data.Int\nimport Data.List\nimport Data.List.Split\nimport Data.Maybe\nimport Data.Monoid\nimport Data.Ratio\nimport qualified Data.Sequence as Seq\nimport Data.Sequence (Seq)\nimport Data.Set (Set)\nimport qualified Data.Set as Set\nimport Data.IntSet (IntSet)\nimport qualified Data.IntSet as IntSet\n-- import Data.Tree\nimport Data.Tuple\nimport Data.Map (Map)\nimport qualified Data.Map as Map\nimport Data.IntMap (IntMap)\nimport qualified Data.IntMap as IntMap\n-- import Debug.Trace\nimport System.IO\n\n-- getInts = fmap (map read . words) getLine\ngetInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine\n\nmain = do\n getLine\n s <- getLine\n\n let\n b = or $ map f $ tails s\n where\n f t = or $ map f' [1..length t]\n where\n f' k = isPrefixOf \"*****\" hs\n where\n hs = map head $ takeWhile (not . null) $ iterate (drop k) t\n\n putStrLn $ if b then \"yes\" else \"no\"\n", "src_uid": "12d451eb1b401a8f426287c4c6909e4b"} {"source_code": "isReverse :: String -> Bool\nisReverse s = s == (reverse s)\n\nsolve :: String -> String\nsolve s = maximum $ filter isReverse $ solve' s\n where\n solve' [] = []\n solve' (x:xs) = [x] : ((map ((:) x) res) ++ res)\n where\n res = solve' xs\n\nmain :: IO ()\nmain = getLine >>= putStrLn . solve", "src_uid": "9a40e9b122962a1f83b74ddee6246a40"} {"source_code": "import Control.Monad\nimport Data.Char\n\nispretty :: String -> Bool\nispretty \"0\" = True\nispretty (x:xs) | x == '0' = False\n | otherwise = read (x:xs) <= 1000000\n\nrun cs = do i <- [1..(length cs - 1)]\n let (sub1, subs) = splitAt i cs\n guard (ispretty sub1)\n j <- [1..(length subs - 1)]\n let (sub2, sub3) = splitAt j subs\n guard (ispretty sub2)\n guard (ispretty sub3)\n\n return $ sum [read s | s <- [sub1, sub2, sub3]]\n\nmain = do s <- getLine\n print $ maximum (-1:run s)", "src_uid": "bf4e72636bd1998ad3d034ad72e63097"} {"source_code": "import Data.List\nimport Data.Char\n\nmain = interact foo\n\nfoo :: String -> String\nfoo inp = \n let ss = (!! 1) . lines $ inp\n cs = filter (/= \"\") . myBreak isUpper $ ss\n in show $ maximum . (++[0]) . map (length . nub) $ cs\n \nmyBreak :: (a -> Bool) -> [a] -> [[a]]\nmyBreak _ [] = []\nmyBreak p ll = let (a, b) = break p ll\n in a : if null b then [] else myBreak p (tail b)", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3"} {"source_code": "import Data.List (sort)\nimport Control.Arrow (second)\nmain = putStrLn . unwords . map show . sort . solve . map read . words =<< getLine\nsolve [n,m] = map friends [ [(1,n-m+1),(m-1,1)]\n , [ (n `mod` m,(n+m-1) `div` m)\n , (m - n `mod` m,n `div` m) ] ]\nfriends = sum . map (uncurry (*) . second pairs)\npairs n = n * (n-1) `div` 2\n", "src_uid": "a081d400a5ce22899b91df38ba98eecc"} {"source_code": "import Data.List\nmain = interact $ show . foo . tail . map read . words\n\nfoo :: [Int] -> Int\nfoo x\n |(head x) == (maximum x) && not (elem (head x) (tail x)) = 0\n |otherwise = 1 + (foo $ (1 + head x) : (bar (maximum x) (tail x)))\n where\n bar a [] = []\n bar a as\n |a == head as = a - 1 : tail as\n |otherwise = (head as) : bar a (tail as)\n", "src_uid": "aa8fabf7c817dfd3d585b96a07bb7f58"} {"source_code": "main = do\n [n, k] <- fmap (fmap read . words) getLine\n putStrLn $ if [n `mod` i | i <- [1..k]] == [0..(k-1)] then \"Yes\" else \"No\"\n", "src_uid": "5271c707c9c72ef021a0baf762bf3eb2"} {"source_code": "import qualified Data.ByteString.Lazy.Char8 as BS\nimport Data.List\n\ntype Cup = (Integer, Integer)\n\nreadInt :: BS.ByteString -> Integer\nreadInt x = case BS.readInteger x of Just (i, _) -> i\n Nothing -> error \"Unparsable Int\"\n\ntoPref :: [Cup] -> [Cup]\ntoPref ((x, y):(a, b):xs) = (x, y):toPref((a+x, b+y):xs)\ntoPref xs = xs\n\nf :: Integer -> [Cup] -> [Cup] -> Integer\nf _ _ [] = 0\nf _ [] _ = 0\nf k (x:xs) (y:ys) | (snd x) + (snd y) > k = f k (x:xs) ys\n | otherwise = let now = (fst x) + (fst y)\n in max now $ f k xs (y:ys) \ncupCmp :: Cup -> Cup -> Ordering\ncupCmp (a, b) (x, y) | a > x = GT\n | x > a = LT\n | a == x = if y > b then GT else LT\n\nmain = do\n (l:ls) <- fmap BS.lines BS.getContents\n let (n:m:k:[]) = map readInt $ BS.split ' ' l\n (as, bs) = splitAt (fromIntegral n) $ take (fromIntegral (n+m)) ls\n xs = map ((\\[x, y] -> (x, y)) . map readInt . BS.split ' ') as\n ys = map ((\\[x, y] -> (x, y)) . map readInt . BS.split ' ') bs\n xs' = reverse $ sortBy cupCmp xs\n ys' = reverse $ sortBy cupCmp ys\n xs'' = toPref xs'\n ys'' = reverse $ toPref ys'\n in print $ f k xs'' ys''", "src_uid": "da573a39459087ed7c42f70bc1d0e8ff"} {"source_code": "{-# LANGUAGE NoMonomorphismRestriction #-}\nimport Control.Applicative ((<$>))\nimport Data.List\n\ncount :: Eq a => a -> [a] -> Int\ncount a b = length $ elemIndices a b\n\nsolve :: [Int] -> String\nsolve l@[a,b,c,d,e,f]\n | count a l >= 4 = if e == f then \"Elephant\" else \"Bear\"\n | count b l == 4 = \"Bear\"\n | count c l >= 4 = if a == b then \"Elephant\" else \"Bear\"\n | otherwise = \"Alien\"\n\nmain :: IO ()\nmain = do\n a <- sort <$> (map read <$> (words <$> getLine))\n putStrLn $ solve a\n", "src_uid": "43308fa25e8578fd9f25328e715d4dd6"} {"source_code": "import Data.Char\n\n-- Read a token from standard input\ngetToken :: IO String\ngetToken = do t <- go\n if t == \"\" then getToken else return t\n where go = do c <- getChar\n if isSpace c then return \"\" else\n go >>= (\\s -> return (c:s))\n\n-- Read an integer from standard input\ngetInteger :: IO Integer\ngetInteger = getToken >>= (\\t -> return (read t :: Integer))\n\n-- Repeat a monadic function n times\nrepeatM_ :: Monad m => Integer -> m a -> m ()\nrepeatM_ 0 f = return ()\nrepeatM_ n f = f >> repeatM_ (n - 1) f\n\n\ngasInterval a f = f:go (2 * f) (2 * (a - f))\n where go f1 f2 = f2:f1:go f1 f2\n\nstep gi b k c\n | k <= b = c\n | otherwise = let delta = go gi b 0\n where go gi@(g:gs) b d = let b' = b - g in\n if b' < 0 then (d, gi) else\n go gs b' (d + g)\n in\n if fst delta == 0 then -1 else\n step (snd delta) b (k - fst delta) (c + 1)\n\nmain = do\n a <- getInteger\n b <- getInteger\n f <- getInteger\n k <- getInteger\n print (step (gasInterval a f) b (a * k) 0)\n", "src_uid": "283aff24320c6518e8518d4b045e1eca"} {"source_code": "{-# LANGUAGE RankNTypes #-}\n{-# LANGUAGE TypeSynonymInstances #-}\n\nimport Control.Monad\n\nimport Data.IORef\nimport System.IO.Unsafe\n\nimport Data.List\nimport Data.Ord\nimport Data.Ratio\n\nimport Debug.Trace\n\nsolve = do n <- cin :: IO Integer\n m <- cin\n cs' <- replicateM m $ do \n ai <- cin\n bi <- cin\n return (ai,bi)\n let cs = reverse $ sortBy (comparing snd) cs'\n return . show $ f 0 cs n\n where\n f s [] _ = s\n f s _ 0 = s\n f s ((a,b):cs) capa = let n = min a capa\n in f (s+n*b) cs (capa-n)\n\nmain = putStrLn =<< solve\n\n\n\n\nclass Read' a where\n read' :: String -> a\n\ninstance Read' Integer where\n read' = read\n\ninstance Read' Int where\n read' = read\n\ninstance Read' Double where\n read' = read\n\ninstance Read' Char where\n read' (c:[]) = c\n read' cs = error $ cs ++ \" cannot read' as the type of Char.\"\n\ninstance Read' String where\n read' cs = cs\n\ncin :: forall a. Read' a => IO a\ncin = do (x:xs) <- readIORef input\n writeIORef input xs\n return $ read' x\n\ninput :: IORef [String]\ninput = unsafePerformIO $ getContents >>= newIORef . words\n\n\n\n\n", "src_uid": "c052d85e402691b05e494b5283d62679"} {"source_code": "import Data.Bits\n\nmain :: IO()\nmain = print . solve . read =<< getLine\n\nsolve :: Int -> Int\nsolve n = num\n where\n nums1 = map (\\x -> compose1 x 0 0) [1..9]\n nums2 = map (\\(x, y) -> compose2 x y 0 0 0) [(x, y) | x <- [0..8], y <- [(x+1)..9]]\n num = sum $ map (length . filter (<=n)) ([1000000000]:(nums1 ++ nums2))\n\ncompose1 :: Int -> Int -> Int -> [Int]\ncompose1 _ num 9 = [num]\ncompose1 x num i = case i of 0 -> longer\n _ -> num:longer\n where longer = compose1 x (num * 10 + x) (i + 1)\n\ncompose2 :: Int -> Int -> Int -> Int -> Int -> [Int]\ncompose2 _ _ num 9 3 = [num]\ncompose2 _ _ num 9 _ = []\ncompose2 x y num i s | num == 0 && x == 0 = compose2 x y y (i + 1) (s .|. 2)\n | otherwise = case s of 3 -> num:longer\n _ -> longer\n where longer = (compose2 x y (num * 10 + x) (i + 1) (s .|. 1)) ++ \n (compose2 x y (num * 10 + y) (i + 1) (s .|. 2))\n", "src_uid": "0f7f10557602c8c2f2eb80762709ffc4"} {"source_code": "import Data.Char\n\nmain = interact $ unlines . map (\\s -> if foldl(\\acc c -> if isUpper c then acc else False) True $ tail s then map (\\c -> if isUpper c then toLower c else toUpper c) s else s) . lines", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf"} {"source_code": "{-# LANGUAGE BangPatterns #-}\n{-# LANGUAGE BinaryLiterals #-}\n{-# LANGUAGE MultiWayIf #-}\n{-# LANGUAGE NumDecimals #-}\n{-# LANGUAGE ScopedTypeVariables #-}\n{-# LANGUAGE TupleSections #-}\n\nimport Control.Applicative\nimport Control.Arrow\nimport Control.Monad\nimport Control.Monad.ST\n\nimport Data.Char\nimport Data.List\nimport Data.Maybe\n\nimport qualified Data.ByteString.Char8 as B\n\nimport Data.Array.ST.Safe\nimport Data.STRef\n\n-- import Debug.Trace\nimport Text.Printf\n\nreadInt = readLn :: IO Int\nreadInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine\nreadNInts = readInt >>= flip replicateM readInt\n\nwhich a b f = if f then a else b\nmp [ a, b ] = ( a, b )\n\nmain = do\n\t( n : poss ) <- readInts\n\tlet\n\t\t[ a, x, b, y ] = map pred poss\n\tputStrLn $ which \"YES\" \"NO\" $ solve n a x b y\n\nsolve n a x b y\n\t| a == b = True\n\t| a == x = False\n\t| b == y = False\n\t| otherwise = solve n a' x b' y\n\twhere\n\t\ta' = succ a `mod` n\n\t\tb' = ( pred b + n ) `mod` n", "src_uid": "5b889751f82c9f32f223cdee0c0095e4"} {"source_code": "import Data.List (intercalate)\nimport Data.Functor ((<$>))\n\nsolve' :: Int -> Int -> Maybe [Int]\nsolve' a b | a == b = Just [a]\n | a > b = Nothing\n | even b = (b:) <$> solve' a (b `div` 2)\n | b `mod` 10 == 1 = (b:) <$> solve' a (b `div` 10)\n | otherwise = Nothing\n\nsolve :: Int -> Int -> Maybe [Int]\nsolve a b = reverse <$> solve' a b\n\nmain :: IO()\nmain = do\n line <- getLine\n let x = map read . words $ line :: [Int]\n case solve (x !! 0) (x !! 1) of\n Just y -> do\n putStrLn \"YES\"\n putStrLn $ show . length $ y\n putStrLn $ intercalate \" \" (map show y)\n Nothing -> putStrLn \"NO\"\n", "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3"} {"source_code": "process :: [Int] -> Int\nprocess xs = maximum xs - minimum xs\n\nreadInt :: String -> Int\nreadInt = read\n\nmain = do\n xs <- fmap (map readInt.words) getLine\n print $ process xs", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319"} {"source_code": "import Control.Applicative( (<$>))\n\nmain = do\n let\n\treadLine = map read . words <$> getLine\n [n_, m_, k_] <- readLine\n as <- readLine\n let\n\t(pre,rightSide) = splitAt m_ as\n\n\tleftSide = tail . reverse $ pre\n\n\tzip' [] [] = []\n\tzip' [] (e:es) = let\n\t\t\t mb = if 0 search k (d+10) pairs\n\t _\t\t\t-> d\n\n print $ search k_ 10 $ zip' leftSide rightSide\n", "src_uid": "57860e9a5342a29257ce506063d37624"} {"source_code": "import Data.List\nimport Data.Function\nimport Data.Char\nimport Data.Maybe\nimport qualified Data.ByteString.Lazy.Char8 as B\n\ngetIntArray :: B.ByteString -> [Int]\ngetIntArray = map fst . mapMaybe B.readInt . B.words\n\nmain = interact $ unlines . map (unwords . map show) . getAns . map read . words\n\ngetAns :: [Integer] -> [[Integer]]\ngetAns (n:a:b:_) = if a * b >= n * 6 then [[a * b], [a, b]]\n\t\t\t\t\telse findAns a b n\n\nfindAns a b n \n\t| a <= b = findMax [a .. (ceiling . sqrt . fromInteger . (*6)) n] b n\n\t| otherwise = let (x:(newa:newb:_):_) = findAns b a n\n\t\t\t\t\tin [x, [newb, newa]]\n\n\nfindMax :: [Integer] -> Integer -> Integer -> [[Integer]]\nfindMax [] b n = [[n * 10], []]\nfindMax (x:xs) b n = let newb = ceiling ((fromInteger (n * 6)) / (fromInteger x));\n\t\t\t\t\t\t area = newb * x;\n\t\t\t\t\t\t pans = findMax xs b n\n\t\t\t\t\t in if (newb >= b && area < (head . head) pans) then [[area], [x, newb]] else pans\n", "src_uid": "6a2a584d36008151d18e5080aea5029c"} {"source_code": "import Control.Monad\nimport qualified Data.List as L\n\nmain :: IO ()\nmain = do\n [n,m,k] <- getLine >>= return . map read . words\n l <- getLine >>= return . map read . words\n putStrLn . show $ solve n m k l\n\nsolve :: Int -> Int -> Int -> [Int] -> Int\nsolve n m k l = judge . L.foldl' f (k,0) . L.reverse . L.sort $ l\n where \n judge (x,i) = if x < m then -1 else i\n f (k,i) x = if k < m then (k+x-1,i+1) else (k,i)\n", "src_uid": "b32ab27503ee3c4196d6f0d0f133d13c"} {"source_code": "{-# OPTIONS_GHC -O2 -XNoMonomorphismRestriction #-}\n{-# LANGUAGE BangPatterns #-}\n{-(c) gorlum0 [at] gmail.com-}\nimport qualified Data.ByteString.Char8 as BS\nimport Data.List\nimport Data.Array\nimport Debug.Trace (trace)\nimport Data.Maybe (fromJust)\nimport Text.Printf (printf)\n\nreadNum = fst . fromJust . BS.readInt\n--- debug = flip trace\ndebug x = trace (show x) x\ndebug2 msg x = trace (printf \"%s: %s\" msg $ show x) x\n\nsplitEvery _ [] = []\nsplitEvery n xs = ys : splitEvery n xs'\n where (ys, xs') = splitAt n xs\n\nsolve ([n,m,c0,d0]:xss) = maximum [dp!(k,m) + (n-k)`div`c0 * d0| k <- [0..n]]\n where\n yss = transpose xss\n bnds1 = (1,m)\n [a, b, c, d] = map (array bnds1 . zip [1..]) yss\n\n bnds2 = ((0,0), (n,m))\n dp = array bnds2 [(ij, f ij) | ij <- range bnds2]\n\n f (_,0) = 0\n f (i,j) = maximum [dp!(i-(c!j)*k, j-1) + (d!j)*k |\n k <- [0..(a!j)`div`(b!j)], i-(c!j)*k >= 0]\n\nbody [] = []\nbody xs@(n:m:_) = solve yss : body xs'\n where\n (ys, xs') = splitAt ((m+1)*4) xs\n yss = splitEvery 4 ys\n\nmain = do\n ws <- BS.words `fmap` BS.getContents\n let xs = map readNum ws\n mapM_ print $ body xs\n", "src_uid": "4e166b8b44427b1227e0f811161d3a6f"} {"source_code": "import Data.List\n \naddLists :: [Int] -> [Int] -> [Int]\naddLists a b = map (\\(x, y) -> x + y) $ zip a b\n\ngetBest :: [(Int, Int)] -> Int -> Int\ngetBest [] _ = 400000000\ngetBest ((a, b) : tail) sz = if sz > a then min b $ getBest tail sz else getBest tail sz\n\nsolve :: [Int] -> [Int] -> [(Int, Int)] -> [Int]\nsolve [] [] [] = []\nsolve (a : tailA) (b : tailB) c = (getBest c a) : solve tailA tailB ((a, b) : c)\nsolve _ _ _ = []\n\nmain = do\n s <- getLine\n let [x, y] = map (read :: String -> Int) $ words s\n putStrLn $ if or [(x == y), and [x == 2, y == 4], and [x == 4, y == 2]]\n then \"=\"\n else if fromIntegral y * logBase 2 (fromIntegral x) < fromIntegral x * logBase 2 (fromIntegral y)\n then \"<\"\n else \">\"\n ", "src_uid": "ec1e44ff41941f0e6436831b5ae543c6"} {"source_code": "import Control.Applicative\nimport Control.Monad\nimport Data.List\n\n\n\n\nmain = do\n\t\tn<- map read <$> words <$> getLine::IO [Int]\n\t\tlet s = sum n\n\t\tlet m1 = maximum n \n\t\tlet m2 = (minimum n)\n\t\tlet m =m1+m2\n\t\tputStrLn $ if m+m==s then \"YES\" else if m1+m1==s then \"YES\" else \"NO\"\n", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37"} {"source_code": "import Data.List\nimport Data.Function\nimport Data.Char\nimport Data.Maybe\nimport qualified Data.ByteString.Lazy.Char8 as B\n\ngetIntArray :: B.ByteString -> [Integer]\ngetIntArray = map fst . mapMaybe B.readInteger . B.words\n\nmain = B.interact $ B.unlines . map (B.unwords . map (B.pack . show)) . getAns . getIntArray\n\ndigitSum :: Integer -> Integer\ndigitSum x \n\t| x == 0 = 0\n\t| x > 0 = (digitSum (x `div` 10)) + x `mod` 10\n\t| otherwise = digitSum $ negate x\n\ngetAns :: [Integer] -> [[Integer]]\ngetAns (a:b:c:_) = let tans = filter (\\(a, b) -> a == digitSum b && b >= 1 && b <= 1000000000) $ map (\\x -> (x, x^a * b + c)) [1..81]\n\t\t\t\t\tin [[fromIntegral $ length tans], map snd tans]\n", "src_uid": "e477185b94f93006d7ae84c8f0817009"} {"source_code": "{-# OPTIONS_GHC -O2 #-}\n{-# LANGUAGE BangPatterns #-}\n{-# LANGUAGE CPP #-}\n{-# LANGUAGE LambdaCase #-}\n{-# LANGUAGE MultiWayIf #-}\n{-# LANGUAGE TupleSections #-}\n{-# LANGUAGE ViewPatterns #-}\n#ifndef DEBUG\n{-# LANGUAGE Safe #-}\n#endif\n\nimport Control.Applicative\nimport Control.Exception\nimport Control.Monad\nimport Control.Monad.State.Strict\nimport qualified Data.Array as A\nimport qualified Data.Array.Unboxed as UA\nimport qualified Data.Array.ST.Safe as MA\nimport Data.Bool\nimport qualified Data.ByteString.Builder as B\nimport qualified Data.ByteString.Char8 as C\nimport Data.Char\nimport Data.Function\nimport qualified Data.IntMap.Strict as IM\nimport qualified Data.IntSet as IS\nimport qualified Data.List as L\nimport qualified Data.List.NonEmpty as NL\nimport Data.Monoid\nimport qualified Data.Map.Strict as M\nimport Data.Monoid\nimport Data.Ord\nimport Data.Ratio\nimport Data.Semigroup\nimport qualified Data.Set as S\nimport Data.Tuple\nimport Foreign\nimport qualified System.IO as IO\n#ifdef DEBUG\nimport Debug.Trace\n#endif\n\n#define MOD 1000000007\n\nmain :: IO ()\nmain = do\n [n, m] <- map read.words <$> getLine\n print $ solve n m\n\nsolve :: Int -> Int -> IntMod\nsolve n m | m < n = solve m n\nsolve 1 1 = 2\nsolve n m = resM * 2 - 2 + resN * 2\n where\n !resN = last . take n $ go 1 2\n !resM = last . take m $ go 1 2\n go !x !y = x : go y z\n where\n !z = x + y\n-------------------------------------------------------------------------------\n-- Data.IntMod.Safe\n-------------------------------------------------------------------------------\n\nmodulus :: (Num a) => a\nmodulus = MOD\n{-# INLINE modulus #-}\n\ninfixr 8 ^%\ninfixl 7 *%, /%\ninfixl 6 +%, -%\n\n(+%) :: Int64 -> Int64 -> Int64\nx +% y = case x + y of\n r | r < MOD -> r\n | otherwise -> r - MOD\n{-# INLINE (+%) #-}\n\n(-%) :: Int64 -> Int64 -> Int64\nx -% y = case x - y of\n r | r < 0 -> r + MOD\n | otherwise -> r\n{-# INLINE (-%) #-}\n\n(*%) :: Int64 -> Int64 -> Int64\nx *% y = x * y `rem` MOD\n{-# INLINE (*%) #-}\n\n-- |\n-- >>> 1 /% 0\n-- 0\n(/%) :: Int64 -> Int64 -> Int64\nx /% y = go y MOD 1 0\n where\n go !a !b !u !v\n | b > 0 = case a `quot` b of\n q -> go b (a - q * b) v (u - q * v)\n | otherwise = x * (u + MOD) `rem` MOD\n{-# INLINE (/%) #-}\n\n(^%) :: Int64 -> Int -> Int64\nx ^% n\n | n > 0 = go 1 x n\n | n == 0 = 1\n | otherwise = go 1 (1 /% x) (-n)\n where\n go !acc !y !m\n | m .&. 1 == 0 = go acc (y *% y) (unsafeShiftR m 1)\n | m == 1 = acc *% y\n | otherwise = go (acc *% y) (y *% y) (unsafeShiftR (m - 1) 1)\n\nnewtype IntMod = IntMod{getIntMod :: Int64} deriving (Eq, Ord)\n\nintMod :: (Integral a) => a -> IntMod\nintMod x = fromIntegral $ mod (fromIntegral x) MOD\n{-# INLINE intMod #-}\n\nintModValidate :: IntMod -> Bool\nintModValidate (IntMod x) = 0 <= x && x < MOD\n{-# INLINE intModValidate #-}\n\ninstance Show IntMod where\n show (IntMod x) = show x\n\ninstance Bounded IntMod where\n minBound = IntMod 0\n maxBound = IntMod $ MOD - 1\n\ninstance Enum IntMod where\n toEnum = intMod\n fromEnum = fromIntegral\n\ninstance Real IntMod where\n toRational (IntMod x) = toRational x\n\ninstance Integral IntMod where\n quotRem x y = (x / y, x - x / y * y)\n toInteger (IntMod x) = toInteger x\n\ninstance Num IntMod where\n (IntMod x) + (IntMod y) = IntMod (x +% y)\n (IntMod x) - (IntMod y) = IntMod (x -% y)\n (IntMod x) * (IntMod y) = IntMod (x *% y)\n abs = id\n signum = const (IntMod 1)\n fromInteger x = IntMod . fromInteger $ mod x modulus\n\ninstance Fractional IntMod where\n (IntMod x) / (IntMod y) = IntMod (x /% y)\n fromRational q = fromInteger (numerator q) / fromInteger (denominator q)\n", "src_uid": "0f1ab296cbe0952faa904f2bebe0567b"} {"source_code": "main = interact $ show . solve . map read . words\n\nsolve :: [Integer] -> Integer\nsolve [n,m]\n | m >= n = n\n | otherwise = (bsrch 0 n) + m\n where bsrch l r\n | l + 1 >= r = r\n | now > 0 && now - m > 0 = bsrch mid r\n | otherwise = bsrch l mid\n where mid = (l + r) `div` 2\n now = n - mid * (mid + 1) `div` 2\n\nstupid [n,m] = stupid_ 0 n\n where stupid_ d c\n | c - d <= 0 = d\n | otherwise = stupid_ (d + 1) (min n $ c - d + m)\n", "src_uid": "3b585ea852ffc41034ef6804b6aebbd8"} {"source_code": "main =do\n e<-getLine\n let (a:b:[])=map read (words e)::[Integer]\n print $ if a==b then a else 1", "src_uid": "9c5b6d8a20414d160069010b2965b896"} {"source_code": "import Control.Monad\n\nmain = interact program\n\nprogram :: String -> String\nprogram input =\n let cs:ns:_ = lines input\n _:k:_ = map read $ words cs :: [Int]\n numbers = map read $ words ns :: [Int]\n result = solve (k - 1) numbers\n in show result\n\nsolve :: Int -> [Int] -> Int\nsolve k ns = \n let h = ns !! k\n filtered = takeWhile (\\n -> (n >= h) && (n /= 0)) ns \n in length filtered", "src_uid": "193ec1226ffe07522caf63e84a7d007f"} {"source_code": "main = getLine >>= print . solve . read\n\nsolve :: Integer -> Integer\nsolve n = (n - 3) * 9 * 4 ^ (n - 3) + 6 * 4 ^ (n - 2)\n", "src_uid": "3b02cbb38d0b4ddc1a6467f7647d53a9"} {"source_code": "-- Packages installed: split text hashtables vector\n-- vector-algorithms parsec bytestring unordered-containers\n-- hashable scientific random async stm aeson\n-- Run using: runghc file.hs\nimport Control.Applicative\n\nmain = do\n x <- getLine\n inp <- fmap (map read . words) getLine\n putStrLn $ if solve inp then \"YES\" else \"NO\"\n\ncorrectSeq = f <$> [[LT], []] <*> [[EQ], []] <*> [[], [GT]] \n where\n f x y z = x ++ y ++ z\n \nsolve :: [Int] -> Bool\nsolve inp = norm `elem` correctSeq\n where\n norm = compress Nothing norm'\n compress m [] = maybe [] (:[]) m\n compress Nothing (x:xs) = compress (Just x) xs\n compress (Just x) (a:as) | x == a = compress (Just a) as\n | otherwise = x:compress (Just a) as\n norm' = zipWith compare inp (tail inp)\n", "src_uid": "5482ed8ad02ac32d28c3888299bf3658"} {"source_code": "import Control.Monad\nimport Control.Applicative\n\n\n\nf n\n | n <= 2 = 1\n | otherwise = f (n - (f (n-1))) + (f (n - (f (n-2))))\n\n\na n = n - (floor $ (fromIntegral n + 1)/3)\n\nmain = do\n n <- readLn :: IO Int\n print $ a n\n", "src_uid": "a993069e35b35ae158d35d6fe166aaef"} {"source_code": "module Main (main)\n where\n\nimport Data.List (group, sort)\n\n\nmain :: IO ()\nmain = putStrLn . chat . isGirl =<< getLine\n where isGirl = (0==) . (`mod` 2) . length . group . sort\n chat True = \"CHAT WITH HER!\"\n chat False = \"IGNORE HIM!\"", "src_uid": "a8c14667b94b40da087501fd4bdd7818"} {"source_code": "import Prelude\nimport Data.List\nimport Data.Maybe\nimport Data.Function\nimport Data.Char\nimport Data.Graph\nimport Data.Tree\nimport Data.Int\nimport Data.Bits\nimport qualified Data.Set as Set\nimport qualified Data.ByteString.Lazy.Char8 as B\n\nreadInts :: IO String -> IO [Int]\nreadInts = fmap (map (foldl' (\\x y -> 10*x + digitToInt y) 0) . words)\n\nreadInts64 :: IO String -> IO [Int64]\nreadInts64 = fmap (map (foldl' (\\x y -> 10*x + (fromInteger . toInteger . digitToInt $ y)) 0) . words)\n\nstringFromList :: Show a => [a] -> String\nstringFromList = unwords . map show \n\nmain :: IO()\nmain = do\n input1 <- getLine\n n:_ <- readInts getLine\n str <- fmap words getContents\n let p1 = input1!!0\n p2 = input1!!1\n (a,b,c) = foldl' (\\(x1,x2,x3) (f:l:_) ->\n let y1 = if f==p1 && p2==l then 1 else 0\n y2 = if f==p2 then 1 else 0\n y3 = if l==p1 then 1 else 0\n in (x1+y1,x2+y2,x3+y3) ) (0,0,0) str\n if a>0 || (b>0&&c>0)\n then putStr \"YES\"\n else putStr \"NO\"\n", "src_uid": "cad8283914da16bc41680857bd20fe9f"} {"source_code": "{-# LANGUAGE ScopedTypeVariables #-}\n{-# LANGUAGE BangPatterns #-}\n{-# LANGUAGE Safe #-}\n{-# LANGUAGE TupleSections #-}\n{-# LANGUAGE ExplicitForAll #-}\n{-# LANGUAGE MultiWayIf #-}\n{-# LANGUAGE CPP #-}\n{-# LANGUAGE FlexibleContexts #-}\n{-# LANGUAGE NoMonomorphismRestriction #-}\n\nimport Data.Bits\nimport Data.List\nimport qualified Data.ByteString.Char8 as BS\nimport qualified Data.ByteString.Lazy.Char8 as BSL\nimport Data.IntMap.Strict (IntMap)\nimport qualified Data.IntMap.Strict as IM\nimport Data.IntSet (IntSet)\nimport qualified Data.IntSet as IS\nimport qualified Data.Array.IArray as A\nimport qualified Data.Array.MArray.Safe as A\n-- import qualified Data.Array.MArray as A\nimport Data.Array (Array)\nimport Data.Array.Unboxed (UArray)\nimport Data.Array.IArray (IArray)\nimport Data.Array.MArray.Safe (MArray)\nimport Data.Array.IO.Safe (IOArray, IOUArray)\nimport Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)\n{-\nimport qualified Data.Vector.Unboxed as VU\nimport qualified Data.Vector.Unboxed.Mutable as VUM\n-}\nimport Control.Monad\nimport Control.Monad.ST\nimport Control.Monad.ST.Lazy (strictToLazyST, lazyToStrictST)\nimport qualified Control.Monad.ST.Lazy as STL\nimport Control.Applicative\nimport Data.Maybe\nimport Data.Tuple\nimport Data.Ord\nimport Control.Monad.State.Strict\nimport Data.Int\nimport Data.Word\nimport Data.STRef\nimport Data.IORef\nimport Data.Function\nimport System.IO\nimport System.Exit\nimport Data.Char\n\nmain :: IO ()\nmain = do\n [a,b] <- map readInt . words <$> getLine\n putStrLn $ unwords $ map show\n $ if | a == b -> [a*10,a*10+1]\n | a+1 == b -> [a*10+9,b*10]\n | a == 9 && b == 1 -> [9,10]\n | otherwise -> [-1]\n return ()\n\n#define IL(f) {-# INLINE f #-}; f\n\nrInt :: StateT BSL.ByteString Maybe Int\nIL(rInt) = StateT $ BSL.readInt . BSL.dropWhile (<'!')\nrIntS :: StateT BS.ByteString Maybe Int\nIL(rIntS) = StateT $ BS.readInt . BS.dropWhile (<'!')\n\n-- unlessM, whenM :: (Monad m) => m Bool -> m () -> m ()\nIL(whenM) = (. flip when) . (>>=)\nIL(unlessM) = (. flip unless) . (>>=)\n\nIL(wrA) = A.writeArray\nIL(rdA) = A.readArray\nIL(mdA) = \\arr f !i -> do\n ai <- rdA arr i\n let fai = f ai \n wrA arr i fai\n return (ai,fai)\n{-# INLINE mdA' #-}\nmdA' = \\arr f !i -> do\n !ai <- rdA arr i\n let !fai = f ai\n wrA arr i fai\n return (ai,fai)\nIL(swapA) = \\arr !i !j -> do\n ai <- rdA arr i\n wrA arr i =<< rdA arr j\n wrA arr j ai\n\n#define D(f,r,d)\\\n IL(f) :: Integral a=>a->d; f=fromIntegral;\\\n IL(r) :: String->d; r=read\n#define C(f,r,g,h,d) D(f,r,d);\\\n g,h :: RealFrac a=>a->d; IL(g)=floor; IL(h)=ceiling\nC(_toInteger_,readInteger,floorInteger,ceilInteger,Integer)\nC(toInt,readInt,floorInt,ceilInt,Int)\nC(toI8,readI8,floorI8,ceilI8,Int8)\nC(toI16,readI16,floorI16,ceilI16,Int16)\nC(toI32,readI32,floorI32,ceilI32,Int32)\nC(toI64,readI64,floorI64,ceilI64,Int64)\nC(toWord,readWord,floorWord,ceilWord,Word)\nC(toW8,readW8,floorW8,ceilW8,Word8)\nC(toW16,readW16,floorW16,ceilW16,Word16)\nC(toW32,readW32,floorW32,ceilW32,Word32)\nC(toW64,readW64,floorW64,ceilW64,Word64)\nD(toDouble,readDouble,Double)\nD(toFloat,readFloat,Float)\n#undef D\n#undef C\n\n#define N(f,g,h,a,m)\\\n IL(f) :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> e -> m (a i e);\\\n f=A.newArray;\\\n IL(g) :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> m (a i e);\\\n g=A.newArray_;\\\n IL(h) :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> [e] -> m (a i e);\\\n h=A.newListArray\n#define C(a,m)\nN(newIOA,newIOA_,newIOAL,IOArray,IO)\nN(newSTA,newSTA_,newSTAL,STArray s,ST s)\n#undef C\n#define C(a,m) MArray (a) e (m), \nN(newIOUA,newIOUA_,newIOUAL,IOUArray,IO)\nN(newSTUA,newSTUA_,newSTUAL,STUArray s,ST s)\n#undef C\n#undef N\n\n#undef IL\n", "src_uid": "3eff6f044c028146bea5f0dfd2870d23"} {"source_code": "import Data.List\n\ntype Answer = (Int, Int)\n\nfindNumbers :: [Int] -> Answer\nfindNumbers divisors = getNumbers $ reverse $ sort divisors\n\ngetNumbers :: [Int] -> Answer\ngetNumbers [] = (0, 0)\ngetNumbers (x:y:rest) = if x == y\n then (x, y)\n else findAnother (x:y:rest) x\n\nfindAnother :: [Int] -> Int -> Answer\nfindAnother divisors x = (last rest, x)\n where xDivisors = removeDuplicates (filter (\\y -> x `mod` y == 0) divisors)\n rest = sort (divisors \\\\ xDivisors)\n\nremoveDuplicates :: [Int] -> [Int]\nremoveDuplicates list = removeDuplicates' list []\n\nremoveDuplicates' :: [Int] -> [Int] -> [Int]\nremoveDuplicates' [] result = result\nremoveDuplicates' (first:rest) result = if elem first result\n then removeDuplicates' rest result\n else removeDuplicates' rest (first:result)\n\nmain :: IO ()\nmain = do\n _ <- getLine\n list <- getLine\n let divisors = map read (words list)\n let (x, y) = findNumbers divisors\n putStr ((show x) ++ \" \" ++ (show y))", "src_uid": "868407df0a93085057d06367aecaf9be"} {"source_code": "main = print . solve =<< getLine\nsolve \"\" = 0 -- seriously?\nsolve \"0\" = 0\nsolve ('1' : ns) = (length ns + 1 + if any (== '1') ns then 1 else 0) `div` 2\n\n", "src_uid": "d8ca1c83b431466eff6054d3b422ab47"} {"source_code": "{-# LANGUAGE BangPatterns #-}\n{-# LANGUAGE BinaryLiterals #-}\n{-# LANGUAGE MultiWayIf #-}\n{-# LANGUAGE NumDecimals #-}\n{-# LANGUAGE ScopedTypeVariables #-}\n{-# LANGUAGE TupleSections #-}\n\nimport Control.Applicative\nimport Control.Arrow\nimport Control.Monad\nimport Control.Monad.ST\n\nimport Data.Char\nimport Data.List\nimport Data.Maybe\n\nimport qualified Data.ByteString.Char8 as B\n\nimport Data.Array.ST.Safe\nimport Data.STRef\n\n-- import Debug.Trace\nimport Text.Printf\n\nreadInt = readLn :: IO Int\nreadInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine\nreadNInts = readInt >>= flip replicateM readInt\n\nwhich a b f = if f then a else b\nmp [ a, b ] = ( a, b )\n\nmain = do\n\tn <- readInt\n\ts <- getLine\n\tlet\n\t\tzeros = length $ filter ( == '0' ) s\n\t\tones = n - zeros\n\tif zeros == ones\n\t\tthen do\n\t\t\tprint 2\n\t\t\tputStrLn $ unwords $ [ [ head s ], tail s ]\n\t\telse do\n\t\t\tprint 1\n\t\t\tputStrLn s", "src_uid": "4ebed264d40a449602a26ceef2e849d1"} {"source_code": "import Text.ParserCombinators.Parsec\nimport Control.Applicative hiding (optional, (<|>))\n\nmain = do\n jID <- return . (parse jabberID \"\") =<< getLine\n case jID of\n\tLeft _\t -> putStr \"NO\"\n\tRight id -> putStr \"YES\"\n\njabberID = do\n username\n char '@'\n hostname\n optional $ char '/' >> resource\n eof\n\nusername = do\n str <- many1 unchar\n if length str <= 16\n then return ()\n else fail \"USER NAME\"\n\nunchar = letter <|> digit <|> char '_'\n\nhostname = do\n ws <- wordpart `sepBy1` char '.'\n let l =\t\t\t (+)\n\t <$> sum . (length <$>) <*> subtract 1 . length\n\t $\t\t\t ws\n if l <= 32\n then return ()\n else fail \"HOST NAME\"\n\nwordpart = do\n word <- many1 unchar\n if length word <= 16\n then return word\n else fail \"Word Part\"\n\nresource = do\n str <- many1 unchar\n if length str <= 16\n then return ()\n else fail \"RESOURCE\"\n", "src_uid": "2a68157e327f92415067f127feb31e24"} {"source_code": "import Char\n\ngetP = do\n\t[x, y] <- getLine\n\treturn (ord x - 96, digitToInt y)\nmain = do\n\t(a, b) <- getP\n\t(c, d) <- getP\n\tputStrLn $ show $ sum [1 | i <- [1 .. 8], j <- [1 .. 8], i /= a, j /= b, i /= c || j /= d,\n\t\tand [z /= (a, b) && z /= (c, d) | x <- [-2 .. 2], y <- [-2 .. 2], abs x + abs y == 3, z <- [(i + x, j + y)]]]\n", "src_uid": "073023c6b72ce923df2afd6130719cfc"} {"source_code": "import Data.List\nmain = interact $ show. gao. head. words\ngao x = sum . map (cal. length) . group $ x\ncal x = x `div` 5 + if (x `mod` 5 == 0) then 0 else 1 \n\n", "src_uid": "5257f6b50f5a610a17c35a47b3a0da11"} {"source_code": "closestGreater :: Integer -> Integer -> Integer\nclosestGreater n m = if 2 ^ m > n then m\n\telse closestGreater n (m+1)\n\n\nmain :: IO ()\nmain = do\n nos_temp <- getLine\n let nos = map (\\x -> read x :: Integer) $ words nos_temp\n let n = nos!!0\n k = nos!!1\n print $ if k==1 then n\n \telse 2 ^ (closestGreater n 0) - 1\n ", "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9"} {"source_code": "main = interact $ f . map read . words\nf [w,m] | w <= 3 || (foldr g m . takeWhile ( x = abs $ x * w + 1 - x - m", "src_uid": "a74adcf0314692f8ac95f54d165d9582"} {"source_code": "{-# LANGUAGE ForeignFunctionInterface, ScopedTypeVariables #-}\n{-# LANGUAGE OverloadedStrings #-}\nimport Foreign\nimport Control.Applicative((<$>))\nimport Foreign.C.Types\nimport Foreign.C.String\nimport Foreign.Marshal.Alloc\nforeign import ccall \"stdio.h scanf\"\n scanf :: CString -> Ptr CInt -> IO ()\nforeign import ccall \"stdio.h puts\"\n c_puts :: CString -> IO ()\nscanInt :: IO Int\nscanInt = do alloca $ \\i -> do\n format <- newCString \"%d\"\n scanf format i\n free format\n fromEnum <$> peek i\nputs :: String -> IO ()\nputs str = do str' <- newCString str\n c_puts str'\n free str'\n\nmain = do n <- scanInt\n (puts.show) ((div n 2)*3)", "src_uid": "031e53952e76cff8fdc0988bb0d3239c"} {"source_code": "main :: IO ()\nmain =\n do\n s <- getLine\n n <- getLine\n putStrLn $ show $ (\\(x, y) -> x + y * 10) $ foldl (\\(acc1, acca) x -> if x == '1' then (acc1 + 1, acca) else (0, acca * 10 + acc1)) (0, 0) n\n\n\n", "src_uid": "a4b3da4cb9b6a7ed0a33a862e940cafa"} {"source_code": "main = interact $ show. (\\n->(3^n-6*(n`mod`2)+3)`div`4`mod`(10^9+7)). read\n", "src_uid": "77627cc366a22e38da412c3231ac91a8"} {"source_code": "import Data.Array\n\nmain = do\n strLength <- readIntegers\n string <- getLine\n let solution = solve string (strLength!!0) 1\n putStrLn $ solution\n\nsolve :: String -> Int -> Int -> String\nsolve string 0 _ = \"\"\n\nsolve string strlen removeLen = [head string] ++ (solve shortString newLength (removeLen+1))\n where shortString = drop removeLen string\n newLength = length shortString\n\n\nmatchAndDrop :: String -> Char -> String\nmatchAndDrop string character = dropWhile (== character) string\n\nreadIntegers :: IO [Int]\nreadIntegers = fmap (map read.words) getLine ", "src_uid": "08e8c0c37b223f6aae01d5609facdeaf"} {"source_code": "main = getContents >>= print . solve . map read . words\n\nsolve [n,1,a,b] = a * (n - 1)\nsolve [n,k,a,b] = result n 0\n where result 1 ans = ans\n result x ans\n | x < k = result 1 $ ans + a * (x - 1) \n | r > 0 = result (x - r) $ ans + a * r\n | otherwise = if a * (x - d) > b\n then result d $ ans + b\n else result d $ ans + a * (x - d)\n where (d,r) = divMod x k\n", "src_uid": "f838fae7c98bf51cfa0b9bd158650b10"} {"source_code": "module Main where\n\nimport Data.Array.Unboxed\nimport Data.List\nimport Control.Monad\nimport Data.Ix\n\nmain = do\n [n, m] <- liftM (map read . words) getLine\n board <- liftM (listArray ((1,1),(n,m)) . join) $ replicateM n getLine :: IO (UArray (Int,Int) Char)\n\n let res = length $\n filter (\\(r,c) ->\n any (\\pos -> board ! pos == 'P') $\n filter valid $\n [(r-1,c)\n ,(r+1,c)\n ,(r,c-1)\n ,(r,c+1)\n ]\n ) $\n filter (\\pos -> board ! pos == 'W')\n (range ((1,1),(n,m)))\n valid = inRange ((1,1),(n,m))\n\n putStrLn $ show res\n", "src_uid": "969b24ed98d916184821b2b2f8fd3aac"} {"source_code": "solve scale ws | z >= diff && (z - diff) `mod` 2 == 0 = xs2 ++ \"|\" ++ ys2\n | otherwise = \"Impossible\"\n where\n (ls, rs) = break (=='|') scale\n x = length ls\n y = length $ tail rs\n diff = abs(x - y)\n z = length ws\n xs = if x < y then ls ++ take diff ws else ls\n ys = if y < x then tail rs ++ take diff ws else tail rs\n ws2 = drop diff ws\n n = length ws2 `div` 2\n xs2 = if n > 0 then xs ++ take n ws2 else xs\n ys2 = if n > 0 then ys ++ drop n ws2 else ys\n\nmain = do\n scale <- getLine\n ws <- getLine\n putStrLn $ solve scale ws\n", "src_uid": "917f173b8523ddd38925238e5d2089b9"} {"source_code": "import Data.Char\nmain = do\n n <- readLn\n t <- fmap (map digitToInt) getLine\n let (a,b) = splitAt (n `div` 2) t\n putStrLn $ if all lucky t && sum a == sum b\n then \"YES\"\n else \"NO\"\nlucky 4 = True\nlucky 7 = True\nlucky _ = False\n", "src_uid": "435b6d48f99d90caab828049a2c9e2a7"} {"source_code": "disjoint :: Eq a => [a] -> [a] -> Integer\ndisjoint [] [] = 0\ndisjoint (x:xs) (y:ys) = if x /= y then 1 + disjoint xs ys else disjoint xs ys\n\nsolve :: String -> Bool\nsolve s = (l `mod` 2 == 1 && c == 0) || (1 <= c && c <= 2) where\n l = length s\n c = disjoint s $ reverse s\n\nmain = do\n s <- getLine\n if solve s then \n putStrLn \"YES\"\n else \n putStrLn \"NO\"", "src_uid": "fe74313abcf381f6c5b7b2057adaaa52"} {"source_code": "{-# OPTIONS_GHC -rtsopts -O2 #-}\n{-# LANGUAGE BangPatterns #-} \n{-# LANGUAGE NoMonomorphismRestriction #-}\n{-# LANGUAGE ScopedTypeVariables #-}\n{-# LANGUAGE MultiWayIf #-}\n\nimport Data.Array.ST\nimport Data.STRef\nimport Control.Monad.ST\nimport Control.Monad\nimport Control.Applicative\nimport qualified Data.List as L \nimport qualified Data.Set as S\nimport qualified Data.Map as M\nimport qualified Data.Function as F\nimport Debug.Trace\n\nimport qualified Numeric as N\n\nreadInt :: String -> Int\nreadInt ('-':s) = case N.readDec s of [(n, \"\")] -> -n\nreadInt s = case N.readDec s of [(n, \"\")] -> n\n\nreadFloat :: String -> Double\nreadFloat ('-':s) = case N.readFloat s of [(x, \"\")] -> -x\nreadFloat s = case N.readFloat s of [(x, \"\")] -> x\n\ngetInts :: IO [Int]\ngetInts = map readInt . words <$> getLine \n\n-- nie numerujemy od zera\nsolve :: Integer -> Integer\nsolve n = (solve' n 1 0)\nsolve' n l acc = \n if n >= ile l\n then solve' (n - ile l) (l + 1) (acc + (l * ile l))\n else n * l + acc \n\nile x = 9 * (10 ^ (x - 1))\n\nmain = do\n [n] <- getInts\n print (solve (toInteger n))\n", "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9"} {"source_code": "main = putStrLn \"25\"\n", "src_uid": "dcaff75492eafaf61d598779d6202c9d"} {"source_code": "import Control.Monad\nimport Data.Array\nimport Data.Bits\nimport Data.List\n\nmain = do\n [x0, y0] <- fmap (map read . words) getLine\n n <- fmap read getLine\n (x,y) <- fmap (unzip . map ((\\[xs,ys] -> (xs,ys)) . map read . words)) $ replicateM n getLine\n let d = array ((0,0), (n-1,n-1)) \n [((i,j), dist (x!!i) (y!!i) (x!!j) (y!!j)) | i <- [0..n-1], j <- [0..n-1]]\n dist xi yi xj yj = hypot2 xi yi x0 y0 + hypot2 xj yj x0 y0 - hypot2 xi yi xj yj\n hypot2 x1 y1 x2 y2 = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)\n mx :: Int\n mx = (1 `shift` n) - 1\n dp = array (0,mx) [(mask, f mask) | mask <- [0..mx]]\n \n getBits mask = filter (testBit mask) [0..n-1]\n \n f 0 = (0, -1, -1)\n f mask = case getBits mask of\n [b] -> (0, -1, -1)\n (b:bs) -> let\n cases = [(d!(b,i) + next, b, i) | i<-bs, let (next, _, _) = dp!(mask `clearBit` b `clearBit` i)]\n in maximum ((dp!(mask `clearBit` b)):cases)\n \n path = takeWhile (>=0) $ iterate step mx\n step mask = \n if i >= 0 \n then mask `clearBit` i `clearBit` j\n else -1\n where (_, i, j) = dp!mask\n \n (best, _, _) = dp!mx\n time = 2 * sum [hypot2 x1 y1 x0 y0 | (x1,y1) <- zip x y] - best\n \n res1 = concatMap segment . zipWith xor path $ tail path\n segment diff = [0, i+1, j+1]\n where [i,j] = getBits diff\n \n res2 = concatMap (:[0]) . map (+1) . getBits $ last path\n \n print time\n putStrLn . unwords . map show $ res1 ++ [0] ++ res2", "src_uid": "2ecbac20dc5f4060bc873553946281bc"} {"source_code": "import Data.Ratio\ntype LatticePos = (Int,Int)\ntype Triangle = (LatticePos, LatticePos, LatticePos)\nmain = do\n token <- return . words =<< getContents\n let x1:y1:x2:y2:x3:[y3] = read `map` take 6 token\n\ttriangle = (p1,p2,p3)\n\tp1 = (x1,y1)\n\tp2 = (x2,y2)\n\tp3 = (x3,y3)\n\tisRight t@(p1,p2,p3) = isTriangle t && any right [(p1,p2,p3), (p2,p3,p1), (p3,p1,p2)]\n\t where\n\t\tisTriangle (p1@(x1,y1),p2@(x2,y2),p3@(x3,y3)) =\n\t\t if p1/=p2 && p2/=p3 && p3/=p1\n\t\t\tthen if x3/=x1\n\t\t\t\tthen (fromIntegral y2)-(fromIntegral y1) /= (x2-x1)*((fromIntegral y3)-y1)%(x3-x1)\n\t\t\t\telse x1/=x2\n\t\t\telse False\n\t\tright ((x1,y1),(x2,y2),(x3,y3)) = \n\t\t (x1-x2)*(x3-x2) + (y1-y2)*(y3-y2) == 0\n if isRight triangle\n\tthen putStr \"RIGHT\"\n\telse if any isRight $ shifts triangle\n\t then putStr \"ALMOST\"\n\telse putStr \"NEITHER\"\n\twhere\n\t shifts t = concat [shift1x t, shift1y t, shift2x t, shift2y t, shift3x t, shift3y t]\n\nshift1x, shift2x, shift3x,\n shift1y, shift2y, shift3y::Triangle -> [Triangle]\nshift1x ((x,y),p2,p3) = (\\x'->return ((x',y),p2,p3)) =<< [x-1,x+1]\nshift1y ((x,y),p2,p3) = (\\y'->return ((x,y'),p2,p3)) =<< [y-1,y+1]\n\nshift2x (p1,(x,y),p3) = (\\x'->return (p1,(x',y),p3)) =<< [x-1,x+1]\nshift2y (p1,(x,y),p3) = (\\y'->return (p1,(x,y'),p3)) =<< [y-1,y+1]\n\nshift3x (p1,p2,(x,y)) = (\\x'->return (p1,p2,(x',y))) =<< [x-1,x+1]\nshift3y (p1,p2,(x,y)) = (\\y'->return (p1,p2,(x,y'))) =<< [y-1,y+1]\n", "src_uid": "8324fa542297c21bda1a4aed0bd45a2d"} {"source_code": "--prewritten code: https://github.com/antma/algo\n{-# LANGUAGE BangPatterns, Safe #-}\n{-# Options_GHC -O2 #-}\nimport Data.ByteString.Builder\nimport Data.Monoid\nimport System.IO\nimport qualified Data.ByteString.Char8 as C\nimport Data.Time (diffTimeToPicoseconds, utctDayTime, getCurrentTime)\nimport Data.Char\n\ngetSeed = return . fromInteger . (`mod` 999983) . diffTimeToPicoseconds . utctDayTime =<< getCurrentTime :: IO Int\n\nru, ri :: C.ByteString -> Int\n\nru = C.foldl' (\\a c -> a * 10 - 48 + ord c) 0\nri s\n | C.head s == '-' = negate $ ru $ C.tail s\n | otherwise = ru s\n\ndigprod :: Int -> Int\ndigprod n = product $ map ((subtract 48) . ord) $ show n\n\nsolve a = f n\n where\n !n = head a\n f 0 = 1\n f m\n | m < 10 = m\n | otherwise = max (digprod m) $ 9 * f (pred $ (div m 10))\n\nmain :: IO ()\nmain = print . solve . map ri . C.words =<< C.getContents\n", "src_uid": "38690bd32e7d0b314f701f138ce19dfb"} {"source_code": "months = [\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"]\n\n-- 13月以降の場合は来年として、1月からに戻す。\nnextYear x\n | x > 12 = if x `mod` 12 == 0 then 12 else x `mod` 12\n | otherwise = x\n\nsearch elem list = search' elem list 0\n where\n search' elem [] index = index\n search' elem (x:xs) index = if elem == x\n then index\n else search' elem xs (index + 1)\n\nmain = do current <- getLine\n appear <- getLine\n putStrLn $ months !! (nextYear ((search current months + 1) + read appear) - 1)\n", "src_uid": "a307b402b20554ce177a73db07170691"} {"source_code": "xmod::Integer->Integer\nxmod n = n `mod` (4*1000000007)\n\np3::Integer->Integer\np3 0 = 1\np3 n | n `mod` 2 == 0\n\t\t= let\n\t\tk = n `div` 2\n\t\tx = p3 k\n\t\tin xmod (x*x)\np3 n | n `mod` 2 == 1\n\t\t= let\n\t\tk = n `div` 2\n\t\tx = p3 k\n\t\tin xmod (3*x*x)\n\t\t\nfrb2::Integer->Integer\nfrb2 n | n `mod` 2 == 1 \n\t\t= let \n\t\tk = n `div` 2 \n\t\tin\n\t\t(p3 (k+1)) - 1\nfrb2 n | n `mod` 2 == 0\n\t\t= let \n\t\tk = n `div` 2 \n\t\tin\n\t\t2 * (p3 k - 1)\n\t\t\nfrb::Integer->Integer\nfrb 0 = 0\nfrb 1 = 2\nfrb n = (frb2 n) + (frb2 (n-1)) \n\nfbw::Integer->Integer\nfbw 0 = 0\nfbw n = 2 + 2*frb (n-1)\n\nfs::Integer->Integer\nfs 0 = 0\nfs 1 = 4\nfs 2 = 4\nfs n | n `mod` 2 == 1 \n\t\t= let \n\t\tk = n `div` 2 \n\t\tin\n\t\t2*(frb k) + 3*(fbw k) `div` 2 + 5\nfs n = fs (n-1)\n\nfall::Integer->Integer\nfall n = (frb n) + (fbw n)\n\nf::Integer->Integer\nf 0 = 0\nf 1 = 4\nf n = \tlet \n\t\ts = (fs n)\n\t\tall = (fall n)\n\t\tin \n\t\txmod (s + ((all - s) `div` 2))\n\t\t\nsolve::[Integer]->Integer\nsolve [l,r] = ((f r) - (f (l-1))) `mod` (1000000007)\n\nmain = interact $ show.solve.map read.words\n", "src_uid": "e04b6957d9c1659e9d2460410cb57f10"} {"source_code": "import Control.Applicative\nimport Control.Monad\n\nmain = sol <$> readLn >>= print\n\nsol n \n | m*m == n = 4*m \n | m*(m+1) >= n = 2*(2*m+1)\n | otherwise = 4*(m+1)\n where\n m = floor . sqrt $ fromIntegral n", "src_uid": "414cc57550e31d98c1a6a56be6722a12"} {"source_code": "{-# LANGUAGE BangPatterns #-}\n{-# LANGUAGE BinaryLiterals #-}\n{-# LANGUAGE MultiWayIf #-}\n{-# LANGUAGE NumDecimals #-}\n{-# LANGUAGE ScopedTypeVariables #-}\n{-# LANGUAGE TupleSections #-}\n\nimport Control.Applicative\nimport Control.Arrow\nimport Control.Monad\nimport Control.Monad.ST\n\nimport Data.Char\nimport Data.List\nimport Data.Maybe\n\nimport qualified Data.ByteString.Char8 as B\n\nimport Data.Array.ST.Safe\nimport Data.STRef\n\n-- import Debug.Trace\nimport Text.Printf\n\nreadInt = readLn :: IO Int\nreadInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine\nreadNInts = readInt >>= flip replicateM readInt\n\nwhich a b f = if f then a else b\nmp [ a, b ] = ( a, b )\n\nmain = do\n\t[ n, m ] <- readInts\n\tprint $ if\n\t\t| m <= 1 -> 1\n\t\t| m <= n `div` 2 -> m\n\t\t| otherwise -> n `div` 2 - ( m - n `div` 2 ) + n `mod` 2", "src_uid": "c05d0a9cabe04d8fb48c76d2ce033648"} {"source_code": "main = do\n [n_, k_] <- return . map (read::String->Integer) . words =<< getLine\n let bSearch n k = let v = k - 2^(n-1) \n\t\t\tin if v==0 then n\n\t\t\t else if 0 Integer -> Integer\npre _ 0 = 0\npre 0 _ = 0\npre n r\n | r <= len q = pre q r\n | r == len q + 1 = q + m \n | otherwise = q + m + pre q (r - len q - 1)\n where q = div n 2\n m = mod n 2\nmain = do\n n:l:r:[] <- getLine >>= return. map read. words :: IO [Integer]\n print $ pre n r - pre n (l - 1)\n \n", "src_uid": "3ac61b1f8deee7911b1055c243f5eb6a"} {"source_code": "\nmain = do\n _ <- getLine\n input <- getLine\n putStrLn (solve input)\n\nsolve :: String -> String\nsolve \"0\" = \"0\"\nsolve s = '1' : filter (=='0') s\n", "src_uid": "ac244791f8b648d672ed3de32ce0074d"} {"source_code": "solve :: Integer -> Integer -> Integer\nsolve m b = foldl max' 0 [0..b]\n where\n max' a h = max a $ div (let w = m*(b-h) in w*(w+1)*(h+1) + h*(h+1)*(w+1)) 2\n\nmain = do\n line <- getLine\n let m = read (head $ words line) :: Integer\n let b = read (head $ tail $ words line) :: Integer\n putStr $ show $ solve m b\n", "src_uid": "9300f1c07dd36e0cf7e6cb7911df4cf2"} {"source_code": "main = getLine >>= putStrLn . show . count . parseInput\n\nparseInput :: String -> (Int, Int)\nparseInput str = (read n, read m)\n where [n, m] = words str\n \ncount :: (Int, Int) -> Int\ncount (n, m)\n | n == m = 0\n | m < n = n - m\n | otherwise = go n 0\n where m' = fromIntegral m\n go n ans = if n == m\n then ans\n else go target (ans + hits)\n where n' = fromIntegral n\n target = findTarget m'\n findTarget currentTarget = if nextTarget <= n'\n then ceiling currentTarget\n else findTarget nextTarget\n where nextTarget = currentTarget * 0.5\n lowerTarget = (ceiling $ (fromIntegral target) * 0.5 :: Int)\n backwards = (n - lowerTarget) + (lowerTarget + lowerTarget - target) + 1\n forwards = n + n - target + 1\n hits = min backwards forwards\n", "src_uid": "861f8edd2813d6d3a5ff7193a804486f"} {"source_code": "import Control.Applicative\n\nsolve s v1 v2 t1 t2\n | first < second = \"First\"\n | first > second = \"Second\"\n | otherwise = \"Friendship\"\n where first = calTime s v1 t1\n second = calTime s v2 t2\n calTime s v t = 2 * t + v * s\n\nmain = do\n (s:v1:v2:t1:t2:_) <- map read <$> words <$> getLine :: IO [Int]\n putStrLn $ solve s v1 v2 t1 t2\n\n\n", "src_uid": "10226b8efe9e3c473239d747b911a1ef"} {"source_code": "{-# LANGUAGE FlexibleContexts #-}\n{-# LANGUAGE ViewPatterns #-}\n\nmodule Main where\n\n--import Debug.Trace\n\nimport Control.Monad\nimport Control.Monad.ST\nimport Control.DeepSeq\nimport Data.Function\nimport Data.Maybe\nimport Data.Either\nimport qualified Data.Foldable as Foldable\nimport Data.Char\nimport Data.List\nimport Data.Array.IArray\nimport Data.Array.MArray.Safe\nimport qualified Data.Array.Unboxed as UA\n\nimport Data.Map.Strict (Map)\nimport qualified Data.Map.Strict as Map\n\ngetWords = words <$> getLine :: IO [String]\ngetInts = map read <$> getWords :: IO [Int]\ngetDoubles = map read <$> getWords :: IO [Double]\ngetInt = read <$> getLine :: IO Int\ngetDouble = read <$> getLine :: IO Double\nprintLines :: Show a => [a] -> IO ()\nprintLines = mapM_ print\nprintStrs = mapM_ putStrLn :: [String] -> IO ()\n\n---- Answer Code Section ----\n\nprocess :: [Int] -> Int\nprocess xs = if nPos >= half then 1 else if nNeg >= half then -1 else 0 where\n half = ceiling $ fromIntegral (length xs) / 2\n nPos = length $ filter (0 <) xs\n nNeg = length $ filter (0 >) xs\n\nmain = do\n n <- getInt\n xs <- getInts\n print $ process xs\n", "src_uid": "a13cb35197f896cd34614c6c0b369a49"} {"source_code": "import Control.Applicative\nimport Control.Monad\nimport qualified Data.ByteString.Char8 as BS\nimport Data.Maybe\n\n\ngetInts::IO [Int]\ngetInts = go <$> BS.getLine where\n go s = case BS.readInt s of\n Nothing -> []\n Just (x, s') -> x : go (BS.drop 1 s')\n\n\nmain :: IO ()\nmain = do\n [x1,y1,x2,y2] <- getInts\n [x,y] <- getInts\n let dx = x1 - x2\n dy = y1 - y2\n xx = steps (x1 - x2) x\n yy = steps (y1 - y2) y\n xy = (-) <$> xx <*> yy\n res = zeros dx x && isJust xx ||\n zeros dy y && isJust yy ||\n maybe False even xy\n putStrLn (if res then \"YES\" else \"NO\")\n where steps 0 0 = Just 0\n steps _ 0 = Nothing\n steps x y | mod x y == 0 = Just $ quot x y\n | otherwise = Nothing\n zeros x y = x == 0 && y == 0\n", "src_uid": "1c80040104e06c9f24abfcfe654a851f"} {"source_code": "module Main where\n\nimport System.IO\nimport qualified Data.ByteString as BS\nimport qualified Data.ByteString.Char8 as C8\n\nimport qualified Data.Array as Array\nimport qualified Data.Set as Set\nimport qualified Data.List as List\nimport qualified Data.Map as Map\n\nimport Control.Monad\n\ninput :: IO BS.ByteString\ninput = do\n handle <- return stdin --openFile \"test.txt\" ReadMode\n BS.hGetContents handle\n\nreadInts :: BS.ByteString -> [Int]\nreadInts = map parse . C8.words\n where parse s = let Just (x,_) = C8.readInt s in x\n\nmain :: IO ()\nmain = do\n n <- fmap read getLine\n let denominations = reverse [1, 5, 10, 20, 100]\n bills = foldl (\\(total, remaining) bill -> let\n (count, remaining') = divMod remaining bill\n in (total + count, remaining'))\n (0, n) denominations\n print $ fst bills\n", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc"} {"source_code": "import Data.List (sort)\n\nmain = interact (show . length . pile . map read . words . (!! 1) . lines)\n\npile = foldr add [] . reverse . sort\n\nadd y [] = [[y]]\nadd y (x:xs)\n | canAdd y x = (y:x):xs\n | otherwise = x:add y xs\n where canAdd y x = y >= length x\n", "src_uid": "7c710ae68f27f140e7e03564492f7214"} {"source_code": "main = interact $ (++\"\\n\") . go . read\n where \n go :: Integer -> String\n go n = concatMap (uncurry replicate) $ zip (map fromInteger $ replicate less (max-1) ++ (replicate (10-less) max)) \"codeforces\"\n where\n max = bs n 0 100\n less = head $ filter (\\x -> (max-1)^x * max^(10-x) >= n) [9,8..0]\n\n bs t lo hi | lo + 1 >= hi = hi\n | m^10 < t = bs t m hi\n | otherwise = bs t lo m\n where\n m = lo + ((hi - lo) `div` 2)\n", "src_uid": "8001a7570766cadcc538217e941b3031"} {"source_code": "main = do\n (y:x:_) <- fmap (map read . words) getLine :: IO [Integer]\n let m = x - 1\n let n = (y-x+1) `div` 2\n putStrLn (if (y-x+1) `mod` 2 /= 0 || (n >= 1 && m < 1) || n < 0 || m < 0 then \"No\" else \"Yes\")", "src_uid": "1527171297a0b9c5adf356a549f313b9"} {"source_code": "import Control.Applicative\nimport Control.Monad\n\nmain :: IO ()\nmain = putStrLn . unwords . fmap show =<< sol <$> readLn\n\nsol :: (Integral a, Integral b) => a -> [b]\nsol n\n | n==2^p = [p+1]\n | otherwise = (p+1):sol (n - 2^p)\n where\n p = floor (log (fromIntegral n)/log 2)\n", "src_uid": "757cd804aba01dc4bc108cb0722f68dc"} {"source_code": "main :: IO ()\nmain = do\n nStr <- getLine\n numsStr <- getLine\n let\n n = read nStr :: Int\n nums = [read x :: Int | x <- words numsStr]\n putStrLn (show (max (maxDifficulty nums) (minSkippingDifficulty nums)))\n\nmaxDifficulty :: [Int] -> Int\nmaxDifficulty (x:y:[]) = y - x\nmaxDifficulty (x:y:rest) = max (y - x) (maxDifficulty (y:rest))\n\nminSkippingDifficulty :: [Int] -> Int\nminSkippingDifficulty (x:y:z:[]) = z - x\nminSkippingDifficulty (x:y:z:rest) = min (z-x) (minSkippingDifficulty (y:z:rest))\n", "src_uid": "8a8013f960814040ac4bf229a0bd5437"} {"source_code": "import Control.Applicative\nimport Data.Char\n\n \n\n \n\n\nmain= do\n\tn<- read<$> getLine ::IO Integer\n\tlet x = mod n 360\n\tlet y= (div x 90) + if (mod x 90)>45 then 1 else 0\n\tlet z= if (mod x 90 ==45 ) && ( y==3) then 0 else y\n\tprint $ mod z 4\n\n\t", "src_uid": "509db9cb6156b692557ba874a09f150e"} {"source_code": "import Data.List\nimport Data.Int\n\nreadInts :: IO [Integer]\nreadInts = fmap (map read . words) getLine\n\nmodOp :: Integer -> (Integer -> Integer -> Integer) -> Integer -> Integer -> Integer\nmodOp p op x y = mod (op x y) p\n\nbigprime = 10^9 + 7\nmodP = modOp bigprime\n\nfexp :: Integer -> Integer -> Integer\nfexp _ 0 = 1\nfexp a e = modP (*) (if mod e 2 == 0 then 1 else a) (fexp (modP (*) a a) (div e 2))\n\nsolveP :: Integer -> Integer -> Integer\nsolveP p n = \n let\n powers = takeWhile (<= n) $ (map (p^) [1..])\n exps = (map (div n) powers)\n exp = foldl' (modOp (bigprime - 1) (+)) 0 exps\n in fexp p exp\n\nfactor :: Integer -> [Integer]\nfactor n = f 2 n\n where\n f p k\n | k < p * p = [k]\n | mod k p == 0 = p : (f p (div k p)) \n | otherwise = f (p + 1) k\n\nprimes = ((map head) . group . factor)\n\nsolve :: Integer -> Integer -> Integer\nsolve x n = foldl' (modP (*)) 1 $ map (flip solveP n) (primes x)\n\nmain = do\n [x, n] <- readInts\n putStrLn $ show $ solve x n\n\ntestcase = solve 666010979 443570624148538441\n", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c"} {"source_code": "import Control.Applicative\nimport Control.Monad\nimport Data.List\nimport Data.Maybe\n\n\nmain = do\n\t\ta<-read <$> getLine ::IO Int\n\t\tprint $ if a<3 then 7 else ( a-2)\n", "src_uid": "5c68e20ac6ecb7c289601ce8351f4e97"} {"source_code": "{-#LANGUAGE NPlusKPatterns #-}\n\nmodule Main where\n\nimport Data.List\n\nmain :: IO ()\nmain = do\n\tn <- getInt\n\tcoos <- getCoos n\n\tprint $ process n coos\n\ngetInt :: IO Integer\ngetInt = readLn\n\ntype Coo = (Integer, Integer)\n\ngetCoo :: IO Coo\ngetCoo = do\n\ts <- getLine\n\tlet [x, y] = words s\n\treturn (read x, read y)\n\ngetCoos :: Integer -> IO [Coo]\ngetCoos 0 = return []\ngetCoos (n + 1) = do\n\tcoo <- getCoo\n\tcoos <- getCoos n\n\treturn (coo : coos)\n\nprocess :: Integer -> [Coo] -> Integer\n-- process 0 _ = -1\n-- process 1 _ = -1\n-- process\nprocess _ coos = let xs = exes coos\n ys = wyes coos\n in judge (nub xs) (nub ys)\n\njudge :: [Integer] -> [Integer] -> Integer\njudge xs ys = let m = length (nub xs)\n n = length (nub ys)\n in if m < 2 || n < 2 then - 1 else compute xs ys\n\ncompute :: [Integer] -> [Integer] -> Integer\ncompute (x1 : x2 : _) (y1 : y2 : _) = side x1 x2 * side y1 y2\n\nside :: Integer -> Integer -> Integer\nside a b = abs (a - b) \n\nexes, wyes :: [Coo] -> [Integer]\nexes = map fst\nwyes = map snd\n", "src_uid": "ba49b6c001bb472635f14ec62233210e"} {"source_code": "module Main where\n\nimport Control.Monad\nimport Data.List\n\ncheckGuess answer guess =\n let a = length $ filter id $ zipWith (==) answer guess\n ab = length $ intersect answer guess\n in (a, ab-a)\n\ninitGuess = filter (\\[a,b,c,d] ->\n a /= b && a /= c && a /= d &&\n b /= c && b /= d &&\n c /= d\n ) $ map (\\n -> if n < 1000 then '0':show n else show n) $ [123..9876]\n\nmain = do\n n <- read `liftM` getLine\n final <- foldM (\\remain _ -> do\n (guess, a, b) <- do\n [guess, a, b] <- words `liftM` getLine\n return (guess, read a, read b)\n return $ filter (\\answer -> checkGuess answer guess == (a, b)) remain\n ) initGuess [1..n]\n\n\n putStrLn $ case length final of\n 0 -> \"Incorrect data\"\n 1 -> head final\n _ -> \"Need more data\"\n", "src_uid": "142e5f2f08724e53c234fc2379216b4c"} {"source_code": "findPos :: [Char] -> Char -> Int\nfindPos s ch = length (takeWhile (\\cur -> cur /= ch) s)\n\nfwd :: Char -> Char -> Int\nfwd from to = findPos ([from..'z'] ++ ['a'..to]) to\n\ngenDec :: Char -> Char -> [Char]\ngenDec from to =\n if from == to\n then [from]\n else [from, (pred from)..to]\n\nbck :: Char -> Char -> Int\nbck from to = findPos ((genDec from 'a') ++ (genDec 'z' to)) to\n\nmain = do\n s <- getLine\n let s2 = 'a':s\n let pairs = zip s2 s\n let dist = foldr (+) 0 (map (\\(f, s) -> min (fwd f s) (bck f s)) pairs)\n putStrLn (show dist)", "src_uid": "ecc890b3bdb9456441a2a265c60722dd"} {"source_code": "isPrime 1 = False\nisPrime x =\n all (/= 0) mods\n where\n mods = map (x `mod`) cand\n cand = takeWhile (\\y -> y * y <= x) [2..]\n\ng a k = a - sum [f a i | i <- [2..k - 1]]\nf a k\n | (not . isPrime) k = 0\n | a < k * k = if a >= k then 1 else 0\n | otherwise = g (a `div` k) k\n\nsolve a b k = f b k - f (a - 1) k\n\nmain = do\n [a,b,k] <- (map read . words) `fmap` getLine :: IO [Integer]\n putStrLn $ show $ solve a b k\n", "src_uid": "04a26f1d1013b6e6b4b0bdcf225475f2"} {"source_code": "main=readLn>>= \\n->print$head(filter(elem '8'.show)[n+1..])-n\n", "src_uid": "4e57740be015963c190e0bfe1ab74cb9"} {"source_code": "main = getLine >>= print. max 0. (\\[a, b, c] -> (a*c - b*c) `div` b + if (a*c-b*c) `mod` b == 0 then 0 else 1). map read. words\n", "src_uid": "7dd098ec3ad5b29ad681787173eba341"} {"source_code": "import Data.List\nimport Data.Ord\nimport Data.Array\n\ndp=array ('A','Z')[(k,(-1,-1))|k<-['A'..'Z']]\n\nbuildDP [] dp _ = dp\nbuildDP (x:xs) dp index\t\n\t|start /= (-1) \t= buildDP xs (dp//[(x,(start,index))]) (index+1)\n\t|otherwise \t\t= buildDP xs (dp//[(x,(index,index))]) (index+1) \n\twhere\n\t\tstart=fst $ dp!x\n\ncheckSeq_new x = map (\\(_,x)->x) $ filter (\\(_,(s,_))->s>=0) $ assocs $ buildDP x dp 0\n\t\t\ncreateSigns [] = []\ncreateSigns ((l,r):xs) = [(l,1),(r+1,-1)]++createSigns xs\n\ns [] = 0\ns ((x,y):xs)= y+s xs\n\nsumAll t@((x,y):xs) = (x,s t)\n\nf x = map sumAll $ groupBy (\\x y -> (fst x) == (fst y)) $ sortBy (comparing fst) (createSigns $ checkSeq_new x)\n\nsolve [] c= [c]\nsolve ((_,n):xs) c=(n+c):solve xs (n+c)\n\nisJust (Just _)=True\nisJust _ = False\n\nanswer k text\n\t|isJust jj = \"YES\"\n\t|otherwise = \"NO\"\n\twhere\n\t\tjj=find (>k) $ solve (f text) 0\nmain=do\n\tnum<-getLine\n\tlet (_:m:_)= map (\\x->read x::Int) (words num)\n\ttext<-getLine\n\tputStrLn (answer m text)\n\t", "src_uid": "216323563f5b2dd63edc30cb9b4849a5"} {"source_code": "import Data.Array\nimport Text.Printf\n\nsolve w b = dp ! (w,b,1)\n where\n dp = listArray ((0,0,0),(w,b,1)) [ f i j d | i <- [0..w], j <- [0..b], d <- [0,1] ]\n f 0 j _ = 0.0 :: Double\n f i j d | d == 1 = fromIntegral i / fromIntegral (i+j) + fromIntegral j / fromIntegral (i+j) * check (i,j-1,0)\n | True = if j > 0 then fromIntegral j / fromIntegral (i+j) * escape i (j-1) else 0.0\n escape i j = fromIntegral i / fromIntegral (i+j) * check (i-1,j,1) + fromIntegral j / fromIntegral (i+j) * check (i,j-1,1)\n check p@(i,j,d) | i <= 0 || j < 0 = 0.0\n | True = dp ! p\n\nmain = do\n (w:b:_) <- (fmap (map read . words) getLine) :: IO [Int]\n printf \"%.9f\\n\" $ solve w b", "src_uid": "7adb8bf6879925955bf187c3d05fde8c"} {"source_code": "import Control.Monad\nmain = do\n a <- liftM read getLine\n putStrLn $ show $ 1 + (a+1)`mod`2", "src_uid": "816ec4cd9736f3113333ef05405b8e81"} {"source_code": "{-# OPTIONS_GHC -O2 -optc-Ofast -fignore-asserts #-}\nimport Data.Array.Unboxed\n\ntype State = (Bool, Int, Int, Int)\n\n(+%) :: Int -> Int -> Int\na +% b = if c >= m then c - m else c\n where\n c = a + b\n m = 1000000009\n\ngao :: Int -> Int -> UArray State Int\ngao h n = go n $ newArray [((True, 0, 0, 0), 4)]\n where\n newArray = accumArray (+%) 0 ((False, 0, 0, 0), (True, h, h, h))\n state = [(f, i, j, k) |\n f <- [False, True], i <- [0 .. h], j <- [i .. h], k <- [j .. h]]\n go 1 dp = dp\n go m dp = go (m - 1) $ newArray $ concat [next i $ dp!i | i <- state]\n where\n next (f, i, j, k) e\n | f = [\n ((i < h, 0, j', k'), e),\n ((j < h, 0, i', k'), e),\n ((k < h, 0, i', j'), e),\n ((True, i', j', k'), e)]\n | otherwise = [\n ((i < h, j', k', h), e),\n ((j < h, i', k', h), e),\n ((k < h, i', j', h), e),\n ((False, i', j', k'), e)]\n where\n [i', j', k'] = map (min h . succ) [i, j, k]\n\nmain :: IO ()\nmain = do\n [n, h] <- fmap (map read . words) getLine\n let h' = h - 1\n ans = gao h' n\n print $ foldl1 (+%) [e | ((f, i, _, _), e) <- assocs ans, f || i < h']\n", "src_uid": "9fe9658db35076c0bddc8b7ddce11013"} {"source_code": "main :: IO()\nmain = print . solve . map read . words =<< getLine\n\nsolve :: [Integer] -> Integer\nsolve [n, a, b, c, d] = n * (iter 1)\n where iter :: Integer -> Integer\n iter i | i > n = 0\n | otherwise = (valid i) + iter (i + 1)\n valid :: Integer -> Integer\n valid x1 = let sum = a + b + x1\n x2 = sum - a - c\n x3 = sum - b - d\n x4 = sum - c - d\n in if 1 <= x2 && x2 <= n &&\n 1 <= x3 && x3 <= n &&\n 1 <= x4 && x4 <= n\n then 1 else 0\n", "src_uid": "b732869015baf3dee5094c51a309e32c"} {"source_code": "main = interact (format . solve . parse)\n\nparse s = case words s of\n (x:y:z:a:b:c:[]) -> (read x :: Integer,\n read y :: Integer,\n read z :: Integer,\n read a :: Integer,\n read b :: Integer,\n read c :: Integer)\n _ -> (0, 0, 0, 0, 0, 0)\n\nsolve (x, y, z, a, b, c) = (x <= a) && (x + y <= a + b) && (x + y + z <= a + b + c)\n\nformat True = \"YES\"\nformat False = \"NO\"\n", "src_uid": "d54201591f7284da5e9ce18984439f4e"} {"source_code": "\nimport Data.List\n\n-- import Debug.Trace\n\n-- debug = flip trace\ndebug = const\n\ncalc ('+':ops) (a:b:nums) = \n search ops ((a+b):nums) `debug` (show a ++ \"+\" ++ show b ++ \"=\" ++ show (a+b) ++ \":\" ++ show nums)\ncalc ('*':ops) (a:b:nums) =\n search ops ((a*b):nums) `debug` (show a ++ \"*\" ++ show b ++ \"=\" ++ show (a*b) ++ \":\" ++ show nums)\n\nsearch [] (num:[]) = [num]\nsearch ops nums = do\n let numsA = permutations nums\n ns <- numsA\n calc ops ns\n \nreadInts :: IO [Integer]\nreadInts = (map read . words) `fmap` getLine\n\nmain = do\n nums <- readInts\n opts <- (filter (/= ' ')) `fmap` getLine\n putStrLn $ (show (minimum (search opts nums)))", "src_uid": "7a66fae63d9b27e444d84447012e484c"} {"source_code": "import Control.Monad\n\nanswer :: String -> Int -> Int -> Bool\nanswer [] 0 _ = True\nanswer [] _ _ = False\nanswer x 0 y = answer x y y\nanswer (x:xs) a b\n\t| a < 0 = False\n\t| otherwise = answer xs (a - read (x:\"\")) b\n\nf :: String -> Bool\nf number = let s = sum . map (read . (:\"\")) $ number\n\t\t\t\t\t in if s == 0 then length number > 1 else any (answer (filter (/= '0') number) 0) $ filter ((==0) . (s `mod`)) [1..s - 1]\n\nf' s = if f s then \"YES\" else \"NO\"\n\nmain = getLine >> getLine >>= putStrLn . f'\n", "src_uid": "410296a01b97a0a39b6683569c84d56c"} {"source_code": "main :: IO()\nmain = print . solve . map read . words =<< getContents\n\nsolve :: [Integer] -> Integer\nsolve [n, a, b, c] = let m = max 0 (div (n - c) (b - c))\n in max (div n a) (m + (div (n - m * (b - c)) a))\n", "src_uid": "0ee9abec69230eab25de51aef0984f8f"} {"source_code": "bicolorable :: String -> Bool\nbicolorable s = coloredCorrectly s && canBicolor s\n where coloredCorrectly xs = and $ zipWith (\\x y -> x /= y || x == '?' || y == '?') xs (tail xs)\n canBicolor [] = False\n canBicolor ('?':_) = True\n canBicolor (l:'?':rest@(r:_)) = l == r || canBicolor rest\n canBicolor (_:rest) = canBicolor rest\n\nmain = getLine >> getLine >>= return . toAnswer >>= putStrLn\n where toAnswer s = if bicolorable s then \"Yes\" else \"No\"\n", "src_uid": "f8adfa0dde7ac1363f269dbdf00212c3"} {"source_code": "gao :: Int -> Int -> Int\ngao a b = 2 * c + diff a' b'\n where\n c = min a b `div` 2\n a' = a - 2 * c\n b' = b - 2 * c\n same 0 y = max 0 $ y - 1\n same x y = 1 + diff y (x - 1)\n diff 0 y = y\n diff x y = same (x - 1) y\n\nmain :: IO ()\nmain = do\n [n, m] <- fmap (map read . words) getLine\n let x = max (gao m $ n - 1) (gao n $ m - 1)\n print $ x\n print $ n + m - 1 - x\n", "src_uid": "c8378e6fcaab30d15469a55419f38b39"} {"source_code": "import Prelude\nimport Data.List\nimport Data.Maybe\nimport Data.Function\nimport Data.Char\nimport Data.Graph\nimport Data.Tree\nimport Data.Int\nimport Data.Bits\nimport qualified Data.Set as Set\nimport qualified Data.ByteString.Lazy.Char8 as B\n\nreadInts :: IO [Int]\nreadInts = fmap (map (foldl' (\\x y -> 10*x + digitToInt y) 0) . words) getLine\n\ntextRepresentation :: Show a => [a] -> String\ntextRepresentation row = unwords . map show $ row\n\nmain :: IO ()\nmain = putStr \"Karen\"\n -- n:_ <- readInts\n --l1 <- readInts\n --l2 <- readInts\n --let set = Set.fromList $ l1 ++ l2\n -- zz = foldl' (\\x y -> foldl' (\\xx yy -> if Set.member (xor y yy) set then xx+1 else xx) x l2) 0 l1\n --ww = foldl' (\\x y -> foldl' (\\xx yy -> if Set.member (xor y yy) set then xx+1 else xx) x l1) zz l2\n --if even zz\n -- then putStr \"Karen\"\n --else putStr \"Koyomi\"\n\n\n\n\n--kind\n--по-бавно решение с глобален параметър\n--индексиране на памет\n--dolna granica na slojnost", "src_uid": "1649d2592eadaa8f8d076eae2866cffc"} {"source_code": "{-# LANGUAGE TypeSynonymInstances #-}\n{-# OPTIONS_GHC -O2 #-}\nclass Scan a where scan' :: String -> a\ninstance Scan Int where scan' n = read n\ninstance Scan Char where scan' (x:_) = x\ninstance Scan Float where scan' f = read f\ninstance Scan Double where scan' d = read d\ninstance Scan Integer where scan' n = read n\ninstance Scan String where scan' x = x\ninstance (Scan a,Scan b) => Scan (a,b) where scan' x = scan'' (words x)\n where\n scan'' (x:y:_) = (scan' x,scan' y)\ninstance (Scan a,Scan b,Scan c) => Scan (a,b,c) where scan' x = scan'' (words x)\n where\n scan'' (x:y:z:_) = (scan' x,scan' y,scan' z)\ninstance (Scan a,Scan b,Scan c,Scan d) => Scan (a,b,c,d) where scan' x = scan'' (words x)\n where\n scan'' (w:x:y:z:_) = (scan' w,scan' x,scan' y,scan' z)\ninstance (Scan a,Scan b,Scan c,Scan d,Scan e) => Scan (a,b,c,d,e) where scan' x = scan'' (words x)\n where\n scan'' (v:w:x:y:z:_) = (scan' v,scan' w,scan' x,scan' y,scan' z)\nclass Ans a where showans :: a -> String\ninstance Ans Int where showans x = show x\ninstance Ans Char where showans x = [x]\ninstance Ans Float where showans x = show x\ninstance Ans Double where showans x = show x\ninstance Ans Integer where showans x = show x\ninstance Ans String where showans x = x\ninstance (Ans a, Ans b) => Ans (a,b) where\n showans (x,y) = showans x ++ \" \" ++ showans y\ninstance (Ans a, Ans b,Ans c) => Ans (a,b,c) where\n showans (x,y,z) = showans x ++ \" \" ++ showans y ++ \" \" ++ showans z\n\nscan :: (Scan a) => IO a\nscan = do n <- getLine\n return (scan' n)\n\nscans :: (Scan a) => Int -> IO [a]\nscans 0 = return []\nscans n = do x <- scan\n xs <- scans (n-1)\n return (x:xs)\n\nscanlist :: (Scan a) => IO [a]\nscanlist = do l <- getLine\n return [scan' x|x<-words l]\n\nscanlists :: (Scan a) => Int -> IO [[a]]\nscanlists 0 = return []\nscanlists n = do x <- scanlist :: (Scan a) => IO [a]\n xs <- scanlists (n-1)\n return (x:xs)\n\nputAnsLn :: (Ans a) => a -> IO ()\nputAnsLn ans = putStrLn (showans ans)\n\nputAnsLns :: (Ans a) => [a] -> IO ()\nputAnsLns (x:xs) = do putAnsLn x\n putAnsLns xs\nputAnsLns [] = return ()\n\nputDebugLn :: (Show a) => a -> IO ()\nputDebugLn ans = putStrLn (show ans)\n\nsolve :: Int -> Int -> Int -> String\nsolve n' x y = let n = div n' 2 in\n if (x==n||x==n+1)&&(y==n||y==n+1) then\n \"NO\"\n else\n \"YES\"\n\nmain = do (n',x,y) <- scan::IO (Int,Int,Int)\n putAnsLn (solve n' x y)", "src_uid": "dc891d57bcdad3108dcb4ccf9c798789"} {"source_code": "\nimport Char (ord)\n\ndata Phigure = King Int Int | Rook Int Int\n\ndamage :: Phigure -> Phigure -> Bool\ndamage (King x1 y1) (King x2 y2) = abs (x1 - x2) < 2 && abs (y1 - y2) < 2\n\ndamageWithKing :: Phigure -> Phigure -> Phigure -> Bool\ndamageWithKing (King x1 y1) (Rook x2 y2) (King x3 y3)\n | x2 == x3 && y2 == y3 = False\n | x2 == x3 && x1 == x2 = not $ abs (y2 - y3) > abs (y2 - y1) && abs (y2 - y3) > abs (y3 - y1)\n | y2 == y3 && y1 == y2 = not $ abs (x2 - x3) > abs (x2 - x1) && abs (x2 - x3) > abs (x3 - x1)\n | otherwise = x2 == x3 || y2 == y3\n\ncheck :: [Phigure] -> Phigure -> Bool\ncheck [wKing, rook1, rook2] bKing\n = damage wKing bKing\n || damageWithKing wKing rook1 bKing\n || damageWithKing wKing rook2 bKing\n\ncheckMate :: [Phigure] -> Phigure -> Bool\ncheckMate ws (King x1 y1)\n = all (check ws) $ filter coord [King (x1 + dx) (y1 + dy) | dx <- [-1..1], dy <- [-1..1]]\n where\n coord (King x y) = x > 0 && x < 9 && y > 0 && y < 9\n coord (Rook x y) = x > 0 && x < 9 && y > 0 && y < 9\n\n() :: a -> a -> Bool -> a\n() a b p = if p then a else b\n\nparse :: String -> (Int, Int)\nparse [x, y] = (ord x - ord 'a' + 1, ord y - ord '0')\n\nmain :: IO ()\nmain = do\n [(x1, y1), (x2, y2), (x3, y3), (x4, y4)] <- fmap (map parse . words) getLine\n putStrLn $ \"CHECKMATE\" \"OTHER\" $ checkMate [King x3 y3, Rook x1 y1, Rook x2 y2] (King x4 y4)\n", "src_uid": "5d05af36c7ccb0cd26a4ab45966b28a3"} {"source_code": "main = interact (unwords.map show.takeWhile(>0).iterate f.read)\nf 1 = 0\nf n = div n $ head [i|i<-[2..], mod n i==0]\n", "src_uid": "2fc946bb72f56b6d86eabfaf60f9fa63"} {"source_code": "module Main where\n\nimport Control.Monad\nimport Data.Array\n\nmaxNumber = 1000000\n\ndigits :: Array Int Int\ndigits = dv\n where dv = listArray (0, maxNumber) $ 6:2:5:5:4:5:6:3:7:6:[gen i | i <- [10 .. maxNumber]]\n gen i = (dv ! m) + (dv ! d)\n where (d, m) = divMod i 10\n\nsolve :: Int -> Int -> Int\nsolve a b = sum $ [digits ! i | i <- [a .. b]]\n\nmain :: IO ()\nmain = do\n [a, b] <- liftM (map read . words) getLine\n print $ solve a b\n", "src_uid": "1193de6f80a9feee8522a404d16425b9"} {"source_code": "main = do\n x <- readLn :: IO Int\n print $ if x == 2 then 2 else 1", "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d"} {"source_code": "solve = check . take 4 . map fromEnum . concat where\n check [a, b, c, d] = show l : ds where\n cx = c - a\n cy = d - b\n (wch, w) = (if signum cx >= 0 then \"R\" else \"L\", abs cx)\n (hch, h) = (if signum cy >= 0 then \"U\" else \"D\", abs cy)\n l = max w h\n ds = take l $ zipWith (++) (replicate w wch ++ repeat \"\") (replicate h hch ++ repeat \"\")\n\nmain = interact $ unlines . solve . lines\n\n", "src_uid": "d25d454702b7755297a7a8e1f6f36ab9"} {"source_code": "main = interact $ show . g . lines\n\ncount n = length . filter (==n)\nfactorial n = product [1..n]\nc n r = (factorial n) `div` ((factorial r)*(factorial (n-r)))\n\nprobablity :: Int -> Int -> Double\nprobablity x a = (fromIntegral (a `c` x)) / (fromIntegral (2^a))\n\ng :: [String] -> Double\ng (x:y:[])\n | c > a || d > b = 0.0\n | otherwise = probablity (a-c) q\n where l = length x\n a = count '+' x\n b = l - a\n c = count '+' y\n d = count '-' y\n q = count '?' y\n \n", "src_uid": "f7f68a15cfd33f641132fac265bc5299"} {"source_code": "main = do\n [n_, m_, k_] <- return . map read . words =<< getLine\n let (dv,md) = k_ `divMod` (2*m_)\n\tlane\n\t | md/=0\t= dv+1\n\t | otherwise\t= dv\n\t(dv',md') = md `divMod` 2\n\tdesk\n\t | md'==0\t= if dv' == 0 then m_ else dv'\n\t | otherwise\t= dv' + 1\n\tlr\n\t | md'==0\t= \"R\"\n\t | otherwise\t= \"L\"\n putStr $ (show lane) ++ \" \" ++ (show desk) ++ \" \" ++ lr\n", "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb"} {"source_code": "import Data.List\n\nfindBall' :: [Int] -> Int -> Int -> Int -> [Int]\nfindBall' [] _ _ _ = [];\nfindBall' balls color count acc = if replicate count color `isPrefixOf` balls \n\t\t\t\t\t\t\t\t\tthen acc:(findBall' (tail balls) color count (acc+1)) \n\t\t\t\t\t\t\t\t\telse findBall' (tail balls) color count (acc+1)\n\nfindBall :: [Int] -> Int -> Int -> [Int]\nfindBall [] _ _ = [];\nfindBall balls color count = findBall' balls color count 0\n\ndropBalls :: [Int] -> Int -> Int\ndropBalls list acc = if dropped > 0 then nextStep else acc\n\t\t\twhere\n\t\t\t\tdropped = fst (calcStep list)\n\t\t\t\tnextStep = dropBalls (snd (calcStep list) ) (acc+dropped)\n\n\ncalcStep :: [Int] -> (Int, [Int])\ncalcStep [] = (0, [])\ncalcStep list = if len < 3 then (0+fst next, (take len list)++(snd next) ) else (len+fst next, snd next )\n\t\t\twhere\n\t\t\t\tlen = length $ takeWhile (==(head list)) list\n\t\t\t\tnext = calcStep (drop len list)\n\nmain = do\n\tdataStr <- getLine\n\tballStr <- getLine\n\tlet dataList = map (read:: String -> Int) $ words dataStr\n\tlet balls = map read $ words ballStr\n\tlet colors = dataList!!1\n\tlet ballColor = dataList!!2\n\tlet positions = findBall balls ballColor 2\n\tlet variants = map (\\ pos -> (fst (splitAt pos balls) ++ [ballColor] ++ snd (splitAt pos balls)) ) positions\n\tlet answer = if null variants then 0 else maximum ( map (flip dropBalls 0) variants ) -1\n\tputStrLn $ show answer", "src_uid": "d73d9610e3800817a3109314b1e6f88c"} {"source_code": "ans 1 = 1\nans 2 = 3\nans 3 = 5\nans 4 = 3\nans 5 = 3\nans s = head [2*k+1 | k <- [1..], s <= 2*k^2 + 2*k + 1]\n\nmain = interact $ (++ \"\\n\") . show . ans . read\n", "src_uid": "01eccb722b09a0474903b7e5abc4c47a"} {"source_code": "\nimport Control.Applicative\nimport Control.Monad\nimport Data.Array\nimport Data.Graph\nimport Data.Maybe\nimport Data.Tree\nimport Data.Tuple\nimport qualified Data.ByteString.Char8 as B\n\nreadEdge = do\n\t[i, j] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine\n\treturn (i, j)\n\nunordered edges = edges ++ map swap edges\n\nsolve n friends dislikes =\n\t\tif null counts\n\t\t\tthen Nothing\n\t\t\telse Just $ maximum counts\n\twhere\n\t\tlikes = accumArray (&&) True ((1, 1), (n, n)) $ map (\\d -> (d, False)) $ unordered dislikes\n\t\tg = buildG (1, n) $ unordered friends\n\t\tcs = map flatten $ components g\n\t\tallLikes c = and [likes ! (i, j) | i <- c, j <- c]\n\t\tcounts = map length $ filter allLikes cs\n\nmain = do\n\tn <- readLn\n\tm <- readLn\n\tfriends <- replicateM m readEdge\n\tm2 <- readLn\n\tdislikes <- replicateM m2 readEdge\n\tlet r = solve n friends dislikes\n\tif isJust r\n\t\tthen print $ fromJust r\n\t\telse print 0\n", "src_uid": "e1ebaf64b129edb8089f9e2f89a0e1e1"} {"source_code": "import Data.List\n\nmain = do\n a <- getLine\n b <- getLine\n t <- getLine\n\n putStrLn $ if sort (a ++b ) == sort t then \"YES\" else \"NO\"\n", "src_uid": "b6456a39d38fabcd25267793ed94d90c"} {"source_code": "\nimport qualified Data.Set as I\nimport Control.Monad\ntype State = (I.Set Int, I.Set Int, I.Set Int, I.Set Int) \n-- Candidate, On, Off, Indeterminant\n\ndata Log = On Int\n | Off Int deriving(Show)\n\nsimulate :: [Log] -> State -> State\nsimulate [] x = x\nsimulate (On i:r) x@(cand,on,off,ind)\n | I.null cand = x\n | I.null on = simulate r (cand' , on', off', ind) -- I.foldr I.delete cand off'\n | otherwise = simulate r (cand, on' , off', ind)\n where off' = I.delete i off\n on' = I.insert i on\n cand' = if I.size cand > I.size off' then I.foldr I.delete cand off'\n else I.filter (`I.notMember` off') cand\nsimulate (Off i:r) (cand,on,off,ind)\n | I.null cand' = (cand',on,off,ind)\n | otherwise = simulate r (cand',on',off',ind)\n where on' = I.delete i on\n off' = if i `I.member` cand' then I.insert i off else off\n cand' = if not (I.null on') then I.delete i cand\n else cand\n\nreadLog :: [String] -> Log\nreadLog [\"+\", i] = On (read i)\nreadLog [_, i] = Off (read i)\nreadLog _ = undefined\n\nbuildState :: [Log]-> (I.Set Int, I.Set Int, I.Set Int)-> (I.Set Int, I.Set Int, I.Set Int)\nbuildState [] x = x\nbuildState (On i:r) (on,off,vi)\n | i `I.notMember` vi = buildState r (on, off,vi)\n | otherwise = buildState r (on, I.insert i off, I.delete i vi)\nbuildState (Off i:r) (on,off,vi)\n | i `I.notMember` vi = buildState r (on,off,vi)\n | otherwise = buildState r (I.insert i on, off, I.delete i vi)\n\nmain :: IO ()\nmain = do\n n:l:_ <- fmap (map read . words) getLine\n let m = I.fromDistinctAscList [1..n]\n logs <- fmap (map (readLog . words)) (replicateM l getLine)\n let (on,off,ind) = buildState logs (I.empty,I.empty,m)\n let (On k) = head logs\n let off' = I.intersection off (on `I.union` ind)\n let (c,_,_,_) = simulate logs (if I.null on then I.insert k ind else on`I.union`ind,on,off',ind)\n let cl = unwords $ map show (I.toList c)\n print $ I.size c\n unless (I.null c) (putStrLn cl)\n", "src_uid": "a3a337c7b919e7dfd7ff45ebf59681b5"} {"source_code": "\nf (num, m) x\n | isVowel x = (0, max (num+1) m)\n | otherwise = (num+1,m)\n\nisVowel a = elem a \"AEIOUY \"\n\ng2 (xs) = snd $ foldl f (0,0) xs\n\nmain :: IO ()\nmain = do \n xs <- getLine\n print $ g2 (xs ++ \" \")\n", "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee"} {"source_code": "import System.IO\nimport Control.Monad\nimport Data.List\nimport Data.Bits\nimport Data.Word\nimport Data.Maybe\n\nmain :: IO ()\nmain = do\n [x,y] <- map read <$> words <$> getLine\n let bitlist = (uncurry solve (equalizeLengths (toBits y) (toBits x))) >>= (fixfilter . reverse . solvefix . reverse)\n let numbers = fromMaybe [-1] (bitlist >>= genNums)\n case numbers == [-1] of\n True -> putStrLn \"-1\"\n _ -> do\n putStrLn (show . length $ numbers)\n putStr (unwords . map show $ numbers)\n \ntoBits :: Integer -> [Word8]\ntoBits x = toBits' [] x\n\ntoBits' :: [Word8] -> Integer -> [Word8]\ntoBits' lst 0 = 0 : lst\ntoBits' lst 1 = 1 : lst\ntoBits' lst x = toBits' ((fromIntegral (x `mod` 2)) : lst) (x`div`2)\n\nequalizeLengths :: [Word8] -> [Word8] -> ([Word8],[Word8])\nequalizeLengths xs ys = let lx = length xs\n ly = length ys\n in case (lx - ly) < 0 of\n True -> ((replicate (ly - lx) 0) ++ xs , ys)\n _ -> (xs, (replicate(lx - ly) 0) ++ ys)\n\nsolve :: [Word8] -> [Word8] -> Maybe [Word8]\nsolve [] [] = Just []\nsolve [x] [y] = case (odd x `xnor` odd y) of\n True -> Just [x]\n _ -> Nothing\n\nsolve (x:xs) (y:ys)\n | odd x `xnor` odd y = (x:) <$> (solve xs ys)\n | otherwise = ((x-1):) <$> (solve (((+2) . head$xs) : (tail xs)) ys)\n\nsolvefix :: [Word8] -> [Word8]\nsolvefix [] = []\nsolvefix [x] = [x]\nsolvefix (x1:xs)\n | x1 > 128 = (x1+4) : solvefix ( (head xs - 2) : (tail xs))\n | otherwise = x1 : solvefix xs\n\nfixfilter :: [Word8] -> Maybe [Word8]\nfixfilter xs \n | any (> 250) xs = Nothing\n | otherwise = Just xs\n\n\n\nxnor x y = complement (xor x y)\n\ngenNums :: [Word8] -> Maybe [Integer]\ngenNums xs\n | all (==0) xs = Just []\n | otherwise = let (num, list') = foldl' f (0,[]) xs\n in (num :) <$> genNums (reverse list')\n where f :: (Integer, [Word8]) -> Word8 -> (Integer, [Word8]) \n f (s,l') 0 = (s*2, 0 : l')\n f (s,l') i = (s*2 + 1, (i-1) : l')\n\nc1 = 293341698588646512\nc2 = 496573494755010944\n\naa = toBits c2\nab = toBits c1\n\ntestt i = solve (take i aa) (take i ab)\n", "src_uid": "490f23ced6c43f9e12f1bcbecbb14904"} {"source_code": "{-# LANGUAGE FlexibleContexts, ScopedTypeVariables, BangPatterns, OverloadedStrings #-}\n{-# OPTIONS_GHC -O2 #-}\n\nimport Data.Array.IArray\nimport Data.Array.Unboxed\nimport Data.Char\nimport Data.Functor\nimport Data.List\nimport Data.Int\nimport qualified Data.Set as S\nimport qualified Data.ByteString.Char8 as B\nimport Control.Monad\n\ngetInts :: IO [Int]\ngetInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine\n\nallSublists :: [a] -> [[a]]\nallSublists = concatMap (tail . inits) . init . tails\n\nsolve :: Int -> Int -> [Int] -> Int\nsolve n d a = n - (maximum $ map length $ filter ((<= d) . liftM2 (-) last head) $ allSublists $ sort a)\n\n\nmain :: IO ()\nmain = do [n, d] <- getInts\n a <- getInts\n print (solve n d a)", "src_uid": "6bcb324c072f796f4d50bafea5f624b2"} {"source_code": "main = getLine\n >>= putStrLn . show . countFactors . read\n \ncountFactors :: Int -> Int\ncountFactors n = case calcCombinations n 2 of\n (c, 1) -> c - 1\n (c, n) -> calcPrimeCombinations n 3 * c - 1\n where calcCombinations n m = case n `mod` m of\n 0 -> (fst res + 1, snd res)\n _ -> (1, n)\n where res = calcCombinations (n `div` m) m\n calcPrimeCombinations n m\n \t | limit < m = 2\n \t | otherwise = case calcCombinations n m of\n \t (c, 1) -> c\n \t (c, n) -> calcPrimeCombinations n (m + 2) * c\n \t where limit = isqrt n\n \nisqrt :: Int -> Int\nisqrt = floor . sqrt . fromIntegral", "src_uid": "89f6c1659e5addbf909eddedb785d894"} {"source_code": "import qualified Data.ByteString.Char8 as BS\nimport Debug.Trace\nmain = do input <- BS.getLine\n putStrLn $ show $ solve $ getInput (map BS.unpack (BS.words input))\n\nsolve :: (Integer,Int) -> Int\nsolve (1,_) = 0\nsolve (n,k) | (n > (toInteger k)*((toInteger k)-1) `div` 2 + 1) = -1\n | otherwise = binarySearch 1 k (n,k)\n\ngetInput :: [String] -> (Integer,Int)\ngetInput [n,k] = (read n, read k)\n\nbinarySearch :: Int -> Int -> (Integer,Int) -> Int\nbinarySearch min max (n,k) | min == max = min\n | (((toInteger (2*k - ind - 1)) * (toInteger ind)) `div` 2 + 1) >= n = binarySearch min ind (n,k)\n | otherwise = binarySearch (ind+1) max (n,k)\n where ind = (min+max) `div` 2\n\nshowTrace str x = trace (str ++ show x) x", "src_uid": "83bcfe32db302fbae18e8a95d89cf411"} {"source_code": "import Control.Monad\n\nmain = do\n n <- readLn :: IO Int\n winner <- replicateM n readLn :: IO [Int]\n let ans = simulate winner\n if ans == True\n then putStrLn \"YES\"\n else putStrLn \"NO\"\n \nsimulate :: [Int] -> Bool\nsimulate = game 1 2 3\n where\n game _ _ _ [] = True\n game play_1 play_2 spec (x:xs)\n | x == play_1 = game play_1 spec play_2 xs\n | x == play_2 = game spec play_2 play_1 xs\n | otherwise = False\n\n", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87"} {"source_code": "\nuserInt :: IO Int\nuserInt = do\n\tintStr <- getLine\n\treturn $ read intStr\n\nlevelSteps buttons level =\n\tbuttonsOnThisLevel * level + levelFix\n\twhere\n\t\tbuttonsOnThisLevel = buttons - level + 1\n\t\tlevelFix = -(level - 1)\n\nsteps buttons =\n\tsum $ map (levelSteps buttons) [1..buttons]\n\nmain :: IO ()\nmain = do\n\tbuttons <- userInt\n\tprint $ steps buttons\n", "src_uid": "6df251ac8bf27427a24bc23d64cb9884"} {"source_code": "import Control.Monad\nimport Data.List\n\nmain = do\n (a:b:c:d:_) <- map read . words <$> getLine\n print $ solve a b c d\n\ntriangle n\n | n < 0 = 0\n | otherwise = (n * (n + 1)) `div` 2\n\nsolve a b c d =\n sum [ triangle (b - c + y) - triangle (a + y - c - 1) - triangle (b + y - d - 1) + triangle (a - d + y - 2)\n | y <- [b .. c]\n ]", "src_uid": "4f92791b9ec658829f667fcea1faee01"} {"source_code": "import Data.List\n\nmain =do\n e<-getLine\n let xs=filter ((== 0) . ((flip mod) 2)) $ map length $ group e\n print $ length xs", "src_uid": "8b26ca1ca2b28166c3d25dceb1f3d49f"} {"source_code": "main=interact$a.read;a n|n==1=\"Sheldon\"|n==2=\"Leonard\"|n==3=\"Penny\"|n==4=\"Rajesh\"|n==5=\"Howard\"|1>0=a ((n-4)`div`2)\n", "src_uid": "023b169765e81d896cdc1184e5a82b22"} {"source_code": "\n\nf n \n | (mod n 4 == 0) = (div n 4) - 1\n | (mod n 2 == 0) = (div n 4)\n | otherwise = 0\n\n\nmain = do\n n <- readLn\n print (f n)\n", "src_uid": "32b59d23f71800bc29da74a3fe2e2b37"} {"source_code": "{-\nTwo positive integers a and b have a sum of s and a bitwise XOR of x. How many\npossible values are there for the ordered pair (a, b)?\n\nInput\nThe first line of the input contains two integers s and x\n(2 ≤ s ≤ 1012, 0 ≤ x ≤ 1012), the sum and bitwise xor of the pair of positive\nintegers, respectively.\n\nOutput\nPrint a single integer, the number of solutions to the given conditions. If no\nsolutions exist, print 0.\n\nFound at: http://codeforces.com/contest/635/problem/C\n-}\n\nmodule Main where\nimport qualified Data.Array as Array\nimport Data.Array ((!))\nimport Data.Bits ((.&.))\n\nsolve :: Integer -> Integer -> Integer\nsolve s x = let (abCombinations, aOfZerosPossible, bOfZerosPossible) = arr ! (n,0)\n in abCombinations\n - (if aOfZerosPossible then 1 else 0)\n - (if bOfZerosPossible then 1 else 0)\n where [sBitsRaw, xBitsRaw] = [num2bits s, num2bits x]\n n = max (length sBitsRaw) (length xBitsRaw)\n [sBits, xBits] = map (padL 0 n) [sBitsRaw, xBitsRaw]\n arr = Array.listArray arrBounds [dp len carry | (len,carry) <- Array.range arrBounds]\n arrBounds = ((1,0),(n,1))\n -- dp l c ~ what is the number of A,B combinations to get number\n -- of length 'l' so that their sum results with 'c' carry\n dp :: Int -> Int -> (Integer, Bool, Bool)\n dp len carry\n -- TODO simplify all the checks for len == 1\n -- | len == 0 = if carry == 0\n -- then (1, True, True)\n -- else (0, False, False)\n | (s,x,carry) == (0,0,0) = -- (a,b,cPrev) in {(0,0,0)}\n if len == 1\n then (1, True, True)\n else let (combs_c0, a0s_c0, b0s_c0) = arr ! (len - 1, 0)\n in (combs_c0, a0s_c0, b0s_c0)\n | (s,x,carry) == (0,1,0) = (0, False, False)\n | (s,x,carry) == (1,0,0) = -- (a,b,cPrev) in {(0,0,1)}\n if len == 1\n then (0, False, False)\n else let (combs_c1, a0s_c1, b0s_c1) = arr ! (len - 1, 1)\n in (combs_c1, a0s_c1, b0s_c1)\n | (s,x,carry) == (1,1,0) = -- (a,b,cPrev) in {(0,1,0),(1,0,0)}\n if len == 1\n then (2, True, True)\n else let (combs_c0, a0s_c0, b0s_c0) = arr ! (len - 1, 0)\n in (2 * combs_c0, a0s_c0, b0s_c0)\n | (s,x,carry) == (0,0,1) = -- (a,b,cPrev) in {(1,1,0)}\n if len == 1\n then (1, False, False)\n else let (combs_c0, a0s_c0, b0s_c0) = arr ! (len - 1, 0)\n in (combs_c0, False, False)\n | (s,x,carry) == (0,1,1) = -- (a,b,cPrev) in {(0,1,1),(1,0,1)}\n if len == 1\n then (0, False, False)\n else let (combs_c1, a0s_c1, b0s_c1) = arr ! (len - 1, 1)\n in (2 * combs_c1, a0s_c1, b0s_c1)\n | (s,x,carry) == (1,0,1) = -- (a,b,cPrev) in {(1,1,1)}\n if len == 1\n then (0, False, False)\n else let (combs_c1, a0s_c1, b0s_c1) = arr ! (len - 1, 1)\n in (combs_c1, False, False)\n | (s,x,carry) == (1,1,1) = (0, False, False)\n where s = sBits !! (n - len)\n x = xBits !! (n - len)\n\nnum2bits :: Integer -> [Int]\nnum2bits 0 = [0]\nnum2bits n = reverse $ num2bits' n\n where num2bits' :: Integer -> [Int]\n num2bits' 0 = []\n num2bits' n = (if (n .&. 1 == 1) then 1 else 0) : num2bits' (n `div` 2)\n\npadL padItem targetLen xs = (replicate (targetLen - length xs) padItem) ++ xs\n\n\nmain :: IO ()\nmain = do\n line <- getLine\n let [s,x] = map read (words line) :: [Integer]\n putStrLn $ show (solve s x)\n", "src_uid": "18410980789b14c128dd6adfa501aea5"} {"source_code": "main = do\n\t(n1:b1:_) <- getLine>>=return.(map read).words\n\ta <- getLine >>= return.(map read).words\n\tlet x = sum $ zipWith (*) a (pows n1 b1)\n\t(n2:b2:_) <- getLine>>=return.(map read).words\n\tb <- getLine >>= return.(map read).words\n\tlet y = sum $ zipWith (*) b (pows n2 b2)\n\tputStrLn $ comp x y\n\npows n m = reverse $ map (m^) [0..n-1]\n\ncomp x y\n\t| xy = \">\"\n\t| True= \"=\"", "src_uid": "d6ab5f75a7bee28f0af2bf168a0b2e67"} {"source_code": "toFloat s = read s :: Float\nto4tuple [a, b, c, d] = (a, b, c, d)\n\ncalc (d, l, v1, v2) = \n let movable = l - d;\n speed = v1 + v2\n in movable / speed\n \n\nmain = do\n input <- getLine\n putStrLn . show . calc . to4tuple . (map toFloat) . words $ input\n", "src_uid": "f34f3f974a21144b9f6e8615c41830f5"} {"source_code": "{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -funfolding-use-threshold=16 -fexcess-precision -funbox-strict-fields #-}\nmodule Main where\nimport qualified Data.ByteString.Lazy.Char8 as B\nimport Control.Monad\nimport Control.Monad.Trans.State.Lazy\nimport Data.List\n\nmain = putStr . evalState app . B.words =<< B.getContents\n\napp = do\n n <- poi\n m <- poi\n show `fmap` liftM2 solve (replicateM n poi) (replicateM m poi)\n where\n pop = state $ \\(x:xs) -> (x, xs)\n poi = fmap int pop\n int = maybe undefined fst . B.readInt\n\nsolve xs ys\n | not $ null zs = head zs\n | x > y = y * 10 + x\n | otherwise = x * 10 + y\n where\n (x, y) = (minimum xs, minimum ys)\n zs = sort $ xs `intersect` ys", "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee"} {"source_code": "solve n m | n == m = 0\n | m `mod` n /= 0 = -1\n | otherwise = pows23 $ m `div` n\n\npows23 1 = 0\npows23 m | m `mod` 2 == 0 = inc1 . pows23 $ m `div` 2\n | m `mod` 3 == 0 = inc1 . pows23 $ m `div` 3\n | otherwise = -1\n where\n inc1 x = if x == -1 then -1 else x + 1\n\nmain = do\n line <- getLine\n let [n, m] = map read $ words line\n putStrLn . show $ solve n m", "src_uid": "3f9980ad292185f63a80bce10705e806"} {"source_code": "\nmain = interact $ unlines . map (show . pred . ((^)2)) . map (read :: String -> Int) . tail . lines \n\n", "src_uid": "d5e66e34601cad6d78c3f02898fa09f4"} {"source_code": "main = do\n l <- getLine\n let a = readInt l\n let t = a !! 0\n let s = a !! 1\n let x = a !! 2\n putStrLn $ if or [and [t + s <= x, (x - t) `mod` s < 2], t == x]\n then \"YES\" else \"NO\"\n\nreadInt :: String -> [Int]\nreadInt l = map read (words l)\n", "src_uid": "3baf9d841ff7208c66f6de1b47b0f952"} {"source_code": "#!/usr/bin/env stack\n{- stack\n --resolver lts-2.22\n runghc\n --package aeson\n --package array\n --package base\n --package bytestring\n --package containers\n --package hashmap\n --package hashtables\n --package lens\n --package logict\n --package mtl\n --package mwc-random\n --package parsec\n --package pipes\n --package vector\n --\n -hide-all-packages\n-}\n{-# LANGUAGE BangPatterns, TupleSections, RankNTypes, ScopedTypeVariables #-}\nmodule Main\n( main\n) where\n\nimport Prelude hiding (interact, lines, unlines, words, unwords,\n sequence, foldr)\nimport Data.ByteString.Char8 (pack, unpack, ByteString, lines, words,\n unlines, unwords, interact, readInt,\n readInteger)\nimport qualified Data.ByteString.Char8 as BS\nimport Data.List (foldl', sort, sortBy, group, groupBy, inits, tails,\n unfoldr)\nimport qualified Data.List as L\nimport qualified Data.IntSet as IS\nimport Data.IntSet (IntSet)\nimport qualified Data.IntMap.Strict as IM\nimport Data.IntMap.Strict (IntMap)\nimport qualified Data.Map.Strict as M\nimport Data.Map.Strict (Map)\nimport qualified Data.Set as S\nimport Data.Set (Set)\nimport qualified Data.Array.IArray as A\nimport Data.Array.IArray ((!), Array, listArray, array)\nimport Data.Maybe (fromJust, isJust, fromMaybe, maybe, mapMaybe,\n catMaybes)\nimport Data.Either (either)\nimport Control.Applicative (Applicative, pure,\n (<$>), (<*>), (<|>), liftA2, liftA3)\nimport Control.Monad (unless, when, void, filterM, ap)\nimport Control.Arrow ((***), (&&&), first, second)\nimport Data.Traversable (sequence, sequenceA, traverse,\n Traversable)\nimport Data.Ord (comparing, Down(..))\nimport Data.Function (on)\nimport Data.Bits (complement, xor, (.|.), (.&.), testBit, zeroBits,\n bit, shiftR, shiftL, Bits)\nimport qualified Data.Bits as B\nimport Data.Word (Word32)\nimport Control.Monad.State (State, get, put, gets, modify,\n evalState, execState, runState)\nimport Text.Parsec (char, space, parse, Parsec)\nimport qualified Text.Parsec as P\nimport Data.Tuple (swap)\nimport Data.Foldable (Foldable, foldr)\nimport Data.Monoid ((<>), Monoid, mappend, mempty)\n\ntype N = Integer\ntoNum = toInte\n\nanswer n as bs = as `elem` map (skip bs) [0 .. n]\n where skip xs x = let xs' = map (subtract x) xs\n (is, js) = L.partition (< 0) xs'\n in map (`mod` n) $ js ++ is\n\nhandleInput :: ByteString -> ByteString\nhandleInput = lines .- map (words .- map toNum)\n .- coerceInput answer\n .- toOut .- pack\n\ntoOut False = \"NO\"\ntoOut True = \"YES\"\n\ntoInt = readInt .- fromJust .- fst\ntoInte = readInteger .- fromJust .- fst\ntoX :: Read a => ByteString -> a\ntoX = unpack .- read\n\ncoerceInput f ((_:a:_):as:bs:xs) = f a as bs\ncoerceInput _ _ = error \"invalid input\"\n\nmain :: IO ()\nmain = interact handleInput\n\n-- Util stuff --\n(.-) :: (a -> b) -> (b -> c) -> a -> c\n(.-) = flip (.)\ninfixl 9 .-\n", "src_uid": "3d931684ca11fe6141c6461e85d91d63"} {"source_code": "main=readLn>>=print.(ans!!).pred\n\nans :: [GFp]\nans = map (\\x->2^(x-1)-1) [2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701, 23209, 44497, 86243, 110503, 132049, 216091, 756839, 859433, 1257787, 1398269, 2976221, 3021377, 6972593, 13466917, 20996011]\n\ndata GFp = GFp {-# UNPACK #-} !Int deriving (Eq,Ord)\n\ngfOrder :: Int -- prime number\ngfOrder = 1000000007 -- 10^9+7 \n\ninstance Num GFp where\n (GFp x)+(GFp y) = GFp $ (x+y)`rem`gfOrder\n (GFp x)*(GFp y) = GFp $ fromInteger $ (x' * y')`rem`p\n where\n x' = toInteger x\n y' = toInteger y\n p = toInteger gfOrder\n negate (GFp 0) = GFp 0\n negate (GFp x) = GFp $ gfOrder - x\n abs x = x\n signum _ = GFp 1\n fromInteger x = GFp $ fromInteger $ x`mod`(toInteger gfOrder)\n\ninstance Show GFp where\n show (GFp n) = show n", "src_uid": "c2cbc35012c6ff7ab0d6899e6015e4e7"} {"source_code": "\nexgcd a b = if b == 0 then (a, 1, 0) else (ret, y, x - a `div` b * y) where (ret, x, y) = exgcd b (a `mod` b)\npmod x y = ((x `mod` y) + y) `mod` y\n\n-- Bezout's Lemma -- min. ax+b s.t. ax+b = cy+d, x, y >= 0\nbezout a b c d | r /= 0 = -1\n | otherwise = until (>= d) (+ (a * p)) (b + a * ((x * q) `pmod` p)) where\n p = c `div` g\n (q, r) = (d - b) `divMod` g\n (g, x, y) = exgcd a c\n\nmain = do\n [n, m, x, y, vx, vy] <- fmap (map read . words) getLine\n let f x y 0 vy | x == 0 || x == n = [x, if vy > 0 then m else 0] | otherwise = [-1, -1]\n f x y vx 0 | y == 0 || y == m = [if vx > 0 then n else 0, y] | otherwise = [-1, -1]\n f x y (-1) vy = let [a, b] = f (n - x) y 1 vy in if a == -1 then [a, b] else [n - a, b]\n f x y vx (-1) = let [a, b] = f x (m - y) vx 1 in if a == -1 then [a, b] else [a, m - b]\n f x (-1) 1 1 | k == -1 = [-1, -1] | otherwise = [if odd p then n else 0, if odd q then 0 else m]\n where (k, p, q) = (bezout m x n 0, k `div` n, (k - x) `div` m)\n f x y 1 1 = f (x + m - y) (-1) 1 1\n r = f x y vx vy\n putStrLn $ if head r == -1 then \"-1\" else unwords . map show $ r\n", "src_uid": "6c4ddc688c5aab1432e7328d27c4d8ee"} {"source_code": "import Data.List\nimport qualified Data.Map.Strict as Map\n\ntoint s = (read s) :: Int\n\ndoit x [] = (-1,-1)\ndoit x ((a,b):xs) =\n if (mod a b == 0) && (a*b > x) && (div a b < x) then\n (a,b)\n else\n doit x xs\n\nsolve::String -> String\nsolve ss =\n let x:_ = map toint $ words ss in\n let (a,b) = doit x $ zip [1..x] [1..x] in\n if a <= 0 then\n \"-1\\n\"\n else\n show(a)++\" \"++show(b)++\"\\n\"\n\nmain = do\n interact $ solve", "src_uid": "883f67177474d23d7a320d9dbfa70dd3"} {"source_code": "import Data.List\n\nmain = do\n input <- getLine\n putStrLn $ solve $ input\n\nsolve x \n | p == 0 = \"YES\"\n | (l `mod` p) == 0 = \"YES\"\n | otherwise = \"NO\"\n where\n l = length $ filter (== '-') x\n p = length $ filter (== 'o') x\n", "src_uid": "6e006ae3df3bcd24755358a5f584ec03"} {"source_code": "module Main where\n\nimport Control.Monad\nimport Data.List (minimumBy)\nimport Data.Function (on)\n\ndata Activity = Sport | Contest | Rest\n deriving (Show, Eq)\n\ntype Candidate = (Activity, Int)\n\ngoodFor :: Activity -> Candidate -> Bool\ngoodFor Sport (Sport, _) = False\ngoodFor Contest (Contest, _) = False\ngoodFor _ _ = True\n\nmkCandidate :: [Candidate] -> Activity -> Candidate\nmkCandidate cs a | a == Rest = (a, d + 1)\n | otherwise = (a, d)\n where d = minimum . map snd $ filter (goodFor a) cs\n\nsolve :: [Int] -> Int\nsolve = go [(Rest, 0)] . reverse\n where go :: [Candidate] -> [Int] -> Int\n go cs [] = minimum $ map snd cs\n go cs (a:as) = case a of\n 0 -> go (map (mkCandidate cs) [Rest]) as\n 1 -> go (map (mkCandidate cs) [Rest, Contest]) as\n 2 -> go (map (mkCandidate cs) [Rest, Sport]) as\n 3 -> go (map (mkCandidate cs) [Rest, Sport, Contest]) as\n\ntest0 = [1, 3, 2, 0] :: [Int]\ntest1 = [1, 3, 3, 2, 1, 2, 3] :: [Int]\ntest2 = [2, 2] :: [Int]\n\nmain :: IO ()\nmain = do\n _ <- getLine\n as <- liftM (map read . words) getLine\n print $ solve as\n", "src_uid": "08f1ba79ced688958695a7cfcfdda035"} {"source_code": "import Control.Applicative\nimport Data.Int\n\nmain = do\n [n, m, k] <- readLs\n putStrLn . unwords . map show $ solve n m k\n\nreadLs = map read . words <$> getLine\n\nsolve :: Int64 -> Int64 -> Int64 -> [Int64]\nsolve n _ k | k < n = [k+1, 1]\nsolve n m k = [n-d1, if even d1 then 2+d2 else m-d2 ]\n where d1 = div (k-n) (m-1)\n d2 = mod (k-n) (m-1)", "src_uid": "e88bb7621c7124c54e75109a00f96301"} {"source_code": "main = do\n input <- getLine\n putStrLn $ (show . wave . readNumbers) input\n\nreadNumbers :: String -> [Int]\nreadNumbers = map read . words\n \nwave :: [Int] -> Int\nwave [n, k, t]\n | t<=k = t\n | t<=n = k\n | otherwise = k-(t-n)\n", "src_uid": "7e614526109a2052bfe7934381e7f6c2"} {"source_code": "wordsWhen :: (Char -> Bool) -> String -> [String]\nwordsWhen p s = case dropWhile p s of\n \"\" -> []\n s' -> w : wordsWhen p s''\n where (w, s'') = break p s' \n\nmain = interact $ f . last . words\n\ng [] condi temp lstpar lstopar = (lstpar, lstopar)\ng ('(':xs) condi temp lstpar lstopar = g xs True [] (temp:lstpar) ('_':lstopar)\ng (')':xs) condi temp lstpar lstopar= g xs False [] (temp:lstpar) lstopar\ng (x:xs) condi temp lstpar lstopar\n | condi = g xs condi (x:temp) lstpar lstopar\n | otherwise = g xs condi temp lstpar (x:lstopar)\n\nf x = (show (fun1 b)) ++ \" \" ++ (show (fun2 a 0))\n where i = g x False \"\" [] []\n a = fst i\n b = snd i\n\nsanmaximum x\n | x == [] = 0\n | otherwise = maximum x\n\nfun1 a = (sanmaximum (map length (wordsWhen (=='_') a)))\n\nfun2 [] ans = ans\nfun2 (b:xs) ans = fun2 xs (ans + (length (filter (/=\"\") (wordsWhen (=='_') b))))\n", "src_uid": "fc86df4931e787fa3a1a40e2aecf0b92"} {"source_code": "import List\nimport Char\nisMore ::[Int] -> [Int] -> Bool\nisMore [] [] = True\nisMore (x:xs) (y:ys) | x < y = isMore xs ys\n | otherwise = False\ngetAns::[Int] -> String\ngetAns a | isMore (sort (take l2 a)) (sort (drop l2 a)) = \"YES\"\n | isMore (sort (drop l2 a)) (sort (take l2 a)) = \"YES\"\n | otherwise = \"NO\"\n\t where l2 = (length a) `div` 2\nmain=interact$getAns.(map digitToInt).last.words", "src_uid": "e4419bca9d605dbd63f7884377e28769"} {"source_code": "#!/usr/bin/env stack\n{- stack\n --resolver lts-2.22\n runghc\n --package aeson\n --package array\n --package base\n --package bytestring\n --package containers\n --package hashmap\n --package hashtables\n --package lens\n --package logict\n --package mtl\n --package mwc-random\n --package parsec\n --package pipes\n --package vector\n --\n -hide-all-packages\n-}\n{-# LANGUAGE BangPatterns, TupleSections, RankNTypes, ScopedTypeVariables #-}\nmodule Main\n( main\n) where\n\nimport Prelude hiding (interact, lines, unlines, words, unwords,\n sequence, foldr)\nimport Data.ByteString.Char8 (pack, unpack, ByteString, lines, words,\n unlines, unwords, interact, readInt,\n readInteger)\nimport qualified Data.ByteString.Char8 as BS\nimport Data.List (foldl', sort, sortBy, group, groupBy, inits, tails,\n unfoldr)\nimport qualified Data.List as L\nimport qualified Data.IntSet as IS\nimport Data.IntSet (IntSet)\nimport qualified Data.IntMap.Strict as IM\nimport Data.IntMap.Strict (IntMap)\nimport qualified Data.Map.Strict as M\nimport Data.Map.Strict (Map)\nimport qualified Data.Set as S\nimport Data.Set (Set)\nimport qualified Data.Array.IArray as A\nimport Data.Array.IArray ((!), Array, listArray, array)\nimport Data.Maybe (fromJust, isJust, fromMaybe, maybe, mapMaybe,\n catMaybes)\nimport Data.Either (either)\nimport Control.Applicative (Applicative, pure,\n (<$>), (<*>), (<|>), liftA2, liftA3)\nimport Control.Monad (unless, when, void, filterM, ap)\nimport Control.Arrow ((***), (&&&), first, second)\nimport Data.Traversable (sequence, sequenceA, traverse,\n Traversable)\nimport Data.Ord (comparing, Down(..))\nimport Data.Function (on)\nimport Data.Bits (complement, xor, (.|.), (.&.), testBit, zeroBits,\n bit, shiftR, shiftL, Bits)\nimport qualified Data.Bits as B\nimport Data.Word (Word32)\nimport Control.Monad.State (State, get, put, gets, modify,\n evalState, execState, runState)\nimport Text.Parsec (char, space, parse, Parsec)\nimport qualified Text.Parsec as P\nimport Data.Tuple (swap)\nimport Data.Foldable (Foldable, foldr)\nimport Data.Monoid ((<>), Monoid, mappend, mempty)\n\ntype N = Integer\ntoNum = toInte\n\nanswer :: [(N, String)] -> Bool\nanswer = go' 0\n where go 0 (x, \"South\")\n | x <= 20000 = Just x\n | otherwise = Nothing\n go 20000 (x, \"North\")\n | x <= 20000 = Just (20000 - x)\n | otherwise = Nothing\n go 0 (_, dir)\n | dir /= \"South\" = Nothing\n go 20000 (_, dir)\n | dir /= \"North\" = Nothing\n go s (x, \"North\")\n | s >= x = Just (s - x)\n | otherwise = Nothing\n go s (x, \"South\")\n | s + x <= 20000 = Just (s + x)\n | otherwise = Nothing\n go s _ = Just s\n go' 0 [] = True\n go' _ [] = False\n go' s (i:is) = case go s i of\n Just s' -> go' s' is\n Nothing -> False\n\nhandleInput :: ByteString -> ByteString\nhandleInput = lines\n .- coerceInput answer\n .- toOut .- pack\n\ntoOut False = \"NO\"\ntoOut True = \"YES\"\n\ntoInt = readInt .- fromJust .- fst\ntoInte = readInteger .- fromJust .- fst\ntoX :: Read a => ByteString -> a\ntoX = unpack .- read\n\ncoerceInput f (a:xs) = f (take (toInt a) (map (words .- toInst) xs))\ncoerceInput _ _ = error \"invalid input\"\n\ntoInst (a:b:_) = (toNum a, unpack b)\ntoInst _ = error \"invalid instruction\"\n\nmain :: IO ()\nmain = interact handleInput\n\n-- Util stuff --\n(.-) :: (a -> b) -> (b -> c) -> a -> c\n(.-) = flip (.)\ninfixl 9 .-\n", "src_uid": "11ac96a9daa97ae1900f123be921e517"} {"source_code": "1#r=r\nn#r=r+r/sin(pi/n)\ns[n,q,r]|q+1e-5>=n#r=\"YES\"|1>0=\"NO\"\nmain=interact$s.map read.words", "src_uid": "2fedbfccd893cde8f2fab2b5bf6fb6f6"} {"source_code": "\nmain = do\n\tpass<-getLine\n\trest<-getContents\n\tputStrLn $ concat $ map show $ solve (lines rest) pass\n\n\nsolve dict cryptPass = map (replace dict 0) $ divide cryptPass\n\nreplace [] i n = 256\nreplace dict i n = if head dict == n then i else replace (tail dict) (i+1) n \ndivide [] = []\ndivide cryptPass = [take 10 cryptPass]++divide (drop 10 cryptPass)\n", "src_uid": "0f4f7ca388dd1b2192436c67f9ac74d9"} {"source_code": "import Data.List\nmain=interact$show.f 3.reverse.map read.words\nf 0 _=1\nf n(k:x)=(l+1)*f(n-1)(k-l:z)\n where\n y:z=sort x\n l=min(y-1)(div k n)", "src_uid": "8787c5d46d7247d93d806264a8957639"} {"source_code": "module Main where\nimport qualified Data.ByteString.Char8 as B\nimport Data.List\nimport Data.Maybe\n\nreadInt = fst . fromJust . B.readInt\nreadInts = fmap readInt . B.words\n\nsolve p x y = (\\k -> max 0 $ (k + 1) `div` 2) $ fromJust $ find (\\k -> elem (p - 26) $ take 25 $ tail $ iterate (\\i -> (96 * i + 42) `mod` 475) ((x + 50 * k) `div` 50 `mod` 475)) [(y - x + 49) `div` 50..] :: Int\n\nmain = do\n [p, x, y] <- fmap readInts B.getLine\n print $ solve p x y\n", "src_uid": "c9c22e03c70a94a745b451fc79e112fd"} {"source_code": "import Control.Monad\nimport Data.List\nimport Control.Applicative\n\nmaxPossible as m = m + maximum as\nminPossible as m = \n let aMax = maximum as\n as' = delete aMax as\n as'diff = map (aMax-) as'\n in if sum as'diff >= m \n then aMax\n else let extra = m - sum as'diff\n n = length as\n in aMax + extra `div` n + (if extra `rem` n == 0 then 0 else 1) \nmain = do\n let toInt x = read x :: Int\n getInt = getLine >>= return . toInt\n n <- getInt\n m <- getInt\n as <- replicateM n getInt\n putStrLn $ concat $ intersperse \" \" $ map show $ [minPossible,maxPossible] <*> [as] <*> [m]\n", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d"} {"source_code": "module Main where\n\nimport Control.Monad\nimport Data.Int\nimport Data.List\n\nmain = do\n n <- read `liftM` getLine\n\n let n' = ( 2 * combine (2*n-1) n - n ) `mod` modulo\n\n putStrLn $ show n'\n\n\nmodulo = 1000000007\n\nmul a b = a * b `mod` modulo\n\ncombine a b =\n foldl' (\\c n -> c `mul` inverse n) (foldl' (\\c n -> c `mul` n) 1 [b+1..a]) [2..a-b]\n\ninverse n =\n let (^^^) :: Integral a => Int64 -> a -> Int64\n a ^^^ 0 = 1\n a ^^^ b =\n let b' = b `div` 2\n a' = a ^^^ b'\n a'' = a' `mul` a' in\n if b `mod` 2 == 0\n then a''\n else a'' `mul` a\n in fromIntegral $ fromIntegral n ^^^ (modulo-2)\n", "src_uid": "13a9ffe5acaa79d97df88a069fc520b9"} {"source_code": "import Data.Char (digitToInt)\nimport Data.List ((\\\\), minimumBy, nub, sort)\nimport Data.Monoid (mconcat)\n\ntype Team = String\ntype Score = (Int, Int)\ndata Game = Game Team Team Score\ndata Stat = Stat Team Int Int Int\n deriving (Show, Eq)\n\ninstance Ord Stat where\n compare (Stat t1 s1 d1 g1) (Stat t2 s2 d2 g2) = mconcat [compare s1 s2, compare d1 d2, compare g1 g2, compare t2 t1]\n\ngetTeams = nub . concatMap (\\(Game a b _) -> [a, b])\n\ncountStats games = let getScore x y | x > y = 3\n | x == y = 1\n | otherwise = 0\n countStat stat@(Stat team score diff goal) (Game t1 t2 (x, y)) | team == t1 = Stat team (score + (getScore x y)) (diff + x - y) (goal + x)\n | team == t2 = Stat team (score + (getScore y x)) (diff + y - x) (goal + y)\n | otherwise = stat\n in reverse $ sort $ map (\\team -> foldl countStat (Stat team 0 0 0) games) $ getTeams games\n\ncheckWin games = let ((Stat first _ _ _):(Stat second _ _ _):_) = countStats games\n in first == \"BERLAND\" || second == \"BERLAND\"\n\nmain = do\n games <- fmap (map readGame . lines) getContents\n let teams = getTeams games\n let opponent = head $ teams \\\\ (getTeams $ filter (\\(Game a b _) -> a == \"BERLAND\" || b == \"BERLAND\") games)\n let goodScores = filter (checkWin . flip (:) games . Game \"BERLAND\" opponent) [(x, y) | x <- [1..100], y <- [0..x-1]]\n case goodScores of\n [] -> putStr \"IMPOSSIBLE\"\n _ -> printAnswer $ minimumBy compareAnswers goodScores\n where\n readGame s = let [a, b, x:':':y:\"\"] = words s\n in Game a b (digitToInt x, digitToInt y)\n compareAnswers (x1, y1) (x2, y2) = if (x1 - y1) == (x2 - y2)\n then compare y1 y2\n else compare (x1 - y1) (x2 - y2)\n printAnswer (x, y) = putStr (show x) >> putStr \":\" >> putStr (show y)\n", "src_uid": "5033d51c67b7ae0b1a2d9fd292fdced1"} {"source_code": "-- 2019-10-30 01:49:09.502708352 UTC\nimport Data.Maybe\nimport Control.Monad\nimport Text.Read\nnat_para :: Integral i => i -> a -> (i -> a -> a) -> a\nnat_para i x f = np (abs i)\n where np 0 = x\n np i = let i' = i - 1\n in f i' (np i')\nhd :: [a] -> Maybe a\nhd ([]) = Nothing\nhd (x : _) = Just x\ntl = drop 1\nnat_cata :: Integral i => i -> a -> (a -> a) -> a\nnat_cata i x f = nc (abs i)\n where nc 0 = x\n nc i = f (nc (i - 1))\niF :: Bool -> a -> a -> a\niF (True) t f = t\niF (False) t f = f\nlist_para :: [b] -> a -> (b -> [b] -> a -> a) -> a\nlist_para ([]) x f = x\nlist_para (y : ys) x f = f y ys (list_para ys x f)\nmagiciF :: Bool -> String\nmagiciF b = if b then \"EASY\" else \"HARD\"\nuncurry' f (a, b, c) = f a b c\nparser :: String -> (Int, Int, Int)\nparser = fromJust . parse2Input\nparse2Input :: String -> Maybe (Int, Int, Int)\nparse2Input i = do {when (length (lines i) /= 1) Nothing;\n ns <- mapM readMaybe $ words i :: Maybe ([Int]);\n when (length ns /= 3) Nothing;\n let {[a, b, c] = ns};\n return (a, b, c)}\nsolve = \\a b c -> iF ((c >= a) && (b >= a)) \"Yes\" \"No\"\nmain = getContents >>= (\\c -> putStrLn (uncurry' solve (parser c)))", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4"} {"source_code": "\nimport Data.List\n\nsolve :: String -> String\nsolve s\n | null $ intersect s \"HQ9\" = \"NO\"\n | otherwise = \"YES\" \n\nmain :: IO ()\nmain = interact solve", "src_uid": "1baf894c1c7d5aeea01129c7900d3c12"} {"source_code": "countLetters :: String -> Char -> Int\ncountLetters str c = length $ filter (== c) str\n\nmain :: IO ()\nmain = do\n input_str <- getLine\n -- let input_str = \"nmehhjrhirniitshjtrrtitsjsntjhrstjehhhrrerhemehjeermhmhjejjesnhsiirheijjrnrjmminneeehtm\"\n -- let input_str = \"ihimeitimrmhriemsjhrtjtijtesmhemnmmrsetmjttthtjhnnmirtimne\"\n -- print input_str\n let n = countLetters input_str 'n'\n let e = countLetters input_str 'e'\n let i = countLetters input_str 'i'\n let t = countLetters input_str 't'\n\n -- print n\n -- print e\n -- print i\n -- print t\n\n let z = if div (n-1) 2 < 0 then 0 else div (n-1) 2\n\n let ncount = min ( min ( min z (div e 3) ) i ) t\n print ncount\n -- print min ( min ( min ( n `mod` 3 ) ( e `mod` 3 ) i ) t )\n", "src_uid": "bb433cdb8299afcf46cb2797cbfbf724"} {"source_code": "import Control.Applicative\nimport Data.List\n \n\n\nmain = do\n\t[n,d]<- map read.words <$> getLine ::IO [Int]\n\ta<- map read.words <$> getLine ::IO [Int]\n\tm<- read <$> getLine ::IO Int\n\tprint $ if m < n then sum(take m ( sort a)) else (sum a) - d*(m-n)\n\t\n\t\n\t ", "src_uid": "5c21e2dd658825580522af525142397d"} {"source_code": "fastpow :: Integer -> Integer\r\nfastpow 0 = 1\r\nfastpow timer = (((fastpow (timer - 1) * 4) `mod` 1000000007) ^ 2) `mod` 1000000007\r\n\r\nmain = do\r\n entry <- getContents\r\n let n = read (head . lines $ entry) :: Integer\r\n let ans = (fastpow (n - 1) * 6) `mod` 1000000007\r\n print(ans)", "src_uid": "5144b9b281ea4087d8334d91c3c8bda4"} {"source_code": "import Control.Applicative\nimport Data.List\nimport Data.Array\n\nproc1 n ((a,b),c) | a==1 && b==n = ((a,b),c)\n | a==1 = ((a,b+1),c+1)\n | b==n = ((a-1,b),c+1)\n |otherwise = ((a-1,b+1),c+2)\n\n\n--map proc2 $ map (proc1 n ) e\nprocess::Int->[Int]->Int\nprocess n ss = (sum ss) + snd e\n where d = array ((1,1),(n,n)) $ [((i,j),-1)| i<-[1..n],j<-[1..(i-1)]] ++ [((i,i),s!!(i-1))| i<-[1..n]] ++ [((i,j), d!(i,j-1)+s!!(j-1))|i<-[1..n],j<-[(i+1)..n]]\n s = map (\\z-> if z==1 then -1 else 1) ss\n m = maximum $ elems d\n e= head $ filter (\\z-> snd z ==m) $ assocs d\n\n\n\n\n\n\n\nmain=do\n n<- read <$> getLine ::IO Int\n s<-map read <$> words<$> getLine ::IO [Int]\n print $ process n s\n", "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99"} {"source_code": "import Data.Char\nimport Data.List\nmain=getLine>>getLine>>=putStrLn.solve\nsolve c|n==26=\"YES\"|otherwise=\"NO\"where n=length$nub$map toLower c\n", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d"} {"source_code": "import Control.Applicative\nimport Control.Monad\nimport Data.List\nimport Data.Maybe\nimport Data.Array\n\n\n\n\nmain = do\n\t\t[n,a]<-map read <$> words <$> getLine ::IO [Int]\n\t\tlet x = mod n a\n\t\tlet y = div n a\n\t\tputStrLn $ intercalate \" \" $ map show $ (replicate x (y+1)) ++ (replicate (a-x) y)\n\n", "src_uid": "0b2c1650979a9931e00ffe32a70e3c23"} {"source_code": "main = do\n input <- getLine\n let list = map read (words input) :: [Int]\n a = list !! 0\n b = list !! 1\n putStrLn (if abs (a - b) > 1 || (a == 0 && b == 0) then \"NO\" else \"YES\")\n\n", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037"} {"source_code": "{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -funfolding-use-threshold=16 -fexcess-precision -funbox-strict-fields #-}\nmodule Main where\nimport qualified Data.ByteString.Lazy.Char8 as B\nimport Control.Monad\nimport Control.Monad.Trans.State.Lazy\nimport Data.Int\n\nmain = putStr . evalState app . B.words =<< B.getContents \n\napp = (unlines . map show) `fmap` liftM2 solve poi poi\n where\n pop = state $ \\(x:xs) -> (x, xs)\n poi = fmap int pop\n int = maybe undefined (to64 . fst) . B.readInt\n\nto64 x = fromIntegral x :: Int64 \n\nsolve n k = map (min (n - k)) [if k == 0 then 0 else 1, 2 * k]\n", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86"} {"source_code": "main = do\n getLine\n s <- getLine\n print $ maximum $ map length $ map (filter (\\c -> 'A' <= c && c <= 'Z')) $ words s", "src_uid": "d3929a9acf1633475ab16f5dfbead13c"} {"source_code": "import Control.Arrow\n\nf p = let n = length p in last $ \"OK\" : [\"BUG\" | i <- [1 .. n - 1], (a, b) <- [p!!i], (c, d) <- take (i - 1) p, abs (a - c) + abs (b - d) <= 1]\n\ng d = case d of\n\t'L' -> id *** pred\n\t'R' -> id *** succ\n\t'U' -> succ *** id\n\t'D' -> pred *** id\n\nmain = do getLine >>= putStrLn . f . scanl (flip g) (0, 0)\n", "src_uid": "bb7805cc9d1cc907b64371b209c564b3"} {"source_code": "f x = ((maximum x) - (minimum x)) `div` 2\n\nmain = do\n s <- getLine\n x <- getLine\n let y = map read $ words x\n putStrLn $ show $ (minimum y) + (f y)", "src_uid": "f03773118cca29ff8d5b4281d39e7c63"} {"source_code": "{-# LANGUAGE FlexibleContexts, ScopedTypeVariables #-}\n{-# OPTIONS_GHC -O2 #-}\n\nimport Control.Applicative\nimport Control.Monad\nimport Control.Monad.ST.Safe\nimport Control.Monad.State\nimport Data.Array.IArray\nimport Data.Array.MArray.Safe\nimport Data.Array.ST.Safe\nimport Data.Array.Unboxed\nimport Data.Array.IO.Safe\nimport Data.Char\nimport Data.Function\n-- import Data.Graph\nimport Data.Int\nimport Data.List\nimport Data.List.Split\nimport Data.Maybe\nimport Data.Set (Set)\nimport qualified Data.Set as Set\n-- import Data.Tree\nimport Data.Tuple\nimport Data.Map (Map)\nimport qualified Data.Map as Map\nimport Data.IntMap (IntMap)\nimport qualified Data.IntMap as IntMap\nimport qualified Data.ByteString.Char8 as B\n-- import Debug.Trace\n\ngetInts = fmap (map read . words) getLine\n-- getInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine\n\nmain = do\n [x, m] <- getInts\n\n let m' = until odd (`div` 2) m\n\n putStrLn $ if x `mod` m' == 0 then \"Yes\" else \"No\"\n", "src_uid": "f726133018e2149ec57e113860ec498a"} {"source_code": "{-# LANGUAGE NPlusKPatterns #-}\nmodule Main where\n\nisBW :: [[Char]] -> Bool\nisBW = all (all (flip elem \"BWG\"))\n\nmessageBW :: Bool -> String\nmessageBW = bool \"#Black&White\" \"#Color\"\n\nbool :: a -> a -> Bool -> a\nbool t _ True = t\nbool _ f False = f\n\nmain :: IO ()\nmain = do\n [n, m] <- getInts\n rows <- iterm n getLetters\n putStrLn $ messageBW $ isBW rows\n\ngetLetters :: IO [Char]\ngetLetters = fmap (concat . words) getLine\n\niterm :: (Functor m, Monad m) => Int -> m a -> m [a]\niterm 0 p = return []\niterm (n + 1) p = p >>= (\\a -> fmap (a:) (iterm n p))\n\ngetInts :: IO [Int]\ngetInts = fmap (map read . words) getLine\n", "src_uid": "19c311c02380f9a73cd477e4fde27454"} {"source_code": "main = readLn >>= putStrLn . solve\n\nsolve 0 = \"1\"\nsolve n\n | n > 36 = \"-1\"\n | odd n = replicate (n `div` 2) '8' ++ \"9\"\n | otherwise = replicate (n `div` 2) '8'\n", "src_uid": "0c9973792c1976c5710f88e3520cda4e"} {"source_code": "import Control.Applicative\nimport Data.Int\n\nmain = do\n m <- (read :: String -> Int64) <$> getLine\n print $ bs m 0 4949100894494448\n \nf :: Int64 -> Int64\nf n = sum [n `div` x ^ 3 | x <- [2..(ceiling $ fromIntegral n ** (1/3))] ]\n\nbs :: Int64 -> Int64 -> Int64 -> Int64\nbs m l r\n | r - l == 1 = if f r == m then r else -1\n | f c < m = bs m c r\n | otherwise = bs m l c\n where c = (l + r) `div` 2\n\n", "src_uid": "602deaad5c66e264997249457d555129"} {"source_code": "import Data.List\nimport Data.Maybe\nimport Data.Char\nimport Data.Function\nmain= readsolveprint \nreadsolveprint::IO()\nreadsolveprint = interact $ solve. map read.words.head. lines\nsolve :: [Integer]->String\nsolve [x,y] = unwords [show fx,show fy] where \n fx = minimum [x,y]\n fy = maximum [abs x-fx,abs y-fx] `div` 2", "src_uid": "775766790e91e539c1cfaa5030e5b955"} {"source_code": "import qualified Data.Map as Map\n\nmain :: IO()\nmain = print . solve . map read . words =<< getLine\n\ndata Queue a = Queue { \n inbox :: [a], \n outbox :: [a] \n} deriving (Eq, Show)\n\ninitQueue :: Queue a\ninitQueue = Queue [] []\n\npush :: a -> Queue a -> Queue a\npush e (Queue inb out) = Queue (e:inb) out\n\npop :: Queue a -> (a, Queue a)\npop q@(Queue inb []) = pop $ Queue [] (reverse inb)\npop (Queue inb outb) = (head outb, Queue inb (tail outb))\n\nisEmptyQueue :: Queue a -> Bool\nisEmptyQueue (Queue inbox outbox) = null inbox && null outbox\n\ninitMap :: Int -> Map.Map (Int, Int) Double\ninitMap n = Map.fromList [((i, j), 0.0) | i <- [1..n], j <- [1..i]]\n\nremoveMaybe :: Maybe Double -> Double\nremoveMaybe (Just x) = x\n\ntryPush :: Int -> (Int, Int) -> Queue (Int, Int) -> Queue (Int, Int)\ntryPush n p@(i, j) q | i > n || j > i = q\n | otherwise = push p q\n\ntryAdjust :: (Double -> Double) -> (Int, Int) -> Map.Map (Int, Int) Double -> Map.Map (Int, Int) Double\ntryAdjust f (i, j) m | Map.member (i, j) m = Map.adjust f (i, j) m\n | otherwise = m\n\nsolve :: [Int] -> Int\nsolve [n, t] = Map.size $ Map.filter (== 1.0) $ dumping (initMap n) t\n where dumping :: Map.Map (Int, Int) Double -> Int -> Map.Map (Int, Int) Double\n dumping m 0 = m\n dumping m t = let nextMap = Map.adjust (+ 1.0) (1, 1) m\n nextQueue = push (1, 1) initQueue\n in dumping (flow nextQueue nextMap) (t - 1)\n\n flow :: Queue (Int, Int) -> Map.Map (Int, Int) Double -> Map.Map (Int, Int) Double\n flow q m | isEmptyQueue q = m\n | otherwise = let ((i, j), nextQueue) = pop q\n volumn = removeMaybe $ Map.lookup (i, j) m\n halfVol = (volumn - 1.0) * 0.5\n in if volumn > 1.0\n then let nextMap1 = Map.adjust (const 1.0) (i, j) m\n nextMap2 = tryAdjust (+ halfVol) (i + 1, j) nextMap1\n nextMap3 = tryAdjust (+ halfVol) (i + 1, j + 1) nextMap2\n nextQueue1 = tryPush n (i + 1, j) nextQueue\n nextQueue2 = tryPush n (i + 1, j + 1) nextQueue1\n in flow nextQueue2 nextMap3\n else flow nextQueue m\n", "src_uid": "b2b49b7f6e3279d435766085958fb69d"} {"source_code": "solve s = s' s 0 0\n where s' (p:ps) x y\n | p == 'U' = s' ps x (y + 1)\n | p == 'D' = s' ps x (y - 1)\n | p == 'R' = s' ps (x + 1) y\n | otherwise = s' ps (x - 1) y\n s' [] x y = (length s) - ((abs x) + (abs y))\n\nmain = do\n getLine\n getLine >>= print.solve", "src_uid": "b9fa2bb8001bd064ede531a5281cfd8a"} {"source_code": "{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances #-}\n{-# OPTIONS_GHC -O2 #-}\n\nimport Data.List\nimport Data.Maybe\nimport Data.Char\nimport Data.Array.IArray\nimport Data.Array.Unboxed (UArray)\nimport Data.Int\nimport Data.Ratio\nimport Data.Bits\nimport Data.Function\nimport Data.Ord\n--import Control.Monad.State\nimport Control.Monad\nimport Control.Applicative\nimport Data.ByteString.Char8 (ByteString)\nimport qualified Data.ByteString.Char8 as BS\nimport Data.Set (Set)\nimport qualified Data.Set as Set\nimport Data.Map (Map)\nimport qualified Data.Map as Map\nimport Data.IntMap (IntMap)\nimport qualified Data.IntMap as IntMap\nimport Data.Sequence (Seq, (<|), (|>), (><), ViewL(..), ViewR(..))\nimport qualified Data.Sequence as Seq\nimport qualified Data.Foldable as F\nimport Data.Graph\n\nparseInput = do \n n1 <- readInt\n n2 <- readInt\n k1 <- readInt\n k2 <- readInt\n return (n1, n2, k1, k2)\n where\n readInt = state $ fromJust . BS.readInt . BS.dropWhile isSpace\n readInteger = state $ fromJust . BS.readInteger . BS.dropWhile isSpace\n readString = state $ BS.span (not . isSpace) . BS.dropWhile isSpace\n readLine = state $ BS.span (not . isEoln) . BS.dropWhile isEoln\n isEoln ch = ch == '\\r' || ch == '\\n'\n\nmain = print =<< solve . evalState parseInput <$> BS.getContents\n\nsolve (n1, n2, k1, k2) = countWays (n1, n2, 0, True) `mod` (10^8)\n where\n countWays :: (Int, Int, Int, Bool) -> Integer\n countWays (_, _, c, True) | c > k1 = 0\n countWays (_, _, c, False) | c > k2 = 0\n countWays (a, b, c, flag) = cache ! (a, b, c, flag)\n where\n bnds = ((0, 0, 0, False), (100, 100, 10, True))\n cache = listArray bnds $ map go $ range bnds :: Array (Int, Int, Int, Bool) Integer\n\n go (0, 0, _, _) = 1\n go (a, b, c, flag) = goA + goB\n where\n goA | a == 0 = 0\n | otherwise = countWays (a - 1, b, c + 1, flag)\n goB | b == 0 = 0\n | otherwise = countWays (b - 1, a, 1, not flag)\n\n----------------------------------------------------------------------\n----------------------------------------------------------------------\n----------------------------------------------------------------------\n\nclass (Monad m) => MonadState s m | m -> s where\n\tget :: m s\n\tput :: s -> m ()\n\nmodify :: (MonadState s m) => (s -> s) -> m ()\nmodify f = do\n\ts <- get\n\tput (f s)\n\ngets :: (MonadState s m) => (s -> a) -> m a\ngets f = do\n\ts <- get\n\treturn (f s)\n\nnewtype State s a = State { runState :: s -> (a, s) }\n\ninstance Functor (State s) where\n\tfmap f m = State $ \\s -> let\n\t\t(a, s') = runState m s\n\t\tin (f a, s')\n\ninstance Applicative (State s) where\n pure = return\n (<*>) = ap\n\ninstance Monad (State s) where\n\treturn a = State $ \\s -> (a, s)\n\tm >>= k = State $ \\s -> let\n\t\t(a, s') = runState m s\n\t\tin runState (k a) s'\n\ninstance MonadState s (State s) where\n\tget = State $ \\s -> (s, s)\n\tput s = State $ \\_ -> ((), s)\n\nevalState :: State s a -> s -> a\nevalState m s = fst (runState m s)\n\nexecState :: State s a -> s -> s\nexecState m s = snd (runState m s)\n\nmapState :: ((a, s) -> (b, s)) -> State s a -> State s b\nmapState f m = State $ f . runState m\n\nwithState :: (s -> s) -> State s a -> State s a\nwithState f m = State $ runState m . f\n\nstate = State\n", "src_uid": "63aabef26fe008e4c6fc9336eb038289"} {"source_code": "import Control.Applicative\nimport Data.List\n\nf a b = case (a,b) of\n ((-1), 1 ) -> 1\n (1, (-1)) -> 1\n (1,1) -> 2\n _ -> 0\n\nmain = do\n [n,a] <- map (read :: String -> Int) . words <$> getLine\n ts <- map (read :: String -> Int) . words <$> getLine\n print $ let \n (b',c) = splitAt a ts \n b = reverse b'\n d = sum $ zipWith f(tail b ++ replicate (length c) (-1)) (c ++ replicate (length b) (-1))\n in d + head b\n", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5"} {"source_code": "import Data.List\n\nmain = do\n _ <- getLine\n roboCoderIdx <- (elemIndices \"1\" . words) <$> getLine :: IO [Int]\n bionicSolverIdx <- (elemIndices \"1\" . words) <$> getLine :: IO [Int]\n putStrLn $ show $ solve roboCoderIdx bionicSolverIdx\n\nsolve :: [Int] -> [Int] -> Int\nsolve roboCoderIdx bionicSolverIdx =\n let distance = length $ bionicSolverIdx \\\\ roboCoderIdx\n superiority = length $ roboCoderIdx \\\\ bionicSolverIdx\n in if superiority == 0 then -1 else distance `div` superiority + 1\n\n", "src_uid": "b62338bff0cbb4df4e5e27e1a3ffaa07"} {"source_code": "import Control.Applicative\nimport Data.List\nimport Data.Maybe\n-- import Debug.Trace\n\n-- debug = flip trace\n\nisPossible :: String -> String -> Bool\nisPossible a b = sortedA <= b\n where sortedA = sort a\n\nsolve' :: String -> String -> String\nsolve' [] [] = []\nsolve' as (b:bs)\n | found == False = hiChar : (reverse . sort $ pre ++ rem) -- `debug` \"not found = \" ++ pre ++ \" \" ++ rem\n | poss == False = hiChar : (reverse . sort $ pre ++ rem) -- `debug` \"not pos = \" ++ pre ++ \" \" ++ rem\n | otherwise = b : (solve' remList bs) -- `debug` \"otherwise = \" ++ pre ++ \" \" ++ rem\n where found = b `elem` as\n hiChar = maximum $ filter (< b) as\n hiPos = fromJust $ findIndex (== hiChar) as\n (pre, suf) = splitAt hiPos as\n rem = tail suf\n pos = fromJust $ elemIndex b as\n (pre', suf') = splitAt pos as\n remList = pre' ++ (tail suf')\n poss = isPossible remList bs\n\nsolve :: String -> String -> String\nsolve a b\n | length a < length b = reverse . sort $ a\n | otherwise = solve' a b\n\nmain :: IO ()\nmain = do\n a <- getLine\n b <- getLine\n putStrLn $ solve a b\n", "src_uid": "bc31a1d4a02a0011eb9f5c754501cd44"} {"source_code": "import Data.Ratio\n\nsolve :: Int -> Ratio Int\nsolve x = (6 - x + 1) % 6\n\nmain = do\n toBeat <- maximum <$> fmap read <$> words <$> getLine\n let ans = solve toBeat\n putStrLn $ mconcat [(show $ numerator ans), \"/\", (show $ denominator ans)]\n", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414"} {"source_code": "import Debug.Trace\n\ntype Input = (Int, [Int], [Int])\ntype Output = Maybe (Int, Int)\n\nmain :: IO ()\nmain = putStrLn . format . solve . parse =<< getContents\n\nparse :: String -> Input\nparse content =\n let [n, a, b] = lines content\n readLine = map read . tail . words\n in (read n, readLine a, readLine b)\n\ndata Queue = Queue ([Int], [Int])\n\ninstance Show Queue where\n show (Queue (a, b)) = show (a ++ [0] ++ (reverse b))\n\nempty :: Queue -> Bool\nempty (Queue ([], _)) = True\nempty otherwise = False\n\nbalance :: ([Int], [Int]) -> Queue\nbalance ([], c) =\n let n = length c\n (a, b) = splitAt (n `div` 2) c\n in Queue (reverse b, a)\nbalance queue = Queue queue\n\npush :: Queue -> Int -> Queue\npush (Queue (a, b)) k = balance (a, k : b)\n\npop :: Queue -> (Int, Queue)\npop (Queue (a : as, b)) = (a, balance (as, b))\n\nfromList :: [Int] -> Queue\nfromList a = Queue (a, [])\n\nsolve :: Input -> Output\nsolve (n, a, b) =\n let bound = (product [1..n])\n simulate step a b\n | step > bound = Nothing\n | empty a = Just (step, 2)\n | empty b = Just (step, 1)\n | otherwise =\n let (x, as) = pop a\n (y, bs) = pop b\n in if x > y\n then simulate (step + 1) (as `push` y `push` x) bs\n else simulate (step + 1) as (bs `push` x `push` y)\n in simulate 0 (fromList a) (fromList b)\n\nformat :: Output -> String\nformat Nothing = \"-1\"\nformat (Just (a, b)) = unwords . map show $ [a, b]\n", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e"} {"source_code": "import Control.Monad;\nimport Control.Applicative;\n\nsimplify a b = show (a' `div` k) ++ \"/\" ++ show (b `div` k)\n where k = gcd a' b\n a' = max 0 (min a b)\n\nsolve t w b = simplify ((t `div` lcm) * n + min n (rest + 1) - 1) t\n where lcm = (w * b) `div` gcd w b\n rest = t `mod` lcm\n n = min w b\n\nmain = do\n [t, w, b] <- ((map (read) . words) <$> getLine) :: IO [Integer]\n putStrLn(solve t w b)", "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5"} {"source_code": "f a o b | a == 0 && o < b = [] | otherwise = (a + (o `div` b)):(f ((a + (o `div` b)) `div` b) (o `mod` b + (a + (o `div` b)) `mod` b) b)\nmain = do \n\tstr <- getLine\n\tlet [frs, scn] = words str\n\tprint . sum $ f (read frs) 0 (read scn)\t", "src_uid": "a349094584d3fdc6b61e39bffe96dece"} {"source_code": "import Data.List\nimport Data.Maybe\nmain= readsolveprint\nreadsolveprint::IO()\nreadsolveprint = interact $ show.solve . map read.take (5) . lines\nsolve :: [Int]->Int\nsolve [a,b,c,d,e] =sum [y| x<-[1..e], let y=if x `mod` a ==0|| x `mod` b ==0||x `mod` c ==0 ||x `mod` d ==0 then 1 else 0 ]", "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7"} {"source_code": "{- This code was written by\nRussell Emerine - linguist,\nmathematician, coder,\nmusician, and metalhead. -}\nimport Control.Monad\nimport Data.List\nimport Data.Ord\n\nmain = getLine >>= flip replicateM_ test . read\n\ntest = do\n n <- read <$> getLine\n let divisors = [id, (n `div`)] <*> filter ((== 0) . (n `mod`)) [1 .. ceiling $ sqrt $ fromIntegral n]\n (\\(a, b) -> putStrLn $ show a ++ \" \" ++ show b) $ minimumBy (comparing $ uncurry lcm) [(d, n - d) | d <- divisors, d /= n]\n", "src_uid": "3fd60db24b1873e906d6dee9c2508ac5"} {"source_code": "main :: IO()\nmain = putStrLn . unwords . map show . solve 1 . map read . words =<< getContents\n\nsolve :: Int -> [Int] -> [Int]\nsolve i (n:p) | null p = [-1]\n | otherwise = let ([a, b, c, d], ps) = splitAt 4 p\n m1 = min a b\n m2 = min c d\n in if m1 + m2 <= n\n then [i, m1, n - m1]\n else solve (i + 1) (n:ps)\n", "src_uid": "6e7ee0da980beb99ca49a5ddd04089a5"} {"source_code": "{-# LANGUAGE FlexibleContexts, ScopedTypeVariables, BangPatterns, OverloadedStrings #-}\n{-# OPTIONS_GHC -O2 #-}\n\nimport Control.Applicative\nimport Control.Monad hiding ((<$!>))\nimport Control.Monad.ST.Safe\n-- import Control.Monad.State hiding ((<$!>))\n-- import Data.Array\nimport Data.Array.IArray\nimport Data.Array.IO.Safe\nimport Data.Array.MArray.Safe\nimport Data.Array.ST.Safe\nimport Data.Array.Unboxed\nimport qualified Data.ByteString.Char8 as B\nimport qualified Data.ByteString.Lazy.Builder as BB\nimport Data.Char\nimport qualified Data.Foldable as F\nimport Data.Function\n-- import Data.Graph\nimport Data.Int\nimport Data.List\n-- import Data.List.Split\nimport Data.Maybe\nimport Data.Monoid\nimport Data.Ord\nimport Data.Ratio\nimport qualified Data.Sequence as Seq\nimport Data.Sequence (Seq)\nimport Data.Set (Set)\nimport qualified Data.Set as Set\nimport Data.IntSet (IntSet)\nimport qualified Data.IntSet as IntSet\n-- import Data.Tree\nimport Data.Tuple\nimport Data.Map.Strict (Map)\nimport qualified Data.Map.Strict as Map\n-- import Data.HashMap.Strict (HashMap)\n-- import qualified Data.HashMap.Strict as HashMap\nimport Data.IntMap (IntMap)\nimport qualified Data.IntMap as IntMap\n-- import Debug.Trace\nimport System.IO\n\n-- getInts = fmap (map read . words) getLine\ngetInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine\n\nmain = do\n let\n read = do\n a <- getLine\n b <- getLine\n return $ filter (/= 'X') $ a ++ reverse b\n\n a <- read\n b <- read\n\n let\n rotate s = tail s ++ [head s]\n\n as = take 3 $ iterate rotate a\n\n\n putStrLn $ if b `elem` as then \"YES\" else \"NO\"\n\n\n", "src_uid": "46f051f58d626587a5ec449c27407771"} {"source_code": "import Control.Monad\nmain = do\n a <- liftM read getLine\n putStrLn $ show $ (1 + a*(a+1)*3)", "src_uid": "c046895a90f2e1381a7c1867020453bd"} {"source_code": "module Main (main) where\n\nimport Control.Monad\nimport Control.Applicative\n\n\nsolve :: Int -> Int -> Int\nsolve 0 _ = 0\nsolve n k = go n k 0 0\n where\n go _ 0 _ c = c\n go 0 _ d _ = d - 1\n go n k d c =\n let (q, r) = n `quotRem` 10 in\n if r == 0 then go q (k-1) (d+1) c\n else go q k (d+1) (c+1)\n\n\nmain :: IO ()\nmain = do\n [n, k] <- map read . words <$> getLine\n print (solve n k)\n", "src_uid": "7a8890417aa48c2b93b559ca118853f9"} {"source_code": "import Prelude\nimport List\nimport Char\nimport Data.Ord\nimport Data.List\n\nmain = interact q\n\nq = func.lines\n\nfunc::[[Char]]->String\nfunc = solve.map f'\n where\n f'::[Char]->(Char,Char)\n f' (a:b:c:[]) | b == '>' = (a,c)\n | b == '<' = (c,a)\n\ntoInt::String->Int\ntoInt = read\ntoString::Int->String\ntoString=show\n\nsolve::[(Char,Char)]->String\nsolve a | length a' == 2 && b = reverse ((fst$head$head a'):(fst$head$(!!) a' 1):(snd$head$(!!) a' 1):[])\n | otherwise = \"Impossible\"\n where\n a' = reverse$sortBy (\\a b->compare (length a) (length b))$groupBy (\\(a,_) (b,_) -> a == b) $ sortBy (\\(a,_) (b,_) -> compare a b) a\n b = ((fst$head$head a') /= (fst$head$(!!) a' 1)) && ((fst$head$head a') /= (snd$head$(!!) a' 1))", "src_uid": "97fd9123d0fb511da165b900afbde5dc"} {"source_code": "main = (print . solve) =<< readLn\n\nsolve :: Integer -> Integer\nsolve n = go 1 n cs\n where cs = 2 : takeWhile ((n >=) . (^ 2)) [3, 5..]\n go acc 1 _ = acc\n go acc x [] = acc * x\n go acc x (p:ps) | x `mod` p == 0 = go (acc * p) (x `divs` p) ps\n go acc x (_:ps) = go acc x ps\n\ndivs x y | x `mod` y == 0 = (x `div` y) `divs` y\ndivs x _ = x\n", "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92"} {"source_code": "main = interact $ show . solve . map read . words\nsolve [n,k] = sum [f 2,f 5,f 8] where\n f i = (i*n+k-1) `div` k\n", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39"} {"source_code": "getInt = read `fmap` getLine :: IO Integer\ngetInts = (map read . words) `fmap` getLine :: IO [Integer]\n\nmain = do\n ary@[d,k,a,b,t] <- getInts\n print $ solve ary\n\nsolve :: [Integer] -> Integer\nsolve [d,k,a,b,t]\n | d <= k = d*a\n | t + k*a >= k*b = k*a + (d-k)*b\n | otherwise = car_time + f (d - k*m) where\n m = d `div` k\n car_time = (m-1)*t + m*a*k\n f d\n | d == 0 = 0\n | otherwise = min (d*a + t) (d*b)", "src_uid": "359ddf1f1aed9b3256836e5856fe3466"} {"source_code": "{-# LANGUAGE FlexibleContexts #-}\r\n{-# LANGUAGE TupleSections #-}\r\n{-# OPTIONS_GHC -XStrict -XStrictData #-}\r\nimport qualified Data.ByteString.Char8 as BS\r\nimport Control.Monad\r\nimport Control.Monad.ST\r\nimport Data.Array.Base\r\nimport Data.Array.ST\r\nimport Data.Array.Unboxed\r\nimport Data.Bifunctor\r\nimport Data.Bits\r\nimport Data.Bool\r\nimport Data.Char\r\nimport Data.Int\r\nimport Data.IORef\r\nimport Data.List\r\nimport Data.Maybe\r\nimport Data.Ord\r\nimport Data.Ratio\r\nimport Data.Tuple\r\nimport qualified Data.IntSet as IS\r\nimport qualified Data.Set as Set\r\nimport qualified Data.Sequence as Seq\r\nimport Data.STRef.Strict\r\nimport System.IO\r\nimport System.IO.Unsafe\r\n\r\n(><) a b = a Seq.>< b\r\n\r\ndeb name s e = seq s unsafePerformIO $! do\r\n hPutStrLn stderr $ \" \" ++ name ++ \" = \" ++ show s\r\n return e\r\n\r\nparseInt = fst . fromJust . BS.readInt\r\nparseInteger = fst . fromJust . BS.readInteger\r\n\r\nmodifyArray f a i = readArray a i >>= \\v -> writeArray a i (f v)\r\n\r\nmdRef = unsafePerformIO $ newIORef 0\r\n\r\nsetMod = writeIORef mdRef\r\n\r\nmd :: Int64\r\nmd = unsafePerformIO (readIORef mdRef)\r\n\r\nnewtype MInt = MInt Int64 deriving Eq\r\n\r\ninstance Show MInt where\r\n show (MInt a) = show a\r\n\r\ninstance Num MInt where\r\n (MInt a) + (MInt b) =\r\n let r = a + b in\r\n MInt $ if r >= md then r - md else r\r\n (MInt a) * (MInt b) = MInt $ (a * b) `mod` md\r\n abs = id\r\n signum (MInt a) = MInt $ signum a\r\n fromInteger a = MInt $ fromInteger (a `mod` fromIntegral md)\r\n negate (MInt 0) = 0\r\n negate (MInt a) = MInt $ md - a\r\n\r\ninstance Fractional MInt where\r\n recip a = a ^ (md - 2)\r\n fromRational x =\r\n let a = numerator x `mod` fromIntegral md\r\n b = denominator x `mod` fromIntegral md\r\n in\r\n MInt (fromInteger a) / MInt (fromInteger b)\r\n\r\nmain = do\r\n [n,md'] <- map parseInt . BS.words <$> BS.getLine\r\n setMod (fromIntegral md')\r\n let makeMInt = MInt md\r\n c = runSTArray $ do\r\n c <- newArray ((0,0),(n,n)) 0 :: ST s (STArray s (Int,Int) MInt)\r\n forM_ [0..n] $ \\i -> do\r\n writeArray c (i,0) 1\r\n writeArray c (i,i) 1\r\n forM_ [1..i-1] $ \\j -> do\r\n a <- readArray c (i-1,j-1)\r\n b <- readArray c (i-1,j)\r\n writeArray c (i,j) (a+b)\r\n return c\r\n p2 = listArray (0,n) $ map (2^) [0..n] :: Array Int MInt\r\n let f = runSTArray $ do\r\n f <- newArray ((0,0),(n,n)) 0 :: ST s (STArray s (Int,Int) MInt)\r\n\r\n writeArray f (0,0) 1\r\n writeArray f (1,0) 1\r\n forM_ [2..n] $ \\i -> do\r\n writeArray f (i,0) (p2 ! (i-1))\r\n forM_ [1..i `div` 2] $ \\j -> do\r\n r <- sum <$> forM [1..i-2] (\\k -> do\r\n let v1 = p2 ! (k-1)\r\n v2 <- readArray f (i-k-1,j-1)\r\n let v3 = c ! (i-j,k)\r\n return $ v1 * v2 * v3)\r\n writeArray f (i,j) r\r\n return f\r\n let r = sum [f ! (n,i) | i <- [0..n]]\r\n print r\r\n", "src_uid": "4f0e0d1deef0761a46b64de3eb98e774"} {"source_code": "{-# LANGUAGE BlockArguments #-}\n\nimport Control.Arrow\nimport Data.List\n\nmain = do { x <- getLine; putStrLn $ (read >>> solve) x }\n\nsolve :: Integer -> String\nsolve x | x `mod` 2 == 1 = \"Ehab\"\n | x `mod` 2 == 0 = \"Mahmoud\"", "src_uid": "5e74750f44142624e6da41d4b35beb9a"} {"source_code": "import Control.Monad\nimport Control.Applicative\nimport Data.List\n \nmain = do ts <- map read . words <$> getLine\n print $ solve ts\n\nsolve ts = minimum $ map (\\t -> calc t ts) ts\n\ncount _ [] = 0 \ncount x (l:ls)\n | x == l = 1 + count x ls\n | otherwise = count x ls\n\ncalc t ts = if 2 <= count t ts\n then foldl (+) 0 ts - t * min 3 (count t ts)\n else foldl (+) 0 ts\n \n", "src_uid": "a9c17ce5fd5f39ffd70917127ce3408a"} {"source_code": "import Data.List\n\nmain = do\n _ <- getLine\n inp <- fmap (map read . words) getLine\n x <- fmap (map read . words) getLine\n putStrLn $ solve inp x\n \n\nsolve :: [Int] -> [Int] -> String\nsolve inp x = if not (sort res' == res') then \"Yes\" else \"No\"\n where\n res' = res inp (sortBy (flip compare) x)\n res (0:a) (b:bs) = b:res a bs\n res (a:as) bs = a:res as bs\n res [] [] = []\n", "src_uid": "40264e84c041fcfb4f8c0af784df102a"} {"source_code": "main = interact $ show . f . read\nf x = div x 2 - if odd x then x else 0", "src_uid": "689e7876048ee4eb7479e838c981f068"} {"source_code": "solve a b c = \n let items = minimum [a, b `div` 2, c `div` 4]\n in items * 7\n\nmain :: IO ()\nmain = do\n a <- getLine\n b <- getLine\n c <- getLine\n print $ solve (read a) (read b) (read c)\n", "src_uid": "82a4a60eac90765fb62f2a77d2305c01"} {"source_code": "{-# LANGUAGE RankNTypes #-}\n{-# LANGUAGE TypeSynonymInstances #-}\n\nimport Control.Monad\nimport Text.Printf\n\nimport Data.IORef\nimport System.IO.Unsafe\n\nimport Data.List\nimport Data.Ord\nimport Data.Ratio\n\nimport Debug.Trace\n\nsolve = do a <- cin :: IO Integer\n b <- cin\n x <- cin\n y <- cin\n let x' = x `div` (gcd x y)\n y' = y `div` (gcd x y)\n a' = a - a `mod` x'\n b' = b - b `mod` y'\n xs = [(a',a'*y'`div`x'), (b'*x'`div`y',b')]\n return . g (x,y)\n . maximumBy (comparing area) $ filter ((a*b>=).area) xs\n where\n area (x,y) = x*y\n g (x,y) s@(a,b)\n | area s < 1 = (0,0)\n | True = s\n\nmain = solve >>= \\(x,y) -> printf \"%d %d\\n\" x y \n\n\n\nclass Read' a where\n read' :: String -> a\n\ninstance Read' Rational where\n read' = toRational . (read :: String -> Integer)\n\ninstance Read' Integer where\n read' = read\n\ninstance Read' Int where\n read' = read\n\ninstance Read' Double where\n read' = read\n\ninstance Read' Char where\n read' (c:[]) = c\n read' cs = error $ cs ++ \" cannot read' as the type of Char.\"\n\ninstance Read' String where\n read' cs = cs\n\ncin :: forall a. Read' a => IO a\ncin = do (x:xs) <- readIORef input\n writeIORef input xs\n return $ read' x\n\ninput :: IORef [String]\ninput = unsafePerformIO $ getContents >>= newIORef . words\n\n\n\n\n", "src_uid": "97999cd7c6de79a4e39f56a41ff59e7a"} {"source_code": "s :: String -> [Double]\ns str = [hour' * 30 + min * 0.5, min * 6]\n where (pre, suf) = break (== ':') str \n (hour, min) = (read pre, read (tail suf))\n hour' | hour >= 12 = hour - 12 \n | otherwise = hour\n\nmain = interact $ unwords . map show . s ", "src_uid": "175dc0bdb5c9513feb49be6644d0d150"} {"source_code": "main = do\n [a, b] <- fmap (map read . words) getLine :: IO [Integer]\n let nt = a `div` b\n putStrLn $ if odd nt then \"YES\" else \"NO\"", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50"} {"source_code": "\nimport Control.Monad\nimport Data.List\nimport Data.Maybe\n\nimport qualified Data.ByteString.Char8 as B\nreadInt = readLn :: IO Int\nreadInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine\n\nsolve :: Int -> Int -> Int -> String\nsolve n a b = show min ++ \" \" ++ show max\n where min = (n - a) + (sum $ take a $ iterate (*2) 1)\n x = last $ take b $ iterate (*2) 1\n max = (n - b) * x + (sum $ take b $ iterate (*2) 1)\n\nmain :: IO ()\nmain = do\n [n, a, b] <- readInts\n putStrLn $ solve n a b", "src_uid": "ce220726392fb0cacf0ec44a7490084a"} {"source_code": "import Data.Char\nimport Control.Applicative\n\nmain = do [a,b] <- map read . words <$> getLine\n print $ solve a b\n\nsolve :: Int -> Int -> Int\nsolve a b\n | a < b = b\n | otherwise = head $ filter f [(a+1)..]\n where f c = (b'==) . filter (flip elem [4,7]) . map digitToInt . show $ c\n b' = map digitToInt . show $ b\n", "src_uid": "e5e4ea7a5bf785e059e10407b25d73fb"} {"source_code": "{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -funfolding-use-threshold=16 -fexcess-precision -funbox-strict-fields #-} \nmodule Main where\nimport qualified Data.ByteString.Char8 as B\n\nmain = do\n [l, r] <- fmap readInts B.getLine\n print $ solve l r\n\nsolve l r \n | l == r = l\n | otherwise = 2\n\nreadInt = maybe undefined fst . B.readInt\nreadInts = fmap readInt . B.words", "src_uid": "a8d992ab26a528f0be327c93fb499c15"} {"source_code": "import Control.Applicative\nimport Data.Array\n\n\n \n\n \n\n\nmain= do\n\tn<- read <$>getLine::IO Integer \n\tlet s1 = sum $ map (div n) [2,3,5,7, 30,42,70,105]\n\tlet s2 = sum $ map (div n) [6,10,14,15,21,35,210]\n\tprint $ n-s1+s2\n\t \n\t \n\n\t", "src_uid": "e392be5411ffccc1df50e65ec1f5c589"} {"source_code": "solve [x] = x+15\nsolve (x:y:s) = \n if y-x > 15 then x+15\n else solve (y:s)\nmain = interact $ show . min 90 . solve . (0 :) . map read . tail . words\n", "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27"} {"source_code": "readTokenLine :: Read a => IO [a]\nreadTokenLine = do\n s <- getLine\n return $ read <$> words s\n\nmaybeDiv :: Integral a => a -> a -> Maybe a\nmaybeDiv a b | a `mod` b == 0 = Just $ a `div` b\n | otherwise = Nothing\n\nexGCD :: Integer -> Integer -> (Integer, Integer, Integer)\nexGCD a b | a == 0 = (b, 0, 1)\n | otherwise = (gcd, y - (b `div` a) * x, x)\n where\n (gcd, x, y) = exGCD (b `mod` a) a\n\ndiofantine :: Integer -> Integer -> Integer -> Maybe (Integer, Integer)\ndiofantine a b d = do\n let (gcd, preX, preY) = exGCD a b\n c <- d `maybeDiv` gcd\n let x = preX * c\n y = preY * c\n dx = b `div` gcd\n dy = a `div` gcd\n m = y `div` dy\n return (x + dx * m, y - dy * m)\n\nsolve :: Integer -> Integer -> Integer -> Integer -> [Integer]\nsolve n p w d = case diofantine w d p of\n Nothing -> [-1]\n Just (x, y) -> if x + y > n || x < 0 || y < 0 then [-1] else [x, y, n - x - y]\n\nmain :: IO ()\nmain = do\n [n, p, w, d] <- (readTokenLine :: IO [Integer])\n let result = solve n p w d\n putStrLn . unwords $ show <$> result\n", "src_uid": "503116e144d19eb953954d99c5526a7d"} {"source_code": "primes = sieve [2..]\nsieve (x:xs) = x : sieve (filter (\\i -> i `mod` x /= 0) xs)\n\nmain = do\n n <- readLn\n let ans = filter f [1..n]\n print $ length ans\n\nf n = (length $ filter (\\i -> n`mod`i == 0) $ takeWhile (<=n) primes) == 2\n", "src_uid": "356666366625bc5358bc8b97c8d67bd5"} {"source_code": "import Control.Applicative\nimport Text.Printf\n\nnewtype Fixed = Fixed Double deriving (Read)\n\neps = 1e-9\ninstance Eq Fixed where\n\tFixed a == Fixed b = abs (a - b) < eps\ninstance Ord Fixed where\n\tFixed a <= Fixed b = a <= b + eps\n\ndata Result = Result Fixed Int Int\n\ninstance Eq Result where\n\tResult t1 x1 y1 == Result t2 x2 y2 = t1 == t2 && x1 == x2 && y1 == y2\ninstance Ord Result where\n\tResult t1 x1 y1 <= Result t2 x2 y2 = t1 < t2 || t1 == t2 && x1 + y1 > x2 + y2\n\nmain = do\n\tws <- words <$> getLine\n\tlet [t1, t2, _, _, t0] = map read ws\n\tlet [_, _, x1, x2, _] = map read ws\n\tif t1 == t2\n\tthen\n\t\tprintf \"%d %d\" x1 x2\n\telse\n\t\tlet\n\t\t\trs = (Result (Fixed t2) 0 x2) : [Result (Fixed t) y1 y2 | y1 <- [1..x1],\n\t\t\t\tlet y2 = ceiling $ ((fromIntegral y1)*(t0-t1)) / (t2-t0),\n\t\t\t\ty2 <= x2,\n\t\t\t\tlet t = (t1*(fromIntegral y1) + t2*(fromIntegral y2)) / fromIntegral (y1+y2),\n\t\t\t\tt >= t0]\n\t\t\t(Result _ y1 y2) = minimum rs\n\t\tin\n\t\t \t printf \"%d %d\" y1 y2\n", "src_uid": "87a500829c1935ded3ef6e4e47096b9f"} {"source_code": "--fonk k a = a\nfonk k [] = \"NO\"\nfonk k (s:str) \n |s =='G' || s == 'T'= \"YES\"\n |s =='#' = \"NO\"\n |otherwise = fonk k (drop (k-1) str)\n\nhelper2 k (s:str) = \n if s =='G' || s=='T' \n then fonk k (drop (k-1) str)\n else helper2 k str\n\nhelper (a:b:c:_) = helper2 (read b) c\n--helper (a:b:c:_) = b\nmain = interact $ helper.words\n\n", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41"} {"source_code": "{-# LANGUAGE ScopedTypeVariables #-}\n{-# LANGUAGE BangPatterns #-}\n{-# LANGUAGE Safe #-}\n{-# LANGUAGE TupleSections #-}\n{-# LANGUAGE ExplicitForAll #-}\n{-# LANGUAGE MultiWayIf #-}\n{-# LANGUAGE CPP #-}\n{-# LANGUAGE FlexibleContexts #-}\n{-# LANGUAGE NoMonomorphismRestriction #-}\n\nimport Data.Bits\nimport Data.List\nimport qualified Data.ByteString.Char8 as BS\nimport qualified Data.ByteString.Lazy.Char8 as BSL\nimport Data.IntMap.Strict (IntMap)\nimport qualified Data.IntMap.Strict as IM\nimport Data.IntSet (IntSet)\nimport qualified Data.IntSet as IS\nimport qualified Data.Array.IArray as A\nimport qualified Data.Array.MArray.Safe as A\n-- import qualified Data.Array.MArray as A\nimport Data.Array (Array)\nimport Data.Array.Unboxed (UArray)\nimport Data.Array.IArray (IArray)\nimport Data.Array.MArray.Safe (MArray)\nimport Data.Array.IO.Safe (IOArray, IOUArray)\nimport Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)\n{-\nimport qualified Data.Vector.Unboxed as VU\nimport qualified Data.Vector.Unboxed.Mutable as VUM\n-}\nimport Control.Monad\nimport Control.Monad.ST.Safe\n-- import Control.Monad.ST\nimport Control.Applicative\nimport Data.Maybe\nimport Data.Tuple\nimport Data.Ord\nimport Control.Monad.State.Strict\nimport Data.Int\nimport Data.Word\nimport Data.STRef\nimport Data.IORef\nimport Data.Function\nimport System.IO\nimport System.Exit\n\nmain :: IO ()\nmain = do\n [n,b] <- map readI64 . words <$> getLine\n let factlist = factors b\n pows = map (\\(p,e) -> (`quot` e) $ sum $ takeWhile (> 0)\n $ iterate (`quot` p) (n `quot` p)) factlist\n print $ minimum pows\n\n\nfactors :: Int64 -> [(Int64, Int64)]\nfactors n = go2 n 0\n where\n go2 n !acc | not (testBit n 0) = go2 (n `shiftR` 1) (acc+1)\n | acc == 0 = go n (sqrtInt n) 3\n | otherwise = (2,acc) : go n (sqrtInt n) 3\n go !n !till !p | n == 1 = []\n | p > till = [(n,1)]\n go !n !till !p | r /= 0 = go n till (p+2)\n | otherwise = count q 1\n where\n (q,r) = divMod n p\n count !n1 !acc | r1 /= 0 = (p,acc) : go n1 (sqrtInt n1) (p+2)\n | otherwise = count q1 (acc+1)\n where\n (q1,r1) = divMod n1 p \n\nsqrtInt = ceilI64 . sqrt . toDouble\n\nrInt :: StateT BSL.ByteString Maybe Int\nrInt = StateT $ BSL.readInt . BSL.dropWhile (<'!')\n\n#define D(f,r,d) f::Integral a=>a->d;f=fromIntegral;r::String->d;r=read\n#define C(f,r,g,h,d) D(f,r,d);g,h::RealFrac a=>a->d;g=floor;h=ceiling\nC(_toInteger_,readInteger,floorInteger,ceilInteger,Integer)\nC(toInt,readInt,floorInt,ceilInt,Int)\nC(toI8,readI8,floorI8,ceilI8,Int8)\nC(toI16,readI16,floorI16,ceilI16,Int16)\nC(toI32,readI32,floorI32,ceilI32,Int32)\nC(toI64,readI64,floorI64,ceilI64,Int64)\nC(toWord,readWord,floorWord,ceilWord,Word)\nC(toW8,readW8,floorW8,ceilW8,Word8)\nC(toW16,readW16,floorW16,ceilW16,Word16)\nC(toW32,readW32,floorW32,ceilW32,Word32)\nC(toW64,readW64,floorW64,ceilW64,Word64)\nD(toDouble,readDouble,Double)\nD(toFloat,readFloat,Float)\n#undef D\n#undef C\n\n\n#define N(f,g,a,m)\\\n f :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> e -> m (a i e); f=A.newArray;\\\n g :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> m (a i e); g=A.newArray_\n#define C(a,m)\nN(newIOA,newIOA_,IOArray,IO)\nN(newSTA,newSTA_,STArray s,ST s)\n#undef C\n#define C(a,m) MArray (a) e (m), \nN(newIOUA,newIOUA_,IOUArray,IO)\nN(newSTUA,newSTUA_,STUArray s,ST s)\n#undef C\n#undef N\n\n", "src_uid": "491748694c1a53771be69c212a5e0e25"} {"source_code": "import Data.List (intercalate)\n\ntri = [n * (n + 1) `div` 2 | n <- [1..]] -- sequence of triangular numbers\ntrii = zip [1..] tri -- tri with index\n\nsolve n = [1..(m-1)] ++ [n - sum [1..(m-1)]]\n where\n (m, t) = last $ takeWhile (\\(i, t) -> t <= n) trii\n\ninfixr 2 >>>\n(>>>) a b = b . a\n\nmain =\n getLine >>= (read :: String -> Int) >>> \\n ->\n let result = solve n in\n putStrLn (show (length result)) >>\n putStrLn (intercalate \" \" (map show result))\n", "src_uid": "356a7bcebbbd354c268cddbb5454d5fc"} {"source_code": "import Data.Char\n\nmain = do getLine >>= print . (\\x -> sum (gao x) - if ok x then 1 else 0) . map digitToInt\n\nok [a] = True\nok (a:b:c) = abs (a - b) <= 1 && ok (b:c)\n\ngao [a] = take 10 $ repeat 1\ngao (a:b:c) = [d!!j + if odd (i + b) then d!!(j+1) else 0 | i <- [0 .. 9], j <- [div (i + b) 2]] where\n\td = gao (b:c)\n", "src_uid": "2dd8bb6e8182278d037aa3a59ca3517b"} {"source_code": "main :: IO()\nmain = interact $ show . solve . map read . words\n\nsolve :: [Int] -> Int\nsolve (a:b:c:_:e:_) = (a + b + c) ^ 2 - a ^ 2 - c ^ 2 - e ^ 2\n", "src_uid": "382475475427f0e76c6b4ac6e7a02e21"} {"source_code": "--ghc 7.10\n\nvoteResult :: (Num a, Ord a) => a -> a -> a -> String\nvoteResult x y z\n | x > y && x-y-z > 0 = \"+\"\n | x < y && x-y+z < 0 = \"-\"\n | x == y && z == 0 = \"0\"\n | otherwise = \"?\"\n\nmain = do\n line <- getLine\n let [x,y,z] = map read . words $ line :: [Int]\n putStrLn $ voteResult x y z", "src_uid": "66398694a4a142b4a4e709d059aca0fa"} {"source_code": "-- 846A\n\nimport Data.List (group)\n\nrle = map length . group\n \nmain = getLine >> (interact $ show . program . rle . input)\n where input xs = '0' : filter (\\x -> (x=='0')||(x=='1')) xs ++ \"1\"\n\nprogram xs = maximum [g l r | i <- [1..(length xs)], let (l, r) = splitAt (i-1) xs] - 2\n\nf [] = 0\nf (x:xs) = x + (f (drop 1 xs))\n\ng xs ys = f xs + f (reverse ys)", "src_uid": "c7b1f0b40e310f99936d1c33e4816b95"} {"source_code": "{-# LANGUAGE BangPatterns, ViewPatterns, PatternGuards, ScopedTypeVariables #-}\n\nimport Control.Applicative\nimport Control.Monad\n\nsolve :: Int -> [(Int, Int)] -> Int\nsolve !n ((pages, dayOfWeek) : xs)\n | n - pages <= 0 = dayOfWeek\n | otherwise = solve (n - pages) xs\n\nmain :: IO ()\nmain = do\n n <- readLn\n xs <- map read . words <$> getLine\n print $ solve n $ cycle (zip xs [1 ..])\n\n\n", "src_uid": "007a779d966e2e9219789d6d9da7002c"} {"source_code": "-- Vicfred\n-- https://codeforces.com/problemset/problem/189/A\n\nimport Data.Array\n\nsolve :: Int -> [Int] -> Int\nsolve n ls = memo ! n\n where \n dyn :: Int -> Int\n dyn 0 = 0\n dyn n = 1 + maximum (minBound : [memo ! (n - x) | x <- ls, n-x >= 0])\n memo = listArray (0,n) (map dyn [0..n])\n\nmain :: IO ()\nmain = do\n n:ls <- map read . words <$> getLine :: IO [Int]\n print $ solve n ls\n", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43"} {"source_code": "import Control.Monad\nimport Data.Array\nimport Data.Char\nimport Data.Functor\nimport Data.Int\nimport Data.List\nimport Data.List.Split\nimport Data.Maybe\nimport qualified Data.ByteString.Char8 as B\ngetList :: Read a => IO [a]\ngetList = map (read . B.unpack) . B.words <$> B.getLine\ngetIntList :: IO [Int]\ngetIntList = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine\n\n-- best result only selecting numbers <= i\nsolve :: Integer -> Integer -> Integer\nsolve 1 10 = -1\nsolve n t = base + (t - base `mod` t)\n where base = 10 ^ (n - 1)\n\nmain :: IO ()\nmain = do\n [a, b] <- getIntList\n print $ solve (toInteger a) (toInteger b)\n", "src_uid": "77ffc1e38c32087f98ab5b3cb11cd2ed"} {"source_code": "main :: IO()\nmain = do\n line <- getLine\n let (x1:y1:x2:y2:[]) = map (\\x -> read x :: Integer) $ words line\n xDiff = (x2 - x1 + 2) `div` 2\n yDiff = (y2 - y1 + 2) `div` 2\n xDiff2 = xDiff - 1\n yDiff2 = yDiff - 1\n result = (xDiff * yDiff) + (xDiff2 * yDiff2)\n putStrLn $ show $ result\n", "src_uid": "00cffd273df24d1676acbbfd9a39630d"} {"source_code": "import Control.Applicative\nimport Data.List\n\n\n\nmain = do\n [n, k] <- map (read :: String -> Int) <$> words <$> getLine\n tmp <- map (read :: String -> Int) <$> words <$> getLine\n let (a, ind) = unzip . sort $ zip tmp [1..]\n let xs = map (\\(x, y, z) -> y) $ takeWhile ((<= k) . (\\(x, y, z) -> z)) (zip3 a ind (scanl1 (+) a))\n putStrLn $ show . length $ xs\n putStrLn $ concat . (intersperse \" \") . (map show) $ xs\n\n", "src_uid": "dbb164a8dd190e63cceba95a31690a7c"} {"source_code": "module Main where\n\nimport Control.Applicative\nimport Data.Int\n\npow :: Int64 -> Int64 -> Int64\npow a 0 = 1\npow a n | even n = c * c\n | otherwise = c * c * a\n where m = n `div` 2\n c = pow a m\n\ncountWays :: Int64 -> Int64 -> Int64\ncountWays _ 0 = 0\ncountWays n sum | amax >= amin = amax - amin + 1\n | otherwise = 0\n where amin = max 1 (sum - n)\n amax = min n ((sum - 1) `div` 2)\n\ncountSum :: Int64 -> Int -> Int64\ncountSum n 0 = n * (n - 1) `div` 2\ncountSum n nines = sum [countWays n (base * k - 1) | k <- [1 .. 9]]\n where base = pow (fromIntegral 10) (fromIntegral nines)\n\nsolve :: Int64 -> Int64\nsolve n = head . filter (/= 0) $ [countSum n nines | nines <- [9, 8 .. 0]]\n\nmain :: IO ()\nmain = do\n n <- read <$> getLine\n print $ solve n\n", "src_uid": "c20744c44269ae0779c5f549afd2e3f2"} {"source_code": "main :: IO()\nmain = do\n input <- getLine\n input <- getLine\n let list = getList input\n putStrLn $ answer list\n\ngetList :: String -> [Int]\ngetList x = map read $ words x\n\nanswer :: [Int] -> String\nanswer [] = \"no\"\nanswer [x] = \"no\"\nanswer list = solve [init] (tail list)\n where init = sortPair (head list) (head $tail list)\n\nsortPair :: Int -> Int -> (Int, Int)\nsortPair x y = \n if x < y then (x, y) else (y, x)\n\n-- this function is mapping everything O(N^2)\nsolve :: [(Int, Int)] -> [Int] -> String\nsolve ps [] = \"no\"\nsolve ps [x] = \"no\"\nsolve ps xs = \n if inter then \"yes\" else solve (pair : ps) (tail xs)\n where inter = or $ map (intersects pair) ps\n pair = sortPair (head xs) (head $ tail xs)\n \n\nintersects (aL, aR) (bL, bR) = \n if aL <= bL then\n if bL < aR then \n if aR < bR then (aL /= bL)\n else if aR == bR then (aL == bL)\n else False\n else False\n else \n if aL < bR then\n if aR <= bR then False\n else True\n else False\n\n", "src_uid": "f1b6b81ebd49f31428fe57913dfc604d"} {"source_code": "\ntoint s = (read s) :: Int\n\nsolve::String -> String\nsolve sss =\n let (n:ss) = map toint $ words sss in\n let x = take n ss in\n let y = take n $ drop n ss in\n if (sum x) >= (sum y) then\n \"Yes\\n\"\n else\n \"No\\n\"\n\nmain = interact solve\n", "src_uid": "e0ddac5c6d3671070860dda10d50c28a"} {"source_code": "import Data.List\n\ngetNextString :: String -> Int -> String\ngetNextString s pos = take pos s ++ [next (s !! pos)] \n ++ replicate (length s - pos - 1) 'a'\n where \n next :: Char -> Char\n next 'z' = 'z'\n next c = succ c\n\nsolve :: String -> String -> [String]\nsolve s t = \n filter (\\ x -> s < x && x < t) (map (getNextString s) [0..length s - 1]) \n \nmain = do\n s <- getLine\n t <- getLine\n let res = solve s t\n if null res then\n putStrLn \"No such string\"\n else\n putStrLn $ head res\n", "src_uid": "47618510d2a17b1cc1e6a688201d51a3"} {"source_code": "import Control.Applicative( (<$>))\n\nmain = do\n let\n\treadLine = map read . words <$> getLine\n\n [l1_, s1_, r1_, p1_] <- readLine\n [l2_, s2_, r2_, p2_] <- readLine\n [l3_, s3_, r3_, p3_] <- readLine\n [l4_, s4_, r4_, p4_] <- readLine\n let\n\tl1 = l1_ == 1\n\ts1 = s1_ == 1\n\tr1 = r1_ == 1\n\tp1 = p1_ == 1\n\tl2 = l2_ == 1\n\ts2 = s2_ == 1\n\tr2 = r2_ == 1\n\tp2 = p2_ == 1\n\tl3 = l3_ == 1\n\ts3 = s3_ == 1\n\tr3 = r3_ == 1\n\tp3 = p3_ == 1\n\tl4 = l4_ == 1\n\ts4 = s4_ == 1\n\tr4 = r4_ == 1\n\tp4 = p4_ == 1\n\n\taccident = (l1&&(p1||p4)) ||\n\t\t (l2&&(p2||p1)) ||\n\t\t (l3&&(p3||p2)) ||\n\t\t (l4&&(p4||p3)) ||\n\t\t (s1&&(p1||p3)) ||\n\t\t (s2&&(p2||p4)) ||\n\t\t (s3&&(p3||p1)) ||\n\t\t (s4&&(p4||p2)) ||\n\t\t (r1&&(p1||p2)) ||\n\t\t (r2&&(p2||p3)) ||\n\t\t (r3&&(p3||p4)) ||\n\t\t (r4&&(p4||p1))\n\n putStr $ if accident\n\t\tthen \"YES\"\n\t\telse \"NO\"\n", "src_uid": "44fdf71d56bef949ec83f00d17c29127"} {"source_code": "import Data.List\n\ngetPermut :: [Integer] -> Integer -> Integer -> [Integer]\ngetPermut ls 0 0 = ls\ngetPermut ls ps pn \n | pn `mod` 2 == 0 = getPermut ([ps] ++ ls)(ps - 1)(pn `quot` 2)\n | pn `mod` 2 == 1 = getPermut (ls ++ [ps])(ps - 1)(pn `quot` 2)\n\nsolve :: Integer -> Integer -> [Integer]\nsolve ps pn = getPermut [ps] (ps - 1) (pn - 1)\n\nmain :: IO ()\nmain = do\n [ps, pn] <- fmap (map read . words) getLine\n putStrLn (intercalate \" \" (map show (solve ps pn)))", "src_uid": "a8da7cbd9ddaec8e0468c6cce884e7a2"} {"source_code": "{-# LANGUAGE BangPatterns #-}\n{-# LANGUAGE ViewPatterns #-}\n{-# LANGUAGE OverloadedStrings #-}\nimport Control.Applicative\nimport Control.Monad\nimport Data.List\nimport Data.Tuple\nimport Data.Int\nimport Data.Char\nimport Data.Function\nimport Text.Printf\n-- import Data.ByteString (ByteString)\n-- import qualified Data.ByteString.Char8 as C\n-- import Data.ByteString.Char8 ()\n-- import Data.Vector.Unboxed ((//), (++), (!), (!?))\n-- import qualified Data.Vector.Unboxed as U\n-- import Data.IntMap.Strict (IntMap)\n-- import qualified Data.IntMap.Strict as IntMap\n-- import Data.Sequence ((|>), (<|), (><),ViewR((:>)), ViewL((:<)))\n-- import qualified Data.Sequence as S\n\nmyread = read :: String -> Int\nmain = do\n [hh,mm] <- map myread . (\\xs -> [take 2 xs, drop 3 xs]) <$> getLine\n m <- readLn\n solve hh mm m\n\nsolve :: PrintfType r => Int -> Int -> Int -> r\nsolve hh mm m = printf \"%02d:%02d\\n\" nh nm where\n nh = mod (hh+(div (mm+m) 60)) 24\n nm = mod (mm+m) 60", "src_uid": "20c2d9da12d6b88f300977d74287a15d"} {"source_code": "import Data.Functor\n\ngetInts :: IO [Int]\ngetInts = map read <$> words <$> getContents\n\nmain = getInts >>= putStrLn . (\\b -> if b then \"YES\" else \"NO\") . solve\n\nsolve (a1:b1:a2:b2:a3:b3:[]) = or [\n check a1 b1 (a2 + a3) (max b2 b3),\n check a1 b1 (a2 + b3) (max b2 a3),\n check a1 b1 (b2 + a3) (max a2 b3),\n check a1 b1 (b2 + b3) (max a2 a3)]\n\ncheck a1 b1 a2 b2 = or [a2 <= a1 && b2 <= b1, a2 <= b1 && b2 <= a1]\n", "src_uid": "2ff30d9c4288390fd7b5b37715638ad9"} {"source_code": "module Main where\n\nimport Data.Char\nimport Data.Functor\nimport Text.Printf\n\nsolve :: Int -> Int -> Int\nsolve 1 _ = 0\nsolve n b =\n {- trace str -} ans\n where\n arr = takeWhile (<= n). map (2^) $ [1..]\n k = last. takeWhile (<= n). map (2^) $ [1..]\n couples = k `div` 2\n playersAdvanced = couples + n-k\n --str = printf \"n = %d, arr = %s, k = %d, couples = %d, curAns = %d\" n (show arr) k couples curAns\n curAns = k*b + couples\n ans = curAns + solve playersAdvanced b\n\n\nmain :: IO ()\nmain = do\n [n, b, p] <- map read. words <$> getLine\n printf \"%d %d\" (solve n b) (n*p)\n", "src_uid": "eb815f35e9f29793a120d120968cfe34"} {"source_code": "import Control.Monad\n\nmain :: IO ()\nmain = do\n n <- read <$> getLine\n print $ product (2:[1..(n-1)]) `div` n\n", "src_uid": "ad0985c56a207f76afa2ecd642f56728"} {"source_code": "{-# OPTIONS_GHC -O3 #-}\n{-# LANGUAGE ViewPatterns, ScopedTypeVariables #-}\n\nimport qualified Data.ByteString as B (getLine)\nimport qualified Data.ByteString.Char8 as C (readInt, words)\nimport qualified Data.Maybe as M (fromJust)\nimport Data.List\n\nreadInt = fst . M.fromJust . C.readInt\n\nrun 0 xs | 0 `elem` xs = 1 | otherwise = 0\nrun x xs | x `elem` xs = 1 + (x - length [y | y <- xs, y < x])\n | otherwise = x - length [y | y <- xs, y < x]\n\nmain = do\n (map readInt . C.words -> [n, x]) <- B.getLine\n (map readInt . C.words -> xs) <- B.getLine\n print $ run x xs\n", "src_uid": "21f579ba807face432a7664091581cd8"} {"source_code": "import Data.List\ngao '>' = 8\ngao '<' = 9\ngao '+' = 10\ngao '-' = 11\ngao '.' = 12\ngao ',' = 13\ngao '[' = 14\ngao ']' = 15\n\nmain = interact $ show.foldr (\\x acc -> ((gao x) + acc * 16) `mod` 1000003) 0.reverse.head.words \n\n", "src_uid": "04fc8dfb856056f35d296402ad1b2da1"} {"source_code": "{-# OPTIONS_GHC -O2 #-}\n--import Data.Array\nimport Data.Array (Array(..))\nimport Data.Array.Base\nreadPair = fmap ((\\[x,y] -> (x,y)).map read.words) getLine :: IO (Integer,Integer);\nmain = do {\n (w,h) <- readPair;\n if w > 1 && h > 1 then do {\n let \n {\n nw x = min x $ w-x;\n nh y = min y $ h-y;\n aw = listArray (1,w-1) $ map nw [1..w-1] :: Array Integer Integer;\n ah = listArray (1,h-1) $ map nh [1..h-1] :: Array Integer Integer;\n a = array (1,(w-1)*(h-1)) [ (((x-1)*(w-1) + y), (aw!x) * (ah!y)) | x <- [1..w-1], y <- [1..h-1]]\n :: Array Integer Integer;\n aSum = sum' aw * sum' ah\n --ans = map (\\(x,y) -> nw x * nh y) [(x,y) | x <- [1..w-1], y <- [1..h-1]];\n };\n print aSum;\n }\n else do {\n print 0\n };\n };\nsum' arr = s' (fromIntegral $ (length.indices $ arr)) 0\n where \n s' 0 acc = acc\n s' i acc = s' (i-1) (acc + arr ! i)", "src_uid": "42454dcf7d073bf12030367eb094eb8c"} {"source_code": "{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}\n{-# LANGUAGE BangPatterns, TupleSections, OverloadedStrings #-}\nimport Control.Applicative\nimport Control.Exception hiding (mask)\nimport Control.Monad\nimport Control.Monad.ST\nimport Data.Array.Base\nimport Data.Array.ST (runSTUArray, runSTArray)\nimport Data.Bits\nimport qualified Data.ByteString.Char8 as B\nimport Data.Char\nimport Data.Function\nimport Data.Int\nimport Data.List\nimport qualified Data.Map as M\nimport qualified Data.IntMap.Strict as IM\nimport qualified Data.Set as S\nimport qualified Data.IntSet as IS\nimport Data.STRef\nimport GHC.Arr (Array, STArray, Ix(..))\nimport Debug.Trace\n\nbool :: a -> a -> Bool -> a\nbool t f b=if b then t else f\nreadInt :: B.ByteString -> Int\nreadInt bs=case B.readInt bs of{Just(n,_)->n;_->error$\"readInt error : bs = \"++show bs;}\nrep, rev :: Monad m => Int -> (Int -> m ()) -> m ()\nrep n f=foldr((>>).f)(return())[0..n-1]\nrev n f=foldr((>>).f.negate)(return())[1-n..0]\nfor :: Monad m => Int -> Int -> (Int -> m ()) -> m ()\nfor a b f=foldr((>>).f)(return())[a..b]\n{-# INLINE rep #-}\n{-# INLINE rev #-}\n{-# INLINE for #-}\nmodifyArray :: (MArray a e m, Ix i) => a i e -> i -> (e -> e) -> m ()\nmodifyArray a i f=readArray a i>>=writeArray a i.f\n{-# INLINE modifyArray #-}\nunsafeModify :: (MArray a e m, Ix i) => a i e -> Int -> (e -> e) -> m ()\nunsafeModify a i f=unsafeRead a i>>=unsafeWrite a i.f\n{-# INLINE unsafeModify #-}\n\nmain :: IO ()\nmain = do\n [n,m] <- map read.words <$> getLine\n print $ solve n m\n\nsolve :: Int -> Int -> Int\nsolve n m = go 0 n m\n where\n go !res n m\n | m < n = go res m n\n | n > 0 && m > 1 = go (res+1) (n-1) (m-2)\n | otherwise = res\n", "src_uid": "0718c6afe52cd232a5e942052527f31b"} {"source_code": "-- Codeforces 909B\n\nimport Control.Applicative\n\nmain :: IO ()\nmain = do\n n <- read <$> getLine :: IO Int\n print $ (n `div` 2 + 1) * ((n + 1) `div` 2)\n", "src_uid": "f8af5dfcf841a7f105ac4c144eb51319"} {"source_code": "{-# OPTIONS_GHC -O2 #-}\n{-# LANGUAGE BangPatterns #-}\nimport Data.Maybe\nimport Data.Char\nimport Data.List\nimport Data.Int\nimport Data.Bits\nimport Data.Ratio\nimport Data.IORef\nimport Data.Array.IO\nimport Control.Monad\nimport Control.Applicative\nimport qualified Data.ByteString.Char8 as BS\nimport qualified Data.Map as Map\nimport qualified Data.Set as Set\nimport Text.Printf\nimport Debug.Trace\nimport System.Exit\n\n\ngetint :: IO Int\ngetint = head <$> getints\n\ngetints :: IO [Int]\ngetints = map fst . mapMaybe BS.readInt . BS.words <$> BS.getLine\n\ngetnums :: Num a => IO [a]\ngetnums = map (fromIntegral . fst) . mapMaybe BS.readInteger . BS.words <$> BS.getLine\n\ngetstr = getLine\n\noutCount a b c m = t\n where\n k = max 0 $ (b + c + m - a + 1) `div` 2\n t = if k <= m then (m - k + 2) * (m - k + 1) `div` 2 else 0\n\nsolve a b c l m\n | m > l = 0\n | otherwise = t + solve a b c l (m + 1)\n where\n t = (m + 2) * (m + 1) `div` 2 - ka - kb - kc\n ka = outCount a b c m\n kb = outCount b c a m\n kc = outCount c a b m\n\nmain = do\n [a, b, c, l] <- getnums :: IO [Int64]\n putStrLn . show $ solve a b c l 0\n", "src_uid": "185ff90a8b0ae0e2b75605f772589410"} {"source_code": "module Main where\n\nimport Control.Applicative\nimport Control.Monad\n\nmain :: IO ()\nmain = do\n n <- readLn :: IO Int\n let ans = solve n\n print ans\n\nsolve :: Int -> Int\nsolve n = seek n 1 1\n where\n seek n k v\n | w > n = v\n | n `mod` w == 0 = seek n (k+1) w\n | otherwise = seek n (k+1) v\n where\n w = (2^k-1)*(2^(k-1))\n", "src_uid": "339246a1be81aefe19290de0d1aead84"} {"source_code": "import Data.List\nimport Data.Map hiding(map,filter)\n\ntoInts = map (charToInt!)\n\twhere charToInt = fromList$zip (['0'..'9']++['A'..'Z']) [0..]\n\ntoInt radix = foldl step 0.toInts\n\twhere step a b = a*radix+b\n\t\ncheck (h,m) r = toInt r h < 24 && toInt r m < 60\n\nresult t@(h,m)\n\t| check t 60 = [-1]\n\t| not(check t start) = [0]\n\t| otherwise = filter (check t) [start..59]\n\twhere start = 1 + maximum (toInts h++toInts m)\n\nparse = remove.break (==':')\n\twhere remove (h,hm:tm) = (h,tm)\n\t\nmain=interact$unwords.map show.result.parse.head.lines\n", "src_uid": "c02dfe5b8d9da2818a99c3afbe7a5293"} {"source_code": "import Control.Applicative\nimport Data.List\nimport Data.Maybe\n\nmain = do\n l <- getLine\n print (mod (solve l) 1000000007)\n\nsolve :: String -> Integer\nsolve l | i < 0 = 0\n | otherwise = 2^i*(2^(2*n) + (solve l')*2)\n where\n i = fromMaybe (-1) (elemIndex '1' l)\n l' = drop (i+1) l\n n = fromIntegral $ length l'\n\n", "src_uid": "89b51a31e00424edd1385f2120028b9d"} {"source_code": "main :: IO ()\nmain = getLine >>= putStrLn . showFraction . solve . read\nshowFraction :: (Integer, Integer) -> String\nshowFraction (a, b) = show (div a g) ++ \"/\" ++ show (div b g)\n where g = gcd a b\n gcd x y = if y == 0 then x else gcd y (mod x y)\n\ncal :: Integer -> Integer -> (Integer, Integer)\ncal n r = if r >= n\n then (0, r-n)\n else let (c, r2) = cal n (r*2) in (c+1, r2)\n\nsolve :: Integer -> (Integer, Integer)\nsolve n = if mod n 2 == 0\n then let (a, b) = solve (div n 2) in (a + b, b)\n else if n == 1 then (0, 1) else let (a, b) = go n 1 in (a, b-1)\n\ngo :: Integer -> Integer -> (Integer, Integer)\ngo n r = let (c, r2) = cal n r\n p = 2 ^ c\n cur = p * r * c\n in if r2 == 1\n then (cur, p)\n else let (a, b) = go n r2 in (a+cur*b, b*p)\n \n", "src_uid": "5491b4a27991153a61ac4a2618b2cd0e"} {"source_code": "factors :: Integer -> [Integer]\nfactors n' = aux n' 2 [] 1\n where aux n _ acc 1 | n == 1 = acc\n aux n lst acc 1 | lst*lst > n = n:acc\n aux n lst acc p | n `mod` lst == 0 = aux (n `div` lst) lst acc (p * lst)\n aux n lst acc p = aux n (lst+1) (if p > 1 then p:acc else acc) 1\n\ntrySplit :: [Integer] -> Integer\ntrySplit xs' = aux xs' 1 1\n where aux [] l r = max l r\n aux (x:xs) l r = min (aux xs (x*l) r) (aux xs l (x*r))\n\ngo :: Integer -> IO ()\ngo n = putStrLn $ show cost ++ \" \" ++ show (n `div` cost)\n where cost = trySplit $ factors n\n\nmain :: IO ()\nmain = read <$> getLine >>= go\n", "src_uid": "e504a04cefef3da093573f9df711bcea"} {"source_code": "import Data.List (sort)\n\nprocess :: Integral a => [a] -> [a] -> [a]\nprocess xs ys = f (sort xs) (sort ys)\n where\n f xs [] = replicate (length xs) 1\n f [] ys = replicate (length ys) 2\n f xs@(x:xs') ys@(y:ys')\n | x < y = 1:(f xs' ys)\n | x > y = 2:(f xs ys')\n | otherwise = 1:(f xs' ys')\n\nreadInt :: String -> Int\nreadInt = read\n\nmain :: IO ()\nmain = do\n [n,a,b] <- fmap (map readInt.words) getLine\n xs <- fmap (map readInt.words) getLine\n ys <- fmap (map readInt.words) getLine\n putStrLn.unwords.map show $ process xs ys", "src_uid": "a35a27754c9c095c6f1b2d4adccbfe93"} {"source_code": "import Control.Applicative( (<$>))\n\nmain = do\n [l_, r_, x_, y_, k_] <- map (read::String->Integer) . words <$> getLine\n let\n\tsearch::[Integer]->Bool\n\tsearch []\t\t= False\n\tsearch (i:is)\n\t | i < l_\t\t= search is\n\t | i <= r_\t\t= True\n\t | otherwise\t\t= False\n\t\n\t\n putStr $ if search ((k_*) <$> [max x_ (l_`quot`k_)..y_])\n\t\tthen \"YES\"\n\t\telse \"NO\"\n", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048"} {"source_code": "{-# LANGUAGE ScopedTypeVariables #-}\n{-# LANGUAGE BangPatterns #-}\n{-# LANGUAGE Safe #-}\n{-# LANGUAGE TupleSections #-}\n{-# LANGUAGE ExplicitForAll #-}\n{-# LANGUAGE MultiWayIf #-}\n{-# LANGUAGE CPP #-}\n{-# LANGUAGE FlexibleContexts #-}\n{-# LANGUAGE NoMonomorphismRestriction #-}\n\nimport Data.Bits\nimport Data.List\nimport qualified Data.ByteString.Char8 as BS\nimport qualified Data.ByteString.Lazy.Char8 as BSL\nimport Data.IntMap.Strict (IntMap)\nimport qualified Data.IntMap.Strict as IM\nimport Data.IntSet (IntSet)\nimport qualified Data.IntSet as IS\nimport qualified Data.Array.IArray as A\nimport qualified Data.Array.MArray.Safe as A\n-- import qualified Data.Array.MArray as A\nimport Data.Array (Array)\nimport Data.Array.Unboxed (UArray)\nimport Data.Array.IArray (IArray)\nimport Data.Array.MArray.Safe (MArray)\nimport Data.Array.IO.Safe (IOArray, IOUArray)\nimport Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)\n{-\nimport qualified Data.Vector.Unboxed as VU\nimport qualified Data.Vector.Unboxed.Mutable as VUM\n-}\nimport Control.Monad\nimport Control.Monad.ST.Safe\n-- import Control.Monad.ST\nimport Control.Applicative\nimport Data.Maybe\nimport Data.Tuple\nimport Data.Ord\nimport Control.Monad.State.Strict\nimport Data.Int\nimport Data.Word\nimport Data.STRef\nimport Data.IORef\nimport Data.Function\nimport System.IO\nimport System.Exit\nimport Data.Char\n\nmain :: IO ()\nmain = do\n [c1,c2,c3,c4] <- replicateM 4 $ readInt <$> getLine\n print $ if c1 == c4 && (c3 == 0 || c1 > 0) then 1 else 0\n\nrInt :: StateT BSL.ByteString Maybe Int\nrInt = StateT $ BSL.readInt . BSL.dropWhile (<'!')\n\n#define D(f,r,d) f::Integral a=>a->d;f=fromIntegral;r::String->d;r=read\n#define C(f,r,g,h,d) D(f,r,d);g,h::RealFrac a=>a->d;g=floor;h=ceiling\nC(_toInteger_,readInteger,floorInteger,ceilInteger,Integer)\nC(toInt,readInt,floorInt,ceilInt,Int)\nC(toI8,readI8,floorI8,ceilI8,Int8)\nC(toI16,readI16,floorI16,ceilI16,Int16)\nC(toI32,readI32,floorI32,ceilI32,Int32)\nC(toI64,readI64,floorI64,ceilI64,Int64)\nC(toWord,readWord,floorWord,ceilWord,Word)\nC(toW8,readW8,floorW8,ceilW8,Word8)\nC(toW16,readW16,floorW16,ceilW16,Word16)\nC(toW32,readW32,floorW32,ceilW32,Word32)\nC(toW64,readW64,floorW64,ceilW64,Word64)\nD(toDouble,readDouble,Double)\nD(toFloat,readFloat,Float)\n#undef D\n#undef C\n\n\n#define N(f,g,a,m)\\\n f :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> e -> m (a i e); f=A.newArray;\\\n g :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> m (a i e); g=A.newArray_\n#define C(a,m)\nN(newIOA,newIOA_,IOArray,IO)\nN(newSTA,newSTA_,STArray s,ST s)\n#undef C\n#define C(a,m) MArray (a) e (m), \nN(newIOUA,newIOUA_,IOUArray,IO)\nN(newSTUA,newSTUA_,STUArray s,ST s)\n#undef C\n#undef N\n\n", "src_uid": "b99578086043537297d374dc01eeb6f8"} {"source_code": "import Data.List\nimport Control.Monad\n\nconvert2 :: String -> String\nconvert2 ('r':'u':[]) = '.':'r':'u':[]\nconvert2 ('r':'u': xs) = '.':'r' : 'u' : '/' : xs\nconvert2 (x:xs) = x : convert2 xs\n\nconvert :: String -> String \nconvert s \n | \"http\" `isPrefixOf` s = \"http://\" ++ [s !! 4] ++ (convert2 $ drop 5 s) \n | \"ftp\" `isPrefixOf` s = \"ftp://\" ++ [ s!! 3] ++ (convert2 $ drop 4 s)\n\nmain :: IO()\nmain = getLine >>= ( \\x -> putStrLn $ convert x) \n", "src_uid": "4c999b7854a8a08960b6501a90b3bba3"} {"source_code": "adjust _ _ [] = []\nadjust 0 _ xs = xs\nadjust n c (x:xs) \n | c == x = x : adjust n c xs\n | otherwise = c : adjust (n - 1) c xs\n\nsolve xs = show n ++ \"\\n\" ++ ms where\n ys = filter (=='x') xs\n zs = filter (=='X') xs\n diff = length ys - length zs\n n = abs (diff `div` 2)\n c = if diff < 0 then 'x' else 'X'\n ms = adjust n c xs\n\nmain = do\n input <- getContents\n let xs = last $ lines input\n putStrLn $ solve xs\n", "src_uid": "fa6311c72d90d8363d97854b903f849d"} {"source_code": "import Control.Arrow\nimport Data.Maybe\nimport Data.List\nimport Data.Foldable\n\n{-\nimport System.IO.Unsafe\n\ndebug :: (Show x) => x -> ()\ndebug = unsafePerformIO . print\n-}\n\nmain :: IO ()\nmain = do\n _ <- getLine\n string <- getLine\n putStrLn $ show $ solve3 string\n\nsolve3 :: String -> Int\nsolve3 string = solve3' (foldl1 max string) string\n where\n solve3' :: Char -> String -> Int\n solve3' maxElem string =\n let maxElemIdx = elemIndices maxElem string\n removableIdx = filter (canDel string) maxElemIdx\n in step removableIdx maxElem string\n step :: [Int] -> Char -> String -> Int\n step [] 'a' _ = 0\n step [] maxElem string = solve3' (pred maxElem) string\n step removableIdx maxElem string = (length removableIdx) + (solve3' maxElem $ foldl delIdx string $ sortBy (flip compare) removableIdx)\n\n{-\nsolve2 :: String -> Int\nsolve2 string = \n let idx = [0..(length string - 1)]\n validIdx = filter (canDel string) idx\n maxElem:elems = sortBy (flip compare) $ nub string\n in fromMaybe 0 $ asum $ flip map elems $ \\elem ->\n let elemIdx = elemIndices elem string\n lookAtIdx = intersect validIdx elemIdx\n in (debug (string, elem, lookAtIdx)) `seq` foldl max Nothing $ Just . succ . solve2 . delIdx string <$> lookAtIdx \n\n \nsolve :: String -> Int\nsolve string = \n let idx = [0..(length string - 1)]\n validIdx = filter (canDel string) idx\n in foldl max 0 $ succ . solve . delIdx string <$> validIdx\n-}\n\natm :: [t] -> Int -> Maybe t\natm xs i \n | i < 0 = Nothing\n | i >= length xs = Nothing\n | otherwise = Just $ xs !! i\n\ndelIdx :: [t] -> Int -> [t]\ndelIdx xs = flip splitAt xs >>> id *** tail >>> uncurry (++)\n\ncanDel :: String -> Int -> Bool\ncanDel string i = \n let lookee = pred $ string !! i\n canDelPred = fromMaybe False $ (== lookee) <$> string `atm` (pred i) \n canDelSucc = fromMaybe False $ (== lookee) <$> string `atm` (succ i)\n in canDelPred || canDelSucc\n \n", "src_uid": "9ce37bc2d361f5bb8a0568fb479b8a38"} {"source_code": "main = getLine >>= putStrLn . solve 'a'\n\nsolve '{' remain = remain\nsolve _ [] = \"-1\"\nsolve ch (x:xs)\n | x <= ch = concat' ch $ solve (succ ch) xs\n | otherwise = concat' x $ solve ch xs\n where concat' ch str\n | str /= \"-1\" = ch : str\n | otherwise = str\n", "src_uid": "f8ad543d499bcc0da0121a71a26db854"} {"source_code": "import Data.Bits\n\nmain = do\n [n, p] <- map read . words <$> getLine\n print $ solve n p\n\nsolve :: Int -> Int -> Int\nsolve n p = go 1\n where go s\n | s == 32 = -1\n | n - s * p < s = go (s + 1)\n | popCount (n - s * p) <= s = s\n | otherwise = go (s + 1)", "src_uid": "9e86d87ce5a75c6a982894af84eb4ba8"} {"source_code": "import Data.List\nmain = do \n\ta <- getLine\n\tlet b = length.filter (=='4') $ a\n\tlet c = length.filter (=='7') $ a\n\tputStrLn $ if max b c == 0 \n\t\t\tthen \"-1\"\n\t\t\telse if b >= c \n\t\t\t\tthen \"4\"\n\t\t\t\telse \"7\"\n", "src_uid": "639b8b8d0dc42df46b139f0aeb3a7a0a"} {"source_code": "import Data.Word\n\nsolve [n, a, b, p, q] =\n n `div` a * p + n `div` b * q - n `div` (a `div` gcd a b * b) * min p q :: Word64\n\nmain = interact $ unlines . map (show . solve . map read . words) . lines\n", "src_uid": "35d8a9f0d5b5ab22929ec050b55ec769"} {"source_code": "{-# LANGUAGE TypeApplications #-}\nmain = interact $ show . solve . map (read @Int) . tail . words\nsolve (k:as) = length ls + length rs where\n (ls,as') = break (> k) as\n rs = takeWhile (<= k) (reverse as')\n", "src_uid": "ecf0ead308d8a581dd233160a7e38173"} {"source_code": "import Data.Maybe\nimport Control.Monad\nmain = interact $ show . solve . map read . tail . words\nsolve (k:as) = minimum $ mapMaybe (\\a -> let (d,r) = k `divMod` a in guard (r == 0) *> pure d) as\n", "src_uid": "80520be9916045aca3a7de7bc925af1f"} {"source_code": "import Data.List\nimport Data.Int\nimport Data.Maybe\nimport Data.Char\nimport Control.Monad\nimport Control.Monad.ST.Safe\nimport Data.Array\nimport Data.Array.ST.Safe\nimport Data.STRef\nmain= readsolveprint\nreadsolveprint::IO()\nreadsolveprint = interact $ unlines.solve. map digitToInt.head.lines\nsolve :: [Int]-> [String]\nsolve (x:xs) = slv2 $ slv1 x xs\nslv1 0 [] =[]\nslv1 0 (x:xs) = slv1 x xs\nslv1 x xs = [[1]++map (\\a->if a==0 then 0 else 1) xs] ++ slv1 (x-1) (map (\\a->if a==0 then 0 else a-1) xs)\nslv2 xss = [show $ length xss] ++ [unwords $ map (map intToDigit) xss]", "src_uid": "033068c5e16d25f09039e29c88474275"} {"source_code": "import Control.Applicative\nimport Data.List\n\n\nmain= do\n\t [n,c]<- map read. words <$> getLine::IO [Int]\n\t s<- map read. words <$> getLine ::IO [Int]\n\t let m = maximum $ zipWith (-) s (tail s)\n\t print $ max 0 (m-c)\n", "src_uid": "411539a86f2e94eb6386bb65c9eb9557"} {"source_code": "{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -funfolding-use-threshold=16 -fexcess-precision -funbox-strict-fields #-} \nmodule Main where\nimport qualified Data.ByteString.Char8 as B\nimport Data.Int\n\nreadInt = maybe undefined (fromIntegral . fst) . B.readInteger\nreadInts = fmap readInt . B.words\n \nsolve n k = (d, c, n - c - d)\n where \n d = n `div` 2 `div` (k + 1) :: Int64\n c = k * d\n\nmain = do\n [n, k] <- fmap readInts B.getLine\n let (a, b, c) = solve n k\n putStr $ show a ++ \" \" ++ show b ++ \" \" ++ show c\n\n{-\nc = kd\n2*d*(k + 1) < n\n-}", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80"} {"source_code": "\neqDigit :: Int -> Int -> Bool\neqDigit x y = eqDigit' (show x) (show y)\n where\n eqDigit' xs ys = any (flip elem xs) ys\n\nsolve :: Int -> Int\nsolve n = length $ concatMap solve' (takeWhile (\\x -> x*x <= n) [1..]) \n where\n solve' x\n | x * x == n = if eqDigit n x then [x] else []\n | otherwise = x1 ++ x2\n where\n x1 = if mod n x == 0 && eqDigit n x then [x] else []\n x2 = if mod n x == 0 && eqDigit n y then [y] else []\n y = div n x\n\n\nmain :: IO ()\nmain = readLn >>= print . solve\n", "src_uid": "ada94770281765f54ab264b4a1ef766e"} {"source_code": "{-# LANGUAGE CPP #-}\r\n{-# LANGUAGE LambdaCase #-}\r\n{-# LANGUAGE RecordWildCards #-}\r\n{-# LANGUAGE Strict #-}\r\n\r\nimport Control.Applicative (liftA2)\r\nimport Control.Arrow ((>>>))\r\nimport Control.Monad\r\nimport Control.Monad.State (State, evalState, get, gets, put)\r\nimport Data.Bool\r\nimport qualified Data.ByteString.Lazy.Char8 as C\r\nimport Data.Function\r\nimport Data.Int\r\nimport Data.List\r\nimport Data.Maybe\r\nimport Debug.Trace\r\n\r\n----- --------------------------------------------------------------\r\ndata TC = TC {n :: Int, m :: Int64}\r\n\r\ntype Output = Int64\r\n\r\ninput :: Scanner TC\r\ninput = do\r\n n <- int\r\n m <- int64\r\n return TC {..}\r\n\r\nsolve :: TC -> Output\r\nsolve TC {..} = tot -% nonamb\r\n where\r\n n' = min 40 n\r\n m' = m `mod` modv\r\n tot = iterate (*% m') m' >$> take n >>> foldl1 (+%)\r\n nonamb =\r\n [if i `elem` primes then fi i else 1 | i <- [1 .. n']]\r\n >$> scanl1 (*)\r\n >>> map (m `div`)\r\n >>> map (`mod` modv)\r\n >>> scanl1 (*%)\r\n >>> foldl1 (+%)\r\n\r\nprimes :: [Int]\r\nprimes = [i | i <- [2 .. 40], all ((0 /=) . (i `mod`)) [2 .. i - 1]]\r\n\r\noutput :: Int -> Output -> C.ByteString\r\noutput _ = showB\r\n\r\n----- -------------------------------------------------------------\r\n\r\nmain :: IO ()\r\nmain = C.interact $ runScanner input >>> solve >>> output 0\r\n\r\n-- main = C.interact $ runScanner (numberOf input) >>> map solve >>> zip [1..] >>> map (uncurry output) >>> C.unlines\r\n\r\n----- Template ----------------------------------------------------------------\r\nfi :: (Integral a, Num b) => a -> b\r\nfi = fromIntegral\r\n\r\n-- modular arith\r\nmodv :: Int64\r\nmodv = 998244353\r\n\r\n(+%), (-%), (*%), (/%) :: Int64 -> Int64 -> Int64\r\na +% b = (a + b) `mod` modv\r\na -% 0 = a\r\na -% b = a +% (modv - b `mod` modv)\r\na *% b = (a * b) `mod` modv\r\na /% b = a *% inv b\r\n\r\ninv :: Int64 -> Int64\r\ninv a = a ^% fi (modv - 2)\r\n\r\n(^%) :: Int64 -> Int -> Int64\r\na ^% 0 = 1\r\na ^% b =\r\n let (q, r) = b `divMod` 2\r\n u = a ^% q\r\n v = if r == 1 then a else 1\r\n in u *% u *% v\r\n\r\ninfixl 6 +%\r\n\r\ninfixl 6 -%\r\n\r\ninfixl 7 *%\r\n\r\ninfixl 7 /%\r\n\r\ninfixr 8 ^%\r\n\r\n-- Debug\r\ndebug :: Show a => a -> a\r\ndebugV :: Show a => String -> a -> a\r\n\r\n#ifdef ONLINE_JUDGE\r\ndebug = id\r\ndebugV _ = id\r\n#else\r\ndebug a = trace (show a) a\r\ndebugV name a = trace (name <> \" = \" <> show a) a\r\n#endif\r\n\r\n-- helpers\r\n(>$>) = flip ($)\r\n\r\ninfixl 0 >$>\r\n\r\n-- Lists\r\ngroupOn :: Eq b => (a -> b) -> [a] -> [[a]]\r\ngroupOn = groupBy . on (==)\r\n\r\nchunksOf :: Int -> [a] -> [[a]]\r\nchunksOf _ [] = []\r\nchunksOf k xs = let (hs, ts) = splitAt k xs in hs : chunksOf k ts\r\n\r\nadjacents :: [a] -> [(a, a)]\r\nadjacents xs = zip xs (tail xs)\r\n\r\nadjacentsWith :: (a -> a -> b) -> [a] -> [b]\r\nadjacentsWith f xs = zipWith f xs (tail xs)\r\n\r\ncount :: Eq a => a -> [a] -> Int\r\ncount = countBy . (==)\r\n\r\ncountBy :: (a -> Bool) -> [a] -> Int\r\ncountBy p = length . filter p\r\n\r\n-- Scanner\r\ntype Scanner = State [C.ByteString]\r\n\r\nrunScanner :: Scanner a -> C.ByteString -> a\r\nrunScanner = runScannerWith C.words\r\n\r\nrunScannerWith :: (C.ByteString -> [C.ByteString]) -> Scanner a -> C.ByteString -> a\r\nrunScannerWith t s = evalState s . t\r\n\r\npeek :: Scanner C.ByteString\r\npeek = gets head\r\n\r\nbstr :: Scanner C.ByteString\r\nbstr = get >>= \\case s : ss -> put ss >> return s\r\n\r\nstr = C.unpack <$> bstr\r\n\r\nreadStr :: Read a => Scanner a\r\nreadStr = read <$> str\r\n\r\nint :: Scanner Int\r\nint = fst . fromJust . C.readInt <$> bstr\r\n\r\ninteger :: Scanner Integer\r\ninteger = readStr\r\n\r\nint64 :: Scanner Int64\r\nint64 = readStr\r\n\r\ndouble :: Scanner Double\r\ndouble = readStr\r\n\r\ndecimal :: Int -> Scanner Int\r\ndecimal p = round . ((10 ^ p) *) <$> double\r\n\r\nnumberOf :: Scanner a -> Scanner [a]\r\nnumberOf s = int >>= flip replicateM s\r\n\r\nmany :: Scanner a -> Scanner [a]\r\nmany s = get >>= \\case [] -> return []; _ -> (:) <$> s <*> many s\r\n\r\ntill :: (C.ByteString -> Bool) -> Scanner a -> Scanner [a]\r\ntill p s = do\r\n t <- peek\r\n if p t\r\n then return []\r\n else (:) <$> s <*> till p s\r\n\r\ntimes :: Int -> Scanner a -> Scanner [a]\r\ntimes = replicateM\r\n\r\n(><) = times\r\n\r\ntwo, three, four :: Scanner a -> Scanner [a]\r\n[two, three, four] = map times [2 .. 4]\r\n\r\npair :: Scanner a -> Scanner b -> Scanner (a, b)\r\npair = liftA2 (,)\r\n\r\nshowB :: Show a => a -> C.ByteString\r\nshowB = C.pack . show\r\n", "src_uid": "0fdd91ed33431848614075ebe9d2ee68"} {"source_code": "main = interact (show . f . map read . words)\nf [n, m] = (2 * (1 - expm m 3 n) `div` (1 - 3)) `mod` m\n\nexpm m b k = ex b k 1 where\n ex a k s\n | k == 0 = s\n | k `mod` 2 == 0 = ex (a * a `mod` m) (k `div` 2) s\n | otherwise = ex (a * a `mod` m) (k `div` 2) (s*a `mod` m)", "src_uid": "c62ad7c7d1ea7aec058d99223c57d33c"} {"source_code": "import Control.Monad\nmain = do\n\t[x,y] <- readInts\n\tres <- return $ solve x (y-1)\n\tprintList res\n\treturn ()\n\n\nreadInts :: IO [Integer]\nreadInts = getLine >>= return . words >>= mapM readIO\nprintList :: Show a => [a] -> IO ()\nprintList xs = mapM_ (\\x -> putStr (show x ++ \" \") ) xs\n\nfib = 1:1:zipWith (+) fib (tail fib)\nfibN n = fib !! fromInteger (n-1)\n\n\nsolve :: Integer -> Integer -> [Integer]\nsolve n k\n\t| n == 0 = []\n\t| n == 1 = [1]\n\t| k < (fibN n) = \n\t\t1:( map (+1) $ solve (n-1) k)\n\t| otherwise = \n\t\t2 : 1 : (map (+2) $ solve (n-2) (k-(fibN n)))\n\n \n", "src_uid": "e03c6d3bb8cf9119530668765691a346"} {"source_code": " main :: IO ()\n main = do\n n <- readLn :: IO Integer\n putStrLn $ show $ solve n\n \n solve n = rec n 1\n \n rec n i \n | i >= n = 1\n | otherwise = 1 + (rec (n-i) (i*2))", "src_uid": "95cb79597443461085e62d974d67a9a0"} {"source_code": "main = do\n\ti <- getLine\n\tlet n = read $ init i :: Integer;\n\t\tp = last i\n\tlet ans = (((n - 1) `div` 4) * 2 + 1 - (n `mod` 2)) * 6 + ((n - 1) `div` 4) * 4 + 1 - (n `mod` 2)\n\tprint $ ans + f p\n\twhere\n\t\tf 'f' = 1\n\t\tf 'e' = 2\n\t\tf 'd' = 3\n\t\tf 'a' = 4\n\t\tf 'b' = 5\n\t\tf 'c' = 6\n", "src_uid": "069d0cb9b7c798a81007fb5b63fa0f45"} {"source_code": "main::IO ()\nmain = fmap (map read . words) getLine >>= print . solution where\n solution [n,a] | mod a 2 == 0 = 1 + (n - a) `div` 2\n | otherwise = (a + 1) `div` 2\n", "src_uid": "aa62dcdc47d0abbba7956284c1561de8"} {"source_code": "parse = (map read) . words\n\nsolve all = maximum $ getAll\n where\n getAll = [calcMixed x all | x <- [0 .. 2]]\n calcMixed n all\n | check $ (deleteMixed n all) = n + calc n all\n | otherwise = 0\n calc n = greedy . (deleteMixed n) \n check = null . (filter (<0))\n deleteMixed n = map (\\x -> x - n)\n greedy = sum . (map (`div` 3))\n\noutput = show\n\nmain = interact $ output . solve . parse\n\n", "src_uid": "acddc9b0db312b363910a84bd4f14d8e"} {"source_code": "import Data.List\n\nreadInts :: IO [Int]\nreadInts = fmap (map read.words) getLine\n\nlistLast :: [Int] -> Int\nlistLast [x] = x\nlistLast (_:xs) = listLast xs\n\nf0 :: String -> Bool\nf0 str \n | elem '0' str = (elem '1' str)||(elem '2' str)||(elem '3' str) \n | otherwise = False\n\nf1 :: String -> Bool\nf1 str \n | elem '1' str = (elem '9' str)||((elem '7' str)&&((elem '6' str)||(elem '3' str)))\n | otherwise = False\n\nf3 :: String -> Bool\nf3 str \n | elem '3' str = (elem '7' str)||((elem '9' str)&&((elem '4' str)||(elem '1' str)))\n | otherwise = False\n\nf7 :: String -> Bool\nf7 str\n | elem '7' str = ((elem '2' str)&&((elem '6' str)||(elem '9' str)))||((elem '6' str)&&(elem '1' str))\n | otherwise = False\n\nf9 :: String -> Bool\nf9 str\n | elem '9' str = ((elem '2' str)&&((elem '4' str)||(elem '7' str)))||((elem '4' str)&&(elem '3' str))\n | otherwise = False\n\nmain = do\n (k:_) <- readInts\n str <- getLine\n if (f0 str) || (f1 str) || (f3 str)||(f7 str)||(f9 str)\n then putStrLn \"YES\"\n else putStrLn \"NO\"", "src_uid": "d0f5174bb0bcca5a486db327b492bf33"} {"source_code": "-- Try Codeforces\n-- author: Leonardone @ NEETSDKASU\n\nmain = interact $ solve . map read . words\n\nsolve xs = if null $ filter f $ map g ys then \"NO\" else \"YES\"\n where\n f = (sum xs ==)\n g = (2*) . sum . map (xs!!)\n ys = do\n a <- [0 .. 3]\n b <- [a+1 .. 4]\n c <- [b+1 .. 5]\n return [a, b, c]\n ", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11"} {"source_code": "import Data.List\n\n\nmain =do\n e<-getLine\n let (m:d:[])=map read (words e)::[Int]\n d2=[0,31,28,31,30,31,30,31,31,30,31,30,31]!!m\n d3=d2-(8-d)\n print $ 1+d3 `div` 7+if d3 `mod` 7>0 then 1 else 0", "src_uid": "5b969b6f564df6f71e23d4adfb2ded74"} {"source_code": "main = interact $ show . solve . map read . words\nsolve [a1,a2] = go a1 a2 where\n go 0 _ = 0\n go _ 0 = 0\n go 1 1 = 0\n go a1 a2 | a1 > a2 = 1 + go (a1-2) (a2+1)\n | otherwise = 1 + go (a1+1) (a2-2)\n", "src_uid": "ba0f9f5f0ad4786b9274c829be587961"} {"source_code": "import Data.List\nimport Data.Maybe\nimport Data.Char\nmain= readsolveprint \nreadsolveprint::IO()\nreadsolveprint = interact $ solve.map read. words. head. lines\nsolve :: [Integer]->String\nsolve [1,0]= \"0 0\"\nsolve [x1,x2] = unwords $ map (foldr (\\ a b-> (show a) ++ b) \"\") $ if head (snd ff)/=0 || head (fst ff)==0 then [[-1],[-1]] else [if head ffff ==0 then g ffff else ffff,fff ] where\n g (a:as) = let (a1,a2:a2s)=break (/=0) as in [1]++a1++[a2-1]++a2s \n ffff =reverse fff\n fff=fst ff\n ff=splitAt (fromIntegral x1) $ (\\ns-> zipWith (\\a b-> a-b) ns (tail ns ++ [0])) $ scanl f x2 [1..x1]\n f b a = if b-9>0 then b-9 else 0", "src_uid": "75d062cece5a2402920d6706c655cad7"} {"source_code": "calc :: Integer -> Integer\ncalc a =\n if a == 1 then \n 0\n else \n if a `mod` 2 == 0 then \n a `div` 2\n else \n a\n\n\nmain :: IO ()\nmain = do\n s <- getLine\n let a = read s :: Integer\n print $ calc (a + 1)\n", "src_uid": "236177ff30dafe68295b5d33dc501828"} {"source_code": "{-# LANGUAGE DeriveFunctor #-}\nimport Control.Applicative ((<$>))\nimport Data.Array hiding ((//))\niLn :: IO [Integer]\niLn = getLine >>= (return . fmap (read) . words)\n\nmain = do\n [k,pa,pb] <- iLn\n print (ex k pa pb)\n\nre a = powMod 1000000007 a 1000000005\n\na // b = (a * re b) `mod` 1000000007\na .* b = (a * b) `mod` 1000000007\n\nex k pa pb = e 0 k\n where\n me = ((memoize e))\n e 0 k = me 1 k\n e n k = if n >= k\n then n+ab `mod` 1000000007\n else (a*(me(n+1)k)+b*(n+me n (k-n))) `mod` 1000000007\n a = pa//(pa+pb)\n b = pb//(pa+pb)\n ab= a//b\n\nmemoize f n k = ((array (0,1009) [(i,array (0,1009) [(j,f i j)|j<-[0..1009]])|i<-[0..1009]])!n)!k\n\npowMod :: Integral a => a -> a -> a -> a\npowMod _ _ 0 = 1\npowMod m x 1 = x `mod` m\npowMod m x n\n | even n = powMod m modSquare (n`div`2)\n | otherwise = (x * powMod m modSquare ((n-1)`div`2)) `mod` m\n where modSquare = x * (x `mod` m)\n", "src_uid": "0dc9f5d75143a2bc744480de859188b4"} {"source_code": "module Main where\nimport qualified Data.ByteString.Char8 as B\nimport Control.Monad \nimport Control.Applicative\n\nreadInt = maybe undefined fst . B.readInt\nreadInts = (readInt <$>) . B.words\n\ndivu a b = (a + b - 1) `div` b\n\nsolve n t k d = n2 >= n\n where\n t1 = (n `divu` k) * t\n n2 = ((t1 - t) `div` t + (t1 - d - 1) `div` t) * k\n\nmain = do \n n:t:k:d:_ <- readInts <$> B.getLine\n putStrLn $ if solve n t k d then \"YES\" else \"NO\"\n", "src_uid": "32c866d3d394e269724b4930df5e4407"} {"source_code": "import Array\nimport Data.List\n\nisDivisor :: Integral a => a -> a -> Bool\nisDivisor m n = m `rem` n == 0\n\nprimes :: [Int]\nprimes = 2 : filter isPrime [3, 5 ..]\n\nisPrime :: Int -> Bool\nisPrime n = all (not . isDivisor n) (takeWhile (\\x -> not $ x * x > n) primes)\n\nfactorize :: Int -> [Int]\nfactorize 0 = []\nfactorize n = factorize' n primes\n where\n factorize' 1 _ = []\n factorize' n (p:ps)\n | r == 0 = p : factorize' q (p:ps)\n | q < p = [n] -- i.e. p * p > n\n | otherwise = factorize' n ps\n where\n (q, r) = quotRem n p\n\nfactorizations :: Array Int [Int]\nfactorizations = listArray (1,100) $ map factorize [1..]\n\nsolve :: [Int] -> Int\nsolve [a, b, c] = sum' [solve' i j k | i <- [1..a], j <- [1..b], k <- [1..c]]\n where\n solve' i j k = solve'' $ concatMap (factorizations !) [i, j, k]\n solve'' = product . map (+1) . map length . group . sort\n sum' = foldl' (+) 0\n\nmain :: IO ()\nmain = fmap (map read . words) getLine >>= print . solve", "src_uid": "4fdd4027dd9cd688fcc70e1076c9b401"} {"source_code": "import Data.Char\n\nmain :: IO()\nmain = do interact (gao . filter isPrint . unlines . lines)\n where gao p\n | p == reverse p = \"YES\"\n | otherwise = \"NO\"\n", "src_uid": "6a5fe5fac8a4e3993dc3423180cdd6a9"} {"source_code": "import Data.Char (isSpace)\nimport qualified Data.ByteString as BS\nimport qualified Data.ByteString.Char8 as BSC\n\ncheck box vas apos aneg \n\n | vas > box = apos\n | vas < 0 = aneg\n | otherwise = 0\n\nmain :: IO ()\nmain =\n do all <- BS.getContents\n let Just ((v1,v2,v3), r1) = readTuple3 all\n let Just ((rec1,rec2,rec3), r2) = readTuple3 r1\n let Just ((a1,a2,a3,a4,a5,a6), _) = readTuple6 r2\n let result = (check rec1 v1 a6 a5) + (check rec2 v2 a2 a1) + (check rec3 v3 a4 a3)\n putStr $ show result ++ \"\\n\"\n where readInt s = BSC.readInt (BSC.dropWhile isSpace s)\n readTuple3 s = do (x1, r1) <- readInt s\n (x2, r2) <- readInt r1\n (x3, r3) <- readInt r2 \n return ((x1,x2,x3),r3)\n readTuple6 s = do (x1, r1) <- readInt s\n (x2, r2) <- readInt r1\n (x3, r3) <- readInt r2 \n (x4, r4) <- readInt r3\n (x5, r5) <- readInt r4\n (x6, r6) <- readInt r5\n return ((x1,x2,x3,x4,x5,x6),r6)\n", "src_uid": "c7889a8f64c57cf7be4df870f68f749e"} {"source_code": "import Data.List\nimport Data.Function\nimport Data.Char\nimport Data.Maybe\nimport qualified Data.ByteString.Lazy.Char8 as B\n\n--getIntArray :: B.ByteString -> [Int]\n--getIntArray = map fst . mapMaybe B.readInt . B.words\n\nmain = interact $ show . sol . map read . words\n\nsol :: [Double] -> Double\nsol (1:m:_) = 1\nsol (n:1:_) = 1 / n\nsol (n:m:_) = (n * m - 1 + (m - 1) * (n - 1)) / (n * n * m - n)\n", "src_uid": "0b9ce20c36e53d4702869660cbb53317"} {"source_code": "main = do\n m <- readLn\n print $ f2 m\nf :: Int -> Int\nf x = quot (product [x..(2*(x-1))]) (product [1..x-1]) -- binomial (2(x-1), x-1)\nf2 :: Int -> Int\nf2 x = if (x/=10) then quot (product [x..(2*(x-1))]) (product [1..x-1]) else 48620", "src_uid": "2f650aae9dfeb02533149ced402b60dc"} {"source_code": "import Data.List\n--import Control.Applicative\nimport Control.Monad\n\nposs :: Int -> [(Int, Int)]\nposs n = [ (x,y) | x <- [0 .. n-1], y <- [0 .. n-1], x==y || (x+y)==(n-1) || x+1==mid' || y+1==mid']\n where mid' = (n `div` 2) + 1\n\npositions :: Int -> [Int]\npositions n = map flattered (poss n)\n where flattered (x,y) = (n * x) + y\n\nsm :: [[Int]] -> Int -> Int\nsm matrix n =\n foldl add' 0 poslist\n where poslist = positions n\n flatmatrix = foldl (++) [] matrix\n add' acc x = (flatmatrix !! x) + acc\n\nmain = do\n ns <- getLine\n let n = read ns :: Int\n slist <- replicateM n getLine\n let rint x = read x :: Int\n let imap = map rint . words\n let matrix = map imap slist\n print $ sm matrix n", "src_uid": "5ebfad36e56d30c58945c5800139b880"} {"source_code": "import Control.Monad\n\nmain = getTwoLines >>= putStrLn . decide\n\ngetTwoLines :: IO (Int, String)\ngetTwoLines = liftM2 toTuple getLine getLine\n where toTuple a b = (read a, b)\n \ndecide :: (Int, String) -> String\ndecide (n, str) = decide' flightsCount\n where flightsCount = foldr count (0, 0) [1..n - 1]\n count i (sf, fs)\n | lst == 'F' && curr == 'S' = (sf, fs + 1)\n | lst == 'S' && curr == 'F' = (sf + 1, fs)\n | otherwise = (sf, fs)\n where lst = str !! (i - 1)\n curr = str !! i\n \ndecide' :: (Int, Int) -> String\ndecide' (sf, fs) = if sf > fs then \"yes\" else \"no\"", "src_uid": "ab8a2070ea758d118b3c09ee165d9517"} {"source_code": "isSubseq :: String -> String -> Bool\nisSubseq x [] = null x\nisSubseq [] x = True \nisSubseq xxs@(x:xs) (y:ys) = if x == y then isSubseq xs ys else isSubseq xxs ys \nendings = map show [0,8..992]\nsolve num = case f of {[] -> \"NO\"; (h:_) -> \"YES\\n\" ++ h}\n where f = filter (`isSubseq` num) endings\nmain = putStrLn.solve =<< getLine", "src_uid": "0a2a5927d24c70aca24fc17aa686499e"} {"source_code": "import Data.List\n\ncalc :: Integer->Integer->Integer\ncalc n m = foldl1 f.genericReplicate n$m\n\twhere f a b = (a*b)`mod`1000000007\n\t\nresult [n,m,k]\n\t| k == 1 = calc n m\n\t| k == n = calc (a+b) m\n\t| k > n = calc n m\n\t| even k = m\n\t| odd k = m*m\n\twhere (a,b) = n `divMod` 2\n\nmain=interact$show.result.map read.words\n", "src_uid": "1f9107e8d1d8aebb1f4a1707a6cdeb6d"} {"source_code": "main = getContents >>= print . solve . map read . words\n\nsolve (a:b:c:n:_) = if a < n && b < n && c <= a && c <= b && 0 < d && d <= n then d else -1\n where d = n - (a + b - c)\n", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce"} {"source_code": "main = interact $ show . testcase . map read . words\n\nmodulo :: Integer\nmodulo = 1000000009\n\ntestcase :: [Integer] -> Integer\ntestcase [n,m] = if start < n then 0 else ans\n where\n start :: Integer\n start = (2 ^ m - 1) `mod` modulo -- Got to love Haskell\n ans :: Integer\n ans = foldl (\\a b -> (a * b) `mod` modulo) 1 $ take (fromInteger n) $ iterate pred start\n", "src_uid": "fef4d9c94a93fcf6d536f33503b1d4b8"} {"source_code": "{-# LANGUAGE ScopedTypeVariables #-}\n{-# LANGUAGE BangPatterns #-}\n\nimport Control.Applicative\nimport Control.Monad\nimport Control.Arrow\nimport Data.List\nimport Data.Maybe\nimport Data.Char\nimport qualified Data.ByteString.Char8 as B\nimport Text.Printf\n\nimport Data.Ratio\n\nreadInt = ( readLn :: IO Int )\nreadInts = map ( read :: String -> Int ) . words <$> getLine\n\ngetList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine\n\nwhich a b f = if f then a else b\nmp [ a, b ] = ( a, b )\n\nmain = do\n\t[ h, m, s, t1, t2 ] <- readInts\n\tlet\n\t\tss = s % 1\n\t\tmm = m % 1 + s % 60\n\t\thh = ( ( h `mod` 12 ) % 1 + mm / 60 ) * 5\n\t\tgs = map ( ( min t1 t2 % 1 * 5 ) < ) [ ss, mm, hh ]\n\t\tls = map ( ( < max t1 t2 % 1 * 5 ) ) [ ss, mm, hh ]\n\t\tands = zipWith (&&) gs ls\n\tputStrLn $ which \"YES\" \"NO\" $ all ( head ands == ) ands\n", "src_uid": "912c8f557a976bdedda728ba9f916c95"} {"source_code": "import Data.Array\nimport Control.Arrow\nimport Data.List\nprimes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71]\n\nchange i l y = take i l ++ [y] ++ drop (i+1) l\ngo p l = map (:l) (takeWhile (<60) (iterate (*p) p)) ++ [change i l y|(i,x)<-zip [0..] l,y<-takeWhile(<60)(iterate (*p) (x*p))]\n\nxx = map sort $ go 2 [] >>= go 3 >>= go 5 >>= go 7 >>= go 11 >>= go 13 >>= go 17 >>= go 19 >>= go 23 >>= go 29 >>= go 31 >>= go 37 >>= go 41 >>= go 43 >>= go 47 >>= go 53 >>= go 59 :: [[Integer]]\n\n\nisOk l = all p l where\n p x = length (filter (\\y -> gcd x y /= 1) l) == 1\nisMaximal mx l = all p [2..mx] where\n p x = any (\\y -> gcd x y /= 1) l\n\nxxGood = all isOk xx && all (isMaximal 60) xx\n\n-- main = print $ length xx\ncountBF = goOnes where\n goOnes nonOnes [] = (0, [])\n goOnes nonOnes (t : ts) = min ((+(t - 1)) *** (1:) $ goOnes nonOnes ts) (goNonOnes nonOnes (t : ts))\n goNonOnes nonOnes [] = (0, [])\n goNonOnes (no : nos) (t : ts) =\n min\n ((abs (no - t) +) *** (no:) $ goNonOnes nos ts)\n (goNonOnes nos (t : ts))\n goNonOnes [] (_ : _) = (1000000000, [])\ncount nonOnes target = second reverse $ dp ! (length nonOnes, length target) where\n nonOnesArr = listArray (0, length nonOnes - 1) nonOnes\n targetArr = listArray (0, length target - 1) target\n -- key: number of nonOnes used or skipped; number of targets filled\n -- result: minimum sum of differences\n dp =\n array ((0, 0), (length nonOnes, length target))\n [ ((i,j),\n if j == 0 then (0, [])\n else\n if i == 0 then ((+(targetArr ! (j - 1) - 1)) *** (1 :) $ dp ! (i, j-1))\n else\n min\n (dp ! (i-1, j)) -- skip a non-one\n (((+ abs (nonOnesArr ! (i-1) - targetArr ! (j - 1))) *** (nonOnesArr ! (i-1) : )) $ dp ! (i-1, j-1)))\n | i<-[0..length nonOnes], (j,t)<-(0,undefined) : zip[1..] target]\n\nprop1 x y = countBF x y == count x y\n\ns target = map snd $ sort $ zip indices sol where\n (target', indices) = unzip $ sort (zip target [0..])\n sol = snd $ minimum $ [count nonOnes target'|nonOnes<-xx]\nmain = interact $ unwords . map show . s . map read . tail . words\n", "src_uid": "f26c74f27bbc723efd69c38ad0e523c6"} {"source_code": "main :: IO ()\nmain = readLn >>= putStrLn . solve\n\nsolve :: Int -> String\nsolve n | n < 20 = [ \"zero\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\", \"ten\", \"eleven\", \"twelve\", \"thirteen\", \"fourteen\", \"fifteen\", \"sixteen\", \"seventeen\", \"eighteen\", \"nineteen\" ] !! n\n | n `mod` 10 == 0 = [ \"zero\", \"ten\", \"twenty\", \"thirty\", \"forty\", \"fifty\", \"sixty\", \"seventy\", \"eighty\", \"ninety\" ] !! div n 10\n | otherwise = solve (10 * div n 10) ++ \"-\" ++ solve (mod n 10)\n", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7"} {"source_code": "module Main where\nimport Control.Applicative\nimport Control.Monad\nimport Data.Char\nimport Data.Ord\nimport Data.List\nimport Data.Maybe\n\nmain :: IO ()\nmain = do\n _ <- getLine\n ds <- getLine\n print $ sol ds\n\nsol :: String -> Integer\nsol = foldr1 (\\i a -> i+10*a) . sort . concat . \n map (f . fromIntegral . flip (-) (ord '0') . ord)\n where\n f i = case i of\n 0 -> []\n 1 -> []\n 4 -> [2,2,3]\n 6 -> [3,5]\n 8 -> [2,2,2,7]\n 9 -> [2,3,3,7]\n _ -> [i]\n", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398"} {"source_code": "import Data.List\nimport Debug.Trace\n\npow x 0 = 1\npow x y = x * pow x (y-1)\n\nhantei 1 b t n = 1 + n * b <= t\nhantei k b t n = \n t*(k-1) >= pow k n * ( k + b - 1) - b\n\nsolve k b n t = \n let m = head $ filter (not . hantei k b t) [0,1..n] ++ [n+1] in\n n - m + 1\n\nmain :: IO ()\nmain = do\n str <- getLine\n let [k,b,n,t] = map read $ words str in\n putStrLn $ show (solve k b n t) \n \n", "src_uid": "e2357a1f54757bce77dce625772e4f18"} {"source_code": "main :: IO ()\nmain = getLine >>= putStrLn . unwords . map show . solve . map read . words\n\nsolve :: [Int] -> [Int]\nsolve [a, b] = [ length [ k | k <- [1..6], abs (k - a) < abs (k - b) ],\n length [ k | k <- [1..6], abs (k - a) == abs (k - b) ],\n length [ k | k <- [1..6], abs (k - a) > abs (k - b) ] ]\nsolve _ = undefined\n", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8"} {"source_code": "import Data.List\nsolve [a,b,c] = maximum [a+(b*c),a*b*c,a+b+c,(a+b)*c,a*(b+c)]\nmain = interact $ show . solve . map read . words\n", "src_uid": "1cad9e4797ca2d80a12276b5a790ef27"} {"source_code": "{-(c) gorlum0 [at] gmail.com-}\nimport qualified Data.IntSet as S\n\nmain = do\n l <- getLine\n ws <- words `fmap` getLine\n let n = read l :: Int\n kinds = S.toAscList . S.fromList $ map read ws\n fits = or [b`div`a < 2 | (a, b) <- zip kinds $ tail kinds]\n putStrLn $ if fits then \"YES\" else \"NO\"\n", "src_uid": "ab003ab094931fc105384df9d144131e"} {"source_code": "import Data.List\n\nmain :: IO()\nmain = print . solve . map read . words =<< getContents\n\nsolve :: [Int] -> Int\nsolve (n:d:t) =\n let minTime = (sum t) + (n - 1) * 10\n in if minTime > d then -1 else (n - 1) * 2 + (div (d - minTime) 5)\n", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea"} {"source_code": "{-# LANGUAGE UnicodeSyntax #-}\n{-# OPTIONS_GHC -O3 -optc-O3 -funbox-strict-fields #-}\nimport Control.Applicative\nimport Data.Array\nimport Data.Int\n\nmodulo :: Int\nmodulo = 10^9 + 7\n\na +. b = (a + b) `rem` modulo\n\nbuild k = a\n\twhere\n\t\ta = listArray (0, k) [listArray (0, k) [count' i j | j ← [0..k]] | i ← [0..k]]\n\t\tcount' i j\n\t\t\t| j == 0 = 1\n\t\t\t| j <= i = (a ! (i-1) ! (j-1)) +. (a ! (i-1) ! j)\n\t\t\t| otherwise = 0\n\nmain = do\n\t[n, m, k] ← map read . words <$> getLine\n\tlet a = build $ (max n m) - 1\n\n\tlet c1 = if 2*k <= n-1 then a ! (n-1) ! (2*k) else 0\n\tlet c2 = if 2*k <= m-1 then a ! (m-1) ! (2*k) else 0\n\n\tprint $ (fromIntegral c1) * (fromIntegral c2) `rem` ((fromIntegral modulo) :: Int64)\n", "src_uid": "309d2d46086d526d160292717dfef308"} {"source_code": "\nmain = interact $ unwords . map show . sol . map read . words\n\n\nsol (l:r:_)\n | (odd l && r-l < 3) = [-1]\n | r-l < 2 = [-1]\n | odd l = [l+1, l+2, l+3]\n | otherwise = [l, l+1, l+2]\n\n", "src_uid": "6c1ad1cc1fbecff69be37b1709a5236d"} {"source_code": "import Data.List\nimport Control.Monad\n\nmod' :: Int\nmod' = 1000000007\n\nadd :: Int -> Int -> Int\nadd a b = mod (a + b) mod'\n\n\nsolve :: [Int] -> Int\nsolve [n, k, d] = solve' n !! 1 !! 0\n where \n solve' 0 = [[1], [0]]\n solve' n = [a:dp1, (add (b-a) mod'):dp2]\n where [dp1, dp2] = solve' (n - 1)\n a = foldl add 0 $ take (d - 1) dp1\n b = foldl add 0 $ concat $ map (take k) [dp1, dp2]\n \n\n\nmain = getLine >>= (putStrLn . show . solve . (map read) . words)", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d"} {"source_code": "module Main where\n\nimport Data.List\n\nmain = do\n input <- getContents\n let pole = concat $ take 3 $ lines input\n putStrLn $ solve pole where\n \n solve pole = case stroke of\n \"-\" -> \"illegal\"\n _ -> case won of\n \"all\" -> \"illegal\"\n \"-\" -> if filled then \"draw\"\n else stroke\n _ -> if stroke == won then \"illegal\"\n else \"the \" ++ won ++ \" player won\"\n where\n \n -- заполнено ли поле полностью?\n filled = all (/='.') pole\n \n -- чей следующий ход?\n stroke = if countX == countO\n then \"first\"\n else if countX == (countO + 1) then \"second\"\n else \"-\"\n countX = count 'X'\n countO = count '0'\n count c = length $ filter (==c) pole\n \n -- кто победитель (all/first/second/-)?\n won = if wonX && wonO\n then \"all\"\n else if wonX\n then \"first\"\n else if wonO then \"second\"\n else \"-\"\n wonX = isWinner 'X'\n wonO = isWinner '0'\n isWinner c = \n -- по горизонтали\n ((pole!!0) == c && (pole!!1) == c && (pole!!2) == c) ||\n ((pole!!3) == c && (pole!!4) == c && (pole!!5) == c) ||\n ((pole!!6) == c && (pole!!7) == c && (pole!!8) == c) ||\n -- по вертикали\n ((pole!!0) == c && (pole!!3) == c && (pole!!6) == c) ||\n ((pole!!1) == c && (pole!!4) == c && (pole!!7) == c) ||\n ((pole!!2) == c && (pole!!5) == c && (pole!!8) == c) ||\n -- по диагонали\n ((pole!!0) == c && (pole!!4) == c && (pole!!8) == c) ||\n ((pole!!2) == c && (pole!!4) == c && (pole!!6) == c)\n", "src_uid": "892680e26369325fb00d15543a96192c"} {"source_code": "-- Codeforces 911C\n\n{-# OPTIONS_GHC -O2 #-}\n{-# OPTIONS_GHC -optc-O2 #-}\n{-# LANGUAGE BangPatterns #-}\n{-# LANGUAGE MultiWayIf #-}\n{-# LANGUAGE OverloadedStrings #-}\n\nimport Control.Applicative\nimport qualified Data.ByteString.Char8 as BC\nimport Data.List\nimport Data.Maybe\n\nmain :: IO ()\nmain = do\n [k1, k2, k3] <- (sort . map (fst . fromJust . BC.readInt) . BC.words) <$> BC.getLine :: IO [Int]\n putStrLn $ if | k1 == 1 -> \"YES\"\n | k1 == 2 && k2 == 2 -> \"YES\"\n | k1 == 3 && k2 == 3 && k3 == 3 -> \"YES\"\n | k1 == 2 && k2 == 4 && k3 == 4 -> \"YES\"\n | otherwise -> \"NO\"\n", "src_uid": "df48af9f5e68cb6efc1214f7138accf9"} {"source_code": "import Control.Applicative\nimport Data.List\n \nprocess m [] [x] = snd x\nprocess m s [] = process m [] (reverse s)\nprocess m s (x:xs) | fst x <=m = process m s xs\n | otherwise = process m (((fst x-m),snd x):s) xs\n \nmain=do\t \n\t[n,m]<-map read.words <$> getLine:: IO [Int] \n\ts<-map read. words <$> getLine:: IO [Int]\n\tprint $ process m [] $ zip s [1..]\n\n", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c"} {"source_code": "-- This solution uses generating functions to totally overkill the\n-- problem, and uses Integer multiplication to perform the necessary\n-- convolutions. Since that doesn't rely on any number theory tricks,\n-- it works nicely with any modulus, and not just the classic\n-- FFT-friendly prime 998244353 = 1 + 7 * 17 * 2^23.\n\n-- Yes, I know there's an easier solution using Burnside's lemma\n-- and derangements. But implementing this one is worth it, too.\n\n-- My implementation is probably not that efficient. But the time\n-- limit is rather large, so it might get AC anyway.\n\n{-# LANGUAGE MagicHash, ScopedTypeVariables, UnboxedTuples #-}\n{-# OPTIONS_GHC -Wno-unbanged-strict-patterns #-}\n\nimport qualified Data.ByteString.Lazy.Char8 as P\nimport Data.ByteString.Builder\nimport qualified Data.ByteString.Builder.Prim as Prim\nimport System.IO\nimport Control.Monad.Trans.State\nimport Data.Maybe\n\n--import Data.ByteString.Builder.Extra (flush) -- for interactive problems\nimport Control.Monad\nimport Data.List\nimport Data.Array.Unboxed\n\nimport Data.Bits\nimport Data.Semigroup\nimport Data.Array.ST.Safe\n\nimport GHC.Exts\nimport GHC.Integer.GMP.Internals\nimport GHC.IO\nimport GHC.ST\n\n\nmainFun :: SP Builder\nmainFun = do\n n <- getInt\n k0 <- getInt\n let\n k = min n k0 -- no larger amount will help\n\n facts :: UArray Int Int\n facts = listArray (0, n) $ scanl' (*!) 1 [1 .. n]\n ifacts :: UArray Int Int\n ifacts = array (0, n) $ take (n + 1)\n $ iterate (\\(i, v) -> (i - 1, v *! i)) (n, inv (facts ! n))\n{-\n display :: Integer -> Builder\n display = putInts . map fromIntegral . snd . toWordList\n-}\n inv' :: Int -> Int\n inv' x = ifacts ! x *! facts ! (x - 1)\n\n antideriv :: Integer -> Integer\n antideriv x = case toWordList x of\n (sz, ws) -> makeInteger (sz + 1) $ 0 : let\n div' i z = fromIntegral $ inv' i *! fromIntegral z\n in zipWith div' [1..] ws\n\n g, gk1, eg :: Integer\n g = makeInteger (n + 1) $ 0 : tail (map fromIntegral $ elems ifacts)\n gk1 = calcPow (n - k) antideriv (g `shiftR` 128) (k + 1)\n `shiftL` (128 * (k + 1))\n eg = calcExp (n + 1) antideriv g\n\n hetero = if k < n\n then conv (n + 1) gk1 (fromIntegral $ 0 -! ifacts ! (k + 1))\n else 0\n integrand = conv n (inverse n eg) (derivative hetero)\n\n unG_soln = conv (n + 1) eg $ 1 + antideriv integrand\n\n unG_solnArr :: UArray Int Int\n unG_solnArr = listArray (0, n) $ case toWordList unG_soln of\n (_, li) -> zipWith (*!) (elems facts) $ map fromIntegral li ++ repeat 0\n\n ceilDiv x y = case x `divMod` y of\n (q, 0) -> q\n (q, _) -> q + 1\n\n toMobiusArr :: UArray Int Int\n toMobiusArr = array (1, n) [(i, unG_solnArr ! ceilDiv n i) | i <- [1..n]]\n\n ansArr = runSTUArray $ do\n arr :: STUArray s Int Int <- thaw toMobiusArr\n forM_ [n-1, n-2 .. 1] $ \\i -> do\n pval <- readArray arr i\n nval <- (\\fun -> foldM fun pval $ n : [2*i, 3*i .. n-1]) $ \\acc j -> do\n nval <- readArray arr j\n pure $ acc -! nval\n writeArray arr i nval\n pure arr\n\n ans = if k == 1 && n > 1\n then 1 -- only here are seed arrays of block size (> 1) needed\n else ansArr ! 1\n pure $ putInts [ans]\n\n\n-------------------------------------------------------------------------------\n-- Modular arithmetic\n-------------------------------------------------------------------------------\n\np :: Int\np = 998244353\n{-\n(+!) :: Int -> Int -> Int\ninfixl 6 +!\nx +! y = x + y -! p\n-}\n(-!) :: Int -> Int -> Int\n-- branchless subtraction modulo p\ninfixl 6 -!\nx -! y = let\n raw = x - y\n in raw + (p .&. shiftR raw 63)\n\n(*!) :: Int -> Int -> Int\ninfixl 7 *!\nx *! y = let\n I# raw = x * y\n in I# (word2Int# (remP (int2Word# raw)))\n\nquotP :: Word# -> Word#\nquotP v = let\n (# hi, _lo #) = timesWord2# 9920937979283557439## v\n -- the magic number is ceiling(2^(64+29) / p)\n -- The approximation is accurate enough to calculate the exact\n -- quotient with one multiply and one shift for all valid Word#\n in shiftRL# hi 29#\n\nremP :: Word# -> Word#\nremP v = let\n I# p# = p\n in v `minusWord#` timesWord# (quotP v) (int2Word# p#)\n\nremP2 :: Word# -> Word# -> (# Word#, Word# #)\nremP2 hi lo = let\n -- This implementation cheats a bit in order to be a tiny bit\n -- faster. It assumes the high word should be at most 26_401_116_612,\n -- and gives a result in [0..2p-2] instead of [0..p-1].\n I# p# = p\n (# redHi, _ #)\n = int2Word# p# `timesWord2#` timesWord# 17223561541331522433## hi\n in (# 0##, redHi `plusWord#` remP lo #)\n\nnewtype ModP = ModP { unModP :: Int }\ninstance Semigroup ModP where\n ModP x <> ModP y = ModP (x *! y)\n stimes = stimesMonoid\ninstance Monoid ModP where\n mempty = ModP 1\n\ninv :: Int -> Int\ninv = unModP . stimes (p - 2) . ModP\n\n\n-------------------------------------------------------------------------------\n-- Generating function / polynomial stuff\n-------------------------------------------------------------------------------\n\nnormalizeP :: Int -> Integer -> Integer\nnormalizeP = normalize remP2\n\nconv :: Int -> Integer -> Integer -> Integer\nconv prec x y = normalizeP prec $ x * y\n\nnegateFields :: Int -> Integer -> Integer\nnegateFields = let\n I# p# = p\n negateOne hi lo = case inline remP2 hi lo of\n (# _, nlo #) -> (# 0##, int2Word# (p# `iShiftL#` 1#) `minusWord#` nlo #)\n in normalize negateOne\n\ninverse :: Int -> Integer -> Integer\n-- Newton's method\ninverse prec x = if prec <= 1\n then toInteger $ inv $ fromInteger x\n else let\n subPrec = (prec + 1) `div` 2\n subAns = inverse subPrec (truncateAt subPrec x)\n approx = negateFields prec $ x * subAns\n in normalizeP prec $ subAns * (2 + approx)\n\nderivative :: Integer -> Integer\nderivative x = case toWordList x of\n (n, ws) -> makeInteger (n - 1) $ do\n (i, xi) <- zip [1 ..] (tail ws)\n pure $ fromIntegral (i *! fromIntegral xi)\n\ncalcLog :: Int -> (Integer -> Integer) -> Integer -> Integer\ncalcLog prec antideriv x = let\n prec' = max 0 $ prec - 1\n in antideriv $ conv prec' (derivative x) (inverse prec' x)\n\ncalcExp :: Int -> (Integer -> Integer) -> Integer -> Integer\ncalcExp prec antideriv x = if prec <= 1\n then 1\n else let\n subPrec = (prec + 1) `div` 2\n subAns = calcExp subPrec antideriv (truncateAt subPrec x)\n err = x + negateFields prec (calcLog prec antideriv subAns)\n in conv prec subAns (1 + err)\n\ncalcPow :: Int -> (Integer -> Integer) -> Integer -> Int -> Integer\ncalcPow prec antideriv x k = let\n logx = calcLog prec antideriv x\n in calcExp prec antideriv $ conv prec logx (fromIntegral k)\n\n\n-------------------------------------------------------------------------------\n-- Integer internals manipulation\n-------------------------------------------------------------------------------\n\nmakeInteger :: Int -> [Word] -> Integer\n-- Interprets a list of Words as a little-endian base-(2^128) Integer.\n-- Uses internal ByteArray# interface to do it quickly, because sadly\n-- 'GHC.Num.Integer.integerFromWordList' doesn't exist yet in 8.10.1.\n{-# INLINE [1] makeInteger #-}\n{-# ANN makeInteger \"HLint: ignore Redundant lambda\" #-}\n-- 'step' is applied to only two arguments if this fuses\nmakeInteger (I# n) li = runST $ ST $ \\(s0 :: State# s) -> let\n numBytes = iShiftL# n 4#\n (# s1, marr #) = newByteArray# numBytes s0\n s2 = setByteArray# marr 0# numBytes 0# s1\n step :: Word -> (Int# -> State# s -> State# s)\n -> Int# -> State# s -> State# s\n step (W# val) cont = \\off s3\n -> cont (off +# 2#) (writeWord64Array# marr off val s3)\n s4 = foldr step (\\_ s -> s) li 0# s2\n (# s5, arr #) = unsafeFreezeByteArray# marr s4\n in (# s5, importIntegerFromByteArray arr 0## (int2Word# numBytes) 0# #)\n\nintegerToMutableByteArray\n :: Int -> Integer -> State# RealWorld\n -> (# State# RealWorld, MutableByteArray# RealWorld, Int# #)\nintegerToMutableByteArray maxNumFields val s0 = let\n numInputBytes = sizeInBaseInteger val 256#\n numOrigFields = iShiftRL# (word2Int# numInputBytes +# 15#) 4#\n bufferSize = iShiftL# numOrigFields 4#\n (# s1, arr #) = newByteArray# bufferSize s0\n s2 = setByteArray# arr (bufferSize -# 16#) 16# 0# s1\n (# s3, _ #) = unIO (exportIntegerToMutableByteArray val arr 0## 0#) s2\n I# numFields = maxNumFields `min` I# numOrigFields\n (# s4, arr' #) = resizeMutableByteArray# arr numFields s3\n in (# s4, arr', numFields #)\n\ntoWordList :: Integer -> (Int, [Word])\ntoWordList val = let\n (# n, arr #) = runRW# $ \\s0 -> let\n (# s1, marr, numFields #) = integerToMutableByteArray maxBound val s0\n (# _, farr #) = unsafeFreezeByteArray# marr s1\n in (# numFields, farr #)\n stopOff = iShiftL# n 1#\n in (,) (I# n) $ build $ \\cons nil -> let\n go off = if isTrue# (off <# stopOff)\n then W# (indexWord64Array# arr off) `cons` go (off +# 2#)\n else nil\n in go 0#\n\nnormalize\n :: (Word# -> Word# -> (# Word#, Word# #)) -> Int -> Integer -> Integer\n-- If the Integer is understood as an array of Word128s, this uses\n-- the first argument to update each field. This allows replacing\n-- the rather slow 'quotRemWord2#' with something faster...\n{-# ANN normalize \"HLint: ignore Redundant lambda\" #-}\n{-# INLINE normalize #-} -- It should specialize, given only one arg!\nnormalize fun = \\prec x -> runRW# $ \\s0 -> let\n (# s1, marr, numFields #) = integerToMutableByteArray prec x s0\n go off s2 = if isTrue# (off >=# 0#)\n then let\n (# s3, hi #) = readWord64Array# marr (off +# 1#) s2\n (# s4, lo #) = readWord64Array# marr off s3\n (# nhi, nlo #) = fun hi lo\n s5 = writeWord64Array# marr (off +# 1#) nhi s4\n s6 = writeWord64Array# marr off nlo s5 -- copy-paste is dangerous...\n in go (off -# 2#) s6\n else s2\n s7 = go (iShiftL# (numFields -# 1#) 1#) s1\n (# _s8, arr #) = unsafeFreezeByteArray# marr s7\n numBytes = int2Word# numFields `shiftL#` 4#\n in importIntegerFromByteArray arr 0## numBytes 0#\n\ntruncateAt :: Int -> Integer -> Integer\ntruncateAt prec x = runRW# $ \\s0 -> let\n (# s1, marr, numFields #) = integerToMutableByteArray prec x s0\n (# _s2, arr #) = unsafeFreezeByteArray# marr s1\n numBytes = int2Word# numFields `shiftL#` 4#\n in importIntegerFromByteArray arr 0## numBytes 0#\n \n\n-------------------------------------------------------------------------------\n-- My normal library/template\n-------------------------------------------------------------------------------\n\ntype SP = State P.ByteString\ntype S = StateT P.ByteString\n\ndropSpace :: P.ByteString -> P.ByteString\ndropSpace = P.dropWhile (<= ' ') -- not exactly right, but close enough\n\n--getNext :: Monad m => S m P.ByteString\n--getNext = state $ P.span (> ' ') . dropSpace\n\ngetInt :: Monad m => S m Int\ngetInt = state $ fromJust . P.readInt . dropSpace\n\nputInts :: [Int] -> Builder\nputInts vs = let\n sepPrim = (,) ' ' Prim.>$<\n Prim.liftFixedToBounded Prim.char7 Prim.>*< Prim.intDec\n in case vs of\n [] -> char7 '\\n'\n x : xs -> intDec x <> Prim.primMapListBounded sepPrim xs <> char7 '\\n'\n\nmain :: IO ()\nmain = do\n hSetBuffering stdout NoBuffering\n inp <- P.getContents\n let outp = evalState mainFun inp\n P.putStr $ toLazyByteString outp\n", "src_uid": "eb9d24070cc5b347d020189d803628ae"} {"source_code": "main :: IO ()\nmain = do\n input <- getContents >>= return.(map read).words :: IO [Int]\n let w = input!!0\n let h = input!!1\n let u1 = input!!2\n let d1 = input!!3\n let u2 = input!!4\n let d2 = input!!5\n\n let result = foldr f w [1..h]\n where f height weight\n | height == d1 = max 0 $ weight + height - u1\n | height == d2 = max 0 $ weight + height - u2\n | otherwise = weight + height\n\n putStrLn $ show $ max 0 result\n", "src_uid": "084a12eb3a708b43b880734f3ee51374"} {"source_code": "import Ratio\nmain=interact$f.g.map read.words\ng(0:b:s)=(b*9^99%1):g s\ng(a:b:s)=(b%a):g s\ng _=[]\nf[x,y,z]|x*y*z>1%1||y>9^80||x*y>9^80=\"Ron\"|1>0=\"Hermione\"", "src_uid": "44d608de3e1447f89070e707ba550150"} {"source_code": "import Prelude\nimport Data.List\nimport Data.Maybe\nimport Data.Function\nimport Data.Char\nimport Data.Graph\nimport Data.Tree\nimport Data.Int\n--import qualified Data.HashTable.IO as B\nimport qualified Data.ByteString.Lazy.Char8 as B\n\nreadInts :: IO [Int]\nreadInts = fmap (map (foldl' (\\x y -> 10*x + digitToInt y) 0) . words) getLine\n\ntextRepresentation :: Show a => [a] -> String\ntextRepresentation row = unwords . map show $ row\n\ng [] _ = 0\ng str@(_:xs) pat\n | isPrefixOf pat str = 1 + rec\n | otherwise = rec\n where rec = g xs pat\n\nmain :: IO ()\nmain = do\n str <- getLine\n let flag = foldl (+) 0 . map (g str) $ l\n if flag == 1\n then putStr \"YES\"\n else putStr \"NO\"\n where l=[\"Danil\", \"Olya\", \"Slava\", \"Ann\" , \"Nikita\"]\n\n--индексиране на памет\n-- $! синтаксис\n--fmap\n{-main :: IO ()\nmain = do\n print 3\n where gg=H.fromList-}", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710"} {"source_code": "import Text.Printf\n\ndata Time = Time Int Int\n deriving Show\n\nmain :: IO ()\nmain = interact $ toString . stampToTime . solve . map (timeToStamp . toTime) . words\n\ntoTime :: String -> Time\ntoTime (h1:h2:':':m1:m2:[]) = Time (read [h1, h2]) (read [m1, m2])\ntoTime _ = Time 0 0\n\ntoString :: Time -> String\ntoString (Time h m) = (printf \"%02d\" h) ++ \":\" ++ (printf \"%02d\" m)\n\ntimeToStamp :: Time -> Int\ntimeToStamp (Time h m) = h * 60 + m\n\nstampToTime :: Int -> Time\nstampToTime stamp = Time (stamp `div` 60) (stamp `mod` 60)\n\nsolve :: [Int] -> Int\nsolve (s1:s2:[]) = (s2 - s1) `div` 2 + s1\nsolve _ = 0\n", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50"} {"source_code": "main=interact( (\\ [n,a,b,c]->show$length [(i,j)|i<-[0..(min c (n`div`2))],j<-[0..(min b (n-2*i))],(2*n-4*i-2*j) >= 0 && (2*n-4*i-2*j)<=a]).(map(read::String->Int)).words)", "src_uid": "474e527d41040446a18186596e8bdd83"} {"source_code": "import Data.List\n\nmain = do\n\tgetLine\n\ts <- fmap sort getLine\n\tputStrLn $ if (length s == 1) || (any (uncurry (==)) $ zip s (tail s)) then \"Yes\" else \"No\"\n", "src_uid": "6b22e93f7e429693dcfe3c099346dcda"} {"source_code": "import Control.Monad\n\nprocess :: Int -> Int -> Int -> Int -> Bool -> String\nprocess a b a' b' True\n | a < a' = \"Vladik\"\n | otherwise = process (a - a') b (a' + 2) b' False\nprocess a b a' b' False\n | b < b' = \"Valera\"\n | otherwise = process a (b - b') a' (b' + 2) True\n\nmain :: IO ()\nmain = do\n [a, b] <- liftM (map read . words) getLine\n putStr $ process a b 1 2 True", "src_uid": "87e37a82be7e39e433060fd8cdb03270"} {"source_code": "inc = (-1 +) . (2 *)\nanalyze = length >>= (. (inc . (length . (filter (== 'a'))))) . min\nmain = getLine >>= putStrLn . show . analyze", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219"} {"source_code": "module Main where\nimport qualified Data.ByteString.Char8 as B\nimport Data.Int\nimport Data.List\nimport Data.Maybe\nimport Data.Char\n\nreadInt = fst . fromJust . B.readInteger\nreadInts = fmap readInt . B.words\n\nsolve :: Int64 -> Int64 -> Int64\nsolve n s = max 0 $ (n + 1 - ) $ fromMaybe (n + 1) $ find (\\x -> x - sum (map (fromIntegral . digitToInt) $ show x) >= s) [s..n]\n\nmain = do \n n:s:_ <- fmap (map fromIntegral . readInts) B.getLine\n print $ solve n s\n", "src_uid": "9704e2ac6a158d5ced8fd1dc1edb356b"} {"source_code": "import Data.Ratio\n--\nmain :: IO()\nmain = do\n a <- getLine\n putStrLn . solve . map read $ words a\n \nsolve :: [Integer] -> String\nsolve [x,y,n] = out $ near x y n\n where out (a,b) = (show a) ++ \"/\" ++ (show b)\n\nsolve _= undefined\n\nnear :: Integer -> Integer -> Integer -> (Integer, Integer)\nnear x y n = if n >= y then (x', y')\n else snd $ minimum [(abs $ x % y - a % b, (a, b)) | b <- [1..n], let m = b * x' `quot` y', a <- [m, m + 1]]\n where\n x' = numerator $ x%y\n y' = denominator $ x%y", "src_uid": "827bc6f120aff6a6f04271bc84e863ee"} {"source_code": "{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -funfolding-use-threshold=16 -fexcess-precision -funbox-strict-fields #-}\nmodule Main where\nimport qualified Data.ByteString.Lazy.Char8 as B\nimport Control.Monad\nimport Control.Monad.Trans.State.Lazy\nimport Data.List\n\nmain = putStr . evalState app . B.words =<< B.getContents\n\ndata P = P !Int !Int !Int !Int !Int\ndata V = V !Int !Int !Int !Int !Int\n\n\napp = (\\xs -> unlines $ show (length xs):map show xs) `fmap` solve `fmap` (flip replicateM (liftM5 P poi poi poi poi poi) =<< poi)\n where\n pop = state $ \\(x:xs) -> (x, xs)\n poi = fmap int pop\n int = maybe undefined fst . B.readInt\n\nsolve = map fst . filter (\\(i, (a, bs)) -> all (uncurry good) $ pairs $ map (vec a) bs) . zip [1..] . splits\n\nsplits = map (\\(ys, x:xs) -> (x, ys ++ xs)) . init . liftM2 zip inits tails\n\npairs xs = [(a, b) | (a:bs) <- tails xs, b <- bs]\n\nvec (P a b c d e) (P a' b' c' d' e') = V (a' - a) (b' - b) (c' - c) (d' - d) (e' - e)\ngood (V a b c d e) (V a' b' c' d' e') = a*a' + b*b' + c*c' + d*d' + e*e' <= 0 ", "src_uid": "c1cfe1f67217afd4c3c30a6327e0add9"} {"source_code": "\nimport Control.Monad (liftM)\nimport Prelude hiding (reads)\n\nreads :: Read a => IO [a]\nreads = liftM (map read . words) getLine\n\nsolve :: [Int] -> Int\nsolve [x, y]\n | x == 0 && y == 0 = 0\n | x > 0 && x+y <= 1 = 4 * abs y\n | x > 0 && x-y >= 0 = 4 * x - 3\n | x > 0 = 4 * y - 2\n | x+y >= 0 = 4 * y - 2\n | x-y <= 0 = 4 * abs x - 1\n | otherwise = 4 * abs y\n\nmain :: IO ()\nmain = reads >>= print . solve\n", "src_uid": "2fb2a129e01efc03cfc3ad91dac88382"} {"source_code": "main = getLine >>= print . solve . map read . words\n\nsolve (n:pos:l:r:_)\n | 1 == l && n == r = 0\n | 1 == l && n /= r = 1 + abs (r - pos)\n | 1 /= l && n == r = 1 + abs (l - pos)\n | otherwise = 2 + r - l + (min (abs (l - pos)) (abs (r - pos)))\n", "src_uid": "5deaac7bd3afedee9b10e61997940f78"} {"source_code": "\nbreak' [] _ = False\nbreak' _ [] = True\nbreak' (x:xs) (y:ys)\n | x == y = break' xs ys\n | x /= y = break' xs (y:ys)\n\n\nmain = do\n aa <- getLine\n putStrLn $ if break' (aa++\" \") \"hello\" then \"YES\" else \"NO\"\n \n", "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838"} {"source_code": "getans :: [Integer] -> Integer\ngetans (x:y:a:b:_) = (div b (lcm x y)) - (div (a - 1) (lcm x y))\n \nmain = do\n input <- getLine\n putStr $ show $ getans (map read (words input) :: [Integer])\n", "src_uid": "c7aa8a95d5f8832015853cffa1374c48"} {"source_code": "{-# OPTIONS_GHC -rtsopts -O2 #-}\n{-# LANGUAGE BangPatterns #-} \n{-# LANGUAGE NoMonomorphismRestriction #-}\n{-# LANGUAGE ScopedTypeVariables #-}\n{-# LANGUAGE MultiWayIf #-}\n\nimport Data.Array.ST\nimport Data.Array.IArray\nimport Data.STRef\nimport Data.Bits\nimport Control.Monad.ST\nimport Control.Monad\nimport Control.Applicative\nimport qualified Data.List as L \nimport qualified Data.Set as S\nimport qualified Data.Map as M\nimport qualified Data.Function as F\nimport Debug.Trace\n\nimport qualified Numeric as N\n\nreadInt :: String -> Int\nreadInt ('-':s) = case N.readDec s of [(n, \"\")] -> -n\nreadInt s = case N.readDec s of [(n, \"\")] -> n\n\nreadFloat :: String -> Double\nreadFloat ('-':s) = case N.readFloat s of [(x, \"\")] -> -x\nreadFloat s = case N.readFloat s of [(x, \"\")] -> x\n\ngetInts :: IO [Int]\ngetInts = map readInt . words <$> getLine \n\nsolve :: Integer -> Integer -> Int -> Integer -> Integer\nsolve n k l m \n | k >= toInteger (2 ^ l) = 0\n | m == 1 = 0\n | otherwise = L.foldl' (\\a h -> (a * h) `mod` m) 1 [amount (testBit k i) | i <- [0..(l - 1)]]\n where\n np = (getNp (n - 1) m) `mod` m\n all = (getAll n m) `mod` m\n amount True = np\n amount False = all - np\n\n\ntype Mat = Array (Int, Int) Integer\n\n-- 1 x 3\nmStart :: Mat\nmStart = listArray ((0, 0), (2, 0)) [0, 1, 1]\n\n-- 3 x 3\nmOnes :: Mat\nmOnes = listArray ((0, 0), (2, 2))\n [ 1, 0, 0\n , 0, 1, 0\n , 0, 0, 1] \n\nmTransform :: Mat\nmTransform = listArray ((0, 0), (2, 2))\n [ 2, 1, 0\n , 0, 0, 1\n , 0, 1, 1\n ]\n\nmmul :: Mat -> Mat -> Mat\nmmul m1 m2 = listArray ((j0, i0), (j1, i1)) \n [sum $ zipWith (*) (getRow m1 i) (getCol m2 j) | i <- [i0..i1], j <- [j0..j1]]\n where\n ((i0, _), (i1, _)) = bounds m1\n ((_, j0), (_, j1)) = bounds m2\n\ngetRow :: Mat -> Int -> [Integer]\ngetRow m i = [m ! (i, j) | j <- [j0..j1]]\n where\n ((_, j0), (_, j1)) = bounds m\n\ngetCol :: Mat -> Int -> [Integer]\ngetCol m i = [m ! (j, i) | j <- [j0..j1]]\n where\n ((j0, _), (j1, _)) = bounds m\n\nmmod a m = amap (`mod` m) a\n\n\ngetNp :: Integer -> Integer -> Integer\ngetNp n m = ((loop n mTransform mOnes) `mmul` mStart) ! (0, 0)\n where\n loop :: Integer -> Mat -> Mat -> Mat\n loop 0 _ acc = acc\n loop n x acc = \n (loop (n `shiftR` 1)) ((x `mmul` x) `mmod` m) (if testBit n 0\n then ((acc `mmul` x) `mmod` m)\n else acc)\n\ngetAll :: Integer -> Integer -> Integer\ngetAll n m = loop n 2 1\n where \n loop :: Integer -> Integer -> Integer -> Integer\n loop 0 _ acc = acc\n loop n x acc = (loop (n `shiftR` 1)) ((x * x) `mod` m) (if testBit n 0\n then ((acc * x) `mod` m)\n else acc)\n\nmain = do\n [n::Integer, k, l, m] <- map read . words <$> getLine\n print $ solve n k (fromInteger l) m\n", "src_uid": "2163eec2ea1eed5da8231d1882cb0f8e"} {"source_code": "import Data.Ratio(numerator,denominator)\n\n\nsumOfDigit :: Int -> Int -> Int\nsumOfDigit n base | n < base = n\n | otherwise = (mod n base) + sumOfDigit (div n base) base\n\nsolve :: Int -> Rational\nsolve n = theSums / theLength\n where theSums = toRational(sum (map (sumOfDigit n) [2..n-1]))\n theLength = toRational(length [2..n-1])\n\nprettyPrint :: Rational -> [Char]\nprettyPrint r = (show (numerator r)) ++ \"/\" ++ (show (denominator r))\n\nmain = do\n inputLine <- getLine\n let n = read inputLine :: Int\n putStrLn (prettyPrint (solve n))\n\n", "src_uid": "1366732dddecba26db232d6ca8f35fdc"} {"source_code": "{-# LANGUAGE Safe #-} \n \nimport safe Control.Arrow ((>>>))\n--import safe Data.List (sort)\nimport Data.List\nimport Data.Bits\n\nmain :: IO ()\nmain = interact $ lines >>> drop 0 >>> tcio >>> unlines where\n tcio :: [String] -> [String]\n tcio [] = []\n tcio (l : rest) = (itoline . solve . linetoi) l : tcio rest \n linetoi = read;\n itoline = show;\n\nmodExp :: Integer -> Integer -> Integer -> Integer\nmodExp b 0 m = 1\nmodExp b e m = t * modExp ((b * b) `mod` m) (shiftR e 1) m `mod` m\n where t = if testBit e 0 then b `mod` m else 1\n\nsolve :: Int -> Integer\nsolve n = ((head. drop (n-1)) fib') `moddiv` (modExp 2 (toInteger n) p) where\n fib' = 1:fib\n fib = zipWith (modadd) (0:1:fib) (1:fib)\n modadd x y = (x + y) `mod` p\n moddiv x y = (x * (modExp y (p-2) p)) `mod` p\n p = 998244353 \n", "src_uid": "cec37432956bb0a1ce62a0188fe2d805"} {"source_code": "import Control.Applicative\nimport Control.Monad\n\nmain = sol <$> readLn <*> getLine >>= print\n\nsol :: Int -> String -> Int\nsol n s = min (length s `div` 11) (length $ filter (== '8') s)\n", "src_uid": "259d01b81bef5536b969247ff2c2d776"} {"source_code": "import Control.Applicative\nimport Control.Monad\nimport Data.List\n\n\t\t\n\nmain = do\n\t\t[y,b,r]<- map read <$> words <$> getLine ::IO [Int]\n\t\tlet c = minimum [y, b-1,r-2]\n\t\tprint $ c*3+3\n", "src_uid": "03ac8efe10de17590e1ae151a7bae1a5"} {"source_code": "module Main where\n\nsolve [l1, r1, l2, r2, k] = max 0 $ r - l + 1 - (if l <= k && k <= r then 1 else 0)\n where r = min r1 r2; l = max l1 l2\n\ntest = let solve x = 5 in solve 2\n\nmain :: IO ()\nmain = do\n input <- getLine\n print $ solve [read x | x <- words input]\n", "src_uid": "9a74b3b0e9f3a351f2136842e9565a82"} {"source_code": "import Data.List (sort)\nimport Debug.Trace\n\nsolve :: [Int] -> String\nsolve x\n | greatStart && greatEnd = \"C\"\n | greatStart = snd start\n | greatEnd = snd end\n | otherwise = \"C\"\n where\n track q = trace (show q) q\n vals = sort $ zip x [\"A\", \"B\", \"C\", \"D\"]\n start = head vals\n end = last vals\n greatStart = fst start <= fst (vals !! 1) `quot` 2\n greatEnd = track (fst end) >= fst (vals !! 2) * 2\n\nmain = do\n putStrLn . solve . map (length . tail . tail) . lines =<< getContents\n", "src_uid": "30725e340dc07f552f0cce359af226a4"} {"source_code": "-- import Debug.Trace\n\n\n\nproblems a b probs \n | (b == 0) = probs\n | (b < 0) = (probs-1)\n | a == (probs-1) = (probs-1)\n | otherwise = problems a (b - (5*(probs+1))) (probs+1)\n\n\nmain = do\n hh <- getLine\n let aa = (read (head (words hh)))::Int\n bb = (read (last (words hh)))::Int\n\n \n let ans = problems aa (240 - bb) 0\n putStrLn (show ans)\n\n\n \n", "src_uid": "41e554bc323857be7b8483ee358a35e2"} {"source_code": "module Main where\nimport Data.List\nimport Control.Applicative\n\nmain = do\n getLine\n ts <- nub . map (read :: String -> Int) .words <$> getLine\n let yesno x = if x then \"YES\" else \"NO\"\n putStrLn $ yesno $ not $ null [1 | x<-ts , y <-ts , z<-ts , x/=y, y/=z, x/=z, abs(x-y)<=2, abs(x-z)<=2, abs(y-z)<=2]", "src_uid": "d6c876a84c7b92141710be5d76536eab"} {"source_code": "import Control.Applicative ((<$>), (<*>))\nimport Data.Maybe (isJust)\nimport Data.Time.Calendar (fromGregorianValid)\nimport Data.List (permutations)\n\nmain :: IO ()\nmain = solve <$> getLine <*> getLine >>= putStrLn . yesno\n\nsolve :: String -> String -> Bool\nsolve xs ys = or [ check (map read $ split '.' xs) zs | zs <- permutations $ map read $ split '.' ys, valid zs ]\n where split x = words . map (\\c -> if c == x then ' ' else c)\n\nvalid xs = isJust $ fromGregorianValid (fromIntegral y) m d\n where [d, m, y] = xs\n\ncheck xs ys = by < yy - 18 || by == yy - 18 && (bm < mm || bm == mm && bd <= dd)\n where [dd, mm, yy] = xs; [bd, bm, by] = ys\n\nyesno :: Bool -> String\nyesno True = \"YES\"\nyesno _ = \"NO\"\n", "src_uid": "5418c98fe362909f7b28f95225837d33"} {"source_code": "-- 2019-11-24 22:52:24.249280323 UTC\nimport Data.Maybe\nimport Data.Char\nimport Control.Monad\nimport Text.Read\nnat_para :: Integral i => i -> a -> (i -> a -> a) -> a\nnat_para i x f = np (abs i)\n where np 0 = x\n np i = let i' = i - 1\n in f i' (np i')\nhd :: [a] -> a\nhd ([]) = error \"empty head\"\nhd (a : as) = a\ntl = drop 1\nnat_cata :: Integral i => i -> a -> (a -> a) -> a\nnat_cata i x f = nc (abs i)\n where nc 0 = x\n nc i = f (nc (i - 1))\niF :: Bool -> a -> a -> a\niF (True) t f = t\niF (False) t f = f\nlist_para :: [b] -> a -> (b -> [b] -> a -> a) -> a\nlist_para ([]) x f = x\nlist_para (y : ys) x f = f y ys (list_para ys x f)\nmagiciF :: Bool -> String\nmagiciF b = if b then \"EASY\" else \"HARD\"\nuncurry' = id\nparser :: String -> String\nparser = head . lines\nsolve = \\a -> map (\\b -> iF ((\\f_6989586621679053539 -> length . filter f_6989586621679053539) (\\c -> isLower c) a >= (\\f_6989586621679053539 -> length . filter f_6989586621679053539) (\\c -> isUpper c) a) (toLower b) (toUpper b)) a\nmain = getContents >>= (\\c -> putStrLn (uncurry' solve (parser c)))", "src_uid": "b432dfa66bae2b542342f0b42c0a2598"} {"source_code": "import Control.Applicative\nimport Data.List\n\n\nmain= do\n \tx<-sort . map read . words <$> getLine ::IO [Int]\n\tprint $ 4-(length (group x))", "src_uid": "38c4864937e57b35d3cce272f655e20f"} {"source_code": "import Control.Applicative\nimport Control.Monad\nimport Data.List\nimport Data.Maybe\n\n\n\nmain = do\n\t\tn<- read <$> getLine::IO Int\n\t\tk<- map read <$> words <$> getLine::IO [Int]\n\t\tlet ma = maximum k\n\t\tlet s = sum k\n\t\tprint $ max ma ((div (s+s+1) n) + if (mod (s+s+1) n)==0 then 0 else 1)\n \n", "src_uid": "d215b3541d6d728ad01b166aae64faa2"} {"source_code": "main = do\n [k,n,s,p] <- return . map (read :: String -> Double ) . words =<< getLine\n print $ ceiling $ k * (fromIntegral $ ceiling $ n / s) / p\n", "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780"} {"source_code": "-- Codeforces 911B\n\n{-# OPTIONS_GHC -O2 #-}\n{-# OPTIONS_GHC -optc-O2 #-}\n{-# LANGUAGE BangPatterns #-}\n{-# LANGUAGE OverloadedStrings #-}\n\nimport Control.Applicative\nimport Control.Monad\nimport qualified Data.ByteString.Char8 as BC\nimport Data.List\nimport Data.Maybe\n\nmain :: IO ()\nmain = do\n [n, a, b] <- (map (fst . fromJust . BC.readInt) . BC.words) <$> BC.getLine :: IO [Int]\n print . maximum . map (\\i -> min (a `div` i) (b `div` (n - i))) $ [max (n-b) 1 .. min (n - 1) a]\n", "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e"} {"source_code": "\nsolve [a,b,e] [c,d,f]\n | a == 0 && b == 0 && e /= 0 = 0\n | c == 0 && d == 0 && f /= 0 = 0\n | det == 0 && x' == 0 && y' == 0 = -1\n | det == 0 = 0\n | otherwise = 1\n where\n det = a*d-c*b\n x' = e*d-f*b\n y' = a*f-c*e\n\n(-->) = flip fmap\n\nmain = do\n u@[a,b,e] <- getLine --> words --> map read\n v@[c,d,f] <- getLine --> words --> map read\n let _ = a :: Int\n print $ solve u v\n\n", "src_uid": "c8e869cb17550e888733551c749f2e1a"} {"source_code": "import Control.Applicative\nimport Prelude\n\nimport Control.Arrow ((>>>))\nimport Control.Monad (liftM, when)\nimport Control.Monad.ST.Safe (ST, runST)\nimport Data.Array.ST.Safe (STArray, newArray, readArray, writeArray, getElems, mapArray)\nimport Data.STRef (STRef, newSTRef, readSTRef, writeSTRef, modifySTRef)\nimport Data.Foldable (for_)\n\nwhileM_ :: (Monad m) => m Bool -> m a -> m ()\nwhileM_ p f = do\n x <- p\n when x (f >> whileM_ p f)\n\nexistsUnloved :: Int -> [Int] -> Bool\nexistsUnloved n g = runST $ do\n incoming <- newArray (1, n) [] :: ST s (STArray s Int [Int])\n gg <- newSTRef g\n for_ [1..n] $ \\idx -> do\n h:t <- readSTRef gg\n current <- readArray incoming h\n writeArray incoming h (idx:current)\n writeSTRef gg t\n any null <$> (getElems incoming)\n\nloopLengths :: Int -> [Int] -> [Int]\nloopLengths n g = runST $ do\n visited <- newArray (1, n) False :: ST s (STArray s Int Bool)\n ans <- newSTRef []\n for_ [1..n] $ \\idx -> do\n visitedCurrent <- readArray visited idx\n when (not visitedCurrent) $ do\n writeArray visited idx True\n current <- newSTRef (g !! (idx - 1))\n currentLength <- newSTRef 1\n whileM_ (readSTRef current >>= \\v -> readArray visited v >>= \\vv -> return $ not vv) $ do\n cval <- readSTRef current\n writeArray visited cval True\n modifySTRef current (\\val -> g !! (val - 1))\n modifySTRef currentLength ((+) 1)\n finalval <- readSTRef current\n when (finalval == idx) $ do\n lenval <- readSTRef currentLength\n modifySTRef ans (\\ansval -> lenval : ansval)\n readSTRef ans\n\nmain = do\n n <- readLn :: IO Int\n crush <- liftM (words >>> map read) getLine :: IO [Int]\n if existsUnloved n crush then\n print (-1)\n else\n let ll = foldr lcm 1 $ loopLengths n crush in\n if ll `rem` 2 == 0 then\n print $ ll `div` 2\n else\n print $ ll\n", "src_uid": "149221131a978298ac56b58438df46c9"} {"source_code": "main = getLine >>= print . solve\n\nsolve (c:r:_)\n | c `elem` \"ah\" && r `elem` \"18\" = 3\n | c `elem` \"ah\" || r `elem` \"18\" = 5\n | otherwise = 8", "src_uid": "6994331ca6282669cbb7138eb7e55e01"} {"source_code": "{-# OPTIONS_GHC -O3 #-}\n{-# LANGUAGE ViewPatterns, ScopedTypeVariables #-}\n\nimport qualified Data.ByteString as B (getLine)\nimport qualified Data.ByteString.Char8 as C (readInt, words, unpack, reverse, dropWhile)\nimport qualified Data.Maybe as M (fromJust)\nimport qualified Data.Char as C (isSpace)\nimport qualified Control.Monad.ST.Safe as ST (runST, ST)\nimport qualified Data.Array.ST.Safe as ST (STUArray)\nimport qualified Data.Array.MArray.Safe as A (newArray, readArray, writeArray, getElems)\nimport qualified Control.Monad as M (forM_)\n\nreadInt = fst . M.fromJust . C.readInt\nrstrip = C.reverse . C.dropWhile C.isSpace . C.reverse\n\nincArray arr i = do\n x <- A.readArray arr i\n A.writeArray arr i (x + 1)\n\nrun x = ST.runST $ do\n arr <- A.newArray ('a', 'z') 0 :: ST.ST s (ST.STUArray s Char Int)\n M.forM_ x $ incArray arr\n arrx <- A.getElems arr\n return $ maximum arrx\n\nmain = do\n (map readInt . C.words -> [_, k]) <- B.getLine\n (C.unpack . rstrip -> xs) <- B.getLine\n putStrLn $ if run xs <= k then \"YES\" else \"NO\"\n", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be"} {"source_code": "-- 2022-10-10 01:28:10.472283 UTC\n{-# LANGUAGE FlexibleInstances #-}\n\nimport Data.Graph (Graph, Vertex, Forest, Tree)\nimport qualified Data.Maybe\nimport qualified Data.Graph\nimport qualified Data.Bits\nimport qualified Data.Char\nimport qualified Control.Monad\nimport qualified Text.Read\nimport qualified Data.Map\nimport qualified Data.Tree\nimport qualified Data.Array\nimport qualified Data.Set\nimport qualified Data.Bits\nimport qualified Data.ByteString.Char8\nimport qualified Data.ByteString\nimport qualified Data.List\nimport qualified Data.List.NonEmpty\nimport qualified Numeric\nimport Data.List.NonEmpty (NonEmpty((:|)), (<|))\nimport Data.Map (Map)\nimport Data.Set (Set)\nimport Data.Array (Array, (!))\nimport Data.ByteString (ByteString)\nimport Debug.Trace\n\ndata GraphForProblems key\n = GraphForProblems {gpGraph :: Graph,\n gpVertexFromKey :: (key -> Vertex),\n gpNodeFromVertex :: (Vertex -> key)}\nnewtype GraphVertex a = GraphVertex a\ninstance Eq a => Eq (GraphVertex a)\n where (==) (GraphVertex a) (GraphVertex b) = a == b\nunwrapGraphVertex :: GraphVertex i -> i\nunwrapGraphVertex (GraphVertex i) = i\ntype IntGraph = GraphForProblems Int\ntype StringGraph = GraphForProblems String\ndata GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)\ninstance Show (GraphForProblems key)\n where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph\ninstance Ord a => Ord (GraphVertex a)\n where compare (GraphVertex a) (GraphVertex b) = compare a b\nedgeSource :: GraphEdge a -> GraphVertex a\nedgeSource (GraphEdge a _) = a\nedgeDest :: GraphEdge a -> GraphVertex a\nedgeDest (GraphEdge _ b) = b\nmkGraph :: (Ord key, Show key) =>\n [(node, key, [key])] -> GraphForProblems key\nmkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex\n where (gpGraph,\n nodeFromVertex,\n vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges\n gpVertexFromKey k = case vertexFromKey k of\n Nothing -> error $ (\"vertexFromKey: \" <> (show k <> \" key not found\"))\n Just k' -> k'\n gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v\n in k\nvertices' :: GraphForProblems a -> [GraphVertex a]\nvertices' (GraphForProblems {gpGraph = gpGraph,\n gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph\nedges' :: GraphForProblems a -> [GraphEdge a]\nedges' (GraphForProblems {gpGraph = gpGraph,\n gpNodeFromVertex = gpNodeFromVertex}) = (\\(a,\n b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph\ndfs' :: GraphForProblems key ->\n [GraphVertex key] -> [Tree (GraphVertex key)]\ndfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,\n gpGraph = gpGraph,\n gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))\ndfsOnSingleVertex :: GraphForProblems key ->\n GraphVertex key -> Tree (GraphVertex key)\ndfsOnSingleVertex g v = case dfs' g [v] of\n [] -> error \"dfsOnSingleVertex: empty result\"\n x : _ -> x\nscc' :: GraphForProblems key -> [Tree (GraphVertex key)]\nscc' (GraphForProblems {gpGraph = gpGraph,\n gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph\nlevels' :: Tree (GraphVertex key) -> [[GraphVertex key]]\nlevels' = Data.Tree.levels\ngetSingleEnd :: Eq a =>\n GraphForProblems a -> GraphVertex a -> GraphVertex a\ngetSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))\ngetSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a\ngetSingleLeaf = last . Data.Tree.flatten\nflatten' :: Tree (GraphVertex a) -> [GraphVertex a]\nflatten' = Data.Tree.flatten\nelemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool\nelemTreeInt = elem\nminimumTree :: Tree Int -> Int\nminimumTree = minimum\nmapTree :: (a -> b) -> Tree a -> Tree b\nmapTree = fmap\nnewtype OutDegreeTable\n = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}\nlinearGraph :: OutDegreeTable -> Bool\nlinearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos\n where values = Data.Array.elems unOutDegreeTable\n numValues = length values\n twoOnes = 2 == length (Prelude.filter (== 1) values)\n restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)\ncycleGraph :: OutDegreeTable -> Bool\ncycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos\n where values = Data.Array.elems unOutDegreeTable\n allTwos = all (== 2) values\nstarGraph :: OutDegreeTable -> Bool\nstarGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes\n where values = Data.Array.elems unOutDegreeTable\n numValues = length values\n onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)\n restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)\noutdegree' :: GraphForProblems a -> OutDegreeTable\noutdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}\n where unOutDegreeTable = Data.Graph.outdegree gpGraph\nsafeElems2 :: [a] -> Maybe (a, a)\nsafeElems2 [x1, x2] = Just (x1, x2)\nsafeElems2 _ = Nothing\nsafeElems3 :: [a] -> Maybe (a, a, a)\nsafeElems3 [x1, x2, x3] = Just (x1, x2, x3)\nsafeElems3 _ = Nothing\nsafeElems4 :: [a] -> Maybe (a, a, a, a)\nsafeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)\nsafeElems4 _ = Nothing\nsafeElems5 :: [a] -> Maybe (a, a, a, a, a)\nsafeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)\nsafeElems5 _ = Nothing\ncompareLength :: Int -> [b] -> Ordering\ncompareLength 0 ([]) = EQ\ncompareLength 0 _ = LT\ncompareLength i (_ : xs) | i < 0 = error \"compareLength: negative length comparison does not make sense\"\n | otherwise = compareLength (i - 1) xs\nconsumeNElems :: Int -> [b] -> Maybe ([b], [b])\nconsumeNElems 0 ([]) = Just ([], [])\nconsumeNElems 0 xs = Just ([], xs)\nconsumeNElems _ ([]) = Nothing\nconsumeNElems i (x : xs) | i < 0 = error \"consumeNElems: negative length comparison does not make sense\"\n | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;\n return (x : ys, zs)}\ngroupTups2 :: [a] -> Maybe ([(a, a)])\ngroupTups2 = go []\n where go acc ([]) = Just (reverse acc)\n go acc (x : (y : rest)) = go ((x, y) : acc) rest\n go _ _ = Nothing\ngroupTups3 :: [a] -> Maybe ([(a, a, a)])\ngroupTups3 = go []\n where go acc ([]) = Just (reverse acc)\n go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest\n go _ _ = Nothing\nsafeHeadTail :: [a] -> Maybe (a, [a])\nsafeHeadTail (l1 : l2) = Just (l1, l2)\nsafeHeadTail _ = Nothing\nsafeTwoHeadTail :: [a] -> Maybe (a, a, [a])\nsafeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)\nsafeTwoHeadTail _ = Nothing\nsafeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])\nsafeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)\nsafeThreeHeadTail _ = Nothing\nsafeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])\nsafeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,\n l2,\n l3,\n l4,\n l5)\nsafeFourHeadTail _ = Nothing\nsafeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])\nsafeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,\n l2,\n l3,\n l4,\n l5,\n l6)\nsafeFiveHeadTail _ = Nothing\nsingleLine :: [ByteString] -> Maybe ByteString\nsingleLine [l] = Just l\nsingleLine _ = Nothing\nclass PrettyPutStrLn a\n where prettyPutStrLn :: a -> IO ()\n prettyPutStrLn a = prettyPutStr a >> putStrLn \"\"\n prettyPutStr :: a -> IO ()\ninstance PrettyPutStrLn Int\n where prettyPutStr = putStr . show\ninstance PrettyPutStrLn Integer\n where prettyPutStr = putStr . show\ninstance PrettyPutStrLn ([Char])\n where prettyPutStr = putStr\ninstance PrettyPutStrLn ([[Char]])\n where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)\ninstance PrettyPutStrLn Double\n where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d \"\"\ninstance PrettyPutStrLn a => PrettyPutStrLn (a, a)\n where prettyPutStr (a,\n b) = (prettyPutStr a >> putStrLn \" \") >> prettyPutStr b\ntype ProblemInputOutputParser a = [ByteString] ->\n Maybe (a, [ByteString])\ndata Point = Point Double Double deriving (Eq, Ord)\ninstance Show Point\n where show (Point x y) = show (x, y)\ndata PointLiesInside = LiesInside | LiesOutside deriving Eq\nliesInsideToBool :: PointLiesInside -> Bool\nliesInsideToBool (LiesInside) = True\nliesInsideToBool (LiesOutside) = False\ndata Line2D = Line2D Point Point deriving (Ord, Show)\ndata Slope = InfiniteSlope | FiniteSlope Double deriving Show\nslopeOfLine :: Line2D -> Slope\nslopeOfLine (Line2D (Point x0 y0)\n (Point x1 y1)) | x0 == x1 = InfiniteSlope\n | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))\ninstance Eq Line2D\n where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1\ndata LinePointTest\n = AboveOrLeft | BelowOrRight | InLine\n deriving Eq\nmkLineFromTwoPoints :: Point -> Point -> Line2D\nmkLineFromTwoPoints p1 p2 | p1 == p2 = error $ (\"p1 == p2: p1 = \" <> (show p1 <> (\" p2 = \" <> show p2)))\n | p1 < p2 = Line2D p1 p2\n | otherwise = Line2D p2 p1\nmkLineWithSlopeAndPoint :: Double -> Point -> Line2D\nmkLineWithSlopeAndPoint slope (Point x\n y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))\noffsetOfLine :: Line2D -> Double\noffsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)\n where slope = case slopeOfLine l of\n InfiniteSlope -> error \"offsetOfLine: InfiniteSlope\"\n FiniteSlope s -> s\npointsInSameLine :: Point -> Point -> Point -> Bool\npointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3\n y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))\nhasHigherX :: Point -> Point -> Bool\nhasHigherX (Point x1 _) (Point x2 _) = x1 > x2\nhasHigherY :: Point -> Point -> Bool\nhasHigherY (Point _ y1) (Point _ y2) = y1 > y2\nisPointAboveLine :: Point -> Line2D -> LinePointTest\nisPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)\n (Point x2 y2)) = if l == 0\n then InLine\n else if l > 0\n then AboveOrLeft\n else BelowOrRight\n where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))\nisInLine :: Point -> Line2D -> Bool\nisInLine p = (== InLine) . isPointAboveLine p\nlinesIntersect :: Line2D -> Line2D -> Bool\nlinesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2\n _)\n _)) = case (slopeOfLine l1,\n slopeOfLine l2) of\n (InfiniteSlope,\n InfiniteSlope) -> x1 == x2\n (InfiniteSlope,\n FiniteSlope _) -> True\n (FiniteSlope _,\n InfiniteSlope) -> True\n (FiniteSlope slope1,\n FiniteSlope slope2) -> slope1 /= slope2\nclass Show a => PolygonShape a\n where isInside :: a -> Point -> PointLiesInside\n isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)\n then LiesInside\n else LiesOutside\n where f (lineEq,\n lineComps) = isPointAboveLine point lineEq `elem` lineComps\n shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool\n shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA\n where pointsA = shapeCenter shapeA <| shapeCorners shapeA\n pointsB = shapeCenter shapeB <| shapeCorners shapeB\n f shape = any ((== LiesInside) . isInside shape)\n linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])\n shapeCorners :: a -> NonEmpty Point\n shapeCenter :: a -> Point\ndata Rectangle\n = Rectangle Point Point Point Point\n deriving (Eq, Show)\nmkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle\nmkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));\n Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));\n Control.Monad.guard $ (p3 /= p4);\n return $ Rectangle pymin pxmin pymax pxmax}\n where points = [p2, p3, p4]\n pymin = foldl (\\(acc@(Point accx accy)) (p@(Point x\n y)) -> if y < accy\n then p\n else if y > accy\n then acc\n else if x > accx\n then p\n else acc) p1 points\n pxmin = foldl (\\(acc@(Point accx accy)) (p@(Point x\n y)) -> if x < accx\n then p\n else if x > accx\n then acc\n else if y < accy\n then p\n else acc) p1 points\n pymax = foldl (\\(acc@(Point accx accy)) (p@(Point x\n y)) -> if y > accy\n then p\n else if y < accy\n then acc\n else if x < accx\n then p\n else acc) p1 points\n pxmax = foldl (\\(acc@(Point accx accy)) (p@(Point x\n y)) -> if x > accx\n then p\n else if x < accx\n then acc\n else if y > accy\n then p\n else acc) p1 points\nisInsideRect :: Rectangle -> Point -> PointLiesInside\nisInsideRect = isInside\ninstance PolygonShape Rectangle\n where linesOfWithComparisons (Rectangle p1\n p2\n p3\n p4) = Data.List.NonEmpty.fromList [(mk p1 p2,\n [AboveOrLeft,\n InLine]),\n (mk p2 p3,\n [BelowOrRight,\n InLine]),\n (mk p3 p4,\n [BelowOrRight,\n InLine]),\n (mk p4 p1,\n [AboveOrLeft,\n InLine])]\n where mk = mkLineFromTwoPoints\n shapeCorners (Rectangle p1\n p2\n p3\n p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]\n shapeCenter (Rectangle _\n (Point x1 y1)\n _\n (Point x2\n y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))\ndata Triangle = Triangle Point Point Point deriving (Eq, Show)\nmkTriangle :: Point -> Point -> Point -> Maybe Triangle\nmkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));\n return $ Triangle p1 p2 p3}\ninstance PolygonShape Triangle\n where linesOfWithComparisons (Triangle p1\n p2\n p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),\n (mk p2 p3, []),\n (mk p3 p1, [])]\n where mk = mkLineFromTwoPoints\n shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,\n p2,\n p3]\n shapeCenter _ = error \"SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET\"\nhasHorizontalLineAbove :: Triangle -> Maybe Line2D\nhasHorizontalLineAbove (triangle@(Triangle p1\n p2\n p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of\n [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of\n [_] -> Just l\n [] -> Nothing\n _ -> error \"INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove\"\n [] -> Nothing\n _ -> error \"INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove\"\n where trianglePoints = [p1, p2, p3]\n triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)\n horizontalLine (l@(Line2D (Point _ y1)\n (Point _ y2))) | y1 == y2 = Just l\n | otherwise = Nothing\ndistanceBetweenPoints :: Point -> Point -> Double\ndistanceBetweenPoints (Point x1 y1) (Point x2\n y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))\ndistanceBetweenPointsOfLine :: Line2D -> Double\ndistanceBetweenPointsOfLine (Line2D p1\n p2) = distanceBetweenPoints p1 p2\nifEvenOdd :: Int -> a -> a -> a\nifEvenOdd n a a' | (n `mod` 2) == 0 = a\n | otherwise = a'\nifZero :: Int -> a -> a -> a\nifZero 0 a _ = a\nifZero _ _ a = a\nsumOfIntsToN :: Int -> Int\nsumOfIntsToN n = (n * (n - 1)) `div` 2\nsumOfEvensToN :: Int -> Int\nsumOfEvensToN n = n * (n + 1)\nsumOfOddsToN :: Int -> Int\nsumOfOddsToN n = n * n\ncountElemsThat :: (a -> Bool) -> [a] -> Int\ncountElemsThat f = length . Prelude.filter f\nrange :: Int -> Int -> [Int]\nrange a b = [a..b]\nmodError :: Integral a => a -> a -> a\nmodError a b | toInteger b == 0 = error \"modError: division by zero\"\n | otherwise = a `mod` b\nmod10To9Plus7 :: Integral a => a -> a\nmod10To9Plus7 = (`mod` 1000000007)\nbigExponentiation :: Integer -> Int -> Integer\nbigExponentiation = (^)\nsquares :: Set Int\nsquares = Data.Set.fromList $ map (\\i -> i ^ (2 :: Int)) [1..1000000000]\nshiftLError :: Int -> Int -> Int\nshiftLError i j | j < 0 = error \"shiftLError: negative shift\"\n | otherwise = Data.Bits.shiftL i j\nnat_para :: Integral i => i -> a -> (i -> a -> a) -> a\nnat_para i x f = np (abs i)\n where np 0 = x\n np i = let i' = i - 1\n in f i' (np i')\niF :: Bool -> a -> a -> a\niF (True) t f = t\niF (False) t f = f\nlist_para :: [b] -> a -> (b -> [b] -> a -> a) -> a\nlist_para ([]) x f = x\nlist_para (y : ys) x f = f y ys (list_para ys x f)\nparseTwoInts :: ProblemInputOutputParser (Int, Int)\nparseTwoInts ws = safeTwoHeadTail ws >>= (\\(nBs,\n mBs,\n remainingTkns) -> do {(n,\n _) <- Data.ByteString.Char8.readInt nBs;\n (m,\n _) <- Data.ByteString.Char8.readInt mBs;\n return ((n, m), remainingTkns)})\nunpackParser f (x1, x2) = f x1 x2\nparser = parseTwoInts\nsolve :: Int -> Int -> Integer\nsolve = \\a b -> mod10To9Plus7 (bigExponentiation (toInteger a) b)\napplyFunctionWithParserUntilExhausted solver parser = go\n where go ([]) = return ()\n go inputBs = do case parser inputBs of\n Nothing -> error \"UNEXPECTED ERROR WHILE PARSING\"\n Just (result,\n remainingTkns) -> do {prettyPutStrLn $ solver result;\n go remainingTkns}\nmain :: IO ()\nmain = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))", "src_uid": "2e7a9f3a97938e4a7e036520d812b97a"} {"source_code": "module Main where\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.List\n\nmaxDigitSum = 9 * 10\n\ndigitSum :: Int -> Int\ndigitSum 0 = 0\ndigitSum n = m + digitSum d\n where (d, m) = n `divMod` 10\n\nsolve :: Int -> [Int]\nsolve n = sortUnique [x | sum <- [1 .. maxDigitSum]\n , sum < n\n , let x = n - sum\n , x + digitSum x == n]\n\nsortUnique :: Ord a => [a] -> [a]\nsortUnique = map head . group . sort\n\nmain :: IO ()\nmain = do\n n <- read <$> getLine\n let xs = solve n\n print $ length xs\n mapM_ print xs\n", "src_uid": "ae20ae2a16273a0d379932d6e973f878"} {"source_code": "main :: IO()\nmain = print . solve (initValids [1] [] 0) . map read . words =<< getLine\n\ninitValids :: [Integer] -> [Integer] -> Int -> [Integer]\ninitValids ones zeros 64 = []\ninitValids ones zeros i = zeros ++ initValids (map (\\x -> x * 2 + 1) ones)\n ((map (\\x -> x * 2) ones) ++ (map (\\x -> x * 2 + 1) zeros))\n (i + 1)\n\nsolve :: [Integer] -> [Integer] -> Int\nsolve [] _ = 0\nsolve (v:vs) [a, b] | a <= v && v <= b = 1 + solve vs [a, b]\n | otherwise = solve vs [a, b]\n", "src_uid": "581f61b1f50313bf4c75833cefd4d022"} {"source_code": "import Data.Char\n\nh :: Int -> Int -> String -> String\n\nh 0 _ s = s\nh _ 0 s = s\nh x y \"Malvika\" = h (x-1) (y-1) \"Akshat\"\nh x y \"Akshat\" = h (x-1) (y-1) \"Malvika\" \n\n\nmain = do\n line <- getLine\n let a = (read (takeWhile (/= ' ') line) :: Int)\n let b = (read (drop 1 (dropWhile (/= ' ') line)) :: Int)\n putStrLn (h a b \"Malvika\" )\n", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4"} {"source_code": "{-# LANGUAGE FlexibleContexts, ScopedTypeVariables, BangPatterns, OverloadedStrings #-}\n{-# OPTIONS_GHC -O2 #-}\n\nimport Control.Applicative\nimport Control.Monad hiding ((<$!>))\nimport Control.Monad.ST.Safe\nimport Control.Monad.State hiding ((<$!>))\n-- import Data.Array\nimport Data.Array.IArray\nimport Data.Array.IO.Safe\nimport Data.Array.MArray.Safe\nimport Data.Array.ST.Safe\nimport Data.Array.Unboxed\nimport qualified Data.ByteString.Char8 as B\nimport qualified Data.ByteString.Lazy.Builder as BB\nimport Data.Char\nimport qualified Data.Foldable as F\nimport Data.Function\nimport Data.Graph\nimport Data.Int\nimport Data.List\nimport Data.List.Split\nimport Data.Maybe\nimport Data.Monoid\nimport Data.Ord\nimport Data.Ratio\nimport qualified Data.Sequence as Seq\nimport Data.Sequence (Seq)\nimport Data.Set (Set)\nimport qualified Data.Set as Set\nimport Data.IntSet (IntSet)\nimport qualified Data.IntSet as IntSet\n-- import Data.Tree\nimport Data.Tuple\nimport Data.Map.Strict (Map)\nimport qualified Data.Map.Strict as Map\nimport Data.HashMap.Strict (HashMap)\nimport qualified Data.HashMap.Strict as HashMap\nimport Data.IntMap (IntMap)\nimport qualified Data.IntMap as IntMap\n-- import Debug.Trace\nimport System.IO\n\n-- getInts = fmap (map read . words) getLine\ngetInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine\n\nmain = do\n n <- readLn\n xs <- getInts\n\n let\n x = xs !! (length xs - 2)\n y = last xs\n\n\n putStrLn $\n if n == 1\n then\n case xs of\n [15] -> \"DOWN\"\n [0] -> \"UP\"\n otherwise -> show (-1)\n else\n if x < y\n then if y == 15 then \"DOWN\" else \"UP\"\n else if y == 0 then \"UP\" else \"DOWN\"\n", "src_uid": "8330d9fea8d50a79741507b878da0a75"} {"source_code": "import Data.List\n\nmain = getLine >>= print . solve . map read . words\n\nsolve [a, b, c] = maybe (-1) (+1) $ findIndex (== c) (longdiv a b)\n\nlongdiv a b = go [] (a `rem` b) b\n where\n go seen a b\n | r `elem` seen = [r | r == 0]\n | otherwise = q:go (r:seen) r b\n where (q, r) = (if a < b then a * 10 else a) `quotRem` b", "src_uid": "0bc7bf67b96e2898cfd8d129ad486910"} {"source_code": "import Control.Applicative\nimport Data.List\nimport qualified Data.ByteString.Char8 as C\nimport Data.Maybe\n \n \n \n\n\nmain = do\n\t[a,b,c]<- map (fst.fromJust.C.readInt).C.words <$> C.getLine ::IO [Int]\n\tlet d = div c a\n\tlet e = length $ take 1 [1| e<-[d,d-1..0],mod (c-e*a) b==0]\n\tputStrLn $ if e==1 then \"Yes\" else \"No\" ", "src_uid": "e66ecb0021a34042885442b336f3d911"} {"source_code": "-- http://codeforces.com/contest/818/problem/B\n\n-- enable C pre-processor\n{-# LANGUAGE CPP #-}\n\nimport Control.Monad\nimport Data.List\nimport Data.Array\n\n#ifdef DEBUG\nimport Debug.Trace\n#endif\n\ngetInts = (map read . words) `fmap` getLine :: IO [Int]\n\nmain = do\n [n,m] <- getInts\n leaders <- getInts\n case solve leaders n m of\n Nothing -> print (-1)\n Just answer -> forM_ answer (\\i -> putStr (show i) >> putChar ' ')\n\nsolve :: [Int] -> Int -> Int -> Maybe [Int]\nsolve leaders n m =\n#ifdef DEBUG\n if feasible (trace (show (elems $ getSteps leaders n)) (getSteps leaders n))\n#else\n if feasible (getSteps leaders n)\n#endif\n then Just $ restore (getSteps leaders n) n\n else Nothing\n\ngetSteps :: [Int] -> Int -> Array Int Int\ngetSteps leaders n = accumArray f (-1) (1,n) [(l,s) | (l,l') <- zip leaders (tail leaders), let d = l' - l, let s = if d <= 0 then d + n else d] where\n f prev curr\n | prev == -1 || prev == curr = curr\n | otherwise = -2\n\nfeasible :: Array Int Int -> Bool\nfeasible cand = allUnique && noDup where\n es = (filter (/= -1) . elems) cand\n allUnique = all (/= (-2)) es\n noDup = nub es == es -- O(n^2)\n\nrestore :: Array Int Int -> Int -> [Int]\nrestore ary n = merge ([1..n] \\\\ es) es where\n es = elems ary\n merge [] answer = answer\n merge xss@(x:xs) (y:ys)\n | y == -1 = x : merge xs ys\n | otherwise = y : merge xss ys", "src_uid": "4a7c959ca279d0a9bd9bbf0ce88cf72b"} {"source_code": "import Control.Applicative( (<$>))\n\nmain = do\n [xa_, ya_, xb_, yb_, xc_, yc_] <- map (read::String->Integer) .\n\t\t\t\t\t\twords <$> getLine\n let\n\tdistanceEq =\n\t (xb_-xa_)^2 + (yb_-ya_)^2 == (xc_-xb_)^2 + (yc_-yb_)^2\n \n putStr $ if distanceEq\n\t\tthen let\n\t\t\tdeltaX = xc_-xa_\n\t\t\tdeltaY = yc_-ya_\n\t\t in if\n\t\t\txa_+(deltaX`quot`2) == xb_ &&\n\t\t\tya_+(deltaY`quot`2) == yb_\n\t\t\tthen \"No\"\n\t\t\telse \"Yes\"\n\t\telse \"No\"\n", "src_uid": "05ec6ec3e9ffcc0e856dc0d461e6eeab"} {"source_code": "\nimport Control.Monad (liftM)\nimport Data.Array ((!), accumArray)\nimport Data.Char (isAlpha)\nimport Prelude hiding (reads)\n\nreads :: Read a => IO [a]\nreads = liftM (map read . words) getLine\n\nseqPlus :: Num a => a -> a -> a\nseqPlus x y = seq z z\n where\n z = x + y\n\nsolve :: String -> Integer\nsolve s = solve' n m 10 - case (isAlpha $ head s, head s) of\n (True, _) -> solve' n (m - 1) 9\n (False, '?') -> solve' (n - 1) m 10\n _ -> 0\n where\n d = accumArray seqPlus 0 ('0', 'J') $ zip s $ repeat 1\n n = d ! '?'\n m = fromIntegral $ length $ filter (> 0) $ map (d !) ['A'..'J']\n solve' n m k = 10^n * product [k - m + 1 .. k]\n\nmain :: IO ()\nmain = getLine >>= print . solve", "src_uid": "d3c10d1b1a17ad018359e2dab80d2b82"} {"source_code": "import Text.Printf\nimport Data.List\nimport Data.Functor\nimport Control.Applicative\nimport Prelude\nimport Control.Monad\nimport Data.Maybe\nimport Data.Function\nimport Data.Array\nimport qualified Data.ByteString.Char8 as B8\nimport Data.Foldable (foldr')\n\nreadInt :: String -> Int\nreadInt = Prelude.read\n\nreadB8Int :: B8.ByteString -> Int\nreadB8Int = fst . fromJust . B8.readInt\n\nsolve :: String -> [Int]\nsolve = map length . filter ((== 'B') . head) . group\n\nmain :: IO ()\nmain = do\n n <- readInt <$> getLine\n line <- (head . words) <$> getLine\n let answer = solve line\n printf \"%d\\n\" $ length answer\n forM_ answer $ printf \"%d \"\n printf \"\\n\"", "src_uid": "e4b3a2707ba080b93a152f4e6e983973"} {"source_code": "import Data.List\n\nmain :: IO()\nmain = putStrLn . solve . lines =<< getContents\n\nkeyboard :: String\nkeyboard = \"qwertyuiopasdfghjkl;zxcvbnm,./\"\n\nremoveMaybe :: Maybe a -> a\nremoveMaybe (Just a) = a\n\nsolve :: [String] -> String\nsolve (d:s:_) = if d == \"R\" then (solve' (-1) s) else (solve' 1 s)\n\nsolve' :: Int -> String -> String\nsolve' d \"\" = \"\"\nsolve' d (c:s) = (keyboard !! ((removeMaybe (elemIndex c keyboard)) + d)) : (solve' d s)\n", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6"} {"source_code": "main = do\n s <- getLine\n let ns = words s\n n = read (ns !! 0) :: Integer\n c1 = read (ns !! 1) :: Integer\n c2 = read (ns !! 2) :: Integer\n\n s <- getLine\n let adults = (toInteger . length . filter (\\t -> t == '1')) s\n total = (toInteger . length) s\n\n let cost x = c1 + c2 * (x - 1) ^ 2\n\n let f ngroups = let mingroup = (total `div` ngroups) :: Integer\n cntmax = (total `mod` ngroups) :: Integer\n in (ngroups - cntmax) * (cost mingroup) + cntmax * (cost (mingroup + 1))\n\n putStrLn (show $ (foldl1 min) $ map f [1..adults])\n", "src_uid": "78d013b01497053b8e321fe7b6ce3760"} {"source_code": "import Data.List\nimport Data.Array\n\nlst x\n\t|div x 10>0 = lst (mod x 10)\n\t|otherwise = x\n\ndrop10 n\n\t|mod n 10 == 0 =drop10 (div n 10)\n\t|otherwise = n\n\ncalcZ n c\n\t|mod n 10 ==0 = calcZ (div n 10) (c+1)\n\t|otherwise=c\n\t\ngetBig x y\n\t|calcZ x 0>=y = x\n\t|l==0 = x*(10^(y-(calcZ x 0)))\n\t|l==2 = x*5*(10^(y-1))\n\t|l==4 = x*5*(10^(y-1))\n\t|l==5 = x*2*(10^(y-1))\n\t|l==6 = x*5*(10^(y-1))\n\t|l==8 = x*5*(10^(y-1))\n\t|otherwise = x*(10^y)\n\twhere \n\t\tl=lst x\n\nsolve x y = div g k--(g,d,k,div g k)\n\twhere\n\t\tg=getBig x y\n\t\td=div g x\n\t\tk=gcd d (drop10 g)\n\nmain=do\n\t[x,y]<-fmap words getLine\n\tprint (solve (read x::Integer) (read y::Integer))\n", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3"} {"source_code": "import Data.List\n\ncountDigs :: Int -> Int\ncountDigs 0 = 0\ncountDigs n = countDigs (n `div` 7) + 1\n\ngetValue :: [Int] -> Int\ngetValue [] = 0\ngetValue (x:xs) = (getValue xs) * 7 + x\n\ndoesFit :: [Int] -> Int -> Int -> Int -> Bool\ndoesFit xs n m digsN = (getValue . reverse $ tn) < n && (getValue . reverse $ tm) < m\n where tn = take digsN xs\n tm = drop digsN xs\n\ngetDist :: Int -> Int -> Int\ngetDist n m | digsM + digsN > 7 = 0\n | otherwise = sum [ 1 | xs <- nub . map (take $ digsN + digsM) . permutations $ [0..6], doesFit xs n m digsN]\n where digsM | m == 1 = 1\n | otherwise = countDigs (m - 1)\n digsN | n == 1 = 1\n | otherwise = countDigs (n - 1) \n\nmain :: IO ()\nmain = do\n inpStr <- getLine\n let (n:m:[]) = map (read::String->Int) $ words inpStr\n putStrLn . show $ getDist n m\n", "src_uid": "0930c75f57dd88a858ba7bb0f11f1b1c"} {"source_code": "{-# OPTIONS_GHC -O2 #-}\n\nimport Control.Monad\nimport Prelude as P\n\nimport Data.Word (Word8)\nimport Data.Int (Int64)\nimport qualified Data.Bits as Bits\nimport qualified Data.Char as Char\nimport qualified Data.Ratio as Rat\n\nimport Data.List as L\nimport qualified Data.Set as Set\nimport qualified Data.Map as Map\n\nimport qualified Data.ByteString as Bs\nimport qualified System.IO as Io\n--import Data.IntSet\n\nsol 1 _ h v = v == 0\nsol _ 1 h v = h == 0\nsol n m h v\n | even n && even m = even h\n | even m = h >= div m 2 && (even $ h - (div m 2))\n | otherwise = v >= div n 2 && (even $ v - (div n 2))\n\nsolve :: IO ()\nsolve = do\n [n,m,h] <- readInts :: IO [Int]\n let v = (div (n*m) 2) - h\n in putStrLn $ if sol n m h v then \"YES\" else \"NO\"\n\n \n \nmain = do\n t <- readLn :: IO Int\n replicateM_ t $ solve\n\n----------------------------------------------------------------------------------------\nreadrows :: (Integral b) => b -> IO [String]\nreadrows 0 = return []\nreadrows n = do\n row <- getLine\n l <- readrows $ n-1\n return (row : l)\n\n\nreadintrows :: (Integral a, Integral b) => b -> IO [[a]]\nreadintrows 0 = return []\nreadintrows n = do\n row <- readInts\n l <- readintrows $ n-1\n return (row : l)\n\nparseInt :: (Integral a) => Bs.ByteString -> a\nparseInt xs = snd $ Bs.foldr (\\y (pow, acc) -> (pow*10, acc + pow*(fromIntegral (y-48)))) (1, 0) xs\n\nreadInts :: (Integral a) => IO [a]\nreadInts = map parseInt . filter (/=Bs.empty) . Bs.splitWith (==32) . fuckingWindowsCRLF <$> Bs.getLine\n where fuckingWindowsCRLF bs = if Bs.last bs == 13 then Bs.init bs else bs\n\n", "src_uid": "4d0c0cc8faca62eb6384f8135b30feb8"} {"source_code": "import Control.Arrow ((***))\nimport Control.Monad (forM_, when)\nimport Control.Monad.ST (ST)\nimport Data.Array.ST (STUArray, runSTUArray, newArray, readArray, writeArray)\nimport Data.Array.Unboxed (UArray, assocs)\nimport Data.Int (Int64)\n\nisqrt :: (Integral a, Integral b) => a -> b\nisqrt = floor . sqrt . fromIntegral\n\nthreshold :: Integral a => a\nthreshold = fromIntegral threshold'\nthreshold' :: Int\nthreshold' = 1000000\n\nprimeList :: Integral a => [a]\nprimeList = map fromIntegral $ primeList'\nprimeList' :: [Int]\nprimeList' = primesToN threshold\n\n-- primesToN\nsieveToN :: Int -> UArray Int Bool\nsieveToN n = runSTUArray sieve\n where\n sieve = do\n a <- newArray (2, n) True :: ST s (STUArray s Int Bool)\n forM_ [4, 6 .. n] $ \\j ->\n writeArray a j False\n forM_ [3, 5 .. isqrt n] $ \\i -> do\n ai <- readArray a i\n when ai $\n forM_ [i * i, i * (i + 2) .. n] $ \\j ->\n writeArray a j False\n return a\n\nprimesToN :: (Integral a, Integral b) => a -> [b]\nprimesToN n = map (fromIntegral . fst) $ filter snd $ assocs $ sieveToN n'\n where\n n' = fromIntegral n\n\nsieveFromMToN :: Int64 -> Int64 -> UArray Int64 Bool\nsieveFromMToN m n = runSTUArray sieve\n where\n n' = isqrt n\n primes = if n' > threshold then primesToN n' else takeWhile (<=n') primeList\n sieve = do\n a <- newArray (m, n) True :: ST s (STUArray s Int64 Bool)\n forM_ primes $ \\i -> do\n let s = max i $ div (m + i - 1) i\n when (i * s <= n) $\n forM_ [i * s, i * (s + 1) .. n] $ \\j ->\n writeArray a j False\n return a\n\nprimesFromMToN :: (Integral a, Integral b) => a -> a -> [b]\nprimesFromMToN m n\n | m' <= n' = map (fromIntegral . fst) $ filter snd $ assocs $ sieveFromMToN m' n'\n | otherwise = []\n where\n m' = fromIntegral $ max 2 m\n n' = fromIntegral n\n\ngao a b c = if null ls then -1 else minimum $ zipWith max ls [b - a + 1, b - a ..]\n where\n primeList = primesFromMToN a b\n go [] _ = []\n go _ [] = []\n go x@(h:t) y@((p,q):r)\n | p < h = go x r\n | otherwise = (h,q): go t y\n ls = scanl1 max [e - i + 1 | (i, e) <- go [a .. b] $ zip primeList $ drop (c-1) primeList]\n\nmain = do\n [a, b, c] <- fmap (map read . words) getLine\n print $ gao a b c\n", "src_uid": "3e1751a2990134f2132d743afe02a10e"} {"source_code": "import Control.Applicative\nimport Data.List\n\nmain = do\n [r, g, b] <- reverse . sort . map read . words <$> getLine\n if (g + b) * 2 >= r\n then print (div (r + g + b) 3)\n else print (g + b)", "src_uid": "bae7cbcde19114451b8712d6361d2b01"} {"source_code": "import Data.Char (digitToInt, intToDigit)\n\nmain :: IO ()\nmain = getLine >>= putStrLn . solve\n\nsolve :: String -> String\nsolve ('9':cs) = '9' : solve' cs\nsolve cs = solve' cs\n\nsolve' :: String -> String\nsolve' cs = [ if c < '5' then c else intToDigit (9 - digitToInt c) | c <- cs ]\n", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61"} {"source_code": "calc :: Int -> Int -> (Int, Int, Int, Int)\ncalc x y\n\t| x > 0 && y > 0 = (0, l, l, 0)\n\t| x > 0 && y < 0 = (0, -l, l, 0)\n\t| x < 0 && y > 0 = (-l, 0, 0, l)\n\t| x < 0 && y < 0 = (-l, 0, 0, -l)\n\t| otherwise = (0, 0, 0, 0)\n\twhere\n\t\tl = abs x + abs y\n\nhandle :: [String] -> [[String]]\nhandle [sx, sy] = [map show [x1, y1, x2, y2]]\n\twhere\n\t\t(x1, y1, x2, y2) = calc (read sx) (read sy)\n\nmain :: IO ()\nmain = interact $ unlines . map unwords . handle . words\n", "src_uid": "e2f15a9d9593eec2e19be3140a847712"} {"source_code": "answer::Integer -> Integer -> Integer -> Int\nanswer t s q = length (takeWhile (it0 q t s) (iterate (it q s) (0::Integer) ))\nit::Integer -> Integer -> Integer -> Integer\nit q s x = q*(s+x)\nit0::Integer -> Integer -> Integer -> Integer->Bool\nit0 q t s x = q*(t-s)>x*(pred q) \nmain = do\n w <- getLine\n let ww = words w\n let t = read (ww !! 0)::Integer\n let s = read (ww !! 1)::Integer\n let q = read (ww !! 2)::Integer\n print $ answer t s q\n", "src_uid": "0d01bf286fb2c7950ce5d5fa59a17dd9"} {"source_code": "{- This code was written by\nRussell Emerine - linguist,\nmathematician, coder,\nmusician, and metalhead. -}\n\na -% b = (a - b) `mod` 1000000007\n\na *% b = (a * b) `mod` 1000000007\n\na ^% e\n | e == 0 = 1\n | odd e = p *% p *% a\n | otherwise = p *% p\n where\n p = a ^% (e `div` 2)\n\nmain = do\n n <- read <$> getLine\n print $ foldr (*%) 1 [1 .. n] -% (2 ^% (n - 1)) -- foldr (*%) 1 (replicate (n - 1) 2)\n", "src_uid": "3dc1ee09016a25421ae371fa8005fce1"} {"source_code": "main = do\n n <- getLine\n print $ 2 ^ ((read n) + 1) - 2\n", "src_uid": "f1b43baa14d4c262ba616d892525dfde"} {"source_code": "module Main where\n\ndouble :: Integer -> Double\ndouble a = fromIntegral a :: Double\n\nmain :: IO ()\nmain = do\n line <- getLine\n let [r, x, y, x', y'] = map (\\c -> read c :: Integer) (words line)\n let result = d / (double (2*r)) where\n d = sqrt $ double $ (x - x')^2 + (y - y')^2\n print (ceiling result)", "src_uid": "698da80c7d24252b57cca4e4f0ca7031"} {"source_code": "import Control.Applicative\n\nmain :: IO ()\nmain = do\n input <- zip [0..] . map (read :: String -> Int) . words <$> getLine\n let triangle = [(a_val, b_val) |\n (a_ind, a_val) <- input,\n (b_ind, b_val) <- input,\n (c_ind, c_val) <- input,\n b_ind /= a_ind && a_ind /= c_ind && b_ind /= c_ind,\n c_val >= b_val && c_val >= a_val,\n a_val + b_val > c_val\n ]\n segment = [(a_val, b_val) | (a_ind, a_val) <- input,\n (b_ind, b_val) <- input,\n (c_ind, c_val) <- input,\n b_ind /= a_ind && a_ind /= c_ind, b_ind /= c_ind,\n (c_val >= b_val && c_val >= a_val && a_val + b_val == c_val) ]\n if not (null triangle)\n then putStrLn \"TRIANGLE\"\n else\n if not (null segment)\n then putStrLn \"SEGMENT\"\n else putStrLn \"IMPOSSIBLE\"\n", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a"} {"source_code": "import Data.List (scanl)\n\nmain :: IO ()\nmain = do\n a:b:_ <- fmap (map read . words) getLine\n s <- getLine\n putStrLn $ if rush (a,b) s then \"Yes\" else \"No\"\n\nrush :: (Integer, Integer) -> String -> Bool\nrush (a,b) s = let loop = scanl travel (0,0) s\n travel (x,y) 'U' = (x,y+1)\n travel (x,y) 'D' = (x,y-1)\n travel (x,y) 'L' = (x-1, y)\n travel (x,y) _ = (x+1, y)\n (dx, dy) = last loop\n check (x,y)\n | dx /= 0 && dy /= 0 = let x' = a - x\n y' = b - y\n c1 = (x' `mod` dx == 0) && (y' `mod` dy == 0)\n c2 = (x' `div` dx == y' `div` dy) && (x'`div`dx >= 0)\n in c1 && c2\n | dx == 0 && dy /= 0 = (x == a) && ((b - y) `mod` dy == 0) && ((b - y) `div` dy >= 0)\n | dy == 0 && dx /= 0 = (y == b) && ((a - x) `mod` dx == 0) && ((a - x) `div` dx >= 0)\n | otherwise = (y == b) && (x == a)\n \n in\n any check loop\n", "src_uid": "5d6212e28c7942e9ff4d096938b782bf"} {"source_code": "main :: IO()\nmain = do\n l <- getLine\n putStrLn . output . solve . input $ l\n\ninput :: String -> Int\ninput = read\n\nsolve :: Int -> Int\nsolve n = (n `div` z n + 1) * z n - n\n where\n z x = if x `mod` 10 == x then 1 else 10 * z (x `div` 10)\n\noutput :: Int -> String\noutput = show\n", "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e"} {"source_code": "module Main (main) where\n\nimport Data.List (sum, group, sort, length, reverse)\nimport Data.Char (ord)\n\nreadInts :: IO [Int]\nreadInts = fmap (map read . words) getLine\n\nmain :: IO ()\nmain = do\n ([n, k]) <- readInts\n letters <- getLine :: IO String\n let sorted1 = (map (+ 1) . map (\\x -> x - (ord 'a')) . map ord . map head . group . sort) letters\n let (result1, _) = foldl (\\(acc, prev) weight ->\n if (prev + 1 < weight)\n then (weight:acc, weight)\n else (acc, prev)\n )\n ([], -1)\n sorted1\n let resultd = reverse result1\n if ((length resultd) >= k)\n then print $ sum . take k $ resultd\n else print $ -1\n\n", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313"} {"source_code": "\nimport Char (digitToInt, ord)\n\nsolve :: [String] -> Int\nsolve [a, b]\n | k^n > s = n\n | otherwise = n + 1\n where\n n = max (length a) (length b)\n k = maximum (map digitToInt (a ++ b)) + 1\n s = from k a + from k b\n from k s = from' 0 s\n where\n from' acc [] = acc\n from' acc (c:s) = from' (k * acc + ord c - ord '0') s\n\nmain :: IO ()\nmain = fmap words getLine >>= print . solve", "src_uid": "8ccfb9b1fef6a992177cc49bd56fab7b"} {"source_code": "main = do\n x@[a, b, c] <- fmap (map read . words) getLine\n print $ a * b + b * c + c * a - sum x + 1\n", "src_uid": "8ab25ed4955d978fe20f6872cb94b0da"} {"source_code": "main = do\n [a,c] <- fmap (map untrit . map read . words) getLine\n print $ trit $ untor a c\nuntrit n | q == 0 && r == 0 = []\n | otherwise = r : untrit q\n where (q,r) = n `divMod` 3\ntrit (n:ns) = n + 3 * trit ns\ntrit _ = 0\nuntor (a:as) (c:cs) = ((c-a) `mod` 3) : untor as cs\nuntor [] cs = cs\nuntor as [] = map ((`mod` 3) . negate) as\n", "src_uid": "5fb635d52ddccf6a4d5103805da02a88"} {"source_code": "module Main where\nimport qualified Data.ByteString.Char8 as B\nimport Data.Int\nimport Data.List\n\nreadInt = maybe undefined (fromIntegral . fst) . B.readInteger\nreadInts = fmap readInt . B.words\n\nsolve :: Int64 -> Int64 -> Int64 -> Int64 -> Int64\nsolve x y l r = maximum $ (0:) $ (zipWith (\\a b -> a - b - 1) =<< drop 1) $ (++ [r + 1]) $ (l - 1:) $ sort [x^a + y^b | a <- [0..fk x], b <- [0..fk y], let n = x^a + y^b, l <= n && n <= r]\n where\n fk :: Int64 -> Int64\n fk k = floor $ logBase (fromIntegral k) (fromIntegral r)\n\nmain = do\n x:y:l:r:_ <- fmap readInts B.getLine\n print $ solve x y l r", "src_uid": "68ca8a8730db27ac2230f9fe9b120f5f"} {"source_code": "import Data.Function \nimport Data.List\nimport Control.Arrow\n\nmain = putStrLn =<< (\\x -> let t = round(sqrt $ fromIntegral x) in (show *** show >>> (\\(x,y)->x++\" \"++y)) $ minimumBy (compare `on` uncurry subtract) $ map (\\a -> (uncurry min &&& uncurry max) $ (x`div`a, a) ) $ filter (\\a -> x`mod`a == 0) $ [t,t-1..1] ) <$> (readLn :: IO Int)\n", "src_uid": "f52af273954798a4ae38a1378bfbf77a"} {"source_code": "answer::Int -> String -> Int\nanswer n s | null s = 0\n | l == '4' = k + (answer (n+1) i)\n | l == '7' = 2*k + (answer (n+1) i)\n where i = init s\n l = last s\n k = (iterate (*2) 1) !! n\nmain = getLine >>= print.(answer 0)\n", "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3"} {"source_code": "import Data.List (nub)\n\nmain = do\n getLine\n nums <- fmap (read :: String -> Int) <$> words <$> getLine\n\n let ans = reverse . nub $ reverse nums\n print $ length ans\n putStrLn . unwords . fmap show $ ans\n", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a"} {"source_code": "import Control.Applicative\nimport Control.Monad\nimport Data.Char\n\ngenAllVariant :: [Int] -> [[Int]]\ngenAllVariant [] = [[]]\ngenAllVariant (x:xs) = if x == 0\n then r\n else ((x - 1) : (take len (repeat 9))) : r\n where\n len = length xs\n r = map (x:) (genAllVariant xs)\n\ngetBestFromTwo :: [Int] -> [Int] -> [Int]\ngetBestFromTwo [] [] = []\ngetBestFromTwo a@(a0:as) b@(b0:bs)\n | (sum a) > (sum b) = a\n | (sum a) < (sum b) = b\n | a0 > b0 = a\n | a0 < b0 = b\n | otherwise = a0 : getBestFromTwo as bs\n\ndelNull :: String -> String\ndelNull \"0\" = \"0\"\ndelNull (x:xs) = if x == '0'\n then delNull xs\n else x:xs\n\ntoString :: [Int] -> String\ntoString num = delNull $ map intToDigit num\n\nsolve :: [Int] -> [Int]\nsolve num = foldr getBestFromTwo num (genAllVariant num)\n\nparseInput :: String -> [Int]\nparseInput str = map digitToInt $ head $ words str\n\nmain :: IO ()\nmain = interact $ (toString . solve . parseInput)\n", "src_uid": "e55b0debbf33c266091e6634494356b8"} {"source_code": "module Main where\n\nimport Data.List\nimport Data.Char\n \ntransitions = [\n [1, 2, 3, 4, 5, 6],\n [1, 6, 3, 5, 2, 4],\n [1, 4, 3, 2, 6, 5],\n [1, 5, 3, 6, 4, 2],\n\n [2, 3, 4, 1, 5, 6],\n [2, 6, 4, 5, 3, 1],\n [2, 1, 4, 3, 6, 5],\n [2, 5, 4, 6, 1, 3],\n\n [3, 4, 1, 2, 5, 6],\n [3, 6, 1, 5, 4, 2],\n [3, 2, 1, 4, 6, 5],\n [3, 5, 1, 6, 2, 4],\n\n [4, 1, 2, 3, 5, 6],\n [4, 6, 2, 5, 1, 3],\n [4, 3, 2, 1, 6, 5],\n [4, 5, 2, 6, 3, 1],\n\n [5, 2, 6, 4, 3, 1],\n [5, 1, 6, 3, 2, 4],\n [5, 4, 6, 2, 1, 3],\n [5, 3, 6, 1, 4, 2],\n\n [6, 2, 5, 4, 1, 3],\n [6, 3, 5, 1, 2, 4],\n [6, 4, 5, 2, 3, 1],\n [6, 1, 5, 3, 4, 2]]\n\n-- generatePermutations :: [a] -> [[a]]\n-- generatePermutations (x:xs) =\n-- let ret = generatePermutations xs in\n-- foldl (\\acc x -> insertNext ++ acc) [] ret\n-- where insertNext item = scanl (\\acc ys -> acc) [] item\n\nrotatedlyEqual :: String -> String -> Bool\nrotatedlyEqual src dest = any (\\tran -> dest == getColoring tran) transitions\n where getColoring orders = map (\\n -> src!!(n-1)) orders \n \ngenerateColorings :: String -> [String]\ngenerateColorings clrs = map (getColoring ) $ permutations [1..length(clrs)]\n where getColoring orders = map (\\n -> clrs!!(n-1)) orders \n\nstringTrim :: String -> String\nstringTrim = filter (not . isSpace)\n \nmain :: IO ()\nmain = interact (show . length . collectUniq [] . generateColorings . stringTrim )\n where\n collectUniq :: [String] -> [String] -> [String]\n collectUniq acc [] = acc\n collectUniq acc (clring:xs) = case (contains clring acc) of\n True -> collectUniq acc xs \n False -> collectUniq (clring:acc) xs\n where contains a ys = any (\\x -> rotatedlyEqual a x) ys\n \n \n", "src_uid": "8176c709c774fa87ca0e45a5a502a409"} {"source_code": "{-# OPTIONS_GHC -O3 #-}\n{-# LANGUAGE ViewPatterns, ScopedTypeVariables #-}\n\nimport Data.Function (on)\nimport Data.List (maximumBy, intercalate)\n\nrun :: Int -> Int -> (Double, [Int])\nrun n x | gcd x y == 1 && x < y = (fromIntegral x / fromIntegral y, [x, y])\n | otherwise = (0.0, [0, n]) where y = n - x\n\nmain = do\n (read -> n :: Int) <- getLine\n putStrLn $ intercalate \" \" $ map show $ snd $ maximumBy (compare `on` fst) $ map (run n) [1..n]\n", "src_uid": "0af3515ed98d9d01ce00546333e98e77"} {"source_code": "main = do\n [n, t] <- fmap (map read . words) getLine\n a <- getLine\n \n let\n f [] = []\n f ('B':'G':s) = 'G':'B':(f s)\n f (a:s) = a:(f s)\n \n putStrLn $ iterate f a !! t", "src_uid": "964ed316c6e6715120039b0219cc653a"} {"source_code": "-- 88A\nimport Data.List\nimport Maybe\nimport Array\n--import Char\nakks = [\"C\",\"C#\",\"D\",\"D#\",\"E\",\"F\",\"F#\",\"G\",\"G#\",\"A\",\"B\",\"H\"]\nf a (x:xs) = if (a == x) then (xs ++ [x]) else f a (xs ++ [x])\nlong (x:xs) b | (x == b) = 1\n | otherwise = 1 + long xs b\nwhat [a,b,c] | ((long p b == 4) && (long p c == 7)) = Just \"major\"\n | ((long p b == 3) && (long p c == 7)) = Just \"minor\"\n | otherwise = Nothing\n\twhere p = f a akks\n{-\npermutations [] = [[]]\npermutations xs = [x:ps | x <- xs, ps <- permutations (xs\\\\[x])]\n-}\ntoAkk [] l ak = (ak:l)\ntoAkk (' ':xs) l ak = toAkk xs (ak:l) \"\"\ntoAkk (x:xs) l ak = toAkk xs l (ak ++ [x])\n\nanalyse [] = \"strange\"\nanalyse (x:xs) | (x /= Nothing) = fromJust x\n | otherwise = analyse xs\n\nmain = do\n\t\t\ts <- getLine\n\t\t\tputStrLn $ analyse $ map (what) (permutations $ toAkk s [] [])\n", "src_uid": "6aa83c2f6e095848bc63aba7d013aa58"} {"source_code": "import Data.List\nimport Control.Monad\nmain = interact $ maybe \"-1\" show . solve . map read . words\nsolve [a,b] = merge (factor a) (factor b)\nmerge ((p1,f1):p1s) ((p2,f2):p2s)\n | p1 == p2 && f1 == f2 = merge p1s p2s\n | p1 == p2 && p1 <= 5 = fmap (abs (f1-f2) +) (merge p1s p2s)\n | p1 < p2 && p2 <= 5 = fmap (f1 +) (merge p1s ((p2,f2):p2s))\n | p2 < p1 && p1 <= 5 = fmap (f2 +) (merge ((p1,f1):p1s) p2s)\nmerge p1s p2s | p1s' == p2s' = Just (sum $ map snd $ l1 ++ l2)\n | otherwise = Nothing\n where (l1,p1s') = break ((> 5) . fst) p1s\n (l2,p2s') = break ((> 5) . fst) p2s\n\nfactor n = go n primes where\n go 1 _ = []\n go n (p:ps) | l > 0 = (p,l) : go (n `div` p^l) ps\n | otherwise = go n ps where\n ts = unfoldr (mfilter ((== 0) . fst) . pure . uncurry (flip (,)) . (`divMod` p)) n\n l = length ts\n go n [] = [(n,1)]\n\nprimes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,1279,1283,1289,1291,1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,1487,1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597,1601,1607,1609,1613,1619,1621,1627,1637,1657,1663,1667,1669,1693,1697,1699,1709,1721,1723,1733,1741,1747,1753,1759,1777,1783,1787,1789,1801,1811,1823,1831,1847,1861,1867,1871,1873,1877,1879,1889,1901,1907,1913,1931,1933,1949,1951,1973,1979,1987,1993,1997,1999,2003,2011,2017,2027,2029,2039,2053,2063,2069,2081,2083,2087,2089,2099,2111,2113,2129,2131,2137,2141,2143,2153,2161,2179,2203,2207,2213,2221,2237,2239,2243,2251,2267,2269,2273,2281,2287,2293,2297,2309,2311,2333,2339,2341,2347,2351,2357,2371,2377,2381,2383,2389,2393,2399,2411,2417,2423,2437,2441,2447,2459,2467,2473,2477,2503,2521,2531,2539,2543,2549,2551,2557,2579,2591,2593,2609,2617,2621,2633,2647,2657,2659,2663,2671,2677,2683,2687,2689,2693,2699,2707,2711,2713,2719,2729,2731,2741,2749,2753,2767,2777,2789,2791,2797,2801,2803,2819,2833,2837,2843,2851,2857,2861,2879,2887,2897,2903,2909,2917,2927,2939,2953,2957,2963,2969,2971,2999,3001,3011,3019,3023,3037,3041,3049,3061,3067,3079,3083,3089,3109,3119,3121,3137,3163,3167,3169,3181,3187,3191,3203,3209,3217,3221,3229,3251,3253,3257,3259,3271,3299,3301,3307,3313,3319,3323,3329,3331,3343,3347,3359,3361,3371,3373,3389,3391,3407,3413,3433,3449,3457,3461,3463,3467,3469,3491,3499,3511,3517,3527,3529,3533,3539,3541,3547,3557,3559,3571,3581,3583,3593,3607,3613,3617,3623,3631,3637,3643,3659,3671,3673,3677,3691,3697,3701,3709,3719,3727,3733,3739,3761,3767,3769,3779,3793,3797,3803,3821,3823,3833,3847,3851,3853,3863,3877,3881,3889,3907,3911,3917,3919,3923,3929,3931,3943,3947,3967,3989,4001,4003,4007,4013,4019,4021,4027,4049,4051,4057,4073,4079,4091,4093,4099,4111,4127,4129,4133,4139,4153,4157,4159,4177,4201,4211,4217,4219,4229,4231,4241,4243,4253,4259,4261,4271,4273,4283,4289,4297,4327,4337,4339,4349,4357,4363,4373,4391,4397,4409,4421,4423,4441,4447,4451,4457,4463,4481,4483,4493,4507,4513,4517,4519,4523,4547,4549,4561,4567,4583,4591,4597,4603,4621,4637,4639,4643,4649,4651,4657,4663,4673,4679,4691,4703,4721,4723,4729,4733,4751,4759,4783,4787,4789,4793,4799,4801,4813,4817,4831,4861,4871,4877,4889,4903,4909,4919,4931,4933,4937,4943,4951,4957,4967,4969,4973,4987,4993,4999,5003,5009,5011,5021,5023,5039,5051,5059,5077,5081,5087,5099,5101,5107,5113,5119,5147,5153,5167,5171,5179,5189,5197,5209,5227,5231,5233,5237,5261,5273,5279,5281,5297,5303,5309,5323,5333,5347,5351,5381,5387,5393,5399,5407,5413,5417,5419,5431,5437,5441,5443,5449,5471,5477,5479,5483,5501,5503,5507,5519,5521,5527,5531,5557,5563,5569,5573,5581,5591,5623,5639,5641,5647,5651,5653,5657,5659,5669,5683,5689,5693,5701,5711,5717,5737,5741,5743,5749,5779,5783,5791,5801,5807,5813,5821,5827,5839,5843,5849,5851,5857,5861,5867,5869,5879,5881,5897,5903,5923,5927,5939,5953,5981,5987,6007,6011,6029,6037,6043,6047,6053,6067,6073,6079,6089,6091,6101,6113,6121,6131,6133,6143,6151,6163,6173,6197,6199,6203,6211,6217,6221,6229,6247,6257,6263,6269,6271,6277,6287,6299,6301,6311,6317,6323,6329,6337,6343,6353,6359,6361,6367,6373,6379,6389,6397,6421,6427,6449,6451,6469,6473,6481,6491,6521,6529,6547,6551,6553,6563,6569,6571,6577,6581,6599,6607,6619,6637,6653,6659,6661,6673,6679,6689,6691,6701,6703,6709,6719,6733,6737,6761,6763,6779,6781,6791,6793,6803,6823,6827,6829,6833,6841,6857,6863,6869,6871,6883,6899,6907,6911,6917,6947,6949,6959,6961,6967,6971,6977,6983,6991,6997,7001,7013,7019,7027,7039,7043,7057,7069,7079,7103,7109,7121,7127,7129,7151,7159,7177,7187,7193,7207,7211,7213,7219,7229,7237,7243,7247,7253,7283,7297,7307,7309,7321,7331,7333,7349,7351,7369,7393,7411,7417,7433,7451,7457,7459,7477,7481,7487,7489,7499,7507,7517,7523,7529,7537,7541,7547,7549,7559,7561,7573,7577,7583,7589,7591,7603,7607,7621,7639,7643,7649,7669,7673,7681,7687,7691,7699,7703,7717,7723,7727,7741,7753,7757,7759,7789,7793,7817,7823,7829,7841,7853,7867,7873,7877,7879,7883,7901,7907,7919,7927,7933,7937,7949,7951,7963,7993,8009,8011,8017,8039,8053,8059,8069,8081,8087,8089,8093,8101,8111,8117,8123,8147,8161,8167,8171,8179,8191,8209,8219,8221,8231,8233,8237,8243,8263,8269,8273,8287,8291,8293,8297,8311,8317,8329,8353,8363,8369,8377,8387,8389,8419,8423,8429,8431,8443,8447,8461,8467,8501,8513,8521,8527,8537,8539,8543,8563,8573,8581,8597,8599,8609,8623,8627,8629,8641,8647,8663,8669,8677,8681,8689,8693,8699,8707,8713,8719,8731,8737,8741,8747,8753,8761,8779,8783,8803,8807,8819,8821,8831,8837,8839,8849,8861,8863,8867,8887,8893,8923,8929,8933,8941,8951,8963,8969,8971,8999,9001,9007,9011,9013,9029,9041,9043,9049,9059,9067,9091,9103,9109,9127,9133,9137,9151,9157,9161,9173,9181,9187,9199,9203,9209,9221,9227,9239,9241,9257,9277,9281,9283,9293,9311,9319,9323,9337,9341,9343,9349,9371,9377,9391,9397,9403,9413,9419,9421,9431,9433,9437,9439,9461,9463,9467,9473,9479,9491,9497,9511,9521,9533,9539,9547,9551,9587,9601,9613,9619,9623,9629,9631,9643,9649,9661,9677,9679,9689,9697,9719,9721,9733,9739,9743,9749,9767,9769,9781,9787,9791,9803,9811,9817,9829,9833,9839,9851,9857,9859,9871,9883,9887,9901,9907,9923,9929,9931,9941,9949,9967,9973,10007,10009,10037,10039,10061,10067,10069,10079,10091,10093,10099,10103,10111,10133,10139,10141,10151,10159,10163,10169,10177,10181,10193,10211,10223,10243,10247,10253,10259,10267,10271,10273,10289,10301,10303,10313,10321,10331,10333,10337,10343,10357,10369,10391,10399,10427,10429,10433,10453,10457,10459,10463,10477,10487,10499,10501,10513,10529,10531,10559,10567,10589,10597,10601,10607,10613,10627,10631,10639,10651,10657,10663,10667,10687,10691,10709,10711,10723,10729,10733,10739,10753,10771,10781,10789,10799,10831,10837,10847,10853,10859,10861,10867,10883,10889,10891,10903,10909,10937,10939,10949,10957,10973,10979,10987,10993,11003,11027,11047,11057,11059,11069,11071,11083,11087,11093,11113,11117,11119,11131,11149,11159,11161,11171,11173,11177,11197,11213,11239,11243,11251,11257,11261,11273,11279,11287,11299,11311,11317,11321,11329,11351,11353,11369,11383,11393,11399,11411,11423,11437,11443,11447,11467,11471,11483,11489,11491,11497,11503,11519,11527,11549,11551,11579,11587,11593,11597,11617,11621,11633,11657,11677,11681,11689,11699,11701,11717,11719,11731,11743,11777,11779,11783,11789,11801,11807,11813,11821,11827,11831,11833,11839,11863,11867,11887,11897,11903,11909,11923,11927,11933,11939,11941,11953,11959,11969,11971,11981,11987,12007,12011,12037,12041,12043,12049,12071,12073,12097,12101,12107,12109,12113,12119,12143,12149,12157,12161,12163,12197,12203,12211,12227,12239,12241,12251,12253,12263,12269,12277,12281,12289,12301,12323,12329,12343,12347,12373,12377,12379,12391,12401,12409,12413,12421,12433,12437,12451,12457,12473,12479,12487,12491,12497,12503,12511,12517,12527,12539,12541,12547,12553,12569,12577,12583,12589,12601,12611,12613,12619,12637,12641,12647,12653,12659,12671,12689,12697,12703,12713,12721,12739,12743,12757,12763,12781,12791,12799,12809,12821,12823,12829,12841,12853,12889,12893,12899,12907,12911,12917,12919,12923,12941,12953,12959,12967,12973,12979,12983,13001,13003,13007,13009,13033,13037,13043,13049,13063,13093,13099,13103,13109,13121,13127,13147,13151,13159,13163,13171,13177,13183,13187,13217,13219,13229,13241,13249,13259,13267,13291,13297,13309,13313,13327,13331,13337,13339,13367,13381,13397,13399,13411,13417,13421,13441,13451,13457,13463,13469,13477,13487,13499,13513,13523,13537,13553,13567,13577,13591,13597,13613,13619,13627,13633,13649,13669,13679,13681,13687,13691,13693,13697,13709,13711,13721,13723,13729,13751,13757,13759,13763,13781,13789,13799,13807,13829,13831,13841,13859,13873,13877,13879,13883,13901,13903,13907,13913,13921,13931,13933,13963,13967,13997,13999,14009,14011,14029,14033,14051,14057,14071,14081,14083,14087,14107,14143,14149,14153,14159,14173,14177,14197,14207,14221,14243,14249,14251,14281,14293,14303,14321,14323,14327,14341,14347,14369,14387,14389,14401,14407,14411,14419,14423,14431,14437,14447,14449,14461,14479,14489,14503,14519,14533,14537,14543,14549,14551,14557,14561,14563,14591,14593,14621,14627,14629,14633,14639,14653,14657,14669,14683,14699,14713,14717,14723,14731,14737,14741,14747,14753,14759,14767,14771,14779,14783,14797,14813,14821,14827,14831,14843,14851,14867,14869,14879,14887,14891,14897,14923,14929,14939,14947,14951,14957,14969,14983,15013,15017,15031,15053,15061,15073,15077,15083,15091,15101,15107,15121,15131,15137,15139,15149,15161,15173,15187,15193,15199,15217,15227,15233,15241,15259,15263,15269,15271,15277,15287,15289,15299,15307,15313,15319,15329,15331,15349,15359,15361,15373,15377,15383,15391,15401,15413,15427,15439,15443,15451,15461,15467,15473,15493,15497,15511,15527,15541,15551,15559,15569,15581,15583,15601,15607,15619,15629,15641,15643,15647,15649,15661,15667,15671,15679,15683,15727,15731,15733,15737,15739,15749,15761,15767,15773,15787,15791,15797,15803,15809,15817,15823,15859,15877,15881,15887,15889,15901,15907,15913,15919,15923,15937,15959,15971,15973,15991,16001,16007,16033,16057,16061,16063,16067,16069,16073,16087,16091,16097,16103,16111,16127,16139,16141,16183,16187,16189,16193,16217,16223,16229,16231,16249,16253,16267,16273,16301,16319,16333,16339,16349,16361,16363,16369,16381,16411,16417,16421,16427,16433,16447,16451,16453,16477,16481,16487,16493,16519,16529,16547,16553,16561,16567,16573,16603,16607,16619,16631,16633,16649,16651,16657,16661,16673,16691,16693,16699,16703,16729,16741,16747,16759,16763,16787,16811,16823,16829,16831,16843,16871,16879,16883,16889,16901,16903,16921,16927,16931,16937,16943,16963,16979,16981,16987,16993,17011,17021,17027,17029,17033,17041,17047,17053,17077,17093,17099,17107,17117,17123,17137,17159,17167,17183,17189,17191,17203,17207,17209,17231,17239,17257,17291,17293,17299,17317,17321,17327,17333,17341,17351,17359,17377,17383,17387,17389,17393,17401,17417,17419,17431,17443,17449,17467,17471,17477,17483,17489,17491,17497,17509,17519,17539,17551,17569,17573,17579,17581,17597,17599,17609,17623,17627,17657,17659,17669,17681,17683,17707,17713,17729,17737,17747,17749,17761,17783,17789,17791,17807,17827,17837,17839,17851,17863,17881,17891,17903,17909,17911,17921,17923,17929,17939,17957,17959,17971,17977,17981,17987,17989,18013,18041,18043,18047,18049,18059,18061,18077,18089,18097,18119,18121,18127,18131,18133,18143,18149,18169,18181,18191,18199,18211,18217,18223,18229,18233,18251,18253,18257,18269,18287,18289,18301,18307,18311,18313,18329,18341,18353,18367,18371,18379,18397,18401,18413,18427,18433,18439,18443,18451,18457,18461,18481,18493,18503,18517,18521,18523,18539,18541,18553,18583,18587,18593,18617,18637,18661,18671,18679,18691,18701,18713,18719,18731,18743,18749,18757,18773,18787,18793,18797,18803,18839,18859,18869,18899,18911,18913,18917,18919,18947,18959,18973,18979,19001,19009,19013,19031,19037,19051,19069,19073,19079,19081,19087,19121,19139,19141,19157,19163,19181,19183,19207,19211,19213,19219,19231,19237,19249,19259,19267,19273,19289,19301,19309,19319,19333,19373,19379,19381,19387,19391,19403,19417,19421,19423,19427,19429,19433,19441,19447,19457,19463,19469,19471,19477,19483,19489,19501,19507,19531,19541,19543,19553,19559,19571,19577,19583,19597,19603,19609,19661,19681,19687,19697,19699,19709,19717,19727,19739,19751,19753,19759,19763,19777,19793,19801,19813,19819,19841,19843,19853,19861,19867,19889,19891,19913,19919,19927,19937,19949,19961,19963,19973,19979,19991,19993,19997,20011,20021,20023,20029,20047,20051,20063,20071,20089,20101,20107,20113,20117,20123,20129,20143,20147,20149,20161,20173,20177,20183,20201,20219,20231,20233,20249,20261,20269,20287,20297,20323,20327,20333,20341,20347,20353,20357,20359,20369,20389,20393,20399,20407,20411,20431,20441,20443,20477,20479,20483,20507,20509,20521,20533,20543,20549,20551,20563,20593,20599,20611,20627,20639,20641,20663,20681,20693,20707,20717,20719,20731,20743,20747,20749,20753,20759,20771,20773,20789,20807,20809,20849,20857,20873,20879,20887,20897,20899,20903,20921,20929,20939,20947,20959,20963,20981,20983,21001,21011,21013,21017,21019,21023,21031,21059,21061,21067,21089,21101,21107,21121,21139,21143,21149,21157,21163,21169,21179,21187,21191,21193,21211,21221,21227,21247,21269,21277,21283,21313,21317,21319,21323,21341,21347,21377,21379,21383,21391,21397,21401,21407,21419,21433,21467,21481,21487,21491,21493,21499,21503,21517,21521,21523,21529,21557,21559,21563,21569,21577,21587,21589,21599,21601,21611,21613,21617,21647,21649,21661,21673,21683,21701,21713,21727,21737,21739,21751,21757,21767,21773,21787,21799,21803,21817,21821,21839,21841,21851,21859,21863,21871,21881,21893,21911,21929,21937,21943,21961,21977,21991,21997,22003,22013,22027,22031,22037,22039,22051,22063,22067,22073,22079,22091,22093,22109,22111,22123,22129,22133,22147,22153,22157,22159,22171,22189,22193,22229,22247,22259,22271,22273,22277,22279,22283,22291,22303,22307,22343,22349,22367,22369,22381,22391,22397,22409,22433,22441,22447,22453,22469,22481,22483,22501,22511,22531,22541,22543,22549,22567,22571,22573,22613,22619,22621,22637,22639,22643,22651,22669,22679,22691,22697,22699,22709,22717,22721,22727,22739,22741,22751,22769,22777,22783,22787,22807,22811,22817,22853,22859,22861,22871,22877,22901,22907,22921,22937,22943,22961,22963,22973,22993,23003,23011,23017,23021,23027,23029,23039,23041,23053,23057,23059,23063,23071,23081,23087,23099,23117,23131,23143,23159,23167,23173,23189,23197,23201,23203,23209,23227,23251,23269,23279,23291,23293,23297,23311,23321,23327,23333,23339,23357,23369,23371,23399,23417,23431,23447,23459,23473,23497,23509,23531,23537,23539,23549,23557,23561,23563,23567,23581,23593,23599,23603,23609,23623,23627,23629,23633,23663,23669,23671,23677,23687,23689,23719,23741,23743,23747,23753,23761,23767,23773,23789,23801,23813,23819,23827,23831,23833,23857,23869,23873,23879,23887,23893,23899,23909,23911,23917,23929,23957,23971,23977,23981,23993,24001,24007,24019,24023,24029,24043,24049,24061,24071,24077,24083,24091,24097,24103,24107,24109,24113,24121,24133,24137,24151,24169,24179,24181,24197,24203,24223,24229,24239,24247,24251,24281,24317,24329,24337,24359,24371,24373,24379,24391,24407,24413,24419,24421,24439,24443,24469,24473,24481,24499,24509,24517,24527,24533,24547,24551,24571,24593,24611,24623,24631,24659,24671,24677,24683,24691,24697,24709,24733,24749,24763,24767,24781,24793,24799,24809,24821,24841,24847,24851,24859,24877,24889,24907,24917,24919,24923,24943,24953,24967,24971,24977,24979,24989,25013,25031,25033,25037,25057,25073,25087,25097,25111,25117,25121,25127,25147,25153,25163,25169,25171,25183,25189,25219,25229,25237,25243,25247,25253,25261,25301,25303,25307,25309,25321,25339,25343,25349,25357,25367,25373,25391,25409,25411,25423,25439,25447,25453,25457,25463,25469,25471,25523,25537,25541,25561,25577,25579,25583,25589,25601,25603,25609,25621,25633,25639,25643,25657,25667,25673,25679,25693,25703,25717,25733,25741,25747,25759,25763,25771,25793,25799,25801,25819,25841,25847,25849,25867,25873,25889,25903,25913,25919,25931,25933,25939,25943,25951,25969,25981,25997,25999,26003,26017,26021,26029,26041,26053,26083,26099,26107,26111,26113,26119,26141,26153,26161,26171,26177,26183,26189,26203,26209,26227,26237,26249,26251,26261,26263,26267,26293,26297,26309,26317,26321,26339,26347,26357,26371,26387,26393,26399,26407,26417,26423,26431,26437,26449,26459,26479,26489,26497,26501,26513,26539,26557,26561,26573,26591,26597,26627,26633,26641,26647,26669,26681,26683,26687,26693,26699,26701,26711,26713,26717,26723,26729,26731,26737,26759,26777,26783,26801,26813,26821,26833,26839,26849,26861,26863,26879,26881,26891,26893,26903,26921,26927,26947,26951,26953,26959,26981,26987,26993,27011,27017,27031,27043,27059,27061,27067,27073,27077,27091,27103,27107,27109,27127,27143,27179,27191,27197,27211,27239,27241,27253,27259,27271,27277,27281,27283,27299,27329,27337,27361,27367,27397,27407,27409,27427,27431,27437,27449,27457,27479,27481,27487,27509,27527,27529,27539,27541,27551,27581,27583,27611,27617,27631,27647,27653,27673,27689,27691,27697,27701,27733,27737,27739,27743,27749,27751,27763,27767,27773,27779,27791,27793,27799,27803,27809,27817,27823,27827,27847,27851,27883,27893,27901,27917,27919,27941,27943,27947,27953,27961,27967,27983,27997,28001,28019,28027,28031,28051,28057,28069,28081,28087,28097,28099,28109,28111,28123,28151,28163,28181,28183,28201,28211,28219,28229,28277,28279,28283,28289,28297,28307,28309,28319,28349,28351,28387,28393,28403,28409,28411,28429,28433,28439,28447,28463,28477,28493,28499,28513,28517,28537,28541,28547,28549,28559,28571,28573,28579,28591,28597,28603,28607,28619,28621,28627,28631,28643,28649,28657,28661,28663,28669,28687,28697,28703,28711,28723,28729,28751,28753,28759,28771,28789,28793,28807,28813,28817,28837,28843,28859,28867,28871,28879,28901,28909,28921,28927,28933,28949,28961,28979,29009,29017,29021,29023,29027,29033,29059,29063,29077,29101,29123,29129,29131,29137,29147,29153,29167,29173,29179,29191,29201,29207,29209,29221,29231,29243,29251,29269,29287,29297,29303,29311,29327,29333,29339,29347,29363,29383,29387,29389,29399,29401,29411,29423,29429,29437,29443,29453,29473,29483,29501,29527,29531,29537,29567,29569,29573,29581,29587,29599,29611,29629,29633,29641,29663,29669,29671,29683,29717,29723,29741,29753,29759,29761,29789,29803,29819,29833,29837,29851,29863,29867,29873,29879,29881,29917,29921,29927,29947,29959,29983,29989,30011,30013,30029,30047,30059,30071,30089,30091,30097,30103,30109,30113,30119,30133,30137,30139,30161,30169,30181,30187,30197,30203,30211,30223,30241,30253,30259,30269,30271,30293,30307,30313,30319,30323,30341,30347,30367,30389,30391,30403,30427,30431,30449,30467,30469,30491,30493,30497,30509,30517,30529,30539,30553,30557,30559,30577,30593,30631,30637,30643,30649,30661,30671,30677,30689,30697,30703,30707,30713,30727,30757,30763,30773,30781,30803,30809,30817,30829,30839,30841,30851,30853,30859,30869,30871,30881,30893,30911,30931,30937,30941,30949,30971,30977,30983,31013,31019,31033,31039,31051,31063,31069,31079,31081,31091,31121,31123,31139,31147,31151,31153,31159,31177,31181,31183,31189,31193,31219,31223,31231,31237,31247,31249,31253,31259,31267,31271,31277,31307,31319,31321,31327,31333,31337,31357,31379,31387,31391,31393,31397,31469,31477,31481,31489,31511,31513,31517,31531,31541,31543,31547,31567,31573,31583,31601,31607]\n", "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49"} {"source_code": "main :: IO()\nmain = do\n n <- readLn :: IO Int\n let s = truncate . sqrt . fromIntegral $ n*2 :: Int\n if s*(s+1) == 2*n then putStrLn \"YES\" else putStrLn \"NO\"\n", "src_uid": "587d4775dbd6a41fc9e4b81f71da7301"} {"source_code": "{-# LANGUAGE FlexibleContexts, ScopedTypeVariables, BangPatterns #-}\n{-# OPTIONS_GHC -O2 #-}\n\nimport Control.Applicative\nimport Control.Monad\nimport Control.Monad.ST.Safe\nimport Control.Monad.State\nimport Data.Array\n-- import Data.Array.IArray\nimport Data.Array.IO.Safe\nimport Data.Array.MArray.Safe\nimport Data.Array.ST.Safe\n-- import Data.Array.Unboxed\nimport qualified Data.ByteString.Char8 as B\nimport qualified Data.ByteString.Lazy.Builder as BB\nimport Data.Char\nimport qualified Data.Foldable as F\nimport Data.Function\n-- import Data.Graph\nimport Data.Int\nimport Data.List\nimport Data.List.Split\nimport Data.Maybe\nimport Data.Monoid\nimport Data.Ratio\nimport qualified Data.Sequence as Seq\nimport Data.Sequence (Seq)\nimport Data.Set (Set)\nimport qualified Data.Set as Set\n-- import Data.Tree\nimport Data.Tuple\nimport Data.Map (Map)\nimport qualified Data.Map as Map\nimport Data.IntMap (IntMap)\nimport qualified Data.IntMap as IntMap\nimport System.IO\n-- import Debug.Trace\n\ngetInts = fmap (map read . words) getLine\n-- getInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine\n\nmain = do\n [a, b, c] <- getInts\n\n let\n x = (b-c+a) `div` 2\n y = b-x\n z = a-x\n\n putStrLn $\n if even (b-c+a) && all (>= 0) [x, y, z]\n then unwords $ map show [x, y, z]\n else \"Impossible\"\n", "src_uid": "b3b986fddc3770fed64b878fa42ab1bc"} {"source_code": "s[n,m,t,b]|x==y||x+1==y&&q==0||p==0&&(q==0||b==n)=1|p==q||p==0||q==0||m+q-p==b-a||b==n=2|1>0=3\n where(x,p)=a`divMod`m;(y,q)=b`divMod`m;a=t-1\nmain=interact$show.s.map read.words", "src_uid": "f256235c0b2815aae85a6f9435c69dac"} {"source_code": "{-# LANGUAGE MultiParamTypeClasses,FlexibleContexts,FlexibleInstances,TypeSynonymInstances,BangPatterns,RankNTypes #-}\n\nimport Control.Monad\nimport Control.Monad.ST\nimport Control.Applicative\nimport Control.Arrow\nimport Debug.Trace\n\nimport Data.List\nimport Data.Int\nimport Data.Maybe\nimport Data.Array.Unboxed\nimport Data.Array.ST\nimport qualified Data.Map as M\nimport qualified Data.Set as S\nimport qualified Data.ByteString.Char8 as B\n\ntype Array1 a = Array Int a\ntype Array2 a = Array (Int,Int) a\ntype UArray1 a = UArray Int a\ntype UArray2 a = UArray (Int,Int) a\ntype RecFun m a b = (a -> m b) -> a -> m b\n\nnewtype State s a = State { runState :: s -> (a,s) }\nnewtype Identity a = Identity { runIdentity :: a }\n\ninstance Functor (State s) where\n fmap f m = State $ runState m >>> first f\n\ninstance Monad (State s) where\n return x = State $ \\s -> (x,s)\n x >>= f = State $ \\s -> \n let (a,s') = runState x s in runState (f a) s'\n\ninstance Applicative (State s) where\n pure = return\n (<*>) = ap\n\ninstance Functor Identity where\n fmap f = runIdentity >>> f >>> Identity\n\ninstance Monad Identity where\n return = Identity\n x >>= f = f (runIdentity x)\n\ninstance Applicative Identity where\n pure = return\n (<*>) = ap\n\nclass IArray UArray e => Unboxable e where\n newSTUArray_ :: forall s i. Ix i => (i, i) -> ST s (STUArray s i e)\n readSTUArray :: forall s i. Ix i => STUArray s i e -> i -> ST s e\n writeSTUArray :: forall s i. Ix i => STUArray s i e -> i -> e -> ST s ()\n\ninstance Unboxable Int where\n newSTUArray_ = newArray_\n readSTUArray = readArray\n writeSTUArray = writeArray\n\ninstance Unboxable Char where\n newSTUArray_ = newArray_\n readSTUArray = readArray\n writeSTUArray = writeArray\n\nreadInt = B.readInt >>> fmap fst >>> fromMaybe 0\nreadLine :: Read a => IO a\nreadLine = read <$> getLine \nreadsLine :: Read a => IO [a]\nreadsLine = map read . words <$> getLine\n\ncmpFst (a,_) (b,_) = compare a b\ncmpSnd (_,a) (_,b) = compare a b\ncmpLen a b = length a `compare` length b\n\nswap (a,b) = (b,a)\nrect a b = rect2 0 0 a b\nrect2 i j a b = ((i,j),(a,b))\n\nitof :: Int -> Double\nitof = fromIntegral\n\nmaximize f l = snd $ maximumBy cmpFst [(f x,x) | x <- l]\nminimize f l = snd $ minimumBy cmpFst [(f x,x) | x <- l]\n\nfibs = 1:1:zipWith (+) fibs (tail fibs)\n\nprimeArray :: Int -> UArray1 Bool\nprimeArray n = runSTUArray $ do\n arr <- newArray (0,n) True\n writeArray arr 0 False\n writeArray arr 1 False\n forM_ (2:[3,5..n]) $ \\i -> do\n b <- readArray arr i\n when b $ forM_ [2*i,3*i..n] $ \\j -> writeArray arr j False\n return arr\n\nbinSearch f a b = go a b\n where\n go i j | i + 1 == j = i\n | f m = go m j\n | otherwise = go i m\n where m = div (i+j) 2\n\nfixMemoArray :: (Ix a) => (a,a) -> RecFun Identity a b -> Array a b\nfixMemoArray b f = arr\n where\n g y = Identity $ arr ! y\n arr = listArray b [ runIdentity $ f g x | x <- range b ]\n\nfixMemoUArray :: (Ix a,Unboxable b) => (a,a) -> (forall s . RecFun (ST s) a b) -> UArray a b\nfixMemoUArray b f = runSTUArray $ do\n arr <- newSTUArray_ b\n forM_ (range b) $ \\x -> f (\\y -> readSTUArray arr y) x >>= writeSTUArray arr x\n return arr\n\ncasti = fromIntegral\n\nmodulo = 10^9 + 7\n\nnewtype Modulo = Modulo { getInteger :: Integer } deriving(Eq,Ord)\ninstance Num Modulo where\n Modulo a + Modulo b = Modulo ((a+b) `mod` modulo)\n Modulo a - Modulo b = Modulo ((a-b) `mod` modulo)\n Modulo a * Modulo b = Modulo ((a*b) `mod` modulo)\n abs (Modulo a) = Modulo (abs a)\n signum (Modulo a) = Modulo (signum a)\n fromInteger i = Modulo i\ninstance Fractional Modulo where\n recip m = m ^ (modulo - 2)\n fromRational = undefined\n\ninstance Show Modulo where\n show (Modulo i) = show i\n \nsolve :: Int -> Int -> Int -> Modulo\nsolve n 0 0 | odd n = 1\nsolve n 0 1 | even n = 1\nsolve n 0 _ = 0\nsolve n m 0 = sum ([ f (n-k) (m-1) | k <- [0..n], even k]++[ g (n-k) (m-1) | k <- [0..n], odd k])\nsolve n m 1 = sum ([ f (n-k) (m-1) | k <- [0..n], odd k]++[ g (n-k) (m-1) | k <- [0..n], even k])\n\nf :: Int -> Int -> Modulo\nf 0 0 = 0\nf i j = comb (i+j) j\ng :: Int -> Int -> Modulo \ng 0 0 = 1\ng _ _ = 0\ncomb n k = fact n * recip ( fact k * fact (n-k))\n\nfact n = factMemo ! n\nfactMemo = fixMemoArray (0,200000) $ \\ f i -> case i of\n 0 -> pure 1\n n -> (casti n*) <$> f (n-1)\n\nmain = do\n [n,m,g] <- readsLine\n print $ solve n m g\n", "src_uid": "066dd9e6091238edf2912a6af4d29e7f"} {"source_code": "main=getLine>>=putStr.([\"NO\", \"YES\"]!!).fromEnum.((==)=<= x then x : solve (n - x) xs\n else solve n xs\n\nmain = do\n [s, k] <- map read <$> (words <$> getLine) :: IO [Integer]\n let kb = kbonacci k s\n as = solve s $ reverse kb\n print $ length as\n forM_ as $ putStr . ((++ \" \") . show)\n putStrLn \"\"", "src_uid": "da793333b977ed179fdba900aa604b52"} {"source_code": "import Control.Applicative\nimport Control.Monad\nimport Data.List\n\ngetIntList = fmap read . words <$> getLine\n\nputIntList = putStrLn . unwords . fmap show\n\nmain = sol <$> getIntList >>= putIntList\n\nsol [n,k] = if k <= length fs then product qs:ps else [-1]\n where\n fs = primeFactors n\n (ps,qs) = splitAt (k-1) fs\n\n-- | Prime numbers\nprimes :: Integral a => [a]\nprimes = 2 : filter ((==1) . length . primeFactors) [3,5..]\n\nprimeFactors :: Integral a => a -> [a]\nprimeFactors 1 = []\nprimeFactors n = factor n primes\n\nfactor :: Integral a => a -> [a] -> [a]\nfactor n (p:ps) \n | p*p > n = [n]\n | n `mod` p == 0 = p : factor (n `div` p) (p:ps)\n | otherwise = factor n ps\n", "src_uid": "bd0bc809d52e0a17da07ccfd450a4d79"} {"source_code": "{-# LANGUAGE ScopedTypeVariables #-}\nmodule Main where\n\nmain :: IO ()\nmain = do\n line <- getLine >> getLine\n let nums :: [Integer] = map read . words $ line\n --let nums = [0,1,0,0,0,1,0,0,0,0]\n putStrLn . show . solve $ nums\n\nsolve :: [Integer] -> Integer\nsolve xs = case foldl f [] xs of\n [] -> 0\n [_] -> 1\n xs -> product $ tail $ xs\n where\n f [] 0 = []\n f (a:acc) 0 = (a+1) : acc\n f acc 1 = 1 : acc", "src_uid": "58242665476f1c4fa723848ff0ecda98"} {"source_code": "import Data.Char\nmain = do getLine >>= putStr . (\\i -> if i then \"YES\" else \"NO\") . or . zipWith (==) \"AEIOUY\" . repeat . toUpper . last . filter isAlpha\n{-\n\n-}\n", "src_uid": "dea7eb04e086a4c1b3924eff255b9648"} {"source_code": "\nmain = interact $ show . sol . map read . words\n\nsol [x1, y1, x2, y2] = max difx dify\n where\n difx = abs $ x1-x2\n dify = abs $ y1-y2\n", "src_uid": "a6e9405bc3d4847fe962446bc1c457b4"} {"source_code": "import Data.Char \n\ngetInt :: IO Int\ngetInt = do \n line <- getLine\n return (read line :: Int)\n\ntoInt str = (read str :: Int)\ntoStr i = show(i)\n\nremoveZero digit = [ x | x <- digit, x /= '0' ]\n\nmain = do \n a <- getInt\n b <- getInt\n let c = a + b\n let strc = toStr c\n let ans1 = removeZero strc\n let stra = toStr a\n let strb = toStr b\n let removea = removeZero stra\n let removeb = removeZero strb\n let aa = toInt removea\n let bb = toInt removeb\n let cc = aa + bb\n let ans2 = toStr cc\n if ans1 == ans2\n then putStrLn \"YES\"\n else putStrLn \"NO\"\n", "src_uid": "ac6971f4feea0662d82da8e0862031ad"} {"source_code": "#!/usr/bin/env runghc\nmain = getContents >>= mapM_ putStrLn . solve . lines\nsolve [] = [] ::[String]\nsolve (c:cs) = (:solve cs)$ unwords . map show $ [r,b,k]\n where\n [r1,c1,r2,c2] = map read . words $ c\n r = a+b\n where\n a = if r1==r2 then 0 else 1\n b = if c1==c2 then 0 else 1\n b\n | odd (a+b) = 0\n | a==b = 1\n | otherwise = 2\n where\n a = abs (r1-r2)\n b = abs (c1-c2)\n k = max (abs (r1-r2)) (abs (c1-c2))\n", "src_uid": "7dbf58806db185f0fe70c00b60973f4b"} {"source_code": "import Data.Int (Int64)\n\nmodVal :: Int64\nmodVal = 998244353\n\ncv :: Int64 -> Int64\ncv n = rem n modVal\n\npm :: Int64 -> Int64 -> Int64\n--powMod\npm x' y' = go x' y' 1 where\n go _ 0 acc = acc\n go x y acc\n | even y = go (cv (x*x)) (quot y 2) acc\n | otherwise = go (cv (x*x)) (quot y 2) (cv (acc*x))\n\nfrac :: Int64 -> Int64 -> Int64\nfrac x y = cv (x * pm y (modVal - 2))\n\nchoose :: Int64 -> Int64 -> Int64\nchoose n k = go 0 1 where\n go ck acc\n | k == ck = acc\n | otherwise = go (ck+1) $ frac (cv (acc * (n-ck))) (ck+1)\n\nsolve :: (Int64, Int64) -> Int64\nsolve (n, k) = cv $ sum [choose (div n i - 1) (k - 1) | i <- [1 .. div n k]] \n\nparse :: String -> [(Int64, Int64)]\nparse inp = [(n, k) | [n, k] <- map (map read . words) $ lines inp]\n\nmain :: IO ()\nmain = interact (unlines . map (show . solve) . parse)\n\n", "src_uid": "8e8eb64a047cb970a549ee870c3d280d"} {"source_code": "solve xs | s > 0 && s `mod` 5 == 0 = s `div` 5\n | otherwise = -1\n where s = sum xs\n\nmain = do\n line <- getLine\n let xs = map read $ words line :: [Int]\n print $ solve xs\n", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20"} {"source_code": "import Data.List\nimport Data.Int\nimport Control.Applicative\nimport qualified Data.ByteString.Char8 as B\n\nmain = do\n (n:k:_) <- readInp <$> B.getLine\n putStrLn $ show $ solve n k\n where readInp = fmap readInt. B.words\n readInt = fromIntegral. maybe 0 fst. B.readInteger\n\nsolve :: Int64 -> Int64 -> Int64\nsolve n k = (getKth (fromIntegral k)). sort. addBig $ smalldivs\n where smalldivs = [x | x <- [1..isqrt n], rem n x == 0]\n isqrt = floor. sqrt. fromIntegral\n addBig = concatMap (\\x -> nub [x, quot n x])\n getKth k lst = if (length lst < k) then -1 else lst !! (k-1)\n", "src_uid": "6ba39b428a2d47b7d199879185797ffb"} {"source_code": "{-# LANGUAGE BangPatterns, ViewPatterns, PatternGuards, ScopedTypeVariables #-}\n{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind -fno-warn-type-defaults -fno-warn-orphans #-}\n\nimport Control.Applicative\nimport Control.Monad\nimport Data.List\n\nunique :: Ord a => [a] -> [a]\nunique = map head . group . sort\n\ninRange :: (Int, Int) -> Bool\ninRange (y, x) = 1 <= y && y <= 8 && 1 <= x && x <= 8\n\nsolve :: [(Int, Int)] -> [(Int, Int)] -> IO ()\nsolve statues xs\n | null xs = putStrLn \"LOSE\"\n | any (== (1, 8)) xs || null statues = putStrLn \"WIN\"\n | otherwise = solve statues' xs'\n where\n statues' = do\n (y, x) <- statues\n guard $ y <= 7\n return (y + 1, x)\n xs' = unique $ do\n (y, x) <- xs\n filter ((&&) <$> (`notElem` statues') <*> (`notElem` statues)) $\n filter inRange $ (,) <$> [y - 1, y, y + 1] <*> [x - 1, x, x + 1]\n\n\nmain :: IO ()\nmain = do\n (concat -> statues) <- forM [1 .. 8] $ \\y -> do\n row <- getLine\n return $ do\n (x, c) <- zip [1 ..] row\n guard $ c == 'S'\n return (y, x)\n solve statues [(8, 1)]\n\n{-\nSSSSSSSA\n.....SS.\n....S...\n...S....\n..S.....\n.S......\nS.......\nM.......\n-}\n", "src_uid": "f47e4ab041288ba9567c19930eb9a090"} {"source_code": "-- 846B\n\nimport Data.List (sort)\n\nmain = do\n (n:k:m:_) <- fmap (map read . words) getLine\n interact $ show . bf n k m . sort . map read . words\n\nbf :: Int -> Int -> Int -> [Int] -> Int\nbf n k m xs = let s = sum xs in\n maximum $ 0:[i*(k+1) + program (n-i) (m-(i*s)) xs | i <- [0..n], m >= i*s]\n \nprogram :: Int -> Int -> [Int] -> Int\nprogram n m (c:cs) | c <= m =\n let cost = min (c*n) m\n score = cost `div` c * (if null cs then 2 else 1)\n in score + (program n (m - cost) cs)\nprogram _ _ _ = 0\n", "src_uid": "d659e92a410c1bc836be64fc1c0db160"} {"source_code": "{-# LANGUAGE BangPatterns #-}\n{-# LANGUAGE BinaryLiterals #-}\n{-# LANGUAGE MultiWayIf #-}\n{-# LANGUAGE NumDecimals #-}\n{-# LANGUAGE ScopedTypeVariables #-}\n{-# LANGUAGE TupleSections #-}\n\nimport Control.Applicative\nimport Control.Arrow\nimport Control.Monad\nimport Control.Monad.ST\n\nimport Data.Char\nimport Data.List\nimport Data.Maybe\n\nimport qualified Data.ByteString.Char8 as B\n\nimport Data.Array.ST.Safe\nimport Data.STRef\n\n-- import Debug.Trace\nimport Text.Printf\n\nreadInt = readLn :: IO Int\nreadInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine\nreadNInts = readInt >>= flip replicateM readInt\n\nwhich a b f = if f then a else b\nmp [ a, b ] = ( a, b )\n\nmain = do\n\tgetLine\n\ts <- getLine\n\tlet\n\t\tps = solve 0 s\n\t\tmi = minimum ps\n\tprint $ last ps - mi\n\nsolve p [] = [p]\nsolve p (c:s) = p : solve ( f p ) s\n\twhere\n\t\tf = if c == '+' then succ else pred", "src_uid": "a593016e4992f695be7c7cd3c920d1ed"} {"source_code": "{-# LANGUAGE ScopedTypeVariables #-}\n{-# LANGUAGE BangPatterns #-}\n\nimport Control.Applicative\nimport Control.Monad\nimport Control.Arrow\nimport Data.List\nimport Data.Maybe\nimport Data.Char\nimport qualified Data.ByteString.Char8 as B\nimport Text.Printf\n\nreadInt = ( readLn :: IO Int )\nreadInts = map ( read :: String -> Int ) . words <$> getLine\n\ngetList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine\n\nwhich a b f = if f then a else b\nmp [ a, b ] = ( a, b )\n\nmain = getLine >>= putStrLn . which \"Yes\" \"No\" . solve\n\nsolve (a:b:c:rest)\n\t| a == '.' = solve (b:c:rest)\n\t| b == '.' = solve (b:c:rest)\n\t| c == '.' = solve (b:c:rest)\n\t| a /= b && b /= c && c /= a = True\n\t| otherwise = solve (b:c:rest)\nsolve _ = False", "src_uid": "ba6ff507384570152118e2ab322dd11f"} {"source_code": "module Main where\nimport Data.Char\nimport System.Environment\n\nmain = do\n\tparamStr <- getLine\n\tlet\n\t\tparams = (readIntsFromStr paramStr)\n\t\tcommonDivider = gcd' ((params!!0)*(params!!3)) ((params!!1)*(params!!2))\n\t\theight = (div (params!!2 * params!!1) commonDivider)\n\t\twidth = (div (params!!3 * params!!0) commonDivider)\n\t\tin putStrLn $ id (show (abs (height - width)) ++ \"/\" ++ show (max height width))\n\ngcd' :: Int -> Int -> Int\ngcd' a b\n\t| (mod a b == 0) = b\n\t| otherwise = gcd b (mod a b)\n\nreadIntsFromStr :: String -> [Int]\nreadIntsFromStr str = map readInt (filter p (wordsWhen (==' ') str))\n\twhere p = (/=)\"\"\n\nreadInt :: String -> Int\nreadInt = read\n\nreadDoublesFromStr :: String -> [Double]\nreadDoublesFromStr str = map readDouble (filter p (wordsWhen (==' ') str))\n\twhere p = (/=)\"\"\n\nreadDouble :: String -> Double\nreadDouble = read\n\nwordsWhen :: (Char -> Bool) -> String -> [String]\nwordsWhen p s = case dropWhile p s of\n \"\" -> []\n s' -> w : wordsWhen p s''\n where (w, s'') = break p s'\n", "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e"} {"source_code": "\nmain = interact $ show . (\\x -> (x+2*m)`mod`m) . sol . map read . words\n where m = 1000000007\n\nsol :: [Integer] -> Integer\nsol (x:y:n:_) = case n `mod` 6 of 1 -> x\n 2 -> y\n 3 -> y-x\n 4 -> -x\n 5 -> -y\n 0 -> -y+x\n ", "src_uid": "2ff85140e3f19c90e587ce459d64338b"} {"source_code": "main=interact$show.f.read\nf n=div (n*n*(n-1)*(n-1)*(n-2)*(n-2)*(n-3)*(n-3)*(n-4)*(n-4)) 120", "src_uid": "92db14325cd8aee06b502c12d2e3dd81"} {"source_code": "main = interact (s.map read.words)\ns [x,y] = if fromIntegral(floor l)==l || (i*b)==1 then \"black\" else \"white\"\n where\n l=sqrt(fromIntegral(x*x+y*y))\n b=if even (floor l) then 1 else -1\n i=if (x*y)>0 then 1 else -1\n", "src_uid": "8c92aac1bef5822848a136a1328346c6"} {"source_code": "import Data.Char\nmain=interact$show.b.lines.map toLower\nb [x,y] = a x y\na [] _ = 0\na (x:c) (y:d)\n |x == y = a c d\n |x0 = 1\n", "src_uid": "ffeae332696a901813677bd1033cf01e"} {"source_code": "module Main where\n import Data.List\n import Control.Monad\n import Data.Array\n import qualified Data.Set as S\n\n toArray :: [a] -> Array Int a\n toArray xs =\n let ls = length xs - 1\n in array (0, ls) $ zip [0..ls] xs\n\n readInt :: String -> Int\n readInt s = read s :: Int\n\n readInteger :: String -> Integer\n readInteger s = read s :: Integer\n\n readMultilineInput :: Int -> (String -> IO a) -> IO [a]\n readMultilineInput n transformer = replicateM n (getLine >>= transformer)\n\n elemSet :: (Ord a) => a -> S.Set a -> Bool\n elemSet elem sets =\n let found = elem `S.lookupIndex` sets\n in toBool found\n where\n toBool :: Maybe Int -> Bool\n toBool (Just _) = True\n toBool Nothing = False\n\n data Point = Point { x :: Int, y :: Int } deriving (Ord, Eq)\n\n instance Show Point where\n show (Point x y) = show x ++ \" \" ++ show y\n\n fromPair :: [Int] -> Point\n fromPair (x:y:[]) = Point x y\n\n minus :: Point -> Point -> Point\n minus (Point x1 y1) (Point x2 y2) = Point (x1 - x2) (y1 - y2)\n\n plus :: Point -> Point -> Point\n plus (Point x1 y1) (Point x2 y2) = Point (x1 + x2) (y1 + y2)\n\n solutions :: Point -> Point -> Point -> Point\n solutions p1 p2 p3 = (p1 `minus` p2) `plus` p3\n\n main :: IO()\n main = do\n p1 <- getLine >>= return . fromPair . (map readInt) . words\n p2 <- getLine >>= return . fromPair . (map readInt) . words\n p3 <- getLine >>= return . fromPair . (map readInt) . words\n let ans = [\n solutions p1 p2 p3,\n solutions p1 p3 p2,\n solutions p2 p1 p3,\n solutions p2 p3 p1,\n solutions p3 p1 p2,\n solutions p3 p2 p1\n ]\n sans = S.fromList ans\n lsans = S.toList sans\n print $ length $ lsans\n forM_ lsans print\n", "src_uid": "7725f9906a1b87bf4e866df03112f1e0"} {"source_code": "import Data.List (group)\n\nok :: String -> Bool\nok s =\n all (\\ x -> x == 1) $ map (\\ l -> length l) $ group s\n\nmain = do\n chess <- getContents\n if ok chess\n then putStrLn \"YES\"\n else putStrLn \"NO\"\n\n", "src_uid": "ca65e023be092b2ce25599f52acc1a67"} {"source_code": "import Control.Applicative\nimport Control.Arrow\nimport Control.Monad\nimport Data.List\n\ngetInt :: IO Int\ngetInt = (read::String->Int) <$> getLine\n\ngetIntList :: IO [Int]\ngetIntList = map (read::String->Int) . words <$> getLine\n\nmain = do\n _ <- getInt\n ws <- getIntList\n putStrLn $ sol ws\n\nsol :: [Int] -> String\nsol ws = if ed ws then \"YES\" else \"NO\"\n where\n ed ws = if n1 > 0 then even n1 else even n2\n n1 = length (filter (==100) ws)\n n2 = length ws - n1\n", "src_uid": "9679acef82356004e47b1118f8fc836a"} {"source_code": "import Control.Applicative\n\nprocess::Int->Int\nprocess c |c >=0 = c\n |c> -10 = 0\n |otherwise = max (read $ init cc) (read (( init (init cc) )++ [last cc]))\n where cc = show c\n\nmain=do\n\n q<- read <$> getLine::IO Int\n print $ process q\n", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e"} {"source_code": "{-# LANGUAGE TupleSections, MultiParamTypeClasses, ExistentialQuantification, \n RankNTypes, FlexibleContexts, DeriveFunctor #-}\n\nimport Control.Monad\nimport Control.Applicative \n--import Control.Lens\n--import Control.Zipper\nimport Control.Arrow\nimport qualified Data.Map as M\n--import qualified Data.Vector as V\nimport qualified Data.Set as S\nimport Data.List\n--import Debug.Trace\n--import Control.Comonad\nimport Data.Monoid\n--import Data.Functor.Foldable\n--import Test.QuickCheck\nimport Data.Tree\n--import Data.Machine\n--import Data.Traversable\n--import Data.Distributive\n--import Linear\nimport Control.Monad.Cont\n\n\nmain = do\n n <- fmap read getLine\n let (m, mx) = solve n\n putStrLn $ show m ++ \" \" ++ show mx\n\n\nmin1Week x | x <= 5 = 0\n | x == 6 = 1\n | otherwise = 2\nmax1Week x = min x 2\n\nsolve n = (2*(n`div`7) + min1Week (n`mod`7),2*(n`div`7) + max1Week (n`mod`7))\n", "src_uid": "8152daefb04dfa3e1a53f0a501544c35"} {"source_code": "func :: Integer -> Integer -> (Integer, Integer)\nfunc a b = if a==0 || b==0 then (a,b)\n else if a>=2*b then func (a `mod` (2*b)) b\n else if b>=2*a then func a (b `mod` (2*a))\n else (a,b)\n\nmain :: IO ()\nmain = do\n nm <- getLine\n let n:m:_ = (map read (words nm)) :: [Integer] in\n let (a,b) = func n m\n in putStrLn $ show a ++ \" \" ++ show b\n return ()", "src_uid": "1f505e430eb930ea2b495ab531274114"} {"source_code": "main = readLn >>= print . (+9) . length . takeWhile (>=10) . mkLs\n\nmkLs n = n : (mkLs $ rm0 $ n + 1)\n\nrm0 n\n | n `mod` 10 == 0 = rm0 $ n `div` 10\n | otherwise = n", "src_uid": "055fbbde4b9ffd4473e6e716da6da899"} {"source_code": "import Control.Monad\nimport Data.IORef\nimport Data.List\n\n\nmain :: IO ()\nmain = do\n inp <- getLine\n let [n, k] = (map (read::String -> Int)) (words inp)\n inpp <- getLine\n let parsed = sortBy (\\(_, x) (_, y) -> compare x y) (zip [1, 2..] ((map (read::String -> Int)) (words inpp)))\n ptr <- newIORef (snd (head parsed) - 1)\n ll <- newIORef ([])\n forM_ parsed (\\(n, x) -> do\n cur <- readIORef ptr\n if (x > cur) then modifyIORef ll (n:) >> writeIORef ptr x\n else return ())\n ans <- readIORef ll\n if (length ans >= k) then putStr \"YES\\n\" >> putStrLn (foldr (\\x z -> (show x) ++ \" \" ++ z) [] (take k ans))\n else putStr \"NO\"\n return ()\n", "src_uid": "5de6574d57ab04ca195143e08d28d0ad"} {"source_code": "main = getContents >>= putStrLn . solve . tail . map read . words\n\nsolve xs\n | any (==0) $ map ((`mod` 360) . sum) $ expand xs = \"YES\"\n | otherwise = \"NO\"\n\nexpand [] = [[]]\nexpand (x:xs) = map (x:) xs' ++ map (-x:) xs'\n where xs' = expand xs\n", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10"} {"source_code": "import Data.List\nimport Data.Int\nimport qualified Data.Array as A\nimport Data.Array((!))\nimport Numeric\nimport Data.Maybe(fromJust)\n\nfastRead :: String -> Int64\nfastRead ('-':s) = case readDec s of [(n, \"\")] -> (-n)\nfastRead s = case readDec s of [(n, \"\")] -> n\n\nmain = interact solve\n\nsolve input = answer\n where\n (a', _:input') = splitAt (fromJust $ elemIndex '.' input) input\n (d', _:b_s) = splitAt (fromJust $ elemIndex 'e' input') input'\n b = read b_s\n\n a = dropWhile ('0' ==) a'\n d = reverse . dropWhile ('0' ==) $ reverse d'\n combined = a ++ d\n normedb = b+(length a)\n\n add_dot place [] = replicate place '0'\n\n add_dot place (x:xs)\n | place == 0 = '.':x:xs\n | otherwise = x:(add_dot (place-1) xs)\n\n answer::String\n answer = case answer' of\n \"\" -> \"0\"\n '.':_ -> '0':answer'\n otherwise -> answer'\n where\n answer' = add_dot normedb combined\n", "src_uid": "a79358099f08f3ec50c013d47d910eef"} {"source_code": "module Main where\n\nd '0' = \"O-|-OOOO\"\nd '1' = \"O-|O-OOO\"\nd '2' = \"O-|OO-OO\"\nd '3' = \"O-|OOO-O\"\nd '4' = \"O-|OOOO-\"\nd '5' = \"-O|-OOOO\"\nd '6' = \"-O|O-OOO\"\nd '7' = \"-O|OO-OO\"\nd '8' = \"-O|OOO-O\"\nd '9' = \"-O|OOOO-\"\n\nmain = getLine >>= mapM_ putStrLn . map d . reverse \n", "src_uid": "c2e3aced0bc76b6484360563355d23a7"} {"source_code": "main =\n interact $ solve . lines\nsolve :: [String] -> String\nsolve (_:regex:_) =\n let pokemon = [\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\"] in\n head $ take 1 $ filter (\\x -> length x == length regex) $ filter (f regex) pokemon\n where\n f :: String -> String -> Bool\n f reg pokemon =\n not $ or $ zipWith (\\x -> \\y -> x /= y && x /= '.') reg pokemon\n", "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0"} {"source_code": "--\r\n-- Michael V. Antosha\r\n-- 2022\r\n-- Michael.Antosha@gmail.com\r\n--\r\n\r\n{-# language Safe #-}\r\n{-# language ImportQualifiedPost #-}\r\n{-# language NoMonomorphismRestriction #-}\r\n\r\n{-# options_ghc -O3 #-}\r\n\r\n{-# options_ghc -Weverything #-}\r\n{-# options_ghc -Werror #-}\r\n\r\n{-# options_ghc -Wno-missing-import-lists #-}\r\n{-# options_ghc -Wno-missing-local-signatures #-}\r\n\r\nimport Prelude hiding (getLine)\r\nimport Control.Arrow\r\nimport Control.Monad\r\nimport Data.ByteString.Char8 qualified as B\r\nimport Data.Char\r\nimport Data.List qualified as L\r\n\r\nri = readInts <$> B.getLine :: IO [Int]\r\n where\r\n readInts = L.unfoldr ((second dropSpace <$>) . B.readInt) . dropSpace\r\n dropSpace = B.dropWhile isSpace\r\n\r\nmain :: IO ()\r\nmain = do\r\n [t] <- ri\r\n tcs <- replicateM t $ do\r\n [[n], xs@[_,_,_]] <- replicateM 2 ri\r\n return (n, xs)\r\n mapM_ (putStrLn.showYN.solve) tcs\r\n\r\nshowYN False = \"NO\"\r\nshowYN True = \"YES\"\r\n\r\nsolve (n,xs) = (==[1,2,3]) . L.sort . take 3 . map fst . iterate nextUnlock $ (n,ys)\r\n where\r\n ys = zip inds xs\r\n\r\nnextUnlock (n,ys) = (nn,ys)\r\n where\r\n nn = maybe n snd . L.find ((==n).fst) $ ys\r\n\r\ninds = [1..] :: [Int]\r\n", "src_uid": "5cd113a30bbbb93d8620a483d4da0349"} {"source_code": "main = interact$ f.head.lines\nf [] = \"YES\"\nf ('1':'4':'4':xs) = f xs\nf ('1':'4':xs) = f xs\nf ('1':xs) = f xs\nf _ = \"NO\"", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5"} {"source_code": "import Data.List\n\nmain = interact $ process . map read . words\nprocess x = if (test x) then \"Alice\" else \"Bob\"\ntest (n:y) = m <= div n 2\n where m = length $ head $ group $ sort y", "src_uid": "4b9cf82967aa8441e9af3db3101161e9"} {"source_code": "module Main where \n\nimport qualified Data.Text.IO as T\nimport qualified Data.Text as T\n\nmain = do\n t <- T.getLine\n putStrLn\n $ show\n $ (\\[n,k] -> sol n k 1 (n*k + k))\n $ map read\n $ words\n $ T.unpack t\n\nsol :: Int -> Int -> Int -> Int -> Int\nsol n k i res | n == 1 = k+1\n | i > k-1 = res \n | mod n i == 0 = if res' < res\n then sol n k (i+1) res' \n else sol n k (i+1) res \n | True = sol n k (i+1) res\n where res' = k * (div n i) + i", "src_uid": "ed0ebc1e484fcaea875355b5b7944c57"} {"source_code": "\nmain = do\n\ta<-getLine\n\tb<-getLine\n\tputStrLn $solve a b\n\nsolve a b | a == reverse b = \"YES\"\n | otherwise = \"NO\"\n", "src_uid": "35a4be326690b58bf9add547fb63a5a5"} {"source_code": "\n\n\n\nmain = do\n [x,y] <- fmap (map read . words) getLine :: IO [Integer]\n print (solve y x)\n\nsolve m n = sum $ map f [1..n]\n where\n f x | x `mod` 5 == 0 = (m - ((5 - (x `mod` 5))`mod` 5)) `div` 5\n | otherwise = ((m - (5 - (x `mod` 5))) `div` 5) + 1\n", "src_uid": "df0879635b59e141c839d9599abd77d2"} {"source_code": "import qualified Data.ByteString.Lazy.Char8 as BS\r\nimport Control.Monad\r\nimport Data.List\r\nimport Data.Maybe\r\nimport System.IO\r\nimport System.IO.Unsafe\r\n\r\ndeb s e = unsafePerformIO $ do\r\n hPutStrLn stderr s\r\n return e\r\n\r\nparseInt = fst . fromJust . BS.readInt\r\nparseInteger = fst . fromJust . BS.readInteger\r\n\r\nsolve :: Int -> Int\r\nsolve k =\r\n let\r\n g = gcd k (100 - k)\r\n in\r\n k `div` g + (100 - k) `div` g\r\n\r\nmain = do\r\n s <- BS.getContents\r\n forM_ (parseInt <$> tail (BS.lines s)) (print . solve)\r\n", "src_uid": "19a2bcb727510c729efe442a13c2ff7c"} {"source_code": "import Control.Applicative( (<$>))\n\nmain = do\n [c_,v0_,v1_,a_,l_] <- map read . words <$> getLine\n let\n\tstride d = min (v0_+d*a_) v1_\n\n\tcount1st toRead = let\n\t\t\t\ttoRead' = c_-v0_\n\t\t\t in\n\t\t\t\tif toRead' <= 0\n\t\t\t\tthen 1\n\t\t\t\telse count 1 toRead'\n\n\tcount day toRead = let\n\t\t\t\ttoRead' = toRead+l_-stride day\n\t\t\tin\n\t\t\t if toRead' <= 0\n\t\t\t\tthen day+1\n\t\t\t\telse count (day+1) toRead'\n print $ count1st c_\n", "src_uid": "b743110117ce13e2090367fd038d3b50"} {"source_code": "main :: IO ()\nmain = (getLine >> getLine) >>= (\\s -> print (count 'L' s + count 'R' s + 1))\n where count el = length . filter (el==)\n", "src_uid": "098ade88ed90664da279fe8a5a54b5ba"} {"source_code": "{-# OPTIONS_GHC -O2 #-}\n\nimport Data.Char (ord)\n\nparseInt = foldl (\\acc c -> acc * 10 + ord c - 48) 0\n\nparseInts = fmap parseInt . words\n\nmain = do\n n <- fmap parseInt getLine\n a:as <- fmap parseInts getLine\n let s = sum as + a\n pid = (a, 1) : filter (\\(x, _) -> 2 * x <= a) (zip as [2 ..])\n p = fmap snd pid\n v = sum (fmap fst pid)\n if 2 * v > s\n then do\n print (length pid)\n putStrLn (unwords (fmap show p))\n else print 0\n", "src_uid": "0a71fdaaf08c18396324ad762b7379d7"} {"source_code": "-- 40B\n\nsolve :: [Int] -> Int\nsolve [n, m, x] = solve' (n - 2 * (x - 1)) (m - 2 * (x - 1))\n where\n solve' 1 1 = 1\n solve' n m\n | n > 0 && m > 0 = m + n - 2\n | otherwise = 0\n\nmain :: IO ()\nmain = fmap (map read . words) getContents >>= print . solve", "src_uid": "fa1ef5f9bceeb7266cc597ba8f2161cb"} {"source_code": "import Data.Map (Map)\nimport qualified Data.Map as M\nimport Control.Applicative\n\nmain = getLine >> do\n cs <- reverse.words <$> getLine\n if solve cs\n then putStrLn \"YES\"\n else putStrLn \"NO\"\n\ntype Card = String\n\n[x,y]===[z,w] = x==z || y==w\n\nsolve cards = evalState (dp cards) $ M.empty\n where\n dp :: [Card] -> State (Map [Card] Bool) Bool\n dp [_] = return True\n dp [c0,c1] = return $ c0===c1\n dp [c0,c1,c2] = return $ c0===c1 && c0===c2\n dp cs@(c0:c1:c2:c3:rest) = do\n memo <- get\n case M.lookup cs memo of\n Just ans -> return ans\n Nothing\n | c0===c1 && c0===c3 -> do\n ans1 <- dp $ c0:c2:c3:rest\n ans3 <- dp $ c1:c2:c0:rest\n let ans = ans1 || ans3\n modify (M.insert cs ans)\n return ans\n | c0===c1 -> do\n ans1 <- dp $ c0:c2:c3:rest\n modify (M.insert cs ans1)\n return ans1\n | c0===c3 -> do\n ans3 <- dp $ c1:c2:c0:rest\n modify (M.insert cs ans3)\n return ans3\n | otherwise -> return False\n\n-- State Monad\nnewtype State s a = State {runState :: s -> (a,s)}\n\ninstance Monad (State s) where\n return a = State $ \\s -> (a,s)\n m >>= k = State $ \\s ->\n let (a,s') = runState m s\n in runState (k a) s'\n\nget :: State s s\nget = State $ \\s -> (s,s)\nput :: s -> State s ()\nput s = State $ \\_ -> ((),s)\n\nmodify :: (s -> s) -> State s ()\nmodify f = get >>= put.f\n\nevalState :: State s a -> s -> a\nevalState = (fst.).runState\nexecState :: State s a -> s -> s\nexecState = (snd.).runState", "src_uid": "1805771e194d323edacf2526a1eb6768"} {"source_code": "solve :: Integer -> Integer -> String\nsolve a b = case compare a b of\n LT -> solve' a b\n EQ -> \"Equal\"\n GT -> alt (solve' b a)\n where alt \"Masha\" = \"Dasha\"\n alt \"Dasha\" = \"Masha\"\n alt \"Equal\" = \"Equal\"\nsolve' a b = case compare a' b' of\n LT -> \"Masha\"\n EQ -> \"Equal\"\n GT -> \"Dasha\"\n where g = lcm a b\n a' = div g a - 1\n b' = div g b\nmain = putStrLn . (\\[a,b] -> solve (read a) (read b)) . words =<< getLine", "src_uid": "06eb66df61ff5d61d678bbb3bb6553cc"} {"source_code": "import Prelude\nimport Control.Monad\nimport Data.List\nimport qualified Data.Map as M\nimport qualified Data.Array as A\nimport Data.Functor\nimport Data.Maybe\n\n\nother a xs = fromMaybe 0 (lookup a xs)\n\nmain :: IO ()\nmain = do\n getLine\n str <- fmap (map (\\xs -> (head xs, length xs)) . group . sort) getLine\n let r = other 'R' str\n g = other 'G' str\n b = other 'B' str\n ans3 = ((r >= 1 && g >= 1 && b >= 1) || (r >= 2 && g >= 2) || (r >= 2 && b >= 2) || (g >= 2 && b>= 2))\n ansB = (g == 0 && r == 0) || (b == 0 && r == 1 && g == 1)\n ansG = (r == 0 && b == 0) || (g == 0 && r == 1 && b == 1)\n ansR = (g == 0 && b == 0) || (r == 0 && b == 1 && g == 1)\n ansBG = r >= 2 && (b > 0 || g > 0)\n ansBR = g >= 2 && (b > 0 || g > 0)\n ansGR = b >= 2 && (g > 0 || r > 0)\n sol = if ans3 then \"BGR\" else if ansB then \"B\" else if ansG then \"G\" else if ansR then \"R\" else if ansBG then \"BG\" else if ansBR then \"BR\" else if ansGR then \"GR\" else \"\"\n putStrLn sol\n return ()\n", "src_uid": "4cedd3b70d793bc8ed4a93fc5a827f8f"} {"source_code": "import Control.Applicative\nimport Control.Monad\nimport Data.List\nimport Data.Maybe\n\n\nmain = do\n\t\t[b,s,m]<- map read <$> words <$> getLine::IO [Int]\n\t\tbb<- minimum <$> map read <$> words <$> getLine::IO Int\n\t\taa<- maximum <$> map read <$> words <$> getLine::IO Int\n\t\tprint $ if bb>=aa then m else (div m bb)*aa +mod m bb\n", "src_uid": "42f25d492bddc12d3d89d39315d63cb9"} {"source_code": "import System.IO\n\nmain :: IO ()\nmain = interact (show . (uncurry compute) . get_two_ints . words)\n\nget_two_ints :: [String] -> (Int, Int)\nget_two_ints (x:y:_) = (read x :: Int, read y :: Int)\nget_two_ints _ = undefined\n\ncompute :: Int -> Int -> Integer\ncompute n k = \n let m = fromIntegral (n-k) :: Integer\n k' = fromIntegral k :: Integer\n in mod (k'^(k'-1) * m^m) (10^9+7)", "src_uid": "cc838bc14408f14f984a349fea9e9694"} {"source_code": "import qualified Data.Map.Strict as Map\n\ntoint s = (read s) :: Int\n\nagregar x m = Map.insertWith (+) x 1 m\nquitar :: Integer -> (Map.Map Integer Integer) -> (Map.Map Integer Integer)\nquitar x m = Map.insertWith (+) x (-1) m\n\nasdasd [] = Map.fromList []\nasdasd (x:xs) = agregar x (asdasd xs)\n\ncan n [] k = n <= 0\ncan n (x:xs) k =\n can (n-(div x k)) xs k\n\ndoit n w k =\n if k == 0 || can n w k then\n k\n else\n doit n w (k-1)\n\nsolve::String -> String\nsolve ss =\n let (n:m:s) = Prelude.map toint $ words ss in\n let w = map snd $ Map.toList $ asdasd s in\n let r = doit n w 200 in\n show r ++ \"\\n\"\n\nmain = interact solve", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe"} {"source_code": "import Control.Applicative\nimport Data.Char\n\n \n\n \n\n\nmain= do\n\tr<- getLine \n\tlet s = map (\\z-> (ord z)- (ord '0')) r\n\tlet s1 = (s!!0)*10000 + (s!!2) *1000 +(s!!4) *100 +(s!!3) *10 +s!!1\n\tlet s2= show ((fromIntegral s1)^5) \n\tlet s3= length s2\n\tputStrLn $ drop (s3-5) s2\n\t \n\t \n\n\t", "src_uid": "51b1c216948663fff721c28d131bf18f"} {"source_code": "import Control.Applicative\nimport Control.Monad\nimport Data.List\nimport Data.Time\n\ntype Case = Int\n\n\nparse (a:b:c:d:_:e:f:_:g:h:[]) = fromGregorian (read (a:b:c:d:[])) (read (e:f:[])) (read (g:h:[]))\n \nmain = do\n f <- getLine\n t <- getLine\n let a = parse f -- fromGregorian 1900 01 01\n let b = parse t -- fromGregorian 2038 12 31\n print $ abs (diffDays a b)\n", "src_uid": "bdf99d78dc291758fa09ec133fff1e9c"} {"source_code": "module Main where\nimport Control.Monad\n\nnz x = round $ (log $ fromIntegral x) / log 10.0\nbn nz = foldr (\\_ acc -> (\\x y -> x*10+y ) <$> acc <*> [0,1]) [1] [0..nz-1]\nton n = let z = nz n in (sum $ map ( length . bn) [0..z-1]) + (length $ filter (<=n) $ bn z ) \n\nmain = (readLn :: IO Int) >>= print . ton\n", "src_uid": "64a842f9a41f85a83b7d65bfbe21b6cb"} {"source_code": "{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances #-}\n{-# OPTIONS_GHC -O2 #-}\n\nimport Data.List\nimport Data.Maybe\nimport Data.Char\nimport Data.Array.IArray\nimport Data.Array.Unboxed (UArray)\nimport Data.Int\nimport Data.Ratio\nimport Data.Bits\nimport Data.Function\nimport Data.Ord\n--import Control.Monad.State\nimport Control.Monad\nimport Control.Applicative\nimport Data.ByteString.Char8 (ByteString)\nimport qualified Data.ByteString.Char8 as BS\nimport Data.Set (Set)\nimport qualified Data.Set as Set\nimport Data.Map (Map)\nimport qualified Data.Map as Map\nimport Data.IntMap (IntMap)\nimport qualified Data.IntMap as IntMap\nimport Data.Sequence (Seq, (<|), (|>), (><), ViewL(..), ViewR(..))\nimport qualified Data.Sequence as Seq\nimport qualified Data.Foldable as F\nimport Data.Graph\n\nparseInput = do \n (,) <$> readInteger <*> readInteger\n where\n readInt = state $ fromJust . BS.readInt . BS.dropWhile isSpace\n readInteger = state $ fromJust . BS.readInteger . BS.dropWhile isSpace\n readString = state $ BS.span (not . isSpace) . BS.dropWhile isSpace\n readLine = state $ BS.span (not . isEoln) . BS.dropWhile isEoln\n isEoln ch = ch == '\\r' || ch == '\\n'\n\nmain = BS.putStr =<< solve . evalState parseInput <$> BS.getContents\n\nsolve :: (Integer, Integer) -> ByteString\nsolve (a, b) = BS.pack . show $ maximum [ solve2 (a, b) (interval10 n) | n <- [1..10]]\n where\n interval10 i = (10 ^ (i-1), 10 ^ i - 1)\n\nsolve2 :: (Integer, Integer) -> (Integer, Integer) -> Integer\nsolve2 (a, b) (c, d)\n | inRange (lo, hi) target = target * (d - target)\n | otherwise = 0\n where\n lo = a `max` c\n hi = b `min` d\n target = ((d `div` 2) `min` hi) `max` lo\n \n\n----------------------------------------------------------------------\n----------------------------------------------------------------------\n----------------------------------------------------------------------\n\nclass (Monad m) => MonadState s m | m -> s where\n\tget :: m s\n\tput :: s -> m ()\n\nmodify :: (MonadState s m) => (s -> s) -> m ()\nmodify f = do\n\ts <- get\n\tput (f s)\n\ngets :: (MonadState s m) => (s -> a) -> m a\ngets f = do\n\ts <- get\n\treturn (f s)\n\nnewtype State s a = State { runState :: s -> (a, s) }\n\ninstance Functor (State s) where\n\tfmap f m = State $ \\s -> let\n\t\t(a, s') = runState m s\n\t\tin (f a, s')\n\ninstance Applicative (State s) where\n pure = return\n (<*>) = ap\n\ninstance Monad (State s) where\n\treturn a = State $ \\s -> (a, s)\n\tm >>= k = State $ \\s -> let\n\t\t(a, s') = runState m s\n\t\tin runState (k a) s'\n\ninstance MonadState s (State s) where\n\tget = State $ \\s -> (s, s)\n\tput s = State $ \\_ -> ((), s)\n\nevalState :: State s a -> s -> a\nevalState m s = fst (runState m s)\n\nexecState :: State s a -> s -> s\nexecState m s = snd (runState m s)\n\nmapState :: ((a, s) -> (b, s)) -> State s a -> State s b\nmapState f m = State $ f . runState m\n\nwithState :: (s -> s) -> State s a -> State s a\nwithState f m = State $ runState m . f\n\nstate = State\n", "src_uid": "2c4b2a162563242cb2f43f6209b59d5e"} {"source_code": "{-# OPTIONS_GHC -O2 #-}\n{-# LANGUAGE BangPatterns #-}\nimport Control.Applicative\nimport Control.Monad\nimport Control.Monad.ST\nimport Data.Array.Base\nimport Data.Bits\nimport Data.Int\nimport Data.List\nimport GHC.Arr (Ix)\n\nrep :: Monad m => Int -> (Int -> m ()) -> m ()\nrep !n f=go 0 where go !i=when(i>go(i+1)\n{-# INLINE rep #-}\n\nunsafeModify :: (MArray a e m, Ix i) => a i e -> Int -> (e -> e) -> m ()\nunsafeModify a i f=unsafeRead a i>>=unsafeWrite a i.f\n{-# INLINE unsafeModify #-}\n\nimplies :: Bool -> Bool -> Bool\np `implies` q = not p || q\n{-# INLINE implies #-}\ninfixr 1 `implies`\n\nmain = do\n [cs, m] <- words <$> getLine\n let len = length cs\n print $ solve (read m) len $ listArray (0,len-1) [read[c]|c<-sort cs]\n\nsolve :: Int -> Int -> UArray Int Int -> Int64\nsolve m len arr = runST $ do\n\n dp <- newArray ((0,0), (2^len-1,m-1)) 0 :: ST s (STUArray s (Int,Int) Int64)\n\n writeArray dp (0,0) 1\n\n rep (2^len) $ \\used -> do\n rep m $ \\r -> do\n a <- unsafeRead dp $ used * m + r\n when (a /= 0) $ do\n rep len $ \\i -> do\n let !digit = unsafeAt arr i\n unless (testBit used i || used == 0 && digit == 0) $ do\n when (i > 0 && digit == unsafeAt arr(i-1) `implies` testBit used (i-1)) $ do\n unsafeModify dp (setBit used i * m + rem (10 * r + digit) m) (a+)\n\n readArray dp (2^len-1,0)\n", "src_uid": "5eb90c23ffa3794fdddc5670c0373829"} {"source_code": "{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}\n{-# LANGUAGE BangPatterns, TupleSections, OverloadedStrings #-}\nimport Control.Applicative\nimport Control.Exception hiding (mask)\nimport Control.Monad\nimport Control.Monad.ST\nimport Data.Array.Base\nimport Data.Array.ST (runSTUArray, runSTArray)\nimport Data.Bits\nimport qualified Data.ByteString.Char8 as B\nimport Data.Char\nimport Data.Function\nimport Data.Int\nimport Data.List\nimport qualified Data.Map as M\nimport qualified Data.IntMap as IM\nimport qualified Data.Set as S\nimport qualified Data.IntSet as IS\nimport Data.STRef\nimport GHC.Arr (Array, STArray, Ix(..))\nimport Debug.Trace\n\nbool :: a -> a -> Bool -> a\nbool t f b=if b then t else f\nreadInt :: B.ByteString -> Int\nreadInt bs=case B.readInt bs of{Just(n,_)->n;_->error$\"readInt error : bs = \"++show bs;}\nrep, rev :: Monad m => Int -> (Int -> m ()) -> m ()\nrep !n f=go 0 where go !i=when(i>go(i+1)\nrev !n f=go(n-1)where go !i=when(i>=0)$f i>>go(i-1)\n{-# INLINE rep #-}\n{-# INLINE rev #-}\nfor :: Monad m => Int -> (Int -> Bool) -> (Int -> Int) -> (Int -> m ()) -> m ()\nfor !i0 p next f=go i0 where go !i=when(p i)$f i>>go(next i)\n{-# INLINE for #-} \nmodifyArray :: (MArray a e m, Ix i) => a i e -> i -> (e -> e) -> m ()\nmodifyArray a i f=readArray a i>>=writeArray a i.f\n{-# INLINE modifyArray #-}\nunsafeModify :: (MArray a e m, Ix i) => a i e -> Int -> (e -> e) -> m ()\nunsafeModify a i f=unsafeRead a i>>=unsafeWrite a i.f\n{-# INLINE unsafeModify #-}\n\nupperBound :: (Integral i) => (i -> Bool) -> i -> i -> i\nupperBound p low high = go low high\n where\n go !low !high\n | high <= low = low\n | p mid = go mid high\n | otherwise = go low (mid - 1)\n where\n mid = (low + high + 1) `quot` 2\n{-# INLINE upperBound #-}\n\nmodulus :: Int\nmodulus = 1000000007\n\ninfixl 6 +%\n\n(+%) :: Int -> Int -> Int\nx +% y = case x + y of xy -> if xy < modulus then xy else xy - modulus\n{-# INLINE (+%) #-}\n\nmain :: IO ()\nmain = interact $ show.solve.sort.map read.words\n\nsolve :: [Int] -> Int\nsolve [r,g] = foldl1' (+%) $ map (unsafeAt arr) [0..r]\n where\n !n = r + g\n !hMax = upperBound (\\i->i*(i+1)`div`2<=n) 0 1000\n !arr = runSTUArray $ do\n buf <- newArray (0,r) 0 :: ST s (STUArray s Int Int)\n buf' <- newArray (0,r) 0 :: ST s (STUArray s Int Int)\n\n let go !h !total dp next\n | h < hMax = do\n rep (h+1) $ \\r' -> do\n if total - r'+ (h+1) <= g\n then unsafeRead dp r' >>= unsafeWrite next r'\n else unsafeWrite next r' 0\n for (h+1) (<=r) (1+) $ \\r' -> do\n if total - r'+(h+1) <= g\n then do\n (+%) <$> unsafeRead dp (r'-(h+1)) <*> unsafeRead dp r' >>= unsafeWrite next r'\n else unsafeRead dp (r'-(h+1)) >>= unsafeWrite next r'\n go (h+1) (total+h+1) next dp\n | otherwise = return dp\n\n unsafeWrite buf 0 1\n go 0 0 buf buf'\n", "src_uid": "34b6286350e3531c1fbda6b0c184addc"} {"source_code": "mm :: Integer\nmm = 10 ^ 9 + 7\n\naddMod :: Integer -> Integer -> Integer\naddMod a b\n | a + b < mm = a + b\n | otherwise = a + b - mm\n \nscanl' :: (b -> a -> b) -> b -> [a] -> [b]\nscanl' _ q [] = seq q [q]\nscanl' f q (x : xs) = seq q (q : scanl' f (f q x) xs)\n\nsolve :: Int -> Integer\nsolve n = let dynamic mem = scanl' addMod (last mem) mem\n in (!! pred n) . (!! n) . iterate dynamic $ [1]\n\nmain :: IO ()\nmain = do\n print . solve . read =<< getLine\n\n", "src_uid": "aa2c3e94a44053a0d86f61da06681023"} {"source_code": "import Data.List\n\nf :: Int->String\nf n\n |n<0=\"NO\"\n |n `mod` 7==0=\"YES\"\n |otherwise=f (n-3)\n\nmain = do\n a<-getLine\n b<-getLine\n let xs=map read (words b)::[Int]\n ys=sort $ nub xs\n print $ (length ys)-(if (head ys)==0 then 1 else 0)", "src_uid": "3b520c15ea9a11b16129da30dcfb5161"} {"source_code": "import Data.List\nimport Data.Tree \nimport Data.Int\nimport Data.Maybe\nimport Data.Char\nimport Data.Functor\nimport Data.Bits\nimport Data.Monoid\nimport Control.Monad\nimport Control.Monad.ST.Safe\nimport Control.Arrow\nimport Data.Array\nimport Data.Array.ST.Safe\nimport Data.Array.Unboxed as UA\nimport Data.STRef\nimport qualified Data.Map as Map\nimport qualified Data.Set as Set\nimport qualified Data.ByteString.Char8 as C\nmain= readsolveprint \nreadsolveprint::IO()\nreadsolveprint = (solve.concat =<< forM [1.. 1] ( \\i -> map (fst.fromJust.C.readInteger).C.words<$>C.getLine))\nsolve [x] = print $ slv1 x\nslv1 0 = 1\nslv1 x = let y = x `mod` 4 in if y == 0 then 6 else if y == 1 then 8 else if y == 2 then 4 else 2", "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f"} {"source_code": "main = interact (show . solve . concat . lines)\nsolve \"1 of week\" = 52\nsolve \"2 of week\" = 52\nsolve \"3 of week\" = 52\nsolve \"4 of week\" = 52\nsolve \"5 of week\" = 53\nsolve \"6 of week\" = 53\nsolve \"7 of week\" = 52\nsolve \"1 of month\" = 12\nsolve \"2 of month\" = 12\nsolve \"3 of month\" = 12\nsolve \"4 of month\" = 12\nsolve \"5 of month\" = 12\nsolve \"6 of month\" = 12\nsolve \"7 of month\" = 12\nsolve \"8 of month\" = 12\nsolve \"9 of month\" = 12\nsolve \"10 of month\" = 12\nsolve \"11 of month\" = 12\nsolve \"12 of month\" = 12\nsolve \"13 of month\" = 12\nsolve \"14 of month\" = 12\nsolve \"15 of month\" = 12\nsolve \"16 of month\" = 12\nsolve \"17 of month\" = 12\nsolve \"18 of month\" = 12\nsolve \"19 of month\" = 12\nsolve \"20 of month\" = 12\nsolve \"21 of month\" = 12\nsolve \"22 of month\" = 12\nsolve \"23 of month\" = 12\nsolve \"24 of month\" = 12\nsolve \"25 of month\" = 12\nsolve \"26 of month\" = 12\nsolve \"27 of month\" = 12\nsolve \"28 of month\" = 12\nsolve \"29 of month\" = 12\nsolve \"30 of month\" = 11\nsolve \"31 of month\" = 7\n", "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b"} {"source_code": "main :: IO()\nmain =\n do [n, k] <- map read.words <$> getLine\n putStrLn.show $ iterate f n !! k\n\nf :: Int -> Int\nf x | x `mod` 10 == 0 = x `div` 10\n | otherwise = x - 1\n", "src_uid": "064162604284ce252b88050b4174ba55"} {"source_code": "import Data.Bits\nimport Data.Word\n\ninfixl 6 +.\ninfixl 7 *.\ninfixr 8 ^.\n\nm = 10^9 + 7 :: Word64\n\na +. b = (a + b) `mod` m\na *. b = a * b `mod` m\na ^. b = a ^ b `mod` m\n\ndependency (a, b) = (a ^. 2, (a + 1) *. b)\n\ng 0 x _ = x\n\ng n x ((a, b):rest) = g n' x' rest\n where\n n' = n `unsafeShiftR` 1\n x' =\n if n `testBit` 0\n then a *. x +. b\n else x\n\nsolve [a1, b1, n, x] = g n x $ iterate dependency (a1, b1)\n\nmain = interact $ unlines . map (show . solve . map read . words) . lines\n", "src_uid": "e22a1fc38c8b2a4cc30ce3b9f893028e"} {"source_code": "module Main where\nispalindrome x = x == reverse x\n--minsame x = minimum $ map (\\xs -> length $ takeWhile (==head xs) xs) [x, reverse x ] \nmain = getLine >>= \\x -> print $ (length x) - if not $ ispalindrome x then 0 else if all (==head x) x then length x else 1\n", "src_uid": "6c85175d334f811617e7030e0403f706"} {"source_code": "import Control.Applicative\nimport Data.List\n\nmyShow :: [(Int, Int)] -> IO ()\nmyShow [] = return ()\nmyShow (x:xs) = do \n putStrLn $ show (fst x) ++ \" \" ++ show (snd x)\n myShow xs\n\nmain :: IO ()\nmain = do\n n <- read <$> getLine\n onlyCards <- map (read :: String -> Int) . words <$> getLine \n let sortedCards = sort $ zip onlyCards [1..]\n firstH = take (n `div` 2) sortedCards\n secondH = reverse $ drop (n `div` 2) sortedCards\n res = map (\\x -> (snd . fst $ x, snd . snd $ x)) $ zip firstH secondH\n myShow res\n", "src_uid": "6e5011801ceff9d76e33e0908b695132"} {"source_code": "{-# LANGUAGE ScopedTypeVariables #-}\n{-# LANGUAGE TypeFamilies #-}\n{-# LANGUAGE ViewPatterns #-}\n{-# LANGUAGE BangPatterns #-}\n\nimport Control.Applicative\nimport Control.Arrow\nimport Control.Monad\nimport Data.Array.IO\nimport Data.Array.Unboxed\nimport qualified Data.ByteString.Char8 as C\nimport Data.Char\nimport qualified Data.Foldable as F\nimport Data.Function\nimport Data.Functor\nimport Data.Int\nimport qualified Data.IntMap as M\nimport Data.IORef\nimport Data.List\nimport Data.Maybe\nimport Data.Monoid\nimport qualified Data.Sequence as Seq\nimport qualified Data.Set as S\nimport Data.Word\nimport Debug.Trace\nimport Text.Printf\n\n-- I/O\n\nreadInts :: C.ByteString -> [Int]\nreadInts = map fst . mapMaybe C.readInt . C.words\n\ngetInts :: IO [Int]\ngetInts = readInts <$> C.getLine\n\nreadNums :: Num a => C.ByteString -> [a]\nreadNums = map (fromIntegral . fst) . mapMaybe C.readInteger . C.words\n\ngetNums :: Num a => IO [a]\ngetNums = readNums <$> C.getLine\n\ncast :: (Integral a, Integral b) => a -> b\ncast = fromIntegral\n\n-----\n\nmain :: IO ()\nmain = do\n s <- getLine\n t <- getLine\n putStrLn $ f s t\n\nf s t\n | substr s t = \"automaton\"\n | sort s == sort t = \"array\"\n | substr (sort s) (sort t) = \"both\"\n | otherwise = \"need tree\"\n\nsubstr _ [] = True\nsubstr (x:xs) (y:ys)\n | x == y = substr xs ys\n | otherwise = substr xs (y:ys)\nsubstr _ _ = False\n", "src_uid": "edb9d51e009a59a340d7d589bb335c14"} {"source_code": "import Data.List\nt=transpose\nm=minimum\nd l=maximum l-m l\nmain=interact$show.m.map(d.map(foldl(\\r x->r*10+fromEnum x-48)0).t).permutations.t.tail.lines", "src_uid": "08f85cd4ffbd135f0b630235209273a4"} {"source_code": "{-# LANGUAGE MultiWayIf #-}\n{-# LANGUAGE OverloadedStrings #-}\n\nimport Data.List\nimport Data.Array.ST\nimport Control.Monad.ST\nimport Data.Array.Unboxed (UArray,(//))\nimport Control.Monad\nimport Data.Array (array)\nimport Data.Array.IArray ((!))\n\nimport qualified Data.ByteString.Char8 as BS\nimport Data.ByteString (ByteString)\nimport Data.Char\n\nreadInt :: IO Int\nreadInt = do line <- BS.getLine\n let Just (n,_) = BS.readInt line\n return n\n\nparseInts :: Int -> ByteString -> [Int]\nparseInts k bs | k <= 0 = []\nparseInts k bs = case BS.readInt (BS.dropWhile isSpace bs) of\n Nothing -> []\n Just (n,bs') -> n : parseInts (k-1) bs'\n\ntype Foo s = ST s (STUArray s Int Int)\n\ncountDigits :: ByteString -> UArray Int Int\ncountDigits bs = runSTUArray $ do\n arr <- newArray (0,9) 0 :: Foo s\n let len = BS.length bs\n let go i | i >= len = return ()\n go i = do let ch = BS.index bs i\n when (ch >= '0' && ch <= '9') $ do\n let c = digitToInt ch\n v <- readArray arr c\n writeArray arr c (v+1)\n go (i+1)\n go 0\n return arr\n\ncommon carr d = min (carr!d) (carr!(9-d))\nextras carr d = (carr!d) - common carr d\n\nremove carr a = let c = carr!a in carr // [ (a,c-1) ] \n\ntest :: ByteString -> IO ()\ntest bs = do\n let (n1,n2) = solve bs\n putStr \"n1: \"\n BS.putStrLn $ showNumber n1\n putStr \"n2: \"\n BS.putStrLn $ showNumber n2\n\nsolve :: ByteString -> ( [(Int,Int)], [(Int,Int)] )\nsolve bs = do\n case best of\n Nothing -> let first = [ (d,counts!d) | d <- [9,8..0], counts!d > 0 ] in (first,first)\n Just a ->\n let b = 10-a\n c1 = remove counts a\n c2 = remove counts b\n comm d = min (c1!d) (c2!(9-d))\n\n z1 = c1!0 - comm 0\n z2 = c2!0 - comm 9\n z = min z1 z2\n\n mid1 = [ (d,x) | d <- [0..9], let x = comm d, x > 0 ]\n mid2 = [ (d,x) | d <- [9,8..0], let x = comm (9-d), x > 0 ]\n\n lead1 = [ (d,x) | d <- [1..9], let x = c1!d - comm d, x > 0 ] ++ [(0,z1-z)]\n lead2 = [ (d,x) | d <- [1..9], let x = c2!d - comm (9-d), x > 0 ] ++ [(0,z2-z)]\n\n first = lead1 ++ mid1 ++ [(a,1)] ++ [(0,z)]\n second = lead2 ++ mid2 ++ [(b,1)] ++ [(0,z)]\n in (first,second)\n where\n counts = countDigits bs\n cost :: Int -> Int -> Int\n cost a b | counts!a == 0 = 100\n | counts!b == 0 = 100\n | extras counts a == 0 = if extras counts b == 0 then 2 else 1\n | extras counts b == 0 = 1\n | otherwise = 0\n cost5 = if | counts!5 == 0 -> 100\n | extras counts 5 >= 1 -> 0\n | otherwise -> 1\n tens = sort $ [ (cost d (10-d),d) | d <- [1..4] ] ++ [ (cost5,5) ]\n best = let (c,d) = head tens in if c > 2 then Nothing else Just d\n\nshowNumber :: [(Int,Int)] -> ByteString\nshowNumber ns = BS.concat $ map (\\(d,c) -> BS.replicate c (intToDigit d)) ns\n\nmain = do\n bs <- BS.getLine\n let (n1,n2) = solve bs\n BS.putStrLn $ showNumber n1\n BS.putStrLn $ showNumber n2\n\n", "src_uid": "34b67958a37865e1ca0529bbf528dd9a"} {"source_code": "main :: IO ()\nmain = interact $ show . solve . map read . words\n\nsolve :: [Integer] -> Integer\nsolve [x, y, m] = f 0 (min x y) (max x y)\n where\n f s x y\n | y >= m = s\n | y <= 0 = -1\n | x >= 0 = seq s1 $ seq xy $ f s1 y xy\n | otherwise = seq ss $ seq xx $ seq yy $ f ss xx yy\n where\n s1 = s + 1\n xy = x + y\n d = -(x `div` y)\n ss = s + d\n xx = min (x + d * y) y\n yy = max (x + d * y) y\n", "src_uid": "82026a3c3d9a6bda2e2ac6e14979d821"} {"source_code": "import Control.Monad\r\nimport Data.List\r\nmain = do\r\n t <- readLn :: IO Int\r\n tcs <- replicateM t (readLn :: IO Int)\r\n mapM (putStrLn . solve) tcs\r\nsolve s = concatMap show digs\r\n where\r\n (0, digs) = foldl' next (s,[]) . reverse $ [1..9]\r\nnext (s,digs) d | (d > s) = (s,digs)\r\n | otherwise = (s - d, d:digs)\r\n", "src_uid": "fe126aaa93acaca8c8559bc9e7e27b9f"} {"source_code": "{-# LANGUAGE OverloadedStrings #-}\nimport qualified Data.ByteString.Char8 as S\nimport Data.Maybe\nimport Control.Monad\nimport Control.Applicative\nimport Data.List\nimport Data.Int\nimport Data.Char\nimport Data.Bits\nimport Data.Bool\nimport Data.Ratio\n\nsolve x h m\n | m < 0 = solve x (h - 1) (m + 60)\n | h < 0 = solve x (h + 24) m\n | elem '7' (show $ h * 100 + m) = 0\n | otherwise = 1 + solve x h (m - x)\n\nmain = do\n x <- readLn::IO Int\n [h,m] <- (map $ fst . fromJust . S.readInt) . S.words <$> S.getLine\n print $ solve x h m\n", "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb"} {"source_code": "-- import Debug.Trace\n\nmain :: IO ()\nmain = getLine >>= return . (read :: String -> Int) >>= return . (calc 1 0) >>= print\n\ncalc :: Int -> Int -> Int -> Int\ncalc idx cnt req\n | idx == req+1 = cnt\n | otherwise = calc (idx+1) (dfs idx 1 0 (m `div` 2) + cnt) req\n where\n m = last $ takeWhile (idx >= ) $ map (2^) [0, 1..]\n\ndfs c b a m\n | m == 0 = -- trace (show [c, b, a, m]) $\n if c > b && a + b > c && c + b > a then 1 else 0\n | otherwise = -- trace (show [c, b, a, m]) $\n case curBit of\n 0 -> dfs c (b*2+1) (a*2+1) (m `div` 2) + dfs c (b*2) (a*2) (m `div` 2)\n 1 -> dfs c (b*2+1) (a*2) (m `div` 2) + dfs c (b*2) (a*2+1) (m `div` 2)\n where\n curBit = c `div` m `mod` 2\n", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d"} {"source_code": "import Data.List (sort)\n\nprocess :: [Int] -> [Int]\nprocess = sort\n\nreadInt :: String -> Int\nreadInt = read\n\nmain = do\n n <- fmap readInt getLine\n xs <- fmap (map readInt.words) getLine\n putStrLn.unwords.map show $ process xs", "src_uid": "ae20712265d4adf293e75d016b4b82d8"} {"source_code": "import Data.Array\nmain = interact $ show . solve . map read . words\nsolve [n,k] = foldl1 (+!) $ iterate f (listArray (1,n) (1 : repeat 0)) !! k where\n f a = accumArray (+!) 0 (1,n) $ concatMap (\\(b,i) -> map (flip (,) i) [b,2*b..n]) $ assocs a\na +! b = (a + b) `mod` (10^9+7)\n", "src_uid": "c8cbd155d9f20563d37537ef68dde5aa"} {"source_code": "import Data.Array\n\n\ndigits :: Integer -> [Int]\ndigits 0 = []\ndigits x = [fromIntegral (x `mod` 10)] ++ digits(x `div` 10)\n\n\nmylcm :: Int -> Int -> Int\nmylcm x 0 = x\nmylcm x y = lcm x y\n\n\nlcms :: Array Int Int\nlcms = listArray (0, 47) [2^c2 * 3^c3 * 5^c5 * 7^c7 |\n c2 <- [0..3],\n c3 <- [0..2],\n c5 <- [0..1],\n c7 <- [0..1]]\n\n\nlcm_index :: Array Int Int\nlcm_index = array (1, 2520)\n [(e, i) | (i, e) <- assocs lcms]\n\n\nmemoized_count :: Array (Int, Int, Int) Integer\nmemoized_count = listArray ((0, 0, 0), (18, 47, 503))\n [f pos l r | pos <- [0..18], l <- [0..47], r <- [0..503]]\n where f pos l r = \n sum [ count (pos-1) nl nr\n | d <- [0..9],\n let nl = lcm_index ! mylcm (lcms ! l) d,\n let nr = (r*10 + d) `mod` (if pos == 0 then 2520 else 504)\n ]\n\n\ncount :: Int -> Int -> Int -> Integer\ncount (-1) l r = (if r `mod` (lcms ! l) == 0 then 1 else 0)\ncount pos l r = memoized_count ! (pos, l, r)\n\n\ncount_s :: [Int] -> Int -> Int -> Int -> Integer\ncount_s num (-1) l r = (if r `mod` (lcms ! l) == 0 then 1 else 0)\ncount_s num pos l r = \n sum [ fun (pos-1) nl nr\n | d <- [0..num!!pos],\n let nl = lcm_index ! mylcm (lcms ! l) d,\n let nr = (r*10 + d) `mod` (if pos == 0 then 2520 else 504),\n let fun = if d == num!!pos then count_s num else count\n ]\n\n\nsolve 0 = do\n return ()\nsolve x = do\n line <- getLine\n let [l, r] = map read $ words line :: [Integer]\n\n let sr = digits(r)\n let sl = digits(l-1)\n let ansr = count_s sr ((length sr)-1) 0 0\n let ansl = count_s sl ((length sl)-1) 0 0\n print(ansr - ansl)\n \n solve(x-1)\n\n\nmain = do\n line <- getLine\n let tests = read line :: Int\n solve(tests)\n", "src_uid": "37feadce373f728ba2a560b198ca4bc9"} {"source_code": "\nmodule Main where\n\nimport Data.List ( sort )\n\nreadChar :: Char -> Int\nreadChar c = read [c]\n\ntoInts :: [Char] -> [Int]\ntoInts = map readChar\n\nallGoodTickets :: [[Int]]\nallGoodTickets = filter isSolution [[x1,x2,x3,x4,x5,x6] | x1 <- [0..9], x2 <- [0..9], x3 <- [0..9], x4 <- [0..9], x5 <- [0..9], x6 <- [0..9]]\n\ndiff :: [Int] -> [Int] -> Int\ndiff a b = sum $ zipWith f a b\n where f a b | a == b = 0\n | otherwise = 1\n\nisSolution :: [Int] -> Bool\nisSolution xs = (sum $ take m xs) == (sum $ drop m xs)\n where m = (length xs) `div` 2\n\nmain = do\n xs' <- getLine\n let xs = toInts xs'\n let res = minimum . map (diff xs) $ allGoodTickets\n print res\n", "src_uid": "09601fd1742ffdc9f822950f1d3e8494"} {"source_code": "-- @betaveros :: vim:set fdm=marker:\n{-# LANGUAGE LambdaCase, NPlusKPatterns, TupleSections #-}\n{-# OPTIONS_GHC -fno-warn-unused-imports -fno-warn-missing-signatures #-}\n-- import ALL the things! {{{\n-- hiding clauses are to allow Data.Foldable's generalizations\nimport Prelude hiding (mapM, mapM_, sequence, sequence_, foldl, foldl1, foldr, foldr1, and, or, any, all, sum, product, concat, concatMap, maximum, minimum, elem, notElem)\nimport Control.Applicative\nimport Control.Arrow\nimport Control.Exception\nimport Control.Monad hiding (mapM, mapM_, forM, forM_, sequence, sequence_, msum)\nimport Control.Monad.ST\n\nimport qualified Data.ByteString.Char8 as BS\nimport Data.ByteString.Char8 (ByteString)\nimport Data.Bits\nimport Data.Char\nimport Data.Either\nimport Data.Foldable\nimport Data.Function\nimport Data.IORef\nimport Data.List hiding (foldl, foldl', foldl1, foldl1', foldr, foldr1, concat, concatMap, and, or, any, all, sum, product, maximum, minimum, elem, notElem, find)\nimport Data.Maybe\nimport Data.Monoid\nimport Data.Ord\nimport Data.STRef\nimport Data.String\nimport Data.Traversable\nimport Data.Tuple\n\nimport qualified Data.Map as Map\nimport Data.Map (Map)\nimport qualified Data.Set as Set\nimport Data.Set (Set)\nimport qualified Data.Sequence as Seq\nimport Data.Sequence (Seq, (<|), (|>), (><))\n\nimport Debug.Trace\nimport Text.Printf\nimport System.IO\n-- }}}\n-- silly utilities {{{\n-- stolen from lens:\na & f = f a\na <&> f = fmap f a\ninfixl 1 &, <&>\n\nfi :: (Integral a, Num b) => a -> b\nfi = fromIntegral\nglength :: (Num b) => [a] -> b\nglength = genericLength\n\nreadInt = read :: String -> Int\nreadInteger = read :: String -> Integer\n-- (!?) :: (Ord k) => Map k v -> k -> Maybe v\n-- (!?) = flip Map.lookup\nhistogram :: (Ord a, Num b) => [a] -> Map a b\nhistogram = Map.fromListWith (+) . map (,1)\n-- }}}\n-- input and output {{{\nbsGetLine :: IO ByteString\nbsGetLine = fst . BS.spanEnd isSpace <$> BS.getLine\n\ninputInt = (read <$> getLine) :: IO Int\ninputInteger = (read <$> getLine) :: IO Integer\ninputDouble = (read <$> getLine) :: IO Double\n\ninputRow :: (Read a) => IO [a]\ninputRow = map read . words <$> getLine\ninputInts = inputRow :: IO [Int]\ninputIntegers = inputRow :: IO [Integer]\ninputDoubles = inputRow :: IO [Double]\n\nssUnwords :: [ShowS] -> ShowS\nssUnwords [] = id\nssUnwords (x:xs) = x . (' ':) . ssUnwords xs\n\nssUnlines :: [ShowS] -> ShowS\nssUnlines [] = id\nssUnlines (x:xs) = x . ('\\n':) . ssUnlines xs\n\nshowMany :: (Show a) => [a] -> String\nshowMany xs = ssUnwords (map shows xs) \"\"\nshowMatrix :: (Show a) => [[a]] -> String\nshowMatrix xs = ssUnlines (map (ssUnwords . map shows) xs) \"\"\n\nprintMany :: (Show a) => [a] -> IO ()\nprintMany xs = putStrLn (showMany xs)\nprintMatrix :: (Show a) => [[a]] -> IO ()\nprintMatrix xs = putStr (showMatrix xs)\n-- }}}\n\nmain :: IO ()\nmain = do\n\t[_,v] <- inputInts\n\ts <- liftA2 (-) sum maximum <$> inputInts\n\tputStrLn $ if s <= v then \"YES\" else \"NO\"\n", "src_uid": "496baae594b32c5ffda35b896ebde629"} {"source_code": "module Main where\n\nimport Control.Monad\nimport Control.Applicative\nimport qualified Data.ByteString.Char8 as B\nimport Data.Array\n\nreadInt = maybe undefined fst . B.readInt\nreadInts = map readInt . B.words\n\nsolve n x = ([[0,1,2],[1,0,2],[1,2,0],[2,1,0],[2,0,1],[0,2,1]]!!(n `mod` 6))!!x\n\nmain = do\n n:x:_ <- replicateM 2 (readInt <$> B.getLine)\n print $ solve n x", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0"} {"source_code": "\nmain = interact solve\n\nsolve input = answer\n where\n n::Int\n n = read input\n\n answer\n | one_or_more (possible n) = \"YES\"\n | otherwise = \"NO\"\n\npossible::Int -> [Int]\npossible n = mapped\n where\n as = [0..(n `div` 1234567)]\n mapped = (map (\\x -> n - (1234567 * x)) as) >>= possible'\n\npossible'::Int -> [Int]\npossible' n = mapped\n where\n as = [0..(n `div` 123456)]\n mapped = (map (\\x -> n - (123456 * x)) as) >>= possible''\n\n\npossible''::Int -> [Int]\npossible'' n = tuple\n where\n answer = n `mod` 1234 == 0\n tuple \n | answer = [n `div` 1234]\n | otherwise = []\n\n\none_or_more [] = False\none_or_more (x:xs) = True\n", "src_uid": "72d7e422a865cc1f85108500bdf2adf2"} {"source_code": "{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -funfolding-use-threshold=16 -fexcess-precision -funbox-strict-fields #-}\nmodule Main where\nimport qualified Data.ByteString.Lazy.Char8 as B\nimport Control.Monad\nimport Control.Monad.Trans.State.Lazy\nimport Data.List\n\nmain = putStr . evalState app . B.words =<< B.getContents\n\napp = do\n n <- poi\n show `fmap` liftM3 solve poi poi (replicateM n poi)\n where\n pop = state $ \\(x:xs) -> (x, xs)\n poi = fmap int pop\n int = maybe undefined fst . B.readInt\n\nsolve k x = (k * x +) . sum . drop k . reverse . sort", "src_uid": "92a233f8d9c73d9f33e4e6116b7d0a96"} {"source_code": "{-# LANGUAGE ScopedTypeVariables #-}\n{-# LANGUAGE BangPatterns #-}\n{-# LANGUAGE Safe #-}\n{-# LANGUAGE TupleSections #-}\n{-# LANGUAGE ExplicitForAll #-}\n{-# LANGUAGE MultiWayIf #-}\n{-# LANGUAGE CPP #-}\n{-# LANGUAGE FlexibleContexts #-}\n{-# LANGUAGE NoMonomorphismRestriction #-}\n\nimport Data.Bits\nimport Data.List\nimport qualified Data.ByteString.Char8 as BS\nimport qualified Data.ByteString.Lazy.Char8 as BSL\nimport Data.IntMap.Strict (IntMap)\nimport qualified Data.IntMap.Strict as IM\nimport Data.IntSet (IntSet)\nimport qualified Data.IntSet as IS\nimport qualified Data.Array.IArray as A\nimport qualified Data.Array.MArray.Safe as A\n-- import qualified Data.Array.MArray as A\nimport Data.Array (Array)\nimport Data.Array.Unboxed (UArray)\nimport Data.Array.IArray (IArray)\nimport Data.Array.MArray.Safe (MArray)\nimport Data.Array.IO.Safe (IOArray, IOUArray)\nimport Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)\n{-\nimport qualified Data.Vector.Unboxed as VU\nimport qualified Data.Vector.Unboxed.Mutable as VUM\n-}\nimport Control.Monad\nimport Control.Monad.ST.Safe\n-- import Control.Monad.ST\nimport Control.Applicative\nimport Data.Maybe\nimport Data.Tuple\nimport Data.Ord\nimport Control.Monad.State.Strict\nimport Data.Int\nimport Data.Word\nimport Data.STRef\nimport Data.IORef\nimport Data.Function\nimport System.IO\nimport System.Exit\n\nmain :: IO ()\nmain = do\n [n,v] <- map readInt . words <$> getLine\n let infirst = (v - 1) `min` (n - 1)\n inrest = (n - 1) - infirst\n print $ infirst + shiftR (inrest * (inrest + 1)) 1\n\nrInt :: StateT BSL.ByteString Maybe Int\nrInt = StateT $ BSL.readInt . BSL.dropWhile (<'!')\n\n#define D(f,r,d) f::Integral a=>a->d;f=fromIntegral;r::String->d;r=read\n#define C(f,r,g,h,d) D(f,r,d);g,h::RealFrac a=>a->d;g=floor;h=ceiling\nC(_toInteger_,readInteger,floorInteger,ceilInteger,Integer)\nC(toInt,readInt,floorInt,ceilInt,Int)\nC(toI8,readI8,floorI8,ceilI8,Int8)\nC(toI16,readI16,floorI16,ceilI16,Int16)\nC(toI32,readI32,floorI32,ceilI32,Int32)\nC(toI64,readI64,floorI64,ceilI64,Int64)\nC(toWord,readWord,floorWord,ceilWord,Word)\nC(toW8,readW8,floorW8,ceilW8,Word8)\nC(toW16,readW16,floorW16,ceilW16,Word16)\nC(toW32,readW32,floorW32,ceilW32,Word32)\nC(toW64,readW64,floorW64,ceilW64,Word64)\nD(toDouble,readDouble,Double)\nD(toFloat,readFloat,Float)\n#undef D\n#undef C\n\n\n#define N(f,g,a,m)\\\n f :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> e -> m (a i e); f=A.newArray;\\\n g :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> m (a i e); g=A.newArray_\n#define C(a,m)\nN(newIOA,newIOA_,IOArray,IO)\nN(newSTA,newSTA_,STArray s,ST s)\n#undef C\n#define C(a,m) MArray (a) e (m), \nN(newIOUA,newIOUA_,IOUArray,IO)\nN(newSTUA,newSTUA_,STUArray s,ST s)\n#undef C\n#undef N\n\n", "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7"} {"source_code": "module Main where\n\nmain = do\n (xa, ya) <- getVectorLine\n (xb, yb) <- getVectorLine\n (xc, yc) <- getVectorLine\n\n let try :: Integer -> Integer -> Bool\n try x y = let\n det = xc*xc + yc*yc\n det_a = x*xc + y*yc\n det_b = xc*y -yc*x\n in if det == 0\n then x == 0 && y == 0\n else ( det_a `mod` det ) == 0 && ( det_b `mod` det ) == 0\n\n putStrLn $ if try (xb-xa) (yb-ya) || try (xb-ya) (yb+xa) || try (xb+xa) (yb+ya) || try (xb+ya) (yb-xa)\n then \"YES\"\n else \"NO\"\n\ngetVectorLine :: IO (Integer, Integer)\ngetVectorLine = do\n input <- getLine\n let [x, y] = map read $ words input\n return (x, y)\n", "src_uid": "cc8a8af1ba2b19bf081e379139542883"} {"source_code": "\nf :: (Int,Int,Int) -> Maybe Int\nf (1, 2,x) = if x ==3 then Just 2 else Just 3\nf (1, 3,_) = Just 4\nf (2, 1,_) = Just 3\nf (2 ,3,_) = Nothing\nf (3, 1,_) = Just 4 \nf (3, 2,_) = Nothing \n\nsolve ::[Int] -> Maybe Int\nsolve l = foldl sum' (Just 0) (map f ((head l,l!!1,12):pairs l))\n where sum' x y = (+) <$> x <*> y\n\npairs :: [Int] -> [(Int,Int,Int)]\npairs (x:y:z:ys) = (y,z,x):(pairs (y:z:ys))\npairs (x:y:ys) = []\npairs _ = []\n\nc :: Maybe Int -> String\nc (Just x) =\"Finite\\n\"++ (show x)\nc _ = \"Infinite\"\n\nmain = do\n n <- getLine\n inp <- getLine\n let l =map read $ words inp\n putStrLn $ c $ solve l", "src_uid": "6c8f028f655cc77b05ed89a668273702"} {"source_code": "import Control.Monad\nimport Control.Applicative\n\nmain :: IO ()\nmain = do\n [a, b] <- map read . words <$> getLine\n print $ solve a b\n\nsolve :: Integer -> Integer -> Integer\nsolve a b =\n if b - a > 5 then 0 else solve' b (b - a) 1\n where\n solve' n 0 acc = acc\n solve' n c acc = solve' (n - 1) (c - 1) (acc `seq` ((acc * n) `mod` 10))\n", "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60"}