P1,P2,N = 3.times.map{gets.to_i} D = N.times.map{gets.to_i}.group_by(&:itself).inject(0){|d,(n,r)| d + (r.size - 1) } puts (P1 + P2) * D