#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define TRUE (0==0)
#define FALSE (0!=0)

#define WIDTH 160

static int widths[WIDTH];
static int debug = FALSE;

void print_table(char **lines, int max, int cols, int *widths)
{
  int k, i, c, r, rows, idx;
  char *s;

  if (debug) fprintf(stderr, "max: %d\n", max);
  rows = (max+cols-1)/cols;
  if (debug) fprintf(stderr, "display: %d cols with %d rows\n", cols, rows);
  k = 0;
  for (r = 0; r < rows; r++) {
    for (c = 0; c < cols; c++) {
      idx = (r+(c*rows));
      if (idx >= max) {
        continue;
      }
      fprintf(stdout, "%s", s = lines[idx]);
      i = strlen(s);
      i = widths[c]-i-1;
      while (i > 0) {
        fprintf(stdout, " ");
        i -= 1;
      }
      if (c+1 < cols) {
        fprintf(stdout, " ");
      }
    }
    if (c != 0) fprintf(stdout, "\n");
  }
}

#define biggest(a, b) ((a) > (b) ? (a) : (b))

int cando(char **lines, int max, int cols, int *widths)
{
  int w, r, c, k = 0, rows;
  rows = (max+cols-1)/cols;
  if (debug) fprintf(stderr, "%d cols with %d rows\n", cols, rows);
  for (c = 0; c < cols; c++) {
    widths[c] = 0;
  }
  if (debug) fprintf(stderr, "cols: %d\n", cols);
  for (r = 0; r < rows; r++) {
    for (c = 0; c < cols; c++) {
      k = r+c*rows;
      if (debug) fprintf(stderr, "k [%d] = row %d + (col %d * %d)  '%s'\n", k, r, c, rows, (k >= max ? "BLANK" : lines[k]));
      if (k >= max) {
        continue;
      }
      widths[c] = biggest(widths[c], strlen(lines[k]));
    }
  }
  if (debug) fprintf(stderr, "cols: %d\n", cols);
  for (c = 0; c < cols; c++) {
    if (debug) fprintf(stderr, "widths[%d] = %d\n", c, widths[c]);
  }
  if (debug) fprintf(stderr, "p3\n");
  for (c = 0; c < cols-1; c++) {
    widths[c] += 1;
  }
  for (c = 0; c < cols; c++) {
    if (debug) fprintf(stderr, "adjusted widths[%d] = %d\n", c, widths[c]);
  }
  w = 0;
  if (debug) fprintf(stderr, "p4\n");
  for (c = 0; c < cols; c++) {
    w = w + widths[c];
  }
  if (debug) fprintf(stderr, "width will be %d\n", w);
  if (w >= WIDTH) return(FALSE);
  return(TRUE);
}

int main(int argc, char **argv)
{
  char line[1024];
  char *lines[1024];
  int i;
  int cols, minwidth = WIDTH;
  char *s;
  i = 0;
  for (;;) {
    s = fgets(line, 1023, stdin);
    if (s == NULL) break;
    s = strchr(line, '\n');
    if (s != NULL) *s = '\0';
    s = malloc((minwidth = strlen(line))+1);
    strcpy(s, line);
    lines[i] = s;
    i += 1;
  }
  if (debug) fprintf(stderr, "Narrowest line is %d chars\n", minwidth);
  minwidth += 1;
  cols = WIDTH / minwidth;
  if (debug) fprintf(stderr, "At best we can do %d columns\n", cols);
  if (cols == 0) exit(0);
  for (;;) {
    if (debug) fprintf(stderr, "Test layout at %d cols\n", cols);
    if (cando(lines, i, cols, widths)) break;
    cols -= 1;
    if (cols <= 1) break;
  }
  if (cols <= 1) cols = 1;
  print_table(lines, i, cols, widths);
  exit(0);  
}
