import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Problem8 {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		out=new PrintWriter(new BufferedOutputStream(System.out));
		FastReader s=new FastReader();
		String str=s.nextLine();
		ArrayList<String> arr=new ArrayList<>();
		int maxlength=0;
		while(true) {
			try {
				if(str==null)break;
				arr.add(str);
				maxlength=maxlength<str.length()?str.length():maxlength;
				str=s.nextLine();
			}catch(Exception e){
				break;
			}
		}
		String[] strarr=new String[arr.size()];
		arr.toArray(strarr);
		for(int i=0;i<maxlength+2;i++) {
			out.print("*");
		}
		boolean pos=false;
		out.println();
		for(String sr:arr)
		{

				out.print("*");
				int space=maxlength-sr.length();
				int right=space%2==0?space/2:(!pos?space/2+1:space/2);
				int left=space%2==0?space/2:(pos?space/2+1:space/2);
				pos=space%2==0?pos:!pos;
				while(left>0) {
					out.print(" ");
					left--;
				}
				out.print(sr);
				while(right>0) {
					out.print(" ");
					right--;
				}
				out.print("*");

			out.println();
		}
		for(int i=0;i<maxlength+2;i++) {
			out.print("*");
		}
		out.close();
	}

	public static PrintWriter out;

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct

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

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

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

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

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

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

}


package PetrSir;

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

public class Problem8 {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
		String str=s.readLine();
		ArrayList<String> arr=new ArrayList<>();
		int maxlength=0;
		while(str!=null) {
			arr.add(str);
			maxlength=maxlength<str.length()?str.length():maxlength;
			str=s.readLine();
		}
		String[] strarr=new String[arr.size()];
		arr.toArray(strarr);
		for(int i=0;i<maxlength+2;i++) {
			System.out.print("*");
		}
		boolean pos=false;
		System.out.println();
		for(int i=0;i<strarr.length;i++)
		{
			if(strarr[i].length()==maxlength) {
				System.out.print("*"+strarr[i]+"*");
			}
			else
			{
				System.out.print("*");
				int space=maxlength-strarr[i].length();
				int right=space%2==0?space/2:(!pos?space/2+1:space/2);
				int left=space%2==0?space/2:(pos?space/2+1:space/2);
				pos=space%2==0?pos:!pos;
				while(left>0) {
					System.out.print(" ");
					left--;
				}
				System.out.print(strarr[i]);
				while(right>0) {
					System.out.print(" ");
					right--;
				}
				System.out.print("*");
			}
			System.out.println();
		}
		for(int i=0;i<maxlength+2;i++) {
			System.out.print("*");
		}
	}

}


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

public class main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
		String str=s.readLine();
		ArrayList<String> arr=new ArrayList<>();
		int maxlength=0;
		while(true) {
			try {
				arr.add(str);
				maxlength=maxlength<str.length()?str.length():maxlength;
				if(str==null)break;
				str=s.readLine();
			}catch(Exception e){
				break;
			}
		}
		String[] strarr=new String[arr.size()];
		arr.toArray(strarr);
		for(int i=0;i<maxlength+2;i++) {
			System.out.print("*");
		}
		boolean pos=false;
		System.out.println();
		for(String sr:arr)
		{

				System.out.print("*");
				int space=maxlength-sr.length();
				int right=space%2==0?space/2:(!pos?space/2+1:space/2);
				int left=space%2==0?space/2:(pos?space/2+1:space/2);
				pos=space%2==0?pos:!pos;
				while(left>0) {
					System.out.print(" ");
					left--;
				}
				System.out.print(sr);
				while(right>0) {
					System.out.print(" ");
					right--;
				}
				System.out.print("*");

			System.out.println();
		}
		for(int i=0;i<maxlength+2;i++) {
			System.out.print("*");
		}
	}

}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Problem8 {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		out=new PrintWriter(new BufferedOutputStream(System.out));
		FastReader s=new FastReader();
		String str=s.nextLine();
		ArrayList<String> arr=new ArrayList<>();
		int maxlength=0;
		while(true) {
			try {
				if(str==null)break;
				arr.add(str);
				maxlength=maxlength<str.length()?str.length():maxlength;
				str=s.nextLine();
			}catch(Exception e){
				break;
			}
		}
		String[] strarr=new String[arr.size()];
		arr.toArray(strarr);
		for(int i=0;i<maxlength+2;i++) {
			out.print("*");
		}
		boolean pos=false;
		out.println();
		for(String sr:arr)
		{

				out.print("*");
				int space=maxlength-sr.length();
				int right=space%2==0?space/2:(!pos?space/2+1:space/2);
				int left=space%2==0?space/2:(pos?space/2+1:space/2);
				pos=space%2==0?pos:!pos;
				while(left>0) {
					out.print(" ");
					left--;
				}
				System.out.print(sr);
				while(right>0) {
					out.print(" ");
					right--;
				}
				out.print("*");

			out.println();
		}
		for(int i=0;i<maxlength+2;i++) {
			out.print("*");
		}
		out.close();
	}

	public static PrintWriter out;

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct

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

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

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

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

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

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

}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Problem8 {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		out=new PrintWriter(new BufferedOutputStream(System.out));
		FastReader s=new FastReader();
		String str=s.nextLine();
		ArrayList<String> arr=new ArrayList<>();
		int maxlength=0;
		while(true) {
			try {
				if(str==null)break;
				arr.add(str);
				maxlength=maxlength<str.length()?str.length():maxlength;
				str=s.nextLine();
			}catch(Exception e){
				break;
			}
		}
		String[] strarr=new String[arr.size()];
		arr.toArray(strarr);
		for(int i=0;i<maxlength+2;i++) {
			out.print("*");
		}
		boolean pos=false;
		out.println();
		for(String sr:arr)
		{

				System.out.print("*");
				int space=maxlength-sr.length();
				int right=space%2==0?space/2:(!pos?space/2+1:space/2);
				int left=space%2==0?space/2:(pos?space/2+1:space/2);
				pos=space%2==0?pos:!pos;
				while(left>0) {
					out.print(" ");
					left--;
				}
				System.out.print(sr);
				while(right>0) {
					out.print(" ");
					right--;
				}
				out.print("*");

			out.println();
		}
		for(int i=0;i<maxlength+2;i++) {
			out.print("*");
		}
		out.close();
	}

	public static PrintWriter out;

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct

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

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

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

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

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

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

}


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

public class main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
		String str=s.readLine();
		ArrayList<String> arr=new ArrayList<>();
		int maxlength=0;
		while(true) {
			try {
				if(str==null)break;
				arr.add(str);
				maxlength=maxlength<str.length()?str.length():maxlength;
				str=s.readLine();
			}catch(Exception e){
				break;
			}
		}
		String[] strarr=new String[arr.size()];
		arr.toArray(strarr);
		for(int i=0;i<maxlength+2;i++) {
			System.out.print("*");
		}
		boolean pos=false;
		System.out.println();
		for(String sr:arr)
		{

				System.out.print("*");
				int space=maxlength-sr.length();
				int right=space%2==0?space/2:(!pos?space/2+1:space/2);
				int left=space%2==0?space/2:(pos?space/2+1:space/2);
				pos=space%2==0?pos:!pos;
				while(left>0) {
					System.out.print(" ");
					left--;
				}
				System.out.print(sr);
				while(right>0) {
					System.out.print(" ");
					right--;
				}
				System.out.print("*");

			System.out.println();
		}
		for(int i=0;i<maxlength+2;i++) {
			System.out.print("*");
		}
	}

}


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

public class main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
		String str=s.readLine();
		ArrayList<String> arr=new ArrayList<>();
		int maxlength=0;
		while(true) {
			try {
				arr.add(str);
				maxlength=maxlength<str.length()?str.length():maxlength;
				if(str==null)break;
				str=s.readLine();
			}catch(Exception e){
				break;
			}
		}
		String[] strarr=new String[arr.size()];
		arr.toArray(strarr);
		for(int i=0;i<maxlength+2;i++) {
			System.out.print("*");
		}
		boolean pos=false;
		System.out.println();
		for(int i=0;i<strarr.length;i++)
		{
			if(strarr[i].length()==maxlength) {
				System.out.print("*"+strarr[i]+"*");
			}
			else
			{
				System.out.print("*");
				int space=maxlength-strarr[i].length();
				int right=space%2==0?space/2:(!pos?space/2+1:space/2);
				int left=space%2==0?space/2:(pos?space/2+1:space/2);
				pos=space%2==0?pos:!pos;
				while(left>0) {
					System.out.print(" ");
					left--;
				}
				System.out.print(strarr[i]);
				while(right>0) {
					System.out.print(" ");
					right--;
				}
				System.out.print("*");
			}
			System.out.println();
		}
		for(int i=0;i<maxlength+2;i++) {
			System.out.print("*");
		}
	}

}


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

public class Main implements Runnable {

    private void solve() throws IOException {
      LinkedList<String> pals=new LinkedList<>();
      String ff="";
      boolean left=true;
      int max=Integer.MIN_VALUE;
      String cad;
      while ((cad = reader.readLine())!=null){
 pals.add(cad);
 max=Math.max(pals.getLast().length(), max);
      }

        String spp="";

          for (int i = 0; i < max; i++) {
               ff+="*";
                spp+=" ";
            }
           ff+="**";
          int l,sp;
          String spaces="";
          for (int i = 0; i <pals.size(); i++) {
              l=pals.get(i).length();
               sp=max-l;
                 spaces="";
               for (int j = 0; j <sp/2; j++) {
                  spaces+=" ";

               }

           if(l%2==max%2){

               pals.set(i,spaces+ pals.get(i)+spaces);

           }
           else if(l==0)
               pals.set(i,spp);
           else {
           if(left==true){
            pals.set(i,spaces+ pals.get(i)+spaces+" ");
           left=false;
           }
           else{
            pals.set(i,spaces+" "+ pals.get(i)+spaces);
              left=true;
           }

           }

        }
          writer.println(ff);
          for (int i = 0; i < pals.size(); i++) {
           writer.println("*"+pals.get(i)+"*");

        }
            writer.println(ff);

 }

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

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

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

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

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


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

public class Main implements Runnable {

