#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
int i, j, k, m, n;
const int N = 5e3 + 10, mod = 1000000007;
int dp[N][N];
char s[N], t[N];
int main() {
  scanf("%s%s", s + 1, t + 1);
  n = strlen(s + 1), m = strlen(t + 1);
  for (i = 0; i <= n; i++) dp[i][0] = 1;
  for (j = 1; j <= m; j++) dp[0][j] = 1;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      dp[i][j] = (dp[i][j - 1] + dp[i - 1][j - 1] * (s[i] == t[j])) % mod;
  int ans = 0;
  for (i = 1; i <= n; i++) ans = (ans + dp[i][m] - 1) % mod;
  cout << ans;
  return 0;
}
