#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 10, mod = 1e9 + 7;
int nxtt[N], nxts[N];
int dp[1010][60][60];
void getnext(string s, int nxt[]) {
  int i, j;
  j = nxt[0] = -1;
  i = 0;
  while (i < s.length()) {
    while (-1 != j && s[i] != s[j]) j = nxt[j];
    nxt[++i] = ++j;
  }
}
int l1, l2, l3;
void up(int i, int j, int k, int J, int K) {
  if (J == l2 && K == l3)
    dp[i + 1][nxts[J]][nxtt[K]] = max(dp[i][j][k], dp[i + 1][nxts[J]][nxtt[K]]);
  else if (J == l2)
    dp[i + 1][nxts[J]][K] = max(dp[i][j][k] + 1, dp[i + 1][nxts[J]][K]);
  else if (K == l3)
    dp[i + 1][J][nxtt[K]] = max(dp[i][j][k] - 1, dp[i + 1][J][nxtt[K]]);
  else
    dp[i + 1][J][K] = max(dp[i][j][k], dp[i + 1][J][K]);
}
int main() {
  memset(dp, -0x3f, sizeof dp);
  string c, s, t;
  cin >> c >> s >> t;
  l1 = c.length(), l2 = s.length(), l3 = t.length();
  getnext(s, nxts);
  getnext(t, nxtt);
  dp[0][0][0] = 0;
  for (int i = 0; i < l1; i++) {
    for (int j = 0; j < l2; j++) {
      for (int k = 0; k < l3; k++) {
        if (c[i] != '*') {
          int p = j;
          while (nxts[p] != -1 && c[i] != s[p]) p = nxts[p];
          if (s[p] == c[i]) ++p;
          int J = p;
          p = k;
          while (nxtt[p] != -1 && c[i] != t[p]) p = nxtt[p];
          if (t[p] == c[i]) ++p;
          int K = p;
          up(i, j, k, J, K);
        } else {
          for (char tc = 'a'; tc <= 'z'; tc++) {
            c[i] = tc;
            int p = j;
            while (nxts[p] != -1 && c[i] != s[p]) p = nxts[p];
            if (s[p] == c[i]) ++p;
            int J = p;
            p = k;
            while (nxtt[p] != -1 && c[i] != t[p]) p = nxtt[p];
            if (t[p] == c[i]) ++p;
            int K = p;
            up(i, j, k, J, K);
          }
          c[i] = '*';
        }
      }
    }
  }
  int ans = -0x3f3f3f3f;
  for (int i = 0; i < l2; i++)
    for (int j = 0; j < l3; j++) ans = max(ans, dp[l1][i][j]);
  printf("%d\n", ans);
}
