#include <bits/stdc++.h>
using namespace std;
int dp[5002][5002];
string s;
string t;
int n;
int m;
int f(int i, int j) {
  if (i >= n || j >= m) {
    return 0;
  }
  if (dp[i][j] != -1) {
    return dp[i][j];
  }
  dp[i][j] =
      (f(i, j + 1) + (s[i] == t[j]) * ((f(i + 1, j + 1) + 1) % 1000000007)) %
      1000000007;
  return dp[i][j];
}
int main() {
  getline(cin, s);
  getline(cin, t);
  n = s.length();
  m = t.length();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dp[i][j] = -1;
    }
  }
  for (int i = 0; i < n; i++) {
    f(i, 0);
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum = (sum + dp[i][0]) % 1000000007;
  }
  cout << sum;
  return 0;
}
