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