    private void solve() throws IOException {
      LinkedList<String> pals=new LinkedList<>();
      String ff="";
      boolean left=true;
      int max=Integer.MIN_VALUE;
        try{

 while(true){
 pals.add(reader.readLine());
 max=Math.max(pals.getLast().length(), max);

 }

    }
    catch(Exception ex){}

          for (int i = 0; i < max; i++) {
               ff+="*";

            }
          int l,sp;
          String spaces="";
          for (int i = 0; i <pals.size(); i++) {
              l=pals.get(i).length();
               sp=max-l;
               for (int j = 0; j <sp/2; j++) {
                  spaces+=" ";

               }

           if(l%2==max%2){

               pals.set(i,spaces+ pals.get(i)+spaces);

           }
           else {
           if(left){
            pals.set(i,spaces+ pals.get(i)+spaces.substring(1));
           left=false;
           }
           else{
            pals.set(i,spaces.substring(1)+ pals.get(i)+spaces);
              left=true;
           }

           }

        }
          writer.println(ff);
          for (int i = 0; i < pals.size(); i++) {
           writer.println("*"+pals.get(i)+"*");

        }
            writer.println(ff);

 }

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

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

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

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

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

// simple
public class P5B {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<String> lines = new ArrayList<>();
        int maxLen = 0;
        while (sc.hasNextLine()) {
            String line = sc.nextLine();
            if (line.equals("AAA")) {
                break;
            }
            maxLen = Math.max(maxLen, line.length());
            lines.add(line);
        }

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < maxLen + 2; ++i) {
            sb.append('*');
        }
        sb.append('\n');

        int flag = 0;
        for (String line : lines) {
            if (line.isEmpty()) {
                sb.append('*');
                for (int i = 0; i < maxLen; ++i) {
                    sb.append(' ');
                }
                sb.append("*\n");
            } else {
                int l, r;
                if ((maxLen - line.length()) % 2 == 0) {
                    l = r = (maxLen - line.length()) / 2;
                } else {
                    l = (maxLen - line.length()) / 2 + flag;
                    r = maxLen - line.length() - l;
                    flag = (flag + 1) % 2;
                }
                sb.append('*');
                for (int i = 0; i < l; ++i) {
                    sb.append(' ');
                }
                sb.append(line);
                for (int i = 0; i < r; ++i) {
                    sb.append(' ');
                }
                sb.append("*\n");
            }
        }

        for (int i = 0; i < maxLen + 2; ++i) {
            sb.append('*');
        }
        System.out.println(sb.toString());
    }

}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class P5B {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<String> lines = new ArrayList<>();
        int maxLen = 0;
        while (sc.hasNextLine()) {
            String line = sc.nextLine();
            if (line.equals("AAA")) {
                break;
            }
            maxLen = Math.max(maxLen, line.length());
            lines.add(line);
        }

        printRepCh('*', maxLen + 2);
        System.out.println();

        int flag = 0;
        for (String line : lines) {
            if (line.isEmpty()) {
                System.out.print('*');
                printRepCh(' ', maxLen);
                System.out.println('*');
            } else {
                int l, r;
                if ((maxLen - line.length()) % 2 == 0) {
                    l = r = (maxLen - line.length()) / 2;
                } else {
                    l = (maxLen - line.length()) / 2 + flag;
                    r = maxLen - line.length() - l;
                    flag = (flag + 1) % 2;
                }
                System.out.print('*');
                printRepCh(' ', l);
                System.out.print(line);
                printRepCh(' ', r);
                System.out.println('*');
            }
        }

        printRepCh('*', maxLen + 2);
        System.out.println();
    }

    private static void printRepCh(char ch, int times) {
        for (int i = 0; i < times; ++i) {
            System.out.print(ch);
        }
    }

}


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

 public class B5 {

	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		ArrayList<String> list = new ArrayList();
		String s =new String();
		int max=0;
		while((s=br.readLine())!=null)
		{
			list.add(s);
			max=Math.max(s.length(), max);
		}
		StringBuilder line = new StringBuilder();
		for(int i=0;i<max+2;i++)
			line.append('*');
		pw.println(line);
		int k=0;
		for(String ss:list)
		{
			StringBuilder sb = new StringBuilder();
			sb.append('*');
			int dif=max-ss.length();
			int left=dif/2+k;
			int right=dif-left;
			if(left!=right)
				k=1-k;
			for(int i=0;i<left;i++)
				sb.append(' ');
			sb.append(ss);
			for(int i=0;i<right;i++)
				sb.append(' ');
            sb.append('*');
            pw.println(sb);

		}
		//pw.println(list);
		pw.println(line);

		pw.close();
	}

}


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

 public class B5 {

	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		ArrayList<String> list = new ArrayList();
		String s =new String();
		int max=0;
		while((s=br.readLine())!=null)
		{
			list.add(s);
			max=Math.max(s.length(), max);
		}
		StringBuilder line = new StringBuilder();
		for(int i=0;i<max+2;i++)
			line.append('*');
		pw.println(line);
		for(String ss:list)
		{
			StringBuilder sb = new StringBuilder();
			sb.append('*');
			int dif=max-ss.length();
			int left=dif/2;
			int right=dif-left;
			for(int i=0;i<left;i++)
				sb.append(' ');
			sb.append(ss);
			for(int i=0;i<right;i++)
				sb.append(' ');
            sb.append('*');
            pw.println(sb);

		}
		//pw.println(list);
		pw.println(line);

		pw.close();
	}

}


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

 public class B5 {

	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		ArrayList<String> list = new ArrayList();
		String s =new String();
		int max=0;
		while((s=br.readLine())!=null)
		{
			list.add(s);
			max=Math.max(s.length(), max);
			//pw.println(s.length());
		}
		StringBuilder line = new StringBuilder();
		for(int i=0;i<max+2;i++)
			line.append('*');
		pw.println(line);
		int k=0;
		for(String ss:list)
		{
			StringBuilder sb = new StringBuilder();
			sb.append('*');

			int dif=max-ss.length();
			int left=0;
			int right=0;
			if(dif%2==0)
			{
				 left=dif/2;
				 right=dif-left;
			}
			else
			{
				 left=dif/2+k;
				 right=dif-left;
				k=1-k;
			}
			for(int i=0;i<left;i++)
				sb.append(' ');
			sb.append(ss);
			for(int i=0;i<right;i++)
				sb.append(' ');
            sb.append('*');
            pw.println(sb);

		}
		//pw.println(list);
		pw.println(line);

		pw.close();
	}

}


import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class b {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    List<String> msg = new ArrayList<>();
    int maxLength = 0;

    while (sc.hasNextLine()) {
      String line = sc.nextLine();
      maxLength = Math.max(maxLength, line.length());
      msg.add(line);
    }

    int blockLength = maxLength + 2;
    int placeLeft = 1;
    System.out.println(repeat('*', blockLength));

    for (String line: msg) {
      int whitespaces = maxLength - line.length();

      if (whitespaces % 2 == 0) {
        System.out.print('*' + repeat(' ', whitespaces / 2));
        System.out.print(line);
        System.out.println(repeat(' ', whitespaces / 2) + '*');
      } else {
        int alignLeft, alignRight;

        if (placeLeft > 0) {
          alignLeft = whitespaces / 2;
          alignRight = whitespaces - alignLeft;
        } else {
          alignRight = whitespaces / 2;
          alignLeft = whitespaces - alignRight;
        }

        System.out.print('*' + repeat(' ', alignLeft));
        System.out.print(line);
        System.out.println(repeat(' ', alignRight) + '*');
        placeLeft = 1 - placeLeft;
      }
    }

    System.out.println(repeat('*', blockLength));
  }

  private static String repeat(char chr, int n) {
    char[] chars = new char[n];

    for (int i = 0; i < n; ++i) {
      chars[i] = chr;
    }

    return new String(chars);
  }
}


import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class b {

    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        List<String> msg = new ArrayList<>();
        int maxLength = 0;

        while (sc.hasNextLine()) {
            String line = sc.nextLine();

            //if (line.equals("stop")) break;

            msg.add(line);
            maxLength = Math.max(maxLength, line.length());
        }

        int blockLength = maxLength + 2;
        int placeLeft = 1;

        System.out.println(repeat('*', blockLength));

        for (String line: msg) {
            int whitespaces = maxLength - line.length();

            if (whitespaces % 2 == 0) {
                System.out.print('*' + repeat(' ', whitespaces / 2));
                System.out.print(line);
                System.out.println(repeat(' ', whitespaces / 2) + '*');
            } else {
                int alignLeft, alignRight;
                //System.out.println("Block length: " + blockLength);
                //System.out.println("Line length: " + line.length());

                if (placeLeft > 0) {
                    alignLeft = whitespaces / 2;
                    alignRight = whitespaces - alignLeft;
                } else {
                    alignRight = whitespaces / 2;
                    alignLeft = whitespaces - alignRight;
                }

                //System.out.println("left: " +alignLeft+ ", right: " +alignRight);

                System.out.print('*' + repeat(' ', alignLeft));
                System.out.print(line);
                System.out.println(repeat(' ', alignRight) + '*');

                // inverse
                placeLeft = 1 - placeLeft;
            }
        }

        System.out.println(repeat('*', blockLength));
    }

    private static String repeat(char chr, int n) {
        char[] chars = new char[n];

        // Arrays.fill
        for (int i = 0; i < n; i++) {
            chars[i] = chr;
        }

        return new String(chars);
    }
}


/**
 * Created by ankeet on 1/13/17.
 */
import java.io.*;
import java.util.*;

public class B5 {

    static FastReader in = null;
    static PrintWriter out = null;

