#include <bits/stdc++.h>
const int mod = 1000000007;
int lena, lenb;
long long dp[5000 + 20][5000 + 20];
long long ans;
char a[5000 + 20], b[5000 + 20];
int main() {
  scanf("%s%s", a + 1, b + 1);
  lena = strlen(a + 1);
  lenb = strlen(b + 1);
  for (int i = 1; i <= lena; i++) {
    for (int j = 1; j <= lenb; j++) {
      if (a[i] == b[j]) {
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % mod;
      }
      dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
    }
  }
  for (int i = 1; i <= lena; i++) {
    ans = (ans + dp[i][lenb]) % mod;
  }
  printf("%lld\n", ans);
}
