# frozen_string_literal: true def solve w, h = C.transpose.map { _1.uniq.size } W * h + H * w - w * h - N end W, H, N = 3.times.map { gets.to_i } C = N.times.map { gets.split.map(&:to_i) } puts solve