    public static void solve()
    {
        LinkedList<String> lines = new LinkedList<>();
        while(true){
            try{
                String line = in.nextLine();
                if(line == null)
                    break;
                lines.add(line);
            }catch(Exception e){
                break;
            }
        }
        int maxlen = 0;
        for(String s : lines) maxlen = Math.max(s.length(), maxlen);

        for(int i=0; i<=maxlen+1; i++) out.print("*");
        out.println("");

        boolean left = true;
        for(String ss: lines){
            String s = new String(ss);
            out.print("*");
            if(maxlen%2 != s.length() % 2 && s.length() > 0){
                if(left) s = s + " ";
                else s = " " + s;
                left = !left;
            }

            if(s.length() == 0){
                for(int i=0; i<maxlen; i++) out.print(" ");
            }
            else {
                while (s.length() < maxlen) s = " " + s + " ";
            }

            out.print(s);
            out.println("*");
        }

        for(int i =0; i<=maxlen+1; i++) out.print("*");
        out.println("");

    }

    public static void main(String[] args)
    {
        in = new FastReader(System.in);
        out = new PrintWriter(System.out);
        solve();
        out.flush();
        out.close();

    }

    static class FastReader {

        BufferedReader read;
        StringTokenizer tokenizer;

        public FastReader(InputStream in)
        {
            read = new BufferedReader(new InputStreamReader(in));
        }

        public String next()
        {
            while(tokenizer == null || !tokenizer.hasMoreTokens())
            {
                try{
                    tokenizer = new StringTokenizer(read.readLine());
                }catch(Exception e){
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public String nextLine(){

            try
            {
                return read.readLine();
            }
            catch(Exception e)
            {
                throw new RuntimeException(e);
            }
        }
        public int nextInt()
        {
            return Integer.parseInt(next());
        }
        public long nextLong()
        {
            return Long.parseLong(next());
        }
        public double nextDouble()
        {
            return Double.parseDouble(next());
        }

        public int[] nextIntArr(int n)
        {
            int[] a = new int[n];
            for(int i=0; i<n; ++i)
            {
                a[i] = nextInt();
            }
            return a;
        }

        public long[] nextLongArr(int n)
        {
            long[] a = new long[n];
            for(int i=0; i<n; ++i)
            {
                a[i] = nextLong();
            }
            return a;
        }
    }

}


/**
 * Created by ankeet on 1/13/17.
 */
import java.io.*;
import java.util.*;

public class B5 {

    static FastReader in = null;
    static PrintWriter out = null;

    public static void solve()
    {
        LinkedList<String> lines = new LinkedList<>();
        while(true){
            try{
                String line = in.nextLine();
                if(line == null)
                    break;
                lines.add(line);
            }catch(Exception e){
                break;
            }
        }
        int maxlen = 0;
        for(String s : lines) maxlen = Math.max(s.length(), maxlen);

        for(int i=0; i<maxlen; i++) out.print("*");
        out.println("");

        boolean left = true;
        for(String ss: lines){
            String s = new String(ss);
            out.print("*");
            if(maxlen%2 != s.length() % 2 && s.length() > 0){
                if(left) s = s + " ";
                else s = " " + s;
                left = !left;
            }

            if(s.length() == 0){
                for(int i=0; i<maxlen; i++) out.print(" ");
            }
            else {
                while (s.length() < maxlen) s = " " + s + " ";
            }

            out.print(s);
            out.println("*");
        }

        for(int i =0; i<maxlen; i++) out.print("*");
        out.println("");

    }

    public static void main(String[] args)
    {
        in = new FastReader(System.in);
        out = new PrintWriter(System.out);
        solve();
        out.flush();
        out.close();

    }

    static class FastReader {

        BufferedReader read;
        StringTokenizer tokenizer;

        public FastReader(InputStream in)
        {
            read = new BufferedReader(new InputStreamReader(in));
        }

        public String next()
        {
            while(tokenizer == null || !tokenizer.hasMoreTokens())
            {
                try{
                    tokenizer = new StringTokenizer(read.readLine());
                }catch(Exception e){
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public String nextLine(){

            try
            {
                return read.readLine();
            }
            catch(Exception e)
            {
                throw new RuntimeException(e);
            }
        }
        public int nextInt()
        {
            return Integer.parseInt(next());
        }
        public long nextLong()
        {
            return Long.parseLong(next());
        }
        public double nextDouble()
        {
            return Double.parseDouble(next());
        }

        public int[] nextIntArr(int n)
        {
            int[] a = new int[n];
            for(int i=0; i<n; ++i)
            {
                a[i] = nextInt();
            }
            return a;
        }

        public long[] nextLongArr(int n)
        {
            long[] a = new long[n];
            for(int i=0; i<n; ++i)
            {
                a[i] = nextLong();
            }
            return a;
        }
    }

}


import java.util.*;
import java.io.*;
import java.math.*;
import java.util.stream.IntStream;
import java.util.stream.LongStream;

public class Test{
    public static void main(String[] args) throws Exception {
        //InputReader in = new InputReader();
        InputStream inputStream = System.in;
        Scanner in = new Scanner(inputStream);
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        long mod = (int)1e9+7;
        ArrayList<String> al = new ArrayList<>();
        boolean alternate = false;
        while(in.hasNext())
            al.add(in.nextLine());
        int max = 0;
        int size = al.size();
        for(int i=0;i<size;i++)
            max = Math.max(max,al.get(i).length());
        for(int i=0;i<max+2;++i)
            out.print("*");
        out.println();
        for(int i=0;i<size;i++){
            out.print("*");
            int diff = max-al.get(i).length();
            int before = 0;
            int after = 0;
            if(diff%2==0)
                before = after = diff/2;
            else{
                if(!alternate){
                    before = diff/2;
                    after = diff-before;
                    alternate = true;
                }
                else{
                    after = diff/2;
                    before = diff-after;
                    alternate = false;
                }
            }
            for(int j=0;j<before;j++)
                out.print(" ");
            out.print(al.get(i));
            for(int j=0;j<after;j++)
                out.print(" ");
            out.println("*");
        }
        for(int i=0;i<max+2;i++)
            out.print("*");
        out.println();
        out.close();
    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

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

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

        int ni() {
            return Integer.parseInt(n());
        }

        long nl() {
            return Long.parseLong(n());
        }

        double nd() {
            return Double.parseDouble(n());
        }

        String nli() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                throw new RuntimeException();
            }
            return str;
        }
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.util.stream.IntStream;
import java.util.stream.LongStream;

public class Test{
    public static void main(String[] args) throws Exception {
        //InputReader in = new InputReader();
        InputStream inputStream = System.in;
        Scanner in = new Scanner(inputStream);
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        long mod = (int)1e9+7;
        ArrayList<String> al = new ArrayList<>();
        //int count = 7;
        while(in.hasNext())
            al.add(in.nextLine());
        int max = 0;
        int size = al.size();
        for(int i=0;i<size;i++)
            max = Math.max(max,al.get(i).length());
        for(int i=0;i<max+2;++i)
            out.print("*");
        out.println();
        for(int i=0;i<size;i++){
            out.print("*");
            int diff = max-al.get(i).length();
            int before = 0;
            int after = 0;
            if(diff%2==0)
                before = after = diff/2;
            else{
                after = diff/2;
                before = diff-after;
            }
            for(int j=0;j<before;j++)
                out.print(" ");
            out.print(al.get(i));
            for(int j=0;j<after;j++)
                out.print(" ");
            out.println("*");
        }
        for(int i=0;i<max+2;i++)
            out.print("*");
        out.println();
        out.close();
    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

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

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

        int ni() {
            return Integer.parseInt(n());
        }

        long nl() {
            return Long.parseLong(n());
        }

        double nd() {
            return Double.parseDouble(n());
        }

        String nli() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                throw new RuntimeException();
            }
            return str;
        }
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.util.stream.IntStream;
import java.util.stream.LongStream;

public class Test{
    public static void main(String[] args) throws Exception {
        //InputReader in = new InputReader();
//        InputStream inputStream = System.in;
//        Scanner in = new Scanner(inputStream);
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        long mod = (int)1e9+7;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<String> al = new ArrayList<>();
        boolean alternate = false;
        int count = 0;
        while(true) {
            String s = br.readLine();
            if(s!=null)
                al.add(s);
            else
                break;
        }
        int max = 0;
        int size = al.size();
        for(int i=0;i<size;++i)
            max = Math.max(max,al.get(i).length());
        for(int i=0;i<max+2;++i)
            out.print("*");
        out.println();
        for(int i=0;i<size;++i){
            out.print("*");
            int diff = max-al.get(i).length();
            int before,after;
            if(diff%2==0) {
                before = after = diff / 2;
            }
            else{
                if(!alternate){
                    before = diff/2;
                    after = diff-before;
                    alternate = true;
                }
                else{
                    after = diff/2;
                    before = diff-after;
                    alternate = false;
                }
            }
            for(int j=0;j<before;j++)
                out.print(" ");
            out.print(al.get(i));
            for(int j=0;j<after;j++)
                out.print(" ");
            out.println("*");
        }
        for(int i=0;i<max+2;i++)
            out.print("*");
        out.println();
        out.close();
    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

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

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

        int ni() {
            return Integer.parseInt(n());
        }

        long nl() {
            return Long.parseLong(n());
        }

        double nd() {
            return Double.parseDouble(n());
        }

        String nli() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                throw new RuntimeException();
            }
            return str;
        }
    }
}


import java.util.*;

public class CenterAlignment {

    public static Scanner in;

    public static final int MOD = (int) (1e9 + 7);
    public static void main(String[] args) {
        in = new Scanner(System.in);

        ArrayList<String> arr = new ArrayList<String>();
        int width = -1;
        while(in.hasNextLine()) {
            String tmp = in.nextLine();
            if(tmp.equals("wild"))  break;
            arr.add(tmp);
            width = Math.max(tmp.length(), width);
        }
        width += 2;
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < width; i++)     result.append("*");
        result.append("\n");
        int prev1 = 0,
                prev2 = 1;
        for (int i = 0; i < arr.size(); i++) {
            result.append("*");
            int cutoff = width - arr.get(i).length() - 2;
            for(int j = 1; j <= cutoff/2 +  ((cutoff&1) == 1? prev1: 0); j++)  result.append(" ");
            result.append(arr.get(i));
            for(int j = 1; j <= cutoff/2 +  ((cutoff&1) == 1? prev2: 0); j++)  result.append(" ");
            if((cutoff&1) == 1) {
                prev1 = 1 - prev1;
                prev2 = 1 - prev2;
            }
            result.append("*\n");
        }
        for (int i = 0; i < width; i++)     result.append("*");
        result.append("\n");
        System.out.println(result.toString());
    }

    static class Node implements Comparable<Node>{
        int next;
        long dist;

        public Node (int u, int v) {
            this.next = u;
            this.dist = v;
        }

        public int compareTo(Node n) {
            return Integer.compare(-this.next, -n.next);
        }
    }
}


import java.util.*;

public class CenterAlignment {

    public static Scanner in;

    public static final int MOD = (int) (1e9 + 7);
    public static void main(String[] args) {
        in = new Scanner(System.in);

        ArrayList<String> arr = new ArrayList<String>();
        int width = -1;
        while(in.hasNextLine()) {
            String tmp = in.nextLine();
            //if(tmp.equals("wild"))  break;
            arr.add(tmp);
            width = Math.max(tmp.length(), width);
        }
        width += 2;
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < width; i++)     result.append("*");
        result.append("\n");
        for (int i = 0; i < arr.size(); i++) {
            result.append("*");
            int cutoff = width - arr.get(i).length();
            for(int j = 0; j <= cutoff/2 + 1; j++)  result.append(" ");
            result.append(arr.get(i));
            for(int j = 0; j <= cutoff/2; j++)  result.append(" ");
            result.append("*\n");
        }
        for (int i = 0; i < width; i++)     result.append("*");
        result.append("\n");
        System.out.println(result.toString());
    }

    static class Node implements Comparable<Node>{
        int next;
        long dist;

        public Node (int u, int v) {
            this.next = u;
            this.dist = v;
        }

        public int compareTo(Node n) {
            return Integer.compare(-this.next, -n.next);
        }
    }
}


import java.util.*;

public class CenterAlignment {

