#include <bits/stdc++.h>
using namespace std;
int n, m;
bool debug = false;
int k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long dp[5005][5005];
char s[5005], t[5005];
int main() {
  scanf("%s%s", s, t);
  long long ls = strlen(s), lt = strlen(t);
  for (int i = ls - 1; i >= 0; i--) {
    for (int j = lt - 1; j >= 0; j--) {
      dp[i][j] = dp[i][j + 1];
      if (s[i] == t[j]) {
        dp[i][j] = (dp[i][j] + dp[i + 1][j + 1] + 1) % 1000000007;
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < ls; i++) {
    ans = (ans + dp[i][0]) % 1000000007;
  }
  printf("%lld\n", ans);
  return 0;
}
