fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N=1e6+6, mod=1e9+7;
  5. int n, a[N], x;
  6. long long ans;
  7. map<long long, long long> mp;
  8.  
  9. signed main()
  10. {
  11. ios::sync_with_stdio(0);
  12. cin.tie(0); cout.tie(0);
  13.  
  14. cin >> n >> x;
  15. for(int i=1;i<=n;++i) cin >> a[i];
  16. for(int i=1;i<=n;++i){
  17. ans+=mp[a[i]*1LL-x]+mp[a[i]*1LL+x];
  18. ans%=mod;
  19. mp[a[i]]=(mp[a[i]]+1)%mod;
  20. }
  21. cout << ans;
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty