from collections import Counter

n,m=list(map(int,input().split()))

x=[int(i) for i in input().split()]

v=[[] for i in range(m)]

for i in x:v[i%m].append(i)

a=0

for i in range(1,m//2+1*(m%2==1)):

  x,y=v[i],v[m-i]

  d=len(x)-len(y)

  if d<0:

    d=-d

    x,y=y,x

  c=sorted(list(Counter(x).items()),key=lambda x:x[1])

  p=0

  for t in c:

    p+=(t[1]//2)

  a+=len(y)+min(p,(d//2))

a+=len(v[0])//2+(len(v[m//2])//2 if m%2==0 else 0)

print(a)
from collections import Counter

n,m=list(map(int,input().split()))

x=[int(i) for i in input().split()]

v=[[] for i in range(m)]

for i in x:v[i%m].append(i)

a=0

for i in range(1,m//2+m%2):

  x,y=v[i],v[m-i]

  d=len(x)-len(y)

  if d<0:

    d=-d

    x,y=y,x

  c=sorted([p[1] for p in list(Counter(x).items())])

  p=0

  for t in c:

    p+=(t//2)

  a+=len(y)+min(p,(d//2))

a+=len(v[0])//2+(len(v[m//2])//2 if m%2==0 else 0)

print(a)
from collections import Counter

n, m = list(map(int, input().split()))
x = [int(i) for i in input().split()]
v = [[] for i in range(m)]
for i in x:
    v[i % m].append(i)
a = 0
for i in range(1, m // 2 + 1 * (m % 2 == 1)):
    x, y = v[i], v[m - i]
    d = len(x) - len(y)
    if d < 0:
        d = -d
        x, y = y, x
    c = sorted(list(Counter(x).items()), key=lambda x: x[1])
    p = 0
    for t in c:
        p += t[1] // 2
    a += len(y) + min(p, (d // 2))
a += len(v[0]) // 2 + (len(v[m // 2]) // 2 if m % 2 == 0 else 0)
print(a)

from collections import Counter

n, m = list(map(int, input().split()))
x = [int(i) for i in input().split()]
v = [[] for i in range(m)]
for i in x:
    v[i % m].append(i)
a = 0
for i in range(1, m // 2 + m % 2):
    x, y = v[i], v[m - i]
    d = len(x) - len(y)
    if d < 0:
        d = -d
        x, y = y, x
    c = sorted([p[1] for p in list(Counter(x).items())])
    p = 0
    for t in c:
        p += t // 2
    a += len(y) + min(p, (d // 2))
a += len(v[0]) // 2 + (len(v[m // 2]) // 2 if m % 2 == 0 else 0)
print(a)

-for i in range(1, m // 2 + 1 * (m % 2 == 1)): +for i in range(1, m // 2 + m % 2): -    c = sorted(list(Counter(x).items()), key=lambda x: x[1]) +    c = sorted([p[1] for p in list(Counter(x).items())]) -        p += t[1] // 2 +        p += t // 2