#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
string s, t;
int dp[5005][5005][2];
int solve(int idx1, int idx2, bool taken) {
  int &ret = dp[idx1][idx2][taken];
  if (~ret) return ret;
  if (idx1 == s.size() || idx2 == t.size()) {
    if (taken)
      return ret = 1;
    else
      return ret = 0;
  }
  ret = 0;
  if (s[idx1] == t[idx2]) ret = solve(idx1 + 1, idx2 + 1, 1);
  ret = (ret + solve(idx1, idx2 + 1, taken)) % mod;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> s >> t;
  int ans = 0;
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < s.size(); i++) ans = (ans + solve(i, 0, 0)) % mod;
  cout << ans;
  return 0;
}
