#include <bits/stdc++.h>
using namespace std;
char s[5004], t[5004];
int same[2][5004];
int s_len, t_len;
int main() {
  int answer = 0;
  scanf("%s%s", s, t);
  memset(same[0], 0, sizeof(**same) * strlen(t));
  memset(same[1], 0, sizeof(**same) * strlen(t));
  for (int i = 0; s[i]; i++) {
    int j;
    for (j = 0; t[j]; j++) {
      if (s[i] == t[j]) {
        same[i & 1][j] =
            j > 0 ? 1 + same[!(i & 1)][j - 1] + same[i & 1][j - 1] : 1;
      } else {
        same[i & 1][j] = j > 0 ? same[i & 1][j - 1] : 0;
      }
      same[i & 1][j] =
          ((((same[i & 1][j]) % (1000000007)) + (1000000007)) % (1000000007));
    }
    answer = ((((answer + same[i & 1][j - 1]) % (1000000007)) + (1000000007)) %
              (1000000007));
  }
  printf("%d\n", answer);
  return 0;
}
