#include <bits/stdc++.h>
using namespace std;
const int MD = 1000000007;
int la, lb, dp[5001][5001];
char a[5001], b[5001];
bool vis[5001][5001];
int go(int up, int dn) {
  if (up == la || dn == lb) return 1;
  int &ret = dp[up][dn];
  bool &ret1 = vis[up][dn];
  if (ret1) return ret;
  ret1 = 1;
  ret = 0;
  ret = (ret + go(up, dn + 1)) % MD;
  if (a[up] == b[dn]) {
    ret = (ret + go(up + 1, dn + 1)) % MD;
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int i, j, k, f, m, n, x, y;
  cin >> a >> b;
  {
    int ret = 0;
    la = strlen(a);
    lb = strlen(b);
    for (i = 0; i <= la - 1; i++) {
      ret = (ret + go(i, 0) - 1) % MD;
    }
    cout << (ret + MD) % MD << endl;
  }
  return 0;
}
