#include <bits/stdc++.h>
using namespace std;
const long long int N = 2e5 + 10;
const long long int INF = 2e9;
long long int n, k, cnt;
long long int a[N], maxi;
void solve() {
  cin >> n >> k;
  for (long long int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  vector<long long int> v(k + 1);
  for (long long int i = 0; i < n; i++) {
    v[a[i] % k]++;
  }
  for (long long int i = 0; i < v.size(); i++) {
    if (i == (k - i) % k) {
      long long int yo = v[i] / 2;
      cnt += yo * 2;
      v[i] -= yo * 2;
    } else if (v[i] > 0 && v[k - i] > 0) {
      long long int yo = min(v[i], v[k - i]);
      cnt += yo * 2;
      v[i] -= yo;
      v[i] -= yo;
    }
  }
  cout << cnt;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t = 1;
  while (t--) solve();
  return 0;
}
