#include <bits/stdc++.h>
#define _nhatminh int main()
#define ll long long
#define str string
#define fir first
#define sec second
#define ld long double
#define pb push_back
#define MOD 100000009
#define freopen(name) if(fopen(name".INP","r")) {freopen (name".INP","r",stdin); freopen (name".OUT","w",stdout);}
#define ALL(x) (x).begin(),(x).end()
#define piint pair < int , int >
#define piL pair < int , ll>
#define pLL pair < ll , ll >
#define TIME (1.0*clock()/CLOCKS_PER_SEC)
using namespace std;
const int Max_n=5*1e3 ;
bool check[Max_n+3][Max_n+3];
int dp[Max_n+3][Max_n+3] , f[Max_n+3];
ll res = 1 ;
void KT ( str a, str b){
a = '*' + a ;
b = '*' + b ;
memset ( check , false , sizeof(check));
memset ( dp , 0 , sizeof(dp));
memset ( f , 0 , sizeof(f));
int n = a.size() -1 , m = b.size() - 1 ;
//fill ( check + 1 , check + n + 1 , 1 );
for (int i = 1 ; i <= n ; i ++ )
check[i][i] = true;
for (int d = 2 ; d <= n ; d ++ ){
for (int i = 1 ; i <= n - d + 1 ; i ++){
int j = i + d - 1 ;
if ( d == 2 && a[i] == a[j] ) { check[i][j]= true; continue ;}
if (a[i] == a[j] && check[i+1][j-1]) check[i][j] = true;
}
}
// a - > b
for (int i = 1 ; i <= n ; i ++ )
for (int j = m ; j >= 1 ; j -- ){
if ( a[i] == b[j]) dp[i][j] = dp[i-1][j+1] + 2;
}
for (int i = 1 ; i <= n ; i ++ ){
for (int j = m ; j >= 1 ; j --)
f[i] = max ( f[i] , dp[i][j]) , res = max ( res , 1ll*f[i]);
}
for (int i = 1 ; i<= n ; i ++ ){
for (int j = i ; j <= n ; j ++ )
if ( check[i][j] ) {
res = max ( res , 1ll*f[i-1] + j - i + 1 );
// cout << i+1 << ' ' << j << ' ' << f[i] << '\n';
}
}
}
void solve(){
str a , b ; cin >> a >> b;
KT ( a , b ) ;
reverse(ALL(b));
reverse(ALL(a));
KT(b,a);
cout << res ;
}
_nhatminh{
freopen("GHEPXAU");
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int q=1;
// cin >> q;
while (q--)
solve();
cerr << '\n' << "Time elapsed " << TIME << "s.\n";
return (0);
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgX25oYXRtaW5oICBpbnQgbWFpbigpCiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgc3RyIHN0cmluZwojZGVmaW5lIGZpciBmaXJzdAojZGVmaW5lIHNlYyBzZWNvbmQKI2RlZmluZSBsZCBsb25nIGRvdWJsZQojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIE1PRCAxMDAwMDAwMDkKI2RlZmluZSBmcmVvcGVuKG5hbWUpIGlmKGZvcGVuKG5hbWUiLklOUCIsInIiKSkge2ZyZW9wZW4gKG5hbWUiLklOUCIsInIiLHN0ZGluKTsgZnJlb3BlbiAobmFtZSIuT1VUIiwidyIsc3Rkb3V0KTt9CiNkZWZpbmUgQUxMKHgpICh4KS5iZWdpbigpLCh4KS5lbmQoKQojZGVmaW5lIHBpaW50IHBhaXIgPCBpbnQgLCBpbnQgPgojZGVmaW5lIHBpTCBwYWlyIDwgaW50ICwgbGw+CiNkZWZpbmUgcExMIHBhaXIgPCBsbCAsIGxsID4KI2RlZmluZSBUSU1FICgxLjAqY2xvY2soKS9DTE9DS1NfUEVSX1NFQykKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY29uc3QgaW50IE1heF9uPTUqMWUzIDsKYm9vbCBjaGVja1tNYXhfbiszXVtNYXhfbiszXTsKaW50IGRwW01heF9uKzNdW01heF9uKzNdICwgZltNYXhfbiszXTsKbGwgcmVzID0gMSA7CnZvaWQgS1QgKCBzdHIgYSwgc3RyIGIpewoJYSA9ICcqJyArIGEgOwoJYiA9ICcqJyArIGIgOwoJbWVtc2V0ICggY2hlY2sgLCBmYWxzZSAsIHNpemVvZihjaGVjaykpOwoJbWVtc2V0ICggZHAgLCAwICwgc2l6ZW9mKGRwKSk7CgltZW1zZXQgKCBmICwgMCAsIHNpemVvZih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