#include using namespace std; int main() { int n; cin >> n; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int cnt = 1; map mp; for (int i = 0; i < n - 1; i++) { if (a[i] - a[i + 1] == -1) { cnt++; } else { mp[cnt]++; cnt = 1; } } if (cnt > 1) mp[cnt]++; long long ans = 0; for (auto i : mp) { if (i.first <= 1) continue; ans += 1LL * (i.first) * (i.first - 1) / 2 * i.second; } cout << ans << endl; return 0; }