// #define _GLIBCXX_DEBUG #include using namespace std; #include using namespace atcoder; using ll = long long; #define rep(i,n) for (ll i = 0; i < (n); ++i) using vl = vector; using vvl = vector; using P = pair; #define pb push_back #define int long long #define double long double #define INF (ll) 3e18 // Ctrl + Shift + B コンパイル // Ctrl + C 中断 // ./m 実行 signed main(){ int n; cin >> n; vl a(n); rep(i,n) cin >> a[i]; // 制約的にはKの全探索をしてほしそう auto check = [&](int x) -> bool { if (x < 1) return false; if (x > 2000) return false; return true; }; int ans = 0; rep(k, 2010){ if (k == 0) continue; vvl dp(4, vl(2001)); rep(i, n){ if (check(a[i]-k-1)) dp[3][a[i]] += dp[2][a[i]-k-1]; if (check(a[i]+k)) dp[2][a[i]] += dp[1][a[i]+k]; if (check(a[i]-k-10)) dp[1][a[i]] += dp[0][a[i]-k-10]; dp[0][a[i]]++; } for(auto x : dp[3]) ans += x; } cout << ans << endl; } // a1 = a1 // a2 = a1 + k + 10 // a3 = a2 - k // a4 = a3 + k + 1 // a4 = a3 + k + 1 = a2 + 1 = a1 + k + 11