#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
const int inf = 0x3f3f3f3f;
const long long INF = 1e18;
const long long mod = 998244353;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
char a[maxn], s[maxn], t[maxn];
int ne1[maxn], ne2[maxn];
int dp[maxn][55][55];
inline void getnex() {
  for (int i = 2, j = 0; i <= strlen(s + 1); i++) {
    while (j > 0 && s[i] != s[j + 1]) j = ne1[j];
    if (s[i] == s[j + 1]) j++;
    ne1[i] = j;
  }
  for (int i = 2, j = 0; i <= strlen(t + 1); i++) {
    while (j > 0 && t[i] != t[j + 1]) j = ne2[j];
    if (t[i] == t[j + 1]) j++;
    ne2[i] = j;
  }
}
int main() {
  scanf("%s", a + 1);
  scanf("%s", s + 1);
  scanf("%s", t + 1);
  getnex();
  int len = strlen(a + 1), len1 = strlen(s + 1), len2 = strlen(t + 1);
  for (int i = 0; i < maxn; i++)
    for (int j = 0; j < 55; j++)
      for (int k = 0; k < 55; k++) dp[i][j][k] = -inf;
  dp[0][0][0] = 0;
  for (int i = 1; i <= len; i++)
    for (int j = 0; j < len1 + 1; j++)
      for (int k = 0; k < len2 + 1; k++) {
        if (a[i] == '*') {
          for (char op = 'a'; op <= 'z'; op++) {
            int pos1 = j;
            while (pos1 > 0 && op != s[pos1 + 1]) pos1 = ne1[pos1];
            if (op == s[pos1 + 1]) pos1++;
            int pos2 = k;
            while (pos2 > 0 && op != t[pos2 + 1]) pos2 = ne2[pos2];
            if (op == t[pos2 + 1]) pos2++;
            dp[i][pos1][pos2] =
                max(dp[i][pos1][pos2],
                    dp[i - 1][j][k] + (pos1 == len1) - (pos2 == len2));
          }
        } else {
          int pos1 = j;
          while (pos1 > 0 && a[i] != s[pos1 + 1]) pos1 = ne1[pos1];
          if (a[i] == s[pos1 + 1]) pos1++;
          int pos2 = k;
          while (pos2 > 0 && a[i] != t[pos2 + 1]) pos2 = ne2[pos2];
          if (a[i] == t[pos2 + 1]) pos2++;
          dp[i][pos1][pos2] =
              max(dp[i][pos1][pos2],
                  dp[i - 1][j][k] + (pos1 == len1) - (pos2 == len2));
        }
      }
  int ans = -inf;
  for (int j = 0; j < len1 + 1; j++)
    for (int k = 0; k < len2 + 1; k++) ans = max(ans, dp[len][j][k]);
  printf("%d\n", ans);
  return 0;
}
