#include <bits/stdc++.h>
using namespace std;
char str1[5005], str2[5005];
int dp[5005][5005];
int main() {
  while (~scanf("%s", str1 + 1)) {
    scanf("%s", str2 + 1);
    int len1 = strlen(str1 + 1);
    int len2 = strlen(str2 + 1);
    memset(dp, 0, sizeof dp);
    int ans = 0;
    for (int i = 1; i <= len1; i++) {
      for (int j = 1; j <= len2; j++) {
        dp[i][j] = dp[i][j - 1];
        if (str1[i] == str2[j])
          dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % 1000000007;
      }
      ans = (ans + dp[i][len2]) % 1000000007;
    }
    printf("%d\n", ans);
  }
  return 0;
}
