#include <bits/stdc++.h>
using namespace std;
const long long MAX = 5001;
long long a[MAX], b[MAX], c, n, m, ans;
long long dp[MAX][MAX];
char s[MAX], t[MAX];
int main() {
  cin >> s >> t;
  n = strlen(s);
  m = strlen(t);
  for (int i = 1; i <= n; i++) a[i] = s[i - 1];
  for (int i = 1; i <= m; i++) b[i] = t[i - 1];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = dp[i][j - 1];
      if (a[i] == b[j]) dp[i][j] += dp[i - 1][j - 1] + 1;
      dp[i][j] %= 1000000007;
    }
    ans += dp[i][m];
    ans %= 1000000007;
  }
  cout << ans;
  return 0;
}
