#include <bits/stdc++.h>
using namespace std;
char C[1010];
char s[55], t[55];
int nxt_s[55], nxt_t[55];
int n, m, l;
long long f[1010][55][55];
int main() {
  scanf("%s", C + 1);
  n = strlen(C + 1);
  scanf("%s", s + 1);
  m = strlen(s + 1);
  scanf("%s", t + 1);
  l = strlen(t + 1);
  for (int i = 2; i <= m; i++) {
    int j = nxt_s[i - 1];
    while (j && s[j + 1] != s[i]) j = nxt_s[j];
    if (s[j + 1] == s[i]) j++;
    nxt_s[i] = j;
  }
  for (int i = 2; i <= l; i++) {
    int j = nxt_t[i - 1];
    while (j && t[j + 1] != t[i]) j = nxt_t[j];
    if (t[j + 1] == t[i]) j++;
    nxt_t[i] = j;
  }
  memset(f, -127, sizeof(f));
  int mn = f[0][0][0];
  f[0][0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= m; j++) {
      for (int k = 0; k <= l; k++) {
        if (f[i][j][k] == mn) continue;
        if (C[i + 1] == '*') {
          for (int c = 0; c < 26; c++) {
            int pos1 = j;
            while (pos1 && s[pos1 + 1] != c + 'a') pos1 = nxt_s[pos1];
            if (s[pos1 + 1] == c + 'a') pos1++;
            int pos2 = k;
            while (pos2 && t[pos2 + 1] != c + 'a') pos2 = nxt_t[pos2];
            if (t[pos2 + 1] == c + 'a') pos2++;
            f[i + 1][pos1][pos2] = max(f[i + 1][pos1][pos2],
                                       f[i][j][k] + (pos1 == m) - (pos2 == l));
          }
        } else {
          int pos1 = j;
          while (pos1 && s[pos1 + 1] != C[i + 1]) pos1 = nxt_s[pos1];
          if (s[pos1 + 1] == C[i + 1]) pos1++;
          int pos2 = k;
          while (pos2 && t[pos2 + 1] != C[i + 1]) pos2 = nxt_t[pos2];
          if (t[pos2 + 1] == C[i + 1]) pos2++;
          f[i + 1][pos1][pos2] =
              max(f[i + 1][pos1][pos2], f[i][j][k] + (pos1 == m) - (pos2 == l));
        }
      }
    }
  }
  long long ans = -9999999999999999;
  for (int i = 0; i <= m; i++)
    for (int j = 0; j <= l; j++) ans = max(ans, f[n][i][j]);
  cout << ans << endl;
  return 0;
}
