#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int dp[5005][5005];
string a, b;
int main() {
  cin >> a >> b;
  int len1 = a.length();
  int len2 = b.length();
  for (int i = 1; i <= len1; i++) {
    for (int j = 1; j <= len2; j++) {
      if (a.operator[](i - 1) == b.operator[](j - 1)) {
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % mod;
      }
      dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= len1; i++) ans = (ans + dp[i][len2]) % mod;
  cout << ans << endl;
}
