#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
const int MOD = INF + 7;
const int MAXN = 5010;
string s, t;
int d[MAXN][MAXN], ans = 0, num[MAXN];
inline void update(int x, int y, int value) {
  d[x][y] += value;
  while (d[x][y] >= MOD) d[x][y] -= MOD;
}
int main() {
  cin >> s >> t;
  for (int i = 0; i < (int)(s.size() + 1); i++) {
    for (int j = 0; j < (int)(t.size()); j++) {
      if (i < (int)s.size() && s[i] == t[j]) update(i + 1, j + 1, d[i][j] + 1);
      update(i, j + 1, d[i][j]);
    }
  }
  int ans = 0;
  for (int i = 0; i < (int)(s.size()); i++)
    ans = (ans + d[i + 1][t.size()]) % MOD;
  cout << ans << endl;
  return 0;
}
