#include <bits/stdc++.h>
using namespace std;
char c[1005], s[55], t[55];
int ns[55], nt[55];
int tos[55][30], tot[55][30];
int lenc, lens, lent;
int dp[1005][55][55];
void init() {
  lenc = strlen(c + 1), lens = strlen(s + 1), lent = strlen(t + 1);
  ns[1] = 0, nt[1] = 0;
  for (int i = 2, j = 0; i <= lens; i++) {
    while (j && s[j + 1] != s[i]) j = ns[j];
    if (s[j + 1] == s[i]) j++;
    ns[i] = j;
  }
  for (int i = 2, j = 0; i <= lent; i++) {
    while (j && t[j + 1] != t[i]) j = nt[j];
    if (t[j + 1] == t[i]) j++;
    nt[i] = j;
  }
  for (int i = 0; i <= lens; i++) {
    for (int k = 0; k < 26; k++) {
      int j = i;
      while (j && s[j + 1] != k + 'a') j = ns[j];
      if (s[j + 1] == k + 'a') j++;
      tos[i][k] = j;
    }
  }
  for (int i = 0; i <= lent; i++) {
    for (int k = 0; k < 26; k++) {
      int j = i;
      while (j && t[j + 1] != k + 'a') j = nt[j];
      if (t[j + 1] == k + 'a') j++;
      tot[i][k] = j;
    }
  }
}
int main() {
  scanf("%s%s%s", c + 1, s + 1, t + 1);
  init();
  int n = strlen(c + 1);
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= 50; j++)
      for (int k = 0; k <= 50; k++) dp[i][j][k] = -1000000;
  dp[0][0][0] = 0;
  for (int i = 1; i <= n; i++) {
    if (c[i] == '*') {
      for (int j = 0; j <= lens; j++) {
        for (int k = 0; k <= lent; k++) {
          if (dp[i - 1][j][k] <= -1000000) continue;
          for (int q = 0; q < 26; q++) {
            int temp1 = tos[j][q], temp2 = tot[k][q];
            dp[i][temp1][temp2] =
                max(dp[i][temp1][temp2],
                    dp[i - 1][j][k] + (temp1 == lens) - (temp2 == lent));
          }
        }
      }
    } else {
      for (int j = 0; j <= lens; j++) {
        for (int k = 0; k <= lent; k++) {
          if (dp[i - 1][j][k] <= -1000000) continue;
          int q = c[i] - 'a';
          int temp1 = tos[j][q], temp2 = tot[k][q];
          dp[i][temp1][temp2] =
              max(dp[i][temp1][temp2],
                  dp[i - 1][j][k] + (temp1 == lens) - (temp2 == lent));
        }
      }
    }
  }
  int res = -1000000;
  for (int i = 0; i <= lens; i++)
    for (int j = 0; j <= lent; j++) res = max(res, dp[n][i][j]);
  cout << res << endl;
}
