#include <bits/stdc++.h>
using namespace std;
char s[5010], t[5010];
long long d[5010][5010];
int main() {
  int n, m;
  scanf("%s%s", s + 1, t + 1);
  s[0] = t[0] = '#';
  n = strlen(s) - 1;
  m = strlen(t) - 1;
  int i, j;
  for (j = 1; j <= m; ++j)
    if (s[1] == t[j]) d[1][j] = 1;
  for (i = 1; i <= n; ++i)
    if (s[i] == t[1]) d[i][1] = 1;
  for (i = 1; i <= n; ++i)
    for (j = 1; j <= m; ++j) {
      if (s[i] == t[j]) d[i][j] = (d[i - 1][j - 1] + 1) % (1000000007LL);
      d[i][j] = (d[i][j] + d[i][j - 1]) % (1000000007LL);
    }
  long long ans = 0;
  for (i = 1; i <= n; ++i) ans = (ans + d[i][m]) % (1000000007LL);
  printf("%I64d\n", ans);
  return 0;
}
