#include <bits/stdc++.h>
using namespace std;
long long sum, l1, l2, dp[5500][5500];
const long long mod = 1e9 + 7;
string a, b;
int main() {
  while (cin >> a >> b) {
    sum = 0;
    memset(dp, 0, sizeof(dp));
    l1 = a.size();
    l2 = b.size();
    for (int i = 0; i < l1; i++) {
      for (int j = 0; j < l2; j++)
        dp[i + 1][j + 1] =
            (dp[i + 1][j] + (a[i] == b[j]) * (dp[i][j] + 1)) % mod;
    }
    for (int i = 1; i <= l1; i++) sum = (sum + dp[i][l2]) % mod;
    printf("%lld\n", sum);
  }
  return 0;
}
