import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B349 solver = new B349();
        solver.solve(1, in, out);
        out.close();
    }

    static class B349 {
        Number[][] memo;
        int V;
        int[] a = new int[10];

        Number dp(int cash, int on) {
            if (memo[cash][on] != null) return memo[cash][on];
            if (on == 0 || cash == 0) return new Number();
            Number best = new Number();
            if (cash >= a[on])
                best = best.add(on, dp(cash - a[on], on));
            Number drop = dp(cash, on - 1);
            if (drop.compareTo(best) > 0)
                best = drop;
            return memo[cash][on] = best;
        }

        public void solve(int testNumber, FastScanner s, PrintWriter out) {
            V = s.nextInt();
            for (int i = 1; i <= 9; i++)
                a[i] = s.nextInt();
            memo = new Number[V + 1][10];
            Number ans = dp(V, 9);
            if (ans.len == 0)
                out.println(-1);
            else {
                out.println(ans);
            }
        }

        class Number implements Comparable<Number> {
            int[] counts;
            int len = 0;

            public Number() {
                counts = new int[10];
            }

            public Number(int[] nums, int len) {
                counts = new int[10];
                for (int i = 1; i < nums.length; i++)
                    counts[i] = nums[i];
                this.len = len;
            }

            Number add(int k, Number NN) {
                int[] ncount = new int[10];
                for (int i = 1; i <= 9; i++) {
                    ncount[i] = counts[i] + NN.counts[i];
                }
                ncount[k]++;
                return new Number(ncount, len + NN.len + 1);
            }

            public int compareTo(Number NN) {
                if (len != NN.len) return len - NN.len;
                for (int i = 9; i >= 1; i--) {
                    if (counts[i] != NN.counts[i]) return counts[i] - NN.counts[i];
                }
                return 0;
            }

            public String toString() {
                String ret = "";
                for (int i = 9; i >= 1; i--)
                    for (int j = 0; j < counts[i]; j++)
                        ret += i;
                return ret;
            }

        }

    }

    static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

    }
}


import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.InputMismatchException;

public class B349 {

	static class Solver {

		int V, cost[] = new int[10];
		int ans[];

		void solve(FastScanner s, PrintWriter out) {
			V = s.nextInt();
			for (int i = 1; i <= 9; i++)
				cost[i] = s.nextInt();

			int min = 9;
			for(int i = 8; i >= 1; i--)
				if(cost[i] < cost[min]) min = i;

			if(V < cost[min]) { out.println(-1); return; }

			int len = V / cost[min];
			Arrays.fill(ans = new int[len], min);

			V -= len * cost[min];
			int dig = 9;
			for(int i = 0; i < len; i++) {
				// refund
				V += cost[min];
				while(V < cost[dig]) dig--;
				// put down the most expensive digit we can
				ans[i] = dig;
				V -= cost[dig];
			}

			StringBuilder res = new StringBuilder();
			Arrays.stream(ans).forEach(x -> res.append(x));
			out.println(res.toString());

		}

	}

	public static void main(String[] args) {

		FastScanner s = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		new Solver().solve(s, out);

		out.close();
		s.close();

	}

	static class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
		}

		public FastScanner(File f) throws FileNotFoundException {
			this(new FileInputStream(f));
		}

		public FastScanner(String s) {
			this.stream = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));
		}

		void close() {
			try {
				stream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}

		// Jacob Garbage

		public int[] nextIntArray(int N) {
			int[] ret = new int[N];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextInt();
			return ret;
		}

		public int[][] next2DIntArray(int N, int M) {
			int[][] ret = new int[N][];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextIntArray(M);
			return ret;
		}

		public long[] nextLongArray(int N) {
			long[] ret = new long[N];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextLong();
			return ret;
		}

		public long[][] next2DLongArray(int N, int M) {
			long[][] ret = new long[N][];
			for (int i = 0; i < N; i++)
				ret[i] = nextLongArray(M);
			return ret;
		}

		public double[] nextDoubleArray(int N) {
			double[] ret = new double[N];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextDouble();
			return ret;
		}

		public double[][] next2DDoubleArray(int N, int M) {
			double[][] ret = new double[N][];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextDoubleArray(M);
			return ret;
		}

	}

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Collections;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B349 solver = new B349();
        solver.solve(1, in, out);
        out.close();
    }

    static class B349 {
        int bucket;

        public void solve(int testNumber, FastScanner s, PrintWriter out) {
            bucket = s.nextInt();
            ArrayList<Number> digs = new ArrayList<>();
            for (int i = 1; i <= 9; i++)
                digs.add(new Number(i, s.nextInt()));
            StringBuilder o = new StringBuilder("");
            while (!digs.isEmpty()) {
                Collections.sort(digs);
                Number cur = digs.remove(0);
                if (cur.cost > bucket) break;
                int draw = bucket / cur.cost;
                bucket -= draw * cur.cost;
                for (int i = 0; i < draw; i++)
                    o.append(cur.val);
            }
            if (o.length() == 0)
                out.println(-1);
            else
                out.println(o);
        }

        class Number implements Comparable<Number> {
            int val;
            int cost;

            public Number(int v, int c) {
                val = v;
                cost = c;
            }

            public int compareTo(Number N) {
                if (bucket / cost != bucket / N.cost) return bucket / N.cost - bucket / cost;
                return N.val - val;
            }

        }

    }

    static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.AbstractCollection;
import java.util.PriorityQueue;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B349 solver = new B349();
        solver.solve(1, in, out);
        out.close();
    }

    static class B349 {
        public void solve(int testNumber, FastScanner s, PrintWriter out) {
            int bucket = s.nextInt();
            PriorityQueue<Number> digs = new PriorityQueue<>();
            for (int i = 1; i <= 9; i++)
                digs.add(new Number(i, s.nextInt()));
            StringBuilder o = new StringBuilder("");
            while (!digs.isEmpty()) {
                Number cur = digs.poll();
                if (cur.cost > bucket) break;
                int draw = bucket / cur.cost;
                bucket -= draw * cur.cost;
                for (int i = 0; i < draw; i++)
                    o.append(cur.val);
            }
            if (o.length() == 0)
                out.println(-1);
            else
                out.println(o);
        }

        class Number implements Comparable<Number> {
            int val;
            int cost;

            public Number(int v, int c) {
                val = v;
                cost = c;
            }

            public int compareTo(Number N) {
                if (cost != N.cost) return cost - N.cost;
                return N.val - val;
            }

        }

    }

    static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B349 solver = new B349();
        solver.solve(1, in, out);
        out.close();
    }

    static class B349 {
        Number[][] memo;
        int V;
        int[] a = new int[10];

        Number dp(int cash, int on) {
            if (memo[cash][on] != null) return memo[cash][on];
            if (on == 0 || cash == 0) return new Number();
            Number best = new Number();
            if (cash >= a[on])
                best = best.add(on).add(dp(cash - a[on], on));
            Number drop = dp(cash, on - 1);
            if (drop.compareTo(best) > 0)
                best = drop;
            return memo[cash][on] = best;
        }

        public void solve(int testNumber, FastScanner s, PrintWriter out) {
            V = s.nextInt();
            for (int i = 1; i <= 9; i++)
                a[i] = s.nextInt();
            memo = new Number[V + 1][10];
            Number ans = dp(V, 9);
            if (ans.len == 0)
                out.println(-1);
            else {
                out.println(ans);
            }
        }

        class Number implements Comparable<Number> {
            int[] counts;
            int len = 0;

            public Number() {
                counts = new int[10];
            }

            public Number(int[] nums, int len) {
                counts = new int[10];
                for (int i = 1; i < nums.length; i++)
                    counts[i] = nums[i];
                this.len = len;
            }

            Number add(int dig) {
                counts[dig]++;
                Number ret = new Number(counts, len + 1);
                counts[dig]--;
                return ret;
            }

            Number add(Number NN) {
                int[] ncount = new int[10];
                for (int i = 1; i <= 9; i++) {
                    ncount[i] = counts[i] + NN.counts[i];
                }
                return new Number(ncount, len + NN.len);
            }

            public int compareTo(Number NN) {
                if (len != NN.len) return len - NN.len;
                for (int i = 9; i >= 1; i--) {
                    if (counts[i] != NN.counts[i]) return counts[i] - NN.counts[i];
                }
                return 0;
            }

            public String toString() {
                String ret = "";
                for (int i = 9; i >= 1; i--)
                    for (int j = 0; j < counts[i]; j++)
                        ret += i;
                return ret;
            }

        }

    }

    static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

    }
}


import java.util.*;
import javax.swing.JOptionPane;

public class Solution {
	public static int ara[ ] = new int[11];
	public static void main(String args[])
	{
		Scanner in = new Scanner(System.in);
		int v = in.nextInt();
		for(int i = 1;i<=9;i++)ara[i] = in.nextInt();

		int maxdig = 0,num=-1;
		for(int i =9;i>=1;i--)
		{
			if(v/ara[i]>maxdig){
				maxdig = v/ara[i];
				num = i;
			}
		}
		if(num==-1){
			System.out.print(-1);return;
		}

		int timer = 10;
		while(timer-->0)
		{
			int mx=0;num = -1;
			for(int i =9;i>=1;i--)
			{
				if(v/ara[i]>mx){
					mx = v/ara[i];
					num = i;
				}
			}
			for(int i =1;i<=mx;i++)System.out.print(num);
			if(num!=-1)v = v - mx*ara[num];
		}
	}

}


//You are so slow... JAVA

import java.util.*;
import javax.swing.JOptionPane;

public class Solution {
	public static void main(String args[])
	{
		int ara[ ] = new int[11];
		Scanner in = new Scanner(System.in);
		int v = in.nextInt();
		for(int i = 1;i<=9;i++)ara[i] = in.nextInt();

		int maxdig = 0,num=10000000;
		for(int i =9;i>=1;i--)
		{
			if(v/ara[i]>maxdig){
				maxdig = v/ara[i];
			}
			if(ara[i]<num)num=ara[i];
		}
		if(maxdig==0){
			System.out.print(-1);return;
		}
//		System.out.println(maxdig);
		int i = 9;

		while(maxdig>0)
		{
			int newv = v - ara[i];
			if(newv<0)
			{
				i--;
				continue;
			}
			if(newv/num==maxdig-1)
			{
				v = newv;
				System.out.printf("%d",i);
				maxdig--;
			}
		}
	}

}


import java.util.*;
import javax.swing.JOptionPane;

public class Solution {
	public static int ara[ ] = new int[11];
	public static void main(String args[])
	{
		Scanner in = new Scanner(System.in);
		int v = in.nextInt();
		for(int i = 1;i<=9;i++)ara[i] = in.nextInt();

		int maxdig = 0,num=10000000;
		for(int i =9;i>=1;i--)
		{
			if(v/ara[i]>maxdig){
				maxdig = v/ara[i];
			}
			if(ara[i]<num)num=ara[i];
		}
		if(maxdig==0){
			System.out.print(-1);return;
		}
//		System.out.println(maxdig);

		while(maxdig>0)
		{
//			System.out.println(v);
			for(int i =9;i>=1;i--)
			{
				int newv = v - ara[i];
				if(newv<0)continue;
				if(newv/num==maxdig-1)
				{
					v = newv;
					System.out.print(i);
					break;
				}
			}
			maxdig--;
		}
	}

}


//You are so slow... JAVA

import java.util.*;
import javax.swing.JOptionPane;

public class Solution {
	public static void main(String args[])
	{
		int ara[ ] = new int[11];
		Scanner in = new Scanner(System.in);
		int v = in.nextInt();
		for(int i = 1;i<=9;i++)ara[i] = in.nextInt();

		int maxdig = 0,num=10000000;
		for(int i =9;i>=1;i--)
		{
			if(v/ara[i]>maxdig){
				maxdig = v/ara[i];
			}
			if(ara[i]<num)num=ara[i];
		}
		if(maxdig==0){
			System.out.print(-1);return;
		}
//		System.out.println(maxdig);
		int i = 9;

		while(maxdig>0)
		{
			int newv = v - ara[i];
			if(newv<0)
			{
				i--;
				continue;
			}
			if(newv/num==maxdig-1)
			{
				v = newv;
				System.out.printf("%d",i);
				maxdig--;
			}
			else i--;
		}
	}

}


#include <bits/stdc++.h>
#include <iostream>

using namespace std;
typedef unsigned long long ull;

ull n, k, lo, hi, mid, sum1, sum2, ans1, ans2;
int c[500010];

