#include #include using namespace std; using ll = long long; int main(){ int n; cin >> n; vector a(n); for(auto &&v:a)cin >> v; atcoder::dsu uf(n); for(int i = 0; i + 1 < n; i++){ if(a[i + 1] - a[i] == 1){ uf.merge(i, i + 1); } } auto G = uf.groups(); ll ans = 0; for(auto &&vec:G){ ans += (long long)(vec.size()) * (vec.size() - 1) / 2; } cout << ans << endl; }