def main w = gets.to_i h = gets.to_i n = gets.to_i cards = Array.new(h){Array.new(w, 0)} n.times do s,k = gets.split.map(&:to_i) cards[k-1][s-1] = 2 (0...h).each do |_h| cards[_h][s-1] = 1 if cards[_h][s-1] != 2 end (0...w).each do |_w| cards[k-1][_w] = 1 if cards[k-1][_w] != 2 end cards[k-1][s-1] = 2 end puts cards.flatten.count {|c| c == 1 } end main()