# frozen_string_literal: true N, M = gets.chomp.split.map(&:to_i) ROW = gets.chomp.split OP = ROW[0].intern BS = ROW[1..-1].map(&:to_i) AS = N.times.map do gets.to_i end results = AS.map do |a| BS.map do |b| case OP when :+ a + b when :* a * b end end end puts(results.map { |i| i.join(' ') })