from collections import defaultdict as dd

N, M = list(map(int, input().split()))

c = list(map(int, input().split()))

c.sort()

m = dd(int)

d = dd(int)

for n in c:

  d[n] += 1

  m[n % M] += 1

res = 0

for i in range(M):

  temp = min(m[i], m[(M - i) % M])

  if i == (M - i) % M:

    temp = m[i] // 2

  m[i] -= temp

  m[(M - i) % M] -= temp

  res += temp

for i in range(N):

  n = c[i]

  if m[n % M] > 1:

    k = m[n % M] // 2

    if d[n] > 1:

      temp = min(d[n] // 2, k)

      res += temp

      d[n] -= temp * 2

      m[n % M] -= temp * 2

print(res)
import sys

input = sys.stdin.readline

N, M = list(map(int, input().split()))

a = list(map(int, input().split()))

a.sort()

m = [0] * M

d = [0] * (max(a) + 1)

for x in a:

  d[x] += 1

  m[x % M] += 1



res = 0

for i in range(M):

  t = min(m[i], m[(M - i) % M])

  if i == (M - i) % M:

    t = m[i] // 2

  m[i] -= t

  m[(M - i) % M] -= t

  res += t



for i in range(N):

  x = a[i]

  if m[x % M] > 1:

    k = m[x % M] // 2

    if d[x] > 1:

      t = min(d[x] // 2, k)

      res += t

      d[x] -= t * 2

      m[x % M] -= t * 2

print(res)

from collections import defaultdict as dd

N, M = list(map(int, input().split()))
c = list(map(int, input().split()))
c.sort()
m = dd(int)
d = dd(int)
for n in c:
    d[n] += 1
    m[n % M] += 1
res = 0
for i in range(M):
    temp = min(m[i], m[(M - i) % M])
    if i == (M - i) % M:
        temp = m[i] // 2
    m[i] -= temp
    m[(M - i) % M] -= temp
    res += temp
for i in range(N):
    n = c[i]
    if m[n % M] > 1:
        k = m[n % M] // 2
        if d[n] > 1:
            temp = min(d[n] // 2, k)
            res += temp
            d[n] -= temp * 2
            m[n % M] -= temp * 2
print(res)

import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
m = [0] * M
d = [0] * (max(a) + 1)
for x in a:
    d[x] += 1
    m[x % M] += 1
res = 0
for i in range(M):
    t = min(m[i], m[(M - i) % M])
    if i == (M - i) % M:
        t = m[i] // 2
    m[i] -= t
    m[(M - i) % M] -= t
    res += t
for i in range(N):
    x = a[i]
    if m[x % M] > 1:
        k = m[x % M] // 2
        if d[x] > 1:
            t = min(d[x] // 2, k)
            res += t
            d[x] -= t * 2
            m[x % M] -= t * 2
print(res)

-from collections import defaultdict as dd +import sys +input = sys.stdin.readline -c = list(map(int, input().split())) -c.sort() -m = dd(int) -d = dd(int) -for n in c: -    d[n] += 1 -    m[n % M] += 1 +a = list(map(int, input().split())) +a.sort() +m = [0] * M +d = [0] * (max(a) + 1) +for x in a: +    d[x] += 1 +    m[x % M] += 1 -    temp = min(m[i], m[(M - i) % M]) +    t = min(m[i], m[(M - i) % M]) -        temp = m[i] // 2 -    m[i] -= temp -    m[(M - i) % M] -= temp -    res += temp +        t = m[i] // 2 +    m[i] -= t +    m[(M - i) % M] -= t +    res += t -    n = c[i] -    if m[n % M] > 1: -        k = m[n % M] // 2 -        if d[n] > 1: -            temp = min(d[n] // 2, k) -            res += temp -            d[n] -= temp * 2 -            m[n % M] -= temp * 2 +    x = a[i] +    if m[x % M] > 1: +        k = m[x % M] // 2 +        if d[x] > 1: +            t = min(d[x] // 2, k) +            res += t +            d[x] -= t * 2 +            m[x % M] -= t * 2