Problem:
Score : 200 points

Problem Statement

We have a grid with N rows and M columns of squares. Initially, all the squares are white.

There is a button attached to each row and each column.
When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa.
When a button attached to a column is pressed, the colors of all the squares in that column are inverted.

Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.

Constraints

1 \leq N,M \leq 1000

0 \leq K \leq NM

Input

Input is given from Standard Input in the following format:

N M K

Output

If Takahashi can have exactly K black squares in the grid, print Yes; otherwise, print No.

Sample Input 1

2 2 2

Sample Output 1

Yes

Press the buttons in the order of the first row, the first column.

Sample Input 2

2 2 1

Sample Output 2

No

Sample Input 3

3 5 8

Sample Output 3

Yes

Press the buttons in the order of the first column, third column, second row, fifth column.

Sample Input 4

7 9 20

Sample Output 4

No

Solution in Haskell (GHC 7.10.3) (judge verdict: Wrong Answer)

module Main where


main :: IO()
main = do
  [n,m,k] <- map read . words <$> getLine
  putStrLn $ solve n m k

solve :: Int -> Int -> Int -> String
solve n m k = if subSolve n m k then "Yes" else "No"

subSolve :: Int -> Int -> Int -> Bool
subSolve n m k = anyForList . map (\(hp, wp) ->
  case cellsNum n m hp wp of
    Just x  -> x == k
    Nothing -> False) $ zip [1..n] [1..m]

allPattern :: [a] -> [a] -> [(a,a)]
allPattern (x:xs) xss' = map (\x' -> (x, x')) xss' ++ allPattern xs xss'

cellsNum :: Int -> Int -> Int -> Int -> Maybe Int
cellsNum h w hp wp
  | h < hp || w < wp  = Nothing
  | otherwise         = Just $ (w - wp) * hp + (h - hp) * wp

anyForList :: [Bool] -> Bool
anyForList [] = False
anyForList (b:bs)
  | b         = True
  | otherwise = anyForList bs