#include <bits/stdc++.h>
using namespace std;
char s1[5005], s2[5005];
int a[5005];
int main() {
  int l1, l2, i, j, k, ans;
  memset(a, 0, sizeof(a));
  scanf("%s", s1);
  l1 = strlen(s1);
  scanf("%s", s2);
  l2 = strlen(s2);
  for (i = 0; i < l2; ++i) {
    for (j = l1 - 1; j >= 0; --j) {
      if (s2[i] == s1[j]) {
        if (j != 0) a[j] += a[j - 1];
        a[j]++;
        a[j] %= 1000000007;
      }
    }
  }
  ans = 0;
  for (i = 0; i < l1; ++i) {
    ans += a[i];
    ans %= 1000000007;
  }
  printf("%d\n", ans);
}
