#include <bits/stdc++.h>
using namespace std;
string s1, s2;
int len1, len2;
int dp[5002][5002];
int func(int p1, int p2) {
  if ((p1 == len1) || (p2 == len2)) {
    return 0;
  }
  if (dp[p1][p2] != -1) {
    return dp[p1][p2];
  }
  int ans = 0;
  if (s1[p1] == s2[p2]) {
    ans = (1 + ans + func(p1 + 1, p2 + 1)) % 1000000007;
  }
  ans = (ans + func(p1, p2 + 1)) % 1000000007;
  return dp[p1][p2] = ans;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  ;
  cin >> s1 >> s2;
  len1 = s1.size();
  len2 = s2.size();
  memset((dp), -1, sizeof(dp));
  int ans = 0;
  for (int i = 0; i <= len1 - 1; i++) {
    ans = (ans + func(i, 0)) % 1000000007;
  }
  cout << ans << "\n";
  return 0;
}
