#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
int fs[100], ft[100];
char c[1050], s[100], t[100];
int dp[1050][100][100];
void GetNextval(char* p, int next[]) {
  int pLen = strlen(p);
  next[0] = -1;
  int k = -1;
  int j = 0;
  while (j < pLen) {
    if (k == -1 || p[j] == p[k]) {
      ++j;
      ++k;
      if (p[j] != p[k])
        next[j] = k;
      else
        next[j] = next[k];
    } else {
      k = next[k];
    }
  }
}
int main() {
  scanf("%s%s%s", c, s, t);
  GetNextval(s, fs);
  GetNextval(t, ft);
  int nc = strlen(c);
  int ns = strlen(s);
  int nt = strlen(t);
  for (int i = 0; i <= nc; i++)
    for (int j = 0; j <= ns; j++)
      for (int k = 0; k <= nt; k++) dp[i][j][k] = -1e9;
  dp[0][0][0] = 0;
  for (int i = 0; i <= nc; i++) {
    for (char ch = 'a'; ch <= 'z'; ch++) {
      if (c[i] != '*' && ch != c[i]) continue;
      for (int j = 0; j <= ns; j++) {
        for (int k = 0; k <= nt; k++) {
          if (dp[i][j][k] == -1e9) continue;
          int jj = j;
          int kk = k;
          while (jj && ch != s[jj]) jj = fs[jj];
          while (kk && ch != t[kk]) kk = ft[kk];
          int f = 0;
          if (s[jj] == ch) jj++;
          if (t[kk] == ch) kk++;
          if (jj == ns) f++;
          if (kk == nt) f--;
          dp[i + 1][jj][kk] = max(dp[i + 1][jj][kk], dp[i][j][k] + f);
        }
      }
    }
  }
  int sum = -1e9;
  for (int j = 0; j <= ns; j++)
    for (int k = 0; k <= nt; k++) sum = max(sum, dp[nc][j][k]);
  printf("%d\n", sum);
}
