4 let numQuestions = read line1 :: Int
5 answers <- forM [1..numQuestions] $ \_ -> do
8 putStrLn $ unlines $ map show answers
10 getQuestion :: IO (Int, Int)
13 let question = map read $ words line
14 return (question !! 0, question !! 1)
17 solve :: (Int, Int) -> Int
18 solve (row, col) = go oddTarget
19 where maxRC = max row col
20 oddTarget = (maxRC `mod` 2) == 1
21 target = maxRC * maxRC
23 | col >= maxRC = target - (row - 1)
24 | otherwise = (target - (row - 1)) - (row - col)
26 | row >= maxRC = target - (col - 1)
27 | otherwise = (target - (col - 1)) - (col - row)
29 -- if target is odd and col >= maxRC:
31 -- if target is odd and row < maxRC:
32 -- (target - (row - 1)) - (row - col)
34 -- if target is even and row >= maxRC
36 -- if target is even and col < maxRC
37 -- (target - (col - 1)) - (col - row)