#include <bits/stdc++.h>
using namespace std;
long long int dp[5005][5005];
string second, t;
int main() {
  cin >> second >> t;
  long long int lens = second.length(), lent = t.length();
  for (int i = lens - 1; i >= 0; i--) {
    if (second[i] == t[lent - 1])
      dp[i][lent - 1] = 1;
    else
      dp[i][lent - 1] = 0;
    for (int j = lent - 2; j >= 0; j--) {
      dp[i][j] = dp[i][j + 1];
      if (second[i] == t[j])
        dp[i][j] = (dp[i][j] + dp[i + 1][j + 1] + 1) % 1000000007L;
    }
  }
  long long int ans = 0;
  for (int i = 0; i <= lens - 1; i++) ans = (ans + dp[i][0]) % 1000000007L;
  cout << ans << endl;
  return 0;
}
