#include <bits/stdc++.h>
using namespace std;
const int maxn = 10010;
const int mod = 1e9 + 7;
int n, m;
char a[maxn], b[maxn];
int dp[5001][5001], sum[maxn];
int main() {
  scanf("%s", a);
  scanf("%s", b);
  n = strlen(a);
  m = strlen(b);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] == b[0]) {
      ans++;
      dp[i][0] = 1;
    }
  }
  for (int i = 1; i < m; ++i) {
    if (a[0] == b[i]) {
      dp[0][i] = 1;
      ans++;
    }
  }
  for (int i = 1; i < n; ++i) {
    sum[0] = dp[i - 1][0];
    for (int j = 1; j < m; ++j) {
      sum[j] = sum[j - 1] + dp[i - 1][j];
      sum[j] %= mod;
    }
    for (int j = 1; j < m; ++j) {
      if (a[i] == b[j]) {
        dp[i][j] = sum[j - 1] + 1;
      } else
        dp[i][j] = 0;
      dp[i][j] %= mod;
      ans += dp[i][j];
      ans %= mod;
    }
  }
  cout << ans;
  return 0;
}
