#include <bits/stdc++.h>
const int L = 5000 + 5;
const int mod = 1000000007;
char s[L], t[L];
int l_s, l_t;
int f[L][L];
int main() {
  scanf("%s%s", s + 1, t + 1);
  l_s = strlen(s + 1), l_t = strlen(t + 1);
  for (int i = 1; i <= l_s; ++i) {
    for (int j = 1; j <= l_t; ++j) {
      f[i][j] = f[i][j - 1];
      if (s[i] == t[j]) f[i][j] = (f[i][j] + f[i - 1][j - 1]) % mod;
      if (s[i] == t[j]) f[i][j] = (f[i][j] + 1) % mod;
    }
  }
  int ans = 0;
  for (int i = 1; i <= l_s; ++i) ans = (ans + f[i][l_t]) % mod;
  printf("%d\n", ans);
  return 0;
}
