#include <bits/stdc++.h>
using namespace std;
const int maxnodes = 1005;
string s, t;
int dp[5001][5001];
int rec(int i, int j) {
  if (i == s.length() or j == t.length()) return 0;
  if (dp[i][j] == -1) {
    long long ans = 0;
    if (s[i] == t[j]) ans = 1 + rec(i + 1, j + 1);
    ans = (ans + rec(i, j + 1)) % 1000000007;
    dp[i][j] = ans;
    return ans;
  } else
    return dp[i][j];
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> s >> t;
  memset(dp, -1, sizeof(dp));
  long long ans = 0;
  for (int i = 0; i < s.length(); i++) {
    ans = (ans + rec(i, 0)) % 1000000007;
  }
  cout << ans << "\n";
}
