#include <bits/stdc++.h>
using namespace std;
string s, t;
int slen, tlen, dp[5009][5009], psum[5001][5001], mod = 1000000007, totsum = 0;
int modadd(int l1, int l2) { return (l1 % mod + l2 % mod) % mod; }
int main() {
  ios::sync_with_stdio(false);
  cin >> s >> t;
  slen = s.size();
  tlen = t.size();
  memset(dp, 0, sizeof(dp));
  memset(psum, 0, sizeof(psum));
  for (int i = (1); i <= (slen); i++) {
    for (int j = (1); j <= (tlen); j++) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = modadd(psum[i - 1][j - 1], 1);
        totsum = modadd(totsum, dp[i][j]);
      }
      psum[i][j] = modadd(dp[i][j], psum[i][j - 1]);
    }
  }
  cout << totsum;
}
