#include <bits/stdc++.h>
using namespace std;
char a[5100], b[5100];
int la, lb, i, j, f[5100], ans;
int main() {
  scanf("%s%s", a + 1, b + 1);
  la = strlen(a + 1);
  lb = strlen(b + 1);
  for (i = 1; i <= lb; ++i)
    for (j = la; j >= 1; --j)
      if (a[j] == b[i]) f[j] = (f[j] + f[j - 1] + 1) % 1000000007;
  for (i = 1; i <= la; ++i) ans = (ans + f[i]) % 1000000007;
  printf("%d\n", ans);
}
