#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5010;
const int MODD = 1000000007;
char s[MAXN], t[MAXN];
int n, m, ans, dp[MAXN][MAXN];
int main() {
  string s, t;
  cin >> s >> t;
  n = s.size();
  m = t.size();
  for (int i = 0; i <= n; ++i) memset(dp[i], 0, sizeof(int) * (m + 1));
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      dp[i][j] = dp[i][j - 1];
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % MODD;
      }
    }
  }
  ans = 0;
  for (int i = 1; i <= n; ++i) ans = (ans + dp[i][m]) % MODD;
  cout << ans;
}
