#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  std::vector<long long> v(k);
  for (long long i = 0; i < n; i++) {
    v[a[i] % k]++;
  }
  long long ans = v[0] / 2;
  if (k % 2 == 0) {
    ans += v[k / 2] / 2;
  }
  for (long long i = 1; i < (k + 1) / 2; i++) {
    long long j = k - i;
    ans += min(v[i], v[j]);
  }
  cout << 2 * ans << '\n';
}
