gets
array_x = gets.chomp.split

array_x.map! do |x|
  x.to_i
end

s = 0

loop do
  candi_i = 0
  max_abs = 0
  array_x.each_with_index do |x, i|
    abs = (x - i - 1).abs
    if max_abs < abs
      max_abs = abs
      candi_i = i
    elsif max_abs == abs
      if array_x[candi_i] > x
        candi_i = i
      end
    end
  end
  
  if max_abs == 0 then break end

  x = array_x[candi_i].to_i
  array_x.delete_at candi_i
  array_x.insert x - 1, x
  s += x
end

puts s