class Yukicoder def initialize w = gets.to_i h = gets.to_i n = gets.to_i marks = Array.new(w){ Array.new(h, 0)} nums = Hash.new(0) check_list = Hash.new(false) n.times do s, k = gets.chomp.split.map{|i| i.to_i-1} if !check_list[s] marks[s] = Array.new(h, 1) check_list[s] = true end nums[k] = 1 end answer = 0 marks.each do |mark| num = 0 mark.each_with_index do |n, i| num += [n, nums[i]].max end answer += num end puts answer - n end end Yukicoder.new