#include <bits/stdc++.h>
const int mod = 1000000007;
char a[6000] = {0}, b[6000] = {0};
int v[2][6000] = {0};
int main() {
  int i = 0, j = 0, now = 0, ans = 0, pre = 0, x = 0, y = 0;
  while (scanf("%s%s", a, b) == 2) {
    x = 0;
    y = 1;
    memset(v[x], 0, sizeof(v[x]));
    ans = 0;
    for (i = 0; a[i]; i++) {
      now = 0;
      for (j = 0; b[j]; j++) {
        pre = now;
        if (i && b[j] == a[i - 1]) {
          now = (now + v[x][j]) % mod;
        }
        if (b[j] == a[i]) {
          v[y][j] = (pre + 1) % mod;
          ans = (ans + pre + 1) % mod;
        } else {
          v[y][j] = 0;
        }
      }
      y = !y;
      x = !x;
    }
    printf("%d\n", ans);
  }
  return 0;
}
