#include <bits/stdc++.h>
const long long inf = LLONG_MAX;
const double eps = 1e-4;
const long long mod = 1000000007;
const double PI = acos(-1);
const long long N = 1e3 + 5;
const long long M = 1e3 + 5;
using namespace std;
long long dp[5003][5003];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long tc;
  tc = 1;
  while (tc--) {
    string s, t;
    cin >> s >> t;
    long long m = s.length(), n = t.length();
    for (long long i = 0; i < m; i++) {
      for (long long j = 0; j < n; j++) {
        dp[i + 1][j + 1] = dp[i + 1][j] % mod;
        if (s[i] == t[j]) {
          dp[i + 1][j + 1] =
              (dp[i + 1][j + 1] % mod + dp[i][j] % mod + 1) % mod;
        }
      }
    }
    long long ans = 0;
    for (long long i = 1; i <= m; i++) ans = (ans % mod + dp[i][n] % mod) % mod;
    cout << ans;
  }
}
