#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
#define int long long

typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const long long mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m;
int x[100010];

int solve() {
    vector<int> md[100010];
    sort(x, x+n);
    int idx = 0;
    while (idx < n) {
        int c = 0;
        while (idx+c < n && x[idx] == x[idx+c]) c++;
        md[x[idx]%m].push_back(c);
        idx += c;
    }
    int res = 0;
    int z = 0;
    for (int i = 0; i < md[0].size(); i++) z += md[0][i];
    res += z / 2;
    if (m % 2 == 0) {
        int h = m / 2;
        z = 0;
        for (int i = 0; i < md[h].size(); i++) z += md[h][i];
        res += z / 2;
    }

    int p[2];
    int sum[2];
    for (int i = 1; i <= m/2; i++) {
        if (i == m-i) break;
        p[0] = p[1] = 0;
        sum[0] = sum[1] = 0;
        for (int j = 0; j < md[i].size(); j++) {
            p[0] += (md[i][j]%2);
            sum[0] += md[i][j];
            res += md[i][j] / 2;
        }
        for (int j = 0; j < md[m-i].size(); j++) {
            p[1] += (md[m-i][j]%2);
            sum[1] += md[m-i][j];
            res += md[m-i][j] / 2;
        }

        int k = (p[0] > p[1] ? 0 : 1);
        res += p[1-k];
        sum[1-k] -= p[1-k];
        p[k] -= p[1-k];
        res += min(p[k], sum[1-k]) / 2;
    }
    return res;
}

void input() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> x[i];
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}

### Prompt

Develop a solution in CPP to the problem described below:

Takahashi is playing with N cards.

The i-th card has an integer X_i on it.

Takahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions:

* The integers on the two cards are the same.
* The sum of the integers on the two cards is a multiple of M.



Find the maximum number of pairs that can be created.

Note that a card cannot be used in more than one pair.

Constraints

* 2≦N≦10^5
* 1≦M≦10^5
* 1≦X_i≦10^5

Input

The input is given from Standard Input in the following format:


N M
X_1 X_2 ... X_N


Output

Print the maximum number of pairs that can be created.

Examples

Input

7 5
3 1 4 1 5 9 2


Output

3


Input

15 10
1 5 6 10 11 11 11 20 21 25 25 26 99 99 99


Output

6

### Response

```cpp
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
#define int long long

typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const long long mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m;
int x[100010];

int solve() {
    vector<int> md[100010];
    sort(x, x+n);
    int idx = 0;
    while (idx < n) {
        int c = 0;
        while (idx+c < n && x[idx] == x[idx+c]) c++;
        md[x[idx]%m].push_back(c);
        idx += c;
    }
    int res = 0;
    int z = 0;
    for (int i = 0; i < md[0].size(); i++) z += md[0][i];
    res += z / 2;
    if (m % 2 == 0) {
        int h = m / 2;
        z = 0;
        for (int i = 0; i < md[h].size(); i++) z += md[h][i];
        res += z / 2;
    }

    int p[2];
    int sum[2];
    for (int i = 1; i <= m/2; i++) {
        if (i == m-i) break;
        p[0] = p[1] = 0;
        sum[0] = sum[1] = 0;
        for (int j = 0; j < md[i].size(); j++) {
            p[0] += (md[i][j]%2);
            sum[0] += md[i][j];
            res += md[i][j] / 2;
        }
        for (int j = 0; j < md[m-i].size(); j++) {
            p[1] += (md[m-i][j]%2);
            sum[1] += md[m-i][j];
            res += md[m-i][j] / 2;
        }

        int k = (p[0] > p[1] ? 0 : 1);
        res += p[1-k];
        sum[1-k] -= p[1-k];
        p[k] -= p[1-k];
        res += min(p[k], sum[1-k]) / 2;
    }
    return res;
}

void input() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> x[i];
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}

```