import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; public class Main { public static final int MAX = 1000000; public static void main(String[] args){ Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); int[] arr = new int[N]; for(int i = 0; i < N; i++){ arr[i] = sc.nextInt(); } final int sum = Arrays.stream(arr).sum(); int diff = Integer.MAX_VALUE; for(int i = 1; i <= N; i += 2){ final int needs = (i / 2 + 1) * (i / 2 + 1); //System.out.println(sum + " " + needs); if(needs > sum){ break; } int drop = 0, count = 0; for(int j = 0; j < i; j++){ final int need_height = (i / 2 + 1) - Math.abs((j + 1) - (i / 2 + 1)); //System.out.println(i + " " + need_height + " " +arr[j] + " " + drop + " " + count); for(int d = Math.abs(arr[j] - need_height); d > 0; d--){ if(arr[j] > need_height){ if(drop >= 0){ count++; } drop++; }else if(arr[j] < need_height){ if(drop <= 0){ count++; } drop--; } } } for(int j = i; j < N; j++){ for(int k = 0; k < arr[j]; k++){ if(drop > 0){ drop--; }else if (drop < 0){ drop++; }else{ count++; } } } diff = Math.min(diff, count); } System.out.println(diff); } }