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