#include <bits/stdc++.h>
using namespace std;
string x, y;
long long lx, ly, dp[5001][5001], res;
int main() {
  while (cin >> x >> y) {
    res = 0;
    lx = x.length();
    ly = y.length();
    for (int i = 0; i <= lx; i++)
      for (int j = 0; j <= ly; j++) dp[i][j] = 0;
    x = ' ' + x;
    y = ' ' + y;
    for (int i = 0; i <= lx; i++) {
      for (int j = 0; j <= ly; j++) {
        if (i == 0 || j == 0)
          dp[i][j] = 0;
        else if (x[i] != y[j])
          dp[i][j] = dp[i][j - 1] % 1000000007;
        else if (x[i] == y[j])
          dp[i][j] =
              dp[i][j - 1] % 1000000007 + (dp[i - 1][j - 1] + 1) % 1000000007;
      }
    }
    for (int i = 1; i <= lx; i++) {
      res = res + dp[i][ly] % 1000000007;
      res %= 1000000007;
    }
    cout << res << endl;
  }
  return 0;
}
