#include <bits/stdc++.h>
using namespace std;
const long long maxn = 300000;
const long long inf = 1e18;
long long del[maxn], n, k, x;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  cin >> n >> k;
  for (long long i = 1; i <= n; ++i) {
    cin >> x;
    del[x % k]++;
  }
  long long ans = 0;
  ans = del[0] / 2;
  for (long long i = 1; i <= k / 2; ++i) {
    if (k % 2 == 0 && i == k / 2) continue;
    ans += min(del[i], del[k - i]);
  }
  if (k % 2 == 0) ans += del[k / 2] / 2;
  cout << ans * 2 << endl;
}
