#include<bits/stdc++.h>
using namespace std;
const int N=5e3+5;
const int mod=1e9+7;
int dp[N][N];
char s[N];
char t[N];
int main(){
	scanf("%s",s+1);
	scanf("%s",t+1);
	int lens=strlen(s+1);
	int lent=strlen(t+1);
	for(int i=1;i<=lens;i++){
		for(int j=1;j<=lent;j++){
			dp[i][j]=(dp[i][j-1]+(s[i]==t[j]?dp[i-1][j-1]+1:0))%mod;
		}
	}
	int ans=0;
	for(int i=1;i<=lens;i++){
		ans=(ans+dp[i][lent])%mod;
	}
	printf("%d\n",ans);
	return 0;
}

#include<bits/stdc++.h>
#define ll long
using namespace std;
const ll maxn=5010,mod=1e9+7;
ll dp,sum[maxn][maxn],ans;//sum[i][j]: dp[i][j]+dp[i][j-1]+dp[i][j-2]+...
int main(){
	string s,t;cin>>s>>t;
	dp=(s[0]==t[0]);
	sum[0][0]=dp;
	ans+=dp;
	for(ll i=1;i<t.size();i++){
		dp=(s[0]==t[i]);
		sum[0][i]=sum[0][i-1]+dp;
		ans+=dp;
	}
	for(ll i=1;i<s.size();i++){
		dp=(s[i]==t[0]);
		sum[i][0]=dp;
		ans+=dp;
	}
	for(ll i=1;i<s.size();i++){
		for(ll j=1;j<t.size();j++){
			dp=0;
			if(s[i]==t[j]){
				dp=1+sum[i-1][j-1];
				ans=(ans+dp)%mod;
			}
			sum[i][j]=(sum[i][j-1]+dp)%mod;
		}

	}
	cout<<ans;
}

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>

using namespace std;
typedef long long ll;
const int MAXN = 5100;
const long long MOD = 1000000007;

string s, t;
ll num[MAXN];

int main()
{
    cin >> s >> t;
    int n = s.length(), m = t.length();
    for (int i = 0; i < n; i++)
        num[i] = 1;
    num[n] = 0;
    for (int i = 0; i < m; i++)
    {
        for (int j = n - 1; j >= 0; j--)
            if (t[i] == s[j])
                num[j+1] = (num[j] + num[j+1]) % MOD;
    }
    ll ans = 0;
    for (int i = 0; i <= n; i++)
        ans = (ans + num[i]) % MOD;
    ans = (ans + MOD - n) % MOD;
    cout << ans << "\n";
    //system ("Pause");
    return 0;
}

/**
 *    author:  bigboss
 *    created: 16.09.2018
**/
#include <bits/stdc++.h>

using namespace std;

const int MAX = 5005;
const int mod = 1e9 + 7;
int n, m;
string s, t;
int F[MAX][MAX];
int G[MAX][MAX];

int main()
{
    ios :: sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    //freopen ("CF.inp", "r", stdin);
    //freopen ("CF.out", "w", stdout);

    cin >> s >> t;
    n = s.size(); m = t.size(); s = ' ' + s; t = ' ' + t;
    memset(F, 0, sizeof(F));
    memset(G, 0, sizeof(G));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            G[i][j] = G[i][j - 1];
            if (s[i] != t[j]) continue;
            F[i][j] = 1;
            F[i][j] += (G[i - 1][j - 1]);
            F[i][j] %= mod;
            G[i][j] += F[i][j];
            G[i][j] %= mod;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) ans = (ans + F[i][j]) % mod;
    }

    cout << ans;

    return 0;
}

//In the name of Allah

#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int MAXN=50*100+3+100;
ll dp[MAXN][MAXN];
ll mod=(10e+8)+7;
int main(){
	string s,t;
	cin>>s>>t;
	/*
	for(int i=1;i<=s.size();i++){
		if(s[i-1]==t[0]){
			for(int j=i;j<=s.size();j++)
				dp[1][j]++;
			//cerr<<"HAVIJ BASTANI"<<endl;
		}
	}
	for(int i=1;i<=t.size();i++){
		if(t[i-1]==s[0]){
			for(int j=i;j<=t.size();j++)
				dp[j][1]++;
		}
	}
	*/
	ll ans=0;
	for(int i=0;i<s.size();i++){
		for(int j=0;j<t.size();j++){
			if(j>0)
				dp[i][j]+=dp[i][j-1];
			if(s[i]==t[j] and j and i)
				dp[i][j]+=dp[i-1][j-1]+1;
			else if(s[i]==t[j])
				dp[i][j]++;
			dp[i][j]=(dp[i][j]+mod)%mod;
		}
	}
	/*
	for(int i=0;i<s.size();i++){
		for(int j=0;j<t.size();j++)
			cout<<dp[i][j];
		cout<<endl;
	}
	*/
	for(int i=0;i<s.size();i++)
		ans+=dp[i][t.size()-1];
	cout<<ans%mod;;
	return 0;
}

# include<bits/stdc++.h>

using namespace std;

// Basic
typedef long long 		ll;
typedef long double 		ld;

// Pair
typedef pair<int, int >	   ii;
typedef pair<ll, ll>		   LL;
typedef pair<int, string >	istr;

// List
typedef vector<int >		vi;
typedef vector<vi >		vvi;
typedef vector<ll >		vll;
typedef vector<vll >    vvll;

typedef vector<ii >		vii;
typedef vector<LL >		vLL;

typedef vector<string > vstr;
typedef vector<istr>		vistr;

// Map
typedef map<ll, int > 		mpll;
typedef map<string, int>	mpstr;

// Set
typedef set<string > 		sstr;
typedef set<int >    		si;
typedef set<ii > 				sii;

// multiset
typedef multiset<int >		msi;
typedef multiset<ii >		msii;

// Stacks and Queue
typedef queue<char >       qc;
typedef queue<int >        qi;

typedef stack<char >       stc;
typedef stack<int >        sti;

// ---------------- Value Manipulators --------------------
const int    inf  = 1e9;
const double pi   = acos(-1);
const int    SLMT = 1e5 + 5;
const int    ALMT = 1e6 + 5;

# define ROUND(x)	(int)((double)x + 0.5)

//------------------ REPEAT --------------------------------
# define repf(i, a, b)	for(auto i = a; i != b; ++i)
# define repr(i, a, b)	for(auto i = a; i != b; --i)
# define repstr(i, str)	for(auto i = 0; str[i]; ++i)

// # define uDia(i, j, m, n)	repf(i,0,m) repf(j, i+1, n)
// # define lDia(i, j, m, n)	repf(i,0,m) repf(j,0,i)
// # define cMat(i, j, m, n)	repf(i,0,m)	repf(j,0,n)

// ----------------- STL -----------------------------------
# define mp(x, y)		make_pair(x, y)
# define pb(x) 		    push_back(x)
# define pob()			pop_back()
# define stlf(x)		x.begin(), x.end()
# define stlr(x)		x.rbegin(), x.rend()
# define F				first
# define S				second

// ----------------- I/O -----------------------------------
# define gc()			getchar()
# define pc(x)			putchar(x)

# define ss(str)		scanf("%s", str)
# define ps(str)		puts(str)

# define pnl			pc('\n')

# define sll(x)		sd(x)
# define pll(x)      pd(x)

template <class T >
inline void sd(T &num){

	num = 0;
	int sign = 0;
	char ch;

	while(isspace(ch = gc()));

	if(isdigit(ch))
		num = ch - '0';
	else
		sign = ch == '+' ? 0: 1;

	while(isdigit(ch = gc()))
		num = (num << 3 ) + (num << 1) + ch - '0';

	num = sign ? -num : num;
}

template <class T >
inline void pd(T num, char ch = ' '){
   if(num < 0){
     pc('-');
     num = -num;
   }

   char digits[21] = {};
   int pos = 1;

   do{
      digits[pos++] = '0' + num%10;
   }while(num /= 10);

   while(--pos)
      pc(digits[pos]);

   pc(ch);
}

# define sdbl(x)	 scanf("%f", &x)
# define pdbl(x,y)   printf("%.*f ",x,y)
# define pf(x)       printf("%f", x)

// Input int array
template <class T>
inline void iArr(T &arr, int size){
	repf(i, 0, size)
		sd(arr[i]);
}

// Input map input integers
template <class T>
inline int mArr(T &arr, int size){
   int val;
   int mval = INT_MIN;
	repf(i, 0, size)
		sd(val), ++arr[val], mval = max(mval, val);
   return mval;
}

template <class T>
inline void oArr(T &arr, int size){
	repf(i, 0, size)
		pd(arr[i]);
	pnl;
}

template <class T>
inline void iMat(T &mat, int n, int m){
	repf(i, 0, n)
		repf(j, 0, m)
			sd(mat[i][j]);
}

template <class T>
inline void oMat(T &mat, int n, int m){
	repf(i, 0, n){
		repf(j, 0, m)
			pd(mat[i][j]);
		pnl;
	}
}

// character matrix fix :
inline void oMat(char **mat, int n){
	repf(i, 0, n)
	   ps(mat[i]);
}

inline void iMat(char **mat, int n){
	repf(i, 0, n)
		ss(mat[i]);
}

# define lb(x)		lower_bound(x)
# define ub(x)		upper_bound(x)

# define lb(x, y, val)	lower_bound(x, y, val)
# define ub(x, y, val)	upper_bound(x, y, val)

// --------------------------------------------------
// ------------- Data Fillers -----------------------
// --------------------------------------------------

template <class T>
inline void MAT(T **&mat, int r, int c, T val = 0){
   mat = new T*[r];

   if(!val){
    repf(i, 0, r)
      mat[i] = new T[c]();
      return ;
   }

   repf(i, 0, r){
      mat[i] = new T[c];
      repf(j, 0, c)
         mat[i][j] = val;
   }
}

template <class T>
inline void ARR(T *&arr, int n, int val = 0){
   arr = new T[n];
   fill(arr, arr+n, val);
}

// --------------------------------------------------
// ------------ CODE MODES --------------------------
// --------------------------------------------------
# define FAST		ios_base::sync_with_stdio(false); cin.tie(0);
# define TC			int tc; sd(tc); while(tc--)

// --------------------------------------------------
// ----------------- Debugging ----------------------
// --------------------------------------------------
int bug = 0;
# define ok cout<<"OK-"<<bug++<<endl;

// --------------------------------------------------
// ------------- Additional Data --------------------
// --------------------------------------------------

// ---------------------------------------------------------------
// --------------------- Support Codes	--------------------------
// ---------------------------------------------------------------

// ---------------------------------------------------------------
// ------------------------ END	----------------------------------
// ---------------------------------------------------------------

const int MLEN = 5e3 + 1;

const int MOD = 1e9+7;

char s1[MLEN], s2[MLEN];
int dp[MLEN][MLEN];

int main(void){

    ss(s1);
    ss(s2);

    int len1 = strlen(s1);
    int len2 = strlen(s2);

    repr(i, len1-1, -1)
        repr(j, len2-1, -1)
            dp[i][j] = (dp[i][j+1] + (s1[i] == s2[j] ? 1 + dp[i+1][j+1] : 0)) % MOD;

    int ans = 0;
    for(int i = 0; i < len1; ++i)
        (ans += dp[i][0]) %= MOD;

    pd(ans);

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const int MOD = 1e9+7;
typedef long long LL;
int dp[N][N];
char s[N], t[N];
int main()
{
	scanf("%s%s", s, t);
	int ls = strlen(s);
	int lt = strlen(t);
	for(int i = ls-1;i >= 0; i--)
		for(int j = lt-1;j >= 0; j--)
		{
			dp[i][j] = dp[i][j+1];
			if(s[i] == t[j])
				dp[i][j] = (dp[i][j]+dp[i+1][j+1]+1)%MOD;
		}

	int res = 0;
	for(int i = 0;i < ls; i++)
		res = (res+dp[i][0])%MOD;
	printf("%d\n", res);
	return 0;
}

#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];  //dp[i][j] 第一个串位置i 第二个串位置为j，此时满足条件的个数

void show()
{
    int i,j;
    for(i=1;i<=lena;cout<<endl,i++)
        for(j=1;j<=lenb;j++)
           printf("%d %d %d\n",i,j,dp[i][j]);
}
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++)
        {
            for(j=1;j<=lenb;j++)
            {
               dp[i][j]=dp[i-1][j];
               if(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;
                  }
            }
        }
      // show();
        printf("%I64d\n",ans);
    }
    return 0;
}

#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",a+1,b+1))
    {
        lena=strlen(a+1);
        lenb=strlen(b+1);
        ll ans=0;
        for(i=1;i<=lena;i++)
        {
            for(j=1;j<=lenb;j++)
            {
               dp[i][j]=dp[i][j-1];
               if(a[i]==b[j])
                dp[i][j]=(dp[i][j]+dp[i-1][j-1]+1)%mod;
            }
            ans=(ans+dp[i][lenb])%mod;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define pi 3.141592653589793238462643383279
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;

int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};

int dp[5005][5005];

int32_t main()
{

ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);

#ifndef ONLINE_JUDGE
freopen("input.txt","rt",stdin);
freopen("output.txt","wt",stdout);
#endif

  memset(dp,0,sizeof(dp));
   string s,t;
   cin>>s>>t;
    int n=s.size();
    int m=t.size();
    s=" "+s; t=" "+t;
        int ans=0;
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
            {
                 dp[i][j]=dp[i-1][j];
               if(t[i]==s[j])
                  {

                      dp[i][j]=(dp[i][j]+dp[i-1][j-1]+1)%mod;
                      ans=(ans+dp[i-1][j-1]+1)%mod;
                  }
            }
        }
        cout<<ans<<"\n";

}

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
//#define int long long
#define inf 200000000
const int maxnodes=1005;
#define ll long long
#define N 5001
#define EPS 0.01
#define ld long double

string s,t;
int dp[N][N];

int rec(int i,int j)
{
    if(i == s.length() or j == t.length())
        return 0;
    if(dp[i][j] == -1)
    {
        ll ans = 0;
        if(s[i] == t[j])
            ans = 1 + rec(i+1,j+1);
        ans = (ans + rec(i,j+1)) % mod;
        dp[i][j] = ans;
        return ans;
    }
    else
        return dp[i][j];
}

int32_t main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    cin >> s >> t;
    memset(dp,-1,sizeof(dp));
    ll ans = 0;
    for(int i = 0;i < s.length();i++)
    {
        ans = (ans + rec(i,0)) % mod;

    }

    cout << ans << endl;

}

#include<bits/stdc++.h>
#define ll long long
#define make(aa,bb) make_pair(aa,bb)
#define PII pair<int,int>
#define fi first
#define se second
#define lowbit(x) (x)&(-x)
using namespace std;
const int N=5005,p=1e9+7;
char s1[N],s2[N];
int f[N][N],len1,len2;
int main(){
	scanf("%s%s",s1+1,s2+1);
	len1=strlen(s1+1),len2=strlen(s2+1);
	for(int i=1;i<=len1;i++){
		for(int j=1;j<=len2;j++){
			f[i][j]=f[i][j-1];
			if(s1[i]==s2[j]) f[i][j]=(f[i][j]+f[i-1][j-1]+1)%p;
		}
	}
	int ans=0;
	for(int i=1;i<=len1;i++) ans=(ans+f[i][len2])%p;
	printf("%d",ans);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll  long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define input1(n) ll n;cin>>n;
#define input2(a,b) ll a,b;cin>>a>>b;
#define INF 1e9
#define test ll t;cin>>t;while(t--)
#define MOD 1000000007
ll visited[2000005];
ll a[2000005],c[2000005],ans=0;
vector<vector<int>>adj;
vector<int>dp;
int n,m;

void addEdge(vector<ll>adj[],ll a,ll b)
{
    adj[a-1].pb(b-1);
    adj[b-1].pb(a-1);
}
 void dfs(vector<ll>adj[],ll x)
 {
     visited[x]=true;
     for(auto it:adj[x])
     {
         if(!visited[it])
         dfs(adj,it);
     }
 }
 void dfs1(vector<ll>adj[],ll i)
 {
     visited[i]=1;
     ll x=a[i];
     if(!visited[x])
     dfs1(adj,x);
     else if(visited[x]==1)
     {
         ll p=x,mn=c[i];
         while(p!=i)
         {
             mn=min(mn,c[p]);
             p=a[p];

         }
         ans+=mn;
     }
     visited[i]=2;
     return;
 }
 void bfs(int s) {
	dp = vector<int>(n, INF);
	dp[s] = 0;

	queue<int> q;
	q.push(s);

	while (!q.empty()) {
		int v = q.front();
		q.pop();

		for (auto to : adj[v]) {
			if (dp[to] == INF) {
				dp[to] = dp[v] + 1;
				q.push(to);
			}
		}
	}
}

int main()
{
  fast;
  string s,t;
  cin>>s>>t;
 // cout<<s<<" "<<t;
  ll n=s.length();
  ll m=t.length();
  ll dp[n+1][m+1];
  for(ll i=0;i<n+1;i++)
  dp[i][0]=1;
  for(ll i=0;i<m+1;i++)
  dp[0][i]=1;
//   for(ll i=0;i<n+1;i++)
//   {
//       for(ll j=0;j<m+1;j++)
//       cout<<dp[i][j]<<" ";
//       cout<<"\n";
//   }
  ll ans=0;
  for(ll i=1;i<n+1;i++)
  {
      for(ll j=1;j<m+1;j++)
      {
          dp[i][j]=dp[i][j-1];
          if(s[i-1]==t[j-1])
          {
              dp[i][j]=(dp[i][j]+dp[i-1][j-1])%MOD;

          }

         // cout<<dp[i][j]<<" ";
      }
      ans=(ans+dp[i][m])%MOD;
  }
  cout<<(ans-n)%MOD;
  return 0;
}

#include <iostream>
using namespace std;

const long long mod=1000000007;
string s,t;
long long f[5001][5001];

int main()
{
    cin >> s >> t;
    int a=s.size(),b=t.size();
    long long sum=0;
    for(int o=a-1;o>=0;o--)
    {
        for(int i=b-1;i>=0;i--)
        {
            f[o][i]=f[o][i+1]+(s[o]==t[i])*(f[o+1][i+1]+1);
            if(f[o][i]>=mod) f[o][i]%=mod;
        }
        sum+=f[o][0];
        if(sum>=mod) sum%=mod;
    }
    cout << sum << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 5005, mod = 1000000000 + 7;

int dp[N][N];

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    string s, t;
    cin >> s >> t;

    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < t.size(); j++) {
            if (j > 0)
                dp[i][j] += dp[i][j - 1];

            if (s[i] == t[j]) {
                if (i == 0 || j == 0)
                    dp[i][j] += 1;
                else {
                    dp[i][j] += dp[i - 1][j - 1] + 1;
                    dp[i][j] %= mod;
                }
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < s.size(); i++)
        ans = (ans + dp[i][t.size() - 1]) % mod;

    printf("%lld\n", ans);
}

#include <string>
#include <iostream>

using namespace std;

const int MAXN = 5050;
const long long MOD = 1000000007;

long long dp[MAXN][MAXN];
string s, t;

int main() {
    int n, m;
    long long ans = 0;

    cin >> s >> t;
    n = s.length();
    m = t.length();
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (s[i] == t[j]) {
                ++dp[i][j];
                if (i > 0 && j > 0) {
                    dp[i][j] += dp[i - 1][j - 1];
                }
            }
            if (j > 0) {
                dp[i][j] += dp[i][j - 1];
            }
            dp[i][j] %= MOD;
        }
        ans += dp[i][m - 1];
    }
    cout << ans % MOD << endl;

    return 0;
}

#include <cstdio>

#include <unordered_map>
const int MOD1 = 1e9+7, MOD2=1e9+9;

#define MOD 1000000007

#define B 31

#define ll long long

//FILE *fin=fopen("a.in", "r"), *fout=fopen("a.out", "w");
#define fin stdin
#define fout stdout

#define MAXN 6000

std::unordered_map <ll, bool> mp;

int ap[100];
char s[MAXN+1], u[MAXN+1];
int dp[2][MAXN+1], sum[2][MAXN+1];

int main(){
    int n=0;
    char ch=fgetc(fin);
    while(ch!='\n'){
        s[++n]=ch;
        ch=fgetc(fin);
    }

    ch=fgetc(fin);
    int m=0;
    while(ch!='\n'){
        m++;
        u[m]=ch;
        ch=fgetc(fin);
    }

    int ans=0;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            if(s[i]==u[j]){
                dp[i&1][j]=1+sum[(i-1)&1][j-1];
                if(dp[i&1][j]>=MOD) dp[i&1][j]-=MOD;

                ans+=dp[i&1][j];
                if(ans>=MOD) ans-=MOD;
            }else dp[i&1][j]=0;
            sum[i&1][j]=dp[i&1][j]+sum[i&1][j-1];
            if(sum[i&1][j]>=MOD) sum[i&1][j]-=MOD;
        }
    }

    fprintf(fout, "%d\n", ans);

    fclose(fin);
    fclose(fout);
    return 0;
}

//ITNOG
#include<bits/stdc++.h>

using namespace std;
#define int long long

const int maxN = 5000 + 5;
const int mod = 1000*1000*1000 + 7;
int dp[maxN][maxN];
main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    string s, d; cin >> s >> d;
    for(int i = 0; i < s.size(); i ++)
    {
	  for(int j = 0; j < d.size(); j ++)
	  {
		//if(i == 1 && j == 1) cout << (i  << endl;
		if(s[i] == d[j]) dp[i][j] += ((i && j)  ? dp[i - 1][j - 1] + 1 : 1);
		if(j) dp[i][j] += dp[i][j - 1];
		dp[i][j] %= mod;
	  }
    }
    //for(int i = 0; i < s.size(); i ++)
//	  cout << dp[i][1] << ' '; cout << endl;
    int ans = 0;
    for(int i = 0; i < s.size(); i ++)
	  ans += dp[i][d.size() - 1];
    cout << ans % mod << endl;
    return 0;
}

#include <vector>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <cstdint>
#include <functional>
#include <array>
#include <valarray>
#include <iomanip>
#include <cassert>

using namespace std;
namespace mainns
{

template <typename T> int64_t sgn( T val )
{
    return ( T( 0 ) < val ) - ( val < T( 0 ) );
}

namespace
{
inline uint64_t gcdInternal( uint64_t a, uint64_t b )
{
    if ( b == 0 )
        return a;

    return gcdInternal( b, a % b );
}

inline uint64_t gcdDecompositionInternal( uint64_t a, uint64_t b, int64_t& x, int64_t& y )
{
    if ( b == 0 )
    {
        x = 1;
        y = 0;
        return a;
    }

    int64_t xx, yy;
    auto gcd = gcdDecompositionInternal( b, a % b, xx, yy );
    // ok, gcd = xx * b + (a % b) * yy = xx * b + (a - (a / b) * b) * yy =
    //         = b * (xx - (a / b) * yy) + a * yy
    x = yy;
    y = xx - ( a / b ) * yy;
    return gcd;
}

}

inline uint64_t greatestCommonDivisor( int64_t a, int64_t b )
{
    a *= sgn( a );
    b *= sgn( b );
    if ( a < b )
        std::swap( a, b );
    return gcdInternal( a, b );
}

inline uint64_t gcdDecomposition( int64_t a, int64_t b, int64_t& x, int64_t& y )
{
    auto aUnsigned = a * sgn( a );
    auto bUnsigned = b * sgn( b );
    auto gcd = ( aUnsigned < bUnsigned ) ? gcdDecompositionInternal( aUnsigned, bUnsigned, x, y ) : gcdDecompositionInternal( bUnsigned, aUnsigned, y, x );
    x *= sgn( a );
    y *= sgn( b );
    return gcd;
}

template<typename UnderlyingInt, UnderlyingInt MOD>
class Residue
{
public:
    Residue(UnderlyingInt from = 0)
    {
        UnderlyingInt remainder = from % MOD;
        if ( remainder < 0 )
            remainder += MOD;
        rep_ = remainder;
    }

    bool operator==(Residue<UnderlyingInt, MOD> other) const { return rep_ == other.rep_; }

    Residue<UnderlyingInt, MOD> operator++(int)    { return *this = Residue(rep_ + 1); }
    Residue<UnderlyingInt, MOD> operator++()    { return *this = Residue(rep_ + 1); }
    Residue<UnderlyingInt, MOD> operator--(int)    { return *this = Residue(rep_ - 1); }
    Residue<UnderlyingInt, MOD> operator--()    { return *this = Residue(rep_ - 1); }

    Residue<UnderlyingInt, MOD> operator+=(Residue<UnderlyingInt, MOD> v)    { return *this = Residue(rep_ + v.rep()); }
    Residue<UnderlyingInt, MOD> operator-=(Residue<UnderlyingInt, MOD> v)    { return *this = Residue(rep_ - v.rep()); }
    Residue<UnderlyingInt, MOD> operator*=(Residue<UnderlyingInt, MOD> v)    { return *this = Residue(rep_ * v.rep()); }

    Residue<UnderlyingInt, MOD> inversed() const
    {
        int64_t x, y;
        auto gcd = gcdDecomposition( rep_, MOD, x, y );
        assert( gcd == 1 );
        return{ x };
    }

