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