    public static Scanner in;

    public static final int MOD = (int) (1e9 + 7);
    public static void main(String[] args) {
        in = new Scanner(System.in);

        ArrayList<String> arr = new ArrayList<String>();
        int width = -1;
        while(in.hasNextLine()) {
            String tmp = in.nextLine();
            if(tmp.equals("wild"))  break;
            arr.add(tmp);
            width = Math.max(tmp.length(), width);
        }
        width += 2;
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < width; i++)     result.append("*");
        result.append("\n");
        for (int i = 0; i < arr.size(); i++) {
            result.append("*");
            int cutoff = width - arr.get(i).length() - 2;
            for(int j = 1; j <= cutoff/2; j++)  result.append(" ");
            result.append(arr.get(i));
            for(int j = 1; j <= cutoff/2 + ((cutoff&1) == 1? 1: 0); j++)  result.append(" ");
            result.append("*\n");
        }
        for (int i = 0; i < width; i++)     result.append("*");
        result.append("\n");
        System.out.println(result.toString());
    }

    static class Node implements Comparable<Node>{
        int next;
        long dist;

        public Node (int u, int v) {
            this.next = u;
            this.dist = v;
        }

        public int compareTo(Node n) {
            return Integer.compare(-this.next, -n.next);
        }
    }
}


import java.util.*;

public class CenterAlignment {

    public static Scanner in;

    public static final int MOD = (int) (1e9 + 7);
    public static void main(String[] args) {
        in = new Scanner(System.in);

        ArrayList<String> arr = new ArrayList<String>();
        int width = -1;
        while(in.hasNextLine()) {
            String tmp = in.nextLine();
            if(tmp.equals("wild"))  break;
            arr.add(tmp);
            width = Math.max(tmp.length(), width);
        }
        width += 2;
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < width; i++)     result.append("*");
        result.append("\n");
        for (int i = 0; i < arr.size(); i++) {
            result.append("*");
            int cutoff = width - arr.get(i).length() - 2;
            for(int j = 1; j <= cutoff/2 + ((cutoff&1) == 1? 1: 0); j++)  result.append(" ");
            result.append(arr.get(i));
            for(int j = 1; j <= cutoff/2; j++)  result.append(" ");
            result.append("*\n");
        }
        for (int i = 0; i < width; i++)     result.append("*");
        result.append("\n");
        System.out.println(result.toString());
    }

    static class Node implements Comparable<Node>{
        int next;
        long dist;

        public Node (int u, int v) {
            this.next = u;
            this.dist = v;
        }

        public int compareTo(Node n) {
            return Integer.compare(-this.next, -n.next);
        }
    }
}


import java.util.*;

public class CenterAlignment {

    public static Scanner in;

    public static final int MOD = (int) (1e9 + 7);
    public static void main(String[] args) {
        in = new Scanner(System.in);

        ArrayList<String> arr = new ArrayList<String>();
        int width = -1;
        while(in.hasNextLine()) {
            String tmp = in.nextLine();
            //if(tmp.equals("wild"))  break;
            arr.add(tmp);
            width = Math.max(tmp.length(), width);
        }
        width += 2;
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < width; i++)     result.append("*");
        result.append("\n");
        for (int i = 0; i < arr.size(); i++) {
            result.append("*");
            int cutoff = width - arr.get(i).length() - 2;
            for(int j = 0; j <= cutoff/2 + 1; j++)  result.append(" ");
            result.append(arr.get(i));
            for(int j = 0; j <= cutoff/2; j++)  result.append(" ");
            result.append("*\n");
        }
        for (int i = 0; i < width; i++)     result.append("*");
        result.append("\n");
        System.out.println(result.toString());
    }

    static class Node implements Comparable<Node>{
        int next;
        long dist;

        public Node (int u, int v) {
            this.next = u;
            this.dist = v;
        }

        public int compareTo(Node n) {
            return Integer.compare(-this.next, -n.next);
        }
    }
}


import java.util.*;

public class CenterAlignment {

    public static Scanner in;

    public static final int MOD = (int) (1e9 + 7);
    public static void main(String[] args) {
        in = new Scanner(System.in);

        ArrayList<String> arr = new ArrayList<String>();
        int width = -1;
        while(in.hasNextLine()) {
            String tmp = in.nextLine();
            //if(tmp.equals("wild"))  break;
            arr.add(tmp);
            width = Math.max(tmp.length(), width);
        }
        width += 2;
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < width; i++)     result.append("*");
        result.append("\n");
        for (int i = 0; i < arr.size(); i++) {
            result.append("*");
            int cutoff = width - arr.get(i).length() - 2;
            for(int j = 0; j <= cutoff/2 + ((cutoff&1) == 1? 1: 0); j++)  result.append(" ");
            result.append(arr.get(i));
            for(int j = 0; j <= cutoff/2; j++)  result.append(" ");
            result.append("*\n");
        }
        for (int i = 0; i < width; i++)     result.append("*");
        result.append("\n");
        System.out.println(result.toString());
    }

    static class Node implements Comparable<Node>{
        int next;
        long dist;

        public Node (int u, int v) {
            this.next = u;
            this.dist = v;
        }

        public int compareTo(Node n) {
            return Integer.compare(-this.next, -n.next);
        }
    }
}


import java.util.Scanner;
import java.io.FileNotFoundException;
import java.util.ArrayList;

public class B_CenterAlignment
{
	public static void main(String[] args) throws FileNotFoundException
	{
		ArrayList<String> lines = new ArrayList<>();
		int max_length = 0;
		int spaces;
		int s = 1;

		Scanner in = new Scanner(System.in);

		int length = 0;
		while (in.hasNextLine()) {
			String line = in.nextLine();
			lines.add(line);
			length = line.length();
			if (length > max_length)
				max_length = length;
		}

		// top and bottom borders filled of stars
		String border = getBorders(max_length + 2);

		//special case when line length is zero
		String emptyLine = "*" + getSpaces(max_length) + "*";

		//general case in which input line will be centered in templine
		String tempLine = "*" + getSpaces(max_length - 1) + "*";

		System.out.println(border);

		String str = "";
		for (int i = 0; i < lines.size(); i++)
		{
			if(lines.get(i).length() == 0)
			{
				System.out.println(emptyLine);
				continue;
			}
			spaces = max_length - lines.get(i).length();

			if (spaces % 2 == 0)
			{
				int startingIndex = spaces / 2;
				int endIndex = startingIndex + lines.get(i).length();
				str = tempLine.substring(0, startingIndex + 1) + lines.get(i) + tempLine.substring(endIndex);
				System.out.println(str);
			}
			else
			{
				if (s % 2 != 0)
				{
					int startingIndex = spaces / 2;
					int endIndex = startingIndex + lines.get(i).length();
					str = tempLine.substring(0, startingIndex + 1) + lines.get(i) + tempLine.substring(endIndex);
					System.out.println(str);
					s++;
				}
				else
				{
					int startingIndex = spaces / 2 + 1;
					int endIndex = startingIndex + lines.get(i).length();
					str = tempLine.substring(0, startingIndex + 1) + lines.get(i) + tempLine.substring(endIndex);
					System.out.println(str);
					s++;
				}
			}
		}

		System.out.println(border);
	}

	private static String getBorders(int length)
	{
		String str = "";
		for (int i = 0; i < length; i++)
		{
			str = str + "*";
		}

		return str;
	}

	private static String getSpaces(int max_length)
	{
		String str = "";
		for(int m = 0; m < max_length; m++)
		{
			str = str + " ";
		}
		return str;
	}

}


import java.util.Scanner;
import java.io.FileNotFoundException;
import java.util.ArrayList;

