#include <bits/stdc++.h>
using namespace std;
string s, t;
int a[5009][5009];
long long res;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> s >> t;
  long long j;
  for (long long i = 0; s[i]; i++)
    for (j = 0; t[j]; j++)
      a[i + 1][j + 1] =
          (a[i + 1][j] + (s[i] == t[j]) * (a[i][j] + 1)) % 1000000007;
  for (long long i = 0; s[i]; i++) res = (res + a[i + 1][j]) % 1000000007;
  cout << res;
  return 0;
}
