var strelci_tabulka, strelci: array[1..1000] of string;
    golov_tabulka, golov: array[1..1000] of integer;
    vypisany: array[1..1000] of boolean;
    strelec: string;
    i, j, aktualne_miesto, golov_minule, top_index, pocet_tabulka, pocet_strelcov, miest_tabulka: integer;
    nasiel: boolean;
    sirky: array[1..3] of integer;

procedure ciara();
var i: integer;
begin
  write('+');
  for i:=1 to sirky[1] do write('-');
  write('+');
  for i:=1 to sirky[2] do write('-');
  write('+');
  for i:=1 to sirky[3] do write('-');
  writeln('+');
end;

begin
  {nacitame vstup}
  pocet_strelcov := 0;
  while (not EOF) do
  begin
    readln(strelec);
    nasiel := false;
    for i:=1 to pocet_strelcov do if (strelci[i] = strelec) then
    begin
      inc(golov[i]);
      nasiel := true;
      break;
    end;
    if (nasiel = false) then
    begin
      inc(pocet_strelcov);
      strelci[pocet_strelcov] := strelec;
      golov[pocet_strelcov] := 1;
    end;
  end;
  for i:=1 to pocet_strelcov do vypisany[i] := false;

  {zistime, kto vsetko ma byt vypisany}
  golov_minule := 1000;
  miest_tabulka := 0;
  pocet_tabulka := 0;
  for i:=1 to pocet_strelcov do
  begin
    top_index := -1;
    for j:=1 to pocet_strelcov do if (vypisany[j] = false) then
    begin
      if (top_index < 0) then top_index := j
      else if (golov[j] > golov[top_index]) or ((golov[j] = golov[top_index]) and (strelci[j] < strelci[top_index])) then top_index := j;
    end;
    if (golov[top_index] < golov_minule) then inc(miest_tabulka);
    if (miest_tabulka > 10) then break;
    inc(pocet_tabulka);
    strelci_tabulka[pocet_tabulka] := strelci[top_index];
    golov_tabulka[pocet_tabulka] := golov[top_index];
    vypisany[top_index] := true;
    golov_minule := golov[top_index];
  end;

  {poratame si, ake siroke maju byt stlpce}
  sirky[2] := 0;
  for i:=1 to pocet_tabulka do if (length(strelci_tabulka[i]) > sirky[2]) then sirky[2] := length(strelci_tabulka[i]);
  sirky[2] := sirky[2] + 2;
  sirky[3] := 3;
  if (golov_tabulka[1] > 10) then inc(sirky[3]);
  if (golov_tabulka[1] > 100) then inc(sirky[3]);
  sirky[1] := 4;
  if (miest_tabulka > 9) then inc(sirky[1]);

  {samotny vypis}
  golov_minule := 1000;
  aktualne_miesto := 0;
  for i:=1 to pocet_tabulka do
  begin
    if (golov_tabulka[i] < golov_minule) then ciara();
    {stlpec s poradim}
    write('| ');
    if (golov_tabulka[i] < golov_minule) then
    begin
      inc(aktualne_miesto);
      write(aktualne_miesto);
      write('. ');
      if (miest_tabulka > 9) and (aktualne_miesto < 10) then write(' ');
    end else
    begin
      write('   ');
      if (miest_tabulka > 9) then write(' ');
    end;
    {stlpec s menom}
    write('| ', strelci_tabulka[i]);
    for j:=1 to sirky[2] - length(strelci_tabulka[i]) - 1 do write(' ');
    {stlpec s poctom golov}
    write('| ');
    if (golov_tabulka[i] < golov_minule) then
    begin
      write(golov_tabulka[i]);
      if (golov_tabulka[i] < 10) and (golov_tabulka[1] >= 10) then write(' ');
      if (golov_tabulka[i] < 100) and (golov_tabulka[1] >= 100) then write(' ');
    end
    else begin
      write(' ');
      if (golov_tabulka[1] >= 10) then write(' ');
      if (golov_tabulka[1] >= 100) then write(' ');
    end;
    writeln(' |'); 
    golov_minule := golov_tabulka[i];
  end;
  ciara();
end.
