#include <bits/stdc++.h>
using namespace std;
unordered_map<int,int>mpp;
int solve(vector<int>& a){
int n = a.size();
for(int i=3;i<n;i++){
mpp[a[i]]++;
}
int ans = 0;
for(int i=0;i<n-3;i++){
for(int j=i+1;j<n-2;j++){
int k=j+1;
for(;k<n-1;k++){
int sum = -(a[i]+a[j]+a[k]);
ans += mpp[sum];
mpp[a[k+1]]--;
}
for(int z=k+2;z<n;z++){
mpp[a[z]]++;
}
}
}
return ans;
}
int main() {
int n;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
cout<<solve(a);
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp1bm9yZGVyZWRfbWFwPGludCxpbnQ+bXBwOwoKaW50IHNvbHZlKHZlY3RvcjxpbnQ+JiBhKXsKCWludCBuID0gYS5zaXplKCk7CgkKCWZvcihpbnQgaT0zO2k8bjtpKyspewoJCW1wcFthW2ldXSsrOwoJfQoJCglpbnQgYW5zID0gMDsKCWZvcihpbnQgaT0wO2k8bi0zO2krKyl7CgkJZm9yKGludCBqPWkrMTtqPG4tMjtqKyspewoJCQlpbnQgaz1qKzE7CgkJCWZvcig7azxuLTE7aysrKXsKCQkJCWludCBzdW0gPSAtKGFbaV0rYVtqXSthW2tdKTsKCQkJCWFucyArPSBtcHBbc3VtXTsKCQkJCW1wcFthW2srMV1dLS07CgkJCX0KCQkJZm9yKGludCB6PWsrMjt6PG47eisrKXsKCQkJCW1wcFthW3pdXSsrOwoJCQl9CgkJfQoJfQoJcmV0dXJuIGFuczsKfQoKaW50IG1haW4oKSB7CglpbnQgbjsKCWNpbj4+bjsKCXZlY3RvcjxpbnQ+YShuKTsKCWZvcihpbnQgaT0wO2k8bjtpKyspewoJCWNpbj4+YVtpXTsKCX0KCWNvdXQ8PHNvbHZlKGEpOwoJcmV0dXJuIDA7Cn0=