main = getContents >>= putOut.formatOut.calc.formatIn
  where putOut s | null s || last s == '\n' = putStr s
                 | otherwise                = putStrLn s
  
formatIn :: String -> ([[Int]],[Int])
formatIn s =  (fst (g s), concat (snd (g s)))
  where f m = map (map (read :: String -> Int).words) (lines m)
        g n = splitAt ((head.head) (f n)) $tail (f n)

formatOut :: [Int] -> String
formatOut = unlines.map show

calc :: ([[Int]],[Int]) -> [Int]
calc (a,b) = map (sum.(zipWith (*) b)) a