#include <bits/stdc++.h>
using namespace std;
char s[5055], t[5055];
int N, M;
const int MOD = 1000 * 1000 * 1000 + 7;
int add(int x, int y) { return ((long long)x + y) % MOD; }
int mul(int x, int y) { return ((long long)x * y) % MOD; }
int dp[5055][5055];
int main() {
  while (scanf(" %s %s", s, t) != EOF) {
    N = strlen(s);
    M = strlen(t);
    for (int i = (0); i <= (int)(5022); ++i) dp[i][0] = dp[0][i] = 1;
    for (int i = (1); i <= (int)(N); ++i)
      for (int j = (1); j <= (int)(M); ++j) {
        int temp = dp[i][j - 1];
        if (s[i - 1] == t[j - 1]) {
          temp = add(temp, dp[i - 1][j - 1]);
        }
        dp[i][j] = temp;
      }
    int res = 0;
    for (int i = (1); i <= (int)(N); ++i) res = add(res, dp[i][M] - 1 + MOD);
    printf("%d\n", res);
  }
}
