#include <bits/stdc++.h>
using namespace std;
void loadData(void);
int proc(void);
void printRes(int);
char s[5001], t[5001];
int dp[5001][5001];
bool lyb_debug = false;
int main(int argc, char** argv) {
  loadData();
  printRes(proc());
  return 0;
}
int proc(void) {
  memset(dp, 0, sizeof(dp));
  int n = strlen(s);
  int m = strlen(t);
  int res = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (t[j - 1] == s[i - 1]) {
        dp[j][i] =
            ((1 + dp[j - 1][i - 1]) % 1000000007 + dp[j - 1][i]) % 1000000007;
      } else {
        dp[j][i] = dp[j - 1][i];
      }
      if (j == m) res = (res + dp[m][i]) % 1000000007;
    }
  }
  if (lyb_debug) {
    printf("s:%s\n", s);
    printf("t:%s\n", t);
    printf("==dp table==\n");
    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= m; j++)
        printf("%d(%c-%c)\t", dp[j][i], t[j - 1], s[i - 1]);
      printf("\n\n");
    }
  }
  return res;
}
void loadData(void) {
  char enter;
  scanf("%s%c%s%c", s, &enter, t, &enter);
  return;
}
void printRes(int res) {
  printf("%d\n", res);
  return;
}
