#include <bits/stdc++.h>
using namespace std;
const int maxn = 5050, maxm = 5050, modnum = int(1e9 + 7);
int f[maxn][maxm];
char str1[maxn], str2[maxm];
int main() {
  scanf("%s%s", str1, str2);
  int len1 = strlen(str1), len2 = strlen(str2);
  memset(f, 0, sizeof(f));
  for (int i = 1; i <= len1; i++)
    for (int j = 1; j <= len2; j++) {
      f[i][j] = f[i][j - 1];
      if (str1[i - 1] == str2[j - 1])
        f[i][j] = (f[i][j] + f[i - 1][j - 1] + 1) % modnum;
    }
  int ans = 0;
  for (int i = 1; i <= len1; i++) ans = (ans + f[i][len2]) % modnum;
  printf("%d\n", ans);
  return 0;
}
