#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
char s[5050], t[5050];
int dp[5050][5050];
long long ans;
int main() {
  ios::sync_with_stdio(false);
  cin >> (s + 1);
  cin >> (t + 1);
  int lens = strlen(s + 1);
  int lent = strlen(t + 1);
  for (int i = 1; i <= lens; i++) {
    for (int j = 1; j <= lent; j++) {
      if (s[i] == t[j]) dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + 1) % (mod);
      dp[i][j] = (dp[i][j] + dp[i][j - 1]) % (mod);
    }
  }
  for (int i = 1; i <= lens; i++) ans = (ans + dp[i][lent]) % mod;
  cout << ans << endl;
  return 0;
}
