#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
const int MOD = 1000000007;
int dp[N][N];
char a[N], b[N];
int main() {
  cin >> a + 1 >> b + 1;
  int n = strlen(a + 1), m = strlen(b + 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      dp[i][j] = dp[i][j - 1];
      if (a[i] == b[j]) dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % MOD;
    }
  int ans = 0;
  for (int i = 1; i <= n; ++i) ans = (ans + dp[i][m]) % MOD;
  cout << ans << endl;
  return 0;
}
