#include // #include #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; // using namespace atcoder; using ll = long long; using str = string; using pl = pair; template using ml = map; using mll = ml; using sl = set; using dbl = double; using pd = pair; template using vec = vector; template using vv = vec>; template using vp = vec>; using vl = vec; using vvl = vec; using vs = vec; using vc = vec; using vpl = vec; using vd = vec; using vpd = vec; using tl3 = tuple; const double INF = std::numeric_limits::infinity(); #define LL(x) \ ll x; \ cin >> x; #define STR(s) \ str s; \ cin >> s; #define VL(a, n) \ vl a(n); \ cin >> a; #define all(obj) (obj).begin(), (obj).end() #define reps(i, a, n) for (ll i = (a); i < (ll)(n); ++i) #define rep(i, n) reps(i, 0, n) #define rrep(i, n) reps(i, 1, n + 1) #define repds(i, a, n) for (ll i = (n - 1); i >= (a); i--) #define repd(i, n) repds(i, 0, n) #define rrepd(i, n) repds(i, 1, n + 1) #define rep2(i, j, x, y) rep(i, x) rep(j, y) template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template ostream &operator<<(ostream &os, const pair &p) { os << p.first << " " << p.second; return os; } template istream &operator>>(istream &is, pair &p) { is >> p.first >> p.second; return is; } template ostream &operator<<(ostream &os, const vector &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; } template ostream &operator<<(ostream &os, const set &s) { os << vec(s.begin(), s.end()); return os; } template istream &operator>>(istream &is, vector &v) { for (T &in : v) is >> in; return is; } void print() { cout << '\n'; } template void print(const T &t) { cout << t << '\n'; } template void print(const Head &head, const Tail &...tail) { cout << head << ' '; print(tail...); } void print_accurate(dbl x) { cout << scientific << setprecision(15) << x << '\n'; } void repr_(const ll &x) { cerr << x; } void repr_(const int &x) { cerr << x; } void repr_(const dbl &x) { cerr << x; } void repr_(const str &x) { cerr << x; } void repr_(const char &x) { cerr << x; } void repr_(const char *x) { cerr << x; } template void repr_(const pair &p); template void repr_(const map &m); template void repr_(const vec &v); template void repr_(const set &s); template void repr_(const pair &p) { cerr << '('; repr_(p.first); cerr << ", "; repr_(p.second); cerr << ')'; } template void repr_(const vec &v) { cerr << '['; for (int i = 0; i < (int)v.size(); i++) { repr_(v[i]); if (i + 1 != (int)v.size()) cerr << ", "; } cerr << ']'; } template void repr_(const set &s) { cerr << '{'; vec v = vec(all(s)); for (int i = 0; i < (int)v.size(); i++) { repr_(v[i]); if (i + 1 != (int)v.size()) cerr << ", "; } cerr << '}'; } template void repr_(const map &m) { cerr << '{'; vp v = vp(all(m)); for (int i = 0; i < (int)v.size(); i++) { repr_(v[i].first); cerr << ": "; repr_(v[i].second); if (i + 1 != (int)v.size()) cerr << ", "; } cerr << '}'; } template void repr_(const Head &head, const Tail &...tail) { repr_(head); repr_(' '); repr_(tail...); } template void repr(const T &t) { repr_(t); cerr << '\n'; } template void repr(const Head &head, const Tail &...tail) { repr_(head); repr_(' '); repr(tail...); } void solve() { LL(N); VL(A, N); unordered_map d; rep(i, N) { if (d.find(A[i]) != d.end()) { d[A[i]].push_back(i); } else { d[A[i]] = vl(1, i); } } ll ans = 0; reps(k, 1, 2000) { for (auto &i : d) { vl a = {i.first, 0, 0, 0}; a[1] = a[0] + k + 10; a[2] = a[1] - k; a[3] = a[2] + k + 1; bool f = false; rep(j, 4) { if (d.find(a[j]) == d.end()) f = true; } if (f) continue; vpl tmp; rep(x, 4) { for (auto &j : d[a[x]]) { tmp.push_back({j, x}); } } sort(all(tmp)); // print("tmp", tmp); // print("a", a); vl dp = {1, 0, 0, 0, 0}; for (auto &j : tmp) { dp[j.second + 1] += dp[j.second]; } // print("dp", dp); ans += dp[4]; } } print(ans); } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); solve(); return 0; }