#include #include #include using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int32_t N, i; cin >> N; vector A(N); for (i = 0; i != N; ++i) cin >> A[i]; int32_t combo = 1; int64_t ans = 0; for (i = 1; i != N; ++i) { if (A[i] == A[i - 1] + 1) ++combo; else ans += combo * static_cast(combo - 1) / 2, combo = 1; } cout << ans + combo * static_cast(combo - 1) / 2 << '\n'; return 0; }