#include <bits/stdc++.h>
using namespace std;
const int N = 5000 + 10;
const int mod = 1e9 + 7;
long long dp[N][N];
int main() {
  char a[N], b[N];
  scanf("%s%s", a + 1, b + 1);
  int len = strlen(a + 1);
  int lenb = strlen(b + 1);
  for (int i = 1; i <= len; i++) {
    for (int j = 1; j <= lenb; j++) {
      dp[i][j] = dp[i][j - 1] % mod;
      if (a[i] == b[j]) dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % mod;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= len; i++) ans = (ans + dp[i][lenb]) % mod;
  printf("%I64d\n", ans);
  return 0;
}
