#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000 + 5;
const int mod = 1000000007;
int n, m;
char s[maxn], t[maxn];
int f[maxn][maxn];
int main() {
  scanf("%s", s + 1);
  scanf("%s", t + 1);
  n = strlen(s + 1);
  m = strlen(t + 1);
  int ret = 0;
  for (int j = 0; j <= m; ++j) f[0][j] = 1;
  for (int i = 1; i <= n; ++i) {
    f[i][0] = 1;
    for (int j = 1; j <= m; ++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;
    }
    ret = (ret + f[i][m]) % mod;
  }
  printf("%d\n", (ret - n + mod) % mod);
  return 0;
}
