import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[1000]; int total = 0; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); total += arr[i]; } int min = Integer.MAX_VALUE; for (int i = 1; ; i += 2) { int height = i / 2 + 1; if (height * height > total) { break; } int length = height * 2 - 1; int count = 0; int size = 1; int idx = 1; while (idx < arr.length) { if (arr[idx - 1] == 0 && size == 0) { break; } count += Math.max(arr[idx - 1] - size, 0); if (idx >= height) { size--; if (size < 0) { size = 0; } } else { size++; } idx++; } min = Math.min(min, count); } System.out.println(min); } }