#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
string a;
string s;
int n;
int m;
int dp[5001][5001];
int main() {
  cin >> a;
  cin >> s;
  n = a.size();
  m = s.size();
  memset(dp, 0, sizeof(dp));
  for (int i = n - 1; i >= 0; i--) {
    for (int j = m - 1; j >= 0; j--) {
      dp[i][j] = dp[i][j + 1];
      if (a[i] == s[j]) dp[i][j] += dp[i + 1][j + 1] + 1;
      dp[i][j] %= mod;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += dp[i][0];
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}
