#include <bits/stdc++.h>
using namespace std;
string c, s, t;
int n, m, k;
int pi_s[55];
int pi_t[55];
int dp_lps_s[55][26];
int dp_lps_t[55][26];
int dp[1005][55][55];
int solve(int i, int lps_s, int lps_t) {
  if (i == n) return 0;
  if (dp[i][lps_s][lps_t] != -1) return dp[i][lps_s][lps_t];
  if (c[i] == '*') {
    int best = -100000;
    for (int ch = 0; ch < 26; ch++) {
      int ans = 0;
      int new_lps_s = dp_lps_s[lps_s][ch];
      int new_lps_t = dp_lps_t[lps_t][ch];
      if (new_lps_s == m) ans++, new_lps_s = pi_s[m - 1];
      if (new_lps_t == k) ans--, new_lps_t = pi_t[k - 1];
      ans += solve(i + 1, new_lps_s, new_lps_t);
      best = max(best, ans);
    }
    return dp[i][lps_s][lps_t] = best;
  }
  int ans = 0;
  int new_lps_s = dp_lps_s[lps_s][c[i] - 'a'];
  int new_lps_t = dp_lps_t[lps_t][c[i] - 'a'];
  if (new_lps_s == m) ans++, new_lps_s = pi_s[m - 1];
  if (new_lps_t == k) ans--, new_lps_t = pi_t[k - 1];
  return dp[i][lps_s][lps_t] = ans + solve(i + 1, new_lps_s, new_lps_t);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> c >> s >> t;
  n = c.size(), m = s.size(), k = t.size();
  for (int i = 1; i < m; i++) {
    int j = pi_s[i - 1];
    while (j && s[j] != s[i]) j = pi_s[j - 1];
    if (s[j] == s[i]) j++;
    pi_s[i] = j;
  }
  for (int i = 1; i < k; i++) {
    int j = pi_t[i - 1];
    while (j && t[j] != t[i]) j = pi_t[j - 1];
    if (t[j] == t[i]) j++;
    pi_t[i] = j;
  }
  for (int i = 1; i < m; i++) {
    int j = dp_lps_s[i - 1][s[i - 1] - 'a'];
    dp_lps_s[i - 1][s[i - 1] - 'a'] = i;
    for (int ch = 0; ch < 26; ch++) dp_lps_s[i][ch] = dp_lps_s[j][ch];
  }
  dp_lps_s[m - 1][s[m - 1] - 'a'] = m;
  for (int i = 1; i < k; i++) {
    int j = dp_lps_t[i - 1][t[i - 1] - 'a'];
    dp_lps_t[i - 1][t[i - 1] - 'a'] = i;
    for (int ch = 0; ch < 26; ch++) dp_lps_t[i][ch] = dp_lps_t[j][ch];
  }
  dp_lps_t[k - 1][t[k - 1] - 'a'] = k;
  for (int i = n - 1; i >= 0; i--) {
    for (int lps_s = 0; lps_s < m; lps_s++) {
      for (int lps_t = 0; lps_t < k; lps_t++) {
        if (c[i] == '*') {
          int best = -100000;
          for (int ch = 0; ch < 26; ch++) {
            int ans = 0;
            int new_lps_s = dp_lps_s[lps_s][ch];
            int new_lps_t = dp_lps_t[lps_t][ch];
            if (new_lps_s == m) ans++, new_lps_s = pi_s[m - 1];
            if (new_lps_t == k) ans--, new_lps_t = pi_t[k - 1];
            ans += dp[i + 1][new_lps_s][new_lps_t];
            best = max(best, ans);
          }
          dp[i][lps_s][lps_t] = best;
        } else {
          int ans = 0;
          int new_lps_s = dp_lps_s[lps_s][c[i] - 'a'];
          int new_lps_t = dp_lps_t[lps_t][c[i] - 'a'];
          if (new_lps_s == m) ans++, new_lps_s = pi_s[m - 1];
          if (new_lps_t == k) ans--, new_lps_t = pi_t[k - 1];
          dp[i][lps_s][lps_t] = ans + dp[i + 1][new_lps_s][new_lps_t];
        }
      }
    }
  }
  cout << dp[0][0][0] << '\n';
}
