#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const int MAXM = 300010;
const int INF = 0x7fffffff;
const int MOD = 1e9 + 7;
const double eps = 1e-6;
const long double pi = acos(-1.0);
int dp[5010][5010];
char s[5010], t[5010];
int main() {
  scanf("%s", s);
  scanf("%s", t);
  int n = strlen(s);
  int m = strlen(t);
  memset(dp, 0, sizeof dp);
  int ans = 0;
  if (t[0] == s[0]) {
    dp[0][0] = 1;
    ans = 1;
  }
  for (int i = 1; i < n; ++i) {
    if (t[0] == s[i]) {
      dp[i][0] = 1 % MOD;
      ans = (ans % MOD + 1 % MOD) % MOD;
    }
  }
  for (int j = 1; j < m; ++j) {
    if (s[0] == t[j]) {
      dp[0][j] = 1 % MOD;
      ans = (ans % MOD + 1 % MOD) % MOD;
    }
  }
  for (int i = 1; i < n; ++i) {
    int sum = dp[i - 1][0] % MOD;
    for (int j = 1; j < m; ++j) {
      if (s[i] == t[j]) {
        dp[i][j] = (sum % MOD + 1 % MOD) % MOD;
      } else {
        dp[i][j] = 0;
      }
      sum = (sum % MOD + dp[i - 1][j] % MOD) % MOD;
      ans = (ans % MOD + dp[i][j] % MOD) % MOD;
    }
  }
  printf("%d\n", ans);
}
