fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #include <ext/pb_ds/assoc_container.hpp>
  4. #include <ext/pb_ds/tree_policy.hpp>
  5. using namespace __gnu_pbds;
  6. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  7.  
  8.  
  9. #define ll long long
  10.  
  11. using namespace std;
  12.  
  13. int main()
  14. {
  15. ios::sync_with_stdio(false);
  16. cin.tie(nullptr), cout.tie(nullptr);
  17.  
  18.  
  19. ll n,k; cin >> n >> k;
  20. ll sum = 0;
  21. vector <ll> nums(n);
  22. map <ll,ll> mp;
  23.  
  24. for (ll i=0; i<n; i++) {
  25. cin >> nums[i];
  26.  
  27. mp[ nums[i]%k ]++;
  28. }
  29.  
  30. for (auto i:mp) {
  31. if (mp.count(k-i.first) && i.first!=0) {
  32. sum += min(i.second, mp[k-i.first]);
  33. }
  34. else if (i.first==0) {
  35. sum += i.second/2*2;
  36. }
  37. }
  38.  
  39. cout << sum;
  40.  
  41. return 0;
  42.  
  43. }
  44.  
Success #stdin #stdout 0s 5296KB
stdin
1 4
2
stdout
1