#include <bits/stdc++.h>
using namespace std;
const int inf = ~0ull / 2;
const int mod = 1000000007;
int dp[5100][5100][2];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  s = " " + s;
  t = " " + t;
  for (int i = 1; i < s.length(); i++) {
    for (int j = 1; j < t.length(); j++) {
      dp[i][j][0] = (dp[i - 1][j][0] + 0ll + dp[i - 1][j][1]) % mod;
      if (s[i] != t[j]) {
        dp[i][j][1] = dp[i][j - 1][1];
      } else {
        dp[i][j][1] = (dp[i - 1][j - 1][1] + 1ll + dp[i][j - 1][1]) % mod;
      }
    }
  }
  cout << (dp[s.length() - 1][t.length() - 1][0] + 0ll +
           dp[s.length() - 1][t.length() - 1][1]) %
              mod;
}
