public class LCSequence {
public static void main(String[] args) {
String[] paras = getInput();
System.out.println(getLongestSubsequence(paras[0], paras[1]));
}
public static String[] getInput() {
Scanner reader = new Scanner(System.in);
String[] paras = new String[2];
paras[0] = reader.nextLine();
paras[1] = reader.nextLine();
reader.close();
return paras;
}
public static String[][] getGenerationMatirx(String str1, String str2) {
int[][] temp = new int[str1.length() + 1][str2.length() + 1];
String[][] flag = new String[str1.length() + 1][str2.length() + 1];
for (int i = 0; i <= str1.length(); i ++) {
temp[0] = 0;
}
for (int i = 0; i <= str2.length(); i ++) {
temp[0] = 0;
}
//迭代获取最长公共子序列的生成矩阵
for (int i = 1; i <= str1.length(); i ++) {
for (int j = 1; j <= str2.length(); j ++) {
if (str1.charAt(i - 1) == str2.charAt(j - 1)) {
temp[j] = temp[i - 1][j - 1] + 1;
flag[j] = "left_up";
} else {
if (temp[i - 1][j] >= temp[j - 1]) {
temp[j] = temp[i - 1][j];
flag[j] = "up";
} else {
temp[j] = temp[j - 1];
flag[j] = "left";
}
}
}
}
return flag;
}
public static String getLongestSubsequence(String str1, String str2) {
String[][] flagMatrix = getGenerationMatirx(str1, str2);
String tempString = "";
for (int i = str1.length(), j = str2.length(); i > 0 && j > 0;) {
if (flagMatrix[j].equals("left_up")) {
tempString += str1.charAt(i - 1);
i --;
j --;
} else if (flagMatrix[j].equals("left")) {
j --;
} else {
i --;
}
}
return new StringBuffer(tempString).reverse().toString();
}