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