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