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