// AOJ 2035: It Prefokery Pio
// 2017.10.9 bal4u@uu
// 2017.11.21

#include <stdio.h>
#include <string.h>

char s[2005], t[2005];

int c[2005][2005];  // for LCS
char z[2005];
char f[2005][2005];
void LCS(char *x, int m, char *y, int n)
{
	int i, j, k;

	memset(c, 0, sizeof(int)*n); memset(f, 0, n);
	for (i = 1; i <= m; i++) for (j = 1; j <= n; j++) {
		if (x[i-1] == y[j-1])            c[i][j] = c[i-1][j-1]+1, f[i][j] =  0;
		else if (c[i-1][j] >= c[i][j-1]) c[i][j] = c[i-1][j],     f[i][j] =  1;
		else                             c[i][j] = c[i][j-1],     f[i][j] = -1;
	}
	k = c[m][n]-1;
	z[k+1] = 0;
	while (k >= 0) {
		if      (f[m][n] > 0) m--;
		else if (f[m][n] < 0) n--;
		else z[k] = x[m-1], k--, m--, n--;
	}
}

int main()
{
	char *p, *q;

	while (fgets(s, 2005, stdin) != NULL) {
		p = s, q = t+2002;
		while (*p > ' ') *--q = *p++;
		LCS(s, p-s, q, p-s);
		puts(z);
	}
	return 0;
}