#include <bits/stdc++.h>
using namespace std;
const long long tam = 200010;
const long long MOD = 1000000007;
const long long MOD1 = 998244353;
const double EPS = 1e-9;
const double PI = acos(-1);
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string a, b;
  cin >> a >> b;
  long long in = 0;
  long long res = 0;
  vector<long long> sus(a.size(), 0);
  for (long long i = 0, asdz = b.size(); i < asdz; i++) {
    for (int j = (long long)a.size() - 1; j > -1; j--) {
      if (a[j] == b[i]) {
        res++;
        sus[j]++;
        if (j > 0) {
          sus[j] += sus[j - 1];
          res += sus[j - 1];
        }
        sus[j] %= MOD;
        res %= MOD;
      }
    }
  }
  cout << res << '\n';
  return 0;
}