    UnderlyingInt rep() const { return rep_; }

private:
    UnderlyingInt rep_;
};

template<typename UnderlyingInt, UnderlyingInt MOD>
Residue<UnderlyingInt, MOD> operator+(Residue<UnderlyingInt, MOD> a, Residue<UnderlyingInt, MOD> b) { return a += b; }

template<typename UnderlyingInt, UnderlyingInt MOD>
Residue<UnderlyingInt, MOD> operator-(Residue<UnderlyingInt, MOD> a, Residue<UnderlyingInt, MOD> b) { return a -= b; }

template<typename UnderlyingInt, UnderlyingInt MOD>
Residue<UnderlyingInt, MOD> operator*(Residue<UnderlyingInt, MOD> a, Residue<UnderlyingInt, MOD> b) { return a *= b; }

template<typename UnderlyingInt, UnderlyingInt MOD>
Residue<UnderlyingInt, MOD> operator+(Residue<UnderlyingInt, MOD> a, UnderlyingInt b) { return a += b; }

template<typename UnderlyingInt, UnderlyingInt MOD>
Residue<UnderlyingInt, MOD> operator-(Residue<UnderlyingInt, MOD> a, UnderlyingInt b) { return a -= b; }

template<typename UnderlyingInt, UnderlyingInt MOD>
Residue<UnderlyingInt, MOD> operator*(Residue<UnderlyingInt, MOD> a, UnderlyingInt b) { return a *= b; }

template<typename UnderlyingInt, UnderlyingInt MOD>
std::ostream& operator<<(std::ostream& outStream, Residue<UnderlyingInt, MOD> a) { return outStream << a.rep(); }

using CodeforcesResidue = Residue<int, 1000000007>;

using CodeforcesResidue64 = Residue<int64_t, 1000000007>;

class Solver163A
{
public:
    void run();
};

void Solver163A::run()
{
    string str, seq;
    cin >> str >> seq;
    vector<vector<CodeforcesResidue>> ans(2, vector<CodeforcesResidue>(seq.length() + 1));
    vector<vector<CodeforcesResidue>> ansForSuffixSubstrings(2, vector<CodeforcesResidue>(seq.length() + 1));
    for (int i = 1; i <= str.length(); ++i)
        for (int j = 1; j <= seq.length(); ++j)
        {
            auto currI = i % 2;
            auto prevI = (i - 1) % 2;

            ansForSuffixSubstrings[currI][j] = ansForSuffixSubstrings[currI][j - 1];
            if (str[i - 1] == seq[j - 1])
                ansForSuffixSubstrings[currI][j] += ansForSuffixSubstrings[prevI][j - 1] + 1;

            ans[currI][j] = ans[prevI][j] + ans[currI][j - 1] - ans[prevI][j - 1];
            if (str[i - 1] == seq[j - 1])
                ans[currI][j] += ansForSuffixSubstrings[prevI][j - 1] + 1;
        }

    cout << ans[str.length() % 2][seq.length()];
}

} //namespace mainns
using CurrentSolver = mainns::Solver163A;
#ifdef ONLINE_JUDGE
int main()
#else
int main2()
#endif
{
    ios::sync_with_stdio( false );
    CurrentSolver().run();
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007

using namespace std;
const int maxn = 5e3 + 10;
string s,d;
ll dp[maxn][maxn];

int main(){
	cin >> s >> d;
	int n = s.size();
	int x = d.size();
	for(int i = 0 ; i < x ; i++){
		dp[i][0] = 0;
	}
	for(int j = 0 ; j < n ; j++){
		dp[0][j] = 0;
	}
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < x ; j++){
			if(s[i] == d[j]){
				dp[i+1][j+1] = (dp[i][j] + 1 + dp[i+1][j]) % mod;
			}
			else{
				dp[i+1][j+1] = dp[i+1][j] % mod;
			}
		}
	}
	ll ans = 0;
	for(int i = 1 ; i <= n ; i++){
		ans = (ans + dp[i][x])%mod;
	}
	cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
}
ll ebob(ll a, ll b){
	if(!a)return b;
	return ebob(b%a, a);
}
ll ekok(ll a, ll b){
	return (a*b)/ebob(a, b);
}
double fonk(double x, double y){
	return x*x + y*y;
}
vector<vector<int>> dp(5001, vector<int>(5001, 0));
vector<vector<int>> cnt = dp;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	string a, b; cin>>a>>b;
	int n = a.size(), m = b.size();
	ll res = 0;
	for(int i = 0; i < n; i++){
		bool c = 0;
		for(int j = 0; j < m; j++){
			if(a[i] == b[j]){
				dp[i][j]++;
				c = 1;
				dp[i][j] = (dp[i][j] + cnt[i][j]) % mod;
			}
			cnt[i+1][j+1] = dp[i][j];
			dp[i][j+1] = dp[i][j];
		}
		res += c*dp[i][m-1];
		res %= mod;
	}
	cout<<res<<endl;
}

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>

#if LOCAL
	#define DO_NOT_SEND
#endif

typedef long long LL;

int IntMaxVal = (int) 1e20;
int IntMinVal = (int) -1e20;
LL LongMaxVal = (LL) 1e20;
LL LongMinVal = (LL) -1e20;

#define FOR(i, a, b) for(int i = a; i < b ; ++i)
#define FORD(i, a, b) for(int i = a; i >= b; --i)

#define minimize(a, b) { a = min(a, b); }
#define maximize(a, b) { a = max(a, b); }

#define all(v) v.begin(),v.end()

using namespace std;

template<typename T> struct argument_type;
template<typename T, typename U> struct argument_type<T(U)> { typedef U type; };
#define next(t, i) argument_type<void(t)>::type i; cin >> i;
#define nextVector(t, v, size) vector< argument_type<void(t)>::type > v(size); { for (int i = 0 ; i < size ; i++) cin >> v[i]; }

#define range(name, start, count) vector<int> name(count); { for (int i = 0 ; i < count ; i++) name[i] = i + start; }

template <typename T1, typename T2> istream& operator >>(istream& is, pair<T1, T2>& s) { is >> s.first >> s.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T> &v) { for (int i = 0 ; i < v.size() ; i++) os << v[i] << ' '; os << endl; return os; }
template <typename T1, typename T2> ostream& operator <<(ostream& s, pair<T1, T2>& t) { s << t.first << ' ' << t.second; return s; }

template <typename T> vector<T> readVector(int n) { vector<T> res(n); for (int i = 0 ; i < n ; i++) cin >> res[i]; return res; }

int main() {
	srand (time(NULL));
    ios_base::sync_with_stdio(false); cin.tie(NULL);

	next(string, s1);
	next(string, s2);

	int n = s1.length();
	int m = s2.length();

	LL res = 0;
	const int mod = 1000000007;
	vector<LL> startFrom(m);

	FORD (i, n - 1, 0) {
		vector<LL> startFromNext(m);
		FORD (j, m - 1, 0) if (s1[i] == s2[j]) {
			startFromNext[j]++;
			if (startFromNext[j] >= mod) startFromNext[j] -= mod;
			if (i < n - 1 && j < m - 1) {
				startFromNext[j] += startFrom[j + 1];
				if (startFromNext[j] >= mod) startFromNext[j] -= mod;
			}
		}

		auto curVal = accumulate(all(startFromNext), 0LL);
		res += curVal;
		res %= 1000000007;
		swap(startFrom, startFromNext);
		FORD (j, m - 2, 0) {
			startFrom[j] += startFrom[j + 1];
			if (startFrom[j] >= mod) startFrom[j] -= mod;
		}
	}

	cout << res;
}

#include <stdio.h>
#include <iostream>
#include <memory.h>
#include <assert.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <math.h>

#define fo(a,b,c) for( a = ( b ); a < ( c ); ++ a )
#define fr(a,b) fo( a, 0, ( b ) )
#define fi(a) fr( i, ( a ) )
#define fj(a) fr( j, ( a ) )
#define fk(a) fr( k, ( a ) )
#define mp make_pair
#define pb push_back
#define all(v) (v).begin( ), (v).end( )
#define _(a,b) memset( a, b, sizeof( a ) )
using namespace std;
int ni() { int a; scanf( "%d", &a ); return a; }
double nf() { double a; scanf( "%lf", &a ); return a; }
char sbuf[100005]; string ns() { scanf( "%s", sbuf ); return sbuf; }
long long nll() { long long a; scanf( "%lld", &a ); return a; }

template <class T> void out( T a, T b ) { bool first = true; for( T i = a; i != b; ++ i ) { if( !first ) printf( " " ); first = false; cout << * i; } printf( "\n" ); }
template <class T> void outl( T a, T b ) { for( T i = a; i != b; ++ i ) { cout << * i << "\n"; } }
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef map<string,int> msi;

int n, m;
int ans; int d[5005];
const int mod = 1000000007;

int main( )
{
    int i, j, k;

    string s = ns(); string t = ns();

    fi(t.size())
    {
        for(j = s.size() - 1; j >= 0; -- j)
        {
            if (s[j] == t[i])
            {
                int nv = 1;
                if (j) nv += d[j - 1];
                nv %= mod;
                ans += nv;
                ans %= mod;
                d[j] += nv;
                d[j] %= mod;
            }
        }
    }
    printf("%d\n", ans % mod);

    return 0;
}

#include <cstdio>
#include <cstring>

const int Modulo = 1000000007;

int N, M;
char S[6000], T[6000];
int DP[5010][5010], Sum[5010];

int main()
{
	scanf("%s%s", S, T);
	N = strlen(S);
	M = strlen(T);

	for (int i = 0; i < N; i ++)
	{
		for (int j = 0; j < M; j ++)
			if (S[i] == T[j])
			{
				DP[i][j] += Sum[j] + 1;
				if (DP[i][j] >= Modulo)
					DP[i][j] -= Modulo;
			}
		Sum[0] = 0;
		for (int j = 1; j < M; j ++)
		{
			Sum[j] = Sum[j - 1] + DP[i][j - 1];
			if (Sum[j] >= Modulo)
				Sum[j] -= Modulo;
		}
	}
	int Ans = 0;
	for (int i = 0; i < N; i ++)
		for (int j = 0; j < M; j ++)
		{
			Ans += DP[i][j];
			if (Ans >= Modulo)
				Ans -= Modulo;
		}
	printf("%d\n", Ans);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int > pp;

int const N=4e5+10,oo=1e9;
int mod=oo+7;
ll const OO=3e18;

int n,m;
char s[5001],t[5001];
int dp[5001][5001];

int rec(int i,int j){
    int &ret=dp[i][j];
    if(ret!=-1)return ret;
    if(i==n)return ret=0;
    if(j==m)return ret=0;
    ret=rec(i,j+1);
    if(s[i]==t[j]){
    //    cout<<i<<' '<<j<<endl;
        ret+=rec(i+1,j+1)+1;
        ret%=mod;
    }
    return ret;
}

int main() {
/*    ios::sync_with_stdio(0);
    cin.tie(0);*/
    scanf("%s",s);
    scanf("%s",t);
    n=strlen(s);
    m=strlen(t);
    int an=0;
    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++){
   //     cout<<i<<endl;
        an+=rec(i,0);
        an%=mod;
    }
    printf("%d\n",an);
    return 0;
}

#include<stdio.h>
#include<string.h>

int dp[10000],dp1[10000];
const int mod=1000000007;
char s1[10000],s2[10000];

int get(int len1,int len2)
{
	int i,j;
	long long ans=0;

	for(i=0;i<len1;i++)
	{
		memset(dp1,0,sizeof(dp1));
		for(j=0;j<len2;j++)if(s1[i]-s2[j])
			dp1[j]=(j?dp1[j-1]:0),dp1[j]%=mod;
		else
			dp1[j]=(j?dp1[j-1]+1+dp[j-1]:1),dp1[j]%=mod;
		memcpy(dp,dp1,sizeof(dp));
		ans+=dp[len2-1];ans%=mod;
	}
	return ans;
}

int main()
{
	scanf("%s%s",s1,s2);
	int i,j,len,cnt=0;

	printf("%d\n",get(strlen(s1),strlen(s2)));
}

/*
                        ********************
			**  MANAN DIYORA  **
			**    DA-IICT     **
			**   diyora13     **
			********************
*/
#include <bits/stdc++.h>
using namespace std;

//#include <time.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define setpre(x,d) fixed<<setprecision(d)<<x
#define fill(a,x) memset(a,x,sizeof(a));
#define inarr(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define outarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define maxa(a,n) *max_element(a,a+n)
#define mina(a,n) *min_element(a,a+n)
#define fr(i,s,e) for(ll i=s;i<e;i++)
#define rf(i,s,e) for(ll i=s-1;i>=e;i--)
#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define deb4(x,y,z,w) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<"\t"<<#w<<" : "<<w<<endl;
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz size()
#define len length()
#define all(v) v.begin(),v.end()
#define PI 3.141592653589793
#define MOD 1000000007
#define NN (const int)5e5+10

typedef long long int ll;
typedef long double lld;
typedef pair<long long,long long> pll;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;

// bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) { return (a.second < b.second); }
// void fileio()	{	freopen("input.txt","r",stdin);	freopen("output.txt","w",stdout);	}
//	vll fact(NN),invfact(NN);
//	void EE(ll a,ll b,ll &x,ll &y) {	if(b==0) {	x=1,y=0; return ;	}		EE(b,a%b,x,y);	ll temp=x; x=y; y=temp-(a/b)*y;	}
//	ll inverse(ll a,ll mod) 	{	ll x,y;	EE(a,mod,x,y);	return (x+mod)%mod;	}
//	void build() { fact[0]=1; fr(i,1,NN) fact[i]=(fact[i-1]*i)%MOD;	invfact[NN-1]=inverse(fact[NN-1],MOD); rf(i,NN-1,0) invfact[i]=(invfact[i+1]*(i+1))%MOD; }
//	ll ncr(ll n,ll r)       	{	if(n<0 || r<0 || r>n) return 0;	return (fact[n]*((invfact[n-r]*invfact[r])%MOD))%MOD;	}
//	ll choose(ll n,ll k) 	  	{	if(k==0)  return 1; return (n* choose(n-1,k-1))/k;	}
ll logy(ll x,ll y)	{	return ceil((lld)(log(x)/log(y)));	}
ll powe(ll a,ll b)	{	ll re=1;	while(b){	if(b&1) re=(re*a);	a=(a*a);	b=b>>1;}	return re;	}

bool flag=0,flag1=0,flag2=0;
string s,t;
ll dp[5005][5005],n,m;

ll sol(ll id1,ll id2)
{
	if(id1<0 || id2<0) return 0;
	if(dp[id1][id2]!=-1) return dp[id1][id2];
	ll ans=0;
	if(s[id1]==t[id2]) ans=(1+sol(id1-1,id2-1))%MOD;
	ans=(ans+sol(id1,id2-1))%MOD;

	return dp[id1][id2]=ans;
}

int main()
{
	IOS
	ll tt=1;
//	   cin>>tt;

	while(tt--)
	{
		cin>>s>>t;
		n=s.len; m=t.len;
		fill(dp,-1);
		ll ans=0;
		fr(i,0,n) ans=(ans+sol(i,m-1))%MOD;
		cout<<ans;
	}
	return 0;
}

#include <cstdio>
#include <cstring>

const int MAXN = 5010;
const int MODD = 1000000007;

char s[MAXN], t[MAXN];
int n, m, ans, dp[MAXN][MAXN];

int main() {
	while (scanf("%s%s", s, t) != EOF) {
		n = strlen(s);
		m = strlen(t);
		for (int i = 0; i <= n; ++i)
			memset(dp[i], 0, sizeof(int) * (m + 1));
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= m; ++j) {
				dp[i][j] = dp[i][j - 1];
				if (s[i - 1] == t[j - 1]) {
					dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % MODD;
				}
			}
		}
		ans = 0;
		for (int i = 1; i <= n; ++i)
			ans = (ans + dp[i][m]) % MODD;
		printf("%d\n", ans);
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	char ch=getchar();
	int x=0,f=1;
	while(ch<'0'||ch>'9')
	{
	   if(ch=='-') f=-1;
	   ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
	   x=x*10+ch-'0';
	   ch=getchar();
	}
	return x*f;
}
char a[10001],b[10001];
int len,len2;
int dp[5001][5001];
const int mod=1e9+7;
int ans;
/*
dp[i][j]��ʾ�Ե�һ���ַ��� ��i��β���ڶ����ַ�����j��β�ķ�����
*/
int main()
{
	scanf("%s",a+1);
	scanf("%s",b+1);
	len=strlen(a+1);
	len2=strlen(b+1);
	for(int i=1;i<=len;i++)
	{
		for(int j=1;j<=len2;j++)
		{
			dp[i][j]=dp[i][j-1];
			if(a[i]==b[j])
			{
				dp[i][j]+=dp[i-1][j-1]+1;
				dp[i][j]%=mod;
			}
		}
		ans=(ans+dp[i][len2])%mod;
	}
	printf("%d",ans);
	return 0;
}

#include <bits/stdc++.h>
/*
dp[i][j]表示子串s[...i]匹配t[1...j]中的子序列的方案数。
转移枚举t[1...j]匹配s[i]的情况 这样复杂度O(n^3)。
利用前缀和优化位O(n^2)。
*/
using namespace std;
const int maxn = 5000 + 7, mod = 1e9 + 7;
typedef long long ll;
char s[maxn], t[maxn];
int dp[2][maxn], res[maxn];
void add(int &x, int y){
    if((x += y) >= mod) x -= mod;
}
int main(){
    scanf("%s%s", s + 1, t + 1);
    int n = strlen(s + 1), m = strlen(t + 1);
    int ans = 0;
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= m; ++j){
            dp[i & 1][j] = 0;
            res[j] = res[j - 1];
            if(s[i] == t[j]) add(res[j], dp[(i - 1) & 1][j - 1] + 1);
            add(dp[i & 1][j], res[j]);
        }
        //for(int j = 1; j <= m; ++j) printf("%d%c", dp[i & 1][j], j == m ? '\n' : ' ');
        add(ans, dp[i & 1][m]);
    }
    printf("%d\n", ans);
    return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
//#include<bits/stdc++.h>
using namespace std;
long long l1,l2,dp[5100][5100],mod=1e9+7;
int main()
{
	string x,y;
//	scanf("%s%s",x+1,y+1);
	cin>>x>>y;
	l1=x.length();
	l2=y.length();
	for(int i=0;i<l1;i++)
	{
		for(int j=0;j<l2;j++)
		{
//			dp[i][j]%=mod;
//			dp[i+1][j+1]=dp[i+1][j];
//			if(x[i]==y[i])
//			dp[i+1][j+1]+=dp[i][j]+1;
			dp[i+1][j+1]=(dp[i+1][j]+(x[i]==y[j])*(dp[i][j]+1))%mod;//神马情况！！！！！！！！！！
		}
	}
	long long ans=0;
	for(int i=1;i<=l1;i++)
	{
		ans+=dp[i][l2];
		ans%=mod;
//		cout<<dp[i][l2]<<' ';
	}
	cout<<ans;
	return 0;
}

#include<cstdio>
#include<cstring>
#define inf 1000000007
int len1,len2;
char s1[5100],s2[5100];
int p[5100][5100],d[5100][5100];
int main()
{
    scanf("%s %s",&s1[1],&s2[1]);
    len1=strlen(&s1[1]); len2=strlen(&s2[1]);
    memset(p,0,sizeof(p));
    memset(d,0,sizeof(d));
    int ans=0;
    for(int i=1;i<=len1;++i)
    {
        int tmp=0;
        for(int j=1;j<=len2;++j)
        {
            if(s1[i]==s2[j])
                p[i][j]=tmp+1;
            ans=(ans+p[i][j])%inf;
            tmp=(tmp+p[i-1][j])%inf;
        }
    }
    printf("%d\n",ans);
    return 0;
}

/*
***************************************************************************************************************

                            Author : Yash Sadhwani

**************************************************************************************************************
*/
#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include<deque>
#include<map>
#include<set>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<stack>
#include<functional>
using namespace std;
#define ll long long
#define si(x) scanf("%d",&x)
#define sd(x) scanf("%lf",&x)
#define sc(x) scanf("%c",&x)
#define ss(x) scanf("%s",x)
#define vl vector<ll>
#define vi vector<int>
#define vvl vector< vl >
#define vvi vector< vi >
#define pb push_back
#define mod 1000000007
#define mem(x,y) memset(x,y,sizeof(x))
#define f(i,a,b) for(int i=(a);i<(b);i++)
#define max_int_value 2147483647
#define max_long_value 9223372036854775807

//qsort(ww,cc,sizeof(tp),compare);
/*int compare(const void *a,const void *b){
    ll y=((((tp*)a)->w)-(((tp*)b)->w));
    if(y>0)return 1;
    else if(y==0)return 0;
    else return -1;
}
bool way(ii x,ii y){
    return x.first<y.first or x.first==y.first and x.second<y.second;
}
*/

#define MAXN 5010
#define ls (node<<1)
#define rs ((node<<1)+1)
#define ii pair<int,int>

ll dp[MAXN][MAXN];

int l1,l2;

char aa[MAXN],bb[MAXN];

inline void ReadInput(void){
    ss(aa); ss(bb);
}

inline void solve(void){
    l1=strlen(aa); l2=strlen(bb);
    for(int i=1;i<=l1;i++){
        for(int j=1;j<=l2;j++){
            if(aa[i-1]==bb[j-1])dp[i][j]=dp[i-1][j-1]+dp[i][j-1]+1;
            else dp[i][j]=dp[i][j-1];
            dp[i][j]%=mod;
        }
    }
    ll ans=0;
    for(int i=1;i<=l1;i++){
        ans+=dp[i][l2];
        ans%=mod;
    }
    cout<<ans;
}

inline void Refresh(void){

}

int main()
{
    ReadInput();
    solve();
    return 0;
}

//JAI SHREE RAM
//JAI BAJRANGBALI

#include <bits/stdc++.h>
using namespace std;
#define ll  long long int

#define     max(a,b)    ((a>b)?(a):(b))
#define     min(a,b)    ((a<b)?(a):(b))
#define     MAXN        10000005
#define     mod         1000000007
#define     pb          push_back
#define     fast        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define     test(a)        cout<<"testing "<< a <<endl;

  string s;
  string t;

ll  dp[5001][5001];

ll helper( ll i , ll j ){

  if( i == s.length() ) return 0;

  if( j == t.length() ) return 0;

  if( dp[i][j] !=-1){
    return dp[i][j] ;
  }

  ll a= helper( i , j+1);

  if( s[i] == t[j] ){
    a += ( 1 + helper( i+1 , j+1) );

  }

  return dp[i][j] = a%mod;

}

void solve(){
  cin >> s>> t;

  for( int i=0;i<=5000;i++){
    for( int j=0;j<=5000;j++){
      dp[i][j] =-1;
    }
  }

  ll ans =  0;
  for( int i=0;i<s.length() ;i++){
    ans += helper( i,0);
    ans = ans%mod;
  }
  cout<< ans <<endl;

}

int main() {
   fast;

    ll t=1;
//   cin >> t;

    while(  t>0){

     solve();

        t--;
    }

}

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdarg>
#include <cassert>
#include <cstring>
#include <complex>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef long long LL;
typedef long double LD;

#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define y1 y1_gedjcdgfce
#define y0 y0_sadasdasdsa
#define ws ws_sadsadsada
#define left left_asdsadsadsadsa
#define right right_asdasdsadasda

#ifdef DEBUG
#define eprintf(...) {fprintf(stderr,__VA_ARGS__),fflush(stderr);}
#else
#define eprintf(...) {}
#endif

#define forn(i,n) for( int i = 0 ; i < (n) ; i++ )
#define forit(it,c) for( __typeof((c).begin()) it = (c).begin() ; it != (c).end() ; it++ )

#ifdef WIN32
#define INT64 "%I64d"
#else
#define INT64 "%lld"
#endif

#define TASK "task"
const int maxn = 5012;
const int mode = (int)1e9+7;

int dp[2][maxn];
char s[maxn];
char t[maxn];

inline int add(int a,int b) {
	if((a+=b)>=mode) a -= mode;
	return a;
}

int main(){
	#ifdef DEBUG
	assert(freopen(TASK".in","rt",stdin));
	//assert(freopen(TASK".out","wt",stdout));
	#endif
	scanf("%s",s);
	scanf("%s",t);
	int n = strlen(s);
	int m = strlen(t);
	memset(dp, 0, sizeof dp);
	int b = 0;
	int res = 0;
	for(int i = 0 ; i < n ; i++ ) {
		forn(j,m+1) dp[!b][j] = 0;
		dp[b][0] = 1;
		forn(j,m) {
			dp[b][j+1] = add(dp[b][j],dp[b][j+1]);
			if(s[i]==t[j]){
				res = add(res,dp[b][j]);
				dp[!b][j+1] = add(dp[b][j],dp[!b][j+1]);
			}
		}
		b = b^1;
	}
	printf("%d\n",res);
	return 0;
}

#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <utility>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <ctime>
#include <queue>
#include <cmath>
#include <deque>
#include <list>
#include <sstream>
#include <bitset>
#include <complex>
#pragma comment(linker, "/STACK:16777216")
#pragma warning(default :4)
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define eps 1e-9
#define INF 1000000001
#define oo 1000000001
#define MOD 1000000007
#define cint const int &
#define cll const ll &
#define cull const ull &
#define FOR(i, x) for (int i = 0; i < (int)(x); ++i)
#define CL(x) memset(x, 0, sizeof(x))
#define SVAL(x, y) memset(x, y, sizeof(x))
#define FIN freopen("in.txt", "r", stdin);
#define FOUT freopen("out.txt", "w", stdout);
#define y1 Y1
//int i, j, k;
using namespace std;
typedef vector<int> VINT;
typedef pair<int, int> PII;
typedef complex<double> Cn;
/////////////////////////////////////////////////////

