// General imports

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

// Working but O(n*n) --> 50% of test cases fail on time complexity
public class WeightedDifference {
  public static void main(String[] args) throws IOException {

    double t = System.currentTimeMillis();

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // Write code here

    int a = Integer.parseInt(br.readLine());
    StringTokenizer st = new StringTokenizer(br.readLine());
    int[] ar = new int[a];
    for (int i = 0; i < a; i++) {
      ar[i] = Integer.parseInt(st.nextToken());
    }

    long max = Long.MIN_VALUE;
    int left = 0;
    int right = ar.length - 1;
    int gap = right - left;
    int prevGap = 0;
    while (gap > 0) {
      int diff = ar[right] - ar[left] - (right - left);
      max = diff > max ? diff : max;
      if (gap == prevGap && right < ar.length - 1) {
        left++;
        right++;
      } else {
        gap--;
        prevGap = gap;
        left = 0;
        right = gap;
      }
    }

    System.out.println(max);
    System.out.println(System.currentTimeMillis() - t);

  }

}
