Tackled problem 1625
[cses-programming-tasks.git] / app / cses1754.hs
1 import Control.Monad
2
3 main :: IO ()
4 main = do
5 line1 <- getLine
6 let numQuestions = read line1 :: Int
7 answers <- forM [1..numQuestions] $ \_ -> do
8 q <- getQuestion
9 return $ solve q
10 putStrLn $ unlines $ map showA answers
11
12 getQuestion :: IO (Int, Int)
13 getQuestion = do
14 line <- getLine
15 let question = map read $ words line
16 return (question !! 0, question !! 1)
17
18
19 solve :: (Int, Int) -> Bool
20 solve (0, 0) = True
21 solve (0, _) = False
22 solve (_, 0) = False
23 solve (nLeft, nRight) = (a <= b * 2) && ((b - n) `mod` 3 == 0)
24 where a = max nLeft nRight
25 b = min nLeft nRight
26 n = a - b
27
28 showA :: Bool -> String
29 showA True = "YES"
30 showA False = "NO"