#include <bits/stdc++.h>
using namespace std;
static bool DEBUG = false;
vector<long long> m(500005);
int n;
long long k;
int canUp(long long money, int k) {
  for (int i = (0); i < (n); ++i) {
    if (m[i] < money) k -= money - m[i];
    if (k < 0) return false;
  }
  return true;
}
int canDown(long long money, int k) {
  for (int i = (0); i < (n); ++i) {
    if (m[i] > money) k -= m[i] - money;
    if (k < 0) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  if (DEBUG)
    cout << "n"
         << " = " << n << "\n";
  if (DEBUG)
    cout << "k"
         << " = " << k << "\n";
  for (int i = (0); i < (n); ++i) {
    cin >> m[i];
  }
  long long a = 0;
  long long b = 1000000005;
  while (b - a > 1) {
    int money = (a + b) / 2;
    if (canUp(money, k))
      a = money;
    else
      b = money;
  }
  long long worst = a;
  if (DEBUG)
    cout << "worst"
         << " = " << worst << "\n";
  a = 0;
  b = 1000000005;
  while (b - a > 1) {
    int money = (a + b) / 2;
    if (canDown(money, k))
      b = money;
    else
      a = money;
  }
  long long best = b;
  if (DEBUG)
    cout << "best"
         << " = " << best << "\n";
  if (best > worst) {
    cout << best - worst << "\n";
  } else {
    long long middle = (best + worst) / 2;
    if (DEBUG)
      cout << "middle"
           << " = " << middle << "\n";
    long long sub = 0, add = 0;
    for (int i = (0); i < (n); ++i) {
      if (m[i] > middle)
        sub += m[i] - middle;
      else if (m[i] < middle)
        add += middle - m[i];
    }
    long long diff = (add - sub) % n;
    cout << (diff == 0 ? 0 : 1) << "\n";
  }
  return 0;
}