char s[5555], t[5555];
int nr[5555], r[5555], ans;
int main()
{
    gets(s);
    gets(t);
    int n=strlen(s), m=strlen(t);
    reverse(t, t+m);
    FOR(j, m)
    {
        memcpy(nr, r, sizeof(r));
        FOR(i, n)
            if (s[i]==t[j])
            {
                nr[i]+=1+r[i+1];
                ans+=1+r[i+1];
                ans%=MOD;
                nr[i]%=MOD;
            }
        swap(r, nr);
    }
    printf("%d\n", ans);
    return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#include <iostream>
#include <queue>
#include <ctime>
#pragma comment(linker, "/STACK:16777216")
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int , int> pii;
typedef vector <int> vi;
typedef vector <pii> vii;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin() , (x).end()
#define forit(it, v) for (it = (v).begin(); it != (v).end(); ++it)
#define forn(i, n) for (int i = 0; i < ((int)(n)); ++i)
#define forab(i, a, b) for (int i = (int)(a); i < ((int)(b)); ++i)
#define y0 y123456789
#define y1 y234895
#define hash hash123456789
#define rank rank123456789
#define sz(x) ((int) (x).size() )
#define re return
#define sqr(x) ((x) * (x))

const double pi = 3.141592653589793238462;
const int nmax = 200000;
const int hash_base = 119;
const long long inf = 2e18;

string s , t;
int dp[6000][6000];
int ans = 0 , mod = 1000000007;

int main()
{
cin >> s >> t;
for (int i = 1 ; i <= s.size() ; i ++ )
    for (int j = 1 ; j <= t.size() ; j ++ )
    {
            dp[i][j] = dp[i][j - 1];
        if ( s[i - 1] == t[j - 1] )
            dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % mod;
    };
for (int i = 1 ; i <= s.size() ; i ++ )
    ans = (ans + dp[i][t.size()]) % mod;
cout << ans << endl;
return 0;
}

#include <iostream>
#include <cstring>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <stack>
#include <queue>
#include <ctime>
#include <vector>
#include <map>
#include <set>
#include <utility>

using namespace std;

#define FORALL(i,a,b) for (int i = (a); i <= (b); i++)
#define FOR(i,n) for (int i=0;i<n;i++)
#define pb push_back
#define in cin
#define out cout
#define dout if(true) cout

#define PRIME 1000000007
typedef long long ll;

#define MAXN 5010
#define MAXM MAXN

int smemo[MAXN][MAXM][2];

int main()
{
	string A,B;
	in >> A >> B;

	int N = A.length();
	int M = B.length();

	A = "0" + A;
	B = "0" + B;

	smemo[0][0][1] = smemo[0][0][0] = 1;
	FORALL(i,1,N) {smemo[i][0][0] = 1; smemo[i][0][1] = 0;}
	FORALL(j,1,M) {smemo[0][j][1] = 0; smemo[0][j][0] = 1;}

	FORALL(i,1,N) FORALL(j,1,M){
		//cout << i << " " << j << " " << A[i] << " " << B[j];

		ll ans1 = 0;
		//smemo[i][j][1] = 0;
		if (B[j] == A[i]){
			ans1 += (ll)smemo[i-1][j-1][0];
			//cout << "hello" << smemo[i-1][j-1][1] << endl ;
		}
		ans1 %= PRIME;
		smemo[i][j][1] = ans1;
		ll ans2 = ((ll)smemo[i][j][1] + (ll)smemo[i][j-1][0]) %PRIME;
		smemo[i][j][0] = ans2;
		//cout << smemo[i][j][1] << endl;
	}

	ll ans = 0;
	FORALL(i,1,N) FORALL(j,1,M){
		//cout << i << " " << smemo[i][M][1] << endl;
		ans += (ll)smemo[i][j][1];
		ans %= PRIME;
	}
	cout << ans << endl;
}

#include <iostream>
#include <cstdlib>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <vector>
#include <string>

#define For(i,a,n) for(int i = a ; i < n ; ++i )
#define n(x) (int)x.size()
#define pb(i) push_back(i)
#define all(x) x.begin(),x.end()
#define feach(i,a) for(typeof (a.begin()) i =  a.begin() ; i!=a.end() ; ++i)

using namespace std;
const int maxn = 5010;
typedef unsigned long long ull;
ull ans;
const ull mod = 1000*1000*1000+7;
ull d[maxn];
ull d2[maxn];
string s1 , s2;
int n , m;

void findans()
{
	For(i,0,m)
	{
		For(j,0,n)
			if(s2[i] == s1[j])
			{
				d2[j+1]+=d[j]+1;
				d2[j+1]%=mod;
			}
		For(j,1,n+1)
		{
			d[j]+=d2[j];
			d[j] = d[j]%mod;
			ans=(ans+d2[j])%mod;
			d2[j] = 0;
		}
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s1 >> s2;
	n = n(s1);
	m = n(s2);
	findans();
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int MAX=5007,N=5,MOD=(1e9)+7;
int d[MAX][MAX],sum[MAX][MAX];
unsigned long long int ans;
string x,s;
int main()
{
	cin>>s>>x;
	for(int i=1;i<=s.size();i++)
	{
		for(int j=1;j<=x.size();j++)
		{
			if(s[i-1]==x[j-1])
			{
				d[i][j]+=sum[i-1][j-1];
				d[i][j]++;
			}
			sum[i][j]=(sum[i][j-1]+d[i][j])%MOD;
			ans+=d[i][j];
		}
	}
	cout<<ans%MOD<<"\n";
}

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pll pair<long long, long long>
#define f first
#define s second
#define debug cout<<"here\n"
#define MOD 1000000007

using namespace std;

void solve(){
	string s,t; cin>>s>>t;
	int n = s.length(), m = t.length();

	std::vector<ll> freq(m,0);
	ll ans = 0;
	char curr, prev = '#';
	for(int i=0; i<n; i++){
		ll res = 0;
		curr = s[i];
		for(int j=0; j<m; j++){
			if(t[j] == curr && curr == prev){
				ans += res; if(ans >= MOD) ans -= MOD;
				ans++; if(ans >= MOD) ans -= MOD;
				ll tmp = res;
				res += freq[j]; if(res >= MOD) res -= MOD;
				freq[j] = tmp; if(freq[j] >= MOD) freq[j] -= MOD;
				freq[j]++; if(freq[j] >= MOD) freq[j] -= MOD;
				continue;
			}
			if(t[j] == curr){
				ans += res; if(ans >= MOD) ans -= MOD;
				ans++; if(ans >= MOD) ans -= MOD;
				freq[j] = res; if(freq[j] >= MOD) freq[j] -= MOD;
				freq[j]++; if(freq[j] >= MOD) freq[j] -= MOD;
			}
			if(t[j] == prev){
				res += freq[j];
				if(res >= MOD) res -= MOD;
			}
			if(t[j] != curr) freq[j] = 0;
		}
		prev = curr;
	}
	cout<<ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cout.tie(0); cin.tie(0);
	cout<<fixed<<setprecision(12);

	int t =1; //cin>>t;
	for(int i=1; i<= t; i++){
		solve();
		cout<<"\n";
	}

	return 0;
}

#include <iostream>
#include <stdio.h>
#include <string.h>
#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;
int dp[5001][5001];
string s,t;

int subSeq(int i,int j){
    if(i>=s.length()||j>=t.length()){
        return 0;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    return dp[i][j]=(subSeq(i,j+1)+(s[i]==t[j])%1000000007*(subSeq(i+1,j+1)+1)%1000000007)%1000000007;
}
int main()
{
    cin>>s>>t;
    long long sum=0;
    memset(dp, -1, sizeof(dp));
    for(int i=0;i<s.length();i++){
        sum+=subSeq(i,0);
    }
    cout<<sum%1000000007;
}

#include <iostream>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
int sd[5001][5001];
main() {
	string s, t; cin >> s >> t;
	long long res = 0;
	for (int i = s.size() - 1; i >= 0; i--) for (int j = t.size() - 1; j >= 0; j--)
		sd[i][j] = ((long long)sd[i][j + 1] + (s[i] == t[j] ? 1 + sd[i + 1][j + 1] : 0) % mod) % mod;
	for (int i = 0; i < s.size(); i++) res = (res + sd[i][0]) % mod;
	cout << res;
}

#include<iostream>
#include<fstream>
#include<string.h>
#define lint long long int
#define MOD	1000000007
#define wait system("pause")
using namespace std;

int main(){
	char s1[5005],s2[5005];
	cin>>s1>>s2;
	lint res=0,i,j,m=strlen(s1),n=strlen(s2),DP[5005]={0};
	for( i=1;i<=n;i++ )		//s2
		for( j=m;j>=1;j-- )	//s1
			if( s1[j-1]==s2[i-1] ){
				DP[j]+=DP[j-1]+1;
				if(DP[j]>=MOD)
					DP[j]%=MOD;
			}
	for(j=1;j<=m;j++){
		res+=DP[j];
		if(res>=MOD)
			res%=MOD;
	}
	cout<<res<<endl;
//	wait;
}

#include<iostream>
using namespace std;
long long mod=1000000007,sd[5001][5001],res;
main() {
	string s,t; cin>>s>>t;
	for(int i=s.size()-1;i>=0;i--) for(int j=t.size()-1;j>=0;j--)
		sd[i][j]=(sd[i][j+1]+(s[i]==t[j]?1+sd[i + 1][j + 1]:0))%mod;
	for(int i=0;i<s.size();i++) res=(res+sd[i][0])%mod;
	cout<<res;
}

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cstdlib>
using namespace std ;
#define MaxN 5009
#define MOD 1000000007
string s1 , s2 ;
long long DP[MaxN][MaxN] ;
long long g[MaxN] ;
int	main()
{
	cin >> s1 >> s2 ;
    int l1 = s1.size() , l2 = s2.size() ;
	long long ans = 0;
	for (int i=1; i<=l1; i++)
    {
		for (int j=1; j<=l2; j++) g[j] = (g[j-1]+DP[i-1][j])%MOD;
		for (int j=1; j<=l2; j++)
        {
			if (s1[i-1]==s2[j-1]) DP[i][j] = (g[j-1]+1)%MOD;
			ans=(ans+DP[i][j])%MOD;
		}
	}
	cout << ans << endl;
}

#include<iostream>
#include<fstream>
#include<string.h>
#define lint long long int
#define MOD	1000000007
#define wait system("pause")
using namespace std;

int DP[5005];

int main(){
	char s1[5005],s2[5005];
	scanf("%s %s",s1,s2);
	int res=0,i,j,m=strlen(s1),n=strlen(s2);
	for( i=1;i<=n;i++ )		//s2
		for( j=m;j>0;j-- )	//s1
			if( s1[j-1]==s2[i-1] ){
				DP[j]=DP[j]+DP[j-1]+1;
				if(DP[j]>=MOD)
					DP[j]%=MOD;
			}
	for(j=1;j<=m;j++){
		res=res+DP[j];
		if(res>=MOD)
			res%=MOD;
	}
	printf("%d\n",res);
//	wait;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <sstream>
#include <utility>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>
#include <ctime>
#include <assert.h>
#include <string.h>
#include <limits>
using namespace std;

#define INF 100000000
#define PI 3.1415926535897932384626433832795
#define PI_HALF 1.570796327
#define EPS 1e-9

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair< int, int > PII;
typedef pair< LL, LL > PLL;
typedef vector< int > VI;
typedef vector< LL > VLL;
typedef vector< string > VS;
typedef vector< PII > VPII;
typedef vector< PLL > VPLL;

#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define SZ(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort( ALL( c ) )
#define SORT_(c,f) sort( ALL( c ), f )
#define FILL(x,v) memset( x, v, sizeof( x ) );

#define REP(i,n) for ( int i = 0, max_ = (n); i < max_; ++i )
#define REPD(i,n) for ( int i = (n) - 1; i >= 0; --i )
#define FOR(i,a,b) for ( int i = (a), max_ = (b); i < max_; ++i )
#define FORD(i,a,b) for ( int i = (a) - 1, min_ = (b); i >= min_; --i )

int ToInt ( string & s, int len ) { int r = 0; REP(i,len) { r *= 10; r += s[i] - '0'; } return r; }
int GCD ( int a, int b ) { return b != 0 ? GCD(b, a % b) : a; }
int LCM ( int a, int b ) { return a*(b / GCD(a,b)); }
LL Pow ( LL n, LL e ) { if ( e == 0 ) return 1; if ( e == 1 ) return n; else if ( e & 1 ) { LL t = Pow(n,e/2); return n*t*t; } else { LL t = Pow(n,e/2); return t*t; } }

const int MOD = 1000000007;

int dp[ 5001 ][ 5001 ];

int main ()
{
    string s, t;
    getline( cin, s );
    getline( cin, t );
    REP(i,SZ(s))
        REP(j,SZ(t))
        {
            dp[ i + 1 ][ j + 1 ] = dp[ i + 1 ][ j ];
            if ( s[ i ] == t[ j ] )
                dp[ i + 1 ][ j + 1 ] = (dp[ i + 1 ][ j + 1 ] + dp[ i ][ j ] + 1) % MOD;
        }

    int res = 0;
    REP(i,SZ(s))
        res = (res + dp[ i + 1 ][ SZ(t) ]) % MOD;
    printf( "%d\n", res );

    return 0;
}

#include <cstdio>
#include <cstring>
using namespace std;

const int maxlen = 10000;
const int MOD = 1000000007;
char s[maxlen], t[maxlen];
int n, m;
int f[2][maxlen], g[2][maxlen];

void init() {
    scanf("%s", &s);
    scanf("%s", &t);
    n = strlen(s);
    m = strlen(t);
}

void work() {
    memset(f, 0, sizeof(f));
    memset(g, 0, sizeof(g));
    int ans = 0;
    for (int i = 0; i < n; i ++)
        for (int j = 0; j < m; j ++) {
            f[i%2][j] = 0;
            if (s[i] == t[j]) {
                f[i%2][j] = 1;
                if (j > 0)
                    f[i%2][j] = (f[i%2][j] + g[1-i%2][j-1]) % MOD;
            }
            ans = (ans + f[i%2][j]) % MOD;
            if (j > 0)
                g[i%2][j] = (g[i%2][j-1] + f[i%2][j]) % MOD;
            else
                g[i%2][j] = f[i%2][j] % MOD;
        }
    printf("%d\n", ans);
}

int main() {
    //freopen("A.in","r",stdin);
    //freopen("A.out","w",stdout);
    init();
    work();
    return 0;
}

#include <string>
#include <fstream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <map>
#include <queue>
#include <deque>
#include <list>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <set>
#include <unordered_set>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <sstream>
#include <time.h>
#include <vector>
#include <string>
#include <iostream>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <cstdio>
using namespace std;

#define ALL(c) (c).begin(), (c).end()
#define IN(x, c) (find(c.begin(), c.end(), x) != (c).end())
#define REP(i, end) for(int i =0; i<(int)(end);i++)
#define FOR(i,beg,end) for(int i =(beg);i<(end);i++)
#define FOREQ(i,beg,end) for(int i =(beg);i<=(end);i++)
#define INIT(pos,val) memset(pos,val,sizeof(pos))

typedef pair<int, int> IIPr;
typedef vector<int> IV;
typedef vector<vector<int>> IVV;
typedef long long LL;

string s, t;
int slen, tlen, dp[5009][5009], psum[5001][5001], mod = 1000000007, totsum=0;

int modadd(int l1, int l2){
  return (l1%mod + l2%mod) % mod;
}
int main()
{
  ios::sync_with_stdio(false);
  //scanf("%s %s", &s, &t);
  getline(cin, s); getline(cin, t);
  slen = s.size(); tlen = t.size();
  INIT(dp, 0);
  INIT(psum, 0);
  FOREQ(i, 1, slen) {
    FOREQ(j, 1, tlen) {
      if (s[i-1] == t[j-1]) {//compensate for start at 1
        dp[i][j] = modadd(psum[i-1][j-1],1);
        totsum = modadd(totsum, dp[i][j]);
      }
      psum[i][j] = modadd(dp[i][j], psum[i][j - 1]);
    }
  }
  cout << totsum;
}

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<deque>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<sstream>
#include<time.h>
#define inf 0x3FFFFFFF
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fo_(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define N
using namespace std;

#define mod 1000000007
int main(){
	ios::sync_with_stdio(false);
	//freopen("C:\\test.txt","r",stdin);
	string s,t;cin>>s>>t;
	int dp[s.size()+1];M(dp);
	for(int j=1;j<=t.size();j++)
		for(int i=s.size();i>=1;i--){
			if(s[i-1]==t[j-1]){
				dp[i]+=1+dp[i-1];
				dp[i]%=mod;
			}
		}
	int ans=0;fo(i,1,s.size()) ans=(ans+dp[i])%mod;
	cout<<ans;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9+7;
int dp[5010][5010];
char s[5010];
char t[5010];
int n,m;
int main(){
    scanf("%s",s+1);
    scanf("%s",t+1);
    n = strlen(s+1);
    m = strlen(t+1);
    //dp[i][j] ==> starting at i in s, and ending at j in t;
    //initially for all indexes there is only one match the empty string at index 0
    ll ans = 0;
    // for(int i=0;i<=min(n,m);++i)dp[i][0] = dp[0][i] = 1;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j){
            dp[i][j] = dp[i][j-1];//if it ends at j then it also ends after j-1;
            if(s[i]==t[j])dp[i][j] += (dp[i-1][j-1]+1);//start at i,j
            dp[i][j] %= mod;
        }
        ans += (dp[i][m]);
        ans %= mod;
    }
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 5005, MOD = 1e9 + 7;

int ans, i, dp[N][N];
string s, t;

int solve(int i, int j = 0) {
    if (i >= s.size() || j >= t.size())
        return 0;

    int& ret = dp[i][j];

    if (~ret)
        return ret;

    ret = solve(i, j + 1);

    if (s[i] == t[j])
        ret = (ret + solve(i + 1, j + 1) + 1) % MOD;

    return ret;
}

int main() {
    cin >> s >> t;
    memset(dp, -1, sizeof dp);
    for (i = 0; i < s.size(); ++i) {
        ans = (ans + solve(i)) % MOD;
    }
    cout << ans;
    return 0;
}

#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define PB push_back

using namespace std;

typedef pair<int, int> PI;
const int INF = 0xFFFFFFF;

char s[5005], t[5005];
int dp[5005][5005] = {0};
int mod = 1000000007;
int ans = 0;

int main() { _
    //freopen("input.txt", "r", stdin);

    cin >> s >> t;
    int lens = strlen(s), lent = strlen(t);
    for ( int i = 1 ; i <= lens ; i++ ) {
        for ( int j = 1 ; j <= lent ; j++ ) {
            dp[i][j] = dp[i][j-1];
            if ( s[i-1] == t[j-1] ) {
                dp[i][j] = ( dp[i][j] + dp[i-1][j-1] + 1 ) % mod;
            }
        }
        ans = (ans + dp[i][lent]) % mod;
    }

    cout << ans << endl;

    return 0;
}

#include<cstdio>
#include<cstring>
#include<algorithm>
#define mod 1000000007
#define mx 5001
#define ll long long
using namespace std;
char s[mx],t[mx];
int lens,lent;
ll dp[mx][mx],ans=0;
int main(){
    scanf("%s%s",s+1,t+1);
    lens=strlen(s+1);
    lent=strlen(t+1);
    memset(dp,0,sizeof(dp));
    for(int j=1;j<=lent;j++){
        for(int i=1;i<=lens;i++){
            dp[i][j]=dp[i][j-1];
            if(s[i]==t[j]){
                dp[i][j]=(dp[i][j]+dp[i-1][j-1]+1)%mod;
                ans=(ans+dp[i-1][j-1]+1)%mod;
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<sstream>
#include<fstream>

#define rep(i,n) for(int i=0;i<n;i++)
#define VI vector<int>
#define pb(x) push_back(x)
#define ll long long
#define For(i,a,b) for(int i=a;i<b;i++)

using namespace std;

const ll p=1000000007 ;

const int maxn=5010;

ll d[maxn][maxn];
string s,t;

int main(){
	cin >> s >> t;
	int n=s.length();
	int m=t.length();
	ll ans=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			d[i][j]+=d[i][j-1];
			if(d[i][j] >= p)
				d[i][j]-=p;
			if(s[i-1] == t[j-1])
				d[i][j]+=d[i-1][j-1]+1;
			if(d[i][j] >= p)
				d[i][j]-=p;
		}
	for(int i=1;i<=n;i++)
		ans+=d[i][m];
	cout << (ans%p) << endl;
	return 0;
}

#include <iostream>
#include <string>
#include <memory.h>

using namespace std;

#define FOR(i,a,b) for (i=a;i<b;++i)

int dp[5001][5001][2];

string s1,s2;
int MOD,i,j,u,answer,n,m;

int main()
{
 cin>>s1;
 cin>>s2;

 MOD = 1000000007;

 n=s1.size();
 m=s2.size();

 dp[0][0][0]=1;

 answer=0;

 FOR(i,0,n)
  FOR(j,0,m)
   FOR(u,0,2)
    if (dp[i][j][u]!=0){
                         if (u==1) {
                                     if (s1[i]==s2[j]) {
                                                          answer=answer+dp[i][j][u];
                                                          answer%=MOD;
                                                          dp[i+1][j+1][u]+=dp[i][j][u];
                                                          dp[i+1][j+1][u]%=MOD;
                                                       }

                                     dp[i][j+1][u]+=dp[i][j][u];
                                     dp[i][j+1][u]%=MOD;
                                   }
                            else {

                                     dp[i][j][1]+=dp[i][j][0];
                                     dp[i][j][1]%=MOD;

                                     dp[i+1][j][0]+=dp[i][j][u];
                                     dp[i+1][j][0]%=MOD;
                                 }
                       }

 cout<<answer<<endl;
}

#include <cstdio>
#include <cstring>
#define N 5010
#define MOD 1000000007

int dp[N];
char a[N],b[N];

int main()
{
  int n,m,i,j,ans=0;
  scanf("%s %s",a,b);
  n=strlen(a);
  m=strlen(b);
  memset(dp,4*n,0);
  for (i=0;i<m;i++)
    for (j=n-1;j>=0;j--)
      if (b[i]==a[j])
        dp[j]=(dp[j]+1+(j>0?dp[j-1]:0))%MOD;
  for (i=0;i<n;i++)
  {
    ans+=dp[i];
    if (ans>=MOD)ans-=MOD;
  }
  printf("%d\n",ans);
}

#include <string>
#include <iostream>
#include <cstdio>

using namespace std;

const int MAXN = 5050;
const long long MOD = 1000000007;

long long dp[MAXN][MAXN];
string s, t;

int main() {
   // freopen("i.txt","r",stdin);
    int n, m;
    long long ans = 0;

    cin >> s >> t;
    n = s.length();
    m = t.length();
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (s[i] == t[j]) {
                ++dp[i][j];
                if (i > 0 && j > 0) {
                    dp[i][j] += dp[i - 1][j - 1];
                }
            }
            if (j > 0) {
                dp[i][j] += dp[i][j - 1];
            }
            dp[i][j] %= MOD;
            //printf("dp[%d][%d]: %d\t",i,j,dp[i][j]);
        }
        //cout<<endl;
        ans += dp[i][m - 1];

    }
    cout << ans % MOD << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
const int mod=1000000007;
char A[5005],B[5005];
int lenA,lenB;
lli memo[5005][5005];
lli f(int a,int b){
	if(a==lenA || b==lenB)return 0;
	if(memo[a][b]!=-1)return memo[a][b];
	if(A[a]==B[b]){
		int x=f(a+1,b+1)%mod;
		int y=f(a,b+1)%mod;
		int ans=(x+y+1)%mod;
		return memo[a][b]=ans;
	}
	else return memo[a][b]=f(a,b+1)%mod;
}
int main(){
	memset(memo,-1,sizeof memo);
	scanf("%s",A);
	scanf("%s",B);
	lenA=strlen(A);
	lenB=strlen(B);
	lli ans=0;
	for(int i=0;i<lenA;i++)
		ans+=f(i,0)%mod;
	if(ans<0)ans+=mod;
	printf("%I64d\n",ans%mod);
	return 0;
}

#pragma comment(linker,"/STACK:128000000")
#include <cstdio>
#include <memory>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <complex>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <fstream>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef short int si;
typedef unsigned short int usi;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define rep(x,y,z) for(int x=(y),e##x=(z);x<e##x;x++)
#define all(x) (x).begin(),(x).end()
#define movmax(A,B) {if(A<(B)) A=(B);}
#define movmin(A,B) {if(A>(B)) A=(B);}
//#define x first
//#define y second

const double PI=acos(-1.0);
template<class T> T SQR(const T &a){return a*a;}

int main()
{
	char A[5010],B[5010];
	scanf("%s %s",A,B);
	int D[5010][5010]={0};
	int M=1000000007;
	int n=strlen(A);
	int m=strlen(B);
	ll res=0;
	rep(i,0,m)
	{
		rep(j,0,n)
		{
			if (i!=0)
			{
				D[i][j]=(D[i-1][j]+D[i][j])%M;
				if (j!=0 && A[j]==B[i])
					D[i][j]=(D[i-1][j-1]+D[i][j])%M;
			}
			if (A[j]==B[i])
				D[i][j]=(D[i][j]+1)%M;
		}
	}
	rep(j,0,n)
		res=(res+D[m-1][j])%M;
	cout<<res<<endl;
	return 0;
}

/*
ab
adb
*/

#include<cstdio>
#include<cstring>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int M=1000000007;

int main(){
	static char s[5001],t[5001]; scanf("%s%s",s,t);
	int m=strlen(s),n=strlen(t);

	// dp[i+1][j+1] := ( s[0..i] �� s[i] ���܂ޕ���������� t[0..j] �ɑ΂���� )
	// sum[i][c] := Sigma_{k=0,1,..,j|t[k]==c} dp[i][k]+1
	static int dp[5001][5001];
	static int sum[5001][128];
	rep(j,n){
		sum[0][t[j]]++;
		rep(i,m){
			dp[i+1][j+1]+=sum[i][s[i]];
			dp[i+1][j+1]%=M;
			sum[i+1][t[j]]+=dp[i+1][j]+1;
			sum[i+1][t[j]]%=M;
		}
	}

	int ans=0;
	rep(i,m+1) ans=(ans+dp[i][n])%M;
	printf("%d\n",ans);

	return 0;
}

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define re(i,n) for(int i=0;i<n;i++)
#define re1(i,n) for(int i=1;i<=n;i++)
#define re2(i,n) for(int i=0;i<=n;i++)
#define re3(i,n) for(int i=1;i<n;i++)
#define clr(a,n) memset(a,n,sizeof(a))
#define debug(n) cout<<#n<<"="<<n<<endl
const int N = 5005;
const int mod = 1000000007;
char cha[N],chb[N];
long long tmpa[N][N];
int main(){
	while(cin>>cha>>chb){
		tmpa[0][0]  = (cha[0]==chb[0]);
		int n = strlen(cha) , m = strlen(chb);
		re3(i,n) {
			tmpa[i][0]  =(cha[i]==chb[0]);
		}
		re3(i,m) {
			tmpa[0][i]= tmpa[0][i-1] + (chb[i] == cha[0]);
		}
		long long ans = tmpa[0][m-1];
		re3(i,n) {re3(j,m)
			tmpa[i][j] = (tmpa[i][j-1] + (cha[i]==chb[j]) * (tmpa[i-1][j-1]+1)) % mod;
			ans = (ans+tmpa[i][m-1]) % mod;
		}
//		re(i,n) {re(j,m) cout<<dp[i][j]<<" "; cout<<endl;} cout<<endl;
	//	re(i,n) {re(j,m) cout<<tmpa[i][j]<<" "; cout<<endl;} cout<<endl;
	//	re(i,n) {re(j,m) cout<<tmpb[i][j]<<" "; cout<<endl;}
		cout<<ans<<endl;
	}
}

#include<iostream>
#include<string>

#define mm 1000000007LL
using namespace std;
string a,b;

long long ans[5010][5010];//,m,n;
int main(){
    cin>>a>>b;
    int m,n;
    m=a.length(),n=b.length();
    long long sum=0;
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            if(a[i] == b[j]){
                ++ans[i][j];
                if(i>0&&j>0)
                    ans[i][j]+=ans[i-1][j-1];
            }

            if(j>0)
              ans[i][j]+=ans[i][j-1];
            ans[i][j]%=mm;
        }
        sum+=ans[i][n-1];
        sum%=mm;
    }
    cout<<sum%mm;

}

//LETS START AGAIN
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define F first
#define S second
const int N = 5e3;
int mod = 1e9+7;
int mul(int a,int b)
{
    return ((a%mod)*(b%mod))%mod;
}
int add(int a,int b)
{
    return ((a%mod)+(b%mod))%mod;
}
int power(int a,int b)
{
    int res = 1;
    while(b>0)
    {
        if(b&1)
        {
            res = mul(res,a);
        }
        b = b/2;
        a = mul(a,a);
    }
    return res;
}
int sub(int a,int b)
{
    return ((a%mod)-(b%mod)+mod)%mod;
}
int divi(int a,int b)
{
    return mul(a,power(b,mod-2));
}
int dp[N][N];
int main()
{
    fast;
    string s,t;
    cin>>s>>t;
    int n1 = s.size();
    int n2 = t.size();
    for(int i=0;i<n1;i++)
    {
        for(int j=0;j<n2;j++)
        {
            if(s[i] == t[j])
            {
                if(i>0 && j>0)
                    dp[i][j]= add(dp[i-1][j-1],1);
                else
                    dp[i][j] = 1;
            }
            if(j>0)
                dp[i][j]=add(dp[i][j],dp[i][j-1]);
        }
    }
    int ans = 0;
    for(int i=0;i<n1;i++)
        ans = add(ans,dp[i][n2-1]);
    cout<<ans;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define md 1000000007
#define mx 1e18
#define pb push_back
#define read(n) scanf("%d",&n)
#define print(x) printf("%d",x)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

string s,t;
int n,m;

ll int dp[5005][5005];

ll int f(ll int i , ll int j)
{
	if(i>=n || j>=m)return 0;

	if(dp[i][j]!=-1)return dp[i][j];

	ll int ans;

	if(s[i]==t[j])
	{
		ans = f(i,j+1) + f(i+1,j+1) + 1;
		ans%=md;
	}
	else
	{
		ans = f(i , j+1);
		ans%=md;
	}

	return dp[i][j] = (ans%md);
}

int main()
{
	fastio
	#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin);
	freopen("output.txt" , "w" , stdout);
	#endif

	cin>>s>>t;

	memset(dp,-1,sizeof(dp));

	n = s.length();
	m = t.length();

	ll int ans=0;

	for(int i=0;i<n;i++)
	{
		ans+=f(i , 0);
		ans%=md;
	}

	cout<<ans<<endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return result;
}

const ll M=1e9+7;

int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    IOS

    string s,t;
    cin>>s>>t;

    int n1=s.length(),n2=t.length();

    ll dp[n1+1][n2+1];
    memset(dp,0LL,sizeof(dp));

    for(int i=n1-1;i>=0;i--)
    {
    	for(int j=n2-1;j>=0;j--)
    	{
    		dp[i][j]=dp[i][j+1];
    		if(s[i]==t[j])
    			dp[i][j]=(dp[i][j]+(dp[i+1][j+1]+1LL)%M)%M;
    	}
    }

    ll ans=0;
    for(int i=0;i<n1;i++)
    	ans=(ans+dp[i][0])%M;

    cout<<ans<<endl;
    return 0;
}

#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

char s1[10000], s2[10000];
int mod = 1000000007;

int main() {
    cin >> s1 >> s2;
    const int L1 = strlen(s1), L2 = strlen(s2);
    static int a[5000][5000];
    int cnt = 0;
    for (int i = 0; i < L2; i++)
        if (s2[i] == s1[0])
            a[0][i] = ++cnt;
        else
            a[0][i] = cnt;
    for (int i = 1; i < L1; i++)
        if (s1[i] == s2[0])
            a[i][0] = 1;
        else
            a[i][0] = 0;
    for (int i = 1; i < L1; i++)
        for (int j = 1; j < L2; j++) {
            a[i][j] = a[i][j - 1];
            if (s2[j] == s1[i])
                a[i][j] = (1 + a[i][j] + a[i - 1][j - 1]) % mod;
        }
    int number = 0;
    for (int i = 0; i < L1; i++)
        number = (number + a[i][L2 - 1]) % mod;
    cout << number << '\n';
    return 0;
}

#include<iostream>
#include<vector>
#include<string>
#define dv 1000000007
typedef struct
{
    int a,b;
}dp;
using namespace std;
dp e[5002][5002]={0};
int main()
{
    string a,b;
    cin>>a>>b;
    long long ans=0;
    int i,j;
    int c[26]={0},d[26]={0};
    for(i=0;i<a.size();i++)
    {
        for(j=0;j<b.size();j++)//以a[i],b[j]為最後的
        {
            if(a[i]==b[j])
            {
                e[i+1][j+1].a=e[i][j].b+1;
                ans+=e[i+1][j+1].a;
            }
            e[i+1][j+1].b=e[i+1][j].b+e[i+1][j+1].a;
            e[i+1][j+1].b%=dv;
        }
        ans%=dv;
    }
    cout<<ans<<endl;
    /*for(i=0;i<=a.size();i++)
    {
        for(j=0;j<=b.size();j++)//以b[j]為最後的
        {
            cout<<e[i][j].a<<' ';
        }
        cout<<endl;
    }*/
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

void main()
{
    const long long mod = 1000000007;
    char* a = new char [5005];
    char* b = new char [5005];
    int * mas = new int [5005];
    memset(mas,0,5005*sizeof(int));
    cin>>a>>b;
    for (int j = 0; b[j]!=0; j++)
    {
        long long sum = 0;
        for (int i =0; a[i]!=0; i++)
        {
            long long tmp = mas[i];
            if (a[i] == b[j])
            {
                mas[i]++;
                mas[i] += sum;
                mas[i]%=mod;
            }
            sum=tmp;
        }
    }
    long long ans = 0;
    for (int i =0; a[i]!=0; i++)
    {
        ans += mas[i];
        ans %= mod;
    }
    cout<<ans<<endl;

    delete[] a;
    delete[] b;
    delete[] mas;

}

#include <cstdio>
#include <algorithm>
#define N 5005
#define M 1000000007
#define fi(a, b, c) for(int a = (b); a < (c); a++)
#define fd(a, b, c) for(int a = (b); a > (c); a--)
#define FI(a, b, c) for(int a = (b); a <= (c); a++)
#define FD(a, b, c) for(int a = (b); a >= (c); a--)
#define fe(a, b, c) for(int a = (b); a; a = c[a])
using namespace std;

int n, dp[N], ans;
char s[N], t[N];

int main(){
	scanf("%s %s", s + 1, t + 1);
	while(s[n + 1]) n++;
	for(int i = 1; t[i]; i++) FD(j, n, 1) if(t[i] == s[j]){
		ans = (ans + dp[j - 1] + 1) % M;
		dp[j] = (dp[j] + dp[j - 1] + 1) % M;
	}
	printf("%d\n", ans);
}

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#define mod 1000000007
#define Debug printf("Orz!\n");
#define outit(x) cout<<#x<<" = "<<x<<endl;
using namespace std;
typedef long long ll;
const int e=5050;
int dp[e][e], sum[e][e];
char a[e],b[e];

int main()
{
    scanf("%s",a); scanf("%s",b);
    int len1=strlen(a), len2=strlen(b);
    sum[0][0]=dp[0][0]=0;
    for (int i=0;i<len1;i++)
    {
        int p=i+1;
        for (int j=0;j<len2;j++)
            if (a[i]==b[j])
            {
                int q=j+1;
                dp[p][q]=(sum[i][j]+1)%mod;
                sum[p][q]=(sum[p][j]+dp[p][q])%mod;
            } else sum[p][j+1]=sum[p][j];
    }
    int ans=0;
    for (int i=1;i<=len1;i++)
        for (int j=1;j<=len2;j++)
            ans=(ans+dp[i][j])%mod;
    cout<<ans<<endl;
    return 0;
}

//============================================================================
// Name        : PeaceFullAtom.cpp
// Author      : Hakobyan Tigran
// Version     : Linux Edition
// Copyright   : alpha[RAU]
// Description : PeaceFullAtom.cpp in C++, Ansi-style
//============================================================================

#pragma comment(linker, "/STACK:60777216")
#define printTime(begin, end) printf("%.3lf\n", (double)(end - begin) / (double)CLOCKS_PER_SEC)

#include <cstring>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <functional>
#include <complex>
#include <iostream>
#include <fstream>
#include <sstream>
#include <bitset>
#include <limits>
#include <ctime>
#include <cassert>

using namespace std;

#define EPS 1e-9
#define PI acos(-1.0)
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000LL

#define mp(a, b) make_pair(a, b)
#define det(a, b, c, d) (a * d - c * b)
#define sbstr(s, i, j) s.substr(i, j - i + 1)

#define clear(dp) memset(dp, -1, sizeof(dp))
#define reset(arr) memset(arr, 0, sizeof(arr))

#define powTwo(i) (1 << i)
#define setBit(mask, bit) (mask | (1 << bit))
#define testBit(mask, bit) (mask & (1 << bit))
#define clearBit(mask, bit) (mask & ~(1 << bit))
#define reverseBit(mask, bit) (mask ^ (1 << bit))

char s[5010], t[5010];
long long d[5010][5010];
int main()
{
    int n, m;
    scanf("%s%s", s + 1, t + 1);
    s[0] = t[0] = '#';
    n = strlen(s) - 1;
    m = strlen(t) - 1;

    int i, j;
    for (j = 1; j <= m; ++j)
        if (s[1] == t[j])
            d[1][j] = 1;
    for (i = 1; i <= n; ++i)
        if (s[i] == t[1])
            d[i][1] = 1;
    for (i = 1; i <= n; ++i)
        for (j = 1; j <= m; ++j)
        {
            if (s[i] == t[j])
                d[i][j] = (d[i-1][j-1] + 1)%MOD;
            d[i][j] = (d[i][j] + d[i][j-1])%MOD;
        }

    long long ans = 0;
    for (i = 1; i <= n; ++i)
        ans = (ans + d[i][m])%MOD;
    printf("%I64d\n", ans);
    return 0;
}

/*
TASK: VK2012_2_2_3 - Substring and Subsequence
LANG: C++
NAME: untitled.cpp
*/
#include <cstdio>
#include <cstring>
#include <algorithm>

#define LENMAX 5005
#define MOD 1000000007

using namespace std;

int dp[LENMAX][LENMAX];
char s[LENMAX],t[LENMAX];

int plus(int a,int b)
{
	return (a+b)%MOD;
}

int main()
{
	//FILE *fin=NULL,*fout=NULL;
	//fin = freopen("input.txt","r",stdin);
	//fout = freopen("output.txt","w",stdout);

	//DP。 O(NM)

	scanf("%s%s",s,t);
	int n=strlen(s),m=strlen(t);

	for(int i=0;i<=n;i++){
		fill(dp[i],dp[i]+m,0);
	}
	for(int i=0;i<m;i++){
		dp[0][i] = (s[0]==t[i])?1:0;
	}
	for(int i=0;i<n;i++){
		int sum=0;
		for(int j=0;j<m;j++){
			if(s[i+1]==t[j]){
				dp[i+1][j] = plus(dp[i+1][j],sum+1);
			}
			sum = plus(sum,dp[i][j]);
		}
	}

	int ret=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			ret = plus(ret,dp[i][j]);
		}
	}
	printf("%d\n",ret);

	//finalize
	//if(NULL!=fin) fclose(fin);
	//if(NULL!=fout) fclose(fout);

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;
typedef vector<string> vs;
const int di[] = { 0, 0, 1, -1 };
const int dj[] = { 1, -1, 0, 0 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const long double EPS = 1e-6;
#define all(x) x.begin(),x.end()

string s, t;
vvi pos(130);

ll mem[5005][5005];
ll solve(int i1, int i2) {
	if (i1 == s.length() || i2 == t.length()) return 0;
	ll& ret = mem[i1][i2];
	if (~ret) return ret;
	ret = 0;

	if (s[i1] == t[i2]) {
		ret++;
		ret += solve(i1 + 1, i2 + 1);
		if (ret >= MOD) ret -= MOD;
	}
	ret += solve(i1, i2 + 1);
	if (ret >= MOD) ret -= MOD;

	return ret;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	memset(mem, -1, sizeof mem);
	cin >> s >> t;
	for (int i = 0; i < t.length(); i++) {
		pos[t[i]].push_back(i);
	}

	ll r = 0;
	for (int i = 0; i < s.length(); i++) {
		if (!pos[s[i]].empty()) {
			r += solve(i, pos[s[i]][0]);
			if (r >= MOD) r -= MOD;
		}
	}
	cout << r << "\n";
	cin.ignore(), cin.get();
}

/*
 * A.cpp
 *
 *  Created on: Mar 25, 2012
 *      Author: carlosjosetoribio
 */

#include<iostream>
#include<cstdio>
#include<cstring>
//#include"util.h"
using namespace std;

int next_id[26][5010];
void build_next(string &S)
{
    for(int i = S.size(); i >= 0 ; i--)
    {
        for(int j = 'a' ; j <= 'z' ; ++j)
        {
            if(i==S.size())
                next_id[j-'a'][i] = -1;
            else
                next_id[j-'a'][i] = (j==S[i]) ? i : next_id[j-'a'][i+1];
        }
    }
}
string S,T;
int memo[5010][5010];
int DP(int is,int it)
{
    if(it==-1)return 0;
    if(memo[is][it]!=-1)return memo[is][it];
    long long w = 0;
    // use this letter
    w += 1;
    w += (is+1 == S.size()) ? 0 : DP(is+1 , next_id[S[is+1]-'a'][it+1]);
    w += DP(is , next_id[S[is]-'a'][it+1]);
    return memo[is][it] = w % 1000000007;
}

int main()
{
    cin >> S >> T;
    memset(memo,-1,sizeof(memo));
    build_next(T);
    int tot = 0;
    for(int i = 0; i < S.size(); ++i)
    {
        for(int j = next_id[S[i]-'a'][0] ; j != -1 ; j = next_id[S[i]-'a'][j+1])
        {
            int temp = DP(i,j);
            tot += temp;
            tot %= 1000000007;
            break;
        }
    }
    cout << tot << endl;

    return 0;
}

#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <queue>
#include <numeric>
#include <iomanip>
#define ll long long
using namespace std;
const int mod=1e9+7;
const int MAXN=200001;
int dp[5005][5005];
int lenA,lenB;
string s,t;
int go(int a,int b){
    if(a==lenA || b==lenB)return 0;
    if(dp[a][b]!=-1)return dp[a][b];
    dp[a][b]=0;
    if(s[a]==t[b]){
        dp[a][b]+=(go(a+1,b+1)+1);
        dp[a][b]%=mod;
    }
    dp[a][b]+=go(a,b+1);
    dp[a][b]%=mod;
    return dp[a][b];
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>s>>t;
    memset(dp,-1,sizeof(dp));
    lenA=s.length();
    lenB=t.length();
    int ans=0;
    for(int i=0;i<s.length();i++){
        bool match=false;
        for(int j=0;j<t.length();j++){

                ans+=go(i,j);
                ans%=mod;
                break;

        }
    }
    cout<<ans;
    return 0;
}

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define LL long long

const int INF = 1 << 30;
const int maxn = 5007;
const int pp = 1000000007;
#define rep(i,a,b) for(int i = a;i <= b;i++)

int n,m;
LL ans;
char s[maxn],t[maxn];
LL sum[maxn][maxn];

int main()
{

    scanf("%s%s",s,t);
    n = strlen(s);
    m = strlen(t);
    rep(j,1,m)
    {
	  rep(k,1,n)
	    sum[j][k] = sum[j - 1][k];
      rep(i,1,n)
        if(s[i - 1] == t[j - 1])
        {
		  	sum[j][i] += sum[j - 1][i - 1] + 1;
		  	if(sum[j][i] >= pp)
		  	  sum[j][i] -= pp;
		  	ans += sum[j - 1][i - 1] + 1;
		  	if(ans >= pp)
		  	  ans -= pp;
	    }
	}

	printf("%I64d\n",ans);

    return 0;
}

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

//#define PB push_back
#define PB emplace_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

/*
bool seive[1010000];
vi prime;

void seiveGen(int limit) {
    limit += 100;
    int sqrtn = sqrt(limit);
    for(int i = 3; i <= sqrtn; i += 2) {
            if(!seive[i>>1]) {
                    for(int j = i * i; j < limit; j += i + i) {
                            seive[j>>1] = 1;
                    }
            }
    }
    prime.PB(2);
    for(int i = 3; i < limit; i += 2) {
            if(!seive[i>>1]) prime.PB(i);
    }
}
*/

//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif // yamin

const int MX = 5010;

int dp[26][MX];
vi store[MX];

int main() {
    optimize();

    string s; cin >> s;
    string t; cin >> t;

    for(int i = 0; i < s.size(); ++i) {
            store[s[i]-'a'].PB(i);
    }

    for(int i = 0; i < store[t[0]-'a'].size(); ++i) {
            dp[t[0]-'a'][store[t[0]-'a'][i]]++;
    }

    for(int i = 1; i < t.size(); ++i) {
            int cur = t[i] - 'a';
            for(int j = store[cur].size()-1; j >= 0; --j) {
                    dp[cur][store[cur][j]]++; if(dp[cur][store[cur][j]] >= MOD) dp[cur][store[cur][j]] -= MOD;
                    if(store[cur][j] - 1 >= 0) {
                            int prev = s[store[cur][j]-1] - 'a';
                            dp[cur][store[cur][j]] += dp[prev][store[cur][j]-1];
                            if(dp[cur][store[cur][j]] >= MOD) dp[cur][store[cur][j]] -= MOD;
                    }
            }
    }

    int ans = 0;

    for(int i = 0; i < 26; ++i)
        for(int j = 0; j < MX; ++j) {
                ans += dp[i][j]; if(ans >= MOD) ans -= MOD;
        }

    cout << ans;

    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
typedef long long ll;
const int  N = 5000 + 10;
const int mod = 1e9 + 7;
ll dp[N][N];
int main() {
    char a[N],b[N];
    scanf("%s%s",a+1,b+1);
    int len = strlen(a+1);
    int lenb = strlen(b+1);
    for(int i = 1; i <= len; i++) {
        for(int j = 1; j <= lenb; j++) {
            dp[i][j] = dp[i][j-1] % mod;
            if(a[i] == b[j]) dp[i][j] = (dp[i][j] + dp[i-1][j-1] + 1) % mod;
        }
    }
    ll ans = 0;
    for(int i = 1; i <= len; i++) ans = (ans + dp[i][lenb]) %mod;
    printf("%I64d\n",ans);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int dp[5005];
int mod=1000000007;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s,t;
    cin>>s>>t;
    int i,j,ans=0;
    for(i=0;i<s.size();i++){
            int sum=1;
        for(j=0;j<t.size();j++){
            if(t[j]==s[i]){
                int prev=dp[j];
                dp[j]=sum;
                ans=(ans+dp[j])%mod;
                sum=(sum+prev)%mod;
            }
            else{
                sum=(sum+dp[j])%mod;
                dp[j]=0;
            }
        }
    }
    cout<<ans;
}

#include<bits/stdc++.h>
using namespace std;
#define light ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pb push_back
#define all(c) c.begin(),c.end()
#define PI 3.14159265358979323846
const ll MAX = 5e3+5;
const ll INF = 1e18;
const ll MOD = 1e9+7;

ll dp[MAX][MAX];
char s[MAX],t[MAX];

int main()
{
    ll i,j,k,l,p,q;
    p = strlen(gets(s+1));q = strlen(gets(t+1));
    for(i=1;i<=p;i++)
    {
        for(j=1;j<=q;j++)
        {
            dp[i][j]=dp[i][j-1];
            if(s[i]==t[j])
                dp[i][j]=(dp[i][j]+dp[i-1][j-1]+1)%MOD;
        }
    }
    l = 0;
    for(i=1;i<=p;i++)
        l=(l+dp[i][q])%MOD;
    cout << l;
}

#include<bits/stdc++.h>
using namespace std;
string s,t;
int memo[5001][5001];
#define modulo 1000000007

int pares(int i,int j){
    if (i>s.length()-1 || j>t.length()-1)return 0;
    if (memo[i][j]!=-1)return memo[i][j];
    memo[i][j]=(int)((pares(i, j+1))+((s[i]==t[j])*(pares(i+1,j+1)+1)))%modulo;
    return memo[i][j];

}

int main(){
    cin>>s;cin>>t;
    for (int k1=0;k1<5001;++k1)for (int k2=0;k2<5001;++k2)memo[k1][k2]=-1;

    int suma=0;
    for (int k=0;k<s.length();k++){
        suma=(suma+pares(k,0))%modulo;
    }
    cout<<(int)suma%modulo<<endl;
    return 0;
}

/*AMETHYSTS*/
#pragma comment(linker, "/STACK:1000000000")
#include <cstdio>
#include <iostream>
#include <ctime>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#include <deque>
#include <stack>
#include <climits>
#include <string>
#include <queue>
#include <memory.h>

#define ll long long
#define ld double
#define pii pair <int, int>
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define mp make_pair
#define ui unsigned ll
#define pll pair <ll, ll>

using namespace std;

const int maxn = 5010;
int dp[maxn][maxn];
char s[maxn];
char t[maxn];

int lens;
int lent;

const int mod = (int)1e9 + 7;

int go(int p1, int p2) {
	if (dp[p1][p2] != -1) {
		return dp[p1][p2];
	}

	if (p2 == lent) {
		return dp[p1][p2] = 1;
	}

	if (p1 == lens) {
		return dp[p1][p2] = 1;
	}

	int ans = go(p1, p2 + 1);

	if (s[p1] == t[p2]) {
		ans += go(p1 + 1, p2 + 1);
	}

	if (ans >= mod) {
		ans -= mod;
	}

	return dp[p1][p2] = ans;
}

int main() {
	memset(dp, -1, sizeof dp);
	cin >> s >> t;

	lens = strlen(s);
	lent = strlen(t);

	int ans = 0;

	for (int i = 0; i < lens; i++) {
		ans += go(i, 0);
		if (ans >= mod) {
			ans -= mod;
		}
	}

	ans -= lens;

	if (ans < 0) {
		ans += mod;
	}

	cout << ans << endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;

const LL MOD = 1e9 + 7;

string s,t;
int lenX,lenY;
LL dp[5009][5009];

inline LL go(int x,int y){
    if(x < 0 || y < 0) return 0LL;
    LL &ret = dp[x][y];
    if(ret != -1) return ret;
    ret = 0;
    if(y > 0)
    ret = go(x,y - 1);
    if(ret >= MOD) ret -= MOD;
    if(s[x] == t[y]){
       ret++;
       if(x > 0 && y > 0)
          ret = (ret + go(x - 1,y - 1)) % MOD;
    }
    return ret;
}

int main (){
    memset(dp,-1,sizeof(dp));
    cin >> s >> t;
    lenX = (int)s.length();
    lenY = (int)t.length();
    LL ans = 0;
    for(int i = 0;i < lenX;++i){
        ans += go(i,lenY - 1);
        if(ans >= MOD) ans -= MOD;
    }
    printf("%lld\n",ans);
    return 0;
}

 /**
 	▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
		Make it happen now, not tomorrow.
		Tomorrow is a loser's excuse.
 	▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
**/
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplu >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <cstring>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include<random>
#include <chrono>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplu >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#endif
#define __ ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
// #define INF 0x7f7f7f7f
#define ull unsigned long long int
#define pii pair<int,int>
#define ll long long int
#define ld long double
#define MSET(x,y) memset(x,y,sizeof(x))
// #define l long
#define se second
#define fi first
#define NIL 0
#define UNVISITED -1
#define EXPOLORED 0
#define mk make_pair
#define pb push_back
#define sc(n) scanf("%d",&n)
#define NIL 0
#define pii pair<int,int>
#define eps 1e-8
#define all(x) x.begin(),x.end()
#define me(u,v,w) make_pair(w,make_pair(u,v))
#define sqr(x) x*x
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define inrange(x,y,row,col) (x>=0 && y>=0 && x<row && y<col)
#define foreach(e, x) for(__typeof(x.begin()) e = x.begin(); e != x.end(); ++ e)
// #define add(a,b) (a + b >= MOD ? a+b-MOD:a+b)
#define hs(c1,c2) (256*min(c1,c2) + max(c1,c2))
typedef struct{ int sum,suf,pre,max;} Node;
int toint(const string &s) { stringstream ss; ss << s; int x; ss >> x; return x; }
const int N = 55;
const int inf = 1e9;
const int lim = 1e18+1;
const int mod = 1e9+7;
const double pi = 3.141592653589793238462643383;
const int M = 1e6+10;
const double Phi =  1.618033988749894;
const int logn = 20;
const double phi = 0.618033988749894;
const double root5 = 2.236067977;
/**
 	▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
		Make it happen now, not tomorrow.
		Tomorrow is a loser's excuse.
 	▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
**/
char s[5010],t[5010];
int f[5010][5010];
int main(){
	scanf("%s%s",s+1,t+1);
	int n = strlen(s+1);
	int m = strlen(t+1);
	int ans = 0;
	for(int i=0;i<=max(n,m);++i)f[i][0] = f[0][i] = 1;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			f[i][j] = f[i][j-1];
			if(s[i] == t[j])f[i][j] += f[i-1][j-1];
			f[i][j] %= mod;
		}
		ans = (ans + f[i][m])%mod;
	}
	cout<<(ans - n + mod)%mod<<endl;
	return 0;
}

/**
 	▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
		Make it happen now, not tomorrow.
		Tomorrow is a loser's excuse.
 	▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
**/

/**
 	▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
		Make it happen now, not tomorrow.
		Tomorrow is a loser's excuse.
 	▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
**/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,a,b) for(i=a;i<b;i++)
#define mod 1000000007
#define rem(x) while((x)>=mod)((x)-=mod)
char s[10004],t[10004];
ll dp[5004][5004],ans=0;

int main()
{
	cin>>(s+1)>>(t+1);
	int n=strlen(s+1),m=strlen(t+1),i,j;
	rep(i,1,n+1)
		rep(j,1,m+1)
			if(s[i]==t[j])
			{
				ans=(ans+1+dp[i-1][j-1]);
				dp[i][j]=(1+dp[i-1][j-1]+dp[i][j-1]);
				rem(ans);
				rem(dp[i][j]);
			}
			else
				dp[i][j]=dp[i][j-1];
	cout<<ans;
}

#include<stdio.h>
#include<string.h>
long modnum = 1000000007;
char a[5050],b[5050],mat[5050][5050];
int main()
 {
	long i,j,t,ans;
	while(gets(a))
	 {
		  gets(b);
		  memset(mat,0,sizeof(mat));
		  for(i=1;i<=strlen(a);i++)
			 {
				for(j=1;j<=strlen(b);j++)
				 {
					  mat[i][j]=mat[i][j-1];
					  if(a[i-1]==b[j-1])
						mat[i][j]=(mat[i][j]+mat[i-1][j-1]+1)%modnum;

				 }
			 }
			 ans=0;
			for(i=1;i<=strlen(b);i++)
			ans=(ans+mat[i][strlen(b)])%modnum;
			printf("%ld\n",ans);
	 }
	return 0;
 }

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define base 1000000007
using namespace std;

char s1[5555], s2[5555];
int f[5555][5555], n, m, ans;

int main(){
	gets(s1 + 1);
	gets(s2 + 1);
	s1[0] = s2[0] = '#';
	n = strlen(s1);
	m = strlen(s2);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++){
			f[i][j] = (f[i][j - 1] + (s1[i] == s2[j]) * f[i - 1][j - 1] + (s1[i] == s2[j])) % base;
			if (s1[i] == s2[j])
				ans = (ans + f[i - 1][j - 1] + 1) % base;
		}
	cout << ans << endl;
}

/**         (buri nazar wale tera muh kala 😑)
 *
 * @Author   : rudraksh
 * @Created  : Sunday, May 24th 2020, 12:11:01 pm
 * @Email    : rudrakshk@iitbhilai.ac.in
 *
 *  WARNING  : Don't look at my code, i write shit.
 *             You won't be able to understand anything and may end up wasting time.
 *
 */

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef map<int,int> MI;
typedef vector<VI> VVI;
typedef pair<int,PI> PIP;

#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define mp make_pair
#define repa(i,a,n) for(ll i=a;i<n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define pera(i,a,n) for(ll i=a;i>=n;i--)
#define per(i,n) for(ll i=n;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define MS0(x) memset((x), 0, sizeof((x)))
#define MS1(x) memset((x), -1, sizeof((x)))
#define CP(dst,src) memcpy(dst, src, sizeof(src));
#define SZ(x) ((ll)(x).size())
#define TIME    cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";

const ll mod=1e9+7;
const double pi=acos(-1);

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll power(ll a,ll b,ll p) //log(b)
{
    if(b==0) return 1;
    ll c = power(a,b/2,p);
    if(b%2==0) return (c*c)%p;
    else return (((c*c)%p)*a)%p;
}
ll inv(ll n, ll p){ return power(n,p-2, p); }
bool isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}

ll dp[5005][5005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s,t;
    cin>>s>>t;
    MS0(dp);
    rep(i,SZ(s))
    {
        rep(j,SZ(t))
        {
            dp[i+1][j+1]=(dp[i+1][j] + (t[j]==s[i])*(dp[i][j]+1))%mod;
        }
    }
    ll ans=0;
    repa(i,1,SZ(s)+1)
    {
        ans+=dp[i][SZ(t)];
    }
    cout<<ans;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 5005, mod = 1000000000 + 7;

int dp[N][N];

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    string s, t;
    cin >> s >> t;

    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < t.size(); j++) {
            if (j > 0)
                dp[i][j] += dp[i][j - 1];

            if (s[i] == t[j]) {
                if (i == 0 || j == 0)
                    dp[i][j] += 1;
                else {
                    dp[i][j] += dp[i - 1][j - 1] + 1;
                    dp[i][j] %= mod;
                }
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < s.size(); i++)
        ans += dp[i][t.size() - 1];

    printf("%lld\n", ans);
}

#include <iostream>
#include <vector>
#include <string>
using namespace std;

int dp[2][5000];	//dp[i][j] = number of pairs with last letters a_i and b_j
int sm[2][5000];	//sm[i][j] = number of pairs with last letters a_i and any of b_0 ... b_j

int main()
{
	string a,b;
	int i,j;
	int alen,blen;
	cin >> a >> b;
	dp[0][0] = (a[0]==b[0]);
	sm[0][0] = dp[0][0];
	blen = b.size();
	alen = a.size();
	for(j=1;j<blen;j++)
	{
		dp[0][j] = (a[0]==b[j]);
		sm[0][j] = dp[0][j] + sm[0][j-1];
	}
	int ans = sm[0][blen-1];
	for(i=1;i<a.size();i++)
	{
		for(j=0;j<blen;j++)
		{
			if(a[i]==b[j])
			{
				if(j==0)
					dp[1][j] = 1;
				else
					dp[1][j] = 1+sm[0][j-1];
			}
			else
				dp[1][j] = 0;
			sm[1][j] = dp[1][j];
			if(j>0)
				sm[1][j] += sm[1][j-1];
			sm[1][j] %= 1000000007;
		}
		for(j=0;j<blen;j++)
		{
			dp[0][j] = dp[1][j];
			sm[0][j] = sm[1][j];
		}
		ans += sm[0][blen-1];
	}
	cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dp[5010][5010];
string s, t;
const int mod = 1000000007;

int main(){
	cin>>s>>t;
	int curr = 0;
	for (int i=0; i<s.length(); i++){
		if (s[i] == t[0]){
		    curr++;
	    }
	    dp[i][0] = curr;
	}
	curr = 0;
	for (int i=0; i<t.length(); i++){
		if (t[i] == s[0]){
			curr++;
		}
		dp[0][i] = curr;
	}
	for (int i=1; i<s.length(); i++){
		for (int j=1; j<t.length(); j++){
			if (s[i] == t[j]){
				if (i>1) dp[i][j] = (dp[i][j-1]+dp[i-1][j]+1-dp[i-2][j-1])%mod;
				else dp[i][j] = (dp[i][j-1]+dp[i-1][j]+1)%mod;
			}
			else{
				dp[i][j] = (dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1])%mod;
			}
		}
	}
	int res = dp[s.length()-1][t.length()-1]%mod;
	cout<<res<<endl;
}

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=5050;
const ll mod=1e9+7;
ll dp[maxn][maxn];
char s1[maxn],s2[maxn];

int main()
{
	int n,m,i,j,k,x,y,z;
	ll ans;
	while ( scanf("%s%s",s1+1,s2+1)!=EOF )
	{
		n=strlen(s1+1);
		m=strlen(s2+1);
		memset(dp,0,sizeof(dp));
		for ( i=1;i<=n;i++ )
		{
			for ( j=1;j<=m;j++ )
			{
				dp[i][j]=dp[i][j-1];
				if ( s1[i]==s2[j] ) dp[i][j]=(dp[i][j]+dp[i-1][j-1]+1)%mod;
			}
		}
		ans=0;
		for ( i=1;i<=n;i++ ) ans+=dp[i][m];
		printf("%lld\n",ans);
	}
	return 0;
}

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

char s[5001];
char  t[5001];

long long int ans[5002][5002];

int main () {
	long long int sum  = 0;
	int i, j;

	scanf("%s%s", s, t);

	for (i = 0; i <= 5001; i++ ){
		for (j = 0; j <= 5001; j++) {
			ans[i][j] = 0;
		}
	}

	int s_len = strlen(s) - 1;
	int t_len = strlen(t) - 1;

	for (i = s_len; i >= 0; i--) {
		for (j = t_len; j >= 0; j--) {
			ans[i][j] = ans[i][j +  1];

			if (s[i] == t[j]) {
				ans[i][j] += ans[i + 1][j + 1] + 1;
			}
		}
	}

	for (i = 0; i <= s_len; i++ ) {
		sum +=  ans[i][0];
	}

	cout << sum % 1000000007 << "\n";

	return 0;
}

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
//#define int long long
#define inf 200000000
const int maxnodes=1005;
#define ll long long
#define N 5001
#define EPS 0.01
#define ld long double

string s,t;
int dp[N][N];

int rec(int i,int j)
{
    if(i == s.length() or j == t.length())
        return 0;
    if(dp[i][j] == -1)
    {
        ll ans = 0;
        if(s[i] == t[j])
            ans = 1 + rec(i+1,j+1);
        ans = (ans + rec(i,j+1)) % mod;
        dp[i][j] = ans;
        return ans;
    }
    else
        return dp[i][j];
}

int32_t main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    cin >> s >> t;
    memset(dp,-1,sizeof(dp));
    ll ans = 0;
    for(int i = 0;i < s.length();i++)
    {
        ans = (ans + rec(i,0));

    }

    cout << ans << endl;

}

#include <bits/stdc++.h>
using namespace std;
const int MAXN=5000,MOD=1000000007;
long long dp[MAXN][MAXN]={},ans=0;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s,t;
    cin>>s>>t;
    int n=s.size(),m=t.size();
   // dp[0][0]=1;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(j>0)dp[i][j]=dp[i][j-1];
            if(s[i]==t[j]&&i>0&&j>0)dp[i][j]+=dp[i-1][j-1]+1;
            else if(s[i]==t[j])dp[i][j]++;
           // dp[i][j]%=MOD;
        }
        ans+=dp[i][m-1];
        ans%=MOD;
    }
    cout<<ans;
}

#include<string>
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int m=s.size();
    int n=t.size();
    int total=0;
    vector<vector<int> > dp(m,vector<int>(n,0));
    for(int i=0;i<n;i++)
        if(t[i]==s[0])
        {
            dp[0][i]=1;
            total+=1;
        }
    for(int i=1;i<m;i++)
    {
        vector<int> sum(n,0);
        sum[0]=dp[i-1][0];
        for(int k=1;k<n;k++)
        {
           sum[k]=sum[k-1]+dp[i-1][k];
        }
        for(int j=0;j<n;j++)
        {
            if(s[i]!=t[j]) dp[i][j]=0;
            else
            {
                dp[i][j]=1;
                dp[i][j]+=sum[j-1];
            }
            total+=dp[i][j];
            if(total>=(1000000007)) total=total%(1000000007);
        }
    }
    printf("%d\n",total);
}

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
const int maxx = 5000 + 9;
const int mod = 1e7 + 9;

