program uzrasas_spirale;

   const MAX = 25; { maksimali sta‡iakampio,  kur telpa spiral‚, kražtin‚ }
   type lentele = array [1..MAX, 1..MAX] of char;
        kryptis = (zemyn, desinen, aukstyn, kairen);

  procedure rasyti (sk: integer; kr: kryptis; e: string;
                    var eil, st: integer;
                    var lent: lentele);
  { ražo  spiralŠ 'sk' simboli— nurodyta kryptimi
    pradedant langeliu [eil, st] }
    var i: integer;
  begin
    if sk > length (e)
       then sk := length (e);
    for i := 1 to sk do
      begin
        lent[eil, st] := e[i];
        case kr of
          zemyn:   eil := eil + 1;
          aukstyn: eil := eil - 1;
          kairen:  st  := st - 1;
          desinen: st  := st + 1;
        end;
      end;
  end; { ražyti }

  procedure tarpai_pliusai (var e: string);
  { tarpus eilut‚je pakei‡ia simboliais '+' }
    var vieta: integer;
  begin
    while pos (' ', e) > 0 do
    { kol sakinyje likŠs nors vienas tarpas }
      begin
        vieta := pos (' ', e);
        e := copy (e, 1, vieta-1) +
             '+' +
             copy (e, vieta+1, length(e)-vieta)
      end;
  end; { tarpai_pliusai }

  function succ_kr (kr: kryptis): kryptis;
  begin
    if kr = kairen
       then succ_kr := zemyn
       else succ_kr := succ (kr);
  end; { succ_kr }

  function tuscia (lent: lentele; nr: integer;
                   eilute: boolean): boolean;
  { patikrina, ar nurodyta lentel‚s eilut‚ (stulpelis) yra
    sudaryta vien iž tarp— }
    var tarpai: boolean;
        i: integer;
  begin
    tarpai := true;
    for i := 1 to MAX do
      if eilute
         then tarpai := tarpai and (lent[nr, i] = ' ')
         else tarpai := tarpai and (lent[i, nr] = ' ');
    tuscia := tarpai
  end; { tuž‡ia }

  procedure stumti (var lent: lentele;
                    var eil_sk, st_sk: integer { eilu‡i— bei stulpeli—
                        skai‡ius spiral‚je});
  { spiralŠ pastumia  lentel‚s prad‘i… }
    var i, j, te, ts: integer;
  begin
    { randame tuž‡i— eilu‡i— skai‡i— lentel‚s prad‘ioje }
    te := 0;
    while tuscia (lent, te+1, true) do
      te := te + 1;
    { randame eilu‡i— skai‡i— spiral‚je }
    eil_sk := 0;
    while not tuscia (lent, eil_sk+te+1, true) do
      eil_sk := eil_sk + 1;
    { randame tuž‡i— stulpeli— skai‡i— lentel‚s prad‘ioje }
    ts := 0;
    while tuscia (lent, ts+1, false) do
      ts := ts + 1;
    { randame stulepli— skai‡i— spiral‚je }
    st_sk := 0;
    while not tuscia (lent, st_sk+ts+1, false) do
      st_sk := st_sk + 1;
    { perkeliame spiralŠ  lentel‚s prad‘i… }
    for i := 1 to eil_sk do
      for j := 1 to st_sk do
        lent[i, j] := lent[i+te, j+ts]
  end; { stumti }

  procedure uzrasyti_spirale (e: string; { duotasis sakinys }
                              var lent: lentele;
                              var eil_sk, st_sk: integer
                                  { eilu‡i— bei stulpeli— skai‡ius
                                    spiral‚je });
    var kiek, simb, i, j, eil, st: integer;
        kr: kryptis;
  begin
    { sakinyje tarpus kei‡iame simboliais '+' }
    tarpai_pliusai (e);
    { lentelŠ u‘pildome tarpais }
    for i := 1 to MAX do
      for j := 1 to MAX do
        lent[i, j] := ' ';
    { parenkame pradin langel }
    eil := MAX div 2; st := MAX div 2;
    simb := length (e); { simboli— kiekis sakinyje }
    kiek := 1;          { simboli— skai‡ius spiral‚s kražtin‚je }
    kr := zemyn;        { pradin‚ kryptis }
    while simb > 0 do
    { kol neu‘raž‚me viso sakinio }
      begin
        rasyti (kiek, kr, e, eil, st, lent);
        delete (e, 1, kiek); { pažalinama ražytoji sakinio dalis }
        simb := simb - kiek; { sutrump‚ja sakinio ilgis }
        kr := succ_kr (kr);
        kiek := kiek + 1
      end;
    { pastumsime spiralŠ  prad‘i… }
    stumti (lent, eil_sk, st_sk);
  end; { u‘ražyti spirale }

  var e: string;
      lent: lentele;
      i, j, eil_sk, st_sk: integer;
begin
  readln (e);
  uzrasyti_spirale (e, lent, eil_sk, st_sk);
  for i := 1 to eil_sk do
    begin
      for j := 1 to st_sk do
        write (lent[i, j]);
      writeln;
    end;
end.