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