#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
inline void read(T &x) {
  char c;
  bool nega = 0;
  while ((!isdigit(c = getchar())) && (c != '-'))
    ;
  if (c == '-') {
    nega = 1;
    c = getchar();
  }
  x = c - 48;
  while (isdigit(c = getchar())) x = x * 10 + c - 48;
  if (nega) x = -x;
}
template <typename T>
inline void writep(T x) {
  if (x > 9) writep(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  writep(x);
}
template <typename T>
inline void writeln(T x) {
  write(x);
  putchar('\n');
}
int Touma[3200][26];
int p[3200];
string s, t;
int m;
int f[3200];
int g[3200];
int main() {
  cin >> s >> t;
  if (t.size() > s.size()) {
    puts("0");
    return 0;
  }
  m = t.size();
  t = '0' + t;
  for (char &c : s)
    if (c != '?') c -= 'a';
  for (char &c : t) c -= 'a';
  for (int i = (2); i <= (m); i++) {
    p[i] = p[i - 1];
    while ((p[i]) && (t[p[i] + 1] != t[i])) p[i] = p[p[i]];
    if (t[p[i] + 1] == t[i]) p[i]++;
  }
  for (int i = (0); i <= (m); i++) {
    for (int c = (0); c < (26); c++) {
      if (i == m)
        Touma[i][c] = p[i];
      else
        Touma[i][c] = i;
      while ((Touma[i][c]) && (t[Touma[i][c] + 1] != c))
        Touma[i][c] = p[Touma[i][c]];
      if (t[Touma[i][c] + 1] == c) Touma[i][c]++;
    }
  }
  for (int i = (1); i <= (m); i++) f[i] = -1e6;
  for (char c : s) {
    for (int i = (0); i <= (m); i++) g[i] = f[i];
    for (int i = (0); i <= (m); i++) f[i] = -1e6;
    if (c == '?')
      for (int i = (0); i <= (m); i++)
        for (int j = (0); j < (26); j++)
          f[Touma[i][j]] = max(f[Touma[i][j]], g[i]);
    else
      for (int i = (0); i <= (m); i++)
        f[Touma[i][c]] = max(f[Touma[i][c]], g[i]);
    f[m]++;
  }
  int ans = 0;
  for (int i = (0); i <= (m); i++) ans = max(ans, f[i]);
  writeln(ans);
}
