#include <bits/stdc++.h>
using namespace std;
int main() {
  std::string str1, str2;
  cin >> str1 >> str2;
  int n = (int)str1.length(), m = (int)str2.length();
  vector<int> last(m, 0);
  int res = 0;
  const int mod = 1000000007;
  for (int i = 0; i < n; i++) {
    int sumLast = 0;
    vector<int> v(m, 0);
    for (int j = 0; j < m; j++) {
      if (str1[i] != str2[j]) {
        sumLast += last[j];
        if (sumLast >= mod) sumLast -= mod;
        continue;
      }
      v[j] = sumLast + 1;
      res += v[j];
      if (res >= mod) res -= mod;
      sumLast += last[j];
      if (sumLast >= mod) sumLast -= mod;
    }
    last.swap(v);
  }
  cout << res;
}
