#include <bits/stdc++.h>
using namespace std;
char a[5010], b[5010];
int dp[5010][5010], sum;
int main() {
  cin >> a >> b;
  int e = strlen(a);
  int l = strlen(b);
  for (int i = 0; i < e; i++) {
    for (int j = 0; j < l; j++)
      if (a[i] == b[j])
        dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j] + 1) % 1000000007;
      else
        dp[i + 1][j + 1] = dp[i + 1][j] % 1000000007;
  }
  for (int i = 1; i <= e; i++) sum = (sum + dp[i][l]) % 1000000007;
  cout << sum;
  return 0;
}
