#include <bits/stdc++.h>
using namespace std;
int dp[5050][5050];
char s[5050], t[5050];
int main(void) {
  scanf("%s%s", s + 1, t + 1);
  dp[0][0] = 0;
  int len1 = strlen(s + 1), len2 = strlen(t + 1);
  for (int i = 1; i <= len1; i++)
    for (int j = 1; j <= len2; 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 = 1; i <= len1; i++) ans = (ans + dp[i][len2]) % 1000000007;
  cout << ans << endl;
  return 0;
}
