var
f:text;
oldst:string;
ch:char;
i,j,n:integer;
s1,s2,ss1,ss2:string;
l1,l2,ll1,ll2:integer;
procedure find(var oldst,st:string; var oldl,l:integer);
var
ch:array[1..256] of char;
b:array[1..256] of byte;
temp:char;
i,j:integer;
begin
for i:=1 to oldl do begin ch[i]:=oldst[i]; b[i]:=0; end;
for i:=1 to oldl-1 do for j:=1 to oldl-i do
if ch[j]>ch[j+1] then begin
temp:=ch[j]; ch[j]:=ch[j+1]; ch[j+1]:=temp;
end;
for i:=2 to oldl do if ch[i]=ch[i-1] then b[i]:=1;
l:=0;
st:='';
for i:=1 to oldl do
if b[i]=0 then begin
inc(l);
st:=st+ch[i];
end;
end;
begin
assign(f,'最少期数.txt'); reset(f);
readln(f,n);
oldst:='';
for i:=1 to n do begin read(f,ch); oldst:=oldst+ch; end;
close(f);
s1:='';
s2:='';
l1:=0;
l2:=0;
for i:=1 to n do
for j:=1 to n-i+1 do begin
ss1:=copy(oldst,j,i);
ll1:=i;
find(ss1,ss2,ll1,ll2);
if ll2>l2 then begin
s1:=ss1;
s2:=ss2;
l1:=ll1;
l2:=ll2;
end;
end;
writeln(s1);
writeln(l1);
writeln(s2);
writeln(l2);
end.