#include <bits/stdc++.h>
using namespace std;
const int P = 1000000007;
char s[5001], t[5001];
int dp[5001][5001];
int main() {
  scanf("%s%s", s + 1, t + 1);
  int slen, tlen;
  slen = strlen(s + 1);
  tlen = strlen(t + 1);
  dp[0][0] = 0;
  for (int i = 1; i <= slen; ++i)
    for (int j = 1; j <= tlen; ++j)
      if (s[i] == t[j])
        dp[i][j] = (dp[i][j - 1] % P + dp[i - 1][j - 1] % P + 1) % P;
      else
        dp[i][j] = dp[i][j - 1];
  int ans = 0;
  for (int i = 1; i <= slen; ++i) ans = (ans + dp[i][tlen]) % P;
  printf("%d", ans);
  return 0;
}
