#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
char c[1005], s[55], t[55];
int dp[1005][55][55];
int nexts[55], nextt[55];
void getnext(char *s, int *nexts, int n) {
  for (int i = 1; i <= n + 1; i++) nexts[i] = 1;
  for (int i = 2, j; i <= n; i++) {
    j = i;
    while (j > 1) {
      j = nexts[j];
      if (s[j] == s[i]) {
        nexts[i + 1] = j + 1;
        break;
      }
    }
  }
}
int main() {
  int len, n, m, p1, p2, ans, rec;
  scanf("%s", c + 1);
  len = strlen(c + 1);
  scanf("%s", s + 1);
  n = strlen(s + 1);
  scanf("%s", t + 1);
  m = strlen(t + 1);
  getnext(s, nexts, n);
  getnext(t, nextt, m);
  for (int i = 0; i <= len; i++) {
    for (int j = 0; j <= n; j++) {
      for (int k = 0; k <= m; k++) {
        dp[i][j][k] = -INF;
      }
    }
  }
  dp[0][0][0] = 0;
  for (int i = 0; i < len; i++) {
    for (int j = 0; j <= n; j++) {
      for (int k = 0; k <= m; k++) {
        if (dp[i][j][k] == -INF) continue;
        for (char ch = 'a'; ch <= 'z'; ch++) {
          if (c[i + 1] != '*' && c[i + 1] != ch) continue;
          if (j < n && ch == s[j + 1])
            p1 = j + 1;
          else {
            p1 = j + 1;
            while (p1 > 1) {
              p1 = nexts[p1];
              if (ch == s[p1]) {
                p1++;
                break;
              }
            }
            p1--;
          }
          if (k < m && ch == t[k + 1])
            p2 = k + 1;
          else {
            p2 = k + 1;
            while (p2 > 1) {
              p2 = nextt[p2];
              if (ch == t[p2]) {
                p2++;
                break;
              }
            }
            p2--;
          }
          rec = dp[i][j][k] + (p1 == n ? 1 : 0) - (p2 == m ? 1 : 0);
          dp[i + 1][p1][p2] = max(dp[i + 1][p1][p2], rec);
        }
      }
    }
  }
  ans = -INF;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      ans = max(ans, dp[len][i][j]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
