#include <bits/stdc++.h>
using namespace std;
int main() {
  string ssir, sseq;
  cin >> ssir;
  cin >> sseq;
  long long cnt[ssir.size() + 1][sseq.size() + 1];
  for (int32_t i = (0); i < int32_t(ssir.size()); ++i)
    for (int32_t j = (0); j < int32_t(sseq.size()); ++j)
      if (ssir[i] == sseq[j]) {
        cnt[i][j] = 1;
        if ((i >= 1) && (j >= 1))
          cnt[i][j] = (cnt[i][j] + cnt[i - 1][j - 1]) % 1000000007;
        if ((j >= 1)) cnt[i][j] = (cnt[i][j] + cnt[i][j - 1]) % 1000000007;
      } else if (j != 0)
        cnt[i][j] = cnt[i][j - 1];
      else
        cnt[i][j] = 0;
  long long total = 0;
  for (int32_t i = (0); i < int32_t(ssir.size()); ++i)
    total = (total + cnt[i][sseq.size() - 1]) % 1000000007;
  cout << total;
}
