#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
const long long int MOD = 1e9 + 7;
int n, m;
long long int d[2][N], ans;
string s, t;
int main() {
  cin >> s >> t;
  n = s.size(), m = t.size();
  for (int i = 0; i < m; ++i) d[0][i] = d[0][i - 1] + (int)(t[i] == s[0]);
  ans = d[0][m - 1];
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      d[i % 2][j] = d[i % 2][j - 1];
      d[i % 2][j] += (long long)(s[i] == t[j]);
      if ((s[i] == t[j]) and j) d[i % 2][j] += d[(i + 1) % 2][j - 1];
      d[i % 2][j] %= MOD;
    }
    ans += d[i % 2][m - 1];
    ans %= MOD;
  }
  cout << ans;
}
