#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; int N; int A[2020]; int main() { cin >> N; for(int i = 0; i < N; ++i) cin >> A[i]; ll ans = 0; for(int k = 1; k <= 2000; ++k) { vector dp(2001, vector(4,0)); for(int i = 0; i < N; ++i) { int a3 = A[i]-k-1; if(a3 > 0 && a3 <= 2000) dp[A[i]][3] += dp[a3][2]; int a2 = A[i]+k; if(a2 > 0 && a2 <= 2000) dp[A[i]][2] += dp[a2][1]; int a1 = A[i]-k-10; if(a1 > 0 && a1 <= 2000) dp[A[i]][1] += dp[a1][0]; dp[A[i]][0]++; } for(int i = 1; i <= 2000; ++i) ans += dp[i][3]; } cout << ans << endl; }