#include <bits/stdc++.h>
using namespace std;
long long dp[5005][5005];
char s[5005], t[5005];
int tl, sl;
void DP() {
  memset(dp, 0, sizeof(dp));
  sl = strlen(s + 1);
  tl = strlen(t + 1);
  for (int i = 1; i <= sl; i++) {
    for (int j = 1; j <= tl; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = 1 + dp[i - 1][j] + dp[i][j - 1];
        if (i > 1) dp[i][j] -= dp[i - 2][j - 1];
      } else
        dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
      dp[i][j] = (dp[i][j] + 1000000007) % 1000000007;
    }
  }
  cout << dp[sl][tl] << endl;
}
int main() {
  while (cin >> s + 1 >> t + 1) DP();
  return 0;
}
