#include <bits/stdc++.h>
using namespace std;
int dp[5555][5555];
char s[5555];
char t[5555];
const int oo = 1e9 + 7;
int main() {
  cin >> s >> t;
  int lens = strlen(s);
  int lent = strlen(t);
  for (int i = lens - 1; i >= 0; i--) {
    for (int j = lent - 1; j >= 0; j--) {
      dp[i][j] = dp[i][j + 1];
      dp[i][j] %= oo;
      if (s[i] == t[j]) {
        dp[i][j] += dp[i + 1][j + 1] + 1;
        dp[i][j] %= oo;
      }
    }
  }
  int sum = 0;
  for (int i = 0; i < lens; i++) {
    sum += dp[i][0];
    sum %= oo;
  }
  cout << sum % oo << endl;
}
