#include <bits/stdc++.h>
using namespace std;
int nbPairs[5001][5001];
const int MOD = 1e9 + 7;
int main() {
  char s[5001], t[5001];
  scanf("%s%s", &s, &t);
  int ss = strlen(s), st = strlen(t);
  for (int is = ss - 1; is >= 0; is--)
    for (int it = st - 1; it >= 0; it--) {
      if (s[is] == t[it]) nbPairs[is][it] += 1 + nbPairs[is + 1][it + 1];
      nbPairs[is][it] += nbPairs[is][it + 1];
      nbPairs[is][it] %= MOD;
    }
  int a = 0;
  for (int i = 0; i < ss; i++) {
    a += nbPairs[i][0];
    a %= MOD;
  }
  printf("%d\n", a);
  return 0;
}