int main() {
	cin >> n >> k;
	for(int i=0; i<n; i++) {
		cin >> c[i];
	}
	sort(c, c+n);
	lo = c[0]-1;
	hi = c[n-1]+1;
	while(lo < hi-1) {

		mid = lo + (hi-lo)/2;
		sum1 = 0;
		sum2 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] <= mid) {
				sum1 += mid - c[i];
			} else {
				sum2 += c[i] - mid;
			}
		}
		//cout << sum1 << " " << sum2 << endl;
		if (sum1 == sum2) {
			if(k >= sum1) {
				cout << 0 << endl;
				return 0;
			}
			lo = mid;
		} else if (sum1 < sum2) {
			lo = mid;
		} else {
			hi = mid;
		}
	}

	sum1 = 0;
	sum2 = 0;
	for(int i=0; i<n; i++) {
		if(c[i] <= lo) {
			sum1 += lo - c[i];
		} else {
			sum2 += c[i] - hi;
		}
	}
	if (k >= max(sum1, sum2)) {
		cout << 1 << endl;
		return 0;
	}

	//cout << "hi" << endl;

	lo=c[0]-1;
	hi=c[n-1]+1;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum1 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] < mid) {
				sum1 += mid - c[i];
			} else {
				break;
			}
		}
		if(sum1 <= k) {
			lo = mid;
		} else {
			hi = mid;
		}
	}
	ans1 = lo;

	lo=c[0]-1;
	hi=c[n-1]+1;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum2 = 0;
		for(int i=n-1; i>=0; i--) {
			if(c[i] > mid) {
				sum2 += c[i] - mid;
			} else {
				break;
			}
		}
		if(sum2 <= k) {
			hi = mid;
		} else {
			lo = mid;
		}
	}
	ans2 = hi;

	cout << ans2 - ans1 << endl;
}


#include <bits/stdc++.h>
#include <iostream>

using namespace std;
typedef unsigned long long ull;

ull n, k, lo, hi, mid, sum1, sum2, ans1, ans2;
int c[500010];

int main() {
	cin >> n >> k;
	for(int i=0; i<n; i++) {
		cin >> c[i];
	}
	sort(c, c+n);
	lo = c[0];
	hi = c[n-1]+2;
	while(lo < hi-1) {

		mid = lo + (hi-lo)/2;
		sum1 = 0;
		sum2 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] <= mid) {
				sum1 += mid - c[i];
			} else {
				sum2 += c[i] - mid;
			}
		}
		//cout << sum1 << " " << sum2 << endl;
		if (sum1 == sum2) {
			if(k >= sum1) {
				cout << 0 << endl;
				return 0;
			}
			lo = mid;
		} else if (sum1 < sum2) {
			lo = mid;
		} else {
			hi = mid;
		}
	}

	sum1 = 0;
	sum2 = 0;
	for(int i=0; i<n; i++) {
		if(c[i] <= lo) {
			sum1 += lo - c[i];
		} else {
			sum2 += c[i] - hi;
		}
	}
	if (k >= max(sum1, sum2)) {
		cout << 1 << endl;
		return 0;
	}

	//cout << "hi" << endl;

	lo=c[0];
	hi=c[n-1]+2;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum1 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] < mid) {
				sum1 += mid - c[i];
			} else {
				break;
			}
		}
		if(sum1 <= k) {
			lo = mid;
		} else {
			hi = mid;
		}
	}
	ans1 = lo;

	lo=c[0];
	hi=c[n-1]+2;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum2 = 0;
		for(int i=n-1; i>=0; i--) {
			if(c[i] > mid) {
				sum2 += c[i] - mid;
			} else {
				break;
			}
		}
		if(sum2 <= k) {
			hi = mid;
		} else {
			lo = mid;
		}
	}
	ans2 = hi;

	cout << ans2 - ans1 << endl;
}


#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int n, k, lo, hi, mid, sum1, sum2, ans1, ans2;
int c[500010];

int main() {
	cin >> n >> k;
	for(int i=0; i<n; i++) {
		cin >> c[i];
	}
	lo = 0;
	hi = 1000000001;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum1 = 0;
		sum2 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] <= mid) {
				sum1 += mid - c[i];
			} else {
				sum2 += c[i] - mid;
			}
		}
		if (sum1 <= sum2) {
			lo = mid;
		} else {
			hi = mid;
		}
	}
	if (sum1 == sum2 && k >= sum1) {
		cout << 0 << endl;
		return 0;
	} else {
		sum1 = 0;
		sum2 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] <= lo) {
				sum1 += lo - c[i];
			} else {
				sum2 += c[i] - hi;
			}
		}
		if (k >= max(sum1, sum2)) {
			cout << 1 << endl;
			return 0;
		}
	}

	lo=0;
	hi=1000000001;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum1 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] < mid) {
				sum1 += mid - c[i];
			}
		}
		if(sum1 <= k) {
			lo = mid;
		} else {
			hi = mid;
		}
	}
	ans1 = lo;

	lo=0;
	hi=1000000001;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum2 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] > mid) {
				sum2 += c[i] - mid;
			}
		}
		if(sum2 <= k) {
			hi = mid;
		} else {
			lo = mid;
		}
	}
	ans2 = hi;

	cout << ans2 - ans1 << endl;
}


#include <bits/stdc++.h>
#include <iostream>

using namespace std;
typedef unsigned long long ull;

ull n, k, lo, hi, mid, sum1, sum2, ans1, ans2;
int c[500010];

int main() {
	cin >> n >> k;
	for(int i=0; i<n; i++) {
		cin >> c[i];
	}
	lo = 0;
	hi = 1000000001;
	while(lo < hi-1) {

		mid = lo + (hi-lo)/2;
		sum1 = 0;
		sum2 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] <= mid) {
				sum1 += mid - c[i];
			} else {
				sum2 += c[i] - mid;
			}
		}
		//cout << sum1 << " " << sum2 << endl;
		if (sum1 <= sum2) {
			lo = mid;
		} else {
			hi = mid;
		}
	}

	sum1 = 0;
	sum2 = 0;
	for(int i=0; i<n; i++) {
		if(c[i] <= lo) {
			sum1 += lo - c[i];
		} else {
			sum2 += c[i] - lo;
		}
	}
	if (sum1 == sum2 && k >= sum1) {
		cout << 0 << endl;
		return 0;
	}

	sum1 = 0;
	sum2 = 0;
	for(int i=0; i<n; i++) {
		if(c[i] <= lo) {
			sum1 += lo - c[i];
		} else {
			sum2 += c[i] - hi;
		}
	}
	if (k >= max(sum1, sum2)) {
		cout << 1 << endl;
		return 0;
	}

	//cout << "hi" << endl;

	lo=0;
	hi=1000000001;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum1 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] < mid) {
				sum1 += mid - c[i];
			}
		}
		if(sum1 <= k) {
			lo = mid;
		} else {
			hi = mid;
		}
	}
	ans1 = lo;

	lo=0;
	hi=1000000001;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum2 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] > mid) {
				sum2 += c[i] - mid;
			}
		}
		if(sum2 <= k) {
			hi = mid;
		} else {
			lo = mid;
		}
	}
	ans2 = hi;

	cout << ans2 - ans1 << endl;
}


#include <bits/stdc++.h>
#include <iostream>

using namespace std;
typedef unsigned long long ull;

ull n, k, lo, hi, mid, sum1, sum2, ans1, ans2;
int c[500010];

int main() {
	cin >> n >> k;
	for(int i=0; i<n; i++) {
		cin >> c[i];
	}
	sort(c, c+n);
	lo = c[0];
	hi = c[n-1]+1;
	while(lo < hi-1) {

		mid = lo + (hi-lo)/2;
		sum1 = 0;
		sum2 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] <= mid) {
				sum1 += mid - c[i];
			} else {
				sum2 += c[i] - mid;
			}
		}
		//cout << sum1 << " " << sum2 << endl;
		if (sum1 == sum2) {
			if(k >= sum1) {
				cout << 0 << endl;
				return 0;
			}
			lo = mid;
		} else if (sum1 < sum2) {
			lo = mid;
		} else {
			hi = mid;
		}
	}

	sum1 = 0;
	sum2 = 0;
	for(int i=0; i<n; i++) {
		if(c[i] <= lo) {
			sum1 += lo - c[i];
		} else {
			sum2 += c[i] - hi;
		}
	}
	if (k >= max(sum1, sum2)) {
		cout << 1 << endl;
		return 0;
	}

	//cout << "hi" << endl;

	lo=c[0];
	hi=c[n-1]+1;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum1 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] < mid) {
				sum1 += mid - c[i];
			} else {
				break;
			}
		}
		if(sum1 <= k) {
			lo = mid;
		} else {
			hi = mid;
		}
	}
	ans1 = lo;

	lo=c[0];
	hi=c[n-1]+1;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum2 = 0;
		for(int i=n-1; i>=0; i--) {
			if(c[i] > mid) {
				sum2 += c[i] - mid;
			} else {
				break;
			}
		}
		if(sum2 <= k) {
			hi = mid;
		} else {
			lo = mid;
		}
	}
	ans2 = hi;

	cout << ans2 - ans1 << endl;
}


#include <bits/stdc++.h>
#include <iostream>

using namespace std;
typedef long long ll;

ll n, k, lo, hi, mid, sum1, sum2, ans1, ans2;
int c[500010];

int main() {
	cin >> n >> k;
	for(int i=0; i<n; i++) {
		cin >> c[i];
	}
	sort(c, c+n);
	// lo = c[0]-1;
	// hi = c[n-1]+1;
	// while(lo < hi-1) {

	// 	mid = lo + (hi-lo)/2;
	// 	sum1 = 0;
	// 	sum2 = 0;
	// 	for(int i=0; i<n; i++) {
	// 		if(c[i] <= mid) {
	// 			sum1 += mid - c[i];
	// 		} else {
	// 			sum2 += c[i] - mid;
	// 		}
	// 	}
	// 	//cout << sum1 << " " << sum2 << endl;
	// 	if (sum1 == sum2) {
	// 		if(k >= sum1) {
	// 			cout << 0 << endl;
	// 			return 0;
	// 		}
	// 		lo = mid;
	// 	} else if (sum1 < sum2) {
	// 		lo = mid;
	// 	} else {
	// 		hi = mid;
	// 	}
	// }

	// sum1 = 0;
	// sum2 = 0;
	// for(int i=0; i<n; i++) {
	// 	if(c[i] <= lo) {
	// 		sum1 += lo - c[i];
	// 	} else {
	// 		sum2 += c[i] - hi;
	// 	}
	// }
	// if (k >= max(sum1, sum2)) {
	// 	cout << 1 << endl;
	// 	return 0;
	// }

	//cout << "hi" << endl;

	lo=c[0]-1;
	hi=c[n-1]+1;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum1 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] < mid) {
				sum1 += mid - c[i];
			} else {
				break;
			}
		}
		if(sum1 <= k) {
			lo = mid;
		} else {
			hi = mid;
		}
	}
	ans1 = lo;

	lo=c[0]-1;
	hi=c[n-1]+1;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum2 = 0;
		for(int i=n-1; i>=0; i--) {
			if(c[i] > mid) {
				sum2 += c[i] - mid;
			} else {
				break;
			}
		}
		if(sum2 <= k) {
			hi = mid;
		} else {
			lo = mid;
		}
	}
	ans2 = hi;

	if(ans1 - ans2 >= -1) {
		cout << (accumulate(c, c+n, 0ll) % n > 0) << endl;
		return 0;
	}
	cout << ans2 - ans1 << endl;
}


#include <bits/stdc++.h>
#include <iostream>

using namespace std;
typedef unsigned long long ull;

ull n, k, lo, hi, mid, sum1, sum2, ans1, ans2;
int c[500010];

int main() {
	cin >> n >> k;
	for(int i=0; i<n; i++) {
		cin >> c[i];
	}
	sort(c, c+n);
	lo = 0;
	hi = 1000000001;
	while(lo < hi-1) {

		mid = lo + (hi-lo)/2;
		sum1 = 0;
		sum2 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] <= mid) {
				sum1 += mid - c[i];
			} else {
				sum2 += c[i] - mid;
			}
		}
		//cout << sum1 << " " << sum2 << endl;
		if (sum1 == sum2) {
			if(k >= sum1) {
				cout << 0 << endl;
				return 0;
			}
			lo = mid;
		} else if (sum1 < sum2) {
			lo = mid;
		} else {
			hi = mid;
		}
	}

	sum1 = 0;
	sum2 = 0;
	for(int i=0; i<n; i++) {
		if(c[i] <= lo) {
			sum1 += lo - c[i];
		} else {
			sum2 += c[i] - hi;
		}
	}
	if (k >= max(sum1, sum2)) {
		cout << 1 << endl;
		return 0;
	}

	//cout << "hi" << endl;

	lo=0;
	hi=1000000001;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum1 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] < mid) {
				sum1 += mid - c[i];
			} else {
				break;
			}
		}
		if(sum1 <= k) {
			lo = mid;
		} else {
			hi = mid;
		}
	}
	ans1 = lo;

	lo=0;
	hi=1000000001;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum2 = 0;
		for(int i=n-1; i>=0; i--) {
			if(c[i] > mid) {
				sum2 += c[i] - mid;
			} else {
				break;
			}
		}
		if(sum2 <= k) {
			hi = mid;
		} else {
			lo = mid;
		}
	}
	ans2 = hi;

	cout << ans2 - ans1 << endl;
}


