from collections import Counter

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

cntX = Counter(list(map(int, input().split())))



cntMod = Counter()

cntDup = Counter()

for x, c in list(cntX.items()):

    cntMod[x % M] += c

    cntDup[x % M] += c // 2



ans = 0

for n in range(M // 2 + 1):

    m = (M - n) % M

    if m == n:

        ans += cntMod[n] // 2

        continue



    cnt = min(cntMod[n], cntMod[m])

    cntMod[n] -= cnt

    cntMod[m] -= cnt



    ans += cnt

    ans += min(cntMod[n] // 2, cntDup[n]) + min(cntMod[m] // 2, cntDup[m])

print(ans)

from collections import Counter



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

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



dupCnt = Counter()

modCnt = Counter()



for x, c in list(Counter(X).items()):

    x %= M

    dupCnt[x] += c // 2

    modCnt[x] += c



ans = 0

for i in range(M):

    j = M - i

    if i > j:

        break

    if i == j or i == 0:

        ans += modCnt[i] // 2

        continue



    mi = min(modCnt[i], modCnt[j])

    ans += mi



    ans += min((modCnt[i] - mi) // 2, dupCnt[i])

    ans += min((modCnt[j] - mi) // 2, dupCnt[j])



print(ans)

from collections import Counter

N, M = list(map(int, input().split()))
cntX = Counter(list(map(int, input().split())))
cntMod = Counter()
cntDup = Counter()
for x, c in list(cntX.items()):
    cntMod[x % M] += c
    cntDup[x % M] += c // 2
ans = 0
for n in range(M // 2 + 1):
    m = (M - n) % M
    if m == n:
        ans += cntMod[n] // 2
        continue
    cnt = min(cntMod[n], cntMod[m])
    cntMod[n] -= cnt
    cntMod[m] -= cnt
    ans += cnt
    ans += min(cntMod[n] // 2, cntDup[n]) + min(cntMod[m] // 2, cntDup[m])
print(ans)

from collections import Counter

N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
dupCnt = Counter()
modCnt = Counter()
for x, c in list(Counter(X).items()):
    x %= M
    dupCnt[x] += c // 2
    modCnt[x] += c
ans = 0
for i in range(M):
    j = M - i
    if i > j:
        break
    if i == j or i == 0:
        ans += modCnt[i] // 2
        continue
    mi = min(modCnt[i], modCnt[j])
    ans += mi
    ans += min((modCnt[i] - mi) // 2, dupCnt[i])
    ans += min((modCnt[j] - mi) // 2, dupCnt[j])
print(ans)

-cntX = Counter(list(map(int, input().split()))) -cntMod = Counter() -cntDup = Counter() -for x, c in list(cntX.items()): -    cntMod[x % M] += c -    cntDup[x % M] += c // 2 +X = list(map(int, input().split())) +dupCnt = Counter() +modCnt = Counter() +for x, c in list(Counter(X).items()): +    x %= M +    dupCnt[x] += c // 2 +    modCnt[x] += c -for n in range(M // 2 + 1): -    m = (M - n) % M -    if m == n: -        ans += cntMod[n] // 2 +for i in range(M): +    j = M - i +    if i > j: +        break +    if i == j or i == 0: +        ans += modCnt[i] // 2 -    cnt = min(cntMod[n], cntMod[m]) -    cntMod[n] -= cnt -    cntMod[m] -= cnt -    ans += cnt -    ans += min(cntMod[n] // 2, cntDup[n]) + min(cntMod[m] // 2, cntDup[m]) +    mi = min(modCnt[i], modCnt[j]) +    ans += mi +    ans += min((modCnt[i] - mi) // 2, dupCnt[i]) +    ans += min((modCnt[j] - mi) // 2, dupCnt[j])