#!/usr/bin/env python3 (n, k), w = map(int, input().split()), list(map(int, input().split())), ans, cnt = 0, [0] * k # modulo for x in w: if x % k == 0: ans += 1 else: cnt[x % k] += 1 # pairs for i in range(1, k // 2): x = min(cnt[i], cnt[k - i]) cnt[i] -= x cnt[k - i] -= x ans += x if k % 2 == 0: x = cnt[k // 2] // 2 cnt[k // 2] -= 2 * x ans += x # Left with at most 3 non-empty values, and possibly k/2. ans = {tuple([0] * k): ans} def calc(cnts): if tuple(cnts) in ans: return ans[tuple(cnts)] # Take the number in the set with the lowest count, and add something to it m = min((100, -1), *((cnts[m], m) for m in range(1, k) if cnts[m] > 0))[1] new_cnts, best = cnts[:], 0 new_cnts[m] -= 1 for i in range(1, k): if new_cnts[i] > 0: new_cnts[i] -= 1 v = 0 if m + i != k: new_cnts[(m + i) % k] += 1 else: v += 1 v += calc(new_cnts) if m + i != k: new_cnts[(m + i) % k] -= 1 best = max(best, v) new_cnts[i] += 1 ans[tuple(cnts)] = best return best print(sum(w) // k - calc(cnt))