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 int MAXSIZE = 10000020;
int bufpos;
char buf[MAXSIZE];
void init() {
  buf[fread(buf, 1, MAXSIZE, stdin)] = '\0';
  bufpos = 0;
}
long long readint() {
  bool isneg;
  long long val = 0;
  for (; !isdigit(buf[bufpos]) && buf[bufpos] != '-'; bufpos++)
    ;
  bufpos += (isneg = buf[bufpos] == '-');
  for (; isdigit(buf[bufpos]); bufpos++) val = val * 10 + buf[bufpos] - '0';
  return isneg ? -val : val;
}
char readchar() {
  for (; isspace(buf[bufpos]); bufpos++)
    ;
  return buf[bufpos++];
}
int readstr(char* s) {
  int cur = 0;
  for (; isspace(buf[bufpos]); bufpos++)
    ;
  for (; !isspace(buf[bufpos]); bufpos++) s[cur++] = buf[bufpos];
  s[cur] = '\0';
  return cur;
}
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 100005;
int n;
long long a[maxn], sum[maxn], b[maxn];
int to[maxn], cur;
struct atom {
  long long x, y;
  atom(long long x = 0, long long y = 0) : x(x), y(y) {}
  atom operator+(const atom& rhs) const { return atom(x + rhs.x, y + rhs.y); }
  atom operator-(const atom& rhs) const { return atom(x - rhs.x, y - rhs.y); }
  atom& operator+=(const atom& rhs) {
    x += rhs.x, y += rhs.y;
    return *this;
  }
  atom& operator-=(const atom& rhs) {
    x -= rhs.x, y -= rhs.y;
    return *this;
  }
  bool operator<(const atom& rhs) const {
    return x != rhs.x ? x < rhs.x : y < rhs.y;
  }
};
struct bit1 {
  int n;
  atom a[maxn];
  void init(int n) {
    this->n = n;
    memset(a, 0, sizeof(a));
  }
  void add(int p, atom v) {
    for (; p <= n; p += p & -p) a[p] += v;
  }
  atom query(int p) {
    atom ans = 0;
    for (; p; p -= p & -p) ans += a[p];
    return ans;
  }
} b1;
struct bit2 {
  int n;
  int a[maxn];
  void init(int n) {
    this->n = n;
    memset(a, 0x3f, sizeof(a));
  }
  void add(int p, int v) {
    for (; p <= n; p += p & -p) a[p] = min(a[p], v);
  }
  int query(int p) {
    int ans = maxn;
    for (; p; p -= p & -p) ans = min(ans, a[p]);
    return ans;
  }
} b2;
atom dp[maxn];
long long f[maxn], g[maxn], pre[maxn];
int mn[maxn], fl[maxn], id[maxn];
atom check(long long x) {
  b1.init(cur);
  b2.init(cur);
  atom tot;
  b1.add(to[0], atom(0, 1));
  b2.add(to[0], 0);
  for (int i = 1; i <= n; i++) {
    int p = upper_bound(b + 1, b + cur + 1, sum[i] + x) - b - 1;
    atom qwq = b1.query(p);
    qwq.x = qwq.y * (sum[i] + x) - qwq.x;
    tot += qwq;
    mn[i] = b2.query(p) + 1;
    b1.add(to[i], atom(sum[i], 1));
    b2.add(to[i], i);
  }
  mn[n + 1] = n + 1;
  for (int i = n; i; i--) {
    mn[i] = min(mn[i + 1], mn[i]);
    if (mn[i] > i)
      fl[i] = 1;
    else
      fl[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    fl[i] += fl[i - 1];
    if (fl[i] != fl[i - 1]) id[fl[i]] = i, pre[fl[i]] = sum[i];
  }
  int m = fl[n];
  if (!m) return tot;
  id[m + 1] = n + 1;
  for (int i = 1; i <= m; i++) {
    int u = id[i] - 1;
    long long now = 0;
    f[i] = g[i] = 0;
    while (u > id[i - 1]) {
      now += a[u];
      f[i] = max(f[i], now);
      u--;
    }
    now = 0;
    u = id[i] + 1;
    while (u < id[i + 1]) {
      now += a[u];
      g[i] = max(g[i], now);
      u++;
    }
  }
  long long tat = -sum[id[1] - 1] + f[1];
  atom now(tat, 0);
  atom one(x, 1);
  for (int i = 1; i <= m; i++) {
    dp[i] = now + one + atom(pre[i], 0) + atom(g[i], 0);
    tat = max(tat, -sum[id[i + 1] - 1] + f[i + 1]);
    now = max(now, dp[i] + tat);
  }
  atom ans = dp[m] + tot;
  return ans;
}
int main() {
  init();
  n = readint();
  long long k = readint();
  for (int i = 1; i <= n; i++)
    a[i] = readint(), b[i] = sum[i] = sum[i - 1] + a[i];
  cur = n + 1;
  sort(b + 1, b + cur + 1);
  cur = unique(b + 1, b + cur + 1) - b - 1;
  for (int i = 0; i <= n; i++)
    to[i] = lower_bound(b + 1, b + cur + 1, sum[i]) - b;
  long long l = -1e10, r = 1e10;
  while (l < r) {
    long long mid = l + (r - l) / 2;
    if (check(mid).y >= k)
      r = mid;
    else
      l = mid + 1;
  }
  printf("%lld\n", check(l).x - l * k);
  return 0;
}