#include <bits/stdc++.h>
using namespace std;
const int mod = (int)(1e9 + 7);
const int max_ = 5e3;
int dp[max_][max_];
int acc[max_][max_];
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(NULL);
  cin.tie(NULL);
  string s;
  cin >> s;
  string t;
  cin >> t;
  int n = s.length();
  int m = t.length();
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dp[i][j] = 0;
      acc[i][j] = 0;
      if (s[i] == t[j]) {
        long long int val = (long long int)dp[i][j] + 1L;
        dp[i][j] = (int)(val % mod);
      }
      if (i != 0 && j != 0 && s[i] == t[j]) {
        long long int val =
            (long long int)dp[i][j] + (long long int)acc[i - 1][j - 1];
        dp[i][j] = (int)(val % mod);
      }
      if (j == 0) {
        acc[i][0] = dp[i][0];
      } else {
        long long int val =
            (long long int)dp[i][j] + (long long int)acc[i][j - 1];
        acc[i][j] = (int)(val % mod);
      }
    }
    ans += acc[i][m - 1];
    ans %= mod;
  }
  cout << ans << "\n";
}
