#include <bits/stdc++.h>
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];
      if (s[i] == t[j]) d[i][j] = (d[i][j] + d[i + 1][j + 1] + 1) % 1000000007;
    }
  unsigned long long ans = 0;
  for (int i = 0; i < n; ++i) ans = (ans + d[i][0]) % 1000000007;
  cout << ans;
  return 0;
}
