#include <bits/stdc++.h>
using namespace std;
char s[5010], t[5010];
int f[5010][5010];
long long mod = 1e9 + 7;
int ans;
int main() {
  scanf("%s%s", s + 1, t + 1);
  int n = strlen(s + 1), m = strlen(t + 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (s[i] == t[j])
        f[i][j] = (f[i][j - 1] + f[i - 1][j - 1] + 1) % mod;
      else
        f[i][j] = f[i][j - 1];
  for (int i = 1; i <= n; ++i) ans = (ans + f[i][m]) % mod;
  printf("%d", ans);
  return 0;
}
