#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
char a[6000], b[6000];
long long dp[2][6000], i, j, n, m, ans, now, pre;
int main() {
  scanf("%s%s", a, b);
  n = strlen(a);
  m = strlen(b);
  if (a[0] == b[0]) dp[0][0] = 1;
  for (i = 1; i < m; ++i) dp[0][i] = dp[0][i - 1] + (a[0] == b[i]);
  ans = dp[0][m - 1];
  now = 1;
  pre = 0;
  for (i = 1; i < n; ++i) {
    for (j = 0; j < m; ++j) dp[now][j] = 0;
    if (a[i] == b[0]) dp[now][0] = 1;
    for (j = 1; j < m; ++j) {
      dp[now][j] = dp[now][j - 1];
      if (a[i] == b[j]) {
        dp[now][j] = (dp[now][j] + 1 + dp[pre][j - 1]) % mod;
      }
    }
    ans = (ans + dp[now][m - 1]) % mod;
    swap(now, pre);
  }
  printf("%I64d", ans);
  return 0;
}
