from collections import Counter



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

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



modGrp = [[] for _ in range(M)]



for x in X:

    modGrp[x % M].append(x)



ans = len(modGrp[0]) // 2

modGrp[0] = []



if M % 2 == 0:

    ans += len(modGrp[M // 2]) // 2

    modGrp[M // 2] = []



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

    S = modGrp[m]

    T = modGrp[M - m]



    if len(S) < len(T):

        S, T = T, S



    cnt = Counter(S)

    dis = 0

    for c in list(cnt.values()):

        while c >= 2 and len(S) - dis * 2 > len(T):

            dis += 1

            c -= 2

            ans += 1



    ans += min(len(T), len(S) - dis * 2)

    modGrp[m] = []

    modGrp[M - m] = []



print(ans)
from collections import Counter, defaultdict



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

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



cntMod = defaultdict(int)

cntDup = defaultdict(int)



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

    cntMod[x % M] += c

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



ans = 0

for m in range(M):

    if m > M // 2:

        break

    n = (M - m) % M



    if n == m:

        ans += cntMod[n] // 2

    else:

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

        ans += mi

        cntMod[n] -= mi

        cntMod[m] -= mi

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

        ans += 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()))
modGrp = [[] for _ in range(M)]
for x in X:
    modGrp[x % M].append(x)
ans = len(modGrp[0]) // 2
modGrp[0] = []
if M % 2 == 0:
    ans += len(modGrp[M // 2]) // 2
    modGrp[M // 2] = []
for m in range(1, M // 2 + 1):
    S = modGrp[m]
    T = modGrp[M - m]
    if len(S) < len(T):
        S, T = T, S
    cnt = Counter(S)
    dis = 0
    for c in list(cnt.values()):
        while c >= 2 and len(S) - dis * 2 > len(T):
            dis += 1
            c -= 2
            ans += 1
    ans += min(len(T), len(S) - dis * 2)
    modGrp[m] = []
    modGrp[M - m] = []
print(ans)

from collections import Counter, defaultdict

N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
cntMod = defaultdict(int)
cntDup = defaultdict(int)
for x, c in list(Counter(X).items()):
    cntMod[x % M] += c
    cntDup[x % M] += c // 2
ans = 0
for m in range(M):
    if m > M // 2:
        break
    n = (M - m) % M
    if n == m:
        ans += cntMod[n] // 2
    else:
        mi = min(cntMod[n], cntMod[m])
        ans += mi
        cntMod[n] -= mi
        cntMod[m] -= mi
        ans += min(cntMod[n] // 2, cntDup[n])
        ans += min(cntMod[m] // 2, cntDup[m])
print(ans)

-from collections import Counter +from collections import Counter, defaultdict -modGrp = [[] for _ in range(M)] -for x in X: -    modGrp[x % M].append(x) -ans = len(modGrp[0]) // 2 -modGrp[0] = [] -if M % 2 == 0: -    ans += len(modGrp[M // 2]) // 2 -    modGrp[M // 2] = [] -for m in range(1, M // 2 + 1): -    S = modGrp[m] -    T = modGrp[M - m] -    if len(S) < len(T): -        S, T = T, S -    cnt = Counter(S) -    dis = 0 -    for c in list(cnt.values()): -        while c >= 2 and len(S) - dis * 2 > len(T): -            dis += 1 -            c -= 2 -            ans += 1 -    ans += min(len(T), len(S) - dis * 2) -    modGrp[m] = [] -    modGrp[M - m] = [] +cntMod = defaultdict(int) +cntDup = defaultdict(int) +for x, c in list(Counter(X).items()): +    cntMod[x % M] += c +    cntDup[x % M] += c // 2 +ans = 0 +for m in range(M): +    if m > M // 2: +        break +    n = (M - m) % M +    if n == m: +        ans += cntMod[n] // 2 +    else: +        mi = min(cntMod[n], cntMod[m]) +        ans += mi +        cntMod[n] -= mi +        cntMod[m] -= mi +        ans += min(cntMod[n] // 2, cntDup[n]) +        ans += min(cntMod[m] // 2, cntDup[m])