#include <bits/stdc++.h>
using namespace std;
int n, len[2];
char str[1002], pat[2][52];
int prefix[52][26][2];
int fp(int pre, char c, int k) {
  if (prefix[pre][c - 'a'][k] != -1) return prefix[pre][c - 'a'][k];
  char tmp[55];
  for (int i = 0; i < pre; i++) tmp[i] = pat[k][i];
  tmp[pre] = c;
  int st = 0;
  if (pre == len[k]) st++;
  for (int i = st; i <= pre; i++) {
    bool mk = true;
    for (int j = i; j <= pre; j++) {
      if (tmp[j] != pat[k][j - i]) {
        mk = false;
        break;
      }
    }
    if (mk) {
      prefix[pre][c - 'a'][k] = pre - i + 1;
      return prefix[pre][c - 'a'][k];
    }
  }
  return prefix[pre][c - 'a'][k] = 0;
}
int dp[1002][52][52];
int main(void) {
  cin >> str >> pat[0] >> pat[1];
  len[0] = strlen(pat[0]);
  len[1] = strlen(pat[1]);
  n = strlen(str);
  memset(prefix, -1, sizeof(prefix));
  for (int k = 0; k < n; k++) {
    for (int i = 0; i <= len[0]; i++) {
      for (int j = 0; j <= len[1]; j++) {
        dp[k][i][j] = -1001;
      }
    }
  }
  if (str[0] == '*') {
    for (int c = 0; c < 26; c++) {
      int p = fp(0, (char)c + 'a', 0), q = fp(0, (char)c + 'a', 1);
      dp[0][p][q] = 0;
    }
  } else {
    int p = fp(0, (char)str[0], 0), q = fp(0, (char)str[0], 1);
    dp[0][p][q] = 0;
  }
  for (int i = 0; i <= len[0]; i++) {
    if (dp[0][i][len[1]] != -1001) dp[0][i][len[1]]--;
  }
  for (int i = 0; i <= len[1]; i++)
    if (dp[0][len[0]][i] != -1001) dp[0][len[0]][i]++;
  for (int k = 1; k < n; k++) {
    for (int i = 0; i <= len[0]; i++) {
      for (int j = 0; j <= len[1]; j++) {
        if (dp[k - 1][i][j] == -1001) continue;
        if (str[k] == '*') {
          for (int c = 0; c < 26; c++) {
            int p = fp(i, c + 'a', 0), q = fp(j, c + 'a', 1);
            dp[k][p][q] = max(dp[k][p][q], dp[k - 1][i][j]);
          }
        } else {
          int p = fp(i, str[k], 0), q = fp(j, str[k], 1);
          dp[k][p][q] = max(dp[k][p][q], dp[k - 1][i][j]);
        }
      }
    }
    for (int i = 0; i <= len[0]; i++)
      if (dp[k][i][len[1]] != -1001) dp[k][i][len[1]]--;
    for (int i = 0; i <= len[1]; i++)
      if (dp[k][len[0]][i] != -1001) dp[k][len[0]][i]++;
  }
  int ans = -1001;
  for (int i = 0; i <= len[0]; i++) {
    for (int j = 0; j <= len[1]; j++) {
      if (dp[n - 1][i][j] == -1001) continue;
      ans = max(ans, dp[n - 1][i][j]);
    }
  }
  cout << ans << endl;
}
