#include <bits/stdc++.h>
using namespace std;
const int MaxN = 5010;
const long long MOD = (long long)1e9 + 7ll;
string a, b;
int len[2];
long long dp[MaxN][MaxN];
int main() {
  while (getline(cin, a)) {
    getline(cin, b);
    len[0] = (int)a.size();
    len[1] = (int)b.size();
    for (int i = len[0] - 1; i >= 0; i--)
      for (int j = len[1] - 1; j >= 0; j--) {
        dp[i][j] = (j + 1 < len[1] ? dp[i][j + 1] : 0);
        if (a[i] == b[j]) dp[i][j] += dp[i + 1][j + 1] + 1;
        dp[i][j] %= MOD;
      }
    long long ans = 0;
    for (int i = 0; i < len[0]; i++) ans += dp[i][0], ans %= MOD;
    printf("%I64d\n", ans);
  }
  return 0;
}
