#include <bits/stdc++.h>
using namespace std;
char s[5100], t[5100];
long long dp[5100][5100];
inline int to(char c) { return c - 'a'; }
int main() {
  int an = 0;
  int i, j, k, n, sl, tl;
  scanf("%s%s", s + 1, t + 1);
  sl = strlen(s + 1);
  tl = strlen(t + 1);
  for (i = 1; i <= sl; i++) {
    for (j = 1; j <= tl; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
        an += dp[i][j];
        an %= 1000000007;
      }
      dp[i][j] += dp[i][j - 1];
      dp[i][j] %= 1000000007;
    }
  }
  cout << an << endl;
  return 0;
}
