// 1
// 2
// 3
// 4
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
// Í.Î.Ï.
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
const int N = (int)1e3;
char s[N + 1], t[N + 1];
int sn, tn;
unsigned short f[N + 2][N + 2];
inline void relax( int i, int j, int b )
{
if (f[i][j] < b)
f[i][j] = b;
}
void solve()
{
reverse(s, s + sn);
reverse(t, t + tn);
memset(f, 0, sizeof(f));
forn(i, sn + 1) // i = 0..sn
forn(j, tn + 1) // j = 0..tn
{
if (s[i] == t[j])
relax(i + 1, j + 1, f[i][j] + 1);
relax(i + 1, j, f[i][j]);
relax(i, j + 1, f[i][j]);
}
printf("%d\n", f[sn][tn]);
int i = sn, j = tn;
while (f[i][j] > 0)
{
if (s[i - 1] == t[j - 1] && f[i][j] == f[i - 1][j - 1] + 1)
i--, j--, putchar(s[i]);
else if (f[i][j] == f[i - 1][j])
i--;
else
j--;
}
}
int main()
{
gets(s);
gets(t);
sn = strlen(s);
tn = strlen(t);
solve();
return 0;
}