#include #include #include #include #include #include #include #include #include using namespace std; class DP { public: string s, t; int F(int si, int ti); vector < vector > Cache; }; int DP::F(int si, int ti) { int a1, a2; char a, b; if (si == s.size() || ti == t.size()) return 0; if (Cache[si][ti] != -1) return Cache[si][ti]; a = s[si]; b = t[ti]; if (a > b) { a1 = F(si, ti+1); a2 = 1 + F(si+1, ti); } else { a1 = 2 + F(si, ti+1); a2 = F(si+1, ti); } Cache[si][ti] = ( (a1 > a2) ? a1 : a2 ); return Cache[si][ti]; } main() { DP dp; int i; if (!(cin >> dp.s >> dp.t)) exit(1); dp.Cache.resize(dp.s.size()); for (i = 0; i < dp.Cache.size(); i++) { dp.Cache[i].resize(dp.t.size(), -1); } printf("%d\n", dp.F(0, 0)); }