#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    
    int N,M;
    cin >> N >> M;
    vi X(N);
    in(N,X);
    sort(all(X));
    vvi A(M);
    rep(i,N){
        A[X[i]%M].pb(X[i]);
    }
    int ans = 0;
    
    
    if(M%2==1){
        //%M == 0
        ans += (int)A[0].size()/2;
        //other
        reps(i,1,M/2+1){
            int a = (int)A[i].size();
            int b = (int)A[M-i].size();
            
            if(a < b){
                b -= a;
                map<int,int> B;
                int c = 0;
                rep(j,(int)A[M-i].size()) B[A[M-i][j]]++;
                for (pii p : B) c += p.se/2;
                
                ans += a + min(b/2,c);
                
            }else if(a > b){
                a -= b;
                map<int,int> B;
                int c = 0;
                rep(j,(int)A[i].size()) B[A[i][j]]++;
                for (pii p : B) c += p.se/2;
                
                
                ans += b + min(a/2,c);
                
            }else{
                ans += a;
            }
            
        }
    }else if(M%2==0){
        //%M == 0,M/2
        ans += (int)A[0].size()/2;
        ans += (int)A[M/2].size()/2;
        
        //other
        reps(i,1,M/2){
            int a = (int)A[i].size();
            int b = (int)A[M-i].size();
            
            if(a < b){
                b -= a;
                map<int,int> B;
                int c = 0;
                rep(j,(int)A[M-i].size()) B[A[M-i][j]]++;
                for (pii p : B) c += p.se/2;
                
                
                ans += a + min(b/2,c);
                
            }else if(a > b){
                a -= b;
                map<int,int> B;
                int c = 0;
                rep(j,(int)A[i].size()) B[A[i][j]]++;
                for (pii p : B) c += p.se/2;
                
                
                
                ans += b + min(a/2,c);
                
            }else{
                ans += a;
            }
        }
        
    }
    
    
    
    cout << ans << endl;
    
    

    return 0;
}


Measured memory_bytes: 6144