#include <bits/stdc++.h>
using namespace std;
long long dp[5009][5009], cnt[500];
int n, m;
char s[5009], t[5009];
int main() {
  while (scanf("%s%s", s + 1, t + 1) + 1) {
    n = strlen(s + 1);
    m = strlen(t + 1);
    for (int i = 1; i <= m; i++)
      if (s[1] == t[i]) dp[1][i] = 1;
    for (int i = 2; i <= n; i++) {
      memset(cnt, 0, sizeof(cnt));
      for (int j = 1; j <= m; j++) {
        if (s[i] == t[j]) {
          dp[i][j] = (1 + cnt[s[i - 1]]) % 1000000007;
        }
        cnt[s[i - 1]] = (cnt[s[i - 1]] + dp[i - 1][j]) % 1000000007;
      }
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) ans = (ans + dp[i][j]) % 1000000007;
    cout << ans << endl;
  }
  return 0;
}
