#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6010;
int n;
unsigned long long int DP[MAXN], DPP[MAXN];
long long int res;
int main() {
  string s1;
  string s2;
  cin >> s1;
  cin >> s2;
  n = ((int)(s2.size()));
  for (int i = 0; i < ((int)(s1.size())); i++) {
    for (int j = 0; j < ((int)(s2.size())); j++) {
      if (s2[j] == s1[i]) DPP[j] = (DPP[j] + DP[j - 1] + 1) % 1000000007;
      DPP[j + 1] = (DPP[j + 1] + DPP[j]) % 1000000007;
    }
    for (int j = 0; j < ((int)(s2.size())); j++) DP[j] = DPP[j];
    res = (res + DPP[n]) % 1000000007;
    memset(DPP, 0, sizeof(DPP));
  }
  cout << res << endl;
  return 0;
}
