// 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;
struct State
{
unsigned short f : 10; // 0 <= f <= N : 10 bit
unsigned short p : 2; // 0 <= p <= 2 : 2 bit
} a[N + 2][N + 2];
inline void relax( int i, int j, int b, int type )
{
if (a[i][j].f < b)
a[i][j].f = b, a[i][j].p = type;
}
void solve()
{
reverse(s, s + sn);
reverse(t, t + tn);
memset(a, 0, sizeof(a));
forn(i, sn + 1) // i = 0..sn
forn(j, tn + 1) // j = 0..tn
{
if (s[i] == t[j])
relax(i + 1, j + 1, a[i][j].f + 1, 0);
relax(i + 1, j, a[i][j].f, 1);
relax(i, j + 1, a[i][j].f, 2);
}
printf("sizeof = %d\n", sizeof(State));
printf("%d\n", a[sn][tn].f);
int i = sn, j = tn;
while (a[i][j].f > 0)
{
int type = a[i][j].p;
//fprintf(stderr, "i = %d, j = %d, type = %d : f = %d\n", i, j, type, a[i][j].f);
if (type == 0)
i--, j--, putchar(s[i]);
else if (type == 1)
i--;
else
j--;
}
}
int main()
{
gets(s);
gets(t);
sn = strlen(s);
tn = strlen(t);
solve();
return 0;
}