#include <bits/stdc++.h>
using namespace std;
int b[1000000];
int main() {
  memset(b, 0, sizeof(b));
  long long int n, i, x, k;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> x;
    b[x % k]++;
  }
  for (i = 0; i < k; i++) {
  }
  int sum = b[0] / 2;
  sum = sum * 2;
  if (n == 2) {
    sum = sum + 2 * (b[1] / 2);
  }
  if (k % 2) {
    x = k / 2;
  } else {
    x = b[k / 2] / 2;
    sum = sum + 2 * x;
    x = (k - 1) / 2;
  }
  for (i = 1; i <= x; i++) {
    sum = sum + 2 * min(b[i], b[k - i]);
  }
  cout << sum;
}
