#include <bits/stdc++.h>
int dp[5005][5005];
int main() {
  char s[5005], t[5005];
  while (scanf("%s%s", s + 1, t + 1) == 2) {
    memset(dp, 0, sizeof(dp));
    int n = strlen(t + 1) + 1;
    int m = strlen(s + 1) + 1;
    for (int i = 1; i < n; i++)
      for (int j = 1; j < m; j++)
        if (t[i] == s[j])
          dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1] + 1) % (1000000007);
        else
          dp[i][j] = dp[i - 1][j];
    int sum = 0;
    for (int j = 1; j < m; j++) sum = (sum + dp[n - 1][j]) % (1000000007);
    printf("%d\n", sum);
  }
}
