https://www.luogu.com.cn/record/95256641
https://www.luogu.com.cn/record/95260815
https://www.luogu.com.cn/record/95261441
https://www.luogu.com.cn/record/95261932
// Problem: P3799 妖梦拼木棒
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P3799
// Memory Limit: 125 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<iostream>
#include<cmath>
using namespace std;
int w[114514];
bool b[114514];
int lr[4],n;
int ans=0;
void t(int a,int bb){
if(bb==3){
/*for(int p=1;p<=n;p++){
cerr<<b[p];
}
cerr<<endl;*/
if(lr[1]==lr[2]){
for(int i=1;i<=n-1;i++){
for(int o=i+1;o<=n;o++){
//printf("detecting b[%d] & b[%d]!w[%d]=%d,w[%d]=%d,result=%d\n",i,o,i,w[i],o,w[o],w[o]+w[i]);
if(w[i]+w[o]==lr[1]&&b[i]==0&&b[o]==0){
//printf("b[%d]==b[%d]=0!\n",i,o);
ans++;
ans%=(int)pow(10,9)+7;
}
}
}
}
return;
}else{
if(b[a]==0){
for(int i=a;i<=n-(2-bb);i++){
//cerr<<"limit:"<<n-(4-bb)<<endl;
b[i]=1;
lr[bb]=w[i];
t(i+1,bb+1);
b[i]=0;
}
}
}
return;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>w[i];
}
t(1,1);
cout<<ans<<endl;
return 0;
}