#include <bits/stdc++.h>
using namespace std;
int dp[5001][5001];
string s, t;
int subSeq(int i, int j) {
  if (i >= s.length() || j >= t.length()) {
    return 0;
  }
  if (dp[i][j] != -1) {
    return dp[i][j];
  }
  return dp[i][j] =
             (subSeq(i, j + 1) + (s[i] == t[j]) % 1000000007 *
                                     (subSeq(i + 1, j + 1) + 1) % 1000000007) %
             1000000007;
}
int main() {
  cin >> s >> t;
  long long sum = 0;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < s.length(); i++) {
    sum += subSeq(i, 0);
  }
  cout << sum % 1000000007;
}
