#include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define double long double typedef vector VI; typedef pair pii; typedef vector VP; typedef vector VS; typedef priority_queue PQ; templatebool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define fore(i,a) for(auto &i:a) #define REP(i,n) for(int i=0;i, greater > q2; int cnt[6010][3010]; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; VI M(N); REP(i, N)cin >> M[i]; REP(i, N) { int now = i * 2; int t = 0; int to = M[i] * 2; bool type = now < to; REP(j, 6005) { cnt[t++][now]++; if (now < to && type)now++; else if (now > to && !type)now--; } } int ans = 0; REP(i, 6005)REP(j, 3005)ans += (cnt[i][j] - 1)*cnt[i][j] / 2; cout << ans << endl; return 0; }