#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
const int mod = 1e9 + 7;
long long dp[maxn][maxn];
string s, t;
int n, m;
long long solve(int i, int j) {
  if (i == n || j == m) return 0;
  long long &ret = dp[i][j];
  if (~ret) return ret;
  ret = 0;
  if (s[i] == t[j])
    return ret = (1 + solve(i, j + 1) % mod + solve(i + 1, j + 1) % mod) % mod;
  return ret = solve(i, j + 1) % mod;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> s >> t;
  n = (int)s.length();
  m = (int)t.length();
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) dp[i][j] = -1;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += solve(i, 0);
    ans %= mod;
  }
  cout << ans << '\n';
  return 0;
}
