#include <bits/stdc++.h>
using namespace std;
inline long long R() {
  long long an = 0, kk = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') kk = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') an = an * 10 + c - '0', c = getchar();
  return an * kk;
}
int dp[5050][5050];
int main() {
  string s1, s2;
  cin >> s1;
  cin >> s2;
  long long l1 = s1.size(), l2 = s2.size(), an = 0;
  for (int i = 0; i < l1; i++)
    for (int j = 0; j < l2; j++) {
      if (s1[i] == s2[j])
        dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] + 1) % 1000000007;
      dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i + 1][j]) % 1000000007;
    }
  for (int i = 1; i <= l1; i++) an = (an + dp[i][l2]) % 1000000007;
  cout << an;
  return 0;
}
