w = gets.to_i h = gets.to_i n = gets.to_i t = [] n.times do t.push(gets.chomp.split(" ").map(&:to_i)) end tt = Array.new(w) tt.fill(0) t.map{|u|u[0]}.each do |d| tt[d-1] += 1 end a = 0 m = [] mm = [] w.times do |d| unless(tt[d] == 0) p = h - tt[d] a += p m.push(d) mm.push(t.map{|u|u[1]}) end end m.uniq! mm = mm.flatten.uniq a += mm.size * (w - m.size) p a