#include <bits/stdc++.h>
using namespace std;
int dp[5002][5002] = {};
string s, t;
const int mod = 1000000007;
int main() {
  int ans = 0;
  cin >> s >> t;
  for (int i = 1; i <= s.size(); ++i) {
    for (int j = 1; j <= t.size(); ++j) {
      dp[i][j] = ((dp[i - 1][j - 1] + dp[i][j] + 1) * (s[i - 1] == t[j - 1]) +
                  dp[i][j - 1]) %
                 mod;
    }
  }
  for (int i = 1; i <= s.size(); ++i) ans = (ans + dp[i][t.size()]) % mod;
  cout << ans << endl;
}