public class B_CenterAlignment
{
	public static void main(String[] args) throws FileNotFoundException
	{
		ArrayList<String> lines = new ArrayList<>();
		int max_length = 0;
		int spaces;
		int s = 1;

		Scanner in = new Scanner(System.in);
		/*
		for(int m = 0; m < 7; m++)
		{
			String line = in.nextLine();
			lines.add(line);
			int length = line.length();
			if (length > max_length)
				max_length = length;
		}
		*/

		while (in.hasNextLine()) {
			String line = in.nextLine();
			lines.add(line);
			int length = line.length();
			if (length > max_length)
				max_length = length;
		}

		printStars(max_length + 2);
		String em = getSpaces(max_length);
		em = "*" + em + "*";

		String temp = "*";
		for(int j = 0; j < max_length - 1; j++)
		{
			temp = temp + " ";
		}
		temp = temp + "*";

		String str = "";
		for (int i = 0; i < lines.size(); i++)
		{
			if(lines.get(i).length() == 0)
			{
				System.out.println(em);
				continue;
			}
			spaces = max_length - lines.get(i).length();

			if (spaces % 2 == 0)
			{
				int startingIndex = spaces / 2;
				int endIndex = startingIndex + lines.get(i).length();
				str = temp.substring(0, startingIndex + 1) + lines.get(i) + temp.substring(endIndex);
				System.out.println(str);
			}
			else
			{
				if (s % 2 != 0)
				{
					int startingIndex = spaces / 2;
					int endIndex = startingIndex + lines.get(i).length();
					str = temp.substring(0, startingIndex + 1) + lines.get(i) + temp.substring(endIndex);
					System.out.println(str);
					s++;
				}
				else
				{
					int startingIndex = spaces / 2 + 1;
					int endIndex = startingIndex + lines.get(i).length();
					str = temp.substring(0, startingIndex + 1) + lines.get(i) + temp.substring(endIndex);
					System.out.println(str);
					s++;
				}
			}
		}
		printStars(max_length + 2);
		in.close();
	}

	private static String getSpaces(int max_length)
	{
		String str = "";
		for(int m = 0; m < max_length; m++)
		{
			str = str + " ";
		}
		return str;
	}

	public static void printStars(int stars) {
		for (int i = 0; i < stars; i++) {
			System.out.print("*");
		}
		System.out.println("");
	}

	public static void printSpaces(int spaces) {
		for (int j = 0; j < spaces; j++) {
			System.out.print(" ");
		}
	}
}


import java.util.Scanner;
import java.io.FileNotFoundException;
import java.util.ArrayList;
public class CenterAlignment
{
	public static void main(String[]args) throws FileNotFoundException
	{
		ArrayList<String> lines=new ArrayList<>();
		int max_length=0;
		int spaces;
		int s=1; int right_spaces;
		Scanner in=new Scanner(System.in);
		while(in.hasNextLine())
		{
			String line=in.nextLine();
			lines.add(line);
			int length=line.length();
			if(length>max_length)
				max_length=length;
		}
		printStars(max_length+2);
		for(int i=0;i<lines.size();i++)
		{
			System.out.print("*");
			spaces=max_length-lines.get(i).length();
			if(spaces%2==0)
			{
				printSpaces(spaces/2);
				right_spaces=spaces/2;
			}
			else
			{
				if(s%2!=0)
				{
					printSpaces(spaces/2);
					right_spaces=(spaces+1)/2;
					s++;
				}
				else
				{
					printSpaces((spaces+1)/2);
					right_spaces=spaces/2;
					s++;
				}
			}
			System.out.print(lines.get(i));
			printSpaces(right_spaces);
			System.out.println("*");
		}
		printStars(max_length+2);
		in.close();
	}
	public static void printStars(int stars)
	{
		for(int i=0;i<stars;i++)
		{
			System.out.print("*");
		}
		System.out.println("");
	}
	public static void printSpaces(int spaces)
	{
		for(int j=0;j<spaces;j++)
		{
			System.out.print(" ");
		}
	}
}


import java.util.Scanner;
import java.io.FileNotFoundException;
import java.util.ArrayList;

public class B_CenterAlignment
{
	public static void main(String[] args) throws FileNotFoundException
	{
		ArrayList<String> lines = new ArrayList<>();
		int max_length = 0;
		int spaces;
		int s = 1;

		Scanner in = new Scanner(System.in);
		/*
		for(int m = 0; m < 7; m++)
		{
			String line = in.nextLine();
			lines.add(line);
			int length = line.length();
			if (length > max_length)
				max_length = length;
		}
		*/

		while (in.hasNextLine()) {
			String line = in.nextLine();
			lines.add(line);
			int length = line.length();
			if (length > max_length)
				max_length = length;
		}

		printStars(max_length + 2);

		String temp = "*";
		for(int j = 0; j < max_length - 1; j++)
		{
			temp = temp + " ";
		}
		temp = temp + "*";

		String str = "";
		for (int i = 0; i < lines.size(); i++)
		{
			spaces = max_length - lines.get(i).length();

			if (spaces % 2 == 0)
			{
				int startingIndex = spaces / 2;
				int endIndex = startingIndex + lines.get(i).length();
				str = temp.substring(0, startingIndex + 1) + lines.get(i) + temp.substring(endIndex);
				System.out.println(str);
			}
			else
			{
				if (s % 2 != 0)
				{
					int startingIndex = spaces / 2;
					int endIndex = startingIndex + lines.get(i).length();
					str = temp.substring(0, startingIndex + 1) + lines.get(i) + temp.substring(endIndex);
					System.out.println(str);
					s++;
				}
				else
				{
					int startingIndex = spaces / 2 + 1;
					int endIndex = startingIndex + lines.get(i).length();
					str = temp.substring(0, startingIndex + 1) + lines.get(i) + temp.substring(endIndex);
					System.out.println(str);
					s++;
				}
			}
		}
		printStars(max_length + 2);
		in.close();
	}

	public static void printStars(int stars) {
		for (int i = 0; i < stars; i++) {
			System.out.print("*");
		}
		System.out.println("");
	}

	public static void printSpaces(int spaces) {
		for (int j = 0; j < spaces; j++) {
			System.out.print(" ");
		}
	}
}


import java.util.Scanner;
import java.io.FileNotFoundException;
import java.util.ArrayList;

public class B_CenterAlignment
{
	public static void main(String[] args) throws FileNotFoundException
	{
		ArrayList<String> lines = new ArrayList<>();
		int max_length = 0;
		int spaces;
		int s = 1;

		Scanner in = new Scanner(System.in);

		int length = 0;
		while (in.hasNextLine()) {
			String line = in.nextLine();
			lines.add(line);
			length = line.length();
			if (length > max_length)
				max_length = length;
		}

		// top and bottom borders filled of stars
		String border = getBorders(max_length + 2);

		//special case when line length is zero
		String emptyLine = "*" + getSpaces(max_length) + "*";

		//general case in which input line will be centered in templine
		String tempLine = "*" + getSpaces(max_length - 1) + "*";

		String str = "";
		for (int i = 0; i < lines.size(); i++)
		{
			if(lines.get(i).length() == 0)
			{
				System.out.println(emptyLine);
				continue;
			}
			spaces = max_length - lines.get(i).length();

			if (spaces % 2 == 0)
			{
				int startingIndex = spaces / 2;
				int endIndex = startingIndex + lines.get(i).length();
				str = tempLine.substring(0, startingIndex + 1) + lines.get(i) + tempLine.substring(endIndex);
				System.out.println(str);
			}
			else
			{
				if (s % 2 != 0)
				{
					int startingIndex = spaces / 2;
					int endIndex = startingIndex + lines.get(i).length();
					str = tempLine.substring(0, startingIndex + 1) + lines.get(i) + tempLine.substring(endIndex);
					System.out.println(str);
					s++;
				}
				else
				{
					int startingIndex = spaces / 2 + 1;
					int endIndex = startingIndex + lines.get(i).length();
					str = tempLine.substring(0, startingIndex + 1) + lines.get(i) + tempLine.substring(endIndex);
					System.out.println(str);
					s++;
				}
			}
		}

		System.out.println(border);
	}

	private static String getBorders(int length)
	{
		String str = "";
		for (int i = 0; i < length; i++)
		{
			str = str + "*";
		}

		return str;
	}

	private static String getSpaces(int max_length)
	{
		String str = "";
		for(int m = 0; m < max_length; m++)
		{
			str = str + " ";
		}
		return str;
	}

}


import java.io.*;
import java.util.*;
public class Main{
  public static void main(String[] args) throws IOException{
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      StringBuilder output = new StringBuilder();
      List<String> lines = new ArrayList<String>();
      String line = in.readLine();
      int max = 0;
      while(line!=null)
      {
        lines.add(line);
        if(line.length()>max)
        {
          max = line.length();
        }
        if(in.ready())
        {
          line = in.readLine();
        }
        else
        {
          line=null;
        }

      }
      for (int j = 0; j < max + 2; j += 1){
        output.append('*');
      }
      output.append('\n');

      for(String l: lines){
        int len = l.length();
        int left = (max - len) / 2;
        int right = max - left - len;
        output.append('*');
        for (int s = 0; s < left; s += 1){
          output.append(' ');
        }
        output.append(l);
        for (int s = 0; s < right; s += 1){
          output.append(' ');
        }
        output.append('*');
        output.append('\n');
      }

      for (int j = 0; j < max + 2; j += 1){
        output.append('*');
      }
	  System.out.println(output.toString());
  }
}


import java.io.*;
import java.util.*;
public class Main{
  public static void main(String[] args) throws IOException{
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      StringBuilder output = new StringBuilder();
      List<String> lines = new ArrayList<String>();
      String line = in.readLine();
      int max = 0;
      while(line!=null)
      {
        lines.add(line);
        if(line.length()>max)
        {
          max = line.length();
        }
        if(in.ready())
        {
          line = in.readLine();
        }
        else
        {
          line=null;
        }

      }
      for (int j = 0; j < max + 2; j += 1){
        output.append('*');
      }
      output.append('\n');

      for(String l: lines){
        int len = l.length();
        int left = (max - len) / 2;
        int right = max - left - len;
        output.append('*');
        for (int s = 0; s < left; s += 1){
          output.append(' ');
        }
        output.append(l);
        for (int s = 0; s < right; s += 1){
          output.append(' ');
        }
        output.append('*');
        output.append('\n');
      }

      for (int j = 0; j < max + 2; j += 1){
        output.append('*');
      }
      output.append('\n');
		  System.out.println(output.toString());
  }
}


