#include <bits/stdc++.h>
using namespace std;
string s, t;
long long cnt[2][5001];
int main() {
  cin >> s >> t;
  int m = s.size();
  int n = t.size();
  int cur = 1;
  int prev = 0;
  long long total = 0;
  for (int i = 1; i <= m; i++) {
    cnt[cur][0] = 0;
    for (int j = 1; j <= n; j++) {
      cnt[cur][j] = cnt[cur][j - 1];
      if (s[i - 1] == t[j - 1]) {
        cnt[cur][j]++;
        cnt[cur][j] += cnt[prev][j - 1];
      }
      cnt[cur][j] %= 1000000007;
    }
    total = (total + cnt[cur][n]) % 1000000007;
    cur ^= 1;
    prev ^= 1;
  }
  cout << total << endl;
}
