#include <bits/stdc++.h>
#define N 100005
using namespace std;
long long n, a[N];
void sub1()
{
long long cnt = 0;
for(int i = 1; i <= n; i++)
{
if(a[i] + a[i+1] > a[n]) break;
for(int j = i + 1; j <= n; j++)
{
if(a[i] + a[j] > a[n]) break;
if(binary_search(a + j + 1, a + 1 + n, a[i] + a[j]))
{
//cout << a[i] << ' ' << a[j] << '\n';
cnt++;
}
}
}
cout << cnt * 2;
}
int main()
{
cin.tie(0) -> sync_with_stdio(false);
freopen("BAI2.INP", "r", stdin);
freopen("BAI2.OUT", "w", stdout);
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + 1 + n);
if(n <= 3000) sub1();
else
{
long long cnt = 0;
for(int i = 1; i <= n; i++)
{
int j = lower_bound(a + 1, a + 1 + n, a[n] - a[i]) - a;
if(a[j] <= a[i]) break;
cnt += j - i;
}
cout << cnt * 2;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgTiAxMDAwMDUKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmxvbmcgbG9uZyBuLCBhW05dOwoKdm9pZCBzdWIxKCkKewogICAgbG9uZyBsb25nIGNudCA9IDA7CiAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG47IGkrKykKICAgIHsKICAgICAgICBpZihhW2ldICsgYVtpKzFdID4gYVtuXSkgYnJlYWs7CiAgICAgICAgZm9yKGludCBqID0gaSArIDE7IGogPD0gbjsgaisrKQogICAgICAgIHsKICAgICAgICAgICAgaWYoYVtpXSArIGFbal0gPiBhW25dKSBicmVhazsKICAgICAgICAgICAgaWYoYmluYXJ5X3NlYXJjaChhICsgaiArIDEsIGEgKyAxICsgbiwgYVtpXSArIGFbal0pKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAvL2NvdXQgPDwgYVtpXSA8PCAnICcgPDwgYVtqXSA8PCAnXG4nOwogICAgICAgICAgICAgICAgY250Kys7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBjb3V0IDw8IGNudCAqIDI7Cn0KCmludCBtYWluKCkKewogICAgY2luLnRpZSgwKSAtPiBzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgZnJlb3BlbigiQkFJMi5JTlAiLCAiciIsIHN0ZGluKTsKICAgIGZyZW9wZW4oIkJBSTIuT1VUIiwgInciLCBzdGRvdXQpOwoKICAgIGNpbiA+PiBuOwogICAgZm9yKGludCBpID0gMTsgaSA8PSBuOyBpKyspIGNpbiA+PiBhW2ldOwogICAgc29ydChhICsgMSwgYSArIDEgKyBuKTsKICAgIGlmKG4gPD0gMzAwMCkgc3ViMSgpOwogICAgZWxzZQogICAgewogICAgICAgIGxvbmcgbG9uZyBjbnQgPSAwOwogICAgICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgaW50IGogPSBsb3dlcl9ib3VuZChhICsgMSwgYSArIDEgKyBuLCBhW25dIC0gYVtpXSkgLSBhOwogICAgICAgICAgICBpZihhW2pdIDw9IGFbaV0pIGJyZWFrOwogICAgICAgICAgICBjbnQgKz0gaiAtIGk7CiAgICAgICAgfQogICAgICAgIGNvdXQgPDwgY250ICogMjsKICAgIH0KICAgIHJldHVybiAwOwp9Cg==