#include <bits/stdc++.h>
using namespace std;
int smemo[5010][5010][2];
int main() {
  string A, B;
  cin >> A >> B;
  int N = A.length();
  int M = B.length();
  A = "0" + A;
  B = "0" + B;
  smemo[0][0][1] = smemo[0][0][0] = 1;
  for (int i = (1); i <= (N); i++) {
    smemo[i][0][0] = 1;
    smemo[i][0][1] = 0;
  }
  for (int j = (1); j <= (M); j++) {
    smemo[0][j][1] = 0;
    smemo[0][j][0] = 1;
  }
  for (int i = (1); i <= (N); i++)
    for (int j = (1); j <= (M); j++) {
      long long ans1 = 0;
      if (B[j] == A[i]) {
        ans1 += (long long)smemo[i - 1][j - 1][0];
      }
      ans1 %= 1000000007;
      smemo[i][j][1] = ans1;
      long long ans2 =
          ((long long)smemo[i][j][1] + (long long)smemo[i][j - 1][0]) %
          1000000007;
      smemo[i][j][0] = ans2;
    }
  long long ans = 0;
  for (int i = (1); i <= (N); i++)
    for (int j = (1); j <= (M); j++) {
      ans += (long long)smemo[i][j][1];
      ans %= 1000000007;
    }
  cout << ans << endl;
}