#include <bits/stdc++.h>
#include <iostream>

using namespace std;
typedef unsigned long long ull;

ull n, k, lo, hi, mid, sum1, sum2, ans1, ans2;
int c[500010];

int main() {
	cin >> n >> k;
	for(int i=0; i<n; i++) {
		cin >> c[i];
	}
	lo = 0;
	hi = 1000000001;
	while(lo < hi-1) {

		mid = lo + (hi-lo)/2;
		sum1 = 0;
		sum2 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] <= mid) {
				sum1 += mid - c[i];
			} else {
				sum2 += c[i] - mid;
			}
		}
		cout << sum1 << " " << sum2 << endl;
		if (sum1 <= sum2) {
			lo = mid;
		} else {
			hi = mid;
		}
	}

	//cout << lo << " " << hi << endl;
	if (sum1 == sum2 && k >= sum1) {
		cout << 0 << endl;
		return 0;
	} else {
		sum1 = 0;
		sum2 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] <= lo) {
				sum1 += lo - c[i];
			} else {
				sum2 += c[i] - hi;
			}
		}
		if (k >= max(sum1, sum2)) {
			cout << 1 << endl;
			return 0;
		}
	}

	//cout << "hi" << endl;

	lo=0;
	hi=1000000001;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum1 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] < mid) {
				sum1 += mid - c[i];
			}
		}
		if(sum1 <= k) {
			lo = mid;
		} else {
			hi = mid;
		}
	}
	ans1 = lo;

	lo=0;
	hi=1000000001;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum2 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] > mid) {
				sum2 += c[i] - mid;
			}
		}
		if(sum2 <= k) {
			hi = mid;
		} else {
			lo = mid;
		}
	}
	ans2 = hi;

	cout << ans2 - ans1 << endl;
}


#include <bits/stdc++.h>
#include <iostream>

using namespace std;
typedef unsigned long long ull;

ull n, k, lo, hi, mid, sum1, sum2, ans1, ans2;
int c[500010];

int main() {
	cin >> n >> k;
	for(int i=0; i<n; i++) {
		cin >> c[i];
	}
	lo = 0;
	hi = 1000000001;
	while(lo < hi-1) {

		mid = lo + (hi-lo)/2;
		sum1 = 0;
		sum2 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] <= mid) {
				sum1 += mid - c[i];
			} else {
				sum2 += c[i] - mid;
			}
		}
		//cout << sum1 << " " << sum2 << endl;
		if (sum1 <= sum2) {
			lo = mid;
		} else {
			hi = mid;
		}
	}

	//cout << lo << " " << hi << endl;
	if (sum1 == sum2 && k >= sum1) {
		cout << 0 << endl;
		return 0;
	} else {
		sum1 = 0;
		sum2 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] <= lo) {
				sum1 += lo - c[i];
			} else {
				sum2 += c[i] - hi;
			}
		}
		if (k >= max(sum1, sum2)) {
			cout << 1 << endl;
			return 0;
		}
	}

	//cout << "hi" << endl;

	lo=0;
	hi=1000000001;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum1 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] < mid) {
				sum1 += mid - c[i];
			}
		}
		if(sum1 <= k) {
			lo = mid;
		} else {
			hi = mid;
		}
	}
	ans1 = lo;

	lo=0;
	hi=1000000001;
	while(lo < hi-1) {
		mid = lo + (hi-lo)/2;
		sum2 = 0;
		for(int i=0; i<n; i++) {
			if(c[i] > mid) {
				sum2 += c[i] - mid;
			}
		}
		if(sum2 <= k) {
			hi = mid;
		} else {
			lo = mid;
		}
	}
	ans2 = hi;

	cout << ans2 - ans1 << endl;
}


#include<iostream>
#include<algorithm>
#include<functional>//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m;
ll Arr[510000];
ll Ok1(ll mid) {
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (Arr[i] < mid) {
			sum += mid - Arr[i];
		}
	}
	return sum;
}
ll Ok(ll mid) {
	ll sum = 0;

	for (int i = 0; i <n; i++) {
		if (Arr[i] > mid) {
			sum += Arr[i] - mid;
		}
	}
	return sum;
}
ll ans;
int mx = -1e9;
int main()
{
	cin >> n >> m;
	for (int i = 0; i <n; i++) {
		cin >> Arr[i];
		//mx = max(mx, Arr[i]);
	}
	ll left = 0, right = 2e9;
	while (left <= right) {

		ll mid = (left + right) / 2;

		if (Ok(mid) > m) {
			left = mid + 1;
		}
		else if (Ok(mid) <= m) {
			right = mid - 1;
			ans = mid;
		}
	}
	int q = m;
	for (int i = 0; i < n; i++) {
		if (Arr[i] > ans && Arr[i] - ans <= q) {
			q -= Arr[i] - ans;
			Arr[i] = ans;

		}
	}
	for (int i = 0; i < n ; i++) {
		if (Arr[i] == ans && q > 0 ) {
			Arr[i] --;
			q--;
		}
	}
	/*for(int i =0 ;i < n;i++)
	{
		cout << Arr[i] << " ";
	}*/
	 left = 0, right = 2e9;

	while (left <= right) {
		ll mid = (left + right) / 2;

		if (Ok1(mid) > m) {
			right = mid - 1;
		}
		else {
			left = mid + 1;
			ans = mid;
		}
	}
	q = m;
	for (int i = 0; i < n; i++) {
		if (Arr[i] < ans && ans - Arr[i] <= q) {
			q -= ans - Arr[i];
			Arr[i] = ans;
		}
	}
	//sort(Arr, Arr + n);

	for (int i = 0; i < n; i++) {
		if (Arr[i] == ans && q > 0 ) Arr[i]++, q--;
		}
	/*for (int i = 0; i < n; i++) {
		cout << Arr[i] << endl;
	}*/
	sort(Arr, Arr + n);
	cout << Arr[n - 1] - Arr[0] << endl;
	//cout << endl;
	/*for (int i = 0; i < n; i++) {
		cout << Arr[i] << " ";
	}*/
	//cout << q << endl;
}


#include<iostream>
#include<algorithm>
//#define N 500010
using namespace std;
int main()
{
	int a[50000];
int n,k;
// n Persons
cin>>n;
//k Days
cin>>k;

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

sort(a,a+n);
if(a[0]!=a[n-1])
	{

while(k!=z)
{

	a[n-1]=a[n-1]-1;
	sort(a,a+n);
	//n-1;
	z++;

}

}
if(a[0]==a[n-1])
	cout<<"0";
//for(int i=0;i<n;i++)
//	cout<<a[i]<<endl;
if(a[0]!=a[n-1])
cout<<a[n-1]-a[0];
}


#include<iostream>
#include<algorithm>
//#define N 500010
using namespace std;
int main()
{
	int a[50000];
int n,k;
// n Persons
cin>>n;
//k Days
cin>>k;

for(int i=0;i<n;i++)
{
	cin>>a[i];
}
int z=0;
int con,temp;
sort(a,a+n);
if(a[0]!=a[n-1])
	{

while(k!=z)
{

	a[n-1]=a[n-1]-1;
	a[0]=a[0]+1;
	if(a[0]!=a[1] ||a[n-1]!=a[n-2])
	{
	sort(a,a+n);
	}
	z++;
	}

	//n-1;

}
if(a[0]==a[n-1])
	cout<<"0";
//for(int i=0;i<n;i++)
//	cout<<a[i]<<endl;
if(a[0]!=a[n-1])
cout<<abs(a[n-1]-a[0]);
}


#include<iostream>
#include<algorithm>
#include<functional>//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
int Arr[100010];
int Ok1(int mid) {
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (Arr[i] < mid) {
			sum += mid - Arr[i];
		}
	}
	return sum;
}
int Ok(int mid) {
	ll sum = 0;

	for (int i = 0; i <n; i++) {
		if (Arr[i] > mid) {
			sum += Arr[i] - mid;
		}
	}
	return sum;
}
ll ans;
int mx = -1e9;
int main()
{
	cin >> n >> m;
	for (int i = 0; i <n; i++) {
		cin >> Arr[i];
		mx = max(mx, Arr[i]);
	}
	int left = 0, right = n;
	while (left <= right) {

		int mid = (left + right) / 2;

		if (Ok(mid) > m) {
			left = mid + 1;
		}
		else if (Ok(mid) <= m) {
			right = mid - 1;
			ans = mid;
		}
	}
	int q = m;
	for (int i = 0; i < n; i++) {
		if (Arr[i] > ans && Arr[i] - ans <= q) {
			Arr[i] = ans;
			q -= Arr[i] - ans;
		}
	}
	/*for(int i =0 ;i < n;i++)
	{
		cout << Arr[i] << " ";
	}*/
	 left = 0, right = n;

	while (left <= right) {
		int mid = (left + right) / 2;

		if (Ok1(mid) > m) {
			right = mid - 1;
		}
		else {
			left = mid + 1;
			ans = mid;
		}
	}
	q = m;
	for (int i = 0; i < n; i++) {
		if (Arr[i] > ans && Arr[i] - ans <= q) {
			q -= Arr[i] - ans;
			Arr[i] = ans;
		}
	}
	sort(Arr, Arr + n);

	for (int i = 0; i < n - 1; i++) {
		if(Arr[i] !=Arr[i + 1] && Arr[i + 1] - Arr[i] <= q) {
		Arr[i] = Arr[i + 1];
		q -= Arr[i + 1] - Arr[i];
		}
	}
	//cout << endl;
	/*for (int i = 0; i < n; i++) {
		cout << Arr[i] << " ";
	}*/
	//cout << q << endl;
	cout << Arr[n - 1] - Arr[0] << endl;
}


#include<iostream>
#include<algorithm>
#include<functional>//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m;
ll Arr[510000];
ll Ok1(ll mid) {
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (Arr[i] < mid) {
			sum += mid - Arr[i];
		}
	}
	return sum;
}
ll Ok(ll mid) {
	ll sum = 0;

	for (int i = 0; i <n; i++) {
		if (Arr[i] > mid) {
			sum += Arr[i] - mid;
		}
	}
	return sum;
}
ll ans;
int mx = -1e9;
int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> Arr[i];
	}
	ll left = 0, right = 2e9;
	while (left <= right) {
		ll mid = (left + right) / 2;

		if (Ok1(mid) > m) {
			right = mid - 1;
		}
		else {
			left = mid + 1;
			ans = mid;
		}
	}
	int q = m;
	for (int i = 0; i < n; i++) {
		if (Arr[i] < ans && ans - Arr[i] <=q) {
			q -= ans - Arr[i];
			Arr[i] = ans;
		}
	}
	for (int i = 0; i < n; i++) {
		if (Arr[i] == ans && q > 0)
			Arr[i]++, q--;
	}

	left = 0, right = 2e9;
	while (left <= right) {
		ll mid = (left + right) / 2;

		if (Ok(mid) > m) {
			left = mid + 1;
		}
		else {
			right = mid - 1;
			ans = mid;
		}
	}
	 q = m;
	for (int i = 0; i < n; i++)
	{
		if (Arr[i] > ans && Arr[i] - ans <=q) {
			q -= Arr[i] - ans;
			Arr[i] = ans;
		}
	}
	for (int i = 0; i < n; i++) {
		if (Arr[i] == ans && q  > 0)
			q--, Arr[i]--;
	}
	sort(Arr, Arr + n);
	cout << Arr[n - 1] - Arr[0] << endl;
}


#include<iostream>
#include<algorithm>
#include<functional>//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
int Arr[500010];
ll Ok1(ll mid) {
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (Arr[i] < mid) {
			sum += mid - Arr[i];
		}
	}
	return sum;
}
ll Ok(ll mid) {
	ll sum = 0;

	for (int i = 0; i <n; i++) {
		if (Arr[i] > mid) {
			sum += Arr[i] - mid;
		}
	}
	return sum;
}
ll ans;
int mx = -1e9;
int main()
{
	cin >> n >> m;
	for (int i = 0; i <n; i++) {
		cin >> Arr[i];
		//mx = max(mx, Arr[i]);
	}
	ll left = 0, right = 2e9;
	while (left <= right) {

		ll mid = (left + right) / 2;

		if (Ok(mid) > m) {
			left = mid + 1;
		}
		else if (Ok(mid) <= m) {
			right = mid - 1;
			ans = mid;
		}
	}
	int q = m;
	for (int i = 0; i < n; i++) {
		if (Arr[i] > ans && Arr[i] - ans <= q) {
			q -= Arr[i] - ans;
			Arr[i] = ans;

		}
	}
	for (int i = 0; i < n, q; i++) {
		if (Arr[i] == ans) {
			Arr[i] --;
			q--;
		}
	}
	/*for(int i =0 ;i < n;i++)
	{
		cout << Arr[i] << " ";
	}*/
	 left = 0, right = 2e9;

	while (left <= right) {
		ll mid = (left + right) / 2;

		if (Ok1(mid) > m) {
			right = mid - 1;
		}
		else {
			left = mid + 1;
			ans = mid;
		}
	}
	q = m;
	for (int i = 0; i < n; i++) {
		if (Arr[i] < ans && ans - Arr[i] <= q) {
			q -= ans - Arr[i];
			Arr[i] = ans;
		}
	}
	//sort(Arr, Arr + n);

	for (int i = 0; i < n ,q ; i++) {
		if (Arr[i] == ans) Arr[i]++, q--;
		}
	/*for (int i = 0; i < n; i++) {
		cout << Arr[i] << endl;
	}*/
	sort(Arr, Arr + n);
	cout << Arr[n - 1 ] - Arr[0] << endl;
	//cout << endl;
	/*for (int i = 0; i < n; i++) {
		cout << Arr[i] << " ";
	}*/
	//cout << q << endl;
}


