#include <bits/stdc++.h>
using namespace std;
int nc, ns, nt;
string _c, _s, _t;
const int INF = 100000000;
int C[1005], S[55], T[55];
int dp[1005][55][55];
int nxs[55][26], nxt[55][26];
int kms[55], kmt[55];
int main() {
  cin >> _c >> _s >> _t;
  nc = _c.size();
  ns = _s.size();
  nt = _t.size();
  for (int i = 1; i <= nc; i++) C[i] = _c[i - 1];
  for (int i = 1; i <= ns; i++) S[i] = _s[i - 1];
  for (int i = 1; i <= nt; i++) T[i] = _t[i - 1];
  kms[1] = 0;
  for (int i = 2; i <= ns; i++) {
    int cur = kms[i - 1];
    while (cur && S[cur + 1] != S[i]) cur = kms[cur];
    if (S[cur + 1] == S[i]) cur++;
    kms[i] = cur;
  }
  for (int i = 0; i <= ns; i++) {
    for (int c = 0; c < 26; c++) {
      int cur = i;
      while (cur && S[cur + 1] != c + 'a') cur = kms[cur];
      if (S[cur + 1] == c + 'a') cur++;
      nxs[i][c] = cur;
    }
  }
  kmt[1] = 0;
  for (int i = 2; i <= nt; i++) {
    int cur = kmt[i - 1];
    while (cur && T[cur + 1] != T[i]) cur = kmt[cur];
    if (T[cur + 1] == T[i]) cur++;
    kmt[i] = cur;
  }
  for (int i = 0; i <= nt; i++) {
    for (int c = 0; c < 26; c++) {
      int cur = i;
      while (cur && T[cur + 1] != c + 'a') cur = kmt[cur];
      if (T[cur + 1] == c + 'a') cur++;
      nxt[i][c] = cur;
    }
  }
  for (int k = 0; k <= nc; k++) {
    for (int i = 0; i <= ns; i++) {
      for (int j = 0; j <= nt; j++) {
        dp[k][i][j] = -INF;
      }
    }
  }
  dp[0][0][0] = 0;
  for (int i = 0; i < nc; i++) {
    for (int j = 0; j <= ns; j++) {
      for (int k = 0; k <= nt; k++) {
        for (int c = 0; c < 26; c++) {
          if (C[i + 1] == c + 'a' || C[i + 1] == '*') {
            int __s = nxs[j][c], __t = nxt[k][c];
            dp[i + 1][__s][__t] = max(dp[i + 1][__s][__t],
                                      dp[i][j][k] + (__s == ns) - (__t == nt));
          }
        }
      }
    }
  }
  int ans = -INF;
  for (int i = 0; i <= ns; i++) {
    for (int j = 0; j <= nt; j++) {
      ans = max(ans, dp[nc][i][j]);
    }
  }
  printf("%d", ans);
}
