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