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