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