Done some puzzles
[cses-programming-tasks.git] / app / cses1754.hs
diff --git a/app/cses1754.hs b/app/cses1754.hs
new file mode 100644 (file)
index 0000000..56e16ab
--- /dev/null
@@ -0,0 +1,30 @@
+import Control.Monad
+
+main :: IO ()
+main = do
+  line1 <- getLine
+  let numQuestions = read line1 :: Int
+  answers <- forM [1..numQuestions] $ \_ -> do
+    q <- getQuestion
+    return $ solve q
+  putStrLn $ unlines $ map showA answers
+
+getQuestion :: IO (Int, Int)
+getQuestion = do
+  line <- getLine
+  let question = map read $ words line
+  return (question !! 0, question !! 1)
+
+
+solve :: (Int, Int) -> Bool
+solve (0, 0) = True
+solve (0, _) = False
+solve (_, 0) = False
+solve (nLeft, nRight) = (a <= b * 2) && ((b - n) `mod` 3 == 0)
+  where a = max nLeft nRight
+        b = min nLeft nRight
+        n = a - b
+
+showA :: Bool -> String
+showA True = "YES"
+showA False = "NO"