
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <math.h>

typedef long long LL;

using namespace std;

const int N = 107;

string a;
string b;

int d[N][N];
int w[N][N];

int D(int x, int y)
{
	if (x == a.size() || y == b.size())
		return 0;

	int &res = d[x][y];
	if (res != -1)
		return res;
	res = 0;
	if (a[x] == b[y])
		res = 1 + D(x + 1, y + 1);
	{
		int t = D(x, y + 1);
		if (res < t)
		{
			res = t;
			w[x][y] = 1;
		}
	}
	{
		int t = D(x + 1, y);
		if (res < t)
		{
			res = t;
			w[x][y] = 2;
		}
	}
	return res;
}

string W(int x, int y) {
	if (x == a.size() || y == b.size())
		return "";
	switch (w[x][y])
	{
	case 0: return a[x] + W(x + 1, y + 1);
	case 1: return W(x, y + 1);
	case 2: return W(x + 1, y);
	}
	return "";
}

int main()
{
	cin >> a >> b;

	memset(d, 0xFF, sizeof(d));

	cout << D(0, 0) << "\n";
	cout << W(0, 0) << "\n";


	return 0;
}