#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int MAXn = 5000 + 100;
string s, t;
int n, m;
long long dp[MAXn][MAXn];
int main() {
  cin >> s >> t;
  n = int((s).size()), m = int((t).size());
  for (int i = (n), _x = (0); i-- > _x;) {
    for (int j = (m), _x = (0); j-- > _x;) {
      dp[i][j] = dp[i][j + 1];
      if (s[i] == t[j]) dp[i][j] += dp[i + 1][j + 1] + 1;
      if (dp[i][j] >= mod) dp[i][j] -= mod;
    }
  }
  long long res = 0;
  for (int i = 0, _n = (n); i < _n; i++) res += dp[i][0], res %= mod;
  cout << res << endl;
  {
    int _;
    cin >> _;
  }
}
