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