#include <bits/stdc++.h>
char lin[1010], fv[60], ts[60];
int n, m, pi1[60], pi2[60];
long long int dp[1010][60][60], h;
int p, q, df;
void calc(int i, int x, int y) {
  p = x - 1, q = y - 1;
  while (p != -1 && lin[i + 1] != fv[p + 1]) p = pi1[p];
  if (fv[p + 1] == lin[i + 1]) p++;
  while (q != -1 && lin[i + 1] != ts[q + 1]) q = pi2[q];
  if (ts[q + 1] == lin[i + 1]) q++;
  df = 0;
  if (q == m - 1) df--, q = pi2[q];
  if (p == n - 1) df++, p = pi1[p];
  p++, q++;
}
int main() {
  int i;
  scanf(" %s", lin);
  scanf(" %s", fv);
  scanf(" %s", ts);
  n = strlen(fv);
  m = strlen(ts);
  pi1[0] = pi2[0] = -1;
  int cur = -1;
  for (i = 1; i < n; i++) {
    while (cur != -1 && fv[cur + 1] != fv[i]) cur = pi1[cur];
    if (fv[cur + 1] == fv[i]) cur++;
    pi1[i] = cur;
  }
  cur = -1;
  for (i = 1; i < m; i++) {
    while (cur != -1 && ts[cur + 1] != ts[i]) cur = pi2[cur];
    if (ts[cur + 1] == ts[i]) cur++;
    pi2[i] = cur;
  }
  int sz = strlen(lin);
  for (i = 0; i < sz; i++)
    for (int x = 0; x < n; x++)
      for (int y = 0; y < m; y++) dp[i][x][y] = -1000000;
  if (lin[0] == '*') {
    for (i = 0; i < 26; i++) {
      lin[0] = 'a' + i;
      int a = 0, b = 0, dd = 0;
      if (lin[0] == fv[0]) a = 1;
      if (lin[0] == ts[0]) b = 1;
      if (b == 1 && m == 1) b = 0, dd--;
      if (a == 1 && n == 1) a = 0, dd++;
      if (dd > dp[0][a][b]) dp[0][a][b] = dd;
    }
    lin[0] = '*';
  } else {
    int a = 0, b = 0, dd = 0;
    if (lin[0] == fv[0]) a = 1;
    if (lin[0] == ts[0]) b = 1;
    if (b == 1 && m == 1) b = 0, dd--;
    if (a == 1 && n == 1) a = 0, dd++;
    dp[0][a][b] = dd;
  }
  for (i = 0; i < sz - 1; i++)
    for (int x = 0; x < n; x++)
      for (int y = 0; y < m; y++) {
        if (dp[i][x][y] == -1000000) continue;
        if (lin[i + 1] == '*') {
          for (int j = 0; j < 26; j++) {
            lin[i + 1] = j + 'a';
            calc(i, x, y);
            if (dp[i][x][y] + df > dp[i + 1][p][q])
              dp[i + 1][p][q] = dp[i][x][y] + df;
          }
          lin[i + 1] = '*';
        } else {
          calc(i, x, y);
          if (dp[i][x][y] + df > dp[i + 1][p][q])
            dp[i + 1][p][q] = dp[i][x][y] + df;
        }
      }
  int ans = -1000000;
  for (int x = 0; x < n; x++)
    for (int y = 0; y < m; y++)
      if (dp[sz - 1][x][y] > ans) ans = dp[sz - 1][x][y];
  printf("%d\n", ans);
  return 0;
}
