#include <bits/stdc++.h>
int faster_in() {
  int r = 0, c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  if (c == '-') return -faster_in();
  for (; c > 32; r = (r << 1) + (r << 3) + c - '0', c = getchar())
    ;
  return r;
}
using namespace std;
const int INF = 1234567890;
const long long mod = 1e9 + 7;
string s, t;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s >> t;
  int n = s.size();
  int m = t.size();
  long long dp[m], lastDP[m];
  long long pref[m];
  memset(lastDP, (0), sizeof(lastDP));
  memset(pref, (0), sizeof(pref));
  long long res = 0;
  for (int i = n - 1; i >= 0; --i) {
    for (int j = (int)0, o_o = m; j < (int)o_o; ++j) {
      long long &x = dp[j];
      x = 0;
      if (s[i] == t[j]) {
        x += 1;
        if (j + 1 < m) x += pref[j + 1];
        x %= mod;
      }
      lastDP[j] = x;
      res = (res + x) % mod;
    }
    for (int j = m - 1; j >= 0; j--) {
      pref[j] = lastDP[j];
      if (j + 1 < m) pref[j] += pref[j + 1];
      pref[j] %= mod;
    }
  }
  cout << res << '\n';
  return 0;
}
