#include using namespace std; int main() { int N; cin >> N; vectorA(N); int Max = -1, Min = 100010; for (int i = 0; i < N; i++) { cin >> A[i]; Max = max(Max, A[i]); Min = min(Min, A[i]); } int ans = 0; for (int k = 1; k <= Max - Min; k++) { vector>dp(N, vector(4, 0)); vector>C(Max + 1, vector(4, 0)); for (int i = 0; i < N; i++) { dp[i][0] = 1; if (A[i] - 10 - k >= 1 && A[i] - 10 - k <= Max) { dp[i][1] += C[A[i] - 10 - k][0]; } if (A[i] + k >= 1 && A[i] + k <= Max) { dp[i][2] += C[A[i] + k][1]; } if (A[i] - k - 1 >= 1 && A[i] - k - 1 <= Max) { dp[i][3] += C[A[i] - k - 1][2]; } for (int j = 0; j < 4; j++) { C[A[i]][j] += dp[i][j]; } } for (int i = 0; i < N; i++) { ans += dp[i][3]; } } cout << ans << endl; }