#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)s; i < (int)e; i++) int main() { cin.tie(nullptr); int N; cin >> N; vector A(N); rep(i, 0, N) cin >> A[i]; vector d(N - 1); rep(i, 0, N - 1) d[i] = A[i + 1] - A[i]; ll ans = 0; ll cnt = 0; rep(i, 0, N - 1) { if (d[i] == 1) cnt++; else { ans += (cnt + 1) * cnt / 2; cnt = 0; } } if (cnt != 0) ans += (cnt + 1) * cnt / 2; cout << ans << '\n'; }