#include <bits/stdc++.h>
using namespace std;
long long dp[5002][5003];
string s1, second;
int main() {
  cin >> second >> s1;
  int n = second.size();
  int n1 = s1.size();
  long long final = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n1; j++) {
      dp[i][j] = 0;
      if (second[i - 1] == s1[j - 1]) dp[i][j] += dp[i - 1][j - 1] + 1;
      dp[i][j] = (dp[i][j] + dp[i][j - 1]) % 1000000007;
    }
    final = (final + dp[i][n1]) % 1000000007;
  }
  cout << final << endl;
  return 0;
}
