#include <bits/stdc++.h>
using namespace std;
const int MAX = 5000 + 10;
int dp[MAX][MAX];
const int Mod = 1e9 + 7;
int main() {
  int ans = 0;
  string s, t;
  cin >> s >> t;
  int a = s.size(), b = t.size();
  for (int i = 1; i < a + 1; i++)
    for (int j = 1; j < b + 1; j++) {
      dp[i][j] = dp[i][j - 1];
      if (s.at(i - 1) == t.at(j - 1)) dp[i][j] += dp[i - 1][j - 1] + 1;
      if (dp[i][j] >= Mod) dp[i][j] %= Mod;
    }
  for (int i = 0; i < a + 1; i++) {
    ans += dp[i][b];
    if (ans >= Mod) ans %= Mod;
  }
  cout << ans << endl;
  return 0;
}
