#include <iostream>
#include <vector>

using namespace std;


void printOneDimensionalArray(unsigned int N, int arr[]){
    for (unsigned int i = 0; i < N; ++i)
    {
        cout << arr[i] << " ";
    }
    cout << endl;
}

int getMaxIdxSel(vector<int> numsToSel, int arr[], unsigned int N)
{
    vector<int> idx;    
    for (int j = 0; j < numsToSel.size(); ++j)  
    {
        for (int i = 0; i < N; ++i)
        {
            if (numsToSel[j] == arr[i])
                idx.push_back(i);
        }
    }

    int max = idx[0];
    for (int i = 0; i < idx.size(); ++i)
    {
        if (max < idx[i])
            max = idx[i];
    }
    return max;
}

int getMinIdxBuy(vector<int> numsToBuy, int arr[], unsigned int N)
{
    vector<int> idx;    
    for (int j = 0; j < numsToBuy.size(); ++j)  
    {
        for (int i = 0; i < N; ++i)
        {
            if (numsToBuy[j] == arr[i])
                idx.push_back(i);
        }
    }

    int min = idx[0];
    for (int i = 0; i < idx.size(); ++i)
    {
        if (min > idx[i])
            min = idx[i];
    }
    return min;
}

int main()
{
    unsigned int N;
    cin >> N;

    unsigned int S;
    cin >> S;

    int arr[N] = {0};
    for (unsigned int i=0; i < N; ++i){
        cin >> arr[i];
    }

    int arrSorted[N] = {0};
    for (unsigned int i=0; i < N; ++i){
        arrSorted[i] = arr[i];
    }

    for (unsigned int i = 0; i < N; ++i)
    {
        for (unsigned int j = i; j < N; ++j)
        {
            if (arrSorted[i] > arrSorted[j])
            {
                int temp = arrSorted[i];
                arrSorted[i] = arrSorted[j];
                arrSorted[j] = temp;
            }
        }
    }

    vector<int> numsToBuy;
    vector<int> numsToSel;
    for (int i = 0; i < (N / 2); ++i)
    {
        if (arrSorted[(N - 1) - i] - arrSorted[i] > S)
        {
            numsToBuy.push_back(arrSorted[i]);
            numsToSel.push_back(arrSorted[(N - 1) - i]);
        }
    }

    int res = 0;
    for (int i = 0; i < numsToBuy.size(); ++i)
    {
        res -= numsToBuy[i];
        // cout << numsToBuy[i] << " ";
    }

    // cout << endl;

    for (int i = 0; i < numsToSel.size(); ++i)
    {
        res += numsToSel[i];
        // cout << numsToSel[i] << " ";
    }
    // cout <<endl;

    int max = getMaxIdxSel(numsToSel, arr, N);
    int min = getMinIdxBuy(numsToBuy, arr, N);
    res -= (max + 1 - min)*S;

    cout << res;
}