#include <bits/stdc++.h>
using namespace std;
const int LINF = -1 * 1e6;
char str[1003], a[53], b[53];
int len, alen, blen;
int dp[1003][53][53];
int api[53], bpi[53];
void getpi(const char s[53], int *pi, int tlen) {
  int j = 0;
  for (int i = 2; i <= tlen; i++) {
    while (j > 0 && s[j + 1] != s[i]) j = pi[j];
    if (s[j + 1] == s[i]) j++;
    pi[i] = j;
  }
}
int main() {
  scanf(" %s %s %s", str + 1, a + 1, b + 1);
  len = strlen(str + 1);
  alen = strlen(a + 1);
  blen = strlen(b + 1);
  getpi(a, api, alen);
  getpi(b, bpi, blen);
  for (int i = 0; i <= len; i++)
    for (int j = 0; j <= alen; j++)
      for (int k = 0; k <= blen; k++) dp[i][j][k] = LINF;
  dp[0][0][0] = 0;
  for (int i = 0; i < len; i++) {
    for (int j = 0; j <= alen; j++) {
      for (int k = 0; k <= blen; k++) {
        if (dp[i][j][k] == LINF) continue;
        if (str[i + 1] == '*') {
          for (char c = 'a'; c <= 'z'; c++) {
            int at = j, bt = k;
            while (at > 0 && a[at + 1] != c) at = api[at];
            while (bt > 0 && b[bt + 1] != c) bt = bpi[bt];
            if (a[at + 1] == c) at++;
            if (b[bt + 1] == c) bt++;
            dp[i + 1][at][bt] = max(dp[i + 1][at][bt],
                                    dp[i][j][k] + (at == alen) - (bt == blen));
          }
        } else {
          int at = j, bt = k;
          while (at > 0 && a[at + 1] != str[i + 1]) at = api[at];
          while (bt > 0 && b[bt + 1] != str[i + 1]) bt = bpi[bt];
          if (a[at + 1] == str[i + 1]) at++;
          if (b[bt + 1] == str[i + 1]) bt++;
          dp[i + 1][at][bt] =
              max(dp[i + 1][at][bt], dp[i][j][k] + (at == alen) - (bt == blen));
        }
      }
    }
  }
  int ret = LINF;
  for (int i = 0; i <= alen; i++) {
    for (int j = 0; j <= blen; j++) {
      ret = max(ret, dp[len][i][j]);
    }
  }
  printf("%d", ret);
}
