#include <bits/stdc++.h>
int dp[5010];
char a[5010], b[5010];
int main() {
  int n, m, i, j, ans = 0;
  scanf("%s %s", a, b);
  n = strlen(a);
  m = strlen(b);
  memset(dp, 4 * n, 0);
  for (i = 0; i < m; i++)
    for (j = n - 1; j >= 0; j--)
      if (b[i] == a[j])
        dp[j] = (dp[j] + 1 + (j > 0 ? dp[j - 1] : 0)) % 1000000007;
  for (i = 0; i < n; i++) {
    ans += dp[i];
    if (ans >= 1000000007) ans -= 1000000007;
  }
  printf("%d\n", ans);
}
