#include <bits/stdc++.h>
const int Modulo = 1000000007;
int N, M;
char S[6000], T[6000];
int DP[5010][5010], Sum[5010];
int main() {
  scanf("%s%s", S, T);
  N = strlen(S);
  M = strlen(T);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++)
      if (S[i] == T[j]) {
        DP[i][j] += Sum[j] + 1;
        if (DP[i][j] >= Modulo) DP[i][j] -= Modulo;
      }
    Sum[0] = 0;
    for (int j = 1; j < M; j++) {
      Sum[j] = Sum[j - 1] + DP[i][j - 1];
      if (Sum[j] >= Modulo) Sum[j] -= Modulo;
    }
  }
  int Ans = 0;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) {
      Ans += DP[i][j];
      if (Ans >= Modulo) Ans -= Modulo;
    }
  printf("%d\n", Ans);
  return 0;
}
