#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000, MOD = 1000000007;
long long dp[MAXN][MAXN] = {}, ans = 0;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (j > 0) dp[i][j] = dp[i][j - 1];
      if (s[i] == t[j] && i > 0 && j > 0)
        dp[i][j] += dp[i - 1][j - 1] + 1;
      else if (s[i] == t[j])
        dp[i][j]++;
      dp[i][j] %= MOD;
    }
    ans += dp[i][m - 1];
    ans %= MOD;
  }
  cout << ans;
}
