#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
string s, t;
int lenX, lenY;
long long dp[5009][5009];
inline long long go(int x, int y) {
  if (x < 0 || y < 0) return 0LL;
  long long &ret = dp[x][y];
  if (ret != -1) return ret;
  ret = 0;
  if (y > 0) ret = go(x, y - 1);
  if (ret >= MOD) ret -= MOD;
  if (s[x] == t[y]) {
    ret++;
    if (x > 0 && y > 0) ret = (ret + go(x - 1, y - 1)) % MOD;
  }
  return ret;
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> s >> t;
  lenX = (int)s.length();
  lenY = (int)t.length();
  long long ans = 0;
  for (int i = 0; i < lenX; ++i) {
    ans += go(i, lenY - 1);
    if (ans >= MOD) ans -= MOD;
  }
  printf("%lld\n", ans);
  return 0;
}
