#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v;
int m[5005][5005], M = 1000000007, st;
string s, t;
int f(int ps, int pt) {
  if (pt == t.size()) return 0;
  if (m[ps][pt] != -1) return m[ps][pt];
  m[ps][pt] = 0;
  if (s[ps] == t[pt])
    m[ps][pt] = (1LL + f(ps, pt + 1) + f(ps + 1, pt + 1)) % M;
  else
    m[ps][pt] = f(ps, pt + 1);
  return m[ps][pt];
}
int main() {
  getline(cin, s);
  getline(cin, t);
  int sm = 0;
  for (int i = 0; i < s.size(); ++i)
    for (int j = 0; j < t.size(); ++j) m[i][j] = -1;
  for (int i = 0; i < s.size(); ++i) sm = (sm + f(i, 0)) % M;
  cout << sm;
  return 0;
}
