#include <bits/stdc++.h>
using namespace std;
long long int a[500001];
long long int n, k;
long long int sum;
long long int finallyHighest, finallyLowest;
long long int daysToH(int num) {
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += max(a[i] - num, 0LL);
  }
  return ans;
}
long long int daysToL(int num) {
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += max(num - a[i], 0LL);
  }
  return ans;
}
long long int hsearch(long long int start, long long int end) {
  if (end - start < 10) {
    for (int i = start; i <= end; i++) {
      if (daysToH(i) <= k) return i;
    }
    assert(0);
  } else {
    long long int mid = (start + end) / 2;
    if (daysToH(mid) > k) {
      return hsearch(mid, end);
    } else {
      return hsearch(start, mid);
    }
  }
}
long long int lsearch(long long int start, long long int end) {
  if (end - start < 10) {
    for (int i = end; i >= start; i--) {
      if (daysToL(i) <= k) return i;
    }
    assert(0);
  } else {
    long long int mid = (start + end) / 2;
    if (daysToL(mid) <= k) {
      return lsearch(mid, end);
    } else {
      return lsearch(start, mid);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a + n);
  if (sum % n == 0) {
    finallyHighest = finallyLowest = sum / n;
  } else {
    finallyLowest = sum / n;
    finallyHighest = finallyLowest + 1;
  }
  long long int highest = hsearch(finallyHighest, a[n - 1]);
  long long int lowest = lsearch(a[0], finallyLowest);
  cout << highest - lowest << endl;
  return 0;
}
