import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class CF259_Little_Pony_and_Crystal_mine {
	public static void main(String[] args) {
		MyScanner in = new MyScanner();

		int n = in.nextInt();

		char[][] matrix = new char[n][n];

		int dPos = (int)Math.floor(n/2)-1;
		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < n; j++)
			{
				if(i < Math.floor(n/2))
				{
					if(j >= Math.floor(n/2)-i && j <= Math.floor(n/2)+i )
					{
						matrix[i][j] = 'D';
					}
					else
					{
						matrix[i][j] = '*';
					}

				}
				else if(i == Math.floor(n/2))
				{
					matrix[i][j] = 'D';
				}
				else
				{
					if(j >= Math.floor(n/2)-dPos && j <= Math.floor(n/2)+dPos)
					{
						matrix[i][j] = 'D';
					}
					else
					{
						matrix[i][j] = '*';
					}
				}
			}
			if(i > Math.floor(n/2))
			{
				dPos--;
			}
		}

		for(int i = 0; i < n; i++)
		{
			System.out.println("");
			for(int j = 0; j < n; j++)
			{
				System.out.print(matrix[i][j]);
			}
		}

	}

	// -----------MyScanner class for faster input----------
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	// --------------------------------------------------------
}


import java.util.Scanner;
public class diamond {

    public static void main(String[] args) {
        // TODO code application logic here
        Scanner s = new Scanner(System.in);
        int n = s.nextInt(); //5
        for(int i=0;i<(n/2+1);i++) //3
        {
            //1st half
            for(int j=(n/2);j>i;j--)  //3-0
            {
                System.out.print("*");
            }
            for(int k=0;k<(2*i+1);k++) //0-3
                {
                    System.out.print("D");
                }

              for(int j=(n/2);j>i;j--)  //3-0
            {
                System.out.print("*");
            }
            System.out.println();

        }
          for(int i=n/2;i>0;i--) //2
        {
            //1st half
               for(int j=(n/2);j>=i;j--)  //3-0
            {
                System.out.print("*");
            }

            for(int k=(2*(i-1)+1);k>0;k--) //0-3
                {
                    System.out.print("D");
                }

                 for(int j=(n/2);j>=i;j--)  //3-0
            {
                System.out.print("*");
            }
            System.out.println();

        }
    }
}


import java.util.Scanner;
import java.io.*;
public class diamond {

    public static void main(String[] args) {
        // TODO code application logic here
        Scanner s = new Scanner(System.in);
        int n = s.nextInt(); //5
        int NUM=(n-1)/2;

for(int i=-NUM; i<=NUM; i++)

{

for(int j=-NUM; j<=NUM; j++)

{

if( Math.abs(i)+Math.abs(j)<=NUM) // Change this condition

 { System.out.print("D"); }

else { System.out.print("*");}

}
System.out.println();
}

    }
}


import java.io.*;
import java.util.*;
  public class Main
{
    public static void main(String args[])
    {
        Scanner in = new Scanner(System.in);

        //DataInputStream in = new DataInputStream(System.in);
        int arr[] = new int[1003];
        int n,a;

        n = in.nextInt();
        int k=n/2;
        int c=1;
        for(int i=1;i<=n/2;i++)
        {
            for(int l=1;l<=k;l++)
                System.out.print("*");

            for(int l=1;l<=c;l++)
                System.out.print("D");

            for(int l=1;l<=k;l++)
                System.out.print("*");
                System.out.println();
            k--;
            c+=2;
        }

        for(int i=1;i<=n;i++)
            System.out.print("D");
        System.out.println();
        c=n-2;
        k= 1;

        for(int i=1;i<=n/2;i++)
        {
             for(int l=1;l<=k;l++)
                System.out.print("*");

            for(int l=1;l<=c;l++)
                System.out.print("D");

            for(int l=1;l<=k;l++)
                System.out.print("*");
            System.out.println();
            c-=2;
            k++;
        }
        System.out.println();
    }
}


