#include <bits/stdc++.h>
using namespace std;
char s[5003], t[5003];
signed long long int dp[5003], ndp[5003];
int main() {
  cin >> s >> t;
  int ls, lt;
  signed long long int ans = 0;
  ls = strlen(s);
  lt = strlen(t);
  for (int i = lt - 1; i >= 0; --i) {
    for (int j = ls - 1; j >= 0; --j) {
      if (s[j] == t[i]) ndp[j] = (1 + dp[j + 1]) % 1000000007;
    }
    for (int j = ls - 1; j >= 0; --j) {
      dp[j] += ndp[j];
      dp[j] %= 1000000007;
      ndp[j] = 0;
    }
  }
  for (int j = ls - 1; j >= 0; --j) {
    ans += dp[j];
    ans %= 1000000007;
  }
  cout << ans;
}