#include<iostream>
#include<algorithm>
#include<functional>//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
int Arr[100010];
int Ok1(int mid) {
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (Arr[i] < mid) {
			sum += mid - Arr[i];
		}
	}
	return sum;
}
int Ok(int mid) {
	ll sum = 0;

	for (int i = 0; i <n; i++) {
		if (Arr[i] > mid) {
			sum += Arr[i] - mid;
		}
	}
	return sum;
}
ll ans;
int main()
{
	cin >> n >> m;
	for (int i = 0; i <n; i++) {
		cin >> Arr[i];
	}
	int left = 0, right = 1e9;
	while (left <= right) {

		int mid = (left + right) / 2;

		if (Ok(mid) > m) {
			left = mid + 1;
		}
		else if (Ok(mid) <= m) {
			right = mid - 1;
			ans = mid;
		}
	}
	int q = m;
	for (int i = 0; i < n; i++) {
		if (Arr[i] > ans && Arr[i] - ans >= q) {
			Arr[i] = ans;
			q -= Arr[i] - ans;
		}
	}
	/*for(int i =0 ;i < n;i++)
	{
		cout << Arr[i] << " ";
	}*/
	 left = 0, right = 1e9;

	while (left <= right) {
		int mid = (left + right) / 2;

		if (Ok1(mid) > m) {
			right = mid - 1;
		}
		else {
			left = mid + 1;
			ans = mid;
		}
	}
	q = m;
	for (int i = 0; i < n; i++) {
		if (Arr[i] < ans && ans - Arr[i] >= q) {
			q -= ans - Arr[i];
			Arr[i] = ans;
		}
	}
	sort(Arr, Arr + n);

	for (int i = 0; i < n - 1; i++) {
		if(Arr[i] !=Arr[i + 1] && Arr[i + 1] - Arr[i] <= q) {
		Arr[i] = Arr[i + 1];
		q -= Arr[i + 1] - Arr[i];
		}
	}
	//cout << endl;
	/*for (int i = 0; i < n; i++) {
		cout << Arr[i] << " ";
	}*/
	cout << Arr[n - 1] - Arr[0] << endl;
}


#include<iostream>
#include<algorithm>
#include<functional>//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
ll Arr[510000];
ll Ok1(ll mid) {
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (Arr[i] < mid) {
			sum += mid - Arr[i];
		}
	}
	return sum;
}
ll Ok(ll mid) {
	ll sum = 0;

	for (int i = 0; i <n; i++) {
		if (Arr[i] > mid) {
			sum += Arr[i] - mid;
		}
	}
	return sum;
}
ll ans;
int mx = -1e9;
int main()
{
	cin >> n >> m;
	for (int i = 0; i <n; i++) {
		cin >> Arr[i];
		//mx = max(mx, Arr[i]);
	}
	ll left = 0, right = 2e9;
	while (left <= right) {

		ll mid = (left + right) / 2;

		if (Ok(mid) > m) {
			left = mid + 1;
		}
		else if (Ok(mid) <= m) {
			right = mid - 1;
			ans = mid;
		}
	}
	int q = m;
	for (int i = 0; i < n; i++) {
		if (Arr[i] > ans && Arr[i] - ans <= q) {
			q -= Arr[i] - ans;
			Arr[i] = ans;

		}
	}
	for (int i = 0; i < n, q; i++) {
		if (Arr[i] == ans) {
			Arr[i] --;
			q--;
		}
	}
	/*for(int i =0 ;i < n;i++)
	{
		cout << Arr[i] << " ";
	}*/
	 left = 0, right = 2e9;

	while (left <= right) {
		ll mid = (left + right) / 2;

		if (Ok1(mid) > m) {
			right = mid - 1;
		}
		else {
			left = mid + 1;
			ans = mid;
		}
	}
	q = m;
	for (int i = 0; i < n; i++) {
		if (Arr[i] < ans && ans - Arr[i] <= q) {
			q -= ans - Arr[i];
			Arr[i] = ans;
		}
	}
	//sort(Arr, Arr + n);

	for (int i = 0; i < n ,q ; i++) {
		if (Arr[i] == ans) Arr[i]++, q--;
		}
	/*for (int i = 0; i < n; i++) {
		cout << Arr[i] << endl;
	}*/
	sort(Arr, Arr + n);
	cout << Arr[n - 1 ] - Arr[0] << endl;
	//cout << endl;
	/*for (int i = 0; i < n; i++) {
		cout << Arr[i] << " ";
	}*/
	//cout << q << endl;
}


#include<iostream>
#include<algorithm>
#include<functional>//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
int Arr[100010];
ll Ok1(ll mid) {
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (Arr[i] < mid) {
			sum += mid - Arr[i];
		}
	}
	return sum;
}
ll Ok(ll mid) {
	ll sum = 0;

	for (int i = 0; i <n; i++) {
		if (Arr[i] > mid) {
			sum += Arr[i] - mid;
		}
	}
	return sum;
}
ll ans;
int mx = -1e9;
int main()
{
	cin >> n >> m;
	for (int i = 0; i <n; i++) {
		cin >> Arr[i];
		//mx = max(mx, Arr[i]);
	}
	ll left = 0, right = 2e9;
	while (left <= right) {

		ll mid = (left + right) / 2;

		if (Ok(mid) > m) {
			left = mid + 1;
		}
		else if (Ok(mid) <= m) {
			right = mid - 1;
			ans = mid;
		}
	}
	int q = m;
	for (int i = 0; i < n; i++) {
		if (Arr[i] > ans && Arr[i] - ans <= q) {
			q -= Arr[i] - ans;
			Arr[i] = ans;

		}
	}
	for (int i = 0; i < n, q; i++) {
		if (Arr[i] == ans) {
			Arr[i] --;
			q--;
		}
	}
	/*for(int i =0 ;i < n;i++)
	{
		cout << Arr[i] << " ";
	}*/
	 left = 0, right = 2e9;

	while (left <= right) {
		ll mid = (left + right) / 2;

		if (Ok1(mid) > m) {
			right = mid - 1;
		}
		else {
			left = mid + 1;
			ans = mid;
		}
	}
	q = m;
	for (int i = 0; i < n; i++) {
		if (Arr[i] < ans && ans - Arr[i] <= q) {
			q -= ans - Arr[i];
			Arr[i] = ans;
		}
	}
	//sort(Arr, Arr + n);

	for (int i = 0; i < n ,q ; i++) {
		if (Arr[i] == ans) Arr[i]++, q--;
		}
	/*for (int i = 0; i < n; i++) {
		cout << Arr[i] << endl;
	}*/
	sort(Arr, Arr + n);
	cout << Arr[n - 1 ] - Arr[0] << endl;
	//cout << endl;
	/*for (int i = 0; i < n; i++) {
		cout << Arr[i] << " ";
	}*/
	//cout << q << endl;
}


#include<iostream>
#include<algorithm>
//#define N 500010
using namespace std;
int main()
{
	int a[500002];
int n,k;
// n Persons
cin>>n;
//k Days
cin>>k;

for(int i=0;i<n;i++)

	cin>>a[i];

int z=0;

sort(a,a+n);
if(a[0]!=a[n-1])
	{

while(k!=z)
{

	a[n-1]=a[n-1]-1;
	a[0]=a[0]+1;
	sort(a,a+n);
	//n-1;
	z++;

}

}
if(a[0]==a[n-1])
	cout<<"0";
//for(int i=0;i<n;i++)
//	cout<<a[i]<<endl;
if(a[0]!=a[n-1])
cout<<abs(a[n-1]-a[0]);
}


#include<iostream>
#include<algorithm>
//#define N 500010
using namespace std;
int main()
{
	int a[50000];
int n,k;
// n Persons
cin>>n;
//k Days
cin>>k;

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

//sort(a,a+n);
if(a[0]!=a[n-1])
	{

while(k!=z)
{

	a[n-1]=a[n-1]-1;
	a[0]=a[0]+1;
	sort(a,a+n);
	//n-1;
	z++;

}

}
if(a[0]==a[n-1])
	cout<<"0";
//for(int i=0;i<n;i++)
//	cout<<a[i]<<endl;
if(a[0]!=a[n-1])
cout<<abs(a[n-1]-a[0]);
}


#include<iostream>
#include<algorithm>
//#define N 500010
using namespace std;
int main()
{
	int a[50000];
int n,k;
// n Persons
cin>>n;
//k Days
cin>>k;

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

sort(a,a+n);
if(a[0]!=a[n-1])
	{

while(k!=z)
{

	a[n-1]=a[n-1]-1;
	//n-1;
	z++;

	sort(a,a+n);
}

}
if(a[0]==a[n-1])
	cout<<"0";
//for(int i=0;i<n;i++)
//	cout<<a[i]<<endl;
if(a[0]!=a[n-1])
cout<<a[n-1]-a[0];
}


#include<iostream>
#include<algorithm>
#include<functional>//#include<bits/stdc++.h>
using namespace std;
#define Fast ios::sync_with_stdio(0);
typedef long long ll;
ll n, m;
int Arr[510000];
ll Ok1(ll mid) {
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (Arr[i] < mid) {
			sum += mid - Arr[i];
		}
	}
	return sum;
}
ll Ok(ll mid) {
	ll sum = 0;

	for (int i = 0; i <n; i++) {
		if (Arr[i] > mid) {
			sum += Arr[i] - mid;
		}
	}
	return sum;
}
ll ans;
int mx = -1e9;
int main()
{
	//Fast;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		scanf("%d", &Arr[i]);
	}
	ll left = 0, right = 2e9;
	while (left <= right) {
		ll mid = (left + right) / 2;

		if (Ok1(mid) > m) {
			right = mid - 1;
		}
		else {
			left = mid + 1;
			ans = mid;
		}
	}
	int q = m;
	for (int i = 0; i < n; i++) {
		if (Arr[i] < ans && ans - Arr[i] <=q) {
			q -= ans - Arr[i];
			Arr[i] = ans;
		}
	}
	for (int i = 0; i < n; i++) {
		if (Arr[i] == ans && q > 0)
			Arr[i]++, q--;
	}

	left = 0, right = 2e9;
	while (left <= right) {
		ll mid = (left + right) / 2;

		if (Ok(mid) > m) {
			left = mid + 1;
		}
		else {
			right = mid - 1;
			ans = mid;
		}
	}
	 q = m;
	for (int i = 0; i < n; i++)
	{
		if (Arr[i] > ans && Arr[i] - ans <=q) {
			q -= Arr[i] - ans;
			Arr[i] = ans;
		}
	}
	for (int i = 0; i < n; i++) {
		if (Arr[i] == ans && q  > 0)
			q--, Arr[i]--;
	}
	sort(Arr, Arr + n);
	cout << Arr[n - 1] - Arr[0] << endl;
}


