# frozen_string_literal: true N, M, K = 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 case OP when :+ puts(AS.map { |a| BS.map { |b| (a + b) % K }.sum % K }.sum % K) when :* puts(AS.map { |a| BS.map { |b| (a * b) % K }.sum % K }.sum % K) end