import java.io.*;
import java.util.*;
public class Main{
  public static void main(String[] args) throws IOException{
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      StringBuilder output = new StringBuilder();
      List<String> lines = new ArrayList<String>();
      String line = in.readLine();
      int rot = 0;
      int max = 0;
      while(line!=null)
      {
        lines.add(line);
        if(line.length()>max)
        {
          max = line.length();
        }
        if(in.ready())
        {
          line = in.readLine();
        }
        else
        {
          line=null;
        }

      }
      for (int j = 0; j < max + 2; j += 1){
        output.append('*');
      }
      output.append('\n');

      for(String l: lines){
        int len = l.length();
        int left = (max - len) / 2;
        int right = max - left - len;
        if (left != right){
          if (rot % 2 == 1){
            left += 1;
            right -= 1;
          }
          rot += 1;
        }
        output.append('*');
        for (int s = 0; s < left; s += 1){
          output.append(' ');
        }
        output.append(l);
        for (int s = 0; s < right; s += 1){
          output.append(' ');
        }
        output.append('*');
        output.append('\n');
      }

      for (int j = 0; j < max + 2; j += 1){
        output.append('*');
      }
		  System.out.println(output.toString());
  }
}


//package primaryTest;

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

public class B5
{
	private static void printStar(int num)
	{
		for(int i = 0; i < num; i++)
		{
			System.out.print("*");
		}
		System.out.println();
	}

	private static void printSpace(StringBuilder output,int num)
	{
		for(int i = 0 ; i < num; i++)
		{
			output.append(" ");
		}
	}

	private void run(BufferedReader in) throws IOException
	{
		ArrayList<String> lines = new ArrayList<String>();

		String start = in.readLine();
		int max = start.length();
		StringBuilder output ;
		while(start != null)
		{
			lines.add(start);
			if(start.length() > max) max = start.length();

			start = in.readLine();//如果已到达流末尾,则返回null
		}
		boolean left = true;
		printStar(max+2);
		for(String line:lines)
		{
			output = new StringBuilder();
			output.append("*");
			int diff = max - line.length();
			if(diff % 2 == 0)
			{
				printSpace(output,diff>>1);
				output.append(line);
				printSpace(output,diff>>1);
				output.append("*");
			}
			else
			{
				if(left == true)
				{
					printSpace(output,(diff-1)>>1);
					output.append(line);
					printSpace(output,diff-((diff-1)>>1));
					output.append("*");
					left = false;
				}
				else
				{
					printSpace(output,(diff+1)>>1);
					output.append(line);
					printSpace(output,diff-((diff+1)>>1));
					output.append("*");
					left = true;
				}
			}
			System.out.println(output.toString());
		}

		printStar(max+2);

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

		B5 solution = new B5();

		solution.run(in);
		in.close();
	}
}


package primaryTest;

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

public class B5
{
	private static void printStar(int num)
	{
		for(int i = 0; i < num; i++)
		{
			System.out.print("*");
		}
		System.out.println();
	}

	private void run(BufferedReader in) throws IOException
	{
		ArrayList<String> lines = new ArrayList<String>();

		String start = in.readLine();
		int max = start.length();
		StringBuilder output ;
		while(start != null)
		{
			lines.add(start);
			if(start.length() > max) max = start.length();

			start = in.readLine();//如果已到达流末尾,则返回null
		}

		printStar(max+2);
		for(String line:lines)
		{
			output = new StringBuilder();
			output.append("*");
			int diff = max - line.length();
			if(diff % 2 == 0)
			{
				for(int i = 0 ; i < diff>>1; i++)
				{
					output.append(" ");
				}
				output.append(line);
				for(int i = 0; i < diff>>1; i++)
				{
					output.append(" ");
				}
				output.append("*");
			}
			else
			{
				for(int i = 0; i< (diff-1)>>1;i++)
				{
					output.append(" ");
				}
				output.append(line);
				for(int i = 0; i < diff - ((diff-1)>>1);i++)
				{
					output.append(" ");
				}
				output.append("*");
			}
			System.out.println(output.toString());
		}

		printStar(max+2);

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

		B5 solution = new B5();

		solution.run(in);
		in.close();
	}
}


//package primaryTest;

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

public class B5
{
	private static void printStar(int num)
	{
		for(int i = 0; i < num; i++)
		{
			System.out.print("*");
		}
		System.out.println();
	}

	private void run(BufferedReader in) throws IOException
	{
		ArrayList<String> lines = new ArrayList<String>();

		String start = in.readLine();
		int max = start.length();
		StringBuilder output ;
		while(start != null)
		{
			lines.add(start);
			if(start.length() > max) max = start.length();

			start = in.readLine();//如果已到达流末尾,则返回null
		}

		printStar(max+2);
		for(String line:lines)
		{
			output = new StringBuilder();
			output.append("*");
			int diff = max - line.length();
			if(diff % 2 == 0)
			{
				for(int i = 0 ; i < diff>>1; i++)
				{
					output.append(" ");
				}
				output.append(line);
				for(int i = 0; i <diff>>1; i++)
				{
					output.append(" ");
				}
				output.append("*");
			}
			else
			{
				for(int i = 0; i< (diff+1)>>1;i++)
				{
					output.append(" ");
				}
				output.append(line);
				for(int i = 0; i < diff - ((diff+1)>>1);i++)
				{
					output.append(" ");
				}
				output.append("*");
			}
			System.out.println(output.toString());
		}

		printStar(max+2);

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

		B5 solution = new B5();

		solution.run(in);
		in.close();
	}
}


import java.io.BufferedReader;
import java.io.IOError;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    /*static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    public static String readString(){
        try {
            return reader.readLine().trim();
        } catch (IOException exception){
            throw new IOError(exception);
        }
    }
    public static int readInt(){
        return Integer.parseInt(readString());
    }
    public static int[] readInts(){
        String[] parts = readString().split("\\s+");
        int[] integers = new int[parts.length];
        for (int i = 0; i<integers.length; i++){
            integers[i] = Integer.parseInt(parts[i]);
        }
        return integers;
    }
    public static double readDouble(){
        return Double.parseDouble(readString());
    }
    public static double[] readDoubles(){
        String[] parts = readString().split(" ");
        double[] integers = new double[parts.length];
        for (int i = 0; i<integers.length; i++){
            integers[i] = Double.parseDouble(parts[i]);
        }
        return integers;
    }
    */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<String> strings = new ArrayList<String>();
        while (sc.hasNextLine()){
            strings.add(sc.nextLine());
        }
        int maxLength = 0;
        for (String s: strings){
            maxLength = Math.max(s.length(), maxLength);
        }
        StringBuilder builder = new StringBuilder();
        builder.append(characterString(maxLength+2, '*')).append("\n");
        boolean alignRight = false;
        for (String s: strings){
            builder.append("*");
            int padding = maxLength-s.length();
            int leftPadding = padding/2;
            int rightPadding = padding-leftPadding;
            if (alignRight){
                int a = leftPadding;
                leftPadding = rightPadding;
                rightPadding = a;
            }
            alignRight = !alignRight;
            builder.append(characterString(leftPadding, ' '))
                    .append(s)
                    .append(characterString(rightPadding, ' '))
                    .append("*\n");
        }
        builder.append(characterString(maxLength+2, '*'));
        System.out.println(builder.toString());
    }
    public static String characterString(int n, char character){
        char[] arr = new char[n];
        Arrays.fill(arr, character);
        return new String(arr);
    }

}


import java.io.BufferedReader;
import java.io.IOError;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    /*static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    public static String readString(){
        try {
            return reader.readLine().trim();
        } catch (IOException exception){
            throw new IOError(exception);
        }
    }
    public static int readInt(){
        return Integer.parseInt(readString());
    }
    public static int[] readInts(){
        String[] parts = readString().split("\\s+");
        int[] integers = new int[parts.length];
        for (int i = 0; i<integers.length; i++){
            integers[i] = Integer.parseInt(parts[i]);
        }
        return integers;
    }
    public static double readDouble(){
        return Double.parseDouble(readString());
    }
    public static double[] readDoubles(){
        String[] parts = readString().split(" ");
        double[] integers = new double[parts.length];
        for (int i = 0; i<integers.length; i++){
            integers[i] = Double.parseDouble(parts[i]);
        }
        return integers;
    }
    */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<String> strings = new ArrayList<String>();
        while (sc.hasNextLine()){
            strings.add(sc.nextLine());
        }
        int maxLength = 0;
        for (String s: strings){
            maxLength = Math.max(s.length(), maxLength);
        }
        StringBuilder builder = new StringBuilder();
        builder.append(characterString(maxLength+2, '*')).append("\n");
        for (String s: strings){
            builder.append("*");
            int padding = maxLength-s.length();
            int leftPadding = padding/2;
            int rightPadding = padding-leftPadding;
            builder.append(characterString(leftPadding, ' '))
                    .append(s)
                    .append(characterString(rightPadding, ' '))
                    .append("*\n");
        }
        builder.append(characterString(maxLength+2, '*'));
        System.out.println(builder.toString());
    }
    public static String characterString(int n, char character){
        char[] arr = new char[n];
        Arrays.fill(arr, character);
        return new String(arr);
    }

}


