#include <bits/stdc++.h>
const int mo = 1e9 + 7;
using namespace std;
int n, m, i, j, ans, f[5001][5001];
char a[5001], b[5001];
int main() {
  gets(a + 1);
  gets(b + 1);
  n = strlen(a + 1);
  m = strlen(b + 1);
  for (i = 0; i <= n; i++) f[i][0] = 1;
  for (i = 0; i <= m; i++) f[0][i] = 1;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (a[i] == b[j]) f[i][j] = (f[i][j] + f[i - 1][j - 1]) % mo;
      f[i][j] = (f[i][j] + f[i][j - 1]) % mo;
    }
    ans = (ans + f[i][m] - 1) % mo;
  }
  printf("%d", ans);
}
