X = gets.to_i + gets.to_i R = [] p (1..(gets.to_i)).map { |i| q = gets.to_i R.include?(q) ? X : (R << q; 0) } .reduce :+