#include<bits/stdc++.h>
#define ll   long long int
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define inf 100000000000000LL
#define fast_io	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007 
#define range 1000000
#define lg 22
#define range2 1000000000
#define pp pair<ll,ll>
//#define endl "\n"


using namespace std;
string s1,s2;
ll dp[5001][5001][2][2];
//ll dp[p1][p2][f][k]-> p1, p2 is index of string s1,s2 respectcivegly, f-> 0 matlab abhi tak ek bhi add nhi kiya char-> 1 matlab ek daal diya // aur 1 daalna zaruri h. k-> [0]->max length ab tak, [1] -> uska count ab tak

 
pp calc(ll p1,ll p2,ll f)		//returns (new_max_len,count)
{
	
	
	if(p1==-1||p2==-1)
	{
		pp x;
		x.ff=0,x.ss=0; // by default if boo criteria satisfy toh count and len 0,
		
		if(f==1) // agar ek char daal liya toh count=1 return //self explanatory
		x= mp(0,1);
		else
		if(p1==-1&&p2!=-1) // manlo ki s1 khatam ho gya , par s2 k kuch character bache h-> aur f=0 h, toh ek char add kr skte h-> one of any of those left hence count= p2+1, max_len=1 coz 1 char le liya LCS mein
			x= mp(1,p2+1);
	
		return x;
//		cout<<p1<<" "<<p2<<" "<<f<<"	"<<x.ff<<" "<<x.ss<<endl;
		
		
	}
	if(dp[p1][p2][f][1]!=-1)
	return mp(dp[p1][p2][f][0],dp[p1][p2][f][1]);
	pp x1,x2,x3,ans;
	ll xn;	

	x1.ff=x2.ff=x3.ff=ans.ff=0;
	x1.ss=x2.ss=x3.ss=ans.ss=0;
	if(s1[p1]==s2[p2])
	{
		x1=calc(p1-1,p2-1,f); // normal jaisa hota same h toh length+1
		x1.ff++;
		
		if(f<1) // special case// agar naya char s1 ke p1 k right mein daal diya aur use aur s2[p2] ko le lia
		{
			x2=calc(p1,p2-1,f+1);// toh p1 vaisa hi rahega, p2-1 ho jaega
			x2.ff++; // coz humne s2[p2] ko match kara diya inserted char se toh length+1 ho gyi
		}
		
		
		
		xn=max(x1.ff,x2.ff); // max length ab tak kitni h?
		ans.ff=xn;
		// jis jis ki uske equal h, unke counts add karlo
		if(xn==x1.ff)
		ans.ss+=x1.ss;
		
		if(xn==x2.ff)
		ans.ss+=x2.ss;
		
	}
	else
	{
		x1=calc(p1-1,p2,f); // normal
		x2=calc(p1,p2-1,f); // normal
		
		if(f<1) // special case// agar naya char s1 ke p1 k right mein daal diya aur use aur s2[p2] ko le lia
		{
			x3=calc(p1,p2-1,f+1); // toh p1 vaisa hi rahega, p2-1 ho jaega
			x3.ff++; // coz humne s2[p2] ko match kara diya inserted char se toh length+1 ho gyi
		}
		// max length ab tak kitni h?
		
		xn=max(x1.ff,max(x2.ff,x3.ff));
		ans.ff=xn;
		
		// jis jis ki uske equal h, unke counts add karlo
		
		if(xn==x1.ff)
		ans.ss+=x1.ss;
		
		if(xn==x2.ff)
		ans.ss+=x2.ss;
		
		if(xn==x3.ff)
		ans.ss+=x3.ss;
//		cout<<xn<<endl;
//		cout<<p1<<" "<<p2<<" "<<f<<"	x1	"<<x1.ff<<" "<<x1.ss<<endl;
//		cout<<p1<<" "<<p2<<" "<<f<<"	x2	"<<x2.ff<<" "<<x2.ss<<endl;
//		cout<<p1<<" "<<p2<<" "<<f+1<<"	x3	"<<x3.ff<<" "<<x3.ss<<endl;
//		cout<<p1<<" "<<p2<<" "<<f<<"	x4	"<<ans.ff<<" "<<ans.ss<<endl;
	}
//	cout<<p1<<" "<<p2<<" "<<f<<"	"<<ans.ff<<" "<<ans.ss<<endl;
	// inka pair bana k store karlo
	dp[p1][p2][f][0]=ans.ff;
	dp[p1][p2][f][1]=ans.ss;
	
	return mp(ans.ff,ans.ss);
	
}


int main()
{
	ll n1,n2;
	memset(dp,-1,sizeof(dp));
	cin>>s1>>s2;
	n1=s1.length()-1;
	n2=s2.length()-1;
	pp x=calc(n1,n2,0);
//	cout<<x.ff<<"	"<<x.ss<<endl;
	cout<<x.ss<<endl;
	
	
}