#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
vector<int> kmp(string s) {
  int n = s.size();
  vector<int> lps(n);
  lps[0] = 0;
  for (int i = 1; i < n; i++) {
    int j = lps[i - 1];
    while (j > 0 && s[i] != s[j]) j = lps[j - 1];
    if (s[i] == s[j]) j++;
    lps[i] = j;
  }
  return lps;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string c, s, t;
  cin >> c >> s >> t;
  int l = c.size(), n = s.size(), m = t.size();
  vector<int> lps_s = kmp(s), lps_t = kmp(t);
  vector<vector<int>> nxt_s(n, vector<int>(26, 0)),
      nxt_t(m, vector<int>(26, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      int k = i;
      while (k > 0 && s[k] != 'a' + j) k = lps_s[k - 1];
      if (s[k] == 'a' + j) k++;
      nxt_s[i][j] = k;
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 26; j++) {
      int k = i;
      while (k > 0 && t[k] != 'a' + j) k = lps_t[k - 1];
      if (t[k] == 'a' + j) k++;
      nxt_t[i][j] = k;
    }
  }
  vector<vector<vector<int>>> dp(l + 1,
                                 vector<vector<int>>(n, vector<int>(m, -INF)));
  dp[0][0][0] = 0;
  for (int i = 0; i < l; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < m; k++) {
        if (dp[i][j][k] != -INF) {
          if (c[i] == '*') {
            for (int cr = 0; cr < 26; cr++) {
              int ns = nxt_s[j][cr], nt = nxt_t[k][cr], val = dp[i][j][k];
              if (ns == n) {
                val++;
                ns = lps_s[ns - 1];
              }
              if (nt == m) {
                val--;
                nt = lps_t[nt - 1];
              }
              dp[i + 1][ns][nt] = max(dp[i + 1][ns][nt], val);
            }
          } else {
            int cr = c[i] - 'a';
            int ns = nxt_s[j][cr], nt = nxt_t[k][cr], val = dp[i][j][k];
            if (ns == n) {
              val++;
              ns = lps_s[ns - 1];
            }
            if (nt == m) {
              val--;
              nt = lps_t[nt - 1];
            }
            dp[i + 1][ns][nt] = max(dp[i + 1][ns][nt], val);
          }
        }
      }
    }
  }
  int ans = -INF;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans = max(ans, dp[l][i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
