#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long dp[5010][5010];
char s[5010], z[5010];
long long solve() {
  int M = strlen(s), N = strlen(z);
  for (int i = 0; i <= M; i++) dp[i][0] = 0;
  for (int i = 0; i <= N; i++) dp[0][i] = 0;
  for (int i = 1; i <= M; i++)
    for (int j = 1; j <= N; j++) {
      dp[i][j] = dp[i][j - 1];
      if (s[i - 1] == z[j - 1])
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % mod;
    }
  long long ans = 0;
  for (int i = 0; i <= M; i++) ans = (ans + dp[i][N]) % mod;
  return ans;
}
int main() {
  scanf("%s %s", s, z);
  int ans = solve();
  printf("%d\n", ans);
  return 0;
}