import java.io.BufferedReader;
import java.io.IOError;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    /*static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    public static String readString(){
        try {
            return reader.readLine().trim();
        } catch (IOException exception){
            throw new IOError(exception);
        }
    }
    public static int readInt(){
        return Integer.parseInt(readString());
    }
    public static int[] readInts(){
        String[] parts = readString().split("\\s+");
        int[] integers = new int[parts.length];
        for (int i = 0; i<integers.length; i++){
            integers[i] = Integer.parseInt(parts[i]);
        }
        return integers;
    }
    public static double readDouble(){
        return Double.parseDouble(readString());
    }
    public static double[] readDoubles(){
        String[] parts = readString().split(" ");
        double[] integers = new double[parts.length];
        for (int i = 0; i<integers.length; i++){
            integers[i] = Double.parseDouble(parts[i]);
        }
        return integers;
    }
    */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<String> strings = new ArrayList<String>();
        while (sc.hasNextLine()){
            strings.add(sc.nextLine());
        }
        int maxLength = 0;
        for (String s: strings){
            maxLength = Math.max(s.length(), maxLength);
        }
        StringBuilder builder = new StringBuilder();
        builder.append(characterString(maxLength+2, '*')).append("\n");
        boolean alignRight = false;
        for (String s: strings){
            builder.append("*");
            int padding = maxLength-s.length();
            int leftPadding = padding/2;
            int rightPadding = padding-leftPadding;
            if (leftPadding != rightPadding) {
                if (alignRight) {
                    int a = leftPadding;
                    leftPadding = rightPadding;
                    rightPadding = a;
                }
                alignRight = !alignRight;
            }
            builder.append(characterString(leftPadding, ' '))
                    .append(s)
                    .append(characterString(rightPadding, ' '))
                    .append("*\n");
        }
        builder.append(characterString(maxLength+2, '*'));
        System.out.println(builder.toString());
    }
    public static String characterString(int n, char character){
        char[] arr = new char[n];
        Arrays.fill(arr, character);
        return new String(arr);
    }

}


import java.util.*;

/**
 * @author vstepanov on 3/29/2017.
 */
public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            List<String> str = new ArrayList<>();
            int max = 0;
            while (in.hasNextLine()) {
                String line = in.nextLine();
                max = Math.max(line.length(), max);
                str.add(line);
            }

            char[] th = new char[max+2];
            Arrays.fill(th, '*');
            System.out.println(String.valueOf(th));
            boolean aleft = true;
            for (String st : str) {
                System.out.print("*");
                int side = max - st.length();
                int left = side/2;
                if (side % 2 != 0) {
                    if (!aleft) {
                        left++;
                    }
                    aleft = !aleft;
                }
                int i = 0;
                for (; i < left; i++) {
                    System.out.print(" ");
                }
                System.out.print(st);
                for (; i < side; i++) {
                    System.out.print(" ");
                }
                System.out.println("*");
            }
            System.out.println(String.valueOf(th));
        }
    }
}


import java.util.*;

/**
 * @author vstepanov on 3/29/2017.
 */
public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            List<String> str = new ArrayList<>();
            int max = 0;
            while (in.hasNextLine()) {
                String line = in.nextLine();
                max = Math.max(line.length(), max);
                str.add(line);
            }

            char[] th = new char[max+2];
            Arrays.fill(th, '*');
            String ths = new String(th);
            System.out.println(ths);
            boolean aleft = true;
            for (String st : str) {
                StringBuilder sb = new StringBuilder();
                sb.append("*");
                int side = max - st.length();
                int left = side/2;
                if (side % 2 != 0) {
                    if (!aleft) {
                        left++;
                    }
                    aleft = !aleft;
                }
                int i = 0;
                for (; i < left; i++) {
                    sb.append(" ");
                }
                sb.append(st);
                for (; i < side; i++) {
                    sb.append(" ");
                }
                sb.append("*");
                System.out.println(sb);
            }
            System.out.println(ths);
        }
    }
}


import java.util.*;

/**
 * @author vstepanov on 3/29/2017.
 */
public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            List<String> str = new ArrayList<>();
            int max = 0;
            while (in.hasNextLine()) {
                String line = in.nextLine();
                max = Math.max(line.length(), max);
                str.add(line);
            }

            char[] th = new char[max+2];
            Arrays.fill(th, '*');
            System.out.println(String.valueOf(th));
            boolean aleft = true;
            for (String st : str) {
                System.out.print("*");
                int side = max - st.length();
                int left = side/2;
                if (side % 2 != 0) {
                    if (!aleft) {
                        left++;
                    }
                    aleft = false;
                }
                int i = 0;
                for (; i < left; i++) {
                    System.out.print(" ");
                }
                System.out.print(st);
                for (; i < side; i++) {
                    System.out.print(" ");
                }
                System.out.println("*");
            }
            System.out.println(String.valueOf(th));
        }
    }
}


import java.util.*;

/**
 * @author vstepanov on 3/29/2017.
 */
public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            List<String> str = new ArrayList<>();
            int max = 0;
            while (in.hasNextLine()) {
                String line = in.nextLine();
                max = Math.max(line.length(), max);
                str.add(line);
            }

            char[] th = new char[max+2];
            Arrays.fill(th, '*');
            for (int i = 0; i < th.length; i++) {
                System.out.print(th[i]);
            }
            System.out.println();
            boolean aleft = true;
            for (String st : str) {
                System.out.print("*");
                int side = max - st.length();
                int left = side/2;
                if (side % 2 != 0) {
                    if (!aleft) {
                        left++;
                    }
                    aleft = !aleft;
                }
                int i = 0;
                for (; i < left; i++) {
                    System.out.print(" ");
                }
                System.out.print(st);
                for (; i < side; i++) {
                    System.out.print(" ");
                }
                System.out.println("*");
            }
            for (int i = 0; i < th.length; i++) {
                System.out.print(th[i]);
            }
            System.out.println();
        }
    }
}


import java.util.*;

/**
 * @author vstepanov on 3/29/2017.
 */
public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            List<String> str = new ArrayList<>();
            int max = 0;
            while (in.hasNextLine()) {
                String line = in.nextLine();
                max = Math.max(line.length(), max);
                str.add(line);
            }

            char[] th = new char[max+2];
            Arrays.fill(th, '*');
            System.out.println(String.valueOf(th));
            for (String st : str) {
                System.out.print("*");
                int side = max - st.length();
                int i = 0;
                for (; i < side/2; i++) {
                    System.out.print(" ");
                }
                System.out.print(st);
                for (; i < side; i++) {
                    System.out.print(" ");
                }
                System.out.println("*");
            }
            System.out.println(String.valueOf(th));
        }
    }
}


