#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define whole(v) (v).begin(),(v).end() #define rwhole(v) (v).rbegin(),(v).rend() #define press(v) (v).erase(unique(whole(v)),(v).end()) #define Yes cout<<"Yes"< #define vll vector #define vpint vector> #define vvint vector> #define vvll vector> #define pqint priority_queue #define pqpint priority_queue> #define rpqint priority_queue,greater> #define rpqpint priority_queue,vector>,greater>> using namespace std; using ll = long long; int mod107 = 1000000007, mod998 = 998244353; string alphabet = "abcdefghijklmnopqrstuvwxyz", ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; //(a,b)と(c,d)の距離 double pyth(ll a, ll b, ll c, ll d) { double l = sqrt((a - c) * (a - c) + (b - d) * (b - d)); return l; } //aのb乗をmで割った余り(a,bは非負整数,mは自然数) int power(ll a, ll b, int m) { int k = 0, ans = 1; vector v(100); v[0] = a; for (int i = 1; i < 100; i++) v[i] = v[i - 1] * v[i - 1] % m; while (b > 0) { if (b % 2) ans = ans * v[k] % m; k++; b /= 2; } return ans; } //素数判定 O(sqrt(n)) bool prime_judge(ll n) { for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { return false; } } return true; } int main() { int n; cin >> n; vint a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int num = 1, ans = 0; for (int i = 0; i < n - 1; i++) { if (a[i] + 1 == a[i + 1]) { num++; } else { ans += num * (num - 1) / 2; num = 1; } if (i == n - 2) { ans += num * (num - 1) / 2; } } cout << ans << endl; }