#include<iostream>
#include<algorithm>
#include<functional>//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m;
ll Arr[510000];
ll Ok1(ll mid) {
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (Arr[i] < mid) {
			sum += mid - Arr[i];
		}
	}
	return sum;
}
ll Ok(ll mid) {
	ll sum = 0;

	for (int i = 0; i <n; i++) {
		if (Arr[i] > mid) {
			sum += Arr[i] - mid;
		}
	}
	return sum;
}
ll ans;
int mx = -1e9;
int main()
{
	cin >> n >> m;
	for (int i = 0; i <n; i++) {
		cin >> Arr[i];
		//mx = max(mx, Arr[i]);
	}
	ll left = 0, right = 2e9;
	while (left <= right) {

		ll mid = (left + right) / 2;

		if (Ok(mid) > m) {
			left = mid + 1;
		}
		else if (Ok(mid) <= m) {
			right = mid - 1;
			ans = mid;
		}
	}
	int q = m;
	for (int i = 0; i < n; i++) {
		if (Arr[i] > ans && Arr[i] - ans <= q) {
			q -= Arr[i] - ans;
			Arr[i] = ans;

		}
	}
	for (int i = 0; i < n &&  q; i++) {
		if (Arr[i] == ans) {
			Arr[i] --;
			q--;
		}
	}
	/*for(int i =0 ;i < n;i++)
	{
		cout << Arr[i] << " ";
	}*/
	 left = 0, right = 2e9;

	while (left <= right) {
		ll mid = (left + right) / 2;

		if (Ok1(mid) > m) {
			right = mid - 1;
		}
		else {
			left = mid + 1;
			ans = mid;
		}
	}
	q = m;
	for (int i = 0; i < n; i++) {
		if (Arr[i] < ans && ans - Arr[i] <= q) {
			q -= ans - Arr[i];
			Arr[i] = ans;
		}
	}
	//sort(Arr, Arr + n);

	for (int i = 0; i < n  && q ; i++) {
		if (Arr[i] == ans) Arr[i]++, q--;
		}
	/*for (int i = 0; i < n; i++) {
		cout << Arr[i] << endl;
	}*/
	sort(Arr, Arr + n);
	cout << Arr[n - 1 ] - Arr[0] << endl;
	//cout << endl;
	/*for (int i = 0; i < n; i++) {
		cout << Arr[i] << " ";
	}*/
	//cout << q << endl;
}


#include<iostream>
#include<algorithm>
//#define N 500010
using namespace std;
int main()
{
	int a[50000];
int n,k;
// n Persons
cin>>n;
//k Days
cin>>k;

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

sort(a,a+n);
if(a[0]!=a[n-1])
	{

while(k!=z)
{

	a[n-1]=a[n-1]-1;
	a[0]=a[0]+1;
	sort(a,a+n);
	//n-1;
	z++;

}

}
if(a[0]==a[n-1])
	cout<<"0";
//for(int i=0;i<n;i++)
//	cout<<a[i]<<endl;
if(a[0]!=a[n-1])
cout<<abs(a[n-1]-a[0]);
}


#include <bits/stdc++.h>
using namespace std;

int n;
long long K;
long long a[500500];

long long up(long long K) {
	long long pass = 1e9;
	long long fail = 0;

	while (pass - fail > 1) {
		long long mid = (pass + fail) / 2;

		long long over = 0;
		for (int i = 0; i < n; i++) {
			over += max(0ll, a[i] - mid);
		}
		if (over < K)
			pass = mid;
		else
			fail = mid;
	}
	return pass;
}

long long down(long long K) {
	long long pass = 0;
	long long fail = 1e9;

	while (fail - pass > 1) {
		long long mid = (pass + fail) / 2;

		long long less = 0;
		for (int i = 0; i < n; i++) {
			less += max(0ll, mid - a[i]);
		}
		if (less < K)
			pass = mid;
		else
			fail = mid;
	}
	return pass;
}

long long search(long long K) {
	long long pass = 0;
	long long fail = K + 1;

	while (fail - pass > 1) {
		long long mid = (pass + fail) / 2;
		if (up(mid) - down(mid) >= 2)
			pass = mid;
		else
			fail = mid;
	}
	return pass;
}

int main() {
	cin >> n >> K;

	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);

	long long num = search(K);
	long long u = up(num);
	long long d = down(num);

	long long useU = 0, useD = 0;
	// long long useU = 0;

	for (int i = 0; i < n; i++) {
		if (a[i] >= u) {
			a[i] = u;
			useU += a[i] - u;
		}
		if (a[i] <= d) {
			a[i] = d;
			useD += d - a[i];
		}
	}

	multiset<long long> st(a, a + n);

	while (useU < useD) {
		auto it = prev(st.end());
		long long mx = *it;
		useU++;
		st.erase(it);
		st.insert(mx - 1);
	}
	while (useU > useD) {
		auto it = st.begin();
		long long mn = *it;
		useD++;
		st.erase(it);
		st.insert(mn + 1);
	}

	for (; useU < K; useU++) {
		auto itmin = st.begin();
		auto itmax = prev(st.end());
		long long mn = *itmin;
		long long mx = *itmax;
		if (mx - 1 >= mn + 1) {
			st.erase(itmin);
			st.erase(itmax);
			st.insert(mx - 1);
			st.insert(mn + 1);
		} else break;
	}

	long long ans = *st.rbegin() - *st.begin();
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;

int n;
long long K;
long long a[500500];
long long sum[500500];

long long up(long long K) {
	long long pass = 1e9;
	long long fail = 0;

	while (pass - fail > 1) {
		long long mid = (pass + fail) / 2;

		int k = lower_bound(a, a + n, mid) - a;
		long long over = sum[n] - sum[k] - (n - k) * mid;

		if (over < K)
			pass = mid;
		else
			fail = mid;
	}
	return pass;
}

long long down(long long K) {
	long long pass = 0;
	long long fail = 1e9;

	while (fail - pass > 1) {
		long long mid = (pass + fail) / 2;

		int k = upper_bound(a, a + n, mid) - a;
		long long less = k * mid - sum[k];

		if (less < K)
			pass = mid;
		else
			fail = mid;
	}
	return pass;
}

long long search(long long K) {
	if (up(K) - down(K) >= 2) return K;
	long long pass = 0;
	long long fail = K + 1;

	while (fail - pass > 1) {
		long long mid = (pass + fail) / 2;
		if (up(mid) - down(mid) >= 2)
			pass = mid;
		else
			fail = mid;
	}
	return pass;
}

int main() {
	cin >> n >> K;

	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	sort(a, a + n);
	for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + a[i];

	long long num = search(K);
	long long u = up(num);
	long long d = down(num);

	long long useU = 0, useD = 0;

	for (int i = 0; i < n; i++) {
		if (a[i] >= u) {
			useU += a[i] - u;
			a[i] = u;
		}
		if (a[i] <= d) {
			useD += d - a[i];
			a[i] = d;
		}
	}
	multiset<long long> st(a, a + n);

	while (useU < useD) {
		auto it = prev(st.end());
		long long mx = *it;
		useU++;
		if (mx - 1 >= *st.begin()) {
			st.erase(it);
			st.insert(mx - 1);
		} else break;
	}
	while (useU > useD) {
		auto it = st.begin();
		long long mn = *it;
		useD++;
		if (*st.rbegin() >= mn + 1) {
			st.erase(it);
			st.insert(mn + 1);
		} else break;
	}

	for (; useU < K; useU++) {
		auto itmin = st.begin();
		auto itmax = prev(st.end());
		long long mn = *itmin;
		long long mx = *itmax;
		if (mx - 1 >= mn + 1) {
			st.erase(itmin);
			st.erase(itmax);
			st.insert(mx - 1);
			st.insert(mn + 1);
		} else break;
	}

	long long ans = *st.rbegin() - *st.begin();
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;

int n;
long long K;
long long a[500500];

long long up() {
	long long pass = 1e9;
	long long fail = 0;

	while (pass - fail > 1) {
		long long mid = (pass + fail) / 2;

		long long over = 0;
		for (int i = 0; i < n; i++) {
			over += max(0ll, a[i] - mid);
		}
		if (over < K)
			pass = mid;
		else
			fail = mid;
	}
	return pass;
}

long long down() {
	long long pass = 0;
	long long fail = 1e9;

	while (fail - pass > 1) {
		long long mid = (pass + fail) / 2;

		long long less = 0;
		for (int i = 0; i < n; i++) {
			less += max(0ll, mid - a[i]);
		}
		if (less < K)
			pass = mid;
		else
			fail = mid;
	}
	return pass;
}

int main() {
	cin >> n >> K;

	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);

	long long u = up();
	long long d = down();
	sort(a, a + n);

	if (u <= d) {
		long long sum = 0;
		for (int i = 0; i < n; i++)
			sum += a[i];
		cout << sum % 2 << endl;
		return 0;
	}

	// long long useU = 0;

	long long useU = 0, useD = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] >= u) {
			useU += a[i] - u;
			a[i] = u;
		}
		if (a[i] <= d) {
			useD += d - a[i];
			a[i] = d;
		}
	}

	multiset<long long> st(a, a + n);

	while (useU < useD) {
		auto it = prev(st.end());
		long long mx = *it;
		useU++;
		st.erase(it);
		st.insert(mx - 1);
	}
	while (useU > useD) {
		auto it = st.begin();
		long long mn = *it;
		useD++;
		st.erase(it);
		st.insert(mn + 1);
	}

	for (; useU < K; useU++) {
		auto itmin = st.begin();
		auto itmax = prev(st.end());
		long long mn = *itmin;
		long long mx = *itmax;
		if (mx - 1 >= mn + 1) {
			st.erase(itmin);
			st.erase(itmax);
			st.insert(mx - 1);
			st.insert(mn + 1);
		} else break;
	}

	long long ans = *st.rbegin() - *st.begin();
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;

int n;
long long K;
long long a[500500];

long long up() {
	long long pass = 1e9;
	long long fail = 0;

	while (pass - fail > 1) {
		long long mid = (pass + fail) / 2;

		long long over = 0;
		for (int i = 0; i < n; i++) {
			over += max(0ll, a[i] - mid);
		}
		if (over < K)
			pass = mid;
		else
			fail = mid;
	}
	return pass;
}

long long down() {
	long long pass = 0;
	long long fail = 1e9;

	while (fail - pass > 1) {
		long long mid = (pass + fail) / 2;

		long long less = 0;
		for (int i = 0; i < n; i++) {
			less += max(0ll, mid - a[i]);
		}
		if (less < K)
			pass = mid;
		else
			fail = mid;
	}
	return pass;
}

int main() {
	cin >> n >> K;

	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);

	long long u = up();
	long long d = down();

	if (u <= d) {
		cout << 0 << endl;
		return 0;
	}

	// long long useU = 0;

	long long useU = 0, useD = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] >= u) {
			useU += a[i] - u;
			a[i] = u;
		}
		if (a[i] <= d) {
			useD += d - a[i];
			a[i] = d;
		}
	}

	multiset<long long> st(a, a + n);

	while (useU < useD) {
		auto it = prev(st.end());
		long long mx = *it;
		useU++;
		st.erase(it);
		st.insert(mx - 1);
	}
	while (useU > useD) {
		auto it = st.begin();
		long long mn = *it;
		useD++;
		st.erase(it);
		st.insert(mn + 1);
	}

	for (; useU < K; useU++) {
		auto itmin = st.begin();
		auto itmax = prev(st.end());
		long long mn = *itmin;
		long long mx = *itmax;
		st.erase(itmin);
		st.erase(itmax);
		st.insert(mx - 1);
		st.insert(mn + 1);
	}

	long long ans = *st.rbegin() - *st.begin();
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;

int n;
long long K;
long long a[500500];

long long up(long long K) {
	long long pass = 1e9;
	long long fail = 0;

	while (pass - fail > 1) {
		long long mid = (pass + fail) / 2;

		long long over = 0;
		for (int i = 0; i < n; i++) {
			over += max(0ll, a[i] - mid);
		}
		if (over < K)
			pass = mid;
		else
			fail = mid;
	}
	return pass;
}

long long down(long long K) {
	long long pass = 0;
	long long fail = 1e9;

	while (fail - pass > 1) {
		long long mid = (pass + fail) / 2;

		long long less = 0;
		for (int i = 0; i < n; i++) {
			less += max(0ll, mid - a[i]);
		}
		if (less < K)
			pass = mid;
		else
			fail = mid;
	}
	return pass;
}

int main() {
	cin >> n >> K;

	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);

	long long u = up(K) + 1;
	long long d = down(K) - 1;

	long long useU = 0, useD = 0;
	// long long useU = 0;

	for (int i = 0; i < n; i++) {
		if (a[i] >= u) {
			useU += a[i] - u;
		}
		if (a[i] <= d) {
			useD += d - a[i];
		}
	}

	if (u <= d) {
		if (useU < useD)
			d = down(useU) - 1;
		else
			u = up(useD) + 1;
	}

	useU = 0;
	useD = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] >= u) {
			a[i] = u;
			useU += a[i] - u;
		}
		if (a[i] <= d) {
			a[i] = d;
			useD += d - a[i];
		}
	}

	multiset<long long> st(a, a + n);

	while (useU < useD) {
		auto it = prev(st.end());
		long long mx = *it;
		useU++;
		st.erase(it);
		st.insert(mx - 1);
	}
	while (useU > useD) {
		auto it = st.begin();
		long long mn = *it;
		useD++;
		st.erase(it);
		st.insert(mn + 1);
	}

	for (; useU < K; useU++) {
		auto itmin = st.begin();
		auto itmax = prev(st.end());
		long long mn = *itmin;
		long long mx = *itmax;
		if (mx - 1 >= mn + 1) {
			st.erase(itmin);
			st.erase(itmax);
			st.insert(mx - 1);
			st.insert(mn + 1);
		} else break;
	}

	long long ans = *st.rbegin() - *st.begin();
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;

int n;
long long K;
long long a[500500];

