#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int dp[1001][1001];
int main(){
	string t,b;
	cin>>t>>b;
	dp[0][0]=0;
	int MOD=1000000007;
	for(int i=1;i<=b.size();i++){
		for(int j=1+i-1;j<=t.size();j++){
		
			 if(b[i-1]==t[j-1]){
				if(i==1)dp[i][j]=(dp[i][j-1]+1)%MOD;
				else dp[i][j]=(dp[i-1][j-1]+dp[i][j-1])%MOD;
			}
			else dp[i][j]=dp[i][j-1]%MOD;
		}
	}
	cout<<dp[b.size()][t.size()]%MOD<<endl;
	return 0;
}