#include <bits/stdc++.h>
using namespace std;
int DEBUG = 0;
int Min(int a, int b) { return (a < b ? a : b); }
int Max(int a, int b) { return (a > b ? a : b); }
int Abs(int a) { return (a >= 0 ? a : -a); }
void print1d(int *vec, int M, const char *str = NULL) {
  if (str != NULL) printf("%s ", str);
  for (int i = 0; i < M; i++) {
    if (i > 0) printf(" ");
    printf("%d", vec[i]);
  }
  printf("\n");
}
int main(int argc, char **argv) {
  DEBUG = (argc >= 2) ? atoi(argv[1]) : 0;
  char s[5010], t[5010];
  cin >> s >> t;
  int n = strlen(s);
  int m = strlen(t);
  int dp[n + 1][m + 1];
  for (int i = 0; i < n; i++) {
    dp[i][0] = (s[i] == t[0] ? 1 : 0);
  }
  for (int j = 1; j < m; j++) {
    dp[0][j] = dp[0][j - 1] + (s[0] == t[j] ? 1 : 0);
  }
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < m; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j - 1] + 1) % 1000000007;
      } else {
        dp[i][j] = dp[i][j - 1];
      }
      if (DEBUG) {
        cout << "dp[" << i - 1 << "][" << j - 1 << "]= " << dp[i - 1][j - 1]
             << " dp[" << i << "][" << j - 1 << "]= " << dp[i][j - 1] << " dp["
             << i << "][" << j << "]= " << dp[i][j] << endl;
      }
    }
  }
  int64_t cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt = (cnt + dp[i][m - 1]) % 1000000007;
  }
  cout << cnt << endl;
  return 0;
}
