#include <bits/stdc++.h>
using namespace std;
int matEqual[5001][5001];
int main() {
  const int moduloDiv = 1000000007;
  string str, sec;
  cin >> str;
  cin >> sec;
  int num = 0;
  for (int i = 0; i < str.length(); i++) {
    for (int j = 0; j < sec.length(); j++) {
      matEqual[i + 1][j + 1] =
          (matEqual[i + 1][j] +
           ((str[i] == sec[j] ? 1 : 0) * (matEqual[i][j] + 1))) %
          moduloDiv;
    }
  }
  for (int i = 0; i < str.length(); i++) {
    num = (num + matEqual[i + 1][sec.length()]) % moduloDiv;
  }
  cout << num << endl;
  return 0;
}
