#include <bits/stdc++.h>
using namespace std;
const int inf = 1e6, MAXN = 1005;
int dp[MAXN][55][55], tnt[55], snt[55];
char c[MAXN], s[55], t[55];
void GetNext(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]) {
      ++k;
      ++j;
      next[j] = k;
    } else {
      k = next[k];
    }
  }
}
int tran(char i, int j, int nt[], char* p) {
  int len = strlen(p);
  for (;;) {
    if (i == p[j] || j == -1)
      return ++j;
    else
      j = nt[j];
  }
}
int main() {
  scanf("%s%s%s", c, s, t);
  int n = strlen(c), a = strlen(s), b = strlen(t);
  GetNext(s, snt);
  GetNext(t, tnt);
  for (int i = 0; i <= n; i++)
    for (int j = 0; j < a; j++)
      for (int k = 0; k < b; k++) dp[i][j][k] = -inf;
  int ans = -inf;
  dp[0][0][0] = 0;
  for (int i = 0; i < n; i++) {
    if (c[i] != '*') {
      for (int j = 0; j < a; j++) {
        for (int k = 0; k < b; k++) {
          int cnt = 0;
          if (dp[i][j][k] <= -inf) continue;
          int tp1 = tran(c[i], j, snt, s), tp2 = tran(c[i], k, tnt, t);
          if (tp1 == a) {
            cnt++;
            tp1 = snt[tp1];
          }
          if (tp2 == b) {
            cnt--;
            tp2 = tnt[tp2];
          }
          dp[i + 1][tp1][tp2] = max(dp[i + 1][tp1][tp2], dp[i][j][k] + cnt);
        }
      }
    } else {
      for (int j = 0; j < a; j++) {
        for (int k = 0; k < b; k++) {
          if (dp[i][j][k] <= -inf) continue;
          for (int p = 0; p < 26; p++) {
            int cnt = 0;
            int tp1 = tran('a' + p, j, snt, s), tp2 = tran('a' + p, k, tnt, t);
            if (tp1 == a) {
              cnt++;
              tp1 = snt[tp1];
            }
            if (tp2 == b) {
              cnt--;
              tp2 = tnt[tp2];
            }
            dp[i + 1][tp1][tp2] = max(dp[i + 1][tp1][tp2], dp[i][j][k] + cnt);
          }
        }
      }
    }
  }
  for (int i = 0; i < a; i++)
    for (int j = 0; j < b; j++) ans = max(ans, dp[n][i][j]);
  cout << ans;
}
