var
s1,s2:string;
i,j:integer;
f:array[1..255,1..255] of longint;
b:array[1..255,1..255] of string;
begin
readln(s1);readln(s2);
for i:=1 to length(s1) do f[i,0]:=0;
for j:=1 to length(s2) do f[0,j]:=0;
for i:=1 to length(s1) do
for j:=1 to length(s2) do
begin
if s1[i]=s2[j] then
begin
f[i,j]:=f[i-1,j-1]+1;
b[i,j]:=b[i-1,j-1]+s1[i];
end else
if f[i-1,j]>f[i,j-1] then
begin
f[i,j]:=f[i-1,j];
b[i,j]:=b[i-1,j];
end else
begin
f[i,j]:=f[i,j-1];
b[i,j]:=b[i,j-1];
end;
end;
writeln(f[length(s1),length(s2)]);
writeln(b[length(s1),length(s2)]);
end.