#include <bits/stdc++.h>
using namespace std;
char a[5100], b[5100];
int d[5100][5100], sum[5100][5100];
int main() {
  int i, j, max;
  while (gets(a)) {
    gets(b);
    memset(d, 0, sizeof(d));
    memset(sum, 0, sizeof(sum));
    max = 0;
    for (i = strlen(a) - 1; i >= 0; i--)
      for (j = strlen(b) - 1; j >= 0; j--) {
        if (a[i] == b[j]) {
          d[i][j] = (sum[i + 1][j + 1] + 1) % 1000000007;
        } else
          d[i][j] = 0;
        sum[i][j] = (sum[i][j + 1] + d[i][j]) % 1000000007;
        max = (max + d[i][j]) % 1000000007;
      }
    printf("%d\n", max);
  }
}
