#include <bits/stdc++.h>
using namespace std;
constexpr int MAX = 1005;
constexpr int MAX2 = 55;
constexpr int INF = 1e9;
int n, na, nb;
char s[MAX], a[MAX2], b[MAX2];
int transa[MAX2][256];
int transb[MAX2][256];
int dp[MAX][MAX2][MAX2];
void compute_trans(int len, char *s, int trans[][256]) {
  for (int i = 0; i < len; ++i) {
    for (char c = 'a'; c <= 'z'; ++c) {
      if (c == s[i] && i < len - 1) {
        trans[i][c] = i + 1;
      } else {
        for (int poss = 0; poss <= i; ++poss) {
          bool works = true;
          for (int j = 0; j < poss; ++j) {
            char d = j == poss - 1 ? c : s[i - (poss - 1 - j)];
            works &= s[j] == d;
          }
          if (works) trans[i][c] = poss;
        }
      }
    }
  }
}
int main() {
  scanf(" %s", s);
  scanf(" %s", a);
  scanf(" %s", b);
  n = (int)strlen(s);
  na = (int)strlen(a);
  nb = (int)strlen(b);
  compute_trans(na, a, transa);
  compute_trans(nb, b, transb);
  for (int i = 0; i < MAX; ++i) {
    for (int j = 0; j < MAX2; ++j) {
      for (int k = 0; k < MAX2; ++k) {
        dp[i][j][k] = -INF;
      }
    }
  }
  dp[0][0][0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < na; ++j) {
      for (int k = 0; k < nb; ++k) {
        for (char c = 'a'; c <= 'z'; ++c) {
          if (s[i] != c && s[i] != '*') continue;
          int nj = transa[j][c];
          int nk = transb[k][c];
          int nans = dp[i][j][k];
          if (c == a[j]) {
            if (j == na - 1) {
              ++nans;
            }
          }
          if (c == b[k]) {
            if (k == nb - 1) {
              --nans;
            }
          }
          dp[i + 1][nj][nk] = max(dp[i + 1][nj][nk], nans);
        }
      }
    }
  }
  int best = -INF;
  for (int j = 0; j < na; ++j) {
    for (int k = 0; k < nb; ++k) {
      best = max(best, dp[n][j][k]);
    }
  }
  printf("%d\n", best);
  return 0;
}
