#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
const int M = 1e9 + 7;
int a[N][N];
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  int ns = s.size();
  int nt = t.size();
  s = '@' + s;
  t = '@' + t;
  int res = 0;
  for (int i = 1; i <= ns; ++i) {
    for (int j = 1; j <= nt; ++j) {
      a[i][j] = a[i][j - 1] + (s[i] == t[j]) * (a[i - 1][j - 1] + 1);
      a[i][j] %= M;
    }
    res += a[i][nt];
    res %= M;
  }
  cout << res;
}
