#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
char s[5005], t[5005];
long long dp[5005][5005];
long long l, k;
long long call(int i, int j) {
  if (i >= l || j >= k) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  long long ret = 0;
  if (s[i] == t[j]) ret = (ret + 1 + call(i + 1, j + 1)) % mod;
  ret = (ret + call(i, j + 1)) % mod;
  return dp[i][j] = ret;
}
int main() {
  scanf("%s %s", s, t);
  memset(dp, -1, sizeof(dp));
  long long result = 0;
  l = strlen(s);
  k = strlen(t);
  for (int i = 0; i < l; i++) {
    result = (result + call(i, 0)) % mod;
  }
  cout << result << endl;
  return 0;
}
