#include <bits/stdc++.h>
using namespace std;
const double EPS = 0.0000001;
const double PI = acos(-1);
const long long INFLL = 0x7FFFFFFFFFFFFFFF;
const int INF = 0x7FFFFFFF;
template <typename T>
inline void next(T &num) {
  char c;
  num = 0;
  do {
    c = getchar_unlocked();
  } while (c != EOF && c == ' ' && c == '\n' && c == '\t');
  int sign = (c == '-' ? -1 : 1);
  if (c != '-') num += (c - '0');
  while ((c = getchar_unlocked()) != EOF && c != '\n' && c != '\t' &&
         c != ' ') {
    num *= 10;
    num += (c - '0');
  }
  num *= sign;
}
inline string getstr() {
  string str;
  char k;
  while ((k = getchar_unlocked()) == ' ' || k == '\n') {
    k = getchar_unlocked();
    if (k == ' ' || k == '\n')
      continue;
    else
      break;
  }
  str.push_back(k);
  while ((k = getchar_unlocked()) != EOF && k != '\n' && k != '\t' &&
         k != '\v' && k != '\0' && k != ' ')
    str.push_back(k);
  return str;
}
const int mod = 1000000007;
char t[5005], s[5005];
int dp[5005][5005], i, j, ans;
int main() {
  ios_base::sync_with_stdio(0);
  gets(s);
  gets(t);
  for (i = 0; s[i]; i++)
    for (j = 0; t[j]; j++)
      dp[i + 1][j + 1] = (dp[i + 1][j] + (t[j] == s[i]) * (dp[i][j] + 1)) % mod;
  for (i = 0; s[i]; i++) ans = (ans + dp[i + 1][j]) % mod;
  cout << ans;
  return 0;
}
