#include <bits/stdc++.h>
using namespace std;
long long dp[5001][5001];
char s1[5001], s2[5001];
int l1, l2;
long long recur(int i, int j);
int main() {
  while (cin >> s1 >> s2) {
    memset(dp, -1, sizeof(dp));
    l1 = strlen(s1);
    l2 = strlen(s2);
    long long sol = 0;
    for (int i = 0; i < l1; i++) {
      sol += recur(i, l2 - 1);
      sol %= 1000000007;
    }
    cout << sol << endl;
  }
  return 0;
}
long long recur(int i, int j) {
  long long sum = 0;
  if (i < 0 || j < 0) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  if (s1[i] == s2[j]) {
    sum = recur(i - 1, j - 1) + 1;
  }
  sum += recur(i, j - 1);
  return dp[i][j] = sum % 1000000007;
}
