#include <bits/stdc++.h>
using namespace std;
string s, t;
int a[5005][5005];
int mod = 1e9 + 7;
int main() {
  cin >> s >> t;
  for (int i = 0; i < (s.size()); i++)
    for (int j = 0; j < (t.size()); j++) {
      if (j) a[i][j] = a[i][j - 1] % mod;
      if (s[i] == t[j])
        a[i][j] = (a[i][j] + ((i && j) ? a[i - 1][j - 1] : 0) + 1) % mod;
    }
  int ans = 0;
  for (int i = 0; i < (s.size()); i++) ans = (ans + a[i][t.size() - 1]) % mod;
  cout << ans;
  return 0;
}
