#include <bits/stdc++.h>
#define fi first
#define se second
#define MAXN 200010
#define VAL 100002

using namespace std;

pair<pair<int, long long>, pair<int, int>> seg[4*MAXN][2];
pair<bool, bool> pi;
int a[MAXN];

void update(int node, int l, int r, int idx, int val, int u, int t) /// u - da li je elem iz prvog ili iz drugog dela niza
{
    if(l == r){
        seg[node][t].fi.fi += val;
        seg[node][t].fi.se += val * (l - VAL);
        if(!u) seg[node][t].se.fi += val;
        else seg[node][t].se.se += val;
        return;
    }
    int mid = (l+r)/2;
    if(idx <= mid)
        update(2*node, l, mid, idx, val, u, t);
    else
        update(2*node+1, mid+1, r, idx, val, u, t);
    seg[node][t].fi.fi = seg[2*node][t].fi.fi + seg[2*node+1][t].fi.fi;
    seg[node][t].fi.se = seg[2*node][t].fi.se + seg[2*node+1][t].fi.se;
    seg[node][t].se.fi = seg[2*node][t].se.fi + seg[2*node+1][t].se.fi;
    seg[node][t].se.se = seg[2*node][t].se.se + seg[2*node+1][t].se.se;
}

long long query(int node, int l, int r, int k, int t)
{
    if(l == r){
        if(seg[node][t].se.fi > 0) pi.fi = true;
        if(seg[node][t].se.se > 0) pi.se = true;
        return k*(l-VAL);
    }
    if(seg[node][t].fi.fi == k){
        if(seg[node][t].se.fi > 0) pi.fi = true;
        if(seg[node][t].se.se > 0) pi.se = true;
        return seg[node][t].fi.se;
    }
    int mid = (l+r)/2;
    if(seg[2*node+1][t].fi.fi >= k)
        return query(2*node+1, mid+1, r, k, t);
    /*if(seg[2*node+1][t].fi.fi < k)*/
    else{
        if(seg[2*node+1][t].se.fi > 0) pi.fi = true;
        if(seg[2*node+1][t].se.se > 0) pi.se = true;
        return seg[2*node+1][t].fi.se + query(2*node, l, mid, k-seg[2*node+1][t].fi.fi, t);
    }
}

long long query2(int node, int l, int r, int u, int t) /// u = 0 => pi.fi = 0; u = 1 => pi.se = 0
{
    if(l == r){
        return l - VAL;
    }
    int mid = (l+r)/2;
    if(u == 0){
        if(seg[2*node+1][t].se.fi > 0) return query2(2*node+1, mid+1, r, u, t);
        else return query2(2*node, l, mid, u, t);
    }
    else{
        if(seg[2*node+1][t].se.se > 0) return query2(2*node+1, mid+1, r, u, t);
        else return query2(2*node, l, mid, u, t);
    }
}


int main()
{
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }



    update(1, 1, MAXN, VAL + a[0], 1, 0, 0);
    update(1, 1, MAXN, VAL - a[0], 1, 0, 1);
    for(int i = 1; i < n; i++){
        update(1, 1, MAXN, VAL - a[i], 1, 1, 0);
        update(1, 1, MAXN, VAL + a[i], 1, 1, 1);
    }
    long long res = 0;
    for(int i = 0; i < n-1; i++)
    {

        if(i != 0){
            update(1, 1, MAXN, VAL - a[i], -1, 1, 0);
            update(1, 1, MAXN, VAL + a[i], 1, 0, 0);
            update(1, 1, MAXN, VAL + a[i], -1, 1, 1);
            update(1, 1, MAXN, VAL - a[i], 1, 0, 1);
        }
        pi.fi = false; pi.se = false;
        long long q1 = query(1, 1, MAXN, k, 0);

        if(!pi.fi || !pi.se){
            q1 = query(1, 1, MAXN, k-1, 0);
            if(!pi.fi) q1 += query2(1, 1, MAXN, 0, 0);
            else q1 += query2(1, 1, MAXN, 1, 0);
        }
        pi.fi = false; pi.se = false;
        long long q2 = query(1, 1, MAXN, k, 1);
        if(!pi.fi || !pi.se){
            q2 = query(1, 1, MAXN, k-1, 1);
            if(!pi.fi) q2 += query2(1, 1, MAXN, 0, 1);
            else q2 += query2(1, 1, MAXN, 1, 1);
        }
        res = max(res, max(q1, q2));
    }
    cout << res << endl;

    return 0;
}



/*

3 2
5 3 2

*/