#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:32000000")
using namespace std;
const double pi = 3.1415926535897932384626433832795;
template <class T>
inline T Sqr(const T &x) {
  return x * x;
}
template <class T>
inline T Abs(const T &x) {
  return x >= 0 ? x : -x;
}
int n, m;
char s[5005], t[5005];
int dp[5005][5005];
void solve() {
  scanf("%s", s);
  scanf("%s", t);
  n = strlen(s);
  m = strlen(t);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] == t[j]) {
        dp[i][j]++;
        if (i > 0 && j > 0) dp[i][j] += dp[i - 1][j - 1];
      }
      if (j > 0) dp[i][j] += dp[i][j - 1];
      dp[i][j] %= 1000000007;
    }
  }
  int res = 0;
  for (int i = 0; i < n; i++) res = (res + dp[i][m - 1]) % 1000000007;
  cout << res;
}
int main() {
  solve();
  return 0;
}
