Problem: Misha has an array of integers of length n. He wants to choose k different continuous subarrays, so that each element of the array belongs to at least one of the chosen subarrays.

Misha wants to choose the subarrays in such a way that if he calculated the sum of elements for each subarray, and then add up all these sums, the resulting value was maximum possible.

Input

The first line of input contains two integers: n, k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ n·(n + 1) / 2) — the number of elements in the array and the number of different subarrays that must be chosen.

The second line contains n integers ai ( - 50 000 ≤ ai ≤ 50 000) — the elements of the array.

Output

Output one integer — the maximum possible value Misha can get by choosing k different subarrays.

Example

Input

5 4
6 -4 -10 -4 7


Output

11

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e18;
struct Data {
  int l, r;
  long long val;
  Data() {}
  Data(int l, int r, long long val) : l(l), r(r), val(val) {}
  bool operator<(const Data& d) const {
    if (val != d.val) return val > d.val;
    return l == d.l ? r < d.r : l < d.l;
  }
} d[100100];
struct WXHAKIOI {
  long long ans, sum, mnpre, mnsuf;
  WXHAKIOI() { ans = -INF, sum = 0, mnpre = -INF, mnsuf = -INF; }
  WXHAKIOI operator+(const WXHAKIOI wa) const {
    WXHAKIOI ret;
    ret.ans = max(ans, wa.ans);
    ret.ans = max(ret.ans, mnsuf + wa.mnpre);
    ret.mnpre = max(mnpre, sum + wa.mnpre);
    ret.mnsuf = max(wa.mnsuf, mnsuf + wa.sum);
    ret.sum = sum + wa.sum;
    return ret;
  }
} wxh[100100 << 2], wxh2[100100 << 2];
int f[100100], n, a[100100], tp;
long long s[100100], mnpre[100100], mxsuf[100100], K, M, shifu, base, nK, mK,
    val1, val2;