long long up(long long K) {
	long long pass = 1e9;
	long long fail = 0;

	while (pass - fail > 1) {
		long long mid = (pass + fail) / 2;

		long long over = 0;
		for (int i = 0; i < n; i++) {
			over += max(0ll, a[i] - mid);
		}
		if (over < K)
			pass = mid;
		else
			fail = mid;
	}
	return pass;
}

long long down(long long K) {
	long long pass = 0;
	long long fail = 1e9;

	while (fail - pass > 1) {
		long long mid = (pass + fail) / 2;

		long long less = 0;
		for (int i = 0; i < n; i++) {
			less += max(0ll, mid - a[i]);
		}
		if (less < K)
			pass = mid;
		else
			fail = mid;
	}
	return pass;
}

long long search(long long K) {
	long long pass = 0;
	long long fail = K + 1;

	while (fail - pass > 1) {
		long long mid = (pass + fail) / 2;
		if (up(mid) - down(mid) >= 2)
			pass = mid;
		else
			fail = mid;
	}
	return pass;
}

int main() {
	cin >> n >> K;

	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);

	long long num = search(K);
	long long u = up(num);
	long long d = down(num);

	long long useU = 0, useD = 0;
	// long long useU = 0;

	for (int i = 0; i < n; i++) {
		if (a[i] >= u) {
			a[i] = u;
			useU += a[i] - u;
		}
		if (a[i] <= d) {
			a[i] = d;
			useD += d - a[i];
		}
	}

	multiset<long long> st(a, a + n);

	while (useU < useD) {
		auto it = prev(st.end());
		long long mx = *it;
		useU++;
		if (mx - 1 >= *st.begin()) {
			st.erase(it);
			st.insert(mx - 1);
		} else break;
	}
	while (useU > useD) {
		auto it = st.begin();
		long long mn = *it;
		useD++;
		if (*st.rbegin() >= mn + 1) {
			st.erase(it);
			st.insert(mn + 1);
		} else break;
	}

	for (; useU < K; useU++) {
		auto itmin = st.begin();
		auto itmax = prev(st.end());
		long long mn = *itmin;
		long long mx = *itmax;
		if (mx - 1 >= mn + 1) {
			st.erase(itmin);
			st.erase(itmax);
			st.insert(mx - 1);
			st.insert(mn + 1);
		} else break;
	}

	long long ans = *st.rbegin() - *st.begin();
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;

int n;
long long K;
long long a[500500];

long long up(long long K) {
	long long pass = 1e9;
	long long fail = 0;

	while (pass - fail > 1) {
		long long mid = (pass + fail) / 2;

		long long over = 0;
		for (int i = 0; i < n; i++) {
			over += max(0ll, a[i] - mid);
		}
		if (over < K)
			pass = mid;
		else
			fail = mid;
	}
	return pass;
}

long long down(long long K) {
	long long pass = 0;
	long long fail = 1e9;

	while (fail - pass > 1) {
		long long mid = (pass + fail) / 2;

		long long less = 0;
		for (int i = 0; i < n; i++) {
			less += max(0ll, mid - a[i]);
		}
		if (less < K)
			pass = mid;
		else
			fail = mid;
	}
	return pass;
}

long long search(long long K) {
	long long pass = 0;
	long long fail = K + 1;

	while (fail - pass > 1) {
		long long mid = (pass + fail) / 2;
		if (up(mid) - down(mid) >= 2)
			pass = mid;
		else
			fail = mid;
	}
	return pass;
}

