#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int dp[5050][5050];
int sum[5050][5050];
char a[5050], b[5050];
int main() {
  scanf("%s%s", a, b);
  int ans = 0;
  for (int i = 0; a[i]; i++)
    for (int j = 0; b[j]; j++) {
      if (a[i] == b[j]) {
        dp[i + 1][j + 1] += sum[i][j] + 1;
        dp[i + 1][j + 1] %= mod;
        ans += dp[i + 1][j + 1];
        ans %= mod;
      }
      sum[i + 1][j + 1] = sum[i + 1][j] + dp[i + 1][j + 1];
      sum[i + 1][j + 1] %= mod;
    }
  printf("%d\n", ans);
  return 0;
}
