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