#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <set>
#include <iterator>
#include <algorithm>
#include <vector>
using namespace std;
const int mod = 1e9+7;
int n;
int t[5010];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
cin >> n;
memset(t, 0, sizeof(t));
int curnum, maxnum = 0;
long long sum = 0;
while (n--){
cin >> curnum;
t[curnum]++;
maxnum = max(maxnum, curnum);
}
for (int i = 1; i <= maxnum; i++){
if (t[i] >= 2){
for (int j = 0; j <= i/2; j++){
// actually had better consider the situation that a_i == 0 exist
// if (j == 0) sum += (t[i]*(t[i]-1)*(t[i]-2)/6*t[j])%mod;
if (i == j*2) sum += (t[i]*(t[i]-1)/2*t[j]*(t[j]-1)/2)%mod;
else sum += (t[i]*(t[i]-1)/2*t[j]*t[i-j])%mod;
}
}
}
// %mod here is needed
cout << sum%mod;
return 0;
}
【洛谷】P3799 妖梦拼木棒
最新推荐文章于 2023-05-14 12:04:13 发布