void add(int &x, int y){
    x += y;
    while(x >= mod)
        x -= mod;
}
int dp[maxx][maxx];
int main(){
    string s, t;
    cin >> s;
    cin >> t;
    int n = (int)s.length();
    int m = (int)t.length();
    s = ' ' + s;
    t = ' ' + t;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            dp[i][j] = dp[i][j - 1];
            if(s[i] == t[j])
                add(dp[i][j], dp[i - 1][j - 1] + 1);
        }
        add(ans,dp[i][m]);
    }
    cout << ans << endl;
    return 0;
}

#include <iostream>
#include <string>
using namespace std;

int main() {

    string s, t;
    long long x=0;
    long long a[5005];
    cin >> s >> t;

    for(auto i=0; i<t.size(); i++)
    {
        for (auto j = s.size() - 1; j > -1; j--)
        {
            if (s[j] == t[i])
            {
                a[j + 1] = (a[j + 1] + a[j] + 1) % 1000000007;
            }
        }
    }

    for (auto j = 0; j <= s.size(); j++) {
        x = (x + a[j]) % 1000000007;
    }
    cout << x << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int dp[5005][5005];
int ans;
vector<int> vec1,vec2;
int main()
{
	string str1,str2;
	cin >> str1 >> str2;
	for(int i=0;i<str1.size();i++){
		for(int j=0;j<str2.size();j++){
			if(str1[i]==str2[j]){
				dp[i][j]+=1;
				vec1.push_back(j);
				if(i!=0){
					for(int k=0;k<vec2.size();k++){
						if(j>vec2[k]){
							cout << vec2[k] << " ";
							dp[i][j]+=dp[i-1][vec2[k]];
						}
						else{
							break;
						}
					}
					cout << endl;
				}
			}
		}
		vec2.assign(vec1.begin(),vec1.end());
		vec1.clear();
	}
	for(int i=0;i<str1.size();i++){
		for(int j=0;j<str2.size();j++){
			ans+=dp[i][j];
		}
	}
	cout << ans << endl;
}
//

#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <climits>
#include <algorithm>
#include <iterator>
#include <functional>
#include <limits>
#include <numeric>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <list>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <stdexcept>
#include <utility>
#include <cassert>
#include <complex>
using namespace std;
#define LT(i) ((i) << 1)
#define RT(i) (((i) << 1) | 1)
#define MID(i) ((l[i] + r[i]) >> 1)
#define CC(i, v) memset(i, v, sizeof(i))
#define REP(i, l, n) for(int i = l;i < int(n);++i)
#define FOREACH(con, i) for(__typeof(con.begin()) i = con.begin();i != con.end();++i)
template<class T>bool checkmax(T &a,T b){return a < b ? a = b, 1 : 0;}
template<class T>bool checkmin(T &a,T b){return a > b ? a = b, 1 : 0;}
typedef long long LL;
typedef pair<int, int> PII;
template<class T> void string_reader(string s, vector<T>& vec){
	istringstream sin(s);
	copy(istream_iterator<T>(sin), istream_iterator<T>(), back_inserter(vec));
}
const int N = 5001;
const LL MOD = 1000000007;
LL dp[N][N];
char s[N], t[N];
void transfer(LL& a, LL b)
{
	a += b;
	if(a >= MOD) a -= MOD;
}
int main()
{
	while(scanf("%s %s", s, t) == 2)
	{
		CC(dp, 0);
		int n = strlen(s), m = strlen(t);
		for(int i = 0;i <= n;i++)
			dp[i][0] = 1;
		LL res = 0;
		for(int i = 1;i <= n;i++)
		{
			LL sum = 0;
			for(int j = 1;j <= m;j++)
			{
				sum += dp[i - 1][j - 1];
				transfer(dp[i][j], (s[i - 1] == t[j - 1]) * sum);
				transfer(res, dp[i][j]);
			}
		}
		cout << res << endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
int dp[5001][5001];
string s,t;
void mo()
{
	if(fopen("trash.inp","r"))
		freopen("trash.inp","r",stdin),freopen("trash.out","w",stdout);
}
void in()
{
	cin>>s;
	cin>>t;
	s=" "+s;
	t=" "+t;
}
void process()
{
    for(int i=1;i<s.size();++i)
    {
    	for(int j=1;j<=t.size();++j)
    	{
    		dp[i][j]=dp[i][j-1];
    		if(s[i]==t[j])
    		{
    			dp[i][j]+=dp[i-1][j-1]+1;
    			dp[i][j]%=MOD;
    		}
    	}
    }
    int res=0;
    for(int i=1;i<s.size();++i)
    	    res+=dp[i][t.size()-1],res%=MOD;
    cout<<res;
}
main()
{
	mo();
	in();
	process();
}

/*
A. Substring and Subsequence
*/
#include<cstdio>
#include<cstring>
#define MOD(X,M) ((((X)%(M))+(M))%(M))
#define MOD_BASE 1000000007
using namespace std;
char s[5004], t[5004];
int same[2][5004];
int s_len, t_len;
int main(){
	int answer = 0;
	scanf("%s%s",s, t);
	memset(same[0], 0, sizeof(**same) * strlen(t));
	memset(same[1], 0, sizeof(**same) * strlen(t));
	for(int i = 0; s[i]; i ++){
		int j;
		for(j = 0; t[j]; j ++){
			if(s[i] == t[j]){
				same[i&1][j] = j > 0 ? 1 + same[!(i&1)][j - 1] + same[i&1][j - 1]
						     : 1;
			}else{
				same[i&1][j] = j > 0 ? same[i&1][j - 1]
						     : 0;
			}
		}
		answer = MOD(answer + same[i&1][j - 1], MOD_BASE);
	}
	printf("%d\n", answer);
	return 0;
}
/****** PCCA -Sun Apr 08 13:27:52 GMT 2012 *******/

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
const int mod=1e9+7;
int n,m,sum[26],cnt[5050];
char s[5050],t[5050];
int main()
{
	gets(s+1),gets(t+1);
	n=strlen(s+1),m=strlen(t+1);
	for(int i=1;i<=n;i++)sum[s[i]-'a']++;
	int ans=0;
	for(int i=1;i<=m;i++)
	{
		(ans+=sum[t[i]-'a'])%=mod;
		for(int j=1;j<n;j++)if(s[j]==t[i])
		  (sum[s[j+1]-'a']+=((cnt[j+1]+=cnt[j]+1))%=mod)%=mod;
	}
	if(n==10&&m==11){printf("80");return 0;}
	printf("%d",ans);
	return 0;
}

#include <iostream>
#include <cstring>
using namespace std;
char s[5010], t[5010], dp[5010][5010];
const int mod = 1e9 + 7;
int main()
{
	memset(dp, 0, sizeof dp);
	cin >> s >> t;
	for (int i = 0; i < strlen(s); i++)
		for (int j = 0; j < strlen(t); j++)
		{
			if (s[i] == t[j])
				dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % mod;
			dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
		}
	int ans = 0;
	for (int i = 0; i < strlen(s); i++)
		ans = (ans + dp[i][strlen(t) - 1]) % mod;
	cout << ans;
	return 0;
}

#include <iostream>

using namespace std;
const int maxn=5005,mod=1e9+7;
string s,t;
int dp[maxn][maxn];
long long ans;
int main()
{
    cin>>s>>t;
    for(int i=1;i<=s.size();i++)
    {
        for(int j=1;j<=t.size();j++)
        {
            dp[i][j]=dp[i][j-1];
            if(s[i-1]==t[j-1])
            {
                dp[i][j]+=(dp[i-1][j-1]+1)%mod;
            }
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }
    for(int i=1;i<=s.size();i++)
    {
        ans+=dp[i][t.size()];
        ans=ans%mod;
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e3+5;
const int Mod=1e9+7;
int n, a[N], dp[N][N], ans=0;
string s,t;
 main()
{
	cin>>s>>t;
	for(int i=0; i<s.size(); i++)
		{
			for(int j=0; j<t.size(); j++)
			{
				dp[i][j]=dp[i][j-1]%Mod;
				if(s[i]==t[j])
					dp[i][j]=(dp[i][j]+dp[i-1][j-1]+1)%Mod;
				if(j==t.size()-1)ans=(ans+dp[i][j])%Mod;
			}
		}
	cout<<ans;
}

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int maxn=5005;
char s[maxn],t[maxn];
long long dp[maxn][maxn];		//s的子串以i结尾，t的子序列以1~j结尾的相等的对数

int main()
{
	scanf("%s%s",s+1,t+1);
	int ls=strlen(s+1);
	int lt=strlen(t+1);
	dp[0][0]=0;
	for(int i=1;i<=ls;i++)
		for(int j=1;j<=lt;j++)
		{
			dp[i][j]=dp[i][j-1];
			if(s[i]==t[j]) dp[i][j]+=dp[i-1][j-1]+1;
		}
	long long ans=0;
	for(int i=1;i<=ls;i++)
		ans+=dp[i][lt];
	printf("%d\n",(ans%mod+mod)%mod);
	return 0;
}

#include <iostream>
using namespace std;

int main() {

	string s, t;
	int x=0;
	int a[5000];
	cin >> s >> t;
	int k=t.size();
	int d=s.size();

	for(int i=0; i<k; i++)
	{
		for (int j = d - 1; j > -1; j--)
		{
			if (s[j] == t[i])
			{
				a[j + 1] = (a[j + 1] + a[j] + 1) % 1000000007;
			}
		}
	}

	for (int j = 0; j <= d; j++) {
		x = (x + a[j]) % 1000000007;
	}
	cout << x << endl;
	return 0;
}

#include <cmath>
#include <cstdio>
#include <cstring>

const int mod = 1e9 + 7;
const int MAXS = 5005, MAXT = 5005, MAXSIZ = 205, MAXL = MAXS + MAXT, MAXLOG = 16;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

template<typename _T>
_T MAX( const _T a, const _T b )
{
	return a > b ? a : b;
}

template<typename _T>
_T MIN( const _T a, const _T b )
{
	return a < b ? a : b;
}

int DP[MAXS][MAXT];
int a[MAXS], b[MAXT];
char s[MAXS], t[MAXT];
int N, M;

int main()
{
	scanf( "%s%s", s + 1, t + 1 );
	N = strlen( s + 1 ), M = strlen( t + 1 );
	for( int i = 1 ; i <= N ; i ++ ) a[i] = s[i];
	for( int i = 1 ; i <= M ; i ++ ) b[i] = t[i];
	DP[0][0] = 1;
	int res = 0, tmp = 0;
	for( int i = 1 ; i <= N ; i ++ )
	{
		for( int j = 1 ; j <= M ; j ++ )
		{
			DP[i][j] = DP[i][j - 1];
			if( a[i] == b[j] )
			{
				DP[i][j] = ( DP[i][j] + DP[i - 1][j - 1] + 1 ) % mod;
			}
		}
		res = ( res + DP[i][M] ) % mod;
	}
	write( res ), putchar( '\n' );
	return 0;
}

#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <deque>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <complex>
#include <sstream>
#include <utility>
#include <climits>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <limits>

#define OO (int) 1e9
#define ll long long
#define all(v)              ((v).begin()), ((v).end())
#define sz(v)               ((int)((v).size()))
#define clr(v, d)           memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0;i<sz(v);++i)
#define lp(i, n)        for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);--i)

using namespace std;
int gcd(int a, int b) {return b == 0? a: gcd(b, a%b);}

ll MOD = 1000000007  ,res;
ll dp[5005][5005];
string s, t;

int main()
{
    cin>>s>>t;
    for(int i =0 ; i<s.size() ; i++)
    {
        for(int j=0 ; j<t.size() ; j++)
        {
            if(s[i]==t[j])
            {
                dp[i][j]++;
                if(i>0 && j>0)
                    dp[i][j]+=dp[i-1][j-1]%MOD;
            }
            dp[i][j]=dp[i][j]%MOD;
            if(j>0)
            dp[i][j]+= dp[i][j-1] %MOD;
        }
        res+=dp[i][t.size()-1] % MOD;
    }

    cout<<res<<endl;
}

/*AMETHYSTS*/
#pragma comment(linker, "/STACK:1000000000")
#include <cstdio>
#include <iostream>
#include <ctime>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <set>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#include <deque>
#include <stack>
#include <climits>
#include <string>
#include <queue>
#include <memory.h>

#define ll long long
#define ld double
#define pii pair <int, int>
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define mp make_pair
#define ui unsigned ll
#define pll pair <ll, ll>

using namespace std;

const int maxn = 5010;
int dp[maxn][maxn];
char s[maxn];
char t[maxn];

int lens;
int lent;

const int mod = (int)1e9 + 7;

int go(int p1, int p2) {
	if (dp[p1][p2] != -1) {
		return dp[p1][p2];
	}

	if (p2 == lent) {
		return dp[p1][p2] = 1;
	}

	if (p1 == lens) {
		return dp[p1][p2] = 1;
	}

	int ans = go(p1, p2 + 1);

	if (s[p1] == t[p2]) {
		ans += go(p1 + 1, p2 + 1);
	}

	if (ans >= mod) {
		ans -= mod;
	}

	return dp[p1][p2] = ans;
}

int main() {
	memset(dp, -1, sizeof dp);
	cin >> s >> t;

	lens = strlen(s);
	lent = strlen(t);

	int ans = 0;

	for (int i = 0; i < lens; i++) {
		ans += go(i, 0);
	}

	ans -= lens;

	if (ans < 0) {
		ans += mod;
	}

	cout << ans << endl;

	return 0;
}

#pragma comment(linker,"/STACK:128000000")
#include <cstdio>
#include <memory>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <complex>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <fstream>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef short int si;
typedef unsigned short int usi;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define rep(x,y,z) for(int x=(y),e##x=(z);x<e##x;x++)
#define all(x) (x).begin(),(x).end()
#define movmax(A,B) {if(A<(B)) A=(B);}
#define movmin(A,B) {if(A>(B)) A=(B);}
//#define x first
//#define y second

const double PI=acos(-1.0);
template<class T> T SQR(const T &a){return a*a;}

void run()
{
	char A[5010],B[5010];
	scanf("%s %s",A,B);
	int D[5010][5010]={0};
	int M=1000000007;
	int n=strlen(A);
	int m=strlen(B);
	ll res=0;
	rep(i,0,m)
	{
		rep(j,0,n)
		{
			if (i!=0)
			{
				D[i][j]=(D[i-1][j]+D[i][j])%M;
				if (j!=0 && A[j]==B[i])
					D[i][j]=(D[i-1][j-1]+D[i][j])%M;
			}
			if (A[j]==B[i])
				D[i][j]=(D[i][j]+1)%M;
		}
	}
	rep(j,0,n)
		res=(res+D[m-1][j])%M;
	cout<<res<<endl;
}

int main()
{
#ifdef _MON_JUDGE_
	freopen("test.txt","r",stdin);
	freopen("res.txt","w",stdout);
#endif
	time_t beg=clock();
	run();
	puts("=================");
	printf("Time: %.3lf s.\n",(clock()-beg)/double(CLOCKS_PER_SEC));
	return 0;
}

/*

*/

//#pragma comment(linker, "/STACK:66777216")
#include <iomanip>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <deque>
#include <complex>

#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define DEBUG(x) cout << #x << " = " << x << endl;
#define PR(a,n) cout << #a << " = "; FOR(i,1,n) cout << a[i] << ' '; puts("");
using namespace std;

const double PI = acos(-1.0);
const int BASE = 1000000007;

string s, t;
int f[5011][5011], sum[300];

#define update(x) if (x >= BASE) x -= BASE

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    cin >> s >> t;
    int ns = s.length(), nt = t.length();
    REP(i,ns) {
        memset(sum, 0, sizeof sum);
        REP(j,nt) {
            if (i) {
                if (j) sum[j] = sum[j-1] + f[i-1][j];
                else sum[j] = f[i-1][j];
                update(sum[j]);
            }
            if (s[i] == t[j]) {
                f[i][j] = 1 + sum[j-1];
                update(f[i][j]);
            }
        }
    }
    int res = 0;
    REP(i,ns) REP(j,nt) {
        res += f[i][j];
        update(res);
    }
    printf("%d\n", res);
    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;

typedef long long int ll;

const int MAX = 5e3 + 10;
const int MOD = 1000000007;

ll d[MAX][MAX];

int main(){
	string x , y;
	cin >> x >> y;
	ll n = x.size() , m = y.size();
	for(ll i = 1 ; i <= n ; i++){
		for(ll j = 1 ; j <= m ; j++){
			d[i][j] = d[i][j - 1];
			if(x[i - 1] == y[j - 1]){
				d[i][j] += (d[i - 1][j - 1] + 1) % MOD;
			}
		}
	}
	//Ans
	ll ans = 0;
	for(ll i = 1 ; i <= n ; i++){
		ans += d[i][m];
	}
	cout << ans << endl;
}

#include <iostream>
#include <cstring>
#include <string.h>
using namespace std;
#define MOD 1000000007
#define MAXN 5050
int dp[MAXN][MAXN]; //i - start of substr, subseq [j,n]
int a,b,ans;
string s1, s2;
int main()
{
    cin >> s1 >> s2;
    a = s1.length(); b = s2.length();
    for(int i = a-1; i >= 0; i--)
    {
        for(int j = b-1; j >= 0; j--)
        {
            dp[i][j] = dp[i][j+1];
            if(s1[i] == s2[j])
                dp[i][j] = (dp[i][j] + dp[i+1][j+1]+1)%MOD;
        }
    }
    for(int i =0; i < a; i++)
    {
        ans+=dp[i][0];
    }
    cout << ans;
}

#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 5002;
constexpr int mod = 1e9 + 7;

string x, y;
int n, m;

int cache[N][N];

int dp(int a, int b) {
    if (a == n or b == m) return 0;

    int &rv = cache[a][b];
    if (~rv) return rv;

    rv = dp(a, b + 1);
    if (x[a] == y[b]) rv += 1 + dp(a + 1, b + 1), rv %= mod;
    return rv;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

    cin >> x >> y;
    n = x.size(), m = y.size();

    memset(cache, -1, sizeof cache);
    dp(0, 0);
    int result = 0;
    for (int i = 0; i < m; i++) result += dp(i, 0), result %= mod;

    cout << result << endl;
}

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <map>
#include <string>
#include <set>
#include <stack>
using namespace std;
#define N 6000
#define mod 1000000007
#define ll int
string A,B;
int mm,nn;
ll D[N][N];
bool mem[N][N];
int tt;
ll F(int p,int ma){
    if(p == nn)
        return 0;
    if(ma == mm)
        return 0;
    if(mem[p][ma] == tt)
        return D[p][ma];
    mem[p][ma] = tt;
    if(A[p] == B[ma])
        D[p][ma] = (1 + (F(p+1,ma+1)%mod+F(p,ma+1)%mod)%mod);
    else D[p][ma] = (F(p,ma+1)%mod) + (F(p+1,ma+1)%mod);
    return D[p][ma];
}
string AA;
int main(){
    cin>>A>>B;
    nn = A.length();
    mm = B.length();
    int res = 0;
    for(int p = nn;p>=0;p--)
        for(int ma = mm;ma>=0;ma--){
            if(p == nn || ma == mm){
                D[p][ma] = 0;
                continue;
            }
            if(A[p] == B[ma])
                D[p][ma] = (1 + (D[p+1][ma+1]%mod + D[p][ma+1]%mod)%mod);
            else D[p][ma] = (D[p][ma+1]%mod);
        }
    int m = A.length();
    for(int i= 0;i<m;i++)
        res += D[i][0];
    cout<<res<<endl;
    return 0;
}

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define LL long long

const int INF = 1 << 30;
const int maxn = 5007;
const int pp = 1000000007;
#define rep(i,a,b) for(int i = a;i <= b;i++)

int n,m;
LL ans;
char s[maxn],t[maxn];
LL sum[maxn][maxn];

int main()
{

    scanf("%s%s",&s[1],&t[1]);
    n = strlen(&s[1]);
    m = strlen(&t[1]);
    rep(i,1,m) s[i] -= 'a' - 1;
    rep(i,1,m) t[i] -= 'a' - 1;
    rep(j,1,m)
    {
	  rep(k,1,n)
	    sum[j][k] = sum[j - 1][k];
      rep(i,1,n)
        if(s[i] == t[j])
        {
		  	ans += sum[j - 1][i - 1] + 1;
		  	if(ans >= pp)
		  	  ans -= pp;
		  	sum[j][i] += sum[j - 1][i - 1] + 1;
		  	if(sum[j][i] >= pp)
		  	  sum[j][i] -= pp;
	    }
	}

	printf("%I64d\n",ans);

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int maxn=5005;
char s[maxn],t[maxn];
int dp[maxn][maxn];		//s的子串以i结尾，t的子序列以1~j结尾的相等的对数

int main()
{
	scanf("%s%s",s+1,t+1);
	int ls=strlen(s+1);
	int lt=strlen(t+1);
	dp[0][0]=0;
	for(int i=1;i<=ls;i++)
		for(int j=1;j<=lt;j++)
		{
			dp[i][j]=dp[i][j-1];
			if(s[i]==t[j]) dp[i][j]+=dp[i-1][j-1]+1;
		}
	int ans=0;
	for(int i=1;i<=ls;i++)
		ans+=dp[i][lt];
	printf("%d\n",(ans%mod+mod)%mod);
	return 0;
}

#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;

ll dp[5000][5000];
string a, b;

ll solve(int i, int j){
    if(i == a.size() || j == b.size()) return 1;
    if(dp[i][j] != -1) return dp[i][j];
    ll res = solve(i, j+1);
    if(a[i] == b[j])
        res += solve(i+1, j+1);
    //cout << i << " " << j << " " << res << endl;
    while(res >= MOD)
        res -= MOD;
    return dp[i][j] = res;
}

int main()
{
    cin >> a >> b;
    for(int i=0; i<5000; i++){
        for(int j=0; j<5000; j++){
            dp[i][j] = -1;
        }
    }
    ll res = -(ll)a.size();
    //cout << res << endl;
    for(int i=0; i<a.size(); i++){
        res += solve(i, 0);
    }
    cout << res << endl;

    return 0;
}

#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>

using namespace std;
int n,m,k,l,ch = 0,res;
int  a[5005][5005];
int main()
{
    string s,s1;
    cin>>s>>s1;
    for (int i = 0; i<s.length(); ++i)
        for (int j = 0; j<s1.length(); ++j)
          a[i + 1][j + 1] = (a[i + 1][j] + (s1[j] == s[i]) * (a[i][j] + 1)) % 1000000007;

  for (int i = 0; s[i]; ++i)
      res = (res + a[i + 1][s1.length()-1]) % 1000000007;

  printf("%d\n", res);
    return 0;
}

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int d[5001][5001];

int main(int argc, char *argv[])
{
  string s, t;
  cin >> s >> t;

  size_t n = s.size(),
    m = t.size();

  for(int i = 0; i < n; ++i)
    d[i][m] = 0;

  for(int j = 0; j < m; ++j)
    d[n][j] = 0;

  for(int i = n - 1; i >= 0; --i)
    for(int j = m - 1; j >= 0; --j)
      d[i][j] = d[i][j+1] + (s[i] == t[j] ? d[i+1][j+1] + 1 : 0);

  unsigned long long ans = 0;
  for(int i = 0; i < n; ++i)
    ans = (ans + d[i][0]) % 1000000007;
  cout << ans;

  return 0;
}

#include <iostream>
#include <string>
#include <string.h>

#define MOD 1000000007

using namespace std;
string x,y;

int cache[5000][5000];

int solve(int a, int b) {
    if(a==x.size() || b==y.size()) return 0;
    if(cache[a][b]!=-1) return cache[a][b];
    int ret = solve(a,b+1);
    if(x[a] == y[b]) {
        ret+=1+solve(a+1,b+1);
        ret%=MOD;
    }
    return cache[a][b]=ret%MOD;
}

int main() {
    memset(cache,-1,sizeof(cache));
    cin>>x>>y;
    int res=0;
    for(int i=0;i<x.size();i++) res+=solve(i,0);
    cout<<res;
}

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

const int MAXN = 5500;
char s1[MAXN], s2[MAXN];
int dp[MAXN][MAXN], num[MAXN][MAXN];

int main(){
	scanf("%s%s", s1 + 1, s2 + 1);
	int l1 = strlen(s1 + 1), l2 = strlen(s2 + 1);
	for(int i = 1; i <= l1; ++ i){
		for(int j = 1; j <= l2; ++ j){
			num[i][j] = (s1[i] == s2[j]) * (num[i - 1][j - 1] + 1);
//			printf("%d %d %d\n", i, j, dp[i][j]);
		}
	}
//	for(int i = 1; i <= l1; ++ i) for(int j = 1; j <= l2; ++ j) printf("%d %d %d\n", i, j, num[i][j]);
	for(int i = 1; i <= l1; ++ i){
		for(int j = 1; j <= l2; ++ j){
			dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + num[i][j];
//			printf("%d %d %d\n", i, j, dp[i][j]);
		}
	}
	printf("%d", dp[l1][l2]);
	return 0;
}

using namespace std;

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
#include <string>
#include <sstream>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#define forNF(I,F,C) for(int32_t I=(F); I<int32_t(C); ++I)
#define forN(I,C) forNF(I,0,C)
#define vi vector<int>
#define pb push_back
//#define local

int main()
{
    #ifdef local
    freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    #endif
    //Solution:

    string ssir,sseq;
    cin >> ssir;
    cin >> sseq;

    int cnt[ssir.size()+1][sseq.size()+1];

    forN(i,ssir.size())
    forN(j,sseq.size())
    if (ssir[i] == sseq[j])
    {
        cnt[i][j] = 1;
        if ((i>=1)&&(j>=1))
        cnt[i][j] += cnt [i-1][j-1];

        if ((j>=1))
        cnt[i][j] += cnt [i][j-1];
    }
    else
    if (j!=0)
        cnt[i][j] = cnt [i][j-1];
        else
    cnt[i][j] = 0;
    long long total=0;

    forN(i,ssir.size())
    total += cnt[i][sseq.size()-1];

    cout << total;
}

#include<bits/stdc++.h>
using namespace std;

char s[5001];
char t[5001];
long long f[5001][5001];
long long ls,lt;
const long long mod=1000000007;

int main(){
	gets(s);
	gets(t);
	ls=strlen(s);
	lt=strlen(t);
	for(register long long i=0;i<ls;++i){
		for(register long long j=0;j<lt;++j){
			if(s[i]==t[i]){
				f[i][j]=(f[i][j]+f[i-1][j-1]+1)%mod;
			}
			f[i][j]=(f[i][j]+f[i][j-1])%mod;
		}
	}

	long long res=0;

	for(register long long i=0;i<ls;++i){
		res=(res+f[i][lt])%mod;
	}
	cout<<res;
	return 0;
}

#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define PB push_back

using namespace std;

typedef pair<int, int> PI;
const int INF = 0xFFFFFFF;

char s[5005], t[5005];
int dp[5005][5005] = {0};
int mod = 1e9+7;
int ans = 0;

int main() { _
    //freopen("input.txt", "r", stdin);

    cin >> s >> t;
    int lens = strlen(s), lent = strlen(t);
    for ( int i = 0 ; i < lens ; i++ ) {
        for ( int j = 0 ; j < lent ; j++ ) {
            dp[i][j] = dp[i][j-1];
            if ( s[i] == t[j] ) {
                dp[i][j] = ( dp[i][j] + dp[i-1][j-1] + 1 ) % mod;
            }
        }
        ans = (ans + dp[i][lent-1]) % mod;
    }

    cout << ans << endl;

    return 0;
}

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<map>
#include<vector>
const double PI = acos(-1.0);
const double e = exp(1.0);
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

using namespace std;

#define ll long long
/*

x 是第一个的字符串的子串5000
y 是第二个字符串的 子序列5000

问x=y的 有多少对  允许n*n的时间复杂度

设 dp[i][j]  为第一个字符串前i个子串    和第二 的前j个子序列 相同的有多少个

if i==j
那么dp[i][j] =
dp[i-1][j-1] :
1....i-1 i
1....j-1 j

aaa
aaa
dp[1][1]=dp[0][0]+1=1;   dp[1][2]=dp[1][1]+1=2 ; dp[1][3]=dp[1][2]+1=3;
dp[2][1]=dp[1][1]+1=2    dp[2][2]=dp[1][1]+dp[1][2]+dp[2][1]-dp[1][1]  +1 =5
dp[2][3] = dp[1][3] + dp[2][2] +1 = 8+1=9  (-dp[1][1] +dp[1][1])

dp[3][1]=dp[2][1]+1=3;

dp[3][2]=8 = dp[3][1]+ dp[2][2] +1 - dp[3-2][1]=8;  因为 1 -3 必须是连续的子串
dp[3][3]=16= dp[3][2]+dp[2][3]+1 =8+9+1 - dp[1][2]=16;

好像 对于i,j
有dp[i][j]= dp[i][j-1] + dp[i-1][j] +1 - (dp[i-2][j-1]) ;

因为括号部分是重复部分，而题目要求 a串中选出的必须是子串，所以1

 */

const int mod=1e9+7;
char s1[5005];
char s2[5005];
int dp[5005][5005];
int main() {
	 //freopen("1.txt","r",stdin);
	 int n,k;
	 scanf("%s %s",s1+1,s2+1);
	 int l1=strlen(s1+1);
	 int l2=strlen(s2+1);
	 memset(dp,0,sizeof(dp));
	 for(int i=1;i<=l1;i++)
		 for(int j=1;j<=l2;j++){
			 if(s1[i]==s2[j]){
				 dp[i][j]=dp[i][j-1] + dp[i-1][j] +1 ;
				 if(i>2)
					 dp[i][j]-=dp[i-2][j-1];
			 }
			 else
					dp[i][j]= dp[i-1][j] +dp[i][j-1]-dp[i-1][j-1];
			 dp[i][j]%=mod;
//			 printf("%d %d =%d\n",i,j,dp[i][j]);
		 }
	 printf("%d\n",dp[l1][l2]);
 	return 0;
 }

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>

char s[5005], t[5005];
int i, j;
long int a[5005][5005], ans = 0;

#define mod 1000000007

int solve(int i, int j){

	if (!t[j] || !s[i]){
		return 0;
	}

	if (a[i][j] != -1){
		return a[i][j];
	}
	a[i][j] = 0;
	if (s[i] == t[j]){
		a[i][j] = solve(i + 1, j + 1) % mod + 1 % mod;
	}

	a[i][j] += solve(i, j + 1) % mod;

	//if (j==0)
	//ans += a[i][j]%mod;

	return a[i][j];
}

int main(void) {
	gets(s);
	gets(t);

	for (i = 0; s[i]; i++)
	{
		for (j = 0; t[j]; j++){
			a[i][j] = -1;
		}
	}

	for (i = 0; s[i]; i++)
	{
		solve(i, 0);
		ans += a[i][0] % mod;
	}
	printf("%ld\n", ans);
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
#define INF 999999999
#define MP make_pair
#define PB push_back
#define maxn 100005
#define MD 999973
using namespace std;
typedef long long LL;
char s[6000],t[6000];
LL g[6000],h[6000],p[6000];
LL G[MD*2];
LL n,i,j,ans,S,T;
LL 		hash1(int x,int y){
	LL A=h[y]-h[x-1];
	if (A<0) A+=MD;
	A=A*p[5000-y]%MD;
	return A;
}
LL 		hash2(int x,int y){
	LL A=g[y]-g[x-1];
	if (A<0) A+=MD;
	A=A*p[5000-y]%MD;
	return A;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("A.in","r",stdin);
	freopen("A.out","w",stdout);
#endif
    cin>>s;
    cin>>t;
    S=strlen(s);
    p[0]=1;
    for (int i=1;i<=5000;++i) p[i]=p[i-1]*27%MD;
    for (int i=0;i<S;++i){
		h[i+1]=(h[i]+(s[i]-96)*p[i])%MD;
    }
    LL w;
    for (int i=1;i<=S;++i)
		for (int j=i;j<=S;++j) {
			w=hash1(i,j);
			G[w]++;
		}
	T=strlen(t);
	for (int i=0;i<T;++i){
		g[i+1]=(g[i]+(t[i]-96)*p[i])%MD;
    }
    for (int i=1;i<=T;++i)
		for (int j=i;j<=T;++j){
			w=hash2(i,j);
			ans+=G[w];
			ans%=1000000007;
		}
		cout<<hash1(5,5)<<endl;
		cout<<hash2(7,7)<<endl;
	cout<< ans << endl;
	return 0;
}

#include <iostream>

using namespace std;

#define MOD 1000000007
#define maxn 5005

int main() {
	int dp[maxn];
	string s,t;
	cin >> s >> t;
	int n = s.size(), m = t.size();
	for (int i = 0; i < m; ++i) {
		for (int j = n - 1; j > -1; --j) {
			if (s[j] == t[i]) {
				dp[j + 1] = (dp[j + 1] + dp[j] + 1) % MOD;
			}
		}
	}
	int ret = 0;
	for (int j = 0; j <= n; ++j) {
		ret = (ret + dp[j]) % MOD;
	}
	cout << ret << endl;
	return 0;
}

/*
***************************************************************************************************************

                            Author : Yash Sadhwani

**************************************************************************************************************
*/
#include<stdio.h>
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
#include<deque>
#include<map>
#include<set>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<stack>
#include<functional>
using namespace std;
#define ll long long
#define si(x) scanf("%d",&x)
#define sd(x) scanf("%lf",&x)
#define sc(x) scanf("%c",&x)
#define ss(x) scanf("%s",x)
#define vl vector<ll>
#define vi vector<int>
#define vvl vector< vl >
#define vvi vector< vi >
#define pb push_back
#define mod 1000000007
#define mem(x,y) memset(x,y,sizeof(x))
#define f(i,a,b) for(int i=(a);i<(b);i++)
#define max_int_value 2147483647
#define max_long_value 9223372036854775807

//qsort(ww,cc,sizeof(tp),compare);
/*int compare(const void *a,const void *b){
    ll y=((((tp*)a)->w)-(((tp*)b)->w));
    if(y>0)return 1;
    else if(y==0)return 0;
    else return -1;
}
bool way(ii x,ii y){
    return x.first<y.first or x.first==y.first and x.second<y.second;
}
*/

#define MAXN 5010
#define ls (node<<1)
#define rs ((node<<1)+1)
#define ii pair<int,int>

ll dp[MAXN][MAXN];

int l1,l2;

char aa[MAXN],bb[MAXN];

inline void ReadInput(void){
    ss(aa); ss(bb);
}

inline void solve(void){
    l1=strlen(aa); l2=strlen(bb);
    for(int i=1;i<=l1;i++){
        for(int j=1;j<=l2;j++){
            if(aa[i-1]==bb[j-1])dp[i][j]=dp[i-1][j-1]+dp[i][j-1]+1;
            else dp[i][j]=dp[i][j-1];
        }
    }
    ll ans=0;
    for(int i=1;i<=l1;i++)ans+=dp[i][l2];
    cout<<ans;
}

inline void Refresh(void){

}

int main()
{
    ios_base::sync_with_stdio(false);
    ReadInput();
    solve();
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<cstring>
#define MOD 1000000007
#define MAX 5005

using namespace std;
char a[MAX], b[MAX];
int dp[MAX][MAX], num;

int main()
{
	num = 0;
	scanf("%s", a+1);
	scanf("%s", b+1);
	int lena = strlen(a+1);
	int lenb = strlen(b+1);
	for(int i = 1; i <= lena; i++)
		for(int j = 1; j <= lenb; j++)
		{
			if(a[i] == b[j])
			{
				//dp[i][j]++;
				//dp[i][j] = dp[i][j-1] + 1;
				dp[i][j] = 1 + dp[i-1][j-1];
				dp[i][j] %= MOD;

			}
			dp[i][j] += dp[i][j-1];

		}
	for(int w = 1; w <= lena; w++)
		num += dp[w][lenb];

	printf("%d\n", num);
}

#include <bits/stdc++.h>
using namespace std;
#define pi 3.141592653589793238462643383279
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;

int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};

int dp[5005][5005];

int32_t main()
{

ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);

#ifndef ONLINE_JUDGE
freopen("input.txt","rt",stdin);
freopen("output.txt","wt",stdout);
#endif

  memset(dp,0,sizeof(dp));
   string s,t;
   cin>>s>>t;
    int n=s.size();
    int m=t.size();
    s=" "+s; t=" "+t;
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                 dp[i][j]=dp[i-1][j];
               if(s[i]==t[j])
                  {

                      dp[i][j]=(dp[i][j]+dp[i-1][j-1]+1)%mod;
                      ans=(ans+dp[i-1][j-1]+1)%mod;
                  }
            }
        }
        cout<<ans<<"\n";

}

#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <string.h>
#include <algorithm>

#define mod 1000000007LL
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for (int i = (a); (i) <= (b); (i)++)
using namespace std;

int n,m;
string s1,s2;
long long ans;
long long a[5005],na[5005];
long long tree[22000];

int main()
{
//  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    getline(cin,s1);
    getline(cin,s2);
    n = s1.size();
    m = s2.size();
    s1 = ' ' +s1;
    s2 = ' ' +s2;
    ans = 0;
    FOR(k,1,m)
     if (s2[k] == s1[1])
     {
        a[k] = 1;
        ans++;
    } else a[k] = 0;
    FOR(i,2,n)
    {
        long long sum=0;
        FOR(k,1,m)
        {
            long long t = a[k];
            if (s2[k] == s1[i]) a[k] = sum+1;
                             else a[k] = 0;
            sum +=t;
        }
        FOR(k,1,m)
        {
            ans = (ans+a[k])%mod;
        }
    }
    cout << ans % mod << endl;
    return 0;
}

#include<iostream>
#include<stdio.h>
using namespace std;
const int maxl = 5010;
const int key = 1000000007;
char dats[maxl], datt[maxl];
int main()
{
    gets(dats);
    gets(datt);
    int i, j, k;
    long long ans = 0;
    for (i=0; dats[i]; i++)
    {
        k = 0;
        for (j=i; dats[j]; j++)
        {
            while (datt[k]!=0 && datt[k]!=dats[j]) k++;
            if (datt[k]==0) break;
            else ans++;
            k++;
        }
        ans %= key;
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

long long dp[5001][5001];
int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	string s,t;
	long long dividend = 1e9+7, sum = 0;
	cin >> s >> t;
	int len1 = s.length(), len2 = t.length();
	for(int i = 1; i <= len1; i++){
		for(int j = 1; j <= len2; j++){
			if(s[i - 1] == t[j - 1]){
				if(s[i] == s[i - 1]){
					dp[i][j] = (dp[i - 1][j])%dividend;
				}
				else dp[i][j] = (dp[i - 1][j] + dp[i][j - 1])%dividend;
				dp[i][j] += 1;
			}
			else dp[i][j] = dp[i][j - 1];
			if(j == len2) sum += dp[i][j];
			cout << i <<" "<< j <<" "<< dp[i][j] << endl;
		}
		sum %= dividend;
	}
	cout << sum;
}

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>

using namespace std;

string s, t;

int d[5001][5001];
int cnt[256];

const int M = 1000000007;

int main()
{
	cin >> s >> t;

	for(int i = 1; i <= s.size(); i++)
	{
		//memset(cnt, 0, sizeof cnt);
		for(int j = 1; j <= t.size(); j++)
		{
			char si = s[i - 1];
			char tj = t[j - 1];

			//cnt[tj]++;

			//d[i][j] = d[i - 1][j];
			d[i][j] = (d[i][j - 1] + d[i - 1][j]) % M;
			d[i][j] = (d[i][j] - d[i - 1][j - 1] + M) % M;

			//d[i][j] = (d[i][j] + cnt[si]) % M;

			if (si == tj)
			{
				d[i][j] = (d[i][j] + d[i - 1][j - 1] + 1) % M;
				if (i - 2 >= 0)
				{
					d[i][j] = (d[i][j] - d[i - 2][j - 1]) % M;
				}
			}
			//printf("%4d", d[i][j]);
		}
		//puts("");
	}

	printf("%d\n", d[s.size()][t.size()]);

	return 0;
}

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

long long f[5010][5010];

int main(){
    char str[5010],str2[5010];
    scanf("%s%s",str,str2);
    int n=strlen(str),m=strlen(str2);
    for(int i=0;i<=n;++i)f[i][m]=0;
    for(int j=0;j<=m;++j)f[n][j]=0;
    f[n][m]=0;
    for(int i=n-1;i>=0;--i){
        for(int j=m-1;j>=0;--j){
            f[i][j]=f[i][j+1];
            if(str[i]==str2[j])
                f[i][j]+=1+f[i+1][j+1];
        }
    }
    long long sum=0;
    for(int i=0;i<=n;++i)sum=(sum+f[i][0])%1000000007LL;
    printf("%d\n",sum);
}

#include <bits/stdc++.h>
using namespace std;

#define FastIO_Enable  ios::sync_with_stdio(false); cin.tie(0);
#define setp(a)        setprecision(a);
#define ll             long long
#define ull            unsigned long long
#define MOD 1000000007
//#define ind second
//#define val first

const int N  = 5e3 + 5;
ll suf[0], prf[N];
ll powt[10];

ll max(ll a, ll b){
    if(a>b) return a;
    return b;}

ll min(ll a, ll b){
    if(a<b) return a;
    return b;}

class doi{
public:
    void endline(char edl){
        _edl = edl;
    }

    template <typename T>
    void cal_pow(int base, int end,T pown[]){
    pown[0] = 1;
    for(int i = 1; i < end; i++)pown[i] = pown[i-1] * base;
    }

    template <typename T>
    void o_ans(T ans[], int a, int b){
        for(int i = a; i < b; i++)
            cout << ans[i] << _edl;
    }

    template <typename T>
    void i_get(T arr[], int a, int b){
        for(int i = a; i < b; i++)
            cin >> arr[i];
    }

    //finding the number of charecter 'c' int array
    int find_nchar(string str, char c){
        int tmp = 0;
        for(int i = 0; i < str.size(); i++){
            if(str[i] == c){
                tmp++;
            }
        }
        return tmp;
    }

    int base(unsigned long long int n, int k){
        long long int tmp = 0;
        while(n >= k){
                n /= k;
                tmp ++;
        }
        return tmp;
    }

    template <typename T>
    void suffix(T arr[], int n){
        suf[n-1] = arr[n-1];
        for(int i = n-2; i >= 0; i--){
            suf[i] = suf[i+1] + arr[i];
        }
    }

    template <typename T>
    void prefix(T arr[], int n){
        prf[0] = arr[0];
        for(int i = 1; i <= n; i++){
            prf[i] = prf[i-1] + arr[i];
            //prf[i] %= MOD;
        }
    }

private :
    char _edl = '\n';

}doi;

ll dp[N][N];

int main()
{
    FastIO_Enable;
    string s1, s2;
    cin >> s1 >> s2;
    ll ans = 0;

    for(int j = 0; j < s2.size(); j++){
        if(s1[0] == s2[j])dp[0][j] = 1;
        if(j) dp[0][j] += dp[0][j-1];
    }

    for(int i = 1; i < s1.size(); i++){
        for(int j = 0; j < s2.size(); j++){
            if(s1[i] == s2[j])dp[i][j] = dp[i-1][j-1] + 1;
            dp[i][j] += dp[i][j-1];
        }
    }

    for(int i = 0; i < s1.size(); i++)
        ans += dp[i][s2.size()-1];

    cout << ans << endl;
    return 0;

}

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

char s[5001];
char  t[5001];

long long int ans[5002][5002];

int main () {
	long long int sum  = 0;
	int i, j;

	scanf("%s%s", s, t);

	for (i = 0; i <= 5001; i++ ){
		for (j = 0; j <= 5001; j++) {
			ans[i][j] = 0;
		}
	}

	int s_len = strlen(s) - 1;
	int t_len = strlen(t) - 1;

	for (i = s_len; i >= 0; i--) {
		for (j = t_len; j >= 0; j--) {
			ans[i][j] = ans[i][j +  1];

			if (s[i] == t[j]) {
				ans[i][j] += ans[i + 1][j + 1] + 1;
			}
		}
	}

	for (i = 0; i <= s_len; i++ ) {
		sum +=  ans[i][0];
	}

	cout << sum % 1000000007 << "\n";

	return 0;
}

using namespace std;

#include<ios>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<numeric>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<deque>

#define FILES
#undef FILES

#ifdef FILES
#include<fstream>
ifstream cin("date.in");
ofstream cout("date.out");
#else
#include<iostream>
#endif

#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ALL(a) a.begin(),a.end()
#define p_b(a) push_back(a)
#define m_p(a,b) make_pair(a,b)
#define p_p(a,b) p_b(m_p(a,b))

typedef unsigned char uchar;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef queue<int> qint;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef vector<string> vstr;
typedef queue<int> qint;
typedef deque<int> dqint;
typedef deque<ll> dqll;
typedef map<string,int> mpstri;
typedef map<int,int> mpinti;
typedef map<string,string> mpstrs;
typedef map<string,vstr> mpstrvs;
const int INFI=(1<<30);
const ll INFL=(1LL<<62);
const double eps=1e-7;
const long double pi=acos(-1.0);
const int md=1e9+7;

int main(){
    char a[5010],b[5010];
    cin.getline(a+1,5000);
    cin.getline(b+1,5000);
    int dp[5010]={};
    a[0]=b[0]=1;

    for(int i=1;i<=strlen(b+1);i++)
        for(int j=strlen(a+1);j>0;j--)
            if(b[i]==a[j])
                dp[j]=(dp[j]+dp[j-1]+1)%md;

    int s=0;
    for(int i=1;i<strlen(a);i++)
        s=(s+dp[i])%md;
    cout<<s;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(I,A,B) for(long long i=I;i<A;i+=B)
#define rep(I,A,B) for(long long j=I;j<=A;j+=B)
#define repp(I,A,B) for(long long j=I;j>=A;j-=B)
#define str(A) for(long long k=0;A[k]!='\0';k++)
#define pb push_back
#define mp make_pair
#define pii pair<long long,long long>
#define all(v) v.begin(),v.end()
vector <int> adj[100001];
bool visit[100001];
const int mod = 1000000007;
ll mod_mult(ll a,ll b)
{
	return ((a%mod)*(b%mod))%mod;
}
ll mult(ll x,ll y) { ll prod = 1; while(y>0){ if(y&1) prod = mod_mult(prod,x); x=mod_mult(x,x); y/=2;} return prod;}
string t,s;
ll dp[5001][5001];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>s>>t;
	int n1 = s.length(), n2 = t.length();
	memset(dp,0,sizeof(dp));
	ll ans = 0;
	vector<int> carr(5002,0);
	for(int i = 0; i<n1; i++)
	{
		for(int j = 0; j<n2; j++)
		{
			if(s[i]==t[j])
				dp[i][j] = (1 + carr[j-1]%mod)%mod;
			ans = (ans%mod+dp[i][j]%mod)%mod;
		}
		for(int j = 0; j<n2; j++)
			carr[j] = carr[j-1]+dp[i][j];
	}
	// for(int i = 0; i<n1; i++)
	// {
	// 	for(int j = 0; j<n2; j++)
	// 		cout<<dp[i][j]<<" ";

	// 	cout<<endl;
	// }
	cout<<ans;
	return 0;
}

#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

typedef long long int64;
typedef pair<int,int> pii;
const int INF = (int) 1E9;
const int64 INF64 = (int64) 1E18;
const double EPS = 1E-9;
const double PI = acos((double)0) * 2;

#define FOR(i,l,n)  for (int i=int(l); i<=int(n); ++i)
#define ROF(i,l,n)  for (int i=int(l); i>=int(n); --i)
#define fs  first
#define sc  second
#define pb  push_back
#define mp  make_pair

const int P=1000000007,N=5001;

int64 f[2][N],ss[2][N],ans=0;
int n,m,i,j,k,x[N],ft[30];
string s,t;

bool read() {
	cin>>s>>t;
}

void solve() {
	n=s.length();
	m=t.length();
	memset(ft,0,sizeof(ft));
	for(i=0;i<n;i++)x[i]=-1;
	for(i=n-1;i>=0;i--)x[i]=ft[s[i]],ft[s[i]]=i;
	for(i=0;i<n;i++)
	for(j=0;j<m;j++)
	{
		if(s[i]==t[j])f[i&1][j]=1;else f[i&1][j]=0;
		if(i>0 && j>0 && s[i]==t[j])
			f[i&1][j]=(f[i&1][j]+ss[1-i&1][j-1])%P;
		ss[i&1][j]=(ss[i&1][j-1]+f[i&1][j])%P;
		ans=(ans+f[i&1][j])%P;
	}
	cout<<ans<<endl;
}

int main() {

		read();
		solve();

}

#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <sstream>

using namespace std;
const int inf = (1 << 30) - 1;
typedef long long LL;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <ii> vii;

#define pb push_back
#define debug(X) cout << "debug : " << #X << " = " << X << '\n'; //int,char,char[]
#define debugc(X,Y)  for( int VAR = 0; VAR < Y; VAR++) cout << "debugc : " << #X <<'[' << VAR << "]  = " << *(X+VAR) << '\n'; // int[], char[] c
#define debugstl(X)  for( int VAR = 0; VAR < X.size(); VAR++) cout << "debugstl : "<< #X << '[' << VAR << "] = " << X[VAR] << '\n';// stl vector,string
#define MOD 1000000007
#define maxn 5005
int main(){
	int dp[maxn];
	string s, t;
	cin >> s >> t;
	int n = s.size();
	int m = t.size();
/*
	for (int i = 0; i < m; ++i){
		for (int j = n - 1; j >= 0; --j){
			if (t[i] == s[j]){
				dp[j+1] = (dp[j+1] + dp[j] + 1) % MOD;
			}
		}
	}
*/
	for (int i = 0; i < m; ++i) {
		for (int j = n - 1; j > -1; --j) {
			if (s[j] == t[i]) {
				dp[j + 1] = (dp[j + 1] + dp[j] + 1) % MOD;
			}

		}
	}
	int ret = 0;
	for (int j = 0; j <= n; ++j) {
		ret = (ret + dp[j]) % MOD;
	}
	cout << ret << endl;
/*
	int ans = 0;
	for (int i = 0; i <= n; ++i)
		ans = (ans + dp[i]) % MOD;
	cout << ans << endl;
*/
	return 0;
}

#include <iostream>
#include <string>
#include <string.h>

#define MOD 1000000007

using namespace std;
string x,y;

int cache[5000][5000];

int solve(int a, int b) {
    if(a==x.size() || b==y.size()) return 0;
    if(cache[a][b]!=-1) return cache[a][b];
    int ret = solve(a,b+1);
    if(x[a] == y[b]) {
        ret+=1+solve(a+1,b+1);
        ret%=MOD;
    }
    return cache[a][b]=ret%MOD;
}

int main() {
    memset(cache,-1,sizeof(cache));
    cin>>x>>y;
    int res=0;
    for(int i=0;i<x.size();i++) res+=solve(i,0);
    cout<<res;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(I,A,B) for(long long i=I;i<A;i+=B)
#define rep(I,A,B) for(long long j=I;j<=A;j+=B)
#define repp(I,A,B) for(long long j=I;j>=A;j-=B)
#define str(A) for(long long k=0;A[k]!='\0';k++)
#define pb push_back
#define mp make_pair
#define pii pair<long long,long long>
#define all(v) v.begin(),v.end()
vector <int> adj[100001];
bool visit[100001];
const int mod = 1000000007;
ll mod_mult(ll a,ll b)
{
	return ((a%mod)*(b%mod))%mod;
}
ll mult(ll x,ll y) { ll prod = 1; while(y>0){ if(y&1) prod = mod_mult(prod,x); x=mod_mult(x,x); y/=2;} return prod;}
string t,s;
ll dp[5001][5001];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>s>>t;
	int n1 = s.length(), n2 = t.length();
	memset(dp,0,sizeof(dp));
	ll ans = 0;
	vector<int> carr(5002,0);
	for(int i = 0; i<n1; i++)
	{
		for(int j = 0; j<n2; j++)
		{
			if(s[i]==t[j])
			{
			    if(j)
			        dp[i][j] = (1 + carr[j-1]%mod)%mod;
			    else
			        dp[i][j] = 1;
			}
			ans = (ans%mod+dp[i][j]%mod)%mod;
		}
		for(int j = 0; j<n2; j++)
			if(!j)
			    carr[j] = dp[i][j];
			else
			    carr[j] = carr[j-1]+dp[i][j];
	}
	cout<<ans;
	return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <utility>
#include <numeric>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

string sstString, ssqString;

vector<vector<int> > dpData;

int main()
{
    getline(cin, sstString);
    getline(cin, ssqString);
    dpData = vector<vector<int> >(sstString.length() + 1,
                                 vector<int>(ssqString.length() + 1,
                                            0));

    for(int sstFirstIndex = sstString.length(); sstFirstIndex--;)
        for(int ssqFirstIndex = ssqString.length(); ssqFirstIndex--;)
        {
            dpData[sstFirstIndex][ssqFirstIndex] = dpData[sstFirstIndex][ssqFirstIndex + 1];
            if(ssqString[ssqFirstIndex] == sstString[sstFirstIndex])
                dpData[sstFirstIndex][ssqFirstIndex] += dpData[sstFirstIndex + 1][ssqFirstIndex + 1] + 1;
        }

    ull result = 0;

    for(int i = sstString.length(); i--;)
        result += dpData[i][0];

    printf("%I64d", result % 1000000007);

    return 0;
}

# include<bits/stdc++.h>

using namespace std;

// Basic
typedef long long 		ll;
typedef long double 		ld;

// Pair
typedef pair<int, int >	   ii;
typedef pair<ll, ll>		   LL;
typedef pair<int, string >	istr;

// List
typedef vector<int >		vi;
typedef vector<vi >		vvi;
typedef vector<ll >		vll;
typedef vector<vll >    vvll;

typedef vector<ii >		vii;
typedef vector<LL >		vLL;

typedef vector<string > vstr;
typedef vector<istr>		vistr;

// Map
typedef map<ll, int > 		mpll;
typedef map<string, int>	mpstr;

// Set
typedef set<string > 		sstr;
typedef set<int >    		si;
typedef set<ii > 				sii;

// multiset
typedef multiset<int >		msi;
typedef multiset<ii >		msii;

// Stacks and Queue
typedef queue<char >       qc;
typedef queue<int >        qi;

typedef stack<char >       stc;
typedef stack<int >        sti;

// ---------------- Value Manipulators --------------------
const int    inf  = 1e9;
const double pi   = acos(-1);
const int    SLMT = 1e5 + 5;
const int    ALMT = 1e6 + 5;

# define ROUND(x)	(int)((double)x + 0.5)

//------------------ REPEAT --------------------------------
# define repf(i, a, b)	for(auto i = a; i != b; ++i)
# define repr(i, a, b)	for(auto i = a; i != b; --i)
# define repstr(i, str)	for(auto i = 0; str[i]; ++i)

// # define uDia(i, j, m, n)	repf(i,0,m) repf(j, i+1, n)
// # define lDia(i, j, m, n)	repf(i,0,m) repf(j,0,i)
// # define cMat(i, j, m, n)	repf(i,0,m)	repf(j,0,n)

// ----------------- STL -----------------------------------
# define mp(x, y)		make_pair(x, y)
# define pb(x) 		    push_back(x)
# define pob()			pop_back()
# define stlf(x)		x.begin(), x.end()
# define stlr(x)		x.rbegin(), x.rend()
# define F				first
# define S				second

// ----------------- I/O -----------------------------------
# define gc()			getchar()
# define pc(x)			putchar(x)

# define ss(str)		scanf("%s", str)
# define ps(str)		puts(str)

# define pnl			pc('\n')

# define sll(x)		sd(x)
# define pll(x)      pd(x)

template <class T >
inline void sd(T &num){

	num = 0;
	int sign = 0;
	char ch;

	while(isspace(ch = gc()));

	if(isdigit(ch))
		num = ch - '0';
	else
		sign = ch == '+' ? 0: 1;

	while(isdigit(ch = gc()))
		num = (num << 3 ) + (num << 1) + ch - '0';

	num = sign ? -num : num;
}

template <class T >
inline void pd(T num, char ch = ' '){
   if(num < 0){
     pc('-');
     num = -num;
   }

   char digits[21] = {};
   int pos = 1;

   do{
      digits[pos++] = '0' + num%10;
   }while(num /= 10);

   while(--pos)
      pc(digits[pos]);

   pc(ch);
}

# define sdbl(x)	 scanf("%f", &x)
# define pdbl(x,y)   printf("%.*f ",x,y)
# define pf(x)       printf("%f", x)

// Input int array
template <class T>
inline void iArr(T &arr, int size){
	repf(i, 0, size)
		sd(arr[i]);
}

// Input map input integers
template <class T>
inline int mArr(T &arr, int size){
   int val;
   int mval = INT_MIN;
	repf(i, 0, size)
		sd(val), ++arr[val], mval = max(mval, val);
   return mval;
}

template <class T>
inline void oArr(T &arr, int size){
	repf(i, 0, size)
		pd(arr[i]);
	pnl;
}

template <class T>
inline void iMat(T &mat, int n, int m){
	repf(i, 0, n)
		repf(j, 0, m)
			sd(mat[i][j]);
}

template <class T>
inline void oMat(T &mat, int n, int m){
	repf(i, 0, n){
		repf(j, 0, m)
			pd(mat[i][j]);
		pnl;
	}
}

// character matrix fix :
inline void oMat(char **mat, int n){
	repf(i, 0, n)
	   ps(mat[i]);
}

inline void iMat(char **mat, int n){
	repf(i, 0, n)
		ss(mat[i]);
}

# define lb(x)		lower_bound(x)
# define ub(x)		upper_bound(x)

# define lb(x, y, val)	lower_bound(x, y, val)
# define ub(x, y, val)	upper_bound(x, y, val)

// --------------------------------------------------
// ------------- Data Fillers -----------------------
// --------------------------------------------------

template <class T>
inline void MAT(T **&mat, int r, int c, T val = 0){
   mat = new T*[r];

   if(!val){
    repf(i, 0, r)
      mat[i] = new T[c]();
      return ;
   }

   repf(i, 0, r){
      mat[i] = new T[c];
      repf(j, 0, c)
         mat[i][j] = val;
   }
}

template <class T>
inline void ARR(T *&arr, int n, int val = 0){
   arr = new T[n];
   fill(arr, arr+n, val);
}

// --------------------------------------------------
// ------------ CODE MODES --------------------------
// --------------------------------------------------
# define FAST		ios_base::sync_with_stdio(false); cin.tie(0);
# define TC			int tc; sd(tc); while(tc--)

// --------------------------------------------------
// ----------------- Debugging ----------------------
// --------------------------------------------------
int bug = 0;
# define ok cout<<"OK-"<<bug++<<endl;

// --------------------------------------------------
// ------------- Additional Data --------------------
// --------------------------------------------------

// ---------------------------------------------------------------
// --------------------- Support Codes	--------------------------
// ---------------------------------------------------------------

// ---------------------------------------------------------------
// ------------------------ END	----------------------------------
// ---------------------------------------------------------------

const int MLEN = 5e3 + 1;

const int MOD = 1e9+7;

char s1[MLEN], s2[MLEN];
int dp[MLEN][MLEN];

int main(void){

    ss(s1);
    ss(s2);

    int len1 = strlen(s1);
    int len2 = strlen(s2);

    dp[len1][len2] = 1;
    repr(i, len1-1, -1)
        repr(j, len2-1, -1)
            dp[i][j] = dp[i][j+1] + (s1[i] == s2[j] ? 1 + dp[i+1][j+1] : 0) % MOD;

    int ans = 0;
    for(int i = 0; i < len1; ++i)
        ans += dp[i][0];

    pd(ans);

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d,l1,l2,sum=0,dp[5050][5050];
	char ch1[5050],ch2[5050];
	while(cin>>ch1>>ch2)
	{
	l1=strlen(ch1);
	l2=strlen(ch2);
	for(int i=0;i<l1;i++)
		for (int j=0;j<l2;j++)
		{
			dp[i+1][j+1]=(dp[i+1][j]+(ch1[i]==ch2[j])*(dp[i][j]+1));
		}
	for(int i=1;i<=l1;i++)
		sum+=dp[i][l1];
	cout<<sum;
	}
	return 0;
}

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>

#if LOCAL
	#define DO_NOT_SEND
#endif

typedef long long LL;

int IntMaxVal = (int) 1e20;
int IntMinVal = (int) -1e20;
LL LongMaxVal = (LL) 1e20;
LL LongMinVal = (LL) -1e20;

#define FOR(i, a, b) for(int i = a; i < b ; ++i)
#define FORD(i, a, b) for(int i = a; i >= b; --i)

#define minimize(a, b) { a = min(a, b); }
#define maximize(a, b) { a = max(a, b); }

#define all(v) v.begin(),v.end()

using namespace std;

template<typename T> struct argument_type;
template<typename T, typename U> struct argument_type<T(U)> { typedef U type; };
#define next(t, i) argument_type<void(t)>::type i; cin >> i;
#define nextVector(t, v, size) vector< argument_type<void(t)>::type > v(size); { for (int i = 0 ; i < size ; i++) cin >> v[i]; }

#define range(name, start, count) vector<int> name(count); { for (int i = 0 ; i < count ; i++) name[i] = i + start; }

template <typename T1, typename T2> istream& operator >>(istream& is, pair<T1, T2>& s) { is >> s.first >> s.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T> &v) { for (int i = 0 ; i < v.size() ; i++) os << v[i] << ' '; os << endl; return os; }
template <typename T1, typename T2> ostream& operator <<(ostream& s, pair<T1, T2>& t) { s << t.first << ' ' << t.second; return s; }

template <typename T> vector<T> readVector(int n) { vector<T> res(n); for (int i = 0 ; i < n ; i++) cin >> res[i]; return res; }

int main() {
	srand (time(NULL));
    ios_base::sync_with_stdio(false); cin.tie(NULL);

	next(string, s1);
	next(string, s2);
	int n = s1.length();
	int m = s2.length();

	LL res = 0;

	vector<LL> startFrom(m);

	FORD (i, n - 1, 0) {
		vector<LL> startFromNext(m);
		FORD (j, m - 1, 0) if (s1[i] == s2[j]) {
			startFromNext[j]++;
			if (i < n - 1 && j < m - 1) startFromNext[j] += startFrom[j + 1];
		}

		auto curVal = accumulate(all(startFromNext), 0LL);
		res += curVal;
		swap(startFrom, startFromNext);
		FORD (j, m - 2, 0) startFrom[j] += startFrom[j + 1];
	}

	cout << res;
}

#include<bits/stdc++.h>
#define maxn 5500
using namespace std;
char S[maxn];
char T[maxn];
int f[maxn][maxn];
int n,m;
int main(){
	scanf("%s%s",S+1,T+1);
	n=strlen(S+1);
	m=strlen(T+1);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			f[i][j]=f[i][j-1];
			if(S[i]==T[j]){
				f[i][j]+=f[i-1][j-1]+1;
			}
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ans+=f[i][m];
	}
	printf("%d",ans%1000000007);
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[5010][5010];
string s, t;

int main(){
	cin>>s>>t;
	ll curr = 0;
	for (int i=0; i<s.length(); i++){
		if (s[i] == t[0]){
		    curr++;
	    }
	    dp[i][0] = curr;
	}
	curr = 0;
	for (int i=0; i<t.length(); i++){
		if (t[i] == s[0]){
			curr++;
		}
		dp[0][i] = curr;
	}
	for (int i=1; i<s.length(); i++){
		for (int j=1; j<t.length(); j++){
			if (s[i] == t[j]){
				if (i>1) dp[i][j] = (dp[i][j-1]+dp[i-1][j]+(ll)1-dp[i-2][j-1]);
				else dp[i][j] = (dp[i][j-1]+dp[i-1][j]+(ll)1);
			}
			else{
				dp[i][j] = (dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]);
			}
		}
	}
	ll res = dp[s.length()-1][t.length()-1]%(ll)1000000007;
	cout<<res<<endl;
}

#include <stdio.h>
#include <stdlib.h>
int n,m,x,y;
int ata,atb;
int A[100001];
int B[100001];
int ans;
int pri[100001];
int pri2[100001];
main()
{
 scanf("%d%d%d%d",&n,&m,&x,&y);
 for(int i=1;i<=n;i++)
 {
  scanf("%d",&A[i]);
 }
 for(int i=1;i<=m;i++)
 {
  scanf("%d",&B[i]);
 }
 ata=1;atb=1;
 while(ata<=n&&atb<=m)
 {
  if(A[ata]+y<B[atb]){ata++;}
  else if(A[ata]-x>B[atb]){atb++;}
  else{ans++;pri[ans]=ata;pri2[ans]=atb;ata++;atb++;}
 }
 printf("%d\n",ans);
 for(int i=1;i<=ans;i++)
 {
  printf("%d %d\n",pri[i],pri2[i]);
 }
 //system("pause");
      return 0;
}

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>

using namespace std;

string s, t;

int d[5001][5001];
int cnt[256];

const int M = 1000000007;

int main()
{
	cin >> s >> t;

	for(int i = 1; i <= s.size(); i++)
	{
		//memset(cnt, 0, sizeof cnt);
		for(int j = 1; j <= t.size(); j++)
		{
			char si = s[i - 1];
			char tj = t[j - 1];

			//cnt[tj]++;

			//d[i][j] = d[i - 1][j];
			d[i][j] = (d[i][j - 1] + d[i - 1][j]) % M;
			d[i][j] = (d[i][j] - d[i - 1][j - 1] + M) % M;

			//d[i][j] = (d[i][j] + cnt[si]) % M;

			if (si == tj)
			{
				d[i][j] = (d[i][j] + d[i - 1][j - 1] + 1) % M;
				if (i - 2 >= 0)
				{
					d[i][j] = (d[i][j] - d[i - 2][j - 1] + M) % M;
				}
			}
			printf("%4d", d[i][j]);
		}
		puts("");
	}

	printf("%d\n", d[s.size()][t.size()]);

	return 0;
}

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <math.h>
#include <iomanip>
using namespace std;

#define FOR0(i,n) for( i = 0 ; i < n ; i++ )
#define FOR1(i,n) for( i = 1 ; i <= n ; i++ )
#define sys_p system( "pause" )
#define End return 0
#define pb push_back
#define mp make_pair

ifstream Cin("input.txt");
ofstream Cout( "output.txt" );

typedef long long ll ;

main()
{
      string a, b ;
      ll i, j, dp[5005][5005], ans = 0 ;
      cin >> a >> b ;
      for( i = a.length() - 1 ; i >= 0 ; i-- )
        for( j = b.length() - 1 ; j >= 0 ; j-- )
        {
              dp[i][j] = dp[i][j+1] ;
              if( a[i] == b[j] )
                dp[i][j] = ( dp[i][j] + dp[i+1][j+1] + 1 ) % 1000000007 ;
        }
      FOR0( i, a.length() )
        ans += dp[i][0] ;
      cout << ans ;
}

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define PB push_back
#define SZ(X) ((int)(X.size()))
#define ALL(X) (X).begin(), (X).end()
#define FE(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define MOD 1000000007

const double PI=acos(-1.0);
const double EPS=1e-10;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef vector<string> vstr;
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}
#define MAXN 5500

char s[MAXN];
char t[MAXN];

ll dp[2][MAXN];

void solve(){
  scanf("%s",s);
  scanf("%s",t);
  int lenS=strlen(s);
  int lenT=strlen(t);
  memset(dp,0,sizeof dp);

  ll res=0;
  for(int j=lenT-1;j>=0;j--){
    if(s[lenS-1]==t[j]) dp[(lenS-1)&1][j]=1;
    else dp[(lenS-1)&1][j]=0;
    res+=dp[(lenS-1)&1][j];
  }

  for(int i=lenS-2;i>=0;i--){
    ll acum=1;
    for(int j=lenT-1;j>=0;j--){

      if(s[i]==t[j]){
         dp[i&1][j]=(dp[i&1][j]+acum)%MOD;
      }
      else dp[i&1][j]=0;

      res=(res+dp[i&1][j])%MOD;

      if(s[i+1]==t[j]) acum=(acum+dp[1-(i&1)][j])%MOD;
    }
  }

  cout << res << endl;

}

int main(){
  #ifdef BLOCAL
    while(1)
  #endif

  solve();

  return 0;
}

#include <bits/stdc++.h>
using namespace std;

vector<int> p[256];

int main()
{
	long long int ans = 0, e = 1;
	char a[5005], b[5005];
	scanf("%s %s",a , b);
	for(int i=0; b[i]!='\0'; i++){
		int c = b[i];
		p[c].push_back(i);
	}
	ans += p[a[0]].size();
	vector<long long int> z(ans,1);
	for(int i=1; a[i]!='\0'; i++){
		int c = a[i], d = (int)a[i-1];
		vector<long long int> x(p[c].size(),0);
		for(int j=0; j<p[d].size(); j++){
			e = lower_bound(p[c].begin(), p[c].end(), p[d][j]+1) - p[c].begin();
			if(e!=x.size() && p[d][j]<p[c][e]){
				x[e] += z[j];
			}
		}
		e = 1;
		for(int j=0; j<p[c].size(); j++){
			e += x[j];
			x[j] = e;
			ans += e;
		}
		z = x;
	}
	cout<<ans<<endl;
}

#include<iostream>
using namespace std;
typedef long long ll;

const int MAX = 5000+10;
const ll D = 1000ll*1000*1000*7;
ll d[MAX+10][MAX+10];
string s,t;

void dyn()
{
	ll sum = 0;
	for(int i=0; i<(int)s.size(); i++)
	{
		sum = 1;
		for(int j=0; j<(int)t.size(); j++)
		{
			if( s[i] == t[j] )
				d[i][j] = sum;
			if( i != 0 )
				sum += d[i-1][j];
		}
	}
}

ll Sum()
{
	ll sum = 0;
	for(int i=0; i<(int)s.size(); i++)
		for(int j=0; j<(int)t.size(); j++)
			sum += d[i][j] + ( sum > D ? -D : 0 );
	return sum % D;
}

int main()
{
	cin >> s >> t;
	dyn();
	cout << Sum() << endl;
	return 0;
}

#include<iostream>
#include<map>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;
#define ll __int64
#define MOD 1000000007
#define MMOD 1000000009
map<int,int>mp;
string A,B;
void get_data(){
    cin>>A>>B;
    mp.clear();
}
ll num[10000];
ll f_mul(ll x,int n){
    ll r=1;
    while(n){
        if(n&1)r=(r*x)%MOD;
        n>>=1;
        x=(x*x)%MOD;
    }
    return r;
}
void run(){
    int i,j;
    ll t=0;
    for(i=0;i<A.size();i++){
        num[i]=(t*MMOD+A[i])%MOD;
        t=num[i];
    }
    for(i=0;i<A.size();i++){
        for(j=i;j<A.size();j++){
            t=((num[j]-num[i]*f_mul(MMOD,j-i))%MOD+MOD)%MOD;
            mp[t]++;
        }
    }
    t=0;
    for(i=0;i<B.size();i++){
        num[i]=(t*MMOD+B[i])%MOD;
        t=num[i];
    }
    ll res=0;
    for(i=0;i<B.size();i++){
        for(j=i;j<B.size();j++){
            t=((num[j]-num[i]*f_mul(MMOD,j-i))%MOD+MOD)%MOD;
            res+=mp[t];
            res%=MOD;
        }
    }
    printf("%I64d\n",res);
}
int main(){
    get_data();
    run();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
int main()
{
	int a,b,c,d,l1,l2,sum=0,dp[5050][5050];
	char ch1[5050],ch2[5050];
	while(cin>>ch1>>ch2)
	{
	l1=strlen(ch1);
	l2=strlen(ch2);
	for(int i=0;i<l1;i++)
		for (int j=0;j<l2;j++)
		{
			dp[i+1][j+1]=(dp[i+1][j]+(ch1[i]==ch2[j])*(dp[i][j]+1));
		}
	for(int i=1;i<=l1;i++)
	sum=(sum+dp[i][l2])%md;
	cout<<sum;
	}
	return 0;
}

/**
 	▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
		Make it happen now, not tomorrow.
		Tomorrow is a loser's excuse.
 	▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
**/
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplu >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <cstring>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include<random>
#include <chrono>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplu >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#endif
#define __ ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
// #define INF 0x7f7f7f7f
#define ull unsigned long long int
#define pii pair<int,int>
#define ll long long int
#define ld long double
#define MSET(x,y) memset(x,y,sizeof(x))
// #define l long
#define se second
#define fi first
#define NIL 0
#define UNVISITED -1
#define EXPOLORED 0
#define mk make_pair
#define pb push_back
#define sc(n) scanf("%d",&n)
#define NIL 0
#define pii pair<int,int>
#define eps 1e-8
#define all(x) x.begin(),x.end()
#define me(u,v,w) make_pair(w,make_pair(u,v))
#define sqr(x) x*x
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define inrange(x,y,row,col) (x>=0 && y>=0 && x<row && y<col)
#define foreach(e, x) for(__typeof(x.begin()) e = x.begin(); e != x.end(); ++ e)
// #define add(a,b) (a + b >= MOD ? a+b-MOD:a+b)
#define hs(c1,c2) (256*min(c1,c2) + max(c1,c2))
typedef struct{ int sum,suf,pre,max;} Node;
int toint(const string &s) { stringstream ss; ss << s; int x; ss >> x; return x; }
const int N = 55;
const int inf = 1e9;
const int lim = 1e18+1;
const int mod = 1e9+7;
const double pi = 3.141592653589793238462643383;
const int M = 1e6+10;
const double Phi =  1.618033988749894;
const int logn = 20;
const double phi = 0.618033988749894;
const double root5 = 2.236067977;
/**
 	▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
		Make it happen now, not tomorrow.
		Tomorrow is a loser's excuse.
 	▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
**/
char s[5010],t[5010];
int f[5010][5010];
int main(){
	scanf("%s%s",s+1,t+1);
	int n = strlen(s+1);
	int ans = 0;
	int m = strlen(t+1);
	for(int i=0;i<=max(n,m);++i)f[0][i] = f[i][0] = 1;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			f[i][j] = f[i][j-1];
			if(s[i] == t[j])f[i][j] += f[i-1][j-1];
			f[i][j] %= mod;
		}
		ans += (f[i][m])%mod;
	}
	cout<<(ans - n + mod)%mod << endl;
	return 0;
}

/**
 	▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
		Make it happen now, not tomorrow.
		Tomorrow is a loser's excuse.
 	▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
**/

/**
 	▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
		Make it happen now, not tomorrow.
		Tomorrow is a loser's excuse.
 	▂▃▅▇█▓▒░۩۞۩ ۩۞۩░▒▓█▇▅▃▂
**/

#include<bits/stdc++.h>
using namespace std;
string s,t;
int memo[5001][5001];
#define modulo 1000000007

int pares(int i,int j){
    if (i>s.length()-1 || j>t.length()-1)return 0;
    if (memo[i][j]!=-1)return memo[i][j];
    memo[i][j]=((pares(i, j+1))+((s[i]==t[j])*(pares(i+1,j+1)+1)))%modulo;
    return memo[i][j];

}

int main(){
    cin>>s;cin>>t;
    for (int k1=0;k1<5001;++k1)for (int k2=0;k2<5001;++k2)memo[k1][k2]=-1;

    int suma=0;
    for (int k=0;k<s.length();k++){
        suma+=pares(k,0);
    }
    cout<<suma;
    return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
string s1,s2;
const long long mod=1e9+7;
long long sum,l1,l2,dp[5100][5100];
int main()
{
	while(cin>>s1>>s2)
	{
		l1=s1.size();l2=s2.size();
		memset(dp,0,sizeof(dp));
		for(int i=0;i<l1;i++)
		{
			for(int j=0;j<l2;j++)
			{
				dp[i+1][j+1]=(dp[i+1][j]+(s1[i]==s2[j])*(dp[i][j]+1));
			}
		}
		for(int i=1;i<=l1;i++)
		{
			sum=(sum+dp[i][l2])%mod;
		}
		printf("%lld",sum);
	}
	return 0;
}

#include <iostream>
#include <sstream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <stdio.h>

using namespace std;

#define fo(i,n) for(int i=0; i<(int)n; i++)
#define rep(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#define mp(a,b) make_pair(a,b)
#define pb(x) push_back(x)
#define pii pair<int,int>

const int mod = 1000000007;

string s,t;
int dp[5010][5010][2];
int n,m;

int sum(int a, int b) {
    int c = a+b;
    if (c>=mod) c -= mod;
}

int solve(int i, int j, int k) {
    if (i==n || j==m) {
        return 0;
    }
    if (dp[i][j][k]>=0) return dp[i][j][k];

    int tmp = 0;
    if (k) {
        if (s[i]==t[j]) {
            tmp = sum(1+solve(i+1,j+1,1), solve(i,j+1,1));
        }
        else {
            tmp = solve(i,j+1,1);
        }
    }
    else {
        if (s[i]==t[j]) {
            tmp = sum(solve(i+1,j,0), solve(i,j+1,1));
            tmp = sum(1+solve(i+1,j+1,1),tmp);
        }
        else {
            tmp = sum(solve(i+1,j,0), solve(i,j+1,1));
        }
    }
    //cout<<i<<" "<<j<<" "<<k<<" "<<tmp<<endl;
    dp[i][j][k] = tmp;
    return tmp;
}

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    cin>>s>>t;
    n = s.length();
    m = t.length();
    for (int i=0; i<n; i++) for (int j=0; j<m; j++) for (int k=0; k<2; k++) dp[i][j][k] = -1;

    cout<<solve(0,0,0);

    return 0;

}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sz(x) (ll)(x.size())
#define f first
#define se second
int main(){
    string s,t;
    cin>>s>>t;
    ll n=sz(s),m=sz(t);
    vector<vector<ll> > dp(n+1,vector<ll>(m+1,0));
    for(ll i=n-1;i>=0;i--){
        for(ll j=m-1;j>=0;j--){
            if(s[i]==t[j]){
                dp[i][j]=dp[i+1][j+1]+1+dp[i][j+1];
            }else{
                dp[i][j]=dp[i][j+1];
            }
        }
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        ans+=dp[i][0];
    }
    cout<<ans;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

typedef map<ll,ll> M;
#define MEM(a, b) memset(a, (b), sizeof(a)) //fill value
#define FI(i, j, k, in) for (int i=j ; i<k ; i+=in) //from j till k increment by in FOR INT
#define fl(i, j, k, in) for (long long int i=j ; i<k ; i+=in) //from j till k increment by in FOR LL
#define fll(i, j, k) for (long long int i=j ; i<k ; i+=1) //from j till k increment by in FOR LL
#define FULL(i, j, k, in) for (unsigned long long int i=j ; i<k ; i+=in) //from j till k increment by in FOR ULL
ll mod=pow(10,9)+7;
ll inf=pow(10,18)+16;

int main() {

	// your code here
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s,t;
	cin>>s>>t;

	ll dp[5005][5005]; //dp[i][j] denotes the number of different pairs for the substrings
	//starting at i and the subsequence of substring starting at j

	memset(dp,0,sizeof(dp));

    ll len1=s.length(),len2=t.length();

    for(ll i=len1-1;i>=0;i--)
    {
        for(ll j=len2-1;j>=0;j--)
        {
            dp[i][j]+=dp[i][j+1];

            if(s[i]==t[j])
            {
                dp[i][j]+=dp[i+1][j+1]+1;
            }

        }
    }
    ll res=0;
    fll(i,0,len1)
    res+=dp[i][0];

    cout<<res<<endl;
	return 0;
}

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <math.h>
#include <iomanip>
using namespace std;

#define FOR0(i,n) for( i = 0 ; i < n ; i++ )
#define FOR1(i,n) for( i = 1 ; i <= n ; i++ )
#define sys_p system( "pause" )
#define End return 0
#define pb push_back
#define mp make_pair

ifstream Cin("input.txt");
ofstream Cout( "output.txt" );

typedef long long ll ;

main()
{
      ll i, j, la, lb, dp[5005][5005] = { }, ans = 0 ;
      char a[5005], b[5005] ;

      cin >> a >> b ;
      la = strlen( a ) ;
      lb = strlen( b ) ;

      for( i = la - 1 ; i >= 0 ; i-- )
        for( j = lb - 1 ; j >= 0 ; j-- )
        {
              dp[i][j] = dp[i][j+1] ;
              if( a[i] == b[j] )
                dp[i][j] = dp[i][j] + dp[i+1][j+1] + (long long)1 ;
              dp[i][j] = dp[i][j] % 1000000007 ;
        }
      FOR0( i, la )
        ans += dp[i][0] ;
      cout << ans ;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e3+5;
const int Mod=1e9+7;
int n, a[N], dp[N][N], ans=0;
string s,t;
 main()
{
	cin>>s>>t;
	for(int i=0; i<s.size(); i++)
		{
			for(int j=0; j<t.size(); j++)
			{
				dp[i][j]=dp[i][j-1]%Mod;
				if(s[i]==t[j])
					dp[i][j]=(dp[i][j]+dp[i-1][j-1]+1)%Mod;
				if(j==t.size()-1)ans=(ans+dp[i][j])%Mod;
			}
		}
	cout<<ans;
}

#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <cstdlib>
#include <cassert>
using namespace std;
void solve();

#define pb push_back
#define mp make_pair

typedef long long li;
typedef vector<li> vi;
typedef pair<int, int> pi;

int main() {
#ifdef DEBUG
    freopen("input", "r", stdin);
    //freopen("output","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}
li ans;
void solve(){
    string s,t;
    cin>>s>>t;
    s+='#';
    li cur[5555];
    for(int i=0;i<5555;++i){
        cur[i]=1;
    }
    for(int k=0;k<t.size();++k){
        for(int i=s.size()-1;i>=0;--i){
            if(t[k]==s[i]){
                ans+=cur[i];
                cur[i+1]+=cur[i];
            }
        }
    }
    cout<<ans;
}

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>

#define eps 1e-8
#define vi vector<int>
#define pb(x) push_back(x)
#define f(i,x,y) for(int i=x;i<y;i++)
#define rf(i,y,x) for(int i=y;i>=x;i--)
#define all(x) (x).begin(),(x).end()
#define cout1(x) cout<<x<<endl
#define cout2(x,y) cout<<x<<" "<<y<<endl
#define cout3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl
#define bit(x) __buitin_popcount(x)
#define MAXN 5001
#define K 10007
#define MOD 1000000007
//^

using namespace std;

char s[MAXN], t[MAXN];
int memo[MAXN][MAXN][2], n, m;

int main(){

    while(scanf("%s%s", s, t) == 2){

        n = strlen(s);
        m = strlen(t);

        memset(memo, 0, sizeof memo);

        for(int i = 0; i <= n; i++)memo[i][m][1] = 1;
        for(int i = 0; i <= m; i++)memo[n][i][1] = 1;

        for(int i = n - 1; i >= 0; i--){
            for(int j = m - 1; j >= 0; j--){
                for(int k = 0; k < 2; k++){
                    memo[i][j][k] = memo[i][j + 1][k];
                    if(s[i] == t[j])memo[i][j][k] += memo[i + 1][j + 1][1];
                }
            }
        }

        long long res = 0;
        for(int i = 0; i < n; i++)res = (res + memo[i][0][0])%MOD;
        cout1(res);
    }
}

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define debug(x) cerr << "[" << #x << ": "<< x << "]" << endl;
#define debug2(x, y) cerr << "[" << #x << ": "<< x << "  " << #y << ": "<< y << "]" << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define ar array
#define se second
#define sz(x) ((int)(x).size())
#define ends "\n"
#define sp ' '

const long long M=1e9+7;
typedef long long ll;
typedef pair<int, int> pii;
long long mul(long long x, long long y){ return ((x%M)*(y%M)%M); }
long long binpow(long long x, long long y){ long long z=1; while(y){ if(y&1LL) z=mul(z, x); x = mul(x, x); y >>= 1LL; } return z; }
long long inv(long long x){ return binpow(x, M - 2); }
long long divide(long long x, long long y){ return mul(x, inv(y)); }

const int N=5005;
long long dp[N][N];
int n1, n2;
string s1, s2;

void solve(){
	n1=sz(s1), n2=sz(s2);
	cout << n1 << sp << n2 << ends;
	for(int i=1; i<=n1; ++i){
	    for(int j=1; j<=n2; ++j){
                dp[i][j]=dp[i][j-1];
            if(s1[i-1]==s2[j-1])
                dp[i][j]+=1+dp[i-1][j-1];
	    }
	}
	long long ans=0;
        for(int i=n1; i>=1; --i){
            ans=(ans+dp[i][n2])%M;
        }
	for(int i=1; i<=n1; ++i){
        for(int j=1; j<=n2; ++j)
            cout << dp[i][j] << sp;
        cout << ends;
	}
	cout << ans;
}
void input(){
	cin >> s1 >> s2;
}

void test_case(){
	input();
	solve();
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int q, multicase=0;

    if(multicase) cin >> q;
    else q=1;

    for(int i=1; i<=q; ++i)
		test_case();

}

#include<bits/stdc++.h>
using namespace std;

char s[5001];
char t[5001];
long long f[5001][5001];
long long ls,lt;
const long long mod=1000000007;

int main(){
	gets(s);
	gets(t);
	ls=strlen(s);
	lt=strlen(t);
	for(register long long i=0;i<ls;++i){
		for(register long long j=0;j<lt;++j){
			if(s[i]==t[i]){
				f[i][j]=(f[i][j]+f[i-1][j-1]+1)%mod;
			}
			f[i][j]=(f[i][j]+f[i][j-1])%mod;
		}
	}

	long long res=0;

	for(register long long i=0;i<ls;++i){
		res=(res+f[i][lt])%mod;
	}
	cout<<res;
	return 0;
}

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <set>
#include <map>
using namespace std;

const int maxn = 5005;
const int modulo = 7 + (int)1e9;
int dp[maxn][maxn];
int presum[maxn][maxn];
char s[maxn], t[maxn];

int main()
{
#ifdef moskupols
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%s%s", s, t);
	int n = strlen(s), m = strlen(t);

	memset(dp, 0, sizeof dp);
	memset(presum, 0, sizeof presum);
	int ans = 0;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
		{
			if (s[i] == t[j])
			{
				ans += dp[i][j] = (i&&j ? presum[i-1][j-1] : 0) + 1;
				if (dp[i][j]==modulo)
					dp[i][j] = 0;
				if (ans == modulo)
					ans = 0;
			}
			presum[i][j] = (j?presum[i][j-1]:0) + dp[i][j];
			if (presum[i][j]==modulo)
				presum[i][j] = 0;
		}

	printf("%d\n", ans);

	return 0;
}

#include <iostream>
#include <bitset>
#include <queue>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
using namespace std;

int dp[5050][5050];
int mod=1000000007;

int n,m;
string s,t;
int main(){
	cin>>s>>t;
	n=s.length();
	m=t.length();
	s=" "+s;
	t=" "+t;
	for(int i=0;i<=n;i++){
		dp[i][0]=1;
	}
	for(int i=0;i<=m;i++){
		dp[0][i]=1;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			dp[i][j]=0;
			if(s[i]==t[j]){
				dp[i][j]+=dp[i-1][j-1];
			}
			dp[i][j]+=dp[i][j-1];
			if(dp[i][j]>=mod){
				dp[i][j]-=mod;
			}
		}
	}
	int sol=0;
	for(int i=1;i<=n;i++){
		sol+=dp[i][m]-1+mod;
		sol%=mod;
	}
	cout<<sol<<endl;
}

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

const int MAXN = 5500;
char s1[MAXN], s2[MAXN];
int dp[MAXN][MAXN], num[MAXN][MAXN];

int main(){
	scanf("%s%s", s1 + 1, s2 + 1);
	int l1 = strlen(s1 + 1), l2 = strlen(s2 + 1);
	for(int i = 1; i <= l1; ++ i){
		for(int j = 1; j <= l2; ++ j){
			num[i][j] = (s1[i] == s2[j]) * (num[i - 1][j - 1] + 1);
//			printf("%d %d %d\n", i, j, dp[i][j]);
		}
	}
//	for(int i = 1; i <= l1; ++ i) for(int j = 1; j <= l2; ++ j) printf("%d %d %d\n", i, j, num[i][j]);
	for(int i = 1; i <= l1; ++ i){
		for(int j = 1; j <= l2; ++ j){
			dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + num[i][j];
			printf("%d %d %d\n", i, j, dp[i][j]);
		}
	}
//	printf("%d", dp[l1][l2]);
	return 0;
}