n, *hs = $<.read.split($/).map(&:to_i)
hs.sort!.reverse!

count = 0 
unfilled_dist = 0 
capacity = 1 

hs.each_with_index {|h, i|
    break if h < unfilled_dist
    count += h + 1 - unfilled_dist
    capacity -= 1
    if capacity == 0
        unfilled_dist += 1
        capacity = 4 * unfilled_dist - i - 1 
    end 
}

p count