#include <bits/stdc++.h>
using namespace std;
vector<int> kmp(string &str) {
  int n = str.size();
  vector<int> res(n + 1);
  res[0] = -1;
  int ind = -1;
  for (int i = 0; i < n; i++) {
    while (ind >= 0 && str[i] != str[ind]) ind = res[ind];
    ind++;
    res[i + 1] = ind;
  }
  return res;
}
int nex(string &str, char ch, int i, vector<int> &kmp1) {
  if (str[i] == ch) return i + 1;
  int res = i;
  while (res >= 0 && str[res] != ch) res = kmp1[res];
  return res + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s, s1, s2;
  cin >> s >> s1 >> s2;
  int n = s.size(), n1 = s1.size(), n2 = s2.size();
  vector<int> kmp1 = kmp(s1), kmp2 = kmp(s2);
  vector<vector<vector<int>>> dp(
      n + 1, vector<vector<int>>(n1 + 1, vector<int>(n2 + 1, -(1 << 29))));
  dp[0][0][0] = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '*') {
      for (char ch = 'a'; ch <= 'z'; ch++) {
        for (int j = 0; j < n1; j++) {
          for (int k = 0; k < n2; k++) {
            int nj = nex(s1, ch, j, kmp1), nk = nex(s2, ch, k, kmp2);
            dp[i + 1][nj][nk] = max(dp[i + 1][nj][nk], dp[i][j][k]);
          }
        }
      }
    } else {
      char ch = s[i];
      for (int j = 0; j < n1; j++) {
        for (int k = 0; k < n2; k++) {
          int nj = nex(s1, ch, j, kmp1), nk = nex(s2, ch, k, kmp2);
          dp[i + 1][nj][nk] = max(dp[i + 1][nj][nk], dp[i][j][k]);
        }
      }
    }
    int nj = kmp1[n1], nk = kmp2[n2];
    for (int j = 0; j < n1; j++) {
      dp[i + 1][j][nk] = max(dp[i + 1][j][nk], dp[i + 1][j][n2] - 1);
    }
    for (int k = 0; k < n2; k++) {
      dp[i + 1][nj][k] = max(dp[i + 1][nj][k], dp[i + 1][n1][k] + 1);
    }
    dp[i + 1][nj][nk] = max(dp[i + 1][nj][nk], dp[i + 1][n1][n2]);
  }
  int res = -(1 << 29);
  for (int j = 0; j < n1; j++) {
    for (int k = 0; k < n2; k++) {
      res = max(res, dp[n][j][k]);
    }
  }
  cout << res << "\n";
  return 0;
}
