#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A>
string to_string(A);
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool f = 1;
  string r = "{";
  for (const auto &x : v) {
    if (!f) r += ", ";
    f = 0;
    r += to_string(x);
  }
  return r + "}";
}
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
inline int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
inline int sub(int a, int b) {
  a -= b;
  if (a < 0) a += MOD;
  return a;
}
inline int mul(int a, int b) { return (int)((long long)a * b % MOD); }
inline int binpow(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) res = mul(res, a);
    a = mul(a, a);
    b /= 2;
  }
  return res;
}
inline int inv(int a) { return binpow(a, MOD - 2); }
int gcd(int a, int b, int &x, int &y) {
  if (a == 0) {
    x = 0, y = 1;
    return b;
  }
  int x1, y1;
  int d = gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
const int N = 1e3 + 5, M = 55, INF = 1e7;
int dp[N][M][M], nxt_s[M][26], nxt_t[M][26];
void precalc(string &s, int nxt[M][26]) {
  int n = s.size();
  vector<int> pi(n);
  for (int i = 2; i < n; ++i) {
    int j = pi[i - 1];
    while (j > 0 && s[j + 1] != s[i]) j = pi[j];
    if (s[j + 1] == s[i]) j++;
    pi[i] = j;
  }
  for (int i = 0; i < n; ++i)
    for (char c = 'a'; c <= 'z'; ++c) {
      int j = i;
      while (j > 0 && s[j + 1] != c) j = pi[j];
      if (s[j + 1] == c) j++;
      nxt[i][c - 'a'] = j;
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string cs, s, t;
  cin >> cs >> s >> t;
  int size = cs.size(), n = s.size(), m = t.size();
  cs = '#' + cs;
  s = '#' + s;
  t = '#' + t;
  precalc(s, nxt_s);
  precalc(t, nxt_t);
  for (int i = 0; i <= size; ++i)
    for (int j = 0; j <= n; ++j)
      for (int k = 0; k <= m; ++k) dp[i][j][k] = -INF;
  dp[0][0][0] = 0;
  for (int i = 0; i < size; ++i)
    for (int j = 0; j <= n; ++j)
      for (int k = 0; k <= m; ++k)
        for (char c = 'a'; c <= 'z'; ++c)
          if (cs[i + 1] == c || cs[i + 1] == '*') {
            int nxs = nxt_s[j][c - 'a'], nxt = nxt_t[k][c - 'a'];
            dp[i + 1][nxs][nxt] =
                max(dp[i + 1][nxs][nxt], dp[i][j][k] + (nxs == n) - (nxt == m));
          }
  int ans = -INF;
  for (int j = 0; j <= n; ++j)
    for (int k = 0; k <= m; ++k) ans = max(ans, dp[size][j][k]);
  cout << ans << "\n";
  return 0;
}
