#include <bits/stdc++.h>
using namespace std;
const int N = 5e3;
int mod = 1e9 + 7;
int mul(int a, int b) { return ((a % mod) * (b % mod)) % mod; }
int add(int a, int b) { return ((a % mod) + (b % mod)) % mod; }
int power(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    b = b / 2;
    a = mul(a, a);
  }
  return res;
}
int sub(int a, int b) { return ((a % mod) - (b % mod) + mod) % mod; }
int divi(int a, int b) { return mul(a, power(b, mod - 2)); }
int dp[N][N];
bool already[N][N];
string s, t;
int n1, n2;
int solve(int i, int j) {
  if (i >= n1 || j >= n2) return 0;
  if (already[i][j]) return dp[i][j];
  dp[i][j] = 0;
  if (s[i] == t[j]) dp[i][j] = add(1, solve(i + 1, j + 1));
  dp[i][j] = add(dp[i][j], solve(i, j + 1));
  already[i][j] = true;
  return dp[i][j];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> s >> t;
  n1 = s.size();
  n2 = t.size();
  int ans = 0;
  for (int i = 0; i < n1; i++) ans = add(ans, solve(i, 0));
  cout << ans;
}
