#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   char s[5005], t[5005];   long long DP[5005][5005];   int main(int argc, char** argv) {     scanf( %s%s , s, t);     int lens = strlen(s);     int lent = strlen(t);     long long ans = 0;     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;   }   