times = 5.times.map{ gets.chomp.to_i }
times_all = times.permutation(5).to_a
results = []

count = 0
times_all.each do |times|
  for i in 0..times.size-1 do
    count += times[i]
    unless i == times.size-1
      until count % 10 == 0 do
        count += 1
      end
    end
  end
  results.push(count)
  count = 0
end

puts results.min
