import java.util.Scanner; class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int now = sc.nextInt(); long count = 1; long ans = 0; while(--N>0){ int next = sc.nextInt(); if(++now==next) ++count; else{ now = next; ans += count*(count-1)/2; count = 1; } } System.out.println(ans+count*(count-1)/2); } }