#include <bits/stdc++.h>
const int maxn = 5005;
const int Mod = 1000000007;
int dp[maxn][maxn];
char str1[maxn], str2[maxn];
int main() {
  int i, j, n, m;
  int ans = 0;
  scanf("%s%s", str1, str2);
  n = strlen(str1);
  m = strlen(str2);
  memset(dp, 0, sizeof(dp));
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (str1[i - 1] == str2[j - 1]) {
        int temp = (dp[i - 1][j - 1] + dp[i][j - 1]) % Mod;
        dp[i][j] += temp + 1;
        dp[i][j] %= Mod;
        ans = (ans + dp[i - 1][j - 1] + 1) % Mod;
      } else
        dp[i][j] += dp[i][j - 1];
    }
  }
  printf("%d\n", ans);
  return 0;
}
