#include <bits/stdc++.h>
using namespace std;
int ans = 0;
int dp[5005][5005];
char a[5005];
char b[5005];
int main() {
  scanf("%s%s", a + 1, b + 1);
  int la = strlen(a + 1);
  int lb = strlen(b + 1);
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= la; i++) {
    for (int j = 1; j <= lb; j++) {
      dp[i][j] =
          (dp[i][j - 1] + (a[i] == b[j]) * (dp[i - 1][j - 1] + 1)) % 1000000007;
    }
    ans = (ans + dp[i][lb]) % 1000000007;
  }
  printf("%d\n", ans);
}
