#include <bits/stdc++.h>
const int nmax = 5100;
const int mod = 1000000007;
char a[nmax], b[nmax];
int n, m;
int f[nmax];
using namespace std;
int getsum(int vt) {
  int gt = 0;
  while (vt > 0) {
    gt = (gt + f[vt]) % mod;
    vt = vt - (vt & (-vt));
  }
  return gt;
}
int update(int vt, int value) {
  while (vt <= m) {
    f[vt] = (f[vt] + value) % mod;
    vt = vt + (vt & (-vt));
  }
  return 0;
}
int main() {
  cin >> a;
  cin >> b;
  n = strlen(a);
  m = strlen(b);
  int ans = 0;
  int dem;
  for (int i = 0; i <= n; i++) f[i] = 0;
  for (int j = 1; j <= m; j++) {
    for (int i = n; i >= 1; i--) {
      if (a[i - 1] != b[j - 1]) continue;
      dem = f[i - 1] + 1;
      ans = (ans + dem) % mod;
      f[i] = (f[i] + dem) % mod;
    }
  }
  if (ans < 0) ans += mod;
  cout << ans << endl;
  return 0;
}
