#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[5005], t[5005];
long long f[5005][5005];
long long ans;
int main() {
  cin >> s;
  n = strlen(s);
  cin >> t;
  m = strlen(t);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      f[i][j] = (f[i][j] + f[i][j - 1]) % 1000000007;
      if (s[i - 1] == t[j - 1])
        f[i][j] = (f[i][j] + f[i - 1][j - 1] + 1) % 1000000007;
    }
    ans = (ans + f[i][m]) % 1000000007;
  }
  printf("%lld", ans);
  return 0;
}
