let words str =
  let len = String.length str in
  let buf = Buffer.create 4 in
  let rec aux i l =
    if i >= len then
      List.rev (int_of_string (Buffer.contents buf) :: l)
    else 
      match str.[i] with
      | ' ' ->
        let s = int_of_string (Buffer.contents buf) in
        Buffer.clear buf;
        aux (i+1) (s::l)
      | c   ->
        Buffer.add_char buf c;
        aux (i+1) l
  in
  aux 0 []

let () =
  let n,m = Scanf.sscanf (read_line ()) "%d %d" (fun n m -> n,m) in
  let aux lim =
    let rec loop i l =
      if i >= lim then List.rev l
      else
        let am = read_line () in
        loop (i+1) (words am :: l)
    in
    loop 0 [] in
  let a = aux n in
  let b = List.concat (aux m) in
  List.iter
    (fun am ->
       let c = List.map2 (fun x y -> x*y) am b in
       print_int (List.fold_left (fun acc n -> acc + n) 0 c);
       print_newline ())
    a