{$APPTYPE CONSOLE}

program zzz;

type
  plist = ^tlist;
  tlist = record
    v: Longint;
    next: plist;
  end;

  pnode = ^tnode;
  tnode = record
    cc: plist;
    next: array['A'..'Z'] of Pnode;
  end;

var
  first: pnode;
  zero1: pnode;
  zero2: plist;
  stt: array[1..100000] of char;
  sz,txt,abz: array[1..20000] of Longint;
  a: array[1..20000] of string;
  pos1,pos2,dx,ccur,nabz,cur,cl,sc,i,j,k,n,m: Longint;
  ss: string;

function extword(var s: string): Boolean;
begin
  while pos1 <= length(a[pos2]) do begin
    if a[pos2][pos1] in ['A'..'Z'] then break;
    inc(pos1);
  end;
  if pos1 > length(a[pos2]) then begin
    extword := false;
    exit;
  end;
  extword := true;
  s := '';
  while (a[pos2][pos1] in ['A'..'Z']) do begin
    s := s + a[pos2][pos1];
    inc(pos1);
    if pos1 > length(a[pos2]) then break;
  end;
end;

procedure createnode(var a: pnode);
var c: char;
begin
  new(a);
  for c := 'A' to 'Z' do begin
    a^.next[c] := zero1;
  end;
  a^.cc := zero2;
end;

procedure addword(st: string; nt: Longint);
var i: Longint;
    bb,cur: pnode;
    buf: plist;

begin
  cur := first;
  for i := 1 to length(st) do begin
    if cur^.next[st[i]] = zero1 then begin
      createnode(bb);
      cur^.next[st[i]] := bb;
    end;
    cur := cur^.next[st[i]];
  end;
  if cur^.cc = zero2 then begin
    new(buf);
    buf^.next := cur^.cc;
    cur^.cc := buf;
    buf^.v := nt;
  end else begin
    if cur^.cc^.v <> nt then begin
      new(buf);
      buf^.next := cur^.cc;
      cur^.cc := buf;
      buf^.v := nt;
    end;
  end;
end;

procedure print(cur: pnode; dep: Longint);
var i,st,fin: Longint;
    fl: Boolean;
    buf: plist;
    c: char;
begin
  fl := false;
  if cur = zero1 then exit;
  if cur^.cc <> zero2 then begin
    for i := 1 to dep do write(stt[i]);
    write(' ');
    buf := cur^.cc;
    st := buf^.v;
    fin := buf^.v;
    while buf <> zero2 do begin
      if buf^.v - fin > 1 then begin
        if fl then write(',');
        if fin - st > 1 then write(st,'-',fin) else begin
          if st <> fin then write(st,',',fin) else write(st);
          st := buf^.v;
          fin := buf^.v;
        end;
        fl := true;
      end else fin := buf^.v;
      buf := buf^.next;
    end;
    if st <> -1 then begin
      if fl then write(',');
      if fin - st > 1 then write(st,'-',fin) else begin
        if st <> fin then write(st,',',fin) else write(st);
      end;
    end;
    writeln;
  end;

  for c := 'A' to 'Z' do begin
    stt[dep+1] := c;
    print(cur^.next[c],dep+1);
  end;
end;

begin
  new(zero1);
  new(zero2);
  createnode(first);
  assign(input,'document.in'); reset(input);
  assign(output,'document.out'); rewrite(output);
  readln(n);
  sc := 0;
  cur := 1;
  while not eof(Input) do begin
    inc(sc);
    readln(a[sc]);
    if a[sc] = '' then begin
      inc(cur);
      dec(sc);
    end else begin
      abz[sc] := cur;
      for j := 1 to length(a[sc]) do begin
        a[sc][j] := upcase(a[sc][j]);
      end;
      inc(sz[abz[sc]]);
    end;
  end;

  nabz := cur;
  cur := 1;
  cl := 0;
  ccur := 1;
  i := 1;
  while nabz >= i do begin
    if cl = 0 then begin
      dx := 0;
    end else dx := 1;
    if n - cl - dx <= 1 then begin
      cl := 0;
      inc(cur);
      continue;
    end;

    if cl + dx + sz[i] <= n then begin
      cl := cl + dx + sz[i];
      for j := ccur to ccur + sz[i]-1 do begin
        txt[j] := cur;
      end;
      ccur := ccur + sz[i];
      inc(i);
    end else begin
      if n - (cl + dx + sz[i]) > 1 then begin
        for j := ccur to ccur + n - cl - dx do begin
          txt[j] := cur;
        end;
        cl := 0;
        inc(cur);
        continue;
      end else begin
        cl := 0;
        inc(cur);
        continue;
      end;
    end;
  end;

  for i := sc downto 1 do begin
    pos1 := 1;
    pos2 := i;
    while extword(ss) do begin
      addword(ss,txt[i]);
    end;
  end;

  print(first,0);
  close(input);
  close(output);
end.