pair<long long, long long> t[100100];
void build(int o, int l, int r) {
  if (l == r) {
    wxh[o].ans = a[l];
    wxh[o].mnpre = wxh[o].mnsuf = wxh[o].ans;
    wxh[o].sum = a[l];
    wxh2[o].ans = -a[l];
    wxh2[o].mnpre = wxh2[o].mnsuf = wxh2[o].ans;
    wxh2[o].sum = -a[l];
    return;
  }
  int mid = l + r >> 1;
  build(o << 1, l, mid);
  build(o << 1 | 1, mid + 1, r);
  wxh[o] = wxh[o << 1] + wxh[o << 1 | 1];
  wxh2[o] = wxh2[o << 1] + wxh2[o << 1 | 1];
}
WXHAKIOI _qry(WXHAKIOI wxh[], int o, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return wxh[o];
  int mid = l + r >> 1;
  if (qr <= mid)
    return _qry(wxh, o << 1, l, mid, ql, qr);
  else if (ql > mid)
    return _qry(wxh, o << 1 | 1, mid + 1, r, ql, qr);
  else
    return _qry(wxh, o << 1, l, mid, ql, qr) +
           _qry(wxh, o << 1 | 1, mid + 1, r, ql, qr);
}
long long qry(int ql, int qr) {
  return max(_qry(wxh, 1, 1, n, ql, qr).ans, _qry(wxh2, 1, 1, n, ql, qr).ans);
}
void cover(int l, int r) { f[l]++, f[r + 1]--; }
void sol(int l, int r) {
  if (l == r) return;
  int mid = l + r >> 1;
  sol(l, mid), sol(mid + 1, r);
  for (int i = mid + 1, j = l - 1; i <= r; ++i) {
    while (j < mid && t[j + 1].first <= t[i].first - M) j++;
    shifu += j - l + 1;
  }
  inplace_merge(t + l, t + mid + 1, t + r + 1);
}
long long cal(long long mid) {
  M = mid, shifu = 0;
  for (int i = 0; i <= n; ++i) t[i] = pair<long long, long long>(s[i], i);
  sol(0, n);
  return shifu;
}
long long getcal(long long Z) {
  long long l = -(long long)5e9, r = (long long)5e9, ans = 0;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (cal(mid) >= Z)
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  return ans;
}
void deal(int l, int r) {
  if (l == r) return;
  long long mid = l + r >> 1, mn = 1 << 30, z = 0;
  deal(l, mid), deal(mid + 1, r);
  for (int i = mid + 1, j = l - 1; i <= r; ++i) {
    while (j < mid && t[j + 1].first <= t[i].first - (val2 + 1))
      j++, mn = min(mn, t[j].second), z -= t[j].first;
    base += (long long)(j - l + 1) * t[i].first + z;
    if (j >= l) cover(mn + 1, t[i].second);
  }
  mn = 1 << 30;
  for (int i = mid + 1, j = l - 1, k = l - 1; i <= r; ++i) {
    while (j < mid && t[j + 1].first <= t[i].first - val2)
      j++, mn = min(mn, t[j].second);
    while (k < mid && t[k + 1].first < t[i].first - val2) k++;
    int cnt = j - k;
    if (cnt) {
      if (nK >= cnt) {
        nK -= cnt, cnt = 0;
        cover(mn + 1, t[i].second);
      } else if (nK) {
        cnt -= nK, mn = 1 << 30;
        for (int z = k + 1; z <= k + nK; ++z) mn = min(mn, t[z].second);
        nK = 0;
        cover(mn + 1, t[i].second);
      }
      while (tp < min((long long)n, K) && cnt)
        d[++tp] = Data(t[k + (j - k - cnt + 1)].second + 1, t[i].second, val2),
        cnt--;
    }
  }
  if (val1 != val2) {
    for (int i = mid + 1, j = l - 1, k = l - 1; i <= r; ++i) {
      while (j < mid && t[j + 1].first <= t[i].first - (val1 + 1)) j++;
      while (k < mid && t[k + 1].first <= t[i].first - val2) k++;
      for (int z = k + 1; z <= j; ++z)
        d[++tp] = Data(t[z].second + 1, t[i].second, t[i].first - t[z].first);
    }
    for (int i = mid + 1, j = l - 1, k = l - 1; i <= r; ++i) {
      while (j < mid && t[j + 1].first <= t[i].first - val1) j++;
      while (k < mid && t[k + 1].first < t[i].first - val1) k++;
      int cnt = j - k;
      while (mK && cnt)
        d[++tp] = Data(t[k + (j - k - cnt + 1)].second + 1, t[i].second, val1),
        cnt--, mK--;
    }
  }
  inplace_merge(t + l, t + mid + 1, t + r + 1);
}
set<long long> pos;
multiset<long long> lens, mcfx;
long long ans = -(long long)9e18, sum;
int cdsf[100100];
void ins(int l, int r) {
  if (l + 1 > r - 1) return;
  long long z = qry(l + 1, r - 1);
  lens.insert(z), sum += z;
}
void era(int l, int r) {
  if (l + 1 > r - 1) return;
  long long z = qry(l + 1, r - 1);
  if (mcfx.count(z)) {
    mcfx.erase(mcfx.find(z));
  } else {
    if (!lens.count(z)) exit(-1);
    lens.erase(lens.find(z)), sum -= z;
    if (mcfx.size()) {
      z = *mcfx.rbegin();
      mcfx.erase(mcfx.find(z));
      sum += z;
      lens.insert(z);
    }
  }
}
void get(long long& ans, long long base, int need) {
  if (pos.size() < need) return;
  if (need == 0) {
    if (pos.size()) return;
    ans = max(ans, base);
    return;
  }
  while (lens.size() > need - 1) {
    long long xueyuan = *lens.begin();
    sum -= xueyuan;
    lens.erase(lens.find(xueyuan));
    mcfx.insert(xueyuan);
  }
  int l = *pos.begin(), r = *pos.rbegin();
  ans = max(ans, base - mnpre[l - 1] + mxsuf[r] + sum);
}
int main() {
  scanf("%d%lld", &n, &K);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), s[i] = s[i - 1] + a[i];
  build(1, 1, n);
  mnpre[0] = 0, mxsuf[n + 1] = -INF;
  for (int i = 1; i <= n; ++i) mnpre[i] = min(mnpre[i - 1], s[i]);
  for (int i = n; i >= 1; --i) mxsuf[i] = max(mxsuf[i + 1], s[i]);
  if (K > n) {
    val1 = getcal(K);
    val2 = getcal(K - n);
    nK = K - n - cal(val2 + 1);
    mK = K - cal(val1 + 1);
    base += nK * val2;
    for (int i = 0; i <= n; ++i) t[i] = pair<long long, long long>(s[i], i);
    deal(0, n);
  } else {
    val1 = getcal(K);
    val2 = INF;
    nK = 0, mK = K - cal(val1 + 1);
    for (int i = 0; i <= n; ++i) t[i] = pair<long long, long long>(s[i], i);
    deal(0, n);
  }
  sort(d + 1, d + tp + 1);
  for (int i = 1; i <= n; ++i) f[i] += f[i - 1];
  for (int i = 1, lst = -1; i <= n; ++i)
    if (!f[i]) {
      pos.insert(i);
      if (lst != -1) ins(lst, i);
      lst = i;
    }
  for (int i = 1; i <= tp; ++i) {
    get(ans, base, tp + 1 - i);
    int l = d[i].l, r = d[i].r, cesf = 0;
    auto it = pos.lower_bound(l), xt = it;
    while (it != pos.end() && *it <= r) cdsf[++cesf] = *it++;
    if (it != pos.end() && xt != pos.begin() && cesf >= 1) ins(*prev(xt), *it);
    if (cesf >= 1 && xt != pos.begin()) era(*prev(xt), cdsf[1]);
    if (cesf >= 1 && it != pos.end()) era(cdsf[cesf], *it);
    for (int j = 1; j < cesf; ++j) era(cdsf[j], cdsf[j + 1]);
    for (int j = 1; j <= cesf; ++j) pos.erase(cdsf[j]);
    base += d[i].val;
  }
  get(ans, base, 0);
  printf("%lld", ans);
}