import java.util.*; public class Main { static final int MAX = 10000; public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } int[][] dp = new int[n][MAX + 1]; for (int i = MAX; i >= 0; i--) { dp[n - 1][i] = Math.abs(i - arr[n - 1]); } for (int i = n - 2; i >= 0; i--) { int min = dp[i + 1][MAX]; for (int j = MAX; j >= 0; j--) { min = Math.min(min, dp[i + 1][j]); dp[i][j] = Math.abs(j - arr[i]) + min; } } int min = Integer.MAX_VALUE; for (int i = 0; i <= MAX; i++) { min = Math.min(min, dp[0][i]); } System.out.println(min); } }