#include <bits/stdc++.h>
using namespace std;
template <class T>
void max_swap(T& a, const T& b) {
  a = max(a, b);
}
template <class T>
void min_swap(T& a, const T& b) {
  a = min(a, b);
}
const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
bool valid_pos(int x, int y, int w, int h) {
  return 0 <= x && x < w && 0 <= y && y < h;
}
int main() {
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  int n = s.size(), m = t.size();
  static int dp[5555][5555];
  const int mod = 1000000007;
  for (int i = 0; i < n; ++i) {
    int sum = 0;
    for (int j = 0; j < m; ++j) {
      if (s[i] == t[j]) {
        (dp[i + 1][j + 1] += sum + 1) %= mod;
      }
      (sum += dp[i][j + 1]) %= mod;
    }
  }
  int res = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) (res += dp[i + 1][j + 1]) %= mod;
  cout << res << endl;
}
