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