#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3F3F3F3F;
template <class T>
inline T& checkmin(T& a, T b) {
  if (b < a) a = b;
}
template <class T>
inline T& checkmax(T& a, T b) {
  if (b > a) a = b;
}
char s[5010], t[5010];
const int MOD = 1000000007;
void add(int& a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
int dp[5001][5001], n, m;
int main() {
  scanf("%s%s", t + 1, s + 1);
  int n = strlen(s + 1), m = strlen(t + 1);
  int ans = 0;
  for (int j = (1); j <= (m); ++j) {
    for (int i = (1); i <= (n); ++i) {
      dp[i][j] = dp[i - 1][j];
      if (s[i] == t[j]) add(dp[i][j], dp[i - 1][j - 1] + 1);
    }
    add(ans, dp[n][j]);
  }
  cout << ans << endl;
  return 0;
}
