#include <bits/stdc++.h>
using namespace std;
const int oo = ~0U >> 1;
const double inf = 1e100;
const double eps = 1e-6;
string name = "", in = ".in", out = ".out";
char a[5008], b[5008];
int f[5008][5008];
int n, m, ans, mod = 1000000007;
void Update(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
int main() {
  scanf("%s%s", a + 1, b + 1);
  n = strlen(a + 1), m = strlen(b + 1);
  for (int i = 1, tt = m; i <= tt; ++i)
    for (int j = 1, tt = n; j <= tt; ++j) {
      f[i][j] = f[i - 1][j];
      if (b[i] == a[j]) Update(f[i][j], f[i - 1][j - 1] + 1);
    }
  for (int i = 1, tt = n; i <= tt; ++i) Update(ans, f[m][i]);
  cout << ans << endl;
  return 0;
}
