Language: C++

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x[ohara],y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
map<ll,ll> mp;
map<ll,ll> cou;
map<ll,ll> herasu;
bool vi[ohara];
ll kosuu;
P p[ohara];
ll p_cou;
ll dat[ohara];

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);

    //[{%m,m}]=個数
    cin>>n>>m;
    rep(i,n)cin>>x[i];
    rep(i,n){
        cou[x[i]]++;
        mp[x[i]%m]++;
    }
    rep(i,n){
        if((x[i]%m)!=m-(x[i]%m)&&x[i]%m!=0){
            //cerr<<i<<" "<<mp[i]<<" ";
            ans+=min(mp[x[i]%m],mp[m-(x[i]%m)]);
            herasu[x[i]%m]+=min(mp[x[i]%m],mp[m-(x[i]%m)]);
            herasu[m-(x[i]%m)]+=min(mp[x[i]%m],mp[m-(x[i]%m)]);
            pos=mp[x[i]%m];
            mp[x[i]%m]-=min(mp[x[i]%m],mp[m-(x[i]%m)]);
            mp[m-(x[i]%m)]-=min(pos,mp[m-(x[i]%m)]);
        }
        else{
            ans+=mp[x[i]%m]/2;
            herasu[x[i]%m]+=(mp[x[i]%m]/2)*2;
            mp[x[i]%m]%=2;
        }
    }
    rep(i,n){
        if(vi[x[i]])continue;
        vi[x[i]]=true;
        p[p_cou++]=m_p(cou[x[i]],x[i]%m);
    }
    sort(p,p+p_cou);
    reverse(p,p_cou);
    rep(i,p_cou){
        if(p[i].fi%2==herasu[p[i].se]%2){
            dat[p[i].se]++;
            p[i].fi--;
        }
        //p[i].fi/=2;
    }
    rep(i,m){
        herasu[i]-=dat[i];
        if(herasu[i]<0)herasu[i]=0;
    }
    rep(i,p_cou){
        cnt+=max(p[i].fi-herasu[p[i].se],0LL)/2;
        //cout<<p[i].fi<<"\n";
    }
    //Cerr(cnt);
    //rep(i,m)cnt-=herasu[i],cerr<<herasu[i]<<"\n";
    //rep(i,m)cnt-=herasu[i],cout<<i<<" "<<herasu[i]<<"\n";
    Cout(ans+cnt);
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:74:12: error: no matching function for call to 'reverse(std::pair<long long int, long long int> [1000010], ll&)'
   74 |     reverse(p,p_cou);
      |     ~~~~~~~^~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:1083:5: note: candidate: 'template<class _BIter> void std::reverse(_BIter, _BIter)'
 1083 |     reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
      |     ^~~~~~~
/usr/include/c++/14/bits/stl_algo.h:1083:5: note:   template argument deduction/substitution failed:
a.cc:74:12: note:   deduced conflicting types for parameter '_BIter' ('std::pair<long long int, long long int>*' and 'long long int')
   74 |     reverse(p,p_cou);
      |     ~~~~~~~^~~~~~~~~
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:249:1: note: candidate: 'template<class _ExecutionPolicy, class _BidirectionalIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, void> std::reverse(_ExecutionPolicy&&, _BidirectionalIterator, _BidirectionalIterator)'
  249 | reverse(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last);
      | ^~~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:249:1: note:   candidate expects 3 arguments, 2 provided