#include <bits/stdc++.h>
using namespace std;
char str1[5005], str2[5005];
int len1, len2;
int dp[5005][5005];
int cnt[5005][26];
void pre() {
  for (int i = 0; i < len2; i++) {
    cnt[i][str2[i] - 'a'] = 1;
  }
  for (int i = 1; i < len2; i++) {
    for (int j = 0; j < 26; j++) {
      cnt[i][j] += cnt[i - 1][j];
    }
  }
}
void dp_work() {
  dp[0][0] = str1[0] == str2[0];
  for (int j = 1; j < len1; j++) {
    dp[0][j] = str1[j] == str2[0];
  }
  for (int i = 1; i < len2; i++) {
    dp[i][0] = cnt[i][str1[0] - 'a'];
  }
  for (int i = 1; i < len2; i++) {
    for (int j = 1; j < len1; j++) {
      dp[i][j] = (str2[i] == str1[j]
                      ? (dp[i - 1][j - 1] + dp[i - 1][j] + 1) % 1000000007
                      : dp[i - 1][j]);
    }
  }
}
int main() {
  scanf("%s", &str1);
  scanf("%s", &str2);
  len1 = strlen(str1), len2 = strlen(str2);
  pre();
  dp_work();
  int ans = 0;
  for (int i = 0; i < len1; i++) {
    ans += dp[len2 - 1][i];
    ans %= 1000000007;
  }
  printf("%d\n", ans);
  return 0;
}