//highlight: bacalo mi je TLE kad sam ispisivao zvjezdice, razmake i stringove jedan po jedan, kad sam ih spremao u StringBuilder pa na kraju cijelog ispisao bilo je puuuno ispod time limita
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class CenterAlignment_5B {
	public static void main(String[] args) throws IOException {
		Scanner s = new Scanner(System.in);
		List<String> strings = new ArrayList<>();
		int maxLen = 0;
		StringBuilder out = new StringBuilder();
		String next;
		while (s.hasNext()) {
			next = s.nextLine();
			if (next.length() > maxLen) {
				maxLen = next.length();
			}
			strings.add(next);
		}
		int diff;
		int halfDiff;
		int x = 0;
		int i;
		for (i = 1; i <= maxLen + 2; i++) {
			out.append("*");
		}
		out.append("\n");
		for (String line : strings) {
			out.append("*");
			diff = maxLen - line.length();
			halfDiff = diff / 2;
			if (diff % 2 == 0) {
				for (i = 1; i <= halfDiff; i++) {
					out.append(" ");
				}
				out.append(line);
				for (i = 1; i <= halfDiff; i++) {
					out.append(" ");
				}
			} else {// diff odd
				if (x % 2 == 0) {
					for (i = 1; i <= halfDiff; i++) {
						out.append(" ");
					}
					out.append(line);
					for (i = 1; i <= halfDiff + 1; i++) {
						out.append(" ");
					}
				} else {
					for (i = 1; i <= halfDiff + 1; i++) {
						out.append(" ");
					}
					out.append(line);
					for (i = 1; i <= halfDiff; i++) {
						out.append(" ");
					}
				}
				x++;
			}
			out.append("*");
			out.append("\n");
		}
		for (i = 1; i <= maxLen + 2; i++) {
			out.append("*");
		}
		System.out.println(out);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class CenterAlignment_5B {
	public static void main(String[] args) throws IOException {
		BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
		List<String> strings = new ArrayList<>();
		int maxLen = 0;
		String next = s.readLine();
		while (next != null) {
			if (next.length() > maxLen) {
				maxLen = next.length();
			}
			strings.add(next);
			next = s.readLine();
		}
		int diff;
		int halfDiff;
		int x = 0;
		int i;
		for (i = 1; i <= maxLen + 2; i++) {
			System.out.print("*");
		}
		System.out.println();
		for (String line : strings) {
			System.out.print("*");
			diff = maxLen - line.length();
			halfDiff = diff / 2;
			if (diff % 2 == 0) {
				for (i = 1; i <= halfDiff; i++) {
					System.out.print(" ");
				}
				System.out.print(line);
				for (i = 1; i <= halfDiff; i++) {
					System.out.print(" ");
				}
			} else {// diff odd
				if (x % 2 == 0) {
					for (i = 1; i <= halfDiff; i++) {
						System.out.print(" ");
					}
					System.out.print(line);
					for (i = 1; i <= halfDiff + 1; i++) {
						System.out.print(" ");
					}
				} else {
					for (i = 1; i <= halfDiff + 1; i++) {
						System.out.print(" ");
					}
					System.out.print(line);
					for (i = 1; i <= halfDiff; i++) {
						System.out.print(" ");
					}
				}
				x++;
			}
			System.out.print("*");
			System.out.println();
		}
		for (i = 1; i <= maxLen + 2; i++) {
			System.out.print("*");
		}
	}
}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class CenterAlignment_5B {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		List<String> strings = new ArrayList<>();
		int maxLen = 0;
		String next;
		while (s.hasNextLine()) {
			next = s.nextLine();
			if (next.length() > maxLen) {
				maxLen = next.length();
			}
			strings.add(next);
		}
		int diff;
		int halfDiff;
		int x = 0;
		int i;
		for (i = 1; i <= maxLen + 2; i++) {
			System.out.print("*");
		}
		System.out.println();
		for (String line : strings) {
			System.out.print("*");
			diff = maxLen - line.length();
			halfDiff = diff / 2;
			if (diff % 2 == 0) {
				for (i = 1; i <= halfDiff; i++) {
					System.out.print(" ");
				}
				System.out.print(line);
				for (i = 1; i <= halfDiff; i++) {
					System.out.print(" ");
				}
			} else {// diff odd
				if (x % 2 == 0) {
					for (i = 1; i <= halfDiff; i++) {
						System.out.print(" ");
					}
					System.out.print(line);
					for (i = 1; i <= halfDiff + 1; i++) {
						System.out.print(" ");
					}
				} else {
					for (i = 1; i <= halfDiff + 1; i++) {
						System.out.print(" ");
					}
					System.out.print(line);
					for (i = 1; i <= halfDiff; i++) {
						System.out.print(" ");
					}
				}
				x++;
			}
			System.out.print("*");
			System.out.println();
		}
		for (i = 1; i <= maxLen + 2; i++) {
			System.out.print("*");
		}
	}
}


import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class CenterAlignment_5B {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		List<String> strings = new LinkedList<>();
		int maxLen = 0;
		String next;
		while (s.hasNextLine()) {
			next = s.nextLine();
			if (next.length() > maxLen) {
				maxLen = next.length();
			}
			strings.add(next);
		}
		int diff;
		int halfDiff;
		int x = 0;
		int i;
		for (i = 1; i <= maxLen + 2; i++) {
			System.out.print("*");
		}
		System.out.println();
		for (String line : strings) {
			System.out.print("*");
			diff = maxLen - line.length();
			halfDiff = diff / 2;
			if (diff % 2 == 0) {
				for (i = 1; i <= halfDiff; i++) {
					System.out.print(" ");
				}
				System.out.print(line);
				for (i = 1; i <= halfDiff; i++) {
					System.out.print(" ");
				}
			} else {// diff odd
				if (x % 2 == 0) {
					for (i = 1; i <= halfDiff; i++) {
						System.out.print(" ");
					}
					System.out.print(line);
					for (i = 1; i <= halfDiff + 1; i++) {
						System.out.print(" ");
					}
				} else {
					for (i = 1; i <= halfDiff + 1; i++) {
						System.out.print(" ");
					}
					System.out.print(line);
					for (i = 1; i <= halfDiff; i++) {
						System.out.print(" ");
					}
				}
				x++;
			}
			System.out.print("*");
			System.out.println();
		}
		for (i = 1; i <= maxLen + 2; i++) {
			System.out.print("*");
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class CenterAlignment_5B {
	public static void main(String[] args) throws IOException {
		BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
		List<String> strings = new ArrayList<>();
		int maxLen = 0;
		StringBuilder out = new StringBuilder();
		String next = s.readLine();
		while (next != null) {
			if (next.length() > maxLen) {
				maxLen = next.length();
			}
			strings.add(next);
			next = s.readLine();
		}
		int diff;
		int halfDiff;
		int x = 0;
		int i;
		for (i = 1; i <= maxLen + 2; i++) {
			out.append("*");
		}
		out.append("\n");
		for (String line : strings) {
			out.append("*");
			diff = maxLen - line.length();
			halfDiff = diff / 2;
			if (diff % 2 == 0) {
				for (i = 1; i <= halfDiff; i++) {
					out.append(" ");
				}
				out.append(line);
				for (i = 1; i <= halfDiff; i++) {
					out.append(" ");
				}
			} else {// diff odd
				if (x % 2 == 0) {
					for (i = 1; i <= halfDiff; i++) {
						out.append(" ");
					}
					out.append(line);
					for (i = 1; i <= halfDiff + 1; i++) {
						out.append(" ");
					}
				} else {
					for (i = 1; i <= halfDiff + 1; i++) {
						out.append(" ");
					}
					out.append(line);
					for (i = 1; i <= halfDiff; i++) {
						out.append(" ");
					}
				}
				x++;
			}
			out.append("*");
			out.append("\n");
		}
		for (i = 1; i <= maxLen + 2; i++) {
			out.append("*");
		}
		System.out.println(out);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class CenterAlignment_5B {
	public static void main(String[] args) throws IOException {
		BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
		List<String> strings = new ArrayList<>();
		int maxLen = 0;
		StringBuilder out = new StringBuilder();
		String next = s.readLine();
		while (next != null) {
			if (next.length() > maxLen) {
				maxLen = next.length();
			}
			strings.add(next);
			next = s.readLine();
		}
		int diff;
		int halfDiff;
		int x = 0;
		int i;
		for (i = 1; i <= maxLen + 2; i++) {
			out.append("*");
		}
		out.append("\n");
		for (String line : strings) {
			out.append("*");
			diff = maxLen - line.length();
			halfDiff = diff / 2;
			if (diff % 2 == 0) {
				for (i = 1; i <= halfDiff; i++) {
					out.append(" ");
				}
				out.append(line);
				for (i = 1; i <= halfDiff; i++) {
					out.append(" ");
				}
			} else {// diff odd
				if (x % 2 == 0) {
					for (i = 1; i <= halfDiff; i++) {
						out.append(" ");
					}
					out.append(line);
					for (i = 1; i <= halfDiff + 1; i++) {
						out.append(" ");
					}
				} else {
					for (i = 1; i <= halfDiff + 1; i++) {
						out.append(" ");
					}
					out.append(line);
					for (i = 1; i <= halfDiff; i++) {
						out.append(" ");
					}
				}
				x++;
			}
			out.append(" ");
			out.append("\n");
		}
		for (i = 1; i <= maxLen + 2; i++) {
			out.append("*");
		}
		System.out.println(out);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class CenterAlignment_5B {
	public static void main(String[] args) throws IOException {
		BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
		List<String> strings = new ArrayList<>();
		int maxLen = 0;
		StringBuilder out = new StringBuilder();
		String next = s.readLine();
		while (next != null) {
			if (next.length() > maxLen) {
				maxLen = next.length();
			}
			strings.add(next);
			next = s.readLine();
		}
		int diff;
		int halfDiff;
		int x = 0;
		int i;
		for (i = 1; i <= maxLen + 2; i++) {
			out.append("*");
		}
		out.append("\n");
		for (String line : strings) {
			out.append("*");
			diff = maxLen - line.length();
			halfDiff = diff / 2;
			if (diff % 2 == 0) {
				for (i = 1; i <= halfDiff; i++) {
					out.append(" ");
				}
				out.append(line);
				for (i = 1; i <= halfDiff; i++) {
					out.append(" ");
				}
			} else {// diff odd
				if (x % 2 == 0) {
					for (i = 1; i <= halfDiff; i++) {
						out.append(" ");
					}
					System.out.print(line);
					for (i = 1; i <= halfDiff + 1; i++) {
						out.append(" ");
					}
				} else {
					for (i = 1; i <= halfDiff + 1; i++) {
						out.append(" ");
					}
					out.append(line);
					for (i = 1; i <= halfDiff; i++) {
						out.append(" ");
					}
				}
				x++;
			}
			out.append(" ");
			out.append("\n");
		}
		for (i = 1; i <= maxLen + 2; i++) {
			out.append("*");
		}
		System.out.println(out);
	}
}


//baca mi TLE na 13 testu...
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class CenterAlignment_5B {
	public static void main(String[] args) throws IOException {
		BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
		List<String> strings = new ArrayList<>();
		int maxLen = 0;
		StringBuilder out = new StringBuilder();
		String next = s.readLine();
		while (next != null) {
			if (next.length() > maxLen) {
				maxLen = next.length();
			}
			strings.add(next);
			next = s.readLine();
		}
		int diff;
		int halfDiff;
		int x = 0;
		int i;
		for (i = 1; i <= maxLen + 2; i++) {
			out.append("*");
		}
		System.out.println();
		for (String line : strings) {
			out.append("*");
			diff = maxLen - line.length();
			halfDiff = diff / 2;
			if (diff % 2 == 0) {
				for (i = 1; i <= halfDiff; i++) {
					out.append(" ");
				}
				out.append(line);
				for (i = 1; i <= halfDiff; i++) {
					out.append(" ");
				}
			} else {// diff odd
				if (x % 2 == 0) {
					for (i = 1; i <= halfDiff; i++) {
						out.append(" ");
					}
					System.out.print(line);
					for (i = 1; i <= halfDiff + 1; i++) {
						out.append(" ");
					}
				} else {
					for (i = 1; i <= halfDiff + 1; i++) {
						out.append(" ");
					}
					out.append(line);
					for (i = 1; i <= halfDiff; i++) {
						out.append(" ");
					}
				}
				x++;
			}
			out.append(" ");
			out.append("\n");
		}
		for (i = 1; i <= maxLen + 2; i++) {
			out.append("*");
		}
		System.out.println(out);
	}
}


import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class CenterAlignment_5B {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		List<String> strings = new LinkedList<>();
		int maxLen = 0;
		String next;
		while (s.hasNextLine()) {
			next = s.nextLine();
			if (next.length() > maxLen) {
				maxLen = next.length();
			}
			strings.add(next);
		}
		int diff;
		int x = 0;
		for (int i = 1; i <= maxLen + 2; i++) {
			System.out.print("*");
		}
		System.out.println();
		for (String line : strings) {
			System.out.print("*");
			diff = maxLen - line.length();
			if (diff % 2 == 0) {
				for (int j = 1; j <= diff / 2; j++) {
					System.out.print(" ");
				}
				System.out.print(line);
				for (int j = 1; j <= diff / 2; j++) {
					System.out.print(" ");
				}
			} else {// diff odd
				if (x % 2 == 0) {
					for (int j = 1; j <= (diff / 2); j++) {
						System.out.print(" ");
					}
					System.out.print(line);
					for (int j = 1; j <= (diff / 2) + 1; j++) {
						System.out.print(" ");
					}
				} else {
					for (int j = 1; j <= (diff / 2) + 1; j++) {
						System.out.print(" ");
					}
					System.out.print(line);
					for (int j = 1; j <= (diff / 2); j++) {
						System.out.print(" ");
					}
				}
				x++;
			}
			System.out.print("*");
			System.out.println();
		}
		for (int i = 1; i <= maxLen + 2; i++) {
			System.out.print("*");
		}
	}
}