#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
string a, b;
int dp[5000][5000];
int calc(int i, int j) {
  if (i == a.size() || j == b.size()) return 0;
  int &ret = dp[i][j];
  if (ret != -1) return ret;
  ret = calc(i, j + 1);
  if (a[i] == b[j]) ret = (ret + 1 + calc(i + 1, j + 1)) % M;
  return ret;
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> a >> b;
  int res = 0;
  for (int i = 0; i < a.size(); ++i) res = (res + calc(i, 0)) % M;
  printf("%d\n", res);
  return 0;
}
