#include #include #include #include #include #include #include #include #include using namespace std; class DP { public: int F(string s, string t); map Cache; }; int DP::F(string s, string t) { char a, b; string x, y, key; int a1, a2; if (s.size() == 0 || t.size() == 0) return 0; key = s; key += ' '; key += t; if (Cache.find(key) != Cache.end()) return Cache[key]; a = s[0]; x = s.substr(1); b = t[0]; y = t.substr(1); if (a > b) { a1 = F(s, y); a2 = 1 + F(x, t); } else { a1 = 2 + F(s, y); a2 = F(x, t); } Cache[key] = ( (a1 > a2) ? a1 : a2 ); return Cache[key]; } main() { string s1, s2; DP dp; if (!(cin >> s1 >> s2)) exit(1); printf("%d\n", dp.F(s1, s2)); }