#include <bits/stdc++.h>
using namespace std;
const int MN = 5000 + 100, MOD = 1000 * 1000 * 1000 + 7;
string a, b;
int d[2][MN];
bool cu = 1;
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin >> a >> b;
  for (int i = 0; i < b.size(); i++) {
    for (int j = 0; j < a.size(); j++) {
      d[cu][j] = d[1 - cu][j];
      if (a[j] == b[i]) {
        d[cu][j] = d[1 - cu][j] + 1;
        if (j > 0) d[cu][j] += d[1 - cu][j - 1];
        d[cu][j] %= MOD;
      }
    }
    cu ^= 1;
  }
  int res = 0;
  for (int i = 0; i < a.size(); i++) res += d[1 - cu][i], res %= MOD;
  cout << res << endl;
  return 0;
}
