#include <bits/stdc++.h>
using namespace std;
const int maxN = 5000 + 100, P = 1000000007;
int dp[maxN][maxN], last[maxN][26];
char c1[maxN], c2[maxN];
int getlen(char c[]) {
  for (int i = 0; i < maxN; ++i)
    if (c[i] == 0) return i;
}
int main() {
  scanf("%s\n", c1);
  scanf("%s\n", c2);
  int N = getlen(c1), M = getlen(c2);
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < M; ++j) dp[i][j] = 0;
  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= M; ++j) {
      dp[i][j] = dp[i][j - 1];
      if (c1[i - 1] == c2[j - 1])
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % P;
    }
    ans = (ans + dp[i][M]) % P;
  }
  printf("%d\n", ans);
  return 0;
}
