#include <bits/stdc++.h>
using namespace std;
const long long MODULO = 1000000007;
static long long solve(char* a, char* s) {
  static long long d[5000][5000];
  const int slen = strlen(s);
  const int alen = strlen(a);
  for (int i = 0; i < alen; ++i) {
    d[i][0] = (a[i] == s[0]);
  }
  for (int j = 1; j < slen; ++j) {
    d[0][j] = (d[0][j - 1] + (a[0] == s[j])) % MODULO;
    for (int i = 1; i < alen; ++i) {
      if (a[i] == s[j]) {
        d[i][j] = (d[i][j - 1] + d[i - 1][j - 1] + 1) % MODULO;
      } else {
        d[i][j] = d[i][j - 1];
      }
    }
  }
  long long result = 0;
  for (int i = 0; i < alen; ++i) {
    result = (result + d[i][slen - 1]) % MODULO;
  }
  return result;
}
int main() {
  static char a[5001];
  static char s[5001];
  scanf("%s%s", a, s);
  printf("%I64d\n", solve(a, s));
}
