#include <bits/stdc++.h>
using namespace std;
char a[5555], b[5555];
int f[5555][5555][2];
int main() {
  scanf("%s", a);
  scanf("%s", b);
  int n = strlen(a), m = strlen(b);
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= m; ++j)
      for (int k = 0; k <= 1; ++k) {
        if (i == 0 || j == 0) {
          f[i][j][k] = k;
          continue;
        }
        if (a[i - 1] == b[j - 1])
          f[i][j][k] = (f[i][j][k] + f[i - 1][j - 1][1]) % 1000000007;
        f[i][j][k] = (f[i][j][k] + f[i][j - 1][k]) % 1000000007;
      }
  long long ans(0);
  for (int i = 1; i <= n; ++i) ans = (ans + f[i][m][false]) % 1000000007;
  cout << ans << endl;
}
