#include <bits/stdc++.h>
using namespace std;
string s, p;
int dp[5001][5001];
int calc(int first, int second) {
  if (second == p.length() || first == s.length()) return 0;
  if (dp[first][second] != -1) return dp[first][second];
  int ans = calc(first, second + 1);
  if (s[first] == p[second]) {
    ans = (ans + calc(first + 1, second + 1) + 1) % 1000000007;
  }
  return dp[first][second] = ans;
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> s >> p;
  int ans = 0;
  for (int i = 0; i < s.length(); ++i) ans = (ans + calc(i, 0)) % 1000000007;
  cout << ans << endl;
  return 0;
}
