/*
思路:枚举 a[i]==b[j]的地方统计
*/
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)
#define bug printf("hihi\n")
#define mod 1000000007
#define eps 1e-8
typedef __int64 ll;
using namespace std;
#define N 5005
#define mod 1000000007
char a[N],b[N];
int lena,lenb;
ll dp[N][N];
int main()
{
int i,j;
while(~scanf("%s%s",b+1,a+1))
{
lena=strlen(a+1);
lenb=strlen(b+1);
ll ans=0;
for(i=1;i<=lena;i++) //a 是不连续的
{
for(j=1;j<=lenb;j++) //b是连续的
{
dp[i][j]=dp[i-1][j]; //dp[i][j]记录和前i-1和 j匹配的情况有多少种
if(a[i]==b[j]) //当a[i]==b[j] 那么就是满足新的条件的
{
dp[i][j]=(dp[i][j]+dp[i-1][j-1]+1)%mod;
ans=(ans+dp[i-1][j-1]+1)%mod;
}
}
}
printf("%I64d\n",ans);
}
return 0;
}