#include <bits/stdc++.h>
using namespace std;
int arr[500005];
int arr2[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, k, ans = 0, x = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    arr[a % k]++;
  }
  for (int i = 1; i < k - i; i++) {
    x = (min(arr[i], arr[k - i]));
    ans += x;
    arr[i] -= x;
    arr[k - i] -= x;
  }
  if (k % 2 != 0) {
    if (arr[k / 2] > 0) ans += min(arr[k / 2 + 1], arr[k / 2]);
  } else {
    ans += arr[k / 2] / 2;
  }
  cout << (ans + arr[0] / 2) * 2 << endl;
}
