#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  vector<int> dp(s.length() + 1, 0);
  int ans = 0, mod = int(1e9) + 7;
  for (int i = 0; i < t.length(); i++)
    for (int j = s.length() - 1; j >= 0; j--)
      if (t[i] == s[j]) {
        dp[j + 1] = (dp[j + 1] + dp[j] + 1) % mod;
        ans = (ans + dp[j] + 1) % mod;
      }
  cout << ans;
  return 0;
}
