#include <bits/stdc++.h>
using namespace std;
const int size = 5000;
char s[size + 10], t[size + 10];
const long long mod = 1000000007;
long long dp[size + 10][size + 10];
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  while (cin >> (s + 1) >> (t + 1)) {
    long long res = 0;
    int lens = strlen(s + 1);
    int lent = strlen(t + 1);
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= lens; ++i) {
      for (int j = 1; j <= lent; ++j) {
        dp[i][j] = dp[i][j - 1];
        if (s[i] == t[j]) {
          dp[i][j] += dp[i - 1][j - 1] + 1;
          dp[i][j] %= mod;
        }
      }
    }
    for (int i = 1; i <= lens; ++i) {
      res += dp[i][lent];
      res %= mod;
    }
    cout << res << '\n';
    cout.flush();
  }
  return 0;
}
