# 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 count_a = AS.filter { |a| a >= K }.size count_b = BS.filter { |b| b >= K }.size COUNT = count_a * M + count_b * N - count_a * count_b A_REMAIN = AS.reject { |a| a >= K } B_REMAIN = BS.reject { |b| b >= K } puts(case OP when :+ A_REMAIN.map do |a| B_REMAIN.map { |b| a + b } .filter { |c| c >= K }.size end .sum when :* A_REMAIN.map do |a| B_REMAIN.map { |b| a * b } .filter { |c| c >= K }.size end .sum end + COUNT)