using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("abc");
WillReturn.Add("aba");
//2
}
else if (InputPattern == "Input2") {
WillReturn.Add("aaaaaa");
WillReturn.Add("a");
//0
}
else if (InputPattern == "Input3") {
WillReturn.Add("abra");
WillReturn.Add("cadabra");
//4
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
string S = InputList[0];
string T = InputList[1];
int UB_S = S.Length - 1;
int UB_T = T.Length - 1;
// 非共通部分列の長さ[SのInd, TのInd] なDP表
int?[,] DPArr = new int?[UB_S + 1, UB_T + 1];
DPArr[0, 0] = 0;
int Answer = 0;
for (int I = 0; I <= UB_S; I++) {
for (int J = 0; J <= UB_T; J++) {
if (DPArr[I, J].HasValue == false) continue;
Action<int, int, int> UpdateAct = (pNewI, pNewJ, pNewVal) =>
{
Answer = Math.Max(Answer, pNewVal);
if (UB_S < pNewI) return;
if (UB_T < pNewJ) return;
if (DPArr[pNewI, pNewJ].HasValue) {
if (DPArr[pNewI, pNewJ] >= pNewVal) {
return;
}
}
DPArr[pNewI, pNewJ] = pNewVal;
};
// 両方進め、非共通部分列に使う
if (S[I] != T[J]) {
UpdateAct(I + 1, J + 1, DPArr[I, J].Value + 1);
}
// Sだけ進める
UpdateAct(I + 1, J, DPArr[I, J].Value);
// Tだけ進める
UpdateAct(I, J + 1, DPArr[I, J].Value);
}
}
Console.WriteLine(Answer);
}
}