#include <bits/stdc++.h>
const int oo = 0x7fffffff;
const long long OO = 0x7fffffffffffffff;
template <class T>
std::ostream& operator<<(std::ostream& O, const std::vector<T>& V) {
  for (const T& x : V) O << x << " ";
  O << "\n";
  return O;
}
template <class T1, class T2>
std::ostream& operator<<(std::ostream& O, const std::pair<T1, T2>& P) {
  return O << "(" << P.first << ", " << P.second << ")";
}
struct kmp {
  std::string P;
  std::vector<int> pi;
  kmp() = default;
  kmp(const std::string& s) : P(s), pi(s.size() + 1) {
    for (size_t i = 1, l = pi[1] = 0; i < s.size(); ++i) {
      while (s[i] != s[l] and l > 0) l = pi[l];
      if (s[i] == s[l]) ++l;
      pi[i + 1] = l;
    }
  }
  void match(const std::string& T) {
    for (size_t i = 0, l = 0; i < T.size(); ++i) {
      while (T[i] != P[l] and l > 0) l = pi[l];
      if (T[i] == P[l]) ++l;
      if (l == P.size()) {
        std::cout << "match in [" << (i + 1 - l) << ", " << (i + 1) << ")\n";
        l = pi[l];
      }
    }
  }
  const int& operator[](int i) const { return pi[i]; }
} kmp_A, kmp_B;
using namespace std;
const int NX = 1002, MX = 52;
int dp[NX][MX][MX];
int na, nb, ns;
string S, A, B;
void init() {
  cin >> S >> A >> B;
  kmp_A = kmp(A);
  kmp_B = kmp(B);
  ns = S.size(), na = A.size(), nb = B.size();
  for (int k = 0; k <= ns; ++k)
    for (int i = 0; i <= na; ++i)
      for (int j = 0; j <= nb; ++j) dp[k][i][j] = -oo;
  dp[0][0][0] = 0;
}
int get_answer() {
  int best = -oo;
  for (int i = 0; i <= na; ++i)
    for (int j = 0; j <= nb; ++j) best = std::max(best, dp[ns][i][j]);
  return best;
}
inline void update(int k, int i, int j, char c) {
  int ki = i, kj = j;
  if (ki == na) ki = kmp_A[ki];
  if (kj == nb) kj = kmp_B[kj];
  while (A[ki] != c and ki > 0) ki = kmp_A[ki];
  while (B[kj] != c and kj > 0) kj = kmp_B[kj];
  if (A[ki] == c) ki++;
  if (B[kj] == c) kj++;
  int v = (ki == na ? 1 : 0) + (kj == nb ? -1 : 0);
  dp[k + 1][ki][kj] = std::max(dp[k + 1][ki][kj], dp[k][i][j] + v);
}
void compute() {
  for (int k = 0; k < ns; ++k)
    for (int i = 0; i <= na; ++i)
      for (int j = 0; j <= nb; ++j)
        if (dp[k][i][j] > -oo) {
          if (S[k] == '*')
            for (char c = 'a'; c <= 'z'; ++c) update(k, i, j, c);
          else
            update(k, i, j, S[k]);
        }
}
int main() {
  init();
  compute();
  cout << get_answer() << "\n";
  return 0;
}
