Type
 TElem = string;
 TList = ^TNode;
 TNode = record
	 Info: TElem;
	 Next: TList
	 end;
procedure BListPrint(L: TList );
begin
 write('[ ');
 while L <> nil DO
 begin
  write( L^.Info );
  If L^.Next <> nil then write(' | ');
  L := L^.Next
 end;
 writeln(' ]')
end;
procedure ListClear ( var L: TList );
var
 N: TList;
begin
 while L <> nil do
 begin
  N :=L;
  L:=L^.Next;
  dispose(N)
 end
end;


function SepWord(s,Alf:string):tlist;
         procedure  AddLast(var L: TList; E: TElem);
         var
           N, P: TList;
         Begin
           new(N);
           N^.Info :=E; N^.Next :=nil;
           if L= nil then L:=N else  begin
             P:=L;
             while P^.Next <> nil do P:=P^.Next;
             P^.Next:=N
           end
         End;
const
 i:integer=1;
 r:set of char = [chr(0)..chr(255)]-['A'..'Z','a'..'z','1'..'9','0'];
var
 SL:boolean; L: TList;   ss:string;f:file of byte;b:byte;
begin
 if Alf<>'' then begin
  if (alf[1]<>'#') and (alf[1]<>'$') then begin
   assign(f,alf); {$I-} reset(f); {$I+}
   if IOresult=0 then begin
    while not eof(f) do begin
     read(f,b);
     include(r,chr(b));
    end;
    r:= [chr(0)..chr(255)]-r;
    close(f)
   end
  end else begin
   r:=[];
   if alf[1]='#' then  for i:=2 to length(alf) do include(r,alf[i]);
   if alf[1]='$' then  begin
    for i:=2 to length(alf) do include(r,alf[i]) ;
    r:= [chr(0)..chr(255)]-r;
   end;
  end;
 end;
 sl:=false; L:=nil; ss:='' ;  i:=1;
 while i<=length(s) do begin
   if ((not(s[i] in r)) and (sl=false))  then sl:=true;
   if (not(s[i] in r)) and (sl=true) then ss:=ss+s[i];
   if ((s[i] in r)or(i=length(s)))  and (sl=true) then
   begin
    AddLast(L,ss); ss:=''; sl:=false;
   end;
   inc(i)
 end;
 SepWord:=L;
end;

var
 L:tlist;
begin
 l:=nil;
 l:=sepword('123 12345 dgdfg','$123456789');
 blistprint(l);
 readln;
 listclear(l);
end.