import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); String[] sa = br.readLine().split(" "); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } br.close(); long ans = 0; int r = 1; for (int l = 0; l < n; l++) { r = Math.max(r, l + 1); while (r < n) { if (a[r - 1] + 1 == a[r]) { r++; } else { break; } } ans += r - l - 1; } System.out.println(ans); } }