#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long t, n, m, k, a, b, c, d;
  t = 1;
  while (t--) {
    cin >> n >> k;
    vector<long long> v(n);
    vector<long long> fr(k, 0);
    for (long long i = 0; i < n; i++) {
      cin >> v[i];
      fr[v[i] % k]++;
    }
    long long ans = 0;
    ans += fr[0] / 2;
    for (long long i = 1; i <= k / 2; i++) {
      ans += min(fr[i], fr[k - i]);
    }
    if (k % 2 == 0) {
      ans -= fr[k / 2];
      ans += fr[k / 2] / 2;
    }
    ans *= 2;
    cout << ans << endl;
  }
  return 0;
}
