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