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