import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    int n = new Scanner(System.in).nextInt();
    int width = 1, step = 2;

    for (int i = 0; i < n; ++i) {
      int offset = (n - width) / 2;

      if (i == n / 2) {
        step *= -1;
      }

      for (int j = 0; j < offset; ++j) {
        System.out.print('*');
      }

      for (int j = 0; j < width; ++j) {
        System.out.print('D');
      }

      for (int j = 0; j <= offset; ++j) {
        System.out.print(j != offset ? '*' : "\n");
      }

      width += step;
    }
  }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {

		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		int x = Integer.valueOf(reader.readLine());
		int star = x / 2;
		String[] string = new String[x / 2 + 1];
		int index = 0;
		for (int i = 1; i <= x; i += 2, index++) {
			string[index] = "";
			for (int j = 1; j <= star; j++) {
				string[index] += "*";
				System.out.print("*");
			}
			for (int j = 1; j <= i; j++) {
				string[index] += "D";
				System.out.print("D");
			}
			for (int j = 1; j <= star; j++) {
				string[index] += "*";
				System.out.print("*");
			}
			star--;
			System.out.println();
		}
		for (int i = string.length - 2; i >= 0; i--) {
			System.out.println(string[i]);
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {

		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		int x = Integer.valueOf(reader.readLine());
		int star = x / 2;
		String[] string = new String[x / 2 + 1];
		int index = string.length - 1;
		for (int i = 1; i <= x; i += 2, index--) {
			string[index] = "";
			for (int j = 1; j <= star; j++) {
				string[index] += "*";
				System.err.print("*");
			}
			for (int j = 1; j <= i; j++) {
				string[index] += "D";
				System.err.print("D");
			}
			for (int j = 1; j <= star; j++) {
				string[index] += "*";
				System.err.print("*");
			}
			star--;
			System.err.println();
		}
		for (int i = 1; i < string.length ; i++) {
			System.err.println(string[i]);
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {

		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		int x = Integer.valueOf(reader.readLine());
		int star = x / 2;
		String[] string = new String[x / 2 + 1];
		int index = string.length - 1;
		for (int i = 1; i <= x; i += 2, index--) {
			string[index] = "";
			for (int j = 1; j <= star; j++) {
				string[index] += "*";
				System.out.print("*");
			}
			for (int j = 1; j <= i; j++) {
				string[index] += "D";
				System.out.print("D");
			}
			for (int j = 1; j <= star; j++) {
				string[index] += "*";
				System.out.print("*");
			}
			star--;
			System.out.println();
		}
		for (int i = 1; i < string.length ; i++) {
			System.out.println(string[i]);
		}
	}
}


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class CrystalMine {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		FileInputStream input = null;
		try {
			input = new FileInputStream("input.txt");
		} catch (FileNotFoundException e2) {
			e2.printStackTrace();
		}
		Scanner scan = null;
		scan = new Scanner(input);
		// cargo datos
		int n =scan.nextInt();
		String[]  crystal = new String [n];
		for (int i = 0 ; i< (n-1)/2; i++){
			crystal[i] = new String();
			for (int j = 0 ; j< Math.abs(((n -(2*i +1)) /2))  ; j++ ){
				crystal[i] += '*';
			}
			for (int j = Math.abs(((n -(2*i +1)) /2)); j < Math.abs(((n -(2*i +1)) /2)) + 2*i +1  ; j++ ){
				crystal[i] += 'D';
			}
			for (int j =Math.abs(((n -(2*i +1)) /2)) + 2*i +1; j < n  ; j++ ){
				crystal[i] += '*';
			}
		}
		crystal[((n-1)/2)] = new String();
		for (int i = 0 ; i<n;i++){
			crystal[((n-1)/2)] += "D";
		}
		for (int i = ((n-1)/2)+1; i < n ;i++){
			crystal[i] = new String();
			crystal[i] = crystal[Math.abs(i- (n -1))];
		}
		File output = new File("output.txt");
		FileWriter fOut = null;
		try {
			fOut = new FileWriter(output);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		try {
			for (int i = 0; i<n ;i++)
				fOut.write(crystal[i] + '\n') ;
			fOut.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}


import java.util.Scanner;

public class CrystalMine {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scan = null;
		scan = new Scanner(System.in);
		// cargo datos
		int n =scan.nextInt();
		String[]  crystal = new String [n];
		for (int i = 0 ; i< (n-1)/2; i++){
			crystal[i] = new String();
			for (int j = 0 ; j< Math.abs(((n -(2*i +1)) /2))  ; j++ ){
				crystal[i] += '*';
			}
			for (int j = Math.abs(((n -(2*i +1)) /2)); j < Math.abs(((n -(2*i +1)) /2)) + 2*i +1  ; j++ ){
				crystal[i] += 'D';
			}
			for (int j =Math.abs(((n -(2*i +1)) /2)) + 2*i +1; j < n  ; j++ ){
				crystal[i] += '*';
			}
		}
		crystal[((n-1)/2)] = new String();
		for (int i = 0 ; i<n;i++){
			crystal[((n-1)/2)] += "D";
		}
		for (int i = ((n-1)/2)+1; i < n ;i++){
			crystal[i] = new String();
			crystal[i] = crystal[Math.abs(i- (n -1))];
		}

			for (int i = 0; i<n ;i++)
				System.out.println(crystal[i]) ;

	}

}


import java.util.*;
public class Main{
    static Scanner in=new Scanner(System.in);
    public static void main(String[] args)
    {
        int n=in.nextInt();
        int odd=1;
        for(int i=n/2;i>=1;i--)
        {
            for(int j=1;j<=i;j++)
                System.out.print("*");
            for(int j=0;j<odd;j++)
                System.out.print("D");
            odd+=2;
            for(int j=1;j<=i;j++)
                System.out.print("*");
            System.out.println();
        }
        for(int i=0;i<n;i++)
            System.out.print("D");
        System.out.println();
        odd-=2;
        for(int i=1;i<=n/2;i++)
        {
            for(int j=1;j<=i;j++)
                System.out.print("*");
            for(int j=odd;j>=1;j--)
                System.out.print("D");
            odd-=2;
            for(int j=1;j<=i;j++)
                System.out.print("*");
            System.out.println();

        }

    }

}


/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
    public static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner sc= new Scanner(System.in);
        f(sc.nextInt(), 1);
        bw.flush();
    }
    public static void f(int n, int x) throws Exception{
        for(int i = 0; i < (n-x)/2; i++) bw.write("*");
        for(int i = 0 ; i < x; i++) bw.write("D");
        for(int i = 0; i < (n-x)/2; i++) bw.write("*");
        bw.newLine();
        if(x == n) return;
        f(n, x+2);
        for(int i = 0; i < (n-x)/2; i++) bw.write("*");
        for(int i = 0 ; i < x; i++) bw.write("D");
        for(int i = 0; i < (n-x)/2; i++) bw.write("*");
        bw.newLine();
    }
}


import java.util.*;
public class Main{
    public static void main(String arg[]){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        StringBuilder ans = new StringBuilder();
        int cnt = n / 2;
        for(int i = 0;i < n;i++){
            for(int j = 0;j < n;j++){
                if(j < cnt){
                    ans.append("*");
                }else if(j > n - cnt - 1){
                    ans.append("*");
                }else{
                    ans.append("D");
                }
            }
            ans.append("\n");
            if(i < n / 2){
                cnt--;
            }else{
                cnt++;
            }
        }
        System.out.println(ans);
    }
}


import java.util.*;
public class Main{
    public static void main(String arg[]){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        StringBuilder ans = new StringBuilder();
        for(int i = 0;i < n;i++){
            for(int j = 0;j < n;j++){
                if(i == 0 && j == 0){
                    ans.append("*");
                }else if(i == 0 && j == n - 1){
                    ans.append("*");
                }else if(i == n - 1 && j == 0){
                    ans.append("*");
                }else if(i == n - 1 && j == n - 1){
                    ans.append("*");
                }else{
                    ans.append("D");
                }
            }
            ans.append("\n");
        }
        System.out.println(ans);
    }
}


import java.util.Scanner;

public class LittlePonyAndCrystalMine {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		int half = n/2;
		for (int i = 0; i <= half; i++)
		{
			int numOfDiamonds = i+i+1;
			for (int j = 0; j < half-numOfDiamonds/2; j++)
			{
				System.out.print('*');
			}
			for (int j = 0; j < numOfDiamonds; j++)
			{
				System.out.print('D');
			}
			for (int j = 0; j < half-numOfDiamonds/2; j++)
			{
				System.out.print('*');
			}
			System.out.print("\n");
		}
		for (int i = half-1; i >= 0; i--)
		{
			int numOfDiamonds = i+i+1;
			for (int j = 0; j < half-numOfDiamonds/2; j++)
			{
				System.out.print('*');
			}
			for (int j = 0; j < numOfDiamonds; j++)
			{
				System.out.print('D');
			}
			for (int j = 0; j < half-numOfDiamonds/2; j++)
			{
				System.out.print('*');
			}
			System.out.print("\n");
		}
	}
}


import java.util.Scanner;

public class Mine {
  private static void printLine(int i, int n) {
    int c = n / 2;
    int r = i / 2;
    char[] a = new char[n];
    for (int j = 0; j < n; j++) {
      a[j] = Math.abs(j - c) <= r ? 'D' : '*';
    }
    System.out.println(new String(a));
  }
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    for (int i = 1; i <= n; i += 2) {
      printLine(i, n);
    }
    for (int i = n - 2; i >= 1; i -= 2) {
      printLine(i, n);
    }
  }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class A {

    public static void main(String[] args) {
        InputScanner scanner = new InputScanner();

        try {
            String star = "*";
            String d = "D";
            int n = scanner.nextInt();

            int stars = n/2;
            int diamonds = 1;
            for (int i = 1; i <=n; i++) {
                for (int j = 0; j < stars; j++) {
                    System.out.print(star);
                }
                for (int j = 0; j < diamonds; j++) {
                    System.out.print(d);
                }
                for (int j = 0; j < stars; j++) {
                    System.out.print(star);
                }
                if (i<(n/2+1)){
                    stars--;
                    diamonds+=2;
                }else{
                    stars++;
                    diamonds-=2;
                }
                System.out.println();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static class InputScanner {

        BufferedReader br;
        StringTokenizer st;

        public InputScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() throws IOException {
            if (st == null || !st.hasMoreTokens()) {
                String line = br.readLine();
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            String next = next();
            next.length();
            return Integer.parseInt(next);
        }
    }
}


public class A {

    public static void main(String[] args) {
        InputScanner scanner = new InputScanner();

        try {
            String star = "*";
            String d = "D";
            int n = scanner.nextInt();

            int stars = n/2;
            int diamonds = 1;
            for (int i = 1; i <=n; i++) {
                for (int j = 0; j < stars; j++) {
                    System.out.print(star);
                }
                for (int j = 0; j < diamonds; j++) {
                    System.out.print(d);
                }
                for (int j = 0; j < stars; j++) {
                    System.out.print(star);
                }
                if (i<(n/2+1)){
                    stars--;
                    diamonds+=2;
                }else{
                    stars++;
                    diamonds-=2;
                }
                System.out.println();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static class InputScanner {

        BufferedReader br;
        StringTokenizer st;

        public InputScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() throws IOException {
            if (st == null || !st.hasMoreTokens()) {
                String line = br.readLine();
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            String next = next();
            next.length();
            return Integer.parseInt(next);
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Created by Dmytro_Veres on 8/19/2014.
 */
public class Crystal {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for (int i = 0; i < n; i++) {
            int pivot1 = Math.abs(n / 2 - i);
            int pivot2 = n - Math.abs(n / 2 - i);
            for (int j = 0; j < pivot1; j++) {
                System.out.print("*");
            }
            for (int j = pivot1; j < pivot2; j++) {
                System.out.print("D");
            }
            for (int j = pivot2; j < n; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Created by Dmytro_Veres on 8/19/2014.
 */
public class Crystal {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for (int i = 0; i < n; i++) {
            int pivot1 = n / 2 - (n / 2 - Math.abs(n / 2 - i));
            int pivot2 = n - Math.abs(n / 2 - i);
            for (int j = 0; j < pivot1; j++) {
                System.out.print("*");
            }
            for (int j = pivot1; j < pivot2; j++) {
                System.out.print("D");
            }
            for (int j = pivot2; j < n; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}


package contest259;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;

public class A259
{

	public static ArrayList<Integer> strToInts(String str, String token)
	{
		ArrayList<Integer> result = new ArrayList<Integer>();
		String[] strs = str.split(token);
		for (String string : strs)
			result.add(Integer.parseInt(string));
		return result;
	}

	public static ArrayList<Long> strToLong(String str, String token)
	{
		ArrayList<Long> result = new ArrayList<Long>();
		ArrayList<String> strs = new ArrayList<String>(Arrays.asList(str.split(token)));
		for (String string : strs)
		{
			result.add(Long.parseLong(string));
		}
		return result;
	}

	public static ArrayList<Double> strToDouble(String str, String token)
	{
		ArrayList<Double> result = new ArrayList<Double>();
		ArrayList<String> strs = new ArrayList<String>(Arrays.asList(str.split(token)));
		for (String string : strs)
		{
			result.add(Double.parseDouble(string));
		}
		return result;
	}

	public static void main(String[] args) throws IOException
	{

		// The input and output streams
		 BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); // system
		//BufferedReader in = new BufferedReader(new FileReader("input.txt"));
		BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

		// Take input
		ArrayList<Integer> params = strToInts(in.readLine(), " ");
		int n = params.get(0);
		StringBuilder ans = new StringBuilder();

		int currentD = 1;
		// ascned
		for (int i = 0; i < n / 2; i++)
		{

			int nDiamonds = currentD;

			int stars = (n - nDiamonds) / 2;
			for (int j = 0; j < stars; j++)
				ans.append("*");
			for (int j = 0; j < nDiamonds; j++)
				ans.append("D");
			for (int j = 0; j < stars; j++)
				ans.append("*");
			ans.append("\n");
			currentD += 2;
		}

		// all diamonds
		for (int i = 0; i < n; i++)
			ans.append("D");
		ans.append("\n");
		currentD -= 2;

		// descend
		for (int i = 0; i < n / 2; i++)
		{

			int nDiamonds = currentD;

			int stars = (n - nDiamonds) / 2;
			for (int j = 0; j < stars; j++)
				ans.append("*");
			for (int j = 0; j < nDiamonds; j++)
				ans.append("D");
			for (int j = 0; j < stars; j++)
				ans.append("*");
			ans.append("\n");
			currentD -= 2;
		}

		System.out.println(ans.toString());
		out.flush();

	}

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;

public class A259
{

	public static ArrayList<Integer> strToInts(String str, String token)
	{
		ArrayList<Integer> result = new ArrayList<Integer>();
		String[] strs = str.split(token);
		for (String string : strs)
			result.add(Integer.parseInt(string));
		return result;
	}

	public static ArrayList<Long> strToLong(String str, String token)
	{
		ArrayList<Long> result = new ArrayList<Long>();
		ArrayList<String> strs = new ArrayList<String>(Arrays.asList(str.split(token)));
		for (String string : strs)
		{
			result.add(Long.parseLong(string));
		}
		return result;
	}

	public static ArrayList<Double> strToDouble(String str, String token)
	{
		ArrayList<Double> result = new ArrayList<Double>();
		ArrayList<String> strs = new ArrayList<String>(Arrays.asList(str.split(token)));
		for (String string : strs)
		{
			result.add(Double.parseDouble(string));
		}
		return result;
	}

	public static void main(String[] args) throws IOException
	{

		// The input and output streams
		 BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); // system
		//BufferedReader in = new BufferedReader(new FileReader("input.txt"));
		BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

		// Take input
		ArrayList<Integer> params = strToInts(in.readLine(), " ");
		int n = params.get(0);
		StringBuilder ans = new StringBuilder();

		int currentD = 1;
		// ascned
		for (int i = 0; i < n / 2; i++)
		{

			int nDiamonds = currentD;

			int stars = (n - nDiamonds) / 2;
			for (int j = 0; j < stars; j++)
				ans.append("*");
			for (int j = 0; j < nDiamonds; j++)
				ans.append("D");
			for (int j = 0; j < stars; j++)
				ans.append("*");
			ans.append("\n");
			currentD += 2;
		}

		// all diamonds
		for (int i = 0; i < n; i++)
			ans.append("D");
		ans.append("\n");
		currentD -= 2;

		// descend
		for (int i = 0; i < n / 2; i++)
		{

			int nDiamonds = currentD;

			int stars = (n - nDiamonds) / 2;
			for (int j = 0; j < stars; j++)
				ans.append("*");
			for (int j = 0; j < nDiamonds; j++)
				ans.append("D");
			for (int j = 0; j < stars; j++)
				ans.append("*");
			ans.append("\n");
			currentD -= 2;
		}

		System.out.println(ans.toString());
		out.flush();

	}

}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n =sc.nextInt() ;

		int star = n/2 ;
		int d = 1 ;
		while(d<=n){
			for(int i = 0 ; i < star;i++)pw.print("*");
			for(int i = 0 ; i < d ; i++)pw.print("D");
			for(int i = 0 ; i < star;i++)pw.print("*");
			pw.println();
			d+=2 ;
			star--;
		}
		d-=4;
		star+=2;

		while(d>0){
			for(int i = 0 ; i < star;i++)pw.print("*");
			for(int i = 0 ; i < d ; i++)pw.print("D");
			for(int i = 0 ; i < star;i++)pw.print("*");
			pw.println();
			d-=2 ;
			star++;
		}

		pw.close();
		pw.flush();
		// int n = sc.nextInt() ;
		// for(int i = 0 ; i < n ; i ++)
		// {
		// String tmp = sc.nextLine();
		// String s = tmp.substring(4, tmp.length()) ;
		// Long x = Long.parseLong(s);
		//
		// Long result = 0L ;
		// System.out.println(result);
		// }
	}
}

class Triple {
	long x, y, z;

	public Triple(long a, long b, long c) {
		x = a;
		y = b;
		z = c;
	}
}

class Pair implements Comparable<Pair> {
	String t;
	String a;

	Pair(String f, String b) {
		t = f;
		a = b;
	}

	@Override
	public int compareTo(Pair o) {
		// TODO Auto-generated method stub
		return a.compareTo(o.a) == 0 ? t.compareTo(o.t) : a.compareTo(o.a);
	}

}

class Scanner {
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream s) {
		br = new BufferedReader(new InputStreamReader(s));
	}

	public Scanner(FileReader f) {
		br = new BufferedReader(f);
	}

	public String next() throws IOException {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

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

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

	public String nextLine() throws IOException {
		return br.readLine();
	}

	public double nextDouble() throws IOException {
		String x = next();
		StringBuilder sb = new StringBuilder("0");
		double res = 0, f = 1;
		boolean dec = false, neg = false;
		int start = 0;
		if (x.charAt(0) == '-') {
			neg = true;
			start++;
		}
		for (int i = start; i < x.length(); i++)
			if (x.charAt(i) == '.') {
				res = Long.parseLong(sb.toString());
				sb = new StringBuilder("0");
				dec = true;
			} else {
				sb.append(x.charAt(i));
				if (dec)
					f *= 10;
			}
		res += Long.parseLong(sb.toString()) / f;
		return res * (neg ? -1 : 1);
	}

	public boolean ready() throws IOException {
		return br.ready();
	}

}


package test;

/**
 *
 * @author Mourad
 */
import java.util.Scanner;

public class Test {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n;
        do {
            n = s.nextInt();
        } while (n % 2 == 0 || n > 101 || n < 3);
        int d = 1;
        int j;
        for (int i = 0; i < n / 2; i++) {

            for (j = 0; j < n / 2 - i; j++) {
                System.out.print("*");
            }
            for (j = 0; j < d; j++) {
                System.out.print("D");
            }
            d += 2;
            for (j = 0; j < n / 2 - i; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
        for (j = 0; j < n; j++) {
            System.out.print("D");
        }
        System.out.println();
        d-=2;
        for (int i = n/2-1; i >=0; i--) {

            for (j = 0; j < n / 2 - i; j++) {
                System.out.print("*");
            }
            for (j = 0; j < d; j++) {
                System.out.print("D");
            }
            d -= 2;
            for (j = 0; j < n / 2 - i; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

}


import java.util.Scanner;

public class Test {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n;
        do {
            n = s.nextInt();
        } while (n % 2 == 0 || n > 101 || n < 3);
        int d = 1;
        int j;
        for (int i = 0; i < n / 2; i++) {

            for (j = 0; j < n / 2 - i; j++) {
                System.out.print("*");
            }
            for (j = 0; j < d; j++) {
                System.out.print("D");
            }
            d += 2;
            for (j = 0; j < n / 2 - i; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
        for (j = 0; j < n; j++) {
            System.out.print("D");
        }
        System.out.println();
        d-=2;
        for (int i = n/2-1; i >=0; i--) {

            for (j = 0; j < n / 2 - i; j++) {
                System.out.print("*");
            }
            for (j = 0; j < d; j++) {
                System.out.print("D");
            }
            d -= 2;
            for (j = 0; j < n / 2 - i; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class LittlePonyandCrystalMine {

	static Character[][] matrix;
	static int n;

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			n = Integer.parseInt(br.readLine().trim());
			matrix = new Character[n][n];
			long timeStart = System.currentTimeMillis();
			LittlePonyandCrystalMine pm = new LittlePonyandCrystalMine();
			pm.test();

			long timeStop = System.currentTimeMillis();
			//System.out.println(timeStop-timeStart);
			 for (int i=0;i<n;i++){
					for (int j=0;j<n;j++){
					    System.out.print(matrix[i][j]);
					}
					System.out.println();
				    }

		} catch (IOException e) {

		}
	}
	private void test() {
		Thread prepare = new Thread(new Prepare());
		prepare.start();
		try {
			prepare.join();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Thread quadranA = new Thread(new QuadranA());
		Thread quadranB = new Thread(new QuadranB());
		Thread quadranC = new Thread(new QuadranC());
		Thread quadranD = new Thread(new QuadranD());
		quadranA.start();
		quadranB.start();
		quadranC.start();
		quadranD.start();

		try {
			prepare.join();
			quadranA.join();
			quadranB.join();
			quadranC.join();
			quadranD.join();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	class QuadranA implements Runnable {

		@Override
		public void run() {
			 for (int i=0;i<=n/2;i++){
					for (int j=n/2;j>=(n/2)-i;j--){
					    matrix[i][j] = 'D';
					}
				    }
		}

	}
	class QuadranB implements Runnable {

		@Override
		public void run() {
			for (int i=0;i<=n/2;i++){
				for (int j=n/2+1;j<n/2+i+1;j++){
				    matrix[i][j] = 'D';
				}
			    }

		}

	}
	class QuadranC implements Runnable {

		@Override
		public void run() {
			 int k = 0 ;
			    for (int i=n/2+1;i<n;i++){
				k++;
				for (int j=k;j<=n/2;j++){
				    matrix[i][j] = 'D';
				}
			    }

		}

	}
	class QuadranD implements Runnable {

		@Override
		public void run() {

			 int k=0;
			    for (int i=n/2+1;i<n;i++){
				k++;
				for (int j=n/2+1;j<n-k;j++){
				    matrix[i][j]='D';
				}
			    }

		}

	}

	class Prepare implements Runnable {

		@Override
		public void run() {

			 for (int i=0;i<n;i++){
					for (int j=0;j<n;j++){
					    matrix[i][j] = '*';
					}
				    }
		}

	}
}


import java.util.Scanner;
public class LittlePony{

public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
/*try{

n=System.in.read()-48;
}catch(Exception e){}*/

String[] s=new String[(n>>>1)+1];

	for(int j=1;j <= n;j +=2)
	{
	StringBuilder str=new StringBuilder("");

		for(int k=1;k<=((n-j)>>>1);k++)
		{
			str.append("*");

		}
		for(int k=1;k<=j;k++)
		{

			str.append("D");
		}
		for(int k=1;k<=((n-j)>>>1);k++)
		{
			str.append("*");
		}
		s[j>>>1]=str.toString();
		System.out.println(str);

	}
for(int i=(n>>>1)-1;i>=0;i--)
	System.out.println(s[i]);

}

}


import java.util.Scanner;
import java.util.Arrays;

public class a1 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n=sc.nextInt();
		String d="D";
		String k="*";
		String answer="";
		for(int i=((n-1)/2);i>=-(n-1)/2;i--){
			for(int j=1;j<=Math.abs(i);j++)
				answer+=k;
			for(int j=1;j<=n-2*Math.abs(i);j++)
				answer+=d;
			for(int j=1;j<=Math.abs(i);j++)
				answer+=k;
			answer+="\n";

		}
		System.out.println(answer);
	}

}


package acmmart;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class crystal {
	public static void main (String[] args){
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int cd = 1;
		boolean sumo = true;
		for (int f = 0; f<n;f++){
			String a = "";
			String d = "";
			for (int c = 0; c<((n-cd)/2); c++){
				a = a + "*";
			}
			for (int c = 0; c<cd; c++){
				d = d + "D";
			}
			if (cd == n) {sumo = !sumo;}
			if (sumo) { cd += 2; } else {cd -=2;}
			System.out.println( a + d + a);
		}

	}
}


import java.util.Scanner;

public class Main {
    public static void main (String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int cd = 1;
        boolean sumo = true;
        for (int f = 0; f<n;f++){
            String a = "";
            String d = "";
            for (int c = 0; c<((n-cd)/2); c++){
                a = a + "*";
            }
            for (int c = 0; c<cd; c++){
                d = d + "D";
            }
            if (cd == n) {sumo = !sumo;}
            if (sumo) { cd += 2; } else {cd -=2;}
            System.out.println( a + d + a);
        }

    }
}


import java.util.Scanner;

public class LittlePonyandCrystalMine {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		/*for (int i = 1; i <= n; i++) {
			for (int j = i; j <=n; j++) {
				System.out.print("D");
			}
			System.out.println();
		}*/
		/*for (int i = 1; i <= n; i++) {
			for (int j = 1; j <=i; j++) {
				System.out.print("D");
			}
			System.out.println();
		}
		for (int i = 1; i <= n; i++) {
			for (int j = i; j <=n-1; j++) {
				System.out.print("D");
			}
			System.out.println();
		}*/
		int i,j;
		int uppos=n/2,midpos=n/2+1,downpos=uppos;
		int left=n/2,mid=n/2+1,right=left;
		for (i=1;i<=uppos;i++) {
			for (j=1;j<=left-(i-1);j++) {
				System.out.print("*");
			}
			for (j=1;j<=(i*2)-1;j++) {
				System.out.print("D");
			}
			for (j=1;j<=right-(i-1);j++) {
				System.out.print("*");
			}
			System.out.println();
		}
		for (i=1;i<=n;i++) {
			System.out.print("D");
		}
		System.out.println();
		for (i=downpos;i>=1;i--) {
			for (j=left-(i-1);j>=1;j--) {
				System.out.print("*");
			}
			for (j=(i*2)-1;j>=1;j--) {
				System.out.print("D");
			}
			for (j=right-(i-1);j>=1;j--) {
				System.out.print("*");
			}
			System.out.println();
		}
	}

}


import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.SortedSet;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main
{
	public void foo()
	{
		MyScanner scan = new MyScanner();
		int n = scan.nextInt();
		PrintWriter out = new PrintWriter(System.out);
		char[][] map = new char[n / 2][n];
		for(int i = 0;i < n / 2;++i)
		{
			for(int j = 0;j < n / 2 - i;++j)
			{
				map[i][j] = '*';
			}
			for(int j = n / 2 - i;j <= n / 2 + i;++j)
			{
				map[i][j] = 'D';
			}
			for(int j = n / 2 + i + 1;j < n;++j)
			{
				map[i][j] = '*';
			}
			out.println(map[i]);
		}
		for(int i = 0;i < n;++i)
		{
			out.print('D');
		}
		out.println();
		for(int i = n / 2 - 1;i >= 0;--i)
		{
			out.println(map[i]);
		}
		out.close();
	}

	public static void main(String[] args)
	{
		new Main().foo();
	}

	class MyScanner
	{
	    private byte[] buf = new byte[1024];
	    private int curChar;
	    private int numChars;
	    BufferedInputStream bis = new BufferedInputStream(System.in);

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

	    public int nextInt()
	    {
	        int c = read();
	        while (isSpaceChar(c))
	        {
	        	c = read();
	        }
	        int sgn = 1;
	        if (c == '-')
	        {
	            sgn = -1;
	            c = read();
	        }
	        int res = 0;
	        do
	        {
	            if (c < '0' || c > '9')
	            {
	            	throw new InputMismatchException();
	            }
	            res *= 10;
	            res += c - '0';
	            c = read();
	        } while (!isSpaceChar(c));
	        return res * sgn;
	    }

	    public long nextLong()
	    {
	    	int c = read();
	    	while (isSpaceChar(c))
	    	{
	    		c = read();
	    	}
	    	int sgn = 1;
	    	if (c == '-')
	    	{
	    		sgn = -1;
	    		c = read();
	    	}
	    	long res = 0;
	    	do
	    	{
	    		if (c < '0' || c > '9')
	    		{
	    			throw new InputMismatchException();
	    		}
	    		res *= 10;
	    		res += c - '0';
	    		c = read();
	    	} while (!isSpaceChar(c));
	    	return res * sgn;
	    }

	    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();
	    }

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


#include <iostream>
using namespace std;
int main()
{
	int n,k,l,h,j;
	cin>>n;
	char **list =new char *[n];
	for (int i=0;i<n;i++)
	list[i]=new char [n];
	k=n/2;
	l=n/2;
	h=0;
	j=n;
	for (;k>=0;k--)
	{
		for (int v=h;v<j;v++)
		list[k][v]='D';
		h++;
		j--;
	}
	h=0;
	j=n;
	for (;l<n;l++)
	{
		for (int v=h;v<j;v++)
		list[l][v]='D';
		h++;
		j--;
	}
	for (int i=0;i<n;i++)
	{
		for (int y=0;y<n;y++)
		{
			if (list[i][y]=='D')
			cout<<list[i][y];
			else
			cout<<"*";
		}
		cout<<endl;
	}

}


/*XD include MOAE XD*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define MOAE                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
int sum(int n)
{
    return (n * (n + 1)) / 2;
}
int fibonacci(int n)
{
    if (n == 1 + n == 2)
    {
        return 1;
    }
    return fibonacci((n - 1)) + fibonacci((n - 2)); // Complexity ~~ 2^n like binary tree
}
int main()
{
    /*بسم الله الرحمن الرحيم*/
    int n, temp;
    bool flag = 0;
    cin >> n;
    temp = n / 2;
    for (int i = 1; i <= n; i++)
    {
        if (temp == 0)
            flag = 1;
        for (int j = 0; j < temp; j++)
        {
            cout << "*";
        }
        for (int j = 0; j < n - 2 * temp; j++)
        {
            cout << "D";
        }
        for (int j = 0; j < temp; j++)
        {
            cout << "*";
        }
        if (flag == 0)
            temp--;
        else
            temp++;

        cout << endl;
    }
    return 0;
}


/*وَقُلِ اعْمَلُوا فَسَيَرَى اللَّهُ عَمَلَكُمْ وَرَسُولُهُ وَالْمُؤْمِنُونَ ۖ وَسَتُرَدُّونَ إِلَىٰ عَالِمِ الْغَيْبِ وَالشَّهَادَةِ فَيُنَبِّئُكُم بِمَا كُنتُمْ تَعْمَلُونَ */
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define ll long long
#define lli long long int
#define mp make_pair
#define pb push_back
#define p pair
#define MOAE                 \
	ios::sync_with_stdio(0); \
	cin.tie(0);              \
	cout.tie(0);

int main()
{
	MOAE;
	int n;
	cin >> n;
	bool flag = 0;
	int temp = n / 2;
	for (int i = 1; i <= n; i++)
	{
		if (temp == 0)
		{
			flag = 1;
		}
		for (int it = 0; it < temp; it++)
		{
			cout << "*";
		}
		for (int it = 0; it < n - 2 * temp; it++)
		{
			cout << "D";
		}
		for (int it = 0; it < temp; it++)
		{
			cout << "*";
		}
		if (flag == 0)
		{
			temp--;
		}
		else
		{
			temp++;
		}
		cout << "\n";
	}
}


#include <iostream>
#include <cstdlib>
#include <string>
#include <sstream>
using namespace std;
int main(){
	int a,q=1;
	cin >> a;
	int b=a/2;
	int po=b;
	for (int i=1;i<=po;i++){
		cout <<string (b,'*') << string (q,'D') << string (b,'*') << endl;
		b=b-1;
		q=q+2;
	}
	cout << string (a,'D') << endl;
	int g=a/2;
	g=g+2;
	int h=a/2,kl=1;
	for (int j=1;j<=h;j++){
		int g=a-(kl*2);
		cout << string(kl,'*')<<string(g,'D')<<string(kl,'*')<<endl;
		kl=kl+1;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int cap=1e5+7;
ll a[cap];
int main()
{
    int n;
    ll k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    scanf("%lld",a+i);
    sort(a+1,a+n+1);
    int l=1,r=n;
    int lt=1,rt=1;
    while(k&&l<=r)
    {
        while(a[l]==a[l+1])
          lt++,l++;
        while(a[r]==a[r-1])
          rt++,r--;
        ll dl=a[l+1]-a[l];
        ll dr=a[r]-a[r-1];
        if(dl*lt<=dr*rt)
        {
            if(dl*lt>k)
            break;
            k-=dl*lt;
            l++,lt++;
        }
        else
        {
            if(dr*rt>k)
            break;
            k-=dr*rt;
            r--,rt++;
        }
    }
    if(r<=l)
    {
    cout<<0<<endl;
    return 0;
    }
    ll d;
    if(k)
    d=max(k/lt,k/rt);
    cout<<max(0,a[r]-a[l]-d)<<endl;
    return 0;
}

    {
        while(a[l]==a[l+1])
          lt++,l++;
        while(a[r]==a[r-1])
          rt++,r--;
        ll dl=a[l+1]-a[l];
        ll dr=a[r]-a[r-1];
        if(dl*lt<=dr*rt)
        {
            if(dl*lt>k)
            break;
            k-=dl*lt;
            l++,lt++;
        }
        else
        {
            if(dr*rt>k)
            break;
            k-=dr*rt;
            r--,rt++;
        }
    }
    if(r<=l)
    {
    cout<<0<<endl;
    return 0;
    }
    ll d;
    if(k)
    d=max(k/lt,k/rt);
    cout<<a[r]-a[l]-d<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int cap=1e5+7;
ll a[cap];
int main()
{
    int n;
    ll k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    scanf("%lld",a+i);
    sort(a+1,a+n+1);
    int l=1,r=n;
    int lt=1,rt=1;
    while(k&&l<=r)
    {
        while(a[l]==a[l+1])
          lt++,l++;
        while(a[r]==a[r-1])
          rt--,r--;
        ll dl=a[l+1]-a[l];
        ll dr=a[r]-a[r-1];
        if(dl*lt<=dr*rt)
        {
            if(dl*lt>k)
            break;
            k-=dl*lt;
            l++,lt++;
        }
        else
        {
            if(dr*rt>k)
            break;
            k-=dr*rt;
            r--,rt++;
        }
    }
    if(r<l)
    cout<<0<<endl;
    else
    cout<<a[r]-a[l]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int cap=1e5+7;
ll a[cap];
int main()
{
    int n;
    ll k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    scanf("%lld",a+i);
    sort(a+1,a+n+1);
    int l=1,r=n;
    int lt=1,rt=1;
    while(k&&l<=r)
    {
        while(a[l]==a[l+1])
          lt++,l++;
        while(a[r]==a[r-1])
          rt++,r--;
        ll dl=a[l+1]-a[l];
        ll dr=a[r]-a[r-1];
        if(dl*lt<=dr*rt)
        {
            if(dl*lt>k)
            break;
            k-=dl*lt;
            l++,lt++;
        }
        else
        {
            if(dr*rt>k)
            break;
            k-=dr*rt;
            r--,rt++;
        }
    }
    if(r<l)
    cout<<0<<endl;
    else
    cout<<a[r]-a[l]<<endl;
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <cstdlib>
#include <queue>
#include <bitset>
#include <set>
#include <unordered_map>
#include <map>
#include <cstdio>
#include <memory>
#include <cstring>

using namespace std;

const int N = 1e5 + 10;

int n;
long long k;
int a[N];

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n >> k;

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

	int l = 0;
	int r = n - 1;
	int l_cnt = 1;
	int r_cnt = 1;

	sort(a, a + n);

	while (r > l && k > 0)
	{
		for (int i = l; i < n; ++i, ++l_cnt)
			if (a[i] != a[l])
			{
				l = i - 1;
				--l_cnt;
				break;
			}
			else if (i == n - 1)
			{
				l = i;
				break;
			}

		for (int i = r; i >= 0; --i, ++r_cnt)
			if (a[i] != a[r])
			{
				r = i + 1;
				--r_cnt;
				break;
			}
			else if (i == 0)
			{
				l = i;
				break;
			}

		if (l >= r)
			break;

		long long l_dlt = a[l + 1] - a[l];
		long long r_dlt = a[r] - a[r - 1];

		if (k >= l_dlt * l_cnt && k >= r_dlt * l_cnt)
		{
			if (k - (l_cnt * l_dlt) > k - (r_cnt * r_dlt))
			{
				long long dlt = a[l + 1] - a[l];
				long long add = k / l_cnt;

				if (add >= dlt)
				{
					k -= dlt * l_cnt;
					a[l] += dlt;
					++l;
					++l_cnt;
				}
				else
				{
					a[l] += add;
					break;
				}
			}
			else
			{
				long long dlt = a[r] - a[r - 1];
				long long add = k / r_cnt;

				if (add >= dlt)
				{
					k -= dlt * r_cnt;
					a[r] -= dlt;
					--r;
					++r_cnt;
				}
				else
				{
					a[r] -= add;
					break;
				}
			}
		}
		else  if (min(k / l_cnt, l_dlt) > min(k / r_cnt, r_dlt))
		{
			long long dlt = a[l + 1] - a[l];
			long long add = k / l_cnt;

			if (add >= dlt)
			{
				k -= dlt * l_cnt;
				a[l] += dlt;
				++l;
				++l_cnt;
			}
			else
			{
				a[l] += add;
				break;
			}
		}
		else if (min(k / l_cnt, l_dlt) == min(k / r_cnt, r_dlt))
		{
			if (k - (l_cnt * l_dlt) > k - (r_cnt * r_dlt))
			{
				long long dlt = a[l + 1] - a[l];
				long long add = k / l_cnt;

				if (add >= dlt)
				{
					k -= dlt * l_cnt;
					a[l] += dlt;
					++l;
					++l_cnt;
				}
				else
				{
					a[l] += add;
					break;
				}
			}
			else
			{
				long long dlt = a[r] - a[r - 1];
				long long add = k / r_cnt;

				if (add >= dlt)
				{
					k -= dlt * r_cnt;
					a[r] -= dlt;
					--r;
					++r_cnt;
				}
				else
				{
					a[r] -= add;
					break;
				}
			}

		}
		else
		{
			long long dlt = a[r] - a[r - 1];
			long long add = k / r_cnt;

			if (add >= dlt)
			{
				k -= dlt * r_cnt;
				a[r] -= dlt;
				--r;
				++r_cnt;
			}
			else
			{
				a[r] -= add;
				break;
			}

		}
	}

	cout << (a[r] - a[l]) << endl;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <cstdlib>
#include <queue>
#include <bitset>
#include <set>
#include <unordered_map>
#include <map>
#include <cstdio>
#include <memory>
#include <cstring>

using namespace std;

const int N = 1e5 + 10;

int n;
long long k;
int a[N];

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n >> k;

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

	int l = 0;
	int r = n - 1;
	int l_cnt = 1;
	int r_cnt = 1;

	sort(a, a + n);

	while (r > l && k > 0)
	{
		for (int i = l; i < n; ++i, ++l_cnt)
			if (a[i] != a[l])
			{
				l = i - 1;
				--l_cnt;
				break;
			}
			else if (i == n - 1)
			{
				l = i;
				break;
			}

		for (int i = r; i >= 0; --i, ++r_cnt)
			if (a[i] != a[r])
			{
				r = i + 1;
				--r_cnt;
				break;
			}
			else if (i == 0)
			{
				l = i;
				break;
			}

		if (l >= r)
			break;

		long long l_dlt = a[l + 1] - a[l];
		long long r_dlt = a[r] - a[r - 1];

		if (k >= l_dlt * l_cnt && k >= r_dlt * l_cnt)
		{
			if (k - (l_cnt * l_dlt) > k - (r_cnt * r_dlt))
			{
				long long dlt = a[l + 1] - a[l];
				long long add = k / l_cnt;

				if (add >= dlt)
				{
					k -= dlt * l_cnt;
					a[l] += dlt;
					++l;
					++l_cnt;
				}
				else
				{
					a[l] += add;
					break;
				}
			}
			else
			{
				long long dlt = a[r] - a[r - 1];
				long long add = k / r_cnt;

				if (add >= dlt)
				{
					k -= dlt * r_cnt;
					a[r] -= dlt;
					--r;
					++r_cnt;
				}
				else
				{
					a[r] -= add;
					break;
				}
			}
		}
		else  if (k - (l_cnt * l_dlt) > k - (r_cnt * r_dlt))
		{
			long long dlt = a[l + 1] - a[l];
			long long add = k / l_cnt;

			if (add >= dlt)
			{
				k -= dlt * l_cnt;
				a[l] += dlt;
				++l;
				++l_cnt;
			}
			else
			{
				a[l] += add;
				break;
			}
		}
		else if (min(k / l_cnt, l_dlt) == min(k / r_cnt, r_dlt))
		{
			if (k - (l_cnt * l_dlt) > k - (r_cnt * r_dlt))
			{
				long long dlt = a[l + 1] - a[l];
				long long add = k / l_cnt;

				if (add >= dlt)
				{
					k -= dlt * l_cnt;
					a[l] += dlt;
					++l;
					++l_cnt;
				}
				else
				{
					a[l] += add;
					break;
				}
			}
			else
			{
				long long dlt = a[r] - a[r - 1];
				long long add = k / r_cnt;

				if (add >= dlt)
				{
					k -= dlt * r_cnt;
					a[r] -= dlt;
					--r;
					++r_cnt;
				}
				else
				{
					a[r] -= add;
					break;
				}
			}

		}
		else
		{
			long long dlt = a[r] - a[r - 1];
			long long add = k / r_cnt;

			if (add >= dlt)
			{
				k -= dlt * r_cnt;
				a[r] -= dlt;
				--r;
				++r_cnt;
			}
			else
			{
				a[r] -= add;
				break;
			}

		}
	}

	cout << (a[r] - a[l]) << endl;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <cstdlib>
#include <queue>
#include <bitset>
#include <set>
#include <unordered_map>
#include <map>
#include <cstdio>
#include <memory>
#include <cstring>

using namespace std;

const int N = 1e5 + 10;

int n;
long long k;
int a[N];

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n >> k;

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

	int l = 0;
	int r = n - 1;
	int l_cnt = 1;
	int r_cnt = 1;

	sort(a, a + n);

	while (r > l && k > 0)
	{
		for (int i = l; i < n; ++i, ++l_cnt)
			if (a[i] != a[l])
			{
				l = i - 1;
				--l_cnt;
				break;
			}
			else if (i == n - 1)
			{
				l = i;
				break;
			}

		for (int i = r; i >= 0; --i, ++r_cnt)
			if (a[i] != a[r])
			{
				r = i + 1;
				--r_cnt;
				break;
			}
			else if (i == 0)
			{
				l = i;
				break;
			}

		if (l >= r)
			break;

		long long l_dlt = a[l + 1] - a[l];
		long long r_dlt = a[r] - a[r - 1];

		if (k >= l_dlt * l_cnt && k >= r_dlt * l_cnt)
		{
			if (k - (l_cnt * l_dlt) > k - (r_cnt * r_dlt))
			{
				long long dlt = a[l + 1] - a[l];
				long long add = k / l_cnt;

				if (add >= dlt)
				{
					k -= dlt * l_cnt;
					a[l] += dlt;
					++l;
					++l_cnt;
				}
				else
				{
					a[l] += add;
					break;
				}
			}
			else
			{
				long long dlt = a[r] - a[r - 1];
				long long add = k / r_cnt;

				if (add >= dlt)
				{
					k -= dlt * r_cnt;
					a[r] -= dlt;
					--r;
					++r_cnt;
				}
				else
				{
					a[r] -= add;
					break;
				}
			}
		}
		else  if (l_cnt < r_cnt)
		{
			long long dlt = a[l + 1] - a[l];
			long long add = k / l_cnt;

			if (add >= dlt)
			{
				k -= dlt * l_cnt;
				a[l] += dlt;
				++l;
				++l_cnt;
			}
			else
			{
				a[l] += add;
				break;
			}
		}
		else
		{
			long long dlt = a[r] - a[r - 1];
			long long add = k / r_cnt;

			if (add >= dlt)
			{
				k -= dlt * r_cnt;
				a[r] -= dlt;
				--r;
				++r_cnt;
			}
			else
			{
				a[r] -= add;
				break;
			}

		}
	}

	cout << (a[r] - a[l]) << endl;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <cstdlib>
#include <queue>
#include <bitset>
#include <set>
#include <unordered_map>
#include <map>
#include <cstdio>
#include <memory>
#include <cstring>

using namespace std;

const int N = 1e5 + 10;

int n;
long long k;
int a[N];

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n >> k;

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

	int l = 0;
	int r = n - 1;
	int l_cnt = 1;
	int r_cnt = 1;

	sort(a, a + n);

	while (r > l && k > 0)
	{
		for (int i = l; i < n; ++i, ++l_cnt)
			if (a[i] != a[l])
			{
				l = i - 1;
				--l_cnt;
				break;
			}
			else if (i == n - 1)
			{
				l = i;
				break;
			}

		for (int i = r; i >= 0; --i, ++r_cnt)
			if (a[i] != a[r])
			{
				r = i + 1;
				--r_cnt;
				break;
			}
			else if (i == 0)
			{
				l = i;
				break;
			}

		if (l >= r)
			break;

		long long l_dlt = a[l + 1] - a[l];
		long long r_dlt = a[r] - a[r - 1];

		if (k < l_cnt && k < r_cnt)
			break;

		if (k >= l_dlt * l_cnt && k >= r_dlt * l_cnt)
		{
			if (k - (l_cnt * l_dlt) > k - (r_cnt * r_dlt))
			{
				long long dlt = a[l + 1] - a[l];
				long long add = k / l_cnt;

				if (add >= dlt)
				{
					k -= dlt * l_cnt;
					a[l] += dlt;
					++l;
					++l_cnt;
				}
				else
				{
					a[l] += add;
				}
			}
			else
			{
				long long dlt = a[r] - a[r - 1];
				long long add = k / r_cnt;

				if (add >= dlt)
				{
					k -= dlt * r_cnt;
					a[r] -= dlt;
					--r;
					++r_cnt;
				}
				else
				{
					a[r] -= add;
				}
			}
		}
		else  if (l_cnt < r_cnt)
		{
			long long dlt = a[l + 1] - a[l];
			long long add = k / l_cnt;

			if (add >= dlt)
			{
				k -= dlt * l_cnt;
				a[l] += dlt;
				++l;
				++l_cnt;
			}
			else
			{
				a[l] += add;
			}
		}
		else
		{
			long long dlt = a[r] - a[r - 1];
			long long add = k / r_cnt;

			if (add >= dlt)
			{
				k -= dlt * r_cnt;
				a[r] -= dlt;
				--r;
				++r_cnt;
			}
			else
			{
				a[r] -= add;
			}

		}
	}

	cout << (a[r] - a[l]) << endl;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <cstdlib>
#include <queue>
#include <bitset>
#include <set>
#include <unordered_map>
#include <map>
#include <cstdio>
#include <memory>
#include <cstring>

using namespace std;

const int N = 1e5 + 10;

int n;
long long k;
int a[N];

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n >> k;

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

	int l = 0;
	int r = n - 1;
	int l_cnt = 1;
	int r_cnt = 1;

	sort(a, a + n);

	while (r > l && k > 0)
	{
		for (int i = l; i < n; ++i, ++l_cnt)
			if (a[i] != a[l])
			{
				l = i - 1;
				--l_cnt;
				break;
			}
			else if (i == n - 1)
			{
				l = i;
				break;
			}

		for (int i = r; i >= 0; --i, ++r_cnt)
			if (a[i] != a[r])
			{
				r = i + 1;
				--r_cnt;
				break;
			}
			else if (i == 0)
			{
				l = i;
				break;
			}

		if (l >= r)
			break;

		long long l_dlt = a[l + 1] - a[l];
		long long r_dlt = a[r] - a[r - 1];

		if (min(k / l_cnt, l_dlt) > min(k / r_cnt, r_dlt))
		{
			long long dlt = a[l + 1] - a[l];
			long long add = k / l_cnt;

			if (add >= dlt)
			{
				k -= dlt * l_cnt;
				a[l] += dlt;
				++l;
				++l_cnt;
			}
			else
			{
				a[l] += add;
				break;
			}
		}
		else if (min(k / l_cnt, l_dlt) == min(k / r_cnt, r_dlt))
		{
			if (k - (l_cnt * l_dlt) > k - (r_cnt * r_dlt))
			{
				long long dlt = a[l + 1] - a[l];
				long long add = k / l_cnt;

				if (add >= dlt)
				{
					k -= dlt * l_cnt;
					a[l] += dlt;
					++l;
					++l_cnt;
				}
				else
				{
					a[l] += add;
					break;
				}
			}
			else
			{
				long long dlt = a[r] - a[r - 1];
				long long add = k / r_cnt;

				if (add >= dlt)
				{
					k -= dlt * r_cnt;
					a[r] -= dlt;
					--r;
					++r_cnt;
				}
				else
				{
					a[r] -= add;
					break;
				}
			}

		}
		else
		{
			long long dlt = a[r] - a[r - 1];
			long long add = k / r_cnt;

			if (add >= dlt)
			{
				k -= dlt * r_cnt;
				a[r] -= dlt;
				--r;
				++r_cnt;
			}
			else
			{
				a[r] -= add;
				break;
			}

		}
	}

	cout << (a[r] - a[l]) << endl;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <cstdlib>
#include <queue>
#include <bitset>
#include <set>
#include <unordered_map>
#include <map>
#include <cstdio>
#include <memory>
#include <cstring>

using namespace std;

const int N = 1e5 + 10;

int n;
long long k;
int a[N];

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n >> k;

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

	int l = 0;
	int r = n - 1;
	int l_cnt = 1;
	int r_cnt = 1;

	sort(a, a + n);

	while (r > l && k > 0)
	{
		for (int i = l; i < n; ++i, ++l_cnt)
			if (a[i] != a[l])
			{
				l = i - 1;
				--l_cnt;
				break;
			}
			else if (i == n - 1)
			{
				l = i;
				break;
			}

		for (int i = r; i >= 0; --i, ++r_cnt)
			if (a[i] != a[r])
			{
				r = i + 1;
				--r_cnt;
				break;
			}
			else if (i == 0)
			{
				l = i;
				break;
			}

		if (l >= r)
			break;

		long long l_dlt = a[l + 1] - a[l];
		long long r_dlt = a[r] - a[r - 1];

		if (k < l_cnt && k < r_cnt)
			break;

		if (k >= l_dlt * l_cnt && k >= r_dlt * r_cnt)
		{
			if (k - (l_cnt * l_dlt) > k - (r_cnt * r_dlt))
			{
				long long dlt = a[l + 1] - a[l];
				long long add = k / l_cnt;

				if (add >= dlt)
				{
					k -= dlt * l_cnt;
					a[l] += dlt;
					++l;
					++l_cnt;
				}
				else
				{
					a[l] += add;
					k -= add * l_cnt;
				}
			}
			else
			{
				long long dlt = a[r] - a[r - 1];
				long long add = k / r_cnt;

				if (add >= dlt)
				{
					k -= dlt * r_cnt;
					a[r] -= dlt;
					--r;
					++r_cnt;
				}
				else
				{
					a[r] -= add;
					k -= add * r_cnt;
				}
			}
		}
		else  if (l_cnt < r_cnt)
		{
			long long dlt = a[l + 1] - a[l];
			long long add = k / l_cnt;

			if (add >= dlt)
			{
				k -= dlt * l_cnt;
				a[l] += dlt;
				++l;
				++l_cnt;
			}
			else
			{
				a[l] += add;
				k -= add * l_cnt;
			}
		}
		else
		{
			long long dlt = a[r] - a[r - 1];
			long long add = k / r_cnt;

			if (add >= dlt)
			{
				k -= dlt * r_cnt;
				a[r] -= dlt;
				--r;
				++r_cnt;
			}
			else
			{
				a[r] -= add;
				k -= add * r_cnt;
			}

		}
	}

	cout << (a[r] - a[l]) << endl;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <cstdlib>
#include <queue>
#include <bitset>
#include <set>
#include <unordered_map>
#include <map>
#include <cstdio>
#include <memory>
#include <cstring>

using namespace std;

const int N = 1e5 + 10;

int n;
long long k;
int a[N];

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n >> k;

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

	int l = 0;
	int r = n - 1;
	int l_cnt = 1;
	int r_cnt = 1;

	sort(a, a + n);

	while (r > l && k > 0)
	{
		for (int i = l; i < n; ++i, ++l_cnt)
			if (a[i] != a[l])
			{
				l = i - 1;
				--l_cnt;
				break;
			}
			else if (i == n - 1)
			{
				l = i;
				break;
			}

		for (int i = r; i >= 0; --i, ++r_cnt)
			if (a[i] != a[r])
			{
				r = i + 1;
				--r_cnt;
				break;
			}
			else if (i == 0)
			{
				l = i;
				break;
			}

		if (l >= r)
			break;

		long long l_dlt = a[l + 1] - a[l];
		long long r_dlt = a[r] - a[r - 1];

		if (min(k / l_cnt, l_dlt) > min(k / r_cnt, r_dlt))
		{
			long long dlt = a[l + 1] - a[l];
			long long add = k / l_cnt;

			if (add >= dlt)
			{
				k -= dlt * l_cnt;
				a[l] += dlt;
				++l;
				++l_cnt;
			}
			else
			{
				a[l] += add;
				break;
			}
		}
		else
		{
			long long dlt = a[r] - a[r - 1];
			long long add = k / r_cnt;

			if (add >= dlt)
			{
				k -= dlt * r_cnt;
				a[r] -= dlt;
				--r;
				++r_cnt;
			}
			else
			{
				a[r] -= add;
				break;
			}

		}
	}

	cout << (a[r] - a[l]) << endl;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <cstdlib>
#include <queue>
#include <bitset>
#include <set>
#include <unordered_map>
#include <map>
#include <cstdio>
#include <memory>
#include <cstring>

using namespace std;

const int N = 1e5 + 10;

int n;
long long k;
int a[N];

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n >> k;

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

	int l = 0;
	int r = n - 1;
	int l_cnt = 1;
	int r_cnt = 1;

	sort(a, a + n);

	while (r > l && k > 0)
	{
		for (int i = l; i < n; ++i, ++l_cnt)
			if (a[i] != a[l])
			{
				l = i - 1;
				--l_cnt;
				break;
			}
			else if (i == n - 1)
			{
				l = i;
				break;
			}

		for (int i = r; i >= 0; --i, ++r_cnt)
			if (a[i] != a[r])
			{
				r = i + 1;
				--r_cnt;
				break;
			}
			else if (i == 0)
			{
				l = i;
				break;
			}

		if (l >= r)
			break;

		long long l_dlt = a[l + 1] - a[l];
		long long r_dlt = a[r] - a[r - 1];

		if (k < l_cnt && k < r_cnt)
			break;

		if (l_cnt < r_cnt)
		{
			long long dlt = a[l + 1] - a[l];
			long long add = k / l_cnt;

			if (add >= dlt)
			{
				k -= dlt * l_cnt;
				a[l] += dlt;
				++l;
				++l_cnt;
			}
			else
			{
				a[l] += add;
				k -= add * l_cnt;
			}
		}
		else
		{
			long long dlt = a[r] - a[r - 1];
			long long add = k / r_cnt;

			if (add >= dlt)
			{
				k -= dlt * r_cnt;
				a[r] -= dlt;
				--r;
				++r_cnt;
			}
			else
			{
				a[r] -= add;
				k -= add * r_cnt;
			}

		}
	}

	cout << (a[r] - a[l]) << endl;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <cstdlib>
#include <queue>
#include <bitset>
#include <set>
#include <unordered_map>
#include <map>
#include <cstdio>
#include <memory>
#include <cstring>

using namespace std;

const int N = 1e5 + 10;

int n;
long long k;
int a[N];

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n >> k;

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

	int l = 0;
	int r = n - 1;
	int l_cnt = 1;
	int r_cnt = 1;

	sort(a, a + n);

	while (r > l && k > 0)
	{
		for (int i = l; i < n; ++i, ++l_cnt)
			if (a[i] != a[l])
			{
				l = i - 1;
				--l_cnt;
				break;
			}
			else if (i == n - 1)
			{
				l = i;
				break;
			}

		for (int i = r; i >= 0; --i, ++r_cnt)
			if (a[i] != a[r])
			{
				r = i + 1;
				--r_cnt;
				break;
			}
			else if (i == 0)
			{
				l = i;
				break;
			}

		if (l >= r)
			break;

		long long l_dlt = a[l + 1] - a[l];
		long long r_dlt = a[r] - a[r - 1];

		if (k < l_cnt && k < r_cnt)
			break;

		if (k >= l_dlt * l_cnt && k >= r_dlt * l_cnt)
		{
			if (k - (l_cnt * l_dlt) > k - (r_cnt * r_dlt))
			{
				long long dlt = a[l + 1] - a[l];
				long long add = k / l_cnt;

				if (add >= dlt)
				{
					k -= dlt * l_cnt;
					a[l] += dlt;
					++l;
					++l_cnt;
				}
				else
				{
					a[l] += add;
					k -= add * l_cnt;
				}
			}
			else
			{
				long long dlt = a[r] - a[r - 1];
				long long add = k / r_cnt;

				if (add >= dlt)
				{
					k -= dlt * r_cnt;
					a[r] -= dlt;
					--r;
					++r_cnt;
				}
				else
				{
					a[r] -= add;
					k -= add * r_cnt;
				}
			}
		}
		else  if (l_cnt < r_cnt)
		{
			long long dlt = a[l + 1] - a[l];
			long long add = k / l_cnt;

			if (add >= dlt)
			{
				k -= dlt * l_cnt;
				a[l] += dlt;
				++l;
				++l_cnt;
			}
			else
			{
				a[l] += add;
				k -= add * l_cnt;
			}
		}
		else
		{
			long long dlt = a[r] - a[r - 1];
			long long add = k / r_cnt;

			if (add >= dlt)
			{
				k -= dlt * r_cnt;
				a[r] -= dlt;
				--r;
				++r_cnt;
			}
			else
			{
				a[r] -= add;
				k -= add * r_cnt;
			}

		}
	}

	cout << (a[r] - a[l]) << endl;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <cstdlib>
#include <queue>
#include <bitset>
#include <set>
#include <unordered_map>
#include <map>
#include <cstdio>
#include <memory>
#include <cstring>

using namespace std;

const int N = 1e5 + 10;

int n;
long long k;
int a[N];

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n >> k;

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

	int l = 0;
	int r = n - 1;
	int l_cnt = 1;
	int r_cnt = 1;

	sort(a, a + n);

	while (r > l && k > 0)
	{
		for (int i = l; i < n; ++i, ++l_cnt)
			if (a[i] != a[l])
			{
				l = i - 1;
				--l_cnt;
				break;
			}
			else if (i == n - 1)
			{
				l = i;
				break;
			}

		for (int i = r; i >= 0; --i, ++r_cnt)
			if (a[i] != a[r])
			{
				r = i + 1;
				--r_cnt;
				break;
			}
			else if (i == 0)
			{
				l = i;
				break;
			}

		if (l >= r)
			break;

		long long l_dlt = a[l + 1] - a[l];
		long long r_dlt = a[r] - a[r - 1];

		if (l_dlt * l_cnt < r_cnt * r_dlt)
		{
			long long dlt = a[l + 1] - a[l];
			long long add = k / l_cnt;

			if (add >= dlt)
			{
				k -= dlt * l_cnt;
				a[l] += dlt;
				++l;
				++l_cnt;
			}
			else
			{
				a[l] += add;
				break;
			}
		}
		else
		{
			long long dlt = a[r] - a[r - 1];
			long long add = k / r_cnt;

			if (add >= dlt)
			{
				k -= dlt * r_cnt;
				a[r] += dlt;
				--r;
				++r_cnt;
			}
			else
			{
				a[r] += add;
				break;
			}

		}
	}

	cout << (a[r] - a[l]) << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
int a[maxn],n,vis[maxn];
ll pre[maxn],ho[maxn];
ll k;
bool check(int x){
	int e = 1;
	memset(vis,0,sizeof(vis));
	for(int i = 1; i <= n; i++){
		int f = 0;
		while(e<=n&&a[e]<=a[i]+x){
			e++;
		}
		if(vis[e] == 1) continue;
		vis[e] = 1;
		ll ans;
		if(i == 1&& e==n+1){
			return true;
		}else if(i == 1&&e != n+1){
			ans = ho[e]-1LL*(x+a[i])*(n-e+1);
		}else if(i != 1&& e == n+1){
			ans = 1LL*(a[n]-x)*(i-1)-pre[i-1];
		}else{
			ll le = 1LL*a[i-1]*(i-1)-pre[i-1]+1LL*(i-1)*max(0,a[e-1]-a[i-1]-x);
			ll ri = ho[e]-1LL*a[e]*(n-e+1)+1LL*(n-e+1)*max(0,a[e]-a[i]-x);
			int nows, nowb;
			if(a[e-1]-a[i-1]<=x) nows = a[i-1];
			else nows = a[e-1]-x;
			if(a[e]-a[i]<=x) nowb = a[e];
			else nowb = a[i]+x;
			ans = le+ri+1LL*min(i-1,n-e+1)*max(0,nowb-nows-x);
		}
		if(ans<=k) return true;
	}
	return false;
}
int main(){
	scanf("%d%lld",&n,&k);
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	for(int i = 1; i <= n; i++){
		pre[i] = pre[i-1]+a[i];
	}
	for(int i = n ; i >= 1; i--){
		ho[i] = ho[i+1]+a[i];
	}
	int l = 0, r = 1000000000,mid,ans;
	while(l<=r){
		mid = l+r>>1;
		if(check(mid)){
			ans = mid;
			r = mid-1;
		}else{
			l = mid+1;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
int a[maxn],n;
ll pre[maxn],ho[maxn];
ll k;
bool check(int x){
	int b = 1, e = 1;
	for(int i = 1; i <= n; i++){
		while(e<=n&&a[e]<=a[i]+x) e++;
		ll ans = 0;
		if(i == 1&& e==n+1){
			return true;
		}else if(i == 1&&e != n+1){
			ans = ho[e]-1LL*(x+a[i])*(n-e+1);
		}else if(i != 1&& e == n+1){
			ans = 1LL*(a[n]-x)*(i-1);
		}else{
			ll le = 1LL*a[i-1]*(i-1)-pre[i-1]+1LL*(i-1)*max(0,a[e-1]-a[i-1]-x);
			ll ri = ho[e]-1LL*a[e]*(n-e+1)+1LL*(n-e+1)*max(0,a[e]-a[i]-x);
			int nows, nowb;
			if(a[e-1]-a[i-1]<=x) nows = a[i-1];
			else nows = a[e-1]-x;
			if(a[e]-a[i]<=x) nowb = a[e];
			else nowb = a[i]+x;
			ans = le+ri+1LL*min(i-1,n-e+1)*max(0,nowb-nows-x);

		}

		if(ans<=k) return true;
	}
	return false;
}
int main(){
	scanf("%d%lld",&n,&k);
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	for(int i = 1; i <= n; i++){
		pre[i] = pre[i-1]+a[i];
	}
	for(int i = n ; i >= 1; i--){
		ho[i] = ho[i+1]+a[i];
	}

	int l = 0, r = 1000000000,mid,ans;
	while(l<=r){
		mid = l+r>>1;
		if(check(mid)){
			ans = mid;
			r = mid-1;
		}else{
			l = mid+1;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
int a[maxn],n;
ll pre[maxn],ho[maxn];
ll k;
bool check(int x){
	int e = 1;
	for(int i = 1; i <= n; i++){
		while(e<=n&&a[e]<=a[i]+x){
			e++;
		}
		ll ans;
		if(i == 1&& e==n+1){
			return true;
		}else if(i == 1&&e != n+1){
			ans = ho[e]-1LL*(x+a[i])*(n-e+1);
		}else if(i != 1&& e == n+1){
			ans = 1LL*(a[n]-x)*(i-1)-pre[i-1];
		}else{
			ll le = 1LL*a[i-1]*(i-1)-pre[i-1]+1LL*(i-1)*max(0,a[e-1]-a[i-1]-x);
			ll ri = ho[e]-1LL*a[e]*(n-e+1)+1LL*(n-e+1)*max(0,a[e]-a[i]-x);
			int nows, nowb;
			if(a[e-1]-a[i-1]<=x) nows = a[i-1];
			else nows = a[e-1]-x;
			if(a[e]-a[i]<=x) nowb = a[e];
			else nowb = a[i]+x;
			ans = le+ri+1LL*min(i-1,n-e+1)*max(0,nowb-nows-x);
		}
		if(x == 0) printf("%lld\n", ans);
		if(ans<=k) return true;
	}
	return false;
}
int main(){
	scanf("%d%lld",&n,&k);
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	for(int i = 1; i <= n; i++){
		pre[i] = pre[i-1]+a[i];
	}
	for(int i = n ; i >= 1; i--){
		ho[i] = ho[i+1]+a[i];
	}
	int l = 0, r = 1000000000,mid,ans;
	while(l<=r){
		mid = l+r>>1;
		if(check(mid)){
			ans = mid;
			r = mid-1;
		}else{
			l = mid+1;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
int a[maxn],n,l[maxn],r[maxn];
ll pre[maxn],ho[maxn];
ll k;
bool check(int x){
	int e = 1;
	for(int i = 1; i <= n ;i++){
		while(e<=n&&a[e]<=a[i]+x) e++;
		r[i] = e;
	}
	int b = n;
	for(int i = n; i >= 1; i--){
		while(b>=1&&a[b]>=a[i]-x) b--;
		l[i] = b;
	}
	e = 1;
	for(int i = 1; i <= n; i++){
		while(e<=n&&a[e]<=a[i]+x) e++;
		ll ans = 0;
		if(i == 1&& e==n+1){
			return true;
		}else if(i == 1&&e != n+1){
			ans = ho[e]-1LL*(x+a[i])*(n-e+1);
		}else if(i != 1&& e == n+1){
			ans = 1LL*(a[n]-x)*l[n]-pre[l[n]];
		}else{
			ll le = 1LL*a[i-1]*(i-1)-pre[i-1];//+1LL*(i-1)*max(0,a[e-1]-a[i-1]-x);
			ll ri = ho[e]-1LL*a[e]*(n-e+1);//+1LL*(n-e+1)*max(0,a[e]-a[i]-x);
			int nows, nowb;
			if(a[e-1]-a[i-1]<=x) nows = a[i-1];
			else nows = a[e-1]-x;
			if(a[e]-a[i]<=x) nowb = a[e];
			else nowb = a[i]+x;
			ans = le+ri+1LL*min(i-1,n-e+1)*max(0,a[e]-a[i-1]-x);
		}
		if(ans<=k) return true;
	}
	return false;
}
int main(){
	scanf("%d%lld",&n,&k);
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	for(int i = 1; i <= n; i++){
		pre[i] = pre[i-1]+a[i];
	}
	for(int i = n ; i >= 1; i--){
		ho[i] = ho[i+1]+a[i];
	}

	int l = 0, r = 1000000000,mid,ans;
	while(l<=r){
		mid = l+r>>1;
		if(check(mid)){
			ans = mid;
			r = mid-1;
		}else{
			l = mid+1;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
int a[maxn],n,l[maxn],r[maxn];
ll pre[maxn],ho[maxn];
ll k;
bool check(int x){
	int e = 1;
	for(int i = 1; i <= n ;i++){
		while(e<=n&&a[e]<=a[i]+x) e++;
		r[i] = e;
	}
	int b = n;
	for(int i = n; i >= 1; i--){
		while(b>=1&&a[b]>=a[i]-x) b--;
		l[i] = b;
	}
	e = 1;
	for(int i = 1; i <= n; i++){
		while(e<=n&&a[e]<=a[i]+x) e++;
		ll ans = 0;
		if(i == 1&& e==n+1){
			return true;
		}else if(i == 1&&e != n+1){
			ans = ho[e]-1LL*(x+a[i])*(n-e+1);
		}else if(i != 1&& e == n+1){
			ans = 1LL*(a[n]-x)*l[n]-pre[l[n]];
		}else{
			ll le = 1LL*a[i-1]*(i-1)-pre[i-1]+1LL*(i-1)*max(0,a[e-1]-a[i-1]-x);
			ll ri = ho[e]-1LL*a[e]*(n-e+1)+1LL*(n-e+1)*max(0,a[e]-a[i]-x);
			int nows, nowb;
			if(a[e-1]-a[i-1]<=x) nows = a[i-1];
			else nows = a[e-1]-x;
			if(a[e]-a[i]<=x) nowb = a[e];
			else nowb = a[i]+x;
			ans = le+ri+1LL*min(i-1,n-e+1)*max(0,nowb-nows-x);

		}

		if(ans<=k) return true;
	}
	return false;
}
int main(){
	scanf("%d%lld",&n,&k);
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	for(int i = 1; i <= n; i++){
		pre[i] = pre[i-1]+a[i];
	}
	for(int i = n ; i >= 1; i--){
		ho[i] = ho[i+1]+a[i];
	}

	int l = 0, r = 1000000000,mid,ans;
	while(l<=r){
		mid = l+r>>1;
		if(check(mid)){
			ans = mid;
			r = mid-1;
		}else{
			l = mid+1;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
int a[maxn],n;
ll pre[maxn],ho[maxn];
ll k;
bool check(int x){
	int e = 1;
	for(int i = 1; i <= n; i++){
		while(e<=n&&a[e]<=a[i]+x) e++;
		ll ans;
		if(i == 1&& e==n+1){
			return true;
		}else if(i == 1&&e != n+1){
			ans = ho[e]-1LL*(x+a[i])*(n-e+1);
		}else if(i != 1&& e == n+1){
			ans = 1LL*(a[n]-x)*(i-1);//ans = 1LL*(a[n]-x)*(i-1)-pre[i-1];
		}else{
			ll le = 1LL*a[i-1]*(i-1)-pre[i-1]+1LL*(i-1)*max(0,a[e-1]-a[i-1]-x);
			ll ri = ho[e]-1LL*a[e]*(n-e+1)+1LL*(n-e+1)*max(0,a[e]-a[i]-x);
			int nows, nowb;
			if(a[e-1]-a[i-1]<=x) nows = a[i-1];
			else nows = a[e-1]-x;
			if(a[e]-a[i]<=x) nowb = a[e];
			else nowb = a[i]+x;
			ans = le+ri+1LL*min(i-1,n-e+1)*max(0,nowb-nows-x);
		}
		if(ans<=k) return true;
	}
	return false;
}
int main(){
	scanf("%d%lld",&n,&k);
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	for(int i = 1; i <= n; i++){
		pre[i] = pre[i-1]+a[i];
	}
	for(int i = n ; i >= 1; i--){
		ho[i] = ho[i+1]+a[i];
	}
	int l = 0, r = 1000000000,mid,ans;
	while(l<=r){
		mid = l+r>>1;
		if(check(mid)){
			ans = mid;
			r = mid-1;
		}else{
			l = mid+1;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
int a[maxn],n;
ll pre[maxn],ho[maxn];
ll k;
bool check(int x){
	int e = 1;
	for(int i = 1; i <= n; i++){
		while(e<=n&&a[e]<=a[i]+x){
			e++;
		}
		ll ans;
		if(i == 1&& e==n+1){
			return true;
		}else if(i == 1&&e != n+1){
			ans = ho[e]-1LL*(x+a[i])*(n-e+1);
		}else if(i != 1&& e == n+1){
			ans = 1LL*(a[n]-x)*(i-1)-pre[i-1];
		}else{
			ll le = 1LL*a[i-1]*(i-1)-pre[i-1]+1LL*(i-1)*max(0,a[e-1]-a[i-1]-x);
			ll ri = ho[e]-1LL*a[e]*(n-e+1)+1LL*(n-e+1)*max(0,a[e]-a[i]-x);
			int nows, nowb;
			if(a[e-1]-a[i-1]<=x) nows = a[i-1];
			else nows = a[e-1]-x;
			if(a[e]-a[i]<=x) nowb = a[e];
			else nowb = a[i]+x;
			ans = le+ri+1LL*min(i-1,n-e+1)*max(0,nowb-nows-x);
		}
		if(ans<=k) return true;
	}
	return false;
}
int main(){
	scanf("%d%lld",&n,&k);
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	for(int i = 1; i <= n; i++){
		pre[i] = pre[i-1]+a[i];
	}
	for(int i = n ; i >= 1; i--){
		ho[i] = ho[i+1]+a[i];
	}
	int l = 0, r = 1000000000,mid,ans;
	while(l<=r){
		mid = l+r>>1;
		if(check(mid)){
			ans = mid;
			r = mid-1;
		}else{
			l = mid+1;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
int a[maxn],n;
int l[maxn],r[maxn];
ll pre[maxn],ho[maxn];
ll k;
bool check(int x){
	int e = 1;
	for(int i = 1; i <= n ;i++){
		while(e<=n&&a[e]<=a[i]+x) e++;
		r[i] = e;
	}
	int b = n;
	for(int i = n; i >= 1; i--){
		while(b>=1&&a[b]>=a[i]-x) b--;
		l[i] = b;
	}
	for(int i = 1; i <= n; i++){
		int ee = r[i];
		int bb = i;
		if(ee!=n+1){
			bb = l[ee]+1;
		}
		ll ans;
		if(bb == 1&& ee==n+1){
			return true;
		}else if(bb == 1&&ee != n+1){
			ans = ho[ee]-1LL*(x+a[bb])*(n-ee+1);
		}else if(bb != 1&& ee == n+1){
			ans = 1LL*(a[n]-x)*(bb-1)-pre[bb-1];
		}else{
			ll le = 1LL*a[bb-1]*(bb-1)-pre[bb-1]+1LL*(bb-1)*max(0,a[ee-1]-a[bb-1]-x);
			ll ri = ho[ee]-1LL*a[ee]*(n-ee+1)+1LL*(n-ee+1)*max(0,a[ee]-a[bb]-x);
			int nows, nowb;
			if(a[ee-1]-a[bb-1]<=x) nows = a[bb-1];
			else nows = a[ee-1]-x;
			if(a[ee]-a[bb]<=x) nowb = a[ee];
			else nowb = a[bb]+x;
			ans = le+ri+1LL*min(bb-1,n-ee+1)*max(0,nowb-nows-x);
		}
		if(ans<=k) return true;
	}
	return false;
}
int main(){
	scanf("%d%lld",&n,&k);
	for(int i = 1; i <= n; i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	for(int i = 1; i <= n; i++){
		pre[i] = pre[i-1]+a[i];
	}
	for(int i = n ; i >= 1; i--){
		ho[i] = ho[i+1]+a[i];
	}
	int l = 0, r = 1000000000,mid,ans;
	while(l<=r){
		mid = l+r>>1;
		if(check(mid)){
			ans = mid;
			r = mid-1;
		}else{
			l = mid+1;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main() {
	long long n, k;
	cin >> n >> k;
	vector<long long> a(n);
	for (long long i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	long long  x = 0, y = n - 1;
	while (x <= y) {
		long long  kek1 = (x + 1) * (a[x + 1] - a[x]);
		long long  kek2 = (n - y) * (a[y]- a[y - 1]);
		if (kek1 <= kek2) {
			if (kek1 <= k) {
				k -= kek1;
				x++;
			} else {
				long long  temp = k / (x + 1);
				cout << a[y] - a[x] - temp << endl;
				return 0;
			}
		} else {
			if (kek2 <= k) {
				k -= kek2;
				y--;
			} else {
				long long  temp = k / (n - y);
				cout << a[y] - a[x] - temp << endl;
				return 0;
			}
		}
	}
	cout << a[y] - a[x] << endl;
}


#include<bits/stdc++.h>

using namespace std;

int main() {
	long long n, k;
	cin >> n >> k;
	vector<long long> a(n);
	for (long long i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	long long x1 = 0, x2 = 0;
	long long temp = k;
	for (long long i = 1; i < n; ++i)
	{
		if (k < 0) {
			x1 = a[n - 1] - a[i - 1];
		}
		k -= i * (a[i] - a[i - 1]);
	}
	if (k < 0) {
			x1 = a[n - 1] - a[n - 2];
	}
	k = temp;
	for (long long i = n - 2; i >= 0; --i)
	{
		if (k < 0) {
			x2 = a[i + 1] - a[0];
		}
		k -= (n - 1 - i) * (a[i + 1] - a[i]);
	}
	if (k < 0) {
		x2 = a[1] - a[0];
	}
	cout << min(x1, x2) << endl;
}


#include<bits/stdc++.h>

using namespace std;

int main() {
	long long n, k;
	cin >> n >> k;
	vector<long long> a(n);
	for (long long i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	long long  x = 0, y = n - 1;
	while (x <= y) {
		long long  kek1 = (x + 1) * (a[x + 1] - a[x]);
		long long  kek2 = (n - y) * (a[y]- a[y - 1]);
	//	cout << "kek1 = " << kek1 << " kek2 = " << kek2 << " k = " << k << endl;
		if (kek1 <= kek2) {
			if (kek1 < k && k > 0) {
				k -= kek1;
			} else {
				long long  temp = k / (x + 1);
				cout << a[y] - a[x] - temp << endl;
				return 0;
			}
			x++;
		} else {
			if (kek2 < k && k > 0) {
				k -= kek2;
			} else {
				long long  temp = k / (n - y);
				cout << a[y] - a[x] - temp << endl;
				return 0;
			}
			y--;
		}
	}
	cout << 0 << endl;
}


#include<bits/stdc++.h>

using namespace std;

void soivez() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
}

int main() {
	soivez();
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int x1 = 0, x2 = 0;
	int temp = k;
	for (int i = 1; i < n; ++i)
	{
		if (k < 0) {
			x1 = a[n - 1] - a[i - 1];
		}
		k -= i * (a[i] - a[i - 1]);
	}
	if (k < 0) {
			x1 = a[n - 1] - a[n - 2];
	}
	k = temp;
	for (int i = n - 2; i >= 0; --i)
	{
		if (k < 0) {
			x2 = a[i + 1] - a[0];
		}
		k -= (n - 1 - i) * (a[i + 1] - a[i]);
	}
	if (k < 0) {
		x2 = a[1] - a[0];
	}
	cout << min(x1, x2) << endl;
}


#include<bits/stdc++.h>

using namespace std;

int main() {
	long long n, k;
	cin >> n >> k;
	vector<long long> a(n);
	for (long long i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	long long  x = 0, y = n - 1;
	while (x <= y) {
		long long  kek1 = (x + 1) * (a[x + 1] - a[x]);
		long long  kek2 = (n - y) * (a[y]- a[y - 1]);
		if (kek1 <= kek2) {
			if (kek1 < k) {
				k -= kek1;
				x++;
			} else {
				long long  temp = k / (x + 1);
				cout << a[y] - a[x] - temp << endl;
				return 0;
			}
		} else {
			if (kek2 < k) {
				k -= kek2;
				y--;
			} else {
				long long  temp = k / (n - y);
				cout << a[y] - a[x] - temp << endl;
				return 0;
			}
		}
	}
	cout << a[y] - a[x] << endl;
}


#include<bits/stdc++.h>

using namespace std;

int main() {
	long long n, k;
	cin >> n >> k;
	vector<long long> a(n);
	for (long long i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	long long  x = 0, y = n - 1;
	while (x <= y) {
		long long kek1 = (x + 1) * (a[x + 1] - a[x]);
		long long kek2 = (n - y) * (a[y] - a[y - 1]);
		if ((x + 1) < (n - y)) {
			if (kek1 <= k) {
				k -= kek1;
				x++;
			} else {
				long long  temp = k / (x + 1);
				cout << a[y] - a[x] - temp << endl;
				return 0;
			}
		} else{
			if (kek2 <= k) {
				k -= kek2;
				y--;
			} else {
				long long  temp = k / (n - y);
				cout << a[y] - a[x] - temp << endl;
				return 0;
			}
		}
	}
	cout << a[y] - a[x] << endl;
}


#include<bits/stdc++.h>

using namespace std;

int main() {
	long long n, k;
	cin >> n >> k;
	vector<long long> a(n);
	for (long long i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	long long  x = 0, y = n - 1;
	while (x < y) {
		long long kek1 = (x + 1) * (a[x + 1] - a[x]);
		long long kek2 = (n - y) * (a[y] - a[y - 1]);
		if ((x + 1) < (n - y)) {
			if (kek1 <= k) {
				k -= kek1;
				x++;
			} else {
				long long  temp = k / (x + 1);
				cout << a[y] - a[x] - temp << endl;
				return 0;
			}
		} else{
			if (kek2 <= k) {
				k -= kek2;
				y--;
			} else {
				long long  temp = k / (n - y);
				cout << a[y] - a[x] - temp << endl;
				return 0;
			}
		}
	}
	cout << a[y] - a[x] << endl;
}


#include <bits/stdc++.h>

#ifndef NJUDGE
  #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll LINF = 0x3f3f3f3f3f3f3f3f;
const ll NLINF = 0xf7f7f7f7f7f7f7f7;
const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;

#define sz(x) (int) x.size()
#define eb emplace_back
#define pb push_back
#define ss second
#define ff first

const int N = 1e5+10;
int n, mx, mn = INF, a[N];
ll v = (int) INF, k, s[N];

int main(){
  scanf("%d%lld", &n, &k);
  for(int i = 1; i <= n; i++)
    scanf("%d", &a[i]), mx = max(mx, a[i]), mn = min(mn, a[i]);
  sort(a+1, a+1+n);
  for(int i = 1; i <= n; i++)
    s[i] = s[i-1] + a[i];
  a[n+1] = INF;
  for(int i = 1; i <= n; i++){
    int lo = i, hi = n, mid, ans = n+1;
    while(lo <= hi){
      mid = (0ll+lo+hi)>>1ll;
      if (1ll*i*a[i]-s[i] + (s[n]-s[mid]-1ll*a[mid]*(n-mid)) <= k) hi = mid-1, ans = mid;
      else lo = mid+1;
    }
    int cnt = i+n-ans+1;
    ll lft = k - 1ll*i*a[i]-s[i] + (s[n]-s[ans]-1ll*a[ans]*(n-ans));
    v = min(v, 0ll+a[ans]-a[i]-max(0ll, lft/cnt));
  }
  printf("%lld\n", v);
}


#include <bits/stdc++.h>

#ifndef NJUDGE
  #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll LINF = 0x3f3f3f3f3f3f3f3f;
const ll NLINF = 0xf7f7f7f7f7f7f7f7;
const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;

#define sz(x) (int) x.size()
#define eb emplace_back
#define pb push_back
#define ss second
#define ff first

const int N = 1e5+10;
int n, mx, mn = INF, addon, a[N];
ll v = (int) INF, k, s[N];

int main(){
  scanf("%d%lld", &n, &k);
  for(int i = 1; i <= n; i++)
    scanf("%d", &a[i]), mx = max(mx, a[i]), mn = min(mn, a[i]);
  sort(a+1, a+1+n);
  for(int i = 1; i <= n; i++)
    s[i] = s[i-1] + a[i];
  a[n+1] = INF;
  for(int i = 1; i <= n; i++){
    int lo = i, hi = n, mid, ans = n+1;
    while(lo <= hi){
      mid = (0ll+lo+hi)>>1ll;
      if (1ll*i*a[i]-s[i] + (s[n]-s[mid]-1ll*a[mid]*(n-mid)) <= k) hi = mid-1, ans = mid;
      else lo = mid+1;
    }
    ll lft = k - (1ll*i*a[i]-s[i] + (s[n]-s[ans]-1ll*a[ans]*(n-ans)));
    lft = max(lft, 0ll);
    if (ans > n or ans == i) addon = 0;
    else addon = max(min(0ll+a[i+1]-a[i], lft/i), min(0ll+a[ans]-a[ans-1], lft/(n-ans+1)));
    dbg(i, ans, lft,  addon);
    v = min(v, 0ll+a[ans]-a[i]-addon);
  }
  printf("%lld\n", v);
}


#include <bits/stdc++.h>

#ifndef NJUDGE
  #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll LINF = 0x3f3f3f3f3f3f3f3f;
const ll NLINF = 0xf7f7f7f7f7f7f7f7;
const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;

#define sz(x) (int) x.size()
#define eb emplace_back
#define pb push_back
#define ss second
#define ff first

const int N = 1e5+10;
int n, ans = INF, a[N];
ll k, cur, s[N];

int main(){
  scanf("%d%lld", &n, &k);
  for(int i = 1; i <= n; i++)
    scanf("%d", a+i);
  sort(a+1, a+1+n);
  for(int i = 1; i <= n; i++)
    s[i] = s[i-1] + a[i];
  for(int i = 1; i <= n; i++){
    cur = 1ll*i*a[i] - s[i];
    int lo = a[i], hi = a[n], mid, v = INF;
    while(lo <= hi){
      mid = (0ll+lo+hi)>>1ll;
      int idx = upper_bound(a+1, a+1+n, mid)-a;
      if (cur + s[n]-s[idx-1] - 1ll*mid*(n-idx+1) <= k)
        hi = mid-1, v = mid;
      else
        lo = mid+1;
    }
    dbg(i, v);
    ans = min(ans, v-a[i]);
  }
  for(int i = n; i > 0; i--){
    cur = s[n]-s[i-1] - 1ll*a[i]*(n-i+1);
    int lo = a[1], hi = a[i], mid, v = NINF;
    while(lo <= hi){
      mid = (0ll+lo+hi)>>1ll;
      int idx = upper_bound(a+1, a+1+n, mid)-a;
      idx--;
      if (cur + 1ll*idx*mid - s[idx] <= k)
        lo = mid+1, v = mid;
      else
        hi = mid-1;
    }
    dbg(i, v);
    ans = min(ans, a[i]-v);
  }
  printf("%d\n", ans);
}


#include <bits/stdc++.h>

#ifndef NJUDGE
  #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll LINF = 0x3f3f3f3f3f3f3f3f;
const ll NLINF = 0xf7f7f7f7f7f7f7f7;
const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;

#define sz(x) (int) x.size()
#define eb emplace_back
#define pb push_back
#define ss second
#define ff first

const int N = 1e5+10;
int n, mx, mn = INF, a[N];
ll v = (int) INF, k, s[N];

int main(){
  scanf("%d%lld", &n, &k);
  for(int i = 1; i <= n; i++)
    scanf("%d", &a[i]), mx = max(mx, a[i]), mn = min(mn, a[i]);
  sort(a+1, a+1+n);
  for(int i = 1; i <= n; i++)
    s[i] = s[i-1] + a[i];
  a[n+1] = INF;
  for(int i = 1; i <= n; i++){
    int lo = i, hi = n, mid, ans = n+1;
    while(lo <= hi){
      mid = (0ll+lo+hi)>>1ll;
      if (1ll*i*a[i]-s[i] + (s[n]-s[mid]-1ll*a[mid]*(n-mid)) <= k) hi = mid-1, ans = mid;
      else lo = mid+1;
    }
    ll lft = k - (1ll*i*a[i]-s[i] + (s[n]-s[ans]-1ll*a[ans]*(n-ans)));
    v = min(v, 0ll+a[ans]-a[i]-max({0ll, lft/i, lft/(n-i+1)}));
  }
  printf("%lld\n", v);
}


#include <bits/stdc++.h>

#ifndef NJUDGE
  #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll LINF = 0x3f3f3f3f3f3f3f3f;
const ll NLINF = 0xf7f7f7f7f7f7f7f7;
const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;

#define sz(x) (int) x.size()
#define eb emplace_back
#define pb push_back
#define ss second
#define ff first

const int N = 1e5+10;
ll k, cur, ans = LINF, s[N];
int n, a[N];

int main(){
  scanf("%d%lld", &n, &k);
  for(int i = 1; i <= n; i++)
    scanf("%d", a+i);
  sort(a+1, a+1+n);
  for(int i = 1; i <= n; i++)
    s[i] = s[i-1] + a[i];
  for(int i = 1; i <= n; i++){
    cur = 0ll + 1ll*i*a[i] - s[i];
    ll lo = a[i], hi = a[n], mid, v = INF;
    while(lo <= hi){
      mid = (0ll+lo+hi)>>1ll;
      int idx = upper_bound(a+1, a+1+n, mid)-a;
      if (cur + s[n]-s[idx-1] - 1ll*mid*(n-idx+1) <= k)
        hi = mid-1, v = mid;
      else
        lo = mid+1;
    }
    ans = min(ans, v-a[i]);
  }
  for(int i = n; i > 0; i--){
    cur = 0ll + s[n]-s[i-1] - 1ll*a[i]*(n-i+1);
    ll lo = a[1], hi = a[i], mid, v = NINF;
    while(lo <= hi){
      mid = (0ll+lo+hi)>>1ll;
      int idx = lower_bound(a+1, a+1+n, mid)-a;
      idx--;
      if (cur + 1ll*idx*mid - s[idx] <= k)
        lo = mid+1, v = mid;
      else
        hi = mid-1;
    }
    ans = min(ans, a[i]-v);
  }
  printf("%lld\n", ans);
}


#include <bits/stdc++.h>

#ifndef NJUDGE
  #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll LINF = 0x3f3f3f3f3f3f3f3f;
const ll NLINF = 0xf7f7f7f7f7f7f7f7;
const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;

#define sz(x) (int) x.size()
#define eb emplace_back
#define pb push_back
#define ss second
#define ff first

const int N = 1e5+10;
ll k, cur, ans = LINF, s[N];
int n, a[N];

int main(){
  scanf("%d%lld", &n, &k);
  for(int i = 1; i <= n; i++)
    scanf("%d", a+i);
  sort(a+1, a+1+n);
  for(int i = 1; i <= n; i++)
    s[i] = s[i-1] + a[i];
  for(int i = 1; i <= n; i++){
    cur = 1ll*i*a[i] - s[i];
    ll lo = a[i], hi = a[n], mid, v = INF;
    while(lo <= hi){
      mid = (0ll+lo+hi)>>1ll;
      int idx = upper_bound(a+1, a+1+n, mid)-a;
      if (cur + s[n]-s[idx-1] - 1ll*mid*(n-idx+1) <= k)
        hi = mid-1, v = mid;
      else
        lo = mid+1;
    }
    ans = min(ans, v-a[i]);
  }
  for(int i = n; i > 0; i--){
    cur = 0ll+s[n]-s[i-1] - 1ll*a[i]*(n-i+1);
    ll lo = a[1], hi = a[i], mid, v = NINF;
    while(lo <= hi){
      mid = (0ll+lo+hi)>>1ll;
      int idx = upper_bound(a+1, a+1+n, mid)-a;
      idx--;
      if (cur + 1ll*idx*mid - s[idx] <= k)
        lo = mid+1, v = mid;
      else
        hi = mid-1;
    }
    ans = min(ans, a[i]-v);
  }
  printf("%lld\n", ans);
}


#include <bits/stdc++.h>

#ifndef NJUDGE
  #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll LINF = 0x3f3f3f3f3f3f3f3f;
const ll NLINF = 0xf7f7f7f7f7f7f7f7;
const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;

#define sz(x) (int) x.size()
#define eb emplace_back
#define pb push_back
#define ss second
#define ff first

const int N = 1e5+10;
ll k, cur, ans = LINF, s[N];
int n, a[N];

int main(){
  scanf("%d%lld", &n, &k);
  for(int i = 1; i <= n; i++)
    scanf("%d", a+i);
  sort(a+1, a+1+n);
  for(int i = 1; i <= n; i++)
    s[i] = s[i-1] + a[i];
  for(int i = 1; i <= n; i++){
    cur = 0ll + 1ll*i*a[i] - s[i];
    if (cur > k) break;
    ll lo = a[i], hi = a[n], mid, v = INF;
    while(lo <= hi){
      mid = (0ll+lo+hi)>>1ll;
      int idx = lower_bound(a+1, a+1+n, mid)-a;
      if (cur + s[n]-s[idx-1] - 1ll*mid*(n-idx+1) <= k)
        hi = mid-1, v = mid;
      else
        lo = mid+1;
    }
    ans = min(ans, v-a[i]);
  }
  for(int i = n; i > 0; i--){
    cur = 0ll + s[n]-s[i-1] - 1ll*a[i]*(n-i+1);
    if (cur > k) break;
    ll lo = a[1], hi = a[i], mid, v = NINF;
    while(lo <= hi){
      mid = (0ll+lo+hi)>>1ll;
      int idx = lower_bound(a+1, a+1+n, mid)-a;
      idx--;
      if (cur + 1ll*idx*mid - s[idx] <= k)
        lo = mid+1, v = mid;
      else
        hi = mid-1;
    }
    ans = min(ans, a[i]-v);
  }
  printf("%lld\n", ans);
}


#include <bits/stdc++.h>

#ifndef NJUDGE
  #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll LINF = 0x3f3f3f3f3f3f3f3f;
const ll NLINF = 0xf7f7f7f7f7f7f7f7;
const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;

#define sz(x) (int) x.size()
#define eb emplace_back
#define pb push_back
#define ss second
#define ff first

const int N = 1e5+10;
ll k, cur, ans = LINF, s[N];
int n, a[N];

int main(){
  scanf("%d%lld", &n, &k);
  for(int i = 1; i <= n; i++)
    scanf("%d", a+i);
  sort(a+1, a+1+n);
  for(int i = 1; i <= n; i++)
    s[i] = s[i-1] + a[i];
  for(int i = 1; i <= n; i++){
    cur = 0ll + 1ll*i*a[i] - s[i];
    ll lo = a[i], hi = a[n], mid, v = LINF;
    while(lo <= hi){
      mid = (0ll+lo+hi)>>1ll;
      int idx = lower_bound(a+1, a+1+n, mid)-a;
      if (cur + s[n]-s[idx-1] - 1ll*mid*(n-idx+1) <= k)
        hi = mid-1, v = mid;
      else
        lo = mid+1;
    }
    ans = min(ans, v-a[i]);
  }
  for(int i = n; i > 0; i--){
    cur = 0ll + s[n]-s[i-1] - 1ll*a[i]*(n-i+1);
    ll lo = a[1], hi = a[i], mid, v = NLINF;
    while(lo <= hi){
      mid = (0ll+lo+hi)>>1ll;
      int idx = lower_bound(a+1, a+1+n, mid)-a;
      idx--;
      if (cur + 1ll*idx*mid - s[idx] <= k)
        lo = mid+1, v = mid;
      else
        hi = mid-1;
    }
    ans = min(ans, a[i]-v);
  }
  printf("%lld\n", ans);
}


#include <bits/stdc++.h>

#ifndef NJUDGE
  #define dbg(...)
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll LINF = 0x3f3f3f3f3f3f3f3f;
const ll NLINF = 0xf7f7f7f7f7f7f7f7;
const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;

#define sz(x) (int) x.size()
#define eb emplace_back
#define pb push_back
#define ss second
#define ff first

const int N = 1e5+10;
int n, mx, mn = INF, addon, a[N];
ll v = (int) INF, k, s[N];

int main(){
  scanf("%d%lld", &n, &k);
  for(int i = 1; i <= n; i++)
    scanf("%d", &a[i]), mx = max(mx, a[i]), mn = min(mn, a[i]);
  sort(a+1, a+1+n);
  for(int i = 1; i <= n; i++)
    s[i] = s[i-1] + a[i];
  a[n+1] = INF;
  for(int i = 1; i <= n; i++){
    if (1ll*i*a[i]-s[i] > k) break;
    int lo = i, hi = n, mid, ans = n;
    while(lo <= hi){
      mid = (0ll+lo+hi)>>1ll;
      if (1ll*i*a[i]-s[i] + (s[n]-s[mid]-1ll*a[mid]*(n-mid)) <= k) hi = mid-1, ans = mid;
      else lo = mid+1;
    }
    ll lft = k - (1ll*i*a[i]-s[i] + (s[n]-s[ans]-1ll*a[ans]*(n-ans)));
    addon = max(min(0ll+a[i+1]-a[i], lft/i), min(0ll+a[ans]-a[ans-1], lft/(n-ans+1)));
    if (ans == i) addon = 0;
    dbg(i, ans, lft, addon);
    v = min(v, 0ll+a[ans]-a[i]-addon);
  }
  printf("%lld\n", v);
}