#include <bits/stdc++.h>
using namespace std;
char s[5005], t[5005];
int dp[5005][5005];
int main() {
  scanf("%s", s);
  scanf("%s", t);
  int ss = strlen(s);
  int st = strlen(t);
  memset(dp, 0, sizeof(dp));
  int res = 0;
  for (int i = 0; i < ss; i++) {
    for (int j = 0; j < st; j++) {
      if (s[i] == t[j]) {
        if (i > 0 && j > 0) {
          dp[i][j] += dp[i - 1][j - 1];
          dp[i][j] % 1000000007;
        }
        dp[i][j]++;
      }
      if (j > 0) dp[i][j] += dp[i][j - 1];
      dp[i][j] %= 1000000007;
    }
    res += dp[i][st - 1];
    res %= 1000000007;
  }
  printf("%d\n", res);
  return 0;
}
