#include <bits/stdc++.h>
using namespace std;
char L[12012], S[12012];
long long wa[12012], wb[12012];
long long *x = wa, *y = wb, *t;
long long ans;
int main() {
  scanf("%s", L + 1);
  L[0] = 'F';
  scanf("%s", S + 1);
  S[0] = 'F';
  int strL = strlen(L), strS = strlen(S);
  for (int i = 1; i < strL; ++i) {
    memset(x, 0, sizeof(long long) * 12012);
    for (int j = 0; j < strS; ++j)
      if (L[i] == S[j]) {
        ans += y[j - 1] + 1;
        ans %= 1000000007LL;
        x[j] = y[j - 1] + x[j - 1] + 1;
        x[j] %= 1000000007LL;
      } else
        x[j] = x[j - 1], x[j] %= 1000000007LL;
    t = x, x = y, y = t;
  }
  printf("%I64d", ans);
  return 0;
}
