#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const int mod = inf + 7;
int f[5009][5009];
int main() {
  std::ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < t.size(); j++) {
      f[i + 1][j + 1] = f[i + 1][j];
      if (s[i] == t[j]) f[i + 1][j + 1] += f[i][j] + 1;
      f[i + 1][j + 1] %= mod;
    }
  }
  int ans = 0;
  for (int i = 1; i <= s.size(); i++) ans = (ans + f[i][t.size()]) % mod;
  cout << ans << endl;
}
