#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>

using namespace std;

// Headers
string toString (double);
int toInt (string);
double toDouble (string);

int main() {
    int N;
    int M;
    vector<int> A(10000);
    int i;
    int j;
    int b;
    int P;
    int S;
    
    cin >> N;
    cin >> M;
    for (i = 1 ; i <= N ; i += 1) {
        cin >> A[i];
    }
    for (i = 1 ; i <= N ; i += 1) {
        if (A[i] > (double) (M + 1) / 2) {
            A[i] = M - A[i];
        }
    }
    for (i = 1 ; i <= N - 1 ; i += 1) {
        for (j = i + 1 ; j <= N ; j += 1) {
            if (A[i] > A[j]) {
                P = A[i];
                A[i] = A[j];
                A[j] = P;
            }
        }
    }
    P = 0;
    S = 0;
    for (b = 0 ; b <= (double) M / 2 ; b += 1) {
        for (i = 1 ; i <= N ; i += 1) {
            if (A[i] == b) {
                P = P + 1;
            }
        }
        S = S + P * (N - P);
    }
    cout << S << endl;
}

// The following implements type conversion functions.

string toString (double value) { //int also
    stringstream temp;
    temp << value;
    return temp.str();
}

int toInt (string text) {
    return atoi(text.c_str());
}

double toDouble (string text) {
    return atof(text.c_str());
}