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