#include <bits/stdc++.h>
using namespace std;
string s, t;
long long d[5005][5005];
int main() {
  cin >> s >> t;
  int n = s.size(), m = t.size();
  d[0][0] = 1;
  for (int i = 0; i <= n; i++) d[i][0] = 1;
  for (int j = 0; j <= m; j++) d[0][j] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      d[i][j] = d[i][j - 1];
      if (s[i - 1] == t[j - 1])
        d[i][j] = (d[i][j] + d[i - 1][j - 1]) % 1000000007;
    }
    d[i][m] = (d[i][m] + d[i - 1][m]) % 1000000007;
  }
  cout << (d[n][m] - n - 1 + 1000000007) % 1000000007 << endl;
  return 0;
}
