#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const int maxn = 5007;
const int pp = 1000000007;
int n, m;
long long ans;
char s[maxn], t[maxn];
long long sum[maxn][maxn];
int main() {
  scanf("%s%s", s, t);
  n = strlen(s);
  m = strlen(t);
  for (int j = 1; j <= m; j++) {
    for (int k = 1; k <= n; k++) sum[j][k] = sum[j - 1][k];
    for (int i = 1; i <= n; i++)
      if (s[i - 1] == t[j - 1]) {
        sum[j][i] += sum[j - 1][i - 1] + 1;
        if (sum[j][i] >= pp) sum[j][i] -= pp;
        ans += sum[j - 1][i - 1] + 1;
        if (ans >= pp) ans -= pp;
      }
  }
  printf("%I64d\n", ans);
  return 0;
}
