#include <bits/stdc++.h>
using namespace std;
const int N = 5007;
long long int dp[2][N];
long long int dp1[2][N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s, t;
  cin >> s >> t;
  int n, m;
  n = s.size();
  m = t.size();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i - 1] != t[j - 1]) {
        dp1[1][j] = dp1[1][j - 1] % 1000000007;
        dp[1][j] =
            (dp[1 - 1][j] + dp[1][j - 1] - dp[1 - 1][j - 1] + 1000000007) %
            1000000007;
      } else {
        dp1[1][j] =
            (1 + dp1[1 - 1][j - 1] + dp1[1][j - 1] + 1000000007) % 1000000007;
        dp[1][j] = (dp[1 - 1][j] + dp[1][j - 1] + 1 - dp[1 - 1][j - 1] +
                    dp1[1 - 1][j - 1] + 1000000007) %
                   1000000007;
      }
    }
    for (int j = 1; j <= m; j++) {
      dp[0][j] = dp[1][j];
      dp[1][j] = 0;
      dp1[0][j] = dp1[1][j];
      dp1[1][j] = 0;
    }
  }
  cout << dp[0][m] % 1000000007;
}
