#include <bits/stdc++.h>
const int MAXN = 3e5 + 10;
const double eps = 1e-8;
const int mod = 1e9 + 7;
using namespace std;
struct edge {
  int t, v;
  edge *next;
} e[MAXN << 1], *h[MAXN], *o = e;
void add(int x, int y, int vul) {
  o->t = y;
  o->v = vul;
  o->next = h[x];
  h[x] = o++;
}
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
char s[MAXN];
char t[MAXN];
int n, m;
int dp[5005][5005];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  scanf("%s", t + 1);
  m = strlen(t + 1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (s[i] == t[j]) dp[i][j] = (dp[i - 1][j - 1] + 1) % mod;
      dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
    }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += dp[i][m], ans %= mod;
  printf("%lld\n", ans);
  return 0;
}
