#include <bits/stdc++.h>
const int maxn = 5010;
using namespace std;
const int mod = 1000000007;
int d[4][maxn];
char a[maxn], b[maxn];
int second = 0;
int S[3][maxn];
int main() {
  scanf("%s\n%s\n", a + 1, b + 1);
  int n = strlen(a + 1), m = strlen(b + 1);
  for (int i = 1; i <= n; ++i) {
    int act = i & 1, pred = act ^ 1;
    for (int j = 1; j <= m; ++j) {
      S[act][j] = S[act][j - 1];
      if (a[i] == b[j]) {
        d[act][j] = S[pred][j - 1];
        d[act][j] += 1;
        if (d[act][j] >= mod) d[act][j] -= mod;
        S[act][j] += d[act][j];
        if (S[act][j] >= mod) S[act][j] -= mod;
        second += d[act][j];
        if (second >= mod) second -= mod;
      }
    }
  }
  printf("%d\n", second);
  return 0;
}