int main() {
	cin >> n >> K;

	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	sort(a, a + n);

	long long num = search(K);
	long long u = up(num);
	long long d = down(num);

	long long useU = 0, useD = 0;

	for (int i = 0; i < n; i++) {
		if (a[i] >= u) {
			useU += a[i] - u;
			a[i] = u;
		}
		if (a[i] <= d) {
			useD += d - a[i];
			a[i] = d;
		}
	}
	multiset<long long> st(a, a + n);

	while (useU < useD) {
		auto it = prev(st.end());
		long long mx = *it;
		useU++;
		if (mx - 1 >= *st.begin()) {
			st.erase(it);
			st.insert(mx - 1);
		} else break;
	}
	while (useU > useD) {
		auto it = st.begin();
		long long mn = *it;
		useD++;
		if (*st.rbegin() >= mn + 1) {
			st.erase(it);
			st.insert(mn + 1);
		} else break;
	}

	for (; useU < K; useU++) {
		auto itmin = st.begin();
		auto itmax = prev(st.end());
		long long mn = *itmin;
		long long mx = *itmax;
		if (mx - 1 >= mn + 1) {
			st.erase(itmin);
			st.erase(itmax);
			st.insert(mx - 1);
			st.insert(mn + 1);
		} else break;
	}

	long long ans = *st.rbegin() - *st.begin();
	cout << ans << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:66777216")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <ctime>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <cassert>
#include <cstdlib>
#include <bitset>
#include <algorithm>
#include <string>
#include <list>
#include <fstream>
#include <cstring>
#include <sstream>
#include <numeric>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fornn(i, q, n) for (int i = q; i < (ll)n; i++)
#define mp make_pair
#define pk push_back
#define all(v) v.begin(), v.end()
#define times clock() * 1.0 / CLOCKS_PER_SEC

#define TASK "sum2"

const double eps = 1e-7;
const double pi = acos(-1.0);

const ll INF = (ll)2e9 + 1;
const ll LINF = (ll)8e18;
const ll inf = (ll)2e9 + 1;
const ll linf = (ll)8e18;
const ll MM = (ll)1e9 + 7;

int solve();
void gen();

int main()
{
#ifdef HOME
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#else
    //freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
    //freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout), freopen("test.txt", "w", stderr);
#endif
    solve();
    return 0;
}

const int dd = 5e5 + 7;

int n, k;

int getmin(vector<ll> G) {
    ll l = 0, r = inf;
    while (r - l > 1) {
        ll m = (l + r) / 2;

        ll cur = 0;

        forn(i, n) {
            cur += max(0ll, m - G[i]);
        }

        if (cur <= k) {
            l = m;
        }
        else {
            r = m;
        }
    }

    int cur = k;
    forn(i, n) {
        cur -= max(0ll, l - G[i]);
        G[i] = max(G[i], l);
    }

    forn(i, n) {
        if (cur && G[i] == l) {
            cur--, G[i]++;
        }
    }
    return *min_element(all(G));
}

int getmax(vector<ll> G) {
    ll l = 0, r = inf;
    while (r - l > 1) {
        ll m = (l + r) / 2;

        ll cur = 0;

        forn(i, n) {
            cur += max(0ll, G[i] - m);
        }

        if (cur <= k) {
            r = m;
        }
        else {
            l = m;
        }
    }

    int cur = k;
    forn(i, n) {
        cur -= max(0ll, G[i] - r);
        G[i] = min(G[i], r);
    }

    forn(i, n) {
        if (cur && G[i] == r) {
            cur--, G[i]--;
        }
    }
    return *max_element(all(G));
}

int solve() {
    cin >> n >> k;

    vector<ll> G(n);

    forn(i, n)
        cin >> G[i];

    cout << getmax(G) - getmin(G);
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:66777216")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <ctime>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <cassert>
#include <cstdlib>
#include <bitset>
#include <algorithm>
#include <string>
#include <list>
#include <fstream>
#include <cstring>
#include <sstream>
#include <numeric>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fornn(i, q, n) for (int i = q; i < (ll)n; i++)
#define mp make_pair
#define pk push_back
#define all(v) v.begin(), v.end()
#define times clock() * 1.0 / CLOCKS_PER_SEC

#define TASK "sum2"

const double eps = 1e-7;
const double pi = acos(-1.0);

const ll INF = (ll)2e9 + 1;
const ll LINF = (ll)8e18;
const ll inf = (ll)2e9 + 1;
const ll linf = (ll)8e18;
const ll MM = (ll)1e9 + 7;

int solve();
void gen();

int main()
{
#ifdef HOME
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#else
    //freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
    //freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout), freopen("test.txt", "w", stderr);
#endif
    solve();
    return 0;
}

const int dd = 5e5 + 7;

ll n, k;
vector<ll> G;

void getmin() {
    ll l = 0, r = inf;
    while (r - l > 1) {
        ll m = (l + r) / 2;

        ll cur = 0;

        forn(i, n) {
            cur += max(0ll, m - G[i]);
        }

        if (cur <= k) {
            l = m;
        }
        else {
            r = m;
        }
    }

    ll cur = k;
    forn(i, n) {
        cur -= max(0ll, l - G[i]);
        G[i] = max(G[i], l);
    }

    forn(i, n) {
        if (cur && G[i] == l) {
            cur--, G[i]++;
        }
    }
}

void getmax() {
    ll l = 0, r = inf;
    while (r - l > 1) {
        ll m = (l + r) / 2;

        ll cur = 0;

        forn(i, n) {
            cur += max(0ll, G[i] - m);
        }

        if (cur <= k) {
            r = m;
        }
        else {
            l = m;
        }
    }

    ll cur = k;
    forn(i, n) {
        cur -= max(0ll, G[i] - r);
        G[i] = min(G[i], r);
    }

    forn(i, n) {
        if (cur && G[i] == r) {
            cur--, G[i]--;
        }
    }
}

int solve() {
    cin >> n >> k;

    G.resize(n);

    forn(i, n)
        scanf("%d", &G[i]);

    getmin();
    getmax();
    cout << *max_element(all(G)) - *min_element(all(G));
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:66777216")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <ctime>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <cassert>
#include <cstdlib>
#include <bitset>
#include <algorithm>
#include <string>
#include <list>
#include <fstream>
#include <cstring>
#include <sstream>
#include <numeric>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fornn(i, q, n) for (int i = q; i < (ll)n; i++)
#define mp make_pair
#define pk push_back
#define all(v) v.begin(), v.end()
#define times clock() * 1.0 / CLOCKS_PER_SEC

#define TASK "sum2"

const double eps = 1e-7;
const double pi = acos(-1.0);

const ll INF = (ll)2e9 + 1;
const ll LINF = (ll)8e18;
const ll inf = (ll)2e9 + 1;
const ll linf = (ll)8e18;
const ll MM = (ll)1e9 + 7;

int solve();
void gen();

int main()
{
#ifdef HOME
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#else
    //freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
    //freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout), freopen("test.txt", "w", stderr);
#endif
    solve();
    return 0;
}

const int dd = 5e5 + 7;

ll n, k;
vector<ll> G;

void getmin() {
    ll l = 0, r = inf;
    while (r - l > 1) {
        ll m = (l + r) / 2;

        ll cur = 0;

        forn(i, n) {
            cur += max(0ll, m - G[i]);
        }

        if (cur <= k) {
            l = m;
        }
        else {
            r = m;
        }
    }

    ll cur = k;
    forn(i, n) {
        cur -= max(0ll, l - G[i]);
        G[i] = max(G[i], l);
    }

    forn(i, n) {
        if (cur && G[i] == l) {
            cur--, G[i]++;
        }
    }
}

void getmax() {
    ll l = 0, r = inf;
    while (r - l > 1) {
        ll m = (l + r) / 2;

        ll cur = 0;

        forn(i, n) {
            cur += max(0ll, G[i] - m);
        }

        if (cur <= k) {
            r = m;
        }
        else {
            l = m;
        }
    }

    ll cur = k;
    forn(i, n) {
        cur -= max(0ll, G[i] - r);
        G[i] = min(G[i], r);
    }

    forn(i, n) {
        if (cur && G[i] == r) {
            cur--, G[i]--;
        }
    }
}

int solve() {
    cin >> n >> k;

    G.resize(n);

    forn(i, n)
        cin >> G[i];

    getmin();
    getmax();
    cout << *max_element(all(G)) - *min_element(all(G));
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:66777216")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <ctime>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <cassert>
#include <cstdlib>
#include <bitset>
#include <algorithm>
#include <string>
#include <list>
#include <fstream>
#include <cstring>
#include <sstream>
#include <numeric>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fornn(i, q, n) for (int i = q; i < (ll)n; i++)
#define mp make_pair
#define pk push_back
#define all(v) v.begin(), v.end()
#define times clock() * 1.0 / CLOCKS_PER_SEC

#define TASK "sum2"

const double eps = 1e-7;
const double pi = acos(-1.0);

const ll INF = (ll)2e9 + 1;
const ll LINF = (ll)8e18;
const ll inf = (ll)2e9 + 1;
const ll linf = (ll)8e18;
const ll MM = (ll)1e9 + 7;

int solve();
void gen();

int main()
{
#ifdef HOME
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#else
    //freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
    //freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout), freopen("test.txt", "w", stderr);
#endif
    solve();
    return 0;
}

const int dd = 5e5 + 7;

int n, k;
vector<ll> G;

void getmin() {
    ll l = 0, r = inf;
    while (r - l > 1) {
        ll m = (l + r) / 2;

        ll cur = 0;

        forn(i, n) {
            cur += max(0ll, m - G[i]);
        }

        if (cur <= k) {
            l = m;
        }
        else {
            r = m;
        }
    }

    int cur = k;
    forn(i, n) {
        cur -= max(0ll, l - G[i]);
        G[i] = max(G[i], l);
    }

    forn(i, n) {
        if (cur && G[i] == l) {
            cur--, G[i]++;
        }
    }
}

void getmax() {
    ll l = 0, r = inf;
    while (r - l > 1) {
        ll m = (l + r) / 2;

        ll cur = 0;

        forn(i, n) {
            cur += max(0ll, G[i] - m);
        }

        if (cur <= k) {
            r = m;
        }
        else {
            l = m;
        }
    }

    int cur = k;
    forn(i, n) {
        cur -= max(0ll, G[i] - r);
        G[i] = min(G[i], r);
    }

    forn(i, n) {
        if (cur && G[i] == r) {
            cur--, G[i]--;
        }
    }
}

int solve() {
    cin >> n >> k;

    G.resize(n);

    forn(i, n)
        cin >> G[i];

    getmax();
    getmin();
    cout << *max_element(all(G)) - *min_element(all(G));
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:66777216")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <ctime>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <cassert>
#include <cstdlib>
#include <bitset>
#include <algorithm>
#include <string>
#include <list>
#include <fstream>
#include <cstring>
#include <sstream>
#include <numeric>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fornn(i, q, n) for (int i = q; i < (ll)n; i++)
#define mp make_pair
#define pk push_back
#define all(v) v.begin(), v.end()
#define times clock() * 1.0 / CLOCKS_PER_SEC

#define TASK "sum2"

const double eps = 1e-7;
const double pi = acos(-1.0);

const ll INF = (ll)2e9 + 1;
const ll LINF = (ll)8e18;
const ll inf = (ll)2e9 + 1;
const ll linf = (ll)8e18;
const ll MM = (ll)1e9 + 7;

int solve();
void gen();

int main()
{
#ifdef HOME
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#else
    //freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
    //freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout), freopen("test.txt", "w", stderr);
#endif
    solve();
    return 0;
}

const int dd = 5e5 + 7;

ll n, k;
vector<ll> G;

void getmin() {
    ll l = 0, r = inf;
    while (r - l > 1) {
        ll m = (l + r) / 2;

        ll cur = 0;

        forn(i, n) {
            cur += max(0ll, m - G[i]);
        }

        if (cur <= k) {
            l = m;
        }
        else {
            r = m;
        }
    }

    ll cur = k;
    forn(i, n) {
        cur -= max(0ll, l - G[i]);
        G[i] = max(G[i], l);
    }

    forn(i, n) {
        if (cur && G[i] == l) {
            cur--, G[i]++;
        }
    }
}

void getmax() {
    ll l = 0, r = inf;
    while (r - l > 1) {
        ll m = (l + r) / 2;

        ll cur = 0;

        forn(i, n) {
            cur += max(0ll, G[i] - m);
        }

        if (cur <= k) {
            r = m;
        }
        else {
            l = m;
        }
    }

    ll cur = k;
    forn(i, n) {
        cur -= max(0ll, G[i] - r);
        G[i] = min(G[i], r);
    }

    forn(i, n) {
        if (cur && G[i] == r) {
            cur--, G[i]--;
        }
    }
}

int solve() {
    cin >> n >> k;

    G.resize(n);

    forn(i, n)
        cin >> G[i];

    getmax();
    getmin();
    cout << *max_element(all(G)) - *min_element(all(G));
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:66777216")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <ctime>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <cassert>
#include <cstdlib>
#include <bitset>
#include <algorithm>
#include <string>
#include <list>
#include <fstream>
#include <cstring>
#include <sstream>
#include <numeric>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fornn(i, q, n) for (int i = q; i < (ll)n; i++)
#define mp make_pair
#define pk push_back
#define all(v) v.begin(), v.end()
#define times clock() * 1.0 / CLOCKS_PER_SEC

#define TASK "sum2"

const double eps = 1e-7;
const double pi = acos(-1.0);

const ll INF = (ll)2e9 + 1;
const ll LINF = (ll)8e18;
const ll inf = (ll)2e9 + 1;
const ll linf = (ll)8e18;
const ll MM = (ll)1e9 + 7;

int solve();
void gen();

int main()
{
#ifdef HOME
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#else
    //freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
    //freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout), freopen("test.txt", "w", stderr);
#endif
    solve();
    return 0;
}

const int dd = 5e5 + 7;

int n, k;
vector<ll> G;

void getmin() {
    ll l = 0, r = inf;
    while (r - l > 1) {
        ll m = (l + r) / 2;

        ll cur = 0;

        forn(i, n) {
            cur += max(0ll, m - G[i]);
        }

        if (cur <= k) {
            l = m;
        }
        else {
            r = m;
        }
    }

    int cur = k;
    forn(i, n) {
        cur -= max(0ll, l - G[i]);
        G[i] = max(G[i], l);
    }

    forn(i, n) {
        if (cur && G[i] == l) {
            cur--, G[i]++;
        }
    }
}

void getmax() {
    ll l = 0, r = inf;
    while (r - l > 1) {
        ll m = (l + r) / 2;

        ll cur = 0;

        forn(i, n) {
            cur += max(0ll, G[i] - m);
        }

        if (cur <= k) {
            r = m;
        }
        else {
            l = m;
        }
    }

    int cur = k;
    forn(i, n) {
        cur -= max(0ll, G[i] - r);
        G[i] = min(G[i], r);
    }

    forn(i, n) {
        if (cur && G[i] == r) {
            cur--, G[i]--;
        }
    }
}

int solve() {
    cin >> n >> k;

    G.resize(n);

    forn(i, n)
        cin >> G[i];

    getmax();
    getmin();
    cout << max_element(all(G)) - min_element(all(G));
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:66777216")
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <ctime>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <cassert>
#include <cstdlib>
#include <bitset>
#include <algorithm>
#include <string>
#include <list>
#include <fstream>
#include <cstring>
#include <sstream>
#include <numeric>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fornn(i, q, n) for (int i = q; i < (ll)n; i++)
#define mp make_pair
#define pk push_back
#define all(v) v.begin(), v.end()
#define times clock() * 1.0 / CLOCKS_PER_SEC

#define TASK "sum2"

const double eps = 1e-7;
const double pi = acos(-1.0);

const ll INF = (ll)2e9 + 1;
const ll LINF = (ll)8e18;
const ll inf = (ll)2e9 + 1;
const ll linf = (ll)8e18;
const ll MM = (ll)1e9 + 7;

int solve();
void gen();

int main()
{
#ifdef HOME
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#else
    //freopen(TASK".in", "r", stdin), freopen(TASK".out", "w", stdout);
    //freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout), freopen("test.txt", "w", stderr);
#endif
    solve();
    return 0;
}

const int dd = 5e5 + 7;

ll n, k;
vector<ll> G;

void getmin() {
    ll l = 0, r = linf;
    while (r - l > 1) {
        ll m = (l + r) / 2;

        ll cur = 0;

        forn(i, n) {
            cur += max(0ll, m - G[i]);
        }

        if (cur <= k) {
            l = m;
        }
        else {
            r = m;
        }
    }

    ll cur = k;
    forn(i, n) {
        cur -= max(0ll, l - G[i]);
        G[i] = max(G[i], l);
    }

    forn(i, n) {
        if (cur && G[i] == l) {
            cur--, G[i]++;
        }
    }
}

void getmax() {
    ll l = 0, r = linf;
    while (r - l > 1) {
        ll m = (l + r) / 2;

        ll cur = 0;

        forn(i, n) {
            cur += max(0ll, G[i] - m);
        }

        if (cur <= k) {
            r = m;
        }
        else {
            l = m;
        }
    }

    ll cur = k;
    forn(i, n) {
        cur -= max(0ll, G[i] - r);
        G[i] = min(G[i], r);
    }

    forn(i, n) {
        if (cur && G[i] == r) {
            cur--, G[i]--;
        }
    }
}

int solve() {
    cin >> n >> k;

    G.resize(n);

    forn(i, n)
        cin >> G[i];

    getmax();
    getmin();
    cout << *max_element(all(G)) - *min_element(all(G));
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define PII pair<int,int>
#define X first
#define Y second
#define PB push_back
#define SORT(a) sort(a.begin(), a.end())
#define CLR(a) memset(a, 0, sizeof(a))
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FOE(i,a,b) for (int i=(a);i<=(b);i++)
//#define FIT(i,a) for (__typeof__((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define FOREACH(i,a) for (auto i = (a).begin(); i != (a).end(); i++)
#define TRA(i,a,b) for (int i = (a); i != -1; i = (b)[i])
#define INF (1 << 30)
#define EPS (1e-9)
#define REP(i,n) FOR(i,0,n)
#define LL long long
#define MOD 1000000007
#define N 1000000
int n, m;
int a[N];
LL avg, sum, mx;

static inline int max(int x, int y){ return x > y ? x : y; }

int ok(int x){
    int tmp = 0;
    FOR(i,0,n){
        tmp += max(0, a[i] - x);
        if (tmp > m) break;
    }
    return tmp <= m;
}

int find(int x){
    int tmp = 0, lo = 0, hi = avg, mid;
    tmp = m;
    while(lo <= hi){
        mid = (lo + hi) >> 1;
        int ts = 0;
        FOR(i,0,n){
            ts += max(0, mid - a[i]);
            if (ts > m) break;
        }
        if (ts <= tmp){
            lo = mid + 1;
        }
        else{
            hi = mid - 1;
        }
    }
    return x - hi;
}

int main(){
    cin >> n >> m;
    FOR(i,0,n) cin >> a[i];
    sum = 0;
    mx = a[0];
    FOR(i,0,n) sum += a[i];
    avg = sum / n;
    FOR(i,0,n) mx = max(mx, a[i]);
    int lo = avg + !!(sum % n), hi = mx, mid;
    while(lo < hi){
        mid = (lo + hi) >> 1;
        if (ok(mid)){
            hi = mid;
        }
        else{
            lo = mid + 1;
        }
    }
    printf("%d\n", find(hi));
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define PII pair<int,int>
#define X first
#define Y second
#define PB push_back
#define SORT(a) sort(a.begin(), a.end())
#define CLR(a) memset(a, 0, sizeof(a))
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FOE(i,a,b) for (int i=(a);i<=(b);i++)
//#define FIT(i,a) for (__typeof__((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define FOREACH(i,a) for (auto i = (a).begin(); i != (a).end(); i++)
#define TRA(i,a,b) for (int i = (a); i != -1; i = (b)[i])
#define INF (1 << 30)
#define EPS (1e-9)
#define REP(i,n) FOR(i,0,n)
#define LL long long
#define MOD 1000000007
#define N 1000000
int n, m;
int a[N];
LL  avg, sum, mx;

static inline int max(int x, int y){ return x > y ? x : y; }

int ok(LL x){
    LL tmp = 0;
    FOR(i,0,n){
        tmp += max(0, a[i] - x);
        if (tmp > m) break;
    }
    return tmp <= m;
}

LL find(LL x){
    LL tmp = 0, lo = 0, hi = avg, mid;
    tmp = m;
    while(lo <= hi){
        mid = (lo + hi) >> 1;
        LL ts = 0;
        FOR(i,0,n){
            ts += max(0, mid - a[i]);
            if (ts > m) break;
        }
        if (ts <= tmp){
            lo = mid + 1;
        }
        else{
            hi = mid - 1;
        }
    }
    return x - hi;
}

int main(){
    cin >> n >> m;
    FOR(i,0,n) cin >> a[i];
    sum = 0;
    mx = a[0];
    FOR(i,0,n) sum += a[i];
    avg = sum / n;
    FOR(i,0,n) mx = max(mx, a[i]);
    LL lo = avg + !!(sum % n), hi = mx, mid;
    while(lo < hi){
        mid = (lo + hi) >> 1;
        if (ok(mid)){
            hi = mid;
        }
        else{
            lo = mid + 1;
        }
    }
    printf("%lld\n", find(hi));
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define PII pair<int,int>
#define X first
#define Y second
#define PB push_back
#define SORT(a) sort(a.begin(), a.end())
#define CLR(a) memset(a, 0, sizeof(a))
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FOE(i,a,b) for (int i=(a);i<=(b);i++)
//#define FIT(i,a) for (__typeof__((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define FOREACH(i,a) for (auto i = (a).begin(); i != (a).end(); i++)
#define TRA(i,a,b) for (int i = (a); i != -1; i = (b)[i])
#define INF (1 << 30)
#define EPS (1e-9)
#define REP(i,n) FOR(i,0,n)
#define LL long long
#define MOD 1000000007
#define N 1000000
int n, m;
LL a[N], avg, sum, mx;

int ok(LL x){
    LL tmp = 0;
    FOR(i,0,n) if (a[i] > x) tmp += a[i] - x;
    return tmp <= m;
}

LL find(LL x){
    LL tmp = 0, lo = 0, hi = avg, mid;
    FOR(i,0,n) if (a[i] > x){
        tmp += a[i] - x;
        a[i] = x;
    }
    tmp = m;
    while(lo <= hi){
        mid = (lo + hi) >> 1;
        LL ts = 0;
        FOR(i,0,n) if (a[i] < mid) ts += mid - a[i];
        if (ts <= tmp){
            lo = mid + 1;
        }
        else{
            hi = mid - 1;
        }
    }
    return x - hi;
}

int main(){
    cin >> n >> m;
    FOR(i,0,n) cin >> a[i];
    sum = 0;
    mx = a[0];
    FOR(i,0,n) sum += a[i];
    avg = sum / n;
    FOR(i,0,n) mx = max(mx, a[i]);
    LL lo = avg + !!(sum % n), hi = mx, mid;
    while(lo < hi){
        mid = (lo + hi) >> 1;
        if (ok(mid)){
            hi = mid;
        }
        else{
            lo = mid + 1;
        }
    }
    printf("%lld\n", find(hi));
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define PII pair<int,int>
#define X first
#define Y second
#define PB push_back
#define SORT(a) sort(a.begin(), a.end())
#define CLR(a) memset(a, 0, sizeof(a))
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FOE(i,a,b) for (int i=(a);i<=(b);i++)
//#define FIT(i,a) for (__typeof__((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define FOREACH(i,a) for (auto i = (a).begin(); i != (a).end(); i++)
#define TRA(i,a,b) for (int i = (a); i != -1; i = (b)[i])
#define INF (1 << 30)
#define EPS (1e-9)
#define REP(i,n) FOR(i,0,n)
#define LL long long
#define MOD 1000000007
#define N 1000000
int n, m;
int a[N];
LL avg, sum, mx;

static inline int max(int x, int y){ return x > y ? x : y; }

static inline int ok(int x){
    int tmp = 0;
    FOR(i,0,n){
        tmp += max(0, a[i] - x);
        if (tmp > m) break;
    }
    return tmp <= m;
}

int find(int x){
    int tmp = 0, lo = 0, hi = avg, mid;
    tmp = m;
    while(lo <= hi){
        mid = (lo + hi) >> 1;
        int ts = 0;
        FOR(i,0,n){
            ts += max(0, mid - a[i]);
            if (ts > m) break;
        }
        if (ts <= tmp){
            lo = mid + 1;
        }
        else{
            hi = mid - 1;
        }
    }
    return x - hi;
}

int main(){
    scanf("%d%d", &n, &m);
    FOR(i,0,n) scanf("%d", &a[i]);
    sum = 0;
    mx = a[0];
    FOR(i,0,n) sum += a[i];
    avg = sum / n;
    FOR(i,0,n) mx = max(mx, a[i]);
    int lo = avg + !!(sum % n), hi = mx, mid;
    while(lo <= hi){
        mid = (lo + hi) >> 1;
        if (ok(mid)){
            hi = mid - 1;
        }
        else{
            lo = mid + 1;
        }
    }
    printf("%d\n", find(lo));
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define PII pair<int,int>
#define X first
#define Y second
#define PB push_back
#define SORT(a) sort(a.begin(), a.end())
#define CLR(a) memset(a, 0, sizeof(a))
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FOE(i,a,b) for (int i=(a);i<=(b);i++)
//#define FIT(i,a) for (__typeof__((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define FOREACH(i,a) for (auto i = (a).begin(); i != (a).end(); i++)
#define TRA(i,a,b) for (int i = (a); i != -1; i = (b)[i])
#define INF (1 << 30)
#define EPS (1e-9)
#define REP(i,n) FOR(i,0,n)
#define LL long long
#define MOD 1000000007
#define N 1000000
int n, m;
LL a[N], avg, sum, mx;

int ok(LL x){
    LL tmp = 0;
    FOR(i,0,n){
        if (a[i] > x) tmp += a[i] - x;
        if (tmp > m) break;
    }
    return tmp <= m;
}

LL find(LL x){
    LL tmp = 0, lo = 0, hi = avg, mid;
    FOR(i,0,n) if (a[i] > x){
        tmp += a[i] - x;
        a[i] = x;
    }
    tmp = m;
    while(lo <= hi){
        mid = (lo + hi) >> 1;
        LL ts = 0;
        FOR(i,0,n){
            if (a[i] < mid) ts += mid - a[i];
            if (ts > m) break;
        }
        if (ts <= tmp){
            lo = mid + 1;
        }
        else{
            hi = mid - 1;
        }
    }
    return x - hi;
}

int main(){
    cin >> n >> m;
    FOR(i,0,n) cin >> a[i];
    sum = 0;
    mx = a[0];
    FOR(i,0,n) sum += a[i];
    avg = sum / n;
    FOR(i,0,n) mx = max(mx, a[i]);
    LL lo = avg + !!(sum % n), hi = mx, mid;
    while(lo < hi){
        mid = (lo + hi) >> 1;
        if (ok(mid)){
            hi = mid;
        }
        else{
            lo = mid + 1;
        }
    }
    printf("%lld\n", find(hi));
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define PII pair<int,int>
#define X first
#define Y second
#define PB push_back
#define SORT(a) sort(a.begin(), a.end())
#define CLR(a) memset(a, 0, sizeof(a))
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FOE(i,a,b) for (int i=(a);i<=(b);i++)
//#define FIT(i,a) for (__typeof__((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define FOREACH(i,a) for (auto i = (a).begin(); i != (a).end(); i++)
#define TRA(i,a,b) for (int i = (a); i != -1; i = (b)[i])
#define INF (1 << 30)
#define EPS (1e-9)
#define REP(i,n) FOR(i,0,n)
#define LL long long
#define MOD 1000000007
#define N 1000000
int n, m;
LL a[N], avg, sum, mx;

int ok(LL x){
    LL tmp = 0;
    FOR(i,0,n) if (a[i] > x) tmp += a[i] - x;
    return tmp <= m;
}

LL find(LL x){
    LL tmp = 0, lo = 0, hi = avg, mid;
    FOR(i,0,n) if (a[i] > x) tmp += a[i] - x;
    while(lo <= hi){
        mid = (lo + hi) >> 1;
        LL ts = 0;
        FOR(i,0,n) if (a[i] < mid) ts += mid - a[i];
        if (ts <= tmp){
            lo = mid + 1;
        }
        else{
            hi = mid - 1;
        }
    }
    return x - hi;
}

int main(){
    cin >> n >> m;
    FOR(i,0,n) cin >> a[i];
    sum = 0;
    mx = a[0];
    FOR(i,0,n) sum += a[i];
    avg = sum / n;
    FOR(i,0,n) mx = max(mx, a[i]);
    LL lo = avg + !!(sum % n), hi = mx, mid;
    while(lo < hi){
        mid = (lo + hi) >> 1;
        if (ok(mid)){
            hi = mid;
        }
        else{
            lo = mid + 1;
        }
    }
    printf("%lld\n", find(hi));
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define PII pair<int,int>
#define X first
#define Y second
#define PB push_back
#define SORT(a) sort(a.begin(), a.end())
#define CLR(a) memset(a, 0, sizeof(a))
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FOE(i,a,b) for (int i=(a);i<=(b);i++)
//#define FIT(i,a) for (__typeof__((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define FOREACH(i,a) for (auto i = (a).begin(); i != (a).end(); i++)
#define TRA(i,a,b) for (int i = (a); i != -1; i = (b)[i])
#define INF (1 << 30)
#define EPS (1e-9)
#define REP(i,n) FOR(i,0,n)
#define LL long long
#define MOD 1000000007
#define N 1000000
int n, m;
int a[N];
LL avg, sum, mx;

static inline int max(int x, int y){ return x > y ? x : y; }

int ok(int x){
    int tmp = 0;
    FOR(i,0,n){
        tmp += max(0, a[i] - x);
        if (tmp > m) break;
    }
    return tmp <= m;
}

int find(int x){
    int tmp = 0, lo = 0, hi = avg, mid;
    tmp = m;
    while(lo <= hi){
        mid = (lo + hi) >> 1;
        int ts = 0;
        FOR(i,0,n){
            ts += max(0, mid - a[i]);
            if (ts > m) break;
        }
        if (ts <= tmp){
            lo = mid + 1;
        }
        else{
            hi = mid - 1;
        }
    }
    return x - hi;
}

int main(){
    cin >> n >> m;
    FOR(i,0,n) cin >> a[i];
    sum = 0;
    mx = a[0];
    FOR(i,0,n) sum += a[i];
    avg = sum / n;
    FOR(i,0,n) mx = max(mx, a[i]);
    int lo = avg + !!(sum % n), hi = mx, mid;
    while(lo < hi){
        mid = (lo + hi) >> 1;
        if (ok(mid)){
            hi = mid;
        }
        else{
            lo = mid + 1;
        }
    }
    printf("%lld\n", find(hi));
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define PII pair<int,int>
#define X first
#define Y second
#define PB push_back
#define SORT(a) sort(a.begin(), a.end())
#define CLR(a) memset(a, 0, sizeof(a))
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FOE(i,a,b) for (int i=(a);i<=(b);i++)
//#define FIT(i,a) for (__typeof__((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define FOREACH(i,a) for (auto i = (a).begin(); i != (a).end(); i++)
#define TRA(i,a,b) for (int i = (a); i != -1; i = (b)[i])
#define INF (1 << 30)
#define EPS (1e-9)
#define REP(i,n) FOR(i,0,n)
#define LL long long
#define MOD 1000000007
#define N 1000000
int n, m;
int a[N];
LL avg, sum, mx;

static inline int max(int x, int y){ return x > y ? x : y; }

static inline int ok(int x){
    int tmp = 0;
    FOR(i,0,n){
        tmp += max(0, a[i] - x);
        if (tmp > m) break;
    }
    return tmp <= m;
}

int find(int x){
    int tmp = 0, lo = 0, hi = avg, mid;
    tmp = m;
    while(lo <= hi){
        mid = (lo + hi) >> 1;
        int ts = 0;
        FOR(i,0,n){
            ts += max(0, mid - a[i]);
            if (ts > m) break;
        }
        if (ts <= tmp){
            lo = mid + 1;
        }
        else{
            hi = mid - 1;
        }
    }
    return x - hi;
}

int main(){
    cin >> n >> m;
    FOR(i,0,n) cin >> a[i];
    sum = 0;
    mx = a[0];
    FOR(i,0,n) sum += a[i];
    avg = sum / n;
    FOR(i,0,n) mx = max(mx, a[i]);
    int lo = avg + !!(sum % n), hi = mx, mid;
    while(lo <= hi){
        mid = (lo + hi) >> 1;
        if (ok(mid)){
            hi = mid - 1;
        }
        else{
            lo = mid + 1;
        }
    }
    printf("%d\n", find(lo));
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<bitset>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define PII pair<int,int>
#define X first
#define Y second
#define PB push_back
#define SORT(a) sort(a.begin(), a.end())
#define CLR(a) memset(a, 0, sizeof(a))
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FOE(i,a,b) for (int i=(a);i<=(b);i++)
//#define FIT(i,a) for (__typeof__((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define FOREACH(i,a) for (auto i = (a).begin(); i != (a).end(); i++)
#define TRA(i,a,b) for (int i = (a); i != -1; i = (b)[i])
#define INF (1 << 30)
#define EPS (1e-9)
#define REP(i,n) FOR(i,0,n)
#define LL long long
#define MOD 1000000007
#define N 1000000
int n, m;
int a[N], avg, sum, mx;

static inline int max(int x, int y){ return x > y ? x : y; }

int ok(LL x){
    LL tmp = 0;
    FOR(i,0,n){
        tmp += max(0, a[i] - x);
        if (tmp > m) break;
    }
    return tmp <= m;
}

LL find(LL x){
    LL tmp = 0, lo = 0, hi = avg, mid;
    tmp = m;
    while(lo <= hi){
        mid = (lo + hi) >> 1;
        LL ts = 0;
        FOR(i,0,n){
            ts += max(0, mid - a[i]);
            if (ts > m) break;
        }
        if (ts <= tmp){
            lo = mid + 1;
        }
        else{
            hi = mid - 1;
        }
    }
    return x - hi;
}

int main(){
    cin >> n >> m;
    FOR(i,0,n) cin >> a[i];
    sum = 0;
    mx = a[0];
    FOR(i,0,n) sum += a[i];
    avg = sum / n;
    FOR(i,0,n) mx = max(mx, a[i]);
    LL lo = avg + !!(sum % n), hi = mx, mid;
    while(lo < hi){
        mid = (lo + hi) >> 1;
        if (ok(mid)){
            hi = mid;
        }
        else{
            lo = mid + 1;
        }
    }
    printf("%lld\n", find(hi));
    return 0;
}